13859Sml29623 /*
23859Sml29623 * CDDL HEADER START
33859Sml29623 *
43859Sml29623 * The contents of this file are subject to the terms of the
53859Sml29623 * Common Development and Distribution License (the "License").
63859Sml29623 * You may not use this file except in compliance with the License.
73859Sml29623 *
83859Sml29623 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
93859Sml29623 * or http://www.opensolaris.org/os/licensing.
103859Sml29623 * See the License for the specific language governing permissions
113859Sml29623 * and limitations under the License.
123859Sml29623 *
133859Sml29623 * When distributing Covered Code, include this CDDL HEADER in each
143859Sml29623 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
153859Sml29623 * If applicable, add the following below this CDDL HEADER, with the
163859Sml29623 * fields enclosed by brackets "[]" replaced with your own identifying
173859Sml29623 * information: Portions Copyright [yyyy] [name of copyright owner]
183859Sml29623 *
193859Sml29623 * CDDL HEADER END
203859Sml29623 */
213859Sml29623 /*
22*11304SJanie.Lu@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
233859Sml29623 * Use is subject to license terms.
243859Sml29623 */
253859Sml29623
263859Sml29623 #include <npi_rxdma.h>
276495Sspeer #include <npi_rx_rd64.h>
286495Sspeer #include <npi_rx_wr64.h>
293859Sml29623 #include <nxge_common.h>
303859Sml29623
313859Sml29623 #define RXDMA_RESET_TRY_COUNT 4
323859Sml29623 #define RXDMA_RESET_DELAY 5
333859Sml29623
343859Sml29623 #define RXDMA_OP_DISABLE 0
353859Sml29623 #define RXDMA_OP_ENABLE 1
363859Sml29623 #define RXDMA_OP_RESET 2
373859Sml29623
383859Sml29623 #define RCR_TIMEOUT_ENABLE 1
393859Sml29623 #define RCR_TIMEOUT_DISABLE 2
403859Sml29623 #define RCR_THRESHOLD 4
413859Sml29623
423859Sml29623 /* assume weight is in byte frames unit */
433859Sml29623 #define WEIGHT_FACTOR 3/2
443859Sml29623
453859Sml29623 uint64_t rdc_dmc_offset[] = {
463859Sml29623 RXDMA_CFIG1_REG, RXDMA_CFIG2_REG, RBR_CFIG_A_REG, RBR_CFIG_B_REG,
473859Sml29623 RBR_KICK_REG, RBR_STAT_REG, RBR_HDH_REG, RBR_HDL_REG,
483859Sml29623 RCRCFIG_A_REG, RCRCFIG_B_REG, RCRSTAT_A_REG, RCRSTAT_B_REG,
493859Sml29623 RCRSTAT_C_REG, RX_DMA_ENT_MSK_REG, RX_DMA_CTL_STAT_REG, RCR_FLSH_REG,
503859Sml29623 RXMISC_DISCARD_REG
513859Sml29623 };
523859Sml29623
533859Sml29623 const char *rdc_dmc_name[] = {
543859Sml29623 "RXDMA_CFIG1", "RXDMA_CFIG2", "RBR_CFIG_A", "RBR_CFIG_B",
553859Sml29623 "RBR_KICK", "RBR_STAT", "RBR_HDH", "RBR_HDL",
563859Sml29623 "RCRCFIG_A", "RCRCFIG_B", "RCRSTAT_A", "RCRSTAT_B",
573859Sml29623 "RCRSTAT_C", "RX_DMA_ENT_MSK", "RX_DMA_CTL_STAT", "RCR_FLSH",
583859Sml29623 "RXMISC_DISCARD"
593859Sml29623 };
603859Sml29623
613859Sml29623 uint64_t rdc_fzc_offset [] = {
623859Sml29623 RX_LOG_PAGE_VLD_REG, RX_LOG_PAGE_MASK1_REG, RX_LOG_PAGE_VAL1_REG,
633859Sml29623 RX_LOG_PAGE_MASK2_REG, RX_LOG_PAGE_VAL2_REG, RX_LOG_PAGE_RELO1_REG,
643859Sml29623 RX_LOG_PAGE_RELO2_REG, RX_LOG_PAGE_HDL_REG, RDC_RED_PARA_REG,
653859Sml29623 RED_DIS_CNT_REG
663859Sml29623 };
673859Sml29623
683859Sml29623
693859Sml29623 const char *rdc_fzc_name [] = {
703859Sml29623 "RX_LOG_PAGE_VLD", "RX_LOG_PAGE_MASK1", "RX_LOG_PAGE_VAL1",
713859Sml29623 "RX_LOG_PAGE_MASK2", "RX_LOG_PAGE_VAL2", "RX_LOG_PAGE_RELO1",
723859Sml29623 "RX_LOG_PAGE_RELO2", "RX_LOG_PAGE_HDL", "RDC_RED_PARA", "RED_DIS_CNT"
733859Sml29623 };
743859Sml29623
753859Sml29623
763859Sml29623 /*
773859Sml29623 * Dump the MEM_ADD register first so all the data registers
783859Sml29623 * will have valid data buffer pointers.
793859Sml29623 */
803859Sml29623 uint64_t rx_fzc_offset[] = {
813859Sml29623 RX_DMA_CK_DIV_REG, DEF_PT0_RDC_REG, DEF_PT1_RDC_REG, DEF_PT2_RDC_REG,
823859Sml29623 DEF_PT3_RDC_REG, RX_ADDR_MD_REG, PT_DRR_WT0_REG, PT_DRR_WT1_REG,
833859Sml29623 PT_DRR_WT2_REG, PT_DRR_WT3_REG, PT_USE0_REG, PT_USE1_REG,
843859Sml29623 PT_USE2_REG, PT_USE3_REG, RED_RAN_INIT_REG, RX_ADDR_MD_REG,
853859Sml29623 RDMC_PRE_PAR_ERR_REG, RDMC_SHA_PAR_ERR_REG,
863859Sml29623 RDMC_MEM_DATA4_REG, RDMC_MEM_DATA3_REG, RDMC_MEM_DATA2_REG,
873859Sml29623 RDMC_MEM_DATA1_REG, RDMC_MEM_DATA0_REG,
883859Sml29623 RDMC_MEM_ADDR_REG,
893859Sml29623 RX_CTL_DAT_FIFO_STAT_REG, RX_CTL_DAT_FIFO_MASK_REG,
903859Sml29623 RX_CTL_DAT_FIFO_STAT_DBG_REG,
913859Sml29623 RDMC_TRAINING_VECTOR_REG,
923859Sml29623 };
933859Sml29623
943859Sml29623
953859Sml29623 const char *rx_fzc_name[] = {
963859Sml29623 "RX_DMA_CK_DIV", "DEF_PT0_RDC", "DEF_PT1_RDC", "DEF_PT2_RDC",
973859Sml29623 "DEF_PT3_RDC", "RX_ADDR_MD", "PT_DRR_WT0", "PT_DRR_WT1",
983859Sml29623 "PT_DRR_WT2", "PT_DRR_WT3", "PT_USE0", "PT_USE1",
993859Sml29623 "PT_USE2", "PT_USE3", "RED_RAN_INIT", "RX_ADDR_MD",
1003859Sml29623 "RDMC_PRE_PAR_ERR", "RDMC_SHA_PAR_ERR",
1013859Sml29623 "RDMC_MEM_DATA4", "RDMC_MEM_DATA3", "RDMC_MEM_DATA2",
1023859Sml29623 "RDMC_MEM_DATA1", "RDMC_MEM_DATA0",
1033859Sml29623 "RDMC_MEM_ADDR",
1043859Sml29623 "RX_CTL_DAT_FIFO_STAT", "RX_CTL_DAT_FIFO_MASK",
1053859Sml29623 "RDMC_TRAINING_VECTOR_REG",
1063859Sml29623 "RX_CTL_DAT_FIFO_STAT_DBG_REG"
1073859Sml29623 };
1083859Sml29623
1093859Sml29623
1103859Sml29623 npi_status_t
1113859Sml29623 npi_rxdma_cfg_rdc_ctl(npi_handle_t handle, uint8_t rdc, uint8_t op);
1123859Sml29623 npi_status_t
1133859Sml29623 npi_rxdma_cfg_rdc_rcr_ctl(npi_handle_t handle, uint8_t rdc, uint8_t op,
1143859Sml29623 uint16_t param);
1153859Sml29623
1163859Sml29623
1173859Sml29623 /*
1183859Sml29623 * npi_rxdma_dump_rdc_regs
1193859Sml29623 * Dumps the contents of rdc csrs and fzc registers
1203859Sml29623 *
1213859Sml29623 * Input:
1223859Sml29623 * handle: opaque handle interpreted by the underlying OS
1233859Sml29623 * rdc: RX DMA number
1243859Sml29623 *
1253859Sml29623 * return:
1263859Sml29623 * NPI_SUCCESS
1273859Sml29623 * NPI_RXDMA_RDC_INVALID
1283859Sml29623 *
1293859Sml29623 */
1303859Sml29623 npi_status_t
npi_rxdma_dump_rdc_regs(npi_handle_t handle,uint8_t rdc)1313859Sml29623 npi_rxdma_dump_rdc_regs(npi_handle_t handle, uint8_t rdc)
1323859Sml29623 {
1333859Sml29623
1343859Sml29623 uint64_t value, offset;
1353859Sml29623 int num_regs, i;
1363859Sml29623 #ifdef NPI_DEBUG
1373859Sml29623 extern uint64_t npi_debug_level;
1383859Sml29623 uint64_t old_npi_debug_level = npi_debug_level;
1393859Sml29623 #endif
1403859Sml29623 ASSERT(RXDMA_CHANNEL_VALID(rdc));
1413859Sml29623 if (!RXDMA_CHANNEL_VALID(rdc)) {
1423859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1436929Smisaki "npi_rxdma_dump_rdc_regs"
1446929Smisaki " Illegal RDC number %d \n",
1456929Smisaki rdc));
1463859Sml29623 return (NPI_RXDMA_RDC_INVALID);
1473859Sml29623 }
1483859Sml29623 #ifdef NPI_DEBUG
1493859Sml29623 npi_debug_level |= DUMP_ALWAYS;
1503859Sml29623 #endif
1513859Sml29623 num_regs = sizeof (rdc_dmc_offset) / sizeof (uint64_t);
1523859Sml29623 NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
1536929Smisaki "\nDMC Register Dump for Channel %d\n",
1546929Smisaki rdc));
1553859Sml29623 for (i = 0; i < num_regs; i++) {
1563859Sml29623 RXDMA_REG_READ64(handle, rdc_dmc_offset[i], rdc, &value);
1573859Sml29623 offset = NXGE_RXDMA_OFFSET(rdc_dmc_offset[i], handle.is_vraddr,
1586929Smisaki rdc);
1593859Sml29623 NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
1606929Smisaki "%08llx %s\t %08llx \n",
1616929Smisaki offset, rdc_dmc_name[i], value));
1623859Sml29623 }
1633859Sml29623
1643859Sml29623 NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
1656929Smisaki "\n Register Dump for Channel %d done\n",
1666929Smisaki rdc));
1673859Sml29623 #ifdef NPI_DEBUG
1683859Sml29623 npi_debug_level = old_npi_debug_level;
1693859Sml29623 #endif
1703859Sml29623 return (NPI_SUCCESS);
1713859Sml29623 }
1723859Sml29623
1733859Sml29623 /*
1743859Sml29623 * npi_rxdma_dump_fzc_regs
1753859Sml29623 * Dumps the contents of rdc csrs and fzc registers
1763859Sml29623 *
1773859Sml29623 * Input:
1783859Sml29623 * handle: opaque handle interpreted by the underlying OS
1793859Sml29623 *
1803859Sml29623 * return:
1813859Sml29623 * NPI_SUCCESS
1823859Sml29623 */
1833859Sml29623 npi_status_t
npi_rxdma_dump_fzc_regs(npi_handle_t handle)1843859Sml29623 npi_rxdma_dump_fzc_regs(npi_handle_t handle)
1853859Sml29623 {
1863859Sml29623
1873859Sml29623 uint64_t value;
1883859Sml29623 int num_regs, i;
1893859Sml29623
1903859Sml29623
1913859Sml29623 NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
1926929Smisaki "\nFZC_DMC Common Register Dump\n"));
1933859Sml29623 num_regs = sizeof (rx_fzc_offset) / sizeof (uint64_t);
1943859Sml29623
1953859Sml29623 for (i = 0; i < num_regs; i++) {
1963859Sml29623 NXGE_REG_RD64(handle, rx_fzc_offset[i], &value);
1973859Sml29623 NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
1986929Smisaki "0x%08llx %s\t 0x%08llx \n",
1996929Smisaki rx_fzc_offset[i],
2006929Smisaki rx_fzc_name[i], value));
2013859Sml29623 }
2023859Sml29623 NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
2036929Smisaki "\n FZC_DMC Register Dump Done \n"));
2043859Sml29623
2053859Sml29623 return (NPI_SUCCESS);
2063859Sml29623 }
2073859Sml29623
2083859Sml29623
2093859Sml29623
2103859Sml29623 /*
2113859Sml29623 * per rdc config functions
2123859Sml29623 */
2133859Sml29623 npi_status_t
npi_rxdma_cfg_logical_page_disable(npi_handle_t handle,uint8_t rdc,uint8_t page_num)2143859Sml29623 npi_rxdma_cfg_logical_page_disable(npi_handle_t handle, uint8_t rdc,
2153859Sml29623 uint8_t page_num)
2163859Sml29623 {
2173859Sml29623 log_page_vld_t page_vld;
2183859Sml29623 uint64_t valid_offset;
2193859Sml29623
2203859Sml29623 ASSERT(RXDMA_CHANNEL_VALID(rdc));
2213859Sml29623 if (!RXDMA_CHANNEL_VALID(rdc)) {
2223859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
2236929Smisaki "rxdma_cfg_logical_page_disable"
2246929Smisaki " Illegal RDC number %d \n",
2256929Smisaki rdc));
2263859Sml29623 return (NPI_RXDMA_RDC_INVALID);
2273859Sml29623 }
2283859Sml29623
2293859Sml29623 ASSERT(RXDMA_PAGE_VALID(page_num));
2303859Sml29623 if (!RXDMA_PAGE_VALID(page_num)) {
2313859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
2326929Smisaki "rxdma_cfg_logical_page_disable"
2336929Smisaki " Illegal page number %d \n",
2346929Smisaki page_num));
2353859Sml29623 return (NPI_RXDMA_PAGE_INVALID);
2363859Sml29623 }
2373859Sml29623
2383859Sml29623 valid_offset = REG_FZC_RDC_OFFSET(RX_LOG_PAGE_VLD_REG, rdc);
2393859Sml29623 NXGE_REG_RD64(handle, valid_offset, &page_vld.value);
2403859Sml29623
2413859Sml29623 if (page_num == 0)
2423859Sml29623 page_vld.bits.ldw.page0 = 0;
2433859Sml29623
2443859Sml29623 if (page_num == 1)
2453859Sml29623 page_vld.bits.ldw.page1 = 0;
2463859Sml29623
2473859Sml29623 NXGE_REG_WR64(handle, valid_offset, page_vld.value);
2483859Sml29623 return (NPI_SUCCESS);
2493859Sml29623
2503859Sml29623 }
2513859Sml29623
2523859Sml29623 npi_status_t
npi_rxdma_cfg_logical_page(npi_handle_t handle,uint8_t rdc,dma_log_page_t * pg_cfg)2533859Sml29623 npi_rxdma_cfg_logical_page(npi_handle_t handle, uint8_t rdc,
2543859Sml29623 dma_log_page_t *pg_cfg)
2553859Sml29623 {
2563859Sml29623 log_page_vld_t page_vld;
2573859Sml29623 log_page_mask_t page_mask;
2583859Sml29623 log_page_value_t page_value;
2593859Sml29623 log_page_relo_t page_reloc;
2603859Sml29623 uint64_t value_offset, reloc_offset, mask_offset;
2613859Sml29623 uint64_t valid_offset;
2623859Sml29623
2633859Sml29623 ASSERT(RXDMA_CHANNEL_VALID(rdc));
2643859Sml29623 if (!RXDMA_CHANNEL_VALID(rdc)) {
2653859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
2666929Smisaki " rxdma_cfg_logical_page"
2676929Smisaki " Illegal RDC number %d \n",
2686929Smisaki rdc));
2693859Sml29623 return (NPI_RXDMA_RDC_INVALID);
2703859Sml29623 }
2713859Sml29623
2723859Sml29623 ASSERT(RXDMA_PAGE_VALID(pg_cfg->page_num));
2733859Sml29623 if (!RXDMA_PAGE_VALID(pg_cfg->page_num)) {
2743859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
2756929Smisaki " rxdma_cfg_logical_page"
2766929Smisaki " Illegal page number %d \n",
2776929Smisaki pg_cfg->page_num));
2783859Sml29623 return (NPI_RXDMA_PAGE_INVALID);
2793859Sml29623 }
2803859Sml29623
2813859Sml29623 valid_offset = REG_FZC_RDC_OFFSET(RX_LOG_PAGE_VLD_REG, rdc);
2823859Sml29623 NXGE_REG_RD64(handle, valid_offset, &page_vld.value);
2833859Sml29623
2843859Sml29623 if (!pg_cfg->valid) {
2853859Sml29623 if (pg_cfg->page_num == 0)
2863859Sml29623 page_vld.bits.ldw.page0 = 0;
2873859Sml29623
2883859Sml29623 if (pg_cfg->page_num == 1)
2893859Sml29623 page_vld.bits.ldw.page1 = 0;
2903859Sml29623 NXGE_REG_WR64(handle, valid_offset, page_vld.value);
2913859Sml29623 return (NPI_SUCCESS);
2923859Sml29623 }
2933859Sml29623
2943859Sml29623 if (pg_cfg->page_num == 0) {
2953859Sml29623 mask_offset = REG_FZC_RDC_OFFSET(RX_LOG_PAGE_MASK1_REG, rdc);
2963859Sml29623 value_offset = REG_FZC_RDC_OFFSET(RX_LOG_PAGE_VAL1_REG, rdc);
2973859Sml29623 reloc_offset = REG_FZC_RDC_OFFSET(RX_LOG_PAGE_RELO1_REG, rdc);
2983859Sml29623 page_vld.bits.ldw.page0 = 1;
2993859Sml29623 }
3003859Sml29623
3013859Sml29623 if (pg_cfg->page_num == 1) {
3023859Sml29623 mask_offset = REG_FZC_RDC_OFFSET(RX_LOG_PAGE_MASK2_REG, rdc);
3033859Sml29623 value_offset = REG_FZC_RDC_OFFSET(RX_LOG_PAGE_VAL2_REG, rdc);
3043859Sml29623 reloc_offset = REG_FZC_RDC_OFFSET(RX_LOG_PAGE_RELO2_REG, rdc);
3053859Sml29623 page_vld.bits.ldw.page1 = 1;
3063859Sml29623 }
3073859Sml29623
3083859Sml29623
3093859Sml29623 page_vld.bits.ldw.func = pg_cfg->func_num;
3103859Sml29623
3113859Sml29623 page_mask.value = 0;
3123859Sml29623 page_value.value = 0;
3133859Sml29623 page_reloc.value = 0;
3143859Sml29623
3153859Sml29623
3163859Sml29623 page_mask.bits.ldw.mask = pg_cfg->mask >> LOG_PAGE_ADDR_SHIFT;
3173859Sml29623 page_value.bits.ldw.value = pg_cfg->value >> LOG_PAGE_ADDR_SHIFT;
3183859Sml29623 page_reloc.bits.ldw.relo = pg_cfg->reloc >> LOG_PAGE_ADDR_SHIFT;
3193859Sml29623
3203859Sml29623
3213859Sml29623 NXGE_REG_WR64(handle, mask_offset, page_mask.value);
3223859Sml29623 NXGE_REG_WR64(handle, value_offset, page_value.value);
3233859Sml29623 NXGE_REG_WR64(handle, reloc_offset, page_reloc.value);
3243859Sml29623
3253859Sml29623
3263859Sml29623 /* enable the logical page */
3273859Sml29623 NXGE_REG_WR64(handle, valid_offset, page_vld.value);
3283859Sml29623 return (NPI_SUCCESS);
3293859Sml29623 }
3303859Sml29623
3313859Sml29623 npi_status_t
npi_rxdma_cfg_logical_page_handle(npi_handle_t handle,uint8_t rdc,uint64_t page_handle)3323859Sml29623 npi_rxdma_cfg_logical_page_handle(npi_handle_t handle, uint8_t rdc,
3333859Sml29623 uint64_t page_handle)
3343859Sml29623 {
3353859Sml29623 uint64_t offset;
3363859Sml29623 log_page_hdl_t page_hdl;
3373859Sml29623
3383859Sml29623 ASSERT(RXDMA_CHANNEL_VALID(rdc));
3393859Sml29623 if (!RXDMA_CHANNEL_VALID(rdc)) {
3403859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
3413859Sml29623 "rxdma_cfg_logical_page_handle"
3423859Sml29623 " Illegal RDC number %d \n", rdc));
3433859Sml29623 return (NPI_RXDMA_RDC_INVALID);
3443859Sml29623 }
3453859Sml29623
3463859Sml29623 page_hdl.value = 0;
3473859Sml29623
3483859Sml29623 page_hdl.bits.ldw.handle = (uint32_t)page_handle;
3493859Sml29623 offset = REG_FZC_RDC_OFFSET(RX_LOG_PAGE_HDL_REG, rdc);
3503859Sml29623 NXGE_REG_WR64(handle, offset, page_hdl.value);
3513859Sml29623
3523859Sml29623 return (NPI_SUCCESS);
3533859Sml29623 }
3543859Sml29623
3553859Sml29623 /*
3563859Sml29623 * RX DMA functions
3573859Sml29623 */
3583859Sml29623 npi_status_t
npi_rxdma_cfg_rdc_ctl(npi_handle_t handle,uint8_t rdc,uint8_t op)3593859Sml29623 npi_rxdma_cfg_rdc_ctl(npi_handle_t handle, uint8_t rdc, uint8_t op)
3603859Sml29623 {
3613859Sml29623
3623859Sml29623 rxdma_cfig1_t cfg;
3633859Sml29623 uint32_t count = RXDMA_RESET_TRY_COUNT;
3643859Sml29623 uint32_t delay_time = RXDMA_RESET_DELAY;
3653859Sml29623 uint32_t error = NPI_RXDMA_ERROR_ENCODE(NPI_RXDMA_RESET_ERR, rdc);
3663859Sml29623
3673859Sml29623 ASSERT(RXDMA_CHANNEL_VALID(rdc));
3683859Sml29623 if (!RXDMA_CHANNEL_VALID(rdc)) {
3693859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
3706929Smisaki "npi_rxdma_cfg_rdc_ctl"
3716929Smisaki " Illegal RDC number %d \n", rdc));
3723859Sml29623 return (NPI_RXDMA_RDC_INVALID);
3733859Sml29623 }
3743859Sml29623
3753859Sml29623
3763859Sml29623 switch (op) {
3773859Sml29623 case RXDMA_OP_ENABLE:
3783859Sml29623 RXDMA_REG_READ64(handle, RXDMA_CFIG1_REG, rdc,
3796929Smisaki &cfg.value);
3803859Sml29623 cfg.bits.ldw.en = 1;
3813859Sml29623 RXDMA_REG_WRITE64(handle, RXDMA_CFIG1_REG,
3826929Smisaki rdc, cfg.value);
3833859Sml29623
3843859Sml29623 NXGE_DELAY(delay_time);
3853859Sml29623 RXDMA_REG_READ64(handle, RXDMA_CFIG1_REG, rdc,
3866929Smisaki &cfg.value);
3873859Sml29623 while ((count--) && (cfg.bits.ldw.qst == 0)) {
3883859Sml29623 NXGE_DELAY(delay_time);
3893859Sml29623 RXDMA_REG_READ64(handle, RXDMA_CFIG1_REG, rdc,
3906929Smisaki &cfg.value);
3913859Sml29623 }
3923859Sml29623
3933859Sml29623 if (cfg.bits.ldw.qst == 0) {
3943859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
3953859Sml29623 " npi_rxdma_cfg_rdc_ctl"
3963859Sml29623 " RXDMA_OP_ENABLE Failed for RDC %d \n",
3973859Sml29623 rdc));
3983859Sml29623 return (error);
3993859Sml29623 }
4003859Sml29623
4013859Sml29623 break;
4023859Sml29623 case RXDMA_OP_DISABLE:
4033859Sml29623 RXDMA_REG_READ64(handle, RXDMA_CFIG1_REG, rdc,
4046929Smisaki &cfg.value);
4053859Sml29623 cfg.bits.ldw.en = 0;
4063859Sml29623 RXDMA_REG_WRITE64(handle, RXDMA_CFIG1_REG,
4076929Smisaki rdc, cfg.value);
4083859Sml29623
4093859Sml29623 NXGE_DELAY(delay_time);
4103859Sml29623 RXDMA_REG_READ64(handle, RXDMA_CFIG1_REG, rdc,
4116929Smisaki &cfg.value);
4123859Sml29623 while ((count--) && (cfg.bits.ldw.qst == 0)) {
4133859Sml29623 NXGE_DELAY(delay_time);
4143859Sml29623 RXDMA_REG_READ64(handle, RXDMA_CFIG1_REG, rdc,
4156929Smisaki &cfg.value);
4163859Sml29623 }
4173859Sml29623 if (cfg.bits.ldw.qst == 0) {
4183859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
4193859Sml29623 " npi_rxdma_cfg_rdc_ctl"
4203859Sml29623 " RXDMA_OP_DISABLE Failed for RDC %d \n",
4213859Sml29623 rdc));
4223859Sml29623 return (error);
4233859Sml29623 }
4243859Sml29623
4253859Sml29623 break;
4263859Sml29623 case RXDMA_OP_RESET:
4273859Sml29623 cfg.value = 0;
4283859Sml29623 cfg.bits.ldw.rst = 1;
4293859Sml29623 RXDMA_REG_WRITE64(handle,
4306929Smisaki RXDMA_CFIG1_REG,
4316929Smisaki rdc, cfg.value);
4323859Sml29623 NXGE_DELAY(delay_time);
4333859Sml29623 RXDMA_REG_READ64(handle, RXDMA_CFIG1_REG, rdc,
4346929Smisaki &cfg.value);
4353859Sml29623 while ((count--) && (cfg.bits.ldw.rst)) {
4363859Sml29623 NXGE_DELAY(delay_time);
4373859Sml29623 RXDMA_REG_READ64(handle, RXDMA_CFIG1_REG, rdc,
4386929Smisaki &cfg.value);
4393859Sml29623 }
4403859Sml29623 if (count == 0) {
4413859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
4426929Smisaki " npi_rxdma_cfg_rdc_ctl"
4436929Smisaki " Reset Failed for RDC %d \n",
4446929Smisaki rdc));
4453859Sml29623 return (error);
4463859Sml29623 }
4473859Sml29623 break;
4483859Sml29623 default:
4493859Sml29623 return (NPI_RXDMA_SW_PARAM_ERROR);
4503859Sml29623 }
4513859Sml29623
4523859Sml29623 return (NPI_SUCCESS);
4533859Sml29623 }
4543859Sml29623
4553859Sml29623 npi_status_t
npi_rxdma_cfg_rdc_enable(npi_handle_t handle,uint8_t rdc)4563859Sml29623 npi_rxdma_cfg_rdc_enable(npi_handle_t handle, uint8_t rdc)
4573859Sml29623 {
4583859Sml29623 return (npi_rxdma_cfg_rdc_ctl(handle, rdc, RXDMA_OP_ENABLE));
4593859Sml29623 }
4603859Sml29623
4613859Sml29623 npi_status_t
npi_rxdma_cfg_rdc_disable(npi_handle_t handle,uint8_t rdc)4623859Sml29623 npi_rxdma_cfg_rdc_disable(npi_handle_t handle, uint8_t rdc)
4633859Sml29623 {
4643859Sml29623 return (npi_rxdma_cfg_rdc_ctl(handle, rdc, RXDMA_OP_DISABLE));
4653859Sml29623 }
4663859Sml29623
4673859Sml29623 npi_status_t
npi_rxdma_cfg_rdc_reset(npi_handle_t handle,uint8_t rdc)4683859Sml29623 npi_rxdma_cfg_rdc_reset(npi_handle_t handle, uint8_t rdc)
4693859Sml29623 {
4703859Sml29623 return (npi_rxdma_cfg_rdc_ctl(handle, rdc, RXDMA_OP_RESET));
4713859Sml29623 }
4723859Sml29623
4733859Sml29623 /*
4743859Sml29623 * npi_rxdma_cfg_defualt_port_rdc()
4753859Sml29623 * Set the default rdc for the port
4763859Sml29623 *
4773859Sml29623 * Inputs:
4783859Sml29623 * handle: register handle interpreted by the underlying OS
4793859Sml29623 * portnm: Physical Port Number
4803859Sml29623 * rdc: RX DMA Channel number
4813859Sml29623 *
4823859Sml29623 * Return:
4833859Sml29623 * NPI_SUCCESS
4843859Sml29623 * NPI_RXDMA_RDC_INVALID
4853859Sml29623 * NPI_RXDMA_PORT_INVALID
4863859Sml29623 *
4873859Sml29623 */
npi_rxdma_cfg_default_port_rdc(npi_handle_t handle,uint8_t portnm,uint8_t rdc)4883859Sml29623 npi_status_t npi_rxdma_cfg_default_port_rdc(npi_handle_t handle,
4893859Sml29623 uint8_t portnm, uint8_t rdc)
4903859Sml29623 {
4913859Sml29623
4923859Sml29623 uint64_t offset;
4933859Sml29623 def_pt_rdc_t cfg;
4943859Sml29623
4953859Sml29623 ASSERT(RXDMA_CHANNEL_VALID(rdc));
4963859Sml29623 if (!RXDMA_CHANNEL_VALID(rdc)) {
4973859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
4986929Smisaki "rxdma_cfg_default_port_rdc"
4996929Smisaki " Illegal RDC number %d \n",
5006929Smisaki rdc));
5013859Sml29623 return (NPI_RXDMA_RDC_INVALID);
5023859Sml29623 }
5033859Sml29623
5043859Sml29623 ASSERT(RXDMA_PORT_VALID(portnm));
5053859Sml29623 if (!RXDMA_PORT_VALID(portnm)) {
5063859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
5076929Smisaki "rxdma_cfg_default_port_rdc"
5086929Smisaki " Illegal Port number %d \n",
5096929Smisaki portnm));
5103859Sml29623 return (NPI_RXDMA_PORT_INVALID);
5113859Sml29623 }
5123859Sml29623
5133859Sml29623 offset = DEF_PT_RDC_REG(portnm);
5143859Sml29623 cfg.value = 0;
5153859Sml29623 cfg.bits.ldw.rdc = rdc;
5163859Sml29623 NXGE_REG_WR64(handle, offset, cfg.value);
5173859Sml29623 return (NPI_SUCCESS);
5183859Sml29623 }
5193859Sml29623
5203859Sml29623 npi_status_t
npi_rxdma_cfg_rdc_rcr_ctl(npi_handle_t handle,uint8_t rdc,uint8_t op,uint16_t param)5213859Sml29623 npi_rxdma_cfg_rdc_rcr_ctl(npi_handle_t handle, uint8_t rdc,
5223859Sml29623 uint8_t op, uint16_t param)
5233859Sml29623 {
5243859Sml29623 rcrcfig_b_t rcr_cfgb;
5253859Sml29623
5263859Sml29623 ASSERT(RXDMA_CHANNEL_VALID(rdc));
5273859Sml29623 if (!RXDMA_CHANNEL_VALID(rdc)) {
5283859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
5296929Smisaki "rxdma_cfg_rdc_rcr_ctl"
5306929Smisaki " Illegal RDC number %d \n",
5316929Smisaki rdc));
5323859Sml29623 return (NPI_RXDMA_RDC_INVALID);
5333859Sml29623 }
5343859Sml29623
5353859Sml29623
5363859Sml29623 RXDMA_REG_READ64(handle, RCRCFIG_B_REG, rdc, &rcr_cfgb.value);
5373859Sml29623
5383859Sml29623 switch (op) {
5393859Sml29623 case RCR_TIMEOUT_ENABLE:
5403859Sml29623 rcr_cfgb.bits.ldw.timeout = (uint8_t)param;
5413859Sml29623 rcr_cfgb.bits.ldw.entout = 1;
5423859Sml29623 break;
5433859Sml29623
5443859Sml29623 case RCR_THRESHOLD:
5453859Sml29623 rcr_cfgb.bits.ldw.pthres = param;
5463859Sml29623 break;
5473859Sml29623
5483859Sml29623 case RCR_TIMEOUT_DISABLE:
5493859Sml29623 rcr_cfgb.bits.ldw.entout = 0;
5503859Sml29623 break;
5513859Sml29623
5523859Sml29623 default:
5533859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
5546929Smisaki "rxdma_cfg_rdc_rcr_ctl"
5556929Smisaki " Illegal opcode %x \n",
5566929Smisaki op));
5573859Sml29623 return (NPI_RXDMA_OPCODE_INVALID(rdc));
5583859Sml29623 }
5593859Sml29623
5603859Sml29623 RXDMA_REG_WRITE64(handle, RCRCFIG_B_REG, rdc, rcr_cfgb.value);
5613859Sml29623 return (NPI_SUCCESS);
5623859Sml29623 }
5633859Sml29623
5643859Sml29623 npi_status_t
npi_rxdma_cfg_rdc_rcr_timeout_disable(npi_handle_t handle,uint8_t rdc)5653859Sml29623 npi_rxdma_cfg_rdc_rcr_timeout_disable(npi_handle_t handle, uint8_t rdc)
5663859Sml29623 {
5673859Sml29623 return (npi_rxdma_cfg_rdc_rcr_ctl(handle, rdc,
5683859Sml29623 RCR_TIMEOUT_DISABLE, 0));
5693859Sml29623 }
5703859Sml29623
5713859Sml29623 npi_status_t
npi_rxdma_cfg_rdc_rcr_threshold(npi_handle_t handle,uint8_t rdc,uint16_t rcr_threshold)5723859Sml29623 npi_rxdma_cfg_rdc_rcr_threshold(npi_handle_t handle, uint8_t rdc,
5733859Sml29623 uint16_t rcr_threshold)
5743859Sml29623 {
5753859Sml29623 return (npi_rxdma_cfg_rdc_rcr_ctl(handle, rdc,
5763859Sml29623 RCR_THRESHOLD, rcr_threshold));
5773859Sml29623
5783859Sml29623 }
5793859Sml29623
5803859Sml29623 npi_status_t
npi_rxdma_cfg_rdc_rcr_timeout(npi_handle_t handle,uint8_t rdc,uint8_t rcr_timeout)5813859Sml29623 npi_rxdma_cfg_rdc_rcr_timeout(npi_handle_t handle, uint8_t rdc,
5823859Sml29623 uint8_t rcr_timeout)
5833859Sml29623 {
5843859Sml29623 return (npi_rxdma_cfg_rdc_rcr_ctl(handle, rdc,
5853859Sml29623 RCR_TIMEOUT_ENABLE, rcr_timeout));
5863859Sml29623
5873859Sml29623 }
5883859Sml29623
5893859Sml29623 /*
5903859Sml29623 * npi_rxdma_cfg_rdc_ring()
5913859Sml29623 * Configure The RDC channel Rcv Buffer Ring
5923859Sml29623 */
5933859Sml29623 npi_status_t
npi_rxdma_cfg_rdc_ring(npi_handle_t handle,uint8_t rdc,rdc_desc_cfg_t * rdc_desc_cfg,boolean_t new_off)5943859Sml29623 npi_rxdma_cfg_rdc_ring(npi_handle_t handle, uint8_t rdc,
595*11304SJanie.Lu@Sun.COM rdc_desc_cfg_t *rdc_desc_cfg, boolean_t new_off)
5963859Sml29623 {
5973859Sml29623 rbr_cfig_a_t cfga;
5983859Sml29623 rbr_cfig_b_t cfgb;
5993859Sml29623 rxdma_cfig1_t cfg1;
6003859Sml29623 rxdma_cfig2_t cfg2;
6013859Sml29623 rcrcfig_a_t rcr_cfga;
6023859Sml29623 rcrcfig_b_t rcr_cfgb;
6033859Sml29623
6043859Sml29623 ASSERT(RXDMA_CHANNEL_VALID(rdc));
6053859Sml29623 if (!RXDMA_CHANNEL_VALID(rdc)) {
6063859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
6076929Smisaki "rxdma_cfg_rdc_ring"
6086929Smisaki " Illegal RDC number %d \n",
6096929Smisaki rdc));
6103859Sml29623 return (NPI_RXDMA_RDC_INVALID);
6113859Sml29623 }
6123859Sml29623
6133859Sml29623
6143859Sml29623 cfga.value = 0;
6153859Sml29623 cfgb.value = 0;
6163859Sml29623 cfg1.value = 0;
6173859Sml29623 cfg2.value = 0;
6183859Sml29623
6193859Sml29623 if (rdc_desc_cfg->mbox_enable == 1) {
6203859Sml29623 cfg1.bits.ldw.mbaddr_h =
6213859Sml29623 (rdc_desc_cfg->mbox_addr >> 32) & 0xfff;
6223859Sml29623 cfg2.bits.ldw.mbaddr =
6233859Sml29623 ((rdc_desc_cfg->mbox_addr &
6246929Smisaki RXDMA_CFIG2_MBADDR_L_MASK) >>
6256929Smisaki RXDMA_CFIG2_MBADDR_L_SHIFT);
6263859Sml29623
6273859Sml29623
6283859Sml29623 /*
6293859Sml29623 * Only after all the configurations are set, then
6303859Sml29623 * enable the RDC or else configuration fatal error
6313859Sml29623 * will be returned (especially if the Hypervisor
6323859Sml29623 * set up the logical pages with non-zero values.
6333859Sml29623 * This NPI function only sets up the configuration.
6343859Sml29623 */
6353859Sml29623 }
6363859Sml29623
6373859Sml29623
6383859Sml29623 if (rdc_desc_cfg->full_hdr == 1)
6393859Sml29623 cfg2.bits.ldw.full_hdr = 1;
6403859Sml29623
641*11304SJanie.Lu@Sun.COM if (new_off) {
642*11304SJanie.Lu@Sun.COM if (RXDMA_RF_BUFF_OFFSET_VALID(rdc_desc_cfg->offset)) {
643*11304SJanie.Lu@Sun.COM switch (rdc_desc_cfg->offset) {
644*11304SJanie.Lu@Sun.COM case SW_OFFSET_NO_OFFSET:
645*11304SJanie.Lu@Sun.COM case SW_OFFSET_64:
646*11304SJanie.Lu@Sun.COM case SW_OFFSET_128:
647*11304SJanie.Lu@Sun.COM case SW_OFFSET_192:
648*11304SJanie.Lu@Sun.COM cfg2.bits.ldw.offset = rdc_desc_cfg->offset;
649*11304SJanie.Lu@Sun.COM cfg2.bits.ldw.offset256 = 0;
650*11304SJanie.Lu@Sun.COM break;
651*11304SJanie.Lu@Sun.COM case SW_OFFSET_256:
652*11304SJanie.Lu@Sun.COM case SW_OFFSET_320:
653*11304SJanie.Lu@Sun.COM case SW_OFFSET_384:
654*11304SJanie.Lu@Sun.COM case SW_OFFSET_448:
655*11304SJanie.Lu@Sun.COM cfg2.bits.ldw.offset =
656*11304SJanie.Lu@Sun.COM rdc_desc_cfg->offset & 0x3;
657*11304SJanie.Lu@Sun.COM cfg2.bits.ldw.offset256 = 1;
658*11304SJanie.Lu@Sun.COM break;
659*11304SJanie.Lu@Sun.COM default:
660*11304SJanie.Lu@Sun.COM cfg2.bits.ldw.offset = SW_OFFSET_NO_OFFSET;
661*11304SJanie.Lu@Sun.COM cfg2.bits.ldw.offset256 = 0;
662*11304SJanie.Lu@Sun.COM }
663*11304SJanie.Lu@Sun.COM } else {
664*11304SJanie.Lu@Sun.COM cfg2.bits.ldw.offset = SW_OFFSET_NO_OFFSET;
665*11304SJanie.Lu@Sun.COM cfg2.bits.ldw.offset256 = 0;
666*11304SJanie.Lu@Sun.COM }
6673859Sml29623 } else {
668*11304SJanie.Lu@Sun.COM if (RXDMA_BUFF_OFFSET_VALID(rdc_desc_cfg->offset)) {
669*11304SJanie.Lu@Sun.COM cfg2.bits.ldw.offset = rdc_desc_cfg->offset;
670*11304SJanie.Lu@Sun.COM } else {
671*11304SJanie.Lu@Sun.COM cfg2.bits.ldw.offset = SW_OFFSET_NO_OFFSET;
672*11304SJanie.Lu@Sun.COM }
6733859Sml29623 }
6743859Sml29623
6753859Sml29623 /* rbr config */
6763859Sml29623
6773859Sml29623 cfga.value = (rdc_desc_cfg->rbr_addr & (RBR_CFIG_A_STDADDR_MASK |
6786929Smisaki RBR_CFIG_A_STDADDR_BASE_MASK));
6793859Sml29623
6803859Sml29623 if ((rdc_desc_cfg->rbr_len < RBR_DEFAULT_MIN_LEN) ||
6816929Smisaki (rdc_desc_cfg->rbr_len > RBR_DEFAULT_MAX_LEN)) {
6823859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
6836929Smisaki "npi_rxdma_cfg_rdc_ring"
6846929Smisaki " Illegal RBR Queue Length %d \n",
6856929Smisaki rdc_desc_cfg->rbr_len));
6866495Sspeer return (NPI_RXDMA_ERROR_ENCODE(NPI_RXDMA_RBRSIZE_INVALID, rdc));
6873859Sml29623 }
6883859Sml29623
6893859Sml29623
6903859Sml29623 cfga.bits.hdw.len = rdc_desc_cfg->rbr_len;
6913859Sml29623 NPI_DEBUG_MSG((handle.function, NPI_RDC_CTL,
6926929Smisaki "npi_rxdma_cfg_rdc_ring"
6936929Smisaki " CFGA 0x%llx hdw.len %d (RBR LEN %d)\n",
6946929Smisaki cfga.value, cfga.bits.hdw.len,
6956929Smisaki rdc_desc_cfg->rbr_len));
6963859Sml29623
6973859Sml29623 if (rdc_desc_cfg->page_size == SIZE_4KB)
6983859Sml29623 cfgb.bits.ldw.bksize = RBR_BKSIZE_4K;
6993859Sml29623 else if (rdc_desc_cfg->page_size == SIZE_8KB)
7003859Sml29623 cfgb.bits.ldw.bksize = RBR_BKSIZE_8K;
7013859Sml29623 else if (rdc_desc_cfg->page_size == SIZE_16KB)
7023859Sml29623 cfgb.bits.ldw.bksize = RBR_BKSIZE_16K;
7033859Sml29623 else if (rdc_desc_cfg->page_size == SIZE_32KB)
7043859Sml29623 cfgb.bits.ldw.bksize = RBR_BKSIZE_32K;
7053859Sml29623 else {
7063859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
7076929Smisaki "rxdma_cfg_rdc_ring"
7086929Smisaki " blksize: Illegal buffer size %d \n",
7096929Smisaki rdc_desc_cfg->page_size));
7106495Sspeer return (NPI_RXDMA_BUFSIZE_INVALID);
7113859Sml29623 }
7123859Sml29623
7133859Sml29623 if (rdc_desc_cfg->valid0) {
7143859Sml29623
7153859Sml29623 if (rdc_desc_cfg->size0 == SIZE_256B)
7163859Sml29623 cfgb.bits.ldw.bufsz0 = RBR_BUFSZ0_256B;
7173859Sml29623 else if (rdc_desc_cfg->size0 == SIZE_512B)
7183859Sml29623 cfgb.bits.ldw.bufsz0 = RBR_BUFSZ0_512B;
7193859Sml29623 else if (rdc_desc_cfg->size0 == SIZE_1KB)
7203859Sml29623 cfgb.bits.ldw.bufsz0 = RBR_BUFSZ0_1K;
7213859Sml29623 else if (rdc_desc_cfg->size0 == SIZE_2KB)
7223859Sml29623 cfgb.bits.ldw.bufsz0 = RBR_BUFSZ0_2K;
7233859Sml29623 else {
7243859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
7256929Smisaki " rxdma_cfg_rdc_ring"
7266929Smisaki " blksize0: Illegal buffer size %x \n",
7276929Smisaki rdc_desc_cfg->size0));
7286495Sspeer return (NPI_RXDMA_BUFSIZE_INVALID);
7293859Sml29623 }
7303859Sml29623 cfgb.bits.ldw.vld0 = 1;
7313859Sml29623 } else {
7323859Sml29623 cfgb.bits.ldw.vld0 = 0;
7333859Sml29623 }
7343859Sml29623
7353859Sml29623
7363859Sml29623 if (rdc_desc_cfg->valid1) {
7373859Sml29623 if (rdc_desc_cfg->size1 == SIZE_1KB)
7383859Sml29623 cfgb.bits.ldw.bufsz1 = RBR_BUFSZ1_1K;
7393859Sml29623 else if (rdc_desc_cfg->size1 == SIZE_2KB)
7403859Sml29623 cfgb.bits.ldw.bufsz1 = RBR_BUFSZ1_2K;
7413859Sml29623 else if (rdc_desc_cfg->size1 == SIZE_4KB)
7423859Sml29623 cfgb.bits.ldw.bufsz1 = RBR_BUFSZ1_4K;
7433859Sml29623 else if (rdc_desc_cfg->size1 == SIZE_8KB)
7443859Sml29623 cfgb.bits.ldw.bufsz1 = RBR_BUFSZ1_8K;
7453859Sml29623 else {
7463859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
7476929Smisaki " rxdma_cfg_rdc_ring"
7486929Smisaki " blksize1: Illegal buffer size %x \n",
7496929Smisaki rdc_desc_cfg->size1));
7506495Sspeer return (NPI_RXDMA_BUFSIZE_INVALID);
7513859Sml29623 }
7523859Sml29623 cfgb.bits.ldw.vld1 = 1;
7533859Sml29623 } else {
7543859Sml29623 cfgb.bits.ldw.vld1 = 0;
7553859Sml29623 }
7563859Sml29623
7573859Sml29623
7583859Sml29623 if (rdc_desc_cfg->valid2) {
7593859Sml29623 if (rdc_desc_cfg->size2 == SIZE_2KB)
7603859Sml29623 cfgb.bits.ldw.bufsz2 = RBR_BUFSZ2_2K;
7613859Sml29623 else if (rdc_desc_cfg->size2 == SIZE_4KB)
7623859Sml29623 cfgb.bits.ldw.bufsz2 = RBR_BUFSZ2_4K;
7633859Sml29623 else if (rdc_desc_cfg->size2 == SIZE_8KB)
7643859Sml29623 cfgb.bits.ldw.bufsz2 = RBR_BUFSZ2_8K;
7653859Sml29623 else if (rdc_desc_cfg->size2 == SIZE_16KB)
7663859Sml29623 cfgb.bits.ldw.bufsz2 = RBR_BUFSZ2_16K;
7673859Sml29623 else {
7683859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
7696929Smisaki " rxdma_cfg_rdc_ring"
7706929Smisaki " blksize2: Illegal buffer size %x \n",
7716929Smisaki rdc_desc_cfg->size2));
7726495Sspeer return (NPI_RXDMA_BUFSIZE_INVALID);
7733859Sml29623 }
7743859Sml29623 cfgb.bits.ldw.vld2 = 1;
7753859Sml29623 } else {
7763859Sml29623 cfgb.bits.ldw.vld2 = 0;
7773859Sml29623 }
7783859Sml29623
7793859Sml29623
7803859Sml29623 rcr_cfga.value = (rdc_desc_cfg->rcr_addr &
7816929Smisaki (RCRCFIG_A_STADDR_MASK |
7826929Smisaki RCRCFIG_A_STADDR_BASE_MASK));
7833859Sml29623
7843859Sml29623
7853859Sml29623 if ((rdc_desc_cfg->rcr_len < RCR_DEFAULT_MIN_LEN) ||
7866929Smisaki (rdc_desc_cfg->rcr_len > NXGE_RCR_MAX)) {
7873859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
7886929Smisaki " rxdma_cfg_rdc_ring"
7896929Smisaki " Illegal RCR Queue Length %d \n",
7906929Smisaki rdc_desc_cfg->rcr_len));
7916495Sspeer return (NPI_RXDMA_ERROR_ENCODE(NPI_RXDMA_RCRSIZE_INVALID, rdc));
7923859Sml29623 }
7933859Sml29623
7943859Sml29623 rcr_cfga.bits.hdw.len = rdc_desc_cfg->rcr_len;
7953859Sml29623
7963859Sml29623
7973859Sml29623 rcr_cfgb.value = 0;
7983859Sml29623 if (rdc_desc_cfg->rcr_timeout_enable == 1) {
7993859Sml29623 /* check if the rcr timeout value is valid */
8003859Sml29623
8013859Sml29623 if (RXDMA_RCR_TO_VALID(rdc_desc_cfg->rcr_timeout)) {
8023859Sml29623 rcr_cfgb.bits.ldw.timeout = rdc_desc_cfg->rcr_timeout;
8033859Sml29623 rcr_cfgb.bits.ldw.entout = 1;
8043859Sml29623 } else {
8053859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
8066929Smisaki " rxdma_cfg_rdc_ring"
8076929Smisaki " Illegal RCR Timeout value %d \n",
8086929Smisaki rdc_desc_cfg->rcr_timeout));
8093859Sml29623 rcr_cfgb.bits.ldw.entout = 0;
8103859Sml29623 }
8113859Sml29623 } else {
8123859Sml29623 rcr_cfgb.bits.ldw.entout = 0;
8133859Sml29623 }
8143859Sml29623
8153859Sml29623 /* check if the rcr threshold value is valid */
8163859Sml29623 if (RXDMA_RCR_THRESH_VALID(rdc_desc_cfg->rcr_threshold)) {
8173859Sml29623 rcr_cfgb.bits.ldw.pthres = rdc_desc_cfg->rcr_threshold;
8183859Sml29623 } else {
8193859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
8206929Smisaki " rxdma_cfg_rdc_ring"
8216929Smisaki " Illegal RCR Threshold value %d \n",
8226929Smisaki rdc_desc_cfg->rcr_threshold));
8233859Sml29623 rcr_cfgb.bits.ldw.pthres = 1;
8243859Sml29623 }
8253859Sml29623
8263859Sml29623 /* now do the actual HW configuration */
8273859Sml29623 RXDMA_REG_WRITE64(handle, RXDMA_CFIG1_REG, rdc, cfg1.value);
8283859Sml29623 RXDMA_REG_WRITE64(handle, RXDMA_CFIG2_REG, rdc, cfg2.value);
8293859Sml29623
8303859Sml29623
8313859Sml29623 RXDMA_REG_WRITE64(handle, RBR_CFIG_A_REG, rdc, cfga.value);
8323859Sml29623 RXDMA_REG_WRITE64(handle, RBR_CFIG_B_REG, rdc, cfgb.value);
8333859Sml29623
8343859Sml29623 RXDMA_REG_WRITE64(handle, RCRCFIG_A_REG, rdc, rcr_cfga.value);
8353859Sml29623 RXDMA_REG_WRITE64(handle, RCRCFIG_B_REG, rdc, rcr_cfgb.value);
8363859Sml29623
8373859Sml29623 return (NPI_SUCCESS);
8383859Sml29623
8393859Sml29623 }
8403859Sml29623
8413859Sml29623 /*
8423859Sml29623 * npi_rxdma_red_discard_stat_get
8433859Sml29623 * Gets the current discrad count due RED
8443859Sml29623 * The counter overflow bit is cleared, if it has been set.
8453859Sml29623 *
8463859Sml29623 * Inputs:
8473859Sml29623 * handle: opaque handle interpreted by the underlying OS
8483859Sml29623 * rdc: RX DMA Channel number
8493859Sml29623 * cnt: Ptr to structure to write current RDC discard stat
8503859Sml29623 *
8513859Sml29623 * Return:
8523859Sml29623 * NPI_SUCCESS
8533859Sml29623 * NPI_RXDMA_RDC_INVALID
8543859Sml29623 *
8553859Sml29623 */
8563859Sml29623 npi_status_t
npi_rxdma_red_discard_stat_get(npi_handle_t handle,uint8_t rdc,rx_disc_cnt_t * cnt)8573859Sml29623 npi_rxdma_red_discard_stat_get(npi_handle_t handle, uint8_t rdc,
8583859Sml29623 rx_disc_cnt_t *cnt)
8593859Sml29623 {
8603859Sml29623 uint64_t offset;
8613859Sml29623
8623859Sml29623 ASSERT(RXDMA_CHANNEL_VALID(rdc));
8633859Sml29623 if (!RXDMA_CHANNEL_VALID(rdc)) {
8643859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
8656929Smisaki " npi_rxdma_red_discard_stat_get"
8666929Smisaki " Illegal RDC Number %d \n",
8676929Smisaki rdc));
8683859Sml29623 return (NPI_RXDMA_RDC_INVALID);
8693859Sml29623 }
8703859Sml29623
8713859Sml29623 offset = RDC_RED_RDC_DISC_REG(rdc);
8723859Sml29623 NXGE_REG_RD64(handle, offset, &cnt->value);
8733859Sml29623 if (cnt->bits.ldw.oflow) {
8743859Sml29623 NPI_DEBUG_MSG((handle.function, NPI_ERR_CTL,
8756929Smisaki " npi_rxdma_red_discard_stat_get"
8766929Smisaki " Counter overflow for channel %d ",
8776929Smisaki " ..... clearing \n",
8786929Smisaki rdc));
8793859Sml29623 cnt->bits.ldw.oflow = 0;
8803859Sml29623 NXGE_REG_WR64(handle, offset, cnt->value);
8813859Sml29623 cnt->bits.ldw.oflow = 1;
8823859Sml29623 }
8833859Sml29623
8843859Sml29623 return (NPI_SUCCESS);
8853859Sml29623 }
8863859Sml29623
8873859Sml29623 /*
8883859Sml29623 * npi_rxdma_red_discard_oflow_clear
8893859Sml29623 * Clear RED discard counter overflow bit
8903859Sml29623 *
8913859Sml29623 * Inputs:
8923859Sml29623 * handle: opaque handle interpreted by the underlying OS
8933859Sml29623 * rdc: RX DMA Channel number
8943859Sml29623 *
8953859Sml29623 * Return:
8963859Sml29623 * NPI_SUCCESS
8973859Sml29623 * NPI_RXDMA_RDC_INVALID
8983859Sml29623 *
8993859Sml29623 */
9003859Sml29623 npi_status_t
npi_rxdma_red_discard_oflow_clear(npi_handle_t handle,uint8_t rdc)9013859Sml29623 npi_rxdma_red_discard_oflow_clear(npi_handle_t handle, uint8_t rdc)
9023859Sml29623
9033859Sml29623 {
9043859Sml29623 uint64_t offset;
9053859Sml29623 rx_disc_cnt_t cnt;
9063859Sml29623
9073859Sml29623 ASSERT(RXDMA_CHANNEL_VALID(rdc));
9083859Sml29623 if (!RXDMA_CHANNEL_VALID(rdc)) {
9093859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
9103859Sml29623 " npi_rxdma_red_discard_oflow_clear"
9113859Sml29623 " Illegal RDC Number %d \n",
9123859Sml29623 rdc));
9133859Sml29623 return (NPI_RXDMA_RDC_INVALID);
9143859Sml29623 }
9153859Sml29623
9163859Sml29623 offset = RDC_RED_RDC_DISC_REG(rdc);
9173859Sml29623 NXGE_REG_RD64(handle, offset, &cnt.value);
9183859Sml29623 if (cnt.bits.ldw.oflow) {
9193859Sml29623 NPI_DEBUG_MSG((handle.function, NPI_RDC_CTL,
9203859Sml29623 " npi_rxdma_red_discard_oflow_clear"
9213859Sml29623 " Counter overflow for channel %d ",
9223859Sml29623 " ..... clearing \n",
9233859Sml29623 rdc));
9243859Sml29623 cnt.bits.ldw.oflow = 0;
9253859Sml29623 NXGE_REG_WR64(handle, offset, cnt.value);
9263859Sml29623 }
9273859Sml29623 return (NPI_SUCCESS);
9283859Sml29623 }
9293859Sml29623
9303859Sml29623 /*
9313859Sml29623 * npi_rxdma_misc_discard_stat_get
9323859Sml29623 * Gets the current discrad count for the rdc due to
9333859Sml29623 * buffer pool empty
9343859Sml29623 * The counter overflow bit is cleared, if it has been set.
9353859Sml29623 *
9363859Sml29623 * Inputs:
9373859Sml29623 * handle: opaque handle interpreted by the underlying OS
9383859Sml29623 * rdc: RX DMA Channel number
9393859Sml29623 * cnt: Ptr to structure to write current RDC discard stat
9403859Sml29623 *
9413859Sml29623 * Return:
9423859Sml29623 * NPI_SUCCESS
9433859Sml29623 * NPI_RXDMA_RDC_INVALID
9443859Sml29623 *
9453859Sml29623 */
9463859Sml29623 npi_status_t
npi_rxdma_misc_discard_stat_get(npi_handle_t handle,uint8_t rdc,rx_disc_cnt_t * cnt)9473859Sml29623 npi_rxdma_misc_discard_stat_get(npi_handle_t handle, uint8_t rdc,
9483859Sml29623 rx_disc_cnt_t *cnt)
9493859Sml29623 {
9503859Sml29623 ASSERT(RXDMA_CHANNEL_VALID(rdc));
9513859Sml29623 if (!RXDMA_CHANNEL_VALID(rdc)) {
9523859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
9536929Smisaki " npi_rxdma_misc_discard_stat_get"
9546929Smisaki " Illegal RDC Number %d \n",
9556929Smisaki rdc));
9563859Sml29623 return (NPI_RXDMA_RDC_INVALID);
9573859Sml29623 }
9583859Sml29623
9593859Sml29623 RXDMA_REG_READ64(handle, RXMISC_DISCARD_REG, rdc, &cnt->value);
9603859Sml29623 if (cnt->bits.ldw.oflow) {
9613859Sml29623 NPI_DEBUG_MSG((handle.function, NPI_RDC_CTL,
9626929Smisaki " npi_rxdma_misc_discard_stat_get"
9636929Smisaki " Counter overflow for channel %d ",
9646929Smisaki " ..... clearing \n",
9656929Smisaki rdc));
9663859Sml29623 cnt->bits.ldw.oflow = 0;
9673859Sml29623 RXDMA_REG_WRITE64(handle, RXMISC_DISCARD_REG, rdc, cnt->value);
9683859Sml29623 cnt->bits.ldw.oflow = 1;
9693859Sml29623 }
9703859Sml29623
9713859Sml29623 return (NPI_SUCCESS);
9723859Sml29623 }
9733859Sml29623
9743859Sml29623 /*
9753859Sml29623 * npi_rxdma_red_discard_oflow_clear
9763859Sml29623 * Clear RED discard counter overflow bit
9773859Sml29623 * clear the overflow bit for buffer pool empty discrad counter
9783859Sml29623 * for the rdc
9793859Sml29623 *
9803859Sml29623 * Inputs:
9813859Sml29623 * handle: opaque handle interpreted by the underlying OS
9823859Sml29623 * rdc: RX DMA Channel number
9833859Sml29623 *
9843859Sml29623 * Return:
9853859Sml29623 * NPI_SUCCESS
9863859Sml29623 * NPI_RXDMA_RDC_INVALID
9873859Sml29623 *
9883859Sml29623 */
9893859Sml29623 npi_status_t
npi_rxdma_misc_discard_oflow_clear(npi_handle_t handle,uint8_t rdc)9903859Sml29623 npi_rxdma_misc_discard_oflow_clear(npi_handle_t handle, uint8_t rdc)
9913859Sml29623 {
9923859Sml29623 rx_disc_cnt_t cnt;
9933859Sml29623
9943859Sml29623 ASSERT(RXDMA_CHANNEL_VALID(rdc));
9953859Sml29623 if (!RXDMA_CHANNEL_VALID(rdc)) {
9963859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
9976929Smisaki " npi_rxdma_misc_discard_oflow_clear"
9986929Smisaki " Illegal RDC Number %d \n",
9996929Smisaki rdc));
10003859Sml29623 return (NPI_RXDMA_RDC_INVALID);
10013859Sml29623 }
10023859Sml29623
10033859Sml29623 RXDMA_REG_READ64(handle, RXMISC_DISCARD_REG, rdc, &cnt.value);
10043859Sml29623 if (cnt.bits.ldw.oflow) {
10053859Sml29623 NPI_DEBUG_MSG((handle.function, NPI_RDC_CTL,
10066929Smisaki " npi_rxdma_misc_discard_oflow_clear"
10076929Smisaki " Counter overflow for channel %d ",
10086929Smisaki " ..... clearing \n",
10096929Smisaki rdc));
10103859Sml29623 cnt.bits.ldw.oflow = 0;
10113859Sml29623 RXDMA_REG_WRITE64(handle, RXMISC_DISCARD_REG, rdc, cnt.value);
10123859Sml29623 }
10133859Sml29623
10143859Sml29623 return (NPI_SUCCESS);
10153859Sml29623 }
10163859Sml29623
10173859Sml29623 /*
10183859Sml29623 * npi_rxdma_ring_perr_stat_get
10193859Sml29623 * Gets the current RDC Memory parity error
10203859Sml29623 * The counter overflow bit is cleared, if it has been set.
10213859Sml29623 *
10223859Sml29623 * Inputs:
10233859Sml29623 * handle: opaque handle interpreted by the underlying OS
10243859Sml29623 * pre_log: Structure to write current RDC Prefetch memory
10253859Sml29623 * Parity Error stat
10263859Sml29623 * sha_log: Structure to write current RDC Shadow memory
10273859Sml29623 * Parity Error stat
10283859Sml29623 *
10293859Sml29623 * Return:
10303859Sml29623 * NPI_SUCCESS
10313859Sml29623 *
10323859Sml29623 */
10333859Sml29623 npi_status_t
npi_rxdma_ring_perr_stat_get(npi_handle_t handle,rdmc_par_err_log_t * pre_log,rdmc_par_err_log_t * sha_log)10343859Sml29623 npi_rxdma_ring_perr_stat_get(npi_handle_t handle,
10353859Sml29623 rdmc_par_err_log_t *pre_log,
10363859Sml29623 rdmc_par_err_log_t *sha_log)
10373859Sml29623 {
10383859Sml29623 uint64_t pre_offset, sha_offset;
10393859Sml29623 rdmc_par_err_log_t clr;
10403859Sml29623 int clr_bits = 0;
10413859Sml29623
10423859Sml29623 pre_offset = RDMC_PRE_PAR_ERR_REG;
10433859Sml29623 sha_offset = RDMC_SHA_PAR_ERR_REG;
10443859Sml29623 NXGE_REG_RD64(handle, pre_offset, &pre_log->value);
10453859Sml29623 NXGE_REG_RD64(handle, sha_offset, &sha_log->value);
10463859Sml29623
10473859Sml29623 clr.value = pre_log->value;
10483859Sml29623 if (pre_log->bits.ldw.err) {
10493859Sml29623 NPI_DEBUG_MSG((handle.function, NPI_RDC_CTL,
10506929Smisaki " npi_rxdma_ring_perr_stat_get"
10516929Smisaki " PRE ERR Bit set ..... clearing \n"));
10523859Sml29623 clr.bits.ldw.err = 0;
10533859Sml29623 clr_bits++;
10543859Sml29623 }
10553859Sml29623
10563859Sml29623 if (pre_log->bits.ldw.merr) {
10573859Sml29623 NPI_DEBUG_MSG((handle.function, NPI_RDC_CTL,
10586929Smisaki " npi_rxdma_ring_perr_stat_get"
10596929Smisaki " PRE MERR Bit set ..... clearing \n"));
10603859Sml29623 clr.bits.ldw.merr = 0;
10613859Sml29623 clr_bits++;
10623859Sml29623 }
10633859Sml29623
10643859Sml29623 if (clr_bits) {
10653859Sml29623 NXGE_REG_WR64(handle, pre_offset, clr.value);
10663859Sml29623 }
10673859Sml29623
10683859Sml29623 clr_bits = 0;
10693859Sml29623 clr.value = sha_log->value;
10703859Sml29623 if (sha_log->bits.ldw.err) {
10713859Sml29623 NPI_DEBUG_MSG((handle.function, NPI_RDC_CTL,
10726929Smisaki " npi_rxdma_ring_perr_stat_get"
10736929Smisaki " SHA ERR Bit set ..... clearing \n"));
10743859Sml29623 clr.bits.ldw.err = 0;
10753859Sml29623 clr_bits++;
10763859Sml29623 }
10773859Sml29623
10783859Sml29623 if (sha_log->bits.ldw.merr) {
10793859Sml29623 NPI_DEBUG_MSG((handle.function, NPI_RDC_CTL,
10806929Smisaki " npi_rxdma_ring_perr_stat_get"
10816929Smisaki " SHA MERR Bit set ..... clearing \n"));
10823859Sml29623 clr.bits.ldw.merr = 0;
10833859Sml29623 clr_bits++;
10843859Sml29623 }
10853859Sml29623
10863859Sml29623 if (clr_bits) {
10873859Sml29623 NXGE_REG_WR64(handle, sha_offset, clr.value);
10883859Sml29623 }
10893859Sml29623
10903859Sml29623 return (NPI_SUCCESS);
10913859Sml29623 }
10923859Sml29623
10933859Sml29623 /*
10943859Sml29623 * npi_rxdma_ring_perr_stat_clear
10953859Sml29623 * Clear RDC Memory Parity Error counter overflow bits
10963859Sml29623 *
10973859Sml29623 * Inputs:
10983859Sml29623 * handle: opaque handle interpreted by the underlying OS
10993859Sml29623 * Return:
11003859Sml29623 * NPI_SUCCESS
11013859Sml29623 *
11023859Sml29623 */
11033859Sml29623 npi_status_t
npi_rxdma_ring_perr_stat_clear(npi_handle_t handle)11043859Sml29623 npi_rxdma_ring_perr_stat_clear(npi_handle_t handle)
11053859Sml29623 {
11063859Sml29623 uint64_t pre_offset, sha_offset;
11073859Sml29623 rdmc_par_err_log_t clr;
11083859Sml29623 int clr_bits = 0;
11093859Sml29623 pre_offset = RDMC_PRE_PAR_ERR_REG;
11103859Sml29623 sha_offset = RDMC_SHA_PAR_ERR_REG;
11113859Sml29623
11123859Sml29623 NXGE_REG_RD64(handle, pre_offset, &clr.value);
11133859Sml29623
11143859Sml29623 if (clr.bits.ldw.err) {
11153859Sml29623 NPI_DEBUG_MSG((handle.function, NPI_RDC_CTL,
11166929Smisaki " npi_rxdma_ring_perr_stat_get"
11176929Smisaki " PRE ERR Bit set ..... clearing \n"));
11183859Sml29623 clr.bits.ldw.err = 0;
11193859Sml29623 clr_bits++;
11203859Sml29623 }
11213859Sml29623
11223859Sml29623 if (clr.bits.ldw.merr) {
11233859Sml29623 NPI_DEBUG_MSG((handle.function, NPI_RDC_CTL,
11246929Smisaki " npi_rxdma_ring_perr_stat_get"
11256929Smisaki " PRE MERR Bit set ..... clearing \n"));
11263859Sml29623 clr.bits.ldw.merr = 0;
11273859Sml29623 clr_bits++;
11283859Sml29623 }
11293859Sml29623
11303859Sml29623 if (clr_bits) {
11313859Sml29623 NXGE_REG_WR64(handle, pre_offset, clr.value);
11323859Sml29623 }
11333859Sml29623
11343859Sml29623 clr_bits = 0;
11353859Sml29623 NXGE_REG_RD64(handle, sha_offset, &clr.value);
11363859Sml29623 if (clr.bits.ldw.err) {
11373859Sml29623 NPI_DEBUG_MSG((handle.function, NPI_RDC_CTL,
11386929Smisaki " npi_rxdma_ring_perr_stat_get"
11396929Smisaki " SHA ERR Bit set ..... clearing \n"));
11403859Sml29623 clr.bits.ldw.err = 0;
11413859Sml29623 clr_bits++;
11423859Sml29623 }
11433859Sml29623
11443859Sml29623 if (clr.bits.ldw.merr) {
11453859Sml29623 NPI_DEBUG_MSG((handle.function, NPI_RDC_CTL,
11466929Smisaki " npi_rxdma_ring_perr_stat_get"
11476929Smisaki " SHA MERR Bit set ..... clearing \n"));
11483859Sml29623 clr.bits.ldw.merr = 0;
11493859Sml29623 clr_bits++;
11503859Sml29623 }
11513859Sml29623
11523859Sml29623 if (clr_bits) {
11533859Sml29623 NXGE_REG_WR64(handle, sha_offset, clr.value);
11543859Sml29623 }
11553859Sml29623
11563859Sml29623 return (NPI_SUCCESS);
11573859Sml29623 }
11583859Sml29623
11593859Sml29623 /*
11603859Sml29623 * Access the RDMC Memory: used for debugging
11613859Sml29623 */
11623859Sml29623 npi_status_t
npi_rxdma_rdmc_memory_io(npi_handle_t handle,rdmc_mem_access_t * data,uint8_t op)11633859Sml29623 npi_rxdma_rdmc_memory_io(npi_handle_t handle,
11643859Sml29623 rdmc_mem_access_t *data, uint8_t op)
11653859Sml29623 {
11663859Sml29623 uint64_t d0_offset, d1_offset, d2_offset, d3_offset, d4_offset;
11673859Sml29623 uint64_t addr_offset;
11683859Sml29623 rdmc_mem_addr_t addr;
11693859Sml29623 rdmc_mem_data_t d0, d1, d2, d3, d4;
11703859Sml29623 d0.value = 0;
11713859Sml29623 d1.value = 0;
11723859Sml29623 d2.value = 0;
11733859Sml29623 d3.value = 0;
11743859Sml29623 d4.value = 0;
11753859Sml29623 addr.value = 0;
11763859Sml29623
11773859Sml29623
11783859Sml29623 if ((data->location != RDMC_MEM_ADDR_PREFETCH) &&
11796929Smisaki (data->location != RDMC_MEM_ADDR_SHADOW)) {
11803859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
11816929Smisaki " npi_rxdma_rdmc_memory_io"
11826929Smisaki " Illegal memory Type %x \n",
11836929Smisaki data->location));
11843859Sml29623 return (NPI_RXDMA_OPCODE_INVALID(0));
11853859Sml29623 }
11863859Sml29623
11873859Sml29623 addr_offset = RDMC_MEM_ADDR_REG;
11883859Sml29623 addr.bits.ldw.addr = data->addr;
11893859Sml29623 addr.bits.ldw.pre_shad = data->location;
11903859Sml29623
11913859Sml29623 d0_offset = RDMC_MEM_DATA0_REG;
11923859Sml29623 d1_offset = RDMC_MEM_DATA1_REG;
11933859Sml29623 d2_offset = RDMC_MEM_DATA2_REG;
11943859Sml29623 d3_offset = RDMC_MEM_DATA3_REG;
11953859Sml29623 d4_offset = RDMC_MEM_DATA4_REG;
11963859Sml29623
11973859Sml29623
11983859Sml29623 if (op == RDMC_MEM_WRITE) {
11993859Sml29623 d0.bits.ldw.data = data->data[0];
12003859Sml29623 d1.bits.ldw.data = data->data[1];
12013859Sml29623 d2.bits.ldw.data = data->data[2];
12023859Sml29623 d3.bits.ldw.data = data->data[3];
12033859Sml29623 d4.bits.ldw.data = data->data[4];
12043859Sml29623 NXGE_REG_WR64(handle, addr_offset, addr.value);
12053859Sml29623 NXGE_REG_WR64(handle, d0_offset, d0.value);
12063859Sml29623 NXGE_REG_WR64(handle, d1_offset, d1.value);
12073859Sml29623 NXGE_REG_WR64(handle, d2_offset, d2.value);
12083859Sml29623 NXGE_REG_WR64(handle, d3_offset, d3.value);
12093859Sml29623 NXGE_REG_WR64(handle, d4_offset, d4.value);
12103859Sml29623 }
12113859Sml29623
12123859Sml29623 if (op == RDMC_MEM_READ) {
12133859Sml29623 NXGE_REG_WR64(handle, addr_offset, addr.value);
12143859Sml29623 NXGE_REG_RD64(handle, d4_offset, &d4.value);
12153859Sml29623 NXGE_REG_RD64(handle, d3_offset, &d3.value);
12163859Sml29623 NXGE_REG_RD64(handle, d2_offset, &d2.value);
12173859Sml29623 NXGE_REG_RD64(handle, d1_offset, &d1.value);
12183859Sml29623 NXGE_REG_RD64(handle, d0_offset, &d0.value);
12193859Sml29623
12203859Sml29623 data->data[0] = d0.bits.ldw.data;
12213859Sml29623 data->data[1] = d1.bits.ldw.data;
12223859Sml29623 data->data[2] = d2.bits.ldw.data;
12233859Sml29623 data->data[3] = d3.bits.ldw.data;
12243859Sml29623 data->data[4] = d4.bits.ldw.data;
12253859Sml29623 } else {
12263859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
12276929Smisaki " npi_rxdma_rdmc_memory_io"
12286929Smisaki " Illegal opcode %x \n",
12296929Smisaki op));
12303859Sml29623 return (NPI_RXDMA_OPCODE_INVALID(0));
12313859Sml29623
12323859Sml29623 }
12333859Sml29623
12343859Sml29623 return (NPI_SUCCESS);
12353859Sml29623 }
12363859Sml29623
12373859Sml29623 /*
12383859Sml29623 * system wide conf functions
12393859Sml29623 */
12403859Sml29623 npi_status_t
npi_rxdma_cfg_clock_div_set(npi_handle_t handle,uint16_t count)12413859Sml29623 npi_rxdma_cfg_clock_div_set(npi_handle_t handle, uint16_t count)
12423859Sml29623 {
12433859Sml29623 uint64_t offset;
12443859Sml29623 rx_dma_ck_div_t clk_div;
12453859Sml29623
12463859Sml29623 offset = RX_DMA_CK_DIV_REG;
12473859Sml29623
12483859Sml29623 clk_div.value = 0;
12493859Sml29623 clk_div.bits.ldw.cnt = count;
12503859Sml29623 NPI_DEBUG_MSG((handle.function, NPI_RDC_CTL,
12516929Smisaki " npi_rxdma_cfg_clock_div_set: add 0x%llx "
12526929Smisaki "handle 0x%llx value 0x%llx",
12536929Smisaki handle.regp, handle.regh, clk_div.value));
12543859Sml29623
12553859Sml29623 NXGE_REG_WR64(handle, offset, clk_div.value);
12563859Sml29623
12573859Sml29623 return (NPI_SUCCESS);
12583859Sml29623 }
12593859Sml29623
12603859Sml29623 npi_status_t
npi_rxdma_cfg_red_rand_init(npi_handle_t handle,uint16_t init_value)12613859Sml29623 npi_rxdma_cfg_red_rand_init(npi_handle_t handle, uint16_t init_value)
12623859Sml29623 {
12633859Sml29623 uint64_t offset;
12643859Sml29623 red_ran_init_t rand_reg;
12653859Sml29623
12663859Sml29623 offset = RED_RAN_INIT_REG;
12673859Sml29623
12683859Sml29623 rand_reg.value = 0;
12693859Sml29623 rand_reg.bits.ldw.init = init_value;
12703859Sml29623 rand_reg.bits.ldw.enable = 1;
12713859Sml29623 NXGE_REG_WR64(handle, offset, rand_reg.value);
12723859Sml29623
12733859Sml29623 return (NPI_SUCCESS);
12743859Sml29623
12753859Sml29623 }
12763859Sml29623
12773859Sml29623 npi_status_t
npi_rxdma_cfg_red_rand_disable(npi_handle_t handle)12783859Sml29623 npi_rxdma_cfg_red_rand_disable(npi_handle_t handle)
12793859Sml29623 {
12803859Sml29623 uint64_t offset;
12813859Sml29623 red_ran_init_t rand_reg;
12823859Sml29623
12833859Sml29623 offset = RED_RAN_INIT_REG;
12843859Sml29623
12853859Sml29623 NXGE_REG_RD64(handle, offset, &rand_reg.value);
12863859Sml29623 rand_reg.bits.ldw.enable = 0;
12873859Sml29623 NXGE_REG_WR64(handle, offset, rand_reg.value);
12883859Sml29623
12893859Sml29623 return (NPI_SUCCESS);
12903859Sml29623
12913859Sml29623 }
12923859Sml29623
12933859Sml29623 npi_status_t
npi_rxdma_cfg_32bitmode_enable(npi_handle_t handle)12943859Sml29623 npi_rxdma_cfg_32bitmode_enable(npi_handle_t handle)
12953859Sml29623 {
12963859Sml29623 uint64_t offset;
12973859Sml29623 rx_addr_md_t md_reg;
12983859Sml29623 offset = RX_ADDR_MD_REG;
12993859Sml29623 md_reg.value = 0;
13003859Sml29623 md_reg.bits.ldw.mode32 = 1;
13013859Sml29623
13023859Sml29623 NXGE_REG_WR64(handle, offset, md_reg.value);
13033859Sml29623 return (NPI_SUCCESS);
13043859Sml29623
13053859Sml29623 }
13063859Sml29623
13073859Sml29623 npi_status_t
npi_rxdma_cfg_32bitmode_disable(npi_handle_t handle)13083859Sml29623 npi_rxdma_cfg_32bitmode_disable(npi_handle_t handle)
13093859Sml29623 {
13103859Sml29623 uint64_t offset;
13113859Sml29623 rx_addr_md_t md_reg;
13123859Sml29623 offset = RX_ADDR_MD_REG;
13133859Sml29623 md_reg.value = 0;
13143859Sml29623
13153859Sml29623 NXGE_REG_WR64(handle, offset, md_reg.value);
13163859Sml29623 return (NPI_SUCCESS);
13173859Sml29623
13183859Sml29623 }
13193859Sml29623
13203859Sml29623 npi_status_t
npi_rxdma_cfg_ram_access_enable(npi_handle_t handle)13213859Sml29623 npi_rxdma_cfg_ram_access_enable(npi_handle_t handle)
13223859Sml29623 {
13233859Sml29623 uint64_t offset;
13243859Sml29623 rx_addr_md_t md_reg;
13253859Sml29623 offset = RX_ADDR_MD_REG;
13263859Sml29623 NXGE_REG_RD64(handle, offset, &md_reg.value);
13273859Sml29623 md_reg.bits.ldw.ram_acc = 1;
13283859Sml29623 NXGE_REG_WR64(handle, offset, md_reg.value);
13293859Sml29623 return (NPI_SUCCESS);
13303859Sml29623
13313859Sml29623 }
13323859Sml29623
13333859Sml29623 npi_status_t
npi_rxdma_cfg_ram_access_disable(npi_handle_t handle)13343859Sml29623 npi_rxdma_cfg_ram_access_disable(npi_handle_t handle)
13353859Sml29623 {
13363859Sml29623 uint64_t offset;
13373859Sml29623 rx_addr_md_t md_reg;
13383859Sml29623 offset = RX_ADDR_MD_REG;
13393859Sml29623 NXGE_REG_RD64(handle, offset, &md_reg.value);
13403859Sml29623 md_reg.bits.ldw.ram_acc = 0;
13413859Sml29623 NXGE_REG_WR64(handle, offset, md_reg.value);
13423859Sml29623 return (NPI_SUCCESS);
13433859Sml29623
13443859Sml29623 }
13453859Sml29623
13463859Sml29623 npi_status_t
npi_rxdma_cfg_port_ddr_weight(npi_handle_t handle,uint8_t portnm,uint32_t weight)13473859Sml29623 npi_rxdma_cfg_port_ddr_weight(npi_handle_t handle,
13483859Sml29623 uint8_t portnm, uint32_t weight)
13493859Sml29623 {
13503859Sml29623
13513859Sml29623 pt_drr_wt_t wt_reg;
13523859Sml29623 uint64_t offset;
13533859Sml29623
13543859Sml29623 ASSERT(RXDMA_PORT_VALID(portnm));
13553859Sml29623 if (!RXDMA_PORT_VALID(portnm)) {
13563859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
13576929Smisaki " rxdma_cfg_port_ddr_weight"
13586929Smisaki " Illegal Port Number %d \n",
13596929Smisaki portnm));
13603859Sml29623 return (NPI_RXDMA_PORT_INVALID);
13613859Sml29623 }
13623859Sml29623
13633859Sml29623 offset = PT_DRR_WT_REG(portnm);
13643859Sml29623 wt_reg.value = 0;
13653859Sml29623 wt_reg.bits.ldw.wt = weight;
13663859Sml29623 NXGE_REG_WR64(handle, offset, wt_reg.value);
13673859Sml29623 return (NPI_SUCCESS);
13683859Sml29623 }
13693859Sml29623
13703859Sml29623 npi_status_t
npi_rxdma_port_usage_get(npi_handle_t handle,uint8_t portnm,uint32_t * blocks)13713859Sml29623 npi_rxdma_port_usage_get(npi_handle_t handle,
13723859Sml29623 uint8_t portnm, uint32_t *blocks)
13733859Sml29623 {
13743859Sml29623
13753859Sml29623 pt_use_t use_reg;
13763859Sml29623 uint64_t offset;
13773859Sml29623
13783859Sml29623 ASSERT(RXDMA_PORT_VALID(portnm));
13793859Sml29623 if (!RXDMA_PORT_VALID(portnm)) {
13803859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
13816929Smisaki " rxdma_port_usage_get"
13826929Smisaki " Illegal Port Number %d \n",
13836929Smisaki portnm));
13843859Sml29623 return (NPI_RXDMA_PORT_INVALID);
13853859Sml29623 }
13863859Sml29623
13873859Sml29623 offset = PT_USE_REG(portnm);
13883859Sml29623 NXGE_REG_RD64(handle, offset, &use_reg.value);
13893859Sml29623 *blocks = use_reg.bits.ldw.cnt;
13903859Sml29623 return (NPI_SUCCESS);
13913859Sml29623
13923859Sml29623 }
13933859Sml29623
13943859Sml29623 npi_status_t
npi_rxdma_cfg_wred_param(npi_handle_t handle,uint8_t rdc,rdc_red_para_t * wred_params)13953859Sml29623 npi_rxdma_cfg_wred_param(npi_handle_t handle, uint8_t rdc,
13963859Sml29623 rdc_red_para_t *wred_params)
13973859Sml29623 {
13983859Sml29623 rdc_red_para_t wred_reg;
13993859Sml29623 uint64_t offset;
14003859Sml29623
14013859Sml29623 ASSERT(RXDMA_CHANNEL_VALID(rdc));
14023859Sml29623 if (!RXDMA_CHANNEL_VALID(rdc)) {
14033859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
14046929Smisaki " rxdma_cfg_wred_param"
14056929Smisaki " Illegal RDC Number %d \n",
14066929Smisaki rdc));
14073859Sml29623 return (NPI_RXDMA_RDC_INVALID);
14083859Sml29623 }
14093859Sml29623
14103859Sml29623 /*
14113859Sml29623 * need to update RDC_RED_PARA_REG as well as bit defs in
14123859Sml29623 * the hw header file
14133859Sml29623 */
14143859Sml29623 offset = RDC_RED_RDC_PARA_REG(rdc);
14153859Sml29623
14163859Sml29623 NPI_DEBUG_MSG((handle.function, NPI_RDC_CTL,
14176929Smisaki " npi_rxdma_cfg_wred_param: "
14186929Smisaki "set RED_PARA: passed value 0x%llx "
14196929Smisaki "win 0x%x thre 0x%x sync 0x%x thre_sync 0x%x",
14206929Smisaki wred_params->value,
14216929Smisaki wred_params->bits.ldw.win,
14226929Smisaki wred_params->bits.ldw.thre,
14236929Smisaki wred_params->bits.ldw.win_syn,
14246929Smisaki wred_params->bits.ldw.thre_sync));
14253859Sml29623
14263859Sml29623 wred_reg.value = 0;
14273859Sml29623 wred_reg.bits.ldw.win = wred_params->bits.ldw.win;
14283859Sml29623 wred_reg.bits.ldw.thre = wred_params->bits.ldw.thre;
14293859Sml29623 wred_reg.bits.ldw.win_syn = wred_params->bits.ldw.win_syn;
14303859Sml29623 wred_reg.bits.ldw.thre_sync = wred_params->bits.ldw.thre_sync;
14313859Sml29623 NXGE_REG_WR64(handle, offset, wred_reg.value);
14323859Sml29623
14333859Sml29623 NPI_DEBUG_MSG((handle.function, NPI_RDC_CTL,
14346929Smisaki "set RED_PARA: value 0x%llx "
14356929Smisaki "win 0x%x thre 0x%x sync 0x%x thre_sync 0x%x",
14366929Smisaki wred_reg.value,
14376929Smisaki wred_reg.bits.ldw.win,
14386929Smisaki wred_reg.bits.ldw.thre,
14396929Smisaki wred_reg.bits.ldw.win_syn,
14406929Smisaki wred_reg.bits.ldw.thre_sync));
14413859Sml29623
14423859Sml29623 return (NPI_SUCCESS);
14433859Sml29623 }
14443859Sml29623
14453859Sml29623 /*
14466495Sspeer * npi_rxdma_rdc_table_config()
14473859Sml29623 * Configure/populate the RDC table
14483859Sml29623 *
14493859Sml29623 * Inputs:
14506495Sspeer * handle: register handle interpreted by the underlying OS
14516495Sspeer * table: RDC Group Number
14526495Sspeer * map: A bitmap of the RDCs to populate with.
14536495Sspeer * count: A count of the RDCs expressed in <map>.
14546495Sspeer *
14556495Sspeer * Notes:
14566495Sspeer * This function assumes that we are not using the TCAM, but are
14576495Sspeer * hashing all fields of the incoming ethernet packet!
14583859Sml29623 *
14593859Sml29623 * Return:
14606495Sspeer * NPI_SUCCESS
14616495Sspeer * NPI_RXDMA_TABLE_INVALID
14623859Sml29623 *
14633859Sml29623 */
14643859Sml29623 npi_status_t
npi_rxdma_rdc_table_config(npi_handle_t handle,uint8_t table,dc_map_t rdc_map,int count)14656495Sspeer npi_rxdma_rdc_table_config(
14666495Sspeer npi_handle_t handle,
14676495Sspeer uint8_t table,
14686495Sspeer dc_map_t rdc_map,
14696495Sspeer int count)
14703859Sml29623 {
14716495Sspeer int8_t set[NXGE_MAX_RDCS];
14726495Sspeer int i, cursor;
14736495Sspeer
14746495Sspeer rdc_tbl_t rdc_tbl;
14753859Sml29623 uint64_t offset;
14763859Sml29623
14773859Sml29623 ASSERT(RXDMA_TABLE_VALID(table));
14783859Sml29623 if (!RXDMA_TABLE_VALID(table)) {
14793859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
14806929Smisaki " npi_rxdma_cfg_rdc_table"
14816929Smisaki " Illegal RDC Table Number %d \n",
14826929Smisaki table));
14833859Sml29623 return (NPI_RXDMA_TABLE_INVALID);
14843859Sml29623 }
14853859Sml29623
14866495Sspeer if (count == 0) /* This shouldn't happen */
14876495Sspeer return (NPI_SUCCESS);
14886495Sspeer
14896495Sspeer for (i = 0, cursor = 0; i < NXGE_MAX_RDCS; i++) {
14906495Sspeer if ((1 << i) & rdc_map) {
14916495Sspeer set[cursor++] = (int8_t)i;
14926495Sspeer if (cursor == count)
14936495Sspeer break;
14946495Sspeer }
14953859Sml29623 }
14963859Sml29623
14976495Sspeer rdc_tbl.value = 0;
14986495Sspeer offset = REG_RDC_TABLE_OFFSET(table);
14996495Sspeer
15006495Sspeer /* Now write ( NXGE_MAX_RDCS / count ) sets of RDC numbers. */
15016495Sspeer for (i = 0, cursor = 0; i < NXGE_MAX_RDCS; i++) {
15026495Sspeer rdc_tbl.bits.ldw.rdc = set[cursor++];
15036495Sspeer NXGE_REG_WR64(handle, offset, rdc_tbl.value);
15046495Sspeer offset += sizeof (rdc_tbl.value);
15056495Sspeer if (cursor == count)
15066495Sspeer cursor = 0;
15076495Sspeer }
15086495Sspeer
15096495Sspeer /*
15106495Sspeer * Here is what the resulting table looks like with:
15116495Sspeer *
15126495Sspeer * 0 1 2 3 4 5 6 7 8 9 a b c d e f
15136495Sspeer * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
15146495Sspeer * |v |w |x |y |z |v |w |x |y |z |v |w |x |y |z |v | 5 RDCs
15156495Sspeer * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
15166495Sspeer * |w |x |y |z |w |x |y |z |w |x |y |z |w |x |y |z | 4 RDCs
15176495Sspeer * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
15186495Sspeer * |x |y |z |x |y |z |x |y |z |x |y |z |x |y |z |x | 3 RDCs
15196495Sspeer * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
15206495Sspeer * |x |y |x |y |x |y |x |y |x |y |x |y |x |y |x |y | 2 RDCs
15216495Sspeer * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
15226495Sspeer * |x |x |x |x |x |x |x |x |x |x |x |x |x |x |x |x | 1 RDC
15236495Sspeer * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
15246495Sspeer */
15256495Sspeer
15263859Sml29623 return (NPI_SUCCESS);
15273859Sml29623 }
15283859Sml29623
15293859Sml29623 npi_status_t
npi_rxdma_cfg_rdc_table_default_rdc(npi_handle_t handle,uint8_t table,uint8_t rdc)15303859Sml29623 npi_rxdma_cfg_rdc_table_default_rdc(npi_handle_t handle,
15313859Sml29623 uint8_t table, uint8_t rdc)
15323859Sml29623 {
15333859Sml29623 uint64_t offset;
15343859Sml29623 rdc_tbl_t tbl_reg;
15353859Sml29623 tbl_reg.value = 0;
15363859Sml29623
15373859Sml29623 ASSERT(RXDMA_TABLE_VALID(table));
15383859Sml29623 if (!RXDMA_TABLE_VALID(table)) {
15393859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
15406929Smisaki " npi_rxdma_cfg_rdc_table"
15416929Smisaki " Illegal RDC table Number %d \n",
15426929Smisaki rdc));
15433859Sml29623 return (NPI_RXDMA_TABLE_INVALID);
15443859Sml29623 }
15453859Sml29623
15463859Sml29623 offset = REG_RDC_TABLE_OFFSET(table);
15473859Sml29623 tbl_reg.bits.ldw.rdc = rdc;
15483859Sml29623 NXGE_REG_WR64(handle, offset, tbl_reg.value);
15493859Sml29623 return (NPI_SUCCESS);
15503859Sml29623
15513859Sml29623 }
15523859Sml29623
15533859Sml29623 npi_status_t
npi_rxdma_dump_rdc_table(npi_handle_t handle,uint8_t table)15543859Sml29623 npi_rxdma_dump_rdc_table(npi_handle_t handle,
15553859Sml29623 uint8_t table)
15563859Sml29623 {
15573859Sml29623 uint64_t offset;
15583859Sml29623 int tbl_offset;
15593859Sml29623 uint64_t value;
15603859Sml29623
15613859Sml29623 ASSERT(RXDMA_TABLE_VALID(table));
15623859Sml29623 if (!RXDMA_TABLE_VALID(table)) {
15633859Sml29623 NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
15646929Smisaki " npi_rxdma_dump_rdc_table"
15656929Smisaki " Illegal RDC Rable Number %d \n",
15666929Smisaki table));
15673859Sml29623 return (NPI_RXDMA_TABLE_INVALID);
15683859Sml29623 }
15693859Sml29623 NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
15706929Smisaki "\n Register Dump for RDC Table %d \n",
15716929Smisaki table));
15723859Sml29623 offset = REG_RDC_TABLE_OFFSET(table);
15733859Sml29623 for (tbl_offset = 0; tbl_offset < NXGE_MAX_RDCS; tbl_offset++) {
15743859Sml29623 NXGE_REG_RD64(handle, offset, &value);
15753859Sml29623 NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
15766929Smisaki " 0x%08llx 0x%08llx \n",
15776929Smisaki offset, value));
15783859Sml29623 offset += 8;
15793859Sml29623 }
15803859Sml29623 NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
15816929Smisaki "\n Register Dump for RDC Table %d done\n",
15826929Smisaki table));
15833859Sml29623 return (NPI_SUCCESS);
15843859Sml29623
15853859Sml29623 }
15863859Sml29623
15873859Sml29623 npi_status_t
npi_rxdma_rdc_rbr_stat_get(npi_handle_t handle,uint8_t rdc,rbr_stat_t * rbr_stat)15883859Sml29623 npi_rxdma_rdc_rbr_stat_get(npi_handle_t handle, uint8_t rdc,
15893859Sml29623 rbr_stat_t *rbr_stat)
15903859Sml29623 {
15913859Sml29623
15923859Sml29623 ASSERT(RXDMA_CHANNEL_VALID(rdc));
15933859Sml29623 if (!RXDMA_CHANNEL_VALID(rdc)) {
15943859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
15956929Smisaki " rxdma_rdc_rbr_stat_get"
15966929Smisaki " Illegal RDC Number %d \n",
15976929Smisaki rdc));
15983859Sml29623 return (NPI_RXDMA_RDC_INVALID);
15993859Sml29623 }
16003859Sml29623
16013859Sml29623 RXDMA_REG_READ64(handle, RBR_STAT_REG, rdc, &rbr_stat->value);
16023859Sml29623 return (NPI_SUCCESS);
16033859Sml29623 }
16043859Sml29623
16053859Sml29623 /*
16063859Sml29623 * npi_rxdma_rdc_rbr_head_get
16073859Sml29623 * Gets the current rbr head pointer.
16083859Sml29623 *
16093859Sml29623 * Inputs:
16103859Sml29623 * handle: opaque handle interpreted by the underlying OS
16113859Sml29623 * rdc: RX DMA Channel number
16123859Sml29623 * hdptr ptr to write the rbr head value
16133859Sml29623 *
16143859Sml29623 * Return:
16153859Sml29623 * NPI_SUCCESS
16163859Sml29623 * NPI_RXDMA_RDC_INVALID
16173859Sml29623 */
16183859Sml29623 npi_status_t
npi_rxdma_rdc_rbr_head_get(npi_handle_t handle,uint8_t rdc,addr44_t * hdptr)16193859Sml29623 npi_rxdma_rdc_rbr_head_get(npi_handle_t handle,
16203859Sml29623 uint8_t rdc, addr44_t *hdptr)
16213859Sml29623 {
16223859Sml29623 rbr_hdh_t hh_ptr;
16233859Sml29623 rbr_hdl_t hl_ptr;
16243859Sml29623
16253859Sml29623 ASSERT(RXDMA_CHANNEL_VALID(rdc));
16263859Sml29623 if (!RXDMA_CHANNEL_VALID(rdc)) {
16273859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
16286929Smisaki " rxdma_rdc_rbr_head_get"
16296929Smisaki " Illegal RDC Number %d \n",
16306929Smisaki rdc));
16313859Sml29623 return (NPI_RXDMA_RDC_INVALID);
16323859Sml29623 }
16333859Sml29623 hh_ptr.value = 0;
16343859Sml29623 hl_ptr.value = 0;
16353859Sml29623 RXDMA_REG_READ64(handle, RBR_HDH_REG, rdc, &hh_ptr.value);
16363859Sml29623 RXDMA_REG_READ64(handle, RBR_HDL_REG, rdc, &hl_ptr.value);
16373859Sml29623 hdptr->bits.ldw = hl_ptr.bits.ldw.head_l << 2;
16383859Sml29623 hdptr->bits.hdw = hh_ptr.bits.ldw.head_h;
16393859Sml29623 return (NPI_SUCCESS);
16403859Sml29623
16413859Sml29623 }
16423859Sml29623
16433859Sml29623 npi_status_t
npi_rxdma_rdc_rcr_qlen_get(npi_handle_t handle,uint8_t rdc,uint16_t * rcr_qlen)16443859Sml29623 npi_rxdma_rdc_rcr_qlen_get(npi_handle_t handle, uint8_t rdc,
16453859Sml29623 uint16_t *rcr_qlen)
16463859Sml29623 {
16473859Sml29623
16483859Sml29623 rcrstat_a_t stats;
16493859Sml29623
16503859Sml29623 ASSERT(RXDMA_CHANNEL_VALID(rdc));
16513859Sml29623 if (!RXDMA_CHANNEL_VALID(rdc)) {
16523859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
16536929Smisaki " rxdma_rdc_rcr_qlen_get"
16546929Smisaki " Illegal RDC Number %d \n",
16556929Smisaki rdc));
16563859Sml29623 return (NPI_RXDMA_RDC_INVALID);
16573859Sml29623 }
16583859Sml29623
16593859Sml29623 RXDMA_REG_READ64(handle, RCRSTAT_A_REG, rdc, &stats.value);
16603859Sml29623 *rcr_qlen = stats.bits.ldw.qlen;
16613859Sml29623 NPI_DEBUG_MSG((handle.function, NPI_RDC_CTL,
16626929Smisaki " rxdma_rdc_rcr_qlen_get"
16636929Smisaki " RDC %d qlen %x qlen %x\n",
16646929Smisaki rdc, *rcr_qlen, stats.bits.ldw.qlen));
16653859Sml29623 return (NPI_SUCCESS);
16663859Sml29623 }
16673859Sml29623
16683859Sml29623 npi_status_t
npi_rxdma_rdc_rcr_tail_get(npi_handle_t handle,uint8_t rdc,addr44_t * tail_addr)16693859Sml29623 npi_rxdma_rdc_rcr_tail_get(npi_handle_t handle,
16703859Sml29623 uint8_t rdc, addr44_t *tail_addr)
16713859Sml29623 {
16723859Sml29623
16733859Sml29623 rcrstat_b_t th_ptr;
16743859Sml29623 rcrstat_c_t tl_ptr;
16753859Sml29623
16763859Sml29623 ASSERT(RXDMA_CHANNEL_VALID(rdc));
16773859Sml29623 if (!RXDMA_CHANNEL_VALID(rdc)) {
16783859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
16796929Smisaki " rxdma_rdc_rcr_tail_get"
16806929Smisaki " Illegal RDC Number %d \n",
16816929Smisaki rdc));
16823859Sml29623 return (NPI_RXDMA_RDC_INVALID);
16833859Sml29623 }
16843859Sml29623 th_ptr.value = 0;
16853859Sml29623 tl_ptr.value = 0;
16863859Sml29623 RXDMA_REG_READ64(handle, RCRSTAT_B_REG, rdc, &th_ptr.value);
16873859Sml29623 RXDMA_REG_READ64(handle, RCRSTAT_C_REG, rdc, &tl_ptr.value);
16883859Sml29623 tail_addr->bits.ldw = tl_ptr.bits.ldw.tlptr_l << 3;
16893859Sml29623 tail_addr->bits.hdw = th_ptr.bits.ldw.tlptr_h;
16903859Sml29623 NPI_DEBUG_MSG((handle.function, NPI_RDC_CTL,
16916929Smisaki " rxdma_rdc_rcr_tail_get"
16926929Smisaki " RDC %d rcr_tail %llx tl %x\n",
16936929Smisaki rdc, tl_ptr.value,
16946929Smisaki tl_ptr.bits.ldw.tlptr_l));
16953859Sml29623
16963859Sml29623 return (NPI_SUCCESS);
16973859Sml29623
16983859Sml29623
16993859Sml29623 }
17003859Sml29623
17013859Sml29623 /*
17023859Sml29623 * npi_rxdma_rxctl_fifo_error_intr_set
17033859Sml29623 * Configure The RX ctrl fifo error interrupt generation
17043859Sml29623 *
17053859Sml29623 * Inputs:
17063859Sml29623 * handle: opaque handle interpreted by the underlying OS
17073859Sml29623 * mask: rx_ctl_dat_fifo_mask_t specifying the errors
17083859Sml29623 * valid fields in rx_ctl_dat_fifo_mask_t structure are:
17093859Sml29623 * zcp_eop_err, ipp_eop_err, id_mismatch. If a field is set
17103859Sml29623 * to 1, we will enable interrupt generation for the
17113859Sml29623 * corresponding error condition. In the hardware, the bit(s)
17123859Sml29623 * have to be cleared to enable interrupt.
17133859Sml29623 *
17143859Sml29623 * Return:
17153859Sml29623 * NPI_SUCCESS
17163859Sml29623 *
17173859Sml29623 */
17183859Sml29623 npi_status_t
npi_rxdma_rxctl_fifo_error_intr_set(npi_handle_t handle,rx_ctl_dat_fifo_mask_t * mask)17193859Sml29623 npi_rxdma_rxctl_fifo_error_intr_set(npi_handle_t handle,
17203859Sml29623 rx_ctl_dat_fifo_mask_t *mask)
17213859Sml29623 {
17223859Sml29623 uint64_t offset;
17233859Sml29623 rx_ctl_dat_fifo_mask_t intr_mask;
17243859Sml29623 offset = RX_CTL_DAT_FIFO_MASK_REG;
17253859Sml29623 NXGE_REG_RD64(handle, offset, &intr_mask.value);
17263859Sml29623
17273859Sml29623 if (mask->bits.ldw.ipp_eop_err) {
17283859Sml29623 intr_mask.bits.ldw.ipp_eop_err = 0;
17293859Sml29623 }
17303859Sml29623
17313859Sml29623 if (mask->bits.ldw.zcp_eop_err) {
17323859Sml29623 intr_mask.bits.ldw.zcp_eop_err = 0;
17333859Sml29623 }
17343859Sml29623
17353859Sml29623 if (mask->bits.ldw.id_mismatch) {
17363859Sml29623 intr_mask.bits.ldw.id_mismatch = 0;
17373859Sml29623 }
17383859Sml29623
17393859Sml29623 NXGE_REG_WR64(handle, offset, intr_mask.value);
17403859Sml29623 return (NPI_SUCCESS);
17413859Sml29623 }
17423859Sml29623
17433859Sml29623 /*
17443859Sml29623 * npi_rxdma_rxctl_fifo_error_stat_get
17453859Sml29623 * Read The RX ctrl fifo error Status
17463859Sml29623 *
17473859Sml29623 * Inputs:
17483859Sml29623 * handle: opaque handle interpreted by the underlying OS
17493859Sml29623 * stat: rx_ctl_dat_fifo_stat_t to read the errors to
17503859Sml29623 * valid fields in rx_ctl_dat_fifo_stat_t structure are:
17513859Sml29623 * zcp_eop_err, ipp_eop_err, id_mismatch.
17523859Sml29623 * Return:
17533859Sml29623 * NPI_SUCCESS
17543859Sml29623 *
17553859Sml29623 */
17563859Sml29623 npi_status_t
npi_rxdma_rxctl_fifo_error_intr_get(npi_handle_t handle,rx_ctl_dat_fifo_stat_t * stat)17573859Sml29623 npi_rxdma_rxctl_fifo_error_intr_get(npi_handle_t handle,
17583859Sml29623 rx_ctl_dat_fifo_stat_t *stat)
17593859Sml29623 {
17603859Sml29623 uint64_t offset = RX_CTL_DAT_FIFO_STAT_REG;
17613859Sml29623 NXGE_REG_RD64(handle, offset, &stat->value);
17623859Sml29623 return (NPI_SUCCESS);
17633859Sml29623 }
17643859Sml29623
17653859Sml29623 npi_status_t
npi_rxdma_rdc_rcr_pktread_update(npi_handle_t handle,uint8_t channel,uint16_t pkts_read)17663859Sml29623 npi_rxdma_rdc_rcr_pktread_update(npi_handle_t handle, uint8_t channel,
17673859Sml29623 uint16_t pkts_read)
17683859Sml29623 {
17693859Sml29623
17703859Sml29623 rx_dma_ctl_stat_t cs;
17713859Sml29623 uint16_t min_read = 0;
17723859Sml29623
17733859Sml29623 ASSERT(RXDMA_CHANNEL_VALID(channel));
17743859Sml29623 if (!RXDMA_CHANNEL_VALID(channel)) {
17753859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
17763859Sml29623 " npi_rxdma_rdc_rcr_pktread_update ",
17773859Sml29623 " channel %d", channel));
17783859Sml29623 return (NPI_FAILURE | NPI_RXDMA_CHANNEL_INVALID(channel));
17793859Sml29623 }
17803859Sml29623
17813859Sml29623 if ((pkts_read < min_read) && (pkts_read > 512)) {
17823859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
17833859Sml29623 " npi_rxdma_rdc_rcr_pktread_update ",
17843859Sml29623 " pkts %d out of bound", pkts_read));
17853859Sml29623 return (NPI_RXDMA_OPCODE_INVALID(pkts_read));
17863859Sml29623 }
17873859Sml29623
17883859Sml29623 RXDMA_REG_READ64(handle, RX_DMA_CTL_STAT_REG, channel,
17896929Smisaki &cs.value);
17903859Sml29623 cs.bits.ldw.pktread = pkts_read;
17913859Sml29623 RXDMA_REG_WRITE64(handle, RX_DMA_CTL_STAT_REG,
17926929Smisaki channel, cs.value);
17933859Sml29623
17943859Sml29623 return (NPI_SUCCESS);
17953859Sml29623 }
17963859Sml29623
17973859Sml29623 npi_status_t
npi_rxdma_rdc_rcr_bufread_update(npi_handle_t handle,uint8_t channel,uint16_t bufs_read)17983859Sml29623 npi_rxdma_rdc_rcr_bufread_update(npi_handle_t handle, uint8_t channel,
17993859Sml29623 uint16_t bufs_read)
18003859Sml29623 {
18013859Sml29623
18023859Sml29623 rx_dma_ctl_stat_t cs;
18033859Sml29623 uint16_t min_read = 0;
18043859Sml29623
18053859Sml29623 ASSERT(RXDMA_CHANNEL_VALID(channel));
18063859Sml29623 if (!RXDMA_CHANNEL_VALID(channel)) {
18073859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
18083859Sml29623 " npi_rxdma_rdc_rcr_bufread_update ",
18093859Sml29623 " channel %d", channel));
18103859Sml29623 return (NPI_FAILURE | NPI_RXDMA_CHANNEL_INVALID(channel));
18113859Sml29623 }
18123859Sml29623
18133859Sml29623 if ((bufs_read < min_read) && (bufs_read > 512)) {
18143859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
18153859Sml29623 " npi_rxdma_rdc_rcr_bufread_update ",
18163859Sml29623 " bufs read %d out of bound", bufs_read));
18173859Sml29623 return (NPI_RXDMA_OPCODE_INVALID(bufs_read));
18183859Sml29623 }
18193859Sml29623
18203859Sml29623 RXDMA_REG_READ64(handle, RX_DMA_CTL_STAT_REG, channel,
18216929Smisaki &cs.value);
18223859Sml29623 cs.bits.ldw.ptrread = bufs_read;
18233859Sml29623 RXDMA_REG_WRITE64(handle, RX_DMA_CTL_STAT_REG,
18246929Smisaki channel, cs.value);
18253859Sml29623
18263859Sml29623 return (NPI_SUCCESS);
18273859Sml29623 }
18283859Sml29623
18293859Sml29623 npi_status_t
npi_rxdma_rdc_rcr_read_update(npi_handle_t handle,uint8_t channel,uint16_t pkts_read,uint16_t bufs_read)18303859Sml29623 npi_rxdma_rdc_rcr_read_update(npi_handle_t handle, uint8_t channel,
18313859Sml29623 uint16_t pkts_read, uint16_t bufs_read)
18323859Sml29623 {
18333859Sml29623
18343859Sml29623 rx_dma_ctl_stat_t cs;
18353859Sml29623
18363859Sml29623 ASSERT(RXDMA_CHANNEL_VALID(channel));
18373859Sml29623 if (!RXDMA_CHANNEL_VALID(channel)) {
18383859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
18393859Sml29623 " npi_rxdma_rdc_rcr_read_update ",
18403859Sml29623 " channel %d", channel));
18413859Sml29623 return (NPI_FAILURE | NPI_RXDMA_CHANNEL_INVALID(channel));
18423859Sml29623 }
18433859Sml29623
18443859Sml29623 NPI_DEBUG_MSG((handle.function, NPI_RDC_CTL,
18453859Sml29623 " npi_rxdma_rdc_rcr_read_update "
18463859Sml29623 " bufs read %d pkt read %d",
18476929Smisaki bufs_read, pkts_read));
18483859Sml29623
18493859Sml29623 RXDMA_REG_READ64(handle, RX_DMA_CTL_STAT_REG, channel,
18506929Smisaki &cs.value);
18513859Sml29623
18523859Sml29623 NPI_DEBUG_MSG((handle.function, NPI_RDC_CTL,
18536929Smisaki " npi_rxdma_rdc_rcr_read_update: "
18546929Smisaki " value: 0x%llx bufs read %d pkt read %d",
18556929Smisaki cs.value,
18566929Smisaki cs.bits.ldw.ptrread, cs.bits.ldw.pktread));
18573859Sml29623
18583859Sml29623 cs.bits.ldw.pktread = pkts_read;
18593859Sml29623 cs.bits.ldw.ptrread = bufs_read;
18603859Sml29623
18613859Sml29623 RXDMA_REG_WRITE64(handle, RX_DMA_CTL_STAT_REG,
18626929Smisaki channel, cs.value);
18633859Sml29623
18643859Sml29623 RXDMA_REG_READ64(handle, RX_DMA_CTL_STAT_REG, channel,
18656929Smisaki &cs.value);
18663859Sml29623
18673859Sml29623 NPI_DEBUG_MSG((handle.function, NPI_RDC_CTL,
18683859Sml29623 " npi_rxdma_rdc_rcr_read_update: read back after update "
18693859Sml29623 " value: 0x%llx bufs read %d pkt read %d",
18706929Smisaki cs.value,
18716929Smisaki cs.bits.ldw.ptrread, cs.bits.ldw.pktread));
18723859Sml29623
18733859Sml29623 return (NPI_SUCCESS);
18743859Sml29623 }
18753859Sml29623
18763859Sml29623 /*
18773859Sml29623 * npi_rxdma_channel_mex_set():
18783859Sml29623 * This function is called to arm the DMA channel with
18793859Sml29623 * mailbox updating capability. Software needs to rearm
18803859Sml29623 * for each update by writing to the control and status register.
18813859Sml29623 *
18823859Sml29623 * Parameters:
18833859Sml29623 * handle - NPI handle (virtualization flag must be defined).
18843859Sml29623 * channel - logical RXDMA channel from 0 to 23.
18853859Sml29623 * (If virtualization flag is not set, then
18863859Sml29623 * logical channel is the same as the hardware
18873859Sml29623 * channel number).
18883859Sml29623 *
18893859Sml29623 * Return:
18903859Sml29623 * NPI_SUCCESS - If enable channel with mailbox update
18913859Sml29623 * is completed successfully.
18923859Sml29623 *
18933859Sml29623 * Error:
18943859Sml29623 * NPI error status code
18953859Sml29623 */
18963859Sml29623 npi_status_t
npi_rxdma_channel_mex_set(npi_handle_t handle,uint8_t channel)18973859Sml29623 npi_rxdma_channel_mex_set(npi_handle_t handle, uint8_t channel)
18983859Sml29623 {
18993859Sml29623 return (npi_rxdma_channel_control(handle, RXDMA_MEX_SET, channel));
19003859Sml29623 }
19013859Sml29623
19023859Sml29623 /*
19033859Sml29623 * npi_rxdma_channel_rcrto_clear():
19043859Sml29623 * This function is called to reset RCRTO bit to 0.
19053859Sml29623 *
19063859Sml29623 * Parameters:
19073859Sml29623 * handle - NPI handle (virtualization flag must be defined).
19083859Sml29623 * channel - logical RXDMA channel from 0 to 23.
19093859Sml29623 * (If virtualization flag is not set, then
19103859Sml29623 * logical channel is the same as the hardware
19113859Sml29623 * channel number).
19123859Sml29623 * Return:
19133859Sml29623 * NPI_SUCCESS
19143859Sml29623 *
19153859Sml29623 * Error:
19163859Sml29623 * NPI error status code
19173859Sml29623 */
19183859Sml29623 npi_status_t
npi_rxdma_channel_rcrto_clear(npi_handle_t handle,uint8_t channel)19193859Sml29623 npi_rxdma_channel_rcrto_clear(npi_handle_t handle, uint8_t channel)
19203859Sml29623 {
19213859Sml29623 return (npi_rxdma_channel_control(handle, RXDMA_RCRTO_CLEAR, channel));
19223859Sml29623 }
19233859Sml29623
19243859Sml29623 /*
19253859Sml29623 * npi_rxdma_channel_pt_drop_pkt_clear():
19263859Sml29623 * This function is called to clear the port drop packet bit (debug).
19273859Sml29623 *
19283859Sml29623 * Parameters:
19293859Sml29623 * handle - NPI handle (virtualization flag must be defined).
19303859Sml29623 * channel - logical RXDMA channel from 0 to 23.
19313859Sml29623 * (If virtualization flag is not set, then
19323859Sml29623 * logical channel is the same as the hardware
19333859Sml29623 * channel number).
19343859Sml29623 * Return:
19353859Sml29623 * NPI_SUCCESS
19363859Sml29623 *
19373859Sml29623 * Error:
19383859Sml29623 * NPI error status code
19393859Sml29623 */
19403859Sml29623 npi_status_t
npi_rxdma_channel_pt_drop_pkt_clear(npi_handle_t handle,uint8_t channel)19413859Sml29623 npi_rxdma_channel_pt_drop_pkt_clear(npi_handle_t handle, uint8_t channel)
19423859Sml29623 {
19433859Sml29623 return (npi_rxdma_channel_control(handle, RXDMA_PT_DROP_PKT_CLEAR,
19446929Smisaki channel));
19453859Sml29623 }
19463859Sml29623
19473859Sml29623 /*
19483859Sml29623 * npi_rxdma_channel_wred_drop_clear():
19493859Sml29623 * This function is called to wred drop bit (debug only).
19503859Sml29623 *
19513859Sml29623 * Parameters:
19523859Sml29623 * handle - NPI handle (virtualization flag must be defined).
19533859Sml29623 * channel - logical RXDMA channel from 0 to 23.
19543859Sml29623 * (If virtualization flag is not set, then
19553859Sml29623 * logical channel is the same as the hardware
19563859Sml29623 * channel number).
19573859Sml29623 * Return:
19583859Sml29623 * NPI_SUCCESS
19593859Sml29623 *
19603859Sml29623 * Error:
19613859Sml29623 * NPI error status code
19623859Sml29623 */
19633859Sml29623 npi_status_t
npi_rxdma_channel_wred_dop_clear(npi_handle_t handle,uint8_t channel)19643859Sml29623 npi_rxdma_channel_wred_dop_clear(npi_handle_t handle, uint8_t channel)
19653859Sml29623 {
19663859Sml29623 return (npi_rxdma_channel_control(handle, RXDMA_WRED_DROP_CLEAR,
19676929Smisaki channel));
19683859Sml29623 }
19693859Sml29623
19703859Sml29623 /*
19713859Sml29623 * npi_rxdma_channel_rcr_shfull_clear():
19723859Sml29623 * This function is called to clear RCR shadow full bit.
19733859Sml29623 *
19743859Sml29623 * Parameters:
19753859Sml29623 * handle - NPI handle (virtualization flag must be defined).
19763859Sml29623 * channel - logical RXDMA channel from 0 to 23.
19773859Sml29623 * (If virtualization flag is not set, then
19783859Sml29623 * logical channel is the same as the hardware
19793859Sml29623 * channel number).
19803859Sml29623 * Return:
19813859Sml29623 * NPI_SUCCESS
19823859Sml29623 *
19833859Sml29623 * Error:
19843859Sml29623 * NPI error status code
19853859Sml29623 */
19863859Sml29623 npi_status_t
npi_rxdma_channel_rcr_shfull_clear(npi_handle_t handle,uint8_t channel)19873859Sml29623 npi_rxdma_channel_rcr_shfull_clear(npi_handle_t handle, uint8_t channel)
19883859Sml29623 {
19893859Sml29623 return (npi_rxdma_channel_control(handle, RXDMA_RCR_SFULL_CLEAR,
19906929Smisaki channel));
19913859Sml29623 }
19923859Sml29623
19933859Sml29623 /*
19943859Sml29623 * npi_rxdma_channel_rcrfull_clear():
19953859Sml29623 * This function is called to clear RCR full bit.
19963859Sml29623 *
19973859Sml29623 * Parameters:
19983859Sml29623 * handle - NPI handle (virtualization flag must be defined).
19993859Sml29623 * channel - logical RXDMA channel from 0 to 23.
20003859Sml29623 * (If virtualization flag is not set, then
20013859Sml29623 * logical channel is the same as the hardware
20023859Sml29623 * channel number).
20033859Sml29623 * Return:
20043859Sml29623 * NPI_SUCCESS
20053859Sml29623 *
20063859Sml29623 * Error:
20073859Sml29623 * NPI error status code
20083859Sml29623 */
20093859Sml29623 npi_status_t
npi_rxdma_channel_rcr_full_clear(npi_handle_t handle,uint8_t channel)20103859Sml29623 npi_rxdma_channel_rcr_full_clear(npi_handle_t handle, uint8_t channel)
20113859Sml29623 {
20123859Sml29623 return (npi_rxdma_channel_control(handle, RXDMA_RCR_FULL_CLEAR,
20136929Smisaki channel));
20143859Sml29623 }
20153859Sml29623
20163859Sml29623 npi_status_t
npi_rxdma_channel_rbr_empty_clear(npi_handle_t handle,uint8_t channel)20173859Sml29623 npi_rxdma_channel_rbr_empty_clear(npi_handle_t handle, uint8_t channel)
20183859Sml29623 {
20193859Sml29623 return (npi_rxdma_channel_control(handle,
20206929Smisaki RXDMA_RBR_EMPTY_CLEAR, channel));
20213859Sml29623 }
20223859Sml29623
20233859Sml29623 npi_status_t
npi_rxdma_channel_cs_clear_all(npi_handle_t handle,uint8_t channel)20243859Sml29623 npi_rxdma_channel_cs_clear_all(npi_handle_t handle, uint8_t channel)
20253859Sml29623 {
20263859Sml29623 return (npi_rxdma_channel_control(handle, RXDMA_CS_CLEAR_ALL, channel));
20273859Sml29623 }
20283859Sml29623
20293859Sml29623 /*
20303859Sml29623 * npi_rxdma_channel_control():
20313859Sml29623 * This function is called to control a receive DMA channel
20323859Sml29623 * for arming the channel with mailbox updates, resetting
20333859Sml29623 * various event status bits (control and status register).
20343859Sml29623 *
20353859Sml29623 * Parameters:
20363859Sml29623 * handle - NPI handle (virtualization flag must be defined).
20373859Sml29623 * control - NPI defined control type supported:
20383859Sml29623 * - RXDMA_MEX_SET
20393859Sml29623 * - RXDMA_RCRTO_CLEAR
20403859Sml29623 * - RXDMA_PT_DROP_PKT_CLEAR
20413859Sml29623 * - RXDMA_WRED_DROP_CLEAR
20423859Sml29623 * - RXDMA_RCR_SFULL_CLEAR
20433859Sml29623 * - RXDMA_RCR_FULL_CLEAR
20443859Sml29623 * - RXDMA_RBR_PRE_EMPTY_CLEAR
20453859Sml29623 * - RXDMA_RBR_EMPTY_CLEAR
20463859Sml29623 * channel - logical RXDMA channel from 0 to 23.
20473859Sml29623 * (If virtualization flag is not set, then
20483859Sml29623 * logical channel is the same as the hardware.
20493859Sml29623 * Return:
20503859Sml29623 * NPI_SUCCESS
20513859Sml29623 *
20523859Sml29623 * Error:
20533859Sml29623 * NPI error status code
20543859Sml29623 */
20553859Sml29623 npi_status_t
npi_rxdma_channel_control(npi_handle_t handle,rxdma_cs_cntl_t control,uint8_t channel)20563859Sml29623 npi_rxdma_channel_control(npi_handle_t handle, rxdma_cs_cntl_t control,
20573859Sml29623 uint8_t channel)
20583859Sml29623 {
20593859Sml29623
20603859Sml29623 rx_dma_ctl_stat_t cs;
20613859Sml29623
20623859Sml29623 ASSERT(RXDMA_CHANNEL_VALID(channel));
20633859Sml29623 if (!RXDMA_CHANNEL_VALID(channel)) {
20643859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
20653859Sml29623 " npi_rxdma_channel_control",
20663859Sml29623 " channel", channel));
20673859Sml29623 return (NPI_FAILURE | NPI_RXDMA_CHANNEL_INVALID(channel));
20683859Sml29623 }
20693859Sml29623
20703859Sml29623 switch (control) {
20713859Sml29623 case RXDMA_MEX_SET:
20723859Sml29623 RXDMA_REG_READ64(handle, RX_DMA_CTL_STAT_REG, channel,
20736929Smisaki &cs.value);
20743859Sml29623 cs.bits.hdw.mex = 1;
20753859Sml29623 RXDMA_REG_WRITE64(handle, RX_DMA_CTL_STAT_REG,
20766929Smisaki channel, cs.value);
20773859Sml29623 break;
20783859Sml29623
20793859Sml29623 case RXDMA_RCRTO_CLEAR:
20803859Sml29623 RXDMA_REG_READ64(handle, RX_DMA_CTL_STAT_REG, channel,
20816929Smisaki &cs.value);
20823859Sml29623 cs.bits.hdw.rcrto = 0;
20833859Sml29623 RXDMA_REG_WRITE64(handle, RX_DMA_CTL_STAT_REG, channel,
20846929Smisaki cs.value);
20853859Sml29623 break;
20863859Sml29623
20873859Sml29623 case RXDMA_PT_DROP_PKT_CLEAR:
20883859Sml29623 RXDMA_REG_READ64(handle, RX_DMA_CTL_STAT_REG, channel,
20896929Smisaki &cs.value);
20903859Sml29623 cs.bits.hdw.port_drop_pkt = 0;
20913859Sml29623 RXDMA_REG_WRITE64(handle, RX_DMA_CTL_STAT_REG, channel,
20926929Smisaki cs.value);
20933859Sml29623 break;
20943859Sml29623
20953859Sml29623 case RXDMA_WRED_DROP_CLEAR:
20963859Sml29623 RXDMA_REG_READ64(handle, RX_DMA_CTL_STAT_REG, channel,
20976929Smisaki &cs.value);
20983859Sml29623 cs.bits.hdw.wred_drop = 0;
20993859Sml29623 RXDMA_REG_WRITE64(handle, RX_DMA_CTL_STAT_REG, channel,
21006929Smisaki cs.value);
21013859Sml29623 break;
21023859Sml29623
21033859Sml29623 case RXDMA_RCR_SFULL_CLEAR:
21043859Sml29623 RXDMA_REG_READ64(handle, RX_DMA_CTL_STAT_REG, channel,
21056929Smisaki &cs.value);
21063859Sml29623 cs.bits.hdw.rcr_shadow_full = 0;
21073859Sml29623 RXDMA_REG_WRITE64(handle, RX_DMA_CTL_STAT_REG, channel,
21086929Smisaki cs.value);
21093859Sml29623 break;
21103859Sml29623
21113859Sml29623 case RXDMA_RCR_FULL_CLEAR:
21123859Sml29623 RXDMA_REG_READ64(handle, RX_DMA_CTL_STAT_REG, channel,
21136929Smisaki &cs.value);
21143859Sml29623 cs.bits.hdw.rcrfull = 0;
21153859Sml29623 RXDMA_REG_WRITE64(handle, RX_DMA_CTL_STAT_REG, channel,
21166929Smisaki cs.value);
21173859Sml29623 break;
21183859Sml29623
21193859Sml29623 case RXDMA_RBR_PRE_EMPTY_CLEAR:
21203859Sml29623 RXDMA_REG_READ64(handle, RX_DMA_CTL_STAT_REG, channel,
21216929Smisaki &cs.value);
21223859Sml29623 cs.bits.hdw.rbr_pre_empty = 0;
21233859Sml29623 RXDMA_REG_WRITE64(handle, RX_DMA_CTL_STAT_REG, channel,
21246929Smisaki cs.value);
21253859Sml29623 break;
21263859Sml29623
21273859Sml29623 case RXDMA_RBR_EMPTY_CLEAR:
21283859Sml29623 RXDMA_REG_READ64(handle, RX_DMA_CTL_STAT_REG, channel,
21296929Smisaki &cs.value);
21303859Sml29623 cs.bits.hdw.rbr_empty = 1;
21313859Sml29623 RXDMA_REG_WRITE64(handle, RX_DMA_CTL_STAT_REG, channel,
21326929Smisaki cs.value);
21333859Sml29623 break;
21343859Sml29623
21353859Sml29623 case RXDMA_CS_CLEAR_ALL:
21363859Sml29623 cs.value = 0;
21373859Sml29623 RXDMA_REG_WRITE64(handle, RX_DMA_CTL_STAT_REG, channel,
21386929Smisaki cs.value);
21393859Sml29623 break;
21403859Sml29623
21413859Sml29623 default:
21423859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
21436929Smisaki "npi_rxdma_channel_control",
21446929Smisaki "control", control));
21453859Sml29623 return (NPI_FAILURE | NPI_RXDMA_OPCODE_INVALID(channel));
21463859Sml29623 }
21473859Sml29623
21483859Sml29623 return (NPI_SUCCESS);
21493859Sml29623 }
21503859Sml29623
21513859Sml29623 /*
21523859Sml29623 * npi_rxdma_control_status():
21533859Sml29623 * This function is called to operate on the control
21543859Sml29623 * and status register.
21553859Sml29623 *
21563859Sml29623 * Parameters:
21573859Sml29623 * handle - NPI handle
21583859Sml29623 * op_mode - OP_GET: get hardware control and status
21593859Sml29623 * OP_SET: set hardware control and status
21603859Sml29623 * OP_UPDATE: update hardware control and status.
21613859Sml29623 * OP_CLEAR: clear control and status register to 0s.
21623859Sml29623 * channel - hardware RXDMA channel from 0 to 23.
21633859Sml29623 * cs_p - pointer to hardware defined control and status
21643859Sml29623 * structure.
21653859Sml29623 * Return:
21663859Sml29623 * NPI_SUCCESS
21673859Sml29623 *
21683859Sml29623 * Error:
21693859Sml29623 * NPI error status code
21703859Sml29623 */
21713859Sml29623 npi_status_t
npi_rxdma_control_status(npi_handle_t handle,io_op_t op_mode,uint8_t channel,p_rx_dma_ctl_stat_t cs_p)21723859Sml29623 npi_rxdma_control_status(npi_handle_t handle, io_op_t op_mode,
21733859Sml29623 uint8_t channel, p_rx_dma_ctl_stat_t cs_p)
21743859Sml29623 {
21753859Sml29623 int status = NPI_SUCCESS;
21763859Sml29623 rx_dma_ctl_stat_t cs;
21773859Sml29623
21783859Sml29623 ASSERT(RXDMA_CHANNEL_VALID(channel));
21793859Sml29623 if (!RXDMA_CHANNEL_VALID(channel)) {
21803859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
21813859Sml29623 "npi_rxdma_control_status",
21823859Sml29623 "channel", channel));
21833859Sml29623 return (NPI_FAILURE | NPI_RXDMA_CHANNEL_INVALID(channel));
21843859Sml29623 }
21853859Sml29623
21863859Sml29623 switch (op_mode) {
21873859Sml29623 case OP_GET:
21883859Sml29623 RXDMA_REG_READ64(handle, RX_DMA_CTL_STAT_REG, channel,
21896929Smisaki &cs_p->value);
21903859Sml29623 break;
21913859Sml29623
21923859Sml29623 case OP_SET:
21933859Sml29623 RXDMA_REG_WRITE64(handle, RX_DMA_CTL_STAT_REG, channel,
21946929Smisaki cs_p->value);
21953859Sml29623 break;
21963859Sml29623
21973859Sml29623 case OP_UPDATE:
21983859Sml29623 RXDMA_REG_READ64(handle, RX_DMA_CTL_STAT_REG, channel,
21996929Smisaki &cs.value);
22003859Sml29623 RXDMA_REG_WRITE64(handle, RX_DMA_CTL_STAT_REG, channel,
22016929Smisaki cs_p->value | cs.value);
22023859Sml29623 break;
22033859Sml29623
22043859Sml29623 default:
22053859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
22063859Sml29623 "npi_rxdma_control_status",
22073859Sml29623 "control", op_mode));
22083859Sml29623 return (NPI_FAILURE | NPI_RXDMA_OPCODE_INVALID(channel));
22093859Sml29623 }
22103859Sml29623
22113859Sml29623 return (status);
22123859Sml29623 }
22133859Sml29623
22143859Sml29623 /*
22153859Sml29623 * npi_rxdma_event_mask():
22163859Sml29623 * This function is called to operate on the event mask
22173859Sml29623 * register which is used for generating interrupts.
22183859Sml29623 *
22193859Sml29623 * Parameters:
22203859Sml29623 * handle - NPI handle
22213859Sml29623 * op_mode - OP_GET: get hardware event mask
22223859Sml29623 * OP_SET: set hardware interrupt event masks
22233859Sml29623 * OP_CLEAR: clear control and status register to 0s.
22243859Sml29623 * channel - hardware RXDMA channel from 0 to 23.
22253859Sml29623 * mask_p - pointer to hardware defined event mask
22263859Sml29623 * structure.
22273859Sml29623 * Return:
22283859Sml29623 * NPI_SUCCESS - If set is complete successfully.
22293859Sml29623 *
22303859Sml29623 * Error:
22313859Sml29623 * NPI error status code
22323859Sml29623 */
22333859Sml29623 npi_status_t
npi_rxdma_event_mask(npi_handle_t handle,io_op_t op_mode,uint8_t channel,p_rx_dma_ent_msk_t mask_p)22343859Sml29623 npi_rxdma_event_mask(npi_handle_t handle, io_op_t op_mode,
22353859Sml29623 uint8_t channel, p_rx_dma_ent_msk_t mask_p)
22363859Sml29623 {
22373859Sml29623 int status = NPI_SUCCESS;
22383859Sml29623 rx_dma_ent_msk_t mask;
22393859Sml29623
22403859Sml29623 ASSERT(RXDMA_CHANNEL_VALID(channel));
22413859Sml29623 if (!RXDMA_CHANNEL_VALID(channel)) {
22423859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
22433859Sml29623 "npi_rxdma_event_mask",
22443859Sml29623 "channel", channel));
22453859Sml29623 return (NPI_FAILURE | NPI_RXDMA_CHANNEL_INVALID(channel));
22463859Sml29623 }
22473859Sml29623
22483859Sml29623 switch (op_mode) {
22493859Sml29623 case OP_GET:
22503859Sml29623 RXDMA_REG_READ64(handle, RX_DMA_ENT_MSK_REG, channel,
22516929Smisaki &mask_p->value);
22523859Sml29623 break;
22533859Sml29623
22543859Sml29623 case OP_SET:
22553859Sml29623 RXDMA_REG_WRITE64(handle, RX_DMA_ENT_MSK_REG, channel,
22566929Smisaki mask_p->value);
22573859Sml29623 break;
22583859Sml29623
22593859Sml29623 case OP_UPDATE:
22603859Sml29623 RXDMA_REG_READ64(handle, RX_DMA_ENT_MSK_REG, channel,
22616929Smisaki &mask.value);
22623859Sml29623 RXDMA_REG_WRITE64(handle, RX_DMA_ENT_MSK_REG, channel,
22636929Smisaki mask_p->value | mask.value);
22643859Sml29623 break;
22653859Sml29623
22663859Sml29623 default:
22673859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
22683859Sml29623 "npi_rxdma_event_mask",
22693859Sml29623 "eventmask", op_mode));
22703859Sml29623 return (NPI_FAILURE | NPI_RXDMA_OPCODE_INVALID(channel));
22713859Sml29623 }
22723859Sml29623
22733859Sml29623 return (status);
22743859Sml29623 }
22753859Sml29623
22763859Sml29623 /*
22773859Sml29623 * npi_rxdma_event_mask_config():
22783859Sml29623 * This function is called to operate on the event mask
22793859Sml29623 * register which is used for generating interrupts
22803859Sml29623 * and status register.
22813859Sml29623 *
22823859Sml29623 * Parameters:
22833859Sml29623 * handle - NPI handle
22843859Sml29623 * op_mode - OP_GET: get hardware event mask
22853859Sml29623 * OP_SET: set hardware interrupt event masks
22863859Sml29623 * OP_CLEAR: clear control and status register to 0s.
22873859Sml29623 * channel - hardware RXDMA channel from 0 to 23.
22883859Sml29623 * mask_cfgp - pointer to NPI defined event mask
22893859Sml29623 * enum data type.
22903859Sml29623 * Return:
22913859Sml29623 * NPI_SUCCESS - If set is complete successfully.
22923859Sml29623 *
22933859Sml29623 * Error:
22943859Sml29623 * NPI error status code
22953859Sml29623 */
22963859Sml29623 npi_status_t
npi_rxdma_event_mask_config(npi_handle_t handle,io_op_t op_mode,uint8_t channel,rxdma_ent_msk_cfg_t * mask_cfgp)22973859Sml29623 npi_rxdma_event_mask_config(npi_handle_t handle, io_op_t op_mode,
22983859Sml29623 uint8_t channel, rxdma_ent_msk_cfg_t *mask_cfgp)
22993859Sml29623 {
23003859Sml29623 int status = NPI_SUCCESS;
23016495Sspeer uint64_t configuration = *mask_cfgp;
23023859Sml29623 uint64_t value;
23033859Sml29623
23043859Sml29623 ASSERT(RXDMA_CHANNEL_VALID(channel));
23053859Sml29623 if (!RXDMA_CHANNEL_VALID(channel)) {
23063859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
23073859Sml29623 "npi_rxdma_event_mask_config",
23083859Sml29623 "channel", channel));
23093859Sml29623 return (NPI_FAILURE | NPI_RXDMA_CHANNEL_INVALID(channel));
23103859Sml29623 }
23113859Sml29623
23123859Sml29623 switch (op_mode) {
23133859Sml29623 case OP_GET:
23143859Sml29623 RXDMA_REG_READ64(handle, RX_DMA_ENT_MSK_REG, channel,
23156495Sspeer (uint64_t *)mask_cfgp);
23163859Sml29623 break;
23173859Sml29623
23183859Sml29623 case OP_SET:
23193859Sml29623 RXDMA_REG_WRITE64(handle, RX_DMA_ENT_MSK_REG, channel,
23206495Sspeer configuration);
23213859Sml29623 break;
23223859Sml29623
23233859Sml29623 case OP_UPDATE:
23243859Sml29623 RXDMA_REG_READ64(handle, RX_DMA_ENT_MSK_REG, channel, &value);
23253859Sml29623 RXDMA_REG_WRITE64(handle, RX_DMA_ENT_MSK_REG, channel,
23266495Sspeer configuration | value);
23273859Sml29623 break;
23283859Sml29623
23293859Sml29623 case OP_CLEAR:
23303859Sml29623 RXDMA_REG_WRITE64(handle, RX_DMA_ENT_MSK_REG, channel,
23316495Sspeer CFG_RXDMA_MASK_ALL);
23323859Sml29623 break;
23333859Sml29623 default:
23343859Sml29623 NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
23353859Sml29623 "npi_rxdma_event_mask_config",
23363859Sml29623 "eventmask", op_mode));
23373859Sml29623 return (NPI_FAILURE | NPI_RXDMA_OPCODE_INVALID(channel));
23383859Sml29623 }
23393859Sml29623
23403859Sml29623 return (status);
23413859Sml29623 }
2342