xref: /titanic_50/usr/src/uts/common/io/ixgbe/ixgbe_stat.c (revision fa25784ca4b51c206177d891a654f1d36a25d41f)
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->got.value.ui64 += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
99 	}
100 	ixgbe_ks->gor.value.ui64 = ixgbe_ks->tor.value.ui64;
101 
102 	ixgbe_ks->prc64.value.ul += IXGBE_READ_REG(hw, IXGBE_PRC64);
103 	ixgbe_ks->prc127.value.ul += IXGBE_READ_REG(hw, IXGBE_PRC127);
104 	ixgbe_ks->prc255.value.ul += IXGBE_READ_REG(hw, IXGBE_PRC255);
105 	ixgbe_ks->prc511.value.ul += IXGBE_READ_REG(hw, IXGBE_PRC511);
106 	ixgbe_ks->prc1023.value.ul += IXGBE_READ_REG(hw, IXGBE_PRC1023);
107 	ixgbe_ks->prc1522.value.ul += IXGBE_READ_REG(hw, IXGBE_PRC1522);
108 	ixgbe_ks->ptc64.value.ul += IXGBE_READ_REG(hw, IXGBE_PTC64);
109 	ixgbe_ks->ptc127.value.ul += IXGBE_READ_REG(hw, IXGBE_PTC127);
110 	ixgbe_ks->ptc255.value.ul += IXGBE_READ_REG(hw, IXGBE_PTC255);
111 	ixgbe_ks->ptc511.value.ul += IXGBE_READ_REG(hw, IXGBE_PTC511);
112 	ixgbe_ks->ptc1023.value.ul += IXGBE_READ_REG(hw, IXGBE_PTC1023);
113 	ixgbe_ks->ptc1522.value.ul += IXGBE_READ_REG(hw, IXGBE_PTC1522);
114 #endif
115 
116 	ixgbe_ks->mspdc.value.ui64 += IXGBE_READ_REG(hw, IXGBE_MSPDC);
117 	for (i = 0; i < 8; i++)
118 		ixgbe_ks->mpc.value.ui64 += IXGBE_READ_REG(hw, IXGBE_MPC(i));
119 	ixgbe_ks->mlfc.value.ui64 += IXGBE_READ_REG(hw, IXGBE_MLFC);
120 	ixgbe_ks->mrfc.value.ui64 += IXGBE_READ_REG(hw, IXGBE_MRFC);
121 	ixgbe_ks->rlec.value.ui64 += IXGBE_READ_REG(hw, IXGBE_RLEC);
122 	ixgbe_ks->lxontxc.value.ui64 += IXGBE_READ_REG(hw, IXGBE_LXONTXC);
123 	ixgbe_ks->lxonrxc.value.ui64 += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
124 	ixgbe_ks->lxofftxc.value.ui64 += IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
125 	ixgbe_ks->lxoffrxc.value.ui64 += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
126 	ixgbe_ks->ruc.value.ui64 += IXGBE_READ_REG(hw, IXGBE_RUC);
127 	ixgbe_ks->rfc.value.ui64 += IXGBE_READ_REG(hw, IXGBE_RFC);
128 	ixgbe_ks->roc.value.ui64 += IXGBE_READ_REG(hw, IXGBE_ROC);
129 	ixgbe_ks->rjc.value.ui64 += IXGBE_READ_REG(hw, IXGBE_RJC);
130 
131 	mutex_exit(&ixgbe->gen_lock);
132 
133 	if (ixgbe_check_acc_handle(ixgbe->osdep.reg_handle) != DDI_FM_OK)
134 		ddi_fm_service_impact(ixgbe->dip, DDI_SERVICE_UNAFFECTED);
135 
136 	return (0);
137 }
138 
139 /*
140  * Create and initialize the driver private statistics.
141  */
142 int
143 ixgbe_init_stats(ixgbe_t *ixgbe)
144 {
145 	kstat_t *ks;
146 	ixgbe_stat_t *ixgbe_ks;
147 
148 	/*
149 	 * Create and init kstat
150 	 */
151 	ks = kstat_create(MODULE_NAME, ddi_get_instance(ixgbe->dip),
152 	    "statistics", "net", KSTAT_TYPE_NAMED,
153 	    sizeof (ixgbe_stat_t) / sizeof (kstat_named_t), 0);
154 
155 	if (ks == NULL) {
156 		ixgbe_error(ixgbe,
157 		    "Could not create kernel statistics");
158 		return (IXGBE_FAILURE);
159 	}
160 
161 	ixgbe->ixgbe_ks = ks;
162 
163 	ixgbe_ks = (ixgbe_stat_t *)ks->ks_data;
164 
165 	/*
166 	 * Initialize all the statistics.
167 	 */
168 	kstat_named_init(&ixgbe_ks->link_speed, "link_speed",
169 	    KSTAT_DATA_UINT64);
170 
171 #ifdef IXGBE_DEBUG
172 	kstat_named_init(&ixgbe_ks->reset_count, "reset_count",
173 	    KSTAT_DATA_UINT64);
174 	kstat_named_init(&ixgbe_ks->rx_frame_error, "rx_frame_error",
175 	    KSTAT_DATA_UINT64);
176 	kstat_named_init(&ixgbe_ks->rx_cksum_error, "rx_cksum_error",
177 	    KSTAT_DATA_UINT64);
178 	kstat_named_init(&ixgbe_ks->rx_exceed_pkt, "rx_exceed_pkt",
179 	    KSTAT_DATA_UINT64);
180 	kstat_named_init(&ixgbe_ks->tx_overload, "tx_overload",
181 	    KSTAT_DATA_UINT64);
182 	kstat_named_init(&ixgbe_ks->tx_fail_no_tbd, "tx_fail_no_tbd",
183 	    KSTAT_DATA_UINT64);
184 	kstat_named_init(&ixgbe_ks->tx_fail_no_tcb, "tx_fail_no_tcb",
185 	    KSTAT_DATA_UINT64);
186 	kstat_named_init(&ixgbe_ks->tx_fail_dma_bind, "tx_fail_dma_bind",
187 	    KSTAT_DATA_UINT64);
188 	kstat_named_init(&ixgbe_ks->tx_reschedule, "tx_reschedule",
189 	    KSTAT_DATA_UINT64);
190 
191 	kstat_named_init(&ixgbe_ks->gprc, "good_pkts_recvd",
192 	    KSTAT_DATA_UINT64);
193 	kstat_named_init(&ixgbe_ks->gptc, "good_pkts_xmitd",
194 	    KSTAT_DATA_UINT64);
195 	kstat_named_init(&ixgbe_ks->gor, "good_octets_recvd",
196 	    KSTAT_DATA_UINT64);
197 	kstat_named_init(&ixgbe_ks->got, "good_octets_xmitd",
198 	    KSTAT_DATA_UINT64);
199 	kstat_named_init(&ixgbe_ks->prc64, "pkts_recvd_(  64b)",
200 	    KSTAT_DATA_UINT64);
201 	kstat_named_init(&ixgbe_ks->prc127, "pkts_recvd_(  65- 127b)",
202 	    KSTAT_DATA_UINT64);
203 	kstat_named_init(&ixgbe_ks->prc255, "pkts_recvd_( 127- 255b)",
204 	    KSTAT_DATA_UINT64);
205 	kstat_named_init(&ixgbe_ks->prc511, "pkts_recvd_( 256- 511b)",
206 	    KSTAT_DATA_UINT64);
207 	kstat_named_init(&ixgbe_ks->prc1023, "pkts_recvd_( 511-1023b)",
208 	    KSTAT_DATA_UINT64);
209 	kstat_named_init(&ixgbe_ks->prc1522, "pkts_recvd_(1024-1522b)",
210 	    KSTAT_DATA_UINT64);
211 	kstat_named_init(&ixgbe_ks->ptc64, "pkts_xmitd_(  64b)",
212 	    KSTAT_DATA_UINT64);
213 	kstat_named_init(&ixgbe_ks->ptc127, "pkts_xmitd_(  65- 127b)",
214 	    KSTAT_DATA_UINT64);
215 	kstat_named_init(&ixgbe_ks->ptc255, "pkts_xmitd_( 128- 255b)",
216 	    KSTAT_DATA_UINT64);
217 	kstat_named_init(&ixgbe_ks->ptc511, "pkts_xmitd_( 255- 511b)",
218 	    KSTAT_DATA_UINT64);
219 	kstat_named_init(&ixgbe_ks->ptc1023, "pkts_xmitd_( 512-1023b)",
220 	    KSTAT_DATA_UINT64);
221 	kstat_named_init(&ixgbe_ks->ptc1522, "pkts_xmitd_(1024-1522b)",
222 	    KSTAT_DATA_UINT64);
223 #endif
224 
225 	kstat_named_init(&ixgbe_ks->mspdc, "mac_short_packet_discard",
226 	    KSTAT_DATA_UINT64);
227 	kstat_named_init(&ixgbe_ks->mpc, "missed_packets",
228 	    KSTAT_DATA_UINT64);
229 	kstat_named_init(&ixgbe_ks->mlfc, "mac_local_fault",
230 	    KSTAT_DATA_UINT64);
231 	kstat_named_init(&ixgbe_ks->mrfc, "mac_remote_fault",
232 	    KSTAT_DATA_UINT64);
233 	kstat_named_init(&ixgbe_ks->rlec, "recv_length_err",
234 	    KSTAT_DATA_UINT64);
235 	kstat_named_init(&ixgbe_ks->lxontxc, "link_xon_xmitd",
236 	    KSTAT_DATA_UINT64);
237 	kstat_named_init(&ixgbe_ks->lxonrxc, "link_xon_recvd",
238 	    KSTAT_DATA_UINT64);
239 	kstat_named_init(&ixgbe_ks->lxofftxc, "link_xoff_xmitd",
240 	    KSTAT_DATA_UINT64);
241 	kstat_named_init(&ixgbe_ks->lxoffrxc, "link_xoff_recvd",
242 	    KSTAT_DATA_UINT64);
243 	kstat_named_init(&ixgbe_ks->ruc, "recv_undersize",
244 	    KSTAT_DATA_UINT64);
245 	kstat_named_init(&ixgbe_ks->rfc, "recv_fragment",
246 	    KSTAT_DATA_UINT64);
247 	kstat_named_init(&ixgbe_ks->roc, "recv_oversize",
248 	    KSTAT_DATA_UINT64);
249 	kstat_named_init(&ixgbe_ks->rjc, "recv_jabber",
250 	    KSTAT_DATA_UINT64);
251 
252 	/*
253 	 * Function to provide kernel stat update on demand
254 	 */
255 	ks->ks_update = ixgbe_update_stats;
256 
257 	ks->ks_private = (void *)ixgbe;
258 
259 	/*
260 	 * Add kstat to systems kstat chain
261 	 */
262 	kstat_install(ks);
263 
264 	return (IXGBE_SUCCESS);
265 }
266