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