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