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