xref: /illumos-gate/usr/src/uts/common/io/e1000g/e1000g_stat.c (revision 592a4d85662412bade15f3d9e9e0cbcf8514348c)
1 /*
2  * This file is provided under a CDDLv1 license.  When using or
3  * redistributing this file, you may do so under this license.
4  * In redistributing this file this license must be included
5  * and no other modification of this header file is permitted.
6  *
7  * CDDL LICENSE SUMMARY
8  *
9  * Copyright(c) 1999 - 2008 Intel Corporation. All rights reserved.
10  *
11  * The contents of this file are subject to the terms of Version
12  * 1.0 of the Common Development and Distribution License (the "License").
13  *
14  * You should have received a copy of the License with this software.
15  * You can obtain a copy of the License at
16  *	http://www.opensolaris.org/os/licensing.
17  * See the License for the specific language governing permissions
18  * and limitations under the License.
19  */
20 
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms of the CDDLv1.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 /*
29  * **********************************************************************
30  *									*
31  * Module Name:  e1000g_stat.c						*
32  *									*
33  * Abstract: Functions for processing statistics			*
34  *									*
35  * **********************************************************************
36  */
37 #include "e1000g_sw.h"
38 #include "e1000g_debug.h"
39 
40 static int e1000g_update_stats(kstat_t *ksp, int rw);
41 
42 /*
43  * e1000_tbi_adjust_stats
44  *
45  * Adjusts statistic counters when a frame is accepted
46  * under the TBI workaround. This function has been
47  * adapted for Solaris from shared code.
48  */
49 void
50 e1000_tbi_adjust_stats(struct e1000g *Adapter,
51     uint32_t frame_len, uint8_t *mac_addr)
52 {
53 	struct e1000_hw *hw = &Adapter->shared;
54 	uint32_t carry_bit;
55 	p_e1000g_stat_t e1000g_ksp;
56 
57 	e1000g_ksp = (p_e1000g_stat_t)Adapter->e1000g_ksp->ks_data;
58 
59 	/* First adjust the frame length */
60 	frame_len--;
61 
62 	/*
63 	 * We need to adjust the statistics counters, since the hardware
64 	 * counters overcount this packet as a CRC error and undercount
65 	 * the packet as a good packet
66 	 */
67 	/* This packet should not be counted as a CRC error */
68 	e1000g_ksp->Crcerrs.value.ul--;
69 	/* This packet does count as a Good Packet Received */
70 	e1000g_ksp->Gprc.value.ul++;
71 
72 	/*
73 	 * Adjust the Good Octets received counters
74 	 */
75 	carry_bit = 0x80000000 & e1000g_ksp->Gorl.value.ul;
76 	e1000g_ksp->Gorl.value.ul += frame_len;
77 	/*
78 	 * If the high bit of Gorcl (the low 32 bits of the Good Octets
79 	 * Received Count) was one before the addition,
80 	 * AND it is zero after, then we lost the carry out,
81 	 * need to add one to Gorch (Good Octets Received Count High).
82 	 * This could be simplified if all environments supported
83 	 * 64-bit integers.
84 	 */
85 	if (carry_bit && ((e1000g_ksp->Gorl.value.ul & 0x80000000) == 0)) {
86 		e1000g_ksp->Gorh.value.ul++;
87 	}
88 	/*
89 	 * Is this a broadcast or multicast?  Check broadcast first,
90 	 * since the test for a multicast frame will test positive on
91 	 * a broadcast frame.
92 	 */
93 	if ((mac_addr[0] == (uint8_t)0xff) &&
94 	    (mac_addr[1] == (uint8_t)0xff)) {
95 		/*
96 		 * Broadcast packet
97 		 */
98 		e1000g_ksp->Bprc.value.ul++;
99 	} else if (*mac_addr & 0x01) {
100 		/*
101 		 * Multicast packet
102 		 */
103 		e1000g_ksp->Mprc.value.ul++;
104 	}
105 
106 	if (frame_len == Adapter->max_frame_size) {
107 		/*
108 		 * In this case, the hardware has overcounted the number of
109 		 * oversize frames.
110 		 */
111 		if (e1000g_ksp->Roc.value.ul > 0)
112 			e1000g_ksp->Roc.value.ul--;
113 	}
114 
115 #ifdef E1000G_DEBUG
116 	/*
117 	 * Adjust the bin counters when the extra byte put the frame in the
118 	 * wrong bin. Remember that the frame_len was adjusted above.
119 	 */
120 	if (frame_len == 64) {
121 		e1000g_ksp->Prc64.value.ul++;
122 		e1000g_ksp->Prc127.value.ul--;
123 	} else if (frame_len == 127) {
124 		e1000g_ksp->Prc127.value.ul++;
125 		e1000g_ksp->Prc255.value.ul--;
126 	} else if (frame_len == 255) {
127 		e1000g_ksp->Prc255.value.ul++;
128 		e1000g_ksp->Prc511.value.ul--;
129 	} else if (frame_len == 511) {
130 		e1000g_ksp->Prc511.value.ul++;
131 		e1000g_ksp->Prc1023.value.ul--;
132 	} else if (frame_len == 1023) {
133 		e1000g_ksp->Prc1023.value.ul++;
134 		e1000g_ksp->Prc1522.value.ul--;
135 	} else if (frame_len == 1522) {
136 		e1000g_ksp->Prc1522.value.ul++;
137 	}
138 #endif
139 }
140 
141 
142 /*
143  * e1000g_update_stats - update driver private kstat counters
144  *
145  * This routine will dump and reset the e1000's internal
146  * statistics counters. The current stats dump values will
147  * be sent to the kernel status area.
148  */
149 static int
150 e1000g_update_stats(kstat_t *ksp, int rw)
151 {
152 	struct e1000g *Adapter;
153 	struct e1000_hw *hw;
154 	p_e1000g_stat_t e1000g_ksp;
155 	e1000g_tx_ring_t *tx_ring;
156 	e1000g_rx_ring_t *rx_ring;
157 	uint64_t val;
158 	uint32_t low_val, high_val;
159 
160 	if (rw == KSTAT_WRITE)
161 		return (EACCES);
162 
163 	Adapter = (struct e1000g *)ksp->ks_private;
164 	ASSERT(Adapter != NULL);
165 	e1000g_ksp = (p_e1000g_stat_t)ksp->ks_data;
166 	ASSERT(e1000g_ksp != NULL);
167 	hw = &Adapter->shared;
168 
169 	tx_ring = Adapter->tx_ring;
170 	rx_ring = Adapter->rx_ring;
171 
172 	rw_enter(&Adapter->chip_lock, RW_WRITER);
173 
174 	e1000g_ksp->link_speed.value.ul = Adapter->link_speed;
175 	e1000g_ksp->reset_count.value.ul = Adapter->reset_count;
176 
177 	e1000g_ksp->rx_error.value.ul = rx_ring->stat_error;
178 	e1000g_ksp->rx_esballoc_fail.value.ul = rx_ring->stat_esballoc_fail;
179 	e1000g_ksp->rx_allocb_fail.value.ul = rx_ring->stat_allocb_fail;
180 
181 	e1000g_ksp->tx_no_swpkt.value.ul = tx_ring->stat_no_swpkt;
182 	e1000g_ksp->tx_no_desc.value.ul = tx_ring->stat_no_desc;
183 	e1000g_ksp->tx_send_fail.value.ul = tx_ring->stat_send_fail;
184 	e1000g_ksp->tx_reschedule.value.ul = tx_ring->stat_reschedule;
185 	e1000g_ksp->tx_over_size.value.ul = tx_ring->stat_over_size;
186 
187 #ifdef E1000G_DEBUG
188 	e1000g_ksp->rx_none.value.ul = rx_ring->stat_none;
189 	e1000g_ksp->rx_multi_desc.value.ul = rx_ring->stat_multi_desc;
190 	e1000g_ksp->rx_no_freepkt.value.ul = rx_ring->stat_no_freepkt;
191 	e1000g_ksp->rx_avail_freepkt.value.ul = rx_ring->avail_freepkt;
192 
193 	e1000g_ksp->tx_under_size.value.ul = tx_ring->stat_under_size;
194 	e1000g_ksp->tx_exceed_frags.value.ul = tx_ring->stat_exceed_frags;
195 	e1000g_ksp->tx_empty_frags.value.ul = tx_ring->stat_empty_frags;
196 	e1000g_ksp->tx_recycle.value.ul = tx_ring->stat_recycle;
197 	e1000g_ksp->tx_recycle_intr.value.ul = tx_ring->stat_recycle_intr;
198 	e1000g_ksp->tx_recycle_retry.value.ul = tx_ring->stat_recycle_retry;
199 	e1000g_ksp->tx_recycle_none.value.ul = tx_ring->stat_recycle_none;
200 	e1000g_ksp->tx_copy.value.ul = tx_ring->stat_copy;
201 	e1000g_ksp->tx_bind.value.ul = tx_ring->stat_bind;
202 	e1000g_ksp->tx_multi_copy.value.ul = tx_ring->stat_multi_copy;
203 	e1000g_ksp->tx_multi_cookie.value.ul = tx_ring->stat_multi_cookie;
204 	e1000g_ksp->tx_lack_desc.value.ul = tx_ring->stat_lack_desc;
205 #endif
206 
207 	/*
208 	 * Standard Stats
209 	 */
210 	e1000g_ksp->Mpc.value.ul += E1000_READ_REG(hw, E1000_MPC);
211 	e1000g_ksp->Rlec.value.ul += E1000_READ_REG(hw, E1000_RLEC);
212 	e1000g_ksp->Xonrxc.value.ul += E1000_READ_REG(hw, E1000_XONRXC);
213 	e1000g_ksp->Xontxc.value.ul += E1000_READ_REG(hw, E1000_XONTXC);
214 	e1000g_ksp->Xoffrxc.value.ul += E1000_READ_REG(hw, E1000_XOFFRXC);
215 	e1000g_ksp->Xofftxc.value.ul += E1000_READ_REG(hw, E1000_XOFFTXC);
216 	e1000g_ksp->Fcruc.value.ul += E1000_READ_REG(hw, E1000_FCRUC);
217 
218 	if ((hw->mac.type != e1000_ich8lan) &&
219 	    (hw->mac.type != e1000_ich9lan)) {
220 		e1000g_ksp->Symerrs.value.ul +=
221 		    E1000_READ_REG(hw, E1000_SYMERRS);
222 #ifdef E1000G_DEBUG
223 		e1000g_ksp->Prc64.value.ul +=
224 		    E1000_READ_REG(hw, E1000_PRC64);
225 		e1000g_ksp->Prc127.value.ul +=
226 		    E1000_READ_REG(hw, E1000_PRC127);
227 		e1000g_ksp->Prc255.value.ul +=
228 		    E1000_READ_REG(hw, E1000_PRC255);
229 		e1000g_ksp->Prc511.value.ul +=
230 		    E1000_READ_REG(hw, E1000_PRC511);
231 		e1000g_ksp->Prc1023.value.ul +=
232 		    E1000_READ_REG(hw, E1000_PRC1023);
233 		e1000g_ksp->Prc1522.value.ul +=
234 		    E1000_READ_REG(hw, E1000_PRC1522);
235 
236 		e1000g_ksp->Ptc64.value.ul +=
237 		    E1000_READ_REG(hw, E1000_PTC64);
238 		e1000g_ksp->Ptc127.value.ul +=
239 		    E1000_READ_REG(hw, E1000_PTC127);
240 		e1000g_ksp->Ptc255.value.ul +=
241 		    E1000_READ_REG(hw, E1000_PTC255);
242 		e1000g_ksp->Ptc511.value.ul +=
243 		    E1000_READ_REG(hw, E1000_PTC511);
244 		e1000g_ksp->Ptc1023.value.ul +=
245 		    E1000_READ_REG(hw, E1000_PTC1023);
246 		e1000g_ksp->Ptc1522.value.ul +=
247 		    E1000_READ_REG(hw, E1000_PTC1522);
248 #endif
249 	}
250 
251 	e1000g_ksp->Gprc.value.ul += E1000_READ_REG(hw, E1000_GPRC);
252 	e1000g_ksp->Gptc.value.ul += E1000_READ_REG(hw, E1000_GPTC);
253 	e1000g_ksp->Ruc.value.ul += E1000_READ_REG(hw, E1000_RUC);
254 	e1000g_ksp->Rfc.value.ul += E1000_READ_REG(hw, E1000_RFC);
255 	e1000g_ksp->Roc.value.ul += E1000_READ_REG(hw, E1000_ROC);
256 	e1000g_ksp->Rjc.value.ul += E1000_READ_REG(hw, E1000_RJC);
257 	e1000g_ksp->Tpr.value.ul += E1000_READ_REG(hw, E1000_TPR);
258 	e1000g_ksp->Tncrs.value.ul += E1000_READ_REG(hw, E1000_TNCRS);
259 	e1000g_ksp->Tsctc.value.ul += E1000_READ_REG(hw, E1000_TSCTC);
260 	e1000g_ksp->Tsctfc.value.ul += E1000_READ_REG(hw, E1000_TSCTFC);
261 
262 	/*
263 	 * Adaptive Calculations
264 	 */
265 	hw->mac.tx_packet_delta = E1000_READ_REG(hw, E1000_TPT);
266 	e1000g_ksp->Tpt.value.ul += hw->mac.tx_packet_delta;
267 
268 	/*
269 	 * The 64-bit register will reset whenever the upper
270 	 * 32 bits are read. So we need to read the lower
271 	 * 32 bits first, then read the upper 32 bits.
272 	 */
273 	low_val = E1000_READ_REG(hw, E1000_GORCL);
274 	high_val = E1000_READ_REG(hw, E1000_GORCH);
275 	val = (uint64_t)e1000g_ksp->Gorh.value.ul << 32 |
276 	    (uint64_t)e1000g_ksp->Gorl.value.ul;
277 	val += (uint64_t)high_val << 32 | (uint64_t)low_val;
278 	e1000g_ksp->Gorl.value.ul = (uint32_t)val;
279 	e1000g_ksp->Gorh.value.ul = (uint32_t)(val >> 32);
280 
281 	low_val = E1000_READ_REG(hw, E1000_GOTCL);
282 	high_val = E1000_READ_REG(hw, E1000_GOTCH);
283 	val = (uint64_t)e1000g_ksp->Goth.value.ul << 32 |
284 	    (uint64_t)e1000g_ksp->Gotl.value.ul;
285 	val += (uint64_t)high_val << 32 | (uint64_t)low_val;
286 	e1000g_ksp->Gotl.value.ul = (uint32_t)val;
287 	e1000g_ksp->Goth.value.ul = (uint32_t)(val >> 32);
288 
289 	low_val = E1000_READ_REG(hw, E1000_TORL);
290 	high_val = E1000_READ_REG(hw, E1000_TORH);
291 	val = (uint64_t)e1000g_ksp->Torh.value.ul << 32 |
292 	    (uint64_t)e1000g_ksp->Torl.value.ul;
293 	val += (uint64_t)high_val << 32 | (uint64_t)low_val;
294 	e1000g_ksp->Torl.value.ul = (uint32_t)val;
295 	e1000g_ksp->Torh.value.ul = (uint32_t)(val >> 32);
296 
297 	low_val = E1000_READ_REG(hw, E1000_TOTL);
298 	high_val = E1000_READ_REG(hw, E1000_TOTH);
299 	val = (uint64_t)e1000g_ksp->Toth.value.ul << 32 |
300 	    (uint64_t)e1000g_ksp->Totl.value.ul;
301 	val += (uint64_t)high_val << 32 | (uint64_t)low_val;
302 	e1000g_ksp->Totl.value.ul = (uint32_t)val;
303 	e1000g_ksp->Toth.value.ul = (uint32_t)(val >> 32);
304 
305 	rw_exit(&Adapter->chip_lock);
306 
307 	if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK)
308 		ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_UNAFFECTED);
309 
310 	return (0);
311 }
312 
313 int
314 e1000g_m_stat(void *arg, uint_t stat, uint64_t *val)
315 {
316 	struct e1000g *Adapter = (struct e1000g *)arg;
317 	struct e1000_hw *hw = &Adapter->shared;
318 	p_e1000g_stat_t e1000g_ksp;
319 	uint32_t low_val, high_val;
320 
321 	e1000g_ksp = (p_e1000g_stat_t)Adapter->e1000g_ksp->ks_data;
322 
323 	rw_enter(&Adapter->chip_lock, RW_READER);
324 
325 	switch (stat) {
326 	case MAC_STAT_IFSPEED:
327 		*val = Adapter->link_speed * 1000000ull;
328 		break;
329 
330 	case MAC_STAT_MULTIRCV:
331 		e1000g_ksp->Mprc.value.ul +=
332 		    E1000_READ_REG(hw, E1000_MPRC);
333 		*val = e1000g_ksp->Mprc.value.ul;
334 		break;
335 
336 	case MAC_STAT_BRDCSTRCV:
337 		e1000g_ksp->Bprc.value.ul +=
338 		    E1000_READ_REG(hw, E1000_BPRC);
339 		*val = e1000g_ksp->Bprc.value.ul;
340 		break;
341 
342 	case MAC_STAT_MULTIXMT:
343 		e1000g_ksp->Mptc.value.ul +=
344 		    E1000_READ_REG(hw, E1000_MPTC);
345 		*val = e1000g_ksp->Mptc.value.ul;
346 		break;
347 
348 	case MAC_STAT_BRDCSTXMT:
349 		e1000g_ksp->Bptc.value.ul +=
350 		    E1000_READ_REG(hw, E1000_BPTC);
351 		*val = e1000g_ksp->Bptc.value.ul;
352 		break;
353 
354 	case MAC_STAT_NORCVBUF:
355 		e1000g_ksp->Rnbc.value.ul +=
356 		    E1000_READ_REG(hw, E1000_RNBC);
357 		*val = e1000g_ksp->Rnbc.value.ul;
358 		break;
359 
360 	case MAC_STAT_IERRORS:
361 		e1000g_ksp->Rxerrc.value.ul +=
362 		    E1000_READ_REG(hw, E1000_RXERRC);
363 		e1000g_ksp->Algnerrc.value.ul +=
364 		    E1000_READ_REG(hw, E1000_ALGNERRC);
365 		e1000g_ksp->Rlec.value.ul +=
366 		    E1000_READ_REG(hw, E1000_RLEC);
367 		e1000g_ksp->Crcerrs.value.ul +=
368 		    E1000_READ_REG(hw, E1000_CRCERRS);
369 		e1000g_ksp->Cexterr.value.ul +=
370 		    E1000_READ_REG(hw, E1000_CEXTERR);
371 		*val = e1000g_ksp->Rxerrc.value.ul +
372 		    e1000g_ksp->Algnerrc.value.ul +
373 		    e1000g_ksp->Rlec.value.ul +
374 		    e1000g_ksp->Crcerrs.value.ul +
375 		    e1000g_ksp->Cexterr.value.ul;
376 		break;
377 
378 	case MAC_STAT_NOXMTBUF:
379 		*val = Adapter->tx_ring->stat_no_desc;
380 		break;
381 
382 	case MAC_STAT_OERRORS:
383 		e1000g_ksp->Ecol.value.ul +=
384 		    E1000_READ_REG(hw, E1000_ECOL);
385 		*val = e1000g_ksp->Ecol.value.ul;
386 		break;
387 
388 	case MAC_STAT_COLLISIONS:
389 		e1000g_ksp->Colc.value.ul +=
390 		    E1000_READ_REG(hw, E1000_COLC);
391 		*val = e1000g_ksp->Colc.value.ul;
392 		break;
393 
394 	case MAC_STAT_RBYTES:
395 		/*
396 		 * The 64-bit register will reset whenever the upper
397 		 * 32 bits are read. So we need to read the lower
398 		 * 32 bits first, then read the upper 32 bits.
399 		 */
400 		low_val = E1000_READ_REG(hw, E1000_TORL);
401 		high_val = E1000_READ_REG(hw, E1000_TORH);
402 		*val = (uint64_t)e1000g_ksp->Torh.value.ul << 32 |
403 		    (uint64_t)e1000g_ksp->Torl.value.ul;
404 		*val += (uint64_t)high_val << 32 | (uint64_t)low_val;
405 
406 		e1000g_ksp->Torl.value.ul = (uint32_t)*val;
407 		e1000g_ksp->Torh.value.ul = (uint32_t)(*val >> 32);
408 		break;
409 
410 	case MAC_STAT_IPACKETS:
411 		e1000g_ksp->Tpr.value.ul +=
412 		    E1000_READ_REG(hw, E1000_TPR);
413 		*val = e1000g_ksp->Tpr.value.ul;
414 		break;
415 
416 	case MAC_STAT_OBYTES:
417 		/*
418 		 * The 64-bit register will reset whenever the upper
419 		 * 32 bits are read. So we need to read the lower
420 		 * 32 bits first, then read the upper 32 bits.
421 		 */
422 		low_val = E1000_READ_REG(hw, E1000_TOTL);
423 		high_val = E1000_READ_REG(hw, E1000_TOTH);
424 		*val = (uint64_t)e1000g_ksp->Toth.value.ul << 32 |
425 		    (uint64_t)e1000g_ksp->Totl.value.ul;
426 		*val += (uint64_t)high_val << 32 | (uint64_t)low_val;
427 
428 		e1000g_ksp->Totl.value.ul = (uint32_t)*val;
429 		e1000g_ksp->Toth.value.ul = (uint32_t)(*val >> 32);
430 		break;
431 
432 	case MAC_STAT_OPACKETS:
433 		e1000g_ksp->Tpt.value.ul +=
434 		    E1000_READ_REG(hw, E1000_TPT);
435 		*val = e1000g_ksp->Tpt.value.ul;
436 		break;
437 
438 	case ETHER_STAT_ALIGN_ERRORS:
439 		e1000g_ksp->Algnerrc.value.ul +=
440 		    E1000_READ_REG(hw, E1000_ALGNERRC);
441 		*val = e1000g_ksp->Algnerrc.value.ul;
442 		break;
443 
444 	case ETHER_STAT_FCS_ERRORS:
445 		e1000g_ksp->Crcerrs.value.ul +=
446 		    E1000_READ_REG(hw, E1000_CRCERRS);
447 		*val = e1000g_ksp->Crcerrs.value.ul;
448 		break;
449 
450 	case ETHER_STAT_SQE_ERRORS:
451 		e1000g_ksp->Sec.value.ul +=
452 		    E1000_READ_REG(hw, E1000_SEC);
453 		*val = e1000g_ksp->Sec.value.ul;
454 		break;
455 
456 	case ETHER_STAT_CARRIER_ERRORS:
457 		e1000g_ksp->Cexterr.value.ul +=
458 		    E1000_READ_REG(hw, E1000_CEXTERR);
459 		*val = e1000g_ksp->Cexterr.value.ul;
460 		break;
461 
462 	case ETHER_STAT_EX_COLLISIONS:
463 		e1000g_ksp->Ecol.value.ul +=
464 		    E1000_READ_REG(hw, E1000_ECOL);
465 		*val = e1000g_ksp->Ecol.value.ul;
466 		break;
467 
468 	case ETHER_STAT_TX_LATE_COLLISIONS:
469 		e1000g_ksp->Latecol.value.ul +=
470 		    E1000_READ_REG(hw, E1000_LATECOL);
471 		*val = e1000g_ksp->Latecol.value.ul;
472 		break;
473 
474 	case ETHER_STAT_DEFER_XMTS:
475 		e1000g_ksp->Dc.value.ul +=
476 		    E1000_READ_REG(hw, E1000_DC);
477 		*val = e1000g_ksp->Dc.value.ul;
478 		break;
479 
480 	case ETHER_STAT_FIRST_COLLISIONS:
481 		e1000g_ksp->Scc.value.ul +=
482 		    E1000_READ_REG(hw, E1000_SCC);
483 		*val = e1000g_ksp->Scc.value.ul;
484 		break;
485 
486 	case ETHER_STAT_MULTI_COLLISIONS:
487 		e1000g_ksp->Mcc.value.ul +=
488 		    E1000_READ_REG(hw, E1000_MCC);
489 		*val = e1000g_ksp->Mcc.value.ul;
490 		break;
491 
492 	case ETHER_STAT_MACRCV_ERRORS:
493 		e1000g_ksp->Rxerrc.value.ul +=
494 		    E1000_READ_REG(hw, E1000_RXERRC);
495 		*val = e1000g_ksp->Rxerrc.value.ul;
496 		break;
497 
498 	case ETHER_STAT_MACXMT_ERRORS:
499 		e1000g_ksp->Ecol.value.ul +=
500 		    E1000_READ_REG(hw, E1000_ECOL);
501 		*val = e1000g_ksp->Ecol.value.ul;
502 		break;
503 
504 	case ETHER_STAT_TOOLONG_ERRORS:
505 		e1000g_ksp->Roc.value.ul +=
506 		    E1000_READ_REG(hw, E1000_ROC);
507 		*val = e1000g_ksp->Roc.value.ul;
508 		break;
509 
510 	case ETHER_STAT_XCVR_ADDR:
511 		/* The Internal PHY's MDI address for each MAC is 1 */
512 		*val = 1;
513 		break;
514 
515 	case ETHER_STAT_XCVR_ID:
516 		*val = hw->phy.id | hw->phy.revision;
517 		break;
518 
519 	case ETHER_STAT_XCVR_INUSE:
520 		switch (Adapter->link_speed) {
521 		case SPEED_1000:
522 			*val =
523 			    (hw->phy.media_type == e1000_media_type_copper) ?
524 			    XCVR_1000T : XCVR_1000X;
525 			break;
526 		case SPEED_100:
527 			*val =
528 			    (hw->phy.media_type == e1000_media_type_copper) ?
529 			    (Adapter->phy_status & MII_SR_100T4_CAPS) ?
530 			    XCVR_100T4 : XCVR_100T2 : XCVR_100X;
531 			break;
532 		case SPEED_10:
533 			*val = XCVR_10;
534 			break;
535 		default:
536 			*val = XCVR_NONE;
537 			break;
538 		}
539 		break;
540 
541 	case ETHER_STAT_CAP_1000FDX:
542 		*val = Adapter->param_1000fdx_cap;
543 		break;
544 
545 	case ETHER_STAT_CAP_1000HDX:
546 		*val = Adapter->param_1000hdx_cap;
547 		break;
548 
549 	case ETHER_STAT_CAP_100FDX:
550 		*val = Adapter->param_100fdx_cap;
551 		break;
552 
553 	case ETHER_STAT_CAP_100HDX:
554 		*val = Adapter->param_100hdx_cap;
555 		break;
556 
557 	case ETHER_STAT_CAP_10FDX:
558 		*val = Adapter->param_10fdx_cap;
559 		break;
560 
561 	case ETHER_STAT_CAP_10HDX:
562 		*val = Adapter->param_10hdx_cap;
563 		break;
564 
565 	case ETHER_STAT_CAP_ASMPAUSE:
566 		*val = Adapter->param_asym_pause_cap;
567 		break;
568 
569 	case ETHER_STAT_CAP_PAUSE:
570 		*val = Adapter->param_pause_cap;
571 		break;
572 
573 	case ETHER_STAT_CAP_AUTONEG:
574 		*val = Adapter->param_autoneg_cap;
575 		break;
576 
577 	case ETHER_STAT_ADV_CAP_1000FDX:
578 		*val = Adapter->param_adv_1000fdx;
579 		break;
580 
581 	case ETHER_STAT_ADV_CAP_1000HDX:
582 		*val = Adapter->param_adv_1000hdx;
583 		break;
584 
585 	case ETHER_STAT_ADV_CAP_100FDX:
586 		*val = Adapter->param_adv_100fdx;
587 		break;
588 
589 	case ETHER_STAT_ADV_CAP_100HDX:
590 		*val = Adapter->param_adv_100hdx;
591 		break;
592 
593 	case ETHER_STAT_ADV_CAP_10FDX:
594 		*val = Adapter->param_adv_10fdx;
595 		break;
596 
597 	case ETHER_STAT_ADV_CAP_10HDX:
598 		*val = Adapter->param_adv_10hdx;
599 		break;
600 
601 	case ETHER_STAT_ADV_CAP_ASMPAUSE:
602 		*val = Adapter->param_adv_asym_pause;
603 		break;
604 
605 	case ETHER_STAT_ADV_CAP_PAUSE:
606 		*val = Adapter->param_adv_pause;
607 		break;
608 
609 	case ETHER_STAT_ADV_CAP_AUTONEG:
610 		*val = hw->mac.autoneg;
611 		break;
612 
613 	case ETHER_STAT_LP_CAP_1000FDX:
614 		*val = Adapter->param_lp_1000fdx;
615 		break;
616 
617 	case ETHER_STAT_LP_CAP_1000HDX:
618 		*val = Adapter->param_lp_1000hdx;
619 		break;
620 
621 	case ETHER_STAT_LP_CAP_100FDX:
622 		*val = Adapter->param_lp_100fdx;
623 		break;
624 
625 	case ETHER_STAT_LP_CAP_100HDX:
626 		*val = Adapter->param_lp_100hdx;
627 		break;
628 
629 	case ETHER_STAT_LP_CAP_10FDX:
630 		*val = Adapter->param_lp_10fdx;
631 		break;
632 
633 	case ETHER_STAT_LP_CAP_10HDX:
634 		*val = Adapter->param_lp_10hdx;
635 		break;
636 
637 	case ETHER_STAT_LP_CAP_ASMPAUSE:
638 		*val = Adapter->param_lp_asym_pause;
639 		break;
640 
641 	case ETHER_STAT_LP_CAP_PAUSE:
642 		*val = Adapter->param_lp_pause;
643 		break;
644 
645 	case ETHER_STAT_LP_CAP_AUTONEG:
646 		*val = Adapter->param_lp_autoneg;
647 		break;
648 
649 	case ETHER_STAT_LINK_ASMPAUSE:
650 		*val = Adapter->param_asym_pause_cap;
651 		break;
652 
653 	case ETHER_STAT_LINK_PAUSE:
654 		*val = Adapter->param_pause_cap;
655 		break;
656 
657 	case ETHER_STAT_LINK_AUTONEG:
658 		*val = hw->mac.autoneg;
659 		break;
660 
661 	case ETHER_STAT_LINK_DUPLEX:
662 		*val = (Adapter->link_duplex == FULL_DUPLEX) ?
663 		    LINK_DUPLEX_FULL : LINK_DUPLEX_HALF;
664 		break;
665 
666 	case ETHER_STAT_CAP_100T4:
667 		*val = Adapter->param_100t4_cap;
668 		break;
669 
670 	case ETHER_STAT_ADV_CAP_100T4:
671 		*val = Adapter->param_adv_100t4;
672 		break;
673 
674 	case ETHER_STAT_LP_CAP_100T4:
675 		*val = Adapter->param_lp_100t4;
676 		break;
677 
678 	default:
679 		rw_exit(&Adapter->chip_lock);
680 		return (ENOTSUP);
681 	}
682 
683 	rw_exit(&Adapter->chip_lock);
684 
685 	if (e1000g_check_acc_handle(Adapter->osdep.reg_handle) != DDI_FM_OK)
686 		ddi_fm_service_impact(Adapter->dip, DDI_SERVICE_UNAFFECTED);
687 
688 	return (0);
689 }
690 
691 /*
692  * e1000g_init_stats - initialize kstat data structures
693  *
694  * This routine will create and initialize the driver private
695  * statistics counters.
696  */
697 int
698 e1000g_init_stats(struct e1000g *Adapter)
699 {
700 	kstat_t *ksp;
701 	p_e1000g_stat_t e1000g_ksp;
702 
703 	/*
704 	 * Create and init kstat
705 	 */
706 	ksp = kstat_create(WSNAME, ddi_get_instance(Adapter->dip),
707 	    "statistics", "net", KSTAT_TYPE_NAMED,
708 	    sizeof (e1000g_stat_t) / sizeof (kstat_named_t), 0);
709 
710 	if (ksp == NULL) {
711 		e1000g_log(Adapter, CE_WARN,
712 		    "Could not create kernel statistics\n");
713 		return (DDI_FAILURE);
714 	}
715 
716 	Adapter->e1000g_ksp = ksp;	/* Fill in the Adapters ksp */
717 
718 	e1000g_ksp = (p_e1000g_stat_t)ksp->ks_data;
719 
720 	/*
721 	 * Initialize all the statistics
722 	 */
723 	kstat_named_init(&e1000g_ksp->link_speed, "link_speed",
724 	    KSTAT_DATA_ULONG);
725 	kstat_named_init(&e1000g_ksp->reset_count, "Reset Count",
726 	    KSTAT_DATA_ULONG);
727 
728 	kstat_named_init(&e1000g_ksp->rx_error, "Rx Error",
729 	    KSTAT_DATA_ULONG);
730 	kstat_named_init(&e1000g_ksp->rx_esballoc_fail, "Rx Desballoc Failure",
731 	    KSTAT_DATA_ULONG);
732 	kstat_named_init(&e1000g_ksp->rx_allocb_fail, "Rx Allocb Failure",
733 	    KSTAT_DATA_ULONG);
734 
735 	kstat_named_init(&e1000g_ksp->tx_no_desc, "Tx No Desc",
736 	    KSTAT_DATA_ULONG);
737 	kstat_named_init(&e1000g_ksp->tx_no_swpkt, "Tx No Buffer",
738 	    KSTAT_DATA_ULONG);
739 	kstat_named_init(&e1000g_ksp->tx_send_fail, "Tx Send Failure",
740 	    KSTAT_DATA_ULONG);
741 	kstat_named_init(&e1000g_ksp->tx_over_size, "Tx Pkt Over Size",
742 	    KSTAT_DATA_ULONG);
743 	kstat_named_init(&e1000g_ksp->tx_reschedule, "Tx Reschedule",
744 	    KSTAT_DATA_ULONG);
745 
746 	kstat_named_init(&e1000g_ksp->Mpc, "Recv_Missed_Packets",
747 	    KSTAT_DATA_ULONG);
748 	kstat_named_init(&e1000g_ksp->Symerrs, "Recv_Symbol_Errors",
749 	    KSTAT_DATA_ULONG);
750 	kstat_named_init(&e1000g_ksp->Rlec, "Recv_Length_Errors",
751 	    KSTAT_DATA_ULONG);
752 	kstat_named_init(&e1000g_ksp->Xonrxc, "XONs_Recvd",
753 	    KSTAT_DATA_ULONG);
754 	kstat_named_init(&e1000g_ksp->Xontxc, "XONs_Xmitd",
755 	    KSTAT_DATA_ULONG);
756 	kstat_named_init(&e1000g_ksp->Xoffrxc, "XOFFs_Recvd",
757 	    KSTAT_DATA_ULONG);
758 	kstat_named_init(&e1000g_ksp->Xofftxc, "XOFFs_Xmitd",
759 	    KSTAT_DATA_ULONG);
760 	kstat_named_init(&e1000g_ksp->Fcruc, "Recv_Unsupport_FC_Pkts",
761 	    KSTAT_DATA_ULONG);
762 #ifdef E1000G_DEBUG
763 	kstat_named_init(&e1000g_ksp->Prc64, "Pkts_Recvd_(  64b)",
764 	    KSTAT_DATA_ULONG);
765 	kstat_named_init(&e1000g_ksp->Prc127, "Pkts_Recvd_(  65- 127b)",
766 	    KSTAT_DATA_ULONG);
767 	kstat_named_init(&e1000g_ksp->Prc255, "Pkts_Recvd_( 127- 255b)",
768 	    KSTAT_DATA_ULONG);
769 	kstat_named_init(&e1000g_ksp->Prc511, "Pkts_Recvd_( 256- 511b)",
770 	    KSTAT_DATA_ULONG);
771 	kstat_named_init(&e1000g_ksp->Prc1023, "Pkts_Recvd_( 511-1023b)",
772 	    KSTAT_DATA_ULONG);
773 	kstat_named_init(&e1000g_ksp->Prc1522, "Pkts_Recvd_(1024-1522b)",
774 	    KSTAT_DATA_ULONG);
775 #endif
776 	kstat_named_init(&e1000g_ksp->Gprc, "Good_Pkts_Recvd",
777 	    KSTAT_DATA_ULONG);
778 	kstat_named_init(&e1000g_ksp->Gptc, "Good_Pkts_Xmitd",
779 	    KSTAT_DATA_ULONG);
780 	kstat_named_init(&e1000g_ksp->Gorl, "Good_Octets_Recvd_Lo",
781 	    KSTAT_DATA_ULONG);
782 	kstat_named_init(&e1000g_ksp->Gorh, "Good_Octets_Recvd_Hi",
783 	    KSTAT_DATA_ULONG);
784 	kstat_named_init(&e1000g_ksp->Gotl, "Good_Octets_Xmitd_Lo",
785 	    KSTAT_DATA_ULONG);
786 	kstat_named_init(&e1000g_ksp->Goth, "Good_Octets_Xmitd_Hi",
787 	    KSTAT_DATA_ULONG);
788 	kstat_named_init(&e1000g_ksp->Ruc, "Recv_Undersize",
789 	    KSTAT_DATA_ULONG);
790 	kstat_named_init(&e1000g_ksp->Rfc, "Recv_Frag",
791 	    KSTAT_DATA_ULONG);
792 	kstat_named_init(&e1000g_ksp->Roc, "Recv_Oversize",
793 	    KSTAT_DATA_ULONG);
794 	kstat_named_init(&e1000g_ksp->Rjc, "Recv_Jabber",
795 	    KSTAT_DATA_ULONG);
796 	kstat_named_init(&e1000g_ksp->Torl, "Total_Octets_Recvd_Lo",
797 	    KSTAT_DATA_ULONG);
798 	kstat_named_init(&e1000g_ksp->Torh, "Total_Octets_Recvd_Hi",
799 	    KSTAT_DATA_ULONG);
800 	kstat_named_init(&e1000g_ksp->Totl, "Total_Octets_Xmitd_Lo",
801 	    KSTAT_DATA_ULONG);
802 	kstat_named_init(&e1000g_ksp->Toth, "Total_Octets_Xmitd_Hi",
803 	    KSTAT_DATA_ULONG);
804 	kstat_named_init(&e1000g_ksp->Tpr, "Total_Packets_Recvd",
805 	    KSTAT_DATA_ULONG);
806 	kstat_named_init(&e1000g_ksp->Tpt, "Total_Packets_Xmitd",
807 	    KSTAT_DATA_ULONG);
808 #ifdef E1000G_DEBUG
809 	kstat_named_init(&e1000g_ksp->Ptc64, "Pkts_Xmitd_(  64b)",
810 	    KSTAT_DATA_ULONG);
811 	kstat_named_init(&e1000g_ksp->Ptc127, "Pkts_Xmitd_(  65- 127b)",
812 	    KSTAT_DATA_ULONG);
813 	kstat_named_init(&e1000g_ksp->Ptc255, "Pkts_Xmitd_( 128- 255b)",
814 	    KSTAT_DATA_ULONG);
815 	kstat_named_init(&e1000g_ksp->Ptc511, "Pkts_Xmitd_( 255- 511b)",
816 	    KSTAT_DATA_ULONG);
817 	kstat_named_init(&e1000g_ksp->Ptc1023, "Pkts_Xmitd_( 512-1023b)",
818 	    KSTAT_DATA_ULONG);
819 	kstat_named_init(&e1000g_ksp->Ptc1522, "Pkts_Xmitd_(1024-1522b)",
820 	    KSTAT_DATA_ULONG);
821 #endif
822 	kstat_named_init(&e1000g_ksp->Tncrs, "Xmit_with_No_CRS",
823 	    KSTAT_DATA_ULONG);
824 	kstat_named_init(&e1000g_ksp->Tsctc, "Xmit_TCP_Seg_Contexts",
825 	    KSTAT_DATA_ULONG);
826 	kstat_named_init(&e1000g_ksp->Tsctfc, "Xmit_TCP_Seg_Contexts_Fail",
827 	    KSTAT_DATA_ULONG);
828 
829 #ifdef E1000G_DEBUG
830 	kstat_named_init(&e1000g_ksp->rx_none, "Rx No Data",
831 	    KSTAT_DATA_ULONG);
832 	kstat_named_init(&e1000g_ksp->rx_multi_desc, "Rx Span Multi Desc",
833 	    KSTAT_DATA_ULONG);
834 	kstat_named_init(&e1000g_ksp->rx_no_freepkt, "Rx Freelist Empty",
835 	    KSTAT_DATA_ULONG);
836 	kstat_named_init(&e1000g_ksp->rx_avail_freepkt, "Rx Freelist Avail",
837 	    KSTAT_DATA_ULONG);
838 
839 	kstat_named_init(&e1000g_ksp->tx_under_size, "Tx Pkt Under Size",
840 	    KSTAT_DATA_ULONG);
841 	kstat_named_init(&e1000g_ksp->tx_exceed_frags, "Tx Exceed Max Frags",
842 	    KSTAT_DATA_ULONG);
843 	kstat_named_init(&e1000g_ksp->tx_empty_frags, "Tx Empty Frags",
844 	    KSTAT_DATA_ULONG);
845 	kstat_named_init(&e1000g_ksp->tx_recycle, "Tx Recycle",
846 	    KSTAT_DATA_ULONG);
847 	kstat_named_init(&e1000g_ksp->tx_recycle_intr, "Tx Recycle Intr",
848 	    KSTAT_DATA_ULONG);
849 	kstat_named_init(&e1000g_ksp->tx_recycle_retry, "Tx Recycle Retry",
850 	    KSTAT_DATA_ULONG);
851 	kstat_named_init(&e1000g_ksp->tx_recycle_none, "Tx Recycled None",
852 	    KSTAT_DATA_ULONG);
853 	kstat_named_init(&e1000g_ksp->tx_copy, "Tx Send Copy",
854 	    KSTAT_DATA_ULONG);
855 	kstat_named_init(&e1000g_ksp->tx_bind, "Tx Send Bind",
856 	    KSTAT_DATA_ULONG);
857 	kstat_named_init(&e1000g_ksp->tx_multi_copy, "Tx Copy Multi Frags",
858 	    KSTAT_DATA_ULONG);
859 	kstat_named_init(&e1000g_ksp->tx_multi_cookie, "Tx Bind Multi Cookies",
860 	    KSTAT_DATA_ULONG);
861 	kstat_named_init(&e1000g_ksp->tx_lack_desc, "Tx Desc Insufficient",
862 	    KSTAT_DATA_ULONG);
863 #endif
864 
865 	/*
866 	 * Function to provide kernel stat update on demand
867 	 */
868 	ksp->ks_update = e1000g_update_stats;
869 
870 	/*
871 	 * Pointer into provider's raw statistics
872 	 */
873 	ksp->ks_private = (void *)Adapter;
874 
875 	/*
876 	 * Add kstat to systems kstat chain
877 	 */
878 	kstat_install(ksp);
879 
880 	return (DDI_SUCCESS);
881 }
882