xref: /titanic_44/usr/src/uts/common/io/ixgbe/ixgbe_stat.c (revision ee0eb9f2d12b8a03b5a193cd667735c1962e0c7b)
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 "ixgbe_sw.h"
32 
33 /*
34  * Update driver private statistics.
35  */
36 static int
37 ixgbe_update_stats(kstat_t *ks, int rw)
38 {
39 	ixgbe_t *ixgbe;
40 	struct ixgbe_hw *hw;
41 	ixgbe_stat_t *ixgbe_ks;
42 	int i;
43 
44 	if (rw == KSTAT_WRITE)
45 		return (EACCES);
46 
47 	ixgbe = (ixgbe_t *)ks->ks_private;
48 	ixgbe_ks = (ixgbe_stat_t *)ks->ks_data;
49 	hw = &ixgbe->hw;
50 
51 	mutex_enter(&ixgbe->gen_lock);
52 
53 	/*
54 	 * Basic information
55 	 */
56 	ixgbe_ks->link_speed.value.ui64 = ixgbe->link_speed;
57 
58 #ifdef IXGBE_DEBUG
59 	ixgbe_ks->reset_count.value.ui64 = ixgbe->reset_count;
60 
61 	ixgbe_ks->rx_frame_error.value.ui64 = 0;
62 	ixgbe_ks->rx_cksum_error.value.ui64 = 0;
63 	ixgbe_ks->rx_exceed_pkt.value.ui64 = 0;
64 	for (i = 0; i < ixgbe->num_rx_rings; i++) {
65 		ixgbe_ks->rx_frame_error.value.ui64 +=
66 		    ixgbe->rx_rings[i].stat_frame_error;
67 		ixgbe_ks->rx_cksum_error.value.ui64 +=
68 		    ixgbe->rx_rings[i].stat_cksum_error;
69 		ixgbe_ks->rx_exceed_pkt.value.ui64 +=
70 		    ixgbe->rx_rings[i].stat_exceed_pkt;
71 	}
72 
73 	ixgbe_ks->tx_overload.value.ui64 = 0;
74 	ixgbe_ks->tx_fail_no_tbd.value.ui64 = 0;
75 	ixgbe_ks->tx_fail_no_tcb.value.ui64 = 0;
76 	ixgbe_ks->tx_fail_dma_bind.value.ui64 = 0;
77 	ixgbe_ks->tx_reschedule.value.ui64 = 0;
78 	for (i = 0; i < ixgbe->num_tx_rings; i++) {
79 		ixgbe_ks->tx_overload.value.ui64 +=
80 		    ixgbe->tx_rings[i].stat_overload;
81 		ixgbe_ks->tx_fail_no_tbd.value.ui64 +=
82 		    ixgbe->tx_rings[i].stat_fail_no_tbd;
83 		ixgbe_ks->tx_fail_no_tcb.value.ui64 +=
84 		    ixgbe->tx_rings[i].stat_fail_no_tcb;
85 		ixgbe_ks->tx_fail_dma_bind.value.ui64 +=
86 		    ixgbe->tx_rings[i].stat_fail_dma_bind;
87 		ixgbe_ks->tx_reschedule.value.ui64 +=
88 		    ixgbe->tx_rings[i].stat_reschedule;
89 	}
90 
91 	/*
92 	 * Hardware calculated statistics.
93 	 */
94 	for (i = 0; i < 16; i++) {
95 		ixgbe_ks->gprc.value.ul += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
96 		ixgbe_ks->gptc.value.ul += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
97 		ixgbe_ks->tor.value.ui64 += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
98 		ixgbe_ks->tot.value.ui64 += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
99 	}
100 
101 	/*
102 	 * This is a Workaround:
103 	 * Currently h/w GORCH, GOTCH, TORH registers are not
104 	 * correctly implemented. We found that the values in
105 	 * these registers are same as those in corresponding
106 	 * *L registers (i.e. GORCL, GOTCL, and TORL). Here the
107 	 * gor and got stat data will not be retrieved through
108 	 * GORC{H/L} and GOTC{H/L} registers but be obtained by
109 	 * simply assigning tor/tot stat data, so the gor/got
110 	 * stat data will not be accurate.
111 	 */
112 	ixgbe_ks->gor.value.ui64 = ixgbe_ks->tor.value.ui64;
113 	ixgbe_ks->got.value.ui64 = ixgbe_ks->tot.value.ui64;
114 
115 	ixgbe_ks->prc64.value.ul += IXGBE_READ_REG(hw, IXGBE_PRC64);
116 	ixgbe_ks->prc127.value.ul += IXGBE_READ_REG(hw, IXGBE_PRC127);
117 	ixgbe_ks->prc255.value.ul += IXGBE_READ_REG(hw, IXGBE_PRC255);
118 	ixgbe_ks->prc511.value.ul += IXGBE_READ_REG(hw, IXGBE_PRC511);
119 	ixgbe_ks->prc1023.value.ul += IXGBE_READ_REG(hw, IXGBE_PRC1023);
120 	ixgbe_ks->prc1522.value.ul += IXGBE_READ_REG(hw, IXGBE_PRC1522);
121 	ixgbe_ks->ptc64.value.ul += IXGBE_READ_REG(hw, IXGBE_PTC64);
122 	ixgbe_ks->ptc127.value.ul += IXGBE_READ_REG(hw, IXGBE_PTC127);
123 	ixgbe_ks->ptc255.value.ul += IXGBE_READ_REG(hw, IXGBE_PTC255);
124 	ixgbe_ks->ptc511.value.ul += IXGBE_READ_REG(hw, IXGBE_PTC511);
125 	ixgbe_ks->ptc1023.value.ul += IXGBE_READ_REG(hw, IXGBE_PTC1023);
126 	ixgbe_ks->ptc1522.value.ul += IXGBE_READ_REG(hw, IXGBE_PTC1522);
127 #endif
128 
129 	ixgbe_ks->mspdc.value.ui64 += IXGBE_READ_REG(hw, IXGBE_MSPDC);
130 	for (i = 0; i < 8; i++)
131 		ixgbe_ks->mpc.value.ui64 += IXGBE_READ_REG(hw, IXGBE_MPC(i));
132 	ixgbe_ks->mlfc.value.ui64 += IXGBE_READ_REG(hw, IXGBE_MLFC);
133 	ixgbe_ks->mrfc.value.ui64 += IXGBE_READ_REG(hw, IXGBE_MRFC);
134 	ixgbe_ks->rlec.value.ui64 += IXGBE_READ_REG(hw, IXGBE_RLEC);
135 	ixgbe_ks->lxontxc.value.ui64 += IXGBE_READ_REG(hw, IXGBE_LXONTXC);
136 	ixgbe_ks->lxonrxc.value.ui64 += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
137 	ixgbe_ks->lxofftxc.value.ui64 += IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
138 	ixgbe_ks->lxoffrxc.value.ui64 += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
139 	ixgbe_ks->ruc.value.ui64 += IXGBE_READ_REG(hw, IXGBE_RUC);
140 	ixgbe_ks->rfc.value.ui64 += IXGBE_READ_REG(hw, IXGBE_RFC);
141 	ixgbe_ks->roc.value.ui64 += IXGBE_READ_REG(hw, IXGBE_ROC);
142 	ixgbe_ks->rjc.value.ui64 += IXGBE_READ_REG(hw, IXGBE_RJC);
143 
144 	mutex_exit(&ixgbe->gen_lock);
145 
146 	if (ixgbe_check_acc_handle(ixgbe->osdep.reg_handle) != DDI_FM_OK)
147 		ddi_fm_service_impact(ixgbe->dip, DDI_SERVICE_UNAFFECTED);
148 
149 	return (0);
150 }
151 
152 /*
153  * Create and initialize the driver private statistics.
154  */
155 int
156 ixgbe_init_stats(ixgbe_t *ixgbe)
157 {
158 	kstat_t *ks;
159 	ixgbe_stat_t *ixgbe_ks;
160 
161 	/*
162 	 * Create and init kstat
163 	 */
164 	ks = kstat_create(MODULE_NAME, ddi_get_instance(ixgbe->dip),
165 	    "statistics", "net", KSTAT_TYPE_NAMED,
166 	    sizeof (ixgbe_stat_t) / sizeof (kstat_named_t), 0);
167 
168 	if (ks == NULL) {
169 		ixgbe_error(ixgbe,
170 		    "Could not create kernel statistics");
171 		return (IXGBE_FAILURE);
172 	}
173 
174 	ixgbe->ixgbe_ks = ks;
175 
176 	ixgbe_ks = (ixgbe_stat_t *)ks->ks_data;
177 
178 	/*
179 	 * Initialize all the statistics.
180 	 */
181 	kstat_named_init(&ixgbe_ks->link_speed, "link_speed",
182 	    KSTAT_DATA_UINT64);
183 
184 #ifdef IXGBE_DEBUG
185 	kstat_named_init(&ixgbe_ks->reset_count, "reset_count",
186 	    KSTAT_DATA_UINT64);
187 	kstat_named_init(&ixgbe_ks->rx_frame_error, "rx_frame_error",
188 	    KSTAT_DATA_UINT64);
189 	kstat_named_init(&ixgbe_ks->rx_cksum_error, "rx_cksum_error",
190 	    KSTAT_DATA_UINT64);
191 	kstat_named_init(&ixgbe_ks->rx_exceed_pkt, "rx_exceed_pkt",
192 	    KSTAT_DATA_UINT64);
193 	kstat_named_init(&ixgbe_ks->tx_overload, "tx_overload",
194 	    KSTAT_DATA_UINT64);
195 	kstat_named_init(&ixgbe_ks->tx_fail_no_tbd, "tx_fail_no_tbd",
196 	    KSTAT_DATA_UINT64);
197 	kstat_named_init(&ixgbe_ks->tx_fail_no_tcb, "tx_fail_no_tcb",
198 	    KSTAT_DATA_UINT64);
199 	kstat_named_init(&ixgbe_ks->tx_fail_dma_bind, "tx_fail_dma_bind",
200 	    KSTAT_DATA_UINT64);
201 	kstat_named_init(&ixgbe_ks->tx_reschedule, "tx_reschedule",
202 	    KSTAT_DATA_UINT64);
203 
204 	kstat_named_init(&ixgbe_ks->gprc, "good_pkts_recvd",
205 	    KSTAT_DATA_UINT64);
206 	kstat_named_init(&ixgbe_ks->gptc, "good_pkts_xmitd",
207 	    KSTAT_DATA_UINT64);
208 	kstat_named_init(&ixgbe_ks->gor, "good_octets_recvd",
209 	    KSTAT_DATA_UINT64);
210 	kstat_named_init(&ixgbe_ks->got, "good_octets_xmitd",
211 	    KSTAT_DATA_UINT64);
212 	kstat_named_init(&ixgbe_ks->prc64, "pkts_recvd_(  64b)",
213 	    KSTAT_DATA_UINT64);
214 	kstat_named_init(&ixgbe_ks->prc127, "pkts_recvd_(  65- 127b)",
215 	    KSTAT_DATA_UINT64);
216 	kstat_named_init(&ixgbe_ks->prc255, "pkts_recvd_( 127- 255b)",
217 	    KSTAT_DATA_UINT64);
218 	kstat_named_init(&ixgbe_ks->prc511, "pkts_recvd_( 256- 511b)",
219 	    KSTAT_DATA_UINT64);
220 	kstat_named_init(&ixgbe_ks->prc1023, "pkts_recvd_( 511-1023b)",
221 	    KSTAT_DATA_UINT64);
222 	kstat_named_init(&ixgbe_ks->prc1522, "pkts_recvd_(1024-1522b)",
223 	    KSTAT_DATA_UINT64);
224 	kstat_named_init(&ixgbe_ks->ptc64, "pkts_xmitd_(  64b)",
225 	    KSTAT_DATA_UINT64);
226 	kstat_named_init(&ixgbe_ks->ptc127, "pkts_xmitd_(  65- 127b)",
227 	    KSTAT_DATA_UINT64);
228 	kstat_named_init(&ixgbe_ks->ptc255, "pkts_xmitd_( 128- 255b)",
229 	    KSTAT_DATA_UINT64);
230 	kstat_named_init(&ixgbe_ks->ptc511, "pkts_xmitd_( 255- 511b)",
231 	    KSTAT_DATA_UINT64);
232 	kstat_named_init(&ixgbe_ks->ptc1023, "pkts_xmitd_( 512-1023b)",
233 	    KSTAT_DATA_UINT64);
234 	kstat_named_init(&ixgbe_ks->ptc1522, "pkts_xmitd_(1024-1522b)",
235 	    KSTAT_DATA_UINT64);
236 #endif
237 
238 	kstat_named_init(&ixgbe_ks->mspdc, "mac_short_packet_discard",
239 	    KSTAT_DATA_UINT64);
240 	kstat_named_init(&ixgbe_ks->mpc, "missed_packets",
241 	    KSTAT_DATA_UINT64);
242 	kstat_named_init(&ixgbe_ks->mlfc, "mac_local_fault",
243 	    KSTAT_DATA_UINT64);
244 	kstat_named_init(&ixgbe_ks->mrfc, "mac_remote_fault",
245 	    KSTAT_DATA_UINT64);
246 	kstat_named_init(&ixgbe_ks->rlec, "recv_length_err",
247 	    KSTAT_DATA_UINT64);
248 	kstat_named_init(&ixgbe_ks->lxontxc, "link_xon_xmitd",
249 	    KSTAT_DATA_UINT64);
250 	kstat_named_init(&ixgbe_ks->lxonrxc, "link_xon_recvd",
251 	    KSTAT_DATA_UINT64);
252 	kstat_named_init(&ixgbe_ks->lxofftxc, "link_xoff_xmitd",
253 	    KSTAT_DATA_UINT64);
254 	kstat_named_init(&ixgbe_ks->lxoffrxc, "link_xoff_recvd",
255 	    KSTAT_DATA_UINT64);
256 	kstat_named_init(&ixgbe_ks->ruc, "recv_undersize",
257 	    KSTAT_DATA_UINT64);
258 	kstat_named_init(&ixgbe_ks->rfc, "recv_fragment",
259 	    KSTAT_DATA_UINT64);
260 	kstat_named_init(&ixgbe_ks->roc, "recv_oversize",
261 	    KSTAT_DATA_UINT64);
262 	kstat_named_init(&ixgbe_ks->rjc, "recv_jabber",
263 	    KSTAT_DATA_UINT64);
264 
265 	/*
266 	 * Function to provide kernel stat update on demand
267 	 */
268 	ks->ks_update = ixgbe_update_stats;
269 
270 	ks->ks_private = (void *)ixgbe;
271 
272 	/*
273 	 * Add kstat to systems kstat chain
274 	 */
275 	kstat_install(ks);
276 
277 	return (IXGBE_SUCCESS);
278 }
279