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 */ 2110577SMichael.Speer@Sun.COM 223859Sml29623 /* 238661SSantwona.Behera@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 243859Sml29623 * Use is subject to license terms. 253859Sml29623 */ 263859Sml29623 273859Sml29623 #include <sys/nxge/nxge_impl.h> 283859Sml29623 #include <sys/nxge/nxge_rxdma.h> 296495Sspeer #include <sys/nxge/nxge_hio.h> 306495Sspeer 316495Sspeer #if !defined(_BIG_ENDIAN) 326495Sspeer #include <npi_rx_rd32.h> 336495Sspeer #endif 346495Sspeer #include <npi_rx_rd64.h> 356495Sspeer #include <npi_rx_wr64.h> 363859Sml29623 373859Sml29623 #define NXGE_ACTUAL_RDCGRP(nxgep, rdcgrp) \ 386495Sspeer (rdcgrp + nxgep->pt_config.hw_config.def_mac_rxdma_grpid) 393859Sml29623 #define NXGE_ACTUAL_RDC(nxgep, rdc) \ 403859Sml29623 (rdc + nxgep->pt_config.hw_config.start_rdc) 413859Sml29623 423859Sml29623 /* 433859Sml29623 * Globals: tunable parameters (/etc/system or adb) 443859Sml29623 * 453859Sml29623 */ 463859Sml29623 extern uint32_t nxge_rbr_size; 473859Sml29623 extern uint32_t nxge_rcr_size; 483859Sml29623 extern uint32_t nxge_rbr_spare_size; 49*11304SJanie.Lu@Sun.COM extern uint16_t nxge_rdc_buf_offset; 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 593859Sml29623 /* 603859Sml29623 * Tunables to manage the receive buffer blocks. 613859Sml29623 * 623859Sml29623 * nxge_rx_threshold_hi: copy all buffers. 633859Sml29623 * nxge_rx_bcopy_size_type: receive buffer block size type. 643859Sml29623 * nxge_rx_threshold_lo: copy only up to tunable block size type. 653859Sml29623 */ 663859Sml29623 extern nxge_rxbuf_threshold_t nxge_rx_threshold_hi; 673859Sml29623 extern nxge_rxbuf_type_t nxge_rx_buf_size_type; 683859Sml29623 extern nxge_rxbuf_threshold_t nxge_rx_threshold_lo; 693859Sml29623 706611Sml29623 extern uint32_t nxge_cksum_offload; 716495Sspeer 726495Sspeer static nxge_status_t nxge_map_rxdma(p_nxge_t, int); 736495Sspeer static void nxge_unmap_rxdma(p_nxge_t, int); 743859Sml29623 753859Sml29623 static nxge_status_t nxge_rxdma_hw_start_common(p_nxge_t); 766495Sspeer 776495Sspeer static nxge_status_t nxge_rxdma_hw_start(p_nxge_t, int); 786495Sspeer static void nxge_rxdma_hw_stop(p_nxge_t, int); 793859Sml29623 803859Sml29623 static nxge_status_t nxge_map_rxdma_channel(p_nxge_t, uint16_t, 813859Sml29623 p_nxge_dma_common_t *, p_rx_rbr_ring_t *, 823859Sml29623 uint32_t, 833859Sml29623 p_nxge_dma_common_t *, p_rx_rcr_ring_t *, 843859Sml29623 p_rx_mbox_t *); 853859Sml29623 static void nxge_unmap_rxdma_channel(p_nxge_t, uint16_t, 863859Sml29623 p_rx_rbr_ring_t, p_rx_rcr_ring_t, p_rx_mbox_t); 873859Sml29623 883859Sml29623 static nxge_status_t nxge_map_rxdma_channel_cfg_ring(p_nxge_t, 893859Sml29623 uint16_t, 903859Sml29623 p_nxge_dma_common_t *, p_rx_rbr_ring_t *, 913859Sml29623 p_rx_rcr_ring_t *, p_rx_mbox_t *); 923859Sml29623 static void nxge_unmap_rxdma_channel_cfg_ring(p_nxge_t, 933859Sml29623 p_rx_rcr_ring_t, p_rx_mbox_t); 943859Sml29623 953859Sml29623 static nxge_status_t nxge_map_rxdma_channel_buf_ring(p_nxge_t, 963859Sml29623 uint16_t, 973859Sml29623 p_nxge_dma_common_t *, 983859Sml29623 p_rx_rbr_ring_t *, uint32_t); 993859Sml29623 static void nxge_unmap_rxdma_channel_buf_ring(p_nxge_t, 1003859Sml29623 p_rx_rbr_ring_t); 1013859Sml29623 1023859Sml29623 static nxge_status_t nxge_rxdma_start_channel(p_nxge_t, uint16_t, 1033859Sml29623 p_rx_rbr_ring_t, p_rx_rcr_ring_t, p_rx_mbox_t); 1043859Sml29623 static nxge_status_t nxge_rxdma_stop_channel(p_nxge_t, uint16_t); 1053859Sml29623 1066495Sspeer static mblk_t * 1076495Sspeer nxge_rx_pkts(p_nxge_t, p_rx_rcr_ring_t, rx_dma_ctl_stat_t, int); 1083859Sml29623 1093859Sml29623 static void nxge_receive_packet(p_nxge_t, 1103859Sml29623 p_rx_rcr_ring_t, 1113859Sml29623 p_rcr_entry_t, 1123859Sml29623 boolean_t *, 1133859Sml29623 mblk_t **, mblk_t **); 1143859Sml29623 1153859Sml29623 nxge_status_t nxge_disable_rxdma_channel(p_nxge_t, uint16_t); 1163859Sml29623 1173859Sml29623 static p_rx_msg_t nxge_allocb(size_t, uint32_t, p_nxge_dma_common_t); 1183859Sml29623 static void nxge_freeb(p_rx_msg_t); 1196495Sspeer static nxge_status_t nxge_rx_err_evnts(p_nxge_t, int, rx_dma_ctl_stat_t); 1203859Sml29623 1213859Sml29623 static nxge_status_t nxge_rxdma_handle_port_errors(p_nxge_t, 1223859Sml29623 uint32_t, uint32_t); 1233859Sml29623 1243859Sml29623 static nxge_status_t nxge_rxbuf_index_info_init(p_nxge_t, 1253859Sml29623 p_rx_rbr_ring_t); 1263859Sml29623 1273859Sml29623 1283859Sml29623 static nxge_status_t 1293859Sml29623 nxge_rxdma_fatal_err_recover(p_nxge_t, uint16_t); 1303859Sml29623 1313859Sml29623 nxge_status_t 1323859Sml29623 nxge_rx_port_fatal_err_recover(p_nxge_t); 1333859Sml29623 1346495Sspeer static void nxge_rxdma_databuf_free(p_rx_rbr_ring_t); 1356495Sspeer 1363859Sml29623 nxge_status_t 1373859Sml29623 nxge_init_rxdma_channels(p_nxge_t nxgep) 1383859Sml29623 { 1397950SMichael.Speer@Sun.COM nxge_grp_set_t *set = &nxgep->rx_set; 1408275SEric Cheng int i, count, channel; 1417950SMichael.Speer@Sun.COM nxge_grp_t *group; 1428275SEric Cheng dc_map_t map; 1438275SEric Cheng int dev_gindex; 1443859Sml29623 1453859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_init_rxdma_channels")); 1463859Sml29623 1476495Sspeer if (!isLDOMguest(nxgep)) { 1486495Sspeer if (nxge_rxdma_hw_start_common(nxgep) != NXGE_OK) { 1496495Sspeer cmn_err(CE_NOTE, "hw_start_common"); 1506495Sspeer return (NXGE_ERROR); 1516495Sspeer } 1526495Sspeer } 1536495Sspeer 1546495Sspeer /* 1556495Sspeer * NXGE_LOGICAL_GROUP_MAX > NXGE_MAX_RDC_GROUPS (8) 1566495Sspeer * We only have 8 hardware RDC tables, but we may have 1576495Sspeer * up to 16 logical (software-defined) groups of RDCS, 1586495Sspeer * if we make use of layer 3 & 4 hardware classification. 1596495Sspeer */ 1606495Sspeer for (i = 0, count = 0; i < NXGE_LOGICAL_GROUP_MAX; i++) { 1616495Sspeer if ((1 << i) & set->lg.map) { 1627950SMichael.Speer@Sun.COM group = set->group[i]; 1638275SEric Cheng dev_gindex = 1648275SEric Cheng nxgep->pt_config.hw_config.def_mac_rxdma_grpid + i; 1658275SEric Cheng map = nxgep->pt_config.rdc_grps[dev_gindex].map; 1666495Sspeer for (channel = 0; channel < NXGE_MAX_RDCS; channel++) { 1678275SEric Cheng if ((1 << channel) & map) { 1686495Sspeer if ((nxge_grp_dc_add(nxgep, 1697755SMisaki.Kataoka@Sun.COM group, VP_BOUND_RX, channel))) 1707950SMichael.Speer@Sun.COM goto init_rxdma_channels_exit; 1716495Sspeer } 1726495Sspeer } 1736495Sspeer } 1746495Sspeer if (++count == set->lg.count) 1756495Sspeer break; 1766495Sspeer } 1776495Sspeer 1786495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "<== nxge_init_rxdma_channels")); 1796495Sspeer return (NXGE_OK); 1807950SMichael.Speer@Sun.COM 1817950SMichael.Speer@Sun.COM init_rxdma_channels_exit: 1827950SMichael.Speer@Sun.COM for (i = 0, count = 0; i < NXGE_LOGICAL_GROUP_MAX; i++) { 1837950SMichael.Speer@Sun.COM if ((1 << i) & set->lg.map) { 1847950SMichael.Speer@Sun.COM group = set->group[i]; 1858275SEric Cheng dev_gindex = 1868275SEric Cheng nxgep->pt_config.hw_config.def_mac_rxdma_grpid + i; 1878275SEric Cheng map = nxgep->pt_config.rdc_grps[dev_gindex].map; 1888275SEric Cheng for (channel = 0; channel < NXGE_MAX_RDCS; channel++) { 1898275SEric Cheng if ((1 << channel) & map) { 1907950SMichael.Speer@Sun.COM nxge_grp_dc_remove(nxgep, 1918275SEric Cheng VP_BOUND_RX, channel); 1927950SMichael.Speer@Sun.COM } 1937950SMichael.Speer@Sun.COM } 1947950SMichael.Speer@Sun.COM } 1957950SMichael.Speer@Sun.COM if (++count == set->lg.count) 1967950SMichael.Speer@Sun.COM break; 1977950SMichael.Speer@Sun.COM } 1987950SMichael.Speer@Sun.COM 1997950SMichael.Speer@Sun.COM NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "<== nxge_init_rxdma_channels")); 2007950SMichael.Speer@Sun.COM return (NXGE_ERROR); 2016495Sspeer } 2026495Sspeer 2036495Sspeer nxge_status_t 2046495Sspeer nxge_init_rxdma_channel(p_nxge_t nxge, int channel) 2056495Sspeer { 2068400SNicolas.Droux@Sun.COM nxge_status_t status; 2076495Sspeer 2086495Sspeer NXGE_DEBUG_MSG((nxge, MEM2_CTL, "==> nxge_init_rxdma_channel")); 2096495Sspeer 2106495Sspeer status = nxge_map_rxdma(nxge, channel); 2113859Sml29623 if (status != NXGE_OK) { 2126495Sspeer NXGE_ERROR_MSG((nxge, NXGE_ERR_CTL, 2136495Sspeer "<== nxge_init_rxdma: status 0x%x", status)); 2143859Sml29623 return (status); 2153859Sml29623 } 2163859Sml29623 2178400SNicolas.Droux@Sun.COM #if defined(sun4v) 2188400SNicolas.Droux@Sun.COM if (isLDOMguest(nxge)) { 2198400SNicolas.Droux@Sun.COM /* set rcr_ring */ 2208400SNicolas.Droux@Sun.COM p_rx_rcr_ring_t ring = nxge->rx_rcr_rings->rcr_rings[channel]; 2218400SNicolas.Droux@Sun.COM 2228400SNicolas.Droux@Sun.COM status = nxge_hio_rxdma_bind_intr(nxge, ring, channel); 2238400SNicolas.Droux@Sun.COM if (status != NXGE_OK) { 2248400SNicolas.Droux@Sun.COM nxge_unmap_rxdma(nxge, channel); 2258400SNicolas.Droux@Sun.COM return (status); 2268400SNicolas.Droux@Sun.COM } 2278400SNicolas.Droux@Sun.COM } 2288400SNicolas.Droux@Sun.COM #endif 2298400SNicolas.Droux@Sun.COM 2306495Sspeer status = nxge_rxdma_hw_start(nxge, channel); 2313859Sml29623 if (status != NXGE_OK) { 2326495Sspeer nxge_unmap_rxdma(nxge, channel); 2333859Sml29623 } 2343859Sml29623 2356495Sspeer if (!nxge->statsp->rdc_ksp[channel]) 2366495Sspeer nxge_setup_rdc_kstats(nxge, channel); 2376495Sspeer 2386495Sspeer NXGE_DEBUG_MSG((nxge, MEM2_CTL, 2396495Sspeer "<== nxge_init_rxdma_channel: status 0x%x", status)); 2403859Sml29623 2413859Sml29623 return (status); 2423859Sml29623 } 2433859Sml29623 2443859Sml29623 void 2453859Sml29623 nxge_uninit_rxdma_channels(p_nxge_t nxgep) 2463859Sml29623 { 2476495Sspeer nxge_grp_set_t *set = &nxgep->rx_set; 2486495Sspeer int rdc; 2496495Sspeer 2503859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_uninit_rxdma_channels")); 2513859Sml29623 2526495Sspeer if (set->owned.map == 0) { 2536495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 2546495Sspeer "nxge_uninit_rxdma_channels: no channels")); 2556495Sspeer return; 2566495Sspeer } 2576495Sspeer 2586495Sspeer for (rdc = 0; rdc < NXGE_MAX_RDCS; rdc++) { 2596495Sspeer if ((1 << rdc) & set->owned.map) { 2606495Sspeer nxge_grp_dc_remove(nxgep, VP_BOUND_RX, rdc); 2616495Sspeer } 2626495Sspeer } 2636495Sspeer 2646495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "<== nxge_uninit_rxdma_channels")); 2656495Sspeer } 2666495Sspeer 2676495Sspeer void 2686495Sspeer nxge_uninit_rxdma_channel(p_nxge_t nxgep, int channel) 2696495Sspeer { 2706495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_uninit_rxdma_channel")); 2716495Sspeer 2726495Sspeer if (nxgep->statsp->rdc_ksp[channel]) { 2736495Sspeer kstat_delete(nxgep->statsp->rdc_ksp[channel]); 2746495Sspeer nxgep->statsp->rdc_ksp[channel] = 0; 2756495Sspeer } 2766495Sspeer 2776495Sspeer nxge_rxdma_hw_stop(nxgep, channel); 2786495Sspeer nxge_unmap_rxdma(nxgep, channel); 2796495Sspeer 2806495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "<== nxge_uinit_rxdma_channel")); 2813859Sml29623 } 2823859Sml29623 2833859Sml29623 nxge_status_t 2843859Sml29623 nxge_reset_rxdma_channel(p_nxge_t nxgep, uint16_t channel) 2853859Sml29623 { 2863859Sml29623 npi_handle_t handle; 2873859Sml29623 npi_status_t rs = NPI_SUCCESS; 2883859Sml29623 nxge_status_t status = NXGE_OK; 2893859Sml29623 2907812SMichael.Speer@Sun.COM NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_reset_rxdma_channel")); 2913859Sml29623 2923859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 2933859Sml29623 rs = npi_rxdma_cfg_rdc_reset(handle, channel); 2943859Sml29623 2953859Sml29623 if (rs != NPI_SUCCESS) { 2963859Sml29623 status = NXGE_ERROR | rs; 2973859Sml29623 } 2983859Sml29623 2997812SMichael.Speer@Sun.COM NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_reset_rxdma_channel")); 3007812SMichael.Speer@Sun.COM 3013859Sml29623 return (status); 3023859Sml29623 } 3033859Sml29623 3043859Sml29623 void 3053859Sml29623 nxge_rxdma_regs_dump_channels(p_nxge_t nxgep) 3063859Sml29623 { 3076495Sspeer nxge_grp_set_t *set = &nxgep->rx_set; 3086495Sspeer int rdc; 3093859Sml29623 3103859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rxdma_regs_dump_channels")); 3113859Sml29623 3126495Sspeer if (!isLDOMguest(nxgep)) { 3136495Sspeer npi_handle_t handle = NXGE_DEV_NPI_HANDLE(nxgep); 3146495Sspeer (void) npi_rxdma_dump_fzc_regs(handle); 3156495Sspeer } 3166495Sspeer 3176495Sspeer if (nxgep->rx_rbr_rings == 0 || nxgep->rx_rbr_rings->rbr_rings == 0) { 3186495Sspeer NXGE_DEBUG_MSG((nxgep, TX_CTL, 3196495Sspeer "nxge_rxdma_regs_dump_channels: " 3206495Sspeer "NULL ring pointer(s)")); 3213859Sml29623 return; 3223859Sml29623 } 3236495Sspeer 3246495Sspeer if (set->owned.map == 0) { 3253859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 3266495Sspeer "nxge_rxdma_regs_dump_channels: no channels")); 3273859Sml29623 return; 3283859Sml29623 } 3293859Sml29623 3306495Sspeer for (rdc = 0; rdc < NXGE_MAX_RDCS; rdc++) { 3316495Sspeer if ((1 << rdc) & set->owned.map) { 3326495Sspeer rx_rbr_ring_t *ring = 3336495Sspeer nxgep->rx_rbr_rings->rbr_rings[rdc]; 3346495Sspeer if (ring) { 3356495Sspeer (void) nxge_dump_rxdma_channel(nxgep, rdc); 3366495Sspeer } 3373859Sml29623 } 3383859Sml29623 } 3393859Sml29623 3403859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_rxdma_regs_dump")); 3413859Sml29623 } 3423859Sml29623 3433859Sml29623 nxge_status_t 3443859Sml29623 nxge_dump_rxdma_channel(p_nxge_t nxgep, uint8_t channel) 3453859Sml29623 { 3463859Sml29623 npi_handle_t handle; 3473859Sml29623 npi_status_t rs = NPI_SUCCESS; 3483859Sml29623 nxge_status_t status = NXGE_OK; 3493859Sml29623 3503859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_dump_rxdma_channel")); 3513859Sml29623 3523859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 3533859Sml29623 rs = npi_rxdma_dump_rdc_regs(handle, channel); 3543859Sml29623 3553859Sml29623 if (rs != NPI_SUCCESS) { 3563859Sml29623 status = NXGE_ERROR | rs; 3573859Sml29623 } 3583859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_dump_rxdma_channel")); 3593859Sml29623 return (status); 3603859Sml29623 } 3613859Sml29623 3623859Sml29623 nxge_status_t 3633859Sml29623 nxge_init_rxdma_channel_event_mask(p_nxge_t nxgep, uint16_t channel, 3643859Sml29623 p_rx_dma_ent_msk_t mask_p) 3653859Sml29623 { 3663859Sml29623 npi_handle_t handle; 3673859Sml29623 npi_status_t rs = NPI_SUCCESS; 3683859Sml29623 nxge_status_t status = NXGE_OK; 3693859Sml29623 3703859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, 3716929Smisaki "<== nxge_init_rxdma_channel_event_mask")); 3723859Sml29623 3733859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 3743859Sml29623 rs = npi_rxdma_event_mask(handle, OP_SET, channel, mask_p); 3753859Sml29623 if (rs != NPI_SUCCESS) { 3763859Sml29623 status = NXGE_ERROR | rs; 3773859Sml29623 } 3783859Sml29623 3793859Sml29623 return (status); 3803859Sml29623 } 3813859Sml29623 3823859Sml29623 nxge_status_t 3833859Sml29623 nxge_init_rxdma_channel_cntl_stat(p_nxge_t nxgep, uint16_t channel, 3843859Sml29623 p_rx_dma_ctl_stat_t cs_p) 3853859Sml29623 { 3863859Sml29623 npi_handle_t handle; 3873859Sml29623 npi_status_t rs = NPI_SUCCESS; 3883859Sml29623 nxge_status_t status = NXGE_OK; 3893859Sml29623 3903859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, 3916929Smisaki "<== nxge_init_rxdma_channel_cntl_stat")); 3923859Sml29623 3933859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 3943859Sml29623 rs = npi_rxdma_control_status(handle, OP_SET, channel, cs_p); 3953859Sml29623 3963859Sml29623 if (rs != NPI_SUCCESS) { 3973859Sml29623 status = NXGE_ERROR | rs; 3983859Sml29623 } 3993859Sml29623 4003859Sml29623 return (status); 4013859Sml29623 } 4023859Sml29623 4036495Sspeer /* 4046495Sspeer * nxge_rxdma_cfg_rdcgrp_default_rdc 4056495Sspeer * 4066495Sspeer * Set the default RDC for an RDC Group (Table) 4076495Sspeer * 4086495Sspeer * Arguments: 4096495Sspeer * nxgep 4106495Sspeer * rdcgrp The group to modify 4116495Sspeer * rdc The new default RDC. 4126495Sspeer * 4136495Sspeer * Notes: 4146495Sspeer * 4156495Sspeer * NPI/NXGE function calls: 4166495Sspeer * npi_rxdma_cfg_rdc_table_default_rdc() 4176495Sspeer * 4186495Sspeer * Registers accessed: 4196495Sspeer * RDC_TBL_REG: FZC_ZCP + 0x10000 4206495Sspeer * 4216495Sspeer * Context: 4226495Sspeer * Service domain 4236495Sspeer */ 4243859Sml29623 nxge_status_t 4256495Sspeer nxge_rxdma_cfg_rdcgrp_default_rdc( 4266495Sspeer p_nxge_t nxgep, 4276495Sspeer uint8_t rdcgrp, 4286495Sspeer uint8_t rdc) 4293859Sml29623 { 4303859Sml29623 npi_handle_t handle; 4313859Sml29623 npi_status_t rs = NPI_SUCCESS; 4323859Sml29623 p_nxge_dma_pt_cfg_t p_dma_cfgp; 4333859Sml29623 p_nxge_rdc_grp_t rdc_grp_p; 4343859Sml29623 uint8_t actual_rdcgrp, actual_rdc; 4353859Sml29623 4363859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 4376929Smisaki " ==> nxge_rxdma_cfg_rdcgrp_default_rdc")); 4383859Sml29623 p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config; 4393859Sml29623 4403859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 4413859Sml29623 4426495Sspeer /* 4436495Sspeer * This has to be rewritten. Do we even allow this anymore? 4446495Sspeer */ 4453859Sml29623 rdc_grp_p = &p_dma_cfgp->rdc_grps[rdcgrp]; 4466495Sspeer RDC_MAP_IN(rdc_grp_p->map, rdc); 4476495Sspeer rdc_grp_p->def_rdc = rdc; 4483859Sml29623 4493859Sml29623 actual_rdcgrp = NXGE_ACTUAL_RDCGRP(nxgep, rdcgrp); 4503859Sml29623 actual_rdc = NXGE_ACTUAL_RDC(nxgep, rdc); 4513859Sml29623 4526495Sspeer rs = npi_rxdma_cfg_rdc_table_default_rdc( 4536929Smisaki handle, actual_rdcgrp, actual_rdc); 4543859Sml29623 4553859Sml29623 if (rs != NPI_SUCCESS) { 4563859Sml29623 return (NXGE_ERROR | rs); 4573859Sml29623 } 4583859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 4596929Smisaki " <== nxge_rxdma_cfg_rdcgrp_default_rdc")); 4603859Sml29623 return (NXGE_OK); 4613859Sml29623 } 4623859Sml29623 4633859Sml29623 nxge_status_t 4643859Sml29623 nxge_rxdma_cfg_port_default_rdc(p_nxge_t nxgep, uint8_t port, uint8_t rdc) 4653859Sml29623 { 4663859Sml29623 npi_handle_t handle; 4673859Sml29623 4683859Sml29623 uint8_t actual_rdc; 4693859Sml29623 npi_status_t rs = NPI_SUCCESS; 4703859Sml29623 4713859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 4726929Smisaki " ==> nxge_rxdma_cfg_port_default_rdc")); 4733859Sml29623 4743859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 4756495Sspeer actual_rdc = rdc; /* XXX Hack! */ 4763859Sml29623 rs = npi_rxdma_cfg_default_port_rdc(handle, port, actual_rdc); 4773859Sml29623 4783859Sml29623 4793859Sml29623 if (rs != NPI_SUCCESS) { 4803859Sml29623 return (NXGE_ERROR | rs); 4813859Sml29623 } 4823859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 4836929Smisaki " <== nxge_rxdma_cfg_port_default_rdc")); 4843859Sml29623 4853859Sml29623 return (NXGE_OK); 4863859Sml29623 } 4873859Sml29623 4883859Sml29623 nxge_status_t 4893859Sml29623 nxge_rxdma_cfg_rcr_threshold(p_nxge_t nxgep, uint8_t channel, 4903859Sml29623 uint16_t pkts) 4913859Sml29623 { 4923859Sml29623 npi_status_t rs = NPI_SUCCESS; 4933859Sml29623 npi_handle_t handle; 4943859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 4956929Smisaki " ==> nxge_rxdma_cfg_rcr_threshold")); 4963859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 4973859Sml29623 4983859Sml29623 rs = npi_rxdma_cfg_rdc_rcr_threshold(handle, channel, pkts); 4993859Sml29623 5003859Sml29623 if (rs != NPI_SUCCESS) { 5013859Sml29623 return (NXGE_ERROR | rs); 5023859Sml29623 } 5033859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, " <== nxge_rxdma_cfg_rcr_threshold")); 5043859Sml29623 return (NXGE_OK); 5053859Sml29623 } 5063859Sml29623 5073859Sml29623 nxge_status_t 5083859Sml29623 nxge_rxdma_cfg_rcr_timeout(p_nxge_t nxgep, uint8_t channel, 5093859Sml29623 uint16_t tout, uint8_t enable) 5103859Sml29623 { 5113859Sml29623 npi_status_t rs = NPI_SUCCESS; 5123859Sml29623 npi_handle_t handle; 5133859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, " ==> nxge_rxdma_cfg_rcr_timeout")); 5143859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 5153859Sml29623 if (enable == 0) { 5163859Sml29623 rs = npi_rxdma_cfg_rdc_rcr_timeout_disable(handle, channel); 5173859Sml29623 } else { 5183859Sml29623 rs = npi_rxdma_cfg_rdc_rcr_timeout(handle, channel, 5196929Smisaki tout); 5203859Sml29623 } 5213859Sml29623 5223859Sml29623 if (rs != NPI_SUCCESS) { 5233859Sml29623 return (NXGE_ERROR | rs); 5243859Sml29623 } 5253859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, " <== nxge_rxdma_cfg_rcr_timeout")); 5263859Sml29623 return (NXGE_OK); 5273859Sml29623 } 5283859Sml29623 5293859Sml29623 nxge_status_t 5303859Sml29623 nxge_enable_rxdma_channel(p_nxge_t nxgep, uint16_t channel, 5313859Sml29623 p_rx_rbr_ring_t rbr_p, p_rx_rcr_ring_t rcr_p, p_rx_mbox_t mbox_p) 5323859Sml29623 { 5333859Sml29623 npi_handle_t handle; 5343859Sml29623 rdc_desc_cfg_t rdc_desc; 5353859Sml29623 p_rcrcfig_b_t cfgb_p; 5363859Sml29623 npi_status_t rs = NPI_SUCCESS; 5373859Sml29623 5383859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_enable_rxdma_channel")); 5393859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 5403859Sml29623 /* 5413859Sml29623 * Use configuration data composed at init time. 5423859Sml29623 * Write to hardware the receive ring configurations. 5433859Sml29623 */ 5443859Sml29623 rdc_desc.mbox_enable = 1; 5453859Sml29623 rdc_desc.mbox_addr = mbox_p->mbox_addr; 5463859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 5476929Smisaki "==> nxge_enable_rxdma_channel: mboxp $%p($%p)", 5486929Smisaki mbox_p->mbox_addr, rdc_desc.mbox_addr)); 5493859Sml29623 5503859Sml29623 rdc_desc.rbr_len = rbr_p->rbb_max; 5513859Sml29623 rdc_desc.rbr_addr = rbr_p->rbr_addr; 5523859Sml29623 5533859Sml29623 switch (nxgep->rx_bksize_code) { 5543859Sml29623 case RBR_BKSIZE_4K: 5553859Sml29623 rdc_desc.page_size = SIZE_4KB; 5563859Sml29623 break; 5573859Sml29623 case RBR_BKSIZE_8K: 5583859Sml29623 rdc_desc.page_size = SIZE_8KB; 5593859Sml29623 break; 5603859Sml29623 case RBR_BKSIZE_16K: 5613859Sml29623 rdc_desc.page_size = SIZE_16KB; 5623859Sml29623 break; 5633859Sml29623 case RBR_BKSIZE_32K: 5643859Sml29623 rdc_desc.page_size = SIZE_32KB; 5653859Sml29623 break; 5663859Sml29623 } 5673859Sml29623 5683859Sml29623 rdc_desc.size0 = rbr_p->npi_pkt_buf_size0; 5693859Sml29623 rdc_desc.valid0 = 1; 5703859Sml29623 5713859Sml29623 rdc_desc.size1 = rbr_p->npi_pkt_buf_size1; 5723859Sml29623 rdc_desc.valid1 = 1; 5733859Sml29623 5743859Sml29623 rdc_desc.size2 = rbr_p->npi_pkt_buf_size2; 5753859Sml29623 rdc_desc.valid2 = 1; 5763859Sml29623 5773859Sml29623 rdc_desc.full_hdr = rcr_p->full_hdr_flag; 5783859Sml29623 rdc_desc.offset = rcr_p->sw_priv_hdr_len; 5793859Sml29623 5803859Sml29623 rdc_desc.rcr_len = rcr_p->comp_size; 5813859Sml29623 rdc_desc.rcr_addr = rcr_p->rcr_addr; 5823859Sml29623 5833859Sml29623 cfgb_p = &(rcr_p->rcr_cfgb); 5843859Sml29623 rdc_desc.rcr_threshold = cfgb_p->bits.ldw.pthres; 5856495Sspeer /* For now, disable this timeout in a guest domain. */ 5866495Sspeer if (isLDOMguest(nxgep)) { 5876495Sspeer rdc_desc.rcr_timeout = 0; 5886495Sspeer rdc_desc.rcr_timeout_enable = 0; 5896495Sspeer } else { 5906495Sspeer rdc_desc.rcr_timeout = cfgb_p->bits.ldw.timeout; 5916495Sspeer rdc_desc.rcr_timeout_enable = cfgb_p->bits.ldw.entout; 5926495Sspeer } 5933859Sml29623 5943859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_enable_rxdma_channel: " 5956929Smisaki "rbr_len qlen %d pagesize code %d rcr_len %d", 5966929Smisaki rdc_desc.rbr_len, rdc_desc.page_size, rdc_desc.rcr_len)); 5973859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_enable_rxdma_channel: " 5986929Smisaki "size 0 %d size 1 %d size 2 %d", 5996929Smisaki rbr_p->npi_pkt_buf_size0, rbr_p->npi_pkt_buf_size1, 6006929Smisaki rbr_p->npi_pkt_buf_size2)); 6013859Sml29623 602*11304SJanie.Lu@Sun.COM if (nxgep->niu_hw_type == NIU_HW_TYPE_RF) 603*11304SJanie.Lu@Sun.COM rs = npi_rxdma_cfg_rdc_ring(handle, rbr_p->rdc, 604*11304SJanie.Lu@Sun.COM &rdc_desc, B_TRUE); 605*11304SJanie.Lu@Sun.COM else 606*11304SJanie.Lu@Sun.COM rs = npi_rxdma_cfg_rdc_ring(handle, rbr_p->rdc, 607*11304SJanie.Lu@Sun.COM &rdc_desc, B_FALSE); 6083859Sml29623 if (rs != NPI_SUCCESS) { 6093859Sml29623 return (NXGE_ERROR | rs); 6103859Sml29623 } 6113859Sml29623 6123859Sml29623 /* 6133859Sml29623 * Enable the timeout and threshold. 6143859Sml29623 */ 6153859Sml29623 rs = npi_rxdma_cfg_rdc_rcr_threshold(handle, channel, 6166929Smisaki rdc_desc.rcr_threshold); 6173859Sml29623 if (rs != NPI_SUCCESS) { 6183859Sml29623 return (NXGE_ERROR | rs); 6193859Sml29623 } 6203859Sml29623 6213859Sml29623 rs = npi_rxdma_cfg_rdc_rcr_timeout(handle, channel, 6226929Smisaki rdc_desc.rcr_timeout); 6233859Sml29623 if (rs != NPI_SUCCESS) { 6243859Sml29623 return (NXGE_ERROR | rs); 6253859Sml29623 } 6263859Sml29623 6279232SMichael.Speer@Sun.COM if (!isLDOMguest(nxgep)) { 6289232SMichael.Speer@Sun.COM /* Enable the DMA */ 6299232SMichael.Speer@Sun.COM rs = npi_rxdma_cfg_rdc_enable(handle, channel); 6309232SMichael.Speer@Sun.COM if (rs != NPI_SUCCESS) { 6319232SMichael.Speer@Sun.COM return (NXGE_ERROR | rs); 6329232SMichael.Speer@Sun.COM } 6333859Sml29623 } 6343859Sml29623 6353859Sml29623 /* Kick the DMA engine. */ 6363859Sml29623 npi_rxdma_rdc_rbr_kick(handle, channel, rbr_p->rbb_max); 6379232SMichael.Speer@Sun.COM 6389232SMichael.Speer@Sun.COM if (!isLDOMguest(nxgep)) { 6399232SMichael.Speer@Sun.COM /* Clear the rbr empty bit */ 6409232SMichael.Speer@Sun.COM (void) npi_rxdma_channel_rbr_empty_clear(handle, channel); 6419232SMichael.Speer@Sun.COM } 6423859Sml29623 6433859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_enable_rxdma_channel")); 6443859Sml29623 6453859Sml29623 return (NXGE_OK); 6463859Sml29623 } 6473859Sml29623 6483859Sml29623 nxge_status_t 6493859Sml29623 nxge_disable_rxdma_channel(p_nxge_t nxgep, uint16_t channel) 6503859Sml29623 { 6513859Sml29623 npi_handle_t handle; 6523859Sml29623 npi_status_t rs = NPI_SUCCESS; 6533859Sml29623 6543859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_disable_rxdma_channel")); 6553859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 6563859Sml29623 6573859Sml29623 /* disable the DMA */ 6583859Sml29623 rs = npi_rxdma_cfg_rdc_disable(handle, channel); 6593859Sml29623 if (rs != NPI_SUCCESS) { 6603859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 6616929Smisaki "<== nxge_disable_rxdma_channel:failed (0x%x)", 6626929Smisaki rs)); 6633859Sml29623 return (NXGE_ERROR | rs); 6643859Sml29623 } 6653859Sml29623 6663859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_disable_rxdma_channel")); 6673859Sml29623 return (NXGE_OK); 6683859Sml29623 } 6693859Sml29623 6703859Sml29623 nxge_status_t 6713859Sml29623 nxge_rxdma_channel_rcrflush(p_nxge_t nxgep, uint8_t channel) 6723859Sml29623 { 6733859Sml29623 npi_handle_t handle; 6743859Sml29623 nxge_status_t status = NXGE_OK; 6753859Sml29623 6763859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, 6776929Smisaki "<== nxge_init_rxdma_channel_rcrflush")); 6783859Sml29623 6793859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 6803859Sml29623 npi_rxdma_rdc_rcr_flush(handle, channel); 6813859Sml29623 6823859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, 6836929Smisaki "<== nxge_init_rxdma_channel_rcrflsh")); 6843859Sml29623 return (status); 6853859Sml29623 6863859Sml29623 } 6873859Sml29623 6883859Sml29623 #define MID_INDEX(l, r) ((r + l + 1) >> 1) 6893859Sml29623 6903859Sml29623 #define TO_LEFT -1 6913859Sml29623 #define TO_RIGHT 1 6923859Sml29623 #define BOTH_RIGHT (TO_RIGHT + TO_RIGHT) 6933859Sml29623 #define BOTH_LEFT (TO_LEFT + TO_LEFT) 6943859Sml29623 #define IN_MIDDLE (TO_RIGHT + TO_LEFT) 6953859Sml29623 #define NO_HINT 0xffffffff 6963859Sml29623 6973859Sml29623 /*ARGSUSED*/ 6983859Sml29623 nxge_status_t 6993859Sml29623 nxge_rxbuf_pp_to_vp(p_nxge_t nxgep, p_rx_rbr_ring_t rbr_p, 7003859Sml29623 uint8_t pktbufsz_type, uint64_t *pkt_buf_addr_pp, 7013859Sml29623 uint64_t **pkt_buf_addr_p, uint32_t *bufoffset, uint32_t *msg_index) 7023859Sml29623 { 7033859Sml29623 int bufsize; 7043859Sml29623 uint64_t pktbuf_pp; 7053859Sml29623 uint64_t dvma_addr; 7063859Sml29623 rxring_info_t *ring_info; 7073859Sml29623 int base_side, end_side; 7083859Sml29623 int r_index, l_index, anchor_index; 7093859Sml29623 int found, search_done; 7103859Sml29623 uint32_t offset, chunk_size, block_size, page_size_mask; 7113859Sml29623 uint32_t chunk_index, block_index, total_index; 7123859Sml29623 int max_iterations, iteration; 7133859Sml29623 rxbuf_index_info_t *bufinfo; 7143859Sml29623 7153859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, "==> nxge_rxbuf_pp_to_vp")); 7163859Sml29623 7173859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 7186929Smisaki "==> nxge_rxbuf_pp_to_vp: buf_pp $%p btype %d", 7196929Smisaki pkt_buf_addr_pp, 7206929Smisaki pktbufsz_type)); 7215125Sjoycey #if defined(__i386) 7225125Sjoycey pktbuf_pp = (uint64_t)(uint32_t)pkt_buf_addr_pp; 7235125Sjoycey #else 7243859Sml29623 pktbuf_pp = (uint64_t)pkt_buf_addr_pp; 7255125Sjoycey #endif 7263859Sml29623 7273859Sml29623 switch (pktbufsz_type) { 7283859Sml29623 case 0: 7293859Sml29623 bufsize = rbr_p->pkt_buf_size0; 7303859Sml29623 break; 7313859Sml29623 case 1: 7323859Sml29623 bufsize = rbr_p->pkt_buf_size1; 7333859Sml29623 break; 7343859Sml29623 case 2: 7353859Sml29623 bufsize = rbr_p->pkt_buf_size2; 7363859Sml29623 break; 7373859Sml29623 case RCR_SINGLE_BLOCK: 7383859Sml29623 bufsize = 0; 7393859Sml29623 anchor_index = 0; 7403859Sml29623 break; 7413859Sml29623 default: 7423859Sml29623 return (NXGE_ERROR); 7433859Sml29623 } 7443859Sml29623 7453859Sml29623 if (rbr_p->num_blocks == 1) { 7463859Sml29623 anchor_index = 0; 7473859Sml29623 ring_info = rbr_p->ring_info; 7483859Sml29623 bufinfo = (rxbuf_index_info_t *)ring_info->buffer; 7493859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 7506929Smisaki "==> nxge_rxbuf_pp_to_vp: (found, 1 block) " 7516929Smisaki "buf_pp $%p btype %d anchor_index %d " 7526929Smisaki "bufinfo $%p", 7536929Smisaki pkt_buf_addr_pp, 7546929Smisaki pktbufsz_type, 7556929Smisaki anchor_index, 7566929Smisaki bufinfo)); 7573859Sml29623 7583859Sml29623 goto found_index; 7593859Sml29623 } 7603859Sml29623 7613859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 7626929Smisaki "==> nxge_rxbuf_pp_to_vp: " 7636929Smisaki "buf_pp $%p btype %d anchor_index %d", 7646929Smisaki pkt_buf_addr_pp, 7656929Smisaki pktbufsz_type, 7666929Smisaki anchor_index)); 7673859Sml29623 7683859Sml29623 ring_info = rbr_p->ring_info; 7693859Sml29623 found = B_FALSE; 7703859Sml29623 bufinfo = (rxbuf_index_info_t *)ring_info->buffer; 7713859Sml29623 iteration = 0; 7723859Sml29623 max_iterations = ring_info->max_iterations; 7733859Sml29623 /* 7743859Sml29623 * First check if this block has been seen 7753859Sml29623 * recently. This is indicated by a hint which 7763859Sml29623 * is initialized when the first buffer of the block 7773859Sml29623 * is seen. The hint is reset when the last buffer of 7783859Sml29623 * the block has been processed. 7793859Sml29623 * As three block sizes are supported, three hints 7803859Sml29623 * are kept. The idea behind the hints is that once 7813859Sml29623 * the hardware uses a block for a buffer of that 7823859Sml29623 * size, it will use it exclusively for that size 7833859Sml29623 * and will use it until it is exhausted. It is assumed 7843859Sml29623 * that there would a single block being used for the same 7853859Sml29623 * buffer sizes at any given time. 7863859Sml29623 */ 7873859Sml29623 if (ring_info->hint[pktbufsz_type] != NO_HINT) { 7883859Sml29623 anchor_index = ring_info->hint[pktbufsz_type]; 7893859Sml29623 dvma_addr = bufinfo[anchor_index].dvma_addr; 7903859Sml29623 chunk_size = bufinfo[anchor_index].buf_size; 7913859Sml29623 if ((pktbuf_pp >= dvma_addr) && 7926929Smisaki (pktbuf_pp < (dvma_addr + chunk_size))) { 7933859Sml29623 found = B_TRUE; 7943859Sml29623 /* 7953859Sml29623 * check if this is the last buffer in the block 7963859Sml29623 * If so, then reset the hint for the size; 7973859Sml29623 */ 7983859Sml29623 7993859Sml29623 if ((pktbuf_pp + bufsize) >= (dvma_addr + chunk_size)) 8003859Sml29623 ring_info->hint[pktbufsz_type] = NO_HINT; 8013859Sml29623 } 8023859Sml29623 } 8033859Sml29623 8043859Sml29623 if (found == B_FALSE) { 8053859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 8066929Smisaki "==> nxge_rxbuf_pp_to_vp: (!found)" 8076929Smisaki "buf_pp $%p btype %d anchor_index %d", 8086929Smisaki pkt_buf_addr_pp, 8096929Smisaki pktbufsz_type, 8106929Smisaki anchor_index)); 8113859Sml29623 8123859Sml29623 /* 8133859Sml29623 * This is the first buffer of the block of this 8143859Sml29623 * size. Need to search the whole information 8153859Sml29623 * array. 8163859Sml29623 * the search algorithm uses a binary tree search 8173859Sml29623 * algorithm. It assumes that the information is 8183859Sml29623 * already sorted with increasing order 8193859Sml29623 * info[0] < info[1] < info[2] .... < info[n-1] 8203859Sml29623 * where n is the size of the information array 8213859Sml29623 */ 8223859Sml29623 r_index = rbr_p->num_blocks - 1; 8233859Sml29623 l_index = 0; 8243859Sml29623 search_done = B_FALSE; 8253859Sml29623 anchor_index = MID_INDEX(r_index, l_index); 8263859Sml29623 while (search_done == B_FALSE) { 8273859Sml29623 if ((r_index == l_index) || 8286929Smisaki (iteration >= max_iterations)) 8293859Sml29623 search_done = B_TRUE; 8303859Sml29623 end_side = TO_RIGHT; /* to the right */ 8313859Sml29623 base_side = TO_LEFT; /* to the left */ 8323859Sml29623 /* read the DVMA address information and sort it */ 8333859Sml29623 dvma_addr = bufinfo[anchor_index].dvma_addr; 8343859Sml29623 chunk_size = bufinfo[anchor_index].buf_size; 8353859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 8366929Smisaki "==> nxge_rxbuf_pp_to_vp: (searching)" 8376929Smisaki "buf_pp $%p btype %d " 8386929Smisaki "anchor_index %d chunk_size %d dvmaaddr $%p", 8396929Smisaki pkt_buf_addr_pp, 8406929Smisaki pktbufsz_type, 8416929Smisaki anchor_index, 8426929Smisaki chunk_size, 8436929Smisaki dvma_addr)); 8443859Sml29623 8453859Sml29623 if (pktbuf_pp >= dvma_addr) 8463859Sml29623 base_side = TO_RIGHT; /* to the right */ 8473859Sml29623 if (pktbuf_pp < (dvma_addr + chunk_size)) 8483859Sml29623 end_side = TO_LEFT; /* to the left */ 8493859Sml29623 8503859Sml29623 switch (base_side + end_side) { 8516929Smisaki case IN_MIDDLE: 8526929Smisaki /* found */ 8536929Smisaki found = B_TRUE; 8546929Smisaki search_done = B_TRUE; 8556929Smisaki if ((pktbuf_pp + bufsize) < 8566929Smisaki (dvma_addr + chunk_size)) 8576929Smisaki ring_info->hint[pktbufsz_type] = 8586929Smisaki bufinfo[anchor_index].buf_index; 8596929Smisaki break; 8606929Smisaki case BOTH_RIGHT: 8616929Smisaki /* not found: go to the right */ 8626929Smisaki l_index = anchor_index + 1; 8636929Smisaki anchor_index = MID_INDEX(r_index, l_index); 8646929Smisaki break; 8656929Smisaki 8666929Smisaki case BOTH_LEFT: 8676929Smisaki /* not found: go to the left */ 8686929Smisaki r_index = anchor_index - 1; 8696929Smisaki anchor_index = MID_INDEX(r_index, l_index); 8706929Smisaki break; 8716929Smisaki default: /* should not come here */ 8726929Smisaki return (NXGE_ERROR); 8733859Sml29623 } 8743859Sml29623 iteration++; 8753859Sml29623 } 8763859Sml29623 8773859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 8786929Smisaki "==> nxge_rxbuf_pp_to_vp: (search done)" 8796929Smisaki "buf_pp $%p btype %d anchor_index %d", 8806929Smisaki pkt_buf_addr_pp, 8816929Smisaki pktbufsz_type, 8826929Smisaki anchor_index)); 8833859Sml29623 } 8843859Sml29623 8853859Sml29623 if (found == B_FALSE) { 8863859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 8876929Smisaki "==> nxge_rxbuf_pp_to_vp: (search failed)" 8886929Smisaki "buf_pp $%p btype %d anchor_index %d", 8896929Smisaki pkt_buf_addr_pp, 8906929Smisaki pktbufsz_type, 8916929Smisaki anchor_index)); 8923859Sml29623 return (NXGE_ERROR); 8933859Sml29623 } 8943859Sml29623 8953859Sml29623 found_index: 8963859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 8976929Smisaki "==> nxge_rxbuf_pp_to_vp: (FOUND1)" 8986929Smisaki "buf_pp $%p btype %d bufsize %d anchor_index %d", 8996929Smisaki pkt_buf_addr_pp, 9006929Smisaki pktbufsz_type, 9016929Smisaki bufsize, 9026929Smisaki anchor_index)); 9033859Sml29623 9043859Sml29623 /* index of the first block in this chunk */ 9053859Sml29623 chunk_index = bufinfo[anchor_index].start_index; 9063859Sml29623 dvma_addr = bufinfo[anchor_index].dvma_addr; 9073859Sml29623 page_size_mask = ring_info->block_size_mask; 9083859Sml29623 9093859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 9106929Smisaki "==> nxge_rxbuf_pp_to_vp: (FOUND3), get chunk)" 9116929Smisaki "buf_pp $%p btype %d bufsize %d " 9126929Smisaki "anchor_index %d chunk_index %d dvma $%p", 9136929Smisaki pkt_buf_addr_pp, 9146929Smisaki pktbufsz_type, 9156929Smisaki bufsize, 9166929Smisaki anchor_index, 9176929Smisaki chunk_index, 9186929Smisaki dvma_addr)); 9193859Sml29623 9203859Sml29623 offset = pktbuf_pp - dvma_addr; /* offset within the chunk */ 9213859Sml29623 block_size = rbr_p->block_size; /* System block(page) size */ 9223859Sml29623 9233859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 9246929Smisaki "==> nxge_rxbuf_pp_to_vp: (FOUND4), get chunk)" 9256929Smisaki "buf_pp $%p btype %d bufsize %d " 9266929Smisaki "anchor_index %d chunk_index %d dvma $%p " 9276929Smisaki "offset %d block_size %d", 9286929Smisaki pkt_buf_addr_pp, 9296929Smisaki pktbufsz_type, 9306929Smisaki bufsize, 9316929Smisaki anchor_index, 9326929Smisaki chunk_index, 9336929Smisaki dvma_addr, 9346929Smisaki offset, 9356929Smisaki block_size)); 9363859Sml29623 9373859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, "==> getting total index")); 9383859Sml29623 9393859Sml29623 block_index = (offset / block_size); /* index within chunk */ 9403859Sml29623 total_index = chunk_index + block_index; 9413859Sml29623 9423859Sml29623 9433859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 9446929Smisaki "==> nxge_rxbuf_pp_to_vp: " 9456929Smisaki "total_index %d dvma_addr $%p " 9466929Smisaki "offset %d block_size %d " 9476929Smisaki "block_index %d ", 9486929Smisaki total_index, dvma_addr, 9496929Smisaki offset, block_size, 9506929Smisaki block_index)); 9515125Sjoycey #if defined(__i386) 9525125Sjoycey *pkt_buf_addr_p = (uint64_t *)((uint32_t)bufinfo[anchor_index].kaddr + 9536929Smisaki (uint32_t)offset); 9545125Sjoycey #else 9555125Sjoycey *pkt_buf_addr_p = (uint64_t *)((uint64_t)bufinfo[anchor_index].kaddr + 9566929Smisaki (uint64_t)offset); 9575125Sjoycey #endif 9583859Sml29623 9593859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 9606929Smisaki "==> nxge_rxbuf_pp_to_vp: " 9616929Smisaki "total_index %d dvma_addr $%p " 9626929Smisaki "offset %d block_size %d " 9636929Smisaki "block_index %d " 9646929Smisaki "*pkt_buf_addr_p $%p", 9656929Smisaki total_index, dvma_addr, 9666929Smisaki offset, block_size, 9676929Smisaki block_index, 9686929Smisaki *pkt_buf_addr_p)); 9693859Sml29623 9703859Sml29623 9713859Sml29623 *msg_index = total_index; 9723859Sml29623 *bufoffset = (offset & page_size_mask); 9733859Sml29623 9743859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 9756929Smisaki "==> nxge_rxbuf_pp_to_vp: get msg index: " 9766929Smisaki "msg_index %d bufoffset_index %d", 9776929Smisaki *msg_index, 9786929Smisaki *bufoffset)); 9793859Sml29623 9803859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, "<== nxge_rxbuf_pp_to_vp")); 9813859Sml29623 9823859Sml29623 return (NXGE_OK); 9833859Sml29623 } 9843859Sml29623 9853859Sml29623 /* 9863859Sml29623 * used by quick sort (qsort) function 9873859Sml29623 * to perform comparison 9883859Sml29623 */ 9893859Sml29623 static int 9903859Sml29623 nxge_sort_compare(const void *p1, const void *p2) 9913859Sml29623 { 9923859Sml29623 9933859Sml29623 rxbuf_index_info_t *a, *b; 9943859Sml29623 9953859Sml29623 a = (rxbuf_index_info_t *)p1; 9963859Sml29623 b = (rxbuf_index_info_t *)p2; 9973859Sml29623 9983859Sml29623 if (a->dvma_addr > b->dvma_addr) 9993859Sml29623 return (1); 10003859Sml29623 if (a->dvma_addr < b->dvma_addr) 10013859Sml29623 return (-1); 10023859Sml29623 return (0); 10033859Sml29623 } 10043859Sml29623 10053859Sml29623 10063859Sml29623 10073859Sml29623 /* 10083859Sml29623 * grabbed this sort implementation from common/syscall/avl.c 10093859Sml29623 * 10103859Sml29623 */ 10113859Sml29623 /* 10123859Sml29623 * Generic shellsort, from K&R (1st ed, p 58.), somewhat modified. 10133859Sml29623 * v = Ptr to array/vector of objs 10143859Sml29623 * n = # objs in the array 10153859Sml29623 * s = size of each obj (must be multiples of a word size) 10163859Sml29623 * f = ptr to function to compare two objs 10173859Sml29623 * returns (-1 = less than, 0 = equal, 1 = greater than 10183859Sml29623 */ 10193859Sml29623 void 10203859Sml29623 nxge_ksort(caddr_t v, int n, int s, int (*f)()) 10213859Sml29623 { 10223859Sml29623 int g, i, j, ii; 10233859Sml29623 unsigned int *p1, *p2; 10243859Sml29623 unsigned int tmp; 10253859Sml29623 10263859Sml29623 /* No work to do */ 10273859Sml29623 if (v == NULL || n <= 1) 10283859Sml29623 return; 10293859Sml29623 /* Sanity check on arguments */ 10303859Sml29623 ASSERT(((uintptr_t)v & 0x3) == 0 && (s & 0x3) == 0); 10313859Sml29623 ASSERT(s > 0); 10323859Sml29623 10333859Sml29623 for (g = n / 2; g > 0; g /= 2) { 10343859Sml29623 for (i = g; i < n; i++) { 10353859Sml29623 for (j = i - g; j >= 0 && 10366929Smisaki (*f)(v + j * s, v + (j + g) * s) == 1; 10376929Smisaki j -= g) { 10383859Sml29623 p1 = (unsigned *)(v + j * s); 10393859Sml29623 p2 = (unsigned *)(v + (j + g) * s); 10403859Sml29623 for (ii = 0; ii < s / 4; ii++) { 10413859Sml29623 tmp = *p1; 10423859Sml29623 *p1++ = *p2; 10433859Sml29623 *p2++ = tmp; 10443859Sml29623 } 10453859Sml29623 } 10463859Sml29623 } 10473859Sml29623 } 10483859Sml29623 } 10493859Sml29623 10503859Sml29623 /* 10513859Sml29623 * Initialize data structures required for rxdma 10523859Sml29623 * buffer dvma->vmem address lookup 10533859Sml29623 */ 10543859Sml29623 /*ARGSUSED*/ 10553859Sml29623 static nxge_status_t 10563859Sml29623 nxge_rxbuf_index_info_init(p_nxge_t nxgep, p_rx_rbr_ring_t rbrp) 10573859Sml29623 { 10583859Sml29623 10593859Sml29623 int index; 10603859Sml29623 rxring_info_t *ring_info; 10613859Sml29623 int max_iteration = 0, max_index = 0; 10623859Sml29623 10633859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_rxbuf_index_info_init")); 10643859Sml29623 10653859Sml29623 ring_info = rbrp->ring_info; 10663859Sml29623 ring_info->hint[0] = NO_HINT; 10673859Sml29623 ring_info->hint[1] = NO_HINT; 10683859Sml29623 ring_info->hint[2] = NO_HINT; 10693859Sml29623 max_index = rbrp->num_blocks; 10703859Sml29623 10713859Sml29623 /* read the DVMA address information and sort it */ 10723859Sml29623 /* do init of the information array */ 10733859Sml29623 10743859Sml29623 10753859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA2_CTL, 10766929Smisaki " nxge_rxbuf_index_info_init Sort ptrs")); 10773859Sml29623 10783859Sml29623 /* sort the array */ 10793859Sml29623 nxge_ksort((void *)ring_info->buffer, max_index, 10806929Smisaki sizeof (rxbuf_index_info_t), nxge_sort_compare); 10813859Sml29623 10823859Sml29623 10833859Sml29623 10843859Sml29623 for (index = 0; index < max_index; index++) { 10853859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA2_CTL, 10866929Smisaki " nxge_rxbuf_index_info_init: sorted chunk %d " 10876929Smisaki " ioaddr $%p kaddr $%p size %x", 10886929Smisaki index, ring_info->buffer[index].dvma_addr, 10896929Smisaki ring_info->buffer[index].kaddr, 10906929Smisaki ring_info->buffer[index].buf_size)); 10913859Sml29623 } 10923859Sml29623 10933859Sml29623 max_iteration = 0; 10943859Sml29623 while (max_index >= (1ULL << max_iteration)) 10953859Sml29623 max_iteration++; 10963859Sml29623 ring_info->max_iterations = max_iteration + 1; 10973859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA2_CTL, 10986929Smisaki " nxge_rxbuf_index_info_init Find max iter %d", 10996929Smisaki ring_info->max_iterations)); 11003859Sml29623 11013859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_rxbuf_index_info_init")); 11023859Sml29623 return (NXGE_OK); 11033859Sml29623 } 11043859Sml29623 11053859Sml29623 /* ARGSUSED */ 11063859Sml29623 void 11073859Sml29623 nxge_dump_rcr_entry(p_nxge_t nxgep, p_rcr_entry_t entry_p) 11083859Sml29623 { 11093859Sml29623 #ifdef NXGE_DEBUG 11103859Sml29623 11113859Sml29623 uint32_t bptr; 11123859Sml29623 uint64_t pp; 11133859Sml29623 11143859Sml29623 bptr = entry_p->bits.hdw.pkt_buf_addr; 11153859Sml29623 11163859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 11176929Smisaki "\trcr entry $%p " 11186929Smisaki "\trcr entry 0x%0llx " 11196929Smisaki "\trcr entry 0x%08x " 11206929Smisaki "\trcr entry 0x%08x " 11216929Smisaki "\tvalue 0x%0llx\n" 11226929Smisaki "\tmulti = %d\n" 11236929Smisaki "\tpkt_type = 0x%x\n" 11246929Smisaki "\tzero_copy = %d\n" 11256929Smisaki "\tnoport = %d\n" 11266929Smisaki "\tpromis = %d\n" 11276929Smisaki "\terror = 0x%04x\n" 11286929Smisaki "\tdcf_err = 0x%01x\n" 11296929Smisaki "\tl2_len = %d\n" 11306929Smisaki "\tpktbufsize = %d\n" 11316929Smisaki "\tpkt_buf_addr = $%p\n" 11326929Smisaki "\tpkt_buf_addr (<< 6) = $%p\n", 11336929Smisaki entry_p, 11346929Smisaki *(int64_t *)entry_p, 11356929Smisaki *(int32_t *)entry_p, 11366929Smisaki *(int32_t *)((char *)entry_p + 32), 11376929Smisaki entry_p->value, 11386929Smisaki entry_p->bits.hdw.multi, 11396929Smisaki entry_p->bits.hdw.pkt_type, 11406929Smisaki entry_p->bits.hdw.zero_copy, 11416929Smisaki entry_p->bits.hdw.noport, 11426929Smisaki entry_p->bits.hdw.promis, 11436929Smisaki entry_p->bits.hdw.error, 11446929Smisaki entry_p->bits.hdw.dcf_err, 11456929Smisaki entry_p->bits.hdw.l2_len, 11466929Smisaki entry_p->bits.hdw.pktbufsz, 11476929Smisaki bptr, 11486929Smisaki entry_p->bits.ldw.pkt_buf_addr)); 11493859Sml29623 11503859Sml29623 pp = (entry_p->value & RCR_PKT_BUF_ADDR_MASK) << 11516929Smisaki RCR_PKT_BUF_ADDR_SHIFT; 11523859Sml29623 11533859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "rcr pp 0x%llx l2 len %d", 11546929Smisaki pp, (*(int64_t *)entry_p >> 40) & 0x3fff)); 11553859Sml29623 #endif 11563859Sml29623 } 11573859Sml29623 11583859Sml29623 void 11593859Sml29623 nxge_rxdma_regs_dump(p_nxge_t nxgep, int rdc) 11603859Sml29623 { 11613859Sml29623 npi_handle_t handle; 11623859Sml29623 rbr_stat_t rbr_stat; 11633859Sml29623 addr44_t hd_addr; 11643859Sml29623 addr44_t tail_addr; 11653859Sml29623 uint16_t qlen; 11663859Sml29623 11673859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 11686929Smisaki "==> nxge_rxdma_regs_dump: rdc channel %d", rdc)); 11693859Sml29623 11703859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 11713859Sml29623 11723859Sml29623 /* RBR head */ 11733859Sml29623 hd_addr.addr = 0; 11743859Sml29623 (void) npi_rxdma_rdc_rbr_head_get(handle, rdc, &hd_addr); 11755165Syc148097 #if defined(__i386) 11763859Sml29623 printf("nxge_rxdma_regs_dump: got hdptr $%p \n", 11776929Smisaki (void *)(uint32_t)hd_addr.addr); 11785125Sjoycey #else 11795165Syc148097 printf("nxge_rxdma_regs_dump: got hdptr $%p \n", 11806929Smisaki (void *)hd_addr.addr); 11815125Sjoycey #endif 11823859Sml29623 11833859Sml29623 /* RBR stats */ 11843859Sml29623 (void) npi_rxdma_rdc_rbr_stat_get(handle, rdc, &rbr_stat); 11853859Sml29623 printf("nxge_rxdma_regs_dump: rbr len %d \n", rbr_stat.bits.ldw.qlen); 11863859Sml29623 11873859Sml29623 /* RCR tail */ 11883859Sml29623 tail_addr.addr = 0; 11893859Sml29623 (void) npi_rxdma_rdc_rcr_tail_get(handle, rdc, &tail_addr); 11905165Syc148097 #if defined(__i386) 11913859Sml29623 printf("nxge_rxdma_regs_dump: got tail ptr $%p \n", 11926929Smisaki (void *)(uint32_t)tail_addr.addr); 11935125Sjoycey #else 11945165Syc148097 printf("nxge_rxdma_regs_dump: got tail ptr $%p \n", 11956929Smisaki (void *)tail_addr.addr); 11965125Sjoycey #endif 11973859Sml29623 11983859Sml29623 /* RCR qlen */ 11993859Sml29623 (void) npi_rxdma_rdc_rcr_qlen_get(handle, rdc, &qlen); 12003859Sml29623 printf("nxge_rxdma_regs_dump: rcr len %x \n", qlen); 12013859Sml29623 12023859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 12036929Smisaki "<== nxge_rxdma_regs_dump: rdc rdc %d", rdc)); 12043859Sml29623 } 12053859Sml29623 12063859Sml29623 nxge_status_t 12073859Sml29623 nxge_rxdma_hw_mode(p_nxge_t nxgep, boolean_t enable) 12083859Sml29623 { 12096495Sspeer nxge_grp_set_t *set = &nxgep->rx_set; 12106495Sspeer nxge_status_t status; 12116495Sspeer npi_status_t rs; 12126495Sspeer int rdc; 12133859Sml29623 12143859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 12156929Smisaki "==> nxge_rxdma_hw_mode: mode %d", enable)); 12163859Sml29623 12173859Sml29623 if (!(nxgep->drv_state & STATE_HW_INITIALIZED)) { 12183859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 12196495Sspeer "<== nxge_rxdma_mode: not initialized")); 12203859Sml29623 return (NXGE_ERROR); 12213859Sml29623 } 12226495Sspeer 12236495Sspeer if (nxgep->rx_rbr_rings == 0 || nxgep->rx_rbr_rings->rbr_rings == 0) { 12246495Sspeer NXGE_DEBUG_MSG((nxgep, TX_CTL, 12256495Sspeer "<== nxge_tx_port_fatal_err_recover: " 12266495Sspeer "NULL ring pointer(s)")); 12273859Sml29623 return (NXGE_ERROR); 12283859Sml29623 } 12293859Sml29623 12306495Sspeer if (set->owned.map == 0) { 12316495Sspeer NXGE_DEBUG_MSG((nxgep, RX_CTL, 12326495Sspeer "nxge_rxdma_regs_dump_channels: no channels")); 12336495Sspeer return (NULL); 12346495Sspeer } 12356495Sspeer 12366495Sspeer for (rdc = 0; rdc < NXGE_MAX_RDCS; rdc++) { 12376495Sspeer if ((1 << rdc) & set->owned.map) { 12386495Sspeer rx_rbr_ring_t *ring = 12396495Sspeer nxgep->rx_rbr_rings->rbr_rings[rdc]; 12406495Sspeer npi_handle_t handle = NXGE_DEV_NPI_HANDLE(nxgep); 12416495Sspeer if (ring) { 12426495Sspeer if (enable) { 12436495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 12446495Sspeer "==> nxge_rxdma_hw_mode: " 12456495Sspeer "channel %d (enable)", rdc)); 12466495Sspeer rs = npi_rxdma_cfg_rdc_enable 12476495Sspeer (handle, rdc); 12486495Sspeer } else { 12496495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 12506495Sspeer "==> nxge_rxdma_hw_mode: " 12516495Sspeer "channel %d disable)", rdc)); 12526495Sspeer rs = npi_rxdma_cfg_rdc_disable 12536495Sspeer (handle, rdc); 12546495Sspeer } 12556495Sspeer } 12563859Sml29623 } 12573859Sml29623 } 12583859Sml29623 12593859Sml29623 status = ((rs == NPI_SUCCESS) ? NXGE_OK : NXGE_ERROR | rs); 12603859Sml29623 12613859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 12626929Smisaki "<== nxge_rxdma_hw_mode: status 0x%x", status)); 12633859Sml29623 12643859Sml29623 return (status); 12653859Sml29623 } 12663859Sml29623 12673859Sml29623 void 12683859Sml29623 nxge_rxdma_enable_channel(p_nxge_t nxgep, uint16_t channel) 12693859Sml29623 { 12703859Sml29623 npi_handle_t handle; 12713859Sml29623 12723859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, 12736929Smisaki "==> nxge_rxdma_enable_channel: channel %d", channel)); 12743859Sml29623 12753859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 12763859Sml29623 (void) npi_rxdma_cfg_rdc_enable(handle, channel); 12773859Sml29623 12783859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_rxdma_enable_channel")); 12793859Sml29623 } 12803859Sml29623 12813859Sml29623 void 12823859Sml29623 nxge_rxdma_disable_channel(p_nxge_t nxgep, uint16_t channel) 12833859Sml29623 { 12843859Sml29623 npi_handle_t handle; 12853859Sml29623 12863859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, 12876929Smisaki "==> nxge_rxdma_disable_channel: channel %d", channel)); 12883859Sml29623 12893859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 12903859Sml29623 (void) npi_rxdma_cfg_rdc_disable(handle, channel); 12913859Sml29623 12923859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_rxdma_disable_channel")); 12933859Sml29623 } 12943859Sml29623 12953859Sml29623 void 12963859Sml29623 nxge_hw_start_rx(p_nxge_t nxgep) 12973859Sml29623 { 12983859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_hw_start_rx")); 12993859Sml29623 13003859Sml29623 (void) nxge_rxdma_hw_mode(nxgep, NXGE_DMA_START); 13013859Sml29623 (void) nxge_rx_mac_enable(nxgep); 13023859Sml29623 13033859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_hw_start_rx")); 13043859Sml29623 } 13053859Sml29623 13063859Sml29623 /*ARGSUSED*/ 13073859Sml29623 void 13083859Sml29623 nxge_fixup_rxdma_rings(p_nxge_t nxgep) 13093859Sml29623 { 13106495Sspeer nxge_grp_set_t *set = &nxgep->rx_set; 13116495Sspeer int rdc; 13123859Sml29623 13133859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_fixup_rxdma_rings")); 13143859Sml29623 13156495Sspeer if (nxgep->rx_rbr_rings == 0 || nxgep->rx_rbr_rings->rbr_rings == 0) { 13166495Sspeer NXGE_DEBUG_MSG((nxgep, TX_CTL, 13176495Sspeer "<== nxge_tx_port_fatal_err_recover: " 13186495Sspeer "NULL ring pointer(s)")); 13193859Sml29623 return; 13203859Sml29623 } 13213859Sml29623 13226495Sspeer if (set->owned.map == 0) { 13233859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 13246495Sspeer "nxge_rxdma_regs_dump_channels: no channels")); 13253859Sml29623 return; 13263859Sml29623 } 13276495Sspeer 13286495Sspeer for (rdc = 0; rdc < NXGE_MAX_RDCS; rdc++) { 13296495Sspeer if ((1 << rdc) & set->owned.map) { 13306495Sspeer rx_rbr_ring_t *ring = 13316495Sspeer nxgep->rx_rbr_rings->rbr_rings[rdc]; 13326495Sspeer if (ring) { 13336495Sspeer nxge_rxdma_hw_stop(nxgep, rdc); 13346495Sspeer NXGE_DEBUG_MSG((nxgep, RX_CTL, 13356929Smisaki "==> nxge_fixup_rxdma_rings: " 13366929Smisaki "channel %d ring $%px", 13376929Smisaki rdc, ring)); 133810218SMichael.Speer@Sun.COM (void) nxge_rxdma_fix_channel(nxgep, rdc); 13396495Sspeer } 13406495Sspeer } 13413859Sml29623 } 13423859Sml29623 13433859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_fixup_rxdma_rings")); 13443859Sml29623 } 13453859Sml29623 13463859Sml29623 void 13473859Sml29623 nxge_rxdma_fix_channel(p_nxge_t nxgep, uint16_t channel) 13483859Sml29623 { 13493859Sml29623 int ndmas; 13503859Sml29623 p_rx_rbr_rings_t rx_rbr_rings; 13513859Sml29623 p_rx_rbr_ring_t *rbr_rings; 13523859Sml29623 p_rx_rcr_rings_t rx_rcr_rings; 13533859Sml29623 p_rx_rcr_ring_t *rcr_rings; 13543859Sml29623 p_rx_mbox_areas_t rx_mbox_areas_p; 13553859Sml29623 p_rx_mbox_t *rx_mbox_p; 13563859Sml29623 p_nxge_dma_pool_t dma_buf_poolp; 13573859Sml29623 p_nxge_dma_pool_t dma_cntl_poolp; 13583859Sml29623 p_rx_rbr_ring_t rbrp; 13593859Sml29623 p_rx_rcr_ring_t rcrp; 13603859Sml29623 p_rx_mbox_t mboxp; 13613859Sml29623 p_nxge_dma_common_t dmap; 13623859Sml29623 nxge_status_t status = NXGE_OK; 13633859Sml29623 136410218SMichael.Speer@Sun.COM NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rxdma_fix_channel")); 13653859Sml29623 13663859Sml29623 (void) nxge_rxdma_stop_channel(nxgep, channel); 13673859Sml29623 13683859Sml29623 dma_buf_poolp = nxgep->rx_buf_pool_p; 13693859Sml29623 dma_cntl_poolp = nxgep->rx_cntl_pool_p; 13703859Sml29623 13713859Sml29623 if (!dma_buf_poolp->buf_allocated || !dma_cntl_poolp->buf_allocated) { 13723859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 137310218SMichael.Speer@Sun.COM "<== nxge_rxdma_fix_channel: buf not allocated")); 13743859Sml29623 return; 13753859Sml29623 } 13763859Sml29623 13773859Sml29623 ndmas = dma_buf_poolp->ndmas; 13783859Sml29623 if (!ndmas) { 13793859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 138010218SMichael.Speer@Sun.COM "<== nxge_rxdma_fix_channel: no dma allocated")); 13813859Sml29623 return; 13823859Sml29623 } 13833859Sml29623 13843859Sml29623 rx_rbr_rings = nxgep->rx_rbr_rings; 13853859Sml29623 rx_rcr_rings = nxgep->rx_rcr_rings; 13863859Sml29623 rbr_rings = rx_rbr_rings->rbr_rings; 13873859Sml29623 rcr_rings = rx_rcr_rings->rcr_rings; 13883859Sml29623 rx_mbox_areas_p = nxgep->rx_mbox_areas_p; 13893859Sml29623 rx_mbox_p = rx_mbox_areas_p->rxmbox_areas; 13903859Sml29623 13913859Sml29623 /* Reinitialize the receive block and completion rings */ 139210218SMichael.Speer@Sun.COM rbrp = (p_rx_rbr_ring_t)rbr_rings[channel], 139310218SMichael.Speer@Sun.COM rcrp = (p_rx_rcr_ring_t)rcr_rings[channel], 139410218SMichael.Speer@Sun.COM mboxp = (p_rx_mbox_t)rx_mbox_p[channel]; 13953859Sml29623 13963859Sml29623 rbrp->rbr_wr_index = (rbrp->rbb_max - 1); 13973859Sml29623 rbrp->rbr_rd_index = 0; 13983859Sml29623 rcrp->comp_rd_index = 0; 13993859Sml29623 rcrp->comp_wt_index = 0; 14003859Sml29623 14013859Sml29623 dmap = (p_nxge_dma_common_t)&rcrp->rcr_desc; 14023859Sml29623 bzero((caddr_t)dmap->kaddrp, dmap->alength); 14033859Sml29623 14043859Sml29623 status = nxge_rxdma_start_channel(nxgep, channel, 14056929Smisaki rbrp, rcrp, mboxp); 14063859Sml29623 if (status != NXGE_OK) { 140710218SMichael.Speer@Sun.COM goto nxge_rxdma_fix_channel_fail; 14088275SEric Cheng } 14098275SEric Cheng 14108275SEric Cheng NXGE_DEBUG_MSG((nxgep, RX_CTL, 141110218SMichael.Speer@Sun.COM "<== nxge_rxdma_fix_channel: success (0x%08x)", status)); 141210218SMichael.Speer@Sun.COM return; 141310218SMichael.Speer@Sun.COM 141410218SMichael.Speer@Sun.COM nxge_rxdma_fix_channel_fail: 14158275SEric Cheng NXGE_DEBUG_MSG((nxgep, RX_CTL, 141610218SMichael.Speer@Sun.COM "<== nxge_rxdma_fix_channel: failed (0x%08x)", status)); 14173859Sml29623 } 14183859Sml29623 14193859Sml29623 p_rx_rbr_ring_t 14203859Sml29623 nxge_rxdma_get_rbr_ring(p_nxge_t nxgep, uint16_t channel) 14213859Sml29623 { 14226495Sspeer nxge_grp_set_t *set = &nxgep->rx_set; 14236495Sspeer nxge_channel_t rdc; 14243859Sml29623 14253859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 14266929Smisaki "==> nxge_rxdma_get_rbr_ring: channel %d", channel)); 14273859Sml29623 14286495Sspeer if (nxgep->rx_rbr_rings == 0 || nxgep->rx_rbr_rings->rbr_rings == 0) { 14296495Sspeer NXGE_DEBUG_MSG((nxgep, TX_CTL, 14306495Sspeer "<== nxge_rxdma_get_rbr_ring: " 14316495Sspeer "NULL ring pointer(s)")); 14323859Sml29623 return (NULL); 14333859Sml29623 } 14346495Sspeer 14356495Sspeer if (set->owned.map == 0) { 14363859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 14376495Sspeer "<== nxge_rxdma_get_rbr_ring: no channels")); 14383859Sml29623 return (NULL); 14393859Sml29623 } 14403859Sml29623 14416495Sspeer for (rdc = 0; rdc < NXGE_MAX_RDCS; rdc++) { 14426495Sspeer if ((1 << rdc) & set->owned.map) { 14436495Sspeer rx_rbr_ring_t *ring = 14446495Sspeer nxgep->rx_rbr_rings->rbr_rings[rdc]; 14456495Sspeer if (ring) { 14466495Sspeer if (channel == ring->rdc) { 14476495Sspeer NXGE_DEBUG_MSG((nxgep, RX_CTL, 14486495Sspeer "==> nxge_rxdma_get_rbr_ring: " 14496495Sspeer "channel %d ring $%p", rdc, ring)); 14506495Sspeer return (ring); 14516495Sspeer } 14526495Sspeer } 14533859Sml29623 } 14543859Sml29623 } 14553859Sml29623 14563859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 14576929Smisaki "<== nxge_rxdma_get_rbr_ring: not found")); 14583859Sml29623 14593859Sml29623 return (NULL); 14603859Sml29623 } 14613859Sml29623 14623859Sml29623 p_rx_rcr_ring_t 14633859Sml29623 nxge_rxdma_get_rcr_ring(p_nxge_t nxgep, uint16_t channel) 14643859Sml29623 { 14656495Sspeer nxge_grp_set_t *set = &nxgep->rx_set; 14666495Sspeer nxge_channel_t rdc; 14673859Sml29623 14683859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 14696929Smisaki "==> nxge_rxdma_get_rcr_ring: channel %d", channel)); 14703859Sml29623 14716495Sspeer if (nxgep->rx_rcr_rings == 0 || nxgep->rx_rcr_rings->rcr_rings == 0) { 14726495Sspeer NXGE_DEBUG_MSG((nxgep, TX_CTL, 14736495Sspeer "<== nxge_rxdma_get_rcr_ring: " 14746495Sspeer "NULL ring pointer(s)")); 14753859Sml29623 return (NULL); 14763859Sml29623 } 14776495Sspeer 14786495Sspeer if (set->owned.map == 0) { 14793859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 14806495Sspeer "<== nxge_rxdma_get_rbr_ring: no channels")); 14813859Sml29623 return (NULL); 14823859Sml29623 } 14833859Sml29623 14846495Sspeer for (rdc = 0; rdc < NXGE_MAX_RDCS; rdc++) { 14856495Sspeer if ((1 << rdc) & set->owned.map) { 14866495Sspeer rx_rcr_ring_t *ring = 14876495Sspeer nxgep->rx_rcr_rings->rcr_rings[rdc]; 14886495Sspeer if (ring) { 14896495Sspeer if (channel == ring->rdc) { 14906495Sspeer NXGE_DEBUG_MSG((nxgep, RX_CTL, 14916495Sspeer "==> nxge_rxdma_get_rcr_ring: " 14926495Sspeer "channel %d ring $%p", rdc, ring)); 14936495Sspeer return (ring); 14946495Sspeer } 14956495Sspeer } 14963859Sml29623 } 14973859Sml29623 } 14983859Sml29623 14993859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 15006929Smisaki "<== nxge_rxdma_get_rcr_ring: not found")); 15013859Sml29623 15023859Sml29623 return (NULL); 15033859Sml29623 } 15043859Sml29623 15053859Sml29623 /* 15063859Sml29623 * Static functions start here. 15073859Sml29623 */ 15083859Sml29623 static p_rx_msg_t 15093859Sml29623 nxge_allocb(size_t size, uint32_t pri, p_nxge_dma_common_t dmabuf_p) 15103859Sml29623 { 15113859Sml29623 p_rx_msg_t nxge_mp = NULL; 15123859Sml29623 p_nxge_dma_common_t dmamsg_p; 15133859Sml29623 uchar_t *buffer; 15143859Sml29623 15153859Sml29623 nxge_mp = KMEM_ZALLOC(sizeof (rx_msg_t), KM_NOSLEEP); 15163859Sml29623 if (nxge_mp == NULL) { 15174185Sspeer NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL, 15186929Smisaki "Allocation of a rx msg failed.")); 15193859Sml29623 goto nxge_allocb_exit; 15203859Sml29623 } 15213859Sml29623 15223859Sml29623 nxge_mp->use_buf_pool = B_FALSE; 15233859Sml29623 if (dmabuf_p) { 15243859Sml29623 nxge_mp->use_buf_pool = B_TRUE; 15253859Sml29623 dmamsg_p = (p_nxge_dma_common_t)&nxge_mp->buf_dma; 15263859Sml29623 *dmamsg_p = *dmabuf_p; 15273859Sml29623 dmamsg_p->nblocks = 1; 15283859Sml29623 dmamsg_p->block_size = size; 15293859Sml29623 dmamsg_p->alength = size; 15303859Sml29623 buffer = (uchar_t *)dmabuf_p->kaddrp; 15313859Sml29623 15323859Sml29623 dmabuf_p->kaddrp = (void *) 15336929Smisaki ((char *)dmabuf_p->kaddrp + size); 15343859Sml29623 dmabuf_p->ioaddr_pp = (void *) 15356929Smisaki ((char *)dmabuf_p->ioaddr_pp + size); 15363859Sml29623 dmabuf_p->alength -= size; 15373859Sml29623 dmabuf_p->offset += size; 15383859Sml29623 dmabuf_p->dma_cookie.dmac_laddress += size; 15393859Sml29623 dmabuf_p->dma_cookie.dmac_size -= size; 15403859Sml29623 15413859Sml29623 } else { 15423859Sml29623 buffer = KMEM_ALLOC(size, KM_NOSLEEP); 15433859Sml29623 if (buffer == NULL) { 15444185Sspeer NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL, 15456929Smisaki "Allocation of a receive page failed.")); 15463859Sml29623 goto nxge_allocb_fail1; 15473859Sml29623 } 15483859Sml29623 } 15493859Sml29623 15503859Sml29623 nxge_mp->rx_mblk_p = desballoc(buffer, size, pri, &nxge_mp->freeb); 15513859Sml29623 if (nxge_mp->rx_mblk_p == NULL) { 15524185Sspeer NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL, "desballoc failed.")); 15533859Sml29623 goto nxge_allocb_fail2; 15543859Sml29623 } 15553859Sml29623 15563859Sml29623 nxge_mp->buffer = buffer; 15573859Sml29623 nxge_mp->block_size = size; 15583859Sml29623 nxge_mp->freeb.free_func = (void (*)())nxge_freeb; 15593859Sml29623 nxge_mp->freeb.free_arg = (caddr_t)nxge_mp; 15603859Sml29623 nxge_mp->ref_cnt = 1; 15613859Sml29623 nxge_mp->free = B_TRUE; 15623859Sml29623 nxge_mp->rx_use_bcopy = B_FALSE; 15633859Sml29623 15643859Sml29623 atomic_inc_32(&nxge_mblks_pending); 15653859Sml29623 15663859Sml29623 goto nxge_allocb_exit; 15673859Sml29623 15683859Sml29623 nxge_allocb_fail2: 15693859Sml29623 if (!nxge_mp->use_buf_pool) { 15703859Sml29623 KMEM_FREE(buffer, size); 15713859Sml29623 } 15723859Sml29623 15733859Sml29623 nxge_allocb_fail1: 15743859Sml29623 KMEM_FREE(nxge_mp, sizeof (rx_msg_t)); 15753859Sml29623 nxge_mp = NULL; 15763859Sml29623 15773859Sml29623 nxge_allocb_exit: 15783859Sml29623 return (nxge_mp); 15793859Sml29623 } 15803859Sml29623 15813859Sml29623 p_mblk_t 15823859Sml29623 nxge_dupb(p_rx_msg_t nxge_mp, uint_t offset, size_t size) 15833859Sml29623 { 15843859Sml29623 p_mblk_t mp; 15853859Sml29623 15863859Sml29623 NXGE_DEBUG_MSG((NULL, MEM_CTL, "==> nxge_dupb")); 15873859Sml29623 NXGE_DEBUG_MSG((NULL, MEM_CTL, "nxge_mp = $%p " 15886929Smisaki "offset = 0x%08X " 15896929Smisaki "size = 0x%08X", 15906929Smisaki nxge_mp, offset, size)); 15913859Sml29623 15923859Sml29623 mp = desballoc(&nxge_mp->buffer[offset], size, 15936929Smisaki 0, &nxge_mp->freeb); 15943859Sml29623 if (mp == NULL) { 15953859Sml29623 NXGE_DEBUG_MSG((NULL, RX_CTL, "desballoc failed")); 15963859Sml29623 goto nxge_dupb_exit; 15973859Sml29623 } 15983859Sml29623 atomic_inc_32(&nxge_mp->ref_cnt); 15993859Sml29623 16003859Sml29623 16013859Sml29623 nxge_dupb_exit: 16023859Sml29623 NXGE_DEBUG_MSG((NULL, MEM_CTL, "<== nxge_dupb mp = $%p", 16036929Smisaki nxge_mp)); 16043859Sml29623 return (mp); 16053859Sml29623 } 16063859Sml29623 16073859Sml29623 p_mblk_t 16083859Sml29623 nxge_dupb_bcopy(p_rx_msg_t nxge_mp, uint_t offset, size_t size) 16093859Sml29623 { 16103859Sml29623 p_mblk_t mp; 16113859Sml29623 uchar_t *dp; 16123859Sml29623 16133859Sml29623 mp = allocb(size + NXGE_RXBUF_EXTRA, 0); 16143859Sml29623 if (mp == NULL) { 16153859Sml29623 NXGE_DEBUG_MSG((NULL, RX_CTL, "desballoc failed")); 16163859Sml29623 goto nxge_dupb_bcopy_exit; 16173859Sml29623 } 16183859Sml29623 dp = mp->b_rptr = mp->b_rptr + NXGE_RXBUF_EXTRA; 16193859Sml29623 bcopy((void *)&nxge_mp->buffer[offset], dp, size); 16203859Sml29623 mp->b_wptr = dp + size; 16213859Sml29623 16223859Sml29623 nxge_dupb_bcopy_exit: 16233859Sml29623 NXGE_DEBUG_MSG((NULL, MEM_CTL, "<== nxge_dupb mp = $%p", 16246929Smisaki nxge_mp)); 16253859Sml29623 return (mp); 16263859Sml29623 } 16273859Sml29623 16283859Sml29623 void nxge_post_page(p_nxge_t nxgep, p_rx_rbr_ring_t rx_rbr_p, 16293859Sml29623 p_rx_msg_t rx_msg_p); 16303859Sml29623 16313859Sml29623 void 16323859Sml29623 nxge_post_page(p_nxge_t nxgep, p_rx_rbr_ring_t rx_rbr_p, p_rx_msg_t rx_msg_p) 16333859Sml29623 { 16343859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_post_page")); 16353859Sml29623 16363859Sml29623 /* Reuse this buffer */ 16373859Sml29623 rx_msg_p->free = B_FALSE; 16383859Sml29623 rx_msg_p->cur_usage_cnt = 0; 16393859Sml29623 rx_msg_p->max_usage_cnt = 0; 16403859Sml29623 rx_msg_p->pkt_buf_size = 0; 16413859Sml29623 16423859Sml29623 if (rx_rbr_p->rbr_use_bcopy) { 16433859Sml29623 rx_msg_p->rx_use_bcopy = B_FALSE; 16443859Sml29623 atomic_dec_32(&rx_rbr_p->rbr_consumed); 16453859Sml29623 } 16463859Sml29623 16473859Sml29623 /* 16483859Sml29623 * Get the rbr header pointer and its offset index. 16493859Sml29623 */ 16503859Sml29623 MUTEX_ENTER(&rx_rbr_p->post_lock); 16513859Sml29623 rx_rbr_p->rbr_wr_index = ((rx_rbr_p->rbr_wr_index + 1) & 16526929Smisaki rx_rbr_p->rbr_wrap_mask); 16533859Sml29623 rx_rbr_p->rbr_desc_vp[rx_rbr_p->rbr_wr_index] = rx_msg_p->shifted_addr; 16543859Sml29623 MUTEX_EXIT(&rx_rbr_p->post_lock); 16555770Sml29623 npi_rxdma_rdc_rbr_kick(NXGE_DEV_NPI_HANDLE(nxgep), 16565770Sml29623 rx_rbr_p->rdc, 1); 16573859Sml29623 16583859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 16596929Smisaki "<== nxge_post_page (channel %d post_next_index %d)", 16606929Smisaki rx_rbr_p->rdc, rx_rbr_p->rbr_wr_index)); 16613859Sml29623 16623859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_post_page")); 16633859Sml29623 } 16643859Sml29623 16653859Sml29623 void 16663859Sml29623 nxge_freeb(p_rx_msg_t rx_msg_p) 16673859Sml29623 { 16683859Sml29623 size_t size; 16693859Sml29623 uchar_t *buffer = NULL; 16703859Sml29623 int ref_cnt; 16714874Sml29623 boolean_t free_state = B_FALSE; 16723859Sml29623 16735170Stm144005 rx_rbr_ring_t *ring = rx_msg_p->rx_rbr_p; 16745170Stm144005 16753859Sml29623 NXGE_DEBUG_MSG((NULL, MEM2_CTL, "==> nxge_freeb")); 16763859Sml29623 NXGE_DEBUG_MSG((NULL, MEM2_CTL, 16776929Smisaki "nxge_freeb:rx_msg_p = $%p (block pending %d)", 16786929Smisaki rx_msg_p, nxge_mblks_pending)); 16793859Sml29623 16804874Sml29623 /* 16814874Sml29623 * First we need to get the free state, then 16824874Sml29623 * atomic decrement the reference count to prevent 16834874Sml29623 * the race condition with the interrupt thread that 16844874Sml29623 * is processing a loaned up buffer block. 16854874Sml29623 */ 16864874Sml29623 free_state = rx_msg_p->free; 16873859Sml29623 ref_cnt = atomic_add_32_nv(&rx_msg_p->ref_cnt, -1); 16883859Sml29623 if (!ref_cnt) { 16895770Sml29623 atomic_dec_32(&nxge_mblks_pending); 16903859Sml29623 buffer = rx_msg_p->buffer; 16913859Sml29623 size = rx_msg_p->block_size; 16923859Sml29623 NXGE_DEBUG_MSG((NULL, MEM2_CTL, "nxge_freeb: " 16936929Smisaki "will free: rx_msg_p = $%p (block pending %d)", 16946929Smisaki rx_msg_p, nxge_mblks_pending)); 16953859Sml29623 16963859Sml29623 if (!rx_msg_p->use_buf_pool) { 16973859Sml29623 KMEM_FREE(buffer, size); 16983859Sml29623 } 16993859Sml29623 17003859Sml29623 KMEM_FREE(rx_msg_p, sizeof (rx_msg_t)); 17015170Stm144005 17025759Smisaki if (ring) { 17035759Smisaki /* 17045759Smisaki * Decrement the receive buffer ring's reference 17055759Smisaki * count, too. 17065759Smisaki */ 17075759Smisaki atomic_dec_32(&ring->rbr_ref_cnt); 17085759Smisaki 17095759Smisaki /* 17106495Sspeer * Free the receive buffer ring, if 17115759Smisaki * 1. all the receive buffers have been freed 17125759Smisaki * 2. and we are in the proper state (that is, 17135759Smisaki * we are not UNMAPPING). 17145759Smisaki */ 17155759Smisaki if (ring->rbr_ref_cnt == 0 && 17165759Smisaki ring->rbr_state == RBR_UNMAPPED) { 17176495Sspeer /* 17186495Sspeer * Free receive data buffers, 17196495Sspeer * buffer index information 17206495Sspeer * (rxring_info) and 17216495Sspeer * the message block ring. 17226495Sspeer */ 17236495Sspeer NXGE_DEBUG_MSG((NULL, RX_CTL, 17246495Sspeer "nxge_freeb:rx_msg_p = $%p " 17256495Sspeer "(block pending %d) free buffers", 17266495Sspeer rx_msg_p, nxge_mblks_pending)); 17276495Sspeer nxge_rxdma_databuf_free(ring); 17286495Sspeer if (ring->ring_info) { 17296495Sspeer KMEM_FREE(ring->ring_info, 17306495Sspeer sizeof (rxring_info_t)); 17316495Sspeer } 17326495Sspeer 17336495Sspeer if (ring->rx_msg_ring) { 17346495Sspeer KMEM_FREE(ring->rx_msg_ring, 17356495Sspeer ring->tnblocks * 17366495Sspeer sizeof (p_rx_msg_t)); 17376495Sspeer } 17385759Smisaki KMEM_FREE(ring, sizeof (*ring)); 17395759Smisaki } 17405170Stm144005 } 17413859Sml29623 return; 17423859Sml29623 } 17433859Sml29623 17443859Sml29623 /* 17453859Sml29623 * Repost buffer. 17463859Sml29623 */ 17475759Smisaki if (free_state && (ref_cnt == 1) && ring) { 17483859Sml29623 NXGE_DEBUG_MSG((NULL, RX_CTL, 17493859Sml29623 "nxge_freeb: post page $%p:", rx_msg_p)); 17505170Stm144005 if (ring->rbr_state == RBR_POSTING) 17515170Stm144005 nxge_post_page(rx_msg_p->nxgep, ring, rx_msg_p); 17523859Sml29623 } 17533859Sml29623 17543859Sml29623 NXGE_DEBUG_MSG((NULL, MEM2_CTL, "<== nxge_freeb")); 17553859Sml29623 } 17563859Sml29623 17573859Sml29623 uint_t 17583859Sml29623 nxge_rx_intr(void *arg1, void *arg2) 17593859Sml29623 { 17603859Sml29623 p_nxge_ldv_t ldvp = (p_nxge_ldv_t)arg1; 17613859Sml29623 p_nxge_t nxgep = (p_nxge_t)arg2; 17623859Sml29623 p_nxge_ldg_t ldgp; 17633859Sml29623 uint8_t channel; 17643859Sml29623 npi_handle_t handle; 17653859Sml29623 rx_dma_ctl_stat_t cs; 176610309SSriharsha.Basavapatna@Sun.COM p_rx_rcr_ring_t rcrp; 17679730SMichael.Speer@Sun.COM mblk_t *mp = NULL; 17683859Sml29623 17693859Sml29623 if (ldvp == NULL) { 17703859Sml29623 NXGE_DEBUG_MSG((NULL, INT_CTL, 17716929Smisaki "<== nxge_rx_intr: arg2 $%p arg1 $%p", 17726929Smisaki nxgep, ldvp)); 17733859Sml29623 return (DDI_INTR_CLAIMED); 17743859Sml29623 } 17753859Sml29623 17763859Sml29623 if (arg2 == NULL || (void *)ldvp->nxgep != arg2) { 17773859Sml29623 nxgep = ldvp->nxgep; 17783859Sml29623 } 17796602Sspeer 17806602Sspeer if ((!(nxgep->drv_state & STATE_HW_INITIALIZED)) || 17816602Sspeer (nxgep->nxge_mac_state != NXGE_MAC_STARTED)) { 17826602Sspeer NXGE_DEBUG_MSG((nxgep, INT_CTL, 17836602Sspeer "<== nxge_rx_intr: interface not started or intialized")); 17846602Sspeer return (DDI_INTR_CLAIMED); 17856602Sspeer } 17866602Sspeer 17873859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 17886929Smisaki "==> nxge_rx_intr: arg2 $%p arg1 $%p", 17896929Smisaki nxgep, ldvp)); 17903859Sml29623 17913859Sml29623 /* 17929232SMichael.Speer@Sun.COM * Get the PIO handle. 17933859Sml29623 */ 17943859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 17958275SEric Cheng 17969232SMichael.Speer@Sun.COM /* 17979232SMichael.Speer@Sun.COM * Get the ring to enable us to process packets. 17989232SMichael.Speer@Sun.COM */ 179910309SSriharsha.Basavapatna@Sun.COM rcrp = nxgep->rx_rcr_rings->rcr_rings[ldvp->vdma_index]; 18008275SEric Cheng 18018275SEric Cheng /* 18028275SEric Cheng * The RCR ring lock must be held when packets 18038275SEric Cheng * are being processed and the hardware registers are 18048275SEric Cheng * being read or written to prevent race condition 18058275SEric Cheng * among the interrupt thread, the polling thread 18068275SEric Cheng * (will cause fatal errors such as rcrincon bit set) 18078275SEric Cheng * and the setting of the poll_flag. 18088275SEric Cheng */ 180910309SSriharsha.Basavapatna@Sun.COM MUTEX_ENTER(&rcrp->lock); 18108275SEric Cheng 18113859Sml29623 /* 18123859Sml29623 * Get the control and status for this channel. 18133859Sml29623 */ 18143859Sml29623 channel = ldvp->channel; 18153859Sml29623 ldgp = ldvp->ldgp; 18168275SEric Cheng 18179232SMichael.Speer@Sun.COM if (!isLDOMguest(nxgep) && (!nxgep->rx_channel_started[channel])) { 18189232SMichael.Speer@Sun.COM NXGE_DEBUG_MSG((nxgep, INT_CTL, 18199232SMichael.Speer@Sun.COM "<== nxge_rx_intr: channel is not started")); 18209232SMichael.Speer@Sun.COM 18219232SMichael.Speer@Sun.COM /* 18229232SMichael.Speer@Sun.COM * We received an interrupt before the ring is started. 18239232SMichael.Speer@Sun.COM */ 18249232SMichael.Speer@Sun.COM RXDMA_REG_READ64(handle, RX_DMA_CTL_STAT_REG, channel, 18259232SMichael.Speer@Sun.COM &cs.value); 18269232SMichael.Speer@Sun.COM cs.value &= RX_DMA_CTL_STAT_WR1C; 18279232SMichael.Speer@Sun.COM cs.bits.hdw.mex = 1; 18289232SMichael.Speer@Sun.COM RXDMA_REG_WRITE64(handle, RX_DMA_CTL_STAT_REG, channel, 18299232SMichael.Speer@Sun.COM cs.value); 18309232SMichael.Speer@Sun.COM 18319232SMichael.Speer@Sun.COM /* 18329232SMichael.Speer@Sun.COM * Rearm this logical group if this is a single device 18339232SMichael.Speer@Sun.COM * group. 18349232SMichael.Speer@Sun.COM */ 18359232SMichael.Speer@Sun.COM if (ldgp->nldvs == 1) { 18369232SMichael.Speer@Sun.COM if (isLDOMguest(nxgep)) { 18379232SMichael.Speer@Sun.COM nxge_hio_ldgimgn(nxgep, ldgp); 18389232SMichael.Speer@Sun.COM } else { 18399232SMichael.Speer@Sun.COM ldgimgm_t mgm; 18409232SMichael.Speer@Sun.COM 18419232SMichael.Speer@Sun.COM mgm.value = 0; 18429232SMichael.Speer@Sun.COM mgm.bits.ldw.arm = 1; 18439232SMichael.Speer@Sun.COM mgm.bits.ldw.timer = ldgp->ldg_timer; 18449232SMichael.Speer@Sun.COM 18459232SMichael.Speer@Sun.COM NXGE_REG_WR64(handle, 18469232SMichael.Speer@Sun.COM LDGIMGN_REG + LDSV_OFFSET(ldgp->ldg), 18479232SMichael.Speer@Sun.COM mgm.value); 18489232SMichael.Speer@Sun.COM } 18498275SEric Cheng } 185010309SSriharsha.Basavapatna@Sun.COM MUTEX_EXIT(&rcrp->lock); 18519232SMichael.Speer@Sun.COM return (DDI_INTR_CLAIMED); 18528275SEric Cheng } 18538275SEric Cheng 185410309SSriharsha.Basavapatna@Sun.COM ASSERT(rcrp->ldgp == ldgp); 185510309SSriharsha.Basavapatna@Sun.COM ASSERT(rcrp->ldvp == ldvp); 18568275SEric Cheng 18573859Sml29623 RXDMA_REG_READ64(handle, RX_DMA_CTL_STAT_REG, channel, &cs.value); 18583859Sml29623 18593859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rx_intr:channel %d " 18606929Smisaki "cs 0x%016llx rcrto 0x%x rcrthres %x", 18616929Smisaki channel, 18626929Smisaki cs.value, 18636929Smisaki cs.bits.hdw.rcrto, 18646929Smisaki cs.bits.hdw.rcrthres)); 18653859Sml29623 186610309SSriharsha.Basavapatna@Sun.COM if (!rcrp->poll_flag) { 186710309SSriharsha.Basavapatna@Sun.COM mp = nxge_rx_pkts(nxgep, rcrp, cs, -1); 18689730SMichael.Speer@Sun.COM } 18693859Sml29623 18703859Sml29623 /* error events. */ 18713859Sml29623 if (cs.value & RX_DMA_CTL_STAT_ERROR) { 18726495Sspeer (void) nxge_rx_err_evnts(nxgep, channel, cs); 18733859Sml29623 } 18743859Sml29623 18753859Sml29623 /* 18763859Sml29623 * Enable the mailbox update interrupt if we want 18773859Sml29623 * to use mailbox. We probably don't need to use 18783859Sml29623 * mailbox as it only saves us one pio read. 18793859Sml29623 * Also write 1 to rcrthres and rcrto to clear 18803859Sml29623 * these two edge triggered bits. 18813859Sml29623 */ 18823859Sml29623 cs.value &= RX_DMA_CTL_STAT_WR1C; 188310309SSriharsha.Basavapatna@Sun.COM cs.bits.hdw.mex = rcrp->poll_flag ? 0 : 1; 18843859Sml29623 RXDMA_REG_WRITE64(handle, RX_DMA_CTL_STAT_REG, channel, 18856929Smisaki cs.value); 18863859Sml29623 18873859Sml29623 /* 18888275SEric Cheng * If the polling mode is enabled, disable the interrupt. 18893859Sml29623 */ 189010309SSriharsha.Basavapatna@Sun.COM if (rcrp->poll_flag) { 18918275SEric Cheng NXGE_DEBUG_MSG((nxgep, NXGE_ERR_CTL, 18928275SEric Cheng "==> nxge_rx_intr: rdc %d ldgp $%p ldvp $%p " 18938275SEric Cheng "(disabling interrupts)", channel, ldgp, ldvp)); 189410309SSriharsha.Basavapatna@Sun.COM 18958275SEric Cheng /* 18968275SEric Cheng * Disarm this logical group if this is a single device 18978275SEric Cheng * group. 18988275SEric Cheng */ 18998275SEric Cheng if (ldgp->nldvs == 1) { 190010309SSriharsha.Basavapatna@Sun.COM if (isLDOMguest(nxgep)) { 190110309SSriharsha.Basavapatna@Sun.COM ldgp->arm = B_FALSE; 190210309SSriharsha.Basavapatna@Sun.COM nxge_hio_ldgimgn(nxgep, ldgp); 190310309SSriharsha.Basavapatna@Sun.COM } else { 190410309SSriharsha.Basavapatna@Sun.COM ldgimgm_t mgm; 190510309SSriharsha.Basavapatna@Sun.COM mgm.value = 0; 190610309SSriharsha.Basavapatna@Sun.COM mgm.bits.ldw.arm = 0; 190710309SSriharsha.Basavapatna@Sun.COM NXGE_REG_WR64(handle, 190810309SSriharsha.Basavapatna@Sun.COM LDGIMGN_REG + LDSV_OFFSET(ldgp->ldg), 190910309SSriharsha.Basavapatna@Sun.COM mgm.value); 191010309SSriharsha.Basavapatna@Sun.COM } 19116495Sspeer } 19128275SEric Cheng } else { 19138275SEric Cheng /* 19148400SNicolas.Droux@Sun.COM * Rearm this logical group if this is a single device 19158400SNicolas.Droux@Sun.COM * group. 19168275SEric Cheng */ 19178275SEric Cheng if (ldgp->nldvs == 1) { 19188275SEric Cheng if (isLDOMguest(nxgep)) { 19198275SEric Cheng nxge_hio_ldgimgn(nxgep, ldgp); 19208275SEric Cheng } else { 19218275SEric Cheng ldgimgm_t mgm; 19228275SEric Cheng 19238275SEric Cheng mgm.value = 0; 19248275SEric Cheng mgm.bits.ldw.arm = 1; 19258275SEric Cheng mgm.bits.ldw.timer = ldgp->ldg_timer; 19268275SEric Cheng 19278275SEric Cheng NXGE_REG_WR64(handle, 19288275SEric Cheng LDGIMGN_REG + LDSV_OFFSET(ldgp->ldg), 19298275SEric Cheng mgm.value); 19308275SEric Cheng } 19318275SEric Cheng } 19328275SEric Cheng 19338275SEric Cheng NXGE_DEBUG_MSG((nxgep, NXGE_ERR_CTL, 19348275SEric Cheng "==> nxge_rx_intr: rdc %d ldgp $%p " 19358275SEric Cheng "exiting ISR (and call mac_rx_ring)", channel, ldgp)); 19363859Sml29623 } 193710309SSriharsha.Basavapatna@Sun.COM MUTEX_EXIT(&rcrp->lock); 19388275SEric Cheng 19399730SMichael.Speer@Sun.COM if (mp != NULL) { 194010309SSriharsha.Basavapatna@Sun.COM mac_rx_ring(nxgep->mach, rcrp->rcr_mac_handle, mp, 194110309SSriharsha.Basavapatna@Sun.COM rcrp->rcr_gen_num); 19428275SEric Cheng } 19438275SEric Cheng NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_rx_intr: DDI_INTR_CLAIMED")); 19448275SEric Cheng return (DDI_INTR_CLAIMED); 19453859Sml29623 } 19463859Sml29623 19473859Sml29623 /* 19483859Sml29623 * This routine is the main packet receive processing function. 19493859Sml29623 * It gets the packet type, error code, and buffer related 19503859Sml29623 * information from the receive completion entry. 19513859Sml29623 * How many completion entries to process is based on the number of packets 19523859Sml29623 * queued by the hardware, a hardware maintained tail pointer 19533859Sml29623 * and a configurable receive packet count. 19543859Sml29623 * 19553859Sml29623 * A chain of message blocks will be created as result of processing 19563859Sml29623 * the completion entries. This chain of message blocks will be returned and 19573859Sml29623 * a hardware control status register will be updated with the number of 19583859Sml29623 * packets were removed from the hardware queue. 19593859Sml29623 * 19608275SEric Cheng * The RCR ring lock is held when entering this function. 19613859Sml29623 */ 19626495Sspeer static mblk_t * 19636495Sspeer nxge_rx_pkts(p_nxge_t nxgep, p_rx_rcr_ring_t rcr_p, rx_dma_ctl_stat_t cs, 19646495Sspeer int bytes_to_pickup) 19653859Sml29623 { 19663859Sml29623 npi_handle_t handle; 19673859Sml29623 uint8_t channel; 19683859Sml29623 uint32_t comp_rd_index; 19693859Sml29623 p_rcr_entry_t rcr_desc_rd_head_p; 19703859Sml29623 p_rcr_entry_t rcr_desc_rd_head_pp; 19713859Sml29623 p_mblk_t nmp, mp_cont, head_mp, *tail_mp; 19723859Sml29623 uint16_t qlen, nrcr_read, npkt_read; 19736495Sspeer uint32_t qlen_hw; 19743859Sml29623 boolean_t multi; 19756495Sspeer rcrcfig_b_t rcr_cfg_b; 19766495Sspeer int totallen = 0; 19773859Sml29623 #if defined(_BIG_ENDIAN) 19783859Sml29623 npi_status_t rs = NPI_SUCCESS; 19793859Sml29623 #endif 19803859Sml29623 19818275SEric Cheng NXGE_DEBUG_MSG((nxgep, NXGE_ERR_CTL, "==> nxge_rx_pkts: " 19826929Smisaki "channel %d", rcr_p->rdc)); 19833859Sml29623 19843859Sml29623 if (!(nxgep->drv_state & STATE_HW_INITIALIZED)) { 19853859Sml29623 return (NULL); 19863859Sml29623 } 19873859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 19883859Sml29623 channel = rcr_p->rdc; 19893859Sml29623 19903859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 19916929Smisaki "==> nxge_rx_pkts: START: rcr channel %d " 19926929Smisaki "head_p $%p head_pp $%p index %d ", 19936929Smisaki channel, rcr_p->rcr_desc_rd_head_p, 19946929Smisaki rcr_p->rcr_desc_rd_head_pp, 19956929Smisaki rcr_p->comp_rd_index)); 19963859Sml29623 19973859Sml29623 19983859Sml29623 #if !defined(_BIG_ENDIAN) 19993859Sml29623 qlen = RXDMA_REG_READ32(handle, RCRSTAT_A_REG, channel) & 0xffff; 20003859Sml29623 #else 20013859Sml29623 rs = npi_rxdma_rdc_rcr_qlen_get(handle, channel, &qlen); 20023859Sml29623 if (rs != NPI_SUCCESS) { 20036495Sspeer NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rx_pkts: " 20043859Sml29623 "channel %d, get qlen failed 0x%08x", 20056929Smisaki channel, rs)); 20063859Sml29623 return (NULL); 20073859Sml29623 } 20083859Sml29623 #endif 20093859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rx_pkts:rcr channel %d " 20106929Smisaki "qlen %d", channel, qlen)); 20113859Sml29623 20123859Sml29623 20133859Sml29623 20143859Sml29623 if (!qlen) { 20158275SEric Cheng NXGE_DEBUG_MSG((nxgep, NXGE_ERR_CTL, 20166929Smisaki "==> nxge_rx_pkts:rcr channel %d " 20176929Smisaki "qlen %d (no pkts)", channel, qlen)); 20183859Sml29623 20193859Sml29623 return (NULL); 20203859Sml29623 } 20213859Sml29623 20223859Sml29623 comp_rd_index = rcr_p->comp_rd_index; 20233859Sml29623 20243859Sml29623 rcr_desc_rd_head_p = rcr_p->rcr_desc_rd_head_p; 20253859Sml29623 rcr_desc_rd_head_pp = rcr_p->rcr_desc_rd_head_pp; 20263859Sml29623 nrcr_read = npkt_read = 0; 20273859Sml29623 20283859Sml29623 /* 20293859Sml29623 * Number of packets queued 20303859Sml29623 * (The jumbo or multi packet will be counted as only one 20313859Sml29623 * packets and it may take up more than one completion entry). 20323859Sml29623 */ 20333859Sml29623 qlen_hw = (qlen < nxge_max_rx_pkts) ? 20346929Smisaki qlen : nxge_max_rx_pkts; 20353859Sml29623 head_mp = NULL; 20363859Sml29623 tail_mp = &head_mp; 20373859Sml29623 nmp = mp_cont = NULL; 20383859Sml29623 multi = B_FALSE; 20393859Sml29623 20403859Sml29623 while (qlen_hw) { 20413859Sml29623 20423859Sml29623 #ifdef NXGE_DEBUG 20433859Sml29623 nxge_dump_rcr_entry(nxgep, rcr_desc_rd_head_p); 20443859Sml29623 #endif 20453859Sml29623 /* 20463859Sml29623 * Process one completion ring entry. 20473859Sml29623 */ 20483859Sml29623 nxge_receive_packet(nxgep, 20496929Smisaki rcr_p, rcr_desc_rd_head_p, &multi, &nmp, &mp_cont); 20503859Sml29623 20513859Sml29623 /* 20523859Sml29623 * message chaining modes 20533859Sml29623 */ 20543859Sml29623 if (nmp) { 20553859Sml29623 nmp->b_next = NULL; 20563859Sml29623 if (!multi && !mp_cont) { /* frame fits a partition */ 20573859Sml29623 *tail_mp = nmp; 20583859Sml29623 tail_mp = &nmp->b_next; 20596495Sspeer totallen += MBLKL(nmp); 20603859Sml29623 nmp = NULL; 20613859Sml29623 } else if (multi && !mp_cont) { /* first segment */ 20623859Sml29623 *tail_mp = nmp; 20633859Sml29623 tail_mp = &nmp->b_cont; 20646495Sspeer totallen += MBLKL(nmp); 20653859Sml29623 } else if (multi && mp_cont) { /* mid of multi segs */ 20663859Sml29623 *tail_mp = mp_cont; 20673859Sml29623 tail_mp = &mp_cont->b_cont; 20686495Sspeer totallen += MBLKL(mp_cont); 20693859Sml29623 } else if (!multi && mp_cont) { /* last segment */ 20703859Sml29623 *tail_mp = mp_cont; 20713859Sml29623 tail_mp = &nmp->b_next; 20726495Sspeer totallen += MBLKL(mp_cont); 20733859Sml29623 nmp = NULL; 20743859Sml29623 } 20753859Sml29623 } 20763859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 20776929Smisaki "==> nxge_rx_pkts: loop: rcr channel %d " 20786929Smisaki "before updating: multi %d " 20796929Smisaki "nrcr_read %d " 20806929Smisaki "npk read %d " 20816929Smisaki "head_pp $%p index %d ", 20826929Smisaki channel, 20836929Smisaki multi, 20846929Smisaki nrcr_read, npkt_read, rcr_desc_rd_head_pp, 20856929Smisaki comp_rd_index)); 20863859Sml29623 20873859Sml29623 if (!multi) { 20883859Sml29623 qlen_hw--; 20893859Sml29623 npkt_read++; 20903859Sml29623 } 20913859Sml29623 20923859Sml29623 /* 20933859Sml29623 * Update the next read entry. 20943859Sml29623 */ 20953859Sml29623 comp_rd_index = NEXT_ENTRY(comp_rd_index, 20966929Smisaki rcr_p->comp_wrap_mask); 20973859Sml29623 20983859Sml29623 rcr_desc_rd_head_p = NEXT_ENTRY_PTR(rcr_desc_rd_head_p, 20996929Smisaki rcr_p->rcr_desc_first_p, 21006929Smisaki rcr_p->rcr_desc_last_p); 21013859Sml29623 21023859Sml29623 nrcr_read++; 21033859Sml29623 21043859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 21056929Smisaki "<== nxge_rx_pkts: (SAM, process one packet) " 21066929Smisaki "nrcr_read %d", 21076929Smisaki nrcr_read)); 21083859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 21096929Smisaki "==> nxge_rx_pkts: loop: rcr channel %d " 21106929Smisaki "multi %d " 21116929Smisaki "nrcr_read %d " 21126929Smisaki "npk read %d " 21136929Smisaki "head_pp $%p index %d ", 21146929Smisaki channel, 21156929Smisaki multi, 21166929Smisaki nrcr_read, npkt_read, rcr_desc_rd_head_pp, 21176929Smisaki comp_rd_index)); 21183859Sml29623 21196495Sspeer if ((bytes_to_pickup != -1) && 21206495Sspeer (totallen >= bytes_to_pickup)) { 21216495Sspeer break; 21226495Sspeer } 21233859Sml29623 } 21243859Sml29623 21253859Sml29623 rcr_p->rcr_desc_rd_head_pp = rcr_desc_rd_head_pp; 21263859Sml29623 rcr_p->comp_rd_index = comp_rd_index; 21273859Sml29623 rcr_p->rcr_desc_rd_head_p = rcr_desc_rd_head_p; 21283859Sml29623 if ((nxgep->intr_timeout != rcr_p->intr_timeout) || 21296929Smisaki (nxgep->intr_threshold != rcr_p->intr_threshold)) { 21308661SSantwona.Behera@Sun.COM 21318661SSantwona.Behera@Sun.COM rcr_p->intr_timeout = (nxgep->intr_timeout < 21328661SSantwona.Behera@Sun.COM NXGE_RDC_RCR_TIMEOUT_MIN) ? NXGE_RDC_RCR_TIMEOUT_MIN : 21338661SSantwona.Behera@Sun.COM nxgep->intr_timeout; 21348661SSantwona.Behera@Sun.COM 21358661SSantwona.Behera@Sun.COM rcr_p->intr_threshold = (nxgep->intr_threshold < 21368661SSantwona.Behera@Sun.COM NXGE_RDC_RCR_THRESHOLD_MIN) ? NXGE_RDC_RCR_THRESHOLD_MIN : 21378661SSantwona.Behera@Sun.COM nxgep->intr_threshold; 21388661SSantwona.Behera@Sun.COM 21393859Sml29623 rcr_cfg_b.value = 0x0ULL; 21408661SSantwona.Behera@Sun.COM rcr_cfg_b.bits.ldw.entout = 1; 21413859Sml29623 rcr_cfg_b.bits.ldw.timeout = rcr_p->intr_timeout; 21423859Sml29623 rcr_cfg_b.bits.ldw.pthres = rcr_p->intr_threshold; 21438661SSantwona.Behera@Sun.COM 21443859Sml29623 RXDMA_REG_WRITE64(handle, RCRCFIG_B_REG, 21456929Smisaki channel, rcr_cfg_b.value); 21463859Sml29623 } 21473859Sml29623 21483859Sml29623 cs.bits.ldw.pktread = npkt_read; 21493859Sml29623 cs.bits.ldw.ptrread = nrcr_read; 21503859Sml29623 RXDMA_REG_WRITE64(handle, RX_DMA_CTL_STAT_REG, 21516929Smisaki channel, cs.value); 21523859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 21536929Smisaki "==> nxge_rx_pkts: EXIT: rcr channel %d " 21546929Smisaki "head_pp $%p index %016llx ", 21556929Smisaki channel, 21566929Smisaki rcr_p->rcr_desc_rd_head_pp, 21576929Smisaki rcr_p->comp_rd_index)); 21583859Sml29623 /* 21593859Sml29623 * Update RCR buffer pointer read and number of packets 21603859Sml29623 * read. 21613859Sml29623 */ 21623859Sml29623 21638275SEric Cheng NXGE_DEBUG_MSG((nxgep, NXGE_ERR_CTL, "<== nxge_rx_pkts: return" 21648275SEric Cheng "channel %d", rcr_p->rdc)); 21658275SEric Cheng 21663859Sml29623 return (head_mp); 21673859Sml29623 } 21683859Sml29623 21693859Sml29623 void 21703859Sml29623 nxge_receive_packet(p_nxge_t nxgep, 21713859Sml29623 p_rx_rcr_ring_t rcr_p, p_rcr_entry_t rcr_desc_rd_head_p, 21723859Sml29623 boolean_t *multi_p, mblk_t **mp, mblk_t **mp_cont) 21733859Sml29623 { 21743859Sml29623 p_mblk_t nmp = NULL; 21753859Sml29623 uint64_t multi; 21763859Sml29623 uint64_t dcf_err; 21773859Sml29623 uint8_t channel; 21783859Sml29623 21793859Sml29623 boolean_t first_entry = B_TRUE; 21803859Sml29623 boolean_t is_tcp_udp = B_FALSE; 21813859Sml29623 boolean_t buffer_free = B_FALSE; 21823859Sml29623 boolean_t error_send_up = B_FALSE; 21833859Sml29623 uint8_t error_type; 21843859Sml29623 uint16_t l2_len; 21853859Sml29623 uint16_t skip_len; 21863859Sml29623 uint8_t pktbufsz_type; 21873859Sml29623 uint64_t rcr_entry; 21883859Sml29623 uint64_t *pkt_buf_addr_pp; 21893859Sml29623 uint64_t *pkt_buf_addr_p; 21903859Sml29623 uint32_t buf_offset; 21913859Sml29623 uint32_t bsize; 21923859Sml29623 uint32_t error_disp_cnt; 21933859Sml29623 uint32_t msg_index; 21943859Sml29623 p_rx_rbr_ring_t rx_rbr_p; 21953859Sml29623 p_rx_msg_t *rx_msg_ring_p; 21963859Sml29623 p_rx_msg_t rx_msg_p; 21973859Sml29623 uint16_t sw_offset_bytes = 0, hdr_size = 0; 21983859Sml29623 nxge_status_t status = NXGE_OK; 21993859Sml29623 boolean_t is_valid = B_FALSE; 22003859Sml29623 p_nxge_rx_ring_stats_t rdc_stats; 22013859Sml29623 uint32_t bytes_read; 22023859Sml29623 uint64_t pkt_type; 22033859Sml29623 uint64_t frag; 22046028Ssbehera boolean_t pkt_too_long_err = B_FALSE; 22053859Sml29623 #ifdef NXGE_DEBUG 22063859Sml29623 int dump_len; 22073859Sml29623 #endif 22083859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, "==> nxge_receive_packet")); 22093859Sml29623 first_entry = (*mp == NULL) ? B_TRUE : B_FALSE; 22103859Sml29623 22113859Sml29623 rcr_entry = *((uint64_t *)rcr_desc_rd_head_p); 22123859Sml29623 22133859Sml29623 multi = (rcr_entry & RCR_MULTI_MASK); 22143859Sml29623 dcf_err = (rcr_entry & RCR_DCF_ERROR_MASK); 22153859Sml29623 pkt_type = (rcr_entry & RCR_PKT_TYPE_MASK); 22163859Sml29623 22173859Sml29623 error_type = ((rcr_entry & RCR_ERROR_MASK) >> RCR_ERROR_SHIFT); 22183859Sml29623 frag = (rcr_entry & RCR_FRAG_MASK); 22193859Sml29623 22203859Sml29623 l2_len = ((rcr_entry & RCR_L2_LEN_MASK) >> RCR_L2_LEN_SHIFT); 22213859Sml29623 22223859Sml29623 pktbufsz_type = ((rcr_entry & RCR_PKTBUFSZ_MASK) >> 22236929Smisaki RCR_PKTBUFSZ_SHIFT); 22245125Sjoycey #if defined(__i386) 22255125Sjoycey pkt_buf_addr_pp = (uint64_t *)(uint32_t)((rcr_entry & 22266929Smisaki RCR_PKT_BUF_ADDR_MASK) << RCR_PKT_BUF_ADDR_SHIFT); 22275125Sjoycey #else 22283859Sml29623 pkt_buf_addr_pp = (uint64_t *)((rcr_entry & RCR_PKT_BUF_ADDR_MASK) << 22296929Smisaki RCR_PKT_BUF_ADDR_SHIFT); 22305125Sjoycey #endif 22313859Sml29623 22323859Sml29623 channel = rcr_p->rdc; 22333859Sml29623 22343859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 22356929Smisaki "==> nxge_receive_packet: entryp $%p entry 0x%0llx " 22366929Smisaki "pkt_buf_addr_pp $%p l2_len %d multi 0x%llx " 22376929Smisaki "error_type 0x%x pkt_type 0x%x " 22386929Smisaki "pktbufsz_type %d ", 22396929Smisaki rcr_desc_rd_head_p, 22406929Smisaki rcr_entry, pkt_buf_addr_pp, l2_len, 22416929Smisaki multi, 22426929Smisaki error_type, 22436929Smisaki pkt_type, 22446929Smisaki pktbufsz_type)); 22453859Sml29623 22463859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 22476929Smisaki "==> nxge_receive_packet: entryp $%p entry 0x%0llx " 22486929Smisaki "pkt_buf_addr_pp $%p l2_len %d multi 0x%llx " 22496929Smisaki "error_type 0x%x pkt_type 0x%x ", rcr_desc_rd_head_p, 22506929Smisaki rcr_entry, pkt_buf_addr_pp, l2_len, 22516929Smisaki multi, 22526929Smisaki error_type, 22536929Smisaki pkt_type)); 22543859Sml29623 22553859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 22566929Smisaki "==> (rbr) nxge_receive_packet: entry 0x%0llx " 22576929Smisaki "full pkt_buf_addr_pp $%p l2_len %d", 22586929Smisaki rcr_entry, pkt_buf_addr_pp, l2_len)); 22593859Sml29623 22603859Sml29623 /* get the stats ptr */ 22613859Sml29623 rdc_stats = rcr_p->rdc_stats; 22623859Sml29623 22633859Sml29623 if (!l2_len) { 22643859Sml29623 22653859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 22666929Smisaki "<== nxge_receive_packet: failed: l2 length is 0.")); 22673859Sml29623 return; 22683859Sml29623 } 22693859Sml29623 22706028Ssbehera /* 22718275SEric Cheng * Software workaround for BMAC hardware limitation that allows 22726028Ssbehera * maxframe size of 1526, instead of 1522 for non-jumbo and 0x2406 22736028Ssbehera * instead of 0x2400 for jumbo. 22746028Ssbehera */ 22756028Ssbehera if (l2_len > nxgep->mac.maxframesize) { 22766028Ssbehera pkt_too_long_err = B_TRUE; 22776028Ssbehera } 22786028Ssbehera 22794185Sspeer /* Hardware sends us 4 bytes of CRC as no stripping is done. */ 22804185Sspeer l2_len -= ETHERFCSL; 22814185Sspeer 22823859Sml29623 /* shift 6 bits to get the full io address */ 22835125Sjoycey #if defined(__i386) 22845125Sjoycey pkt_buf_addr_pp = (uint64_t *)((uint32_t)pkt_buf_addr_pp << 22856929Smisaki RCR_PKT_BUF_ADDR_SHIFT_FULL); 22865125Sjoycey #else 22873859Sml29623 pkt_buf_addr_pp = (uint64_t *)((uint64_t)pkt_buf_addr_pp << 22886929Smisaki RCR_PKT_BUF_ADDR_SHIFT_FULL); 22895125Sjoycey #endif 22903859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 22916929Smisaki "==> (rbr) nxge_receive_packet: entry 0x%0llx " 22926929Smisaki "full pkt_buf_addr_pp $%p l2_len %d", 22936929Smisaki rcr_entry, pkt_buf_addr_pp, l2_len)); 22943859Sml29623 22953859Sml29623 rx_rbr_p = rcr_p->rx_rbr_p; 22963859Sml29623 rx_msg_ring_p = rx_rbr_p->rx_msg_ring; 22973859Sml29623 22983859Sml29623 if (first_entry) { 22993859Sml29623 hdr_size = (rcr_p->full_hdr_flag ? RXDMA_HDR_SIZE_FULL : 23006929Smisaki RXDMA_HDR_SIZE_DEFAULT); 23013859Sml29623 23023859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 23036929Smisaki "==> nxge_receive_packet: first entry 0x%016llx " 23046929Smisaki "pkt_buf_addr_pp $%p l2_len %d hdr %d", 23056929Smisaki rcr_entry, pkt_buf_addr_pp, l2_len, 23066929Smisaki hdr_size)); 23073859Sml29623 } 23083859Sml29623 23093859Sml29623 MUTEX_ENTER(&rx_rbr_p->lock); 23103859Sml29623 23113859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 23126929Smisaki "==> (rbr 1) nxge_receive_packet: entry 0x%0llx " 23136929Smisaki "full pkt_buf_addr_pp $%p l2_len %d", 23146929Smisaki rcr_entry, pkt_buf_addr_pp, l2_len)); 23153859Sml29623 23163859Sml29623 /* 23173859Sml29623 * Packet buffer address in the completion entry points 23183859Sml29623 * to the starting buffer address (offset 0). 23193859Sml29623 * Use the starting buffer address to locate the corresponding 23203859Sml29623 * kernel address. 23213859Sml29623 */ 23223859Sml29623 status = nxge_rxbuf_pp_to_vp(nxgep, rx_rbr_p, 23236929Smisaki pktbufsz_type, pkt_buf_addr_pp, &pkt_buf_addr_p, 23246929Smisaki &buf_offset, 23256929Smisaki &msg_index); 23263859Sml29623 23273859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 23286929Smisaki "==> (rbr 2) nxge_receive_packet: entry 0x%0llx " 23296929Smisaki "full pkt_buf_addr_pp $%p l2_len %d", 23306929Smisaki rcr_entry, pkt_buf_addr_pp, l2_len)); 23313859Sml29623 23323859Sml29623 if (status != NXGE_OK) { 23333859Sml29623 MUTEX_EXIT(&rx_rbr_p->lock); 23343859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 23356929Smisaki "<== nxge_receive_packet: found vaddr failed %d", 23366929Smisaki status)); 23373859Sml29623 return; 23383859Sml29623 } 23393859Sml29623 23403859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 23416929Smisaki "==> (rbr 3) nxge_receive_packet: entry 0x%0llx " 23426929Smisaki "full pkt_buf_addr_pp $%p l2_len %d", 23436929Smisaki rcr_entry, pkt_buf_addr_pp, l2_len)); 23443859Sml29623 23453859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 23466929Smisaki "==> (rbr 4 msgindex %d) nxge_receive_packet: entry 0x%0llx " 23476929Smisaki "full pkt_buf_addr_pp $%p l2_len %d", 23486929Smisaki msg_index, rcr_entry, pkt_buf_addr_pp, l2_len)); 23493859Sml29623 23503859Sml29623 rx_msg_p = rx_msg_ring_p[msg_index]; 23513859Sml29623 23523859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 23536929Smisaki "==> (rbr 4 msgindex %d) nxge_receive_packet: entry 0x%0llx " 23546929Smisaki "full pkt_buf_addr_pp $%p l2_len %d", 23556929Smisaki msg_index, rcr_entry, pkt_buf_addr_pp, l2_len)); 23563859Sml29623 23573859Sml29623 switch (pktbufsz_type) { 23583859Sml29623 case RCR_PKTBUFSZ_0: 23593859Sml29623 bsize = rx_rbr_p->pkt_buf_size0_bytes; 23603859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 23616929Smisaki "==> nxge_receive_packet: 0 buf %d", bsize)); 23623859Sml29623 break; 23633859Sml29623 case RCR_PKTBUFSZ_1: 23643859Sml29623 bsize = rx_rbr_p->pkt_buf_size1_bytes; 23653859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 23666929Smisaki "==> nxge_receive_packet: 1 buf %d", bsize)); 23673859Sml29623 break; 23683859Sml29623 case RCR_PKTBUFSZ_2: 23693859Sml29623 bsize = rx_rbr_p->pkt_buf_size2_bytes; 23703859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 23716929Smisaki "==> nxge_receive_packet: 2 buf %d", bsize)); 23723859Sml29623 break; 23733859Sml29623 case RCR_SINGLE_BLOCK: 23743859Sml29623 bsize = rx_msg_p->block_size; 23753859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 23766929Smisaki "==> nxge_receive_packet: single %d", bsize)); 23773859Sml29623 23783859Sml29623 break; 23793859Sml29623 default: 23803859Sml29623 MUTEX_EXIT(&rx_rbr_p->lock); 23813859Sml29623 return; 23823859Sml29623 } 23833859Sml29623 2384*11304SJanie.Lu@Sun.COM switch (nxge_rdc_buf_offset) { 2385*11304SJanie.Lu@Sun.COM case SW_OFFSET_NO_OFFSET: 2386*11304SJanie.Lu@Sun.COM sw_offset_bytes = 0; 2387*11304SJanie.Lu@Sun.COM break; 2388*11304SJanie.Lu@Sun.COM case SW_OFFSET_64: 2389*11304SJanie.Lu@Sun.COM sw_offset_bytes = 64; 2390*11304SJanie.Lu@Sun.COM break; 2391*11304SJanie.Lu@Sun.COM case SW_OFFSET_128: 2392*11304SJanie.Lu@Sun.COM sw_offset_bytes = 128; 2393*11304SJanie.Lu@Sun.COM break; 2394*11304SJanie.Lu@Sun.COM case SW_OFFSET_192: 2395*11304SJanie.Lu@Sun.COM sw_offset_bytes = 192; 2396*11304SJanie.Lu@Sun.COM break; 2397*11304SJanie.Lu@Sun.COM case SW_OFFSET_256: 2398*11304SJanie.Lu@Sun.COM sw_offset_bytes = 256; 2399*11304SJanie.Lu@Sun.COM break; 2400*11304SJanie.Lu@Sun.COM case SW_OFFSET_320: 2401*11304SJanie.Lu@Sun.COM sw_offset_bytes = 320; 2402*11304SJanie.Lu@Sun.COM break; 2403*11304SJanie.Lu@Sun.COM case SW_OFFSET_384: 2404*11304SJanie.Lu@Sun.COM sw_offset_bytes = 384; 2405*11304SJanie.Lu@Sun.COM break; 2406*11304SJanie.Lu@Sun.COM case SW_OFFSET_448: 2407*11304SJanie.Lu@Sun.COM sw_offset_bytes = 448; 2408*11304SJanie.Lu@Sun.COM break; 2409*11304SJanie.Lu@Sun.COM default: 2410*11304SJanie.Lu@Sun.COM sw_offset_bytes = 0; 2411*11304SJanie.Lu@Sun.COM break; 2412*11304SJanie.Lu@Sun.COM } 2413*11304SJanie.Lu@Sun.COM 24143859Sml29623 DMA_COMMON_SYNC_OFFSET(rx_msg_p->buf_dma, 24156929Smisaki (buf_offset + sw_offset_bytes), 24166929Smisaki (hdr_size + l2_len), 24176929Smisaki DDI_DMA_SYNC_FORCPU); 24183859Sml29623 24193859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 24206929Smisaki "==> nxge_receive_packet: after first dump:usage count")); 24213859Sml29623 24223859Sml29623 if (rx_msg_p->cur_usage_cnt == 0) { 24233859Sml29623 if (rx_rbr_p->rbr_use_bcopy) { 24243859Sml29623 atomic_inc_32(&rx_rbr_p->rbr_consumed); 24253859Sml29623 if (rx_rbr_p->rbr_consumed < 24266929Smisaki rx_rbr_p->rbr_threshold_hi) { 24273859Sml29623 if (rx_rbr_p->rbr_threshold_lo == 0 || 24286929Smisaki ((rx_rbr_p->rbr_consumed >= 24296929Smisaki rx_rbr_p->rbr_threshold_lo) && 24306929Smisaki (rx_rbr_p->rbr_bufsize_type >= 24316929Smisaki pktbufsz_type))) { 24323859Sml29623 rx_msg_p->rx_use_bcopy = B_TRUE; 24333859Sml29623 } 24343859Sml29623 } else { 24353859Sml29623 rx_msg_p->rx_use_bcopy = B_TRUE; 24363859Sml29623 } 24373859Sml29623 } 24383859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 24396929Smisaki "==> nxge_receive_packet: buf %d (new block) ", 24406929Smisaki bsize)); 24413859Sml29623 24423859Sml29623 rx_msg_p->pkt_buf_size_code = pktbufsz_type; 24433859Sml29623 rx_msg_p->pkt_buf_size = bsize; 24443859Sml29623 rx_msg_p->cur_usage_cnt = 1; 24453859Sml29623 if (pktbufsz_type == RCR_SINGLE_BLOCK) { 24463859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 24476929Smisaki "==> nxge_receive_packet: buf %d " 24486929Smisaki "(single block) ", 24496929Smisaki bsize)); 24503859Sml29623 /* 24513859Sml29623 * Buffer can be reused once the free function 24523859Sml29623 * is called. 24533859Sml29623 */ 24543859Sml29623 rx_msg_p->max_usage_cnt = 1; 24553859Sml29623 buffer_free = B_TRUE; 24563859Sml29623 } else { 24573859Sml29623 rx_msg_p->max_usage_cnt = rx_msg_p->block_size/bsize; 24583859Sml29623 if (rx_msg_p->max_usage_cnt == 1) { 24593859Sml29623 buffer_free = B_TRUE; 24603859Sml29623 } 24613859Sml29623 } 24623859Sml29623 } else { 24633859Sml29623 rx_msg_p->cur_usage_cnt++; 24643859Sml29623 if (rx_msg_p->cur_usage_cnt == rx_msg_p->max_usage_cnt) { 24653859Sml29623 buffer_free = B_TRUE; 24663859Sml29623 } 24673859Sml29623 } 24683859Sml29623 24693859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 24703859Sml29623 "msgbuf index = %d l2len %d bytes usage %d max_usage %d ", 24716929Smisaki msg_index, l2_len, 24726929Smisaki rx_msg_p->cur_usage_cnt, rx_msg_p->max_usage_cnt)); 24733859Sml29623 24746028Ssbehera if ((error_type) || (dcf_err) || (pkt_too_long_err)) { 24753859Sml29623 rdc_stats->ierrors++; 24763859Sml29623 if (dcf_err) { 24773859Sml29623 rdc_stats->dcf_err++; 24783859Sml29623 #ifdef NXGE_DEBUG 24793859Sml29623 if (!rdc_stats->dcf_err) { 24803859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 24813859Sml29623 "nxge_receive_packet: channel %d dcf_err rcr" 24823859Sml29623 " 0x%llx", channel, rcr_entry)); 24833859Sml29623 } 24843859Sml29623 #endif 24853859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, nxgep->mac.portnum, NULL, 24866929Smisaki NXGE_FM_EREPORT_RDMC_DCF_ERR); 24876028Ssbehera } else if (pkt_too_long_err) { 24886028Ssbehera rdc_stats->pkt_too_long_err++; 24896028Ssbehera NXGE_DEBUG_MSG((nxgep, RX_CTL, " nxge_receive_packet:" 24906028Ssbehera " channel %d packet length [%d] > " 24916028Ssbehera "maxframesize [%d]", channel, l2_len + ETHERFCSL, 24926028Ssbehera nxgep->mac.maxframesize)); 24933859Sml29623 } else { 24943859Sml29623 /* Update error stats */ 24953859Sml29623 error_disp_cnt = NXGE_ERROR_SHOW_MAX; 24963859Sml29623 rdc_stats->errlog.compl_err_type = error_type; 24973859Sml29623 24983859Sml29623 switch (error_type) { 24995523Syc148097 /* 25005523Syc148097 * Do not send FMA ereport for RCR_L2_ERROR and 25015523Syc148097 * RCR_L4_CSUM_ERROR because most likely they indicate 25025523Syc148097 * back pressure rather than HW failures. 25035523Syc148097 */ 25045165Syc148097 case RCR_L2_ERROR: 25055165Syc148097 rdc_stats->l2_err++; 25065165Syc148097 if (rdc_stats->l2_err < 25075165Syc148097 error_disp_cnt) { 25085165Syc148097 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 25095165Syc148097 " nxge_receive_packet:" 25105165Syc148097 " channel %d RCR L2_ERROR", 25115165Syc148097 channel)); 25125165Syc148097 } 25135165Syc148097 break; 25145165Syc148097 case RCR_L4_CSUM_ERROR: 25155165Syc148097 error_send_up = B_TRUE; 25165165Syc148097 rdc_stats->l4_cksum_err++; 25175165Syc148097 if (rdc_stats->l4_cksum_err < 25185165Syc148097 error_disp_cnt) { 25193859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 25205165Syc148097 " nxge_receive_packet:" 25215165Syc148097 " channel %d" 25225165Syc148097 " RCR L4_CSUM_ERROR", channel)); 25235165Syc148097 } 25245165Syc148097 break; 25255523Syc148097 /* 25265523Syc148097 * Do not send FMA ereport for RCR_FFLP_SOFT_ERROR and 25275523Syc148097 * RCR_ZCP_SOFT_ERROR because they reflect the same 25285523Syc148097 * FFLP and ZCP errors that have been reported by 25295523Syc148097 * nxge_fflp.c and nxge_zcp.c. 25305523Syc148097 */ 25315165Syc148097 case RCR_FFLP_SOFT_ERROR: 25325165Syc148097 error_send_up = B_TRUE; 25335165Syc148097 rdc_stats->fflp_soft_err++; 25345165Syc148097 if (rdc_stats->fflp_soft_err < 25355165Syc148097 error_disp_cnt) { 25365165Syc148097 NXGE_ERROR_MSG((nxgep, 25375165Syc148097 NXGE_ERR_CTL, 25385165Syc148097 " nxge_receive_packet:" 25395165Syc148097 " channel %d" 25405165Syc148097 " RCR FFLP_SOFT_ERROR", channel)); 25415165Syc148097 } 25425165Syc148097 break; 25435165Syc148097 case RCR_ZCP_SOFT_ERROR: 25445165Syc148097 error_send_up = B_TRUE; 25455165Syc148097 rdc_stats->fflp_soft_err++; 25465165Syc148097 if (rdc_stats->zcp_soft_err < 25475165Syc148097 error_disp_cnt) 25485165Syc148097 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 25495165Syc148097 " nxge_receive_packet: Channel %d" 25505165Syc148097 " RCR ZCP_SOFT_ERROR", channel)); 25515165Syc148097 break; 25525165Syc148097 default: 25535165Syc148097 rdc_stats->rcr_unknown_err++; 25545165Syc148097 if (rdc_stats->rcr_unknown_err 25555165Syc148097 < error_disp_cnt) { 25565165Syc148097 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 25575165Syc148097 " nxge_receive_packet: Channel %d" 25585165Syc148097 " RCR entry 0x%llx error 0x%x", 25595165Syc148097 rcr_entry, channel, error_type)); 25605165Syc148097 } 25615165Syc148097 break; 25623859Sml29623 } 25633859Sml29623 } 25643859Sml29623 25653859Sml29623 /* 25663859Sml29623 * Update and repost buffer block if max usage 25673859Sml29623 * count is reached. 25683859Sml29623 */ 25693859Sml29623 if (error_send_up == B_FALSE) { 25704874Sml29623 atomic_inc_32(&rx_msg_p->ref_cnt); 25713859Sml29623 if (buffer_free == B_TRUE) { 25723859Sml29623 rx_msg_p->free = B_TRUE; 25733859Sml29623 } 25743859Sml29623 25753859Sml29623 MUTEX_EXIT(&rx_rbr_p->lock); 25763859Sml29623 nxge_freeb(rx_msg_p); 25773859Sml29623 return; 25783859Sml29623 } 25793859Sml29623 } 25803859Sml29623 25813859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 25826929Smisaki "==> nxge_receive_packet: DMA sync second ")); 25833859Sml29623 25845165Syc148097 bytes_read = rcr_p->rcvd_pkt_bytes; 25853859Sml29623 skip_len = sw_offset_bytes + hdr_size; 25863859Sml29623 if (!rx_msg_p->rx_use_bcopy) { 25874874Sml29623 /* 25884874Sml29623 * For loaned up buffers, the driver reference count 25894874Sml29623 * will be incremented first and then the free state. 25904874Sml29623 */ 25915165Syc148097 if ((nmp = nxge_dupb(rx_msg_p, buf_offset, bsize)) != NULL) { 25925165Syc148097 if (first_entry) { 25935165Syc148097 nmp->b_rptr = &nmp->b_rptr[skip_len]; 25945165Syc148097 if (l2_len < bsize - skip_len) { 25955165Syc148097 nmp->b_wptr = &nmp->b_rptr[l2_len]; 25965165Syc148097 } else { 25975165Syc148097 nmp->b_wptr = &nmp->b_rptr[bsize 25985165Syc148097 - skip_len]; 25995165Syc148097 } 26005165Syc148097 } else { 26015165Syc148097 if (l2_len - bytes_read < bsize) { 26025165Syc148097 nmp->b_wptr = 26035165Syc148097 &nmp->b_rptr[l2_len - bytes_read]; 26045165Syc148097 } else { 26055165Syc148097 nmp->b_wptr = &nmp->b_rptr[bsize]; 26065165Syc148097 } 26075165Syc148097 } 26085165Syc148097 } 26093859Sml29623 } else { 26105165Syc148097 if (first_entry) { 26115165Syc148097 nmp = nxge_dupb_bcopy(rx_msg_p, buf_offset + skip_len, 26125165Syc148097 l2_len < bsize - skip_len ? 26135165Syc148097 l2_len : bsize - skip_len); 26145165Syc148097 } else { 26155165Syc148097 nmp = nxge_dupb_bcopy(rx_msg_p, buf_offset, 26165165Syc148097 l2_len - bytes_read < bsize ? 26175165Syc148097 l2_len - bytes_read : bsize); 26185165Syc148097 } 26193859Sml29623 } 26203859Sml29623 if (nmp != NULL) { 26217145Syc148097 if (first_entry) { 26227145Syc148097 /* 26237145Syc148097 * Jumbo packets may be received with more than one 26247145Syc148097 * buffer, increment ipackets for the first entry only. 26257145Syc148097 */ 26267145Syc148097 rdc_stats->ipackets++; 26277145Syc148097 26287145Syc148097 /* Update ibytes for kstat. */ 26297145Syc148097 rdc_stats->ibytes += skip_len 26307145Syc148097 + l2_len < bsize ? l2_len : bsize; 26317145Syc148097 /* 26327145Syc148097 * Update the number of bytes read so far for the 26337145Syc148097 * current frame. 26347145Syc148097 */ 26355165Syc148097 bytes_read = nmp->b_wptr - nmp->b_rptr; 26367145Syc148097 } else { 26377145Syc148097 rdc_stats->ibytes += l2_len - bytes_read < bsize ? 26387145Syc148097 l2_len - bytes_read : bsize; 26393859Sml29623 bytes_read += nmp->b_wptr - nmp->b_rptr; 26407145Syc148097 } 26415165Syc148097 26425165Syc148097 NXGE_DEBUG_MSG((nxgep, RX_CTL, 26435165Syc148097 "==> nxge_receive_packet after dupb: " 26445165Syc148097 "rbr consumed %d " 26455165Syc148097 "pktbufsz_type %d " 26465165Syc148097 "nmp $%p rptr $%p wptr $%p " 26475165Syc148097 "buf_offset %d bzise %d l2_len %d skip_len %d", 26485165Syc148097 rx_rbr_p->rbr_consumed, 26495165Syc148097 pktbufsz_type, 26505165Syc148097 nmp, nmp->b_rptr, nmp->b_wptr, 26515165Syc148097 buf_offset, bsize, l2_len, skip_len)); 26523859Sml29623 } else { 26533859Sml29623 cmn_err(CE_WARN, "!nxge_receive_packet: " 26546929Smisaki "update stats (error)"); 26554977Sraghus atomic_inc_32(&rx_msg_p->ref_cnt); 26564977Sraghus if (buffer_free == B_TRUE) { 26574977Sraghus rx_msg_p->free = B_TRUE; 26584977Sraghus } 26594977Sraghus MUTEX_EXIT(&rx_rbr_p->lock); 26604977Sraghus nxge_freeb(rx_msg_p); 26614977Sraghus return; 26623859Sml29623 } 26635060Syc148097 26643859Sml29623 if (buffer_free == B_TRUE) { 26653859Sml29623 rx_msg_p->free = B_TRUE; 26663859Sml29623 } 26677145Syc148097 26683859Sml29623 is_valid = (nmp != NULL); 26695165Syc148097 26705165Syc148097 rcr_p->rcvd_pkt_bytes = bytes_read; 26715165Syc148097 26723859Sml29623 MUTEX_EXIT(&rx_rbr_p->lock); 26733859Sml29623 26743859Sml29623 if (rx_msg_p->free && rx_msg_p->rx_use_bcopy) { 26753859Sml29623 atomic_inc_32(&rx_msg_p->ref_cnt); 26763859Sml29623 nxge_freeb(rx_msg_p); 26773859Sml29623 } 26783859Sml29623 26793859Sml29623 if (is_valid) { 26803859Sml29623 nmp->b_cont = NULL; 26813859Sml29623 if (first_entry) { 26823859Sml29623 *mp = nmp; 26833859Sml29623 *mp_cont = NULL; 26845165Syc148097 } else { 26853859Sml29623 *mp_cont = nmp; 26865165Syc148097 } 26873859Sml29623 } 26883859Sml29623 26893859Sml29623 /* 26907145Syc148097 * ERROR, FRAG and PKT_TYPE are only reported in the first entry. 26917145Syc148097 * If a packet is not fragmented and no error bit is set, then 26927145Syc148097 * L4 checksum is OK. 26933859Sml29623 */ 26947145Syc148097 26953859Sml29623 if (is_valid && !multi) { 26966495Sspeer /* 26976611Sml29623 * If the checksum flag nxge_chksum_offload 26986611Sml29623 * is 1, TCP and UDP packets can be sent 26996495Sspeer * up with good checksum. If the checksum flag 27006611Sml29623 * is set to 0, checksum reporting will apply to 27016495Sspeer * TCP packets only (workaround for a hardware bug). 27026611Sml29623 * If the checksum flag nxge_cksum_offload is 27036611Sml29623 * greater than 1, both TCP and UDP packets 27046611Sml29623 * will not be reported its hardware checksum results. 27056495Sspeer */ 27066611Sml29623 if (nxge_cksum_offload == 1) { 27076495Sspeer is_tcp_udp = ((pkt_type == RCR_PKT_IS_TCP || 27086929Smisaki pkt_type == RCR_PKT_IS_UDP) ? 27096929Smisaki B_TRUE: B_FALSE); 27106611Sml29623 } else if (!nxge_cksum_offload) { 27116495Sspeer /* TCP checksum only. */ 27126495Sspeer is_tcp_udp = ((pkt_type == RCR_PKT_IS_TCP) ? 27136929Smisaki B_TRUE: B_FALSE); 27146495Sspeer } 27153859Sml29623 27163859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_receive_packet: " 27176929Smisaki "is_valid 0x%x multi 0x%llx pkt %d frag %d error %d", 27186929Smisaki is_valid, multi, is_tcp_udp, frag, error_type)); 27193859Sml29623 27203859Sml29623 if (is_tcp_udp && !frag && !error_type) { 27213859Sml29623 (void) hcksum_assoc(nmp, NULL, NULL, 0, 0, 0, 0, 27226929Smisaki HCK_FULLCKSUM_OK | HCK_FULLCKSUM, 0); 27233859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 27246929Smisaki "==> nxge_receive_packet: Full tcp/udp cksum " 27256929Smisaki "is_valid 0x%x multi 0x%llx pkt %d frag %d " 27266929Smisaki "error %d", 27276929Smisaki is_valid, multi, is_tcp_udp, frag, error_type)); 27283859Sml29623 } 27293859Sml29623 } 27303859Sml29623 27313859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, 27326929Smisaki "==> nxge_receive_packet: *mp 0x%016llx", *mp)); 27333859Sml29623 27343859Sml29623 *multi_p = (multi == RCR_MULTI_MASK); 27353859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_receive_packet: " 27366929Smisaki "multi %d nmp 0x%016llx *mp 0x%016llx *mp_cont 0x%016llx", 27376929Smisaki *multi_p, nmp, *mp, *mp_cont)); 27383859Sml29623 } 27393859Sml29623 27408275SEric Cheng /* 27418275SEric Cheng * Enable polling for a ring. Interrupt for the ring is disabled when 27428275SEric Cheng * the nxge interrupt comes (see nxge_rx_intr). 27438275SEric Cheng */ 27448275SEric Cheng int 27458275SEric Cheng nxge_enable_poll(void *arg) 27468275SEric Cheng { 27478275SEric Cheng p_nxge_ring_handle_t ring_handle = (p_nxge_ring_handle_t)arg; 27488275SEric Cheng p_rx_rcr_ring_t ringp; 27498275SEric Cheng p_nxge_t nxgep; 27508275SEric Cheng p_nxge_ldg_t ldgp; 27518275SEric Cheng uint32_t channel; 27528275SEric Cheng 27538275SEric Cheng if (ring_handle == NULL) { 275410309SSriharsha.Basavapatna@Sun.COM ASSERT(ring_handle != NULL); 27558275SEric Cheng return (0); 27568275SEric Cheng } 27578275SEric Cheng 27588275SEric Cheng nxgep = ring_handle->nxgep; 27598275SEric Cheng channel = nxgep->pt_config.hw_config.start_rdc + ring_handle->index; 27608275SEric Cheng ringp = nxgep->rx_rcr_rings->rcr_rings[channel]; 27618275SEric Cheng NXGE_DEBUG_MSG((nxgep, NXGE_ERR_CTL, 27628275SEric Cheng "==> nxge_enable_poll: rdc %d ", ringp->rdc)); 27638275SEric Cheng ldgp = ringp->ldgp; 27648275SEric Cheng if (ldgp == NULL) { 27658275SEric Cheng NXGE_DEBUG_MSG((nxgep, NXGE_ERR_CTL, 27668275SEric Cheng "==> nxge_enable_poll: rdc %d NULL ldgp: no change", 27678275SEric Cheng ringp->rdc)); 27688275SEric Cheng return (0); 27698275SEric Cheng } 27708275SEric Cheng 27718275SEric Cheng MUTEX_ENTER(&ringp->lock); 27728275SEric Cheng /* enable polling */ 27738275SEric Cheng if (ringp->poll_flag == 0) { 27748275SEric Cheng ringp->poll_flag = 1; 27758275SEric Cheng NXGE_DEBUG_MSG((nxgep, NXGE_ERR_CTL, 27768275SEric Cheng "==> nxge_enable_poll: rdc %d set poll flag to 1", 27778275SEric Cheng ringp->rdc)); 27788275SEric Cheng } 27798275SEric Cheng 27808275SEric Cheng MUTEX_EXIT(&ringp->lock); 27818275SEric Cheng return (0); 27828275SEric Cheng } 27838275SEric Cheng /* 27848275SEric Cheng * Disable polling for a ring and enable its interrupt. 27858275SEric Cheng */ 27868275SEric Cheng int 27878275SEric Cheng nxge_disable_poll(void *arg) 27888275SEric Cheng { 27898275SEric Cheng p_nxge_ring_handle_t ring_handle = (p_nxge_ring_handle_t)arg; 27908275SEric Cheng p_rx_rcr_ring_t ringp; 27918275SEric Cheng p_nxge_t nxgep; 27928275SEric Cheng uint32_t channel; 27938275SEric Cheng 27948275SEric Cheng if (ring_handle == NULL) { 279510309SSriharsha.Basavapatna@Sun.COM ASSERT(ring_handle != NULL); 27968275SEric Cheng return (0); 27978275SEric Cheng } 27988275SEric Cheng 27998275SEric Cheng nxgep = ring_handle->nxgep; 28008275SEric Cheng channel = nxgep->pt_config.hw_config.start_rdc + ring_handle->index; 28018275SEric Cheng ringp = nxgep->rx_rcr_rings->rcr_rings[channel]; 28028275SEric Cheng 28038275SEric Cheng NXGE_DEBUG_MSG((nxgep, NXGE_ERR_CTL, 28048275SEric Cheng "==> nxge_disable_poll: rdc %d poll_flag %d", ringp->rdc)); 28058275SEric Cheng 28068275SEric Cheng MUTEX_ENTER(&ringp->lock); 28078275SEric Cheng 28088275SEric Cheng /* disable polling: enable interrupt */ 28098275SEric Cheng if (ringp->poll_flag) { 28108275SEric Cheng npi_handle_t handle; 28118275SEric Cheng rx_dma_ctl_stat_t cs; 28128275SEric Cheng uint8_t channel; 28138275SEric Cheng p_nxge_ldg_t ldgp; 28148275SEric Cheng 28158275SEric Cheng /* 28168275SEric Cheng * Get the control and status for this channel. 28178275SEric Cheng */ 28188275SEric Cheng handle = NXGE_DEV_NPI_HANDLE(nxgep); 28198275SEric Cheng channel = ringp->rdc; 28208275SEric Cheng RXDMA_REG_READ64(handle, RX_DMA_CTL_STAT_REG, 28218275SEric Cheng channel, &cs.value); 28228275SEric Cheng 28238275SEric Cheng /* 28248275SEric Cheng * Enable mailbox update 28258275SEric Cheng * Since packets were not read and the hardware uses 28268275SEric Cheng * bits pktread and ptrread to update the queue 28278275SEric Cheng * length, we need to set both bits to 0. 28288275SEric Cheng */ 28298275SEric Cheng cs.bits.ldw.pktread = 0; 28308275SEric Cheng cs.bits.ldw.ptrread = 0; 28318275SEric Cheng cs.bits.hdw.mex = 1; 28328275SEric Cheng RXDMA_REG_WRITE64(handle, RX_DMA_CTL_STAT_REG, channel, 28338275SEric Cheng cs.value); 28348275SEric Cheng 28358275SEric Cheng /* 28368275SEric Cheng * Rearm this logical group if this is a single device 28378275SEric Cheng * group. 28388275SEric Cheng */ 28398275SEric Cheng ldgp = ringp->ldgp; 28408275SEric Cheng if (ldgp == NULL) { 28418275SEric Cheng ringp->poll_flag = 0; 28428275SEric Cheng MUTEX_EXIT(&ringp->lock); 28438275SEric Cheng NXGE_DEBUG_MSG((nxgep, NXGE_ERR_CTL, 28448275SEric Cheng "==> nxge_disable_poll: no ldgp rdc %d " 28458275SEric Cheng "(still set poll to 0", ringp->rdc)); 28468275SEric Cheng return (0); 28478275SEric Cheng } 28488275SEric Cheng NXGE_DEBUG_MSG((nxgep, NXGE_ERR_CTL, 28498275SEric Cheng "==> nxge_disable_poll: rdc %d ldgp $%p (enable intr)", 28508275SEric Cheng ringp->rdc, ldgp)); 28518275SEric Cheng if (ldgp->nldvs == 1) { 285210309SSriharsha.Basavapatna@Sun.COM if (isLDOMguest(nxgep)) { 285310309SSriharsha.Basavapatna@Sun.COM ldgp->arm = B_TRUE; 285410309SSriharsha.Basavapatna@Sun.COM nxge_hio_ldgimgn(nxgep, ldgp); 285510309SSriharsha.Basavapatna@Sun.COM } else { 285610309SSriharsha.Basavapatna@Sun.COM ldgimgm_t mgm; 285710309SSriharsha.Basavapatna@Sun.COM mgm.value = 0; 285810309SSriharsha.Basavapatna@Sun.COM mgm.bits.ldw.arm = 1; 285910309SSriharsha.Basavapatna@Sun.COM mgm.bits.ldw.timer = ldgp->ldg_timer; 286010309SSriharsha.Basavapatna@Sun.COM NXGE_REG_WR64(handle, 286110309SSriharsha.Basavapatna@Sun.COM LDGIMGN_REG + LDSV_OFFSET(ldgp->ldg), 286210309SSriharsha.Basavapatna@Sun.COM mgm.value); 286310309SSriharsha.Basavapatna@Sun.COM } 28648275SEric Cheng } 28658275SEric Cheng ringp->poll_flag = 0; 28668275SEric Cheng } 28678275SEric Cheng 28688275SEric Cheng MUTEX_EXIT(&ringp->lock); 28698275SEric Cheng return (0); 28708275SEric Cheng } 28718275SEric Cheng 28728275SEric Cheng /* 28738275SEric Cheng * Poll 'bytes_to_pickup' bytes of message from the rx ring. 28748275SEric Cheng */ 28758275SEric Cheng mblk_t * 28768275SEric Cheng nxge_rx_poll(void *arg, int bytes_to_pickup) 28778275SEric Cheng { 28788275SEric Cheng p_nxge_ring_handle_t ring_handle = (p_nxge_ring_handle_t)arg; 28798275SEric Cheng p_rx_rcr_ring_t rcr_p; 28808275SEric Cheng p_nxge_t nxgep; 28818275SEric Cheng npi_handle_t handle; 28828275SEric Cheng rx_dma_ctl_stat_t cs; 28838275SEric Cheng mblk_t *mblk; 28848275SEric Cheng p_nxge_ldv_t ldvp; 28858275SEric Cheng uint32_t channel; 28868275SEric Cheng 28878275SEric Cheng nxgep = ring_handle->nxgep; 28888275SEric Cheng 28898275SEric Cheng /* 28908275SEric Cheng * Get the control and status for this channel. 28918275SEric Cheng */ 28928275SEric Cheng handle = NXGE_DEV_NPI_HANDLE(nxgep); 28938275SEric Cheng channel = nxgep->pt_config.hw_config.start_rdc + ring_handle->index; 28948275SEric Cheng rcr_p = nxgep->rx_rcr_rings->rcr_rings[channel]; 28958275SEric Cheng MUTEX_ENTER(&rcr_p->lock); 28968275SEric Cheng ASSERT(rcr_p->poll_flag == 1); 28978275SEric Cheng 28988275SEric Cheng RXDMA_REG_READ64(handle, RX_DMA_CTL_STAT_REG, rcr_p->rdc, &cs.value); 28998275SEric Cheng 29008275SEric Cheng NXGE_DEBUG_MSG((nxgep, NXGE_ERR_CTL, 29018275SEric Cheng "==> nxge_rx_poll: calling nxge_rx_pkts: rdc %d poll_flag %d", 29028275SEric Cheng rcr_p->rdc, rcr_p->poll_flag)); 29038275SEric Cheng mblk = nxge_rx_pkts(nxgep, rcr_p, cs, bytes_to_pickup); 29048275SEric Cheng 29058275SEric Cheng ldvp = rcr_p->ldvp; 29068275SEric Cheng /* error events. */ 29078275SEric Cheng if (ldvp && (cs.value & RX_DMA_CTL_STAT_ERROR)) { 29088275SEric Cheng (void) nxge_rx_err_evnts(nxgep, ldvp->vdma_index, cs); 29098275SEric Cheng } 29108275SEric Cheng 29118275SEric Cheng MUTEX_EXIT(&rcr_p->lock); 29128275SEric Cheng 29138275SEric Cheng NXGE_DEBUG_MSG((nxgep, NXGE_ERR_CTL, 29148275SEric Cheng "<== nxge_rx_poll: rdc %d mblk $%p", rcr_p->rdc, mblk)); 29158275SEric Cheng return (mblk); 29168275SEric Cheng } 29178275SEric Cheng 29188275SEric Cheng 29193859Sml29623 /*ARGSUSED*/ 29203859Sml29623 static nxge_status_t 29216495Sspeer nxge_rx_err_evnts(p_nxge_t nxgep, int channel, rx_dma_ctl_stat_t cs) 29223859Sml29623 { 29233859Sml29623 p_nxge_rx_ring_stats_t rdc_stats; 29243859Sml29623 npi_handle_t handle; 29253859Sml29623 npi_status_t rs; 29263859Sml29623 boolean_t rxchan_fatal = B_FALSE; 29273859Sml29623 boolean_t rxport_fatal = B_FALSE; 29283859Sml29623 uint8_t portn; 29293859Sml29623 nxge_status_t status = NXGE_OK; 29303859Sml29623 uint32_t error_disp_cnt = NXGE_ERROR_SHOW_MAX; 29313859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_rx_err_evnts")); 29323859Sml29623 29333859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 29343859Sml29623 portn = nxgep->mac.portnum; 29356495Sspeer rdc_stats = &nxgep->statsp->rdc_stats[channel]; 29363859Sml29623 29373859Sml29623 if (cs.bits.hdw.rbr_tmout) { 29383859Sml29623 rdc_stats->rx_rbr_tmout++; 29393859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, portn, channel, 29406929Smisaki NXGE_FM_EREPORT_RDMC_RBR_TMOUT); 29413859Sml29623 rxchan_fatal = B_TRUE; 29423859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 29436929Smisaki "==> nxge_rx_err_evnts: rx_rbr_timeout")); 29443859Sml29623 } 29453859Sml29623 if (cs.bits.hdw.rsp_cnt_err) { 29463859Sml29623 rdc_stats->rsp_cnt_err++; 29473859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, portn, channel, 29486929Smisaki NXGE_FM_EREPORT_RDMC_RSP_CNT_ERR); 29493859Sml29623 rxchan_fatal = B_TRUE; 29503859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 29516929Smisaki "==> nxge_rx_err_evnts(channel %d): " 29526929Smisaki "rsp_cnt_err", channel)); 29533859Sml29623 } 29543859Sml29623 if (cs.bits.hdw.byte_en_bus) { 29553859Sml29623 rdc_stats->byte_en_bus++; 29563859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, portn, channel, 29576929Smisaki NXGE_FM_EREPORT_RDMC_BYTE_EN_BUS); 29583859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 29596929Smisaki "==> nxge_rx_err_evnts(channel %d): " 29606929Smisaki "fatal error: byte_en_bus", channel)); 29613859Sml29623 rxchan_fatal = B_TRUE; 29623859Sml29623 } 29633859Sml29623 if (cs.bits.hdw.rsp_dat_err) { 29643859Sml29623 rdc_stats->rsp_dat_err++; 29653859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, portn, channel, 29666929Smisaki NXGE_FM_EREPORT_RDMC_RSP_DAT_ERR); 29673859Sml29623 rxchan_fatal = B_TRUE; 29683859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 29696929Smisaki "==> nxge_rx_err_evnts(channel %d): " 29706929Smisaki "fatal error: rsp_dat_err", channel)); 29713859Sml29623 } 29723859Sml29623 if (cs.bits.hdw.rcr_ack_err) { 29733859Sml29623 rdc_stats->rcr_ack_err++; 29743859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, portn, channel, 29756929Smisaki NXGE_FM_EREPORT_RDMC_RCR_ACK_ERR); 29763859Sml29623 rxchan_fatal = B_TRUE; 29773859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 29786929Smisaki "==> nxge_rx_err_evnts(channel %d): " 29796929Smisaki "fatal error: rcr_ack_err", channel)); 29803859Sml29623 } 29813859Sml29623 if (cs.bits.hdw.dc_fifo_err) { 29823859Sml29623 rdc_stats->dc_fifo_err++; 29833859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, portn, channel, 29846929Smisaki NXGE_FM_EREPORT_RDMC_DC_FIFO_ERR); 29853859Sml29623 /* This is not a fatal error! */ 29863859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 29876929Smisaki "==> nxge_rx_err_evnts(channel %d): " 29886929Smisaki "dc_fifo_err", channel)); 29893859Sml29623 rxport_fatal = B_TRUE; 29903859Sml29623 } 29913859Sml29623 if ((cs.bits.hdw.rcr_sha_par) || (cs.bits.hdw.rbr_pre_par)) { 29923859Sml29623 if ((rs = npi_rxdma_ring_perr_stat_get(handle, 29936929Smisaki &rdc_stats->errlog.pre_par, 29946929Smisaki &rdc_stats->errlog.sha_par)) 29956929Smisaki != NPI_SUCCESS) { 29963859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 29976929Smisaki "==> nxge_rx_err_evnts(channel %d): " 29986929Smisaki "rcr_sha_par: get perr", channel)); 29993859Sml29623 return (NXGE_ERROR | rs); 30003859Sml29623 } 30013859Sml29623 if (cs.bits.hdw.rcr_sha_par) { 30023859Sml29623 rdc_stats->rcr_sha_par++; 30033859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, portn, channel, 30046929Smisaki NXGE_FM_EREPORT_RDMC_RCR_SHA_PAR); 30053859Sml29623 rxchan_fatal = B_TRUE; 30063859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 30076929Smisaki "==> nxge_rx_err_evnts(channel %d): " 30086929Smisaki "fatal error: rcr_sha_par", channel)); 30093859Sml29623 } 30103859Sml29623 if (cs.bits.hdw.rbr_pre_par) { 30113859Sml29623 rdc_stats->rbr_pre_par++; 30123859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, portn, channel, 30136929Smisaki NXGE_FM_EREPORT_RDMC_RBR_PRE_PAR); 30143859Sml29623 rxchan_fatal = B_TRUE; 30153859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 30166929Smisaki "==> nxge_rx_err_evnts(channel %d): " 30176929Smisaki "fatal error: rbr_pre_par", channel)); 30183859Sml29623 } 30193859Sml29623 } 30206172Syc148097 /* 30216172Syc148097 * The Following 4 status bits are for information, the system 30226172Syc148097 * is running fine. There is no need to send FMA ereports or 30236172Syc148097 * log messages. 30246172Syc148097 */ 30253859Sml29623 if (cs.bits.hdw.port_drop_pkt) { 30263859Sml29623 rdc_stats->port_drop_pkt++; 30273859Sml29623 } 30283859Sml29623 if (cs.bits.hdw.wred_drop) { 30293859Sml29623 rdc_stats->wred_drop++; 30303859Sml29623 } 30313859Sml29623 if (cs.bits.hdw.rbr_pre_empty) { 30323859Sml29623 rdc_stats->rbr_pre_empty++; 30333859Sml29623 } 30343859Sml29623 if (cs.bits.hdw.rcr_shadow_full) { 30353859Sml29623 rdc_stats->rcr_shadow_full++; 30363859Sml29623 } 30373859Sml29623 if (cs.bits.hdw.config_err) { 30383859Sml29623 rdc_stats->config_err++; 30393859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, portn, channel, 30406929Smisaki NXGE_FM_EREPORT_RDMC_CONFIG_ERR); 30413859Sml29623 rxchan_fatal = B_TRUE; 30423859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 30436929Smisaki "==> nxge_rx_err_evnts(channel %d): " 30446929Smisaki "config error", channel)); 30453859Sml29623 } 30463859Sml29623 if (cs.bits.hdw.rcrincon) { 30473859Sml29623 rdc_stats->rcrincon++; 30483859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, portn, channel, 30496929Smisaki NXGE_FM_EREPORT_RDMC_RCRINCON); 30503859Sml29623 rxchan_fatal = B_TRUE; 30513859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 30526929Smisaki "==> nxge_rx_err_evnts(channel %d): " 30536929Smisaki "fatal error: rcrincon error", channel)); 30543859Sml29623 } 30553859Sml29623 if (cs.bits.hdw.rcrfull) { 30563859Sml29623 rdc_stats->rcrfull++; 30573859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, portn, channel, 30586929Smisaki NXGE_FM_EREPORT_RDMC_RCRFULL); 30593859Sml29623 rxchan_fatal = B_TRUE; 30603859Sml29623 if (rdc_stats->rcrfull < error_disp_cnt) 30613859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 30626929Smisaki "==> nxge_rx_err_evnts(channel %d): " 30636929Smisaki "fatal error: rcrfull error", channel)); 30643859Sml29623 } 30653859Sml29623 if (cs.bits.hdw.rbr_empty) { 30666172Syc148097 /* 30676172Syc148097 * This bit is for information, there is no need 30686172Syc148097 * send FMA ereport or log a message. 30696172Syc148097 */ 30703859Sml29623 rdc_stats->rbr_empty++; 30713859Sml29623 } 30723859Sml29623 if (cs.bits.hdw.rbrfull) { 30733859Sml29623 rdc_stats->rbrfull++; 30743859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, portn, channel, 30756929Smisaki NXGE_FM_EREPORT_RDMC_RBRFULL); 30763859Sml29623 rxchan_fatal = B_TRUE; 30773859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 30786929Smisaki "==> nxge_rx_err_evnts(channel %d): " 30796929Smisaki "fatal error: rbr_full error", channel)); 30803859Sml29623 } 30813859Sml29623 if (cs.bits.hdw.rbrlogpage) { 30823859Sml29623 rdc_stats->rbrlogpage++; 30833859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, portn, channel, 30846929Smisaki NXGE_FM_EREPORT_RDMC_RBRLOGPAGE); 30853859Sml29623 rxchan_fatal = B_TRUE; 30863859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 30876929Smisaki "==> nxge_rx_err_evnts(channel %d): " 30886929Smisaki "fatal error: rbr logical page error", channel)); 30893859Sml29623 } 30903859Sml29623 if (cs.bits.hdw.cfiglogpage) { 30913859Sml29623 rdc_stats->cfiglogpage++; 30923859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, portn, channel, 30936929Smisaki NXGE_FM_EREPORT_RDMC_CFIGLOGPAGE); 30943859Sml29623 rxchan_fatal = B_TRUE; 30953859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 30966929Smisaki "==> nxge_rx_err_evnts(channel %d): " 30976929Smisaki "fatal error: cfig logical page error", channel)); 30983859Sml29623 } 30993859Sml29623 31003859Sml29623 if (rxport_fatal) { 31013859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 31026495Sspeer " nxge_rx_err_evnts: fatal error on Port #%d\n", 31036495Sspeer portn)); 31046495Sspeer if (isLDOMguest(nxgep)) { 31056495Sspeer status = NXGE_ERROR; 31066495Sspeer } else { 31076495Sspeer status = nxge_ipp_fatal_err_recover(nxgep); 31086495Sspeer if (status == NXGE_OK) { 31096495Sspeer FM_SERVICE_RESTORED(nxgep); 31106495Sspeer } 31113859Sml29623 } 31123859Sml29623 } 31133859Sml29623 31143859Sml29623 if (rxchan_fatal) { 31153859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 31166495Sspeer " nxge_rx_err_evnts: fatal error on Channel #%d\n", 31176495Sspeer channel)); 31186495Sspeer if (isLDOMguest(nxgep)) { 31196495Sspeer status = NXGE_ERROR; 31206495Sspeer } else { 31216495Sspeer status = nxge_rxdma_fatal_err_recover(nxgep, channel); 31226495Sspeer if (status == NXGE_OK) { 31236495Sspeer FM_SERVICE_RESTORED(nxgep); 31246495Sspeer } 31253859Sml29623 } 31263859Sml29623 } 31273859Sml29623 31283859Sml29623 NXGE_DEBUG_MSG((nxgep, RX2_CTL, "<== nxge_rx_err_evnts")); 31293859Sml29623 31303859Sml29623 return (status); 31313859Sml29623 } 31323859Sml29623 31336495Sspeer /* 31346495Sspeer * nxge_rdc_hvio_setup 31356495Sspeer * 31366495Sspeer * This code appears to setup some Hypervisor variables. 31376495Sspeer * 31386495Sspeer * Arguments: 31396495Sspeer * nxgep 31406495Sspeer * channel 31416495Sspeer * 31426495Sspeer * Notes: 31436495Sspeer * What does NIU_LP_WORKAROUND mean? 31446495Sspeer * 31456495Sspeer * NPI/NXGE function calls: 31466495Sspeer * na 31476495Sspeer * 31486495Sspeer * Context: 31496495Sspeer * Any domain 31506495Sspeer */ 31516495Sspeer #if defined(sun4v) && defined(NIU_LP_WORKAROUND) 31526495Sspeer static void 31536495Sspeer nxge_rdc_hvio_setup( 31546495Sspeer nxge_t *nxgep, int channel) 31553859Sml29623 { 31566495Sspeer nxge_dma_common_t *dma_common; 31576495Sspeer nxge_dma_common_t *dma_control; 31586495Sspeer rx_rbr_ring_t *ring; 31596495Sspeer 31606495Sspeer ring = nxgep->rx_rbr_rings->rbr_rings[channel]; 31616495Sspeer dma_common = nxgep->rx_buf_pool_p->dma_buf_pool_p[channel]; 31626495Sspeer 31636495Sspeer ring->hv_set = B_FALSE; 31646495Sspeer 31656495Sspeer ring->hv_rx_buf_base_ioaddr_pp = (uint64_t) 31666495Sspeer dma_common->orig_ioaddr_pp; 31676495Sspeer ring->hv_rx_buf_ioaddr_size = (uint64_t) 31686495Sspeer dma_common->orig_alength; 31696495Sspeer 31706495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_map_rxdma_channel: " 31716495Sspeer "channel %d data buf base io $%lx ($%p) size 0x%lx (%ld 0x%lx)", 31726495Sspeer channel, ring->hv_rx_buf_base_ioaddr_pp, 31736495Sspeer dma_common->ioaddr_pp, ring->hv_rx_buf_ioaddr_size, 31746495Sspeer dma_common->orig_alength, dma_common->orig_alength)); 31756495Sspeer 31766495Sspeer dma_control = nxgep->rx_cntl_pool_p->dma_buf_pool_p[channel]; 31776495Sspeer 31786495Sspeer ring->hv_rx_cntl_base_ioaddr_pp = 31796495Sspeer (uint64_t)dma_control->orig_ioaddr_pp; 31806495Sspeer ring->hv_rx_cntl_ioaddr_size = 31816495Sspeer (uint64_t)dma_control->orig_alength; 31826495Sspeer 31836495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_map_rxdma_channel: " 31846495Sspeer "channel %d cntl base io $%p ($%p) size 0x%llx (%d 0x%x)", 31856495Sspeer channel, ring->hv_rx_cntl_base_ioaddr_pp, 31866495Sspeer dma_control->ioaddr_pp, ring->hv_rx_cntl_ioaddr_size, 31876495Sspeer dma_control->orig_alength, dma_control->orig_alength)); 31886495Sspeer } 31893859Sml29623 #endif 31903859Sml29623 31916495Sspeer /* 31926495Sspeer * nxge_map_rxdma 31936495Sspeer * 31946495Sspeer * Map an RDC into our kernel space. 31956495Sspeer * 31966495Sspeer * Arguments: 31976495Sspeer * nxgep 31986495Sspeer * channel The channel to map. 31996495Sspeer * 32006495Sspeer * Notes: 32016495Sspeer * 1. Allocate & initialise a memory pool, if necessary. 32026495Sspeer * 2. Allocate however many receive buffers are required. 32036495Sspeer * 3. Setup buffers, descriptors, and mailbox. 32046495Sspeer * 32056495Sspeer * NPI/NXGE function calls: 32066495Sspeer * nxge_alloc_rx_mem_pool() 32076495Sspeer * nxge_alloc_rbb() 32086495Sspeer * nxge_map_rxdma_channel() 32096495Sspeer * 32106495Sspeer * Registers accessed: 32116495Sspeer * 32126495Sspeer * Context: 32136495Sspeer * Any domain 32146495Sspeer */ 32156495Sspeer static nxge_status_t 32166495Sspeer nxge_map_rxdma(p_nxge_t nxgep, int channel) 32176495Sspeer { 32186495Sspeer nxge_dma_common_t **data; 32196495Sspeer nxge_dma_common_t **control; 32206495Sspeer rx_rbr_ring_t **rbr_ring; 32216495Sspeer rx_rcr_ring_t **rcr_ring; 32226495Sspeer rx_mbox_t **mailbox; 32236495Sspeer uint32_t chunks; 32246495Sspeer 32256495Sspeer nxge_status_t status; 32266495Sspeer 32273859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_map_rxdma")); 32283859Sml29623 32296495Sspeer if (!nxgep->rx_buf_pool_p) { 32306495Sspeer if (nxge_alloc_rx_mem_pool(nxgep) != NXGE_OK) { 32316495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 32326495Sspeer "<== nxge_map_rxdma: buf not allocated")); 32336495Sspeer return (NXGE_ERROR); 32346495Sspeer } 32353859Sml29623 } 32363859Sml29623 32376495Sspeer if (nxge_alloc_rxb(nxgep, channel) != NXGE_OK) 32386495Sspeer return (NXGE_ERROR); 32393859Sml29623 32403859Sml29623 /* 32416495Sspeer * Map descriptors from the buffer polls for each dma channel. 32426495Sspeer */ 32436495Sspeer 32446495Sspeer /* 32456495Sspeer * Set up and prepare buffer blocks, descriptors 32466495Sspeer * and mailbox. 32473859Sml29623 */ 32486495Sspeer data = &nxgep->rx_buf_pool_p->dma_buf_pool_p[channel]; 32496495Sspeer rbr_ring = &nxgep->rx_rbr_rings->rbr_rings[channel]; 32506495Sspeer chunks = nxgep->rx_buf_pool_p->num_chunks[channel]; 32516495Sspeer 32526495Sspeer control = &nxgep->rx_cntl_pool_p->dma_buf_pool_p[channel]; 32536495Sspeer rcr_ring = &nxgep->rx_rcr_rings->rcr_rings[channel]; 32546495Sspeer 32556495Sspeer mailbox = &nxgep->rx_mbox_areas_p->rxmbox_areas[channel]; 32566495Sspeer 32576495Sspeer status = nxge_map_rxdma_channel(nxgep, channel, data, rbr_ring, 32586495Sspeer chunks, control, rcr_ring, mailbox); 32596495Sspeer if (status != NXGE_OK) { 32606495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 32616929Smisaki "==> nxge_map_rxdma: nxge_map_rxdma_channel(%d) " 32626929Smisaki "returned 0x%x", 32636929Smisaki channel, status)); 32646495Sspeer return (status); 32656495Sspeer } 32666495Sspeer nxgep->rx_rbr_rings->rbr_rings[channel]->index = (uint16_t)channel; 32676495Sspeer nxgep->rx_rcr_rings->rcr_rings[channel]->index = (uint16_t)channel; 32686495Sspeer nxgep->rx_rcr_rings->rcr_rings[channel]->rdc_stats = 32696495Sspeer &nxgep->statsp->rdc_stats[channel]; 32703859Sml29623 32713859Sml29623 #if defined(sun4v) && defined(NIU_LP_WORKAROUND) 32726495Sspeer if (!isLDOMguest(nxgep)) 32736495Sspeer nxge_rdc_hvio_setup(nxgep, channel); 32746495Sspeer #endif 32756495Sspeer 32763859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 32776495Sspeer "<== nxge_map_rxdma: (status 0x%x channel %d)", status, channel)); 32783859Sml29623 32793859Sml29623 return (status); 32803859Sml29623 } 32813859Sml29623 32823859Sml29623 static void 32836495Sspeer nxge_unmap_rxdma(p_nxge_t nxgep, int channel) 32843859Sml29623 { 32856495Sspeer rx_rbr_ring_t *rbr_ring; 32866495Sspeer rx_rcr_ring_t *rcr_ring; 32876495Sspeer rx_mbox_t *mailbox; 32886495Sspeer 32896495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_unmap_rxdma(%d)", channel)); 32906495Sspeer 32916495Sspeer if (!nxgep->rx_rbr_rings || !nxgep->rx_rcr_rings || 32926495Sspeer !nxgep->rx_mbox_areas_p) 32933859Sml29623 return; 32946495Sspeer 32956495Sspeer rbr_ring = nxgep->rx_rbr_rings->rbr_rings[channel]; 32966495Sspeer rcr_ring = nxgep->rx_rcr_rings->rcr_rings[channel]; 32976495Sspeer mailbox = nxgep->rx_mbox_areas_p->rxmbox_areas[channel]; 32986495Sspeer 32996495Sspeer if (!rbr_ring || !rcr_ring || !mailbox) 33003859Sml29623 return; 33016495Sspeer 33026495Sspeer (void) nxge_unmap_rxdma_channel( 33036929Smisaki nxgep, channel, rbr_ring, rcr_ring, mailbox); 33046495Sspeer 33056495Sspeer nxge_free_rxb(nxgep, channel); 33066495Sspeer 33076495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "<== nxge_unmap_rxdma")); 33083859Sml29623 } 33093859Sml29623 33103859Sml29623 nxge_status_t 33113859Sml29623 nxge_map_rxdma_channel(p_nxge_t nxgep, uint16_t channel, 33123859Sml29623 p_nxge_dma_common_t *dma_buf_p, p_rx_rbr_ring_t *rbr_p, 33133859Sml29623 uint32_t num_chunks, 33143859Sml29623 p_nxge_dma_common_t *dma_cntl_p, p_rx_rcr_ring_t *rcr_p, 33153859Sml29623 p_rx_mbox_t *rx_mbox_p) 33163859Sml29623 { 33173859Sml29623 int status = NXGE_OK; 33183859Sml29623 33193859Sml29623 /* 33203859Sml29623 * Set up and prepare buffer blocks, descriptors 33213859Sml29623 * and mailbox. 33223859Sml29623 */ 33233859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 33246929Smisaki "==> nxge_map_rxdma_channel (channel %d)", channel)); 33253859Sml29623 /* 33263859Sml29623 * Receive buffer blocks 33273859Sml29623 */ 33283859Sml29623 status = nxge_map_rxdma_channel_buf_ring(nxgep, channel, 33296929Smisaki dma_buf_p, rbr_p, num_chunks); 33303859Sml29623 if (status != NXGE_OK) { 33313859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 33326929Smisaki "==> nxge_map_rxdma_channel (channel %d): " 33336929Smisaki "map buffer failed 0x%x", channel, status)); 33343859Sml29623 goto nxge_map_rxdma_channel_exit; 33353859Sml29623 } 33363859Sml29623 33373859Sml29623 /* 33383859Sml29623 * Receive block ring, completion ring and mailbox. 33393859Sml29623 */ 33403859Sml29623 status = nxge_map_rxdma_channel_cfg_ring(nxgep, channel, 33416929Smisaki dma_cntl_p, rbr_p, rcr_p, rx_mbox_p); 33423859Sml29623 if (status != NXGE_OK) { 33433859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 33446929Smisaki "==> nxge_map_rxdma_channel (channel %d): " 33456929Smisaki "map config failed 0x%x", channel, status)); 33463859Sml29623 goto nxge_map_rxdma_channel_fail2; 33473859Sml29623 } 33483859Sml29623 33493859Sml29623 goto nxge_map_rxdma_channel_exit; 33503859Sml29623 33513859Sml29623 nxge_map_rxdma_channel_fail3: 33523859Sml29623 /* Free rbr, rcr */ 33533859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 33546929Smisaki "==> nxge_map_rxdma_channel: free rbr/rcr " 33556929Smisaki "(status 0x%x channel %d)", 33566929Smisaki status, channel)); 33573859Sml29623 nxge_unmap_rxdma_channel_cfg_ring(nxgep, 33586929Smisaki *rcr_p, *rx_mbox_p); 33593859Sml29623 33603859Sml29623 nxge_map_rxdma_channel_fail2: 33613859Sml29623 /* Free buffer blocks */ 33623859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 33636929Smisaki "==> nxge_map_rxdma_channel: free rx buffers" 33646929Smisaki "(nxgep 0x%x status 0x%x channel %d)", 33656929Smisaki nxgep, status, channel)); 33663859Sml29623 nxge_unmap_rxdma_channel_buf_ring(nxgep, *rbr_p); 33673859Sml29623 33684185Sspeer status = NXGE_ERROR; 33694185Sspeer 33703859Sml29623 nxge_map_rxdma_channel_exit: 33713859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 33726929Smisaki "<== nxge_map_rxdma_channel: " 33736929Smisaki "(nxgep 0x%x status 0x%x channel %d)", 33746929Smisaki nxgep, status, channel)); 33753859Sml29623 33763859Sml29623 return (status); 33773859Sml29623 } 33783859Sml29623 33793859Sml29623 /*ARGSUSED*/ 33803859Sml29623 static void 33813859Sml29623 nxge_unmap_rxdma_channel(p_nxge_t nxgep, uint16_t channel, 33823859Sml29623 p_rx_rbr_ring_t rbr_p, p_rx_rcr_ring_t rcr_p, p_rx_mbox_t rx_mbox_p) 33833859Sml29623 { 33843859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 33856929Smisaki "==> nxge_unmap_rxdma_channel (channel %d)", channel)); 33863859Sml29623 33873859Sml29623 /* 33883859Sml29623 * unmap receive block ring, completion ring and mailbox. 33893859Sml29623 */ 33903859Sml29623 (void) nxge_unmap_rxdma_channel_cfg_ring(nxgep, 33916929Smisaki rcr_p, rx_mbox_p); 33923859Sml29623 33933859Sml29623 /* unmap buffer blocks */ 33943859Sml29623 (void) nxge_unmap_rxdma_channel_buf_ring(nxgep, rbr_p); 33953859Sml29623 33963859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "<== nxge_unmap_rxdma_channel")); 33973859Sml29623 } 33983859Sml29623 33993859Sml29623 /*ARGSUSED*/ 34003859Sml29623 static nxge_status_t 34013859Sml29623 nxge_map_rxdma_channel_cfg_ring(p_nxge_t nxgep, uint16_t dma_channel, 34023859Sml29623 p_nxge_dma_common_t *dma_cntl_p, p_rx_rbr_ring_t *rbr_p, 34033859Sml29623 p_rx_rcr_ring_t *rcr_p, p_rx_mbox_t *rx_mbox_p) 34043859Sml29623 { 34053859Sml29623 p_rx_rbr_ring_t rbrp; 34063859Sml29623 p_rx_rcr_ring_t rcrp; 34073859Sml29623 p_rx_mbox_t mboxp; 34083859Sml29623 p_nxge_dma_common_t cntl_dmap; 34093859Sml29623 p_nxge_dma_common_t dmap; 34103859Sml29623 p_rx_msg_t *rx_msg_ring; 34113859Sml29623 p_rx_msg_t rx_msg_p; 34123859Sml29623 p_rbr_cfig_a_t rcfga_p; 34133859Sml29623 p_rbr_cfig_b_t rcfgb_p; 34143859Sml29623 p_rcrcfig_a_t cfga_p; 34153859Sml29623 p_rcrcfig_b_t cfgb_p; 34163859Sml29623 p_rxdma_cfig1_t cfig1_p; 34173859Sml29623 p_rxdma_cfig2_t cfig2_p; 34183859Sml29623 p_rbr_kick_t kick_p; 34193859Sml29623 uint32_t dmaaddrp; 34203859Sml29623 uint32_t *rbr_vaddrp; 34213859Sml29623 uint32_t bkaddr; 34223859Sml29623 nxge_status_t status = NXGE_OK; 34233859Sml29623 int i; 34243859Sml29623 uint32_t nxge_port_rcr_size; 34253859Sml29623 34263859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 34276929Smisaki "==> nxge_map_rxdma_channel_cfg_ring")); 34283859Sml29623 34293859Sml29623 cntl_dmap = *dma_cntl_p; 34303859Sml29623 34313859Sml29623 /* Map in the receive block ring */ 34323859Sml29623 rbrp = *rbr_p; 34333859Sml29623 dmap = (p_nxge_dma_common_t)&rbrp->rbr_desc; 34343859Sml29623 nxge_setup_dma_common(dmap, cntl_dmap, rbrp->rbb_max, 4); 34353859Sml29623 /* 34363859Sml29623 * Zero out buffer block ring descriptors. 34373859Sml29623 */ 34383859Sml29623 bzero((caddr_t)dmap->kaddrp, dmap->alength); 34393859Sml29623 34403859Sml29623 rcfga_p = &(rbrp->rbr_cfga); 34413859Sml29623 rcfgb_p = &(rbrp->rbr_cfgb); 34423859Sml29623 kick_p = &(rbrp->rbr_kick); 34433859Sml29623 rcfga_p->value = 0; 34443859Sml29623 rcfgb_p->value = 0; 34453859Sml29623 kick_p->value = 0; 34463859Sml29623 rbrp->rbr_addr = dmap->dma_cookie.dmac_laddress; 34473859Sml29623 rcfga_p->value = (rbrp->rbr_addr & 34486929Smisaki (RBR_CFIG_A_STDADDR_MASK | 34496929Smisaki RBR_CFIG_A_STDADDR_BASE_MASK)); 34503859Sml29623 rcfga_p->value |= ((uint64_t)rbrp->rbb_max << RBR_CFIG_A_LEN_SHIFT); 34513859Sml29623 34523859Sml29623 rcfgb_p->bits.ldw.bufsz0 = rbrp->pkt_buf_size0; 34533859Sml29623 rcfgb_p->bits.ldw.vld0 = 1; 34543859Sml29623 rcfgb_p->bits.ldw.bufsz1 = rbrp->pkt_buf_size1; 34553859Sml29623 rcfgb_p->bits.ldw.vld1 = 1; 34563859Sml29623 rcfgb_p->bits.ldw.bufsz2 = rbrp->pkt_buf_size2; 34573859Sml29623 rcfgb_p->bits.ldw.vld2 = 1; 34583859Sml29623 rcfgb_p->bits.ldw.bksize = nxgep->rx_bksize_code; 34593859Sml29623 34603859Sml29623 /* 34613859Sml29623 * For each buffer block, enter receive block address to the ring. 34623859Sml29623 */ 34633859Sml29623 rbr_vaddrp = (uint32_t *)dmap->kaddrp; 34643859Sml29623 rbrp->rbr_desc_vp = (uint32_t *)dmap->kaddrp; 34653859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 34666929Smisaki "==> nxge_map_rxdma_channel_cfg_ring: channel %d " 34676929Smisaki "rbr_vaddrp $%p", dma_channel, rbr_vaddrp)); 34683859Sml29623 34693859Sml29623 rx_msg_ring = rbrp->rx_msg_ring; 34703859Sml29623 for (i = 0; i < rbrp->tnblocks; i++) { 34713859Sml29623 rx_msg_p = rx_msg_ring[i]; 34723859Sml29623 rx_msg_p->nxgep = nxgep; 34733859Sml29623 rx_msg_p->rx_rbr_p = rbrp; 34743859Sml29623 bkaddr = (uint32_t) 34756929Smisaki ((rx_msg_p->buf_dma.dma_cookie.dmac_laddress 34766929Smisaki >> RBR_BKADDR_SHIFT)); 34773859Sml29623 rx_msg_p->free = B_FALSE; 34783859Sml29623 rx_msg_p->max_usage_cnt = 0xbaddcafe; 34793859Sml29623 34803859Sml29623 *rbr_vaddrp++ = bkaddr; 34813859Sml29623 } 34823859Sml29623 34833859Sml29623 kick_p->bits.ldw.bkadd = rbrp->rbb_max; 34843859Sml29623 rbrp->rbr_wr_index = (rbrp->rbb_max - 1); 34853859Sml29623 34863859Sml29623 rbrp->rbr_rd_index = 0; 34873859Sml29623 34883859Sml29623 rbrp->rbr_consumed = 0; 34893859Sml29623 rbrp->rbr_use_bcopy = B_TRUE; 34903859Sml29623 rbrp->rbr_bufsize_type = RCR_PKTBUFSZ_0; 34913859Sml29623 /* 34923859Sml29623 * Do bcopy on packets greater than bcopy size once 34933859Sml29623 * the lo threshold is reached. 34943859Sml29623 * This lo threshold should be less than the hi threshold. 34953859Sml29623 * 34963859Sml29623 * Do bcopy on every packet once the hi threshold is reached. 34973859Sml29623 */ 34983859Sml29623 if (nxge_rx_threshold_lo >= nxge_rx_threshold_hi) { 34993859Sml29623 /* default it to use hi */ 35003859Sml29623 nxge_rx_threshold_lo = nxge_rx_threshold_hi; 35013859Sml29623 } 35023859Sml29623 35033859Sml29623 if (nxge_rx_buf_size_type > NXGE_RBR_TYPE2) { 35043859Sml29623 nxge_rx_buf_size_type = NXGE_RBR_TYPE2; 35053859Sml29623 } 35063859Sml29623 rbrp->rbr_bufsize_type = nxge_rx_buf_size_type; 35073859Sml29623 35083859Sml29623 switch (nxge_rx_threshold_hi) { 35093859Sml29623 default: 35103859Sml29623 case NXGE_RX_COPY_NONE: 35113859Sml29623 /* Do not do bcopy at all */ 35123859Sml29623 rbrp->rbr_use_bcopy = B_FALSE; 35133859Sml29623 rbrp->rbr_threshold_hi = rbrp->rbb_max; 35143859Sml29623 break; 35153859Sml29623 35163859Sml29623 case NXGE_RX_COPY_1: 35173859Sml29623 case NXGE_RX_COPY_2: 35183859Sml29623 case NXGE_RX_COPY_3: 35193859Sml29623 case NXGE_RX_COPY_4: 35203859Sml29623 case NXGE_RX_COPY_5: 35213859Sml29623 case NXGE_RX_COPY_6: 35223859Sml29623 case NXGE_RX_COPY_7: 35233859Sml29623 rbrp->rbr_threshold_hi = 35246929Smisaki rbrp->rbb_max * 35256929Smisaki (nxge_rx_threshold_hi)/NXGE_RX_BCOPY_SCALE; 35263859Sml29623 break; 35273859Sml29623 35283859Sml29623 case NXGE_RX_COPY_ALL: 35293859Sml29623 rbrp->rbr_threshold_hi = 0; 35303859Sml29623 break; 35313859Sml29623 } 35323859Sml29623 35333859Sml29623 switch (nxge_rx_threshold_lo) { 35343859Sml29623 default: 35353859Sml29623 case NXGE_RX_COPY_NONE: 35363859Sml29623 /* Do not do bcopy at all */ 35373859Sml29623 if (rbrp->rbr_use_bcopy) { 35383859Sml29623 rbrp->rbr_use_bcopy = B_FALSE; 35393859Sml29623 } 35403859Sml29623 rbrp->rbr_threshold_lo = rbrp->rbb_max; 35413859Sml29623 break; 35423859Sml29623 35433859Sml29623 case NXGE_RX_COPY_1: 35443859Sml29623 case NXGE_RX_COPY_2: 35453859Sml29623 case NXGE_RX_COPY_3: 35463859Sml29623 case NXGE_RX_COPY_4: 35473859Sml29623 case NXGE_RX_COPY_5: 35483859Sml29623 case NXGE_RX_COPY_6: 35493859Sml29623 case NXGE_RX_COPY_7: 35503859Sml29623 rbrp->rbr_threshold_lo = 35516929Smisaki rbrp->rbb_max * 35526929Smisaki (nxge_rx_threshold_lo)/NXGE_RX_BCOPY_SCALE; 35533859Sml29623 break; 35543859Sml29623 35553859Sml29623 case NXGE_RX_COPY_ALL: 35563859Sml29623 rbrp->rbr_threshold_lo = 0; 35573859Sml29623 break; 35583859Sml29623 } 35593859Sml29623 35603859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 35616929Smisaki "nxge_map_rxdma_channel_cfg_ring: channel %d " 35626929Smisaki "rbb_max %d " 35636929Smisaki "rbrp->rbr_bufsize_type %d " 35646929Smisaki "rbb_threshold_hi %d " 35656929Smisaki "rbb_threshold_lo %d", 35666929Smisaki dma_channel, 35676929Smisaki rbrp->rbb_max, 35686929Smisaki rbrp->rbr_bufsize_type, 35696929Smisaki rbrp->rbr_threshold_hi, 35706929Smisaki rbrp->rbr_threshold_lo)); 35713859Sml29623 35723859Sml29623 rbrp->page_valid.value = 0; 35733859Sml29623 rbrp->page_mask_1.value = rbrp->page_mask_2.value = 0; 35743859Sml29623 rbrp->page_value_1.value = rbrp->page_value_2.value = 0; 35753859Sml29623 rbrp->page_reloc_1.value = rbrp->page_reloc_2.value = 0; 35763859Sml29623 rbrp->page_hdl.value = 0; 35773859Sml29623 35783859Sml29623 rbrp->page_valid.bits.ldw.page0 = 1; 35793859Sml29623 rbrp->page_valid.bits.ldw.page1 = 1; 35803859Sml29623 35813859Sml29623 /* Map in the receive completion ring */ 35823859Sml29623 rcrp = (p_rx_rcr_ring_t) 35836929Smisaki KMEM_ZALLOC(sizeof (rx_rcr_ring_t), KM_SLEEP); 35843859Sml29623 rcrp->rdc = dma_channel; 35853859Sml29623 35863859Sml29623 nxge_port_rcr_size = nxgep->nxge_port_rcr_size; 35873859Sml29623 rcrp->comp_size = nxge_port_rcr_size; 35883859Sml29623 rcrp->comp_wrap_mask = nxge_port_rcr_size - 1; 35893859Sml29623 35903859Sml29623 rcrp->max_receive_pkts = nxge_max_rx_pkts; 35913859Sml29623 35923859Sml29623 dmap = (p_nxge_dma_common_t)&rcrp->rcr_desc; 35933859Sml29623 nxge_setup_dma_common(dmap, cntl_dmap, rcrp->comp_size, 35946929Smisaki sizeof (rcr_entry_t)); 35953859Sml29623 rcrp->comp_rd_index = 0; 35963859Sml29623 rcrp->comp_wt_index = 0; 35973859Sml29623 rcrp->rcr_desc_rd_head_p = rcrp->rcr_desc_first_p = 35986929Smisaki (p_rcr_entry_t)DMA_COMMON_VPTR(rcrp->rcr_desc); 35995125Sjoycey #if defined(__i386) 36006929Smisaki rcrp->rcr_desc_rd_head_pp = rcrp->rcr_desc_first_pp = 36016929Smisaki (p_rcr_entry_t)(uint32_t)DMA_COMMON_IOADDR(rcrp->rcr_desc); 36025125Sjoycey #else 36036929Smisaki rcrp->rcr_desc_rd_head_pp = rcrp->rcr_desc_first_pp = 36046929Smisaki (p_rcr_entry_t)DMA_COMMON_IOADDR(rcrp->rcr_desc); 36055125Sjoycey #endif 36063859Sml29623 36073859Sml29623 rcrp->rcr_desc_last_p = rcrp->rcr_desc_rd_head_p + 36086929Smisaki (nxge_port_rcr_size - 1); 36093859Sml29623 rcrp->rcr_desc_last_pp = rcrp->rcr_desc_rd_head_pp + 36106929Smisaki (nxge_port_rcr_size - 1); 36113859Sml29623 36123859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 36136929Smisaki "==> nxge_map_rxdma_channel_cfg_ring: " 36146929Smisaki "channel %d " 36156929Smisaki "rbr_vaddrp $%p " 36166929Smisaki "rcr_desc_rd_head_p $%p " 36176929Smisaki "rcr_desc_rd_head_pp $%p " 36186929Smisaki "rcr_desc_rd_last_p $%p " 36196929Smisaki "rcr_desc_rd_last_pp $%p ", 36206929Smisaki dma_channel, 36216929Smisaki rbr_vaddrp, 36226929Smisaki rcrp->rcr_desc_rd_head_p, 36236929Smisaki rcrp->rcr_desc_rd_head_pp, 36246929Smisaki rcrp->rcr_desc_last_p, 36256929Smisaki rcrp->rcr_desc_last_pp)); 36263859Sml29623 36273859Sml29623 /* 36283859Sml29623 * Zero out buffer block ring descriptors. 36293859Sml29623 */ 36303859Sml29623 bzero((caddr_t)dmap->kaddrp, dmap->alength); 36318661SSantwona.Behera@Sun.COM 36328661SSantwona.Behera@Sun.COM rcrp->intr_timeout = (nxgep->intr_timeout < 36338661SSantwona.Behera@Sun.COM NXGE_RDC_RCR_TIMEOUT_MIN) ? NXGE_RDC_RCR_TIMEOUT_MIN : 36348661SSantwona.Behera@Sun.COM nxgep->intr_timeout; 36358661SSantwona.Behera@Sun.COM 36368661SSantwona.Behera@Sun.COM rcrp->intr_threshold = (nxgep->intr_threshold < 36378661SSantwona.Behera@Sun.COM NXGE_RDC_RCR_THRESHOLD_MIN) ? NXGE_RDC_RCR_THRESHOLD_MIN : 36388661SSantwona.Behera@Sun.COM nxgep->intr_threshold; 36398661SSantwona.Behera@Sun.COM 36403859Sml29623 rcrp->full_hdr_flag = B_FALSE; 3641*11304SJanie.Lu@Sun.COM 3642*11304SJanie.Lu@Sun.COM rcrp->sw_priv_hdr_len = nxge_rdc_buf_offset; 3643*11304SJanie.Lu@Sun.COM 36443859Sml29623 36453859Sml29623 cfga_p = &(rcrp->rcr_cfga); 36463859Sml29623 cfgb_p = &(rcrp->rcr_cfgb); 36473859Sml29623 cfga_p->value = 0; 36483859Sml29623 cfgb_p->value = 0; 36493859Sml29623 rcrp->rcr_addr = dmap->dma_cookie.dmac_laddress; 36503859Sml29623 cfga_p->value = (rcrp->rcr_addr & 36516929Smisaki (RCRCFIG_A_STADDR_MASK | 36526929Smisaki RCRCFIG_A_STADDR_BASE_MASK)); 36533859Sml29623 36543859Sml29623 rcfga_p->value |= ((uint64_t)rcrp->comp_size << 36556929Smisaki RCRCFIG_A_LEN_SHIF); 36563859Sml29623 36573859Sml29623 /* 36583859Sml29623 * Timeout should be set based on the system clock divider. 36598661SSantwona.Behera@Sun.COM * A timeout value of 1 assumes that the 36603859Sml29623 * granularity (1000) is 3 microseconds running at 300MHz. 36613859Sml29623 */ 36623859Sml29623 cfgb_p->bits.ldw.pthres = rcrp->intr_threshold; 36633859Sml29623 cfgb_p->bits.ldw.timeout = rcrp->intr_timeout; 36643859Sml29623 cfgb_p->bits.ldw.entout = 1; 36653859Sml29623 36663859Sml29623 /* Map in the mailbox */ 36673859Sml29623 mboxp = (p_rx_mbox_t) 36686929Smisaki KMEM_ZALLOC(sizeof (rx_mbox_t), KM_SLEEP); 36693859Sml29623 dmap = (p_nxge_dma_common_t)&mboxp->rx_mbox; 36703859Sml29623 nxge_setup_dma_common(dmap, cntl_dmap, 1, sizeof (rxdma_mailbox_t)); 36713859Sml29623 cfig1_p = (p_rxdma_cfig1_t)&mboxp->rx_cfg1; 36723859Sml29623 cfig2_p = (p_rxdma_cfig2_t)&mboxp->rx_cfg2; 36733859Sml29623 cfig1_p->value = cfig2_p->value = 0; 36743859Sml29623 36753859Sml29623 mboxp->mbox_addr = dmap->dma_cookie.dmac_laddress; 36763859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 36776929Smisaki "==> nxge_map_rxdma_channel_cfg_ring: " 36786929Smisaki "channel %d cfg1 0x%016llx cfig2 0x%016llx cookie 0x%016llx", 36796929Smisaki dma_channel, cfig1_p->value, cfig2_p->value, 36806929Smisaki mboxp->mbox_addr)); 36813859Sml29623 36823859Sml29623 dmaaddrp = (uint32_t)(dmap->dma_cookie.dmac_laddress >> 32 36836929Smisaki & 0xfff); 36843859Sml29623 cfig1_p->bits.ldw.mbaddr_h = dmaaddrp; 36853859Sml29623 36863859Sml29623 36873859Sml29623 dmaaddrp = (uint32_t)(dmap->dma_cookie.dmac_laddress & 0xffffffff); 36883859Sml29623 dmaaddrp = (uint32_t)(dmap->dma_cookie.dmac_laddress & 36896929Smisaki RXDMA_CFIG2_MBADDR_L_MASK); 36903859Sml29623 36913859Sml29623 cfig2_p->bits.ldw.mbaddr = (dmaaddrp >> RXDMA_CFIG2_MBADDR_L_SHIFT); 36923859Sml29623 36933859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 36946929Smisaki "==> nxge_map_rxdma_channel_cfg_ring: " 36956929Smisaki "channel %d damaddrp $%p " 36966929Smisaki "cfg1 0x%016llx cfig2 0x%016llx", 36976929Smisaki dma_channel, dmaaddrp, 36986929Smisaki cfig1_p->value, cfig2_p->value)); 36993859Sml29623 37003859Sml29623 cfig2_p->bits.ldw.full_hdr = rcrp->full_hdr_flag; 3701*11304SJanie.Lu@Sun.COM if (nxgep->niu_hw_type == NIU_HW_TYPE_RF) { 3702*11304SJanie.Lu@Sun.COM switch (rcrp->sw_priv_hdr_len) { 3703*11304SJanie.Lu@Sun.COM case SW_OFFSET_NO_OFFSET: 3704*11304SJanie.Lu@Sun.COM case SW_OFFSET_64: 3705*11304SJanie.Lu@Sun.COM case SW_OFFSET_128: 3706*11304SJanie.Lu@Sun.COM case SW_OFFSET_192: 3707*11304SJanie.Lu@Sun.COM cfig2_p->bits.ldw.offset = 3708*11304SJanie.Lu@Sun.COM rcrp->sw_priv_hdr_len; 3709*11304SJanie.Lu@Sun.COM cfig2_p->bits.ldw.offset256 = 0; 3710*11304SJanie.Lu@Sun.COM break; 3711*11304SJanie.Lu@Sun.COM case SW_OFFSET_256: 3712*11304SJanie.Lu@Sun.COM case SW_OFFSET_320: 3713*11304SJanie.Lu@Sun.COM case SW_OFFSET_384: 3714*11304SJanie.Lu@Sun.COM case SW_OFFSET_448: 3715*11304SJanie.Lu@Sun.COM cfig2_p->bits.ldw.offset = 3716*11304SJanie.Lu@Sun.COM rcrp->sw_priv_hdr_len & 0x3; 3717*11304SJanie.Lu@Sun.COM cfig2_p->bits.ldw.offset256 = 1; 3718*11304SJanie.Lu@Sun.COM break; 3719*11304SJanie.Lu@Sun.COM default: 3720*11304SJanie.Lu@Sun.COM cfig2_p->bits.ldw.offset = SW_OFFSET_NO_OFFSET; 3721*11304SJanie.Lu@Sun.COM cfig2_p->bits.ldw.offset256 = 0; 3722*11304SJanie.Lu@Sun.COM } 3723*11304SJanie.Lu@Sun.COM } else { 3724*11304SJanie.Lu@Sun.COM cfig2_p->bits.ldw.offset = rcrp->sw_priv_hdr_len; 3725*11304SJanie.Lu@Sun.COM } 37263859Sml29623 37273859Sml29623 rbrp->rx_rcr_p = rcrp; 37283859Sml29623 rcrp->rx_rbr_p = rbrp; 37293859Sml29623 *rcr_p = rcrp; 37303859Sml29623 *rx_mbox_p = mboxp; 37313859Sml29623 37323859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 37336929Smisaki "<== nxge_map_rxdma_channel_cfg_ring status 0x%08x", status)); 37343859Sml29623 37353859Sml29623 return (status); 37363859Sml29623 } 37373859Sml29623 37383859Sml29623 /*ARGSUSED*/ 37393859Sml29623 static void 37403859Sml29623 nxge_unmap_rxdma_channel_cfg_ring(p_nxge_t nxgep, 37413859Sml29623 p_rx_rcr_ring_t rcr_p, p_rx_mbox_t rx_mbox_p) 37423859Sml29623 { 37433859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 37446929Smisaki "==> nxge_unmap_rxdma_channel_cfg_ring: channel %d", 37456929Smisaki rcr_p->rdc)); 37463859Sml29623 37473859Sml29623 KMEM_FREE(rcr_p, sizeof (rx_rcr_ring_t)); 37483859Sml29623 KMEM_FREE(rx_mbox_p, sizeof (rx_mbox_t)); 37493859Sml29623 37503859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 37516929Smisaki "<== nxge_unmap_rxdma_channel_cfg_ring")); 37523859Sml29623 } 37533859Sml29623 37543859Sml29623 static nxge_status_t 37553859Sml29623 nxge_map_rxdma_channel_buf_ring(p_nxge_t nxgep, uint16_t channel, 37563859Sml29623 p_nxge_dma_common_t *dma_buf_p, 37573859Sml29623 p_rx_rbr_ring_t *rbr_p, uint32_t num_chunks) 37583859Sml29623 { 37593859Sml29623 p_rx_rbr_ring_t rbrp; 37603859Sml29623 p_nxge_dma_common_t dma_bufp, tmp_bufp; 37613859Sml29623 p_rx_msg_t *rx_msg_ring; 37623859Sml29623 p_rx_msg_t rx_msg_p; 37633859Sml29623 p_mblk_t mblk_p; 37643859Sml29623 37653859Sml29623 rxring_info_t *ring_info; 37663859Sml29623 nxge_status_t status = NXGE_OK; 37673859Sml29623 int i, j, index; 37683859Sml29623 uint32_t size, bsize, nblocks, nmsgs; 37693859Sml29623 37703859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 37716929Smisaki "==> nxge_map_rxdma_channel_buf_ring: channel %d", 37726929Smisaki channel)); 37733859Sml29623 37743859Sml29623 dma_bufp = tmp_bufp = *dma_buf_p; 37753859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 37766929Smisaki " nxge_map_rxdma_channel_buf_ring: channel %d to map %d " 37776929Smisaki "chunks bufp 0x%016llx", 37786929Smisaki channel, num_chunks, dma_bufp)); 37793859Sml29623 37803859Sml29623 nmsgs = 0; 37813859Sml29623 for (i = 0; i < num_chunks; i++, tmp_bufp++) { 37823859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 37836929Smisaki "==> nxge_map_rxdma_channel_buf_ring: channel %d " 37846929Smisaki "bufp 0x%016llx nblocks %d nmsgs %d", 37856929Smisaki channel, tmp_bufp, tmp_bufp->nblocks, nmsgs)); 37863859Sml29623 nmsgs += tmp_bufp->nblocks; 37873859Sml29623 } 37883859Sml29623 if (!nmsgs) { 37894185Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 37906929Smisaki "<== nxge_map_rxdma_channel_buf_ring: channel %d " 37916929Smisaki "no msg blocks", 37926929Smisaki channel)); 37933859Sml29623 status = NXGE_ERROR; 37943859Sml29623 goto nxge_map_rxdma_channel_buf_ring_exit; 37953859Sml29623 } 37963859Sml29623 37975170Stm144005 rbrp = (p_rx_rbr_ring_t)KMEM_ZALLOC(sizeof (*rbrp), KM_SLEEP); 37983859Sml29623 37993859Sml29623 size = nmsgs * sizeof (p_rx_msg_t); 38003859Sml29623 rx_msg_ring = KMEM_ZALLOC(size, KM_SLEEP); 38013859Sml29623 ring_info = (rxring_info_t *)KMEM_ZALLOC(sizeof (rxring_info_t), 38026929Smisaki KM_SLEEP); 38033859Sml29623 38043859Sml29623 MUTEX_INIT(&rbrp->lock, NULL, MUTEX_DRIVER, 38056929Smisaki (void *)nxgep->interrupt_cookie); 38063859Sml29623 MUTEX_INIT(&rbrp->post_lock, NULL, MUTEX_DRIVER, 38076929Smisaki (void *)nxgep->interrupt_cookie); 38083859Sml29623 rbrp->rdc = channel; 38093859Sml29623 rbrp->num_blocks = num_chunks; 38103859Sml29623 rbrp->tnblocks = nmsgs; 38113859Sml29623 rbrp->rbb_max = nmsgs; 38123859Sml29623 rbrp->rbr_max_size = nmsgs; 38133859Sml29623 rbrp->rbr_wrap_mask = (rbrp->rbb_max - 1); 38143859Sml29623 38153859Sml29623 /* 38163859Sml29623 * Buffer sizes suggested by NIU architect. 38173859Sml29623 * 256, 512 and 2K. 38183859Sml29623 */ 38193859Sml29623 38203859Sml29623 rbrp->pkt_buf_size0 = RBR_BUFSZ0_256B; 38213859Sml29623 rbrp->pkt_buf_size0_bytes = RBR_BUFSZ0_256_BYTES; 38223859Sml29623 rbrp->npi_pkt_buf_size0 = SIZE_256B; 38233859Sml29623 38243859Sml29623 rbrp->pkt_buf_size1 = RBR_BUFSZ1_1K; 38253859Sml29623 rbrp->pkt_buf_size1_bytes = RBR_BUFSZ1_1K_BYTES; 38263859Sml29623 rbrp->npi_pkt_buf_size1 = SIZE_1KB; 38273859Sml29623 38283859Sml29623 rbrp->block_size = nxgep->rx_default_block_size; 38293859Sml29623 38309730SMichael.Speer@Sun.COM if (!nxgep->mac.is_jumbo) { 38313859Sml29623 rbrp->pkt_buf_size2 = RBR_BUFSZ2_2K; 38323859Sml29623 rbrp->pkt_buf_size2_bytes = RBR_BUFSZ2_2K_BYTES; 38333859Sml29623 rbrp->npi_pkt_buf_size2 = SIZE_2KB; 38343859Sml29623 } else { 38353859Sml29623 if (rbrp->block_size >= 0x2000) { 38363859Sml29623 rbrp->pkt_buf_size2 = RBR_BUFSZ2_8K; 38373859Sml29623 rbrp->pkt_buf_size2_bytes = RBR_BUFSZ2_8K_BYTES; 38383859Sml29623 rbrp->npi_pkt_buf_size2 = SIZE_8KB; 38393859Sml29623 } else { 38403859Sml29623 rbrp->pkt_buf_size2 = RBR_BUFSZ2_4K; 38413859Sml29623 rbrp->pkt_buf_size2_bytes = RBR_BUFSZ2_4K_BYTES; 38423859Sml29623 rbrp->npi_pkt_buf_size2 = SIZE_4KB; 38433859Sml29623 } 38443859Sml29623 } 38453859Sml29623 38463859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 38476929Smisaki "==> nxge_map_rxdma_channel_buf_ring: channel %d " 38486929Smisaki "actual rbr max %d rbb_max %d nmsgs %d " 38496929Smisaki "rbrp->block_size %d default_block_size %d " 38506929Smisaki "(config nxge_rbr_size %d nxge_rbr_spare_size %d)", 38516929Smisaki channel, rbrp->rbr_max_size, rbrp->rbb_max, nmsgs, 38526929Smisaki rbrp->block_size, nxgep->rx_default_block_size, 38536929Smisaki nxge_rbr_size, nxge_rbr_spare_size)); 38543859Sml29623 38553859Sml29623 /* Map in buffers from the buffer pool. */ 38563859Sml29623 index = 0; 38573859Sml29623 for (i = 0; i < rbrp->num_blocks; i++, dma_bufp++) { 38583859Sml29623 bsize = dma_bufp->block_size; 38593859Sml29623 nblocks = dma_bufp->nblocks; 38605125Sjoycey #if defined(__i386) 38615125Sjoycey ring_info->buffer[i].dvma_addr = (uint32_t)dma_bufp->ioaddr_pp; 38625125Sjoycey #else 38633859Sml29623 ring_info->buffer[i].dvma_addr = (uint64_t)dma_bufp->ioaddr_pp; 38645125Sjoycey #endif 38653859Sml29623 ring_info->buffer[i].buf_index = i; 38663859Sml29623 ring_info->buffer[i].buf_size = dma_bufp->alength; 38673859Sml29623 ring_info->buffer[i].start_index = index; 38685125Sjoycey #if defined(__i386) 38695125Sjoycey ring_info->buffer[i].kaddr = (uint32_t)dma_bufp->kaddrp; 38705125Sjoycey #else 38713859Sml29623 ring_info->buffer[i].kaddr = (uint64_t)dma_bufp->kaddrp; 38725125Sjoycey #endif 38733859Sml29623 38743859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 38756929Smisaki " nxge_map_rxdma_channel_buf_ring: map channel %d " 38766929Smisaki "chunk %d" 38776929Smisaki " nblocks %d chunk_size %x block_size 0x%x " 38786929Smisaki "dma_bufp $%p", channel, i, 38796929Smisaki dma_bufp->nblocks, ring_info->buffer[i].buf_size, bsize, 38806929Smisaki dma_bufp)); 38813859Sml29623 38823859Sml29623 for (j = 0; j < nblocks; j++) { 38833859Sml29623 if ((rx_msg_p = nxge_allocb(bsize, BPRI_LO, 38846929Smisaki dma_bufp)) == NULL) { 38854185Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 38866929Smisaki "allocb failed (index %d i %d j %d)", 38876929Smisaki index, i, j)); 38884185Sspeer goto nxge_map_rxdma_channel_buf_ring_fail1; 38893859Sml29623 } 38903859Sml29623 rx_msg_ring[index] = rx_msg_p; 38913859Sml29623 rx_msg_p->block_index = index; 38923859Sml29623 rx_msg_p->shifted_addr = (uint32_t) 38936929Smisaki ((rx_msg_p->buf_dma.dma_cookie.dmac_laddress >> 38946929Smisaki RBR_BKADDR_SHIFT)); 38953859Sml29623 38963859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 38976929Smisaki "index %d j %d rx_msg_p $%p mblk %p", 38986929Smisaki index, j, rx_msg_p, rx_msg_p->rx_mblk_p)); 38993859Sml29623 39003859Sml29623 mblk_p = rx_msg_p->rx_mblk_p; 39013859Sml29623 mblk_p->b_wptr = mblk_p->b_rptr + bsize; 39025170Stm144005 39035170Stm144005 rbrp->rbr_ref_cnt++; 39043859Sml29623 index++; 39053859Sml29623 rx_msg_p->buf_dma.dma_channel = channel; 39063859Sml29623 } 39076495Sspeer 39086495Sspeer rbrp->rbr_alloc_type = DDI_MEM_ALLOC; 39096495Sspeer if (dma_bufp->contig_alloc_type) { 39106495Sspeer rbrp->rbr_alloc_type = CONTIG_MEM_ALLOC; 39116495Sspeer } 39126495Sspeer 39136495Sspeer if (dma_bufp->kmem_alloc_type) { 39146495Sspeer rbrp->rbr_alloc_type = KMEM_ALLOC; 39156495Sspeer } 39166495Sspeer 39176495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 39186495Sspeer " nxge_map_rxdma_channel_buf_ring: map channel %d " 39196495Sspeer "chunk %d" 39206495Sspeer " nblocks %d chunk_size %x block_size 0x%x " 39216495Sspeer "dma_bufp $%p", 39226495Sspeer channel, i, 39236495Sspeer dma_bufp->nblocks, ring_info->buffer[i].buf_size, bsize, 39246495Sspeer dma_bufp)); 39253859Sml29623 } 39263859Sml29623 if (i < rbrp->num_blocks) { 39273859Sml29623 goto nxge_map_rxdma_channel_buf_ring_fail1; 39283859Sml29623 } 39293859Sml29623 39303859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 39316929Smisaki "nxge_map_rxdma_channel_buf_ring: done buf init " 39326929Smisaki "channel %d msg block entries %d", 39336929Smisaki channel, index)); 39343859Sml29623 ring_info->block_size_mask = bsize - 1; 39353859Sml29623 rbrp->rx_msg_ring = rx_msg_ring; 39363859Sml29623 rbrp->dma_bufp = dma_buf_p; 39373859Sml29623 rbrp->ring_info = ring_info; 39383859Sml29623 39393859Sml29623 status = nxge_rxbuf_index_info_init(nxgep, rbrp); 39403859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 39416929Smisaki " nxge_map_rxdma_channel_buf_ring: " 39426929Smisaki "channel %d done buf info init", channel)); 39433859Sml29623 39445170Stm144005 /* 39455170Stm144005 * Finally, permit nxge_freeb() to call nxge_post_page(). 39465170Stm144005 */ 39475170Stm144005 rbrp->rbr_state = RBR_POSTING; 39485170Stm144005 39493859Sml29623 *rbr_p = rbrp; 39503859Sml29623 goto nxge_map_rxdma_channel_buf_ring_exit; 39513859Sml29623 39523859Sml29623 nxge_map_rxdma_channel_buf_ring_fail1: 39533859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 39546929Smisaki " nxge_map_rxdma_channel_buf_ring: failed channel (0x%x)", 39556929Smisaki channel, status)); 39563859Sml29623 39573859Sml29623 index--; 39583859Sml29623 for (; index >= 0; index--) { 39593859Sml29623 rx_msg_p = rx_msg_ring[index]; 39603859Sml29623 if (rx_msg_p != NULL) { 39613859Sml29623 freeb(rx_msg_p->rx_mblk_p); 39623859Sml29623 rx_msg_ring[index] = NULL; 39633859Sml29623 } 39643859Sml29623 } 39653859Sml29623 nxge_map_rxdma_channel_buf_ring_fail: 39663859Sml29623 MUTEX_DESTROY(&rbrp->post_lock); 39673859Sml29623 MUTEX_DESTROY(&rbrp->lock); 39683859Sml29623 KMEM_FREE(ring_info, sizeof (rxring_info_t)); 39693859Sml29623 KMEM_FREE(rx_msg_ring, size); 39703859Sml29623 KMEM_FREE(rbrp, sizeof (rx_rbr_ring_t)); 39713859Sml29623 39724185Sspeer status = NXGE_ERROR; 39734185Sspeer 39743859Sml29623 nxge_map_rxdma_channel_buf_ring_exit: 39753859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 39766929Smisaki "<== nxge_map_rxdma_channel_buf_ring status 0x%08x", status)); 39773859Sml29623 39783859Sml29623 return (status); 39793859Sml29623 } 39803859Sml29623 39813859Sml29623 /*ARGSUSED*/ 39823859Sml29623 static void 39833859Sml29623 nxge_unmap_rxdma_channel_buf_ring(p_nxge_t nxgep, 39843859Sml29623 p_rx_rbr_ring_t rbr_p) 39853859Sml29623 { 39863859Sml29623 p_rx_msg_t *rx_msg_ring; 39873859Sml29623 p_rx_msg_t rx_msg_p; 39883859Sml29623 rxring_info_t *ring_info; 39893859Sml29623 int i; 39903859Sml29623 uint32_t size; 39913859Sml29623 #ifdef NXGE_DEBUG 39923859Sml29623 int num_chunks; 39933859Sml29623 #endif 39943859Sml29623 39953859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 39966929Smisaki "==> nxge_unmap_rxdma_channel_buf_ring")); 39973859Sml29623 if (rbr_p == NULL) { 39983859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 39996929Smisaki "<== nxge_unmap_rxdma_channel_buf_ring: NULL rbrp")); 40003859Sml29623 return; 40013859Sml29623 } 40023859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 40036929Smisaki "==> nxge_unmap_rxdma_channel_buf_ring: channel %d", 40046929Smisaki rbr_p->rdc)); 40053859Sml29623 40063859Sml29623 rx_msg_ring = rbr_p->rx_msg_ring; 40073859Sml29623 ring_info = rbr_p->ring_info; 40083859Sml29623 40093859Sml29623 if (rx_msg_ring == NULL || ring_info == NULL) { 40106929Smisaki NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 40116929Smisaki "<== nxge_unmap_rxdma_channel_buf_ring: " 40126929Smisaki "rx_msg_ring $%p ring_info $%p", 40136929Smisaki rx_msg_p, ring_info)); 40143859Sml29623 return; 40153859Sml29623 } 40163859Sml29623 40173859Sml29623 #ifdef NXGE_DEBUG 40183859Sml29623 num_chunks = rbr_p->num_blocks; 40193859Sml29623 #endif 40203859Sml29623 size = rbr_p->tnblocks * sizeof (p_rx_msg_t); 40213859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 40226929Smisaki " nxge_unmap_rxdma_channel_buf_ring: channel %d chunks %d " 40236929Smisaki "tnblocks %d (max %d) size ptrs %d ", 40246929Smisaki rbr_p->rdc, num_chunks, 40256929Smisaki rbr_p->tnblocks, rbr_p->rbr_max_size, size)); 40263859Sml29623 40273859Sml29623 for (i = 0; i < rbr_p->tnblocks; i++) { 40283859Sml29623 rx_msg_p = rx_msg_ring[i]; 40293859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 40306929Smisaki " nxge_unmap_rxdma_channel_buf_ring: " 40316929Smisaki "rx_msg_p $%p", 40326929Smisaki rx_msg_p)); 40333859Sml29623 if (rx_msg_p != NULL) { 40343859Sml29623 freeb(rx_msg_p->rx_mblk_p); 40353859Sml29623 rx_msg_ring[i] = NULL; 40363859Sml29623 } 40373859Sml29623 } 40383859Sml29623 40395170Stm144005 /* 40405170Stm144005 * We no longer may use the mutex <post_lock>. By setting 40415170Stm144005 * <rbr_state> to anything but POSTING, we prevent 40425170Stm144005 * nxge_post_page() from accessing a dead mutex. 40435170Stm144005 */ 40445170Stm144005 rbr_p->rbr_state = RBR_UNMAPPING; 40453859Sml29623 MUTEX_DESTROY(&rbr_p->post_lock); 40465170Stm144005 40473859Sml29623 MUTEX_DESTROY(&rbr_p->lock); 40485170Stm144005 40495170Stm144005 if (rbr_p->rbr_ref_cnt == 0) { 40506495Sspeer /* 40516495Sspeer * This is the normal state of affairs. 40526495Sspeer * Need to free the following buffers: 40536495Sspeer * - data buffers 40546495Sspeer * - rx_msg ring 40556495Sspeer * - ring_info 40566495Sspeer * - rbr ring 40576495Sspeer */ 40586495Sspeer NXGE_DEBUG_MSG((nxgep, RX_CTL, 40596495Sspeer "unmap_rxdma_buf_ring: No outstanding - freeing ")); 40606495Sspeer nxge_rxdma_databuf_free(rbr_p); 40616495Sspeer KMEM_FREE(ring_info, sizeof (rxring_info_t)); 40626495Sspeer KMEM_FREE(rx_msg_ring, size); 40635170Stm144005 KMEM_FREE(rbr_p, sizeof (*rbr_p)); 40645170Stm144005 } else { 40655170Stm144005 /* 40665170Stm144005 * Some of our buffers are still being used. 40675170Stm144005 * Therefore, tell nxge_freeb() this ring is 40685170Stm144005 * unmapped, so it may free <rbr_p> for us. 40695170Stm144005 */ 40705170Stm144005 rbr_p->rbr_state = RBR_UNMAPPED; 40715170Stm144005 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 40725170Stm144005 "unmap_rxdma_buf_ring: %d %s outstanding.", 40735170Stm144005 rbr_p->rbr_ref_cnt, 40745170Stm144005 rbr_p->rbr_ref_cnt == 1 ? "msg" : "msgs")); 40755170Stm144005 } 40763859Sml29623 40773859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 40786929Smisaki "<== nxge_unmap_rxdma_channel_buf_ring")); 40793859Sml29623 } 40803859Sml29623 40816495Sspeer /* 40826495Sspeer * nxge_rxdma_hw_start_common 40836495Sspeer * 40846495Sspeer * Arguments: 40856495Sspeer * nxgep 40866495Sspeer * 40876495Sspeer * Notes: 40886495Sspeer * 40896495Sspeer * NPI/NXGE function calls: 40906495Sspeer * nxge_init_fzc_rx_common(); 40916495Sspeer * nxge_init_fzc_rxdma_port(); 40926495Sspeer * 40936495Sspeer * Registers accessed: 40946495Sspeer * 40956495Sspeer * Context: 40966495Sspeer * Service domain 40976495Sspeer */ 40983859Sml29623 static nxge_status_t 40993859Sml29623 nxge_rxdma_hw_start_common(p_nxge_t nxgep) 41003859Sml29623 { 41013859Sml29623 nxge_status_t status = NXGE_OK; 41023859Sml29623 41033859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_hw_start_common")); 41043859Sml29623 41053859Sml29623 /* 41063859Sml29623 * Load the sharable parameters by writing to the 41073859Sml29623 * function zero control registers. These FZC registers 41083859Sml29623 * should be initialized only once for the entire chip. 41093859Sml29623 */ 41103859Sml29623 (void) nxge_init_fzc_rx_common(nxgep); 41113859Sml29623 41123859Sml29623 /* 41133859Sml29623 * Initialize the RXDMA port specific FZC control configurations. 41143859Sml29623 * These FZC registers are pertaining to each port. 41153859Sml29623 */ 41163859Sml29623 (void) nxge_init_fzc_rxdma_port(nxgep); 41173859Sml29623 41183859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_hw_start_common")); 41193859Sml29623 41203859Sml29623 return (status); 41213859Sml29623 } 41223859Sml29623 41233859Sml29623 static nxge_status_t 41246495Sspeer nxge_rxdma_hw_start(p_nxge_t nxgep, int channel) 41253859Sml29623 { 41263859Sml29623 int i, ndmas; 41273859Sml29623 p_rx_rbr_rings_t rx_rbr_rings; 41283859Sml29623 p_rx_rbr_ring_t *rbr_rings; 41293859Sml29623 p_rx_rcr_rings_t rx_rcr_rings; 41303859Sml29623 p_rx_rcr_ring_t *rcr_rings; 41313859Sml29623 p_rx_mbox_areas_t rx_mbox_areas_p; 41323859Sml29623 p_rx_mbox_t *rx_mbox_p; 41333859Sml29623 nxge_status_t status = NXGE_OK; 41343859Sml29623 41353859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_hw_start")); 41363859Sml29623 41373859Sml29623 rx_rbr_rings = nxgep->rx_rbr_rings; 41383859Sml29623 rx_rcr_rings = nxgep->rx_rcr_rings; 41393859Sml29623 if (rx_rbr_rings == NULL || rx_rcr_rings == NULL) { 41403859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 41416929Smisaki "<== nxge_rxdma_hw_start: NULL ring pointers")); 41423859Sml29623 return (NXGE_ERROR); 41433859Sml29623 } 41443859Sml29623 ndmas = rx_rbr_rings->ndmas; 41453859Sml29623 if (ndmas == 0) { 41463859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 41476929Smisaki "<== nxge_rxdma_hw_start: no dma channel allocated")); 41483859Sml29623 return (NXGE_ERROR); 41493859Sml29623 } 41503859Sml29623 41513859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 41526929Smisaki "==> nxge_rxdma_hw_start (ndmas %d)", ndmas)); 41533859Sml29623 41543859Sml29623 rbr_rings = rx_rbr_rings->rbr_rings; 41553859Sml29623 rcr_rings = rx_rcr_rings->rcr_rings; 41563859Sml29623 rx_mbox_areas_p = nxgep->rx_mbox_areas_p; 41573859Sml29623 if (rx_mbox_areas_p) { 41583859Sml29623 rx_mbox_p = rx_mbox_areas_p->rxmbox_areas; 41593859Sml29623 } 41603859Sml29623 41616495Sspeer i = channel; 41626495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 41636929Smisaki "==> nxge_rxdma_hw_start (ndmas %d) channel %d", 41646929Smisaki ndmas, channel)); 41656495Sspeer status = nxge_rxdma_start_channel(nxgep, channel, 41666495Sspeer (p_rx_rbr_ring_t)rbr_rings[i], 41676495Sspeer (p_rx_rcr_ring_t)rcr_rings[i], 41686495Sspeer (p_rx_mbox_t)rx_mbox_p[i]); 41696495Sspeer if (status != NXGE_OK) { 41706495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 41716495Sspeer "==> nxge_rxdma_hw_start: disable " 41726495Sspeer "(status 0x%x channel %d)", status, channel)); 41736495Sspeer return (status); 41743859Sml29623 } 41753859Sml29623 41763859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_hw_start: " 41776929Smisaki "rx_rbr_rings 0x%016llx rings 0x%016llx", 41786929Smisaki rx_rbr_rings, rx_rcr_rings)); 41793859Sml29623 41803859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 41816929Smisaki "==> nxge_rxdma_hw_start: (status 0x%x)", status)); 41823859Sml29623 41833859Sml29623 return (status); 41843859Sml29623 } 41853859Sml29623 41863859Sml29623 static void 41876495Sspeer nxge_rxdma_hw_stop(p_nxge_t nxgep, int channel) 41883859Sml29623 { 41893859Sml29623 p_rx_rbr_rings_t rx_rbr_rings; 41903859Sml29623 p_rx_rcr_rings_t rx_rcr_rings; 41913859Sml29623 41923859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_hw_stop")); 41933859Sml29623 41943859Sml29623 rx_rbr_rings = nxgep->rx_rbr_rings; 41953859Sml29623 rx_rcr_rings = nxgep->rx_rcr_rings; 41963859Sml29623 if (rx_rbr_rings == NULL || rx_rcr_rings == NULL) { 41973859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 41986929Smisaki "<== nxge_rxdma_hw_stop: NULL ring pointers")); 41993859Sml29623 return; 42003859Sml29623 } 42013859Sml29623 42023859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 42036929Smisaki "==> nxge_rxdma_hw_stop(channel %d)", 42046929Smisaki channel)); 42056495Sspeer (void) nxge_rxdma_stop_channel(nxgep, channel); 42063859Sml29623 42073859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_hw_stop: " 42086929Smisaki "rx_rbr_rings 0x%016llx rings 0x%016llx", 42096929Smisaki rx_rbr_rings, rx_rcr_rings)); 42103859Sml29623 42113859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "<== nxge_rxdma_hw_stop")); 42123859Sml29623 } 42133859Sml29623 42143859Sml29623 42153859Sml29623 static nxge_status_t 42163859Sml29623 nxge_rxdma_start_channel(p_nxge_t nxgep, uint16_t channel, 42173859Sml29623 p_rx_rbr_ring_t rbr_p, p_rx_rcr_ring_t rcr_p, p_rx_mbox_t mbox_p) 42183859Sml29623 42193859Sml29623 { 42203859Sml29623 npi_handle_t handle; 42213859Sml29623 npi_status_t rs = NPI_SUCCESS; 42223859Sml29623 rx_dma_ctl_stat_t cs; 42233859Sml29623 rx_dma_ent_msk_t ent_mask; 42243859Sml29623 nxge_status_t status = NXGE_OK; 42253859Sml29623 42263859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_start_channel")); 42273859Sml29623 42283859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 42293859Sml29623 42303859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "nxge_rxdma_start_channel: " 42313859Sml29623 "npi handle addr $%p acc $%p", 42323859Sml29623 nxgep->npi_handle.regp, nxgep->npi_handle.regh)); 42333859Sml29623 42346495Sspeer /* Reset RXDMA channel, but not if you're a guest. */ 42356495Sspeer if (!isLDOMguest(nxgep)) { 42366495Sspeer rs = npi_rxdma_cfg_rdc_reset(handle, channel); 42376495Sspeer if (rs != NPI_SUCCESS) { 42386495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 42396495Sspeer "==> nxge_init_fzc_rdc: " 42406495Sspeer "npi_rxdma_cfg_rdc_reset(%d) returned 0x%08x", 42416495Sspeer channel, rs)); 42426495Sspeer return (NXGE_ERROR | rs); 42436495Sspeer } 42446495Sspeer 42456495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 42466495Sspeer "==> nxge_rxdma_start_channel: reset done: channel %d", 42476495Sspeer channel)); 42483859Sml29623 } 42493859Sml29623 42506495Sspeer #if defined(sun4v) && defined(NIU_LP_WORKAROUND) 42516495Sspeer if (isLDOMguest(nxgep)) 42526495Sspeer (void) nxge_rdc_lp_conf(nxgep, channel); 42536495Sspeer #endif 42543859Sml29623 42553859Sml29623 /* 42563859Sml29623 * Initialize the RXDMA channel specific FZC control 42573859Sml29623 * configurations. These FZC registers are pertaining 42583859Sml29623 * to each RX channel (logical pages). 42593859Sml29623 */ 42606495Sspeer if (!isLDOMguest(nxgep)) { 42616495Sspeer status = nxge_init_fzc_rxdma_channel(nxgep, channel); 42626495Sspeer if (status != NXGE_OK) { 42636495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 42646495Sspeer "==> nxge_rxdma_start_channel: " 42656495Sspeer "init fzc rxdma failed (0x%08x channel %d)", 42666495Sspeer status, channel)); 42676495Sspeer return (status); 42686495Sspeer } 42696495Sspeer 42706495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 42716495Sspeer "==> nxge_rxdma_start_channel: fzc done")); 42723859Sml29623 } 42733859Sml29623 42743859Sml29623 /* Set up the interrupt event masks. */ 42753859Sml29623 ent_mask.value = 0; 42763859Sml29623 ent_mask.value |= RX_DMA_ENT_MSK_RBREMPTY_MASK; 42773859Sml29623 rs = npi_rxdma_event_mask(handle, OP_SET, channel, 42786495Sspeer &ent_mask); 42793859Sml29623 if (rs != NPI_SUCCESS) { 42803859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 42813859Sml29623 "==> nxge_rxdma_start_channel: " 42826495Sspeer "init rxdma event masks failed " 42836495Sspeer "(0x%08x channel %d)", 42843859Sml29623 status, channel)); 42853859Sml29623 return (NXGE_ERROR | rs); 42863859Sml29623 } 42873859Sml29623 42886495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 42896495Sspeer "==> nxge_rxdma_start_channel: " 42903859Sml29623 "event done: channel %d (mask 0x%016llx)", 42913859Sml29623 channel, ent_mask.value)); 42923859Sml29623 42933859Sml29623 /* Initialize the receive DMA control and status register */ 42943859Sml29623 cs.value = 0; 42953859Sml29623 cs.bits.hdw.mex = 1; 42963859Sml29623 cs.bits.hdw.rcrthres = 1; 42973859Sml29623 cs.bits.hdw.rcrto = 1; 42983859Sml29623 cs.bits.hdw.rbr_empty = 1; 42993859Sml29623 status = nxge_init_rxdma_channel_cntl_stat(nxgep, channel, &cs); 43003859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_start_channel: " 43013859Sml29623 "channel %d rx_dma_cntl_stat 0x%0016llx", channel, cs.value)); 43023859Sml29623 if (status != NXGE_OK) { 43033859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 43043859Sml29623 "==> nxge_rxdma_start_channel: " 43053859Sml29623 "init rxdma control register failed (0x%08x channel %d", 43063859Sml29623 status, channel)); 43073859Sml29623 return (status); 43083859Sml29623 } 43093859Sml29623 43103859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_start_channel: " 43113859Sml29623 "control done - channel %d cs 0x%016llx", channel, cs.value)); 43123859Sml29623 43133859Sml29623 /* 43143859Sml29623 * Load RXDMA descriptors, buffers, mailbox, 43153859Sml29623 * initialise the receive DMA channels and 43163859Sml29623 * enable each DMA channel. 43173859Sml29623 */ 43183859Sml29623 status = nxge_enable_rxdma_channel(nxgep, 43196495Sspeer channel, rbr_p, rcr_p, mbox_p); 43203859Sml29623 43213859Sml29623 if (status != NXGE_OK) { 43223859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 43236495Sspeer " nxge_rxdma_start_channel: " 43246495Sspeer " enable rxdma failed (0x%08x channel %d)", 43256495Sspeer status, channel)); 43266495Sspeer return (status); 43276495Sspeer } 43286495Sspeer 43296495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 43306495Sspeer "==> nxge_rxdma_start_channel: enabled channel %d")); 43316495Sspeer 43326495Sspeer if (isLDOMguest(nxgep)) { 43336495Sspeer /* Add interrupt handler for this channel. */ 433410577SMichael.Speer@Sun.COM status = nxge_hio_intr_add(nxgep, VP_BOUND_RX, channel); 433510577SMichael.Speer@Sun.COM if (status != NXGE_OK) { 43366495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 43373859Sml29623 " nxge_rxdma_start_channel: " 43386495Sspeer " nxge_hio_intr_add failed (0x%08x channel %d)", 433910577SMichael.Speer@Sun.COM status, channel)); 434010577SMichael.Speer@Sun.COM return (status); 43416495Sspeer } 43423859Sml29623 } 43433859Sml29623 43443859Sml29623 ent_mask.value = 0; 43453859Sml29623 ent_mask.value |= (RX_DMA_ENT_MSK_WRED_DROP_MASK | 43463859Sml29623 RX_DMA_ENT_MSK_PTDROP_PKT_MASK); 43473859Sml29623 rs = npi_rxdma_event_mask(handle, OP_SET, channel, 43483859Sml29623 &ent_mask); 43493859Sml29623 if (rs != NPI_SUCCESS) { 43503859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 43513859Sml29623 "==> nxge_rxdma_start_channel: " 43523859Sml29623 "init rxdma event masks failed (0x%08x channel %d)", 43533859Sml29623 status, channel)); 43543859Sml29623 return (NXGE_ERROR | rs); 43553859Sml29623 } 43563859Sml29623 43573859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_rxdma_start_channel: " 43583859Sml29623 "control done - channel %d cs 0x%016llx", channel, cs.value)); 43593859Sml29623 43603859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "<== nxge_rxdma_start_channel")); 43613859Sml29623 43623859Sml29623 return (NXGE_OK); 43633859Sml29623 } 43643859Sml29623 43653859Sml29623 static nxge_status_t 43663859Sml29623 nxge_rxdma_stop_channel(p_nxge_t nxgep, uint16_t channel) 43673859Sml29623 { 43683859Sml29623 npi_handle_t handle; 43693859Sml29623 npi_status_t rs = NPI_SUCCESS; 43703859Sml29623 rx_dma_ctl_stat_t cs; 43713859Sml29623 rx_dma_ent_msk_t ent_mask; 43723859Sml29623 nxge_status_t status = NXGE_OK; 43733859Sml29623 43743859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rxdma_stop_channel")); 43753859Sml29623 43763859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 43773859Sml29623 43783859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "nxge_rxdma_stop_channel: " 43796929Smisaki "npi handle addr $%p acc $%p", 43806929Smisaki nxgep->npi_handle.regp, nxgep->npi_handle.regh)); 43813859Sml29623 43827812SMichael.Speer@Sun.COM if (!isLDOMguest(nxgep)) { 43837812SMichael.Speer@Sun.COM /* 43847812SMichael.Speer@Sun.COM * Stop RxMAC = A.9.2.6 43857812SMichael.Speer@Sun.COM */ 43867812SMichael.Speer@Sun.COM if (nxge_rx_mac_disable(nxgep) != NXGE_OK) { 43877812SMichael.Speer@Sun.COM NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 43887812SMichael.Speer@Sun.COM "nxge_rxdma_stop_channel: " 43897812SMichael.Speer@Sun.COM "Failed to disable RxMAC")); 43907812SMichael.Speer@Sun.COM } 43917812SMichael.Speer@Sun.COM 43927812SMichael.Speer@Sun.COM /* 43937812SMichael.Speer@Sun.COM * Drain IPP Port = A.9.3.6 43947812SMichael.Speer@Sun.COM */ 43957812SMichael.Speer@Sun.COM (void) nxge_ipp_drain(nxgep); 43967812SMichael.Speer@Sun.COM } 43977812SMichael.Speer@Sun.COM 43983859Sml29623 /* Reset RXDMA channel */ 43993859Sml29623 rs = npi_rxdma_cfg_rdc_reset(handle, channel); 44003859Sml29623 if (rs != NPI_SUCCESS) { 44013859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 44026929Smisaki " nxge_rxdma_stop_channel: " 44036929Smisaki " reset rxdma failed (0x%08x channel %d)", 44046929Smisaki rs, channel)); 44053859Sml29623 return (NXGE_ERROR | rs); 44063859Sml29623 } 44073859Sml29623 44083859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 44096929Smisaki "==> nxge_rxdma_stop_channel: reset done")); 44103859Sml29623 44113859Sml29623 /* Set up the interrupt event masks. */ 44123859Sml29623 ent_mask.value = RX_DMA_ENT_MSK_ALL; 44133859Sml29623 rs = npi_rxdma_event_mask(handle, OP_SET, channel, 44146929Smisaki &ent_mask); 44153859Sml29623 if (rs != NPI_SUCCESS) { 44163859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 44176929Smisaki "==> nxge_rxdma_stop_channel: " 44186929Smisaki "set rxdma event masks failed (0x%08x channel %d)", 44196929Smisaki rs, channel)); 44203859Sml29623 return (NXGE_ERROR | rs); 44213859Sml29623 } 44223859Sml29623 44233859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 44246929Smisaki "==> nxge_rxdma_stop_channel: event done")); 44253859Sml29623 44267812SMichael.Speer@Sun.COM /* 44277812SMichael.Speer@Sun.COM * Initialize the receive DMA control and status register 44287812SMichael.Speer@Sun.COM */ 44293859Sml29623 cs.value = 0; 44307812SMichael.Speer@Sun.COM status = nxge_init_rxdma_channel_cntl_stat(nxgep, channel, &cs); 44313859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rxdma_stop_channel: control " 44326929Smisaki " to default (all 0s) 0x%08x", cs.value)); 44333859Sml29623 if (status != NXGE_OK) { 44343859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 44356929Smisaki " nxge_rxdma_stop_channel: init rxdma" 44366929Smisaki " control register failed (0x%08x channel %d", 44376929Smisaki status, channel)); 44383859Sml29623 return (status); 44393859Sml29623 } 44403859Sml29623 44413859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, 44426929Smisaki "==> nxge_rxdma_stop_channel: control done")); 44433859Sml29623 44447812SMichael.Speer@Sun.COM /* 44457812SMichael.Speer@Sun.COM * Make sure channel is disabled. 44467812SMichael.Speer@Sun.COM */ 44473859Sml29623 status = nxge_disable_rxdma_channel(nxgep, channel); 44488275SEric Cheng 44493859Sml29623 if (status != NXGE_OK) { 44503859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 44516929Smisaki " nxge_rxdma_stop_channel: " 44526929Smisaki " init enable rxdma failed (0x%08x channel %d)", 44536929Smisaki status, channel)); 44543859Sml29623 return (status); 44553859Sml29623 } 44563859Sml29623 44577812SMichael.Speer@Sun.COM if (!isLDOMguest(nxgep)) { 44587812SMichael.Speer@Sun.COM /* 44597812SMichael.Speer@Sun.COM * Enable RxMAC = A.9.2.10 44607812SMichael.Speer@Sun.COM */ 44617812SMichael.Speer@Sun.COM if (nxge_rx_mac_enable(nxgep) != NXGE_OK) { 44627812SMichael.Speer@Sun.COM NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 44637812SMichael.Speer@Sun.COM "nxge_rxdma_stop_channel: Rx MAC still disabled")); 44647812SMichael.Speer@Sun.COM } 44657812SMichael.Speer@Sun.COM } 44667812SMichael.Speer@Sun.COM 44673859Sml29623 NXGE_DEBUG_MSG((nxgep, 44686929Smisaki RX_CTL, "==> nxge_rxdma_stop_channel: disable done")); 44693859Sml29623 44703859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_rxdma_stop_channel")); 44713859Sml29623 44723859Sml29623 return (NXGE_OK); 44733859Sml29623 } 44743859Sml29623 44753859Sml29623 nxge_status_t 44763859Sml29623 nxge_rxdma_handle_sys_errors(p_nxge_t nxgep) 44773859Sml29623 { 44783859Sml29623 npi_handle_t handle; 44793859Sml29623 p_nxge_rdc_sys_stats_t statsp; 44803859Sml29623 rx_ctl_dat_fifo_stat_t stat; 44813859Sml29623 uint32_t zcp_err_status; 44823859Sml29623 uint32_t ipp_err_status; 44833859Sml29623 nxge_status_t status = NXGE_OK; 44843859Sml29623 npi_status_t rs = NPI_SUCCESS; 44853859Sml29623 boolean_t my_err = B_FALSE; 44863859Sml29623 44873859Sml29623 handle = nxgep->npi_handle; 44883859Sml29623 statsp = (p_nxge_rdc_sys_stats_t)&nxgep->statsp->rdc_sys_stats; 44893859Sml29623 44903859Sml29623 rs = npi_rxdma_rxctl_fifo_error_intr_get(handle, &stat); 44913859Sml29623 44923859Sml29623 if (rs != NPI_SUCCESS) 44933859Sml29623 return (NXGE_ERROR | rs); 44943859Sml29623 44953859Sml29623 if (stat.bits.ldw.id_mismatch) { 44963859Sml29623 statsp->id_mismatch++; 44973859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, nxgep->mac.portnum, NULL, 44986929Smisaki NXGE_FM_EREPORT_RDMC_ID_MISMATCH); 44993859Sml29623 /* Global fatal error encountered */ 45003859Sml29623 } 45013859Sml29623 45023859Sml29623 if ((stat.bits.ldw.zcp_eop_err) || (stat.bits.ldw.ipp_eop_err)) { 45033859Sml29623 switch (nxgep->mac.portnum) { 45043859Sml29623 case 0: 45053859Sml29623 if ((stat.bits.ldw.zcp_eop_err & FIFO_EOP_PORT0) || 45066929Smisaki (stat.bits.ldw.ipp_eop_err & FIFO_EOP_PORT0)) { 45073859Sml29623 my_err = B_TRUE; 45083859Sml29623 zcp_err_status = stat.bits.ldw.zcp_eop_err; 45093859Sml29623 ipp_err_status = stat.bits.ldw.ipp_eop_err; 45103859Sml29623 } 45113859Sml29623 break; 45123859Sml29623 case 1: 45133859Sml29623 if ((stat.bits.ldw.zcp_eop_err & FIFO_EOP_PORT1) || 45146929Smisaki (stat.bits.ldw.ipp_eop_err & FIFO_EOP_PORT1)) { 45153859Sml29623 my_err = B_TRUE; 45163859Sml29623 zcp_err_status = stat.bits.ldw.zcp_eop_err; 45173859Sml29623 ipp_err_status = stat.bits.ldw.ipp_eop_err; 45183859Sml29623 } 45193859Sml29623 break; 45203859Sml29623 case 2: 45213859Sml29623 if ((stat.bits.ldw.zcp_eop_err & FIFO_EOP_PORT2) || 45226929Smisaki (stat.bits.ldw.ipp_eop_err & FIFO_EOP_PORT2)) { 45233859Sml29623 my_err = B_TRUE; 45243859Sml29623 zcp_err_status = stat.bits.ldw.zcp_eop_err; 45253859Sml29623 ipp_err_status = stat.bits.ldw.ipp_eop_err; 45263859Sml29623 } 45273859Sml29623 break; 45283859Sml29623 case 3: 45293859Sml29623 if ((stat.bits.ldw.zcp_eop_err & FIFO_EOP_PORT3) || 45306929Smisaki (stat.bits.ldw.ipp_eop_err & FIFO_EOP_PORT3)) { 45313859Sml29623 my_err = B_TRUE; 45323859Sml29623 zcp_err_status = stat.bits.ldw.zcp_eop_err; 45333859Sml29623 ipp_err_status = stat.bits.ldw.ipp_eop_err; 45343859Sml29623 } 45353859Sml29623 break; 45363859Sml29623 default: 45373859Sml29623 return (NXGE_ERROR); 45383859Sml29623 } 45393859Sml29623 } 45403859Sml29623 45413859Sml29623 if (my_err) { 45423859Sml29623 status = nxge_rxdma_handle_port_errors(nxgep, ipp_err_status, 45436929Smisaki zcp_err_status); 45443859Sml29623 if (status != NXGE_OK) 45453859Sml29623 return (status); 45463859Sml29623 } 45473859Sml29623 45483859Sml29623 return (NXGE_OK); 45493859Sml29623 } 45503859Sml29623 45513859Sml29623 static nxge_status_t 45523859Sml29623 nxge_rxdma_handle_port_errors(p_nxge_t nxgep, uint32_t ipp_status, 45533859Sml29623 uint32_t zcp_status) 45543859Sml29623 { 45553859Sml29623 boolean_t rxport_fatal = B_FALSE; 45563859Sml29623 p_nxge_rdc_sys_stats_t statsp; 45573859Sml29623 nxge_status_t status = NXGE_OK; 45583859Sml29623 uint8_t portn; 45593859Sml29623 45603859Sml29623 portn = nxgep->mac.portnum; 45613859Sml29623 statsp = (p_nxge_rdc_sys_stats_t)&nxgep->statsp->rdc_sys_stats; 45623859Sml29623 45633859Sml29623 if (ipp_status & (0x1 << portn)) { 45643859Sml29623 statsp->ipp_eop_err++; 45653859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, portn, NULL, 45666929Smisaki NXGE_FM_EREPORT_RDMC_IPP_EOP_ERR); 45673859Sml29623 rxport_fatal = B_TRUE; 45683859Sml29623 } 45693859Sml29623 45703859Sml29623 if (zcp_status & (0x1 << portn)) { 45713859Sml29623 statsp->zcp_eop_err++; 45723859Sml29623 NXGE_FM_REPORT_ERROR(nxgep, portn, NULL, 45736929Smisaki NXGE_FM_EREPORT_RDMC_ZCP_EOP_ERR); 45743859Sml29623 rxport_fatal = B_TRUE; 45753859Sml29623 } 45763859Sml29623 45773859Sml29623 if (rxport_fatal) { 45783859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 45796929Smisaki " nxge_rxdma_handle_port_error: " 45806929Smisaki " fatal error on Port #%d\n", 45816929Smisaki portn)); 45823859Sml29623 status = nxge_rx_port_fatal_err_recover(nxgep); 45833859Sml29623 if (status == NXGE_OK) { 45843859Sml29623 FM_SERVICE_RESTORED(nxgep); 45853859Sml29623 } 45863859Sml29623 } 45873859Sml29623 45883859Sml29623 return (status); 45893859Sml29623 } 45903859Sml29623 45913859Sml29623 static nxge_status_t 45923859Sml29623 nxge_rxdma_fatal_err_recover(p_nxge_t nxgep, uint16_t channel) 45933859Sml29623 { 45943859Sml29623 npi_handle_t handle; 45953859Sml29623 npi_status_t rs = NPI_SUCCESS; 45963859Sml29623 nxge_status_t status = NXGE_OK; 45973859Sml29623 p_rx_rbr_ring_t rbrp; 45983859Sml29623 p_rx_rcr_ring_t rcrp; 45993859Sml29623 p_rx_mbox_t mboxp; 46003859Sml29623 rx_dma_ent_msk_t ent_mask; 46013859Sml29623 p_nxge_dma_common_t dmap; 46023859Sml29623 uint32_t ref_cnt; 46033859Sml29623 p_rx_msg_t rx_msg_p; 46043859Sml29623 int i; 46053859Sml29623 uint32_t nxge_port_rcr_size; 46063859Sml29623 46073859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_rxdma_fatal_err_recover")); 46083859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 46096929Smisaki "Recovering from RxDMAChannel#%d error...", channel)); 46103859Sml29623 46113859Sml29623 /* 46123859Sml29623 * Stop the dma channel waits for the stop done. 46133859Sml29623 * If the stop done bit is not set, then create 46143859Sml29623 * an error. 46153859Sml29623 */ 46163859Sml29623 46173859Sml29623 handle = NXGE_DEV_NPI_HANDLE(nxgep); 46183859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "Rx DMA stop...")); 46193859Sml29623 462010218SMichael.Speer@Sun.COM rbrp = (p_rx_rbr_ring_t)nxgep->rx_rbr_rings->rbr_rings[channel]; 462110218SMichael.Speer@Sun.COM rcrp = (p_rx_rcr_ring_t)nxgep->rx_rcr_rings->rcr_rings[channel]; 46223859Sml29623 46233859Sml29623 MUTEX_ENTER(&rbrp->lock); 46243859Sml29623 MUTEX_ENTER(&rbrp->post_lock); 46253859Sml29623 46263859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "Disable RxDMA channel...")); 46273859Sml29623 46283859Sml29623 rs = npi_rxdma_cfg_rdc_disable(handle, channel); 46293859Sml29623 if (rs != NPI_SUCCESS) { 46303859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 46316929Smisaki "nxge_disable_rxdma_channel:failed")); 46323859Sml29623 goto fail; 46333859Sml29623 } 46343859Sml29623 46353859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "Disable RxDMA interrupt...")); 46363859Sml29623 46373859Sml29623 /* Disable interrupt */ 46383859Sml29623 ent_mask.value = RX_DMA_ENT_MSK_ALL; 46393859Sml29623 rs = npi_rxdma_event_mask(handle, OP_SET, channel, &ent_mask); 46403859Sml29623 if (rs != NPI_SUCCESS) { 46413859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 46426929Smisaki "nxge_rxdma_stop_channel: " 46436929Smisaki "set rxdma event masks failed (channel %d)", 46446929Smisaki channel)); 46453859Sml29623 } 46463859Sml29623 46473859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "RxDMA channel reset...")); 46483859Sml29623 46493859Sml29623 /* Reset RXDMA channel */ 46503859Sml29623 rs = npi_rxdma_cfg_rdc_reset(handle, channel); 46513859Sml29623 if (rs != NPI_SUCCESS) { 46523859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 46536929Smisaki "nxge_rxdma_fatal_err_recover: " 46546929Smisaki " reset rxdma failed (channel %d)", channel)); 46553859Sml29623 goto fail; 46563859Sml29623 } 46573859Sml29623 46583859Sml29623 nxge_port_rcr_size = nxgep->nxge_port_rcr_size; 46593859Sml29623 466010218SMichael.Speer@Sun.COM mboxp = (p_rx_mbox_t)nxgep->rx_mbox_areas_p->rxmbox_areas[channel]; 46613859Sml29623 46623859Sml29623 rbrp->rbr_wr_index = (rbrp->rbb_max - 1); 46633859Sml29623 rbrp->rbr_rd_index = 0; 46643859Sml29623 46653859Sml29623 rcrp->comp_rd_index = 0; 46663859Sml29623 rcrp->comp_wt_index = 0; 46673859Sml29623 rcrp->rcr_desc_rd_head_p = rcrp->rcr_desc_first_p = 46686929Smisaki (p_rcr_entry_t)DMA_COMMON_VPTR(rcrp->rcr_desc); 46695125Sjoycey #if defined(__i386) 46706929Smisaki rcrp->rcr_desc_rd_head_pp = rcrp->rcr_desc_first_pp = 46716929Smisaki (p_rcr_entry_t)(uint32_t)DMA_COMMON_IOADDR(rcrp->rcr_desc); 46725125Sjoycey #else 46736929Smisaki rcrp->rcr_desc_rd_head_pp = rcrp->rcr_desc_first_pp = 46746929Smisaki (p_rcr_entry_t)DMA_COMMON_IOADDR(rcrp->rcr_desc); 46755125Sjoycey #endif 46763859Sml29623 46773859Sml29623 rcrp->rcr_desc_last_p = rcrp->rcr_desc_rd_head_p + 46786929Smisaki (nxge_port_rcr_size - 1); 46793859Sml29623 rcrp->rcr_desc_last_pp = rcrp->rcr_desc_rd_head_pp + 46806929Smisaki (nxge_port_rcr_size - 1); 46813859Sml29623 46823859Sml29623 dmap = (p_nxge_dma_common_t)&rcrp->rcr_desc; 46833859Sml29623 bzero((caddr_t)dmap->kaddrp, dmap->alength); 46843859Sml29623 46853859Sml29623 cmn_err(CE_NOTE, "!rbr entries = %d\n", rbrp->rbr_max_size); 46863859Sml29623 46873859Sml29623 for (i = 0; i < rbrp->rbr_max_size; i++) { 46883859Sml29623 rx_msg_p = rbrp->rx_msg_ring[i]; 46893859Sml29623 ref_cnt = rx_msg_p->ref_cnt; 46903859Sml29623 if (ref_cnt != 1) { 46913859Sml29623 if (rx_msg_p->cur_usage_cnt != 46926929Smisaki rx_msg_p->max_usage_cnt) { 46933859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 46946929Smisaki "buf[%d]: cur_usage_cnt = %d " 46956929Smisaki "max_usage_cnt = %d\n", i, 46966929Smisaki rx_msg_p->cur_usage_cnt, 46976929Smisaki rx_msg_p->max_usage_cnt)); 46983859Sml29623 } else { 46993859Sml29623 /* Buffer can be re-posted */ 47003859Sml29623 rx_msg_p->free = B_TRUE; 47013859Sml29623 rx_msg_p->cur_usage_cnt = 0; 47023859Sml29623 rx_msg_p->max_usage_cnt = 0xbaddcafe; 47033859Sml29623 rx_msg_p->pkt_buf_size = 0; 47043859Sml29623 } 47053859Sml29623 } 47063859Sml29623 } 47073859Sml29623 47083859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "RxDMA channel re-start...")); 47093859Sml29623 47103859Sml29623 status = nxge_rxdma_start_channel(nxgep, channel, rbrp, rcrp, mboxp); 47113859Sml29623 if (status != NXGE_OK) { 47123859Sml29623 goto fail; 47133859Sml29623 } 47143859Sml29623 47153859Sml29623 MUTEX_EXIT(&rbrp->post_lock); 47163859Sml29623 MUTEX_EXIT(&rbrp->lock); 47173859Sml29623 47183859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 47196929Smisaki "Recovery Successful, RxDMAChannel#%d Restored", 47206929Smisaki channel)); 47213859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_rxdma_fatal_err_recover")); 47223859Sml29623 return (NXGE_OK); 472310577SMichael.Speer@Sun.COM 47243859Sml29623 fail: 47253859Sml29623 MUTEX_EXIT(&rbrp->post_lock); 47263859Sml29623 MUTEX_EXIT(&rbrp->lock); 47273859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "Recovery failed")); 47283859Sml29623 return (NXGE_ERROR | rs); 47293859Sml29623 } 47303859Sml29623 47313859Sml29623 nxge_status_t 47323859Sml29623 nxge_rx_port_fatal_err_recover(p_nxge_t nxgep) 47333859Sml29623 { 47346495Sspeer nxge_grp_set_t *set = &nxgep->rx_set; 47356495Sspeer nxge_status_t status = NXGE_OK; 473610577SMichael.Speer@Sun.COM p_rx_rcr_ring_t rcrp; 47376495Sspeer int rdc; 47383859Sml29623 47393859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_rx_port_fatal_err_recover")); 47403859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 47416929Smisaki "Recovering from RxPort error...")); 47426495Sspeer NXGE_DEBUG_MSG((nxgep, RX_CTL, "Disabling RxMAC...\n")); 47436495Sspeer 47443859Sml29623 if (nxge_rx_mac_disable(nxgep) != NXGE_OK) 47453859Sml29623 goto fail; 47463859Sml29623 47473859Sml29623 NXGE_DELAY(1000); 47483859Sml29623 47496495Sspeer NXGE_DEBUG_MSG((nxgep, RX_CTL, "Stopping all RxDMA channels...")); 47506495Sspeer 47516495Sspeer for (rdc = 0; rdc < NXGE_MAX_RDCS; rdc++) { 47526495Sspeer if ((1 << rdc) & set->owned.map) { 475310577SMichael.Speer@Sun.COM rcrp = nxgep->rx_rcr_rings->rcr_rings[rdc]; 475410577SMichael.Speer@Sun.COM if (rcrp != NULL) { 475510577SMichael.Speer@Sun.COM MUTEX_ENTER(&rcrp->lock); 475610577SMichael.Speer@Sun.COM if (nxge_rxdma_fatal_err_recover(nxgep, 475710577SMichael.Speer@Sun.COM rdc) != NXGE_OK) { 475810577SMichael.Speer@Sun.COM NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 475910577SMichael.Speer@Sun.COM "Could not recover " 476010577SMichael.Speer@Sun.COM "channel %d", rdc)); 476110577SMichael.Speer@Sun.COM } 476210577SMichael.Speer@Sun.COM MUTEX_EXIT(&rcrp->lock); 47636495Sspeer } 47643859Sml29623 } 47653859Sml29623 } 47663859Sml29623 47676495Sspeer NXGE_DEBUG_MSG((nxgep, RX_CTL, "Resetting IPP...")); 47683859Sml29623 47693859Sml29623 /* Reset IPP */ 47703859Sml29623 if (nxge_ipp_reset(nxgep) != NXGE_OK) { 47713859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 47726929Smisaki "nxge_rx_port_fatal_err_recover: " 47736929Smisaki "Failed to reset IPP")); 47743859Sml29623 goto fail; 47753859Sml29623 } 47763859Sml29623 47773859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "Reset RxMAC...")); 47783859Sml29623 47793859Sml29623 /* Reset RxMAC */ 47803859Sml29623 if (nxge_rx_mac_reset(nxgep) != NXGE_OK) { 47813859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 47826929Smisaki "nxge_rx_port_fatal_err_recover: " 47836929Smisaki "Failed to reset RxMAC")); 47843859Sml29623 goto fail; 47853859Sml29623 } 47863859Sml29623 47873859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "Re-initialize IPP...")); 47883859Sml29623 47893859Sml29623 /* Re-Initialize IPP */ 47903859Sml29623 if (nxge_ipp_init(nxgep) != NXGE_OK) { 47913859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 47926929Smisaki "nxge_rx_port_fatal_err_recover: " 47936929Smisaki "Failed to init IPP")); 47943859Sml29623 goto fail; 47953859Sml29623 } 47963859Sml29623 47973859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "Re-initialize RxMAC...")); 47983859Sml29623 47993859Sml29623 /* Re-Initialize RxMAC */ 48003859Sml29623 if ((status = nxge_rx_mac_init(nxgep)) != NXGE_OK) { 48013859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 48026929Smisaki "nxge_rx_port_fatal_err_recover: " 48036929Smisaki "Failed to reset RxMAC")); 48043859Sml29623 goto fail; 48053859Sml29623 } 48063859Sml29623 48073859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "Re-enable RxMAC...")); 48083859Sml29623 48093859Sml29623 /* Re-enable RxMAC */ 48103859Sml29623 if ((status = nxge_rx_mac_enable(nxgep)) != NXGE_OK) { 48113859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 48126929Smisaki "nxge_rx_port_fatal_err_recover: " 48136929Smisaki "Failed to enable RxMAC")); 48143859Sml29623 goto fail; 48153859Sml29623 } 48163859Sml29623 48173859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 48186929Smisaki "Recovery Successful, RxPort Restored")); 48193859Sml29623 48203859Sml29623 return (NXGE_OK); 48213859Sml29623 fail: 48223859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "Recovery failed")); 48233859Sml29623 return (status); 48243859Sml29623 } 48253859Sml29623 48263859Sml29623 void 48273859Sml29623 nxge_rxdma_inject_err(p_nxge_t nxgep, uint32_t err_id, uint8_t chan) 48283859Sml29623 { 48293859Sml29623 rx_dma_ctl_stat_t cs; 48303859Sml29623 rx_ctl_dat_fifo_stat_t cdfs; 48313859Sml29623 48323859Sml29623 switch (err_id) { 48333859Sml29623 case NXGE_FM_EREPORT_RDMC_RCR_ACK_ERR: 48343859Sml29623 case NXGE_FM_EREPORT_RDMC_DC_FIFO_ERR: 48353859Sml29623 case NXGE_FM_EREPORT_RDMC_RCR_SHA_PAR: 48363859Sml29623 case NXGE_FM_EREPORT_RDMC_RBR_PRE_PAR: 48373859Sml29623 case NXGE_FM_EREPORT_RDMC_RBR_TMOUT: 48383859Sml29623 case NXGE_FM_EREPORT_RDMC_RSP_CNT_ERR: 48393859Sml29623 case NXGE_FM_EREPORT_RDMC_BYTE_EN_BUS: 48403859Sml29623 case NXGE_FM_EREPORT_RDMC_RSP_DAT_ERR: 48413859Sml29623 case NXGE_FM_EREPORT_RDMC_RCRINCON: 48423859Sml29623 case NXGE_FM_EREPORT_RDMC_RCRFULL: 48433859Sml29623 case NXGE_FM_EREPORT_RDMC_RBRFULL: 48443859Sml29623 case NXGE_FM_EREPORT_RDMC_RBRLOGPAGE: 48453859Sml29623 case NXGE_FM_EREPORT_RDMC_CFIGLOGPAGE: 48463859Sml29623 case NXGE_FM_EREPORT_RDMC_CONFIG_ERR: 48473859Sml29623 RXDMA_REG_READ64(nxgep->npi_handle, RX_DMA_CTL_STAT_DBG_REG, 48486929Smisaki chan, &cs.value); 48493859Sml29623 if (err_id == NXGE_FM_EREPORT_RDMC_RCR_ACK_ERR) 48503859Sml29623 cs.bits.hdw.rcr_ack_err = 1; 48513859Sml29623 else if (err_id == NXGE_FM_EREPORT_RDMC_DC_FIFO_ERR) 48523859Sml29623 cs.bits.hdw.dc_fifo_err = 1; 48533859Sml29623 else if (err_id == NXGE_FM_EREPORT_RDMC_RCR_SHA_PAR) 48543859Sml29623 cs.bits.hdw.rcr_sha_par = 1; 48553859Sml29623 else if (err_id == NXGE_FM_EREPORT_RDMC_RBR_PRE_PAR) 48563859Sml29623 cs.bits.hdw.rbr_pre_par = 1; 48573859Sml29623 else if (err_id == NXGE_FM_EREPORT_RDMC_RBR_TMOUT) 48583859Sml29623 cs.bits.hdw.rbr_tmout = 1; 48593859Sml29623 else if (err_id == NXGE_FM_EREPORT_RDMC_RSP_CNT_ERR) 48603859Sml29623 cs.bits.hdw.rsp_cnt_err = 1; 48613859Sml29623 else if (err_id == NXGE_FM_EREPORT_RDMC_BYTE_EN_BUS) 48623859Sml29623 cs.bits.hdw.byte_en_bus = 1; 48633859Sml29623 else if (err_id == NXGE_FM_EREPORT_RDMC_RSP_DAT_ERR) 48643859Sml29623 cs.bits.hdw.rsp_dat_err = 1; 48653859Sml29623 else if (err_id == NXGE_FM_EREPORT_RDMC_CONFIG_ERR) 48663859Sml29623 cs.bits.hdw.config_err = 1; 48673859Sml29623 else if (err_id == NXGE_FM_EREPORT_RDMC_RCRINCON) 48683859Sml29623 cs.bits.hdw.rcrincon = 1; 48693859Sml29623 else if (err_id == NXGE_FM_EREPORT_RDMC_RCRFULL) 48703859Sml29623 cs.bits.hdw.rcrfull = 1; 48713859Sml29623 else if (err_id == NXGE_FM_EREPORT_RDMC_RBRFULL) 48723859Sml29623 cs.bits.hdw.rbrfull = 1; 48733859Sml29623 else if (err_id == NXGE_FM_EREPORT_RDMC_RBRLOGPAGE) 48743859Sml29623 cs.bits.hdw.rbrlogpage = 1; 48753859Sml29623 else if (err_id == NXGE_FM_EREPORT_RDMC_CFIGLOGPAGE) 48763859Sml29623 cs.bits.hdw.cfiglogpage = 1; 48775125Sjoycey #if defined(__i386) 48785125Sjoycey cmn_err(CE_NOTE, "!Write 0x%llx to RX_DMA_CTL_STAT_DBG_REG\n", 48796929Smisaki cs.value); 48805125Sjoycey #else 48813859Sml29623 cmn_err(CE_NOTE, "!Write 0x%lx to RX_DMA_CTL_STAT_DBG_REG\n", 48826929Smisaki cs.value); 48835125Sjoycey #endif 48843859Sml29623 RXDMA_REG_WRITE64(nxgep->npi_handle, RX_DMA_CTL_STAT_DBG_REG, 48856929Smisaki chan, cs.value); 48863859Sml29623 break; 48873859Sml29623 case NXGE_FM_EREPORT_RDMC_ID_MISMATCH: 48883859Sml29623 case NXGE_FM_EREPORT_RDMC_ZCP_EOP_ERR: 48893859Sml29623 case NXGE_FM_EREPORT_RDMC_IPP_EOP_ERR: 48903859Sml29623 cdfs.value = 0; 48913859Sml29623 if (err_id == NXGE_FM_EREPORT_RDMC_ID_MISMATCH) 48923859Sml29623 cdfs.bits.ldw.id_mismatch = (1 << nxgep->mac.portnum); 48933859Sml29623 else if (err_id == NXGE_FM_EREPORT_RDMC_ZCP_EOP_ERR) 48943859Sml29623 cdfs.bits.ldw.zcp_eop_err = (1 << nxgep->mac.portnum); 48953859Sml29623 else if (err_id == NXGE_FM_EREPORT_RDMC_IPP_EOP_ERR) 48963859Sml29623 cdfs.bits.ldw.ipp_eop_err = (1 << nxgep->mac.portnum); 48975125Sjoycey #if defined(__i386) 48985125Sjoycey cmn_err(CE_NOTE, 48996929Smisaki "!Write 0x%llx to RX_CTL_DAT_FIFO_STAT_DBG_REG\n", 49006929Smisaki cdfs.value); 49015125Sjoycey #else 49023859Sml29623 cmn_err(CE_NOTE, 49036929Smisaki "!Write 0x%lx to RX_CTL_DAT_FIFO_STAT_DBG_REG\n", 49046929Smisaki cdfs.value); 49055125Sjoycey #endif 49066495Sspeer NXGE_REG_WR64(nxgep->npi_handle, 49076495Sspeer RX_CTL_DAT_FIFO_STAT_DBG_REG, cdfs.value); 49083859Sml29623 break; 49093859Sml29623 case NXGE_FM_EREPORT_RDMC_DCF_ERR: 49103859Sml29623 break; 49115165Syc148097 case NXGE_FM_EREPORT_RDMC_RCR_ERR: 49123859Sml29623 break; 49133859Sml29623 } 49143859Sml29623 } 49156495Sspeer 49166495Sspeer static void 49176495Sspeer nxge_rxdma_databuf_free(p_rx_rbr_ring_t rbr_p) 49186495Sspeer { 49196495Sspeer rxring_info_t *ring_info; 49206495Sspeer int index; 49216495Sspeer uint32_t chunk_size; 49226495Sspeer uint64_t kaddr; 49236495Sspeer uint_t num_blocks; 49246495Sspeer 49256495Sspeer NXGE_DEBUG_MSG((NULL, DMA_CTL, "==> nxge_rxdma_databuf_free")); 49266495Sspeer 49276495Sspeer if (rbr_p == NULL) { 49286495Sspeer NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL, 49296495Sspeer "==> nxge_rxdma_databuf_free: NULL rbr pointer")); 49306495Sspeer return; 49316495Sspeer } 49326495Sspeer 49336495Sspeer if (rbr_p->rbr_alloc_type == DDI_MEM_ALLOC) { 49349232SMichael.Speer@Sun.COM NXGE_DEBUG_MSG((NULL, DMA_CTL, 49359232SMichael.Speer@Sun.COM "<== nxge_rxdma_databuf_free: DDI")); 49366495Sspeer return; 49376495Sspeer } 49386495Sspeer 49396495Sspeer ring_info = rbr_p->ring_info; 49406495Sspeer if (ring_info == NULL) { 49416495Sspeer NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL, 49426495Sspeer "==> nxge_rxdma_databuf_free: NULL ring info")); 49436495Sspeer return; 49446495Sspeer } 49456495Sspeer num_blocks = rbr_p->num_blocks; 49466495Sspeer for (index = 0; index < num_blocks; index++) { 49476495Sspeer kaddr = ring_info->buffer[index].kaddr; 49486495Sspeer chunk_size = ring_info->buffer[index].buf_size; 49496495Sspeer NXGE_DEBUG_MSG((NULL, DMA_CTL, 49506495Sspeer "==> nxge_rxdma_databuf_free: free chunk %d " 49516495Sspeer "kaddrp $%p chunk size %d", 49526495Sspeer index, kaddr, chunk_size)); 49536495Sspeer if (kaddr == NULL) continue; 49546495Sspeer nxge_free_buf(rbr_p->rbr_alloc_type, kaddr, chunk_size); 49556495Sspeer ring_info->buffer[index].kaddr = NULL; 49566495Sspeer } 49576495Sspeer 49586495Sspeer NXGE_DEBUG_MSG((NULL, DMA_CTL, "<== nxge_rxdma_databuf_free")); 49596495Sspeer } 49606495Sspeer 49616495Sspeer #if defined(sun4v) && defined(NIU_LP_WORKAROUND) 49626495Sspeer extern void contig_mem_free(void *, size_t); 49636495Sspeer #endif 49646495Sspeer 49656495Sspeer void 49666495Sspeer nxge_free_buf(buf_alloc_type_t alloc_type, uint64_t kaddr, uint32_t buf_size) 49676495Sspeer { 49686495Sspeer NXGE_DEBUG_MSG((NULL, DMA_CTL, "==> nxge_free_buf")); 49696495Sspeer 49706495Sspeer if (kaddr == NULL || !buf_size) { 49716495Sspeer NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL, 49726495Sspeer "==> nxge_free_buf: invalid kaddr $%p size to free %d", 49736495Sspeer kaddr, buf_size)); 49746495Sspeer return; 49756495Sspeer } 49766495Sspeer 49776495Sspeer switch (alloc_type) { 49786495Sspeer case KMEM_ALLOC: 49796495Sspeer NXGE_DEBUG_MSG((NULL, DMA_CTL, 49806495Sspeer "==> nxge_free_buf: freeing kmem $%p size %d", 49816495Sspeer kaddr, buf_size)); 49826495Sspeer #if defined(__i386) 49836495Sspeer KMEM_FREE((void *)(uint32_t)kaddr, buf_size); 49846495Sspeer #else 49856495Sspeer KMEM_FREE((void *)kaddr, buf_size); 49866495Sspeer #endif 49876495Sspeer break; 49886495Sspeer 49896495Sspeer #if defined(sun4v) && defined(NIU_LP_WORKAROUND) 49906495Sspeer case CONTIG_MEM_ALLOC: 49916495Sspeer NXGE_DEBUG_MSG((NULL, DMA_CTL, 49926495Sspeer "==> nxge_free_buf: freeing contig_mem kaddr $%p size %d", 49936495Sspeer kaddr, buf_size)); 49946495Sspeer contig_mem_free((void *)kaddr, buf_size); 49956495Sspeer break; 49966495Sspeer #endif 49976495Sspeer 49986495Sspeer default: 49996495Sspeer NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL, 50006495Sspeer "<== nxge_free_buf: unsupported alloc type %d", 50016495Sspeer alloc_type)); 50026495Sspeer return; 50036495Sspeer } 50046495Sspeer 50056495Sspeer NXGE_DEBUG_MSG((NULL, DMA_CTL, "<== nxge_free_buf")); 50066495Sspeer } 5007