Emulex Logo
OneCoreā„¢ Storage SDK Release 11.2
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
elxu_commands.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2018, Emulex
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
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.
14  *
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.
18  *
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.
30  *
31  */
32 
33 /**
34  * @file
35  * Defines the elxsdkutil command handlers.
36  */
37 
38  /**
39  *
40  * @defgroup cmd_handler Command Handlers
41  *
42  */
43 
44 #include <stdio.h>
45 #include <getopt.h>
46 #include <string.h>
47 #include <stdlib.h>
48 #include <sys/ioctl.h>
49 #include <ctype.h>
50 #include <fcntl.h>
51 
52 #include "version.h"
53 #include "elxu_commands.h"
54 #include "elxu_common.h"
55 #include "elxu_dwnld.h"
56 #include "elxu_device.h"
57 #include "elxu_dump.h"
58 #include "elxu_mgmt.h"
59 #include "elx_pt_ioctl.h"
60 
61 #include <ocs_ioctl.h>
62 
63 #define PORTSPEED_1GFC 0x00000001 /* 1G FC */
64 #define PORTSPEED_2GFC 0x00000002 /* 2G FC */
65 #define PORTSPEED_4GFC 0x00000008 /* 4G FC */
66 #define PORTSPEED_8GFC 0x00000010 /* 8G FC */
67 #define PORTSPEED_16GFC 0x00000020 /* 16G FC */
68 #define PORTSPEED_32GFC 0x00000040 /* 32G FC */
69 #define PORTSPEED_64GFC 0x00000400 /* 64G FC*/
70 #define PORTSPEED_128GFC 0x00000200 /* 128G FC */
71 #define PORTSPEED_UNKNOWN 0x00008000 /* Unknown*/
72 char *supported_linkcfgs[] = {
80 
81 #define ETH_FC_AUTO "0"
82 #define ETH_FC_10G "1000"
83 #define FC_2G "2000"
84 #define FC_4G "4000"
85 #define FC_8G "8000"
86 #define FC_16G "16000"
87 #define FC_32G "32000"
88 
91  ETH_FC_10G,
92  FC_2G,
93  FC_4G,
94  FC_8G,
95  FC_16G,
96  FC_32G};
97 
98 #define AUTO "0"
99 #define N_PORT "1"
100 #define LOOP "2"
102  AUTO,
103  N_PORT,
104  LOOP
105 };
106 
107 #define OCS_MAX_SLI_PORTS_PER_DEVICE 4
108 
109 #define OCS_FC_TRUNK_2_PORT_CONFIG 0x30
110 #define OCS_FC_TRUNK_2_PORT_HI_CONFIG 0xC0
111 #define OCS_FC_TRUNK_4_PORT_CONFIG 0xF0
112 
113 #define OCS_FC_TRUNK_CONFIG_MASK 0xF0
114 #define OCS_FC_TRUNK_LINK_STATE_MASK 0x0F
115 
116 static void show_examples();
117 
118 typedef struct elx_sfp_transceiver_data_A0_s {
119  uint8_t identifier;
120  uint8_t ext_identifier;
121  uint8_t connector;
122  uint8_t transceiver[8];
123  uint8_t encoding;
124  uint8_t br_nominal;
125  uint8_t rate_id;
126  uint8_t length_9um_km;
127  uint8_t length_9um;
128  uint8_t length_50um;
129  uint8_t length_62_5_um;
130  uint8_t len_copper;
131  uint8_t length_om3;
132  char vendor_name[16];
133  uint8_t transciever;
134  uint8_t vendor_oui[3];
135  char vendor_pn[16];
136  char vendor_rev[4];
137  uint8_t wavelength[2];
138  uint8_t unallocated;
139  uint8_t cc_base;
140  uint8_t options[2];
141  uint8_t br_max;
142  uint8_t br_min;
143  char vendor_sn[16];
144  uint8_t date_code[8];
146  uint8_t enhance_opt;
148  uint8_t cc_ext;
149  uint8_t vendor_specific[32];
151 
152 typedef struct {
153  char* vendor;
154  char* vendor_pn;
155  char* vendor_rev; /* Note: This is minimum rev number */
156  uint8_t length_copper;
158 
159 
160 typedef struct {
161  char* vendor_pn;
163 
164 /**
165  * @ingroup cmd_handler
166  * @brief Command handler for the file-info command.
167  *
168  * @par Description
169  * This function processes the file-info command. <br><br>
170  * Command:</b> file-info <br>
171  * Required Parameters: <filename> <br>
172  * Optional Parameters: None <br>
173  * Supported Devices: N/A<br>
174  * Supported Protocols: N/A<br>
175  *
176  * @param argc The number of command line arguments.
177  * @param argv An array of pointers to the command line
178  * arguments.
179  *
180  * @return Returns 0 on success; or a non-zero error code value
181  * on failure.
182  */
183 int elxu_cmd_file_info(int argc, char **argv)
184 {
185  cmd_options_t options;
186  if (argc < 3) {
187  fprintf(stderr, "Filename is required\n");
188  return -1;
189  }
190 
191  /* Parse arguments, to pick up a --host argument */
192  if (parse_arguments(argc, argv, &options, 0, 1) == -1) {
193  return -1;
194  }
195 
196  if (options.file == NULL) {
197  fprintf(stderr, "Filename missing\n");
198  return -1;
199  }
200 
201  printf("file: %s \n", options.file);
202  file_handler(NULL, options.file, FW_FILE_DISPLAY_INFO);
203  return 0;
204 }
205 
206 /**
207  * @ingroup cmd_handler
208  * @brief Command handler for the list command.
209  *
210  * @par Description
211  * This function processes the list command.
212  *
213  * Command: list <br>
214  * Required Parameters: None <br>
215  * Optional Parameters: None <br>
216  * Supported Devices: N/A <br>
217  * Supported Protocols: N/A<br>
218  *
219  * @param argc The number of command line arguments.
220  * @param argv An array of pointers to the command line
221  * arguments.
222  *
223  * @return Returns 0 on success; or a non-zero error code value
224  * on failure.
225  */
226 int elxu_cmd_list(int argc, char **argv)
227 {
228  cmd_options_t options;
229 
230  /* Parse arguments, to pick up a --host argument */
231  if (parse_arguments(argc, argv, &options, 0, 1) == -1) {
232  return -1;
233  }
234 
236  return 0;
237 }
238 
239 /**
240  * @ingroup cmd_handler
241  * @brief Command handler for the read command.
242  *
243  * @par Description
244  * This function processes the read command.
245  *
246  * Command: read<br>
247  * Required Parameters: <objname> <br>
248  * Optional Parameters: -d <device> -f <filename> <br>
249  * Supported Devices: Lancer <br>
250  * Supported Protocols: N/A<br>
251  *
252  * @param argc The number of command line arguments.
253  * @param argv An array of pointers to the command line arguments.
254  *
255  * @return Returns 0 on success; or a non-zero error code value on failure.
256  */
257 int elxu_cmd_read(int argc, char **argv)
258 {
259  char *objname = NULL;
260  cmd_options_t options;
261 
262  if (argc < 3) {
263  fprintf(stderr, "objname is required\n");
264  return -1;
265  }
266 
267  objname = argv[2];
268 
269  if (parse_arguments(argc, argv, &options, 1, 2) == -1) {
270  return -1;
271  }
272 
273  if (objname == NULL) {
274  printf ("Missing object name argument\n");
275  return -1;
276  }
277 
278  /* Read Obj only supported for Lancer */
279  if(!is_lancer(options.device) && !is_prism(options.device)) {
280  fprintf(stderr, "readobj is only supported on Lancer/Prism\n");
281  return -1;
282  }
283 
284  hba_data_object_upload (options.device, objname, options.file);
285 
286  return 0;
287 }
288 
289 /**
290  * @ingroup cmd_handler
291  * @brief Command handler for the write command.
292  *
293  * @par Description
294  * This function processes the write command.
295  *
296  * Command: write <br>
297  * Required Parameters: -f <filename> <br>
298  * Optional Parameters: -d <device> <br>
299  * Supported Devices: Any <br>
300  * Supported Protocols: N/A<br>
301  *
302  * @param argc The number of command line arguments.
303  * @param argv An array of pointers to the command line arguments.
304  *
305  * @return Returns 0 on success; or a non-zero error code value on failure.
306  */
307 int elxu_cmd_write(int argc, char **argv)
308 {
309  cmd_options_t options;
310 
311  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
312  return -1;
313  }
314 
315  if (options.device == NULL) {
316  fprintf(stderr, "Unable to open device\n");
317  return -1;
318  }
319 
320  if (options.file == NULL) {
321  fprintf(stderr, "Filename missing\n");
322  return -1;
323  }
324 
325  return file_handler (options.device, options.file, FW_FILE_DOWNLOAD);
326 }
327 
328 /**
329  * @ingroup cmd_handler
330  * @brief Command handler for the version command.
331  *
332  * @par Description
333  * This function processes the version command.
334  *
335  * Command: version <br>
336  * Required Parameters: None <br>
337  * Optional Parameters: None <br>
338  * Supported Devices: N/A <br>
339  * Supported Protocols: N/A<br>
340  *
341  * @param argc The number of command line arguments.
342  * @param argv An array of pointers to the command line arguments.
343  *
344  * @return Returns 0 on success; or a non-zero error code value on failure.
345  */
346 int elxu_cmd_version(int argc, char **argv)
347 {
348  printf ("\nVersion %s\n", ELXU_VERSION);
349  return 0;
350 }
351 
352 /**
353  * @ingroup cmd_handler
354  * @brief Command handler for the cmp command.
355  *
356  * @par Description
357  * This function processes the cmp command.
358  *
359  * Command: cmp <br>
360  * Required Parameters: -f <filename> <br>
361  * Optional Parameters: -d <device> <br>
362  * Supported Devices: Skyhawk <br>
363  * Supported Protocols: N/A<br>
364  *
365  * @param argc The number of command line arguments.
366  * @param argv An array of pointers to the command line arguments.
367  *
368  * @return Returns 0 on success; or a non-zero error code value on failure.
369  */
370 int elxu_cmd_cmp(int argc, char **argv)
371 {
372  cmd_options_t options;
373 
374  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
375  return -1;
376  }
377 
378  if (options.device == NULL) {
379  fprintf(stderr, "Unable to open device\n");
380  return -1;
381  }
382 
383  if (options.file == NULL) {
384  fprintf(stderr, "Filename missing\n");
385  return -1;
386  }
387 
388  return file_handler (options.device, options.file, FW_FILE_VERIFY);
389 }
390 
391 /**
392  * @ingroup cmd_handler
393  * @brief Command handler for the dump command.
394  *
395  * @par Description
396  * This function processes the dump command.
397  *
398  * Command: dump <br>
399  * Required Parameters: None <br>
400  * Optional Parameters: dump type (--fat, --efd, --ecd), -f <filename>, -d <device> <br>
401  * Supported Devices: Any <br>
402  * Supported Protocols: N/A<br>
403  *
404  * @param argc The number of command line arguments.
405  * @param argv An array of pointers to the command line arguments.
406  *
407  * @return Returns 0 on success; or a non-zero error code value on failure.
408  */
409 int elxu_cmd_dump(int argc, char **argv)
410 {
411  cmd_options_t options;
412  data_type_req_t dump_type;
413  int rc;
414 
415  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
416  return -1;
417  }
418 
419  if (options.device == NULL) {
420  fprintf(stderr, "Unable to open device\n");
421  return -1;
422  }
423 
424  if (is_lancer(options.device) || is_prism(options.device)) {
425  /* No dump type option for Lancer */
426  if ((options.fat) || (options.efd) || (options.ecd) || (options.ecd_test)) {
427  fprintf(stderr, "Dump type option does not apply to Lancer/Prism\n");
428  return -1;
429  }
430  dump_type = LANCER_DUMP;
431  } else {
432  /* Could be ecd, ecdtest, fat, or efd. Default is ecd */
433  dump_type = ECD_DATA;
434 
435  /* Verify that no more than one dump type is selected */
436  if ((options.fat + options.efd + options.ecd + options.ecd_test) > 1) {
437  fprintf(stderr, "Choose no more than one of --fat, --efd, --ecd, or --ecdtest\n");
438  return -1;
439  }
440  if (options.efd) {
441  dump_type = EFD_DATA;
442  } else if (options.fat) {
443  dump_type = FAT_DATA;
444  }
445  }
446 
447  switch(dump_type) {
448  case FAT_DATA:
449  case EFD_DATA:
450  case LANCER_DUMP:
451  rc = hba_data_upload (options.device, options.file, dump_type);
452  break;
453  case ECD_DATA:
454  /*
455  * Because of the way ioctls are implemented in the user space driver an ECD
456  * is very slow (several days to get a dump.) For that reason ECD dump is
457  * not supported with the userspace driver.
458  */
459  if (is_uspace(options.device)) {
460  fprintf(stderr, "ECD dump not supported with user space driver.\n");
461  return -1;
462  }
463  rc = elxu_core_dump(options.device, options.file, options.ecd_test);
464  break;
465  default:
466  /* This shouldn't happen */
467  fprintf(stderr, "No dump type selected\n");
468  rc = -1;
469 
470  }
471 
472  return rc;
473 }
474 
475 /**
476  * @ingroup cmd_handler
477  * @brief Command handler for the efdc command.
478  *
479  * @par Description
480  * This function processes the efdc command.
481  *
482  * Command: efdc <br>
483  * Required Parameters: None <br>
484  * Optional Parameters: -f <filename>, -d <device> <br>
485  * Supported Devices: Skyhawk <br>
486  * Supported Protocols: N/A<br>
487  *
488  * @param argc The number of command line arguments.
489  * @param argv An array of pointers to the command line arguments.
490  *
491  * @return Returns 0 on success; or a non-zero error code value on failure.
492  */
493 int elxu_cmd_efdc(int argc, char **argv)
494 {
495  cmd_options_t options;
496 
497  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
498  return -1;
499  }
500 
501  if (options.device == NULL) {
502  fprintf(stderr, "Unable to open device\n");
503  return -1;
504  }
505 
506  if (!is_skyhawk(options.device)) {
507  fprintf(stderr, "efdc is only supported on Skyhwawk\n");
508  return -1;
509  }
510 
511  return ext_fat_capabilities_upld(options.device);
512 }
513 
514 /**
515  * @ingroup cmd_handler
516  * @brief Command handler for the objenum command.
517  *
518  * @par Description
519  * This function processes the objenum command.
520  *
521  * Command: objenum <br>
522  * Required Parameters: None <br>
523  * Optional Parameters: -d <device> <br>
524  * Supported Devices: Lancer <br>
525  * Supported Protocols: N/A<br>
526  *
527  * @param argc The number of command line arguments.
528  * @param argv An array of pointers to the command line arguments.
529  *
530  * @return Returns 0 on success; or a non-zero error code value on failure.
531  */
532 int elxu_cmd_objenum(int argc, char **argv)
533 {
534  sli4_object_t *objlist;
535  sli4_object_t *obj;
536  int cnt = 0;
537  cmd_options_t options;
538 
539  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
540  return -1;
541  }
542 
543  if (options.device == NULL) {
544  fprintf(stderr, "Unable to open device\n");
545  return -1;
546  }
547 
548  if (!is_lancer(options.device) && !is_prism(options.device)) {
549  fprintf(stderr, "objenum is only supported on Lancer/Prism\n");
550  return -1;
551  }
552 
553  objlist = sli4_object_enumerate(options.device);
554 
555  for (obj = objlist; obj; obj=obj->next, cnt++) {
556  if (obj->type != OFT_DIRECTORY_OBJECT) {
557  printf ("[%2d] %-20s ......... %6d\n",
558  cnt, obj->name, obj->length);
559  } else {
560  printf ("[%2d] %-20s \n", cnt, obj->name);
561  }
562  }
563  sli4_object_free_list (objlist);
564  return 0;
565 }
566 char * elxu_decode_sfp_id(uint32_t value)
567 {
568  char *identify = "UNKNOWN";
569  switch (value) {
570  case 0x0:
571  identify = "Unknown";
572  break;
573  case 0x1:
574  identify = "GBIC";
575  break;
576  case 0x2:
577  identify = "Module/connector soldered to motherboard ";
578  break;
579  case 0x3:
580  identify = "SFP";
581  break;
582  case 0x4:
583  identify = "300 pin XBI";
584  break;
585  case 0x5:
586  identify = "XENPAK";
587  break;
588  case 0x6:
589  identify = "XFP";
590  break;
591  case 0xC:
592  identify = "QSFP";
593  break;
594  default:
595  identify = "Refer Spec";
596  }
597 
598  return identify;
599 }
600 char * elxu_decode_sfp_connector(uint32_t value)
601 {
602  char *identify = "UNKNOWN";
603 
604  switch (value) {
605  case 0x0:
606  identify = "Unknown";
607  break;
608  case 0x1:
609  identify = "SC";
610  break;
611  case 0x2:
612  identify = "Fibre Channel Style 1 copper connector";
613  break;
614  case 0x3:
615  identify = "Fibre Channel Style 2 copper connector";
616  break;
617  case 0x4:
618  identify = "BNC/TNC";
619  break;
620  case 0x5:
621  identify = "Fibre Channel coaxial headers";
622  break;
623  case 0x6:
624  identify = "FiberJack";
625  break;
626  case 0x7:
627  identify = "LC";
628  break;
629  default:
630  identify = "Refer Spec";
631  }
632 
633  return identify;
634 }
635 
636 char * elxu_decode_sfp_rate_id(uint32_t value)
637 {
638  char *identify;
639 
640  switch (value) {
641  case 0x1:
642  identify = "SFF-8079";
643  break;
644  case 0x2:
645  case 0x4:
646  case 0x6:
647  identify = "SFF-8431";
648  break;
649  case 0x8:
650  case 0xA:
651  identify = "FC-PI-5";
652  break;
653  default:
654  identify = "Unspecified";
655  }
656  return identify;
657 }
658 
659 char * elxu_sfp_encoding_info(uint32_t value)
660 {
661  char *identify;
662 
663  switch (value) {
664  case 0x0:
665  identify = "Unspecified";
666  break;
667  case 0x1:
668  identify = "8B10B";
669  break;
670  case 0x2:
671  identify = "4B5B";
672  break;
673  case 0x3:
674  identify = "NRZ";
675  break;
676  case 0x4:
677  identify = "Manchester";
678  break;
679  case 0x5:
680  identify = "SONET Scrambled";
681  break;
682  case 0x6:
683  identify = "64B/66B";
684  break;
685  default:
686  identify = "Unspecified";
687  }
688  return identify;
689 }
690 
692 {
693  int rc;
694  uint32_t *resp_buff;
695 
696  resp_buff = malloc(OCS_DUMP_TYPE4_WKI_TAG_SAT_TEM_RESP_LEN);
697  if (resp_buff == NULL) {
698  perror("malloc");
699  return -1;
700  }
701 
702  memset(resp_buff, 0, OCS_DUMP_TYPE4_WKI_TAG_SAT_TEM_RESP_LEN);
703  rc = elxu_device_exec(device, "/ocs/driver/lancer_temp", NULL, 0,
705  if (rc != 0) {
706  printf("Get board temperature failed\n");
707  free(resp_buff);
708  return -1;
709  }
710 
711  /*
712  * Following is the format of resp buffer:
713  * Word 0 - curr_temp
714  * Word 1 - crit_temp_thrshld
715  * Word 2 - warn_temp_thrshld
716  * Word 3 - norm_temp_thrshld
717  * Word 4 - fan_off_thrshld
718  * Word 5 - fan_on_thrshld
719  */
720  printf("Device %d temperature details - \n", device->deviceIndex);
721  printf("\tCurrent temperature: \t %d degrees\n\n", resp_buff[0]);
722  printf("\tCritical temperature threshold:\t %d degrees\n", resp_buff[1]);
723  printf("\tWarning temperature threshold: \t %d degrees\n", resp_buff[2]);
724 
725  free(resp_buff);
726  return rc;
727 }
728 
729 /**
730  * @ingroup cmd_handler
731  * @brief Command handler for the board temperature.
732  *
733  * @par Description
734  * This function processes the Dump Type 4 (Well Known Item) command for Lancer.
735  * WKI selection ID 0x1040 (WKI_TAG_SAT_TEM) to read board temperature data.
736  *
737  * Command: boardtemp <br>
738  * Required Parameters: None <br>
739  * Optional Parameters: -d <device> <br>
740  * Supported Devices: Lancer <br>
741  * Supported Protocols: N/A <br>
742  *
743  * @param argc The number of command line arguments.
744  * @param argv An array of pointers to the command line arguments.
745  *
746  * @return Returns 0 on success; or a non-zero error code value on failure.
747  */
748 int elxu_cmd_board_temp(int argc, char **argv)
749 {
750  cmd_options_t options;
751 
752  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
753  return -1;
754  }
755 
756  /* Board temperature supported for Lancer */
757  if (!is_lancer(options.device)) {
758  printf("boardtemp is only supproted on Lancer\n");
759  return -1;
760  }
761 
762  if (is_uspace(options.device)) {
763  printf("boardtemp is not supported with the user space driver\n");
764  return -1;
765  }
766 
767  return elxu_device_get_lancer_temp(options.device);
768 }
769 
770 /**
771  * @ingroup cmd_handler
772  * @brief Command handler for the sfp command.
773  *
774  * @par Description
775  * This function processes the sfp command.
776  * sfp data returned by the mgmt api is an ASCII string of hex values
777  * but it isn't formatted nicely. This function retrives the string,
778  * converts it to binary, then uses dump8() to display it nicely
779  * formatted.
780  *
781  * Command: sfp <br>
782  * Required Parameters: None <br>
783  * Optional Parameters: -d <device> <br>
784  * Supported Devices: All <br>
785  * Supported Protocols: N/A<br>
786  *
787  * @param argc The number of command line arguments.
788  * @param argv An array of pointers to the command line arguments.
789  *
790  * @return Returns 0 on success; or a non-zero error code value on failure.
791  */
792 int elxu_cmd_sfp(int argc, char **argv)
793 {
794  uint8_t transceiver_buffer[TRANSCEIVER_INFO_PAGE_SIZE];
795  elx_sfp_transceiver_data_A0_t a0_page_info;
796  cmd_options_t options;
797  char *value;
798  char *s;
799  uint8_t *d;
800 
801  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
802  return -1;
803  }
804 
805  if (options.device == NULL) {
806  fprintf(stderr, "Unable to open device\n");
807  return -1;
808  }
809 
810  value = elxu_device_get_value(options.device, "/ocs/sfp_a0");
811  if ((strcmp(value, "no-sfp") == 0)) {
812  printf("Warning: No SFP module present on this device.\n");
813  }
814  if ((strlen(value) != 0) && (strcmp(value, "(unknown)") != 0) && (strcmp(value, "no-sfp") != 0)) {
815  d = transceiver_buffer;
816  s = value;
817  while (isalnum(*s)) {
818  *d = (uint8_t) strtoul(s, NULL, 16);
819  ++d;
820  s += 3;
821  }
822 
823  if (!options.sfp_diag_data && !options.sfp_xceiver_data) {
824  dump8("Hex information from page 0xA0 ---\n", transceiver_buffer,
826  printf("\n");
827  }
828 
829  if (options.sfp_xceiver_data) {
830  int i = 0;
831 
832  memcpy(&a0_page_info, transceiver_buffer, min(TRANSCEIVER_INFO_PAGE_SIZE, sizeof(a0_page_info)));
833 
834  printf("\n\nSFP Transceiver data\n");
835  printf("==============================================================================\n");
836  printf("Identifier : 0x%x(%s)\n", a0_page_info.identifier, elxu_decode_sfp_id(a0_page_info.identifier));
837  printf("Ext Identifier: : 0x%x(%s)\n", a0_page_info.ext_identifier,
838  (a0_page_info.ext_identifier == 0x4) ? "non-custom SFP, SFP+ and GBIC module": "Unknown");
839  printf("Connector : 0x%x (%s)\n", a0_page_info.connector, elxu_decode_sfp_connector(a0_page_info.connector));
840  printf("Transceiver codes : 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
841  a0_page_info.transceiver[0], a0_page_info.transceiver[1],a0_page_info.transceiver[2],a0_page_info.transceiver[3],
842  a0_page_info.transceiver[4],a0_page_info.transceiver[5],a0_page_info.transceiver[6],a0_page_info.transceiver[7]);
843 
844  printf("FC Transceiver Speed : ");
845  for (i = 0; i < 8; i++) {
846  if (a0_page_info.transceiver[7] & (1 << i)) {
847  switch (i) {
848  case 0:
849  printf("100 MBytes/sec ");
850  break;
851  case 1:
852  printf("Unallocated ");
853  break;
854  case 2:
855  printf("200 MBytes/sec ");
856  break;
857  case 3:
858  printf("3200 MBytes/sec ");
859  break;
860  case 4:
861  printf("400 MBytes/sec ");
862  break;
863  case 5:
864  printf("1600 MBytes/sec ");
865  break;
866  case 6:
867  printf("800 MBytes/sec ");
868  break;
869  case 7:
870  printf("1200 MBytes/sec ");
871  break;
872  default:
873  printf("Unknown ");
874  }
875 
876  }
877  }
878 
879  printf("\nEncoding : 0x%x (%s)\n", a0_page_info.encoding, elxu_sfp_encoding_info(a0_page_info.encoding));
880  printf("BR, Nominal : 0x%x\n", a0_page_info.br_nominal);
881  printf("Rate Id : 0x%x (%s)\n", a0_page_info.rate_id, elxu_decode_sfp_rate_id(a0_page_info.rate_id));
882  printf("Length(9um,km) : 0x%x\n", a0_page_info.length_9um_km);
883  printf("Length(9um) : 0x%x\n", a0_page_info.length_9um);
884  printf("Length(50um) : 0x%x\n", a0_page_info.length_50um);
885  printf("Length(62.5) : 0x%x\n", a0_page_info.length_62_5_um);
886  printf("Length(Copper) : 0x%x\n", a0_page_info.len_copper);
887  printf("Length(OM3) : 0x%x\n", a0_page_info.length_om3);
888  printf("Vendor name : ");
889  for (i=0; i<16; i++)
890  printf("%c", a0_page_info.vendor_name[i]);
891  printf("\nVendor OUI : %x:%x:%x", a0_page_info.vendor_oui[0],a0_page_info.vendor_oui[1],a0_page_info.vendor_oui[2]);
892  printf("\nVendor PN : ");
893  for (i = 0; i<16; i++)
894  printf("%c", a0_page_info.vendor_pn[i]);
895  printf("\nVendor Revision : ");
896  for (i = 0; i<4; i++)
897  printf("%c", a0_page_info.vendor_rev[i]);
898  printf("\nOption values : 0x%x 0x%x\n", a0_page_info.options[0], a0_page_info.options[1]);
899  printf("BR margin, max : %d%s\n", a0_page_info.br_max, " %");
900  printf("BR margin, min : %d%s\n", a0_page_info.br_min, " %");
901  printf("Vendor SN : ");
902  for (i = 0; i<16; i++)
903  printf("%c", a0_page_info.vendor_sn[i]);
904  printf("\nDate code : ");
905  for (i = 0; i<8; i++)
906  printf("%c", a0_page_info.date_code[i]);
907  printf("\nOptical diagnostics support : %s", (a0_page_info.diag_monitor_type & 1 << 6) ? "Yes":"No");
908  printf("\n==============================================================================\n");
909  }
910  }
911 
912  value = elxu_device_get_value(options.device, "/ocs/sfp_a2");
913  if ((strlen(value) != 0) && (strcmp(value, "(unknown)") != 0)) {
914  d = transceiver_buffer;
915  s = value;
916  while (isalnum(*s)) {
917  *d = (uint8_t) strtoul(s, NULL, 16);
918  ++d;
919  s += 3;
920  }
921 
922  if (!options.sfp_diag_data && !options.sfp_xceiver_data) {
923  dump8("Hex information from page 0xA2 ---\n", transceiver_buffer,
925  printf("\n");
926  } else {
927  float temp_high,temp_low,vcc_high,vcc_low,tx_bias_high,tx_bias_low;
928  float tx_power_high,tx_power_low,rx_power_high,rx_power_low;
929  float temp_high_warn,temp_low_warn,vcc_high_warn,vcc_low_warn,tx_bias_high_warn,tx_bias_low_warn;
930  float tx_power_high_warn,tx_power_low_warn,rx_power_high_warn,rx_power_low_warn;
931  float temperature,vcc,tx_bias_current,tx_power,rx_power;
932 
933  temp_high = ((transceiver_buffer[0] << 8) | transceiver_buffer[1])/(float)256;
934  temp_low = ((transceiver_buffer[2] << 8) | transceiver_buffer[3])/(float)256;
935  temp_high_warn = ((transceiver_buffer[4] << 8) | transceiver_buffer[5])/(float)256;
936  temp_low_warn = ((transceiver_buffer[6] << 8) | transceiver_buffer[7])/(float)256;
937 
938  vcc_high = ((transceiver_buffer[8] << 8) | transceiver_buffer[9]) * (float)100 / 1000000;
939  vcc_low = ((transceiver_buffer[10] << 8) | transceiver_buffer[11]) * (float)100 / 1000000;
940  vcc_high_warn = ((transceiver_buffer[12] << 8) | transceiver_buffer[13]) * (float)100 / 1000000;
941  vcc_low_warn = ((transceiver_buffer[14] << 8) | transceiver_buffer[15]) * (float)100 / 1000000;
942 
943  tx_bias_high = ((transceiver_buffer[16] << 8) | transceiver_buffer[17]) * (float)2 / 1000;
944  tx_bias_low = ((transceiver_buffer[18] << 8) | transceiver_buffer[19]) * (float)2 / 1000;
945  tx_bias_high_warn = ((transceiver_buffer[20] << 8) | transceiver_buffer[21]) * (float)2 / 1000;
946  tx_bias_low_warn = ((transceiver_buffer[22] << 8) | transceiver_buffer[23]) * (float)2 / 1000;
947 
948  tx_power_high = ((transceiver_buffer[24] << 8) | transceiver_buffer[25]) * (float)0.1 / 1000;
949  tx_power_low = ((transceiver_buffer[26] << 8) | transceiver_buffer[27]) * (float)0.1 / 1000;
950  tx_power_high_warn = ((transceiver_buffer[28] << 8) | transceiver_buffer[29]) * (float)0.1 / 1000;
951  tx_power_low_warn = ((transceiver_buffer[30] << 8) | transceiver_buffer[31]) * (float)0.1 / 1000;
952 
953  rx_power_high = ((transceiver_buffer[32] << 8) | transceiver_buffer[33]) * (float)0.1 / 1000;
954  rx_power_low = ((transceiver_buffer[34] << 8) | transceiver_buffer[35]) * (float)0.1 / 1000;
955  rx_power_high_warn = ((transceiver_buffer[36] << 8) | transceiver_buffer[37]) * (float)0.1 / 1000;
956  rx_power_low_warn = ((transceiver_buffer[38] << 8) | transceiver_buffer[39]) * (float)0.1 / 1000;
957 
958  printf("== Threshold data ==\n");
959  printf("Temperature : -%f C(low) - %f C(high)\n", temp_low, temp_high);
960  printf("Voltage : %f V(low) - %f V(high)\n", vcc_low, vcc_high);
961  printf("TX Bias Current : %f mA(low) - %f mA(high)\n", tx_bias_low, tx_bias_high);
962  printf("TX Power : %f mW(low) - %f mW(high)\n", tx_power_low, tx_power_high);
963  printf("RX Power : %f mW(low) - %f mW(high)\n\n", rx_power_low, rx_power_high);
964 
965  printf("== Threshold warnings data ==\n");
966  printf("Temperature : %f (low) - %f (high)\n", temp_low_warn, temp_high_warn);
967  printf("Voltage : %f V(low) - %f V(high)\n", vcc_low_warn, vcc_high_warn);
968  printf("TX Bias Current : %f mA(low) - %f mA(high)\n", tx_bias_low_warn, tx_bias_high_warn);
969  printf("TX Power : %f mW(low) - %f mW(high)\n", tx_power_low_warn, tx_power_high_warn);
970  printf("RX Power : %f mW(low) - %f mW(high)\n\n", rx_power_low_warn, rx_power_high_warn);
971 
972  temperature = ((transceiver_buffer[96] << 8) | transceiver_buffer[97])/(float)256;
973  vcc = ((transceiver_buffer[98] << 8) | transceiver_buffer[99]) * (float)100 / 1000000;
974  tx_bias_current = ((transceiver_buffer[100] << 8) | transceiver_buffer[101]) * (float)2 / 1000;
975  tx_power = ((transceiver_buffer[102] << 8) | transceiver_buffer[103]) * (float)0.1 / 1000;
976  rx_power = ((transceiver_buffer[104] << 8) | transceiver_buffer[105]) * (float)0.1 / 1000;
977  printf("== Current SFP diagnostic data ==\n");
978  printf("Temperature: %f C \nSupply Voltage: %f V\n", temperature, vcc);
979  printf("TX Bias Current: %f mA\nTX Power: %f mW\nRX power: %f mW\n\n",
980  tx_bias_current, tx_power, rx_power);
981  }
982  }
983 
984  return 0;
985 }
986 
987 /**
988  * @ingroup cmd_handler
989  * @brief Command handler for the gendump command.
990  *
991  * @par Description
992  * This function processes the gendump command.
993  *
994  * Command: gendump <br>
995  * Required Parameters: None <br>
996  * Optional Parameters: -d <device> <br>
997  * Supported Devices: Lancer <br>
998  * Supported Protocols: N/A<br>
999  *
1000  * @param argc The number of command line arguments.
1001  * @param argv An array of pointers to the command line arguments.
1002  *
1003  * @return Returns 0 on success; or a non-zero error code value on failure.
1004  */
1005 int elxu_cmd_gendump(int argc, char **argv)
1006 {
1007  cmd_options_t options;
1008 
1009  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
1010  return -1;
1011  }
1012 
1013  /* Read Obj only supported for Lancer/Prism */
1014  if (!is_lancer(options.device) && !is_prism(options.device))
1015  {
1016  printf ("gendump is only supported on Lancer/Prism\n");
1017  return -1;
1018  }
1019  return lancer_gen_dump(options.device, options.fdb_dump);
1020 }
1021 
1022 /**
1023  * @ingroup cmd_handler
1024  * @brief Command handler for the fw-diag-log command.
1025  *
1026  * @par Description
1027  * This function processes the fw-diag-log command.
1028  *
1029  * Command: fw-diag-log <br>
1030  * Required Parameters: -d <device> -f <filename> <br>
1031  * Optional Parameters: None <br>
1032  * Supported Devices: Lancer G6 and Prism <br>
1033  * Supported Protocols: FC <br>
1034  *
1035  * @param argc The number of command line arguments.
1036  * @param argv An array of pointers to the command line arguments.
1037  *
1038  * @return Returns 0 on success; or a non-zero error code value on failure.
1039  */
1040 int elxu_cmd_fw_diagnostic_log(int argc, char **argv)
1041 {
1042  cmd_options_t options;
1043 
1044  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
1045  return -1;
1046  }
1047 
1048  if (!is_fc(options.device)) {
1049  fprintf(stderr, "FW diagnostic logging is only supported for FC devices.\n");
1050  return -1;
1051  }
1052 
1053  elxu_get_fw_diagnostic_log(options.device, options.file);
1054 
1055  return 0;
1056 }
1057 
1058 
1059 /**
1060  * @ingroup cmd_handler
1061  * @brief Command handler for the dump command.
1062  *
1063  * @par Description
1064  * This function processes the dump command.
1065  *
1066  * Command: dump-to-host <br>
1067  * Required Parameters: None <br>
1068  * Optional Parameters: -d <device> -f <filename> <br>
1069  * Supported Devices: Lancer <br>
1070  * Supported Protocols: N/A<br>
1071  *
1072  * @param argc The number of command line arguments.
1073  * @param argv An array of pointers to the command line arguments.
1074  *
1075  * @return Returns 0 on success; or a non-zero error code value on failure.
1076  */
1077 int elxu_cmd_dump_to_host(int argc, char **argv)
1078 {
1079  cmd_options_t options;
1080  char *pci_dev;
1081  char *pci_func;
1082 
1083  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
1084  return -1;
1085  }
1086 
1087  /* Dump to host only supported for Lancer/Prism */
1088  if (!is_lancer(options.device) && !is_prism(options.device)) {
1089  printf ("dump-to-host is only supported on Lancer/Prism\n");
1090  return -1;
1091  }
1092 
1093  if (is_uspace(options.device)) {
1094  printf("dump-to-host is not supported with the user space driver\n");
1095  return -1;
1096  }
1097 
1098  pci_dev = elxu_device_get_value(options.device, "/ocs/businfo");
1099  pci_func = strrchr(pci_dev, '.') + 1;
1100  if (!options.fdb_dump && strcmp(pci_func, "0") != 0) {
1101  printf("dump-to-host is only valid for PCI function 0, ");
1102  printf("device index %d corresponds to PCI function %s of device %s\n",
1103  options.device->deviceIndex, pci_func, pci_dev);
1104  return -1;
1105  }
1106  return lancer_dump_to_host(options.device, options.file, options.fdb_dump);
1107 }
1108 
1109 /**
1110  * @ingroup cmd_handler
1111  * @brief Command handler for the read-status command.
1112  *
1113  * @par Description
1114  * This function processes the read-status command.
1115  *
1116  * Command: read-status <br>
1117  * Required Parameters: None <br>
1118  * Optional Parameters: -d <device> --cc <br>
1119  * Supported Devices: Lancer <br>
1120  * Supported Protocols: N/A<br>
1121  *
1122  * @param argc The number of command line arguments.
1123  * @param argv An array of pointers to the command line arguments.
1124  *
1125  * @return Returns 0 on success; or a non-zero error code value on failure.
1126  */
1127 int elxu_cmd_read_status(int argc, char **argv)
1128 {
1129  cmd_options_t options;
1130 
1131  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
1132  return -1;
1133  }
1134 
1135  if (is_iscsi(options.device)) {
1136  printf ("iSCSI does not support this command\n");
1137  return -1;
1138  }
1139 
1140  return mbox_read_status(options.device, options.cc);
1141 }
1142 
1143 /**
1144  * @ingroup cmd_handler
1145  * @brief Command handler for the read-link-status command.
1146  *
1147  * @par Description
1148  * This function processes the read-link-status command.
1149  *
1150  * Command: read-link-status <br>
1151  * Required Parameters: None <br>
1152  * Optional Parameters: -d <device> <br>
1153  * Supported Devices: Lancer <br>
1154  * Supported Protocols: N/A<br>
1155  *
1156  * @param argc The number of command line arguments.
1157  * @param argv An array of pointers to the command line arguments.
1158  *
1159  * @return Returns 0 on success; or a non-zero error code value on failure.
1160  */
1161 int elxu_cmd_read_link_status(int argc, char **argv)
1162 {
1163  cmd_options_t options;
1164 
1165  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
1166  return -1;
1167  }
1168 
1169  if (is_iscsi(options.device)) {
1170  printf ("iSCSI does not support this command\n");
1171  return -1;
1172  }
1173 
1174  return mbox_read_link_status(options.device, options.clof, options.clrc);
1175 }
1176 
1178 {
1179  uint8_t transceiver_buffer[TRANSCEIVER_INFO_PAGE_SIZE];
1180  elx_sfp_transceiver_data_A0_t *a0_page_info;
1181  char *value, *s;
1182  uint8_t *d;
1183  int i;
1184 
1185  /* Explicitily supported SFP table */
1186  elx_dport_sfp_table1_entry supported_table1[] =
1187  {
1188  {"HP-F", "QW923A", "", 0x0C }, // Finisar, HP branded
1189  {"HP-A", "QW923A", "", 0 }, // Avago, HP branded
1190  {"HP-A", "E7Y09A", "", 0 }, // Avago, HP branded 16G
1191  {"FINISAR CORP.", "FTLF8529P3BCV-EM", "B", 0 }, // Finisar, Emulex branded
1192  {"EMULEX", "AFBR-57F5MZ-ELX", "", 0 }, // Avago, Emulex branded
1193  {"FINISAR CORP.", "FTLF8532P4BCV-EM", "", 0 }, // Finisar, Emulex Branded for 32G SFP
1194  {"AVAGO", "AFBR-57G5MZ-ELX", "", 0 }, // Avago, Emulex Branded for 32G SFP
1195  {"HPE-F", "P9H30A", "", 0 }, // Finisar, HP Branded for 32G SFP
1196  {"HPE-A", "P9H30A", "", 0 }, // Avago(Broadcom)-FIT, HP Branded for 32G SFP
1197  {"HP-F", "E7Y10A", "", 0 }, // Finisar, HP Branded for 16G SFP
1198  {"HP-A", "E7Y10A", "", 0 }, // Avago(Broadcom)-FIT, HP Branded for 16G SFP
1199  {"AVAGO", "AFCT-57F3TMZ-ELX", "B", 0 }, // Avago(Broadcom)-FIT, (Downrev of Rev "B"), FIT 16G
1200  };
1201  #define DPORT_SFP_TABLE1_LEN (sizeof(supported_table1) / sizeof(elx_dport_sfp_table1_entry))
1202 
1203  /* Implicitily supported SFP table for emulex branded */
1204  elx_dport_sfp_table2_entry supported_table2[] =
1205  {
1206  {"FTLF8529"}, // Finisar, Emulex branded
1207  {"AFBR-57F"}, // Avago, Emulex branded
1208  {"AFCT-57F"}, // Avago, Emulex Branded 16G
1209  {"AFCT-57G"}, // Avago, Emulex Branded 32G
1210  {"FTLF1429"}, // Finisar, Emulex Branded 16
1211  {"FTLF1432"}, // Finisar, Emulex Branded 32G
1212  };
1213  #define DPORT_SFP_TABLE2_LEN (sizeof(supported_table2) / sizeof(elx_dport_sfp_table2_entry))
1214 
1215  value = elxu_device_get_value(device, "/ocs/sfp_a0");
1216  if ((strcmp(value, "no-sfp") == 0)) {
1217  printf("Warning: No SFP module present on this device.\n");
1218  }
1219 
1220  if ((strlen(value) != 0) && (strcmp(value, "(unknown)") != 0) && (strcmp(value, "no-sfp") != 0)) {
1221  d = transceiver_buffer;
1222  s = value;
1223  while (isalnum(*s)) {
1224  *d = (uint8_t) strtoul(s, NULL, 16);
1225  ++d;
1226  s += 3;
1227  }
1228 
1229  a0_page_info = (elx_sfp_transceiver_data_A0_t *)transceiver_buffer;
1230 
1231  /* Validate against first table */
1232  for (i = 0; i < DPORT_SFP_TABLE1_LEN; i ++) {
1233  /* Validate vendor name */
1234  if (strncmp(a0_page_info->vendor_name, supported_table1[i].vendor,
1235  strlen(supported_table1[i].vendor)) == 0) {
1236 
1237  /* Validate vendor part number */
1238  if (strncmp(a0_page_info->vendor_pn, supported_table1[i].vendor_pn,
1239  strlen(supported_table1[i].vendor_pn)) == 0) {
1240 
1241  /* Validate revision number */
1242  if ((strncmp(a0_page_info->vendor_rev, supported_table1[i].vendor_rev,
1243  strlen(supported_table1[i].vendor_rev)) == 0) ||
1244  (a0_page_info->vendor_rev[0] > supported_table1[i].vendor_rev[0])) {
1245  return 0; /* Supported */
1246  }
1247 
1248  }
1249  }
1250  }
1251 
1252  /* Validate against second table */
1253  for (i = 0; i < DPORT_SFP_TABLE2_LEN; i ++) {
1254  if (strncmp(a0_page_info->vendor_pn, supported_table2[i].vendor_pn,
1255  strlen(supported_table2[i].vendor_pn)) == 0) {
1256  if ((strncmp((char *)a0_page_info->vendor_specific, "Emulex Certified", strlen("Emulex Certified")) == 0) ||
1257  (strncmp((char *)a0_page_info->vendor_specific, "Emulex.Certified", strlen("Emulex.Certified")) == 0)) {
1258  return 0; /* Supported */
1259  }
1260  }
1261  }
1262  }
1263 
1264  return -1;
1265 }
1266 
1267 /**
1268  * @ingroup cmd_handler
1269  * @brief Command handler for the get-dport-stats command.
1270  *
1271  * @par Description
1272  * This function processes the get-dport-stats command.
1273  *
1274  * Command: get-dport-stats <br>
1275  * Required Parameters: None <br>
1276  * Optional Parameters: -d <device> <br>
1277  * Supported Devices: Lancer <br>
1278  * Supported Protocols: FC<br>
1279  *
1280  * @param argc The number of command line arguments.
1281  * @param argv An array of pointers to the command line arguments.
1282  *
1283  * @return Returns 0 on success; or a non-zero error code value on failure.
1284  */
1285 int elxu_cmd_get_dport_stats(int argc, char **argv)
1286 {
1287  cmd_options_t options;
1288 
1289  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
1290  return -1;
1291  }
1292 
1293  if (is_iscsi(options.device)) {
1294  printf ("iSCSI does not support this command\n");
1295  return -1;
1296  }
1297 
1298  if (elxu_check_sfp_dport_support(options.device) != 0) {
1299  printf ("SFP is not supported for Dport tests\n");
1300  return -1;
1301  }
1302 
1303  return mbox_get_dport_stats(options.device);
1304 }
1305 
1306 int elxu_cmd_set_dport_dynamic_mode(int argc, char **argv)
1307 {
1308  cmd_options_t options;
1309  char *value;
1310 
1311  if (argc < 3) {
1312  fprintf(stderr, "Value (enable or disable) is required\n");
1313  return -1;
1314  }
1315 
1316  value = argv[2];
1317 
1318  if ((strcasecmp(value, "enable") != 0) &&
1319  (strcasecmp(value, "disable") != 0)) {
1320  fprintf(stderr, "Unexpected value '%s' - should be 'enable' or 'disable'\n", value);
1321  return -1;
1322  }
1323 
1324  if (parse_arguments(argc, argv, &options, 1, 2) == -1) {
1325  return -1;
1326  }
1327 
1328  if(is_iscsi(options.device)) {
1329  printf("iSCSI does not support this command\n");
1330  return -1;
1331  }
1332 
1333  return mbox_set_dynamic_dport(options.device, value);
1334 }
1335 
1336 int elxu_cmd_get_dynamic_dport_status(int argc, char **argv)
1337 {
1338  cmd_options_t options;
1339 
1340  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
1341  return -1;
1342  }
1343 
1344  if (is_iscsi(options.device)) {
1345  printf ("iSCSI does not support this command\n");
1346  return -1;
1347  }
1348 
1349  return mbox_query_dynamic_dport_status(options.device);
1350 }
1351 
1352 int elxu_cmd_diag_loopback_tests(int argc, char **argv)
1353 {
1354  cmd_options_t options;
1355 
1356  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
1357  return -1;
1358  }
1359  if (!is_lancer(options.device) && !is_prism(options.device)) {
1360  printf (" Command supports only to lancer/Prism\n");
1361  return -1;
1362  }
1363  return mbox_diag_loopback_tests(options.device, options.loopback_type, options.retry_count);
1364 }
1365 /**
1366  * @ingroup cmd_handler
1367  * @brief Command handler for the read-rev command.
1368  *
1369  * @par Description
1370  * This function processes the read-rev command.
1371  *
1372  * Command: read-rev <br>
1373  * Required Parameters: None <br>
1374  * Optional Parameters: -d <device> <br>
1375  * Supported Devices: Lancer, Skyhawk <br>
1376  * Supported Protocols: N/A<br>
1377  *
1378  * @param argc The number of command line arguments.
1379  * @param argv An array of pointers to the command line arguments.
1380  *
1381  * @return Returns 0 on success; or a non-zero error code value on failure.
1382  */
1383 int elxu_cmd_read_rev(int argc, char **argv)
1384 {
1385  cmd_options_t options;
1386 
1387  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
1388  return -1;
1389  }
1390 
1391  return mbox_read_rev(options.device);
1392 }
1393 
1394 /**
1395  * @ingroup cmd_handler
1396  * @brief Command handler for the ack-frequency command.
1397  *
1398  * @par Description
1399  * This function processes the ack-frequency command.
1400  *
1401  * Command: ack-frequency <br>
1402  * Required Parameters: <frequency> <br>
1403  * Optional Parameters: -d <device> <br>
1404  * Supported Devices: Skyhawk <br>
1405  * Supported Protocols: iSCSI <br>
1406  *
1407  * @param argc The number of command line arguments.
1408  * @param argv An array of pointers to the command line arguments.
1409  *
1410  * @return Returns 0 on success; or a non-zero error code value on failure.
1411  */
1412 int elxu_cmd_ack_frequency(int argc, char **argv)
1413 {
1414  uint32_t freq;
1415  cmd_options_t options;
1416 
1417  if (argc < 3) {
1418  fprintf(stderr, "ACK frequency is required\n");
1419  return -1;
1420  }
1421 
1422  freq = strtoul(argv[2], NULL, 0);
1423 
1424  if (parse_arguments(argc, argv, &options, 1, 2) == -1) {
1425  return -1;
1426  }
1427 
1428  if (!is_skyhawk(options.device)) {
1429  printf("Setting TCP parameters is only supported on Skyhawk\n");
1430  return -1;
1431  }
1432 
1433  return mbox_tcp_parameters(options.device,
1434  ISCSI_UPDATE_ACK_FREQUENCY, freq, 0);
1435 }
1436 
1437 /**
1438  * @ingroup cmd_handler
1439  * @brief Command handler for the delayed-ack-timer command.
1440  *
1441  * @par Description
1442  * This function processes the delayed-ack-timer command.
1443  *
1444  * Command: delayed-ack-timer <br>
1445  * Required Parameters: <time> <br>
1446  * Optional Parameters: -d <device> <br>
1447  * Supported Devices: Skyhawk <br>
1448  * Supported Protocols: iSCSI <br>
1449  *
1450  * @param argc The number of command line arguments.
1451  * @param argv An array of pointers to the command line arguments.
1452  *
1453  * @return Returns 0 on success; or a non-zero error code value on failure.
1454  */
1455 int elxu_cmd_delayed_ack_timer(int argc, char **argv)
1456 {
1457  uint32_t freq;
1458  cmd_options_t options;
1459 
1460  if (argc < 3) {
1461  fprintf(stderr, "Delayed ACK timer value is required\n");
1462  return -1;
1463  }
1464 
1465  freq = strtoul(argv[2], NULL, 0);
1466 
1467  if (parse_arguments(argc, argv, &options, 1, 2) == -1) {
1468  return -1;
1469  }
1470 
1471  if (!is_skyhawk(options.device)) {
1472  printf("Setting TCP parameters is only supported on Skyhawk\n");
1473  return -1;
1474  }
1475 
1476  return mbox_tcp_parameters(options.device,
1478 }
1479 
1480 /**
1481  * @ingroup cmd_handler
1482  * @brief Command handler for the constrain-window command.
1483  *
1484  * @par Description
1485  * This function processes the constrain-window command.
1486  *
1487  * Command: constrain-window <br>
1488  * Required Parameters: <window_size>, --connection-id <connection_id> <br>
1489  * Optional Parameters: -d <device> <br>
1490  * Supported Devices: Skyhawk <br>
1491  * Supported Protocols: iSCSI <br>
1492  *
1493  * @param argc The number of command line arguments.
1494  * @param argv An array of pointers to the command line arguments.
1495  *
1496  * @return Returns 0 on success; or a non-zero error code value on failure.
1497  */
1498 int elxu_cmd_constrain_window(int argc, char **argv)
1499 {
1500  uint32_t window_size;
1501  cmd_options_t options;
1502 
1503  if (argc < 3) {
1504  fprintf(stderr, "Window size value is required\n");
1505  return -1;
1506  }
1507 
1508  window_size = strtoul(argv[2], NULL, 0);
1509 
1510  if (parse_arguments(argc, argv, &options, 1, 2) == -1) {
1511  return -1;
1512  }
1513 
1514  if (options.connection_id == NULL) {
1515  fprintf(stderr, "Connection ID is required\n");
1516  return -1;
1517  }
1518 
1519  if (!is_skyhawk(options.device)) {
1520  printf("Setting TCP parameters is only supported on Skyhawk\n");
1521  return -1;
1522  }
1523 
1525  strtoul(options.connection_id, NULL, 0), window_size);
1526 }
1527 
1528 /**
1529  * @ingroup cmd_handler
1530  * @brief Command handler for the driver-dump command.
1531  *
1532  * @par Description
1533  * This function processes the driver-dump command.
1534  *
1535  * Command: driver-dump <br>
1536  * Required Parameters: None <br>
1537  * Optional Parameters: -d <device> <br>
1538  * Supported Devices: Any <br>
1539  * Supported Protocols: N/A <br>
1540  *
1541  * @param argc The number of command line arguments.
1542  * @param argv An array of pointers to the command line arguments.
1543  *
1544  * @return Returns 0 on success; or a non-zero error code value on failure.
1545  */
1546 int elxu_cmd_driver_dump(int argc, char **argv)
1547 {
1548  cmd_options_t options;
1549  ocs_ioctl_ddump_arg_t args;
1550 
1551  /* by default, get normal ddump */
1552  memset(&args, 0, sizeof(args));
1553  args.action = OCS_IOCTL_DDUMP_GET;
1554  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
1555  return -1;
1556  }
1557 
1558  if (options.saved) {
1560  } else if (options.clr_saved) {
1562  }
1563 
1564  if (options.wqes) {
1566  }
1567  if (options.cqes) {
1569  }
1570  if (options.rqes) {
1572  }
1573  if (options.mqes) {
1575  }
1576  if (options.eqes) {
1578  }
1579 
1580  /* by default, dump entire queues */
1581  if (options.qentries == 0) {
1582  args.q_entries = -1;
1583  } else {
1584  args.q_entries = options.qentries;
1585  }
1586 
1587  if (args.flags == 0) {
1588  /* by default, dump WQs, CQs, MQ */
1592  }
1593  elxu_driver_dump(options.device, options.bufsize, &args);
1594 
1595  return 0;
1596 }
1597 
1598 /**
1599  * @ingroup cmd_handler
1600  * @brief Command handler for the mgmt-info command.
1601  *
1602  * @par Description
1603  * This function processes the mgmt-info command.
1604  *
1605  * Command: mgmt-info <br>
1606  * Required Parameters: None <br>
1607  * Optional Parameters: -d <device> <br>
1608  * Supported Devices: Any <br>
1609  * Supported Protocols: N/A <br>
1610  *
1611  * @param argc The number of command line arguments.
1612  * @param argv An array of pointers to the command line arguments.
1613  *
1614  * @return Returns 0 on success; or a non-zero error code value on failure.
1615  */
1616 int elxu_cmd_mgmt_info(int argc, char **argv)
1617 {
1618  cmd_options_t options;
1619 
1620  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
1621  return -1;
1622  }
1623 
1624  elxu_mgmt_info(options.device);
1625 
1626  return 0;
1627 }
1628 
1629 /**
1630  * @ingroup cmd_handler
1631  * @brief Command handler for the connection-info command.
1632  *
1633  * @par Description
1634  * This function processes the connection-info command.
1635  *
1636  * Command: connection-info <br>
1637  * Required Parameters: None <br>
1638  * Optional Parameters: --connection-handle <handle>, -d <device> <br>
1639  * Supported Devices: Skyhawk <br>
1640  * Supported Protocols: iSCSI <br>
1641  *
1642  * @param argc The number of command line arguments.
1643  * @param argv An array of pointers to the command line arguments.
1644  *
1645  * @return Returns 0 on success; or a non-zero error code value on failure.
1646  */
1647 int elxu_cmd_connection_info(int argc, char **argv)
1648 {
1649  cmd_options_t options;
1650 
1651  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
1652  return -1;
1653  }
1654 
1655  if (!is_iscsi(options.device)) {
1656  fprintf(stderr, "connection-info is only supported on iSCSI devices.\n");
1657  return -1;
1658  }
1659 
1660  // If we were given a connection ID then we want to use the mbox
1661  // command to get connection info from the chip. Without a connection
1662  // ID we will show a list of connection information from the driver
1663  if (options.connection_handle != NULL) {
1665  strtoul(options.connection_handle, NULL, 0));
1666  } else {
1668  }
1669 
1670  return 0;
1671 }
1672 
1673 int elxu_cmd_iclusttgt_check_args(int argc, char **argv)
1674 {
1675  if (argc < 3)
1676  return -1;
1677 
1678  if (argc == 3 &&
1679  (strncmp(argv[2], "show", 4) && strncmp(argv[2], "clear", 5)))
1680  return -1;
1681 
1682  if (argc == 5 &&
1683  (strncmp(argv[2], "add", 3) && strncmp(argv[2], "del", 3)))
1684  return -1;
1685 
1686  return 0;
1687 }
1688 
1690 {
1691  int rval;
1692  int num_clust_tgts = 0;
1693  int inx = OCS_CLUST_TARGET_KEY_RETCNT;
1694  int len;
1695  char out_buf[512];
1696  char tgtportal[256];
1697  char in_buf[32];
1698  char *slash;
1699  int num_chars;
1700 
1701  /* Get max max number of cluster targets saved in the list.
1702  * Use inx = key, to read the num of cluster targets.
1703  */
1704  len = snprintf(in_buf, sizeof(in_buf), "%d", inx);
1705  rval = elxu_device_exec(device, "/ocs/iclusttgt_get",
1706  in_buf, len, NULL, 0);
1707  if (rval < 0)
1708  return rval;
1709 
1710  if (rval == 0) {
1711  printf("iclusttgt list is empty\n");
1712  return rval;
1713  }
1714 
1715  num_clust_tgts = rval;
1716 
1717  printf("iclusttgt Show targets %d\n", num_clust_tgts);
1718 
1719  /* Now get and display all the saved targets in cluster */
1720  printf("INDEX\tTARGET NAME AND ADDRESS\n");
1721  inx = 0;
1722  while (inx < num_clust_tgts) {
1723  memset(out_buf, 0, sizeof(out_buf));
1724  len = snprintf(in_buf, sizeof(in_buf), "%d", inx);
1725  rval = elxu_device_exec(device, "/ocs/iclusttgt_get",
1726  in_buf, len, out_buf, sizeof(out_buf));
1727  if (rval)
1728  break;
1729 
1730  slash = strchr(out_buf, '/');
1731  if (!slash)
1732  return -1;
1733 
1734  printf("%5d\t", inx+1);
1735 
1736  num_chars = slash - (char *)out_buf;
1737  memcpy(tgtportal, out_buf, num_chars);
1738  tgtportal[num_chars] = '\0';
1739  printf("%s ", tgtportal);
1740 
1741  num_chars = strlen(out_buf) - (num_chars + 1);
1742  memcpy(tgtportal, slash + 1, num_chars);
1743  tgtportal[num_chars] = '\0';
1744  printf("%s\n", tgtportal);
1745 
1746  inx++;
1747  }
1748 
1749  return rval;
1750 }
1751 
1752 int elxu_cmd_iclusttgt(int argc, char **argv)
1753 {
1754  int rval = 0;
1755  char cmd[32];
1756  cmd_options_t options;
1757  char ip[32];
1758  char *portal_portnum;
1759  char *portal_grptag;
1760  /* Max of iSCSI target name plus max of target portal-address */
1761  char parms[512];
1762  int parmlen;
1763  int i;
1764 
1765  if ((rval = parse_arguments(argc, argv, &options, 1, argc-1))) {
1766  fprintf(stderr, "Parse arguments failed on %s\n",
1767  argv[1]);
1768  return rval;
1769  }
1770 
1771  if (!is_iscsi(options.device)) {
1772  printf("iclusttgt is only supported in iSCSI\n");
1773  return -1;
1774  }
1775 
1776  /* Device arg in the form of -d <devnum> */
1777  if (strcmp(argv[1], "-d") == 0) {
1778  for (i = 1; i < argc-1; i++)
1779  memcpy((argv+i), (argv+i)+1, sizeof(argv[i+1]));
1780 
1781  argc -= 1;
1782  argv[argc] = NULL;
1783 
1784  for (i = 1; i < argc-1; i++)
1785  memcpy((argv+i), (argv+i)+1, sizeof(argv[i+1]));
1786 
1787  argc -= 1;
1788  argv[argc] = NULL;
1789  } else if (argv[1][0] == '-') {
1790  /* Device arg in the form of -d<devnum> */
1791  for (i = 1; i < argc-1; i++)
1792  memcpy((argv+i), (argv+i)+1, sizeof(argv[i+1]));
1793  argc -= 1;
1794  argv[argc] = NULL;
1795  }
1796 
1797  if ((rval = elxu_cmd_iclusttgt_check_args(argc, argv))) {
1798  fprintf(stderr, "Invalid number of arguments. "
1799  "Run %s help %s\n", argv[0], argv[1]);
1800  return rval;
1801  }
1802 
1803 
1804  memset(parms, 0, sizeof(parms));
1805  if (argc == 5) {
1806  portal_portnum = strchr(argv[4], ':');
1807  portal_grptag = strchr(argv[4], ',');
1808 
1809  if (!portal_portnum && portal_grptag) {
1810  fprintf(stderr, "Invalid number of arguments. "
1811  "Run %s help %s\n", argv[0], argv[1]);
1812  return -1;
1813  }
1814 
1815  strcpy(ip, argv[4]);
1816  if (portal_portnum && !portal_grptag)
1817  snprintf(ip, sizeof(ip), "%s,%d", argv[4],
1819 
1820  if (!portal_portnum)
1821  snprintf(ip, sizeof(ip), "%s:%d,%d", argv[4],
1823 
1824  parmlen = snprintf(parms, sizeof(parms), "%s/%s",
1825  argv[3], ip);
1826  }
1827 
1828  if (0 == strncmp(argv[2], "show", 4))
1829  rval = elxu_cmd_iclusttgt_show(options.device);
1830  else {
1831  snprintf(cmd, sizeof(cmd), "/ocs/iclusttgt_%s", argv[2]);
1832  rval = elxu_device_exec(options.device, cmd,
1833  parms, parmlen, NULL, 0);
1834  }
1835 
1836  if (rval)
1837  perror("ioctl-iclusttgt");
1838 
1839  printf("Command %s %s is %s on device %d\n",
1840  argv[1], argv[2], (rval ? "failed" : "success"),
1841  options.device->deviceIndex);
1842 
1843  return rval;
1844 }
1845 
1846 /**
1847  * @ingroup cmd_handler
1848  * @brief Command handler for the route command.
1849  *
1850  * @par Description
1851  * This function processes the route command.
1852  *
1853  * Command: route <br>
1854  * Required Parameters: <add|del|show>
1855  * Parameters: <add|del> <netmask> <gateway>, -d <device> <br>
1856  * Optional Parameters: -d <device> <br>
1857  * Supported Devices: Skyhawk <br>
1858  * Supported Protocols: iSCSI <br>
1859  *
1860  * @param argc The number of command line arguments.
1861  * @param argv An array of pointers to the command line arguments.
1862  *
1863  * @return Returns 0 on success; or a non-zero error code value on failure.
1864  */
1865 int elxu_cmd_route(int argc, char **argv)
1866 {
1867  cmd_options_t options;
1868  ocs_route_table_t *route_table;
1869  char cmd_params[256];
1870  char cmd[32];
1871  int param_len;
1872  int rval = -1;
1873  int inx;
1874  char *ip_addr;
1875  char *netmask;
1876  char *gateway;
1877  char *action;
1878 
1879  if (argc < 3) {
1880  fprintf(stderr, "Insufficient parameters\n");
1881  return rval;
1882  }
1883 
1884  action = argv[2];
1885  if ((0 == strcmp(action, "--add")) || (0 == strcmp(action, "--del"))) {
1886  if (argc < 6) {
1887  fprintf(stderr, "Insufficient parameters\n");
1888  return rval;
1889  }
1890 
1891  ip_addr = argv[3];
1892  netmask = argv[4];
1893  gateway = argv[5];
1894  }
1895 
1896  if (parse_arguments(argc-2, argv+2, &options, 1, 5) == -1) {
1897  fprintf(stderr, "parse arguments failed\n");
1898  return rval;
1899  }
1900 
1901  if (!is_iscsi(options.device)) {
1902  printf("Route table add/del is only supported in iSCSI\n");
1903  return rval;
1904  }
1905 
1906 
1907  if ((0 == strcmp(action, "--add")) || (0 == strcmp(action, "--del"))) {
1908  param_len = snprintf(cmd_params, sizeof(cmd_params), "%s/%s/%s",
1909  ip_addr, netmask, gateway);
1910  snprintf(cmd, sizeof(cmd), "/ocs/route_%s", action+2);
1911  rval = elxu_device_exec(options.device, cmd,
1912  &cmd_params, param_len, NULL, 0);
1913  if (rval == 0) {
1914  printf("Route %s for IP-%s/%s gateway %s is successful\n",
1915  action, ip_addr, netmask, gateway);
1916  } else {
1917  printf("Route %s for IP-%s/%s gateway %s is failed\n",
1918  action, ip_addr, netmask, gateway);
1919  }
1920  } else if (0 == strcmp(action, "--show")) {
1921  route_table = malloc(sizeof(*route_table));
1922  if (route_table == NULL) {
1923  fprintf(stderr, "malloc failed\n");
1924  return -1;
1925  }
1926 
1927  snprintf(cmd, sizeof(cmd), "/ocs/route_%s", action+2);
1928  rval = elxu_device_exec(options.device, cmd,
1929  NULL, 0, route_table, sizeof(*route_table));
1930  if (rval) {
1931  printf("Route %s failed\n", action);
1932  free(route_table);
1933  return rval;
1934  }
1935 
1936  printf("Route table entries %d\n", route_table->entry_count);
1937  if (route_table->entry_count) {
1938  printf("%-16s %-16s %-16s\n", "IP", "Subnet", "Gateway");
1939  for (inx = 0; inx < route_table->entry_count; inx++) {
1940  printf("%-16s %-16s %-16s\n",
1941  route_table->entry[inx].ip_addr,
1942  route_table->entry[inx].subnet,
1943  route_table->entry[inx].gateway);
1944  }
1945  }
1946 
1947  free(route_table);
1948  } else {
1949  fprintf(stderr, "Invalid command %s for route\n", action);
1950  rval = -1;
1951  }
1952 
1953  return rval;
1954 }
1955 
1956 /**
1957  * @ingroup cmd_handler
1958  * @brief Command handler for the vlan command.
1959  *
1960  * @par Description
1961  * This function processes the vlan command.
1962  *
1963  * Command: vlan <br>
1964  * Required Parameters: <add|del|show>
1965  * Parameters: <add|del> <vlan-id>
1966  * Optional Parameters: -d <device> <br>
1967  * Supported Devices: Skyhawk <br>
1968  * Supported Protocols: iSCSI <br>
1969  *
1970  * @param argc The number of command line arguments.
1971  * @param argv An array of pointers to the command line arguments.
1972  *
1973  * @return Returns 0 on success; or a non-zero error code value on failure.
1974  */
1975 int elxu_cmd_vlan(int argc, char **argv)
1976 {
1977  cmd_options_t options;
1978  char cmd[32];
1979  unsigned int vlan_id;
1980  char *action;
1981  char *show_buff = NULL;
1982  int rval = -1;
1983 
1984  if (argc < 3) {
1985  fprintf(stderr, "Insufficient parameters\n");
1986  return rval;
1987  }
1988 
1989  action = argv[2];
1990  if ((0 == strcmp(action, "--add")) || (0 == strcmp(action, "--del"))) {
1991  if (argc < 4) {
1992  fprintf(stderr, "Insufficient parameters\n");
1993  return rval;
1994  }
1995 
1996  vlan_id = atoi(argv[3]);
1997  if (!(vlan_id >= 2 && vlan_id <= 4096)) {
1998  fprintf(stderr, "Invalid VLAN id %d\n", vlan_id);
1999  return rval;
2000  }
2001  } else if ((0 == strcmp(action, "--show"))) {
2002  show_buff = malloc(ELXU_CMD_VLAN_SHOW_BUFFER_SIZE);
2003  if (!show_buff) {
2004  fprintf(stderr, "malloc failed\n");
2005  return rval;
2006  }
2007  } else {
2008  fprintf(stderr, "Invalid parameters\n");
2009  return rval;
2010  }
2011 
2012  if (parse_arguments(argc-2, argv+2, &options, 1, 3) == -1) {
2013  fprintf(stderr, "parse failed\n");
2014  goto exit_free;
2015  }
2016 
2017  if(!is_iscsi(options.device)) {
2018  printf("VLAN config is only supported in iSCSI\n");
2019  goto exit_free;
2020  }
2021 
2022  snprintf(cmd, sizeof(cmd), "/ocs/vlan_%s", action+2);
2023  rval = elxu_device_exec(options.device, cmd,
2024  &vlan_id, sizeof(vlan_id),
2025  show_buff,
2026  (show_buff ? ELXU_CMD_VLAN_SHOW_BUFFER_SIZE : 0));
2027  if (rval) {
2028  fprintf(stderr, "iSCSI vlan %s is failed on device %d\n",
2029  action, options.device->deviceIndex);
2030  goto exit_free;
2031  }
2032 
2033  printf("iSCSI vlan %s is successful on device %d\n",
2034  action, options.device->deviceIndex);
2035 
2036 exit_free:
2037  if ((0 == strcmp(action, "--show"))) {
2038  printf("%s ", show_buff);
2039  free(show_buff);
2040  }
2041  return rval;
2042 }
2043 
2044 #define ELXU_IP_GET_ADDRESS_LIST_SIZE (4096 * 2)
2045 int elxu_check_ip_address_exists(cmd_options_t *options, char *ipaddr, int *ip_found)
2046 {
2047  char *ipv4_addrs = NULL;
2048  char *ipv6_addrs = NULL;
2049  uint32_t version;
2050  int rval = 0;
2051 
2052  ipv4_addrs = malloc(ELXU_IP_GET_ADDRESS_LIST_SIZE);
2053  if (!ipv4_addrs) {
2054  fprintf(stderr, "IPv4 malloc failed\n");
2055  return -1;
2056  }
2057 
2058  // Get current IPs
2059  version = 4;
2060  rval = elxu_device_exec(options->device, "/ocs/ip_get", &version,
2061  sizeof(version), ipv4_addrs, ELXU_IP_GET_ADDRESS_LIST_SIZE);
2062  if (rval) {
2063  printf("Failed to read existing IPv4 addresses\n");
2064  goto exit;
2065  }
2066 
2067  ipv6_addrs = malloc(ELXU_IP_GET_ADDRESS_LIST_SIZE);
2068  if (!ipv6_addrs) {
2069  fprintf(stderr, "IPv6 malloc failed\n");
2070  goto exit;
2071  }
2072 
2073  version = 6;
2074  rval = elxu_device_exec(options->device, "/ocs/ip_get", &version,
2075  sizeof(version), ipv6_addrs, ELXU_IP_GET_ADDRESS_LIST_SIZE);
2076  if (rval) {
2077  printf("Failed to read existing IPv6 addresses\n");
2078  goto exit;
2079  }
2080 
2081  if ((strstr(ipv4_addrs, ipaddr) != NULL) ||
2082  (strstr(ipv6_addrs, ipaddr) != NULL)) {
2083  *ip_found = 1;
2084  }
2085 
2086 exit:
2087  if (ipv4_addrs)
2088  free(ipv4_addrs);
2089  if (ipv6_addrs)
2090  free(ipv6_addrs);
2091 
2092  return rval;
2093 }
2094 
2095 /**
2096  * @ingroup cmd_handler
2097  * @brief Command handler for the add-ip command.
2098  *
2099  * @par Description
2100  * This function processes the add-ip command.
2101  *
2102  * Command: add-ip <br>
2103  * Required Parameters: <ip address> <netmask> <br>
2104  * Optional Parameters: -d <device> [--vlan-id <vlan_id>] <br>
2105  * Supported Devices: Skyhawk <br>
2106  * Supported Protocols: iSCSI <br>
2107  *
2108  * @param argc The number of command line arguments.
2109  * @param argv An array of pointers to the command line arguments.
2110  *
2111  * @return Returns 0 on success; or a non-zero error code value on failure.
2112  */
2113 int elxu_cmd_add_ip(int argc, char **argv)
2114 {
2115  cmd_options_t options;
2116  char *ipaddr_p;
2117  char *netmask_p;
2118  char cmd_parms[128];
2119  int ip_found = 0;
2120  int parm_len;
2121  int rval;
2122 
2123  if (argc < 4) {
2124  fprintf(stderr, "IP address and netmask is required\n");
2125  return -1;
2126  }
2127 
2128  ipaddr_p = argv[2];
2129  netmask_p = argv[3];
2130  if (parse_arguments(argc, argv, &options, 1, 3) == -1) {
2131  return -1;
2132  }
2133 
2134  if(!is_iscsi(options.device)) {
2135  printf("Add IP address is only supported in iSCSI\n");
2136  return -1;
2137  }
2138 
2139  rval = elxu_check_ip_address_exists(&options, ipaddr_p, &ip_found);
2140  if (rval) {
2141  printf("Check IP addresses failed\n");
2142  return rval;
2143  }
2144 
2145  if (!ip_found) {
2146  parm_len = snprintf(cmd_parms, sizeof(cmd_parms), "%s/%s/%d",
2147  ipaddr_p, netmask_p, options.vlan_id);
2148  rval = elxu_device_exec(options.device, "/ocs/ip_add", cmd_parms,
2149  parm_len, NULL, 0);
2150  if (rval == 0) {
2151  printf("IP address %s added to device %d\n",
2152  ipaddr_p, options.device->deviceIndex);
2153  } else {
2154  printf("Failed to add IP address %s from device %d\n",
2155  ipaddr_p, options.device->deviceIndex);
2156  }
2157  } else {
2158  printf("IP address %s is already exists\n", ipaddr_p);
2159  }
2160 
2161  return rval;
2162 }
2163 
2164 /**
2165  * @ingroup cmd_handler
2166  * @brief Command handler for the remove-ip command.
2167  *
2168  * @par Description
2169  * This function processes the remove-ip command.
2170  *
2171  * Command: remove-ip <br>
2172  * Required Parameters: <ip_address> <br>
2173  * Optional Parameters: -d <device> [--vlan-id <vlan_id>] <br>
2174  * Supported Devices: Skyhawk <br>
2175  * Supported Protocols: iSCSI <br>
2176  *
2177  * @param argc The number of command line arguments.
2178  * @param argv An array of pointers to the command line arguments.
2179  *
2180  * @return Returns 0 on success; or a non-zero error code value on failure.
2181  */
2182 int elxu_cmd_remove_ip(int argc, char **argv)
2183 {
2184  cmd_options_t options;
2185  char *ipaddr_p;
2186  int rval;
2187  int32_t ip_found = 0;
2188  char cmd_parms[128];
2189  int parm_len;
2190 
2191  if (argc < 3) {
2192  fprintf(stderr, "IP address is required\n");
2193  return -1;
2194  }
2195 
2196  ipaddr_p = argv[2];
2197  if (parse_arguments(argc, argv, &options, 1, 3) == -1) {
2198  return -1;
2199  }
2200 
2201  if(!is_iscsi(options.device)) {
2202  printf("Add IP address is only supported in iSCSI\n");
2203  return -1;
2204  }
2205 
2206  rval = elxu_check_ip_address_exists(&options, ipaddr_p, &ip_found);
2207  if (rval) {
2208  printf("Check IP addresses failed\n");
2209  return rval;
2210  }
2211 
2212  if (ip_found) {
2213  parm_len = snprintf(cmd_parms, sizeof(cmd_parms), "%s/%d",
2214  ipaddr_p, options.vlan_id);
2215  rval = elxu_device_exec(options.device, "/ocs/ip_remove",
2216  cmd_parms, parm_len, NULL, 0);
2217  if (rval == 0) {
2218  printf("IP address %s removed from device %d\n",
2219  ipaddr_p, options.device->deviceIndex);
2220  } else {
2221  printf("Failed to remove IP address %s from device %d\n",
2222  ipaddr_p, options.device->deviceIndex);
2223  }
2224  } else {
2225  printf("IP address %s is not found\n", ipaddr_p);
2226  }
2227 
2228  return rval;
2229 }
2230 
2231 /**
2232  * @ingroup cmd_handler
2233  * @brief Command handler for the show-ips command.
2234  *
2235  * @par Description
2236  * This function processes the show-ips command.
2237  *
2238  * Command: show-ips <br>
2239  * Required Parameters: None <br>
2240  * Optional Parameters: -d <device> <br>
2241  * Supported Devices: Skyhawk <br>
2242  * Supported Protocols: iSCSI <br>
2243  *
2244  * @param argc The number of command line arguments.
2245  * @param argv An array of pointers to the command line arguments.
2246  *
2247  * @return Returns 0 on success; or a non-zero error code value on failure.
2248  */
2249 int elxu_cmd_show_ips(int argc, char **argv)
2250 {
2251  cmd_options_t options;
2252  char *buf;
2253  uint32_t version;
2254  int rval;
2255 
2256  if (argc < 3) {
2257  fprintf(stderr, "IP address version required\n");
2258  return -1;
2259  }
2260 
2261  version = strtoul(argv[2], NULL, 10);
2262  if (version != 4 && version != 6) {
2263  fprintf(stderr, "Invalid IP version (must be 4 or 6)\n");
2264  return -1;
2265  }
2266 
2267  if (parse_arguments(argc, argv, &options, 1, 2) == -1) {
2268  return -1;
2269  }
2270 
2271  if (!is_iscsi(options.device)) {
2272  fprintf(stderr, "Show IPs command is only supported on iSCSI\n");
2273  return -1;
2274  }
2275 
2276  buf = malloc(ELXU_IP_GET_ADDRESS_LIST_SIZE);
2277  if (!buf) {
2278  fprintf(stderr, "malloc failed\n");
2279  return -1;
2280  }
2281 
2282  rval = elxu_device_exec(options.device, "/ocs/ip_get", &version,
2283  sizeof(version), buf, ELXU_IP_GET_ADDRESS_LIST_SIZE);
2284  if (rval != 0) {
2285  perror("ioctl");
2286  } else {
2287  printf("IP addresses on device %d:\n%s\n",
2288  options.device->deviceIndex, buf);
2289  }
2290 
2291  free(buf);
2292  return rval;
2293 }
2294 
2295 /**
2296  * @ingroup cmd_handler
2297  * @brief Command handler for the set-gateway command.
2298  *
2299  * @par Description
2300  * This function processes the set-gateway command.
2301  *
2302  * Command: set-gateway <br>
2303  * Required Parameters: <ip_address> <br>
2304  * Optional Parameters: -d <device> <br>
2305  * Supported Devices: Skyhawk <br>
2306  * Supported Protocols: iSCSI <br>
2307  *
2308  * @param argc The number of command line arguments.
2309  * @param argv An array of pointers to the command line arguments.
2310  *
2311  * @return Returns 0 on success; or a non-zero error code value on failure.
2312  */
2313 int elxu_cmd_set_gateway(int argc, char **argv)
2314 {
2315  cmd_options_t options;
2316  char *ipaddr_p;
2317  int rval;
2318 
2319  if (argc < 3) {
2320  fprintf(stderr, "IP address is required\n");
2321  return -1;
2322  }
2323 
2324  ipaddr_p = argv[2];
2325 
2326  if (parse_arguments(argc, argv, &options, 1, 2) == -1) {
2327  return -1;
2328  }
2329 
2330  if(!is_iscsi(options.device)) {
2331  printf("Set gateway address is only supported in iSCSI\n");
2332  return -1;
2333  }
2334 
2335  rval = mgmt_set_value(options.device, "/ocs/gateway", ipaddr_p);
2336  if (rval == 0) {
2337  printf("Gateway address set to %s for device %d\n", ipaddr_p, options.device->deviceIndex);
2338  } else {
2339  printf("Failed to set gateway on from device %d, rval is %d\n", options.device->deviceIndex, rval);
2340  }
2341 
2342  return rval;
2343 }
2344 
2345 /**
2346  * @ingroup cmd_handler
2347  * @brief Command handler for the get-gateway command.
2348  *
2349  * @par Description
2350  * This function processes the get-gateway command.
2351  *
2352  * Command: get-gateway <br>
2353  * Required Parameters: None <br>
2354  * Optional Parameters: -d <device> <br>
2355  * Supported Devices: Skyhawk <br>
2356  * Supported Protocols: iSCSI <br>
2357  *
2358  * @param argc The number of command line arguments.
2359  * @param argv An array of pointers to the command line arguments.
2360  *
2361  * @return Returns 0 on success; or a non-zero error code value on failure.
2362  */
2363 int elxu_cmd_get_gateway(int argc, char **argv)
2364 {
2365  cmd_options_t options;
2366  char *result;
2367  int rval;
2368 
2369  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
2370  return -1;
2371  }
2372 
2373  if(!is_iscsi(options.device)) {
2374  printf("Gateway address is only supported in iSCSI\n");
2375  return -1;
2376  }
2377 
2378  result = elxu_device_get_value(options.device, "/ocs/gateway");
2379  if (strlen(result) != 0) {
2380  printf("Gateway address is %s\n", result);
2381  rval = 0;
2382  } else {
2383  printf("Failed to get gateway from from device %d\n", options.device->deviceIndex);
2384  rval = -1;
2385  }
2386 
2387  return rval;
2388 }
2389 
2390 /**
2391  * @ingroup cmd_handler
2392  * @brief Command handler for the add-chap command
2393  *
2394  * @par Description
2395  * This function processes the add-chap command
2396  *
2397  * Command: add-chap<br>
2398  * Required Parameters: <name>:<secret> <br>
2399  * Optional Parameters: -d <device> <br>
2400  * Supported Devices: Skyhawk <br>
2401  * Supported Protocols: iSCSI <br>
2402  *
2403  * @param argc The number of command line arguments.
2404  * @param argv An array of pointers to the command line arguments.
2405  *
2406  * @return Returns 0 on success; or a non-zero error code value on failure.
2407  */
2408 int elxu_cmd_add_chap(int argc, char **argv)
2409 {
2410  cmd_options_t options;
2411  int rval;
2412  char *separator;
2413  int username_len;
2414  int secret_len;
2415  ocs_chap_user_buffer_t *chap_user_buff;
2416  char *name_and_secret;
2417 
2418  if (argc < 3) {
2419  fprintf(stderr, "Name and secret are required\n");
2420  return -1;
2421  }
2422 
2423  name_and_secret = argv[2];
2424  separator = strchr(argv[2], ':');
2425  if (separator == NULL) {
2426  fprintf(stderr, "Name and secret must be in the format name:secret\n");
2427  return -1;
2428  }
2429  username_len = separator - (char *)argv[2];
2430  secret_len = strlen(argv[2]) - username_len - 1;
2431 
2432  if (parse_arguments(argc, argv, &options, 1, 2) == -1) {
2433  return -1;
2434  }
2435 
2436  if(!is_iscsi(options.device)) {
2437  printf("Add CHAP is only supported in iSCSI\n");
2438  return -1;
2439  }
2440 
2441  chap_user_buff = malloc(sizeof(ocs_chap_user_buffer_t));
2442  if (chap_user_buff == NULL) {
2443  fprintf(stderr, "malloc failed\n");
2444  return -1;
2445  }
2446 
2447  strncpy(chap_user_buff->username, name_and_secret, username_len);
2448  chap_user_buff->username[username_len] = '\0';
2449 
2450  ++separator;
2451  strncpy(chap_user_buff->secret, separator, secret_len);
2452  chap_user_buff->secret[secret_len] = '\0';
2453 
2454  chap_user_buff->type = options.chap_type;
2455  chap_user_buff->mode = OCS_CHAP_MODE_TARGET;
2456 
2457  rval = elxu_device_exec(options.device, "/ocs/add_chap_user", chap_user_buff,
2458  sizeof(*chap_user_buff), NULL, 0);
2459  if (rval == 0) {
2460  printf("CHAP user %s:%s added\n", chap_user_buff->username,
2461  chap_user_buff->secret);
2462  } else {
2463  printf("Failed to add CHAP user %s:%s\n", chap_user_buff->username,
2464  chap_user_buff->secret);
2465  }
2466 
2467  free(chap_user_buff);
2468 
2469  return rval;
2470 }
2471 
2472 /**
2473  * @ingroup cmd_handler
2474  * @brief Command handler for remove-chap
2475  *
2476  * @par Description
2477  * This function processes the remove-chap command
2478  *
2479  * Command: remove-chap<br>
2480  * Required Parameters: name <br>
2481  * Optional Parameters: -d <device> <br>
2482  * Supported Devices: Skyhawk <br>
2483  * Supported Protocols: iSCSI <br>
2484  *
2485  * @param argc The number of command line arguments.
2486  * @param argv An array of pointers to the command line arguments.
2487  *
2488  * @return Returns 0 on success; or a non-zero error code value on failure.
2489  */
2490 int elxu_cmd_remove_chap(int argc, char **argv)
2491 {
2492  cmd_options_t options;
2493  int rval;
2494  ocs_chap_user_buffer_t *chap_user_buff;
2495  char *username;
2496 
2497  if (argc < 3) {
2498  fprintf(stderr, "Name is required\n");
2499  return -1;
2500  }
2501 
2502  username = argv[2];
2503  if (parse_arguments(argc, argv, &options, 1, 2) == -1) {
2504  return -1;
2505  }
2506 
2507  if(!is_iscsi(options.device)) {
2508  printf("Remove CHAP is only supported in iSCSI\n");
2509  return -1;
2510  }
2511 
2512  chap_user_buff = malloc(sizeof(ocs_chap_user_buffer_t));
2513  if (chap_user_buff == NULL) {
2514  fprintf(stderr, "malloc failed\n");
2515  return -1;
2516  }
2517 
2518  strcpy(chap_user_buff->username, username);
2519  /* secret is not required */
2520  chap_user_buff->secret[0] = '\0';
2521  chap_user_buff->type = options.chap_type;
2522  chap_user_buff->mode = OCS_CHAP_MODE_TARGET;
2523 
2524  rval = elxu_device_exec(options.device, "/ocs/remove_chap_user", chap_user_buff,
2525  sizeof(*chap_user_buff), NULL, 0);
2526  if (rval == 0) {
2527  printf("CHAP user %s removed\n", chap_user_buff->username);
2528  } else {
2529  printf("Failed to remove CHAP user %s\n", chap_user_buff->username);
2530  }
2531 
2532  free(chap_user_buff);
2533 
2534  return rval;
2535 }
2536 
2537 /**
2538  * @ingroup cmd_handler
2539  * @brief Command handler for show-chap
2540  *
2541  * @par Description
2542  * This function retrieves the CHAP users list.
2543  * At first stage, read the number of entries of ocs_chap_user_buffer_t
2544  * items by passing arg_in && arg_out buffers as NULL.
2545  * At second stage, allocate required memory for chap users list.
2546  *
2547  * Command: show-chap<br>
2548  * Optional Parameters: -d <device> <br>
2549  * Supported Devices: Skyhawk <br>
2550  * Supported Protocols: iSCSI <br>
2551  *
2552  * @param argc The number of command line arguments.
2553  * @param argv An array of pointers to the command line arguments.
2554  *
2555  * @return Returns 0 on success; or a non-zero error code value on failure.
2556  */
2557 int elxu_cmd_show_chap_list(int argc, char **argv)
2558 {
2559  cmd_options_t options;
2560  int rval;
2561  int cnt;
2562  int ii;
2563  char *out_buf;
2564  int out_buf_size;
2565  ocs_chap_user_buffer_t *chap_user_buff;
2566  int offset;
2567 
2568  if (parse_arguments(argc, argv, &options, 1, 2) == -1) {
2569  return -1;
2570  }
2571 
2572  if(!is_iscsi(options.device)) {
2573  printf("Show CHAP is only supported in iSCSI\n");
2574  return -1;
2575  }
2576 
2577  /*
2578  * To read count of CHAP users list, arg_in & arg_out must be NULL.
2579  * The return is the count of ocs_chap_user_buffer_t items.
2580  */
2581  rval = elxu_device_exec(options.device, "/ocs/show_chap_list",
2582  NULL, 0, NULL, 0);
2583  if (rval < 0)
2584  return rval;
2585 
2586  if (rval == 0) {
2587  printf("CHAP users list is empty\n");
2588  return rval;
2589  }
2590 
2591  cnt = rval;
2592  out_buf_size = cnt * sizeof(ocs_chap_user_buffer_t);
2593  out_buf = malloc(out_buf_size);
2594  if (out_buf == NULL) {
2595  fprintf(stderr, "malloc failed\n");
2596  return -1;
2597  }
2598 
2599  rval = elxu_device_exec(options.device, "/ocs/show_chap_list",
2600  NULL, 0, out_buf, out_buf_size);
2601  if (rval < 0) {
2602  printf("CHAP show users list failed\n");
2603  free(out_buf);
2604  return rval;
2605  }
2606 
2607  offset = 0;
2608  printf("%-16s %-16s %-12s\n", "User", "Secret", "Type");
2609  for (ii = 0; ii < cnt; ii++) {
2610  if (offset >= out_buf_size) {
2611  fprintf(stderr, "CHAP user buffer overflowed\n");
2612  break;
2613  }
2614 
2615  chap_user_buff = (ocs_chap_user_buffer_t *) (out_buf + offset);
2616  printf("%-16s %-16s %-12s\n", chap_user_buff->username, chap_user_buff->secret,
2617  (chap_user_buff->type == OCS_CHAP_TYPE_INCOMING) ? OCS_CHAP_INCOMING :
2619  offset += sizeof(ocs_chap_user_buffer_t);
2620  }
2621 
2622  free(out_buf);
2623  return rval;
2624 }
2625 
2626 /**
2627  * @ingroup cmd_handler
2628  * @brief Command handler for set-require-chap
2629  *
2630  * @par Description
2631  * This function processes the set-require-chap command
2632  *
2633  * Command: set-require-chap<br>
2634  * Required Parameters: true or false <br>
2635  * Optional Parameters: -d <device> <br>
2636  * Supported Devices: Skyhawk <br>
2637  * Supported Protocols: iSCSI <br>
2638  *
2639  * @param argc The number of command line arguments.
2640  * @param argv An array of pointers to the command line arguments.
2641  *
2642  * @return Returns 0 on success; or a non-zero error code value on failure.
2643  */
2644 int elxu_cmd_set_require_chap(int argc, char **argv)
2645 {
2646  cmd_options_t options;
2647  int rval;
2648  char *value;
2649 
2650  if (argc < 3) {
2651  fprintf(stderr, "Value (true or false) is required\n");
2652  return -1;
2653  }
2654 
2655  value = argv[2];
2656 
2657  if ((strcasecmp(value, "true") != 0) &&
2658  (strcasecmp(value, "false") != 0)) {
2659  fprintf(stderr, "Unexpected value '%s' - should be 'true' or 'false'\n", value);
2660  return -1;
2661  }
2662 
2663  if (parse_arguments(argc, argv, &options, 1, 2) == -1) {
2664  return -1;
2665  }
2666 
2667  if(!is_iscsi(options.device)) {
2668  printf("CHAP is only supported in iSCSI\n");
2669  return -1;
2670  }
2671 
2672  rval = mgmt_set_value(options.device, "/ocs/require_chap", value);
2673 
2674  if (rval == 0) {
2675  printf("Require-chap set to %s\n", value);
2676  } else {
2677  printf("Failed to set require-chap, rval is %d\n", rval);
2678  }
2679 
2680  return rval;
2681 }
2682 
2683 /**
2684  * @ingroup cmd_handler
2685  * @brief Command handler for get-require-chap
2686  *
2687  * @par Description
2688  * This function processes the set-require-chap command
2689  *
2690  * Command: get-require-chap<br>
2691  * Required Parameters: None <br>
2692  * Optional Parameters: -d <device> <br>
2693  * Supported Devices: Skyhawk <br>
2694  * Supported Protocols: iSCSI <br>
2695  *
2696  * @param argc The number of command line arguments.
2697  * @param argv An array of pointers to the command line arguments.
2698  *
2699  * @return Returns 0 on success; or a non-zero error code value on failure.
2700  */
2701 int elxu_cmd_get_require_chap(int argc, char **argv)
2702 {
2703  cmd_options_t options;
2704  char *result;
2705 
2706  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
2707  return -1;
2708  }
2709 
2710  if(!is_iscsi(options.device)) {
2711  printf("CHAP is only supported in iSCSI\n");
2712  return -1;
2713  }
2714 
2715  result = elxu_device_get_value(options.device, "/ocs/require_chap");
2716 
2717  if (strlen(result) != 0) {
2718  printf("Require-chap is %s\n", result);
2719  } else {
2720  printf("Failed to get require-chap flag\n");
2721  }
2722 
2723  return 0;
2724 }
2725 
2726 /**
2727  * @ingroup cmd_handler
2728  * @brief Command handler for the enable-jumbo command
2729  *
2730  * @par Description
2731  * This function processes the enable-jumbo command
2732  *
2733  * Command: enable-jumbo<br>
2734  * Required Parameters: None <br>
2735  * Optional Parameters: -d <device> <br>
2736  * Supported Devices: Skyhawk <br>
2737  * Supported Protocols: iSCSI <br>
2738  *
2739  * @param argc The number of command line arguments.
2740  * @param argv An array of pointers to the command line arguments.
2741  *
2742  * @return Returns 0 on success; or a non-zero error code value on failure.
2743  */
2744 int elxu_cmd_enable_jumbo(int argc, char **argv)
2745 {
2746  cmd_options_t options;
2747  int rval;
2748 
2749  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
2750  return -1;
2751  }
2752 
2753  if (!is_iscsi(options.device)) {
2754  fprintf(stderr, "Jumbo frames are only supported on iSCSI\n");
2755  return -1;
2756  }
2757 
2758  rval = mgmt_set_value(options.device, "/ocs/jumbo_frames", "true");
2759 
2760  if (rval) {
2761  fprintf(stderr, "Failed to enable jumbo frames, rval is %d\n", rval);
2762  } else {
2763  printf("Jumbo frames enabled\n");
2764  }
2765 
2766  return rval;
2767 }
2768 
2769 /**
2770  * @ingroup cmd_handler
2771  * @brief Command handler for the disable-jumbo command.
2772  *
2773  * @par Description
2774  * This function processes the disable-jumbo command.
2775  *
2776  * Command: disable-jumbo<br>
2777  * Required Parameters: None <br>
2778  * Optional Parameters: -d <device> <br>
2779  * Supported Devices: Skyhawk <br>
2780  * Supported Protocols: iSCSI <br>
2781  *
2782  * @param argc The number of command line arguments.
2783  * @param argv An array of pointers to the command line arguments.
2784  *
2785  * @return Returns 0 on success; or a non-zero error code value on failure.
2786  */
2787 int elxu_cmd_disable_jumbo(int argc, char **argv)
2788 {
2789  cmd_options_t options;
2790  int rval;
2791 
2792  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
2793  return -1;
2794  }
2795 
2796  if (!is_iscsi(options.device)) {
2797  fprintf(stderr, "Jumbo frames are only supported on iSCSI\n");
2798  return -1;
2799  }
2800 
2801  rval = mgmt_set_value(options.device, "/ocs/jumbo_frames", "false");
2802 
2803  if (rval) {
2804  fprintf(stderr, "Failed to disable jumbo frames, rval is %d\n", rval);
2805  } else {
2806  printf("Jumbo frames disabled\n");
2807  }
2808 
2809  return rval;
2810 }
2811 
2812 /**
2813  * @ingroup cmd_handler
2814  * @brief Command handler for enable-header-digest
2815  *
2816  * @par Description
2817  * This function processes the enable-header-digets command.
2818  *
2819  * Command: enable-header-digest<br>
2820  * Required Parameters: None <br>
2821  * Optional Parameters: -d <device> <br>
2822  * Supported Devices: Skyhawk <br>
2823  * Supported Protocols: iSCSI <br>
2824  *
2825  * @param argc The number of command line arguments.
2826  * @param argv An array of pointers to the command line arguments.
2827  *
2828  * @return Returns 0 on success; or a non-zero error code value on failure.
2829  */
2830 int elxu_cmd_enable_header_digest(int argc, char **argv)
2831 {
2832  cmd_options_t options;
2833  int rval;
2834 
2835  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
2836  return -1;
2837  }
2838 
2839  if (!is_iscsi(options.device)) {
2840  fprintf(stderr, "Header digests are only supported on iSCSI\n");
2841  return -1;
2842  }
2843 
2844  rval = mgmt_set_value(options.device, "/ocs/header_digest", "true");
2845 
2846  if (rval) {
2847  fprintf(stderr, "Failed to enable header digests, rval is %d\n", rval);
2848  } else {
2849  printf("Header digests enabled\n");
2850  }
2851 
2852  return rval;
2853 }
2854 
2855 /**
2856  * @ingroup cmd_handler
2857  * @brief Command handler for the disable-header-digest comand.
2858  *
2859  * @par Description
2860  * This function processes the disable-header-digest command.
2861  *
2862  * Command: disable-header-digest <br>
2863  * Required Parameters: None <br>
2864  * Optional Parameters: -d <device> <br>
2865  * Supported Devices: Skyhawk <br>
2866  * Supported Protocols: iSCSI <br>
2867  *
2868  * @param argc The number of command line arguments.
2869  * @param argv An array of pointers to the command line arguments.
2870  *
2871  * @return Returns 0 on success; or a non-zero error code value on failure.
2872  */
2873 int elxu_cmd_disable_header_digest(int argc, char **argv)
2874 {
2875  cmd_options_t options;
2876  int rval;
2877 
2878  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
2879  return -1;
2880  }
2881 
2882  if (!is_iscsi(options.device)) {
2883  fprintf(stderr, "Header digests are only supported on iSCSI\n");
2884  return -1;
2885  }
2886 
2887  rval = mgmt_set_value(options.device, "/ocs/header_digest", "false");
2888 
2889  if (rval) {
2890  fprintf(stderr, "Failed to disable header digests, rval is %d\n", rval);
2891  } else {
2892  printf("Header digests disabled\n");
2893  }
2894 
2895  return rval;
2896 }
2897 
2898 /**
2899  * @ingroup cmd_handler
2900  * @brief Command handler for enable-data-digest
2901  *
2902  * @par Description
2903  * This function processes the enable-data-digest command.
2904  *
2905  * Command: enable-data-digest<br>
2906  * Required Parameters: None <br>
2907  * Optional Parameters: -d <device> <br>
2908  * Supported Devices: Skyhawk <br>
2909  * Supported Protocols: iSCSI <br>
2910  *
2911  * @param argc The number of command line arguments.
2912  * @param argv An array of pointers to the command line arguments.
2913  *
2914  * @return Returns 0 on success; or a non-zero error code value on failure.
2915  */
2916 int elxu_cmd_enable_data_digest(int argc, char **argv)
2917 {
2918  cmd_options_t options;
2919  int rval;
2920 
2921  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
2922  return -1;
2923  }
2924 
2925  if (!is_iscsi(options.device)) {
2926  fprintf(stderr, "Data digests are only supported on iSCSI\n");
2927  return -1;
2928  }
2929 
2930  rval = mgmt_set_value(options.device, "/ocs/data_digest", "true");
2931 
2932  if (rval) {
2933  fprintf(stderr, "Failed to enable data digests, rval is %d\n", rval);
2934  } else {
2935  printf("Data digests enabled\n");
2936  }
2937 
2938  return rval;
2939 }
2940 
2941 /**
2942  * @ingroup cmd_handler
2943  * @brief Command handler for the disable-data-digest command.
2944  *
2945  * @par Description
2946  * This function processes the disable-data-digest command.
2947  *
2948  * Command: disable-data-digest<br>
2949  * Required Parameters: None <br>
2950  * Optional Parameters: -d <device> <br>
2951  * Supported Devices: Skyhawk <br>
2952  * Supported Protocols: iSCSI <br>
2953  *
2954  * @param argc The number of command line arguments.
2955  * @param argv An array of pointers to the command line arguments.
2956  *
2957  * @return Returns 0 on success; or a non-zero error code value on failure.
2958  */
2959 int elxu_cmd_disable_data_digest(int argc, char **argv)
2960 {
2961  cmd_options_t options;
2962  int rval;
2963 
2964  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
2965  return -1;
2966  }
2967 
2968  if (!is_iscsi(options.device)) {
2969  fprintf(stderr, "Data digests are only supported on iSCSI\n");
2970  return -1;
2971  }
2972 
2973  rval = mgmt_set_value(options.device, "/ocs/data_digest", "false");
2974 
2975  if (rval) {
2976  fprintf(stderr, "Failed to disable data digests, rval is %d\n", rval);
2977  } else {
2978  printf("Data digests disabled\n");
2979  }
2980 
2981  return rval;
2982 }
2983 
2984 /**
2985  * @ingroup cmd_handler
2986  * @brief Command handler for the set-tcp-window-size command.
2987  *
2988  * @par Description
2989  * This function processes the set-tcp-window-size command.
2990  *
2991  * Command: set-tcp-window-size<br>
2992  * Required Parameters: window_size <br>
2993  * Optional Parameters: -d <device> <br>
2994  * Supported Devices: Skyhawk <br>
2995  * Supported Protocols: iSCSI <br>
2996  *
2997  * @param argc The number of command line arguments.
2998  * @param argv An array of pointers to the command line arguments.
2999  *
3000  * @return Returns 0 on success; or a non-zero error code value on failure.
3001  */
3002 int elxu_cmd_set_tcp_window_size(int argc, char **argv)
3003 {
3004  cmd_options_t options;
3005  uint32_t window_size;
3006  int rval;
3007 
3008  if (argc < 3) {
3009  fprintf(stderr, "Window size is required\n");
3010  return -1;
3011  }
3012 
3013  window_size = strtoul(argv[2], NULL, 10);
3014  if ((window_size < 1) || (window_size > 65535)) {
3015  fprintf(stderr, "Windows size %d invalid. Valid range is 1 to 65535\n", window_size);
3016  return -1;
3017  }
3018 
3019  if (parse_arguments(argc, argv, &options, 1, 2) == -1) {
3020  return -1;
3021  }
3022 
3023  if (!is_iscsi(options.device)) {
3024  fprintf(stderr, "Window size command is only supported on iSCSI\n");
3025  return -1;
3026  }
3027 
3028  rval = mgmt_set_value(options.device, "/ocs/tcp_window_size", argv[2]);
3029 
3030  if (rval) {
3031  fprintf(stderr, "Failed to set window size, rval is %d\n", rval);
3032  } else {
3033  printf("Window size set\n");
3034  }
3035 
3036  return rval;
3037 }
3038 
3039 /**
3040  * @ingroup cmd_handler
3041  * @brief Command handler for get-tcp-window-size
3042  *
3043  * @par Description
3044  * This function processes the get-tcp-window-size command.
3045  *
3046  * Command: get-tcp-window-size<br>
3047  * Required Parameters: None <br>
3048  * Optional Parameters: -d <device> <br>
3049  * Supported Devices: Skyhawk <br>
3050  * Supported Protocols: iSCSI <br>
3051  *
3052  * @param argc The number of command line arguments.
3053  * @param argv An array of pointers to the command line arguments.
3054  *
3055  * @return Returns 0 on success; or a non-zero error code value on failure.
3056  */
3057 int elxu_cmd_get_tcp_window_size(int argc, char **argv)
3058 {
3059  cmd_options_t options;
3060  int rval;
3061  char *result;
3062 
3063  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
3064  return -1;
3065  }
3066 
3067  if (!is_iscsi(options.device)) {
3068  fprintf(stderr, "Window size command is only supported on iSCSI\n");
3069  return -1;
3070  }
3071 
3072  result = elxu_device_get_value(options.device, "/ocs/tcp_window_size");
3073 
3074  if (strlen(result) == 0) {
3075  fprintf(stderr, "Failed to get window size\n");
3076  rval = -1;
3077  } else {
3078  printf("Current window size is %s\n", result);
3079  rval = 0;
3080  }
3081 
3082  return rval;
3083 }
3084 
3085 /**
3086  * @ingroup cmd_handler
3087  * @brief Command handler for set-tcp-window-scale
3088  *
3089  * @par Description
3090  * This function processes the set-tcp-window-scale command.
3091  *
3092  * Command: set-tcp-window-scale<br>
3093  * Required Parameters: <window_scale> <br>
3094  * Optional Parameters: -d <device> <br>
3095  * Supported Devices: Skyhawk <br>
3096  * Supported Protocols: iSCSI <br>
3097  *
3098  * @param argc The number of command line arguments.
3099  * @param argv An array of pointers to the command line arguments.
3100  *
3101  * @return Returns 0 on success; or a non-zero error code value on failure.
3102  */
3103 int elxu_cmd_set_tcp_window_scale(int argc, char **argv)
3104 {
3105  cmd_options_t options;
3106  uint32_t window_scale;
3107  int rval;
3108 
3109  if (argc < 3) {
3110  fprintf(stderr, "Window scale is required\n");
3111  return -1;
3112  }
3113 
3114  window_scale = strtoul(argv[2], NULL, 10);
3115  if (window_scale > 14) {
3116  fprintf(stderr, "Windows scale %d invalid. Valid range is 0 to 14\n", window_scale);
3117  return -1;
3118  }
3119 
3120  if (parse_arguments(argc, argv, &options, 1, 2) == -1) {
3121  return -1;
3122  }
3123 
3124  if (!is_iscsi(options.device)) {
3125  fprintf(stderr, "Window scale command is only supported on iSCSI\n");
3126  return -1;
3127  }
3128 
3129  rval = mgmt_set_value(options.device, "/ocs/tcp_window_scale", argv[2]);
3130 
3131  if (rval) {
3132  fprintf(stderr, "Failed to set window scale, rval is %d\n", rval);
3133  } else {
3134  printf("Window scale set\n");
3135  }
3136 
3137  return rval;
3138 }
3139 
3140 /**
3141  * @ingroup cmd_handler
3142  * @brief Command handler for get-tcp-window-scale
3143  *
3144  * @par Description
3145  * This function processes the get-tcp-window-scale command.
3146  *
3147  * Command: get-tcp-window-scale<br>
3148  * Required Parameters: None <br>
3149  * Optional Parameters: -d <device> <br>
3150  * Supported Devices: Skyhawk <br>
3151  * Supported Protocols: iSCSI <br>
3152  *
3153  * @param argc The number of command line arguments.
3154  * @param argv An array of pointers to the command line arguments.
3155  *
3156  * @return Returns 0 on success; or a non-zero error code value on failure.
3157  */
3158 int elxu_cmd_get_tcp_window_scale(int argc, char **argv)
3159 {
3160  cmd_options_t options;
3161  int rval;
3162  char *result;
3163 
3164  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
3165  return -1;
3166  }
3167 
3168  if (!is_iscsi(options.device)) {
3169  fprintf(stderr, "Window scale command is only supported on iSCSI\n");
3170  return -1;
3171  }
3172 
3173  result = elxu_device_get_value(options.device, "/ocs/tcp_window_scale");
3174 
3175  if (strlen(result) == 0) {
3176  fprintf(stderr, "Failed to get window scale\n");
3177  rval = -1;
3178  } else {
3179  printf("Current window scale is %s\n", result);
3180  rval = 0;
3181  }
3182 
3183  return rval;
3184 }
3185 
3186 /**
3187  * @ingroup cmd_handler
3188  * @brief Command handler for set-max-connections
3189  *
3190  * @par Description
3191  * This function processes the set-max-connections command.
3192  *
3193  * Command: set-max-connections<br>
3194  * Required Parameters: <max_connections_per_session> <br>
3195  * Optional Parameters: -d <device> <br>
3196  * Supported Devices: Skyhawk <br>
3197  * Supported Protocols: iSCSI <br>
3198  *
3199  * @param argc The number of command line arguments.
3200  * @param argv An array of pointers to the command line arguments.
3201  *
3202  * @return Returns 0 on success; or a non-zero error code value on failure.
3203  */
3204 int elxu_cmd_set_max_connections(int argc, char **argv)
3205 {
3206  cmd_options_t options;
3207  int rval;
3208 
3209  if (argc < 3) {
3210  fprintf(stderr, "Max connections is required\n");
3211  return -1;
3212  }
3213 
3214  if (parse_arguments(argc, argv, &options, 1, 2) == -1) {
3215  return -1;
3216  }
3217 
3218  if (!is_iscsi(options.device)) {
3219  fprintf(stderr, "Max connections command is only supported on iSCSI\n");
3220  return -1;
3221  }
3222 
3223  rval = mgmt_set_value(options.device, "/ocs/max_cxns_per_session", argv[2]);
3224 
3225  if (rval) {
3226  fprintf(stderr, "Failed to set max connections per session, rval is %d\n", rval);
3227  } else {
3228  printf("Max connections per session set\n");
3229  }
3230 
3231  return rval;
3232 }
3233 
3234 /**
3235  * @ingroup cmd_handler
3236  * @brief Command handler for get-max-connections
3237  *
3238  * @par Description
3239  * This function processes the get-max-connections command.
3240  *
3241  * Command: get-max-connections<br>
3242  * Required Parameters: None <br>
3243  * Optional Parameters: -d <device> <br>
3244  * Supported Devices: Skyhawk <br>
3245  * Supported Protocols: iSCSI <br>
3246  *
3247  * @param argc The number of command line arguments.
3248  * @param argv An array of pointers to the command line arguments.
3249  *
3250  * @return Returns 0 on success; or a non-zero error code value on failure.
3251  */
3252 int elxu_cmd_get_max_connections(int argc, char **argv)
3253 {
3254  cmd_options_t options;
3255  int rval;
3256  char *result;
3257 
3258  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
3259  return -1;
3260  }
3261 
3262  if (!is_iscsi(options.device)) {
3263  fprintf(stderr, "Max connections command is only supported on iSCSI\n");
3264  return -1;
3265  }
3266 
3267  result = elxu_device_get_value(options.device, "/ocs/max_cxns_per_session");
3268 
3269  if (strlen(result) == 0) {
3270  fprintf(stderr, "Failed to get max connections per session\n");
3271  rval = -1;
3272  } else {
3273  printf("Current max connections per session is %s\n", result);
3274  rval = 0;
3275  }
3276 
3277  return rval;
3278 }
3279 
3280 /**
3281  * @ingroup cmd_handler
3282  * @brief Command handler for start-listen
3283  *
3284  * @par Description
3285  * This function processes the start-listen command.
3286  *
3287  * Command: start-listen<br>
3288  * Required Parameters: <ip_address> <br>
3289  * Optional Parameters: -d <device> <br>
3290  * Supported Devices: Skyhawk <br>
3291  * Supported Protocols: iSCSI <br>
3292  *
3293  * @param argc The number of command line arguments.
3294  * @param argv An array of pointers to the command line arguments.
3295  *
3296  * @return Returns 0 on success; or a non-zero error code value on failure.
3297  */
3298 int elxu_cmd_start_listen(int argc, char **argv)
3299 {
3300  cmd_options_t options;
3301  int rval;
3302  char *ip_addr;
3303 
3304  if (argc < 3) {
3305  fprintf(stderr, "IP address is required\n");
3306  return -1;
3307  }
3308 
3309  ip_addr = argv[2];
3310 
3311  if (parse_arguments(argc, argv, &options, 1, 2) == -1) {
3312  return -1;
3313  }
3314 
3315  if(!is_iscsi(options.device)) {
3316  printf("Start-listen is only supported in iSCSI\n");
3317  return -1;
3318  }
3319 
3320  rval = elxu_device_exec(options.device, "/ocs/listen_start", ip_addr, strlen(ip_addr), NULL, 0);
3321 
3322  if (rval == 0) {
3323  printf("Now listening on IP address %s\n", ip_addr);
3324  } else {
3325  printf("Failed to start listening on IP address %s\n", ip_addr);
3326  }
3327 
3328  return rval;
3329 }
3330 
3331 /**
3332  * @ingroup cmd_handler
3333  * @brief Command handler for stop-listen
3334  *
3335  * @par Description
3336  * This function processes the stop-listen command.
3337  *
3338  * Command: stop-listen<br>
3339  * Required Parameters: <ip_address> <br>
3340  * Optional Parameters: -d <device> <br>
3341  * Supported Devices: Skyhawk <br>
3342  * Supported Protocols: iSCSI <br>
3343  *
3344  * @param argc The number of command line arguments.
3345  * @param argv An array of pointers to the command line arguments.
3346  *
3347  * @return Returns 0 on success; or a non-zero error code value on failure.
3348  */
3349 int elxu_cmd_stop_listen(int argc, char **argv)
3350 {
3351  cmd_options_t options;
3352  int rval;
3353  char *ip_addr;
3354 
3355  if (argc < 3) {
3356  fprintf(stderr, "IP address is required\n");
3357  return -1;
3358  }
3359 
3360  ip_addr = argv[2];
3361 
3362  if (parse_arguments(argc, argv, &options, 1, 2) == -1) {
3363  return -1;
3364  }
3365 
3366  if(!is_iscsi(options.device)) {
3367  printf("Stop-listen is only supported in iSCSI\n");
3368  return -1;
3369  }
3370 
3371  rval = elxu_device_exec(options.device, "/ocs/listen_stop", ip_addr, strlen(ip_addr), NULL, 0);
3372 
3373  if (rval == 0) {
3374  printf("Stopped listening on IP address %s\n", ip_addr);
3375  } else {
3376  printf("Failed to stop listening on IP address %s\n", ip_addr);
3377  }
3378 
3379  return rval;
3380 }
3381 
3382 /**
3383  * @ingroup cmd_handler
3384  * @brief Command handler for the set-mac command.
3385  *
3386  * @par Description
3387  * This function processes the set-mac command.
3388  *
3389  * Command: set-mac <br>
3390  * Required Parameters: <mac address> <br>
3391  * Optional Parameters: -d <device> <br>
3392  * Supported Devices: Skyhawk <br>
3393  * Supported Protocols: iSCSI <br>
3394  *
3395  * @param argc The number of command line arguments.
3396  * @param argv An array of pointers to the command line arguments.
3397  *
3398  * @return Returns 0 on success; or a non-zero error code value on failure.
3399  */
3400 
3401 /*
3402  * NOTE: This function is not currently being use because of issues with
3403  * setting the MAC address through the OCS driver.
3404  */
3405 int elxu_cmd_set_mac_ocs(int argc, char **argv)
3406 {
3407  char *macaddr_p;
3408  cmd_options_t options;
3409 
3410  if (argc < 3) {
3411  fprintf(stderr, "MAC address value is required\n");
3412  return -1;
3413  }
3414 
3415  macaddr_p = argv[2];
3416 
3417  if (parse_arguments(argc, argv, &options, 1, 2) == -1) {
3418  return -1;
3419  }
3420 
3421  if(!is_iscsi(options.device)) {
3422  printf("Soft assigned MAC is only supported in iSCSI\n");
3423  return -1;
3424  }
3425 
3426  int macaddr[6];
3427 
3428  sscanf(macaddr_p, "%x:%x:%x:%x:%x:%x",
3429  &macaddr[0], &macaddr[1], &macaddr[2],
3430  &macaddr[3], &macaddr[4], &macaddr[5]);
3431 
3432  printf(" soft assigned MAC: %02x:%02x:%02x:%02x:%02x:%02x\n",
3433  macaddr[0], macaddr[1], macaddr[2],
3434  macaddr[3], macaddr[4], macaddr[5]);
3435 
3436  return mbox_soft_assign_mac(options.device, macaddr);
3437 }
3438 
3439 /**
3440  * @ingroup cmd_handler
3441  * @brief Command handler for the set-nv-mac command.
3442  *
3443  * @par Description
3444  * This function processes the set-nv-mac command.
3445  *
3446  * Command: set-nv-mac <br>
3447  * Required Parameters: <mac address> <br>
3448  * Optional Parameters: -d <device> <br>
3449  * Supported Devices: Skyhawk <br>
3450  * Supported Protocols: iSCSI <br>
3451  *
3452  * @param argc The number of command line arguments.
3453  * @param argv An array of pointers to the command line arguments.
3454  *
3455  * @return Returns 0 on success; or a non-zero error code value on failure.
3456  */
3457 int elxu_cmd_set_nv_mac_pt(int argc, char **argv)
3458 {
3459  char *macaddr_p;
3460  cmd_options_t options;
3461  int rc;
3462 
3463  if (argc < 3) {
3464  fprintf(stderr, "MAC address value is required\n");
3465  return -1;
3466  }
3467 
3468  macaddr_p = argv[2];
3469 
3470  if (parse_arguments(argc, argv, &options, 1, 2) == -1) {
3471  return -1;
3472  }
3473 
3474  if(!is_iscsi(options.device) && !(is_nic(options.device))) {
3475  printf("MAC addresses apply only to iSCSI and NIC\n");
3476  return -1;
3477  }
3478 
3479  int macaddr[6];
3480 
3481  sscanf(macaddr_p, "%x:%x:%x:%x:%x:%x",
3482  &macaddr[0], &macaddr[1], &macaddr[2],
3483  &macaddr[3], &macaddr[4], &macaddr[5]);
3484 
3485  rc = mbox_set_nv_mac_pt(options.device, macaddr);
3486 
3487  if (rc == 0) {
3488  printf(" New MAC address: %02x:%02x:%02x:%02x:%02x:%02x\n",
3489  macaddr[0], macaddr[1], macaddr[2],
3490  macaddr[3], macaddr[4], macaddr[5]);
3491  } else {
3492  printf(" Failed to change MAC address\n");
3493  }
3494 
3495  return rc;
3496 }
3497 
3498 /**
3499  * @ingroup cmd_handler
3500  * @brief Command handler for the show-mac command for the OCS drivers
3501  *
3502  * @par Description
3503  * This function processes the show-mac command
3504  *
3505  * Command: show-mac <br>
3506  * Required Parameters: None <br>
3507  * Optional Parameters: -d <device> <br>
3508  * Supported Devices: Skyhawk <br>
3509  * Supported Protocols: iSCSI <br>
3510  *
3511  * @param argc The number of command line arguments.
3512  * @param argv An array of pointers to the command line arguments.
3513  *
3514  * @return Returns 0 on success; or a non-zero error code value on failure.
3515  */
3516 int elxu_cmd_show_mac_ocs(int argc, char **argv)
3517 {
3518  cmd_options_t options;
3519  char *mac;
3520  int i;
3521 
3522  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
3523  return -1;
3524  }
3525 
3526  if (!is_iscsi(options.device)) {
3527  fprintf(stderr, "Show MAC command is only supported on iSCSI\n");
3528  return -1;
3529  }
3530 
3531 
3532  mac = elxu_device_get_value(options.device, "/ocs/domain[0]/sport[0]/mac");
3533 
3534 
3535  if (strlen(mac) != 0) {
3536  printf(" MAC on adapter: ");
3537  for (i=0; i<strlen(mac); i++) {
3538  printf("%c", mac[i]);
3539  if (((i % 2) == 1) && (i != strlen(mac)-1)) {
3540  printf(":");
3541  }
3542  }
3543  printf("\n");
3544  return 0;
3545  } else {
3546  printf(" Unable to retrieve MAC address\n");
3547  return -1;
3548  }
3549 }
3550 
3551 /**
3552  * @ingroup cmd_handler
3553  * @brief Command handler for the show-mac command for the elx_pt driver.
3554  *
3555  * @par Description
3556  * This function processes the show-mac command.
3557  *
3558  * Command: show-mac <br>
3559  * Required Parameters: None <br>
3560  * Optional Parameters: -d <device> <br>
3561  * Supported Devices: Skyhawk <br>
3562  * Supported Protocols: iSCSI <br>
3563  *
3564  * @param argc The number of command line arguments.
3565  * @param argv An array of pointers to the command line arguments.
3566  *
3567  * @return Returns 0 on success; or a non-zero error code value on failure.
3568  */
3569 int elxu_cmd_show_mac_pt(int argc, char **argv)
3570 {
3571  cmd_options_t options;
3572  uint8_t mac[6];
3573 
3574  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
3575  return -1;
3576  }
3577 
3578  if (!is_iscsi(options.device) && !is_nic(options.device)) {
3579  fprintf(stderr, "Show MAC command is only supported on iSCSI and NIC\n");
3580  return -1;
3581  }
3582 
3583  mbox_get_mac_pt(options.device, mac);
3584 
3585  printf(" MAC on adapter: %s\n", hex_dump(mac, 6));
3586 
3587  return 0;
3588 }
3589 
3590 /**
3591  * @ingroup cmd_handler
3592  * @brief Command handler for the show-wwn command.
3593  *
3594  * @par Description
3595  * This function processes the show-wwn command.
3596  *
3597  * Command: show-wwn <br>
3598  * Required Parameters: None <br>
3599  * Optional Parameters: -d <device> <br>
3600  * Supported Devices: All <br>
3601  * Supported Protocols: FC <br>
3602  *
3603  * @param argc The number of command line arguments.
3604  * @param argv An array of pointers to the command line arguments.
3605  *
3606  * @return Returns 0 on success; or a non-zero error code value on failure.
3607  */
3608 int elxu_cmd_show_wwn(int argc, char **argv)
3609 {
3610  cmd_options_t options;
3611 
3612  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
3613  return -1;
3614  }
3615 
3616  if (!is_fc(options.device)) {
3617  fprintf(stderr, "Show WWN command is only supported on FC\n");
3618  return -1;
3619  }
3620 
3621  printf("WWNN: %s\n", hex_dump(options.device->wwnn, 8));
3622  printf("WWPN: %s\n", hex_dump(options.device->wwpn, 8));
3623 
3624  return 0;
3625 }
3626 
3627 /**
3628  * @ingroup cmd_handler
3629  * @brief Command handler for the set-wwn command.
3630  *
3631  * @par Description
3632  * This function processes the set-wwn command.
3633  *
3634  * Command: set-wwn <br>
3635  * Required Parameters: WWN <br>
3636  * Optional Parameters: -d <device> <br>
3637  * Supported Devices: All <br>
3638  * Supported Protocols: FC <br>
3639  *
3640  * @param argc The number of command line arguments.
3641  * @param argv An array of pointers to the command line arguments.
3642  *
3643  * @return Returns 0 on success; or a non-zero error code value on failure.
3644  */
3645 int elxu_cmd_set_wwn(int argc, char **argv)
3646 {
3647  cmd_options_t options;
3648  char *wwpn_p;
3649  char *wwnn_p;
3650  char *wwn_p;
3651  int rc = -1;
3652 
3653  if (argc < 3) {
3654  //Too few arguments
3655  fprintf(stderr, "WWN value is required\n");
3656  return -1;
3657  }
3658 
3659  if (parse_arguments(argc, argv, &options, 1, 2) == -1) {
3660  return -1;
3661  }
3662 
3663  if(!is_fc(options.device)) {
3664  printf("WWN applies only to FC\n");
3665  return -1;
3666  }
3667 
3668  wwn_p = zmalloc(80);
3669  if (wwn_p == NULL) {
3670  return -1;
3671  }
3672 
3673  wwpn_p = options.wwpn;
3674  wwnn_p = options.wwnn;
3675 
3676  if ((wwpn_p == NULL) && (wwnn_p == NULL)) {
3677  printf("Failed to set WWN. Please provide valid WWNN/WWPN as input.\n");
3678  zfree(wwn_p);
3679  return -1;
3680  }
3681  /* Prepare wwn_p string which contains wwpn@wwnn */
3682  if (wwpn_p != NULL) {
3683  strncpy(wwn_p, wwpn_p, strlen(wwpn_p));
3684  } else {
3685  strncat(wwn_p, "NA", 2);
3686  }
3687  strncat(wwn_p, "@", 1);
3688 
3689  if (wwnn_p != NULL) {
3690  strncat(wwn_p, wwnn_p, strlen(wwnn_p));
3691  } else {
3692  strncat(wwn_p, "NA", 2);
3693  }
3694 
3695  if (options.device->driver == DEVICE_DRIVER_PT) {
3696  rc = mbox_set_nv_wwn_pt(options.device, wwpn_p, wwnn_p);
3697  } else if (options.device->driver == DEVICE_DRIVER_OCS) {
3698  rc = mgmt_set_value(options.device, "/ocs/nv_wwn", wwn_p);
3699  }
3700 
3701  if (rc == 0) {
3702  if (wwnn_p != NULL) {
3703  printf("New WWNN: %s\n", wwnn_p);
3704  }
3705 
3706  if (wwpn_p != NULL) {
3707  printf("New WWPN: %s\n", wwpn_p);
3708  }
3709  printf("Successfully changed WWN. Please reset adapter for changes to take effect.\n");
3710  } else {
3711  printf("Failed to change WWN\n");
3712  }
3713 
3714  zfree(wwn_p);
3715  return rc;
3716 }
3717 
3718 /**
3719  * @ingroup cmd_handler
3720  * @brief Command handler for the driver-info command.
3721  *
3722  * @par Description
3723  * This function processes the driver-info command.
3724  *
3725  * Command: driver-info <br>
3726  * Required Parameters: None <br>
3727  * Optional Parameters: -d <device> <br>
3728  * Supported Devices: All <br>
3729  * Supported Protocols: N/A <br>
3730  *
3731  * @param argc The number of command line arguments.
3732  * @param argv An array of pointers to the command line arguments.
3733  *
3734  * @return Returns 0 on success; or a non-zero error code value on failure.
3735  */
3736 int elxu_cmd_driver_info(int argc, char **argv)
3737 {
3738  cmd_options_t options;
3739  mgmt_list_t *status_list;
3740  mgmt_object_t *obj;
3741  char *value;
3742 
3743  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
3744  return -1;
3745  }
3746 
3747  /* The test team wants driver_version and pm_state first */
3748  value = elxu_device_get_value(options.device, "/ocs/driver_version");
3749  if (value && (strlen(value) > 0)) {
3750  printf(" driver_version: %s\n", value);
3751  }
3752 
3753  value = elxu_device_get_value(options.device, "/ocs/driver/pm_state");
3754  if (value && (strlen(value) > 0)) {
3755  printf(" pm_state: %s\n", value);
3756  }
3757 
3758  status_list = mgmt_get_all(options.device);
3759 
3760  /* Remove pm_state from the list if it's there */
3761  obj = mgmt_list_remove(status_list, "/ocs/driver/pm_state");
3762 
3763  /* Sort the remaining list items */
3764  mgmt_list_sort(status_list);
3765 
3766  /* Report the list items that start with /ocs/driver/ */
3767  obj = status_list->head;
3768  while (obj) {
3769  mgmt_property_t *prop;
3770 
3771  prop = obj->head;
3772  if (strncmp(prop->name, "/ocs/driver/", 12) == 0) {
3773  if (strstr(prop->access, "r") && (strlen(prop->value) > 0)) {
3774  char *s;
3775  s = strrchr(prop->name, '/') + 1;
3776  printf(" %s: %s\n", s, prop->value);
3777  }
3778  }
3779  obj = obj->next;
3780  }
3781 
3782  mgmt_delete_list(status_list);
3783 
3784  return 0;
3785 }
3786 
3787 /**
3788  * @ingroup cmd_handler
3789  * @brief Command handler for the create-vport command.
3790  *
3791  * @par Description
3792  * This function processes the create-vport command.
3793  *
3794  * Command: create-vport <br>
3795  * Required Parameters: [<wwnn> <wwpn>] ( --target | --initiator ) <br>
3796  * Optional Parameters: -d <device> <br>
3797  * Supported Devices: All <br>
3798  * Supported Protocols: FC <br>
3799  *
3800  * @param argc The number of command line arguments.
3801  * @param argv An array of pointers to the command line arguments.
3802  *
3803  * @return Returns 0 on success; or a non-zero error code value on failure.
3804  */
3805 int elxu_cmd_create_vport(int argc, char **argv)
3806 {
3807  char *wwnn_arg;
3808  char *wwpn_arg;
3809  uint64_t wwnn;
3810  uint64_t wwpn;
3811  cmd_options_t options;
3812 
3813  /* If wwnn and wwpn are provided they will be argv[2] and argv[3].
3814  * They can be omitted, in which case they default to zeroes.
3815  * Either --target, --initiator, or both must be specified
3816  */
3817  if (argc < 3) {
3818  // Too few arguments
3819  usage();
3820  return -1;
3821  }
3822 
3823  if (argv[2][0] == '-') {
3824  // argv[2] begins with a -, so the wwnn and wwpn were omitted
3825  wwnn_arg="00:00:00:00:00:00:00:00";
3826  wwpn_arg="00:00:00:00:00:00:00:00";
3827  } else {
3828  wwnn_arg = argv[2];
3829  wwpn_arg = argv[3];
3830  }
3831 
3832  if (parse_arguments(argc, argv, &options, 1, 3) == -1) {
3833  return -1;
3834  }
3835 
3836  if (!options.target && !options.initiator) {
3837  fprintf(stderr, "Must specify either --target or --initiator\n");
3838  return -1;
3839  }
3840 
3841  if ((!is_fc(options.device)) && (!is_fcoe(options.device))) {
3842  fprintf(stderr, "Vports are only supported on FC and FCoE\n");
3843  return -1;
3844  }
3845 
3846  if (parse_wwn(wwnn_arg, &wwnn) != 0) {
3847  printf("Invalid WWNN: %s\n", wwnn_arg);
3848  return -1;
3849  }
3850 
3851  if (parse_wwn(wwpn_arg, &wwpn) != 0) {
3852  printf("Invalid WWPN: %s\n", wwpn_arg);
3853  return -1;
3854  }
3855 
3856  return create_vport(options.device, wwnn, wwpn, options.target, options.initiator);
3857 }
3858 
3859 /**
3860  * @ingroup cmd_handler
3861  * @brief Command handler for the remove-vport command.
3862  *
3863  * @par Description
3864  * This function processes the remove-vport command.
3865  *
3866  * Command: remove-vport <br>
3867  * Required Parameters: <wwn> <wwn> <br>
3868  * Optional Parameters: -d <device> <br>
3869  * Supported Devices: All <br>
3870  * Supported Protocols: FC <br>
3871  *
3872  * @param argc The number of command line arguments.
3873  * @param argv An array of pointers to the command line arguments.
3874  *
3875  * @return Returns 0 on success; or a non-zero error code value on failure.
3876  */
3877 int elxu_cmd_remove_vport(int argc, char **argv)
3878 {
3879  char *wwnn_arg;
3880  char *wwpn_arg;
3881  uint64_t wwnn;
3882  uint64_t wwpn;
3883  cmd_options_t options;
3884 
3885  if (argc < 4) {
3886  fprintf(stderr, "WWNN and WWPN are required\n");
3887  return -1;
3888  }
3889 
3890  wwnn_arg = argv[2];
3891  wwpn_arg = argv[3];
3892 
3893  if (parse_arguments(argc, argv, &options, 1, 3) == -1) {
3894  return -1;
3895  }
3896 
3897  if ((!is_fc(options.device)) && (!is_fcoe(options.device))) {
3898  fprintf(stderr, "Vports are only supported on FC and FCoE\n");
3899  return -1;
3900  }
3901 
3902  if (parse_wwn(wwnn_arg, &wwnn) != 0) {
3903  printf("Invalid WWNN: %s\n", wwnn_arg);
3904  return -1;
3905  }
3906 
3907  if (parse_wwn(wwpn_arg, &wwpn) != 0) {
3908  printf("Invalid WWPN: %s\n", wwpn_arg);
3909  return -1;
3910  }
3911 
3912  return remove_vport(options.device, wwnn, wwpn, options.target, options.initiator);
3913 }
3914 
3915 /**
3916  * @ingroup cmd_handler
3917  * @brief Command handler for the linkcfg-get command.
3918  *
3919  * @par Description
3920  * This function processes the linkcfg-get command.
3921  *
3922  * Command: linkcfg-get <br>
3923  * Required Parameters: None <br>
3924  * Optional Parameters: -d <device> <br>
3925  * Supported Devices: All <br>
3926  * Supported Protocols: N/A <br>
3927  *
3928  * @param argc The number of command line arguments.
3929  * @param argv An array of pointers to the command line arguments.
3930  *
3931  * @return Returns 0 on success; or a non-zero error code value on failure.
3932  */
3933 int elxu_cmd_get_linkcfg(int argc, char **argv)
3934 {
3935  cmd_options_t options;
3936  char *linkcfg = NULL;
3937 
3938  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
3939  return -1;
3940  }
3941 
3942  if (options.device->driver == DEVICE_DRIVER_OCS) {
3943  /* send IOCTL to get link config; note this will use the generic
3944  * "get config" management framework -- no need to add a dedicated
3945  * IOCTL
3946  */
3947  linkcfg = elxu_device_get_value(options.device, "/ocs/linkcfg");
3948  } else if (options.device->driver == DEVICE_DRIVER_PT) {
3949  linkcfg = mbox_get_linkcfg_pt(options.device);
3950  }
3951  if (linkcfg == NULL) {
3952  printf("Failed to get linkcfg value\n");
3953  return -1;
3954  }
3955  printf("Link config: %s\n", linkcfg);
3956  return 0;
3957 }
3958 
3959 /**
3960  * @ingroup cmd_handler
3961  * @brief Command handler for the linkspeed-get command.
3962  *
3963  * @par Description
3964  * This function processes the linkspeed-get command.
3965  *
3966  * Command: linkspeed-get <br>
3967  * Required Parameters: None <br>
3968  * Optional Parameters: -d <device> <br>
3969  * Supported Devices: All <br>
3970  * Supported Protocols: N/A <br>
3971  *
3972  * @param argc The number of command line arguments.
3973  * @param argv An array of pointers to the command line arguments.
3974  *
3975  * @return Returns 0 on success; or a non-zero error code value on failure.
3976  */
3977 int elxu_cmd_get_linkspeed(int argc, char **argv)
3978 {
3979  cmd_options_t options;
3980  char *linkspeed = NULL;
3981 
3982  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
3983  return -1;
3984  }
3985 
3986  if (options.device->driver == DEVICE_DRIVER_OCS) {
3987  /* send IOCTL to get link config; note this will use the generic
3988  * "get linkspeed" management framework -- no need to add a dedicated
3989  * IOCTL
3990  */
3991  linkspeed = elxu_device_get_value(options.device, "/ocs/configured_speed");
3992  }
3993  if (linkspeed == NULL) {
3994  printf("Failed to get linkspeed value\n");
3995  return -1;
3996  }
3997  printf("Link speed: %s\n", linkspeed);
3998  return 0;
3999 }
4000 
4001 /**
4002 * @ingroup cmd_handler
4003  * @brief Command handler for the linktopology-get command.
4004  *
4005  * @par Description
4006  * This function processes the linktopology-get command.
4007  *
4008  * Command: linktopology-get <br>
4009  * Required Parameters: None <br>
4010  * Optional Parameters: -d <device> <br>
4011  * Supported Devices: All <br>
4012  * Supported Protocols: N/A <br>
4013  *
4014  * @param argc The number of command line arguments.
4015  * @param argv An array of pointers to the command line arguments.
4016  *
4017  * @return Returns 0 on success; or a non-zero error code value on failure.
4018  */
4019 int elxu_cmd_get_linktopology(int argc, char **argv)
4020 {
4021  cmd_options_t options;
4022  char *linktopology = NULL;
4023 
4024  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
4025  return -1;
4026  }
4027 
4028  if (options.device->driver == DEVICE_DRIVER_OCS) {
4029  /* send IOCTL to get link config; note this will use the generic
4030  * "get linkspeed" management framework -- no need to add a dedicated
4031  * IOCTL
4032  */
4033  linktopology = elxu_device_get_value(options.device, "/ocs/configured_topology");
4034  }
4035  if (linktopology == NULL) {
4036  printf("Failed to get linktopology value\n");
4037  return -1;
4038  }
4039  printf("Link topology: %s\n", linktopology);
4040  return 0;
4041 }
4042 /**
4043  * @ingroup cmd_handler
4044  * @brief Command handler for the linkcfg-set command.
4045  *
4046  * @par Description
4047  * This function processes the linkcfg-set command.
4048  *
4049  * Command: linkcfg-set <br>
4050  * Required Parameters: --linkcfg <link configuration> <br>
4051  * Optional Parameters: -d <device> <br>
4052  * Supported Devices: ALl <br>
4053  * Supported Protocols: N/A <br>
4054  *
4055  * @param argc The number of command line arguments.
4056  * @param argv An array of pointers to the command line arguments.
4057  *
4058  * @return Returns 0 on success; or a non-zero error code value on failure.
4059  */
4060 int elxu_cmd_set_linkcfg(int argc, char **argv)
4061 {
4062  cmd_options_t options;
4063  uint8_t supported = 0;
4064  int32_t rval = -1;
4065  int32_t i;
4066 
4067  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
4068  return -1;
4069  }
4070 
4071  /* check to see if this is a supported link configuration */
4072  for (i = 0; i < ARRAY_SIZE(supported_linkcfgs); i++) {
4073  if (strcmp(supported_linkcfgs[i], options.linkcfg) == 0) {
4074  supported = 1;
4075  break;
4076  }
4077  }
4078  if (!supported) {
4079  printf("Unsupported link config=%s\n", options.linkcfg);
4080  return -1;
4081  }
4082 
4083  if (options.device->driver == DEVICE_DRIVER_OCS) {
4084  /* send IOCTL to set link config; note this will use the generic
4085  * "set config" management framework -- no need to add a dedicated
4086  * IOCTL
4087  */
4088  rval = mgmt_set_value(options.device, "/ocs/linkcfg", options.linkcfg);
4089  } else if (options.device->driver == DEVICE_DRIVER_PT) {
4090  rval = mbox_set_linkcfg_pt(options.device, options.linkcfg);
4091  }
4092 
4093  if (rval) {
4094  printf("Failed to set link config, IOCTL failed status=%d\n", rval);
4095  return rval;
4096  }
4097 
4098  printf("Successfully set link config. Please reboot for changes to take effect.\n");
4099  return 0;
4100 }
4101 
4102 /**
4103  * @ingroup cmd_handler
4104  * @brief Command handler for the link-speed-set command.
4105  *
4106  * @par Description
4107  * This function processes the link-speed-set command.
4108  *
4109  * Command: linkspeed-set <br>
4110  * Required Parameters: --link-speed <link configuration> <br>
4111  * Optional Parameters: -d <device> <br>
4112  * Supported Devices: ALl <br>
4113  * Supported Protocols: N/A <br>
4114  *
4115  * @param argc The number of command line arguments.
4116  * @param argv An array of pointers to the command line arguments.
4117  *
4118  * @return Returns 0 on success; or a non-zero error code value on failure.
4119  */
4120 int elxu_cmd_set_linkspeed(int argc, char **argv)
4121 {
4122  cmd_options_t options;
4123  uint8_t supported = 0;
4124  int32_t rval = -1;
4125  int32_t i;
4126 
4127  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
4128  return -1;
4129  }
4130 
4131  /* check to see if this is a supported link speed */
4132  for (i = 0; i < ARRAY_SIZE(supported_linkspeed); i++) {
4133  if (strcmp(supported_linkspeed[i], options.linkspeed) == 0) {
4134  supported = 1;
4135  break;
4136  }
4137  }
4138  if (!supported) {
4139  printf("Unsupported link config=%s\n", options.linkspeed);
4140  return -1;
4141  }
4142 
4143  if (options.device->driver == DEVICE_DRIVER_OCS) {
4144  /* send IOCTL to set link config; note this will use the generic
4145  * "set config" management framework -- no need to add a dedicated
4146  * IOCTL
4147  */
4148  rval = mgmt_set_value(options.device, "/ocs/configured_speed", options.linkspeed);
4149  } else {
4150  printf("link speed is not supported for this driver\n");
4151  return -1;
4152  }
4153 
4154  if (rval) {
4155  printf("Failed to set link speed, IOCTL failed status=%d\n", rval);
4156  return rval;
4157  }
4158 
4159  printf("Successfully set link speed.\n");
4160  return 0;
4161 }
4162 
4163 /**
4164  * @ingroup cmd_handler
4165  * @brief Command handler for the linktopology-set command.
4166  *
4167  * @par Description
4168  * This function processes the linktopology-set command.
4169  *
4170  * Command: linktopology-set <br>
4171  * Required Parameters: --link-topology <link configuration> <br>
4172  * Optional Parameters: -d <device> <br>
4173  * Supported Devices: ALl <br>
4174  * Supported Protocols: N/A <br>
4175  *
4176  * @param argc The number of command line arguments.
4177  * @param argv An array of pointers to the command line arguments.
4178  *
4179  * @return Returns 0 on success; or a non-zero error code value on failure.
4180  */
4181 int elxu_cmd_set_linktopology(int argc, char **argv)
4182 {
4183  cmd_options_t options;
4184  uint8_t supported = 0;
4185  int32_t rval = -1;
4186  int32_t i;
4187 
4188  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
4189  return -1;
4190  }
4191 
4192  /* check to see if this is a supported link topology */
4193  for (i = 0; i < ARRAY_SIZE(supported_linktopology); i++) {
4194  if (strcmp(supported_linktopology[i], options.linktopology) == 0) {
4195 
4196  /* restrict LOOP only for g5 */
4197  if ((strcmp(options.linktopology, LOOP) == 0) &&
4198  !is_lancer_g5(options.device))
4199  break;
4200 
4201  supported = 1;
4202  break;
4203  }
4204  }
4205  if (!supported) {
4206  printf("Unsupported link topology=%s\n", options.linktopology);
4207  return -1;
4208  }
4209 
4210  if (options.device->driver == DEVICE_DRIVER_OCS) {
4211  /* send IOCTL to set link config; note this will use the generic
4212  * "set link topology" management framework -- no need to add a dedicated
4213  * IOCTL
4214  */
4215  rval = mgmt_set_value(options.device, "/ocs/configured_topology", options.linktopology);
4216  } else {
4217  printf("link topology is not supported for this driver\n");
4218  return -1;
4219  }
4220 
4221  if (rval) {
4222  printf("Failed to set link topology, IOCTL failed status=%d\n", rval);
4223  return rval;
4224  }
4225 
4226  printf("Successfully set link topology.\n");
4227  return 0;
4228 }
4229 
4230 /**
4231  * @ingroup cmd_handler
4232  * @brief Command handler for the get-profile-list command.
4233  *
4234  * @par Description
4235  * This function processes the get-profile-list command.
4236  *
4237  * Command: get-profile-list <br>
4238  * Required Parameters: None <br>
4239  * Optional Parameters: -d <device> <br>
4240  * Supported Devices: Skyhawk <br>
4241  * Supported Protocols: N/A <br>
4242  *
4243  * @param argc The number of command line arguments.
4244  * @param argv An array of pointers to the command line arguments.
4245  *
4246  * @return Returns 0 on success; or a non-zero error code value on failure.
4247  */
4248 int elxu_cmd_get_profile_list(int argc, char **argv)
4249 {
4250  cmd_options_t options;
4251  char *response;
4252  int rc;
4253 
4254  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
4255  return -1;
4256  }
4257 
4258  if (!is_skyhawk(options.device)) {
4259  fprintf(stderr, "Profiles are only supported on Skyhawk\n");
4260  return -1;
4261  }
4262 
4263  response = elxu_device_get_value(options.device, "/ocs/profile_list");
4264 
4265  if (strlen(response) == 0) {
4266  printf("Failed to get supported profile list\n");
4267  rc = -1;
4268  } else {
4269  printf("Supported profiles:\n");
4270  printf("%s\n", response);
4271  rc = 0;
4272  }
4273 
4274  return rc;
4275 }
4276 
4277 /**
4278  * @ingroup cmd_handler
4279  * @brief Command handler for the get-active-profile command.
4280  *
4281  * @par Description
4282  * This function processes the get-active-profile command.
4283  *
4284  * Command: get-active-profile <br>
4285  * Required Parameters: None <br>
4286  * Optional Parameters: -d <device> <br>
4287  * Supported Devices: Skyhawk <br>
4288  * Supported Protocols: N/A <br>
4289  *
4290  * @param argc The number of command line arguments.
4291  * @param argv An array of pointers to the command line arguments.
4292  *
4293  * @return Returns 0 on success; or a non-zero error code value on failure.
4294  */
4295 int elxu_cmd_get_active_profile(int argc, char **argv)
4296 {
4297  cmd_options_t options;
4298  char *response;
4299  int rc = -1;
4300  char profile_description[80];
4301 
4302  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
4303  goto exit_get_active_profile;
4304  }
4305 
4306  if (!is_skyhawk(options.device)) {
4307  fprintf(stderr, "Profiles are only supported on Skyhawk\n");
4308  goto exit_get_active_profile;
4309  }
4310 
4311  response = elxu_device_get_value(options.device, "/ocs/active_profile");
4312 
4313  if (strlen(response)== 0) {
4314  printf("Failed to get active profile\n");
4315  } else {
4316  int profile;
4317  profile = strtol(response, NULL, 0);
4318 
4319  /* Got the profile ID, get the list to get a description */
4320  strcpy(profile_description, "(Description not available)");
4321 
4322  response = elxu_device_get_value(options.device, "/ocs/profile_list");
4323  if (strlen(response) != 0) {
4324  char *line;
4325  char *tokptr1;
4326  char *tokptr2;
4327  char *id;
4328  char *description;
4329 
4330  /* Break the response into lines */
4331  line = strtok_r(response, "\n", &tokptr1);
4332  while (line) {
4333  /* Break the line into fields */
4334  id = strtok_r(line, ":", &tokptr2);
4335  description = strtok_r(NULL, "\n", &tokptr2);
4336  if (strtol(id, NULL, 0) == profile) {
4337  if (strlen(description) < 80) {
4338  strncpy(profile_description, description, strlen(description));
4339  rc = 0;
4340  }
4341  break;
4342  }
4343  line = strtok_r(NULL, "\n", &tokptr1);
4344  }
4345 
4346  printf("Active profile:\n");
4347  printf("0x%02x: %s\n", profile, profile_description);
4348  }
4349 
4350  }
4351 
4352 exit_get_active_profile:
4353  return rc;
4354 }
4355 
4356 /**
4357  * @ingroup cmd_handler
4358  * @brief Command handler for the set-active-profile command.
4359  *
4360  * @par Description
4361  * This function processes the set-active-profile command.
4362  *
4363  * Command: set-active-profile <br>
4364  * Required Parameters: <profile_id> <br>
4365  * Optional Parameters: -d <device> <br>
4366  * Supported Devices: Skyhawk <br>
4367  * Supported Protocols: N/A <br>
4368  *
4369  * @param argc The number of command line arguments.
4370  * @param argv An array of pointers to the command line arguments.
4371  *
4372  * @return Returns 0 on success; or a non-zero error code value on failure.
4373  */
4374 int elxu_cmd_set_active_profile(int argc, char **argv)
4375 {
4376  cmd_options_t options;
4377  char *new_profile_id;
4378  int rc;
4379 
4380  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
4381  return -1;
4382  }
4383 
4384  if (!is_skyhawk(options.device)) {
4385  fprintf(stderr, "Profiles are only supported on Skyhawk\n");
4386  return -1;
4387  }
4388 
4389  new_profile_id = options.profile_id;
4390 
4391  rc = mgmt_set_value(options.device, "/ocs/active_profile", new_profile_id);
4392 
4393  if (rc) {
4394  printf("Set active profile failed.\n");
4395  } else {
4396  printf("Active profile set to %s\n",new_profile_id);
4397  printf("New profile will be in effect after reboot\n");
4398  }
4399 
4400  return rc;
4401 }
4402 
4403 /**
4404  * @ingroup cmd_handler
4405  * @brief Command handler for the get-profile-list command for the elx_pt driver.
4406  *
4407  * @par Description
4408  * This function processes the get-profile-list command.
4409  *
4410  * Command: get-profile-list <br>
4411  * Required Parameters: None <br>
4412  * Optional Parameters: -d <device> <br>
4413  * Supported Devices: Skyhawk <br>
4414  * Supported Protocols: N/A <br>
4415  *
4416  * @param argc The number of command line arguments.
4417  * @param argv An array of pointers to the command line arguments.
4418  *
4419  * @return Returns 0 on success; or a non-zero error code value on failure.
4420  */
4421 int elxu_cmd_get_profile_list_pt(int argc, char **argv)
4422 {
4423  cmd_options_t options;
4424  int rc = -1;
4425  char result[5*1024];
4426 
4427  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
4428  return -1;
4429  }
4430 
4431  rc = mbox_get_profile_list_pt(options.device, result, sizeof(result));
4432  if (rc == 0) {
4433  printf("Supported profiles:\n");
4434  printf("%s\n", result);
4435  } else {
4436  printf("Failed to get list of supported profiles\n");
4437  }
4438 
4439  return rc;
4440 }
4441 
4442 /**
4443  * @ingroup cmd_handler
4444  * @brief Command handler for the get-active-profile command for the elx_pt driver.
4445  *
4446  * @par Description
4447  * This function processes the get-active-profile command.
4448  *
4449  * Command: get-active-profile <br>
4450  * Required Parameters: None <br>
4451  * Optional Parameters: -d <device> <br>
4452  * Supported Devices: Skyhawk <br>
4453  * Supported Protocols: N/A <br>
4454  *
4455  * @param argc The number of command line arguments.
4456  * @param argv An array of pointers to the command line arguments.
4457  *
4458  * @return Returns 0 on success; or a non-zero error code value on failure.
4459  */
4460 int elxu_cmd_get_active_profile_pt(int argc, char **argv)
4461 {
4462  cmd_options_t options;
4463  int rc = -1;
4464  char result[256];
4465 
4466  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
4467  return -1;
4468  }
4469 
4470  rc = mbox_get_active_profile_pt(options.device, result, sizeof(result));
4471  if (rc == 0) {
4472  printf("Active profile:\n");
4473  printf("%s\n", result);
4474  } else {
4475  printf("Failed to get active profile\n");
4476  }
4477 
4478  return rc;
4479 }
4480 
4481 /**
4482  * @ingroup cmd_handler
4483  * @brief Command handler for the set-active-profile command for the elx_pt driver.
4484  *
4485  * @par Description
4486  * This function processes the set-active-profile command.
4487  *
4488  * Command: set-active-profile <br>
4489  * Required Parameters: <profile_id> <br>
4490  * Optional Parameters: -d <device> <br>
4491  * Supported Devices: Skyhawk <br>
4492  * Supported Protocols: N/A <br>
4493  *
4494  * @param argc The number of command line arguments.
4495  * @param argv An array of pointers to the command line arguments.
4496  *
4497  * @return Returns 0 on success; or a non-zero error code value on failure.
4498  */
4499 int elxu_cmd_set_active_profile_pt(int argc, char **argv)
4500 {
4501  cmd_options_t options;
4502  int rc = -1;
4503  char *new_profile_id;
4504 
4505  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
4506  return -1;
4507  }
4508 
4509  new_profile_id = options.profile_id;
4510 
4511  rc = mbox_set_active_profile_pt(options.device, new_profile_id);
4512 
4513  if (rc) {
4514  printf("Set active profile failed.\n");
4515  } else {
4516  printf("Active profile set to %s\n",new_profile_id);
4517  printf("New profile will be in effect after reboot\n");
4518  }
4519 
4520  return rc;
4521 }
4522 
4523 /**
4524  * @ingroup cmd_handler
4525  * @brief Command handler for the get-port-protocol command.
4526  *
4527  * @par Description
4528  * This function processes the get-port-protocol command.
4529  *
4530  * Command: get-port-protocol <br>
4531  * Required Parameters: None <br>
4532  * Optional Parameters: -d <device> <br>
4533  * Supported Devices: Skyhawk <br>
4534  * Supported Protocols: N/A <br>
4535  *
4536  * @param argc The number of command line arguments.
4537  * @param argv An array of pointers to the command line arguments.
4538  *
4539  * @return Returns 0 on success; or a non-zero error code value on failure.
4540  */
4541 int elxu_cmd_get_port_protocol(int argc, char **argv)
4542 {
4543  cmd_options_t options;
4544  char *response;
4545  int rc;
4546 
4547  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
4548  return -1;
4549  }
4550 
4551  if (!is_skyhawk(options.device)) {
4552  fprintf(stderr, "Port protocols are only supported on Skyhawk\n");
4553  return -1;
4554  }
4555 
4556  response = elxu_device_get_value(options.device, "/ocs/port_protocol");
4557 
4558  if (strlen(response)== 0) {
4559  printf("Failed to get port protocol\n");
4560  rc = -1;
4561  } else {
4562  printf("Port protocol:\n");
4563  printf("%s\n", response);
4564  rc = 0;
4565  }
4566 
4567  return rc;
4568 }
4569 
4570 /**
4571  * @ingroup cmd_handler
4572  * @brief Command handler for the set-port-protocol command.
4573  *
4574  * @par Description
4575  * This function processes the set-port-protocol command.
4576  *
4577  * Command: set-port-protocol <br>
4578  * Required Parameters: --protocol <protocol_name> <br>
4579  * Optional Parameters: -d <device> <br>
4580  * Supported Devices: Skyhawk <br>
4581  * Supported Protocols: N/A <br>
4582  *
4583  * @param argc The number of command line arguments.
4584  * @param argv An array of pointers to the command line arguments.
4585  *
4586  * @return Returns 0 on success; or a non-zero error code value on failure.
4587  */
4588 int elxu_cmd_set_port_protocol(int argc, char **argv)
4589 {
4590  cmd_options_t options;
4591  char *new_protocol_name;
4592  int rc;
4593 
4594  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
4595  return -1;
4596  }
4597 
4598  if (!is_skyhawk(options.device)) {
4599  fprintf(stderr, "Port protocols are only supported on Skyhawk\n");
4600  return -1;
4601  }
4602 
4603  new_protocol_name = options.protocol_name;
4604 
4605  rc = mgmt_set_value(options.device, "/ocs/port_protocol", new_protocol_name);
4606 
4607  if (rc) {
4608  printf("Set port protocol failed.\n");
4609  } else {
4610  printf("Port protocol set\n");
4611  }
4612 
4613  return rc;
4614 }
4615 
4616 /**
4617  * @ingroup cmd_handler
4618  * @brief Command handler for the firmware-reset command.
4619  *
4620  * @par Description
4621  * This function processes the firmware-reset command.
4622  *
4623  * Command: firmware-reset <br>
4624  * Required Parameters: none <br>
4625  * Optional Parameters: -d <device> <br>
4626  * Supported Devices: All <br>
4627  * Supported Protocols: N/A <br>
4628  *
4629  * @param argc The number of command line arguments.
4630  * @param argv An array of pointers to the command line arguments.
4631  *
4632  * @return Returns 0 on success; or a non-zero error code value on failure.
4633  */
4634 int elxu_cmd_firmware_reset(int argc, char **argv)
4635 {
4636  int rval;
4637  cmd_options_t options;
4638 
4639  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
4640  return -1;
4641  }
4642 
4643  rval = elxu_device_exec(options.device, "/ocs/firmware_reset", NULL, 0, NULL, 0);
4644 
4645  if (rval == 0) {
4646  printf("Firmware reset successful, driver must now be reloaded\n");
4647  } else {
4648  perror("ioctl");
4649  }
4650 
4651  return rval;
4652 }
4653 
4654 /**
4655  * @ingroup cmd_handler
4656  * @brief Command handler for the elxu_cmd_get_fdmi_hba_list command.
4657  *
4658  * @par Description
4659  * This function processes the elxu_cmd_get_fdmi_hba_list command.
4660  *
4661  * Command: elxu_cmd_get_fdmi_hba_list <br>
4662  * Required Parameters: none <br>
4663  * Optional Parameters: -d <device> <br>
4664  * Supported Devices: All <br>
4665  * Supported Protocols: N/A <br>
4666  *
4667  * @param argc The number of command line arguments.
4668  * @param argv An array of pointers to the command line arguments.
4669  *
4670  * @return Returns 0 on success; or a non-zero error code value on failure.
4671  */
4672 int elxu_cmd_get_fdmi_hba_list(int argc, char **argv)
4673 {
4674  int rval;
4675  cmd_options_t options;
4676  ocs_fdmi_hba_list_info_t *hba_list_info = NULL;
4677 
4678  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
4679  rval = -1;
4680  goto done;
4681  }
4682 
4683  hba_list_info = malloc(sizeof(*hba_list_info));
4684  if (hba_list_info == NULL) {
4685  perror("malloc");
4686  rval = -1;
4687  goto done;
4688  }
4689 
4690  rval = elxu_device_exec(options.device, "/ocs/domain[0]/sport[0]/get_fdmi_hba_list",
4691  NULL, 0, hba_list_info, sizeof(*hba_list_info));
4692  if (rval == 0) {
4693  uint32_t i;
4694 
4695  printf("FDMI HBA list:\n");
4696  printf(" Number of HBA entries: %d\n", hba_list_info->entry_count);
4697 
4698  for (i = 0; i < hba_list_info->entry_count; i++)
4699  printf(" 0x%lx\n", hba_list_info->hba_identifier[i]);
4700 
4701  printf("\n");
4702 
4703  } else {
4704  perror("ioctl");
4705  }
4706 
4707 done:
4708  if (hba_list_info)
4709  free(hba_list_info);
4710 
4711  return rval;
4712 }
4713 
4714 /**
4715  * @ingroup cmd_handler
4716  * @brief Command handler for the elxu_cmd_get_fdmi_port_list command.
4717  *
4718  * @par Description
4719  * This function processes the elxu_cmd_get_fdmi_port_list command.
4720  *
4721  * Command: elxu_cmd_get_fdmi_port_list <br>
4722  * Required Parameters: none <br>
4723  * Optional Parameters: -d <device> <br>
4724  * Supported Devices: All <br>
4725  * Supported Protocols: N/A <br>
4726  *
4727  * @param argc The number of command line arguments.
4728  * @param argv An array of pointers to the command line arguments.
4729  *
4730  * @return Returns 0 on success; or a non-zero error code value on failure.
4731  */
4732 int elxu_cmd_get_fdmi_port_list(int argc, char **argv)
4733 {
4734  int rval = 0;
4735  cmd_options_t options;
4736  ocs_fdmi_port_list_info_t *port_list_info = NULL;
4737  char hba_id[128] = {0,};
4738  uint32_t hba_id_len;
4739 
4740  if (argc < 3) {
4741  //Too few arguments
4742  fprintf(stderr, "HBA identifier is required\n");
4743  goto done;
4744  }
4745 
4746  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
4747  rval = -1;
4748  goto done;
4749  }
4750 
4751  if (options.hba_identifier == NULL) {
4752  rval = -1;
4753  printf("Please provide valid HBA identifier as input\n");
4754  goto done;
4755  }
4756 
4757  port_list_info = malloc(sizeof(*port_list_info));
4758  if (port_list_info == NULL) {
4759  perror("malloc");
4760  rval = -1;
4761  goto done;
4762  }
4763 
4764 
4765  hba_id_len = snprintf(hba_id, sizeof(hba_id), "%s", options.hba_identifier);
4766  rval = elxu_device_exec(options.device, "/ocs/domain[0]/sport[0]/get_fdmi_port_list",
4767  hba_id, hba_id_len, port_list_info, sizeof(*port_list_info));
4768  if (rval == 0) {
4769  uint32_t i;
4770 
4771  printf("FDMI Port list:\n");
4772  printf(" Number of Port entries: %d\n", port_list_info->entry_count);
4773 
4774  for (i = 0; i < port_list_info->entry_count; i++)
4775  printf(" 0x%lx\n", port_list_info->port_identifier[i]);
4776 
4777  printf("\n");
4778 
4779  } else {
4780  perror("ioctl");
4781  }
4782 
4783 done:
4784  if (port_list_info)
4785  free(port_list_info);
4786 
4787  return rval;
4788 }
4789 
4790 /**
4791  * @ingroup cmd_handler
4792  * @brief Command handler for the elxu_cmd_get_fdmi_hba_info command.
4793  *
4794  * @par Description
4795  * This function processes the elxu_cmd_get_fdmi_hba_info command.
4796  *
4797  * Command: elxu_cmd_get_fdmi_hba_list <br>
4798  * Required Parameters: none <br>
4799  * Optional Parameters: -d <device> <br>
4800  * Supported Devices: All <br>
4801  * Supported Protocols: N/A <br>
4802  *
4803  * @param argc The number of command line arguments.
4804  * @param argv An array of pointers to the command line arguments.
4805  *
4806  * @return Returns 0 on success; or a non-zero error code value on failure.
4807  */
4808 int elxu_cmd_get_fdmi_hba_info(int argc, char **argv)
4809 {
4810  int rval = -1;
4811  cmd_options_t options;
4812  ocs_fdmi_hba_attr_info_t *hba_info = NULL;
4813  char hba_id[128] = {0,};
4814  uint32_t hba_id_len;
4815 
4816  if (argc < 3) {
4817  //Too few arguments
4818  fprintf(stderr, "HBA identifier is required\n");
4819  goto done;
4820  }
4821 
4822  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
4823  rval = -1;
4824  goto done;
4825  }
4826 
4827  if (options.hba_identifier == NULL) {
4828  rval = -1;
4829  printf("Please provide valid HBA identifier as input\n");
4830  goto done;
4831  }
4832 
4833  hba_info = malloc(sizeof(*hba_info));
4834  if (hba_info == NULL) {
4835  perror("malloc");
4836  rval = -1;
4837  goto done;
4838  }
4839 
4840 
4841  hba_id_len = snprintf(hba_id, sizeof(hba_id), "%s", options.hba_identifier);
4842  rval = elxu_device_exec(options.device, "/ocs/domain[0]/sport[0]/get_fdmi_hba_info",
4843  hba_id, hba_id_len, hba_info, sizeof(*hba_info));
4844  if (rval == 0) {
4845  uint32_t i;
4846 
4847  printf("FDMI HBA info:\n");
4848  printf(" Number of Port entries: %d\n", hba_info->num_port_entries);
4849 
4850  for (i = 0; i < hba_info->num_port_entries; i++)
4851  printf(" 0x%lx\n", hba_info->port_identifier[i]);
4852 
4853  if (hba_info->node_name_valid)
4854  printf(" Node name: 0x%lx\n", hba_info->node_name);
4855 
4856  if (hba_info->manufacturer_valid)
4857  printf(" Manufacturer name: %s\n", hba_info->manufacturer);
4858 
4859  if (hba_info->serial_num_valid)
4860  printf(" Serial Number: %s\n", hba_info->serial_num);
4861 
4862  if (hba_info->model_name_valid)
4863  printf(" Model name: %s\n", hba_info->model_name);
4864 
4865  if (hba_info->model_desc_valid)
4866  printf(" Model Description: %s\n", hba_info->model_desc);
4867 
4868  if (hba_info->hw_ver_valid)
4869  printf(" Hardware Version: %s\n", hba_info->hw_ver);
4870 
4871  if (hba_info->driver_ver_valid)
4872  printf(" Driver Version: %s\n", hba_info->driver_ver);
4873 
4874  if (hba_info->opt_rom_ver_valid)
4875  printf(" Optional ROM Version: %s\n", hba_info->opt_rom_ver);
4876 
4877  if (hba_info->fw_ver_valid)
4878  printf(" Firmware Version: %s\n", hba_info->fw_ver);
4879 
4880  if (hba_info->os_name_ver_valid)
4881  printf(" OS Name and Version: %s\n", hba_info->os_name_ver);
4882 
4883  if (hba_info->max_ct_payload_valid)
4884  printf(" MAX CT Payload length: %d\n", hba_info->max_ct_payload_len);
4885 
4886  if (hba_info->node_symb_name_valid)
4887  printf(" Node Symbolic Name: %s\n", hba_info->node_symb_name);
4888 
4889  if (hba_info->vendor_info_valid)
4890  printf(" Vendor Info: 0x%x\n", hba_info->vendor_info);
4891 
4892  if (hba_info->num_ports_valid)
4893  printf(" No of Ports: %d\n", hba_info->num_ports);
4894 
4895  if (hba_info->fabric_name_valid)
4896  printf(" Fabric Name: 0x%lx\n", hba_info->fabric_name);
4897 
4898  if (hba_info->bios_ver_valid)
4899  printf(" BIOS version: %s\n", hba_info->bios_ver);
4900 
4901  if (hba_info->boot_state_valid)
4902  printf(" BOOT state: %d\n", hba_info->boot_state);
4903 
4904  if (hba_info->vendor_id_valid)
4905  printf(" Vendor ID: %s\n", hba_info->vendor_id);
4906  } else {
4907  perror("ioctl");
4908  }
4909 
4910 done:
4911  if (hba_info)
4912  free(hba_info);
4913 
4914  return rval;
4915 }
4916 
4917 void elxu_decode_port_speed(uint32_t port_speed, char *buf)
4918 {
4919  char port_speed_str[256] = {0,};
4920 
4921  if (port_speed & PORTSPEED_1GFC) {
4922  strcat(port_speed_str, "1 ");
4923  }
4924  if (port_speed & PORTSPEED_2GFC) {
4925  strcat(port_speed_str, "2 ");
4926  }
4927  if (port_speed & PORTSPEED_4GFC) {
4928  strcat(port_speed_str, "4 ");
4929  }
4930  if (port_speed & PORTSPEED_8GFC) {
4931  strcat(port_speed_str, "8 ");
4932  }
4933  if (port_speed & PORTSPEED_16GFC) {
4934  strcat(port_speed_str, "16 ");
4935  }
4936  if (port_speed & PORTSPEED_32GFC) {
4937  strcat(port_speed_str, "32 ");
4938  }
4939  if (port_speed & PORTSPEED_64GFC) {
4940  strcat(port_speed_str, "64 ");
4941  }
4942  if (port_speed & PORTSPEED_128GFC) {
4943  strcat(port_speed_str, "128 ");
4944  }
4945  strcat(port_speed_str, "Gb/s");
4946  strncpy(buf, port_speed_str, 256);
4947 
4948  return;
4949 }
4950 
4951 /**
4952  * @ingroup cmd_handler
4953  * @brief Command handler for the elxu_cmd_get_fdmi_port_info command.
4954  *
4955  * @par Description
4956  * This function processes the elxu_cmd_get_fdmi_port_info command.
4957  *
4958  * Command: elxu_cmd_get_fdmi_port_info <br>
4959  * Required Parameters: none <br>
4960  * Optional Parameters: -d <device> <br>
4961  * Supported Devices: All <br>
4962  * Supported Protocols: N/A <br>
4963  *
4964  * @param argc The number of command line arguments.
4965  * @param argv An array of pointers to the command line arguments.
4966  *
4967  * @return Returns 0 on success; or a non-zero error code value on failure.
4968  */
4969 int elxu_cmd_get_fdmi_port_info(int argc, char **argv)
4970 {
4971  int rval;
4972  cmd_options_t options;
4973  ocs_fdmi_port_attr_info_t *port_info = NULL;
4974  char port_id[128] = {0,};
4975  uint32_t port_id_len;
4976 
4977  if (argc < 3) {
4978  //Too few arguments
4979  fprintf(stderr, "Port identifier is required\n");
4980  goto done;
4981  }
4982 
4983  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
4984  rval = -1;
4985  goto done;
4986  }
4987 
4988  if (options.port_identifier == NULL) {
4989  rval = -1;
4990  printf("Please provide valid port identifier as input\n");
4991  goto done;
4992  }
4993 
4994  port_info = malloc(sizeof(*port_info));
4995  if (port_info == NULL) {
4996  perror("malloc");
4997  rval = -1;
4998  goto done;
4999  }
5000 
5001 
5002  port_id_len = snprintf(port_id, sizeof(port_id), "%s", options.port_identifier);
5003  rval = elxu_device_exec(options.device, "/ocs/domain[0]/sport[0]/get_fdmi_port_info",
5004  port_id, port_id_len, port_info, sizeof(*port_info));
5005  if (rval == 0) {
5006  printf("FDMI Port info:\n");
5007  printf(" Number of Port attributes: %d\n", port_info->num_port_attr_entries);
5008 
5009  if (port_info->supported_fc_types_valid) {
5010  int byte = 0;
5011 
5012  printf(" Supported FC-4 types: ");
5013  for (byte = 0; byte < sizeof(port_info->supported_fc4_types); byte++)
5014  printf("0x%x ", port_info->supported_fc4_types[byte]);
5015  printf("\n");
5016 
5017  }
5018  if (port_info->supported_speed_valid) {
5019  char port_speed_str[256] = {0,};
5020 
5021  elxu_decode_port_speed(port_info->supported_speed, port_speed_str);
5022  printf(" Supported speed: %s\n", port_speed_str);
5023  }
5024 
5025  if (port_info->current_speed_valid) {
5026  char port_speed_str[256] = {0,};
5027 
5028  elxu_decode_port_speed(port_info->current_port_speed, port_speed_str);
5029  printf(" Port Current speed: %s\n", port_speed_str);
5030  }
5031 
5032  if (port_info->max_frame_size_valid)
5033  printf(" Maximum frame size: 0x%x\n", port_info->max_frame_size);
5034 
5035  if (port_info->os_dev_name_valid)
5036  printf(" OS Device Name: %s\n", port_info->os_dev_name);
5037 
5038  if (port_info->host_name_valid)
5039  printf(" Host Name: %s\n", port_info->host_name);
5040 
5041  if (port_info->node_name_valid)
5042  printf(" Node Name: 0x%lx\n", port_info->node_name);
5043 
5044  if (port_info->port_name_valid)
5045  printf(" Port Name: 0x%lx\n", port_info->port_name);
5046 
5047  if (port_info->port_symb_name_valid)
5048  printf(" Port symbolic name: %s\n", port_info->port_symb_name);
5049 
5050  if (port_info->port_type_valid) {
5051  printf(" Port type: ");
5052  switch (port_info->port_type) {
5053  case 0x1:
5054  printf("N_Port\n");
5055  break;
5056  case 0x2:
5057  printf("NL_Port\n");
5058  break;
5059  case 0x3:
5060  printf("F/NL_Port\n");
5061  break;
5062  case 0x81:
5063  printf("F_Port\n");
5064  break;
5065  case 0x82:
5066  printf("FL_Port\n");
5067  break;
5068  default:
5069  printf("Undefined\n");
5070  }
5071  }
5072  if (port_info->supported_cos_valid) {
5073  printf(" Supported Class of service: %d\n",
5074  port_info->supported_class_of_service);
5075  }
5076 
5077  if (port_info->port_fabric_name_valid)
5078  printf(" Port fabric name: 0x%lx\n", port_info->port_fabric_name);
5079 
5080  if (port_info->port_state_valid)
5081  printf(" Port state: %d\n", port_info->port_state);
5082 
5083  if (port_info->num_disc_ports_valid)
5084  printf(" Number of Discovered Ports: %d\n", port_info->num_disc_ports);
5085 
5086  if (port_info->port_id_valid)
5087  printf(" Port identifier: 0x%x\n", port_info->port_identifier);
5088 
5089  if (port_info->active_fc_types_valid) {
5090  int byte = 0;
5091 
5092  printf(" Active FC-4 types: ");
5093  for (byte = 0; byte < sizeof(port_info->active_fc4_types); byte++)
5094  printf("0x%x ", port_info->active_fc4_types[byte]);
5095  printf("\n");
5096  }
5097  } else {
5098  perror("ioctl");
5099  }
5100 
5101 done:
5102  if (port_info)
5103  free(port_info);
5104 
5105  return 0;
5106 }
5107 
5108 
5109 /**
5110  * @ingroup cmd_handler
5111  * @brief Command handler for elxu_cmd_set_trunk_mode command.
5112  *
5113  * @par Description
5114  * This function processes the elxu_cmd_set_trunk_mode command.
5115  *
5116  * Command: elxu_cmd_set_trunk_mode <br>
5117  * Required Parameters: -d <device> --mode <trunk mode> <br>
5118  * Optional Parameters: None <br>
5119  * Supported Devices: Prism <br>
5120  * Supported Protocols: FC <br>
5121  *
5122  * @param argc The number of command line arguments.
5123  * @param argv An array of pointers to the command line arguments.
5124  *
5125  * @return Returns 0 on success; or a non-zero error code value on failure.
5126  */
5127 int elxu_cmd_set_trunk_mode(int argc, char **argv)
5128 {
5129  cmd_options_t options;
5130  int rc;
5131 
5132  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
5133  return -1;
5134  }
5135 
5136  if(!is_prism(options.device)) {
5137  fprintf(stderr, "Trunking is only supported on Prism adapters.\n");
5138  return -1;
5139  }
5140 
5141  rc = elxu_device_exec(options.device, "/ocs/driver/trunk_mode", &options.trunk_mode, sizeof(options.trunk_mode), NULL, 0);
5142  if (rc < 0) {
5143  printf("Set trunk mode failed, rc %d.\n", rc);
5144  } else {
5145  printf("Device configured to (%d) trunk mode. Host reboot is required for new trunk mode to take effect.\n", options.trunk_mode);
5146  }
5147 
5148  return rc;
5149 }
5150 
5151 static void
5152 ocs_fc_report_trunk_links(uint8_t ports_active, char *active_ports_str, size_t max_str_len)
5153 {
5154  char tmp[8];
5155  char *ptr = active_ports_str;
5156  int i;
5157 
5158  memset(active_ports_str, 0x0, max_str_len);
5159  for (i = 0; i < OCS_MAX_SLI_PORTS_PER_DEVICE; i++) {
5160  if (!(ports_active & (1 << i)))
5161  continue;
5162  if (!strlen(active_ports_str)) {
5163  snprintf(tmp, sizeof(tmp), "%d", i);
5164  } else {
5165  snprintf(tmp, sizeof(tmp), ",%d", i);
5166  }
5167  if (strlen(active_ports_str) + strlen(tmp) > max_str_len)
5168  break;
5169  strcpy(ptr, tmp);
5170  ptr += strlen(tmp);
5171  }
5172 
5173  if (!strlen(active_ports_str)) {
5174  strcpy(active_ports_str, "None");
5175  }
5176 }
5177 
5178 
5179 /**
5180  * @ingroup cmd_handler
5181  * @brief Command handler for elxu_cmd_get_trunk_config command.
5182  *
5183  * @par Description
5184  * This function processes the elxu_cmd_get_trunk_config command.
5185  *
5186  * Command: elxu_cmd_get_trunk_config <br>
5187  * Required Parameters: -d <device> <br>
5188  * Optional Parameters: None <br>
5189  * Supported Devices: Prism <br>
5190  * Supported Protocols: FC <br>
5191  *
5192  * @param argc The number of command line arguments.
5193  * @param argv An array of pointers to the command line arguments.
5194  *
5195  * @return Returns 0 on success; or a non-zero error code value on failure.
5196  */
5197 int elxu_cmd_get_trunk_config(int argc, char **argv)
5198 {
5199  cmd_options_t options;
5200  uint32_t trunk_info;
5201  char *logical_link_speed;
5202  char active_ports_str[16];
5203  int rc;
5204 
5205  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
5206  return -1;
5207  }
5208 
5209  if(!is_prism(options.device)) {
5210  fprintf(stderr, "Trunking is only supported on Prism adapters.\n");
5211  return -1;
5212  }
5213 
5214  rc = elxu_device_exec(options.device, "/ocs/driver/trunk_info",
5215  NULL, 0, &trunk_info, sizeof(trunk_info));
5216  if (rc < 0) {
5217  printf("Get trunk mode failed, rc %d.\n", rc);
5218  return rc;
5219  }
5220 
5222  active_ports_str, sizeof(active_ports_str));
5223  switch (trunk_info & OCS_FC_TRUNK_CONFIG_MASK) {
5224  case 0:
5225  printf("SLI port is a single physical FC link\n");
5226  break;
5228  /* 2 links per trunk config, trunk incorporates either,
5229  * 1) port 0/1 of a 4-port device
5230  * 2) Both ports of a 2-port device
5231  */
5232  printf("FC Trunk Configuration:\n\tLinks=2\n\tMember ports={ 0,1 }\n\tActive ports={ %s }\n", active_ports_str);
5233  break;
5235  /* 2 links per trunk config that incorporates port 2/3 of a 4-port device. */
5236  printf("FC Trunk Configuration:\n\tLinks=2\n\tMember ports={ 2,3 }\n\tActive ports={ %s }\n", active_ports_str);
5237  break;
5239  /* 4 links per trunk config that incorporates all ports of a 4-port device. */
5240  printf("FC Trunk Configuration:\n\tLinks=4\n\tMember ports={ 0,1,2,3 }\n\tActive ports={ %s }\n", active_ports_str);
5241  break;
5242  default:
5243  printf("Invalid FC link topology\n");
5244  }
5245 
5246  logical_link_speed = elxu_device_get_value(options.device, "/ocs/logical_link_speed");
5247  if (strlen(logical_link_speed) == 0) {
5248  printf("Failed to get logical link speed from device %d\n",
5249  options.device->deviceIndex);
5250  return -1;
5251  }
5252  printf("\n Logical Link Speed: %ld Gbps\n", strtoul(logical_link_speed, NULL, 0)/1000);
5253  return 0;
5254 }
5255 
5256 /**
5257  * @ingroup cmd_handler
5258  * @brief Command handler for the port-migration command.
5259  *
5260  * @par Description
5261  * This function processes the port-migration command.
5262  *
5263  * Command: port-migration <br>
5264  * Required Parameters: none <br>
5265  * Optional Parameters: -d <device> <br>
5266  * Supported Devices: All <br>
5267  * Supported Protocols: N/A <br>
5268  *
5269  * @param argc The number of command line arguments.
5270  * @param argv An array of pointers to the command line arguments.
5271  *
5272  * @return Returns 0 on success; or a non-zero error code value on failure.
5273  */
5274 int elxu_cmd_port_migration(int argc, char **argv)
5275 {
5276  int rval;
5277  cmd_options_t options;
5278 
5279  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
5280  return -1;
5281  }
5282 
5283  rval = elxu_device_exec(options.device, "/ocs/port_migration", NULL, 0, NULL, 0);
5284 
5285  if (rval == 0) {
5286  printf("Port migration operation is successed\n");
5287  } else {
5288  perror("ioctl");
5289  }
5290 
5291  return rval;
5292 }
5293 
5294 /**
5295  * @ingroup cmd_handler
5296  * @brief Command handler for the get-parity-stats command.
5297  *
5298  * @par Description
5299  * This function processes the get-parity-stats command.
5300  *
5301  * Command: get-parity-stats <br>
5302  * Required Parameters: none <br>
5303  * Optional Parameters: -d <device> --cc <br>
5304  * Supported Devices: All <br>
5305  * Supported Protocols: N/A <br>
5306  *
5307  * @param argc The number of command line arguments.
5308  * @param argv An array of pointers to the command line arguments.
5309  *
5310  * @return Returns 0 on success; or a non-zero error code value on failure.
5311  */
5312 int elxu_cmd_get_parity_stats(int argc, char **argv)
5313 {
5314  int i, rval;
5315  cmd_options_t options;
5316  int arg_in_len, arg_out_len;
5317  char *arg_in = NULL;
5318  void *arg_out = NULL;
5319  ocs_parity_err_count_t *counter = NULL;
5320 
5321  rval = parse_arguments(argc, argv, &options, 1, 1);
5322  if (rval)
5323  return -1;
5324 
5325  if (options.cc) {
5326  /* Clear the stats */
5327  arg_in = "clear";
5328  arg_in_len = strlen("clear") + 1;
5329  }
5330 
5331  arg_out_len = (OCS_MAX_SLI4_ULP * sizeof(ocs_parity_err_count_t));
5332  arg_out = (void *)malloc(arg_out_len);
5333  if (!arg_out)
5334  return -1;
5335 
5336  memset(arg_out, 0, arg_out_len);
5337  rval = elxu_device_exec(options.device, "/ocs/get_parity_stats", arg_in, arg_in_len, arg_out, arg_out_len);
5338  if (rval) {
5339  perror("ioctl");
5340  } else {
5341  counter = (ocs_parity_err_count_t *)arg_out;
5342  printf("ITCM Parity Stats:\n");
5343  printf("==================\n");
5344  for (i = 0; i < OCS_MAX_SLI4_ULP; i++) {
5345  printf("parity_bit_error_count[%d] = %d, total_parity_error_count[%d] = %d\n",
5346  i, counter[i].pbec, i, counter[i].tpec);
5347  }
5348  }
5349 
5350  free(arg_out);
5351  return rval;
5352 }
5353 
5354 /**
5355  * @ingroup cmd_handler
5356  * @brief Send a firmware reset via the elx_pt driver
5357  *
5358  * @par Description
5359  * This function sends a firmware reset via the elx_pt driver.
5360  *
5361  * Command: firmware-reset <br>
5362  * Required Parameters: none <br>
5363  * Optional Parameters: -d <device> <br>
5364  * Supported Devices: All <br>
5365  * Supported Protocols: N/A <br>
5366  *
5367  * @param argc The number of command line arguments.
5368  * @param argv An array of pointers to the command line arguments.
5369  *
5370  * @return Returns 0 on success; or a non-zero error code value on failure.
5371  */
5372 int elxu_cmd_firmware_reset_pt(int argc, char **argv)
5373 {
5374  cmd_options_t options;
5375 
5376  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
5377  return -1;
5378  }
5379 
5380  if (mbox_fw_reset_pt(options.device, 0)) {
5381  printf("Firmware reset failed\n");
5382  return -1;
5383  }
5384 
5385  printf("Firmware reset successful, driver must now be reloaded\n");
5386  return 0;
5387 }
5388 
5389 /**
5390  * @ingroup cmd_handler
5391  * @brief Command handler for user space driver unload
5392  *
5393  * @par Description
5394  * This function processes the unload command.
5395  *
5396  * Command: unload <br>
5397  * Required Parameters: none <br>
5398  * Optional Parameters: -d <device> <br>
5399  * Supported Devices: All <br>
5400  * Supported Protocols: N/A <br>
5401  *
5402  * @param argc The number of command line arguments.
5403  * @param argv An array of pointers to the command line arguments.
5404  *
5405  * @return Returns 0 on success; or a non-zero error code value on failure.
5406  */
5407 int elxu_cmd_unload(int argc, char **argv)
5408 {
5409  int rval;
5410  cmd_options_t options;
5411 
5412  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
5413  return -1;
5414  }
5415 
5416  if (!is_uspace(options.device)) {
5417  fprintf(stderr, "Unload command is only supported on user space drivers\n");
5418  return -1;
5419  }
5420  rval = elxu_ioctl_device(options.device, OCS_IOCTL_CMD_UNLOAD, NULL);
5421  if (rval) {
5422  fprintf(stderr, "elxu_iocl_device CMD_UNLOAD failed: %d\n", rval);
5423  }
5424 
5425  return rval;
5426 }
5427 
5428 /**
5429  * @ingroup cmd_handler
5430  * @brief Command handler for the node-abort-cnt command.
5431  *
5432  * @par Description
5433  * This function processes the node-abort-cnt command.
5434  *
5435  * Command: get-node-abort-cnt <br>
5436  * Required Parameters: None <br>
5437  * Optional Parameters: -d <device> <br>
5438  * Supported Devices: All <br>
5439  * Supported Protocols: FC and FCoE <br>
5440  *
5441  * @param argc The number of command line arguments.
5442  * @param argv An array of pointers to the command line arguments.
5443  *
5444  * @return Returns 0 on success; or a non-zero error code value on failure.
5445  */
5446 int elxu_cmd_node_abort_cnt(int argc, char **argv)
5447 {
5448  cmd_options_t options;
5449  char *value;
5450 
5451  if (parse_arguments(argc, argv, &options, 1, 1) == -1) {
5452  return -1;
5453  }
5454 
5455  if (!is_fc(options.device) && !is_fcoe(options.device)) {
5456  fprintf(stderr, "Node aborts are applicable only on FC or FCoE\n");
5457  return -1;
5458  }
5459 
5460  value = elxu_device_get_value(options.device, "/ocs/node_abort_cnt");
5461  if (strlen(value) == 0) {
5462  printf("Failed to get sum of nodes abort count from device %d\n",
5463  options.device->deviceIndex);
5464  return -1;
5465  }
5466 
5467  printf("Sum of all nodes abort_cnt = %s\n", value);
5468 
5469  return 0;
5470 }
5471 
5472 /**
5473  * @ingroup cmd_handler
5474  * @brief Command handler for the help command.
5475  *
5476  * @par Description
5477  * This function processes the help command.
5478  *
5479  * Command: help <br>
5480  * Required Parameters: None <br>
5481  * Optional Parameters: <command> <br>
5482  * Supported Devices: N/A <br>
5483  * Supported Protocols: N/A <br>
5484  *
5485  * @param argc The number of command line arguments.
5486  * @param argv An array of pointers to the command line arguments.
5487  *
5488  * @return Returns 0 on success; or a non-zero error code value on failure.
5489  */
5490 int elxu_cmd_help(int argc, char **argv)
5491 {
5492  int i;
5493 
5494  if (argc > 2) {
5495  if (strcmp(argv[2], "examples") == 0) {
5496  show_examples();
5497  return 0;
5498  }
5499  for (i=0; i<ARRAY_SIZE(cmd_table); i++) {
5500  if (strcmp(argv[2],cmd_table[i].name) == 0) {
5501  printf("Command: %s\n", cmd_table[i].syntax);
5502  printf("Usage: %s\n", cmd_table[i].help_text);
5503  /*
5504  * Check for per-driver command support. Currently there
5505  * are only three cases we care about: OCS only, elx_pt
5506  * only, or both.
5507  */
5508  if (cmd_table[i].ocs_handler == NULL) {
5509  if (cmd_table[i].pt_handler != NULL) {
5510  printf("This command is supported only with the elx_pt driver.\n");
5511  }
5512  } else {
5513  if (cmd_table[i].pt_handler == NULL) {
5514  printf("This command is not supported with the elx_pt driver.\n");
5515  }
5516  }
5517  return 0;
5518  }
5519  }
5520  }
5521 
5522  printf("Type 'elxsdkutil help <command>' for help on a specific command.\n");
5523  printf("Type 'elxsdkutil help examples' for usage examples.\n\n");
5524 
5525  printf("Available commands:\n");
5526  for (i=0; i<ARRAY_SIZE(cmd_table); i++) {
5527  printf(" %s", cmd_table[i].name);
5528  if ((cmd_table[i].pt_handler == NULL) && (cmd_table[i].ocs_handler != NULL)) {
5529  /* OCS driver only */
5530  printf(" (1)\n");
5531  } else if ((cmd_table[i].pt_handler != NULL) && (cmd_table[i].ocs_handler == NULL)) {
5532  /* elx_pt only */
5533  printf(" (2)\n");
5534  } else {
5535  printf("\n");
5536  }
5537  }
5538  printf(" (1) indicates a command supported by the OneCoreStorage drivers but not the elx_pt driver.\n");
5539  printf(" (2) indicates a command supported by the elx_pt driver but not the OneCoreStorage drivers.\n");
5540 
5541  return 0;
5542 }
5543 
5544 /**
5545  * @brief Show program usage.
5546  *
5547  * @par Description
5548  * Displays program help text.
5549  */
5550 void usage()
5551 {
5552  elxu_cmd_help(0, NULL);
5553 }
5554 
5555 /**
5556  * @brief Parse command line arguments.
5557  *
5558  * @par Description
5559  * Given the argc and argv parameters from the main program,
5560  * function parses the command line arguments and stores the results
5561  * in the cmd_options_t structure.
5562  *
5563  *
5564  * @param argc Count of arguments.
5565  * @param argv Array of pointers to argument strings.
5566  * @param options Pointer to array into which the results will be stored.
5567  * @param openflag If TRUE the device specified by the options should be opened.
5568  * @param expected_nonargs Expected number of extra arguments.
5569  *
5570  * @return Returns 0 on success; non-zero on failure.
5571  */
5572 int parse_arguments(int argc, char**argv, cmd_options_t *options, int openflag, int expected_nonargs)
5573 {
5574  int ch;
5575  elxu_device_name_t devname = {0, NULL};
5576 
5577  static struct option opts[] = {
5578  /* Options */
5579  {"device", required_argument, NULL, 'd'},
5580  {"path", required_argument, NULL, 'p'},
5581  {"host", required_argument, NULL, CMD_HOSTNAME},
5582  {"file", required_argument, NULL, 'f'},
5583  {"cc", no_argument, NULL, CLEAR_COUNTER},
5584  {"clof", no_argument, NULL, CLEAR_OVERFLOW_FLAG},
5585  {"clrc", no_argument, NULL, CLEAR_ALL_COUNTER},
5586  {"wwnn", required_argument, NULL, WWNN},
5587  {"wwpn", required_argument, NULL, WWPN},
5588  {"initiator", no_argument, NULL, INITIATOR},
5589  {"target", no_argument, NULL, TARGET},
5590  {"fat", no_argument, NULL, FAT_DUMP},
5591  {"efd", no_argument, NULL, EFD_DUMP},
5592  {"ecd", no_argument, NULL, ECD_DUMP},
5593  {"fdb_dump", no_argument, NULL, FDB_DUMP},
5594  {"ecdtest", no_argument, NULL, TEST_DUMP},
5595  {"connection-handle", required_argument, NULL, CONNECTION_HANDLE},
5596  {"connection-id", required_argument, NULL, CONNECTION_ID},
5597  {"linkcfg", required_argument, NULL, LINKCFG},
5598  {"linkspeed", required_argument, NULL, LINKSPEED},
5599  {"linktopology", required_argument, NULL, LINKTOPOLOGY},
5600  {"bufsize", required_argument, NULL, BUFSIZE},
5601  {"saved", no_argument, NULL, SAVED},
5602  {"clrsaved", no_argument, NULL, CLRSAVED},
5603  {"profile-id", required_argument, NULL, PROFILE_ID},
5604  {"protocol", required_argument, NULL, PROTOCOL_NAME},
5605  {"wqes", no_argument, NULL, WQES},
5606  {"cqes", no_argument, NULL, CQES},
5607  {"rqes", no_argument, NULL, RQES},
5608  {"mqes", no_argument, NULL, MQES},
5609  {"eqes", no_argument, NULL, EQES},
5610  {"qentries", required_argument, NULL, QENTRIES},
5611  {"firmware-reset", no_argument, NULL, FIRMWARE_RESET},
5612  {"port-migration", no_argument, NULL, PORT_MIGRATION},
5613  {"sfp_diag_data", no_argument, NULL, SFP_DIAG_DATA},
5614  {"sfp_xceiver_data", no_argument, NULL, SFP_TRANSCEIVER},
5615  {"loopback_type", required_argument, NULL, LOOPBACK_TYPE},
5616  {"retry_count", required_argument, NULL, RETRY_COUNT},
5617  {"chap-type", required_argument, NULL, CHAP_TYPE},
5618  {"vlan-id", required_argument, NULL, VLAN_ID},
5619  {"hba_identifier", required_argument, NULL, HBA_ID},
5620  {"port_identifier", required_argument, NULL, PORT_ID},
5621  {"mode", required_argument, NULL, TRUNK_MODE},
5622 
5623  /* End of list marker */
5624  {0,0,0,0}
5625  };
5626 
5627  memset(options, 0, sizeof(*options));
5628  options->chap_type = OCS_CHAP_TYPE_INCOMING;
5629  options->vlan_id = 0;
5630 
5631  // Set defaults
5632  options->bufsize = 16 * 1024 * 1024;
5633 
5634  while ((ch = getopt_long(argc, argv, "f:d:", opts, NULL)) != -1) {
5635 
5636  switch (ch) {
5637  case 'f':
5638  options->file = strdup(optarg);
5639  break;
5640  case 'd':
5641  if (!isdigit(*optarg)) {
5642  fprintf(stderr, "Invalid device '%s': not a number\n", optarg);
5643  return -1;
5644  }
5645  devname.devidx = atoi(optarg);
5646  break;
5647  case CMD_HOSTNAME:
5648  options->hostname = strdup(optarg);
5649  devname.hostname = strdup(optarg);
5650  break;
5651  case 'p':
5652  break;
5653  case CLEAR_COUNTER:
5654  options->cc = 1;
5655  break;
5656  case SAVED:
5657  options->saved = 1;
5658  break;
5659  case WQES:
5660  options->wqes = 1;
5661  break;
5662  case CQES:
5663  options->cqes = 1;
5664  break;
5665  case MQES:
5666  options->mqes = 1;
5667  break;
5668  case RQES:
5669  options->rqes = 1;
5670  break;
5671  case EQES:
5672  options->eqes = 1;
5673  break;
5674  case QENTRIES:
5675  options->qentries = atoi(optarg);
5676  break;
5677  case CLRSAVED:
5678  options->clr_saved = 1;
5679  break;
5680  case CLEAR_OVERFLOW_FLAG:
5681  options->clof = 1;
5682  break;
5683  case CLEAR_ALL_COUNTER:
5684  options->clrc = 1;
5685  break;
5686  case WWNN:
5687  options->wwnn = strdup(optarg);
5688  break;
5689  case WWPN:
5690  options->wwpn = strdup(optarg);
5691  break;
5692  case INITIATOR:
5693  options->initiator = 1;
5694  break;
5695  case TARGET:
5696  options->target = 1;
5697  break;
5698  case CONNECTION_HANDLE:
5699  options->connection_handle = strdup(optarg);
5700  break;
5701  case CONNECTION_ID:
5702  options->connection_id = strdup(optarg);
5703  break;
5704  case TEST_DUMP:
5705  options->ecd_test = 1;
5706  break;
5707  case FAT_DUMP:
5708  options->fat = 1;
5709  break;
5710  case EFD_DUMP:
5711  options->efd = 1;
5712  break;
5713  case ECD_DUMP:
5714  options->ecd = 1;
5715  break;
5716  case FDB_DUMP:
5717  options->fdb_dump = 1;
5718  break;
5719  case SFP_DIAG_DATA:
5720  options->sfp_diag_data = 1;
5721  break;
5722  case SFP_TRANSCEIVER:
5723  options->sfp_xceiver_data = 1;
5724  break;
5725  case LINKCFG:
5726  strncpy(options->linkcfg, optarg, (sizeof(options->linkcfg) - 1));
5727  break;
5728  case LINKSPEED:
5729  strncpy(options->linkspeed, optarg, (sizeof(options->linkspeed) - 1));
5730  break;
5731  case LINKTOPOLOGY:
5732  strncpy(options->linktopology, optarg, (sizeof(options->linktopology) - 1));
5733  break;
5734  case LOOPBACK_TYPE:
5735  options->loopback_type = atoi(optarg);
5736  break;
5737  case RETRY_COUNT:
5738  options->retry_count = atoi(optarg);
5739  break;
5740  case PROFILE_ID:
5741  options->profile_id = strdup(optarg);
5742  break;
5743  case PROTOCOL_NAME:
5744  options->protocol_name = strdup(optarg);
5745  break;
5746  case BUFSIZE:
5747  {
5748  int optlen;
5749  char suffix;
5750 
5751  optlen = strlen(optarg);
5752  suffix = optarg[optlen-1];
5753 
5754  options->bufsize = atoi(optarg);
5755  if (toupper(suffix) == 'K') {
5756  options->bufsize *= 1024;
5757  }
5758  if (toupper(suffix) == 'M') {
5759  options->bufsize *= (1024 * 1024);
5760  }
5761  }
5762  break;
5763  case CHAP_TYPE:
5764  {
5765  if (0 == strncmp(optarg, OCS_CHAP_INCOMING, strlen(optarg))) {
5766  options->chap_type = OCS_CHAP_TYPE_INCOMING;
5767  } else if (0 == strncmp(optarg, OCS_CHAP_OUTGOING, strlen(optarg))) {
5768  options->chap_type = OCS_CHAP_TYPE_OUTGOING;
5769  } else {
5770  fprintf(stderr, "Invalid argument: chap type %s\n", optarg);
5771  return -1;
5772  }
5773  }
5774  break;
5775  case VLAN_ID:
5776  {
5777  options->vlan_id = atoi(optarg);
5778  }
5779  break;
5780  case HBA_ID:
5781  options->hba_identifier = strdup(optarg);
5782  break;
5783  case PORT_ID:
5784  options->port_identifier = strdup(optarg);
5785  break;
5786  case TRUNK_MODE:
5787  options->trunk_mode = atoi(optarg);
5788  break;
5789  default:
5790  return -1;
5791  }
5792  }
5793 
5794  if ((argc - optind) > expected_nonargs) {
5795  fprintf(stderr, "Unexpected argument: %s\n", argv[optind + expected_nonargs]);
5796  return -1;
5797  }
5798 
5799  if (openflag) {
5800  options->device = elxu_open_device(&devname);
5801 
5802  if (options->device == NULL) {
5803  fprintf(stderr, "Unable to open device %d\n", devname.devidx);
5804  return -1;
5805  }
5806  }
5807 
5808  return 0;
5809 }
5810 
5811 /**
5812  * @brief Print examples of commands.
5813  *
5814  * @par Description
5815  * This function is called as part of the "help" command. It displays
5816  * examples of command usage.
5817  *
5818  * @return Returns nothing.
5819  *
5820  */
5821 static void show_examples()
5822 {
5823  printf ("Where <device> is an integer 0..n indicating which HBA to use.\n");
5824  printf ("If <device> is not specified it defaults to 0\n");
5825  printf ("\n");
5826  printf ("Examples:\n");
5827  printf ("Compare file data with data stored in device 0 flash:\n");
5828  printf ("elxsdkutil cmp myfile -d 0\n");
5829  printf ("\n");
5830  printf ("Display device 0 EFD capabilities:\n");
5831  printf ("elxsdkutil efdc -d 0\n");
5832  printf ("\n");
5833  printf ("Generate dump on device 0 to be read by --efd command:\n");
5834  printf ("elxsdkutil gendump -d 0\n");
5835  printf ("\n");
5836  printf ("Save device 0 EFD data in the file myfile:\n");
5837  printf ("elxsdkutil efd -d 0 -f myfile\n");
5838  printf ("\n");
5839  printf ("Save device 0 FAT content in the file myfile:\n");
5840  printf ("elxsdkutil fat -d 0 -f myfile\n");
5841  printf ("\n");
5842  printf ("Display UFI file and image information for the file myfile:\n");
5843  printf ("elxsdkutil info myfile\n");
5844  printf ("\n");
5845  printf ("List HBA devices:\n");
5846  printf ("elxsdkutil list\n");
5847  printf ("\n");
5848  printf ("List device filesystem objects on device 0:\n");
5849  printf ("elxsdkutil objenum -d 0\n");
5850  printf ("\n");
5851  printf ("Copy an object instance \"/obj/inst\" into file the specified file:\n");
5852  printf ("elxsdkutil read /obj/inst -d 0 -f myfile\n");
5853  printf ("\n");
5854  printf ("Write firmware image to device 0:\n");
5855  printf ("elxsdkutil write myfile -d 0\n");
5856  printf ("\n");
5857  printf ("Print hexadecimal diagnostic information from the Transceiver:\n");
5858  printf ("elxsdkutil sfp -d 0\n");
5859  printf ("\n");
5860  printf ("Retrieve Core Dump image to file:\n");
5861  printf ("elxsdkutil ecd -d 0 -f myfile\n");
5862  printf ("\n");
5863  printf ("Create a vport on device 0:\n");
5864  printf ("elxsdkutil create-vport 20:00:00:00:c9:01:02:03 10:00:00:00:c9:01:02:03 --target\n");
5865  printf ("\n");
5866  printf ("Remove a vport from device 0:\n");
5867  printf ("elxsdkutil remove-vport 20:00:00:00:c9:01:02:03 10:00:00:00:c9:01:02:03\n");
5868  printf ("\n");
5869  printf ("List devices user space driver\n");
5870  printf ("elxsdkutil list --host localhost\n\n");
5871 
5872  printf ("\nVersion: %s\n", ELXU_VERSION);
5873 }
5874 
5875 /**
5876 * @page cmd_line_parsing Command Line Parsing and Execution
5877 *
5878 * Command parsing and execution in the elxsdkutil is table driven. The
5879 * elxu_commands.h file contains an array (cmd_table[]), which describes the available
5880 * commands. Each entry in this table has the name of the command, a pointer to a
5881 * command handler function, and help text that describes the function.
5882 *
5883 * @ref cmd_handler are located in elxu_commands.c. Each of these functions parses
5884 * additional options as needed, validates the options given, then calls the appropriate
5885 * function to execute the command.
5886 *
5887 * The main() function simply compares the first command line argument to each of the
5888 * commands in the command table. If a match is found, then the corresponding handler
5889 * function is called. If no match is found, then an error message is displayed.
5890 *
5891 * @section commands_list List of Commands with Associated Command Handlers
5892 *
5893 * <table class="dashboard">
5894 * <tr><th>Command</th><th>Name</th><th>Command Handler</th></tr>
5895 * <tr><td>@ref cmd_add_ip "add-ip"</td><td>Add IP</td><td>elxu_cmd_add_ip()</td></tr>
5896 * <tr><td>@ref cmd_compare "cmp"</td><td>Compare</td><td>elxu_cmd_cmp()</td></tr>
5897 * <tr><td>@ref cmd_connection_info "connection-info"</td><td>Connection Information</td><td>elxu_cmd_connection_info()</td></tr>
5898 * <tr><td>@ref cmd_create_vport "create-vport"</td><td>Create VPort</td><td>elxu_cmd_create_vport()</td></tr>
5899 * <tr><td>@ref cmd_driver_dump "driver-dump"</td><td>Driver Dump</td><td>elxu_cmd_driver_dump()</td></tr>
5900 * <tr><td>@ref cmd_driver_info "driver-info"</td><td>Driver Information</td><td>elxu_cmd_driver_info()</td></tr>
5901 * <tr><td>@ref cmd_dump "dump"</td><td>Firmware Dump</td><td>elxu_cmd_dump()</td></tr>
5902 * <tr><td>@ref cmd_dump_to_host "dump-to-host"</td><td>Generate Dump to Host</td><td>elxu_cmd_dump_to_host()</td></tr>
5903 * <tr><td>@ref cmd_efdc "efdc"</td><td>EFD Capabilities</td><td>elxu_cmd_efdc()</td></tr>
5904 * <tr><td>@ref cmd_file_info "file-info"</td><td>File Information of UFI</td><td>elxu_cmd_file_info()</td></tr>
5905 * <tr><td>@ref cmd_gendump "gendump"</td><td>Generate Dump</td><td>elxu_cmd_gendump()</td></tr>
5906 * <tr><td>@ref cmd_help "help"</td><td>Help</td><td>elxu_cmd_help()</td></tr>
5907 * <tr><td>@ref cmd_linkcfg_get "linkcfg-get"</td><td>Get Link Configuration</td><td>elxu_cmd_linkcfg_get()</td></tr>
5908 * <tr><td>@ref cmd_linkcfg_set "linkcfg-get"</td><td>Set Link Configuration</td><td>elxu_cmd_linkcfg_set()</td></tr>
5909 * <tr><td>@ref cmd_list "list"</td><td>List Adapters</td><td>elxu_cmd_list()</td></tr>
5910 * <tr><td>@ref cmd_mgmt_info "mgmt-info"</td><td>Management Information</td><td>elxu_cmd_mgmt_info()</td></tr>
5911 * <tr><td>@ref cmd_objenum "objenum"</td><td>Objects Enumerate</td><td>elxu_cmd_objenum()</td></tr>
5912 * <tr><td>@ref cmd_read_link_status "read-link-status"</td><td>Read Link Status</td><td>elxu_cmd_read_link_status()</td></tr>
5913 * <tr><td>@ref cmd_read_rev "read-rev"</td><td>Read Adapter Version</td><td>elxu_cmd_read_rev()</td>></tr>
5914 * <tr><td>@ref cmd_read_status "read-status"</td><td>Read Device Status</td><td>elxu_cmd_read_status()</td></tr>
5915 * <tr><td>@ref cmd_read "read"</td><td>Read Object File</td><td>elxu_cmd_read()</td></tr>
5916 * <tr><td>@ref cmd_remove_vport "remove-vport"</td><td>Remove VPort</td><td>elxu_cmd_remove_vport()</td></tr>
5917 * <tr><td>@ref cmd_set_mac "set-mac"</td><td>Set MAC Address</td><td>elxu_cmd_set_mac()</td></tr>
5918 * <tr><td>@ref cmd_sfp "sfp"</td><td>SFP EEPROM Data</td><td>elxu_cmd_sfp()</td></tr>
5919 * <tr><td>@ref cmd_show_ips "show-ips"</td><td>Show IPs</td><td>elxu_cmd_show_ips()</td></tr>
5920 * <tr><td>@ref cmd_show_mac "show-mac"</td><td>Show MAC</td><td>elxu_cmd_show_mac()</td></tr>
5921 * <tr><td>@ref cmd_version "version"</td><td>Version of Program</td><td>elxu_cmd_version()</td></tr>
5922 * <tr><td>@ref cmd_write "write"</td><td>Write Firmware Image</td><td>elxu_cmd_write()</td></tr>
5923 * </table><br>
5924 */
uint32_t port_fabric_name_valid
Definition: ocs_ioctl.h:427
int elxu_cmd_node_abort_cnt(int argc, char **argv)
Command handler for the node-abort-cnt command.
uint8_t gateway[64]
Definition: ocs_ioctl.h:291
#define PORT_ID
Definition: elxu_commands.h:96
int elxu_cmd_help(int argc, char **argv)
Command handler for the help command.
#define OCS_CONFIG_LINKCFG_4X10G
linkcfg strings
Definition: ocs_ioctl.h:472
char * supported_linkspeed[]
Definition: elxu_commands.c:89
char * elxu_decode_sfp_id(uint32_t value)
int elxu_core_dump(elxu_device_t *device_p, char *fname_p, int test_dump)
Core Dump functionality.
Definition: elxu_dump.c:855
int elxu_cmd_disable_data_digest(int argc, char **argv)
Command handler for the disable-data-digest command.
int elxu_check_sfp_dport_support(elxu_device_t *device)
char * connection_handle
Definition: elxu_common.h:101
int elxu_cmd_set_nv_mac_pt(int argc, char **argv)
Command handler for the set-nv-mac command.
int mbox_connection_update(elxu_device_t *device, uint32_t request_flags, uint16_t connectionId, uint32_t constrainWindowValue)
Definition: elxu_mbox.c:1719
struct mgmt_object * head
Definition: elxu_mgmt.h:62
uint8_t wwpn[8]
Definition: elxu_device.h:99
#define OCS_CHAP_INCOMING
Definition: ocs_ioctl.h:269
uint8_t os_name_ver[256]
Definition: ocs_ioctl.h:414
int elxu_cmd_read_rev(int argc, char **argv)
Command handler for the read-rev command.
#define RQES
Definition: elxu_commands.h:80
int elxu_cmd_show_mac_pt(int argc, char **argv)
Command handler for the show-mac command for the elx_pt driver.
int elxu_cmd_driver_info(int argc, char **argv)
Command handler for the driver-info command.
#define RETRY_COUNT
Definition: elxu_commands.h:89
#define PROTOCOL_NAME
Definition: elxu_commands.h:84
int hba_data_upload(elxu_device_t *device_p, char const *fname_p, data_type_req_t req)
FAT data upload functionality.
Definition: elxu_dump.c:822
#define ELXU_IP_GET_ADDRESS_LIST_SIZE
#define SFP_DIAG_DATA
Definition: elxu_commands.h:87
int elxu_cmd_set_gateway(int argc, char **argv)
Command handler for the set-gateway command.
int elxu_cmd_set_active_profile(int argc, char **argv)
Command handler for the set-active-profile command.
int mbox_set_nv_wwn_pt(elxu_device_t *device, char *wwpn_p, char *wwnn_p)
Issue a set non-volatile WWNN/WWPN.
Definition: elxu_mbox.c:1276
uint8_t os_dev_name[256]
Definition: ocs_ioctl.h:448
int is_fc(elxu_device_t *device_p)
Return true IFF the HBA is a FC HBA.
Definition: elxu_device.c:1185
#define DPORT_SFP_TABLE2_LEN
int elxu_cmd_set_mac_ocs(int argc, char **argv)
Command handler for the set-mac command.
#define ELXU_CMD_VLAN_SHOW_BUFFER_SIZE
int elxu_cmd_sfp(int argc, char **argv)
Command handler for the sfp command.
int lancer_dump_to_host(elxu_device_t *device_p, const char *fname, int fdb_dump)
Trigger dump-to-host on Lancer.
Definition: elxu_dump.c:660
int elxu_cmd_diag_loopback_tests(int argc, char **argv)
int mbox_tcp_parameters(elxu_device_t *device, uint32_t request_flags, uint32_t ackFrequency, uint32_t delayedAckTimerValue)
Issue the Set TCP Parameters mbox command.
Definition: elxu_mbox.c:1663
int elxu_cmd_set_tcp_window_size(int argc, char **argv)
Command handler for the set-tcp-window-size command.
int elxu_cmd_get_profile_list(int argc, char **argv)
Command handler for the get-profile-list command.
char * value
Definition: elxu_mgmt.h:45
uint8_t bios_ver[256]
Definition: ocs_ioctl.h:420
int elxu_device_exec(elxu_device_t *device, char *name, void *arg_in, int arg_in_len, void *arg_out, int arg_out_len)
Execute a management function on a device.
Definition: elxu_device.c:952
#define OCS_FC_TRUNK_LINK_STATE_MASK
int parse_wwn(char *wwn_in, uint64_t *wwn_out)
Parse a WWN from a string into a 64-bit value.
Definition: elxu_common.c:327
int elxu_cmd_firmware_reset(int argc, char **argv)
Command handler for the firmware-reset command.
void elxu_display_device_list(char *hostname)
Display the list of available devices.
Definition: elxu_common.c:152
int elxu_cmd_remove_ip(int argc, char **argv)
Command handler for the remove-ip command.
int elxu_cmd_remove_vport(int argc, char **argv)
Command handler for the remove-vport command.
#define OCS_ISCSI_PORTAL_GRPTAG
uint32_t max_ct_payload_valid
Definition: ocs_ioctl.h:386
#define OCS_IOCTL_DDUMP_FLAGS_CQES
Definition: ocs_ioctl.h:310
int elxu_cmd_add_chap(int argc, char **argv)
Command handler for the add-chap command.
uint8_t active_fc4_types[32]
Definition: ocs_ioctl.h:456
char * supported_linkcfgs[]
Definition: elxu_commands.c:72
#define TRANSCEIVER_INFO_PAGE_SIZE
Definition: elxu_common.h:43
int elxu_cmd_set_active_profile_pt(int argc, char **argv)
Command handler for the set-active-profile command for the elx_pt driver.
elxu_device_t * device
Definition: elxu_common.h:69
int elxu_cmd_get_fdmi_hba_list(int argc, char **argv)
Command handler for the elxu_cmd_get_fdmi_hba_list command.
#define OCS_CONFIG_LINKCFG_1X40G
Definition: ocs_ioctl.h:473
#define LOOP
#define CLEAR_ALL_COUNTER
Definition: elxu_commands.h:61
int elxu_cmd_start_listen(int argc, char **argv)
Command handler for start-listen.
uint32_t entry_count
Definition: ocs_ioctl.h:295
char * vendor_pn
#define CLRSAVED
Definition: elxu_commands.h:76
int elxu_cmd_enable_data_digest(int argc, char **argv)
Command handler for enable-data-digest.
uint32_t supported_class_of_service
Definition: ocs_ioctl.h:454
uint32_t node_symb_name_valid
Definition: ocs_ioctl.h:386
int elxu_cmd_delayed_ack_timer(int argc, char **argv)
Command handler for the delayed-ack-timer command.
char * hba_identifier
Definition: elxu_common.h:110
int mbox_set_dynamic_dport(elxu_device_t *device, char *state_str)
Definition: elxu_mbox.c:385
#define OCS_CHAP_MODE_TARGET
Definition: ocs_ioctl.h:275
uint32_t supported_speed_valid
Definition: ocs_ioctl.h:427
int elxu_cmd_gendump(int argc, char **argv)
Command handler for the gendump command.
int elxu_cmd_read(int argc, char **argv)
Command handler for the read command.
int elxu_cmd_set_linkcfg(int argc, char **argv)
Command handler for the linkcfg-set command.
#define OCS_IOCTL_DDUMP_FLAGS_RQES
Definition: ocs_ioctl.h:312
int elxu_cmd_get_linkspeed(int argc, char **argv)
Command handler for the linkspeed-get command.
int mbox_read_rev(elxu_device_t *device)
Issue read rev mailbox command.
Definition: elxu_mbox.c:194
int mbox_soft_assign_mac(elxu_device_t *device, int *macaddr)
Soft assign MAC.
Definition: elxu_mbox.c:939
int mbox_query_dynamic_dport_status(elxu_device_t *device)
Definition: elxu_mbox.c:369
int elxu_cmd_show_ips(int argc, char **argv)
Command handler for the show-ips command.
int elxu_cmd_list(int argc, char **argv)
Command handler for the list command.
int elxu_cmd_dump_to_host(int argc, char **argv)
Command handler for the dump command.
int elxu_cmd_dump(int argc, char **argv)
Command handler for the dump command.
#define PORT_MIGRATION
Definition: elxu_commands.h:98
#define OCS_MAX_SLI4_ULP
Definition: ocs_ioctl.h:462
int elxu_get_fw_diagnostic_log(elxu_device_t *device_p, char const *fname)
gather firmware diagnostic logs
Definition: elxu_dump.c:765
#define OCS_ISCSI_TCP_PORT
void elxu_mgmt_info(elxu_device_t *device)
Definition: elxu_mgmt.c:59
int elxu_cmd_file_info(int argc, char **argv)
Command handler for the file-info command.
int elxu_cmd_get_tcp_window_size(int argc, char **argv)
Command handler for get-tcp-window-size.
#define QENTRIES
Definition: elxu_commands.h:83
#define OCS_DUMP_TYPE4_WKI_TAG_SAT_TEM_RESP_LEN
Definition: ocs_ioctl.h:267
#define OCS_CONFIG_LINKCFG_4X8G
Definition: ocs_ioctl.h:475
#define CONNECTION_HANDLE
Definition: elxu_commands.h:70
device name specifier This structure is used to describe the type and name of the device ioctl connec...
Definition: elxu_device.h:113
int is_lancer_g5(elxu_device_t *device_p)
Return true IFF the HBA is a Lancer G5.
Definition: elxu_device.c:1253
void * zmalloc(uint32_t len)
Allocates and zeroes memory to be used.
Definition: elxu_common.c:63
uint8_t model_desc[256]
Definition: ocs_ioctl.h:409
int elxu_cmd_set_tcp_window_scale(int argc, char **argv)
Command handler for set-tcp-window-scale.
int elxu_cmd_set_dport_dynamic_mode(int argc, char **argv)
int elxu_cmd_get_linktopology(int argc, char **argv)
Command handler for the linktopology-get command.
int elxu_cmd_get_gateway(int argc, char **argv)
Command handler for the get-gateway command.
#define PORTSPEED_1GFC
Definition: elxu_commands.c:63
#define ETH_FC_AUTO
Definition: elxu_commands.c:81
int ext_fat_capabilities_upld(elxu_device_t *device_p)
Displays EXT FAT capabilities.
Definition: elxu_dump.c:309
int elxu_cmd_get_trunk_config(int argc, char **argv)
Command handler for elxu_cmd_get_trunk_config command.
#define INITIATOR
Definition: elxu_commands.h:68
int elxu_cmd_set_require_chap(int argc, char **argv)
Command handler for set-require-chap.
uint8_t subnet[64]
Definition: ocs_ioctl.h:290
#define LINKCFG
Definition: elxu_commands.h:73
#define FC_32G
Definition: elxu_commands.c:87
#define LOOPBACK_TYPE
Definition: elxu_commands.h:88
#define OFT_DIRECTORY_OBJECT
Definition: elxu_sli4.h:704
int elxu_cmd_objenum(int argc, char **argv)
Command handler for the objenum command.
char * elxu_sfp_encoding_info(uint32_t value)
int elxu_cmd_unload(int argc, char **argv)
Command handler for user space driver unload.
#define OCS_IOCTL_CMD_UNLOAD
Definition: ocs_ioctl.h:497
int is_uspace(elxu_device_t *device_p)
Return true IFF the device is managed by a user space driver.
Definition: elxu_device.c:1305
int elxu_cmd_disable_jumbo(int argc, char **argv)
Command handler for the disable-jumbo command.
uint64_t hba_identifier[MAX_FDMI_HBA_COUNT]
Definition: ocs_ioctl.h:375
int mbox_set_linkcfg_pt(elxu_device_t *device, char *config)
Set Link configuration.
Definition: elxu_mbox.c:2306
int elxu_cmd_get_active_profile_pt(int argc, char **argv)
Command handler for the get-active-profile command for the elx_pt driver.
int elxu_cmd_driver_dump(int argc, char **argv)
Command handler for the driver-dump command.
int elxu_cmd_set_linktopology(int argc, char **argv)
Command handler for the linktopology-set command.
int elxu_ioctl_device(elxu_device_t *device, int req, void *arg)
Send an ioctl to a device.
Definition: elxu_device.c:322
void zfree(void *p)
Frees memory that has been allocated.
Definition: elxu_common.c:80
uint32_t type
Definition: elxu_lancer.h:41
char * supported_linktopology[]
int elxu_cmd_port_migration(int argc, char **argv)
Command handler for the port-migration command.
int is_lancer(elxu_device_t *device_p)
Return true IFF the HBA is a Lancer.
Definition: elxu_device.c:1236
char linkspeed[LINKSPEED_VALUE_NAME_MAX]
Definition: elxu_common.h:98
#define SFP_TRANSCEIVER
Definition: elxu_commands.h:93
mgmt_object_t * mgmt_list_remove(mgmt_list_t *list, char *name)
Remove an object from a list.
Definition: elxu_mgmt.c:164
uint8_t driver_ver[256]
Definition: ocs_ioctl.h:411
char * hostname
Definition: elxu_common.h:103
#define OCS_MAX_SLI_PORTS_PER_DEVICE
int elxu_cmd_constrain_window(int argc, char **argv)
Command handler for the constrain-window command.
int remove_vport(elxu_device_t *device_p, uint64_t wwnn, uint64_t wwpn, int targetFlag, int initiatorFlag)
Definition: elxu_mbox.c:2339
#define PORTSPEED_64GFC
Definition: elxu_commands.c:69
int elxu_cmd_enable_jumbo(int argc, char **argv)
Command handler for the enable-jumbo command.
#define OCS_CHAP_TYPE_INCOMING
Definition: ocs_ioctl.h:273
int mbox_get_dport_stats(elxu_device_t *device)
Issue Get dport stats mailbox command Create a GET_DPORT_STAT mailbox command.
Definition: elxu_mbox.c:408
int mbox_set_nv_mac_pt(elxu_device_t *device, int *macaddr)
Definition: elxu_mbox.c:1098
int mbox_read_status(elxu_device_t *device, uint32_t clear_counter)
Issue read status mailbox command.
Definition: elxu_mbox.c:763
uint8_t host_name[256]
Definition: ocs_ioctl.h:449
static cmd_table_entry_t cmd_table[]
char * port_identifier
Definition: elxu_common.h:111
#define FC_4G
Definition: elxu_commands.c:84
struct mgmt_object * next
Definition: elxu_mgmt.h:55
char * protocol_name
Definition: elxu_common.h:106
#define min(x, y)
Definition: elxu_mbox.h:39
#define ECD_DUMP
Definition: elxu_commands.h:65
int elxu_cmd_get_linkcfg(int argc, char **argv)
Command handler for the linkcfg-get command.
#define PORTSPEED_8GFC
Definition: elxu_commands.c:66
#define VLAN_ID
Definition: elxu_commands.h:94
uint32_t num_port_attr_entries
Definition: ocs_ioctl.h:426
#define PORTSPEED_128GFC
Definition: elxu_commands.c:70
#define PORTSPEED_16GFC
Definition: elxu_commands.c:67
int mgmt_set_value(elxu_device_t *device, char *name, char *value)
Definition: elxu_mgmt.c:447
#define OCS_FC_TRUNK_2_PORT_CONFIG
char * profile_id
Definition: elxu_common.h:105
#define N_PORT
Definition: elxu_commands.c:99
#define PORTSPEED_4GFC
Definition: elxu_commands.c:65
#define OCS_IOCTL_DDUMP_FLAGS_MQES
Definition: ocs_ioctl.h:311
#define WQES
Definition: elxu_commands.h:78
int elxu_cmd_show_chap_list(int argc, char **argv)
Command handler for show-chap.
int sfp_xceiver_data
Definition: elxu_common.h:92
int elxu_cmd_create_vport(int argc, char **argv)
Command handler for the create-vport command.
int mbox_set_active_profile_pt(elxu_device_t *device, char *new_profile_id)
Definition: elxu_mbox.c:2940
#define ISCSI_UPDATE_TCP_WINDOW
Definition: elxu_sli4.h:890
int elxu_cmd_stop_listen(int argc, char **argv)
Command handler for stop-listen.
uint8_t serial_num[64]
Definition: ocs_ioctl.h:407
int elxu_cmd_fw_diagnostic_log(int argc, char **argv)
Command handler for the fw-diag-log command.
void elxu_driver_dump(elxu_device_t *device, int bufsize, ocs_ioctl_ddump_arg_t *args)
Definition: elxu_dump.c:163
int elxu_cmd_mgmt_info(int argc, char **argv)
Command handler for the mgmt-info command.
#define OCS_CONFIG_LINKCFG_4X1G
Definition: ocs_ioctl.h:476
int lancer_gen_dump(elxu_device_t *device_p, int fdb_dump)
Trigger dump generation on Lancer.
Definition: elxu_dump.c:630
#define OCS_IOCTL_DDUMP_FLAGS_EQES
Definition: ocs_ioctl.h:313
int elxu_cmd_ack_frequency(int argc, char **argv)
Command handler for the ack-frequency command.
char * elxu_decode_sfp_connector(uint32_t value)
char * vendor_pn
uint64_t port_identifier[MAX_FDMI_PORT_COUNT]
Definition: ocs_ioctl.h:380
int elxu_cmd_board_temp(int argc, char **argv)
Command handler for the board temperature.
uint32_t active_fc_types_valid
Definition: ocs_ioctl.h:427
int elxu_cmd_get_fdmi_port_list(int argc, char **argv)
Command handler for the elxu_cmd_get_fdmi_port_list command.
char linkcfg[LINKCFG_VALUE_NAME_MAX]
Definition: elxu_common.h:96
#define FC_8G
Definition: elxu_commands.c:85
uint32_t deviceIndex
Definition: elxu_device.h:85
int elxu_cmd_set_linkspeed(int argc, char **argv)
Command handler for the link-speed-set command.
#define EFD_DUMP
Definition: elxu_commands.h:64
uint32_t supported_fc_types_valid
Definition: ocs_ioctl.h:427
char * connection_id
Definition: elxu_common.h:102
ocs_route_table_entry_t entry[OCS_ISCSI_ROUTE_TABLE_ENTRIES_MAX]
Definition: ocs_ioctl.h:296
#define WWNN
Definition: elxu_commands.h:66
#define CLEAR_OVERFLOW_FLAG
Definition: elxu_commands.h:60
#define TRUNK_MODE
Definition: elxu_commands.h:97
int elxu_cmd_read_link_status(int argc, char **argv)
Command handler for the read-link-status command.
int elxu_cmd_cmp(int argc, char **argv)
Command handler for the cmp command.
void mgmt_delete_list(mgmt_list_t *list)
mgmt_delete_list Delete a linked list and free its contents
Definition: elxu_mgmt.c:111
#define CQES
Definition: elxu_commands.h:79
mgmt_list is a linked list of objects
Definition: elxu_mgmt.h:61
#define OCS_CONFIG_LINKCFG_2X16G
Definition: ocs_ioctl.h:474
int is_skyhawk(elxu_device_t *device_p)
Return true IFF the HBA is a Skyhawk.
Definition: elxu_device.c:1219
void elxu_get_connection_info(elxu_device_t *device)
Print iSCSI connection info for the given device.
Definition: elxu_bsd.c:230
#define WWPN
Definition: elxu_commands.h:67
int elxu_cmd_set_wwn(int argc, char **argv)
Command handler for the set-wwn command.
int elxu_cmd_set_max_connections(int argc, char **argv)
Command handler for set-max-connections.
int elxu_cmd_get_profile_list_pt(int argc, char **argv)
Command handler for the get-profile-list command for the elx_pt driver.
int is_fcoe(elxu_device_t *device_p)
Return true IFF the HBA is a FCoE HBA.
Definition: elxu_device.c:1202
char * elxu_decode_sfp_rate_id(uint32_t value)
#define BUFSIZE
Definition: elxu_commands.h:74
uint8_t ip_addr[64]
Definition: ocs_ioctl.h:289
#define ELXU_VERSION
Definition: elxu_common.h:40
char * vendor_rev
int is_nic(elxu_device_t *device_p)
Return true IFF the HBA is a NIC HBA.
Definition: elxu_device.c:1168
char * access
Definition: elxu_mgmt.h:46
uint64_t port_identifier[MAX_FDMI_PORT_COUNT]
Definition: ocs_ioctl.h:385
int elxu_cmd_efdc(int argc, char **argv)
Command handler for the efdc command.
char * elxu_device_get_value(elxu_device_t *device, char *key)
Return a property value for a device.
Definition: elxu_device.c:765
int mbox_read_link_status(elxu_device_t *device, int clof, int clrc)
Issue read link status mailbox command.
Definition: elxu_mbox.c:666
#define PROFILE_ID
Definition: elxu_commands.h:77
#define ARRAY_SIZE(x)
Definition: elxu_common.h:46
int elxu_cmd_add_ip(int argc, char **argv)
Command handler for the add-ip command.
#define DPORT_SFP_TABLE1_LEN
char * mbox_get_linkcfg_pt(elxu_device_t *device)
Get Link configuration.
Definition: elxu_mbox.c:2086
#define OCS_FC_TRUNK_CONFIG_MASK
#define CHAP_TYPE
Definition: elxu_commands.h:92
#define OCS_CONFIG_LINKCFG_2X10G
Definition: ocs_ioctl.h:477
uint8_t port_symb_name[256]
Definition: ocs_ioctl.h:452
mgmt_list_t * mgmt_get_all(elxu_device_t *device)
Definition: elxu_mgmt.c:482
#define LINKTOPOLOGY
Definition: elxu_commands.h:91
int mbox_get_active_profile_pt(elxu_device_t *device, char *result, int result_len)
Definition: elxu_mbox.c:2844
#define EQES
Definition: elxu_commands.h:82
int elxu_cmd_read_status(int argc, char **argv)
Command handler for the read-status command.
#define SAVED
Definition: elxu_commands.h:75
int elxu_device_get_lancer_temp(elxu_device_t *device)
int elxu_cmd_get_max_connections(int argc, char **argv)
Command handler for get-max-connections.
char * vendor
#define AUTO
Definition: elxu_commands.c:98
#define OCS_FC_TRUNK_4_PORT_CONFIG
int create_vport(elxu_device_t *device_p, uint64_t wwnn, uint64_t wwpn, int targetFlag, int initiatorFlag)
Definition: elxu_mbox.c:2319
#define FDB_DUMP
Definition: elxu_commands.h:86
elxu_device_t * elxu_open_device(elxu_device_name_t *devname)
Open a device file.
Definition: elxu_device.c:212
char linktopology[LINKTOPO_VALUE_NAME_MAX]
Definition: elxu_common.h:100
uint8_t supported_fc4_types[32]
Definition: ocs_ioctl.h:444
int elxu_cmd_iclusttgt_show(elxu_device_t *device)
int is_iscsi(elxu_device_t *device_p)
Return true IFF the HBA is an iSCSI HBA.
Definition: elxu_device.c:1151
sli4_object_t * sli4_object_enumerate(elxu_device_t *device)
Create a list of all SLI4 objects.
Definition: elxu_lancer.c:53
int elxu_cmd_get_fdmi_port_info(int argc, char **argv)
Command handler for the elxu_cmd_get_fdmi_port_info command.
static void show_examples()
Print examples of commands.
void usage()
Show program usage.
ocs_ddump_action_t action
Definition: ocs_ioctl.h:316
uint32_t length
Definition: elxu_lancer.h:42
int elxu_cmd_remove_chap(int argc, char **argv)
Command handler for remove-chap.
uint8_t manufacturer[64]
Definition: ocs_ioctl.h:406
mgmt_object is a list of properties
Definition: elxu_mgmt.h:53
int elxu_cmd_set_port_protocol(int argc, char **argv)
Command handler for the set-port-protocol command.
#define FC_2G
Definition: elxu_commands.c:83
uint8_t node_symb_name[256]
Definition: ocs_ioctl.h:416
int elxu_cmd_get_dynamic_dport_status(int argc, char **argv)
void mgmt_list_sort(mgmt_list_t *list)
Definition: elxu_mgmt.c:211
#define ISCSI_UPDATE_ACK_FREQUENCY
Definition: elxu_sli4.h:874
#define PORTSPEED_2GFC
Definition: elxu_commands.c:64
int elxu_check_ip_address_exists(cmd_options_t *options, char *ipaddr, int *ip_found)
int file_handler(elxu_device_t *device_p, char const *file_name_p, int action)
File manipulating functionality.
Definition: elxu_dwnld.c:966
int elxu_cmd_vlan(int argc, char **argv)
Command handler for the vlan command.
#define FC_16G
Definition: elxu_commands.c:86
#define OCS_CHAP_OUTGOING
Definition: ocs_ioctl.h:270
int mbox_fw_reset_pt(elxu_device_t *device, int dd)
Definition: elxu_mbox.c:2625
#define ISCSI_UPDATE_DELAYED_ACK_TIMER
Definition: elxu_sli4.h:873
#define LINKSPEED
Definition: elxu_commands.h:90
int mbox_diag_loopback_tests(elxu_device_t *device, int loopback_type, int retry_count)
Issue set link diag loopback mailbox command.
Definition: elxu_mbox.c:543
int elxu_cmd_get_dport_stats(int argc, char **argv)
Command handler for the get-dport-stats command.
int is_prism(elxu_device_t *device_p)
Return true IFF the HBA is a Prism.
Definition: elxu_device.c:1270
void mbox_get_mac_pt(elxu_device_t *device, uint8_t *mac_addr)
Definition: elxu_mbox.c:950
int elxu_cmd_get_fdmi_hba_info(int argc, char **argv)
Command handler for the elxu_cmd_get_fdmi_hba_info command.
int elxu_cmd_disable_header_digest(int argc, char **argv)
Command handler for the disable-header-digest comand.
int elxu_cmd_get_active_profile(int argc, char **argv)
Command handler for the get-active-profile command.
mgmt_property is a name / value pair
Definition: elxu_mgmt.h:43
void elxu_decode_port_speed(uint32_t port_speed, char *buf)
#define OCS_IOCTL_DDUMP_FLAGS_WQES
Definition: ocs_ioctl.h:309
int elxu_cmd_iclusttgt(int argc, char **argv)
uint8_t length_copper
#define TARGET
Definition: elxu_commands.h:69
static void ocs_fc_report_trunk_links(uint8_t ports_active, char *active_ports_str, size_t max_str_len)
#define HBA_ID
Definition: elxu_commands.h:95
int hba_data_object_upload(elxu_device_t *device_p, char const *objname_p, char const *fname_p)
Definition: elxu_dump.c:564
int elxu_cmd_show_mac_ocs(int argc, char **argv)
Command handler for the show-mac command for the OCS drivers.
#define OCS_CLUST_TARGET_KEY_RETCNT
int elxu_cmd_connection_info(int argc, char **argv)
Command handler for the connection-info command.
void dump8(const char *label, void *buffer, uint32_t bufferLength)
Print a buffer in hexadecimal and ASCII.
Definition: elxu_common.c:100
#define FAT_DUMP
Definition: elxu_commands.h:63
struct sli4_object_s * next
Definition: elxu_lancer.h:39
int elxu_cmd_enable_header_digest(int argc, char **argv)
Command handler for enable-header-digest.
elxu_device_driver_e driver
Definition: elxu_device.h:90
int elxu_cmd_iclusttgt_check_args(int argc, char **argv)
uint8_t opt_rom_ver[256]
Definition: ocs_ioctl.h:412
#define MQES
Definition: elxu_commands.h:81
char * hex_dump(uint8_t *value, int size)
Display a buffer in hexadecimal.
Definition: elxu_common.c:401
int elxu_cmd_get_parity_stats(int argc, char **argv)
Command handler for the get-parity-stats command.
#define FIRMWARE_RESET
Definition: elxu_commands.h:85
int mbox_get_profile_list_pt(elxu_device_t *device, char *result, int result_len)
Definition: elxu_mbox.c:2771
#define CLEAR_COUNTER
Definition: elxu_commands.h:59
int elxu_cmd_show_wwn(int argc, char **argv)
Command handler for the show-wwn command.
int elxu_cmd_version(int argc, char **argv)
Command handler for the version command.
int elxu_cmd_write(int argc, char **argv)
Command handler for the write command.
uint8_t model_name[256]
Definition: ocs_ioctl.h:408
uint8_t wwnn[8]
Definition: elxu_device.h:98
#define OCS_CONFIG_LINKCFG_2X10G_2X8G
Definition: ocs_ioctl.h:478
int elxu_cmd_get_require_chap(int argc, char **argv)
Command handler for get-require-chap.
int elxu_cmd_firmware_reset_pt(int argc, char **argv)
Send a firmware reset via the elx_pt driver.
#define ETH_FC_10G
Definition: elxu_commands.c:82
int elxu_cmd_route(int argc, char **argv)
Command handler for the route command.
#define TEST_DUMP
Definition: elxu_commands.h:62
#define CMD_HOSTNAME
Definition: elxu_commands.h:72
int elxu_cmd_get_tcp_window_scale(int argc, char **argv)
Command handler for get-tcp-window-scale.
int elxu_cmd_get_port_protocol(int argc, char **argv)
Command handler for the get-port-protocol command.
#define OCS_CHAP_TYPE_OUTGOING
Definition: ocs_ioctl.h:274
#define OCS_FC_TRUNK_2_PORT_HI_CONFIG
#define PORTSPEED_32GFC
Definition: elxu_commands.c:68
int elxu_cmd_set_trunk_mode(int argc, char **argv)
Command handler for elxu_cmd_set_trunk_mode command.
int mbox_get_connection_info(elxu_device_t *device, uint32_t connectionHandle)
Get connection info.
Definition: elxu_mbox.c:1776
void sli4_object_free_list(sli4_object_t *head)
Free a list of sli4_object_t&#39;s.
Definition: elxu_lancer.c:570
#define CONNECTION_ID
Definition: elxu_commands.h:71
struct mgmt_property * head
Definition: elxu_mgmt.h:54
int parse_arguments(int argc, char **argv, cmd_options_t *options, int openflag, int expected_nonargs)
Parse command line arguments.
data_type_req_t
Definition: elxu_dump.h:40