xref: /titanic_44/usr/src/uts/common/io/igb/igb_stat.c (revision a776e90690d98f629ab57f6493ff5949af9d65bd)
1 /*
2  * CDDL HEADER START
3  *
4  * Copyright(c) 2007-2008 Intel Corporation. All rights reserved.
5  * The contents of this file are subject to the terms of the
6  * Common Development and Distribution License (the "License").
7  * You may not use this file except in compliance with the License.
8  *
9  * You can obtain a copy of the license at:
10  *	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 using or redistributing this file, you may do so under the
15  * License only. No other modification of this header is permitted.
16  *
17  * If applicable, add the following below this CDDL HEADER, with the
18  * fields enclosed by brackets "[]" replaced with your own identifying
19  * information: Portions Copyright [yyyy] [name of copyright owner]
20  *
21  * CDDL HEADER END
22  */
23 
24 /*
25  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms of the CDDL.
27  */
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include "igb_sw.h"
32 
33 /*
34  * Update driver private statistics.
35  */
36 static int
37 igb_update_stats(kstat_t *ks, int rw)
38 {
39 	igb_t *igb;
40 	struct e1000_hw *hw;
41 	igb_stat_t *igb_ks;
42 	uint32_t val_low, val_high;
43 #ifdef IGB_DEBUG
44 	int i;
45 #endif
46 
47 	if (rw == KSTAT_WRITE)
48 		return (EACCES);
49 
50 	igb = (igb_t *)ks->ks_private;
51 	igb_ks = (igb_stat_t *)ks->ks_data;
52 	hw = &igb->hw;
53 
54 	mutex_enter(&igb->gen_lock);
55 
56 	/*
57 	 * Basic information.
58 	 */
59 	igb_ks->link_speed.value.ui64 = igb->link_speed;
60 
61 #ifdef IGB_DEBUG
62 	igb_ks->reset_count.value.ui64 = igb->reset_count;
63 
64 	igb_ks->rx_frame_error.value.ui64 = 0;
65 	igb_ks->rx_cksum_error.value.ui64 = 0;
66 	igb_ks->rx_exceed_pkt.value.ui64 = 0;
67 	for (i = 0; i < igb->num_rx_rings; i++) {
68 		igb_ks->rx_frame_error.value.ui64 +=
69 		    igb->rx_rings[i].stat_frame_error;
70 		igb_ks->rx_cksum_error.value.ui64 +=
71 		    igb->rx_rings[i].stat_cksum_error;
72 		igb_ks->rx_exceed_pkt.value.ui64 +=
73 		    igb->rx_rings[i].stat_exceed_pkt;
74 	}
75 
76 	igb_ks->tx_overload.value.ui64 = 0;
77 	igb_ks->tx_fail_no_tbd.value.ui64 = 0;
78 	igb_ks->tx_fail_no_tcb.value.ui64 = 0;
79 	igb_ks->tx_fail_dma_bind.value.ui64 = 0;
80 	igb_ks->tx_reschedule.value.ui64 = 0;
81 	for (i = 0; i < igb->num_tx_rings; i++) {
82 		igb_ks->tx_overload.value.ui64 +=
83 		    igb->tx_rings[i].stat_overload;
84 		igb_ks->tx_fail_no_tbd.value.ui64 +=
85 		    igb->tx_rings[i].stat_fail_no_tbd;
86 		igb_ks->tx_fail_no_tcb.value.ui64 +=
87 		    igb->tx_rings[i].stat_fail_no_tcb;
88 		igb_ks->tx_fail_dma_bind.value.ui64 +=
89 		    igb->tx_rings[i].stat_fail_dma_bind;
90 		igb_ks->tx_reschedule.value.ui64 +=
91 		    igb->tx_rings[i].stat_reschedule;
92 	}
93 
94 	/*
95 	 * Hardware calculated statistics.
96 	 */
97 	igb_ks->gprc.value.ul += E1000_READ_REG(hw, E1000_GPRC);
98 	igb_ks->gptc.value.ul += E1000_READ_REG(hw, E1000_GPTC);
99 	igb_ks->prc64.value.ul += E1000_READ_REG(hw, E1000_PRC64);
100 	igb_ks->prc127.value.ul += E1000_READ_REG(hw, E1000_PRC127);
101 	igb_ks->prc255.value.ul += E1000_READ_REG(hw, E1000_PRC255);
102 	igb_ks->prc511.value.ul += E1000_READ_REG(hw, E1000_PRC511);
103 	igb_ks->prc1023.value.ul += E1000_READ_REG(hw, E1000_PRC1023);
104 	igb_ks->prc1522.value.ul += E1000_READ_REG(hw, E1000_PRC1522);
105 	igb_ks->ptc64.value.ul += E1000_READ_REG(hw, E1000_PTC64);
106 	igb_ks->ptc127.value.ul += E1000_READ_REG(hw, E1000_PTC127);
107 	igb_ks->ptc255.value.ul += E1000_READ_REG(hw, E1000_PTC255);
108 	igb_ks->ptc511.value.ul += E1000_READ_REG(hw, E1000_PTC511);
109 	igb_ks->ptc1023.value.ul += E1000_READ_REG(hw, E1000_PTC1023);
110 	igb_ks->ptc1522.value.ul += E1000_READ_REG(hw, E1000_PTC1522);
111 
112 	/*
113 	 * The 64-bit register will reset whenever the upper
114 	 * 32 bits are read. So we need to read the lower
115 	 * 32 bits first, then read the upper 32 bits.
116 	 */
117 	val_low = E1000_READ_REG(hw, E1000_GORCL);
118 	val_high = E1000_READ_REG(hw, E1000_GORCH);
119 	igb_ks->gor.value.ui64 += (uint64_t)val_high << 32 | (uint64_t)val_low;
120 
121 	val_low = E1000_READ_REG(hw, E1000_GOTCL);
122 	val_high = E1000_READ_REG(hw, E1000_GOTCH);
123 	igb_ks->got.value.ui64 += (uint64_t)val_high << 32 | (uint64_t)val_low;
124 #endif
125 
126 	igb_ks->symerrs.value.ui64 += E1000_READ_REG(hw, E1000_SYMERRS);
127 	igb_ks->mpc.value.ui64 += E1000_READ_REG(hw, E1000_MPC);
128 	igb_ks->rlec.value.ui64 += E1000_READ_REG(hw, E1000_RLEC);
129 	igb_ks->fcruc.value.ui64 += E1000_READ_REG(hw, E1000_FCRUC);
130 	igb_ks->rfc.value.ul += E1000_READ_REG(hw, E1000_RFC);
131 	igb_ks->tncrs.value.ul += E1000_READ_REG(hw, E1000_TNCRS);
132 	igb_ks->tsctc.value.ul += E1000_READ_REG(hw, E1000_TSCTC);
133 	igb_ks->tsctfc.value.ul += E1000_READ_REG(hw, E1000_TSCTFC);
134 	igb_ks->xonrxc.value.ui64 += E1000_READ_REG(hw, E1000_XONRXC);
135 	igb_ks->xontxc.value.ui64 += E1000_READ_REG(hw, E1000_XONTXC);
136 	igb_ks->xoffrxc.value.ui64 += E1000_READ_REG(hw, E1000_XOFFRXC);
137 	igb_ks->xofftxc.value.ui64 += E1000_READ_REG(hw, E1000_XOFFTXC);
138 
139 	mutex_exit(&igb->gen_lock);
140 
141 	return (0);
142 }
143 
144 /*
145  * Create and initialize the driver private statistics.
146  */
147 int
148 igb_init_stats(igb_t *igb)
149 {
150 	kstat_t *ks;
151 	igb_stat_t *igb_ks;
152 
153 	/*
154 	 * Create and init kstat
155 	 */
156 	ks = kstat_create(MODULE_NAME, ddi_get_instance(igb->dip),
157 	    "statistics", "net", KSTAT_TYPE_NAMED,
158 	    sizeof (igb_stat_t) / sizeof (kstat_named_t), 0);
159 
160 	if (ks == NULL) {
161 		igb_error(igb,
162 		    "Could not create kernel statistics");
163 		return (IGB_FAILURE);
164 	}
165 
166 	igb->igb_ks = ks;
167 
168 	igb_ks = (igb_stat_t *)ks->ks_data;
169 
170 	/*
171 	 * Initialize all the statistics.
172 	 */
173 	kstat_named_init(&igb_ks->link_speed, "link_speed",
174 	    KSTAT_DATA_UINT64);
175 
176 #ifdef IGB_DEBUG
177 	kstat_named_init(&igb_ks->reset_count, "reset_count",
178 	    KSTAT_DATA_UINT64);
179 	kstat_named_init(&igb_ks->rx_frame_error, "rx_frame_error",
180 	    KSTAT_DATA_UINT64);
181 	kstat_named_init(&igb_ks->rx_cksum_error, "rx_cksum_error",
182 	    KSTAT_DATA_UINT64);
183 	kstat_named_init(&igb_ks->rx_exceed_pkt, "rx_exceed_pkt",
184 	    KSTAT_DATA_UINT64);
185 	kstat_named_init(&igb_ks->tx_overload, "tx_overload",
186 	    KSTAT_DATA_UINT64);
187 	kstat_named_init(&igb_ks->tx_fail_no_tbd, "tx_fail_no_tbd",
188 	    KSTAT_DATA_UINT64);
189 	kstat_named_init(&igb_ks->tx_fail_no_tcb, "tx_fail_no_tcb",
190 	    KSTAT_DATA_UINT64);
191 	kstat_named_init(&igb_ks->tx_fail_dma_bind, "tx_fail_dma_bind",
192 	    KSTAT_DATA_UINT64);
193 	kstat_named_init(&igb_ks->tx_reschedule, "tx_reschedule",
194 	    KSTAT_DATA_UINT64);
195 
196 	kstat_named_init(&igb_ks->gprc, "good_pkts_recvd",
197 	    KSTAT_DATA_UINT64);
198 	kstat_named_init(&igb_ks->gptc, "good_pkts_xmitd",
199 	    KSTAT_DATA_UINT64);
200 	kstat_named_init(&igb_ks->gor, "good_octets_recvd",
201 	    KSTAT_DATA_UINT64);
202 	kstat_named_init(&igb_ks->got, "good_octets_xmitd",
203 	    KSTAT_DATA_UINT64);
204 	kstat_named_init(&igb_ks->prc64, "pkts_recvd_(  64b)",
205 	    KSTAT_DATA_UINT64);
206 	kstat_named_init(&igb_ks->prc127, "pkts_recvd_(  65- 127b)",
207 	    KSTAT_DATA_UINT64);
208 	kstat_named_init(&igb_ks->prc255, "pkts_recvd_( 127- 255b)",
209 	    KSTAT_DATA_UINT64);
210 	kstat_named_init(&igb_ks->prc511, "pkts_recvd_( 256- 511b)",
211 	    KSTAT_DATA_UINT64);
212 	kstat_named_init(&igb_ks->prc1023, "pkts_recvd_( 511-1023b)",
213 	    KSTAT_DATA_UINT64);
214 	kstat_named_init(&igb_ks->prc1522, "pkts_recvd_(1024-1522b)",
215 	    KSTAT_DATA_UINT64);
216 	kstat_named_init(&igb_ks->ptc64, "pkts_xmitd_(  64b)",
217 	    KSTAT_DATA_UINT64);
218 	kstat_named_init(&igb_ks->ptc127, "pkts_xmitd_(  65- 127b)",
219 	    KSTAT_DATA_UINT64);
220 	kstat_named_init(&igb_ks->ptc255, "pkts_xmitd_( 128- 255b)",
221 	    KSTAT_DATA_UINT64);
222 	kstat_named_init(&igb_ks->ptc511, "pkts_xmitd_( 255- 511b)",
223 	    KSTAT_DATA_UINT64);
224 	kstat_named_init(&igb_ks->ptc1023, "pkts_xmitd_( 512-1023b)",
225 	    KSTAT_DATA_UINT64);
226 	kstat_named_init(&igb_ks->ptc1522, "pkts_xmitd_(1024-1522b)",
227 	    KSTAT_DATA_UINT64);
228 #endif
229 
230 	kstat_named_init(&igb_ks->symerrs, "recv_symbol_errors",
231 	    KSTAT_DATA_UINT64);
232 	kstat_named_init(&igb_ks->mpc, "recv_missed_packets",
233 	    KSTAT_DATA_UINT64);
234 	kstat_named_init(&igb_ks->rlec, "recv_length_errors",
235 	    KSTAT_DATA_UINT64);
236 	kstat_named_init(&igb_ks->fcruc, "recv_unsupport_FC_pkts",
237 	    KSTAT_DATA_UINT64);
238 	kstat_named_init(&igb_ks->rfc, "recv_frag",
239 	    KSTAT_DATA_UINT64);
240 	kstat_named_init(&igb_ks->tncrs, "xmit_with_no_CRS",
241 	    KSTAT_DATA_UINT64);
242 	kstat_named_init(&igb_ks->tsctc, "xmit_TCP_seg_contexts",
243 	    KSTAT_DATA_UINT64);
244 	kstat_named_init(&igb_ks->tsctfc, "xmit_TCP_seg_contexts_fail",
245 	    KSTAT_DATA_UINT64);
246 	kstat_named_init(&igb_ks->xonrxc, "XONs_recvd",
247 	    KSTAT_DATA_UINT64);
248 	kstat_named_init(&igb_ks->xontxc, "XONs_xmitd",
249 	    KSTAT_DATA_UINT64);
250 	kstat_named_init(&igb_ks->xoffrxc, "XOFFs_recvd",
251 	    KSTAT_DATA_UINT64);
252 	kstat_named_init(&igb_ks->xofftxc, "XOFFs_xmitd",
253 	    KSTAT_DATA_UINT64);
254 
255 	/*
256 	 * Function to provide kernel stat update on demand
257 	 */
258 	ks->ks_update = igb_update_stats;
259 
260 	ks->ks_private = (void *)igb;
261 
262 	/*
263 	 * Add kstat to systems kstat chain
264 	 */
265 	kstat_install(ks);
266 
267 	return (IGB_SUCCESS);
268 }
269