13859Sml29623 /* 23859Sml29623 * CDDL HEADER START 33859Sml29623 * 43859Sml29623 * The contents of this file are subject to the terms of the 53859Sml29623 * Common Development and Distribution License (the "License"). 63859Sml29623 * You may not use this file except in compliance with the License. 73859Sml29623 * 83859Sml29623 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 93859Sml29623 * or http://www.opensolaris.org/os/licensing. 103859Sml29623 * See the License for the specific language governing permissions 113859Sml29623 * and limitations under the License. 123859Sml29623 * 133859Sml29623 * When distributing Covered Code, include this CDDL HEADER in each 143859Sml29623 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 153859Sml29623 * If applicable, add the following below this CDDL HEADER, with the 163859Sml29623 * fields enclosed by brackets "[]" replaced with your own identifying 173859Sml29623 * information: Portions Copyright [yyyy] [name of copyright owner] 183859Sml29623 * 193859Sml29623 * CDDL HEADER END 203859Sml29623 */ 213859Sml29623 /* 225759Smisaki * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 233859Sml29623 * Use is subject to license terms. 243859Sml29623 */ 253859Sml29623 263859Sml29623 #pragma ident "%Z%%M% %I% %E% SMI" 273859Sml29623 283859Sml29623 #include <sys/nxge/nxge_impl.h> 293859Sml29623 #include <sys/nxge/nxge_rxdma.h> 306495Sspeer #include <sys/nxge/nxge_hio.h> 316495Sspeer 326495Sspeer #if !defined(_BIG_ENDIAN) 336495Sspeer #include <npi_rx_rd32.h> 346495Sspeer #endif 356495Sspeer #include <npi_rx_rd64.h> 366495Sspeer #include <npi_rx_wr64.h> 373859Sml29623 383859Sml29623 #define NXGE_ACTUAL_RDCGRP(nxgep, rdcgrp) \ 396495Sspeer (rdcgrp + nxgep->pt_config.hw_config.def_mac_rxdma_grpid) 403859Sml29623 #define NXGE_ACTUAL_RDC(nxgep, rdc) \ 413859Sml29623 (rdc + nxgep->pt_config.hw_config.start_rdc) 423859Sml29623 433859Sml29623 /* 443859Sml29623 * Globals: tunable parameters (/etc/system or adb) 453859Sml29623 * 463859Sml29623 */ 473859Sml29623 extern uint32_t nxge_rbr_size; 483859Sml29623 extern uint32_t nxge_rcr_size; 493859Sml29623 extern uint32_t nxge_rbr_spare_size; 503859Sml29623 513859Sml29623 extern uint32_t nxge_mblks_pending; 523859Sml29623 533859Sml29623 /* 543859Sml29623 * Tunable to reduce the amount of time spent in the 553859Sml29623 * ISR doing Rx Processing. 563859Sml29623 */ 573859Sml29623 extern uint32_t nxge_max_rx_pkts; 583859Sml29623 boolean_t nxge_jumbo_enable; 593859Sml29623 603859Sml29623 /* 613859Sml29623 * Tunables to manage the receive buffer blocks. 623859Sml29623 * 633859Sml29623 * nxge_rx_threshold_hi: copy all buffers. 643859Sml29623 * nxge_rx_bcopy_size_type: receive buffer block size type. 653859Sml29623 * nxge_rx_threshold_lo: copy only up to tunable block size type. 663859Sml29623 */ 673859Sml29623 extern nxge_rxbuf_threshold_t nxge_rx_threshold_hi; 683859Sml29623 extern nxge_rxbuf_type_t nxge_rx_buf_size_type; 693859Sml29623 extern nxge_rxbuf_threshold_t nxge_rx_threshold_lo; 703859Sml29623 71*6611Sml29623 extern uint32_t nxge_cksum_offload; 726495Sspeer 736495Sspeer static nxge_status_t nxge_map_rxdma(p_nxge_t, int); 746495Sspeer static void nxge_unmap_rxdma(p_nxge_t, int); 753859Sml29623 763859Sml29623 static nxge_status_t nxge_rxdma_hw_start_common(p_nxge_t); 776495Sspeer 786495Sspeer static nxge_status_t nxge_rxdma_hw_start(p_nxge_t, int); 796495Sspeer static void nxge_rxdma_hw_stop(p_nxge_t, int); 803859Sml29623 813859Sml29623 static nxge_status_t nxge_map_rxdma_channel(p_nxge_t, uint16_t, 823859Sml29623 p_nxge_dma_common_t *, p_rx_rbr_ring_t *, 833859Sml29623 uint32_t, 843859Sml29623 p_nxge_dma_common_t *, p_rx_rcr_ring_t *, 853859Sml29623 p_rx_mbox_t *); 863859Sml29623 static void nxge_unmap_rxdma_channel(p_nxge_t, uint16_t, 873859Sml29623 p_rx_rbr_ring_t, p_rx_rcr_ring_t, p_rx_mbox_t); 883859Sml29623 893859Sml29623 static nxge_status_t nxge_map_rxdma_channel_cfg_ring(p_nxge_t, 903859Sml29623 uint16_t, 913859Sml29623 p_nxge_dma_common_t *, p_rx_rbr_ring_t *, 923859Sml29623 p_rx_rcr_ring_t *, p_rx_mbox_t *); 933859Sml29623 static void nxge_unmap_rxdma_channel_cfg_ring(p_nxge_t, 943859Sml29623 p_rx_rcr_ring_t, p_rx_mbox_t); 953859Sml29623 963859Sml29623 static nxge_status_t nxge_map_rxdma_channel_buf_ring(p_nxge_t, 973859Sml29623 uint16_t, 983859Sml29623 p_nxge_dma_common_t *, 993859Sml29623 p_rx_rbr_ring_t *, uint32_t); 1003859Sml29623 static void nxge_unmap_rxdma_channel_buf_ring(p_nxge_t, 1013859Sml29623 p_rx_rbr_ring_t); 1023859Sml29623 1033859Sml29623 static nxge_status_t nxge_rxdma_start_channel(p_nxge_t, uint16_t, 1043859Sml29623 p_rx_rbr_ring_t, p_rx_rcr_ring_t, p_rx_mbox_t); 1053859Sml29623 static nxge_status_t nxge_rxdma_stop_channel(p_nxge_t, uint16_t); 1063859Sml29623 1076495Sspeer static mblk_t * 1086495Sspeer nxge_rx_pkts(p_nxge_t, p_rx_rcr_ring_t, rx_dma_ctl_stat_t, int); 1093859Sml29623 1103859Sml29623 static void nxge_receive_packet(p_nxge_t, 1113859Sml29623 p_rx_rcr_ring_t, 1123859Sml29623 p_rcr_entry_t, 1133859Sml29623 boolean_t *, 1143859Sml29623 mblk_t **, mblk_t **); 1153859Sml29623 1163859Sml29623 nxge_status_t nxge_disable_rxdma_channel(p_nxge_t, uint16_t); 1173859Sml29623 1183859Sml29623 static p_rx_msg_t nxge_allocb(size_t, uint32_t, p_nxge_dma_common_t); 1193859Sml29623 static void nxge_freeb(p_rx_msg_t); 1206495Sspeer static void nxge_rx_pkts_vring(p_nxge_t, uint_t, rx_dma_ctl_stat_t); 1216495Sspeer static nxge_status_t nxge_rx_err_evnts(p_nxge_t, int, rx_dma_ctl_stat_t); 1223859Sml29623 1233859Sml29623 static nxge_status_t nxge_rxdma_handle_port_errors(p_nxge_t, 1243859Sml29623 uint32_t, uint32_t); 1253859Sml29623 1263859Sml29623 static nxge_status_t nxge_rxbuf_index_info_init(p_nxge_t, 1273859Sml29623 p_rx_rbr_ring_t); 1283859Sml29623 1293859Sml29623 1303859Sml29623 static nxge_status_t 1313859Sml29623 nxge_rxdma_fatal_err_recover(p_nxge_t, uint16_t); 1323859Sml29623 1333859Sml29623 nxge_status_t 1343859Sml29623 nxge_rx_port_fatal_err_recover(p_nxge_t); 1353859Sml29623 1366495Sspeer static void nxge_rxdma_databuf_free(p_rx_rbr_ring_t); 1376495Sspeer 1383859Sml29623 nxge_status_t 1393859Sml29623 nxge_init_rxdma_channels(p_nxge_t nxgep) 1403859Sml29623 { 1416495Sspeer nxge_grp_set_t *set = &nxgep->rx_set; 1426495Sspeer int i, count; 1433859Sml29623 1443859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_init_rxdma_channels")); 1453859Sml29623 1466495Sspeer if (!isLDOMguest(nxgep)) { 1476495Sspeer if (nxge_rxdma_hw_start_common(nxgep) != NXGE_OK) { 1486495Sspeer cmn_err(CE_NOTE, "hw_start_common"); 1496495Sspeer return (NXGE_ERROR); 1506495Sspeer } 1516495Sspeer } 1526495Sspeer 1536495Sspeer /* 1546495Sspeer * NXGE_LOGICAL_GROUP_MAX > NXGE_MAX_RDC_GROUPS (8) 1556495Sspeer * We only have 8 hardware RDC tables, but we may have 1566495Sspeer * up to 16 logical (software-defined) groups of RDCS, 1576495Sspeer * if we make use of layer 3 & 4 hardware classification. 1586495Sspeer */ 1596495Sspeer for (i = 0, count = 0; i < NXGE_LOGICAL_GROUP_MAX; i++) { 1606495Sspeer if ((1 << i) & set->lg.map) { 1616495Sspeer int channel; 1626495Sspeer nxge_grp_t *group = set->group[i]; 1636495Sspeer for (channel = 0; channel < NXGE_MAX_RDCS; channel++) { 1646495Sspeer if ((1 << channel) & group->map) { 1656495Sspeer if ((nxge_grp_dc_add(nxgep, 1666495Sspeer (vr_handle_t)group, 1676495Sspeer VP_BOUND_RX, channel))) 1686495Sspeer return (NXGE_ERROR); 1696495Sspeer } 1706495Sspeer } 1716495Sspeer } 1726495Sspeer if (++count == set->lg.count) 1736495Sspeer break; 1746495Sspeer } 1756495Sspeer 1766495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "<== nxge_init_rxdma_channels")); 1776495Sspeer 1786495Sspeer return (NXGE_OK); 1796495Sspeer } 1806495Sspeer 1816495Sspeer nxge_status_t 1826495Sspeer nxge_init_rxdma_channel(p_nxge_t nxge, int channel) 1836495Sspeer { 1846495Sspeer nxge_status_t status; 1856495Sspeer 1866495Sspeer NXGE_DEBUG_MSG((nxge, MEM2_CTL, "==> nxge_init_rxdma_channel")); 1876495Sspeer 1886495Sspeer status = nxge_map_rxdma(nxge, channel); 1893859Sml29623 if (status != NXGE_OK) { 1906495Sspeer NXGE_ERROR_MSG((nxge, NXGE_ERR_CTL, 1916495Sspeer "<== nxge_init_rxdma: status 0x%x", status)); 1923859Sml29623 return (status); 1933859Sml29623 } 1943859Sml29623 1956495Sspeer status = nxge_rxdma_hw_start(nxge, channel); 1963859Sml29623 if (status != NXGE_OK) { 1976495Sspeer nxge_unmap_rxdma(nxge, channel); 1983859Sml29623 } 1993859Sml29623 2006495Sspeer if (!nxge->statsp->rdc_ksp[channel]) 2016495Sspeer nxge_setup_rdc_kstats(nxge, channel); 2026495Sspeer 2036495Sspeer NXGE_DEBUG_MSG((nxge, MEM2_CTL, 2046495Sspeer "<== nxge_init_rxdma_channel: status 0x%x", status)); 2053859Sml29623 2063859Sml29623 return (status); 2073859Sml29623 } 2083859Sml29623 2093859Sml29623 void 2103859Sml29623 nxge_uninit_rxdma_channels(p_nxge_t nxgep) 2113859Sml29623 { 2126495Sspeer nxge_grp_set_t *set = &nxgep->rx_set; 2136495Sspeer int rdc; 2146495Sspeer 2153859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_uninit_rxdma_channels")); 2163859Sml29623 2176495Sspeer if (set->owned.map == 0) { 2186495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 2196495Sspeer "nxge_uninit_rxdma_channels: no channels")); 2206495Sspeer return; 2216495Sspeer } 2226495Sspeer 2236495Sspeer for (rdc = 0; rdc < NXGE_MAX_RDCS; rdc++) { 2246495Sspeer if ((1 << rdc) & set->owned.map) { 2256495Sspeer nxge_grp_dc_remove(nxgep, VP_BOUND_RX, rdc); 2266495Sspeer } 2276495Sspeer } 2286495Sspeer 2296495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "<== nxge_uninit_rxdma_channels")); 2306495Sspeer } 2316495Sspeer 2326495Sspeer void 2336495Sspeer nxge_uninit_rxdma_channel(p_nxge_t nxgep, int channel) 2346495Sspeer { 2356495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_uninit_rxdma_channel")); 2366495Sspeer 2376495Sspeer if (nxgep->statsp->rdc_ksp[channel]) { 2386495Sspeer kstat_delete(nxgep->statsp->rdc_ksp[channel]); 2396495Sspeer nxgep->statsp->rdc_ksp[channel] = 0; 2406495Sspeer } 2416495Sspeer 2426495Sspeer nxge_rxdma_hw_stop(nxgep, channel); 2436495Sspeer nxge_unmap_rxdma(nxgep, channel); 2446495Sspeer 2456495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "<== nxge_uinit_rxdma_channel")); 2463859Sml29623 } 2473859Sml29623 2483859Sml29623 nxge_status_t 2493859Sml29623 nxge_reset_rxdma_channel(p_nxge_t nxgep, uint16_t channel) 2503859Sml29623 { 2513859Sml29623 npi_handle_t handle; 2523859Sml29623 npi_status_t rs = NPI_SUCCESS; 2533859Sml29623 nxge_status_t status = NXGE_OK; 2543859Sml29623 2553859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_reset_rxdma_channel")); 2563859Sml29623 2573859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 2583859Sml29623 rs = npi_rxdma_cfg_rdc_reset(handle, channel); 2593859Sml29623 2603859Sml29623 if (rs != NPI_SUCCESS) { 2613859Sml29623 status = NXGE_ERROR | rs; 2623859Sml29623 } 2633859Sml29623 2643859Sml29623 return (status); 2653859Sml29623 } 2663859Sml29623 2673859Sml29623 void 2683859Sml29623 nxge_rxdma_regs_dump_channels(p_nxge_t nxgep) 2693859Sml29623 { 2706495Sspeer nxge_grp_set_t *set = &nxgep->rx_set; 2716495Sspeer int rdc; 2723859Sml29623 2733859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rxdma_regs_dump_channels")); 2743859Sml29623 2756495Sspeer if (!isLDOMguest(nxgep)) { 2766495Sspeer npi_handle_t handle = NXGE_DEV_NPI_HANDLE(nxgep); 2776495Sspeer (void) npi_rxdma_dump_fzc_regs(handle); 2786495Sspeer } 2796495Sspeer 2806495Sspeer if (nxgep->rx_rbr_rings == 0 || nxgep->rx_rbr_rings->rbr_rings == 0) { 2816495Sspeer NXGE_DEBUG_MSG((nxgep, TX_CTL, 2826495Sspeer "nxge_rxdma_regs_dump_channels: " 2836495Sspeer "NULL ring pointer(s)")); 2843859Sml29623 return; 2853859Sml29623 } 2866495Sspeer 2876495Sspeer if (set->owned.map == 0) { 2883859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 2896495Sspeer "nxge_rxdma_regs_dump_channels: no channels")); 2903859Sml29623 return; 2913859Sml29623 } 2923859Sml29623 2936495Sspeer for (rdc = 0; rdc < NXGE_MAX_RDCS; rdc++) { 2946495Sspeer if ((1 << rdc) & set->owned.map) { 2956495Sspeer rx_rbr_ring_t *ring = 2966495Sspeer nxgep->rx_rbr_rings->rbr_rings[rdc]; 2976495Sspeer if (ring) { 2986495Sspeer (void) nxge_dump_rxdma_channel(nxgep, rdc); 2996495Sspeer } 3003859Sml29623 } 3013859Sml29623 } 3023859Sml29623 3033859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_rxdma_regs_dump")); 3043859Sml29623 } 3053859Sml29623 3063859Sml29623 nxge_status_t 3073859Sml29623 nxge_dump_rxdma_channel(p_nxge_t nxgep, uint8_t channel) 3083859Sml29623 { 3093859Sml29623 npi_handle_t handle; 3103859Sml29623 npi_status_t rs = NPI_SUCCESS; 3113859Sml29623 nxge_status_t status = NXGE_OK; 3123859Sml29623 3133859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_dump_rxdma_channel")); 3143859Sml29623 3153859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 3163859Sml29623 rs = npi_rxdma_dump_rdc_regs(handle, channel); 3173859Sml29623 3183859Sml29623 if (rs != NPI_SUCCESS) { 3193859Sml29623 status = NXGE_ERROR | rs; 3203859Sml29623 } 3213859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_dump_rxdma_channel")); 3223859Sml29623 return (status); 3233859Sml29623 } 3243859Sml29623 3253859Sml29623 nxge_status_t 3263859Sml29623 nxge_init_rxdma_channel_event_mask(p_nxge_t nxgep, uint16_t channel, 3273859Sml29623 p_rx_dma_ent_msk_t mask_p) 3283859Sml29623 { 3293859Sml29623 npi_handle_t handle; 3303859Sml29623 npi_status_t rs = NPI_SUCCESS; 3313859Sml29623 nxge_status_t status = NXGE_OK; 3323859Sml29623 3333859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, 3343859Sml29623 "<== nxge_init_rxdma_channel_event_mask")); 3353859Sml29623 3363859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 3373859Sml29623 rs = npi_rxdma_event_mask(handle, OP_SET, channel, mask_p); 3383859Sml29623 if (rs != NPI_SUCCESS) { 3393859Sml29623 status = NXGE_ERROR | rs; 3403859Sml29623 } 3413859Sml29623 3423859Sml29623 return (status); 3433859Sml29623 } 3443859Sml29623 3453859Sml29623 nxge_status_t 3463859Sml29623 nxge_init_rxdma_channel_cntl_stat(p_nxge_t nxgep, uint16_t channel, 3473859Sml29623 p_rx_dma_ctl_stat_t cs_p) 3483859Sml29623 { 3493859Sml29623 npi_handle_t handle; 3503859Sml29623 npi_status_t rs = NPI_SUCCESS; 3513859Sml29623 nxge_status_t status = NXGE_OK; 3523859Sml29623 3533859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, 3543859Sml29623 "<== nxge_init_rxdma_channel_cntl_stat")); 3553859Sml29623 3563859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 3573859Sml29623 rs = npi_rxdma_control_status(handle, OP_SET, channel, cs_p); 3583859Sml29623 3593859Sml29623 if (rs != NPI_SUCCESS) { 3603859Sml29623 status = NXGE_ERROR | rs; 3613859Sml29623 } 3623859Sml29623 3633859Sml29623 return (status); 3643859Sml29623 } 3653859Sml29623 3666495Sspeer /* 3676495Sspeer * nxge_rxdma_cfg_rdcgrp_default_rdc 3686495Sspeer * 3696495Sspeer * Set the default RDC for an RDC Group (Table) 3706495Sspeer * 3716495Sspeer * Arguments: 3726495Sspeer * nxgep 3736495Sspeer * rdcgrp The group to modify 3746495Sspeer * rdc The new default RDC. 3756495Sspeer * 3766495Sspeer * Notes: 3776495Sspeer * 3786495Sspeer * NPI/NXGE function calls: 3796495Sspeer * npi_rxdma_cfg_rdc_table_default_rdc() 3806495Sspeer * 3816495Sspeer * Registers accessed: 3826495Sspeer * RDC_TBL_REG: FZC_ZCP + 0x10000 3836495Sspeer * 3846495Sspeer * Context: 3856495Sspeer * Service domain 3866495Sspeer */ 3873859Sml29623 nxge_status_t 3886495Sspeer nxge_rxdma_cfg_rdcgrp_default_rdc( 3896495Sspeer p_nxge_t nxgep, 3906495Sspeer uint8_t rdcgrp, 3916495Sspeer uint8_t rdc) 3923859Sml29623 { 3933859Sml29623 npi_handle_t handle; 3943859Sml29623 npi_status_t rs = NPI_SUCCESS; 3953859Sml29623 p_nxge_dma_pt_cfg_t p_dma_cfgp; 3963859Sml29623 p_nxge_rdc_grp_t rdc_grp_p; 3973859Sml29623 uint8_t actual_rdcgrp, actual_rdc; 3983859Sml29623 3993859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 4003859Sml29623 " ==> nxge_rxdma_cfg_rdcgrp_default_rdc")); 4013859Sml29623 p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config; 4023859Sml29623 4033859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 4043859Sml29623 4056495Sspeer /* 4066495Sspeer * This has to be rewritten. Do we even allow this anymore? 4076495Sspeer */ 4083859Sml29623 rdc_grp_p = &p_dma_cfgp->rdc_grps[rdcgrp]; 4096495Sspeer RDC_MAP_IN(rdc_grp_p->map, rdc); 4106495Sspeer rdc_grp_p->def_rdc = rdc; 4113859Sml29623 4123859Sml29623 actual_rdcgrp = NXGE_ACTUAL_RDCGRP(nxgep, rdcgrp); 4133859Sml29623 actual_rdc = NXGE_ACTUAL_RDC(nxgep, rdc); 4143859Sml29623 4156495Sspeer rs = npi_rxdma_cfg_rdc_table_default_rdc( 4166495Sspeer handle, actual_rdcgrp, actual_rdc); 4173859Sml29623 4183859Sml29623 if (rs != NPI_SUCCESS) { 4193859Sml29623 return (NXGE_ERROR | rs); 4203859Sml29623 } 4213859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 4223859Sml29623 " <== nxge_rxdma_cfg_rdcgrp_default_rdc")); 4233859Sml29623 return (NXGE_OK); 4243859Sml29623 } 4253859Sml29623 4263859Sml29623 nxge_status_t 4273859Sml29623 nxge_rxdma_cfg_port_default_rdc(p_nxge_t nxgep, uint8_t port, uint8_t rdc) 4283859Sml29623 { 4293859Sml29623 npi_handle_t handle; 4303859Sml29623 4313859Sml29623 uint8_t actual_rdc; 4323859Sml29623 npi_status_t rs = NPI_SUCCESS; 4333859Sml29623 4343859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 4353859Sml29623 " ==> nxge_rxdma_cfg_port_default_rdc")); 4363859Sml29623 4373859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 4386495Sspeer actual_rdc = rdc; /* XXX Hack! */ 4393859Sml29623 rs = npi_rxdma_cfg_default_port_rdc(handle, port, actual_rdc); 4403859Sml29623 4413859Sml29623 4423859Sml29623 if (rs != NPI_SUCCESS) { 4433859Sml29623 return (NXGE_ERROR | rs); 4443859Sml29623 } 4453859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 4463859Sml29623 " <== nxge_rxdma_cfg_port_default_rdc")); 4473859Sml29623 4483859Sml29623 return (NXGE_OK); 4493859Sml29623 } 4503859Sml29623 4513859Sml29623 nxge_status_t 4523859Sml29623 nxge_rxdma_cfg_rcr_threshold(p_nxge_t nxgep, uint8_t channel, 4533859Sml29623 uint16_t pkts) 4543859Sml29623 { 4553859Sml29623 npi_status_t rs = NPI_SUCCESS; 4563859Sml29623 npi_handle_t handle; 4573859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 4583859Sml29623 " ==> nxge_rxdma_cfg_rcr_threshold")); 4593859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 4603859Sml29623 4613859Sml29623 rs = npi_rxdma_cfg_rdc_rcr_threshold(handle, channel, pkts); 4623859Sml29623 4633859Sml29623 if (rs != NPI_SUCCESS) { 4643859Sml29623 return (NXGE_ERROR | rs); 4653859Sml29623 } 4663859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, " <== nxge_rxdma_cfg_rcr_threshold")); 4673859Sml29623 return (NXGE_OK); 4683859Sml29623 } 4693859Sml29623 4703859Sml29623 nxge_status_t 4713859Sml29623 nxge_rxdma_cfg_rcr_timeout(p_nxge_t nxgep, uint8_t channel, 4723859Sml29623 uint16_t tout, uint8_t enable) 4733859Sml29623 { 4743859Sml29623 npi_status_t rs = NPI_SUCCESS; 4753859Sml29623 npi_handle_t handle; 4763859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, " ==> nxge_rxdma_cfg_rcr_timeout")); 4773859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 4783859Sml29623 if (enable == 0) { 4793859Sml29623 rs = npi_rxdma_cfg_rdc_rcr_timeout_disable(handle, channel); 4803859Sml29623 } else { 4813859Sml29623 rs = npi_rxdma_cfg_rdc_rcr_timeout(handle, channel, 4823859Sml29623 tout); 4833859Sml29623 } 4843859Sml29623 4853859Sml29623 if (rs != NPI_SUCCESS) { 4863859Sml29623 return (NXGE_ERROR | rs); 4873859Sml29623 } 4883859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, " <== nxge_rxdma_cfg_rcr_timeout")); 4893859Sml29623 return (NXGE_OK); 4903859Sml29623 } 4913859Sml29623 4923859Sml29623 nxge_status_t 4933859Sml29623 nxge_enable_rxdma_channel(p_nxge_t nxgep, uint16_t channel, 4943859Sml29623 p_rx_rbr_ring_t rbr_p, p_rx_rcr_ring_t rcr_p, p_rx_mbox_t mbox_p) 4953859Sml29623 { 4963859Sml29623 npi_handle_t handle; 4973859Sml29623 rdc_desc_cfg_t rdc_desc; 4983859Sml29623 p_rcrcfig_b_t cfgb_p; 4993859Sml29623 npi_status_t rs = NPI_SUCCESS; 5003859Sml29623 5013859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_enable_rxdma_channel")); 5023859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 5033859Sml29623 /* 5043859Sml29623 * Use configuration data composed at init time. 5053859Sml29623 * Write to hardware the receive ring configurations. 5063859Sml29623 */ 5073859Sml29623 rdc_desc.mbox_enable = 1; 5083859Sml29623 rdc_desc.mbox_addr = mbox_p->mbox_addr; 5093859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 5103859Sml29623 "==> nxge_enable_rxdma_channel: mboxp $%p($%p)", 5113859Sml29623 mbox_p->mbox_addr, rdc_desc.mbox_addr)); 5123859Sml29623 5133859Sml29623 rdc_desc.rbr_len = rbr_p->rbb_max; 5143859Sml29623 rdc_desc.rbr_addr = rbr_p->rbr_addr; 5153859Sml29623 5163859Sml29623 switch (nxgep->rx_bksize_code) { 5173859Sml29623 case RBR_BKSIZE_4K: 5183859Sml29623 rdc_desc.page_size = SIZE_4KB; 5193859Sml29623 break; 5203859Sml29623 case RBR_BKSIZE_8K: 5213859Sml29623 rdc_desc.page_size = SIZE_8KB; 5223859Sml29623 break; 5233859Sml29623 case RBR_BKSIZE_16K: 5243859Sml29623 rdc_desc.page_size = SIZE_16KB; 5253859Sml29623 break; 5263859Sml29623 case RBR_BKSIZE_32K: 5273859Sml29623 rdc_desc.page_size = SIZE_32KB; 5283859Sml29623 break; 5293859Sml29623 } 5303859Sml29623 5313859Sml29623 rdc_desc.size0 = rbr_p->npi_pkt_buf_size0; 5323859Sml29623 rdc_desc.valid0 = 1; 5333859Sml29623 5343859Sml29623 rdc_desc.size1 = rbr_p->npi_pkt_buf_size1; 5353859Sml29623 rdc_desc.valid1 = 1; 5363859Sml29623 5373859Sml29623 rdc_desc.size2 = rbr_p->npi_pkt_buf_size2; 5383859Sml29623 rdc_desc.valid2 = 1; 5393859Sml29623 5403859Sml29623 rdc_desc.full_hdr = rcr_p->full_hdr_flag; 5413859Sml29623 rdc_desc.offset = rcr_p->sw_priv_hdr_len; 5423859Sml29623 5433859Sml29623 rdc_desc.rcr_len = rcr_p->comp_size; 5443859Sml29623 rdc_desc.rcr_addr = rcr_p->rcr_addr; 5453859Sml29623 5463859Sml29623 cfgb_p = &(rcr_p->rcr_cfgb); 5473859Sml29623 rdc_desc.rcr_threshold = cfgb_p->bits.ldw.pthres; 5486495Sspeer /* For now, disable this timeout in a guest domain. */ 5496495Sspeer if (isLDOMguest(nxgep)) { 5506495Sspeer rdc_desc.rcr_timeout = 0; 5516495Sspeer rdc_desc.rcr_timeout_enable = 0; 5526495Sspeer } else { 5536495Sspeer rdc_desc.rcr_timeout = cfgb_p->bits.ldw.timeout; 5546495Sspeer rdc_desc.rcr_timeout_enable = cfgb_p->bits.ldw.entout; 5556495Sspeer } 5563859Sml29623 5573859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_enable_rxdma_channel: " 5583859Sml29623 "rbr_len qlen %d pagesize code %d rcr_len %d", 5593859Sml29623 rdc_desc.rbr_len, rdc_desc.page_size, rdc_desc.rcr_len)); 5603859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_enable_rxdma_channel: " 5613859Sml29623 "size 0 %d size 1 %d size 2 %d", 5623859Sml29623 rbr_p->npi_pkt_buf_size0, rbr_p->npi_pkt_buf_size1, 5633859Sml29623 rbr_p->npi_pkt_buf_size2)); 5643859Sml29623 5653859Sml29623 rs = npi_rxdma_cfg_rdc_ring(handle, rbr_p->rdc, &rdc_desc); 5663859Sml29623 if (rs != NPI_SUCCESS) { 5673859Sml29623 return (NXGE_ERROR | rs); 5683859Sml29623 } 5693859Sml29623 5703859Sml29623 /* 5713859Sml29623 * Enable the timeout and threshold. 5723859Sml29623 */ 5733859Sml29623 rs = npi_rxdma_cfg_rdc_rcr_threshold(handle, channel, 5743859Sml29623 rdc_desc.rcr_threshold); 5753859Sml29623 if (rs != NPI_SUCCESS) { 5763859Sml29623 return (NXGE_ERROR | rs); 5773859Sml29623 } 5783859Sml29623 5793859Sml29623 rs = npi_rxdma_cfg_rdc_rcr_timeout(handle, channel, 5803859Sml29623 rdc_desc.rcr_timeout); 5813859Sml29623 if (rs != NPI_SUCCESS) { 5823859Sml29623 return (NXGE_ERROR | rs); 5833859Sml29623 } 5843859Sml29623 5853859Sml29623 /* Enable the DMA */ 5863859Sml29623 rs = npi_rxdma_cfg_rdc_enable(handle, channel); 5873859Sml29623 if (rs != NPI_SUCCESS) { 5883859Sml29623 return (NXGE_ERROR | rs); 5893859Sml29623 } 5903859Sml29623 5913859Sml29623 /* Kick the DMA engine. */ 5923859Sml29623 npi_rxdma_rdc_rbr_kick(handle, channel, rbr_p->rbb_max); 5933859Sml29623 /* Clear the rbr empty bit */ 5943859Sml29623 (void) npi_rxdma_channel_rbr_empty_clear(handle, channel); 5953859Sml29623 5963859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_enable_rxdma_channel")); 5973859Sml29623 5983859Sml29623 return (NXGE_OK); 5993859Sml29623 } 6003859Sml29623 6013859Sml29623 nxge_status_t 6023859Sml29623 nxge_disable_rxdma_channel(p_nxge_t nxgep, uint16_t channel) 6033859Sml29623 { 6043859Sml29623 npi_handle_t handle; 6053859Sml29623 npi_status_t rs = NPI_SUCCESS; 6063859Sml29623 6073859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_disable_rxdma_channel")); 6083859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 6093859Sml29623 6103859Sml29623 /* disable the DMA */ 6113859Sml29623 rs = npi_rxdma_cfg_rdc_disable(handle, channel); 6123859Sml29623 if (rs != NPI_SUCCESS) { 6133859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 6143859Sml29623 "<== nxge_disable_rxdma_channel:failed (0x%x)", 6153859Sml29623 rs)); 6163859Sml29623 return (NXGE_ERROR | rs); 6173859Sml29623 } 6183859Sml29623 6193859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_disable_rxdma_channel")); 6203859Sml29623 return (NXGE_OK); 6213859Sml29623 } 6223859Sml29623 6233859Sml29623 nxge_status_t 6243859Sml29623 nxge_rxdma_channel_rcrflush(p_nxge_t nxgep, uint8_t channel) 6253859Sml29623 { 6263859Sml29623 npi_handle_t handle; 6273859Sml29623 nxge_status_t status = NXGE_OK; 6283859Sml29623 6293859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, 6303859Sml29623 "<== nxge_init_rxdma_channel_rcrflush")); 6313859Sml29623 6323859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 6333859Sml29623 npi_rxdma_rdc_rcr_flush(handle, channel); 6343859Sml29623 6353859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, 6363859Sml29623 "<== nxge_init_rxdma_channel_rcrflsh")); 6373859Sml29623 return (status); 6383859Sml29623 6393859Sml29623 } 6403859Sml29623 6413859Sml29623 #define MID_INDEX(l, r) ((r + l + 1) >> 1) 6423859Sml29623 6433859Sml29623 #define TO_LEFT -1 6443859Sml29623 #define TO_RIGHT 1 6453859Sml29623 #define BOTH_RIGHT (TO_RIGHT + TO_RIGHT) 6463859Sml29623 #define BOTH_LEFT (TO_LEFT + TO_LEFT) 6473859Sml29623 #define IN_MIDDLE (TO_RIGHT + TO_LEFT) 6483859Sml29623 #define NO_HINT 0xffffffff 6493859Sml29623 6503859Sml29623 /*ARGSUSED*/ 6513859Sml29623 nxge_status_t 6523859Sml29623 nxge_rxbuf_pp_to_vp(p_nxge_t nxgep, p_rx_rbr_ring_t rbr_p, 6533859Sml29623 uint8_t pktbufsz_type, uint64_t *pkt_buf_addr_pp, 6543859Sml29623 uint64_t **pkt_buf_addr_p, uint32_t *bufoffset, uint32_t *msg_index) 6553859Sml29623 { 6563859Sml29623 int bufsize; 6573859Sml29623 uint64_t pktbuf_pp; 6583859Sml29623 uint64_t dvma_addr; 6593859Sml29623 rxring_info_t *ring_info; 6603859Sml29623 int base_side, end_side; 6613859Sml29623 int r_index, l_index, anchor_index; 6623859Sml29623 int found, search_done; 6633859Sml29623 uint32_t offset, chunk_size, block_size, page_size_mask; 6643859Sml29623 uint32_t chunk_index, block_index, total_index; 6653859Sml29623 int max_iterations, iteration; 6663859Sml29623 rxbuf_index_info_t *bufinfo; 6673859Sml29623 6683859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, "==> nxge_rxbuf_pp_to_vp")); 6693859Sml29623 6703859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 6713859Sml29623 "==> nxge_rxbuf_pp_to_vp: buf_pp $%p btype %d", 6723859Sml29623 pkt_buf_addr_pp, 6733859Sml29623 pktbufsz_type)); 6745125Sjoycey #if defined(__i386) 6755125Sjoycey pktbuf_pp = (uint64_t)(uint32_t)pkt_buf_addr_pp; 6765125Sjoycey #else 6773859Sml29623 pktbuf_pp = (uint64_t)pkt_buf_addr_pp; 6785125Sjoycey #endif 6793859Sml29623 6803859Sml29623 switch (pktbufsz_type) { 6813859Sml29623 case 0: 6823859Sml29623 bufsize = rbr_p->pkt_buf_size0; 6833859Sml29623 break; 6843859Sml29623 case 1: 6853859Sml29623 bufsize = rbr_p->pkt_buf_size1; 6863859Sml29623 break; 6873859Sml29623 case 2: 6883859Sml29623 bufsize = rbr_p->pkt_buf_size2; 6893859Sml29623 break; 6903859Sml29623 case RCR_SINGLE_BLOCK: 6913859Sml29623 bufsize = 0; 6923859Sml29623 anchor_index = 0; 6933859Sml29623 break; 6943859Sml29623 default: 6953859Sml29623 return (NXGE_ERROR); 6963859Sml29623 } 6973859Sml29623 6983859Sml29623 if (rbr_p->num_blocks == 1) { 6993859Sml29623 anchor_index = 0; 7003859Sml29623 ring_info = rbr_p->ring_info; 7013859Sml29623 bufinfo = (rxbuf_index_info_t *)ring_info->buffer; 7023859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 7033859Sml29623 "==> nxge_rxbuf_pp_to_vp: (found, 1 block) " 7043859Sml29623 "buf_pp $%p btype %d anchor_index %d " 7053859Sml29623 "bufinfo $%p", 7063859Sml29623 pkt_buf_addr_pp, 7073859Sml29623 pktbufsz_type, 7083859Sml29623 anchor_index, 7093859Sml29623 bufinfo)); 7103859Sml29623 7113859Sml29623 goto found_index; 7123859Sml29623 } 7133859Sml29623 7143859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 7153859Sml29623 "==> nxge_rxbuf_pp_to_vp: " 7163859Sml29623 "buf_pp $%p btype %d anchor_index %d", 7173859Sml29623 pkt_buf_addr_pp, 7183859Sml29623 pktbufsz_type, 7193859Sml29623 anchor_index)); 7203859Sml29623 7213859Sml29623 ring_info = rbr_p->ring_info; 7223859Sml29623 found = B_FALSE; 7233859Sml29623 bufinfo = (rxbuf_index_info_t *)ring_info->buffer; 7243859Sml29623 iteration = 0; 7253859Sml29623 max_iterations = ring_info->max_iterations; 7263859Sml29623 /* 7273859Sml29623 * First check if this block has been seen 7283859Sml29623 * recently. This is indicated by a hint which 7293859Sml29623 * is initialized when the first buffer of the block 7303859Sml29623 * is seen. The hint is reset when the last buffer of 7313859Sml29623 * the block has been processed. 7323859Sml29623 * As three block sizes are supported, three hints 7333859Sml29623 * are kept. The idea behind the hints is that once 7343859Sml29623 * the hardware uses a block for a buffer of that 7353859Sml29623 * size, it will use it exclusively for that size 7363859Sml29623 * and will use it until it is exhausted. It is assumed 7373859Sml29623 * that there would a single block being used for the same 7383859Sml29623 * buffer sizes at any given time. 7393859Sml29623 */ 7403859Sml29623 if (ring_info->hint[pktbufsz_type] != NO_HINT) { 7413859Sml29623 anchor_index = ring_info->hint[pktbufsz_type]; 7423859Sml29623 dvma_addr = bufinfo[anchor_index].dvma_addr; 7433859Sml29623 chunk_size = bufinfo[anchor_index].buf_size; 7443859Sml29623 if ((pktbuf_pp >= dvma_addr) && 7453859Sml29623 (pktbuf_pp < (dvma_addr + chunk_size))) { 7463859Sml29623 found = B_TRUE; 7473859Sml29623 /* 7483859Sml29623 * check if this is the last buffer in the block 7493859Sml29623 * If so, then reset the hint for the size; 7503859Sml29623 */ 7513859Sml29623 7523859Sml29623 if ((pktbuf_pp + bufsize) >= (dvma_addr + chunk_size)) 7533859Sml29623 ring_info->hint[pktbufsz_type] = NO_HINT; 7543859Sml29623 } 7553859Sml29623 } 7563859Sml29623 7573859Sml29623 if (found == B_FALSE) { 7583859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 7593859Sml29623 "==> nxge_rxbuf_pp_to_vp: (!found)" 7603859Sml29623 "buf_pp $%p btype %d anchor_index %d", 7613859Sml29623 pkt_buf_addr_pp, 7623859Sml29623 pktbufsz_type, 7633859Sml29623 anchor_index)); 7643859Sml29623 7653859Sml29623 /* 7663859Sml29623 * This is the first buffer of the block of this 7673859Sml29623 * size. Need to search the whole information 7683859Sml29623 * array. 7693859Sml29623 * the search algorithm uses a binary tree search 7703859Sml29623 * algorithm. It assumes that the information is 7713859Sml29623 * already sorted with increasing order 7723859Sml29623 * info[0] < info[1] < info[2] .... < info[n-1] 7733859Sml29623 * where n is the size of the information array 7743859Sml29623 */ 7753859Sml29623 r_index = rbr_p->num_blocks - 1; 7763859Sml29623 l_index = 0; 7773859Sml29623 search_done = B_FALSE; 7783859Sml29623 anchor_index = MID_INDEX(r_index, l_index); 7793859Sml29623 while (search_done == B_FALSE) { 7803859Sml29623 if ((r_index == l_index) || 7813859Sml29623 (iteration >= max_iterations)) 7823859Sml29623 search_done = B_TRUE; 7833859Sml29623 end_side = TO_RIGHT; /* to the right */ 7843859Sml29623 base_side = TO_LEFT; /* to the left */ 7853859Sml29623 /* read the DVMA address information and sort it */ 7863859Sml29623 dvma_addr = bufinfo[anchor_index].dvma_addr; 7873859Sml29623 chunk_size = bufinfo[anchor_index].buf_size; 7883859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 7893859Sml29623 "==> nxge_rxbuf_pp_to_vp: (searching)" 7903859Sml29623 "buf_pp $%p btype %d " 7913859Sml29623 "anchor_index %d chunk_size %d dvmaaddr $%p", 7923859Sml29623 pkt_buf_addr_pp, 7933859Sml29623 pktbufsz_type, 7943859Sml29623 anchor_index, 7953859Sml29623 chunk_size, 7963859Sml29623 dvma_addr)); 7973859Sml29623 7983859Sml29623 if (pktbuf_pp >= dvma_addr) 7993859Sml29623 base_side = TO_RIGHT; /* to the right */ 8003859Sml29623 if (pktbuf_pp < (dvma_addr + chunk_size)) 8013859Sml29623 end_side = TO_LEFT; /* to the left */ 8023859Sml29623 8033859Sml29623 switch (base_side + end_side) { 8043859Sml29623 case IN_MIDDLE: 8053859Sml29623 /* found */ 8063859Sml29623 found = B_TRUE; 8073859Sml29623 search_done = B_TRUE; 8083859Sml29623 if ((pktbuf_pp + bufsize) < 8093859Sml29623 (dvma_addr + chunk_size)) 8103859Sml29623 ring_info->hint[pktbufsz_type] = 8113859Sml29623 bufinfo[anchor_index].buf_index; 8123859Sml29623 break; 8133859Sml29623 case BOTH_RIGHT: 8143859Sml29623 /* not found: go to the right */ 8153859Sml29623 l_index = anchor_index + 1; 8163859Sml29623 anchor_index = 8173859Sml29623 MID_INDEX(r_index, l_index); 8183859Sml29623 break; 8193859Sml29623 8203859Sml29623 case BOTH_LEFT: 8213859Sml29623 /* not found: go to the left */ 8223859Sml29623 r_index = anchor_index - 1; 8233859Sml29623 anchor_index = MID_INDEX(r_index, 8243859Sml29623 l_index); 8253859Sml29623 break; 8263859Sml29623 default: /* should not come here */ 8273859Sml29623 return (NXGE_ERROR); 8283859Sml29623 } 8293859Sml29623 iteration++; 8303859Sml29623 } 8313859Sml29623 8323859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 8333859Sml29623 "==> nxge_rxbuf_pp_to_vp: (search done)" 8343859Sml29623 "buf_pp $%p btype %d anchor_index %d", 8353859Sml29623 pkt_buf_addr_pp, 8363859Sml29623 pktbufsz_type, 8373859Sml29623 anchor_index)); 8383859Sml29623 } 8393859Sml29623 8403859Sml29623 if (found == B_FALSE) { 8413859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 8423859Sml29623 "==> nxge_rxbuf_pp_to_vp: (search failed)" 8433859Sml29623 "buf_pp $%p btype %d anchor_index %d", 8443859Sml29623 pkt_buf_addr_pp, 8453859Sml29623 pktbufsz_type, 8463859Sml29623 anchor_index)); 8473859Sml29623 return (NXGE_ERROR); 8483859Sml29623 } 8493859Sml29623 8503859Sml29623 found_index: 8513859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 8523859Sml29623 "==> nxge_rxbuf_pp_to_vp: (FOUND1)" 8533859Sml29623 "buf_pp $%p btype %d bufsize %d anchor_index %d", 8543859Sml29623 pkt_buf_addr_pp, 8553859Sml29623 pktbufsz_type, 8563859Sml29623 bufsize, 8573859Sml29623 anchor_index)); 8583859Sml29623 8593859Sml29623 /* index of the first block in this chunk */ 8603859Sml29623 chunk_index = bufinfo[anchor_index].start_index; 8613859Sml29623 dvma_addr = bufinfo[anchor_index].dvma_addr; 8623859Sml29623 page_size_mask = ring_info->block_size_mask; 8633859Sml29623 8643859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 8653859Sml29623 "==> nxge_rxbuf_pp_to_vp: (FOUND3), get chunk)" 8663859Sml29623 "buf_pp $%p btype %d bufsize %d " 8673859Sml29623 "anchor_index %d chunk_index %d dvma $%p", 8683859Sml29623 pkt_buf_addr_pp, 8693859Sml29623 pktbufsz_type, 8703859Sml29623 bufsize, 8713859Sml29623 anchor_index, 8723859Sml29623 chunk_index, 8733859Sml29623 dvma_addr)); 8743859Sml29623 8753859Sml29623 offset = pktbuf_pp - dvma_addr; /* offset within the chunk */ 8763859Sml29623 block_size = rbr_p->block_size; /* System block(page) size */ 8773859Sml29623 8783859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 8793859Sml29623 "==> nxge_rxbuf_pp_to_vp: (FOUND4), get chunk)" 8803859Sml29623 "buf_pp $%p btype %d bufsize %d " 8813859Sml29623 "anchor_index %d chunk_index %d dvma $%p " 8823859Sml29623 "offset %d block_size %d", 8833859Sml29623 pkt_buf_addr_pp, 8843859Sml29623 pktbufsz_type, 8853859Sml29623 bufsize, 8863859Sml29623 anchor_index, 8873859Sml29623 chunk_index, 8883859Sml29623 dvma_addr, 8893859Sml29623 offset, 8903859Sml29623 block_size)); 8913859Sml29623 8923859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, "==> getting total index")); 8933859Sml29623 8943859Sml29623 block_index = (offset / block_size); /* index within chunk */ 8953859Sml29623 total_index = chunk_index + block_index; 8963859Sml29623 8973859Sml29623 8983859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 8993859Sml29623 "==> nxge_rxbuf_pp_to_vp: " 9003859Sml29623 "total_index %d dvma_addr $%p " 9013859Sml29623 "offset %d block_size %d " 9023859Sml29623 "block_index %d ", 9033859Sml29623 total_index, dvma_addr, 9043859Sml29623 offset, block_size, 9053859Sml29623 block_index)); 9065125Sjoycey #if defined(__i386) 9075125Sjoycey *pkt_buf_addr_p = (uint64_t *)((uint32_t)bufinfo[anchor_index].kaddr + 9085125Sjoycey (uint32_t)offset); 9095125Sjoycey #else 9105125Sjoycey *pkt_buf_addr_p = (uint64_t *)((uint64_t)bufinfo[anchor_index].kaddr + 9115125Sjoycey (uint64_t)offset); 9125125Sjoycey #endif 9133859Sml29623 9143859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 9153859Sml29623 "==> nxge_rxbuf_pp_to_vp: " 9163859Sml29623 "total_index %d dvma_addr $%p " 9173859Sml29623 "offset %d block_size %d " 9183859Sml29623 "block_index %d " 9193859Sml29623 "*pkt_buf_addr_p $%p", 9203859Sml29623 total_index, dvma_addr, 9213859Sml29623 offset, block_size, 9223859Sml29623 block_index, 9233859Sml29623 *pkt_buf_addr_p)); 9243859Sml29623 9253859Sml29623 9263859Sml29623 *msg_index = total_index; 9273859Sml29623 *bufoffset = (offset & page_size_mask); 9283859Sml29623 9293859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 9303859Sml29623 "==> nxge_rxbuf_pp_to_vp: get msg index: " 9313859Sml29623 "msg_index %d bufoffset_index %d", 9323859Sml29623 *msg_index, 9333859Sml29623 *bufoffset)); 9343859Sml29623 9353859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, "<== nxge_rxbuf_pp_to_vp")); 9363859Sml29623 9373859Sml29623 return (NXGE_OK); 9383859Sml29623 } 9393859Sml29623 9403859Sml29623 /* 9413859Sml29623 * used by quick sort (qsort) function 9423859Sml29623 * to perform comparison 9433859Sml29623 */ 9443859Sml29623 static int 9453859Sml29623 nxge_sort_compare(const void *p1, const void *p2) 9463859Sml29623 { 9473859Sml29623 9483859Sml29623 rxbuf_index_info_t *a, *b; 9493859Sml29623 9503859Sml29623 a = (rxbuf_index_info_t *)p1; 9513859Sml29623 b = (rxbuf_index_info_t *)p2; 9523859Sml29623 9533859Sml29623 if (a->dvma_addr > b->dvma_addr) 9543859Sml29623 return (1); 9553859Sml29623 if (a->dvma_addr < b->dvma_addr) 9563859Sml29623 return (-1); 9573859Sml29623 return (0); 9583859Sml29623 } 9593859Sml29623 9603859Sml29623 9613859Sml29623 9623859Sml29623 /* 9633859Sml29623 * grabbed this sort implementation from common/syscall/avl.c 9643859Sml29623 * 9653859Sml29623 */ 9663859Sml29623 /* 9673859Sml29623 * Generic shellsort, from K&R (1st ed, p 58.), somewhat modified. 9683859Sml29623 * v = Ptr to array/vector of objs 9693859Sml29623 * n = # objs in the array 9703859Sml29623 * s = size of each obj (must be multiples of a word size) 9713859Sml29623 * f = ptr to function to compare two objs 9723859Sml29623 * returns (-1 = less than, 0 = equal, 1 = greater than 9733859Sml29623 */ 9743859Sml29623 void 9753859Sml29623 nxge_ksort(caddr_t v, int n, int s, int (*f)()) 9763859Sml29623 { 9773859Sml29623 int g, i, j, ii; 9783859Sml29623 unsigned int *p1, *p2; 9793859Sml29623 unsigned int tmp; 9803859Sml29623 9813859Sml29623 /* No work to do */ 9823859Sml29623 if (v == NULL || n <= 1) 9833859Sml29623 return; 9843859Sml29623 /* Sanity check on arguments */ 9853859Sml29623 ASSERT(((uintptr_t)v & 0x3) == 0 && (s & 0x3) == 0); 9863859Sml29623 ASSERT(s > 0); 9873859Sml29623 9883859Sml29623 for (g = n / 2; g > 0; g /= 2) { 9893859Sml29623 for (i = g; i < n; i++) { 9903859Sml29623 for (j = i - g; j >= 0 && 9913859Sml29623 (*f)(v + j * s, v + (j + g) * s) == 1; 9923859Sml29623 j -= g) { 9933859Sml29623 p1 = (unsigned *)(v + j * s); 9943859Sml29623 p2 = (unsigned *)(v + (j + g) * s); 9953859Sml29623 for (ii = 0; ii < s / 4; ii++) { 9963859Sml29623 tmp = *p1; 9973859Sml29623 *p1++ = *p2; 9983859Sml29623 *p2++ = tmp; 9993859Sml29623 } 10003859Sml29623 } 10013859Sml29623 } 10023859Sml29623 } 10033859Sml29623 } 10043859Sml29623 10053859Sml29623 /* 10063859Sml29623 * Initialize data structures required for rxdma 10073859Sml29623 * buffer dvma->vmem address lookup 10083859Sml29623 */ 10093859Sml29623 /*ARGSUSED*/ 10103859Sml29623 static nxge_status_t 10113859Sml29623 nxge_rxbuf_index_info_init(p_nxge_t nxgep, p_rx_rbr_ring_t rbrp) 10123859Sml29623 { 10133859Sml29623 10143859Sml29623 int index; 10153859Sml29623 rxring_info_t *ring_info; 10163859Sml29623 int max_iteration = 0, max_index = 0; 10173859Sml29623 10183859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_rxbuf_index_info_init")); 10193859Sml29623 10203859Sml29623 ring_info = rbrp->ring_info; 10213859Sml29623 ring_info->hint[0] = NO_HINT; 10223859Sml29623 ring_info->hint[1] = NO_HINT; 10233859Sml29623 ring_info->hint[2] = NO_HINT; 10243859Sml29623 max_index = rbrp->num_blocks; 10253859Sml29623 10263859Sml29623 /* read the DVMA address information and sort it */ 10273859Sml29623 /* do init of the information array */ 10283859Sml29623 10293859Sml29623 10303859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA2_CTL, 10313859Sml29623 " nxge_rxbuf_index_info_init Sort ptrs")); 10323859Sml29623 10333859Sml29623 /* sort the array */ 10343859Sml29623 nxge_ksort((void *)ring_info->buffer, max_index, 10353859Sml29623 sizeof (rxbuf_index_info_t), nxge_sort_compare); 10363859Sml29623 10373859Sml29623 10383859Sml29623 10393859Sml29623 for (index = 0; index < max_index; index++) { 10403859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA2_CTL, 10413859Sml29623 " nxge_rxbuf_index_info_init: sorted chunk %d " 10423859Sml29623 " ioaddr $%p kaddr $%p size %x", 10433859Sml29623 index, ring_info->buffer[index].dvma_addr, 10443859Sml29623 ring_info->buffer[index].kaddr, 10453859Sml29623 ring_info->buffer[index].buf_size)); 10463859Sml29623 } 10473859Sml29623 10483859Sml29623 max_iteration = 0; 10493859Sml29623 while (max_index >= (1ULL << max_iteration)) 10503859Sml29623 max_iteration++; 10513859Sml29623 ring_info->max_iterations = max_iteration + 1; 10523859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA2_CTL, 10533859Sml29623 " nxge_rxbuf_index_info_init Find max iter %d", 10543859Sml29623 ring_info->max_iterations)); 10553859Sml29623 10563859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_rxbuf_index_info_init")); 10573859Sml29623 return (NXGE_OK); 10583859Sml29623 } 10593859Sml29623 10603859Sml29623 /* ARGSUSED */ 10613859Sml29623 void 10623859Sml29623 nxge_dump_rcr_entry(p_nxge_t nxgep, p_rcr_entry_t entry_p) 10633859Sml29623 { 10643859Sml29623 #ifdef NXGE_DEBUG 10653859Sml29623 10663859Sml29623 uint32_t bptr; 10673859Sml29623 uint64_t pp; 10683859Sml29623 10693859Sml29623 bptr = entry_p->bits.hdw.pkt_buf_addr; 10703859Sml29623 10713859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 10723859Sml29623 "\trcr entry $%p " 10733859Sml29623 "\trcr entry 0x%0llx " 10743859Sml29623 "\trcr entry 0x%08x " 10753859Sml29623 "\trcr entry 0x%08x " 10763859Sml29623 "\tvalue 0x%0llx\n" 10773859Sml29623 "\tmulti = %d\n" 10783859Sml29623 "\tpkt_type = 0x%x\n" 10793859Sml29623 "\tzero_copy = %d\n" 10803859Sml29623 "\tnoport = %d\n" 10813859Sml29623 "\tpromis = %d\n" 10823859Sml29623 "\terror = 0x%04x\n" 10833859Sml29623 "\tdcf_err = 0x%01x\n" 10843859Sml29623 "\tl2_len = %d\n" 10853859Sml29623 "\tpktbufsize = %d\n" 10863859Sml29623 "\tpkt_buf_addr = $%p\n" 10873859Sml29623 "\tpkt_buf_addr (<< 6) = $%p\n", 10883859Sml29623 entry_p, 10893859Sml29623 *(int64_t *)entry_p, 10903859Sml29623 *(int32_t *)entry_p, 10913859Sml29623 *(int32_t *)((char *)entry_p + 32), 10923859Sml29623 entry_p->value, 10933859Sml29623 entry_p->bits.hdw.multi, 10943859Sml29623 entry_p->bits.hdw.pkt_type, 10953859Sml29623 entry_p->bits.hdw.zero_copy, 10963859Sml29623 entry_p->bits.hdw.noport, 10973859Sml29623 entry_p->bits.hdw.promis, 10983859Sml29623 entry_p->bits.hdw.error, 10993859Sml29623 entry_p->bits.hdw.dcf_err, 11003859Sml29623 entry_p->bits.hdw.l2_len, 11013859Sml29623 entry_p->bits.hdw.pktbufsz, 11023859Sml29623 bptr, 11033859Sml29623 entry_p->bits.ldw.pkt_buf_addr)); 11043859Sml29623 11053859Sml29623 pp = (entry_p->value & RCR_PKT_BUF_ADDR_MASK) << 11063859Sml29623 RCR_PKT_BUF_ADDR_SHIFT; 11073859Sml29623 11083859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "rcr pp 0x%llx l2 len %d", 11093859Sml29623 pp, (*(int64_t *)entry_p >> 40) & 0x3fff)); 11103859Sml29623 #endif 11113859Sml29623 } 11123859Sml29623 11133859Sml29623 void 11143859Sml29623 nxge_rxdma_regs_dump(p_nxge_t nxgep, int rdc) 11153859Sml29623 { 11163859Sml29623 npi_handle_t handle; 11173859Sml29623 rbr_stat_t rbr_stat; 11183859Sml29623 addr44_t hd_addr; 11193859Sml29623 addr44_t tail_addr; 11203859Sml29623 uint16_t qlen; 11213859Sml29623 11223859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 11233859Sml29623 "==> nxge_rxdma_regs_dump: rdc channel %d", rdc)); 11243859Sml29623 11253859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 11263859Sml29623 11273859Sml29623 /* RBR head */ 11283859Sml29623 hd_addr.addr = 0; 11293859Sml29623 (void) npi_rxdma_rdc_rbr_head_get(handle, rdc, &hd_addr); 11305165Syc148097 #if defined(__i386) 11313859Sml29623 printf("nxge_rxdma_regs_dump: got hdptr $%p \n", 11325125Sjoycey (void *)(uint32_t)hd_addr.addr); 11335125Sjoycey #else 11345165Syc148097 printf("nxge_rxdma_regs_dump: got hdptr $%p \n", 11353859Sml29623 (void *)hd_addr.addr); 11365125Sjoycey #endif 11373859Sml29623 11383859Sml29623 /* RBR stats */ 11393859Sml29623 (void) npi_rxdma_rdc_rbr_stat_get(handle, rdc, &rbr_stat); 11403859Sml29623 printf("nxge_rxdma_regs_dump: rbr len %d \n", rbr_stat.bits.ldw.qlen); 11413859Sml29623 11423859Sml29623 /* RCR tail */ 11433859Sml29623 tail_addr.addr = 0; 11443859Sml29623 (void) npi_rxdma_rdc_rcr_tail_get(handle, rdc, &tail_addr); 11455165Syc148097 #if defined(__i386) 11463859Sml29623 printf("nxge_rxdma_regs_dump: got tail ptr $%p \n", 11475125Sjoycey (void *)(uint32_t)tail_addr.addr); 11485125Sjoycey #else 11495165Syc148097 printf("nxge_rxdma_regs_dump: got tail ptr $%p \n", 11503859Sml29623 (void *)tail_addr.addr); 11515125Sjoycey #endif 11523859Sml29623 11533859Sml29623 /* RCR qlen */ 11543859Sml29623 (void) npi_rxdma_rdc_rcr_qlen_get(handle, rdc, &qlen); 11553859Sml29623 printf("nxge_rxdma_regs_dump: rcr len %x \n", qlen); 11563859Sml29623 11573859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 11583859Sml29623 "<== nxge_rxdma_regs_dump: rdc rdc %d", rdc)); 11593859Sml29623 } 11603859Sml29623 11613859Sml29623 void 11623859Sml29623 nxge_rxdma_stop(p_nxge_t nxgep) 11633859Sml29623 { 11643859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rxdma_stop")); 11653859Sml29623 11663859Sml29623 (void) nxge_link_monitor(nxgep, LINK_MONITOR_STOP); 11673859Sml29623 (void) nxge_rx_mac_disable(nxgep); 11683859Sml29623 (void) nxge_rxdma_hw_mode(nxgep, NXGE_DMA_STOP); 11693859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_rxdma_stop")); 11703859Sml29623 } 11713859Sml29623 11723859Sml29623 void 11733859Sml29623 nxge_rxdma_stop_reinit(p_nxge_t nxgep) 11743859Sml29623 { 11753859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rxdma_stop_reinit")); 11763859Sml29623 11773859Sml29623 (void) nxge_rxdma_stop(nxgep); 11783859Sml29623 (void) nxge_uninit_rxdma_channels(nxgep); 11793859Sml29623 (void) nxge_init_rxdma_channels(nxgep); 11803859Sml29623 11813859Sml29623 #ifndef AXIS_DEBUG_LB 11823859Sml29623 (void) nxge_xcvr_init(nxgep); 11833859Sml29623 (void) nxge_link_monitor(nxgep, LINK_MONITOR_START); 11843859Sml29623 #endif 11853859Sml29623 (void) nxge_rx_mac_enable(nxgep); 11863859Sml29623 11873859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_rxdma_stop_reinit")); 11883859Sml29623 } 11893859Sml29623 11903859Sml29623 nxge_status_t 11913859Sml29623 nxge_rxdma_hw_mode(p_nxge_t nxgep, boolean_t enable) 11923859Sml29623 { 11936495Sspeer nxge_grp_set_t *set = &nxgep->rx_set; 11946495Sspeer nxge_status_t status; 11956495Sspeer npi_status_t rs; 11966495Sspeer int rdc; 11973859Sml29623 11983859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 11993859Sml29623 "==> nxge_rxdma_hw_mode: mode %d", enable)); 12003859Sml29623 12013859Sml29623 if (!(nxgep->drv_state & STATE_HW_INITIALIZED)) { 12023859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 12036495Sspeer "<== nxge_rxdma_mode: not initialized")); 12043859Sml29623 return (NXGE_ERROR); 12053859Sml29623 } 12066495Sspeer 12076495Sspeer if (nxgep->rx_rbr_rings == 0 || nxgep->rx_rbr_rings->rbr_rings == 0) { 12086495Sspeer NXGE_DEBUG_MSG((nxgep, TX_CTL, 12096495Sspeer "<== nxge_tx_port_fatal_err_recover: " 12106495Sspeer "NULL ring pointer(s)")); 12113859Sml29623 return (NXGE_ERROR); 12123859Sml29623 } 12133859Sml29623 12146495Sspeer if (set->owned.map == 0) { 12156495Sspeer NXGE_DEBUG_MSG((nxgep, RX_CTL, 12166495Sspeer "nxge_rxdma_regs_dump_channels: no channels")); 12176495Sspeer return (NULL); 12186495Sspeer } 12196495Sspeer 12206495Sspeer for (rdc = 0; rdc < NXGE_MAX_RDCS; rdc++) { 12216495Sspeer if ((1 << rdc) & set->owned.map) { 12226495Sspeer rx_rbr_ring_t *ring = 12236495Sspeer nxgep->rx_rbr_rings->rbr_rings[rdc]; 12246495Sspeer npi_handle_t handle = NXGE_DEV_NPI_HANDLE(nxgep); 12256495Sspeer if (ring) { 12266495Sspeer if (enable) { 12276495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 12286495Sspeer "==> nxge_rxdma_hw_mode: " 12296495Sspeer "channel %d (enable)", rdc)); 12306495Sspeer rs = npi_rxdma_cfg_rdc_enable 12316495Sspeer (handle, rdc); 12326495Sspeer } else { 12336495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 12346495Sspeer "==> nxge_rxdma_hw_mode: " 12356495Sspeer "channel %d disable)", rdc)); 12366495Sspeer rs = npi_rxdma_cfg_rdc_disable 12376495Sspeer (handle, rdc); 12386495Sspeer } 12396495Sspeer } 12403859Sml29623 } 12413859Sml29623 } 12423859Sml29623 12433859Sml29623 status = ((rs == NPI_SUCCESS) ? NXGE_OK : NXGE_ERROR | rs); 12443859Sml29623 12453859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 12463859Sml29623 "<== nxge_rxdma_hw_mode: status 0x%x", status)); 12473859Sml29623 12483859Sml29623 return (status); 12493859Sml29623 } 12503859Sml29623 12513859Sml29623 void 12523859Sml29623 nxge_rxdma_enable_channel(p_nxge_t nxgep, uint16_t channel) 12533859Sml29623 { 12543859Sml29623 npi_handle_t handle; 12553859Sml29623 12563859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, 12573859Sml29623 "==> nxge_rxdma_enable_channel: channel %d", channel)); 12583859Sml29623 12593859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 12603859Sml29623 (void) npi_rxdma_cfg_rdc_enable(handle, channel); 12613859Sml29623 12623859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_rxdma_enable_channel")); 12633859Sml29623 } 12643859Sml29623 12653859Sml29623 void 12663859Sml29623 nxge_rxdma_disable_channel(p_nxge_t nxgep, uint16_t channel) 12673859Sml29623 { 12683859Sml29623 npi_handle_t handle; 12693859Sml29623 12703859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, 12713859Sml29623 "==> nxge_rxdma_disable_channel: channel %d", channel)); 12723859Sml29623 12733859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 12743859Sml29623 (void) npi_rxdma_cfg_rdc_disable(handle, channel); 12753859Sml29623 12763859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_rxdma_disable_channel")); 12773859Sml29623 } 12783859Sml29623 12793859Sml29623 void 12803859Sml29623 nxge_hw_start_rx(p_nxge_t nxgep) 12813859Sml29623 { 12823859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_hw_start_rx")); 12833859Sml29623 12843859Sml29623 (void) nxge_rxdma_hw_mode(nxgep, NXGE_DMA_START); 12853859Sml29623 (void) nxge_rx_mac_enable(nxgep); 12863859Sml29623 12873859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_hw_start_rx")); 12883859Sml29623 } 12893859Sml29623 12903859Sml29623 /*ARGSUSED*/ 12913859Sml29623 void 12923859Sml29623 nxge_fixup_rxdma_rings(p_nxge_t nxgep) 12933859Sml29623 { 12946495Sspeer nxge_grp_set_t *set = &nxgep->rx_set; 12956495Sspeer int rdc; 12963859Sml29623 12973859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_fixup_rxdma_rings")); 12983859Sml29623 12996495Sspeer if (nxgep->rx_rbr_rings == 0 || nxgep->rx_rbr_rings->rbr_rings == 0) { 13006495Sspeer NXGE_DEBUG_MSG((nxgep, TX_CTL, 13016495Sspeer "<== nxge_tx_port_fatal_err_recover: " 13026495Sspeer "NULL ring pointer(s)")); 13033859Sml29623 return; 13043859Sml29623 } 13053859Sml29623 13066495Sspeer if (set->owned.map == 0) { 13073859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 13086495Sspeer "nxge_rxdma_regs_dump_channels: no channels")); 13093859Sml29623 return; 13103859Sml29623 } 13116495Sspeer 13126495Sspeer for (rdc = 0; rdc < NXGE_MAX_RDCS; rdc++) { 13136495Sspeer if ((1 << rdc) & set->owned.map) { 13146495Sspeer rx_rbr_ring_t *ring = 13156495Sspeer nxgep->rx_rbr_rings->rbr_rings[rdc]; 13166495Sspeer if (ring) { 13176495Sspeer nxge_rxdma_hw_stop(nxgep, rdc); 13186495Sspeer NXGE_DEBUG_MSG((nxgep, RX_CTL, 13196495Sspeer "==> nxge_fixup_rxdma_rings: " 13206495Sspeer "channel %d ring $%px", 13216495Sspeer rdc, ring)); 13226495Sspeer (void) nxge_rxdma_fixup_channel 13236495Sspeer (nxgep, rdc, rdc); 13246495Sspeer } 13256495Sspeer } 13263859Sml29623 } 13273859Sml29623 13283859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_fixup_rxdma_rings")); 13293859Sml29623 } 13303859Sml29623 13313859Sml29623 void 13323859Sml29623 nxge_rxdma_fix_channel(p_nxge_t nxgep, uint16_t channel) 13333859Sml29623 { 13343859Sml29623 int i; 13353859Sml29623 13363859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rxdma_fix_channel")); 13373859Sml29623 i = nxge_rxdma_get_ring_index(nxgep, channel); 13383859Sml29623 if (i < 0) { 13393859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 13403859Sml29623 "<== nxge_rxdma_fix_channel: no entry found")); 13413859Sml29623 return; 13423859Sml29623 } 13433859Sml29623 13443859Sml29623 nxge_rxdma_fixup_channel(nxgep, channel, i); 13453859Sml29623 13466495Sspeer NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_rxdma_fix_channel")); 13473859Sml29623 } 13483859Sml29623 13493859Sml29623 void 13503859Sml29623 nxge_rxdma_fixup_channel(p_nxge_t nxgep, uint16_t channel, int entry) 13513859Sml29623 { 13523859Sml29623 int ndmas; 13533859Sml29623 p_rx_rbr_rings_t rx_rbr_rings; 13543859Sml29623 p_rx_rbr_ring_t *rbr_rings; 13553859Sml29623 p_rx_rcr_rings_t rx_rcr_rings; 13563859Sml29623 p_rx_rcr_ring_t *rcr_rings; 13573859Sml29623 p_rx_mbox_areas_t rx_mbox_areas_p; 13583859Sml29623 p_rx_mbox_t *rx_mbox_p; 13593859Sml29623 p_nxge_dma_pool_t dma_buf_poolp; 13603859Sml29623 p_nxge_dma_pool_t dma_cntl_poolp; 13613859Sml29623 p_rx_rbr_ring_t rbrp; 13623859Sml29623 p_rx_rcr_ring_t rcrp; 13633859Sml29623 p_rx_mbox_t mboxp; 13643859Sml29623 p_nxge_dma_common_t dmap; 13653859Sml29623 nxge_status_t status = NXGE_OK; 13663859Sml29623 13673859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rxdma_fixup_channel")); 13683859Sml29623 13693859Sml29623 (void) nxge_rxdma_stop_channel(nxgep, channel); 13703859Sml29623 13713859Sml29623 dma_buf_poolp = nxgep->rx_buf_pool_p; 13723859Sml29623 dma_cntl_poolp = nxgep->rx_cntl_pool_p; 13733859Sml29623 13743859Sml29623 if (!dma_buf_poolp->buf_allocated || !dma_cntl_poolp->buf_allocated) { 13753859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 13763859Sml29623 "<== nxge_rxdma_fixup_channel: buf not allocated")); 13773859Sml29623 return; 13783859Sml29623 } 13793859Sml29623 13803859Sml29623 ndmas = dma_buf_poolp->ndmas; 13813859Sml29623 if (!ndmas) { 13823859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 13833859Sml29623 "<== nxge_rxdma_fixup_channel: no dma allocated")); 13843859Sml29623 return; 13853859Sml29623 } 13863859Sml29623 13873859Sml29623 rx_rbr_rings = nxgep->rx_rbr_rings; 13883859Sml29623 rx_rcr_rings = nxgep->rx_rcr_rings; 13893859Sml29623 rbr_rings = rx_rbr_rings->rbr_rings; 13903859Sml29623 rcr_rings = rx_rcr_rings->rcr_rings; 13913859Sml29623 rx_mbox_areas_p = nxgep->rx_mbox_areas_p; 13923859Sml29623 rx_mbox_p = rx_mbox_areas_p->rxmbox_areas; 13933859Sml29623 13943859Sml29623 /* Reinitialize the receive block and completion rings */ 13953859Sml29623 rbrp = (p_rx_rbr_ring_t)rbr_rings[entry], 13963859Sml29623 rcrp = (p_rx_rcr_ring_t)rcr_rings[entry], 13973859Sml29623 mboxp = (p_rx_mbox_t)rx_mbox_p[entry]; 13983859Sml29623 13993859Sml29623 14003859Sml29623 rbrp->rbr_wr_index = (rbrp->rbb_max - 1); 14013859Sml29623 rbrp->rbr_rd_index = 0; 14023859Sml29623 rcrp->comp_rd_index = 0; 14033859Sml29623 rcrp->comp_wt_index = 0; 14043859Sml29623 14053859Sml29623 dmap = (p_nxge_dma_common_t)&rcrp->rcr_desc; 14063859Sml29623 bzero((caddr_t)dmap->kaddrp, dmap->alength); 14073859Sml29623 14083859Sml29623 status = nxge_rxdma_start_channel(nxgep, channel, 14093859Sml29623 rbrp, rcrp, mboxp); 14103859Sml29623 if (status != NXGE_OK) { 14113859Sml29623 goto nxge_rxdma_fixup_channel_fail; 14123859Sml29623 } 14133859Sml29623 if (status != NXGE_OK) { 14143859Sml29623 goto nxge_rxdma_fixup_channel_fail; 14153859Sml29623 } 14163859Sml29623 14173859Sml29623 nxge_rxdma_fixup_channel_fail: 14183859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 14193859Sml29623 "==> nxge_rxdma_fixup_channel: failed (0x%08x)", status)); 14203859Sml29623 14213859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_rxdma_fixup_channel")); 14223859Sml29623 } 14233859Sml29623 14246495Sspeer /* ARGSUSED */ 14253859Sml29623 int 14263859Sml29623 nxge_rxdma_get_ring_index(p_nxge_t nxgep, uint16_t channel) 14273859Sml29623 { 14286495Sspeer return (channel); 14293859Sml29623 } 14303859Sml29623 14313859Sml29623 p_rx_rbr_ring_t 14323859Sml29623 nxge_rxdma_get_rbr_ring(p_nxge_t nxgep, uint16_t channel) 14333859Sml29623 { 14346495Sspeer nxge_grp_set_t *set = &nxgep->rx_set; 14356495Sspeer nxge_channel_t rdc; 14363859Sml29623 14373859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 14383859Sml29623 "==> nxge_rxdma_get_rbr_ring: channel %d", channel)); 14393859Sml29623 14406495Sspeer if (nxgep->rx_rbr_rings == 0 || nxgep->rx_rbr_rings->rbr_rings == 0) { 14416495Sspeer NXGE_DEBUG_MSG((nxgep, TX_CTL, 14426495Sspeer "<== nxge_rxdma_get_rbr_ring: " 14436495Sspeer "NULL ring pointer(s)")); 14443859Sml29623 return (NULL); 14453859Sml29623 } 14466495Sspeer 14476495Sspeer if (set->owned.map == 0) { 14483859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 14496495Sspeer "<== nxge_rxdma_get_rbr_ring: no channels")); 14503859Sml29623 return (NULL); 14513859Sml29623 } 14523859Sml29623 14536495Sspeer for (rdc = 0; rdc < NXGE_MAX_RDCS; rdc++) { 14546495Sspeer if ((1 << rdc) & set->owned.map) { 14556495Sspeer rx_rbr_ring_t *ring = 14566495Sspeer nxgep->rx_rbr_rings->rbr_rings[rdc]; 14576495Sspeer if (ring) { 14586495Sspeer if (channel == ring->rdc) { 14596495Sspeer NXGE_DEBUG_MSG((nxgep, RX_CTL, 14606495Sspeer "==> nxge_rxdma_get_rbr_ring: " 14616495Sspeer "channel %d ring $%p", rdc, ring)); 14626495Sspeer return (ring); 14636495Sspeer } 14646495Sspeer } 14653859Sml29623 } 14663859Sml29623 } 14673859Sml29623 14683859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 14693859Sml29623 "<== nxge_rxdma_get_rbr_ring: not found")); 14703859Sml29623 14713859Sml29623 return (NULL); 14723859Sml29623 } 14733859Sml29623 14743859Sml29623 p_rx_rcr_ring_t 14753859Sml29623 nxge_rxdma_get_rcr_ring(p_nxge_t nxgep, uint16_t channel) 14763859Sml29623 { 14776495Sspeer nxge_grp_set_t *set = &nxgep->rx_set; 14786495Sspeer nxge_channel_t rdc; 14793859Sml29623 14803859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 14813859Sml29623 "==> nxge_rxdma_get_rcr_ring: channel %d", channel)); 14823859Sml29623 14836495Sspeer if (nxgep->rx_rcr_rings == 0 || nxgep->rx_rcr_rings->rcr_rings == 0) { 14846495Sspeer NXGE_DEBUG_MSG((nxgep, TX_CTL, 14856495Sspeer "<== nxge_rxdma_get_rcr_ring: " 14866495Sspeer "NULL ring pointer(s)")); 14873859Sml29623 return (NULL); 14883859Sml29623 } 14896495Sspeer 14906495Sspeer if (set->owned.map == 0) { 14913859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 14926495Sspeer "<== nxge_rxdma_get_rbr_ring: no channels")); 14933859Sml29623 return (NULL); 14943859Sml29623 } 14953859Sml29623 14966495Sspeer for (rdc = 0; rdc < NXGE_MAX_RDCS; rdc++) { 14976495Sspeer if ((1 << rdc) & set->owned.map) { 14986495Sspeer rx_rcr_ring_t *ring = 14996495Sspeer nxgep->rx_rcr_rings->rcr_rings[rdc]; 15006495Sspeer if (ring) { 15016495Sspeer if (channel == ring->rdc) { 15026495Sspeer NXGE_DEBUG_MSG((nxgep, RX_CTL, 15036495Sspeer "==> nxge_rxdma_get_rcr_ring: " 15046495Sspeer "channel %d ring $%p", rdc, ring)); 15056495Sspeer return (ring); 15066495Sspeer } 15076495Sspeer } 15083859Sml29623 } 15093859Sml29623 } 15103859Sml29623 15113859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 15123859Sml29623 "<== nxge_rxdma_get_rcr_ring: not found")); 15133859Sml29623 15143859Sml29623 return (NULL); 15153859Sml29623 } 15163859Sml29623 15173859Sml29623 /* 15183859Sml29623 * Static functions start here. 15193859Sml29623 */ 15203859Sml29623 static p_rx_msg_t 15213859Sml29623 nxge_allocb(size_t size, uint32_t pri, p_nxge_dma_common_t dmabuf_p) 15223859Sml29623 { 15233859Sml29623 p_rx_msg_t nxge_mp = NULL; 15243859Sml29623 p_nxge_dma_common_t dmamsg_p; 15253859Sml29623 uchar_t *buffer; 15263859Sml29623 15273859Sml29623 nxge_mp = KMEM_ZALLOC(sizeof (rx_msg_t), KM_NOSLEEP); 15283859Sml29623 if (nxge_mp == NULL) { 15294185Sspeer NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL, 15303859Sml29623 "Allocation of a rx msg failed.")); 15313859Sml29623 goto nxge_allocb_exit; 15323859Sml29623 } 15333859Sml29623 15343859Sml29623 nxge_mp->use_buf_pool = B_FALSE; 15353859Sml29623 if (dmabuf_p) { 15363859Sml29623 nxge_mp->use_buf_pool = B_TRUE; 15373859Sml29623 dmamsg_p = (p_nxge_dma_common_t)&nxge_mp->buf_dma; 15383859Sml29623 *dmamsg_p = *dmabuf_p; 15393859Sml29623 dmamsg_p->nblocks = 1; 15403859Sml29623 dmamsg_p->block_size = size; 15413859Sml29623 dmamsg_p->alength = size; 15423859Sml29623 buffer = (uchar_t *)dmabuf_p->kaddrp; 15433859Sml29623 15443859Sml29623 dmabuf_p->kaddrp = (void *) 15453859Sml29623 ((char *)dmabuf_p->kaddrp + size); 15463859Sml29623 dmabuf_p->ioaddr_pp = (void *) 15473859Sml29623 ((char *)dmabuf_p->ioaddr_pp + size); 15483859Sml29623 dmabuf_p->alength -= size; 15493859Sml29623 dmabuf_p->offset += size; 15503859Sml29623 dmabuf_p->dma_cookie.dmac_laddress += size; 15513859Sml29623 dmabuf_p->dma_cookie.dmac_size -= size; 15523859Sml29623 15533859Sml29623 } else { 15543859Sml29623 buffer = KMEM_ALLOC(size, KM_NOSLEEP); 15553859Sml29623 if (buffer == NULL) { 15564185Sspeer NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL, 15573859Sml29623 "Allocation of a receive page failed.")); 15583859Sml29623 goto nxge_allocb_fail1; 15593859Sml29623 } 15603859Sml29623 } 15613859Sml29623 15623859Sml29623 nxge_mp->rx_mblk_p = desballoc(buffer, size, pri, &nxge_mp->freeb); 15633859Sml29623 if (nxge_mp->rx_mblk_p == NULL) { 15644185Sspeer NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL, "desballoc failed.")); 15653859Sml29623 goto nxge_allocb_fail2; 15663859Sml29623 } 15673859Sml29623 15683859Sml29623 nxge_mp->buffer = buffer; 15693859Sml29623 nxge_mp->block_size = size; 15703859Sml29623 nxge_mp->freeb.free_func = (void (*)())nxge_freeb; 15713859Sml29623 nxge_mp->freeb.free_arg = (caddr_t)nxge_mp; 15723859Sml29623 nxge_mp->ref_cnt = 1; 15733859Sml29623 nxge_mp->free = B_TRUE; 15743859Sml29623 nxge_mp->rx_use_bcopy = B_FALSE; 15753859Sml29623 15763859Sml29623 atomic_inc_32(&nxge_mblks_pending); 15773859Sml29623 15783859Sml29623 goto nxge_allocb_exit; 15793859Sml29623 15803859Sml29623 nxge_allocb_fail2: 15813859Sml29623 if (!nxge_mp->use_buf_pool) { 15823859Sml29623 KMEM_FREE(buffer, size); 15833859Sml29623 } 15843859Sml29623 15853859Sml29623 nxge_allocb_fail1: 15863859Sml29623 KMEM_FREE(nxge_mp, sizeof (rx_msg_t)); 15873859Sml29623 nxge_mp = NULL; 15883859Sml29623 15893859Sml29623 nxge_allocb_exit: 15903859Sml29623 return (nxge_mp); 15913859Sml29623 } 15923859Sml29623 15933859Sml29623 p_mblk_t 15943859Sml29623 nxge_dupb(p_rx_msg_t nxge_mp, uint_t offset, size_t size) 15953859Sml29623 { 15963859Sml29623 p_mblk_t mp; 15973859Sml29623 15983859Sml29623 NXGE_DEBUG_MSG((NULL, MEM_CTL, "==> nxge_dupb")); 15993859Sml29623 NXGE_DEBUG_MSG((NULL, MEM_CTL, "nxge_mp = $%p " 16003859Sml29623 "offset = 0x%08X " 16013859Sml29623 "size = 0x%08X", 16023859Sml29623 nxge_mp, offset, size)); 16033859Sml29623 16043859Sml29623 mp = desballoc(&nxge_mp->buffer[offset], size, 16053859Sml29623 0, &nxge_mp->freeb); 16063859Sml29623 if (mp == NULL) { 16073859Sml29623 NXGE_DEBUG_MSG((NULL, RX_CTL, "desballoc failed")); 16083859Sml29623 goto nxge_dupb_exit; 16093859Sml29623 } 16103859Sml29623 atomic_inc_32(&nxge_mp->ref_cnt); 16113859Sml29623 16123859Sml29623 16133859Sml29623 nxge_dupb_exit: 16143859Sml29623 NXGE_DEBUG_MSG((NULL, MEM_CTL, "<== nxge_dupb mp = $%p", 16153859Sml29623 nxge_mp)); 16163859Sml29623 return (mp); 16173859Sml29623 } 16183859Sml29623 16193859Sml29623 p_mblk_t 16203859Sml29623 nxge_dupb_bcopy(p_rx_msg_t nxge_mp, uint_t offset, size_t size) 16213859Sml29623 { 16223859Sml29623 p_mblk_t mp; 16233859Sml29623 uchar_t *dp; 16243859Sml29623 16253859Sml29623 mp = allocb(size + NXGE_RXBUF_EXTRA, 0); 16263859Sml29623 if (mp == NULL) { 16273859Sml29623 NXGE_DEBUG_MSG((NULL, RX_CTL, "desballoc failed")); 16283859Sml29623 goto nxge_dupb_bcopy_exit; 16293859Sml29623 } 16303859Sml29623 dp = mp->b_rptr = mp->b_rptr + NXGE_RXBUF_EXTRA; 16313859Sml29623 bcopy((void *)&nxge_mp->buffer[offset], dp, size); 16323859Sml29623 mp->b_wptr = dp + size; 16333859Sml29623 16343859Sml29623 nxge_dupb_bcopy_exit: 16353859Sml29623 NXGE_DEBUG_MSG((NULL, MEM_CTL, "<== nxge_dupb mp = $%p", 16363859Sml29623 nxge_mp)); 16373859Sml29623 return (mp); 16383859Sml29623 } 16393859Sml29623 16403859Sml29623 void nxge_post_page(p_nxge_t nxgep, p_rx_rbr_ring_t rx_rbr_p, 16413859Sml29623 p_rx_msg_t rx_msg_p); 16423859Sml29623 16433859Sml29623 void 16443859Sml29623 nxge_post_page(p_nxge_t nxgep, p_rx_rbr_ring_t rx_rbr_p, p_rx_msg_t rx_msg_p) 16453859Sml29623 { 16463859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_post_page")); 16473859Sml29623 16483859Sml29623 /* Reuse this buffer */ 16493859Sml29623 rx_msg_p->free = B_FALSE; 16503859Sml29623 rx_msg_p->cur_usage_cnt = 0; 16513859Sml29623 rx_msg_p->max_usage_cnt = 0; 16523859Sml29623 rx_msg_p->pkt_buf_size = 0; 16533859Sml29623 16543859Sml29623 if (rx_rbr_p->rbr_use_bcopy) { 16553859Sml29623 rx_msg_p->rx_use_bcopy = B_FALSE; 16563859Sml29623 atomic_dec_32(&rx_rbr_p->rbr_consumed); 16573859Sml29623 } 16583859Sml29623 16593859Sml29623 /* 16603859Sml29623 * Get the rbr header pointer and its offset index. 16613859Sml29623 */ 16623859Sml29623 MUTEX_ENTER(&rx_rbr_p->post_lock); 16633859Sml29623 rx_rbr_p->rbr_wr_index = ((rx_rbr_p->rbr_wr_index + 1) & 16643859Sml29623 rx_rbr_p->rbr_wrap_mask); 16653859Sml29623 rx_rbr_p->rbr_desc_vp[rx_rbr_p->rbr_wr_index] = rx_msg_p->shifted_addr; 16663859Sml29623 MUTEX_EXIT(&rx_rbr_p->post_lock); 16675770Sml29623 npi_rxdma_rdc_rbr_kick(NXGE_DEV_NPI_HANDLE(nxgep), 16685770Sml29623 rx_rbr_p->rdc, 1); 16693859Sml29623 16703859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 16713859Sml29623 "<== nxge_post_page (channel %d post_next_index %d)", 16723859Sml29623 rx_rbr_p->rdc, rx_rbr_p->rbr_wr_index)); 16733859Sml29623 16743859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_post_page")); 16753859Sml29623 } 16763859Sml29623 16773859Sml29623 void 16783859Sml29623 nxge_freeb(p_rx_msg_t rx_msg_p) 16793859Sml29623 { 16803859Sml29623 size_t size; 16813859Sml29623 uchar_t *buffer = NULL; 16823859Sml29623 int ref_cnt; 16834874Sml29623 boolean_t free_state = B_FALSE; 16843859Sml29623 16855170Stm144005 rx_rbr_ring_t *ring = rx_msg_p->rx_rbr_p; 16865170Stm144005 16873859Sml29623 NXGE_DEBUG_MSG((NULL, MEM2_CTL, "==> nxge_freeb")); 16883859Sml29623 NXGE_DEBUG_MSG((NULL, MEM2_CTL, 16893859Sml29623 "nxge_freeb:rx_msg_p = $%p (block pending %d)", 16903859Sml29623 rx_msg_p, nxge_mblks_pending)); 16913859Sml29623 16924874Sml29623 /* 16934874Sml29623 * First we need to get the free state, then 16944874Sml29623 * atomic decrement the reference count to prevent 16954874Sml29623 * the race condition with the interrupt thread that 16964874Sml29623 * is processing a loaned up buffer block. 16974874Sml29623 */ 16984874Sml29623 free_state = rx_msg_p->free; 16993859Sml29623 ref_cnt = atomic_add_32_nv(&rx_msg_p->ref_cnt, -1); 17003859Sml29623 if (!ref_cnt) { 17015770Sml29623 atomic_dec_32(&nxge_mblks_pending); 17023859Sml29623 buffer = rx_msg_p->buffer; 17033859Sml29623 size = rx_msg_p->block_size; 17043859Sml29623 NXGE_DEBUG_MSG((NULL, MEM2_CTL, "nxge_freeb: " 17053859Sml29623 "will free: rx_msg_p = $%p (block pending %d)", 17064185Sspeer rx_msg_p, nxge_mblks_pending)); 17073859Sml29623 17083859Sml29623 if (!rx_msg_p->use_buf_pool) { 17093859Sml29623 KMEM_FREE(buffer, size); 17103859Sml29623 } 17113859Sml29623 17123859Sml29623 KMEM_FREE(rx_msg_p, sizeof (rx_msg_t)); 17135170Stm144005 17145759Smisaki if (ring) { 17155759Smisaki /* 17165759Smisaki * Decrement the receive buffer ring's reference 17175759Smisaki * count, too. 17185759Smisaki */ 17195759Smisaki atomic_dec_32(&ring->rbr_ref_cnt); 17205759Smisaki 17215759Smisaki /* 17226495Sspeer * Free the receive buffer ring, if 17235759Smisaki * 1. all the receive buffers have been freed 17245759Smisaki * 2. and we are in the proper state (that is, 17255759Smisaki * we are not UNMAPPING). 17265759Smisaki */ 17275759Smisaki if (ring->rbr_ref_cnt == 0 && 17285759Smisaki ring->rbr_state == RBR_UNMAPPED) { 17296495Sspeer /* 17306495Sspeer * Free receive data buffers, 17316495Sspeer * buffer index information 17326495Sspeer * (rxring_info) and 17336495Sspeer * the message block ring. 17346495Sspeer */ 17356495Sspeer NXGE_DEBUG_MSG((NULL, RX_CTL, 17366495Sspeer "nxge_freeb:rx_msg_p = $%p " 17376495Sspeer "(block pending %d) free buffers", 17386495Sspeer rx_msg_p, nxge_mblks_pending)); 17396495Sspeer nxge_rxdma_databuf_free(ring); 17406495Sspeer if (ring->ring_info) { 17416495Sspeer KMEM_FREE(ring->ring_info, 17426495Sspeer sizeof (rxring_info_t)); 17436495Sspeer } 17446495Sspeer 17456495Sspeer if (ring->rx_msg_ring) { 17466495Sspeer KMEM_FREE(ring->rx_msg_ring, 17476495Sspeer ring->tnblocks * 17486495Sspeer sizeof (p_rx_msg_t)); 17496495Sspeer } 17505759Smisaki KMEM_FREE(ring, sizeof (*ring)); 17515759Smisaki } 17525170Stm144005 } 17533859Sml29623 return; 17543859Sml29623 } 17553859Sml29623 17563859Sml29623 /* 17573859Sml29623 * Repost buffer. 17583859Sml29623 */ 17595759Smisaki if (free_state && (ref_cnt == 1) && ring) { 17603859Sml29623 NXGE_DEBUG_MSG((NULL, RX_CTL, 17613859Sml29623 "nxge_freeb: post page $%p:", rx_msg_p)); 17625170Stm144005 if (ring->rbr_state == RBR_POSTING) 17635170Stm144005 nxge_post_page(rx_msg_p->nxgep, ring, rx_msg_p); 17643859Sml29623 } 17653859Sml29623 17663859Sml29623 NXGE_DEBUG_MSG((NULL, MEM2_CTL, "<== nxge_freeb")); 17673859Sml29623 } 17683859Sml29623 17693859Sml29623 uint_t 17703859Sml29623 nxge_rx_intr(void *arg1, void *arg2) 17713859Sml29623 { 17723859Sml29623 p_nxge_ldv_t ldvp = (p_nxge_ldv_t)arg1; 17733859Sml29623 p_nxge_t nxgep = (p_nxge_t)arg2; 17743859Sml29623 p_nxge_ldg_t ldgp; 17753859Sml29623 uint8_t channel; 17763859Sml29623 npi_handle_t handle; 17773859Sml29623 rx_dma_ctl_stat_t cs; 17783859Sml29623 17793859Sml29623 #ifdef NXGE_DEBUG 17803859Sml29623 rxdma_cfig1_t cfg; 17813859Sml29623 #endif 17823859Sml29623 uint_t serviced = DDI_INTR_UNCLAIMED; 17833859Sml29623 17843859Sml29623 if (ldvp == NULL) { 17853859Sml29623 NXGE_DEBUG_MSG((NULL, INT_CTL, 17863859Sml29623 "<== nxge_rx_intr: arg2 $%p arg1 $%p", 17873859Sml29623 nxgep, ldvp)); 17883859Sml29623 17893859Sml29623 return (DDI_INTR_CLAIMED); 17903859Sml29623 } 17913859Sml29623 17923859Sml29623 if (arg2 == NULL || (void *)ldvp->nxgep != arg2) { 17933859Sml29623 nxgep = ldvp->nxgep; 17943859Sml29623 } 17956602Sspeer 17966602Sspeer if ((!(nxgep->drv_state & STATE_HW_INITIALIZED)) || 17976602Sspeer (nxgep->nxge_mac_state != NXGE_MAC_STARTED)) { 17986602Sspeer NXGE_DEBUG_MSG((nxgep, INT_CTL, 17996602Sspeer "<== nxge_rx_intr: interface not started or intialized")); 18006602Sspeer return (DDI_INTR_CLAIMED); 18016602Sspeer } 18026602Sspeer 18033859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 18043859Sml29623 "==> nxge_rx_intr: arg2 $%p arg1 $%p", 18053859Sml29623 nxgep, ldvp)); 18063859Sml29623 18073859Sml29623 /* 18083859Sml29623 * This interrupt handler is for a specific 18093859Sml29623 * receive dma channel. 18103859Sml29623 */ 18113859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 18123859Sml29623 /* 18133859Sml29623 * Get the control and status for this channel. 18143859Sml29623 */ 18153859Sml29623 channel = ldvp->channel; 18163859Sml29623 ldgp = ldvp->ldgp; 18173859Sml29623 RXDMA_REG_READ64(handle, RX_DMA_CTL_STAT_REG, channel, &cs.value); 18183859Sml29623 18193859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rx_intr:channel %d " 18203859Sml29623 "cs 0x%016llx rcrto 0x%x rcrthres %x", 18213859Sml29623 channel, 18223859Sml29623 cs.value, 18233859Sml29623 cs.bits.hdw.rcrto, 18243859Sml29623 cs.bits.hdw.rcrthres)); 18253859Sml29623 18266495Sspeer nxge_rx_pkts_vring(nxgep, ldvp->vdma_index, cs); 18273859Sml29623 serviced = DDI_INTR_CLAIMED; 18283859Sml29623 18293859Sml29623 /* error events. */ 18303859Sml29623 if (cs.value & RX_DMA_CTL_STAT_ERROR) { 18316495Sspeer (void) nxge_rx_err_evnts(nxgep, channel, cs); 18323859Sml29623 } 18333859Sml29623 18343859Sml29623 nxge_intr_exit: 18353859Sml29623 /* 18363859Sml29623 * Enable the mailbox update interrupt if we want 18373859Sml29623 * to use mailbox. We probably don't need to use 18383859Sml29623 * mailbox as it only saves us one pio read. 18393859Sml29623 * Also write 1 to rcrthres and rcrto to clear 18403859Sml29623 * these two edge triggered bits. 18413859Sml29623 */ 18423859Sml29623 18433859Sml29623 cs.value &= RX_DMA_CTL_STAT_WR1C; 18443859Sml29623 cs.bits.hdw.mex = 1; 18453859Sml29623 RXDMA_REG_WRITE64(handle, RX_DMA_CTL_STAT_REG, channel, 18463859Sml29623 cs.value); 18473859Sml29623 18483859Sml29623 /* 18493859Sml29623 * Rearm this logical group if this is a single device 18503859Sml29623 * group. 18513859Sml29623 */ 18523859Sml29623 if (ldgp->nldvs == 1) { 18533859Sml29623 ldgimgm_t mgm; 18543859Sml29623 mgm.value = 0; 18553859Sml29623 mgm.bits.ldw.arm = 1; 18563859Sml29623 mgm.bits.ldw.timer = ldgp->ldg_timer; 18576495Sspeer if (isLDOMguest(nxgep)) { 18586495Sspeer nxge_hio_ldgimgn(nxgep, ldgp); 18596495Sspeer } else { 18606495Sspeer NXGE_REG_WR64(handle, 18613859Sml29623 LDGIMGN_REG + LDSV_OFFSET(ldgp->ldg), 18623859Sml29623 mgm.value); 18636495Sspeer } 18643859Sml29623 } 18653859Sml29623 18663859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_rx_intr: serviced %d", 18673859Sml29623 serviced)); 18683859Sml29623 return (serviced); 18693859Sml29623 } 18703859Sml29623 18713859Sml29623 /* 18723859Sml29623 * Process the packets received in the specified logical device 18733859Sml29623 * and pass up a chain of message blocks to the upper layer. 18743859Sml29623 */ 18753859Sml29623 static void 18766495Sspeer nxge_rx_pkts_vring(p_nxge_t nxgep, uint_t vindex, rx_dma_ctl_stat_t cs) 18773859Sml29623 { 18783859Sml29623 p_mblk_t mp; 18793859Sml29623 p_rx_rcr_ring_t rcrp; 18803859Sml29623 18813859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rx_pkts_vring")); 18826495Sspeer rcrp = nxgep->rx_rcr_rings->rcr_rings[vindex]; 18836495Sspeer if (rcrp->poll_flag) { 18846495Sspeer /* It is in the poll mode */ 18856495Sspeer return; 18866495Sspeer } 18876495Sspeer 18886495Sspeer if ((mp = nxge_rx_pkts(nxgep, rcrp, cs, -1)) == NULL) { 18893859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 18903859Sml29623 "<== nxge_rx_pkts_vring: no mp")); 18913859Sml29623 return; 18923859Sml29623 } 18933859Sml29623 18943859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rx_pkts_vring: $%p", 18953859Sml29623 mp)); 18963859Sml29623 18973859Sml29623 #ifdef NXGE_DEBUG 18983859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 18993859Sml29623 "==> nxge_rx_pkts_vring:calling mac_rx " 19003859Sml29623 "LEN %d mp $%p mp->b_cont $%p mp->b_next $%p rcrp $%p " 19013859Sml29623 "mac_handle $%p", 19023859Sml29623 mp->b_wptr - mp->b_rptr, 19033859Sml29623 mp, mp->b_cont, mp->b_next, 19043859Sml29623 rcrp, rcrp->rcr_mac_handle)); 19053859Sml29623 19063859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 19073859Sml29623 "==> nxge_rx_pkts_vring: dump packets " 19083859Sml29623 "(mp $%p b_rptr $%p b_wptr $%p):\n %s", 19093859Sml29623 mp, 19103859Sml29623 mp->b_rptr, 19113859Sml29623 mp->b_wptr, 19123859Sml29623 nxge_dump_packet((char *)mp->b_rptr, 19133859Sml29623 mp->b_wptr - mp->b_rptr))); 19143859Sml29623 if (mp->b_cont) { 19153859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 19163859Sml29623 "==> nxge_rx_pkts_vring: dump b_cont packets " 19173859Sml29623 "(mp->b_cont $%p b_rptr $%p b_wptr $%p):\n %s", 19183859Sml29623 mp->b_cont, 19193859Sml29623 mp->b_cont->b_rptr, 19203859Sml29623 mp->b_cont->b_wptr, 19213859Sml29623 nxge_dump_packet((char *)mp->b_cont->b_rptr, 19223859Sml29623 mp->b_cont->b_wptr - mp->b_cont->b_rptr))); 19233859Sml29623 } 19243859Sml29623 if (mp->b_next) { 19253859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 19263859Sml29623 "==> nxge_rx_pkts_vring: dump next packets " 19273859Sml29623 "(b_rptr $%p): %s", 19283859Sml29623 mp->b_next->b_rptr, 19293859Sml29623 nxge_dump_packet((char *)mp->b_next->b_rptr, 19303859Sml29623 mp->b_next->b_wptr - mp->b_next->b_rptr))); 19313859Sml29623 } 19323859Sml29623 #endif 19333859Sml29623 19346495Sspeer if (!isLDOMguest(nxgep)) 19356495Sspeer mac_rx(nxgep->mach, rcrp->rcr_mac_handle, mp); 19366495Sspeer #if defined(sun4v) 19376495Sspeer else { /* isLDOMguest(nxgep) */ 19386495Sspeer nxge_hio_data_t *nhd = (nxge_hio_data_t *) 19396495Sspeer nxgep->nxge_hw_p->hio; 19406495Sspeer nx_vio_fp_t *vio = &nhd->hio.vio; 19416495Sspeer 19426495Sspeer if (vio->cb.vio_net_rx_cb) { 19436495Sspeer (*vio->cb.vio_net_rx_cb) 19446495Sspeer (nxgep->hio_vr->vhp, mp); 19456495Sspeer } 19466495Sspeer } 19476495Sspeer #endif 19483859Sml29623 } 19493859Sml29623 19503859Sml29623 19513859Sml29623 /* 19523859Sml29623 * This routine is the main packet receive processing function. 19533859Sml29623 * It gets the packet type, error code, and buffer related 19543859Sml29623 * information from the receive completion entry. 19553859Sml29623 * How many completion entries to process is based on the number of packets 19563859Sml29623 * queued by the hardware, a hardware maintained tail pointer 19573859Sml29623 * and a configurable receive packet count. 19583859Sml29623 * 19593859Sml29623 * A chain of message blocks will be created as result of processing 19603859Sml29623 * the completion entries. This chain of message blocks will be returned and 19613859Sml29623 * a hardware control status register will be updated with the number of 19623859Sml29623 * packets were removed from the hardware queue. 19633859Sml29623 * 19643859Sml29623 */ 19656495Sspeer static mblk_t * 19666495Sspeer nxge_rx_pkts(p_nxge_t nxgep, p_rx_rcr_ring_t rcr_p, rx_dma_ctl_stat_t cs, 19676495Sspeer int bytes_to_pickup) 19683859Sml29623 { 19693859Sml29623 npi_handle_t handle; 19703859Sml29623 uint8_t channel; 19713859Sml29623 uint32_t comp_rd_index; 19723859Sml29623 p_rcr_entry_t rcr_desc_rd_head_p; 19733859Sml29623 p_rcr_entry_t rcr_desc_rd_head_pp; 19743859Sml29623 p_mblk_t nmp, mp_cont, head_mp, *tail_mp; 19753859Sml29623 uint16_t qlen, nrcr_read, npkt_read; 19766495Sspeer uint32_t qlen_hw; 19773859Sml29623 boolean_t multi; 19786495Sspeer rcrcfig_b_t rcr_cfg_b; 19796495Sspeer int totallen = 0; 19803859Sml29623 #if defined(_BIG_ENDIAN) 19813859Sml29623 npi_status_t rs = NPI_SUCCESS; 19823859Sml29623 #endif 19833859Sml29623 19846495Sspeer NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rx_pkts: " 19856495Sspeer "channel %d", rcr_p->rdc)); 19863859Sml29623 19873859Sml29623 if (!(nxgep->drv_state & STATE_HW_INITIALIZED)) { 19883859Sml29623 return (NULL); 19893859Sml29623 } 19903859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 19913859Sml29623 channel = rcr_p->rdc; 19923859Sml29623 19933859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 19943859Sml29623 "==> nxge_rx_pkts: START: rcr channel %d " 19953859Sml29623 "head_p $%p head_pp $%p index %d ", 19963859Sml29623 channel, rcr_p->rcr_desc_rd_head_p, 19973859Sml29623 rcr_p->rcr_desc_rd_head_pp, 19983859Sml29623 rcr_p->comp_rd_index)); 19993859Sml29623 20003859Sml29623 20013859Sml29623 #if !defined(_BIG_ENDIAN) 20023859Sml29623 qlen = RXDMA_REG_READ32(handle, RCRSTAT_A_REG, channel) & 0xffff; 20033859Sml29623 #else 20043859Sml29623 rs = npi_rxdma_rdc_rcr_qlen_get(handle, channel, &qlen); 20053859Sml29623 if (rs != NPI_SUCCESS) { 20066495Sspeer NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rx_pkts: " 20073859Sml29623 "channel %d, get qlen failed 0x%08x", 20086495Sspeer channel, rs)); 20093859Sml29623 return (NULL); 20103859Sml29623 } 20113859Sml29623 #endif 20123859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rx_pkts:rcr channel %d " 20133859Sml29623 "qlen %d", channel, qlen)); 20143859Sml29623 20153859Sml29623 20163859Sml29623 20173859Sml29623 if (!qlen) { 20183859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 20193859Sml29623 "==> nxge_rx_pkts:rcr channel %d " 20203859Sml29623 "qlen %d (no pkts)", channel, qlen)); 20213859Sml29623 20223859Sml29623 return (NULL); 20233859Sml29623 } 20243859Sml29623 20253859Sml29623 comp_rd_index = rcr_p->comp_rd_index; 20263859Sml29623 20273859Sml29623 rcr_desc_rd_head_p = rcr_p->rcr_desc_rd_head_p; 20283859Sml29623 rcr_desc_rd_head_pp = rcr_p->rcr_desc_rd_head_pp; 20293859Sml29623 nrcr_read = npkt_read = 0; 20303859Sml29623 20313859Sml29623 /* 20323859Sml29623 * Number of packets queued 20333859Sml29623 * (The jumbo or multi packet will be counted as only one 20343859Sml29623 * packets and it may take up more than one completion entry). 20353859Sml29623 */ 20363859Sml29623 qlen_hw = (qlen < nxge_max_rx_pkts) ? 20373859Sml29623 qlen : nxge_max_rx_pkts; 20383859Sml29623 head_mp = NULL; 20393859Sml29623 tail_mp = &head_mp; 20403859Sml29623 nmp = mp_cont = NULL; 20413859Sml29623 multi = B_FALSE; 20423859Sml29623 20433859Sml29623 while (qlen_hw) { 20443859Sml29623 20453859Sml29623 #ifdef NXGE_DEBUG 20463859Sml29623 nxge_dump_rcr_entry(nxgep, rcr_desc_rd_head_p); 20473859Sml29623 #endif 20483859Sml29623 /* 20493859Sml29623 * Process one completion ring entry. 20503859Sml29623 */ 20513859Sml29623 nxge_receive_packet(nxgep, 20523859Sml29623 rcr_p, rcr_desc_rd_head_p, &multi, &nmp, &mp_cont); 20533859Sml29623 20543859Sml29623 /* 20553859Sml29623 * message chaining modes 20563859Sml29623 */ 20573859Sml29623 if (nmp) { 20583859Sml29623 nmp->b_next = NULL; 20593859Sml29623 if (!multi && !mp_cont) { /* frame fits a partition */ 20603859Sml29623 *tail_mp = nmp; 20613859Sml29623 tail_mp = &nmp->b_next; 20626495Sspeer totallen += MBLKL(nmp); 20633859Sml29623 nmp = NULL; 20643859Sml29623 } else if (multi && !mp_cont) { /* first segment */ 20653859Sml29623 *tail_mp = nmp; 20663859Sml29623 tail_mp = &nmp->b_cont; 20676495Sspeer totallen += MBLKL(nmp); 20683859Sml29623 } else if (multi && mp_cont) { /* mid of multi segs */ 20693859Sml29623 *tail_mp = mp_cont; 20703859Sml29623 tail_mp = &mp_cont->b_cont; 20716495Sspeer totallen += MBLKL(mp_cont); 20723859Sml29623 } else if (!multi && mp_cont) { /* last segment */ 20733859Sml29623 *tail_mp = mp_cont; 20743859Sml29623 tail_mp = &nmp->b_next; 20756495Sspeer totallen += MBLKL(mp_cont); 20763859Sml29623 nmp = NULL; 20773859Sml29623 } 20783859Sml29623 } 20793859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 20803859Sml29623 "==> nxge_rx_pkts: loop: rcr channel %d " 20813859Sml29623 "before updating: multi %d " 20823859Sml29623 "nrcr_read %d " 20833859Sml29623 "npk read %d " 20843859Sml29623 "head_pp $%p index %d ", 20853859Sml29623 channel, 20863859Sml29623 multi, 20873859Sml29623 nrcr_read, npkt_read, rcr_desc_rd_head_pp, 20883859Sml29623 comp_rd_index)); 20893859Sml29623 20903859Sml29623 if (!multi) { 20913859Sml29623 qlen_hw--; 20923859Sml29623 npkt_read++; 20933859Sml29623 } 20943859Sml29623 20953859Sml29623 /* 20963859Sml29623 * Update the next read entry. 20973859Sml29623 */ 20983859Sml29623 comp_rd_index = NEXT_ENTRY(comp_rd_index, 20993859Sml29623 rcr_p->comp_wrap_mask); 21003859Sml29623 21013859Sml29623 rcr_desc_rd_head_p = NEXT_ENTRY_PTR(rcr_desc_rd_head_p, 21023859Sml29623 rcr_p->rcr_desc_first_p, 21033859Sml29623 rcr_p->rcr_desc_last_p); 21043859Sml29623 21053859Sml29623 nrcr_read++; 21063859Sml29623 21073859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 21083859Sml29623 "<== nxge_rx_pkts: (SAM, process one packet) " 21093859Sml29623 "nrcr_read %d", 21103859Sml29623 nrcr_read)); 21113859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 21123859Sml29623 "==> nxge_rx_pkts: loop: rcr channel %d " 21133859Sml29623 "multi %d " 21143859Sml29623 "nrcr_read %d " 21153859Sml29623 "npk read %d " 21163859Sml29623 "head_pp $%p index %d ", 21173859Sml29623 channel, 21183859Sml29623 multi, 21193859Sml29623 nrcr_read, npkt_read, rcr_desc_rd_head_pp, 21203859Sml29623 comp_rd_index)); 21213859Sml29623 21226495Sspeer if ((bytes_to_pickup != -1) && 21236495Sspeer (totallen >= bytes_to_pickup)) { 21246495Sspeer break; 21256495Sspeer } 21263859Sml29623 } 21273859Sml29623 21283859Sml29623 rcr_p->rcr_desc_rd_head_pp = rcr_desc_rd_head_pp; 21293859Sml29623 rcr_p->comp_rd_index = comp_rd_index; 21303859Sml29623 rcr_p->rcr_desc_rd_head_p = rcr_desc_rd_head_p; 21313859Sml29623 21323859Sml29623 if ((nxgep->intr_timeout != rcr_p->intr_timeout) || 21333859Sml29623 (nxgep->intr_threshold != rcr_p->intr_threshold)) { 21343859Sml29623 rcr_p->intr_timeout = nxgep->intr_timeout; 21353859Sml29623 rcr_p->intr_threshold = nxgep->intr_threshold; 21363859Sml29623 rcr_cfg_b.value = 0x0ULL; 21373859Sml29623 if (rcr_p->intr_timeout) 21383859Sml29623 rcr_cfg_b.bits.ldw.entout = 1; 21393859Sml29623 rcr_cfg_b.bits.ldw.timeout = rcr_p->intr_timeout; 21403859Sml29623 rcr_cfg_b.bits.ldw.pthres = rcr_p->intr_threshold; 21413859Sml29623 RXDMA_REG_WRITE64(handle, RCRCFIG_B_REG, 21423859Sml29623 channel, rcr_cfg_b.value); 21433859Sml29623 } 21443859Sml29623 21453859Sml29623 cs.bits.ldw.pktread = npkt_read; 21463859Sml29623 cs.bits.ldw.ptrread = nrcr_read; 21473859Sml29623 RXDMA_REG_WRITE64(handle, RX_DMA_CTL_STAT_REG, 21483859Sml29623 channel, cs.value); 21493859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 21503859Sml29623 "==> nxge_rx_pkts: EXIT: rcr channel %d " 21513859Sml29623 "head_pp $%p index %016llx ", 21523859Sml29623 channel, 21533859Sml29623 rcr_p->rcr_desc_rd_head_pp, 21543859Sml29623 rcr_p->comp_rd_index)); 21553859Sml29623 /* 21563859Sml29623 * Update RCR buffer pointer read and number of packets 21573859Sml29623 * read. 21583859Sml29623 */ 21593859Sml29623 21603859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_rx_pkts")); 21613859Sml29623 return (head_mp); 21623859Sml29623 } 21633859Sml29623 21643859Sml29623 void 21653859Sml29623 nxge_receive_packet(p_nxge_t nxgep, 21663859Sml29623 p_rx_rcr_ring_t rcr_p, p_rcr_entry_t rcr_desc_rd_head_p, 21673859Sml29623 boolean_t *multi_p, mblk_t **mp, mblk_t **mp_cont) 21683859Sml29623 { 21693859Sml29623 p_mblk_t nmp = NULL; 21703859Sml29623 uint64_t multi; 21713859Sml29623 uint64_t dcf_err; 21723859Sml29623 uint8_t channel; 21733859Sml29623 21743859Sml29623 boolean_t first_entry = B_TRUE; 21753859Sml29623 boolean_t is_tcp_udp = B_FALSE; 21763859Sml29623 boolean_t buffer_free = B_FALSE; 21773859Sml29623 boolean_t error_send_up = B_FALSE; 21783859Sml29623 uint8_t error_type; 21793859Sml29623 uint16_t l2_len; 21803859Sml29623 uint16_t skip_len; 21813859Sml29623 uint8_t pktbufsz_type; 21823859Sml29623 uint64_t rcr_entry; 21833859Sml29623 uint64_t *pkt_buf_addr_pp; 21843859Sml29623 uint64_t *pkt_buf_addr_p; 21853859Sml29623 uint32_t buf_offset; 21863859Sml29623 uint32_t bsize; 21873859Sml29623 uint32_t error_disp_cnt; 21883859Sml29623 uint32_t msg_index; 21893859Sml29623 p_rx_rbr_ring_t rx_rbr_p; 21903859Sml29623 p_rx_msg_t *rx_msg_ring_p; 21913859Sml29623 p_rx_msg_t rx_msg_p; 21923859Sml29623 uint16_t sw_offset_bytes = 0, hdr_size = 0; 21933859Sml29623 nxge_status_t status = NXGE_OK; 21943859Sml29623 boolean_t is_valid = B_FALSE; 21953859Sml29623 p_nxge_rx_ring_stats_t rdc_stats; 21963859Sml29623 uint32_t bytes_read; 21973859Sml29623 uint64_t pkt_type; 21983859Sml29623 uint64_t frag; 21996028Ssbehera boolean_t pkt_too_long_err = B_FALSE; 22003859Sml29623 #ifdef NXGE_DEBUG 22013859Sml29623 int dump_len; 22023859Sml29623 #endif 22033859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, "==> nxge_receive_packet")); 22043859Sml29623 first_entry = (*mp == NULL) ? B_TRUE : B_FALSE; 22053859Sml29623 22063859Sml29623 rcr_entry = *((uint64_t *)rcr_desc_rd_head_p); 22073859Sml29623 22083859Sml29623 multi = (rcr_entry & RCR_MULTI_MASK); 22093859Sml29623 dcf_err = (rcr_entry & RCR_DCF_ERROR_MASK); 22103859Sml29623 pkt_type = (rcr_entry & RCR_PKT_TYPE_MASK); 22113859Sml29623 22123859Sml29623 error_type = ((rcr_entry & RCR_ERROR_MASK) >> RCR_ERROR_SHIFT); 22133859Sml29623 frag = (rcr_entry & RCR_FRAG_MASK); 22143859Sml29623 22153859Sml29623 l2_len = ((rcr_entry & RCR_L2_LEN_MASK) >> RCR_L2_LEN_SHIFT); 22163859Sml29623 22173859Sml29623 pktbufsz_type = ((rcr_entry & RCR_PKTBUFSZ_MASK) >> 22183859Sml29623 RCR_PKTBUFSZ_SHIFT); 22195125Sjoycey #if defined(__i386) 22205125Sjoycey pkt_buf_addr_pp = (uint64_t *)(uint32_t)((rcr_entry & 22215125Sjoycey RCR_PKT_BUF_ADDR_MASK) << RCR_PKT_BUF_ADDR_SHIFT); 22225125Sjoycey #else 22233859Sml29623 pkt_buf_addr_pp = (uint64_t *)((rcr_entry & RCR_PKT_BUF_ADDR_MASK) << 22243859Sml29623 RCR_PKT_BUF_ADDR_SHIFT); 22255125Sjoycey #endif 22263859Sml29623 22273859Sml29623 channel = rcr_p->rdc; 22283859Sml29623 22293859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 22303859Sml29623 "==> nxge_receive_packet: entryp $%p entry 0x%0llx " 22313859Sml29623 "pkt_buf_addr_pp $%p l2_len %d multi 0x%llx " 22323859Sml29623 "error_type 0x%x pkt_type 0x%x " 22333859Sml29623 "pktbufsz_type %d ", 22343859Sml29623 rcr_desc_rd_head_p, 22353859Sml29623 rcr_entry, pkt_buf_addr_pp, l2_len, 22363859Sml29623 multi, 22373859Sml29623 error_type, 22383859Sml29623 pkt_type, 22393859Sml29623 pktbufsz_type)); 22403859Sml29623 22413859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 22423859Sml29623 "==> nxge_receive_packet: entryp $%p entry 0x%0llx " 22433859Sml29623 "pkt_buf_addr_pp $%p l2_len %d multi 0x%llx " 22443859Sml29623 "error_type 0x%x pkt_type 0x%x ", rcr_desc_rd_head_p, 22453859Sml29623 rcr_entry, pkt_buf_addr_pp, l2_len, 22463859Sml29623 multi, 22473859Sml29623 error_type, 22483859Sml29623 pkt_type)); 22493859Sml29623 22503859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 22513859Sml29623 "==> (rbr) nxge_receive_packet: entry 0x%0llx " 22523859Sml29623 "full pkt_buf_addr_pp $%p l2_len %d", 22533859Sml29623 rcr_entry, pkt_buf_addr_pp, l2_len)); 22543859Sml29623 22553859Sml29623 /* get the stats ptr */ 22563859Sml29623 rdc_stats = rcr_p->rdc_stats; 22573859Sml29623 22583859Sml29623 if (!l2_len) { 22593859Sml29623 22603859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 22613859Sml29623 "<== nxge_receive_packet: failed: l2 length is 0.")); 22623859Sml29623 return; 22633859Sml29623 } 22643859Sml29623 22656028Ssbehera /* 22666028Ssbehera * Sofware workaround for BMAC hardware limitation that allows 22676028Ssbehera * maxframe size of 1526, instead of 1522 for non-jumbo and 0x2406 22686028Ssbehera * instead of 0x2400 for jumbo. 22696028Ssbehera */ 22706028Ssbehera if (l2_len > nxgep->mac.maxframesize) { 22716028Ssbehera pkt_too_long_err = B_TRUE; 22726028Ssbehera } 22736028Ssbehera 22744185Sspeer /* Hardware sends us 4 bytes of CRC as no stripping is done. */ 22754185Sspeer l2_len -= ETHERFCSL; 22764185Sspeer 22773859Sml29623 /* shift 6 bits to get the full io address */ 22785125Sjoycey #if defined(__i386) 22795125Sjoycey pkt_buf_addr_pp = (uint64_t *)((uint32_t)pkt_buf_addr_pp << 22805125Sjoycey RCR_PKT_BUF_ADDR_SHIFT_FULL); 22815125Sjoycey #else 22823859Sml29623 pkt_buf_addr_pp = (uint64_t *)((uint64_t)pkt_buf_addr_pp << 22833859Sml29623 RCR_PKT_BUF_ADDR_SHIFT_FULL); 22845125Sjoycey #endif 22853859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 22863859Sml29623 "==> (rbr) nxge_receive_packet: entry 0x%0llx " 22873859Sml29623 "full pkt_buf_addr_pp $%p l2_len %d", 22883859Sml29623 rcr_entry, pkt_buf_addr_pp, l2_len)); 22893859Sml29623 22903859Sml29623 rx_rbr_p = rcr_p->rx_rbr_p; 22913859Sml29623 rx_msg_ring_p = rx_rbr_p->rx_msg_ring; 22923859Sml29623 22933859Sml29623 if (first_entry) { 22943859Sml29623 hdr_size = (rcr_p->full_hdr_flag ? RXDMA_HDR_SIZE_FULL : 22953859Sml29623 RXDMA_HDR_SIZE_DEFAULT); 22963859Sml29623 22973859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 22983859Sml29623 "==> nxge_receive_packet: first entry 0x%016llx " 22993859Sml29623 "pkt_buf_addr_pp $%p l2_len %d hdr %d", 23003859Sml29623 rcr_entry, pkt_buf_addr_pp, l2_len, 23013859Sml29623 hdr_size)); 23023859Sml29623 } 23033859Sml29623 23043859Sml29623 MUTEX_ENTER(&rcr_p->lock); 23053859Sml29623 MUTEX_ENTER(&rx_rbr_p->lock); 23063859Sml29623 23073859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 23083859Sml29623 "==> (rbr 1) nxge_receive_packet: entry 0x%0llx " 23093859Sml29623 "full pkt_buf_addr_pp $%p l2_len %d", 23103859Sml29623 rcr_entry, pkt_buf_addr_pp, l2_len)); 23113859Sml29623 23123859Sml29623 /* 23133859Sml29623 * Packet buffer address in the completion entry points 23143859Sml29623 * to the starting buffer address (offset 0). 23153859Sml29623 * Use the starting buffer address to locate the corresponding 23163859Sml29623 * kernel address. 23173859Sml29623 */ 23183859Sml29623 status = nxge_rxbuf_pp_to_vp(nxgep, rx_rbr_p, 23193859Sml29623 pktbufsz_type, pkt_buf_addr_pp, &pkt_buf_addr_p, 23203859Sml29623 &buf_offset, 23213859Sml29623 &msg_index); 23223859Sml29623 23233859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 23243859Sml29623 "==> (rbr 2) nxge_receive_packet: entry 0x%0llx " 23253859Sml29623 "full pkt_buf_addr_pp $%p l2_len %d", 23263859Sml29623 rcr_entry, pkt_buf_addr_pp, l2_len)); 23273859Sml29623 23283859Sml29623 if (status != NXGE_OK) { 23293859Sml29623 MUTEX_EXIT(&rx_rbr_p->lock); 23303859Sml29623 MUTEX_EXIT(&rcr_p->lock); 23313859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 23323859Sml29623 "<== nxge_receive_packet: found vaddr failed %d", 23333859Sml29623 status)); 23343859Sml29623 return; 23353859Sml29623 } 23363859Sml29623 23373859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 23383859Sml29623 "==> (rbr 3) nxge_receive_packet: entry 0x%0llx " 23393859Sml29623 "full pkt_buf_addr_pp $%p l2_len %d", 23403859Sml29623 rcr_entry, pkt_buf_addr_pp, l2_len)); 23413859Sml29623 23423859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 23433859Sml29623 "==> (rbr 4 msgindex %d) nxge_receive_packet: entry 0x%0llx " 23443859Sml29623 "full pkt_buf_addr_pp $%p l2_len %d", 23453859Sml29623 msg_index, rcr_entry, pkt_buf_addr_pp, l2_len)); 23463859Sml29623 23473859Sml29623 rx_msg_p = rx_msg_ring_p[msg_index]; 23483859Sml29623 23493859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 23503859Sml29623 "==> (rbr 4 msgindex %d) nxge_receive_packet: entry 0x%0llx " 23513859Sml29623 "full pkt_buf_addr_pp $%p l2_len %d", 23523859Sml29623 msg_index, rcr_entry, pkt_buf_addr_pp, l2_len)); 23533859Sml29623 23543859Sml29623 switch (pktbufsz_type) { 23553859Sml29623 case RCR_PKTBUFSZ_0: 23563859Sml29623 bsize = rx_rbr_p->pkt_buf_size0_bytes; 23573859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 23583859Sml29623 "==> nxge_receive_packet: 0 buf %d", bsize)); 23593859Sml29623 break; 23603859Sml29623 case RCR_PKTBUFSZ_1: 23613859Sml29623 bsize = rx_rbr_p->pkt_buf_size1_bytes; 23623859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 23633859Sml29623 "==> nxge_receive_packet: 1 buf %d", bsize)); 23643859Sml29623 break; 23653859Sml29623 case RCR_PKTBUFSZ_2: 23663859Sml29623 bsize = rx_rbr_p->pkt_buf_size2_bytes; 23673859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 23683859Sml29623 "==> nxge_receive_packet: 2 buf %d", bsize)); 23693859Sml29623 break; 23703859Sml29623 case RCR_SINGLE_BLOCK: 23713859Sml29623 bsize = rx_msg_p->block_size; 23723859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 23733859Sml29623 "==> nxge_receive_packet: single %d", bsize)); 23743859Sml29623 23753859Sml29623 break; 23763859Sml29623 default: 23773859Sml29623 MUTEX_EXIT(&rx_rbr_p->lock); 23783859Sml29623 MUTEX_EXIT(&rcr_p->lock); 23793859Sml29623 return; 23803859Sml29623 } 23813859Sml29623 23823859Sml29623 DMA_COMMON_SYNC_OFFSET(rx_msg_p->buf_dma, 23833859Sml29623 (buf_offset + sw_offset_bytes), 23843859Sml29623 (hdr_size + l2_len), 23853859Sml29623 DDI_DMA_SYNC_FORCPU); 23863859Sml29623 23873859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 23883859Sml29623 "==> nxge_receive_packet: after first dump:usage count")); 23893859Sml29623 23903859Sml29623 if (rx_msg_p->cur_usage_cnt == 0) { 23913859Sml29623 if (rx_rbr_p->rbr_use_bcopy) { 23923859Sml29623 atomic_inc_32(&rx_rbr_p->rbr_consumed); 23933859Sml29623 if (rx_rbr_p->rbr_consumed < 23943859Sml29623 rx_rbr_p->rbr_threshold_hi) { 23953859Sml29623 if (rx_rbr_p->rbr_threshold_lo == 0 || 23963859Sml29623 ((rx_rbr_p->rbr_consumed >= 23973859Sml29623 rx_rbr_p->rbr_threshold_lo) && 23983859Sml29623 (rx_rbr_p->rbr_bufsize_type >= 23993859Sml29623 pktbufsz_type))) { 24003859Sml29623 rx_msg_p->rx_use_bcopy = B_TRUE; 24013859Sml29623 } 24023859Sml29623 } else { 24033859Sml29623 rx_msg_p->rx_use_bcopy = B_TRUE; 24043859Sml29623 } 24053859Sml29623 } 24063859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 24073859Sml29623 "==> nxge_receive_packet: buf %d (new block) ", 24083859Sml29623 bsize)); 24093859Sml29623 24103859Sml29623 rx_msg_p->pkt_buf_size_code = pktbufsz_type; 24113859Sml29623 rx_msg_p->pkt_buf_size = bsize; 24123859Sml29623 rx_msg_p->cur_usage_cnt = 1; 24133859Sml29623 if (pktbufsz_type == RCR_SINGLE_BLOCK) { 24143859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 24153859Sml29623 "==> nxge_receive_packet: buf %d " 24163859Sml29623 "(single block) ", 24173859Sml29623 bsize)); 24183859Sml29623 /* 24193859Sml29623 * Buffer can be reused once the free function 24203859Sml29623 * is called. 24213859Sml29623 */ 24223859Sml29623 rx_msg_p->max_usage_cnt = 1; 24233859Sml29623 buffer_free = B_TRUE; 24243859Sml29623 } else { 24253859Sml29623 rx_msg_p->max_usage_cnt = rx_msg_p->block_size/bsize; 24263859Sml29623 if (rx_msg_p->max_usage_cnt == 1) { 24273859Sml29623 buffer_free = B_TRUE; 24283859Sml29623 } 24293859Sml29623 } 24303859Sml29623 } else { 24313859Sml29623 rx_msg_p->cur_usage_cnt++; 24323859Sml29623 if (rx_msg_p->cur_usage_cnt == rx_msg_p->max_usage_cnt) { 24333859Sml29623 buffer_free = B_TRUE; 24343859Sml29623 } 24353859Sml29623 } 24363859Sml29623 24373859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 24383859Sml29623 "msgbuf index = %d l2len %d bytes usage %d max_usage %d ", 24393859Sml29623 msg_index, l2_len, 24403859Sml29623 rx_msg_p->cur_usage_cnt, rx_msg_p->max_usage_cnt)); 24413859Sml29623 24426028Ssbehera if ((error_type) || (dcf_err) || (pkt_too_long_err)) { 24433859Sml29623 rdc_stats->ierrors++; 24443859Sml29623 if (dcf_err) { 24453859Sml29623 rdc_stats->dcf_err++; 24463859Sml29623 #ifdef NXGE_DEBUG 24473859Sml29623 if (!rdc_stats->dcf_err) { 24483859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 24493859Sml29623 "nxge_receive_packet: channel %d dcf_err rcr" 24503859Sml29623 " 0x%llx", channel, rcr_entry)); 24513859Sml29623 } 24523859Sml29623 #endif 24533859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, nxgep->mac.portnum, NULL, 24543859Sml29623 NXGE_FM_EREPORT_RDMC_DCF_ERR); 24556028Ssbehera } else if (pkt_too_long_err) { 24566028Ssbehera rdc_stats->pkt_too_long_err++; 24576028Ssbehera NXGE_DEBUG_MSG((nxgep, RX_CTL, " nxge_receive_packet:" 24586028Ssbehera " channel %d packet length [%d] > " 24596028Ssbehera "maxframesize [%d]", channel, l2_len + ETHERFCSL, 24606028Ssbehera nxgep->mac.maxframesize)); 24613859Sml29623 } else { 24623859Sml29623 /* Update error stats */ 24633859Sml29623 error_disp_cnt = NXGE_ERROR_SHOW_MAX; 24643859Sml29623 rdc_stats->errlog.compl_err_type = error_type; 24653859Sml29623 24663859Sml29623 switch (error_type) { 24675523Syc148097 /* 24685523Syc148097 * Do not send FMA ereport for RCR_L2_ERROR and 24695523Syc148097 * RCR_L4_CSUM_ERROR because most likely they indicate 24705523Syc148097 * back pressure rather than HW failures. 24715523Syc148097 */ 24725165Syc148097 case RCR_L2_ERROR: 24735165Syc148097 rdc_stats->l2_err++; 24745165Syc148097 if (rdc_stats->l2_err < 24755165Syc148097 error_disp_cnt) { 24765165Syc148097 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 24775165Syc148097 " nxge_receive_packet:" 24785165Syc148097 " channel %d RCR L2_ERROR", 24795165Syc148097 channel)); 24805165Syc148097 } 24815165Syc148097 break; 24825165Syc148097 case RCR_L4_CSUM_ERROR: 24835165Syc148097 error_send_up = B_TRUE; 24845165Syc148097 rdc_stats->l4_cksum_err++; 24855165Syc148097 if (rdc_stats->l4_cksum_err < 24865165Syc148097 error_disp_cnt) { 24873859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 24885165Syc148097 " nxge_receive_packet:" 24895165Syc148097 " channel %d" 24905165Syc148097 " RCR L4_CSUM_ERROR", channel)); 24915165Syc148097 } 24925165Syc148097 break; 24935523Syc148097 /* 24945523Syc148097 * Do not send FMA ereport for RCR_FFLP_SOFT_ERROR and 24955523Syc148097 * RCR_ZCP_SOFT_ERROR because they reflect the same 24965523Syc148097 * FFLP and ZCP errors that have been reported by 24975523Syc148097 * nxge_fflp.c and nxge_zcp.c. 24985523Syc148097 */ 24995165Syc148097 case RCR_FFLP_SOFT_ERROR: 25005165Syc148097 error_send_up = B_TRUE; 25015165Syc148097 rdc_stats->fflp_soft_err++; 25025165Syc148097 if (rdc_stats->fflp_soft_err < 25035165Syc148097 error_disp_cnt) { 25045165Syc148097 NXGE_ERROR_MSG((nxgep, 25055165Syc148097 NXGE_ERR_CTL, 25065165Syc148097 " nxge_receive_packet:" 25075165Syc148097 " channel %d" 25085165Syc148097 " RCR FFLP_SOFT_ERROR", channel)); 25095165Syc148097 } 25105165Syc148097 break; 25115165Syc148097 case RCR_ZCP_SOFT_ERROR: 25125165Syc148097 error_send_up = B_TRUE; 25135165Syc148097 rdc_stats->fflp_soft_err++; 25145165Syc148097 if (rdc_stats->zcp_soft_err < 25155165Syc148097 error_disp_cnt) 25165165Syc148097 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 25175165Syc148097 " nxge_receive_packet: Channel %d" 25185165Syc148097 " RCR ZCP_SOFT_ERROR", channel)); 25195165Syc148097 break; 25205165Syc148097 default: 25215165Syc148097 rdc_stats->rcr_unknown_err++; 25225165Syc148097 if (rdc_stats->rcr_unknown_err 25235165Syc148097 < error_disp_cnt) { 25245165Syc148097 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 25255165Syc148097 " nxge_receive_packet: Channel %d" 25265165Syc148097 " RCR entry 0x%llx error 0x%x", 25275165Syc148097 rcr_entry, channel, error_type)); 25285165Syc148097 } 25295165Syc148097 break; 25303859Sml29623 } 25313859Sml29623 } 25323859Sml29623 25333859Sml29623 /* 25343859Sml29623 * Update and repost buffer block if max usage 25353859Sml29623 * count is reached. 25363859Sml29623 */ 25373859Sml29623 if (error_send_up == B_FALSE) { 25384874Sml29623 atomic_inc_32(&rx_msg_p->ref_cnt); 25393859Sml29623 if (buffer_free == B_TRUE) { 25403859Sml29623 rx_msg_p->free = B_TRUE; 25413859Sml29623 } 25423859Sml29623 25433859Sml29623 MUTEX_EXIT(&rx_rbr_p->lock); 25443859Sml29623 MUTEX_EXIT(&rcr_p->lock); 25453859Sml29623 nxge_freeb(rx_msg_p); 25463859Sml29623 return; 25473859Sml29623 } 25483859Sml29623 } 25493859Sml29623 25503859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 25513859Sml29623 "==> nxge_receive_packet: DMA sync second ")); 25523859Sml29623 25535165Syc148097 bytes_read = rcr_p->rcvd_pkt_bytes; 25543859Sml29623 skip_len = sw_offset_bytes + hdr_size; 25553859Sml29623 if (!rx_msg_p->rx_use_bcopy) { 25564874Sml29623 /* 25574874Sml29623 * For loaned up buffers, the driver reference count 25584874Sml29623 * will be incremented first and then the free state. 25594874Sml29623 */ 25605165Syc148097 if ((nmp = nxge_dupb(rx_msg_p, buf_offset, bsize)) != NULL) { 25615165Syc148097 if (first_entry) { 25625165Syc148097 nmp->b_rptr = &nmp->b_rptr[skip_len]; 25635165Syc148097 if (l2_len < bsize - skip_len) { 25645165Syc148097 nmp->b_wptr = &nmp->b_rptr[l2_len]; 25655165Syc148097 } else { 25665165Syc148097 nmp->b_wptr = &nmp->b_rptr[bsize 25675165Syc148097 - skip_len]; 25685165Syc148097 } 25695165Syc148097 } else { 25705165Syc148097 if (l2_len - bytes_read < bsize) { 25715165Syc148097 nmp->b_wptr = 25725165Syc148097 &nmp->b_rptr[l2_len - bytes_read]; 25735165Syc148097 } else { 25745165Syc148097 nmp->b_wptr = &nmp->b_rptr[bsize]; 25755165Syc148097 } 25765165Syc148097 } 25775165Syc148097 } 25783859Sml29623 } else { 25795165Syc148097 if (first_entry) { 25805165Syc148097 nmp = nxge_dupb_bcopy(rx_msg_p, buf_offset + skip_len, 25815165Syc148097 l2_len < bsize - skip_len ? 25825165Syc148097 l2_len : bsize - skip_len); 25835165Syc148097 } else { 25845165Syc148097 nmp = nxge_dupb_bcopy(rx_msg_p, buf_offset, 25855165Syc148097 l2_len - bytes_read < bsize ? 25865165Syc148097 l2_len - bytes_read : bsize); 25875165Syc148097 } 25883859Sml29623 } 25893859Sml29623 if (nmp != NULL) { 25905165Syc148097 if (first_entry) 25915165Syc148097 bytes_read = nmp->b_wptr - nmp->b_rptr; 25925165Syc148097 else 25933859Sml29623 bytes_read += nmp->b_wptr - nmp->b_rptr; 25945165Syc148097 25955165Syc148097 NXGE_DEBUG_MSG((nxgep, RX_CTL, 25965165Syc148097 "==> nxge_receive_packet after dupb: " 25975165Syc148097 "rbr consumed %d " 25985165Syc148097 "pktbufsz_type %d " 25995165Syc148097 "nmp $%p rptr $%p wptr $%p " 26005165Syc148097 "buf_offset %d bzise %d l2_len %d skip_len %d", 26015165Syc148097 rx_rbr_p->rbr_consumed, 26025165Syc148097 pktbufsz_type, 26035165Syc148097 nmp, nmp->b_rptr, nmp->b_wptr, 26045165Syc148097 buf_offset, bsize, l2_len, skip_len)); 26053859Sml29623 } else { 26063859Sml29623 cmn_err(CE_WARN, "!nxge_receive_packet: " 26073859Sml29623 "update stats (error)"); 26084977Sraghus atomic_inc_32(&rx_msg_p->ref_cnt); 26094977Sraghus if (buffer_free == B_TRUE) { 26104977Sraghus rx_msg_p->free = B_TRUE; 26114977Sraghus } 26124977Sraghus MUTEX_EXIT(&rx_rbr_p->lock); 26134977Sraghus MUTEX_EXIT(&rcr_p->lock); 26144977Sraghus nxge_freeb(rx_msg_p); 26154977Sraghus return; 26163859Sml29623 } 26175060Syc148097 26183859Sml29623 if (buffer_free == B_TRUE) { 26193859Sml29623 rx_msg_p->free = B_TRUE; 26203859Sml29623 } 26213859Sml29623 /* 26223859Sml29623 * ERROR, FRAG and PKT_TYPE are only reported 26233859Sml29623 * in the first entry. 26243859Sml29623 * If a packet is not fragmented and no error bit is set, then 26253859Sml29623 * L4 checksum is OK. 26263859Sml29623 */ 26273859Sml29623 is_valid = (nmp != NULL); 26285165Syc148097 if (first_entry) { 26295165Syc148097 rdc_stats->ipackets++; /* count only 1st seg for jumbo */ 26305165Syc148097 rdc_stats->ibytes += skip_len + l2_len < bsize ? 26315183Syc148097 l2_len : bsize; 26325165Syc148097 } else { 26335165Syc148097 rdc_stats->ibytes += l2_len - bytes_read < bsize ? 26345165Syc148097 l2_len - bytes_read : bsize; 26355165Syc148097 } 26365165Syc148097 26375165Syc148097 rcr_p->rcvd_pkt_bytes = bytes_read; 26385165Syc148097 26393859Sml29623 MUTEX_EXIT(&rx_rbr_p->lock); 26403859Sml29623 MUTEX_EXIT(&rcr_p->lock); 26413859Sml29623 26423859Sml29623 if (rx_msg_p->free && rx_msg_p->rx_use_bcopy) { 26433859Sml29623 atomic_inc_32(&rx_msg_p->ref_cnt); 26443859Sml29623 nxge_freeb(rx_msg_p); 26453859Sml29623 } 26463859Sml29623 26473859Sml29623 if (is_valid) { 26483859Sml29623 nmp->b_cont = NULL; 26493859Sml29623 if (first_entry) { 26503859Sml29623 *mp = nmp; 26513859Sml29623 *mp_cont = NULL; 26525165Syc148097 } else { 26533859Sml29623 *mp_cont = nmp; 26545165Syc148097 } 26553859Sml29623 } 26563859Sml29623 26573859Sml29623 /* 26583859Sml29623 * Update stats and hardware checksuming. 26593859Sml29623 */ 26603859Sml29623 if (is_valid && !multi) { 26616495Sspeer /* 2662*6611Sml29623 * If the checksum flag nxge_chksum_offload 2663*6611Sml29623 * is 1, TCP and UDP packets can be sent 26646495Sspeer * up with good checksum. If the checksum flag 2665*6611Sml29623 * is set to 0, checksum reporting will apply to 26666495Sspeer * TCP packets only (workaround for a hardware bug). 2667*6611Sml29623 * If the checksum flag nxge_cksum_offload is 2668*6611Sml29623 * greater than 1, both TCP and UDP packets 2669*6611Sml29623 * will not be reported its hardware checksum results. 26706495Sspeer */ 2671*6611Sml29623 if (nxge_cksum_offload == 1) { 26726495Sspeer is_tcp_udp = ((pkt_type == RCR_PKT_IS_TCP || 26733859Sml29623 pkt_type == RCR_PKT_IS_UDP) ? 26743859Sml29623 B_TRUE: B_FALSE); 2675*6611Sml29623 } else if (!nxge_cksum_offload) { 26766495Sspeer /* TCP checksum only. */ 26776495Sspeer is_tcp_udp = ((pkt_type == RCR_PKT_IS_TCP) ? 26786495Sspeer B_TRUE: B_FALSE); 26796495Sspeer } 26803859Sml29623 26813859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_receive_packet: " 26823859Sml29623 "is_valid 0x%x multi 0x%llx pkt %d frag %d error %d", 26833859Sml29623 is_valid, multi, is_tcp_udp, frag, error_type)); 26843859Sml29623 26853859Sml29623 if (is_tcp_udp && !frag && !error_type) { 26863859Sml29623 (void) hcksum_assoc(nmp, NULL, NULL, 0, 0, 0, 0, 26873859Sml29623 HCK_FULLCKSUM_OK | HCK_FULLCKSUM, 0); 26883859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 26893859Sml29623 "==> nxge_receive_packet: Full tcp/udp cksum " 26903859Sml29623 "is_valid 0x%x multi 0x%llx pkt %d frag %d " 26913859Sml29623 "error %d", 26923859Sml29623 is_valid, multi, is_tcp_udp, frag, error_type)); 26933859Sml29623 } 26943859Sml29623 } 26953859Sml29623 26963859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 26973859Sml29623 "==> nxge_receive_packet: *mp 0x%016llx", *mp)); 26983859Sml29623 26993859Sml29623 *multi_p = (multi == RCR_MULTI_MASK); 27003859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_receive_packet: " 27013859Sml29623 "multi %d nmp 0x%016llx *mp 0x%016llx *mp_cont 0x%016llx", 27023859Sml29623 *multi_p, nmp, *mp, *mp_cont)); 27033859Sml29623 } 27043859Sml29623 27053859Sml29623 /*ARGSUSED*/ 27063859Sml29623 static nxge_status_t 27076495Sspeer nxge_rx_err_evnts(p_nxge_t nxgep, int channel, rx_dma_ctl_stat_t cs) 27083859Sml29623 { 27093859Sml29623 p_nxge_rx_ring_stats_t rdc_stats; 27103859Sml29623 npi_handle_t handle; 27113859Sml29623 npi_status_t rs; 27123859Sml29623 boolean_t rxchan_fatal = B_FALSE; 27133859Sml29623 boolean_t rxport_fatal = B_FALSE; 27143859Sml29623 uint8_t portn; 27153859Sml29623 nxge_status_t status = NXGE_OK; 27163859Sml29623 uint32_t error_disp_cnt = NXGE_ERROR_SHOW_MAX; 27173859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_rx_err_evnts")); 27183859Sml29623 27193859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 27203859Sml29623 portn = nxgep->mac.portnum; 27216495Sspeer rdc_stats = &nxgep->statsp->rdc_stats[channel]; 27223859Sml29623 27233859Sml29623 if (cs.bits.hdw.rbr_tmout) { 27243859Sml29623 rdc_stats->rx_rbr_tmout++; 27253859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, portn, channel, 27263859Sml29623 NXGE_FM_EREPORT_RDMC_RBR_TMOUT); 27273859Sml29623 rxchan_fatal = B_TRUE; 27283859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 27293859Sml29623 "==> nxge_rx_err_evnts: rx_rbr_timeout")); 27303859Sml29623 } 27313859Sml29623 if (cs.bits.hdw.rsp_cnt_err) { 27323859Sml29623 rdc_stats->rsp_cnt_err++; 27333859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, portn, channel, 27343859Sml29623 NXGE_FM_EREPORT_RDMC_RSP_CNT_ERR); 27353859Sml29623 rxchan_fatal = B_TRUE; 27363859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 27373859Sml29623 "==> nxge_rx_err_evnts(channel %d): " 27383859Sml29623 "rsp_cnt_err", channel)); 27393859Sml29623 } 27403859Sml29623 if (cs.bits.hdw.byte_en_bus) { 27413859Sml29623 rdc_stats->byte_en_bus++; 27423859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, portn, channel, 27433859Sml29623 NXGE_FM_EREPORT_RDMC_BYTE_EN_BUS); 27443859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 27453859Sml29623 "==> nxge_rx_err_evnts(channel %d): " 27463859Sml29623 "fatal error: byte_en_bus", channel)); 27473859Sml29623 rxchan_fatal = B_TRUE; 27483859Sml29623 } 27493859Sml29623 if (cs.bits.hdw.rsp_dat_err) { 27503859Sml29623 rdc_stats->rsp_dat_err++; 27513859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, portn, channel, 27523859Sml29623 NXGE_FM_EREPORT_RDMC_RSP_DAT_ERR); 27533859Sml29623 rxchan_fatal = B_TRUE; 27543859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 27553859Sml29623 "==> nxge_rx_err_evnts(channel %d): " 27563859Sml29623 "fatal error: rsp_dat_err", channel)); 27573859Sml29623 } 27583859Sml29623 if (cs.bits.hdw.rcr_ack_err) { 27593859Sml29623 rdc_stats->rcr_ack_err++; 27603859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, portn, channel, 27613859Sml29623 NXGE_FM_EREPORT_RDMC_RCR_ACK_ERR); 27623859Sml29623 rxchan_fatal = B_TRUE; 27633859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 27643859Sml29623 "==> nxge_rx_err_evnts(channel %d): " 27653859Sml29623 "fatal error: rcr_ack_err", channel)); 27663859Sml29623 } 27673859Sml29623 if (cs.bits.hdw.dc_fifo_err) { 27683859Sml29623 rdc_stats->dc_fifo_err++; 27693859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, portn, channel, 27703859Sml29623 NXGE_FM_EREPORT_RDMC_DC_FIFO_ERR); 27713859Sml29623 /* This is not a fatal error! */ 27723859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 27733859Sml29623 "==> nxge_rx_err_evnts(channel %d): " 27743859Sml29623 "dc_fifo_err", channel)); 27753859Sml29623 rxport_fatal = B_TRUE; 27763859Sml29623 } 27773859Sml29623 if ((cs.bits.hdw.rcr_sha_par) || (cs.bits.hdw.rbr_pre_par)) { 27783859Sml29623 if ((rs = npi_rxdma_ring_perr_stat_get(handle, 27793859Sml29623 &rdc_stats->errlog.pre_par, 27803859Sml29623 &rdc_stats->errlog.sha_par)) 27813859Sml29623 != NPI_SUCCESS) { 27823859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 27833859Sml29623 "==> nxge_rx_err_evnts(channel %d): " 27843859Sml29623 "rcr_sha_par: get perr", channel)); 27853859Sml29623 return (NXGE_ERROR | rs); 27863859Sml29623 } 27873859Sml29623 if (cs.bits.hdw.rcr_sha_par) { 27883859Sml29623 rdc_stats->rcr_sha_par++; 27893859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, portn, channel, 27903859Sml29623 NXGE_FM_EREPORT_RDMC_RCR_SHA_PAR); 27913859Sml29623 rxchan_fatal = B_TRUE; 27923859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 27933859Sml29623 "==> nxge_rx_err_evnts(channel %d): " 27943859Sml29623 "fatal error: rcr_sha_par", channel)); 27953859Sml29623 } 27963859Sml29623 if (cs.bits.hdw.rbr_pre_par) { 27973859Sml29623 rdc_stats->rbr_pre_par++; 27983859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, portn, channel, 27993859Sml29623 NXGE_FM_EREPORT_RDMC_RBR_PRE_PAR); 28003859Sml29623 rxchan_fatal = B_TRUE; 28013859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 28023859Sml29623 "==> nxge_rx_err_evnts(channel %d): " 28033859Sml29623 "fatal error: rbr_pre_par", channel)); 28043859Sml29623 } 28053859Sml29623 } 28066172Syc148097 /* 28076172Syc148097 * The Following 4 status bits are for information, the system 28086172Syc148097 * is running fine. There is no need to send FMA ereports or 28096172Syc148097 * log messages. 28106172Syc148097 */ 28113859Sml29623 if (cs.bits.hdw.port_drop_pkt) { 28123859Sml29623 rdc_stats->port_drop_pkt++; 28133859Sml29623 } 28143859Sml29623 if (cs.bits.hdw.wred_drop) { 28153859Sml29623 rdc_stats->wred_drop++; 28163859Sml29623 } 28173859Sml29623 if (cs.bits.hdw.rbr_pre_empty) { 28183859Sml29623 rdc_stats->rbr_pre_empty++; 28193859Sml29623 } 28203859Sml29623 if (cs.bits.hdw.rcr_shadow_full) { 28213859Sml29623 rdc_stats->rcr_shadow_full++; 28223859Sml29623 } 28233859Sml29623 if (cs.bits.hdw.config_err) { 28243859Sml29623 rdc_stats->config_err++; 28253859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, portn, channel, 28263859Sml29623 NXGE_FM_EREPORT_RDMC_CONFIG_ERR); 28273859Sml29623 rxchan_fatal = B_TRUE; 28283859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 28293859Sml29623 "==> nxge_rx_err_evnts(channel %d): " 28303859Sml29623 "config error", channel)); 28313859Sml29623 } 28323859Sml29623 if (cs.bits.hdw.rcrincon) { 28333859Sml29623 rdc_stats->rcrincon++; 28343859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, portn, channel, 28353859Sml29623 NXGE_FM_EREPORT_RDMC_RCRINCON); 28363859Sml29623 rxchan_fatal = B_TRUE; 28373859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 28383859Sml29623 "==> nxge_rx_err_evnts(channel %d): " 28393859Sml29623 "fatal error: rcrincon error", channel)); 28403859Sml29623 } 28413859Sml29623 if (cs.bits.hdw.rcrfull) { 28423859Sml29623 rdc_stats->rcrfull++; 28433859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, portn, channel, 28443859Sml29623 NXGE_FM_EREPORT_RDMC_RCRFULL); 28453859Sml29623 rxchan_fatal = B_TRUE; 28463859Sml29623 if (rdc_stats->rcrfull < error_disp_cnt) 28473859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 28483859Sml29623 "==> nxge_rx_err_evnts(channel %d): " 28493859Sml29623 "fatal error: rcrfull error", channel)); 28503859Sml29623 } 28513859Sml29623 if (cs.bits.hdw.rbr_empty) { 28526172Syc148097 /* 28536172Syc148097 * This bit is for information, there is no need 28546172Syc148097 * send FMA ereport or log a message. 28556172Syc148097 */ 28563859Sml29623 rdc_stats->rbr_empty++; 28573859Sml29623 } 28583859Sml29623 if (cs.bits.hdw.rbrfull) { 28593859Sml29623 rdc_stats->rbrfull++; 28603859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, portn, channel, 28613859Sml29623 NXGE_FM_EREPORT_RDMC_RBRFULL); 28623859Sml29623 rxchan_fatal = B_TRUE; 28633859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 28643859Sml29623 "==> nxge_rx_err_evnts(channel %d): " 28653859Sml29623 "fatal error: rbr_full error", channel)); 28663859Sml29623 } 28673859Sml29623 if (cs.bits.hdw.rbrlogpage) { 28683859Sml29623 rdc_stats->rbrlogpage++; 28693859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, portn, channel, 28703859Sml29623 NXGE_FM_EREPORT_RDMC_RBRLOGPAGE); 28713859Sml29623 rxchan_fatal = B_TRUE; 28723859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 28733859Sml29623 "==> nxge_rx_err_evnts(channel %d): " 28743859Sml29623 "fatal error: rbr logical page error", channel)); 28753859Sml29623 } 28763859Sml29623 if (cs.bits.hdw.cfiglogpage) { 28773859Sml29623 rdc_stats->cfiglogpage++; 28783859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, portn, channel, 28793859Sml29623 NXGE_FM_EREPORT_RDMC_CFIGLOGPAGE); 28803859Sml29623 rxchan_fatal = B_TRUE; 28813859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 28823859Sml29623 "==> nxge_rx_err_evnts(channel %d): " 28833859Sml29623 "fatal error: cfig logical page error", channel)); 28843859Sml29623 } 28853859Sml29623 28863859Sml29623 if (rxport_fatal) { 28873859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 28886495Sspeer " nxge_rx_err_evnts: fatal error on Port #%d\n", 28896495Sspeer portn)); 28906495Sspeer if (isLDOMguest(nxgep)) { 28916495Sspeer status = NXGE_ERROR; 28926495Sspeer } else { 28936495Sspeer status = nxge_ipp_fatal_err_recover(nxgep); 28946495Sspeer if (status == NXGE_OK) { 28956495Sspeer FM_SERVICE_RESTORED(nxgep); 28966495Sspeer } 28973859Sml29623 } 28983859Sml29623 } 28993859Sml29623 29003859Sml29623 if (rxchan_fatal) { 29013859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 29026495Sspeer " nxge_rx_err_evnts: fatal error on Channel #%d\n", 29036495Sspeer channel)); 29046495Sspeer if (isLDOMguest(nxgep)) { 29056495Sspeer status = NXGE_ERROR; 29066495Sspeer } else { 29076495Sspeer status = nxge_rxdma_fatal_err_recover(nxgep, channel); 29086495Sspeer if (status == NXGE_OK) { 29096495Sspeer FM_SERVICE_RESTORED(nxgep); 29106495Sspeer } 29113859Sml29623 } 29123859Sml29623 } 29133859Sml29623 29143859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, "<== nxge_rx_err_evnts")); 29153859Sml29623 29163859Sml29623 return (status); 29173859Sml29623 } 29183859Sml29623 29196495Sspeer /* 29206495Sspeer * nxge_rdc_hvio_setup 29216495Sspeer * 29226495Sspeer * This code appears to setup some Hypervisor variables. 29236495Sspeer * 29246495Sspeer * Arguments: 29256495Sspeer * nxgep 29266495Sspeer * channel 29276495Sspeer * 29286495Sspeer * Notes: 29296495Sspeer * What does NIU_LP_WORKAROUND mean? 29306495Sspeer * 29316495Sspeer * NPI/NXGE function calls: 29326495Sspeer * na 29336495Sspeer * 29346495Sspeer * Context: 29356495Sspeer * Any domain 29366495Sspeer */ 29376495Sspeer #if defined(sun4v) && defined(NIU_LP_WORKAROUND) 29386495Sspeer static void 29396495Sspeer nxge_rdc_hvio_setup( 29406495Sspeer nxge_t *nxgep, int channel) 29413859Sml29623 { 29426495Sspeer nxge_dma_common_t *dma_common; 29436495Sspeer nxge_dma_common_t *dma_control; 29446495Sspeer rx_rbr_ring_t *ring; 29456495Sspeer 29466495Sspeer ring = nxgep->rx_rbr_rings->rbr_rings[channel]; 29476495Sspeer dma_common = nxgep->rx_buf_pool_p->dma_buf_pool_p[channel]; 29486495Sspeer 29496495Sspeer ring->hv_set = B_FALSE; 29506495Sspeer 29516495Sspeer ring->hv_rx_buf_base_ioaddr_pp = (uint64_t) 29526495Sspeer dma_common->orig_ioaddr_pp; 29536495Sspeer ring->hv_rx_buf_ioaddr_size = (uint64_t) 29546495Sspeer dma_common->orig_alength; 29556495Sspeer 29566495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_map_rxdma_channel: " 29576495Sspeer "channel %d data buf base io $%lx ($%p) size 0x%lx (%ld 0x%lx)", 29586495Sspeer channel, ring->hv_rx_buf_base_ioaddr_pp, 29596495Sspeer dma_common->ioaddr_pp, ring->hv_rx_buf_ioaddr_size, 29606495Sspeer dma_common->orig_alength, dma_common->orig_alength)); 29616495Sspeer 29626495Sspeer dma_control = nxgep->rx_cntl_pool_p->dma_buf_pool_p[channel]; 29636495Sspeer 29646495Sspeer ring->hv_rx_cntl_base_ioaddr_pp = 29656495Sspeer (uint64_t)dma_control->orig_ioaddr_pp; 29666495Sspeer ring->hv_rx_cntl_ioaddr_size = 29676495Sspeer (uint64_t)dma_control->orig_alength; 29686495Sspeer 29696495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_map_rxdma_channel: " 29706495Sspeer "channel %d cntl base io $%p ($%p) size 0x%llx (%d 0x%x)", 29716495Sspeer channel, ring->hv_rx_cntl_base_ioaddr_pp, 29726495Sspeer dma_control->ioaddr_pp, ring->hv_rx_cntl_ioaddr_size, 29736495Sspeer dma_control->orig_alength, dma_control->orig_alength)); 29746495Sspeer } 29753859Sml29623 #endif 29763859Sml29623 29776495Sspeer /* 29786495Sspeer * nxge_map_rxdma 29796495Sspeer * 29806495Sspeer * Map an RDC into our kernel space. 29816495Sspeer * 29826495Sspeer * Arguments: 29836495Sspeer * nxgep 29846495Sspeer * channel The channel to map. 29856495Sspeer * 29866495Sspeer * Notes: 29876495Sspeer * 1. Allocate & initialise a memory pool, if necessary. 29886495Sspeer * 2. Allocate however many receive buffers are required. 29896495Sspeer * 3. Setup buffers, descriptors, and mailbox. 29906495Sspeer * 29916495Sspeer * NPI/NXGE function calls: 29926495Sspeer * nxge_alloc_rx_mem_pool() 29936495Sspeer * nxge_alloc_rbb() 29946495Sspeer * nxge_map_rxdma_channel() 29956495Sspeer * 29966495Sspeer * Registers accessed: 29976495Sspeer * 29986495Sspeer * Context: 29996495Sspeer * Any domain 30006495Sspeer */ 30016495Sspeer static nxge_status_t 30026495Sspeer nxge_map_rxdma(p_nxge_t nxgep, int channel) 30036495Sspeer { 30046495Sspeer nxge_dma_common_t **data; 30056495Sspeer nxge_dma_common_t **control; 30066495Sspeer rx_rbr_ring_t **rbr_ring; 30076495Sspeer rx_rcr_ring_t **rcr_ring; 30086495Sspeer rx_mbox_t **mailbox; 30096495Sspeer uint32_t chunks; 30106495Sspeer 30116495Sspeer nxge_status_t status; 30126495Sspeer 30133859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_map_rxdma")); 30143859Sml29623 30156495Sspeer if (!nxgep->rx_buf_pool_p) { 30166495Sspeer if (nxge_alloc_rx_mem_pool(nxgep) != NXGE_OK) { 30176495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 30186495Sspeer "<== nxge_map_rxdma: buf not allocated")); 30196495Sspeer return (NXGE_ERROR); 30206495Sspeer } 30213859Sml29623 } 30223859Sml29623 30236495Sspeer if (nxge_alloc_rxb(nxgep, channel) != NXGE_OK) 30246495Sspeer return (NXGE_ERROR); 30253859Sml29623 30263859Sml29623 /* 30273859Sml29623 * Timeout should be set based on the system clock divider. 30283859Sml29623 * The following timeout value of 1 assumes that the 30293859Sml29623 * granularity (1000) is 3 microseconds running at 300MHz. 30303859Sml29623 */ 30313859Sml29623 30323859Sml29623 nxgep->intr_threshold = RXDMA_RCR_PTHRES_DEFAULT; 30333859Sml29623 nxgep->intr_timeout = RXDMA_RCR_TO_DEFAULT; 30343859Sml29623 30353859Sml29623 /* 30366495Sspeer * Map descriptors from the buffer polls for each dma channel. 30376495Sspeer */ 30386495Sspeer 30396495Sspeer /* 30406495Sspeer * Set up and prepare buffer blocks, descriptors 30416495Sspeer * and mailbox. 30423859Sml29623 */ 30436495Sspeer data = &nxgep->rx_buf_pool_p->dma_buf_pool_p[channel]; 30446495Sspeer rbr_ring = &nxgep->rx_rbr_rings->rbr_rings[channel]; 30456495Sspeer chunks = nxgep->rx_buf_pool_p->num_chunks[channel]; 30466495Sspeer 30476495Sspeer control = &nxgep->rx_cntl_pool_p->dma_buf_pool_p[channel]; 30486495Sspeer rcr_ring = &nxgep->rx_rcr_rings->rcr_rings[channel]; 30496495Sspeer 30506495Sspeer mailbox = &nxgep->rx_mbox_areas_p->rxmbox_areas[channel]; 30516495Sspeer 30526495Sspeer status = nxge_map_rxdma_channel(nxgep, channel, data, rbr_ring, 30536495Sspeer chunks, control, rcr_ring, mailbox); 30546495Sspeer if (status != NXGE_OK) { 30556495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 30566495Sspeer "==> nxge_map_rxdma: nxge_map_rxdma_channel(%d) " 30576495Sspeer "returned 0x%x", 30586495Sspeer channel, status)); 30596495Sspeer return (status); 30606495Sspeer } 30616495Sspeer nxgep->rx_rbr_rings->rbr_rings[channel]->index = (uint16_t)channel; 30626495Sspeer nxgep->rx_rcr_rings->rcr_rings[channel]->index = (uint16_t)channel; 30636495Sspeer nxgep->rx_rcr_rings->rcr_rings[channel]->rdc_stats = 30646495Sspeer &nxgep->statsp->rdc_stats[channel]; 30653859Sml29623 30663859Sml29623 #if defined(sun4v) && defined(NIU_LP_WORKAROUND) 30676495Sspeer if (!isLDOMguest(nxgep)) 30686495Sspeer nxge_rdc_hvio_setup(nxgep, channel); 30696495Sspeer #endif 30706495Sspeer 30713859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 30726495Sspeer "<== nxge_map_rxdma: (status 0x%x channel %d)", status, channel)); 30733859Sml29623 30743859Sml29623 return (status); 30753859Sml29623 } 30763859Sml29623 30773859Sml29623 static void 30786495Sspeer nxge_unmap_rxdma(p_nxge_t nxgep, int channel) 30793859Sml29623 { 30806495Sspeer rx_rbr_ring_t *rbr_ring; 30816495Sspeer rx_rcr_ring_t *rcr_ring; 30826495Sspeer rx_mbox_t *mailbox; 30836495Sspeer 30846495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_unmap_rxdma(%d)", channel)); 30856495Sspeer 30866495Sspeer if (!nxgep->rx_rbr_rings || !nxgep->rx_rcr_rings || 30876495Sspeer !nxgep->rx_mbox_areas_p) 30883859Sml29623 return; 30896495Sspeer 30906495Sspeer rbr_ring = nxgep->rx_rbr_rings->rbr_rings[channel]; 30916495Sspeer rcr_ring = nxgep->rx_rcr_rings->rcr_rings[channel]; 30926495Sspeer mailbox = nxgep->rx_mbox_areas_p->rxmbox_areas[channel]; 30936495Sspeer 30946495Sspeer if (!rbr_ring || !rcr_ring || !mailbox) 30953859Sml29623 return; 30966495Sspeer 30976495Sspeer (void) nxge_unmap_rxdma_channel( 30986495Sspeer nxgep, channel, rbr_ring, rcr_ring, mailbox); 30996495Sspeer 31006495Sspeer nxge_free_rxb(nxgep, channel); 31016495Sspeer 31026495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "<== nxge_unmap_rxdma")); 31033859Sml29623 } 31043859Sml29623 31053859Sml29623 nxge_status_t 31063859Sml29623 nxge_map_rxdma_channel(p_nxge_t nxgep, uint16_t channel, 31073859Sml29623 p_nxge_dma_common_t *dma_buf_p, p_rx_rbr_ring_t *rbr_p, 31083859Sml29623 uint32_t num_chunks, 31093859Sml29623 p_nxge_dma_common_t *dma_cntl_p, p_rx_rcr_ring_t *rcr_p, 31103859Sml29623 p_rx_mbox_t *rx_mbox_p) 31113859Sml29623 { 31123859Sml29623 int status = NXGE_OK; 31133859Sml29623 31143859Sml29623 /* 31153859Sml29623 * Set up and prepare buffer blocks, descriptors 31163859Sml29623 * and mailbox. 31173859Sml29623 */ 31183859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 31193859Sml29623 "==> nxge_map_rxdma_channel (channel %d)", channel)); 31203859Sml29623 /* 31213859Sml29623 * Receive buffer blocks 31223859Sml29623 */ 31233859Sml29623 status = nxge_map_rxdma_channel_buf_ring(nxgep, channel, 31243859Sml29623 dma_buf_p, rbr_p, num_chunks); 31253859Sml29623 if (status != NXGE_OK) { 31263859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 31273859Sml29623 "==> nxge_map_rxdma_channel (channel %d): " 31283859Sml29623 "map buffer failed 0x%x", channel, status)); 31293859Sml29623 goto nxge_map_rxdma_channel_exit; 31303859Sml29623 } 31313859Sml29623 31323859Sml29623 /* 31333859Sml29623 * Receive block ring, completion ring and mailbox. 31343859Sml29623 */ 31353859Sml29623 status = nxge_map_rxdma_channel_cfg_ring(nxgep, channel, 31363859Sml29623 dma_cntl_p, rbr_p, rcr_p, rx_mbox_p); 31373859Sml29623 if (status != NXGE_OK) { 31383859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 31393859Sml29623 "==> nxge_map_rxdma_channel (channel %d): " 31403859Sml29623 "map config failed 0x%x", channel, status)); 31413859Sml29623 goto nxge_map_rxdma_channel_fail2; 31423859Sml29623 } 31433859Sml29623 31443859Sml29623 goto nxge_map_rxdma_channel_exit; 31453859Sml29623 31463859Sml29623 nxge_map_rxdma_channel_fail3: 31473859Sml29623 /* Free rbr, rcr */ 31483859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 31493859Sml29623 "==> nxge_map_rxdma_channel: free rbr/rcr " 31503859Sml29623 "(status 0x%x channel %d)", 31513859Sml29623 status, channel)); 31523859Sml29623 nxge_unmap_rxdma_channel_cfg_ring(nxgep, 31533859Sml29623 *rcr_p, *rx_mbox_p); 31543859Sml29623 31553859Sml29623 nxge_map_rxdma_channel_fail2: 31563859Sml29623 /* Free buffer blocks */ 31573859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 31583859Sml29623 "==> nxge_map_rxdma_channel: free rx buffers" 31593859Sml29623 "(nxgep 0x%x status 0x%x channel %d)", 31603859Sml29623 nxgep, status, channel)); 31613859Sml29623 nxge_unmap_rxdma_channel_buf_ring(nxgep, *rbr_p); 31623859Sml29623 31634185Sspeer status = NXGE_ERROR; 31644185Sspeer 31653859Sml29623 nxge_map_rxdma_channel_exit: 31663859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 31673859Sml29623 "<== nxge_map_rxdma_channel: " 31683859Sml29623 "(nxgep 0x%x status 0x%x channel %d)", 31693859Sml29623 nxgep, status, channel)); 31703859Sml29623 31713859Sml29623 return (status); 31723859Sml29623 } 31733859Sml29623 31743859Sml29623 /*ARGSUSED*/ 31753859Sml29623 static void 31763859Sml29623 nxge_unmap_rxdma_channel(p_nxge_t nxgep, uint16_t channel, 31773859Sml29623 p_rx_rbr_ring_t rbr_p, p_rx_rcr_ring_t rcr_p, p_rx_mbox_t rx_mbox_p) 31783859Sml29623 { 31793859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 31803859Sml29623 "==> nxge_unmap_rxdma_channel (channel %d)", channel)); 31813859Sml29623 31823859Sml29623 /* 31833859Sml29623 * unmap receive block ring, completion ring and mailbox. 31843859Sml29623 */ 31853859Sml29623 (void) nxge_unmap_rxdma_channel_cfg_ring(nxgep, 31863859Sml29623 rcr_p, rx_mbox_p); 31873859Sml29623 31883859Sml29623 /* unmap buffer blocks */ 31893859Sml29623 (void) nxge_unmap_rxdma_channel_buf_ring(nxgep, rbr_p); 31903859Sml29623 31913859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "<== nxge_unmap_rxdma_channel")); 31923859Sml29623 } 31933859Sml29623 31943859Sml29623 /*ARGSUSED*/ 31953859Sml29623 static nxge_status_t 31963859Sml29623 nxge_map_rxdma_channel_cfg_ring(p_nxge_t nxgep, uint16_t dma_channel, 31973859Sml29623 p_nxge_dma_common_t *dma_cntl_p, p_rx_rbr_ring_t *rbr_p, 31983859Sml29623 p_rx_rcr_ring_t *rcr_p, p_rx_mbox_t *rx_mbox_p) 31993859Sml29623 { 32003859Sml29623 p_rx_rbr_ring_t rbrp; 32013859Sml29623 p_rx_rcr_ring_t rcrp; 32023859Sml29623 p_rx_mbox_t mboxp; 32033859Sml29623 p_nxge_dma_common_t cntl_dmap; 32043859Sml29623 p_nxge_dma_common_t dmap; 32053859Sml29623 p_rx_msg_t *rx_msg_ring; 32063859Sml29623 p_rx_msg_t rx_msg_p; 32073859Sml29623 p_rbr_cfig_a_t rcfga_p; 32083859Sml29623 p_rbr_cfig_b_t rcfgb_p; 32093859Sml29623 p_rcrcfig_a_t cfga_p; 32103859Sml29623 p_rcrcfig_b_t cfgb_p; 32113859Sml29623 p_rxdma_cfig1_t cfig1_p; 32123859Sml29623 p_rxdma_cfig2_t cfig2_p; 32133859Sml29623 p_rbr_kick_t kick_p; 32143859Sml29623 uint32_t dmaaddrp; 32153859Sml29623 uint32_t *rbr_vaddrp; 32163859Sml29623 uint32_t bkaddr; 32173859Sml29623 nxge_status_t status = NXGE_OK; 32183859Sml29623 int i; 32193859Sml29623 uint32_t nxge_port_rcr_size; 32203859Sml29623 32213859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 32223859Sml29623 "==> nxge_map_rxdma_channel_cfg_ring")); 32233859Sml29623 32243859Sml29623 cntl_dmap = *dma_cntl_p; 32253859Sml29623 32263859Sml29623 /* Map in the receive block ring */ 32273859Sml29623 rbrp = *rbr_p; 32283859Sml29623 dmap = (p_nxge_dma_common_t)&rbrp->rbr_desc; 32293859Sml29623 nxge_setup_dma_common(dmap, cntl_dmap, rbrp->rbb_max, 4); 32303859Sml29623 /* 32313859Sml29623 * Zero out buffer block ring descriptors. 32323859Sml29623 */ 32333859Sml29623 bzero((caddr_t)dmap->kaddrp, dmap->alength); 32343859Sml29623 32353859Sml29623 rcfga_p = &(rbrp->rbr_cfga); 32363859Sml29623 rcfgb_p = &(rbrp->rbr_cfgb); 32373859Sml29623 kick_p = &(rbrp->rbr_kick); 32383859Sml29623 rcfga_p->value = 0; 32393859Sml29623 rcfgb_p->value = 0; 32403859Sml29623 kick_p->value = 0; 32413859Sml29623 rbrp->rbr_addr = dmap->dma_cookie.dmac_laddress; 32423859Sml29623 rcfga_p->value = (rbrp->rbr_addr & 32433859Sml29623 (RBR_CFIG_A_STDADDR_MASK | 32443859Sml29623 RBR_CFIG_A_STDADDR_BASE_MASK)); 32453859Sml29623 rcfga_p->value |= ((uint64_t)rbrp->rbb_max << RBR_CFIG_A_LEN_SHIFT); 32463859Sml29623 32473859Sml29623 rcfgb_p->bits.ldw.bufsz0 = rbrp->pkt_buf_size0; 32483859Sml29623 rcfgb_p->bits.ldw.vld0 = 1; 32493859Sml29623 rcfgb_p->bits.ldw.bufsz1 = rbrp->pkt_buf_size1; 32503859Sml29623 rcfgb_p->bits.ldw.vld1 = 1; 32513859Sml29623 rcfgb_p->bits.ldw.bufsz2 = rbrp->pkt_buf_size2; 32523859Sml29623 rcfgb_p->bits.ldw.vld2 = 1; 32533859Sml29623 rcfgb_p->bits.ldw.bksize = nxgep->rx_bksize_code; 32543859Sml29623 32553859Sml29623 /* 32563859Sml29623 * For each buffer block, enter receive block address to the ring. 32573859Sml29623 */ 32583859Sml29623 rbr_vaddrp = (uint32_t *)dmap->kaddrp; 32593859Sml29623 rbrp->rbr_desc_vp = (uint32_t *)dmap->kaddrp; 32603859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 32613859Sml29623 "==> nxge_map_rxdma_channel_cfg_ring: channel %d " 32623859Sml29623 "rbr_vaddrp $%p", dma_channel, rbr_vaddrp)); 32633859Sml29623 32643859Sml29623 rx_msg_ring = rbrp->rx_msg_ring; 32653859Sml29623 for (i = 0; i < rbrp->tnblocks; i++) { 32663859Sml29623 rx_msg_p = rx_msg_ring[i]; 32673859Sml29623 rx_msg_p->nxgep = nxgep; 32683859Sml29623 rx_msg_p->rx_rbr_p = rbrp; 32693859Sml29623 bkaddr = (uint32_t) 32703859Sml29623 ((rx_msg_p->buf_dma.dma_cookie.dmac_laddress 32713859Sml29623 >> RBR_BKADDR_SHIFT)); 32723859Sml29623 rx_msg_p->free = B_FALSE; 32733859Sml29623 rx_msg_p->max_usage_cnt = 0xbaddcafe; 32743859Sml29623 32753859Sml29623 *rbr_vaddrp++ = bkaddr; 32763859Sml29623 } 32773859Sml29623 32783859Sml29623 kick_p->bits.ldw.bkadd = rbrp->rbb_max; 32793859Sml29623 rbrp->rbr_wr_index = (rbrp->rbb_max - 1); 32803859Sml29623 32813859Sml29623 rbrp->rbr_rd_index = 0; 32823859Sml29623 32833859Sml29623 rbrp->rbr_consumed = 0; 32843859Sml29623 rbrp->rbr_use_bcopy = B_TRUE; 32853859Sml29623 rbrp->rbr_bufsize_type = RCR_PKTBUFSZ_0; 32863859Sml29623 /* 32873859Sml29623 * Do bcopy on packets greater than bcopy size once 32883859Sml29623 * the lo threshold is reached. 32893859Sml29623 * This lo threshold should be less than the hi threshold. 32903859Sml29623 * 32913859Sml29623 * Do bcopy on every packet once the hi threshold is reached. 32923859Sml29623 */ 32933859Sml29623 if (nxge_rx_threshold_lo >= nxge_rx_threshold_hi) { 32943859Sml29623 /* default it to use hi */ 32953859Sml29623 nxge_rx_threshold_lo = nxge_rx_threshold_hi; 32963859Sml29623 } 32973859Sml29623 32983859Sml29623 if (nxge_rx_buf_size_type > NXGE_RBR_TYPE2) { 32993859Sml29623 nxge_rx_buf_size_type = NXGE_RBR_TYPE2; 33003859Sml29623 } 33013859Sml29623 rbrp->rbr_bufsize_type = nxge_rx_buf_size_type; 33023859Sml29623 33033859Sml29623 switch (nxge_rx_threshold_hi) { 33043859Sml29623 default: 33053859Sml29623 case NXGE_RX_COPY_NONE: 33063859Sml29623 /* Do not do bcopy at all */ 33073859Sml29623 rbrp->rbr_use_bcopy = B_FALSE; 33083859Sml29623 rbrp->rbr_threshold_hi = rbrp->rbb_max; 33093859Sml29623 break; 33103859Sml29623 33113859Sml29623 case NXGE_RX_COPY_1: 33123859Sml29623 case NXGE_RX_COPY_2: 33133859Sml29623 case NXGE_RX_COPY_3: 33143859Sml29623 case NXGE_RX_COPY_4: 33153859Sml29623 case NXGE_RX_COPY_5: 33163859Sml29623 case NXGE_RX_COPY_6: 33173859Sml29623 case NXGE_RX_COPY_7: 33183859Sml29623 rbrp->rbr_threshold_hi = 33193859Sml29623 rbrp->rbb_max * 33203859Sml29623 (nxge_rx_threshold_hi)/NXGE_RX_BCOPY_SCALE; 33213859Sml29623 break; 33223859Sml29623 33233859Sml29623 case NXGE_RX_COPY_ALL: 33243859Sml29623 rbrp->rbr_threshold_hi = 0; 33253859Sml29623 break; 33263859Sml29623 } 33273859Sml29623 33283859Sml29623 switch (nxge_rx_threshold_lo) { 33293859Sml29623 default: 33303859Sml29623 case NXGE_RX_COPY_NONE: 33313859Sml29623 /* Do not do bcopy at all */ 33323859Sml29623 if (rbrp->rbr_use_bcopy) { 33333859Sml29623 rbrp->rbr_use_bcopy = B_FALSE; 33343859Sml29623 } 33353859Sml29623 rbrp->rbr_threshold_lo = rbrp->rbb_max; 33363859Sml29623 break; 33373859Sml29623 33383859Sml29623 case NXGE_RX_COPY_1: 33393859Sml29623 case NXGE_RX_COPY_2: 33403859Sml29623 case NXGE_RX_COPY_3: 33413859Sml29623 case NXGE_RX_COPY_4: 33423859Sml29623 case NXGE_RX_COPY_5: 33433859Sml29623 case NXGE_RX_COPY_6: 33443859Sml29623 case NXGE_RX_COPY_7: 33453859Sml29623 rbrp->rbr_threshold_lo = 33463859Sml29623 rbrp->rbb_max * 33473859Sml29623 (nxge_rx_threshold_lo)/NXGE_RX_BCOPY_SCALE; 33483859Sml29623 break; 33493859Sml29623 33503859Sml29623 case NXGE_RX_COPY_ALL: 33513859Sml29623 rbrp->rbr_threshold_lo = 0; 33523859Sml29623 break; 33533859Sml29623 } 33543859Sml29623 33553859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 33563859Sml29623 "nxge_map_rxdma_channel_cfg_ring: channel %d " 33573859Sml29623 "rbb_max %d " 33583859Sml29623 "rbrp->rbr_bufsize_type %d " 33593859Sml29623 "rbb_threshold_hi %d " 33603859Sml29623 "rbb_threshold_lo %d", 33613859Sml29623 dma_channel, 33623859Sml29623 rbrp->rbb_max, 33633859Sml29623 rbrp->rbr_bufsize_type, 33643859Sml29623 rbrp->rbr_threshold_hi, 33653859Sml29623 rbrp->rbr_threshold_lo)); 33663859Sml29623 33673859Sml29623 rbrp->page_valid.value = 0; 33683859Sml29623 rbrp->page_mask_1.value = rbrp->page_mask_2.value = 0; 33693859Sml29623 rbrp->page_value_1.value = rbrp->page_value_2.value = 0; 33703859Sml29623 rbrp->page_reloc_1.value = rbrp->page_reloc_2.value = 0; 33713859Sml29623 rbrp->page_hdl.value = 0; 33723859Sml29623 33733859Sml29623 rbrp->page_valid.bits.ldw.page0 = 1; 33743859Sml29623 rbrp->page_valid.bits.ldw.page1 = 1; 33753859Sml29623 33763859Sml29623 /* Map in the receive completion ring */ 33773859Sml29623 rcrp = (p_rx_rcr_ring_t) 33783859Sml29623 KMEM_ZALLOC(sizeof (rx_rcr_ring_t), KM_SLEEP); 33793859Sml29623 rcrp->rdc = dma_channel; 33803859Sml29623 33813859Sml29623 nxge_port_rcr_size = nxgep->nxge_port_rcr_size; 33823859Sml29623 rcrp->comp_size = nxge_port_rcr_size; 33833859Sml29623 rcrp->comp_wrap_mask = nxge_port_rcr_size - 1; 33843859Sml29623 33853859Sml29623 rcrp->max_receive_pkts = nxge_max_rx_pkts; 33863859Sml29623 33873859Sml29623 dmap = (p_nxge_dma_common_t)&rcrp->rcr_desc; 33883859Sml29623 nxge_setup_dma_common(dmap, cntl_dmap, rcrp->comp_size, 33893859Sml29623 sizeof (rcr_entry_t)); 33903859Sml29623 rcrp->comp_rd_index = 0; 33913859Sml29623 rcrp->comp_wt_index = 0; 33923859Sml29623 rcrp->rcr_desc_rd_head_p = rcrp->rcr_desc_first_p = 33933859Sml29623 (p_rcr_entry_t)DMA_COMMON_VPTR(rcrp->rcr_desc); 33943859Sml29623 rcrp->rcr_desc_rd_head_pp = rcrp->rcr_desc_first_pp = 33955125Sjoycey #if defined(__i386) 33965125Sjoycey (p_rcr_entry_t)(uint32_t)DMA_COMMON_IOADDR(rcrp->rcr_desc); 33975125Sjoycey #else 33983859Sml29623 (p_rcr_entry_t)DMA_COMMON_IOADDR(rcrp->rcr_desc); 33995125Sjoycey #endif 34003859Sml29623 34013859Sml29623 rcrp->rcr_desc_last_p = rcrp->rcr_desc_rd_head_p + 34023859Sml29623 (nxge_port_rcr_size - 1); 34033859Sml29623 rcrp->rcr_desc_last_pp = rcrp->rcr_desc_rd_head_pp + 34043859Sml29623 (nxge_port_rcr_size - 1); 34053859Sml29623 34063859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 34073859Sml29623 "==> nxge_map_rxdma_channel_cfg_ring: " 34083859Sml29623 "channel %d " 34093859Sml29623 "rbr_vaddrp $%p " 34103859Sml29623 "rcr_desc_rd_head_p $%p " 34113859Sml29623 "rcr_desc_rd_head_pp $%p " 34123859Sml29623 "rcr_desc_rd_last_p $%p " 34133859Sml29623 "rcr_desc_rd_last_pp $%p ", 34143859Sml29623 dma_channel, 34153859Sml29623 rbr_vaddrp, 34163859Sml29623 rcrp->rcr_desc_rd_head_p, 34173859Sml29623 rcrp->rcr_desc_rd_head_pp, 34183859Sml29623 rcrp->rcr_desc_last_p, 34193859Sml29623 rcrp->rcr_desc_last_pp)); 34203859Sml29623 34213859Sml29623 /* 34223859Sml29623 * Zero out buffer block ring descriptors. 34233859Sml29623 */ 34243859Sml29623 bzero((caddr_t)dmap->kaddrp, dmap->alength); 34253859Sml29623 rcrp->intr_timeout = nxgep->intr_timeout; 34263859Sml29623 rcrp->intr_threshold = nxgep->intr_threshold; 34273859Sml29623 rcrp->full_hdr_flag = B_FALSE; 34283859Sml29623 rcrp->sw_priv_hdr_len = 0; 34293859Sml29623 34303859Sml29623 cfga_p = &(rcrp->rcr_cfga); 34313859Sml29623 cfgb_p = &(rcrp->rcr_cfgb); 34323859Sml29623 cfga_p->value = 0; 34333859Sml29623 cfgb_p->value = 0; 34343859Sml29623 rcrp->rcr_addr = dmap->dma_cookie.dmac_laddress; 34353859Sml29623 cfga_p->value = (rcrp->rcr_addr & 34363859Sml29623 (RCRCFIG_A_STADDR_MASK | 34373859Sml29623 RCRCFIG_A_STADDR_BASE_MASK)); 34383859Sml29623 34393859Sml29623 rcfga_p->value |= ((uint64_t)rcrp->comp_size << 34403859Sml29623 RCRCFIG_A_LEN_SHIF); 34413859Sml29623 34423859Sml29623 /* 34433859Sml29623 * Timeout should be set based on the system clock divider. 34443859Sml29623 * The following timeout value of 1 assumes that the 34453859Sml29623 * granularity (1000) is 3 microseconds running at 300MHz. 34463859Sml29623 */ 34473859Sml29623 cfgb_p->bits.ldw.pthres = rcrp->intr_threshold; 34483859Sml29623 cfgb_p->bits.ldw.timeout = rcrp->intr_timeout; 34493859Sml29623 cfgb_p->bits.ldw.entout = 1; 34503859Sml29623 34513859Sml29623 /* Map in the mailbox */ 34523859Sml29623 mboxp = (p_rx_mbox_t) 34533859Sml29623 KMEM_ZALLOC(sizeof (rx_mbox_t), KM_SLEEP); 34543859Sml29623 dmap = (p_nxge_dma_common_t)&mboxp->rx_mbox; 34553859Sml29623 nxge_setup_dma_common(dmap, cntl_dmap, 1, sizeof (rxdma_mailbox_t)); 34563859Sml29623 cfig1_p = (p_rxdma_cfig1_t)&mboxp->rx_cfg1; 34573859Sml29623 cfig2_p = (p_rxdma_cfig2_t)&mboxp->rx_cfg2; 34583859Sml29623 cfig1_p->value = cfig2_p->value = 0; 34593859Sml29623 34603859Sml29623 mboxp->mbox_addr = dmap->dma_cookie.dmac_laddress; 34613859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 34623859Sml29623 "==> nxge_map_rxdma_channel_cfg_ring: " 34633859Sml29623 "channel %d cfg1 0x%016llx cfig2 0x%016llx cookie 0x%016llx", 34643859Sml29623 dma_channel, cfig1_p->value, cfig2_p->value, 34653859Sml29623 mboxp->mbox_addr)); 34663859Sml29623 34673859Sml29623 dmaaddrp = (uint32_t)(dmap->dma_cookie.dmac_laddress >> 32 34683859Sml29623 & 0xfff); 34693859Sml29623 cfig1_p->bits.ldw.mbaddr_h = dmaaddrp; 34703859Sml29623 34713859Sml29623 34723859Sml29623 dmaaddrp = (uint32_t)(dmap->dma_cookie.dmac_laddress & 0xffffffff); 34733859Sml29623 dmaaddrp = (uint32_t)(dmap->dma_cookie.dmac_laddress & 34743859Sml29623 RXDMA_CFIG2_MBADDR_L_MASK); 34753859Sml29623 34763859Sml29623 cfig2_p->bits.ldw.mbaddr = (dmaaddrp >> RXDMA_CFIG2_MBADDR_L_SHIFT); 34773859Sml29623 34783859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 34793859Sml29623 "==> nxge_map_rxdma_channel_cfg_ring: " 34803859Sml29623 "channel %d damaddrp $%p " 34813859Sml29623 "cfg1 0x%016llx cfig2 0x%016llx", 34823859Sml29623 dma_channel, dmaaddrp, 34833859Sml29623 cfig1_p->value, cfig2_p->value)); 34843859Sml29623 34853859Sml29623 cfig2_p->bits.ldw.full_hdr = rcrp->full_hdr_flag; 34863859Sml29623 cfig2_p->bits.ldw.offset = rcrp->sw_priv_hdr_len; 34873859Sml29623 34883859Sml29623 rbrp->rx_rcr_p = rcrp; 34893859Sml29623 rcrp->rx_rbr_p = rbrp; 34903859Sml29623 *rcr_p = rcrp; 34913859Sml29623 *rx_mbox_p = mboxp; 34923859Sml29623 34933859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 34943859Sml29623 "<== nxge_map_rxdma_channel_cfg_ring status 0x%08x", status)); 34953859Sml29623 34963859Sml29623 return (status); 34973859Sml29623 } 34983859Sml29623 34993859Sml29623 /*ARGSUSED*/ 35003859Sml29623 static void 35013859Sml29623 nxge_unmap_rxdma_channel_cfg_ring(p_nxge_t nxgep, 35023859Sml29623 p_rx_rcr_ring_t rcr_p, p_rx_mbox_t rx_mbox_p) 35033859Sml29623 { 35043859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 35053859Sml29623 "==> nxge_unmap_rxdma_channel_cfg_ring: channel %d", 35063859Sml29623 rcr_p->rdc)); 35073859Sml29623 35083859Sml29623 KMEM_FREE(rcr_p, sizeof (rx_rcr_ring_t)); 35093859Sml29623 KMEM_FREE(rx_mbox_p, sizeof (rx_mbox_t)); 35103859Sml29623 35113859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 35123859Sml29623 "<== nxge_unmap_rxdma_channel_cfg_ring")); 35133859Sml29623 } 35143859Sml29623 35153859Sml29623 static nxge_status_t 35163859Sml29623 nxge_map_rxdma_channel_buf_ring(p_nxge_t nxgep, uint16_t channel, 35173859Sml29623 p_nxge_dma_common_t *dma_buf_p, 35183859Sml29623 p_rx_rbr_ring_t *rbr_p, uint32_t num_chunks) 35193859Sml29623 { 35203859Sml29623 p_rx_rbr_ring_t rbrp; 35213859Sml29623 p_nxge_dma_common_t dma_bufp, tmp_bufp; 35223859Sml29623 p_rx_msg_t *rx_msg_ring; 35233859Sml29623 p_rx_msg_t rx_msg_p; 35243859Sml29623 p_mblk_t mblk_p; 35253859Sml29623 35263859Sml29623 rxring_info_t *ring_info; 35273859Sml29623 nxge_status_t status = NXGE_OK; 35283859Sml29623 int i, j, index; 35293859Sml29623 uint32_t size, bsize, nblocks, nmsgs; 35303859Sml29623 35313859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 35323859Sml29623 "==> nxge_map_rxdma_channel_buf_ring: channel %d", 35333859Sml29623 channel)); 35343859Sml29623 35353859Sml29623 dma_bufp = tmp_bufp = *dma_buf_p; 35363859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 35373859Sml29623 " nxge_map_rxdma_channel_buf_ring: channel %d to map %d " 35383859Sml29623 "chunks bufp 0x%016llx", 35393859Sml29623 channel, num_chunks, dma_bufp)); 35403859Sml29623 35413859Sml29623 nmsgs = 0; 35423859Sml29623 for (i = 0; i < num_chunks; i++, tmp_bufp++) { 35433859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 35443859Sml29623 "==> nxge_map_rxdma_channel_buf_ring: channel %d " 35453859Sml29623 "bufp 0x%016llx nblocks %d nmsgs %d", 35463859Sml29623 channel, tmp_bufp, tmp_bufp->nblocks, nmsgs)); 35473859Sml29623 nmsgs += tmp_bufp->nblocks; 35483859Sml29623 } 35493859Sml29623 if (!nmsgs) { 35504185Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 35513859Sml29623 "<== nxge_map_rxdma_channel_buf_ring: channel %d " 35523859Sml29623 "no msg blocks", 35533859Sml29623 channel)); 35543859Sml29623 status = NXGE_ERROR; 35553859Sml29623 goto nxge_map_rxdma_channel_buf_ring_exit; 35563859Sml29623 } 35573859Sml29623 35585170Stm144005 rbrp = (p_rx_rbr_ring_t)KMEM_ZALLOC(sizeof (*rbrp), KM_SLEEP); 35593859Sml29623 35603859Sml29623 size = nmsgs * sizeof (p_rx_msg_t); 35613859Sml29623 rx_msg_ring = KMEM_ZALLOC(size, KM_SLEEP); 35623859Sml29623 ring_info = (rxring_info_t *)KMEM_ZALLOC(sizeof (rxring_info_t), 35633859Sml29623 KM_SLEEP); 35643859Sml29623 35653859Sml29623 MUTEX_INIT(&rbrp->lock, NULL, MUTEX_DRIVER, 35663859Sml29623 (void *)nxgep->interrupt_cookie); 35673859Sml29623 MUTEX_INIT(&rbrp->post_lock, NULL, MUTEX_DRIVER, 35683859Sml29623 (void *)nxgep->interrupt_cookie); 35693859Sml29623 rbrp->rdc = channel; 35703859Sml29623 rbrp->num_blocks = num_chunks; 35713859Sml29623 rbrp->tnblocks = nmsgs; 35723859Sml29623 rbrp->rbb_max = nmsgs; 35733859Sml29623 rbrp->rbr_max_size = nmsgs; 35743859Sml29623 rbrp->rbr_wrap_mask = (rbrp->rbb_max - 1); 35753859Sml29623 35763859Sml29623 /* 35773859Sml29623 * Buffer sizes suggested by NIU architect. 35783859Sml29623 * 256, 512 and 2K. 35793859Sml29623 */ 35803859Sml29623 35813859Sml29623 rbrp->pkt_buf_size0 = RBR_BUFSZ0_256B; 35823859Sml29623 rbrp->pkt_buf_size0_bytes = RBR_BUFSZ0_256_BYTES; 35833859Sml29623 rbrp->npi_pkt_buf_size0 = SIZE_256B; 35843859Sml29623 35853859Sml29623 rbrp->pkt_buf_size1 = RBR_BUFSZ1_1K; 35863859Sml29623 rbrp->pkt_buf_size1_bytes = RBR_BUFSZ1_1K_BYTES; 35873859Sml29623 rbrp->npi_pkt_buf_size1 = SIZE_1KB; 35883859Sml29623 35893859Sml29623 rbrp->block_size = nxgep->rx_default_block_size; 35903859Sml29623 35913859Sml29623 if (!nxge_jumbo_enable && !nxgep->param_arr[param_accept_jumbo].value) { 35923859Sml29623 rbrp->pkt_buf_size2 = RBR_BUFSZ2_2K; 35933859Sml29623 rbrp->pkt_buf_size2_bytes = RBR_BUFSZ2_2K_BYTES; 35943859Sml29623 rbrp->npi_pkt_buf_size2 = SIZE_2KB; 35953859Sml29623 } else { 35963859Sml29623 if (rbrp->block_size >= 0x2000) { 35973859Sml29623 rbrp->pkt_buf_size2 = RBR_BUFSZ2_8K; 35983859Sml29623 rbrp->pkt_buf_size2_bytes = RBR_BUFSZ2_8K_BYTES; 35993859Sml29623 rbrp->npi_pkt_buf_size2 = SIZE_8KB; 36003859Sml29623 } else { 36013859Sml29623 rbrp->pkt_buf_size2 = RBR_BUFSZ2_4K; 36023859Sml29623 rbrp->pkt_buf_size2_bytes = RBR_BUFSZ2_4K_BYTES; 36033859Sml29623 rbrp->npi_pkt_buf_size2 = SIZE_4KB; 36043859Sml29623 } 36053859Sml29623 } 36063859Sml29623 36073859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 36083859Sml29623 "==> nxge_map_rxdma_channel_buf_ring: channel %d " 36093859Sml29623 "actual rbr max %d rbb_max %d nmsgs %d " 36103859Sml29623 "rbrp->block_size %d default_block_size %d " 36113859Sml29623 "(config nxge_rbr_size %d nxge_rbr_spare_size %d)", 36123859Sml29623 channel, rbrp->rbr_max_size, rbrp->rbb_max, nmsgs, 36133859Sml29623 rbrp->block_size, nxgep->rx_default_block_size, 36143859Sml29623 nxge_rbr_size, nxge_rbr_spare_size)); 36153859Sml29623 36163859Sml29623 /* Map in buffers from the buffer pool. */ 36173859Sml29623 index = 0; 36183859Sml29623 for (i = 0; i < rbrp->num_blocks; i++, dma_bufp++) { 36193859Sml29623 bsize = dma_bufp->block_size; 36203859Sml29623 nblocks = dma_bufp->nblocks; 36215125Sjoycey #if defined(__i386) 36225125Sjoycey ring_info->buffer[i].dvma_addr = (uint32_t)dma_bufp->ioaddr_pp; 36235125Sjoycey #else 36243859Sml29623 ring_info->buffer[i].dvma_addr = (uint64_t)dma_bufp->ioaddr_pp; 36255125Sjoycey #endif 36263859Sml29623 ring_info->buffer[i].buf_index = i; 36273859Sml29623 ring_info->buffer[i].buf_size = dma_bufp->alength; 36283859Sml29623 ring_info->buffer[i].start_index = index; 36295125Sjoycey #if defined(__i386) 36305125Sjoycey ring_info->buffer[i].kaddr = (uint32_t)dma_bufp->kaddrp; 36315125Sjoycey #else 36323859Sml29623 ring_info->buffer[i].kaddr = (uint64_t)dma_bufp->kaddrp; 36335125Sjoycey #endif 36343859Sml29623 36353859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 36363859Sml29623 " nxge_map_rxdma_channel_buf_ring: map channel %d " 36373859Sml29623 "chunk %d" 36383859Sml29623 " nblocks %d chunk_size %x block_size 0x%x " 36393859Sml29623 "dma_bufp $%p", channel, i, 36403859Sml29623 dma_bufp->nblocks, ring_info->buffer[i].buf_size, bsize, 36413859Sml29623 dma_bufp)); 36423859Sml29623 36433859Sml29623 for (j = 0; j < nblocks; j++) { 36443859Sml29623 if ((rx_msg_p = nxge_allocb(bsize, BPRI_LO, 36453859Sml29623 dma_bufp)) == NULL) { 36464185Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 36474185Sspeer "allocb failed (index %d i %d j %d)", 36484185Sspeer index, i, j)); 36494185Sspeer goto nxge_map_rxdma_channel_buf_ring_fail1; 36503859Sml29623 } 36513859Sml29623 rx_msg_ring[index] = rx_msg_p; 36523859Sml29623 rx_msg_p->block_index = index; 36533859Sml29623 rx_msg_p->shifted_addr = (uint32_t) 36543859Sml29623 ((rx_msg_p->buf_dma.dma_cookie.dmac_laddress >> 36553859Sml29623 RBR_BKADDR_SHIFT)); 36563859Sml29623 36573859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 36584185Sspeer "index %d j %d rx_msg_p $%p mblk %p", 36594185Sspeer index, j, rx_msg_p, rx_msg_p->rx_mblk_p)); 36603859Sml29623 36613859Sml29623 mblk_p = rx_msg_p->rx_mblk_p; 36623859Sml29623 mblk_p->b_wptr = mblk_p->b_rptr + bsize; 36635170Stm144005 36645170Stm144005 rbrp->rbr_ref_cnt++; 36653859Sml29623 index++; 36663859Sml29623 rx_msg_p->buf_dma.dma_channel = channel; 36673859Sml29623 } 36686495Sspeer 36696495Sspeer rbrp->rbr_alloc_type = DDI_MEM_ALLOC; 36706495Sspeer if (dma_bufp->contig_alloc_type) { 36716495Sspeer rbrp->rbr_alloc_type = CONTIG_MEM_ALLOC; 36726495Sspeer } 36736495Sspeer 36746495Sspeer if (dma_bufp->kmem_alloc_type) { 36756495Sspeer rbrp->rbr_alloc_type = KMEM_ALLOC; 36766495Sspeer } 36776495Sspeer 36786495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 36796495Sspeer " nxge_map_rxdma_channel_buf_ring: map channel %d " 36806495Sspeer "chunk %d" 36816495Sspeer " nblocks %d chunk_size %x block_size 0x%x " 36826495Sspeer "dma_bufp $%p", 36836495Sspeer channel, i, 36846495Sspeer dma_bufp->nblocks, ring_info->buffer[i].buf_size, bsize, 36856495Sspeer dma_bufp)); 36863859Sml29623 } 36873859Sml29623 if (i < rbrp->num_blocks) { 36883859Sml29623 goto nxge_map_rxdma_channel_buf_ring_fail1; 36893859Sml29623 } 36903859Sml29623 36913859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 36923859Sml29623 "nxge_map_rxdma_channel_buf_ring: done buf init " 36933859Sml29623 "channel %d msg block entries %d", 36943859Sml29623 channel, index)); 36953859Sml29623 ring_info->block_size_mask = bsize - 1; 36963859Sml29623 rbrp->rx_msg_ring = rx_msg_ring; 36973859Sml29623 rbrp->dma_bufp = dma_buf_p; 36983859Sml29623 rbrp->ring_info = ring_info; 36993859Sml29623 37003859Sml29623 status = nxge_rxbuf_index_info_init(nxgep, rbrp); 37013859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 37023859Sml29623 " nxge_map_rxdma_channel_buf_ring: " 37033859Sml29623 "channel %d done buf info init", channel)); 37043859Sml29623 37055170Stm144005 /* 37065170Stm144005 * Finally, permit nxge_freeb() to call nxge_post_page(). 37075170Stm144005 */ 37085170Stm144005 rbrp->rbr_state = RBR_POSTING; 37095170Stm144005 37103859Sml29623 *rbr_p = rbrp; 37113859Sml29623 goto nxge_map_rxdma_channel_buf_ring_exit; 37123859Sml29623 37133859Sml29623 nxge_map_rxdma_channel_buf_ring_fail1: 37143859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 37153859Sml29623 " nxge_map_rxdma_channel_buf_ring: failed channel (0x%x)", 37163859Sml29623 channel, status)); 37173859Sml29623 37183859Sml29623 index--; 37193859Sml29623 for (; index >= 0; index--) { 37203859Sml29623 rx_msg_p = rx_msg_ring[index]; 37213859Sml29623 if (rx_msg_p != NULL) { 37223859Sml29623 freeb(rx_msg_p->rx_mblk_p); 37233859Sml29623 rx_msg_ring[index] = NULL; 37243859Sml29623 } 37253859Sml29623 } 37263859Sml29623 nxge_map_rxdma_channel_buf_ring_fail: 37273859Sml29623 MUTEX_DESTROY(&rbrp->post_lock); 37283859Sml29623 MUTEX_DESTROY(&rbrp->lock); 37293859Sml29623 KMEM_FREE(ring_info, sizeof (rxring_info_t)); 37303859Sml29623 KMEM_FREE(rx_msg_ring, size); 37313859Sml29623 KMEM_FREE(rbrp, sizeof (rx_rbr_ring_t)); 37323859Sml29623 37334185Sspeer status = NXGE_ERROR; 37344185Sspeer 37353859Sml29623 nxge_map_rxdma_channel_buf_ring_exit: 37363859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 37373859Sml29623 "<== nxge_map_rxdma_channel_buf_ring status 0x%08x", status)); 37383859Sml29623 37393859Sml29623 return (status); 37403859Sml29623 } 37413859Sml29623 37423859Sml29623 /*ARGSUSED*/ 37433859Sml29623 static void 37443859Sml29623 nxge_unmap_rxdma_channel_buf_ring(p_nxge_t nxgep, 37453859Sml29623 p_rx_rbr_ring_t rbr_p) 37463859Sml29623 { 37473859Sml29623 p_rx_msg_t *rx_msg_ring; 37483859Sml29623 p_rx_msg_t rx_msg_p; 37493859Sml29623 rxring_info_t *ring_info; 37503859Sml29623 int i; 37513859Sml29623 uint32_t size; 37523859Sml29623 #ifdef NXGE_DEBUG 37533859Sml29623 int num_chunks; 37543859Sml29623 #endif 37553859Sml29623 37563859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 37573859Sml29623 "==> nxge_unmap_rxdma_channel_buf_ring")); 37583859Sml29623 if (rbr_p == NULL) { 37593859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 37603859Sml29623 "<== nxge_unmap_rxdma_channel_buf_ring: NULL rbrp")); 37613859Sml29623 return; 37623859Sml29623 } 37633859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 37643859Sml29623 "==> nxge_unmap_rxdma_channel_buf_ring: channel %d", 37653859Sml29623 rbr_p->rdc)); 37663859Sml29623 37673859Sml29623 rx_msg_ring = rbr_p->rx_msg_ring; 37683859Sml29623 ring_info = rbr_p->ring_info; 37693859Sml29623 37703859Sml29623 if (rx_msg_ring == NULL || ring_info == NULL) { 37713859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 37723859Sml29623 "<== nxge_unmap_rxdma_channel_buf_ring: " 37733859Sml29623 "rx_msg_ring $%p ring_info $%p", 37743859Sml29623 rx_msg_p, ring_info)); 37753859Sml29623 return; 37763859Sml29623 } 37773859Sml29623 37783859Sml29623 #ifdef NXGE_DEBUG 37793859Sml29623 num_chunks = rbr_p->num_blocks; 37803859Sml29623 #endif 37813859Sml29623 size = rbr_p->tnblocks * sizeof (p_rx_msg_t); 37823859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 37833859Sml29623 " nxge_unmap_rxdma_channel_buf_ring: channel %d chunks %d " 37843859Sml29623 "tnblocks %d (max %d) size ptrs %d ", 37853859Sml29623 rbr_p->rdc, num_chunks, 37863859Sml29623 rbr_p->tnblocks, rbr_p->rbr_max_size, size)); 37873859Sml29623 37883859Sml29623 for (i = 0; i < rbr_p->tnblocks; i++) { 37893859Sml29623 rx_msg_p = rx_msg_ring[i]; 37903859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 37913859Sml29623 " nxge_unmap_rxdma_channel_buf_ring: " 37923859Sml29623 "rx_msg_p $%p", 37933859Sml29623 rx_msg_p)); 37943859Sml29623 if (rx_msg_p != NULL) { 37953859Sml29623 freeb(rx_msg_p->rx_mblk_p); 37963859Sml29623 rx_msg_ring[i] = NULL; 37973859Sml29623 } 37983859Sml29623 } 37993859Sml29623 38005170Stm144005 /* 38015170Stm144005 * We no longer may use the mutex <post_lock>. By setting 38025170Stm144005 * <rbr_state> to anything but POSTING, we prevent 38035170Stm144005 * nxge_post_page() from accessing a dead mutex. 38045170Stm144005 */ 38055170Stm144005 rbr_p->rbr_state = RBR_UNMAPPING; 38063859Sml29623 MUTEX_DESTROY(&rbr_p->post_lock); 38075170Stm144005 38083859Sml29623 MUTEX_DESTROY(&rbr_p->lock); 38095170Stm144005 38105170Stm144005 if (rbr_p->rbr_ref_cnt == 0) { 38116495Sspeer /* 38126495Sspeer * This is the normal state of affairs. 38136495Sspeer * Need to free the following buffers: 38146495Sspeer * - data buffers 38156495Sspeer * - rx_msg ring 38166495Sspeer * - ring_info 38176495Sspeer * - rbr ring 38186495Sspeer */ 38196495Sspeer NXGE_DEBUG_MSG((nxgep, RX_CTL, 38206495Sspeer "unmap_rxdma_buf_ring: No outstanding - freeing ")); 38216495Sspeer nxge_rxdma_databuf_free(rbr_p); 38226495Sspeer KMEM_FREE(ring_info, sizeof (rxring_info_t)); 38236495Sspeer KMEM_FREE(rx_msg_ring, size); 38245170Stm144005 KMEM_FREE(rbr_p, sizeof (*rbr_p)); 38255170Stm144005 } else { 38265170Stm144005 /* 38275170Stm144005 * Some of our buffers are still being used. 38285170Stm144005 * Therefore, tell nxge_freeb() this ring is 38295170Stm144005 * unmapped, so it may free <rbr_p> for us. 38305170Stm144005 */ 38315170Stm144005 rbr_p->rbr_state = RBR_UNMAPPED; 38325170Stm144005 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 38335170Stm144005 "unmap_rxdma_buf_ring: %d %s outstanding.", 38345170Stm144005 rbr_p->rbr_ref_cnt, 38355170Stm144005 rbr_p->rbr_ref_cnt == 1 ? "msg" : "msgs")); 38365170Stm144005 } 38373859Sml29623 38383859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 38393859Sml29623 "<== nxge_unmap_rxdma_channel_buf_ring")); 38403859Sml29623 } 38413859Sml29623 38426495Sspeer /* 38436495Sspeer * nxge_rxdma_hw_start_common 38446495Sspeer * 38456495Sspeer * Arguments: 38466495Sspeer * nxgep 38476495Sspeer * 38486495Sspeer * Notes: 38496495Sspeer * 38506495Sspeer * NPI/NXGE function calls: 38516495Sspeer * nxge_init_fzc_rx_common(); 38526495Sspeer * nxge_init_fzc_rxdma_port(); 38536495Sspeer * 38546495Sspeer * Registers accessed: 38556495Sspeer * 38566495Sspeer * Context: 38576495Sspeer * Service domain 38586495Sspeer */ 38593859Sml29623 static nxge_status_t 38603859Sml29623 nxge_rxdma_hw_start_common(p_nxge_t nxgep) 38613859Sml29623 { 38623859Sml29623 nxge_status_t status = NXGE_OK; 38633859Sml29623 38643859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_hw_start_common")); 38653859Sml29623 38663859Sml29623 /* 38673859Sml29623 * Load the sharable parameters by writing to the 38683859Sml29623 * function zero control registers. These FZC registers 38693859Sml29623 * should be initialized only once for the entire chip. 38703859Sml29623 */ 38713859Sml29623 (void) nxge_init_fzc_rx_common(nxgep); 38723859Sml29623 38733859Sml29623 /* 38743859Sml29623 * Initialize the RXDMA port specific FZC control configurations. 38753859Sml29623 * These FZC registers are pertaining to each port. 38763859Sml29623 */ 38773859Sml29623 (void) nxge_init_fzc_rxdma_port(nxgep); 38783859Sml29623 38793859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_hw_start_common")); 38803859Sml29623 38813859Sml29623 return (status); 38823859Sml29623 } 38833859Sml29623 38843859Sml29623 static nxge_status_t 38856495Sspeer nxge_rxdma_hw_start(p_nxge_t nxgep, int channel) 38863859Sml29623 { 38873859Sml29623 int i, ndmas; 38883859Sml29623 p_rx_rbr_rings_t rx_rbr_rings; 38893859Sml29623 p_rx_rbr_ring_t *rbr_rings; 38903859Sml29623 p_rx_rcr_rings_t rx_rcr_rings; 38913859Sml29623 p_rx_rcr_ring_t *rcr_rings; 38923859Sml29623 p_rx_mbox_areas_t rx_mbox_areas_p; 38933859Sml29623 p_rx_mbox_t *rx_mbox_p; 38943859Sml29623 nxge_status_t status = NXGE_OK; 38953859Sml29623 38963859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_hw_start")); 38973859Sml29623 38983859Sml29623 rx_rbr_rings = nxgep->rx_rbr_rings; 38993859Sml29623 rx_rcr_rings = nxgep->rx_rcr_rings; 39003859Sml29623 if (rx_rbr_rings == NULL || rx_rcr_rings == NULL) { 39013859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 39023859Sml29623 "<== nxge_rxdma_hw_start: NULL ring pointers")); 39033859Sml29623 return (NXGE_ERROR); 39043859Sml29623 } 39053859Sml29623 ndmas = rx_rbr_rings->ndmas; 39063859Sml29623 if (ndmas == 0) { 39073859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 39083859Sml29623 "<== nxge_rxdma_hw_start: no dma channel allocated")); 39093859Sml29623 return (NXGE_ERROR); 39103859Sml29623 } 39113859Sml29623 39123859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 39133859Sml29623 "==> nxge_rxdma_hw_start (ndmas %d)", ndmas)); 39143859Sml29623 39153859Sml29623 rbr_rings = rx_rbr_rings->rbr_rings; 39163859Sml29623 rcr_rings = rx_rcr_rings->rcr_rings; 39173859Sml29623 rx_mbox_areas_p = nxgep->rx_mbox_areas_p; 39183859Sml29623 if (rx_mbox_areas_p) { 39193859Sml29623 rx_mbox_p = rx_mbox_areas_p->rxmbox_areas; 39203859Sml29623 } 39213859Sml29623 39226495Sspeer i = channel; 39236495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 39246495Sspeer "==> nxge_rxdma_hw_start (ndmas %d) channel %d", 39256495Sspeer ndmas, channel)); 39266495Sspeer status = nxge_rxdma_start_channel(nxgep, channel, 39276495Sspeer (p_rx_rbr_ring_t)rbr_rings[i], 39286495Sspeer (p_rx_rcr_ring_t)rcr_rings[i], 39296495Sspeer (p_rx_mbox_t)rx_mbox_p[i]); 39306495Sspeer if (status != NXGE_OK) { 39316495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 39326495Sspeer "==> nxge_rxdma_hw_start: disable " 39336495Sspeer "(status 0x%x channel %d)", status, channel)); 39346495Sspeer return (status); 39353859Sml29623 } 39363859Sml29623 39373859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_hw_start: " 39383859Sml29623 "rx_rbr_rings 0x%016llx rings 0x%016llx", 39393859Sml29623 rx_rbr_rings, rx_rcr_rings)); 39403859Sml29623 39413859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 39423859Sml29623 "==> nxge_rxdma_hw_start: (status 0x%x)", status)); 39433859Sml29623 39443859Sml29623 return (status); 39453859Sml29623 } 39463859Sml29623 39473859Sml29623 static void 39486495Sspeer nxge_rxdma_hw_stop(p_nxge_t nxgep, int channel) 39493859Sml29623 { 39503859Sml29623 p_rx_rbr_rings_t rx_rbr_rings; 39513859Sml29623 p_rx_rcr_rings_t rx_rcr_rings; 39523859Sml29623 39533859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_hw_stop")); 39543859Sml29623 39553859Sml29623 rx_rbr_rings = nxgep->rx_rbr_rings; 39563859Sml29623 rx_rcr_rings = nxgep->rx_rcr_rings; 39573859Sml29623 if (rx_rbr_rings == NULL || rx_rcr_rings == NULL) { 39583859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 39593859Sml29623 "<== nxge_rxdma_hw_stop: NULL ring pointers")); 39603859Sml29623 return; 39613859Sml29623 } 39623859Sml29623 39633859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 39646495Sspeer "==> nxge_rxdma_hw_stop(channel %d)", 39656495Sspeer channel)); 39666495Sspeer (void) nxge_rxdma_stop_channel(nxgep, channel); 39673859Sml29623 39683859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_hw_stop: " 39693859Sml29623 "rx_rbr_rings 0x%016llx rings 0x%016llx", 39703859Sml29623 rx_rbr_rings, rx_rcr_rings)); 39713859Sml29623 39723859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "<== nxge_rxdma_hw_stop")); 39733859Sml29623 } 39743859Sml29623 39753859Sml29623 39763859Sml29623 static nxge_status_t 39773859Sml29623 nxge_rxdma_start_channel(p_nxge_t nxgep, uint16_t channel, 39783859Sml29623 p_rx_rbr_ring_t rbr_p, p_rx_rcr_ring_t rcr_p, p_rx_mbox_t mbox_p) 39793859Sml29623 39803859Sml29623 { 39813859Sml29623 npi_handle_t handle; 39823859Sml29623 npi_status_t rs = NPI_SUCCESS; 39833859Sml29623 rx_dma_ctl_stat_t cs; 39843859Sml29623 rx_dma_ent_msk_t ent_mask; 39853859Sml29623 nxge_status_t status = NXGE_OK; 39863859Sml29623 39873859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_start_channel")); 39883859Sml29623 39893859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 39903859Sml29623 39913859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "nxge_rxdma_start_channel: " 39923859Sml29623 "npi handle addr $%p acc $%p", 39933859Sml29623 nxgep->npi_handle.regp, nxgep->npi_handle.regh)); 39943859Sml29623 39956495Sspeer /* Reset RXDMA channel, but not if you're a guest. */ 39966495Sspeer if (!isLDOMguest(nxgep)) { 39976495Sspeer rs = npi_rxdma_cfg_rdc_reset(handle, channel); 39986495Sspeer if (rs != NPI_SUCCESS) { 39996495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 40006495Sspeer "==> nxge_init_fzc_rdc: " 40016495Sspeer "npi_rxdma_cfg_rdc_reset(%d) returned 0x%08x", 40026495Sspeer channel, rs)); 40036495Sspeer return (NXGE_ERROR | rs); 40046495Sspeer } 40056495Sspeer 40066495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 40076495Sspeer "==> nxge_rxdma_start_channel: reset done: channel %d", 40086495Sspeer channel)); 40093859Sml29623 } 40103859Sml29623 40116495Sspeer #if defined(sun4v) && defined(NIU_LP_WORKAROUND) 40126495Sspeer if (isLDOMguest(nxgep)) 40136495Sspeer (void) nxge_rdc_lp_conf(nxgep, channel); 40146495Sspeer #endif 40153859Sml29623 40163859Sml29623 /* 40173859Sml29623 * Initialize the RXDMA channel specific FZC control 40183859Sml29623 * configurations. These FZC registers are pertaining 40193859Sml29623 * to each RX channel (logical pages). 40203859Sml29623 */ 40216495Sspeer if (!isLDOMguest(nxgep)) { 40226495Sspeer status = nxge_init_fzc_rxdma_channel(nxgep, channel); 40236495Sspeer if (status != NXGE_OK) { 40246495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 40256495Sspeer "==> nxge_rxdma_start_channel: " 40266495Sspeer "init fzc rxdma failed (0x%08x channel %d)", 40276495Sspeer status, channel)); 40286495Sspeer return (status); 40296495Sspeer } 40306495Sspeer 40316495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 40326495Sspeer "==> nxge_rxdma_start_channel: fzc done")); 40333859Sml29623 } 40343859Sml29623 40353859Sml29623 /* Set up the interrupt event masks. */ 40363859Sml29623 ent_mask.value = 0; 40373859Sml29623 ent_mask.value |= RX_DMA_ENT_MSK_RBREMPTY_MASK; 40383859Sml29623 rs = npi_rxdma_event_mask(handle, OP_SET, channel, 40396495Sspeer &ent_mask); 40403859Sml29623 if (rs != NPI_SUCCESS) { 40413859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 40423859Sml29623 "==> nxge_rxdma_start_channel: " 40436495Sspeer "init rxdma event masks failed " 40446495Sspeer "(0x%08x channel %d)", 40453859Sml29623 status, channel)); 40463859Sml29623 return (NXGE_ERROR | rs); 40473859Sml29623 } 40483859Sml29623 40496495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 40506495Sspeer "==> nxge_rxdma_start_channel: " 40513859Sml29623 "event done: channel %d (mask 0x%016llx)", 40523859Sml29623 channel, ent_mask.value)); 40533859Sml29623 40543859Sml29623 /* Initialize the receive DMA control and status register */ 40553859Sml29623 cs.value = 0; 40563859Sml29623 cs.bits.hdw.mex = 1; 40573859Sml29623 cs.bits.hdw.rcrthres = 1; 40583859Sml29623 cs.bits.hdw.rcrto = 1; 40593859Sml29623 cs.bits.hdw.rbr_empty = 1; 40603859Sml29623 status = nxge_init_rxdma_channel_cntl_stat(nxgep, channel, &cs); 40613859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_start_channel: " 40623859Sml29623 "channel %d rx_dma_cntl_stat 0x%0016llx", channel, cs.value)); 40633859Sml29623 if (status != NXGE_OK) { 40643859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 40653859Sml29623 "==> nxge_rxdma_start_channel: " 40663859Sml29623 "init rxdma control register failed (0x%08x channel %d", 40673859Sml29623 status, channel)); 40683859Sml29623 return (status); 40693859Sml29623 } 40703859Sml29623 40713859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_start_channel: " 40723859Sml29623 "control done - channel %d cs 0x%016llx", channel, cs.value)); 40733859Sml29623 40743859Sml29623 /* 40753859Sml29623 * Load RXDMA descriptors, buffers, mailbox, 40763859Sml29623 * initialise the receive DMA channels and 40773859Sml29623 * enable each DMA channel. 40783859Sml29623 */ 40793859Sml29623 status = nxge_enable_rxdma_channel(nxgep, 40806495Sspeer channel, rbr_p, rcr_p, mbox_p); 40813859Sml29623 40823859Sml29623 if (status != NXGE_OK) { 40833859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 40846495Sspeer " nxge_rxdma_start_channel: " 40856495Sspeer " enable rxdma failed (0x%08x channel %d)", 40866495Sspeer status, channel)); 40876495Sspeer return (status); 40886495Sspeer } 40896495Sspeer 40906495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 40916495Sspeer "==> nxge_rxdma_start_channel: enabled channel %d")); 40926495Sspeer 40936495Sspeer if (isLDOMguest(nxgep)) { 40946495Sspeer /* Add interrupt handler for this channel. */ 40956495Sspeer if (nxge_hio_intr_add(nxgep, VP_BOUND_RX, channel) 40966495Sspeer != NXGE_OK) { 40976495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 40983859Sml29623 " nxge_rxdma_start_channel: " 40996495Sspeer " nxge_hio_intr_add failed (0x%08x channel %d)", 41006495Sspeer status, channel)); 41016495Sspeer } 41023859Sml29623 } 41033859Sml29623 41043859Sml29623 ent_mask.value = 0; 41053859Sml29623 ent_mask.value |= (RX_DMA_ENT_MSK_WRED_DROP_MASK | 41063859Sml29623 RX_DMA_ENT_MSK_PTDROP_PKT_MASK); 41073859Sml29623 rs = npi_rxdma_event_mask(handle, OP_SET, channel, 41083859Sml29623 &ent_mask); 41093859Sml29623 if (rs != NPI_SUCCESS) { 41103859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 41113859Sml29623 "==> nxge_rxdma_start_channel: " 41123859Sml29623 "init rxdma event masks failed (0x%08x channel %d)", 41133859Sml29623 status, channel)); 41143859Sml29623 return (NXGE_ERROR | rs); 41153859Sml29623 } 41163859Sml29623 41173859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_start_channel: " 41183859Sml29623 "control done - channel %d cs 0x%016llx", channel, cs.value)); 41193859Sml29623 41203859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "<== nxge_rxdma_start_channel")); 41213859Sml29623 41223859Sml29623 return (NXGE_OK); 41233859Sml29623 } 41243859Sml29623 41253859Sml29623 static nxge_status_t 41263859Sml29623 nxge_rxdma_stop_channel(p_nxge_t nxgep, uint16_t channel) 41273859Sml29623 { 41283859Sml29623 npi_handle_t handle; 41293859Sml29623 npi_status_t rs = NPI_SUCCESS; 41303859Sml29623 rx_dma_ctl_stat_t cs; 41313859Sml29623 rx_dma_ent_msk_t ent_mask; 41323859Sml29623 nxge_status_t status = NXGE_OK; 41333859Sml29623 41343859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rxdma_stop_channel")); 41353859Sml29623 41363859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 41373859Sml29623 41383859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "nxge_rxdma_stop_channel: " 41393859Sml29623 "npi handle addr $%p acc $%p", 41403859Sml29623 nxgep->npi_handle.regp, nxgep->npi_handle.regh)); 41413859Sml29623 41423859Sml29623 /* Reset RXDMA channel */ 41433859Sml29623 rs = npi_rxdma_cfg_rdc_reset(handle, channel); 41443859Sml29623 if (rs != NPI_SUCCESS) { 41453859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 41463859Sml29623 " nxge_rxdma_stop_channel: " 41473859Sml29623 " reset rxdma failed (0x%08x channel %d)", 41483859Sml29623 rs, channel)); 41493859Sml29623 return (NXGE_ERROR | rs); 41503859Sml29623 } 41513859Sml29623 41523859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 41533859Sml29623 "==> nxge_rxdma_stop_channel: reset done")); 41543859Sml29623 41553859Sml29623 /* Set up the interrupt event masks. */ 41563859Sml29623 ent_mask.value = RX_DMA_ENT_MSK_ALL; 41573859Sml29623 rs = npi_rxdma_event_mask(handle, OP_SET, channel, 41583859Sml29623 &ent_mask); 41593859Sml29623 if (rs != NPI_SUCCESS) { 41603859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 41613859Sml29623 "==> nxge_rxdma_stop_channel: " 41623859Sml29623 "set rxdma event masks failed (0x%08x channel %d)", 41633859Sml29623 rs, channel)); 41643859Sml29623 return (NXGE_ERROR | rs); 41653859Sml29623 } 41663859Sml29623 41673859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 41683859Sml29623 "==> nxge_rxdma_stop_channel: event done")); 41693859Sml29623 41703859Sml29623 /* Initialize the receive DMA control and status register */ 41713859Sml29623 cs.value = 0; 41723859Sml29623 status = nxge_init_rxdma_channel_cntl_stat(nxgep, channel, 41733859Sml29623 &cs); 41743859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rxdma_stop_channel: control " 41753859Sml29623 " to default (all 0s) 0x%08x", cs.value)); 41763859Sml29623 if (status != NXGE_OK) { 41773859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 41783859Sml29623 " nxge_rxdma_stop_channel: init rxdma" 41793859Sml29623 " control register failed (0x%08x channel %d", 41803859Sml29623 status, channel)); 41813859Sml29623 return (status); 41823859Sml29623 } 41833859Sml29623 41843859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 41853859Sml29623 "==> nxge_rxdma_stop_channel: control done")); 41863859Sml29623 41873859Sml29623 /* disable dma channel */ 41883859Sml29623 status = nxge_disable_rxdma_channel(nxgep, channel); 41893859Sml29623 41903859Sml29623 if (status != NXGE_OK) { 41913859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 41923859Sml29623 " nxge_rxdma_stop_channel: " 41933859Sml29623 " init enable rxdma failed (0x%08x channel %d)", 41943859Sml29623 status, channel)); 41953859Sml29623 return (status); 41963859Sml29623 } 41973859Sml29623 41983859Sml29623 NXGE_DEBUG_MSG((nxgep, 41993859Sml29623 RX_CTL, "==> nxge_rxdma_stop_channel: disable done")); 42003859Sml29623 42013859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_rxdma_stop_channel")); 42023859Sml29623 42033859Sml29623 return (NXGE_OK); 42043859Sml29623 } 42053859Sml29623 42063859Sml29623 nxge_status_t 42073859Sml29623 nxge_rxdma_handle_sys_errors(p_nxge_t nxgep) 42083859Sml29623 { 42093859Sml29623 npi_handle_t handle; 42103859Sml29623 p_nxge_rdc_sys_stats_t statsp; 42113859Sml29623 rx_ctl_dat_fifo_stat_t stat; 42123859Sml29623 uint32_t zcp_err_status; 42133859Sml29623 uint32_t ipp_err_status; 42143859Sml29623 nxge_status_t status = NXGE_OK; 42153859Sml29623 npi_status_t rs = NPI_SUCCESS; 42163859Sml29623 boolean_t my_err = B_FALSE; 42173859Sml29623 42183859Sml29623 handle = nxgep->npi_handle; 42193859Sml29623 statsp = (p_nxge_rdc_sys_stats_t)&nxgep->statsp->rdc_sys_stats; 42203859Sml29623 42213859Sml29623 rs = npi_rxdma_rxctl_fifo_error_intr_get(handle, &stat); 42223859Sml29623 42233859Sml29623 if (rs != NPI_SUCCESS) 42243859Sml29623 return (NXGE_ERROR | rs); 42253859Sml29623 42263859Sml29623 if (stat.bits.ldw.id_mismatch) { 42273859Sml29623 statsp->id_mismatch++; 42283859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, nxgep->mac.portnum, NULL, 42293859Sml29623 NXGE_FM_EREPORT_RDMC_ID_MISMATCH); 42303859Sml29623 /* Global fatal error encountered */ 42313859Sml29623 } 42323859Sml29623 42333859Sml29623 if ((stat.bits.ldw.zcp_eop_err) || (stat.bits.ldw.ipp_eop_err)) { 42343859Sml29623 switch (nxgep->mac.portnum) { 42353859Sml29623 case 0: 42363859Sml29623 if ((stat.bits.ldw.zcp_eop_err & FIFO_EOP_PORT0) || 42373859Sml29623 (stat.bits.ldw.ipp_eop_err & FIFO_EOP_PORT0)) { 42383859Sml29623 my_err = B_TRUE; 42393859Sml29623 zcp_err_status = stat.bits.ldw.zcp_eop_err; 42403859Sml29623 ipp_err_status = stat.bits.ldw.ipp_eop_err; 42413859Sml29623 } 42423859Sml29623 break; 42433859Sml29623 case 1: 42443859Sml29623 if ((stat.bits.ldw.zcp_eop_err & FIFO_EOP_PORT1) || 42453859Sml29623 (stat.bits.ldw.ipp_eop_err & FIFO_EOP_PORT1)) { 42463859Sml29623 my_err = B_TRUE; 42473859Sml29623 zcp_err_status = stat.bits.ldw.zcp_eop_err; 42483859Sml29623 ipp_err_status = stat.bits.ldw.ipp_eop_err; 42493859Sml29623 } 42503859Sml29623 break; 42513859Sml29623 case 2: 42523859Sml29623 if ((stat.bits.ldw.zcp_eop_err & FIFO_EOP_PORT2) || 42533859Sml29623 (stat.bits.ldw.ipp_eop_err & FIFO_EOP_PORT2)) { 42543859Sml29623 my_err = B_TRUE; 42553859Sml29623 zcp_err_status = stat.bits.ldw.zcp_eop_err; 42563859Sml29623 ipp_err_status = stat.bits.ldw.ipp_eop_err; 42573859Sml29623 } 42583859Sml29623 break; 42593859Sml29623 case 3: 42603859Sml29623 if ((stat.bits.ldw.zcp_eop_err & FIFO_EOP_PORT3) || 42613859Sml29623 (stat.bits.ldw.ipp_eop_err & FIFO_EOP_PORT3)) { 42623859Sml29623 my_err = B_TRUE; 42633859Sml29623 zcp_err_status = stat.bits.ldw.zcp_eop_err; 42643859Sml29623 ipp_err_status = stat.bits.ldw.ipp_eop_err; 42653859Sml29623 } 42663859Sml29623 break; 42673859Sml29623 default: 42683859Sml29623 return (NXGE_ERROR); 42693859Sml29623 } 42703859Sml29623 } 42713859Sml29623 42723859Sml29623 if (my_err) { 42733859Sml29623 status = nxge_rxdma_handle_port_errors(nxgep, ipp_err_status, 42743859Sml29623 zcp_err_status); 42753859Sml29623 if (status != NXGE_OK) 42763859Sml29623 return (status); 42773859Sml29623 } 42783859Sml29623 42793859Sml29623 return (NXGE_OK); 42803859Sml29623 } 42813859Sml29623 42823859Sml29623 static nxge_status_t 42833859Sml29623 nxge_rxdma_handle_port_errors(p_nxge_t nxgep, uint32_t ipp_status, 42843859Sml29623 uint32_t zcp_status) 42853859Sml29623 { 42863859Sml29623 boolean_t rxport_fatal = B_FALSE; 42873859Sml29623 p_nxge_rdc_sys_stats_t statsp; 42883859Sml29623 nxge_status_t status = NXGE_OK; 42893859Sml29623 uint8_t portn; 42903859Sml29623 42913859Sml29623 portn = nxgep->mac.portnum; 42923859Sml29623 statsp = (p_nxge_rdc_sys_stats_t)&nxgep->statsp->rdc_sys_stats; 42933859Sml29623 42943859Sml29623 if (ipp_status & (0x1 << portn)) { 42953859Sml29623 statsp->ipp_eop_err++; 42963859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, portn, NULL, 42973859Sml29623 NXGE_FM_EREPORT_RDMC_IPP_EOP_ERR); 42983859Sml29623 rxport_fatal = B_TRUE; 42993859Sml29623 } 43003859Sml29623 43013859Sml29623 if (zcp_status & (0x1 << portn)) { 43023859Sml29623 statsp->zcp_eop_err++; 43033859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, portn, NULL, 43043859Sml29623 NXGE_FM_EREPORT_RDMC_ZCP_EOP_ERR); 43053859Sml29623 rxport_fatal = B_TRUE; 43063859Sml29623 } 43073859Sml29623 43083859Sml29623 if (rxport_fatal) { 43093859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 43103859Sml29623 " nxge_rxdma_handle_port_error: " 43113859Sml29623 " fatal error on Port #%d\n", 43123859Sml29623 portn)); 43133859Sml29623 status = nxge_rx_port_fatal_err_recover(nxgep); 43143859Sml29623 if (status == NXGE_OK) { 43153859Sml29623 FM_SERVICE_RESTORED(nxgep); 43163859Sml29623 } 43173859Sml29623 } 43183859Sml29623 43193859Sml29623 return (status); 43203859Sml29623 } 43213859Sml29623 43223859Sml29623 static nxge_status_t 43233859Sml29623 nxge_rxdma_fatal_err_recover(p_nxge_t nxgep, uint16_t channel) 43243859Sml29623 { 43253859Sml29623 npi_handle_t handle; 43263859Sml29623 npi_status_t rs = NPI_SUCCESS; 43273859Sml29623 nxge_status_t status = NXGE_OK; 43283859Sml29623 p_rx_rbr_ring_t rbrp; 43293859Sml29623 p_rx_rcr_ring_t rcrp; 43303859Sml29623 p_rx_mbox_t mboxp; 43313859Sml29623 rx_dma_ent_msk_t ent_mask; 43323859Sml29623 p_nxge_dma_common_t dmap; 43333859Sml29623 int ring_idx; 43343859Sml29623 uint32_t ref_cnt; 43353859Sml29623 p_rx_msg_t rx_msg_p; 43363859Sml29623 int i; 43373859Sml29623 uint32_t nxge_port_rcr_size; 43383859Sml29623 43393859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_rxdma_fatal_err_recover")); 43403859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 43413859Sml29623 "Recovering from RxDMAChannel#%d error...", channel)); 43423859Sml29623 43433859Sml29623 /* 43443859Sml29623 * Stop the dma channel waits for the stop done. 43453859Sml29623 * If the stop done bit is not set, then create 43463859Sml29623 * an error. 43473859Sml29623 */ 43483859Sml29623 43493859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 43503859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "Rx DMA stop...")); 43513859Sml29623 43523859Sml29623 ring_idx = nxge_rxdma_get_ring_index(nxgep, channel); 43533859Sml29623 rbrp = (p_rx_rbr_ring_t)nxgep->rx_rbr_rings->rbr_rings[ring_idx]; 43543859Sml29623 rcrp = (p_rx_rcr_ring_t)nxgep->rx_rcr_rings->rcr_rings[ring_idx]; 43553859Sml29623 43563859Sml29623 MUTEX_ENTER(&rcrp->lock); 43573859Sml29623 MUTEX_ENTER(&rbrp->lock); 43583859Sml29623 MUTEX_ENTER(&rbrp->post_lock); 43593859Sml29623 43603859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "Disable RxDMA channel...")); 43613859Sml29623 43623859Sml29623 rs = npi_rxdma_cfg_rdc_disable(handle, channel); 43633859Sml29623 if (rs != NPI_SUCCESS) { 43643859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 43653859Sml29623 "nxge_disable_rxdma_channel:failed")); 43663859Sml29623 goto fail; 43673859Sml29623 } 43683859Sml29623 43693859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "Disable RxDMA interrupt...")); 43703859Sml29623 43713859Sml29623 /* Disable interrupt */ 43723859Sml29623 ent_mask.value = RX_DMA_ENT_MSK_ALL; 43733859Sml29623 rs = npi_rxdma_event_mask(handle, OP_SET, channel, &ent_mask); 43743859Sml29623 if (rs != NPI_SUCCESS) { 43753859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 43763859Sml29623 "nxge_rxdma_stop_channel: " 43773859Sml29623 "set rxdma event masks failed (channel %d)", 43783859Sml29623 channel)); 43793859Sml29623 } 43803859Sml29623 43813859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "RxDMA channel reset...")); 43823859Sml29623 43833859Sml29623 /* Reset RXDMA channel */ 43843859Sml29623 rs = npi_rxdma_cfg_rdc_reset(handle, channel); 43853859Sml29623 if (rs != NPI_SUCCESS) { 43863859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 43873859Sml29623 "nxge_rxdma_fatal_err_recover: " 43883859Sml29623 " reset rxdma failed (channel %d)", channel)); 43893859Sml29623 goto fail; 43903859Sml29623 } 43913859Sml29623 43923859Sml29623 nxge_port_rcr_size = nxgep->nxge_port_rcr_size; 43933859Sml29623 43943859Sml29623 mboxp = 43953859Sml29623 (p_rx_mbox_t)nxgep->rx_mbox_areas_p->rxmbox_areas[ring_idx]; 43963859Sml29623 43973859Sml29623 rbrp->rbr_wr_index = (rbrp->rbb_max - 1); 43983859Sml29623 rbrp->rbr_rd_index = 0; 43993859Sml29623 44003859Sml29623 rcrp->comp_rd_index = 0; 44013859Sml29623 rcrp->comp_wt_index = 0; 44023859Sml29623 rcrp->rcr_desc_rd_head_p = rcrp->rcr_desc_first_p = 44033859Sml29623 (p_rcr_entry_t)DMA_COMMON_VPTR(rcrp->rcr_desc); 44043859Sml29623 rcrp->rcr_desc_rd_head_pp = rcrp->rcr_desc_first_pp = 44055125Sjoycey #if defined(__i386) 44065125Sjoycey (p_rcr_entry_t)(uint32_t)DMA_COMMON_IOADDR(rcrp->rcr_desc); 44075125Sjoycey #else 44083859Sml29623 (p_rcr_entry_t)DMA_COMMON_IOADDR(rcrp->rcr_desc); 44095125Sjoycey #endif 44103859Sml29623 44113859Sml29623 rcrp->rcr_desc_last_p = rcrp->rcr_desc_rd_head_p + 44123859Sml29623 (nxge_port_rcr_size - 1); 44133859Sml29623 rcrp->rcr_desc_last_pp = rcrp->rcr_desc_rd_head_pp + 44143859Sml29623 (nxge_port_rcr_size - 1); 44153859Sml29623 44163859Sml29623 dmap = (p_nxge_dma_common_t)&rcrp->rcr_desc; 44173859Sml29623 bzero((caddr_t)dmap->kaddrp, dmap->alength); 44183859Sml29623 44193859Sml29623 cmn_err(CE_NOTE, "!rbr entries = %d\n", rbrp->rbr_max_size); 44203859Sml29623 44213859Sml29623 for (i = 0; i < rbrp->rbr_max_size; i++) { 44223859Sml29623 rx_msg_p = rbrp->rx_msg_ring[i]; 44233859Sml29623 ref_cnt = rx_msg_p->ref_cnt; 44243859Sml29623 if (ref_cnt != 1) { 44253859Sml29623 if (rx_msg_p->cur_usage_cnt != 44263859Sml29623 rx_msg_p->max_usage_cnt) { 44273859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 44283859Sml29623 "buf[%d]: cur_usage_cnt = %d " 44293859Sml29623 "max_usage_cnt = %d\n", i, 44303859Sml29623 rx_msg_p->cur_usage_cnt, 44313859Sml29623 rx_msg_p->max_usage_cnt)); 44323859Sml29623 } else { 44333859Sml29623 /* Buffer can be re-posted */ 44343859Sml29623 rx_msg_p->free = B_TRUE; 44353859Sml29623 rx_msg_p->cur_usage_cnt = 0; 44363859Sml29623 rx_msg_p->max_usage_cnt = 0xbaddcafe; 44373859Sml29623 rx_msg_p->pkt_buf_size = 0; 44383859Sml29623 } 44393859Sml29623 } 44403859Sml29623 } 44413859Sml29623 44423859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "RxDMA channel re-start...")); 44433859Sml29623 44443859Sml29623 status = nxge_rxdma_start_channel(nxgep, channel, rbrp, rcrp, mboxp); 44453859Sml29623 if (status != NXGE_OK) { 44463859Sml29623 goto fail; 44473859Sml29623 } 44483859Sml29623 44493859Sml29623 MUTEX_EXIT(&rbrp->post_lock); 44503859Sml29623 MUTEX_EXIT(&rbrp->lock); 44513859Sml29623 MUTEX_EXIT(&rcrp->lock); 44523859Sml29623 44533859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 44543859Sml29623 "Recovery Successful, RxDMAChannel#%d Restored", 44553859Sml29623 channel)); 44563859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rxdma_fatal_err_recover")); 44573859Sml29623 44583859Sml29623 return (NXGE_OK); 44593859Sml29623 fail: 44603859Sml29623 MUTEX_EXIT(&rbrp->post_lock); 44613859Sml29623 MUTEX_EXIT(&rbrp->lock); 44623859Sml29623 MUTEX_EXIT(&rcrp->lock); 44633859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "Recovery failed")); 44643859Sml29623 44653859Sml29623 return (NXGE_ERROR | rs); 44663859Sml29623 } 44673859Sml29623 44683859Sml29623 nxge_status_t 44693859Sml29623 nxge_rx_port_fatal_err_recover(p_nxge_t nxgep) 44703859Sml29623 { 44716495Sspeer nxge_grp_set_t *set = &nxgep->rx_set; 44726495Sspeer nxge_status_t status = NXGE_OK; 44736495Sspeer int rdc; 44743859Sml29623 44753859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_rx_port_fatal_err_recover")); 44763859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 44773859Sml29623 "Recovering from RxPort error...")); 44786495Sspeer NXGE_DEBUG_MSG((nxgep, RX_CTL, "Disabling RxMAC...\n")); 44796495Sspeer 44803859Sml29623 if (nxge_rx_mac_disable(nxgep) != NXGE_OK) 44813859Sml29623 goto fail; 44823859Sml29623 44833859Sml29623 NXGE_DELAY(1000); 44843859Sml29623 44856495Sspeer NXGE_DEBUG_MSG((nxgep, RX_CTL, "Stopping all RxDMA channels...")); 44866495Sspeer 44876495Sspeer for (rdc = 0; rdc < NXGE_MAX_RDCS; rdc++) { 44886495Sspeer if ((1 << rdc) & set->owned.map) { 44896495Sspeer if (nxge_rxdma_fatal_err_recover(nxgep, rdc) 44906495Sspeer != NXGE_OK) { 44916495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 44926495Sspeer "Could not recover channel %d", rdc)); 44936495Sspeer } 44943859Sml29623 } 44953859Sml29623 } 44963859Sml29623 44976495Sspeer NXGE_DEBUG_MSG((nxgep, RX_CTL, "Resetting IPP...")); 44983859Sml29623 44993859Sml29623 /* Reset IPP */ 45003859Sml29623 if (nxge_ipp_reset(nxgep) != NXGE_OK) { 45013859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 45023859Sml29623 "nxge_rx_port_fatal_err_recover: " 45033859Sml29623 "Failed to reset IPP")); 45043859Sml29623 goto fail; 45053859Sml29623 } 45063859Sml29623 45073859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "Reset RxMAC...")); 45083859Sml29623 45093859Sml29623 /* Reset RxMAC */ 45103859Sml29623 if (nxge_rx_mac_reset(nxgep) != NXGE_OK) { 45113859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 45123859Sml29623 "nxge_rx_port_fatal_err_recover: " 45133859Sml29623 "Failed to reset RxMAC")); 45143859Sml29623 goto fail; 45153859Sml29623 } 45163859Sml29623 45173859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "Re-initialize IPP...")); 45183859Sml29623 45193859Sml29623 /* Re-Initialize IPP */ 45203859Sml29623 if (nxge_ipp_init(nxgep) != NXGE_OK) { 45213859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 45223859Sml29623 "nxge_rx_port_fatal_err_recover: " 45233859Sml29623 "Failed to init IPP")); 45243859Sml29623 goto fail; 45253859Sml29623 } 45263859Sml29623 45273859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "Re-initialize RxMAC...")); 45283859Sml29623 45293859Sml29623 /* Re-Initialize RxMAC */ 45303859Sml29623 if ((status = nxge_rx_mac_init(nxgep)) != NXGE_OK) { 45313859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 45323859Sml29623 "nxge_rx_port_fatal_err_recover: " 45333859Sml29623 "Failed to reset RxMAC")); 45343859Sml29623 goto fail; 45353859Sml29623 } 45363859Sml29623 45373859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "Re-enable RxMAC...")); 45383859Sml29623 45393859Sml29623 /* Re-enable RxMAC */ 45403859Sml29623 if ((status = nxge_rx_mac_enable(nxgep)) != NXGE_OK) { 45413859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 45423859Sml29623 "nxge_rx_port_fatal_err_recover: " 45433859Sml29623 "Failed to enable RxMAC")); 45443859Sml29623 goto fail; 45453859Sml29623 } 45463859Sml29623 45473859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 45483859Sml29623 "Recovery Successful, RxPort Restored")); 45493859Sml29623 45503859Sml29623 return (NXGE_OK); 45513859Sml29623 fail: 45523859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "Recovery failed")); 45533859Sml29623 return (status); 45543859Sml29623 } 45553859Sml29623 45563859Sml29623 void 45573859Sml29623 nxge_rxdma_inject_err(p_nxge_t nxgep, uint32_t err_id, uint8_t chan) 45583859Sml29623 { 45593859Sml29623 rx_dma_ctl_stat_t cs; 45603859Sml29623 rx_ctl_dat_fifo_stat_t cdfs; 45613859Sml29623 45623859Sml29623 switch (err_id) { 45633859Sml29623 case NXGE_FM_EREPORT_RDMC_RCR_ACK_ERR: 45643859Sml29623 case NXGE_FM_EREPORT_RDMC_DC_FIFO_ERR: 45653859Sml29623 case NXGE_FM_EREPORT_RDMC_RCR_SHA_PAR: 45663859Sml29623 case NXGE_FM_EREPORT_RDMC_RBR_PRE_PAR: 45673859Sml29623 case NXGE_FM_EREPORT_RDMC_RBR_TMOUT: 45683859Sml29623 case NXGE_FM_EREPORT_RDMC_RSP_CNT_ERR: 45693859Sml29623 case NXGE_FM_EREPORT_RDMC_BYTE_EN_BUS: 45703859Sml29623 case NXGE_FM_EREPORT_RDMC_RSP_DAT_ERR: 45713859Sml29623 case NXGE_FM_EREPORT_RDMC_RCRINCON: 45723859Sml29623 case NXGE_FM_EREPORT_RDMC_RCRFULL: 45733859Sml29623 case NXGE_FM_EREPORT_RDMC_RBRFULL: 45743859Sml29623 case NXGE_FM_EREPORT_RDMC_RBRLOGPAGE: 45753859Sml29623 case NXGE_FM_EREPORT_RDMC_CFIGLOGPAGE: 45763859Sml29623 case NXGE_FM_EREPORT_RDMC_CONFIG_ERR: 45773859Sml29623 RXDMA_REG_READ64(nxgep->npi_handle, RX_DMA_CTL_STAT_DBG_REG, 45783859Sml29623 chan, &cs.value); 45793859Sml29623 if (err_id == NXGE_FM_EREPORT_RDMC_RCR_ACK_ERR) 45803859Sml29623 cs.bits.hdw.rcr_ack_err = 1; 45813859Sml29623 else if (err_id == NXGE_FM_EREPORT_RDMC_DC_FIFO_ERR) 45823859Sml29623 cs.bits.hdw.dc_fifo_err = 1; 45833859Sml29623 else if (err_id == NXGE_FM_EREPORT_RDMC_RCR_SHA_PAR) 45843859Sml29623 cs.bits.hdw.rcr_sha_par = 1; 45853859Sml29623 else if (err_id == NXGE_FM_EREPORT_RDMC_RBR_PRE_PAR) 45863859Sml29623 cs.bits.hdw.rbr_pre_par = 1; 45873859Sml29623 else if (err_id == NXGE_FM_EREPORT_RDMC_RBR_TMOUT) 45883859Sml29623 cs.bits.hdw.rbr_tmout = 1; 45893859Sml29623 else if (err_id == NXGE_FM_EREPORT_RDMC_RSP_CNT_ERR) 45903859Sml29623 cs.bits.hdw.rsp_cnt_err = 1; 45913859Sml29623 else if (err_id == NXGE_FM_EREPORT_RDMC_BYTE_EN_BUS) 45923859Sml29623 cs.bits.hdw.byte_en_bus = 1; 45933859Sml29623 else if (err_id == NXGE_FM_EREPORT_RDMC_RSP_DAT_ERR) 45943859Sml29623 cs.bits.hdw.rsp_dat_err = 1; 45953859Sml29623 else if (err_id == NXGE_FM_EREPORT_RDMC_CONFIG_ERR) 45963859Sml29623 cs.bits.hdw.config_err = 1; 45973859Sml29623 else if (err_id == NXGE_FM_EREPORT_RDMC_RCRINCON) 45983859Sml29623 cs.bits.hdw.rcrincon = 1; 45993859Sml29623 else if (err_id == NXGE_FM_EREPORT_RDMC_RCRFULL) 46003859Sml29623 cs.bits.hdw.rcrfull = 1; 46013859Sml29623 else if (err_id == NXGE_FM_EREPORT_RDMC_RBRFULL) 46023859Sml29623 cs.bits.hdw.rbrfull = 1; 46033859Sml29623 else if (err_id == NXGE_FM_EREPORT_RDMC_RBRLOGPAGE) 46043859Sml29623 cs.bits.hdw.rbrlogpage = 1; 46053859Sml29623 else if (err_id == NXGE_FM_EREPORT_RDMC_CFIGLOGPAGE) 46063859Sml29623 cs.bits.hdw.cfiglogpage = 1; 46075125Sjoycey #if defined(__i386) 46085125Sjoycey cmn_err(CE_NOTE, "!Write 0x%llx to RX_DMA_CTL_STAT_DBG_REG\n", 46095125Sjoycey cs.value); 46105125Sjoycey #else 46113859Sml29623 cmn_err(CE_NOTE, "!Write 0x%lx to RX_DMA_CTL_STAT_DBG_REG\n", 46123859Sml29623 cs.value); 46135125Sjoycey #endif 46143859Sml29623 RXDMA_REG_WRITE64(nxgep->npi_handle, RX_DMA_CTL_STAT_DBG_REG, 46153859Sml29623 chan, cs.value); 46163859Sml29623 break; 46173859Sml29623 case NXGE_FM_EREPORT_RDMC_ID_MISMATCH: 46183859Sml29623 case NXGE_FM_EREPORT_RDMC_ZCP_EOP_ERR: 46193859Sml29623 case NXGE_FM_EREPORT_RDMC_IPP_EOP_ERR: 46203859Sml29623 cdfs.value = 0; 46213859Sml29623 if (err_id == NXGE_FM_EREPORT_RDMC_ID_MISMATCH) 46223859Sml29623 cdfs.bits.ldw.id_mismatch = (1 << nxgep->mac.portnum); 46233859Sml29623 else if (err_id == NXGE_FM_EREPORT_RDMC_ZCP_EOP_ERR) 46243859Sml29623 cdfs.bits.ldw.zcp_eop_err = (1 << nxgep->mac.portnum); 46253859Sml29623 else if (err_id == NXGE_FM_EREPORT_RDMC_IPP_EOP_ERR) 46263859Sml29623 cdfs.bits.ldw.ipp_eop_err = (1 << nxgep->mac.portnum); 46275125Sjoycey #if defined(__i386) 46285125Sjoycey cmn_err(CE_NOTE, 46295125Sjoycey "!Write 0x%llx to RX_CTL_DAT_FIFO_STAT_DBG_REG\n", 46305125Sjoycey cdfs.value); 46315125Sjoycey #else 46323859Sml29623 cmn_err(CE_NOTE, 46333859Sml29623 "!Write 0x%lx to RX_CTL_DAT_FIFO_STAT_DBG_REG\n", 46343859Sml29623 cdfs.value); 46355125Sjoycey #endif 46366495Sspeer NXGE_REG_WR64(nxgep->npi_handle, 46376495Sspeer RX_CTL_DAT_FIFO_STAT_DBG_REG, cdfs.value); 46383859Sml29623 break; 46393859Sml29623 case NXGE_FM_EREPORT_RDMC_DCF_ERR: 46403859Sml29623 break; 46415165Syc148097 case NXGE_FM_EREPORT_RDMC_RCR_ERR: 46423859Sml29623 break; 46433859Sml29623 } 46443859Sml29623 } 46456495Sspeer 46466495Sspeer static void 46476495Sspeer nxge_rxdma_databuf_free(p_rx_rbr_ring_t rbr_p) 46486495Sspeer { 46496495Sspeer rxring_info_t *ring_info; 46506495Sspeer int index; 46516495Sspeer uint32_t chunk_size; 46526495Sspeer uint64_t kaddr; 46536495Sspeer uint_t num_blocks; 46546495Sspeer 46556495Sspeer NXGE_DEBUG_MSG((NULL, DMA_CTL, "==> nxge_rxdma_databuf_free")); 46566495Sspeer 46576495Sspeer if (rbr_p == NULL) { 46586495Sspeer NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL, 46596495Sspeer "==> nxge_rxdma_databuf_free: NULL rbr pointer")); 46606495Sspeer return; 46616495Sspeer } 46626495Sspeer 46636495Sspeer if (rbr_p->rbr_alloc_type == DDI_MEM_ALLOC) { 46646495Sspeer NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL, 46656495Sspeer "==> nxge_rxdma_databuf_free: DDI")); 46666495Sspeer return; 46676495Sspeer } 46686495Sspeer 46696495Sspeer ring_info = rbr_p->ring_info; 46706495Sspeer if (ring_info == NULL) { 46716495Sspeer NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL, 46726495Sspeer "==> nxge_rxdma_databuf_free: NULL ring info")); 46736495Sspeer return; 46746495Sspeer } 46756495Sspeer num_blocks = rbr_p->num_blocks; 46766495Sspeer for (index = 0; index < num_blocks; index++) { 46776495Sspeer kaddr = ring_info->buffer[index].kaddr; 46786495Sspeer chunk_size = ring_info->buffer[index].buf_size; 46796495Sspeer NXGE_DEBUG_MSG((NULL, DMA_CTL, 46806495Sspeer "==> nxge_rxdma_databuf_free: free chunk %d " 46816495Sspeer "kaddrp $%p chunk size %d", 46826495Sspeer index, kaddr, chunk_size)); 46836495Sspeer if (kaddr == NULL) continue; 46846495Sspeer nxge_free_buf(rbr_p->rbr_alloc_type, kaddr, chunk_size); 46856495Sspeer ring_info->buffer[index].kaddr = NULL; 46866495Sspeer } 46876495Sspeer 46886495Sspeer NXGE_DEBUG_MSG((NULL, DMA_CTL, "<== nxge_rxdma_databuf_free")); 46896495Sspeer } 46906495Sspeer 46916495Sspeer #if defined(sun4v) && defined(NIU_LP_WORKAROUND) 46926495Sspeer extern void contig_mem_free(void *, size_t); 46936495Sspeer #endif 46946495Sspeer 46956495Sspeer void 46966495Sspeer nxge_free_buf(buf_alloc_type_t alloc_type, uint64_t kaddr, uint32_t buf_size) 46976495Sspeer { 46986495Sspeer NXGE_DEBUG_MSG((NULL, DMA_CTL, "==> nxge_free_buf")); 46996495Sspeer 47006495Sspeer if (kaddr == NULL || !buf_size) { 47016495Sspeer NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL, 47026495Sspeer "==> nxge_free_buf: invalid kaddr $%p size to free %d", 47036495Sspeer kaddr, buf_size)); 47046495Sspeer return; 47056495Sspeer } 47066495Sspeer 47076495Sspeer switch (alloc_type) { 47086495Sspeer case KMEM_ALLOC: 47096495Sspeer NXGE_DEBUG_MSG((NULL, DMA_CTL, 47106495Sspeer "==> nxge_free_buf: freeing kmem $%p size %d", 47116495Sspeer kaddr, buf_size)); 47126495Sspeer #if defined(__i386) 47136495Sspeer KMEM_FREE((void *)(uint32_t)kaddr, buf_size); 47146495Sspeer #else 47156495Sspeer KMEM_FREE((void *)kaddr, buf_size); 47166495Sspeer #endif 47176495Sspeer break; 47186495Sspeer 47196495Sspeer #if defined(sun4v) && defined(NIU_LP_WORKAROUND) 47206495Sspeer case CONTIG_MEM_ALLOC: 47216495Sspeer NXGE_DEBUG_MSG((NULL, DMA_CTL, 47226495Sspeer "==> nxge_free_buf: freeing contig_mem kaddr $%p size %d", 47236495Sspeer kaddr, buf_size)); 47246495Sspeer contig_mem_free((void *)kaddr, buf_size); 47256495Sspeer break; 47266495Sspeer #endif 47276495Sspeer 47286495Sspeer default: 47296495Sspeer NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL, 47306495Sspeer "<== nxge_free_buf: unsupported alloc type %d", 47316495Sspeer alloc_type)); 47326495Sspeer return; 47336495Sspeer } 47346495Sspeer 47356495Sspeer NXGE_DEBUG_MSG((NULL, DMA_CTL, "<== nxge_free_buf")); 47366495Sspeer } 4737