xref: /titanic_50/usr/src/uts/common/io/nxge/nxge_hw.c (revision d14d7d31f2a70b1e0a9c933607d6627f5718980e)
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 2007 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 
30 /*
31  * Tunable Receive Completion Ring Configuration B parameters.
32  */
33 uint16_t nxge_rx_pkt_thres;	/* 16 bits */
34 uint8_t nxge_rx_pkt_timeout;	/* 6 bits based on DMA clock divider */
35 
36 lb_property_t lb_normal = {normal, "normal", nxge_lb_normal};
37 lb_property_t lb_external10g = {external, "external10g", nxge_lb_ext10g};
38 lb_property_t lb_external1000 = {external, "external1000", nxge_lb_ext1000};
39 lb_property_t lb_external100 = {external, "external100", nxge_lb_ext100};
40 lb_property_t lb_external10 = {external, "external10", nxge_lb_ext10};
41 lb_property_t lb_phy10g = {internal, "phy10g", nxge_lb_phy10g};
42 lb_property_t lb_phy1000 = {internal, "phy1000", nxge_lb_phy1000};
43 lb_property_t lb_phy = {internal, "phy", nxge_lb_phy};
44 lb_property_t lb_serdes10g = {internal, "serdes10g", nxge_lb_serdes10g};
45 lb_property_t lb_serdes1000 = {internal, "serdes", nxge_lb_serdes1000};
46 lb_property_t lb_mac10g = {internal, "mac10g", nxge_lb_mac10g};
47 lb_property_t lb_mac1000 = {internal, "mac1000", nxge_lb_mac1000};
48 lb_property_t lb_mac = {internal, "mac10/100", nxge_lb_mac};
49 
50 uint32_t nxge_lb_dbg = 1;
51 void nxge_get_mii(p_nxge_t nxgep, p_mblk_t mp);
52 void nxge_put_mii(p_nxge_t nxgep, p_mblk_t mp);
53 static nxge_status_t nxge_check_xaui_xfp(p_nxge_t nxgep);
54 
55 extern uint32_t nxge_rx_mode;
56 extern uint32_t nxge_jumbo_mtu;
57 extern boolean_t nxge_jumbo_enable;
58 
59 static void
60 nxge_rtrace_ioctl(p_nxge_t, queue_t *, mblk_t *, struct iocblk *);
61 
62 /* ARGSUSED */
63 void
64 nxge_global_reset(p_nxge_t nxgep)
65 {
66 	NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_global_reset"));
67 
68 	(void) nxge_link_monitor(nxgep, LINK_MONITOR_STOP);
69 	(void) nxge_intr_hw_disable(nxgep);
70 
71 	if ((nxgep->suspended) ||
72 			((nxgep->statsp->port_stats.lb_mode ==
73 			nxge_lb_phy1000) ||
74 			(nxgep->statsp->port_stats.lb_mode ==
75 			nxge_lb_phy10g) ||
76 			(nxgep->statsp->port_stats.lb_mode ==
77 			nxge_lb_serdes1000) ||
78 			(nxgep->statsp->port_stats.lb_mode ==
79 			nxge_lb_serdes10g))) {
80 		(void) nxge_link_init(nxgep);
81 	}
82 	(void) nxge_link_monitor(nxgep, LINK_MONITOR_START);
83 	(void) nxge_mac_init(nxgep);
84 	(void) nxge_intr_hw_enable(nxgep);
85 
86 	NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_global_reset"));
87 }
88 
89 /* ARGSUSED */
90 void
91 nxge_hw_id_init(p_nxge_t nxgep)
92 {
93 	NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_hw_id_init"));
94 	/*
95 	 * Set up initial hardware parameters required such as mac mtu size.
96 	 */
97 	nxgep->mac.is_jumbo = B_FALSE;
98 	nxgep->mac.maxframesize = NXGE_MTU_DEFAULT_MAX;	/* 1522 */
99 	if (nxgep->param_arr[param_accept_jumbo].value || nxge_jumbo_enable) {
100 		nxgep->mac.maxframesize = (uint16_t)nxge_jumbo_mtu;
101 		nxgep->mac.is_jumbo = B_TRUE;
102 	}
103 	NXGE_DEBUG_MSG((nxgep, DDI_CTL,
104 		"==> nxge_hw_id_init: maxframesize %d",
105 		nxgep->mac.maxframesize));
106 
107 	NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_hw_id_init"));
108 }
109 
110 /* ARGSUSED */
111 void
112 nxge_hw_init_niu_common(p_nxge_t nxgep)
113 {
114 	p_nxge_hw_list_t hw_p;
115 
116 	NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_hw_init_niu_common"));
117 
118 	if ((hw_p = nxgep->nxge_hw_p) == NULL) {
119 		return;
120 	}
121 	MUTEX_ENTER(&hw_p->nxge_cfg_lock);
122 	if (hw_p->flags & COMMON_INIT_DONE) {
123 		NXGE_DEBUG_MSG((nxgep, MOD_CTL,
124 			"nxge_hw_init_niu_common"
125 			" already done for dip $%p function %d exiting",
126 			hw_p->parent_devp, nxgep->function_num));
127 		MUTEX_EXIT(&hw_p->nxge_cfg_lock);
128 		return;
129 	}
130 
131 	hw_p->flags = COMMON_INIT_START;
132 	NXGE_DEBUG_MSG((nxgep, MOD_CTL, "nxge_hw_init_niu_common"
133 		" Started for device id %x with function %d",
134 		hw_p->parent_devp, nxgep->function_num));
135 
136 	/* per neptune common block init */
137 	(void) nxge_fflp_hw_reset(nxgep);
138 
139 	hw_p->flags = COMMON_INIT_DONE;
140 	MUTEX_EXIT(&hw_p->nxge_cfg_lock);
141 
142 	NXGE_DEBUG_MSG((nxgep, MOD_CTL, "nxge_hw_init_niu_common"
143 		" Done for device id %x with function %d",
144 		hw_p->parent_devp, nxgep->function_num));
145 	NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_hw_init_niu_common"));
146 }
147 
148 /* ARGSUSED */
149 uint_t
150 nxge_intr(void *arg1, void *arg2)
151 {
152 	p_nxge_ldv_t ldvp = (p_nxge_ldv_t)arg1;
153 	p_nxge_t nxgep = (p_nxge_t)arg2;
154 	uint_t serviced = DDI_INTR_UNCLAIMED;
155 	uint8_t ldv;
156 	npi_handle_t handle;
157 	p_nxge_ldgv_t ldgvp;
158 	p_nxge_ldg_t ldgp, t_ldgp;
159 	p_nxge_ldv_t t_ldvp;
160 	uint64_t vector0 = 0, vector1 = 0, vector2 = 0;
161 	int i, j, nldvs, nintrs = 1;
162 	npi_status_t rs = NPI_SUCCESS;
163 
164 	/* DDI interface returns second arg as NULL (n2 niumx driver) !!! */
165 	if (arg2 == NULL || (void *) ldvp->nxgep != arg2) {
166 		nxgep = ldvp->nxgep;
167 	}
168 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_intr"));
169 
170 	if (!(nxgep->drv_state & STATE_HW_INITIALIZED)) {
171 		NXGE_ERROR_MSG((nxgep, INT_CTL,
172 			"<== nxge_intr: not initialized 0x%x", serviced));
173 		return (serviced);
174 	}
175 
176 	ldgvp = nxgep->ldgvp;
177 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_intr: ldgvp $%p", ldgvp));
178 	if (ldvp == NULL && ldgvp) {
179 		t_ldvp = ldvp = ldgvp->ldvp;
180 	}
181 	if (ldvp) {
182 		ldgp = t_ldgp = ldvp->ldgp;
183 	}
184 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_intr: "
185 		"ldgvp $%p ldvp $%p ldgp $%p", ldgvp, ldvp, ldgp));
186 	if (ldgvp == NULL || ldvp == NULL || ldgp == NULL) {
187 		NXGE_ERROR_MSG((nxgep, INT_CTL, "==> nxge_intr: "
188 			"ldgvp $%p ldvp $%p ldgp $%p", ldgvp, ldvp, ldgp));
189 		NXGE_ERROR_MSG((nxgep, INT_CTL, "<== nxge_intr: not ready"));
190 		return (DDI_INTR_UNCLAIMED);
191 	}
192 	/*
193 	 * This interrupt handler will have to go through all the logical
194 	 * devices to find out which logical device interrupts us and then call
195 	 * its handler to process the events.
196 	 */
197 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
198 	t_ldgp = ldgp;
199 	t_ldvp = ldgp->ldvp;
200 
201 	nldvs = ldgp->nldvs;
202 
203 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_intr: #ldvs %d #intrs %d",
204 			nldvs, ldgvp->ldg_intrs));
205 
206 	serviced = DDI_INTR_CLAIMED;
207 	for (i = 0; i < nintrs; i++, t_ldgp++) {
208 		NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_intr(%d): #ldvs %d "
209 				" #intrs %d", i, nldvs, nintrs));
210 		/* Get this group's flag bits.  */
211 		t_ldgp->interrupted = B_FALSE;
212 		rs = npi_ldsv_ldfs_get(handle, t_ldgp->ldg,
213 			&vector0, &vector1, &vector2);
214 		if (rs) {
215 			continue;
216 		}
217 		if (!vector0 && !vector1 && !vector2) {
218 			NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_intr: "
219 				"no interrupts on group %d", t_ldgp->ldg));
220 			continue;
221 		}
222 		NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_intr: "
223 			"vector0 0x%llx vector1 0x%llx vector2 0x%llx",
224 			vector0, vector1, vector2));
225 		t_ldgp->interrupted = B_TRUE;
226 		nldvs = t_ldgp->nldvs;
227 		for (j = 0; j < nldvs; j++, t_ldvp++) {
228 			/*
229 			 * Call device's handler if flag bits are on.
230 			 */
231 			ldv = t_ldvp->ldv;
232 			if (((ldv < NXGE_MAC_LD_START) &&
233 					(LDV_ON(ldv, vector0) |
234 					(LDV_ON(ldv, vector1)))) ||
235 					(ldv >= NXGE_MAC_LD_START &&
236 					((LDV2_ON_1(ldv, vector2)) ||
237 					(LDV2_ON_2(ldv, vector2))))) {
238 				(void) (t_ldvp->ldv_intr_handler)(
239 					(caddr_t)t_ldvp, arg2);
240 				NXGE_DEBUG_MSG((nxgep, INT_CTL,
241 					"==> nxge_intr: "
242 					"calling device %d #ldvs %d #intrs %d",
243 					j, nldvs, nintrs));
244 			}
245 		}
246 	}
247 
248 	t_ldgp = ldgp;
249 	for (i = 0; i < nintrs; i++, t_ldgp++) {
250 		/* rearm group interrupts */
251 		if (t_ldgp->interrupted) {
252 			NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_intr: arm "
253 				"group %d", t_ldgp->ldg));
254 			(void) npi_intr_ldg_mgmt_set(handle, t_ldgp->ldg,
255 				t_ldgp->arm, t_ldgp->ldg_timer);
256 		}
257 	}
258 
259 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_intr: serviced 0x%x",
260 		serviced));
261 	return (serviced);
262 }
263 
264 /* ARGSUSED */
265 static nxge_status_t
266 nxge_check_xaui_xfp(p_nxge_t nxgep)
267 {
268 	nxge_status_t	status = NXGE_OK;
269 	uint8_t		phy_port_addr;
270 	uint16_t	val;
271 	uint16_t	val1;
272 	uint8_t		portn;
273 
274 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_check_xaui_xfp"));
275 
276 	portn = nxgep->mac.portnum;
277 	phy_port_addr = nxgep->statsp->mac_stats.xcvr_portn;
278 
279 	if ((status = nxge_mdio_read(nxgep, phy_port_addr,
280 	    BCM8704_USER_DEV3_ADDR,
281 	    BCM8704_USER_ANALOG_STATUS0_REG, &val)) == NXGE_OK) {
282 		status = nxge_mdio_read(nxgep, phy_port_addr,
283 		    BCM8704_USER_DEV3_ADDR,
284 		    BCM8704_USER_TX_ALARM_STATUS_REG, &val1);
285 	}
286 	if (status != NXGE_OK) {
287 		NXGE_FM_REPORT_ERROR(nxgep, portn, NULL,
288 		    NXGE_FM_EREPORT_XAUI_ERR);
289 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
290 		    "XAUI is bad or absent on port<%d>\n", portn));
291 	} else if (nxgep->mac.portmode == PORT_10G_FIBER) {
292 		/*
293 		 * 0x03FC = 0000 0011 1111 1100
294 		 * 0x639C = 0110 0011 1001 1100
295 		 * bit14 = 1: PDM loss-of-light indicator
296 		 * bit13 = 1: PDM Rx loss-of-signal
297 		 * bit6  = 0: Light is NOT ok
298 		 * bit5  = 0: PMD Rx signal is NOT ok
299 		 */
300 		if (val != 0x3FC && val == 0x639C) {
301 			NXGE_FM_REPORT_ERROR(nxgep, portn, NULL,
302 			    NXGE_FM_EREPORT_XFP_ERR);
303 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
304 			    "XFP is bad or absent on port<%d>\n", portn));
305 			status = NXGE_ERROR;
306 		}
307 	}
308 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_check_xaui_xfp"));
309 	return (status);
310 }
311 
312 
313 /* ARGSUSED */
314 uint_t
315 nxge_syserr_intr(void *arg1, void *arg2)
316 {
317 	p_nxge_ldv_t ldvp = (p_nxge_ldv_t)arg1;
318 	p_nxge_t nxgep = (p_nxge_t)arg2;
319 	p_nxge_ldg_t ldgp = NULL;
320 	npi_handle_t handle;
321 	sys_err_stat_t estat;
322 	uint_t serviced = DDI_INTR_UNCLAIMED;
323 
324 	if (arg1 == NULL && arg2 == NULL) {
325 		return (serviced);
326 	}
327 	if (arg2 == NULL || ((ldvp != NULL && (void *) ldvp->nxgep != arg2))) {
328 		if (ldvp != NULL) {
329 			nxgep = ldvp->nxgep;
330 		}
331 	}
332 	NXGE_DEBUG_MSG((nxgep, SYSERR_CTL,
333 		"==> nxge_syserr_intr: arg2 $%p arg1 $%p", nxgep, ldvp));
334 	if (ldvp != NULL && ldvp->use_timer == B_FALSE) {
335 		ldgp = ldvp->ldgp;
336 		if (ldgp == NULL) {
337 			NXGE_ERROR_MSG((nxgep, SYSERR_CTL,
338 				"<== nxge_syserrintr(no logical group): "
339 				"arg2 $%p arg1 $%p", nxgep, ldvp));
340 			return (DDI_INTR_UNCLAIMED);
341 		}
342 		/*
343 		 * Get the logical device state if the function uses interrupt.
344 		 */
345 	}
346 
347 	/* This interrupt handler is for system error interrupts.  */
348 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
349 	estat.value = 0;
350 	(void) npi_fzc_sys_err_stat_get(handle, &estat);
351 	NXGE_DEBUG_MSG((nxgep, SYSERR_CTL,
352 		"==> nxge_syserr_intr: device error 0x%016llx", estat.value));
353 
354 	if (estat.bits.ldw.smx) {
355 		/* SMX */
356 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
357 			"==> nxge_syserr_intr: device error - SMX"));
358 	} else if (estat.bits.ldw.mac) {
359 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
360 			"==> nxge_syserr_intr: device error - MAC"));
361 		/*
362 		 * There is nothing to be done here. All MAC errors go to per
363 		 * MAC port interrupt. MIF interrupt is the only MAC sub-block
364 		 * that can generate status here. MIF status reported will be
365 		 * ignored here. It is checked by per port timer instead.
366 		 */
367 	} else if (estat.bits.ldw.ipp) {
368 		NXGE_DEBUG_MSG((nxgep, NXGE_ERR_CTL,
369 			"==> nxge_syserr_intr: device error - IPP"));
370 		(void) nxge_ipp_handle_sys_errors(nxgep);
371 	} else if (estat.bits.ldw.zcp) {
372 		/* ZCP */
373 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
374 			"==> nxge_syserr_intr: device error - ZCP"));
375 		(void) nxge_zcp_handle_sys_errors(nxgep);
376 	} else if (estat.bits.ldw.tdmc) {
377 		/* TDMC */
378 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
379 			"==> nxge_syserr_intr: device error - TDMC"));
380 		/*
381 		 * There is no TDMC system errors defined in the PRM. All TDMC
382 		 * channel specific errors are reported on a per channel basis.
383 		 */
384 	} else if (estat.bits.ldw.rdmc) {
385 		/* RDMC */
386 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
387 			"==> nxge_syserr_intr: device error - RDMC"));
388 		(void) nxge_rxdma_handle_sys_errors(nxgep);
389 	} else if (estat.bits.ldw.txc) {
390 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
391 			"==> nxge_syserr_intr: device error - TXC"));
392 		(void) nxge_txc_handle_sys_errors(nxgep);
393 	} else if ((nxgep->niu_type != N2_NIU) && estat.bits.ldw.peu) {
394 		/* PCI-E */
395 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
396 			"==> nxge_syserr_intr: device error - PCI-E"));
397 	} else if (estat.bits.ldw.meta1) {
398 		/* META1 */
399 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
400 			"==> nxge_syserr_intr: device error - META1"));
401 	} else if (estat.bits.ldw.meta2) {
402 		/* META2 */
403 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
404 			"==> nxge_syserr_intr: device error - META2"));
405 	} else if (estat.bits.ldw.fflp) {
406 		/* FFLP */
407 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
408 			"==> nxge_syserr_intr: device error - FFLP"));
409 		(void) nxge_fflp_handle_sys_errors(nxgep);
410 	}
411 
412 	if (nxgep->mac.portmode == PORT_10G_FIBER ||
413 	    nxgep->mac.portmode == PORT_10G_COPPER) {
414 		if (nxge_check_xaui_xfp(nxgep) != NXGE_OK) {
415 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
416 			    "==> nxge_syserr_intr: device error - XAUI"));
417 		}
418 	}
419 
420 	serviced = DDI_INTR_CLAIMED;
421 
422 	if (ldgp != NULL && ldvp != NULL && ldgp->nldvs == 1 &&
423 		!ldvp->use_timer) {
424 		(void) npi_intr_ldg_mgmt_set(handle, ldgp->ldg,
425 			B_TRUE, ldgp->ldg_timer);
426 	}
427 	NXGE_DEBUG_MSG((nxgep, SYSERR_CTL, "<== nxge_syserr_intr"));
428 	return (serviced);
429 }
430 
431 /* ARGSUSED */
432 void
433 nxge_intr_hw_enable(p_nxge_t nxgep)
434 {
435 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_intr_hw_enable"));
436 	(void) nxge_intr_mask_mgmt_set(nxgep, B_TRUE);
437 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_intr_hw_enable"));
438 }
439 
440 /* ARGSUSED */
441 void
442 nxge_intr_hw_disable(p_nxge_t nxgep)
443 {
444 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_intr_hw_disable"));
445 	(void) nxge_intr_mask_mgmt_set(nxgep, B_FALSE);
446 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_intr_hw_disable"));
447 }
448 
449 /* ARGSUSED */
450 void
451 nxge_rx_hw_blank(void *arg, time_t ticks, uint_t count)
452 {
453 	p_nxge_t nxgep = (p_nxge_t)arg;
454 	uint8_t channel;
455 	npi_handle_t handle;
456 	p_nxge_ldgv_t ldgvp;
457 	p_nxge_ldv_t ldvp;
458 	int i;
459 
460 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_rx_hw_blank"));
461 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
462 
463 	if ((ldgvp = nxgep->ldgvp) == NULL) {
464 		NXGE_ERROR_MSG((nxgep, INT_CTL,
465 			"<== nxge_rx_hw_blank (not enabled)"));
466 		return;
467 	}
468 	ldvp = nxgep->ldgvp->ldvp;
469 	if (ldvp == NULL) {
470 		return;
471 	}
472 	for (i = 0; i < ldgvp->nldvs; i++, ldvp++) {
473 		if (ldvp->is_rxdma) {
474 			channel = ldvp->channel;
475 			(void) npi_rxdma_cfg_rdc_rcr_threshold(handle,
476 				channel, count);
477 			(void) npi_rxdma_cfg_rdc_rcr_timeout(handle,
478 				channel, ticks);
479 		}
480 	}
481 
482 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_rx_hw_blank"));
483 }
484 
485 /* ARGSUSED */
486 void
487 nxge_hw_stop(p_nxge_t nxgep)
488 {
489 	NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_hw_stop"));
490 
491 	(void) nxge_tx_mac_disable(nxgep);
492 	(void) nxge_rx_mac_disable(nxgep);
493 	(void) nxge_txdma_hw_mode(nxgep, NXGE_DMA_STOP);
494 	(void) nxge_rxdma_hw_mode(nxgep, NXGE_DMA_STOP);
495 
496 	NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_hw_stop"));
497 }
498 
499 /* ARGSUSED */
500 void
501 nxge_hw_ioctl(p_nxge_t nxgep, queue_t *wq, mblk_t *mp, struct iocblk *iocp)
502 {
503 	int cmd;
504 
505 	NXGE_DEBUG_MSG((nxgep, IOC_CTL, "==> nxge_hw_ioctl"));
506 
507 	if (nxgep == NULL) {
508 		miocnak(wq, mp, 0, EINVAL);
509 		return;
510 	}
511 	iocp->ioc_error = 0;
512 	cmd = iocp->ioc_cmd;
513 
514 	switch (cmd) {
515 	default:
516 		miocnak(wq, mp, 0, EINVAL);
517 		return;
518 
519 	case NXGE_GET_MII:
520 		nxge_get_mii(nxgep, mp->b_cont);
521 		miocack(wq, mp, sizeof (uint16_t), 0);
522 		break;
523 
524 	case NXGE_PUT_MII:
525 		nxge_put_mii(nxgep, mp->b_cont);
526 		miocack(wq, mp, 0, 0);
527 		break;
528 
529 	case NXGE_GET64:
530 		nxge_get64(nxgep, mp->b_cont);
531 		miocack(wq, mp, sizeof (uint32_t), 0);
532 		break;
533 
534 	case NXGE_PUT64:
535 		nxge_put64(nxgep, mp->b_cont);
536 		miocack(wq, mp, 0, 0);
537 		break;
538 
539 	case NXGE_PUT_TCAM:
540 		nxge_put_tcam(nxgep, mp->b_cont);
541 		miocack(wq, mp, 0, 0);
542 		break;
543 
544 	case NXGE_GET_TCAM:
545 		nxge_get_tcam(nxgep, mp->b_cont);
546 		miocack(wq, mp, 0, 0);
547 		break;
548 
549 	case NXGE_TX_REGS_DUMP:
550 		nxge_txdma_regs_dump_channels(nxgep);
551 		miocack(wq, mp, 0, 0);
552 		break;
553 	case NXGE_RX_REGS_DUMP:
554 		nxge_rxdma_regs_dump_channels(nxgep);
555 		miocack(wq, mp, 0, 0);
556 		break;
557 	case NXGE_VIR_INT_REGS_DUMP:
558 	case NXGE_INT_REGS_DUMP:
559 		nxge_virint_regs_dump(nxgep);
560 		miocack(wq, mp, 0, 0);
561 		break;
562 	case NXGE_RTRACE:
563 		nxge_rtrace_ioctl(nxgep, wq, mp, iocp);
564 		break;
565 	}
566 }
567 
568 /* ARGSUSED */
569 void
570 nxge_loopback_ioctl(p_nxge_t nxgep, queue_t *wq, mblk_t *mp,
571 	struct iocblk *iocp)
572 {
573 	p_lb_property_t lb_props;
574 
575 	size_t size;
576 	int i;
577 
578 	if (mp->b_cont == NULL) {
579 		miocnak(wq, mp, 0, EINVAL);
580 	}
581 	switch (iocp->ioc_cmd) {
582 	case LB_GET_MODE:
583 		NXGE_DEBUG_MSG((nxgep, IOC_CTL, "NXGE_GET_LB_MODE command"));
584 		if (nxgep != NULL) {
585 			*(lb_info_sz_t *)mp->b_cont->b_rptr =
586 				nxgep->statsp->port_stats.lb_mode;
587 			miocack(wq, mp, sizeof (nxge_lb_t), 0);
588 		} else {
589 			miocnak(wq, mp, 0, EINVAL);
590 		}
591 		break;
592 	case LB_SET_MODE:
593 		NXGE_DEBUG_MSG((nxgep, IOC_CTL, "NXGE_SET_LB_MODE command"));
594 		if (iocp->ioc_count != sizeof (uint32_t)) {
595 			miocack(wq, mp, 0, 0);
596 			break;
597 		}
598 		if ((nxgep != NULL) && nxge_set_lb(nxgep, wq, mp->b_cont)) {
599 			miocack(wq, mp, 0, 0);
600 		} else {
601 			miocnak(wq, mp, 0, EPROTO);
602 		}
603 		break;
604 	case LB_GET_INFO_SIZE:
605 		NXGE_DEBUG_MSG((nxgep, IOC_CTL, "LB_GET_INFO_SIZE command"));
606 		if (nxgep != NULL) {
607 			size = sizeof (lb_normal);
608 			if (nxgep->statsp->mac_stats.cap_10gfdx) {
609 				size += sizeof (lb_external10g);
610 				size += sizeof (lb_phy10g);
611 				size += sizeof (lb_serdes10g);
612 				size += sizeof (lb_mac10g);
613 			}
614 			if (nxgep->statsp->mac_stats.cap_1000fdx) {
615 				size += sizeof (lb_external1000);
616 				size += sizeof (lb_mac1000);
617 				if ((nxgep->mac.portmode == PORT_1G_COPPER) ||
618 				    (nxgep->mac.portmode ==
619 				    PORT_1G_RGMII_FIBER))
620 					size += sizeof (lb_phy1000);
621 			}
622 			if (nxgep->statsp->mac_stats.cap_100fdx)
623 				size += sizeof (lb_external100);
624 			if (nxgep->statsp->mac_stats.cap_10fdx)
625 				size += sizeof (lb_external10);
626 			else if ((nxgep->mac.portmode == PORT_1G_FIBER) ||
627 			    (nxgep->mac.portmode == PORT_1G_SERDES))
628 				size += sizeof (lb_serdes1000);
629 
630 			*(lb_info_sz_t *)mp->b_cont->b_rptr = size;
631 
632 			NXGE_DEBUG_MSG((nxgep, IOC_CTL,
633 				"NXGE_GET_LB_INFO command: size %d", size));
634 			miocack(wq, mp, sizeof (lb_info_sz_t), 0);
635 		} else
636 			miocnak(wq, mp, 0, EINVAL);
637 		break;
638 
639 	case LB_GET_INFO:
640 		NXGE_DEBUG_MSG((nxgep, IOC_CTL, "NXGE_GET_LB_INFO command"));
641 		if (nxgep != NULL) {
642 			size = sizeof (lb_normal);
643 			if (nxgep->statsp->mac_stats.cap_10gfdx) {
644 				size += sizeof (lb_external10g);
645 				size += sizeof (lb_phy10g);
646 				size += sizeof (lb_serdes10g);
647 				size += sizeof (lb_mac10g);
648 			}
649 			if (nxgep->statsp->mac_stats.cap_1000fdx) {
650 				size += sizeof (lb_external1000);
651 				size += sizeof (lb_mac1000);
652 				if ((nxgep->mac.portmode == PORT_1G_COPPER) ||
653 				    (nxgep->mac.portmode ==
654 				    PORT_1G_RGMII_FIBER))
655 					size += sizeof (lb_phy1000);
656 			}
657 			if (nxgep->statsp->mac_stats.cap_100fdx)
658 				size += sizeof (lb_external100);
659 			if (nxgep->statsp->mac_stats.cap_10fdx)
660 				size += sizeof (lb_external10);
661 			else if ((nxgep->mac.portmode == PORT_1G_FIBER) ||
662 			    (nxgep->mac.portmode == PORT_1G_SERDES))
663 				size += sizeof (lb_serdes1000);
664 
665 			NXGE_DEBUG_MSG((nxgep, IOC_CTL,
666 				"NXGE_GET_LB_INFO command: size %d", size));
667 			if (size == iocp->ioc_count) {
668 				i = 0;
669 				lb_props = (p_lb_property_t)mp->b_cont->b_rptr;
670 				lb_props[i++] = lb_normal;
671 				if (nxgep->statsp->mac_stats.cap_10gfdx) {
672 					lb_props[i++] = lb_mac10g;
673 					lb_props[i++] = lb_serdes10g;
674 					lb_props[i++] = lb_phy10g;
675 					lb_props[i++] = lb_external10g;
676 				}
677 				if (nxgep->statsp->mac_stats.cap_1000fdx)
678 					lb_props[i++] = lb_external1000;
679 				if (nxgep->statsp->mac_stats.cap_100fdx)
680 					lb_props[i++] = lb_external100;
681 				if (nxgep->statsp->mac_stats.cap_10fdx)
682 					lb_props[i++] = lb_external10;
683 				if (nxgep->statsp->mac_stats.cap_1000fdx)
684 					lb_props[i++] = lb_mac1000;
685 				if ((nxgep->mac.portmode == PORT_1G_COPPER) ||
686 				    (nxgep->mac.portmode ==
687 				    PORT_1G_RGMII_FIBER)) {
688 					if (nxgep->statsp->mac_stats.
689 						cap_1000fdx)
690 						lb_props[i++] = lb_phy1000;
691 				} else if ((nxgep->mac.portmode ==
692 				    PORT_1G_FIBER) ||
693 				    (nxgep->mac.portmode == PORT_1G_SERDES)) {
694 					lb_props[i++] = lb_serdes1000;
695 				}
696 				miocack(wq, mp, size, 0);
697 			} else
698 				miocnak(wq, mp, 0, EINVAL);
699 		} else {
700 			miocnak(wq, mp, 0, EINVAL);
701 			cmn_err(CE_NOTE, "!nxge_hw_ioctl: invalid command 0x%x",
702 				iocp->ioc_cmd);
703 		}
704 		break;
705 	}
706 }
707 
708 /*
709  * DMA channel interfaces to access various channel specific
710  * hardware functions.
711  */
712 /* ARGSUSED */
713 void
714 nxge_rxdma_channel_put64(nxge_os_acc_handle_t handle, void *reg_addrp,
715 	uint32_t reg_base, uint16_t channel, uint64_t reg_data)
716 {
717 	uint64_t reg_offset;
718 
719 	NXGE_DEBUG_MSG((NULL, DMA_CTL, "<== nxge_rxdma_channel_put64"));
720 
721 	/*
722 	 * Channel is assumed to be from 0 to the maximum DMA channel #. If we
723 	 * use the virtual DMA CSR address space from the config space (in PCI
724 	 * case), then the following code need to be use different offset
725 	 * computation macro.
726 	 */
727 	reg_offset = reg_base + DMC_OFFSET(channel);
728 	NXGE_PIO_WRITE64(handle, reg_addrp, reg_offset, reg_data);
729 
730 	NXGE_DEBUG_MSG((NULL, DMA_CTL, "<== nxge_rxdma_channel_put64"));
731 }
732 
733 /* ARGSUSED */
734 uint64_t
735 nxge_rxdma_channel_get64(nxge_os_acc_handle_t handle, void *reg_addrp,
736 	uint32_t reg_base, uint16_t channel)
737 {
738 	uint64_t reg_offset;
739 
740 	NXGE_DEBUG_MSG((NULL, DMA_CTL, "<== nxge_rxdma_channel_get64"));
741 
742 	/*
743 	 * Channel is assumed to be from 0 to the maximum DMA channel #. If we
744 	 * use the virtual DMA CSR address space from the config space (in PCI
745 	 * case), then the following code need to be use different offset
746 	 * computation macro.
747 	 */
748 	reg_offset = reg_base + DMC_OFFSET(channel);
749 
750 	NXGE_DEBUG_MSG((NULL, DMA_CTL, "<== nxge_rxdma_channel_get64"));
751 
752 	return (NXGE_PIO_READ64(handle, reg_addrp, reg_offset));
753 }
754 
755 /* ARGSUSED */
756 void
757 nxge_get32(p_nxge_t nxgep, p_mblk_t mp)
758 {
759 	nxge_os_acc_handle_t nxge_regh;
760 
761 	NXGE_DEBUG_MSG((nxgep, IOC_CTL, "nxge_get32"));
762 	nxge_regh = nxgep->dev_regs->nxge_regh;
763 
764 	*(uint32_t *)mp->b_rptr = NXGE_PIO_READ32(nxge_regh,
765 		nxgep->dev_regs->nxge_regp, *(uint32_t *)mp->b_rptr);
766 
767 	NXGE_DEBUG_MSG((nxgep, IOC_CTL, "value = 0x%08X",
768 		*(uint32_t *)mp->b_rptr));
769 	NXGE_DEBUG_MSG((nxgep, IOC_CTL, "nxge_get32"));
770 }
771 
772 /* ARGSUSED */
773 void
774 nxge_put32(p_nxge_t nxgep, p_mblk_t mp)
775 {
776 	nxge_os_acc_handle_t nxge_regh;
777 	uint32_t *buf;
778 	uint8_t *reg;
779 
780 	NXGE_DEBUG_MSG((nxgep, IOC_CTL, "nxge_put32"));
781 	nxge_regh = nxgep->dev_regs->nxge_regh;
782 
783 	buf = (uint32_t *)mp->b_rptr;
784 	reg = (uint8_t *)(nxgep->dev_regs->nxge_regp) + buf[0];
785 	NXGE_DEBUG_MSG((nxgep, IOC_CTL,
786 		"reg = 0x%016llX index = 0x%08X value = 0x%08X",
787 		reg, buf[0], buf[1]));
788 	NXGE_PIO_WRITE32(nxge_regh, (uint32_t *)reg, 0, buf[1]);
789 	NXGE_DEBUG_MSG((nxgep, IOC_CTL, "nxge_put32"));
790 }
791 
792 /*ARGSUSED*/
793 boolean_t
794 nxge_set_lb(p_nxge_t nxgep, queue_t *wq, p_mblk_t mp)
795 {
796 	boolean_t status = B_TRUE;
797 	uint32_t lb_mode;
798 	lb_property_t *lb_info;
799 
800 	NXGE_DEBUG_MSG((nxgep, IOC_CTL, "<== nxge_set_lb"));
801 	lb_mode = nxgep->statsp->port_stats.lb_mode;
802 	if (lb_mode == *(uint32_t *)mp->b_rptr) {
803 		cmn_err(CE_NOTE,
804 			"!nxge%d: Loopback mode already set (lb_mode %d).\n",
805 			nxgep->instance, lb_mode);
806 		status = B_FALSE;
807 		goto nxge_set_lb_exit;
808 	}
809 	lb_mode = *(uint32_t *)mp->b_rptr;
810 	lb_info = NULL;
811 	if (lb_mode == lb_normal.value)
812 		lb_info = &lb_normal;
813 	else if ((lb_mode == lb_external10g.value) &&
814 		(nxgep->statsp->mac_stats.cap_10gfdx))
815 		lb_info = &lb_external10g;
816 	else if ((lb_mode == lb_external1000.value) &&
817 		(nxgep->statsp->mac_stats.cap_1000fdx))
818 		lb_info = &lb_external1000;
819 	else if ((lb_mode == lb_external100.value) &&
820 		(nxgep->statsp->mac_stats.cap_100fdx))
821 		lb_info = &lb_external100;
822 	else if ((lb_mode == lb_external10.value) &&
823 		(nxgep->statsp->mac_stats.cap_10fdx))
824 		lb_info = &lb_external10;
825 	else if ((lb_mode == lb_phy10g.value) &&
826 			((nxgep->mac.portmode == PORT_10G_COPPER) ||
827 			(nxgep->mac.portmode == PORT_10G_FIBER)))
828 		lb_info = &lb_phy10g;
829 	else if ((lb_mode == lb_phy1000.value) &&
830 	    ((nxgep->mac.portmode == PORT_1G_COPPER) ||
831 	    (nxgep->mac.portmode == PORT_1G_RGMII_FIBER)))
832 		lb_info = &lb_phy1000;
833 	else if ((lb_mode == lb_phy.value) &&
834 		(nxgep->mac.portmode == PORT_1G_COPPER))
835 		lb_info = &lb_phy;
836 	else if ((lb_mode == lb_serdes10g.value) &&
837 	    ((nxgep->mac.portmode == PORT_10G_FIBER) ||
838 	    (nxgep->mac.portmode == PORT_10G_COPPER) ||
839 	    (nxgep->mac.portmode == PORT_10G_SERDES)))
840 		lb_info = &lb_serdes10g;
841 	else if ((lb_mode == lb_serdes1000.value) &&
842 	    (nxgep->mac.portmode == PORT_1G_FIBER ||
843 	    (nxgep->mac.portmode == PORT_1G_SERDES)))
844 		lb_info = &lb_serdes1000;
845 	else if (lb_mode == lb_mac10g.value)
846 		lb_info = &lb_mac10g;
847 	else if (lb_mode == lb_mac1000.value)
848 		lb_info = &lb_mac1000;
849 	else if (lb_mode == lb_mac.value)
850 		lb_info = &lb_mac;
851 	else {
852 		cmn_err(CE_NOTE,
853 			"!nxge%d: Loopback mode not supported(mode %d).\n",
854 			nxgep->instance, lb_mode);
855 		status = B_FALSE;
856 		goto nxge_set_lb_exit;
857 	}
858 
859 	if (lb_mode == nxge_lb_normal) {
860 		if (nxge_lb_dbg) {
861 			cmn_err(CE_NOTE,
862 				"!nxge%d: Returning to normal operation",
863 				nxgep->instance);
864 		}
865 		nxge_set_lb_normal(nxgep);
866 		goto nxge_set_lb_exit;
867 	}
868 	nxgep->statsp->port_stats.lb_mode = lb_mode;
869 
870 	if (nxge_lb_dbg)
871 		cmn_err(CE_NOTE,
872 			"!nxge%d: Adapter now in %s loopback mode",
873 			nxgep->instance, lb_info->key);
874 	nxgep->param_arr[param_autoneg].value = 0;
875 	nxgep->param_arr[param_anar_10gfdx].value =
876 		(nxgep->statsp->port_stats.lb_mode == nxge_lb_ext10g) ||
877 		(nxgep->statsp->port_stats.lb_mode == nxge_lb_mac10g) ||
878 		(nxgep->statsp->port_stats.lb_mode == nxge_lb_phy10g) ||
879 		(nxgep->statsp->port_stats.lb_mode == nxge_lb_serdes10g);
880 	nxgep->param_arr[param_anar_10ghdx].value = 0;
881 	nxgep->param_arr[param_anar_1000fdx].value =
882 		(nxgep->statsp->port_stats.lb_mode == nxge_lb_ext1000) ||
883 		(nxgep->statsp->port_stats.lb_mode == nxge_lb_mac1000) ||
884 		(nxgep->statsp->port_stats.lb_mode == nxge_lb_phy1000) ||
885 		(nxgep->statsp->port_stats.lb_mode == nxge_lb_serdes1000);
886 	nxgep->param_arr[param_anar_1000hdx].value = 0;
887 	nxgep->param_arr[param_anar_100fdx].value =
888 		(nxgep->statsp->port_stats.lb_mode == nxge_lb_phy) ||
889 		(nxgep->statsp->port_stats.lb_mode == nxge_lb_mac) ||
890 		(nxgep->statsp->port_stats.lb_mode == nxge_lb_ext100);
891 	nxgep->param_arr[param_anar_100hdx].value = 0;
892 	nxgep->param_arr[param_anar_10fdx].value =
893 		(nxgep->statsp->port_stats.lb_mode == nxge_lb_mac) ||
894 		(nxgep->statsp->port_stats.lb_mode == nxge_lb_ext10);
895 	if (nxgep->statsp->port_stats.lb_mode == nxge_lb_ext1000) {
896 		nxgep->param_arr[param_master_cfg_enable].value = 1;
897 		nxgep->param_arr[param_master_cfg_value].value = 1;
898 	}
899 	if ((nxgep->statsp->port_stats.lb_mode == nxge_lb_ext10g) ||
900 		(nxgep->statsp->port_stats.lb_mode == nxge_lb_ext1000) ||
901 		(nxgep->statsp->port_stats.lb_mode == nxge_lb_ext100) ||
902 		(nxgep->statsp->port_stats.lb_mode == nxge_lb_ext10) ||
903 		(nxgep->statsp->port_stats.lb_mode == nxge_lb_phy10g) ||
904 		(nxgep->statsp->port_stats.lb_mode == nxge_lb_phy1000) ||
905 		(nxgep->statsp->port_stats.lb_mode == nxge_lb_phy)) {
906 
907 		(void) nxge_link_monitor(nxgep, LINK_MONITOR_STOP);
908 		(void) nxge_xcvr_find(nxgep);
909 		(void) nxge_link_init(nxgep);
910 		(void) nxge_link_monitor(nxgep, LINK_MONITOR_START);
911 	}
912 	if (lb_info->lb_type == internal) {
913 		if ((nxgep->statsp->port_stats.lb_mode == nxge_lb_mac10g) ||
914 				(nxgep->statsp->port_stats.lb_mode ==
915 				nxge_lb_phy10g) ||
916 				(nxgep->statsp->port_stats.lb_mode ==
917 				nxge_lb_serdes10g)) {
918 			nxgep->statsp->mac_stats.link_speed = 10000;
919 		} else if ((nxgep->statsp->port_stats.lb_mode
920 				== nxge_lb_mac1000) ||
921 				(nxgep->statsp->port_stats.lb_mode ==
922 				nxge_lb_phy1000) ||
923 				(nxgep->statsp->port_stats.lb_mode ==
924 				nxge_lb_serdes1000)) {
925 			nxgep->statsp->mac_stats.link_speed = 1000;
926 		} else {
927 			nxgep->statsp->mac_stats.link_speed = 100;
928 		}
929 		nxgep->statsp->mac_stats.link_duplex = 2;
930 		nxgep->statsp->mac_stats.link_up = 1;
931 	}
932 	nxge_global_reset(nxgep);
933 
934 nxge_set_lb_exit:
935 	NXGE_DEBUG_MSG((nxgep, DDI_CTL,
936 		"<== nxge_set_lb status = 0x%08x", status));
937 	return (status);
938 }
939 
940 /* ARGSUSED */
941 void
942 nxge_set_lb_normal(p_nxge_t nxgep)
943 {
944 	NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_set_lb_normal"));
945 	nxgep->statsp->port_stats.lb_mode = nxge_lb_normal;
946 	nxgep->param_arr[param_autoneg].value =
947 		nxgep->param_arr[param_autoneg].old_value;
948 	nxgep->param_arr[param_anar_1000fdx].value =
949 		nxgep->param_arr[param_anar_1000fdx].old_value;
950 	nxgep->param_arr[param_anar_1000hdx].value =
951 		nxgep->param_arr[param_anar_1000hdx].old_value;
952 	nxgep->param_arr[param_anar_100fdx].value =
953 		nxgep->param_arr[param_anar_100fdx].old_value;
954 	nxgep->param_arr[param_anar_100hdx].value =
955 		nxgep->param_arr[param_anar_100hdx].old_value;
956 	nxgep->param_arr[param_anar_10fdx].value =
957 		nxgep->param_arr[param_anar_10fdx].old_value;
958 	nxgep->param_arr[param_master_cfg_enable].value =
959 		nxgep->param_arr[param_master_cfg_enable].old_value;
960 	nxgep->param_arr[param_master_cfg_value].value =
961 		nxgep->param_arr[param_master_cfg_value].old_value;
962 
963 	nxge_global_reset(nxgep);
964 
965 	(void) nxge_link_monitor(nxgep, LINK_MONITOR_STOP);
966 	(void) nxge_xcvr_find(nxgep);
967 	(void) nxge_link_init(nxgep);
968 	(void) nxge_link_monitor(nxgep, LINK_MONITOR_START);
969 
970 	NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_set_lb_normal"));
971 }
972 
973 /* ARGSUSED */
974 void
975 nxge_get_mii(p_nxge_t nxgep, p_mblk_t mp)
976 {
977 	uint16_t reg;
978 
979 	NXGE_DEBUG_MSG((nxgep, IOC_CTL, "==> nxge_get_mii"));
980 
981 	reg = *(uint16_t *)mp->b_rptr;
982 	(void) nxge_mii_read(nxgep, nxgep->statsp->mac_stats.xcvr_portn, reg,
983 		(uint16_t *)mp->b_rptr);
984 	NXGE_DEBUG_MSG((nxgep, IOC_CTL, "reg = 0x%08X value = 0x%04X",
985 		reg, *(uint16_t *)mp->b_rptr));
986 	NXGE_DEBUG_MSG((nxgep, IOC_CTL, "<== nxge_get_mii"));
987 }
988 
989 /* ARGSUSED */
990 void
991 nxge_put_mii(p_nxge_t nxgep, p_mblk_t mp)
992 {
993 	uint16_t *buf;
994 	uint8_t reg;
995 
996 	NXGE_DEBUG_MSG((nxgep, IOC_CTL, "==> nxge_put_mii"));
997 	buf = (uint16_t *)mp->b_rptr;
998 	reg = (uint8_t)buf[0];
999 	NXGE_DEBUG_MSG((nxgep, IOC_CTL,
1000 		"reg = 0x%08X index = 0x%08X value = 0x%08X",
1001 		reg, buf[0], buf[1]));
1002 	(void) nxge_mii_write(nxgep, nxgep->statsp->mac_stats.xcvr_portn,
1003 		reg, buf[1]);
1004 	NXGE_DEBUG_MSG((nxgep, IOC_CTL, "<== nxge_put_mii"));
1005 }
1006 
1007 /* ARGSUSED */
1008 void
1009 nxge_check_hw_state(p_nxge_t nxgep)
1010 {
1011 	p_nxge_ldgv_t ldgvp;
1012 	p_nxge_ldv_t t_ldvp;
1013 
1014 	NXGE_DEBUG_MSG((nxgep, SYSERR_CTL, "==> nxge_check_hw_state"));
1015 
1016 	MUTEX_ENTER(nxgep->genlock);
1017 	nxgep->nxge_timerid = 0;
1018 	if (!(nxgep->drv_state & STATE_HW_INITIALIZED)) {
1019 		goto nxge_check_hw_state_exit;
1020 	}
1021 	nxge_check_tx_hang(nxgep);
1022 
1023 	ldgvp = nxgep->ldgvp;
1024 	if (ldgvp == NULL || (ldgvp->ldvp_syserr == NULL)) {
1025 		NXGE_ERROR_MSG((nxgep, SYSERR_CTL, "<== nxge_check_hw_state: "
1026 				"NULL ldgvp (interrupt not ready)."));
1027 		goto nxge_check_hw_state_exit;
1028 	}
1029 	t_ldvp = ldgvp->ldvp_syserr;
1030 	if (!t_ldvp->use_timer) {
1031 		NXGE_DEBUG_MSG((nxgep, SYSERR_CTL, "<== nxge_check_hw_state: "
1032 				"ldgvp $%p t_ldvp $%p use_timer flag %d",
1033 				ldgvp, t_ldvp, t_ldvp->use_timer));
1034 		goto nxge_check_hw_state_exit;
1035 	}
1036 	if (fm_check_acc_handle(nxgep->dev_regs->nxge_regh) != DDI_FM_OK) {
1037 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
1038 			"port%d Bad register acc handle", nxgep->mac.portnum));
1039 	}
1040 	(void) nxge_syserr_intr((void *) t_ldvp, (void *) nxgep);
1041 
1042 	nxgep->nxge_timerid = nxge_start_timer(nxgep, nxge_check_hw_state,
1043 		NXGE_CHECK_TIMER);
1044 
1045 nxge_check_hw_state_exit:
1046 	MUTEX_EXIT(nxgep->genlock);
1047 	NXGE_DEBUG_MSG((nxgep, SYSERR_CTL, "<== nxge_check_hw_state"));
1048 }
1049 
1050 /*ARGSUSED*/
1051 static void
1052 nxge_rtrace_ioctl(p_nxge_t nxgep, queue_t *wq, mblk_t *mp,
1053 	struct iocblk *iocp)
1054 {
1055 	ssize_t size;
1056 	rtrace_t *rtp;
1057 	mblk_t *nmp;
1058 	uint32_t i, j;
1059 	uint32_t start_blk;
1060 	uint32_t base_entry;
1061 	uint32_t num_entries;
1062 
1063 	NXGE_DEBUG_MSG((nxgep, STR_CTL, "==> nxge_rtrace_ioctl"));
1064 
1065 	size = 1024;
1066 	if (mp->b_cont == NULL || MBLKL(mp->b_cont) < size) {
1067 		NXGE_DEBUG_MSG((nxgep, STR_CTL,
1068 				"malformed M_IOCTL MBLKL = %d size = %d",
1069 				MBLKL(mp->b_cont), size));
1070 		miocnak(wq, mp, 0, EINVAL);
1071 		return;
1072 	}
1073 	nmp = mp->b_cont;
1074 	rtp = (rtrace_t *)nmp->b_rptr;
1075 	start_blk = rtp->next_idx;
1076 	num_entries = rtp->last_idx;
1077 	base_entry = start_blk * MAX_RTRACE_IOC_ENTRIES;
1078 
1079 	NXGE_DEBUG_MSG((nxgep, STR_CTL, "start_blk = %d\n", start_blk));
1080 	NXGE_DEBUG_MSG((nxgep, STR_CTL, "num_entries = %d\n", num_entries));
1081 	NXGE_DEBUG_MSG((nxgep, STR_CTL, "base_entry = %d\n", base_entry));
1082 
1083 	rtp->next_idx = npi_rtracebuf.next_idx;
1084 	rtp->last_idx = npi_rtracebuf.last_idx;
1085 	rtp->wrapped = npi_rtracebuf.wrapped;
1086 	for (i = 0, j = base_entry; i < num_entries; i++, j++) {
1087 		rtp->buf[i].ctl_addr = npi_rtracebuf.buf[j].ctl_addr;
1088 		rtp->buf[i].val_l32 = npi_rtracebuf.buf[j].val_l32;
1089 		rtp->buf[i].val_h32 = npi_rtracebuf.buf[j].val_h32;
1090 	}
1091 
1092 	nmp->b_wptr = nmp->b_rptr + size;
1093 	NXGE_DEBUG_MSG((nxgep, STR_CTL, "<== nxge_rtrace_ioctl"));
1094 	miocack(wq, mp, (int)size, 0);
1095 }
1096