#include "ocs.h"
#include "ocs_mgmt.h"
#include "ocs_gendump.h"
#include "ocs_vpd.h"
#define SFP_PAGE_SIZE 128
static int ocs_mgmt_firmware_write(ocs_t *ocs, char *, void *buf, uint32_t buf_len, void*, uint32_t);
static int ocs_mgmt_firmware_reset(ocs_t *ocs, char *, void *buf, uint32_t buf_len, void*, uint32_t);
static int ocs_mgmt_function_reset(ocs_t *ocs, char *, void *buf, uint32_t buf_len, void*, uint32_t);
static void ocs_mgmt_fw_write_cb(int32_t status, uint32_t actual_write_length, uint32_t change_status, void *arg);
static int ocs_mgmt_force_assert(ocs_t *ocs, char *, void *buf, uint32_t buf_len, void*, uint32_t);
static void get_nodes_count(ocs_t *, char *, ocs_textbuf_t*);
static void get_desc(ocs_t *, char *, ocs_textbuf_t*);
static void get_fw_rev(ocs_t *, char *, ocs_textbuf_t*);
static void get_fw_rev2(ocs_t *, char *, ocs_textbuf_t*);
static void get_ipl(ocs_t *, char *, ocs_textbuf_t*);
static void get_wwnn(ocs_t *, char *, ocs_textbuf_t*);
static void get_wwpn(ocs_t *, char *, ocs_textbuf_t*);
static void get_fcid(ocs_t *, char *, ocs_textbuf_t *);
static void get_sn(ocs_t *, char *, ocs_textbuf_t*);
static void get_pn(ocs_t *, char *, ocs_textbuf_t*);
static void get_sli4_intf_reg(ocs_t *, char *, ocs_textbuf_t*);
static void get_phy_port_num(ocs_t *, char *, ocs_textbuf_t*);
static void get_asic_id(ocs_t *, char *, ocs_textbuf_t*);
static void get_pci_vendor(ocs_t *, char *, ocs_textbuf_t*);
static void get_pci_device(ocs_t *, char *, ocs_textbuf_t*);
static void get_pci_subsystem_vendor(ocs_t *, char *, ocs_textbuf_t*);
static void get_pci_subsystem_device(ocs_t *, char *, ocs_textbuf_t*);
static void get_businfo(ocs_t *, char *, ocs_textbuf_t*);
static void get_sfp_a0(ocs_t *, char *, ocs_textbuf_t*);
static void get_sfp_a2(ocs_t *, char *, ocs_textbuf_t*);
static void get_hw_rev1(ocs_t *, char *, ocs_textbuf_t*);
static void get_hw_rev2(ocs_t *, char *, ocs_textbuf_t*);
static void get_hw_rev3(ocs_t *, char *, ocs_textbuf_t*);
static void get_debug_mq_dump(ocs_t*, char*, ocs_textbuf_t*);
static void get_debug_cq_dump(ocs_t*, char*, ocs_textbuf_t*);
static void get_debug_wq_dump(ocs_t*, char*, ocs_textbuf_t*);
static void get_debug_eq_dump(ocs_t*, char*, ocs_textbuf_t*);
static void get_logmask(ocs_t*, char*, ocs_textbuf_t*);
static void get_current_speed(ocs_t*, char*, ocs_textbuf_t*);
static void get_current_topology(ocs_t*, char*, ocs_textbuf_t*);
static void get_current_link_state(ocs_t*, char*, ocs_textbuf_t*);
static void get_configured_speed(ocs_t*, char*, ocs_textbuf_t*);
static void get_configured_topology(ocs_t*, char*, ocs_textbuf_t*);
static void get_configured_link_state(ocs_t*, char*, ocs_textbuf_t*);
static void get_linkcfg(ocs_t*, char*, ocs_textbuf_t*);
static void get_req_wwnn(ocs_t*, char*, ocs_textbuf_t*);
static void get_req_wwpn(ocs_t*, char*, ocs_textbuf_t*);
static void get_nodedb_mask(ocs_t*, char*, ocs_textbuf_t*);
static void get_profile_list(ocs_t*, char*, ocs_textbuf_t*);
static void get_active_profile(ocs_t*, char*, ocs_textbuf_t*);
static void get_port_protocol(ocs_t*, char*, ocs_textbuf_t*);
static void get_driver_version(ocs_t*, char*, ocs_textbuf_t*);
static void get_chip_type(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
static void get_tgt_rscn_delay(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
static void get_tgt_rscn_period(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
static void get_inject_drop_cmd(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
static void get_inject_free_drop_cmd(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
static void get_inject_drop_data(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
static void get_inject_drop_resp(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
static void get_cmd_err_inject(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
static void get_cmd_delay_value(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
static void get_nv_wwpn(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
static void get_nv_wwnn(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
static void get_loglevel(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
static void get_node_abort_cnt(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
static int set_debug_mq_dump(ocs_t*, char*, char*);
static int set_debug_cq_dump(ocs_t*, char*, char*);
static int set_debug_wq_dump(ocs_t*, char*, char*);
static int set_debug_eq_dump(ocs_t*, char*, char*);
static int set_logmask(ocs_t*, char*, char*);
static int set_configured_link_state(ocs_t*, char*, char*);
static int set_linkcfg(ocs_t*, char*, char*);
static int set_nodedb_mask(ocs_t*, char*, char*);
static int set_port_protocol(ocs_t*, char*, char*);
static int set_active_profile(ocs_t*, char*, char*);
static int set_tgt_rscn_delay(ocs_t*, char*, char*);
static int set_tgt_rscn_period(ocs_t*, char*, char*);
static int set_inject_drop_cmd(ocs_t*, char*, char*);
static int set_inject_free_drop_cmd(ocs_t*, char*, char*);
static int set_inject_drop_data(ocs_t*, char*, char*);
static int set_inject_drop_resp(ocs_t*, char*, char*);
static int set_cmd_err_inject(ocs_t*, char*, char*);
static int set_cmd_delay_value(ocs_t*, char*, char*);
static int set_nv_wwn(ocs_t*, char*, char*);
static int set_loglevel(ocs_t*, char*, char*);
static void ocs_mgmt_linkcfg_cb(int32_t status, uintptr_t value, void *arg);
ocs_mgmt_table_entry_t mgmt_table[] = {
{"nodes_count", get_nodes_count, NULL, NULL},
{"desc", get_desc, NULL, NULL},
{"fw_rev", get_fw_rev, NULL, NULL},
{"fw_rev2", get_fw_rev2, NULL, NULL},
{"ipl", get_ipl, NULL, NULL},
{"hw_rev1", get_hw_rev1, NULL, NULL},
{"hw_rev2", get_hw_rev2, NULL, NULL},
{"hw_rev3", get_hw_rev3, NULL, NULL},
{"wwnn", get_wwnn, NULL, NULL},
{"wwpn", get_wwpn, NULL, NULL},
{"fc_id", get_fcid, NULL, NULL},
{"sn", get_sn, NULL, NULL},
{"pn", get_pn, NULL, NULL},
{"sli4_intf_reg", get_sli4_intf_reg, NULL, NULL},
{"phy_port_num", get_phy_port_num, NULL, NULL},
{"asic_id_reg", get_asic_id, NULL, NULL},
{"pci_vendor", get_pci_vendor, NULL, NULL},
{"pci_device", get_pci_device, NULL, NULL},
{"pci_subsystem_vendor", get_pci_subsystem_vendor, NULL, NULL},
{"pci_subsystem_device", get_pci_subsystem_device, NULL, NULL},
{"businfo", get_businfo, NULL, NULL},
{"sfp_a0", get_sfp_a0, NULL, NULL},
{"sfp_a2", get_sfp_a2, NULL, NULL},
{"profile_list", get_profile_list, NULL, NULL},
{"driver_version", get_driver_version, NULL, NULL},
{"current_speed", get_current_speed, NULL, NULL},
{"current_topology", get_current_topology, NULL, NULL},
{"current_link_state", get_current_link_state, NULL, NULL},
{"chip_type", get_chip_type, NULL, NULL},
{"configured_speed", get_configured_speed, set_configured_speed, NULL},
{"configured_topology", get_configured_topology, set_configured_topology, NULL},
{"configured_link_state", get_configured_link_state, set_configured_link_state, NULL},
{"debug_mq_dump", get_debug_mq_dump, set_debug_mq_dump, NULL},
{"debug_cq_dump", get_debug_cq_dump, set_debug_cq_dump, NULL},
{"debug_wq_dump", get_debug_wq_dump, set_debug_wq_dump, NULL},
{"debug_eq_dump", get_debug_eq_dump, set_debug_eq_dump, NULL},
{"logmask", get_logmask, set_logmask, NULL},
{"loglevel", get_loglevel, set_loglevel, NULL},
{"linkcfg", get_linkcfg, set_linkcfg, NULL},
{"requested_wwnn", get_req_wwnn, set_req_wwnn, NULL},
{"requested_wwpn", get_req_wwpn, set_req_wwpn, NULL},
{"nodedb_mask", get_nodedb_mask, set_nodedb_mask, NULL},
{"port_protocol", get_port_protocol, set_port_protocol, NULL},
{"active_profile", get_active_profile, set_active_profile, NULL},
{"firmware_write", NULL, NULL, ocs_mgmt_firmware_write},
{"firmware_reset", NULL, NULL, ocs_mgmt_firmware_reset},
{"function_reset", NULL, NULL, ocs_mgmt_function_reset},
{"force_assert", NULL, NULL, ocs_mgmt_force_assert},
{"tgt_rscn_delay", get_tgt_rscn_delay, set_tgt_rscn_delay, NULL},
{"tgt_rscn_period", get_tgt_rscn_period, set_tgt_rscn_period, NULL},
{"inject_drop_cmd", get_inject_drop_cmd, set_inject_drop_cmd, NULL},
{"inject_free_drop_cmd", get_inject_free_drop_cmd, set_inject_free_drop_cmd, NULL},
{"inject_drop_data", get_inject_drop_data, set_inject_drop_data, NULL},
{"inject_drop_resp", get_inject_drop_resp, set_inject_drop_resp, NULL},
{"cmd_err_inject", get_cmd_err_inject, set_cmd_err_inject, NULL},
{"cmd_delay_value", get_cmd_delay_value, set_cmd_delay_value, NULL},
{"nv_wwpn", get_nv_wwpn, NULL, NULL},
{"nv_wwnn", get_nv_wwnn, NULL, NULL},
{"nv_wwn", NULL, set_nv_wwn, NULL},
{"node_abort_cnt", get_node_abort_cnt, NULL, NULL},
};
void
ocs_mgmt_get_list(ocs_t *ocs, ocs_textbuf_t *textbuf)
{
ocs_domain_t *domain;
uint32_t i;
int access;
ocs_mgmt_start_unnumbered_section(textbuf, "ocs");
for (i = 0; i < ARRAY_SIZE(mgmt_table); i++) {
access = 0;
if (mgmt_table[i].get_handler) {
access |= MGMT_MODE_RD;
}
if (mgmt_table[i].set_handler) {
access |= MGMT_MODE_WR;
}
if (mgmt_table[i].action_handler) {
access |= MGMT_MODE_EX;
}
ocs_mgmt_emit_property_name(textbuf, access, mgmt_table[i].name);
}
if ((ocs->mgmt_functions) && (ocs->mgmt_functions->get_list_handler)) {
ocs->mgmt_functions->get_list_handler(textbuf, ocs);
}
if ((ocs->tgt_mgmt_functions) && (ocs->tgt_mgmt_functions->get_list_handler)) {
ocs->tgt_mgmt_functions->get_list_handler(textbuf, &(ocs->tgt_ocs));
}
if (ocs_device_lock_try(ocs) == TRUE) {
ocs_list_foreach(&ocs->domain_list, domain) {
if ((domain->mgmt_functions) && (domain->mgmt_functions->get_list_handler)) {
domain->mgmt_functions->get_list_handler(textbuf, domain);
}
}
ocs_device_unlock(ocs);
}
ocs_mgmt_end_unnumbered_section(textbuf, "ocs");
}
int
ocs_mgmt_get(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_domain_t *domain;
char qualifier[6];
int retval = -1;
uint32_t i;
ocs_mgmt_start_unnumbered_section(textbuf, "ocs");
snprintf(qualifier, sizeof(qualifier), "/ocs");
if (ocs_strncmp(name, qualifier, strlen(qualifier)) == 0) {
char *unqualified_name = name + strlen(qualifier) + 1;
for (i = 0; i < ARRAY_SIZE(mgmt_table); i++) {
if (ocs_strcmp(unqualified_name, mgmt_table[i].name) == 0) {
if (mgmt_table[i].get_handler) {
mgmt_table[i].get_handler(ocs, name, textbuf);
ocs_mgmt_end_unnumbered_section(textbuf, "ocs");
return 0;
}
}
}
if ((ocs->mgmt_functions) && (ocs->mgmt_functions->get_handler)) {
retval = ocs->mgmt_functions->get_handler(textbuf, qualifier, (char*)name, ocs);
}
if (retval != 0) {
if ((ocs->tgt_mgmt_functions) && (ocs->tgt_mgmt_functions->get_handler)) {
retval = ocs->tgt_mgmt_functions->get_handler(textbuf, qualifier,
(char*)name, &(ocs->tgt_ocs));
}
}
if (retval != 0) {
ocs_device_lock(ocs);
ocs_list_foreach(&ocs->domain_list, domain) {
if ((domain->mgmt_functions) && (domain->mgmt_functions->get_handler)) {
retval = domain->mgmt_functions->get_handler(textbuf, qualifier, (char*)name, domain);
}
if (retval == 0) {
break;
}
}
ocs_device_unlock(ocs);
}
}
ocs_mgmt_end_unnumbered_section(textbuf, "ocs");
return retval;
}
int
ocs_mgmt_set(ocs_t *ocs, char *name, char *value)
{
ocs_domain_t *domain;
int result = -1;
char qualifier[80];
uint32_t i;
snprintf(qualifier, sizeof(qualifier), "/ocs");
if (ocs_strncmp(name, qualifier, strlen(qualifier)) == 0) {
char *unqualified_name = name + strlen(qualifier) +1;
for (i = 0; i < ARRAY_SIZE(mgmt_table); i++) {
if (ocs_strcmp(unqualified_name, mgmt_table[i].name) == 0) {
if (mgmt_table[i].set_handler) {
return mgmt_table[i].set_handler(ocs, name, value);
}
}
}
if ((ocs->mgmt_functions) && (ocs->mgmt_functions->set_handler)) {
result = ocs->mgmt_functions->set_handler(qualifier, name, (char *)value, ocs);
}
if (result != 0) {
if ((ocs->tgt_mgmt_functions) && (ocs->tgt_mgmt_functions->set_handler)) {
result = ocs->tgt_mgmt_functions->set_handler(qualifier, name,
(char *)value, &(ocs->tgt_ocs));
}
}
if (result != 0) {
ocs_device_lock(ocs);
ocs_list_foreach(&ocs->domain_list, domain) {
if ((domain->mgmt_functions) && (domain->mgmt_functions->set_handler)) {
result = domain->mgmt_functions->set_handler(qualifier, name, (char*)value, domain);
}
if (result == 0) {
break;
}
}
ocs_device_unlock(ocs);
}
}
return result;
}
int
ocs_mgmt_exec(ocs_t *ocs, char *action, void *arg_in,
uint32_t arg_in_length, void *arg_out, uint32_t arg_out_length)
{
ocs_domain_t *domain;
int result = -1;
char qualifier[80];
uint32_t i;
snprintf(qualifier, sizeof(qualifier), "/ocs");
if (ocs_strncmp(action, qualifier, strlen(qualifier)) == 0) {
char *unqualified_name = action + strlen(qualifier) +1;
for (i = 0; i < ARRAY_SIZE(mgmt_table); i++) {
if (ocs_strcmp(unqualified_name, mgmt_table[i].name) == 0) {
if (mgmt_table[i].action_handler) {
return mgmt_table[i].action_handler(ocs, action, arg_in, arg_in_length,
arg_out, arg_out_length);
}
}
}
if (ocs_strcmp(unqualified_name, "driver/gendump") == 0) {
return ocs_gen_dump(ocs);
}
if (ocs_strcmp(unqualified_name, "driver/dump_to_host") == 0) {
return ocs_dump_to_host(ocs, arg_out, arg_out_length);
}
if ((ocs->mgmt_functions) && (ocs->mgmt_functions->exec_handler)) {
result = ocs->mgmt_functions->exec_handler(qualifier, action, arg_in, arg_in_length,
arg_out, arg_out_length, ocs);
}
if (result != 0) {
if ((ocs->tgt_mgmt_functions) && (ocs->tgt_mgmt_functions->exec_handler)) {
result = ocs->tgt_mgmt_functions->exec_handler(qualifier, action,
arg_in, arg_in_length, arg_out, arg_out_length,
&(ocs->tgt_ocs));
}
}
if (result != 0) {
ocs_device_lock(ocs);
ocs_list_foreach(&ocs->domain_list, domain) {
if ((domain->mgmt_functions) && (domain->mgmt_functions->exec_handler)) {
result = domain->mgmt_functions->exec_handler(qualifier, action, arg_in, arg_in_length, arg_out,
arg_out_length, domain);
}
if (result == 0) {
break;
}
}
ocs_device_unlock(ocs);
}
}
return result;
}
void
ocs_mgmt_get_all(ocs_t *ocs, ocs_textbuf_t *textbuf)
{
ocs_domain_t *domain;
uint32_t i;
ocs_mgmt_start_unnumbered_section(textbuf, "ocs");
for (i = 0; i < ARRAY_SIZE(mgmt_table); i++) {
if (mgmt_table[i].get_handler) {
mgmt_table[i].get_handler(ocs, mgmt_table[i].name, textbuf);
} else if (mgmt_table[i].action_handler) {
ocs_mgmt_emit_property_name(textbuf, MGMT_MODE_EX, mgmt_table[i].name);
}
}
if ((ocs->mgmt_functions) && (ocs->mgmt_functions->get_all_handler)) {
ocs->mgmt_functions->get_all_handler(textbuf, ocs);
}
if ((ocs->tgt_mgmt_functions) && (ocs->tgt_mgmt_functions->get_all_handler)) {
ocs->tgt_mgmt_functions->get_all_handler(textbuf, &(ocs->tgt_ocs));
}
ocs_device_lock(ocs);
ocs_list_foreach(&ocs->domain_list, domain) {
if ((domain->mgmt_functions) && (domain->mgmt_functions->get_all_handler)) {
domain->mgmt_functions->get_all_handler(textbuf, domain);
}
}
ocs_device_unlock(ocs);
ocs_mgmt_end_unnumbered_section(textbuf, "ocs");
}
static int32_t
ocs_mgmt_firmware_reset(ocs_t *ocs, char *name, void *buf, uint32_t buf_len, void *arg_out, uint32_t arg_out_length)
{
int rc = 0;
int index = 0;
uint8_t bus, dev, func;
ocs_t *other_ocs;
ocs_get_bus_dev_func(ocs, &bus, &dev, &func);
ocs_log_debug(ocs, "Resetting port\n");
if (ocs_hw_reset(&ocs->hw, OCS_HW_RESET_FIRMWARE)) {
ocs_log_test(ocs, "failed to reset port\n");
rc = -1;
} else {
ocs_log_debug(ocs, "successfully reset port\n");
while ((other_ocs = ocs_get_instance(index++)) != NULL) {
uint8_t other_bus, other_dev, other_func;
ocs_get_bus_dev_func(other_ocs, &other_bus, &other_dev, &other_func);
if ((bus == other_bus) && (dev == other_dev)) {
if (other_ocs->hw.state !=
OCS_HW_STATE_UNINITIALIZED) {
other_ocs->hw.state =
OCS_HW_STATE_QUEUES_ALLOCATED;
}
ocs_device_detach(other_ocs);
if (ocs_device_attach(other_ocs)) {
ocs_log_err(other_ocs,
"device %d attach failed \n", index);
rc = -1;
}
}
}
}
return rc;
}
static int32_t
ocs_mgmt_function_reset(ocs_t *ocs, char *name, void *buf, uint32_t buf_len, void *arg_out, uint32_t arg_out_length)
{
int32_t rc;
ocs_device_detach(ocs);
rc = ocs_device_attach(ocs);
return rc;
}
static int32_t
ocs_mgmt_firmware_write(ocs_t *ocs, char *name, void *buf, uint32_t buf_len, void *arg_out, uint32_t arg_out_length)
{
int rc = 0;
uint32_t bytes_left;
uint32_t xfer_size;
uint32_t offset;
uint8_t *userp;
ocs_dma_t dma;
int last = 0;
ocs_mgmt_fw_write_result_t result;
uint32_t change_status = 0;
char status_str[80];
ocs_sem_init(&(result.semaphore), 0, "fw_write");
bytes_left = buf_len;
offset = 0;
userp = (uint8_t *)buf;
if (ocs_dma_alloc(ocs, &dma, FW_WRITE_BUFSIZE, 4096)) {
ocs_log_err(ocs, "ocs_mgmt_firmware_write: malloc failed");
return -ENOMEM;
}
while (bytes_left > 0) {
if (bytes_left > FW_WRITE_BUFSIZE) {
xfer_size = FW_WRITE_BUFSIZE;
} else {
xfer_size = bytes_left;
}
if (ocs_copy_from_user(dma.virt, userp, xfer_size)) {
rc = -EFAULT;
break;
}
if (bytes_left == xfer_size) {
last = 1;
}
ocs_hw_firmware_write(&ocs->hw, &dma, xfer_size, offset, last, ocs_mgmt_fw_write_cb, &result);
if (ocs_sem_p(&(result.semaphore), OCS_SEM_FOREVER) != 0) {
ocs_log_err(ocs, "ocs_sem_p failed\n");
rc = -ENXIO;
break;
}
if (result.actual_xfer == 0) {
ocs_log_test(ocs, "actual_write_length is %d\n", result.actual_xfer);
rc = -EFAULT;
break;
}
if (result.status != 0) {
ocs_log_test(ocs, "write returned status %d\n", result.status);
rc = -EFAULT;
break;
}
if (last) {
change_status = result.change_status;
}
bytes_left -= result.actual_xfer;
offset += result.actual_xfer;
userp += result.actual_xfer;
}
if ((arg_out_length > 0) && (arg_out != NULL)) {
if (arg_out_length > sizeof(status_str)) {
arg_out_length = sizeof(status_str);
}
ocs_memset(status_str, 0, sizeof(status_str));
ocs_snprintf(status_str, arg_out_length, "%d", change_status);
if (ocs_copy_to_user(arg_out, status_str, arg_out_length)) {
ocs_log_test(ocs, "copy to user failed for change_status\n");
}
}
ocs_dma_free(ocs, &dma);
return rc;
}
static void
ocs_mgmt_fw_write_cb(int32_t status, uint32_t actual_write_length, uint32_t change_status, void *arg)
{
ocs_mgmt_fw_write_result_t *result = arg;
result->status = status;
result->actual_xfer = actual_write_length;
result->change_status = change_status;
ocs_sem_v(&(result->semaphore));
}
typedef struct ocs_mgmt_sfp_result {
ocs_sem_t semaphore;
ocs_lock_t cb_lock;
int32_t running;
int32_t status;
uint32_t bytes_read;
uint32_t page_data[32];
} ocs_mgmt_sfp_result_t;
static void
ocs_mgmt_sfp_cb(void *os, int32_t status, uint32_t bytes_read, uint32_t *data, void *arg)
{
ocs_mgmt_sfp_result_t *result = arg;
ocs_t *ocs = os;
ocs_lock(&(result->cb_lock));
result->running++;
if(result->running == 2) {
ocs_unlock(&(result->cb_lock));
ocs_free(ocs, result, sizeof(ocs_mgmt_sfp_result_t));
return;
}
result->status = status;
result->bytes_read = bytes_read;
ocs_memcpy(&result->page_data, data, SFP_PAGE_SIZE);
ocs_sem_v(&(result->semaphore));
ocs_unlock(&(result->cb_lock));
}
static int32_t
ocs_mgmt_get_sfp(ocs_t *ocs, uint16_t page, void *buf, uint32_t buf_len)
{
int rc = 0;
ocs_mgmt_sfp_result_t *result = ocs_malloc(ocs, sizeof(ocs_mgmt_sfp_result_t), OCS_M_ZERO | OCS_M_NOWAIT);
ocs_sem_init(&(result->semaphore), 0, "get_sfp");
ocs_lock_init(ocs, &(result->cb_lock), "get_sfp");
ocs_hw_get_sfp(&ocs->hw, page, ocs_mgmt_sfp_cb, result);
if (ocs_sem_p(&(result->semaphore), 5 * 1000 * 1000) != 0) {
ocs_lock(&(result->cb_lock));
result->running++;
if(result->running == 1) {
ocs_log_err(ocs, "ocs_sem_p failed\n");
ocs_unlock(&(result->cb_lock));
return (-ENXIO);
}
ocs_unlock(&(result->cb_lock));
}
if (result->status != 0) {
ocs_log_test(ocs, "read_transceiver_data returned status %d\n",
result->status);
rc = -EFAULT;
}
if (rc == 0) {
rc = (result->bytes_read > buf_len ? buf_len : result->bytes_read);
ocs_memcpy(buf, result->page_data, rc);
}
ocs_free(ocs, result, sizeof(ocs_mgmt_sfp_result_t));
return rc;
}
static int32_t
ocs_mgmt_force_assert(ocs_t *ocs, char *name, void *buf, uint32_t buf_len, void *arg_out, uint32_t arg_out_length)
{
ocs_assert(FALSE, 0);
}
static void
get_nodes_count(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_xport_t *xport = ocs->xport;
ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "nodes_count", "%d", xport->nodes_count);
}
static void
get_driver_version(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "driver_version", ocs->driver_version);
}
static void
get_desc(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "desc", ocs->desc);
}
static void
get_fw_rev(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "fw_rev", ocs_hw_get_ptr(&ocs->hw, OCS_HW_FW_REV));
}
static void
get_fw_rev2(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "fw_rev2", ocs_hw_get_ptr(&ocs->hw, OCS_HW_FW_REV2));
}
static void
get_ipl(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "ipl", ocs_hw_get_ptr(&ocs->hw, OCS_HW_IPL));
}
static void
get_hw_rev1(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
uint32_t value;
ocs_hw_get(&ocs->hw, OCS_HW_HW_REV1, &value);
ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "hw_rev1", "%u", value);
}
static void
get_hw_rev2(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
uint32_t value;
ocs_hw_get(&ocs->hw, OCS_HW_HW_REV2, &value);
ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "hw_rev2", "%u", value);
}
static void
get_hw_rev3(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
uint32_t value;
ocs_hw_get(&ocs->hw, OCS_HW_HW_REV3, &value);
ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "hw_rev3", "%u", value);
}
static void
get_wwnn(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
uint64_t *wwnn;
wwnn = ocs_hw_get_ptr(&ocs->hw, OCS_HW_WWN_NODE);
ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "wwnn", "0x%llx", (unsigned long long)ocs_htobe64(*wwnn));
}
static void
get_wwpn(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
uint64_t *wwpn;
wwpn = ocs_hw_get_ptr(&ocs->hw, OCS_HW_WWN_PORT);
ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "wwpn", "0x%llx", (unsigned long long)ocs_htobe64(*wwpn));
}
static void
get_fcid(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
if (ocs->domain && ocs->domain->attached) {
ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "fc_id", "0x%06x",
ocs->domain->sport->fc_id);
} else {
ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "fc_id", "UNKNOWN");
}
}
static void
get_sn(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
uint8_t *pserial;
uint32_t len;
char sn_buf[256];
pserial = ocs_scsi_get_property_ptr(ocs, OCS_SCSI_SERIALNUMBER);
if (pserial) {
len = *pserial ++;
strncpy(sn_buf, (char*)pserial, len);
sn_buf[len] = '\0';
ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "sn", sn_buf);
}
}
static void
get_pn(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
uint8_t *pserial;
uint32_t len;
char sn_buf[256];
pserial = ocs_scsi_get_property_ptr(ocs, OCS_SCSI_PARTNUMBER);
if (pserial) {
len = *pserial ++;
strncpy(sn_buf, (char*)pserial, len);
sn_buf[len] = '\0';
ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "pn", sn_buf);
} else {
ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "pn", ocs->model);
}
}
static void
get_sli4_intf_reg(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "sli4_intf_reg", "0x%04x",
ocs_config_read32(ocs, SLI4_INTF_REG));
}
static void
get_phy_port_num(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
char *phy_port = NULL;
phy_port = ocs_scsi_get_property_ptr(ocs, OCS_SCSI_PORTNUM);
if (phy_port) {
ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "phy_port_num", phy_port);
} else {
ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "phy_port_num", "unknown");
}
}
static void
get_asic_id(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "asic_id_reg", "0x%04x",
ocs_config_read32(ocs, SLI4_ASIC_ID_REG));
}
static void
get_chip_type(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
uint32_t family;
uint32_t asic_id;
uint32_t asic_gen_num;
uint32_t asic_rev_num;
uint32_t rev_id;
char result_buf[80];
char tmp_buf[80];
family = (ocs_config_read32(ocs, SLI4_INTF_REG) & 0x00000f00) >> 8;
asic_id = ocs_config_read32(ocs, SLI4_ASIC_ID_REG);
asic_rev_num = asic_id & 0xff;
asic_gen_num = (asic_id & 0xff00) >> 8;
rev_id = ocs_config_read32(ocs, SLI4_PCI_CLASS_REVISION) & 0xff;
switch(family) {
case 0x00:
ocs_strncpy(result_buf, "BE2 A", sizeof(result_buf));
ocs_snprintf(tmp_buf, 2, "%d", rev_id);
strcat(result_buf, tmp_buf);
break;
case 0x01:
ocs_strncpy(result_buf, "BE3", sizeof(result_buf));
if (rev_id >= 0x10) {
strcat(result_buf, "-R");
}
ocs_snprintf(tmp_buf, 3, " %c", ((rev_id & 0xf0) >> 4) + 'A');
strcat(result_buf, tmp_buf);
ocs_snprintf(tmp_buf, 2, "%d", rev_id & 0x0f);
strcat(result_buf, tmp_buf);
break;
case 0x02:
ocs_strncpy(result_buf, "Skyhawk A0", sizeof(result_buf));
break;
case 0x0a:
ocs_strncpy(result_buf, "Lancer A", sizeof(result_buf));
ocs_snprintf(tmp_buf, 2, "%d", rev_id & 0x0f);
strcat(result_buf, tmp_buf);
break;
case 0x0b:
ocs_strncpy(result_buf, "Lancer", sizeof(result_buf));
ocs_snprintf(tmp_buf, 3, " %c", ((rev_id & 0xf0) >> 4) + 'A');
strcat(result_buf, tmp_buf);
ocs_snprintf(tmp_buf, 2, "%d", rev_id & 0x0f);
strcat(result_buf, tmp_buf);
break;
case 0x0c:
ocs_strncpy(result_buf, "Lancer G6", sizeof(result_buf));
break;
case 0x0f:
switch(asic_gen_num) {
case 0x00:
ocs_strncpy(result_buf, "BE2", sizeof(result_buf));
break;
case 0x03:
ocs_strncpy(result_buf, "BE3-R", sizeof(result_buf));
break;
case 0x04:
ocs_strncpy(result_buf, "Skyhawk-R", sizeof(result_buf));
break;
case 0x05:
ocs_strncpy(result_buf, "Corsair", sizeof(result_buf));
break;
case 0x0b:
ocs_strncpy(result_buf, "Lancer", sizeof(result_buf));
break;
case 0x0c:
ocs_strncpy(result_buf, "LancerG6", sizeof(result_buf));
break;
default:
ocs_strncpy(result_buf, "Unknown", sizeof(result_buf));
}
if (ocs_strcmp(result_buf, "Unknown") != 0) {
ocs_snprintf(tmp_buf, 3, " %c", ((asic_rev_num & 0xf0) >> 4) + 'A');
strcat(result_buf, tmp_buf);
ocs_snprintf(tmp_buf, 2, "%d", asic_rev_num & 0x0f);
strcat(result_buf, tmp_buf);
}
break;
default:
ocs_strncpy(result_buf, "Unknown", sizeof(result_buf));
}
ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "chip_type", result_buf);
}
static void
get_pci_vendor(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "pci_vendor", "0x%04x", ocs->pci_vendor);
}
static void
get_pci_device(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "pci_device", "0x%04x", ocs->pci_device);
}
static void
get_pci_subsystem_vendor(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "pci_subsystem_vendor", "0x%04x", ocs->pci_subsystem_vendor);
}
static void
get_pci_subsystem_device(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "pci_subsystem_device", "0x%04x", ocs->pci_subsystem_device);
}
static void
get_tgt_rscn_delay(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "tgt_rscn_delay", "%ld", (unsigned long)ocs->tgt_rscn_delay_msec / 1000);
}
static void
get_tgt_rscn_period(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "tgt_rscn_period", "%ld", (unsigned long)ocs->tgt_rscn_period_msec / 1000);
}
static void
get_inject_drop_cmd(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "inject_drop_cmd", "%d",
(ocs->err_injection == INJECT_DROP_CMD ? 1:0));
}
static void
get_inject_free_drop_cmd(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "inject_free_drop_cmd", "%d",
(ocs->err_injection == INJECT_FREE_DROPPED ? 1:0));
}
static void
get_inject_drop_data(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "inject_drop_data", "%d",
(ocs->err_injection == INJECT_DROP_DATA ? 1:0));
}
static void
get_inject_drop_resp(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "inject_drop_resp", "%d",
(ocs->err_injection == INJECT_DROP_RESP ? 1:0));
}
static void
get_cmd_err_inject(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "cmd_err_inject", "0x%02x", ocs->cmd_err_inject);
}
static void
get_cmd_delay_value(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "cmd_delay_value", "%ld", (unsigned long)ocs->delay_value_msec);
}
static void
get_businfo(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "businfo", ocs->businfo);
}
static void
get_sfp_a0(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
uint8_t *page_data;
char *buf;
int i;
int32_t bytes_read;
page_data = ocs_malloc(ocs, SFP_PAGE_SIZE, OCS_M_ZERO | OCS_M_NOWAIT);
if (page_data == NULL) {
return;
}
buf = ocs_malloc(ocs, (SFP_PAGE_SIZE * 3) + 1, OCS_M_ZERO | OCS_M_NOWAIT);
if (buf == NULL) {
ocs_free(ocs, page_data, SFP_PAGE_SIZE);
return;
}
bytes_read = ocs_mgmt_get_sfp(ocs, 0xa0, page_data, SFP_PAGE_SIZE);
if (bytes_read <= 0) {
ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "sfp_a0", "(unknown)");
} else {
char *d = buf;
uint8_t *s = page_data;
int buffer_remaining = (SFP_PAGE_SIZE * 3) + 1;
int bytes_added;
for (i = 0; i < bytes_read; i++) {
bytes_added = ocs_snprintf(d, buffer_remaining, "%02x ", *s);
++s;
d += bytes_added;
buffer_remaining -= bytes_added;
}
*d = '\0';
ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "sfp_a0", buf);
}
ocs_free(ocs, page_data, SFP_PAGE_SIZE);
ocs_free(ocs, buf, (3 * SFP_PAGE_SIZE) + 1);
}
static void
get_sfp_a2(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
uint8_t *page_data;
char *buf;
int i;
int32_t bytes_read;
page_data = ocs_malloc(ocs, SFP_PAGE_SIZE, OCS_M_ZERO | OCS_M_NOWAIT);
if (page_data == NULL) {
return;
}
buf = ocs_malloc(ocs, (SFP_PAGE_SIZE * 3) + 1, OCS_M_ZERO | OCS_M_NOWAIT);
if (buf == NULL) {
ocs_free(ocs, page_data, SFP_PAGE_SIZE);
return;
}
bytes_read = ocs_mgmt_get_sfp(ocs, 0xa2, page_data, SFP_PAGE_SIZE);
if (bytes_read <= 0) {
ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "sfp_a2", "(unknown)");
} else {
char *d = buf;
uint8_t *s = page_data;
int buffer_remaining = (SFP_PAGE_SIZE * 3) + 1;
int bytes_added;
for (i = 0; i < bytes_read; i++) {
bytes_added = ocs_snprintf(d, buffer_remaining, "%02x ", *s);
++s;
d += bytes_added;
buffer_remaining -= bytes_added;
}
*d = '\0';
ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "sfp_a2", buf);
}
ocs_free(ocs, page_data, SFP_PAGE_SIZE);
ocs_free(ocs, buf, (3 * SFP_PAGE_SIZE) + 1);
}
static void
get_debug_mq_dump(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_mgmt_emit_boolean(textbuf, MGMT_MODE_RW, "debug_mq_dump",
ocs_debug_is_enabled(OCS_DEBUG_ENABLE_MQ_DUMP));
}
static void
get_debug_cq_dump(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_mgmt_emit_boolean(textbuf, MGMT_MODE_RW, "debug_cq_dump",
ocs_debug_is_enabled(OCS_DEBUG_ENABLE_CQ_DUMP));
}
static void
get_debug_wq_dump(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_mgmt_emit_boolean(textbuf, MGMT_MODE_RW, "debug_wq_dump",
ocs_debug_is_enabled(OCS_DEBUG_ENABLE_WQ_DUMP));
}
static void
get_debug_eq_dump(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_mgmt_emit_boolean(textbuf, MGMT_MODE_RW, "debug_eq_dump",
ocs_debug_is_enabled(OCS_DEBUG_ENABLE_EQ_DUMP));
}
static void
get_logmask(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "logmask", "0x%02x", ocs->logmask);
}
static void
get_loglevel(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "loglevel", "%d", loglevel);
}
static void
get_current_speed(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
uint32_t value;
ocs_hw_get(&(ocs->hw), OCS_HW_LINK_SPEED, &value);
ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "current_speed", "%d", value);
}
static void
get_configured_speed(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
uint32_t value;
ocs_hw_get(&(ocs->hw), OCS_HW_LINK_CONFIG_SPEED, &value);
if (value == 0) {
ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "configured_speed", "auto");
} else {
ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "configured_speed", "%d", value);
}
}
static void
get_current_topology(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
uint32_t value;
ocs_hw_get(&(ocs->hw), OCS_HW_TOPOLOGY, &value);
ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "current_topology", "%d", value);
}
static void
get_configured_topology(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
uint32_t value;
ocs_hw_get(&(ocs->hw), OCS_HW_CONFIG_TOPOLOGY, &value);
ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "configured_topology", "%d", value);
}
static void
get_current_link_state(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_xport_stats_t value;
if (ocs_xport_status(ocs->xport, OCS_XPORT_PORT_STATUS, &value) == 0) {
if (value.value == OCS_XPORT_PORT_ONLINE) {
ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "current_link_state", "online");
} else {
ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "current_link_state", "offline");
}
}
}
static void
get_configured_link_state(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_xport_stats_t value;
if (ocs_xport_status(ocs->xport, OCS_XPORT_CONFIG_PORT_STATUS, &value) == 0) {
if (value.value == OCS_XPORT_PORT_ONLINE) {
ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "configured_link_state", "online");
} else {
ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "configured_link_state", "offline");
}
}
}
typedef struct ocs_mgmt_linkcfg_map_s {
ocs_hw_linkcfg_e linkcfg;
const char *mgmt_str;
} ocs_mgmt_linkcfg_map_t;
static ocs_mgmt_linkcfg_map_t mgmt_linkcfg_map[] = {
{OCS_HW_LINKCFG_4X10G, OCS_CONFIG_LINKCFG_4X10G},
{OCS_HW_LINKCFG_1X40G, OCS_CONFIG_LINKCFG_1X40G},
{OCS_HW_LINKCFG_2X16G, OCS_CONFIG_LINKCFG_2X16G},
{OCS_HW_LINKCFG_4X8G, OCS_CONFIG_LINKCFG_4X8G},
{OCS_HW_LINKCFG_4X1G, OCS_CONFIG_LINKCFG_4X1G},
{OCS_HW_LINKCFG_2X10G, OCS_CONFIG_LINKCFG_2X10G},
{OCS_HW_LINKCFG_2X10G_2X8G, OCS_CONFIG_LINKCFG_2X10G_2X8G}};
static ocs_hw_linkcfg_e
ocs_hw_linkcfg_from_mgmt(const char *mgmt_str)
{
uint32_t i;
for (i = 0; i < ARRAY_SIZE(mgmt_linkcfg_map); i++) {
if (ocs_strncmp(mgmt_linkcfg_map[i].mgmt_str,
mgmt_str, ocs_strlen(mgmt_str)) == 0) {
return mgmt_linkcfg_map[i].linkcfg;
}
}
return OCS_HW_LINKCFG_NA;
}
static const char *
ocs_mgmt_from_hw_linkcfg(ocs_hw_linkcfg_e linkcfg)
{
uint32_t i;
for (i = 0; i < ARRAY_SIZE(mgmt_linkcfg_map); i++) {
if (mgmt_linkcfg_map[i].linkcfg == linkcfg) {
return mgmt_linkcfg_map[i].mgmt_str;
}
}
return OCS_CONFIG_LINKCFG_UNKNOWN;
}
typedef struct ocs_mgmt_linkcfg_arg_s {
ocs_sem_t semaphore;
int32_t status;
ocs_hw_linkcfg_e linkcfg;
} ocs_mgmt_linkcfg_arg_t;
static void
get_linkcfg(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
const char *linkcfg_str = NULL;
uint32_t value;
ocs_hw_linkcfg_e linkcfg;
ocs_hw_get(&ocs->hw, OCS_HW_LINKCFG, &value);
linkcfg = (ocs_hw_linkcfg_e)value;
linkcfg_str = ocs_mgmt_from_hw_linkcfg(linkcfg);
ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "linkcfg", linkcfg_str);
}
static void
get_req_wwnn(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_xport_t *xport = ocs->xport;
ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "requested_wwnn", "0x%llx", (unsigned long long)xport->req_wwnn);
}
static void
get_req_wwpn(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_xport_t *xport = ocs->xport;
ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "requested_wwpn", "0x%llx", (unsigned long long)xport->req_wwpn);
}
static void
get_nodedb_mask(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "nodedb_mask", "0x%08x", ocs->nodedb_mask);
}
int
set_req_wwnn(ocs_t *ocs, char *name, char *value)
{
int rc;
uint64_t wwnn;
if (ocs_strcasecmp(value, "default") == 0) {
wwnn = 0;
}
else if (parse_wwn(value, &wwnn) != 0) {
ocs_log_test(ocs, "Invalid WWNN: %s\n", value);
return 1;
}
rc = ocs_xport_control(ocs->xport, OCS_XPORT_WWNN_SET, wwnn);
if(rc) {
ocs_log_test(ocs, "OCS_XPORT_WWNN_SET failed: %d\n", rc);
return rc;
}
rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_OFFLINE);
if (rc) {
ocs_log_test(ocs, "port offline failed : %d\n", rc);
}
rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_ONLINE);
if (rc) {
ocs_log_test(ocs, "port online failed : %d\n", rc);
}
return rc;
}
int
set_req_wwpn(ocs_t *ocs, char *name, char *value)
{
int rc;
uint64_t wwpn;
if (ocs_strcasecmp(value, "default") == 0) {
wwpn = 0;
}
else if (parse_wwn(value, &wwpn) != 0) {
ocs_log_test(ocs, "Invalid WWPN: %s\n", value);
return 1;
}
rc = ocs_xport_control(ocs->xport, OCS_XPORT_WWPN_SET, wwpn);
if(rc) {
ocs_log_test(ocs, "OCS_XPORT_WWPN_SET failed: %d\n", rc);
return rc;
}
rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_OFFLINE);
if (rc) {
ocs_log_test(ocs, "port offline failed : %d\n", rc);
}
rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_ONLINE);
if (rc) {
ocs_log_test(ocs, "port online failed : %d\n", rc);
}
return rc;
}
static int
set_nodedb_mask(ocs_t *ocs, char *name, char *value)
{
ocs->nodedb_mask = ocs_strtoul(value, 0, 0);
return 0;
}
static int
set_linkcfg(ocs_t *ocs, char *name, char *value)
{
ocs_hw_linkcfg_e linkcfg;
ocs_mgmt_linkcfg_arg_t cb_arg;
ocs_hw_rtn_e status;
ocs_sem_init(&cb_arg.semaphore, 0, "mgmt_linkcfg");
linkcfg = ocs_hw_linkcfg_from_mgmt(value);
status = ocs_hw_port_control(&ocs->hw, OCS_HW_PORT_SET_LINK_CONFIG,
(uintptr_t)linkcfg, ocs_mgmt_linkcfg_cb, &cb_arg);
if (status) {
ocs_log_test(ocs, "ocs_hw_set_linkcfg failed\n");
return -1;
}
if (ocs_sem_p(&cb_arg.semaphore, OCS_SEM_FOREVER)) {
ocs_log_err(ocs, "ocs_sem_p failed\n");
return -1;
}
if (cb_arg.status) {
ocs_log_test(ocs, "failed to set linkcfg from HW status=%d\n",
cb_arg.status);
return -1;
}
return 0;
}
static void
ocs_mgmt_linkcfg_cb(int32_t status, uintptr_t value, void *arg)
{
ocs_mgmt_linkcfg_arg_t *cb_arg = (ocs_mgmt_linkcfg_arg_t *)arg;
cb_arg->status = status;
cb_arg->linkcfg = (ocs_hw_linkcfg_e)value;
ocs_sem_v(&cb_arg->semaphore);
}
static int
set_debug_mq_dump(ocs_t *ocs, char *name, char *value)
{
int result;
if (ocs_strcasecmp(value, "false") == 0) {
ocs_debug_disable(OCS_DEBUG_ENABLE_MQ_DUMP);
result = 0;
} else if (ocs_strcasecmp(value, "true") == 0) {
ocs_debug_enable(OCS_DEBUG_ENABLE_MQ_DUMP);
result = 0;
} else {
result = -1;
}
return result;
}
static int
set_debug_cq_dump(ocs_t *ocs, char *name, char *value)
{
int result;
if (ocs_strcasecmp(value, "false") == 0) {
ocs_debug_disable(OCS_DEBUG_ENABLE_CQ_DUMP);
result = 0;
} else if (ocs_strcasecmp(value, "true") == 0) {
ocs_debug_enable(OCS_DEBUG_ENABLE_CQ_DUMP);
result = 0;
} else {
result = -1;
}
return result;
}
static int
set_debug_wq_dump(ocs_t *ocs, char *name, char *value)
{
int result;
if (ocs_strcasecmp(value, "false") == 0) {
ocs_debug_disable(OCS_DEBUG_ENABLE_WQ_DUMP);
result = 0;
} else if (ocs_strcasecmp(value, "true") == 0) {
ocs_debug_enable(OCS_DEBUG_ENABLE_WQ_DUMP);
result = 0;
} else {
result = -1;
}
return result;
}
static int
set_debug_eq_dump(ocs_t *ocs, char *name, char *value)
{
int result;
if (ocs_strcasecmp(value, "false") == 0) {
ocs_debug_disable(OCS_DEBUG_ENABLE_EQ_DUMP);
result = 0;
} else if (ocs_strcasecmp(value, "true") == 0) {
ocs_debug_enable(OCS_DEBUG_ENABLE_EQ_DUMP);
result = 0;
} else {
result = -1;
}
return result;
}
static int
set_logmask(ocs_t *ocs, char *name, char *value)
{
ocs->logmask = ocs_strtoul(value, NULL, 0);
return 0;
}
static int
set_loglevel(ocs_t *ocs, char *name, char *value)
{
loglevel = ocs_strtoul(value, NULL, 0);
return 0;
}
int
set_configured_speed(ocs_t *ocs, char *name, char *value)
{
int result = 0;
ocs_hw_rtn_e hw_rc;
int xport_rc;
uint32_t spd;
spd = ocs_strtoul(value, NULL, 0);
if ((spd != 0) && (spd != 2000) && (spd != 4000) &&
(spd != 8000) && (spd != 16000) && (spd != 32000)) {
ocs_log_test(ocs, "unsupported speed %d\n", spd);
return 1;
}
ocs_log_debug(ocs, "Taking port offline\n");
xport_rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_OFFLINE);
if (xport_rc != 0) {
ocs_log_test(ocs, "Port offline failed\n");
result = 1;
} else {
ocs_log_debug(ocs, "Setting port to speed %d\n", spd);
hw_rc = ocs_hw_set(&ocs->hw, OCS_HW_LINK_SPEED, spd);
if (hw_rc != OCS_HW_RTN_SUCCESS) {
ocs_log_test(ocs, "Speed set failed\n");
result = 1;
}
ocs_log_debug(ocs, "Bringing port online\n");
xport_rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_ONLINE);
if (xport_rc != 0) {
result = 1;
}
}
return result;
}
int
set_configured_topology(ocs_t *ocs, char *name, char *value)
{
int result = 0;
ocs_hw_rtn_e hw_rc;
int xport_rc;
uint32_t topo;
topo = ocs_strtoul(value, NULL, 0);
if (topo >= OCS_HW_TOPOLOGY_NONE) {
return 1;
}
ocs_log_debug(ocs, "Taking port offline\n");
xport_rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_OFFLINE);
if (xport_rc != 0) {
ocs_log_test(ocs, "Port offline failed\n");
result = 1;
} else {
ocs_log_debug(ocs, "Setting port to topology %d\n", topo);
hw_rc = ocs_hw_set(&ocs->hw, OCS_HW_TOPOLOGY, topo);
if (hw_rc != OCS_HW_RTN_SUCCESS) {
ocs_log_test(ocs, "Topology set failed\n");
result = 1;
} else {
hw_rc = ocs_hw_set_persistent_topology(&ocs->hw, topo, OCS_CMD_NOWAIT);
if (hw_rc != OCS_HW_RTN_SUCCESS)
ocs_log_err(ocs, "Set persistent topology feature failed: %d\n", hw_rc);
}
ocs_log_debug(ocs, "Bringing port online\n");
xport_rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_ONLINE);
if (xport_rc != 0) {
result = 1;
}
}
return result;
}
static int
set_configured_link_state(ocs_t *ocs, char *name, char *value)
{
int result = 0;
int xport_rc;
if (ocs_strcasecmp(value, "offline") == 0) {
ocs_log_debug(ocs, "Setting port to %s\n", value);
xport_rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_OFFLINE);
if (xport_rc != 0) {
ocs_log_test(ocs, "Setting port to offline failed\n");
result = -1;
}
} else if (ocs_strcasecmp(value, "online") == 0) {
ocs_log_debug(ocs, "Setting port to %s\n", value);
xport_rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_ONLINE);
if (xport_rc != 0) {
ocs_log_test(ocs, "Setting port to online failed\n");
result = -1;
}
} else {
ocs_log_test(ocs, "Unsupported link state \"%s\"\n", value);
result = -1;
}
return result;
}
typedef struct ocs_mgmt_get_port_protocol_result {
ocs_sem_t semaphore;
int32_t status;
ocs_hw_port_protocol_e port_protocol;
} ocs_mgmt_get_port_protocol_result_t;
static void
ocs_mgmt_get_port_protocol_cb(int32_t status,
ocs_hw_port_protocol_e port_protocol,
void *arg)
{
ocs_mgmt_get_port_protocol_result_t *result = arg;
result->status = status;
result->port_protocol = port_protocol;
ocs_sem_v(&(result->semaphore));
}
static void
get_port_protocol(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_mgmt_get_port_protocol_result_t result;
uint8_t bus;
uint8_t dev;
uint8_t func;
ocs_sem_init(&(result.semaphore), 0, "get_port_protocol");
ocs_get_bus_dev_func(ocs, &bus, &dev, &func);
if(ocs_hw_get_port_protocol(&ocs->hw, func, ocs_mgmt_get_port_protocol_cb, &result) == OCS_HW_RTN_SUCCESS) {
if (ocs_sem_p(&(result.semaphore), OCS_SEM_FOREVER) != 0) {
ocs_log_err(ocs, "ocs_sem_p failed\n");
}
if (result.status == 0) {
switch (result.port_protocol) {
case OCS_HW_PORT_PROTOCOL_ISCSI:
ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "port_protocol", "iSCSI");
break;
case OCS_HW_PORT_PROTOCOL_FCOE:
ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "port_protocol", "FCoE");
break;
case OCS_HW_PORT_PROTOCOL_FC:
ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "port_protocol", "FC");
break;
case OCS_HW_PORT_PROTOCOL_OTHER:
ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "port_protocol", "Other");
break;
}
} else {
ocs_log_test(ocs, "getting port profile status 0x%x\n", result.status);
ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "port_protocol", "Unknown");
}
}
}
typedef struct ocs_mgmt_set_port_protocol_result {
ocs_sem_t semaphore;
int32_t status;
} ocs_mgmt_set_port_protocol_result_t;
static void
ocs_mgmt_set_port_protocol_cb(int32_t status,
void *arg)
{
ocs_mgmt_get_port_protocol_result_t *result = arg;
result->status = status;
ocs_sem_v(&(result->semaphore));
}
static int32_t
set_port_protocol(ocs_t *ocs, char *name, char *value)
{
ocs_mgmt_set_port_protocol_result_t result;
int32_t rc = 0;
ocs_hw_port_protocol_e new_protocol;
uint8_t bus;
uint8_t dev;
uint8_t func;
ocs_get_bus_dev_func(ocs, &bus, &dev, &func);
ocs_sem_init(&(result.semaphore), 0, "set_port_protocol");
if (ocs_strcasecmp(value, "iscsi") == 0) {
new_protocol = OCS_HW_PORT_PROTOCOL_ISCSI;
} else if (ocs_strcasecmp(value, "fc") == 0) {
new_protocol = OCS_HW_PORT_PROTOCOL_FC;
} else if (ocs_strcasecmp(value, "fcoe") == 0) {
new_protocol = OCS_HW_PORT_PROTOCOL_FCOE;
} else {
return -1;
}
rc = ocs_hw_set_port_protocol(&ocs->hw, new_protocol, func,
ocs_mgmt_set_port_protocol_cb, &result);
if (rc == OCS_HW_RTN_SUCCESS) {
if (ocs_sem_p(&(result.semaphore), OCS_SEM_FOREVER) != 0) {
ocs_log_err(ocs, "ocs_sem_p failed\n");
return -ENXIO;
}
if (result.status == 0) {
rc = 0;
} else {
rc = -1;
ocs_log_test(ocs, "setting active profile status 0x%x\n",
result.status);
}
}
return rc;
}
typedef struct ocs_mgmt_get_profile_list_result_s {
ocs_sem_t semaphore;
int32_t status;
ocs_hw_profile_list_t *list;
} ocs_mgmt_get_profile_list_result_t;
static void
ocs_mgmt_get_profile_list_cb(int32_t status, ocs_hw_profile_list_t *list, void *ul_arg)
{
ocs_mgmt_get_profile_list_result_t *result = ul_arg;
result->status = status;
result->list = list;
ocs_sem_v(&(result->semaphore));
}
static void
get_profile_list(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
ocs_mgmt_get_profile_list_result_t result;
ocs_sem_init(&(result.semaphore), 0, "get_profile_list");
if(ocs_hw_get_profile_list(&ocs->hw, ocs_mgmt_get_profile_list_cb, &result) == OCS_HW_RTN_SUCCESS) {
if (ocs_sem_p(&(result.semaphore), OCS_SEM_FOREVER) != 0) {
ocs_log_err(ocs, "ocs_sem_p failed\n");
}
if (result.status == 0) {
#define MAX_LINE_SIZE 520
#define BUFFER_SIZE MAX_LINE_SIZE*40
char *result_buf;
char result_line[MAX_LINE_SIZE];
uint32_t bytes_left;
uint32_t i;
result_buf = ocs_malloc(ocs, BUFFER_SIZE, OCS_M_ZERO);
bytes_left = BUFFER_SIZE;
for (i = 0; i < result.list->num_descriptors; i++) {
sprintf(result_line, "0x%02x:%s\n", result.list->descriptors[i].profile_id,
result.list->descriptors[i].profile_description);
if (strlen(result_line) < bytes_left) {
strcat(result_buf, result_line);
bytes_left -= strlen(result_line);
}
}
ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "profile_list", result_buf);
ocs_free(ocs, result_buf, BUFFER_SIZE);
ocs_free(ocs, result.list, sizeof(ocs_hw_profile_list_t));
} else {
ocs_log_test(ocs, "getting profile list status 0x%x\n", result.status);
}
}
}
typedef struct ocs_mgmt_get_active_profile_result {
ocs_sem_t semaphore;
int32_t status;
uint32_t active_profile_id;
} ocs_mgmt_get_active_profile_result_t;
static void
ocs_mgmt_get_active_profile_cb(int32_t status, uint32_t active_profile, void *ul_arg)
{
ocs_mgmt_get_active_profile_result_t *result = ul_arg;
result->status = status;
result->active_profile_id = active_profile;
ocs_sem_v(&(result->semaphore));
}
#define MAX_PROFILE_LENGTH 5
static void
get_active_profile(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
char result_string[MAX_PROFILE_LENGTH];
ocs_mgmt_get_active_profile_result_t result;
ocs_sem_init(&(result.semaphore), 0, "get_active_profile");
if(ocs_hw_get_active_profile(&ocs->hw, ocs_mgmt_get_active_profile_cb, &result) == OCS_HW_RTN_SUCCESS) {
if (ocs_sem_p(&(result.semaphore), OCS_SEM_FOREVER) != 0) {
ocs_log_err(ocs, "ocs_sem_p failed\n");
}
if (result.status == 0) {
sprintf(result_string, "0x%02x", result.active_profile_id);
ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "active_profile", result_string);
} else {
ocs_log_test(ocs, "getting active profile status 0x%x\n", result.status);
}
}
}
typedef struct ocs_mgmt_set_active_profile_result {
ocs_sem_t semaphore;
int32_t status;
} ocs_mgmt_set_active_profile_result_t;
static void
ocs_mgmt_set_active_profile_cb(int32_t status, void *ul_arg)
{
ocs_mgmt_get_profile_list_result_t *result = ul_arg;
result->status = status;
ocs_sem_v(&(result->semaphore));
}
static int32_t
set_active_profile(ocs_t *ocs, char *name, char *value)
{
ocs_mgmt_set_active_profile_result_t result;
int32_t rc = 0;
int32_t new_profile;
new_profile = ocs_strtoul(value, NULL, 0);
ocs_sem_init(&(result.semaphore), 0, "set_active_profile");
rc = ocs_hw_set_active_profile(&ocs->hw, ocs_mgmt_set_active_profile_cb, new_profile, &result);
if (rc == OCS_HW_RTN_SUCCESS) {
if (ocs_sem_p(&(result.semaphore), OCS_SEM_FOREVER) != 0) {
ocs_log_err(ocs, "ocs_sem_p failed\n");
return -ENXIO;
}
if (result.status == 0) {
rc = 0;
} else {
rc = -1;
ocs_log_test(ocs, "setting active profile status 0x%x\n", result.status);
}
}
return rc;
}
typedef struct ocs_mgmt_get_nvparms_result {
ocs_sem_t semaphore;
int32_t status;
uint8_t wwpn[8];
uint8_t wwnn[8];
uint8_t hard_alpa;
uint32_t preferred_d_id;
} ocs_mgmt_get_nvparms_result_t;
static void
ocs_mgmt_get_nvparms_cb(int32_t status, uint8_t *wwpn, uint8_t *wwnn, uint8_t hard_alpa,
uint32_t preferred_d_id, void *ul_arg)
{
ocs_mgmt_get_nvparms_result_t *result = ul_arg;
result->status = status;
ocs_memcpy(result->wwpn, wwpn, sizeof(result->wwpn));
ocs_memcpy(result->wwnn, wwnn, sizeof(result->wwnn));
result->hard_alpa = hard_alpa;
result->preferred_d_id = preferred_d_id;
ocs_sem_v(&(result->semaphore));
}
static void
get_nv_wwpn(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
char result_string[24];
ocs_mgmt_get_nvparms_result_t result;
ocs_sem_init(&(result.semaphore), 0, "get_nv_wwpn");
if(ocs_hw_get_nvparms(&ocs->hw, ocs_mgmt_get_nvparms_cb, &result) == OCS_HW_RTN_SUCCESS) {
if (ocs_sem_p(&(result.semaphore), OCS_SEM_FOREVER) != 0) {
ocs_log_err(ocs, "ocs_sem_p failed\n");
return;
}
if (result.status == 0) {
sprintf(result_string, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
result.wwpn[0], result.wwpn[1], result.wwpn[2],
result.wwpn[3], result.wwpn[4], result.wwpn[5],
result.wwpn[6], result.wwpn[7]);
ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "nv_wwpn", result_string);
} else {
ocs_log_test(ocs, "getting wwpn status 0x%x\n", result.status);
}
}
}
static void
get_nv_wwnn(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
char result_string[24];
ocs_mgmt_get_nvparms_result_t result;
ocs_sem_init(&(result.semaphore), 0, "get_nv_wwnn");
if(ocs_hw_get_nvparms(&ocs->hw, ocs_mgmt_get_nvparms_cb, &result) == OCS_HW_RTN_SUCCESS) {
if (ocs_sem_p(&(result.semaphore), OCS_SEM_FOREVER) != 0) {
ocs_log_err(ocs, "ocs_sem_p failed\n");
return;
}
if (result.status == 0) {
ocs_snprintf(result_string, sizeof(result_string), "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
result.wwnn[0], result.wwnn[1], result.wwnn[2],
result.wwnn[3], result.wwnn[4], result.wwnn[5],
result.wwnn[6], result.wwnn[7]);
ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "nv_wwnn", result_string);
} else {
ocs_log_test(ocs, "getting wwnn status 0x%x\n", result.status);
}
}
}
static void
get_node_abort_cnt(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
{
uint32_t abort_counts = 0;
ocs_domain_t *domain;
ocs_sport_t *sport;
ocs_node_t *node;
if (ocs_device_lock_try(ocs) != TRUE) {
return;
}
ocs_list_foreach(&ocs->domain_list, domain) {
if (ocs_domain_lock_try(domain) != TRUE) {
ocs_device_unlock(ocs);
return;
}
ocs_list_foreach(&domain->sport_list, sport) {
if (ocs_sport_lock_try(sport) != TRUE) {
ocs_domain_unlock(domain);
ocs_device_unlock(ocs);
return;
}
ocs_list_foreach(&sport->node_list, node) {
abort_counts += node->abort_cnt;
}
ocs_sport_unlock(sport);
}
ocs_domain_unlock(domain);
}
ocs_device_unlock(ocs);
ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "node_abort_cnt", "%d" , abort_counts);
}
typedef struct ocs_mgmt_set_nvparms_result {
ocs_sem_t semaphore;
int32_t status;
} ocs_mgmt_set_nvparms_result_t;
static void
ocs_mgmt_set_nvparms_cb(int32_t status, void *ul_arg)
{
ocs_mgmt_get_profile_list_result_t *result = ul_arg;
result->status = status;
ocs_sem_v(&(result->semaphore));
}
static int32_t
set_nv_wwn(ocs_t *ocs, char *name, char *wwn_p)
{
ocs_mgmt_get_nvparms_result_t result;
uint8_t new_wwpn[8];
uint8_t new_wwnn[8];
char *wwpn_p = NULL;
char *wwnn_p = NULL;
int32_t rc = -1;
int wwpn = 0;
int wwnn = 0;
int i;
ocs_sem_init(&(result.semaphore), 0, "set_nv_wwn1");
rc = ocs_hw_get_nvparms(&ocs->hw, ocs_mgmt_get_nvparms_cb, &result);
if (rc == OCS_HW_RTN_SUCCESS) {
if (ocs_sem_p(&(result.semaphore), OCS_SEM_FOREVER) != 0) {
ocs_log_err(ocs, "ocs_sem_p failed\n");
return -ENXIO;
}
if (result.status != 0) {
ocs_log_test(ocs, "getting nvparms status 0x%x\n", result.status);
return -1;
}
}
if (wwn_p != NULL) {
wwpn_p = ocs_strsep(&wwn_p, "@");
wwnn_p = wwn_p;
}
if (wwpn_p != NULL) {
wwpn = ocs_strcmp(wwpn_p, "NA");
}
if (wwnn_p != NULL) {
wwnn = ocs_strcmp(wwnn_p, "NA");
}
if ((wwpn_p != NULL) && (wwpn != 0)) {
if (ocs_sscanf(wwpn_p, "%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx",
&(new_wwpn[0]), &(new_wwpn[1]), &(new_wwpn[2]),
&(new_wwpn[3]), &(new_wwpn[4]), &(new_wwpn[5]),
&(new_wwpn[6]), &(new_wwpn[7])) != 8) {
ocs_log_test(ocs, "can't parse WWPN %s\n", wwpn_p);
return -1;
}
}
if ((wwnn_p != NULL) && (wwnn != 0 )) {
if (ocs_sscanf(wwnn_p, "%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx",
&(new_wwnn[0]), &(new_wwnn[1]), &(new_wwnn[2]),
&(new_wwnn[3]), &(new_wwnn[4]), &(new_wwnn[5]),
&(new_wwnn[6]), &(new_wwnn[7])) != 8) {
ocs_log_test(ocs, "can't parse WWNN %s\n", wwnn_p);
return -1;
}
}
for (i = 0; i < 8; i++) {
if (wwpn == 0) {
new_wwpn[i] = result.wwpn[i];
}
if (wwnn == 0) {
new_wwnn[i] = result.wwnn[i];
}
}
ocs_sem_init(&(result.semaphore), 0, "set_nv_wwn2");
rc = ocs_hw_set_nvparms(&ocs->hw, ocs_mgmt_set_nvparms_cb, new_wwpn,
new_wwnn, result.hard_alpa, result.preferred_d_id,
&result);
if (rc == OCS_HW_RTN_SUCCESS) {
if (ocs_sem_p(&(result.semaphore), OCS_SEM_FOREVER) != 0) {
ocs_log_err(ocs, "ocs_sem_p failed\n");
return -ENXIO;
}
if (result.status != 0) {
ocs_log_test(ocs, "setting wwn status 0x%x\n", result.status);
return -1;
}
}
return rc;
}
static int
set_tgt_rscn_delay(ocs_t *ocs, char *name, char *value)
{
ocs->tgt_rscn_delay_msec = ocs_strtoul(value, NULL, 0) * 1000;
ocs_log_debug(ocs, "mgmt set: %s %s\n", name, value);
return 0;
}
static int
set_tgt_rscn_period(ocs_t *ocs, char *name, char *value)
{
ocs->tgt_rscn_period_msec = ocs_strtoul(value, NULL, 0) * 1000;
ocs_log_debug(ocs, "mgmt set: %s %s\n", name, value);
return 0;
}
static int
set_inject_drop_cmd(ocs_t *ocs, char *name, char *value)
{
ocs->err_injection = (ocs_strtoul(value, NULL, 0) == 0 ? NO_ERR_INJECT : INJECT_DROP_CMD);
ocs_log_debug(ocs, "mgmt set: %s %s\n", name, value);
return 0;
}
static int
set_inject_free_drop_cmd(ocs_t *ocs, char *name, char *value)
{
ocs->err_injection = (ocs_strtoul(value, NULL, 0) == 0 ? NO_ERR_INJECT : INJECT_FREE_DROPPED);
ocs_log_debug(ocs, "mgmt set: %s %s\n", name, value);
return 0;
}
static int
set_inject_drop_data(ocs_t *ocs, char *name, char *value)
{
ocs->err_injection = (ocs_strtoul(value, NULL, 0) == 0 ? NO_ERR_INJECT : INJECT_DROP_DATA);
ocs_log_debug(ocs, "mgmt set: %s %s\n", name, value);
return 0;
}
static int
set_inject_drop_resp(ocs_t *ocs, char *name, char *value)
{
ocs->err_injection = (ocs_strtoul(value, NULL, 0) == 0 ? NO_ERR_INJECT : INJECT_DROP_RESP);
ocs_log_debug(ocs, "mgmt set: %s %s\n", name, value);
return 0;
}
static int
set_cmd_err_inject(ocs_t *ocs, char *name, char *value)
{
ocs->cmd_err_inject = ocs_strtoul(value, NULL, 0);
ocs_log_debug(ocs, "mgmt set: %s %s\n", name, value);
return 0;
}
static int
set_cmd_delay_value(ocs_t *ocs, char *name, char *value)
{
ocs->delay_value_msec = ocs_strtoul(value, NULL, 0);
ocs->err_injection = (ocs->delay_value_msec == 0 ? NO_ERR_INJECT : INJECT_DELAY_CMD);
ocs_log_debug(ocs, "mgmt set: %s %s\n", name, value);
return 0;
}
int
parse_wwn(char *wwn_in, uint64_t *wwn_out)
{
uint8_t byte0;
uint8_t byte1;
uint8_t byte2;
uint8_t byte3;
uint8_t byte4;
uint8_t byte5;
uint8_t byte6;
uint8_t byte7;
int rc;
rc = ocs_sscanf(wwn_in, "0x%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx",
&byte0, &byte1, &byte2, &byte3,
&byte4, &byte5, &byte6, &byte7);
if (rc == 8) {
*wwn_out = ((uint64_t)byte0 << 56) |
((uint64_t)byte1 << 48) |
((uint64_t)byte2 << 40) |
((uint64_t)byte3 << 32) |
((uint64_t)byte4 << 24) |
((uint64_t)byte5 << 16) |
((uint64_t)byte6 << 8) |
((uint64_t)byte7);
return 0;
} else {
return 1;
}
}
static char *mode_string(int mode);
extern void ocs_mgmt_start_section(ocs_textbuf_t *textbuf, const char *name, int index)
{
ocs_textbuf_printf(textbuf, "<%s instance=\"%d\">\n", name, index);
}
extern void ocs_mgmt_start_unnumbered_section(ocs_textbuf_t *textbuf, const char *name)
{
ocs_textbuf_printf(textbuf, "<%s>\n", name);
}
void ocs_mgmt_end_unnumbered_section(ocs_textbuf_t *textbuf, const char *name)
{
ocs_textbuf_printf(textbuf, "</%s>\n", name);
}
void ocs_mgmt_end_section(ocs_textbuf_t *textbuf, const char *name, int index)
{
ocs_textbuf_printf(textbuf, "</%s>\n", name);
}
void ocs_mgmt_emit_property_name(ocs_textbuf_t *textbuf, int mode, const char *name)
{
ocs_textbuf_printf(textbuf, "<%s mode=\"%s\"/>\n", name, mode_string(mode));
}
void ocs_mgmt_emit_string(ocs_textbuf_t *textbuf, int mode, const char *name, const char *value)
{
ocs_textbuf_printf(textbuf, "<%s mode=\"%s\">%s</%s>\n", name, mode_string(mode), value, name);
}
void ocs_mgmt_emit_int(ocs_textbuf_t *textbuf, int mode, const char *name, const char *fmt, ...)
{
va_list ap;
char valuebuf[64];
va_start(ap, fmt);
ocs_vsnprintf(valuebuf, sizeof(valuebuf), fmt, ap);
va_end(ap);
ocs_textbuf_printf(textbuf, "<%s mode=\"%s\">%s</%s>\n", name, mode_string(mode), valuebuf, name);
}
void ocs_mgmt_emit_boolean(ocs_textbuf_t *textbuf, int mode, const char *name, int value)
{
char *valuebuf = value ? "true" : "false";
ocs_textbuf_printf(textbuf, "<%s mode=\"%s\">%s</%s>\n", name, mode_string(mode), valuebuf, name);
}
static char *mode_string(int mode)
{
static char mode_str[4];
mode_str[0] = '\0';
if (mode & MGMT_MODE_RD) {
strcat(mode_str, "r");
}
if (mode & MGMT_MODE_WR) {
strcat(mode_str, "w");
}
if (mode & MGMT_MODE_EX) {
strcat(mode_str, "x");
}
return mode_str;
}