xref: /freebsd/sys/dev/oce/oce_sysctl.c (revision 8d20be1e22095c27faf8fe8b2f0d089739cc742e)
1 /*-
2  * Copyright (C) 2013 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
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the Emulex Corporation nor the names of its
16  *    contributors may be used to endorse or promote products derived from
17  *    this software 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 OWNER 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  * Contact Information:
32  * freebsd-drivers@emulex.com
33  *
34  * Emulex
35  * 3333 Susan Street
36  * Costa Mesa, CA 92626
37  */
38 
39 /* $FreeBSD$ */
40 
41 #include "oce_if.h"
42 
43 static void copy_stats_to_sc_xe201(POCE_SOFTC sc);
44 static void copy_stats_to_sc_be3(POCE_SOFTC sc);
45 static void copy_stats_to_sc_be2(POCE_SOFTC sc);
46 static int  oce_sysctl_loopback(SYSCTL_HANDLER_ARGS);
47 static int  oce_be3_fwupgrade(POCE_SOFTC sc, const struct firmware *fw);
48 static int oce_skyhawk_fwupgrade(POCE_SOFTC sc, const struct firmware *fw);
49 static int  oce_sys_fwupgrade(SYSCTL_HANDLER_ARGS);
50 static int  oce_lancer_fwupgrade(POCE_SOFTC sc, const struct firmware *fw);
51 static int oce_sysctl_sfp_vpd_dump(SYSCTL_HANDLER_ARGS);
52 static boolean_t oce_phy_flashing_required(POCE_SOFTC sc);
53 static boolean_t oce_img_flashing_required(POCE_SOFTC sc, const char *p,
54 				int img_optype, uint32_t img_offset,
55 				uint32_t img_size, uint32_t hdrs_size);
56 static void oce_add_stats_sysctls_be3(POCE_SOFTC sc,
57 				struct sysctl_ctx_list *ctx,
58 				struct sysctl_oid *stats_node);
59 static void oce_add_stats_sysctls_xe201(POCE_SOFTC sc,
60 				struct sysctl_ctx_list *ctx,
61 				struct sysctl_oid *stats_node);
62 
63 
64 extern char component_revision[32];
65 uint32_t sfp_vpd_dump_buffer[TRANSCEIVER_DATA_NUM_ELE];
66 
67 struct flash_img_attri {
68 	int img_offset;
69 	int img_size;
70 	int img_type;
71 	bool skip_image;
72 	int optype;
73 };
74 
75 void
76 oce_add_sysctls(POCE_SOFTC sc)
77 {
78 
79 	struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->dev);
80 	struct sysctl_oid *tree = device_get_sysctl_tree(sc->dev);
81 	struct sysctl_oid_list *child = SYSCTL_CHILDREN(tree);
82 	struct sysctl_oid *stats_node;
83 
84 	SYSCTL_ADD_STRING(ctx, child,
85 			OID_AUTO, "component_revision",
86 			CTLTYPE_INT | CTLFLAG_RD,
87 			&component_revision,
88 			sizeof(component_revision),
89 			"EMULEX One-Connect device driver revision");
90 
91 	SYSCTL_ADD_STRING(ctx, child,
92 			OID_AUTO, "firmware_version",
93 			CTLTYPE_INT | CTLFLAG_RD,
94 			&sc->fw_version,
95 			sizeof(sc->fw_version),
96 			"EMULEX One-Connect Firmware Version");
97 
98 	SYSCTL_ADD_INT(ctx, child,
99 			OID_AUTO, "max_rsp_handled",
100 			CTLTYPE_INT | CTLFLAG_RW,
101 			&oce_max_rsp_handled,
102 			sizeof(oce_max_rsp_handled),
103 			"Maximum receive frames handled per interupt");
104 
105 	if ((sc->function_mode & FNM_FLEX10_MODE) ||
106 	    (sc->function_mode & FNM_UMC_MODE))
107 		SYSCTL_ADD_UINT(ctx, child,
108 				OID_AUTO, "speed",
109 				CTLFLAG_RD,
110 				&sc->qos_link_speed,
111 				0,"QOS Speed");
112 	else
113 		SYSCTL_ADD_UINT(ctx, child,
114 				OID_AUTO, "speed",
115 				CTLFLAG_RD,
116 				&sc->speed,
117 				0,"Link Speed");
118 
119 	if (sc->function_mode & FNM_UMC_MODE)
120 		SYSCTL_ADD_UINT(ctx, child,
121 				OID_AUTO, "pvid",
122 				CTLFLAG_RD,
123 				&sc->pvid,
124 				0,"PVID");
125 
126 	SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "loop_back",
127 		CTLTYPE_INT | CTLFLAG_RW, (void *)sc, 0,
128 		oce_sysctl_loopback, "I", "Loop Back Tests");
129 
130 	SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "fw_upgrade",
131 		CTLTYPE_STRING | CTLFLAG_RW, (void *)sc, 0,
132 		oce_sys_fwupgrade, "A", "Firmware ufi file");
133 
134         /*
135          *  Dumps Transceiver data
136 	 *  "sysctl dev.oce.0.sfp_vpd_dump=0"
137          *  "sysctl -x dev.oce.0.sfp_vpd_dump_buffer" for hex dump
138          *  "sysctl -b dev.oce.0.sfp_vpd_dump_buffer > sfp.bin" for binary dump
139          */
140 	SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "sfp_vpd_dump",
141 			CTLTYPE_INT | CTLFLAG_RW, (void *)sc, 0, oce_sysctl_sfp_vpd_dump,
142 			"I", "Initiate a sfp_vpd_dump operation");
143 	SYSCTL_ADD_OPAQUE(ctx, child, OID_AUTO, "sfp_vpd_dump_buffer",
144 			CTLFLAG_RD, sfp_vpd_dump_buffer,
145 			TRANSCEIVER_DATA_SIZE, "IU", "Access sfp_vpd_dump buffer");
146 
147 	stats_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "stats",
148 				CTLFLAG_RD, NULL, "Ethernet Statistics");
149 
150 	if (IS_BE(sc) || IS_SH(sc))
151 		oce_add_stats_sysctls_be3(sc, ctx, stats_node);
152 	else
153 		oce_add_stats_sysctls_xe201(sc, ctx, stats_node);
154 
155 
156 }
157 
158 
159 static uint32_t
160 oce_loopback_test(struct oce_softc *sc, uint8_t loopback_type)
161 {
162 	uint32_t status = 0;
163 
164 	oce_mbox_cmd_set_loopback(sc, sc->port_id, loopback_type, 1);
165 	status = oce_mbox_cmd_test_loopback(sc, sc->port_id, loopback_type,
166 				1500, 2, 0xabc);
167 	oce_mbox_cmd_set_loopback(sc, sc->port_id, OCE_NO_LOOPBACK, 1);
168 
169 	return status;
170 }
171 
172 static int
173 oce_sysctl_loopback(SYSCTL_HANDLER_ARGS)
174 {
175 	int value = 0;
176 	uint32_t status;
177 	struct oce_softc *sc  = (struct oce_softc *)arg1;
178 
179 	status = sysctl_handle_int(oidp, &value, 0, req);
180 	if (status || !req->newptr)
181 		return status;
182 
183 	if (value != 1) {
184 		device_printf(sc->dev,
185 			"Not a Valid value. Set to loop_back=1 to run tests\n");
186 		return 0;
187 	}
188 
189 	if ((status = oce_loopback_test(sc, OCE_MAC_LOOPBACK))) {
190 		device_printf(sc->dev,
191 			"MAC Loopback Test = Failed (Error status = %d)\n",
192 			 status);
193 	} else
194 		device_printf(sc->dev, "MAC Loopback Test = Success\n");
195 
196 	if ((status = oce_loopback_test(sc, OCE_PHY_LOOPBACK))) {
197 		device_printf(sc->dev,
198 			"PHY Loopback Test = Failed (Error status = %d)\n",
199 			 status);
200 	} else
201 		device_printf(sc->dev, "PHY Loopback Test = Success\n");
202 
203 	if ((status = oce_loopback_test(sc, OCE_ONE_PORT_EXT_LOOPBACK))) {
204 		device_printf(sc->dev,
205 			"EXT Loopback Test = Failed (Error status = %d)\n",
206 			 status);
207 	} else
208 		device_printf(sc->dev, "EXT Loopback Test = Success\n");
209 
210 	return 0;
211 }
212 
213 
214 static int
215 oce_sys_fwupgrade(SYSCTL_HANDLER_ARGS)
216 {
217 	char ufiname[256] = {0};
218 	uint32_t status = 1;
219 	struct oce_softc *sc  = (struct oce_softc *)arg1;
220 	const struct firmware *fw;
221 
222 	status = sysctl_handle_string(oidp, ufiname, sizeof(ufiname), req);
223 	if (status || !req->newptr)
224 		return status;
225 
226 	fw = firmware_get(ufiname);
227 	if (fw == NULL) {
228 		device_printf(sc->dev, "Unable to get Firmware. "
229 			"Make sure %s is copied to /boot/modules\n", ufiname);
230 		return ENOENT;
231 	}
232 
233 	if (IS_BE(sc)) {
234 		if ((sc->flags & OCE_FLAGS_BE2)) {
235 			device_printf(sc->dev,
236 				"Flashing not supported for BE2 yet.\n");
237 			status = 1;
238 			goto done;
239 		}
240 		status = oce_be3_fwupgrade(sc, fw);
241 	} else if (IS_SH(sc)) {
242 		status = oce_skyhawk_fwupgrade(sc,fw);
243 	} else
244 		status = oce_lancer_fwupgrade(sc, fw);
245 done:
246 	if (status) {
247 		device_printf(sc->dev, "Firmware Upgrade failed\n");
248 	} else {
249 		device_printf(sc->dev, "Firmware Flashed successfully\n");
250 	}
251 
252 	/* Release Firmware*/
253 	firmware_put(fw, FIRMWARE_UNLOAD);
254 
255 	return status;
256 }
257 
258 static void oce_fill_flash_img_data(POCE_SOFTC sc, const struct flash_sec_info * fsec,
259 				struct flash_img_attri *pimg, int i,
260 				const struct firmware *fw, int bin_offset)
261 {
262 	if (IS_SH(sc)) {
263 		pimg->img_offset = HOST_32(fsec->fsec_entry[i].offset);
264 		pimg->img_size   = HOST_32(fsec->fsec_entry[i].pad_size);
265 	}
266 
267 	pimg->img_type = HOST_32(fsec->fsec_entry[i].type);
268 	pimg->skip_image = FALSE;
269 	switch (pimg->img_type) {
270 		case IMG_ISCSI:
271 			pimg->optype = 0;
272 			if (IS_BE3(sc)) {
273 				pimg->img_offset = 2097152;
274 				pimg->img_size   = 2097152;
275 			}
276 			break;
277 		case IMG_REDBOOT:
278 			pimg->optype = 1;
279 			if (IS_BE3(sc)) {
280 				pimg->img_offset = 262144;
281 				pimg->img_size   = 1048576;
282 			}
283 			if (!oce_img_flashing_required(sc, fw->data,
284 						pimg->optype,
285 						pimg->img_offset,
286 						pimg->img_size,
287 						bin_offset))
288 				pimg->skip_image = TRUE;
289 			break;
290 		case IMG_BIOS:
291 			pimg->optype = 2;
292 			if (IS_BE3(sc)) {
293 				pimg->img_offset = 12582912;
294 				pimg->img_size   = 524288;
295 			}
296 			break;
297 		case IMG_PXEBIOS:
298 			pimg->optype = 3;
299 			if (IS_BE3(sc)) {
300 				pimg->img_offset =  13107200;;
301 				pimg->img_size   = 524288;
302 			}
303 			break;
304 		case IMG_FCOEBIOS:
305 			pimg->optype = 8;
306 			if (IS_BE3(sc)) {
307 				pimg->img_offset = 13631488;
308 				pimg->img_size   = 524288;
309 			}
310 			break;
311 		case IMG_ISCSI_BAK:
312 			pimg->optype = 9;
313 			if (IS_BE3(sc)) {
314 				pimg->img_offset = 4194304;
315 				pimg->img_size   = 2097152;
316 			}
317 			break;
318 		case IMG_FCOE:
319 			pimg->optype = 10;
320 			if (IS_BE3(sc)) {
321 				pimg->img_offset = 6291456;
322 				pimg->img_size   = 2097152;
323 			}
324 			break;
325 		case IMG_FCOE_BAK:
326 			pimg->optype = 11;
327 			if (IS_BE3(sc)) {
328 				pimg->img_offset = 8388608;
329 				pimg->img_size   = 2097152;
330 			}
331 			break;
332 		case IMG_NCSI:
333 			pimg->optype = 13;
334 			if (IS_BE3(sc)) {
335 				pimg->img_offset = 15990784;
336 				pimg->img_size   = 262144;
337 			}
338 			break;
339 		case IMG_PHY:
340 			pimg->optype = 99;
341 			if (IS_BE3(sc)) {
342 				pimg->img_offset = 1310720;
343 				pimg->img_size   = 262144;
344 			}
345 			if (!oce_phy_flashing_required(sc))
346 				pimg->skip_image = TRUE;
347 			break;
348 		default:
349 			pimg->skip_image = TRUE;
350 			break;
351 	}
352 
353 }
354 
355 static int
356 oce_sh_be3_flashdata(POCE_SOFTC sc, const struct firmware *fw, int32_t num_imgs)
357 {
358 	char cookie[2][16] =    {"*** SE FLAS", "H DIRECTORY *** "};
359 	const char *p = (const char *)fw->data;
360 	const struct flash_sec_info *fsec = NULL;
361 	struct mbx_common_read_write_flashrom *req;
362 	int rc = 0, i, bin_offset = 0, opcode, num_bytes;
363 	OCE_DMA_MEM dma_mem;
364 	struct flash_img_attri imgatt;
365 
366 	/* Validate Cookie */
367 	bin_offset = (sizeof(struct flash_file_hdr) +
368 			(num_imgs * sizeof(struct image_hdr)));
369 	p += bin_offset;
370 	while (p < ((const char *)fw->data + fw->datasize)) {
371 		fsec = (const struct flash_sec_info *)p;
372 		if (!memcmp(cookie, fsec->cookie, sizeof(cookie)))
373 			break;
374 		fsec = NULL;
375 		p += 32;
376 	}
377 
378 	if (!fsec) {
379 		device_printf(sc->dev,
380 				"Invalid Cookie. Firmware image corrupted ?\n");
381 		return EINVAL;
382 	}
383 
384 	rc = oce_dma_alloc(sc, sizeof(struct mbx_common_read_write_flashrom)
385 			+ 32*1024, &dma_mem, 0);
386 	if (rc) {
387 		device_printf(sc->dev,
388 				"Memory allocation failure while flashing\n");
389 		return ENOMEM;
390 	}
391 	req = OCE_DMAPTR(&dma_mem, struct mbx_common_read_write_flashrom);
392 
393 	if (IS_SH(sc))
394 		num_imgs = HOST_32(fsec->fsec_hdr.num_images);
395 	else if (IS_BE3(sc))
396 		num_imgs = MAX_FLASH_COMP;
397 
398 	for (i = 0; i < num_imgs; i++) {
399 
400 		bzero(&imgatt, sizeof(struct flash_img_attri));
401 
402 		oce_fill_flash_img_data(sc, fsec, &imgatt, i, fw, bin_offset);
403 
404 		if (imgatt.skip_image)
405 			continue;
406 
407 		p = fw->data;
408 		p = p + bin_offset + imgatt.img_offset;
409 
410 		if ((p + imgatt.img_size) > ((const char *)fw->data + fw->datasize)) {
411 			rc = 1;
412 			goto ret;
413 		}
414 
415 		while (imgatt.img_size) {
416 
417 			if (imgatt.img_size > 32*1024)
418 				num_bytes = 32*1024;
419 			else
420 				num_bytes = imgatt.img_size;
421 			imgatt.img_size -= num_bytes;
422 
423 			if (!imgatt.img_size)
424 				opcode = FLASHROM_OPER_FLASH;
425 			else
426 				opcode = FLASHROM_OPER_SAVE;
427 
428 			memcpy(req->data_buffer, p, num_bytes);
429 			p += num_bytes;
430 
431 			rc = oce_mbox_write_flashrom(sc, imgatt.optype, opcode,
432 					&dma_mem, num_bytes);
433 			if (rc) {
434 				device_printf(sc->dev,
435 						"cmd to write to flash rom failed.\n");
436 				rc = EIO;
437 				goto ret;
438 			}
439 			/* Leave the CPU for others for some time */
440 			pause("yield", 10);
441 
442 		}
443 
444 	}
445 
446 ret:
447 	oce_dma_free(sc, &dma_mem);
448 	return rc;
449 }
450 
451 #define UFI_TYPE2		2
452 #define UFI_TYPE3		3
453 #define UFI_TYPE3R		10
454 #define UFI_TYPE4		4
455 #define UFI_TYPE4R		11
456 static int oce_get_ufi_type(POCE_SOFTC sc,
457 			    const struct flash_file_hdr *fhdr)
458 {
459 	if (fhdr == NULL)
460 		goto be_get_ufi_exit;
461 
462 	if (IS_SH(sc) && fhdr->build[0] == '4') {
463 		if (fhdr->asic_type_rev >= 0x10)
464 			return UFI_TYPE4R;
465 		else
466 			return UFI_TYPE4;
467 	} else if (IS_BE3(sc) && fhdr->build[0] == '3') {
468 		if (fhdr->asic_type_rev == 0x10)
469 			return UFI_TYPE3R;
470 		else
471 			return UFI_TYPE3;
472 	} else if (IS_BE2(sc) && fhdr->build[0] == '2')
473 		return UFI_TYPE2;
474 
475 be_get_ufi_exit:
476 	device_printf(sc->dev,
477 		"UFI and Interface are not compatible for flashing\n");
478 	return -1;
479 }
480 
481 
482 static int
483 oce_skyhawk_fwupgrade(POCE_SOFTC sc, const struct firmware *fw)
484 {
485 	int rc = 0, num_imgs = 0, i = 0, ufi_type;
486 	const struct flash_file_hdr *fhdr;
487 	const struct image_hdr *img_ptr;
488 
489 	fhdr = (const struct flash_file_hdr *)fw->data;
490 
491 	ufi_type = oce_get_ufi_type(sc, fhdr);
492 
493 	/* Display flash version */
494 	device_printf(sc->dev, "Flashing Firmware %s\n", &fhdr->build[2]);
495 
496 	num_imgs = fhdr->num_imgs;
497 	for (i = 0; i < num_imgs; i++) {
498 		img_ptr = (const struct image_hdr *)((const char *)fw->data +
499 				sizeof(struct flash_file_hdr) +
500 				(i * sizeof(struct image_hdr)));
501 
502 		if (img_ptr->imageid != 1)
503 			continue;
504 
505 		switch (ufi_type) {
506 			case UFI_TYPE4R:
507 				rc = oce_sh_be3_flashdata(sc, fw,
508 						num_imgs);
509 				break;
510 			case UFI_TYPE4:
511 				if (sc->asic_revision < 0x10)
512 					rc = oce_sh_be3_flashdata(sc, fw,
513 								   num_imgs);
514 				else {
515 					rc = -1;
516 					device_printf(sc->dev,
517 						"Cant load SH A0 UFI on B0\n");
518 				}
519 				break;
520 			default:
521 				rc = -1;
522 				break;
523 
524 		}
525 	}
526 
527 	return rc;
528 }
529 
530 static int
531 oce_be3_fwupgrade(POCE_SOFTC sc, const struct firmware *fw)
532 {
533 	int rc = 0, num_imgs = 0, i = 0;
534 	const struct flash_file_hdr *fhdr;
535 	const struct image_hdr *img_ptr;
536 
537 	fhdr = (const struct flash_file_hdr *)fw->data;
538 	if (fhdr->build[0] != '3') {
539 		device_printf(sc->dev, "Invalid BE3 firmware image\n");
540 		return EINVAL;
541 	}
542 	/* Display flash version */
543 	device_printf(sc->dev, "Flashing Firmware %s\n", &fhdr->build[2]);
544 
545 	num_imgs = fhdr->num_imgs;
546 	for (i = 0; i < num_imgs; i++) {
547 		img_ptr = (const struct image_hdr *)((const char *)fw->data +
548 				sizeof(struct flash_file_hdr) +
549 				(i * sizeof(struct image_hdr)));
550 		if (img_ptr->imageid == 1) {
551 			rc = oce_sh_be3_flashdata(sc, fw, num_imgs);
552 
553 			break;
554 		}
555 	}
556 
557 	return rc;
558 }
559 
560 
561 static boolean_t
562 oce_phy_flashing_required(POCE_SOFTC sc)
563 {
564 	int status = 0;
565 	struct oce_phy_info phy_info;
566 
567 	status = oce_mbox_get_phy_info(sc, &phy_info);
568 	if (status)
569 		return FALSE;
570 
571 	if ((phy_info.phy_type == TN_8022) &&
572 		(phy_info.interface_type == PHY_TYPE_BASET_10GB)) {
573 		return TRUE;
574 	}
575 
576 	return FALSE;
577 }
578 
579 
580 static boolean_t
581 oce_img_flashing_required(POCE_SOFTC sc, const char *p,
582 				int img_optype, uint32_t img_offset,
583 				uint32_t img_size, uint32_t hdrs_size)
584 {
585 	uint32_t crc_offset;
586 	uint8_t flashed_crc[4];
587 	int status;
588 
589 	crc_offset = hdrs_size + img_offset + img_size - 4;
590 
591 	p += crc_offset;
592 
593 	status = oce_mbox_get_flashrom_crc(sc, flashed_crc,
594 			(img_size - 4), img_optype);
595 	if (status)
596 		return TRUE; /* Some thing worng. ReFlash */
597 
598 	/*update redboot only if crc does not match*/
599 	if (bcmp(flashed_crc, p, 4))
600 		return TRUE;
601 	else
602 		return FALSE;
603 }
604 
605 
606 static int
607 oce_lancer_fwupgrade(POCE_SOFTC sc, const struct firmware *fw)
608 {
609 
610 	int rc = 0;
611 	OCE_DMA_MEM dma_mem;
612 	const uint8_t *data = NULL;
613 	uint8_t *dest_image_ptr = NULL;
614 	size_t size = 0;
615 	uint32_t data_written = 0, chunk_size = 0;
616 	uint32_t offset = 0, add_status = 0;
617 
618 	if (!IS_ALIGNED(fw->datasize, sizeof(uint32_t))) {
619 		device_printf(sc->dev,
620 			"Lancer FW image is not 4 byte aligned.");
621 		return EINVAL;
622 	}
623 
624 	rc = oce_dma_alloc(sc, 32*1024, &dma_mem, 0);
625 	if (rc) {
626 		device_printf(sc->dev,
627 			"Memory allocation failure while flashing Lancer\n");
628 		return ENOMEM;
629 	}
630 
631 	size = fw->datasize;
632 	data = fw->data;
633 	dest_image_ptr = OCE_DMAPTR(&dma_mem, uint8_t);
634 
635 	while (size) {
636 		chunk_size = MIN(size, (32*1024));
637 
638 		bcopy(data, dest_image_ptr, chunk_size);
639 
640 		rc = oce_mbox_lancer_write_flashrom(sc, chunk_size, offset,
641 				&dma_mem, &data_written, &add_status);
642 
643 		if (rc)
644 			break;
645 
646 		size	-= data_written;
647 		data	+= data_written;
648 		offset	+= data_written;
649 		pause("yield", 10);
650 
651 	}
652 
653 	if (!rc)
654 		/* Commit the firmware*/
655 		rc = oce_mbox_lancer_write_flashrom(sc, 0, offset, &dma_mem,
656 						&data_written, &add_status);
657 	if (rc) {
658 		device_printf(sc->dev, "Lancer firmware load error. "
659 			"Addstatus = 0x%x, status = %d \n", add_status, rc);
660 		rc = EIO;
661 	}
662 	oce_dma_free(sc, &dma_mem);
663 	return rc;
664 
665 }
666 
667 
668 static void
669 oce_add_stats_sysctls_be3(POCE_SOFTC sc,
670 				  struct sysctl_ctx_list *ctx,
671 				  struct sysctl_oid *stats_node)
672 {
673 	struct sysctl_oid *rx_stats_node, *tx_stats_node;
674 	struct sysctl_oid_list *rx_stat_list, *tx_stat_list;
675 	struct sysctl_oid_list *queue_stats_list;
676 	struct sysctl_oid *queue_stats_node;
677 	struct oce_drv_stats *stats;
678 	char prefix[32];
679 	int i;
680 
681 	stats = &sc->oce_stats_info;
682 
683 	rx_stats_node = SYSCTL_ADD_NODE(ctx,
684 					SYSCTL_CHILDREN(stats_node),
685 					OID_AUTO,"rx", CTLFLAG_RD,
686 					NULL, "RX Ethernet Statistics");
687 	rx_stat_list = SYSCTL_CHILDREN(rx_stats_node);
688 
689 
690 	SYSCTL_ADD_QUAD(ctx, rx_stat_list, OID_AUTO, "total_pkts",
691 			CTLFLAG_RD, &stats->rx.t_rx_pkts,
692 			"Total Received Packets");
693 	SYSCTL_ADD_QUAD(ctx, rx_stat_list, OID_AUTO, "total_bytes",
694 			CTLFLAG_RD, &stats->rx.t_rx_bytes,
695 			"Total Received Bytes");
696 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "total_frags",
697 			CTLFLAG_RD, &stats->rx.t_rx_frags, 0,
698 			"Total Received Fragements");
699 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "total_mcast_pkts",
700 			CTLFLAG_RD, &stats->rx.t_rx_mcast_pkts, 0,
701 			"Total Received Multicast Packets");
702 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "total_ucast_pkts",
703 			CTLFLAG_RD, &stats->rx.t_rx_ucast_pkts, 0,
704 			"Total Received Unicast Packets");
705 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "total_rxcp_errs",
706 			CTLFLAG_RD, &stats->rx.t_rxcp_errs, 0,
707 			"Total Receive completion errors");
708 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "pause_frames",
709 			CTLFLAG_RD, &stats->u0.be.rx_pause_frames, 0,
710 			"Pause Frames");
711 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "priority_pause_frames",
712 			CTLFLAG_RD, &stats->u0.be.rx_priority_pause_frames, 0,
713 			"Priority Pause Frames");
714 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "control_frames",
715 			CTLFLAG_RD, &stats->u0.be.rx_control_frames, 0,
716 			"Control Frames");
717 
718 	for (i = 0; i < sc->nrqs; i++) {
719 		sprintf(prefix, "queue%d",i);
720 		queue_stats_node = SYSCTL_ADD_NODE(ctx,
721 						SYSCTL_CHILDREN(rx_stats_node),
722 						OID_AUTO, prefix, CTLFLAG_RD,
723 						NULL, "Queue name");
724 		queue_stats_list = SYSCTL_CHILDREN(queue_stats_node);
725 
726 		SYSCTL_ADD_QUAD(ctx, queue_stats_list, OID_AUTO, "rx_pkts",
727 			CTLFLAG_RD, &sc->rq[i]->rx_stats.rx_pkts,
728 			"Receive Packets");
729 		SYSCTL_ADD_QUAD(ctx, queue_stats_list, OID_AUTO, "rx_bytes",
730 			CTLFLAG_RD, &sc->rq[i]->rx_stats.rx_bytes,
731 			"Recived Bytes");
732 		SYSCTL_ADD_UINT(ctx, queue_stats_list, OID_AUTO, "rx_frags",
733 			CTLFLAG_RD, &sc->rq[i]->rx_stats.rx_frags, 0,
734 			"Received Fragments");
735 		SYSCTL_ADD_UINT(ctx, queue_stats_list, OID_AUTO,
736 				"rx_mcast_pkts", CTLFLAG_RD,
737 				&sc->rq[i]->rx_stats.rx_mcast_pkts, 0,
738 					"Received Multicast Packets");
739 		SYSCTL_ADD_UINT(ctx, queue_stats_list, OID_AUTO,
740 				"rx_ucast_pkts", CTLFLAG_RD,
741 				&sc->rq[i]->rx_stats.rx_ucast_pkts, 0,
742 					"Received Unicast Packets");
743 		SYSCTL_ADD_UINT(ctx, queue_stats_list, OID_AUTO, "rxcp_err",
744 			CTLFLAG_RD, &sc->rq[i]->rx_stats.rxcp_err, 0,
745 			"Received Completion Errors");
746 
747 	}
748 
749 	rx_stats_node = SYSCTL_ADD_NODE(ctx,
750 					SYSCTL_CHILDREN(rx_stats_node),
751 					OID_AUTO, "err", CTLFLAG_RD,
752 					NULL, "Receive Error Stats");
753 	rx_stat_list = SYSCTL_CHILDREN(rx_stats_node);
754 
755 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "crc_errs",
756 			CTLFLAG_RD, &stats->u0.be.rx_crc_errors, 0,
757 			"CRC Errors");
758 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "pbuf_errors",
759 			CTLFLAG_RD, &stats->u0.be.rx_drops_no_pbuf, 0,
760 			"Drops due to pbuf full");
761 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "erx_errors",
762 			CTLFLAG_RD, &stats->u0.be.rx_drops_no_erx_descr, 0,
763 			"ERX Errors");
764 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "alignment_errors",
765 			CTLFLAG_RD, &stats->u0.be.rx_drops_too_many_frags, 0,
766 			"RX Alignmnet Errors");
767 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "in_range_errors",
768 			CTLFLAG_RD, &stats->u0.be.rx_in_range_errors, 0,
769 			"In Range Errors");
770 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "out_range_errors",
771 			CTLFLAG_RD, &stats->u0.be.rx_out_range_errors, 0,
772 			"Out Range Errors");
773 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "frame_too_long",
774 			CTLFLAG_RD, &stats->u0.be.rx_frame_too_long, 0,
775 			"Frame Too Long");
776 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "address_match_errors",
777 			CTLFLAG_RD, &stats->u0.be.rx_address_match_errors, 0,
778 			"Address Match Errors");
779 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "dropped_too_small",
780 			CTLFLAG_RD, &stats->u0.be.rx_dropped_too_small, 0,
781 			"Dropped Too Small");
782 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "dropped_too_short",
783 			CTLFLAG_RD, &stats->u0.be.rx_dropped_too_short, 0,
784 			"Dropped Too Short");
785 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO,
786 			"dropped_header_too_small", CTLFLAG_RD,
787 			&stats->u0.be.rx_dropped_header_too_small, 0,
788 			"Dropped Header Too Small");
789 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "dropped_tcp_length",
790 			CTLFLAG_RD, &stats->u0.be.rx_dropped_tcp_length, 0,
791 			"Dropped TCP Length");
792 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "dropped_runt",
793 			CTLFLAG_RD, &stats->u0.be.rx_dropped_runt, 0,
794 			"Dropped runt");
795 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "ip_checksum_errs",
796 			CTLFLAG_RD, &stats->u0.be.rx_ip_checksum_errs, 0,
797 			"IP Checksum Errors");
798 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "tcp_checksum_errs",
799 			CTLFLAG_RD, &stats->u0.be.rx_tcp_checksum_errs, 0,
800 			"TCP Checksum Errors");
801 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "udp_checksum_errs",
802 			CTLFLAG_RD, &stats->u0.be.rx_udp_checksum_errs, 0,
803 			"UDP Checksum Errors");
804 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "fifo_overflow_drop",
805 			CTLFLAG_RD, &stats->u0.be.rxpp_fifo_overflow_drop, 0,
806 			"FIFO Overflow Drop");
807 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO,
808 			"input_fifo_overflow_drop", CTLFLAG_RD,
809 			&stats->u0.be.rx_input_fifo_overflow_drop, 0,
810 			"Input FIFO Overflow Drop");
811 
812 	tx_stats_node = SYSCTL_ADD_NODE(ctx,
813 					SYSCTL_CHILDREN(stats_node), OID_AUTO,
814 					"tx",CTLFLAG_RD, NULL,
815 					"TX Ethernet Statistics");
816 	tx_stat_list = SYSCTL_CHILDREN(tx_stats_node);
817 
818 	SYSCTL_ADD_QUAD(ctx, tx_stat_list, OID_AUTO, "total_tx_pkts",
819 			CTLFLAG_RD, &stats->tx.t_tx_pkts,
820 			"Total Transmit Packets");
821 	SYSCTL_ADD_QUAD(ctx, tx_stat_list, OID_AUTO, "total_tx_bytes",
822 			CTLFLAG_RD, &stats->tx.t_tx_bytes,
823 			"Total Transmit Bytes");
824 	SYSCTL_ADD_UINT(ctx, tx_stat_list, OID_AUTO, "total_tx_reqs",
825 			CTLFLAG_RD, &stats->tx.t_tx_reqs, 0,
826 			"Total Transmit Requests");
827 	SYSCTL_ADD_UINT(ctx, tx_stat_list, OID_AUTO, "total_tx_stops",
828 			CTLFLAG_RD, &stats->tx.t_tx_stops, 0,
829 			"Total Transmit Stops");
830 	SYSCTL_ADD_UINT(ctx, tx_stat_list, OID_AUTO, "total_tx_wrbs",
831 			CTLFLAG_RD, &stats->tx.t_tx_wrbs, 0,
832 			"Total Transmit WRB's");
833 	SYSCTL_ADD_UINT(ctx, tx_stat_list, OID_AUTO, "total_tx_compl",
834 			CTLFLAG_RD, &stats->tx.t_tx_compl, 0,
835 			"Total Transmit Completions");
836 	SYSCTL_ADD_UINT(ctx, tx_stat_list, OID_AUTO,
837 			"total_ipv6_ext_hdr_tx_drop", CTLFLAG_RD,
838 			&stats->tx.t_ipv6_ext_hdr_tx_drop, 0,
839 			"Total Transmit IPV6 Drops");
840 	SYSCTL_ADD_UINT(ctx, tx_stat_list, OID_AUTO, "pauseframes",
841 			CTLFLAG_RD, &stats->u0.be.tx_pauseframes, 0,
842 			"Pause Frames");
843 	SYSCTL_ADD_UINT(ctx, tx_stat_list, OID_AUTO, "priority_pauseframes",
844 			CTLFLAG_RD, &stats->u0.be.tx_priority_pauseframes, 0,
845 			"Priority Pauseframes");
846 	SYSCTL_ADD_UINT(ctx, tx_stat_list, OID_AUTO, "controlframes",
847 			CTLFLAG_RD, &stats->u0.be.tx_controlframes, 0,
848 			"Tx Control Frames");
849 
850 	for (i = 0; i < sc->nwqs; i++) {
851 		sprintf(prefix, "queue%d",i);
852 		queue_stats_node = SYSCTL_ADD_NODE(ctx,
853 						SYSCTL_CHILDREN(tx_stats_node),
854 						OID_AUTO, prefix, CTLFLAG_RD,
855 						NULL, "Queue name");
856 		queue_stats_list = SYSCTL_CHILDREN(queue_stats_node);
857 
858 		SYSCTL_ADD_QUAD(ctx, queue_stats_list, OID_AUTO, "tx_pkts",
859 			CTLFLAG_RD, &sc->wq[i]->tx_stats.tx_pkts,
860 			"Transmit Packets");
861 		SYSCTL_ADD_QUAD(ctx, queue_stats_list, OID_AUTO, "tx_bytes",
862 			CTLFLAG_RD, &sc->wq[i]->tx_stats.tx_bytes,
863 			"Transmit Bytes");
864 		SYSCTL_ADD_UINT(ctx, queue_stats_list, OID_AUTO, "tx_reqs",
865 			CTLFLAG_RD, &sc->wq[i]->tx_stats.tx_reqs, 0,
866 			"Transmit Requests");
867 		SYSCTL_ADD_UINT(ctx, queue_stats_list, OID_AUTO, "tx_stops",
868 			CTLFLAG_RD, &sc->wq[i]->tx_stats.tx_stops, 0,
869 			"Transmit Stops");
870 		SYSCTL_ADD_UINT(ctx, queue_stats_list, OID_AUTO, "tx_wrbs",
871 			CTLFLAG_RD, &sc->wq[i]->tx_stats.tx_wrbs, 0,
872 			"Transmit WRB's");
873 		SYSCTL_ADD_UINT(ctx, queue_stats_list, OID_AUTO, "tx_compl",
874 			CTLFLAG_RD, &sc->wq[i]->tx_stats.tx_compl, 0,
875 			"Transmit Completions");
876 		SYSCTL_ADD_UINT(ctx, queue_stats_list, OID_AUTO,
877 			"ipv6_ext_hdr_tx_drop",CTLFLAG_RD,
878 			&sc->wq[i]->tx_stats.ipv6_ext_hdr_tx_drop, 0,
879 			"Transmit IPV6 Ext Header Drop");
880 
881 	}
882 	return;
883 }
884 
885 
886 static void
887 oce_add_stats_sysctls_xe201(POCE_SOFTC sc,
888 				  struct sysctl_ctx_list *ctx,
889 				  struct sysctl_oid *stats_node)
890 {
891 	struct sysctl_oid *rx_stats_node, *tx_stats_node;
892 	struct sysctl_oid_list *rx_stat_list, *tx_stat_list;
893 	struct sysctl_oid_list *queue_stats_list;
894 	struct sysctl_oid *queue_stats_node;
895 	struct oce_drv_stats *stats;
896 	char prefix[32];
897 	int i;
898 
899 	stats = &sc->oce_stats_info;
900 
901 	rx_stats_node = SYSCTL_ADD_NODE(ctx,
902 					SYSCTL_CHILDREN(stats_node),
903 					OID_AUTO, "rx", CTLFLAG_RD,
904 					NULL, "RX Ethernet Statistics");
905 	rx_stat_list = SYSCTL_CHILDREN(rx_stats_node);
906 
907 
908 	SYSCTL_ADD_QUAD(ctx, rx_stat_list, OID_AUTO, "total_pkts",
909 			CTLFLAG_RD, &stats->rx.t_rx_pkts,
910 			"Total Received Packets");
911 	SYSCTL_ADD_QUAD(ctx, rx_stat_list, OID_AUTO, "total_bytes",
912 			CTLFLAG_RD, &stats->rx.t_rx_bytes,
913 			"Total Received Bytes");
914 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "total_frags",
915 			CTLFLAG_RD, &stats->rx.t_rx_frags, 0,
916 			"Total Received Fragements");
917 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "total_mcast_pkts",
918 			CTLFLAG_RD, &stats->rx.t_rx_mcast_pkts, 0,
919 			"Total Received Multicast Packets");
920 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "total_ucast_pkts",
921 			CTLFLAG_RD, &stats->rx.t_rx_ucast_pkts, 0,
922 			"Total Received Unicast Packets");
923 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "total_rxcp_errs",
924 			CTLFLAG_RD, &stats->rx.t_rxcp_errs, 0,
925 			"Total Receive completion errors");
926 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "pause_frames",
927 			CTLFLAG_RD, &stats->u0.xe201.rx_pause_frames, 0,
928 			"Pause Frames");
929 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "control_frames",
930 			CTLFLAG_RD, &stats->u0.xe201.rx_control_frames, 0,
931 			"Control Frames");
932 
933 	for (i = 0; i < sc->nrqs; i++) {
934 		sprintf(prefix, "queue%d",i);
935 		queue_stats_node = SYSCTL_ADD_NODE(ctx,
936 						SYSCTL_CHILDREN(rx_stats_node),
937 						OID_AUTO, prefix, CTLFLAG_RD,
938 						NULL, "Queue name");
939 		queue_stats_list = SYSCTL_CHILDREN(queue_stats_node);
940 
941 		SYSCTL_ADD_QUAD(ctx, queue_stats_list, OID_AUTO, "rx_pkts",
942 			CTLFLAG_RD, &sc->rq[i]->rx_stats.rx_pkts,
943 			"Receive Packets");
944 		SYSCTL_ADD_QUAD(ctx, queue_stats_list, OID_AUTO, "rx_bytes",
945 			CTLFLAG_RD, &sc->rq[i]->rx_stats.rx_bytes,
946 			"Recived Bytes");
947 		SYSCTL_ADD_UINT(ctx, queue_stats_list, OID_AUTO, "rx_frags",
948 			CTLFLAG_RD, &sc->rq[i]->rx_stats.rx_frags, 0,
949 			"Received Fragments");
950 		SYSCTL_ADD_UINT(ctx, queue_stats_list, OID_AUTO,
951 			"rx_mcast_pkts", CTLFLAG_RD,
952 			&sc->rq[i]->rx_stats.rx_mcast_pkts, 0,
953 			"Received Multicast Packets");
954 		SYSCTL_ADD_UINT(ctx, queue_stats_list, OID_AUTO,
955 			"rx_ucast_pkts",CTLFLAG_RD,
956 			&sc->rq[i]->rx_stats.rx_ucast_pkts, 0,
957 			"Received Unicast Packets");
958 		SYSCTL_ADD_UINT(ctx, queue_stats_list, OID_AUTO, "rxcp_err",
959 			CTLFLAG_RD, &sc->rq[i]->rx_stats.rxcp_err, 0,
960 			"Received Completion Errors");
961 
962 	}
963 
964 	rx_stats_node = SYSCTL_ADD_NODE(ctx,
965 					SYSCTL_CHILDREN(rx_stats_node),
966 					OID_AUTO, "err", CTLFLAG_RD,
967 					NULL, "Receive Error Stats");
968 	rx_stat_list = SYSCTL_CHILDREN(rx_stats_node);
969 
970 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "crc_errs",
971 			CTLFLAG_RD, &stats->u0.xe201.rx_crc_errors, 0,
972 			"CRC Errors");
973 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "alignment_errors",
974 			CTLFLAG_RD, &stats->u0.xe201.rx_alignment_errors, 0,
975 			"RX Alignmnet Errors");
976 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "in_range_errors",
977 			CTLFLAG_RD, &stats->u0.xe201.rx_in_range_errors, 0,
978 			"In Range Errors");
979 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "out_range_errors",
980 			CTLFLAG_RD, &stats->u0.xe201.rx_out_of_range_errors, 0,
981 			"Out Range Errors");
982 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "frame_too_long",
983 			CTLFLAG_RD, &stats->u0.xe201.rx_frames_too_long, 0,
984 			"Frame Too Long");
985 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "address_match_errors",
986 			CTLFLAG_RD, &stats->u0.xe201.rx_address_match_errors, 0,
987 			"Address Match Errors");
988 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "dropped_too_small",
989 			CTLFLAG_RD, &stats->u0.xe201.rx_dropped_too_small, 0,
990 			"Dropped Too Small");
991 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "dropped_too_short",
992 			CTLFLAG_RD, &stats->u0.xe201.rx_dropped_too_short, 0,
993 			"Dropped Too Short");
994 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO,
995 			"dropped_header_too_small", CTLFLAG_RD,
996 			&stats->u0.xe201.rx_dropped_header_too_small, 0,
997 			"Dropped Header Too Small");
998 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO,
999 			"dropped_tcp_length", CTLFLAG_RD,
1000 			&stats->u0.xe201.rx_dropped_invalid_tcp_length, 0,
1001 			"Dropped TCP Length");
1002 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "dropped_runt",
1003 			CTLFLAG_RD, &stats->u0.xe201.rx_dropped_runt, 0,
1004 			"Dropped runt");
1005 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "ip_checksum_errs",
1006 			CTLFLAG_RD, &stats->u0.xe201.rx_ip_checksum_errors, 0,
1007 			"IP Checksum Errors");
1008 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "tcp_checksum_errs",
1009 			CTLFLAG_RD, &stats->u0.xe201.rx_tcp_checksum_errors, 0,
1010 			"TCP Checksum Errors");
1011 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "udp_checksum_errs",
1012 			CTLFLAG_RD, &stats->u0.xe201.rx_udp_checksum_errors, 0,
1013 			"UDP Checksum Errors");
1014 	SYSCTL_ADD_UINT(ctx, rx_stat_list, OID_AUTO, "input_fifo_overflow_drop",
1015 			CTLFLAG_RD, &stats->u0.xe201.rx_fifo_overflow, 0,
1016 			"Input FIFO Overflow Drop");
1017 
1018 	tx_stats_node = SYSCTL_ADD_NODE(ctx,
1019 					SYSCTL_CHILDREN(stats_node),
1020 					OID_AUTO, "tx", CTLFLAG_RD,
1021 					NULL, "TX Ethernet Statistics");
1022 	tx_stat_list = SYSCTL_CHILDREN(tx_stats_node);
1023 
1024 	SYSCTL_ADD_QUAD(ctx, tx_stat_list, OID_AUTO, "total_tx_pkts",
1025 			CTLFLAG_RD, &stats->tx.t_tx_pkts,
1026 			"Total Transmit Packets");
1027 	SYSCTL_ADD_QUAD(ctx, tx_stat_list, OID_AUTO, "total_tx_bytes",
1028 			CTLFLAG_RD, &stats->tx.t_tx_bytes,
1029 			"Total Transmit Bytes");
1030 	SYSCTL_ADD_UINT(ctx, tx_stat_list, OID_AUTO, "total_tx_reqs",
1031 			CTLFLAG_RD, &stats->tx.t_tx_reqs, 0,
1032 			"Total Transmit Requests");
1033 	SYSCTL_ADD_UINT(ctx, tx_stat_list, OID_AUTO, "total_tx_stops",
1034 			CTLFLAG_RD, &stats->tx.t_tx_stops, 0,
1035 			"Total Transmit Stops");
1036 	SYSCTL_ADD_UINT(ctx, tx_stat_list, OID_AUTO, "total_tx_wrbs",
1037 			CTLFLAG_RD, &stats->tx.t_tx_wrbs, 0,
1038 			"Total Transmit WRB's");
1039 	SYSCTL_ADD_UINT(ctx, tx_stat_list, OID_AUTO, "total_tx_compl",
1040 			CTLFLAG_RD, &stats->tx.t_tx_compl, 0,
1041 			"Total Transmit Completions");
1042 	SYSCTL_ADD_UINT(ctx, tx_stat_list, OID_AUTO,
1043 			"total_ipv6_ext_hdr_tx_drop",
1044 			CTLFLAG_RD, &stats->tx.t_ipv6_ext_hdr_tx_drop, 0,
1045 			"Total Transmit IPV6 Drops");
1046 	SYSCTL_ADD_UINT(ctx, tx_stat_list, OID_AUTO, "pauseframes",
1047 			CTLFLAG_RD, &stats->u0.xe201.tx_pause_frames, 0,
1048 			"Pause Frames");
1049 	SYSCTL_ADD_UINT(ctx, tx_stat_list, OID_AUTO, "controlframes",
1050 			CTLFLAG_RD, &stats->u0.xe201.tx_control_frames, 0,
1051 			"Tx Control Frames");
1052 
1053 	for (i = 0; i < sc->nwqs; i++) {
1054 		sprintf(prefix, "queue%d",i);
1055 		queue_stats_node = SYSCTL_ADD_NODE(ctx,
1056 						SYSCTL_CHILDREN(tx_stats_node),
1057 						OID_AUTO, prefix, CTLFLAG_RD,
1058 						NULL, "Queue name");
1059 		queue_stats_list = SYSCTL_CHILDREN(queue_stats_node);
1060 
1061 		SYSCTL_ADD_QUAD(ctx, queue_stats_list, OID_AUTO, "tx_pkts",
1062 			CTLFLAG_RD, &sc->wq[i]->tx_stats.tx_pkts,
1063 			"Transmit Packets");
1064 		SYSCTL_ADD_QUAD(ctx, queue_stats_list, OID_AUTO, "tx_bytes",
1065 			CTLFLAG_RD, &sc->wq[i]->tx_stats.tx_bytes,
1066 			"Transmit Bytes");
1067 		SYSCTL_ADD_UINT(ctx, queue_stats_list, OID_AUTO, "tx_reqs",
1068 			CTLFLAG_RD, &sc->wq[i]->tx_stats.tx_reqs, 0,
1069 			"Transmit Requests");
1070 		SYSCTL_ADD_UINT(ctx, queue_stats_list, OID_AUTO, "tx_stops",
1071 			CTLFLAG_RD, &sc->wq[i]->tx_stats.tx_stops, 0,
1072 			"Transmit Stops");
1073 		SYSCTL_ADD_UINT(ctx, queue_stats_list, OID_AUTO, "tx_wrbs",
1074 			CTLFLAG_RD, &sc->wq[i]->tx_stats.tx_wrbs, 0,
1075 			"Transmit WRB's");
1076 		SYSCTL_ADD_UINT(ctx, queue_stats_list, OID_AUTO, "tx_compl",
1077 			CTLFLAG_RD, &sc->wq[i]->tx_stats.tx_compl, 0,
1078 			"Transmit Completions");
1079 		SYSCTL_ADD_UINT(ctx, queue_stats_list, OID_AUTO,
1080 			"ipv6_ext_hdr_tx_drop", CTLFLAG_RD,
1081 			&sc->wq[i]->tx_stats.ipv6_ext_hdr_tx_drop, 0,
1082 			"Transmit IPV6 Ext Header Drop");
1083 
1084 	}
1085 	return;
1086 }
1087 
1088 
1089 void
1090 oce_refresh_queue_stats(POCE_SOFTC sc)
1091 {
1092 	struct oce_drv_stats *adapter_stats;
1093 	int i;
1094 
1095 	adapter_stats = &sc->oce_stats_info;
1096 
1097 	/* Caluculate total TX and TXstats from all queues */
1098 
1099 	bzero(&adapter_stats->rx, sizeof(struct oce_rx_stats));
1100 	for (i = 0; i < sc->nrqs; i++) {
1101 
1102 		adapter_stats->rx.t_rx_pkts += sc->rq[i]->rx_stats.rx_pkts;
1103 		adapter_stats->rx.t_rx_bytes += sc->rq[i]->rx_stats.rx_bytes;
1104 		adapter_stats->rx.t_rx_frags += sc->rq[i]->rx_stats.rx_frags;
1105 		adapter_stats->rx.t_rx_mcast_pkts +=
1106 					sc->rq[i]->rx_stats.rx_mcast_pkts;
1107 		adapter_stats->rx.t_rx_ucast_pkts +=
1108 					sc->rq[i]->rx_stats.rx_ucast_pkts;
1109 		adapter_stats->rx.t_rxcp_errs += sc-> rq[i]->rx_stats.rxcp_err;
1110 	}
1111 
1112 	bzero(&adapter_stats->tx, sizeof(struct oce_tx_stats));
1113 	for (i = 0; i < sc->nwqs; i++) {
1114 		adapter_stats->tx.t_tx_reqs += sc->wq[i]->tx_stats.tx_reqs;
1115 		adapter_stats->tx.t_tx_stops += sc->wq[i]->tx_stats.tx_stops;
1116 		adapter_stats->tx.t_tx_wrbs += sc->wq[i]->tx_stats.tx_wrbs;
1117 		adapter_stats->tx.t_tx_compl += sc->wq[i]->tx_stats.tx_compl;
1118 		adapter_stats->tx.t_tx_bytes += sc->wq[i]->tx_stats.tx_bytes;
1119 		adapter_stats->tx.t_tx_pkts += sc->wq[i]->tx_stats.tx_pkts;
1120 		adapter_stats->tx.t_ipv6_ext_hdr_tx_drop +=
1121 				sc->wq[i]->tx_stats.ipv6_ext_hdr_tx_drop;
1122 	}
1123 
1124 }
1125 
1126 
1127 
1128 static void
1129 copy_stats_to_sc_xe201(POCE_SOFTC sc)
1130 {
1131 	struct oce_xe201_stats *adapter_stats;
1132 	struct mbx_get_pport_stats *nic_mbx;
1133 	struct pport_stats *port_stats;
1134 
1135 	nic_mbx = OCE_DMAPTR(&sc->stats_mem, struct mbx_get_pport_stats);
1136 	port_stats = &nic_mbx->params.rsp.pps;
1137 	adapter_stats = &sc->oce_stats_info.u0.xe201;
1138 
1139 	adapter_stats->tx_pkts = port_stats->tx_pkts;
1140 	adapter_stats->tx_unicast_pkts = port_stats->tx_unicast_pkts;
1141 	adapter_stats->tx_multicast_pkts = port_stats->tx_multicast_pkts;
1142 	adapter_stats->tx_broadcast_pkts = port_stats->tx_broadcast_pkts;
1143 	adapter_stats->tx_bytes = port_stats->tx_bytes;
1144 	adapter_stats->tx_unicast_bytes = port_stats->tx_unicast_bytes;
1145 	adapter_stats->tx_multicast_bytes = port_stats->tx_multicast_bytes;
1146 	adapter_stats->tx_broadcast_bytes = port_stats->tx_broadcast_bytes;
1147 	adapter_stats->tx_discards = port_stats->tx_discards;
1148 	adapter_stats->tx_errors = port_stats->tx_errors;
1149 	adapter_stats->tx_pause_frames = port_stats->tx_pause_frames;
1150 	adapter_stats->tx_pause_on_frames = port_stats->tx_pause_on_frames;
1151 	adapter_stats->tx_pause_off_frames = port_stats->tx_pause_off_frames;
1152 	adapter_stats->tx_internal_mac_errors =
1153 		port_stats->tx_internal_mac_errors;
1154 	adapter_stats->tx_control_frames = port_stats->tx_control_frames;
1155 	adapter_stats->tx_pkts_64_bytes = port_stats->tx_pkts_64_bytes;
1156 	adapter_stats->tx_pkts_65_to_127_bytes =
1157 		port_stats->tx_pkts_65_to_127_bytes;
1158 	adapter_stats->tx_pkts_128_to_255_bytes =
1159 		port_stats->tx_pkts_128_to_255_bytes;
1160 	adapter_stats->tx_pkts_256_to_511_bytes =
1161 		port_stats->tx_pkts_256_to_511_bytes;
1162 	adapter_stats->tx_pkts_512_to_1023_bytes =
1163 		port_stats->tx_pkts_512_to_1023_bytes;
1164 	adapter_stats->tx_pkts_1024_to_1518_bytes =
1165 		port_stats->tx_pkts_1024_to_1518_bytes;
1166 	adapter_stats->tx_pkts_1519_to_2047_bytes =
1167 		port_stats->tx_pkts_1519_to_2047_bytes;
1168 	adapter_stats->tx_pkts_2048_to_4095_bytes =
1169 		port_stats->tx_pkts_2048_to_4095_bytes;
1170 	adapter_stats->tx_pkts_4096_to_8191_bytes =
1171 		port_stats->tx_pkts_4096_to_8191_bytes;
1172 	adapter_stats->tx_pkts_8192_to_9216_bytes =
1173 		port_stats->tx_pkts_8192_to_9216_bytes;
1174 	adapter_stats->tx_lso_pkts = port_stats->tx_lso_pkts;
1175 	adapter_stats->rx_pkts = port_stats->rx_pkts;
1176 	adapter_stats->rx_unicast_pkts = port_stats->rx_unicast_pkts;
1177 	adapter_stats->rx_multicast_pkts = port_stats->rx_multicast_pkts;
1178 	adapter_stats->rx_broadcast_pkts = port_stats->rx_broadcast_pkts;
1179 	adapter_stats->rx_bytes = port_stats->rx_bytes;
1180 	adapter_stats->rx_unicast_bytes = port_stats->rx_unicast_bytes;
1181 	adapter_stats->rx_multicast_bytes = port_stats->rx_multicast_bytes;
1182 	adapter_stats->rx_broadcast_bytes = port_stats->rx_broadcast_bytes;
1183 	adapter_stats->rx_unknown_protos = port_stats->rx_unknown_protos;
1184 	adapter_stats->rx_discards = port_stats->rx_discards;
1185 	adapter_stats->rx_errors = port_stats->rx_errors;
1186 	adapter_stats->rx_crc_errors = port_stats->rx_crc_errors;
1187 	adapter_stats->rx_alignment_errors = port_stats->rx_alignment_errors;
1188 	adapter_stats->rx_symbol_errors = port_stats->rx_symbol_errors;
1189 	adapter_stats->rx_pause_frames = port_stats->rx_pause_frames;
1190 	adapter_stats->rx_pause_on_frames = port_stats->rx_pause_on_frames;
1191 	adapter_stats->rx_pause_off_frames = port_stats->rx_pause_off_frames;
1192 	adapter_stats->rx_frames_too_long = port_stats->rx_frames_too_long;
1193 	adapter_stats->rx_internal_mac_errors =
1194 		port_stats->rx_internal_mac_errors;
1195 	adapter_stats->rx_undersize_pkts = port_stats->rx_undersize_pkts;
1196 	adapter_stats->rx_oversize_pkts = port_stats->rx_oversize_pkts;
1197 	adapter_stats->rx_fragment_pkts = port_stats->rx_fragment_pkts;
1198 	adapter_stats->rx_jabbers = port_stats->rx_jabbers;
1199 	adapter_stats->rx_control_frames = port_stats->rx_control_frames;
1200 	adapter_stats->rx_control_frames_unknown_opcode =
1201 		port_stats->rx_control_frames_unknown_opcode;
1202 	adapter_stats->rx_in_range_errors = port_stats->rx_in_range_errors;
1203 	adapter_stats->rx_out_of_range_errors =
1204 		port_stats->rx_out_of_range_errors;
1205 	adapter_stats->rx_address_match_errors =
1206 		port_stats->rx_address_match_errors;
1207 	adapter_stats->rx_vlan_mismatch_errors =
1208 		port_stats->rx_vlan_mismatch_errors;
1209 	adapter_stats->rx_dropped_too_small = port_stats->rx_dropped_too_small;
1210 	adapter_stats->rx_dropped_too_short = port_stats->rx_dropped_too_short;
1211 	adapter_stats->rx_dropped_header_too_small =
1212 		port_stats->rx_dropped_header_too_small;
1213 	adapter_stats->rx_dropped_invalid_tcp_length =
1214 		port_stats->rx_dropped_invalid_tcp_length;
1215 	adapter_stats->rx_dropped_runt = port_stats->rx_dropped_runt;
1216 	adapter_stats->rx_ip_checksum_errors =
1217 		port_stats->rx_ip_checksum_errors;
1218 	adapter_stats->rx_tcp_checksum_errors =
1219 		port_stats->rx_tcp_checksum_errors;
1220 	adapter_stats->rx_udp_checksum_errors =
1221 		port_stats->rx_udp_checksum_errors;
1222 	adapter_stats->rx_non_rss_pkts = port_stats->rx_non_rss_pkts;
1223 	adapter_stats->rx_ipv4_pkts = port_stats->rx_ipv4_pkts;
1224 	adapter_stats->rx_ipv6_pkts = port_stats->rx_ipv6_pkts;
1225 	adapter_stats->rx_ipv4_bytes = port_stats->rx_ipv4_bytes;
1226 	adapter_stats->rx_ipv6_bytes = port_stats->rx_ipv6_bytes;
1227 	adapter_stats->rx_nic_pkts = port_stats->rx_nic_pkts;
1228 	adapter_stats->rx_tcp_pkts = port_stats->rx_tcp_pkts;
1229 	adapter_stats->rx_iscsi_pkts = port_stats->rx_iscsi_pkts;
1230 	adapter_stats->rx_management_pkts = port_stats->rx_management_pkts;
1231 	adapter_stats->rx_switched_unicast_pkts =
1232 		port_stats->rx_switched_unicast_pkts;
1233 	adapter_stats->rx_switched_multicast_pkts =
1234 		port_stats->rx_switched_multicast_pkts;
1235 	adapter_stats->rx_switched_broadcast_pkts =
1236 		port_stats->rx_switched_broadcast_pkts;
1237 	adapter_stats->num_forwards = port_stats->num_forwards;
1238 	adapter_stats->rx_fifo_overflow = port_stats->rx_fifo_overflow;
1239 	adapter_stats->rx_input_fifo_overflow =
1240 		port_stats->rx_input_fifo_overflow;
1241 	adapter_stats->rx_drops_too_many_frags =
1242 		port_stats->rx_drops_too_many_frags;
1243 	adapter_stats->rx_drops_invalid_queue =
1244 		port_stats->rx_drops_invalid_queue;
1245 	adapter_stats->rx_drops_mtu = port_stats->rx_drops_mtu;
1246 	adapter_stats->rx_pkts_64_bytes = port_stats->rx_pkts_64_bytes;
1247 	adapter_stats->rx_pkts_65_to_127_bytes =
1248 		port_stats->rx_pkts_65_to_127_bytes;
1249 	adapter_stats->rx_pkts_128_to_255_bytes =
1250 		port_stats->rx_pkts_128_to_255_bytes;
1251 	adapter_stats->rx_pkts_256_to_511_bytes =
1252 		port_stats->rx_pkts_256_to_511_bytes;
1253 	adapter_stats->rx_pkts_512_to_1023_bytes =
1254 		port_stats->rx_pkts_512_to_1023_bytes;
1255 	adapter_stats->rx_pkts_1024_to_1518_bytes =
1256 		port_stats->rx_pkts_1024_to_1518_bytes;
1257 	adapter_stats->rx_pkts_1519_to_2047_bytes =
1258 		port_stats->rx_pkts_1519_to_2047_bytes;
1259 	adapter_stats->rx_pkts_2048_to_4095_bytes =
1260 		port_stats->rx_pkts_2048_to_4095_bytes;
1261 	adapter_stats->rx_pkts_4096_to_8191_bytes =
1262 		port_stats->rx_pkts_4096_to_8191_bytes;
1263 	adapter_stats->rx_pkts_8192_to_9216_bytes =
1264 		port_stats->rx_pkts_8192_to_9216_bytes;
1265 }
1266 
1267 
1268 
1269 static void
1270 copy_stats_to_sc_be2(POCE_SOFTC sc)
1271 {
1272 	struct oce_be_stats *adapter_stats;
1273 	struct oce_pmem_stats *pmem;
1274 	struct oce_rxf_stats_v0 *rxf_stats;
1275 	struct oce_port_rxf_stats_v0 *port_stats;
1276 	struct mbx_get_nic_stats_v0 *nic_mbx;
1277 	uint32_t port = sc->port_id;
1278 
1279 	nic_mbx = OCE_DMAPTR(&sc->stats_mem, struct mbx_get_nic_stats_v0);
1280 	pmem = &nic_mbx->params.rsp.stats.pmem;
1281 	rxf_stats = &nic_mbx->params.rsp.stats.rxf;
1282 	port_stats = &nic_mbx->params.rsp.stats.rxf.port[port];
1283 
1284 	adapter_stats = &sc->oce_stats_info.u0.be;
1285 
1286 
1287 	/* Update stats */
1288 	adapter_stats->rx_pause_frames = port_stats->rx_pause_frames;
1289 	adapter_stats->rx_crc_errors = port_stats->rx_crc_errors;
1290 	adapter_stats->rx_control_frames = port_stats->rx_control_frames;
1291 	adapter_stats->rx_in_range_errors = port_stats->rx_in_range_errors;
1292 	adapter_stats->rx_frame_too_long = port_stats->rx_frame_too_long;
1293 	adapter_stats->rx_dropped_runt = port_stats->rx_dropped_runt;
1294 	adapter_stats->rx_ip_checksum_errs = port_stats->rx_ip_checksum_errs;
1295 	adapter_stats->rx_tcp_checksum_errs = port_stats->rx_tcp_checksum_errs;
1296 	adapter_stats->rx_udp_checksum_errs = port_stats->rx_udp_checksum_errs;
1297 	adapter_stats->rxpp_fifo_overflow_drop =
1298 					port_stats->rxpp_fifo_overflow_drop;
1299 	adapter_stats->rx_dropped_tcp_length =
1300 		port_stats->rx_dropped_tcp_length;
1301 	adapter_stats->rx_dropped_too_small = port_stats->rx_dropped_too_small;
1302 	adapter_stats->rx_dropped_too_short = port_stats->rx_dropped_too_short;
1303 	adapter_stats->rx_out_range_errors = port_stats->rx_out_range_errors;
1304 	adapter_stats->rx_dropped_header_too_small =
1305 		port_stats->rx_dropped_header_too_small;
1306 	adapter_stats->rx_input_fifo_overflow_drop =
1307 		port_stats->rx_input_fifo_overflow_drop;
1308 	adapter_stats->rx_address_match_errors =
1309 		port_stats->rx_address_match_errors;
1310 	adapter_stats->rx_alignment_symbol_errors =
1311 		port_stats->rx_alignment_symbol_errors;
1312 	adapter_stats->tx_pauseframes = port_stats->tx_pauseframes;
1313 	adapter_stats->tx_controlframes = port_stats->tx_controlframes;
1314 
1315 	if (sc->if_id)
1316 		adapter_stats->jabber_events = rxf_stats->port1_jabber_events;
1317 	else
1318 		adapter_stats->jabber_events = rxf_stats->port0_jabber_events;
1319 
1320 	adapter_stats->rx_drops_no_pbuf = rxf_stats->rx_drops_no_pbuf;
1321 	adapter_stats->rx_drops_no_txpb = rxf_stats->rx_drops_no_txpb;
1322 	adapter_stats->rx_drops_no_erx_descr = rxf_stats->rx_drops_no_erx_descr;
1323 	adapter_stats->rx_drops_invalid_ring = rxf_stats->rx_drops_invalid_ring;
1324 	adapter_stats->forwarded_packets = rxf_stats->forwarded_packets;
1325 	adapter_stats->rx_drops_mtu = rxf_stats->rx_drops_mtu;
1326 	adapter_stats->rx_drops_no_tpre_descr =
1327 		rxf_stats->rx_drops_no_tpre_descr;
1328 	adapter_stats->rx_drops_too_many_frags =
1329 		rxf_stats->rx_drops_too_many_frags;
1330 	adapter_stats->eth_red_drops = pmem->eth_red_drops;
1331 }
1332 
1333 
1334 static void
1335 copy_stats_to_sc_be3(POCE_SOFTC sc)
1336 {
1337 	struct oce_be_stats *adapter_stats;
1338 	struct oce_pmem_stats *pmem;
1339 	struct oce_rxf_stats_v1 *rxf_stats;
1340 	struct oce_port_rxf_stats_v1 *port_stats;
1341 	struct mbx_get_nic_stats *nic_mbx;
1342 	uint32_t port = sc->port_id;
1343 
1344 	nic_mbx = OCE_DMAPTR(&sc->stats_mem, struct mbx_get_nic_stats);
1345 	pmem = &nic_mbx->params.rsp.stats.pmem;
1346 	rxf_stats = &nic_mbx->params.rsp.stats.rxf;
1347 	port_stats = &nic_mbx->params.rsp.stats.rxf.port[port];
1348 
1349 	adapter_stats = &sc->oce_stats_info.u0.be;
1350 
1351 	/* Update stats */
1352 	adapter_stats->pmem_fifo_overflow_drop =
1353 		port_stats->pmem_fifo_overflow_drop;
1354 	adapter_stats->rx_priority_pause_frames =
1355 		port_stats->rx_priority_pause_frames;
1356 	adapter_stats->rx_pause_frames = port_stats->rx_pause_frames;
1357 	adapter_stats->rx_crc_errors = port_stats->rx_crc_errors;
1358 	adapter_stats->rx_control_frames = port_stats->rx_control_frames;
1359 	adapter_stats->rx_in_range_errors = port_stats->rx_in_range_errors;
1360 	adapter_stats->rx_frame_too_long = port_stats->rx_frame_too_long;
1361 	adapter_stats->rx_dropped_runt = port_stats->rx_dropped_runt;
1362 	adapter_stats->rx_ip_checksum_errs = port_stats->rx_ip_checksum_errs;
1363 	adapter_stats->rx_tcp_checksum_errs = port_stats->rx_tcp_checksum_errs;
1364 	adapter_stats->rx_udp_checksum_errs = port_stats->rx_udp_checksum_errs;
1365 	adapter_stats->rx_dropped_tcp_length =
1366 		port_stats->rx_dropped_tcp_length;
1367 	adapter_stats->rx_dropped_too_small = port_stats->rx_dropped_too_small;
1368 	adapter_stats->rx_dropped_too_short = port_stats->rx_dropped_too_short;
1369 	adapter_stats->rx_out_range_errors = port_stats->rx_out_range_errors;
1370 	adapter_stats->rx_dropped_header_too_small =
1371 		port_stats->rx_dropped_header_too_small;
1372 	adapter_stats->rx_input_fifo_overflow_drop =
1373 		port_stats->rx_input_fifo_overflow_drop;
1374 	adapter_stats->rx_address_match_errors =
1375 		port_stats->rx_address_match_errors;
1376 	adapter_stats->rx_alignment_symbol_errors =
1377 		port_stats->rx_alignment_symbol_errors;
1378 	adapter_stats->rxpp_fifo_overflow_drop =
1379 		port_stats->rxpp_fifo_overflow_drop;
1380 	adapter_stats->tx_pauseframes = port_stats->tx_pauseframes;
1381 	adapter_stats->tx_controlframes = port_stats->tx_controlframes;
1382 	adapter_stats->jabber_events = port_stats->jabber_events;
1383 
1384 	adapter_stats->rx_drops_no_pbuf = rxf_stats->rx_drops_no_pbuf;
1385 	adapter_stats->rx_drops_no_txpb = rxf_stats->rx_drops_no_txpb;
1386 	adapter_stats->rx_drops_no_erx_descr = rxf_stats->rx_drops_no_erx_descr;
1387 	adapter_stats->rx_drops_invalid_ring = rxf_stats->rx_drops_invalid_ring;
1388 	adapter_stats->forwarded_packets = rxf_stats->forwarded_packets;
1389 	adapter_stats->rx_drops_mtu = rxf_stats->rx_drops_mtu;
1390 	adapter_stats->rx_drops_no_tpre_descr =
1391 		rxf_stats->rx_drops_no_tpre_descr;
1392 	adapter_stats->rx_drops_too_many_frags =
1393 		rxf_stats->rx_drops_too_many_frags;
1394 
1395 	adapter_stats->eth_red_drops = pmem->eth_red_drops;
1396 }
1397 
1398 
1399 int
1400 oce_stats_init(POCE_SOFTC sc)
1401 {
1402 	int rc = 0, sz;
1403 
1404 	if (IS_BE(sc) || IS_SH(sc)) {
1405 		if (sc->flags & OCE_FLAGS_BE2)
1406 			sz = sizeof(struct mbx_get_nic_stats_v0);
1407 		else
1408 			sz = sizeof(struct mbx_get_nic_stats);
1409 	} else
1410 		sz = sizeof(struct mbx_get_pport_stats);
1411 
1412 	rc = oce_dma_alloc(sc, sz, &sc->stats_mem, 0);
1413 
1414 	return rc;
1415 }
1416 
1417 
1418 void
1419 oce_stats_free(POCE_SOFTC sc)
1420 {
1421 
1422 	oce_dma_free(sc, &sc->stats_mem);
1423 
1424 }
1425 
1426 
1427 int
1428 oce_refresh_nic_stats(POCE_SOFTC sc)
1429 {
1430 	int rc = 0, reset = 0;
1431 
1432 	if (IS_BE(sc) || IS_SH(sc)) {
1433 		if (sc->flags & OCE_FLAGS_BE2) {
1434 			rc = oce_mbox_get_nic_stats_v0(sc, &sc->stats_mem);
1435 			if (!rc)
1436 				copy_stats_to_sc_be2(sc);
1437 		} else {
1438 			rc = oce_mbox_get_nic_stats(sc, &sc->stats_mem);
1439 			if (!rc)
1440 				copy_stats_to_sc_be3(sc);
1441 		}
1442 
1443 	} else {
1444 		rc = oce_mbox_get_pport_stats(sc, &sc->stats_mem, reset);
1445 		if (!rc)
1446 			copy_stats_to_sc_xe201(sc);
1447 	}
1448 
1449 	return rc;
1450 }
1451 
1452 static int
1453 oce_sysctl_sfp_vpd_dump(SYSCTL_HANDLER_ARGS)
1454 {
1455 	int result = 0, error;
1456 	int rc = 0;
1457 	POCE_SOFTC sc = (POCE_SOFTC) arg1;
1458 
1459 	/* sysctl default handler */
1460 	error = sysctl_handle_int(oidp, &result, 0, req);
1461 	if (error || !req->newptr)
1462 		return (error);
1463 
1464 	if(result == -1) {
1465 		return EINVAL;
1466 	}
1467 	bzero((char *)sfp_vpd_dump_buffer, TRANSCEIVER_DATA_SIZE);
1468 
1469 	rc = oce_mbox_read_transrecv_data(sc, PAGE_NUM_A0);
1470 	if(rc)
1471 		return rc;
1472 
1473 	rc = oce_mbox_read_transrecv_data(sc, PAGE_NUM_A2);
1474 	if(rc)
1475 		return rc;
1476 
1477 	return rc;
1478 }
1479