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