xref: /titanic_51/usr/src/uts/common/io/bge/bge_kstats.c (revision 06e46062ef4f5f4b687cbafb4518fb123fe23920)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include "sys/bge_impl.h"
30 
31 #define	BGE_DBG		BGE_DBG_STATS	/* debug flag for this code	*/
32 
33 /*
34  * Type of transceiver currently in use.  The IEEE 802.3 std aPhyType
35  * enumerates the following set
36  */
37 enum xcvr_type {
38 	XCVR_TYPE_UNDEFINED = 0,    /* 0 = undefined, or not yet known */
39 	XCVR_TYPE_NONE,		/* 1= MII present & nothing connected */
40 	XCVR_TYPE_10BASE_T,		/* 2 = 10 Mbps copper */
41 	XCVR_TYPE_100BASE_T4,	/* 3 = 10 Mbps copper */
42 	XCVR_TYPE_100BASE_X,	/* 4 = 100 Mbps copper */
43 	XCVR_TYPE_100BASE_T2,	/* 5 = 100 Mbps copper */
44 	XCVR_TYPE_1000BASE_X,	/* 6 = 1000 Mbps SerDes */
45 	XCVR_TYPE_1000BASE_T	/* 7 = 1000 Mbps copper */
46 };
47 
48 /*
49  * Local datatype for defining tables of (Offset, Name) pairs
50  */
51 typedef struct {
52 	offset_t	index;
53 	char		*name;
54 } bge_ksindex_t;
55 
56 
57 /*
58  * Table of Hardware-defined Statistics Block Offsets and Names
59  */
60 #define	KS_NAME(s)			{ KS_ ## s, #s }
61 
62 static const bge_ksindex_t bge_statistics[] = {
63 	KS_NAME(ifHCInOctets),
64 	KS_NAME(etherStatsFragments),
65 	KS_NAME(ifHCInUcastPkts),
66 	KS_NAME(ifHCInMulticastPkts),
67 	KS_NAME(ifHCInBroadcastPkts),
68 	KS_NAME(dot3StatsFCSErrors),
69 	KS_NAME(dot3StatsAlignmentErrors),
70 	KS_NAME(xonPauseFramesReceived),
71 	KS_NAME(xoffPauseFramesReceived),
72 	KS_NAME(macControlFramesReceived),
73 	KS_NAME(xoffStateEntered),
74 	KS_NAME(dot3StatsFrameTooLongs),
75 	KS_NAME(etherStatsJabbers),
76 	KS_NAME(etherStatsUndersizePkts),
77 	KS_NAME(inRangeLengthError),
78 	KS_NAME(outRangeLengthError),
79 	KS_NAME(etherStatsPkts64Octets),
80 	KS_NAME(etherStatsPkts65to127Octets),
81 	KS_NAME(etherStatsPkts128to255Octets),
82 	KS_NAME(etherStatsPkts256to511Octets),
83 	KS_NAME(etherStatsPkts512to1023Octets),
84 	KS_NAME(etherStatsPkts1024to1518Octets),
85 	KS_NAME(etherStatsPkts1519to2047Octets),
86 	KS_NAME(etherStatsPkts2048to4095Octets),
87 	KS_NAME(etherStatsPkts4096to8191Octets),
88 	KS_NAME(etherStatsPkts8192to9022Octets),
89 
90 	KS_NAME(ifHCOutOctets),
91 	KS_NAME(etherStatsCollisions),
92 	KS_NAME(outXonSent),
93 	KS_NAME(outXoffSent),
94 	KS_NAME(flowControlDone),
95 	KS_NAME(dot3StatsInternalMacTransmitErrors),
96 	KS_NAME(dot3StatsSingleCollisionFrames),
97 	KS_NAME(dot3StatsMultipleCollisionFrames),
98 	KS_NAME(dot3StatsDeferredTransmissions),
99 	KS_NAME(dot3StatsExcessiveCollisions),
100 	KS_NAME(dot3StatsLateCollisions),
101 	KS_NAME(dot3Collided2Times),
102 	KS_NAME(dot3Collided3Times),
103 	KS_NAME(dot3Collided4Times),
104 	KS_NAME(dot3Collided5Times),
105 	KS_NAME(dot3Collided6Times),
106 	KS_NAME(dot3Collided7Times),
107 	KS_NAME(dot3Collided8Times),
108 	KS_NAME(dot3Collided9Times),
109 	KS_NAME(dot3Collided10Times),
110 	KS_NAME(dot3Collided11Times),
111 	KS_NAME(dot3Collided12Times),
112 	KS_NAME(dot3Collided13Times),
113 	KS_NAME(dot3Collided14Times),
114 	KS_NAME(dot3Collided15Times),
115 	KS_NAME(ifHCOutUcastPkts),
116 	KS_NAME(ifHCOutMulticastPkts),
117 	KS_NAME(ifHCOutBroadcastPkts),
118 	KS_NAME(dot3StatsCarrierSenseErrors),
119 	KS_NAME(ifOutDiscards),
120 	KS_NAME(ifOutErrors),
121 
122 	KS_NAME(COSIfHCInPkts_1),
123 	KS_NAME(COSIfHCInPkts_2),
124 	KS_NAME(COSIfHCInPkts_3),
125 	KS_NAME(COSIfHCInPkts_4),
126 	KS_NAME(COSIfHCInPkts_5),
127 	KS_NAME(COSIfHCInPkts_6),
128 	KS_NAME(COSIfHCInPkts_7),
129 	KS_NAME(COSIfHCInPkts_8),
130 	KS_NAME(COSIfHCInPkts_9),
131 	KS_NAME(COSIfHCInPkts_10),
132 	KS_NAME(COSIfHCInPkts_11),
133 	KS_NAME(COSIfHCInPkts_12),
134 	KS_NAME(COSIfHCInPkts_13),
135 	KS_NAME(COSIfHCInPkts_14),
136 	KS_NAME(COSIfHCInPkts_15),
137 	KS_NAME(COSIfHCInPkts_16),
138 	KS_NAME(COSFramesDroppedDueToFilters),
139 	KS_NAME(nicDmaWriteQueueFull),
140 	KS_NAME(nicDmaWriteHighPriQueueFull),
141 	KS_NAME(nicNoMoreRxBDs),
142 	KS_NAME(ifInDiscards),
143 	KS_NAME(ifInErrors),
144 	KS_NAME(nicRecvThresholdHit),
145 
146 	KS_NAME(COSIfHCOutPkts_1),
147 	KS_NAME(COSIfHCOutPkts_2),
148 	KS_NAME(COSIfHCOutPkts_3),
149 	KS_NAME(COSIfHCOutPkts_4),
150 	KS_NAME(COSIfHCOutPkts_5),
151 	KS_NAME(COSIfHCOutPkts_6),
152 	KS_NAME(COSIfHCOutPkts_7),
153 	KS_NAME(COSIfHCOutPkts_8),
154 	KS_NAME(COSIfHCOutPkts_9),
155 	KS_NAME(COSIfHCOutPkts_10),
156 	KS_NAME(COSIfHCOutPkts_11),
157 	KS_NAME(COSIfHCOutPkts_12),
158 	KS_NAME(COSIfHCOutPkts_13),
159 	KS_NAME(COSIfHCOutPkts_14),
160 	KS_NAME(COSIfHCOutPkts_15),
161 	KS_NAME(COSIfHCOutPkts_16),
162 	KS_NAME(nicDmaReadQueueFull),
163 	KS_NAME(nicDmaReadHighPriQueueFull),
164 	KS_NAME(nicSendDataCompQueueFull),
165 	KS_NAME(nicRingSetSendProdIndex),
166 	KS_NAME(nicRingStatusUpdate),
167 	KS_NAME(nicInterrupts),
168 	KS_NAME(nicAvoidedInterrupts),
169 	KS_NAME(nicSendThresholdHit),
170 
171 	{ KS_STATS_SIZE, NULL }
172 };
173 
174 static const bge_ksindex_t bge_stat_val[] = {
175 	KS_NAME(ifHCOutOctets),
176 	KS_NAME(etherStatsCollisions),
177 	KS_NAME(outXonSent),
178 	KS_NAME(outXoffSent),
179 	KS_NAME(dot3StatsInternalMacTransmitErrors),
180 	KS_NAME(dot3StatsSingleCollisionFrames),
181 	KS_NAME(dot3StatsMultipleCollisionFrames),
182 	KS_NAME(dot3StatsDeferredTransmissions),
183 	KS_NAME(dot3StatsExcessiveCollisions),
184 	KS_NAME(dot3StatsLateCollisions),
185 	KS_NAME(ifHCOutUcastPkts),
186 	KS_NAME(ifHCOutMulticastPkts),
187 	KS_NAME(ifHCOutBroadcastPkts),
188 	KS_NAME(ifHCInOctets),
189 	KS_NAME(etherStatsFragments),
190 	KS_NAME(ifHCInUcastPkts),
191 	KS_NAME(ifHCInMulticastPkts),
192 	KS_NAME(ifHCInBroadcastPkts),
193 	KS_NAME(dot3StatsFCSErrors),
194 	KS_NAME(dot3StatsAlignmentErrors),
195 	KS_NAME(xonPauseFramesReceived),
196 	KS_NAME(xoffPauseFramesReceived),
197 	KS_NAME(macControlFramesReceived),
198 	KS_NAME(xoffStateEntered),
199 	KS_NAME(dot3StatsFrameTooLongs),
200 	KS_NAME(etherStatsJabbers),
201 	KS_NAME(etherStatsUndersizePkts),
202 
203 	{ KS_STAT_REG_SIZE, NULL }
204 };
205 
206 static int
207 bge_statistics_update(kstat_t *ksp, int flag)
208 {
209 	bge_t *bgep;
210 	bge_statistics_t *bstp;
211 	kstat_named_t *knp;
212 	const bge_ksindex_t *ksip;
213 
214 	if (flag != KSTAT_READ)
215 		return (EACCES);
216 
217 	bgep = ksp->ks_private;
218 	if (bgep->chipid.statistic_type == BGE_STAT_BLK)
219 		bstp = DMA_VPTR(bgep->statistics);
220 
221 	knp = ksp->ks_data;
222 
223 	/*
224 	 * Transfer the statistics values from the copy that the
225 	 * chip updates via DMA to the named-kstat structure.
226 	 *
227 	 * As above, we don't bother to sync or stop updates to the
228 	 * statistics, 'cos it doesn't really matter if they're a few
229 	 * microsends out of date or less than 100% consistent ...
230 	 */
231 	if (bgep->chipid.statistic_type == BGE_STAT_BLK)
232 		for (ksip = bge_statistics; ksip->name != NULL; ++knp, ++ksip)
233 			knp->value.ui64 = bstp->a[ksip->index];
234 	else {
235 		(knp++)->value.ui64 =
236 			(uint64_t)(bgep->stat_val.ifHCOutOctets);
237 		(knp++)->value.ui64 =
238 			(uint64_t)(bgep->stat_val.etherStatsCollisions);
239 		(knp++)->value.ui64 =
240 			(uint64_t)(bgep->stat_val.outXonSent);
241 		(knp++)->value.ui64 =
242 			(uint64_t)(bgep->stat_val.outXoffSent);
243 		(knp++)->value.ui64 =
244 			(uint64_t)(bgep->
245 				stat_val.dot3StatsInternalMacTransmitErrors);
246 		(knp++)->value.ui64 =
247 			(uint64_t)(bgep->
248 				stat_val.dot3StatsSingleCollisionFrames);
249 		(knp++)->value.ui64 =
250 			(uint64_t)(bgep->
251 				stat_val.dot3StatsMultipleCollisionFrames);
252 		(knp++)->value.ui64 =
253 			(uint64_t)(bgep->
254 				stat_val.dot3StatsDeferredTransmissions);
255 		(knp++)->value.ui64 =
256 			(uint64_t)(bgep->stat_val.dot3StatsExcessiveCollisions);
257 		(knp++)->value.ui64 =
258 			(uint64_t)(bgep->stat_val.dot3StatsLateCollisions);
259 		(knp++)->value.ui64 =
260 			(uint64_t)(bgep->stat_val.ifHCOutUcastPkts);
261 		(knp++)->value.ui64 =
262 			(uint64_t)(bgep->stat_val.ifHCOutMulticastPkts);
263 		(knp++)->value.ui64 =
264 			(uint64_t)(bgep->stat_val.ifHCOutBroadcastPkts);
265 		(knp++)->value.ui64 =
266 			(uint64_t)(bgep->stat_val.ifHCInOctets);
267 		(knp++)->value.ui64 =
268 			(uint64_t)(bgep->stat_val.etherStatsFragments);
269 		(knp++)->value.ui64 =
270 			(uint64_t)(bgep->stat_val.ifHCInUcastPkts);
271 		(knp++)->value.ui64 =
272 			(uint64_t)(bgep->stat_val.ifHCInMulticastPkts);
273 		(knp++)->value.ui64 =
274 			(uint64_t)(bgep->stat_val.ifHCInBroadcastPkts);
275 		(knp++)->value.ui64 =
276 			(uint64_t)(bgep->stat_val.dot3StatsFCSErrors);
277 		(knp++)->value.ui64 =
278 			(uint64_t)(bgep->stat_val.dot3StatsAlignmentErrors);
279 		(knp++)->value.ui64 =
280 			(uint64_t)(bgep->stat_val.xonPauseFramesReceived);
281 		(knp++)->value.ui64 =
282 			(uint64_t)(bgep->stat_val.xoffPauseFramesReceived);
283 		(knp++)->value.ui64 =
284 			(uint64_t)(bgep->stat_val.macControlFramesReceived);
285 		(knp++)->value.ui64 =
286 			(uint64_t)(bgep->stat_val.xoffStateEntered);
287 		(knp++)->value.ui64 =
288 			(uint64_t)(bgep->stat_val.dot3StatsFrameTooLongs);
289 		(knp++)->value.ui64 =
290 			(uint64_t)(bgep->stat_val.etherStatsJabbers);
291 		(knp++)->value.ui64 =
292 			(uint64_t)(bgep->stat_val.etherStatsUndersizePkts);
293 	}
294 
295 	return (0);
296 }
297 
298 static int
299 bge_params_update(kstat_t *ksp, int flag)
300 {
301 	bge_t *bgep;
302 	kstat_named_t *knp;
303 	int i;
304 
305 	if (flag != KSTAT_READ)
306 		return (EACCES);
307 
308 	bgep = ksp->ks_private;
309 	for (knp = ksp->ks_data, i = 0; i < PARAM_COUNT; ++knp, ++i)
310 		knp->value.ui64 = bgep->nd_params[i].ndp_val;
311 
312 	return (0);
313 }
314 
315 static const bge_ksindex_t bge_chipid[] = {
316 	{ 0,				"asic_rev"		},
317 	{ 1,				"businfo"		},
318 	{ 2,				"command"		},
319 
320 	{ 3,				"vendor_id"		},
321 	{ 4,				"device_id"		},
322 	{ 5,				"subsystem_vendor_id"	},
323 	{ 6,				"subsystem_device_id"	},
324 	{ 7,				"revision_id"		},
325 	{ 8,				"cache_line_size"	},
326 	{ 9,				"latency_timer"		},
327 
328 	{ 10,				"flags"			},
329 	{ 11,				"chip_type"		},
330 	{ 12,				"mbuf_base"		},
331 	{ 13,				"mbuf_count"		},
332 	{ 14,				"hw_mac_addr"		},
333 
334 	{ 15,				"&bus_type"		},
335 	{ 16,				"&bus_speed"		},
336 	{ 17,				"&bus_size"		},
337 	{ 18,				"&supported"		},
338 	{ 19,				"&interface"		},
339 
340 	{ -1,				NULL 			}
341 };
342 
343 static void
344 bge_set_char_kstat(kstat_named_t *knp, const char *s)
345 {
346 	(void) strncpy(knp->value.c, s, sizeof (knp->value.c));
347 }
348 
349 static int
350 bge_chipid_update(kstat_t *ksp, int flag)
351 {
352 	bge_t *bgep;
353 	kstat_named_t *knp;
354 	uint64_t tmp;
355 
356 	if (flag != KSTAT_READ)
357 		return (EACCES);
358 
359 	bgep = ksp->ks_private;
360 	knp = ksp->ks_data;
361 
362 	(knp++)->value.ui64 = bgep->chipid.asic_rev;
363 	(knp++)->value.ui64 = bgep->chipid.businfo;
364 	(knp++)->value.ui64 = bgep->chipid.command;
365 
366 	(knp++)->value.ui64 = bgep->chipid.vendor;
367 	(knp++)->value.ui64 = bgep->chipid.device;
368 	(knp++)->value.ui64 = bgep->chipid.subven;
369 	(knp++)->value.ui64 = bgep->chipid.subdev;
370 	(knp++)->value.ui64 = bgep->chipid.revision;
371 	(knp++)->value.ui64 = bgep->chipid.clsize;
372 	(knp++)->value.ui64 = bgep->chipid.latency;
373 
374 	(knp++)->value.ui64 = bgep->chipid.flags;
375 	(knp++)->value.ui64 = bgep->chipid.chip_label;
376 	(knp++)->value.ui64 = bgep->chipid.mbuf_base;
377 	(knp++)->value.ui64 = bgep->chipid.mbuf_length;
378 	(knp++)->value.ui64 = bgep->chipid.hw_mac_addr;
379 
380 	/*
381 	 * Now we interpret some of the above into readable strings
382 	 */
383 	tmp = bgep->chipid.businfo;
384 	bge_set_char_kstat(knp++,
385 		tmp & PCISTATE_BUS_IS_PCI ? "PCI" : "PCI-X");
386 	bge_set_char_kstat(knp++,
387 		tmp & PCISTATE_BUS_IS_FAST ? "fast" : "normal");
388 	bge_set_char_kstat(knp++,
389 		tmp & PCISTATE_BUS_IS_32_BIT ? "32 bit" : "64 bit");
390 
391 	tmp = bgep->chipid.flags;
392 	bge_set_char_kstat(knp++,
393 		tmp & CHIP_FLAG_SUPPORTED ? "yes" : "no");
394 	bge_set_char_kstat(knp++,
395 		tmp & CHIP_FLAG_SERDES ? "serdes" : "copper");
396 
397 	return (0);
398 }
399 
400 static const bge_ksindex_t bge_driverinfo[] = {
401 	{ 0,				"rx_buff_addr"		},
402 	{ 1,				"tx_buff_addr"		},
403 	{ 2,				"rx_desc_addr"		},
404 	{ 3,				"tx_desc_addr"		},
405 
406 	{ 4,				"tx_desc_free"		},
407 	{ 5,				"resched_needed"	},
408 	{ 6,				"watchdog"		},
409 	{ 7,				"chip_resets"		},
410 	{ 8,				"dma_misses"		},
411 
412 	{ 9,				"misc_host_config"	},
413 	{ 10,				"dma_rw_control"	},
414 	{ 11,				"pci_bus_info"		},
415 
416 	{ 12,				"buff_mgr_status"	},
417 	{ 13,				"rcv_init_status"	},
418 
419 	{ -1,				NULL 			}
420 };
421 
422 static int
423 bge_driverinfo_update(kstat_t *ksp, int flag)
424 {
425 	bge_t *bgep;
426 	kstat_named_t *knp;
427 	ddi_acc_handle_t handle;
428 
429 	if (flag != KSTAT_READ)
430 		return (EACCES);
431 
432 	bgep = ksp->ks_private;
433 	knp = ksp->ks_data;
434 
435 	(knp++)->value.ui64 = bgep->rx_buff[0].cookie.dmac_laddress;
436 	(knp++)->value.ui64 = bgep->tx_buff[0].cookie.dmac_laddress;
437 	(knp++)->value.ui64 = bgep->rx_desc[0].cookie.dmac_laddress;
438 	(knp++)->value.ui64 = bgep->tx_desc.cookie.dmac_laddress;
439 
440 	(knp++)->value.ui64 = bgep->send[0].tx_free;
441 	(knp++)->value.ui64 = bgep->resched_needed;
442 	(knp++)->value.ui64 = bgep->watchdog;
443 	(knp++)->value.ui64 = bgep->chip_resets;
444 	(knp++)->value.ui64 = bgep->missed_dmas;
445 
446 	/*
447 	 * Hold the mutex while accessing the chip registers
448 	 * just in case the factotum is trying to reset it!
449 	 */
450 	handle = bgep->cfg_handle;
451 	mutex_enter(bgep->genlock);
452 	(knp++)->value.ui64 = pci_config_get32(handle, PCI_CONF_BGE_MHCR);
453 	(knp++)->value.ui64 = pci_config_get32(handle, PCI_CONF_BGE_PDRWCR);
454 	(knp++)->value.ui64 = pci_config_get32(handle, PCI_CONF_BGE_PCISTATE);
455 
456 	(knp++)->value.ui64 = bge_reg_get32(bgep, BUFFER_MANAGER_STATUS_REG);
457 	(knp++)->value.ui64 = bge_reg_get32(bgep, RCV_INITIATOR_STATUS_REG);
458 	mutex_exit(bgep->genlock);
459 
460 	return (0);
461 }
462 
463 static const bge_ksindex_t bge_mii_kstats[] = {
464 	{ 0,				"%xcvr_addr"		},
465 	{ 1,				"%xcvr_id"			},
466 	{ 2,				"%xcvr_inuse"		},
467 
468 	{ 3,				"%cap_1000fdx"		},
469 	{ 4,				"%cap_1000hdx"		},
470 	{ 5,				"%cap_100fdx"		},
471 	{ 6,				"%cap_100hdx"		},
472 	{ 7,				"%cap_10fdx"		},
473 	{ 8,				"%cap_10hdx"		},
474 	{ 9,				"%cap_asmpause"		},
475 	{ 10,				"%cap_pause"		},
476 	{ 11,				"%cap_rem_fault"	},
477 	{ 12,				"%cap_autoneg"		},
478 
479 	{ 13,				"%adv_cap_1000fdx"	},
480 	{ 14,				"%adv_cap_1000hdx"	},
481 	{ 15,				"%adv_cap_100fdx"	},
482 	{ 16,				"%adv_cap_100hdx"	},
483 	{ 17,				"%adv_cap_10fdx"	},
484 	{ 18,				"%adv_cap_10hdx"	},
485 	{ 19,				"%adv_cap_asmpause"	},
486 	{ 20,				"%adv_cap_pause"	},
487 	{ 21,				"%adv_rem_fault"	},
488 	{ 22,				"%adv_cap_autoneg"	},
489 
490 	{ 23,				"%lp_cap_1000fdx"	},
491 	{ 24,				"%lp_cap_1000hdx"	},
492 	{ 25,				"%lp_cap_100fdx"	},
493 	{ 26,				"%lp_cap_100hdx"	},
494 	{ 27,				"%lp_cap_10fdx"		},
495 	{ 28,				"%lp_cap_10hdx"		},
496 	{ 29,				"%lp_cap_asmpause"	},
497 	{ 30,				"%lp_cap_pause"		},
498 	{ 31,				"%lp_rem_fault"		},
499 	{ 32,				"%lp_cap_autoneg"	},
500 
501 	{ 33,				"%link_asmpause"	},
502 	{ 34,				"%link_pause"		},
503 	{ 35,				"%link_duplex"		},
504 	{ 36,				"%link_up"			},
505 
506 	{ -1,				NULL 				}
507 };
508 
509 /*
510  * Derive and publish the standard "mii" kstats.
511  *
512  * The information required is somewhat scattered: some is already held
513  * in driver softstate, some is available in the MII registers, and some
514  * has to be computed from combinations of both ...
515  */
516 static int
517 bge_mii_update(kstat_t *ksp, int flag)
518 {
519 	bge_t *bgep;
520 	kstat_named_t *knp;
521 	uint16_t anlpar;
522 	uint16_t anar;
523 	uint32_t xcvr_id;
524 	uint32_t xcvr_inuse;
525 	boolean_t asym_pause;
526 
527 	if (flag != KSTAT_READ)
528 		return (EACCES);
529 
530 	bgep = ksp->ks_private;
531 	knp = ksp->ks_data;
532 
533 	/*
534 	 * Read all the relevant PHY registers
535 	 */
536 	mutex_enter(bgep->genlock);
537 	anlpar = bge_mii_get16(bgep, MII_AN_LPABLE);
538 	anar = bge_mii_get16(bgep, MII_AN_ADVERT);
539 
540 	/*
541 	 * Derive PHY characterisation parameters
542 	 */
543 	xcvr_id = bge_mii_get16(bgep, MII_PHYIDH);
544 	xcvr_id <<= 16;
545 	xcvr_id |= bge_mii_get16(bgep, MII_PHYIDL);
546 	mutex_exit(bgep->genlock);
547 
548 	switch (bgep->param_link_speed) {
549 	case 1000:
550 		if (bgep->chipid.flags & CHIP_FLAG_SERDES)
551 			xcvr_inuse = XCVR_TYPE_1000BASE_X;
552 		else
553 			xcvr_inuse = XCVR_TYPE_1000BASE_T;
554 		break;
555 
556 	case 100:
557 		xcvr_inuse = XCVR_TYPE_100BASE_X;
558 		break;
559 
560 	case 10:
561 		xcvr_inuse = XCVR_TYPE_10BASE_T;
562 		break;
563 
564 	default:
565 		xcvr_inuse = XCVR_TYPE_UNDEFINED;
566 		break;
567 	}
568 
569 	/*
570 	 * Other miscellaneous transformations ...
571 	 */
572 	asym_pause = bgep->param_link_rx_pause != bgep->param_link_tx_pause;
573 
574 	/*
575 	 * All required values are now available; assign them to the
576 	 * actual kstats, in the sequence defined by the table above.
577 	 */
578 	(knp++)->value.ui32 = bgep->phy_mii_addr;
579 	(knp++)->value.ui32 = xcvr_id;
580 	(knp++)->value.ui32 = xcvr_inuse;
581 
582 	/*
583 	 * Our capabilities
584 	 */
585 	(knp++)->value.ui32 = bgep->nd_params[PARAM_1000FDX_CAP].ndp_val;
586 	(knp++)->value.ui32 = bgep->nd_params[PARAM_1000HDX_CAP].ndp_val;
587 	(knp++)->value.ui32 = bgep->nd_params[PARAM_100FDX_CAP].ndp_val;
588 	(knp++)->value.ui32 = bgep->nd_params[PARAM_100HDX_CAP].ndp_val;
589 	(knp++)->value.ui32 = bgep->nd_params[PARAM_10FDX_CAP].ndp_val;
590 	(knp++)->value.ui32 = bgep->nd_params[PARAM_10HDX_CAP].ndp_val;
591 	(knp++)->value.ui32 = bgep->nd_params[PARAM_ASYM_PAUSE_CAP].ndp_val;
592 	(knp++)->value.ui32 = bgep->nd_params[PARAM_PAUSE_CAP].ndp_val;
593 	(knp++)->value.ui32 = B_TRUE;
594 	(knp++)->value.ui32 = bgep->nd_params[PARAM_AUTONEG_CAP].ndp_val;
595 
596 	/*
597 	 * Our *advertised* capabilities
598 	 */
599 	(knp++)->value.ui32 = bgep->param_adv_1000fdx;
600 	(knp++)->value.ui32 = bgep->param_adv_1000hdx;
601 	(knp++)->value.ui32 = bgep->param_adv_100fdx;
602 	(knp++)->value.ui32 = bgep->param_adv_100hdx;
603 	(knp++)->value.ui32 = bgep->param_adv_10fdx;
604 	(knp++)->value.ui32 = bgep->param_adv_10hdx;
605 	(knp++)->value.ui32 = bgep->param_adv_asym_pause;
606 	(knp++)->value.ui32 = bgep->param_adv_pause;
607 	(knp++)->value.ui32 = (anar & MII_AN_ADVERT_REMFAULT) ? 1 : 0;
608 	(knp++)->value.ui32 = bgep->param_adv_autoneg;
609 
610 	/*
611 	 * Link Partner's advertised capabilities
612 	 */
613 	(knp++)->value.ui32 = bgep->param_lp_1000fdx;
614 	(knp++)->value.ui32 = bgep->param_lp_1000hdx;
615 	(knp++)->value.ui32 = bgep->param_lp_100fdx;
616 	(knp++)->value.ui32 = bgep->param_lp_100hdx;
617 	(knp++)->value.ui32 = bgep->param_lp_10fdx;
618 	(knp++)->value.ui32 = bgep->param_lp_10hdx;
619 	(knp++)->value.ui32 = bgep->param_lp_asym_pause;
620 	(knp++)->value.ui32 = bgep->param_lp_pause;
621 	(knp++)->value.ui32 = (anlpar & MII_AN_ADVERT_REMFAULT) ? 1 : 0;
622 	(knp++)->value.ui32 = bgep->param_lp_autoneg;
623 
624 	/*
625 	 * Current operating modes
626 	 */
627 	(knp++)->value.ui32 = asym_pause;
628 	(knp++)->value.ui32 = bgep->param_link_rx_pause;
629 	(knp++)->value.ui32 = bgep->param_link_duplex;
630 	(knp++)->value.ui32 = bgep->param_link_up;
631 
632 	return (0);
633 }
634 
635 static const bge_ksindex_t bge_serdes[] = {
636 	{ 0,				"serdes_status"		},
637 	{ 1,				"serdes_advert"		},
638 	{ 2,				"serdes_lpadv"		},
639 
640 	{ -1,				NULL }
641 };
642 
643 static int
644 bge_serdes_update(kstat_t *ksp, int flag)
645 {
646 	bge_t *bgep;
647 	kstat_named_t *knp;
648 
649 	if (flag != KSTAT_READ)
650 		return (EACCES);
651 
652 	bgep = ksp->ks_private;
653 	knp = ksp->ks_data;
654 
655 	(knp++)->value.ui64 = bgep->serdes_status;
656 	(knp++)->value.ui64 = bgep->serdes_advert;
657 	(knp++)->value.ui64 = bgep->serdes_lpadv;
658 
659 	return (0);
660 }
661 
662 static const bge_ksindex_t bge_phydata[] = {
663 	{ MII_CONTROL,			"mii_control"		},
664 	{ MII_STATUS,			"mii_status"		},
665 	{ MII_PHYIDH,			"phy_identifier"	},
666 	{ MII_AN_ADVERT,		"an_advert"		},
667 	{ MII_AN_LPABLE,		"an_lp_ability"		},
668 	{ MII_AN_EXPANSION,		"an_expansion"		},
669 	{ MII_AN_LPNXTPG,		"an_lp_nextpage"	},
670 	{ MII_1000BASE_T_CONTROL,	"gbit_control"		},
671 	{ MII_1000BASE_T_STATUS,	"gbit_status"		},
672 	{ MII_IEEE_EXT_STATUS,		"ieee_ext_status"	},
673 	{ MII_EXT_CONTROL,		"phy_ext_control"	},
674 	{ MII_EXT_STATUS,		"phy_ext_status"	},
675 	{ MII_RCV_ERR_COUNT,		"receive_error_count"	},
676 	{ MII_FALSE_CARR_COUNT,		"false_carrier_count"	},
677 	{ MII_RCV_NOT_OK_COUNT,		"receiver_not_ok_count"	},
678 	{ MII_AUX_CONTROL,		"aux_control"		},
679 	{ MII_AUX_STATUS,		"aux_status"		},
680 	{ MII_INTR_STATUS,		"intr_status"		},
681 	{ MII_INTR_MASK,		"intr_mask"		},
682 	{ MII_HCD_STATUS,		"hcd_status"		},
683 
684 	{ -1,				NULL }
685 };
686 
687 static int
688 bge_phydata_update(kstat_t *ksp, int flag)
689 {
690 	bge_t *bgep;
691 	kstat_named_t *knp;
692 	const bge_ksindex_t *ksip;
693 
694 	if (flag != KSTAT_READ)
695 		return (EACCES);
696 
697 	bgep = ksp->ks_private;
698 	knp = ksp->ks_data;
699 
700 	/*
701 	 * Read the PHY registers & update the kstats ...
702 	 *
703 	 * We need to hold the mutex while performing MII reads, but
704 	 * we don't want to hold it across the entire sequence of reads.
705 	 * So we grab and release it on each iteration, 'cos it doesn't
706 	 * really matter if the kstats are less than 100% consistent ...
707 	 */
708 	for (ksip = bge_phydata; ksip->name != NULL; ++knp, ++ksip) {
709 		mutex_enter(bgep->genlock);
710 		switch (ksip->index) {
711 		case MII_STATUS:
712 			knp->value.ui64 = bgep->phy_gen_status;
713 			break;
714 
715 		case MII_PHYIDH:
716 			knp->value.ui64 = bge_mii_get16(bgep, MII_PHYIDH);
717 			knp->value.ui64 <<= 16;
718 			knp->value.ui64 |= bge_mii_get16(bgep, MII_PHYIDL);
719 			break;
720 
721 		default:
722 			knp->value.ui64 = bge_mii_get16(bgep, ksip->index);
723 			break;
724 		}
725 		mutex_exit(bgep->genlock);
726 	}
727 
728 	return (0);
729 }
730 
731 static kstat_t *
732 bge_setup_named_kstat(bge_t *bgep, int instance, char *name,
733 	const bge_ksindex_t *ksip, size_t size, int (*update)(kstat_t *, int))
734 {
735 	kstat_t *ksp;
736 	kstat_named_t *knp;
737 	char *np;
738 	int type;
739 
740 	size /= sizeof (bge_ksindex_t);
741 	ksp = kstat_create(BGE_DRIVER_NAME, instance, name, "net",
742 		KSTAT_TYPE_NAMED, size-1, KSTAT_FLAG_PERSISTENT);
743 	if (ksp == NULL)
744 		return (NULL);
745 
746 	ksp->ks_private = bgep;
747 	ksp->ks_update = update;
748 	for (knp = ksp->ks_data; (np = ksip->name) != NULL; ++knp, ++ksip) {
749 		switch (*np) {
750 		default:
751 			type = KSTAT_DATA_UINT64;
752 			break;
753 		case '%':
754 			np += 1;
755 			type = KSTAT_DATA_UINT32;
756 			break;
757 		case '$':
758 			np += 1;
759 			type = KSTAT_DATA_STRING;
760 			break;
761 		case '&':
762 			np += 1;
763 			type = KSTAT_DATA_CHAR;
764 			break;
765 		}
766 		kstat_named_init(knp, np, type);
767 	}
768 	kstat_install(ksp);
769 
770 	return (ksp);
771 }
772 
773 /*
774  * Create kstats corresponding to NDD parameters
775  */
776 static kstat_t *
777 bge_setup_params_kstat(bge_t *bgep, int instance, char *name,
778 	int (*update)(kstat_t *, int))
779 {
780 	kstat_t *ksp;
781 	kstat_named_t *knp;
782 	int i;
783 
784 	ksp = kstat_create(BGE_DRIVER_NAME, instance, name, "net",
785 		KSTAT_TYPE_NAMED, PARAM_COUNT, KSTAT_FLAG_PERSISTENT);
786 	if (ksp != NULL) {
787 		ksp->ks_private = bgep;
788 		ksp->ks_update = update;
789 		for (knp = ksp->ks_data, i = 0; i < PARAM_COUNT; ++knp, ++i)
790 			kstat_named_init(knp, bgep->nd_params[i].ndp_name+1,
791 				KSTAT_DATA_UINT64);
792 		kstat_install(ksp);
793 	}
794 
795 	return (ksp);
796 }
797 
798 void
799 bge_init_kstats(bge_t *bgep, int instance)
800 {
801 	kstat_t *ksp;
802 
803 	BGE_TRACE(("bge_init_kstats($%p, %d)", (void *)bgep, instance));
804 
805 	if (bgep->chipid.statistic_type == BGE_STAT_BLK) {
806 		DMA_ZERO(bgep->statistics);
807 		bgep->bge_kstats[BGE_KSTAT_RAW] = ksp =
808 			kstat_create(BGE_DRIVER_NAME, instance,
809 				"raw_statistics", "net", KSTAT_TYPE_RAW,
810 				sizeof (bge_statistics_t), KSTAT_FLAG_VIRTUAL);
811 		if (ksp != NULL) {
812 			ksp->ks_data = DMA_VPTR(bgep->statistics);
813 			kstat_install(ksp);
814 		}
815 
816 		bgep->bge_kstats[BGE_KSTAT_STATS] = bge_setup_named_kstat(bgep,
817 			instance, "statistics", bge_statistics,
818 			sizeof (bge_statistics), bge_statistics_update);
819 	} else {
820 		bgep->bge_kstats[BGE_KSTAT_STATS] = bge_setup_named_kstat(bgep,
821 			instance, "statistics", bge_stat_val,
822 			sizeof (bge_stat_val), bge_statistics_update);
823 	}
824 
825 	bgep->bge_kstats[BGE_KSTAT_CHIPID] = bge_setup_named_kstat(bgep,
826 		instance, "chipid", bge_chipid,
827 		sizeof (bge_chipid), bge_chipid_update);
828 
829 	bgep->bge_kstats[BGE_KSTAT_DRIVER] = bge_setup_named_kstat(bgep,
830 		instance, "driverinfo", bge_driverinfo,
831 		sizeof (bge_driverinfo), bge_driverinfo_update);
832 
833 	bgep->bge_kstats[BGE_KSTAT_MII] = bge_setup_named_kstat(bgep,
834 		instance, "mii", bge_mii_kstats,
835 		sizeof (bge_mii_kstats), bge_mii_update);
836 
837 	if (bgep->chipid.flags & CHIP_FLAG_SERDES)
838 		bgep->bge_kstats[BGE_KSTAT_PHYS] = bge_setup_named_kstat(bgep,
839 			instance, "serdes", bge_serdes,
840 			sizeof (bge_serdes), bge_serdes_update);
841 	else
842 		bgep->bge_kstats[BGE_KSTAT_PHYS] = bge_setup_named_kstat(bgep,
843 			instance, "phydata", bge_phydata,
844 			sizeof (bge_phydata), bge_phydata_update);
845 
846 	bgep->bge_kstats[BGE_KSTAT_PARAMS] = bge_setup_params_kstat(bgep,
847 		instance, "parameters", bge_params_update);
848 }
849 
850 void
851 bge_fini_kstats(bge_t *bgep)
852 {
853 	int i;
854 
855 	BGE_TRACE(("bge_fini_kstats($%p)", (void *)bgep));
856 
857 	for (i = BGE_KSTAT_COUNT; --i >= 0; )
858 		if (bgep->bge_kstats[i] != NULL)
859 			kstat_delete(bgep->bge_kstats[i]);
860 }
861 
862 uint64_t
863 bge_m_stat(void *arg, enum mac_stat stat)
864 {
865 	bge_t *bgep = arg;
866 	bge_statistics_t *bstp;
867 	uint64_t val;
868 
869 	if (bgep->chipid.statistic_type == BGE_STAT_BLK)
870 		bstp = DMA_VPTR(bgep->statistics);
871 	else {
872 
873 		bgep->stat_val.ifHCOutOctets +=
874 			bge_reg_get32(bgep, STAT_IFHCOUT_OCTETS_REG);
875 		bgep->stat_val.etherStatsCollisions +=
876 			bge_reg_get32(bgep, STAT_ETHER_COLLIS_REG);
877 		bgep->stat_val.outXonSent +=
878 			bge_reg_get32(bgep, STAT_OUTXON_SENT_REG);
879 		bgep->stat_val.outXoffSent +=
880 			bge_reg_get32(bgep, STAT_OUTXOFF_SENT_REG);
881 		bgep->stat_val.dot3StatsInternalMacTransmitErrors +=
882 			bge_reg_get32(bgep, STAT_DOT3_INTMACTX_ERR_REG);
883 		bgep->stat_val.dot3StatsSingleCollisionFrames +=
884 			bge_reg_get32(bgep, STAT_DOT3_SCOLLI_FRAME_REG);
885 		bgep->stat_val.dot3StatsMultipleCollisionFrames +=
886 			bge_reg_get32(bgep, STAT_DOT3_MCOLLI_FRAME_REG);
887 		bgep->stat_val.dot3StatsDeferredTransmissions +=
888 			bge_reg_get32(bgep, STAT_DOT3_DEFERED_TX_REG);
889 		bgep->stat_val.dot3StatsExcessiveCollisions +=
890 			bge_reg_get32(bgep, STAT_DOT3_EXCE_COLLI_REG);
891 		bgep->stat_val.dot3StatsLateCollisions +=
892 			bge_reg_get32(bgep, STAT_DOT3_LATE_COLLI_REG);
893 		bgep->stat_val.ifHCOutUcastPkts +=
894 			bge_reg_get32(bgep, STAT_IFHCOUT_UPKGS_REG);
895 		bgep->stat_val.ifHCOutMulticastPkts +=
896 			bge_reg_get32(bgep, STAT_IFHCOUT_MPKGS_REG);
897 		bgep->stat_val.ifHCOutBroadcastPkts +=
898 			bge_reg_get32(bgep, STAT_IFHCOUT_BPKGS_REG);
899 		bgep->stat_val.ifHCInOctets +=
900 			bge_reg_get32(bgep, STAT_IFHCIN_OCTETS_REG);
901 		bgep->stat_val.etherStatsFragments +=
902 			bge_reg_get32(bgep, STAT_ETHER_FRAGMENT_REG);
903 		bgep->stat_val.ifHCInUcastPkts +=
904 			bge_reg_get32(bgep, STAT_IFHCIN_UPKGS_REG);
905 		bgep->stat_val.ifHCInMulticastPkts +=
906 			bge_reg_get32(bgep, STAT_IFHCIN_MPKGS_REG);
907 		bgep->stat_val.ifHCInBroadcastPkts +=
908 			bge_reg_get32(bgep, STAT_IFHCIN_BPKGS_REG);
909 		bgep->stat_val.dot3StatsFCSErrors +=
910 			bge_reg_get32(bgep, STAT_DOT3_FCS_ERR_REG);
911 		bgep->stat_val.dot3StatsAlignmentErrors +=
912 			bge_reg_get32(bgep, STAT_DOT3_ALIGN_ERR_REG);
913 		bgep->stat_val.xonPauseFramesReceived +=
914 			bge_reg_get32(bgep, STAT_XON_PAUSE_RX_REG);
915 		bgep->stat_val.xoffPauseFramesReceived +=
916 			bge_reg_get32(bgep, STAT_XOFF_PAUSE_RX_REG);
917 		bgep->stat_val.macControlFramesReceived +=
918 			bge_reg_get32(bgep, STAT_MAC_CTRL_RX_REG);
919 		bgep->stat_val.xoffStateEntered +=
920 			bge_reg_get32(bgep, STAT_XOFF_STATE_ENTER_REG);
921 		bgep->stat_val.dot3StatsFrameTooLongs +=
922 			bge_reg_get32(bgep, STAT_DOT3_FRAME_TOOLONG_REG);
923 		bgep->stat_val.etherStatsJabbers +=
924 			bge_reg_get32(bgep, STAT_ETHER_JABBERS_REG);
925 		bgep->stat_val.etherStatsUndersizePkts +=
926 			bge_reg_get32(bgep, STAT_ETHER_UNDERSIZE_REG);
927 		}
928 
929 	switch (stat) {
930 	case MAC_STAT_IFSPEED:
931 		val = bgep->param_link_speed * 1000000ull;
932 		break;
933 
934 	case MAC_STAT_MULTIRCV:
935 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
936 			val = bstp->s.ifHCInMulticastPkts;
937 		else
938 			val = bgep->stat_val.ifHCInMulticastPkts;
939 		break;
940 
941 	case MAC_STAT_BRDCSTRCV:
942 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
943 			val = bstp->s.ifHCInBroadcastPkts;
944 		else
945 			val = bgep->stat_val.ifHCInBroadcastPkts;
946 		break;
947 
948 	case MAC_STAT_MULTIXMT:
949 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
950 			val = bstp->s.ifHCOutMulticastPkts;
951 		else
952 			val = bgep->stat_val.ifHCOutMulticastPkts;
953 		break;
954 
955 	case MAC_STAT_BRDCSTXMT:
956 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
957 			val = bstp->s.ifHCOutBroadcastPkts;
958 		else
959 			val = bgep->stat_val.ifHCOutBroadcastPkts;
960 		break;
961 
962 	case MAC_STAT_NORCVBUF:
963 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
964 			val = bstp->s.ifInDiscards;
965 		else
966 			val = 0;
967 		break;
968 
969 	case MAC_STAT_IERRORS:
970 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
971 			val = bstp->s.ifInErrors;
972 		else
973 			val = 0;
974 		break;
975 
976 	case MAC_STAT_NOXMTBUF:
977 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
978 			val = bstp->s.ifOutDiscards;
979 		else
980 			val = 0;
981 		break;
982 
983 	case MAC_STAT_OERRORS:
984 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
985 			val = bstp->s.ifOutDiscards;
986 		else
987 			val = 0;
988 		break;
989 
990 	case MAC_STAT_COLLISIONS:
991 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
992 			val = bstp->s.etherStatsCollisions;
993 		else
994 			val = bgep->stat_val.etherStatsCollisions;
995 		break;
996 
997 	case MAC_STAT_RBYTES:
998 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
999 			val = bstp->s.ifHCInOctets;
1000 		else
1001 			val = bgep->stat_val.ifHCInOctets;
1002 		break;
1003 
1004 	case MAC_STAT_IPACKETS:
1005 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1006 			val = bstp->s.ifHCInUcastPkts +
1007 				bstp->s.ifHCInMulticastPkts +
1008 				bstp->s.ifHCInBroadcastPkts;
1009 		else
1010 			val = bgep->stat_val.ifHCInUcastPkts +
1011 				bgep->stat_val.ifHCInMulticastPkts +
1012 				bgep->stat_val.ifHCInBroadcastPkts;
1013 		break;
1014 
1015 	case MAC_STAT_OBYTES:
1016 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1017 			val = bstp->s.ifHCOutOctets;
1018 		else
1019 			val = bgep->stat_val.ifHCOutOctets;
1020 		break;
1021 
1022 	case MAC_STAT_OPACKETS:
1023 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1024 			val = bstp->s.ifHCOutUcastPkts +
1025 				bstp->s.ifHCOutMulticastPkts +
1026 				bstp->s.ifHCOutBroadcastPkts;
1027 		else
1028 			val = bgep->stat_val.ifHCOutUcastPkts +
1029 				bgep->stat_val.ifHCOutMulticastPkts +
1030 				bgep->stat_val.ifHCOutBroadcastPkts;
1031 		break;
1032 
1033 	case MAC_STAT_ALIGN_ERRORS:
1034 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1035 			val = bstp->s.dot3StatsAlignmentErrors;
1036 		else
1037 			val = bgep->stat_val.dot3StatsAlignmentErrors;
1038 		break;
1039 
1040 	case MAC_STAT_FCS_ERRORS:
1041 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1042 			val = bstp->s.dot3StatsFCSErrors;
1043 		else
1044 			val = bgep->stat_val.dot3StatsFCSErrors;
1045 		break;
1046 
1047 	case MAC_STAT_FIRST_COLLISIONS:
1048 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1049 			val = bstp->s.dot3StatsSingleCollisionFrames;
1050 		else
1051 			val = bgep->stat_val.dot3StatsSingleCollisionFrames;
1052 		break;
1053 
1054 	case MAC_STAT_MULTI_COLLISIONS:
1055 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1056 			val = bstp->s.dot3StatsMultipleCollisionFrames;
1057 		else
1058 			val = bgep->stat_val.dot3StatsMultipleCollisionFrames;
1059 		break;
1060 
1061 	case MAC_STAT_DEFER_XMTS:
1062 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1063 			val = bstp->s.dot3StatsDeferredTransmissions;
1064 		else
1065 			val = bgep->stat_val.dot3StatsDeferredTransmissions;
1066 		break;
1067 
1068 	case MAC_STAT_TX_LATE_COLLISIONS:
1069 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1070 			val = bstp->s.dot3StatsLateCollisions;
1071 		else
1072 			val = bgep->stat_val.dot3StatsLateCollisions;
1073 		break;
1074 
1075 	case MAC_STAT_EX_COLLISIONS:
1076 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1077 			val = bstp->s.dot3StatsExcessiveCollisions;
1078 		else
1079 			val = bgep->stat_val.dot3StatsExcessiveCollisions;
1080 		break;
1081 
1082 	case MAC_STAT_MACXMT_ERRORS:
1083 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1084 			val = bstp->s.dot3StatsInternalMacTransmitErrors;
1085 		else
1086 			val = bgep->stat_val.dot3StatsInternalMacTransmitErrors;
1087 		break;
1088 
1089 	case MAC_STAT_CARRIER_ERRORS:
1090 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1091 			val = bstp->s.dot3StatsCarrierSenseErrors;
1092 		else
1093 			val = 0;
1094 		break;
1095 
1096 	case MAC_STAT_TOOLONG_ERRORS:
1097 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1098 			val = bstp->s.dot3StatsFrameTooLongs;
1099 		else
1100 			val = bgep->stat_val.dot3StatsFrameTooLongs;
1101 		break;
1102 
1103 	case MAC_STAT_XCVR_ADDR:
1104 		val = bgep->phy_mii_addr;
1105 		break;
1106 
1107 	case MAC_STAT_XCVR_ID:
1108 		mutex_enter(bgep->genlock);
1109 		val = bge_mii_get16(bgep, MII_PHYIDH);
1110 		val <<= 16;
1111 		val |= bge_mii_get16(bgep, MII_PHYIDL);
1112 		mutex_exit(bgep->genlock);
1113 		break;
1114 
1115 	case MAC_STAT_XCVR_INUSE:
1116 		val = XCVR_1000T;
1117 		break;
1118 
1119 	case MAC_STAT_CAP_1000FDX:
1120 		val = 1;
1121 		break;
1122 
1123 	case MAC_STAT_CAP_1000HDX:
1124 		val = 1;
1125 		break;
1126 
1127 	case MAC_STAT_CAP_100FDX:
1128 		val = 1;
1129 		break;
1130 
1131 	case MAC_STAT_CAP_100HDX:
1132 		val = 1;
1133 		break;
1134 
1135 	case MAC_STAT_CAP_10FDX:
1136 		val = 1;
1137 		break;
1138 
1139 	case MAC_STAT_CAP_10HDX:
1140 		val = 1;
1141 		break;
1142 
1143 	case MAC_STAT_CAP_ASMPAUSE:
1144 		val = 1;
1145 		break;
1146 
1147 	case MAC_STAT_CAP_PAUSE:
1148 		val = 1;
1149 		break;
1150 
1151 	case MAC_STAT_CAP_AUTONEG:
1152 		val = 1;
1153 		break;
1154 
1155 	case MAC_STAT_ADV_CAP_1000FDX:
1156 		val = bgep->param_adv_1000fdx;
1157 		break;
1158 
1159 	case MAC_STAT_ADV_CAP_1000HDX:
1160 		val = bgep->param_adv_1000hdx;
1161 		break;
1162 
1163 	case MAC_STAT_ADV_CAP_100FDX:
1164 		val = bgep->param_adv_100fdx;
1165 		break;
1166 
1167 	case MAC_STAT_ADV_CAP_100HDX:
1168 		val = bgep->param_adv_100hdx;
1169 		break;
1170 
1171 	case MAC_STAT_ADV_CAP_10FDX:
1172 		val = bgep->param_adv_10fdx;
1173 		break;
1174 
1175 	case MAC_STAT_ADV_CAP_10HDX:
1176 		val = bgep->param_adv_10hdx;
1177 		break;
1178 
1179 	case MAC_STAT_ADV_CAP_ASMPAUSE:
1180 		val = bgep->param_adv_asym_pause;
1181 		break;
1182 
1183 	case MAC_STAT_ADV_CAP_PAUSE:
1184 		val = bgep->param_adv_pause;
1185 		break;
1186 
1187 	case MAC_STAT_ADV_CAP_AUTONEG:
1188 		val = bgep->param_adv_autoneg;
1189 		break;
1190 
1191 	case MAC_STAT_LP_CAP_1000FDX:
1192 		val = bgep->param_lp_1000fdx;
1193 		break;
1194 
1195 	case MAC_STAT_LP_CAP_1000HDX:
1196 		val = bgep->param_lp_1000hdx;
1197 		break;
1198 
1199 	case MAC_STAT_LP_CAP_100FDX:
1200 		val = bgep->param_lp_100fdx;
1201 		break;
1202 
1203 	case MAC_STAT_LP_CAP_100HDX:
1204 		val = bgep->param_lp_100hdx;
1205 		break;
1206 
1207 	case MAC_STAT_LP_CAP_10FDX:
1208 		val = bgep->param_lp_10fdx;
1209 		break;
1210 
1211 	case MAC_STAT_LP_CAP_10HDX:
1212 		val = bgep->param_lp_10hdx;
1213 		break;
1214 
1215 	case MAC_STAT_LP_CAP_ASMPAUSE:
1216 		val = bgep->param_lp_asym_pause;
1217 		break;
1218 
1219 	case MAC_STAT_LP_CAP_PAUSE:
1220 		val = bgep->param_lp_pause;
1221 		break;
1222 
1223 	case MAC_STAT_LP_CAP_AUTONEG:
1224 		val = bgep->param_lp_autoneg;
1225 		break;
1226 
1227 	case MAC_STAT_LINK_ASMPAUSE:
1228 		val = bgep->param_adv_asym_pause &&
1229 		    bgep->param_lp_asym_pause &&
1230 		    bgep->param_adv_pause != bgep->param_lp_pause;
1231 		break;
1232 
1233 	case MAC_STAT_LINK_PAUSE:
1234 		val = bgep->param_link_rx_pause;
1235 		break;
1236 
1237 	case MAC_STAT_LINK_AUTONEG:
1238 		val = bgep->param_link_autoneg;
1239 		break;
1240 
1241 	case MAC_STAT_LINK_DUPLEX:
1242 		val = bgep->param_link_duplex;
1243 		break;
1244 
1245 #ifdef	DEBUG
1246 	default:
1247 		/*
1248 		 * Shouldn't reach here...
1249 		 */
1250 		cmn_err(CE_PANIC,
1251 		    "bge_m_stat: unrecognized parameter value = %d",
1252 		    stat);
1253 #endif
1254 	}
1255 
1256 	return (val);
1257 }
1258