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