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