2 * Copyright (c) 2017 Broadcom. All rights reserved.
3 * The term "Broadcom" refers to Broadcom Limited and/or its subsidiaries.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
15 * 3. Neither the name of the copyright holder nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
36 * The ocs_mgmt top level functions for Fibre Channel.
40 * @defgroup mgmt Management Functions
45 #include "ocs_gendump.h"
48 #define SFP_PAGE_SIZE 128
52 static int ocs_mgmt_firmware_write(ocs_t *ocs, char *, void *buf, uint32_t buf_len, void*, uint32_t);
53 static int ocs_mgmt_firmware_reset(ocs_t *ocs, char *, void *buf, uint32_t buf_len, void*, uint32_t);
54 static int ocs_mgmt_function_reset(ocs_t *ocs, char *, void *buf, uint32_t buf_len, void*, uint32_t);
56 static void ocs_mgmt_fw_write_cb(int32_t status, uint32_t actual_write_length, uint32_t change_status, void *arg);
57 static int ocs_mgmt_force_assert(ocs_t *ocs, char *, void *buf, uint32_t buf_len, void*, uint32_t);
61 static void get_nodes_count(ocs_t *, char *, ocs_textbuf_t*);
62 static void get_desc(ocs_t *, char *, ocs_textbuf_t*);
63 static void get_fw_rev(ocs_t *, char *, ocs_textbuf_t*);
64 static void get_fw_rev2(ocs_t *, char *, ocs_textbuf_t*);
65 static void get_ipl(ocs_t *, char *, ocs_textbuf_t*);
66 static void get_wwnn(ocs_t *, char *, ocs_textbuf_t*);
67 static void get_wwpn(ocs_t *, char *, ocs_textbuf_t*);
68 static void get_fcid(ocs_t *, char *, ocs_textbuf_t *);
69 static void get_sn(ocs_t *, char *, ocs_textbuf_t*);
70 static void get_pn(ocs_t *, char *, ocs_textbuf_t*);
71 static void get_sli4_intf_reg(ocs_t *, char *, ocs_textbuf_t*);
72 static void get_phy_port_num(ocs_t *, char *, ocs_textbuf_t*);
73 static void get_asic_id(ocs_t *, char *, ocs_textbuf_t*);
74 static void get_pci_vendor(ocs_t *, char *, ocs_textbuf_t*);
75 static void get_pci_device(ocs_t *, char *, ocs_textbuf_t*);
76 static void get_pci_subsystem_vendor(ocs_t *, char *, ocs_textbuf_t*);
77 static void get_pci_subsystem_device(ocs_t *, char *, ocs_textbuf_t*);
78 static void get_businfo(ocs_t *, char *, ocs_textbuf_t*);
79 static void get_sfp_a0(ocs_t *, char *, ocs_textbuf_t*);
80 static void get_sfp_a2(ocs_t *, char *, ocs_textbuf_t*);
81 static void get_hw_rev1(ocs_t *, char *, ocs_textbuf_t*);
82 static void get_hw_rev2(ocs_t *, char *, ocs_textbuf_t*);
83 static void get_hw_rev3(ocs_t *, char *, ocs_textbuf_t*);
84 static void get_debug_mq_dump(ocs_t*, char*, ocs_textbuf_t*);
85 static void get_debug_cq_dump(ocs_t*, char*, ocs_textbuf_t*);
86 static void get_debug_wq_dump(ocs_t*, char*, ocs_textbuf_t*);
87 static void get_debug_eq_dump(ocs_t*, char*, ocs_textbuf_t*);
88 static void get_logmask(ocs_t*, char*, ocs_textbuf_t*);
89 static void get_current_speed(ocs_t*, char*, ocs_textbuf_t*);
90 static void get_current_topology(ocs_t*, char*, ocs_textbuf_t*);
91 static void get_current_link_state(ocs_t*, char*, ocs_textbuf_t*);
92 static void get_configured_speed(ocs_t*, char*, ocs_textbuf_t*);
93 static void get_configured_topology(ocs_t*, char*, ocs_textbuf_t*);
94 static void get_configured_link_state(ocs_t*, char*, ocs_textbuf_t*);
95 static void get_linkcfg(ocs_t*, char*, ocs_textbuf_t*);
96 static void get_req_wwnn(ocs_t*, char*, ocs_textbuf_t*);
97 static void get_req_wwpn(ocs_t*, char*, ocs_textbuf_t*);
98 static void get_nodedb_mask(ocs_t*, char*, ocs_textbuf_t*);
99 static void get_profile_list(ocs_t*, char*, ocs_textbuf_t*);
100 static void get_active_profile(ocs_t*, char*, ocs_textbuf_t*);
101 static void get_port_protocol(ocs_t*, char*, ocs_textbuf_t*);
102 static void get_driver_version(ocs_t*, char*, ocs_textbuf_t*);
103 static void get_chip_type(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
104 static void get_tgt_rscn_delay(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
105 static void get_tgt_rscn_period(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
106 static void get_inject_drop_cmd(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
107 static void get_inject_free_drop_cmd(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
108 static void get_inject_drop_data(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
109 static void get_inject_drop_resp(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
110 static void get_cmd_err_inject(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
111 static void get_cmd_delay_value(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
112 static void get_nv_wwpn(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
113 static void get_nv_wwnn(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
114 static void get_loglevel(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
115 static void get_node_abort_cnt(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
118 static int set_debug_mq_dump(ocs_t*, char*, char*);
119 static int set_debug_cq_dump(ocs_t*, char*, char*);
120 static int set_debug_wq_dump(ocs_t*, char*, char*);
121 static int set_debug_eq_dump(ocs_t*, char*, char*);
122 static int set_logmask(ocs_t*, char*, char*);
123 static int set_configured_link_state(ocs_t*, char*, char*);
124 static int set_linkcfg(ocs_t*, char*, char*);
125 static int set_nodedb_mask(ocs_t*, char*, char*);
126 static int set_port_protocol(ocs_t*, char*, char*);
127 static int set_active_profile(ocs_t*, char*, char*);
128 static int set_tgt_rscn_delay(ocs_t*, char*, char*);
129 static int set_tgt_rscn_period(ocs_t*, char*, char*);
130 static int set_inject_drop_cmd(ocs_t*, char*, char*);
131 static int set_inject_free_drop_cmd(ocs_t*, char*, char*);
132 static int set_inject_drop_data(ocs_t*, char*, char*);
133 static int set_inject_drop_resp(ocs_t*, char*, char*);
134 static int set_cmd_err_inject(ocs_t*, char*, char*);
135 static int set_cmd_delay_value(ocs_t*, char*, char*);
136 static int set_nv_wwn(ocs_t*, char*, char*);
137 static int set_loglevel(ocs_t*, char*, char*);
139 static void ocs_mgmt_linkcfg_cb(int32_t status, uintptr_t value, void *arg);
141 ocs_mgmt_table_entry_t mgmt_table[] = {
142 {"nodes_count", get_nodes_count, NULL, NULL},
143 {"desc", get_desc, NULL, NULL},
144 {"fw_rev", get_fw_rev, NULL, NULL},
145 {"fw_rev2", get_fw_rev2, NULL, NULL},
146 {"ipl", get_ipl, NULL, NULL},
147 {"hw_rev1", get_hw_rev1, NULL, NULL},
148 {"hw_rev2", get_hw_rev2, NULL, NULL},
149 {"hw_rev3", get_hw_rev3, NULL, NULL},
150 {"wwnn", get_wwnn, NULL, NULL},
151 {"wwpn", get_wwpn, NULL, NULL},
152 {"fc_id", get_fcid, NULL, NULL},
153 {"sn", get_sn, NULL, NULL},
154 {"pn", get_pn, NULL, NULL},
155 {"sli4_intf_reg", get_sli4_intf_reg, NULL, NULL},
156 {"phy_port_num", get_phy_port_num, NULL, NULL},
157 {"asic_id_reg", get_asic_id, NULL, NULL},
158 {"pci_vendor", get_pci_vendor, NULL, NULL},
159 {"pci_device", get_pci_device, NULL, NULL},
160 {"pci_subsystem_vendor", get_pci_subsystem_vendor, NULL, NULL},
161 {"pci_subsystem_device", get_pci_subsystem_device, NULL, NULL},
162 {"businfo", get_businfo, NULL, NULL},
163 {"sfp_a0", get_sfp_a0, NULL, NULL},
164 {"sfp_a2", get_sfp_a2, NULL, NULL},
165 {"profile_list", get_profile_list, NULL, NULL},
166 {"driver_version", get_driver_version, NULL, NULL},
167 {"current_speed", get_current_speed, NULL, NULL},
168 {"current_topology", get_current_topology, NULL, NULL},
169 {"current_link_state", get_current_link_state, NULL, NULL},
170 {"chip_type", get_chip_type, NULL, NULL},
171 {"configured_speed", get_configured_speed, set_configured_speed, NULL},
172 {"configured_topology", get_configured_topology, set_configured_topology, NULL},
173 {"configured_link_state", get_configured_link_state, set_configured_link_state, NULL},
174 {"debug_mq_dump", get_debug_mq_dump, set_debug_mq_dump, NULL},
175 {"debug_cq_dump", get_debug_cq_dump, set_debug_cq_dump, NULL},
176 {"debug_wq_dump", get_debug_wq_dump, set_debug_wq_dump, NULL},
177 {"debug_eq_dump", get_debug_eq_dump, set_debug_eq_dump, NULL},
178 {"logmask", get_logmask, set_logmask, NULL},
179 {"loglevel", get_loglevel, set_loglevel, NULL},
180 {"linkcfg", get_linkcfg, set_linkcfg, NULL},
181 {"requested_wwnn", get_req_wwnn, set_req_wwnn, NULL},
182 {"requested_wwpn", get_req_wwpn, set_req_wwpn, NULL},
183 {"nodedb_mask", get_nodedb_mask, set_nodedb_mask, NULL},
184 {"port_protocol", get_port_protocol, set_port_protocol, NULL},
185 {"active_profile", get_active_profile, set_active_profile, NULL},
186 {"firmware_write", NULL, NULL, ocs_mgmt_firmware_write},
187 {"firmware_reset", NULL, NULL, ocs_mgmt_firmware_reset},
188 {"function_reset", NULL, NULL, ocs_mgmt_function_reset},
189 {"force_assert", NULL, NULL, ocs_mgmt_force_assert},
191 {"tgt_rscn_delay", get_tgt_rscn_delay, set_tgt_rscn_delay, NULL},
192 {"tgt_rscn_period", get_tgt_rscn_period, set_tgt_rscn_period, NULL},
193 {"inject_drop_cmd", get_inject_drop_cmd, set_inject_drop_cmd, NULL},
194 {"inject_free_drop_cmd", get_inject_free_drop_cmd, set_inject_free_drop_cmd, NULL},
195 {"inject_drop_data", get_inject_drop_data, set_inject_drop_data, NULL},
196 {"inject_drop_resp", get_inject_drop_resp, set_inject_drop_resp, NULL},
197 {"cmd_err_inject", get_cmd_err_inject, set_cmd_err_inject, NULL},
198 {"cmd_delay_value", get_cmd_delay_value, set_cmd_delay_value, NULL},
199 {"nv_wwpn", get_nv_wwpn, NULL, NULL},
200 {"nv_wwnn", get_nv_wwnn, NULL, NULL},
201 {"nv_wwn", NULL, set_nv_wwn, NULL},
202 {"node_abort_cnt", get_node_abort_cnt, NULL, NULL},
207 * @brief Get a list of options supported by the driver.
210 * This is the top level "get list" handler for the driver. It
211 * performs the following:
212 * - Adds entries to the textbuf for any actions supported by this level in the driver.
213 * - Calls a back-end function to add any actions supported by the back-end.
214 * - Calls a function on each child (domain) to recursively add supported actions.
216 * @param ocs Pointer to the ocs structure.
217 * @param textbuf Pointer to an ocs_textbuf, which is used to accumulate the results.
219 * @return Returns 0 on success, or a negative value on failure.
223 ocs_mgmt_get_list(ocs_t *ocs, ocs_textbuf_t *textbuf)
225 ocs_domain_t *domain;
229 ocs_mgmt_start_unnumbered_section(textbuf, "ocs");
231 for (i=0;i<ARRAY_SIZE(mgmt_table);i++) {
233 if (mgmt_table[i].get_handler) {
234 access |= MGMT_MODE_RD;
236 if (mgmt_table[i].set_handler) {
237 access |= MGMT_MODE_WR;
239 if (mgmt_table[i].action_handler) {
240 access |= MGMT_MODE_EX;
242 ocs_mgmt_emit_property_name(textbuf, access, mgmt_table[i].name);
245 if ((ocs->mgmt_functions) && (ocs->mgmt_functions->get_list_handler)) {
246 ocs->mgmt_functions->get_list_handler(textbuf, ocs);
249 if ((ocs->tgt_mgmt_functions) && (ocs->tgt_mgmt_functions->get_list_handler)) {
250 ocs->tgt_mgmt_functions->get_list_handler(textbuf, &(ocs->tgt_ocs));
253 /* Have each of my children add their actions */
254 if (ocs_device_lock_try(ocs) == TRUE) {
255 /* If we get here then we are holding the device lock */
256 ocs_list_foreach(&ocs->domain_list, domain) {
257 if ((domain->mgmt_functions) && (domain->mgmt_functions->get_list_handler)) {
258 domain->mgmt_functions->get_list_handler(textbuf, domain);
261 ocs_device_unlock(ocs);
264 ocs_mgmt_end_unnumbered_section(textbuf, "ocs");
270 * @brief Return the value of a management item.
273 * This is the top level "get" handler for the driver. It
274 * performs the following:
275 * - Checks that the qualifier portion of the name begins with my qualifier (ocs).
276 * - If the remaining part of the name matches a parameter that is known at this level,
277 * writes the value into textbuf.
278 * - If the name is not known, sends the request to the back-ends to fulfill (if possible).
279 * - If the request has not been fulfilled by the back-end,
280 * passes the request to each of the children (domains) to
281 * have them (recursively) try to respond.
283 * In passing the request to other entities, the request is considered to be answered
284 * when a response has been written into textbuf, indicated by textbuf->buffer_written
287 * @param ocs Pointer to the ocs structure.
288 * @param name Name of the status item to be retrieved.
289 * @param textbuf Pointer to an ocs_textbuf, which is used to return the results.
291 * @return Returns 0 if the value was found and returned, or -1 if an error occurred.
295 ocs_mgmt_get(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
297 ocs_domain_t *domain;
302 ocs_mgmt_start_unnumbered_section(textbuf, "ocs");
304 snprintf(qualifier, sizeof(qualifier), "/ocs");
306 /* See if the name starts with my qualifier. If not then this request isn't for me */
307 if (ocs_strncmp(name, qualifier, strlen(qualifier)) == 0) {
308 char *unqualified_name = name + strlen(qualifier) + 1;
310 for (i=0;i<ARRAY_SIZE(mgmt_table);i++) {
311 if (ocs_strcmp(unqualified_name, mgmt_table[i].name) == 0) {
312 if (mgmt_table[i].get_handler) {
313 mgmt_table[i].get_handler(ocs, name, textbuf);
314 ocs_mgmt_end_unnumbered_section(textbuf, "ocs");
320 if ((ocs->mgmt_functions) && (ocs->mgmt_functions->get_handler)) {
321 retval = ocs->mgmt_functions->get_handler(textbuf, qualifier, (char*)name, ocs);
325 if ((ocs->tgt_mgmt_functions) && (ocs->tgt_mgmt_functions->get_handler)) {
326 retval = ocs->tgt_mgmt_functions->get_handler(textbuf, qualifier,
327 (char*)name, &(ocs->tgt_ocs));
332 /* The driver didn't handle it, pass it to each domain */
334 ocs_device_lock(ocs);
335 ocs_list_foreach(&ocs->domain_list, domain) {
336 if ((domain->mgmt_functions) && (domain->mgmt_functions->get_handler)) {
337 retval = domain->mgmt_functions->get_handler(textbuf, qualifier, (char*)name, domain);
344 ocs_device_unlock(ocs);
348 ocs_mgmt_end_unnumbered_section(textbuf, "ocs");
355 * @brief Set the value of a mgmt item.
358 * This is the top level "set" handler for the driver. It
359 * performs the following:
360 * - Checks that the qualifier portion of the name begins with my qualifier (ocs).
361 * - If the remaining part of the name matches a parameter that is known at this level,
362 * calls the correct function to change the configuration.
363 * - If the name is not known, sends the request to the back-ends to fulfill (if possible).
364 * - If the request has not been fulfilled by the back-end, passes the request to each of the
365 * children (domains) to have them (recursively) try to respond.
367 * In passing the request to other entities, the request is considered to be handled
368 * if the function returns 0.
370 * @param ocs Pointer to the ocs structure.
371 * @param name Name of the property to be changed.
372 * @param value Requested new value of the property.
374 * @return Returns 0 if the configuration value was updated, or -1 otherwise.
378 ocs_mgmt_set(ocs_t *ocs, char *name, char *value)
380 ocs_domain_t *domain;
385 snprintf(qualifier, sizeof(qualifier), "/ocs");
387 /* If it doesn't start with my qualifier I don't know what to do with it */
388 if (ocs_strncmp(name, qualifier, strlen(qualifier)) == 0) {
389 char *unqualified_name = name + strlen(qualifier) +1;
391 /* See if it's a value I can set */
392 for (i=0;i<ARRAY_SIZE(mgmt_table);i++) {
393 if (ocs_strcmp(unqualified_name, mgmt_table[i].name) == 0) {
394 if (mgmt_table[i].set_handler) {
395 return mgmt_table[i].set_handler(ocs, name, value);
400 if ((ocs->mgmt_functions) && (ocs->mgmt_functions->set_handler)) {
401 result = ocs->mgmt_functions->set_handler(qualifier, name, (char *)value, ocs);
405 if ((ocs->tgt_mgmt_functions) && (ocs->tgt_mgmt_functions->set_handler)) {
406 result = ocs->tgt_mgmt_functions->set_handler(qualifier, name,
407 (char *)value, &(ocs->tgt_ocs));
411 /* If I didn't know how to set this config value pass the request to each of my children */
413 ocs_device_lock(ocs);
414 ocs_list_foreach(&ocs->domain_list, domain) {
415 if ((domain->mgmt_functions) && (domain->mgmt_functions->set_handler)) {
416 result = domain->mgmt_functions->set_handler(qualifier, name, (char*)value, domain);
422 ocs_device_unlock(ocs);
431 * @brief Perform a management action.
434 * This is the top level "exec" handler for the driver. It
435 * performs the following:
436 * - Checks that the qualifier portion of the name begins with my qualifier (ocs).
437 * - If the remaining part of the name matches an action that is known at this level,
438 * calls the correct function to perform the action.
439 * - If the name is not known, sends the request to the back-ends to fulfill (if possible).
440 * - If the request has not been fulfilled by the back-end, passes the request to each of the
441 * children (domains) to have them (recursively) try to respond.
443 * In passing the request to other entities, the request is considered to be handled
444 * if the function returns 0.
446 * @param ocs Pointer to the ocs structure.
447 * @param action Name of the action to be performed.
448 * @param arg_in Pointer to an argument being passed to the action.
449 * @param arg_in_length Length of the argument pointed to by @c arg_in.
450 * @param arg_out Pointer to an argument being passed to the action.
451 * @param arg_out_length Length of the argument pointed to by @c arg_out.
453 * @return Returns 0 if the action was completed, or -1 otherwise.
459 ocs_mgmt_exec(ocs_t *ocs, char *action, void *arg_in,
460 uint32_t arg_in_length, void *arg_out, uint32_t arg_out_length)
462 ocs_domain_t *domain;
467 snprintf(qualifier, sizeof(qualifier), "/ocs");
469 /* If it doesn't start with my qualifier I don't know what to do with it */
470 if (ocs_strncmp(action, qualifier, strlen(qualifier)) == 0) {
471 char *unqualified_name = action + strlen(qualifier) +1;
473 /* See if it's an action I can perform */
474 for (i=0;i<ARRAY_SIZE(mgmt_table); i++) {
475 if (ocs_strcmp(unqualified_name, mgmt_table[i].name) == 0) {
476 if (mgmt_table[i].action_handler) {
477 return mgmt_table[i].action_handler(ocs, action, arg_in, arg_in_length,
478 arg_out, arg_out_length);
483 /* See if it's a value I can supply */
484 if (ocs_strcmp(unqualified_name, "driver/gendump") == 0) {
485 return ocs_gen_dump(ocs);
488 if (ocs_strcmp(unqualified_name, "driver/dump_to_host") == 0) {
489 return ocs_dump_to_host(ocs, arg_out, arg_out_length);
492 if ((ocs->mgmt_functions) && (ocs->mgmt_functions->exec_handler)) {
493 result = ocs->mgmt_functions->exec_handler(qualifier, action, arg_in, arg_in_length,
494 arg_out, arg_out_length, ocs);
498 if ((ocs->tgt_mgmt_functions) && (ocs->tgt_mgmt_functions->exec_handler)) {
499 result = ocs->tgt_mgmt_functions->exec_handler(qualifier, action,
500 arg_in, arg_in_length, arg_out, arg_out_length,
505 /* If I didn't know how to do this action pass the request to each of my children */
507 ocs_device_lock(ocs);
508 ocs_list_foreach(&ocs->domain_list, domain) {
509 if ((domain->mgmt_functions) && (domain->mgmt_functions->exec_handler)) {
510 result = domain->mgmt_functions->exec_handler(qualifier, action, arg_in, arg_in_length, arg_out,
511 arg_out_length, domain);
517 ocs_device_unlock(ocs);
525 ocs_mgmt_get_all(ocs_t *ocs, ocs_textbuf_t *textbuf)
527 ocs_domain_t *domain;
530 ocs_mgmt_start_unnumbered_section(textbuf, "ocs");
532 for (i=0;i<ARRAY_SIZE(mgmt_table);i++) {
533 if (mgmt_table[i].get_handler) {
534 mgmt_table[i].get_handler(ocs, mgmt_table[i].name, textbuf);
535 } else if (mgmt_table[i].action_handler) {
536 /* No get_handler, but there's an action_handler. Just report
538 ocs_mgmt_emit_property_name(textbuf, MGMT_MODE_EX, mgmt_table[i].name);
542 if ((ocs->mgmt_functions) && (ocs->mgmt_functions->get_all_handler)) {
543 ocs->mgmt_functions->get_all_handler(textbuf, ocs);
546 if ((ocs->tgt_mgmt_functions) && (ocs->tgt_mgmt_functions->get_all_handler)) {
547 ocs->tgt_mgmt_functions->get_all_handler(textbuf, &(ocs->tgt_ocs));
550 ocs_device_lock(ocs);
551 ocs_list_foreach(&ocs->domain_list, domain) {
552 if ((domain->mgmt_functions) && (domain->mgmt_functions->get_all_handler)) {
553 domain->mgmt_functions->get_all_handler(textbuf, domain);
556 ocs_device_unlock(ocs);
558 ocs_mgmt_end_unnumbered_section(textbuf, "ocs");
562 ocs_mgmt_firmware_reset(ocs_t *ocs, char *name, void *buf, uint32_t buf_len, void *arg_out, uint32_t arg_out_length)
566 uint8_t bus, dev, func;
569 ocs_get_bus_dev_func(ocs, &bus, &dev, &func);
571 ocs_log_debug(ocs, "Resetting port\n");
572 if (ocs_hw_reset(&ocs->hw, OCS_HW_RESET_FIRMWARE)) {
573 ocs_log_test(ocs, "failed to reset port\n");
576 ocs_log_debug(ocs, "successfully reset port\n");
578 /* now reset all functions on the same device */
580 while ((other_ocs = ocs_get_instance(index++)) != NULL) {
581 uint8_t other_bus, other_dev, other_func;
583 ocs_get_bus_dev_func(other_ocs, &other_bus, &other_dev, &other_func);
585 if ((bus == other_bus) && (dev == other_dev)) {
586 if (other_ocs->hw.state !=
587 OCS_HW_STATE_UNINITIALIZED) {
588 other_ocs->hw.state =
589 OCS_HW_STATE_QUEUES_ALLOCATED;
592 ocs_device_detach(other_ocs);
593 if (ocs_device_attach(other_ocs)) {
594 ocs_log_err(other_ocs,
595 "device %d attach failed \n", index);
605 ocs_mgmt_function_reset(ocs_t *ocs, char *name, void *buf, uint32_t buf_len, void *arg_out, uint32_t arg_out_length)
609 ocs_device_detach(ocs);
610 rc = ocs_device_attach(ocs);
616 ocs_mgmt_firmware_write(ocs_t *ocs, char *name, void *buf, uint32_t buf_len, void *arg_out, uint32_t arg_out_length)
625 ocs_mgmt_fw_write_result_t result;
626 uint32_t change_status = 0;
629 ocs_sem_init(&(result.semaphore), 0, "fw_write");
631 bytes_left = buf_len;
633 userp = (uint8_t *)buf;
635 if (ocs_dma_alloc(ocs, &dma, FW_WRITE_BUFSIZE, 4096)) {
636 ocs_log_err(ocs, "ocs_mgmt_firmware_write: malloc failed");
640 while (bytes_left > 0) {
641 if (bytes_left > FW_WRITE_BUFSIZE) {
642 xfer_size = FW_WRITE_BUFSIZE;
644 xfer_size = bytes_left;
647 /* Copy xfer_size bytes from user space to kernel buffer */
648 if (ocs_copy_from_user(dma.virt, userp, xfer_size)) {
653 /* See if this is the last block */
654 if (bytes_left == xfer_size) {
658 /* Send the HW command */
659 ocs_hw_firmware_write(&ocs->hw, &dma, xfer_size, offset, last, ocs_mgmt_fw_write_cb, &result);
661 /* Wait for semaphore to be signaled when the command completes
662 * TODO: Should there be a timeout on this? If so, how long? */
663 if (ocs_sem_p(&(result.semaphore), OCS_SEM_FOREVER) != 0) {
664 ocs_log_err(ocs, "ocs_sem_p failed\n");
669 if (result.actual_xfer == 0) {
670 ocs_log_test(ocs, "actual_write_length is %d\n", result.actual_xfer);
676 if (result.status != 0) {
677 ocs_log_test(ocs, "write returned status %d\n", result.status);
683 change_status = result.change_status;
686 bytes_left -= result.actual_xfer;
687 offset += result.actual_xfer;
688 userp += result.actual_xfer;
691 /* Create string with status and copy to userland */
692 if ((arg_out_length > 0) && (arg_out != NULL)) {
693 if (arg_out_length > sizeof(status_str)) {
694 arg_out_length = sizeof(status_str);
696 ocs_memset(status_str, 0, sizeof(status_str));
697 ocs_snprintf(status_str, arg_out_length, "%d", change_status);
698 if (ocs_copy_to_user(arg_out, status_str, arg_out_length)) {
699 ocs_log_test(ocs, "copy to user failed for change_status\n");
703 ocs_dma_free(ocs, &dma);
709 ocs_mgmt_fw_write_cb(int32_t status, uint32_t actual_write_length, uint32_t change_status, void *arg)
711 ocs_mgmt_fw_write_result_t *result = arg;
713 result->status = status;
714 result->actual_xfer = actual_write_length;
715 result->change_status = change_status;
717 ocs_sem_v(&(result->semaphore));
720 typedef struct ocs_mgmt_sfp_result {
726 uint32_t page_data[32];
727 } ocs_mgmt_sfp_result_t;
730 ocs_mgmt_sfp_cb(void *os, int32_t status, uint32_t bytes_read, uint32_t *data, void *arg)
732 ocs_mgmt_sfp_result_t *result = arg;
735 ocs_lock(&(result->cb_lock));
737 if(result->running == 2) {
738 /* get_sfp() has timed out */
739 ocs_unlock(&(result->cb_lock));
740 ocs_free(ocs, result, sizeof(ocs_mgmt_sfp_result_t));
744 result->status = status;
745 result->bytes_read = bytes_read;
746 ocs_memcpy(&result->page_data, data, SFP_PAGE_SIZE);
748 ocs_sem_v(&(result->semaphore));
749 ocs_unlock(&(result->cb_lock));
753 ocs_mgmt_get_sfp(ocs_t *ocs, uint16_t page, void *buf, uint32_t buf_len)
756 ocs_mgmt_sfp_result_t *result = ocs_malloc(ocs, sizeof(ocs_mgmt_sfp_result_t), OCS_M_ZERO | OCS_M_NOWAIT);
758 ocs_sem_init(&(result->semaphore), 0, "get_sfp");
759 ocs_lock_init(ocs, &(result->cb_lock), "get_sfp");
761 /* Send the HW command */
762 ocs_hw_get_sfp(&ocs->hw, page, ocs_mgmt_sfp_cb, result);
764 /* Wait for semaphore to be signaled when the command completes */
765 if (ocs_sem_p(&(result->semaphore), 5 * 1000 * 1000) != 0) {
766 /* Timed out, callback will free memory */
767 ocs_lock(&(result->cb_lock));
769 if(result->running == 1) {
770 ocs_log_err(ocs, "ocs_sem_p failed\n");
771 ocs_unlock(&(result->cb_lock));
774 /* sfp_cb() has already executed, proceed as normal */
775 ocs_unlock(&(result->cb_lock));
779 if (result->status != 0) {
780 ocs_log_test(ocs, "read_transceiver_data returned status %d\n",
786 rc = (result->bytes_read > buf_len ? buf_len : result->bytes_read);
787 /* Copy the results back to the supplied buffer */
788 ocs_memcpy(buf, result->page_data, rc);
791 ocs_free(ocs, result, sizeof(ocs_mgmt_sfp_result_t));
796 ocs_mgmt_force_assert(ocs_t *ocs, char *name, void *buf, uint32_t buf_len, void *arg_out, uint32_t arg_out_length)
798 ocs_assert(FALSE, 0);
802 get_nodes_count(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
804 ocs_xport_t *xport = ocs->xport;
806 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "nodes_count", "%d", xport->nodes_count);
810 get_driver_version(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
812 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "driver_version", ocs->driver_version);
816 get_desc(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
818 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "desc", ocs->desc);
822 get_fw_rev(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
824 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "fw_rev", ocs_hw_get_ptr(&ocs->hw, OCS_HW_FW_REV));
828 get_fw_rev2(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
830 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "fw_rev2", ocs_hw_get_ptr(&ocs->hw, OCS_HW_FW_REV2));
834 get_ipl(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
836 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "ipl", ocs_hw_get_ptr(&ocs->hw, OCS_HW_IPL));
840 get_hw_rev1(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
844 ocs_hw_get(&ocs->hw, OCS_HW_HW_REV1, &value);
846 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "hw_rev1", "%u", value);
850 get_hw_rev2(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
854 ocs_hw_get(&ocs->hw, OCS_HW_HW_REV2, &value);
856 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "hw_rev2", "%u", value);
860 get_hw_rev3(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
863 ocs_hw_get(&ocs->hw, OCS_HW_HW_REV3, &value);
865 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "hw_rev3", "%u", value);
869 get_wwnn(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
873 wwnn = ocs_hw_get_ptr(&ocs->hw, OCS_HW_WWN_NODE);
875 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "wwnn", "0x%llx", (unsigned long long)ocs_htobe64(*wwnn));
879 get_wwpn(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
883 wwpn = ocs_hw_get_ptr(&ocs->hw, OCS_HW_WWN_PORT);
885 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "wwpn", "0x%llx", (unsigned long long)ocs_htobe64(*wwpn));
889 get_fcid(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
892 if (ocs->domain && ocs->domain->attached) {
893 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "fc_id", "0x%06x",
894 ocs->domain->sport->fc_id);
896 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "fc_id", "UNKNOWN");
902 get_sn(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
908 pserial = ocs_scsi_get_property_ptr(ocs, OCS_SCSI_SERIALNUMBER);
911 strncpy(sn_buf, (char*)pserial, len);
913 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "sn", sn_buf);
918 get_pn(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
924 pserial = ocs_scsi_get_property_ptr(ocs, OCS_SCSI_PARTNUMBER);
927 strncpy(sn_buf, (char*)pserial, len);
929 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "pn", sn_buf);
931 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "pn", ocs->model);
936 get_sli4_intf_reg(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
939 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "sli4_intf_reg", "0x%04x",
940 ocs_config_read32(ocs, SLI4_INTF_REG));
944 get_phy_port_num(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
946 char *phy_port = NULL;
948 phy_port = ocs_scsi_get_property_ptr(ocs, OCS_SCSI_PORTNUM);
950 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "phy_port_num", phy_port);
952 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "phy_port_num", "unknown");
956 get_asic_id(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
959 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "asic_id_reg", "0x%04x",
960 ocs_config_read32(ocs, SLI4_ASIC_ID_REG));
964 get_chip_type(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
968 uint32_t asic_gen_num;
969 uint32_t asic_rev_num;
974 family = (ocs_config_read32(ocs, SLI4_INTF_REG) & 0x00000f00) >> 8;
975 asic_id = ocs_config_read32(ocs, SLI4_ASIC_ID_REG);
976 asic_rev_num = asic_id & 0xff;
977 asic_gen_num = (asic_id & 0xff00) >> 8;
979 rev_id = ocs_config_read32(ocs, SLI4_PCI_CLASS_REVISION) & 0xff;
984 ocs_strncpy(result_buf, "BE2 A", sizeof(result_buf));
985 ocs_snprintf(tmp_buf, 2, "%d", rev_id);
986 strcat(result_buf, tmp_buf);
990 ocs_strncpy(result_buf, "BE3", sizeof(result_buf));
991 if (rev_id >= 0x10) {
992 strcat(result_buf, "-R");
994 ocs_snprintf(tmp_buf, 3, " %c", ((rev_id & 0xf0) >> 4) + 'A');
995 strcat(result_buf, tmp_buf);
996 ocs_snprintf(tmp_buf, 2, "%d", rev_id & 0x0f);
997 strcat(result_buf, tmp_buf);
1001 ocs_strncpy(result_buf, "Skyhawk A0", sizeof(result_buf));
1005 ocs_strncpy(result_buf, "Lancer A", sizeof(result_buf));
1006 ocs_snprintf(tmp_buf, 2, "%d", rev_id & 0x0f);
1007 strcat(result_buf, tmp_buf);
1010 /* Lancer B0 or D0 */
1011 ocs_strncpy(result_buf, "Lancer", sizeof(result_buf));
1012 ocs_snprintf(tmp_buf, 3, " %c", ((rev_id & 0xf0) >> 4) + 'A');
1013 strcat(result_buf, tmp_buf);
1014 ocs_snprintf(tmp_buf, 2, "%d", rev_id & 0x0f);
1015 strcat(result_buf, tmp_buf);
1018 ocs_strncpy(result_buf, "Lancer G6", sizeof(result_buf));
1021 /* Refer to ASIC_ID */
1022 switch(asic_gen_num) {
1024 ocs_strncpy(result_buf, "BE2", sizeof(result_buf));
1027 ocs_strncpy(result_buf, "BE3-R", sizeof(result_buf));
1030 ocs_strncpy(result_buf, "Skyhawk-R", sizeof(result_buf));
1033 ocs_strncpy(result_buf, "Corsair", sizeof(result_buf));
1036 ocs_strncpy(result_buf, "Lancer", sizeof(result_buf));
1039 ocs_strncpy(result_buf, "LancerG6", sizeof(result_buf));
1042 ocs_strncpy(result_buf, "Unknown", sizeof(result_buf));
1044 if (ocs_strcmp(result_buf, "Unknown") != 0) {
1045 ocs_snprintf(tmp_buf, 3, " %c", ((asic_rev_num & 0xf0) >> 4) + 'A');
1046 strcat(result_buf, tmp_buf);
1047 ocs_snprintf(tmp_buf, 2, "%d", asic_rev_num & 0x0f);
1048 strcat(result_buf, tmp_buf);
1052 ocs_strncpy(result_buf, "Unknown", sizeof(result_buf));
1055 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "chip_type", result_buf);
1060 get_pci_vendor(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1063 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "pci_vendor", "0x%04x", ocs->pci_vendor);
1067 get_pci_device(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1070 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "pci_device", "0x%04x", ocs->pci_device);
1074 get_pci_subsystem_vendor(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1077 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "pci_subsystem_vendor", "0x%04x", ocs->pci_subsystem_vendor);
1081 get_pci_subsystem_device(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1084 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "pci_subsystem_device", "0x%04x", ocs->pci_subsystem_device);
1088 get_tgt_rscn_delay(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1090 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "tgt_rscn_delay", "%ld", (unsigned long)ocs->tgt_rscn_delay_msec / 1000);
1094 get_tgt_rscn_period(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1096 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "tgt_rscn_period", "%ld", (unsigned long)ocs->tgt_rscn_period_msec / 1000);
1100 get_inject_drop_cmd(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1102 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "inject_drop_cmd", "%d",
1103 (ocs->err_injection == INJECT_DROP_CMD ? 1:0));
1107 get_inject_free_drop_cmd(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1109 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "inject_free_drop_cmd", "%d",
1110 (ocs->err_injection == INJECT_FREE_DROPPED ? 1:0));
1114 get_inject_drop_data(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1116 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "inject_drop_data", "%d",
1117 (ocs->err_injection == INJECT_DROP_DATA ? 1:0));
1121 get_inject_drop_resp(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1123 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "inject_drop_resp", "%d",
1124 (ocs->err_injection == INJECT_DROP_RESP ? 1:0));
1128 get_cmd_err_inject(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1130 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "cmd_err_inject", "0x%02x", ocs->cmd_err_inject);
1134 get_cmd_delay_value(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1136 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "cmd_delay_value", "%ld", (unsigned long)ocs->delay_value_msec);
1140 get_businfo(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1142 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "businfo", ocs->businfo);
1146 get_sfp_a0(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1153 page_data = ocs_malloc(ocs, SFP_PAGE_SIZE, OCS_M_ZERO | OCS_M_NOWAIT);
1154 if (page_data == NULL) {
1158 buf = ocs_malloc(ocs, (SFP_PAGE_SIZE * 3) + 1, OCS_M_ZERO | OCS_M_NOWAIT);
1160 ocs_free(ocs, page_data, SFP_PAGE_SIZE);
1164 bytes_read = ocs_mgmt_get_sfp(ocs, 0xa0, page_data, SFP_PAGE_SIZE);
1166 if (bytes_read <= 0) {
1167 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "sfp_a0", "(unknown)");
1170 uint8_t *s = page_data;
1171 int buffer_remaining = (SFP_PAGE_SIZE * 3) + 1;
1174 for (i = 0; i < bytes_read; i++) {
1175 bytes_added = ocs_snprintf(d, buffer_remaining, "%02x ", *s);
1178 buffer_remaining -= bytes_added;
1181 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "sfp_a0", buf);
1184 ocs_free(ocs, page_data, SFP_PAGE_SIZE);
1185 ocs_free(ocs, buf, (3 * SFP_PAGE_SIZE) + 1);
1189 get_sfp_a2(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1196 page_data = ocs_malloc(ocs, SFP_PAGE_SIZE, OCS_M_ZERO | OCS_M_NOWAIT);
1197 if (page_data == NULL) {
1201 buf = ocs_malloc(ocs, (SFP_PAGE_SIZE * 3) + 1, OCS_M_ZERO | OCS_M_NOWAIT);
1203 ocs_free(ocs, page_data, SFP_PAGE_SIZE);
1207 bytes_read = ocs_mgmt_get_sfp(ocs, 0xa2, page_data, SFP_PAGE_SIZE);
1209 if (bytes_read <= 0) {
1210 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "sfp_a2", "(unknown)");
1213 uint8_t *s = page_data;
1214 int buffer_remaining = (SFP_PAGE_SIZE * 3) + 1;
1217 for (i=0; i < bytes_read; i++) {
1218 bytes_added = ocs_snprintf(d, buffer_remaining, "%02x ", *s);
1221 buffer_remaining -= bytes_added;
1224 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "sfp_a2", buf);
1227 ocs_free(ocs, page_data, SFP_PAGE_SIZE);
1228 ocs_free(ocs, buf, (3 * SFP_PAGE_SIZE) + 1);
1232 get_debug_mq_dump(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1235 ocs_mgmt_emit_boolean(textbuf, MGMT_MODE_RW, "debug_mq_dump",
1236 ocs_debug_is_enabled(OCS_DEBUG_ENABLE_MQ_DUMP));
1240 get_debug_cq_dump(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1243 ocs_mgmt_emit_boolean(textbuf, MGMT_MODE_RW, "debug_cq_dump",
1244 ocs_debug_is_enabled(OCS_DEBUG_ENABLE_CQ_DUMP));
1248 get_debug_wq_dump(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1250 ocs_mgmt_emit_boolean(textbuf, MGMT_MODE_RW, "debug_wq_dump",
1251 ocs_debug_is_enabled(OCS_DEBUG_ENABLE_WQ_DUMP));
1255 get_debug_eq_dump(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1257 ocs_mgmt_emit_boolean(textbuf, MGMT_MODE_RW, "debug_eq_dump",
1258 ocs_debug_is_enabled(OCS_DEBUG_ENABLE_EQ_DUMP));
1262 get_logmask(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1265 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "logmask", "0x%02x", ocs->logmask);
1270 get_loglevel(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1273 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "loglevel", "%d", loglevel);
1278 get_current_speed(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1282 ocs_hw_get(&(ocs->hw), OCS_HW_LINK_SPEED, &value);
1284 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "current_speed", "%d", value);
1288 get_configured_speed(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1292 ocs_hw_get(&(ocs->hw), OCS_HW_LINK_CONFIG_SPEED, &value);
1294 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "configured_speed", "auto");
1296 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "configured_speed", "%d", value);
1302 get_current_topology(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1306 ocs_hw_get(&(ocs->hw), OCS_HW_TOPOLOGY, &value);
1307 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "current_topology", "%d", value);
1312 get_configured_topology(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1316 ocs_hw_get(&(ocs->hw), OCS_HW_CONFIG_TOPOLOGY, &value);
1317 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "configured_topology", "%d", value);
1322 get_current_link_state(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1324 ocs_xport_stats_t value;
1326 if (ocs_xport_status(ocs->xport, OCS_XPORT_PORT_STATUS, &value) == 0) {
1327 if (value.value == OCS_XPORT_PORT_ONLINE) {
1328 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "current_link_state", "online");
1330 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "current_link_state", "offline");
1336 get_configured_link_state(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1338 ocs_xport_stats_t value;
1340 if (ocs_xport_status(ocs->xport, OCS_XPORT_CONFIG_PORT_STATUS, &value) == 0) {
1341 if (value.value == OCS_XPORT_PORT_ONLINE) {
1342 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "configured_link_state", "online");
1344 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "configured_link_state", "offline");
1350 * @brief HW link config enum to mgmt string value mapping.
1352 * This structure provides a mapping from the ocs_hw_linkcfg_e
1353 * enum (enum exposed for the OCS_HW_PORT_SET_LINK_CONFIG port
1354 * control) to the mgmt string that is passed in by the mgmt application
1357 typedef struct ocs_mgmt_linkcfg_map_s {
1358 ocs_hw_linkcfg_e linkcfg;
1359 const char *mgmt_str;
1360 } ocs_mgmt_linkcfg_map_t;
1362 static ocs_mgmt_linkcfg_map_t mgmt_linkcfg_map[] = {
1363 {OCS_HW_LINKCFG_4X10G, OCS_CONFIG_LINKCFG_4X10G},
1364 {OCS_HW_LINKCFG_1X40G, OCS_CONFIG_LINKCFG_1X40G},
1365 {OCS_HW_LINKCFG_2X16G, OCS_CONFIG_LINKCFG_2X16G},
1366 {OCS_HW_LINKCFG_4X8G, OCS_CONFIG_LINKCFG_4X8G},
1367 {OCS_HW_LINKCFG_4X1G, OCS_CONFIG_LINKCFG_4X1G},
1368 {OCS_HW_LINKCFG_2X10G, OCS_CONFIG_LINKCFG_2X10G},
1369 {OCS_HW_LINKCFG_2X10G_2X8G, OCS_CONFIG_LINKCFG_2X10G_2X8G}};
1372 * @brief Get the HW linkcfg enum from the mgmt config string.
1374 * @param mgmt_str mgmt string value.
1376 * @return Returns the HW linkcfg enum corresponding to clp_str.
1378 static ocs_hw_linkcfg_e
1379 ocs_hw_linkcfg_from_mgmt(const char *mgmt_str)
1382 for (i = 0; i < ARRAY_SIZE(mgmt_linkcfg_map); i++) {
1383 if (ocs_strncmp(mgmt_linkcfg_map[i].mgmt_str,
1384 mgmt_str, ocs_strlen(mgmt_str)) == 0) {
1385 return mgmt_linkcfg_map[i].linkcfg;
1388 return OCS_HW_LINKCFG_NA;
1392 * @brief Get the mgmt string value from the HW linkcfg enum.
1394 * @param linkcfg HW linkcfg enum.
1396 * @return Returns the mgmt string value corresponding to the given HW linkcfg.
1399 ocs_mgmt_from_hw_linkcfg(ocs_hw_linkcfg_e linkcfg)
1402 for (i = 0; i < ARRAY_SIZE(mgmt_linkcfg_map); i++) {
1403 if (mgmt_linkcfg_map[i].linkcfg == linkcfg) {
1404 return mgmt_linkcfg_map[i].mgmt_str;
1407 return OCS_CONFIG_LINKCFG_UNKNOWN;
1411 * @brief Link configuration callback argument
1413 typedef struct ocs_mgmt_linkcfg_arg_s {
1414 ocs_sem_t semaphore;
1416 ocs_hw_linkcfg_e linkcfg;
1417 } ocs_mgmt_linkcfg_arg_t;
1420 * @brief Get linkcfg config value
1422 * @param ocs Pointer to the ocs structure.
1423 * @param name Not used.
1424 * @param textbuf The textbuf to which the result is written.
1429 get_linkcfg(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1431 const char *linkcfg_str = NULL;
1433 ocs_hw_linkcfg_e linkcfg;
1434 ocs_hw_get(&ocs->hw, OCS_HW_LINKCFG, &value);
1435 linkcfg = (ocs_hw_linkcfg_e)value;
1436 linkcfg_str = ocs_mgmt_from_hw_linkcfg(linkcfg);
1437 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "linkcfg", linkcfg_str);
1441 * @brief Get requested WWNN config value
1443 * @param ocs Pointer to the ocs structure.
1444 * @param name Not used.
1445 * @param textbuf The textbuf to which the result is written.
1450 get_req_wwnn(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1452 ocs_xport_t *xport = ocs->xport;
1454 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "requested_wwnn", "0x%llx", (unsigned long long)xport->req_wwnn);
1458 * @brief Get requested WWPN config value
1460 * @param ocs Pointer to the ocs structure.
1461 * @param name Not used.
1462 * @param textbuf The textbuf to which the result is written.
1467 get_req_wwpn(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1469 ocs_xport_t *xport = ocs->xport;
1471 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "requested_wwpn", "0x%llx", (unsigned long long)xport->req_wwpn);
1475 * @brief Get requested nodedb_mask config value
1477 * @param ocs Pointer to the ocs structure.
1478 * @param name Not used.
1479 * @param textbuf The textbuf to which the result is written.
1484 get_nodedb_mask(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1486 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "nodedb_mask", "0x%08x", ocs->nodedb_mask);
1490 * @brief Set requested WWNN value.
1492 * @param ocs Pointer to the ocs structure.
1493 * @param name Not used.
1494 * @param value Value to which the linkcfg is set.
1496 * @return Returns 0 on success.
1500 set_req_wwnn(ocs_t *ocs, char *name, char *value)
1505 if (ocs_strcasecmp(value, "default") == 0) {
1508 else if (parse_wwn(value, &wwnn) != 0) {
1509 ocs_log_test(ocs, "Invalid WWNN: %s\n", value);
1513 rc = ocs_xport_control(ocs->xport, OCS_XPORT_WWNN_SET, wwnn);
1516 ocs_log_test(ocs, "OCS_XPORT_WWNN_SET failed: %d\n", rc);
1520 rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_OFFLINE);
1522 ocs_log_test(ocs, "port offline failed : %d\n", rc);
1525 rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_ONLINE);
1527 ocs_log_test(ocs, "port online failed : %d\n", rc);
1534 * @brief Set requested WWNP value.
1536 * @param ocs Pointer to the ocs structure.
1537 * @param name Not used.
1538 * @param value Value to which the linkcfg is set.
1540 * @return Returns 0 on success.
1544 set_req_wwpn(ocs_t *ocs, char *name, char *value)
1549 if (ocs_strcasecmp(value, "default") == 0) {
1552 else if (parse_wwn(value, &wwpn) != 0) {
1553 ocs_log_test(ocs, "Invalid WWPN: %s\n", value);
1557 rc = ocs_xport_control(ocs->xport, OCS_XPORT_WWPN_SET, wwpn);
1560 ocs_log_test(ocs, "OCS_XPORT_WWPN_SET failed: %d\n", rc);
1564 rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_OFFLINE);
1566 ocs_log_test(ocs, "port offline failed : %d\n", rc);
1569 rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_ONLINE);
1571 ocs_log_test(ocs, "port online failed : %d\n", rc);
1578 * @brief Set node debug mask value
1580 * @param ocs Pointer to the ocs structure.
1581 * @param name Not used.
1582 * @param value Value to which the nodedb_mask is set.
1584 * @return Returns 0 on success.
1587 set_nodedb_mask(ocs_t *ocs, char *name, char *value)
1589 ocs->nodedb_mask = ocs_strtoul(value, 0, 0);
1594 * @brief Set linkcfg config value.
1596 * @param ocs Pointer to the ocs structure.
1597 * @param name Not used.
1598 * @param value Value to which the linkcfg is set.
1600 * @return Returns 0 on success.
1603 set_linkcfg(ocs_t *ocs, char *name, char *value)
1605 ocs_hw_linkcfg_e linkcfg;
1606 ocs_mgmt_linkcfg_arg_t cb_arg;
1607 ocs_hw_rtn_e status;
1609 ocs_sem_init(&cb_arg.semaphore, 0, "mgmt_linkcfg");
1611 /* translate mgmt linkcfg string to HW linkcfg enum */
1612 linkcfg = ocs_hw_linkcfg_from_mgmt(value);
1614 /* set HW linkcfg */
1615 status = ocs_hw_port_control(&ocs->hw, OCS_HW_PORT_SET_LINK_CONFIG,
1616 (uintptr_t)linkcfg, ocs_mgmt_linkcfg_cb, &cb_arg);
1618 ocs_log_test(ocs, "ocs_hw_set_linkcfg failed\n");
1622 if (ocs_sem_p(&cb_arg.semaphore, OCS_SEM_FOREVER)) {
1623 ocs_log_err(ocs, "ocs_sem_p failed\n");
1627 if (cb_arg.status) {
1628 ocs_log_test(ocs, "failed to set linkcfg from HW status=%d\n",
1637 * @brief Linkcfg callback
1639 * @param status Result of the linkcfg get/set operation.
1640 * @param value Resulting linkcfg value.
1641 * @param arg Callback argument.
1646 ocs_mgmt_linkcfg_cb(int32_t status, uintptr_t value, void *arg)
1648 ocs_mgmt_linkcfg_arg_t *cb_arg = (ocs_mgmt_linkcfg_arg_t *)arg;
1649 cb_arg->status = status;
1650 cb_arg->linkcfg = (ocs_hw_linkcfg_e)value;
1651 ocs_sem_v(&cb_arg->semaphore);
1655 set_debug_mq_dump(ocs_t *ocs, char *name, char *value)
1659 if (ocs_strcasecmp(value, "false") == 0) {
1660 ocs_debug_disable(OCS_DEBUG_ENABLE_MQ_DUMP);
1662 } else if (ocs_strcasecmp(value, "true") == 0) {
1663 ocs_debug_enable(OCS_DEBUG_ENABLE_MQ_DUMP);
1673 set_debug_cq_dump(ocs_t *ocs, char *name, char *value)
1677 if (ocs_strcasecmp(value, "false") == 0) {
1678 ocs_debug_disable(OCS_DEBUG_ENABLE_CQ_DUMP);
1680 } else if (ocs_strcasecmp(value, "true") == 0) {
1681 ocs_debug_enable(OCS_DEBUG_ENABLE_CQ_DUMP);
1691 set_debug_wq_dump(ocs_t *ocs, char *name, char *value)
1695 if (ocs_strcasecmp(value, "false") == 0) {
1696 ocs_debug_disable(OCS_DEBUG_ENABLE_WQ_DUMP);
1698 } else if (ocs_strcasecmp(value, "true") == 0) {
1699 ocs_debug_enable(OCS_DEBUG_ENABLE_WQ_DUMP);
1709 set_debug_eq_dump(ocs_t *ocs, char *name, char *value)
1713 if (ocs_strcasecmp(value, "false") == 0) {
1714 ocs_debug_disable(OCS_DEBUG_ENABLE_EQ_DUMP);
1716 } else if (ocs_strcasecmp(value, "true") == 0) {
1717 ocs_debug_enable(OCS_DEBUG_ENABLE_EQ_DUMP);
1727 set_logmask(ocs_t *ocs, char *name, char *value)
1730 ocs->logmask = ocs_strtoul(value, NULL, 0);
1736 set_loglevel(ocs_t *ocs, char *name, char *value)
1739 loglevel = ocs_strtoul(value, NULL, 0);
1745 set_configured_speed(ocs_t *ocs, char *name, char *value)
1752 spd = ocs_strtoul(value, NULL, 0);
1754 if ((spd != 0) && (spd != 2000) && (spd != 4000) &&
1755 (spd != 8000) && (spd != 16000) && (spd != 32000)) {
1756 ocs_log_test(ocs, "unsupported speed %d\n", spd);
1760 ocs_log_debug(ocs, "Taking port offline\n");
1761 xport_rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_OFFLINE);
1762 if (xport_rc != 0) {
1763 ocs_log_test(ocs, "Port offline failed\n");
1766 ocs_log_debug(ocs, "Setting port to speed %d\n", spd);
1767 hw_rc = ocs_hw_set(&ocs->hw, OCS_HW_LINK_SPEED, spd);
1768 if (hw_rc != OCS_HW_RTN_SUCCESS) {
1769 ocs_log_test(ocs, "Speed set failed\n");
1773 /* If we failed to set the speed we still want to try to bring
1774 * the port back online */
1776 ocs_log_debug(ocs, "Bringing port online\n");
1777 xport_rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_ONLINE);
1778 if (xport_rc != 0) {
1787 set_configured_topology(ocs_t *ocs, char *name, char *value)
1794 topo = ocs_strtoul(value, NULL, 0);
1795 if (topo >= OCS_HW_TOPOLOGY_NONE) {
1799 ocs_log_debug(ocs, "Taking port offline\n");
1800 xport_rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_OFFLINE);
1801 if (xport_rc != 0) {
1802 ocs_log_test(ocs, "Port offline failed\n");
1805 ocs_log_debug(ocs, "Setting port to topology %d\n", topo);
1806 hw_rc = ocs_hw_set(&ocs->hw, OCS_HW_TOPOLOGY, topo);
1807 if (hw_rc != OCS_HW_RTN_SUCCESS) {
1808 ocs_log_test(ocs, "Topology set failed\n");
1812 /* If we failed to set the topology we still want to try to bring
1813 * the port back online */
1815 ocs_log_debug(ocs, "Bringing port online\n");
1816 xport_rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_ONLINE);
1817 if (xport_rc != 0) {
1826 set_configured_link_state(ocs_t *ocs, char *name, char *value)
1831 if (ocs_strcasecmp(value, "offline") == 0) {
1832 ocs_log_debug(ocs, "Setting port to %s\n", value);
1833 xport_rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_OFFLINE);
1834 if (xport_rc != 0) {
1835 ocs_log_test(ocs, "Setting port to offline failed\n");
1838 } else if (ocs_strcasecmp(value, "online") == 0) {
1839 ocs_log_debug(ocs, "Setting port to %s\n", value);
1840 xport_rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_ONLINE);
1841 if (xport_rc != 0) {
1842 ocs_log_test(ocs, "Setting port to online failed\n");
1846 ocs_log_test(ocs, "Unsupported link state \"%s\"\n", value);
1853 typedef struct ocs_mgmt_get_port_protocol_result {
1854 ocs_sem_t semaphore;
1856 ocs_hw_port_protocol_e port_protocol;
1857 } ocs_mgmt_get_port_protocol_result_t;
1860 ocs_mgmt_get_port_protocol_cb(int32_t status,
1861 ocs_hw_port_protocol_e port_protocol,
1864 ocs_mgmt_get_port_protocol_result_t *result = arg;
1866 result->status = status;
1867 result->port_protocol = port_protocol;
1869 ocs_sem_v(&(result->semaphore));
1873 get_port_protocol(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1875 ocs_mgmt_get_port_protocol_result_t result;
1880 ocs_sem_init(&(result.semaphore), 0, "get_port_protocol");
1882 ocs_get_bus_dev_func(ocs, &bus, &dev, &func);
1884 if(ocs_hw_get_port_protocol(&ocs->hw, func, ocs_mgmt_get_port_protocol_cb, &result) == OCS_HW_RTN_SUCCESS) {
1885 if (ocs_sem_p(&(result.semaphore), OCS_SEM_FOREVER) != 0) {
1886 /* Undefined failure */
1887 ocs_log_err(ocs, "ocs_sem_p failed\n");
1889 if (result.status == 0) {
1890 switch (result.port_protocol) {
1891 case OCS_HW_PORT_PROTOCOL_ISCSI:
1892 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "port_protocol", "iSCSI");
1894 case OCS_HW_PORT_PROTOCOL_FCOE:
1895 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "port_protocol", "FCoE");
1897 case OCS_HW_PORT_PROTOCOL_FC:
1898 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "port_protocol", "FC");
1900 case OCS_HW_PORT_PROTOCOL_OTHER:
1901 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "port_protocol", "Other");
1905 ocs_log_test(ocs, "getting port profile status 0x%x\n", result.status);
1906 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "port_protocol", "Unknown");
1911 typedef struct ocs_mgmt_set_port_protocol_result {
1912 ocs_sem_t semaphore;
1914 } ocs_mgmt_set_port_protocol_result_t;
1917 ocs_mgmt_set_port_protocol_cb(int32_t status,
1920 ocs_mgmt_get_port_protocol_result_t *result = arg;
1922 result->status = status;
1924 ocs_sem_v(&(result->semaphore));
1928 * @brief Set port protocol
1930 * This is a management action handler to set the current
1931 * port protocol. Input value should be one of iSCSI,
1934 * @param ocs Pointer to the ocs structure.
1935 * @param name Name of the action being performed.
1936 * @param value The value to be assigned
1938 * @return Returns 0 on success, non-zero on failure.
1941 set_port_protocol(ocs_t *ocs, char *name, char *value)
1943 ocs_mgmt_set_port_protocol_result_t result;
1945 ocs_hw_port_protocol_e new_protocol;
1950 ocs_get_bus_dev_func(ocs, &bus, &dev, &func);
1952 ocs_sem_init(&(result.semaphore), 0, "set_port_protocol");
1954 if (ocs_strcasecmp(value, "iscsi") == 0) {
1955 new_protocol = OCS_HW_PORT_PROTOCOL_ISCSI;
1956 } else if (ocs_strcasecmp(value, "fc") == 0) {
1957 new_protocol = OCS_HW_PORT_PROTOCOL_FC;
1958 } else if (ocs_strcasecmp(value, "fcoe") == 0) {
1959 new_protocol = OCS_HW_PORT_PROTOCOL_FCOE;
1964 rc = ocs_hw_set_port_protocol(&ocs->hw, new_protocol, func,
1965 ocs_mgmt_set_port_protocol_cb, &result);
1966 if (rc == OCS_HW_RTN_SUCCESS) {
1967 if (ocs_sem_p(&(result.semaphore), OCS_SEM_FOREVER) != 0) {
1968 /* Undefined failure */
1969 ocs_log_err(ocs, "ocs_sem_p failed\n");
1972 if (result.status == 0) {
1977 ocs_log_test(ocs, "setting active profile status 0x%x\n",
1985 typedef struct ocs_mgmt_get_profile_list_result_s {
1986 ocs_sem_t semaphore;
1988 ocs_hw_profile_list_t *list;
1989 } ocs_mgmt_get_profile_list_result_t;
1992 ocs_mgmt_get_profile_list_cb(int32_t status, ocs_hw_profile_list_t *list, void *ul_arg)
1994 ocs_mgmt_get_profile_list_result_t *result = ul_arg;
1996 result->status = status;
1997 result->list = list;
1999 ocs_sem_v(&(result->semaphore));
2003 * @brief Get list of profiles
2005 * This is a management action handler to get the list of
2006 * profiles supported by the SLI port. Although the spec says
2007 * that all SLI platforms support this, only Skyhawk actually
2008 * has a useful implementation.
2010 * @param ocs Pointer to the ocs structure.
2011 * @param name Name of the action being performed.
2012 * @param textbuf Pointer to an ocs_textbuf, which is used to return the results.
2017 get_profile_list(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
2019 ocs_mgmt_get_profile_list_result_t result;
2021 ocs_sem_init(&(result.semaphore), 0, "get_profile_list");
2023 if(ocs_hw_get_profile_list(&ocs->hw, ocs_mgmt_get_profile_list_cb, &result) == OCS_HW_RTN_SUCCESS) {
2024 if (ocs_sem_p(&(result.semaphore), OCS_SEM_FOREVER) != 0) {
2025 /* Undefined failure */
2026 ocs_log_err(ocs, "ocs_sem_p failed\n");
2028 if (result.status == 0) {
2030 #define MAX_LINE_SIZE 520
2031 #define BUFFER_SIZE MAX_LINE_SIZE*40
2033 char result_line[MAX_LINE_SIZE];
2034 uint32_t bytes_left;
2037 result_buf = ocs_malloc(ocs, BUFFER_SIZE, OCS_M_ZERO);
2038 bytes_left = BUFFER_SIZE;
2040 for (i=0; i<result.list->num_descriptors; i++) {
2041 sprintf(result_line, "0x%02x:%s\n", result.list->descriptors[i].profile_id,
2042 result.list->descriptors[i].profile_description);
2043 if (strlen(result_line) < bytes_left) {
2044 strcat(result_buf, result_line);
2045 bytes_left -= strlen(result_line);
2049 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "profile_list", result_buf);
2051 ocs_free(ocs, result_buf, BUFFER_SIZE);
2052 ocs_free(ocs, result.list, sizeof(ocs_hw_profile_list_t));
2054 ocs_log_test(ocs, "getting profile list status 0x%x\n", result.status);
2059 typedef struct ocs_mgmt_get_active_profile_result {
2060 ocs_sem_t semaphore;
2062 uint32_t active_profile_id;
2063 } ocs_mgmt_get_active_profile_result_t;
2066 ocs_mgmt_get_active_profile_cb(int32_t status, uint32_t active_profile, void *ul_arg)
2068 ocs_mgmt_get_active_profile_result_t *result = ul_arg;
2070 result->status = status;
2071 result->active_profile_id = active_profile;
2073 ocs_sem_v(&(result->semaphore));
2076 #define MAX_PROFILE_LENGTH 5
2079 * @brief Get active profile
2081 * This is a management action handler to get the currently
2082 * active profile for an SLI port. Although the spec says that
2083 * all SLI platforms support this, only Skyhawk actually has a
2084 * useful implementation.
2086 * @param ocs Pointer to the ocs structure.
2087 * @param name Name of the action being performed.
2088 * @param textbuf Pointer to an ocs_textbuf, which is used to return the results.
2093 get_active_profile(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
2095 char result_string[MAX_PROFILE_LENGTH];
2096 ocs_mgmt_get_active_profile_result_t result;
2098 ocs_sem_init(&(result.semaphore), 0, "get_active_profile");
2100 if(ocs_hw_get_active_profile(&ocs->hw, ocs_mgmt_get_active_profile_cb, &result) == OCS_HW_RTN_SUCCESS) {
2101 if (ocs_sem_p(&(result.semaphore), OCS_SEM_FOREVER) != 0) {
2102 /* Undefined failure */
2103 ocs_log_err(ocs, "ocs_sem_p failed\n");
2105 if (result.status == 0) {
2107 sprintf(result_string, "0x%02x", result.active_profile_id);
2108 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "active_profile", result_string);
2110 ocs_log_test(ocs, "getting active profile status 0x%x\n", result.status);
2115 typedef struct ocs_mgmt_set_active_profile_result {
2116 ocs_sem_t semaphore;
2118 } ocs_mgmt_set_active_profile_result_t;
2121 ocs_mgmt_set_active_profile_cb(int32_t status, void *ul_arg)
2123 ocs_mgmt_get_profile_list_result_t *result = ul_arg;
2125 result->status = status;
2127 ocs_sem_v(&(result->semaphore));
2131 * @brief Set active profile
2133 * This is a management action handler to set the currently
2134 * active profile for an SLI port. Although the spec says that
2135 * all SLI platforms support this, only Skyhawk actually has a
2136 * useful implementation.
2138 * @param ocs Pointer to the ocs structure.
2139 * @param name Name of the action being performed.
2140 * @param value Requested new value of the property.
2142 * @return Returns 0 on success, non-zero on failure.
2145 set_active_profile(ocs_t *ocs, char *name, char *value)
2147 ocs_mgmt_set_active_profile_result_t result;
2149 int32_t new_profile;
2151 new_profile = ocs_strtoul(value, NULL, 0);
2153 ocs_sem_init(&(result.semaphore), 0, "set_active_profile");
2155 rc = ocs_hw_set_active_profile(&ocs->hw, ocs_mgmt_set_active_profile_cb, new_profile, &result);
2156 if (rc == OCS_HW_RTN_SUCCESS) {
2157 if (ocs_sem_p(&(result.semaphore), OCS_SEM_FOREVER) != 0) {
2158 /* Undefined failure */
2159 ocs_log_err(ocs, "ocs_sem_p failed\n");
2162 if (result.status == 0) {
2167 ocs_log_test(ocs, "setting active profile status 0x%x\n", result.status);
2174 typedef struct ocs_mgmt_get_nvparms_result {
2175 ocs_sem_t semaphore;
2180 uint32_t preferred_d_id;
2181 } ocs_mgmt_get_nvparms_result_t;
2184 ocs_mgmt_get_nvparms_cb(int32_t status, uint8_t *wwpn, uint8_t *wwnn, uint8_t hard_alpa,
2185 uint32_t preferred_d_id, void *ul_arg)
2187 ocs_mgmt_get_nvparms_result_t *result = ul_arg;
2189 result->status = status;
2190 ocs_memcpy(result->wwpn, wwpn, sizeof(result->wwpn));
2191 ocs_memcpy(result->wwnn, wwnn, sizeof(result->wwnn));
2192 result->hard_alpa = hard_alpa;
2193 result->preferred_d_id = preferred_d_id;
2195 ocs_sem_v(&(result->semaphore));
2203 * @param ocs Pointer to the ocs structure.
2204 * @param name Name of the action being performed.
2205 * @param textbuf Pointer to an ocs_textbuf, which is used to return the results.
2210 get_nv_wwpn(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
2212 char result_string[24];
2213 ocs_mgmt_get_nvparms_result_t result;
2215 ocs_sem_init(&(result.semaphore), 0, "get_nv_wwpn");
2217 if(ocs_hw_get_nvparms(&ocs->hw, ocs_mgmt_get_nvparms_cb, &result) == OCS_HW_RTN_SUCCESS) {
2218 if (ocs_sem_p(&(result.semaphore), OCS_SEM_FOREVER) != 0) {
2219 /* Undefined failure */
2220 ocs_log_err(ocs, "ocs_sem_p failed\n");
2223 if (result.status == 0) {
2224 /* Success. Copy wwpn from result struct to result string */
2225 sprintf(result_string, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
2226 result.wwpn[0], result.wwpn[1], result.wwpn[2],
2227 result.wwpn[3], result.wwpn[4], result.wwpn[5],
2228 result.wwpn[6], result.wwpn[7]);
2229 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "nv_wwpn", result_string);
2231 ocs_log_test(ocs, "getting wwpn status 0x%x\n", result.status);
2241 * @param ocs Pointer to the ocs structure.
2242 * @param name Name of the action being performed.
2243 * @param textbuf Pointer to an ocs_textbuf, which is used to return the results.
2248 get_nv_wwnn(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
2250 char result_string[24];
2251 ocs_mgmt_get_nvparms_result_t result;
2253 ocs_sem_init(&(result.semaphore), 0, "get_nv_wwnn");
2255 if(ocs_hw_get_nvparms(&ocs->hw, ocs_mgmt_get_nvparms_cb, &result) == OCS_HW_RTN_SUCCESS) {
2256 if (ocs_sem_p(&(result.semaphore), OCS_SEM_FOREVER) != 0) {
2257 /* Undefined failure */
2258 ocs_log_err(ocs, "ocs_sem_p failed\n");
2261 if (result.status == 0) {
2262 /* Success. Copy wwnn from result struct to result string */
2263 ocs_snprintf(result_string, sizeof(result_string), "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
2264 result.wwnn[0], result.wwnn[1], result.wwnn[2],
2265 result.wwnn[3], result.wwnn[4], result.wwnn[5],
2266 result.wwnn[6], result.wwnn[7]);
2267 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "nv_wwnn", result_string);
2269 ocs_log_test(ocs, "getting wwnn status 0x%x\n", result.status);
2275 * @brief Get accumulated node abort counts
2276 * @par Description Get the sum of all nodes abort count.
2278 * @param ocs Pointer to the ocs structure.
2279 * @param name Name of the action being performed.
2280 * @param textbuf Pointer to an ocs_textbuf, which is used to return the results.
2285 get_node_abort_cnt(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
2287 uint32_t abort_counts = 0;
2288 ocs_domain_t *domain;
2292 if (ocs_device_lock_try(ocs) != TRUE) {
2293 /* Didn't get the lock */
2297 /* Here the Device lock is held */
2298 ocs_list_foreach(&ocs->domain_list, domain) {
2299 if (ocs_domain_lock_try(domain) != TRUE) {
2300 /* Didn't get the lock */
2301 ocs_device_unlock(ocs);
2305 /* Here the Domain lock is held */
2306 ocs_list_foreach(&domain->sport_list, sport) {
2307 if (ocs_sport_lock_try(sport) != TRUE) {
2308 /* Didn't get the lock */
2309 ocs_domain_unlock(domain);
2310 ocs_device_unlock(ocs);
2314 /* Here the sport lock is held */
2315 ocs_list_foreach(&sport->node_list, node) {
2316 abort_counts += node->abort_cnt;
2319 ocs_sport_unlock(sport);
2322 ocs_domain_unlock(domain);
2325 ocs_device_unlock(ocs);
2327 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "node_abort_cnt", "%d" , abort_counts);
2330 typedef struct ocs_mgmt_set_nvparms_result {
2331 ocs_sem_t semaphore;
2333 } ocs_mgmt_set_nvparms_result_t;
2336 ocs_mgmt_set_nvparms_cb(int32_t status, void *ul_arg)
2338 ocs_mgmt_get_profile_list_result_t *result = ul_arg;
2340 result->status = status;
2342 ocs_sem_v(&(result->semaphore));
2347 * @par Description Sets the Non-volatile worldwide names,
2350 * @param ocs Pointer to the ocs structure.
2351 * @param name Name of the action being performed.
2352 * @param wwn_p Requested new WWN values.
2354 * @return Returns 0 on success, non-zero on failure.
2357 set_nv_wwn(ocs_t *ocs, char *name, char *wwn_p)
2359 ocs_mgmt_get_nvparms_result_t result;
2360 uint8_t new_wwpn[8];
2361 uint8_t new_wwnn[8];
2362 char *wwpn_p = NULL;
2363 char *wwnn_p = NULL;
2369 /* This is a read-modify-write operation, so first we have to read
2370 * the current values
2372 ocs_sem_init(&(result.semaphore), 0, "set_nv_wwn1");
2374 rc = ocs_hw_get_nvparms(&ocs->hw, ocs_mgmt_get_nvparms_cb, &result);
2376 if (rc == OCS_HW_RTN_SUCCESS) {
2377 if (ocs_sem_p(&(result.semaphore), OCS_SEM_FOREVER) != 0) {
2378 /* Undefined failure */
2379 ocs_log_err(ocs, "ocs_sem_p failed\n");
2382 if (result.status != 0) {
2383 ocs_log_test(ocs, "getting nvparms status 0x%x\n", result.status);
2388 /* wwn_p contains wwpn_p@wwnn_p values */
2389 if (wwn_p != NULL) {
2390 wwpn_p = ocs_strsep(&wwn_p, "@");
2394 if (wwpn_p != NULL) {
2395 wwpn = ocs_strcmp(wwpn_p, "NA");
2398 if (wwnn_p != NULL) {
2399 wwnn = ocs_strcmp(wwnn_p, "NA");
2402 /* Parse the new WWPN */
2403 if ((wwpn_p != NULL) && (wwpn != 0)) {
2404 if (ocs_sscanf(wwpn_p, "%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx",
2405 &(new_wwpn[0]), &(new_wwpn[1]), &(new_wwpn[2]),
2406 &(new_wwpn[3]), &(new_wwpn[4]), &(new_wwpn[5]),
2407 &(new_wwpn[6]), &(new_wwpn[7])) != 8) {
2408 ocs_log_test(ocs, "can't parse WWPN %s\n", wwpn_p);
2413 /* Parse the new WWNN */
2414 if ((wwnn_p != NULL) && (wwnn != 0 )) {
2415 if (ocs_sscanf(wwnn_p, "%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx",
2416 &(new_wwnn[0]), &(new_wwnn[1]), &(new_wwnn[2]),
2417 &(new_wwnn[3]), &(new_wwnn[4]), &(new_wwnn[5]),
2418 &(new_wwnn[6]), &(new_wwnn[7])) != 8) {
2419 ocs_log_test(ocs, "can't parse WWNN %s\n", wwnn_p);
2424 for (i = 0; i < 8; i++) {
2425 /* Use active wwpn, if new one is not provided */
2427 new_wwpn[i] = result.wwpn[i];
2430 /* Use active wwnn, if new one is not provided */
2432 new_wwnn[i] = result.wwnn[i];
2436 /* Modify the nv_wwnn and nv_wwpn, then write it back */
2437 ocs_sem_init(&(result.semaphore), 0, "set_nv_wwn2");
2439 rc = ocs_hw_set_nvparms(&ocs->hw, ocs_mgmt_set_nvparms_cb, new_wwpn,
2440 new_wwnn, result.hard_alpa, result.preferred_d_id,
2442 if (rc == OCS_HW_RTN_SUCCESS) {
2443 if (ocs_sem_p(&(result.semaphore), OCS_SEM_FOREVER) != 0) {
2444 /* Undefined failure */
2445 ocs_log_err(ocs, "ocs_sem_p failed\n");
2448 if (result.status != 0) {
2449 ocs_log_test(ocs, "setting wwn status 0x%x\n", result.status);
2458 set_tgt_rscn_delay(ocs_t *ocs, char *name, char *value)
2460 ocs->tgt_rscn_delay_msec = ocs_strtoul(value, NULL, 0) * 1000;
2461 ocs_log_debug(ocs, "mgmt set: %s %s\n", name, value);
2466 set_tgt_rscn_period(ocs_t *ocs, char *name, char *value)
2468 ocs->tgt_rscn_period_msec = ocs_strtoul(value, NULL, 0) * 1000;
2469 ocs_log_debug(ocs, "mgmt set: %s %s\n", name, value);
2474 set_inject_drop_cmd(ocs_t *ocs, char *name, char *value)
2476 ocs->err_injection = (ocs_strtoul(value, NULL, 0) == 0 ? NO_ERR_INJECT : INJECT_DROP_CMD);
2477 ocs_log_debug(ocs, "mgmt set: %s %s\n", name, value);
2482 set_inject_free_drop_cmd(ocs_t *ocs, char *name, char *value)
2484 ocs->err_injection = (ocs_strtoul(value, NULL, 0) == 0 ? NO_ERR_INJECT : INJECT_FREE_DROPPED);
2485 ocs_log_debug(ocs, "mgmt set: %s %s\n", name, value);
2490 set_inject_drop_data(ocs_t *ocs, char *name, char *value)
2492 ocs->err_injection = (ocs_strtoul(value, NULL, 0) == 0 ? NO_ERR_INJECT : INJECT_DROP_DATA);
2493 ocs_log_debug(ocs, "mgmt set: %s %s\n", name, value);
2498 set_inject_drop_resp(ocs_t *ocs, char *name, char *value)
2500 ocs->err_injection = (ocs_strtoul(value, NULL, 0) == 0 ? NO_ERR_INJECT : INJECT_DROP_RESP);
2501 ocs_log_debug(ocs, "mgmt set: %s %s\n", name, value);
2506 set_cmd_err_inject(ocs_t *ocs, char *name, char *value)
2508 ocs->cmd_err_inject = ocs_strtoul(value, NULL, 0);
2509 ocs_log_debug(ocs, "mgmt set: %s %s\n", name, value);
2514 set_cmd_delay_value(ocs_t *ocs, char *name, char *value)
2516 ocs->delay_value_msec = ocs_strtoul(value, NULL, 0);
2517 ocs->err_injection = (ocs->delay_value_msec == 0 ? NO_ERR_INJECT : INJECT_DELAY_CMD);
2518 ocs_log_debug(ocs, "mgmt set: %s %s\n", name, value);
2523 * @brief parse a WWN from a string into a 64-bit value
2525 * Given a pointer to a string, parse the string into a 64-bit
2526 * WWN value. The format of the string must be xx:xx:xx:xx:xx:xx:xx:xx
2528 * @param wwn_in pointer to the string to be parsed
2529 * @param wwn_out pointer to uint64_t in which to put the parsed result
2531 * @return 0 if successful, non-zero if the WWN is malformed and couldn't be parsed
2534 parse_wwn(char *wwn_in, uint64_t *wwn_out)
2546 rc = ocs_sscanf(wwn_in, "0x%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx",
2547 &byte0, &byte1, &byte2, &byte3,
2548 &byte4, &byte5, &byte6, &byte7);
2551 *wwn_out = ((uint64_t)byte0 << 56) |
2552 ((uint64_t)byte1 << 48) |
2553 ((uint64_t)byte2 << 40) |
2554 ((uint64_t)byte3 << 32) |
2555 ((uint64_t)byte4 << 24) |
2556 ((uint64_t)byte5 << 16) |
2557 ((uint64_t)byte6 << 8) |
2566 static char *mode_string(int mode);
2570 * @brief Generate the beginning of a numbered section in a management XML document.
2573 * This function begins a section. The XML information is appended to
2574 * the textbuf. This form of the function is used for sections that might have
2575 * multiple instances, such as a node or a SLI Port (sport). The index number
2576 * is appended to the name.
2578 * @param textbuf Pointer to the driver dump text buffer.
2579 * @param name Name of the section.
2580 * @param index Index number of this instance of the section.
2585 extern void ocs_mgmt_start_section(ocs_textbuf_t *textbuf, const char *name, int index)
2587 ocs_textbuf_printf(textbuf, "<%s instance=\"%d\">\n", name, index);
2592 * @brief Generate the beginning of an unnumbered section in a management XML document.
2595 * This function begins a section. The XML information is appended to
2596 * the textbuf. This form of the function is used for sections that have
2597 * a single instance only. Therefore, no index number is needed.
2599 * @param textbuf Pointer to the driver dump text buffer.
2600 * @param name Name of the section.
2605 extern void ocs_mgmt_start_unnumbered_section(ocs_textbuf_t *textbuf, const char *name)
2607 ocs_textbuf_printf(textbuf, "<%s>\n", name);
2612 * @brief Generate the end of a section in a management XML document.
2615 * This function ends a section. The XML information is appended to
2618 * @param textbuf Pointer to the driver dump text buffer.
2619 * @param name Name of the section.
2624 void ocs_mgmt_end_unnumbered_section(ocs_textbuf_t *textbuf, const char *name)
2626 ocs_textbuf_printf(textbuf, "</%s>\n", name);
2631 * @brief Generate the indexed end of a section in a management XML document.
2634 * This function ends a section. The XML information is appended to
2637 * @param textbuf Pointer to the driver dump text buffer.
2638 * @param name Name of the section.
2639 * @param index Index number of this instance of the section.
2644 void ocs_mgmt_end_section(ocs_textbuf_t *textbuf, const char *name, int index)
2647 ocs_textbuf_printf(textbuf, "</%s>\n", name);
2653 * @brief Generate a property, with no value, in a management XML document.
2656 * This function generates a property name. The XML information is appended to
2657 * the textbuf. This form of the function is used by the list functions
2658 * when the property name only (and not the current value) is given.
2660 * @param textbuf Pointer to the driver dump text buffer.
2661 * @param mode Defines whether the property is read(r)/write(w)/executable(x).
2662 * @param name Name of the property.
2667 void ocs_mgmt_emit_property_name(ocs_textbuf_t *textbuf, int mode, const char *name)
2669 ocs_textbuf_printf(textbuf, "<%s mode=\"%s\"/>\n", name, mode_string(mode));
2674 * @brief Generate a property with a string value in a management XML document.
2677 * This function generates a property name and a string value.
2678 * The XML information is appended to the textbuf.
2680 * @param textbuf Pointer to the driver dump text buffer.
2681 * @param mode Defines whether the property is read(r)/write(w)/executable(x).
2682 * @param name Name of the property.
2683 * @param value Value of the property.
2688 void ocs_mgmt_emit_string(ocs_textbuf_t *textbuf, int mode, const char *name, const char *value)
2690 ocs_textbuf_printf(textbuf, "<%s mode=\"%s\">%s</%s>\n", name, mode_string(mode), value, name);
2695 * @brief Generate a property with an integer value in a management XML document.
2698 * This function generates a property name and an integer value.
2699 * The XML information is appended to the textbuf.
2701 * @param textbuf Pointer to driver dump text buffer.
2702 * @param mode Defines whether the property is read(r)/write(w)/executable(x).
2703 * @param name Name of the property.
2704 * @param fmt A printf format for formatting the integer value.
2709 void ocs_mgmt_emit_int(ocs_textbuf_t *textbuf, int mode, const char *name, const char *fmt, ...)
2715 ocs_vsnprintf(valuebuf, sizeof(valuebuf), fmt, ap);
2718 ocs_textbuf_printf(textbuf, "<%s mode=\"%s\">%s</%s>\n", name, mode_string(mode), valuebuf, name);
2723 * @brief Generate a property with a boolean value in a management XML document.
2726 * This function generates a property name and a boolean value.
2727 * The XML information is appended to the textbuf.
2729 * @param textbuf Pointer to the driver dump text buffer.
2730 * @param mode Defines whether the property is read(r)/write(w)/executable(x).
2731 * @param name Name of the property.
2732 * @param value Boolean value to be added to the textbuf.
2737 void ocs_mgmt_emit_boolean(ocs_textbuf_t *textbuf, int mode, const char *name, int value)
2739 char *valuebuf = value ? "true" : "false";
2741 ocs_textbuf_printf(textbuf, "<%s mode=\"%s\">%s</%s>\n", name, mode_string(mode), valuebuf, name);
2744 static char *mode_string(int mode)
2746 static char mode_str[4];
2749 if (mode & MGMT_MODE_RD) {
2750 strcat(mode_str, "r");
2752 if (mode & MGMT_MODE_WR) {
2753 strcat(mode_str, "w");
2755 if (mode & MGMT_MODE_EX) {
2756 strcat(mode_str, "x");