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