2 * Copyright (c) 2002-2007 Neterion, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 main( int argc, char *argv[] )
34 int status = EXIT_FAILURE;
37 if(!((strcmp(argv[2], "getregister") == 0) ||
38 (strcmp(argv[2], "setregister") == 0) ||
39 (strcmp(argv[2], "setbufmode") == 0))) {
48 if(!((strcmp(argv[2], "hwstats") == 0) ||
49 (strcmp(argv[2], "pciconf") == 0) ||
50 (strcmp(argv[2], "devconf") == 0) ||
51 (strcmp(argv[2], "registers") == 0) ||
52 (strcmp(argv[2], "version") == 0) ||
53 (strcmp(argv[2], "swstats") == 0) ||
54 (strcmp(argv[2], "drvstats") == 0) ||
55 (strcmp(argv[2], "getbufmode") == 0) ||
56 (strcmp(argv[2], "devstats") == 0))) {
62 if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
63 printf("Creating socket failed\n");
67 ifreqp.ifr_addr.sa_family = AF_INET;
68 strcpy(ifreqp.ifr_name, argv[1]);
70 if (strcmp(argv[2], "pciconf") == 0)
71 status = xge_get_pciconf();
72 else if(strcmp(argv[2], "devconf") == 0)
73 status = xge_get_devconf();
74 else if(strcmp(argv[2], "hwstats") == 0)
75 status = xge_get_hwstats();
76 else if(strcmp(argv[2], "registers") == 0)
77 status = xge_get_registers();
78 else if(strcmp(argv[2], "devstats") == 0)
79 status = xge_get_devstats();
80 else if(strcmp(argv[2], "swstats") == 0)
81 status = xge_get_swstats();
82 else if(strcmp(argv[2], "drvstats") == 0)
83 status = xge_get_drvstats();
84 else if(strcmp(argv[2], "version") == 0)
85 status = xge_get_drv_version();
86 else if(strcmp(argv[2], "getbufmode") == 0)
87 status = xge_get_buffer_mode();
88 else if(strcmp(argv[2], "getregister") == 0)
89 status = xge_get_register(argv[3]);
90 else if(strcmp(argv[2], "setregister") == 0)
91 status = xge_set_register(argv[3], argv[4]);
92 else if(strcmp(argv[2], "setbufmode") == 0)
93 status = xge_change_buffer_mode(argv[3]);
98 printf("getinfo <INTERFACE> [hwstats] [swstats] [devstats] ");
99 printf("[drvstats] [version] [registers] [getregister offset] ");
100 printf("[setregister offset value] [pciconf] [devconf] [getbufmode] ");
101 printf("[setbufmode]\n");
102 printf("\tINTERFACE : Interface (nxge0, nxge1, nxge2, ..) \n");
103 printf("\thwstats : Prints hardware statistics \n");
104 printf("\tswstats : Prints software statistics \n");
105 printf("\tdevstats : Prints device statistics \n");
106 printf("\tdrvstats : Prints driver statistics \n");
107 printf("\tversion : Prints driver version \n");
108 printf("\tregisters : Prints register values \n");
109 printf("\tgetregister : Read a register \n");
110 printf("\tsetregister : Write to a register \n");
111 printf("\tpciconf : Prints PCI configuration space \n");
112 printf("\tdevconf : Prints device configuration \n");
113 printf("\tgetbufmode : Prints Buffer Mode \n");
114 printf("\tsetbufmode : Changes buffer mode \n");
122 * Gets hardware statistics
124 * Returns EXIT_SUCCESS or EXIT_FAILURE
127 xge_get_hwstats(void)
129 char *hw_stats = NULL, *pci_cfg = NULL;
130 unsigned short device_id;
132 int status = EXIT_FAILURE;
134 buffer_size = GET_OFFSET_STATS(XGE_COUNT_STATS - 1) + 8;
136 hw_stats = (char *)malloc(buffer_size);
138 printf("Allocating memory for hardware statistics failed\n");
141 *hw_stats = XGE_QUERY_STATS;
142 ifreqp.ifr_data = (caddr_t) hw_stats;
144 if(ioctl(sockfd, SIOCGPRIVATE_0, &ifreqp) < 0) {
145 printf("Getting hardware statistics failed\n");
149 buffer_size = GET_OFFSET_PCICONF(XGE_COUNT_PCICONF - 1) + 8;
150 pci_cfg = (void *)malloc(buffer_size);
152 printf("Allocating memory for PCI configuration failed\n");
156 *pci_cfg = XGE_QUERY_PCICONF;
157 ifreqp.ifr_data = (caddr_t)pci_cfg;
159 if(ioctl(sockfd, SIOCGPRIVATE_0, &ifreqp) < 0) {
160 printf("Getting pci configuration space failed\n");
163 device_id = *((u16 *)((unsigned char *)pci_cfg +
164 GET_OFFSET_PCICONF(index)));
166 xge_print_hwstats(hw_stats,device_id);
167 status = EXIT_SUCCESS;
181 * Gets PCI configuration space
183 * Returns EXIT_SUCCESS or EXIT_FAILURE
186 xge_get_pciconf(void)
188 char *pci_cfg = NULL;
189 int status = EXIT_FAILURE;
191 buffer_size = GET_OFFSET_PCICONF(XGE_COUNT_PCICONF - 1) + 8;
193 pci_cfg = (char *)malloc(buffer_size);
195 printf("Allocating memory for PCI configuration failed\n");
199 *pci_cfg = XGE_QUERY_PCICONF;
200 ifreqp.ifr_data = (caddr_t)pci_cfg;
202 if(ioctl(sockfd, SIOCGPRIVATE_0, &ifreqp) < 0) {
203 printf("Getting PCI configuration space failed\n");
207 xge_print_pciconf( pci_cfg );
208 status = EXIT_SUCCESS;
219 * Gets device configuration
221 * Returns EXIT_SUCCESS or EXIT_FAILURE
224 xge_get_devconf(void)
226 char *device_cfg = NULL;
227 int status = EXIT_FAILURE;
229 buffer_size = XGE_COUNT_DEVCONF * sizeof(int);
231 device_cfg = (char *)malloc(buffer_size);
233 printf("Allocating memory for device configuration failed\n");
237 *device_cfg = XGE_QUERY_DEVCONF;
238 ifreqp.ifr_data = (caddr_t)device_cfg;
240 if(ioctl(sockfd, SIOCGPRIVATE_0, &ifreqp) < 0) {
241 printf("Getting Device Configuration failed\n");
245 xge_print_devconf( device_cfg );
246 status = EXIT_SUCCESS;
256 * xge_get_buffer_mode
257 * Get current Rx buffer mode
259 * Return EXIT_SUCCESS or EXIT_FAILURE
262 xge_get_buffer_mode(void)
264 char *buf_mode = NULL;
265 int status = EXIT_FAILURE;
267 buf_mode = (char *)malloc(sizeof(int));
269 printf("Allocating memory for buffer mode failed\n");
273 *buf_mode = XGE_QUERY_BUFFER_MODE;
274 ifreqp.ifr_data = (void *)buf_mode;
276 if(ioctl(sockfd, SIOCGPRIVATE_0, &ifreqp) < 0) {
277 printf("Getting Buffer Mode failed\n");
280 printf("Rx Buffer Mode: %d\n", *ifreqp.ifr_data);
281 status = EXIT_SUCCESS;
291 * xge_change_buffer_mode
292 * Change Rx buffer mode
294 * Returns EXIT_SUCCESS or EXIT_FAILURE
297 xge_change_buffer_mode(char *bufmode)
299 char *print_msg = NULL;
300 int status = EXIT_FAILURE;
302 print_msg = (char *)malloc(sizeof(char));
303 if(print_msg == NULL) {
304 printf("Allocation of memory for message failed\n");
308 if (*bufmode == '1') *print_msg = XGE_SET_BUFFER_MODE_1;
309 else if(*bufmode == '2') *print_msg = XGE_SET_BUFFER_MODE_2;
310 else if(*bufmode == '5') *print_msg = XGE_SET_BUFFER_MODE_5;
312 printf("Invalid Buffer mode\n");
316 ifreqp.ifr_data = (char *)print_msg;
317 if(ioctl(sockfd, SIOCGPRIVATE_0, &ifreqp) < 0) {
318 printf("Changing buffer mode failed\n");
322 if(*print_msg == 'Y') {
323 printf("Requested buffer mode was already enabled\n");
325 else if(*print_msg == 'N') {
326 printf("Requested buffer mode is not implemented OR\n");
327 printf("Dynamic buffer changing is not supported in this driver\n");
329 else if(*print_msg == 'C') {
330 printf("Buffer mode changed to %c\n", *bufmode);
332 status = EXIT_SUCCESS;
344 * Gets register values
346 * Returns EXIT_SUCCESS or EXIT_FAILURE
349 xge_get_registers(void)
351 void *registers = NULL;
352 int status = EXIT_FAILURE;
354 buffer_size = regInfo[XGE_COUNT_REGS - 1].offset + 8;
356 registers = (void *)malloc(buffer_size);
358 printf("Allocating memory for register dump failed\n");
362 ifreqp.ifr_data = (caddr_t)registers;
363 if(ioctl(sockfd, SIOCGPRIVATE_1, &ifreqp) < 0) {
364 printf("Getting register values failed\n");
368 xge_print_registers(registers);
369 status = EXIT_SUCCESS;
380 * Reads a register specified offset
382 * @offset Offset of register from base address
384 * Returns EXIT_SUCCESS or EXIT_FAILURE
387 xge_get_register(char *offset)
389 xge_register_info_t *register_info = NULL;
390 int status = EXIT_FAILURE;
393 (xge_register_info_t *)malloc(sizeof(xge_register_info_t));
395 printf("Allocating memory for register info failed\n");
399 strcpy(register_info->option, "-r");
400 sscanf(offset, "%x", ®ister_info->offset);
401 ifreqp.ifr_data = (caddr_t)register_info;
403 if(ioctl(sockfd, SIOCGPRIVATE_1, &ifreqp) < 0) {
404 printf("Reading register failed\n");
408 xge_print_register(register_info->offset, register_info->value);
409 status = EXIT_SUCCESS;
420 * Writes to a register specified offset
422 * @offset Offset of register from base address
423 * @value Value to write to
425 * Returns EXIT_SUCCESS or EXIT_FAILURE
428 xge_set_register(char *offset, char *value)
430 xge_register_info_t *register_info = NULL;
431 int status = EXIT_FAILURE;
434 (xge_register_info_t *)malloc(sizeof(xge_register_info_t));
436 printf("Allocating memory for register info failed\n");
440 strcpy(register_info->option, "-w");
441 sscanf(offset, "%x", ®ister_info->offset);
442 sscanf(value, "%llx", ®ister_info->value);
444 ifreqp.ifr_data = (caddr_t)register_info;
445 if(ioctl(sockfd, SIOCGPRIVATE_1, &ifreqp) < 0) {
446 printf("Writing register failed\n");
449 status = EXIT_SUCCESS;
460 * Gets device statistics
462 * Returns EXIT_SUCCESS or EXIT_FAILURE
465 xge_get_devstats(void)
467 char *dev_stats = NULL;
468 int status = EXIT_FAILURE;
470 buffer_size = XGE_COUNT_INTRSTAT * sizeof(u32);
472 dev_stats = (char *)malloc(buffer_size);
474 printf("Allocating memory for device statistics failed\n");
478 *dev_stats = XGE_QUERY_DEVSTATS;
479 ifreqp.ifr_data = (caddr_t)dev_stats;
481 if(ioctl(sockfd, SIOCGPRIVATE_0, &ifreqp) < 0) {
482 printf("Getting device statistics failed\n");
486 xge_print_devstats(dev_stats);
487 status = EXIT_SUCCESS;
498 * Gets software statistics
500 * Returns EXIT_SUCCESS or EXIT_FAILURE
503 xge_get_swstats(void)
505 char *sw_stats = NULL;
506 int status = EXIT_FAILURE;
508 buffer_size = XGE_COUNT_SWSTAT * sizeof(u32);
510 sw_stats = (char *) malloc(buffer_size);
512 printf("Allocating memory for software statistics failed\n");
516 *sw_stats = XGE_QUERY_SWSTATS;
517 ifreqp.ifr_data = (caddr_t)sw_stats;
519 if(ioctl(sockfd, SIOCGPRIVATE_0, &ifreqp) < 0) {
520 printf("Getting software statistics failed\n");
524 xge_print_swstats(sw_stats);
525 status = EXIT_SUCCESS;
535 * xge_get_drv_version
536 * Gets driver version
538 * Returns EXIT_SUCCESS or EXIT_FAILURE
541 xge_get_drv_version(void)
543 char *version = NULL;
544 int status = EXIT_FAILURE;
547 version = (char *)malloc(buffer_size);
549 printf("Allocating memory for driver version failed\n");
553 *version = XGE_READ_VERSION;
554 ifreqp.ifr_data = ( caddr_t )version;
556 if(ioctl(sockfd, SIOCGPRIVATE_0, &ifreqp) < 0) {
557 printf("Getting driver version failed\n");
560 xge_print_drv_version(version);
561 status = EXIT_SUCCESS;
572 * Gets driver statistics
574 * Returns EXIT_SUCCESS or EXIT_FAILURE
577 xge_get_drvstats(void)
579 char *driver_stats = NULL;
580 int status = EXIT_FAILURE;
582 buffer_size = XGE_COUNT_DRIVERSTATS * sizeof(u64);
584 driver_stats = (char *)malloc(buffer_size);
586 printf("Allocating memory for driver statistics failed\n");
590 *driver_stats = XGE_QUERY_DRIVERSTATS;
591 ifreqp.ifr_data = (caddr_t)driver_stats;
593 if(ioctl(sockfd, SIOCGPRIVATE_0, &ifreqp) < 0) {
594 printf("Getting Driver Statistics failed\n");
598 xge_print_drvstats(driver_stats);
599 status = EXIT_SUCCESS;