xref: /titanic_51/usr/src/uts/common/io/nxge/nxge_rxdma.c (revision 15d9d0b528387242011cdcc6190c9e598cfe3a07)
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 <sys/nxge/nxge_rxdma.h>
30 
31 #define	NXGE_ACTUAL_RDCGRP(nxgep, rdcgrp)	\
32 	(rdcgrp + nxgep->pt_config.hw_config.start_rdc_grpid)
33 #define	NXGE_ACTUAL_RDC(nxgep, rdc)	\
34 	(rdc + nxgep->pt_config.hw_config.start_rdc)
35 
36 /*
37  * Globals: tunable parameters (/etc/system or adb)
38  *
39  */
40 extern uint32_t nxge_rbr_size;
41 extern uint32_t nxge_rcr_size;
42 extern uint32_t	nxge_rbr_spare_size;
43 
44 extern uint32_t nxge_mblks_pending;
45 
46 /*
47  * Tunable to reduce the amount of time spent in the
48  * ISR doing Rx Processing.
49  */
50 extern uint32_t nxge_max_rx_pkts;
51 boolean_t nxge_jumbo_enable;
52 
53 /*
54  * Tunables to manage the receive buffer blocks.
55  *
56  * nxge_rx_threshold_hi: copy all buffers.
57  * nxge_rx_bcopy_size_type: receive buffer block size type.
58  * nxge_rx_threshold_lo: copy only up to tunable block size type.
59  */
60 extern nxge_rxbuf_threshold_t nxge_rx_threshold_hi;
61 extern nxge_rxbuf_type_t nxge_rx_buf_size_type;
62 extern nxge_rxbuf_threshold_t nxge_rx_threshold_lo;
63 
64 static nxge_status_t nxge_map_rxdma(p_nxge_t);
65 static void nxge_unmap_rxdma(p_nxge_t);
66 
67 static nxge_status_t nxge_rxdma_hw_start_common(p_nxge_t);
68 static void nxge_rxdma_hw_stop_common(p_nxge_t);
69 
70 static nxge_status_t nxge_rxdma_hw_start(p_nxge_t);
71 static void nxge_rxdma_hw_stop(p_nxge_t);
72 
73 static nxge_status_t nxge_map_rxdma_channel(p_nxge_t, uint16_t,
74     p_nxge_dma_common_t *,  p_rx_rbr_ring_t *,
75     uint32_t,
76     p_nxge_dma_common_t *, p_rx_rcr_ring_t *,
77     p_rx_mbox_t *);
78 static void nxge_unmap_rxdma_channel(p_nxge_t, uint16_t,
79     p_rx_rbr_ring_t, p_rx_rcr_ring_t, p_rx_mbox_t);
80 
81 static nxge_status_t nxge_map_rxdma_channel_cfg_ring(p_nxge_t,
82     uint16_t,
83     p_nxge_dma_common_t *, p_rx_rbr_ring_t *,
84     p_rx_rcr_ring_t *, p_rx_mbox_t *);
85 static void nxge_unmap_rxdma_channel_cfg_ring(p_nxge_t,
86     p_rx_rcr_ring_t, p_rx_mbox_t);
87 
88 static nxge_status_t nxge_map_rxdma_channel_buf_ring(p_nxge_t,
89     uint16_t,
90     p_nxge_dma_common_t *,
91     p_rx_rbr_ring_t *, uint32_t);
92 static void nxge_unmap_rxdma_channel_buf_ring(p_nxge_t,
93     p_rx_rbr_ring_t);
94 
95 static nxge_status_t nxge_rxdma_start_channel(p_nxge_t, uint16_t,
96     p_rx_rbr_ring_t, p_rx_rcr_ring_t, p_rx_mbox_t);
97 static nxge_status_t nxge_rxdma_stop_channel(p_nxge_t, uint16_t);
98 
99 mblk_t *
100 nxge_rx_pkts(p_nxge_t, uint_t, p_nxge_ldv_t,
101     p_rx_rcr_ring_t *, rx_dma_ctl_stat_t);
102 
103 static void nxge_receive_packet(p_nxge_t,
104 	p_rx_rcr_ring_t,
105 	p_rcr_entry_t,
106 	boolean_t *,
107 	mblk_t **, mblk_t **);
108 
109 nxge_status_t nxge_disable_rxdma_channel(p_nxge_t, uint16_t);
110 
111 static p_rx_msg_t nxge_allocb(size_t, uint32_t, p_nxge_dma_common_t);
112 static void nxge_freeb(p_rx_msg_t);
113 static void nxge_rx_pkts_vring(p_nxge_t, uint_t,
114     p_nxge_ldv_t, rx_dma_ctl_stat_t);
115 static nxge_status_t nxge_rx_err_evnts(p_nxge_t, uint_t,
116 				p_nxge_ldv_t, rx_dma_ctl_stat_t);
117 
118 static nxge_status_t nxge_rxdma_handle_port_errors(p_nxge_t,
119 				uint32_t, uint32_t);
120 
121 static nxge_status_t nxge_rxbuf_index_info_init(p_nxge_t,
122     p_rx_rbr_ring_t);
123 
124 
125 static nxge_status_t
126 nxge_rxdma_fatal_err_recover(p_nxge_t, uint16_t);
127 
128 nxge_status_t
129 nxge_rx_port_fatal_err_recover(p_nxge_t);
130 
131 nxge_status_t
132 nxge_init_rxdma_channels(p_nxge_t nxgep)
133 {
134 	nxge_status_t	status = NXGE_OK;
135 
136 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_init_rxdma_channels"));
137 
138 	status = nxge_map_rxdma(nxgep);
139 	if (status != NXGE_OK) {
140 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
141 			"<== nxge_init_rxdma: status 0x%x", status));
142 		return (status);
143 	}
144 
145 	status = nxge_rxdma_hw_start_common(nxgep);
146 	if (status != NXGE_OK) {
147 		nxge_unmap_rxdma(nxgep);
148 	}
149 
150 	status = nxge_rxdma_hw_start(nxgep);
151 	if (status != NXGE_OK) {
152 		nxge_unmap_rxdma(nxgep);
153 	}
154 
155 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
156 		"<== nxge_init_rxdma_channels: status 0x%x", status));
157 
158 	return (status);
159 }
160 
161 void
162 nxge_uninit_rxdma_channels(p_nxge_t nxgep)
163 {
164 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_uninit_rxdma_channels"));
165 
166 	nxge_rxdma_hw_stop(nxgep);
167 	nxge_rxdma_hw_stop_common(nxgep);
168 	nxge_unmap_rxdma(nxgep);
169 
170 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
171 		"<== nxge_uinit_rxdma_channels"));
172 }
173 
174 nxge_status_t
175 nxge_reset_rxdma_channel(p_nxge_t nxgep, uint16_t channel)
176 {
177 	npi_handle_t		handle;
178 	npi_status_t		rs = NPI_SUCCESS;
179 	nxge_status_t		status = NXGE_OK;
180 
181 	NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_reset_rxdma_channel"));
182 
183 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
184 	rs = npi_rxdma_cfg_rdc_reset(handle, channel);
185 
186 	if (rs != NPI_SUCCESS) {
187 		status = NXGE_ERROR | rs;
188 	}
189 
190 	return (status);
191 }
192 
193 void
194 nxge_rxdma_regs_dump_channels(p_nxge_t nxgep)
195 {
196 	int			i, ndmas;
197 	uint16_t		channel;
198 	p_rx_rbr_rings_t 	rx_rbr_rings;
199 	p_rx_rbr_ring_t		*rbr_rings;
200 	npi_handle_t		handle;
201 
202 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rxdma_regs_dump_channels"));
203 
204 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
205 	(void) npi_rxdma_dump_fzc_regs(handle);
206 
207 	rx_rbr_rings = nxgep->rx_rbr_rings;
208 	if (rx_rbr_rings == NULL) {
209 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
210 			"<== nxge_rxdma_regs_dump_channels: "
211 			"NULL ring pointer"));
212 		return;
213 	}
214 	if (rx_rbr_rings->rbr_rings == NULL) {
215 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
216 			"<== nxge_rxdma_regs_dump_channels: "
217 			" NULL rbr rings pointer"));
218 		return;
219 	}
220 
221 	ndmas = rx_rbr_rings->ndmas;
222 	if (!ndmas) {
223 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
224 			"<== nxge_rxdma_regs_dump_channels: no channel"));
225 		return;
226 	}
227 
228 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
229 		"==> nxge_rxdma_regs_dump_channels (ndmas %d)", ndmas));
230 
231 	rbr_rings = rx_rbr_rings->rbr_rings;
232 	for (i = 0; i < ndmas; i++) {
233 		if (rbr_rings == NULL || rbr_rings[i] == NULL) {
234 			continue;
235 		}
236 		channel = rbr_rings[i]->rdc;
237 		(void) nxge_dump_rxdma_channel(nxgep, channel);
238 	}
239 
240 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_rxdma_regs_dump"));
241 
242 }
243 
244 nxge_status_t
245 nxge_dump_rxdma_channel(p_nxge_t nxgep, uint8_t channel)
246 {
247 	npi_handle_t		handle;
248 	npi_status_t		rs = NPI_SUCCESS;
249 	nxge_status_t		status = NXGE_OK;
250 
251 	NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_dump_rxdma_channel"));
252 
253 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
254 	rs = npi_rxdma_dump_rdc_regs(handle, channel);
255 
256 	if (rs != NPI_SUCCESS) {
257 		status = NXGE_ERROR | rs;
258 	}
259 	NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_dump_rxdma_channel"));
260 	return (status);
261 }
262 
263 nxge_status_t
264 nxge_init_rxdma_channel_event_mask(p_nxge_t nxgep, uint16_t channel,
265     p_rx_dma_ent_msk_t mask_p)
266 {
267 	npi_handle_t		handle;
268 	npi_status_t		rs = NPI_SUCCESS;
269 	nxge_status_t		status = NXGE_OK;
270 
271 	NXGE_DEBUG_MSG((nxgep, DMA_CTL,
272 		"<== nxge_init_rxdma_channel_event_mask"));
273 
274 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
275 	rs = npi_rxdma_event_mask(handle, OP_SET, channel, mask_p);
276 	if (rs != NPI_SUCCESS) {
277 		status = NXGE_ERROR | rs;
278 	}
279 
280 	return (status);
281 }
282 
283 nxge_status_t
284 nxge_init_rxdma_channel_cntl_stat(p_nxge_t nxgep, uint16_t channel,
285     p_rx_dma_ctl_stat_t cs_p)
286 {
287 	npi_handle_t		handle;
288 	npi_status_t		rs = NPI_SUCCESS;
289 	nxge_status_t		status = NXGE_OK;
290 
291 	NXGE_DEBUG_MSG((nxgep, DMA_CTL,
292 		"<== nxge_init_rxdma_channel_cntl_stat"));
293 
294 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
295 	rs = npi_rxdma_control_status(handle, OP_SET, channel, cs_p);
296 
297 	if (rs != NPI_SUCCESS) {
298 		status = NXGE_ERROR | rs;
299 	}
300 
301 	return (status);
302 }
303 
304 nxge_status_t
305 nxge_rxdma_cfg_rdcgrp_default_rdc(p_nxge_t nxgep, uint8_t rdcgrp,
306 				    uint8_t rdc)
307 {
308 	npi_handle_t		handle;
309 	npi_status_t		rs = NPI_SUCCESS;
310 	p_nxge_dma_pt_cfg_t	p_dma_cfgp;
311 	p_nxge_rdc_grp_t	rdc_grp_p;
312 	uint8_t actual_rdcgrp, actual_rdc;
313 
314 	NXGE_DEBUG_MSG((nxgep, RX2_CTL,
315 			    " ==> nxge_rxdma_cfg_rdcgrp_default_rdc"));
316 	p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
317 
318 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
319 
320 	rdc_grp_p = &p_dma_cfgp->rdc_grps[rdcgrp];
321 	rdc_grp_p->rdc[0] = rdc;
322 
323 	actual_rdcgrp = NXGE_ACTUAL_RDCGRP(nxgep, rdcgrp);
324 	actual_rdc = NXGE_ACTUAL_RDC(nxgep, rdc);
325 
326 	rs = npi_rxdma_cfg_rdc_table_default_rdc(handle, actual_rdcgrp,
327 							    actual_rdc);
328 
329 	if (rs != NPI_SUCCESS) {
330 		return (NXGE_ERROR | rs);
331 	}
332 	NXGE_DEBUG_MSG((nxgep, RX2_CTL,
333 			    " <== nxge_rxdma_cfg_rdcgrp_default_rdc"));
334 	return (NXGE_OK);
335 }
336 
337 nxge_status_t
338 nxge_rxdma_cfg_port_default_rdc(p_nxge_t nxgep, uint8_t port, uint8_t rdc)
339 {
340 	npi_handle_t		handle;
341 
342 	uint8_t actual_rdc;
343 	npi_status_t		rs = NPI_SUCCESS;
344 
345 	NXGE_DEBUG_MSG((nxgep, RX2_CTL,
346 			    " ==> nxge_rxdma_cfg_port_default_rdc"));
347 
348 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
349 	actual_rdc = NXGE_ACTUAL_RDC(nxgep, rdc);
350 	rs = npi_rxdma_cfg_default_port_rdc(handle, port, actual_rdc);
351 
352 
353 	if (rs != NPI_SUCCESS) {
354 		return (NXGE_ERROR | rs);
355 	}
356 	NXGE_DEBUG_MSG((nxgep, RX2_CTL,
357 			    " <== nxge_rxdma_cfg_port_default_rdc"));
358 
359 	return (NXGE_OK);
360 }
361 
362 nxge_status_t
363 nxge_rxdma_cfg_rcr_threshold(p_nxge_t nxgep, uint8_t channel,
364 				    uint16_t pkts)
365 {
366 	npi_status_t	rs = NPI_SUCCESS;
367 	npi_handle_t	handle;
368 	NXGE_DEBUG_MSG((nxgep, RX2_CTL,
369 			    " ==> nxge_rxdma_cfg_rcr_threshold"));
370 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
371 
372 	rs = npi_rxdma_cfg_rdc_rcr_threshold(handle, channel, pkts);
373 
374 	if (rs != NPI_SUCCESS) {
375 		return (NXGE_ERROR | rs);
376 	}
377 	NXGE_DEBUG_MSG((nxgep, RX2_CTL, " <== nxge_rxdma_cfg_rcr_threshold"));
378 	return (NXGE_OK);
379 }
380 
381 nxge_status_t
382 nxge_rxdma_cfg_rcr_timeout(p_nxge_t nxgep, uint8_t channel,
383 			    uint16_t tout, uint8_t enable)
384 {
385 	npi_status_t	rs = NPI_SUCCESS;
386 	npi_handle_t	handle;
387 	NXGE_DEBUG_MSG((nxgep, RX2_CTL, " ==> nxge_rxdma_cfg_rcr_timeout"));
388 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
389 	if (enable == 0) {
390 		rs = npi_rxdma_cfg_rdc_rcr_timeout_disable(handle, channel);
391 	} else {
392 		rs = npi_rxdma_cfg_rdc_rcr_timeout(handle, channel,
393 							    tout);
394 	}
395 
396 	if (rs != NPI_SUCCESS) {
397 		return (NXGE_ERROR | rs);
398 	}
399 	NXGE_DEBUG_MSG((nxgep, RX2_CTL, " <== nxge_rxdma_cfg_rcr_timeout"));
400 	return (NXGE_OK);
401 }
402 
403 nxge_status_t
404 nxge_enable_rxdma_channel(p_nxge_t nxgep, uint16_t channel,
405     p_rx_rbr_ring_t rbr_p, p_rx_rcr_ring_t rcr_p, p_rx_mbox_t mbox_p)
406 {
407 	npi_handle_t		handle;
408 	rdc_desc_cfg_t 		rdc_desc;
409 	p_rcrcfig_b_t		cfgb_p;
410 	npi_status_t		rs = NPI_SUCCESS;
411 
412 	NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_enable_rxdma_channel"));
413 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
414 	/*
415 	 * Use configuration data composed at init time.
416 	 * Write to hardware the receive ring configurations.
417 	 */
418 	rdc_desc.mbox_enable = 1;
419 	rdc_desc.mbox_addr = mbox_p->mbox_addr;
420 	NXGE_DEBUG_MSG((nxgep, RX_CTL,
421 		"==> nxge_enable_rxdma_channel: mboxp $%p($%p)",
422 		mbox_p->mbox_addr, rdc_desc.mbox_addr));
423 
424 	rdc_desc.rbr_len = rbr_p->rbb_max;
425 	rdc_desc.rbr_addr = rbr_p->rbr_addr;
426 
427 	switch (nxgep->rx_bksize_code) {
428 	case RBR_BKSIZE_4K:
429 		rdc_desc.page_size = SIZE_4KB;
430 		break;
431 	case RBR_BKSIZE_8K:
432 		rdc_desc.page_size = SIZE_8KB;
433 		break;
434 	case RBR_BKSIZE_16K:
435 		rdc_desc.page_size = SIZE_16KB;
436 		break;
437 	case RBR_BKSIZE_32K:
438 		rdc_desc.page_size = SIZE_32KB;
439 		break;
440 	}
441 
442 	rdc_desc.size0 = rbr_p->npi_pkt_buf_size0;
443 	rdc_desc.valid0 = 1;
444 
445 	rdc_desc.size1 = rbr_p->npi_pkt_buf_size1;
446 	rdc_desc.valid1 = 1;
447 
448 	rdc_desc.size2 = rbr_p->npi_pkt_buf_size2;
449 	rdc_desc.valid2 = 1;
450 
451 	rdc_desc.full_hdr = rcr_p->full_hdr_flag;
452 	rdc_desc.offset = rcr_p->sw_priv_hdr_len;
453 
454 	rdc_desc.rcr_len = rcr_p->comp_size;
455 	rdc_desc.rcr_addr = rcr_p->rcr_addr;
456 
457 	cfgb_p = &(rcr_p->rcr_cfgb);
458 	rdc_desc.rcr_threshold = cfgb_p->bits.ldw.pthres;
459 	rdc_desc.rcr_timeout = cfgb_p->bits.ldw.timeout;
460 	rdc_desc.rcr_timeout_enable = cfgb_p->bits.ldw.entout;
461 
462 	NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_enable_rxdma_channel: "
463 		"rbr_len qlen %d pagesize code %d rcr_len %d",
464 		rdc_desc.rbr_len, rdc_desc.page_size, rdc_desc.rcr_len));
465 	NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_enable_rxdma_channel: "
466 		"size 0 %d size 1 %d size 2 %d",
467 		rbr_p->npi_pkt_buf_size0, rbr_p->npi_pkt_buf_size1,
468 		rbr_p->npi_pkt_buf_size2));
469 
470 	rs = npi_rxdma_cfg_rdc_ring(handle, rbr_p->rdc, &rdc_desc);
471 	if (rs != NPI_SUCCESS) {
472 		return (NXGE_ERROR | rs);
473 	}
474 
475 	/*
476 	 * Enable the timeout and threshold.
477 	 */
478 	rs = npi_rxdma_cfg_rdc_rcr_threshold(handle, channel,
479 			rdc_desc.rcr_threshold);
480 	if (rs != NPI_SUCCESS) {
481 		return (NXGE_ERROR | rs);
482 	}
483 
484 	rs = npi_rxdma_cfg_rdc_rcr_timeout(handle, channel,
485 			rdc_desc.rcr_timeout);
486 	if (rs != NPI_SUCCESS) {
487 		return (NXGE_ERROR | rs);
488 	}
489 
490 	/* Enable the DMA */
491 	rs = npi_rxdma_cfg_rdc_enable(handle, channel);
492 	if (rs != NPI_SUCCESS) {
493 		return (NXGE_ERROR | rs);
494 	}
495 
496 	/* Kick the DMA engine. */
497 	npi_rxdma_rdc_rbr_kick(handle, channel, rbr_p->rbb_max);
498 	/* Clear the rbr empty bit */
499 	(void) npi_rxdma_channel_rbr_empty_clear(handle, channel);
500 
501 	NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_enable_rxdma_channel"));
502 
503 	return (NXGE_OK);
504 }
505 
506 nxge_status_t
507 nxge_disable_rxdma_channel(p_nxge_t nxgep, uint16_t channel)
508 {
509 	npi_handle_t		handle;
510 	npi_status_t		rs = NPI_SUCCESS;
511 
512 	NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_disable_rxdma_channel"));
513 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
514 
515 	/* disable the DMA */
516 	rs = npi_rxdma_cfg_rdc_disable(handle, channel);
517 	if (rs != NPI_SUCCESS) {
518 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
519 			"<== nxge_disable_rxdma_channel:failed (0x%x)",
520 			rs));
521 		return (NXGE_ERROR | rs);
522 	}
523 
524 	NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_disable_rxdma_channel"));
525 	return (NXGE_OK);
526 }
527 
528 nxge_status_t
529 nxge_rxdma_channel_rcrflush(p_nxge_t nxgep, uint8_t channel)
530 {
531 	npi_handle_t		handle;
532 	nxge_status_t		status = NXGE_OK;
533 
534 	NXGE_DEBUG_MSG((nxgep, DMA_CTL,
535 		"<== nxge_init_rxdma_channel_rcrflush"));
536 
537 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
538 	npi_rxdma_rdc_rcr_flush(handle, channel);
539 
540 	NXGE_DEBUG_MSG((nxgep, DMA_CTL,
541 		"<== nxge_init_rxdma_channel_rcrflsh"));
542 	return (status);
543 
544 }
545 
546 #define	MID_INDEX(l, r) ((r + l + 1) >> 1)
547 
548 #define	TO_LEFT -1
549 #define	TO_RIGHT 1
550 #define	BOTH_RIGHT (TO_RIGHT + TO_RIGHT)
551 #define	BOTH_LEFT (TO_LEFT + TO_LEFT)
552 #define	IN_MIDDLE (TO_RIGHT + TO_LEFT)
553 #define	NO_HINT 0xffffffff
554 
555 /*ARGSUSED*/
556 nxge_status_t
557 nxge_rxbuf_pp_to_vp(p_nxge_t nxgep, p_rx_rbr_ring_t rbr_p,
558 	uint8_t pktbufsz_type, uint64_t *pkt_buf_addr_pp,
559 	uint64_t **pkt_buf_addr_p, uint32_t *bufoffset, uint32_t *msg_index)
560 {
561 	int			bufsize;
562 	uint64_t		pktbuf_pp;
563 	uint64_t 		dvma_addr;
564 	rxring_info_t 		*ring_info;
565 	int 			base_side, end_side;
566 	int 			r_index, l_index, anchor_index;
567 	int 			found, search_done;
568 	uint32_t offset, chunk_size, block_size, page_size_mask;
569 	uint32_t chunk_index, block_index, total_index;
570 	int 			max_iterations, iteration;
571 	rxbuf_index_info_t 	*bufinfo;
572 
573 	NXGE_DEBUG_MSG((nxgep, RX2_CTL, "==> nxge_rxbuf_pp_to_vp"));
574 
575 	NXGE_DEBUG_MSG((nxgep, RX2_CTL,
576 		"==> nxge_rxbuf_pp_to_vp: buf_pp $%p btype %d",
577 		pkt_buf_addr_pp,
578 		pktbufsz_type));
579 #if defined(__i386)
580 	pktbuf_pp = (uint64_t)(uint32_t)pkt_buf_addr_pp;
581 #else
582 	pktbuf_pp = (uint64_t)pkt_buf_addr_pp;
583 #endif
584 
585 	switch (pktbufsz_type) {
586 	case 0:
587 		bufsize = rbr_p->pkt_buf_size0;
588 		break;
589 	case 1:
590 		bufsize = rbr_p->pkt_buf_size1;
591 		break;
592 	case 2:
593 		bufsize = rbr_p->pkt_buf_size2;
594 		break;
595 	case RCR_SINGLE_BLOCK:
596 		bufsize = 0;
597 		anchor_index = 0;
598 		break;
599 	default:
600 		return (NXGE_ERROR);
601 	}
602 
603 	if (rbr_p->num_blocks == 1) {
604 		anchor_index = 0;
605 		ring_info = rbr_p->ring_info;
606 		bufinfo = (rxbuf_index_info_t *)ring_info->buffer;
607 		NXGE_DEBUG_MSG((nxgep, RX2_CTL,
608 			"==> nxge_rxbuf_pp_to_vp: (found, 1 block) "
609 			"buf_pp $%p btype %d anchor_index %d "
610 			"bufinfo $%p",
611 			pkt_buf_addr_pp,
612 			pktbufsz_type,
613 			anchor_index,
614 			bufinfo));
615 
616 		goto found_index;
617 	}
618 
619 	NXGE_DEBUG_MSG((nxgep, RX2_CTL,
620 		"==> nxge_rxbuf_pp_to_vp: "
621 		"buf_pp $%p btype %d  anchor_index %d",
622 		pkt_buf_addr_pp,
623 		pktbufsz_type,
624 		anchor_index));
625 
626 	ring_info = rbr_p->ring_info;
627 	found = B_FALSE;
628 	bufinfo = (rxbuf_index_info_t *)ring_info->buffer;
629 	iteration = 0;
630 	max_iterations = ring_info->max_iterations;
631 		/*
632 		 * First check if this block has been seen
633 		 * recently. This is indicated by a hint which
634 		 * is initialized when the first buffer of the block
635 		 * is seen. The hint is reset when the last buffer of
636 		 * the block has been processed.
637 		 * As three block sizes are supported, three hints
638 		 * are kept. The idea behind the hints is that once
639 		 * the hardware  uses a block for a buffer  of that
640 		 * size, it will use it exclusively for that size
641 		 * and will use it until it is exhausted. It is assumed
642 		 * that there would a single block being used for the same
643 		 * buffer sizes at any given time.
644 		 */
645 	if (ring_info->hint[pktbufsz_type] != NO_HINT) {
646 		anchor_index = ring_info->hint[pktbufsz_type];
647 		dvma_addr =  bufinfo[anchor_index].dvma_addr;
648 		chunk_size = bufinfo[anchor_index].buf_size;
649 		if ((pktbuf_pp >= dvma_addr) &&
650 			(pktbuf_pp < (dvma_addr + chunk_size))) {
651 			found = B_TRUE;
652 				/*
653 				 * check if this is the last buffer in the block
654 				 * If so, then reset the hint for the size;
655 				 */
656 
657 			if ((pktbuf_pp + bufsize) >= (dvma_addr + chunk_size))
658 				ring_info->hint[pktbufsz_type] = NO_HINT;
659 		}
660 	}
661 
662 	if (found == B_FALSE) {
663 		NXGE_DEBUG_MSG((nxgep, RX2_CTL,
664 			"==> nxge_rxbuf_pp_to_vp: (!found)"
665 			"buf_pp $%p btype %d anchor_index %d",
666 			pkt_buf_addr_pp,
667 			pktbufsz_type,
668 			anchor_index));
669 
670 			/*
671 			 * This is the first buffer of the block of this
672 			 * size. Need to search the whole information
673 			 * array.
674 			 * the search algorithm uses a binary tree search
675 			 * algorithm. It assumes that the information is
676 			 * already sorted with increasing order
677 			 * info[0] < info[1] < info[2]  .... < info[n-1]
678 			 * where n is the size of the information array
679 			 */
680 		r_index = rbr_p->num_blocks - 1;
681 		l_index = 0;
682 		search_done = B_FALSE;
683 		anchor_index = MID_INDEX(r_index, l_index);
684 		while (search_done == B_FALSE) {
685 			if ((r_index == l_index) ||
686 				(iteration >= max_iterations))
687 				search_done = B_TRUE;
688 			end_side = TO_RIGHT; /* to the right */
689 			base_side = TO_LEFT; /* to the left */
690 			/* read the DVMA address information and sort it */
691 			dvma_addr =  bufinfo[anchor_index].dvma_addr;
692 			chunk_size = bufinfo[anchor_index].buf_size;
693 			NXGE_DEBUG_MSG((nxgep, RX2_CTL,
694 				"==> nxge_rxbuf_pp_to_vp: (searching)"
695 				"buf_pp $%p btype %d "
696 				"anchor_index %d chunk_size %d dvmaaddr $%p",
697 				pkt_buf_addr_pp,
698 				pktbufsz_type,
699 				anchor_index,
700 				chunk_size,
701 				dvma_addr));
702 
703 			if (pktbuf_pp >= dvma_addr)
704 				base_side = TO_RIGHT; /* to the right */
705 			if (pktbuf_pp < (dvma_addr + chunk_size))
706 				end_side = TO_LEFT; /* to the left */
707 
708 			switch (base_side + end_side) {
709 				case IN_MIDDLE:
710 					/* found */
711 					found = B_TRUE;
712 					search_done = B_TRUE;
713 					if ((pktbuf_pp + bufsize) <
714 						(dvma_addr + chunk_size))
715 						ring_info->hint[pktbufsz_type] =
716 						bufinfo[anchor_index].buf_index;
717 					break;
718 				case BOTH_RIGHT:
719 						/* not found: go to the right */
720 					l_index = anchor_index + 1;
721 					anchor_index =
722 						MID_INDEX(r_index, l_index);
723 					break;
724 
725 				case  BOTH_LEFT:
726 						/* not found: go to the left */
727 					r_index = anchor_index - 1;
728 					anchor_index = MID_INDEX(r_index,
729 						l_index);
730 					break;
731 				default: /* should not come here */
732 					return (NXGE_ERROR);
733 			}
734 			iteration++;
735 		}
736 
737 		NXGE_DEBUG_MSG((nxgep, RX2_CTL,
738 			"==> nxge_rxbuf_pp_to_vp: (search done)"
739 			"buf_pp $%p btype %d anchor_index %d",
740 			pkt_buf_addr_pp,
741 			pktbufsz_type,
742 			anchor_index));
743 	}
744 
745 	if (found == B_FALSE) {
746 		NXGE_DEBUG_MSG((nxgep, RX2_CTL,
747 			"==> nxge_rxbuf_pp_to_vp: (search failed)"
748 			"buf_pp $%p btype %d anchor_index %d",
749 			pkt_buf_addr_pp,
750 			pktbufsz_type,
751 			anchor_index));
752 		return (NXGE_ERROR);
753 	}
754 
755 found_index:
756 	NXGE_DEBUG_MSG((nxgep, RX2_CTL,
757 		"==> nxge_rxbuf_pp_to_vp: (FOUND1)"
758 		"buf_pp $%p btype %d bufsize %d anchor_index %d",
759 		pkt_buf_addr_pp,
760 		pktbufsz_type,
761 		bufsize,
762 		anchor_index));
763 
764 	/* index of the first block in this chunk */
765 	chunk_index = bufinfo[anchor_index].start_index;
766 	dvma_addr =  bufinfo[anchor_index].dvma_addr;
767 	page_size_mask = ring_info->block_size_mask;
768 
769 	NXGE_DEBUG_MSG((nxgep, RX2_CTL,
770 		"==> nxge_rxbuf_pp_to_vp: (FOUND3), get chunk)"
771 		"buf_pp $%p btype %d bufsize %d "
772 		"anchor_index %d chunk_index %d dvma $%p",
773 		pkt_buf_addr_pp,
774 		pktbufsz_type,
775 		bufsize,
776 		anchor_index,
777 		chunk_index,
778 		dvma_addr));
779 
780 	offset = pktbuf_pp - dvma_addr; /* offset within the chunk */
781 	block_size = rbr_p->block_size; /* System  block(page) size */
782 
783 	NXGE_DEBUG_MSG((nxgep, RX2_CTL,
784 		"==> nxge_rxbuf_pp_to_vp: (FOUND4), get chunk)"
785 		"buf_pp $%p btype %d bufsize %d "
786 		"anchor_index %d chunk_index %d dvma $%p "
787 		"offset %d block_size %d",
788 		pkt_buf_addr_pp,
789 		pktbufsz_type,
790 		bufsize,
791 		anchor_index,
792 		chunk_index,
793 		dvma_addr,
794 		offset,
795 		block_size));
796 
797 	NXGE_DEBUG_MSG((nxgep, RX2_CTL, "==> getting total index"));
798 
799 	block_index = (offset / block_size); /* index within chunk */
800 	total_index = chunk_index + block_index;
801 
802 
803 	NXGE_DEBUG_MSG((nxgep, RX2_CTL,
804 		"==> nxge_rxbuf_pp_to_vp: "
805 		"total_index %d dvma_addr $%p "
806 		"offset %d block_size %d "
807 		"block_index %d ",
808 		total_index, dvma_addr,
809 		offset, block_size,
810 		block_index));
811 #if defined(__i386)
812 	*pkt_buf_addr_p = (uint64_t *)((uint32_t)bufinfo[anchor_index].kaddr +
813 		(uint32_t)offset);
814 #else
815 	*pkt_buf_addr_p = (uint64_t *)((uint64_t)bufinfo[anchor_index].kaddr +
816 		(uint64_t)offset);
817 #endif
818 
819 	NXGE_DEBUG_MSG((nxgep, RX2_CTL,
820 		"==> nxge_rxbuf_pp_to_vp: "
821 		"total_index %d dvma_addr $%p "
822 		"offset %d block_size %d "
823 		"block_index %d "
824 		"*pkt_buf_addr_p $%p",
825 		total_index, dvma_addr,
826 		offset, block_size,
827 		block_index,
828 		*pkt_buf_addr_p));
829 
830 
831 	*msg_index = total_index;
832 	*bufoffset =  (offset & page_size_mask);
833 
834 	NXGE_DEBUG_MSG((nxgep, RX2_CTL,
835 		"==> nxge_rxbuf_pp_to_vp: get msg index: "
836 		"msg_index %d bufoffset_index %d",
837 		*msg_index,
838 		*bufoffset));
839 
840 	NXGE_DEBUG_MSG((nxgep, RX2_CTL, "<== nxge_rxbuf_pp_to_vp"));
841 
842 	return (NXGE_OK);
843 }
844 
845 /*
846  * used by quick sort (qsort) function
847  * to perform comparison
848  */
849 static int
850 nxge_sort_compare(const void *p1, const void *p2)
851 {
852 
853 	rxbuf_index_info_t *a, *b;
854 
855 	a = (rxbuf_index_info_t *)p1;
856 	b = (rxbuf_index_info_t *)p2;
857 
858 	if (a->dvma_addr > b->dvma_addr)
859 		return (1);
860 	if (a->dvma_addr < b->dvma_addr)
861 		return (-1);
862 	return (0);
863 }
864 
865 
866 
867 /*
868  * grabbed this sort implementation from common/syscall/avl.c
869  *
870  */
871 /*
872  * Generic shellsort, from K&R (1st ed, p 58.), somewhat modified.
873  * v = Ptr to array/vector of objs
874  * n = # objs in the array
875  * s = size of each obj (must be multiples of a word size)
876  * f = ptr to function to compare two objs
877  *	returns (-1 = less than, 0 = equal, 1 = greater than
878  */
879 void
880 nxge_ksort(caddr_t v, int n, int s, int (*f)())
881 {
882 	int g, i, j, ii;
883 	unsigned int *p1, *p2;
884 	unsigned int tmp;
885 
886 	/* No work to do */
887 	if (v == NULL || n <= 1)
888 		return;
889 	/* Sanity check on arguments */
890 	ASSERT(((uintptr_t)v & 0x3) == 0 && (s & 0x3) == 0);
891 	ASSERT(s > 0);
892 
893 	for (g = n / 2; g > 0; g /= 2) {
894 		for (i = g; i < n; i++) {
895 			for (j = i - g; j >= 0 &&
896 				(*f)(v + j * s, v + (j + g) * s) == 1;
897 					j -= g) {
898 				p1 = (unsigned *)(v + j * s);
899 				p2 = (unsigned *)(v + (j + g) * s);
900 				for (ii = 0; ii < s / 4; ii++) {
901 					tmp = *p1;
902 					*p1++ = *p2;
903 					*p2++ = tmp;
904 				}
905 			}
906 		}
907 	}
908 }
909 
910 /*
911  * Initialize data structures required for rxdma
912  * buffer dvma->vmem address lookup
913  */
914 /*ARGSUSED*/
915 static nxge_status_t
916 nxge_rxbuf_index_info_init(p_nxge_t nxgep, p_rx_rbr_ring_t rbrp)
917 {
918 
919 	int index;
920 	rxring_info_t *ring_info;
921 	int max_iteration = 0, max_index = 0;
922 
923 	NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_rxbuf_index_info_init"));
924 
925 	ring_info = rbrp->ring_info;
926 	ring_info->hint[0] = NO_HINT;
927 	ring_info->hint[1] = NO_HINT;
928 	ring_info->hint[2] = NO_HINT;
929 	max_index = rbrp->num_blocks;
930 
931 		/* read the DVMA address information and sort it */
932 		/* do init of the information array */
933 
934 
935 	NXGE_DEBUG_MSG((nxgep, DMA2_CTL,
936 		" nxge_rxbuf_index_info_init Sort ptrs"));
937 
938 		/* sort the array */
939 	nxge_ksort((void *)ring_info->buffer, max_index,
940 		sizeof (rxbuf_index_info_t), nxge_sort_compare);
941 
942 
943 
944 	for (index = 0; index < max_index; index++) {
945 		NXGE_DEBUG_MSG((nxgep, DMA2_CTL,
946 			" nxge_rxbuf_index_info_init: sorted chunk %d "
947 			" ioaddr $%p kaddr $%p size %x",
948 			index, ring_info->buffer[index].dvma_addr,
949 			ring_info->buffer[index].kaddr,
950 			ring_info->buffer[index].buf_size));
951 	}
952 
953 	max_iteration = 0;
954 	while (max_index >= (1ULL << max_iteration))
955 		max_iteration++;
956 	ring_info->max_iterations = max_iteration + 1;
957 	NXGE_DEBUG_MSG((nxgep, DMA2_CTL,
958 		" nxge_rxbuf_index_info_init Find max iter %d",
959 					ring_info->max_iterations));
960 
961 	NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_rxbuf_index_info_init"));
962 	return (NXGE_OK);
963 }
964 
965 /* ARGSUSED */
966 void
967 nxge_dump_rcr_entry(p_nxge_t nxgep, p_rcr_entry_t entry_p)
968 {
969 #ifdef	NXGE_DEBUG
970 
971 	uint32_t bptr;
972 	uint64_t pp;
973 
974 	bptr = entry_p->bits.hdw.pkt_buf_addr;
975 
976 	NXGE_DEBUG_MSG((nxgep, RX_CTL,
977 		"\trcr entry $%p "
978 		"\trcr entry 0x%0llx "
979 		"\trcr entry 0x%08x "
980 		"\trcr entry 0x%08x "
981 		"\tvalue 0x%0llx\n"
982 		"\tmulti = %d\n"
983 		"\tpkt_type = 0x%x\n"
984 		"\tzero_copy = %d\n"
985 		"\tnoport = %d\n"
986 		"\tpromis = %d\n"
987 		"\terror = 0x%04x\n"
988 		"\tdcf_err = 0x%01x\n"
989 		"\tl2_len = %d\n"
990 		"\tpktbufsize = %d\n"
991 		"\tpkt_buf_addr = $%p\n"
992 		"\tpkt_buf_addr (<< 6) = $%p\n",
993 		entry_p,
994 		*(int64_t *)entry_p,
995 		*(int32_t *)entry_p,
996 		*(int32_t *)((char *)entry_p + 32),
997 		entry_p->value,
998 		entry_p->bits.hdw.multi,
999 		entry_p->bits.hdw.pkt_type,
1000 		entry_p->bits.hdw.zero_copy,
1001 		entry_p->bits.hdw.noport,
1002 		entry_p->bits.hdw.promis,
1003 		entry_p->bits.hdw.error,
1004 		entry_p->bits.hdw.dcf_err,
1005 		entry_p->bits.hdw.l2_len,
1006 		entry_p->bits.hdw.pktbufsz,
1007 		bptr,
1008 		entry_p->bits.ldw.pkt_buf_addr));
1009 
1010 	pp = (entry_p->value & RCR_PKT_BUF_ADDR_MASK) <<
1011 		RCR_PKT_BUF_ADDR_SHIFT;
1012 
1013 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "rcr pp 0x%llx l2 len %d",
1014 		pp, (*(int64_t *)entry_p >> 40) & 0x3fff));
1015 #endif
1016 }
1017 
1018 void
1019 nxge_rxdma_regs_dump(p_nxge_t nxgep, int rdc)
1020 {
1021 	npi_handle_t		handle;
1022 	rbr_stat_t 		rbr_stat;
1023 	addr44_t 		hd_addr;
1024 	addr44_t 		tail_addr;
1025 	uint16_t 		qlen;
1026 
1027 	NXGE_DEBUG_MSG((nxgep, RX_CTL,
1028 		"==> nxge_rxdma_regs_dump: rdc channel %d", rdc));
1029 
1030 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
1031 
1032 	/* RBR head */
1033 	hd_addr.addr = 0;
1034 	(void) npi_rxdma_rdc_rbr_head_get(handle, rdc, &hd_addr);
1035 #if defined(__i386)
1036 	printf("nxge_rxdma_regs_dump: got hdptr $%p \n",
1037 		(void *)(uint32_t)hd_addr.addr);
1038 #else
1039 	printf("nxge_rxdma_regs_dump: got hdptr $%p \n",
1040 		(void *)hd_addr.addr);
1041 #endif
1042 
1043 	/* RBR stats */
1044 	(void) npi_rxdma_rdc_rbr_stat_get(handle, rdc, &rbr_stat);
1045 	printf("nxge_rxdma_regs_dump: rbr len %d \n", rbr_stat.bits.ldw.qlen);
1046 
1047 	/* RCR tail */
1048 	tail_addr.addr = 0;
1049 	(void) npi_rxdma_rdc_rcr_tail_get(handle, rdc, &tail_addr);
1050 #if defined(__i386)
1051 	printf("nxge_rxdma_regs_dump: got tail ptr $%p \n",
1052 		(void *)(uint32_t)tail_addr.addr);
1053 #else
1054 	printf("nxge_rxdma_regs_dump: got tail ptr $%p \n",
1055 		(void *)tail_addr.addr);
1056 #endif
1057 
1058 	/* RCR qlen */
1059 	(void) npi_rxdma_rdc_rcr_qlen_get(handle, rdc, &qlen);
1060 	printf("nxge_rxdma_regs_dump: rcr len %x \n", qlen);
1061 
1062 	NXGE_DEBUG_MSG((nxgep, RX_CTL,
1063 		"<== nxge_rxdma_regs_dump: rdc rdc %d", rdc));
1064 }
1065 
1066 void
1067 nxge_rxdma_stop(p_nxge_t nxgep)
1068 {
1069 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rxdma_stop"));
1070 
1071 	(void) nxge_link_monitor(nxgep, LINK_MONITOR_STOP);
1072 	(void) nxge_rx_mac_disable(nxgep);
1073 	(void) nxge_rxdma_hw_mode(nxgep, NXGE_DMA_STOP);
1074 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_rxdma_stop"));
1075 }
1076 
1077 void
1078 nxge_rxdma_stop_reinit(p_nxge_t nxgep)
1079 {
1080 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rxdma_stop_reinit"));
1081 
1082 	(void) nxge_rxdma_stop(nxgep);
1083 	(void) nxge_uninit_rxdma_channels(nxgep);
1084 	(void) nxge_init_rxdma_channels(nxgep);
1085 
1086 #ifndef	AXIS_DEBUG_LB
1087 	(void) nxge_xcvr_init(nxgep);
1088 	(void) nxge_link_monitor(nxgep, LINK_MONITOR_START);
1089 #endif
1090 	(void) nxge_rx_mac_enable(nxgep);
1091 
1092 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_rxdma_stop_reinit"));
1093 }
1094 
1095 nxge_status_t
1096 nxge_rxdma_hw_mode(p_nxge_t nxgep, boolean_t enable)
1097 {
1098 	int			i, ndmas;
1099 	uint16_t		channel;
1100 	p_rx_rbr_rings_t 	rx_rbr_rings;
1101 	p_rx_rbr_ring_t		*rbr_rings;
1102 	npi_handle_t		handle;
1103 	npi_status_t		rs = NPI_SUCCESS;
1104 	nxge_status_t		status = NXGE_OK;
1105 
1106 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
1107 		"==> nxge_rxdma_hw_mode: mode %d", enable));
1108 
1109 	if (!(nxgep->drv_state & STATE_HW_INITIALIZED)) {
1110 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
1111 			"<== nxge_rxdma_mode: not initialized"));
1112 		return (NXGE_ERROR);
1113 	}
1114 
1115 	rx_rbr_rings = nxgep->rx_rbr_rings;
1116 	if (rx_rbr_rings == NULL) {
1117 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
1118 			"<== nxge_rxdma_mode: NULL ring pointer"));
1119 		return (NXGE_ERROR);
1120 	}
1121 	if (rx_rbr_rings->rbr_rings == NULL) {
1122 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
1123 			"<== nxge_rxdma_mode: NULL rbr rings pointer"));
1124 		return (NXGE_ERROR);
1125 	}
1126 
1127 	ndmas = rx_rbr_rings->ndmas;
1128 	if (!ndmas) {
1129 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
1130 			"<== nxge_rxdma_mode: no channel"));
1131 		return (NXGE_ERROR);
1132 	}
1133 
1134 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
1135 		"==> nxge_rxdma_mode (ndmas %d)", ndmas));
1136 
1137 	rbr_rings = rx_rbr_rings->rbr_rings;
1138 
1139 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
1140 	for (i = 0; i < ndmas; i++) {
1141 		if (rbr_rings == NULL || rbr_rings[i] == NULL) {
1142 			continue;
1143 		}
1144 		channel = rbr_rings[i]->rdc;
1145 		if (enable) {
1146 			NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
1147 				"==> nxge_rxdma_hw_mode: channel %d (enable)",
1148 				channel));
1149 			rs = npi_rxdma_cfg_rdc_enable(handle, channel);
1150 		} else {
1151 			NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
1152 				"==> nxge_rxdma_hw_mode: channel %d (disable)",
1153 				channel));
1154 			rs = npi_rxdma_cfg_rdc_disable(handle, channel);
1155 		}
1156 	}
1157 
1158 	status = ((rs == NPI_SUCCESS) ? NXGE_OK : NXGE_ERROR | rs);
1159 
1160 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
1161 		"<== nxge_rxdma_hw_mode: status 0x%x", status));
1162 
1163 	return (status);
1164 }
1165 
1166 void
1167 nxge_rxdma_enable_channel(p_nxge_t nxgep, uint16_t channel)
1168 {
1169 	npi_handle_t		handle;
1170 
1171 	NXGE_DEBUG_MSG((nxgep, DMA_CTL,
1172 		"==> nxge_rxdma_enable_channel: channel %d", channel));
1173 
1174 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
1175 	(void) npi_rxdma_cfg_rdc_enable(handle, channel);
1176 
1177 	NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_rxdma_enable_channel"));
1178 }
1179 
1180 void
1181 nxge_rxdma_disable_channel(p_nxge_t nxgep, uint16_t channel)
1182 {
1183 	npi_handle_t		handle;
1184 
1185 	NXGE_DEBUG_MSG((nxgep, DMA_CTL,
1186 		"==> nxge_rxdma_disable_channel: channel %d", channel));
1187 
1188 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
1189 	(void) npi_rxdma_cfg_rdc_disable(handle, channel);
1190 
1191 	NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_rxdma_disable_channel"));
1192 }
1193 
1194 void
1195 nxge_hw_start_rx(p_nxge_t nxgep)
1196 {
1197 	NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_hw_start_rx"));
1198 
1199 	(void) nxge_rxdma_hw_mode(nxgep, NXGE_DMA_START);
1200 	(void) nxge_rx_mac_enable(nxgep);
1201 
1202 	NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_hw_start_rx"));
1203 }
1204 
1205 /*ARGSUSED*/
1206 void
1207 nxge_fixup_rxdma_rings(p_nxge_t nxgep)
1208 {
1209 	int			i, ndmas;
1210 	uint16_t		rdc;
1211 	p_rx_rbr_rings_t 	rx_rbr_rings;
1212 	p_rx_rbr_ring_t		*rbr_rings;
1213 	p_rx_rcr_rings_t 	rx_rcr_rings;
1214 
1215 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_fixup_rxdma_rings"));
1216 
1217 	rx_rbr_rings = nxgep->rx_rbr_rings;
1218 	if (rx_rbr_rings == NULL) {
1219 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
1220 			"<== nxge_fixup_rxdma_rings: NULL ring pointer"));
1221 		return;
1222 	}
1223 	ndmas = rx_rbr_rings->ndmas;
1224 	if (!ndmas) {
1225 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
1226 			"<== nxge_fixup_rxdma_rings: no channel"));
1227 		return;
1228 	}
1229 
1230 	rx_rcr_rings = nxgep->rx_rcr_rings;
1231 	if (rx_rcr_rings == NULL) {
1232 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
1233 			"<== nxge_fixup_rxdma_rings: NULL ring pointer"));
1234 		return;
1235 	}
1236 	NXGE_DEBUG_MSG((nxgep, RX_CTL,
1237 		"==> nxge_fixup_rxdma_rings (ndmas %d)", ndmas));
1238 
1239 	nxge_rxdma_hw_stop(nxgep);
1240 
1241 	rbr_rings = rx_rbr_rings->rbr_rings;
1242 	for (i = 0; i < ndmas; i++) {
1243 		rdc = rbr_rings[i]->rdc;
1244 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
1245 			"==> nxge_fixup_rxdma_rings: channel %d "
1246 			"ring $%px", rdc, rbr_rings[i]));
1247 		(void) nxge_rxdma_fixup_channel(nxgep, rdc, i);
1248 	}
1249 
1250 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_fixup_rxdma_rings"));
1251 }
1252 
1253 void
1254 nxge_rxdma_fix_channel(p_nxge_t nxgep, uint16_t channel)
1255 {
1256 	int		i;
1257 
1258 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rxdma_fix_channel"));
1259 	i = nxge_rxdma_get_ring_index(nxgep, channel);
1260 	if (i < 0) {
1261 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
1262 			"<== nxge_rxdma_fix_channel: no entry found"));
1263 		return;
1264 	}
1265 
1266 	nxge_rxdma_fixup_channel(nxgep, channel, i);
1267 
1268 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_txdma_fix_channel"));
1269 }
1270 
1271 void
1272 nxge_rxdma_fixup_channel(p_nxge_t nxgep, uint16_t channel, int entry)
1273 {
1274 	int			ndmas;
1275 	p_rx_rbr_rings_t 	rx_rbr_rings;
1276 	p_rx_rbr_ring_t		*rbr_rings;
1277 	p_rx_rcr_rings_t 	rx_rcr_rings;
1278 	p_rx_rcr_ring_t		*rcr_rings;
1279 	p_rx_mbox_areas_t 	rx_mbox_areas_p;
1280 	p_rx_mbox_t		*rx_mbox_p;
1281 	p_nxge_dma_pool_t	dma_buf_poolp;
1282 	p_nxge_dma_pool_t	dma_cntl_poolp;
1283 	p_rx_rbr_ring_t 	rbrp;
1284 	p_rx_rcr_ring_t 	rcrp;
1285 	p_rx_mbox_t 		mboxp;
1286 	p_nxge_dma_common_t 	dmap;
1287 	nxge_status_t		status = NXGE_OK;
1288 
1289 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rxdma_fixup_channel"));
1290 
1291 	(void) nxge_rxdma_stop_channel(nxgep, channel);
1292 
1293 	dma_buf_poolp = nxgep->rx_buf_pool_p;
1294 	dma_cntl_poolp = nxgep->rx_cntl_pool_p;
1295 
1296 	if (!dma_buf_poolp->buf_allocated || !dma_cntl_poolp->buf_allocated) {
1297 		NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
1298 			"<== nxge_rxdma_fixup_channel: buf not allocated"));
1299 		return;
1300 	}
1301 
1302 	ndmas = dma_buf_poolp->ndmas;
1303 	if (!ndmas) {
1304 		NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
1305 			"<== nxge_rxdma_fixup_channel: no dma allocated"));
1306 		return;
1307 	}
1308 
1309 	rx_rbr_rings = nxgep->rx_rbr_rings;
1310 	rx_rcr_rings = nxgep->rx_rcr_rings;
1311 	rbr_rings = rx_rbr_rings->rbr_rings;
1312 	rcr_rings = rx_rcr_rings->rcr_rings;
1313 	rx_mbox_areas_p = nxgep->rx_mbox_areas_p;
1314 	rx_mbox_p = rx_mbox_areas_p->rxmbox_areas;
1315 
1316 	/* Reinitialize the receive block and completion rings */
1317 	rbrp = (p_rx_rbr_ring_t)rbr_rings[entry],
1318 	rcrp = (p_rx_rcr_ring_t)rcr_rings[entry],
1319 	mboxp = (p_rx_mbox_t)rx_mbox_p[entry];
1320 
1321 
1322 	rbrp->rbr_wr_index = (rbrp->rbb_max - 1);
1323 	rbrp->rbr_rd_index = 0;
1324 	rcrp->comp_rd_index = 0;
1325 	rcrp->comp_wt_index = 0;
1326 
1327 	dmap = (p_nxge_dma_common_t)&rcrp->rcr_desc;
1328 	bzero((caddr_t)dmap->kaddrp, dmap->alength);
1329 
1330 	status = nxge_rxdma_start_channel(nxgep, channel,
1331 			rbrp, rcrp, mboxp);
1332 	if (status != NXGE_OK) {
1333 		goto nxge_rxdma_fixup_channel_fail;
1334 	}
1335 	if (status != NXGE_OK) {
1336 		goto nxge_rxdma_fixup_channel_fail;
1337 	}
1338 
1339 nxge_rxdma_fixup_channel_fail:
1340 	NXGE_DEBUG_MSG((nxgep, RX_CTL,
1341 		"==> nxge_rxdma_fixup_channel: failed (0x%08x)", status));
1342 
1343 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_rxdma_fixup_channel"));
1344 }
1345 
1346 int
1347 nxge_rxdma_get_ring_index(p_nxge_t nxgep, uint16_t channel)
1348 {
1349 	int			i, ndmas;
1350 	uint16_t		rdc;
1351 	p_rx_rbr_rings_t 	rx_rbr_rings;
1352 	p_rx_rbr_ring_t		*rbr_rings;
1353 
1354 	NXGE_DEBUG_MSG((nxgep, RX_CTL,
1355 		"==> nxge_rxdma_get_ring_index: channel %d", channel));
1356 
1357 	rx_rbr_rings = nxgep->rx_rbr_rings;
1358 	if (rx_rbr_rings == NULL) {
1359 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
1360 			"<== nxge_rxdma_get_ring_index: NULL ring pointer"));
1361 		return (-1);
1362 	}
1363 	ndmas = rx_rbr_rings->ndmas;
1364 	if (!ndmas) {
1365 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
1366 			"<== nxge_rxdma_get_ring_index: no channel"));
1367 		return (-1);
1368 	}
1369 
1370 	NXGE_DEBUG_MSG((nxgep, RX_CTL,
1371 		"==> nxge_rxdma_get_ring_index (ndmas %d)", ndmas));
1372 
1373 	rbr_rings = rx_rbr_rings->rbr_rings;
1374 	for (i = 0; i < ndmas; i++) {
1375 		rdc = rbr_rings[i]->rdc;
1376 		if (channel == rdc) {
1377 			NXGE_DEBUG_MSG((nxgep, RX_CTL,
1378 				"==> nxge_rxdma_get_rbr_ring: "
1379 				"channel %d (index %d) "
1380 				"ring %d", channel, i,
1381 				rbr_rings[i]));
1382 			return (i);
1383 		}
1384 	}
1385 
1386 	NXGE_DEBUG_MSG((nxgep, RX_CTL,
1387 		"<== nxge_rxdma_get_rbr_ring_index: not found"));
1388 
1389 	return (-1);
1390 }
1391 
1392 p_rx_rbr_ring_t
1393 nxge_rxdma_get_rbr_ring(p_nxge_t nxgep, uint16_t channel)
1394 {
1395 	int			i, ndmas;
1396 	uint16_t		rdc;
1397 	p_rx_rbr_rings_t 	rx_rbr_rings;
1398 	p_rx_rbr_ring_t		*rbr_rings;
1399 
1400 	NXGE_DEBUG_MSG((nxgep, RX_CTL,
1401 		"==> nxge_rxdma_get_rbr_ring: channel %d", channel));
1402 
1403 	rx_rbr_rings = nxgep->rx_rbr_rings;
1404 	if (rx_rbr_rings == NULL) {
1405 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
1406 			"<== nxge_rxdma_get_rbr_ring: NULL ring pointer"));
1407 		return (NULL);
1408 	}
1409 	ndmas = rx_rbr_rings->ndmas;
1410 	if (!ndmas) {
1411 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
1412 			"<== nxge_rxdma_get_rbr_ring: no channel"));
1413 		return (NULL);
1414 	}
1415 
1416 	NXGE_DEBUG_MSG((nxgep, RX_CTL,
1417 		"==> nxge_rxdma_get_ring (ndmas %d)", ndmas));
1418 
1419 	rbr_rings = rx_rbr_rings->rbr_rings;
1420 	for (i = 0; i < ndmas; i++) {
1421 		rdc = rbr_rings[i]->rdc;
1422 		if (channel == rdc) {
1423 			NXGE_DEBUG_MSG((nxgep, RX_CTL,
1424 				"==> nxge_rxdma_get_rbr_ring: channel %d "
1425 				"ring $%p", channel, rbr_rings[i]));
1426 			return (rbr_rings[i]);
1427 		}
1428 	}
1429 
1430 	NXGE_DEBUG_MSG((nxgep, RX_CTL,
1431 		"<== nxge_rxdma_get_rbr_ring: not found"));
1432 
1433 	return (NULL);
1434 }
1435 
1436 p_rx_rcr_ring_t
1437 nxge_rxdma_get_rcr_ring(p_nxge_t nxgep, uint16_t channel)
1438 {
1439 	int			i, ndmas;
1440 	uint16_t		rdc;
1441 	p_rx_rcr_rings_t 	rx_rcr_rings;
1442 	p_rx_rcr_ring_t		*rcr_rings;
1443 
1444 	NXGE_DEBUG_MSG((nxgep, RX_CTL,
1445 		"==> nxge_rxdma_get_rcr_ring: channel %d", channel));
1446 
1447 	rx_rcr_rings = nxgep->rx_rcr_rings;
1448 	if (rx_rcr_rings == NULL) {
1449 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
1450 			"<== nxge_rxdma_get_rcr_ring: NULL ring pointer"));
1451 		return (NULL);
1452 	}
1453 	ndmas = rx_rcr_rings->ndmas;
1454 	if (!ndmas) {
1455 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
1456 			"<== nxge_rxdma_get_rcr_ring: no channel"));
1457 		return (NULL);
1458 	}
1459 
1460 	NXGE_DEBUG_MSG((nxgep, RX_CTL,
1461 		"==> nxge_rxdma_get_rcr_ring (ndmas %d)", ndmas));
1462 
1463 	rcr_rings = rx_rcr_rings->rcr_rings;
1464 	for (i = 0; i < ndmas; i++) {
1465 		rdc = rcr_rings[i]->rdc;
1466 		if (channel == rdc) {
1467 			NXGE_DEBUG_MSG((nxgep, RX_CTL,
1468 				"==> nxge_rxdma_get_rcr_ring: channel %d "
1469 				"ring $%p", channel, rcr_rings[i]));
1470 			return (rcr_rings[i]);
1471 		}
1472 	}
1473 
1474 	NXGE_DEBUG_MSG((nxgep, RX_CTL,
1475 		"<== nxge_rxdma_get_rcr_ring: not found"));
1476 
1477 	return (NULL);
1478 }
1479 
1480 /*
1481  * Static functions start here.
1482  */
1483 static p_rx_msg_t
1484 nxge_allocb(size_t size, uint32_t pri, p_nxge_dma_common_t dmabuf_p)
1485 {
1486 	p_rx_msg_t nxge_mp 		= NULL;
1487 	p_nxge_dma_common_t		dmamsg_p;
1488 	uchar_t 			*buffer;
1489 
1490 	nxge_mp = KMEM_ZALLOC(sizeof (rx_msg_t), KM_NOSLEEP);
1491 	if (nxge_mp == NULL) {
1492 		NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL,
1493 			"Allocation of a rx msg failed."));
1494 		goto nxge_allocb_exit;
1495 	}
1496 
1497 	nxge_mp->use_buf_pool = B_FALSE;
1498 	if (dmabuf_p) {
1499 		nxge_mp->use_buf_pool = B_TRUE;
1500 		dmamsg_p = (p_nxge_dma_common_t)&nxge_mp->buf_dma;
1501 		*dmamsg_p = *dmabuf_p;
1502 		dmamsg_p->nblocks = 1;
1503 		dmamsg_p->block_size = size;
1504 		dmamsg_p->alength = size;
1505 		buffer = (uchar_t *)dmabuf_p->kaddrp;
1506 
1507 		dmabuf_p->kaddrp = (void *)
1508 				((char *)dmabuf_p->kaddrp + size);
1509 		dmabuf_p->ioaddr_pp = (void *)
1510 				((char *)dmabuf_p->ioaddr_pp + size);
1511 		dmabuf_p->alength -= size;
1512 		dmabuf_p->offset += size;
1513 		dmabuf_p->dma_cookie.dmac_laddress += size;
1514 		dmabuf_p->dma_cookie.dmac_size -= size;
1515 
1516 	} else {
1517 		buffer = KMEM_ALLOC(size, KM_NOSLEEP);
1518 		if (buffer == NULL) {
1519 			NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL,
1520 				"Allocation of a receive page failed."));
1521 			goto nxge_allocb_fail1;
1522 		}
1523 	}
1524 
1525 	nxge_mp->rx_mblk_p = desballoc(buffer, size, pri, &nxge_mp->freeb);
1526 	if (nxge_mp->rx_mblk_p == NULL) {
1527 		NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL, "desballoc failed."));
1528 		goto nxge_allocb_fail2;
1529 	}
1530 
1531 	nxge_mp->buffer = buffer;
1532 	nxge_mp->block_size = size;
1533 	nxge_mp->freeb.free_func = (void (*)())nxge_freeb;
1534 	nxge_mp->freeb.free_arg = (caddr_t)nxge_mp;
1535 	nxge_mp->ref_cnt = 1;
1536 	nxge_mp->free = B_TRUE;
1537 	nxge_mp->rx_use_bcopy = B_FALSE;
1538 
1539 	atomic_inc_32(&nxge_mblks_pending);
1540 
1541 	goto nxge_allocb_exit;
1542 
1543 nxge_allocb_fail2:
1544 	if (!nxge_mp->use_buf_pool) {
1545 		KMEM_FREE(buffer, size);
1546 	}
1547 
1548 nxge_allocb_fail1:
1549 	KMEM_FREE(nxge_mp, sizeof (rx_msg_t));
1550 	nxge_mp = NULL;
1551 
1552 nxge_allocb_exit:
1553 	return (nxge_mp);
1554 }
1555 
1556 p_mblk_t
1557 nxge_dupb(p_rx_msg_t nxge_mp, uint_t offset, size_t size)
1558 {
1559 	p_mblk_t mp;
1560 
1561 	NXGE_DEBUG_MSG((NULL, MEM_CTL, "==> nxge_dupb"));
1562 	NXGE_DEBUG_MSG((NULL, MEM_CTL, "nxge_mp = $%p "
1563 		"offset = 0x%08X "
1564 		"size = 0x%08X",
1565 		nxge_mp, offset, size));
1566 
1567 	mp = desballoc(&nxge_mp->buffer[offset], size,
1568 				0, &nxge_mp->freeb);
1569 	if (mp == NULL) {
1570 		NXGE_DEBUG_MSG((NULL, RX_CTL, "desballoc failed"));
1571 		goto nxge_dupb_exit;
1572 	}
1573 	atomic_inc_32(&nxge_mp->ref_cnt);
1574 
1575 
1576 nxge_dupb_exit:
1577 	NXGE_DEBUG_MSG((NULL, MEM_CTL, "<== nxge_dupb mp = $%p",
1578 		nxge_mp));
1579 	return (mp);
1580 }
1581 
1582 p_mblk_t
1583 nxge_dupb_bcopy(p_rx_msg_t nxge_mp, uint_t offset, size_t size)
1584 {
1585 	p_mblk_t mp;
1586 	uchar_t *dp;
1587 
1588 	mp = allocb(size + NXGE_RXBUF_EXTRA, 0);
1589 	if (mp == NULL) {
1590 		NXGE_DEBUG_MSG((NULL, RX_CTL, "desballoc failed"));
1591 		goto nxge_dupb_bcopy_exit;
1592 	}
1593 	dp = mp->b_rptr = mp->b_rptr + NXGE_RXBUF_EXTRA;
1594 	bcopy((void *)&nxge_mp->buffer[offset], dp, size);
1595 	mp->b_wptr = dp + size;
1596 
1597 nxge_dupb_bcopy_exit:
1598 	NXGE_DEBUG_MSG((NULL, MEM_CTL, "<== nxge_dupb mp = $%p",
1599 		nxge_mp));
1600 	return (mp);
1601 }
1602 
1603 void nxge_post_page(p_nxge_t nxgep, p_rx_rbr_ring_t rx_rbr_p,
1604 	p_rx_msg_t rx_msg_p);
1605 
1606 void
1607 nxge_post_page(p_nxge_t nxgep, p_rx_rbr_ring_t rx_rbr_p, p_rx_msg_t rx_msg_p)
1608 {
1609 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_post_page"));
1610 
1611 	/* Reuse this buffer */
1612 	rx_msg_p->free = B_FALSE;
1613 	rx_msg_p->cur_usage_cnt = 0;
1614 	rx_msg_p->max_usage_cnt = 0;
1615 	rx_msg_p->pkt_buf_size = 0;
1616 
1617 	if (rx_rbr_p->rbr_use_bcopy) {
1618 		rx_msg_p->rx_use_bcopy = B_FALSE;
1619 		atomic_dec_32(&rx_rbr_p->rbr_consumed);
1620 	}
1621 
1622 	/*
1623 	 * Get the rbr header pointer and its offset index.
1624 	 */
1625 	MUTEX_ENTER(&rx_rbr_p->post_lock);
1626 	rx_rbr_p->rbr_wr_index =  ((rx_rbr_p->rbr_wr_index + 1) &
1627 					    rx_rbr_p->rbr_wrap_mask);
1628 	rx_rbr_p->rbr_desc_vp[rx_rbr_p->rbr_wr_index] = rx_msg_p->shifted_addr;
1629 	MUTEX_EXIT(&rx_rbr_p->post_lock);
1630 	npi_rxdma_rdc_rbr_kick(NXGE_DEV_NPI_HANDLE(nxgep),
1631 	    rx_rbr_p->rdc, 1);
1632 
1633 	NXGE_DEBUG_MSG((nxgep, RX_CTL,
1634 		"<== nxge_post_page (channel %d post_next_index %d)",
1635 		rx_rbr_p->rdc, rx_rbr_p->rbr_wr_index));
1636 
1637 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_post_page"));
1638 }
1639 
1640 void
1641 nxge_freeb(p_rx_msg_t rx_msg_p)
1642 {
1643 	size_t size;
1644 	uchar_t *buffer = NULL;
1645 	int ref_cnt;
1646 	boolean_t free_state = B_FALSE;
1647 
1648 	rx_rbr_ring_t *ring = rx_msg_p->rx_rbr_p;
1649 
1650 	NXGE_DEBUG_MSG((NULL, MEM2_CTL, "==> nxge_freeb"));
1651 	NXGE_DEBUG_MSG((NULL, MEM2_CTL,
1652 		"nxge_freeb:rx_msg_p = $%p (block pending %d)",
1653 		rx_msg_p, nxge_mblks_pending));
1654 
1655 	/*
1656 	 * First we need to get the free state, then
1657 	 * atomic decrement the reference count to prevent
1658 	 * the race condition with the interrupt thread that
1659 	 * is processing a loaned up buffer block.
1660 	 */
1661 	free_state = rx_msg_p->free;
1662 	ref_cnt = atomic_add_32_nv(&rx_msg_p->ref_cnt, -1);
1663 	if (!ref_cnt) {
1664 		atomic_dec_32(&nxge_mblks_pending);
1665 		buffer = rx_msg_p->buffer;
1666 		size = rx_msg_p->block_size;
1667 		NXGE_DEBUG_MSG((NULL, MEM2_CTL, "nxge_freeb: "
1668 			"will free: rx_msg_p = $%p (block pending %d)",
1669 			rx_msg_p, nxge_mblks_pending));
1670 
1671 		if (!rx_msg_p->use_buf_pool) {
1672 			KMEM_FREE(buffer, size);
1673 		}
1674 
1675 		KMEM_FREE(rx_msg_p, sizeof (rx_msg_t));
1676 
1677 		if (ring) {
1678 			/*
1679 			 * Decrement the receive buffer ring's reference
1680 			 * count, too.
1681 			 */
1682 			atomic_dec_32(&ring->rbr_ref_cnt);
1683 
1684 			/*
1685 			 * Free the receive buffer ring, iff
1686 			 * 1. all the receive buffers have been freed
1687 			 * 2. and we are in the proper state (that is,
1688 			 *    we are not UNMAPPING).
1689 			 */
1690 			if (ring->rbr_ref_cnt == 0 &&
1691 			    ring->rbr_state == RBR_UNMAPPED) {
1692 				KMEM_FREE(ring, sizeof (*ring));
1693 			}
1694 		}
1695 		return;
1696 	}
1697 
1698 	/*
1699 	 * Repost buffer.
1700 	 */
1701 	if (free_state && (ref_cnt == 1) && ring) {
1702 		NXGE_DEBUG_MSG((NULL, RX_CTL,
1703 		    "nxge_freeb: post page $%p:", rx_msg_p));
1704 		if (ring->rbr_state == RBR_POSTING)
1705 			nxge_post_page(rx_msg_p->nxgep, ring, rx_msg_p);
1706 	}
1707 
1708 	NXGE_DEBUG_MSG((NULL, MEM2_CTL, "<== nxge_freeb"));
1709 }
1710 
1711 uint_t
1712 nxge_rx_intr(void *arg1, void *arg2)
1713 {
1714 	p_nxge_ldv_t		ldvp = (p_nxge_ldv_t)arg1;
1715 	p_nxge_t		nxgep = (p_nxge_t)arg2;
1716 	p_nxge_ldg_t		ldgp;
1717 	uint8_t			channel;
1718 	npi_handle_t		handle;
1719 	rx_dma_ctl_stat_t	cs;
1720 
1721 #ifdef	NXGE_DEBUG
1722 	rxdma_cfig1_t		cfg;
1723 #endif
1724 	uint_t 			serviced = DDI_INTR_UNCLAIMED;
1725 
1726 	if (ldvp == NULL) {
1727 		NXGE_DEBUG_MSG((NULL, INT_CTL,
1728 			"<== nxge_rx_intr: arg2 $%p arg1 $%p",
1729 			nxgep, ldvp));
1730 
1731 		return (DDI_INTR_CLAIMED);
1732 	}
1733 
1734 	if (arg2 == NULL || (void *)ldvp->nxgep != arg2) {
1735 		nxgep = ldvp->nxgep;
1736 	}
1737 	NXGE_DEBUG_MSG((nxgep, RX_CTL,
1738 		"==> nxge_rx_intr: arg2 $%p arg1 $%p",
1739 		nxgep, ldvp));
1740 
1741 	/*
1742 	 * This interrupt handler is for a specific
1743 	 * receive dma channel.
1744 	 */
1745 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
1746 	/*
1747 	 * Get the control and status for this channel.
1748 	 */
1749 	channel = ldvp->channel;
1750 	ldgp = ldvp->ldgp;
1751 	RXDMA_REG_READ64(handle, RX_DMA_CTL_STAT_REG, channel, &cs.value);
1752 
1753 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rx_intr:channel %d "
1754 		"cs 0x%016llx rcrto 0x%x rcrthres %x",
1755 		channel,
1756 		cs.value,
1757 		cs.bits.hdw.rcrto,
1758 		cs.bits.hdw.rcrthres));
1759 
1760 	nxge_rx_pkts_vring(nxgep, ldvp->vdma_index, ldvp, cs);
1761 	serviced = DDI_INTR_CLAIMED;
1762 
1763 	/* error events. */
1764 	if (cs.value & RX_DMA_CTL_STAT_ERROR) {
1765 		(void) nxge_rx_err_evnts(nxgep, ldvp->vdma_index, ldvp, cs);
1766 	}
1767 
1768 nxge_intr_exit:
1769 
1770 
1771 	/*
1772 	 * Enable the mailbox update interrupt if we want
1773 	 * to use mailbox. We probably don't need to use
1774 	 * mailbox as it only saves us one pio read.
1775 	 * Also write 1 to rcrthres and rcrto to clear
1776 	 * these two edge triggered bits.
1777 	 */
1778 
1779 	cs.value &= RX_DMA_CTL_STAT_WR1C;
1780 	cs.bits.hdw.mex = 1;
1781 	RXDMA_REG_WRITE64(handle, RX_DMA_CTL_STAT_REG, channel,
1782 			cs.value);
1783 
1784 	/*
1785 	 * Rearm this logical group if this is a single device
1786 	 * group.
1787 	 */
1788 	if (ldgp->nldvs == 1) {
1789 		ldgimgm_t		mgm;
1790 		mgm.value = 0;
1791 		mgm.bits.ldw.arm = 1;
1792 		mgm.bits.ldw.timer = ldgp->ldg_timer;
1793 		NXGE_REG_WR64(handle,
1794 			    LDGIMGN_REG + LDSV_OFFSET(ldgp->ldg),
1795 			    mgm.value);
1796 	}
1797 
1798 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_rx_intr: serviced %d",
1799 		serviced));
1800 	return (serviced);
1801 }
1802 
1803 /*
1804  * Process the packets received in the specified logical device
1805  * and pass up a chain of message blocks to the upper layer.
1806  */
1807 static void
1808 nxge_rx_pkts_vring(p_nxge_t nxgep, uint_t vindex, p_nxge_ldv_t ldvp,
1809 				    rx_dma_ctl_stat_t cs)
1810 {
1811 	p_mblk_t		mp;
1812 	p_rx_rcr_ring_t		rcrp;
1813 
1814 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rx_pkts_vring"));
1815 	if ((mp = nxge_rx_pkts(nxgep, vindex, ldvp, &rcrp, cs)) == NULL) {
1816 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
1817 			"<== nxge_rx_pkts_vring: no mp"));
1818 		return;
1819 	}
1820 
1821 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rx_pkts_vring: $%p",
1822 		mp));
1823 
1824 #ifdef  NXGE_DEBUG
1825 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
1826 			"==> nxge_rx_pkts_vring:calling mac_rx "
1827 			"LEN %d mp $%p mp->b_cont $%p mp->b_next $%p rcrp $%p "
1828 			"mac_handle $%p",
1829 			mp->b_wptr - mp->b_rptr,
1830 			mp, mp->b_cont, mp->b_next,
1831 			rcrp, rcrp->rcr_mac_handle));
1832 
1833 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
1834 			"==> nxge_rx_pkts_vring: dump packets "
1835 			"(mp $%p b_rptr $%p b_wptr $%p):\n %s",
1836 			mp,
1837 			mp->b_rptr,
1838 			mp->b_wptr,
1839 			nxge_dump_packet((char *)mp->b_rptr,
1840 			mp->b_wptr - mp->b_rptr)));
1841 		if (mp->b_cont) {
1842 			NXGE_DEBUG_MSG((nxgep, RX_CTL,
1843 				"==> nxge_rx_pkts_vring: dump b_cont packets "
1844 				"(mp->b_cont $%p b_rptr $%p b_wptr $%p):\n %s",
1845 				mp->b_cont,
1846 				mp->b_cont->b_rptr,
1847 				mp->b_cont->b_wptr,
1848 				nxge_dump_packet((char *)mp->b_cont->b_rptr,
1849 				mp->b_cont->b_wptr - mp->b_cont->b_rptr)));
1850 		}
1851 		if (mp->b_next) {
1852 			NXGE_DEBUG_MSG((nxgep, RX_CTL,
1853 				"==> nxge_rx_pkts_vring: dump next packets "
1854 				"(b_rptr $%p): %s",
1855 				mp->b_next->b_rptr,
1856 				nxge_dump_packet((char *)mp->b_next->b_rptr,
1857 				mp->b_next->b_wptr - mp->b_next->b_rptr)));
1858 		}
1859 #endif
1860 
1861 	mac_rx(nxgep->mach, rcrp->rcr_mac_handle, mp);
1862 }
1863 
1864 
1865 /*
1866  * This routine is the main packet receive processing function.
1867  * It gets the packet type, error code, and buffer related
1868  * information from the receive completion entry.
1869  * How many completion entries to process is based on the number of packets
1870  * queued by the hardware, a hardware maintained tail pointer
1871  * and a configurable receive packet count.
1872  *
1873  * A chain of message blocks will be created as result of processing
1874  * the completion entries. This chain of message blocks will be returned and
1875  * a hardware control status register will be updated with the number of
1876  * packets were removed from the hardware queue.
1877  *
1878  */
1879 mblk_t *
1880 nxge_rx_pkts(p_nxge_t nxgep, uint_t vindex, p_nxge_ldv_t ldvp,
1881     p_rx_rcr_ring_t *rcrp, rx_dma_ctl_stat_t cs)
1882 {
1883 	npi_handle_t		handle;
1884 	uint8_t			channel;
1885 	p_rx_rcr_rings_t	rx_rcr_rings;
1886 	p_rx_rcr_ring_t		rcr_p;
1887 	uint32_t		comp_rd_index;
1888 	p_rcr_entry_t		rcr_desc_rd_head_p;
1889 	p_rcr_entry_t		rcr_desc_rd_head_pp;
1890 	p_mblk_t		nmp, mp_cont, head_mp, *tail_mp;
1891 	uint16_t		qlen, nrcr_read, npkt_read;
1892 	uint32_t qlen_hw;
1893 	boolean_t		multi;
1894 	rcrcfig_b_t rcr_cfg_b;
1895 #if defined(_BIG_ENDIAN)
1896 	npi_status_t		rs = NPI_SUCCESS;
1897 #endif
1898 
1899 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rx_pkts:vindex %d "
1900 		"channel %d", vindex, ldvp->channel));
1901 
1902 	if (!(nxgep->drv_state & STATE_HW_INITIALIZED)) {
1903 		return (NULL);
1904 	}
1905 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
1906 	rx_rcr_rings = nxgep->rx_rcr_rings;
1907 	rcr_p = rx_rcr_rings->rcr_rings[vindex];
1908 	channel = rcr_p->rdc;
1909 	if (channel != ldvp->channel) {
1910 		NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rx_pkts:index %d "
1911 			"channel %d, and rcr channel %d not matched.",
1912 			vindex, ldvp->channel, channel));
1913 		return (NULL);
1914 	}
1915 
1916 	NXGE_DEBUG_MSG((nxgep, RX_CTL,
1917 		"==> nxge_rx_pkts: START: rcr channel %d "
1918 		"head_p $%p head_pp $%p  index %d ",
1919 		channel, rcr_p->rcr_desc_rd_head_p,
1920 		rcr_p->rcr_desc_rd_head_pp,
1921 		rcr_p->comp_rd_index));
1922 
1923 
1924 #if !defined(_BIG_ENDIAN)
1925 	qlen = RXDMA_REG_READ32(handle, RCRSTAT_A_REG, channel) & 0xffff;
1926 #else
1927 	rs = npi_rxdma_rdc_rcr_qlen_get(handle, channel, &qlen);
1928 	if (rs != NPI_SUCCESS) {
1929 		NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rx_pkts:index %d "
1930 		"channel %d, get qlen failed 0x%08x",
1931 		vindex, ldvp->channel, rs));
1932 		return (NULL);
1933 	}
1934 #endif
1935 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rx_pkts:rcr channel %d "
1936 		"qlen %d", channel, qlen));
1937 
1938 
1939 
1940 	if (!qlen) {
1941 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
1942 			"==> nxge_rx_pkts:rcr channel %d "
1943 			"qlen %d (no pkts)", channel, qlen));
1944 
1945 		return (NULL);
1946 	}
1947 
1948 	comp_rd_index = rcr_p->comp_rd_index;
1949 
1950 	rcr_desc_rd_head_p = rcr_p->rcr_desc_rd_head_p;
1951 	rcr_desc_rd_head_pp = rcr_p->rcr_desc_rd_head_pp;
1952 	nrcr_read = npkt_read = 0;
1953 
1954 	/*
1955 	 * Number of packets queued
1956 	 * (The jumbo or multi packet will be counted as only one
1957 	 *  packets and it may take up more than one completion entry).
1958 	 */
1959 	qlen_hw = (qlen < nxge_max_rx_pkts) ?
1960 		qlen : nxge_max_rx_pkts;
1961 	head_mp = NULL;
1962 	tail_mp = &head_mp;
1963 	nmp = mp_cont = NULL;
1964 	multi = B_FALSE;
1965 
1966 	while (qlen_hw) {
1967 
1968 #ifdef NXGE_DEBUG
1969 		nxge_dump_rcr_entry(nxgep, rcr_desc_rd_head_p);
1970 #endif
1971 		/*
1972 		 * Process one completion ring entry.
1973 		 */
1974 		nxge_receive_packet(nxgep,
1975 			rcr_p, rcr_desc_rd_head_p, &multi, &nmp, &mp_cont);
1976 
1977 		/*
1978 		 * message chaining modes
1979 		 */
1980 		if (nmp) {
1981 			nmp->b_next = NULL;
1982 			if (!multi && !mp_cont) { /* frame fits a partition */
1983 				*tail_mp = nmp;
1984 				tail_mp = &nmp->b_next;
1985 				nmp = NULL;
1986 			} else if (multi && !mp_cont) { /* first segment */
1987 				*tail_mp = nmp;
1988 				tail_mp = &nmp->b_cont;
1989 			} else if (multi && mp_cont) {	/* mid of multi segs */
1990 				*tail_mp = mp_cont;
1991 				tail_mp = &mp_cont->b_cont;
1992 			} else if (!multi && mp_cont) { /* last segment */
1993 				*tail_mp = mp_cont;
1994 				tail_mp = &nmp->b_next;
1995 				nmp = NULL;
1996 			}
1997 		}
1998 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
1999 			"==> nxge_rx_pkts: loop: rcr channel %d "
2000 			"before updating: multi %d "
2001 			"nrcr_read %d "
2002 			"npk read %d "
2003 			"head_pp $%p  index %d ",
2004 			channel,
2005 			multi,
2006 			nrcr_read, npkt_read, rcr_desc_rd_head_pp,
2007 			comp_rd_index));
2008 
2009 		if (!multi) {
2010 			qlen_hw--;
2011 			npkt_read++;
2012 		}
2013 
2014 		/*
2015 		 * Update the next read entry.
2016 		 */
2017 		comp_rd_index = NEXT_ENTRY(comp_rd_index,
2018 					rcr_p->comp_wrap_mask);
2019 
2020 		rcr_desc_rd_head_p = NEXT_ENTRY_PTR(rcr_desc_rd_head_p,
2021 				rcr_p->rcr_desc_first_p,
2022 				rcr_p->rcr_desc_last_p);
2023 
2024 		nrcr_read++;
2025 
2026 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
2027 			"<== nxge_rx_pkts: (SAM, process one packet) "
2028 			"nrcr_read %d",
2029 			nrcr_read));
2030 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
2031 			"==> nxge_rx_pkts: loop: rcr channel %d "
2032 			"multi %d "
2033 			"nrcr_read %d "
2034 			"npk read %d "
2035 			"head_pp $%p  index %d ",
2036 			channel,
2037 			multi,
2038 			nrcr_read, npkt_read, rcr_desc_rd_head_pp,
2039 			comp_rd_index));
2040 
2041 	}
2042 
2043 	rcr_p->rcr_desc_rd_head_pp = rcr_desc_rd_head_pp;
2044 	rcr_p->comp_rd_index = comp_rd_index;
2045 	rcr_p->rcr_desc_rd_head_p = rcr_desc_rd_head_p;
2046 
2047 	if ((nxgep->intr_timeout != rcr_p->intr_timeout) ||
2048 		(nxgep->intr_threshold != rcr_p->intr_threshold)) {
2049 		rcr_p->intr_timeout = nxgep->intr_timeout;
2050 		rcr_p->intr_threshold = nxgep->intr_threshold;
2051 		rcr_cfg_b.value = 0x0ULL;
2052 		if (rcr_p->intr_timeout)
2053 			rcr_cfg_b.bits.ldw.entout = 1;
2054 		rcr_cfg_b.bits.ldw.timeout = rcr_p->intr_timeout;
2055 		rcr_cfg_b.bits.ldw.pthres = rcr_p->intr_threshold;
2056 		RXDMA_REG_WRITE64(handle, RCRCFIG_B_REG,
2057 				    channel, rcr_cfg_b.value);
2058 	}
2059 
2060 	cs.bits.ldw.pktread = npkt_read;
2061 	cs.bits.ldw.ptrread = nrcr_read;
2062 	RXDMA_REG_WRITE64(handle, RX_DMA_CTL_STAT_REG,
2063 			    channel, cs.value);
2064 	NXGE_DEBUG_MSG((nxgep, RX_CTL,
2065 		"==> nxge_rx_pkts: EXIT: rcr channel %d "
2066 		"head_pp $%p  index %016llx ",
2067 		channel,
2068 		rcr_p->rcr_desc_rd_head_pp,
2069 		rcr_p->comp_rd_index));
2070 	/*
2071 	 * Update RCR buffer pointer read and number of packets
2072 	 * read.
2073 	 */
2074 
2075 	*rcrp = rcr_p;
2076 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_rx_pkts"));
2077 	return (head_mp);
2078 }
2079 
2080 void
2081 nxge_receive_packet(p_nxge_t nxgep,
2082     p_rx_rcr_ring_t rcr_p, p_rcr_entry_t rcr_desc_rd_head_p,
2083     boolean_t *multi_p, mblk_t **mp, mblk_t **mp_cont)
2084 {
2085 	p_mblk_t		nmp = NULL;
2086 	uint64_t		multi;
2087 	uint64_t		dcf_err;
2088 	uint8_t			channel;
2089 
2090 	boolean_t		first_entry = B_TRUE;
2091 	boolean_t		is_tcp_udp = B_FALSE;
2092 	boolean_t		buffer_free = B_FALSE;
2093 	boolean_t		error_send_up = B_FALSE;
2094 	uint8_t			error_type;
2095 	uint16_t		l2_len;
2096 	uint16_t		skip_len;
2097 	uint8_t			pktbufsz_type;
2098 	uint64_t		rcr_entry;
2099 	uint64_t		*pkt_buf_addr_pp;
2100 	uint64_t		*pkt_buf_addr_p;
2101 	uint32_t		buf_offset;
2102 	uint32_t		bsize;
2103 	uint32_t		error_disp_cnt;
2104 	uint32_t		msg_index;
2105 	p_rx_rbr_ring_t		rx_rbr_p;
2106 	p_rx_msg_t 		*rx_msg_ring_p;
2107 	p_rx_msg_t		rx_msg_p;
2108 	uint16_t		sw_offset_bytes = 0, hdr_size = 0;
2109 	nxge_status_t		status = NXGE_OK;
2110 	boolean_t		is_valid = B_FALSE;
2111 	p_nxge_rx_ring_stats_t	rdc_stats;
2112 	uint32_t		bytes_read;
2113 	uint64_t		pkt_type;
2114 	uint64_t		frag;
2115 #ifdef	NXGE_DEBUG
2116 	int			dump_len;
2117 #endif
2118 	NXGE_DEBUG_MSG((nxgep, RX2_CTL, "==> nxge_receive_packet"));
2119 	first_entry = (*mp == NULL) ? B_TRUE : B_FALSE;
2120 
2121 	rcr_entry = *((uint64_t *)rcr_desc_rd_head_p);
2122 
2123 	multi = (rcr_entry & RCR_MULTI_MASK);
2124 	dcf_err = (rcr_entry & RCR_DCF_ERROR_MASK);
2125 	pkt_type = (rcr_entry & RCR_PKT_TYPE_MASK);
2126 
2127 	error_type = ((rcr_entry & RCR_ERROR_MASK) >> RCR_ERROR_SHIFT);
2128 	frag = (rcr_entry & RCR_FRAG_MASK);
2129 
2130 	l2_len = ((rcr_entry & RCR_L2_LEN_MASK) >> RCR_L2_LEN_SHIFT);
2131 
2132 	pktbufsz_type = ((rcr_entry & RCR_PKTBUFSZ_MASK) >>
2133 				RCR_PKTBUFSZ_SHIFT);
2134 #if defined(__i386)
2135 	pkt_buf_addr_pp = (uint64_t *)(uint32_t)((rcr_entry &
2136 			RCR_PKT_BUF_ADDR_MASK) << RCR_PKT_BUF_ADDR_SHIFT);
2137 #else
2138 	pkt_buf_addr_pp = (uint64_t *)((rcr_entry & RCR_PKT_BUF_ADDR_MASK) <<
2139 			RCR_PKT_BUF_ADDR_SHIFT);
2140 #endif
2141 
2142 	channel = rcr_p->rdc;
2143 
2144 	NXGE_DEBUG_MSG((nxgep, RX2_CTL,
2145 		"==> nxge_receive_packet: entryp $%p entry 0x%0llx "
2146 		"pkt_buf_addr_pp $%p l2_len %d multi 0x%llx "
2147 		"error_type 0x%x pkt_type 0x%x  "
2148 		"pktbufsz_type %d ",
2149 		rcr_desc_rd_head_p,
2150 		rcr_entry, pkt_buf_addr_pp, l2_len,
2151 		multi,
2152 		error_type,
2153 		pkt_type,
2154 		pktbufsz_type));
2155 
2156 	NXGE_DEBUG_MSG((nxgep, RX2_CTL,
2157 		"==> nxge_receive_packet: entryp $%p entry 0x%0llx "
2158 		"pkt_buf_addr_pp $%p l2_len %d multi 0x%llx "
2159 		"error_type 0x%x pkt_type 0x%x ", rcr_desc_rd_head_p,
2160 		rcr_entry, pkt_buf_addr_pp, l2_len,
2161 		multi,
2162 		error_type,
2163 		pkt_type));
2164 
2165 	NXGE_DEBUG_MSG((nxgep, RX2_CTL,
2166 		"==> (rbr) nxge_receive_packet: entry 0x%0llx "
2167 		"full pkt_buf_addr_pp $%p l2_len %d",
2168 		rcr_entry, pkt_buf_addr_pp, l2_len));
2169 
2170 	/* get the stats ptr */
2171 	rdc_stats = rcr_p->rdc_stats;
2172 
2173 	if (!l2_len) {
2174 
2175 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
2176 			"<== nxge_receive_packet: failed: l2 length is 0."));
2177 		return;
2178 	}
2179 
2180 	/* Hardware sends us 4 bytes of CRC as no stripping is done.  */
2181 	l2_len -= ETHERFCSL;
2182 
2183 	/* shift 6 bits to get the full io address */
2184 #if defined(__i386)
2185 	pkt_buf_addr_pp = (uint64_t *)((uint32_t)pkt_buf_addr_pp <<
2186 				RCR_PKT_BUF_ADDR_SHIFT_FULL);
2187 #else
2188 	pkt_buf_addr_pp = (uint64_t *)((uint64_t)pkt_buf_addr_pp <<
2189 				RCR_PKT_BUF_ADDR_SHIFT_FULL);
2190 #endif
2191 	NXGE_DEBUG_MSG((nxgep, RX2_CTL,
2192 		"==> (rbr) nxge_receive_packet: entry 0x%0llx "
2193 		"full pkt_buf_addr_pp $%p l2_len %d",
2194 		rcr_entry, pkt_buf_addr_pp, l2_len));
2195 
2196 	rx_rbr_p = rcr_p->rx_rbr_p;
2197 	rx_msg_ring_p = rx_rbr_p->rx_msg_ring;
2198 
2199 	if (first_entry) {
2200 		hdr_size = (rcr_p->full_hdr_flag ? RXDMA_HDR_SIZE_FULL :
2201 			RXDMA_HDR_SIZE_DEFAULT);
2202 
2203 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
2204 			"==> nxge_receive_packet: first entry 0x%016llx "
2205 			"pkt_buf_addr_pp $%p l2_len %d hdr %d",
2206 			rcr_entry, pkt_buf_addr_pp, l2_len,
2207 			hdr_size));
2208 	}
2209 
2210 	MUTEX_ENTER(&rcr_p->lock);
2211 	MUTEX_ENTER(&rx_rbr_p->lock);
2212 
2213 	NXGE_DEBUG_MSG((nxgep, RX_CTL,
2214 		"==> (rbr 1) nxge_receive_packet: entry 0x%0llx "
2215 		"full pkt_buf_addr_pp $%p l2_len %d",
2216 		rcr_entry, pkt_buf_addr_pp, l2_len));
2217 
2218 	/*
2219 	 * Packet buffer address in the completion entry points
2220 	 * to the starting buffer address (offset 0).
2221 	 * Use the starting buffer address to locate the corresponding
2222 	 * kernel address.
2223 	 */
2224 	status = nxge_rxbuf_pp_to_vp(nxgep, rx_rbr_p,
2225 			pktbufsz_type, pkt_buf_addr_pp, &pkt_buf_addr_p,
2226 			&buf_offset,
2227 			&msg_index);
2228 
2229 	NXGE_DEBUG_MSG((nxgep, RX_CTL,
2230 		"==> (rbr 2) nxge_receive_packet: entry 0x%0llx "
2231 		"full pkt_buf_addr_pp $%p l2_len %d",
2232 		rcr_entry, pkt_buf_addr_pp, l2_len));
2233 
2234 	if (status != NXGE_OK) {
2235 		MUTEX_EXIT(&rx_rbr_p->lock);
2236 		MUTEX_EXIT(&rcr_p->lock);
2237 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
2238 			"<== nxge_receive_packet: found vaddr failed %d",
2239 				status));
2240 		return;
2241 	}
2242 
2243 	NXGE_DEBUG_MSG((nxgep, RX2_CTL,
2244 		"==> (rbr 3) nxge_receive_packet: entry 0x%0llx "
2245 		"full pkt_buf_addr_pp $%p l2_len %d",
2246 		rcr_entry, pkt_buf_addr_pp, l2_len));
2247 
2248 	NXGE_DEBUG_MSG((nxgep, RX2_CTL,
2249 		"==> (rbr 4 msgindex %d) nxge_receive_packet: entry 0x%0llx "
2250 		"full pkt_buf_addr_pp $%p l2_len %d",
2251 		msg_index, rcr_entry, pkt_buf_addr_pp, l2_len));
2252 
2253 	rx_msg_p = rx_msg_ring_p[msg_index];
2254 
2255 	NXGE_DEBUG_MSG((nxgep, RX2_CTL,
2256 		"==> (rbr 4 msgindex %d) nxge_receive_packet: entry 0x%0llx "
2257 		"full pkt_buf_addr_pp $%p l2_len %d",
2258 		msg_index, rcr_entry, pkt_buf_addr_pp, l2_len));
2259 
2260 	switch (pktbufsz_type) {
2261 	case RCR_PKTBUFSZ_0:
2262 		bsize = rx_rbr_p->pkt_buf_size0_bytes;
2263 		NXGE_DEBUG_MSG((nxgep, RX2_CTL,
2264 			"==> nxge_receive_packet: 0 buf %d", bsize));
2265 		break;
2266 	case RCR_PKTBUFSZ_1:
2267 		bsize = rx_rbr_p->pkt_buf_size1_bytes;
2268 		NXGE_DEBUG_MSG((nxgep, RX2_CTL,
2269 			"==> nxge_receive_packet: 1 buf %d", bsize));
2270 		break;
2271 	case RCR_PKTBUFSZ_2:
2272 		bsize = rx_rbr_p->pkt_buf_size2_bytes;
2273 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
2274 			"==> nxge_receive_packet: 2 buf %d", bsize));
2275 		break;
2276 	case RCR_SINGLE_BLOCK:
2277 		bsize = rx_msg_p->block_size;
2278 		NXGE_DEBUG_MSG((nxgep, RX2_CTL,
2279 			"==> nxge_receive_packet: single %d", bsize));
2280 
2281 		break;
2282 	default:
2283 		MUTEX_EXIT(&rx_rbr_p->lock);
2284 		MUTEX_EXIT(&rcr_p->lock);
2285 		return;
2286 	}
2287 
2288 	DMA_COMMON_SYNC_OFFSET(rx_msg_p->buf_dma,
2289 		(buf_offset + sw_offset_bytes),
2290 		(hdr_size + l2_len),
2291 		DDI_DMA_SYNC_FORCPU);
2292 
2293 	NXGE_DEBUG_MSG((nxgep, RX2_CTL,
2294 		"==> nxge_receive_packet: after first dump:usage count"));
2295 
2296 	if (rx_msg_p->cur_usage_cnt == 0) {
2297 		if (rx_rbr_p->rbr_use_bcopy) {
2298 			atomic_inc_32(&rx_rbr_p->rbr_consumed);
2299 			if (rx_rbr_p->rbr_consumed <
2300 					rx_rbr_p->rbr_threshold_hi) {
2301 				if (rx_rbr_p->rbr_threshold_lo == 0 ||
2302 					((rx_rbr_p->rbr_consumed >=
2303 						rx_rbr_p->rbr_threshold_lo) &&
2304 						(rx_rbr_p->rbr_bufsize_type >=
2305 							pktbufsz_type))) {
2306 					rx_msg_p->rx_use_bcopy = B_TRUE;
2307 				}
2308 			} else {
2309 				rx_msg_p->rx_use_bcopy = B_TRUE;
2310 			}
2311 		}
2312 		NXGE_DEBUG_MSG((nxgep, RX2_CTL,
2313 			"==> nxge_receive_packet: buf %d (new block) ",
2314 			bsize));
2315 
2316 		rx_msg_p->pkt_buf_size_code = pktbufsz_type;
2317 		rx_msg_p->pkt_buf_size = bsize;
2318 		rx_msg_p->cur_usage_cnt = 1;
2319 		if (pktbufsz_type == RCR_SINGLE_BLOCK) {
2320 			NXGE_DEBUG_MSG((nxgep, RX2_CTL,
2321 				"==> nxge_receive_packet: buf %d "
2322 				"(single block) ",
2323 				bsize));
2324 			/*
2325 			 * Buffer can be reused once the free function
2326 			 * is called.
2327 			 */
2328 			rx_msg_p->max_usage_cnt = 1;
2329 			buffer_free = B_TRUE;
2330 		} else {
2331 			rx_msg_p->max_usage_cnt = rx_msg_p->block_size/bsize;
2332 			if (rx_msg_p->max_usage_cnt == 1) {
2333 				buffer_free = B_TRUE;
2334 			}
2335 		}
2336 	} else {
2337 		rx_msg_p->cur_usage_cnt++;
2338 		if (rx_msg_p->cur_usage_cnt == rx_msg_p->max_usage_cnt) {
2339 			buffer_free = B_TRUE;
2340 		}
2341 	}
2342 
2343 	NXGE_DEBUG_MSG((nxgep, RX_CTL,
2344 	    "msgbuf index = %d l2len %d bytes usage %d max_usage %d ",
2345 		msg_index, l2_len,
2346 		rx_msg_p->cur_usage_cnt, rx_msg_p->max_usage_cnt));
2347 
2348 	if ((error_type) || (dcf_err)) {
2349 		rdc_stats->ierrors++;
2350 		if (dcf_err) {
2351 			rdc_stats->dcf_err++;
2352 #ifdef	NXGE_DEBUG
2353 			if (!rdc_stats->dcf_err) {
2354 				NXGE_DEBUG_MSG((nxgep, RX_CTL,
2355 				"nxge_receive_packet: channel %d dcf_err rcr"
2356 				" 0x%llx", channel, rcr_entry));
2357 			}
2358 #endif
2359 			NXGE_FM_REPORT_ERROR(nxgep, nxgep->mac.portnum, NULL,
2360 					NXGE_FM_EREPORT_RDMC_DCF_ERR);
2361 		} else {
2362 				/* Update error stats */
2363 			error_disp_cnt = NXGE_ERROR_SHOW_MAX;
2364 			rdc_stats->errlog.compl_err_type = error_type;
2365 
2366 			switch (error_type) {
2367 			/*
2368 			 * Do not send FMA ereport for RCR_L2_ERROR and
2369 			 * RCR_L4_CSUM_ERROR because most likely they indicate
2370 			 * back pressure rather than HW failures.
2371 			 */
2372 			case RCR_L2_ERROR:
2373 				rdc_stats->l2_err++;
2374 				if (rdc_stats->l2_err <
2375 				    error_disp_cnt) {
2376 					NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
2377 					    " nxge_receive_packet:"
2378 					    " channel %d RCR L2_ERROR",
2379 					    channel));
2380 				}
2381 				break;
2382 			case RCR_L4_CSUM_ERROR:
2383 				error_send_up = B_TRUE;
2384 				rdc_stats->l4_cksum_err++;
2385 				if (rdc_stats->l4_cksum_err <
2386 				    error_disp_cnt) {
2387 					NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
2388 					    " nxge_receive_packet:"
2389 					    " channel %d"
2390 					    " RCR L4_CSUM_ERROR", channel));
2391 				}
2392 				break;
2393 			/*
2394 			 * Do not send FMA ereport for RCR_FFLP_SOFT_ERROR and
2395 			 * RCR_ZCP_SOFT_ERROR because they reflect the same
2396 			 * FFLP and ZCP errors that have been reported by
2397 			 * nxge_fflp.c and nxge_zcp.c.
2398 			 */
2399 			case RCR_FFLP_SOFT_ERROR:
2400 				error_send_up = B_TRUE;
2401 				rdc_stats->fflp_soft_err++;
2402 				if (rdc_stats->fflp_soft_err <
2403 				    error_disp_cnt) {
2404 					NXGE_ERROR_MSG((nxgep,
2405 					    NXGE_ERR_CTL,
2406 					    " nxge_receive_packet:"
2407 					    " channel %d"
2408 					    " RCR FFLP_SOFT_ERROR", channel));
2409 				}
2410 				break;
2411 			case RCR_ZCP_SOFT_ERROR:
2412 				error_send_up = B_TRUE;
2413 				rdc_stats->fflp_soft_err++;
2414 				if (rdc_stats->zcp_soft_err <
2415 				    error_disp_cnt)
2416 					NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
2417 					    " nxge_receive_packet: Channel %d"
2418 					    " RCR ZCP_SOFT_ERROR", channel));
2419 				break;
2420 			default:
2421 				rdc_stats->rcr_unknown_err++;
2422 				if (rdc_stats->rcr_unknown_err
2423 				    < error_disp_cnt) {
2424 					NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
2425 					    " nxge_receive_packet: Channel %d"
2426 					    " RCR entry 0x%llx error 0x%x",
2427 					    rcr_entry, channel, error_type));
2428 				}
2429 				break;
2430 			}
2431 		}
2432 
2433 		/*
2434 		 * Update and repost buffer block if max usage
2435 		 * count is reached.
2436 		 */
2437 		if (error_send_up == B_FALSE) {
2438 			atomic_inc_32(&rx_msg_p->ref_cnt);
2439 			if (buffer_free == B_TRUE) {
2440 				rx_msg_p->free = B_TRUE;
2441 			}
2442 
2443 			MUTEX_EXIT(&rx_rbr_p->lock);
2444 			MUTEX_EXIT(&rcr_p->lock);
2445 			nxge_freeb(rx_msg_p);
2446 			return;
2447 		}
2448 	}
2449 
2450 	NXGE_DEBUG_MSG((nxgep, RX2_CTL,
2451 		"==> nxge_receive_packet: DMA sync second "));
2452 
2453 	bytes_read = rcr_p->rcvd_pkt_bytes;
2454 	skip_len = sw_offset_bytes + hdr_size;
2455 	if (!rx_msg_p->rx_use_bcopy) {
2456 		/*
2457 		 * For loaned up buffers, the driver reference count
2458 		 * will be incremented first and then the free state.
2459 		 */
2460 		if ((nmp = nxge_dupb(rx_msg_p, buf_offset, bsize)) != NULL) {
2461 			if (first_entry) {
2462 				nmp->b_rptr = &nmp->b_rptr[skip_len];
2463 				if (l2_len < bsize - skip_len) {
2464 					nmp->b_wptr = &nmp->b_rptr[l2_len];
2465 				} else {
2466 					nmp->b_wptr = &nmp->b_rptr[bsize
2467 					    - skip_len];
2468 				}
2469 			} else {
2470 				if (l2_len - bytes_read < bsize) {
2471 					nmp->b_wptr =
2472 					    &nmp->b_rptr[l2_len - bytes_read];
2473 				} else {
2474 					nmp->b_wptr = &nmp->b_rptr[bsize];
2475 				}
2476 			}
2477 		}
2478 	} else {
2479 		if (first_entry) {
2480 			nmp = nxge_dupb_bcopy(rx_msg_p, buf_offset + skip_len,
2481 			    l2_len < bsize - skip_len ?
2482 			    l2_len : bsize - skip_len);
2483 		} else {
2484 			nmp = nxge_dupb_bcopy(rx_msg_p, buf_offset,
2485 			    l2_len - bytes_read < bsize ?
2486 			    l2_len - bytes_read : bsize);
2487 		}
2488 	}
2489 	if (nmp != NULL) {
2490 		if (first_entry)
2491 			bytes_read  = nmp->b_wptr - nmp->b_rptr;
2492 		else
2493 			bytes_read += nmp->b_wptr - nmp->b_rptr;
2494 
2495 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
2496 		    "==> nxge_receive_packet after dupb: "
2497 		    "rbr consumed %d "
2498 		    "pktbufsz_type %d "
2499 		    "nmp $%p rptr $%p wptr $%p "
2500 		    "buf_offset %d bzise %d l2_len %d skip_len %d",
2501 		    rx_rbr_p->rbr_consumed,
2502 		    pktbufsz_type,
2503 		    nmp, nmp->b_rptr, nmp->b_wptr,
2504 		    buf_offset, bsize, l2_len, skip_len));
2505 	} else {
2506 		cmn_err(CE_WARN, "!nxge_receive_packet: "
2507 			"update stats (error)");
2508 		atomic_inc_32(&rx_msg_p->ref_cnt);
2509 		if (buffer_free == B_TRUE) {
2510 			rx_msg_p->free = B_TRUE;
2511 		}
2512 		MUTEX_EXIT(&rx_rbr_p->lock);
2513 		MUTEX_EXIT(&rcr_p->lock);
2514 		nxge_freeb(rx_msg_p);
2515 		return;
2516 	}
2517 
2518 	if (buffer_free == B_TRUE) {
2519 		rx_msg_p->free = B_TRUE;
2520 	}
2521 	/*
2522 	 * ERROR, FRAG and PKT_TYPE are only reported
2523 	 * in the first entry.
2524 	 * If a packet is not fragmented and no error bit is set, then
2525 	 * L4 checksum is OK.
2526 	 */
2527 	is_valid = (nmp != NULL);
2528 	if (first_entry) {
2529 		rdc_stats->ipackets++; /* count only 1st seg for jumbo */
2530 		rdc_stats->ibytes += skip_len + l2_len < bsize ?
2531 		    l2_len : bsize;
2532 	} else {
2533 		rdc_stats->ibytes += l2_len - bytes_read < bsize ?
2534 		    l2_len - bytes_read : bsize;
2535 	}
2536 
2537 	rcr_p->rcvd_pkt_bytes = bytes_read;
2538 
2539 	MUTEX_EXIT(&rx_rbr_p->lock);
2540 	MUTEX_EXIT(&rcr_p->lock);
2541 
2542 	if (rx_msg_p->free && rx_msg_p->rx_use_bcopy) {
2543 		atomic_inc_32(&rx_msg_p->ref_cnt);
2544 		nxge_freeb(rx_msg_p);
2545 	}
2546 
2547 	if (is_valid) {
2548 		nmp->b_cont = NULL;
2549 		if (first_entry) {
2550 			*mp = nmp;
2551 			*mp_cont = NULL;
2552 		} else {
2553 			*mp_cont = nmp;
2554 		}
2555 	}
2556 
2557 	/*
2558 	 * Update stats and hardware checksuming.
2559 	 */
2560 	if (is_valid && !multi) {
2561 
2562 		is_tcp_udp = ((pkt_type == RCR_PKT_IS_TCP ||
2563 				pkt_type == RCR_PKT_IS_UDP) ?
2564 					B_TRUE: B_FALSE);
2565 
2566 		NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_receive_packet: "
2567 			"is_valid 0x%x multi 0x%llx pkt %d frag %d error %d",
2568 			is_valid, multi, is_tcp_udp, frag, error_type));
2569 
2570 		if (is_tcp_udp && !frag && !error_type) {
2571 			(void) hcksum_assoc(nmp, NULL, NULL, 0, 0, 0, 0,
2572 				HCK_FULLCKSUM_OK | HCK_FULLCKSUM, 0);
2573 			NXGE_DEBUG_MSG((nxgep, RX_CTL,
2574 				"==> nxge_receive_packet: Full tcp/udp cksum "
2575 				"is_valid 0x%x multi 0x%llx pkt %d frag %d "
2576 				"error %d",
2577 				is_valid, multi, is_tcp_udp, frag, error_type));
2578 		}
2579 	}
2580 
2581 	NXGE_DEBUG_MSG((nxgep, RX2_CTL,
2582 		"==> nxge_receive_packet: *mp 0x%016llx", *mp));
2583 
2584 	*multi_p = (multi == RCR_MULTI_MASK);
2585 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_receive_packet: "
2586 		"multi %d nmp 0x%016llx *mp 0x%016llx *mp_cont 0x%016llx",
2587 		*multi_p, nmp, *mp, *mp_cont));
2588 }
2589 
2590 /*ARGSUSED*/
2591 static nxge_status_t
2592 nxge_rx_err_evnts(p_nxge_t nxgep, uint_t index, p_nxge_ldv_t ldvp,
2593 						rx_dma_ctl_stat_t cs)
2594 {
2595 	p_nxge_rx_ring_stats_t	rdc_stats;
2596 	npi_handle_t		handle;
2597 	npi_status_t		rs;
2598 	boolean_t		rxchan_fatal = B_FALSE;
2599 	boolean_t		rxport_fatal = B_FALSE;
2600 	uint8_t			channel;
2601 	uint8_t			portn;
2602 	nxge_status_t		status = NXGE_OK;
2603 	uint32_t		error_disp_cnt = NXGE_ERROR_SHOW_MAX;
2604 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_rx_err_evnts"));
2605 
2606 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
2607 	channel = ldvp->channel;
2608 	portn = nxgep->mac.portnum;
2609 	rdc_stats = &nxgep->statsp->rdc_stats[ldvp->vdma_index];
2610 
2611 	if (cs.bits.hdw.rbr_tmout) {
2612 		rdc_stats->rx_rbr_tmout++;
2613 		NXGE_FM_REPORT_ERROR(nxgep, portn, channel,
2614 					NXGE_FM_EREPORT_RDMC_RBR_TMOUT);
2615 		rxchan_fatal = B_TRUE;
2616 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
2617 			"==> nxge_rx_err_evnts: rx_rbr_timeout"));
2618 	}
2619 	if (cs.bits.hdw.rsp_cnt_err) {
2620 		rdc_stats->rsp_cnt_err++;
2621 		NXGE_FM_REPORT_ERROR(nxgep, portn, channel,
2622 					NXGE_FM_EREPORT_RDMC_RSP_CNT_ERR);
2623 		rxchan_fatal = B_TRUE;
2624 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
2625 			"==> nxge_rx_err_evnts(channel %d): "
2626 			"rsp_cnt_err", channel));
2627 	}
2628 	if (cs.bits.hdw.byte_en_bus) {
2629 		rdc_stats->byte_en_bus++;
2630 		NXGE_FM_REPORT_ERROR(nxgep, portn, channel,
2631 					NXGE_FM_EREPORT_RDMC_BYTE_EN_BUS);
2632 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
2633 			"==> nxge_rx_err_evnts(channel %d): "
2634 			"fatal error: byte_en_bus", channel));
2635 		rxchan_fatal = B_TRUE;
2636 	}
2637 	if (cs.bits.hdw.rsp_dat_err) {
2638 		rdc_stats->rsp_dat_err++;
2639 		NXGE_FM_REPORT_ERROR(nxgep, portn, channel,
2640 					NXGE_FM_EREPORT_RDMC_RSP_DAT_ERR);
2641 		rxchan_fatal = B_TRUE;
2642 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
2643 			"==> nxge_rx_err_evnts(channel %d): "
2644 			"fatal error: rsp_dat_err", channel));
2645 	}
2646 	if (cs.bits.hdw.rcr_ack_err) {
2647 		rdc_stats->rcr_ack_err++;
2648 		NXGE_FM_REPORT_ERROR(nxgep, portn, channel,
2649 					NXGE_FM_EREPORT_RDMC_RCR_ACK_ERR);
2650 		rxchan_fatal = B_TRUE;
2651 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
2652 			"==> nxge_rx_err_evnts(channel %d): "
2653 			"fatal error: rcr_ack_err", channel));
2654 	}
2655 	if (cs.bits.hdw.dc_fifo_err) {
2656 		rdc_stats->dc_fifo_err++;
2657 		NXGE_FM_REPORT_ERROR(nxgep, portn, channel,
2658 					NXGE_FM_EREPORT_RDMC_DC_FIFO_ERR);
2659 		/* This is not a fatal error! */
2660 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
2661 			"==> nxge_rx_err_evnts(channel %d): "
2662 			"dc_fifo_err", channel));
2663 		rxport_fatal = B_TRUE;
2664 	}
2665 	if ((cs.bits.hdw.rcr_sha_par) || (cs.bits.hdw.rbr_pre_par)) {
2666 		if ((rs = npi_rxdma_ring_perr_stat_get(handle,
2667 				&rdc_stats->errlog.pre_par,
2668 				&rdc_stats->errlog.sha_par))
2669 				!= NPI_SUCCESS) {
2670 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
2671 				"==> nxge_rx_err_evnts(channel %d): "
2672 				"rcr_sha_par: get perr", channel));
2673 			return (NXGE_ERROR | rs);
2674 		}
2675 		if (cs.bits.hdw.rcr_sha_par) {
2676 			rdc_stats->rcr_sha_par++;
2677 			NXGE_FM_REPORT_ERROR(nxgep, portn, channel,
2678 					NXGE_FM_EREPORT_RDMC_RCR_SHA_PAR);
2679 			rxchan_fatal = B_TRUE;
2680 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
2681 				"==> nxge_rx_err_evnts(channel %d): "
2682 				"fatal error: rcr_sha_par", channel));
2683 		}
2684 		if (cs.bits.hdw.rbr_pre_par) {
2685 			rdc_stats->rbr_pre_par++;
2686 			NXGE_FM_REPORT_ERROR(nxgep, portn, channel,
2687 					NXGE_FM_EREPORT_RDMC_RBR_PRE_PAR);
2688 			rxchan_fatal = B_TRUE;
2689 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
2690 				"==> nxge_rx_err_evnts(channel %d): "
2691 				"fatal error: rbr_pre_par", channel));
2692 		}
2693 	}
2694 	if (cs.bits.hdw.port_drop_pkt) {
2695 		rdc_stats->port_drop_pkt++;
2696 		if (rdc_stats->port_drop_pkt < error_disp_cnt)
2697 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
2698 			"==> nxge_rx_err_evnts (channel %d): "
2699 			"port_drop_pkt", channel));
2700 	}
2701 	if (cs.bits.hdw.wred_drop) {
2702 		rdc_stats->wred_drop++;
2703 		NXGE_DEBUG_MSG((nxgep, NXGE_ERR_CTL,
2704 			"==> nxge_rx_err_evnts(channel %d): "
2705 		"wred_drop", channel));
2706 	}
2707 	if (cs.bits.hdw.rbr_pre_empty) {
2708 		rdc_stats->rbr_pre_empty++;
2709 		if (rdc_stats->rbr_pre_empty < error_disp_cnt)
2710 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
2711 			"==> nxge_rx_err_evnts(channel %d): "
2712 			"rbr_pre_empty", channel));
2713 	}
2714 	if (cs.bits.hdw.rcr_shadow_full) {
2715 		rdc_stats->rcr_shadow_full++;
2716 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
2717 			"==> nxge_rx_err_evnts(channel %d): "
2718 			"rcr_shadow_full", channel));
2719 	}
2720 	if (cs.bits.hdw.config_err) {
2721 		rdc_stats->config_err++;
2722 		NXGE_FM_REPORT_ERROR(nxgep, portn, channel,
2723 					NXGE_FM_EREPORT_RDMC_CONFIG_ERR);
2724 		rxchan_fatal = B_TRUE;
2725 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
2726 			"==> nxge_rx_err_evnts(channel %d): "
2727 			"config error", channel));
2728 	}
2729 	if (cs.bits.hdw.rcrincon) {
2730 		rdc_stats->rcrincon++;
2731 		NXGE_FM_REPORT_ERROR(nxgep, portn, channel,
2732 					NXGE_FM_EREPORT_RDMC_RCRINCON);
2733 		rxchan_fatal = B_TRUE;
2734 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
2735 			"==> nxge_rx_err_evnts(channel %d): "
2736 			"fatal error: rcrincon error", channel));
2737 	}
2738 	if (cs.bits.hdw.rcrfull) {
2739 		rdc_stats->rcrfull++;
2740 		NXGE_FM_REPORT_ERROR(nxgep, portn, channel,
2741 					NXGE_FM_EREPORT_RDMC_RCRFULL);
2742 		rxchan_fatal = B_TRUE;
2743 		if (rdc_stats->rcrfull < error_disp_cnt)
2744 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
2745 			"==> nxge_rx_err_evnts(channel %d): "
2746 			"fatal error: rcrfull error", channel));
2747 	}
2748 	if (cs.bits.hdw.rbr_empty) {
2749 		rdc_stats->rbr_empty++;
2750 		if (rdc_stats->rbr_empty < error_disp_cnt)
2751 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
2752 			"==> nxge_rx_err_evnts(channel %d): "
2753 			"rbr empty error", channel));
2754 	}
2755 	if (cs.bits.hdw.rbrfull) {
2756 		rdc_stats->rbrfull++;
2757 		NXGE_FM_REPORT_ERROR(nxgep, portn, channel,
2758 					NXGE_FM_EREPORT_RDMC_RBRFULL);
2759 		rxchan_fatal = B_TRUE;
2760 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
2761 			"==> nxge_rx_err_evnts(channel %d): "
2762 			"fatal error: rbr_full error", channel));
2763 	}
2764 	if (cs.bits.hdw.rbrlogpage) {
2765 		rdc_stats->rbrlogpage++;
2766 		NXGE_FM_REPORT_ERROR(nxgep, portn, channel,
2767 					NXGE_FM_EREPORT_RDMC_RBRLOGPAGE);
2768 		rxchan_fatal = B_TRUE;
2769 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
2770 			"==> nxge_rx_err_evnts(channel %d): "
2771 			"fatal error: rbr logical page error", channel));
2772 	}
2773 	if (cs.bits.hdw.cfiglogpage) {
2774 		rdc_stats->cfiglogpage++;
2775 		NXGE_FM_REPORT_ERROR(nxgep, portn, channel,
2776 					NXGE_FM_EREPORT_RDMC_CFIGLOGPAGE);
2777 		rxchan_fatal = B_TRUE;
2778 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
2779 			"==> nxge_rx_err_evnts(channel %d): "
2780 			"fatal error: cfig logical page error", channel));
2781 	}
2782 
2783 	if (rxport_fatal)  {
2784 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
2785 				" nxge_rx_err_evnts: "
2786 				" fatal error on Port #%d\n",
2787 				portn));
2788 		status = nxge_ipp_fatal_err_recover(nxgep);
2789 		if (status == NXGE_OK) {
2790 			FM_SERVICE_RESTORED(nxgep);
2791 		}
2792 	}
2793 
2794 	if (rxchan_fatal) {
2795 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
2796 				" nxge_rx_err_evnts: "
2797 				" fatal error on Channel #%d\n",
2798 				channel));
2799 		status = nxge_rxdma_fatal_err_recover(nxgep, channel);
2800 		if (status == NXGE_OK) {
2801 			FM_SERVICE_RESTORED(nxgep);
2802 		}
2803 	}
2804 
2805 	NXGE_DEBUG_MSG((nxgep, RX2_CTL, "<== nxge_rx_err_evnts"));
2806 
2807 	return (status);
2808 }
2809 
2810 static nxge_status_t
2811 nxge_map_rxdma(p_nxge_t nxgep)
2812 {
2813 	int			i, ndmas;
2814 	uint16_t		channel;
2815 	p_rx_rbr_rings_t 	rx_rbr_rings;
2816 	p_rx_rbr_ring_t		*rbr_rings;
2817 	p_rx_rcr_rings_t 	rx_rcr_rings;
2818 	p_rx_rcr_ring_t		*rcr_rings;
2819 	p_rx_mbox_areas_t 	rx_mbox_areas_p;
2820 	p_rx_mbox_t		*rx_mbox_p;
2821 	p_nxge_dma_pool_t	dma_buf_poolp;
2822 	p_nxge_dma_pool_t	dma_cntl_poolp;
2823 	p_nxge_dma_common_t	*dma_buf_p;
2824 	p_nxge_dma_common_t	*dma_cntl_p;
2825 	uint32_t		*num_chunks;
2826 	nxge_status_t		status = NXGE_OK;
2827 #if	defined(sun4v) && defined(NIU_LP_WORKAROUND)
2828 	p_nxge_dma_common_t	t_dma_buf_p;
2829 	p_nxge_dma_common_t	t_dma_cntl_p;
2830 #endif
2831 
2832 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_map_rxdma"));
2833 
2834 	dma_buf_poolp = nxgep->rx_buf_pool_p;
2835 	dma_cntl_poolp = nxgep->rx_cntl_pool_p;
2836 
2837 	if (!dma_buf_poolp->buf_allocated || !dma_cntl_poolp->buf_allocated) {
2838 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
2839 			"<== nxge_map_rxdma: buf not allocated"));
2840 		return (NXGE_ERROR);
2841 	}
2842 
2843 	ndmas = dma_buf_poolp->ndmas;
2844 	if (!ndmas) {
2845 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
2846 			"<== nxge_map_rxdma: no dma allocated"));
2847 		return (NXGE_ERROR);
2848 	}
2849 
2850 	num_chunks = dma_buf_poolp->num_chunks;
2851 	dma_buf_p = dma_buf_poolp->dma_buf_pool_p;
2852 	dma_cntl_p = dma_cntl_poolp->dma_buf_pool_p;
2853 
2854 	rx_rbr_rings = (p_rx_rbr_rings_t)
2855 		KMEM_ZALLOC(sizeof (rx_rbr_rings_t), KM_SLEEP);
2856 	rbr_rings = (p_rx_rbr_ring_t *)
2857 		KMEM_ZALLOC(sizeof (p_rx_rbr_ring_t) * ndmas, KM_SLEEP);
2858 	rx_rcr_rings = (p_rx_rcr_rings_t)
2859 		KMEM_ZALLOC(sizeof (rx_rcr_rings_t), KM_SLEEP);
2860 	rcr_rings = (p_rx_rcr_ring_t *)
2861 		KMEM_ZALLOC(sizeof (p_rx_rcr_ring_t) * ndmas, KM_SLEEP);
2862 	rx_mbox_areas_p = (p_rx_mbox_areas_t)
2863 		KMEM_ZALLOC(sizeof (rx_mbox_areas_t), KM_SLEEP);
2864 	rx_mbox_p = (p_rx_mbox_t *)
2865 		KMEM_ZALLOC(sizeof (p_rx_mbox_t) * ndmas, KM_SLEEP);
2866 
2867 	/*
2868 	 * Timeout should be set based on the system clock divider.
2869 	 * The following timeout value of 1 assumes that the
2870 	 * granularity (1000) is 3 microseconds running at 300MHz.
2871 	 */
2872 
2873 	nxgep->intr_threshold = RXDMA_RCR_PTHRES_DEFAULT;
2874 	nxgep->intr_timeout = RXDMA_RCR_TO_DEFAULT;
2875 
2876 	/*
2877 	 * Map descriptors from the buffer polls for each dam channel.
2878 	 */
2879 	for (i = 0; i < ndmas; i++) {
2880 		/*
2881 		 * Set up and prepare buffer blocks, descriptors
2882 		 * and mailbox.
2883 		 */
2884 		channel = ((p_nxge_dma_common_t)dma_buf_p[i])->dma_channel;
2885 		status = nxge_map_rxdma_channel(nxgep, channel,
2886 				(p_nxge_dma_common_t *)&dma_buf_p[i],
2887 				(p_rx_rbr_ring_t *)&rbr_rings[i],
2888 				num_chunks[i],
2889 				(p_nxge_dma_common_t *)&dma_cntl_p[i],
2890 				(p_rx_rcr_ring_t *)&rcr_rings[i],
2891 				(p_rx_mbox_t *)&rx_mbox_p[i]);
2892 		if (status != NXGE_OK) {
2893 			goto nxge_map_rxdma_fail1;
2894 		}
2895 		rbr_rings[i]->index = (uint16_t)i;
2896 		rcr_rings[i]->index = (uint16_t)i;
2897 		rcr_rings[i]->rdc_stats = &nxgep->statsp->rdc_stats[i];
2898 
2899 #if	defined(sun4v) && defined(NIU_LP_WORKAROUND)
2900 		if (nxgep->niu_type == N2_NIU && NXGE_DMA_BLOCK == 1) {
2901 			rbr_rings[i]->hv_set = B_FALSE;
2902 			t_dma_buf_p = (p_nxge_dma_common_t)dma_buf_p[i];
2903 			t_dma_cntl_p =
2904 				(p_nxge_dma_common_t)dma_cntl_p[i];
2905 
2906 			rbr_rings[i]->hv_rx_buf_base_ioaddr_pp =
2907 				(uint64_t)t_dma_buf_p->orig_ioaddr_pp;
2908 			rbr_rings[i]->hv_rx_buf_ioaddr_size =
2909 				(uint64_t)t_dma_buf_p->orig_alength;
2910 			NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
2911 				"==> nxge_map_rxdma_channel: "
2912 				"channel %d "
2913 				"data buf base io $%p ($%p) "
2914 				"size 0x%llx (%d 0x%x)",
2915 				channel,
2916 				rbr_rings[i]->hv_rx_buf_base_ioaddr_pp,
2917 				t_dma_cntl_p->ioaddr_pp,
2918 				rbr_rings[i]->hv_rx_buf_ioaddr_size,
2919 				t_dma_buf_p->orig_alength,
2920 				t_dma_buf_p->orig_alength));
2921 
2922 			rbr_rings[i]->hv_rx_cntl_base_ioaddr_pp =
2923 				(uint64_t)t_dma_cntl_p->orig_ioaddr_pp;
2924 			rbr_rings[i]->hv_rx_cntl_ioaddr_size =
2925 				(uint64_t)t_dma_cntl_p->orig_alength;
2926 			NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
2927 				"==> nxge_map_rxdma_channel: "
2928 				"channel %d "
2929 				"cntl base io $%p ($%p) "
2930 				"size 0x%llx (%d 0x%x)",
2931 				channel,
2932 				rbr_rings[i]->hv_rx_cntl_base_ioaddr_pp,
2933 				t_dma_cntl_p->ioaddr_pp,
2934 				rbr_rings[i]->hv_rx_cntl_ioaddr_size,
2935 				t_dma_cntl_p->orig_alength,
2936 				t_dma_cntl_p->orig_alength));
2937 		}
2938 
2939 #endif	/* sun4v and NIU_LP_WORKAROUND */
2940 	}
2941 
2942 	rx_rbr_rings->ndmas = rx_rcr_rings->ndmas = ndmas;
2943 	rx_rbr_rings->rbr_rings = rbr_rings;
2944 	nxgep->rx_rbr_rings = rx_rbr_rings;
2945 	rx_rcr_rings->rcr_rings = rcr_rings;
2946 	nxgep->rx_rcr_rings = rx_rcr_rings;
2947 
2948 	rx_mbox_areas_p->rxmbox_areas = rx_mbox_p;
2949 	nxgep->rx_mbox_areas_p = rx_mbox_areas_p;
2950 
2951 	goto nxge_map_rxdma_exit;
2952 
2953 nxge_map_rxdma_fail1:
2954 	NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
2955 		"==> nxge_map_rxdma: unmap rbr,rcr "
2956 		"(status 0x%x channel %d i %d)",
2957 		status, channel, i));
2958 	i--;
2959 	for (; i >= 0; i--) {
2960 		channel = ((p_nxge_dma_common_t)dma_buf_p[i])->dma_channel;
2961 		nxge_unmap_rxdma_channel(nxgep, channel,
2962 			rbr_rings[i],
2963 			rcr_rings[i],
2964 			rx_mbox_p[i]);
2965 	}
2966 
2967 	KMEM_FREE(rbr_rings, sizeof (p_rx_rbr_ring_t) * ndmas);
2968 	KMEM_FREE(rx_rbr_rings, sizeof (rx_rbr_rings_t));
2969 	KMEM_FREE(rcr_rings, sizeof (p_rx_rcr_ring_t) * ndmas);
2970 	KMEM_FREE(rx_rcr_rings, sizeof (rx_rcr_rings_t));
2971 	KMEM_FREE(rx_mbox_p, sizeof (p_rx_mbox_t) * ndmas);
2972 	KMEM_FREE(rx_mbox_areas_p, sizeof (rx_mbox_areas_t));
2973 
2974 nxge_map_rxdma_exit:
2975 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
2976 		"<== nxge_map_rxdma: "
2977 		"(status 0x%x channel %d)",
2978 		status, channel));
2979 
2980 	return (status);
2981 }
2982 
2983 static void
2984 nxge_unmap_rxdma(p_nxge_t nxgep)
2985 {
2986 	int			i, ndmas;
2987 	uint16_t		channel;
2988 	p_rx_rbr_rings_t 	rx_rbr_rings;
2989 	p_rx_rbr_ring_t		*rbr_rings;
2990 	p_rx_rcr_rings_t 	rx_rcr_rings;
2991 	p_rx_rcr_ring_t		*rcr_rings;
2992 	p_rx_mbox_areas_t 	rx_mbox_areas_p;
2993 	p_rx_mbox_t		*rx_mbox_p;
2994 	p_nxge_dma_pool_t	dma_buf_poolp;
2995 	p_nxge_dma_pool_t	dma_cntl_poolp;
2996 	p_nxge_dma_common_t	*dma_buf_p;
2997 
2998 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_unmap_rxdma"));
2999 
3000 	dma_buf_poolp = nxgep->rx_buf_pool_p;
3001 	dma_cntl_poolp = nxgep->rx_cntl_pool_p;
3002 
3003 	if (!dma_buf_poolp->buf_allocated || !dma_cntl_poolp->buf_allocated) {
3004 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
3005 			"<== nxge_unmap_rxdma: NULL buf pointers"));
3006 		return;
3007 	}
3008 
3009 	rx_rbr_rings = nxgep->rx_rbr_rings;
3010 	rx_rcr_rings = nxgep->rx_rcr_rings;
3011 	if (rx_rbr_rings == NULL || rx_rcr_rings == NULL) {
3012 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
3013 			"<== nxge_unmap_rxdma: NULL ring pointers"));
3014 		return;
3015 	}
3016 	ndmas = rx_rbr_rings->ndmas;
3017 	if (!ndmas) {
3018 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
3019 			"<== nxge_unmap_rxdma: no channel"));
3020 		return;
3021 	}
3022 
3023 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3024 		"==> nxge_unmap_rxdma (ndmas %d)", ndmas));
3025 	rbr_rings = rx_rbr_rings->rbr_rings;
3026 	rcr_rings = rx_rcr_rings->rcr_rings;
3027 	rx_mbox_areas_p = nxgep->rx_mbox_areas_p;
3028 	rx_mbox_p = rx_mbox_areas_p->rxmbox_areas;
3029 	dma_buf_p = dma_buf_poolp->dma_buf_pool_p;
3030 
3031 	for (i = 0; i < ndmas; i++) {
3032 		channel = ((p_nxge_dma_common_t)dma_buf_p[i])->dma_channel;
3033 		NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3034 			"==> nxge_unmap_rxdma (ndmas %d) channel %d",
3035 				ndmas, channel));
3036 		(void) nxge_unmap_rxdma_channel(nxgep, channel,
3037 				(p_rx_rbr_ring_t)rbr_rings[i],
3038 				(p_rx_rcr_ring_t)rcr_rings[i],
3039 				(p_rx_mbox_t)rx_mbox_p[i]);
3040 	}
3041 
3042 	KMEM_FREE(rx_rbr_rings, sizeof (rx_rbr_rings_t));
3043 	KMEM_FREE(rbr_rings, sizeof (p_rx_rbr_ring_t) * ndmas);
3044 	KMEM_FREE(rx_rcr_rings, sizeof (rx_rcr_rings_t));
3045 	KMEM_FREE(rcr_rings, sizeof (p_rx_rcr_ring_t) * ndmas);
3046 	KMEM_FREE(rx_mbox_areas_p, sizeof (rx_mbox_areas_t));
3047 	KMEM_FREE(rx_mbox_p, sizeof (p_rx_mbox_t) * ndmas);
3048 
3049 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3050 		"<== nxge_unmap_rxdma"));
3051 }
3052 
3053 nxge_status_t
3054 nxge_map_rxdma_channel(p_nxge_t nxgep, uint16_t channel,
3055     p_nxge_dma_common_t *dma_buf_p,  p_rx_rbr_ring_t *rbr_p,
3056     uint32_t num_chunks,
3057     p_nxge_dma_common_t *dma_cntl_p, p_rx_rcr_ring_t *rcr_p,
3058     p_rx_mbox_t *rx_mbox_p)
3059 {
3060 	int	status = NXGE_OK;
3061 
3062 	/*
3063 	 * Set up and prepare buffer blocks, descriptors
3064 	 * and mailbox.
3065 	 */
3066 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3067 		"==> nxge_map_rxdma_channel (channel %d)", channel));
3068 	/*
3069 	 * Receive buffer blocks
3070 	 */
3071 	status = nxge_map_rxdma_channel_buf_ring(nxgep, channel,
3072 			dma_buf_p, rbr_p, num_chunks);
3073 	if (status != NXGE_OK) {
3074 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
3075 			"==> nxge_map_rxdma_channel (channel %d): "
3076 			"map buffer failed 0x%x", channel, status));
3077 		goto nxge_map_rxdma_channel_exit;
3078 	}
3079 
3080 	/*
3081 	 * Receive block ring, completion ring and mailbox.
3082 	 */
3083 	status = nxge_map_rxdma_channel_cfg_ring(nxgep, channel,
3084 			dma_cntl_p, rbr_p, rcr_p, rx_mbox_p);
3085 	if (status != NXGE_OK) {
3086 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
3087 			"==> nxge_map_rxdma_channel (channel %d): "
3088 			"map config failed 0x%x", channel, status));
3089 		goto nxge_map_rxdma_channel_fail2;
3090 	}
3091 
3092 	goto nxge_map_rxdma_channel_exit;
3093 
3094 nxge_map_rxdma_channel_fail3:
3095 	/* Free rbr, rcr */
3096 	NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
3097 		"==> nxge_map_rxdma_channel: free rbr/rcr "
3098 		"(status 0x%x channel %d)",
3099 		status, channel));
3100 	nxge_unmap_rxdma_channel_cfg_ring(nxgep,
3101 		*rcr_p, *rx_mbox_p);
3102 
3103 nxge_map_rxdma_channel_fail2:
3104 	/* Free buffer blocks */
3105 	NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
3106 		"==> nxge_map_rxdma_channel: free rx buffers"
3107 		"(nxgep 0x%x status 0x%x channel %d)",
3108 		nxgep, status, channel));
3109 	nxge_unmap_rxdma_channel_buf_ring(nxgep, *rbr_p);
3110 
3111 	status = NXGE_ERROR;
3112 
3113 nxge_map_rxdma_channel_exit:
3114 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3115 		"<== nxge_map_rxdma_channel: "
3116 		"(nxgep 0x%x status 0x%x channel %d)",
3117 		nxgep, status, channel));
3118 
3119 	return (status);
3120 }
3121 
3122 /*ARGSUSED*/
3123 static void
3124 nxge_unmap_rxdma_channel(p_nxge_t nxgep, uint16_t channel,
3125     p_rx_rbr_ring_t rbr_p, p_rx_rcr_ring_t rcr_p, p_rx_mbox_t rx_mbox_p)
3126 {
3127 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3128 		"==> nxge_unmap_rxdma_channel (channel %d)", channel));
3129 
3130 	/*
3131 	 * unmap receive block ring, completion ring and mailbox.
3132 	 */
3133 	(void) nxge_unmap_rxdma_channel_cfg_ring(nxgep,
3134 			rcr_p, rx_mbox_p);
3135 
3136 	/* unmap buffer blocks */
3137 	(void) nxge_unmap_rxdma_channel_buf_ring(nxgep, rbr_p);
3138 
3139 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "<== nxge_unmap_rxdma_channel"));
3140 }
3141 
3142 /*ARGSUSED*/
3143 static nxge_status_t
3144 nxge_map_rxdma_channel_cfg_ring(p_nxge_t nxgep, uint16_t dma_channel,
3145     p_nxge_dma_common_t *dma_cntl_p, p_rx_rbr_ring_t *rbr_p,
3146     p_rx_rcr_ring_t *rcr_p, p_rx_mbox_t *rx_mbox_p)
3147 {
3148 	p_rx_rbr_ring_t 	rbrp;
3149 	p_rx_rcr_ring_t 	rcrp;
3150 	p_rx_mbox_t 		mboxp;
3151 	p_nxge_dma_common_t 	cntl_dmap;
3152 	p_nxge_dma_common_t 	dmap;
3153 	p_rx_msg_t 		*rx_msg_ring;
3154 	p_rx_msg_t 		rx_msg_p;
3155 	p_rbr_cfig_a_t		rcfga_p;
3156 	p_rbr_cfig_b_t		rcfgb_p;
3157 	p_rcrcfig_a_t		cfga_p;
3158 	p_rcrcfig_b_t		cfgb_p;
3159 	p_rxdma_cfig1_t		cfig1_p;
3160 	p_rxdma_cfig2_t		cfig2_p;
3161 	p_rbr_kick_t		kick_p;
3162 	uint32_t		dmaaddrp;
3163 	uint32_t		*rbr_vaddrp;
3164 	uint32_t		bkaddr;
3165 	nxge_status_t		status = NXGE_OK;
3166 	int			i;
3167 	uint32_t 		nxge_port_rcr_size;
3168 
3169 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3170 		"==> nxge_map_rxdma_channel_cfg_ring"));
3171 
3172 	cntl_dmap = *dma_cntl_p;
3173 
3174 	/* Map in the receive block ring */
3175 	rbrp = *rbr_p;
3176 	dmap = (p_nxge_dma_common_t)&rbrp->rbr_desc;
3177 	nxge_setup_dma_common(dmap, cntl_dmap, rbrp->rbb_max, 4);
3178 	/*
3179 	 * Zero out buffer block ring descriptors.
3180 	 */
3181 	bzero((caddr_t)dmap->kaddrp, dmap->alength);
3182 
3183 	rcfga_p = &(rbrp->rbr_cfga);
3184 	rcfgb_p = &(rbrp->rbr_cfgb);
3185 	kick_p = &(rbrp->rbr_kick);
3186 	rcfga_p->value = 0;
3187 	rcfgb_p->value = 0;
3188 	kick_p->value = 0;
3189 	rbrp->rbr_addr = dmap->dma_cookie.dmac_laddress;
3190 	rcfga_p->value = (rbrp->rbr_addr &
3191 				(RBR_CFIG_A_STDADDR_MASK |
3192 				RBR_CFIG_A_STDADDR_BASE_MASK));
3193 	rcfga_p->value |= ((uint64_t)rbrp->rbb_max << RBR_CFIG_A_LEN_SHIFT);
3194 
3195 	rcfgb_p->bits.ldw.bufsz0 = rbrp->pkt_buf_size0;
3196 	rcfgb_p->bits.ldw.vld0 = 1;
3197 	rcfgb_p->bits.ldw.bufsz1 = rbrp->pkt_buf_size1;
3198 	rcfgb_p->bits.ldw.vld1 = 1;
3199 	rcfgb_p->bits.ldw.bufsz2 = rbrp->pkt_buf_size2;
3200 	rcfgb_p->bits.ldw.vld2 = 1;
3201 	rcfgb_p->bits.ldw.bksize = nxgep->rx_bksize_code;
3202 
3203 	/*
3204 	 * For each buffer block, enter receive block address to the ring.
3205 	 */
3206 	rbr_vaddrp = (uint32_t *)dmap->kaddrp;
3207 	rbrp->rbr_desc_vp = (uint32_t *)dmap->kaddrp;
3208 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3209 		"==> nxge_map_rxdma_channel_cfg_ring: channel %d "
3210 		"rbr_vaddrp $%p", dma_channel, rbr_vaddrp));
3211 
3212 	rx_msg_ring = rbrp->rx_msg_ring;
3213 	for (i = 0; i < rbrp->tnblocks; i++) {
3214 		rx_msg_p = rx_msg_ring[i];
3215 		rx_msg_p->nxgep = nxgep;
3216 		rx_msg_p->rx_rbr_p = rbrp;
3217 		bkaddr = (uint32_t)
3218 			((rx_msg_p->buf_dma.dma_cookie.dmac_laddress
3219 				>> RBR_BKADDR_SHIFT));
3220 		rx_msg_p->free = B_FALSE;
3221 		rx_msg_p->max_usage_cnt = 0xbaddcafe;
3222 
3223 		*rbr_vaddrp++ = bkaddr;
3224 	}
3225 
3226 	kick_p->bits.ldw.bkadd = rbrp->rbb_max;
3227 	rbrp->rbr_wr_index = (rbrp->rbb_max - 1);
3228 
3229 	rbrp->rbr_rd_index = 0;
3230 
3231 	rbrp->rbr_consumed = 0;
3232 	rbrp->rbr_use_bcopy = B_TRUE;
3233 	rbrp->rbr_bufsize_type = RCR_PKTBUFSZ_0;
3234 	/*
3235 	 * Do bcopy on packets greater than bcopy size once
3236 	 * the lo threshold is reached.
3237 	 * This lo threshold should be less than the hi threshold.
3238 	 *
3239 	 * Do bcopy on every packet once the hi threshold is reached.
3240 	 */
3241 	if (nxge_rx_threshold_lo >= nxge_rx_threshold_hi) {
3242 		/* default it to use hi */
3243 		nxge_rx_threshold_lo = nxge_rx_threshold_hi;
3244 	}
3245 
3246 	if (nxge_rx_buf_size_type > NXGE_RBR_TYPE2) {
3247 		nxge_rx_buf_size_type = NXGE_RBR_TYPE2;
3248 	}
3249 	rbrp->rbr_bufsize_type = nxge_rx_buf_size_type;
3250 
3251 	switch (nxge_rx_threshold_hi) {
3252 	default:
3253 	case	NXGE_RX_COPY_NONE:
3254 		/* Do not do bcopy at all */
3255 		rbrp->rbr_use_bcopy = B_FALSE;
3256 		rbrp->rbr_threshold_hi = rbrp->rbb_max;
3257 		break;
3258 
3259 	case NXGE_RX_COPY_1:
3260 	case NXGE_RX_COPY_2:
3261 	case NXGE_RX_COPY_3:
3262 	case NXGE_RX_COPY_4:
3263 	case NXGE_RX_COPY_5:
3264 	case NXGE_RX_COPY_6:
3265 	case NXGE_RX_COPY_7:
3266 		rbrp->rbr_threshold_hi =
3267 			rbrp->rbb_max *
3268 			(nxge_rx_threshold_hi)/NXGE_RX_BCOPY_SCALE;
3269 		break;
3270 
3271 	case NXGE_RX_COPY_ALL:
3272 		rbrp->rbr_threshold_hi = 0;
3273 		break;
3274 	}
3275 
3276 	switch (nxge_rx_threshold_lo) {
3277 	default:
3278 	case	NXGE_RX_COPY_NONE:
3279 		/* Do not do bcopy at all */
3280 		if (rbrp->rbr_use_bcopy) {
3281 			rbrp->rbr_use_bcopy = B_FALSE;
3282 		}
3283 		rbrp->rbr_threshold_lo = rbrp->rbb_max;
3284 		break;
3285 
3286 	case NXGE_RX_COPY_1:
3287 	case NXGE_RX_COPY_2:
3288 	case NXGE_RX_COPY_3:
3289 	case NXGE_RX_COPY_4:
3290 	case NXGE_RX_COPY_5:
3291 	case NXGE_RX_COPY_6:
3292 	case NXGE_RX_COPY_7:
3293 		rbrp->rbr_threshold_lo =
3294 			rbrp->rbb_max *
3295 			(nxge_rx_threshold_lo)/NXGE_RX_BCOPY_SCALE;
3296 		break;
3297 
3298 	case NXGE_RX_COPY_ALL:
3299 		rbrp->rbr_threshold_lo = 0;
3300 		break;
3301 	}
3302 
3303 	NXGE_DEBUG_MSG((nxgep, RX_CTL,
3304 		"nxge_map_rxdma_channel_cfg_ring: channel %d "
3305 		"rbb_max %d "
3306 		"rbrp->rbr_bufsize_type %d "
3307 		"rbb_threshold_hi %d "
3308 		"rbb_threshold_lo %d",
3309 		dma_channel,
3310 		rbrp->rbb_max,
3311 		rbrp->rbr_bufsize_type,
3312 		rbrp->rbr_threshold_hi,
3313 		rbrp->rbr_threshold_lo));
3314 
3315 	rbrp->page_valid.value = 0;
3316 	rbrp->page_mask_1.value = rbrp->page_mask_2.value = 0;
3317 	rbrp->page_value_1.value = rbrp->page_value_2.value = 0;
3318 	rbrp->page_reloc_1.value = rbrp->page_reloc_2.value = 0;
3319 	rbrp->page_hdl.value = 0;
3320 
3321 	rbrp->page_valid.bits.ldw.page0 = 1;
3322 	rbrp->page_valid.bits.ldw.page1 = 1;
3323 
3324 	/* Map in the receive completion ring */
3325 	rcrp = (p_rx_rcr_ring_t)
3326 		KMEM_ZALLOC(sizeof (rx_rcr_ring_t), KM_SLEEP);
3327 	rcrp->rdc = dma_channel;
3328 
3329 	nxge_port_rcr_size = nxgep->nxge_port_rcr_size;
3330 	rcrp->comp_size = nxge_port_rcr_size;
3331 	rcrp->comp_wrap_mask = nxge_port_rcr_size - 1;
3332 
3333 	rcrp->max_receive_pkts = nxge_max_rx_pkts;
3334 
3335 	dmap = (p_nxge_dma_common_t)&rcrp->rcr_desc;
3336 	nxge_setup_dma_common(dmap, cntl_dmap, rcrp->comp_size,
3337 			sizeof (rcr_entry_t));
3338 	rcrp->comp_rd_index = 0;
3339 	rcrp->comp_wt_index = 0;
3340 	rcrp->rcr_desc_rd_head_p = rcrp->rcr_desc_first_p =
3341 		(p_rcr_entry_t)DMA_COMMON_VPTR(rcrp->rcr_desc);
3342 	rcrp->rcr_desc_rd_head_pp = rcrp->rcr_desc_first_pp =
3343 #if defined(__i386)
3344 		(p_rcr_entry_t)(uint32_t)DMA_COMMON_IOADDR(rcrp->rcr_desc);
3345 #else
3346 		(p_rcr_entry_t)DMA_COMMON_IOADDR(rcrp->rcr_desc);
3347 #endif
3348 
3349 	rcrp->rcr_desc_last_p = rcrp->rcr_desc_rd_head_p +
3350 			(nxge_port_rcr_size - 1);
3351 	rcrp->rcr_desc_last_pp = rcrp->rcr_desc_rd_head_pp +
3352 			(nxge_port_rcr_size - 1);
3353 
3354 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3355 		"==> nxge_map_rxdma_channel_cfg_ring: "
3356 		"channel %d "
3357 		"rbr_vaddrp $%p "
3358 		"rcr_desc_rd_head_p $%p "
3359 		"rcr_desc_rd_head_pp $%p "
3360 		"rcr_desc_rd_last_p $%p "
3361 		"rcr_desc_rd_last_pp $%p ",
3362 		dma_channel,
3363 		rbr_vaddrp,
3364 		rcrp->rcr_desc_rd_head_p,
3365 		rcrp->rcr_desc_rd_head_pp,
3366 		rcrp->rcr_desc_last_p,
3367 		rcrp->rcr_desc_last_pp));
3368 
3369 	/*
3370 	 * Zero out buffer block ring descriptors.
3371 	 */
3372 	bzero((caddr_t)dmap->kaddrp, dmap->alength);
3373 	rcrp->intr_timeout = nxgep->intr_timeout;
3374 	rcrp->intr_threshold = nxgep->intr_threshold;
3375 	rcrp->full_hdr_flag = B_FALSE;
3376 	rcrp->sw_priv_hdr_len = 0;
3377 
3378 	cfga_p = &(rcrp->rcr_cfga);
3379 	cfgb_p = &(rcrp->rcr_cfgb);
3380 	cfga_p->value = 0;
3381 	cfgb_p->value = 0;
3382 	rcrp->rcr_addr = dmap->dma_cookie.dmac_laddress;
3383 	cfga_p->value = (rcrp->rcr_addr &
3384 			    (RCRCFIG_A_STADDR_MASK |
3385 			    RCRCFIG_A_STADDR_BASE_MASK));
3386 
3387 	rcfga_p->value |= ((uint64_t)rcrp->comp_size <<
3388 				RCRCFIG_A_LEN_SHIF);
3389 
3390 	/*
3391 	 * Timeout should be set based on the system clock divider.
3392 	 * The following timeout value of 1 assumes that the
3393 	 * granularity (1000) is 3 microseconds running at 300MHz.
3394 	 */
3395 	cfgb_p->bits.ldw.pthres = rcrp->intr_threshold;
3396 	cfgb_p->bits.ldw.timeout = rcrp->intr_timeout;
3397 	cfgb_p->bits.ldw.entout = 1;
3398 
3399 	/* Map in the mailbox */
3400 	mboxp = (p_rx_mbox_t)
3401 			KMEM_ZALLOC(sizeof (rx_mbox_t), KM_SLEEP);
3402 	dmap = (p_nxge_dma_common_t)&mboxp->rx_mbox;
3403 	nxge_setup_dma_common(dmap, cntl_dmap, 1, sizeof (rxdma_mailbox_t));
3404 	cfig1_p = (p_rxdma_cfig1_t)&mboxp->rx_cfg1;
3405 	cfig2_p = (p_rxdma_cfig2_t)&mboxp->rx_cfg2;
3406 	cfig1_p->value = cfig2_p->value = 0;
3407 
3408 	mboxp->mbox_addr = dmap->dma_cookie.dmac_laddress;
3409 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3410 		"==> nxge_map_rxdma_channel_cfg_ring: "
3411 		"channel %d cfg1 0x%016llx cfig2 0x%016llx cookie 0x%016llx",
3412 		dma_channel, cfig1_p->value, cfig2_p->value,
3413 		mboxp->mbox_addr));
3414 
3415 	dmaaddrp = (uint32_t)(dmap->dma_cookie.dmac_laddress >> 32
3416 			& 0xfff);
3417 	cfig1_p->bits.ldw.mbaddr_h = dmaaddrp;
3418 
3419 
3420 	dmaaddrp = (uint32_t)(dmap->dma_cookie.dmac_laddress & 0xffffffff);
3421 	dmaaddrp = (uint32_t)(dmap->dma_cookie.dmac_laddress &
3422 				RXDMA_CFIG2_MBADDR_L_MASK);
3423 
3424 	cfig2_p->bits.ldw.mbaddr = (dmaaddrp >> RXDMA_CFIG2_MBADDR_L_SHIFT);
3425 
3426 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3427 		"==> nxge_map_rxdma_channel_cfg_ring: "
3428 		"channel %d damaddrp $%p "
3429 		"cfg1 0x%016llx cfig2 0x%016llx",
3430 		dma_channel, dmaaddrp,
3431 		cfig1_p->value, cfig2_p->value));
3432 
3433 	cfig2_p->bits.ldw.full_hdr = rcrp->full_hdr_flag;
3434 	cfig2_p->bits.ldw.offset = rcrp->sw_priv_hdr_len;
3435 
3436 	rbrp->rx_rcr_p = rcrp;
3437 	rcrp->rx_rbr_p = rbrp;
3438 	*rcr_p = rcrp;
3439 	*rx_mbox_p = mboxp;
3440 
3441 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3442 		"<== nxge_map_rxdma_channel_cfg_ring status 0x%08x", status));
3443 
3444 	return (status);
3445 }
3446 
3447 /*ARGSUSED*/
3448 static void
3449 nxge_unmap_rxdma_channel_cfg_ring(p_nxge_t nxgep,
3450     p_rx_rcr_ring_t rcr_p, p_rx_mbox_t rx_mbox_p)
3451 {
3452 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3453 		"==> nxge_unmap_rxdma_channel_cfg_ring: channel %d",
3454 		rcr_p->rdc));
3455 
3456 	KMEM_FREE(rcr_p, sizeof (rx_rcr_ring_t));
3457 	KMEM_FREE(rx_mbox_p, sizeof (rx_mbox_t));
3458 
3459 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3460 		"<== nxge_unmap_rxdma_channel_cfg_ring"));
3461 }
3462 
3463 static nxge_status_t
3464 nxge_map_rxdma_channel_buf_ring(p_nxge_t nxgep, uint16_t channel,
3465     p_nxge_dma_common_t *dma_buf_p,
3466     p_rx_rbr_ring_t *rbr_p, uint32_t num_chunks)
3467 {
3468 	p_rx_rbr_ring_t 	rbrp;
3469 	p_nxge_dma_common_t 	dma_bufp, tmp_bufp;
3470 	p_rx_msg_t 		*rx_msg_ring;
3471 	p_rx_msg_t 		rx_msg_p;
3472 	p_mblk_t 		mblk_p;
3473 
3474 	rxring_info_t *ring_info;
3475 	nxge_status_t		status = NXGE_OK;
3476 	int			i, j, index;
3477 	uint32_t		size, bsize, nblocks, nmsgs;
3478 
3479 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3480 		"==> nxge_map_rxdma_channel_buf_ring: channel %d",
3481 		channel));
3482 
3483 	dma_bufp = tmp_bufp = *dma_buf_p;
3484 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3485 		" nxge_map_rxdma_channel_buf_ring: channel %d to map %d "
3486 		"chunks bufp 0x%016llx",
3487 		channel, num_chunks, dma_bufp));
3488 
3489 	nmsgs = 0;
3490 	for (i = 0; i < num_chunks; i++, tmp_bufp++) {
3491 		NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3492 			"==> nxge_map_rxdma_channel_buf_ring: channel %d "
3493 			"bufp 0x%016llx nblocks %d nmsgs %d",
3494 			channel, tmp_bufp, tmp_bufp->nblocks, nmsgs));
3495 		nmsgs += tmp_bufp->nblocks;
3496 	}
3497 	if (!nmsgs) {
3498 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
3499 			"<== nxge_map_rxdma_channel_buf_ring: channel %d "
3500 			"no msg blocks",
3501 			channel));
3502 		status = NXGE_ERROR;
3503 		goto nxge_map_rxdma_channel_buf_ring_exit;
3504 	}
3505 
3506 	rbrp = (p_rx_rbr_ring_t)KMEM_ZALLOC(sizeof (*rbrp), KM_SLEEP);
3507 
3508 	size = nmsgs * sizeof (p_rx_msg_t);
3509 	rx_msg_ring = KMEM_ZALLOC(size, KM_SLEEP);
3510 	ring_info = (rxring_info_t *)KMEM_ZALLOC(sizeof (rxring_info_t),
3511 		KM_SLEEP);
3512 
3513 	MUTEX_INIT(&rbrp->lock, NULL, MUTEX_DRIVER,
3514 				(void *)nxgep->interrupt_cookie);
3515 	MUTEX_INIT(&rbrp->post_lock, NULL, MUTEX_DRIVER,
3516 				(void *)nxgep->interrupt_cookie);
3517 	rbrp->rdc = channel;
3518 	rbrp->num_blocks = num_chunks;
3519 	rbrp->tnblocks = nmsgs;
3520 	rbrp->rbb_max = nmsgs;
3521 	rbrp->rbr_max_size = nmsgs;
3522 	rbrp->rbr_wrap_mask = (rbrp->rbb_max - 1);
3523 
3524 	/*
3525 	 * Buffer sizes suggested by NIU architect.
3526 	 * 256, 512 and 2K.
3527 	 */
3528 
3529 	rbrp->pkt_buf_size0 = RBR_BUFSZ0_256B;
3530 	rbrp->pkt_buf_size0_bytes = RBR_BUFSZ0_256_BYTES;
3531 	rbrp->npi_pkt_buf_size0 = SIZE_256B;
3532 
3533 	rbrp->pkt_buf_size1 = RBR_BUFSZ1_1K;
3534 	rbrp->pkt_buf_size1_bytes = RBR_BUFSZ1_1K_BYTES;
3535 	rbrp->npi_pkt_buf_size1 = SIZE_1KB;
3536 
3537 	rbrp->block_size = nxgep->rx_default_block_size;
3538 
3539 	if (!nxge_jumbo_enable && !nxgep->param_arr[param_accept_jumbo].value) {
3540 		rbrp->pkt_buf_size2 = RBR_BUFSZ2_2K;
3541 		rbrp->pkt_buf_size2_bytes = RBR_BUFSZ2_2K_BYTES;
3542 		rbrp->npi_pkt_buf_size2 = SIZE_2KB;
3543 	} else {
3544 		if (rbrp->block_size >= 0x2000) {
3545 			rbrp->pkt_buf_size2 = RBR_BUFSZ2_8K;
3546 			rbrp->pkt_buf_size2_bytes = RBR_BUFSZ2_8K_BYTES;
3547 			rbrp->npi_pkt_buf_size2 = SIZE_8KB;
3548 		} else {
3549 			rbrp->pkt_buf_size2 = RBR_BUFSZ2_4K;
3550 			rbrp->pkt_buf_size2_bytes = RBR_BUFSZ2_4K_BYTES;
3551 			rbrp->npi_pkt_buf_size2 = SIZE_4KB;
3552 		}
3553 	}
3554 
3555 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3556 		"==> nxge_map_rxdma_channel_buf_ring: channel %d "
3557 		"actual rbr max %d rbb_max %d nmsgs %d "
3558 		"rbrp->block_size %d default_block_size %d "
3559 		"(config nxge_rbr_size %d nxge_rbr_spare_size %d)",
3560 		channel, rbrp->rbr_max_size, rbrp->rbb_max, nmsgs,
3561 		rbrp->block_size, nxgep->rx_default_block_size,
3562 		nxge_rbr_size, nxge_rbr_spare_size));
3563 
3564 	/* Map in buffers from the buffer pool.  */
3565 	index = 0;
3566 	for (i = 0; i < rbrp->num_blocks; i++, dma_bufp++) {
3567 		bsize = dma_bufp->block_size;
3568 		nblocks = dma_bufp->nblocks;
3569 #if defined(__i386)
3570 		ring_info->buffer[i].dvma_addr = (uint32_t)dma_bufp->ioaddr_pp;
3571 #else
3572 		ring_info->buffer[i].dvma_addr = (uint64_t)dma_bufp->ioaddr_pp;
3573 #endif
3574 		ring_info->buffer[i].buf_index = i;
3575 		ring_info->buffer[i].buf_size = dma_bufp->alength;
3576 		ring_info->buffer[i].start_index = index;
3577 #if defined(__i386)
3578 		ring_info->buffer[i].kaddr = (uint32_t)dma_bufp->kaddrp;
3579 #else
3580 		ring_info->buffer[i].kaddr = (uint64_t)dma_bufp->kaddrp;
3581 #endif
3582 
3583 		NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3584 			" nxge_map_rxdma_channel_buf_ring: map channel %d "
3585 			"chunk %d"
3586 			" nblocks %d chunk_size %x block_size 0x%x "
3587 			"dma_bufp $%p", channel, i,
3588 			dma_bufp->nblocks, ring_info->buffer[i].buf_size, bsize,
3589 			dma_bufp));
3590 
3591 		for (j = 0; j < nblocks; j++) {
3592 			if ((rx_msg_p = nxge_allocb(bsize, BPRI_LO,
3593 					dma_bufp)) == NULL) {
3594 				NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
3595 					"allocb failed (index %d i %d j %d)",
3596 					index, i, j));
3597 				goto nxge_map_rxdma_channel_buf_ring_fail1;
3598 			}
3599 			rx_msg_ring[index] = rx_msg_p;
3600 			rx_msg_p->block_index = index;
3601 			rx_msg_p->shifted_addr = (uint32_t)
3602 				((rx_msg_p->buf_dma.dma_cookie.dmac_laddress >>
3603 					    RBR_BKADDR_SHIFT));
3604 
3605 			NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3606 				"index %d j %d rx_msg_p $%p mblk %p",
3607 				index, j, rx_msg_p, rx_msg_p->rx_mblk_p));
3608 
3609 			mblk_p = rx_msg_p->rx_mblk_p;
3610 			mblk_p->b_wptr = mblk_p->b_rptr + bsize;
3611 
3612 			rbrp->rbr_ref_cnt++;
3613 			index++;
3614 			rx_msg_p->buf_dma.dma_channel = channel;
3615 		}
3616 	}
3617 	if (i < rbrp->num_blocks) {
3618 		goto nxge_map_rxdma_channel_buf_ring_fail1;
3619 	}
3620 
3621 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3622 		"nxge_map_rxdma_channel_buf_ring: done buf init "
3623 			"channel %d msg block entries %d",
3624 			channel, index));
3625 	ring_info->block_size_mask = bsize - 1;
3626 	rbrp->rx_msg_ring = rx_msg_ring;
3627 	rbrp->dma_bufp = dma_buf_p;
3628 	rbrp->ring_info = ring_info;
3629 
3630 	status = nxge_rxbuf_index_info_init(nxgep, rbrp);
3631 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3632 		" nxge_map_rxdma_channel_buf_ring: "
3633 		"channel %d done buf info init", channel));
3634 
3635 	/*
3636 	 * Finally, permit nxge_freeb() to call nxge_post_page().
3637 	 */
3638 	rbrp->rbr_state = RBR_POSTING;
3639 
3640 	*rbr_p = rbrp;
3641 	goto nxge_map_rxdma_channel_buf_ring_exit;
3642 
3643 nxge_map_rxdma_channel_buf_ring_fail1:
3644 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3645 		" nxge_map_rxdma_channel_buf_ring: failed channel (0x%x)",
3646 		channel, status));
3647 
3648 	index--;
3649 	for (; index >= 0; index--) {
3650 		rx_msg_p = rx_msg_ring[index];
3651 		if (rx_msg_p != NULL) {
3652 			freeb(rx_msg_p->rx_mblk_p);
3653 			rx_msg_ring[index] = NULL;
3654 		}
3655 	}
3656 nxge_map_rxdma_channel_buf_ring_fail:
3657 	MUTEX_DESTROY(&rbrp->post_lock);
3658 	MUTEX_DESTROY(&rbrp->lock);
3659 	KMEM_FREE(ring_info, sizeof (rxring_info_t));
3660 	KMEM_FREE(rx_msg_ring, size);
3661 	KMEM_FREE(rbrp, sizeof (rx_rbr_ring_t));
3662 
3663 	status = NXGE_ERROR;
3664 
3665 nxge_map_rxdma_channel_buf_ring_exit:
3666 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3667 		"<== nxge_map_rxdma_channel_buf_ring status 0x%08x", status));
3668 
3669 	return (status);
3670 }
3671 
3672 /*ARGSUSED*/
3673 static void
3674 nxge_unmap_rxdma_channel_buf_ring(p_nxge_t nxgep,
3675     p_rx_rbr_ring_t rbr_p)
3676 {
3677 	p_rx_msg_t 		*rx_msg_ring;
3678 	p_rx_msg_t 		rx_msg_p;
3679 	rxring_info_t 		*ring_info;
3680 	int			i;
3681 	uint32_t		size;
3682 #ifdef	NXGE_DEBUG
3683 	int			num_chunks;
3684 #endif
3685 
3686 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3687 		"==> nxge_unmap_rxdma_channel_buf_ring"));
3688 	if (rbr_p == NULL) {
3689 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
3690 			"<== nxge_unmap_rxdma_channel_buf_ring: NULL rbrp"));
3691 		return;
3692 	}
3693 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3694 		"==> nxge_unmap_rxdma_channel_buf_ring: channel %d",
3695 		rbr_p->rdc));
3696 
3697 	rx_msg_ring = rbr_p->rx_msg_ring;
3698 	ring_info = rbr_p->ring_info;
3699 
3700 	if (rx_msg_ring == NULL || ring_info == NULL) {
3701 			NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3702 		"<== nxge_unmap_rxdma_channel_buf_ring: "
3703 		"rx_msg_ring $%p ring_info $%p",
3704 		rx_msg_p, ring_info));
3705 		return;
3706 	}
3707 
3708 #ifdef	NXGE_DEBUG
3709 	num_chunks = rbr_p->num_blocks;
3710 #endif
3711 	size = rbr_p->tnblocks * sizeof (p_rx_msg_t);
3712 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3713 		" nxge_unmap_rxdma_channel_buf_ring: channel %d chunks %d "
3714 		"tnblocks %d (max %d) size ptrs %d ",
3715 		rbr_p->rdc, num_chunks,
3716 		rbr_p->tnblocks, rbr_p->rbr_max_size, size));
3717 
3718 	for (i = 0; i < rbr_p->tnblocks; i++) {
3719 		rx_msg_p = rx_msg_ring[i];
3720 		NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3721 			" nxge_unmap_rxdma_channel_buf_ring: "
3722 			"rx_msg_p $%p",
3723 			rx_msg_p));
3724 		if (rx_msg_p != NULL) {
3725 			freeb(rx_msg_p->rx_mblk_p);
3726 			rx_msg_ring[i] = NULL;
3727 		}
3728 	}
3729 
3730 	/*
3731 	 * We no longer may use the mutex <post_lock>. By setting
3732 	 * <rbr_state> to anything but POSTING, we prevent
3733 	 * nxge_post_page() from accessing a dead mutex.
3734 	 */
3735 	rbr_p->rbr_state = RBR_UNMAPPING;
3736 	MUTEX_DESTROY(&rbr_p->post_lock);
3737 
3738 	MUTEX_DESTROY(&rbr_p->lock);
3739 	KMEM_FREE(ring_info, sizeof (rxring_info_t));
3740 	KMEM_FREE(rx_msg_ring, size);
3741 
3742 	if (rbr_p->rbr_ref_cnt == 0) {
3743 		/* This is the normal state of affairs. */
3744 		KMEM_FREE(rbr_p, sizeof (*rbr_p));
3745 	} else {
3746 		/*
3747 		 * Some of our buffers are still being used.
3748 		 * Therefore, tell nxge_freeb() this ring is
3749 		 * unmapped, so it may free <rbr_p> for us.
3750 		 */
3751 		rbr_p->rbr_state = RBR_UNMAPPED;
3752 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
3753 		    "unmap_rxdma_buf_ring: %d %s outstanding.",
3754 		    rbr_p->rbr_ref_cnt,
3755 		    rbr_p->rbr_ref_cnt == 1 ? "msg" : "msgs"));
3756 	}
3757 
3758 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3759 		"<== nxge_unmap_rxdma_channel_buf_ring"));
3760 }
3761 
3762 static nxge_status_t
3763 nxge_rxdma_hw_start_common(p_nxge_t nxgep)
3764 {
3765 	nxge_status_t		status = NXGE_OK;
3766 
3767 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_hw_start_common"));
3768 
3769 	/*
3770 	 * Load the sharable parameters by writing to the
3771 	 * function zero control registers. These FZC registers
3772 	 * should be initialized only once for the entire chip.
3773 	 */
3774 	(void) nxge_init_fzc_rx_common(nxgep);
3775 
3776 	/*
3777 	 * Initialize the RXDMA port specific FZC control configurations.
3778 	 * These FZC registers are pertaining to each port.
3779 	 */
3780 	(void) nxge_init_fzc_rxdma_port(nxgep);
3781 
3782 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_hw_start_common"));
3783 
3784 	return (status);
3785 }
3786 
3787 /*ARGSUSED*/
3788 static void
3789 nxge_rxdma_hw_stop_common(p_nxge_t nxgep)
3790 {
3791 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_hw_stop_common"));
3792 
3793 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_hw_stop_common"));
3794 }
3795 
3796 static nxge_status_t
3797 nxge_rxdma_hw_start(p_nxge_t nxgep)
3798 {
3799 	int			i, ndmas;
3800 	uint16_t		channel;
3801 	p_rx_rbr_rings_t 	rx_rbr_rings;
3802 	p_rx_rbr_ring_t		*rbr_rings;
3803 	p_rx_rcr_rings_t 	rx_rcr_rings;
3804 	p_rx_rcr_ring_t		*rcr_rings;
3805 	p_rx_mbox_areas_t 	rx_mbox_areas_p;
3806 	p_rx_mbox_t		*rx_mbox_p;
3807 	nxge_status_t		status = NXGE_OK;
3808 
3809 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_hw_start"));
3810 
3811 	rx_rbr_rings = nxgep->rx_rbr_rings;
3812 	rx_rcr_rings = nxgep->rx_rcr_rings;
3813 	if (rx_rbr_rings == NULL || rx_rcr_rings == NULL) {
3814 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
3815 			"<== nxge_rxdma_hw_start: NULL ring pointers"));
3816 		return (NXGE_ERROR);
3817 	}
3818 	ndmas = rx_rbr_rings->ndmas;
3819 	if (ndmas == 0) {
3820 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
3821 			"<== nxge_rxdma_hw_start: no dma channel allocated"));
3822 		return (NXGE_ERROR);
3823 	}
3824 
3825 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3826 		"==> nxge_rxdma_hw_start (ndmas %d)", ndmas));
3827 
3828 	rbr_rings = rx_rbr_rings->rbr_rings;
3829 	rcr_rings = rx_rcr_rings->rcr_rings;
3830 	rx_mbox_areas_p = nxgep->rx_mbox_areas_p;
3831 	if (rx_mbox_areas_p) {
3832 		rx_mbox_p = rx_mbox_areas_p->rxmbox_areas;
3833 	}
3834 
3835 	for (i = 0; i < ndmas; i++) {
3836 		channel = rbr_rings[i]->rdc;
3837 		NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3838 			"==> nxge_rxdma_hw_start (ndmas %d) channel %d",
3839 				ndmas, channel));
3840 		status = nxge_rxdma_start_channel(nxgep, channel,
3841 				(p_rx_rbr_ring_t)rbr_rings[i],
3842 				(p_rx_rcr_ring_t)rcr_rings[i],
3843 				(p_rx_mbox_t)rx_mbox_p[i]);
3844 		if (status != NXGE_OK) {
3845 			goto nxge_rxdma_hw_start_fail1;
3846 		}
3847 	}
3848 
3849 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_hw_start: "
3850 		"rx_rbr_rings 0x%016llx rings 0x%016llx",
3851 		rx_rbr_rings, rx_rcr_rings));
3852 
3853 	goto nxge_rxdma_hw_start_exit;
3854 
3855 nxge_rxdma_hw_start_fail1:
3856 	NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
3857 		"==> nxge_rxdma_hw_start: disable "
3858 		"(status 0x%x channel %d i %d)", status, channel, i));
3859 	for (; i >= 0; i--) {
3860 		channel = rbr_rings[i]->rdc;
3861 		(void) nxge_rxdma_stop_channel(nxgep, channel);
3862 	}
3863 
3864 nxge_rxdma_hw_start_exit:
3865 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3866 		"==> nxge_rxdma_hw_start: (status 0x%x)", status));
3867 
3868 	return (status);
3869 }
3870 
3871 static void
3872 nxge_rxdma_hw_stop(p_nxge_t nxgep)
3873 {
3874 	int			i, ndmas;
3875 	uint16_t		channel;
3876 	p_rx_rbr_rings_t 	rx_rbr_rings;
3877 	p_rx_rbr_ring_t		*rbr_rings;
3878 	p_rx_rcr_rings_t 	rx_rcr_rings;
3879 
3880 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_hw_stop"));
3881 
3882 	rx_rbr_rings = nxgep->rx_rbr_rings;
3883 	rx_rcr_rings = nxgep->rx_rcr_rings;
3884 	if (rx_rbr_rings == NULL || rx_rcr_rings == NULL) {
3885 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
3886 			"<== nxge_rxdma_hw_stop: NULL ring pointers"));
3887 		return;
3888 	}
3889 	ndmas = rx_rbr_rings->ndmas;
3890 	if (!ndmas) {
3891 		NXGE_DEBUG_MSG((nxgep, RX_CTL,
3892 			"<== nxge_rxdma_hw_stop: no dma channel allocated"));
3893 		return;
3894 	}
3895 
3896 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3897 		"==> nxge_rxdma_hw_stop (ndmas %d)", ndmas));
3898 
3899 	rbr_rings = rx_rbr_rings->rbr_rings;
3900 
3901 	for (i = 0; i < ndmas; i++) {
3902 		channel = rbr_rings[i]->rdc;
3903 		NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3904 			"==> nxge_rxdma_hw_stop (ndmas %d) channel %d",
3905 				ndmas, channel));
3906 		(void) nxge_rxdma_stop_channel(nxgep, channel);
3907 	}
3908 
3909 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_hw_stop: "
3910 		"rx_rbr_rings 0x%016llx rings 0x%016llx",
3911 		rx_rbr_rings, rx_rcr_rings));
3912 
3913 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "<== nxge_rxdma_hw_stop"));
3914 }
3915 
3916 
3917 static nxge_status_t
3918 nxge_rxdma_start_channel(p_nxge_t nxgep, uint16_t channel,
3919     p_rx_rbr_ring_t rbr_p, p_rx_rcr_ring_t rcr_p, p_rx_mbox_t mbox_p)
3920 
3921 {
3922 	npi_handle_t		handle;
3923 	npi_status_t		rs = NPI_SUCCESS;
3924 	rx_dma_ctl_stat_t	cs;
3925 	rx_dma_ent_msk_t	ent_mask;
3926 	nxge_status_t		status = NXGE_OK;
3927 
3928 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_start_channel"));
3929 
3930 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
3931 
3932 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "nxge_rxdma_start_channel: "
3933 		"npi handle addr $%p acc $%p",
3934 		nxgep->npi_handle.regp, nxgep->npi_handle.regh));
3935 
3936 	/* Reset RXDMA channel */
3937 	rs = npi_rxdma_cfg_rdc_reset(handle, channel);
3938 	if (rs != NPI_SUCCESS) {
3939 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
3940 			"==> nxge_rxdma_start_channel: "
3941 			"reset rxdma failed (0x%08x channel %d)",
3942 			status, channel));
3943 		return (NXGE_ERROR | rs);
3944 	}
3945 
3946 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3947 		"==> nxge_rxdma_start_channel: reset done: channel %d",
3948 		channel));
3949 
3950 	/*
3951 	 * Initialize the RXDMA channel specific FZC control
3952 	 * configurations. These FZC registers are pertaining
3953 	 * to each RX channel (logical pages).
3954 	 */
3955 	status = nxge_init_fzc_rxdma_channel(nxgep,
3956 			channel, rbr_p, rcr_p, mbox_p);
3957 	if (status != NXGE_OK) {
3958 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
3959 			"==> nxge_rxdma_start_channel: "
3960 			"init fzc rxdma failed (0x%08x channel %d)",
3961 			status, channel));
3962 		return (status);
3963 	}
3964 
3965 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
3966 		"==> nxge_rxdma_start_channel: fzc done"));
3967 
3968 	/*
3969 	 * Zero out the shadow  and prefetch ram.
3970 	 */
3971 
3972 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_start_channel: "
3973 		"ram done"));
3974 
3975 	/* Set up the interrupt event masks. */
3976 	ent_mask.value = 0;
3977 	ent_mask.value |= RX_DMA_ENT_MSK_RBREMPTY_MASK;
3978 	rs = npi_rxdma_event_mask(handle, OP_SET, channel,
3979 			&ent_mask);
3980 	if (rs != NPI_SUCCESS) {
3981 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
3982 			"==> nxge_rxdma_start_channel: "
3983 			"init rxdma event masks failed (0x%08x channel %d)",
3984 			status, channel));
3985 		return (NXGE_ERROR | rs);
3986 	}
3987 
3988 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_start_channel: "
3989 		"event done: channel %d (mask 0x%016llx)",
3990 		channel, ent_mask.value));
3991 
3992 	/* Initialize the receive DMA control and status register */
3993 	cs.value = 0;
3994 	cs.bits.hdw.mex = 1;
3995 	cs.bits.hdw.rcrthres = 1;
3996 	cs.bits.hdw.rcrto = 1;
3997 	cs.bits.hdw.rbr_empty = 1;
3998 	status = nxge_init_rxdma_channel_cntl_stat(nxgep, channel, &cs);
3999 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_start_channel: "
4000 		"channel %d rx_dma_cntl_stat 0x%0016llx", channel, cs.value));
4001 	if (status != NXGE_OK) {
4002 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
4003 			"==> nxge_rxdma_start_channel: "
4004 			"init rxdma control register failed (0x%08x channel %d",
4005 			status, channel));
4006 		return (status);
4007 	}
4008 
4009 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_start_channel: "
4010 		"control done - channel %d cs 0x%016llx", channel, cs.value));
4011 
4012 	/*
4013 	 * Load RXDMA descriptors, buffers, mailbox,
4014 	 * initialise the receive DMA channels and
4015 	 * enable each DMA channel.
4016 	 */
4017 	status = nxge_enable_rxdma_channel(nxgep,
4018 			channel, rbr_p, rcr_p, mbox_p);
4019 
4020 	if (status != NXGE_OK) {
4021 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
4022 			    " nxge_rxdma_start_channel: "
4023 			    " init enable rxdma failed (0x%08x channel %d)",
4024 			    status, channel));
4025 		return (status);
4026 	}
4027 
4028 	ent_mask.value = 0;
4029 	ent_mask.value |= (RX_DMA_ENT_MSK_WRED_DROP_MASK |
4030 				RX_DMA_ENT_MSK_PTDROP_PKT_MASK);
4031 	rs = npi_rxdma_event_mask(handle, OP_SET, channel,
4032 			&ent_mask);
4033 	if (rs != NPI_SUCCESS) {
4034 		NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
4035 			"==> nxge_rxdma_start_channel: "
4036 			"init rxdma event masks failed (0x%08x channel %d)",
4037 			status, channel));
4038 		return (NXGE_ERROR | rs);
4039 	}
4040 
4041 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_start_channel: "
4042 		"control done - channel %d cs 0x%016llx", channel, cs.value));
4043 
4044 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
4045 		"==> nxge_rxdma_start_channel: enable done"));
4046 
4047 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "<== nxge_rxdma_start_channel"));
4048 
4049 	return (NXGE_OK);
4050 }
4051 
4052 static nxge_status_t
4053 nxge_rxdma_stop_channel(p_nxge_t nxgep, uint16_t channel)
4054 {
4055 	npi_handle_t		handle;
4056 	npi_status_t		rs = NPI_SUCCESS;
4057 	rx_dma_ctl_stat_t	cs;
4058 	rx_dma_ent_msk_t	ent_mask;
4059 	nxge_status_t		status = NXGE_OK;
4060 
4061 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rxdma_stop_channel"));
4062 
4063 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
4064 
4065 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "nxge_rxdma_stop_channel: "
4066 		"npi handle addr $%p acc $%p",
4067 		nxgep->npi_handle.regp, nxgep->npi_handle.regh));
4068 
4069 	/* Reset RXDMA channel */
4070 	rs = npi_rxdma_cfg_rdc_reset(handle, channel);
4071 	if (rs != NPI_SUCCESS) {
4072 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
4073 			    " nxge_rxdma_stop_channel: "
4074 			    " reset rxdma failed (0x%08x channel %d)",
4075 			    rs, channel));
4076 		return (NXGE_ERROR | rs);
4077 	}
4078 
4079 	NXGE_DEBUG_MSG((nxgep, RX_CTL,
4080 		"==> nxge_rxdma_stop_channel: reset done"));
4081 
4082 	/* Set up the interrupt event masks. */
4083 	ent_mask.value = RX_DMA_ENT_MSK_ALL;
4084 	rs = npi_rxdma_event_mask(handle, OP_SET, channel,
4085 			&ent_mask);
4086 	if (rs != NPI_SUCCESS) {
4087 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
4088 			    "==> nxge_rxdma_stop_channel: "
4089 			    "set rxdma event masks failed (0x%08x channel %d)",
4090 			    rs, channel));
4091 		return (NXGE_ERROR | rs);
4092 	}
4093 
4094 	NXGE_DEBUG_MSG((nxgep, RX_CTL,
4095 		"==> nxge_rxdma_stop_channel: event done"));
4096 
4097 	/* Initialize the receive DMA control and status register */
4098 	cs.value = 0;
4099 	status = nxge_init_rxdma_channel_cntl_stat(nxgep, channel,
4100 			&cs);
4101 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rxdma_stop_channel: control "
4102 		" to default (all 0s) 0x%08x", cs.value));
4103 	if (status != NXGE_OK) {
4104 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
4105 			    " nxge_rxdma_stop_channel: init rxdma"
4106 			    " control register failed (0x%08x channel %d",
4107 			status, channel));
4108 		return (status);
4109 	}
4110 
4111 	NXGE_DEBUG_MSG((nxgep, RX_CTL,
4112 		"==> nxge_rxdma_stop_channel: control done"));
4113 
4114 	/* disable dma channel */
4115 	status = nxge_disable_rxdma_channel(nxgep, channel);
4116 
4117 	if (status != NXGE_OK) {
4118 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
4119 			    " nxge_rxdma_stop_channel: "
4120 			    " init enable rxdma failed (0x%08x channel %d)",
4121 			    status, channel));
4122 		return (status);
4123 	}
4124 
4125 	NXGE_DEBUG_MSG((nxgep,
4126 		RX_CTL, "==> nxge_rxdma_stop_channel: disable done"));
4127 
4128 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_rxdma_stop_channel"));
4129 
4130 	return (NXGE_OK);
4131 }
4132 
4133 nxge_status_t
4134 nxge_rxdma_handle_sys_errors(p_nxge_t nxgep)
4135 {
4136 	npi_handle_t		handle;
4137 	p_nxge_rdc_sys_stats_t	statsp;
4138 	rx_ctl_dat_fifo_stat_t	stat;
4139 	uint32_t		zcp_err_status;
4140 	uint32_t		ipp_err_status;
4141 	nxge_status_t		status = NXGE_OK;
4142 	npi_status_t		rs = NPI_SUCCESS;
4143 	boolean_t		my_err = B_FALSE;
4144 
4145 	handle = nxgep->npi_handle;
4146 	statsp = (p_nxge_rdc_sys_stats_t)&nxgep->statsp->rdc_sys_stats;
4147 
4148 	rs = npi_rxdma_rxctl_fifo_error_intr_get(handle, &stat);
4149 
4150 	if (rs != NPI_SUCCESS)
4151 		return (NXGE_ERROR | rs);
4152 
4153 	if (stat.bits.ldw.id_mismatch) {
4154 		statsp->id_mismatch++;
4155 		NXGE_FM_REPORT_ERROR(nxgep, nxgep->mac.portnum, NULL,
4156 					NXGE_FM_EREPORT_RDMC_ID_MISMATCH);
4157 		/* Global fatal error encountered */
4158 	}
4159 
4160 	if ((stat.bits.ldw.zcp_eop_err) || (stat.bits.ldw.ipp_eop_err)) {
4161 		switch (nxgep->mac.portnum) {
4162 		case 0:
4163 			if ((stat.bits.ldw.zcp_eop_err & FIFO_EOP_PORT0) ||
4164 				(stat.bits.ldw.ipp_eop_err & FIFO_EOP_PORT0)) {
4165 				my_err = B_TRUE;
4166 				zcp_err_status = stat.bits.ldw.zcp_eop_err;
4167 				ipp_err_status = stat.bits.ldw.ipp_eop_err;
4168 			}
4169 			break;
4170 		case 1:
4171 			if ((stat.bits.ldw.zcp_eop_err & FIFO_EOP_PORT1) ||
4172 				(stat.bits.ldw.ipp_eop_err & FIFO_EOP_PORT1)) {
4173 				my_err = B_TRUE;
4174 				zcp_err_status = stat.bits.ldw.zcp_eop_err;
4175 				ipp_err_status = stat.bits.ldw.ipp_eop_err;
4176 			}
4177 			break;
4178 		case 2:
4179 			if ((stat.bits.ldw.zcp_eop_err & FIFO_EOP_PORT2) ||
4180 				(stat.bits.ldw.ipp_eop_err & FIFO_EOP_PORT2)) {
4181 				my_err = B_TRUE;
4182 				zcp_err_status = stat.bits.ldw.zcp_eop_err;
4183 				ipp_err_status = stat.bits.ldw.ipp_eop_err;
4184 			}
4185 			break;
4186 		case 3:
4187 			if ((stat.bits.ldw.zcp_eop_err & FIFO_EOP_PORT3) ||
4188 				(stat.bits.ldw.ipp_eop_err & FIFO_EOP_PORT3)) {
4189 				my_err = B_TRUE;
4190 				zcp_err_status = stat.bits.ldw.zcp_eop_err;
4191 				ipp_err_status = stat.bits.ldw.ipp_eop_err;
4192 			}
4193 			break;
4194 		default:
4195 			return (NXGE_ERROR);
4196 		}
4197 	}
4198 
4199 	if (my_err) {
4200 		status = nxge_rxdma_handle_port_errors(nxgep, ipp_err_status,
4201 							zcp_err_status);
4202 		if (status != NXGE_OK)
4203 			return (status);
4204 	}
4205 
4206 	return (NXGE_OK);
4207 }
4208 
4209 static nxge_status_t
4210 nxge_rxdma_handle_port_errors(p_nxge_t nxgep, uint32_t ipp_status,
4211 							uint32_t zcp_status)
4212 {
4213 	boolean_t		rxport_fatal = B_FALSE;
4214 	p_nxge_rdc_sys_stats_t	statsp;
4215 	nxge_status_t		status = NXGE_OK;
4216 	uint8_t			portn;
4217 
4218 	portn = nxgep->mac.portnum;
4219 	statsp = (p_nxge_rdc_sys_stats_t)&nxgep->statsp->rdc_sys_stats;
4220 
4221 	if (ipp_status & (0x1 << portn)) {
4222 		statsp->ipp_eop_err++;
4223 		NXGE_FM_REPORT_ERROR(nxgep, portn, NULL,
4224 					NXGE_FM_EREPORT_RDMC_IPP_EOP_ERR);
4225 		rxport_fatal = B_TRUE;
4226 	}
4227 
4228 	if (zcp_status & (0x1 << portn)) {
4229 		statsp->zcp_eop_err++;
4230 		NXGE_FM_REPORT_ERROR(nxgep, portn, NULL,
4231 					NXGE_FM_EREPORT_RDMC_ZCP_EOP_ERR);
4232 		rxport_fatal = B_TRUE;
4233 	}
4234 
4235 	if (rxport_fatal) {
4236 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
4237 			    " nxge_rxdma_handle_port_error: "
4238 			    " fatal error on Port #%d\n",
4239 				portn));
4240 		status = nxge_rx_port_fatal_err_recover(nxgep);
4241 		if (status == NXGE_OK) {
4242 			FM_SERVICE_RESTORED(nxgep);
4243 		}
4244 	}
4245 
4246 	return (status);
4247 }
4248 
4249 static nxge_status_t
4250 nxge_rxdma_fatal_err_recover(p_nxge_t nxgep, uint16_t channel)
4251 {
4252 	npi_handle_t		handle;
4253 	npi_status_t		rs = NPI_SUCCESS;
4254 	nxge_status_t		status = NXGE_OK;
4255 	p_rx_rbr_ring_t		rbrp;
4256 	p_rx_rcr_ring_t		rcrp;
4257 	p_rx_mbox_t		mboxp;
4258 	rx_dma_ent_msk_t	ent_mask;
4259 	p_nxge_dma_common_t	dmap;
4260 	int			ring_idx;
4261 	uint32_t		ref_cnt;
4262 	p_rx_msg_t		rx_msg_p;
4263 	int			i;
4264 	uint32_t		nxge_port_rcr_size;
4265 
4266 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_rxdma_fatal_err_recover"));
4267 	NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
4268 			"Recovering from RxDMAChannel#%d error...", channel));
4269 
4270 	/*
4271 	 * Stop the dma channel waits for the stop done.
4272 	 * If the stop done bit is not set, then create
4273 	 * an error.
4274 	 */
4275 
4276 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
4277 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "Rx DMA stop..."));
4278 
4279 	ring_idx = nxge_rxdma_get_ring_index(nxgep, channel);
4280 	rbrp = (p_rx_rbr_ring_t)nxgep->rx_rbr_rings->rbr_rings[ring_idx];
4281 	rcrp = (p_rx_rcr_ring_t)nxgep->rx_rcr_rings->rcr_rings[ring_idx];
4282 
4283 	MUTEX_ENTER(&rcrp->lock);
4284 	MUTEX_ENTER(&rbrp->lock);
4285 	MUTEX_ENTER(&rbrp->post_lock);
4286 
4287 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "Disable RxDMA channel..."));
4288 
4289 	rs = npi_rxdma_cfg_rdc_disable(handle, channel);
4290 	if (rs != NPI_SUCCESS) {
4291 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
4292 			"nxge_disable_rxdma_channel:failed"));
4293 		goto fail;
4294 	}
4295 
4296 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "Disable RxDMA interrupt..."));
4297 
4298 	/* Disable interrupt */
4299 	ent_mask.value = RX_DMA_ENT_MSK_ALL;
4300 	rs = npi_rxdma_event_mask(handle, OP_SET, channel, &ent_mask);
4301 	if (rs != NPI_SUCCESS) {
4302 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
4303 				"nxge_rxdma_stop_channel: "
4304 				"set rxdma event masks failed (channel %d)",
4305 				channel));
4306 	}
4307 
4308 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "RxDMA channel reset..."));
4309 
4310 	/* Reset RXDMA channel */
4311 	rs = npi_rxdma_cfg_rdc_reset(handle, channel);
4312 	if (rs != NPI_SUCCESS) {
4313 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
4314 			"nxge_rxdma_fatal_err_recover: "
4315 				" reset rxdma failed (channel %d)", channel));
4316 		goto fail;
4317 	}
4318 
4319 	nxge_port_rcr_size = nxgep->nxge_port_rcr_size;
4320 
4321 	mboxp =
4322 	(p_rx_mbox_t)nxgep->rx_mbox_areas_p->rxmbox_areas[ring_idx];
4323 
4324 	rbrp->rbr_wr_index = (rbrp->rbb_max - 1);
4325 	rbrp->rbr_rd_index = 0;
4326 
4327 	rcrp->comp_rd_index = 0;
4328 	rcrp->comp_wt_index = 0;
4329 	rcrp->rcr_desc_rd_head_p = rcrp->rcr_desc_first_p =
4330 		(p_rcr_entry_t)DMA_COMMON_VPTR(rcrp->rcr_desc);
4331 	rcrp->rcr_desc_rd_head_pp = rcrp->rcr_desc_first_pp =
4332 #if defined(__i386)
4333 		(p_rcr_entry_t)(uint32_t)DMA_COMMON_IOADDR(rcrp->rcr_desc);
4334 #else
4335 		(p_rcr_entry_t)DMA_COMMON_IOADDR(rcrp->rcr_desc);
4336 #endif
4337 
4338 	rcrp->rcr_desc_last_p = rcrp->rcr_desc_rd_head_p +
4339 		(nxge_port_rcr_size - 1);
4340 	rcrp->rcr_desc_last_pp = rcrp->rcr_desc_rd_head_pp +
4341 		(nxge_port_rcr_size - 1);
4342 
4343 	dmap = (p_nxge_dma_common_t)&rcrp->rcr_desc;
4344 	bzero((caddr_t)dmap->kaddrp, dmap->alength);
4345 
4346 	cmn_err(CE_NOTE, "!rbr entries = %d\n", rbrp->rbr_max_size);
4347 
4348 	for (i = 0; i < rbrp->rbr_max_size; i++) {
4349 		rx_msg_p = rbrp->rx_msg_ring[i];
4350 		ref_cnt = rx_msg_p->ref_cnt;
4351 		if (ref_cnt != 1) {
4352 			if (rx_msg_p->cur_usage_cnt !=
4353 					rx_msg_p->max_usage_cnt) {
4354 				NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
4355 						"buf[%d]: cur_usage_cnt = %d "
4356 						"max_usage_cnt = %d\n", i,
4357 						rx_msg_p->cur_usage_cnt,
4358 						rx_msg_p->max_usage_cnt));
4359 			} else {
4360 				/* Buffer can be re-posted */
4361 				rx_msg_p->free = B_TRUE;
4362 				rx_msg_p->cur_usage_cnt = 0;
4363 				rx_msg_p->max_usage_cnt = 0xbaddcafe;
4364 				rx_msg_p->pkt_buf_size = 0;
4365 			}
4366 		}
4367 	}
4368 
4369 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "RxDMA channel re-start..."));
4370 
4371 	status = nxge_rxdma_start_channel(nxgep, channel, rbrp, rcrp, mboxp);
4372 	if (status != NXGE_OK) {
4373 		goto fail;
4374 	}
4375 
4376 	MUTEX_EXIT(&rbrp->post_lock);
4377 	MUTEX_EXIT(&rbrp->lock);
4378 	MUTEX_EXIT(&rcrp->lock);
4379 
4380 	NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
4381 			"Recovery Successful, RxDMAChannel#%d Restored",
4382 			channel));
4383 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rxdma_fatal_err_recover"));
4384 
4385 	return (NXGE_OK);
4386 fail:
4387 	MUTEX_EXIT(&rbrp->post_lock);
4388 	MUTEX_EXIT(&rbrp->lock);
4389 	MUTEX_EXIT(&rcrp->lock);
4390 	NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "Recovery failed"));
4391 
4392 	return (NXGE_ERROR | rs);
4393 }
4394 
4395 nxge_status_t
4396 nxge_rx_port_fatal_err_recover(p_nxge_t nxgep)
4397 {
4398 	nxge_status_t		status = NXGE_OK;
4399 	p_nxge_dma_common_t	*dma_buf_p;
4400 	uint16_t		channel;
4401 	int			ndmas;
4402 	int			i;
4403 
4404 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_rx_port_fatal_err_recover"));
4405 	NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
4406 				"Recovering from RxPort error..."));
4407 	/* Disable RxMAC */
4408 
4409 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "Disable RxMAC...\n"));
4410 	if (nxge_rx_mac_disable(nxgep) != NXGE_OK)
4411 		goto fail;
4412 
4413 	NXGE_DELAY(1000);
4414 
4415 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "Stop all RxDMA channels..."));
4416 
4417 	ndmas = nxgep->rx_buf_pool_p->ndmas;
4418 	dma_buf_p = nxgep->rx_buf_pool_p->dma_buf_pool_p;
4419 
4420 	for (i = 0; i < ndmas; i++) {
4421 		channel = ((p_nxge_dma_common_t)dma_buf_p[i])->dma_channel;
4422 		if (nxge_rxdma_fatal_err_recover(nxgep, channel) != NXGE_OK) {
4423 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
4424 					"Could not recover channel %d",
4425 					channel));
4426 		}
4427 	}
4428 
4429 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "Reset IPP..."));
4430 
4431 	/* Reset IPP */
4432 	if (nxge_ipp_reset(nxgep) != NXGE_OK) {
4433 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
4434 			"nxge_rx_port_fatal_err_recover: "
4435 			"Failed to reset IPP"));
4436 		goto fail;
4437 	}
4438 
4439 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "Reset RxMAC..."));
4440 
4441 	/* Reset RxMAC */
4442 	if (nxge_rx_mac_reset(nxgep) != NXGE_OK) {
4443 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
4444 			"nxge_rx_port_fatal_err_recover: "
4445 			"Failed to reset RxMAC"));
4446 		goto fail;
4447 	}
4448 
4449 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "Re-initialize IPP..."));
4450 
4451 	/* Re-Initialize IPP */
4452 	if (nxge_ipp_init(nxgep) != NXGE_OK) {
4453 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
4454 			"nxge_rx_port_fatal_err_recover: "
4455 			"Failed to init IPP"));
4456 		goto fail;
4457 	}
4458 
4459 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "Re-initialize RxMAC..."));
4460 
4461 	/* Re-Initialize RxMAC */
4462 	if ((status = nxge_rx_mac_init(nxgep)) != NXGE_OK) {
4463 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
4464 			"nxge_rx_port_fatal_err_recover: "
4465 			"Failed to reset RxMAC"));
4466 		goto fail;
4467 	}
4468 
4469 	NXGE_DEBUG_MSG((nxgep, RX_CTL, "Re-enable RxMAC..."));
4470 
4471 	/* Re-enable RxMAC */
4472 	if ((status = nxge_rx_mac_enable(nxgep)) != NXGE_OK) {
4473 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
4474 			"nxge_rx_port_fatal_err_recover: "
4475 			"Failed to enable RxMAC"));
4476 		goto fail;
4477 	}
4478 
4479 	NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
4480 			"Recovery Successful, RxPort Restored"));
4481 
4482 	return (NXGE_OK);
4483 fail:
4484 	NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "Recovery failed"));
4485 	return (status);
4486 }
4487 
4488 void
4489 nxge_rxdma_inject_err(p_nxge_t nxgep, uint32_t err_id, uint8_t chan)
4490 {
4491 	rx_dma_ctl_stat_t	cs;
4492 	rx_ctl_dat_fifo_stat_t	cdfs;
4493 
4494 	switch (err_id) {
4495 	case NXGE_FM_EREPORT_RDMC_RCR_ACK_ERR:
4496 	case NXGE_FM_EREPORT_RDMC_DC_FIFO_ERR:
4497 	case NXGE_FM_EREPORT_RDMC_RCR_SHA_PAR:
4498 	case NXGE_FM_EREPORT_RDMC_RBR_PRE_PAR:
4499 	case NXGE_FM_EREPORT_RDMC_RBR_TMOUT:
4500 	case NXGE_FM_EREPORT_RDMC_RSP_CNT_ERR:
4501 	case NXGE_FM_EREPORT_RDMC_BYTE_EN_BUS:
4502 	case NXGE_FM_EREPORT_RDMC_RSP_DAT_ERR:
4503 	case NXGE_FM_EREPORT_RDMC_RCRINCON:
4504 	case NXGE_FM_EREPORT_RDMC_RCRFULL:
4505 	case NXGE_FM_EREPORT_RDMC_RBRFULL:
4506 	case NXGE_FM_EREPORT_RDMC_RBRLOGPAGE:
4507 	case NXGE_FM_EREPORT_RDMC_CFIGLOGPAGE:
4508 	case NXGE_FM_EREPORT_RDMC_CONFIG_ERR:
4509 		RXDMA_REG_READ64(nxgep->npi_handle, RX_DMA_CTL_STAT_DBG_REG,
4510 			chan, &cs.value);
4511 		if (err_id == NXGE_FM_EREPORT_RDMC_RCR_ACK_ERR)
4512 			cs.bits.hdw.rcr_ack_err = 1;
4513 		else if (err_id == NXGE_FM_EREPORT_RDMC_DC_FIFO_ERR)
4514 			cs.bits.hdw.dc_fifo_err = 1;
4515 		else if (err_id == NXGE_FM_EREPORT_RDMC_RCR_SHA_PAR)
4516 			cs.bits.hdw.rcr_sha_par = 1;
4517 		else if (err_id == NXGE_FM_EREPORT_RDMC_RBR_PRE_PAR)
4518 			cs.bits.hdw.rbr_pre_par = 1;
4519 		else if (err_id == NXGE_FM_EREPORT_RDMC_RBR_TMOUT)
4520 			cs.bits.hdw.rbr_tmout = 1;
4521 		else if (err_id == NXGE_FM_EREPORT_RDMC_RSP_CNT_ERR)
4522 			cs.bits.hdw.rsp_cnt_err = 1;
4523 		else if (err_id == NXGE_FM_EREPORT_RDMC_BYTE_EN_BUS)
4524 			cs.bits.hdw.byte_en_bus = 1;
4525 		else if (err_id == NXGE_FM_EREPORT_RDMC_RSP_DAT_ERR)
4526 			cs.bits.hdw.rsp_dat_err = 1;
4527 		else if (err_id == NXGE_FM_EREPORT_RDMC_CONFIG_ERR)
4528 			cs.bits.hdw.config_err = 1;
4529 		else if (err_id == NXGE_FM_EREPORT_RDMC_RCRINCON)
4530 			cs.bits.hdw.rcrincon = 1;
4531 		else if (err_id == NXGE_FM_EREPORT_RDMC_RCRFULL)
4532 			cs.bits.hdw.rcrfull = 1;
4533 		else if (err_id == NXGE_FM_EREPORT_RDMC_RBRFULL)
4534 			cs.bits.hdw.rbrfull = 1;
4535 		else if (err_id == NXGE_FM_EREPORT_RDMC_RBRLOGPAGE)
4536 			cs.bits.hdw.rbrlogpage = 1;
4537 		else if (err_id == NXGE_FM_EREPORT_RDMC_CFIGLOGPAGE)
4538 			cs.bits.hdw.cfiglogpage = 1;
4539 #if defined(__i386)
4540 		cmn_err(CE_NOTE, "!Write 0x%llx to RX_DMA_CTL_STAT_DBG_REG\n",
4541 				cs.value);
4542 #else
4543 		cmn_err(CE_NOTE, "!Write 0x%lx to RX_DMA_CTL_STAT_DBG_REG\n",
4544 				cs.value);
4545 #endif
4546 		RXDMA_REG_WRITE64(nxgep->npi_handle, RX_DMA_CTL_STAT_DBG_REG,
4547 			chan, cs.value);
4548 		break;
4549 	case NXGE_FM_EREPORT_RDMC_ID_MISMATCH:
4550 	case NXGE_FM_EREPORT_RDMC_ZCP_EOP_ERR:
4551 	case NXGE_FM_EREPORT_RDMC_IPP_EOP_ERR:
4552 		cdfs.value = 0;
4553 		if (err_id ==  NXGE_FM_EREPORT_RDMC_ID_MISMATCH)
4554 			cdfs.bits.ldw.id_mismatch = (1 << nxgep->mac.portnum);
4555 		else if (err_id == NXGE_FM_EREPORT_RDMC_ZCP_EOP_ERR)
4556 			cdfs.bits.ldw.zcp_eop_err = (1 << nxgep->mac.portnum);
4557 		else if (err_id == NXGE_FM_EREPORT_RDMC_IPP_EOP_ERR)
4558 			cdfs.bits.ldw.ipp_eop_err = (1 << nxgep->mac.portnum);
4559 #if defined(__i386)
4560 		cmn_err(CE_NOTE,
4561 			"!Write 0x%llx to RX_CTL_DAT_FIFO_STAT_DBG_REG\n",
4562 			cdfs.value);
4563 #else
4564 		cmn_err(CE_NOTE,
4565 			"!Write 0x%lx to RX_CTL_DAT_FIFO_STAT_DBG_REG\n",
4566 			cdfs.value);
4567 #endif
4568 		RXDMA_REG_WRITE64(nxgep->npi_handle,
4569 			RX_CTL_DAT_FIFO_STAT_DBG_REG, chan, cdfs.value);
4570 		break;
4571 	case NXGE_FM_EREPORT_RDMC_DCF_ERR:
4572 		break;
4573 	case NXGE_FM_EREPORT_RDMC_RCR_ERR:
4574 		break;
4575 	}
4576 }
4577