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 /* 225770Sml29623 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 233859Sml29623 * Use is subject to license terms. 243859Sml29623 */ 253859Sml29623 263859Sml29623 #pragma ident "%Z%%M% %I% %E% SMI" 273859Sml29623 283859Sml29623 /* 293859Sml29623 * SunOs MT STREAMS NIU/Neptune 10Gb Ethernet Device Driver. 303859Sml29623 */ 313859Sml29623 #include <sys/nxge/nxge_impl.h> 326495Sspeer #include <sys/nxge/nxge_hio.h> 336495Sspeer #include <sys/nxge/nxge_rxdma.h> 343859Sml29623 #include <sys/pcie.h> 353859Sml29623 363859Sml29623 uint32_t nxge_use_partition = 0; /* debug partition flag */ 373859Sml29623 uint32_t nxge_dma_obp_props_only = 1; /* use obp published props */ 383859Sml29623 uint32_t nxge_use_rdc_intr = 1; /* debug to assign rdc intr */ 393859Sml29623 /* 405013Sml29623 * PSARC/2007/453 MSI-X interrupt limit override 415013Sml29623 * (This PSARC case is limited to MSI-X vectors 425013Sml29623 * and SPARC platforms only). 433859Sml29623 */ 445013Sml29623 #if defined(_BIG_ENDIAN) 455013Sml29623 uint32_t nxge_msi_enable = 2; 465013Sml29623 #else 475013Sml29623 uint32_t nxge_msi_enable = 1; 485013Sml29623 #endif 493859Sml29623 506495Sspeer uint32_t nxge_cksum_enable = 0; 516495Sspeer 523859Sml29623 /* 533859Sml29623 * Globals: tunable parameters (/etc/system or adb) 543859Sml29623 * 553859Sml29623 */ 563859Sml29623 uint32_t nxge_rbr_size = NXGE_RBR_RBB_DEFAULT; 573859Sml29623 uint32_t nxge_rbr_spare_size = 0; 583859Sml29623 uint32_t nxge_rcr_size = NXGE_RCR_DEFAULT; 593859Sml29623 uint32_t nxge_tx_ring_size = NXGE_TX_RING_DEFAULT; 604193Sspeer boolean_t nxge_no_msg = B_TRUE; /* control message display */ 613859Sml29623 uint32_t nxge_no_link_notify = 0; /* control DL_NOTIFY */ 623859Sml29623 uint32_t nxge_bcopy_thresh = TX_BCOPY_MAX; 633859Sml29623 uint32_t nxge_dvma_thresh = TX_FASTDVMA_MIN; 643859Sml29623 uint32_t nxge_dma_stream_thresh = TX_STREAM_MIN; 653859Sml29623 uint32_t nxge_jumbo_mtu = TX_JUMBO_MTU; 663859Sml29623 boolean_t nxge_jumbo_enable = B_FALSE; 673859Sml29623 uint16_t nxge_rcr_timeout = NXGE_RDC_RCR_TIMEOUT; 683859Sml29623 uint16_t nxge_rcr_threshold = NXGE_RDC_RCR_THRESHOLD; 693952Sml29623 nxge_tx_mode_t nxge_tx_scheme = NXGE_USE_SERIAL; 703859Sml29623 715770Sml29623 /* MAX LSO size */ 725770Sml29623 #define NXGE_LSO_MAXLEN 65535 735770Sml29623 uint32_t nxge_lso_max = NXGE_LSO_MAXLEN; 745770Sml29623 753859Sml29623 /* 763859Sml29623 * Debugging flags: 773859Sml29623 * nxge_no_tx_lb : transmit load balancing 783859Sml29623 * nxge_tx_lb_policy: 0 - TCP port (default) 793859Sml29623 * 3 - DEST MAC 803859Sml29623 */ 813859Sml29623 uint32_t nxge_no_tx_lb = 0; 823859Sml29623 uint32_t nxge_tx_lb_policy = NXGE_TX_LB_TCPUDP; 833859Sml29623 843859Sml29623 /* 853859Sml29623 * Add tunable to reduce the amount of time spent in the 863859Sml29623 * ISR doing Rx Processing. 873859Sml29623 */ 883859Sml29623 uint32_t nxge_max_rx_pkts = 1024; 893859Sml29623 903859Sml29623 /* 913859Sml29623 * Tunables to manage the receive buffer blocks. 923859Sml29623 * 933859Sml29623 * nxge_rx_threshold_hi: copy all buffers. 943859Sml29623 * nxge_rx_bcopy_size_type: receive buffer block size type. 953859Sml29623 * nxge_rx_threshold_lo: copy only up to tunable block size type. 963859Sml29623 */ 973859Sml29623 nxge_rxbuf_threshold_t nxge_rx_threshold_hi = NXGE_RX_COPY_6; 983859Sml29623 nxge_rxbuf_type_t nxge_rx_buf_size_type = RCR_PKTBUFSZ_0; 993859Sml29623 nxge_rxbuf_threshold_t nxge_rx_threshold_lo = NXGE_RX_COPY_3; 1003859Sml29623 1016495Sspeer /* Use kmem_alloc() to allocate data buffers. */ 1026495Sspeer #if !defined(__i386) 103*6498Sspeer uint32_t nxge_use_kmem_alloc = 1; 1046495Sspeer #else 105*6498Sspeer uint32_t nxge_use_kmem_alloc = 0; 1066495Sspeer #endif 1076495Sspeer 1083859Sml29623 rtrace_t npi_rtracebuf; 1093859Sml29623 1103859Sml29623 #if defined(sun4v) 1113859Sml29623 /* 1123859Sml29623 * Hypervisor N2/NIU services information. 1133859Sml29623 */ 1143859Sml29623 static hsvc_info_t niu_hsvc = { 1153859Sml29623 HSVC_REV_1, NULL, HSVC_GROUP_NIU, NIU_MAJOR_VER, 1163859Sml29623 NIU_MINOR_VER, "nxge" 1173859Sml29623 }; 1186495Sspeer 1196495Sspeer static int nxge_hsvc_register(p_nxge_t); 1203859Sml29623 #endif 1213859Sml29623 1223859Sml29623 /* 1233859Sml29623 * Function Prototypes 1243859Sml29623 */ 1253859Sml29623 static int nxge_attach(dev_info_t *, ddi_attach_cmd_t); 1263859Sml29623 static int nxge_detach(dev_info_t *, ddi_detach_cmd_t); 1273859Sml29623 static void nxge_unattach(p_nxge_t); 1283859Sml29623 1293859Sml29623 #if NXGE_PROPERTY 1303859Sml29623 static void nxge_remove_hard_properties(p_nxge_t); 1313859Sml29623 #endif 1323859Sml29623 1336495Sspeer /* 1346495Sspeer * These two functions are required by nxge_hio.c 1356495Sspeer */ 1366495Sspeer extern int nxge_m_mmac_add(void *arg, mac_multi_addr_t *maddr); 1376495Sspeer extern int nxge_m_mmac_remove(void *arg, mac_addr_slot_t slot); 1386495Sspeer 1393859Sml29623 static nxge_status_t nxge_setup_system_dma_pages(p_nxge_t); 1403859Sml29623 1413859Sml29623 static nxge_status_t nxge_setup_mutexes(p_nxge_t); 1423859Sml29623 static void nxge_destroy_mutexes(p_nxge_t); 1433859Sml29623 1443859Sml29623 static nxge_status_t nxge_map_regs(p_nxge_t nxgep); 1453859Sml29623 static void nxge_unmap_regs(p_nxge_t nxgep); 1463859Sml29623 #ifdef NXGE_DEBUG 1473859Sml29623 static void nxge_test_map_regs(p_nxge_t nxgep); 1483859Sml29623 #endif 1493859Sml29623 1503859Sml29623 static nxge_status_t nxge_add_intrs(p_nxge_t nxgep); 1513859Sml29623 static nxge_status_t nxge_add_soft_intrs(p_nxge_t nxgep); 1523859Sml29623 static void nxge_remove_intrs(p_nxge_t nxgep); 1533859Sml29623 static void nxge_remove_soft_intrs(p_nxge_t nxgep); 1543859Sml29623 1553859Sml29623 static nxge_status_t nxge_add_intrs_adv(p_nxge_t nxgep); 1563859Sml29623 static nxge_status_t nxge_add_intrs_adv_type(p_nxge_t, uint32_t); 1573859Sml29623 static nxge_status_t nxge_add_intrs_adv_type_fix(p_nxge_t, uint32_t); 1583859Sml29623 static void nxge_intrs_enable(p_nxge_t nxgep); 1593859Sml29623 static void nxge_intrs_disable(p_nxge_t nxgep); 1603859Sml29623 1613859Sml29623 static void nxge_suspend(p_nxge_t); 1623859Sml29623 static nxge_status_t nxge_resume(p_nxge_t); 1633859Sml29623 1643859Sml29623 static nxge_status_t nxge_setup_dev(p_nxge_t); 1653859Sml29623 static void nxge_destroy_dev(p_nxge_t); 1663859Sml29623 1673859Sml29623 static nxge_status_t nxge_alloc_mem_pool(p_nxge_t); 1683859Sml29623 static void nxge_free_mem_pool(p_nxge_t); 1693859Sml29623 1706495Sspeer nxge_status_t nxge_alloc_rx_mem_pool(p_nxge_t); 1713859Sml29623 static void nxge_free_rx_mem_pool(p_nxge_t); 1723859Sml29623 1736495Sspeer nxge_status_t nxge_alloc_tx_mem_pool(p_nxge_t); 1743859Sml29623 static void nxge_free_tx_mem_pool(p_nxge_t); 1753859Sml29623 1763859Sml29623 static nxge_status_t nxge_dma_mem_alloc(p_nxge_t, dma_method_t, 1773859Sml29623 struct ddi_dma_attr *, 1783859Sml29623 size_t, ddi_device_acc_attr_t *, uint_t, 1793859Sml29623 p_nxge_dma_common_t); 1803859Sml29623 1813859Sml29623 static void nxge_dma_mem_free(p_nxge_dma_common_t); 1826495Sspeer static void nxge_dma_free_rx_data_buf(p_nxge_dma_common_t); 1833859Sml29623 1843859Sml29623 static nxge_status_t nxge_alloc_rx_buf_dma(p_nxge_t, uint16_t, 1853859Sml29623 p_nxge_dma_common_t *, size_t, size_t, uint32_t *); 1863859Sml29623 static void nxge_free_rx_buf_dma(p_nxge_t, p_nxge_dma_common_t, uint32_t); 1873859Sml29623 1883859Sml29623 static nxge_status_t nxge_alloc_rx_cntl_dma(p_nxge_t, uint16_t, 1893859Sml29623 p_nxge_dma_common_t *, size_t); 1903859Sml29623 static void nxge_free_rx_cntl_dma(p_nxge_t, p_nxge_dma_common_t); 1913859Sml29623 1926495Sspeer extern nxge_status_t nxge_alloc_tx_buf_dma(p_nxge_t, uint16_t, 1933859Sml29623 p_nxge_dma_common_t *, size_t, size_t, uint32_t *); 1943859Sml29623 static void nxge_free_tx_buf_dma(p_nxge_t, p_nxge_dma_common_t, uint32_t); 1953859Sml29623 1966495Sspeer extern nxge_status_t nxge_alloc_tx_cntl_dma(p_nxge_t, uint16_t, 1973859Sml29623 p_nxge_dma_common_t *, 1983859Sml29623 size_t); 1993859Sml29623 static void nxge_free_tx_cntl_dma(p_nxge_t, p_nxge_dma_common_t); 2003859Sml29623 2013859Sml29623 static int nxge_init_common_dev(p_nxge_t); 2023859Sml29623 static void nxge_uninit_common_dev(p_nxge_t); 2033859Sml29623 2043859Sml29623 /* 2053859Sml29623 * The next declarations are for the GLDv3 interface. 2063859Sml29623 */ 2073859Sml29623 static int nxge_m_start(void *); 2083859Sml29623 static void nxge_m_stop(void *); 2093859Sml29623 static int nxge_m_unicst(void *, const uint8_t *); 2103859Sml29623 static int nxge_m_multicst(void *, boolean_t, const uint8_t *); 2113859Sml29623 static int nxge_m_promisc(void *, boolean_t); 2123859Sml29623 static void nxge_m_ioctl(void *, queue_t *, mblk_t *); 2133859Sml29623 static void nxge_m_resources(void *); 2143859Sml29623 mblk_t *nxge_m_tx(void *arg, mblk_t *); 2153859Sml29623 static nxge_status_t nxge_mac_register(p_nxge_t); 2163859Sml29623 static int nxge_altmac_set(p_nxge_t nxgep, uint8_t *mac_addr, 2173859Sml29623 mac_addr_slot_t slot); 2186495Sspeer void nxge_mmac_kstat_update(p_nxge_t nxgep, mac_addr_slot_t slot, 2193859Sml29623 boolean_t factory); 2203859Sml29623 static int nxge_m_mmac_reserve(void *arg, mac_multi_addr_t *maddr); 2213859Sml29623 static int nxge_m_mmac_modify(void *arg, mac_multi_addr_t *maddr); 2223859Sml29623 static int nxge_m_mmac_get(void *arg, mac_multi_addr_t *maddr); 2236439Sml29623 static boolean_t nxge_m_getcapab(void *, mac_capab_t, void *); 2246439Sml29623 static int nxge_m_setprop(void *, const char *, mac_prop_id_t, 2256439Sml29623 uint_t, const void *); 2266439Sml29623 static int nxge_m_getprop(void *, const char *, mac_prop_id_t, 2276439Sml29623 uint_t, void *); 2286439Sml29623 static int nxge_set_priv_prop(nxge_t *, const char *, uint_t, 2296439Sml29623 const void *); 2306439Sml29623 static int nxge_get_priv_prop(nxge_t *, const char *, uint_t, 2316439Sml29623 void *); 2326439Sml29623 2336439Sml29623 #define NXGE_M_CALLBACK_FLAGS\ 2346439Sml29623 (MC_RESOURCES | MC_IOCTL | MC_GETCAPAB | MC_SETPROP | MC_GETPROP) 2356439Sml29623 2363859Sml29623 2373859Sml29623 #define NXGE_NEPTUNE_MAGIC 0x4E584745UL 2383859Sml29623 #define MAX_DUMP_SZ 256 2393859Sml29623 2406439Sml29623 #define NXGE_M_CALLBACK_FLAGS \ 2416439Sml29623 (MC_RESOURCES | MC_IOCTL | MC_GETCAPAB | MC_SETPROP | MC_GETPROP) 2426439Sml29623 2436495Sspeer mac_callbacks_t nxge_m_callbacks = { 2443859Sml29623 NXGE_M_CALLBACK_FLAGS, 2453859Sml29623 nxge_m_stat, 2463859Sml29623 nxge_m_start, 2473859Sml29623 nxge_m_stop, 2483859Sml29623 nxge_m_promisc, 2493859Sml29623 nxge_m_multicst, 2503859Sml29623 nxge_m_unicst, 2513859Sml29623 nxge_m_tx, 2523859Sml29623 nxge_m_resources, 2533859Sml29623 nxge_m_ioctl, 2546439Sml29623 nxge_m_getcapab, 2556439Sml29623 NULL, 2566439Sml29623 NULL, 2576439Sml29623 nxge_m_setprop, 2586439Sml29623 nxge_m_getprop 2593859Sml29623 }; 2603859Sml29623 2613859Sml29623 void 2623859Sml29623 nxge_err_inject(p_nxge_t, queue_t *, mblk_t *); 2633859Sml29623 2645013Sml29623 /* PSARC/2007/453 MSI-X interrupt limit override. */ 2655013Sml29623 #define NXGE_MSIX_REQUEST_10G 8 2665013Sml29623 #define NXGE_MSIX_REQUEST_1G 2 2675013Sml29623 static int nxge_create_msi_property(p_nxge_t); 2685013Sml29623 2693859Sml29623 /* 2703859Sml29623 * These global variables control the message 2713859Sml29623 * output. 2723859Sml29623 */ 2733859Sml29623 out_dbgmsg_t nxge_dbgmsg_out = DBG_CONSOLE | STR_LOG; 2746495Sspeer uint64_t nxge_debug_level; 2753859Sml29623 2763859Sml29623 /* 2773859Sml29623 * This list contains the instance structures for the Neptune 2783859Sml29623 * devices present in the system. The lock exists to guarantee 2793859Sml29623 * mutually exclusive access to the list. 2803859Sml29623 */ 2813859Sml29623 void *nxge_list = NULL; 2823859Sml29623 2833859Sml29623 void *nxge_hw_list = NULL; 2843859Sml29623 nxge_os_mutex_t nxge_common_lock; 2853859Sml29623 2863859Sml29623 extern uint64_t npi_debug_level; 2873859Sml29623 2883859Sml29623 extern nxge_status_t nxge_ldgv_init(p_nxge_t, int *, int *); 2893859Sml29623 extern nxge_status_t nxge_ldgv_init_n2(p_nxge_t, int *, int *); 2903859Sml29623 extern nxge_status_t nxge_ldgv_uninit(p_nxge_t); 2913859Sml29623 extern nxge_status_t nxge_intr_ldgv_init(p_nxge_t); 2923859Sml29623 extern void nxge_fm_init(p_nxge_t, 2933859Sml29623 ddi_device_acc_attr_t *, 2943859Sml29623 ddi_device_acc_attr_t *, 2953859Sml29623 ddi_dma_attr_t *); 2963859Sml29623 extern void nxge_fm_fini(p_nxge_t); 2973859Sml29623 extern npi_status_t npi_mac_altaddr_disable(npi_handle_t, uint8_t, uint8_t); 2983859Sml29623 2993859Sml29623 /* 3003859Sml29623 * Count used to maintain the number of buffers being used 3013859Sml29623 * by Neptune instances and loaned up to the upper layers. 3023859Sml29623 */ 3033859Sml29623 uint32_t nxge_mblks_pending = 0; 3043859Sml29623 3053859Sml29623 /* 3063859Sml29623 * Device register access attributes for PIO. 3073859Sml29623 */ 3083859Sml29623 static ddi_device_acc_attr_t nxge_dev_reg_acc_attr = { 3093859Sml29623 DDI_DEVICE_ATTR_V0, 3103859Sml29623 DDI_STRUCTURE_LE_ACC, 3113859Sml29623 DDI_STRICTORDER_ACC, 3123859Sml29623 }; 3133859Sml29623 3143859Sml29623 /* 3153859Sml29623 * Device descriptor access attributes for DMA. 3163859Sml29623 */ 3173859Sml29623 static ddi_device_acc_attr_t nxge_dev_desc_dma_acc_attr = { 3183859Sml29623 DDI_DEVICE_ATTR_V0, 3193859Sml29623 DDI_STRUCTURE_LE_ACC, 3203859Sml29623 DDI_STRICTORDER_ACC 3213859Sml29623 }; 3223859Sml29623 3233859Sml29623 /* 3243859Sml29623 * Device buffer access attributes for DMA. 3253859Sml29623 */ 3263859Sml29623 static ddi_device_acc_attr_t nxge_dev_buf_dma_acc_attr = { 3273859Sml29623 DDI_DEVICE_ATTR_V0, 3283859Sml29623 DDI_STRUCTURE_BE_ACC, 3293859Sml29623 DDI_STRICTORDER_ACC 3303859Sml29623 }; 3313859Sml29623 3323859Sml29623 ddi_dma_attr_t nxge_desc_dma_attr = { 3333859Sml29623 DMA_ATTR_V0, /* version number. */ 3343859Sml29623 0, /* low address */ 3353859Sml29623 0xffffffffffffffff, /* high address */ 3363859Sml29623 0xffffffffffffffff, /* address counter max */ 3373859Sml29623 #ifndef NIU_PA_WORKAROUND 3383859Sml29623 0x100000, /* alignment */ 3393859Sml29623 #else 3403859Sml29623 0x2000, 3413859Sml29623 #endif 3423859Sml29623 0xfc00fc, /* dlim_burstsizes */ 3433859Sml29623 0x1, /* minimum transfer size */ 3443859Sml29623 0xffffffffffffffff, /* maximum transfer size */ 3453859Sml29623 0xffffffffffffffff, /* maximum segment size */ 3463859Sml29623 1, /* scatter/gather list length */ 3473859Sml29623 (unsigned int) 1, /* granularity */ 3483859Sml29623 0 /* attribute flags */ 3493859Sml29623 }; 3503859Sml29623 3513859Sml29623 ddi_dma_attr_t nxge_tx_dma_attr = { 3523859Sml29623 DMA_ATTR_V0, /* version number. */ 3533859Sml29623 0, /* low address */ 3543859Sml29623 0xffffffffffffffff, /* high address */ 3553859Sml29623 0xffffffffffffffff, /* address counter max */ 3563859Sml29623 #if defined(_BIG_ENDIAN) 3573859Sml29623 0x2000, /* alignment */ 3583859Sml29623 #else 3593859Sml29623 0x1000, /* alignment */ 3603859Sml29623 #endif 3613859Sml29623 0xfc00fc, /* dlim_burstsizes */ 3623859Sml29623 0x1, /* minimum transfer size */ 3633859Sml29623 0xffffffffffffffff, /* maximum transfer size */ 3643859Sml29623 0xffffffffffffffff, /* maximum segment size */ 3653859Sml29623 5, /* scatter/gather list length */ 3663859Sml29623 (unsigned int) 1, /* granularity */ 3673859Sml29623 0 /* attribute flags */ 3683859Sml29623 }; 3693859Sml29623 3703859Sml29623 ddi_dma_attr_t nxge_rx_dma_attr = { 3713859Sml29623 DMA_ATTR_V0, /* version number. */ 3723859Sml29623 0, /* low address */ 3733859Sml29623 0xffffffffffffffff, /* high address */ 3743859Sml29623 0xffffffffffffffff, /* address counter max */ 3753859Sml29623 0x2000, /* alignment */ 3763859Sml29623 0xfc00fc, /* dlim_burstsizes */ 3773859Sml29623 0x1, /* minimum transfer size */ 3783859Sml29623 0xffffffffffffffff, /* maximum transfer size */ 3793859Sml29623 0xffffffffffffffff, /* maximum segment size */ 3803859Sml29623 1, /* scatter/gather list length */ 3813859Sml29623 (unsigned int) 1, /* granularity */ 3824781Ssbehera DDI_DMA_RELAXED_ORDERING /* attribute flags */ 3833859Sml29623 }; 3843859Sml29623 3853859Sml29623 ddi_dma_lim_t nxge_dma_limits = { 3863859Sml29623 (uint_t)0, /* dlim_addr_lo */ 3873859Sml29623 (uint_t)0xffffffff, /* dlim_addr_hi */ 3883859Sml29623 (uint_t)0xffffffff, /* dlim_cntr_max */ 3893859Sml29623 (uint_t)0xfc00fc, /* dlim_burstsizes for 32 and 64 bit xfers */ 3903859Sml29623 0x1, /* dlim_minxfer */ 3913859Sml29623 1024 /* dlim_speed */ 3923859Sml29623 }; 3933859Sml29623 3943859Sml29623 dma_method_t nxge_force_dma = DVMA; 3953859Sml29623 3963859Sml29623 /* 3973859Sml29623 * dma chunk sizes. 3983859Sml29623 * 3993859Sml29623 * Try to allocate the largest possible size 4003859Sml29623 * so that fewer number of dma chunks would be managed 4013859Sml29623 */ 4023859Sml29623 #ifdef NIU_PA_WORKAROUND 4033859Sml29623 size_t alloc_sizes [] = {0x2000}; 4043859Sml29623 #else 4053859Sml29623 size_t alloc_sizes [] = {0x1000, 0x2000, 0x4000, 0x8000, 4063859Sml29623 0x10000, 0x20000, 0x40000, 0x80000, 4075770Sml29623 0x100000, 0x200000, 0x400000, 0x800000, 4085770Sml29623 0x1000000, 0x2000000, 0x4000000}; 4093859Sml29623 #endif 4103859Sml29623 4113859Sml29623 /* 4123859Sml29623 * Translate "dev_t" to a pointer to the associated "dev_info_t". 4133859Sml29623 */ 4143859Sml29623 4156495Sspeer extern void nxge_get_environs(nxge_t *); 4166495Sspeer 4173859Sml29623 static int 4183859Sml29623 nxge_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) 4193859Sml29623 { 4203859Sml29623 p_nxge_t nxgep = NULL; 4213859Sml29623 int instance; 4223859Sml29623 int status = DDI_SUCCESS; 4233859Sml29623 uint8_t portn; 4243859Sml29623 nxge_mmac_t *mmac_info; 4253859Sml29623 4263859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_attach")); 4273859Sml29623 4283859Sml29623 /* 4293859Sml29623 * Get the device instance since we'll need to setup 4303859Sml29623 * or retrieve a soft state for this instance. 4313859Sml29623 */ 4323859Sml29623 instance = ddi_get_instance(dip); 4333859Sml29623 4343859Sml29623 switch (cmd) { 4353859Sml29623 case DDI_ATTACH: 4363859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "doing DDI_ATTACH")); 4373859Sml29623 break; 4383859Sml29623 4393859Sml29623 case DDI_RESUME: 4403859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "doing DDI_RESUME")); 4413859Sml29623 nxgep = (p_nxge_t)ddi_get_soft_state(nxge_list, instance); 4423859Sml29623 if (nxgep == NULL) { 4433859Sml29623 status = DDI_FAILURE; 4443859Sml29623 break; 4453859Sml29623 } 4463859Sml29623 if (nxgep->dip != dip) { 4473859Sml29623 status = DDI_FAILURE; 4483859Sml29623 break; 4493859Sml29623 } 4503859Sml29623 if (nxgep->suspended == DDI_PM_SUSPEND) { 4513859Sml29623 status = ddi_dev_is_needed(nxgep->dip, 0, 1); 4523859Sml29623 } else { 4534185Sspeer status = nxge_resume(nxgep); 4543859Sml29623 } 4553859Sml29623 goto nxge_attach_exit; 4563859Sml29623 4573859Sml29623 case DDI_PM_RESUME: 4583859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "doing DDI_PM_RESUME")); 4593859Sml29623 nxgep = (p_nxge_t)ddi_get_soft_state(nxge_list, instance); 4603859Sml29623 if (nxgep == NULL) { 4613859Sml29623 status = DDI_FAILURE; 4623859Sml29623 break; 4633859Sml29623 } 4643859Sml29623 if (nxgep->dip != dip) { 4653859Sml29623 status = DDI_FAILURE; 4663859Sml29623 break; 4673859Sml29623 } 4684185Sspeer status = nxge_resume(nxgep); 4693859Sml29623 goto nxge_attach_exit; 4703859Sml29623 4713859Sml29623 default: 4723859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "doing unknown")); 4733859Sml29623 status = DDI_FAILURE; 4743859Sml29623 goto nxge_attach_exit; 4753859Sml29623 } 4763859Sml29623 4773859Sml29623 4783859Sml29623 if (ddi_soft_state_zalloc(nxge_list, instance) == DDI_FAILURE) { 4793859Sml29623 status = DDI_FAILURE; 4803859Sml29623 goto nxge_attach_exit; 4813859Sml29623 } 4823859Sml29623 4833859Sml29623 nxgep = ddi_get_soft_state(nxge_list, instance); 4843859Sml29623 if (nxgep == NULL) { 4854977Sraghus status = NXGE_ERROR; 4864977Sraghus goto nxge_attach_fail2; 4873859Sml29623 } 4883859Sml29623 4894693Stm144005 nxgep->nxge_magic = NXGE_MAGIC; 4904693Stm144005 4913859Sml29623 nxgep->drv_state = 0; 4923859Sml29623 nxgep->dip = dip; 4933859Sml29623 nxgep->instance = instance; 4943859Sml29623 nxgep->p_dip = ddi_get_parent(dip); 4953859Sml29623 nxgep->nxge_debug_level = nxge_debug_level; 4963859Sml29623 npi_debug_level = nxge_debug_level; 4973859Sml29623 4986495Sspeer /* Are we a guest running in a Hybrid I/O environment? */ 4996495Sspeer nxge_get_environs(nxgep); 5003859Sml29623 5013859Sml29623 status = nxge_map_regs(nxgep); 5026495Sspeer 5033859Sml29623 if (status != NXGE_OK) { 5043859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "nxge_map_regs failed")); 5054977Sraghus goto nxge_attach_fail3; 5063859Sml29623 } 5073859Sml29623 5086495Sspeer nxge_fm_init(nxgep, &nxge_dev_reg_acc_attr, 5096495Sspeer &nxge_dev_desc_dma_acc_attr, 5106495Sspeer &nxge_rx_dma_attr); 5116495Sspeer 5126495Sspeer /* Create & initialize the per-Neptune data structure */ 5136495Sspeer /* (even if we're a guest). */ 5143859Sml29623 status = nxge_init_common_dev(nxgep); 5153859Sml29623 if (status != NXGE_OK) { 5163859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 5173859Sml29623 "nxge_init_common_dev failed")); 5184977Sraghus goto nxge_attach_fail4; 5193859Sml29623 } 5203859Sml29623 5216495Sspeer #if defined(sun4v) 5226495Sspeer /* This is required by nxge_hio_init(), which follows. */ 5236495Sspeer if ((status = nxge_hsvc_register(nxgep)) != DDI_SUCCESS) 5246495Sspeer goto nxge_attach_fail; 5256495Sspeer #endif 5266495Sspeer 5276495Sspeer if ((status = nxge_hio_init(nxgep)) != NXGE_OK) { 5286495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 5296495Sspeer "nxge_hio_init failed")); 5306495Sspeer goto nxge_attach_fail4; 5316495Sspeer } 5326495Sspeer 5334732Sdavemq if (nxgep->niu_type == NEPTUNE_2_10GF) { 5344732Sdavemq if (nxgep->function_num > 1) { 5356028Ssbehera NXGE_DEBUG_MSG((nxgep, DDI_CTL, "Unsupported" 5364732Sdavemq " function %d. Only functions 0 and 1 are " 5374732Sdavemq "supported for this card.", nxgep->function_num)); 5384732Sdavemq status = NXGE_ERROR; 5394977Sraghus goto nxge_attach_fail4; 5404732Sdavemq } 5414732Sdavemq } 5424732Sdavemq 5436495Sspeer if (isLDOMguest(nxgep)) { 5446495Sspeer /* 5456495Sspeer * Use the function number here. 5466495Sspeer */ 5476495Sspeer nxgep->mac.portnum = nxgep->function_num; 5486495Sspeer nxgep->mac.porttype = PORT_TYPE_LOGICAL; 5496495Sspeer 5506495Sspeer /* XXX We'll set the MAC address counts to 1 for now. */ 5516495Sspeer mmac_info = &nxgep->nxge_mmac_info; 5526495Sspeer mmac_info->num_mmac = 1; 5536495Sspeer mmac_info->naddrfree = 1; 5543859Sml29623 } else { 5556495Sspeer portn = NXGE_GET_PORT_NUM(nxgep->function_num); 5566495Sspeer nxgep->mac.portnum = portn; 5576495Sspeer if ((portn == 0) || (portn == 1)) 5586495Sspeer nxgep->mac.porttype = PORT_TYPE_XMAC; 5596495Sspeer else 5606495Sspeer nxgep->mac.porttype = PORT_TYPE_BMAC; 5616495Sspeer /* 5626495Sspeer * Neptune has 4 ports, the first 2 ports use XMAC (10G MAC) 5636495Sspeer * internally, the rest 2 ports use BMAC (1G "Big" MAC). 5646495Sspeer * The two types of MACs have different characterizations. 5656495Sspeer */ 5666495Sspeer mmac_info = &nxgep->nxge_mmac_info; 5676495Sspeer if (nxgep->function_num < 2) { 5686495Sspeer mmac_info->num_mmac = XMAC_MAX_ALT_ADDR_ENTRY; 5696495Sspeer mmac_info->naddrfree = XMAC_MAX_ALT_ADDR_ENTRY; 5706495Sspeer } else { 5716495Sspeer mmac_info->num_mmac = BMAC_MAX_ALT_ADDR_ENTRY; 5726495Sspeer mmac_info->naddrfree = BMAC_MAX_ALT_ADDR_ENTRY; 5736495Sspeer } 5743859Sml29623 } 5753859Sml29623 /* 5763859Sml29623 * Setup the Ndd parameters for the this instance. 5773859Sml29623 */ 5783859Sml29623 nxge_init_param(nxgep); 5793859Sml29623 5803859Sml29623 /* 5813859Sml29623 * Setup Register Tracing Buffer. 5823859Sml29623 */ 5833859Sml29623 npi_rtrace_buf_init((rtrace_t *)&npi_rtracebuf); 5843859Sml29623 5853859Sml29623 /* init stats ptr */ 5863859Sml29623 nxge_init_statsp(nxgep); 5874185Sspeer 5884977Sraghus /* 5896495Sspeer * Copy the vpd info from eeprom to a local data 5906495Sspeer * structure, and then check its validity. 5914977Sraghus */ 5926495Sspeer if (!isLDOMguest(nxgep)) { 5936495Sspeer int *regp; 5946495Sspeer uint_t reglen; 5956495Sspeer int rv; 5966495Sspeer 5976495Sspeer nxge_vpd_info_get(nxgep); 5986495Sspeer 5996495Sspeer /* Find the NIU config handle. */ 6006495Sspeer rv = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, 6016495Sspeer ddi_get_parent(nxgep->dip), DDI_PROP_DONTPASS, 6026495Sspeer "reg", ®p, ®len); 6036495Sspeer 6046495Sspeer if (rv != DDI_PROP_SUCCESS) { 6056495Sspeer goto nxge_attach_fail5; 6066495Sspeer } 6076495Sspeer /* 6086495Sspeer * The address_hi, that is the first int, in the reg 6096495Sspeer * property consists of config handle, but need to remove 6106495Sspeer * the bits 28-31 which are OBP specific info. 6116495Sspeer */ 6126495Sspeer nxgep->niu_cfg_hdl = (*regp) & 0xFFFFFFF; 6136495Sspeer ddi_prop_free(regp); 6146495Sspeer } 6156495Sspeer 6166495Sspeer if (isLDOMguest(nxgep)) { 6176495Sspeer uchar_t *prop_val; 6186495Sspeer uint_t prop_len; 6196495Sspeer 6206495Sspeer extern void nxge_get_logical_props(p_nxge_t); 6216495Sspeer 6226495Sspeer nxgep->statsp->mac_stats.xcvr_inuse = LOGICAL_XCVR; 6236495Sspeer nxgep->mac.portmode = PORT_LOGICAL; 6246495Sspeer (void) ddi_prop_update_string(DDI_DEV_T_NONE, nxgep->dip, 6256495Sspeer "phy-type", "virtual transceiver"); 6266495Sspeer 6276495Sspeer nxgep->nports = 1; 6286495Sspeer nxgep->board_ver = 0; /* XXX What? */ 6296495Sspeer 6306495Sspeer /* 6316495Sspeer * local-mac-address property gives us info on which 6326495Sspeer * specific MAC address the Hybrid resource is associated 6336495Sspeer * with. 6346495Sspeer */ 6356495Sspeer if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0, 6366495Sspeer "local-mac-address", &prop_val, 6376495Sspeer &prop_len) != DDI_PROP_SUCCESS) { 6386495Sspeer goto nxge_attach_fail5; 6396495Sspeer } 6406495Sspeer if (prop_len != ETHERADDRL) { 6416495Sspeer ddi_prop_free(prop_val); 6426495Sspeer goto nxge_attach_fail5; 6436495Sspeer } 6446495Sspeer ether_copy(prop_val, nxgep->hio_mac_addr); 6456495Sspeer ddi_prop_free(prop_val); 6466495Sspeer nxge_get_logical_props(nxgep); 6476495Sspeer 6486495Sspeer } else { 6496495Sspeer status = nxge_xcvr_find(nxgep); 6506495Sspeer 6516495Sspeer if (status != NXGE_OK) { 6526495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "nxge_attach: " 6536495Sspeer " Couldn't determine card type" 6546495Sspeer " .... exit ")); 6556495Sspeer goto nxge_attach_fail5; 6566495Sspeer } 6576495Sspeer 6586495Sspeer status = nxge_get_config_properties(nxgep); 6596495Sspeer 6606495Sspeer if (status != NXGE_OK) { 6616495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 6626495Sspeer "get_hw create failed")); 6636495Sspeer goto nxge_attach_fail; 6646495Sspeer } 6653859Sml29623 } 6663859Sml29623 6673859Sml29623 /* 6683859Sml29623 * Setup the Kstats for the driver. 6693859Sml29623 */ 6703859Sml29623 nxge_setup_kstats(nxgep); 6713859Sml29623 6726495Sspeer if (!isLDOMguest(nxgep)) 6736495Sspeer nxge_setup_param(nxgep); 6743859Sml29623 6753859Sml29623 status = nxge_setup_system_dma_pages(nxgep); 6763859Sml29623 if (status != NXGE_OK) { 6773859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "set dma page failed")); 6783859Sml29623 goto nxge_attach_fail; 6793859Sml29623 } 6803859Sml29623 6813859Sml29623 nxge_hw_id_init(nxgep); 6826495Sspeer 6836495Sspeer if (!isLDOMguest(nxgep)) 6846495Sspeer nxge_hw_init_niu_common(nxgep); 6853859Sml29623 6863859Sml29623 status = nxge_setup_mutexes(nxgep); 6873859Sml29623 if (status != NXGE_OK) { 6883859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "set mutex failed")); 6893859Sml29623 goto nxge_attach_fail; 6903859Sml29623 } 6913859Sml29623 6926495Sspeer #if defined(sun4v) 6936495Sspeer if (isLDOMguest(nxgep)) { 6946495Sspeer /* Find our VR & channel sets. */ 6956495Sspeer status = nxge_hio_vr_add(nxgep); 6966495Sspeer goto nxge_attach_exit; 6976495Sspeer } 6986495Sspeer #endif 6996495Sspeer 7003859Sml29623 status = nxge_setup_dev(nxgep); 7013859Sml29623 if (status != DDI_SUCCESS) { 7023859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "set dev failed")); 7033859Sml29623 goto nxge_attach_fail; 7043859Sml29623 } 7053859Sml29623 7063859Sml29623 status = nxge_add_intrs(nxgep); 7073859Sml29623 if (status != DDI_SUCCESS) { 7083859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "add_intr failed")); 7093859Sml29623 goto nxge_attach_fail; 7103859Sml29623 } 7113859Sml29623 status = nxge_add_soft_intrs(nxgep); 7123859Sml29623 if (status != DDI_SUCCESS) { 7136495Sspeer NXGE_DEBUG_MSG((nxgep, NXGE_ERR_CTL, 7146495Sspeer "add_soft_intr failed")); 7153859Sml29623 goto nxge_attach_fail; 7163859Sml29623 } 7173859Sml29623 7183859Sml29623 /* 7193859Sml29623 * Enable interrupts. 7203859Sml29623 */ 7213859Sml29623 nxge_intrs_enable(nxgep); 7223859Sml29623 7236495Sspeer // If a guest, register with vio_net instead. 7244977Sraghus if ((status = nxge_mac_register(nxgep)) != NXGE_OK) { 7253859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 7266495Sspeer "unable to register to mac layer (%d)", status)); 7273859Sml29623 goto nxge_attach_fail; 7283859Sml29623 } 7293859Sml29623 7303859Sml29623 mac_link_update(nxgep->mach, LINK_STATE_UNKNOWN); 7313859Sml29623 7326495Sspeer NXGE_DEBUG_MSG((nxgep, DDI_CTL, 7336495Sspeer "registered to mac (instance %d)", instance)); 7343859Sml29623 7353859Sml29623 (void) nxge_link_monitor(nxgep, LINK_MONITOR_START); 7363859Sml29623 7373859Sml29623 goto nxge_attach_exit; 7383859Sml29623 7393859Sml29623 nxge_attach_fail: 7403859Sml29623 nxge_unattach(nxgep); 7414977Sraghus goto nxge_attach_fail1; 7424977Sraghus 7434977Sraghus nxge_attach_fail5: 7444977Sraghus /* 7454977Sraghus * Tear down the ndd parameters setup. 7464977Sraghus */ 7474977Sraghus nxge_destroy_param(nxgep); 7484977Sraghus 7494977Sraghus /* 7504977Sraghus * Tear down the kstat setup. 7514977Sraghus */ 7524977Sraghus nxge_destroy_kstats(nxgep); 7534977Sraghus 7544977Sraghus nxge_attach_fail4: 7554977Sraghus if (nxgep->nxge_hw_p) { 7564977Sraghus nxge_uninit_common_dev(nxgep); 7574977Sraghus nxgep->nxge_hw_p = NULL; 7584977Sraghus } 7594977Sraghus 7604977Sraghus nxge_attach_fail3: 7614977Sraghus /* 7624977Sraghus * Unmap the register setup. 7634977Sraghus */ 7644977Sraghus nxge_unmap_regs(nxgep); 7654977Sraghus 7664977Sraghus nxge_fm_fini(nxgep); 7674977Sraghus 7684977Sraghus nxge_attach_fail2: 7694977Sraghus ddi_soft_state_free(nxge_list, nxgep->instance); 7704977Sraghus 7714977Sraghus nxge_attach_fail1: 7724185Sspeer if (status != NXGE_OK) 7734185Sspeer status = (NXGE_ERROR | NXGE_DDI_FAILED); 7743859Sml29623 nxgep = NULL; 7753859Sml29623 7763859Sml29623 nxge_attach_exit: 7773859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_attach status = 0x%08x", 7783859Sml29623 status)); 7793859Sml29623 7803859Sml29623 return (status); 7813859Sml29623 } 7823859Sml29623 7833859Sml29623 static int 7843859Sml29623 nxge_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) 7853859Sml29623 { 7863859Sml29623 int status = DDI_SUCCESS; 7873859Sml29623 int instance; 7883859Sml29623 p_nxge_t nxgep = NULL; 7893859Sml29623 7903859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_detach")); 7913859Sml29623 instance = ddi_get_instance(dip); 7923859Sml29623 nxgep = ddi_get_soft_state(nxge_list, instance); 7933859Sml29623 if (nxgep == NULL) { 7943859Sml29623 status = DDI_FAILURE; 7953859Sml29623 goto nxge_detach_exit; 7963859Sml29623 } 7973859Sml29623 7983859Sml29623 switch (cmd) { 7993859Sml29623 case DDI_DETACH: 8003859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "doing DDI_DETACH")); 8013859Sml29623 break; 8023859Sml29623 8033859Sml29623 case DDI_PM_SUSPEND: 8043859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "doing DDI_PM_SUSPEND")); 8053859Sml29623 nxgep->suspended = DDI_PM_SUSPEND; 8063859Sml29623 nxge_suspend(nxgep); 8073859Sml29623 break; 8083859Sml29623 8093859Sml29623 case DDI_SUSPEND: 8103859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "doing DDI_SUSPEND")); 8113859Sml29623 if (nxgep->suspended != DDI_PM_SUSPEND) { 8123859Sml29623 nxgep->suspended = DDI_SUSPEND; 8133859Sml29623 nxge_suspend(nxgep); 8143859Sml29623 } 8153859Sml29623 break; 8163859Sml29623 8173859Sml29623 default: 8183859Sml29623 status = DDI_FAILURE; 8193859Sml29623 } 8203859Sml29623 8213859Sml29623 if (cmd != DDI_DETACH) 8223859Sml29623 goto nxge_detach_exit; 8233859Sml29623 8243859Sml29623 /* 8253859Sml29623 * Stop the xcvr polling. 8263859Sml29623 */ 8273859Sml29623 nxgep->suspended = cmd; 8283859Sml29623 8293859Sml29623 (void) nxge_link_monitor(nxgep, LINK_MONITOR_STOP); 8303859Sml29623 8316495Sspeer if (isLDOMguest(nxgep)) { 8326495Sspeer nxge_hio_unregister(nxgep); 8336495Sspeer } else if (nxgep->mach && (status = mac_unregister(nxgep->mach)) != 0) { 8343859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 8353859Sml29623 "<== nxge_detach status = 0x%08X", status)); 8363859Sml29623 return (DDI_FAILURE); 8373859Sml29623 } 8383859Sml29623 8393859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 8403859Sml29623 "<== nxge_detach (mac_unregister) status = 0x%08X", status)); 8413859Sml29623 8423859Sml29623 nxge_unattach(nxgep); 8433859Sml29623 nxgep = NULL; 8443859Sml29623 8453859Sml29623 nxge_detach_exit: 8463859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_detach status = 0x%08X", 8473859Sml29623 status)); 8483859Sml29623 8493859Sml29623 return (status); 8503859Sml29623 } 8513859Sml29623 8523859Sml29623 static void 8533859Sml29623 nxge_unattach(p_nxge_t nxgep) 8543859Sml29623 { 8553859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_unattach")); 8563859Sml29623 8573859Sml29623 if (nxgep == NULL || nxgep->dev_regs == NULL) { 8583859Sml29623 return; 8593859Sml29623 } 8603859Sml29623 8614693Stm144005 nxgep->nxge_magic = 0; 8624693Stm144005 8635780Ssbehera if (nxgep->nxge_timerid) { 8645780Ssbehera nxge_stop_timer(nxgep, nxgep->nxge_timerid); 8655780Ssbehera nxgep->nxge_timerid = 0; 8665780Ssbehera } 8675780Ssbehera 8686495Sspeer #if defined(sun4v) 8696495Sspeer if (isLDOMguest(nxgep)) { 870*6498Sspeer (void) nxge_hio_vr_release(nxgep); 8716495Sspeer } 8726495Sspeer #endif 8736495Sspeer 8743859Sml29623 if (nxgep->nxge_hw_p) { 8753859Sml29623 nxge_uninit_common_dev(nxgep); 8763859Sml29623 nxgep->nxge_hw_p = NULL; 8773859Sml29623 } 8783859Sml29623 8793859Sml29623 #if defined(sun4v) 8803859Sml29623 if (nxgep->niu_type == N2_NIU && nxgep->niu_hsvc_available == B_TRUE) { 8813859Sml29623 (void) hsvc_unregister(&nxgep->niu_hsvc); 8823859Sml29623 nxgep->niu_hsvc_available = B_FALSE; 8833859Sml29623 } 8843859Sml29623 #endif 8853859Sml29623 /* 8863859Sml29623 * Stop any further interrupts. 8873859Sml29623 */ 8883859Sml29623 nxge_remove_intrs(nxgep); 8893859Sml29623 8903859Sml29623 /* remove soft interrups */ 8913859Sml29623 nxge_remove_soft_intrs(nxgep); 8923859Sml29623 8933859Sml29623 /* 8943859Sml29623 * Stop the device and free resources. 8953859Sml29623 */ 8966495Sspeer if (!isLDOMguest(nxgep)) { 8976495Sspeer nxge_destroy_dev(nxgep); 8986495Sspeer } 8993859Sml29623 9003859Sml29623 /* 9013859Sml29623 * Tear down the ndd parameters setup. 9023859Sml29623 */ 9033859Sml29623 nxge_destroy_param(nxgep); 9043859Sml29623 9053859Sml29623 /* 9063859Sml29623 * Tear down the kstat setup. 9073859Sml29623 */ 9083859Sml29623 nxge_destroy_kstats(nxgep); 9093859Sml29623 9103859Sml29623 /* 9113859Sml29623 * Destroy all mutexes. 9123859Sml29623 */ 9133859Sml29623 nxge_destroy_mutexes(nxgep); 9143859Sml29623 9153859Sml29623 /* 9163859Sml29623 * Remove the list of ndd parameters which 9173859Sml29623 * were setup during attach. 9183859Sml29623 */ 9193859Sml29623 if (nxgep->dip) { 9203859Sml29623 NXGE_DEBUG_MSG((nxgep, OBP_CTL, 9213859Sml29623 " nxge_unattach: remove all properties")); 9223859Sml29623 9233859Sml29623 (void) ddi_prop_remove_all(nxgep->dip); 9243859Sml29623 } 9253859Sml29623 9263859Sml29623 #if NXGE_PROPERTY 9273859Sml29623 nxge_remove_hard_properties(nxgep); 9283859Sml29623 #endif 9293859Sml29623 9303859Sml29623 /* 9313859Sml29623 * Unmap the register setup. 9323859Sml29623 */ 9333859Sml29623 nxge_unmap_regs(nxgep); 9343859Sml29623 9353859Sml29623 nxge_fm_fini(nxgep); 9363859Sml29623 9373859Sml29623 ddi_soft_state_free(nxge_list, nxgep->instance); 9383859Sml29623 9393859Sml29623 NXGE_DEBUG_MSG((NULL, DDI_CTL, "<== nxge_unattach")); 9403859Sml29623 } 9413859Sml29623 9426495Sspeer #if defined(sun4v) 9436495Sspeer int 9446495Sspeer nxge_hsvc_register( 9456495Sspeer nxge_t *nxgep) 9466495Sspeer { 9476495Sspeer nxge_status_t status; 9486495Sspeer 9496495Sspeer if (nxgep->niu_type == N2_NIU) { 9506495Sspeer nxgep->niu_hsvc_available = B_FALSE; 9516495Sspeer bcopy(&niu_hsvc, &nxgep->niu_hsvc, sizeof (hsvc_info_t)); 9526495Sspeer if ((status = hsvc_register(&nxgep->niu_hsvc, 9536495Sspeer &nxgep->niu_min_ver)) != 0) { 9546495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 9556495Sspeer "nxge_attach: %s: cannot negotiate " 9566495Sspeer "hypervisor services revision %d group: 0x%lx " 9576495Sspeer "major: 0x%lx minor: 0x%lx errno: %d", 9586495Sspeer niu_hsvc.hsvc_modname, niu_hsvc.hsvc_rev, 9596495Sspeer niu_hsvc.hsvc_group, niu_hsvc.hsvc_major, 9606495Sspeer niu_hsvc.hsvc_minor, status)); 9616495Sspeer return (DDI_FAILURE); 9626495Sspeer } 9636495Sspeer nxgep->niu_hsvc_available = B_TRUE; 9646495Sspeer NXGE_DEBUG_MSG((nxgep, DDI_CTL, 9656495Sspeer "NIU Hypervisor service enabled")); 9666495Sspeer } 9676495Sspeer 9686495Sspeer return (DDI_SUCCESS); 9696495Sspeer } 9706495Sspeer #endif 9716495Sspeer 9723859Sml29623 static char n2_siu_name[] = "niu"; 9733859Sml29623 9743859Sml29623 static nxge_status_t 9753859Sml29623 nxge_map_regs(p_nxge_t nxgep) 9763859Sml29623 { 9773859Sml29623 int ddi_status = DDI_SUCCESS; 9783859Sml29623 p_dev_regs_t dev_regs; 9793859Sml29623 char buf[MAXPATHLEN + 1]; 9803859Sml29623 char *devname; 9813859Sml29623 #ifdef NXGE_DEBUG 9823859Sml29623 char *sysname; 9833859Sml29623 #endif 9843859Sml29623 off_t regsize; 9853859Sml29623 nxge_status_t status = NXGE_OK; 9863859Sml29623 #if !defined(_BIG_ENDIAN) 9873859Sml29623 off_t pci_offset; 9883859Sml29623 uint16_t pcie_devctl; 9893859Sml29623 #endif 9903859Sml29623 9916495Sspeer if (isLDOMguest(nxgep)) { 9926495Sspeer return (nxge_guest_regs_map(nxgep)); 9936495Sspeer } 9946495Sspeer 9953859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_map_regs")); 9963859Sml29623 nxgep->dev_regs = NULL; 9973859Sml29623 dev_regs = KMEM_ZALLOC(sizeof (dev_regs_t), KM_SLEEP); 9983859Sml29623 dev_regs->nxge_regh = NULL; 9993859Sml29623 dev_regs->nxge_pciregh = NULL; 10003859Sml29623 dev_regs->nxge_msix_regh = NULL; 10013859Sml29623 dev_regs->nxge_vir_regh = NULL; 10023859Sml29623 dev_regs->nxge_vir2_regh = NULL; 10034732Sdavemq nxgep->niu_type = NIU_TYPE_NONE; 10043859Sml29623 10053859Sml29623 devname = ddi_pathname(nxgep->dip, buf); 10063859Sml29623 ASSERT(strlen(devname) > 0); 10073859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 10083859Sml29623 "nxge_map_regs: pathname devname %s", devname)); 10093859Sml29623 10103859Sml29623 if (strstr(devname, n2_siu_name)) { 10113859Sml29623 /* N2/NIU */ 10123859Sml29623 nxgep->niu_type = N2_NIU; 10133859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 10143859Sml29623 "nxge_map_regs: N2/NIU devname %s", devname)); 10153859Sml29623 /* get function number */ 10163859Sml29623 nxgep->function_num = 10173859Sml29623 (devname[strlen(devname) -1] == '1' ? 1 : 0); 10183859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 10193859Sml29623 "nxge_map_regs: N2/NIU function number %d", 10203859Sml29623 nxgep->function_num)); 10213859Sml29623 } else { 10223859Sml29623 int *prop_val; 10233859Sml29623 uint_t prop_len; 10243859Sml29623 uint8_t func_num; 10253859Sml29623 10263859Sml29623 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 10273859Sml29623 0, "reg", 10283859Sml29623 &prop_val, &prop_len) != DDI_PROP_SUCCESS) { 10293859Sml29623 NXGE_DEBUG_MSG((nxgep, VPD_CTL, 10303859Sml29623 "Reg property not found")); 10313859Sml29623 ddi_status = DDI_FAILURE; 10323859Sml29623 goto nxge_map_regs_fail0; 10333859Sml29623 10343859Sml29623 } else { 10353859Sml29623 func_num = (prop_val[0] >> 8) & 0x7; 10363859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 10373859Sml29623 "Reg property found: fun # %d", 10383859Sml29623 func_num)); 10393859Sml29623 nxgep->function_num = func_num; 10406495Sspeer if (isLDOMguest(nxgep)) { 10416495Sspeer nxgep->function_num /= 2; 10426495Sspeer return (NXGE_OK); 10436495Sspeer } 10443859Sml29623 ddi_prop_free(prop_val); 10453859Sml29623 } 10463859Sml29623 } 10473859Sml29623 10483859Sml29623 switch (nxgep->niu_type) { 10493859Sml29623 default: 10503859Sml29623 (void) ddi_dev_regsize(nxgep->dip, 0, ®size); 10513859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 10523859Sml29623 "nxge_map_regs: pci config size 0x%x", regsize)); 10533859Sml29623 10543859Sml29623 ddi_status = ddi_regs_map_setup(nxgep->dip, 0, 10553859Sml29623 (caddr_t *)&(dev_regs->nxge_pciregp), 0, 0, 10563859Sml29623 &nxge_dev_reg_acc_attr, &dev_regs->nxge_pciregh); 10573859Sml29623 if (ddi_status != DDI_SUCCESS) { 10583859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 10593859Sml29623 "ddi_map_regs, nxge bus config regs failed")); 10603859Sml29623 goto nxge_map_regs_fail0; 10613859Sml29623 } 10623859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 10633859Sml29623 "nxge_map_reg: PCI config addr 0x%0llx " 10643859Sml29623 " handle 0x%0llx", dev_regs->nxge_pciregp, 10653859Sml29623 dev_regs->nxge_pciregh)); 10663859Sml29623 /* 10673859Sml29623 * IMP IMP 10683859Sml29623 * workaround for bit swapping bug in HW 10693859Sml29623 * which ends up in no-snoop = yes 10703859Sml29623 * resulting, in DMA not synched properly 10713859Sml29623 */ 10723859Sml29623 #if !defined(_BIG_ENDIAN) 10733859Sml29623 /* workarounds for x86 systems */ 10743859Sml29623 pci_offset = 0x80 + PCIE_DEVCTL; 10753859Sml29623 pcie_devctl = 0x0; 10763859Sml29623 pcie_devctl &= PCIE_DEVCTL_ENABLE_NO_SNOOP; 10773859Sml29623 pcie_devctl |= PCIE_DEVCTL_RO_EN; 10783859Sml29623 pci_config_put16(dev_regs->nxge_pciregh, pci_offset, 10793859Sml29623 pcie_devctl); 10803859Sml29623 #endif 10813859Sml29623 10823859Sml29623 (void) ddi_dev_regsize(nxgep->dip, 1, ®size); 10833859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 10843859Sml29623 "nxge_map_regs: pio size 0x%x", regsize)); 10853859Sml29623 /* set up the device mapped register */ 10863859Sml29623 ddi_status = ddi_regs_map_setup(nxgep->dip, 1, 10873859Sml29623 (caddr_t *)&(dev_regs->nxge_regp), 0, 0, 10883859Sml29623 &nxge_dev_reg_acc_attr, &dev_regs->nxge_regh); 10893859Sml29623 if (ddi_status != DDI_SUCCESS) { 10903859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 10913859Sml29623 "ddi_map_regs for Neptune global reg failed")); 10923859Sml29623 goto nxge_map_regs_fail1; 10933859Sml29623 } 10943859Sml29623 10953859Sml29623 /* set up the msi/msi-x mapped register */ 10963859Sml29623 (void) ddi_dev_regsize(nxgep->dip, 2, ®size); 10973859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 10983859Sml29623 "nxge_map_regs: msix size 0x%x", regsize)); 10993859Sml29623 ddi_status = ddi_regs_map_setup(nxgep->dip, 2, 11003859Sml29623 (caddr_t *)&(dev_regs->nxge_msix_regp), 0, 0, 11013859Sml29623 &nxge_dev_reg_acc_attr, &dev_regs->nxge_msix_regh); 11023859Sml29623 if (ddi_status != DDI_SUCCESS) { 11033859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 11043859Sml29623 "ddi_map_regs for msi reg failed")); 11053859Sml29623 goto nxge_map_regs_fail2; 11063859Sml29623 } 11073859Sml29623 11083859Sml29623 /* set up the vio region mapped register */ 11093859Sml29623 (void) ddi_dev_regsize(nxgep->dip, 3, ®size); 11103859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 11113859Sml29623 "nxge_map_regs: vio size 0x%x", regsize)); 11123859Sml29623 ddi_status = ddi_regs_map_setup(nxgep->dip, 3, 11133859Sml29623 (caddr_t *)&(dev_regs->nxge_vir_regp), 0, 0, 11143859Sml29623 &nxge_dev_reg_acc_attr, &dev_regs->nxge_vir_regh); 11153859Sml29623 11163859Sml29623 if (ddi_status != DDI_SUCCESS) { 11173859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 11183859Sml29623 "ddi_map_regs for nxge vio reg failed")); 11193859Sml29623 goto nxge_map_regs_fail3; 11203859Sml29623 } 11213859Sml29623 nxgep->dev_regs = dev_regs; 11223859Sml29623 11233859Sml29623 NPI_PCI_ACC_HANDLE_SET(nxgep, dev_regs->nxge_pciregh); 11243859Sml29623 NPI_PCI_ADD_HANDLE_SET(nxgep, 11253859Sml29623 (npi_reg_ptr_t)dev_regs->nxge_pciregp); 11263859Sml29623 NPI_MSI_ACC_HANDLE_SET(nxgep, dev_regs->nxge_msix_regh); 11273859Sml29623 NPI_MSI_ADD_HANDLE_SET(nxgep, 11283859Sml29623 (npi_reg_ptr_t)dev_regs->nxge_msix_regp); 11293859Sml29623 11303859Sml29623 NPI_ACC_HANDLE_SET(nxgep, dev_regs->nxge_regh); 11313859Sml29623 NPI_ADD_HANDLE_SET(nxgep, (npi_reg_ptr_t)dev_regs->nxge_regp); 11323859Sml29623 11333859Sml29623 NPI_REG_ACC_HANDLE_SET(nxgep, dev_regs->nxge_regh); 11343859Sml29623 NPI_REG_ADD_HANDLE_SET(nxgep, 11353859Sml29623 (npi_reg_ptr_t)dev_regs->nxge_regp); 11363859Sml29623 11373859Sml29623 NPI_VREG_ACC_HANDLE_SET(nxgep, dev_regs->nxge_vir_regh); 11383859Sml29623 NPI_VREG_ADD_HANDLE_SET(nxgep, 11393859Sml29623 (npi_reg_ptr_t)dev_regs->nxge_vir_regp); 11403859Sml29623 11413859Sml29623 break; 11423859Sml29623 11433859Sml29623 case N2_NIU: 11443859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "ddi_map_regs, NIU")); 11453859Sml29623 /* 11463859Sml29623 * Set up the device mapped register (FWARC 2006/556) 11473859Sml29623 * (changed back to 1: reg starts at 1!) 11483859Sml29623 */ 11493859Sml29623 (void) ddi_dev_regsize(nxgep->dip, 1, ®size); 11503859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 11513859Sml29623 "nxge_map_regs: dev size 0x%x", regsize)); 11523859Sml29623 ddi_status = ddi_regs_map_setup(nxgep->dip, 1, 11533859Sml29623 (caddr_t *)&(dev_regs->nxge_regp), 0, 0, 11543859Sml29623 &nxge_dev_reg_acc_attr, &dev_regs->nxge_regh); 11553859Sml29623 11563859Sml29623 if (ddi_status != DDI_SUCCESS) { 11573859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 11583859Sml29623 "ddi_map_regs for N2/NIU, global reg failed ")); 11593859Sml29623 goto nxge_map_regs_fail1; 11603859Sml29623 } 11613859Sml29623 11626495Sspeer /* set up the first vio region mapped register */ 11633859Sml29623 (void) ddi_dev_regsize(nxgep->dip, 2, ®size); 11643859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 11653859Sml29623 "nxge_map_regs: vio (1) size 0x%x", regsize)); 11663859Sml29623 ddi_status = ddi_regs_map_setup(nxgep->dip, 2, 11673859Sml29623 (caddr_t *)&(dev_regs->nxge_vir_regp), 0, 0, 11683859Sml29623 &nxge_dev_reg_acc_attr, &dev_regs->nxge_vir_regh); 11693859Sml29623 11703859Sml29623 if (ddi_status != DDI_SUCCESS) { 11713859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 11723859Sml29623 "ddi_map_regs for nxge vio reg failed")); 11733859Sml29623 goto nxge_map_regs_fail2; 11743859Sml29623 } 11756495Sspeer /* set up the second vio region mapped register */ 11763859Sml29623 (void) ddi_dev_regsize(nxgep->dip, 3, ®size); 11773859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 11783859Sml29623 "nxge_map_regs: vio (3) size 0x%x", regsize)); 11793859Sml29623 ddi_status = ddi_regs_map_setup(nxgep->dip, 3, 11803859Sml29623 (caddr_t *)&(dev_regs->nxge_vir2_regp), 0, 0, 11813859Sml29623 &nxge_dev_reg_acc_attr, &dev_regs->nxge_vir2_regh); 11823859Sml29623 11833859Sml29623 if (ddi_status != DDI_SUCCESS) { 11843859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 11853859Sml29623 "ddi_map_regs for nxge vio2 reg failed")); 11863859Sml29623 goto nxge_map_regs_fail3; 11873859Sml29623 } 11883859Sml29623 nxgep->dev_regs = dev_regs; 11893859Sml29623 11903859Sml29623 NPI_ACC_HANDLE_SET(nxgep, dev_regs->nxge_regh); 11913859Sml29623 NPI_ADD_HANDLE_SET(nxgep, (npi_reg_ptr_t)dev_regs->nxge_regp); 11923859Sml29623 11933859Sml29623 NPI_REG_ACC_HANDLE_SET(nxgep, dev_regs->nxge_regh); 11943859Sml29623 NPI_REG_ADD_HANDLE_SET(nxgep, 11953859Sml29623 (npi_reg_ptr_t)dev_regs->nxge_regp); 11963859Sml29623 11973859Sml29623 NPI_VREG_ACC_HANDLE_SET(nxgep, dev_regs->nxge_vir_regh); 11983859Sml29623 NPI_VREG_ADD_HANDLE_SET(nxgep, 11993859Sml29623 (npi_reg_ptr_t)dev_regs->nxge_vir_regp); 12003859Sml29623 12013859Sml29623 NPI_V2REG_ACC_HANDLE_SET(nxgep, dev_regs->nxge_vir2_regh); 12023859Sml29623 NPI_V2REG_ADD_HANDLE_SET(nxgep, 12033859Sml29623 (npi_reg_ptr_t)dev_regs->nxge_vir2_regp); 12043859Sml29623 12053859Sml29623 break; 12063859Sml29623 } 12073859Sml29623 12083859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "nxge_map_reg: hardware addr 0x%0llx " 12093859Sml29623 " handle 0x%0llx", dev_regs->nxge_regp, dev_regs->nxge_regh)); 12103859Sml29623 12113859Sml29623 goto nxge_map_regs_exit; 12123859Sml29623 nxge_map_regs_fail3: 12133859Sml29623 if (dev_regs->nxge_msix_regh) { 12143859Sml29623 ddi_regs_map_free(&dev_regs->nxge_msix_regh); 12153859Sml29623 } 12163859Sml29623 if (dev_regs->nxge_vir_regh) { 12173859Sml29623 ddi_regs_map_free(&dev_regs->nxge_regh); 12183859Sml29623 } 12193859Sml29623 nxge_map_regs_fail2: 12203859Sml29623 if (dev_regs->nxge_regh) { 12213859Sml29623 ddi_regs_map_free(&dev_regs->nxge_regh); 12223859Sml29623 } 12233859Sml29623 nxge_map_regs_fail1: 12243859Sml29623 if (dev_regs->nxge_pciregh) { 12253859Sml29623 ddi_regs_map_free(&dev_regs->nxge_pciregh); 12263859Sml29623 } 12273859Sml29623 nxge_map_regs_fail0: 12283859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "Freeing register set memory")); 12293859Sml29623 kmem_free(dev_regs, sizeof (dev_regs_t)); 12303859Sml29623 12313859Sml29623 nxge_map_regs_exit: 12323859Sml29623 if (ddi_status != DDI_SUCCESS) 12333859Sml29623 status |= (NXGE_ERROR | NXGE_DDI_FAILED); 12343859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_map_regs")); 12353859Sml29623 return (status); 12363859Sml29623 } 12373859Sml29623 12383859Sml29623 static void 12393859Sml29623 nxge_unmap_regs(p_nxge_t nxgep) 12403859Sml29623 { 12413859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_unmap_regs")); 12426495Sspeer 12436495Sspeer if (isLDOMguest(nxgep)) { 12446495Sspeer nxge_guest_regs_map_free(nxgep); 12456495Sspeer return; 12466495Sspeer } 12476495Sspeer 12483859Sml29623 if (nxgep->dev_regs) { 12493859Sml29623 if (nxgep->dev_regs->nxge_pciregh) { 12503859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 12513859Sml29623 "==> nxge_unmap_regs: bus")); 12523859Sml29623 ddi_regs_map_free(&nxgep->dev_regs->nxge_pciregh); 12533859Sml29623 nxgep->dev_regs->nxge_pciregh = NULL; 12543859Sml29623 } 12553859Sml29623 if (nxgep->dev_regs->nxge_regh) { 12563859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 12573859Sml29623 "==> nxge_unmap_regs: device registers")); 12583859Sml29623 ddi_regs_map_free(&nxgep->dev_regs->nxge_regh); 12593859Sml29623 nxgep->dev_regs->nxge_regh = NULL; 12603859Sml29623 } 12613859Sml29623 if (nxgep->dev_regs->nxge_msix_regh) { 12623859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 12633859Sml29623 "==> nxge_unmap_regs: device interrupts")); 12643859Sml29623 ddi_regs_map_free(&nxgep->dev_regs->nxge_msix_regh); 12653859Sml29623 nxgep->dev_regs->nxge_msix_regh = NULL; 12663859Sml29623 } 12673859Sml29623 if (nxgep->dev_regs->nxge_vir_regh) { 12683859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 12693859Sml29623 "==> nxge_unmap_regs: vio region")); 12703859Sml29623 ddi_regs_map_free(&nxgep->dev_regs->nxge_vir_regh); 12713859Sml29623 nxgep->dev_regs->nxge_vir_regh = NULL; 12723859Sml29623 } 12733859Sml29623 if (nxgep->dev_regs->nxge_vir2_regh) { 12743859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 12753859Sml29623 "==> nxge_unmap_regs: vio2 region")); 12763859Sml29623 ddi_regs_map_free(&nxgep->dev_regs->nxge_vir2_regh); 12773859Sml29623 nxgep->dev_regs->nxge_vir2_regh = NULL; 12783859Sml29623 } 12793859Sml29623 12803859Sml29623 kmem_free(nxgep->dev_regs, sizeof (dev_regs_t)); 12813859Sml29623 nxgep->dev_regs = NULL; 12823859Sml29623 } 12833859Sml29623 12843859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_unmap_regs")); 12853859Sml29623 } 12863859Sml29623 12873859Sml29623 static nxge_status_t 12883859Sml29623 nxge_setup_mutexes(p_nxge_t nxgep) 12893859Sml29623 { 12903859Sml29623 int ddi_status = DDI_SUCCESS; 12913859Sml29623 nxge_status_t status = NXGE_OK; 12923859Sml29623 nxge_classify_t *classify_ptr; 12933859Sml29623 int partition; 12943859Sml29623 12953859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_setup_mutexes")); 12963859Sml29623 12973859Sml29623 /* 12983859Sml29623 * Get the interrupt cookie so the mutexes can be 12993859Sml29623 * Initialized. 13003859Sml29623 */ 13016495Sspeer if (isLDOMguest(nxgep)) { 13026495Sspeer nxgep->interrupt_cookie = 0; 13036495Sspeer } else { 13046495Sspeer ddi_status = ddi_get_iblock_cookie(nxgep->dip, 0, 13056495Sspeer &nxgep->interrupt_cookie); 13066495Sspeer 13076495Sspeer if (ddi_status != DDI_SUCCESS) { 13086495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 13096495Sspeer "<== nxge_setup_mutexes: failed 0x%x", 13106495Sspeer ddi_status)); 13116495Sspeer goto nxge_setup_mutexes_exit; 13126495Sspeer } 13133859Sml29623 } 13143859Sml29623 13154693Stm144005 cv_init(&nxgep->poll_cv, NULL, CV_DRIVER, NULL); 13164693Stm144005 MUTEX_INIT(&nxgep->poll_lock, NULL, 13174693Stm144005 MUTEX_DRIVER, (void *)nxgep->interrupt_cookie); 13184693Stm144005 13193859Sml29623 /* 13204693Stm144005 * Initialize mutexes for this device. 13213859Sml29623 */ 13223859Sml29623 MUTEX_INIT(nxgep->genlock, NULL, 13233859Sml29623 MUTEX_DRIVER, (void *)nxgep->interrupt_cookie); 13243859Sml29623 MUTEX_INIT(&nxgep->ouraddr_lock, NULL, 13253859Sml29623 MUTEX_DRIVER, (void *)nxgep->interrupt_cookie); 13263859Sml29623 MUTEX_INIT(&nxgep->mif_lock, NULL, 13273859Sml29623 MUTEX_DRIVER, (void *)nxgep->interrupt_cookie); 13286495Sspeer MUTEX_INIT(&nxgep->group_lock, NULL, 13296495Sspeer MUTEX_DRIVER, (void *)nxgep->interrupt_cookie); 13303859Sml29623 RW_INIT(&nxgep->filter_lock, NULL, 13313859Sml29623 RW_DRIVER, (void *)nxgep->interrupt_cookie); 13323859Sml29623 13333859Sml29623 classify_ptr = &nxgep->classifier; 13343859Sml29623 /* 13353859Sml29623 * FFLP Mutexes are never used in interrupt context 13363859Sml29623 * as fflp operation can take very long time to 13373859Sml29623 * complete and hence not suitable to invoke from interrupt 13383859Sml29623 * handlers. 13393859Sml29623 */ 13403859Sml29623 MUTEX_INIT(&classify_ptr->tcam_lock, NULL, 13414732Sdavemq NXGE_MUTEX_DRIVER, (void *)nxgep->interrupt_cookie); 13424977Sraghus if (NXGE_IS_VALID_NEPTUNE_TYPE(nxgep)) { 13433859Sml29623 MUTEX_INIT(&classify_ptr->fcram_lock, NULL, 13444732Sdavemq NXGE_MUTEX_DRIVER, (void *)nxgep->interrupt_cookie); 13453859Sml29623 for (partition = 0; partition < MAX_PARTITION; partition++) { 13463859Sml29623 MUTEX_INIT(&classify_ptr->hash_lock[partition], NULL, 13473859Sml29623 NXGE_MUTEX_DRIVER, (void *)nxgep->interrupt_cookie); 13483859Sml29623 } 13493859Sml29623 } 13503859Sml29623 13513859Sml29623 nxge_setup_mutexes_exit: 13523859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 13534732Sdavemq "<== nxge_setup_mutexes status = %x", status)); 13543859Sml29623 13553859Sml29623 if (ddi_status != DDI_SUCCESS) 13563859Sml29623 status |= (NXGE_ERROR | NXGE_DDI_FAILED); 13573859Sml29623 13583859Sml29623 return (status); 13593859Sml29623 } 13603859Sml29623 13613859Sml29623 static void 13623859Sml29623 nxge_destroy_mutexes(p_nxge_t nxgep) 13633859Sml29623 { 13643859Sml29623 int partition; 13653859Sml29623 nxge_classify_t *classify_ptr; 13663859Sml29623 13673859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_destroy_mutexes")); 13683859Sml29623 RW_DESTROY(&nxgep->filter_lock); 13696495Sspeer MUTEX_DESTROY(&nxgep->group_lock); 13703859Sml29623 MUTEX_DESTROY(&nxgep->mif_lock); 13713859Sml29623 MUTEX_DESTROY(&nxgep->ouraddr_lock); 13723859Sml29623 MUTEX_DESTROY(nxgep->genlock); 13733859Sml29623 13743859Sml29623 classify_ptr = &nxgep->classifier; 13753859Sml29623 MUTEX_DESTROY(&classify_ptr->tcam_lock); 13763859Sml29623 13774693Stm144005 /* Destroy all polling resources. */ 13784693Stm144005 MUTEX_DESTROY(&nxgep->poll_lock); 13794693Stm144005 cv_destroy(&nxgep->poll_cv); 13804693Stm144005 13814693Stm144005 /* free data structures, based on HW type */ 13824977Sraghus if (NXGE_IS_VALID_NEPTUNE_TYPE(nxgep)) { 13833859Sml29623 MUTEX_DESTROY(&classify_ptr->fcram_lock); 13843859Sml29623 for (partition = 0; partition < MAX_PARTITION; partition++) { 13853859Sml29623 MUTEX_DESTROY(&classify_ptr->hash_lock[partition]); 13863859Sml29623 } 13873859Sml29623 } 13883859Sml29623 13893859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_destroy_mutexes")); 13903859Sml29623 } 13913859Sml29623 13923859Sml29623 nxge_status_t 13933859Sml29623 nxge_init(p_nxge_t nxgep) 13943859Sml29623 { 13956495Sspeer nxge_status_t status = NXGE_OK; 13963859Sml29623 13973859Sml29623 NXGE_DEBUG_MSG((nxgep, STR_CTL, "==> nxge_init")); 13983859Sml29623 13993859Sml29623 if (nxgep->drv_state & STATE_HW_INITIALIZED) { 14003859Sml29623 return (status); 14013859Sml29623 } 14023859Sml29623 14033859Sml29623 /* 14043859Sml29623 * Allocate system memory for the receive/transmit buffer blocks 14053859Sml29623 * and receive/transmit descriptor rings. 14063859Sml29623 */ 14073859Sml29623 status = nxge_alloc_mem_pool(nxgep); 14083859Sml29623 if (status != NXGE_OK) { 14093859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "alloc mem failed\n")); 14103859Sml29623 goto nxge_init_fail1; 14113859Sml29623 } 14123859Sml29623 14136495Sspeer if (!isLDOMguest(nxgep)) { 14146495Sspeer /* 14156495Sspeer * Initialize and enable the TXC registers. 14166495Sspeer * (Globally enable the Tx controller, 14176495Sspeer * enable the port, configure the dma channel bitmap, 14186495Sspeer * configure the max burst size). 14196495Sspeer */ 14206495Sspeer status = nxge_txc_init(nxgep); 14216495Sspeer if (status != NXGE_OK) { 14226495Sspeer NXGE_ERROR_MSG((nxgep, 14236495Sspeer NXGE_ERR_CTL, "init txc failed\n")); 14246495Sspeer goto nxge_init_fail2; 14256495Sspeer } 14263859Sml29623 } 14273859Sml29623 14283859Sml29623 /* 14293859Sml29623 * Initialize and enable TXDMA channels. 14303859Sml29623 */ 14313859Sml29623 status = nxge_init_txdma_channels(nxgep); 14323859Sml29623 if (status != NXGE_OK) { 14333859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "init txdma failed\n")); 14343859Sml29623 goto nxge_init_fail3; 14353859Sml29623 } 14363859Sml29623 14373859Sml29623 /* 14383859Sml29623 * Initialize and enable RXDMA channels. 14393859Sml29623 */ 14403859Sml29623 status = nxge_init_rxdma_channels(nxgep); 14413859Sml29623 if (status != NXGE_OK) { 14423859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "init rxdma failed\n")); 14433859Sml29623 goto nxge_init_fail4; 14443859Sml29623 } 14453859Sml29623 14463859Sml29623 /* 14476495Sspeer * The guest domain is now done. 14486495Sspeer */ 14496495Sspeer if (isLDOMguest(nxgep)) { 14506495Sspeer nxgep->drv_state |= STATE_HW_INITIALIZED; 14516495Sspeer goto nxge_init_exit; 14526495Sspeer } 14536495Sspeer 14546495Sspeer /* 14553859Sml29623 * Initialize TCAM and FCRAM (Neptune). 14563859Sml29623 */ 14573859Sml29623 status = nxge_classify_init(nxgep); 14583859Sml29623 if (status != NXGE_OK) { 14593859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "init classify failed\n")); 14603859Sml29623 goto nxge_init_fail5; 14613859Sml29623 } 14623859Sml29623 14633859Sml29623 /* 14643859Sml29623 * Initialize ZCP 14653859Sml29623 */ 14663859Sml29623 status = nxge_zcp_init(nxgep); 14673859Sml29623 if (status != NXGE_OK) { 14683859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "init ZCP failed\n")); 14693859Sml29623 goto nxge_init_fail5; 14703859Sml29623 } 14713859Sml29623 14723859Sml29623 /* 14733859Sml29623 * Initialize IPP. 14743859Sml29623 */ 14753859Sml29623 status = nxge_ipp_init(nxgep); 14763859Sml29623 if (status != NXGE_OK) { 14773859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "init IPP failed\n")); 14783859Sml29623 goto nxge_init_fail5; 14793859Sml29623 } 14803859Sml29623 14813859Sml29623 /* 14823859Sml29623 * Initialize the MAC block. 14833859Sml29623 */ 14843859Sml29623 status = nxge_mac_init(nxgep); 14853859Sml29623 if (status != NXGE_OK) { 14863859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "init MAC failed\n")); 14873859Sml29623 goto nxge_init_fail5; 14883859Sml29623 } 14893859Sml29623 14906495Sspeer nxge_intrs_enable(nxgep); /* XXX What changes do I need to make here? */ 14913859Sml29623 14923859Sml29623 /* 14933859Sml29623 * Enable hardware interrupts. 14943859Sml29623 */ 14953859Sml29623 nxge_intr_hw_enable(nxgep); 14963859Sml29623 nxgep->drv_state |= STATE_HW_INITIALIZED; 14973859Sml29623 14983859Sml29623 goto nxge_init_exit; 14993859Sml29623 15003859Sml29623 nxge_init_fail5: 15013859Sml29623 nxge_uninit_rxdma_channels(nxgep); 15023859Sml29623 nxge_init_fail4: 15033859Sml29623 nxge_uninit_txdma_channels(nxgep); 15043859Sml29623 nxge_init_fail3: 15056495Sspeer if (!isLDOMguest(nxgep)) { 15066495Sspeer (void) nxge_txc_uninit(nxgep); 15076495Sspeer } 15083859Sml29623 nxge_init_fail2: 15093859Sml29623 nxge_free_mem_pool(nxgep); 15103859Sml29623 nxge_init_fail1: 15113859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 15123859Sml29623 "<== nxge_init status (failed) = 0x%08x", status)); 15133859Sml29623 return (status); 15143859Sml29623 15153859Sml29623 nxge_init_exit: 15163859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_init status = 0x%08x", 15173859Sml29623 status)); 15183859Sml29623 return (status); 15193859Sml29623 } 15203859Sml29623 15213859Sml29623 15223859Sml29623 timeout_id_t 15233859Sml29623 nxge_start_timer(p_nxge_t nxgep, fptrv_t func, int msec) 15243859Sml29623 { 15253859Sml29623 if ((nxgep->suspended == 0) || 15263859Sml29623 (nxgep->suspended == DDI_RESUME)) { 15273859Sml29623 return (timeout(func, (caddr_t)nxgep, 15283859Sml29623 drv_usectohz(1000 * msec))); 15293859Sml29623 } 15303859Sml29623 return (NULL); 15313859Sml29623 } 15323859Sml29623 15333859Sml29623 /*ARGSUSED*/ 15343859Sml29623 void 15353859Sml29623 nxge_stop_timer(p_nxge_t nxgep, timeout_id_t timerid) 15363859Sml29623 { 15373859Sml29623 if (timerid) { 15383859Sml29623 (void) untimeout(timerid); 15393859Sml29623 } 15403859Sml29623 } 15413859Sml29623 15423859Sml29623 void 15433859Sml29623 nxge_uninit(p_nxge_t nxgep) 15443859Sml29623 { 15453859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_uninit")); 15463859Sml29623 15473859Sml29623 if (!(nxgep->drv_state & STATE_HW_INITIALIZED)) { 15483859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 15493859Sml29623 "==> nxge_uninit: not initialized")); 15503859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 15513859Sml29623 "<== nxge_uninit")); 15523859Sml29623 return; 15533859Sml29623 } 15543859Sml29623 15553859Sml29623 /* stop timer */ 15563859Sml29623 if (nxgep->nxge_timerid) { 15573859Sml29623 nxge_stop_timer(nxgep, nxgep->nxge_timerid); 15583859Sml29623 nxgep->nxge_timerid = 0; 15593859Sml29623 } 15603859Sml29623 15613859Sml29623 (void) nxge_link_monitor(nxgep, LINK_MONITOR_STOP); 15623859Sml29623 (void) nxge_intr_hw_disable(nxgep); 15633859Sml29623 15643859Sml29623 /* 15653859Sml29623 * Reset the receive MAC side. 15663859Sml29623 */ 15673859Sml29623 (void) nxge_rx_mac_disable(nxgep); 15683859Sml29623 15693859Sml29623 /* Disable and soft reset the IPP */ 15706495Sspeer if (!isLDOMguest(nxgep)) 15716495Sspeer (void) nxge_ipp_disable(nxgep); 15723859Sml29623 15733859Sml29623 /* Free classification resources */ 15743859Sml29623 (void) nxge_classify_uninit(nxgep); 15753859Sml29623 15763859Sml29623 /* 15773859Sml29623 * Reset the transmit/receive DMA side. 15783859Sml29623 */ 15793859Sml29623 (void) nxge_txdma_hw_mode(nxgep, NXGE_DMA_STOP); 15803859Sml29623 (void) nxge_rxdma_hw_mode(nxgep, NXGE_DMA_STOP); 15813859Sml29623 15823859Sml29623 nxge_uninit_txdma_channels(nxgep); 15833859Sml29623 nxge_uninit_rxdma_channels(nxgep); 15843859Sml29623 15853859Sml29623 /* 15863859Sml29623 * Reset the transmit MAC side. 15873859Sml29623 */ 15883859Sml29623 (void) nxge_tx_mac_disable(nxgep); 15893859Sml29623 15903859Sml29623 nxge_free_mem_pool(nxgep); 15913859Sml29623 15923859Sml29623 (void) nxge_link_monitor(nxgep, LINK_MONITOR_START); 15933859Sml29623 15943859Sml29623 nxgep->drv_state &= ~STATE_HW_INITIALIZED; 15953859Sml29623 15963859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_uninit: " 15973859Sml29623 "nxge_mblks_pending %d", nxge_mblks_pending)); 15983859Sml29623 } 15993859Sml29623 16003859Sml29623 void 16013859Sml29623 nxge_get64(p_nxge_t nxgep, p_mblk_t mp) 16023859Sml29623 { 16035125Sjoycey #if defined(__i386) 16045125Sjoycey size_t reg; 16055125Sjoycey #else 16063859Sml29623 uint64_t reg; 16075125Sjoycey #endif 16083859Sml29623 uint64_t regdata; 16093859Sml29623 int i, retry; 16103859Sml29623 16113859Sml29623 bcopy((char *)mp->b_rptr, (char *)®, sizeof (uint64_t)); 16123859Sml29623 regdata = 0; 16133859Sml29623 retry = 1; 16143859Sml29623 16153859Sml29623 for (i = 0; i < retry; i++) { 16163859Sml29623 NXGE_REG_RD64(nxgep->npi_handle, reg, ®data); 16173859Sml29623 } 16183859Sml29623 bcopy((char *)®data, (char *)mp->b_rptr, sizeof (uint64_t)); 16193859Sml29623 } 16203859Sml29623 16213859Sml29623 void 16223859Sml29623 nxge_put64(p_nxge_t nxgep, p_mblk_t mp) 16233859Sml29623 { 16245125Sjoycey #if defined(__i386) 16255125Sjoycey size_t reg; 16265125Sjoycey #else 16273859Sml29623 uint64_t reg; 16285125Sjoycey #endif 16293859Sml29623 uint64_t buf[2]; 16303859Sml29623 16313859Sml29623 bcopy((char *)mp->b_rptr, (char *)&buf[0], 2 * sizeof (uint64_t)); 16325133Sjoycey #if defined(__i386) 16335133Sjoycey reg = (size_t)buf[0]; 16345133Sjoycey #else 16353859Sml29623 reg = buf[0]; 16365133Sjoycey #endif 16373859Sml29623 16383859Sml29623 NXGE_NPI_PIO_WRITE64(nxgep->npi_handle, reg, buf[1]); 16393859Sml29623 } 16403859Sml29623 16413859Sml29623 16423859Sml29623 nxge_os_mutex_t nxgedebuglock; 16433859Sml29623 int nxge_debug_init = 0; 16443859Sml29623 16453859Sml29623 /*ARGSUSED*/ 16463859Sml29623 /*VARARGS*/ 16473859Sml29623 void 16483859Sml29623 nxge_debug_msg(p_nxge_t nxgep, uint64_t level, char *fmt, ...) 16493859Sml29623 { 16503859Sml29623 char msg_buffer[1048]; 16513859Sml29623 char prefix_buffer[32]; 16523859Sml29623 int instance; 16533859Sml29623 uint64_t debug_level; 16543859Sml29623 int cmn_level = CE_CONT; 16553859Sml29623 va_list ap; 16563859Sml29623 16576495Sspeer if (nxgep && nxgep->nxge_debug_level != nxge_debug_level) { 16586495Sspeer /* In case a developer has changed nxge_debug_level. */ 16596495Sspeer if (nxgep->nxge_debug_level != nxge_debug_level) 16606495Sspeer nxgep->nxge_debug_level = nxge_debug_level; 16616495Sspeer } 16626495Sspeer 16633859Sml29623 debug_level = (nxgep == NULL) ? nxge_debug_level : 16643859Sml29623 nxgep->nxge_debug_level; 16653859Sml29623 16663859Sml29623 if ((level & debug_level) || 16673859Sml29623 (level == NXGE_NOTE) || 16683859Sml29623 (level == NXGE_ERR_CTL)) { 16693859Sml29623 /* do the msg processing */ 16703859Sml29623 if (nxge_debug_init == 0) { 16713859Sml29623 MUTEX_INIT(&nxgedebuglock, NULL, MUTEX_DRIVER, NULL); 16723859Sml29623 nxge_debug_init = 1; 16733859Sml29623 } 16743859Sml29623 16753859Sml29623 MUTEX_ENTER(&nxgedebuglock); 16763859Sml29623 16773859Sml29623 if ((level & NXGE_NOTE)) { 16783859Sml29623 cmn_level = CE_NOTE; 16793859Sml29623 } 16803859Sml29623 16813859Sml29623 if (level & NXGE_ERR_CTL) { 16823859Sml29623 cmn_level = CE_WARN; 16833859Sml29623 } 16843859Sml29623 16853859Sml29623 va_start(ap, fmt); 16863859Sml29623 (void) vsprintf(msg_buffer, fmt, ap); 16873859Sml29623 va_end(ap); 16883859Sml29623 if (nxgep == NULL) { 16893859Sml29623 instance = -1; 16903859Sml29623 (void) sprintf(prefix_buffer, "%s :", "nxge"); 16913859Sml29623 } else { 16923859Sml29623 instance = nxgep->instance; 16933859Sml29623 (void) sprintf(prefix_buffer, 16943859Sml29623 "%s%d :", "nxge", instance); 16953859Sml29623 } 16963859Sml29623 16973859Sml29623 MUTEX_EXIT(&nxgedebuglock); 16983859Sml29623 cmn_err(cmn_level, "!%s %s\n", 16993859Sml29623 prefix_buffer, msg_buffer); 17003859Sml29623 17013859Sml29623 } 17023859Sml29623 } 17033859Sml29623 17043859Sml29623 char * 17053859Sml29623 nxge_dump_packet(char *addr, int size) 17063859Sml29623 { 17073859Sml29623 uchar_t *ap = (uchar_t *)addr; 17083859Sml29623 int i; 17093859Sml29623 static char etherbuf[1024]; 17103859Sml29623 char *cp = etherbuf; 17113859Sml29623 char digits[] = "0123456789abcdef"; 17123859Sml29623 17133859Sml29623 if (!size) 17143859Sml29623 size = 60; 17153859Sml29623 17163859Sml29623 if (size > MAX_DUMP_SZ) { 17173859Sml29623 /* Dump the leading bytes */ 17183859Sml29623 for (i = 0; i < MAX_DUMP_SZ/2; i++) { 17193859Sml29623 if (*ap > 0x0f) 17203859Sml29623 *cp++ = digits[*ap >> 4]; 17213859Sml29623 *cp++ = digits[*ap++ & 0xf]; 17223859Sml29623 *cp++ = ':'; 17233859Sml29623 } 17243859Sml29623 for (i = 0; i < 20; i++) 17253859Sml29623 *cp++ = '.'; 17263859Sml29623 /* Dump the last MAX_DUMP_SZ/2 bytes */ 17273859Sml29623 ap = (uchar_t *)(addr + (size - MAX_DUMP_SZ/2)); 17283859Sml29623 for (i = 0; i < MAX_DUMP_SZ/2; i++) { 17293859Sml29623 if (*ap > 0x0f) 17303859Sml29623 *cp++ = digits[*ap >> 4]; 17313859Sml29623 *cp++ = digits[*ap++ & 0xf]; 17323859Sml29623 *cp++ = ':'; 17333859Sml29623 } 17343859Sml29623 } else { 17353859Sml29623 for (i = 0; i < size; i++) { 17363859Sml29623 if (*ap > 0x0f) 17373859Sml29623 *cp++ = digits[*ap >> 4]; 17383859Sml29623 *cp++ = digits[*ap++ & 0xf]; 17393859Sml29623 *cp++ = ':'; 17403859Sml29623 } 17413859Sml29623 } 17423859Sml29623 *--cp = 0; 17433859Sml29623 return (etherbuf); 17443859Sml29623 } 17453859Sml29623 17463859Sml29623 #ifdef NXGE_DEBUG 17473859Sml29623 static void 17483859Sml29623 nxge_test_map_regs(p_nxge_t nxgep) 17493859Sml29623 { 17503859Sml29623 ddi_acc_handle_t cfg_handle; 17513859Sml29623 p_pci_cfg_t cfg_ptr; 17523859Sml29623 ddi_acc_handle_t dev_handle; 17533859Sml29623 char *dev_ptr; 17543859Sml29623 ddi_acc_handle_t pci_config_handle; 17553859Sml29623 uint32_t regval; 17563859Sml29623 int i; 17573859Sml29623 17583859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_test_map_regs")); 17593859Sml29623 17603859Sml29623 dev_handle = nxgep->dev_regs->nxge_regh; 17613859Sml29623 dev_ptr = (char *)nxgep->dev_regs->nxge_regp; 17623859Sml29623 17634977Sraghus if (NXGE_IS_VALID_NEPTUNE_TYPE(nxgep)) { 17643859Sml29623 cfg_handle = nxgep->dev_regs->nxge_pciregh; 17653859Sml29623 cfg_ptr = (void *)nxgep->dev_regs->nxge_pciregp; 17663859Sml29623 17673859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 17684732Sdavemq "Neptune PCI regp cfg_ptr 0x%llx", (char *)cfg_ptr)); 17693859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 17704732Sdavemq "Neptune PCI cfg_ptr vendor id ptr 0x%llx", 17714732Sdavemq &cfg_ptr->vendorid)); 17723859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 17734732Sdavemq "\tvendorid 0x%x devid 0x%x", 17744732Sdavemq NXGE_PIO_READ16(cfg_handle, &cfg_ptr->vendorid, 0), 17754732Sdavemq NXGE_PIO_READ16(cfg_handle, &cfg_ptr->devid, 0))); 17763859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 17774732Sdavemq "PCI BAR: base 0x%x base14 0x%x base 18 0x%x " 17784732Sdavemq "bar1c 0x%x", 17794732Sdavemq NXGE_PIO_READ32(cfg_handle, &cfg_ptr->base, 0), 17804732Sdavemq NXGE_PIO_READ32(cfg_handle, &cfg_ptr->base14, 0), 17814732Sdavemq NXGE_PIO_READ32(cfg_handle, &cfg_ptr->base18, 0), 17824732Sdavemq NXGE_PIO_READ32(cfg_handle, &cfg_ptr->base1c, 0))); 17833859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 17844732Sdavemq "\nNeptune PCI BAR: base20 0x%x base24 0x%x " 17854732Sdavemq "base 28 0x%x bar2c 0x%x\n", 17864732Sdavemq NXGE_PIO_READ32(cfg_handle, &cfg_ptr->base20, 0), 17874732Sdavemq NXGE_PIO_READ32(cfg_handle, &cfg_ptr->base24, 0), 17884732Sdavemq NXGE_PIO_READ32(cfg_handle, &cfg_ptr->base28, 0), 17894732Sdavemq NXGE_PIO_READ32(cfg_handle, &cfg_ptr->base2c, 0))); 17903859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 17914732Sdavemq "\nNeptune PCI BAR: base30 0x%x\n", 17924732Sdavemq NXGE_PIO_READ32(cfg_handle, &cfg_ptr->base30, 0))); 17933859Sml29623 17943859Sml29623 cfg_handle = nxgep->dev_regs->nxge_pciregh; 17953859Sml29623 cfg_ptr = (void *)nxgep->dev_regs->nxge_pciregp; 17963859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 17974732Sdavemq "first 0x%llx second 0x%llx third 0x%llx " 17984732Sdavemq "last 0x%llx ", 17994732Sdavemq NXGE_PIO_READ64(dev_handle, 18004732Sdavemq (uint64_t *)(dev_ptr + 0), 0), 18014732Sdavemq NXGE_PIO_READ64(dev_handle, 18024732Sdavemq (uint64_t *)(dev_ptr + 8), 0), 18034732Sdavemq NXGE_PIO_READ64(dev_handle, 18044732Sdavemq (uint64_t *)(dev_ptr + 16), 0), 18054732Sdavemq NXGE_PIO_READ64(cfg_handle, 18064732Sdavemq (uint64_t *)(dev_ptr + 24), 0))); 18073859Sml29623 } 18083859Sml29623 } 18093859Sml29623 18103859Sml29623 #endif 18113859Sml29623 18123859Sml29623 static void 18133859Sml29623 nxge_suspend(p_nxge_t nxgep) 18143859Sml29623 { 18153859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_suspend")); 18163859Sml29623 18173859Sml29623 nxge_intrs_disable(nxgep); 18183859Sml29623 nxge_destroy_dev(nxgep); 18193859Sml29623 18203859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_suspend")); 18213859Sml29623 } 18223859Sml29623 18233859Sml29623 static nxge_status_t 18243859Sml29623 nxge_resume(p_nxge_t nxgep) 18253859Sml29623 { 18263859Sml29623 nxge_status_t status = NXGE_OK; 18273859Sml29623 18283859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_resume")); 18294587Sjoycey 18303859Sml29623 nxgep->suspended = DDI_RESUME; 18314587Sjoycey (void) nxge_link_monitor(nxgep, LINK_MONITOR_START); 18324587Sjoycey (void) nxge_rxdma_hw_mode(nxgep, NXGE_DMA_START); 18334587Sjoycey (void) nxge_txdma_hw_mode(nxgep, NXGE_DMA_START); 18344587Sjoycey (void) nxge_rx_mac_enable(nxgep); 18354587Sjoycey (void) nxge_tx_mac_enable(nxgep); 18364587Sjoycey nxge_intrs_enable(nxgep); 18373859Sml29623 nxgep->suspended = 0; 18383859Sml29623 18393859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 18403859Sml29623 "<== nxge_resume status = 0x%x", status)); 18413859Sml29623 return (status); 18423859Sml29623 } 18433859Sml29623 18443859Sml29623 static nxge_status_t 18453859Sml29623 nxge_setup_dev(p_nxge_t nxgep) 18463859Sml29623 { 18473859Sml29623 nxge_status_t status = NXGE_OK; 18483859Sml29623 18493859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_setup_dev port %d", 18504732Sdavemq nxgep->mac.portnum)); 18513859Sml29623 18523859Sml29623 status = nxge_link_init(nxgep); 18533859Sml29623 18543859Sml29623 if (fm_check_acc_handle(nxgep->dev_regs->nxge_regh) != DDI_FM_OK) { 18553859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 18563859Sml29623 "port%d Bad register acc handle", nxgep->mac.portnum)); 18573859Sml29623 status = NXGE_ERROR; 18583859Sml29623 } 18593859Sml29623 18603859Sml29623 if (status != NXGE_OK) { 18613859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 18623859Sml29623 " nxge_setup_dev status " 18633859Sml29623 "(xcvr init 0x%08x)", status)); 18643859Sml29623 goto nxge_setup_dev_exit; 18653859Sml29623 } 18663859Sml29623 18673859Sml29623 nxge_setup_dev_exit: 18683859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 18693859Sml29623 "<== nxge_setup_dev port %d status = 0x%08x", 18703859Sml29623 nxgep->mac.portnum, status)); 18713859Sml29623 18723859Sml29623 return (status); 18733859Sml29623 } 18743859Sml29623 18753859Sml29623 static void 18763859Sml29623 nxge_destroy_dev(p_nxge_t nxgep) 18773859Sml29623 { 18783859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_destroy_dev")); 18793859Sml29623 18803859Sml29623 (void) nxge_link_monitor(nxgep, LINK_MONITOR_STOP); 18813859Sml29623 18823859Sml29623 (void) nxge_hw_stop(nxgep); 18833859Sml29623 18843859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_destroy_dev")); 18853859Sml29623 } 18863859Sml29623 18873859Sml29623 static nxge_status_t 18883859Sml29623 nxge_setup_system_dma_pages(p_nxge_t nxgep) 18893859Sml29623 { 18903859Sml29623 int ddi_status = DDI_SUCCESS; 18913859Sml29623 uint_t count; 18923859Sml29623 ddi_dma_cookie_t cookie; 18933859Sml29623 uint_t iommu_pagesize; 18943859Sml29623 nxge_status_t status = NXGE_OK; 18953859Sml29623 18966495Sspeer NXGE_ERROR_MSG((nxgep, DDI_CTL, "==> nxge_setup_system_dma_pages")); 18973859Sml29623 nxgep->sys_page_sz = ddi_ptob(nxgep->dip, (ulong_t)1); 18983859Sml29623 if (nxgep->niu_type != N2_NIU) { 18993859Sml29623 iommu_pagesize = dvma_pagesize(nxgep->dip); 19003859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 19013859Sml29623 " nxge_setup_system_dma_pages: page %d (ddi_ptob %d) " 19023859Sml29623 " default_block_size %d iommu_pagesize %d", 19033859Sml29623 nxgep->sys_page_sz, 19043859Sml29623 ddi_ptob(nxgep->dip, (ulong_t)1), 19053859Sml29623 nxgep->rx_default_block_size, 19063859Sml29623 iommu_pagesize)); 19073859Sml29623 19083859Sml29623 if (iommu_pagesize != 0) { 19093859Sml29623 if (nxgep->sys_page_sz == iommu_pagesize) { 19103859Sml29623 if (iommu_pagesize > 0x4000) 19113859Sml29623 nxgep->sys_page_sz = 0x4000; 19123859Sml29623 } else { 19133859Sml29623 if (nxgep->sys_page_sz > iommu_pagesize) 19143859Sml29623 nxgep->sys_page_sz = iommu_pagesize; 19153859Sml29623 } 19163859Sml29623 } 19173859Sml29623 } 19183859Sml29623 nxgep->sys_page_mask = ~(nxgep->sys_page_sz - 1); 19193859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 19203859Sml29623 "==> nxge_setup_system_dma_pages: page %d (ddi_ptob %d) " 19213859Sml29623 "default_block_size %d page mask %d", 19223859Sml29623 nxgep->sys_page_sz, 19233859Sml29623 ddi_ptob(nxgep->dip, (ulong_t)1), 19243859Sml29623 nxgep->rx_default_block_size, 19253859Sml29623 nxgep->sys_page_mask)); 19263859Sml29623 19273859Sml29623 19283859Sml29623 switch (nxgep->sys_page_sz) { 19293859Sml29623 default: 19303859Sml29623 nxgep->sys_page_sz = 0x1000; 19313859Sml29623 nxgep->sys_page_mask = ~(nxgep->sys_page_sz - 1); 19323859Sml29623 nxgep->rx_default_block_size = 0x1000; 19333859Sml29623 nxgep->rx_bksize_code = RBR_BKSIZE_4K; 19343859Sml29623 break; 19353859Sml29623 case 0x1000: 19363859Sml29623 nxgep->rx_default_block_size = 0x1000; 19373859Sml29623 nxgep->rx_bksize_code = RBR_BKSIZE_4K; 19383859Sml29623 break; 19393859Sml29623 case 0x2000: 19403859Sml29623 nxgep->rx_default_block_size = 0x2000; 19413859Sml29623 nxgep->rx_bksize_code = RBR_BKSIZE_8K; 19423859Sml29623 break; 19433859Sml29623 case 0x4000: 19443859Sml29623 nxgep->rx_default_block_size = 0x4000; 19453859Sml29623 nxgep->rx_bksize_code = RBR_BKSIZE_16K; 19463859Sml29623 break; 19473859Sml29623 case 0x8000: 19483859Sml29623 nxgep->rx_default_block_size = 0x8000; 19493859Sml29623 nxgep->rx_bksize_code = RBR_BKSIZE_32K; 19503859Sml29623 break; 19513859Sml29623 } 19523859Sml29623 19533859Sml29623 #ifndef USE_RX_BIG_BUF 19543859Sml29623 nxge_rx_dma_attr.dma_attr_align = nxgep->sys_page_sz; 19553859Sml29623 #else 19563859Sml29623 nxgep->rx_default_block_size = 0x2000; 19573859Sml29623 nxgep->rx_bksize_code = RBR_BKSIZE_8K; 19583859Sml29623 #endif 19593859Sml29623 /* 19603859Sml29623 * Get the system DMA burst size. 19613859Sml29623 */ 19623859Sml29623 ddi_status = ddi_dma_alloc_handle(nxgep->dip, &nxge_tx_dma_attr, 19633859Sml29623 DDI_DMA_DONTWAIT, 0, 19643859Sml29623 &nxgep->dmasparehandle); 19653859Sml29623 if (ddi_status != DDI_SUCCESS) { 19663859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 19673859Sml29623 "ddi_dma_alloc_handle: failed " 19683859Sml29623 " status 0x%x", ddi_status)); 19693859Sml29623 goto nxge_get_soft_properties_exit; 19703859Sml29623 } 19713859Sml29623 19723859Sml29623 ddi_status = ddi_dma_addr_bind_handle(nxgep->dmasparehandle, NULL, 19733859Sml29623 (caddr_t)nxgep->dmasparehandle, 19743859Sml29623 sizeof (nxgep->dmasparehandle), 19753859Sml29623 DDI_DMA_RDWR | DDI_DMA_CONSISTENT, 19763859Sml29623 DDI_DMA_DONTWAIT, 0, 19773859Sml29623 &cookie, &count); 19783859Sml29623 if (ddi_status != DDI_DMA_MAPPED) { 19793859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 19803859Sml29623 "Binding spare handle to find system" 19813859Sml29623 " burstsize failed.")); 19823859Sml29623 ddi_status = DDI_FAILURE; 19833859Sml29623 goto nxge_get_soft_properties_fail1; 19843859Sml29623 } 19853859Sml29623 19863859Sml29623 nxgep->sys_burst_sz = ddi_dma_burstsizes(nxgep->dmasparehandle); 19873859Sml29623 (void) ddi_dma_unbind_handle(nxgep->dmasparehandle); 19883859Sml29623 19893859Sml29623 nxge_get_soft_properties_fail1: 19903859Sml29623 ddi_dma_free_handle(&nxgep->dmasparehandle); 19913859Sml29623 19923859Sml29623 nxge_get_soft_properties_exit: 19933859Sml29623 19943859Sml29623 if (ddi_status != DDI_SUCCESS) 19953859Sml29623 status |= (NXGE_ERROR | NXGE_DDI_FAILED); 19963859Sml29623 19973859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 19983859Sml29623 "<== nxge_setup_system_dma_pages status = 0x%08x", status)); 19993859Sml29623 return (status); 20003859Sml29623 } 20013859Sml29623 20023859Sml29623 static nxge_status_t 20033859Sml29623 nxge_alloc_mem_pool(p_nxge_t nxgep) 20043859Sml29623 { 20053859Sml29623 nxge_status_t status = NXGE_OK; 20063859Sml29623 20073859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_alloc_mem_pool")); 20083859Sml29623 20093859Sml29623 status = nxge_alloc_rx_mem_pool(nxgep); 20103859Sml29623 if (status != NXGE_OK) { 20113859Sml29623 return (NXGE_ERROR); 20123859Sml29623 } 20133859Sml29623 20143859Sml29623 status = nxge_alloc_tx_mem_pool(nxgep); 20153859Sml29623 if (status != NXGE_OK) { 20163859Sml29623 nxge_free_rx_mem_pool(nxgep); 20173859Sml29623 return (NXGE_ERROR); 20183859Sml29623 } 20193859Sml29623 20203859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_alloc_mem_pool")); 20213859Sml29623 return (NXGE_OK); 20223859Sml29623 } 20233859Sml29623 20243859Sml29623 static void 20253859Sml29623 nxge_free_mem_pool(p_nxge_t nxgep) 20263859Sml29623 { 20273859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM_CTL, "==> nxge_free_mem_pool")); 20283859Sml29623 20293859Sml29623 nxge_free_rx_mem_pool(nxgep); 20303859Sml29623 nxge_free_tx_mem_pool(nxgep); 20313859Sml29623 20323859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM_CTL, "<== nxge_free_mem_pool")); 20333859Sml29623 } 20343859Sml29623 20356495Sspeer nxge_status_t 20363859Sml29623 nxge_alloc_rx_mem_pool(p_nxge_t nxgep) 20373859Sml29623 { 20386495Sspeer uint32_t rdc_max; 20393859Sml29623 p_nxge_dma_pt_cfg_t p_all_cfgp; 20403859Sml29623 p_nxge_hw_pt_cfg_t p_cfgp; 20413859Sml29623 p_nxge_dma_pool_t dma_poolp; 20423859Sml29623 p_nxge_dma_common_t *dma_buf_p; 20433859Sml29623 p_nxge_dma_pool_t dma_cntl_poolp; 20443859Sml29623 p_nxge_dma_common_t *dma_cntl_p; 20453859Sml29623 uint32_t *num_chunks; /* per dma */ 20463859Sml29623 nxge_status_t status = NXGE_OK; 20473859Sml29623 20483859Sml29623 uint32_t nxge_port_rbr_size; 20493859Sml29623 uint32_t nxge_port_rbr_spare_size; 20503859Sml29623 uint32_t nxge_port_rcr_size; 20516495Sspeer uint32_t rx_cntl_alloc_size; 20523859Sml29623 20533859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_alloc_rx_mem_pool")); 20543859Sml29623 20553859Sml29623 p_all_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config; 20563859Sml29623 p_cfgp = (p_nxge_hw_pt_cfg_t)&p_all_cfgp->hw_config; 20576495Sspeer rdc_max = NXGE_MAX_RDCS; 20583859Sml29623 20593859Sml29623 /* 20606495Sspeer * Allocate memory for the common DMA data structures. 20613859Sml29623 */ 20623859Sml29623 dma_poolp = (p_nxge_dma_pool_t)KMEM_ZALLOC(sizeof (nxge_dma_pool_t), 20633859Sml29623 KM_SLEEP); 20643859Sml29623 dma_buf_p = (p_nxge_dma_common_t *)KMEM_ZALLOC( 20656495Sspeer sizeof (p_nxge_dma_common_t) * rdc_max, KM_SLEEP); 20663859Sml29623 20673859Sml29623 dma_cntl_poolp = (p_nxge_dma_pool_t) 20683859Sml29623 KMEM_ZALLOC(sizeof (nxge_dma_pool_t), KM_SLEEP); 20693859Sml29623 dma_cntl_p = (p_nxge_dma_common_t *)KMEM_ZALLOC( 20706495Sspeer sizeof (p_nxge_dma_common_t) * rdc_max, KM_SLEEP); 20713859Sml29623 20723859Sml29623 num_chunks = (uint32_t *)KMEM_ZALLOC( 20736495Sspeer sizeof (uint32_t) * rdc_max, KM_SLEEP); 20743859Sml29623 20753859Sml29623 /* 20766495Sspeer * Assume that each DMA channel will be configured with 20776495Sspeer * the default block size. 20786495Sspeer * rbr block counts are modulo the batch count (16). 20793859Sml29623 */ 20803859Sml29623 nxge_port_rbr_size = p_all_cfgp->rbr_size; 20813859Sml29623 nxge_port_rcr_size = p_all_cfgp->rcr_size; 20823859Sml29623 20833859Sml29623 if (!nxge_port_rbr_size) { 20843859Sml29623 nxge_port_rbr_size = NXGE_RBR_RBB_DEFAULT; 20853859Sml29623 } 20863859Sml29623 if (nxge_port_rbr_size % NXGE_RXDMA_POST_BATCH) { 20873859Sml29623 nxge_port_rbr_size = (NXGE_RXDMA_POST_BATCH * 20883859Sml29623 (nxge_port_rbr_size / NXGE_RXDMA_POST_BATCH + 1)); 20893859Sml29623 } 20903859Sml29623 20913859Sml29623 p_all_cfgp->rbr_size = nxge_port_rbr_size; 20923859Sml29623 nxge_port_rbr_spare_size = nxge_rbr_spare_size; 20933859Sml29623 20943859Sml29623 if (nxge_port_rbr_spare_size % NXGE_RXDMA_POST_BATCH) { 20953859Sml29623 nxge_port_rbr_spare_size = (NXGE_RXDMA_POST_BATCH * 20963859Sml29623 (nxge_port_rbr_spare_size / NXGE_RXDMA_POST_BATCH + 1)); 20973859Sml29623 } 20985770Sml29623 if (nxge_port_rbr_size > RBR_DEFAULT_MAX_BLKS) { 20995770Sml29623 NXGE_DEBUG_MSG((nxgep, MEM_CTL, 21005770Sml29623 "nxge_alloc_rx_mem_pool: RBR size too high %d, " 21015770Sml29623 "set to default %d", 21025770Sml29623 nxge_port_rbr_size, RBR_DEFAULT_MAX_BLKS)); 21035770Sml29623 nxge_port_rbr_size = RBR_DEFAULT_MAX_BLKS; 21045770Sml29623 } 21055770Sml29623 if (nxge_port_rcr_size > RCR_DEFAULT_MAX) { 21065770Sml29623 NXGE_DEBUG_MSG((nxgep, MEM_CTL, 21075770Sml29623 "nxge_alloc_rx_mem_pool: RCR too high %d, " 21085770Sml29623 "set to default %d", 21095770Sml29623 nxge_port_rcr_size, RCR_DEFAULT_MAX)); 21105770Sml29623 nxge_port_rcr_size = RCR_DEFAULT_MAX; 21115770Sml29623 } 21123859Sml29623 21133859Sml29623 /* 21143859Sml29623 * N2/NIU has limitation on the descriptor sizes (contiguous 21153859Sml29623 * memory allocation on data buffers to 4M (contig_mem_alloc) 21163859Sml29623 * and little endian for control buffers (must use the ddi/dki mem alloc 21173859Sml29623 * function). 21183859Sml29623 */ 21193859Sml29623 #if defined(sun4v) && defined(NIU_LP_WORKAROUND) 21203859Sml29623 if (nxgep->niu_type == N2_NIU) { 21213859Sml29623 nxge_port_rbr_spare_size = 0; 21223859Sml29623 if ((nxge_port_rbr_size > NXGE_NIU_CONTIG_RBR_MAX) || 21233859Sml29623 (!ISP2(nxge_port_rbr_size))) { 21243859Sml29623 nxge_port_rbr_size = NXGE_NIU_CONTIG_RBR_MAX; 21253859Sml29623 } 21263859Sml29623 if ((nxge_port_rcr_size > NXGE_NIU_CONTIG_RCR_MAX) || 21273859Sml29623 (!ISP2(nxge_port_rcr_size))) { 21283859Sml29623 nxge_port_rcr_size = NXGE_NIU_CONTIG_RCR_MAX; 21293859Sml29623 } 21303859Sml29623 } 21313859Sml29623 #endif 21323859Sml29623 21333859Sml29623 /* 21343859Sml29623 * Addresses of receive block ring, receive completion ring and the 21353859Sml29623 * mailbox must be all cache-aligned (64 bytes). 21363859Sml29623 */ 21373859Sml29623 rx_cntl_alloc_size = nxge_port_rbr_size + nxge_port_rbr_spare_size; 21383859Sml29623 rx_cntl_alloc_size *= (sizeof (rx_desc_t)); 21393859Sml29623 rx_cntl_alloc_size += (sizeof (rcr_entry_t) * nxge_port_rcr_size); 21403859Sml29623 rx_cntl_alloc_size += sizeof (rxdma_mailbox_t); 21413859Sml29623 21423859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_alloc_rx_mem_pool: " 21433859Sml29623 "nxge_port_rbr_size = %d nxge_port_rbr_spare_size = %d " 21443859Sml29623 "nxge_port_rcr_size = %d " 21453859Sml29623 "rx_cntl_alloc_size = %d", 21463859Sml29623 nxge_port_rbr_size, nxge_port_rbr_spare_size, 21473859Sml29623 nxge_port_rcr_size, 21483859Sml29623 rx_cntl_alloc_size)); 21493859Sml29623 21503859Sml29623 #if defined(sun4v) && defined(NIU_LP_WORKAROUND) 21513859Sml29623 if (nxgep->niu_type == N2_NIU) { 21526495Sspeer uint32_t rx_buf_alloc_size = (nxgep->rx_default_block_size * 21536495Sspeer (nxge_port_rbr_size + nxge_port_rbr_spare_size)); 21546495Sspeer 21553859Sml29623 if (!ISP2(rx_buf_alloc_size)) { 21563859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 21573859Sml29623 "==> nxge_alloc_rx_mem_pool: " 21583859Sml29623 " must be power of 2")); 21593859Sml29623 status |= (NXGE_ERROR | NXGE_DDI_FAILED); 21603859Sml29623 goto nxge_alloc_rx_mem_pool_exit; 21613859Sml29623 } 21623859Sml29623 21633859Sml29623 if (rx_buf_alloc_size > (1 << 22)) { 21643859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 21653859Sml29623 "==> nxge_alloc_rx_mem_pool: " 21663859Sml29623 " limit size to 4M")); 21673859Sml29623 status |= (NXGE_ERROR | NXGE_DDI_FAILED); 21683859Sml29623 goto nxge_alloc_rx_mem_pool_exit; 21693859Sml29623 } 21703859Sml29623 21713859Sml29623 if (rx_cntl_alloc_size < 0x2000) { 21723859Sml29623 rx_cntl_alloc_size = 0x2000; 21733859Sml29623 } 21743859Sml29623 } 21753859Sml29623 #endif 21763859Sml29623 nxgep->nxge_port_rbr_size = nxge_port_rbr_size; 21773859Sml29623 nxgep->nxge_port_rcr_size = nxge_port_rcr_size; 21786495Sspeer nxgep->nxge_port_rbr_spare_size = nxge_port_rbr_spare_size; 21796495Sspeer nxgep->nxge_port_rx_cntl_alloc_size = rx_cntl_alloc_size; 21806495Sspeer 21816495Sspeer dma_poolp->ndmas = p_cfgp->max_rdcs; 21823859Sml29623 dma_poolp->num_chunks = num_chunks; 21833859Sml29623 dma_poolp->buf_allocated = B_TRUE; 21843859Sml29623 nxgep->rx_buf_pool_p = dma_poolp; 21853859Sml29623 dma_poolp->dma_buf_pool_p = dma_buf_p; 21863859Sml29623 21876495Sspeer dma_cntl_poolp->ndmas = p_cfgp->max_rdcs; 21883859Sml29623 dma_cntl_poolp->buf_allocated = B_TRUE; 21893859Sml29623 nxgep->rx_cntl_pool_p = dma_cntl_poolp; 21903859Sml29623 dma_cntl_poolp->dma_buf_pool_p = dma_cntl_p; 21913859Sml29623 21926495Sspeer /* Allocate the receive rings, too. */ 21936495Sspeer nxgep->rx_rbr_rings = 21946495Sspeer KMEM_ZALLOC(sizeof (rx_rbr_rings_t), KM_SLEEP); 21956495Sspeer nxgep->rx_rbr_rings->rbr_rings = 21966495Sspeer KMEM_ZALLOC(sizeof (p_rx_rbr_ring_t) * rdc_max, KM_SLEEP); 21976495Sspeer nxgep->rx_rcr_rings = 21986495Sspeer KMEM_ZALLOC(sizeof (rx_rcr_rings_t), KM_SLEEP); 21996495Sspeer nxgep->rx_rcr_rings->rcr_rings = 22006495Sspeer KMEM_ZALLOC(sizeof (p_rx_rcr_ring_t) * rdc_max, KM_SLEEP); 22016495Sspeer nxgep->rx_mbox_areas_p = 22026495Sspeer KMEM_ZALLOC(sizeof (rx_mbox_areas_t), KM_SLEEP); 22036495Sspeer nxgep->rx_mbox_areas_p->rxmbox_areas = 22046495Sspeer KMEM_ZALLOC(sizeof (p_rx_mbox_t) * rdc_max, KM_SLEEP); 22056495Sspeer 22066495Sspeer nxgep->rx_rbr_rings->ndmas = nxgep->rx_rcr_rings->ndmas = 22076495Sspeer p_cfgp->max_rdcs; 22086495Sspeer 22093859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, 22106495Sspeer "<== nxge_alloc_rx_mem_pool:status 0x%08x", status)); 22113859Sml29623 22123859Sml29623 nxge_alloc_rx_mem_pool_exit: 22136495Sspeer return (status); 22146495Sspeer } 22156495Sspeer 22166495Sspeer /* 22176495Sspeer * nxge_alloc_rxb 22186495Sspeer * 22196495Sspeer * Allocate buffers for an RDC. 22206495Sspeer * 22216495Sspeer * Arguments: 22226495Sspeer * nxgep 22236495Sspeer * channel The channel to map into our kernel space. 22246495Sspeer * 22256495Sspeer * Notes: 22266495Sspeer * 22276495Sspeer * NPI function calls: 22286495Sspeer * 22296495Sspeer * NXGE function calls: 22306495Sspeer * 22316495Sspeer * Registers accessed: 22326495Sspeer * 22336495Sspeer * Context: 22346495Sspeer * 22356495Sspeer * Taking apart: 22366495Sspeer * 22376495Sspeer * Open questions: 22386495Sspeer * 22396495Sspeer */ 22406495Sspeer nxge_status_t 22416495Sspeer nxge_alloc_rxb( 22426495Sspeer p_nxge_t nxgep, 22436495Sspeer int channel) 22446495Sspeer { 22456495Sspeer size_t rx_buf_alloc_size; 22466495Sspeer nxge_status_t status = NXGE_OK; 22476495Sspeer 22486495Sspeer nxge_dma_common_t **data; 22496495Sspeer nxge_dma_common_t **control; 22506495Sspeer uint32_t *num_chunks; 22516495Sspeer 22526495Sspeer NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_alloc_rbb")); 22536495Sspeer 22546495Sspeer /* 22556495Sspeer * Allocate memory for the receive buffers and descriptor rings. 22566495Sspeer * Replace these allocation functions with the interface functions 22576495Sspeer * provided by the partition manager if/when they are available. 22586495Sspeer */ 22596495Sspeer 22606495Sspeer /* 22616495Sspeer * Allocate memory for the receive buffer blocks. 22626495Sspeer */ 22636495Sspeer rx_buf_alloc_size = (nxgep->rx_default_block_size * 22646495Sspeer (nxgep->nxge_port_rbr_size + nxgep->nxge_port_rbr_spare_size)); 22656495Sspeer 22666495Sspeer data = &nxgep->rx_buf_pool_p->dma_buf_pool_p[channel]; 22676495Sspeer num_chunks = &nxgep->rx_buf_pool_p->num_chunks[channel]; 22686495Sspeer 22696495Sspeer if ((status = nxge_alloc_rx_buf_dma( 22706495Sspeer nxgep, channel, data, rx_buf_alloc_size, 22716495Sspeer nxgep->rx_default_block_size, num_chunks)) != NXGE_OK) { 22726495Sspeer return (status); 22736495Sspeer } 22746495Sspeer 22756495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "<== nxge_alloc_rxb(): " 22766495Sspeer "dma %d dma_buf_p %llx &dma_buf_p %llx", channel, *data, data)); 22776495Sspeer 22786495Sspeer /* 22796495Sspeer * Allocate memory for descriptor rings and mailbox. 22806495Sspeer */ 22816495Sspeer control = &nxgep->rx_cntl_pool_p->dma_buf_pool_p[channel]; 22826495Sspeer 22836495Sspeer if ((status = nxge_alloc_rx_cntl_dma( 22846495Sspeer nxgep, channel, control, nxgep->nxge_port_rx_cntl_alloc_size)) 22856495Sspeer != NXGE_OK) { 22866495Sspeer nxge_free_rx_cntl_dma(nxgep, *control); 22876495Sspeer (*data)->buf_alloc_state |= BUF_ALLOCATED_WAIT_FREE; 22886495Sspeer nxge_free_rx_buf_dma(nxgep, *data, *num_chunks); 22896495Sspeer return (status); 22906495Sspeer } 22916495Sspeer 22923859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, 22936495Sspeer "<== nxge_alloc_rx_mem_pool:status 0x%08x", status)); 22943859Sml29623 22953859Sml29623 return (status); 22963859Sml29623 } 22973859Sml29623 22986495Sspeer void 22996495Sspeer nxge_free_rxb( 23006495Sspeer p_nxge_t nxgep, 23016495Sspeer int channel) 23026495Sspeer { 23036495Sspeer nxge_dma_common_t *data; 23046495Sspeer nxge_dma_common_t *control; 23056495Sspeer uint32_t num_chunks; 23066495Sspeer 23076495Sspeer NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_alloc_rbb")); 23086495Sspeer 23096495Sspeer data = nxgep->rx_buf_pool_p->dma_buf_pool_p[channel]; 23106495Sspeer num_chunks = nxgep->rx_buf_pool_p->num_chunks[channel]; 23116495Sspeer nxge_free_rx_buf_dma(nxgep, data, num_chunks); 23126495Sspeer 23136495Sspeer nxgep->rx_buf_pool_p->dma_buf_pool_p[channel] = 0; 23146495Sspeer nxgep->rx_buf_pool_p->num_chunks[channel] = 0; 23156495Sspeer 23166495Sspeer control = nxgep->rx_cntl_pool_p->dma_buf_pool_p[channel]; 23176495Sspeer nxge_free_rx_cntl_dma(nxgep, control); 23186495Sspeer 23196495Sspeer nxgep->rx_cntl_pool_p->dma_buf_pool_p[channel] = 0; 23206495Sspeer 23216495Sspeer KMEM_FREE(data, sizeof (nxge_dma_common_t) * NXGE_DMA_BLOCK); 23226495Sspeer KMEM_FREE(control, sizeof (nxge_dma_common_t)); 23236495Sspeer 23246495Sspeer NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_alloc_rbb")); 23256495Sspeer } 23266495Sspeer 23273859Sml29623 static void 23283859Sml29623 nxge_free_rx_mem_pool(p_nxge_t nxgep) 23293859Sml29623 { 23306495Sspeer int rdc_max = NXGE_MAX_RDCS; 23313859Sml29623 23323859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_free_rx_mem_pool")); 23333859Sml29623 23346495Sspeer if (!nxgep->rx_buf_pool_p || !nxgep->rx_buf_pool_p->buf_allocated) { 23353859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 23363859Sml29623 "<== nxge_free_rx_mem_pool " 23373859Sml29623 "(null rx buf pool or buf not allocated")); 23383859Sml29623 return; 23393859Sml29623 } 23406495Sspeer if (!nxgep->rx_cntl_pool_p || !nxgep->rx_cntl_pool_p->buf_allocated) { 23413859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 23423859Sml29623 "<== nxge_free_rx_mem_pool " 23433859Sml29623 "(null rx cntl buf pool or cntl buf not allocated")); 23443859Sml29623 return; 23453859Sml29623 } 23463859Sml29623 23476495Sspeer KMEM_FREE(nxgep->rx_cntl_pool_p->dma_buf_pool_p, 23486495Sspeer sizeof (p_nxge_dma_common_t) * rdc_max); 23496495Sspeer KMEM_FREE(nxgep->rx_cntl_pool_p, sizeof (nxge_dma_pool_t)); 23506495Sspeer 23516495Sspeer KMEM_FREE(nxgep->rx_buf_pool_p->num_chunks, 23526495Sspeer sizeof (uint32_t) * rdc_max); 23536495Sspeer KMEM_FREE(nxgep->rx_buf_pool_p->dma_buf_pool_p, 23546495Sspeer sizeof (p_nxge_dma_common_t) * rdc_max); 23556495Sspeer KMEM_FREE(nxgep->rx_buf_pool_p, sizeof (nxge_dma_pool_t)); 23566495Sspeer 23576495Sspeer nxgep->rx_buf_pool_p = 0; 23586495Sspeer nxgep->rx_cntl_pool_p = 0; 23596495Sspeer 23606495Sspeer KMEM_FREE(nxgep->rx_rbr_rings->rbr_rings, 23616495Sspeer sizeof (p_rx_rbr_ring_t) * rdc_max); 23626495Sspeer KMEM_FREE(nxgep->rx_rbr_rings, sizeof (rx_rbr_rings_t)); 23636495Sspeer KMEM_FREE(nxgep->rx_rcr_rings->rcr_rings, 23646495Sspeer sizeof (p_rx_rcr_ring_t) * rdc_max); 23656495Sspeer KMEM_FREE(nxgep->rx_rcr_rings, sizeof (rx_rcr_rings_t)); 23666495Sspeer KMEM_FREE(nxgep->rx_mbox_areas_p->rxmbox_areas, 23676495Sspeer sizeof (p_rx_mbox_t) * rdc_max); 23686495Sspeer KMEM_FREE(nxgep->rx_mbox_areas_p, sizeof (rx_mbox_areas_t)); 23696495Sspeer 23706495Sspeer nxgep->rx_rbr_rings = 0; 23716495Sspeer nxgep->rx_rcr_rings = 0; 23726495Sspeer nxgep->rx_mbox_areas_p = 0; 23733859Sml29623 23743859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "<== nxge_free_rx_mem_pool")); 23753859Sml29623 } 23763859Sml29623 23773859Sml29623 23783859Sml29623 static nxge_status_t 23793859Sml29623 nxge_alloc_rx_buf_dma(p_nxge_t nxgep, uint16_t dma_channel, 23803859Sml29623 p_nxge_dma_common_t *dmap, 23813859Sml29623 size_t alloc_size, size_t block_size, uint32_t *num_chunks) 23823859Sml29623 { 23833859Sml29623 p_nxge_dma_common_t rx_dmap; 23843859Sml29623 nxge_status_t status = NXGE_OK; 23853859Sml29623 size_t total_alloc_size; 23863859Sml29623 size_t allocated = 0; 23873859Sml29623 int i, size_index, array_size; 23886495Sspeer boolean_t use_kmem_alloc = B_FALSE; 23893859Sml29623 23903859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_alloc_rx_buf_dma")); 23913859Sml29623 23923859Sml29623 rx_dmap = (p_nxge_dma_common_t) 23933859Sml29623 KMEM_ZALLOC(sizeof (nxge_dma_common_t) * NXGE_DMA_BLOCK, 23943859Sml29623 KM_SLEEP); 23953859Sml29623 23963859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 23973859Sml29623 " alloc_rx_buf_dma rdc %d asize %x bsize %x bbuf %llx ", 23983859Sml29623 dma_channel, alloc_size, block_size, dmap)); 23993859Sml29623 24003859Sml29623 total_alloc_size = alloc_size; 24013859Sml29623 24023859Sml29623 #if defined(RX_USE_RECLAIM_POST) 24033859Sml29623 total_alloc_size = alloc_size + alloc_size/4; 24043859Sml29623 #endif 24053859Sml29623 24063859Sml29623 i = 0; 24073859Sml29623 size_index = 0; 24083859Sml29623 array_size = sizeof (alloc_sizes)/sizeof (size_t); 24093859Sml29623 while ((alloc_sizes[size_index] < alloc_size) && 24103859Sml29623 (size_index < array_size)) 24113859Sml29623 size_index++; 24123859Sml29623 if (size_index >= array_size) { 24133859Sml29623 size_index = array_size - 1; 24143859Sml29623 } 24153859Sml29623 24166495Sspeer /* For Neptune, use kmem_alloc if the kmem flag is set. */ 24176495Sspeer if (nxgep->niu_type != N2_NIU && nxge_use_kmem_alloc) { 24186495Sspeer use_kmem_alloc = B_TRUE; 24196495Sspeer #if defined(__i386) || defined(__amd64) 24206495Sspeer size_index = 0; 24216495Sspeer #endif 24226495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 24236495Sspeer "==> nxge_alloc_rx_buf_dma: " 24246495Sspeer "Neptune use kmem_alloc() - size_index %d", 24256495Sspeer size_index)); 24266495Sspeer } 24276495Sspeer 24283859Sml29623 while ((allocated < total_alloc_size) && 24293859Sml29623 (size_index >= 0) && (i < NXGE_DMA_BLOCK)) { 24303859Sml29623 rx_dmap[i].dma_chunk_index = i; 24313859Sml29623 rx_dmap[i].block_size = block_size; 24323859Sml29623 rx_dmap[i].alength = alloc_sizes[size_index]; 24333859Sml29623 rx_dmap[i].orig_alength = rx_dmap[i].alength; 24343859Sml29623 rx_dmap[i].nblocks = alloc_sizes[size_index] / block_size; 24353859Sml29623 rx_dmap[i].dma_channel = dma_channel; 24363859Sml29623 rx_dmap[i].contig_alloc_type = B_FALSE; 24376495Sspeer rx_dmap[i].kmem_alloc_type = B_FALSE; 24386495Sspeer rx_dmap[i].buf_alloc_type = DDI_MEM_ALLOC; 24393859Sml29623 24403859Sml29623 /* 24413859Sml29623 * N2/NIU: data buffers must be contiguous as the driver 24423859Sml29623 * needs to call Hypervisor api to set up 24433859Sml29623 * logical pages. 24443859Sml29623 */ 24453859Sml29623 if ((nxgep->niu_type == N2_NIU) && (NXGE_DMA_BLOCK == 1)) { 24463859Sml29623 rx_dmap[i].contig_alloc_type = B_TRUE; 24476495Sspeer rx_dmap[i].buf_alloc_type = CONTIG_MEM_ALLOC; 24486495Sspeer } else if (use_kmem_alloc) { 24496495Sspeer /* For Neptune, use kmem_alloc */ 24506495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 24516495Sspeer "==> nxge_alloc_rx_buf_dma: " 24526495Sspeer "Neptune use kmem_alloc()")); 24536495Sspeer rx_dmap[i].kmem_alloc_type = B_TRUE; 24546495Sspeer rx_dmap[i].buf_alloc_type = KMEM_ALLOC; 24553859Sml29623 } 24563859Sml29623 24573859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 24583859Sml29623 "alloc_rx_buf_dma rdc %d chunk %d bufp %llx size %x " 24593859Sml29623 "i %d nblocks %d alength %d", 24603859Sml29623 dma_channel, i, &rx_dmap[i], block_size, 24613859Sml29623 i, rx_dmap[i].nblocks, 24623859Sml29623 rx_dmap[i].alength)); 24633859Sml29623 status = nxge_dma_mem_alloc(nxgep, nxge_force_dma, 24643859Sml29623 &nxge_rx_dma_attr, 24653859Sml29623 rx_dmap[i].alength, 24663859Sml29623 &nxge_dev_buf_dma_acc_attr, 24673859Sml29623 DDI_DMA_READ | DDI_DMA_STREAMING, 24683859Sml29623 (p_nxge_dma_common_t)(&rx_dmap[i])); 24693859Sml29623 if (status != NXGE_OK) { 24703859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 24716495Sspeer "nxge_alloc_rx_buf_dma: Alloc Failed: " 24726495Sspeer "dma %d size_index %d size requested %d", 24736495Sspeer dma_channel, 24746495Sspeer size_index, 24756495Sspeer rx_dmap[i].alength)); 24763859Sml29623 size_index--; 24773859Sml29623 } else { 24786495Sspeer rx_dmap[i].buf_alloc_state = BUF_ALLOCATED; 24796495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 24806495Sspeer " nxge_alloc_rx_buf_dma DONE alloc mem: " 24816495Sspeer "dma %d dma_buf_p $%p kaddrp $%p alength %d " 24826495Sspeer "buf_alloc_state %d alloc_type %d", 24836495Sspeer dma_channel, 24846495Sspeer &rx_dmap[i], 24856495Sspeer rx_dmap[i].kaddrp, 24866495Sspeer rx_dmap[i].alength, 24876495Sspeer rx_dmap[i].buf_alloc_state, 24886495Sspeer rx_dmap[i].buf_alloc_type)); 24896495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 24906495Sspeer " alloc_rx_buf_dma allocated rdc %d " 24916495Sspeer "chunk %d size %x dvma %x bufp %llx kaddrp $%p", 24926495Sspeer dma_channel, i, rx_dmap[i].alength, 24936495Sspeer rx_dmap[i].ioaddr_pp, &rx_dmap[i], 24946495Sspeer rx_dmap[i].kaddrp)); 24953859Sml29623 i++; 24963859Sml29623 allocated += alloc_sizes[size_index]; 24973859Sml29623 } 24983859Sml29623 } 24993859Sml29623 25003859Sml29623 if (allocated < total_alloc_size) { 25015770Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 25026495Sspeer "==> nxge_alloc_rx_buf_dma: not enough for channel %d " 25035770Sml29623 "allocated 0x%x requested 0x%x", 25045770Sml29623 dma_channel, 25055770Sml29623 allocated, total_alloc_size)); 25065770Sml29623 status = NXGE_ERROR; 25073859Sml29623 goto nxge_alloc_rx_mem_fail1; 25083859Sml29623 } 25093859Sml29623 25105770Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 25116495Sspeer "==> nxge_alloc_rx_buf_dma: Allocated for channel %d " 25125770Sml29623 "allocated 0x%x requested 0x%x", 25135770Sml29623 dma_channel, 25145770Sml29623 allocated, total_alloc_size)); 25155770Sml29623 25163859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, 25173859Sml29623 " alloc_rx_buf_dma rdc %d allocated %d chunks", 25183859Sml29623 dma_channel, i)); 25193859Sml29623 *num_chunks = i; 25203859Sml29623 *dmap = rx_dmap; 25213859Sml29623 25223859Sml29623 goto nxge_alloc_rx_mem_exit; 25233859Sml29623 25243859Sml29623 nxge_alloc_rx_mem_fail1: 25253859Sml29623 KMEM_FREE(rx_dmap, sizeof (nxge_dma_common_t) * NXGE_DMA_BLOCK); 25263859Sml29623 25273859Sml29623 nxge_alloc_rx_mem_exit: 25283859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, 25293859Sml29623 "<== nxge_alloc_rx_buf_dma status 0x%08x", status)); 25303859Sml29623 25313859Sml29623 return (status); 25323859Sml29623 } 25333859Sml29623 25343859Sml29623 /*ARGSUSED*/ 25353859Sml29623 static void 25363859Sml29623 nxge_free_rx_buf_dma(p_nxge_t nxgep, p_nxge_dma_common_t dmap, 25373859Sml29623 uint32_t num_chunks) 25383859Sml29623 { 25393859Sml29623 int i; 25403859Sml29623 25413859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 25423859Sml29623 "==> nxge_free_rx_buf_dma: # of chunks %d", num_chunks)); 25433859Sml29623 25446495Sspeer if (dmap == 0) 25456495Sspeer return; 25466495Sspeer 25473859Sml29623 for (i = 0; i < num_chunks; i++) { 25483859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 25493859Sml29623 "==> nxge_free_rx_buf_dma: chunk %d dmap 0x%llx", 25503859Sml29623 i, dmap)); 25516495Sspeer nxge_dma_free_rx_data_buf(dmap++); 25523859Sml29623 } 25533859Sml29623 25543859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_free_rx_buf_dma")); 25553859Sml29623 } 25563859Sml29623 25573859Sml29623 /*ARGSUSED*/ 25583859Sml29623 static nxge_status_t 25593859Sml29623 nxge_alloc_rx_cntl_dma(p_nxge_t nxgep, uint16_t dma_channel, 25603859Sml29623 p_nxge_dma_common_t *dmap, size_t size) 25613859Sml29623 { 25623859Sml29623 p_nxge_dma_common_t rx_dmap; 25633859Sml29623 nxge_status_t status = NXGE_OK; 25643859Sml29623 25653859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_alloc_rx_cntl_dma")); 25663859Sml29623 25673859Sml29623 rx_dmap = (p_nxge_dma_common_t) 25683859Sml29623 KMEM_ZALLOC(sizeof (nxge_dma_common_t), KM_SLEEP); 25693859Sml29623 25703859Sml29623 rx_dmap->contig_alloc_type = B_FALSE; 25716495Sspeer rx_dmap->kmem_alloc_type = B_FALSE; 25723859Sml29623 25733859Sml29623 status = nxge_dma_mem_alloc(nxgep, nxge_force_dma, 25743859Sml29623 &nxge_desc_dma_attr, 25753859Sml29623 size, 25763859Sml29623 &nxge_dev_desc_dma_acc_attr, 25773859Sml29623 DDI_DMA_RDWR | DDI_DMA_CONSISTENT, 25783859Sml29623 rx_dmap); 25793859Sml29623 if (status != NXGE_OK) { 25803859Sml29623 goto nxge_alloc_rx_cntl_dma_fail1; 25813859Sml29623 } 25823859Sml29623 25833859Sml29623 *dmap = rx_dmap; 25843859Sml29623 goto nxge_alloc_rx_cntl_dma_exit; 25853859Sml29623 25863859Sml29623 nxge_alloc_rx_cntl_dma_fail1: 25873859Sml29623 KMEM_FREE(rx_dmap, sizeof (nxge_dma_common_t)); 25883859Sml29623 25893859Sml29623 nxge_alloc_rx_cntl_dma_exit: 25903859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, 25913859Sml29623 "<== nxge_alloc_rx_cntl_dma status 0x%08x", status)); 25923859Sml29623 25933859Sml29623 return (status); 25943859Sml29623 } 25953859Sml29623 25963859Sml29623 /*ARGSUSED*/ 25973859Sml29623 static void 25983859Sml29623 nxge_free_rx_cntl_dma(p_nxge_t nxgep, p_nxge_dma_common_t dmap) 25993859Sml29623 { 26003859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_free_rx_cntl_dma")); 26013859Sml29623 26026495Sspeer if (dmap == 0) 26036495Sspeer return; 26046495Sspeer 26053859Sml29623 nxge_dma_mem_free(dmap); 26063859Sml29623 26073859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_free_rx_cntl_dma")); 26083859Sml29623 } 26093859Sml29623 26106495Sspeer typedef struct { 26116495Sspeer size_t tx_size; 26126495Sspeer size_t cr_size; 26136495Sspeer size_t threshhold; 26146495Sspeer } nxge_tdc_sizes_t; 26156495Sspeer 26166495Sspeer static 26176495Sspeer nxge_status_t 26186495Sspeer nxge_tdc_sizes( 26196495Sspeer nxge_t *nxgep, 26206495Sspeer nxge_tdc_sizes_t *sizes) 26216495Sspeer { 26226495Sspeer uint32_t threshhold; /* The bcopy() threshhold */ 26236495Sspeer size_t tx_size; /* Transmit buffer size */ 26246495Sspeer size_t cr_size; /* Completion ring size */ 26256495Sspeer 26266495Sspeer /* 26276495Sspeer * Assume that each DMA channel will be configured with the 26286495Sspeer * default transmit buffer size for copying transmit data. 26296495Sspeer * (If a packet is bigger than this, it will not be copied.) 26306495Sspeer */ 26316495Sspeer if (nxgep->niu_type == N2_NIU) { 26326495Sspeer threshhold = TX_BCOPY_SIZE; 26336495Sspeer } else { 26346495Sspeer threshhold = nxge_bcopy_thresh; 26356495Sspeer } 26366495Sspeer tx_size = nxge_tx_ring_size * threshhold; 26376495Sspeer 26386495Sspeer cr_size = nxge_tx_ring_size * sizeof (tx_desc_t); 26396495Sspeer cr_size += sizeof (txdma_mailbox_t); 26406495Sspeer 26416495Sspeer #if defined(sun4v) && defined(NIU_LP_WORKAROUND) 26426495Sspeer if (nxgep->niu_type == N2_NIU) { 26436495Sspeer if (!ISP2(tx_size)) { 26446495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 26456495Sspeer "==> nxge_tdc_sizes: Tx size" 26466495Sspeer " must be power of 2")); 26476495Sspeer return (NXGE_ERROR); 26486495Sspeer } 26496495Sspeer 26506495Sspeer if (tx_size > (1 << 22)) { 26516495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 26526495Sspeer "==> nxge_tdc_sizes: Tx size" 26536495Sspeer " limited to 4M")); 26546495Sspeer return (NXGE_ERROR); 26556495Sspeer } 26566495Sspeer 26576495Sspeer if (cr_size < 0x2000) 26586495Sspeer cr_size = 0x2000; 26596495Sspeer } 26606495Sspeer #endif 26616495Sspeer 26626495Sspeer sizes->threshhold = threshhold; 26636495Sspeer sizes->tx_size = tx_size; 26646495Sspeer sizes->cr_size = cr_size; 26656495Sspeer 26666495Sspeer return (NXGE_OK); 26676495Sspeer } 26686495Sspeer /* 26696495Sspeer * nxge_alloc_txb 26706495Sspeer * 26716495Sspeer * Allocate buffers for an TDC. 26726495Sspeer * 26736495Sspeer * Arguments: 26746495Sspeer * nxgep 26756495Sspeer * channel The channel to map into our kernel space. 26766495Sspeer * 26776495Sspeer * Notes: 26786495Sspeer * 26796495Sspeer * NPI function calls: 26806495Sspeer * 26816495Sspeer * NXGE function calls: 26826495Sspeer * 26836495Sspeer * Registers accessed: 26846495Sspeer * 26856495Sspeer * Context: 26866495Sspeer * 26876495Sspeer * Taking apart: 26886495Sspeer * 26896495Sspeer * Open questions: 26906495Sspeer * 26916495Sspeer */ 26926495Sspeer nxge_status_t 26936495Sspeer nxge_alloc_txb( 26946495Sspeer p_nxge_t nxgep, 26956495Sspeer int channel) 26966495Sspeer { 26976495Sspeer nxge_dma_common_t **dma_buf_p; 26986495Sspeer nxge_dma_common_t **dma_cntl_p; 26996495Sspeer uint32_t *num_chunks; 27006495Sspeer nxge_status_t status = NXGE_OK; 27016495Sspeer 27026495Sspeer nxge_tdc_sizes_t sizes; 27036495Sspeer 27046495Sspeer NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_alloc_tbb")); 27056495Sspeer 27066495Sspeer if (nxge_tdc_sizes(nxgep, &sizes) != NXGE_OK) 27076495Sspeer return (NXGE_ERROR); 27086495Sspeer 27096495Sspeer /* 27106495Sspeer * Allocate memory for transmit buffers and descriptor rings. 27116495Sspeer * Replace these allocation functions with the interface functions 27126495Sspeer * provided by the partition manager Real Soon Now. 27136495Sspeer */ 27146495Sspeer dma_buf_p = &nxgep->tx_buf_pool_p->dma_buf_pool_p[channel]; 27156495Sspeer num_chunks = &nxgep->tx_buf_pool_p->num_chunks[channel]; 27166495Sspeer 27176495Sspeer dma_cntl_p = &nxgep->tx_cntl_pool_p->dma_buf_pool_p[channel]; 27186495Sspeer 27196495Sspeer /* 27206495Sspeer * Allocate memory for transmit buffers and descriptor rings. 27216495Sspeer * Replace allocation functions with interface functions provided 27226495Sspeer * by the partition manager when it is available. 27236495Sspeer * 27246495Sspeer * Allocate memory for the transmit buffer pool. 27256495Sspeer */ 27266495Sspeer NXGE_DEBUG_MSG((nxgep, DMA_CTL, 27276495Sspeer "sizes: tx: %ld, cr:%ld, th:%ld", 27286495Sspeer sizes.tx_size, sizes.cr_size, sizes.threshhold)); 27296495Sspeer 27306495Sspeer *num_chunks = 0; 27316495Sspeer status = nxge_alloc_tx_buf_dma(nxgep, channel, dma_buf_p, 27326495Sspeer sizes.tx_size, sizes.threshhold, num_chunks); 27336495Sspeer if (status != NXGE_OK) { 27346495Sspeer cmn_err(CE_NOTE, "nxge_alloc_tx_buf_dma failed!"); 27356495Sspeer return (status); 27366495Sspeer } 27376495Sspeer 27386495Sspeer /* 27396495Sspeer * Allocate memory for descriptor rings and mailbox. 27406495Sspeer */ 27416495Sspeer status = nxge_alloc_tx_cntl_dma(nxgep, channel, dma_cntl_p, 27426495Sspeer sizes.cr_size); 27436495Sspeer if (status != NXGE_OK) { 27446495Sspeer nxge_free_tx_buf_dma(nxgep, *dma_buf_p, *num_chunks); 27456495Sspeer cmn_err(CE_NOTE, "nxge_alloc_tx_cntl_dma failed!"); 27466495Sspeer return (status); 27476495Sspeer } 27486495Sspeer 27496495Sspeer return (NXGE_OK); 27506495Sspeer } 27516495Sspeer 27526495Sspeer void 27536495Sspeer nxge_free_txb( 27546495Sspeer p_nxge_t nxgep, 27556495Sspeer int channel) 27566495Sspeer { 27576495Sspeer nxge_dma_common_t *data; 27586495Sspeer nxge_dma_common_t *control; 27596495Sspeer uint32_t num_chunks; 27606495Sspeer 27616495Sspeer NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_free_txb")); 27626495Sspeer 27636495Sspeer data = nxgep->tx_buf_pool_p->dma_buf_pool_p[channel]; 27646495Sspeer num_chunks = nxgep->tx_buf_pool_p->num_chunks[channel]; 27656495Sspeer nxge_free_tx_buf_dma(nxgep, data, num_chunks); 27666495Sspeer 27676495Sspeer nxgep->tx_buf_pool_p->dma_buf_pool_p[channel] = 0; 27686495Sspeer nxgep->tx_buf_pool_p->num_chunks[channel] = 0; 27696495Sspeer 27706495Sspeer control = nxgep->tx_cntl_pool_p->dma_buf_pool_p[channel]; 27716495Sspeer nxge_free_tx_cntl_dma(nxgep, control); 27726495Sspeer 27736495Sspeer nxgep->tx_cntl_pool_p->dma_buf_pool_p[channel] = 0; 27746495Sspeer 27756495Sspeer KMEM_FREE(data, sizeof (nxge_dma_common_t) * NXGE_DMA_BLOCK); 27766495Sspeer KMEM_FREE(control, sizeof (nxge_dma_common_t)); 27776495Sspeer 27786495Sspeer NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_free_txb")); 27796495Sspeer } 27806495Sspeer 27816495Sspeer /* 27826495Sspeer * nxge_alloc_tx_mem_pool 27836495Sspeer * 27846495Sspeer * This function allocates all of the per-port TDC control data structures. 27856495Sspeer * The per-channel (TDC) data structures are allocated when needed. 27866495Sspeer * 27876495Sspeer * Arguments: 27886495Sspeer * nxgep 27896495Sspeer * 27906495Sspeer * Notes: 27916495Sspeer * 27926495Sspeer * Context: 27936495Sspeer * Any domain 27946495Sspeer */ 27956495Sspeer nxge_status_t 27963859Sml29623 nxge_alloc_tx_mem_pool(p_nxge_t nxgep) 27973859Sml29623 { 27986495Sspeer nxge_hw_pt_cfg_t *p_cfgp; 27996495Sspeer nxge_dma_pool_t *dma_poolp; 28006495Sspeer nxge_dma_common_t **dma_buf_p; 28016495Sspeer nxge_dma_pool_t *dma_cntl_poolp; 28026495Sspeer nxge_dma_common_t **dma_cntl_p; 28033859Sml29623 uint32_t *num_chunks; /* per dma */ 28046495Sspeer int tdc_max; 28053859Sml29623 28063859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM_CTL, "==> nxge_alloc_tx_mem_pool")); 28073859Sml29623 28086495Sspeer p_cfgp = &nxgep->pt_config.hw_config; 28096495Sspeer tdc_max = NXGE_MAX_TDCS; 28106495Sspeer 28113859Sml29623 /* 28123859Sml29623 * Allocate memory for each transmit DMA channel. 28133859Sml29623 */ 28143859Sml29623 dma_poolp = (p_nxge_dma_pool_t)KMEM_ZALLOC(sizeof (nxge_dma_pool_t), 28153859Sml29623 KM_SLEEP); 28163859Sml29623 dma_buf_p = (p_nxge_dma_common_t *)KMEM_ZALLOC( 28176495Sspeer sizeof (p_nxge_dma_common_t) * tdc_max, KM_SLEEP); 28183859Sml29623 28193859Sml29623 dma_cntl_poolp = (p_nxge_dma_pool_t) 28203859Sml29623 KMEM_ZALLOC(sizeof (nxge_dma_pool_t), KM_SLEEP); 28213859Sml29623 dma_cntl_p = (p_nxge_dma_common_t *)KMEM_ZALLOC( 28226495Sspeer sizeof (p_nxge_dma_common_t) * tdc_max, KM_SLEEP); 28233859Sml29623 28245770Sml29623 if (nxge_tx_ring_size > TDC_DEFAULT_MAX) { 28255770Sml29623 NXGE_DEBUG_MSG((nxgep, MEM_CTL, 28265770Sml29623 "nxge_alloc_tx_mem_pool: TDC too high %d, " 28275770Sml29623 "set to default %d", 28285770Sml29623 nxge_tx_ring_size, TDC_DEFAULT_MAX)); 28295770Sml29623 nxge_tx_ring_size = TDC_DEFAULT_MAX; 28305770Sml29623 } 28315770Sml29623 28323859Sml29623 #if defined(sun4v) && defined(NIU_LP_WORKAROUND) 28333859Sml29623 /* 28343859Sml29623 * N2/NIU has limitation on the descriptor sizes (contiguous 28353859Sml29623 * memory allocation on data buffers to 4M (contig_mem_alloc) 28363859Sml29623 * and little endian for control buffers (must use the ddi/dki mem alloc 28373859Sml29623 * function). The transmit ring is limited to 8K (includes the 28383859Sml29623 * mailbox). 28393859Sml29623 */ 28403859Sml29623 if (nxgep->niu_type == N2_NIU) { 28413859Sml29623 if ((nxge_tx_ring_size > NXGE_NIU_CONTIG_TX_MAX) || 28423859Sml29623 (!ISP2(nxge_tx_ring_size))) { 28433859Sml29623 nxge_tx_ring_size = NXGE_NIU_CONTIG_TX_MAX; 28443859Sml29623 } 28453859Sml29623 } 28463859Sml29623 #endif 28473859Sml29623 28483859Sml29623 nxgep->nxge_port_tx_ring_size = nxge_tx_ring_size; 28493859Sml29623 28503859Sml29623 num_chunks = (uint32_t *)KMEM_ZALLOC( 28516495Sspeer sizeof (uint32_t) * tdc_max, KM_SLEEP); 28526495Sspeer 28536495Sspeer dma_poolp->ndmas = p_cfgp->tdc.owned; 28543859Sml29623 dma_poolp->num_chunks = num_chunks; 28553859Sml29623 dma_poolp->dma_buf_pool_p = dma_buf_p; 28563859Sml29623 nxgep->tx_buf_pool_p = dma_poolp; 28573859Sml29623 28586495Sspeer dma_poolp->buf_allocated = B_TRUE; 28596495Sspeer 28606495Sspeer dma_cntl_poolp->ndmas = p_cfgp->tdc.owned; 28613859Sml29623 dma_cntl_poolp->dma_buf_pool_p = dma_cntl_p; 28623859Sml29623 nxgep->tx_cntl_pool_p = dma_cntl_poolp; 28633859Sml29623 28646495Sspeer dma_cntl_poolp->buf_allocated = B_TRUE; 28656495Sspeer 28666495Sspeer nxgep->tx_rings = 28676495Sspeer KMEM_ZALLOC(sizeof (tx_rings_t), KM_SLEEP); 28686495Sspeer nxgep->tx_rings->rings = 28696495Sspeer KMEM_ZALLOC(sizeof (p_tx_ring_t) * tdc_max, KM_SLEEP); 28706495Sspeer nxgep->tx_mbox_areas_p = 28716495Sspeer KMEM_ZALLOC(sizeof (tx_mbox_areas_t), KM_SLEEP); 28726495Sspeer nxgep->tx_mbox_areas_p->txmbox_areas_p = 28736495Sspeer KMEM_ZALLOC(sizeof (p_tx_mbox_t) * tdc_max, KM_SLEEP); 28746495Sspeer 28756495Sspeer nxgep->tx_rings->ndmas = p_cfgp->tdc.owned; 28766495Sspeer 28773859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM_CTL, 28786495Sspeer "==> nxge_alloc_tx_mem_pool: ndmas %d poolp->ndmas %d", 28796495Sspeer tdc_max, dma_poolp->ndmas)); 28806495Sspeer 28816495Sspeer return (NXGE_OK); 28823859Sml29623 } 28833859Sml29623 28846495Sspeer nxge_status_t 28853859Sml29623 nxge_alloc_tx_buf_dma(p_nxge_t nxgep, uint16_t dma_channel, 28863859Sml29623 p_nxge_dma_common_t *dmap, size_t alloc_size, 28873859Sml29623 size_t block_size, uint32_t *num_chunks) 28883859Sml29623 { 28893859Sml29623 p_nxge_dma_common_t tx_dmap; 28903859Sml29623 nxge_status_t status = NXGE_OK; 28913859Sml29623 size_t total_alloc_size; 28923859Sml29623 size_t allocated = 0; 28933859Sml29623 int i, size_index, array_size; 28943859Sml29623 28953859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_alloc_tx_buf_dma")); 28963859Sml29623 28973859Sml29623 tx_dmap = (p_nxge_dma_common_t) 28983859Sml29623 KMEM_ZALLOC(sizeof (nxge_dma_common_t) * NXGE_DMA_BLOCK, 28993859Sml29623 KM_SLEEP); 29003859Sml29623 29013859Sml29623 total_alloc_size = alloc_size; 29023859Sml29623 i = 0; 29033859Sml29623 size_index = 0; 29043859Sml29623 array_size = sizeof (alloc_sizes) / sizeof (size_t); 29053859Sml29623 while ((alloc_sizes[size_index] < alloc_size) && 29063859Sml29623 (size_index < array_size)) 29073859Sml29623 size_index++; 29083859Sml29623 if (size_index >= array_size) { 29093859Sml29623 size_index = array_size - 1; 29103859Sml29623 } 29113859Sml29623 29123859Sml29623 while ((allocated < total_alloc_size) && 29133859Sml29623 (size_index >= 0) && (i < NXGE_DMA_BLOCK)) { 29143859Sml29623 29153859Sml29623 tx_dmap[i].dma_chunk_index = i; 29163859Sml29623 tx_dmap[i].block_size = block_size; 29173859Sml29623 tx_dmap[i].alength = alloc_sizes[size_index]; 29183859Sml29623 tx_dmap[i].orig_alength = tx_dmap[i].alength; 29193859Sml29623 tx_dmap[i].nblocks = alloc_sizes[size_index] / block_size; 29203859Sml29623 tx_dmap[i].dma_channel = dma_channel; 29213859Sml29623 tx_dmap[i].contig_alloc_type = B_FALSE; 29226495Sspeer tx_dmap[i].kmem_alloc_type = B_FALSE; 29233859Sml29623 29243859Sml29623 /* 29253859Sml29623 * N2/NIU: data buffers must be contiguous as the driver 29263859Sml29623 * needs to call Hypervisor api to set up 29273859Sml29623 * logical pages. 29283859Sml29623 */ 29293859Sml29623 if ((nxgep->niu_type == N2_NIU) && (NXGE_DMA_BLOCK == 1)) { 29303859Sml29623 tx_dmap[i].contig_alloc_type = B_TRUE; 29313859Sml29623 } 29323859Sml29623 29333859Sml29623 status = nxge_dma_mem_alloc(nxgep, nxge_force_dma, 29343859Sml29623 &nxge_tx_dma_attr, 29353859Sml29623 tx_dmap[i].alength, 29363859Sml29623 &nxge_dev_buf_dma_acc_attr, 29373859Sml29623 DDI_DMA_WRITE | DDI_DMA_STREAMING, 29383859Sml29623 (p_nxge_dma_common_t)(&tx_dmap[i])); 29393859Sml29623 if (status != NXGE_OK) { 29403859Sml29623 size_index--; 29413859Sml29623 } else { 29423859Sml29623 i++; 29433859Sml29623 allocated += alloc_sizes[size_index]; 29443859Sml29623 } 29453859Sml29623 } 29463859Sml29623 29473859Sml29623 if (allocated < total_alloc_size) { 29485770Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 29495770Sml29623 "==> nxge_alloc_tx_buf_dma: not enough channel %d: " 29505770Sml29623 "allocated 0x%x requested 0x%x", 29515770Sml29623 dma_channel, 29525770Sml29623 allocated, total_alloc_size)); 29535770Sml29623 status = NXGE_ERROR; 29543859Sml29623 goto nxge_alloc_tx_mem_fail1; 29553859Sml29623 } 29563859Sml29623 29575770Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 29585770Sml29623 "==> nxge_alloc_tx_buf_dma: Allocated for channel %d: " 29595770Sml29623 "allocated 0x%x requested 0x%x", 29605770Sml29623 dma_channel, 29615770Sml29623 allocated, total_alloc_size)); 29625770Sml29623 29633859Sml29623 *num_chunks = i; 29643859Sml29623 *dmap = tx_dmap; 29653859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, 29663859Sml29623 "==> nxge_alloc_tx_buf_dma dmap 0x%016llx num chunks %d", 29673859Sml29623 *dmap, i)); 29683859Sml29623 goto nxge_alloc_tx_mem_exit; 29693859Sml29623 29703859Sml29623 nxge_alloc_tx_mem_fail1: 29713859Sml29623 KMEM_FREE(tx_dmap, sizeof (nxge_dma_common_t) * NXGE_DMA_BLOCK); 29723859Sml29623 29733859Sml29623 nxge_alloc_tx_mem_exit: 29743859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, 29753859Sml29623 "<== nxge_alloc_tx_buf_dma status 0x%08x", status)); 29763859Sml29623 29773859Sml29623 return (status); 29783859Sml29623 } 29793859Sml29623 29803859Sml29623 /*ARGSUSED*/ 29813859Sml29623 static void 29823859Sml29623 nxge_free_tx_buf_dma(p_nxge_t nxgep, p_nxge_dma_common_t dmap, 29833859Sml29623 uint32_t num_chunks) 29843859Sml29623 { 29853859Sml29623 int i; 29863859Sml29623 29873859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM_CTL, "==> nxge_free_tx_buf_dma")); 29883859Sml29623 29896495Sspeer if (dmap == 0) 29906495Sspeer return; 29916495Sspeer 29923859Sml29623 for (i = 0; i < num_chunks; i++) { 29933859Sml29623 nxge_dma_mem_free(dmap++); 29943859Sml29623 } 29953859Sml29623 29963859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM_CTL, "<== nxge_free_tx_buf_dma")); 29973859Sml29623 } 29983859Sml29623 29993859Sml29623 /*ARGSUSED*/ 30006495Sspeer nxge_status_t 30013859Sml29623 nxge_alloc_tx_cntl_dma(p_nxge_t nxgep, uint16_t dma_channel, 30023859Sml29623 p_nxge_dma_common_t *dmap, size_t size) 30033859Sml29623 { 30043859Sml29623 p_nxge_dma_common_t tx_dmap; 30053859Sml29623 nxge_status_t status = NXGE_OK; 30063859Sml29623 30073859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_alloc_tx_cntl_dma")); 30083859Sml29623 tx_dmap = (p_nxge_dma_common_t) 30093859Sml29623 KMEM_ZALLOC(sizeof (nxge_dma_common_t), KM_SLEEP); 30103859Sml29623 30113859Sml29623 tx_dmap->contig_alloc_type = B_FALSE; 30126495Sspeer tx_dmap->kmem_alloc_type = B_FALSE; 30133859Sml29623 30143859Sml29623 status = nxge_dma_mem_alloc(nxgep, nxge_force_dma, 30153859Sml29623 &nxge_desc_dma_attr, 30163859Sml29623 size, 30173859Sml29623 &nxge_dev_desc_dma_acc_attr, 30183859Sml29623 DDI_DMA_RDWR | DDI_DMA_CONSISTENT, 30193859Sml29623 tx_dmap); 30203859Sml29623 if (status != NXGE_OK) { 30213859Sml29623 goto nxge_alloc_tx_cntl_dma_fail1; 30223859Sml29623 } 30233859Sml29623 30243859Sml29623 *dmap = tx_dmap; 30253859Sml29623 goto nxge_alloc_tx_cntl_dma_exit; 30263859Sml29623 30273859Sml29623 nxge_alloc_tx_cntl_dma_fail1: 30283859Sml29623 KMEM_FREE(tx_dmap, sizeof (nxge_dma_common_t)); 30293859Sml29623 30303859Sml29623 nxge_alloc_tx_cntl_dma_exit: 30313859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, 30323859Sml29623 "<== nxge_alloc_tx_cntl_dma status 0x%08x", status)); 30333859Sml29623 30343859Sml29623 return (status); 30353859Sml29623 } 30363859Sml29623 30373859Sml29623 /*ARGSUSED*/ 30383859Sml29623 static void 30393859Sml29623 nxge_free_tx_cntl_dma(p_nxge_t nxgep, p_nxge_dma_common_t dmap) 30403859Sml29623 { 30413859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_free_tx_cntl_dma")); 30423859Sml29623 30436495Sspeer if (dmap == 0) 30446495Sspeer return; 30456495Sspeer 30463859Sml29623 nxge_dma_mem_free(dmap); 30473859Sml29623 30483859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_free_tx_cntl_dma")); 30493859Sml29623 } 30503859Sml29623 30516495Sspeer /* 30526495Sspeer * nxge_free_tx_mem_pool 30536495Sspeer * 30546495Sspeer * This function frees all of the per-port TDC control data structures. 30556495Sspeer * The per-channel (TDC) data structures are freed when the channel 30566495Sspeer * is stopped. 30576495Sspeer * 30586495Sspeer * Arguments: 30596495Sspeer * nxgep 30606495Sspeer * 30616495Sspeer * Notes: 30626495Sspeer * 30636495Sspeer * Context: 30646495Sspeer * Any domain 30656495Sspeer */ 30663859Sml29623 static void 30673859Sml29623 nxge_free_tx_mem_pool(p_nxge_t nxgep) 30683859Sml29623 { 30696495Sspeer int tdc_max = NXGE_MAX_TDCS; 30706495Sspeer 30716495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_free_tx_mem_pool")); 30726495Sspeer 30736495Sspeer if (!nxgep->tx_buf_pool_p || !nxgep->tx_buf_pool_p->buf_allocated) { 30746495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 30753859Sml29623 "<== nxge_free_tx_mem_pool " 30766495Sspeer "(null tx buf pool or buf not allocated")); 30773859Sml29623 return; 30783859Sml29623 } 30796495Sspeer if (!nxgep->tx_cntl_pool_p || !nxgep->tx_cntl_pool_p->buf_allocated) { 30806495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 30813859Sml29623 "<== nxge_free_tx_mem_pool " 30823859Sml29623 "(null tx cntl buf pool or cntl buf not allocated")); 30833859Sml29623 return; 30843859Sml29623 } 30853859Sml29623 30866495Sspeer /* 1. Free the mailboxes. */ 30876495Sspeer KMEM_FREE(nxgep->tx_mbox_areas_p->txmbox_areas_p, 30886495Sspeer sizeof (p_tx_mbox_t) * tdc_max); 30896495Sspeer KMEM_FREE(nxgep->tx_mbox_areas_p, sizeof (tx_mbox_areas_t)); 30906495Sspeer 30916495Sspeer nxgep->tx_mbox_areas_p = 0; 30926495Sspeer 30936495Sspeer /* 2. Free the transmit ring arrays. */ 30946495Sspeer KMEM_FREE(nxgep->tx_rings->rings, 30956495Sspeer sizeof (p_tx_ring_t) * tdc_max); 30966495Sspeer KMEM_FREE(nxgep->tx_rings, sizeof (tx_rings_t)); 30976495Sspeer 30986495Sspeer nxgep->tx_rings = 0; 30996495Sspeer 31006495Sspeer /* 3. Free the completion ring data structures. */ 31016495Sspeer KMEM_FREE(nxgep->tx_cntl_pool_p->dma_buf_pool_p, 31026495Sspeer sizeof (p_nxge_dma_common_t) * tdc_max); 31036495Sspeer KMEM_FREE(nxgep->tx_cntl_pool_p, sizeof (nxge_dma_pool_t)); 31046495Sspeer 31056495Sspeer nxgep->tx_cntl_pool_p = 0; 31066495Sspeer 31076495Sspeer /* 4. Free the data ring data structures. */ 31086495Sspeer KMEM_FREE(nxgep->tx_buf_pool_p->num_chunks, 31096495Sspeer sizeof (uint32_t) * tdc_max); 31106495Sspeer KMEM_FREE(nxgep->tx_buf_pool_p->dma_buf_pool_p, 31116495Sspeer sizeof (p_nxge_dma_common_t) * tdc_max); 31126495Sspeer KMEM_FREE(nxgep->tx_buf_pool_p, sizeof (nxge_dma_pool_t)); 31136495Sspeer 31146495Sspeer nxgep->tx_buf_pool_p = 0; 31156495Sspeer 31166495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "<== nxge_free_tx_mem_pool")); 31173859Sml29623 } 31183859Sml29623 31193859Sml29623 /*ARGSUSED*/ 31203859Sml29623 static nxge_status_t 31213859Sml29623 nxge_dma_mem_alloc(p_nxge_t nxgep, dma_method_t method, 31223859Sml29623 struct ddi_dma_attr *dma_attrp, 31233859Sml29623 size_t length, ddi_device_acc_attr_t *acc_attr_p, uint_t xfer_flags, 31243859Sml29623 p_nxge_dma_common_t dma_p) 31253859Sml29623 { 31263859Sml29623 caddr_t kaddrp; 31273859Sml29623 int ddi_status = DDI_SUCCESS; 31283859Sml29623 boolean_t contig_alloc_type; 31296495Sspeer boolean_t kmem_alloc_type; 31303859Sml29623 31313859Sml29623 contig_alloc_type = dma_p->contig_alloc_type; 31323859Sml29623 31333859Sml29623 if (contig_alloc_type && (nxgep->niu_type != N2_NIU)) { 31343859Sml29623 /* 31353859Sml29623 * contig_alloc_type for contiguous memory only allowed 31363859Sml29623 * for N2/NIU. 31373859Sml29623 */ 31383859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 31396495Sspeer "nxge_dma_mem_alloc: alloc type not allowed (%d)", 31403859Sml29623 dma_p->contig_alloc_type)); 31413859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 31423859Sml29623 } 31433859Sml29623 31443859Sml29623 dma_p->dma_handle = NULL; 31453859Sml29623 dma_p->acc_handle = NULL; 31463859Sml29623 dma_p->kaddrp = dma_p->last_kaddrp = NULL; 31473859Sml29623 dma_p->first_ioaddr_pp = dma_p->last_ioaddr_pp = NULL; 31483859Sml29623 ddi_status = ddi_dma_alloc_handle(nxgep->dip, dma_attrp, 31493859Sml29623 DDI_DMA_DONTWAIT, NULL, &dma_p->dma_handle); 31503859Sml29623 if (ddi_status != DDI_SUCCESS) { 31513859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 31523859Sml29623 "nxge_dma_mem_alloc:ddi_dma_alloc_handle failed.")); 31533859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 31543859Sml29623 } 31553859Sml29623 31566495Sspeer kmem_alloc_type = dma_p->kmem_alloc_type; 31576495Sspeer 31583859Sml29623 switch (contig_alloc_type) { 31593859Sml29623 case B_FALSE: 31606495Sspeer switch (kmem_alloc_type) { 31616495Sspeer case B_FALSE: 31626495Sspeer ddi_status = ddi_dma_mem_alloc(dma_p->dma_handle, 31636495Sspeer length, 31646495Sspeer acc_attr_p, 31656495Sspeer xfer_flags, 31666495Sspeer DDI_DMA_DONTWAIT, 0, &kaddrp, &dma_p->alength, 31676495Sspeer &dma_p->acc_handle); 31686495Sspeer if (ddi_status != DDI_SUCCESS) { 31696495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 31706495Sspeer "nxge_dma_mem_alloc: " 31716495Sspeer "ddi_dma_mem_alloc failed")); 31726495Sspeer ddi_dma_free_handle(&dma_p->dma_handle); 31736495Sspeer dma_p->dma_handle = NULL; 31746495Sspeer return (NXGE_ERROR | NXGE_DDI_FAILED); 31756495Sspeer } 31766495Sspeer if (dma_p->alength < length) { 31776495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 31786495Sspeer "nxge_dma_mem_alloc:di_dma_mem_alloc " 31796495Sspeer "< length.")); 31806495Sspeer ddi_dma_mem_free(&dma_p->acc_handle); 31816495Sspeer ddi_dma_free_handle(&dma_p->dma_handle); 31826495Sspeer dma_p->acc_handle = NULL; 31836495Sspeer dma_p->dma_handle = NULL; 31846495Sspeer return (NXGE_ERROR); 31856495Sspeer } 31866495Sspeer 31876495Sspeer ddi_status = ddi_dma_addr_bind_handle(dma_p->dma_handle, 31886495Sspeer NULL, 31896495Sspeer kaddrp, dma_p->alength, xfer_flags, 31906495Sspeer DDI_DMA_DONTWAIT, 31916495Sspeer 0, &dma_p->dma_cookie, &dma_p->ncookies); 31926495Sspeer if (ddi_status != DDI_DMA_MAPPED) { 31936495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 31946495Sspeer "nxge_dma_mem_alloc: ddi_dma_addr_bind " 31956495Sspeer "failed " 31966495Sspeer "(staus 0x%x ncookies %d.)", ddi_status, 31976495Sspeer dma_p->ncookies)); 31986495Sspeer if (dma_p->acc_handle) { 31996495Sspeer ddi_dma_mem_free(&dma_p->acc_handle); 32006495Sspeer dma_p->acc_handle = NULL; 32016495Sspeer } 32026495Sspeer ddi_dma_free_handle(&dma_p->dma_handle); 32036495Sspeer dma_p->dma_handle = NULL; 32046495Sspeer return (NXGE_ERROR | NXGE_DDI_FAILED); 32056495Sspeer } 32066495Sspeer 32076495Sspeer if (dma_p->ncookies != 1) { 32086495Sspeer NXGE_DEBUG_MSG((nxgep, DMA_CTL, 32096495Sspeer "nxge_dma_mem_alloc:ddi_dma_addr_bind " 32106495Sspeer "> 1 cookie" 32116495Sspeer "(staus 0x%x ncookies %d.)", ddi_status, 32126495Sspeer dma_p->ncookies)); 32136495Sspeer if (dma_p->acc_handle) { 32146495Sspeer ddi_dma_mem_free(&dma_p->acc_handle); 32156495Sspeer dma_p->acc_handle = NULL; 32166495Sspeer } 32176495Sspeer (void) ddi_dma_unbind_handle(dma_p->dma_handle); 32186495Sspeer ddi_dma_free_handle(&dma_p->dma_handle); 32196495Sspeer dma_p->dma_handle = NULL; 32206495Sspeer return (NXGE_ERROR); 32216495Sspeer } 32226495Sspeer break; 32236495Sspeer 32246495Sspeer case B_TRUE: 32256495Sspeer kaddrp = KMEM_ALLOC(length, KM_NOSLEEP); 32266495Sspeer if (kaddrp == NULL) { 32276495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 32286495Sspeer "nxge_dma_mem_alloc:ddi_dma_mem_alloc " 32296495Sspeer "kmem alloc failed")); 32306495Sspeer return (NXGE_ERROR); 32316495Sspeer } 32326495Sspeer 32336495Sspeer dma_p->alength = length; 32346495Sspeer ddi_status = ddi_dma_addr_bind_handle(dma_p->dma_handle, 32356495Sspeer NULL, kaddrp, dma_p->alength, xfer_flags, 32366495Sspeer DDI_DMA_DONTWAIT, 0, 32376495Sspeer &dma_p->dma_cookie, &dma_p->ncookies); 32386495Sspeer if (ddi_status != DDI_DMA_MAPPED) { 32396495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 32406495Sspeer "nxge_dma_mem_alloc:ddi_dma_addr_bind: " 32416495Sspeer "(kmem_alloc) failed kaddrp $%p length %d " 32426495Sspeer "(staus 0x%x (%d) ncookies %d.)", 32436495Sspeer kaddrp, length, 32446495Sspeer ddi_status, ddi_status, dma_p->ncookies)); 32456495Sspeer KMEM_FREE(kaddrp, length); 32466495Sspeer dma_p->acc_handle = NULL; 32476495Sspeer ddi_dma_free_handle(&dma_p->dma_handle); 32486495Sspeer dma_p->dma_handle = NULL; 32496495Sspeer dma_p->kaddrp = NULL; 32506495Sspeer return (NXGE_ERROR | NXGE_DDI_FAILED); 32516495Sspeer } 32526495Sspeer 32536495Sspeer if (dma_p->ncookies != 1) { 32546495Sspeer NXGE_DEBUG_MSG((nxgep, DMA_CTL, 32556495Sspeer "nxge_dma_mem_alloc:ddi_dma_addr_bind " 32566495Sspeer "(kmem_alloc) > 1 cookie" 32576495Sspeer "(staus 0x%x ncookies %d.)", ddi_status, 32583859Sml29623 dma_p->ncookies)); 32596495Sspeer KMEM_FREE(kaddrp, length); 32603859Sml29623 dma_p->acc_handle = NULL; 32616495Sspeer (void) ddi_dma_unbind_handle(dma_p->dma_handle); 32626495Sspeer ddi_dma_free_handle(&dma_p->dma_handle); 32636495Sspeer dma_p->dma_handle = NULL; 32646495Sspeer dma_p->kaddrp = NULL; 32656495Sspeer return (NXGE_ERROR); 32663859Sml29623 } 32676495Sspeer 32686495Sspeer dma_p->kaddrp = kaddrp; 32696495Sspeer 32706495Sspeer NXGE_DEBUG_MSG((nxgep, NXGE_ERR_CTL, 32716495Sspeer "nxge_dma_mem_alloc: kmem_alloc dmap $%p " 32726495Sspeer "kaddr $%p alength %d", 32736495Sspeer dma_p, 32746495Sspeer kaddrp, 32756495Sspeer dma_p->alength)); 32766495Sspeer break; 32773859Sml29623 } 32783859Sml29623 break; 32793859Sml29623 32803859Sml29623 #if defined(sun4v) && defined(NIU_LP_WORKAROUND) 32813859Sml29623 case B_TRUE: 32823859Sml29623 kaddrp = (caddr_t)contig_mem_alloc(length); 32833859Sml29623 if (kaddrp == NULL) { 32843859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 32853859Sml29623 "nxge_dma_mem_alloc:contig_mem_alloc failed.")); 32863859Sml29623 ddi_dma_free_handle(&dma_p->dma_handle); 32873859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 32883859Sml29623 } 32893859Sml29623 32903859Sml29623 dma_p->alength = length; 32913859Sml29623 ddi_status = ddi_dma_addr_bind_handle(dma_p->dma_handle, NULL, 32923859Sml29623 kaddrp, dma_p->alength, xfer_flags, DDI_DMA_DONTWAIT, 0, 32933859Sml29623 &dma_p->dma_cookie, &dma_p->ncookies); 32943859Sml29623 if (ddi_status != DDI_DMA_MAPPED) { 32953859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 32963859Sml29623 "nxge_dma_mem_alloc:di_dma_addr_bind failed " 32973859Sml29623 "(status 0x%x ncookies %d.)", ddi_status, 32983859Sml29623 dma_p->ncookies)); 32993859Sml29623 33003859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, 33013859Sml29623 "==> nxge_dma_mem_alloc: (not mapped)" 33023859Sml29623 "length %lu (0x%x) " 33033859Sml29623 "free contig kaddrp $%p " 33043859Sml29623 "va_to_pa $%p", 33053859Sml29623 length, length, 33063859Sml29623 kaddrp, 33073859Sml29623 va_to_pa(kaddrp))); 33083859Sml29623 33093859Sml29623 33103859Sml29623 contig_mem_free((void *)kaddrp, length); 33113859Sml29623 ddi_dma_free_handle(&dma_p->dma_handle); 33123859Sml29623 33133859Sml29623 dma_p->dma_handle = NULL; 33143859Sml29623 dma_p->acc_handle = NULL; 33153859Sml29623 dma_p->alength = NULL; 33163859Sml29623 dma_p->kaddrp = NULL; 33173859Sml29623 33183859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 33193859Sml29623 } 33203859Sml29623 33213859Sml29623 if (dma_p->ncookies != 1 || 33223859Sml29623 (dma_p->dma_cookie.dmac_laddress == NULL)) { 33233859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 33243859Sml29623 "nxge_dma_mem_alloc:di_dma_addr_bind > 1 " 33253859Sml29623 "cookie or " 33263859Sml29623 "dmac_laddress is NULL $%p size %d " 33273859Sml29623 " (status 0x%x ncookies %d.)", 33283859Sml29623 ddi_status, 33293859Sml29623 dma_p->dma_cookie.dmac_laddress, 33303859Sml29623 dma_p->dma_cookie.dmac_size, 33313859Sml29623 dma_p->ncookies)); 33323859Sml29623 33333859Sml29623 contig_mem_free((void *)kaddrp, length); 33344185Sspeer (void) ddi_dma_unbind_handle(dma_p->dma_handle); 33353859Sml29623 ddi_dma_free_handle(&dma_p->dma_handle); 33363859Sml29623 33373859Sml29623 dma_p->alength = 0; 33383859Sml29623 dma_p->dma_handle = NULL; 33393859Sml29623 dma_p->acc_handle = NULL; 33403859Sml29623 dma_p->kaddrp = NULL; 33413859Sml29623 33423859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 33433859Sml29623 } 33443859Sml29623 break; 33453859Sml29623 33463859Sml29623 #else 33473859Sml29623 case B_TRUE: 33483859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 33493859Sml29623 "nxge_dma_mem_alloc: invalid alloc type for !sun4v")); 33503859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 33513859Sml29623 #endif 33523859Sml29623 } 33533859Sml29623 33543859Sml29623 dma_p->kaddrp = kaddrp; 33553859Sml29623 dma_p->last_kaddrp = (unsigned char *)kaddrp + 33563859Sml29623 dma_p->alength - RXBUF_64B_ALIGNED; 33575125Sjoycey #if defined(__i386) 33585125Sjoycey dma_p->ioaddr_pp = 33595125Sjoycey (unsigned char *)(uint32_t)dma_p->dma_cookie.dmac_laddress; 33605125Sjoycey #else 33613859Sml29623 dma_p->ioaddr_pp = (unsigned char *)dma_p->dma_cookie.dmac_laddress; 33625125Sjoycey #endif 33633859Sml29623 dma_p->last_ioaddr_pp = 33645125Sjoycey #if defined(__i386) 33655125Sjoycey (unsigned char *)(uint32_t)dma_p->dma_cookie.dmac_laddress + 33665125Sjoycey #else 33673859Sml29623 (unsigned char *)dma_p->dma_cookie.dmac_laddress + 33685125Sjoycey #endif 33693859Sml29623 dma_p->alength - RXBUF_64B_ALIGNED; 33703859Sml29623 33713859Sml29623 NPI_DMA_ACC_HANDLE_SET(dma_p, dma_p->acc_handle); 33723859Sml29623 33733859Sml29623 #if defined(sun4v) && defined(NIU_LP_WORKAROUND) 33743859Sml29623 dma_p->orig_ioaddr_pp = 33753859Sml29623 (unsigned char *)dma_p->dma_cookie.dmac_laddress; 33763859Sml29623 dma_p->orig_alength = length; 33773859Sml29623 dma_p->orig_kaddrp = kaddrp; 33783859Sml29623 dma_p->orig_vatopa = (uint64_t)va_to_pa(kaddrp); 33793859Sml29623 #endif 33803859Sml29623 33813859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_dma_mem_alloc: " 33823859Sml29623 "dma buffer allocated: dma_p $%p " 33833859Sml29623 "return dmac_ladress from cookie $%p cookie dmac_size %d " 33843859Sml29623 "dma_p->ioaddr_p $%p " 33853859Sml29623 "dma_p->orig_ioaddr_p $%p " 33863859Sml29623 "orig_vatopa $%p " 33873859Sml29623 "alength %d (0x%x) " 33883859Sml29623 "kaddrp $%p " 33893859Sml29623 "length %d (0x%x)", 33903859Sml29623 dma_p, 33913859Sml29623 dma_p->dma_cookie.dmac_laddress, dma_p->dma_cookie.dmac_size, 33923859Sml29623 dma_p->ioaddr_pp, 33933859Sml29623 dma_p->orig_ioaddr_pp, 33943859Sml29623 dma_p->orig_vatopa, 33953859Sml29623 dma_p->alength, dma_p->alength, 33963859Sml29623 kaddrp, 33973859Sml29623 length, length)); 33983859Sml29623 33993859Sml29623 return (NXGE_OK); 34003859Sml29623 } 34013859Sml29623 34023859Sml29623 static void 34033859Sml29623 nxge_dma_mem_free(p_nxge_dma_common_t dma_p) 34043859Sml29623 { 34053859Sml29623 if (dma_p->dma_handle != NULL) { 34063859Sml29623 if (dma_p->ncookies) { 34073859Sml29623 (void) ddi_dma_unbind_handle(dma_p->dma_handle); 34083859Sml29623 dma_p->ncookies = 0; 34093859Sml29623 } 34103859Sml29623 ddi_dma_free_handle(&dma_p->dma_handle); 34113859Sml29623 dma_p->dma_handle = NULL; 34123859Sml29623 } 34133859Sml29623 34143859Sml29623 if (dma_p->acc_handle != NULL) { 34153859Sml29623 ddi_dma_mem_free(&dma_p->acc_handle); 34163859Sml29623 dma_p->acc_handle = NULL; 34173859Sml29623 NPI_DMA_ACC_HANDLE_SET(dma_p, NULL); 34183859Sml29623 } 34193859Sml29623 34203859Sml29623 #if defined(sun4v) && defined(NIU_LP_WORKAROUND) 34213859Sml29623 if (dma_p->contig_alloc_type && 34223859Sml29623 dma_p->orig_kaddrp && dma_p->orig_alength) { 34233859Sml29623 NXGE_DEBUG_MSG((NULL, DMA_CTL, "nxge_dma_mem_free: " 34243859Sml29623 "kaddrp $%p (orig_kaddrp $%p)" 34253859Sml29623 "mem type %d ", 34263859Sml29623 "orig_alength %d " 34273859Sml29623 "alength 0x%x (%d)", 34283859Sml29623 dma_p->kaddrp, 34293859Sml29623 dma_p->orig_kaddrp, 34303859Sml29623 dma_p->contig_alloc_type, 34313859Sml29623 dma_p->orig_alength, 34323859Sml29623 dma_p->alength, dma_p->alength)); 34333859Sml29623 34343859Sml29623 contig_mem_free(dma_p->orig_kaddrp, dma_p->orig_alength); 34353859Sml29623 dma_p->orig_alength = NULL; 34363859Sml29623 dma_p->orig_kaddrp = NULL; 34373859Sml29623 dma_p->contig_alloc_type = B_FALSE; 34383859Sml29623 } 34393859Sml29623 #endif 34403859Sml29623 dma_p->kaddrp = NULL; 34413859Sml29623 dma_p->alength = NULL; 34423859Sml29623 } 34433859Sml29623 34446495Sspeer static void 34456495Sspeer nxge_dma_free_rx_data_buf(p_nxge_dma_common_t dma_p) 34466495Sspeer { 34476495Sspeer uint64_t kaddr; 34486495Sspeer uint32_t buf_size; 34496495Sspeer 34506495Sspeer NXGE_DEBUG_MSG((NULL, DMA_CTL, "==> nxge_dma_free_rx_data_buf")); 34516495Sspeer 34526495Sspeer if (dma_p->dma_handle != NULL) { 34536495Sspeer if (dma_p->ncookies) { 34546495Sspeer (void) ddi_dma_unbind_handle(dma_p->dma_handle); 34556495Sspeer dma_p->ncookies = 0; 34566495Sspeer } 34576495Sspeer ddi_dma_free_handle(&dma_p->dma_handle); 34586495Sspeer dma_p->dma_handle = NULL; 34596495Sspeer } 34606495Sspeer 34616495Sspeer if (dma_p->acc_handle != NULL) { 34626495Sspeer ddi_dma_mem_free(&dma_p->acc_handle); 34636495Sspeer dma_p->acc_handle = NULL; 34646495Sspeer NPI_DMA_ACC_HANDLE_SET(dma_p, NULL); 34656495Sspeer } 34666495Sspeer 34676495Sspeer NXGE_DEBUG_MSG((NULL, DMA_CTL, 34686495Sspeer "==> nxge_dma_free_rx_data_buf: dmap $%p buf_alloc_state %d", 34696495Sspeer dma_p, 34706495Sspeer dma_p->buf_alloc_state)); 34716495Sspeer 34726495Sspeer if (!(dma_p->buf_alloc_state & BUF_ALLOCATED_WAIT_FREE)) { 34736495Sspeer NXGE_DEBUG_MSG((NULL, DMA_CTL, 34746495Sspeer "<== nxge_dma_free_rx_data_buf: " 34756495Sspeer "outstanding data buffers")); 34766495Sspeer return; 34776495Sspeer } 34786495Sspeer 34796495Sspeer #if defined(sun4v) && defined(NIU_LP_WORKAROUND) 34806495Sspeer if (dma_p->contig_alloc_type && 34816495Sspeer dma_p->orig_kaddrp && dma_p->orig_alength) { 34826495Sspeer NXGE_DEBUG_MSG((NULL, DMA_CTL, "nxge_dma_free_rx_data_buf: " 34836495Sspeer "kaddrp $%p (orig_kaddrp $%p)" 34846495Sspeer "mem type %d ", 34856495Sspeer "orig_alength %d " 34866495Sspeer "alength 0x%x (%d)", 34876495Sspeer dma_p->kaddrp, 34886495Sspeer dma_p->orig_kaddrp, 34896495Sspeer dma_p->contig_alloc_type, 34906495Sspeer dma_p->orig_alength, 34916495Sspeer dma_p->alength, dma_p->alength)); 34926495Sspeer 34936495Sspeer kaddr = (uint64_t)dma_p->orig_kaddrp; 34946495Sspeer buf_size = dma_p->orig_alength; 34956495Sspeer nxge_free_buf(CONTIG_MEM_ALLOC, kaddr, buf_size); 34966495Sspeer dma_p->orig_alength = NULL; 34976495Sspeer dma_p->orig_kaddrp = NULL; 34986495Sspeer dma_p->contig_alloc_type = B_FALSE; 34996495Sspeer dma_p->kaddrp = NULL; 35006495Sspeer dma_p->alength = NULL; 35016495Sspeer return; 35026495Sspeer } 35036495Sspeer #endif 35046495Sspeer 35056495Sspeer if (dma_p->kmem_alloc_type) { 35066495Sspeer NXGE_DEBUG_MSG((NULL, DMA_CTL, 35076495Sspeer "nxge_dma_free_rx_data_buf: free kmem " 35086495Sspeer "kaddrp $%p (orig_kaddrp $%p)" 35096495Sspeer "alloc type %d " 35106495Sspeer "orig_alength %d " 35116495Sspeer "alength 0x%x (%d)", 35126495Sspeer dma_p->kaddrp, 35136495Sspeer dma_p->orig_kaddrp, 35146495Sspeer dma_p->kmem_alloc_type, 35156495Sspeer dma_p->orig_alength, 35166495Sspeer dma_p->alength, dma_p->alength)); 35176495Sspeer #if defined(__i386) 35186495Sspeer kaddr = (uint64_t)(uint32_t)dma_p->kaddrp; 35196495Sspeer #else 35206495Sspeer kaddr = (uint64_t)dma_p->kaddrp; 35216495Sspeer #endif 35226495Sspeer buf_size = dma_p->orig_alength; 35236495Sspeer NXGE_DEBUG_MSG((NULL, DMA_CTL, 35246495Sspeer "nxge_dma_free_rx_data_buf: free dmap $%p " 35256495Sspeer "kaddr $%p buf_size %d", 35266495Sspeer dma_p, 35276495Sspeer kaddr, buf_size)); 35286495Sspeer nxge_free_buf(KMEM_ALLOC, kaddr, buf_size); 35296495Sspeer dma_p->alength = 0; 35306495Sspeer dma_p->orig_alength = 0; 35316495Sspeer dma_p->kaddrp = NULL; 35326495Sspeer dma_p->kmem_alloc_type = B_FALSE; 35336495Sspeer } 35346495Sspeer 35356495Sspeer NXGE_DEBUG_MSG((NULL, DMA_CTL, "<== nxge_dma_free_rx_data_buf")); 35366495Sspeer } 35376495Sspeer 35383859Sml29623 /* 35393859Sml29623 * nxge_m_start() -- start transmitting and receiving. 35403859Sml29623 * 35413859Sml29623 * This function is called by the MAC layer when the first 35423859Sml29623 * stream is open to prepare the hardware ready for sending 35433859Sml29623 * and transmitting packets. 35443859Sml29623 */ 35453859Sml29623 static int 35463859Sml29623 nxge_m_start(void *arg) 35473859Sml29623 { 35483859Sml29623 p_nxge_t nxgep = (p_nxge_t)arg; 35493859Sml29623 35503859Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, "==> nxge_m_start")); 35513859Sml29623 35523859Sml29623 MUTEX_ENTER(nxgep->genlock); 35533859Sml29623 if (nxge_init(nxgep) != NXGE_OK) { 35543859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 35553859Sml29623 "<== nxge_m_start: initialization failed")); 35563859Sml29623 MUTEX_EXIT(nxgep->genlock); 35573859Sml29623 return (EIO); 35583859Sml29623 } 35593859Sml29623 35603859Sml29623 if (nxgep->nxge_mac_state == NXGE_MAC_STARTED) 35613859Sml29623 goto nxge_m_start_exit; 35623859Sml29623 /* 35633859Sml29623 * Start timer to check the system error and tx hangs 35643859Sml29623 */ 35656495Sspeer if (!isLDOMguest(nxgep)) 35666495Sspeer nxgep->nxge_timerid = nxge_start_timer(nxgep, 35676495Sspeer nxge_check_hw_state, NXGE_CHECK_TIMER); 35686495Sspeer #if defined(sun4v) 35696495Sspeer else 35706495Sspeer nxge_hio_start_timer(nxgep); 35716495Sspeer #endif 35723859Sml29623 35733859Sml29623 nxgep->link_notify = B_TRUE; 35743859Sml29623 35753859Sml29623 nxgep->nxge_mac_state = NXGE_MAC_STARTED; 35763859Sml29623 35773859Sml29623 nxge_m_start_exit: 35783859Sml29623 MUTEX_EXIT(nxgep->genlock); 35793859Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, "<== nxge_m_start")); 35803859Sml29623 return (0); 35813859Sml29623 } 35823859Sml29623 35833859Sml29623 /* 35843859Sml29623 * nxge_m_stop(): stop transmitting and receiving. 35853859Sml29623 */ 35863859Sml29623 static void 35873859Sml29623 nxge_m_stop(void *arg) 35883859Sml29623 { 35893859Sml29623 p_nxge_t nxgep = (p_nxge_t)arg; 35903859Sml29623 35913859Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, "==> nxge_m_stop")); 35923859Sml29623 35933859Sml29623 if (nxgep->nxge_timerid) { 35943859Sml29623 nxge_stop_timer(nxgep, nxgep->nxge_timerid); 35953859Sml29623 nxgep->nxge_timerid = 0; 35963859Sml29623 } 35973859Sml29623 35983859Sml29623 MUTEX_ENTER(nxgep->genlock); 35996495Sspeer nxgep->nxge_mac_state = NXGE_MAC_STOPPING; 36003859Sml29623 nxge_uninit(nxgep); 36013859Sml29623 36023859Sml29623 nxgep->nxge_mac_state = NXGE_MAC_STOPPED; 36033859Sml29623 36043859Sml29623 MUTEX_EXIT(nxgep->genlock); 36053859Sml29623 36063859Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, "<== nxge_m_stop")); 36073859Sml29623 } 36083859Sml29623 36093859Sml29623 static int 36103859Sml29623 nxge_m_unicst(void *arg, const uint8_t *macaddr) 36113859Sml29623 { 36123859Sml29623 p_nxge_t nxgep = (p_nxge_t)arg; 36133859Sml29623 struct ether_addr addrp; 36143859Sml29623 36153859Sml29623 NXGE_DEBUG_MSG((nxgep, MAC_CTL, "==> nxge_m_unicst")); 36163859Sml29623 36173859Sml29623 bcopy(macaddr, (uint8_t *)&addrp, ETHERADDRL); 36183859Sml29623 if (nxge_set_mac_addr(nxgep, &addrp)) { 36193859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 36203859Sml29623 "<== nxge_m_unicst: set unitcast failed")); 36213859Sml29623 return (EINVAL); 36223859Sml29623 } 36233859Sml29623 36243859Sml29623 NXGE_DEBUG_MSG((nxgep, MAC_CTL, "<== nxge_m_unicst")); 36253859Sml29623 36263859Sml29623 return (0); 36273859Sml29623 } 36283859Sml29623 36293859Sml29623 static int 36303859Sml29623 nxge_m_multicst(void *arg, boolean_t add, const uint8_t *mca) 36313859Sml29623 { 36323859Sml29623 p_nxge_t nxgep = (p_nxge_t)arg; 36333859Sml29623 struct ether_addr addrp; 36343859Sml29623 36353859Sml29623 NXGE_DEBUG_MSG((nxgep, MAC_CTL, 36363859Sml29623 "==> nxge_m_multicst: add %d", add)); 36373859Sml29623 36383859Sml29623 bcopy(mca, (uint8_t *)&addrp, ETHERADDRL); 36393859Sml29623 if (add) { 36403859Sml29623 if (nxge_add_mcast_addr(nxgep, &addrp)) { 36413859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 36423859Sml29623 "<== nxge_m_multicst: add multicast failed")); 36433859Sml29623 return (EINVAL); 36443859Sml29623 } 36453859Sml29623 } else { 36463859Sml29623 if (nxge_del_mcast_addr(nxgep, &addrp)) { 36473859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 36483859Sml29623 "<== nxge_m_multicst: del multicast failed")); 36493859Sml29623 return (EINVAL); 36503859Sml29623 } 36513859Sml29623 } 36523859Sml29623 36533859Sml29623 NXGE_DEBUG_MSG((nxgep, MAC_CTL, "<== nxge_m_multicst")); 36543859Sml29623 36553859Sml29623 return (0); 36563859Sml29623 } 36573859Sml29623 36583859Sml29623 static int 36593859Sml29623 nxge_m_promisc(void *arg, boolean_t on) 36603859Sml29623 { 36613859Sml29623 p_nxge_t nxgep = (p_nxge_t)arg; 36623859Sml29623 36633859Sml29623 NXGE_DEBUG_MSG((nxgep, MAC_CTL, 36643859Sml29623 "==> nxge_m_promisc: on %d", on)); 36653859Sml29623 36663859Sml29623 if (nxge_set_promisc(nxgep, on)) { 36673859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 36683859Sml29623 "<== nxge_m_promisc: set promisc failed")); 36693859Sml29623 return (EINVAL); 36703859Sml29623 } 36713859Sml29623 36723859Sml29623 NXGE_DEBUG_MSG((nxgep, MAC_CTL, 36733859Sml29623 "<== nxge_m_promisc: on %d", on)); 36743859Sml29623 36753859Sml29623 return (0); 36763859Sml29623 } 36773859Sml29623 36783859Sml29623 static void 36793859Sml29623 nxge_m_ioctl(void *arg, queue_t *wq, mblk_t *mp) 36803859Sml29623 { 36813859Sml29623 p_nxge_t nxgep = (p_nxge_t)arg; 36824185Sspeer struct iocblk *iocp; 36833859Sml29623 boolean_t need_privilege; 36843859Sml29623 int err; 36853859Sml29623 int cmd; 36863859Sml29623 36873859Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, "==> nxge_m_ioctl")); 36883859Sml29623 36893859Sml29623 iocp = (struct iocblk *)mp->b_rptr; 36903859Sml29623 iocp->ioc_error = 0; 36913859Sml29623 need_privilege = B_TRUE; 36923859Sml29623 cmd = iocp->ioc_cmd; 36933859Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, "==> nxge_m_ioctl: cmd 0x%08x", cmd)); 36943859Sml29623 switch (cmd) { 36953859Sml29623 default: 36963859Sml29623 miocnak(wq, mp, 0, EINVAL); 36973859Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, "<== nxge_m_ioctl: invalid")); 36983859Sml29623 return; 36993859Sml29623 37003859Sml29623 case LB_GET_INFO_SIZE: 37013859Sml29623 case LB_GET_INFO: 37023859Sml29623 case LB_GET_MODE: 37033859Sml29623 need_privilege = B_FALSE; 37043859Sml29623 break; 37053859Sml29623 case LB_SET_MODE: 37063859Sml29623 break; 37073859Sml29623 37083859Sml29623 case ND_GET: 37093859Sml29623 need_privilege = B_FALSE; 37103859Sml29623 break; 37113859Sml29623 case ND_SET: 37123859Sml29623 break; 37133859Sml29623 37143859Sml29623 case NXGE_GET_MII: 37153859Sml29623 case NXGE_PUT_MII: 37163859Sml29623 case NXGE_GET64: 37173859Sml29623 case NXGE_PUT64: 37183859Sml29623 case NXGE_GET_TX_RING_SZ: 37193859Sml29623 case NXGE_GET_TX_DESC: 37203859Sml29623 case NXGE_TX_SIDE_RESET: 37213859Sml29623 case NXGE_RX_SIDE_RESET: 37223859Sml29623 case NXGE_GLOBAL_RESET: 37233859Sml29623 case NXGE_RESET_MAC: 37243859Sml29623 case NXGE_TX_REGS_DUMP: 37253859Sml29623 case NXGE_RX_REGS_DUMP: 37263859Sml29623 case NXGE_INT_REGS_DUMP: 37273859Sml29623 case NXGE_VIR_INT_REGS_DUMP: 37283859Sml29623 case NXGE_PUT_TCAM: 37293859Sml29623 case NXGE_GET_TCAM: 37303859Sml29623 case NXGE_RTRACE: 37313859Sml29623 case NXGE_RDUMP: 37323859Sml29623 37333859Sml29623 need_privilege = B_FALSE; 37343859Sml29623 break; 37353859Sml29623 case NXGE_INJECT_ERR: 37363859Sml29623 cmn_err(CE_NOTE, "!nxge_m_ioctl: Inject error\n"); 37373859Sml29623 nxge_err_inject(nxgep, wq, mp); 37383859Sml29623 break; 37393859Sml29623 } 37403859Sml29623 37413859Sml29623 if (need_privilege) { 37424185Sspeer err = secpolicy_net_config(iocp->ioc_cr, B_FALSE); 37433859Sml29623 if (err != 0) { 37443859Sml29623 miocnak(wq, mp, 0, err); 37453859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 37463859Sml29623 "<== nxge_m_ioctl: no priv")); 37473859Sml29623 return; 37483859Sml29623 } 37493859Sml29623 } 37503859Sml29623 37513859Sml29623 switch (cmd) { 37523859Sml29623 case ND_GET: 37533859Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, "ND_GET command")); 37543859Sml29623 case ND_SET: 37553859Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, "ND_SET command")); 37563859Sml29623 nxge_param_ioctl(nxgep, wq, mp, iocp); 37573859Sml29623 break; 37583859Sml29623 37593859Sml29623 case LB_GET_MODE: 37603859Sml29623 case LB_SET_MODE: 37613859Sml29623 case LB_GET_INFO_SIZE: 37623859Sml29623 case LB_GET_INFO: 37633859Sml29623 nxge_loopback_ioctl(nxgep, wq, mp, iocp); 37643859Sml29623 break; 37653859Sml29623 37663859Sml29623 case NXGE_GET_MII: 37673859Sml29623 case NXGE_PUT_MII: 37683859Sml29623 case NXGE_PUT_TCAM: 37693859Sml29623 case NXGE_GET_TCAM: 37703859Sml29623 case NXGE_GET64: 37713859Sml29623 case NXGE_PUT64: 37723859Sml29623 case NXGE_GET_TX_RING_SZ: 37733859Sml29623 case NXGE_GET_TX_DESC: 37743859Sml29623 case NXGE_TX_SIDE_RESET: 37753859Sml29623 case NXGE_RX_SIDE_RESET: 37763859Sml29623 case NXGE_GLOBAL_RESET: 37773859Sml29623 case NXGE_RESET_MAC: 37783859Sml29623 case NXGE_TX_REGS_DUMP: 37793859Sml29623 case NXGE_RX_REGS_DUMP: 37803859Sml29623 case NXGE_INT_REGS_DUMP: 37813859Sml29623 case NXGE_VIR_INT_REGS_DUMP: 37823859Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 37833859Sml29623 "==> nxge_m_ioctl: cmd 0x%x", cmd)); 37843859Sml29623 nxge_hw_ioctl(nxgep, wq, mp, iocp); 37853859Sml29623 break; 37863859Sml29623 } 37873859Sml29623 37883859Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, "<== nxge_m_ioctl")); 37893859Sml29623 } 37903859Sml29623 37913859Sml29623 extern void nxge_rx_hw_blank(void *arg, time_t ticks, uint_t count); 37923859Sml29623 37933859Sml29623 static void 37943859Sml29623 nxge_m_resources(void *arg) 37953859Sml29623 { 37963859Sml29623 p_nxge_t nxgep = arg; 37973859Sml29623 mac_rx_fifo_t mrf; 37986495Sspeer 37996495Sspeer nxge_grp_set_t *set = &nxgep->rx_set; 38006495Sspeer uint8_t rdc; 38016495Sspeer 38026495Sspeer rx_rcr_ring_t *ring; 38033859Sml29623 38043859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "==> nxge_m_resources")); 38053859Sml29623 38063859Sml29623 MUTEX_ENTER(nxgep->genlock); 38073859Sml29623 38086495Sspeer if (set->owned.map == 0) { 38096495Sspeer NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL, 38106495Sspeer "nxge_m_resources: no receive resources")); 38116495Sspeer goto nxge_m_resources_exit; 38126495Sspeer } 38136495Sspeer 38143859Sml29623 /* 38153859Sml29623 * CR 6492541 Check to see if the drv_state has been initialized, 38163859Sml29623 * if not * call nxge_init(). 38173859Sml29623 */ 38183859Sml29623 if (!(nxgep->drv_state & STATE_HW_INITIALIZED)) { 38196495Sspeer if (nxge_init(nxgep) != NXGE_OK) 38203859Sml29623 goto nxge_m_resources_exit; 38213859Sml29623 } 38223859Sml29623 38233859Sml29623 mrf.mrf_type = MAC_RX_FIFO; 38243859Sml29623 mrf.mrf_blank = nxge_rx_hw_blank; 38253859Sml29623 mrf.mrf_arg = (void *)nxgep; 38263859Sml29623 38273859Sml29623 mrf.mrf_normal_blank_time = 128; 38283859Sml29623 mrf.mrf_normal_pkt_count = 8; 38293859Sml29623 38303859Sml29623 /* 38313859Sml29623 * Export our receive resources to the MAC layer. 38323859Sml29623 */ 38336495Sspeer for (rdc = 0; rdc < NXGE_MAX_RDCS; rdc++) { 38346495Sspeer if ((1 << rdc) & set->owned.map) { 38356495Sspeer ring = nxgep->rx_rcr_rings->rcr_rings[rdc]; 38366495Sspeer if (ring == 0) { 38376495Sspeer /* 38386495Sspeer * This is a big deal only if we are 38396495Sspeer * *not* in an LDOMs environment. 38406495Sspeer */ 38416495Sspeer if (nxgep->environs == SOLARIS_DOMAIN) { 38426495Sspeer cmn_err(CE_NOTE, 38436495Sspeer "==> nxge_m_resources: " 38446495Sspeer "ring %d == 0", rdc); 38456495Sspeer } 38466495Sspeer continue; 38476495Sspeer } 38486495Sspeer ring->rcr_mac_handle = mac_resource_add 38496495Sspeer (nxgep->mach, (mac_resource_t *)&mrf); 38506495Sspeer 38516495Sspeer NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 38526495Sspeer "==> nxge_m_resources: RDC %d RCR %p MAC handle %p", 38536495Sspeer rdc, ring, ring->rcr_mac_handle)); 38546495Sspeer } 38553859Sml29623 } 38563859Sml29623 38573859Sml29623 nxge_m_resources_exit: 38583859Sml29623 MUTEX_EXIT(nxgep->genlock); 38593859Sml29623 NXGE_DEBUG_MSG((nxgep, RX_CTL, "<== nxge_m_resources")); 38603859Sml29623 } 38613859Sml29623 38626495Sspeer void 38633859Sml29623 nxge_mmac_kstat_update(p_nxge_t nxgep, mac_addr_slot_t slot, boolean_t factory) 38643859Sml29623 { 38653859Sml29623 p_nxge_mmac_stats_t mmac_stats; 38663859Sml29623 int i; 38673859Sml29623 nxge_mmac_t *mmac_info; 38683859Sml29623 38693859Sml29623 mmac_info = &nxgep->nxge_mmac_info; 38703859Sml29623 38713859Sml29623 mmac_stats = &nxgep->statsp->mmac_stats; 38723859Sml29623 mmac_stats->mmac_max_cnt = mmac_info->num_mmac; 38733859Sml29623 mmac_stats->mmac_avail_cnt = mmac_info->naddrfree; 38743859Sml29623 38753859Sml29623 for (i = 0; i < ETHERADDRL; i++) { 38763859Sml29623 if (factory) { 38773859Sml29623 mmac_stats->mmac_avail_pool[slot-1].ether_addr_octet[i] 38783859Sml29623 = mmac_info->factory_mac_pool[slot][(ETHERADDRL-1) - i]; 38793859Sml29623 } else { 38803859Sml29623 mmac_stats->mmac_avail_pool[slot-1].ether_addr_octet[i] 38813859Sml29623 = mmac_info->mac_pool[slot].addr[(ETHERADDRL - 1) - i]; 38823859Sml29623 } 38833859Sml29623 } 38843859Sml29623 } 38853859Sml29623 38863859Sml29623 /* 38873859Sml29623 * nxge_altmac_set() -- Set an alternate MAC address 38883859Sml29623 */ 38893859Sml29623 static int 38903859Sml29623 nxge_altmac_set(p_nxge_t nxgep, uint8_t *maddr, mac_addr_slot_t slot) 38913859Sml29623 { 38923859Sml29623 uint8_t addrn; 38933859Sml29623 uint8_t portn; 38943859Sml29623 npi_mac_addr_t altmac; 38954484Sspeer hostinfo_t mac_rdc; 38964484Sspeer p_nxge_class_pt_cfg_t clscfgp; 38973859Sml29623 38983859Sml29623 altmac.w2 = ((uint16_t)maddr[0] << 8) | ((uint16_t)maddr[1] & 0x0ff); 38993859Sml29623 altmac.w1 = ((uint16_t)maddr[2] << 8) | ((uint16_t)maddr[3] & 0x0ff); 39003859Sml29623 altmac.w0 = ((uint16_t)maddr[4] << 8) | ((uint16_t)maddr[5] & 0x0ff); 39013859Sml29623 39023859Sml29623 portn = nxgep->mac.portnum; 39033859Sml29623 addrn = (uint8_t)slot - 1; 39043859Sml29623 39053859Sml29623 if (npi_mac_altaddr_entry(nxgep->npi_handle, OP_SET, portn, 39063859Sml29623 addrn, &altmac) != NPI_SUCCESS) 39073859Sml29623 return (EIO); 39084484Sspeer 39094484Sspeer /* 39104484Sspeer * Set the rdc table number for the host info entry 39114484Sspeer * for this mac address slot. 39124484Sspeer */ 39134484Sspeer clscfgp = (p_nxge_class_pt_cfg_t)&nxgep->class_config; 39144484Sspeer mac_rdc.value = 0; 39154484Sspeer mac_rdc.bits.w0.rdc_tbl_num = clscfgp->mac_host_info[addrn].rdctbl; 39164484Sspeer mac_rdc.bits.w0.mac_pref = clscfgp->mac_host_info[addrn].mpr_npr; 39174484Sspeer 39184484Sspeer if (npi_mac_hostinfo_entry(nxgep->npi_handle, OP_SET, 39194484Sspeer nxgep->function_num, addrn, &mac_rdc) != NPI_SUCCESS) { 39204484Sspeer return (EIO); 39214484Sspeer } 39224484Sspeer 39233859Sml29623 /* 39243859Sml29623 * Enable comparison with the alternate MAC address. 39253859Sml29623 * While the first alternate addr is enabled by bit 1 of register 39263859Sml29623 * BMAC_ALTAD_CMPEN, it is enabled by bit 0 of register 39273859Sml29623 * XMAC_ADDR_CMPEN, so slot needs to be converted to addrn 39283859Sml29623 * accordingly before calling npi_mac_altaddr_entry. 39293859Sml29623 */ 39303859Sml29623 if (portn == XMAC_PORT_0 || portn == XMAC_PORT_1) 39313859Sml29623 addrn = (uint8_t)slot - 1; 39323859Sml29623 else 39333859Sml29623 addrn = (uint8_t)slot; 39343859Sml29623 39353859Sml29623 if (npi_mac_altaddr_enable(nxgep->npi_handle, portn, addrn) 39363859Sml29623 != NPI_SUCCESS) 39373859Sml29623 return (EIO); 39383859Sml29623 39393859Sml29623 return (0); 39403859Sml29623 } 39413859Sml29623 39423859Sml29623 /* 39433859Sml29623 * nxeg_m_mmac_add() - find an unused address slot, set the address 39443859Sml29623 * value to the one specified, enable the port to start filtering on 39453859Sml29623 * the new MAC address. Returns 0 on success. 39463859Sml29623 */ 39476495Sspeer int 39483859Sml29623 nxge_m_mmac_add(void *arg, mac_multi_addr_t *maddr) 39493859Sml29623 { 39503859Sml29623 p_nxge_t nxgep = arg; 39513859Sml29623 mac_addr_slot_t slot; 39523859Sml29623 nxge_mmac_t *mmac_info; 39533859Sml29623 int err; 39543859Sml29623 nxge_status_t status; 39553859Sml29623 39563859Sml29623 mutex_enter(nxgep->genlock); 39573859Sml29623 39583859Sml29623 /* 39593859Sml29623 * Make sure that nxge is initialized, if _start() has 39603859Sml29623 * not been called. 39613859Sml29623 */ 39623859Sml29623 if (!(nxgep->drv_state & STATE_HW_INITIALIZED)) { 39633859Sml29623 status = nxge_init(nxgep); 39643859Sml29623 if (status != NXGE_OK) { 39653859Sml29623 mutex_exit(nxgep->genlock); 39663859Sml29623 return (ENXIO); 39673859Sml29623 } 39683859Sml29623 } 39693859Sml29623 39703859Sml29623 mmac_info = &nxgep->nxge_mmac_info; 39713859Sml29623 if (mmac_info->naddrfree == 0) { 39723859Sml29623 mutex_exit(nxgep->genlock); 39733859Sml29623 return (ENOSPC); 39743859Sml29623 } 39753859Sml29623 if (!mac_unicst_verify(nxgep->mach, maddr->mma_addr, 39763859Sml29623 maddr->mma_addrlen)) { 39773859Sml29623 mutex_exit(nxgep->genlock); 39783859Sml29623 return (EINVAL); 39793859Sml29623 } 39803859Sml29623 /* 39813859Sml29623 * Search for the first available slot. Because naddrfree 39823859Sml29623 * is not zero, we are guaranteed to find one. 39833859Sml29623 * Slot 0 is for unique (primary) MAC. The first alternate 39843859Sml29623 * MAC slot is slot 1. 39853859Sml29623 * Each of the first two ports of Neptune has 16 alternate 39866495Sspeer * MAC slots but only the first 7 (of 15) slots have assigned factory 39873859Sml29623 * MAC addresses. We first search among the slots without bundled 39883859Sml29623 * factory MACs. If we fail to find one in that range, then we 39893859Sml29623 * search the slots with bundled factory MACs. A factory MAC 39903859Sml29623 * will be wasted while the slot is used with a user MAC address. 39913859Sml29623 * But the slot could be used by factory MAC again after calling 39923859Sml29623 * nxge_m_mmac_remove and nxge_m_mmac_reserve. 39933859Sml29623 */ 39943859Sml29623 if (mmac_info->num_factory_mmac < mmac_info->num_mmac) { 39953859Sml29623 for (slot = mmac_info->num_factory_mmac + 1; 39963859Sml29623 slot <= mmac_info->num_mmac; slot++) { 39973859Sml29623 if (!(mmac_info->mac_pool[slot].flags & MMAC_SLOT_USED)) 39983859Sml29623 break; 39993859Sml29623 } 40003859Sml29623 if (slot > mmac_info->num_mmac) { 40013859Sml29623 for (slot = 1; slot <= mmac_info->num_factory_mmac; 40023859Sml29623 slot++) { 40033859Sml29623 if (!(mmac_info->mac_pool[slot].flags 40043859Sml29623 & MMAC_SLOT_USED)) 40053859Sml29623 break; 40063859Sml29623 } 40073859Sml29623 } 40083859Sml29623 } else { 40093859Sml29623 for (slot = 1; slot <= mmac_info->num_mmac; slot++) { 40103859Sml29623 if (!(mmac_info->mac_pool[slot].flags & MMAC_SLOT_USED)) 40113859Sml29623 break; 40123859Sml29623 } 40133859Sml29623 } 40143859Sml29623 ASSERT(slot <= mmac_info->num_mmac); 40153859Sml29623 if ((err = nxge_altmac_set(nxgep, maddr->mma_addr, slot)) != 0) { 40163859Sml29623 mutex_exit(nxgep->genlock); 40173859Sml29623 return (err); 40183859Sml29623 } 40193859Sml29623 bcopy(maddr->mma_addr, mmac_info->mac_pool[slot].addr, ETHERADDRL); 40203859Sml29623 mmac_info->mac_pool[slot].flags |= MMAC_SLOT_USED; 40213859Sml29623 mmac_info->mac_pool[slot].flags &= ~MMAC_VENDOR_ADDR; 40223859Sml29623 mmac_info->naddrfree--; 40233859Sml29623 nxge_mmac_kstat_update(nxgep, slot, B_FALSE); 40243859Sml29623 40253859Sml29623 maddr->mma_slot = slot; 40263859Sml29623 40273859Sml29623 mutex_exit(nxgep->genlock); 40283859Sml29623 return (0); 40293859Sml29623 } 40303859Sml29623 40313859Sml29623 /* 40323859Sml29623 * This function reserves an unused slot and programs the slot and the HW 40333859Sml29623 * with a factory mac address. 40343859Sml29623 */ 40353859Sml29623 static int 40363859Sml29623 nxge_m_mmac_reserve(void *arg, mac_multi_addr_t *maddr) 40373859Sml29623 { 40383859Sml29623 p_nxge_t nxgep = arg; 40393859Sml29623 mac_addr_slot_t slot; 40403859Sml29623 nxge_mmac_t *mmac_info; 40413859Sml29623 int err; 40423859Sml29623 nxge_status_t status; 40433859Sml29623 40443859Sml29623 mutex_enter(nxgep->genlock); 40453859Sml29623 40463859Sml29623 /* 40473859Sml29623 * Make sure that nxge is initialized, if _start() has 40483859Sml29623 * not been called. 40493859Sml29623 */ 40503859Sml29623 if (!(nxgep->drv_state & STATE_HW_INITIALIZED)) { 40513859Sml29623 status = nxge_init(nxgep); 40523859Sml29623 if (status != NXGE_OK) { 40533859Sml29623 mutex_exit(nxgep->genlock); 40543859Sml29623 return (ENXIO); 40553859Sml29623 } 40563859Sml29623 } 40573859Sml29623 40583859Sml29623 mmac_info = &nxgep->nxge_mmac_info; 40593859Sml29623 if (mmac_info->naddrfree == 0) { 40603859Sml29623 mutex_exit(nxgep->genlock); 40613859Sml29623 return (ENOSPC); 40623859Sml29623 } 40633859Sml29623 40643859Sml29623 slot = maddr->mma_slot; 40653859Sml29623 if (slot == -1) { /* -1: Take the first available slot */ 40663859Sml29623 for (slot = 1; slot <= mmac_info->num_factory_mmac; slot++) { 40673859Sml29623 if (!(mmac_info->mac_pool[slot].flags & MMAC_SLOT_USED)) 40683859Sml29623 break; 40693859Sml29623 } 40703859Sml29623 if (slot > mmac_info->num_factory_mmac) { 40713859Sml29623 mutex_exit(nxgep->genlock); 40723859Sml29623 return (ENOSPC); 40733859Sml29623 } 40743859Sml29623 } 40753859Sml29623 if (slot < 1 || slot > mmac_info->num_factory_mmac) { 40763859Sml29623 /* 40773859Sml29623 * Do not support factory MAC at a slot greater than 40783859Sml29623 * num_factory_mmac even when there are available factory 40793859Sml29623 * MAC addresses because the alternate MACs are bundled with 40803859Sml29623 * slot[1] through slot[num_factory_mmac] 40813859Sml29623 */ 40823859Sml29623 mutex_exit(nxgep->genlock); 40833859Sml29623 return (EINVAL); 40843859Sml29623 } 40853859Sml29623 if (mmac_info->mac_pool[slot].flags & MMAC_SLOT_USED) { 40863859Sml29623 mutex_exit(nxgep->genlock); 40873859Sml29623 return (EBUSY); 40883859Sml29623 } 40893859Sml29623 /* Verify the address to be reserved */ 40903859Sml29623 if (!mac_unicst_verify(nxgep->mach, 40913859Sml29623 mmac_info->factory_mac_pool[slot], ETHERADDRL)) { 40923859Sml29623 mutex_exit(nxgep->genlock); 40933859Sml29623 return (EINVAL); 40943859Sml29623 } 40953859Sml29623 if (err = nxge_altmac_set(nxgep, 40963859Sml29623 mmac_info->factory_mac_pool[slot], slot)) { 40973859Sml29623 mutex_exit(nxgep->genlock); 40983859Sml29623 return (err); 40993859Sml29623 } 41003859Sml29623 bcopy(mmac_info->factory_mac_pool[slot], maddr->mma_addr, ETHERADDRL); 41013859Sml29623 mmac_info->mac_pool[slot].flags |= MMAC_SLOT_USED | MMAC_VENDOR_ADDR; 41023859Sml29623 mmac_info->naddrfree--; 41033859Sml29623 41043859Sml29623 nxge_mmac_kstat_update(nxgep, slot, B_TRUE); 41053859Sml29623 mutex_exit(nxgep->genlock); 41063859Sml29623 41073859Sml29623 /* Pass info back to the caller */ 41083859Sml29623 maddr->mma_slot = slot; 41093859Sml29623 maddr->mma_addrlen = ETHERADDRL; 41103859Sml29623 maddr->mma_flags = MMAC_SLOT_USED | MMAC_VENDOR_ADDR; 41113859Sml29623 41123859Sml29623 return (0); 41133859Sml29623 } 41143859Sml29623 41153859Sml29623 /* 41163859Sml29623 * Remove the specified mac address and update the HW not to filter 41173859Sml29623 * the mac address anymore. 41183859Sml29623 */ 41196495Sspeer int 41203859Sml29623 nxge_m_mmac_remove(void *arg, mac_addr_slot_t slot) 41213859Sml29623 { 41223859Sml29623 p_nxge_t nxgep = arg; 41233859Sml29623 nxge_mmac_t *mmac_info; 41243859Sml29623 uint8_t addrn; 41253859Sml29623 uint8_t portn; 41263859Sml29623 int err = 0; 41273859Sml29623 nxge_status_t status; 41283859Sml29623 41293859Sml29623 mutex_enter(nxgep->genlock); 41303859Sml29623 41313859Sml29623 /* 41323859Sml29623 * Make sure that nxge is initialized, if _start() has 41333859Sml29623 * not been called. 41343859Sml29623 */ 41353859Sml29623 if (!(nxgep->drv_state & STATE_HW_INITIALIZED)) { 41363859Sml29623 status = nxge_init(nxgep); 41373859Sml29623 if (status != NXGE_OK) { 41383859Sml29623 mutex_exit(nxgep->genlock); 41393859Sml29623 return (ENXIO); 41403859Sml29623 } 41413859Sml29623 } 41423859Sml29623 41433859Sml29623 mmac_info = &nxgep->nxge_mmac_info; 41443859Sml29623 if (slot < 1 || slot > mmac_info->num_mmac) { 41453859Sml29623 mutex_exit(nxgep->genlock); 41463859Sml29623 return (EINVAL); 41473859Sml29623 } 41483859Sml29623 41493859Sml29623 portn = nxgep->mac.portnum; 41503859Sml29623 if (portn == XMAC_PORT_0 || portn == XMAC_PORT_1) 41513859Sml29623 addrn = (uint8_t)slot - 1; 41523859Sml29623 else 41533859Sml29623 addrn = (uint8_t)slot; 41543859Sml29623 41553859Sml29623 if (mmac_info->mac_pool[slot].flags & MMAC_SLOT_USED) { 41563859Sml29623 if (npi_mac_altaddr_disable(nxgep->npi_handle, portn, addrn) 41573859Sml29623 == NPI_SUCCESS) { 41583859Sml29623 mmac_info->naddrfree++; 41593859Sml29623 mmac_info->mac_pool[slot].flags &= ~MMAC_SLOT_USED; 41603859Sml29623 /* 41613859Sml29623 * Regardless if the MAC we just stopped filtering 41623859Sml29623 * is a user addr or a facory addr, we must set 41633859Sml29623 * the MMAC_VENDOR_ADDR flag if this slot has an 41643859Sml29623 * associated factory MAC to indicate that a factory 41653859Sml29623 * MAC is available. 41663859Sml29623 */ 41673859Sml29623 if (slot <= mmac_info->num_factory_mmac) { 41683859Sml29623 mmac_info->mac_pool[slot].flags 41693859Sml29623 |= MMAC_VENDOR_ADDR; 41703859Sml29623 } 41713859Sml29623 /* 41723859Sml29623 * Clear mac_pool[slot].addr so that kstat shows 0 41733859Sml29623 * alternate MAC address if the slot is not used. 41743859Sml29623 * (But nxge_m_mmac_get returns the factory MAC even 41753859Sml29623 * when the slot is not used!) 41763859Sml29623 */ 41773859Sml29623 bzero(mmac_info->mac_pool[slot].addr, ETHERADDRL); 41783859Sml29623 nxge_mmac_kstat_update(nxgep, slot, B_FALSE); 41793859Sml29623 } else { 41803859Sml29623 err = EIO; 41813859Sml29623 } 41823859Sml29623 } else { 41833859Sml29623 err = EINVAL; 41843859Sml29623 } 41853859Sml29623 41863859Sml29623 mutex_exit(nxgep->genlock); 41873859Sml29623 return (err); 41883859Sml29623 } 41893859Sml29623 41903859Sml29623 /* 41913859Sml29623 * Modify a mac address added by nxge_m_mmac_add or nxge_m_mmac_reserve(). 41923859Sml29623 */ 41933859Sml29623 static int 41943859Sml29623 nxge_m_mmac_modify(void *arg, mac_multi_addr_t *maddr) 41953859Sml29623 { 41963859Sml29623 p_nxge_t nxgep = arg; 41973859Sml29623 mac_addr_slot_t slot; 41983859Sml29623 nxge_mmac_t *mmac_info; 41993859Sml29623 int err = 0; 42003859Sml29623 nxge_status_t status; 42013859Sml29623 42023859Sml29623 if (!mac_unicst_verify(nxgep->mach, maddr->mma_addr, 42033859Sml29623 maddr->mma_addrlen)) 42043859Sml29623 return (EINVAL); 42053859Sml29623 42063859Sml29623 slot = maddr->mma_slot; 42073859Sml29623 42083859Sml29623 mutex_enter(nxgep->genlock); 42093859Sml29623 42103859Sml29623 /* 42113859Sml29623 * Make sure that nxge is initialized, if _start() has 42123859Sml29623 * not been called. 42133859Sml29623 */ 42143859Sml29623 if (!(nxgep->drv_state & STATE_HW_INITIALIZED)) { 42153859Sml29623 status = nxge_init(nxgep); 42163859Sml29623 if (status != NXGE_OK) { 42173859Sml29623 mutex_exit(nxgep->genlock); 42183859Sml29623 return (ENXIO); 42193859Sml29623 } 42203859Sml29623 } 42213859Sml29623 42223859Sml29623 mmac_info = &nxgep->nxge_mmac_info; 42233859Sml29623 if (slot < 1 || slot > mmac_info->num_mmac) { 42243859Sml29623 mutex_exit(nxgep->genlock); 42253859Sml29623 return (EINVAL); 42263859Sml29623 } 42273859Sml29623 if (mmac_info->mac_pool[slot].flags & MMAC_SLOT_USED) { 42283859Sml29623 if ((err = nxge_altmac_set(nxgep, maddr->mma_addr, slot)) 42293859Sml29623 != 0) { 42303859Sml29623 bcopy(maddr->mma_addr, mmac_info->mac_pool[slot].addr, 42313859Sml29623 ETHERADDRL); 42323859Sml29623 /* 42333859Sml29623 * Assume that the MAC passed down from the caller 42343859Sml29623 * is not a factory MAC address (The user should 42353859Sml29623 * call mmac_remove followed by mmac_reserve if 42363859Sml29623 * he wants to use the factory MAC for this slot). 42373859Sml29623 */ 42383859Sml29623 mmac_info->mac_pool[slot].flags &= ~MMAC_VENDOR_ADDR; 42393859Sml29623 nxge_mmac_kstat_update(nxgep, slot, B_FALSE); 42403859Sml29623 } 42413859Sml29623 } else { 42423859Sml29623 err = EINVAL; 42433859Sml29623 } 42443859Sml29623 mutex_exit(nxgep->genlock); 42453859Sml29623 return (err); 42463859Sml29623 } 42473859Sml29623 42483859Sml29623 /* 42493859Sml29623 * nxge_m_mmac_get() - Get the MAC address and other information 42503859Sml29623 * related to the slot. mma_flags should be set to 0 in the call. 42513859Sml29623 * Note: although kstat shows MAC address as zero when a slot is 42523859Sml29623 * not used, Crossbow expects nxge_m_mmac_get to copy factory MAC 42533859Sml29623 * to the caller as long as the slot is not using a user MAC address. 42543859Sml29623 * The following table shows the rules, 42553859Sml29623 * 42563859Sml29623 * USED VENDOR mma_addr 42573859Sml29623 * ------------------------------------------------------------ 42583859Sml29623 * (1) Slot uses a user MAC: yes no user MAC 42593859Sml29623 * (2) Slot uses a factory MAC: yes yes factory MAC 42603859Sml29623 * (3) Slot is not used but is 42613859Sml29623 * factory MAC capable: no yes factory MAC 42623859Sml29623 * (4) Slot is not used and is 42633859Sml29623 * not factory MAC capable: no no 0 42643859Sml29623 * ------------------------------------------------------------ 42653859Sml29623 */ 42663859Sml29623 static int 42673859Sml29623 nxge_m_mmac_get(void *arg, mac_multi_addr_t *maddr) 42683859Sml29623 { 42693859Sml29623 nxge_t *nxgep = arg; 42703859Sml29623 mac_addr_slot_t slot; 42713859Sml29623 nxge_mmac_t *mmac_info; 42723859Sml29623 nxge_status_t status; 42733859Sml29623 42743859Sml29623 slot = maddr->mma_slot; 42753859Sml29623 42763859Sml29623 mutex_enter(nxgep->genlock); 42773859Sml29623 42783859Sml29623 /* 42793859Sml29623 * Make sure that nxge is initialized, if _start() has 42803859Sml29623 * not been called. 42813859Sml29623 */ 42823859Sml29623 if (!(nxgep->drv_state & STATE_HW_INITIALIZED)) { 42833859Sml29623 status = nxge_init(nxgep); 42843859Sml29623 if (status != NXGE_OK) { 42853859Sml29623 mutex_exit(nxgep->genlock); 42863859Sml29623 return (ENXIO); 42873859Sml29623 } 42883859Sml29623 } 42893859Sml29623 42903859Sml29623 mmac_info = &nxgep->nxge_mmac_info; 42913859Sml29623 42923859Sml29623 if (slot < 1 || slot > mmac_info->num_mmac) { 42933859Sml29623 mutex_exit(nxgep->genlock); 42943859Sml29623 return (EINVAL); 42953859Sml29623 } 42963859Sml29623 maddr->mma_flags = 0; 42973859Sml29623 if (mmac_info->mac_pool[slot].flags & MMAC_SLOT_USED) 42983859Sml29623 maddr->mma_flags |= MMAC_SLOT_USED; 42993859Sml29623 43003859Sml29623 if (mmac_info->mac_pool[slot].flags & MMAC_VENDOR_ADDR) { 43013859Sml29623 maddr->mma_flags |= MMAC_VENDOR_ADDR; 43023859Sml29623 bcopy(mmac_info->factory_mac_pool[slot], 43033859Sml29623 maddr->mma_addr, ETHERADDRL); 43043859Sml29623 maddr->mma_addrlen = ETHERADDRL; 43053859Sml29623 } else { 43063859Sml29623 if (maddr->mma_flags & MMAC_SLOT_USED) { 43073859Sml29623 bcopy(mmac_info->mac_pool[slot].addr, 43083859Sml29623 maddr->mma_addr, ETHERADDRL); 43093859Sml29623 maddr->mma_addrlen = ETHERADDRL; 43103859Sml29623 } else { 43113859Sml29623 bzero(maddr->mma_addr, ETHERADDRL); 43123859Sml29623 maddr->mma_addrlen = 0; 43133859Sml29623 } 43143859Sml29623 } 43153859Sml29623 mutex_exit(nxgep->genlock); 43163859Sml29623 return (0); 43173859Sml29623 } 43183859Sml29623 43193859Sml29623 static boolean_t 43203859Sml29623 nxge_m_getcapab(void *arg, mac_capab_t cap, void *cap_data) 43213859Sml29623 { 43223859Sml29623 nxge_t *nxgep = arg; 43233859Sml29623 uint32_t *txflags = cap_data; 43243859Sml29623 multiaddress_capab_t *mmacp = cap_data; 43253859Sml29623 43263859Sml29623 switch (cap) { 43273859Sml29623 case MAC_CAPAB_HCKSUM: 43286495Sspeer NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 43296495Sspeer "==> nxge_m_getcapab: checksum %d", nxge_cksum_enable)); 43306495Sspeer if (nxge_cksum_enable) { 43316495Sspeer *txflags = HCKSUM_INET_PARTIAL; 43326495Sspeer } 43333859Sml29623 break; 43346495Sspeer 43353859Sml29623 case MAC_CAPAB_POLL: 43363859Sml29623 /* 43373859Sml29623 * There's nothing for us to fill in, simply returning 43383859Sml29623 * B_TRUE stating that we support polling is sufficient. 43393859Sml29623 */ 43403859Sml29623 break; 43413859Sml29623 43423859Sml29623 case MAC_CAPAB_MULTIADDRESS: 43436495Sspeer mmacp = (multiaddress_capab_t *)cap_data; 43443859Sml29623 mutex_enter(nxgep->genlock); 43453859Sml29623 43463859Sml29623 mmacp->maddr_naddr = nxgep->nxge_mmac_info.num_mmac; 43473859Sml29623 mmacp->maddr_naddrfree = nxgep->nxge_mmac_info.naddrfree; 43483859Sml29623 mmacp->maddr_flag = 0; /* 0 is requried by PSARC2006/265 */ 43493859Sml29623 /* 43503859Sml29623 * maddr_handle is driver's private data, passed back to 43513859Sml29623 * entry point functions as arg. 43523859Sml29623 */ 43533859Sml29623 mmacp->maddr_handle = nxgep; 43543859Sml29623 mmacp->maddr_add = nxge_m_mmac_add; 43553859Sml29623 mmacp->maddr_remove = nxge_m_mmac_remove; 43563859Sml29623 mmacp->maddr_modify = nxge_m_mmac_modify; 43573859Sml29623 mmacp->maddr_get = nxge_m_mmac_get; 43583859Sml29623 mmacp->maddr_reserve = nxge_m_mmac_reserve; 43593859Sml29623 43603859Sml29623 mutex_exit(nxgep->genlock); 43613859Sml29623 break; 43626495Sspeer 43635770Sml29623 case MAC_CAPAB_LSO: { 43645770Sml29623 mac_capab_lso_t *cap_lso = cap_data; 43655770Sml29623 43666003Sml29623 if (nxgep->soft_lso_enable) { 43675770Sml29623 cap_lso->lso_flags = LSO_TX_BASIC_TCP_IPV4; 43685770Sml29623 if (nxge_lso_max > NXGE_LSO_MAXLEN) { 43695770Sml29623 nxge_lso_max = NXGE_LSO_MAXLEN; 43705770Sml29623 } 43715770Sml29623 cap_lso->lso_basic_tcp_ipv4.lso_max = nxge_lso_max; 43725770Sml29623 break; 43735770Sml29623 } else { 43745770Sml29623 return (B_FALSE); 43755770Sml29623 } 43765770Sml29623 } 43775770Sml29623 43786495Sspeer #if defined(sun4v) 43796495Sspeer case MAC_CAPAB_RINGS: { 43806495Sspeer mac_capab_rings_t *mrings = (mac_capab_rings_t *)cap_data; 43816495Sspeer 43826495Sspeer /* 43836495Sspeer * Only the service domain driver responds to 43846495Sspeer * this capability request. 43856495Sspeer */ 43866495Sspeer if (isLDOMservice(nxgep)) { 43876495Sspeer mrings->mr_handle = (void *)nxgep; 43886495Sspeer 43896495Sspeer /* 43906495Sspeer * No dynamic allocation of groups and 43916495Sspeer * rings at this time. Shares dictate the 43926495Sspeer * configurartion. 43936495Sspeer */ 43946495Sspeer mrings->mr_gadd_ring = NULL; 43956495Sspeer mrings->mr_grem_ring = NULL; 43966495Sspeer mrings->mr_rget = NULL; 43976495Sspeer mrings->mr_gget = nxge_hio_group_get; 43986495Sspeer 43996495Sspeer if (mrings->mr_type == MAC_RING_TYPE_RX) { 44006495Sspeer mrings->mr_rnum = 8; /* XXX */ 44016495Sspeer mrings->mr_gnum = 6; /* XXX */ 44026495Sspeer } else { 44036495Sspeer mrings->mr_rnum = 8; /* XXX */ 44046495Sspeer mrings->mr_gnum = 0; /* XXX */ 44056495Sspeer } 44066495Sspeer } else 44076495Sspeer return (B_FALSE); 44086495Sspeer break; 44096495Sspeer } 44106495Sspeer 44116495Sspeer case MAC_CAPAB_SHARES: { 44126495Sspeer mac_capab_share_t *mshares = (mac_capab_share_t *)cap_data; 44136495Sspeer 44146495Sspeer /* 44156495Sspeer * Only the service domain driver responds to 44166495Sspeer * this capability request. 44176495Sspeer */ 44186495Sspeer if (isLDOMservice(nxgep)) { 44196495Sspeer mshares->ms_snum = 3; 44206495Sspeer mshares->ms_handle = (void *)nxgep; 44216495Sspeer mshares->ms_salloc = nxge_hio_share_alloc; 44226495Sspeer mshares->ms_sfree = nxge_hio_share_free; 44236495Sspeer mshares->ms_sadd = NULL; 44246495Sspeer mshares->ms_sremove = NULL; 44256495Sspeer mshares->ms_squery = nxge_hio_share_query; 44266495Sspeer } else 44276495Sspeer return (B_FALSE); 44286495Sspeer break; 44296495Sspeer } 44306495Sspeer #endif 44313859Sml29623 default: 44323859Sml29623 return (B_FALSE); 44333859Sml29623 } 44343859Sml29623 return (B_TRUE); 44353859Sml29623 } 44363859Sml29623 44376439Sml29623 static boolean_t 44386439Sml29623 nxge_param_locked(mac_prop_id_t pr_num) 44396439Sml29623 { 44406439Sml29623 /* 44416439Sml29623 * All adv_* parameters are locked (read-only) while 44426439Sml29623 * the device is in any sort of loopback mode ... 44436439Sml29623 */ 44446439Sml29623 switch (pr_num) { 44456439Sml29623 case DLD_PROP_ADV_1000FDX_CAP: 44466439Sml29623 case DLD_PROP_EN_1000FDX_CAP: 44476439Sml29623 case DLD_PROP_ADV_1000HDX_CAP: 44486439Sml29623 case DLD_PROP_EN_1000HDX_CAP: 44496439Sml29623 case DLD_PROP_ADV_100FDX_CAP: 44506439Sml29623 case DLD_PROP_EN_100FDX_CAP: 44516439Sml29623 case DLD_PROP_ADV_100HDX_CAP: 44526439Sml29623 case DLD_PROP_EN_100HDX_CAP: 44536439Sml29623 case DLD_PROP_ADV_10FDX_CAP: 44546439Sml29623 case DLD_PROP_EN_10FDX_CAP: 44556439Sml29623 case DLD_PROP_ADV_10HDX_CAP: 44566439Sml29623 case DLD_PROP_EN_10HDX_CAP: 44576439Sml29623 case DLD_PROP_AUTONEG: 44586439Sml29623 case DLD_PROP_FLOWCTRL: 44596439Sml29623 return (B_TRUE); 44606439Sml29623 } 44616439Sml29623 return (B_FALSE); 44626439Sml29623 } 44636439Sml29623 44646439Sml29623 /* 44656439Sml29623 * callback functions for set/get of properties 44666439Sml29623 */ 44676439Sml29623 static int 44686439Sml29623 nxge_m_setprop(void *barg, const char *pr_name, mac_prop_id_t pr_num, 44696439Sml29623 uint_t pr_valsize, const void *pr_val) 44706439Sml29623 { 44716439Sml29623 nxge_t *nxgep = barg; 44726439Sml29623 p_nxge_param_t param_arr; 44736439Sml29623 p_nxge_stats_t statsp; 44746439Sml29623 int err = 0; 44756439Sml29623 uint8_t val; 44766439Sml29623 uint32_t cur_mtu, new_mtu, old_framesize; 44776439Sml29623 link_flowctrl_t fl; 44786439Sml29623 44796439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, "==> nxge_m_setprop")); 44806439Sml29623 param_arr = nxgep->param_arr; 44816439Sml29623 statsp = nxgep->statsp; 44826439Sml29623 mutex_enter(nxgep->genlock); 44836439Sml29623 if (statsp->port_stats.lb_mode != nxge_lb_normal && 44846439Sml29623 nxge_param_locked(pr_num)) { 44856439Sml29623 /* 44866439Sml29623 * All adv_* parameters are locked (read-only) 44876439Sml29623 * while the device is in any sort of loopback mode. 44886439Sml29623 */ 44896439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 44906439Sml29623 "==> nxge_m_setprop: loopback mode: read only")); 44916439Sml29623 mutex_exit(nxgep->genlock); 44926439Sml29623 return (EBUSY); 44936439Sml29623 } 44946439Sml29623 44956439Sml29623 val = *(uint8_t *)pr_val; 44966439Sml29623 switch (pr_num) { 44976439Sml29623 case DLD_PROP_EN_1000FDX_CAP: 44986439Sml29623 nxgep->param_en_1000fdx = val; 44996439Sml29623 param_arr[param_anar_1000fdx].value = val; 45006439Sml29623 45016439Sml29623 goto reprogram; 45026439Sml29623 45036439Sml29623 case DLD_PROP_EN_100FDX_CAP: 45046439Sml29623 nxgep->param_en_100fdx = val; 45056439Sml29623 param_arr[param_anar_100fdx].value = val; 45066439Sml29623 45076439Sml29623 goto reprogram; 45086439Sml29623 45096439Sml29623 case DLD_PROP_EN_10FDX_CAP: 45106439Sml29623 nxgep->param_en_10fdx = val; 45116439Sml29623 param_arr[param_anar_10fdx].value = val; 45126439Sml29623 45136439Sml29623 goto reprogram; 45146439Sml29623 45156439Sml29623 case DLD_PROP_EN_1000HDX_CAP: 45166439Sml29623 case DLD_PROP_EN_100HDX_CAP: 45176439Sml29623 case DLD_PROP_EN_10HDX_CAP: 45186439Sml29623 case DLD_PROP_ADV_1000FDX_CAP: 45196439Sml29623 case DLD_PROP_ADV_1000HDX_CAP: 45206439Sml29623 case DLD_PROP_ADV_100FDX_CAP: 45216439Sml29623 case DLD_PROP_ADV_100HDX_CAP: 45226439Sml29623 case DLD_PROP_ADV_10FDX_CAP: 45236439Sml29623 case DLD_PROP_ADV_10HDX_CAP: 45246439Sml29623 case DLD_PROP_STATUS: 45256439Sml29623 case DLD_PROP_SPEED: 45266439Sml29623 case DLD_PROP_DUPLEX: 45276439Sml29623 err = EINVAL; /* cannot set read-only properties */ 45286439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 45296439Sml29623 "==> nxge_m_setprop: read only property %d", 45306439Sml29623 pr_num)); 45316439Sml29623 break; 45326439Sml29623 45336439Sml29623 case DLD_PROP_AUTONEG: 45346439Sml29623 param_arr[param_autoneg].value = val; 45356439Sml29623 45366439Sml29623 goto reprogram; 45376439Sml29623 45386439Sml29623 case DLD_PROP_DEFMTU: 45396439Sml29623 if (nxgep->nxge_mac_state == NXGE_MAC_STARTED) { 45406439Sml29623 err = EBUSY; 45416439Sml29623 break; 45426439Sml29623 } 45436439Sml29623 45446439Sml29623 cur_mtu = nxgep->mac.default_mtu; 45456439Sml29623 bcopy(pr_val, &new_mtu, sizeof (new_mtu)); 45466439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 45476439Sml29623 "==> nxge_m_setprop: set MTU: %d is_jumbo %d", 45486439Sml29623 new_mtu, nxgep->mac.is_jumbo)); 45496439Sml29623 45506439Sml29623 if (new_mtu == cur_mtu) { 45516439Sml29623 err = 0; 45526439Sml29623 break; 45536439Sml29623 } 45546439Sml29623 if (new_mtu < NXGE_DEFAULT_MTU || 45556439Sml29623 new_mtu > NXGE_MAXIMUM_MTU) { 45566439Sml29623 err = EINVAL; 45576439Sml29623 break; 45586439Sml29623 } 45596439Sml29623 45606439Sml29623 if ((new_mtu > NXGE_DEFAULT_MTU) && 45616439Sml29623 !nxgep->mac.is_jumbo) { 45626439Sml29623 err = EINVAL; 45636439Sml29623 break; 45646439Sml29623 } 45656439Sml29623 45666439Sml29623 old_framesize = (uint32_t)nxgep->mac.maxframesize; 45676439Sml29623 nxgep->mac.maxframesize = (uint16_t) 45686439Sml29623 (new_mtu + NXGE_EHEADER_VLAN_CRC); 45696439Sml29623 if (nxge_mac_set_framesize(nxgep)) { 45706444Sml29623 nxgep->mac.maxframesize = 45716444Sml29623 (uint16_t)old_framesize; 45726439Sml29623 err = EINVAL; 45736439Sml29623 break; 45746439Sml29623 } 45756439Sml29623 45766439Sml29623 err = mac_maxsdu_update(nxgep->mach, new_mtu); 45776439Sml29623 if (err) { 45786444Sml29623 nxgep->mac.maxframesize = 45796444Sml29623 (uint16_t)old_framesize; 45806439Sml29623 err = EINVAL; 45816439Sml29623 break; 45826439Sml29623 } 45836439Sml29623 45846439Sml29623 nxgep->mac.default_mtu = new_mtu; 45856439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 45866439Sml29623 "==> nxge_m_setprop: set MTU: %d maxframe %d", 45876439Sml29623 new_mtu, nxgep->mac.maxframesize)); 45886439Sml29623 break; 45896439Sml29623 45906439Sml29623 case DLD_PROP_FLOWCTRL: 45916439Sml29623 bcopy(pr_val, &fl, sizeof (fl)); 45926439Sml29623 switch (fl) { 45936439Sml29623 default: 45946439Sml29623 err = EINVAL; 45956439Sml29623 break; 45966439Sml29623 45976439Sml29623 case LINK_FLOWCTRL_NONE: 45986439Sml29623 param_arr[param_anar_pause].value = 0; 45996439Sml29623 break; 46006439Sml29623 46016439Sml29623 case LINK_FLOWCTRL_RX: 46026439Sml29623 param_arr[param_anar_pause].value = 1; 46036439Sml29623 break; 46046439Sml29623 46056439Sml29623 case LINK_FLOWCTRL_TX: 46066439Sml29623 case LINK_FLOWCTRL_BI: 46076439Sml29623 err = EINVAL; 46086439Sml29623 break; 46096439Sml29623 } 46106439Sml29623 46116439Sml29623 reprogram: 46126439Sml29623 if (err == 0) { 46136439Sml29623 if (!nxge_param_link_update(nxgep)) { 46146439Sml29623 err = EINVAL; 46156439Sml29623 } 46166439Sml29623 } 46176439Sml29623 break; 46186439Sml29623 46196439Sml29623 default: 46206439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 46216439Sml29623 "==> nxge_m_setprop: private property")); 46226439Sml29623 err = nxge_set_priv_prop(nxgep, pr_name, pr_valsize, 46236439Sml29623 pr_val); 46246439Sml29623 break; 46256439Sml29623 } 46266439Sml29623 46276439Sml29623 mutex_exit(nxgep->genlock); 46286439Sml29623 46296439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 46306439Sml29623 "<== nxge_m_setprop (return %d)", err)); 46316439Sml29623 return (err); 46326439Sml29623 } 46336439Sml29623 46346439Sml29623 static int 46356439Sml29623 nxge_m_getprop(void *barg, const char *pr_name, mac_prop_id_t pr_num, 46366439Sml29623 uint_t pr_valsize, void *pr_val) 46376439Sml29623 { 46386439Sml29623 nxge_t *nxgep = barg; 46396439Sml29623 p_nxge_param_t param_arr = nxgep->param_arr; 46406439Sml29623 p_nxge_stats_t statsp = nxgep->statsp; 46416439Sml29623 int err = 0; 46426439Sml29623 link_flowctrl_t fl; 46436439Sml29623 uint64_t tmp = 0; 46446439Sml29623 46456439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 46466439Sml29623 "==> nxge_m_getprop: pr_num %d", pr_num)); 46476439Sml29623 bzero(pr_val, pr_valsize); 46486439Sml29623 switch (pr_num) { 46496439Sml29623 case DLD_PROP_DUPLEX: 46506439Sml29623 if (pr_valsize < sizeof (uint8_t)) 46516439Sml29623 return (EINVAL); 46526439Sml29623 *(uint8_t *)pr_val = statsp->mac_stats.link_duplex; 46536439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 46546439Sml29623 "==> nxge_m_getprop: duplex mode %d", 46556439Sml29623 *(uint8_t *)pr_val)); 46566439Sml29623 break; 46576439Sml29623 46586439Sml29623 case DLD_PROP_SPEED: 46596439Sml29623 if (pr_valsize < sizeof (uint64_t)) 46606439Sml29623 return (EINVAL); 46616439Sml29623 tmp = statsp->mac_stats.link_speed * 1000000ull; 46626439Sml29623 bcopy(&tmp, pr_val, sizeof (tmp)); 46636439Sml29623 break; 46646439Sml29623 46656439Sml29623 case DLD_PROP_STATUS: 46666439Sml29623 if (pr_valsize < sizeof (uint8_t)) 46676439Sml29623 return (EINVAL); 46686439Sml29623 *(uint8_t *)pr_val = statsp->mac_stats.link_up; 46696439Sml29623 break; 46706439Sml29623 46716439Sml29623 case DLD_PROP_AUTONEG: 46726439Sml29623 if (pr_valsize < sizeof (uint8_t)) 46736439Sml29623 return (EINVAL); 46746439Sml29623 *(uint8_t *)pr_val = 46756439Sml29623 param_arr[param_autoneg].value; 46766439Sml29623 break; 46776439Sml29623 46786439Sml29623 46796439Sml29623 case DLD_PROP_DEFMTU: { 46806439Sml29623 if (pr_valsize < sizeof (uint64_t)) 46816439Sml29623 return (EINVAL); 46826439Sml29623 tmp = nxgep->mac.default_mtu; 46836439Sml29623 bcopy(&tmp, pr_val, sizeof (tmp)); 46846439Sml29623 break; 46856439Sml29623 } 46866439Sml29623 46876439Sml29623 case DLD_PROP_FLOWCTRL: 46886439Sml29623 if (pr_valsize < sizeof (link_flowctrl_t)) 46896439Sml29623 return (EINVAL); 46906439Sml29623 46916439Sml29623 fl = LINK_FLOWCTRL_NONE; 46926439Sml29623 if (param_arr[param_anar_pause].value) { 46936439Sml29623 fl = LINK_FLOWCTRL_RX; 46946439Sml29623 } 46956439Sml29623 bcopy(&fl, pr_val, sizeof (fl)); 46966439Sml29623 break; 46976439Sml29623 46986439Sml29623 case DLD_PROP_ADV_1000FDX_CAP: 46996439Sml29623 if (pr_valsize < sizeof (uint8_t)) 47006439Sml29623 return (EINVAL); 47016439Sml29623 *(uint8_t *)pr_val = 47026439Sml29623 param_arr[param_anar_1000fdx].value; 47036439Sml29623 break; 47046439Sml29623 47056439Sml29623 case DLD_PROP_EN_1000FDX_CAP: 47066439Sml29623 if (pr_valsize < sizeof (uint8_t)) 47076439Sml29623 return (EINVAL); 47086439Sml29623 *(uint8_t *)pr_val = nxgep->param_en_1000fdx; 47096439Sml29623 break; 47106439Sml29623 47116439Sml29623 case DLD_PROP_ADV_100FDX_CAP: 47126439Sml29623 if (pr_valsize < sizeof (uint8_t)) 47136439Sml29623 return (EINVAL); 47146439Sml29623 *(uint8_t *)pr_val = 47156439Sml29623 param_arr[param_anar_100fdx].value; 47166439Sml29623 break; 47176439Sml29623 47186439Sml29623 case DLD_PROP_EN_100FDX_CAP: 47196439Sml29623 if (pr_valsize < sizeof (uint8_t)) 47206439Sml29623 return (EINVAL); 47216439Sml29623 *(uint8_t *)pr_val = nxgep->param_en_100fdx; 47226439Sml29623 break; 47236439Sml29623 47246439Sml29623 case DLD_PROP_ADV_10FDX_CAP: 47256439Sml29623 if (pr_valsize < sizeof (uint8_t)) 47266439Sml29623 return (EINVAL); 47276439Sml29623 *(uint8_t *)pr_val = 47286439Sml29623 param_arr[param_anar_10fdx].value; 47296439Sml29623 break; 47306439Sml29623 47316439Sml29623 case DLD_PROP_EN_10FDX_CAP: 47326439Sml29623 if (pr_valsize < sizeof (uint8_t)) 47336439Sml29623 return (EINVAL); 47346439Sml29623 *(uint8_t *)pr_val = nxgep->param_en_10fdx; 47356439Sml29623 break; 47366439Sml29623 47376439Sml29623 case DLD_PROP_EN_1000HDX_CAP: 47386439Sml29623 case DLD_PROP_EN_100HDX_CAP: 47396439Sml29623 case DLD_PROP_EN_10HDX_CAP: 47406439Sml29623 case DLD_PROP_ADV_1000HDX_CAP: 47416439Sml29623 case DLD_PROP_ADV_100HDX_CAP: 47426439Sml29623 case DLD_PROP_ADV_10HDX_CAP: 47436439Sml29623 err = EINVAL; 47446439Sml29623 break; 47456439Sml29623 47466439Sml29623 default: 47476439Sml29623 err = nxge_get_priv_prop(nxgep, pr_name, pr_valsize, 47486439Sml29623 pr_val); 47496439Sml29623 } 47506439Sml29623 47516439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, "<== nxge_m_getprop")); 47526439Sml29623 47536439Sml29623 return (err); 47546439Sml29623 } 47556439Sml29623 47566439Sml29623 /* ARGSUSED */ 47576439Sml29623 static int 47586439Sml29623 nxge_set_priv_prop(p_nxge_t nxgep, const char *pr_name, uint_t pr_valsize, 47596439Sml29623 const void *pr_val) 47606439Sml29623 { 47616439Sml29623 p_nxge_param_t param_arr = nxgep->param_arr; 47626439Sml29623 int err = 0; 47636439Sml29623 long result; 47646439Sml29623 47656439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 47666439Sml29623 "==> nxge_set_priv_prop: name %s", pr_name)); 47676439Sml29623 47686439Sml29623 if (strcmp(pr_name, "_accept_jumbo") == 0) { 47696439Sml29623 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 47706439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 47716439Sml29623 "<== nxge_set_priv_prop: name %s " 47726439Sml29623 "pr_val %s result %d " 47736439Sml29623 "param %d is_jumbo %d", 47746439Sml29623 pr_name, pr_val, result, 47756439Sml29623 param_arr[param_accept_jumbo].value, 47766439Sml29623 nxgep->mac.is_jumbo)); 47776439Sml29623 47786439Sml29623 if (result > 1 || result < 0) { 47796439Sml29623 err = EINVAL; 47806439Sml29623 } else { 47816439Sml29623 if (nxgep->mac.is_jumbo == 47826439Sml29623 (uint32_t)result) { 47836439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 47846439Sml29623 "no change (%d %d)", 47856439Sml29623 nxgep->mac.is_jumbo, 47866439Sml29623 result)); 47876439Sml29623 return (0); 47886439Sml29623 } 47896439Sml29623 } 47906439Sml29623 47916439Sml29623 param_arr[param_accept_jumbo].value = result; 47926439Sml29623 nxgep->mac.is_jumbo = B_FALSE; 47936439Sml29623 if (result) { 47946439Sml29623 nxgep->mac.is_jumbo = B_TRUE; 47956439Sml29623 } 47966439Sml29623 47976439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 47986439Sml29623 "<== nxge_set_priv_prop: name %s (value %d) is_jumbo %d", 47996439Sml29623 pr_name, result, nxgep->mac.is_jumbo)); 48006439Sml29623 48016439Sml29623 return (err); 48026439Sml29623 } 48036439Sml29623 48046439Sml29623 /* Blanking */ 48056439Sml29623 if (strcmp(pr_name, "_rxdma_intr_time") == 0) { 48066439Sml29623 err = nxge_param_rx_intr_time(nxgep, NULL, NULL, 48076439Sml29623 (char *)pr_val, 48086439Sml29623 (caddr_t)¶m_arr[param_rxdma_intr_time]); 48096439Sml29623 if (err) { 48106439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 48116439Sml29623 "<== nxge_set_priv_prop: " 48126439Sml29623 "unable to set (%s)", pr_name)); 48136439Sml29623 err = EINVAL; 48146439Sml29623 } else { 48156439Sml29623 err = 0; 48166439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 48176439Sml29623 "<== nxge_set_priv_prop: " 48186439Sml29623 "set (%s)", pr_name)); 48196439Sml29623 } 48206439Sml29623 48216439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 48226439Sml29623 "<== nxge_set_priv_prop: name %s (value %d)", 48236439Sml29623 pr_name, result)); 48246439Sml29623 48256439Sml29623 return (err); 48266439Sml29623 } 48276439Sml29623 48286439Sml29623 if (strcmp(pr_name, "_rxdma_intr_pkts") == 0) { 48296439Sml29623 err = nxge_param_rx_intr_pkts(nxgep, NULL, NULL, 48306439Sml29623 (char *)pr_val, 48316439Sml29623 (caddr_t)¶m_arr[param_rxdma_intr_pkts]); 48326439Sml29623 if (err) { 48336439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 48346439Sml29623 "<== nxge_set_priv_prop: " 48356439Sml29623 "unable to set (%s)", pr_name)); 48366439Sml29623 err = EINVAL; 48376439Sml29623 } else { 48386439Sml29623 err = 0; 48396439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 48406439Sml29623 "<== nxge_set_priv_prop: " 48416439Sml29623 "set (%s)", pr_name)); 48426439Sml29623 } 48436439Sml29623 48446439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 48456439Sml29623 "<== nxge_set_priv_prop: name %s (value %d)", 48466439Sml29623 pr_name, result)); 48476439Sml29623 48486439Sml29623 return (err); 48496439Sml29623 } 48506439Sml29623 48516439Sml29623 /* Classification */ 48526439Sml29623 if (strcmp(pr_name, "_class_opt_ipv4_tcp") == 0) { 48536439Sml29623 if (pr_val == NULL) { 48546439Sml29623 err = EINVAL; 48556439Sml29623 return (err); 48566439Sml29623 } 48576439Sml29623 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 48586439Sml29623 48596439Sml29623 err = nxge_param_set_ip_opt(nxgep, NULL, 48606439Sml29623 NULL, (char *)pr_val, 48616439Sml29623 (caddr_t)¶m_arr[param_class_opt_ipv4_tcp]); 48626439Sml29623 48636439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 48646439Sml29623 "<== nxge_set_priv_prop: name %s (value 0x%x)", 48656439Sml29623 pr_name, result)); 48666439Sml29623 48676439Sml29623 return (err); 48686439Sml29623 } 48696439Sml29623 48706439Sml29623 if (strcmp(pr_name, "_class_opt_ipv4_udp") == 0) { 48716439Sml29623 if (pr_val == NULL) { 48726439Sml29623 err = EINVAL; 48736439Sml29623 return (err); 48746439Sml29623 } 48756439Sml29623 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 48766439Sml29623 48776439Sml29623 err = nxge_param_set_ip_opt(nxgep, NULL, 48786439Sml29623 NULL, (char *)pr_val, 48796439Sml29623 (caddr_t)¶m_arr[param_class_opt_ipv4_udp]); 48806439Sml29623 48816439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 48826439Sml29623 "<== nxge_set_priv_prop: name %s (value 0x%x)", 48836439Sml29623 pr_name, result)); 48846439Sml29623 48856439Sml29623 return (err); 48866439Sml29623 } 48876439Sml29623 if (strcmp(pr_name, "_class_opt_ipv4_ah") == 0) { 48886439Sml29623 if (pr_val == NULL) { 48896439Sml29623 err = EINVAL; 48906439Sml29623 return (err); 48916439Sml29623 } 48926439Sml29623 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 48936439Sml29623 48946439Sml29623 err = nxge_param_set_ip_opt(nxgep, NULL, 48956439Sml29623 NULL, (char *)pr_val, 48966439Sml29623 (caddr_t)¶m_arr[param_class_opt_ipv4_ah]); 48976439Sml29623 48986439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 48996439Sml29623 "<== nxge_set_priv_prop: name %s (value 0x%x)", 49006439Sml29623 pr_name, result)); 49016439Sml29623 49026439Sml29623 return (err); 49036439Sml29623 } 49046439Sml29623 if (strcmp(pr_name, "_class_opt_ipv4_sctp") == 0) { 49056439Sml29623 if (pr_val == NULL) { 49066439Sml29623 err = EINVAL; 49076439Sml29623 return (err); 49086439Sml29623 } 49096439Sml29623 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 49106439Sml29623 49116439Sml29623 err = nxge_param_set_ip_opt(nxgep, NULL, 49126439Sml29623 NULL, (char *)pr_val, 49136439Sml29623 (caddr_t)¶m_arr[param_class_opt_ipv4_sctp]); 49146439Sml29623 49156439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 49166439Sml29623 "<== nxge_set_priv_prop: name %s (value 0x%x)", 49176439Sml29623 pr_name, result)); 49186439Sml29623 49196439Sml29623 return (err); 49206439Sml29623 } 49216439Sml29623 49226439Sml29623 if (strcmp(pr_name, "_class_opt_ipv6_tcp") == 0) { 49236439Sml29623 if (pr_val == NULL) { 49246439Sml29623 err = EINVAL; 49256439Sml29623 return (err); 49266439Sml29623 } 49276439Sml29623 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 49286439Sml29623 49296439Sml29623 err = nxge_param_set_ip_opt(nxgep, NULL, 49306439Sml29623 NULL, (char *)pr_val, 49316439Sml29623 (caddr_t)¶m_arr[param_class_opt_ipv6_tcp]); 49326439Sml29623 49336439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 49346439Sml29623 "<== nxge_set_priv_prop: name %s (value 0x%x)", 49356439Sml29623 pr_name, result)); 49366439Sml29623 49376439Sml29623 return (err); 49386439Sml29623 } 49396439Sml29623 49406439Sml29623 if (strcmp(pr_name, "_class_opt_ipv6_udp") == 0) { 49416439Sml29623 if (pr_val == NULL) { 49426439Sml29623 err = EINVAL; 49436439Sml29623 return (err); 49446439Sml29623 } 49456439Sml29623 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 49466439Sml29623 49476439Sml29623 err = nxge_param_set_ip_opt(nxgep, NULL, 49486439Sml29623 NULL, (char *)pr_val, 49496439Sml29623 (caddr_t)¶m_arr[param_class_opt_ipv6_udp]); 49506439Sml29623 49516439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 49526439Sml29623 "<== nxge_set_priv_prop: name %s (value 0x%x)", 49536439Sml29623 pr_name, result)); 49546439Sml29623 49556439Sml29623 return (err); 49566439Sml29623 } 49576439Sml29623 if (strcmp(pr_name, "_class_opt_ipv6_ah") == 0) { 49586439Sml29623 if (pr_val == NULL) { 49596439Sml29623 err = EINVAL; 49606439Sml29623 return (err); 49616439Sml29623 } 49626439Sml29623 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 49636439Sml29623 49646439Sml29623 err = nxge_param_set_ip_opt(nxgep, NULL, 49656439Sml29623 NULL, (char *)pr_val, 49666439Sml29623 (caddr_t)¶m_arr[param_class_opt_ipv6_ah]); 49676439Sml29623 49686439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 49696439Sml29623 "<== nxge_set_priv_prop: name %s (value 0x%x)", 49706439Sml29623 pr_name, result)); 49716439Sml29623 49726439Sml29623 return (err); 49736439Sml29623 } 49746439Sml29623 if (strcmp(pr_name, "_class_opt_ipv6_sctp") == 0) { 49756439Sml29623 if (pr_val == NULL) { 49766439Sml29623 err = EINVAL; 49776439Sml29623 return (err); 49786439Sml29623 } 49796439Sml29623 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 49806439Sml29623 49816439Sml29623 err = nxge_param_set_ip_opt(nxgep, NULL, 49826439Sml29623 NULL, (char *)pr_val, 49836439Sml29623 (caddr_t)¶m_arr[param_class_opt_ipv6_sctp]); 49846439Sml29623 49856439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 49866439Sml29623 "<== nxge_set_priv_prop: name %s (value 0x%x)", 49876439Sml29623 pr_name, result)); 49886439Sml29623 49896439Sml29623 return (err); 49906439Sml29623 } 49916439Sml29623 49926439Sml29623 if (strcmp(pr_name, "_soft_lso_enable") == 0) { 49936439Sml29623 if (nxgep->nxge_mac_state == NXGE_MAC_STARTED) { 49946439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 49956439Sml29623 "==> nxge_set_priv_prop: name %s (busy)", pr_name)); 49966439Sml29623 err = EBUSY; 49976439Sml29623 return (err); 49986439Sml29623 } 49996439Sml29623 if (pr_val == NULL) { 50006439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 50016439Sml29623 "==> nxge_set_priv_prop: name %s (null)", pr_name)); 50026439Sml29623 err = EINVAL; 50036439Sml29623 return (err); 50046439Sml29623 } 50056439Sml29623 50066439Sml29623 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 50076439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 50086439Sml29623 "<== nxge_set_priv_prop: name %s " 50096439Sml29623 "(lso %d pr_val %s value %d)", 50106439Sml29623 pr_name, nxgep->soft_lso_enable, pr_val, result)); 50116439Sml29623 50126439Sml29623 if (result > 1 || result < 0) { 50136439Sml29623 err = EINVAL; 50146439Sml29623 } else { 50156439Sml29623 if (nxgep->soft_lso_enable == (uint32_t)result) { 50166439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 50176439Sml29623 "no change (%d %d)", 50186439Sml29623 nxgep->soft_lso_enable, result)); 50196439Sml29623 return (0); 50206439Sml29623 } 50216439Sml29623 } 50226439Sml29623 50236439Sml29623 nxgep->soft_lso_enable = (int)result; 50246439Sml29623 50256439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 50266439Sml29623 "<== nxge_set_priv_prop: name %s (value %d)", 50276439Sml29623 pr_name, result)); 50286439Sml29623 50296439Sml29623 return (err); 50306439Sml29623 } 50316439Sml29623 50326439Sml29623 return (EINVAL); 50336439Sml29623 } 50346439Sml29623 50356439Sml29623 static int 50366439Sml29623 nxge_get_priv_prop(p_nxge_t nxgep, const char *pr_name, uint_t pr_valsize, 50376439Sml29623 void *pr_val) 50386439Sml29623 { 50396439Sml29623 p_nxge_param_t param_arr = nxgep->param_arr; 50406439Sml29623 char valstr[MAXNAMELEN]; 50416439Sml29623 int err = EINVAL; 50426439Sml29623 uint_t strsize; 50436439Sml29623 50446439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 50456439Sml29623 "==> nxge_get_priv_prop: property %s", pr_name)); 50466439Sml29623 50476439Sml29623 /* function number */ 50486439Sml29623 if (strcmp(pr_name, "_function_number") == 0) { 50496439Sml29623 (void) sprintf(valstr, "%d", nxgep->function_num); 50506439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 50516439Sml29623 "==> nxge_get_priv_prop: name %s " 50526439Sml29623 "(value %d valstr %s)", 50536439Sml29623 pr_name, nxgep->function_num, valstr)); 50546439Sml29623 50556439Sml29623 err = 0; 50566439Sml29623 goto done; 50576439Sml29623 } 50586439Sml29623 50596439Sml29623 /* Neptune firmware version */ 50606439Sml29623 if (strcmp(pr_name, "_fw_version") == 0) { 50616439Sml29623 (void) sprintf(valstr, "%s", nxgep->vpd_info.ver); 50626439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 50636439Sml29623 "==> nxge_get_priv_prop: name %s " 50646439Sml29623 "(value %d valstr %s)", 50656439Sml29623 pr_name, nxgep->vpd_info.ver, valstr)); 50666439Sml29623 50676439Sml29623 err = 0; 50686439Sml29623 goto done; 50696439Sml29623 } 50706439Sml29623 50716439Sml29623 /* port PHY mode */ 50726439Sml29623 if (strcmp(pr_name, "_port_mode") == 0) { 50736439Sml29623 switch (nxgep->mac.portmode) { 50746439Sml29623 case PORT_1G_COPPER: 50756439Sml29623 (void) sprintf(valstr, "1G copper %s", 50766439Sml29623 nxgep->hot_swappable_phy ? 50776439Sml29623 "[Hot Swappable]" : ""); 50786439Sml29623 break; 50796439Sml29623 case PORT_1G_FIBER: 50806439Sml29623 (void) sprintf(valstr, "1G fiber %s", 50816439Sml29623 nxgep->hot_swappable_phy ? 50826439Sml29623 "[hot swappable]" : ""); 50836439Sml29623 break; 50846439Sml29623 case PORT_10G_COPPER: 50856439Sml29623 (void) sprintf(valstr, "10G copper %s", 50866439Sml29623 nxgep->hot_swappable_phy ? 50876439Sml29623 "[hot swappable]" : ""); 50886439Sml29623 break; 50896439Sml29623 case PORT_10G_FIBER: 50906439Sml29623 (void) sprintf(valstr, "10G fiber %s", 50916439Sml29623 nxgep->hot_swappable_phy ? 50926439Sml29623 "[hot swappable]" : ""); 50936439Sml29623 break; 50946439Sml29623 case PORT_10G_SERDES: 50956439Sml29623 (void) sprintf(valstr, "10G serdes %s", 50966439Sml29623 nxgep->hot_swappable_phy ? 50976439Sml29623 "[hot swappable]" : ""); 50986439Sml29623 break; 50996439Sml29623 case PORT_1G_SERDES: 51006439Sml29623 (void) sprintf(valstr, "1G serdes %s", 51016439Sml29623 nxgep->hot_swappable_phy ? 51026439Sml29623 "[hot swappable]" : ""); 51036439Sml29623 break; 51046439Sml29623 case PORT_1G_RGMII_FIBER: 51056439Sml29623 (void) sprintf(valstr, "1G rgmii fiber %s", 51066439Sml29623 nxgep->hot_swappable_phy ? 51076439Sml29623 "[hot swappable]" : ""); 51086439Sml29623 break; 51096439Sml29623 case PORT_HSP_MODE: 51106444Sml29623 (void) sprintf(valstr, 51116444Sml29623 "phy not present[hot swappable]"); 51126439Sml29623 break; 51136439Sml29623 default: 51146439Sml29623 (void) sprintf(valstr, "unknown %s", 51156439Sml29623 nxgep->hot_swappable_phy ? 51166439Sml29623 "[hot swappable]" : ""); 51176439Sml29623 break; 51186439Sml29623 } 51196439Sml29623 51206439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 51216439Sml29623 "==> nxge_get_priv_prop: name %s (value %s)", 51226439Sml29623 pr_name, valstr)); 51236439Sml29623 51246439Sml29623 err = 0; 51256439Sml29623 goto done; 51266439Sml29623 } 51276439Sml29623 51286439Sml29623 /* Hot swappable PHY */ 51296439Sml29623 if (strcmp(pr_name, "_hot_swap_phy") == 0) { 51306439Sml29623 (void) sprintf(valstr, "%s", 51316439Sml29623 nxgep->hot_swappable_phy ? 51326439Sml29623 "yes" : "no"); 51336439Sml29623 51346439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 51356439Sml29623 "==> nxge_get_priv_prop: name %s " 51366439Sml29623 "(value %d valstr %s)", 51376439Sml29623 pr_name, nxgep->hot_swappable_phy, valstr)); 51386439Sml29623 51396439Sml29623 err = 0; 51406439Sml29623 goto done; 51416439Sml29623 } 51426439Sml29623 51436439Sml29623 51446439Sml29623 /* accept jumbo */ 51456439Sml29623 if (strcmp(pr_name, "_accept_jumbo") == 0) { 51466439Sml29623 (void) sprintf(valstr, "%d", nxgep->mac.is_jumbo); 51476439Sml29623 err = 0; 51486439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 51496439Sml29623 "==> nxge_get_priv_prop: name %s (value %d (%d, %d))", 51506439Sml29623 pr_name, 51516439Sml29623 (uint32_t)param_arr[param_accept_jumbo].value, 51526439Sml29623 nxgep->mac.is_jumbo, 51536439Sml29623 nxge_jumbo_enable)); 51546439Sml29623 51556439Sml29623 goto done; 51566439Sml29623 } 51576439Sml29623 51586439Sml29623 /* Receive Interrupt Blanking Parameters */ 51596439Sml29623 if (strcmp(pr_name, "_rxdma_intr_time") == 0) { 51606439Sml29623 (void) sprintf(valstr, "%d", nxgep->intr_timeout); 51616439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 51626439Sml29623 "==> nxge_get_priv_prop: name %s (value %d)", 51636439Sml29623 pr_name, 51646439Sml29623 (uint32_t)nxgep->intr_timeout)); 51656439Sml29623 err = 0; 51666439Sml29623 goto done; 51676439Sml29623 } 51686439Sml29623 51696439Sml29623 if (strcmp(pr_name, "_rxdma_intr_pkts") == 0) { 51706439Sml29623 (void) sprintf(valstr, "%d", nxgep->intr_threshold); 51716439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 51726439Sml29623 "==> nxge_get_priv_prop: name %s (value %d)", 51736439Sml29623 pr_name, (uint32_t)nxgep->intr_threshold)); 51746439Sml29623 51756439Sml29623 err = 0; 51766439Sml29623 goto done; 51776439Sml29623 } 51786439Sml29623 51796439Sml29623 /* Classification and Load Distribution Configuration */ 51806439Sml29623 if (strcmp(pr_name, "_class_opt_ipv4_tcp") == 0) { 51816439Sml29623 err = nxge_dld_get_ip_opt(nxgep, 51826439Sml29623 (caddr_t)¶m_arr[param_class_opt_ipv4_tcp]); 51836439Sml29623 51846439Sml29623 (void) sprintf(valstr, "%x", 51856439Sml29623 (int)param_arr[param_class_opt_ipv4_tcp].value); 51866439Sml29623 51876439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 51886439Sml29623 "==> nxge_get_priv_prop: %s", valstr)); 51896439Sml29623 goto done; 51906439Sml29623 } 51916439Sml29623 51926439Sml29623 if (strcmp(pr_name, "_class_opt_ipv4_udp") == 0) { 51936439Sml29623 err = nxge_dld_get_ip_opt(nxgep, 51946439Sml29623 (caddr_t)¶m_arr[param_class_opt_ipv4_udp]); 51956439Sml29623 51966439Sml29623 (void) sprintf(valstr, "%x", 51976439Sml29623 (int)param_arr[param_class_opt_ipv4_udp].value); 51986439Sml29623 51996439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 52006439Sml29623 "==> nxge_get_priv_prop: %s", valstr)); 52016439Sml29623 goto done; 52026439Sml29623 } 52036439Sml29623 if (strcmp(pr_name, "_class_opt_ipv4_ah") == 0) { 52046439Sml29623 err = nxge_dld_get_ip_opt(nxgep, 52056439Sml29623 (caddr_t)¶m_arr[param_class_opt_ipv4_ah]); 52066439Sml29623 52076439Sml29623 (void) sprintf(valstr, "%x", 52086439Sml29623 (int)param_arr[param_class_opt_ipv4_ah].value); 52096439Sml29623 52106439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 52116439Sml29623 "==> nxge_get_priv_prop: %s", valstr)); 52126439Sml29623 goto done; 52136439Sml29623 } 52146439Sml29623 52156439Sml29623 if (strcmp(pr_name, "_class_opt_ipv4_sctp") == 0) { 52166439Sml29623 err = nxge_dld_get_ip_opt(nxgep, 52176439Sml29623 (caddr_t)¶m_arr[param_class_opt_ipv4_sctp]); 52186439Sml29623 52196439Sml29623 (void) printf(valstr, "%x", 52206439Sml29623 (int)param_arr[param_class_opt_ipv4_sctp].value); 52216439Sml29623 52226439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 52236439Sml29623 "==> nxge_get_priv_prop: %s", valstr)); 52246439Sml29623 goto done; 52256439Sml29623 } 52266439Sml29623 52276439Sml29623 if (strcmp(pr_name, "_class_opt_ipv6_tcp") == 0) { 52286439Sml29623 err = nxge_dld_get_ip_opt(nxgep, 52296439Sml29623 (caddr_t)¶m_arr[param_class_opt_ipv6_tcp]); 52306439Sml29623 52316439Sml29623 (void) sprintf(valstr, "%x", 52326439Sml29623 (int)param_arr[param_class_opt_ipv6_tcp].value); 52336439Sml29623 52346439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 52356439Sml29623 "==> nxge_get_priv_prop: %s", valstr)); 52366439Sml29623 err = 0; 52376439Sml29623 goto done; 52386439Sml29623 } 52396439Sml29623 52406439Sml29623 if (strcmp(pr_name, "_class_opt_ipv6_udp") == 0) { 52416439Sml29623 err = nxge_dld_get_ip_opt(nxgep, 52426439Sml29623 (caddr_t)¶m_arr[param_class_opt_ipv6_udp]); 52436439Sml29623 52446439Sml29623 (void) sprintf(valstr, "%x", 52456439Sml29623 (int)param_arr[param_class_opt_ipv6_udp].value); 52466439Sml29623 52476439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 52486439Sml29623 "==> nxge_get_priv_prop: %s", valstr)); 52496439Sml29623 goto done; 52506439Sml29623 } 52516439Sml29623 52526439Sml29623 if (strcmp(pr_name, "_class_opt_ipv6_ah") == 0) { 52536439Sml29623 err = nxge_dld_get_ip_opt(nxgep, 52546439Sml29623 (caddr_t)¶m_arr[param_class_opt_ipv6_ah]); 52556439Sml29623 52566439Sml29623 (void) sprintf(valstr, "%x", 52576439Sml29623 (int)param_arr[param_class_opt_ipv6_ah].value); 52586439Sml29623 52596439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 52606439Sml29623 "==> nxge_get_priv_prop: %s", valstr)); 52616439Sml29623 goto done; 52626439Sml29623 } 52636439Sml29623 52646439Sml29623 if (strcmp(pr_name, "_class_opt_ipv6_sctp") == 0) { 52656439Sml29623 err = nxge_dld_get_ip_opt(nxgep, 52666439Sml29623 (caddr_t)¶m_arr[param_class_opt_ipv6_sctp]); 52676439Sml29623 52686439Sml29623 (void) sprintf(valstr, "%x", 52696439Sml29623 (int)param_arr[param_class_opt_ipv6_sctp].value); 52706439Sml29623 52716439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 52726439Sml29623 "==> nxge_get_priv_prop: %s", valstr)); 52736439Sml29623 goto done; 52746439Sml29623 } 52756439Sml29623 52766439Sml29623 /* Software LSO */ 52776439Sml29623 if (strcmp(pr_name, "_soft_lso_enable") == 0) { 52786439Sml29623 (void) sprintf(valstr, "%d", nxgep->soft_lso_enable); 52796439Sml29623 err = 0; 52806439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 52816439Sml29623 "==> nxge_get_priv_prop: name %s (value %d)", 52826439Sml29623 pr_name, nxgep->soft_lso_enable)); 52836439Sml29623 52846439Sml29623 goto done; 52856439Sml29623 } 52866439Sml29623 52876439Sml29623 done: 52886439Sml29623 if (err == 0) { 52896439Sml29623 strsize = (uint_t)strlen(valstr); 52906439Sml29623 if (pr_valsize < strsize) { 52916439Sml29623 err = ENOBUFS; 52926439Sml29623 } else { 52936439Sml29623 (void) strlcpy(pr_val, valstr, pr_valsize); 52946439Sml29623 } 52956439Sml29623 } 52966439Sml29623 52976439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 52986439Sml29623 "<== nxge_get_priv_prop: return %d", err)); 52996439Sml29623 return (err); 53006439Sml29623 } 53016439Sml29623 53023859Sml29623 /* 53033859Sml29623 * Module loading and removing entry points. 53043859Sml29623 */ 53053859Sml29623 53063859Sml29623 static struct cb_ops nxge_cb_ops = { 53073859Sml29623 nodev, /* cb_open */ 53083859Sml29623 nodev, /* cb_close */ 53093859Sml29623 nodev, /* cb_strategy */ 53103859Sml29623 nodev, /* cb_print */ 53113859Sml29623 nodev, /* cb_dump */ 53123859Sml29623 nodev, /* cb_read */ 53133859Sml29623 nodev, /* cb_write */ 53143859Sml29623 nodev, /* cb_ioctl */ 53153859Sml29623 nodev, /* cb_devmap */ 53163859Sml29623 nodev, /* cb_mmap */ 53173859Sml29623 nodev, /* cb_segmap */ 53183859Sml29623 nochpoll, /* cb_chpoll */ 53193859Sml29623 ddi_prop_op, /* cb_prop_op */ 53203859Sml29623 NULL, 53213859Sml29623 D_MP, /* cb_flag */ 53223859Sml29623 CB_REV, /* rev */ 53233859Sml29623 nodev, /* int (*cb_aread)() */ 53243859Sml29623 nodev /* int (*cb_awrite)() */ 53253859Sml29623 }; 53263859Sml29623 53273859Sml29623 static struct dev_ops nxge_dev_ops = { 53283859Sml29623 DEVO_REV, /* devo_rev */ 53293859Sml29623 0, /* devo_refcnt */ 53303859Sml29623 nulldev, 53313859Sml29623 nulldev, /* devo_identify */ 53323859Sml29623 nulldev, /* devo_probe */ 53333859Sml29623 nxge_attach, /* devo_attach */ 53343859Sml29623 nxge_detach, /* devo_detach */ 53353859Sml29623 nodev, /* devo_reset */ 53363859Sml29623 &nxge_cb_ops, /* devo_cb_ops */ 53373859Sml29623 (struct bus_ops *)NULL, /* devo_bus_ops */ 53383859Sml29623 ddi_power /* devo_power */ 53393859Sml29623 }; 53403859Sml29623 53413859Sml29623 extern struct mod_ops mod_driverops; 53423859Sml29623 53434977Sraghus #define NXGE_DESC_VER "Sun NIU 10Gb Ethernet" 53443859Sml29623 53453859Sml29623 /* 53463859Sml29623 * Module linkage information for the kernel. 53473859Sml29623 */ 53483859Sml29623 static struct modldrv nxge_modldrv = { 53493859Sml29623 &mod_driverops, 53503859Sml29623 NXGE_DESC_VER, 53513859Sml29623 &nxge_dev_ops 53523859Sml29623 }; 53533859Sml29623 53543859Sml29623 static struct modlinkage modlinkage = { 53553859Sml29623 MODREV_1, (void *) &nxge_modldrv, NULL 53563859Sml29623 }; 53573859Sml29623 53583859Sml29623 int 53593859Sml29623 _init(void) 53603859Sml29623 { 53613859Sml29623 int status; 53623859Sml29623 53633859Sml29623 NXGE_DEBUG_MSG((NULL, MOD_CTL, "==> _init")); 53643859Sml29623 mac_init_ops(&nxge_dev_ops, "nxge"); 53653859Sml29623 status = ddi_soft_state_init(&nxge_list, sizeof (nxge_t), 0); 53663859Sml29623 if (status != 0) { 53673859Sml29623 NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL, 53683859Sml29623 "failed to init device soft state")); 53693859Sml29623 goto _init_exit; 53703859Sml29623 } 53713859Sml29623 status = mod_install(&modlinkage); 53723859Sml29623 if (status != 0) { 53733859Sml29623 ddi_soft_state_fini(&nxge_list); 53743859Sml29623 NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL, "Mod install failed")); 53753859Sml29623 goto _init_exit; 53763859Sml29623 } 53773859Sml29623 53783859Sml29623 MUTEX_INIT(&nxge_common_lock, NULL, MUTEX_DRIVER, NULL); 53793859Sml29623 53803859Sml29623 _init_exit: 53813859Sml29623 NXGE_DEBUG_MSG((NULL, MOD_CTL, "_init status = 0x%X", status)); 53823859Sml29623 53833859Sml29623 return (status); 53843859Sml29623 } 53853859Sml29623 53863859Sml29623 int 53873859Sml29623 _fini(void) 53883859Sml29623 { 53893859Sml29623 int status; 53903859Sml29623 53913859Sml29623 NXGE_DEBUG_MSG((NULL, MOD_CTL, "==> _fini")); 53923859Sml29623 53933859Sml29623 NXGE_DEBUG_MSG((NULL, MOD_CTL, "==> _fini: mod_remove")); 53943859Sml29623 53953859Sml29623 if (nxge_mblks_pending) 53963859Sml29623 return (EBUSY); 53973859Sml29623 53983859Sml29623 status = mod_remove(&modlinkage); 53993859Sml29623 if (status != DDI_SUCCESS) { 54003859Sml29623 NXGE_DEBUG_MSG((NULL, MOD_CTL, 54013859Sml29623 "Module removal failed 0x%08x", 54023859Sml29623 status)); 54033859Sml29623 goto _fini_exit; 54043859Sml29623 } 54053859Sml29623 54063859Sml29623 mac_fini_ops(&nxge_dev_ops); 54073859Sml29623 54083859Sml29623 ddi_soft_state_fini(&nxge_list); 54093859Sml29623 54103859Sml29623 MUTEX_DESTROY(&nxge_common_lock); 54113859Sml29623 _fini_exit: 54123859Sml29623 NXGE_DEBUG_MSG((NULL, MOD_CTL, "_fini status = 0x%08x", status)); 54133859Sml29623 54143859Sml29623 return (status); 54153859Sml29623 } 54163859Sml29623 54173859Sml29623 int 54183859Sml29623 _info(struct modinfo *modinfop) 54193859Sml29623 { 54203859Sml29623 int status; 54213859Sml29623 54223859Sml29623 NXGE_DEBUG_MSG((NULL, MOD_CTL, "==> _info")); 54233859Sml29623 status = mod_info(&modlinkage, modinfop); 54243859Sml29623 NXGE_DEBUG_MSG((NULL, MOD_CTL, " _info status = 0x%X", status)); 54253859Sml29623 54263859Sml29623 return (status); 54273859Sml29623 } 54283859Sml29623 54293859Sml29623 /*ARGSUSED*/ 54303859Sml29623 static nxge_status_t 54313859Sml29623 nxge_add_intrs(p_nxge_t nxgep) 54323859Sml29623 { 54333859Sml29623 54343859Sml29623 int intr_types; 54353859Sml29623 int type = 0; 54363859Sml29623 int ddi_status = DDI_SUCCESS; 54373859Sml29623 nxge_status_t status = NXGE_OK; 54383859Sml29623 54393859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_add_intrs")); 54403859Sml29623 54413859Sml29623 nxgep->nxge_intr_type.intr_registered = B_FALSE; 54423859Sml29623 nxgep->nxge_intr_type.intr_enabled = B_FALSE; 54433859Sml29623 nxgep->nxge_intr_type.msi_intx_cnt = 0; 54443859Sml29623 nxgep->nxge_intr_type.intr_added = 0; 54453859Sml29623 nxgep->nxge_intr_type.niu_msi_enable = B_FALSE; 54463859Sml29623 nxgep->nxge_intr_type.intr_type = 0; 54473859Sml29623 54483859Sml29623 if (nxgep->niu_type == N2_NIU) { 54493859Sml29623 nxgep->nxge_intr_type.niu_msi_enable = B_TRUE; 54503859Sml29623 } else if (nxge_msi_enable) { 54513859Sml29623 nxgep->nxge_intr_type.niu_msi_enable = B_TRUE; 54523859Sml29623 } 54533859Sml29623 54543859Sml29623 /* Get the supported interrupt types */ 54553859Sml29623 if ((ddi_status = ddi_intr_get_supported_types(nxgep->dip, &intr_types)) 54563859Sml29623 != DDI_SUCCESS) { 54573859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "<== nxge_add_intrs: " 54583859Sml29623 "ddi_intr_get_supported_types failed: status 0x%08x", 54593859Sml29623 ddi_status)); 54603859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 54613859Sml29623 } 54623859Sml29623 nxgep->nxge_intr_type.intr_types = intr_types; 54633859Sml29623 54643859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_add_intrs: " 54653859Sml29623 "ddi_intr_get_supported_types: 0x%08x", intr_types)); 54663859Sml29623 54673859Sml29623 /* 54683859Sml29623 * Solaris MSIX is not supported yet. use MSI for now. 54693859Sml29623 * nxge_msi_enable (1): 54703859Sml29623 * 1 - MSI 2 - MSI-X others - FIXED 54713859Sml29623 */ 54723859Sml29623 switch (nxge_msi_enable) { 54733859Sml29623 default: 54743859Sml29623 type = DDI_INTR_TYPE_FIXED; 54753859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_add_intrs: " 54763859Sml29623 "use fixed (intx emulation) type %08x", 54773859Sml29623 type)); 54783859Sml29623 break; 54793859Sml29623 54803859Sml29623 case 2: 54813859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_add_intrs: " 54823859Sml29623 "ddi_intr_get_supported_types: 0x%08x", intr_types)); 54833859Sml29623 if (intr_types & DDI_INTR_TYPE_MSIX) { 54843859Sml29623 type = DDI_INTR_TYPE_MSIX; 54853859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_add_intrs: " 54863859Sml29623 "ddi_intr_get_supported_types: MSIX 0x%08x", 54873859Sml29623 type)); 54883859Sml29623 } else if (intr_types & DDI_INTR_TYPE_MSI) { 54893859Sml29623 type = DDI_INTR_TYPE_MSI; 54903859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_add_intrs: " 54913859Sml29623 "ddi_intr_get_supported_types: MSI 0x%08x", 54923859Sml29623 type)); 54933859Sml29623 } else if (intr_types & DDI_INTR_TYPE_FIXED) { 54943859Sml29623 type = DDI_INTR_TYPE_FIXED; 54953859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_add_intrs: " 54963859Sml29623 "ddi_intr_get_supported_types: MSXED0x%08x", 54973859Sml29623 type)); 54983859Sml29623 } 54993859Sml29623 break; 55003859Sml29623 55013859Sml29623 case 1: 55023859Sml29623 if (intr_types & DDI_INTR_TYPE_MSI) { 55033859Sml29623 type = DDI_INTR_TYPE_MSI; 55043859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_add_intrs: " 55053859Sml29623 "ddi_intr_get_supported_types: MSI 0x%08x", 55063859Sml29623 type)); 55073859Sml29623 } else if (intr_types & DDI_INTR_TYPE_MSIX) { 55083859Sml29623 type = DDI_INTR_TYPE_MSIX; 55093859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_add_intrs: " 55103859Sml29623 "ddi_intr_get_supported_types: MSIX 0x%08x", 55113859Sml29623 type)); 55123859Sml29623 } else if (intr_types & DDI_INTR_TYPE_FIXED) { 55133859Sml29623 type = DDI_INTR_TYPE_FIXED; 55143859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_add_intrs: " 55153859Sml29623 "ddi_intr_get_supported_types: MSXED0x%08x", 55163859Sml29623 type)); 55173859Sml29623 } 55183859Sml29623 } 55193859Sml29623 55203859Sml29623 nxgep->nxge_intr_type.intr_type = type; 55213859Sml29623 if ((type == DDI_INTR_TYPE_MSIX || type == DDI_INTR_TYPE_MSI || 55223859Sml29623 type == DDI_INTR_TYPE_FIXED) && 55233859Sml29623 nxgep->nxge_intr_type.niu_msi_enable) { 55243859Sml29623 if ((status = nxge_add_intrs_adv(nxgep)) != DDI_SUCCESS) { 55253859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 55263859Sml29623 " nxge_add_intrs: " 55273859Sml29623 " nxge_add_intrs_adv failed: status 0x%08x", 55283859Sml29623 status)); 55293859Sml29623 return (status); 55303859Sml29623 } else { 55313859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_add_intrs: " 55323859Sml29623 "interrupts registered : type %d", type)); 55333859Sml29623 nxgep->nxge_intr_type.intr_registered = B_TRUE; 55343859Sml29623 55353859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 55363859Sml29623 "\nAdded advanced nxge add_intr_adv " 55373859Sml29623 "intr type 0x%x\n", type)); 55383859Sml29623 55393859Sml29623 return (status); 55403859Sml29623 } 55413859Sml29623 } 55423859Sml29623 55433859Sml29623 if (!nxgep->nxge_intr_type.intr_registered) { 55443859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "==> nxge_add_intrs: " 55453859Sml29623 "failed to register interrupts")); 55463859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 55473859Sml29623 } 55483859Sml29623 55493859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_add_intrs")); 55503859Sml29623 return (status); 55513859Sml29623 } 55523859Sml29623 55533859Sml29623 /*ARGSUSED*/ 55543859Sml29623 static nxge_status_t 55553859Sml29623 nxge_add_soft_intrs(p_nxge_t nxgep) 55563859Sml29623 { 55573859Sml29623 55583859Sml29623 int ddi_status = DDI_SUCCESS; 55593859Sml29623 nxge_status_t status = NXGE_OK; 55603859Sml29623 55613859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_add_soft_intrs")); 55623859Sml29623 55633859Sml29623 nxgep->resched_id = NULL; 55643859Sml29623 nxgep->resched_running = B_FALSE; 55653859Sml29623 ddi_status = ddi_add_softintr(nxgep->dip, DDI_SOFTINT_LOW, 55663859Sml29623 &nxgep->resched_id, 55673859Sml29623 NULL, NULL, nxge_reschedule, (caddr_t)nxgep); 55683859Sml29623 if (ddi_status != DDI_SUCCESS) { 55693859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "<== nxge_add_soft_intrs: " 55703859Sml29623 "ddi_add_softintrs failed: status 0x%08x", 55713859Sml29623 ddi_status)); 55723859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 55733859Sml29623 } 55743859Sml29623 55753859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_ddi_add_soft_intrs")); 55763859Sml29623 55773859Sml29623 return (status); 55783859Sml29623 } 55793859Sml29623 55803859Sml29623 static nxge_status_t 55813859Sml29623 nxge_add_intrs_adv(p_nxge_t nxgep) 55823859Sml29623 { 55833859Sml29623 int intr_type; 55843859Sml29623 p_nxge_intr_t intrp; 55853859Sml29623 55863859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_add_intrs_adv")); 55873859Sml29623 55883859Sml29623 intrp = (p_nxge_intr_t)&nxgep->nxge_intr_type; 55893859Sml29623 intr_type = intrp->intr_type; 55903859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_add_intrs_adv: type 0x%x", 55913859Sml29623 intr_type)); 55923859Sml29623 55933859Sml29623 switch (intr_type) { 55943859Sml29623 case DDI_INTR_TYPE_MSI: /* 0x2 */ 55953859Sml29623 case DDI_INTR_TYPE_MSIX: /* 0x4 */ 55963859Sml29623 return (nxge_add_intrs_adv_type(nxgep, intr_type)); 55973859Sml29623 55983859Sml29623 case DDI_INTR_TYPE_FIXED: /* 0x1 */ 55993859Sml29623 return (nxge_add_intrs_adv_type_fix(nxgep, intr_type)); 56003859Sml29623 56013859Sml29623 default: 56023859Sml29623 return (NXGE_ERROR); 56033859Sml29623 } 56043859Sml29623 } 56053859Sml29623 56063859Sml29623 56073859Sml29623 /*ARGSUSED*/ 56083859Sml29623 static nxge_status_t 56093859Sml29623 nxge_add_intrs_adv_type(p_nxge_t nxgep, uint32_t int_type) 56103859Sml29623 { 56113859Sml29623 dev_info_t *dip = nxgep->dip; 56123859Sml29623 p_nxge_ldg_t ldgp; 56133859Sml29623 p_nxge_intr_t intrp; 56143859Sml29623 uint_t *inthandler; 56153859Sml29623 void *arg1, *arg2; 56163859Sml29623 int behavior; 56175013Sml29623 int nintrs, navail, nrequest; 56183859Sml29623 int nactual, nrequired; 56193859Sml29623 int inum = 0; 56203859Sml29623 int x, y; 56213859Sml29623 int ddi_status = DDI_SUCCESS; 56223859Sml29623 nxge_status_t status = NXGE_OK; 56233859Sml29623 56243859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_add_intrs_adv_type")); 56253859Sml29623 intrp = (p_nxge_intr_t)&nxgep->nxge_intr_type; 56263859Sml29623 intrp->start_inum = 0; 56273859Sml29623 56283859Sml29623 ddi_status = ddi_intr_get_nintrs(dip, int_type, &nintrs); 56293859Sml29623 if ((ddi_status != DDI_SUCCESS) || (nintrs == 0)) { 56303859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 56313859Sml29623 "ddi_intr_get_nintrs() failed, status: 0x%x%, " 56323859Sml29623 "nintrs: %d", ddi_status, nintrs)); 56333859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 56343859Sml29623 } 56353859Sml29623 56363859Sml29623 ddi_status = ddi_intr_get_navail(dip, int_type, &navail); 56373859Sml29623 if ((ddi_status != DDI_SUCCESS) || (navail == 0)) { 56383859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 56393859Sml29623 "ddi_intr_get_navail() failed, status: 0x%x%, " 56403859Sml29623 "nintrs: %d", ddi_status, navail)); 56413859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 56423859Sml29623 } 56433859Sml29623 56443859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, 56453859Sml29623 "ddi_intr_get_navail() returned: nintrs %d, navail %d", 56463859Sml29623 nintrs, navail)); 56473859Sml29623 56485013Sml29623 /* PSARC/2007/453 MSI-X interrupt limit override */ 56495013Sml29623 if (int_type == DDI_INTR_TYPE_MSIX) { 56505013Sml29623 nrequest = nxge_create_msi_property(nxgep); 56515013Sml29623 if (nrequest < navail) { 56525013Sml29623 navail = nrequest; 56535013Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, 56545013Sml29623 "nxge_add_intrs_adv_type: nintrs %d " 56555013Sml29623 "navail %d (nrequest %d)", 56565013Sml29623 nintrs, navail, nrequest)); 56575013Sml29623 } 56585013Sml29623 } 56595013Sml29623 56603859Sml29623 if (int_type == DDI_INTR_TYPE_MSI && !ISP2(navail)) { 56613859Sml29623 /* MSI must be power of 2 */ 56623859Sml29623 if ((navail & 16) == 16) { 56633859Sml29623 navail = 16; 56643859Sml29623 } else if ((navail & 8) == 8) { 56653859Sml29623 navail = 8; 56663859Sml29623 } else if ((navail & 4) == 4) { 56673859Sml29623 navail = 4; 56683859Sml29623 } else if ((navail & 2) == 2) { 56693859Sml29623 navail = 2; 56703859Sml29623 } else { 56713859Sml29623 navail = 1; 56723859Sml29623 } 56733859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, 56743859Sml29623 "ddi_intr_get_navail(): (msi power of 2) nintrs %d, " 56753859Sml29623 "navail %d", nintrs, navail)); 56763859Sml29623 } 56773859Sml29623 56783859Sml29623 behavior = ((int_type == DDI_INTR_TYPE_FIXED) ? DDI_INTR_ALLOC_STRICT : 56793859Sml29623 DDI_INTR_ALLOC_NORMAL); 56803859Sml29623 intrp->intr_size = navail * sizeof (ddi_intr_handle_t); 56813859Sml29623 intrp->htable = kmem_alloc(intrp->intr_size, KM_SLEEP); 56823859Sml29623 ddi_status = ddi_intr_alloc(dip, intrp->htable, int_type, inum, 56833859Sml29623 navail, &nactual, behavior); 56843859Sml29623 if (ddi_status != DDI_SUCCESS || nactual == 0) { 56853859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 56863859Sml29623 " ddi_intr_alloc() failed: %d", 56873859Sml29623 ddi_status)); 56883859Sml29623 kmem_free(intrp->htable, intrp->intr_size); 56893859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 56903859Sml29623 } 56913859Sml29623 56923859Sml29623 if ((ddi_status = ddi_intr_get_pri(intrp->htable[0], 56933859Sml29623 (uint_t *)&intrp->pri)) != DDI_SUCCESS) { 56943859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 56953859Sml29623 " ddi_intr_get_pri() failed: %d", 56963859Sml29623 ddi_status)); 56973859Sml29623 /* Free already allocated interrupts */ 56983859Sml29623 for (y = 0; y < nactual; y++) { 56993859Sml29623 (void) ddi_intr_free(intrp->htable[y]); 57003859Sml29623 } 57013859Sml29623 57023859Sml29623 kmem_free(intrp->htable, intrp->intr_size); 57033859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 57043859Sml29623 } 57053859Sml29623 57063859Sml29623 nrequired = 0; 57073859Sml29623 switch (nxgep->niu_type) { 57083859Sml29623 default: 57093859Sml29623 status = nxge_ldgv_init(nxgep, &nactual, &nrequired); 57103859Sml29623 break; 57113859Sml29623 57123859Sml29623 case N2_NIU: 57133859Sml29623 status = nxge_ldgv_init_n2(nxgep, &nactual, &nrequired); 57143859Sml29623 break; 57153859Sml29623 } 57163859Sml29623 57173859Sml29623 if (status != NXGE_OK) { 57183859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 57193859Sml29623 "nxge_add_intrs_adv_typ:nxge_ldgv_init " 57203859Sml29623 "failed: 0x%x", status)); 57213859Sml29623 /* Free already allocated interrupts */ 57223859Sml29623 for (y = 0; y < nactual; y++) { 57233859Sml29623 (void) ddi_intr_free(intrp->htable[y]); 57243859Sml29623 } 57253859Sml29623 57263859Sml29623 kmem_free(intrp->htable, intrp->intr_size); 57273859Sml29623 return (status); 57283859Sml29623 } 57293859Sml29623 57303859Sml29623 ldgp = nxgep->ldgvp->ldgp; 57313859Sml29623 for (x = 0; x < nrequired; x++, ldgp++) { 57323859Sml29623 ldgp->vector = (uint8_t)x; 57333859Sml29623 ldgp->intdata = SID_DATA(ldgp->func, x); 57343859Sml29623 arg1 = ldgp->ldvp; 57353859Sml29623 arg2 = nxgep; 57363859Sml29623 if (ldgp->nldvs == 1) { 57373859Sml29623 inthandler = (uint_t *)ldgp->ldvp->ldv_intr_handler; 57383859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, 57393859Sml29623 "nxge_add_intrs_adv_type: " 57403859Sml29623 "arg1 0x%x arg2 0x%x: " 57413859Sml29623 "1-1 int handler (entry %d intdata 0x%x)\n", 57423859Sml29623 arg1, arg2, 57433859Sml29623 x, ldgp->intdata)); 57443859Sml29623 } else if (ldgp->nldvs > 1) { 57453859Sml29623 inthandler = (uint_t *)ldgp->sys_intr_handler; 57463859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, 57473859Sml29623 "nxge_add_intrs_adv_type: " 57483859Sml29623 "arg1 0x%x arg2 0x%x: " 57493859Sml29623 "nldevs %d int handler " 57503859Sml29623 "(entry %d intdata 0x%x)\n", 57513859Sml29623 arg1, arg2, 57523859Sml29623 ldgp->nldvs, x, ldgp->intdata)); 57533859Sml29623 } 57543859Sml29623 57553859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, 57563859Sml29623 "==> nxge_add_intrs_adv_type: ddi_add_intr(inum) #%d " 57573859Sml29623 "htable 0x%llx", x, intrp->htable[x])); 57583859Sml29623 57593859Sml29623 if ((ddi_status = ddi_intr_add_handler(intrp->htable[x], 57603859Sml29623 (ddi_intr_handler_t *)inthandler, arg1, arg2)) 57613859Sml29623 != DDI_SUCCESS) { 57623859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 57633859Sml29623 "==> nxge_add_intrs_adv_type: failed #%d " 57643859Sml29623 "status 0x%x", x, ddi_status)); 57653859Sml29623 for (y = 0; y < intrp->intr_added; y++) { 57663859Sml29623 (void) ddi_intr_remove_handler( 57673859Sml29623 intrp->htable[y]); 57683859Sml29623 } 57693859Sml29623 /* Free already allocated intr */ 57703859Sml29623 for (y = 0; y < nactual; y++) { 57713859Sml29623 (void) ddi_intr_free(intrp->htable[y]); 57723859Sml29623 } 57733859Sml29623 kmem_free(intrp->htable, intrp->intr_size); 57743859Sml29623 57753859Sml29623 (void) nxge_ldgv_uninit(nxgep); 57763859Sml29623 57773859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 57783859Sml29623 } 57793859Sml29623 intrp->intr_added++; 57803859Sml29623 } 57813859Sml29623 57823859Sml29623 intrp->msi_intx_cnt = nactual; 57833859Sml29623 57843859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 57853859Sml29623 "Requested: %d, Allowed: %d msi_intx_cnt %d intr_added %d", 57863859Sml29623 navail, nactual, 57873859Sml29623 intrp->msi_intx_cnt, 57883859Sml29623 intrp->intr_added)); 57893859Sml29623 57903859Sml29623 (void) ddi_intr_get_cap(intrp->htable[0], &intrp->intr_cap); 57913859Sml29623 57923859Sml29623 (void) nxge_intr_ldgv_init(nxgep); 57933859Sml29623 57943859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_add_intrs_adv_type")); 57953859Sml29623 57963859Sml29623 return (status); 57973859Sml29623 } 57983859Sml29623 57993859Sml29623 /*ARGSUSED*/ 58003859Sml29623 static nxge_status_t 58013859Sml29623 nxge_add_intrs_adv_type_fix(p_nxge_t nxgep, uint32_t int_type) 58023859Sml29623 { 58033859Sml29623 dev_info_t *dip = nxgep->dip; 58043859Sml29623 p_nxge_ldg_t ldgp; 58053859Sml29623 p_nxge_intr_t intrp; 58063859Sml29623 uint_t *inthandler; 58073859Sml29623 void *arg1, *arg2; 58083859Sml29623 int behavior; 58093859Sml29623 int nintrs, navail; 58103859Sml29623 int nactual, nrequired; 58113859Sml29623 int inum = 0; 58123859Sml29623 int x, y; 58133859Sml29623 int ddi_status = DDI_SUCCESS; 58143859Sml29623 nxge_status_t status = NXGE_OK; 58153859Sml29623 58163859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_add_intrs_adv_type_fix")); 58173859Sml29623 intrp = (p_nxge_intr_t)&nxgep->nxge_intr_type; 58183859Sml29623 intrp->start_inum = 0; 58193859Sml29623 58203859Sml29623 ddi_status = ddi_intr_get_nintrs(dip, int_type, &nintrs); 58213859Sml29623 if ((ddi_status != DDI_SUCCESS) || (nintrs == 0)) { 58223859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, 58233859Sml29623 "ddi_intr_get_nintrs() failed, status: 0x%x%, " 58243859Sml29623 "nintrs: %d", status, nintrs)); 58253859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 58263859Sml29623 } 58273859Sml29623 58283859Sml29623 ddi_status = ddi_intr_get_navail(dip, int_type, &navail); 58293859Sml29623 if ((ddi_status != DDI_SUCCESS) || (navail == 0)) { 58303859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 58313859Sml29623 "ddi_intr_get_navail() failed, status: 0x%x%, " 58323859Sml29623 "nintrs: %d", ddi_status, navail)); 58333859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 58343859Sml29623 } 58353859Sml29623 58363859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, 58373859Sml29623 "ddi_intr_get_navail() returned: nintrs %d, naavail %d", 58383859Sml29623 nintrs, navail)); 58393859Sml29623 58403859Sml29623 behavior = ((int_type == DDI_INTR_TYPE_FIXED) ? DDI_INTR_ALLOC_STRICT : 58413859Sml29623 DDI_INTR_ALLOC_NORMAL); 58423859Sml29623 intrp->intr_size = navail * sizeof (ddi_intr_handle_t); 58433859Sml29623 intrp->htable = kmem_alloc(intrp->intr_size, KM_SLEEP); 58443859Sml29623 ddi_status = ddi_intr_alloc(dip, intrp->htable, int_type, inum, 58453859Sml29623 navail, &nactual, behavior); 58463859Sml29623 if (ddi_status != DDI_SUCCESS || nactual == 0) { 58473859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 58483859Sml29623 " ddi_intr_alloc() failed: %d", 58493859Sml29623 ddi_status)); 58503859Sml29623 kmem_free(intrp->htable, intrp->intr_size); 58513859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 58523859Sml29623 } 58533859Sml29623 58543859Sml29623 if ((ddi_status = ddi_intr_get_pri(intrp->htable[0], 58553859Sml29623 (uint_t *)&intrp->pri)) != DDI_SUCCESS) { 58563859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 58573859Sml29623 " ddi_intr_get_pri() failed: %d", 58583859Sml29623 ddi_status)); 58593859Sml29623 /* Free already allocated interrupts */ 58603859Sml29623 for (y = 0; y < nactual; y++) { 58613859Sml29623 (void) ddi_intr_free(intrp->htable[y]); 58623859Sml29623 } 58633859Sml29623 58643859Sml29623 kmem_free(intrp->htable, intrp->intr_size); 58653859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 58663859Sml29623 } 58673859Sml29623 58683859Sml29623 nrequired = 0; 58693859Sml29623 switch (nxgep->niu_type) { 58703859Sml29623 default: 58713859Sml29623 status = nxge_ldgv_init(nxgep, &nactual, &nrequired); 58723859Sml29623 break; 58733859Sml29623 58743859Sml29623 case N2_NIU: 58753859Sml29623 status = nxge_ldgv_init_n2(nxgep, &nactual, &nrequired); 58763859Sml29623 break; 58773859Sml29623 } 58783859Sml29623 58793859Sml29623 if (status != NXGE_OK) { 58803859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 58813859Sml29623 "nxge_add_intrs_adv_type_fix:nxge_ldgv_init " 58823859Sml29623 "failed: 0x%x", status)); 58833859Sml29623 /* Free already allocated interrupts */ 58843859Sml29623 for (y = 0; y < nactual; y++) { 58853859Sml29623 (void) ddi_intr_free(intrp->htable[y]); 58863859Sml29623 } 58873859Sml29623 58883859Sml29623 kmem_free(intrp->htable, intrp->intr_size); 58893859Sml29623 return (status); 58903859Sml29623 } 58913859Sml29623 58923859Sml29623 ldgp = nxgep->ldgvp->ldgp; 58933859Sml29623 for (x = 0; x < nrequired; x++, ldgp++) { 58943859Sml29623 ldgp->vector = (uint8_t)x; 58953859Sml29623 if (nxgep->niu_type != N2_NIU) { 58963859Sml29623 ldgp->intdata = SID_DATA(ldgp->func, x); 58973859Sml29623 } 58983859Sml29623 58993859Sml29623 arg1 = ldgp->ldvp; 59003859Sml29623 arg2 = nxgep; 59013859Sml29623 if (ldgp->nldvs == 1) { 59023859Sml29623 inthandler = (uint_t *)ldgp->ldvp->ldv_intr_handler; 59033859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, 59043859Sml29623 "nxge_add_intrs_adv_type_fix: " 59053859Sml29623 "1-1 int handler(%d) ldg %d ldv %d " 59063859Sml29623 "arg1 $%p arg2 $%p\n", 59073859Sml29623 x, ldgp->ldg, ldgp->ldvp->ldv, 59083859Sml29623 arg1, arg2)); 59093859Sml29623 } else if (ldgp->nldvs > 1) { 59103859Sml29623 inthandler = (uint_t *)ldgp->sys_intr_handler; 59113859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, 59123859Sml29623 "nxge_add_intrs_adv_type_fix: " 59133859Sml29623 "shared ldv %d int handler(%d) ldv %d ldg %d" 59143859Sml29623 "arg1 0x%016llx arg2 0x%016llx\n", 59153859Sml29623 x, ldgp->nldvs, ldgp->ldg, ldgp->ldvp->ldv, 59163859Sml29623 arg1, arg2)); 59173859Sml29623 } 59183859Sml29623 59193859Sml29623 if ((ddi_status = ddi_intr_add_handler(intrp->htable[x], 59203859Sml29623 (ddi_intr_handler_t *)inthandler, arg1, arg2)) 59213859Sml29623 != DDI_SUCCESS) { 59223859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 59233859Sml29623 "==> nxge_add_intrs_adv_type_fix: failed #%d " 59243859Sml29623 "status 0x%x", x, ddi_status)); 59253859Sml29623 for (y = 0; y < intrp->intr_added; y++) { 59263859Sml29623 (void) ddi_intr_remove_handler( 59273859Sml29623 intrp->htable[y]); 59283859Sml29623 } 59293859Sml29623 for (y = 0; y < nactual; y++) { 59303859Sml29623 (void) ddi_intr_free(intrp->htable[y]); 59313859Sml29623 } 59323859Sml29623 /* Free already allocated intr */ 59333859Sml29623 kmem_free(intrp->htable, intrp->intr_size); 59343859Sml29623 59353859Sml29623 (void) nxge_ldgv_uninit(nxgep); 59363859Sml29623 59373859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 59383859Sml29623 } 59393859Sml29623 intrp->intr_added++; 59403859Sml29623 } 59413859Sml29623 59423859Sml29623 intrp->msi_intx_cnt = nactual; 59433859Sml29623 59443859Sml29623 (void) ddi_intr_get_cap(intrp->htable[0], &intrp->intr_cap); 59453859Sml29623 59463859Sml29623 status = nxge_intr_ldgv_init(nxgep); 59473859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_add_intrs_adv_type_fix")); 59483859Sml29623 59493859Sml29623 return (status); 59503859Sml29623 } 59513859Sml29623 59523859Sml29623 static void 59533859Sml29623 nxge_remove_intrs(p_nxge_t nxgep) 59543859Sml29623 { 59553859Sml29623 int i, inum; 59563859Sml29623 p_nxge_intr_t intrp; 59573859Sml29623 59583859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_remove_intrs")); 59593859Sml29623 intrp = (p_nxge_intr_t)&nxgep->nxge_intr_type; 59603859Sml29623 if (!intrp->intr_registered) { 59613859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, 59623859Sml29623 "<== nxge_remove_intrs: interrupts not registered")); 59633859Sml29623 return; 59643859Sml29623 } 59653859Sml29623 59663859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_remove_intrs:advanced")); 59673859Sml29623 59683859Sml29623 if (intrp->intr_cap & DDI_INTR_FLAG_BLOCK) { 59693859Sml29623 (void) ddi_intr_block_disable(intrp->htable, 59703859Sml29623 intrp->intr_added); 59713859Sml29623 } else { 59723859Sml29623 for (i = 0; i < intrp->intr_added; i++) { 59733859Sml29623 (void) ddi_intr_disable(intrp->htable[i]); 59743859Sml29623 } 59753859Sml29623 } 59763859Sml29623 59773859Sml29623 for (inum = 0; inum < intrp->intr_added; inum++) { 59783859Sml29623 if (intrp->htable[inum]) { 59793859Sml29623 (void) ddi_intr_remove_handler(intrp->htable[inum]); 59803859Sml29623 } 59813859Sml29623 } 59823859Sml29623 59833859Sml29623 for (inum = 0; inum < intrp->msi_intx_cnt; inum++) { 59843859Sml29623 if (intrp->htable[inum]) { 59853859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 59863859Sml29623 "nxge_remove_intrs: ddi_intr_free inum %d " 59873859Sml29623 "msi_intx_cnt %d intr_added %d", 59883859Sml29623 inum, 59893859Sml29623 intrp->msi_intx_cnt, 59903859Sml29623 intrp->intr_added)); 59913859Sml29623 59923859Sml29623 (void) ddi_intr_free(intrp->htable[inum]); 59933859Sml29623 } 59943859Sml29623 } 59953859Sml29623 59963859Sml29623 kmem_free(intrp->htable, intrp->intr_size); 59973859Sml29623 intrp->intr_registered = B_FALSE; 59983859Sml29623 intrp->intr_enabled = B_FALSE; 59993859Sml29623 intrp->msi_intx_cnt = 0; 60003859Sml29623 intrp->intr_added = 0; 60013859Sml29623 60023859Sml29623 (void) nxge_ldgv_uninit(nxgep); 60033859Sml29623 60045013Sml29623 (void) ddi_prop_remove(DDI_DEV_T_NONE, nxgep->dip, 60055013Sml29623 "#msix-request"); 60065013Sml29623 60073859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_remove_intrs")); 60083859Sml29623 } 60093859Sml29623 60103859Sml29623 /*ARGSUSED*/ 60113859Sml29623 static void 60123859Sml29623 nxge_remove_soft_intrs(p_nxge_t nxgep) 60133859Sml29623 { 60143859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_remove_soft_intrs")); 60153859Sml29623 if (nxgep->resched_id) { 60163859Sml29623 ddi_remove_softintr(nxgep->resched_id); 60173859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, 60183859Sml29623 "==> nxge_remove_soft_intrs: removed")); 60193859Sml29623 nxgep->resched_id = NULL; 60203859Sml29623 } 60213859Sml29623 60223859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_remove_soft_intrs")); 60233859Sml29623 } 60243859Sml29623 60253859Sml29623 /*ARGSUSED*/ 60263859Sml29623 static void 60273859Sml29623 nxge_intrs_enable(p_nxge_t nxgep) 60283859Sml29623 { 60293859Sml29623 p_nxge_intr_t intrp; 60303859Sml29623 int i; 60313859Sml29623 int status; 60323859Sml29623 60333859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_intrs_enable")); 60343859Sml29623 60353859Sml29623 intrp = (p_nxge_intr_t)&nxgep->nxge_intr_type; 60363859Sml29623 60373859Sml29623 if (!intrp->intr_registered) { 60383859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "<== nxge_intrs_enable: " 60393859Sml29623 "interrupts are not registered")); 60403859Sml29623 return; 60413859Sml29623 } 60423859Sml29623 60433859Sml29623 if (intrp->intr_enabled) { 60443859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, 60453859Sml29623 "<== nxge_intrs_enable: already enabled")); 60463859Sml29623 return; 60473859Sml29623 } 60483859Sml29623 60493859Sml29623 if (intrp->intr_cap & DDI_INTR_FLAG_BLOCK) { 60503859Sml29623 status = ddi_intr_block_enable(intrp->htable, 60513859Sml29623 intrp->intr_added); 60523859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_intrs_enable " 60533859Sml29623 "block enable - status 0x%x total inums #%d\n", 60543859Sml29623 status, intrp->intr_added)); 60553859Sml29623 } else { 60563859Sml29623 for (i = 0; i < intrp->intr_added; i++) { 60573859Sml29623 status = ddi_intr_enable(intrp->htable[i]); 60583859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_intrs_enable " 60593859Sml29623 "ddi_intr_enable:enable - status 0x%x " 60603859Sml29623 "total inums %d enable inum #%d\n", 60613859Sml29623 status, intrp->intr_added, i)); 60623859Sml29623 if (status == DDI_SUCCESS) { 60633859Sml29623 intrp->intr_enabled = B_TRUE; 60643859Sml29623 } 60653859Sml29623 } 60663859Sml29623 } 60673859Sml29623 60683859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_intrs_enable")); 60693859Sml29623 } 60703859Sml29623 60713859Sml29623 /*ARGSUSED*/ 60723859Sml29623 static void 60733859Sml29623 nxge_intrs_disable(p_nxge_t nxgep) 60743859Sml29623 { 60753859Sml29623 p_nxge_intr_t intrp; 60763859Sml29623 int i; 60773859Sml29623 60783859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_intrs_disable")); 60793859Sml29623 60803859Sml29623 intrp = (p_nxge_intr_t)&nxgep->nxge_intr_type; 60813859Sml29623 60823859Sml29623 if (!intrp->intr_registered) { 60833859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_intrs_disable: " 60843859Sml29623 "interrupts are not registered")); 60853859Sml29623 return; 60863859Sml29623 } 60873859Sml29623 60883859Sml29623 if (intrp->intr_cap & DDI_INTR_FLAG_BLOCK) { 60893859Sml29623 (void) ddi_intr_block_disable(intrp->htable, 60903859Sml29623 intrp->intr_added); 60913859Sml29623 } else { 60923859Sml29623 for (i = 0; i < intrp->intr_added; i++) { 60933859Sml29623 (void) ddi_intr_disable(intrp->htable[i]); 60943859Sml29623 } 60953859Sml29623 } 60963859Sml29623 60973859Sml29623 intrp->intr_enabled = B_FALSE; 60983859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_intrs_disable")); 60993859Sml29623 } 61003859Sml29623 61013859Sml29623 static nxge_status_t 61023859Sml29623 nxge_mac_register(p_nxge_t nxgep) 61033859Sml29623 { 61043859Sml29623 mac_register_t *macp; 61053859Sml29623 int status; 61063859Sml29623 61073859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_mac_register")); 61083859Sml29623 61093859Sml29623 if ((macp = mac_alloc(MAC_VERSION)) == NULL) 61103859Sml29623 return (NXGE_ERROR); 61113859Sml29623 61123859Sml29623 macp->m_type_ident = MAC_PLUGIN_IDENT_ETHER; 61133859Sml29623 macp->m_driver = nxgep; 61143859Sml29623 macp->m_dip = nxgep->dip; 61153859Sml29623 macp->m_src_addr = nxgep->ouraddr.ether_addr_octet; 61163859Sml29623 macp->m_callbacks = &nxge_m_callbacks; 61173859Sml29623 macp->m_min_sdu = 0; 61186439Sml29623 nxgep->mac.default_mtu = nxgep->mac.maxframesize - 61196439Sml29623 NXGE_EHEADER_VLAN_CRC; 61206439Sml29623 macp->m_max_sdu = nxgep->mac.default_mtu; 61215895Syz147064 macp->m_margin = VLAN_TAGSZ; 61223859Sml29623 61236439Sml29623 NXGE_DEBUG_MSG((nxgep, MAC_CTL, 61246439Sml29623 "==> nxge_mac_register: instance %d " 61256439Sml29623 "max_sdu %d margin %d maxframe %d (header %d)", 61266439Sml29623 nxgep->instance, 61276439Sml29623 macp->m_max_sdu, macp->m_margin, 61286439Sml29623 nxgep->mac.maxframesize, 61296439Sml29623 NXGE_EHEADER_VLAN_CRC)); 61306439Sml29623 61313859Sml29623 status = mac_register(macp, &nxgep->mach); 61323859Sml29623 mac_free(macp); 61333859Sml29623 61343859Sml29623 if (status != 0) { 61353859Sml29623 cmn_err(CE_WARN, 61363859Sml29623 "!nxge_mac_register failed (status %d instance %d)", 61373859Sml29623 status, nxgep->instance); 61383859Sml29623 return (NXGE_ERROR); 61393859Sml29623 } 61403859Sml29623 61413859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_mac_register success " 61423859Sml29623 "(instance %d)", nxgep->instance)); 61433859Sml29623 61443859Sml29623 return (NXGE_OK); 61453859Sml29623 } 61463859Sml29623 61473859Sml29623 void 61483859Sml29623 nxge_err_inject(p_nxge_t nxgep, queue_t *wq, mblk_t *mp) 61493859Sml29623 { 61503859Sml29623 ssize_t size; 61513859Sml29623 mblk_t *nmp; 61523859Sml29623 uint8_t blk_id; 61533859Sml29623 uint8_t chan; 61543859Sml29623 uint32_t err_id; 61553859Sml29623 err_inject_t *eip; 61563859Sml29623 61573859Sml29623 NXGE_DEBUG_MSG((nxgep, STR_CTL, "==> nxge_err_inject")); 61583859Sml29623 61593859Sml29623 size = 1024; 61603859Sml29623 nmp = mp->b_cont; 61613859Sml29623 eip = (err_inject_t *)nmp->b_rptr; 61623859Sml29623 blk_id = eip->blk_id; 61633859Sml29623 err_id = eip->err_id; 61643859Sml29623 chan = eip->chan; 61653859Sml29623 cmn_err(CE_NOTE, "!blk_id = 0x%x\n", blk_id); 61663859Sml29623 cmn_err(CE_NOTE, "!err_id = 0x%x\n", err_id); 61673859Sml29623 cmn_err(CE_NOTE, "!chan = 0x%x\n", chan); 61683859Sml29623 switch (blk_id) { 61693859Sml29623 case MAC_BLK_ID: 61703859Sml29623 break; 61713859Sml29623 case TXMAC_BLK_ID: 61723859Sml29623 break; 61733859Sml29623 case RXMAC_BLK_ID: 61743859Sml29623 break; 61753859Sml29623 case MIF_BLK_ID: 61763859Sml29623 break; 61773859Sml29623 case IPP_BLK_ID: 61783859Sml29623 nxge_ipp_inject_err(nxgep, err_id); 61793859Sml29623 break; 61803859Sml29623 case TXC_BLK_ID: 61813859Sml29623 nxge_txc_inject_err(nxgep, err_id); 61823859Sml29623 break; 61833859Sml29623 case TXDMA_BLK_ID: 61843859Sml29623 nxge_txdma_inject_err(nxgep, err_id, chan); 61853859Sml29623 break; 61863859Sml29623 case RXDMA_BLK_ID: 61873859Sml29623 nxge_rxdma_inject_err(nxgep, err_id, chan); 61883859Sml29623 break; 61893859Sml29623 case ZCP_BLK_ID: 61903859Sml29623 nxge_zcp_inject_err(nxgep, err_id); 61913859Sml29623 break; 61923859Sml29623 case ESPC_BLK_ID: 61933859Sml29623 break; 61943859Sml29623 case FFLP_BLK_ID: 61953859Sml29623 break; 61963859Sml29623 case PHY_BLK_ID: 61973859Sml29623 break; 61983859Sml29623 case ETHER_SERDES_BLK_ID: 61993859Sml29623 break; 62003859Sml29623 case PCIE_SERDES_BLK_ID: 62013859Sml29623 break; 62023859Sml29623 case VIR_BLK_ID: 62033859Sml29623 break; 62043859Sml29623 } 62053859Sml29623 62063859Sml29623 nmp->b_wptr = nmp->b_rptr + size; 62073859Sml29623 NXGE_DEBUG_MSG((nxgep, STR_CTL, "<== nxge_err_inject")); 62083859Sml29623 62093859Sml29623 miocack(wq, mp, (int)size, 0); 62103859Sml29623 } 62113859Sml29623 62123859Sml29623 static int 62133859Sml29623 nxge_init_common_dev(p_nxge_t nxgep) 62143859Sml29623 { 62153859Sml29623 p_nxge_hw_list_t hw_p; 62163859Sml29623 dev_info_t *p_dip; 62173859Sml29623 62183859Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, "==> nxge_init_common_device")); 62193859Sml29623 62203859Sml29623 p_dip = nxgep->p_dip; 62213859Sml29623 MUTEX_ENTER(&nxge_common_lock); 62223859Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, 62233859Sml29623 "==> nxge_init_common_dev:func # %d", 62243859Sml29623 nxgep->function_num)); 62253859Sml29623 /* 62263859Sml29623 * Loop through existing per neptune hardware list. 62273859Sml29623 */ 62283859Sml29623 for (hw_p = nxge_hw_list; hw_p; hw_p = hw_p->next) { 62293859Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, 62303859Sml29623 "==> nxge_init_common_device:func # %d " 62313859Sml29623 "hw_p $%p parent dip $%p", 62323859Sml29623 nxgep->function_num, 62333859Sml29623 hw_p, 62343859Sml29623 p_dip)); 62353859Sml29623 if (hw_p->parent_devp == p_dip) { 62363859Sml29623 nxgep->nxge_hw_p = hw_p; 62373859Sml29623 hw_p->ndevs++; 62383859Sml29623 hw_p->nxge_p[nxgep->function_num] = nxgep; 62393859Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, 62403859Sml29623 "==> nxge_init_common_device:func # %d " 62413859Sml29623 "hw_p $%p parent dip $%p " 62423859Sml29623 "ndevs %d (found)", 62433859Sml29623 nxgep->function_num, 62443859Sml29623 hw_p, 62453859Sml29623 p_dip, 62463859Sml29623 hw_p->ndevs)); 62473859Sml29623 break; 62483859Sml29623 } 62493859Sml29623 } 62503859Sml29623 62513859Sml29623 if (hw_p == NULL) { 62523859Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, 62533859Sml29623 "==> nxge_init_common_device:func # %d " 62543859Sml29623 "parent dip $%p (new)", 62553859Sml29623 nxgep->function_num, 62563859Sml29623 p_dip)); 62573859Sml29623 hw_p = kmem_zalloc(sizeof (nxge_hw_list_t), KM_SLEEP); 62583859Sml29623 hw_p->parent_devp = p_dip; 62593859Sml29623 hw_p->magic = NXGE_NEPTUNE_MAGIC; 62603859Sml29623 nxgep->nxge_hw_p = hw_p; 62613859Sml29623 hw_p->ndevs++; 62623859Sml29623 hw_p->nxge_p[nxgep->function_num] = nxgep; 62633859Sml29623 hw_p->next = nxge_hw_list; 62644732Sdavemq if (nxgep->niu_type == N2_NIU) { 62654732Sdavemq hw_p->niu_type = N2_NIU; 62664732Sdavemq hw_p->platform_type = P_NEPTUNE_NIU; 62674732Sdavemq } else { 62684732Sdavemq hw_p->niu_type = NIU_TYPE_NONE; 62694977Sraghus hw_p->platform_type = P_NEPTUNE_NONE; 62704732Sdavemq } 62713859Sml29623 62723859Sml29623 MUTEX_INIT(&hw_p->nxge_cfg_lock, NULL, MUTEX_DRIVER, NULL); 62733859Sml29623 MUTEX_INIT(&hw_p->nxge_tcam_lock, NULL, MUTEX_DRIVER, NULL); 62743859Sml29623 MUTEX_INIT(&hw_p->nxge_vlan_lock, NULL, MUTEX_DRIVER, NULL); 62753859Sml29623 MUTEX_INIT(&hw_p->nxge_mdio_lock, NULL, MUTEX_DRIVER, NULL); 62763859Sml29623 62773859Sml29623 nxge_hw_list = hw_p; 62784732Sdavemq 62794732Sdavemq (void) nxge_scan_ports_phy(nxgep, nxge_hw_list); 62803859Sml29623 } 62813859Sml29623 62823859Sml29623 MUTEX_EXIT(&nxge_common_lock); 62834732Sdavemq 62844977Sraghus nxgep->platform_type = hw_p->platform_type; 62854732Sdavemq if (nxgep->niu_type != N2_NIU) { 62864732Sdavemq nxgep->niu_type = hw_p->niu_type; 62874732Sdavemq } 62884732Sdavemq 62893859Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, 62903859Sml29623 "==> nxge_init_common_device (nxge_hw_list) $%p", 62913859Sml29623 nxge_hw_list)); 62923859Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, "<== nxge_init_common_device")); 62933859Sml29623 62943859Sml29623 return (NXGE_OK); 62953859Sml29623 } 62963859Sml29623 62973859Sml29623 static void 62983859Sml29623 nxge_uninit_common_dev(p_nxge_t nxgep) 62993859Sml29623 { 63003859Sml29623 p_nxge_hw_list_t hw_p, h_hw_p; 63013859Sml29623 dev_info_t *p_dip; 63023859Sml29623 63033859Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, "==> nxge_uninit_common_device")); 63043859Sml29623 if (nxgep->nxge_hw_p == NULL) { 63053859Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, 63063859Sml29623 "<== nxge_uninit_common_device (no common)")); 63073859Sml29623 return; 63083859Sml29623 } 63093859Sml29623 63103859Sml29623 MUTEX_ENTER(&nxge_common_lock); 63113859Sml29623 h_hw_p = nxge_hw_list; 63123859Sml29623 for (hw_p = nxge_hw_list; hw_p; hw_p = hw_p->next) { 63133859Sml29623 p_dip = hw_p->parent_devp; 63143859Sml29623 if (nxgep->nxge_hw_p == hw_p && 63153859Sml29623 p_dip == nxgep->p_dip && 63163859Sml29623 nxgep->nxge_hw_p->magic == NXGE_NEPTUNE_MAGIC && 63173859Sml29623 hw_p->magic == NXGE_NEPTUNE_MAGIC) { 63183859Sml29623 63193859Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, 63203859Sml29623 "==> nxge_uninit_common_device:func # %d " 63213859Sml29623 "hw_p $%p parent dip $%p " 63223859Sml29623 "ndevs %d (found)", 63233859Sml29623 nxgep->function_num, 63243859Sml29623 hw_p, 63253859Sml29623 p_dip, 63263859Sml29623 hw_p->ndevs)); 63273859Sml29623 63283859Sml29623 if (hw_p->ndevs) { 63293859Sml29623 hw_p->ndevs--; 63303859Sml29623 } 63313859Sml29623 hw_p->nxge_p[nxgep->function_num] = NULL; 63323859Sml29623 if (!hw_p->ndevs) { 63333859Sml29623 MUTEX_DESTROY(&hw_p->nxge_vlan_lock); 63343859Sml29623 MUTEX_DESTROY(&hw_p->nxge_tcam_lock); 63353859Sml29623 MUTEX_DESTROY(&hw_p->nxge_cfg_lock); 63363859Sml29623 MUTEX_DESTROY(&hw_p->nxge_mdio_lock); 63373859Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, 63383859Sml29623 "==> nxge_uninit_common_device: " 63393859Sml29623 "func # %d " 63403859Sml29623 "hw_p $%p parent dip $%p " 63413859Sml29623 "ndevs %d (last)", 63423859Sml29623 nxgep->function_num, 63433859Sml29623 hw_p, 63443859Sml29623 p_dip, 63453859Sml29623 hw_p->ndevs)); 63463859Sml29623 63476495Sspeer nxge_hio_uninit(nxgep); 63486495Sspeer 63493859Sml29623 if (hw_p == nxge_hw_list) { 63503859Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, 63513859Sml29623 "==> nxge_uninit_common_device:" 63523859Sml29623 "remove head func # %d " 63533859Sml29623 "hw_p $%p parent dip $%p " 63543859Sml29623 "ndevs %d (head)", 63553859Sml29623 nxgep->function_num, 63563859Sml29623 hw_p, 63573859Sml29623 p_dip, 63583859Sml29623 hw_p->ndevs)); 63593859Sml29623 nxge_hw_list = hw_p->next; 63603859Sml29623 } else { 63613859Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, 63623859Sml29623 "==> nxge_uninit_common_device:" 63633859Sml29623 "remove middle func # %d " 63643859Sml29623 "hw_p $%p parent dip $%p " 63653859Sml29623 "ndevs %d (middle)", 63663859Sml29623 nxgep->function_num, 63673859Sml29623 hw_p, 63683859Sml29623 p_dip, 63693859Sml29623 hw_p->ndevs)); 63703859Sml29623 h_hw_p->next = hw_p->next; 63713859Sml29623 } 63723859Sml29623 63736495Sspeer nxgep->nxge_hw_p = NULL; 63743859Sml29623 KMEM_FREE(hw_p, sizeof (nxge_hw_list_t)); 63753859Sml29623 } 63763859Sml29623 break; 63773859Sml29623 } else { 63783859Sml29623 h_hw_p = hw_p; 63793859Sml29623 } 63803859Sml29623 } 63813859Sml29623 63823859Sml29623 MUTEX_EXIT(&nxge_common_lock); 63833859Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, 63843859Sml29623 "==> nxge_uninit_common_device (nxge_hw_list) $%p", 63853859Sml29623 nxge_hw_list)); 63863859Sml29623 63873859Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, "<= nxge_uninit_common_device")); 63883859Sml29623 } 63894732Sdavemq 63904732Sdavemq /* 63914977Sraghus * Determines the number of ports from the niu_type or the platform type. 63924732Sdavemq * Returns the number of ports, or returns zero on failure. 63934732Sdavemq */ 63944732Sdavemq 63954732Sdavemq int 63964977Sraghus nxge_get_nports(p_nxge_t nxgep) 63974732Sdavemq { 63984732Sdavemq int nports = 0; 63994732Sdavemq 64004977Sraghus switch (nxgep->niu_type) { 64014732Sdavemq case N2_NIU: 64024732Sdavemq case NEPTUNE_2_10GF: 64034732Sdavemq nports = 2; 64044732Sdavemq break; 64054732Sdavemq case NEPTUNE_4_1GC: 64064732Sdavemq case NEPTUNE_2_10GF_2_1GC: 64074732Sdavemq case NEPTUNE_1_10GF_3_1GC: 64084732Sdavemq case NEPTUNE_1_1GC_1_10GF_2_1GC: 64096261Sjoycey case NEPTUNE_2_10GF_2_1GRF: 64104732Sdavemq nports = 4; 64114732Sdavemq break; 64124732Sdavemq default: 64134977Sraghus switch (nxgep->platform_type) { 64144977Sraghus case P_NEPTUNE_NIU: 64154977Sraghus case P_NEPTUNE_ATLAS_2PORT: 64164977Sraghus nports = 2; 64174977Sraghus break; 64184977Sraghus case P_NEPTUNE_ATLAS_4PORT: 64194977Sraghus case P_NEPTUNE_MARAMBA_P0: 64204977Sraghus case P_NEPTUNE_MARAMBA_P1: 64215196Ssbehera case P_NEPTUNE_ALONSO: 64224977Sraghus nports = 4; 64234977Sraghus break; 64244977Sraghus default: 64254977Sraghus break; 64264977Sraghus } 64274732Sdavemq break; 64284732Sdavemq } 64294732Sdavemq 64304732Sdavemq return (nports); 64314732Sdavemq } 64325013Sml29623 64335013Sml29623 /* 64345013Sml29623 * The following two functions are to support 64355013Sml29623 * PSARC/2007/453 MSI-X interrupt limit override. 64365013Sml29623 */ 64375013Sml29623 static int 64385013Sml29623 nxge_create_msi_property(p_nxge_t nxgep) 64395013Sml29623 { 64405013Sml29623 int nmsi; 64415013Sml29623 extern int ncpus; 64425013Sml29623 64435013Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, "==>nxge_create_msi_property")); 64445013Sml29623 64455013Sml29623 switch (nxgep->mac.portmode) { 64465013Sml29623 case PORT_10G_COPPER: 64475013Sml29623 case PORT_10G_FIBER: 64485013Sml29623 (void) ddi_prop_create(DDI_DEV_T_NONE, nxgep->dip, 64495013Sml29623 DDI_PROP_CANSLEEP, "#msix-request", NULL, 0); 64505013Sml29623 /* 64515013Sml29623 * The maximum MSI-X requested will be 8. 64525013Sml29623 * If the # of CPUs is less than 8, we will reqeust 64535013Sml29623 * # MSI-X based on the # of CPUs. 64545013Sml29623 */ 64555013Sml29623 if (ncpus >= NXGE_MSIX_REQUEST_10G) { 64565013Sml29623 nmsi = NXGE_MSIX_REQUEST_10G; 64575013Sml29623 } else { 64585013Sml29623 nmsi = ncpus; 64595013Sml29623 } 64605013Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, 64615013Sml29623 "==>nxge_create_msi_property(10G): exists 0x%x (nmsi %d)", 64625013Sml29623 ddi_prop_exists(DDI_DEV_T_NONE, nxgep->dip, 64635013Sml29623 DDI_PROP_CANSLEEP, "#msix-request"), nmsi)); 64645013Sml29623 break; 64655013Sml29623 64665013Sml29623 default: 64675013Sml29623 nmsi = NXGE_MSIX_REQUEST_1G; 64685013Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, 64695013Sml29623 "==>nxge_create_msi_property(1G): exists 0x%x (nmsi %d)", 64705013Sml29623 ddi_prop_exists(DDI_DEV_T_NONE, nxgep->dip, 64715013Sml29623 DDI_PROP_CANSLEEP, "#msix-request"), nmsi)); 64725013Sml29623 break; 64735013Sml29623 } 64745013Sml29623 64755013Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, "<==nxge_create_msi_property")); 64765013Sml29623 return (nmsi); 64775013Sml29623 } 6478