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
47 #define SFP_PAGE_SIZE 128
51 static int ocs_mgmt_firmware_write(ocs_t *ocs, char *, void *buf, uint32_t buf_len, void*, uint32_t);
52 static int ocs_mgmt_firmware_reset(ocs_t *ocs, char *, void *buf, uint32_t buf_len, void*, uint32_t);
53 static int ocs_mgmt_function_reset(ocs_t *ocs, char *, void *buf, uint32_t buf_len, void*, uint32_t);
55 static void ocs_mgmt_fw_write_cb(int32_t status, uint32_t actual_write_length, uint32_t change_status, void *arg);
56 static int ocs_mgmt_force_assert(ocs_t *ocs, char *, void *buf, uint32_t buf_len, void*, uint32_t);
58 #if defined(OCS_INCLUDE_RAMD)
60 ocs_mgmt_read_phys(ocs_t *ocs, char *, void *, uint32_t , void *, uint32_t);
66 static void get_nodes_count(ocs_t *, char *, ocs_textbuf_t*);
67 static void get_desc(ocs_t *, char *, ocs_textbuf_t*);
68 static void get_fw_rev(ocs_t *, char *, ocs_textbuf_t*);
69 static void get_fw_rev2(ocs_t *, char *, ocs_textbuf_t*);
70 static void get_ipl(ocs_t *, char *, ocs_textbuf_t*);
71 static void get_wwnn(ocs_t *, char *, ocs_textbuf_t*);
72 static void get_wwpn(ocs_t *, char *, ocs_textbuf_t*);
73 static void get_fcid(ocs_t *, char *, ocs_textbuf_t *);
74 static void get_sn(ocs_t *, char *, ocs_textbuf_t*);
75 static void get_pn(ocs_t *, char *, ocs_textbuf_t*);
76 static void get_sli4_intf_reg(ocs_t *, char *, ocs_textbuf_t*);
77 static void get_phy_port_num(ocs_t *, char *, ocs_textbuf_t*);
78 static void get_asic_id(ocs_t *, char *, ocs_textbuf_t*);
79 static void get_pci_vendor(ocs_t *, char *, ocs_textbuf_t*);
80 static void get_pci_device(ocs_t *, char *, ocs_textbuf_t*);
81 static void get_pci_subsystem_vendor(ocs_t *, char *, ocs_textbuf_t*);
82 static void get_pci_subsystem_device(ocs_t *, char *, ocs_textbuf_t*);
83 static void get_businfo(ocs_t *, char *, ocs_textbuf_t*);
84 static void get_sfp_a0(ocs_t *, char *, ocs_textbuf_t*);
85 static void get_sfp_a2(ocs_t *, char *, ocs_textbuf_t*);
86 static void get_hw_rev1(ocs_t *, char *, ocs_textbuf_t*);
87 static void get_hw_rev2(ocs_t *, char *, ocs_textbuf_t*);
88 static void get_hw_rev3(ocs_t *, char *, ocs_textbuf_t*);
89 static void get_debug_mq_dump(ocs_t*, char*, ocs_textbuf_t*);
90 static void get_debug_cq_dump(ocs_t*, char*, ocs_textbuf_t*);
91 static void get_debug_wq_dump(ocs_t*, char*, ocs_textbuf_t*);
92 static void get_debug_eq_dump(ocs_t*, char*, ocs_textbuf_t*);
93 static void get_logmask(ocs_t*, char*, ocs_textbuf_t*);
94 static void get_current_speed(ocs_t*, char*, ocs_textbuf_t*);
95 static void get_current_topology(ocs_t*, char*, ocs_textbuf_t*);
96 static void get_current_link_state(ocs_t*, char*, ocs_textbuf_t*);
97 static void get_configured_speed(ocs_t*, char*, ocs_textbuf_t*);
98 static void get_configured_topology(ocs_t*, char*, ocs_textbuf_t*);
99 static void get_configured_link_state(ocs_t*, char*, ocs_textbuf_t*);
100 static void get_linkcfg(ocs_t*, char*, ocs_textbuf_t*);
101 static void get_req_wwnn(ocs_t*, char*, ocs_textbuf_t*);
102 static void get_req_wwpn(ocs_t*, char*, ocs_textbuf_t*);
103 static void get_nodedb_mask(ocs_t*, char*, ocs_textbuf_t*);
104 static void get_profile_list(ocs_t*, char*, ocs_textbuf_t*);
105 static void get_active_profile(ocs_t*, char*, ocs_textbuf_t*);
106 static void get_port_protocol(ocs_t*, char*, ocs_textbuf_t*);
107 static void get_driver_version(ocs_t*, char*, ocs_textbuf_t*);
108 static void get_chip_type(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
109 static void get_tgt_rscn_delay(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
110 static void get_tgt_rscn_period(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
111 static void get_inject_drop_cmd(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
112 static void get_inject_free_drop_cmd(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
113 static void get_inject_drop_data(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
114 static void get_inject_drop_resp(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
115 static void get_cmd_err_inject(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
116 static void get_cmd_delay_value(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
117 static void get_nv_wwpn(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
118 static void get_nv_wwnn(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
119 static void get_loglevel(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
120 static void get_node_abort_cnt(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf);
123 static int set_debug_mq_dump(ocs_t*, char*, char*);
124 static int set_debug_cq_dump(ocs_t*, char*, char*);
125 static int set_debug_wq_dump(ocs_t*, char*, char*);
126 static int set_debug_eq_dump(ocs_t*, char*, char*);
127 static int set_logmask(ocs_t*, char*, char*);
128 static int set_configured_link_state(ocs_t*, char*, char*);
129 static int set_linkcfg(ocs_t*, char*, char*);
130 static int set_nodedb_mask(ocs_t*, char*, char*);
131 static int set_port_protocol(ocs_t*, char*, char*);
132 static int set_active_profile(ocs_t*, char*, char*);
133 static int set_tgt_rscn_delay(ocs_t*, char*, char*);
134 static int set_tgt_rscn_period(ocs_t*, char*, char*);
135 static int set_inject_drop_cmd(ocs_t*, char*, char*);
136 static int set_inject_free_drop_cmd(ocs_t*, char*, char*);
137 static int set_inject_drop_data(ocs_t*, char*, char*);
138 static int set_inject_drop_resp(ocs_t*, char*, char*);
139 static int set_cmd_err_inject(ocs_t*, char*, char*);
140 static int set_cmd_delay_value(ocs_t*, char*, char*);
141 static int set_nv_wwn(ocs_t*, char*, char*);
142 static int set_loglevel(ocs_t*, char*, char*);
144 static void ocs_mgmt_linkcfg_cb(int32_t status, uintptr_t value, void *arg);
145 #if defined(OCS_INCLUDE_RAMD)
146 static void* find_address_in_target(ocs_ramdisc_t **ramdisc_array, uint32_t ramdisc_count, uintptr_t target_addr);
149 ocs_mgmt_table_entry_t mgmt_table[] = {
150 {"nodes_count", get_nodes_count, NULL, NULL},
151 {"desc", get_desc, NULL, NULL},
152 {"fw_rev", get_fw_rev, NULL, NULL},
153 {"fw_rev2", get_fw_rev2, NULL, NULL},
154 {"ipl", get_ipl, NULL, NULL},
155 {"hw_rev1", get_hw_rev1, NULL, NULL},
156 {"hw_rev2", get_hw_rev2, NULL, NULL},
157 {"hw_rev3", get_hw_rev3, NULL, NULL},
158 {"wwnn", get_wwnn, NULL, NULL},
159 {"wwpn", get_wwpn, NULL, NULL},
160 {"fc_id", get_fcid, NULL, NULL},
161 {"sn", get_sn, NULL, NULL},
162 {"pn", get_pn, NULL, NULL},
163 {"sli4_intf_reg", get_sli4_intf_reg, NULL, NULL},
164 {"phy_port_num", get_phy_port_num, NULL, NULL},
165 {"asic_id_reg", get_asic_id, NULL, NULL},
166 {"pci_vendor", get_pci_vendor, NULL, NULL},
167 {"pci_device", get_pci_device, NULL, NULL},
168 {"pci_subsystem_vendor", get_pci_subsystem_vendor, NULL, NULL},
169 {"pci_subsystem_device", get_pci_subsystem_device, NULL, NULL},
170 {"businfo", get_businfo, NULL, NULL},
171 {"sfp_a0", get_sfp_a0, NULL, NULL},
172 {"sfp_a2", get_sfp_a2, NULL, NULL},
173 {"profile_list", get_profile_list, NULL, NULL},
174 {"driver_version", get_driver_version, NULL, NULL},
175 {"current_speed", get_current_speed, NULL, NULL},
176 {"current_topology", get_current_topology, NULL, NULL},
177 {"current_link_state", get_current_link_state, NULL, NULL},
178 {"chip_type", get_chip_type, NULL, NULL},
179 {"configured_speed", get_configured_speed, set_configured_speed, NULL},
180 {"configured_topology", get_configured_topology, set_configured_topology, NULL},
181 {"configured_link_state", get_configured_link_state, set_configured_link_state, NULL},
182 {"debug_mq_dump", get_debug_mq_dump, set_debug_mq_dump, NULL},
183 {"debug_cq_dump", get_debug_cq_dump, set_debug_cq_dump, NULL},
184 {"debug_wq_dump", get_debug_wq_dump, set_debug_wq_dump, NULL},
185 {"debug_eq_dump", get_debug_eq_dump, set_debug_eq_dump, NULL},
186 {"logmask", get_logmask, set_logmask, NULL},
187 {"loglevel", get_loglevel, set_loglevel, NULL},
188 {"linkcfg", get_linkcfg, set_linkcfg, NULL},
189 {"requested_wwnn", get_req_wwnn, set_req_wwnn, NULL},
190 {"requested_wwpn", get_req_wwpn, set_req_wwpn, NULL},
191 {"nodedb_mask", get_nodedb_mask, set_nodedb_mask, NULL},
192 {"port_protocol", get_port_protocol, set_port_protocol, NULL},
193 {"active_profile", get_active_profile, set_active_profile, NULL},
194 {"firmware_write", NULL, NULL, ocs_mgmt_firmware_write},
195 {"firmware_reset", NULL, NULL, ocs_mgmt_firmware_reset},
196 {"function_reset", NULL, NULL, ocs_mgmt_function_reset},
197 #if defined(OCS_INCLUDE_RAMD)
198 {"read_phys", NULL, NULL, ocs_mgmt_read_phys},
200 {"force_assert", NULL, NULL, ocs_mgmt_force_assert},
202 {"tgt_rscn_delay", get_tgt_rscn_delay, set_tgt_rscn_delay, NULL},
203 {"tgt_rscn_period", get_tgt_rscn_period, set_tgt_rscn_period, NULL},
204 {"inject_drop_cmd", get_inject_drop_cmd, set_inject_drop_cmd, NULL},
205 {"inject_free_drop_cmd", get_inject_free_drop_cmd, set_inject_free_drop_cmd, NULL},
206 {"inject_drop_data", get_inject_drop_data, set_inject_drop_data, NULL},
207 {"inject_drop_resp", get_inject_drop_resp, set_inject_drop_resp, NULL},
208 {"cmd_err_inject", get_cmd_err_inject, set_cmd_err_inject, NULL},
209 {"cmd_delay_value", get_cmd_delay_value, set_cmd_delay_value, NULL},
210 {"nv_wwpn", get_nv_wwpn, NULL, NULL},
211 {"nv_wwnn", get_nv_wwnn, NULL, NULL},
212 {"nv_wwn", NULL, set_nv_wwn, NULL},
213 {"node_abort_cnt", get_node_abort_cnt, NULL, NULL},
218 * @brief Get a list of options supported by the driver.
221 * This is the top level "get list" handler for the driver. It
222 * performs the following:
223 * - Adds entries to the textbuf for any actions supported by this level in the driver.
224 * - Calls a back-end function to add any actions supported by the back-end.
225 * - Calls a function on each child (domain) to recursively add supported actions.
227 * @param ocs Pointer to the ocs structure.
228 * @param textbuf Pointer to an ocs_textbuf, which is used to accumulate the results.
230 * @return Returns 0 on success, or a negative value on failure.
234 ocs_mgmt_get_list(ocs_t *ocs, ocs_textbuf_t *textbuf)
236 ocs_domain_t *domain;
240 ocs_mgmt_start_unnumbered_section(textbuf, "ocs");
242 for (i=0;i<ARRAY_SIZE(mgmt_table);i++) {
244 if (mgmt_table[i].get_handler) {
245 access |= MGMT_MODE_RD;
247 if (mgmt_table[i].set_handler) {
248 access |= MGMT_MODE_WR;
250 if (mgmt_table[i].action_handler) {
251 access |= MGMT_MODE_EX;
253 ocs_mgmt_emit_property_name(textbuf, access, mgmt_table[i].name);
256 if ((ocs->mgmt_functions) && (ocs->mgmt_functions->get_list_handler)) {
257 ocs->mgmt_functions->get_list_handler(textbuf, ocs);
260 if ((ocs->tgt_mgmt_functions) && (ocs->tgt_mgmt_functions->get_list_handler)) {
261 ocs->tgt_mgmt_functions->get_list_handler(textbuf, &(ocs->tgt_ocs));
264 /* Have each of my children add their actions */
265 if (ocs_device_lock_try(ocs) == TRUE) {
267 /* If we get here then we are holding the device lock */
268 ocs_list_foreach(&ocs->domain_list, domain) {
269 if ((domain->mgmt_functions) && (domain->mgmt_functions->get_list_handler)) {
270 domain->mgmt_functions->get_list_handler(textbuf, domain);
273 ocs_device_unlock(ocs);
276 ocs_mgmt_end_unnumbered_section(textbuf, "ocs");
282 * @brief Return the value of a management item.
285 * This is the top level "get" handler for the driver. It
286 * performs the following:
287 * - Checks that the qualifier portion of the name begins with my qualifier (ocs).
288 * - If the remaining part of the name matches a parameter that is known at this level,
289 * writes the value into textbuf.
290 * - If the name is not known, sends the request to the back-ends to fulfill (if possible).
291 * - If the request has not been fulfilled by the back-end,
292 * passes the request to each of the children (domains) to
293 * have them (recursively) try to respond.
295 * In passing the request to other entities, the request is considered to be answered
296 * when a response has been written into textbuf, indicated by textbuf->buffer_written
299 * @param ocs Pointer to the ocs structure.
300 * @param name Name of the status item to be retrieved.
301 * @param textbuf Pointer to an ocs_textbuf, which is used to return the results.
303 * @return Returns 0 if the value was found and returned, or -1 if an error occurred.
308 ocs_mgmt_get(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
310 ocs_domain_t *domain;
315 ocs_mgmt_start_unnumbered_section(textbuf, "ocs");
318 snprintf(qualifier, sizeof(qualifier), "/ocs");
320 /* See if the name starts with my qualifier. If not then this request isn't for me */
321 if (ocs_strncmp(name, qualifier, strlen(qualifier)) == 0) {
322 char *unqualified_name = name + strlen(qualifier) + 1;
324 for (i=0;i<ARRAY_SIZE(mgmt_table);i++) {
325 if (ocs_strcmp(unqualified_name, mgmt_table[i].name) == 0) {
326 if (mgmt_table[i].get_handler) {
327 mgmt_table[i].get_handler(ocs, name, textbuf);
328 ocs_mgmt_end_unnumbered_section(textbuf, "ocs");
334 if ((ocs->mgmt_functions) && (ocs->mgmt_functions->get_handler)) {
335 retval = ocs->mgmt_functions->get_handler(textbuf, qualifier, (char*)name, ocs);
339 if ((ocs->tgt_mgmt_functions) && (ocs->tgt_mgmt_functions->get_handler)) {
340 retval = ocs->tgt_mgmt_functions->get_handler(textbuf, qualifier,
341 (char*)name, &(ocs->tgt_ocs));
346 /* The driver didn't handle it, pass it to each domain */
348 ocs_device_lock(ocs);
349 ocs_list_foreach(&ocs->domain_list, domain) {
350 if ((domain->mgmt_functions) && (domain->mgmt_functions->get_handler)) {
351 retval = domain->mgmt_functions->get_handler(textbuf, qualifier, (char*)name, domain);
360 ocs_device_unlock(ocs);
365 ocs_mgmt_end_unnumbered_section(textbuf, "ocs");
373 * @brief Set the value of a mgmt item.
376 * This is the top level "set" handler for the driver. It
377 * performs the following:
378 * - Checks that the qualifier portion of the name begins with my qualifier (ocs).
379 * - If the remaining part of the name matches a parameter that is known at this level,
380 * calls the correct function to change the configuration.
381 * - If the name is not known, sends the request to the back-ends to fulfill (if possible).
382 * - If the request has not been fulfilled by the back-end, passes the request to each of the
383 * children (domains) to have them (recursively) try to respond.
385 * In passing the request to other entities, the request is considered to be handled
386 * if the function returns 0.
388 * @param ocs Pointer to the ocs structure.
389 * @param name Name of the property to be changed.
390 * @param value Requested new value of the property.
392 * @return Returns 0 if the configuration value was updated, or -1 otherwise.
396 ocs_mgmt_set(ocs_t *ocs, char *name, char *value)
398 ocs_domain_t *domain;
403 snprintf(qualifier, sizeof(qualifier), "/ocs");
405 /* If it doesn't start with my qualifier I don't know what to do with it */
406 if (ocs_strncmp(name, qualifier, strlen(qualifier)) == 0) {
407 char *unqualified_name = name + strlen(qualifier) +1;
409 /* See if it's a value I can set */
410 for (i=0;i<ARRAY_SIZE(mgmt_table);i++) {
411 if (ocs_strcmp(unqualified_name, mgmt_table[i].name) == 0) {
412 if (mgmt_table[i].set_handler) {
413 return mgmt_table[i].set_handler(ocs, name, value);
418 if ((ocs->mgmt_functions) && (ocs->mgmt_functions->set_handler)) {
419 result = ocs->mgmt_functions->set_handler(qualifier, name, (char *)value, ocs);
423 if ((ocs->tgt_mgmt_functions) && (ocs->tgt_mgmt_functions->set_handler)) {
424 result = ocs->tgt_mgmt_functions->set_handler(qualifier, name,
425 (char *)value, &(ocs->tgt_ocs));
429 /* If I didn't know how to set this config value pass the request to each of my children */
431 ocs_device_lock(ocs);
432 ocs_list_foreach(&ocs->domain_list, domain) {
433 if ((domain->mgmt_functions) && (domain->mgmt_functions->set_handler)) {
434 result = domain->mgmt_functions->set_handler(qualifier, name, (char*)value, domain);
440 ocs_device_unlock(ocs);
451 * @brief Perform a management action.
454 * This is the top level "exec" handler for the driver. It
455 * performs the following:
456 * - Checks that the qualifier portion of the name begins with my qualifier (ocs).
457 * - If the remaining part of the name matches an action that is known at this level,
458 * calls the correct function to perform the action.
459 * - If the name is not known, sends the request to the back-ends to fulfill (if possible).
460 * - If the request has not been fulfilled by the back-end, passes the request to each of the
461 * children (domains) to have them (recursively) try to respond.
463 * In passing the request to other entities, the request is considered to be handled
464 * if the function returns 0.
466 * @param ocs Pointer to the ocs structure.
467 * @param action Name of the action to be performed.
468 * @param arg_in Pointer to an argument being passed to the action.
469 * @param arg_in_length Length of the argument pointed to by @c arg_in.
470 * @param arg_out Pointer to an argument being passed to the action.
471 * @param arg_out_length Length of the argument pointed to by @c arg_out.
473 * @return Returns 0 if the action was completed, or -1 otherwise.
479 ocs_mgmt_exec(ocs_t *ocs, char *action, void *arg_in,
480 uint32_t arg_in_length, void *arg_out, uint32_t arg_out_length)
482 ocs_domain_t *domain;
487 snprintf(qualifier, sizeof(qualifier), "/ocs");
489 /* If it doesn't start with my qualifier I don't know what to do with it */
490 if (ocs_strncmp(action, qualifier, strlen(qualifier)) == 0) {
491 char *unqualified_name = action + strlen(qualifier) +1;
493 /* See if it's an action I can perform */
494 for (i=0;i<ARRAY_SIZE(mgmt_table); i++) {
495 if (ocs_strcmp(unqualified_name, mgmt_table[i].name) == 0) {
496 if (mgmt_table[i].action_handler) {
497 return mgmt_table[i].action_handler(ocs, action, arg_in, arg_in_length,
498 arg_out, arg_out_length);
504 if ((ocs->mgmt_functions) && (ocs->mgmt_functions->exec_handler)) {
505 result = ocs->mgmt_functions->exec_handler(qualifier, action, arg_in, arg_in_length,
506 arg_out, arg_out_length, ocs);
510 if ((ocs->tgt_mgmt_functions) && (ocs->tgt_mgmt_functions->exec_handler)) {
511 result = ocs->tgt_mgmt_functions->exec_handler(qualifier, action,
512 arg_in, arg_in_length, arg_out, arg_out_length,
517 /* If I didn't know how to do this action pass the request to each of my children */
519 ocs_device_lock(ocs);
520 ocs_list_foreach(&ocs->domain_list, domain) {
521 if ((domain->mgmt_functions) && (domain->mgmt_functions->exec_handler)) {
522 result = domain->mgmt_functions->exec_handler(qualifier, action, arg_in, arg_in_length, arg_out,
523 arg_out_length, domain);
529 ocs_device_unlock(ocs);
538 ocs_mgmt_get_all(ocs_t *ocs, ocs_textbuf_t *textbuf)
540 ocs_domain_t *domain;
543 ocs_mgmt_start_unnumbered_section(textbuf, "ocs");
545 for (i=0;i<ARRAY_SIZE(mgmt_table);i++) {
546 if (mgmt_table[i].get_handler) {
547 mgmt_table[i].get_handler(ocs, mgmt_table[i].name, textbuf);
548 } else if (mgmt_table[i].action_handler) {
549 /* No get_handler, but there's an action_handler. Just report
551 ocs_mgmt_emit_property_name(textbuf, MGMT_MODE_EX, mgmt_table[i].name);
555 if ((ocs->mgmt_functions) && (ocs->mgmt_functions->get_all_handler)) {
556 ocs->mgmt_functions->get_all_handler(textbuf, ocs);
559 if ((ocs->tgt_mgmt_functions) && (ocs->tgt_mgmt_functions->get_all_handler)) {
560 ocs->tgt_mgmt_functions->get_all_handler(textbuf, &(ocs->tgt_ocs));
563 ocs_device_lock(ocs);
564 ocs_list_foreach(&ocs->domain_list, domain) {
565 if ((domain->mgmt_functions) && (domain->mgmt_functions->get_all_handler)) {
566 domain->mgmt_functions->get_all_handler(textbuf, domain);
569 ocs_device_unlock(ocs);
571 ocs_mgmt_end_unnumbered_section(textbuf, "ocs");
574 #if defined(OCS_INCLUDE_RAMD)
576 ocs_mgmt_read_phys(ocs_t *ocs, char *name, void *arg_in, uint32_t arg_in_length, void *arg_out, uint32_t arg_out_length)
580 uintptr_t target_addr;
582 ocs_ramdisc_t **ramdisc_array;
583 uint32_t ramdisc_count;
586 if ((arg_in == NULL) ||
587 (arg_in_length == 0) ||
589 (arg_out_length == 0)) {
593 if (arg_in_length > 80) {
597 if (ocs_copy_from_user(addr_str, arg_in, arg_in_length)) {
598 ocs_log_test(ocs, "Failed to copy addr from user\n");
602 target_addr = (uintptr_t)ocs_strtoul(addr_str, NULL, 0);
603 /* addr_str must be the physical address of a buffer that was reported
604 * in an SGL. Search ramdiscs looking for a segment that contains that
608 if (ocs->tgt_ocs.use_global_ramd) {
609 /* Only one target */
610 ramdisc_count = ocs->tgt_ocs.rdisc_count;
611 ramdisc_array = ocs->tgt_ocs.rdisc;
612 vaddr = find_address_in_target(ramdisc_array, ramdisc_count, target_addr);
614 /* Multiple targets. Each target is on a sport */
617 for (domain_idx=0; domain_idx<ocs->domain_instance_count; domain_idx++) {
618 ocs_domain_t *domain;
621 domain = ocs_domain_get_instance(ocs, domain_idx);
622 for (sport_idx=0; sport_idx < domain->sport_instance_count; sport_idx++) {
625 sport = ocs_sport_get_instance(domain, sport_idx);
626 ramdisc_count = sport->tgt_sport.rdisc_count;
627 ramdisc_array = sport->tgt_sport.rdisc;
628 vaddr = find_address_in_target(ramdisc_array, ramdisc_count, target_addr);
640 length = arg_out_length;
644 if (ocs_copy_to_user(arg_out, vaddr, length)) {
645 ocs_log_test(ocs, "Failed to copy buffer to user\n");
658 * This function searches a target for a given physical address.
659 * The target is made up of a number of LUNs, each represented by
662 static void* find_address_in_target(ocs_ramdisc_t **ramdisc_array, uint32_t ramdisc_count, uintptr_t target_addr)
665 uint32_t ramdisc_idx;
667 /* Check each ramdisc */
668 for (ramdisc_idx=0; ramdisc_idx<ramdisc_count; ramdisc_idx++) {
669 uint32_t segment_idx;
670 ocs_ramdisc_t *rdisc;
671 rdisc = ramdisc_array[ramdisc_idx];
672 /* Check each segment in the ramdisc */
673 for (segment_idx=0; segment_idx<rdisc->segment_count; segment_idx++) {
674 ramdisc_segment_t *segment = rdisc->segments[segment_idx];
675 uintptr_t segment_start;
676 uintptr_t segment_end;
679 segment_start = segment->data_segment.phys;
680 segment_end = segment->data_segment.phys + segment->data_segment.size - 1;
681 if ((target_addr >= segment_start) && (target_addr <= segment_end)) {
682 /* Found the target address */
683 offset = target_addr - segment_start;
684 vaddr = (uint32_t*)segment->data_segment.virt + offset;
687 if (rdisc->dif_separate) {
688 segment_start = segment->dif_segment.phys;
689 segment_end = segment->data_segment.phys + segment->dif_segment.size - 1;
690 if ((target_addr >= segment_start) && (target_addr <= segment_end)) {
691 /* Found the target address */
692 offset = target_addr - segment_start;
693 vaddr = (uint32_t*)segment->dif_segment.virt + offset;
717 ocs_mgmt_firmware_reset(ocs_t *ocs, char *name, void *buf, uint32_t buf_len, void *arg_out, uint32_t arg_out_length)
721 uint8_t bus, dev, func;
724 ocs_get_bus_dev_func(ocs, &bus, &dev, &func);
726 ocs_log_debug(ocs, "Resetting port\n");
727 if (ocs_hw_reset(&ocs->hw, OCS_HW_RESET_FIRMWARE)) {
728 ocs_log_test(ocs, "failed to reset port\n");
731 ocs_log_debug(ocs, "successfully reset port\n");
733 /* now reset all functions on the same device */
735 while ((other_ocs = ocs_get_instance(index++)) != NULL) {
736 uint8_t other_bus, other_dev, other_func;
738 ocs_get_bus_dev_func(other_ocs, &other_bus, &other_dev, &other_func);
740 if ((bus == other_bus) && (dev == other_dev)) {
741 if (other_ocs->hw.state !=
742 OCS_HW_STATE_UNINITIALIZED) {
743 other_ocs->hw.state =
744 OCS_HW_STATE_QUEUES_ALLOCATED;
747 ocs_device_detach(other_ocs);
748 if (ocs_device_attach(other_ocs)) {
749 ocs_log_err(other_ocs,
750 "device %d attach failed \n", index);
760 ocs_mgmt_function_reset(ocs_t *ocs, char *name, void *buf, uint32_t buf_len, void *arg_out, uint32_t arg_out_length)
764 ocs_device_detach(ocs);
765 rc = ocs_device_attach(ocs);
771 ocs_mgmt_firmware_write(ocs_t *ocs, char *name, void *buf, uint32_t buf_len, void *arg_out, uint32_t arg_out_length)
780 ocs_mgmt_fw_write_result_t result;
781 uint32_t change_status = 0;
784 ocs_sem_init(&(result.semaphore), 0, "fw_write");
786 bytes_left = buf_len;
788 userp = (uint8_t *)buf;
790 if (ocs_dma_alloc(ocs, &dma, FW_WRITE_BUFSIZE, 4096)) {
791 ocs_log_err(ocs, "ocs_mgmt_firmware_write: malloc failed");
795 while (bytes_left > 0) {
798 if (bytes_left > FW_WRITE_BUFSIZE) {
799 xfer_size = FW_WRITE_BUFSIZE;
801 xfer_size = bytes_left;
804 /* Copy xfer_size bytes from user space to kernel buffer */
805 if (ocs_copy_from_user(dma.virt, userp, xfer_size)) {
810 /* See if this is the last block */
811 if (bytes_left == xfer_size) {
815 /* Send the HW command */
816 ocs_hw_firmware_write(&ocs->hw, &dma, xfer_size, offset, last, ocs_mgmt_fw_write_cb, &result);
818 /* Wait for semaphore to be signaled when the command completes
819 * TODO: Should there be a timeout on this? If so, how long? */
820 if (ocs_sem_p(&(result.semaphore), OCS_SEM_FOREVER) != 0) {
821 ocs_log_err(ocs, "ocs_sem_p failed\n");
826 if (result.actual_xfer == 0) {
827 ocs_log_test(ocs, "actual_write_length is %d\n", result.actual_xfer);
833 if (result.status != 0) {
834 ocs_log_test(ocs, "write returned status %d\n", result.status);
840 change_status = result.change_status;
843 bytes_left -= result.actual_xfer;
844 offset += result.actual_xfer;
845 userp += result.actual_xfer;
849 /* Create string with status and copy to userland */
850 if ((arg_out_length > 0) && (arg_out != NULL)) {
851 if (arg_out_length > sizeof(status_str)) {
852 arg_out_length = sizeof(status_str);
854 ocs_snprintf(status_str, arg_out_length, "%d", change_status);
855 if (ocs_copy_to_user(arg_out, status_str, arg_out_length)) {
856 ocs_log_test(ocs, "copy to user failed for change_status\n");
861 ocs_dma_free(ocs, &dma);
867 ocs_mgmt_fw_write_cb(int32_t status, uint32_t actual_write_length, uint32_t change_status, void *arg)
869 ocs_mgmt_fw_write_result_t *result = arg;
871 result->status = status;
872 result->actual_xfer = actual_write_length;
873 result->change_status = change_status;
875 ocs_sem_v(&(result->semaphore));
878 typedef struct ocs_mgmt_sfp_result {
884 uint32_t page_data[32];
885 } ocs_mgmt_sfp_result_t;
888 ocs_mgmt_sfp_cb(void *os, int32_t status, uint32_t bytes_read, uint32_t *data, void *arg)
890 ocs_mgmt_sfp_result_t *result = arg;
893 ocs_lock(&(result->cb_lock));
895 if(result->running == 2) {
896 /* get_sfp() has timed out */
897 ocs_unlock(&(result->cb_lock));
898 ocs_free(ocs, result, sizeof(ocs_mgmt_sfp_result_t));
902 result->status = status;
903 result->bytes_read = bytes_read;
904 ocs_memcpy(&result->page_data, data, SFP_PAGE_SIZE);
906 ocs_sem_v(&(result->semaphore));
907 ocs_unlock(&(result->cb_lock));
911 ocs_mgmt_get_sfp(ocs_t *ocs, uint16_t page, void *buf, uint32_t buf_len)
914 ocs_mgmt_sfp_result_t *result = ocs_malloc(ocs, sizeof(ocs_mgmt_sfp_result_t), OCS_M_ZERO | OCS_M_NOWAIT);;
916 ocs_sem_init(&(result->semaphore), 0, "get_sfp");
917 ocs_lock_init(ocs, &(result->cb_lock), "get_sfp");
919 /* Send the HW command */
920 ocs_hw_get_sfp(&ocs->hw, page, ocs_mgmt_sfp_cb, result);
922 /* Wait for semaphore to be signaled when the command completes */
923 if (ocs_sem_p(&(result->semaphore), 5 * 1000 * 1000) != 0) {
924 /* Timed out, callback will free memory */
925 ocs_lock(&(result->cb_lock));
927 if(result->running == 1) {
928 ocs_log_err(ocs, "ocs_sem_p failed\n");
929 ocs_unlock(&(result->cb_lock));
932 /* sfp_cb() has already executed, proceed as normal */
933 ocs_unlock(&(result->cb_lock));
937 if (result->status != 0) {
938 ocs_log_test(ocs, "read_transceiver_data returned status %d\n",
944 rc = (result->bytes_read > buf_len ? buf_len : result->bytes_read);
945 /* Copy the results back to the supplied buffer */
946 ocs_memcpy(buf, result->page_data, rc);
949 ocs_free(ocs, result, sizeof(ocs_mgmt_sfp_result_t));
954 ocs_mgmt_force_assert(ocs_t *ocs, char *name, void *buf, uint32_t buf_len, void *arg_out, uint32_t arg_out_length)
956 ocs_assert(FALSE, 0);
960 get_nodes_count(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
962 ocs_xport_t *xport = ocs->xport;
964 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "nodes_count", "%d", xport->nodes_count);
968 get_driver_version(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
970 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "driver_version", ocs->driver_version);
974 get_desc(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
976 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "desc", ocs->desc);
980 get_fw_rev(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
982 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "fw_rev", ocs_hw_get_ptr(&ocs->hw, OCS_HW_FW_REV));
986 get_fw_rev2(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
988 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "fw_rev2", ocs_hw_get_ptr(&ocs->hw, OCS_HW_FW_REV2));
992 get_ipl(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
994 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "ipl", ocs_hw_get_ptr(&ocs->hw, OCS_HW_IPL));
998 get_hw_rev1(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1002 ocs_hw_get(&ocs->hw, OCS_HW_HW_REV1, &value);
1004 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "hw_rev1", "%u", value);
1008 get_hw_rev2(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1012 ocs_hw_get(&ocs->hw, OCS_HW_HW_REV2, &value);
1014 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "hw_rev2", "%u", value);
1018 get_hw_rev3(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1021 ocs_hw_get(&ocs->hw, OCS_HW_HW_REV3, &value);
1023 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "hw_rev3", "%u", value);
1027 get_wwnn(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1031 wwnn = ocs_hw_get_ptr(&ocs->hw, OCS_HW_WWN_NODE);
1033 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "wwnn", "0x%llx", (unsigned long long)ocs_htobe64(*wwnn));
1037 get_wwpn(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1041 wwpn = ocs_hw_get_ptr(&ocs->hw, OCS_HW_WWN_PORT);
1043 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "wwpn", "0x%llx", (unsigned long long)ocs_htobe64(*wwpn));
1047 get_fcid(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1050 if (ocs->domain && ocs->domain->attached) {
1051 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "fc_id", "0x%06x",
1052 ocs->domain->sport->fc_id);
1054 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "fc_id", "UNKNOWN");
1060 get_sn(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1066 pserial = ocs_scsi_get_property_ptr(ocs, OCS_SCSI_SERIALNUMBER);
1069 strncpy(sn_buf, (char*)pserial, len);
1071 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "sn", sn_buf);
1076 get_pn(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1082 pserial = ocs_scsi_get_property_ptr(ocs, OCS_SCSI_PARTNUMBER);
1085 strncpy(sn_buf, (char*)pserial, len);
1087 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "pn", sn_buf);
1089 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "pn", ocs->model);
1094 get_sli4_intf_reg(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1097 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "sli4_intf_reg", "0x%04x",
1098 ocs_config_read32(ocs, SLI4_INTF_REG));
1102 get_phy_port_num(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1104 char *phy_port = NULL;
1106 phy_port = ocs_scsi_get_property_ptr(ocs, OCS_SCSI_PORTNUM);
1108 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "phy_port_num", phy_port);
1110 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "phy_port_num", "unknown");
1114 get_asic_id(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1117 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "asic_id_reg", "0x%04x",
1118 ocs_config_read32(ocs, SLI4_ASIC_ID_REG));
1122 get_chip_type(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1126 uint32_t asic_gen_num;
1127 uint32_t asic_rev_num;
1129 char result_buf[80];
1132 family = (ocs_config_read32(ocs, SLI4_INTF_REG) & 0x00000f00) >> 8;
1133 asic_id = ocs_config_read32(ocs, SLI4_ASIC_ID_REG);
1134 asic_rev_num = asic_id & 0xff;
1135 asic_gen_num = (asic_id & 0xff00) >> 8;
1137 rev_id = ocs_config_read32(ocs, SLI4_PCI_CLASS_REVISION) & 0xff;
1142 ocs_strncpy(result_buf, "BE2 A", sizeof(result_buf));
1143 ocs_snprintf(tmp_buf, 2, "%d", rev_id);
1144 strcat(result_buf, tmp_buf);
1148 ocs_strncpy(result_buf, "BE3", sizeof(result_buf));
1149 if (rev_id >= 0x10) {
1150 strcat(result_buf, "-R");
1152 ocs_snprintf(tmp_buf, 3, " %c", ((rev_id & 0xf0) >> 4) + 'A');
1153 strcat(result_buf, tmp_buf);
1154 ocs_snprintf(tmp_buf, 2, "%d", rev_id & 0x0f);
1155 strcat(result_buf, tmp_buf);
1159 ocs_strncpy(result_buf, "Skyhawk A0", sizeof(result_buf));
1163 ocs_strncpy(result_buf, "Lancer A", sizeof(result_buf));
1164 ocs_snprintf(tmp_buf, 2, "%d", rev_id & 0x0f);
1165 strcat(result_buf, tmp_buf);
1168 /* Lancer B0 or D0 */
1169 ocs_strncpy(result_buf, "Lancer", sizeof(result_buf));
1170 ocs_snprintf(tmp_buf, 3, " %c", ((rev_id & 0xf0) >> 4) + 'A');
1171 strcat(result_buf, tmp_buf);
1172 ocs_snprintf(tmp_buf, 2, "%d", rev_id & 0x0f);
1173 strcat(result_buf, tmp_buf);
1176 ocs_strncpy(result_buf, "Lancer G6", sizeof(result_buf));
1179 /* Refer to ASIC_ID */
1180 switch(asic_gen_num) {
1182 ocs_strncpy(result_buf, "BE2", sizeof(result_buf));
1185 ocs_strncpy(result_buf, "BE3-R", sizeof(result_buf));
1188 ocs_strncpy(result_buf, "Skyhawk-R", sizeof(result_buf));
1191 ocs_strncpy(result_buf, "Corsair", sizeof(result_buf));
1194 ocs_strncpy(result_buf, "Lancer", sizeof(result_buf));
1197 ocs_strncpy(result_buf, "LancerG6", sizeof(result_buf));
1200 ocs_strncpy(result_buf, "Unknown", sizeof(result_buf));
1202 if (ocs_strcmp(result_buf, "Unknown") != 0) {
1203 ocs_snprintf(tmp_buf, 3, " %c", ((asic_rev_num & 0xf0) >> 4) + 'A');
1204 strcat(result_buf, tmp_buf);
1205 ocs_snprintf(tmp_buf, 2, "%d", asic_rev_num & 0x0f);
1206 strcat(result_buf, tmp_buf);
1210 ocs_strncpy(result_buf, "Unknown", sizeof(result_buf));
1213 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "chip_type", result_buf);
1218 get_pci_vendor(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1221 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "pci_vendor", "0x%04x", ocs->pci_vendor);
1225 get_pci_device(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1228 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "pci_device", "0x%04x", ocs->pci_device);
1232 get_pci_subsystem_vendor(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1235 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "pci_subsystem_vendor", "0x%04x", ocs->pci_subsystem_vendor);
1239 get_pci_subsystem_device(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1242 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "pci_subsystem_device", "0x%04x", ocs->pci_subsystem_device);
1246 get_tgt_rscn_delay(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1248 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "tgt_rscn_delay", "%ld", (unsigned long)ocs->tgt_rscn_delay_msec / 1000);
1252 get_tgt_rscn_period(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1254 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "tgt_rscn_period", "%ld", (unsigned long)ocs->tgt_rscn_period_msec / 1000);
1258 get_inject_drop_cmd(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1260 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "inject_drop_cmd", "%d",
1261 (ocs->err_injection == INJECT_DROP_CMD ? 1:0));
1265 get_inject_free_drop_cmd(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1267 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "inject_free_drop_cmd", "%d",
1268 (ocs->err_injection == INJECT_FREE_DROPPED ? 1:0));
1272 get_inject_drop_data(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1274 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "inject_drop_data", "%d",
1275 (ocs->err_injection == INJECT_DROP_DATA ? 1:0));
1279 get_inject_drop_resp(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1281 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "inject_drop_resp", "%d",
1282 (ocs->err_injection == INJECT_DROP_RESP ? 1:0));
1286 get_cmd_err_inject(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1288 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "cmd_err_inject", "0x%02x", ocs->cmd_err_inject);
1292 get_cmd_delay_value(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1294 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "cmd_delay_value", "%ld", (unsigned long)ocs->delay_value_msec);
1298 get_businfo(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1300 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "businfo", ocs->businfo);
1304 get_sfp_a0(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1311 page_data = ocs_malloc(ocs, SFP_PAGE_SIZE, OCS_M_ZERO | OCS_M_NOWAIT);
1312 if (page_data == NULL) {
1316 buf = ocs_malloc(ocs, (SFP_PAGE_SIZE * 3) + 1, OCS_M_ZERO | OCS_M_NOWAIT);
1318 ocs_free(ocs, page_data, SFP_PAGE_SIZE);
1322 bytes_read = ocs_mgmt_get_sfp(ocs, 0xa0, page_data, SFP_PAGE_SIZE);
1324 if (bytes_read <= 0) {
1325 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "sfp_a0", "(unknown)");
1328 uint8_t *s = page_data;
1329 int buffer_remaining = (SFP_PAGE_SIZE * 3) + 1;
1332 for (i = 0; i < bytes_read; i++) {
1333 bytes_added = ocs_snprintf(d, buffer_remaining, "%02x ", *s);
1336 buffer_remaining -= bytes_added;
1339 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "sfp_a0", buf);
1342 ocs_free(ocs, page_data, SFP_PAGE_SIZE);
1343 ocs_free(ocs, buf, (3 * SFP_PAGE_SIZE) + 1);
1347 get_sfp_a2(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1354 page_data = ocs_malloc(ocs, SFP_PAGE_SIZE, OCS_M_ZERO | OCS_M_NOWAIT);
1355 if (page_data == NULL) {
1359 buf = ocs_malloc(ocs, (SFP_PAGE_SIZE * 3) + 1, OCS_M_ZERO | OCS_M_NOWAIT);
1361 ocs_free(ocs, page_data, SFP_PAGE_SIZE);
1365 bytes_read = ocs_mgmt_get_sfp(ocs, 0xa2, page_data, SFP_PAGE_SIZE);
1367 if (bytes_read <= 0) {
1368 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "sfp_a2", "(unknown)");
1371 uint8_t *s = page_data;
1372 int buffer_remaining = (SFP_PAGE_SIZE * 3) + 1;
1375 for (i=0; i < bytes_read; i++) {
1376 bytes_added = ocs_snprintf(d, buffer_remaining, "%02x ", *s);
1379 buffer_remaining -= bytes_added;
1382 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "sfp_a2", buf);
1385 ocs_free(ocs, page_data, SFP_PAGE_SIZE);
1386 ocs_free(ocs, buf, (3 * SFP_PAGE_SIZE) + 1);
1390 get_debug_mq_dump(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1393 ocs_mgmt_emit_boolean(textbuf, MGMT_MODE_RW, "debug_mq_dump",
1394 ocs_debug_is_enabled(OCS_DEBUG_ENABLE_MQ_DUMP));
1398 get_debug_cq_dump(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1401 ocs_mgmt_emit_boolean(textbuf, MGMT_MODE_RW, "debug_cq_dump",
1402 ocs_debug_is_enabled(OCS_DEBUG_ENABLE_CQ_DUMP));
1406 get_debug_wq_dump(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1408 ocs_mgmt_emit_boolean(textbuf, MGMT_MODE_RW, "debug_wq_dump",
1409 ocs_debug_is_enabled(OCS_DEBUG_ENABLE_WQ_DUMP));
1413 get_debug_eq_dump(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1415 ocs_mgmt_emit_boolean(textbuf, MGMT_MODE_RW, "debug_eq_dump",
1416 ocs_debug_is_enabled(OCS_DEBUG_ENABLE_EQ_DUMP));
1420 get_logmask(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1423 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "logmask", "0x%02x", ocs->logmask);
1428 get_loglevel(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1431 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "loglevel", "%d", loglevel);
1436 get_current_speed(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1440 ocs_hw_get(&(ocs->hw), OCS_HW_LINK_SPEED, &value);
1442 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "current_speed", "%d", value);
1446 get_configured_speed(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1450 ocs_hw_get(&(ocs->hw), OCS_HW_LINK_CONFIG_SPEED, &value);
1452 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "configured_speed", "auto");
1454 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "configured_speed", "%d", value);
1460 get_current_topology(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1464 ocs_hw_get(&(ocs->hw), OCS_HW_TOPOLOGY, &value);
1465 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "current_topology", "%d", value);
1470 get_configured_topology(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1474 ocs_hw_get(&(ocs->hw), OCS_HW_CONFIG_TOPOLOGY, &value);
1475 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "configured_topology", "%d", value);
1480 get_current_link_state(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1482 ocs_xport_stats_t value;
1484 if (ocs_xport_status(ocs->xport, OCS_XPORT_PORT_STATUS, &value) == 0) {
1485 if (value.value == OCS_XPORT_PORT_ONLINE) {
1486 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "current_link_state", "online");
1488 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "current_link_state", "offline");
1494 get_configured_link_state(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1496 ocs_xport_stats_t value;
1498 if (ocs_xport_status(ocs->xport, OCS_XPORT_CONFIG_PORT_STATUS, &value) == 0) {
1499 if (value.value == OCS_XPORT_PORT_ONLINE) {
1500 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "configured_link_state", "online");
1502 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "configured_link_state", "offline");
1508 * @brief HW link config enum to mgmt string value mapping.
1510 * This structure provides a mapping from the ocs_hw_linkcfg_e
1511 * enum (enum exposed for the OCS_HW_PORT_SET_LINK_CONFIG port
1512 * control) to the mgmt string that is passed in by the mgmt application
1515 typedef struct ocs_mgmt_linkcfg_map_s {
1516 ocs_hw_linkcfg_e linkcfg;
1517 const char *mgmt_str;
1518 } ocs_mgmt_linkcfg_map_t;
1520 static ocs_mgmt_linkcfg_map_t mgmt_linkcfg_map[] = {
1521 {OCS_HW_LINKCFG_4X10G, OCS_CONFIG_LINKCFG_4X10G},
1522 {OCS_HW_LINKCFG_1X40G, OCS_CONFIG_LINKCFG_1X40G},
1523 {OCS_HW_LINKCFG_2X16G, OCS_CONFIG_LINKCFG_2X16G},
1524 {OCS_HW_LINKCFG_4X8G, OCS_CONFIG_LINKCFG_4X8G},
1525 {OCS_HW_LINKCFG_4X1G, OCS_CONFIG_LINKCFG_4X1G},
1526 {OCS_HW_LINKCFG_2X10G, OCS_CONFIG_LINKCFG_2X10G},
1527 {OCS_HW_LINKCFG_2X10G_2X8G, OCS_CONFIG_LINKCFG_2X10G_2X8G}};
1530 * @brief Get the HW linkcfg enum from the mgmt config string.
1532 * @param mgmt_str mgmt string value.
1534 * @return Returns the HW linkcfg enum corresponding to clp_str.
1536 static ocs_hw_linkcfg_e
1537 ocs_hw_linkcfg_from_mgmt(const char *mgmt_str)
1540 for (i = 0; i < ARRAY_SIZE(mgmt_linkcfg_map); i++) {
1541 if (ocs_strncmp(mgmt_linkcfg_map[i].mgmt_str,
1542 mgmt_str, ocs_strlen(mgmt_str)) == 0) {
1543 return mgmt_linkcfg_map[i].linkcfg;
1546 return OCS_HW_LINKCFG_NA;
1550 * @brief Get the mgmt string value from the HW linkcfg enum.
1552 * @param linkcfg HW linkcfg enum.
1554 * @return Returns the mgmt string value corresponding to the given HW linkcfg.
1557 ocs_mgmt_from_hw_linkcfg(ocs_hw_linkcfg_e linkcfg)
1560 for (i = 0; i < ARRAY_SIZE(mgmt_linkcfg_map); i++) {
1561 if (mgmt_linkcfg_map[i].linkcfg == linkcfg) {
1562 return mgmt_linkcfg_map[i].mgmt_str;
1565 return OCS_CONFIG_LINKCFG_UNKNOWN;
1569 * @brief Link configuration callback argument
1571 typedef struct ocs_mgmt_linkcfg_arg_s {
1572 ocs_sem_t semaphore;
1574 ocs_hw_linkcfg_e linkcfg;
1575 } ocs_mgmt_linkcfg_arg_t;
1578 * @brief Get linkcfg config value
1580 * @param ocs Pointer to the ocs structure.
1581 * @param name Not used.
1582 * @param textbuf The textbuf to which the result is written.
1587 get_linkcfg(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1589 const char *linkcfg_str = NULL;
1591 ocs_hw_linkcfg_e linkcfg;
1592 ocs_hw_get(&ocs->hw, OCS_HW_LINKCFG, &value);
1593 linkcfg = (ocs_hw_linkcfg_e)value;
1594 linkcfg_str = ocs_mgmt_from_hw_linkcfg(linkcfg);
1595 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "linkcfg", linkcfg_str);
1599 * @brief Get requested WWNN config value
1601 * @param ocs Pointer to the ocs structure.
1602 * @param name Not used.
1603 * @param textbuf The textbuf to which the result is written.
1608 get_req_wwnn(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1610 ocs_xport_t *xport = ocs->xport;
1612 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "requested_wwnn", "0x%llx", (unsigned long long)xport->req_wwnn);
1616 * @brief Get requested WWPN config value
1618 * @param ocs Pointer to the ocs structure.
1619 * @param name Not used.
1620 * @param textbuf The textbuf to which the result is written.
1625 get_req_wwpn(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1627 ocs_xport_t *xport = ocs->xport;
1629 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "requested_wwpn", "0x%llx", (unsigned long long)xport->req_wwpn);
1633 * @brief Get requested nodedb_mask config value
1635 * @param ocs Pointer to the ocs structure.
1636 * @param name Not used.
1637 * @param textbuf The textbuf to which the result is written.
1642 get_nodedb_mask(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
1644 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "nodedb_mask", "0x%08x", ocs->nodedb_mask);
1648 * @brief Set requested WWNN value.
1650 * @param ocs Pointer to the ocs structure.
1651 * @param name Not used.
1652 * @param value Value to which the linkcfg is set.
1654 * @return Returns 0 on success.
1658 set_req_wwnn(ocs_t *ocs, char *name, char *value)
1663 if (ocs_strcasecmp(value, "default") == 0) {
1666 else if (parse_wwn(value, &wwnn) != 0) {
1667 ocs_log_test(ocs, "Invalid WWNN: %s\n", value);
1671 rc = ocs_xport_control(ocs->xport, OCS_XPORT_WWNN_SET, wwnn);
1674 ocs_log_test(ocs, "OCS_XPORT_WWNN_SET failed: %d\n", rc);
1678 rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_OFFLINE);
1680 ocs_log_test(ocs, "port offline failed : %d\n", rc);
1683 rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_ONLINE);
1685 ocs_log_test(ocs, "port online failed : %d\n", rc);
1692 * @brief Set requested WWNP value.
1694 * @param ocs Pointer to the ocs structure.
1695 * @param name Not used.
1696 * @param value Value to which the linkcfg is set.
1698 * @return Returns 0 on success.
1702 set_req_wwpn(ocs_t *ocs, char *name, char *value)
1707 if (ocs_strcasecmp(value, "default") == 0) {
1710 else if (parse_wwn(value, &wwpn) != 0) {
1711 ocs_log_test(ocs, "Invalid WWPN: %s\n", value);
1715 rc = ocs_xport_control(ocs->xport, OCS_XPORT_WWPN_SET, wwpn);
1718 ocs_log_test(ocs, "OCS_XPORT_WWPN_SET failed: %d\n", rc);
1722 rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_OFFLINE);
1724 ocs_log_test(ocs, "port offline failed : %d\n", rc);
1727 rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_ONLINE);
1729 ocs_log_test(ocs, "port online failed : %d\n", rc);
1736 * @brief Set node debug mask value
1738 * @param ocs Pointer to the ocs structure.
1739 * @param name Not used.
1740 * @param value Value to which the nodedb_mask is set.
1742 * @return Returns 0 on success.
1745 set_nodedb_mask(ocs_t *ocs, char *name, char *value)
1747 ocs->nodedb_mask = ocs_strtoul(value, 0, 0);
1752 * @brief Set linkcfg config value.
1754 * @param ocs Pointer to the ocs structure.
1755 * @param name Not used.
1756 * @param value Value to which the linkcfg is set.
1758 * @return Returns 0 on success.
1761 set_linkcfg(ocs_t *ocs, char *name, char *value)
1763 ocs_hw_linkcfg_e linkcfg;
1764 ocs_mgmt_linkcfg_arg_t cb_arg;
1765 ocs_hw_rtn_e status;
1767 ocs_sem_init(&cb_arg.semaphore, 0, "mgmt_linkcfg");
1769 /* translate mgmt linkcfg string to HW linkcfg enum */
1770 linkcfg = ocs_hw_linkcfg_from_mgmt(value);
1772 /* set HW linkcfg */
1773 status = ocs_hw_port_control(&ocs->hw, OCS_HW_PORT_SET_LINK_CONFIG,
1774 (uintptr_t)linkcfg, ocs_mgmt_linkcfg_cb, &cb_arg);
1776 ocs_log_test(ocs, "ocs_hw_set_linkcfg failed\n");
1780 if (ocs_sem_p(&cb_arg.semaphore, OCS_SEM_FOREVER)) {
1781 ocs_log_err(ocs, "ocs_sem_p failed\n");
1785 if (cb_arg.status) {
1786 ocs_log_test(ocs, "failed to set linkcfg from HW status=%d\n",
1795 * @brief Linkcfg callback
1797 * @param status Result of the linkcfg get/set operation.
1798 * @param value Resulting linkcfg value.
1799 * @param arg Callback argument.
1804 ocs_mgmt_linkcfg_cb(int32_t status, uintptr_t value, void *arg)
1806 ocs_mgmt_linkcfg_arg_t *cb_arg = (ocs_mgmt_linkcfg_arg_t *)arg;
1807 cb_arg->status = status;
1808 cb_arg->linkcfg = (ocs_hw_linkcfg_e)value;
1809 ocs_sem_v(&cb_arg->semaphore);
1813 set_debug_mq_dump(ocs_t *ocs, char *name, char *value)
1817 if (ocs_strcasecmp(value, "false") == 0) {
1818 ocs_debug_disable(OCS_DEBUG_ENABLE_MQ_DUMP);
1820 } else if (ocs_strcasecmp(value, "true") == 0) {
1821 ocs_debug_enable(OCS_DEBUG_ENABLE_MQ_DUMP);
1831 set_debug_cq_dump(ocs_t *ocs, char *name, char *value)
1835 if (ocs_strcasecmp(value, "false") == 0) {
1836 ocs_debug_disable(OCS_DEBUG_ENABLE_CQ_DUMP);
1838 } else if (ocs_strcasecmp(value, "true") == 0) {
1839 ocs_debug_enable(OCS_DEBUG_ENABLE_CQ_DUMP);
1849 set_debug_wq_dump(ocs_t *ocs, char *name, char *value)
1853 if (ocs_strcasecmp(value, "false") == 0) {
1854 ocs_debug_disable(OCS_DEBUG_ENABLE_WQ_DUMP);
1856 } else if (ocs_strcasecmp(value, "true") == 0) {
1857 ocs_debug_enable(OCS_DEBUG_ENABLE_WQ_DUMP);
1867 set_debug_eq_dump(ocs_t *ocs, char *name, char *value)
1871 if (ocs_strcasecmp(value, "false") == 0) {
1872 ocs_debug_disable(OCS_DEBUG_ENABLE_EQ_DUMP);
1874 } else if (ocs_strcasecmp(value, "true") == 0) {
1875 ocs_debug_enable(OCS_DEBUG_ENABLE_EQ_DUMP);
1885 set_logmask(ocs_t *ocs, char *name, char *value)
1888 ocs->logmask = ocs_strtoul(value, NULL, 0);
1894 set_loglevel(ocs_t *ocs, char *name, char *value)
1897 loglevel = ocs_strtoul(value, NULL, 0);
1903 set_configured_speed(ocs_t *ocs, char *name, char *value)
1910 spd = ocs_strtoul(value, NULL, 0);
1912 if ((spd != 0) && (spd != 2000) && (spd != 4000) &&
1913 (spd != 8000) && (spd != 16000) && (spd != 32000)) {
1914 ocs_log_test(ocs, "unsupported speed %d\n", spd);
1918 ocs_log_debug(ocs, "Taking port offline\n");
1919 xport_rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_OFFLINE);
1920 if (xport_rc != 0) {
1921 ocs_log_test(ocs, "Port offline failed\n");
1924 ocs_log_debug(ocs, "Setting port to speed %d\n", spd);
1925 hw_rc = ocs_hw_set(&ocs->hw, OCS_HW_LINK_SPEED, spd);
1926 if (hw_rc != OCS_HW_RTN_SUCCESS) {
1927 ocs_log_test(ocs, "Speed set failed\n");
1931 /* If we failed to set the speed we still want to try to bring
1932 * the port back online */
1934 ocs_log_debug(ocs, "Bringing port online\n");
1935 xport_rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_ONLINE);
1936 if (xport_rc != 0) {
1945 set_configured_topology(ocs_t *ocs, char *name, char *value)
1952 topo = ocs_strtoul(value, NULL, 0);
1953 if (topo >= OCS_HW_TOPOLOGY_NONE) {
1957 ocs_log_debug(ocs, "Taking port offline\n");
1958 xport_rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_OFFLINE);
1959 if (xport_rc != 0) {
1960 ocs_log_test(ocs, "Port offline failed\n");
1963 ocs_log_debug(ocs, "Setting port to topology %d\n", topo);
1964 hw_rc = ocs_hw_set(&ocs->hw, OCS_HW_TOPOLOGY, topo);
1965 if (hw_rc != OCS_HW_RTN_SUCCESS) {
1966 ocs_log_test(ocs, "Topology set failed\n");
1970 /* If we failed to set the topology we still want to try to bring
1971 * the port back online */
1973 ocs_log_debug(ocs, "Bringing port online\n");
1974 xport_rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_ONLINE);
1975 if (xport_rc != 0) {
1984 set_configured_link_state(ocs_t *ocs, char *name, char *value)
1989 if (ocs_strcasecmp(value, "offline") == 0) {
1990 ocs_log_debug(ocs, "Setting port to %s\n", value);
1991 xport_rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_OFFLINE);
1992 if (xport_rc != 0) {
1993 ocs_log_test(ocs, "Setting port to offline failed\n");
1996 } else if (ocs_strcasecmp(value, "online") == 0) {
1997 ocs_log_debug(ocs, "Setting port to %s\n", value);
1998 xport_rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_ONLINE);
1999 if (xport_rc != 0) {
2000 ocs_log_test(ocs, "Setting port to online failed\n");
2004 ocs_log_test(ocs, "Unsupported link state \"%s\"\n", value);
2011 typedef struct ocs_mgmt_get_port_protocol_result {
2012 ocs_sem_t semaphore;
2014 ocs_hw_port_protocol_e port_protocol;
2015 } ocs_mgmt_get_port_protocol_result_t;
2019 ocs_mgmt_get_port_protocol_cb(int32_t status,
2020 ocs_hw_port_protocol_e port_protocol,
2023 ocs_mgmt_get_port_protocol_result_t *result = arg;
2025 result->status = status;
2026 result->port_protocol = port_protocol;
2028 ocs_sem_v(&(result->semaphore));
2032 get_port_protocol(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
2034 ocs_mgmt_get_port_protocol_result_t result;
2039 ocs_sem_init(&(result.semaphore), 0, "get_port_protocol");
2041 ocs_get_bus_dev_func(ocs, &bus, &dev, &func);
2043 if(ocs_hw_get_port_protocol(&ocs->hw, func, ocs_mgmt_get_port_protocol_cb, &result) == OCS_HW_RTN_SUCCESS) {
2044 if (ocs_sem_p(&(result.semaphore), OCS_SEM_FOREVER) != 0) {
2045 /* Undefined failure */
2046 ocs_log_err(ocs, "ocs_sem_p failed\n");
2048 if (result.status == 0) {
2049 switch (result.port_protocol) {
2050 case OCS_HW_PORT_PROTOCOL_ISCSI:
2051 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "port_protocol", "iSCSI");
2053 case OCS_HW_PORT_PROTOCOL_FCOE:
2054 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "port_protocol", "FCoE");
2056 case OCS_HW_PORT_PROTOCOL_FC:
2057 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "port_protocol", "FC");
2059 case OCS_HW_PORT_PROTOCOL_OTHER:
2060 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "port_protocol", "Other");
2064 ocs_log_test(ocs, "getting port profile status 0x%x\n", result.status);
2065 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "port_protocol", "Unknown");
2070 typedef struct ocs_mgmt_set_port_protocol_result {
2071 ocs_sem_t semaphore;
2073 } ocs_mgmt_set_port_protocol_result_t;
2078 ocs_mgmt_set_port_protocol_cb(int32_t status,
2081 ocs_mgmt_get_port_protocol_result_t *result = arg;
2083 result->status = status;
2085 ocs_sem_v(&(result->semaphore));
2089 * @brief Set port protocol
2091 * This is a management action handler to set the current
2092 * port protocol. Input value should be one of iSCSI,
2095 * @param ocs Pointer to the ocs structure.
2096 * @param name Name of the action being performed.
2097 * @param value The value to be assigned
2099 * @return Returns 0 on success, non-zero on failure.
2102 set_port_protocol(ocs_t *ocs, char *name, char *value)
2104 ocs_mgmt_set_port_protocol_result_t result;
2106 ocs_hw_port_protocol_e new_protocol;
2111 ocs_get_bus_dev_func(ocs, &bus, &dev, &func);
2113 ocs_sem_init(&(result.semaphore), 0, "set_port_protocol");
2115 if (ocs_strcasecmp(value, "iscsi") == 0) {
2116 new_protocol = OCS_HW_PORT_PROTOCOL_ISCSI;
2117 } else if (ocs_strcasecmp(value, "fc") == 0) {
2118 new_protocol = OCS_HW_PORT_PROTOCOL_FC;
2119 } else if (ocs_strcasecmp(value, "fcoe") == 0) {
2120 new_protocol = OCS_HW_PORT_PROTOCOL_FCOE;
2125 rc = ocs_hw_set_port_protocol(&ocs->hw, new_protocol, func,
2126 ocs_mgmt_set_port_protocol_cb, &result);
2127 if (rc == OCS_HW_RTN_SUCCESS) {
2128 if (ocs_sem_p(&(result.semaphore), OCS_SEM_FOREVER) != 0) {
2129 /* Undefined failure */
2130 ocs_log_err(ocs, "ocs_sem_p failed\n");
2133 if (result.status == 0) {
2138 ocs_log_test(ocs, "setting active profile status 0x%x\n",
2146 typedef struct ocs_mgmt_get_profile_list_result_s {
2147 ocs_sem_t semaphore;
2149 ocs_hw_profile_list_t *list;
2150 } ocs_mgmt_get_profile_list_result_t;
2153 ocs_mgmt_get_profile_list_cb(int32_t status, ocs_hw_profile_list_t *list, void *ul_arg)
2155 ocs_mgmt_get_profile_list_result_t *result = ul_arg;
2157 result->status = status;
2158 result->list = list;
2160 ocs_sem_v(&(result->semaphore));
2164 * @brief Get list of profiles
2166 * This is a management action handler to get the list of
2167 * profiles supported by the SLI port. Although the spec says
2168 * that all SLI platforms support this, only Skyhawk actually
2169 * has a useful implementation.
2171 * @param ocs Pointer to the ocs structure.
2172 * @param name Name of the action being performed.
2173 * @param textbuf Pointer to an ocs_textbuf, which is used to return the results.
2178 get_profile_list(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
2180 ocs_mgmt_get_profile_list_result_t result;
2182 ocs_sem_init(&(result.semaphore), 0, "get_profile_list");
2184 if(ocs_hw_get_profile_list(&ocs->hw, ocs_mgmt_get_profile_list_cb, &result) == OCS_HW_RTN_SUCCESS) {
2185 if (ocs_sem_p(&(result.semaphore), OCS_SEM_FOREVER) != 0) {
2186 /* Undefined failure */
2187 ocs_log_err(ocs, "ocs_sem_p failed\n");
2189 if (result.status == 0) {
2191 #define MAX_LINE_SIZE 520
2192 #define BUFFER_SIZE MAX_LINE_SIZE*40
2194 char result_line[MAX_LINE_SIZE];
2195 uint32_t bytes_left;
2198 result_buf = ocs_malloc(ocs, BUFFER_SIZE, OCS_M_ZERO);
2199 bytes_left = BUFFER_SIZE;
2201 for (i=0; i<result.list->num_descriptors; i++) {
2202 sprintf(result_line, "0x%02x:%s\n", result.list->descriptors[i].profile_id,
2203 result.list->descriptors[i].profile_description);
2204 if (strlen(result_line) < bytes_left) {
2205 strcat(result_buf, result_line);
2206 bytes_left -= strlen(result_line);
2211 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "profile_list", result_buf);
2213 ocs_free(ocs, result_buf, BUFFER_SIZE);
2214 ocs_free(ocs, result.list, sizeof(ocs_hw_profile_list_t));
2216 ocs_log_test(ocs, "getting profile list status 0x%x\n", result.status);
2221 typedef struct ocs_mgmt_get_active_profile_result {
2222 ocs_sem_t semaphore;
2224 uint32_t active_profile_id;
2225 } ocs_mgmt_get_active_profile_result_t;
2228 ocs_mgmt_get_active_profile_cb(int32_t status, uint32_t active_profile, void *ul_arg)
2230 ocs_mgmt_get_active_profile_result_t *result = ul_arg;
2232 result->status = status;
2233 result->active_profile_id = active_profile;
2235 ocs_sem_v(&(result->semaphore));
2238 #define MAX_PROFILE_LENGTH 5
2241 * @brief Get active profile
2243 * This is a management action handler to get the currently
2244 * active profile for an SLI port. Although the spec says that
2245 * all SLI platforms support this, only Skyhawk actually has a
2246 * useful implementation.
2248 * @param ocs Pointer to the ocs structure.
2249 * @param name Name of the action being performed.
2250 * @param textbuf Pointer to an ocs_textbuf, which is used to return the results.
2255 get_active_profile(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
2257 char result_string[MAX_PROFILE_LENGTH];
2258 ocs_mgmt_get_active_profile_result_t result;
2260 ocs_sem_init(&(result.semaphore), 0, "get_active_profile");
2262 if(ocs_hw_get_active_profile(&ocs->hw, ocs_mgmt_get_active_profile_cb, &result) == OCS_HW_RTN_SUCCESS) {
2263 if (ocs_sem_p(&(result.semaphore), OCS_SEM_FOREVER) != 0) {
2264 /* Undefined failure */
2265 ocs_log_err(ocs, "ocs_sem_p failed\n");
2267 if (result.status == 0) {
2269 sprintf(result_string, "0x%02x", result.active_profile_id);
2270 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "active_profile", result_string);
2272 ocs_log_test(ocs, "getting active profile status 0x%x\n", result.status);
2277 typedef struct ocs_mgmt_set_active_profile_result {
2278 ocs_sem_t semaphore;
2280 } ocs_mgmt_set_active_profile_result_t;
2284 ocs_mgmt_set_active_profile_cb(int32_t status, void *ul_arg)
2286 ocs_mgmt_get_profile_list_result_t *result = ul_arg;
2288 result->status = status;
2290 ocs_sem_v(&(result->semaphore));
2294 * @brief Set active profile
2296 * This is a management action handler to set the currently
2297 * active profile for an SLI port. Although the spec says that
2298 * all SLI platforms support this, only Skyhawk actually has a
2299 * useful implementation.
2301 * @param ocs Pointer to the ocs structure.
2302 * @param name Name of the action being performed.
2303 * @param value Requested new value of the property.
2305 * @return Returns 0 on success, non-zero on failure.
2308 set_active_profile(ocs_t *ocs, char *name, char *value)
2310 ocs_mgmt_set_active_profile_result_t result;
2312 int32_t new_profile;
2314 new_profile = ocs_strtoul(value, NULL, 0);
2316 ocs_sem_init(&(result.semaphore), 0, "set_active_profile");
2318 rc = ocs_hw_set_active_profile(&ocs->hw, ocs_mgmt_set_active_profile_cb, new_profile, &result);
2319 if (rc == OCS_HW_RTN_SUCCESS) {
2320 if (ocs_sem_p(&(result.semaphore), OCS_SEM_FOREVER) != 0) {
2321 /* Undefined failure */
2322 ocs_log_err(ocs, "ocs_sem_p failed\n");
2325 if (result.status == 0) {
2330 ocs_log_test(ocs, "setting active profile status 0x%x\n", result.status);
2337 typedef struct ocs_mgmt_get_nvparms_result {
2338 ocs_sem_t semaphore;
2343 uint32_t preferred_d_id;
2344 } ocs_mgmt_get_nvparms_result_t;
2347 ocs_mgmt_get_nvparms_cb(int32_t status, uint8_t *wwpn, uint8_t *wwnn, uint8_t hard_alpa,
2348 uint32_t preferred_d_id, void *ul_arg)
2350 ocs_mgmt_get_nvparms_result_t *result = ul_arg;
2352 result->status = status;
2353 ocs_memcpy(result->wwpn, wwpn, sizeof(result->wwpn));
2354 ocs_memcpy(result->wwnn, wwnn, sizeof(result->wwnn));
2355 result->hard_alpa = hard_alpa;
2356 result->preferred_d_id = preferred_d_id;
2358 ocs_sem_v(&(result->semaphore));
2366 * @param ocs Pointer to the ocs structure.
2367 * @param name Name of the action being performed.
2368 * @param textbuf Pointer to an ocs_textbuf, which is used to return the results.
2373 get_nv_wwpn(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
2375 char result_string[24];
2376 ocs_mgmt_get_nvparms_result_t result;
2378 ocs_sem_init(&(result.semaphore), 0, "get_nv_wwpn");
2380 if(ocs_hw_get_nvparms(&ocs->hw, ocs_mgmt_get_nvparms_cb, &result) == OCS_HW_RTN_SUCCESS) {
2381 if (ocs_sem_p(&(result.semaphore), OCS_SEM_FOREVER) != 0) {
2382 /* Undefined failure */
2383 ocs_log_err(ocs, "ocs_sem_p failed\n");
2386 if (result.status == 0) {
2387 /* Success. Copy wwpn from result struct to result string */
2388 sprintf(result_string, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
2389 result.wwpn[0], result.wwpn[1], result.wwpn[2],
2390 result.wwpn[3], result.wwpn[4], result.wwpn[5],
2391 result.wwpn[6], result.wwpn[7]);
2392 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "nv_wwpn", result_string);
2394 ocs_log_test(ocs, "getting wwpn status 0x%x\n", result.status);
2404 * @param ocs Pointer to the ocs structure.
2405 * @param name Name of the action being performed.
2406 * @param textbuf Pointer to an ocs_textbuf, which is used to return the results.
2411 get_nv_wwnn(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
2413 char result_string[24];
2414 ocs_mgmt_get_nvparms_result_t result;
2416 ocs_sem_init(&(result.semaphore), 0, "get_nv_wwnn");
2418 if(ocs_hw_get_nvparms(&ocs->hw, ocs_mgmt_get_nvparms_cb, &result) == OCS_HW_RTN_SUCCESS) {
2419 if (ocs_sem_p(&(result.semaphore), OCS_SEM_FOREVER) != 0) {
2420 /* Undefined failure */
2421 ocs_log_err(ocs, "ocs_sem_p failed\n");
2424 if (result.status == 0) {
2425 /* Success. Copy wwnn from result struct to result string */
2426 ocs_snprintf(result_string, sizeof(result_string), "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
2427 result.wwnn[0], result.wwnn[1], result.wwnn[2],
2428 result.wwnn[3], result.wwnn[4], result.wwnn[5],
2429 result.wwnn[6], result.wwnn[7]);
2430 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "nv_wwnn", result_string);
2432 ocs_log_test(ocs, "getting wwnn status 0x%x\n", result.status);
2438 * @brief Get accumulated node abort counts
2439 * @par Description Get the sum of all nodes abort count.
2441 * @param ocs Pointer to the ocs structure.
2442 * @param name Name of the action being performed.
2443 * @param textbuf Pointer to an ocs_textbuf, which is used to return the results.
2448 get_node_abort_cnt(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf)
2450 uint32_t abort_counts = 0;
2451 ocs_domain_t *domain;
2455 if (ocs_device_lock_try(ocs) != TRUE) {
2456 /* Didn't get the lock */
2460 /* Here the Device lock is held */
2461 ocs_list_foreach(&ocs->domain_list, domain) {
2462 if (ocs_domain_lock_try(domain) != TRUE) {
2463 /* Didn't get the lock */
2464 ocs_device_unlock(ocs);
2468 /* Here the Domain lock is held */
2469 ocs_list_foreach(&domain->sport_list, sport) {
2470 if (ocs_sport_lock_try(sport) != TRUE) {
2471 /* Didn't get the lock */
2472 ocs_domain_unlock(domain);
2473 ocs_device_unlock(ocs);
2477 /* Here the sport lock is held */
2478 ocs_list_foreach(&sport->node_list, node) {
2479 abort_counts += node->abort_cnt;
2482 ocs_sport_unlock(sport);
2485 ocs_domain_unlock(domain);
2488 ocs_device_unlock(ocs);
2490 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "node_abort_cnt", "%d" , abort_counts);
2493 typedef struct ocs_mgmt_set_nvparms_result {
2494 ocs_sem_t semaphore;
2496 } ocs_mgmt_set_nvparms_result_t;
2500 ocs_mgmt_set_nvparms_cb(int32_t status, void *ul_arg)
2502 ocs_mgmt_get_profile_list_result_t *result = ul_arg;
2504 result->status = status;
2506 ocs_sem_v(&(result->semaphore));
2511 * @par Description Sets the Non-volatile worldwide names,
2514 * @param ocs Pointer to the ocs structure.
2515 * @param name Name of the action being performed.
2516 * @param wwn_p Requested new WWN values.
2518 * @return Returns 0 on success, non-zero on failure.
2521 set_nv_wwn(ocs_t *ocs, char *name, char *wwn_p)
2523 ocs_mgmt_get_nvparms_result_t result;
2524 uint8_t new_wwpn[8];
2525 uint8_t new_wwnn[8];
2526 char *wwpn_p = NULL;
2527 char *wwnn_p = NULL;
2533 /* This is a read-modify-write operation, so first we have to read
2534 * the current values
2536 ocs_sem_init(&(result.semaphore), 0, "set_nv_wwn1");
2538 rc = ocs_hw_get_nvparms(&ocs->hw, ocs_mgmt_get_nvparms_cb, &result);
2540 if (rc == OCS_HW_RTN_SUCCESS) {
2541 if (ocs_sem_p(&(result.semaphore), OCS_SEM_FOREVER) != 0) {
2542 /* Undefined failure */
2543 ocs_log_err(ocs, "ocs_sem_p failed\n");
2546 if (result.status != 0) {
2547 ocs_log_test(ocs, "getting nvparms status 0x%x\n", result.status);
2552 /* wwn_p contains wwpn_p@wwnn_p values */
2553 if (wwn_p != NULL) {
2554 wwpn_p = ocs_strsep(&wwn_p, "@");
2558 wwpn = ocs_strcmp(wwpn_p, "NA");
2559 wwnn = ocs_strcmp(wwnn_p, "NA");
2561 /* Parse the new WWPN */
2562 if ((wwpn_p != NULL) && (wwpn != 0)) {
2563 if (ocs_sscanf(wwpn_p, "%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx",
2564 &(new_wwpn[0]), &(new_wwpn[1]), &(new_wwpn[2]),
2565 &(new_wwpn[3]), &(new_wwpn[4]), &(new_wwpn[5]),
2566 &(new_wwpn[6]), &(new_wwpn[7])) != 8) {
2567 ocs_log_test(ocs, "can't parse WWPN %s\n", wwpn_p);
2572 /* Parse the new WWNN */
2573 if ((wwnn_p != NULL) && (wwnn != 0 )) {
2574 if (ocs_sscanf(wwnn_p, "%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx",
2575 &(new_wwnn[0]), &(new_wwnn[1]), &(new_wwnn[2]),
2576 &(new_wwnn[3]), &(new_wwnn[4]), &(new_wwnn[5]),
2577 &(new_wwnn[6]), &(new_wwnn[7])) != 8) {
2578 ocs_log_test(ocs, "can't parse WWNN %s\n", wwnn_p);
2583 for (i = 0; i < 8; i++) {
2584 /* Use active wwpn, if new one is not provided */
2586 new_wwpn[i] = result.wwpn[i];
2589 /* Use active wwnn, if new one is not provided */
2591 new_wwnn[i] = result.wwnn[i];
2595 /* Modify the nv_wwnn and nv_wwpn, then write it back */
2596 ocs_sem_init(&(result.semaphore), 0, "set_nv_wwn2");
2598 rc = ocs_hw_set_nvparms(&ocs->hw, ocs_mgmt_set_nvparms_cb, new_wwpn,
2599 new_wwnn, result.hard_alpa, result.preferred_d_id,
2601 if (rc == OCS_HW_RTN_SUCCESS) {
2602 if (ocs_sem_p(&(result.semaphore), OCS_SEM_FOREVER) != 0) {
2603 /* Undefined failure */
2604 ocs_log_err(ocs, "ocs_sem_p failed\n");
2607 if (result.status != 0) {
2608 ocs_log_test(ocs, "setting wwn status 0x%x\n", result.status);
2617 set_tgt_rscn_delay(ocs_t *ocs, char *name, char *value)
2619 ocs->tgt_rscn_delay_msec = ocs_strtoul(value, NULL, 0) * 1000;
2620 ocs_log_debug(ocs, "mgmt set: %s %s\n", name, value);
2625 set_tgt_rscn_period(ocs_t *ocs, char *name, char *value)
2627 ocs->tgt_rscn_period_msec = ocs_strtoul(value, NULL, 0) * 1000;
2628 ocs_log_debug(ocs, "mgmt set: %s %s\n", name, value);
2633 set_inject_drop_cmd(ocs_t *ocs, char *name, char *value)
2635 ocs->err_injection = (ocs_strtoul(value, NULL, 0) == 0 ? NO_ERR_INJECT : INJECT_DROP_CMD);
2636 ocs_log_debug(ocs, "mgmt set: %s %s\n", name, value);
2641 set_inject_free_drop_cmd(ocs_t *ocs, char *name, char *value)
2643 ocs->err_injection = (ocs_strtoul(value, NULL, 0) == 0 ? NO_ERR_INJECT : INJECT_FREE_DROPPED);
2644 ocs_log_debug(ocs, "mgmt set: %s %s\n", name, value);
2649 set_inject_drop_data(ocs_t *ocs, char *name, char *value)
2651 ocs->err_injection = (ocs_strtoul(value, NULL, 0) == 0 ? NO_ERR_INJECT : INJECT_DROP_DATA);
2652 ocs_log_debug(ocs, "mgmt set: %s %s\n", name, value);
2657 set_inject_drop_resp(ocs_t *ocs, char *name, char *value)
2659 ocs->err_injection = (ocs_strtoul(value, NULL, 0) == 0 ? NO_ERR_INJECT : INJECT_DROP_RESP);
2660 ocs_log_debug(ocs, "mgmt set: %s %s\n", name, value);
2665 set_cmd_err_inject(ocs_t *ocs, char *name, char *value)
2667 ocs->cmd_err_inject = ocs_strtoul(value, NULL, 0);
2668 ocs_log_debug(ocs, "mgmt set: %s %s\n", name, value);
2673 set_cmd_delay_value(ocs_t *ocs, char *name, char *value)
2675 ocs->delay_value_msec = ocs_strtoul(value, NULL, 0);
2676 ocs->err_injection = (ocs->delay_value_msec == 0 ? NO_ERR_INJECT : INJECT_DELAY_CMD);
2677 ocs_log_debug(ocs, "mgmt set: %s %s\n", name, value);
2682 * @brief parse a WWN from a string into a 64-bit value
2684 * Given a pointer to a string, parse the string into a 64-bit
2685 * WWN value. The format of the string must be xx:xx:xx:xx:xx:xx:xx:xx
2687 * @param wwn_in pointer to the string to be parsed
2688 * @param wwn_out pointer to uint64_t in which to put the parsed result
2690 * @return 0 if successful, non-zero if the WWN is malformed and couldn't be parsed
2693 parse_wwn(char *wwn_in, uint64_t *wwn_out)
2705 rc = ocs_sscanf(wwn_in, "0x%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx",
2706 &byte0, &byte1, &byte2, &byte3,
2707 &byte4, &byte5, &byte6, &byte7);
2710 *wwn_out = ((uint64_t)byte0 << 56) |
2711 ((uint64_t)byte1 << 48) |
2712 ((uint64_t)byte2 << 40) |
2713 ((uint64_t)byte3 << 32) |
2714 ((uint64_t)byte4 << 24) |
2715 ((uint64_t)byte5 << 16) |
2716 ((uint64_t)byte6 << 8) |
2727 static char *mode_string(int mode);
2732 * @brief Generate the beginning of a numbered section in a management XML document.
2735 * This function begins a section. The XML information is appended to
2736 * the textbuf. This form of the function is used for sections that might have
2737 * multiple instances, such as a node or a SLI Port (sport). The index number
2738 * is appended to the name.
2740 * @param textbuf Pointer to the driver dump text buffer.
2741 * @param name Name of the section.
2742 * @param index Index number of this instance of the section.
2747 extern void ocs_mgmt_start_section(ocs_textbuf_t *textbuf, const char *name, int index)
2749 ocs_textbuf_printf(textbuf, "<%s instance=\"%d\">\n", name, index);
2754 * @brief Generate the beginning of an unnumbered section in a management XML document.
2757 * This function begins a section. The XML information is appended to
2758 * the textbuf. This form of the function is used for sections that have
2759 * a single instance only. Therefore, no index number is needed.
2761 * @param textbuf Pointer to the driver dump text buffer.
2762 * @param name Name of the section.
2767 extern void ocs_mgmt_start_unnumbered_section(ocs_textbuf_t *textbuf, const char *name)
2769 ocs_textbuf_printf(textbuf, "<%s>\n", name);
2774 * @brief Generate the end of a section in a management XML document.
2777 * This function ends a section. The XML information is appended to
2780 * @param textbuf Pointer to the driver dump text buffer.
2781 * @param name Name of the section.
2786 void ocs_mgmt_end_unnumbered_section(ocs_textbuf_t *textbuf, const char *name)
2788 ocs_textbuf_printf(textbuf, "</%s>\n", name);
2793 * @brief Generate the indexed end of a section in a management XML document.
2796 * This function ends a section. The XML information is appended to
2799 * @param textbuf Pointer to the driver dump text buffer.
2800 * @param name Name of the section.
2801 * @param index Index number of this instance of the section.
2806 void ocs_mgmt_end_section(ocs_textbuf_t *textbuf, const char *name, int index)
2809 ocs_textbuf_printf(textbuf, "</%s>\n", name);
2815 * @brief Generate a property, with no value, in a management XML document.
2818 * This function generates a property name. The XML information is appended to
2819 * the textbuf. This form of the function is used by the list functions
2820 * when the property name only (and not the current value) is given.
2822 * @param textbuf Pointer to the driver dump text buffer.
2823 * @param mode Defines whether the property is read(r)/write(w)/executable(x).
2824 * @param name Name of the property.
2829 void ocs_mgmt_emit_property_name(ocs_textbuf_t *textbuf, int mode, const char *name)
2831 ocs_textbuf_printf(textbuf, "<%s mode=\"%s\"/>\n", name, mode_string(mode));
2836 * @brief Generate a property with a string value in a management XML document.
2839 * This function generates a property name and a string value.
2840 * The XML information is appended to the textbuf.
2842 * @param textbuf Pointer to the driver dump text buffer.
2843 * @param mode Defines whether the property is read(r)/write(w)/executable(x).
2844 * @param name Name of the property.
2845 * @param value Value of the property.
2850 void ocs_mgmt_emit_string(ocs_textbuf_t *textbuf, int mode, const char *name, const char *value)
2852 ocs_textbuf_printf(textbuf, "<%s mode=\"%s\">%s</%s>\n", name, mode_string(mode), value, name);
2857 * @brief Generate a property with an integer value in a management XML document.
2860 * This function generates a property name and an integer value.
2861 * The XML information is appended to the textbuf.
2863 * @param textbuf Pointer to driver dump text buffer.
2864 * @param mode Defines whether the property is read(r)/write(w)/executable(x).
2865 * @param name Name of the property.
2866 * @param fmt A printf format for formatting the integer value.
2871 void ocs_mgmt_emit_int(ocs_textbuf_t *textbuf, int mode, const char *name, const char *fmt, ...)
2877 ocs_vsnprintf(valuebuf, sizeof(valuebuf), fmt, ap);
2880 ocs_textbuf_printf(textbuf, "<%s mode=\"%s\">%s</%s>\n", name, mode_string(mode), valuebuf, name);
2885 * @brief Generate a property with a boolean value in a management XML document.
2888 * This function generates a property name and a boolean value.
2889 * The XML information is appended to the textbuf.
2891 * @param textbuf Pointer to the driver dump text buffer.
2892 * @param mode Defines whether the property is read(r)/write(w)/executable(x).
2893 * @param name Name of the property.
2894 * @param value Boolean value to be added to the textbuf.
2899 void ocs_mgmt_emit_boolean(ocs_textbuf_t *textbuf, int mode, const char *name, int value)
2901 char *valuebuf = value ? "true" : "false";
2903 ocs_textbuf_printf(textbuf, "<%s mode=\"%s\">%s</%s>\n", name, mode_string(mode), valuebuf, name);
2906 static char *mode_string(int mode)
2908 static char mode_str[4];
2911 if (mode & MGMT_MODE_RD) {
2912 strcat(mode_str, "r");
2914 if (mode & MGMT_MODE_WR) {
2915 strcat(mode_str, "w");
2917 if (mode & MGMT_MODE_EX) {
2918 strcat(mode_str, "x");