xref: /titanic_44/usr/src/uts/common/io/nxge/nxge_kstats.c (revision a776e90690d98f629ab57f6493ff5949af9d65bd)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 #include <sys/nxge/nxge_impl.h>
29 #include <inet/mi.h>
30 
31 #define	RDC_NAME_FORMAT1	"RDC Channel"
32 #define	TDC_NAME_FORMAT1	"TDC Channel"
33 #define	CH_NAME_FORMAT		" %d Stats"
34 #define	TDC_NAME_FORMAT		"TDC Channel %d Stats"
35 #define	RDC_NAME_FORMAT		"RDC Channel %d Stats"
36 
37 void nxge_mac_init_kstats(p_nxge_t, struct kstat *);
38 void nxge_xmac_init_kstats(struct kstat *);
39 void nxge_bmac_init_kstats(struct kstat *);
40 
41 /* ARGSUSED */
42 void
43 nxge_init_statsp(p_nxge_t nxgep)
44 {
45 	size_t stats_size;
46 
47 	NXGE_DEBUG_MSG((nxgep, KST_CTL, "==> nxge_init_statsp"));
48 
49 	stats_size = sizeof (nxge_stats_t);
50 	nxgep->statsp = KMEM_ZALLOC(stats_size, KM_SLEEP);
51 	nxgep->statsp->stats_size = stats_size;
52 
53 	NXGE_DEBUG_MSG((nxgep, KST_CTL, " <== nxge_init_statsp"));
54 }
55 
56 typedef struct {
57 	uint8_t index;
58 	uint8_t type;
59 	char *name;
60 } nxge_kstat_index_t;
61 
62 typedef enum {
63 	RDC_STAT_PACKETS = 0,
64 	RDC_STAT_BYTES,
65 	RDC_STAT_ERRORS,
66 	RDC_STAT_DCF_ERR,
67 	RDC_STAT_RCR_ACK_ERR,
68 	RDC_STAT_RCR_DC_FIFOFLOW_ERR,
69 	RDC_STAT_RCR_SHA_PAR_ERR,
70 	RDC_STAT_RBR_PRE_PAR_ERR,
71 	RDC_STAT_WRED_DROP,
72 	RDC_STAT_RBR_PRE_EMTY,
73 	RDC_STAT_RCR_SHADOW_FULL,
74 	RDC_STAT_RBR_TMOUT,
75 	RDC_STAT_RSP_CNT_ERR,
76 	RDC_STAT_BYTE_EN_BUS,
77 	RDC_STAT_RSP_DAT_ERR,
78 	RDC_STAT_PKT_TOO_LONG_ERR,
79 	RDC_STAT_COMPL_L2_ERR,
80 	RDC_STAT_COMPL_L4_CKSUM_ERR,
81 	RDC_STAT_COMPL_ZCP_SOFT_ERR,
82 	RDC_STAT_COMPL_FFLP_SOFT_ERR,
83 	RDC_STAT_CONFIG_ERR,
84 	RDC_STAT_RCRINCON,
85 	RDC_STAT_RCRFULL,
86 	RDC_STAT_RBR_EMPTY,
87 	RDC_STAT_RBR_FULL,
88 	RDC_STAT_RBRLOGPAGE,
89 	RDC_STAT_CFIGLOGPAGE,
90 	RDC_STAT_PORT_DROP_PKT,
91 	RDC_STAT_RCRTO,
92 	RDC_STAT_RCRTHRES,
93 	RDC_STAT_MEX,
94 	RDC_STAT_ID_MIS,
95 	RDC_STAT_ZCP_EOP,
96 	RDC_STAT_IPP_EOP,
97 	RDC_STAT_END
98 } nxge_rdc_stat_index_t;
99 
100 nxge_kstat_index_t nxge_rdc_stats[] = {
101 	{RDC_STAT_PACKETS, KSTAT_DATA_UINT64, "rdc_packets"},
102 	{RDC_STAT_BYTES, KSTAT_DATA_UINT64, "rdc_bytes"},
103 	{RDC_STAT_ERRORS, KSTAT_DATA_ULONG, "rdc_errors"},
104 	{RDC_STAT_DCF_ERR, KSTAT_DATA_ULONG, "rdc_dcf_err"},
105 	{RDC_STAT_RCR_ACK_ERR, KSTAT_DATA_ULONG, "rdc_rcr_ack_err"},
106 	{RDC_STAT_RCR_DC_FIFOFLOW_ERR, KSTAT_DATA_ULONG, "rdc_dc_fifoflow_err"},
107 	{RDC_STAT_RCR_SHA_PAR_ERR, KSTAT_DATA_ULONG, "rdc_rcr_sha_par_err"},
108 	{RDC_STAT_RBR_PRE_PAR_ERR, KSTAT_DATA_ULONG, "rdc_rbr_pre_par_err"},
109 	{RDC_STAT_WRED_DROP, KSTAT_DATA_ULONG, "rdc_wred_drop"},
110 	{RDC_STAT_RBR_PRE_EMTY, KSTAT_DATA_ULONG, "rdc_rbr_pre_empty"},
111 	{RDC_STAT_RCR_SHADOW_FULL, KSTAT_DATA_ULONG, "rdc_rcr_shadow_full"},
112 	{RDC_STAT_RBR_TMOUT, KSTAT_DATA_ULONG, "rdc_rbr_tmout"},
113 	{RDC_STAT_RSP_CNT_ERR, KSTAT_DATA_ULONG, "rdc_rsp_cnt_err"},
114 	{RDC_STAT_BYTE_EN_BUS, KSTAT_DATA_ULONG, "rdc_byte_en_bus"},
115 	{RDC_STAT_RSP_DAT_ERR, KSTAT_DATA_ULONG, "rdc_rsp_dat_err"},
116 	{RDC_STAT_PKT_TOO_LONG_ERR, KSTAT_DATA_ULONG, "rdc_pkt_too_long_err"},
117 	{RDC_STAT_COMPL_L2_ERR, KSTAT_DATA_ULONG, "rdc_compl_l2_err"},
118 	{RDC_STAT_COMPL_L4_CKSUM_ERR, KSTAT_DATA_ULONG, "rdc_compl_l4_cksum"},
119 	{RDC_STAT_COMPL_ZCP_SOFT_ERR, KSTAT_DATA_ULONG,
120 		"rdc_compl_zcp_soft_err"},
121 	{RDC_STAT_COMPL_FFLP_SOFT_ERR, KSTAT_DATA_ULONG,
122 		"rdc_compl_fflp_soft_err"},
123 	{RDC_STAT_CONFIG_ERR, KSTAT_DATA_ULONG, "rdc_config_err"},
124 	{RDC_STAT_RCRINCON, KSTAT_DATA_ULONG, "rdc_rcrincon"},
125 	{RDC_STAT_RCRFULL, KSTAT_DATA_ULONG, "rdc_rcrfull"},
126 	{RDC_STAT_RBR_EMPTY, KSTAT_DATA_ULONG, "rdc_rbr_empty"},
127 	{RDC_STAT_RBR_FULL, KSTAT_DATA_ULONG, "rdc_rbrfull"},
128 	{RDC_STAT_RBRLOGPAGE, KSTAT_DATA_ULONG, "rdc_rbrlogpage"},
129 	{RDC_STAT_CFIGLOGPAGE, KSTAT_DATA_ULONG, "rdc_cfiglogpage"},
130 	{RDC_STAT_PORT_DROP_PKT, KSTAT_DATA_ULONG, "rdc_port_drop_pkt"},
131 	{RDC_STAT_RCRTO, KSTAT_DATA_ULONG, "rdc_rcrto"},
132 	{RDC_STAT_RCRTHRES, KSTAT_DATA_ULONG, "rdc_rcrthres"},
133 	{RDC_STAT_MEX, KSTAT_DATA_ULONG, "rdc_mex"},
134 	{RDC_STAT_ID_MIS, KSTAT_DATA_ULONG, "rdc_id_mismatch"},
135 	{RDC_STAT_ZCP_EOP, KSTAT_DATA_ULONG, "rdc_zcp_eop"},
136 	{RDC_STAT_IPP_EOP, KSTAT_DATA_ULONG, "rdc_ipp_eop"},
137 	{RDC_STAT_END, NULL, NULL}
138 };
139 
140 typedef enum {
141 	RDC_SYS_STAT_PRE_PAR_ERR = 0,
142 	RDC_SYS_STAT_SHA_PAR_ERR,
143 	RDC_SYS_STAT_ID_MISMATCH,
144 	RDC_SYS_STAT_IPP_EOP_ERR,
145 	RDC_SYS_STAT_ZCP_EOP_ERR,
146 	RDC_SYS_STAT_END
147 } nxge_rdc_sys_stat_idx_t;
148 
149 nxge_kstat_index_t nxge_rdc_sys_stats[] = {
150 	{RDC_SYS_STAT_PRE_PAR_ERR, KSTAT_DATA_UINT64, "rdc_pre_par_err"},
151 	{RDC_SYS_STAT_SHA_PAR_ERR, KSTAT_DATA_UINT64, "rdc_sha_par_err"},
152 	{RDC_SYS_STAT_ID_MISMATCH, KSTAT_DATA_UINT64, "rdc_stat_id_mismatch"},
153 	{RDC_SYS_STAT_IPP_EOP_ERR, KSTAT_DATA_UINT64, "rdc_ipp_eop_err"},
154 	{RDC_SYS_STAT_ZCP_EOP_ERR, KSTAT_DATA_UINT64, "rdc_zcp_eop_err"},
155 	{RDC_SYS_STAT_END, NULL, NULL}
156 };
157 
158 typedef enum {
159 	TDC_STAT_PACKETS = 0,
160 	TDC_STAT_BYTES,
161 	TDC_STAT_ERRORS,
162 	TDC_STAT_TX_INITS,
163 	TDC_STAT_TX_NO_BUF,
164 	TDC_STAT_MBOX_ERR,
165 	TDC_STAT_PKT_SIZE_ERR,
166 	TDC_STAT_TX_RING_OFLOW,
167 	TDC_STAT_PREF_BUF_ECC_ERR,
168 	TDC_STAT_NACK_PREF,
169 	TDC_STAT_NACK_PKT_RD,
170 	TDC_STAT_CONF_PART_ERR,
171 	TDC_STAT_PKT_PRT_ERR,
172 	TDC_STAT_RESET_FAIL,
173 	TDC_STAT_TX_STARTS,
174 	TDC_STAT_TX_NOCANPUT,
175 	TDC_STAT_TX_MSGDUP_FAIL,
176 	TDC_STAT_TX_ALLOCB_FAIL,
177 	TDC_STAT_TX_NO_DESC,
178 	TDC_STAT_TX_DMA_BIND_FAIL,
179 	TDC_STAT_TX_UFLOW,
180 	TDC_STAT_TX_HDR_PKTS,
181 	TDC_STAT_TX_DDI_PKTS,
182 	TDC_STAT_TX_DVMA_PKTS,
183 	TDC_STAT_TX_MAX_PEND,
184 	TDC_STAT_END
185 } nxge_tdc_stats_index_t;
186 
187 nxge_kstat_index_t nxge_tdc_stats[] = {
188 	{TDC_STAT_PACKETS, KSTAT_DATA_UINT64, "tdc_packets"},
189 	{TDC_STAT_BYTES, KSTAT_DATA_UINT64, "tdc_bytes"},
190 	{TDC_STAT_ERRORS, KSTAT_DATA_UINT64, "tdc_errors"},
191 	{TDC_STAT_TX_INITS, KSTAT_DATA_ULONG, "tdc_tx_inits"},
192 	{TDC_STAT_TX_NO_BUF, KSTAT_DATA_ULONG, "tdc_tx_no_buf"},
193 	{TDC_STAT_MBOX_ERR, KSTAT_DATA_ULONG, "tdc_mbox_err"},
194 	{TDC_STAT_PKT_SIZE_ERR, KSTAT_DATA_ULONG, "tdc_pkt_size_err"},
195 	{TDC_STAT_TX_RING_OFLOW,
196 		KSTAT_DATA_ULONG, "tdc_tx_ring_oflow"},
197 	{TDC_STAT_PREF_BUF_ECC_ERR,
198 		KSTAT_DATA_ULONG, "tdc_pref_buf_err_err"},
199 	{TDC_STAT_NACK_PREF, KSTAT_DATA_ULONG, "tdc_nack_pref"},
200 	{TDC_STAT_NACK_PKT_RD, KSTAT_DATA_ULONG, "tdc_nack_pkt_rd"},
201 	{TDC_STAT_CONF_PART_ERR,
202 		KSTAT_DATA_ULONG, "tdc_conf_part_err"},
203 	{TDC_STAT_PKT_PRT_ERR, KSTAT_DATA_ULONG, "tdc_pkt_prt_err"},
204 	{TDC_STAT_RESET_FAIL, KSTAT_DATA_ULONG, "tdc_reset_fail"},
205 	{TDC_STAT_TX_STARTS, KSTAT_DATA_ULONG, "tdc_tx_starts"},
206 	{TDC_STAT_TX_NOCANPUT, KSTAT_DATA_ULONG, "tdc_tx_nocanput"},
207 	{TDC_STAT_TX_MSGDUP_FAIL, KSTAT_DATA_ULONG, "tdc_tx_msgdup_fail"},
208 	{TDC_STAT_TX_ALLOCB_FAIL, KSTAT_DATA_ULONG, "tdc_tx_allocb_fail"},
209 	{TDC_STAT_TX_NO_DESC, KSTAT_DATA_ULONG, "tdc_tx_no_desc"},
210 	{TDC_STAT_TX_DMA_BIND_FAIL, KSTAT_DATA_ULONG, "tdc_tx_dma_bind_fail"},
211 	{TDC_STAT_TX_UFLOW, KSTAT_DATA_ULONG, "tdc_tx_uflow"},
212 	{TDC_STAT_TX_HDR_PKTS, KSTAT_DATA_ULONG, "tdc_tx_hdr_pkts"},
213 	{TDC_STAT_TX_DDI_PKTS, KSTAT_DATA_ULONG, "tdc_tx_ddi_pkts"},
214 	{TDC_STAT_TX_DVMA_PKTS, KSTAT_DATA_ULONG, "tdc_tx_dvma_pkts"},
215 	{TDC_STAT_TX_MAX_PEND, KSTAT_DATA_ULONG, "tdc_tx_max_pend"},
216 	{TDC_STAT_END, NULL, NULL}
217 };
218 
219 /* IPP Statistics definitions */
220 typedef enum {
221 	IPP_STAT_EOP_MISS = 0,
222 	IPP_STAT_SOP_MISS,
223 	IPP_STAT_DFIFO_UE,
224 	IPP_STAT_ECC_ERR,
225 	IPP_STAT_PFIFO_PERR,
226 	IPP_STAT_PFIFO_OVER,
227 	IPP_STAT_PFIFO_UND,
228 	IPP_STAT_BAD_CS,
229 	IPP_STAT_BAD_DIS,
230 	IPP_STAT_END
231 } nxge_ipp_stat_index_t;
232 
233 nxge_kstat_index_t nxge_ipp_stats[] = {
234 	{IPP_STAT_EOP_MISS, KSTAT_DATA_ULONG, "rxipp_eop_miss"},
235 	{IPP_STAT_SOP_MISS, KSTAT_DATA_ULONG, "rxipp_sop_miss"},
236 	{IPP_STAT_DFIFO_UE, KSTAT_DATA_ULONG, "rxipp_dfifo_ue"},
237 	{IPP_STAT_ECC_ERR, KSTAT_DATA_ULONG, "rxipp_ecc_err"},
238 	{IPP_STAT_PFIFO_PERR, KSTAT_DATA_ULONG, "rxipp_pfifo_perr"},
239 	{IPP_STAT_PFIFO_OVER, KSTAT_DATA_ULONG, "rxipp_pfifo_over"},
240 	{IPP_STAT_PFIFO_UND, KSTAT_DATA_ULONG, "rxipp_pfifo_und"},
241 	{IPP_STAT_BAD_CS, KSTAT_DATA_ULONG, "rxipp_bad_cs"},
242 	{IPP_STAT_BAD_DIS, KSTAT_DATA_ULONG, "rxipp_bad_dis"},
243 	{IPP_STAT_END, NULL, NULL}
244 };
245 
246 /* TXC Statistics definitions */
247 typedef enum {
248 	TXC_STAT_PKT_STUFFED = 0,
249 	TXC_STAT_PKT_XMIT,
250 	TXC_STAT_RO_CORRECT_ERR,
251 	TXC_STAT_RO_UNCORRECT_ERR,
252 	TXC_STAT_SF_CORRECT_ERR,
253 	TXC_STAT_SF_UNCORRECT_ERR,
254 	TXC_STAT_ADDRESS_FAILED,
255 	TXC_STAT_DMA_FAILED,
256 	TXC_STAT_LENGTH_FAILED,
257 	TXC_STAT_PKT_ASSY_DEAD,
258 	TXC_STAT_REORDER_ERR,
259 	TXC_STAT_END
260 } nxge_txc_stat_index_t;
261 
262 nxge_kstat_index_t nxge_txc_stats[] = {
263 	{TXC_STAT_PKT_STUFFED, KSTAT_DATA_ULONG, "txc_pkt_stuffed"},
264 	{TXC_STAT_PKT_XMIT, KSTAT_DATA_ULONG, "txc_pkt_xmit"},
265 	{TXC_STAT_RO_CORRECT_ERR, KSTAT_DATA_ULONG, "txc_ro_correct_err"},
266 	{TXC_STAT_RO_UNCORRECT_ERR, KSTAT_DATA_ULONG, "txc_ro_uncorrect_err"},
267 	{TXC_STAT_SF_CORRECT_ERR, KSTAT_DATA_ULONG, "txc_sf_correct_err"},
268 	{TXC_STAT_SF_UNCORRECT_ERR, KSTAT_DATA_ULONG, "txc_sf_uncorrect_err"},
269 	{TXC_STAT_ADDRESS_FAILED, KSTAT_DATA_ULONG, "txc_address_failed"},
270 	{TXC_STAT_DMA_FAILED, KSTAT_DATA_ULONG, "txc_dma_failed"},
271 	{TXC_STAT_LENGTH_FAILED, KSTAT_DATA_ULONG, "txc_length_failed"},
272 	{TXC_STAT_PKT_ASSY_DEAD, KSTAT_DATA_ULONG, "txc_pkt_assy_dead"},
273 	{TXC_STAT_REORDER_ERR, KSTAT_DATA_ULONG, "txc_reorder_err"},
274 	{TXC_STAT_END, NULL, NULL}
275 };
276 
277 typedef enum {
278 	XMAC_STAT_TX_FRAME_CNT = 0,
279 	XMAC_STAT_TX_UNDERFLOW_ERR,
280 	XMAC_STAT_TX_MAXPKTSIZE_ERR,
281 	XMAC_STAT_TX_OVERFLOW_ERR,
282 	XMAC_STAT_TX_FIFO_XFR_ERR,
283 	XMAC_STAT_TX_BYTE_CNT,
284 	XMAC_STAT_RX_FRAME_CNT,
285 	XMAC_STAT_RX_UNDERFLOW_ERR,
286 	XMAC_STAT_RX_OVERFLOW_ERR,
287 	XMAC_STAT_RX_CRC_ERR_CNT,
288 	XMAC_STAT_RX_LEN_ERR_CNT,
289 	XMAC_STAT_RX_VIOL_ERR_CNT,
290 	XMAC_STAT_RX_BYTE_CNT,
291 	XMAC_STAT_RX_HIST1_CNT,
292 	XMAC_STAT_RX_HIST2_CNT,
293 	XMAC_STAT_RX_HIST3_CNT,
294 	XMAC_STAT_RX_HIST4_CNT,
295 	XMAC_STAT_RX_HIST5_CNT,
296 	XMAC_STAT_RX_HIST6_CNT,
297 	XMAC_STAT_RX_HIST7_CNT,
298 	XMAC_STAT_RX_BROADCAST_CNT,
299 	XMAC_STAT_RX_MULT_CNT,
300 	XMAC_STAT_RX_FRAG_CNT,
301 	XMAC_STAT_RX_FRAME_ALIGN_ERR_CNT,
302 	XMAC_STAT_RX_LINKFAULT_ERR_CNT,
303 	XMAC_STAT_RX_REMOTEFAULT_ERR,
304 	XMAC_STAT_RX_LOCALFAULT_ERR,
305 	XMAC_STAT_RX_PAUSE_CNT,
306 	XMAC_STAT_TX_PAUSE_STATE,
307 	XMAC_STAT_TX_NOPAUSE_STATE,
308 	XMAC_STAT_XPCS_DESKEW_ERR_CNT,
309 #ifdef	NXGE_DEBUG_SYMBOL_ERR
310 	XMAC_STAT_XPCS_SYMBOL_L0_ERR_CNT,
311 	XMAC_STAT_XPCS_SYMBOL_L1_ERR_CNT,
312 	XMAC_STAT_XPCS_SYMBOL_L2_ERR_CNT,
313 	XMAC_STAT_XPCS_SYMBOL_L3_ERR_CNT,
314 #endif
315 	XMAC_STAT_END
316 } nxge_xmac_stat_index_t;
317 
318 nxge_kstat_index_t nxge_xmac_stats[] = {
319 	{XMAC_STAT_TX_FRAME_CNT, KSTAT_DATA_ULONG, "txmac_frame_cnt"},
320 	{XMAC_STAT_TX_UNDERFLOW_ERR, KSTAT_DATA_ULONG, "tmac_underflow_err"},
321 	{XMAC_STAT_TX_MAXPKTSIZE_ERR, KSTAT_DATA_ULONG, "txmac_maxpktsize_err"},
322 	{XMAC_STAT_TX_OVERFLOW_ERR, KSTAT_DATA_ULONG, "txmac_overflow_err"},
323 	{XMAC_STAT_TX_FIFO_XFR_ERR, KSTAT_DATA_ULONG, "txmac_fifo_xfr_err"},
324 	{XMAC_STAT_TX_BYTE_CNT, KSTAT_DATA_ULONG, "txmac_byte_cnt"},
325 	{XMAC_STAT_RX_FRAME_CNT, KSTAT_DATA_ULONG, "rxmac_frame_cnt"},
326 	{XMAC_STAT_RX_UNDERFLOW_ERR, KSTAT_DATA_ULONG, "rxmac_underflow_err"},
327 	{XMAC_STAT_RX_OVERFLOW_ERR, KSTAT_DATA_ULONG, "rxmac_overflow_err"},
328 	{XMAC_STAT_RX_CRC_ERR_CNT, KSTAT_DATA_ULONG, "rxmac_crc_err"},
329 	{XMAC_STAT_RX_LEN_ERR_CNT, KSTAT_DATA_ULONG, "rxmac_length_err"},
330 	{XMAC_STAT_RX_VIOL_ERR_CNT, KSTAT_DATA_ULONG, "rxmac_code_violations"},
331 	{XMAC_STAT_RX_BYTE_CNT, KSTAT_DATA_ULONG, "rxmac_byte_cnt"},
332 	{XMAC_STAT_RX_HIST1_CNT, KSTAT_DATA_ULONG, "rxmac_64_cnt"},
333 	{XMAC_STAT_RX_HIST2_CNT, KSTAT_DATA_ULONG, "rxmac_65_127_cnt"},
334 	{XMAC_STAT_RX_HIST3_CNT, KSTAT_DATA_ULONG, "rxmac_128_255_cnt"},
335 	{XMAC_STAT_RX_HIST4_CNT, KSTAT_DATA_ULONG, "rxmac_256_511_cnt"},
336 	{XMAC_STAT_RX_HIST5_CNT, KSTAT_DATA_ULONG, "rxmac_512_1023_cnt"},
337 	{XMAC_STAT_RX_HIST6_CNT, KSTAT_DATA_ULONG, "rxmac_1024_1522_cnt"},
338 	{XMAC_STAT_RX_HIST7_CNT, KSTAT_DATA_ULONG, "rxmac_jumbo_cnt"},
339 	{XMAC_STAT_RX_BROADCAST_CNT, KSTAT_DATA_ULONG, "rxmac_broadcast_cnt"},
340 	{XMAC_STAT_RX_MULT_CNT, KSTAT_DATA_ULONG, "rxmac_multicast_cnt"},
341 	{XMAC_STAT_RX_FRAG_CNT, KSTAT_DATA_ULONG, "rxmac_fragment_cnt"},
342 	{XMAC_STAT_RX_FRAME_ALIGN_ERR_CNT,
343 		KSTAT_DATA_ULONG, "rxmac_alignment_err"},
344 	{XMAC_STAT_RX_LINKFAULT_ERR_CNT,
345 		KSTAT_DATA_ULONG, "rxmac_linkfault_errs"},
346 	{XMAC_STAT_RX_REMOTEFAULT_ERR,
347 		KSTAT_DATA_ULONG, "rxmac_remote_faults"},
348 	{XMAC_STAT_RX_LOCALFAULT_ERR,
349 		KSTAT_DATA_ULONG, "rxmac_local_faults"},
350 	{XMAC_STAT_RX_PAUSE_CNT, KSTAT_DATA_ULONG, "rxmac_pause_cnt"},
351 	{XMAC_STAT_TX_PAUSE_STATE, KSTAT_DATA_ULONG, "txmac_pause_state"},
352 	{XMAC_STAT_TX_NOPAUSE_STATE, KSTAT_DATA_ULONG, "txmac_nopause_state"},
353 	{XMAC_STAT_XPCS_DESKEW_ERR_CNT,
354 		KSTAT_DATA_ULONG, "xpcs_deskew_err_cnt"},
355 #ifdef	NXGE_DEBUG_SYMBOL_ERR
356 	{XMAC_STAT_XPCS_SYMBOL_L0_ERR_CNT,
357 		KSTAT_DATA_ULONG, "xpcs_ln0_symbol_err_cnt"},
358 	{XMAC_STAT_XPCS_SYMBOL_L1_ERR_CNT,
359 		KSTAT_DATA_ULONG, "xpcs_ln1_symbol_err_cnt"},
360 	{XMAC_STAT_XPCS_SYMBOL_L2_ERR_CNT,
361 		KSTAT_DATA_ULONG, "xpcs_ln2_symbol_err_cnt"},
362 	{XMAC_STAT_XPCS_SYMBOL_L3_ERR_CNT,
363 		KSTAT_DATA_ULONG, "xpcs_ln3_symbol_err_cnt"},
364 #endif
365 	{XMAC_STAT_END, NULL, NULL}
366 };
367 
368 typedef enum {
369 	BMAC_STAT_TX_FRAME_CNT = 0,
370 	BMAC_STAT_TX_UNDERRUN_ERR,
371 	BMAC_STAT_TX_MAX_PKT_ERR,
372 	BMAC_STAT_TX_BYTE_CNT,
373 	BMAC_STAT_RX_FRAME_CNT,
374 	BMAC_STAT_RX_BYTE_CNT,
375 	BMAC_STAT_RX_OVERFLOW_ERR,
376 	BMAC_STAT_RX_ALIGN_ERR_CNT,
377 	BMAC_STAT_RX_CRC_ERR_CNT,
378 	BMAC_STAT_RX_LEN_ERR_CNT,
379 	BMAC_STAT_RX_VIOL_ERR_CNT,
380 	BMAC_STAT_RX_PAUSE_CNT,
381 	BMAC_STAT_RX_PAUSE_STATE,
382 	BMAC_STAT_RX_NOPAUSE_STATE,
383 	BMAC_STAT_END
384 } nxge_bmac_stat_index_t;
385 
386 nxge_kstat_index_t nxge_bmac_stats[] = {
387 	{BMAC_STAT_TX_FRAME_CNT, KSTAT_DATA_ULONG, "txmac_frame_cnt"},
388 	{BMAC_STAT_TX_UNDERRUN_ERR, KSTAT_DATA_ULONG, "txmac_underrun_err"},
389 	{BMAC_STAT_TX_MAX_PKT_ERR, KSTAT_DATA_ULONG, "txmac_max_pkt_err"},
390 	{BMAC_STAT_TX_BYTE_CNT, KSTAT_DATA_ULONG, "txmac_byte_cnt"},
391 	{BMAC_STAT_RX_FRAME_CNT, KSTAT_DATA_ULONG, "rxmac_frame_cnt"},
392 	{BMAC_STAT_RX_BYTE_CNT, KSTAT_DATA_ULONG, "rxmac_byte_cnt"},
393 	{BMAC_STAT_RX_OVERFLOW_ERR, KSTAT_DATA_ULONG, "rxmac_overflow_err"},
394 	{BMAC_STAT_RX_ALIGN_ERR_CNT, KSTAT_DATA_ULONG, "rxmac_align_err_cnt"},
395 	{BMAC_STAT_RX_CRC_ERR_CNT, KSTAT_DATA_ULONG, "rxmac_crc_err_cnt"},
396 	{BMAC_STAT_RX_LEN_ERR_CNT, KSTAT_DATA_ULONG, "rxmac_len_err_cnt"},
397 	{BMAC_STAT_RX_VIOL_ERR_CNT, KSTAT_DATA_ULONG, "rxmac_viol_err_cnt"},
398 	{BMAC_STAT_RX_PAUSE_CNT, KSTAT_DATA_ULONG, "rxmac_pause_cnt"},
399 	{BMAC_STAT_RX_PAUSE_STATE, KSTAT_DATA_ULONG, "txmac_pause_state"},
400 	{BMAC_STAT_RX_NOPAUSE_STATE, KSTAT_DATA_ULONG, "tx_nopause_state"},
401 	{BMAC_STAT_END, NULL, NULL}
402 };
403 
404 typedef enum {
405 	ZCP_STAT_ERRORS,
406 	ZCP_STAT_INITS,
407 	ZCP_STAT_RRFIFO_UNDERRUN,
408 	ZCP_STAT_RRFIFO_OVERRUN,
409 	ZCP_STAT_RSPFIFO_UNCORR_ERR,
410 	ZCP_STAT_BUFFER_OVERFLOW,
411 	ZCP_STAT_STAT_TBL_PERR,
412 	ZCP_STAT_DYN_TBL_PERR,
413 	ZCP_STAT_BUF_TBL_PERR,
414 	ZCP_STAT_TT_PROGRAM_ERR,
415 	ZCP_STAT_RSP_TT_INDEX_ERR,
416 	ZCP_STAT_SLV_TT_INDEX_ERR,
417 	ZCP_STAT_ZCP_TT_INDEX_ERR,
418 	ZCP_STAT_ZCP_ACCESS_FAIL,
419 	ZCP_CFIFO_ECC,
420 	ZCP_STAT_END
421 } nxge_zcp_stat_index_t;
422 
423 nxge_kstat_index_t nxge_zcp_stats[] = {
424 	{ZCP_STAT_ERRORS, KSTAT_DATA_ULONG, "zcp_erros"},
425 	{ZCP_STAT_INITS, KSTAT_DATA_ULONG, "zcp_inits"},
426 	{ZCP_STAT_RRFIFO_UNDERRUN, KSTAT_DATA_ULONG, "zcp_rrfifo_underrun"},
427 	{ZCP_STAT_RRFIFO_OVERRUN, KSTAT_DATA_ULONG, "zcp_rrfifo_overrun"},
428 	{ZCP_STAT_RSPFIFO_UNCORR_ERR, KSTAT_DATA_ULONG,
429 	"zcp_rspfifo_uncorr_err"},
430 	{ZCP_STAT_BUFFER_OVERFLOW, KSTAT_DATA_ULONG, "zcp_buffer_overflow"},
431 	{ZCP_STAT_STAT_TBL_PERR, KSTAT_DATA_ULONG, "zcp_stat_tbl_perr"},
432 	{ZCP_STAT_DYN_TBL_PERR, KSTAT_DATA_ULONG, "zcp_dyn_tbl_perr"},
433 	{ZCP_STAT_BUF_TBL_PERR, KSTAT_DATA_ULONG, "zcp_buf_tbl_perr"},
434 	{ZCP_STAT_TT_PROGRAM_ERR, KSTAT_DATA_ULONG, "zcp_tt_program_err"},
435 	{ZCP_STAT_RSP_TT_INDEX_ERR, KSTAT_DATA_ULONG, "zcp_rsp_tt_index_err"},
436 	{ZCP_STAT_SLV_TT_INDEX_ERR, KSTAT_DATA_ULONG, "zcp_slv_tt_index_err"},
437 	{ZCP_STAT_ZCP_TT_INDEX_ERR, KSTAT_DATA_ULONG, "zcp_zcp_tt_index_err"},
438 	{ZCP_STAT_ZCP_ACCESS_FAIL, KSTAT_DATA_ULONG, "zcp_access_fail"},
439 	{ZCP_STAT_ZCP_ACCESS_FAIL, KSTAT_DATA_ULONG, "zcp_cfifo_ecc"},
440 	{ZCP_STAT_END, NULL, NULL}
441 };
442 
443 typedef enum {
444 	FFLP_STAT_TCAM_PERR,
445 	FFLP_STAT_TCAM_ECC_ERR,
446 	FFLP_STAT_VLAN_PERR,
447 	FFLP_STAT_HASH_LOOKUP_ERR,
448 	FFLP_STAT_HASH_P0_PIO_ERR,
449 	FFLP_STAT_HASH_P1_PIO_ERR,
450 	FFLP_STAT_HASH_P2_PIO_ERR,
451 	FFLP_STAT_HASH_P3_PIO_ERR,
452 	FFLP_STAT_HASH_P4_PIO_ERR,
453 	FFLP_STAT_HASH_P5_PIO_ERR,
454 	FFLP_STAT_HASH_P6_PIO_ERR,
455 	FFLP_STAT_HASH_P7_PIO_ERR,
456 	FFLP_STAT_END
457 } nxge_fflp_stat_index_t;
458 
459 nxge_kstat_index_t nxge_fflp_stats[] = {
460 	{FFLP_STAT_TCAM_PERR, KSTAT_DATA_ULONG, "fflp_tcam_perr"},
461 	{FFLP_STAT_TCAM_ECC_ERR, KSTAT_DATA_ULONG, "fflp_tcam_ecc_err"},
462 	{FFLP_STAT_VLAN_PERR, KSTAT_DATA_ULONG, "fflp_vlan_perr"},
463 	{FFLP_STAT_HASH_LOOKUP_ERR, KSTAT_DATA_ULONG, "fflp_hash_lookup_err"},
464 	{FFLP_STAT_HASH_P0_PIO_ERR, KSTAT_DATA_ULONG, "fflp_hash_p0_pio_err"},
465 	{FFLP_STAT_HASH_P1_PIO_ERR, KSTAT_DATA_ULONG, "fflp_hash_p1_pio_err"},
466 	{FFLP_STAT_HASH_P2_PIO_ERR, KSTAT_DATA_ULONG, "fflp_hash_p2_pio_err"},
467 	{FFLP_STAT_HASH_P3_PIO_ERR, KSTAT_DATA_ULONG, "fflp_hash_p3_pio_err"},
468 	{FFLP_STAT_HASH_P4_PIO_ERR, KSTAT_DATA_ULONG, "fflp_hash_p4_pio_err"},
469 	{FFLP_STAT_HASH_P5_PIO_ERR, KSTAT_DATA_ULONG, "fflp_hash_p5_pio_err"},
470 	{FFLP_STAT_HASH_P6_PIO_ERR, KSTAT_DATA_ULONG, "fflp_hash_p6_pio_err"},
471 	{FFLP_STAT_HASH_P7_PIO_ERR, KSTAT_DATA_ULONG, "fflp_hash_p7_pio_err"},
472 	{FFLP_STAT_END, NULL, NULL}
473 };
474 
475 typedef enum {
476 	MMAC_MAX_ADDR,
477 	MMAC_AVAIL_ADDR,
478 	MMAC_ADDR_POOL1,
479 	MMAC_ADDR_POOL2,
480 	MMAC_ADDR_POOL3,
481 	MMAC_ADDR_POOL4,
482 	MMAC_ADDR_POOL5,
483 	MMAC_ADDR_POOL6,
484 	MMAC_ADDR_POOL7,
485 	MMAC_ADDR_POOL8,
486 	MMAC_ADDR_POOL9,
487 	MMAC_ADDR_POOL10,
488 	MMAC_ADDR_POOL11,
489 	MMAC_ADDR_POOL12,
490 	MMAC_ADDR_POOL13,
491 	MMAC_ADDR_POOL14,
492 	MMAC_ADDR_POOL15,
493 	MMAC_ADDR_POOL16,
494 	MMAC_STATS_END
495 } nxge_mmac_stat_index_t;
496 
497 nxge_kstat_index_t nxge_mmac_stats[] = {
498 	{MMAC_MAX_ADDR, KSTAT_DATA_UINT64, "max_mmac_addr"},
499 	{MMAC_AVAIL_ADDR, KSTAT_DATA_UINT64, "avail_mmac_addr"},
500 	{MMAC_ADDR_POOL1, KSTAT_DATA_UINT64, "mmac_addr_1"},
501 	{MMAC_ADDR_POOL2, KSTAT_DATA_UINT64, "mmac_addr_2"},
502 	{MMAC_ADDR_POOL3, KSTAT_DATA_UINT64, "mmac_addr_3"},
503 	{MMAC_ADDR_POOL4, KSTAT_DATA_UINT64, "mmac_addr_4"},
504 	{MMAC_ADDR_POOL5, KSTAT_DATA_UINT64, "mmac_addr_5"},
505 	{MMAC_ADDR_POOL6, KSTAT_DATA_UINT64, "mmac_addr_6"},
506 	{MMAC_ADDR_POOL7, KSTAT_DATA_UINT64, "mmac_addr_7"},
507 	{MMAC_ADDR_POOL8, KSTAT_DATA_UINT64, "mmac_addr_8"},
508 	{MMAC_ADDR_POOL9, KSTAT_DATA_UINT64, "mmac_addr_9"},
509 	{MMAC_ADDR_POOL10, KSTAT_DATA_UINT64, "mmac_addr_10"},
510 	{MMAC_ADDR_POOL11, KSTAT_DATA_UINT64, "mmac_addr_11"},
511 	{MMAC_ADDR_POOL12, KSTAT_DATA_UINT64, "mmac_addr_12"},
512 	{MMAC_ADDR_POOL13, KSTAT_DATA_UINT64, "mmac_addr_13"},
513 	{MMAC_ADDR_POOL14, KSTAT_DATA_UINT64, "mmac_addr_14"},
514 	{MMAC_ADDR_POOL15, KSTAT_DATA_UINT64, "mmac_addr_15"},
515 	{MMAC_ADDR_POOL16, KSTAT_DATA_UINT64, "mmac_addr_16"},
516 	{MMAC_STATS_END, NULL, NULL},
517 };
518 
519 /* ARGSUSED */
520 int
521 nxge_tdc_stat_update(kstat_t *ksp, int rw)
522 {
523 	p_nxge_t nxgep;
524 	p_nxge_tdc_kstat_t tdc_kstatsp;
525 	p_nxge_tx_ring_stats_t statsp;
526 	int channel;
527 	char *ch_name, *end;
528 
529 	nxgep = (p_nxge_t)ksp->ks_private;
530 	if (nxgep == NULL)
531 		return (-1);
532 
533 	NXGE_DEBUG_MSG((nxgep, KST_CTL, "==> nxge_rxstat_update"));
534 
535 	ch_name = ksp->ks_name;
536 	ch_name += strlen(TDC_NAME_FORMAT1);
537 	channel = mi_strtol(ch_name, &end, 10);
538 
539 	tdc_kstatsp = (p_nxge_tdc_kstat_t)ksp->ks_data;
540 	statsp = (p_nxge_tx_ring_stats_t)&nxgep->statsp->tdc_stats[channel];
541 
542 	NXGE_DEBUG_MSG((nxgep, KST_CTL,
543 		"nxge_tdc_stat_update data $%p statsp $%p channel %d",
544 		ksp->ks_data, statsp, channel));
545 
546 	if (rw == KSTAT_WRITE) {
547 		statsp->opackets = tdc_kstatsp->opackets.value.ull;
548 		statsp->obytes = tdc_kstatsp->obytes.value.ull;
549 		statsp->oerrors = tdc_kstatsp->oerrors.value.ull;
550 		statsp->mbox_err = tdc_kstatsp->mbox_err.value.ul;
551 		statsp->pkt_size_err = tdc_kstatsp->pkt_size_err.value.ul;
552 		statsp->tx_ring_oflow = tdc_kstatsp->tx_ring_oflow.value.ul;
553 		statsp->pre_buf_par_err =
554 			tdc_kstatsp->pref_buf_ecc_err.value.ul;
555 		statsp->nack_pref = tdc_kstatsp->nack_pref.value.ul;
556 		statsp->nack_pkt_rd = tdc_kstatsp->nack_pkt_rd.value.ul;
557 		statsp->conf_part_err = tdc_kstatsp->conf_part_err.value.ul;
558 		statsp->pkt_part_err = tdc_kstatsp->pkt_prt_err.value.ul;
559 	} else {
560 		tdc_kstatsp->opackets.value.ull = statsp->opackets;
561 		tdc_kstatsp->obytes.value.ull = statsp->obytes;
562 		tdc_kstatsp->oerrors.value.ull = statsp->oerrors;
563 		tdc_kstatsp->tx_hdr_pkts.value.ull = statsp->tx_hdr_pkts;
564 		tdc_kstatsp->tx_ddi_pkts.value.ull = statsp->tx_ddi_pkts;
565 		tdc_kstatsp->tx_dvma_pkts.value.ull = statsp->tx_dvma_pkts;
566 		tdc_kstatsp->tx_max_pend.value.ull = statsp->tx_max_pend;
567 		tdc_kstatsp->mbox_err.value.ul = statsp->mbox_err;
568 		tdc_kstatsp->pkt_size_err.value.ul = statsp->pkt_size_err;
569 		tdc_kstatsp->tx_ring_oflow.value.ul = statsp->tx_ring_oflow;
570 		tdc_kstatsp->pref_buf_ecc_err.value.ul =
571 			statsp->pre_buf_par_err;
572 		tdc_kstatsp->nack_pref.value.ul = statsp->nack_pref;
573 		tdc_kstatsp->nack_pkt_rd.value.ul = statsp->nack_pkt_rd;
574 		tdc_kstatsp->conf_part_err.value.ul = statsp->conf_part_err;
575 		tdc_kstatsp->pkt_prt_err.value.ul = statsp->pkt_part_err;
576 		tdc_kstatsp->tx_starts.value.ul = statsp->tx_starts;
577 		tdc_kstatsp->tx_nocanput.value.ul = statsp->tx_nocanput;
578 		tdc_kstatsp->tx_msgdup_fail.value.ul = statsp->tx_msgdup_fail;
579 		tdc_kstatsp->tx_allocb_fail.value.ul = statsp->tx_allocb_fail;
580 		tdc_kstatsp->tx_no_desc.value.ul = statsp->tx_no_desc;
581 		tdc_kstatsp->tx_dma_bind_fail.value.ul =
582 			statsp->tx_dma_bind_fail;
583 	}
584 	NXGE_DEBUG_MSG((nxgep, KST_CTL, " <== nxge_tdc_stat_update"));
585 	return (0);
586 }
587 
588 /* ARGSUSED */
589 int
590 nxge_rdc_stat_update(kstat_t *ksp, int rw)
591 {
592 	p_nxge_t nxgep;
593 	p_nxge_rdc_kstat_t rdc_kstatsp;
594 	p_nxge_rx_ring_stats_t statsp;
595 	int channel;
596 	char *ch_name, *end;
597 
598 	nxgep = (p_nxge_t)ksp->ks_private;
599 	if (nxgep == NULL)
600 		return (-1);
601 
602 	NXGE_DEBUG_MSG((nxgep, KST_CTL, "==> nxge_rdc_stat_update"));
603 
604 	ch_name = ksp->ks_name;
605 	ch_name += strlen(RDC_NAME_FORMAT1);
606 	channel = mi_strtol(ch_name, &end, 10);
607 
608 	rdc_kstatsp = (p_nxge_rdc_kstat_t)ksp->ks_data;
609 	statsp = (p_nxge_rx_ring_stats_t)&nxgep->statsp->rdc_stats[channel];
610 
611 	NXGE_DEBUG_MSG((nxgep, KST_CTL,
612 		"nxge_rdc_stat_update $%p statsp $%p channel %d",
613 		ksp->ks_data, statsp, channel));
614 
615 	if (rw == KSTAT_WRITE) {
616 		statsp->dcf_err = rdc_kstatsp->dcf_err.value.ul;
617 		statsp->rcr_ack_err = rdc_kstatsp->rcr_ack_err.value.ul;
618 		statsp->dc_fifo_err = rdc_kstatsp->dc_fifoflow_err.value.ul;
619 		statsp->rcr_sha_par = rdc_kstatsp->rcr_sha_par_err.value.ul;
620 		statsp->rbr_pre_par = rdc_kstatsp->rbr_pre_par_err.value.ul;
621 		statsp->wred_drop = rdc_kstatsp->wred_drop.value.ul;
622 		statsp->rbr_pre_empty = rdc_kstatsp->rbr_pre_emty.value.ul;
623 		statsp->rcr_shadow_full = rdc_kstatsp->rcr_shadow_full.value.ul;
624 		statsp->rx_rbr_tmout = rdc_kstatsp->rbr_tmout.value.ul;
625 		statsp->rsp_cnt_err = rdc_kstatsp->rsp_cnt_err.value.ul;
626 		statsp->byte_en_bus = rdc_kstatsp->byte_en_bus.value.ul;
627 		statsp->rsp_dat_err = rdc_kstatsp->rsp_dat_err.value.ul;
628 		statsp->pkt_too_long_err =
629 		    rdc_kstatsp->pkt_too_long_err.value.ul;
630 		statsp->l2_err = rdc_kstatsp->compl_l2_err.value.ul;
631 		statsp->l4_cksum_err = rdc_kstatsp->compl_l4_cksum_err.value.ul;
632 		statsp->fflp_soft_err =
633 			rdc_kstatsp->compl_fflp_soft_err.value.ul;
634 		statsp->zcp_soft_err = rdc_kstatsp->compl_zcp_soft_err.value.ul;
635 		statsp->config_err = rdc_kstatsp->config_err.value.ul;
636 		statsp->rcrincon = rdc_kstatsp->rcrincon.value.ul;
637 		statsp->rcrfull = rdc_kstatsp->rcrfull.value.ul;
638 		statsp->rbr_empty = rdc_kstatsp->rbr_empty.value.ul;
639 		statsp->rbrfull = rdc_kstatsp->rbrfull.value.ul;
640 		statsp->rbrlogpage = rdc_kstatsp->rbrlogpage.value.ul;
641 		statsp->cfiglogpage = rdc_kstatsp->cfiglogpage.value.ul;
642 	} else {
643 		rdc_kstatsp->ipackets.value.ull = statsp->ipackets;
644 		rdc_kstatsp->rbytes.value.ull = statsp->ibytes;
645 		rdc_kstatsp->errors.value.ul = statsp->ierrors;
646 		rdc_kstatsp->dcf_err.value.ul = statsp->dcf_err;
647 		rdc_kstatsp->rcr_ack_err.value.ul = statsp->rcr_ack_err;
648 		rdc_kstatsp->dc_fifoflow_err.value.ul = statsp->dc_fifo_err;
649 		rdc_kstatsp->rcr_sha_par_err.value.ul = statsp->rcr_sha_par;
650 		rdc_kstatsp->rbr_pre_par_err.value.ul = statsp->rbr_pre_par;
651 		rdc_kstatsp->wred_drop.value.ul = statsp->wred_drop;
652 		rdc_kstatsp->port_drop_pkt.value.ul = statsp->port_drop_pkt;
653 		rdc_kstatsp->rbr_pre_emty.value.ul = statsp->rbr_pre_empty;
654 		rdc_kstatsp->rcr_shadow_full.value.ul = statsp->rcr_shadow_full;
655 		rdc_kstatsp->rbr_tmout.value.ul = statsp->rx_rbr_tmout;
656 		rdc_kstatsp->rsp_cnt_err.value.ul = statsp->rsp_cnt_err;
657 		rdc_kstatsp->byte_en_bus.value.ul = statsp->byte_en_bus;
658 		rdc_kstatsp->rsp_dat_err.value.ul = statsp->rsp_dat_err;
659 		rdc_kstatsp->pkt_too_long_err.value.ul =
660 		    statsp->pkt_too_long_err;
661 		rdc_kstatsp->compl_l2_err.value.ul = statsp->l2_err;
662 		rdc_kstatsp->compl_l4_cksum_err.value.ul = statsp->l4_cksum_err;
663 		rdc_kstatsp->compl_fflp_soft_err.value.ul =
664 			statsp->fflp_soft_err;
665 		rdc_kstatsp->compl_zcp_soft_err.value.ul = statsp->zcp_soft_err;
666 		rdc_kstatsp->config_err.value.ul = statsp->config_err;
667 		rdc_kstatsp->rcrincon.value.ul = statsp->rcrincon;
668 		rdc_kstatsp->rcrfull.value.ul = statsp->rcrfull;
669 		rdc_kstatsp->rbr_empty.value.ul = statsp->rbr_empty;
670 		rdc_kstatsp->rbrfull.value.ul = statsp->rbrfull;
671 		rdc_kstatsp->rbrlogpage.value.ul = statsp->rbrlogpage;
672 		rdc_kstatsp->cfiglogpage.value.ul = statsp->cfiglogpage;
673 	}
674 
675 	NXGE_DEBUG_MSG((nxgep, KST_CTL, " <== nxge_rdc_stat_update"));
676 	return (0);
677 }
678 
679 /* ARGSUSED */
680 int
681 nxge_rdc_sys_stat_update(kstat_t *ksp, int rw)
682 {
683 	p_nxge_t nxgep;
684 	p_nxge_rdc_sys_kstat_t rdc_sys_kstatsp;
685 	p_nxge_rdc_sys_stats_t statsp;
686 
687 	nxgep = (p_nxge_t)ksp->ks_private;
688 	if (nxgep == NULL)
689 		return (-1);
690 
691 	NXGE_DEBUG_MSG((nxgep, KST_CTL, "==> nxge_rdc_sys_stat_update"));
692 
693 	rdc_sys_kstatsp = (p_nxge_rdc_sys_kstat_t)ksp->ks_data;
694 	statsp = (p_nxge_rdc_sys_stats_t)&nxgep->statsp->rdc_sys_stats;
695 
696 	NXGE_DEBUG_MSG((nxgep, KST_CTL, "nxge_rdc_sys_stat_update %llx",
697 		ksp->ks_data));
698 
699 	if (rw == KSTAT_WRITE) {
700 		statsp->id_mismatch = rdc_sys_kstatsp->id_mismatch.value.ul;
701 		statsp->ipp_eop_err = rdc_sys_kstatsp->ipp_eop_err.value.ul;
702 		statsp->zcp_eop_err = rdc_sys_kstatsp->zcp_eop_err.value.ul;
703 	} else {
704 		rdc_sys_kstatsp->id_mismatch.value.ul = statsp->id_mismatch;
705 		rdc_sys_kstatsp->ipp_eop_err.value.ul = statsp->ipp_eop_err;
706 		rdc_sys_kstatsp->zcp_eop_err.value.ul = statsp->zcp_eop_err;
707 	}
708 	NXGE_DEBUG_MSG((nxgep, KST_CTL, " <== nxge_rdc_sys_stat_update"));
709 	return (0);
710 }
711 
712 /* ARGSUSED */
713 static int
714 nxge_txc_stat_update(kstat_t *ksp, int rw)
715 {
716 	p_nxge_t nxgep;
717 	p_nxge_txc_kstat_t txc_kstatsp;
718 	p_nxge_txc_stats_t statsp;
719 
720 	nxgep = (p_nxge_t)ksp->ks_private;
721 
722 	if (nxgep == NULL)
723 		return (-1);
724 
725 	NXGE_DEBUG_MSG((nxgep, KST_CTL, "==> nxge_txc_stat_update"));
726 
727 	txc_kstatsp = (p_nxge_txc_kstat_t)ksp->ks_data;
728 	statsp = (p_nxge_txc_stats_t)&nxgep->statsp->txc_stats;
729 
730 	if (rw == KSTAT_WRITE) {
731 		statsp->pkt_stuffed = txc_kstatsp->pkt_stuffed.value.ul;
732 		statsp->pkt_xmit = txc_kstatsp->pkt_xmit.value.ul;
733 		statsp->ro_correct_err = txc_kstatsp->ro_correct_err.value.ul;
734 		statsp->ro_uncorrect_err =
735 			txc_kstatsp->ro_uncorrect_err.value.ul;
736 		statsp->sf_correct_err = txc_kstatsp->sf_correct_err.value.ul;
737 		statsp->sf_uncorrect_err =
738 			txc_kstatsp->sf_uncorrect_err.value.ul;
739 		statsp->address_failed = txc_kstatsp->address_failed.value.ul;
740 		statsp->dma_failed = txc_kstatsp->dma_failed.value.ul;
741 		statsp->length_failed = txc_kstatsp->length_failed.value.ul;
742 		statsp->pkt_assy_dead = txc_kstatsp->pkt_assy_dead.value.ul;
743 		statsp->reorder_err = txc_kstatsp->reorder_err.value.ul;
744 	} else {
745 		txc_kstatsp->pkt_stuffed.value.ul = statsp->pkt_stuffed;
746 		txc_kstatsp->pkt_xmit.value.ul = statsp->pkt_xmit;
747 		txc_kstatsp->ro_correct_err.value.ul = statsp->ro_correct_err;
748 		txc_kstatsp->ro_uncorrect_err.value.ul =
749 			statsp->ro_uncorrect_err;
750 		txc_kstatsp->sf_correct_err.value.ul = statsp->sf_correct_err;
751 		txc_kstatsp->sf_uncorrect_err.value.ul =
752 			statsp->sf_uncorrect_err;
753 		txc_kstatsp->address_failed.value.ul = statsp->address_failed;
754 		txc_kstatsp->dma_failed.value.ul = statsp->dma_failed;
755 		txc_kstatsp->length_failed.value.ul = statsp->length_failed;
756 		txc_kstatsp->pkt_assy_dead.value.ul = statsp->pkt_assy_dead;
757 		txc_kstatsp->reorder_err.value.ul = statsp->reorder_err;
758 	}
759 	NXGE_DEBUG_MSG((nxgep, KST_CTL, "<== nxge_txc_stat_update"));
760 	return (0);
761 }
762 
763 /* ARGSUSED */
764 int
765 nxge_ipp_stat_update(kstat_t *ksp, int rw)
766 {
767 	p_nxge_t nxgep;
768 	p_nxge_ipp_kstat_t ipp_kstatsp;
769 	p_nxge_ipp_stats_t statsp;
770 
771 	nxgep = (p_nxge_t)ksp->ks_private;
772 	if (nxgep == NULL)
773 		return (-1);
774 
775 	NXGE_DEBUG_MSG((nxgep, KST_CTL, "==> nxge_ipp_stat_update"));
776 
777 	ipp_kstatsp = (p_nxge_ipp_kstat_t)ksp->ks_data;
778 	statsp = (p_nxge_ipp_stats_t)&nxgep->statsp->ipp_stats;
779 
780 	if (rw == KSTAT_WRITE) {
781 		statsp->eop_miss = ipp_kstatsp->eop_miss.value.ul;
782 		statsp->sop_miss = ipp_kstatsp->sop_miss.value.ul;
783 		statsp->dfifo_ue = ipp_kstatsp->dfifo_ue.value.ul;
784 		statsp->ecc_err_cnt = ipp_kstatsp->ecc_err_cnt.value.ul;
785 		statsp->pfifo_perr = ipp_kstatsp->pfifo_perr.value.ul;
786 		statsp->pfifo_over = ipp_kstatsp->pfifo_over.value.ul;
787 		statsp->pfifo_und = ipp_kstatsp->pfifo_und.value.ul;
788 		statsp->bad_cs_cnt = ipp_kstatsp->bad_cs_cnt.value.ul;
789 		statsp->pkt_dis_cnt = ipp_kstatsp->pkt_dis_cnt.value.ul;
790 	} else {
791 		ipp_kstatsp->eop_miss.value.ul = statsp->eop_miss;
792 		ipp_kstatsp->sop_miss.value.ul = statsp->sop_miss;
793 		ipp_kstatsp->dfifo_ue.value.ul = statsp->dfifo_ue;
794 		ipp_kstatsp->ecc_err_cnt.value.ul = statsp->ecc_err_cnt;
795 		ipp_kstatsp->pfifo_perr.value.ul = statsp->pfifo_perr;
796 		ipp_kstatsp->pfifo_over.value.ul = statsp->pfifo_over;
797 		ipp_kstatsp->pfifo_und.value.ul = statsp->pfifo_und;
798 		ipp_kstatsp->bad_cs_cnt.value.ul = statsp->bad_cs_cnt;
799 		ipp_kstatsp->pkt_dis_cnt.value.ul = statsp->pkt_dis_cnt;
800 	}
801 	NXGE_DEBUG_MSG((nxgep, KST_CTL, "<== nxge_ipp_stat_update"));
802 	return (0);
803 }
804 
805 /* ARGSUSED */
806 int
807 nxge_xmac_stat_update(kstat_t *ksp, int rw)
808 {
809 	p_nxge_t nxgep;
810 	p_nxge_xmac_kstat_t xmac_kstatsp;
811 	p_nxge_xmac_stats_t statsp;
812 
813 	nxgep = (p_nxge_t)ksp->ks_private;
814 	if (nxgep == NULL)
815 		return (-1);
816 
817 	NXGE_DEBUG_MSG((nxgep, KST_CTL, "==> nxge_xmac_stat_update"));
818 
819 	xmac_kstatsp = (p_nxge_xmac_kstat_t)ksp->ks_data;
820 	statsp = (p_nxge_xmac_stats_t)&nxgep->statsp->xmac_stats;
821 
822 	if (rw == KSTAT_WRITE) {
823 		statsp->tx_frame_cnt = xmac_kstatsp->tx_frame_cnt.value.ul;
824 		statsp->tx_underflow_err =
825 			xmac_kstatsp->tx_underflow_err.value.ul;
826 		statsp->tx_maxpktsize_err =
827 			xmac_kstatsp->tx_maxpktsize_err.value.ul;
828 		statsp->tx_overflow_err =
829 			xmac_kstatsp->tx_overflow_err.value.ul;
830 		statsp->tx_fifo_xfr_err =
831 			xmac_kstatsp->tx_fifo_xfr_err.value.ul;
832 		statsp->tx_byte_cnt = xmac_kstatsp->tx_byte_cnt.value.ul;
833 		statsp->rx_underflow_err =
834 			xmac_kstatsp->rx_underflow_err.value.ul;
835 		statsp->rx_overflow_err =
836 			xmac_kstatsp->rx_overflow_err.value.ul;
837 		statsp->rx_crc_err_cnt = xmac_kstatsp->rx_crc_err_cnt.value.ul;
838 		statsp->rx_len_err_cnt = xmac_kstatsp->rx_len_err_cnt.value.ul;
839 		statsp->rx_viol_err_cnt =
840 			xmac_kstatsp->rx_viol_err_cnt.value.ul;
841 		statsp->rx_byte_cnt = xmac_kstatsp->rx_byte_cnt.value.ul;
842 		statsp->rx_frame_cnt = xmac_kstatsp->rx_frame_cnt.value.ul;
843 		statsp->rx_hist1_cnt = xmac_kstatsp->rx_hist1_cnt.value.ul;
844 		statsp->rx_hist2_cnt = xmac_kstatsp->rx_hist2_cnt.value.ul;
845 		statsp->rx_hist3_cnt = xmac_kstatsp->rx_hist3_cnt.value.ul;
846 		statsp->rx_hist4_cnt = xmac_kstatsp->rx_hist4_cnt.value.ul;
847 		statsp->rx_hist5_cnt = xmac_kstatsp->rx_hist5_cnt.value.ul;
848 		statsp->rx_hist6_cnt = xmac_kstatsp->rx_hist6_cnt.value.ul;
849 		statsp->rx_hist7_cnt = xmac_kstatsp->rx_hist7_cnt.value.ul;
850 		statsp->rx_mult_cnt = xmac_kstatsp->rx_mult_cnt.value.ul;
851 		statsp->rx_frag_cnt = xmac_kstatsp->rx_frag_cnt.value.ul;
852 		statsp->rx_frame_align_err_cnt =
853 			xmac_kstatsp->rx_frame_align_err_cnt.value.ul;
854 		statsp->rx_linkfault_err_cnt =
855 			xmac_kstatsp->rx_linkfault_err_cnt.value.ul;
856 		statsp->rx_localfault_err =
857 			xmac_kstatsp->rx_local_fault_err_cnt.value.ul;
858 		statsp->rx_remotefault_err =
859 			xmac_kstatsp->rx_remote_fault_err_cnt.value.ul;
860 		statsp->xpcs_deskew_err_cnt =
861 			xmac_kstatsp->xpcs_deskew_err_cnt.value.ul;
862 #ifdef	NXGE_DEBUG_SYMBOL_ERR
863 		statsp->xpcs_ln0_symbol_err_cnt =
864 			xmac_kstatsp->xpcs_ln0_symbol_err_cnt.value.ul;
865 		statsp->xpcs_ln1_symbol_err_cnt =
866 			xmac_kstatsp->xpcs_ln1_symbol_err_cnt.value.ul;
867 		statsp->xpcs_ln2_symbol_err_cnt =
868 			xmac_kstatsp->xpcs_ln2_symbol_err_cnt.value.ul;
869 		statsp->xpcs_ln3_symbol_err_cnt =
870 			xmac_kstatsp->xpcs_ln3_symbol_err_cnt.value.ul;
871 #endif
872 	} else {
873 		xmac_kstatsp->tx_frame_cnt.value.ul = statsp->tx_frame_cnt;
874 		xmac_kstatsp->tx_underflow_err.value.ul =
875 			statsp->tx_underflow_err;
876 		xmac_kstatsp->tx_maxpktsize_err.value.ul =
877 			statsp->tx_maxpktsize_err;
878 		xmac_kstatsp->tx_overflow_err.value.ul =
879 			statsp->tx_overflow_err;
880 		xmac_kstatsp->tx_fifo_xfr_err.value.ul =
881 			statsp->tx_fifo_xfr_err;
882 		xmac_kstatsp->tx_byte_cnt.value.ul = statsp->tx_byte_cnt;
883 		xmac_kstatsp->rx_underflow_err.value.ul =
884 			statsp->rx_underflow_err;
885 		xmac_kstatsp->rx_overflow_err.value.ul =
886 			statsp->rx_overflow_err;
887 		xmac_kstatsp->rx_crc_err_cnt.value.ul = statsp->rx_crc_err_cnt;
888 		xmac_kstatsp->rx_len_err_cnt.value.ul = statsp->rx_len_err_cnt;
889 		xmac_kstatsp->rx_viol_err_cnt.value.ul =
890 			statsp->rx_viol_err_cnt;
891 		xmac_kstatsp->rx_byte_cnt.value.ul = statsp->rx_byte_cnt;
892 		xmac_kstatsp->rx_frame_cnt.value.ul = statsp->rx_frame_cnt;
893 		xmac_kstatsp->rx_hist1_cnt.value.ul = statsp->rx_hist1_cnt;
894 		xmac_kstatsp->rx_hist2_cnt.value.ul = statsp->rx_hist2_cnt;
895 		xmac_kstatsp->rx_hist3_cnt.value.ul = statsp->rx_hist3_cnt;
896 		xmac_kstatsp->rx_hist4_cnt.value.ul = statsp->rx_hist4_cnt;
897 		xmac_kstatsp->rx_hist5_cnt.value.ul = statsp->rx_hist5_cnt;
898 		xmac_kstatsp->rx_hist6_cnt.value.ul = statsp->rx_hist6_cnt;
899 		xmac_kstatsp->rx_hist7_cnt.value.ul = statsp->rx_hist7_cnt;
900 		xmac_kstatsp->rx_mult_cnt.value.ul = statsp->rx_mult_cnt;
901 		xmac_kstatsp->rx_frag_cnt.value.ul = statsp->rx_frag_cnt;
902 		xmac_kstatsp->rx_frame_align_err_cnt.value.ul =
903 			statsp->rx_frame_align_err_cnt;
904 		xmac_kstatsp->rx_linkfault_err_cnt.value.ul =
905 			statsp->rx_linkfault_err_cnt;
906 		xmac_kstatsp->rx_local_fault_err_cnt.value.ul =
907 			statsp->rx_localfault_err;
908 		xmac_kstatsp->rx_remote_fault_err_cnt.value.ul =
909 			statsp->rx_remotefault_err;
910 		xmac_kstatsp->xpcs_deskew_err_cnt.value.ul =
911 			statsp->xpcs_deskew_err_cnt;
912 #ifdef	NXGE_DEBUG_SYMBOL_ERR
913 		xmac_kstatsp->xpcs_ln0_symbol_err_cnt.value.ul =
914 			statsp->xpcs_ln0_symbol_err_cnt;
915 		xmac_kstatsp->xpcs_ln1_symbol_err_cnt.value.ul =
916 			statsp->xpcs_ln1_symbol_err_cnt;
917 		xmac_kstatsp->xpcs_ln2_symbol_err_cnt.value.ul =
918 			statsp->xpcs_ln2_symbol_err_cnt;
919 		xmac_kstatsp->xpcs_ln3_symbol_err_cnt.value.ul =
920 			statsp->xpcs_ln3_symbol_err_cnt;
921 #endif
922 	}
923 	NXGE_DEBUG_MSG((nxgep, KST_CTL, "<== nxge_xmac_stat_update"));
924 	return (0);
925 }
926 
927 /* ARGSUSED */
928 int
929 nxge_bmac_stat_update(kstat_t *ksp, int rw)
930 {
931 	p_nxge_t nxgep;
932 	p_nxge_bmac_kstat_t bmac_kstatsp;
933 	p_nxge_bmac_stats_t statsp;
934 
935 	nxgep = (p_nxge_t)ksp->ks_private;
936 	if (nxgep == NULL)
937 		return (-1);
938 
939 	NXGE_DEBUG_MSG((nxgep, KST_CTL, "==> nxge_bmac_stat_update"));
940 
941 	bmac_kstatsp = (p_nxge_bmac_kstat_t)ksp->ks_data;
942 	statsp = (p_nxge_bmac_stats_t)&nxgep->statsp->bmac_stats;
943 
944 	if (rw == KSTAT_WRITE) {
945 		statsp->tx_frame_cnt = bmac_kstatsp->tx_frame_cnt.value.ul;
946 		statsp->tx_underrun_err =
947 			bmac_kstatsp->tx_underrun_err.value.ul;
948 		statsp->tx_max_pkt_err = bmac_kstatsp->tx_max_pkt_err.value.ul;
949 		statsp->tx_byte_cnt = bmac_kstatsp->tx_byte_cnt.value.ul;
950 		statsp->rx_frame_cnt = bmac_kstatsp->rx_frame_cnt.value.ul;
951 		statsp->rx_byte_cnt = bmac_kstatsp->rx_byte_cnt.value.ul;
952 		statsp->rx_overflow_err =
953 			bmac_kstatsp->rx_overflow_err.value.ul;
954 		statsp->rx_align_err_cnt =
955 			bmac_kstatsp->rx_align_err_cnt.value.ul;
956 		statsp->rx_crc_err_cnt = bmac_kstatsp->rx_crc_err_cnt.value.ul;
957 		statsp->rx_len_err_cnt = bmac_kstatsp->rx_len_err_cnt.value.ul;
958 		statsp->rx_viol_err_cnt =
959 			bmac_kstatsp->rx_viol_err_cnt.value.ul;
960 	} else {
961 		bmac_kstatsp->tx_frame_cnt.value.ul = statsp->tx_frame_cnt;
962 		bmac_kstatsp->tx_underrun_err.value.ul =
963 			statsp->tx_underrun_err;
964 		bmac_kstatsp->tx_max_pkt_err.value.ul = statsp->tx_max_pkt_err;
965 		bmac_kstatsp->tx_byte_cnt.value.ul = statsp->tx_byte_cnt;
966 		bmac_kstatsp->rx_frame_cnt.value.ul = statsp->rx_frame_cnt;
967 		bmac_kstatsp->rx_byte_cnt.value.ul = statsp->rx_byte_cnt;
968 		bmac_kstatsp->rx_overflow_err.value.ul =
969 			statsp->rx_overflow_err;
970 		bmac_kstatsp->rx_align_err_cnt.value.ul =
971 			statsp->rx_align_err_cnt;
972 		bmac_kstatsp->rx_crc_err_cnt.value.ul = statsp->rx_crc_err_cnt;
973 		bmac_kstatsp->rx_len_err_cnt.value.ul = statsp->rx_len_err_cnt;
974 		bmac_kstatsp->rx_viol_err_cnt.value.ul =
975 			statsp->rx_viol_err_cnt;
976 	}
977 	NXGE_DEBUG_MSG((nxgep, KST_CTL, "<== nxge_bmac_stat_update"));
978 	return (0);
979 }
980 
981 /* ARGSUSED */
982 int
983 nxge_zcp_stat_update(kstat_t *ksp, int rw)
984 {
985 	p_nxge_t nxgep;
986 	p_nxge_zcp_kstat_t zcp_kstatsp;
987 	p_nxge_zcp_stats_t statsp;
988 
989 	nxgep = (p_nxge_t)ksp->ks_private;
990 	if (nxgep == NULL)
991 		return (-1);
992 
993 	NXGE_DEBUG_MSG((nxgep, KST_CTL, "==> nxge_zcp_stat_update"));
994 
995 	zcp_kstatsp = (p_nxge_zcp_kstat_t)ksp->ks_data;
996 	statsp = (p_nxge_zcp_stats_t)&nxgep->statsp->zcp_stats;
997 
998 	if (rw == KSTAT_WRITE) {
999 		statsp->rrfifo_underrun = zcp_kstatsp->rrfifo_underrun.value.ul;
1000 		statsp->rrfifo_overrun = zcp_kstatsp->rrfifo_overrun.value.ul;
1001 		statsp->rspfifo_uncorr_err =
1002 			zcp_kstatsp->rspfifo_uncorr_err.value.ul;
1003 		statsp->buffer_overflow = zcp_kstatsp->buffer_overflow.value.ul;
1004 		statsp->stat_tbl_perr = zcp_kstatsp->stat_tbl_perr.value.ul;
1005 		statsp->dyn_tbl_perr = zcp_kstatsp->dyn_tbl_perr.value.ul;
1006 		statsp->buf_tbl_perr = zcp_kstatsp->buf_tbl_perr.value.ul;
1007 		statsp->tt_program_err = zcp_kstatsp->tt_program_err.value.ul;
1008 		statsp->rsp_tt_index_err =
1009 			zcp_kstatsp->rsp_tt_index_err.value.ul;
1010 		statsp->slv_tt_index_err =
1011 			zcp_kstatsp->slv_tt_index_err.value.ul;
1012 		statsp->zcp_tt_index_err =
1013 			zcp_kstatsp->zcp_tt_index_err.value.ul;
1014 		statsp->cfifo_ecc = zcp_kstatsp->cfifo_ecc.value.ul;
1015 	} else {
1016 		zcp_kstatsp->rrfifo_underrun.value.ul = statsp->rrfifo_underrun;
1017 		zcp_kstatsp->rrfifo_overrun.value.ul = statsp->rrfifo_overrun;
1018 		zcp_kstatsp->rspfifo_uncorr_err.value.ul =
1019 			statsp->rspfifo_uncorr_err;
1020 		zcp_kstatsp->buffer_overflow.value.ul =
1021 			statsp->buffer_overflow;
1022 		zcp_kstatsp->stat_tbl_perr.value.ul = statsp->stat_tbl_perr;
1023 		zcp_kstatsp->dyn_tbl_perr.value.ul = statsp->dyn_tbl_perr;
1024 		zcp_kstatsp->buf_tbl_perr.value.ul = statsp->buf_tbl_perr;
1025 		zcp_kstatsp->tt_program_err.value.ul = statsp->tt_program_err;
1026 		zcp_kstatsp->rsp_tt_index_err.value.ul =
1027 			statsp->rsp_tt_index_err;
1028 		zcp_kstatsp->slv_tt_index_err.value.ul =
1029 			statsp->slv_tt_index_err;
1030 		zcp_kstatsp->zcp_tt_index_err.value.ul =
1031 			statsp->zcp_tt_index_err;
1032 		zcp_kstatsp->cfifo_ecc.value.ul = statsp->cfifo_ecc;
1033 	}
1034 	NXGE_DEBUG_MSG((nxgep, KST_CTL, "<== nxge_zcp_stat_update"));
1035 	return (0);
1036 }
1037 
1038 /* ARGSUSED */
1039 int
1040 nxge_fflp_stat_update(kstat_t *ksp, int rw)
1041 {
1042 	p_nxge_t nxgep;
1043 	p_nxge_fflp_kstat_t fflp_kstatsp;
1044 	p_nxge_fflp_stats_t statsp;
1045 	int ldc_grp;
1046 
1047 	nxgep = (p_nxge_t)ksp->ks_private;
1048 	if (nxgep == NULL)
1049 		return (-1);
1050 
1051 	NXGE_DEBUG_MSG((nxgep, KST_CTL, "==> nxge_fflp_stat_update"));
1052 
1053 	fflp_kstatsp = (p_nxge_fflp_kstat_t)ksp->ks_data;
1054 	statsp = (p_nxge_fflp_stats_t)&nxgep->statsp->fflp_stats;
1055 
1056 	if (rw == KSTAT_WRITE) {
1057 		statsp->tcam_parity_err = fflp_kstatsp->fflp_tcam_perr.value.ul;
1058 		statsp->tcam_ecc_err = fflp_kstatsp->fflp_tcam_ecc_err.value.ul;
1059 		statsp->vlan_parity_err = fflp_kstatsp->fflp_vlan_perr.value.ul;
1060 		statsp->hash_lookup_err =
1061 			fflp_kstatsp->fflp_hasht_lookup_err.value.ul;
1062 		for (ldc_grp = 0; ldc_grp < MAX_PARTITION; ldc_grp++) {
1063 			statsp->hash_pio_err[ldc_grp] =
1064 				fflp_kstatsp->fflp_hasht_data_err[ldc_grp].
1065 				value.ul;
1066 		}
1067 	} else {
1068 		fflp_kstatsp->fflp_tcam_perr.value.ul =
1069 			fflp_kstatsp->fflp_tcam_perr.value.ul;
1070 		fflp_kstatsp->fflp_tcam_ecc_err.value.ul = statsp->tcam_ecc_err;
1071 		fflp_kstatsp->fflp_vlan_perr.value.ul = statsp->vlan_parity_err;
1072 		fflp_kstatsp->fflp_hasht_lookup_err.value.ul =
1073 			statsp->hash_lookup_err;
1074 		for (ldc_grp = 0; ldc_grp < MAX_PARTITION; ldc_grp++) {
1075 			fflp_kstatsp->fflp_hasht_data_err[ldc_grp].value.ul =
1076 				statsp->hash_pio_err[ldc_grp];
1077 		}
1078 	}
1079 	NXGE_DEBUG_MSG((nxgep, KST_CTL, "<== nxge_fflp_stat_update"));
1080 	return (0);
1081 }
1082 
1083 /* ARGSUSED */
1084 static uint64_t
1085 nxge_mac_octet_to_u64(struct ether_addr addr)
1086 {
1087 	int i;
1088 	uint64_t addr64 = 0;
1089 
1090 	for (i = ETHERADDRL - 1; i >= 0; i--) {
1091 		addr64 <<= 8;
1092 		addr64 |= addr.ether_addr_octet[i];
1093 	}
1094 	return (addr64);
1095 }
1096 
1097 /* ARGSUSED */
1098 int
1099 nxge_mmac_stat_update(kstat_t *ksp, int rw)
1100 {
1101 	p_nxge_t nxgep;
1102 	p_nxge_mmac_kstat_t mmac_kstatsp;
1103 	p_nxge_mmac_stats_t statsp;
1104 
1105 	nxgep = (p_nxge_t)ksp->ks_private;
1106 	if (nxgep == NULL)
1107 		return (-1);
1108 
1109 	NXGE_DEBUG_MSG((nxgep, KST_CTL, "==> nxge_mmac_stat_update"));
1110 
1111 	mmac_kstatsp = (p_nxge_mmac_kstat_t)ksp->ks_data;
1112 	statsp = (p_nxge_mmac_stats_t)&nxgep->statsp->mmac_stats;
1113 
1114 	if (rw == KSTAT_WRITE) {
1115 		cmn_err(CE_WARN, "Can not write mmac stats");
1116 	} else {
1117 		mmac_kstatsp->mmac_max_addr_cnt.value.ul =
1118 			statsp->mmac_max_cnt;
1119 		mmac_kstatsp->mmac_avail_addr_cnt.value.ul =
1120 			statsp->mmac_avail_cnt;
1121 		mmac_kstatsp->mmac_addr1.value.ul =
1122 			nxge_mac_octet_to_u64(statsp->mmac_avail_pool[0]);
1123 		mmac_kstatsp->mmac_addr2.value.ul =
1124 			nxge_mac_octet_to_u64(statsp->mmac_avail_pool[1]);
1125 		mmac_kstatsp->mmac_addr3.value.ul =
1126 			nxge_mac_octet_to_u64(statsp->mmac_avail_pool[2]);
1127 		mmac_kstatsp->mmac_addr4.value.ul =
1128 			nxge_mac_octet_to_u64(statsp->mmac_avail_pool[3]);
1129 		mmac_kstatsp->mmac_addr5.value.ul =
1130 			nxge_mac_octet_to_u64(statsp->mmac_avail_pool[4]);
1131 		mmac_kstatsp->mmac_addr6.value.ul =
1132 			nxge_mac_octet_to_u64(statsp->mmac_avail_pool[5]);
1133 		mmac_kstatsp->mmac_addr7.value.ul =
1134 			nxge_mac_octet_to_u64(statsp->mmac_avail_pool[6]);
1135 		mmac_kstatsp->mmac_addr8.value.ul =
1136 			nxge_mac_octet_to_u64(statsp->mmac_avail_pool[7]);
1137 		mmac_kstatsp->mmac_addr9.value.ul =
1138 			nxge_mac_octet_to_u64(statsp->mmac_avail_pool[8]);
1139 		mmac_kstatsp->mmac_addr10.value.ul =
1140 			nxge_mac_octet_to_u64(statsp->mmac_avail_pool[9]);
1141 		mmac_kstatsp->mmac_addr11.value.ul =
1142 			nxge_mac_octet_to_u64(statsp->mmac_avail_pool[10]);
1143 		mmac_kstatsp->mmac_addr12.value.ul =
1144 			nxge_mac_octet_to_u64(statsp->mmac_avail_pool[11]);
1145 		mmac_kstatsp->mmac_addr13.value.ul =
1146 			nxge_mac_octet_to_u64(statsp->mmac_avail_pool[12]);
1147 		mmac_kstatsp->mmac_addr14.value.ul =
1148 			nxge_mac_octet_to_u64(statsp->mmac_avail_pool[13]);
1149 		mmac_kstatsp->mmac_addr15.value.ul =
1150 			nxge_mac_octet_to_u64(statsp->mmac_avail_pool[14]);
1151 		mmac_kstatsp->mmac_addr16.value.ul =
1152 			nxge_mac_octet_to_u64(statsp->mmac_avail_pool[15]);
1153 	}
1154 	NXGE_DEBUG_MSG((nxgep, KST_CTL, "<== nxge_mmac_stat_update"));
1155 	return (0);
1156 }
1157 
1158 /* ARGSUSED */
1159 static kstat_t *
1160 nxge_setup_local_kstat(p_nxge_t nxgep, int instance, char *name,
1161 	const nxge_kstat_index_t *ksip, size_t count,
1162 	int (*update) (kstat_t *, int))
1163 {
1164 	kstat_t *ksp;
1165 	kstat_named_t *knp;
1166 	int i;
1167 
1168 	ksp = kstat_create(NXGE_DRIVER_NAME, instance, name, "net",
1169 		KSTAT_TYPE_NAMED, count, 0);
1170 	if (ksp == NULL)
1171 		return (NULL);
1172 
1173 	ksp->ks_private = (void *)nxgep;
1174 	ksp->ks_update = update;
1175 	knp = ksp->ks_data;
1176 
1177 	for (i = 0; ksip[i].name != NULL; i++) {
1178 		kstat_named_init(&knp[i], ksip[i].name, ksip[i].type);
1179 	}
1180 
1181 	kstat_install(ksp);
1182 	return (ksp);
1183 }
1184 
1185 /* ARGSUSED */
1186 void
1187 nxge_setup_kstats(p_nxge_t nxgep)
1188 {
1189 	struct kstat *ksp;
1190 	p_nxge_port_kstat_t nxgekp;
1191 	size_t nxge_kstat_sz;
1192 	char stat_name[64];
1193 	char mmac_name[64];
1194 	int i;
1195 
1196 	NXGE_DEBUG_MSG((nxgep, KST_CTL, "==> nxge_setup_kstats"));
1197 
1198 
1199 	/* Setup RDC statistics */
1200 	for (i = 0; i < nxgep->nrdc; i++) {
1201 		(void) sprintf(stat_name, "%s" CH_NAME_FORMAT,
1202 			RDC_NAME_FORMAT1, i);
1203 		nxgep->statsp->rdc_ksp[i] = nxge_setup_local_kstat(nxgep,
1204 			nxgep->instance, stat_name,
1205 			&nxge_rdc_stats[0], RDC_STAT_END, nxge_rdc_stat_update);
1206 #ifdef	NXGE_DEBUG_ERROR
1207 		if (nxgep->statsp->rdc_ksp[i] == NULL)
1208 			NXGE_DEBUG_MSG((nxgep, KST_CTL,
1209 				"kstat_create failed for rdc channel %d", i));
1210 #endif
1211 	}
1212 
1213 	/* Setup RDC System statistics */
1214 	nxgep->statsp->rdc_sys_ksp = nxge_setup_local_kstat(nxgep,
1215 		nxgep->instance,
1216 		"RDC System Stats",
1217 		&nxge_rdc_sys_stats[0],
1218 		RDC_SYS_STAT_END,
1219 		nxge_rdc_sys_stat_update);
1220 
1221 	/* Setup IPP statistics */
1222 	nxgep->statsp->ipp_ksp = nxge_setup_local_kstat(nxgep,
1223 		nxgep->instance,
1224 		"IPP Stats",
1225 		&nxge_ipp_stats[0],
1226 		IPP_STAT_END,
1227 		nxge_ipp_stat_update);
1228 #ifdef	NXGE_DEBUG_ERROR
1229 	if (nxgep->istatsp->pp_ksp == NULL)
1230 		NXGE_DEBUG_MSG((nxgep, KST_CTL, "kstat_create failed for ipp"));
1231 #endif
1232 
1233 	/* Setup TDC statistics */
1234 	for (i = 0; i < nxgep->ntdc; i++) {
1235 		(void) sprintf(stat_name, "%s" CH_NAME_FORMAT,
1236 			TDC_NAME_FORMAT1, i);
1237 		nxgep->statsp->tdc_ksp[i] = nxge_setup_local_kstat(nxgep,
1238 			nxgep->instance,
1239 			stat_name,
1240 			&nxge_tdc_stats[0],
1241 			TDC_STAT_END,
1242 			nxge_tdc_stat_update);
1243 #ifdef	NXGE_DEBUG_ERROR
1244 		if (nxgep->statsp->tdc_ksp[i] == NULL) {
1245 			NXGE_DEBUG_MSG((nxgep, KST_CTL,
1246 				"kstat_create failed for tdc channel %d", i));
1247 		}
1248 #endif
1249 	}
1250 
1251 	/* Setup TXC statistics */
1252 	nxgep->statsp->txc_ksp = nxge_setup_local_kstat(nxgep,
1253 		nxgep->instance, "TXC Stats", &nxge_txc_stats[0],
1254 		TXC_STAT_END, nxge_txc_stat_update);
1255 #ifdef	NXGE_DEBUG_ERROR
1256 	if (nxgep->statsp->txc_ksp == NULL)
1257 		NXGE_DEBUG_MSG((nxgep, KST_CTL, "kstat_create failed for txc"));
1258 #endif
1259 
1260 	/* Setup ZCP statistics */
1261 	nxgep->statsp->zcp_ksp = nxge_setup_local_kstat(nxgep,
1262 		nxgep->instance, "ZCP Stats", &nxge_zcp_stats[0],
1263 		ZCP_STAT_END, nxge_zcp_stat_update);
1264 #ifdef	NXGE_DEBUG_ERROR
1265 	if (nxgep->statsp->zcp_ksp == NULL)
1266 		NXGE_DEBUG_MSG((nxgep, KST_CTL, "kstat_create failed for zcp"));
1267 #endif
1268 
1269 	/* Setup FFLP statistics */
1270 	nxgep->statsp->fflp_ksp[0] = nxge_setup_local_kstat(nxgep,
1271 		nxgep->instance, "FFLP Stats", &nxge_fflp_stats[0],
1272 		FFLP_STAT_END, nxge_fflp_stat_update);
1273 
1274 #ifdef	NXGE_DEBUG_ERROR
1275 	if (nxgep->statsp->fflp_ksp == NULL)
1276 		NXGE_DEBUG_MSG((nxgep, KST_CTL,
1277 			"kstat_create failed for fflp"));
1278 #endif
1279 
1280 	(void) sprintf(mmac_name, "MMAC Stats%d", nxgep->instance);
1281 	nxgep->statsp->mmac_ksp = nxge_setup_local_kstat(nxgep,
1282 		nxgep->instance, "MMAC Stats", &nxge_mmac_stats[0],
1283 		MMAC_STATS_END, nxge_mmac_stat_update);
1284 
1285 	nxge_kstat_sz = sizeof (nxge_port_kstat_t) +
1286 		sizeof (nxge_mac_kstat_t) - sizeof (kstat_named_t);
1287 
1288 	if ((ksp = kstat_create(NXGE_DRIVER_NAME, nxgep->instance,
1289 			"Port Stats", "net", KSTAT_TYPE_NAMED,
1290 			nxge_kstat_sz / sizeof (kstat_named_t), 0)) == NULL) {
1291 		NXGE_DEBUG_MSG((nxgep, KST_CTL, "kstat_create failed"));
1292 		NXGE_DEBUG_MSG((nxgep, KST_CTL, "<== nxge_setup_kstats"));
1293 		return;
1294 	}
1295 
1296 	/*
1297 	 * kstats
1298 	 */
1299 	nxgekp = (p_nxge_port_kstat_t)ksp->ks_data;
1300 
1301 	/*
1302 	 * transceiver state informations.
1303 	 */
1304 	kstat_named_init(&nxgekp->xcvr_inits, "xcvr_inits",
1305 		KSTAT_DATA_ULONG);
1306 	kstat_named_init(&nxgekp->xcvr_inuse, "xcvr_inuse",
1307 		KSTAT_DATA_ULONG);
1308 	kstat_named_init(&nxgekp->xcvr_addr, "xcvr_addr",
1309 		KSTAT_DATA_ULONG);
1310 	kstat_named_init(&nxgekp->xcvr_id, "xcvr_id",
1311 		KSTAT_DATA_ULONG);
1312 	kstat_named_init(&nxgekp->cap_autoneg, "cap_autoneg",
1313 		KSTAT_DATA_ULONG);
1314 	kstat_named_init(&nxgekp->cap_10gfdx, "cap_10gfdx",
1315 		KSTAT_DATA_ULONG);
1316 	kstat_named_init(&nxgekp->cap_10ghdx, "cap_10ghdx",
1317 		KSTAT_DATA_ULONG);
1318 	kstat_named_init(&nxgekp->cap_1000fdx, "cap_1000fdx",
1319 		KSTAT_DATA_ULONG);
1320 	kstat_named_init(&nxgekp->cap_1000hdx, "cap_1000hdx",
1321 		KSTAT_DATA_ULONG);
1322 	kstat_named_init(&nxgekp->cap_100T4, "cap_100T4",
1323 		KSTAT_DATA_ULONG);
1324 	kstat_named_init(&nxgekp->cap_100fdx, "cap_100fdx",
1325 		KSTAT_DATA_ULONG);
1326 	kstat_named_init(&nxgekp->cap_100hdx, "cap_100hdx",
1327 		KSTAT_DATA_ULONG);
1328 	kstat_named_init(&nxgekp->cap_10fdx, "cap_10fdx",
1329 		KSTAT_DATA_ULONG);
1330 	kstat_named_init(&nxgekp->cap_10hdx, "cap_10hdx",
1331 		KSTAT_DATA_ULONG);
1332 	kstat_named_init(&nxgekp->cap_asmpause, "cap_asmpause",
1333 		KSTAT_DATA_ULONG);
1334 	kstat_named_init(&nxgekp->cap_pause, "cap_pause",
1335 		KSTAT_DATA_ULONG);
1336 
1337 	/*
1338 	 * Link partner capabilities.
1339 	 */
1340 	kstat_named_init(&nxgekp->lp_cap_autoneg, "lp_cap_autoneg",
1341 		KSTAT_DATA_ULONG);
1342 	kstat_named_init(&nxgekp->lp_cap_10gfdx, "lp_cap_10gfdx",
1343 		KSTAT_DATA_ULONG);
1344 	kstat_named_init(&nxgekp->lp_cap_10ghdx, "lp_cap_10ghdx",
1345 		KSTAT_DATA_ULONG);
1346 	kstat_named_init(&nxgekp->lp_cap_1000fdx, "lp_cap_1000fdx",
1347 		KSTAT_DATA_ULONG);
1348 	kstat_named_init(&nxgekp->lp_cap_1000hdx, "lp_cap_1000hdx",
1349 		KSTAT_DATA_ULONG);
1350 	kstat_named_init(&nxgekp->lp_cap_100T4, "lp_cap_100T4",
1351 		KSTAT_DATA_ULONG);
1352 	kstat_named_init(&nxgekp->lp_cap_100fdx, "lp_cap_100fdx",
1353 		KSTAT_DATA_ULONG);
1354 	kstat_named_init(&nxgekp->lp_cap_100hdx, "lp_cap_100hdx",
1355 		KSTAT_DATA_ULONG);
1356 	kstat_named_init(&nxgekp->lp_cap_10fdx, "lp_cap_10fdx",
1357 		KSTAT_DATA_ULONG);
1358 	kstat_named_init(&nxgekp->lp_cap_10hdx, "lp_cap_10hdx",
1359 		KSTAT_DATA_ULONG);
1360 	kstat_named_init(&nxgekp->lp_cap_asmpause, "lp_cap_asmpause",
1361 		KSTAT_DATA_ULONG);
1362 	kstat_named_init(&nxgekp->lp_cap_pause, "lp_cap_pause",
1363 		KSTAT_DATA_ULONG);
1364 	/*
1365 	 * Shared link setup.
1366 	 */
1367 	kstat_named_init(&nxgekp->link_T4, "link_T4",
1368 		KSTAT_DATA_ULONG);
1369 	kstat_named_init(&nxgekp->link_speed, "link_speed",
1370 		KSTAT_DATA_ULONG);
1371 	kstat_named_init(&nxgekp->link_duplex, "link_duplex",
1372 		KSTAT_DATA_CHAR);
1373 	kstat_named_init(&nxgekp->link_asmpause, "link_asmpause",
1374 		KSTAT_DATA_ULONG);
1375 	kstat_named_init(&nxgekp->link_pause, "link_pause",
1376 		KSTAT_DATA_ULONG);
1377 	kstat_named_init(&nxgekp->link_up, "link_up",
1378 		KSTAT_DATA_ULONG);
1379 
1380 	/*
1381 	 * Let the user know the MTU currently in use by the physical MAC
1382 	 * port.
1383 	 */
1384 	kstat_named_init(&nxgekp->mac_mtu, "mac_mtu",
1385 		KSTAT_DATA_ULONG);
1386 
1387 	/*
1388 	 * Loopback statistics.
1389 	 */
1390 	kstat_named_init(&nxgekp->lb_mode, "lb_mode",
1391 		KSTAT_DATA_ULONG);
1392 
1393 	/*
1394 	 * This tells the user whether the driver is in QOS mode or not.
1395 	 */
1396 	kstat_named_init(&nxgekp->qos_mode, "qos_mode",
1397 		KSTAT_DATA_ULONG);
1398 
1399 	/*
1400 	 * This tells whether the instance is trunked or not
1401 	 */
1402 	kstat_named_init(&nxgekp->trunk_mode, "trunk_mode",
1403 		KSTAT_DATA_ULONG);
1404 
1405 #if defined MULTI_DATA_TX || defined MULTI_DATA_TXV2
1406 	kstat_named_init(&nxgekp->mdt_reqs, "mdt_reqs",
1407 		KSTAT_DATA_ULONG);
1408 	kstat_named_init(&nxgekp->mdt_hdr_bufs, "mdt_hdr_bufs",
1409 		KSTAT_DATA_ULONG);
1410 	kstat_named_init(&nxgekp->mdt_pld_bufs, "mdt_pld_bufs",
1411 		KSTAT_DATA_ULONG);
1412 	kstat_named_init(&nxgekp->mdt_pkts, "mdt_pkts",
1413 		KSTAT_DATA_ULONG);
1414 	kstat_named_init(&nxgekp->mdt_hdrs, "mdt_hdrs",
1415 		KSTAT_DATA_ULONG);
1416 	kstat_named_init(&nxgekp->mdt_plds, "mdt_plds",
1417 		KSTAT_DATA_ULONG);
1418 	kstat_named_init(&nxgekp->mdt_hdr_bind_fail, "mdt_hdr_bind_fail",
1419 		KSTAT_DATA_ULONG);
1420 	kstat_named_init(&nxgekp->mdt_pld_bind_fail, "mdt_pld_bind_fail",
1421 		KSTAT_DATA_ULONG);
1422 #endif
1423 #ifdef ACCEPT_JUMBO
1424 	kstat_named_init(&nxgekp->tx_jumbo_pkts, "tx_jumbo_pkts",
1425 		KSTAT_DATA_ULONG);
1426 #endif
1427 
1428 	/*
1429 	 * Rx Statistics.
1430 	 */
1431 #ifdef ACCEPT_JUMBO
1432 	kstat_named_init(&nxgekp->rx_jumbo_pkts, "rx_jumbo_pkts",
1433 		KSTAT_DATA_ULONG);
1434 #endif
1435 	/* General MAC statistics */
1436 	kstat_named_init(&nxgekp->ifspeed, "ifspeed",
1437 		KSTAT_DATA_UINT64);
1438 	kstat_named_init(&nxgekp->promisc, "promisc",
1439 		KSTAT_DATA_CHAR);
1440 	kstat_named_init(&nxgekp->rev_id, "rev_id",
1441 		KSTAT_DATA_ULONG);
1442 
1443 	ksp->ks_update = nxge_port_kstat_update;
1444 	ksp->ks_private = (void *) nxgep;
1445 	if (nxgep->mac.porttype == PORT_TYPE_XMAC)
1446 		nxge_xmac_init_kstats(ksp);
1447 	else
1448 		nxge_bmac_init_kstats(ksp);
1449 	kstat_install(ksp);
1450 	nxgep->statsp->port_ksp = ksp;
1451 	NXGE_DEBUG_MSG((nxgep, KST_CTL, "<== nxge_setup_kstats"));
1452 }
1453 
1454 /* ARGSUSED */
1455 void
1456 nxge_xmac_init_kstats(struct kstat *ksp)
1457 {
1458 	p_nxge_xmac_kstat_t nxgekp;
1459 
1460 	nxgekp = (p_nxge_xmac_kstat_t)ksp->ks_data;
1461 
1462 	/*
1463 	 * Transmit MAC statistics.
1464 	 */
1465 	kstat_named_init(&nxgekp->tx_frame_cnt, "txmac_frame_cnt",
1466 		KSTAT_DATA_ULONG);
1467 	kstat_named_init(&nxgekp->tx_underflow_err, "txmac_underflow_err",
1468 		KSTAT_DATA_ULONG);
1469 	kstat_named_init(&nxgekp->tx_overflow_err, "txmac_overflow_err",
1470 		KSTAT_DATA_ULONG);
1471 	kstat_named_init(&nxgekp->tx_maxpktsize_err, "txmac_maxpktsize_err",
1472 		KSTAT_DATA_ULONG);
1473 	kstat_named_init(&nxgekp->tx_fifo_xfr_err, "txmac_fifo_xfr_err",
1474 		KSTAT_DATA_ULONG);
1475 	kstat_named_init(&nxgekp->tx_byte_cnt, "txmac_byte_cnt",
1476 		KSTAT_DATA_ULONG);
1477 
1478 	/* Receive MAC statistics */
1479 	kstat_named_init(&nxgekp->rx_frame_cnt, "rxmac_frame_cnt",
1480 	    KSTAT_DATA_ULONG);
1481 	kstat_named_init(&nxgekp->rx_overflow_err, "rxmac_overflow_err",
1482 		KSTAT_DATA_ULONG);
1483 	kstat_named_init(&nxgekp->rx_underflow_err, "rxmac_underflow_err",
1484 		KSTAT_DATA_ULONG);
1485 	kstat_named_init(&nxgekp->rx_crc_err_cnt, "rxmac_crc_err",
1486 		KSTAT_DATA_ULONG);
1487 	kstat_named_init(&nxgekp->rx_len_err_cnt, "rxmac_length_err",
1488 		KSTAT_DATA_ULONG);
1489 	kstat_named_init(&nxgekp->rx_viol_err_cnt, "rxmac_code_violations",
1490 		KSTAT_DATA_ULONG);
1491 	kstat_named_init(&nxgekp->rx_byte_cnt, "rxmac_byte_cnt",
1492 		KSTAT_DATA_ULONG);
1493 	kstat_named_init(&nxgekp->rx_frame_align_err_cnt,
1494 		"rxmac_alignment_err",
1495 		KSTAT_DATA_ULONG);
1496 	kstat_named_init(&nxgekp->rx_hist1_cnt, "rxmac_64_cnt",
1497 		KSTAT_DATA_ULONG);
1498 	kstat_named_init(&nxgekp->rx_hist2_cnt, "rxmac_65_127_cnt",
1499 		KSTAT_DATA_ULONG);
1500 	kstat_named_init(&nxgekp->rx_hist3_cnt, "rxmac_128_255_cnt",
1501 		KSTAT_DATA_ULONG);
1502 	kstat_named_init(&nxgekp->rx_hist4_cnt, "rxmac_256_511_cnt",
1503 		KSTAT_DATA_ULONG);
1504 	kstat_named_init(&nxgekp->rx_hist5_cnt, "rxmac_512_1023_cnt",
1505 		KSTAT_DATA_ULONG);
1506 	kstat_named_init(&nxgekp->rx_hist6_cnt, "rxmac_1024_1522_cnt",
1507 		KSTAT_DATA_ULONG);
1508 	kstat_named_init(&nxgekp->rx_hist7_cnt, "rxmac_jumbo_cnt",
1509 	    KSTAT_DATA_ULONG);
1510 	kstat_named_init(&nxgekp->rx_broadcast_cnt, "rxmac_broadcast_cnt",
1511 		KSTAT_DATA_ULONG);
1512 	kstat_named_init(&nxgekp->rx_mult_cnt, "rxmac_multicast_cnt",
1513 		KSTAT_DATA_ULONG);
1514 	kstat_named_init(&nxgekp->rx_frag_cnt, "rxmac_fragment_cnt",
1515 		KSTAT_DATA_ULONG);
1516 	kstat_named_init(&nxgekp->rx_linkfault_err_cnt, "rxmac_linkfault_errs",
1517 		KSTAT_DATA_ULONG);
1518 	kstat_named_init(&nxgekp->rx_remote_fault_err_cnt,
1519 		"rxmac_remote_faults",
1520 		KSTAT_DATA_ULONG);
1521 	kstat_named_init(&nxgekp->rx_local_fault_err_cnt, "rxmac_local_faults",
1522 		KSTAT_DATA_ULONG);
1523 
1524 	/* XPCS statistics */
1525 
1526 	kstat_named_init(&nxgekp->xpcs_deskew_err_cnt, "xpcs_deskew_err_cnt",
1527 		KSTAT_DATA_ULONG);
1528 #ifdef	NXGE_DEBUG_SYMBOL_ERR
1529 	kstat_named_init(&nxgekp->xpcs_ln0_symbol_err_cnt,
1530 		"xpcs_ln0_symbol_err_cnt",
1531 		KSTAT_DATA_ULONG);
1532 	kstat_named_init(&nxgekp->xpcs_ln1_symbol_err_cnt,
1533 		"xpcs_ln1_symbol_err_cnt",
1534 		KSTAT_DATA_ULONG);
1535 	kstat_named_init(&nxgekp->xpcs_ln2_symbol_err_cnt,
1536 		"xpcs_ln2_symbol_err_cnt",
1537 		KSTAT_DATA_ULONG);
1538 	kstat_named_init(&nxgekp->xpcs_ln3_symbol_err_cnt,
1539 		"xpcs_ln3_symbol_err_cnt",
1540 		KSTAT_DATA_ULONG);
1541 #endif
1542 }
1543 
1544 /* ARGSUSED */
1545 void
1546 nxge_bmac_init_kstats(struct kstat *ksp)
1547 {
1548 	p_nxge_bmac_kstat_t nxgekp;
1549 
1550 	nxgekp = (p_nxge_bmac_kstat_t)ksp->ks_data;
1551 
1552 	/*
1553 	 * Transmit MAC statistics.
1554 	 */
1555 	kstat_named_init(&nxgekp->tx_frame_cnt, "txmac_frame_cnt",
1556 		KSTAT_DATA_ULONG);
1557 	kstat_named_init(&nxgekp->tx_underrun_err, "txmac_underflow_err",
1558 		KSTAT_DATA_ULONG);
1559 	kstat_named_init(&nxgekp->tx_max_pkt_err, "txmac_maxpktsize_err",
1560 		KSTAT_DATA_ULONG);
1561 	kstat_named_init(&nxgekp->tx_byte_cnt, "txmac_byte_cnt",
1562 		KSTAT_DATA_ULONG);
1563 
1564 	/* Receive MAC statistics */
1565 	kstat_named_init(&nxgekp->rx_overflow_err, "rxmac_overflow_err",
1566 		KSTAT_DATA_ULONG);
1567 	kstat_named_init(&nxgekp->rx_crc_err_cnt, "rxmac_crc_err",
1568 		KSTAT_DATA_ULONG);
1569 	kstat_named_init(&nxgekp->rx_len_err_cnt, "rxmac_length_err",
1570 		KSTAT_DATA_ULONG);
1571 	kstat_named_init(&nxgekp->rx_viol_err_cnt, "rxmac_code_violations",
1572 		KSTAT_DATA_ULONG);
1573 	kstat_named_init(&nxgekp->rx_byte_cnt, "rxmac_byte_cnt",
1574 		KSTAT_DATA_ULONG);
1575 	kstat_named_init(&nxgekp->rx_align_err_cnt, "rxmac_alignment_err",
1576 		KSTAT_DATA_ULONG);
1577 	kstat_named_init(&nxgekp->rx_frame_cnt, "rxmac_frame_cnt",
1578 		KSTAT_DATA_ULONG);
1579 }
1580 
1581 /* ARGSUSED */
1582 void
1583 nxge_mac_init_kstats(p_nxge_t nxgep, struct kstat *ksp)
1584 {
1585 	p_nxge_mac_kstat_t nxgekp;
1586 
1587 	nxgekp = (p_nxge_mac_kstat_t)ksp->ks_data;
1588 
1589 	/*
1590 	 * Transmit MAC statistics.
1591 	 */
1592 	kstat_named_init(&nxgekp->tx_frame_cnt, "txmac_frame_cnt",
1593 		KSTAT_DATA_ULONG);
1594 	kstat_named_init(&nxgekp->tx_underflow_err, "txmac_underflow_err",
1595 		KSTAT_DATA_ULONG);
1596 	kstat_named_init(&nxgekp->tx_overflow_err, "txmac_overflow_err",
1597 		KSTAT_DATA_ULONG);
1598 	kstat_named_init(&nxgekp->tx_maxpktsize_err, "txmac_maxpktsize_err",
1599 		KSTAT_DATA_ULONG);
1600 	kstat_named_init(&nxgekp->tx_fifo_xfr_err, "txmac_fifo_xfr_err",
1601 		KSTAT_DATA_ULONG);
1602 	kstat_named_init(&nxgekp->tx_byte_cnt, "txmac_byte_cnt",
1603 		KSTAT_DATA_ULONG);
1604 
1605 	/*
1606 	 * Receive MAC statistics
1607 	 */
1608 	kstat_named_init(&nxgekp->rx_overflow_err, "rxmac_overflow_err",
1609 		KSTAT_DATA_ULONG);
1610 	kstat_named_init(&nxgekp->rx_underflow_err, "rxmac_underflow_err",
1611 		KSTAT_DATA_ULONG);
1612 	kstat_named_init(&nxgekp->rx_crc_err_cnt, "rxmac_crc_err",
1613 		KSTAT_DATA_ULONG);
1614 	kstat_named_init(&nxgekp->rx_len_err_cnt, "rxmac_length_err",
1615 		KSTAT_DATA_ULONG);
1616 	kstat_named_init(&nxgekp->rx_viol_err_cnt, "rxmac_code_violations",
1617 		KSTAT_DATA_ULONG);
1618 	kstat_named_init(&nxgekp->rx_byte_cnt, "rxmac_byte_cnt",
1619 		KSTAT_DATA_ULONG);
1620 	kstat_named_init(&nxgekp->rx_frame_align_err_cnt,
1621 		"rxmac_alignment_err",
1622 		KSTAT_DATA_ULONG);
1623 	kstat_named_init(&nxgekp->rx_frame_cnt, "rxmac_frame_cnt",
1624 	    KSTAT_DATA_ULONG);
1625 	if (nxgep->mac.porttype == PORT_TYPE_XMAC) {
1626 		kstat_named_init(&nxgekp->rx_hist1_cnt, "rxmac_64_cnt",
1627 			KSTAT_DATA_ULONG);
1628 		kstat_named_init(&nxgekp->rx_hist2_cnt, "rxmac_65_127_cnt",
1629 			KSTAT_DATA_ULONG);
1630 		kstat_named_init(&nxgekp->rx_hist3_cnt, "rxmac_128_255_cnt",
1631 			KSTAT_DATA_ULONG);
1632 		kstat_named_init(&nxgekp->rx_hist4_cnt, "rxmac_256_511_cnt",
1633 			KSTAT_DATA_ULONG);
1634 		kstat_named_init(&nxgekp->rx_hist5_cnt, "rxmac_512_1023_cnt",
1635 			KSTAT_DATA_ULONG);
1636 		kstat_named_init(&nxgekp->rx_hist6_cnt, "rxmac_1024_1522_cnt",
1637 			KSTAT_DATA_ULONG);
1638 		kstat_named_init(&nxgekp->rx_hist7_cnt, "rxmac_jumbo_cnt",
1639 		    KSTAT_DATA_ULONG);
1640 		kstat_named_init(&nxgekp->rx_broadcast_cnt,
1641 			"rxmac_broadcast_cnt",
1642 			KSTAT_DATA_ULONG);
1643 		kstat_named_init(&nxgekp->rx_mult_cnt, "rxmac_multicast_cnt",
1644 			KSTAT_DATA_ULONG);
1645 		kstat_named_init(&nxgekp->rx_frag_cnt, "rxmac_fragment_cnt",
1646 			KSTAT_DATA_ULONG);
1647 		kstat_named_init(&nxgekp->rx_linkfault_err_cnt,
1648 			"rxmac_linkfault_errs",
1649 			KSTAT_DATA_ULONG);
1650 		kstat_named_init(&nxgekp->rx_remote_fault_err_cnt,
1651 			"rxmac_remote_faults",
1652 			KSTAT_DATA_ULONG);
1653 		kstat_named_init(&nxgekp->rx_local_fault_err_cnt,
1654 			"rxmac_local_faults",
1655 			KSTAT_DATA_ULONG);
1656 	}
1657 }
1658 
1659 /* ARGSUSED */
1660 void
1661 nxge_destroy_kstats(p_nxge_t nxgep)
1662 {
1663 	int channel;
1664 	p_nxge_dma_pt_cfg_t p_dma_cfgp;
1665 	p_nxge_hw_pt_cfg_t p_cfgp;
1666 
1667 	NXGE_DEBUG_MSG((nxgep, KST_CTL, "==> nxge_destroy_kstats"));
1668 
1669 	if (nxgep->statsp == NULL)
1670 		return;
1671 	if (nxgep->statsp->ksp)
1672 		kstat_delete(nxgep->statsp->ksp);
1673 
1674 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
1675 	p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
1676 
1677 	for (channel = 0; channel < p_cfgp->max_rdcs; channel++) {
1678 		if (nxgep->statsp->rdc_ksp[channel])
1679 			kstat_delete(nxgep->statsp->rdc_ksp[channel]);
1680 	}
1681 
1682 	for (channel = 0; channel < p_cfgp->max_tdcs; channel++) {
1683 		if (nxgep->statsp->tdc_ksp[channel])
1684 			kstat_delete(nxgep->statsp->tdc_ksp[channel]);
1685 	}
1686 
1687 	if (nxgep->statsp->rdc_sys_ksp)
1688 		kstat_delete(nxgep->statsp->rdc_sys_ksp);
1689 	if (nxgep->statsp->fflp_ksp[0])
1690 		kstat_delete(nxgep->statsp->fflp_ksp[0]);
1691 	if (nxgep->statsp->ipp_ksp)
1692 		kstat_delete(nxgep->statsp->ipp_ksp);
1693 	if (nxgep->statsp->txc_ksp)
1694 		kstat_delete(nxgep->statsp->txc_ksp);
1695 	if (nxgep->statsp->mac_ksp)
1696 		kstat_delete(nxgep->statsp->mac_ksp);
1697 	if (nxgep->statsp->zcp_ksp)
1698 		kstat_delete(nxgep->statsp->zcp_ksp);
1699 	if (nxgep->statsp->port_ksp)
1700 		kstat_delete(nxgep->statsp->port_ksp);
1701 	if (nxgep->statsp->mmac_ksp)
1702 		kstat_delete(nxgep->statsp->mmac_ksp);
1703 	if (nxgep->statsp)
1704 		KMEM_FREE(nxgep->statsp, nxgep->statsp->stats_size);
1705 
1706 	NXGE_DEBUG_MSG((nxgep, KST_CTL, "<== nxge_destroy_kstats"));
1707 }
1708 
1709 /* ARGSUSED */
1710 int
1711 nxge_port_kstat_update(kstat_t *ksp, int rw)
1712 {
1713 	p_nxge_t nxgep;
1714 	p_nxge_stats_t statsp;
1715 	p_nxge_port_kstat_t nxgekp;
1716 
1717 	nxgep = (p_nxge_t)ksp->ks_private;
1718 	if (nxgep == NULL)
1719 		return (-1);
1720 
1721 	NXGE_DEBUG_MSG((nxgep, KST_CTL, "==> nxge_port_kstat_update"));
1722 	statsp = (p_nxge_stats_t)nxgep->statsp;
1723 	nxgekp = (p_nxge_port_kstat_t)ksp->ks_data;
1724 	nxge_save_cntrs(nxgep);
1725 
1726 	if (rw == KSTAT_WRITE) {
1727 		/*
1728 		 * transceiver state informations.
1729 		 */
1730 		statsp->mac_stats.xcvr_inits = nxgekp->xcvr_inits.value.ul;
1731 
1732 		/*
1733 		 * Tx Statistics.
1734 		 */
1735 #if defined MULTI_DATA_TX || defined MULTI_DATA_TXV2
1736 		statsp->port_stats.mdt_reqs = nxgekp->mdt_reqs.value.ul;
1737 		statsp->port_stats.mdt_hdr_bufs = nxgekp->mdt_hdr_bufs.value.ul;
1738 		statsp->port_stats.mdt_pld_bufs = nxgekp->mdt_pld_bufs.value.ul;
1739 		statsp->port_stats.mdt_pkts = nxgekp->mdt_pkts.value.ul;
1740 		statsp->port_stats.mdt_hdrs = nxgekp->mdt_hdrs.value.ul;
1741 		statsp->port_stats.mdt_plds = nxgekp->mdt_plds.value.ul;
1742 		statsp->port_stats.mdt_hdr_bind_fail =
1743 			nxgekp->mdt_hdr_bind_fail.value.ul;
1744 		statsp->port_stats.mdt_pld_bind_fail =
1745 			nxgekp->mdt_pld_bind_fail.value.ul;
1746 #endif
1747 #ifdef ACCEPT_JUMBO
1748 		statsp->port_stats.tx_jumbo_pkts =
1749 			nxgekp->tx_jumbo_pkts.value.ul;
1750 #endif
1751 		/*
1752 		 * Rx Statistics.
1753 		 */
1754 #ifdef ACCEPT_JUMBO
1755 		statsp->port_stats.rx_jumbo_pkts =
1756 			nxgekp->rx_jumbo_pkts.value.ul;
1757 #endif
1758 		if (nxgep->mac.porttype == PORT_TYPE_XMAC) {
1759 			(void) nxge_xmac_stat_update(ksp, KSTAT_WRITE);
1760 		} else {
1761 			(void) nxge_bmac_stat_update(ksp, KSTAT_WRITE);
1762 		}
1763 		return (0);
1764 	} else {
1765 		if (nxgep->filter.all_phys_cnt)
1766 			(void) strcpy(nxgekp->promisc.value.c, "phys");
1767 		else if (nxgep->filter.all_multicast_cnt)
1768 			(void) strcpy(nxgekp->promisc.value.c, "multi");
1769 		else
1770 			(void) strcpy(nxgekp->promisc.value.c, "off");
1771 		nxgekp->ifspeed.value.ul =
1772 			statsp->mac_stats.link_speed * 1000000ULL;
1773 		nxgekp->rev_id.value.ul = statsp->mac_stats.rev_id;
1774 
1775 		/*
1776 		 * transceiver state informations.
1777 		 */
1778 		nxgekp->xcvr_inits.value.ul = statsp->mac_stats.xcvr_inits;
1779 		nxgekp->xcvr_inuse.value.ul = statsp->mac_stats.xcvr_inuse;
1780 		nxgekp->xcvr_addr.value.ul = statsp->mac_stats.xcvr_portn;
1781 		nxgekp->xcvr_id.value.ul = statsp->mac_stats.xcvr_id;
1782 		nxgekp->cap_autoneg.value.ul = statsp->mac_stats.cap_autoneg;
1783 		nxgekp->cap_10gfdx.value.ul = statsp->mac_stats.cap_10gfdx;
1784 		nxgekp->cap_10ghdx.value.ul = statsp->mac_stats.cap_10ghdx;
1785 		nxgekp->cap_1000fdx.value.ul = statsp->mac_stats.cap_1000fdx;
1786 		nxgekp->cap_1000hdx.value.ul = statsp->mac_stats.cap_1000hdx;
1787 		nxgekp->cap_100T4.value.ul = statsp->mac_stats.cap_100T4;
1788 		nxgekp->cap_100fdx.value.ul = statsp->mac_stats.cap_100fdx;
1789 		nxgekp->cap_100hdx.value.ul = statsp->mac_stats.cap_100hdx;
1790 		nxgekp->cap_10fdx.value.ul = statsp->mac_stats.cap_10fdx;
1791 		nxgekp->cap_10hdx.value.ul = statsp->mac_stats.cap_10hdx;
1792 		nxgekp->cap_asmpause.value.ul =
1793 			statsp->mac_stats.cap_asmpause;
1794 		nxgekp->cap_pause.value.ul = statsp->mac_stats.cap_pause;
1795 
1796 		/*
1797 		 * Link partner capabilities.
1798 		 */
1799 		nxgekp->lp_cap_autoneg.value.ul =
1800 			statsp->mac_stats.lp_cap_autoneg;
1801 		nxgekp->lp_cap_10gfdx.value.ul =
1802 			statsp->mac_stats.lp_cap_10gfdx;
1803 		nxgekp->lp_cap_10ghdx.value.ul =
1804 			statsp->mac_stats.lp_cap_10ghdx;
1805 		nxgekp->lp_cap_1000fdx.value.ul =
1806 			statsp->mac_stats.lp_cap_1000fdx;
1807 		nxgekp->lp_cap_1000hdx.value.ul =
1808 			statsp->mac_stats.lp_cap_1000hdx;
1809 		nxgekp->lp_cap_100T4.value.ul =
1810 			statsp->mac_stats.lp_cap_100T4;
1811 		nxgekp->lp_cap_100fdx.value.ul =
1812 			statsp->mac_stats.lp_cap_100fdx;
1813 		nxgekp->lp_cap_100hdx.value.ul =
1814 			statsp->mac_stats.lp_cap_100hdx;
1815 		nxgekp->lp_cap_10fdx.value.ul =
1816 			statsp->mac_stats.lp_cap_10fdx;
1817 		nxgekp->lp_cap_10hdx.value.ul =
1818 			statsp->mac_stats.lp_cap_10hdx;
1819 		nxgekp->lp_cap_asmpause.value.ul =
1820 			statsp->mac_stats.lp_cap_asmpause;
1821 		nxgekp->lp_cap_pause.value.ul =
1822 			statsp->mac_stats.lp_cap_pause;
1823 
1824 		/*
1825 		 * Physical link statistics.
1826 		 */
1827 		nxgekp->link_T4.value.ul = statsp->mac_stats.link_T4;
1828 		nxgekp->link_speed.value.ul = statsp->mac_stats.link_speed;
1829 		if (statsp->mac_stats.link_duplex == 2)
1830 			(void) strcpy(nxgekp->link_duplex.value.c, "full");
1831 		else if (statsp->mac_stats.link_duplex == 1)
1832 			(void) strcpy(nxgekp->link_duplex.value.c, "half");
1833 		else
1834 			(void) strcpy(nxgekp->link_duplex.value.c, "unknown");
1835 		nxgekp->link_asmpause.value.ul =
1836 			statsp->mac_stats.link_asmpause;
1837 		nxgekp->link_pause.value.ul = statsp->mac_stats.link_pause;
1838 		nxgekp->link_up.value.ul = statsp->mac_stats.link_up;
1839 
1840 		/*
1841 		 * Lets the user know the MTU currently in use by the physical
1842 		 * MAC port.
1843 		 */
1844 		nxgekp->mac_mtu.value.ul = statsp->mac_stats.mac_mtu;
1845 
1846 		/*
1847 		 * Loopback statistics.
1848 		 */
1849 		nxgekp->lb_mode.value.ul = statsp->port_stats.lb_mode;
1850 
1851 		/*
1852 		 * This tells the user whether the driver is in QOS mode or
1853 		 * not.
1854 		 */
1855 		nxgekp->qos_mode.value.ul = statsp->port_stats.qos_mode;
1856 
1857 		/*
1858 		 * This tells whether the instance is trunked or not
1859 		 */
1860 		nxgekp->trunk_mode.value.ul = statsp->port_stats.trunk_mode;
1861 
1862 #if defined MULTI_DATA_TX || defined MULTI_DATA_TXV2
1863 		nxgekp->mdt_reqs.value.ul = statsp->port_stats.mdt_reqs;
1864 		nxgekp->mdt_hdr_bufs.value.ul =
1865 			statsp->port_stats.mdt_hdr_bufs;
1866 		nxgekp->mdt_pld_bufs.value.ul =
1867 			statsp->port_stats.mdt_pld_bufs;
1868 		nxgekp->mdt_pkts.value.ul = statsp->port_stats.mdt_pkts;
1869 		nxgekp->mdt_hdrs.value.ul = statsp->port_stats.mdt_hdrs;
1870 		nxgekp->mdt_plds.value.ul = statsp->port_stats.mdt_plds;
1871 		nxgekp->mdt_hdr_bind_fail.value.ul =
1872 			statsp->port_stats.mdt_hdr_bind_fail;
1873 		nxgekp->mdt_pld_bind_fail.value.ul =
1874 			statsp->port_stats.mdt_pld_bind_fail;
1875 #endif
1876 #ifdef ACCEPT_JUMBO
1877 		nxgekp->tx_jumbo_pkts.value.ul =
1878 			statsp->port_stats.tx_jumbo_pkts;
1879 #endif
1880 #ifdef TX_MBLK_DEST
1881 		nxgekp->tx_1_desc.value.ul = statsp->port_stats.tx_1_desc;
1882 		nxgekp->tx_2_desc.value.ul = statsp->port_stats.tx_2_desc;
1883 		nxgekp->tx_3_desc.value.ul = statsp->port_stats.tx_3_desc;
1884 		nxgekp->tx_4_desc.value.ul = statsp->port_stats.tx_4_desc;
1885 		nxgekp->tx_5_desc.value.ul = statsp->port_stats.tx_5_desc;
1886 		nxgekp->tx_6_desc.value.ul = statsp->port_stats.tx_6_desc;
1887 		nxgekp->tx_7_desc.value.ul = statsp->port_stats.tx_7_desc;
1888 		nxgekp->tx_8_desc.value.ul = statsp->port_stats.tx_8_desc;
1889 		nxgekp->tx_max_desc.value.ul =
1890 			statsp->port_stats.tx_max_desc;
1891 #endif
1892 		/*
1893 		 * Rx Statistics.
1894 		 */
1895 #ifdef ACCEPT_JUMBO
1896 		nxgekp->rx_jumbo_pkts.value.ul =
1897 			statsp->port_stats.rx_jumbo_pkts;
1898 #endif
1899 		if (nxgep->mac.porttype == PORT_TYPE_XMAC) {
1900 			(void) nxge_xmac_stat_update(ksp, KSTAT_READ);
1901 		} else {
1902 			(void) nxge_bmac_stat_update(ksp, KSTAT_READ);
1903 		}
1904 	}
1905 
1906 	NXGE_DEBUG_MSG((nxgep, KST_CTL, "<== nxge_port_kstat_update"));
1907 	return (0);
1908 }
1909 
1910 /*
1911  * if this is the first init do not bother to save the
1912  * counters.
1913  */
1914 /* ARGSUSED */
1915 void
1916 nxge_save_cntrs(p_nxge_t nxgep)
1917 {
1918 	p_nxge_stats_t statsp;
1919 	uint64_t val;
1920 	npi_handle_t handle;
1921 	uint8_t portn;
1922 	uint8_t cnt8;
1923 	uint16_t cnt16;
1924 	uint32_t cnt32;
1925 
1926 	NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_save_cntrs"));
1927 
1928 	statsp = (p_nxge_stats_t)nxgep->statsp;
1929 	handle = nxgep->npi_handle;
1930 	portn = nxgep->mac.portnum;
1931 
1932 	MUTEX_ENTER(&nxgep->ouraddr_lock);
1933 
1934 	if (nxgep->mac.porttype == PORT_TYPE_XMAC) {
1935 		/*
1936 		 * Transmit MAC statistics.
1937 		 */
1938 		XMAC_REG_RD(handle, portn, XTXMAC_FRM_CNT_REG, &val);
1939 		statsp->xmac_stats.tx_frame_cnt += (val & XTXMAC_FRM_CNT_MASK);
1940 		XMAC_REG_RD(handle, portn, XTXMAC_BYTE_CNT_REG, &val);
1941 		statsp->xmac_stats.tx_byte_cnt += (val & XTXMAC_BYTE_CNT_MASK);
1942 		/*
1943 		 * Receive XMAC statistics.
1944 		 */
1945 		XMAC_REG_RD(handle, portn, XRXMAC_CRC_ER_CNT_REG, &val);
1946 		statsp->xmac_stats.rx_crc_err_cnt +=
1947 			(val & XRXMAC_CRC_ER_CNT_MASK);
1948 
1949 		XMAC_REG_RD(handle, portn, XRXMAC_MPSZER_CNT_REG, &val);
1950 		statsp->xmac_stats.rx_len_err_cnt +=
1951 			(val & XRXMAC_MPSZER_CNT_MASK);
1952 
1953 		XMAC_REG_RD(handle, portn, XRXMAC_CD_VIO_CNT_REG, &val);
1954 		statsp->xmac_stats.rx_viol_err_cnt +=
1955 			(val & XRXMAC_CD_VIO_CNT_MASK);
1956 
1957 		XMAC_REG_RD(handle, portn, XRXMAC_BT_CNT_REG, &val);
1958 		statsp->xmac_stats.rx_byte_cnt += (val & XRXMAC_BT_CNT_MASK);
1959 
1960 		XMAC_REG_RD(handle, portn, XRXMAC_HIST_CNT1_REG, &val);
1961 		statsp->xmac_stats.rx_hist1_cnt +=
1962 			(val & XRXMAC_HIST_CNT1_MASK);
1963 		statsp->xmac_stats.rx_frame_cnt +=
1964 		    (val & XRXMAC_HIST_CNT1_MASK);
1965 
1966 		XMAC_REG_RD(handle, portn, XRXMAC_HIST_CNT2_REG, &val);
1967 		statsp->xmac_stats.rx_hist2_cnt +=
1968 			(val & XRXMAC_HIST_CNT2_MASK);
1969 		statsp->xmac_stats.rx_frame_cnt +=
1970 		    (val & XRXMAC_HIST_CNT2_MASK);
1971 
1972 		XMAC_REG_RD(handle, portn, XRXMAC_HIST_CNT3_REG, &val);
1973 		statsp->xmac_stats.rx_hist3_cnt +=
1974 			(val & XRXMAC_HIST_CNT3_MASK);
1975 		statsp->xmac_stats.rx_frame_cnt +=
1976 		    (val & XRXMAC_HIST_CNT3_MASK);
1977 
1978 		XMAC_REG_RD(handle, portn, XRXMAC_HIST_CNT4_REG, &val);
1979 		statsp->xmac_stats.rx_hist4_cnt +=
1980 			(val & XRXMAC_HIST_CNT4_MASK);
1981 		statsp->xmac_stats.rx_frame_cnt +=
1982 		    (val & XRXMAC_HIST_CNT4_MASK);
1983 
1984 		XMAC_REG_RD(handle, portn, XRXMAC_HIST_CNT5_REG, &val);
1985 		statsp->xmac_stats.rx_hist5_cnt +=
1986 			(val & XRXMAC_HIST_CNT5_MASK);
1987 		statsp->xmac_stats.rx_frame_cnt +=
1988 		    (val & XRXMAC_HIST_CNT5_MASK);
1989 
1990 		XMAC_REG_RD(handle, portn, XRXMAC_HIST_CNT6_REG, &val);
1991 		statsp->xmac_stats.rx_hist6_cnt +=
1992 			(val & XRXMAC_HIST_CNT6_MASK);
1993 		statsp->xmac_stats.rx_frame_cnt +=
1994 		    (val & XRXMAC_HIST_CNT6_MASK);
1995 
1996 		XMAC_REG_RD(handle, portn, XRXMAC_HIST_CNT7_REG, &val);
1997 		statsp->xmac_stats.rx_hist7_cnt +=
1998 		    (val & XRXMAC_HIST_CNT7_MASK);
1999 		statsp->xmac_stats.rx_frame_cnt +=
2000 		    (val & XRXMAC_HIST_CNT7_MASK);
2001 
2002 		XMAC_REG_RD(handle, portn, XRXMAC_BC_FRM_CNT_REG, &val);
2003 		statsp->xmac_stats.rx_broadcast_cnt +=
2004 			(val & XRXMAC_BC_FRM_CNT_MASK);
2005 
2006 		XMAC_REG_RD(handle, portn, XRXMAC_MC_FRM_CNT_REG, &val);
2007 		statsp->xmac_stats.rx_mult_cnt +=
2008 			(val & XRXMAC_MC_FRM_CNT_MASK);
2009 
2010 		XMAC_REG_RD(handle, portn, XRXMAC_FRAG_CNT_REG, &val);
2011 		statsp->xmac_stats.rx_frag_cnt += (val & XRXMAC_FRAG_CNT_MASK);
2012 
2013 		XMAC_REG_RD(handle, portn, XRXMAC_AL_ER_CNT_REG, &val);
2014 		statsp->xmac_stats.rx_frame_align_err_cnt +=
2015 			(val & XRXMAC_AL_ER_CNT_MASK);
2016 
2017 		XMAC_REG_RD(handle, portn, XMAC_LINK_FLT_CNT_REG, &val);
2018 		statsp->xmac_stats.rx_linkfault_err_cnt +=
2019 			(val & XMAC_LINK_FLT_CNT_MASK);
2020 
2021 		(void) npi_xmac_xpcs_read(handle, portn,
2022 			XPCS_REG_DESCWERR_COUNTER, &cnt32);
2023 		statsp->xmac_stats.xpcs_deskew_err_cnt +=
2024 			(val & XMAC_XPCS_DESKEW_ERR_CNT_MASK);
2025 
2026 #ifdef	NXGE_DEBUG_SYMBOL_ERR
2027 		(void) npi_xmac_xpcs_read(handle, portn,
2028 			XPCS_REG_SYMBOL_ERR_L0_1_COUNTER, &cnt32);
2029 		statsp->xmac_stats.xpcs_ln0_symbol_err_cnt +=
2030 			(cnt32 & XMAC_XPCS_SYM_ERR_CNT_L0_MASK);
2031 		statsp->xmac_stats.xpcs_ln1_symbol_err_cnt +=
2032 			((cnt32 & XMAC_XPCS_SYM_ERR_CNT_L1_MASK) >>
2033 			XMAC_XPCS_SYM_ERR_CNT_L1_SHIFT);
2034 		(void) npi_xmac_xpcs_read(handle, portn,
2035 			XPCS_REG_SYMBOL_ERR_L2_3_COUNTER, &cnt32);
2036 		statsp->xmac_stats.xpcs_ln2_symbol_err_cnt +=
2037 			(cnt32 & XMAC_XPCS_SYM_ERR_CNT_L2_MASK);
2038 		statsp->xmac_stats.xpcs_ln3_symbol_err_cnt +=
2039 			((cnt32 & XMAC_XPCS_SYM_ERR_CNT_L3_MASK) >>
2040 			XMAC_XPCS_SYM_ERR_CNT_L3_SHIFT);
2041 #endif
2042 	} else if (nxgep->mac.porttype == PORT_TYPE_BMAC) {
2043 		/*
2044 		 * Transmit MAC statistics.
2045 		 */
2046 		BMAC_REG_RD(handle, portn, BTXMAC_FRM_CNT_REG, &val);
2047 		statsp->bmac_stats.tx_frame_cnt += (val & BTXMAC_FRM_CNT_MASK);
2048 		/* Clear register as it is not auto clear on read */
2049 		BMAC_REG_WR(handle, portn, BTXMAC_FRM_CNT_REG, 0);
2050 
2051 		BMAC_REG_RD(handle, portn, BTXMAC_BYTE_CNT_REG, &val);
2052 		statsp->bmac_stats.tx_byte_cnt += (val & BTXMAC_BYTE_CNT_MASK);
2053 		/* Clear register as it is not auto clear on read */
2054 		BMAC_REG_WR(handle, portn, BTXMAC_BYTE_CNT_REG, 0);
2055 
2056 		/*
2057 		 * Receive MAC statistics.
2058 		 */
2059 		BMAC_REG_RD(handle, portn, RXMAC_FRM_CNT_REG, &val);
2060 		statsp->bmac_stats.rx_frame_cnt += (val & RXMAC_FRM_CNT_MASK);
2061 		/* Clear register as it is not auto clear on read */
2062 		BMAC_REG_WR(handle, portn, RXMAC_FRM_CNT_REG, 0);
2063 
2064 		BMAC_REG_RD(handle, portn, BRXMAC_BYTE_CNT_REG, &val);
2065 		statsp->bmac_stats.rx_byte_cnt += (val & BRXMAC_BYTE_CNT_MASK);
2066 		/* Clear register as it is not auto clear on read */
2067 		BMAC_REG_WR(handle, portn, BRXMAC_BYTE_CNT_REG, 0);
2068 
2069 		BMAC_REG_RD(handle, portn, BMAC_AL_ER_CNT_REG, &val);
2070 		statsp->bmac_stats.rx_align_err_cnt +=
2071 			(val & BMAC_AL_ER_CNT_MASK);
2072 		/* Clear register as it is not auto clear on read */
2073 		BMAC_REG_WR(handle, portn, BMAC_AL_ER_CNT_REG, 0);
2074 
2075 		BMAC_REG_RD(handle, portn, MAC_LEN_ER_CNT_REG, &val);
2076 		statsp->bmac_stats.rx_len_err_cnt +=
2077 			(val & MAC_LEN_ER_CNT_MASK);
2078 		/* Clear register as it is not auto clear on read */
2079 		BMAC_REG_WR(handle, portn, MAC_LEN_ER_CNT_REG, 0);
2080 
2081 		BMAC_REG_RD(handle, portn, BMAC_CRC_ER_CNT_REG, &val);
2082 		statsp->bmac_stats.rx_crc_err_cnt +=
2083 			(val & BMAC_CRC_ER_CNT_MASK);
2084 		/* Clear register as it is not auto clear on read */
2085 		BMAC_REG_WR(handle, portn, BMAC_CRC_ER_CNT_REG, 0);
2086 
2087 		BMAC_REG_RD(handle, portn, BMAC_CD_VIO_CNT_REG, &val);
2088 		statsp->bmac_stats.rx_viol_err_cnt +=
2089 			(val & BMAC_CD_VIO_CNT_MASK);
2090 		/* Clear register as it is not auto clear on read */
2091 		BMAC_REG_WR(handle, portn, BMAC_CD_VIO_CNT_REG, 0);
2092 	}
2093 	/* Update IPP counters */
2094 	(void) npi_ipp_get_ecc_err_count(handle, portn, &cnt8);
2095 	statsp->ipp_stats.ecc_err_cnt += cnt8;
2096 	(void) npi_ipp_get_pkt_dis_count(handle, portn, &cnt16);
2097 	statsp->ipp_stats.pkt_dis_cnt += cnt16;
2098 	(void) npi_ipp_get_cs_err_count(handle, portn, &cnt16);
2099 	statsp->ipp_stats.bad_cs_cnt += cnt16;
2100 
2101 	MUTEX_EXIT(&nxgep->ouraddr_lock);
2102 
2103 nxge_save_cntrs_exit:
2104 	NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_save_cntrs"));
2105 }
2106 
2107 /* ARGSUSED */
2108 int
2109 nxge_m_stat(void *arg, uint_t stat, uint64_t *value)
2110 {
2111 	p_nxge_t nxgep = (p_nxge_t)arg;
2112 	p_nxge_stats_t statsp;
2113 	uint64_t val = 0;
2114 	int channel;
2115 
2116 	NXGE_DEBUG_MSG((nxgep, KST_CTL, "==> nxge_m_stat"));
2117 	statsp = (p_nxge_stats_t)nxgep->statsp;
2118 
2119 	switch (stat) {
2120 	case MAC_STAT_IFSPEED:
2121 		val = statsp->mac_stats.link_speed * 1000000ull;
2122 		break;
2123 
2124 	case MAC_STAT_MULTIRCV:
2125 		val = statsp->port_stats.multircv;
2126 		break;
2127 
2128 	case MAC_STAT_BRDCSTRCV:
2129 		val = statsp->port_stats.brdcstrcv;
2130 		break;
2131 
2132 	case MAC_STAT_MULTIXMT:
2133 		val = statsp->port_stats.multixmt;
2134 		break;
2135 
2136 	case MAC_STAT_BRDCSTXMT:
2137 		val = statsp->port_stats.brdcstxmt;
2138 		break;
2139 
2140 	case MAC_STAT_NORCVBUF:
2141 		val = statsp->port_stats.norcvbuf;
2142 		break;
2143 
2144 	case MAC_STAT_IERRORS:
2145 	case ETHER_STAT_MACRCV_ERRORS:
2146 		val = 0;
2147 		for (channel = 0; channel < nxgep->nrdc; channel++) {
2148 			val += statsp->rdc_stats[channel].ierrors;
2149 		}
2150 		break;
2151 
2152 	case MAC_STAT_NOXMTBUF:
2153 		val = statsp->port_stats.noxmtbuf;
2154 		break;
2155 
2156 	case MAC_STAT_OERRORS:
2157 		for (channel = 0; channel < nxgep->ntdc; channel++) {
2158 			val += statsp->tdc_stats[channel].oerrors;
2159 		}
2160 
2161 		break;
2162 
2163 	case MAC_STAT_COLLISIONS:
2164 		val = 0;
2165 		break;
2166 
2167 	case MAC_STAT_RBYTES:
2168 		for (channel = 0; channel < nxgep->nrdc; channel++) {
2169 			val += statsp->rdc_stats[channel].ibytes;
2170 		}
2171 		break;
2172 
2173 	case MAC_STAT_IPACKETS:
2174 		for (channel = 0; channel < nxgep->nrdc; channel++) {
2175 			val += statsp->rdc_stats[channel].ipackets;
2176 		}
2177 		break;
2178 
2179 	case MAC_STAT_OBYTES:
2180 		for (channel = 0; channel < nxgep->ntdc; channel++) {
2181 			val += statsp->tdc_stats[channel].obytes;
2182 		}
2183 		break;
2184 
2185 	case MAC_STAT_OPACKETS:
2186 		for (channel = 0; channel < nxgep->ntdc; channel++) {
2187 			val += statsp->tdc_stats[channel].opackets;
2188 		}
2189 		break;
2190 	case MAC_STAT_LINK_STATE:
2191 		val = statsp->mac_stats.link_duplex;
2192 		break;
2193 	case MAC_STAT_LINK_UP:
2194 		val = statsp->mac_stats.link_up;
2195 		break;
2196 	case MAC_STAT_PROMISC:
2197 		val = statsp->mac_stats.promisc;
2198 		break;
2199 	case ETHER_STAT_SQE_ERRORS:
2200 		val = 0;
2201 		break;
2202 
2203 	case ETHER_STAT_ALIGN_ERRORS:
2204 		if (nxgep->mac.porttype == PORT_TYPE_XMAC)
2205 			val = statsp->xmac_stats.rx_frame_align_err_cnt;
2206 		else if (nxgep->mac.porttype == PORT_TYPE_BMAC)
2207 			val = statsp->bmac_stats.rx_align_err_cnt;
2208 		else
2209 			val = 0;
2210 		break;
2211 
2212 	case ETHER_STAT_FCS_ERRORS:
2213 		if (nxgep->mac.porttype == PORT_TYPE_XMAC)
2214 			val = statsp->xmac_stats.rx_crc_err_cnt;
2215 		else if (nxgep->mac.porttype == PORT_TYPE_BMAC)
2216 			val = statsp->bmac_stats.rx_crc_err_cnt;
2217 		else
2218 			val = 0;
2219 		break;
2220 
2221 	case ETHER_STAT_FIRST_COLLISIONS:
2222 		val = 0;
2223 		break;
2224 
2225 	case ETHER_STAT_MULTI_COLLISIONS:
2226 		val = 0;
2227 		break;
2228 
2229 	case ETHER_STAT_TX_LATE_COLLISIONS:
2230 		val = 0;
2231 		break;
2232 
2233 	case ETHER_STAT_EX_COLLISIONS:
2234 		val = 0;
2235 		break;
2236 
2237 	case ETHER_STAT_DEFER_XMTS:
2238 		val = 0;
2239 		break;
2240 
2241 	case ETHER_STAT_MACXMT_ERRORS:
2242 		if (nxgep->mac.porttype == PORT_TYPE_XMAC) {
2243 			val = statsp->xmac_stats.tx_underflow_err +
2244 				statsp->xmac_stats.tx_maxpktsize_err +
2245 				statsp->xmac_stats.tx_overflow_err +
2246 				statsp->xmac_stats.tx_fifo_xfr_err;
2247 		} else {
2248 			val = statsp->bmac_stats.tx_underrun_err +
2249 				statsp->bmac_stats.tx_max_pkt_err;
2250 		}
2251 		break;
2252 
2253 	case ETHER_STAT_CARRIER_ERRORS:
2254 		if (nxgep->mac.porttype == PORT_TYPE_XMAC) {
2255 			val = statsp->xmac_stats.rx_linkfault_err_cnt;
2256 		} else {
2257 			val = statsp->mac_stats.xcvr_inits +
2258 				statsp->mac_stats.serdes_inits;
2259 		}
2260 		break;
2261 
2262 	case ETHER_STAT_TOOLONG_ERRORS:
2263 		if (nxgep->mac.porttype == PORT_TYPE_XMAC) {
2264 			val = statsp->xmac_stats.tx_maxpktsize_err +
2265 				statsp->xmac_stats.rx_len_err_cnt;
2266 
2267 		} else {
2268 			val = statsp->bmac_stats.rx_len_err_cnt +
2269 				statsp->bmac_stats.tx_max_pkt_err;
2270 		}
2271 		break;
2272 
2273 
2274 	case ETHER_STAT_XCVR_ADDR:
2275 		val = statsp->mac_stats.xcvr_portn;
2276 		break;
2277 	case ETHER_STAT_XCVR_ID:
2278 		val = statsp->mac_stats.xcvr_id;
2279 		break;
2280 
2281 	case ETHER_STAT_XCVR_INUSE:
2282 		val = statsp->mac_stats.xcvr_inuse;
2283 		break;
2284 
2285 	case ETHER_STAT_CAP_1000FDX:
2286 		val = statsp->mac_stats.cap_1000fdx;
2287 		break;
2288 
2289 	case ETHER_STAT_CAP_1000HDX:
2290 		val = statsp->mac_stats.cap_1000hdx;
2291 		break;
2292 
2293 	case ETHER_STAT_CAP_100FDX:
2294 		val = statsp->mac_stats.cap_100fdx;
2295 		break;
2296 
2297 	case ETHER_STAT_CAP_100HDX:
2298 		val = statsp->mac_stats.cap_100hdx;
2299 		break;
2300 
2301 	case ETHER_STAT_CAP_10FDX:
2302 		val = statsp->mac_stats.cap_10fdx;
2303 		break;
2304 
2305 	case ETHER_STAT_CAP_10HDX:
2306 		val = statsp->mac_stats.cap_10hdx;
2307 		break;
2308 
2309 	case ETHER_STAT_CAP_ASMPAUSE:
2310 		val = statsp->mac_stats.cap_asmpause;
2311 		val = 1;
2312 		break;
2313 
2314 	case ETHER_STAT_CAP_PAUSE:
2315 		val = statsp->mac_stats.cap_pause;
2316 		break;
2317 
2318 	case ETHER_STAT_CAP_AUTONEG:
2319 		val = statsp->mac_stats.cap_autoneg;
2320 		break;
2321 
2322 	case ETHER_STAT_ADV_CAP_1000FDX:
2323 		val = statsp->mac_stats.adv_cap_1000fdx;
2324 		break;
2325 
2326 	case ETHER_STAT_ADV_CAP_1000HDX:
2327 		val = statsp->mac_stats.adv_cap_1000hdx;
2328 		break;
2329 
2330 	case ETHER_STAT_ADV_CAP_100FDX:
2331 		val = statsp->mac_stats.adv_cap_100fdx;
2332 		break;
2333 
2334 	case ETHER_STAT_ADV_CAP_100HDX:
2335 		val = statsp->mac_stats.adv_cap_100hdx;
2336 		break;
2337 
2338 	case ETHER_STAT_ADV_CAP_10FDX:
2339 		val = statsp->mac_stats.adv_cap_10fdx;
2340 		break;
2341 
2342 	case ETHER_STAT_ADV_CAP_10HDX:
2343 		val = statsp->mac_stats.adv_cap_10hdx;
2344 		break;
2345 
2346 	case ETHER_STAT_ADV_CAP_ASMPAUSE:
2347 		val = statsp->mac_stats.adv_cap_asmpause;
2348 		break;
2349 
2350 	case ETHER_STAT_ADV_CAP_PAUSE:
2351 		val = statsp->mac_stats.adv_cap_pause;
2352 		break;
2353 
2354 	case ETHER_STAT_ADV_CAP_AUTONEG:
2355 		val = statsp->mac_stats.adv_cap_autoneg;
2356 		break;
2357 
2358 	case ETHER_STAT_LP_CAP_1000FDX:
2359 		val = statsp->mac_stats.lp_cap_1000fdx;
2360 		break;
2361 
2362 	case ETHER_STAT_LP_CAP_1000HDX:
2363 		val = statsp->mac_stats.lp_cap_1000hdx;
2364 		break;
2365 
2366 	case ETHER_STAT_LP_CAP_100FDX:
2367 		val = statsp->mac_stats.lp_cap_100fdx;
2368 		break;
2369 
2370 	case ETHER_STAT_LP_CAP_100HDX:
2371 		val = statsp->mac_stats.lp_cap_100hdx;
2372 		break;
2373 
2374 	case ETHER_STAT_LP_CAP_10FDX:
2375 		val = statsp->mac_stats.lp_cap_10fdx;
2376 		break;
2377 
2378 	case ETHER_STAT_LP_CAP_10HDX:
2379 		val = statsp->mac_stats.lp_cap_10hdx;
2380 		break;
2381 
2382 	case ETHER_STAT_LP_CAP_ASMPAUSE:
2383 		val = statsp->mac_stats.lp_cap_asmpause;
2384 		break;
2385 
2386 	case ETHER_STAT_LP_CAP_PAUSE:
2387 		val = statsp->mac_stats.lp_cap_pause;
2388 		break;
2389 
2390 	case ETHER_STAT_LP_CAP_AUTONEG:
2391 		val = statsp->mac_stats.lp_cap_autoneg;
2392 		break;
2393 
2394 	case ETHER_STAT_LINK_ASMPAUSE:
2395 		val = statsp->mac_stats.link_asmpause;
2396 		break;
2397 
2398 	case ETHER_STAT_LINK_PAUSE:
2399 		val = statsp->mac_stats.link_pause;
2400 		break;
2401 
2402 	case ETHER_STAT_LINK_AUTONEG:
2403 		val = statsp->mac_stats.cap_autoneg;
2404 		break;
2405 
2406 	case ETHER_STAT_LINK_DUPLEX:
2407 		val = statsp->mac_stats.link_duplex;
2408 		break;
2409 
2410 	default:
2411 		/*
2412 		 * Shouldn't reach here...
2413 		 */
2414 #ifdef NXGE_DEBUG
2415 		NXGE_ERROR_MSG((nxgep, KST_CTL,
2416 			"nxge_m_stat: unrecognized parameter value = 0x%x",
2417 			stat));
2418 #endif
2419 
2420 		return (ENOTSUP);
2421 	}
2422 	*value = val;
2423 	return (0);
2424 }
2425