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 /* 228661SSantwona.Behera@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 233859Sml29623 * Use is subject to license terms. 243859Sml29623 */ 253859Sml29623 263859Sml29623 /* 273859Sml29623 * SunOs MT STREAMS NIU/Neptune 10Gb Ethernet Device Driver. 283859Sml29623 */ 293859Sml29623 #include <sys/nxge/nxge_impl.h> 306495Sspeer #include <sys/nxge/nxge_hio.h> 316495Sspeer #include <sys/nxge/nxge_rxdma.h> 323859Sml29623 #include <sys/pcie.h> 333859Sml29623 343859Sml29623 uint32_t nxge_use_partition = 0; /* debug partition flag */ 353859Sml29623 uint32_t nxge_dma_obp_props_only = 1; /* use obp published props */ 363859Sml29623 uint32_t nxge_use_rdc_intr = 1; /* debug to assign rdc intr */ 373859Sml29623 /* 385013Sml29623 * PSARC/2007/453 MSI-X interrupt limit override 393859Sml29623 */ 405013Sml29623 uint32_t nxge_msi_enable = 2; 413859Sml29623 426611Sml29623 /* 436705Sml29623 * Software workaround for a Neptune (PCI-E) 446705Sml29623 * hardware interrupt bug which the hardware 456705Sml29623 * may generate spurious interrupts after the 466705Sml29623 * device interrupt handler was removed. If this flag 476705Sml29623 * is enabled, the driver will reset the 486705Sml29623 * hardware when devices are being detached. 496705Sml29623 */ 506705Sml29623 uint32_t nxge_peu_reset_enable = 0; 516705Sml29623 526705Sml29623 /* 536611Sml29623 * Software workaround for the hardware 546611Sml29623 * checksum bugs that affect packet transmission 556611Sml29623 * and receive: 566611Sml29623 * 576611Sml29623 * Usage of nxge_cksum_offload: 586611Sml29623 * 596611Sml29623 * (1) nxge_cksum_offload = 0 (default): 606611Sml29623 * - transmits packets: 616611Sml29623 * TCP: uses the hardware checksum feature. 626611Sml29623 * UDP: driver will compute the software checksum 636611Sml29623 * based on the partial checksum computed 646611Sml29623 * by the IP layer. 656611Sml29623 * - receives packets 666611Sml29623 * TCP: marks packets checksum flags based on hardware result. 676611Sml29623 * UDP: will not mark checksum flags. 686611Sml29623 * 696611Sml29623 * (2) nxge_cksum_offload = 1: 706611Sml29623 * - transmit packets: 716611Sml29623 * TCP/UDP: uses the hardware checksum feature. 726611Sml29623 * - receives packets 736611Sml29623 * TCP/UDP: marks packet checksum flags based on hardware result. 746611Sml29623 * 756611Sml29623 * (3) nxge_cksum_offload = 2: 766611Sml29623 * - The driver will not register its checksum capability. 776611Sml29623 * Checksum for both TCP and UDP will be computed 786611Sml29623 * by the stack. 796611Sml29623 * - The software LSO is not allowed in this case. 806611Sml29623 * 816611Sml29623 * (4) nxge_cksum_offload > 2: 826611Sml29623 * - Will be treated as it is set to 2 836611Sml29623 * (stack will compute the checksum). 846611Sml29623 * 856611Sml29623 * (5) If the hardware bug is fixed, this workaround 866611Sml29623 * needs to be updated accordingly to reflect 876611Sml29623 * the new hardware revision. 886611Sml29623 */ 896611Sml29623 uint32_t nxge_cksum_offload = 0; 906495Sspeer 913859Sml29623 /* 923859Sml29623 * Globals: tunable parameters (/etc/system or adb) 933859Sml29623 * 943859Sml29623 */ 953859Sml29623 uint32_t nxge_rbr_size = NXGE_RBR_RBB_DEFAULT; 963859Sml29623 uint32_t nxge_rbr_spare_size = 0; 973859Sml29623 uint32_t nxge_rcr_size = NXGE_RCR_DEFAULT; 983859Sml29623 uint32_t nxge_tx_ring_size = NXGE_TX_RING_DEFAULT; 994193Sspeer boolean_t nxge_no_msg = B_TRUE; /* control message display */ 1003859Sml29623 uint32_t nxge_no_link_notify = 0; /* control DL_NOTIFY */ 1013859Sml29623 uint32_t nxge_bcopy_thresh = TX_BCOPY_MAX; 1023859Sml29623 uint32_t nxge_dvma_thresh = TX_FASTDVMA_MIN; 1033859Sml29623 uint32_t nxge_dma_stream_thresh = TX_STREAM_MIN; 1043859Sml29623 uint32_t nxge_jumbo_mtu = TX_JUMBO_MTU; 1053859Sml29623 boolean_t nxge_jumbo_enable = B_FALSE; 1063952Sml29623 nxge_tx_mode_t nxge_tx_scheme = NXGE_USE_SERIAL; 1073859Sml29623 1085770Sml29623 /* MAX LSO size */ 1095770Sml29623 #define NXGE_LSO_MAXLEN 65535 1105770Sml29623 uint32_t nxge_lso_max = NXGE_LSO_MAXLEN; 1115770Sml29623 1123859Sml29623 1133859Sml29623 /* 1143859Sml29623 * Add tunable to reduce the amount of time spent in the 1153859Sml29623 * ISR doing Rx Processing. 1163859Sml29623 */ 1173859Sml29623 uint32_t nxge_max_rx_pkts = 1024; 1183859Sml29623 1193859Sml29623 /* 1203859Sml29623 * Tunables to manage the receive buffer blocks. 1213859Sml29623 * 1223859Sml29623 * nxge_rx_threshold_hi: copy all buffers. 1233859Sml29623 * nxge_rx_bcopy_size_type: receive buffer block size type. 1243859Sml29623 * nxge_rx_threshold_lo: copy only up to tunable block size type. 1253859Sml29623 */ 1263859Sml29623 nxge_rxbuf_threshold_t nxge_rx_threshold_hi = NXGE_RX_COPY_6; 1273859Sml29623 nxge_rxbuf_type_t nxge_rx_buf_size_type = RCR_PKTBUFSZ_0; 1283859Sml29623 nxge_rxbuf_threshold_t nxge_rx_threshold_lo = NXGE_RX_COPY_3; 1293859Sml29623 1306495Sspeer /* Use kmem_alloc() to allocate data buffers. */ 1316909Sml29623 #if defined(_BIG_ENDIAN) 1326498Sspeer uint32_t nxge_use_kmem_alloc = 1; 1336495Sspeer #else 1346498Sspeer uint32_t nxge_use_kmem_alloc = 0; 1356495Sspeer #endif 1366495Sspeer 1373859Sml29623 rtrace_t npi_rtracebuf; 1383859Sml29623 1397126Sml29623 /* 1407126Sml29623 * The hardware sometimes fails to allow enough time for the link partner 1417126Sml29623 * to send an acknowledgement for packets that the hardware sent to it. The 1427126Sml29623 * hardware resends the packets earlier than it should be in those instances. 1437126Sml29623 * This behavior caused some switches to acknowledge the wrong packets 1447126Sml29623 * and it triggered the fatal error. 1457126Sml29623 * This software workaround is to set the replay timer to a value 1467126Sml29623 * suggested by the hardware team. 1477126Sml29623 * 1487126Sml29623 * PCI config space replay timer register: 1497126Sml29623 * The following replay timeout value is 0xc 1507126Sml29623 * for bit 14:18. 1517126Sml29623 */ 1527126Sml29623 #define PCI_REPLAY_TIMEOUT_CFG_OFFSET 0xb8 1537126Sml29623 #define PCI_REPLAY_TIMEOUT_SHIFT 14 1547126Sml29623 1557126Sml29623 uint32_t nxge_set_replay_timer = 1; 1567126Sml29623 uint32_t nxge_replay_timeout = 0xc; 1577126Sml29623 1587241Sml29623 /* 1597241Sml29623 * The transmit serialization sometimes causes 1607241Sml29623 * longer sleep before calling the driver transmit 1617241Sml29623 * function as it sleeps longer than it should. 1627241Sml29623 * The performace group suggests that a time wait tunable 1637241Sml29623 * can be used to set the maximum wait time when needed 1647241Sml29623 * and the default is set to 1 tick. 1657241Sml29623 */ 1667241Sml29623 uint32_t nxge_tx_serial_maxsleep = 1; 1677241Sml29623 1683859Sml29623 #if defined(sun4v) 1693859Sml29623 /* 1703859Sml29623 * Hypervisor N2/NIU services information. 1713859Sml29623 */ 1723859Sml29623 static hsvc_info_t niu_hsvc = { 1733859Sml29623 HSVC_REV_1, NULL, HSVC_GROUP_NIU, NIU_MAJOR_VER, 1743859Sml29623 NIU_MINOR_VER, "nxge" 1753859Sml29623 }; 1766495Sspeer 1776495Sspeer static int nxge_hsvc_register(p_nxge_t); 1783859Sml29623 #endif 1793859Sml29623 1803859Sml29623 /* 1813859Sml29623 * Function Prototypes 1823859Sml29623 */ 1833859Sml29623 static int nxge_attach(dev_info_t *, ddi_attach_cmd_t); 1843859Sml29623 static int nxge_detach(dev_info_t *, ddi_detach_cmd_t); 1853859Sml29623 static void nxge_unattach(p_nxge_t); 1867656SSherry.Moore@Sun.COM static int nxge_quiesce(dev_info_t *); 1873859Sml29623 1883859Sml29623 #if NXGE_PROPERTY 1893859Sml29623 static void nxge_remove_hard_properties(p_nxge_t); 1903859Sml29623 #endif 1913859Sml29623 1926495Sspeer /* 1936495Sspeer * These two functions are required by nxge_hio.c 1946495Sspeer */ 1958275SEric Cheng extern int nxge_m_mmac_remove(void *arg, int slot); 1967766SMichael.Speer@Sun.COM extern void nxge_grp_cleanup(p_nxge_t nxge); 1976495Sspeer 1983859Sml29623 static nxge_status_t nxge_setup_system_dma_pages(p_nxge_t); 1993859Sml29623 2003859Sml29623 static nxge_status_t nxge_setup_mutexes(p_nxge_t); 2013859Sml29623 static void nxge_destroy_mutexes(p_nxge_t); 2023859Sml29623 2033859Sml29623 static nxge_status_t nxge_map_regs(p_nxge_t nxgep); 2043859Sml29623 static void nxge_unmap_regs(p_nxge_t nxgep); 2053859Sml29623 #ifdef NXGE_DEBUG 2063859Sml29623 static void nxge_test_map_regs(p_nxge_t nxgep); 2073859Sml29623 #endif 2083859Sml29623 2093859Sml29623 static nxge_status_t nxge_add_intrs(p_nxge_t nxgep); 2103859Sml29623 static void nxge_remove_intrs(p_nxge_t nxgep); 2113859Sml29623 2123859Sml29623 static nxge_status_t nxge_add_intrs_adv(p_nxge_t nxgep); 2133859Sml29623 static nxge_status_t nxge_add_intrs_adv_type(p_nxge_t, uint32_t); 2143859Sml29623 static nxge_status_t nxge_add_intrs_adv_type_fix(p_nxge_t, uint32_t); 2153859Sml29623 static void nxge_intrs_enable(p_nxge_t nxgep); 2163859Sml29623 static void nxge_intrs_disable(p_nxge_t nxgep); 2173859Sml29623 2183859Sml29623 static void nxge_suspend(p_nxge_t); 2193859Sml29623 static nxge_status_t nxge_resume(p_nxge_t); 2203859Sml29623 2213859Sml29623 static nxge_status_t nxge_setup_dev(p_nxge_t); 2223859Sml29623 static void nxge_destroy_dev(p_nxge_t); 2233859Sml29623 2243859Sml29623 static nxge_status_t nxge_alloc_mem_pool(p_nxge_t); 2253859Sml29623 static void nxge_free_mem_pool(p_nxge_t); 2263859Sml29623 2276495Sspeer nxge_status_t nxge_alloc_rx_mem_pool(p_nxge_t); 2283859Sml29623 static void nxge_free_rx_mem_pool(p_nxge_t); 2293859Sml29623 2306495Sspeer nxge_status_t nxge_alloc_tx_mem_pool(p_nxge_t); 2313859Sml29623 static void nxge_free_tx_mem_pool(p_nxge_t); 2323859Sml29623 2333859Sml29623 static nxge_status_t nxge_dma_mem_alloc(p_nxge_t, dma_method_t, 2343859Sml29623 struct ddi_dma_attr *, 2353859Sml29623 size_t, ddi_device_acc_attr_t *, uint_t, 2363859Sml29623 p_nxge_dma_common_t); 2373859Sml29623 2383859Sml29623 static void nxge_dma_mem_free(p_nxge_dma_common_t); 2396495Sspeer static void nxge_dma_free_rx_data_buf(p_nxge_dma_common_t); 2403859Sml29623 2413859Sml29623 static nxge_status_t nxge_alloc_rx_buf_dma(p_nxge_t, uint16_t, 2423859Sml29623 p_nxge_dma_common_t *, size_t, size_t, uint32_t *); 2433859Sml29623 static void nxge_free_rx_buf_dma(p_nxge_t, p_nxge_dma_common_t, uint32_t); 2443859Sml29623 2453859Sml29623 static nxge_status_t nxge_alloc_rx_cntl_dma(p_nxge_t, uint16_t, 2463859Sml29623 p_nxge_dma_common_t *, size_t); 2473859Sml29623 static void nxge_free_rx_cntl_dma(p_nxge_t, p_nxge_dma_common_t); 2483859Sml29623 2496495Sspeer extern nxge_status_t nxge_alloc_tx_buf_dma(p_nxge_t, uint16_t, 2503859Sml29623 p_nxge_dma_common_t *, size_t, size_t, uint32_t *); 2513859Sml29623 static void nxge_free_tx_buf_dma(p_nxge_t, p_nxge_dma_common_t, uint32_t); 2523859Sml29623 2536495Sspeer extern nxge_status_t nxge_alloc_tx_cntl_dma(p_nxge_t, uint16_t, 2543859Sml29623 p_nxge_dma_common_t *, 2553859Sml29623 size_t); 2563859Sml29623 static void nxge_free_tx_cntl_dma(p_nxge_t, p_nxge_dma_common_t); 2573859Sml29623 2583859Sml29623 static int nxge_init_common_dev(p_nxge_t); 2593859Sml29623 static void nxge_uninit_common_dev(p_nxge_t); 2606512Ssowmini extern int nxge_param_set_mac(p_nxge_t, queue_t *, mblk_t *, 2616512Ssowmini char *, caddr_t); 2629232SMichael.Speer@Sun.COM #if defined(sun4v) 2639232SMichael.Speer@Sun.COM extern nxge_status_t nxge_hio_rdc_enable(p_nxge_t nxgep); 2649232SMichael.Speer@Sun.COM extern nxge_status_t nxge_hio_rdc_intr_arm(p_nxge_t nxge, boolean_t arm); 2659232SMichael.Speer@Sun.COM #endif 2663859Sml29623 2673859Sml29623 /* 2683859Sml29623 * The next declarations are for the GLDv3 interface. 2693859Sml29623 */ 2703859Sml29623 static int nxge_m_start(void *); 2713859Sml29623 static void nxge_m_stop(void *); 2723859Sml29623 static int nxge_m_multicst(void *, boolean_t, const uint8_t *); 2733859Sml29623 static int nxge_m_promisc(void *, boolean_t); 2743859Sml29623 static void nxge_m_ioctl(void *, queue_t *, mblk_t *); 2753859Sml29623 static nxge_status_t nxge_mac_register(p_nxge_t); 2768275SEric Cheng static int nxge_altmac_set(p_nxge_t nxgep, uint8_t *mac_addr, 2778275SEric Cheng int slot, int rdctbl, boolean_t usetbl); 2788275SEric Cheng void nxge_mmac_kstat_update(p_nxge_t nxgep, int slot, 2793859Sml29623 boolean_t factory); 2808275SEric Cheng #if defined(sun4v) 2818275SEric Cheng extern mblk_t *nxge_m_tx(void *arg, mblk_t *mp); 2828275SEric Cheng #endif 2838275SEric Cheng 2848275SEric Cheng static void nxge_m_getfactaddr(void *, uint_t, uint8_t *); 2856439Sml29623 static boolean_t nxge_m_getcapab(void *, mac_capab_t, void *); 2866439Sml29623 static int nxge_m_setprop(void *, const char *, mac_prop_id_t, 2876439Sml29623 uint_t, const void *); 2886439Sml29623 static int nxge_m_getprop(void *, const char *, mac_prop_id_t, 2898118SVasumathi.Sundaram@Sun.COM uint_t, uint_t, void *, uint_t *); 2906439Sml29623 static int nxge_set_priv_prop(nxge_t *, const char *, uint_t, 2916439Sml29623 const void *); 2926512Ssowmini static int nxge_get_priv_prop(nxge_t *, const char *, uint_t, uint_t, 2938118SVasumathi.Sundaram@Sun.COM void *, uint_t *); 2946512Ssowmini static int nxge_get_def_val(nxge_t *, mac_prop_id_t, uint_t, void *); 2958275SEric Cheng static void nxge_fill_ring(void *, mac_ring_type_t, const int, const int, 2968275SEric Cheng mac_ring_info_t *, mac_ring_handle_t); 2978275SEric Cheng static void nxge_group_add_ring(mac_group_driver_t, mac_ring_driver_t, 2988275SEric Cheng mac_ring_type_t); 2998275SEric Cheng static void nxge_group_rem_ring(mac_group_driver_t, mac_ring_driver_t, 3008275SEric Cheng mac_ring_type_t); 3016512Ssowmini 3026705Sml29623 static void nxge_niu_peu_reset(p_nxge_t nxgep); 3037126Sml29623 static void nxge_set_pci_replay_timeout(nxge_t *); 3046512Ssowmini 3056512Ssowmini mac_priv_prop_t nxge_priv_props[] = { 3066512Ssowmini {"_adv_10gfdx_cap", MAC_PROP_PERM_RW}, 3076512Ssowmini {"_adv_pause_cap", MAC_PROP_PERM_RW}, 3086512Ssowmini {"_function_number", MAC_PROP_PERM_READ}, 3096512Ssowmini {"_fw_version", MAC_PROP_PERM_READ}, 3106512Ssowmini {"_port_mode", MAC_PROP_PERM_READ}, 3116512Ssowmini {"_hot_swap_phy", MAC_PROP_PERM_READ}, 3126512Ssowmini {"_accept_jumbo", MAC_PROP_PERM_RW}, 3136512Ssowmini {"_rxdma_intr_time", MAC_PROP_PERM_RW}, 3146512Ssowmini {"_rxdma_intr_pkts", MAC_PROP_PERM_RW}, 3156512Ssowmini {"_class_opt_ipv4_tcp", MAC_PROP_PERM_RW}, 3166512Ssowmini {"_class_opt_ipv4_udp", MAC_PROP_PERM_RW}, 3176512Ssowmini {"_class_opt_ipv4_ah", MAC_PROP_PERM_RW}, 3186512Ssowmini {"_class_opt_ipv4_sctp", MAC_PROP_PERM_RW}, 3196512Ssowmini {"_class_opt_ipv6_tcp", MAC_PROP_PERM_RW}, 3206512Ssowmini {"_class_opt_ipv6_udp", MAC_PROP_PERM_RW}, 3216512Ssowmini {"_class_opt_ipv6_ah", MAC_PROP_PERM_RW}, 3226512Ssowmini {"_class_opt_ipv6_sctp", MAC_PROP_PERM_RW}, 3236512Ssowmini {"_soft_lso_enable", MAC_PROP_PERM_RW} 3246512Ssowmini }; 3256512Ssowmini 3266512Ssowmini #define NXGE_MAX_PRIV_PROPS \ 3276512Ssowmini (sizeof (nxge_priv_props)/sizeof (mac_priv_prop_t)) 3286439Sml29623 3293859Sml29623 #define NXGE_NEPTUNE_MAGIC 0x4E584745UL 3303859Sml29623 #define MAX_DUMP_SZ 256 3313859Sml29623 3326439Sml29623 #define NXGE_M_CALLBACK_FLAGS \ 3338275SEric Cheng (MC_IOCTL | MC_GETCAPAB | MC_SETPROP | MC_GETPROP) 3346439Sml29623 3356495Sspeer mac_callbacks_t nxge_m_callbacks = { 3363859Sml29623 NXGE_M_CALLBACK_FLAGS, 3373859Sml29623 nxge_m_stat, 3383859Sml29623 nxge_m_start, 3393859Sml29623 nxge_m_stop, 3403859Sml29623 nxge_m_promisc, 3413859Sml29623 nxge_m_multicst, 3428275SEric Cheng NULL, 3438275SEric Cheng NULL, 3443859Sml29623 nxge_m_ioctl, 3456439Sml29623 nxge_m_getcapab, 3466439Sml29623 NULL, 3476439Sml29623 NULL, 3486439Sml29623 nxge_m_setprop, 3496439Sml29623 nxge_m_getprop 3503859Sml29623 }; 3513859Sml29623 3523859Sml29623 void 3533859Sml29623 nxge_err_inject(p_nxge_t, queue_t *, mblk_t *); 3543859Sml29623 3555013Sml29623 /* PSARC/2007/453 MSI-X interrupt limit override. */ 3565013Sml29623 #define NXGE_MSIX_REQUEST_10G 8 3575013Sml29623 #define NXGE_MSIX_REQUEST_1G 2 3585013Sml29623 static int nxge_create_msi_property(p_nxge_t); 3598455Stc99174@train /* 3608455Stc99174@train * For applications that care about the 3618455Stc99174@train * latency, it was requested by PAE and the 3628455Stc99174@train * customers that the driver has tunables that 3638455Stc99174@train * allow the user to tune it to a higher number 3648455Stc99174@train * interrupts to spread the interrupts among 3658455Stc99174@train * multiple channels. The DDI framework limits 3668455Stc99174@train * the maximum number of MSI-X resources to allocate 3678455Stc99174@train * to 8 (ddi_msix_alloc_limit). If more than 8 3688455Stc99174@train * is set, ddi_msix_alloc_limit must be set accordingly. 3698455Stc99174@train * The default number of MSI interrupts are set to 3708455Stc99174@train * 8 for 10G and 2 for 1G link. 3718455Stc99174@train */ 3728455Stc99174@train #define NXGE_MSIX_MAX_ALLOWED 32 3738455Stc99174@train uint32_t nxge_msix_10g_intrs = NXGE_MSIX_REQUEST_10G; 3748455Stc99174@train uint32_t nxge_msix_1g_intrs = NXGE_MSIX_REQUEST_1G; 3755013Sml29623 3763859Sml29623 /* 3773859Sml29623 * These global variables control the message 3783859Sml29623 * output. 3793859Sml29623 */ 3803859Sml29623 out_dbgmsg_t nxge_dbgmsg_out = DBG_CONSOLE | STR_LOG; 3816495Sspeer uint64_t nxge_debug_level; 3823859Sml29623 3833859Sml29623 /* 3843859Sml29623 * This list contains the instance structures for the Neptune 3853859Sml29623 * devices present in the system. The lock exists to guarantee 3863859Sml29623 * mutually exclusive access to the list. 3873859Sml29623 */ 3883859Sml29623 void *nxge_list = NULL; 3893859Sml29623 3903859Sml29623 void *nxge_hw_list = NULL; 3913859Sml29623 nxge_os_mutex_t nxge_common_lock; 3923859Sml29623 3933859Sml29623 extern uint64_t npi_debug_level; 3943859Sml29623 3953859Sml29623 extern nxge_status_t nxge_ldgv_init(p_nxge_t, int *, int *); 3963859Sml29623 extern nxge_status_t nxge_ldgv_init_n2(p_nxge_t, int *, int *); 3973859Sml29623 extern nxge_status_t nxge_ldgv_uninit(p_nxge_t); 3983859Sml29623 extern nxge_status_t nxge_intr_ldgv_init(p_nxge_t); 3993859Sml29623 extern void nxge_fm_init(p_nxge_t, 4003859Sml29623 ddi_device_acc_attr_t *, 4013859Sml29623 ddi_device_acc_attr_t *, 4023859Sml29623 ddi_dma_attr_t *); 4033859Sml29623 extern void nxge_fm_fini(p_nxge_t); 4043859Sml29623 extern npi_status_t npi_mac_altaddr_disable(npi_handle_t, uint8_t, uint8_t); 4053859Sml29623 4063859Sml29623 /* 4073859Sml29623 * Count used to maintain the number of buffers being used 4083859Sml29623 * by Neptune instances and loaned up to the upper layers. 4093859Sml29623 */ 4103859Sml29623 uint32_t nxge_mblks_pending = 0; 4113859Sml29623 4123859Sml29623 /* 4133859Sml29623 * Device register access attributes for PIO. 4143859Sml29623 */ 4153859Sml29623 static ddi_device_acc_attr_t nxge_dev_reg_acc_attr = { 4163859Sml29623 DDI_DEVICE_ATTR_V0, 4173859Sml29623 DDI_STRUCTURE_LE_ACC, 4183859Sml29623 DDI_STRICTORDER_ACC, 4193859Sml29623 }; 4203859Sml29623 4213859Sml29623 /* 4223859Sml29623 * Device descriptor access attributes for DMA. 4233859Sml29623 */ 4243859Sml29623 static ddi_device_acc_attr_t nxge_dev_desc_dma_acc_attr = { 4253859Sml29623 DDI_DEVICE_ATTR_V0, 4263859Sml29623 DDI_STRUCTURE_LE_ACC, 4273859Sml29623 DDI_STRICTORDER_ACC 4283859Sml29623 }; 4293859Sml29623 4303859Sml29623 /* 4313859Sml29623 * Device buffer access attributes for DMA. 4323859Sml29623 */ 4333859Sml29623 static ddi_device_acc_attr_t nxge_dev_buf_dma_acc_attr = { 4343859Sml29623 DDI_DEVICE_ATTR_V0, 4353859Sml29623 DDI_STRUCTURE_BE_ACC, 4363859Sml29623 DDI_STRICTORDER_ACC 4373859Sml29623 }; 4383859Sml29623 4393859Sml29623 ddi_dma_attr_t nxge_desc_dma_attr = { 4403859Sml29623 DMA_ATTR_V0, /* version number. */ 4413859Sml29623 0, /* low address */ 4423859Sml29623 0xffffffffffffffff, /* high address */ 4433859Sml29623 0xffffffffffffffff, /* address counter max */ 4443859Sml29623 #ifndef NIU_PA_WORKAROUND 4453859Sml29623 0x100000, /* alignment */ 4463859Sml29623 #else 4473859Sml29623 0x2000, 4483859Sml29623 #endif 4493859Sml29623 0xfc00fc, /* dlim_burstsizes */ 4503859Sml29623 0x1, /* minimum transfer size */ 4513859Sml29623 0xffffffffffffffff, /* maximum transfer size */ 4523859Sml29623 0xffffffffffffffff, /* maximum segment size */ 4533859Sml29623 1, /* scatter/gather list length */ 4543859Sml29623 (unsigned int) 1, /* granularity */ 4553859Sml29623 0 /* attribute flags */ 4563859Sml29623 }; 4573859Sml29623 4583859Sml29623 ddi_dma_attr_t nxge_tx_dma_attr = { 4593859Sml29623 DMA_ATTR_V0, /* version number. */ 4603859Sml29623 0, /* low address */ 4613859Sml29623 0xffffffffffffffff, /* high address */ 4623859Sml29623 0xffffffffffffffff, /* address counter max */ 4633859Sml29623 #if defined(_BIG_ENDIAN) 4643859Sml29623 0x2000, /* alignment */ 4653859Sml29623 #else 4663859Sml29623 0x1000, /* alignment */ 4673859Sml29623 #endif 4683859Sml29623 0xfc00fc, /* dlim_burstsizes */ 4693859Sml29623 0x1, /* minimum transfer size */ 4703859Sml29623 0xffffffffffffffff, /* maximum transfer size */ 4713859Sml29623 0xffffffffffffffff, /* maximum segment size */ 4723859Sml29623 5, /* scatter/gather list length */ 4733859Sml29623 (unsigned int) 1, /* granularity */ 4743859Sml29623 0 /* attribute flags */ 4753859Sml29623 }; 4763859Sml29623 4773859Sml29623 ddi_dma_attr_t nxge_rx_dma_attr = { 4783859Sml29623 DMA_ATTR_V0, /* version number. */ 4793859Sml29623 0, /* low address */ 4803859Sml29623 0xffffffffffffffff, /* high address */ 4813859Sml29623 0xffffffffffffffff, /* address counter max */ 4823859Sml29623 0x2000, /* alignment */ 4833859Sml29623 0xfc00fc, /* dlim_burstsizes */ 4843859Sml29623 0x1, /* minimum transfer size */ 4853859Sml29623 0xffffffffffffffff, /* maximum transfer size */ 4863859Sml29623 0xffffffffffffffff, /* maximum segment size */ 4873859Sml29623 1, /* scatter/gather list length */ 4883859Sml29623 (unsigned int) 1, /* granularity */ 4894781Ssbehera DDI_DMA_RELAXED_ORDERING /* attribute flags */ 4903859Sml29623 }; 4913859Sml29623 4923859Sml29623 ddi_dma_lim_t nxge_dma_limits = { 4933859Sml29623 (uint_t)0, /* dlim_addr_lo */ 4943859Sml29623 (uint_t)0xffffffff, /* dlim_addr_hi */ 4953859Sml29623 (uint_t)0xffffffff, /* dlim_cntr_max */ 4963859Sml29623 (uint_t)0xfc00fc, /* dlim_burstsizes for 32 and 64 bit xfers */ 4973859Sml29623 0x1, /* dlim_minxfer */ 4983859Sml29623 1024 /* dlim_speed */ 4993859Sml29623 }; 5003859Sml29623 5013859Sml29623 dma_method_t nxge_force_dma = DVMA; 5023859Sml29623 5033859Sml29623 /* 5043859Sml29623 * dma chunk sizes. 5053859Sml29623 * 5063859Sml29623 * Try to allocate the largest possible size 5073859Sml29623 * so that fewer number of dma chunks would be managed 5083859Sml29623 */ 5093859Sml29623 #ifdef NIU_PA_WORKAROUND 5103859Sml29623 size_t alloc_sizes [] = {0x2000}; 5113859Sml29623 #else 5123859Sml29623 size_t alloc_sizes [] = {0x1000, 0x2000, 0x4000, 0x8000, 5133859Sml29623 0x10000, 0x20000, 0x40000, 0x80000, 5145770Sml29623 0x100000, 0x200000, 0x400000, 0x800000, 5155770Sml29623 0x1000000, 0x2000000, 0x4000000}; 5163859Sml29623 #endif 5173859Sml29623 5183859Sml29623 /* 5193859Sml29623 * Translate "dev_t" to a pointer to the associated "dev_info_t". 5203859Sml29623 */ 5213859Sml29623 5226495Sspeer extern void nxge_get_environs(nxge_t *); 5236495Sspeer 5243859Sml29623 static int 5253859Sml29623 nxge_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) 5263859Sml29623 { 5273859Sml29623 p_nxge_t nxgep = NULL; 5283859Sml29623 int instance; 5293859Sml29623 int status = DDI_SUCCESS; 5303859Sml29623 uint8_t portn; 5313859Sml29623 nxge_mmac_t *mmac_info; 5327529SSriharsha.Basavapatna@Sun.COM p_nxge_param_t param_arr; 5333859Sml29623 5343859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_attach")); 5353859Sml29623 5363859Sml29623 /* 5373859Sml29623 * Get the device instance since we'll need to setup 5383859Sml29623 * or retrieve a soft state for this instance. 5393859Sml29623 */ 5403859Sml29623 instance = ddi_get_instance(dip); 5413859Sml29623 5423859Sml29623 switch (cmd) { 5433859Sml29623 case DDI_ATTACH: 5443859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "doing DDI_ATTACH")); 5453859Sml29623 break; 5463859Sml29623 5473859Sml29623 case DDI_RESUME: 5483859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "doing DDI_RESUME")); 5493859Sml29623 nxgep = (p_nxge_t)ddi_get_soft_state(nxge_list, instance); 5503859Sml29623 if (nxgep == NULL) { 5513859Sml29623 status = DDI_FAILURE; 5523859Sml29623 break; 5533859Sml29623 } 5543859Sml29623 if (nxgep->dip != dip) { 5553859Sml29623 status = DDI_FAILURE; 5563859Sml29623 break; 5573859Sml29623 } 5583859Sml29623 if (nxgep->suspended == DDI_PM_SUSPEND) { 5593859Sml29623 status = ddi_dev_is_needed(nxgep->dip, 0, 1); 5603859Sml29623 } else { 5614185Sspeer status = nxge_resume(nxgep); 5623859Sml29623 } 5633859Sml29623 goto nxge_attach_exit; 5643859Sml29623 5653859Sml29623 case DDI_PM_RESUME: 5663859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "doing DDI_PM_RESUME")); 5673859Sml29623 nxgep = (p_nxge_t)ddi_get_soft_state(nxge_list, instance); 5683859Sml29623 if (nxgep == NULL) { 5693859Sml29623 status = DDI_FAILURE; 5703859Sml29623 break; 5713859Sml29623 } 5723859Sml29623 if (nxgep->dip != dip) { 5733859Sml29623 status = DDI_FAILURE; 5743859Sml29623 break; 5753859Sml29623 } 5764185Sspeer status = nxge_resume(nxgep); 5773859Sml29623 goto nxge_attach_exit; 5783859Sml29623 5793859Sml29623 default: 5803859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "doing unknown")); 5813859Sml29623 status = DDI_FAILURE; 5823859Sml29623 goto nxge_attach_exit; 5833859Sml29623 } 5843859Sml29623 5853859Sml29623 5863859Sml29623 if (ddi_soft_state_zalloc(nxge_list, instance) == DDI_FAILURE) { 5873859Sml29623 status = DDI_FAILURE; 5883859Sml29623 goto nxge_attach_exit; 5893859Sml29623 } 5903859Sml29623 5913859Sml29623 nxgep = ddi_get_soft_state(nxge_list, instance); 5923859Sml29623 if (nxgep == NULL) { 5934977Sraghus status = NXGE_ERROR; 5944977Sraghus goto nxge_attach_fail2; 5953859Sml29623 } 5963859Sml29623 5974693Stm144005 nxgep->nxge_magic = NXGE_MAGIC; 5984693Stm144005 5993859Sml29623 nxgep->drv_state = 0; 6003859Sml29623 nxgep->dip = dip; 6013859Sml29623 nxgep->instance = instance; 6023859Sml29623 nxgep->p_dip = ddi_get_parent(dip); 6033859Sml29623 nxgep->nxge_debug_level = nxge_debug_level; 6043859Sml29623 npi_debug_level = nxge_debug_level; 6053859Sml29623 6066495Sspeer /* Are we a guest running in a Hybrid I/O environment? */ 6076495Sspeer nxge_get_environs(nxgep); 6083859Sml29623 6093859Sml29623 status = nxge_map_regs(nxgep); 6106495Sspeer 6113859Sml29623 if (status != NXGE_OK) { 6123859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "nxge_map_regs failed")); 6134977Sraghus goto nxge_attach_fail3; 6143859Sml29623 } 6153859Sml29623 6166495Sspeer nxge_fm_init(nxgep, &nxge_dev_reg_acc_attr, 6176495Sspeer &nxge_dev_desc_dma_acc_attr, 6186495Sspeer &nxge_rx_dma_attr); 6196495Sspeer 6206495Sspeer /* Create & initialize the per-Neptune data structure */ 6216495Sspeer /* (even if we're a guest). */ 6223859Sml29623 status = nxge_init_common_dev(nxgep); 6233859Sml29623 if (status != NXGE_OK) { 6243859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 6256512Ssowmini "nxge_init_common_dev failed")); 6264977Sraghus goto nxge_attach_fail4; 6273859Sml29623 } 6283859Sml29623 6297126Sml29623 /* 6307126Sml29623 * Software workaround: set the replay timer. 6317126Sml29623 */ 6327126Sml29623 if (nxgep->niu_type != N2_NIU) { 6337126Sml29623 nxge_set_pci_replay_timeout(nxgep); 6347126Sml29623 } 6358275SEric Cheng #if defined(sun4v) 6368275SEric Cheng if (isLDOMguest(nxgep)) { 6378275SEric Cheng nxge_m_callbacks.mc_tx = nxge_m_tx; 6388275SEric Cheng } 6398275SEric Cheng #endif 6407126Sml29623 6416495Sspeer #if defined(sun4v) 6426495Sspeer /* This is required by nxge_hio_init(), which follows. */ 6436495Sspeer if ((status = nxge_hsvc_register(nxgep)) != DDI_SUCCESS) 6447587SMichael.Speer@Sun.COM goto nxge_attach_fail4; 6456495Sspeer #endif 6466495Sspeer 6476495Sspeer if ((status = nxge_hio_init(nxgep)) != NXGE_OK) { 6486495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 6496512Ssowmini "nxge_hio_init failed")); 6506495Sspeer goto nxge_attach_fail4; 6516495Sspeer } 6526495Sspeer 6534732Sdavemq if (nxgep->niu_type == NEPTUNE_2_10GF) { 6544732Sdavemq if (nxgep->function_num > 1) { 6556028Ssbehera NXGE_DEBUG_MSG((nxgep, DDI_CTL, "Unsupported" 6564732Sdavemq " function %d. Only functions 0 and 1 are " 6574732Sdavemq "supported for this card.", nxgep->function_num)); 6584732Sdavemq status = NXGE_ERROR; 6594977Sraghus goto nxge_attach_fail4; 6604732Sdavemq } 6614732Sdavemq } 6624732Sdavemq 6636495Sspeer if (isLDOMguest(nxgep)) { 6646495Sspeer /* 6656495Sspeer * Use the function number here. 6666495Sspeer */ 6676495Sspeer nxgep->mac.portnum = nxgep->function_num; 6686495Sspeer nxgep->mac.porttype = PORT_TYPE_LOGICAL; 6696495Sspeer 6706495Sspeer /* XXX We'll set the MAC address counts to 1 for now. */ 6716495Sspeer mmac_info = &nxgep->nxge_mmac_info; 6726495Sspeer mmac_info->num_mmac = 1; 6736495Sspeer mmac_info->naddrfree = 1; 6743859Sml29623 } else { 6756495Sspeer portn = NXGE_GET_PORT_NUM(nxgep->function_num); 6766495Sspeer nxgep->mac.portnum = portn; 6776495Sspeer if ((portn == 0) || (portn == 1)) 6786495Sspeer nxgep->mac.porttype = PORT_TYPE_XMAC; 6796495Sspeer else 6806495Sspeer nxgep->mac.porttype = PORT_TYPE_BMAC; 6816495Sspeer /* 6826495Sspeer * Neptune has 4 ports, the first 2 ports use XMAC (10G MAC) 6836495Sspeer * internally, the rest 2 ports use BMAC (1G "Big" MAC). 6846495Sspeer * The two types of MACs have different characterizations. 6856495Sspeer */ 6866495Sspeer mmac_info = &nxgep->nxge_mmac_info; 6876495Sspeer if (nxgep->function_num < 2) { 6886495Sspeer mmac_info->num_mmac = XMAC_MAX_ALT_ADDR_ENTRY; 6896495Sspeer mmac_info->naddrfree = XMAC_MAX_ALT_ADDR_ENTRY; 6906495Sspeer } else { 6916495Sspeer mmac_info->num_mmac = BMAC_MAX_ALT_ADDR_ENTRY; 6926495Sspeer mmac_info->naddrfree = BMAC_MAX_ALT_ADDR_ENTRY; 6936495Sspeer } 6943859Sml29623 } 6953859Sml29623 /* 6963859Sml29623 * Setup the Ndd parameters for the this instance. 6973859Sml29623 */ 6983859Sml29623 nxge_init_param(nxgep); 6993859Sml29623 7003859Sml29623 /* 7013859Sml29623 * Setup Register Tracing Buffer. 7023859Sml29623 */ 7033859Sml29623 npi_rtrace_buf_init((rtrace_t *)&npi_rtracebuf); 7043859Sml29623 7053859Sml29623 /* init stats ptr */ 7063859Sml29623 nxge_init_statsp(nxgep); 7074185Sspeer 7084977Sraghus /* 7096495Sspeer * Copy the vpd info from eeprom to a local data 7106495Sspeer * structure, and then check its validity. 7114977Sraghus */ 7126495Sspeer if (!isLDOMguest(nxgep)) { 7136495Sspeer int *regp; 7146495Sspeer uint_t reglen; 7156495Sspeer int rv; 7166495Sspeer 7176495Sspeer nxge_vpd_info_get(nxgep); 7186495Sspeer 7196495Sspeer /* Find the NIU config handle. */ 7206495Sspeer rv = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, 7216495Sspeer ddi_get_parent(nxgep->dip), DDI_PROP_DONTPASS, 7226495Sspeer "reg", ®p, ®len); 7236495Sspeer 7246495Sspeer if (rv != DDI_PROP_SUCCESS) { 7256495Sspeer goto nxge_attach_fail5; 7266495Sspeer } 7276495Sspeer /* 7286495Sspeer * The address_hi, that is the first int, in the reg 7296495Sspeer * property consists of config handle, but need to remove 7306495Sspeer * the bits 28-31 which are OBP specific info. 7316495Sspeer */ 7326495Sspeer nxgep->niu_cfg_hdl = (*regp) & 0xFFFFFFF; 7336495Sspeer ddi_prop_free(regp); 7346495Sspeer } 7356495Sspeer 7366495Sspeer if (isLDOMguest(nxgep)) { 7376495Sspeer uchar_t *prop_val; 7386495Sspeer uint_t prop_len; 7397529SSriharsha.Basavapatna@Sun.COM uint32_t max_frame_size; 7406495Sspeer 7416495Sspeer extern void nxge_get_logical_props(p_nxge_t); 7426495Sspeer 7436495Sspeer nxgep->statsp->mac_stats.xcvr_inuse = LOGICAL_XCVR; 7446495Sspeer nxgep->mac.portmode = PORT_LOGICAL; 7456495Sspeer (void) ddi_prop_update_string(DDI_DEV_T_NONE, nxgep->dip, 7466495Sspeer "phy-type", "virtual transceiver"); 7476495Sspeer 7486495Sspeer nxgep->nports = 1; 7496495Sspeer nxgep->board_ver = 0; /* XXX What? */ 7506495Sspeer 7516495Sspeer /* 7526495Sspeer * local-mac-address property gives us info on which 7536495Sspeer * specific MAC address the Hybrid resource is associated 7546495Sspeer * with. 7556495Sspeer */ 7566495Sspeer if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0, 7576495Sspeer "local-mac-address", &prop_val, 7586495Sspeer &prop_len) != DDI_PROP_SUCCESS) { 7596495Sspeer goto nxge_attach_fail5; 7606495Sspeer } 7616495Sspeer if (prop_len != ETHERADDRL) { 7626495Sspeer ddi_prop_free(prop_val); 7636495Sspeer goto nxge_attach_fail5; 7646495Sspeer } 7656495Sspeer ether_copy(prop_val, nxgep->hio_mac_addr); 7666495Sspeer ddi_prop_free(prop_val); 7676495Sspeer nxge_get_logical_props(nxgep); 7686495Sspeer 7697529SSriharsha.Basavapatna@Sun.COM /* 7707529SSriharsha.Basavapatna@Sun.COM * Enable Jumbo property based on the "max-frame-size" 7717529SSriharsha.Basavapatna@Sun.COM * property value. 7727529SSriharsha.Basavapatna@Sun.COM */ 7737529SSriharsha.Basavapatna@Sun.COM max_frame_size = ddi_prop_get_int(DDI_DEV_T_ANY, 7747529SSriharsha.Basavapatna@Sun.COM nxgep->dip, DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, 7757529SSriharsha.Basavapatna@Sun.COM "max-frame-size", NXGE_MTU_DEFAULT_MAX); 7767529SSriharsha.Basavapatna@Sun.COM if ((max_frame_size > NXGE_MTU_DEFAULT_MAX) && 7777529SSriharsha.Basavapatna@Sun.COM (max_frame_size <= TX_JUMBO_MTU)) { 7787529SSriharsha.Basavapatna@Sun.COM param_arr = nxgep->param_arr; 7797529SSriharsha.Basavapatna@Sun.COM 7807529SSriharsha.Basavapatna@Sun.COM param_arr[param_accept_jumbo].value = 1; 7817529SSriharsha.Basavapatna@Sun.COM nxgep->mac.is_jumbo = B_TRUE; 7827529SSriharsha.Basavapatna@Sun.COM nxgep->mac.maxframesize = (uint16_t)max_frame_size; 7837529SSriharsha.Basavapatna@Sun.COM nxgep->mac.default_mtu = nxgep->mac.maxframesize - 7847529SSriharsha.Basavapatna@Sun.COM NXGE_EHEADER_VLAN_CRC; 7857529SSriharsha.Basavapatna@Sun.COM } 7866495Sspeer } else { 7876495Sspeer status = nxge_xcvr_find(nxgep); 7886495Sspeer 7896495Sspeer if (status != NXGE_OK) { 7906495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "nxge_attach: " 7916512Ssowmini " Couldn't determine card type" 7926512Ssowmini " .... exit ")); 7936495Sspeer goto nxge_attach_fail5; 7946495Sspeer } 7956495Sspeer 7966495Sspeer status = nxge_get_config_properties(nxgep); 7976495Sspeer 7986495Sspeer if (status != NXGE_OK) { 7996495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 8006512Ssowmini "get_hw create failed")); 8016495Sspeer goto nxge_attach_fail; 8026495Sspeer } 8033859Sml29623 } 8043859Sml29623 8053859Sml29623 /* 8063859Sml29623 * Setup the Kstats for the driver. 8073859Sml29623 */ 8083859Sml29623 nxge_setup_kstats(nxgep); 8093859Sml29623 8106495Sspeer if (!isLDOMguest(nxgep)) 8116495Sspeer nxge_setup_param(nxgep); 8123859Sml29623 8133859Sml29623 status = nxge_setup_system_dma_pages(nxgep); 8143859Sml29623 if (status != NXGE_OK) { 8153859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "set dma page failed")); 8163859Sml29623 goto nxge_attach_fail; 8173859Sml29623 } 8183859Sml29623 8193859Sml29623 nxge_hw_id_init(nxgep); 8206495Sspeer 8216495Sspeer if (!isLDOMguest(nxgep)) 8226495Sspeer nxge_hw_init_niu_common(nxgep); 8233859Sml29623 8243859Sml29623 status = nxge_setup_mutexes(nxgep); 8253859Sml29623 if (status != NXGE_OK) { 8263859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "set mutex failed")); 8273859Sml29623 goto nxge_attach_fail; 8283859Sml29623 } 8293859Sml29623 8306495Sspeer #if defined(sun4v) 8316495Sspeer if (isLDOMguest(nxgep)) { 8326495Sspeer /* Find our VR & channel sets. */ 8336495Sspeer status = nxge_hio_vr_add(nxgep); 8347812SMichael.Speer@Sun.COM if (status != NXGE_OK) { 8357812SMichael.Speer@Sun.COM NXGE_DEBUG_MSG((nxgep, DDI_CTL, 8367812SMichael.Speer@Sun.COM "nxge_hio_vr_add failed")); 8377812SMichael.Speer@Sun.COM (void) hsvc_unregister(&nxgep->niu_hsvc); 8387812SMichael.Speer@Sun.COM nxgep->niu_hsvc_available = B_FALSE; 8397812SMichael.Speer@Sun.COM } 8406495Sspeer goto nxge_attach_exit; 8416495Sspeer } 8426495Sspeer #endif 8436495Sspeer 8443859Sml29623 status = nxge_setup_dev(nxgep); 8453859Sml29623 if (status != DDI_SUCCESS) { 8463859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "set dev failed")); 8473859Sml29623 goto nxge_attach_fail; 8483859Sml29623 } 8493859Sml29623 8503859Sml29623 status = nxge_add_intrs(nxgep); 8513859Sml29623 if (status != DDI_SUCCESS) { 8523859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "add_intr failed")); 8533859Sml29623 goto nxge_attach_fail; 8543859Sml29623 } 8557812SMichael.Speer@Sun.COM 8566835Syc148097 /* If a guest, register with vio_net instead. */ 8574977Sraghus if ((status = nxge_mac_register(nxgep)) != NXGE_OK) { 8583859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 8596495Sspeer "unable to register to mac layer (%d)", status)); 8603859Sml29623 goto nxge_attach_fail; 8613859Sml29623 } 8623859Sml29623 8633859Sml29623 mac_link_update(nxgep->mach, LINK_STATE_UNKNOWN); 8643859Sml29623 8656495Sspeer NXGE_DEBUG_MSG((nxgep, DDI_CTL, 8666495Sspeer "registered to mac (instance %d)", instance)); 8673859Sml29623 8686835Syc148097 /* nxge_link_monitor calls xcvr.check_link recursively */ 8693859Sml29623 (void) nxge_link_monitor(nxgep, LINK_MONITOR_START); 8703859Sml29623 8713859Sml29623 goto nxge_attach_exit; 8723859Sml29623 8733859Sml29623 nxge_attach_fail: 8743859Sml29623 nxge_unattach(nxgep); 8754977Sraghus goto nxge_attach_fail1; 8764977Sraghus 8774977Sraghus nxge_attach_fail5: 8784977Sraghus /* 8794977Sraghus * Tear down the ndd parameters setup. 8804977Sraghus */ 8814977Sraghus nxge_destroy_param(nxgep); 8824977Sraghus 8834977Sraghus /* 8844977Sraghus * Tear down the kstat setup. 8854977Sraghus */ 8864977Sraghus nxge_destroy_kstats(nxgep); 8874977Sraghus 8884977Sraghus nxge_attach_fail4: 8894977Sraghus if (nxgep->nxge_hw_p) { 8904977Sraghus nxge_uninit_common_dev(nxgep); 8914977Sraghus nxgep->nxge_hw_p = NULL; 8924977Sraghus } 8934977Sraghus 8944977Sraghus nxge_attach_fail3: 8954977Sraghus /* 8964977Sraghus * Unmap the register setup. 8974977Sraghus */ 8984977Sraghus nxge_unmap_regs(nxgep); 8994977Sraghus 9004977Sraghus nxge_fm_fini(nxgep); 9014977Sraghus 9024977Sraghus nxge_attach_fail2: 9034977Sraghus ddi_soft_state_free(nxge_list, nxgep->instance); 9044977Sraghus 9054977Sraghus nxge_attach_fail1: 9064185Sspeer if (status != NXGE_OK) 9074185Sspeer status = (NXGE_ERROR | NXGE_DDI_FAILED); 9083859Sml29623 nxgep = NULL; 9093859Sml29623 9103859Sml29623 nxge_attach_exit: 9113859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_attach status = 0x%08x", 9126512Ssowmini status)); 9133859Sml29623 9143859Sml29623 return (status); 9153859Sml29623 } 9163859Sml29623 9173859Sml29623 static int 9183859Sml29623 nxge_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) 9193859Sml29623 { 9203859Sml29623 int status = DDI_SUCCESS; 9213859Sml29623 int instance; 9223859Sml29623 p_nxge_t nxgep = NULL; 9233859Sml29623 9243859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_detach")); 9253859Sml29623 instance = ddi_get_instance(dip); 9263859Sml29623 nxgep = ddi_get_soft_state(nxge_list, instance); 9273859Sml29623 if (nxgep == NULL) { 9283859Sml29623 status = DDI_FAILURE; 9293859Sml29623 goto nxge_detach_exit; 9303859Sml29623 } 9313859Sml29623 9323859Sml29623 switch (cmd) { 9333859Sml29623 case DDI_DETACH: 9343859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "doing DDI_DETACH")); 9353859Sml29623 break; 9363859Sml29623 9373859Sml29623 case DDI_PM_SUSPEND: 9383859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "doing DDI_PM_SUSPEND")); 9393859Sml29623 nxgep->suspended = DDI_PM_SUSPEND; 9403859Sml29623 nxge_suspend(nxgep); 9413859Sml29623 break; 9423859Sml29623 9433859Sml29623 case DDI_SUSPEND: 9443859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "doing DDI_SUSPEND")); 9453859Sml29623 if (nxgep->suspended != DDI_PM_SUSPEND) { 9463859Sml29623 nxgep->suspended = DDI_SUSPEND; 9473859Sml29623 nxge_suspend(nxgep); 9483859Sml29623 } 9493859Sml29623 break; 9503859Sml29623 9513859Sml29623 default: 9523859Sml29623 status = DDI_FAILURE; 9533859Sml29623 } 9543859Sml29623 9553859Sml29623 if (cmd != DDI_DETACH) 9563859Sml29623 goto nxge_detach_exit; 9573859Sml29623 9583859Sml29623 /* 9593859Sml29623 * Stop the xcvr polling. 9603859Sml29623 */ 9613859Sml29623 nxgep->suspended = cmd; 9623859Sml29623 9633859Sml29623 (void) nxge_link_monitor(nxgep, LINK_MONITOR_STOP); 9643859Sml29623 9656495Sspeer if (isLDOMguest(nxgep)) { 9667466SMisaki.Kataoka@Sun.COM if (nxgep->nxge_mac_state == NXGE_MAC_STARTED) 9677466SMisaki.Kataoka@Sun.COM nxge_m_stop((void *)nxgep); 9686495Sspeer nxge_hio_unregister(nxgep); 9696495Sspeer } else if (nxgep->mach && (status = mac_unregister(nxgep->mach)) != 0) { 9703859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 9716512Ssowmini "<== nxge_detach status = 0x%08X", status)); 9723859Sml29623 return (DDI_FAILURE); 9733859Sml29623 } 9743859Sml29623 9753859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 9766512Ssowmini "<== nxge_detach (mac_unregister) status = 0x%08X", status)); 9773859Sml29623 9783859Sml29623 nxge_unattach(nxgep); 9793859Sml29623 nxgep = NULL; 9803859Sml29623 9813859Sml29623 nxge_detach_exit: 9823859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_detach status = 0x%08X", 9836512Ssowmini status)); 9843859Sml29623 9853859Sml29623 return (status); 9863859Sml29623 } 9873859Sml29623 9883859Sml29623 static void 9893859Sml29623 nxge_unattach(p_nxge_t nxgep) 9903859Sml29623 { 9913859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_unattach")); 9923859Sml29623 9933859Sml29623 if (nxgep == NULL || nxgep->dev_regs == NULL) { 9943859Sml29623 return; 9953859Sml29623 } 9963859Sml29623 9974693Stm144005 nxgep->nxge_magic = 0; 9984693Stm144005 9995780Ssbehera if (nxgep->nxge_timerid) { 10005780Ssbehera nxge_stop_timer(nxgep, nxgep->nxge_timerid); 10015780Ssbehera nxgep->nxge_timerid = 0; 10025780Ssbehera } 10035780Ssbehera 10046705Sml29623 /* 10056705Sml29623 * If this flag is set, it will affect the Neptune 10066705Sml29623 * only. 10076705Sml29623 */ 10086705Sml29623 if ((nxgep->niu_type != N2_NIU) && nxge_peu_reset_enable) { 10096705Sml29623 nxge_niu_peu_reset(nxgep); 10106705Sml29623 } 10116705Sml29623 10126495Sspeer #if defined(sun4v) 10136495Sspeer if (isLDOMguest(nxgep)) { 10146498Sspeer (void) nxge_hio_vr_release(nxgep); 10156495Sspeer } 10166495Sspeer #endif 10176495Sspeer 10183859Sml29623 if (nxgep->nxge_hw_p) { 10193859Sml29623 nxge_uninit_common_dev(nxgep); 10203859Sml29623 nxgep->nxge_hw_p = NULL; 10213859Sml29623 } 10223859Sml29623 10233859Sml29623 #if defined(sun4v) 10243859Sml29623 if (nxgep->niu_type == N2_NIU && nxgep->niu_hsvc_available == B_TRUE) { 10253859Sml29623 (void) hsvc_unregister(&nxgep->niu_hsvc); 10263859Sml29623 nxgep->niu_hsvc_available = B_FALSE; 10273859Sml29623 } 10283859Sml29623 #endif 10293859Sml29623 /* 10303859Sml29623 * Stop any further interrupts. 10313859Sml29623 */ 10323859Sml29623 nxge_remove_intrs(nxgep); 10333859Sml29623 10343859Sml29623 /* 10353859Sml29623 * Stop the device and free resources. 10363859Sml29623 */ 10376495Sspeer if (!isLDOMguest(nxgep)) { 10386495Sspeer nxge_destroy_dev(nxgep); 10396495Sspeer } 10403859Sml29623 10413859Sml29623 /* 10423859Sml29623 * Tear down the ndd parameters setup. 10433859Sml29623 */ 10443859Sml29623 nxge_destroy_param(nxgep); 10453859Sml29623 10463859Sml29623 /* 10473859Sml29623 * Tear down the kstat setup. 10483859Sml29623 */ 10493859Sml29623 nxge_destroy_kstats(nxgep); 10503859Sml29623 10513859Sml29623 /* 10523859Sml29623 * Destroy all mutexes. 10533859Sml29623 */ 10543859Sml29623 nxge_destroy_mutexes(nxgep); 10553859Sml29623 10563859Sml29623 /* 10573859Sml29623 * Remove the list of ndd parameters which 10583859Sml29623 * were setup during attach. 10593859Sml29623 */ 10603859Sml29623 if (nxgep->dip) { 10613859Sml29623 NXGE_DEBUG_MSG((nxgep, OBP_CTL, 10626512Ssowmini " nxge_unattach: remove all properties")); 10633859Sml29623 10643859Sml29623 (void) ddi_prop_remove_all(nxgep->dip); 10653859Sml29623 } 10663859Sml29623 10673859Sml29623 #if NXGE_PROPERTY 10683859Sml29623 nxge_remove_hard_properties(nxgep); 10693859Sml29623 #endif 10703859Sml29623 10713859Sml29623 /* 10723859Sml29623 * Unmap the register setup. 10733859Sml29623 */ 10743859Sml29623 nxge_unmap_regs(nxgep); 10753859Sml29623 10763859Sml29623 nxge_fm_fini(nxgep); 10773859Sml29623 10783859Sml29623 ddi_soft_state_free(nxge_list, nxgep->instance); 10793859Sml29623 10803859Sml29623 NXGE_DEBUG_MSG((NULL, DDI_CTL, "<== nxge_unattach")); 10813859Sml29623 } 10823859Sml29623 10836495Sspeer #if defined(sun4v) 10846495Sspeer int 10857587SMichael.Speer@Sun.COM nxge_hsvc_register(nxge_t *nxgep) 10866495Sspeer { 10876495Sspeer nxge_status_t status; 10886495Sspeer 10896495Sspeer if (nxgep->niu_type == N2_NIU) { 10906495Sspeer nxgep->niu_hsvc_available = B_FALSE; 10916495Sspeer bcopy(&niu_hsvc, &nxgep->niu_hsvc, sizeof (hsvc_info_t)); 10926495Sspeer if ((status = hsvc_register(&nxgep->niu_hsvc, 10936495Sspeer &nxgep->niu_min_ver)) != 0) { 10946495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 10956495Sspeer "nxge_attach: %s: cannot negotiate " 10966495Sspeer "hypervisor services revision %d group: 0x%lx " 10976495Sspeer "major: 0x%lx minor: 0x%lx errno: %d", 10986495Sspeer niu_hsvc.hsvc_modname, niu_hsvc.hsvc_rev, 10996495Sspeer niu_hsvc.hsvc_group, niu_hsvc.hsvc_major, 11006495Sspeer niu_hsvc.hsvc_minor, status)); 11016495Sspeer return (DDI_FAILURE); 11026495Sspeer } 11036495Sspeer nxgep->niu_hsvc_available = B_TRUE; 11046495Sspeer NXGE_DEBUG_MSG((nxgep, DDI_CTL, 11056512Ssowmini "NIU Hypervisor service enabled")); 11066495Sspeer } 11076495Sspeer 11086495Sspeer return (DDI_SUCCESS); 11096495Sspeer } 11106495Sspeer #endif 11116495Sspeer 11123859Sml29623 static char n2_siu_name[] = "niu"; 11133859Sml29623 11143859Sml29623 static nxge_status_t 11153859Sml29623 nxge_map_regs(p_nxge_t nxgep) 11163859Sml29623 { 11173859Sml29623 int ddi_status = DDI_SUCCESS; 11183859Sml29623 p_dev_regs_t dev_regs; 11193859Sml29623 char buf[MAXPATHLEN + 1]; 11203859Sml29623 char *devname; 11213859Sml29623 #ifdef NXGE_DEBUG 11223859Sml29623 char *sysname; 11233859Sml29623 #endif 11243859Sml29623 off_t regsize; 11253859Sml29623 nxge_status_t status = NXGE_OK; 11263859Sml29623 #if !defined(_BIG_ENDIAN) 11273859Sml29623 off_t pci_offset; 11283859Sml29623 uint16_t pcie_devctl; 11293859Sml29623 #endif 11303859Sml29623 11316495Sspeer if (isLDOMguest(nxgep)) { 11326495Sspeer return (nxge_guest_regs_map(nxgep)); 11336495Sspeer } 11346495Sspeer 11353859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_map_regs")); 11363859Sml29623 nxgep->dev_regs = NULL; 11373859Sml29623 dev_regs = KMEM_ZALLOC(sizeof (dev_regs_t), KM_SLEEP); 11383859Sml29623 dev_regs->nxge_regh = NULL; 11393859Sml29623 dev_regs->nxge_pciregh = NULL; 11403859Sml29623 dev_regs->nxge_msix_regh = NULL; 11413859Sml29623 dev_regs->nxge_vir_regh = NULL; 11423859Sml29623 dev_regs->nxge_vir2_regh = NULL; 11434732Sdavemq nxgep->niu_type = NIU_TYPE_NONE; 11443859Sml29623 11453859Sml29623 devname = ddi_pathname(nxgep->dip, buf); 11463859Sml29623 ASSERT(strlen(devname) > 0); 11473859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 11486512Ssowmini "nxge_map_regs: pathname devname %s", devname)); 11493859Sml29623 11506835Syc148097 /* 11516835Syc148097 * The driver is running on a N2-NIU system if devname is something 11526835Syc148097 * like "/niu@80/network@0" 11536835Syc148097 */ 11543859Sml29623 if (strstr(devname, n2_siu_name)) { 11553859Sml29623 /* N2/NIU */ 11563859Sml29623 nxgep->niu_type = N2_NIU; 11573859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 11586512Ssowmini "nxge_map_regs: N2/NIU devname %s", devname)); 11593859Sml29623 /* get function number */ 11603859Sml29623 nxgep->function_num = 11616512Ssowmini (devname[strlen(devname) -1] == '1' ? 1 : 0); 11623859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 11636512Ssowmini "nxge_map_regs: N2/NIU function number %d", 11646512Ssowmini nxgep->function_num)); 11653859Sml29623 } else { 11663859Sml29623 int *prop_val; 11673859Sml29623 uint_t prop_len; 11683859Sml29623 uint8_t func_num; 11693859Sml29623 11703859Sml29623 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 11716512Ssowmini 0, "reg", 11726512Ssowmini &prop_val, &prop_len) != DDI_PROP_SUCCESS) { 11733859Sml29623 NXGE_DEBUG_MSG((nxgep, VPD_CTL, 11746512Ssowmini "Reg property not found")); 11753859Sml29623 ddi_status = DDI_FAILURE; 11763859Sml29623 goto nxge_map_regs_fail0; 11773859Sml29623 11783859Sml29623 } else { 11793859Sml29623 func_num = (prop_val[0] >> 8) & 0x7; 11803859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 11816512Ssowmini "Reg property found: fun # %d", 11826512Ssowmini func_num)); 11833859Sml29623 nxgep->function_num = func_num; 11846495Sspeer if (isLDOMguest(nxgep)) { 11856495Sspeer nxgep->function_num /= 2; 11866495Sspeer return (NXGE_OK); 11876495Sspeer } 11883859Sml29623 ddi_prop_free(prop_val); 11893859Sml29623 } 11903859Sml29623 } 11913859Sml29623 11923859Sml29623 switch (nxgep->niu_type) { 11933859Sml29623 default: 11943859Sml29623 (void) ddi_dev_regsize(nxgep->dip, 0, ®size); 11953859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 11966512Ssowmini "nxge_map_regs: pci config size 0x%x", regsize)); 11973859Sml29623 11983859Sml29623 ddi_status = ddi_regs_map_setup(nxgep->dip, 0, 11996512Ssowmini (caddr_t *)&(dev_regs->nxge_pciregp), 0, 0, 12006512Ssowmini &nxge_dev_reg_acc_attr, &dev_regs->nxge_pciregh); 12013859Sml29623 if (ddi_status != DDI_SUCCESS) { 12023859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 12036512Ssowmini "ddi_map_regs, nxge bus config regs failed")); 12043859Sml29623 goto nxge_map_regs_fail0; 12053859Sml29623 } 12063859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 12076512Ssowmini "nxge_map_reg: PCI config addr 0x%0llx " 12086512Ssowmini " handle 0x%0llx", dev_regs->nxge_pciregp, 12096512Ssowmini dev_regs->nxge_pciregh)); 12103859Sml29623 /* 12113859Sml29623 * IMP IMP 12123859Sml29623 * workaround for bit swapping bug in HW 12133859Sml29623 * which ends up in no-snoop = yes 12143859Sml29623 * resulting, in DMA not synched properly 12153859Sml29623 */ 12163859Sml29623 #if !defined(_BIG_ENDIAN) 12173859Sml29623 /* workarounds for x86 systems */ 12183859Sml29623 pci_offset = 0x80 + PCIE_DEVCTL; 12193859Sml29623 pcie_devctl = 0x0; 12203859Sml29623 pcie_devctl &= PCIE_DEVCTL_ENABLE_NO_SNOOP; 12213859Sml29623 pcie_devctl |= PCIE_DEVCTL_RO_EN; 12223859Sml29623 pci_config_put16(dev_regs->nxge_pciregh, pci_offset, 12236512Ssowmini pcie_devctl); 12243859Sml29623 #endif 12253859Sml29623 12263859Sml29623 (void) ddi_dev_regsize(nxgep->dip, 1, ®size); 12273859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 12286512Ssowmini "nxge_map_regs: pio size 0x%x", regsize)); 12293859Sml29623 /* set up the device mapped register */ 12303859Sml29623 ddi_status = ddi_regs_map_setup(nxgep->dip, 1, 12316512Ssowmini (caddr_t *)&(dev_regs->nxge_regp), 0, 0, 12326512Ssowmini &nxge_dev_reg_acc_attr, &dev_regs->nxge_regh); 12333859Sml29623 if (ddi_status != DDI_SUCCESS) { 12343859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 12356512Ssowmini "ddi_map_regs for Neptune global reg failed")); 12363859Sml29623 goto nxge_map_regs_fail1; 12373859Sml29623 } 12383859Sml29623 12393859Sml29623 /* set up the msi/msi-x mapped register */ 12403859Sml29623 (void) ddi_dev_regsize(nxgep->dip, 2, ®size); 12413859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 12426512Ssowmini "nxge_map_regs: msix size 0x%x", regsize)); 12433859Sml29623 ddi_status = ddi_regs_map_setup(nxgep->dip, 2, 12446512Ssowmini (caddr_t *)&(dev_regs->nxge_msix_regp), 0, 0, 12456512Ssowmini &nxge_dev_reg_acc_attr, &dev_regs->nxge_msix_regh); 12463859Sml29623 if (ddi_status != DDI_SUCCESS) { 12473859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 12486512Ssowmini "ddi_map_regs for msi reg failed")); 12493859Sml29623 goto nxge_map_regs_fail2; 12503859Sml29623 } 12513859Sml29623 12523859Sml29623 /* set up the vio region mapped register */ 12533859Sml29623 (void) ddi_dev_regsize(nxgep->dip, 3, ®size); 12543859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 12556512Ssowmini "nxge_map_regs: vio size 0x%x", regsize)); 12563859Sml29623 ddi_status = ddi_regs_map_setup(nxgep->dip, 3, 12576512Ssowmini (caddr_t *)&(dev_regs->nxge_vir_regp), 0, 0, 12586512Ssowmini &nxge_dev_reg_acc_attr, &dev_regs->nxge_vir_regh); 12593859Sml29623 12603859Sml29623 if (ddi_status != DDI_SUCCESS) { 12613859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 12626512Ssowmini "ddi_map_regs for nxge vio reg failed")); 12633859Sml29623 goto nxge_map_regs_fail3; 12643859Sml29623 } 12653859Sml29623 nxgep->dev_regs = dev_regs; 12663859Sml29623 12673859Sml29623 NPI_PCI_ACC_HANDLE_SET(nxgep, dev_regs->nxge_pciregh); 12683859Sml29623 NPI_PCI_ADD_HANDLE_SET(nxgep, 12696512Ssowmini (npi_reg_ptr_t)dev_regs->nxge_pciregp); 12703859Sml29623 NPI_MSI_ACC_HANDLE_SET(nxgep, dev_regs->nxge_msix_regh); 12713859Sml29623 NPI_MSI_ADD_HANDLE_SET(nxgep, 12726512Ssowmini (npi_reg_ptr_t)dev_regs->nxge_msix_regp); 12733859Sml29623 12743859Sml29623 NPI_ACC_HANDLE_SET(nxgep, dev_regs->nxge_regh); 12753859Sml29623 NPI_ADD_HANDLE_SET(nxgep, (npi_reg_ptr_t)dev_regs->nxge_regp); 12763859Sml29623 12773859Sml29623 NPI_REG_ACC_HANDLE_SET(nxgep, dev_regs->nxge_regh); 12783859Sml29623 NPI_REG_ADD_HANDLE_SET(nxgep, 12796512Ssowmini (npi_reg_ptr_t)dev_regs->nxge_regp); 12803859Sml29623 12813859Sml29623 NPI_VREG_ACC_HANDLE_SET(nxgep, dev_regs->nxge_vir_regh); 12823859Sml29623 NPI_VREG_ADD_HANDLE_SET(nxgep, 12836512Ssowmini (npi_reg_ptr_t)dev_regs->nxge_vir_regp); 12843859Sml29623 12853859Sml29623 break; 12863859Sml29623 12873859Sml29623 case N2_NIU: 12883859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "ddi_map_regs, NIU")); 12893859Sml29623 /* 12903859Sml29623 * Set up the device mapped register (FWARC 2006/556) 12913859Sml29623 * (changed back to 1: reg starts at 1!) 12923859Sml29623 */ 12933859Sml29623 (void) ddi_dev_regsize(nxgep->dip, 1, ®size); 12943859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 12956512Ssowmini "nxge_map_regs: dev size 0x%x", regsize)); 12963859Sml29623 ddi_status = ddi_regs_map_setup(nxgep->dip, 1, 12976512Ssowmini (caddr_t *)&(dev_regs->nxge_regp), 0, 0, 12986512Ssowmini &nxge_dev_reg_acc_attr, &dev_regs->nxge_regh); 12993859Sml29623 13003859Sml29623 if (ddi_status != DDI_SUCCESS) { 13013859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 13026512Ssowmini "ddi_map_regs for N2/NIU, global reg failed ")); 13033859Sml29623 goto nxge_map_regs_fail1; 13043859Sml29623 } 13053859Sml29623 13066495Sspeer /* set up the first vio region mapped register */ 13073859Sml29623 (void) ddi_dev_regsize(nxgep->dip, 2, ®size); 13083859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 13096512Ssowmini "nxge_map_regs: vio (1) size 0x%x", regsize)); 13103859Sml29623 ddi_status = ddi_regs_map_setup(nxgep->dip, 2, 13116512Ssowmini (caddr_t *)&(dev_regs->nxge_vir_regp), 0, 0, 13126512Ssowmini &nxge_dev_reg_acc_attr, &dev_regs->nxge_vir_regh); 13133859Sml29623 13143859Sml29623 if (ddi_status != DDI_SUCCESS) { 13153859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 13166512Ssowmini "ddi_map_regs for nxge vio reg failed")); 13173859Sml29623 goto nxge_map_regs_fail2; 13183859Sml29623 } 13196495Sspeer /* set up the second vio region mapped register */ 13203859Sml29623 (void) ddi_dev_regsize(nxgep->dip, 3, ®size); 13213859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 13226512Ssowmini "nxge_map_regs: vio (3) size 0x%x", regsize)); 13233859Sml29623 ddi_status = ddi_regs_map_setup(nxgep->dip, 3, 13246512Ssowmini (caddr_t *)&(dev_regs->nxge_vir2_regp), 0, 0, 13256512Ssowmini &nxge_dev_reg_acc_attr, &dev_regs->nxge_vir2_regh); 13263859Sml29623 13273859Sml29623 if (ddi_status != DDI_SUCCESS) { 13283859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 13296512Ssowmini "ddi_map_regs for nxge vio2 reg failed")); 13303859Sml29623 goto nxge_map_regs_fail3; 13313859Sml29623 } 13323859Sml29623 nxgep->dev_regs = dev_regs; 13333859Sml29623 13343859Sml29623 NPI_ACC_HANDLE_SET(nxgep, dev_regs->nxge_regh); 13353859Sml29623 NPI_ADD_HANDLE_SET(nxgep, (npi_reg_ptr_t)dev_regs->nxge_regp); 13363859Sml29623 13373859Sml29623 NPI_REG_ACC_HANDLE_SET(nxgep, dev_regs->nxge_regh); 13383859Sml29623 NPI_REG_ADD_HANDLE_SET(nxgep, 13396512Ssowmini (npi_reg_ptr_t)dev_regs->nxge_regp); 13403859Sml29623 13413859Sml29623 NPI_VREG_ACC_HANDLE_SET(nxgep, dev_regs->nxge_vir_regh); 13423859Sml29623 NPI_VREG_ADD_HANDLE_SET(nxgep, 13436512Ssowmini (npi_reg_ptr_t)dev_regs->nxge_vir_regp); 13443859Sml29623 13453859Sml29623 NPI_V2REG_ACC_HANDLE_SET(nxgep, dev_regs->nxge_vir2_regh); 13463859Sml29623 NPI_V2REG_ADD_HANDLE_SET(nxgep, 13476512Ssowmini (npi_reg_ptr_t)dev_regs->nxge_vir2_regp); 13483859Sml29623 13493859Sml29623 break; 13503859Sml29623 } 13513859Sml29623 13523859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "nxge_map_reg: hardware addr 0x%0llx " 13536512Ssowmini " handle 0x%0llx", dev_regs->nxge_regp, dev_regs->nxge_regh)); 13543859Sml29623 13553859Sml29623 goto nxge_map_regs_exit; 13563859Sml29623 nxge_map_regs_fail3: 13573859Sml29623 if (dev_regs->nxge_msix_regh) { 13583859Sml29623 ddi_regs_map_free(&dev_regs->nxge_msix_regh); 13593859Sml29623 } 13603859Sml29623 if (dev_regs->nxge_vir_regh) { 13613859Sml29623 ddi_regs_map_free(&dev_regs->nxge_regh); 13623859Sml29623 } 13633859Sml29623 nxge_map_regs_fail2: 13643859Sml29623 if (dev_regs->nxge_regh) { 13653859Sml29623 ddi_regs_map_free(&dev_regs->nxge_regh); 13663859Sml29623 } 13673859Sml29623 nxge_map_regs_fail1: 13683859Sml29623 if (dev_regs->nxge_pciregh) { 13693859Sml29623 ddi_regs_map_free(&dev_regs->nxge_pciregh); 13703859Sml29623 } 13713859Sml29623 nxge_map_regs_fail0: 13723859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "Freeing register set memory")); 13733859Sml29623 kmem_free(dev_regs, sizeof (dev_regs_t)); 13743859Sml29623 13753859Sml29623 nxge_map_regs_exit: 13763859Sml29623 if (ddi_status != DDI_SUCCESS) 13773859Sml29623 status |= (NXGE_ERROR | NXGE_DDI_FAILED); 13783859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_map_regs")); 13793859Sml29623 return (status); 13803859Sml29623 } 13813859Sml29623 13823859Sml29623 static void 13833859Sml29623 nxge_unmap_regs(p_nxge_t nxgep) 13843859Sml29623 { 13853859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_unmap_regs")); 13866495Sspeer 13876495Sspeer if (isLDOMguest(nxgep)) { 13886495Sspeer nxge_guest_regs_map_free(nxgep); 13896495Sspeer return; 13906495Sspeer } 13916495Sspeer 13923859Sml29623 if (nxgep->dev_regs) { 13933859Sml29623 if (nxgep->dev_regs->nxge_pciregh) { 13943859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 13956512Ssowmini "==> nxge_unmap_regs: bus")); 13963859Sml29623 ddi_regs_map_free(&nxgep->dev_regs->nxge_pciregh); 13973859Sml29623 nxgep->dev_regs->nxge_pciregh = NULL; 13983859Sml29623 } 13993859Sml29623 if (nxgep->dev_regs->nxge_regh) { 14003859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 14016512Ssowmini "==> nxge_unmap_regs: device registers")); 14023859Sml29623 ddi_regs_map_free(&nxgep->dev_regs->nxge_regh); 14033859Sml29623 nxgep->dev_regs->nxge_regh = NULL; 14043859Sml29623 } 14053859Sml29623 if (nxgep->dev_regs->nxge_msix_regh) { 14063859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 14076512Ssowmini "==> nxge_unmap_regs: device interrupts")); 14083859Sml29623 ddi_regs_map_free(&nxgep->dev_regs->nxge_msix_regh); 14093859Sml29623 nxgep->dev_regs->nxge_msix_regh = NULL; 14103859Sml29623 } 14113859Sml29623 if (nxgep->dev_regs->nxge_vir_regh) { 14123859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 14136512Ssowmini "==> nxge_unmap_regs: vio region")); 14143859Sml29623 ddi_regs_map_free(&nxgep->dev_regs->nxge_vir_regh); 14153859Sml29623 nxgep->dev_regs->nxge_vir_regh = NULL; 14163859Sml29623 } 14173859Sml29623 if (nxgep->dev_regs->nxge_vir2_regh) { 14183859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 14196512Ssowmini "==> nxge_unmap_regs: vio2 region")); 14203859Sml29623 ddi_regs_map_free(&nxgep->dev_regs->nxge_vir2_regh); 14213859Sml29623 nxgep->dev_regs->nxge_vir2_regh = NULL; 14223859Sml29623 } 14233859Sml29623 14243859Sml29623 kmem_free(nxgep->dev_regs, sizeof (dev_regs_t)); 14253859Sml29623 nxgep->dev_regs = NULL; 14263859Sml29623 } 14273859Sml29623 14283859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_unmap_regs")); 14293859Sml29623 } 14303859Sml29623 14313859Sml29623 static nxge_status_t 14323859Sml29623 nxge_setup_mutexes(p_nxge_t nxgep) 14333859Sml29623 { 14343859Sml29623 int ddi_status = DDI_SUCCESS; 14353859Sml29623 nxge_status_t status = NXGE_OK; 14363859Sml29623 nxge_classify_t *classify_ptr; 14373859Sml29623 int partition; 14383859Sml29623 14393859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_setup_mutexes")); 14403859Sml29623 14413859Sml29623 /* 14423859Sml29623 * Get the interrupt cookie so the mutexes can be 14433859Sml29623 * Initialized. 14443859Sml29623 */ 14456495Sspeer if (isLDOMguest(nxgep)) { 14466495Sspeer nxgep->interrupt_cookie = 0; 14476495Sspeer } else { 14486495Sspeer ddi_status = ddi_get_iblock_cookie(nxgep->dip, 0, 14496495Sspeer &nxgep->interrupt_cookie); 14506495Sspeer 14516495Sspeer if (ddi_status != DDI_SUCCESS) { 14526495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 14536495Sspeer "<== nxge_setup_mutexes: failed 0x%x", 14546495Sspeer ddi_status)); 14556495Sspeer goto nxge_setup_mutexes_exit; 14566495Sspeer } 14573859Sml29623 } 14583859Sml29623 14594693Stm144005 cv_init(&nxgep->poll_cv, NULL, CV_DRIVER, NULL); 14604693Stm144005 MUTEX_INIT(&nxgep->poll_lock, NULL, 14614693Stm144005 MUTEX_DRIVER, (void *)nxgep->interrupt_cookie); 14624693Stm144005 14633859Sml29623 /* 14644693Stm144005 * Initialize mutexes for this device. 14653859Sml29623 */ 14663859Sml29623 MUTEX_INIT(nxgep->genlock, NULL, 14676512Ssowmini MUTEX_DRIVER, (void *)nxgep->interrupt_cookie); 14683859Sml29623 MUTEX_INIT(&nxgep->ouraddr_lock, NULL, 14696512Ssowmini MUTEX_DRIVER, (void *)nxgep->interrupt_cookie); 14703859Sml29623 MUTEX_INIT(&nxgep->mif_lock, NULL, 14716512Ssowmini MUTEX_DRIVER, (void *)nxgep->interrupt_cookie); 14726495Sspeer MUTEX_INIT(&nxgep->group_lock, NULL, 14736495Sspeer MUTEX_DRIVER, (void *)nxgep->interrupt_cookie); 14743859Sml29623 RW_INIT(&nxgep->filter_lock, NULL, 14756512Ssowmini RW_DRIVER, (void *)nxgep->interrupt_cookie); 14763859Sml29623 14773859Sml29623 classify_ptr = &nxgep->classifier; 14783859Sml29623 /* 14793859Sml29623 * FFLP Mutexes are never used in interrupt context 14803859Sml29623 * as fflp operation can take very long time to 14813859Sml29623 * complete and hence not suitable to invoke from interrupt 14823859Sml29623 * handlers. 14833859Sml29623 */ 14843859Sml29623 MUTEX_INIT(&classify_ptr->tcam_lock, NULL, 14854732Sdavemq NXGE_MUTEX_DRIVER, (void *)nxgep->interrupt_cookie); 14864977Sraghus if (NXGE_IS_VALID_NEPTUNE_TYPE(nxgep)) { 14873859Sml29623 MUTEX_INIT(&classify_ptr->fcram_lock, NULL, 14884732Sdavemq NXGE_MUTEX_DRIVER, (void *)nxgep->interrupt_cookie); 14893859Sml29623 for (partition = 0; partition < MAX_PARTITION; partition++) { 14903859Sml29623 MUTEX_INIT(&classify_ptr->hash_lock[partition], NULL, 14913859Sml29623 NXGE_MUTEX_DRIVER, (void *)nxgep->interrupt_cookie); 14923859Sml29623 } 14933859Sml29623 } 14943859Sml29623 14953859Sml29623 nxge_setup_mutexes_exit: 14963859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 14974732Sdavemq "<== nxge_setup_mutexes status = %x", status)); 14983859Sml29623 14993859Sml29623 if (ddi_status != DDI_SUCCESS) 15003859Sml29623 status |= (NXGE_ERROR | NXGE_DDI_FAILED); 15013859Sml29623 15023859Sml29623 return (status); 15033859Sml29623 } 15043859Sml29623 15053859Sml29623 static void 15063859Sml29623 nxge_destroy_mutexes(p_nxge_t nxgep) 15073859Sml29623 { 15083859Sml29623 int partition; 15093859Sml29623 nxge_classify_t *classify_ptr; 15103859Sml29623 15113859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_destroy_mutexes")); 15123859Sml29623 RW_DESTROY(&nxgep->filter_lock); 15136495Sspeer MUTEX_DESTROY(&nxgep->group_lock); 15143859Sml29623 MUTEX_DESTROY(&nxgep->mif_lock); 15153859Sml29623 MUTEX_DESTROY(&nxgep->ouraddr_lock); 15163859Sml29623 MUTEX_DESTROY(nxgep->genlock); 15173859Sml29623 15183859Sml29623 classify_ptr = &nxgep->classifier; 15193859Sml29623 MUTEX_DESTROY(&classify_ptr->tcam_lock); 15203859Sml29623 15214693Stm144005 /* Destroy all polling resources. */ 15224693Stm144005 MUTEX_DESTROY(&nxgep->poll_lock); 15234693Stm144005 cv_destroy(&nxgep->poll_cv); 15244693Stm144005 15254693Stm144005 /* free data structures, based on HW type */ 15264977Sraghus if (NXGE_IS_VALID_NEPTUNE_TYPE(nxgep)) { 15273859Sml29623 MUTEX_DESTROY(&classify_ptr->fcram_lock); 15283859Sml29623 for (partition = 0; partition < MAX_PARTITION; partition++) { 15293859Sml29623 MUTEX_DESTROY(&classify_ptr->hash_lock[partition]); 15303859Sml29623 } 15313859Sml29623 } 15323859Sml29623 15333859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_destroy_mutexes")); 15343859Sml29623 } 15353859Sml29623 15363859Sml29623 nxge_status_t 15373859Sml29623 nxge_init(p_nxge_t nxgep) 15383859Sml29623 { 15396495Sspeer nxge_status_t status = NXGE_OK; 15403859Sml29623 15413859Sml29623 NXGE_DEBUG_MSG((nxgep, STR_CTL, "==> nxge_init")); 15423859Sml29623 15433859Sml29623 if (nxgep->drv_state & STATE_HW_INITIALIZED) { 15443859Sml29623 return (status); 15453859Sml29623 } 15463859Sml29623 15473859Sml29623 /* 15483859Sml29623 * Allocate system memory for the receive/transmit buffer blocks 15493859Sml29623 * and receive/transmit descriptor rings. 15503859Sml29623 */ 15513859Sml29623 status = nxge_alloc_mem_pool(nxgep); 15523859Sml29623 if (status != NXGE_OK) { 15533859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "alloc mem failed\n")); 15543859Sml29623 goto nxge_init_fail1; 15553859Sml29623 } 15563859Sml29623 15576495Sspeer if (!isLDOMguest(nxgep)) { 15586495Sspeer /* 15596495Sspeer * Initialize and enable the TXC registers. 15606495Sspeer * (Globally enable the Tx controller, 15616495Sspeer * enable the port, configure the dma channel bitmap, 15626495Sspeer * configure the max burst size). 15636495Sspeer */ 15646495Sspeer status = nxge_txc_init(nxgep); 15656495Sspeer if (status != NXGE_OK) { 15666495Sspeer NXGE_ERROR_MSG((nxgep, 15676495Sspeer NXGE_ERR_CTL, "init txc failed\n")); 15686495Sspeer goto nxge_init_fail2; 15696495Sspeer } 15703859Sml29623 } 15713859Sml29623 15723859Sml29623 /* 15733859Sml29623 * Initialize and enable TXDMA channels. 15743859Sml29623 */ 15753859Sml29623 status = nxge_init_txdma_channels(nxgep); 15763859Sml29623 if (status != NXGE_OK) { 15773859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "init txdma failed\n")); 15783859Sml29623 goto nxge_init_fail3; 15793859Sml29623 } 15803859Sml29623 15813859Sml29623 /* 15823859Sml29623 * Initialize and enable RXDMA channels. 15833859Sml29623 */ 15843859Sml29623 status = nxge_init_rxdma_channels(nxgep); 15853859Sml29623 if (status != NXGE_OK) { 15863859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "init rxdma failed\n")); 15873859Sml29623 goto nxge_init_fail4; 15883859Sml29623 } 15893859Sml29623 15903859Sml29623 /* 15916495Sspeer * The guest domain is now done. 15926495Sspeer */ 15936495Sspeer if (isLDOMguest(nxgep)) { 15946495Sspeer nxgep->drv_state |= STATE_HW_INITIALIZED; 15956495Sspeer goto nxge_init_exit; 15966495Sspeer } 15976495Sspeer 15986495Sspeer /* 15993859Sml29623 * Initialize TCAM and FCRAM (Neptune). 16003859Sml29623 */ 16013859Sml29623 status = nxge_classify_init(nxgep); 16023859Sml29623 if (status != NXGE_OK) { 16033859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "init classify failed\n")); 16043859Sml29623 goto nxge_init_fail5; 16053859Sml29623 } 16063859Sml29623 16073859Sml29623 /* 16083859Sml29623 * Initialize ZCP 16093859Sml29623 */ 16103859Sml29623 status = nxge_zcp_init(nxgep); 16113859Sml29623 if (status != NXGE_OK) { 16123859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "init ZCP failed\n")); 16133859Sml29623 goto nxge_init_fail5; 16143859Sml29623 } 16153859Sml29623 16163859Sml29623 /* 16173859Sml29623 * Initialize IPP. 16183859Sml29623 */ 16193859Sml29623 status = nxge_ipp_init(nxgep); 16203859Sml29623 if (status != NXGE_OK) { 16213859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "init IPP failed\n")); 16223859Sml29623 goto nxge_init_fail5; 16233859Sml29623 } 16243859Sml29623 16253859Sml29623 /* 16263859Sml29623 * Initialize the MAC block. 16273859Sml29623 */ 16283859Sml29623 status = nxge_mac_init(nxgep); 16293859Sml29623 if (status != NXGE_OK) { 16303859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "init MAC failed\n")); 16313859Sml29623 goto nxge_init_fail5; 16323859Sml29623 } 16333859Sml29623 16343859Sml29623 /* 16359232SMichael.Speer@Sun.COM * Enable the interrrupts for DDI. 16363859Sml29623 */ 16379232SMichael.Speer@Sun.COM nxge_intrs_enable(nxgep); 16389232SMichael.Speer@Sun.COM 16393859Sml29623 nxgep->drv_state |= STATE_HW_INITIALIZED; 16403859Sml29623 16413859Sml29623 goto nxge_init_exit; 16423859Sml29623 16433859Sml29623 nxge_init_fail5: 16443859Sml29623 nxge_uninit_rxdma_channels(nxgep); 16453859Sml29623 nxge_init_fail4: 16463859Sml29623 nxge_uninit_txdma_channels(nxgep); 16473859Sml29623 nxge_init_fail3: 16486495Sspeer if (!isLDOMguest(nxgep)) { 16496495Sspeer (void) nxge_txc_uninit(nxgep); 16506495Sspeer } 16513859Sml29623 nxge_init_fail2: 16523859Sml29623 nxge_free_mem_pool(nxgep); 16533859Sml29623 nxge_init_fail1: 16543859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 16556512Ssowmini "<== nxge_init status (failed) = 0x%08x", status)); 16563859Sml29623 return (status); 16573859Sml29623 16583859Sml29623 nxge_init_exit: 16593859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_init status = 0x%08x", 16606512Ssowmini status)); 16613859Sml29623 return (status); 16623859Sml29623 } 16633859Sml29623 16643859Sml29623 16653859Sml29623 timeout_id_t 16663859Sml29623 nxge_start_timer(p_nxge_t nxgep, fptrv_t func, int msec) 16673859Sml29623 { 16686512Ssowmini if ((nxgep->suspended == 0) || (nxgep->suspended == DDI_RESUME)) { 16693859Sml29623 return (timeout(func, (caddr_t)nxgep, 16706512Ssowmini drv_usectohz(1000 * msec))); 16713859Sml29623 } 16723859Sml29623 return (NULL); 16733859Sml29623 } 16743859Sml29623 16753859Sml29623 /*ARGSUSED*/ 16763859Sml29623 void 16773859Sml29623 nxge_stop_timer(p_nxge_t nxgep, timeout_id_t timerid) 16783859Sml29623 { 16793859Sml29623 if (timerid) { 16803859Sml29623 (void) untimeout(timerid); 16813859Sml29623 } 16823859Sml29623 } 16833859Sml29623 16843859Sml29623 void 16853859Sml29623 nxge_uninit(p_nxge_t nxgep) 16863859Sml29623 { 16873859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_uninit")); 16883859Sml29623 16893859Sml29623 if (!(nxgep->drv_state & STATE_HW_INITIALIZED)) { 16903859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 16916512Ssowmini "==> nxge_uninit: not initialized")); 16923859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 16936512Ssowmini "<== nxge_uninit")); 16943859Sml29623 return; 16953859Sml29623 } 16963859Sml29623 16979232SMichael.Speer@Sun.COM if (!isLDOMguest(nxgep)) { 16989232SMichael.Speer@Sun.COM /* 16999232SMichael.Speer@Sun.COM * Reset the receive MAC side. 17009232SMichael.Speer@Sun.COM */ 17019232SMichael.Speer@Sun.COM (void) nxge_rx_mac_disable(nxgep); 17029232SMichael.Speer@Sun.COM 17039232SMichael.Speer@Sun.COM /* 17049232SMichael.Speer@Sun.COM * Drain the IPP. 17059232SMichael.Speer@Sun.COM */ 17069232SMichael.Speer@Sun.COM (void) nxge_ipp_drain(nxgep); 17079232SMichael.Speer@Sun.COM } 17089232SMichael.Speer@Sun.COM 17093859Sml29623 /* stop timer */ 17103859Sml29623 if (nxgep->nxge_timerid) { 17113859Sml29623 nxge_stop_timer(nxgep, nxgep->nxge_timerid); 17123859Sml29623 nxgep->nxge_timerid = 0; 17133859Sml29623 } 17143859Sml29623 17153859Sml29623 (void) nxge_link_monitor(nxgep, LINK_MONITOR_STOP); 17163859Sml29623 (void) nxge_intr_hw_disable(nxgep); 17173859Sml29623 17183859Sml29623 17193859Sml29623 /* Disable and soft reset the IPP */ 17206495Sspeer if (!isLDOMguest(nxgep)) 17216495Sspeer (void) nxge_ipp_disable(nxgep); 17223859Sml29623 17233859Sml29623 /* Free classification resources */ 17243859Sml29623 (void) nxge_classify_uninit(nxgep); 17253859Sml29623 17263859Sml29623 /* 17273859Sml29623 * Reset the transmit/receive DMA side. 17283859Sml29623 */ 17293859Sml29623 (void) nxge_txdma_hw_mode(nxgep, NXGE_DMA_STOP); 17303859Sml29623 (void) nxge_rxdma_hw_mode(nxgep, NXGE_DMA_STOP); 17313859Sml29623 17323859Sml29623 nxge_uninit_txdma_channels(nxgep); 17333859Sml29623 nxge_uninit_rxdma_channels(nxgep); 17343859Sml29623 17353859Sml29623 /* 17363859Sml29623 * Reset the transmit MAC side. 17373859Sml29623 */ 17383859Sml29623 (void) nxge_tx_mac_disable(nxgep); 17393859Sml29623 17403859Sml29623 nxge_free_mem_pool(nxgep); 17413859Sml29623 17426705Sml29623 /* 17436705Sml29623 * Start the timer if the reset flag is not set. 17446705Sml29623 * If this reset flag is set, the link monitor 17456705Sml29623 * will not be started in order to stop furthur bus 17466705Sml29623 * activities coming from this interface. 17476705Sml29623 * The driver will start the monitor function 17486705Sml29623 * if the interface was initialized again later. 17496705Sml29623 */ 17506705Sml29623 if (!nxge_peu_reset_enable) { 17516705Sml29623 (void) nxge_link_monitor(nxgep, LINK_MONITOR_START); 17526705Sml29623 } 17533859Sml29623 17543859Sml29623 nxgep->drv_state &= ~STATE_HW_INITIALIZED; 17553859Sml29623 17563859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_uninit: " 17576512Ssowmini "nxge_mblks_pending %d", nxge_mblks_pending)); 17583859Sml29623 } 17593859Sml29623 17603859Sml29623 void 17613859Sml29623 nxge_get64(p_nxge_t nxgep, p_mblk_t mp) 17623859Sml29623 { 17633859Sml29623 uint64_t reg; 17643859Sml29623 uint64_t regdata; 17653859Sml29623 int i, retry; 17663859Sml29623 17673859Sml29623 bcopy((char *)mp->b_rptr, (char *)®, sizeof (uint64_t)); 17683859Sml29623 regdata = 0; 17693859Sml29623 retry = 1; 17703859Sml29623 17713859Sml29623 for (i = 0; i < retry; i++) { 17723859Sml29623 NXGE_REG_RD64(nxgep->npi_handle, reg, ®data); 17733859Sml29623 } 17743859Sml29623 bcopy((char *)®data, (char *)mp->b_rptr, sizeof (uint64_t)); 17753859Sml29623 } 17763859Sml29623 17773859Sml29623 void 17783859Sml29623 nxge_put64(p_nxge_t nxgep, p_mblk_t mp) 17793859Sml29623 { 17803859Sml29623 uint64_t reg; 17813859Sml29623 uint64_t buf[2]; 17823859Sml29623 17833859Sml29623 bcopy((char *)mp->b_rptr, (char *)&buf[0], 2 * sizeof (uint64_t)); 17843859Sml29623 reg = buf[0]; 17853859Sml29623 17863859Sml29623 NXGE_NPI_PIO_WRITE64(nxgep->npi_handle, reg, buf[1]); 17873859Sml29623 } 17883859Sml29623 17893859Sml29623 17903859Sml29623 nxge_os_mutex_t nxgedebuglock; 17913859Sml29623 int nxge_debug_init = 0; 17923859Sml29623 17933859Sml29623 /*ARGSUSED*/ 17943859Sml29623 /*VARARGS*/ 17953859Sml29623 void 17963859Sml29623 nxge_debug_msg(p_nxge_t nxgep, uint64_t level, char *fmt, ...) 17973859Sml29623 { 17983859Sml29623 char msg_buffer[1048]; 17993859Sml29623 char prefix_buffer[32]; 18003859Sml29623 int instance; 18013859Sml29623 uint64_t debug_level; 18023859Sml29623 int cmn_level = CE_CONT; 18033859Sml29623 va_list ap; 18043859Sml29623 18056495Sspeer if (nxgep && nxgep->nxge_debug_level != nxge_debug_level) { 18066495Sspeer /* In case a developer has changed nxge_debug_level. */ 18076495Sspeer if (nxgep->nxge_debug_level != nxge_debug_level) 18086495Sspeer nxgep->nxge_debug_level = nxge_debug_level; 18096495Sspeer } 18106495Sspeer 18113859Sml29623 debug_level = (nxgep == NULL) ? nxge_debug_level : 18126512Ssowmini nxgep->nxge_debug_level; 18133859Sml29623 18143859Sml29623 if ((level & debug_level) || 18156512Ssowmini (level == NXGE_NOTE) || 18166512Ssowmini (level == NXGE_ERR_CTL)) { 18173859Sml29623 /* do the msg processing */ 18183859Sml29623 if (nxge_debug_init == 0) { 18193859Sml29623 MUTEX_INIT(&nxgedebuglock, NULL, MUTEX_DRIVER, NULL); 18203859Sml29623 nxge_debug_init = 1; 18213859Sml29623 } 18223859Sml29623 18233859Sml29623 MUTEX_ENTER(&nxgedebuglock); 18243859Sml29623 18253859Sml29623 if ((level & NXGE_NOTE)) { 18263859Sml29623 cmn_level = CE_NOTE; 18273859Sml29623 } 18283859Sml29623 18293859Sml29623 if (level & NXGE_ERR_CTL) { 18303859Sml29623 cmn_level = CE_WARN; 18313859Sml29623 } 18323859Sml29623 18333859Sml29623 va_start(ap, fmt); 18343859Sml29623 (void) vsprintf(msg_buffer, fmt, ap); 18353859Sml29623 va_end(ap); 18363859Sml29623 if (nxgep == NULL) { 18373859Sml29623 instance = -1; 18383859Sml29623 (void) sprintf(prefix_buffer, "%s :", "nxge"); 18393859Sml29623 } else { 18403859Sml29623 instance = nxgep->instance; 18413859Sml29623 (void) sprintf(prefix_buffer, 18426512Ssowmini "%s%d :", "nxge", instance); 18433859Sml29623 } 18443859Sml29623 18453859Sml29623 MUTEX_EXIT(&nxgedebuglock); 18463859Sml29623 cmn_err(cmn_level, "!%s %s\n", 18476512Ssowmini prefix_buffer, msg_buffer); 18483859Sml29623 18493859Sml29623 } 18503859Sml29623 } 18513859Sml29623 18523859Sml29623 char * 18533859Sml29623 nxge_dump_packet(char *addr, int size) 18543859Sml29623 { 18553859Sml29623 uchar_t *ap = (uchar_t *)addr; 18563859Sml29623 int i; 18573859Sml29623 static char etherbuf[1024]; 18583859Sml29623 char *cp = etherbuf; 18593859Sml29623 char digits[] = "0123456789abcdef"; 18603859Sml29623 18613859Sml29623 if (!size) 18623859Sml29623 size = 60; 18633859Sml29623 18643859Sml29623 if (size > MAX_DUMP_SZ) { 18653859Sml29623 /* Dump the leading bytes */ 18663859Sml29623 for (i = 0; i < MAX_DUMP_SZ/2; i++) { 18673859Sml29623 if (*ap > 0x0f) 18683859Sml29623 *cp++ = digits[*ap >> 4]; 18693859Sml29623 *cp++ = digits[*ap++ & 0xf]; 18703859Sml29623 *cp++ = ':'; 18713859Sml29623 } 18723859Sml29623 for (i = 0; i < 20; i++) 18733859Sml29623 *cp++ = '.'; 18743859Sml29623 /* Dump the last MAX_DUMP_SZ/2 bytes */ 18753859Sml29623 ap = (uchar_t *)(addr + (size - MAX_DUMP_SZ/2)); 18763859Sml29623 for (i = 0; i < MAX_DUMP_SZ/2; i++) { 18773859Sml29623 if (*ap > 0x0f) 18783859Sml29623 *cp++ = digits[*ap >> 4]; 18793859Sml29623 *cp++ = digits[*ap++ & 0xf]; 18803859Sml29623 *cp++ = ':'; 18813859Sml29623 } 18823859Sml29623 } else { 18833859Sml29623 for (i = 0; i < size; i++) { 18843859Sml29623 if (*ap > 0x0f) 18853859Sml29623 *cp++ = digits[*ap >> 4]; 18863859Sml29623 *cp++ = digits[*ap++ & 0xf]; 18873859Sml29623 *cp++ = ':'; 18883859Sml29623 } 18893859Sml29623 } 18903859Sml29623 *--cp = 0; 18913859Sml29623 return (etherbuf); 18923859Sml29623 } 18933859Sml29623 18943859Sml29623 #ifdef NXGE_DEBUG 18953859Sml29623 static void 18963859Sml29623 nxge_test_map_regs(p_nxge_t nxgep) 18973859Sml29623 { 18983859Sml29623 ddi_acc_handle_t cfg_handle; 18993859Sml29623 p_pci_cfg_t cfg_ptr; 19003859Sml29623 ddi_acc_handle_t dev_handle; 19013859Sml29623 char *dev_ptr; 19023859Sml29623 ddi_acc_handle_t pci_config_handle; 19033859Sml29623 uint32_t regval; 19043859Sml29623 int i; 19053859Sml29623 19063859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_test_map_regs")); 19073859Sml29623 19083859Sml29623 dev_handle = nxgep->dev_regs->nxge_regh; 19093859Sml29623 dev_ptr = (char *)nxgep->dev_regs->nxge_regp; 19103859Sml29623 19114977Sraghus if (NXGE_IS_VALID_NEPTUNE_TYPE(nxgep)) { 19123859Sml29623 cfg_handle = nxgep->dev_regs->nxge_pciregh; 19133859Sml29623 cfg_ptr = (void *)nxgep->dev_regs->nxge_pciregp; 19143859Sml29623 19153859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 19164732Sdavemq "Neptune PCI regp cfg_ptr 0x%llx", (char *)cfg_ptr)); 19173859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 19184732Sdavemq "Neptune PCI cfg_ptr vendor id ptr 0x%llx", 19194732Sdavemq &cfg_ptr->vendorid)); 19203859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 19214732Sdavemq "\tvendorid 0x%x devid 0x%x", 19224732Sdavemq NXGE_PIO_READ16(cfg_handle, &cfg_ptr->vendorid, 0), 19234732Sdavemq NXGE_PIO_READ16(cfg_handle, &cfg_ptr->devid, 0))); 19243859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 19254732Sdavemq "PCI BAR: base 0x%x base14 0x%x base 18 0x%x " 19264732Sdavemq "bar1c 0x%x", 19274732Sdavemq NXGE_PIO_READ32(cfg_handle, &cfg_ptr->base, 0), 19284732Sdavemq NXGE_PIO_READ32(cfg_handle, &cfg_ptr->base14, 0), 19294732Sdavemq NXGE_PIO_READ32(cfg_handle, &cfg_ptr->base18, 0), 19304732Sdavemq NXGE_PIO_READ32(cfg_handle, &cfg_ptr->base1c, 0))); 19313859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 19324732Sdavemq "\nNeptune PCI BAR: base20 0x%x base24 0x%x " 19334732Sdavemq "base 28 0x%x bar2c 0x%x\n", 19344732Sdavemq NXGE_PIO_READ32(cfg_handle, &cfg_ptr->base20, 0), 19354732Sdavemq NXGE_PIO_READ32(cfg_handle, &cfg_ptr->base24, 0), 19364732Sdavemq NXGE_PIO_READ32(cfg_handle, &cfg_ptr->base28, 0), 19374732Sdavemq NXGE_PIO_READ32(cfg_handle, &cfg_ptr->base2c, 0))); 19383859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 19394732Sdavemq "\nNeptune PCI BAR: base30 0x%x\n", 19404732Sdavemq NXGE_PIO_READ32(cfg_handle, &cfg_ptr->base30, 0))); 19413859Sml29623 19423859Sml29623 cfg_handle = nxgep->dev_regs->nxge_pciregh; 19433859Sml29623 cfg_ptr = (void *)nxgep->dev_regs->nxge_pciregp; 19443859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 19454732Sdavemq "first 0x%llx second 0x%llx third 0x%llx " 19464732Sdavemq "last 0x%llx ", 19474732Sdavemq NXGE_PIO_READ64(dev_handle, 19484732Sdavemq (uint64_t *)(dev_ptr + 0), 0), 19494732Sdavemq NXGE_PIO_READ64(dev_handle, 19504732Sdavemq (uint64_t *)(dev_ptr + 8), 0), 19514732Sdavemq NXGE_PIO_READ64(dev_handle, 19524732Sdavemq (uint64_t *)(dev_ptr + 16), 0), 19534732Sdavemq NXGE_PIO_READ64(cfg_handle, 19544732Sdavemq (uint64_t *)(dev_ptr + 24), 0))); 19553859Sml29623 } 19563859Sml29623 } 19573859Sml29623 19583859Sml29623 #endif 19593859Sml29623 19603859Sml29623 static void 19613859Sml29623 nxge_suspend(p_nxge_t nxgep) 19623859Sml29623 { 19633859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_suspend")); 19643859Sml29623 19653859Sml29623 nxge_intrs_disable(nxgep); 19663859Sml29623 nxge_destroy_dev(nxgep); 19673859Sml29623 19683859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_suspend")); 19693859Sml29623 } 19703859Sml29623 19713859Sml29623 static nxge_status_t 19723859Sml29623 nxge_resume(p_nxge_t nxgep) 19733859Sml29623 { 19743859Sml29623 nxge_status_t status = NXGE_OK; 19753859Sml29623 19763859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_resume")); 19774587Sjoycey 19783859Sml29623 nxgep->suspended = DDI_RESUME; 19794587Sjoycey (void) nxge_link_monitor(nxgep, LINK_MONITOR_START); 19804587Sjoycey (void) nxge_rxdma_hw_mode(nxgep, NXGE_DMA_START); 19814587Sjoycey (void) nxge_txdma_hw_mode(nxgep, NXGE_DMA_START); 19824587Sjoycey (void) nxge_rx_mac_enable(nxgep); 19834587Sjoycey (void) nxge_tx_mac_enable(nxgep); 19844587Sjoycey nxge_intrs_enable(nxgep); 19853859Sml29623 nxgep->suspended = 0; 19863859Sml29623 19873859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 19886512Ssowmini "<== nxge_resume status = 0x%x", status)); 19893859Sml29623 return (status); 19903859Sml29623 } 19913859Sml29623 19923859Sml29623 static nxge_status_t 19933859Sml29623 nxge_setup_dev(p_nxge_t nxgep) 19943859Sml29623 { 19953859Sml29623 nxge_status_t status = NXGE_OK; 19963859Sml29623 19973859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_setup_dev port %d", 19984732Sdavemq nxgep->mac.portnum)); 19993859Sml29623 20003859Sml29623 status = nxge_link_init(nxgep); 20013859Sml29623 20023859Sml29623 if (fm_check_acc_handle(nxgep->dev_regs->nxge_regh) != DDI_FM_OK) { 20033859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 20046512Ssowmini "port%d Bad register acc handle", nxgep->mac.portnum)); 20053859Sml29623 status = NXGE_ERROR; 20063859Sml29623 } 20073859Sml29623 20083859Sml29623 if (status != NXGE_OK) { 20093859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 20106512Ssowmini " nxge_setup_dev status " 20116512Ssowmini "(xcvr init 0x%08x)", status)); 20123859Sml29623 goto nxge_setup_dev_exit; 20133859Sml29623 } 20143859Sml29623 20153859Sml29623 nxge_setup_dev_exit: 20163859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 20176512Ssowmini "<== nxge_setup_dev port %d status = 0x%08x", 20186512Ssowmini nxgep->mac.portnum, status)); 20193859Sml29623 20203859Sml29623 return (status); 20213859Sml29623 } 20223859Sml29623 20233859Sml29623 static void 20243859Sml29623 nxge_destroy_dev(p_nxge_t nxgep) 20253859Sml29623 { 20263859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_destroy_dev")); 20273859Sml29623 20283859Sml29623 (void) nxge_link_monitor(nxgep, LINK_MONITOR_STOP); 20293859Sml29623 20303859Sml29623 (void) nxge_hw_stop(nxgep); 20313859Sml29623 20323859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_destroy_dev")); 20333859Sml29623 } 20343859Sml29623 20353859Sml29623 static nxge_status_t 20363859Sml29623 nxge_setup_system_dma_pages(p_nxge_t nxgep) 20373859Sml29623 { 20383859Sml29623 int ddi_status = DDI_SUCCESS; 20393859Sml29623 uint_t count; 20403859Sml29623 ddi_dma_cookie_t cookie; 20413859Sml29623 uint_t iommu_pagesize; 20423859Sml29623 nxge_status_t status = NXGE_OK; 20433859Sml29623 20446495Sspeer NXGE_ERROR_MSG((nxgep, DDI_CTL, "==> nxge_setup_system_dma_pages")); 20453859Sml29623 nxgep->sys_page_sz = ddi_ptob(nxgep->dip, (ulong_t)1); 20463859Sml29623 if (nxgep->niu_type != N2_NIU) { 20473859Sml29623 iommu_pagesize = dvma_pagesize(nxgep->dip); 20483859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 20496512Ssowmini " nxge_setup_system_dma_pages: page %d (ddi_ptob %d) " 20506512Ssowmini " default_block_size %d iommu_pagesize %d", 20516512Ssowmini nxgep->sys_page_sz, 20526512Ssowmini ddi_ptob(nxgep->dip, (ulong_t)1), 20536512Ssowmini nxgep->rx_default_block_size, 20546512Ssowmini iommu_pagesize)); 20553859Sml29623 20563859Sml29623 if (iommu_pagesize != 0) { 20573859Sml29623 if (nxgep->sys_page_sz == iommu_pagesize) { 20583859Sml29623 if (iommu_pagesize > 0x4000) 20593859Sml29623 nxgep->sys_page_sz = 0x4000; 20603859Sml29623 } else { 20613859Sml29623 if (nxgep->sys_page_sz > iommu_pagesize) 20623859Sml29623 nxgep->sys_page_sz = iommu_pagesize; 20633859Sml29623 } 20643859Sml29623 } 20653859Sml29623 } 20663859Sml29623 nxgep->sys_page_mask = ~(nxgep->sys_page_sz - 1); 20673859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 20686512Ssowmini "==> nxge_setup_system_dma_pages: page %d (ddi_ptob %d) " 20696512Ssowmini "default_block_size %d page mask %d", 20706512Ssowmini nxgep->sys_page_sz, 20716512Ssowmini ddi_ptob(nxgep->dip, (ulong_t)1), 20726512Ssowmini nxgep->rx_default_block_size, 20736512Ssowmini nxgep->sys_page_mask)); 20743859Sml29623 20753859Sml29623 20763859Sml29623 switch (nxgep->sys_page_sz) { 20773859Sml29623 default: 20783859Sml29623 nxgep->sys_page_sz = 0x1000; 20793859Sml29623 nxgep->sys_page_mask = ~(nxgep->sys_page_sz - 1); 20803859Sml29623 nxgep->rx_default_block_size = 0x1000; 20813859Sml29623 nxgep->rx_bksize_code = RBR_BKSIZE_4K; 20823859Sml29623 break; 20833859Sml29623 case 0x1000: 20843859Sml29623 nxgep->rx_default_block_size = 0x1000; 20853859Sml29623 nxgep->rx_bksize_code = RBR_BKSIZE_4K; 20863859Sml29623 break; 20873859Sml29623 case 0x2000: 20883859Sml29623 nxgep->rx_default_block_size = 0x2000; 20893859Sml29623 nxgep->rx_bksize_code = RBR_BKSIZE_8K; 20903859Sml29623 break; 20913859Sml29623 case 0x4000: 20923859Sml29623 nxgep->rx_default_block_size = 0x4000; 20933859Sml29623 nxgep->rx_bksize_code = RBR_BKSIZE_16K; 20943859Sml29623 break; 20953859Sml29623 case 0x8000: 20963859Sml29623 nxgep->rx_default_block_size = 0x8000; 20973859Sml29623 nxgep->rx_bksize_code = RBR_BKSIZE_32K; 20983859Sml29623 break; 20993859Sml29623 } 21003859Sml29623 21013859Sml29623 #ifndef USE_RX_BIG_BUF 21023859Sml29623 nxge_rx_dma_attr.dma_attr_align = nxgep->sys_page_sz; 21033859Sml29623 #else 21043859Sml29623 nxgep->rx_default_block_size = 0x2000; 21053859Sml29623 nxgep->rx_bksize_code = RBR_BKSIZE_8K; 21063859Sml29623 #endif 21073859Sml29623 /* 21083859Sml29623 * Get the system DMA burst size. 21093859Sml29623 */ 21103859Sml29623 ddi_status = ddi_dma_alloc_handle(nxgep->dip, &nxge_tx_dma_attr, 21116512Ssowmini DDI_DMA_DONTWAIT, 0, 21126512Ssowmini &nxgep->dmasparehandle); 21133859Sml29623 if (ddi_status != DDI_SUCCESS) { 21143859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 21156512Ssowmini "ddi_dma_alloc_handle: failed " 21166512Ssowmini " status 0x%x", ddi_status)); 21173859Sml29623 goto nxge_get_soft_properties_exit; 21183859Sml29623 } 21193859Sml29623 21203859Sml29623 ddi_status = ddi_dma_addr_bind_handle(nxgep->dmasparehandle, NULL, 21216512Ssowmini (caddr_t)nxgep->dmasparehandle, 21226512Ssowmini sizeof (nxgep->dmasparehandle), 21236512Ssowmini DDI_DMA_RDWR | DDI_DMA_CONSISTENT, 21246512Ssowmini DDI_DMA_DONTWAIT, 0, 21256512Ssowmini &cookie, &count); 21263859Sml29623 if (ddi_status != DDI_DMA_MAPPED) { 21273859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 21286512Ssowmini "Binding spare handle to find system" 21296512Ssowmini " burstsize failed.")); 21303859Sml29623 ddi_status = DDI_FAILURE; 21313859Sml29623 goto nxge_get_soft_properties_fail1; 21323859Sml29623 } 21333859Sml29623 21343859Sml29623 nxgep->sys_burst_sz = ddi_dma_burstsizes(nxgep->dmasparehandle); 21353859Sml29623 (void) ddi_dma_unbind_handle(nxgep->dmasparehandle); 21363859Sml29623 21373859Sml29623 nxge_get_soft_properties_fail1: 21383859Sml29623 ddi_dma_free_handle(&nxgep->dmasparehandle); 21393859Sml29623 21403859Sml29623 nxge_get_soft_properties_exit: 21413859Sml29623 21423859Sml29623 if (ddi_status != DDI_SUCCESS) 21433859Sml29623 status |= (NXGE_ERROR | NXGE_DDI_FAILED); 21443859Sml29623 21453859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 21466512Ssowmini "<== nxge_setup_system_dma_pages status = 0x%08x", status)); 21473859Sml29623 return (status); 21483859Sml29623 } 21493859Sml29623 21503859Sml29623 static nxge_status_t 21513859Sml29623 nxge_alloc_mem_pool(p_nxge_t nxgep) 21523859Sml29623 { 21533859Sml29623 nxge_status_t status = NXGE_OK; 21543859Sml29623 21553859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_alloc_mem_pool")); 21563859Sml29623 21573859Sml29623 status = nxge_alloc_rx_mem_pool(nxgep); 21583859Sml29623 if (status != NXGE_OK) { 21593859Sml29623 return (NXGE_ERROR); 21603859Sml29623 } 21613859Sml29623 21623859Sml29623 status = nxge_alloc_tx_mem_pool(nxgep); 21633859Sml29623 if (status != NXGE_OK) { 21643859Sml29623 nxge_free_rx_mem_pool(nxgep); 21653859Sml29623 return (NXGE_ERROR); 21663859Sml29623 } 21673859Sml29623 21683859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_alloc_mem_pool")); 21693859Sml29623 return (NXGE_OK); 21703859Sml29623 } 21713859Sml29623 21723859Sml29623 static void 21733859Sml29623 nxge_free_mem_pool(p_nxge_t nxgep) 21743859Sml29623 { 21753859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM_CTL, "==> nxge_free_mem_pool")); 21763859Sml29623 21773859Sml29623 nxge_free_rx_mem_pool(nxgep); 21783859Sml29623 nxge_free_tx_mem_pool(nxgep); 21793859Sml29623 21803859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM_CTL, "<== nxge_free_mem_pool")); 21813859Sml29623 } 21823859Sml29623 21836495Sspeer nxge_status_t 21843859Sml29623 nxge_alloc_rx_mem_pool(p_nxge_t nxgep) 21853859Sml29623 { 21866495Sspeer uint32_t rdc_max; 21873859Sml29623 p_nxge_dma_pt_cfg_t p_all_cfgp; 21883859Sml29623 p_nxge_hw_pt_cfg_t p_cfgp; 21893859Sml29623 p_nxge_dma_pool_t dma_poolp; 21903859Sml29623 p_nxge_dma_common_t *dma_buf_p; 21913859Sml29623 p_nxge_dma_pool_t dma_cntl_poolp; 21923859Sml29623 p_nxge_dma_common_t *dma_cntl_p; 21933859Sml29623 uint32_t *num_chunks; /* per dma */ 21943859Sml29623 nxge_status_t status = NXGE_OK; 21953859Sml29623 21963859Sml29623 uint32_t nxge_port_rbr_size; 21973859Sml29623 uint32_t nxge_port_rbr_spare_size; 21983859Sml29623 uint32_t nxge_port_rcr_size; 21996495Sspeer uint32_t rx_cntl_alloc_size; 22003859Sml29623 22013859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_alloc_rx_mem_pool")); 22023859Sml29623 22033859Sml29623 p_all_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config; 22043859Sml29623 p_cfgp = (p_nxge_hw_pt_cfg_t)&p_all_cfgp->hw_config; 22056495Sspeer rdc_max = NXGE_MAX_RDCS; 22063859Sml29623 22073859Sml29623 /* 22086495Sspeer * Allocate memory for the common DMA data structures. 22093859Sml29623 */ 22103859Sml29623 dma_poolp = (p_nxge_dma_pool_t)KMEM_ZALLOC(sizeof (nxge_dma_pool_t), 22116512Ssowmini KM_SLEEP); 22123859Sml29623 dma_buf_p = (p_nxge_dma_common_t *)KMEM_ZALLOC( 22136512Ssowmini sizeof (p_nxge_dma_common_t) * rdc_max, KM_SLEEP); 22143859Sml29623 22153859Sml29623 dma_cntl_poolp = (p_nxge_dma_pool_t) 22166512Ssowmini KMEM_ZALLOC(sizeof (nxge_dma_pool_t), KM_SLEEP); 22173859Sml29623 dma_cntl_p = (p_nxge_dma_common_t *)KMEM_ZALLOC( 22186512Ssowmini sizeof (p_nxge_dma_common_t) * rdc_max, KM_SLEEP); 22193859Sml29623 22203859Sml29623 num_chunks = (uint32_t *)KMEM_ZALLOC( 22216512Ssowmini sizeof (uint32_t) * rdc_max, KM_SLEEP); 22223859Sml29623 22233859Sml29623 /* 22246495Sspeer * Assume that each DMA channel will be configured with 22256495Sspeer * the default block size. 22266495Sspeer * rbr block counts are modulo the batch count (16). 22273859Sml29623 */ 22283859Sml29623 nxge_port_rbr_size = p_all_cfgp->rbr_size; 22293859Sml29623 nxge_port_rcr_size = p_all_cfgp->rcr_size; 22303859Sml29623 22313859Sml29623 if (!nxge_port_rbr_size) { 22323859Sml29623 nxge_port_rbr_size = NXGE_RBR_RBB_DEFAULT; 22333859Sml29623 } 22343859Sml29623 if (nxge_port_rbr_size % NXGE_RXDMA_POST_BATCH) { 22353859Sml29623 nxge_port_rbr_size = (NXGE_RXDMA_POST_BATCH * 22366512Ssowmini (nxge_port_rbr_size / NXGE_RXDMA_POST_BATCH + 1)); 22373859Sml29623 } 22383859Sml29623 22393859Sml29623 p_all_cfgp->rbr_size = nxge_port_rbr_size; 22403859Sml29623 nxge_port_rbr_spare_size = nxge_rbr_spare_size; 22413859Sml29623 22423859Sml29623 if (nxge_port_rbr_spare_size % NXGE_RXDMA_POST_BATCH) { 22433859Sml29623 nxge_port_rbr_spare_size = (NXGE_RXDMA_POST_BATCH * 22446512Ssowmini (nxge_port_rbr_spare_size / NXGE_RXDMA_POST_BATCH + 1)); 22453859Sml29623 } 22465770Sml29623 if (nxge_port_rbr_size > RBR_DEFAULT_MAX_BLKS) { 22475770Sml29623 NXGE_DEBUG_MSG((nxgep, MEM_CTL, 22485770Sml29623 "nxge_alloc_rx_mem_pool: RBR size too high %d, " 22495770Sml29623 "set to default %d", 22505770Sml29623 nxge_port_rbr_size, RBR_DEFAULT_MAX_BLKS)); 22515770Sml29623 nxge_port_rbr_size = RBR_DEFAULT_MAX_BLKS; 22525770Sml29623 } 22535770Sml29623 if (nxge_port_rcr_size > RCR_DEFAULT_MAX) { 22545770Sml29623 NXGE_DEBUG_MSG((nxgep, MEM_CTL, 22555770Sml29623 "nxge_alloc_rx_mem_pool: RCR too high %d, " 22565770Sml29623 "set to default %d", 22575770Sml29623 nxge_port_rcr_size, RCR_DEFAULT_MAX)); 22585770Sml29623 nxge_port_rcr_size = RCR_DEFAULT_MAX; 22595770Sml29623 } 22603859Sml29623 22613859Sml29623 /* 22623859Sml29623 * N2/NIU has limitation on the descriptor sizes (contiguous 22633859Sml29623 * memory allocation on data buffers to 4M (contig_mem_alloc) 22643859Sml29623 * and little endian for control buffers (must use the ddi/dki mem alloc 22653859Sml29623 * function). 22663859Sml29623 */ 22673859Sml29623 #if defined(sun4v) && defined(NIU_LP_WORKAROUND) 22683859Sml29623 if (nxgep->niu_type == N2_NIU) { 22693859Sml29623 nxge_port_rbr_spare_size = 0; 22703859Sml29623 if ((nxge_port_rbr_size > NXGE_NIU_CONTIG_RBR_MAX) || 22716512Ssowmini (!ISP2(nxge_port_rbr_size))) { 22723859Sml29623 nxge_port_rbr_size = NXGE_NIU_CONTIG_RBR_MAX; 22733859Sml29623 } 22743859Sml29623 if ((nxge_port_rcr_size > NXGE_NIU_CONTIG_RCR_MAX) || 22756512Ssowmini (!ISP2(nxge_port_rcr_size))) { 22763859Sml29623 nxge_port_rcr_size = NXGE_NIU_CONTIG_RCR_MAX; 22773859Sml29623 } 22783859Sml29623 } 22793859Sml29623 #endif 22803859Sml29623 22813859Sml29623 /* 22823859Sml29623 * Addresses of receive block ring, receive completion ring and the 22833859Sml29623 * mailbox must be all cache-aligned (64 bytes). 22843859Sml29623 */ 22853859Sml29623 rx_cntl_alloc_size = nxge_port_rbr_size + nxge_port_rbr_spare_size; 22863859Sml29623 rx_cntl_alloc_size *= (sizeof (rx_desc_t)); 22873859Sml29623 rx_cntl_alloc_size += (sizeof (rcr_entry_t) * nxge_port_rcr_size); 22883859Sml29623 rx_cntl_alloc_size += sizeof (rxdma_mailbox_t); 22893859Sml29623 22903859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_alloc_rx_mem_pool: " 22916512Ssowmini "nxge_port_rbr_size = %d nxge_port_rbr_spare_size = %d " 22926512Ssowmini "nxge_port_rcr_size = %d " 22936512Ssowmini "rx_cntl_alloc_size = %d", 22946512Ssowmini nxge_port_rbr_size, nxge_port_rbr_spare_size, 22956512Ssowmini nxge_port_rcr_size, 22966512Ssowmini rx_cntl_alloc_size)); 22973859Sml29623 22983859Sml29623 #if defined(sun4v) && defined(NIU_LP_WORKAROUND) 22993859Sml29623 if (nxgep->niu_type == N2_NIU) { 23006495Sspeer uint32_t rx_buf_alloc_size = (nxgep->rx_default_block_size * 23016495Sspeer (nxge_port_rbr_size + nxge_port_rbr_spare_size)); 23026495Sspeer 23033859Sml29623 if (!ISP2(rx_buf_alloc_size)) { 23043859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 23056512Ssowmini "==> nxge_alloc_rx_mem_pool: " 23066512Ssowmini " must be power of 2")); 23073859Sml29623 status |= (NXGE_ERROR | NXGE_DDI_FAILED); 23083859Sml29623 goto nxge_alloc_rx_mem_pool_exit; 23093859Sml29623 } 23103859Sml29623 23113859Sml29623 if (rx_buf_alloc_size > (1 << 22)) { 23123859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 23136512Ssowmini "==> nxge_alloc_rx_mem_pool: " 23146512Ssowmini " limit size to 4M")); 23153859Sml29623 status |= (NXGE_ERROR | NXGE_DDI_FAILED); 23163859Sml29623 goto nxge_alloc_rx_mem_pool_exit; 23173859Sml29623 } 23183859Sml29623 23193859Sml29623 if (rx_cntl_alloc_size < 0x2000) { 23203859Sml29623 rx_cntl_alloc_size = 0x2000; 23213859Sml29623 } 23223859Sml29623 } 23233859Sml29623 #endif 23243859Sml29623 nxgep->nxge_port_rbr_size = nxge_port_rbr_size; 23253859Sml29623 nxgep->nxge_port_rcr_size = nxge_port_rcr_size; 23266495Sspeer nxgep->nxge_port_rbr_spare_size = nxge_port_rbr_spare_size; 23276495Sspeer nxgep->nxge_port_rx_cntl_alloc_size = rx_cntl_alloc_size; 23286495Sspeer 23296495Sspeer dma_poolp->ndmas = p_cfgp->max_rdcs; 23303859Sml29623 dma_poolp->num_chunks = num_chunks; 23313859Sml29623 dma_poolp->buf_allocated = B_TRUE; 23323859Sml29623 nxgep->rx_buf_pool_p = dma_poolp; 23333859Sml29623 dma_poolp->dma_buf_pool_p = dma_buf_p; 23343859Sml29623 23356495Sspeer dma_cntl_poolp->ndmas = p_cfgp->max_rdcs; 23363859Sml29623 dma_cntl_poolp->buf_allocated = B_TRUE; 23373859Sml29623 nxgep->rx_cntl_pool_p = dma_cntl_poolp; 23383859Sml29623 dma_cntl_poolp->dma_buf_pool_p = dma_cntl_p; 23393859Sml29623 23406495Sspeer /* Allocate the receive rings, too. */ 23416495Sspeer nxgep->rx_rbr_rings = 23426512Ssowmini KMEM_ZALLOC(sizeof (rx_rbr_rings_t), KM_SLEEP); 23436495Sspeer nxgep->rx_rbr_rings->rbr_rings = 23446512Ssowmini KMEM_ZALLOC(sizeof (p_rx_rbr_ring_t) * rdc_max, KM_SLEEP); 23456495Sspeer nxgep->rx_rcr_rings = 23466512Ssowmini KMEM_ZALLOC(sizeof (rx_rcr_rings_t), KM_SLEEP); 23476495Sspeer nxgep->rx_rcr_rings->rcr_rings = 23486512Ssowmini KMEM_ZALLOC(sizeof (p_rx_rcr_ring_t) * rdc_max, KM_SLEEP); 23496495Sspeer nxgep->rx_mbox_areas_p = 23506512Ssowmini KMEM_ZALLOC(sizeof (rx_mbox_areas_t), KM_SLEEP); 23516495Sspeer nxgep->rx_mbox_areas_p->rxmbox_areas = 23526512Ssowmini KMEM_ZALLOC(sizeof (p_rx_mbox_t) * rdc_max, KM_SLEEP); 23536495Sspeer 23546495Sspeer nxgep->rx_rbr_rings->ndmas = nxgep->rx_rcr_rings->ndmas = 23556495Sspeer p_cfgp->max_rdcs; 23566495Sspeer 23573859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, 23586512Ssowmini "<== nxge_alloc_rx_mem_pool:status 0x%08x", status)); 23593859Sml29623 23603859Sml29623 nxge_alloc_rx_mem_pool_exit: 23616495Sspeer return (status); 23626495Sspeer } 23636495Sspeer 23646495Sspeer /* 23656495Sspeer * nxge_alloc_rxb 23666495Sspeer * 23676495Sspeer * Allocate buffers for an RDC. 23686495Sspeer * 23696495Sspeer * Arguments: 23706495Sspeer * nxgep 23716495Sspeer * channel The channel to map into our kernel space. 23726495Sspeer * 23736495Sspeer * Notes: 23746495Sspeer * 23756495Sspeer * NPI function calls: 23766495Sspeer * 23776495Sspeer * NXGE function calls: 23786495Sspeer * 23796495Sspeer * Registers accessed: 23806495Sspeer * 23816495Sspeer * Context: 23826495Sspeer * 23836495Sspeer * Taking apart: 23846495Sspeer * 23856495Sspeer * Open questions: 23866495Sspeer * 23876495Sspeer */ 23886495Sspeer nxge_status_t 23896495Sspeer nxge_alloc_rxb( 23906495Sspeer p_nxge_t nxgep, 23916495Sspeer int channel) 23926495Sspeer { 23936495Sspeer size_t rx_buf_alloc_size; 23946495Sspeer nxge_status_t status = NXGE_OK; 23956495Sspeer 23966495Sspeer nxge_dma_common_t **data; 23976495Sspeer nxge_dma_common_t **control; 23986495Sspeer uint32_t *num_chunks; 23996495Sspeer 24006495Sspeer NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_alloc_rbb")); 24016495Sspeer 24026495Sspeer /* 24036495Sspeer * Allocate memory for the receive buffers and descriptor rings. 24046495Sspeer * Replace these allocation functions with the interface functions 24056495Sspeer * provided by the partition manager if/when they are available. 24066495Sspeer */ 24076495Sspeer 24086495Sspeer /* 24096495Sspeer * Allocate memory for the receive buffer blocks. 24106495Sspeer */ 24116495Sspeer rx_buf_alloc_size = (nxgep->rx_default_block_size * 24126512Ssowmini (nxgep->nxge_port_rbr_size + nxgep->nxge_port_rbr_spare_size)); 24136495Sspeer 24146495Sspeer data = &nxgep->rx_buf_pool_p->dma_buf_pool_p[channel]; 24156495Sspeer num_chunks = &nxgep->rx_buf_pool_p->num_chunks[channel]; 24166495Sspeer 24176495Sspeer if ((status = nxge_alloc_rx_buf_dma( 24186495Sspeer nxgep, channel, data, rx_buf_alloc_size, 24196495Sspeer nxgep->rx_default_block_size, num_chunks)) != NXGE_OK) { 24206495Sspeer return (status); 24216495Sspeer } 24226495Sspeer 24236495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "<== nxge_alloc_rxb(): " 24246495Sspeer "dma %d dma_buf_p %llx &dma_buf_p %llx", channel, *data, data)); 24256495Sspeer 24266495Sspeer /* 24276495Sspeer * Allocate memory for descriptor rings and mailbox. 24286495Sspeer */ 24296495Sspeer control = &nxgep->rx_cntl_pool_p->dma_buf_pool_p[channel]; 24306495Sspeer 24316495Sspeer if ((status = nxge_alloc_rx_cntl_dma( 24326495Sspeer nxgep, channel, control, nxgep->nxge_port_rx_cntl_alloc_size)) 24336495Sspeer != NXGE_OK) { 24346495Sspeer nxge_free_rx_cntl_dma(nxgep, *control); 24356495Sspeer (*data)->buf_alloc_state |= BUF_ALLOCATED_WAIT_FREE; 24366495Sspeer nxge_free_rx_buf_dma(nxgep, *data, *num_chunks); 24376495Sspeer return (status); 24386495Sspeer } 24396495Sspeer 24403859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, 24416495Sspeer "<== nxge_alloc_rx_mem_pool:status 0x%08x", status)); 24423859Sml29623 24433859Sml29623 return (status); 24443859Sml29623 } 24453859Sml29623 24466495Sspeer void 24476495Sspeer nxge_free_rxb( 24486495Sspeer p_nxge_t nxgep, 24496495Sspeer int channel) 24506495Sspeer { 24516495Sspeer nxge_dma_common_t *data; 24526495Sspeer nxge_dma_common_t *control; 24536495Sspeer uint32_t num_chunks; 24546495Sspeer 24556495Sspeer NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_alloc_rbb")); 24566495Sspeer 24576495Sspeer data = nxgep->rx_buf_pool_p->dma_buf_pool_p[channel]; 24586495Sspeer num_chunks = nxgep->rx_buf_pool_p->num_chunks[channel]; 24596495Sspeer nxge_free_rx_buf_dma(nxgep, data, num_chunks); 24606495Sspeer 24616495Sspeer nxgep->rx_buf_pool_p->dma_buf_pool_p[channel] = 0; 24626495Sspeer nxgep->rx_buf_pool_p->num_chunks[channel] = 0; 24636495Sspeer 24646495Sspeer control = nxgep->rx_cntl_pool_p->dma_buf_pool_p[channel]; 24656495Sspeer nxge_free_rx_cntl_dma(nxgep, control); 24666495Sspeer 24676495Sspeer nxgep->rx_cntl_pool_p->dma_buf_pool_p[channel] = 0; 24686495Sspeer 24696495Sspeer KMEM_FREE(data, sizeof (nxge_dma_common_t) * NXGE_DMA_BLOCK); 24706495Sspeer KMEM_FREE(control, sizeof (nxge_dma_common_t)); 24716495Sspeer 24726495Sspeer NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_alloc_rbb")); 24736495Sspeer } 24746495Sspeer 24753859Sml29623 static void 24763859Sml29623 nxge_free_rx_mem_pool(p_nxge_t nxgep) 24773859Sml29623 { 24786495Sspeer int rdc_max = NXGE_MAX_RDCS; 24793859Sml29623 24803859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_free_rx_mem_pool")); 24813859Sml29623 24826495Sspeer if (!nxgep->rx_buf_pool_p || !nxgep->rx_buf_pool_p->buf_allocated) { 24833859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 24846512Ssowmini "<== nxge_free_rx_mem_pool " 24856512Ssowmini "(null rx buf pool or buf not allocated")); 24863859Sml29623 return; 24873859Sml29623 } 24886495Sspeer if (!nxgep->rx_cntl_pool_p || !nxgep->rx_cntl_pool_p->buf_allocated) { 24893859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 24906512Ssowmini "<== nxge_free_rx_mem_pool " 24916512Ssowmini "(null rx cntl buf pool or cntl buf not allocated")); 24923859Sml29623 return; 24933859Sml29623 } 24943859Sml29623 24956495Sspeer KMEM_FREE(nxgep->rx_cntl_pool_p->dma_buf_pool_p, 24966495Sspeer sizeof (p_nxge_dma_common_t) * rdc_max); 24976495Sspeer KMEM_FREE(nxgep->rx_cntl_pool_p, sizeof (nxge_dma_pool_t)); 24986495Sspeer 24996495Sspeer KMEM_FREE(nxgep->rx_buf_pool_p->num_chunks, 25006495Sspeer sizeof (uint32_t) * rdc_max); 25016495Sspeer KMEM_FREE(nxgep->rx_buf_pool_p->dma_buf_pool_p, 25026495Sspeer sizeof (p_nxge_dma_common_t) * rdc_max); 25036495Sspeer KMEM_FREE(nxgep->rx_buf_pool_p, sizeof (nxge_dma_pool_t)); 25046495Sspeer 25056495Sspeer nxgep->rx_buf_pool_p = 0; 25066495Sspeer nxgep->rx_cntl_pool_p = 0; 25076495Sspeer 25086495Sspeer KMEM_FREE(nxgep->rx_rbr_rings->rbr_rings, 25096495Sspeer sizeof (p_rx_rbr_ring_t) * rdc_max); 25106495Sspeer KMEM_FREE(nxgep->rx_rbr_rings, sizeof (rx_rbr_rings_t)); 25116495Sspeer KMEM_FREE(nxgep->rx_rcr_rings->rcr_rings, 25126495Sspeer sizeof (p_rx_rcr_ring_t) * rdc_max); 25136495Sspeer KMEM_FREE(nxgep->rx_rcr_rings, sizeof (rx_rcr_rings_t)); 25146495Sspeer KMEM_FREE(nxgep->rx_mbox_areas_p->rxmbox_areas, 25156495Sspeer sizeof (p_rx_mbox_t) * rdc_max); 25166495Sspeer KMEM_FREE(nxgep->rx_mbox_areas_p, sizeof (rx_mbox_areas_t)); 25176495Sspeer 25186495Sspeer nxgep->rx_rbr_rings = 0; 25196495Sspeer nxgep->rx_rcr_rings = 0; 25206495Sspeer nxgep->rx_mbox_areas_p = 0; 25213859Sml29623 25223859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "<== nxge_free_rx_mem_pool")); 25233859Sml29623 } 25243859Sml29623 25253859Sml29623 25263859Sml29623 static nxge_status_t 25273859Sml29623 nxge_alloc_rx_buf_dma(p_nxge_t nxgep, uint16_t dma_channel, 25283859Sml29623 p_nxge_dma_common_t *dmap, 25293859Sml29623 size_t alloc_size, size_t block_size, uint32_t *num_chunks) 25303859Sml29623 { 25313859Sml29623 p_nxge_dma_common_t rx_dmap; 25323859Sml29623 nxge_status_t status = NXGE_OK; 25333859Sml29623 size_t total_alloc_size; 25343859Sml29623 size_t allocated = 0; 25353859Sml29623 int i, size_index, array_size; 25366495Sspeer boolean_t use_kmem_alloc = B_FALSE; 25373859Sml29623 25383859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_alloc_rx_buf_dma")); 25393859Sml29623 25403859Sml29623 rx_dmap = (p_nxge_dma_common_t) 25416512Ssowmini KMEM_ZALLOC(sizeof (nxge_dma_common_t) * NXGE_DMA_BLOCK, 25426512Ssowmini KM_SLEEP); 25433859Sml29623 25443859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 25456512Ssowmini " alloc_rx_buf_dma rdc %d asize %x bsize %x bbuf %llx ", 25466512Ssowmini dma_channel, alloc_size, block_size, dmap)); 25473859Sml29623 25483859Sml29623 total_alloc_size = alloc_size; 25493859Sml29623 25503859Sml29623 #if defined(RX_USE_RECLAIM_POST) 25513859Sml29623 total_alloc_size = alloc_size + alloc_size/4; 25523859Sml29623 #endif 25533859Sml29623 25543859Sml29623 i = 0; 25553859Sml29623 size_index = 0; 25563859Sml29623 array_size = sizeof (alloc_sizes)/sizeof (size_t); 25578661SSantwona.Behera@Sun.COM while ((size_index < array_size) && 25588661SSantwona.Behera@Sun.COM (alloc_sizes[size_index] < alloc_size)) 25596512Ssowmini size_index++; 25603859Sml29623 if (size_index >= array_size) { 25613859Sml29623 size_index = array_size - 1; 25623859Sml29623 } 25633859Sml29623 25646495Sspeer /* For Neptune, use kmem_alloc if the kmem flag is set. */ 25656495Sspeer if (nxgep->niu_type != N2_NIU && nxge_use_kmem_alloc) { 25666495Sspeer use_kmem_alloc = B_TRUE; 25676495Sspeer #if defined(__i386) || defined(__amd64) 25686495Sspeer size_index = 0; 25696495Sspeer #endif 25706495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 25716495Sspeer "==> nxge_alloc_rx_buf_dma: " 25726495Sspeer "Neptune use kmem_alloc() - size_index %d", 25736495Sspeer size_index)); 25746495Sspeer } 25756495Sspeer 25763859Sml29623 while ((allocated < total_alloc_size) && 25776512Ssowmini (size_index >= 0) && (i < NXGE_DMA_BLOCK)) { 25783859Sml29623 rx_dmap[i].dma_chunk_index = i; 25793859Sml29623 rx_dmap[i].block_size = block_size; 25803859Sml29623 rx_dmap[i].alength = alloc_sizes[size_index]; 25813859Sml29623 rx_dmap[i].orig_alength = rx_dmap[i].alength; 25823859Sml29623 rx_dmap[i].nblocks = alloc_sizes[size_index] / block_size; 25833859Sml29623 rx_dmap[i].dma_channel = dma_channel; 25843859Sml29623 rx_dmap[i].contig_alloc_type = B_FALSE; 25856495Sspeer rx_dmap[i].kmem_alloc_type = B_FALSE; 25866495Sspeer rx_dmap[i].buf_alloc_type = DDI_MEM_ALLOC; 25873859Sml29623 25883859Sml29623 /* 25893859Sml29623 * N2/NIU: data buffers must be contiguous as the driver 25903859Sml29623 * needs to call Hypervisor api to set up 25913859Sml29623 * logical pages. 25923859Sml29623 */ 25933859Sml29623 if ((nxgep->niu_type == N2_NIU) && (NXGE_DMA_BLOCK == 1)) { 25943859Sml29623 rx_dmap[i].contig_alloc_type = B_TRUE; 25956495Sspeer rx_dmap[i].buf_alloc_type = CONTIG_MEM_ALLOC; 25966495Sspeer } else if (use_kmem_alloc) { 25976495Sspeer /* For Neptune, use kmem_alloc */ 25986495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 25996495Sspeer "==> nxge_alloc_rx_buf_dma: " 26006495Sspeer "Neptune use kmem_alloc()")); 26016495Sspeer rx_dmap[i].kmem_alloc_type = B_TRUE; 26026495Sspeer rx_dmap[i].buf_alloc_type = KMEM_ALLOC; 26033859Sml29623 } 26043859Sml29623 26053859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 26066512Ssowmini "alloc_rx_buf_dma rdc %d chunk %d bufp %llx size %x " 26076512Ssowmini "i %d nblocks %d alength %d", 26086512Ssowmini dma_channel, i, &rx_dmap[i], block_size, 26096512Ssowmini i, rx_dmap[i].nblocks, 26106512Ssowmini rx_dmap[i].alength)); 26113859Sml29623 status = nxge_dma_mem_alloc(nxgep, nxge_force_dma, 26126512Ssowmini &nxge_rx_dma_attr, 26136512Ssowmini rx_dmap[i].alength, 26146512Ssowmini &nxge_dev_buf_dma_acc_attr, 26156512Ssowmini DDI_DMA_READ | DDI_DMA_STREAMING, 26166512Ssowmini (p_nxge_dma_common_t)(&rx_dmap[i])); 26173859Sml29623 if (status != NXGE_OK) { 26183859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 26196495Sspeer "nxge_alloc_rx_buf_dma: Alloc Failed: " 26206495Sspeer "dma %d size_index %d size requested %d", 26216495Sspeer dma_channel, 26226495Sspeer size_index, 26236495Sspeer rx_dmap[i].alength)); 26243859Sml29623 size_index--; 26253859Sml29623 } else { 26266495Sspeer rx_dmap[i].buf_alloc_state = BUF_ALLOCATED; 26276495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 26286495Sspeer " nxge_alloc_rx_buf_dma DONE alloc mem: " 26296495Sspeer "dma %d dma_buf_p $%p kaddrp $%p alength %d " 26306495Sspeer "buf_alloc_state %d alloc_type %d", 26316495Sspeer dma_channel, 26326495Sspeer &rx_dmap[i], 26336495Sspeer rx_dmap[i].kaddrp, 26346495Sspeer rx_dmap[i].alength, 26356495Sspeer rx_dmap[i].buf_alloc_state, 26366495Sspeer rx_dmap[i].buf_alloc_type)); 26376495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 26386495Sspeer " alloc_rx_buf_dma allocated rdc %d " 26396495Sspeer "chunk %d size %x dvma %x bufp %llx kaddrp $%p", 26406495Sspeer dma_channel, i, rx_dmap[i].alength, 26416495Sspeer rx_dmap[i].ioaddr_pp, &rx_dmap[i], 26426495Sspeer rx_dmap[i].kaddrp)); 26433859Sml29623 i++; 26443859Sml29623 allocated += alloc_sizes[size_index]; 26453859Sml29623 } 26463859Sml29623 } 26473859Sml29623 26483859Sml29623 if (allocated < total_alloc_size) { 26495770Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 26506495Sspeer "==> nxge_alloc_rx_buf_dma: not enough for channel %d " 26515770Sml29623 "allocated 0x%x requested 0x%x", 26525770Sml29623 dma_channel, 26535770Sml29623 allocated, total_alloc_size)); 26545770Sml29623 status = NXGE_ERROR; 26553859Sml29623 goto nxge_alloc_rx_mem_fail1; 26563859Sml29623 } 26573859Sml29623 26585770Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 26596495Sspeer "==> nxge_alloc_rx_buf_dma: Allocated for channel %d " 26605770Sml29623 "allocated 0x%x requested 0x%x", 26615770Sml29623 dma_channel, 26625770Sml29623 allocated, total_alloc_size)); 26635770Sml29623 26643859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, 26656512Ssowmini " alloc_rx_buf_dma rdc %d allocated %d chunks", 26666512Ssowmini dma_channel, i)); 26673859Sml29623 *num_chunks = i; 26683859Sml29623 *dmap = rx_dmap; 26693859Sml29623 26703859Sml29623 goto nxge_alloc_rx_mem_exit; 26713859Sml29623 26723859Sml29623 nxge_alloc_rx_mem_fail1: 26733859Sml29623 KMEM_FREE(rx_dmap, sizeof (nxge_dma_common_t) * NXGE_DMA_BLOCK); 26743859Sml29623 26753859Sml29623 nxge_alloc_rx_mem_exit: 26763859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, 26776512Ssowmini "<== nxge_alloc_rx_buf_dma status 0x%08x", status)); 26783859Sml29623 26793859Sml29623 return (status); 26803859Sml29623 } 26813859Sml29623 26823859Sml29623 /*ARGSUSED*/ 26833859Sml29623 static void 26843859Sml29623 nxge_free_rx_buf_dma(p_nxge_t nxgep, p_nxge_dma_common_t dmap, 26853859Sml29623 uint32_t num_chunks) 26863859Sml29623 { 26873859Sml29623 int i; 26883859Sml29623 26893859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 26906512Ssowmini "==> nxge_free_rx_buf_dma: # of chunks %d", num_chunks)); 26913859Sml29623 26926495Sspeer if (dmap == 0) 26936495Sspeer return; 26946495Sspeer 26953859Sml29623 for (i = 0; i < num_chunks; i++) { 26963859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 26976512Ssowmini "==> nxge_free_rx_buf_dma: chunk %d dmap 0x%llx", 26986512Ssowmini i, dmap)); 26996495Sspeer nxge_dma_free_rx_data_buf(dmap++); 27003859Sml29623 } 27013859Sml29623 27023859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_free_rx_buf_dma")); 27033859Sml29623 } 27043859Sml29623 27053859Sml29623 /*ARGSUSED*/ 27063859Sml29623 static nxge_status_t 27073859Sml29623 nxge_alloc_rx_cntl_dma(p_nxge_t nxgep, uint16_t dma_channel, 27083859Sml29623 p_nxge_dma_common_t *dmap, size_t size) 27093859Sml29623 { 27103859Sml29623 p_nxge_dma_common_t rx_dmap; 27113859Sml29623 nxge_status_t status = NXGE_OK; 27123859Sml29623 27133859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_alloc_rx_cntl_dma")); 27143859Sml29623 27153859Sml29623 rx_dmap = (p_nxge_dma_common_t) 27166512Ssowmini KMEM_ZALLOC(sizeof (nxge_dma_common_t), KM_SLEEP); 27173859Sml29623 27183859Sml29623 rx_dmap->contig_alloc_type = B_FALSE; 27196495Sspeer rx_dmap->kmem_alloc_type = B_FALSE; 27203859Sml29623 27213859Sml29623 status = nxge_dma_mem_alloc(nxgep, nxge_force_dma, 27226512Ssowmini &nxge_desc_dma_attr, 27236512Ssowmini size, 27246512Ssowmini &nxge_dev_desc_dma_acc_attr, 27256512Ssowmini DDI_DMA_RDWR | DDI_DMA_CONSISTENT, 27266512Ssowmini rx_dmap); 27273859Sml29623 if (status != NXGE_OK) { 27283859Sml29623 goto nxge_alloc_rx_cntl_dma_fail1; 27293859Sml29623 } 27303859Sml29623 27313859Sml29623 *dmap = rx_dmap; 27323859Sml29623 goto nxge_alloc_rx_cntl_dma_exit; 27333859Sml29623 27343859Sml29623 nxge_alloc_rx_cntl_dma_fail1: 27353859Sml29623 KMEM_FREE(rx_dmap, sizeof (nxge_dma_common_t)); 27363859Sml29623 27373859Sml29623 nxge_alloc_rx_cntl_dma_exit: 27383859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, 27396512Ssowmini "<== nxge_alloc_rx_cntl_dma status 0x%08x", status)); 27403859Sml29623 27413859Sml29623 return (status); 27423859Sml29623 } 27433859Sml29623 27443859Sml29623 /*ARGSUSED*/ 27453859Sml29623 static void 27463859Sml29623 nxge_free_rx_cntl_dma(p_nxge_t nxgep, p_nxge_dma_common_t dmap) 27473859Sml29623 { 27483859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_free_rx_cntl_dma")); 27493859Sml29623 27506495Sspeer if (dmap == 0) 27516495Sspeer return; 27526495Sspeer 27533859Sml29623 nxge_dma_mem_free(dmap); 27543859Sml29623 27553859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_free_rx_cntl_dma")); 27563859Sml29623 } 27573859Sml29623 27586495Sspeer typedef struct { 27596495Sspeer size_t tx_size; 27606495Sspeer size_t cr_size; 27616495Sspeer size_t threshhold; 27626495Sspeer } nxge_tdc_sizes_t; 27636495Sspeer 27646495Sspeer static 27656495Sspeer nxge_status_t 27666495Sspeer nxge_tdc_sizes( 27676495Sspeer nxge_t *nxgep, 27686495Sspeer nxge_tdc_sizes_t *sizes) 27696495Sspeer { 27706495Sspeer uint32_t threshhold; /* The bcopy() threshhold */ 27716495Sspeer size_t tx_size; /* Transmit buffer size */ 27726495Sspeer size_t cr_size; /* Completion ring size */ 27736495Sspeer 27746495Sspeer /* 27756495Sspeer * Assume that each DMA channel will be configured with the 27766495Sspeer * default transmit buffer size for copying transmit data. 27776495Sspeer * (If a packet is bigger than this, it will not be copied.) 27786495Sspeer */ 27796495Sspeer if (nxgep->niu_type == N2_NIU) { 27806495Sspeer threshhold = TX_BCOPY_SIZE; 27816495Sspeer } else { 27826495Sspeer threshhold = nxge_bcopy_thresh; 27836495Sspeer } 27846495Sspeer tx_size = nxge_tx_ring_size * threshhold; 27856495Sspeer 27866495Sspeer cr_size = nxge_tx_ring_size * sizeof (tx_desc_t); 27876495Sspeer cr_size += sizeof (txdma_mailbox_t); 27886495Sspeer 27896495Sspeer #if defined(sun4v) && defined(NIU_LP_WORKAROUND) 27906495Sspeer if (nxgep->niu_type == N2_NIU) { 27916495Sspeer if (!ISP2(tx_size)) { 27926495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 27936512Ssowmini "==> nxge_tdc_sizes: Tx size" 27946512Ssowmini " must be power of 2")); 27956495Sspeer return (NXGE_ERROR); 27966495Sspeer } 27976495Sspeer 27986495Sspeer if (tx_size > (1 << 22)) { 27996495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 28006512Ssowmini "==> nxge_tdc_sizes: Tx size" 28016512Ssowmini " limited to 4M")); 28026495Sspeer return (NXGE_ERROR); 28036495Sspeer } 28046495Sspeer 28056495Sspeer if (cr_size < 0x2000) 28066495Sspeer cr_size = 0x2000; 28076495Sspeer } 28086495Sspeer #endif 28096495Sspeer 28106495Sspeer sizes->threshhold = threshhold; 28116495Sspeer sizes->tx_size = tx_size; 28126495Sspeer sizes->cr_size = cr_size; 28136495Sspeer 28146495Sspeer return (NXGE_OK); 28156495Sspeer } 28166495Sspeer /* 28176495Sspeer * nxge_alloc_txb 28186495Sspeer * 28196495Sspeer * Allocate buffers for an TDC. 28206495Sspeer * 28216495Sspeer * Arguments: 28226495Sspeer * nxgep 28236495Sspeer * channel The channel to map into our kernel space. 28246495Sspeer * 28256495Sspeer * Notes: 28266495Sspeer * 28276495Sspeer * NPI function calls: 28286495Sspeer * 28296495Sspeer * NXGE function calls: 28306495Sspeer * 28316495Sspeer * Registers accessed: 28326495Sspeer * 28336495Sspeer * Context: 28346495Sspeer * 28356495Sspeer * Taking apart: 28366495Sspeer * 28376495Sspeer * Open questions: 28386495Sspeer * 28396495Sspeer */ 28406495Sspeer nxge_status_t 28416495Sspeer nxge_alloc_txb( 28426495Sspeer p_nxge_t nxgep, 28436495Sspeer int channel) 28446495Sspeer { 28456495Sspeer nxge_dma_common_t **dma_buf_p; 28466495Sspeer nxge_dma_common_t **dma_cntl_p; 28476495Sspeer uint32_t *num_chunks; 28486495Sspeer nxge_status_t status = NXGE_OK; 28496495Sspeer 28506495Sspeer nxge_tdc_sizes_t sizes; 28516495Sspeer 28526495Sspeer NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_alloc_tbb")); 28536495Sspeer 28546495Sspeer if (nxge_tdc_sizes(nxgep, &sizes) != NXGE_OK) 28556495Sspeer return (NXGE_ERROR); 28566495Sspeer 28576495Sspeer /* 28586495Sspeer * Allocate memory for transmit buffers and descriptor rings. 28596495Sspeer * Replace these allocation functions with the interface functions 28606495Sspeer * provided by the partition manager Real Soon Now. 28616495Sspeer */ 28626495Sspeer dma_buf_p = &nxgep->tx_buf_pool_p->dma_buf_pool_p[channel]; 28636495Sspeer num_chunks = &nxgep->tx_buf_pool_p->num_chunks[channel]; 28646495Sspeer 28656495Sspeer dma_cntl_p = &nxgep->tx_cntl_pool_p->dma_buf_pool_p[channel]; 28666495Sspeer 28676495Sspeer /* 28686495Sspeer * Allocate memory for transmit buffers and descriptor rings. 28696495Sspeer * Replace allocation functions with interface functions provided 28706495Sspeer * by the partition manager when it is available. 28716495Sspeer * 28726495Sspeer * Allocate memory for the transmit buffer pool. 28736495Sspeer */ 28746495Sspeer NXGE_DEBUG_MSG((nxgep, DMA_CTL, 28756512Ssowmini "sizes: tx: %ld, cr:%ld, th:%ld", 28766512Ssowmini sizes.tx_size, sizes.cr_size, sizes.threshhold)); 28776495Sspeer 28786495Sspeer *num_chunks = 0; 28796495Sspeer status = nxge_alloc_tx_buf_dma(nxgep, channel, dma_buf_p, 28806495Sspeer sizes.tx_size, sizes.threshhold, num_chunks); 28816495Sspeer if (status != NXGE_OK) { 28826495Sspeer cmn_err(CE_NOTE, "nxge_alloc_tx_buf_dma failed!"); 28836495Sspeer return (status); 28846495Sspeer } 28856495Sspeer 28866495Sspeer /* 28876495Sspeer * Allocate memory for descriptor rings and mailbox. 28886495Sspeer */ 28896495Sspeer status = nxge_alloc_tx_cntl_dma(nxgep, channel, dma_cntl_p, 28906495Sspeer sizes.cr_size); 28916495Sspeer if (status != NXGE_OK) { 28926495Sspeer nxge_free_tx_buf_dma(nxgep, *dma_buf_p, *num_chunks); 28936495Sspeer cmn_err(CE_NOTE, "nxge_alloc_tx_cntl_dma failed!"); 28946495Sspeer return (status); 28956495Sspeer } 28966495Sspeer 28976495Sspeer return (NXGE_OK); 28986495Sspeer } 28996495Sspeer 29006495Sspeer void 29016495Sspeer nxge_free_txb( 29026495Sspeer p_nxge_t nxgep, 29036495Sspeer int channel) 29046495Sspeer { 29056495Sspeer nxge_dma_common_t *data; 29066495Sspeer nxge_dma_common_t *control; 29076495Sspeer uint32_t num_chunks; 29086495Sspeer 29096495Sspeer NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_free_txb")); 29106495Sspeer 29116495Sspeer data = nxgep->tx_buf_pool_p->dma_buf_pool_p[channel]; 29126495Sspeer num_chunks = nxgep->tx_buf_pool_p->num_chunks[channel]; 29136495Sspeer nxge_free_tx_buf_dma(nxgep, data, num_chunks); 29146495Sspeer 29156495Sspeer nxgep->tx_buf_pool_p->dma_buf_pool_p[channel] = 0; 29166495Sspeer nxgep->tx_buf_pool_p->num_chunks[channel] = 0; 29176495Sspeer 29186495Sspeer control = nxgep->tx_cntl_pool_p->dma_buf_pool_p[channel]; 29196495Sspeer nxge_free_tx_cntl_dma(nxgep, control); 29206495Sspeer 29216495Sspeer nxgep->tx_cntl_pool_p->dma_buf_pool_p[channel] = 0; 29226495Sspeer 29236495Sspeer KMEM_FREE(data, sizeof (nxge_dma_common_t) * NXGE_DMA_BLOCK); 29246495Sspeer KMEM_FREE(control, sizeof (nxge_dma_common_t)); 29256495Sspeer 29266495Sspeer NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_free_txb")); 29276495Sspeer } 29286495Sspeer 29296495Sspeer /* 29306495Sspeer * nxge_alloc_tx_mem_pool 29316495Sspeer * 29326495Sspeer * This function allocates all of the per-port TDC control data structures. 29336495Sspeer * The per-channel (TDC) data structures are allocated when needed. 29346495Sspeer * 29356495Sspeer * Arguments: 29366495Sspeer * nxgep 29376495Sspeer * 29386495Sspeer * Notes: 29396495Sspeer * 29406495Sspeer * Context: 29416495Sspeer * Any domain 29426495Sspeer */ 29436495Sspeer nxge_status_t 29443859Sml29623 nxge_alloc_tx_mem_pool(p_nxge_t nxgep) 29453859Sml29623 { 29466495Sspeer nxge_hw_pt_cfg_t *p_cfgp; 29476495Sspeer nxge_dma_pool_t *dma_poolp; 29486495Sspeer nxge_dma_common_t **dma_buf_p; 29496495Sspeer nxge_dma_pool_t *dma_cntl_poolp; 29506495Sspeer nxge_dma_common_t **dma_cntl_p; 29513859Sml29623 uint32_t *num_chunks; /* per dma */ 29526495Sspeer int tdc_max; 29533859Sml29623 29543859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM_CTL, "==> nxge_alloc_tx_mem_pool")); 29553859Sml29623 29566495Sspeer p_cfgp = &nxgep->pt_config.hw_config; 29576495Sspeer tdc_max = NXGE_MAX_TDCS; 29586495Sspeer 29593859Sml29623 /* 29603859Sml29623 * Allocate memory for each transmit DMA channel. 29613859Sml29623 */ 29623859Sml29623 dma_poolp = (p_nxge_dma_pool_t)KMEM_ZALLOC(sizeof (nxge_dma_pool_t), 29636512Ssowmini KM_SLEEP); 29643859Sml29623 dma_buf_p = (p_nxge_dma_common_t *)KMEM_ZALLOC( 29656512Ssowmini sizeof (p_nxge_dma_common_t) * tdc_max, KM_SLEEP); 29663859Sml29623 29673859Sml29623 dma_cntl_poolp = (p_nxge_dma_pool_t) 29686512Ssowmini KMEM_ZALLOC(sizeof (nxge_dma_pool_t), KM_SLEEP); 29693859Sml29623 dma_cntl_p = (p_nxge_dma_common_t *)KMEM_ZALLOC( 29706512Ssowmini sizeof (p_nxge_dma_common_t) * tdc_max, KM_SLEEP); 29713859Sml29623 29725770Sml29623 if (nxge_tx_ring_size > TDC_DEFAULT_MAX) { 29735770Sml29623 NXGE_DEBUG_MSG((nxgep, MEM_CTL, 29745770Sml29623 "nxge_alloc_tx_mem_pool: TDC too high %d, " 29755770Sml29623 "set to default %d", 29765770Sml29623 nxge_tx_ring_size, TDC_DEFAULT_MAX)); 29775770Sml29623 nxge_tx_ring_size = TDC_DEFAULT_MAX; 29785770Sml29623 } 29795770Sml29623 29803859Sml29623 #if defined(sun4v) && defined(NIU_LP_WORKAROUND) 29813859Sml29623 /* 29823859Sml29623 * N2/NIU has limitation on the descriptor sizes (contiguous 29833859Sml29623 * memory allocation on data buffers to 4M (contig_mem_alloc) 29843859Sml29623 * and little endian for control buffers (must use the ddi/dki mem alloc 29853859Sml29623 * function). The transmit ring is limited to 8K (includes the 29863859Sml29623 * mailbox). 29873859Sml29623 */ 29883859Sml29623 if (nxgep->niu_type == N2_NIU) { 29893859Sml29623 if ((nxge_tx_ring_size > NXGE_NIU_CONTIG_TX_MAX) || 29906512Ssowmini (!ISP2(nxge_tx_ring_size))) { 29913859Sml29623 nxge_tx_ring_size = NXGE_NIU_CONTIG_TX_MAX; 29923859Sml29623 } 29933859Sml29623 } 29943859Sml29623 #endif 29953859Sml29623 29963859Sml29623 nxgep->nxge_port_tx_ring_size = nxge_tx_ring_size; 29973859Sml29623 29983859Sml29623 num_chunks = (uint32_t *)KMEM_ZALLOC( 29996512Ssowmini sizeof (uint32_t) * tdc_max, KM_SLEEP); 30006495Sspeer 30016495Sspeer dma_poolp->ndmas = p_cfgp->tdc.owned; 30023859Sml29623 dma_poolp->num_chunks = num_chunks; 30033859Sml29623 dma_poolp->dma_buf_pool_p = dma_buf_p; 30043859Sml29623 nxgep->tx_buf_pool_p = dma_poolp; 30053859Sml29623 30066495Sspeer dma_poolp->buf_allocated = B_TRUE; 30076495Sspeer 30086495Sspeer dma_cntl_poolp->ndmas = p_cfgp->tdc.owned; 30093859Sml29623 dma_cntl_poolp->dma_buf_pool_p = dma_cntl_p; 30103859Sml29623 nxgep->tx_cntl_pool_p = dma_cntl_poolp; 30113859Sml29623 30126495Sspeer dma_cntl_poolp->buf_allocated = B_TRUE; 30136495Sspeer 30146495Sspeer nxgep->tx_rings = 30156495Sspeer KMEM_ZALLOC(sizeof (tx_rings_t), KM_SLEEP); 30166495Sspeer nxgep->tx_rings->rings = 30176495Sspeer KMEM_ZALLOC(sizeof (p_tx_ring_t) * tdc_max, KM_SLEEP); 30186495Sspeer nxgep->tx_mbox_areas_p = 30196495Sspeer KMEM_ZALLOC(sizeof (tx_mbox_areas_t), KM_SLEEP); 30206495Sspeer nxgep->tx_mbox_areas_p->txmbox_areas_p = 30216495Sspeer KMEM_ZALLOC(sizeof (p_tx_mbox_t) * tdc_max, KM_SLEEP); 30226495Sspeer 30236495Sspeer nxgep->tx_rings->ndmas = p_cfgp->tdc.owned; 30246495Sspeer 30253859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM_CTL, 30266512Ssowmini "==> nxge_alloc_tx_mem_pool: ndmas %d poolp->ndmas %d", 30276512Ssowmini tdc_max, dma_poolp->ndmas)); 30286495Sspeer 30296495Sspeer return (NXGE_OK); 30303859Sml29623 } 30313859Sml29623 30326495Sspeer nxge_status_t 30333859Sml29623 nxge_alloc_tx_buf_dma(p_nxge_t nxgep, uint16_t dma_channel, 30343859Sml29623 p_nxge_dma_common_t *dmap, size_t alloc_size, 30353859Sml29623 size_t block_size, uint32_t *num_chunks) 30363859Sml29623 { 30373859Sml29623 p_nxge_dma_common_t tx_dmap; 30383859Sml29623 nxge_status_t status = NXGE_OK; 30393859Sml29623 size_t total_alloc_size; 30403859Sml29623 size_t allocated = 0; 30413859Sml29623 int i, size_index, array_size; 30423859Sml29623 30433859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_alloc_tx_buf_dma")); 30443859Sml29623 30453859Sml29623 tx_dmap = (p_nxge_dma_common_t) 30466512Ssowmini KMEM_ZALLOC(sizeof (nxge_dma_common_t) * NXGE_DMA_BLOCK, 30476512Ssowmini KM_SLEEP); 30483859Sml29623 30493859Sml29623 total_alloc_size = alloc_size; 30503859Sml29623 i = 0; 30513859Sml29623 size_index = 0; 30523859Sml29623 array_size = sizeof (alloc_sizes) / sizeof (size_t); 30538661SSantwona.Behera@Sun.COM while ((size_index < array_size) && 30548661SSantwona.Behera@Sun.COM (alloc_sizes[size_index] < alloc_size)) 30553859Sml29623 size_index++; 30563859Sml29623 if (size_index >= array_size) { 30573859Sml29623 size_index = array_size - 1; 30583859Sml29623 } 30593859Sml29623 30603859Sml29623 while ((allocated < total_alloc_size) && 30616512Ssowmini (size_index >= 0) && (i < NXGE_DMA_BLOCK)) { 30623859Sml29623 30633859Sml29623 tx_dmap[i].dma_chunk_index = i; 30643859Sml29623 tx_dmap[i].block_size = block_size; 30653859Sml29623 tx_dmap[i].alength = alloc_sizes[size_index]; 30663859Sml29623 tx_dmap[i].orig_alength = tx_dmap[i].alength; 30673859Sml29623 tx_dmap[i].nblocks = alloc_sizes[size_index] / block_size; 30683859Sml29623 tx_dmap[i].dma_channel = dma_channel; 30693859Sml29623 tx_dmap[i].contig_alloc_type = B_FALSE; 30706495Sspeer tx_dmap[i].kmem_alloc_type = B_FALSE; 30713859Sml29623 30723859Sml29623 /* 30733859Sml29623 * N2/NIU: data buffers must be contiguous as the driver 30743859Sml29623 * needs to call Hypervisor api to set up 30753859Sml29623 * logical pages. 30763859Sml29623 */ 30773859Sml29623 if ((nxgep->niu_type == N2_NIU) && (NXGE_DMA_BLOCK == 1)) { 30783859Sml29623 tx_dmap[i].contig_alloc_type = B_TRUE; 30793859Sml29623 } 30803859Sml29623 30813859Sml29623 status = nxge_dma_mem_alloc(nxgep, nxge_force_dma, 30826512Ssowmini &nxge_tx_dma_attr, 30836512Ssowmini tx_dmap[i].alength, 30846512Ssowmini &nxge_dev_buf_dma_acc_attr, 30856512Ssowmini DDI_DMA_WRITE | DDI_DMA_STREAMING, 30866512Ssowmini (p_nxge_dma_common_t)(&tx_dmap[i])); 30873859Sml29623 if (status != NXGE_OK) { 30883859Sml29623 size_index--; 30893859Sml29623 } else { 30903859Sml29623 i++; 30913859Sml29623 allocated += alloc_sizes[size_index]; 30923859Sml29623 } 30933859Sml29623 } 30943859Sml29623 30953859Sml29623 if (allocated < total_alloc_size) { 30965770Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 30975770Sml29623 "==> nxge_alloc_tx_buf_dma: not enough channel %d: " 30985770Sml29623 "allocated 0x%x requested 0x%x", 30995770Sml29623 dma_channel, 31005770Sml29623 allocated, total_alloc_size)); 31015770Sml29623 status = NXGE_ERROR; 31023859Sml29623 goto nxge_alloc_tx_mem_fail1; 31033859Sml29623 } 31043859Sml29623 31055770Sml29623 NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 31065770Sml29623 "==> nxge_alloc_tx_buf_dma: Allocated for channel %d: " 31075770Sml29623 "allocated 0x%x requested 0x%x", 31085770Sml29623 dma_channel, 31095770Sml29623 allocated, total_alloc_size)); 31105770Sml29623 31113859Sml29623 *num_chunks = i; 31123859Sml29623 *dmap = tx_dmap; 31133859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, 31146512Ssowmini "==> nxge_alloc_tx_buf_dma dmap 0x%016llx num chunks %d", 31156512Ssowmini *dmap, i)); 31163859Sml29623 goto nxge_alloc_tx_mem_exit; 31173859Sml29623 31183859Sml29623 nxge_alloc_tx_mem_fail1: 31193859Sml29623 KMEM_FREE(tx_dmap, sizeof (nxge_dma_common_t) * NXGE_DMA_BLOCK); 31203859Sml29623 31213859Sml29623 nxge_alloc_tx_mem_exit: 31223859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, 31236512Ssowmini "<== nxge_alloc_tx_buf_dma status 0x%08x", status)); 31243859Sml29623 31253859Sml29623 return (status); 31263859Sml29623 } 31273859Sml29623 31283859Sml29623 /*ARGSUSED*/ 31293859Sml29623 static void 31303859Sml29623 nxge_free_tx_buf_dma(p_nxge_t nxgep, p_nxge_dma_common_t dmap, 31313859Sml29623 uint32_t num_chunks) 31323859Sml29623 { 31333859Sml29623 int i; 31343859Sml29623 31353859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM_CTL, "==> nxge_free_tx_buf_dma")); 31363859Sml29623 31376495Sspeer if (dmap == 0) 31386495Sspeer return; 31396495Sspeer 31403859Sml29623 for (i = 0; i < num_chunks; i++) { 31413859Sml29623 nxge_dma_mem_free(dmap++); 31423859Sml29623 } 31433859Sml29623 31443859Sml29623 NXGE_DEBUG_MSG((nxgep, MEM_CTL, "<== nxge_free_tx_buf_dma")); 31453859Sml29623 } 31463859Sml29623 31473859Sml29623 /*ARGSUSED*/ 31486495Sspeer nxge_status_t 31493859Sml29623 nxge_alloc_tx_cntl_dma(p_nxge_t nxgep, uint16_t dma_channel, 31503859Sml29623 p_nxge_dma_common_t *dmap, size_t size) 31513859Sml29623 { 31523859Sml29623 p_nxge_dma_common_t tx_dmap; 31533859Sml29623 nxge_status_t status = NXGE_OK; 31543859Sml29623 31553859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_alloc_tx_cntl_dma")); 31563859Sml29623 tx_dmap = (p_nxge_dma_common_t) 31576512Ssowmini KMEM_ZALLOC(sizeof (nxge_dma_common_t), KM_SLEEP); 31583859Sml29623 31593859Sml29623 tx_dmap->contig_alloc_type = B_FALSE; 31606495Sspeer tx_dmap->kmem_alloc_type = B_FALSE; 31613859Sml29623 31623859Sml29623 status = nxge_dma_mem_alloc(nxgep, nxge_force_dma, 31636512Ssowmini &nxge_desc_dma_attr, 31646512Ssowmini size, 31656512Ssowmini &nxge_dev_desc_dma_acc_attr, 31666512Ssowmini DDI_DMA_RDWR | DDI_DMA_CONSISTENT, 31676512Ssowmini tx_dmap); 31683859Sml29623 if (status != NXGE_OK) { 31693859Sml29623 goto nxge_alloc_tx_cntl_dma_fail1; 31703859Sml29623 } 31713859Sml29623 31723859Sml29623 *dmap = tx_dmap; 31733859Sml29623 goto nxge_alloc_tx_cntl_dma_exit; 31743859Sml29623 31753859Sml29623 nxge_alloc_tx_cntl_dma_fail1: 31763859Sml29623 KMEM_FREE(tx_dmap, sizeof (nxge_dma_common_t)); 31773859Sml29623 31783859Sml29623 nxge_alloc_tx_cntl_dma_exit: 31793859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, 31806512Ssowmini "<== nxge_alloc_tx_cntl_dma status 0x%08x", status)); 31813859Sml29623 31823859Sml29623 return (status); 31833859Sml29623 } 31843859Sml29623 31853859Sml29623 /*ARGSUSED*/ 31863859Sml29623 static void 31873859Sml29623 nxge_free_tx_cntl_dma(p_nxge_t nxgep, p_nxge_dma_common_t dmap) 31883859Sml29623 { 31893859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "==> nxge_free_tx_cntl_dma")); 31903859Sml29623 31916495Sspeer if (dmap == 0) 31926495Sspeer return; 31936495Sspeer 31943859Sml29623 nxge_dma_mem_free(dmap); 31953859Sml29623 31963859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_free_tx_cntl_dma")); 31973859Sml29623 } 31983859Sml29623 31996495Sspeer /* 32006495Sspeer * nxge_free_tx_mem_pool 32016495Sspeer * 32026495Sspeer * This function frees all of the per-port TDC control data structures. 32036495Sspeer * The per-channel (TDC) data structures are freed when the channel 32046495Sspeer * is stopped. 32056495Sspeer * 32066495Sspeer * Arguments: 32076495Sspeer * nxgep 32086495Sspeer * 32096495Sspeer * Notes: 32106495Sspeer * 32116495Sspeer * Context: 32126495Sspeer * Any domain 32136495Sspeer */ 32143859Sml29623 static void 32153859Sml29623 nxge_free_tx_mem_pool(p_nxge_t nxgep) 32163859Sml29623 { 32176495Sspeer int tdc_max = NXGE_MAX_TDCS; 32186495Sspeer 32196495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_free_tx_mem_pool")); 32206495Sspeer 32216495Sspeer if (!nxgep->tx_buf_pool_p || !nxgep->tx_buf_pool_p->buf_allocated) { 32226495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 32236512Ssowmini "<== nxge_free_tx_mem_pool " 32246512Ssowmini "(null tx buf pool or buf not allocated")); 32253859Sml29623 return; 32263859Sml29623 } 32276495Sspeer if (!nxgep->tx_cntl_pool_p || !nxgep->tx_cntl_pool_p->buf_allocated) { 32286495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, 32296512Ssowmini "<== nxge_free_tx_mem_pool " 32306512Ssowmini "(null tx cntl buf pool or cntl buf not allocated")); 32313859Sml29623 return; 32323859Sml29623 } 32333859Sml29623 32346495Sspeer /* 1. Free the mailboxes. */ 32356495Sspeer KMEM_FREE(nxgep->tx_mbox_areas_p->txmbox_areas_p, 32366495Sspeer sizeof (p_tx_mbox_t) * tdc_max); 32376495Sspeer KMEM_FREE(nxgep->tx_mbox_areas_p, sizeof (tx_mbox_areas_t)); 32386495Sspeer 32396495Sspeer nxgep->tx_mbox_areas_p = 0; 32406495Sspeer 32416495Sspeer /* 2. Free the transmit ring arrays. */ 32426495Sspeer KMEM_FREE(nxgep->tx_rings->rings, 32436495Sspeer sizeof (p_tx_ring_t) * tdc_max); 32446495Sspeer KMEM_FREE(nxgep->tx_rings, sizeof (tx_rings_t)); 32456495Sspeer 32466495Sspeer nxgep->tx_rings = 0; 32476495Sspeer 32486495Sspeer /* 3. Free the completion ring data structures. */ 32496495Sspeer KMEM_FREE(nxgep->tx_cntl_pool_p->dma_buf_pool_p, 32506495Sspeer sizeof (p_nxge_dma_common_t) * tdc_max); 32516495Sspeer KMEM_FREE(nxgep->tx_cntl_pool_p, sizeof (nxge_dma_pool_t)); 32526495Sspeer 32536495Sspeer nxgep->tx_cntl_pool_p = 0; 32546495Sspeer 32556495Sspeer /* 4. Free the data ring data structures. */ 32566495Sspeer KMEM_FREE(nxgep->tx_buf_pool_p->num_chunks, 32576495Sspeer sizeof (uint32_t) * tdc_max); 32586495Sspeer KMEM_FREE(nxgep->tx_buf_pool_p->dma_buf_pool_p, 32596495Sspeer sizeof (p_nxge_dma_common_t) * tdc_max); 32606495Sspeer KMEM_FREE(nxgep->tx_buf_pool_p, sizeof (nxge_dma_pool_t)); 32616495Sspeer 32626495Sspeer nxgep->tx_buf_pool_p = 0; 32636495Sspeer 32646495Sspeer NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "<== nxge_free_tx_mem_pool")); 32653859Sml29623 } 32663859Sml29623 32673859Sml29623 /*ARGSUSED*/ 32683859Sml29623 static nxge_status_t 32693859Sml29623 nxge_dma_mem_alloc(p_nxge_t nxgep, dma_method_t method, 32703859Sml29623 struct ddi_dma_attr *dma_attrp, 32713859Sml29623 size_t length, ddi_device_acc_attr_t *acc_attr_p, uint_t xfer_flags, 32723859Sml29623 p_nxge_dma_common_t dma_p) 32733859Sml29623 { 32743859Sml29623 caddr_t kaddrp; 32753859Sml29623 int ddi_status = DDI_SUCCESS; 32763859Sml29623 boolean_t contig_alloc_type; 32776495Sspeer boolean_t kmem_alloc_type; 32783859Sml29623 32793859Sml29623 contig_alloc_type = dma_p->contig_alloc_type; 32803859Sml29623 32813859Sml29623 if (contig_alloc_type && (nxgep->niu_type != N2_NIU)) { 32823859Sml29623 /* 32833859Sml29623 * contig_alloc_type for contiguous memory only allowed 32843859Sml29623 * for N2/NIU. 32853859Sml29623 */ 32863859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 32876512Ssowmini "nxge_dma_mem_alloc: alloc type not allowed (%d)", 32886512Ssowmini dma_p->contig_alloc_type)); 32893859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 32903859Sml29623 } 32913859Sml29623 32923859Sml29623 dma_p->dma_handle = NULL; 32933859Sml29623 dma_p->acc_handle = NULL; 32943859Sml29623 dma_p->kaddrp = dma_p->last_kaddrp = NULL; 32953859Sml29623 dma_p->first_ioaddr_pp = dma_p->last_ioaddr_pp = NULL; 32963859Sml29623 ddi_status = ddi_dma_alloc_handle(nxgep->dip, dma_attrp, 32976512Ssowmini DDI_DMA_DONTWAIT, NULL, &dma_p->dma_handle); 32983859Sml29623 if (ddi_status != DDI_SUCCESS) { 32993859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 33006512Ssowmini "nxge_dma_mem_alloc:ddi_dma_alloc_handle failed.")); 33013859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 33023859Sml29623 } 33033859Sml29623 33046495Sspeer kmem_alloc_type = dma_p->kmem_alloc_type; 33056495Sspeer 33063859Sml29623 switch (contig_alloc_type) { 33073859Sml29623 case B_FALSE: 33086495Sspeer switch (kmem_alloc_type) { 33096495Sspeer case B_FALSE: 33106495Sspeer ddi_status = ddi_dma_mem_alloc(dma_p->dma_handle, 33116512Ssowmini length, 33126512Ssowmini acc_attr_p, 33136512Ssowmini xfer_flags, 33146512Ssowmini DDI_DMA_DONTWAIT, 0, &kaddrp, &dma_p->alength, 33156512Ssowmini &dma_p->acc_handle); 33166495Sspeer if (ddi_status != DDI_SUCCESS) { 33176495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 33186495Sspeer "nxge_dma_mem_alloc: " 33196495Sspeer "ddi_dma_mem_alloc failed")); 33206495Sspeer ddi_dma_free_handle(&dma_p->dma_handle); 33216495Sspeer dma_p->dma_handle = NULL; 33226495Sspeer return (NXGE_ERROR | NXGE_DDI_FAILED); 33236495Sspeer } 33246495Sspeer if (dma_p->alength < length) { 33256495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 33266495Sspeer "nxge_dma_mem_alloc:di_dma_mem_alloc " 33276495Sspeer "< length.")); 33286495Sspeer ddi_dma_mem_free(&dma_p->acc_handle); 33296495Sspeer ddi_dma_free_handle(&dma_p->dma_handle); 33306495Sspeer dma_p->acc_handle = NULL; 33316495Sspeer dma_p->dma_handle = NULL; 33326495Sspeer return (NXGE_ERROR); 33336495Sspeer } 33346495Sspeer 33356495Sspeer ddi_status = ddi_dma_addr_bind_handle(dma_p->dma_handle, 33366495Sspeer NULL, 33376495Sspeer kaddrp, dma_p->alength, xfer_flags, 33386495Sspeer DDI_DMA_DONTWAIT, 33396495Sspeer 0, &dma_p->dma_cookie, &dma_p->ncookies); 33406495Sspeer if (ddi_status != DDI_DMA_MAPPED) { 33416495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 33426495Sspeer "nxge_dma_mem_alloc: ddi_dma_addr_bind " 33436495Sspeer "failed " 33446495Sspeer "(staus 0x%x ncookies %d.)", ddi_status, 33456495Sspeer dma_p->ncookies)); 33466495Sspeer if (dma_p->acc_handle) { 33476495Sspeer ddi_dma_mem_free(&dma_p->acc_handle); 33486495Sspeer dma_p->acc_handle = NULL; 33496495Sspeer } 33506495Sspeer ddi_dma_free_handle(&dma_p->dma_handle); 33516495Sspeer dma_p->dma_handle = NULL; 33526495Sspeer return (NXGE_ERROR | NXGE_DDI_FAILED); 33536495Sspeer } 33546495Sspeer 33556495Sspeer if (dma_p->ncookies != 1) { 33566495Sspeer NXGE_DEBUG_MSG((nxgep, DMA_CTL, 33576495Sspeer "nxge_dma_mem_alloc:ddi_dma_addr_bind " 33586495Sspeer "> 1 cookie" 33596495Sspeer "(staus 0x%x ncookies %d.)", ddi_status, 33606495Sspeer dma_p->ncookies)); 33617812SMichael.Speer@Sun.COM (void) ddi_dma_unbind_handle(dma_p->dma_handle); 33626495Sspeer if (dma_p->acc_handle) { 33636495Sspeer ddi_dma_mem_free(&dma_p->acc_handle); 33646495Sspeer dma_p->acc_handle = NULL; 33656495Sspeer } 33666495Sspeer ddi_dma_free_handle(&dma_p->dma_handle); 33676495Sspeer dma_p->dma_handle = NULL; 33687812SMichael.Speer@Sun.COM dma_p->acc_handle = NULL; 33696495Sspeer return (NXGE_ERROR); 33706495Sspeer } 33716495Sspeer break; 33726495Sspeer 33736495Sspeer case B_TRUE: 33746495Sspeer kaddrp = KMEM_ALLOC(length, KM_NOSLEEP); 33756495Sspeer if (kaddrp == NULL) { 33766495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 33776495Sspeer "nxge_dma_mem_alloc:ddi_dma_mem_alloc " 33786495Sspeer "kmem alloc failed")); 33796495Sspeer return (NXGE_ERROR); 33806495Sspeer } 33816495Sspeer 33826495Sspeer dma_p->alength = length; 33836495Sspeer ddi_status = ddi_dma_addr_bind_handle(dma_p->dma_handle, 33846495Sspeer NULL, kaddrp, dma_p->alength, xfer_flags, 33856495Sspeer DDI_DMA_DONTWAIT, 0, 33866495Sspeer &dma_p->dma_cookie, &dma_p->ncookies); 33876495Sspeer if (ddi_status != DDI_DMA_MAPPED) { 33886495Sspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 33896495Sspeer "nxge_dma_mem_alloc:ddi_dma_addr_bind: " 33906495Sspeer "(kmem_alloc) failed kaddrp $%p length %d " 33916495Sspeer "(staus 0x%x (%d) ncookies %d.)", 33926495Sspeer kaddrp, length, 33936495Sspeer ddi_status, ddi_status, dma_p->ncookies)); 33946495Sspeer KMEM_FREE(kaddrp, length); 33956495Sspeer dma_p->acc_handle = NULL; 33966495Sspeer ddi_dma_free_handle(&dma_p->dma_handle); 33976495Sspeer dma_p->dma_handle = NULL; 33986495Sspeer dma_p->kaddrp = NULL; 33996495Sspeer return (NXGE_ERROR | NXGE_DDI_FAILED); 34006495Sspeer } 34016495Sspeer 34026495Sspeer if (dma_p->ncookies != 1) { 34036495Sspeer NXGE_DEBUG_MSG((nxgep, DMA_CTL, 34046495Sspeer "nxge_dma_mem_alloc:ddi_dma_addr_bind " 34056495Sspeer "(kmem_alloc) > 1 cookie" 34066495Sspeer "(staus 0x%x ncookies %d.)", ddi_status, 34076512Ssowmini dma_p->ncookies)); 34087812SMichael.Speer@Sun.COM (void) ddi_dma_unbind_handle(dma_p->dma_handle); 34096495Sspeer KMEM_FREE(kaddrp, length); 34106495Sspeer ddi_dma_free_handle(&dma_p->dma_handle); 34116495Sspeer dma_p->dma_handle = NULL; 34127812SMichael.Speer@Sun.COM dma_p->acc_handle = NULL; 34136495Sspeer dma_p->kaddrp = NULL; 34146495Sspeer return (NXGE_ERROR); 34153859Sml29623 } 34166495Sspeer 34176495Sspeer dma_p->kaddrp = kaddrp; 34186495Sspeer 34196495Sspeer NXGE_DEBUG_MSG((nxgep, NXGE_ERR_CTL, 34206512Ssowmini "nxge_dma_mem_alloc: kmem_alloc dmap $%p " 34216512Ssowmini "kaddr $%p alength %d", 34226512Ssowmini dma_p, 34236512Ssowmini kaddrp, 34246512Ssowmini dma_p->alength)); 34256495Sspeer break; 34263859Sml29623 } 34273859Sml29623 break; 34283859Sml29623 34293859Sml29623 #if defined(sun4v) && defined(NIU_LP_WORKAROUND) 34303859Sml29623 case B_TRUE: 34313859Sml29623 kaddrp = (caddr_t)contig_mem_alloc(length); 34323859Sml29623 if (kaddrp == NULL) { 34333859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 34346512Ssowmini "nxge_dma_mem_alloc:contig_mem_alloc failed.")); 34353859Sml29623 ddi_dma_free_handle(&dma_p->dma_handle); 34363859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 34373859Sml29623 } 34383859Sml29623 34393859Sml29623 dma_p->alength = length; 34403859Sml29623 ddi_status = ddi_dma_addr_bind_handle(dma_p->dma_handle, NULL, 34416512Ssowmini kaddrp, dma_p->alength, xfer_flags, DDI_DMA_DONTWAIT, 0, 34426512Ssowmini &dma_p->dma_cookie, &dma_p->ncookies); 34433859Sml29623 if (ddi_status != DDI_DMA_MAPPED) { 34443859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 34456512Ssowmini "nxge_dma_mem_alloc:di_dma_addr_bind failed " 34466512Ssowmini "(status 0x%x ncookies %d.)", ddi_status, 34476512Ssowmini dma_p->ncookies)); 34483859Sml29623 34493859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, 34506512Ssowmini "==> nxge_dma_mem_alloc: (not mapped)" 34516512Ssowmini "length %lu (0x%x) " 34526512Ssowmini "free contig kaddrp $%p " 34536512Ssowmini "va_to_pa $%p", 34546512Ssowmini length, length, 34556512Ssowmini kaddrp, 34566512Ssowmini va_to_pa(kaddrp))); 34573859Sml29623 34583859Sml29623 34593859Sml29623 contig_mem_free((void *)kaddrp, length); 34603859Sml29623 ddi_dma_free_handle(&dma_p->dma_handle); 34613859Sml29623 34623859Sml29623 dma_p->dma_handle = NULL; 34633859Sml29623 dma_p->acc_handle = NULL; 34643859Sml29623 dma_p->alength = NULL; 34653859Sml29623 dma_p->kaddrp = NULL; 34663859Sml29623 34673859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 34683859Sml29623 } 34693859Sml29623 34703859Sml29623 if (dma_p->ncookies != 1 || 34716512Ssowmini (dma_p->dma_cookie.dmac_laddress == NULL)) { 34723859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 34736512Ssowmini "nxge_dma_mem_alloc:di_dma_addr_bind > 1 " 34746512Ssowmini "cookie or " 34756512Ssowmini "dmac_laddress is NULL $%p size %d " 34766512Ssowmini " (status 0x%x ncookies %d.)", 34776512Ssowmini ddi_status, 34786512Ssowmini dma_p->dma_cookie.dmac_laddress, 34796512Ssowmini dma_p->dma_cookie.dmac_size, 34806512Ssowmini dma_p->ncookies)); 34813859Sml29623 34823859Sml29623 contig_mem_free((void *)kaddrp, length); 34834185Sspeer (void) ddi_dma_unbind_handle(dma_p->dma_handle); 34843859Sml29623 ddi_dma_free_handle(&dma_p->dma_handle); 34853859Sml29623 34863859Sml29623 dma_p->alength = 0; 34873859Sml29623 dma_p->dma_handle = NULL; 34883859Sml29623 dma_p->acc_handle = NULL; 34893859Sml29623 dma_p->kaddrp = NULL; 34903859Sml29623 34913859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 34923859Sml29623 } 34933859Sml29623 break; 34943859Sml29623 34953859Sml29623 #else 34963859Sml29623 case B_TRUE: 34973859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 34986512Ssowmini "nxge_dma_mem_alloc: invalid alloc type for !sun4v")); 34993859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 35003859Sml29623 #endif 35013859Sml29623 } 35023859Sml29623 35033859Sml29623 dma_p->kaddrp = kaddrp; 35043859Sml29623 dma_p->last_kaddrp = (unsigned char *)kaddrp + 35056512Ssowmini dma_p->alength - RXBUF_64B_ALIGNED; 35065125Sjoycey #if defined(__i386) 35075125Sjoycey dma_p->ioaddr_pp = 35086512Ssowmini (unsigned char *)(uint32_t)dma_p->dma_cookie.dmac_laddress; 35095125Sjoycey #else 35103859Sml29623 dma_p->ioaddr_pp = (unsigned char *)dma_p->dma_cookie.dmac_laddress; 35115125Sjoycey #endif 35123859Sml29623 dma_p->last_ioaddr_pp = 35135125Sjoycey #if defined(__i386) 35146512Ssowmini (unsigned char *)(uint32_t)dma_p->dma_cookie.dmac_laddress + 35155125Sjoycey #else 35166512Ssowmini (unsigned char *)dma_p->dma_cookie.dmac_laddress + 35175125Sjoycey #endif 35186512Ssowmini dma_p->alength - RXBUF_64B_ALIGNED; 35193859Sml29623 35203859Sml29623 NPI_DMA_ACC_HANDLE_SET(dma_p, dma_p->acc_handle); 35213859Sml29623 35223859Sml29623 #if defined(sun4v) && defined(NIU_LP_WORKAROUND) 35233859Sml29623 dma_p->orig_ioaddr_pp = 35246512Ssowmini (unsigned char *)dma_p->dma_cookie.dmac_laddress; 35253859Sml29623 dma_p->orig_alength = length; 35263859Sml29623 dma_p->orig_kaddrp = kaddrp; 35273859Sml29623 dma_p->orig_vatopa = (uint64_t)va_to_pa(kaddrp); 35283859Sml29623 #endif 35293859Sml29623 35303859Sml29623 NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_dma_mem_alloc: " 35316512Ssowmini "dma buffer allocated: dma_p $%p " 35326512Ssowmini "return dmac_ladress from cookie $%p cookie dmac_size %d " 35336512Ssowmini "dma_p->ioaddr_p $%p " 35346512Ssowmini "dma_p->orig_ioaddr_p $%p " 35356512Ssowmini "orig_vatopa $%p " 35366512Ssowmini "alength %d (0x%x) " 35376512Ssowmini "kaddrp $%p " 35386512Ssowmini "length %d (0x%x)", 35396512Ssowmini dma_p, 35406512Ssowmini dma_p->dma_cookie.dmac_laddress, dma_p->dma_cookie.dmac_size, 35416512Ssowmini dma_p->ioaddr_pp, 35426512Ssowmini dma_p->orig_ioaddr_pp, 35436512Ssowmini dma_p->orig_vatopa, 35446512Ssowmini dma_p->alength, dma_p->alength, 35456512Ssowmini kaddrp, 35466512Ssowmini length, length)); 35473859Sml29623 35483859Sml29623 return (NXGE_OK); 35493859Sml29623 } 35503859Sml29623 35513859Sml29623 static void 35523859Sml29623 nxge_dma_mem_free(p_nxge_dma_common_t dma_p) 35533859Sml29623 { 35543859Sml29623 if (dma_p->dma_handle != NULL) { 35553859Sml29623 if (dma_p->ncookies) { 35563859Sml29623 (void) ddi_dma_unbind_handle(dma_p->dma_handle); 35573859Sml29623 dma_p->ncookies = 0; 35583859Sml29623 } 35593859Sml29623 ddi_dma_free_handle(&dma_p->dma_handle); 35603859Sml29623 dma_p->dma_handle = NULL; 35613859Sml29623 } 35623859Sml29623 35633859Sml29623 if (dma_p->acc_handle != NULL) { 35643859Sml29623 ddi_dma_mem_free(&dma_p->acc_handle); 35653859Sml29623 dma_p->acc_handle = NULL; 35663859Sml29623 NPI_DMA_ACC_HANDLE_SET(dma_p, NULL); 35673859Sml29623 } 35683859Sml29623 35693859Sml29623 #if defined(sun4v) && defined(NIU_LP_WORKAROUND) 35703859Sml29623 if (dma_p->contig_alloc_type && 35716512Ssowmini dma_p->orig_kaddrp && dma_p->orig_alength) { 35723859Sml29623 NXGE_DEBUG_MSG((NULL, DMA_CTL, "nxge_dma_mem_free: " 35736512Ssowmini "kaddrp $%p (orig_kaddrp $%p)" 35746512Ssowmini "mem type %d ", 35756512Ssowmini "orig_alength %d " 35766512Ssowmini "alength 0x%x (%d)", 35776512Ssowmini dma_p->kaddrp, 35786512Ssowmini dma_p->orig_kaddrp, 35796512Ssowmini dma_p->contig_alloc_type, 35806512Ssowmini dma_p->orig_alength, 35816512Ssowmini dma_p->alength, dma_p->alength)); 35823859Sml29623 35833859Sml29623 contig_mem_free(dma_p->orig_kaddrp, dma_p->orig_alength); 35843859Sml29623 dma_p->orig_alength = NULL; 35853859Sml29623 dma_p->orig_kaddrp = NULL; 35863859Sml29623 dma_p->contig_alloc_type = B_FALSE; 35873859Sml29623 } 35883859Sml29623 #endif 35893859Sml29623 dma_p->kaddrp = NULL; 35903859Sml29623 dma_p->alength = NULL; 35913859Sml29623 } 35923859Sml29623 35936495Sspeer static void 35946495Sspeer nxge_dma_free_rx_data_buf(p_nxge_dma_common_t dma_p) 35956495Sspeer { 35966495Sspeer uint64_t kaddr; 35976495Sspeer uint32_t buf_size; 35986495Sspeer 35996495Sspeer NXGE_DEBUG_MSG((NULL, DMA_CTL, "==> nxge_dma_free_rx_data_buf")); 36006495Sspeer 36016495Sspeer if (dma_p->dma_handle != NULL) { 36026495Sspeer if (dma_p->ncookies) { 36036495Sspeer (void) ddi_dma_unbind_handle(dma_p->dma_handle); 36046495Sspeer dma_p->ncookies = 0; 36056495Sspeer } 36066495Sspeer ddi_dma_free_handle(&dma_p->dma_handle); 36076495Sspeer dma_p->dma_handle = NULL; 36086495Sspeer } 36096495Sspeer 36106495Sspeer if (dma_p->acc_handle != NULL) { 36116495Sspeer ddi_dma_mem_free(&dma_p->acc_handle); 36126495Sspeer dma_p->acc_handle = NULL; 36136495Sspeer NPI_DMA_ACC_HANDLE_SET(dma_p, NULL); 36146495Sspeer } 36156495Sspeer 36166495Sspeer NXGE_DEBUG_MSG((NULL, DMA_CTL, 36176495Sspeer "==> nxge_dma_free_rx_data_buf: dmap $%p buf_alloc_state %d", 36186495Sspeer dma_p, 36196495Sspeer dma_p->buf_alloc_state)); 36206495Sspeer 36216495Sspeer if (!(dma_p->buf_alloc_state & BUF_ALLOCATED_WAIT_FREE)) { 36226495Sspeer NXGE_DEBUG_MSG((NULL, DMA_CTL, 36236495Sspeer "<== nxge_dma_free_rx_data_buf: " 36246495Sspeer "outstanding data buffers")); 36256495Sspeer return; 36266495Sspeer } 36276495Sspeer 36286495Sspeer #if defined(sun4v) && defined(NIU_LP_WORKAROUND) 36296495Sspeer if (dma_p->contig_alloc_type && 36306512Ssowmini dma_p->orig_kaddrp && dma_p->orig_alength) { 36316495Sspeer NXGE_DEBUG_MSG((NULL, DMA_CTL, "nxge_dma_free_rx_data_buf: " 36326495Sspeer "kaddrp $%p (orig_kaddrp $%p)" 36336495Sspeer "mem type %d ", 36346495Sspeer "orig_alength %d " 36356495Sspeer "alength 0x%x (%d)", 36366495Sspeer dma_p->kaddrp, 36376495Sspeer dma_p->orig_kaddrp, 36386495Sspeer dma_p->contig_alloc_type, 36396495Sspeer dma_p->orig_alength, 36406495Sspeer dma_p->alength, dma_p->alength)); 36416495Sspeer 36426495Sspeer kaddr = (uint64_t)dma_p->orig_kaddrp; 36436495Sspeer buf_size = dma_p->orig_alength; 36446495Sspeer nxge_free_buf(CONTIG_MEM_ALLOC, kaddr, buf_size); 36456495Sspeer dma_p->orig_alength = NULL; 36466495Sspeer dma_p->orig_kaddrp = NULL; 36476495Sspeer dma_p->contig_alloc_type = B_FALSE; 36486495Sspeer dma_p->kaddrp = NULL; 36496495Sspeer dma_p->alength = NULL; 36506495Sspeer return; 36516495Sspeer } 36526495Sspeer #endif 36536495Sspeer 36546495Sspeer if (dma_p->kmem_alloc_type) { 36556495Sspeer NXGE_DEBUG_MSG((NULL, DMA_CTL, 36566495Sspeer "nxge_dma_free_rx_data_buf: free kmem " 36576512Ssowmini "kaddrp $%p (orig_kaddrp $%p)" 36586512Ssowmini "alloc type %d " 36596512Ssowmini "orig_alength %d " 36606512Ssowmini "alength 0x%x (%d)", 36616512Ssowmini dma_p->kaddrp, 36626512Ssowmini dma_p->orig_kaddrp, 36636512Ssowmini dma_p->kmem_alloc_type, 36646512Ssowmini dma_p->orig_alength, 36656512Ssowmini dma_p->alength, dma_p->alength)); 36666495Sspeer #if defined(__i386) 36676495Sspeer kaddr = (uint64_t)(uint32_t)dma_p->kaddrp; 36686495Sspeer #else 36696495Sspeer kaddr = (uint64_t)dma_p->kaddrp; 36706495Sspeer #endif 36716495Sspeer buf_size = dma_p->orig_alength; 36726495Sspeer NXGE_DEBUG_MSG((NULL, DMA_CTL, 36736495Sspeer "nxge_dma_free_rx_data_buf: free dmap $%p " 36746495Sspeer "kaddr $%p buf_size %d", 36756495Sspeer dma_p, 36766495Sspeer kaddr, buf_size)); 36776495Sspeer nxge_free_buf(KMEM_ALLOC, kaddr, buf_size); 36786495Sspeer dma_p->alength = 0; 36796495Sspeer dma_p->orig_alength = 0; 36806495Sspeer dma_p->kaddrp = NULL; 36816495Sspeer dma_p->kmem_alloc_type = B_FALSE; 36826495Sspeer } 36836495Sspeer 36846495Sspeer NXGE_DEBUG_MSG((NULL, DMA_CTL, "<== nxge_dma_free_rx_data_buf")); 36856495Sspeer } 36866495Sspeer 36873859Sml29623 /* 36883859Sml29623 * nxge_m_start() -- start transmitting and receiving. 36893859Sml29623 * 36903859Sml29623 * This function is called by the MAC layer when the first 36913859Sml29623 * stream is open to prepare the hardware ready for sending 36923859Sml29623 * and transmitting packets. 36933859Sml29623 */ 36943859Sml29623 static int 36953859Sml29623 nxge_m_start(void *arg) 36963859Sml29623 { 36973859Sml29623 p_nxge_t nxgep = (p_nxge_t)arg; 36983859Sml29623 36993859Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, "==> nxge_m_start")); 37003859Sml29623 37019232SMichael.Speer@Sun.COM /* 37029232SMichael.Speer@Sun.COM * Are we already started? 37039232SMichael.Speer@Sun.COM */ 37049232SMichael.Speer@Sun.COM if (nxgep->nxge_mac_state == NXGE_MAC_STARTED) { 37059232SMichael.Speer@Sun.COM return (0); 37069232SMichael.Speer@Sun.COM } 37079232SMichael.Speer@Sun.COM 37086705Sml29623 if (nxge_peu_reset_enable && !nxgep->nxge_link_poll_timerid) { 37096705Sml29623 (void) nxge_link_monitor(nxgep, LINK_MONITOR_START); 37106705Sml29623 } 37116705Sml29623 37129232SMichael.Speer@Sun.COM /* 37139232SMichael.Speer@Sun.COM * Make sure RX MAC is disabled while we initialize. 37149232SMichael.Speer@Sun.COM */ 37159232SMichael.Speer@Sun.COM if (!isLDOMguest(nxgep)) { 37169232SMichael.Speer@Sun.COM (void) nxge_rx_mac_disable(nxgep); 37179232SMichael.Speer@Sun.COM } 37189232SMichael.Speer@Sun.COM 37199232SMichael.Speer@Sun.COM /* 37209232SMichael.Speer@Sun.COM * Grab the global lock. 37219232SMichael.Speer@Sun.COM */ 37223859Sml29623 MUTEX_ENTER(nxgep->genlock); 37239232SMichael.Speer@Sun.COM 37249232SMichael.Speer@Sun.COM /* 37259232SMichael.Speer@Sun.COM * Initialize the driver and hardware. 37269232SMichael.Speer@Sun.COM */ 37273859Sml29623 if (nxge_init(nxgep) != NXGE_OK) { 37283859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 37296512Ssowmini "<== nxge_m_start: initialization failed")); 37303859Sml29623 MUTEX_EXIT(nxgep->genlock); 37313859Sml29623 return (EIO); 37323859Sml29623 } 37333859Sml29623 37343859Sml29623 /* 37353859Sml29623 * Start timer to check the system error and tx hangs 37363859Sml29623 */ 37376495Sspeer if (!isLDOMguest(nxgep)) 37386495Sspeer nxgep->nxge_timerid = nxge_start_timer(nxgep, 37396495Sspeer nxge_check_hw_state, NXGE_CHECK_TIMER); 37409232SMichael.Speer@Sun.COM #if defined(sun4v) 37416495Sspeer else 37426495Sspeer nxge_hio_start_timer(nxgep); 37436495Sspeer #endif 37443859Sml29623 37453859Sml29623 nxgep->link_notify = B_TRUE; 37463859Sml29623 nxgep->nxge_mac_state = NXGE_MAC_STARTED; 37473859Sml29623 37489232SMichael.Speer@Sun.COM /* 37499232SMichael.Speer@Sun.COM * Let the global lock go, since we are intialized. 37509232SMichael.Speer@Sun.COM */ 37513859Sml29623 MUTEX_EXIT(nxgep->genlock); 37529232SMichael.Speer@Sun.COM 37539232SMichael.Speer@Sun.COM /* 37549232SMichael.Speer@Sun.COM * Let the MAC start receiving packets, now that 37559232SMichael.Speer@Sun.COM * we are initialized. 37569232SMichael.Speer@Sun.COM */ 37579232SMichael.Speer@Sun.COM if (!isLDOMguest(nxgep)) { 37589232SMichael.Speer@Sun.COM if (nxge_rx_mac_enable(nxgep) != NXGE_OK) { 37599232SMichael.Speer@Sun.COM NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 37609232SMichael.Speer@Sun.COM "<== nxge_m_start: enable of RX mac failed")); 37619232SMichael.Speer@Sun.COM return (EIO); 37629232SMichael.Speer@Sun.COM } 37639232SMichael.Speer@Sun.COM 37649232SMichael.Speer@Sun.COM /* 37659232SMichael.Speer@Sun.COM * Enable hardware interrupts. 37669232SMichael.Speer@Sun.COM */ 37679232SMichael.Speer@Sun.COM nxge_intr_hw_enable(nxgep); 37689232SMichael.Speer@Sun.COM } 37699232SMichael.Speer@Sun.COM #if defined(sun4v) 37709232SMichael.Speer@Sun.COM else { 37719232SMichael.Speer@Sun.COM /* 37729232SMichael.Speer@Sun.COM * In guest domain we enable RDCs and their interrupts as 37739232SMichael.Speer@Sun.COM * the last step. 37749232SMichael.Speer@Sun.COM */ 37759232SMichael.Speer@Sun.COM if (nxge_hio_rdc_enable(nxgep) != NXGE_OK) { 37769232SMichael.Speer@Sun.COM NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 37779232SMichael.Speer@Sun.COM "<== nxge_m_start: enable of RDCs failed")); 37789232SMichael.Speer@Sun.COM return (EIO); 37799232SMichael.Speer@Sun.COM } 37809232SMichael.Speer@Sun.COM 37819232SMichael.Speer@Sun.COM if (nxge_hio_rdc_intr_arm(nxgep, B_TRUE) != NXGE_OK) { 37829232SMichael.Speer@Sun.COM NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 37839232SMichael.Speer@Sun.COM "<== nxge_m_start: intrs enable for RDCs failed")); 37849232SMichael.Speer@Sun.COM return (EIO); 37859232SMichael.Speer@Sun.COM } 37869232SMichael.Speer@Sun.COM } 37879232SMichael.Speer@Sun.COM #endif 37883859Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, "<== nxge_m_start")); 37893859Sml29623 return (0); 37903859Sml29623 } 37913859Sml29623 37928275SEric Cheng static boolean_t 37938275SEric Cheng nxge_check_groups_stopped(p_nxge_t nxgep) 37948275SEric Cheng { 37958275SEric Cheng int i; 37968275SEric Cheng 37978275SEric Cheng for (i = 0; i < NXGE_MAX_RDC_GROUPS; i++) { 37988275SEric Cheng if (nxgep->rx_hio_groups[i].started) 37998275SEric Cheng return (B_FALSE); 38008275SEric Cheng } 38018275SEric Cheng 38028275SEric Cheng return (B_TRUE); 38038275SEric Cheng } 38048275SEric Cheng 38053859Sml29623 /* 38063859Sml29623 * nxge_m_stop(): stop transmitting and receiving. 38073859Sml29623 */ 38083859Sml29623 static void 38093859Sml29623 nxge_m_stop(void *arg) 38103859Sml29623 { 38113859Sml29623 p_nxge_t nxgep = (p_nxge_t)arg; 38128275SEric Cheng boolean_t groups_stopped; 38133859Sml29623 38143859Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, "==> nxge_m_stop")); 38153859Sml29623 38169232SMichael.Speer@Sun.COM /* 38179232SMichael.Speer@Sun.COM * Are the groups stopped? 38189232SMichael.Speer@Sun.COM */ 38198275SEric Cheng groups_stopped = nxge_check_groups_stopped(nxgep); 38209232SMichael.Speer@Sun.COM ASSERT(groups_stopped == B_TRUE); 38218275SEric Cheng if (!groups_stopped) { 38228275SEric Cheng cmn_err(CE_WARN, "nxge(%d): groups are not stopped!\n", 38238275SEric Cheng nxgep->instance); 38248275SEric Cheng return; 38258275SEric Cheng } 38268275SEric Cheng 38279232SMichael.Speer@Sun.COM if (!isLDOMguest(nxgep)) { 38289232SMichael.Speer@Sun.COM /* 38299232SMichael.Speer@Sun.COM * Disable the RX mac. 38309232SMichael.Speer@Sun.COM */ 38319232SMichael.Speer@Sun.COM (void) nxge_rx_mac_disable(nxgep); 38329232SMichael.Speer@Sun.COM 38339232SMichael.Speer@Sun.COM /* 38349232SMichael.Speer@Sun.COM * Wait for the IPP to drain. 38359232SMichael.Speer@Sun.COM */ 38369232SMichael.Speer@Sun.COM (void) nxge_ipp_drain(nxgep); 38379232SMichael.Speer@Sun.COM 38389232SMichael.Speer@Sun.COM /* 38399232SMichael.Speer@Sun.COM * Disable hardware interrupts. 38409232SMichael.Speer@Sun.COM */ 38419232SMichael.Speer@Sun.COM nxge_intr_hw_disable(nxgep); 38429232SMichael.Speer@Sun.COM } 38439232SMichael.Speer@Sun.COM #if defined(sun4v) 38449232SMichael.Speer@Sun.COM else { 38459232SMichael.Speer@Sun.COM (void) nxge_hio_rdc_intr_arm(nxgep, B_FALSE); 38469232SMichael.Speer@Sun.COM } 38479232SMichael.Speer@Sun.COM #endif 38489232SMichael.Speer@Sun.COM 38499232SMichael.Speer@Sun.COM /* 38509232SMichael.Speer@Sun.COM * Grab the global lock. 38519232SMichael.Speer@Sun.COM */ 38527466SMisaki.Kataoka@Sun.COM MUTEX_ENTER(nxgep->genlock); 38539232SMichael.Speer@Sun.COM 38547466SMisaki.Kataoka@Sun.COM nxgep->nxge_mac_state = NXGE_MAC_STOPPING; 38553859Sml29623 if (nxgep->nxge_timerid) { 38563859Sml29623 nxge_stop_timer(nxgep, nxgep->nxge_timerid); 38573859Sml29623 nxgep->nxge_timerid = 0; 38583859Sml29623 } 38593859Sml29623 38609232SMichael.Speer@Sun.COM /* 38619232SMichael.Speer@Sun.COM * Clean up. 38629232SMichael.Speer@Sun.COM */ 38633859Sml29623 nxge_uninit(nxgep); 38643859Sml29623 38653859Sml29623 nxgep->nxge_mac_state = NXGE_MAC_STOPPED; 38663859Sml29623 38679232SMichael.Speer@Sun.COM /* 38689232SMichael.Speer@Sun.COM * Let go of the global lock. 38699232SMichael.Speer@Sun.COM */ 38703859Sml29623 MUTEX_EXIT(nxgep->genlock); 38713859Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, "<== nxge_m_stop")); 38723859Sml29623 } 38733859Sml29623 38743859Sml29623 static int 38753859Sml29623 nxge_m_multicst(void *arg, boolean_t add, const uint8_t *mca) 38763859Sml29623 { 38773859Sml29623 p_nxge_t nxgep = (p_nxge_t)arg; 38783859Sml29623 struct ether_addr addrp; 38793859Sml29623 38803859Sml29623 NXGE_DEBUG_MSG((nxgep, MAC_CTL, 38816512Ssowmini "==> nxge_m_multicst: add %d", add)); 38823859Sml29623 38833859Sml29623 bcopy(mca, (uint8_t *)&addrp, ETHERADDRL); 38843859Sml29623 if (add) { 38853859Sml29623 if (nxge_add_mcast_addr(nxgep, &addrp)) { 38863859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 38876512Ssowmini "<== nxge_m_multicst: add multicast failed")); 38883859Sml29623 return (EINVAL); 38893859Sml29623 } 38903859Sml29623 } else { 38913859Sml29623 if (nxge_del_mcast_addr(nxgep, &addrp)) { 38923859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 38936512Ssowmini "<== nxge_m_multicst: del multicast failed")); 38943859Sml29623 return (EINVAL); 38953859Sml29623 } 38963859Sml29623 } 38973859Sml29623 38983859Sml29623 NXGE_DEBUG_MSG((nxgep, MAC_CTL, "<== nxge_m_multicst")); 38993859Sml29623 39003859Sml29623 return (0); 39013859Sml29623 } 39023859Sml29623 39033859Sml29623 static int 39043859Sml29623 nxge_m_promisc(void *arg, boolean_t on) 39053859Sml29623 { 39063859Sml29623 p_nxge_t nxgep = (p_nxge_t)arg; 39073859Sml29623 39083859Sml29623 NXGE_DEBUG_MSG((nxgep, MAC_CTL, 39096512Ssowmini "==> nxge_m_promisc: on %d", on)); 39103859Sml29623 39113859Sml29623 if (nxge_set_promisc(nxgep, on)) { 39123859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 39136512Ssowmini "<== nxge_m_promisc: set promisc failed")); 39143859Sml29623 return (EINVAL); 39153859Sml29623 } 39163859Sml29623 39173859Sml29623 NXGE_DEBUG_MSG((nxgep, MAC_CTL, 39186512Ssowmini "<== nxge_m_promisc: on %d", on)); 39193859Sml29623 39203859Sml29623 return (0); 39213859Sml29623 } 39223859Sml29623 39233859Sml29623 static void 39243859Sml29623 nxge_m_ioctl(void *arg, queue_t *wq, mblk_t *mp) 39253859Sml29623 { 39263859Sml29623 p_nxge_t nxgep = (p_nxge_t)arg; 39274185Sspeer struct iocblk *iocp; 39283859Sml29623 boolean_t need_privilege; 39293859Sml29623 int err; 39303859Sml29623 int cmd; 39313859Sml29623 39323859Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, "==> nxge_m_ioctl")); 39333859Sml29623 39343859Sml29623 iocp = (struct iocblk *)mp->b_rptr; 39353859Sml29623 iocp->ioc_error = 0; 39363859Sml29623 need_privilege = B_TRUE; 39373859Sml29623 cmd = iocp->ioc_cmd; 39383859Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, "==> nxge_m_ioctl: cmd 0x%08x", cmd)); 39393859Sml29623 switch (cmd) { 39403859Sml29623 default: 39413859Sml29623 miocnak(wq, mp, 0, EINVAL); 39423859Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, "<== nxge_m_ioctl: invalid")); 39433859Sml29623 return; 39443859Sml29623 39453859Sml29623 case LB_GET_INFO_SIZE: 39463859Sml29623 case LB_GET_INFO: 39473859Sml29623 case LB_GET_MODE: 39483859Sml29623 need_privilege = B_FALSE; 39493859Sml29623 break; 39503859Sml29623 case LB_SET_MODE: 39513859Sml29623 break; 39523859Sml29623 39533859Sml29623 39543859Sml29623 case NXGE_GET_MII: 39553859Sml29623 case NXGE_PUT_MII: 39563859Sml29623 case NXGE_GET64: 39573859Sml29623 case NXGE_PUT64: 39583859Sml29623 case NXGE_GET_TX_RING_SZ: 39593859Sml29623 case NXGE_GET_TX_DESC: 39603859Sml29623 case NXGE_TX_SIDE_RESET: 39613859Sml29623 case NXGE_RX_SIDE_RESET: 39623859Sml29623 case NXGE_GLOBAL_RESET: 39633859Sml29623 case NXGE_RESET_MAC: 39643859Sml29623 case NXGE_TX_REGS_DUMP: 39653859Sml29623 case NXGE_RX_REGS_DUMP: 39663859Sml29623 case NXGE_INT_REGS_DUMP: 39673859Sml29623 case NXGE_VIR_INT_REGS_DUMP: 39683859Sml29623 case NXGE_PUT_TCAM: 39693859Sml29623 case NXGE_GET_TCAM: 39703859Sml29623 case NXGE_RTRACE: 39713859Sml29623 case NXGE_RDUMP: 39723859Sml29623 39733859Sml29623 need_privilege = B_FALSE; 39743859Sml29623 break; 39753859Sml29623 case NXGE_INJECT_ERR: 39763859Sml29623 cmn_err(CE_NOTE, "!nxge_m_ioctl: Inject error\n"); 39773859Sml29623 nxge_err_inject(nxgep, wq, mp); 39783859Sml29623 break; 39793859Sml29623 } 39803859Sml29623 39813859Sml29623 if (need_privilege) { 39824185Sspeer err = secpolicy_net_config(iocp->ioc_cr, B_FALSE); 39833859Sml29623 if (err != 0) { 39843859Sml29623 miocnak(wq, mp, 0, err); 39853859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 39866512Ssowmini "<== nxge_m_ioctl: no priv")); 39873859Sml29623 return; 39883859Sml29623 } 39893859Sml29623 } 39903859Sml29623 39913859Sml29623 switch (cmd) { 39923859Sml29623 39933859Sml29623 case LB_GET_MODE: 39943859Sml29623 case LB_SET_MODE: 39953859Sml29623 case LB_GET_INFO_SIZE: 39963859Sml29623 case LB_GET_INFO: 39973859Sml29623 nxge_loopback_ioctl(nxgep, wq, mp, iocp); 39983859Sml29623 break; 39993859Sml29623 40003859Sml29623 case NXGE_GET_MII: 40013859Sml29623 case NXGE_PUT_MII: 40023859Sml29623 case NXGE_PUT_TCAM: 40033859Sml29623 case NXGE_GET_TCAM: 40043859Sml29623 case NXGE_GET64: 40053859Sml29623 case NXGE_PUT64: 40063859Sml29623 case NXGE_GET_TX_RING_SZ: 40073859Sml29623 case NXGE_GET_TX_DESC: 40083859Sml29623 case NXGE_TX_SIDE_RESET: 40093859Sml29623 case NXGE_RX_SIDE_RESET: 40103859Sml29623 case NXGE_GLOBAL_RESET: 40113859Sml29623 case NXGE_RESET_MAC: 40123859Sml29623 case NXGE_TX_REGS_DUMP: 40133859Sml29623 case NXGE_RX_REGS_DUMP: 40143859Sml29623 case NXGE_INT_REGS_DUMP: 40153859Sml29623 case NXGE_VIR_INT_REGS_DUMP: 40163859Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 40176512Ssowmini "==> nxge_m_ioctl: cmd 0x%x", cmd)); 40183859Sml29623 nxge_hw_ioctl(nxgep, wq, mp, iocp); 40193859Sml29623 break; 40203859Sml29623 } 40213859Sml29623 40223859Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, "<== nxge_m_ioctl")); 40233859Sml29623 } 40243859Sml29623 40253859Sml29623 extern void nxge_rx_hw_blank(void *arg, time_t ticks, uint_t count); 40263859Sml29623 40276495Sspeer void 40288275SEric Cheng nxge_mmac_kstat_update(p_nxge_t nxgep, int slot, boolean_t factory) 40293859Sml29623 { 40303859Sml29623 p_nxge_mmac_stats_t mmac_stats; 40313859Sml29623 int i; 40323859Sml29623 nxge_mmac_t *mmac_info; 40333859Sml29623 40343859Sml29623 mmac_info = &nxgep->nxge_mmac_info; 40353859Sml29623 40363859Sml29623 mmac_stats = &nxgep->statsp->mmac_stats; 40373859Sml29623 mmac_stats->mmac_max_cnt = mmac_info->num_mmac; 40383859Sml29623 mmac_stats->mmac_avail_cnt = mmac_info->naddrfree; 40393859Sml29623 40403859Sml29623 for (i = 0; i < ETHERADDRL; i++) { 40413859Sml29623 if (factory) { 40423859Sml29623 mmac_stats->mmac_avail_pool[slot-1].ether_addr_octet[i] 40436512Ssowmini = mmac_info->factory_mac_pool[slot][ 40446512Ssowmini (ETHERADDRL-1) - i]; 40453859Sml29623 } else { 40463859Sml29623 mmac_stats->mmac_avail_pool[slot-1].ether_addr_octet[i] 40476512Ssowmini = mmac_info->mac_pool[slot].addr[ 40486512Ssowmini (ETHERADDRL - 1) - i]; 40493859Sml29623 } 40503859Sml29623 } 40513859Sml29623 } 40523859Sml29623 40533859Sml29623 /* 40543859Sml29623 * nxge_altmac_set() -- Set an alternate MAC address 40553859Sml29623 */ 40568275SEric Cheng static int 40578275SEric Cheng nxge_altmac_set(p_nxge_t nxgep, uint8_t *maddr, int slot, 40588275SEric Cheng int rdctbl, boolean_t usetbl) 40593859Sml29623 { 40603859Sml29623 uint8_t addrn; 40613859Sml29623 uint8_t portn; 40623859Sml29623 npi_mac_addr_t altmac; 40634484Sspeer hostinfo_t mac_rdc; 40644484Sspeer p_nxge_class_pt_cfg_t clscfgp; 40653859Sml29623 40668275SEric Cheng 40673859Sml29623 altmac.w2 = ((uint16_t)maddr[0] << 8) | ((uint16_t)maddr[1] & 0x0ff); 40683859Sml29623 altmac.w1 = ((uint16_t)maddr[2] << 8) | ((uint16_t)maddr[3] & 0x0ff); 40693859Sml29623 altmac.w0 = ((uint16_t)maddr[4] << 8) | ((uint16_t)maddr[5] & 0x0ff); 40703859Sml29623 40713859Sml29623 portn = nxgep->mac.portnum; 40723859Sml29623 addrn = (uint8_t)slot - 1; 40733859Sml29623 40748275SEric Cheng if (npi_mac_altaddr_entry(nxgep->npi_handle, OP_SET, 40758275SEric Cheng nxgep->function_num, addrn, &altmac) != NPI_SUCCESS) 40763859Sml29623 return (EIO); 40774484Sspeer 40784484Sspeer /* 40794484Sspeer * Set the rdc table number for the host info entry 40804484Sspeer * for this mac address slot. 40814484Sspeer */ 40824484Sspeer clscfgp = (p_nxge_class_pt_cfg_t)&nxgep->class_config; 40834484Sspeer mac_rdc.value = 0; 40848275SEric Cheng if (usetbl) 40858275SEric Cheng mac_rdc.bits.w0.rdc_tbl_num = rdctbl; 40868275SEric Cheng else 40878275SEric Cheng mac_rdc.bits.w0.rdc_tbl_num = 40888275SEric Cheng clscfgp->mac_host_info[addrn].rdctbl; 40894484Sspeer mac_rdc.bits.w0.mac_pref = clscfgp->mac_host_info[addrn].mpr_npr; 40904484Sspeer 40914484Sspeer if (npi_mac_hostinfo_entry(nxgep->npi_handle, OP_SET, 40924484Sspeer nxgep->function_num, addrn, &mac_rdc) != NPI_SUCCESS) { 40934484Sspeer return (EIO); 40944484Sspeer } 40954484Sspeer 40963859Sml29623 /* 40973859Sml29623 * Enable comparison with the alternate MAC address. 40983859Sml29623 * While the first alternate addr is enabled by bit 1 of register 40993859Sml29623 * BMAC_ALTAD_CMPEN, it is enabled by bit 0 of register 41003859Sml29623 * XMAC_ADDR_CMPEN, so slot needs to be converted to addrn 41013859Sml29623 * accordingly before calling npi_mac_altaddr_entry. 41023859Sml29623 */ 41033859Sml29623 if (portn == XMAC_PORT_0 || portn == XMAC_PORT_1) 41043859Sml29623 addrn = (uint8_t)slot - 1; 41053859Sml29623 else 41063859Sml29623 addrn = (uint8_t)slot; 41073859Sml29623 41088275SEric Cheng if (npi_mac_altaddr_enable(nxgep->npi_handle, 41098275SEric Cheng nxgep->function_num, addrn) != NPI_SUCCESS) { 41103859Sml29623 return (EIO); 41118275SEric Cheng } 41128275SEric Cheng 41133859Sml29623 return (0); 41143859Sml29623 } 41153859Sml29623 41163859Sml29623 /* 41178275SEric Cheng * nxeg_m_mmac_add_g() - find an unused address slot, set the address 41183859Sml29623 * value to the one specified, enable the port to start filtering on 41193859Sml29623 * the new MAC address. Returns 0 on success. 41203859Sml29623 */ 41216495Sspeer int 41228275SEric Cheng nxge_m_mmac_add_g(void *arg, const uint8_t *maddr, int rdctbl, 41238275SEric Cheng boolean_t usetbl) 41243859Sml29623 { 41253859Sml29623 p_nxge_t nxgep = arg; 41268275SEric Cheng int slot; 41273859Sml29623 nxge_mmac_t *mmac_info; 41283859Sml29623 int err; 41293859Sml29623 nxge_status_t status; 41303859Sml29623 41313859Sml29623 mutex_enter(nxgep->genlock); 41323859Sml29623 41333859Sml29623 /* 41343859Sml29623 * Make sure that nxge is initialized, if _start() has 41353859Sml29623 * not been called. 41363859Sml29623 */ 41373859Sml29623 if (!(nxgep->drv_state & STATE_HW_INITIALIZED)) { 41383859Sml29623 status = nxge_init(nxgep); 41393859Sml29623 if (status != NXGE_OK) { 41403859Sml29623 mutex_exit(nxgep->genlock); 41413859Sml29623 return (ENXIO); 41423859Sml29623 } 41433859Sml29623 } 41443859Sml29623 41453859Sml29623 mmac_info = &nxgep->nxge_mmac_info; 41463859Sml29623 if (mmac_info->naddrfree == 0) { 41473859Sml29623 mutex_exit(nxgep->genlock); 41483859Sml29623 return (ENOSPC); 41493859Sml29623 } 41508275SEric Cheng 41513859Sml29623 /* 41523859Sml29623 * Search for the first available slot. Because naddrfree 41533859Sml29623 * is not zero, we are guaranteed to find one. 41543859Sml29623 * Each of the first two ports of Neptune has 16 alternate 41556495Sspeer * MAC slots but only the first 7 (of 15) slots have assigned factory 41563859Sml29623 * MAC addresses. We first search among the slots without bundled 41573859Sml29623 * factory MACs. If we fail to find one in that range, then we 41583859Sml29623 * search the slots with bundled factory MACs. A factory MAC 41593859Sml29623 * will be wasted while the slot is used with a user MAC address. 41603859Sml29623 * But the slot could be used by factory MAC again after calling 41613859Sml29623 * nxge_m_mmac_remove and nxge_m_mmac_reserve. 41623859Sml29623 */ 41638275SEric Cheng for (slot = 0; slot <= mmac_info->num_mmac; slot++) { 41648275SEric Cheng if (!(mmac_info->mac_pool[slot].flags & MMAC_SLOT_USED)) 41658275SEric Cheng break; 41668275SEric Cheng } 41678275SEric Cheng 41683859Sml29623 ASSERT(slot <= mmac_info->num_mmac); 41698047SMichael.Speer@Sun.COM 41708275SEric Cheng if ((err = nxge_altmac_set(nxgep, (uint8_t *)maddr, slot, rdctbl, 41718275SEric Cheng usetbl)) != 0) { 41723859Sml29623 mutex_exit(nxgep->genlock); 41733859Sml29623 return (err); 41743859Sml29623 } 41758047SMichael.Speer@Sun.COM 41768275SEric Cheng bcopy(maddr, mmac_info->mac_pool[slot].addr, ETHERADDRL); 41773859Sml29623 mmac_info->mac_pool[slot].flags |= MMAC_SLOT_USED; 41783859Sml29623 mmac_info->mac_pool[slot].flags &= ~MMAC_VENDOR_ADDR; 41793859Sml29623 mmac_info->naddrfree--; 41803859Sml29623 nxge_mmac_kstat_update(nxgep, slot, B_FALSE); 41813859Sml29623 41823859Sml29623 mutex_exit(nxgep->genlock); 41833859Sml29623 return (0); 41843859Sml29623 } 41853859Sml29623 41863859Sml29623 /* 41873859Sml29623 * Remove the specified mac address and update the HW not to filter 41883859Sml29623 * the mac address anymore. 41893859Sml29623 */ 41906495Sspeer int 41918275SEric Cheng nxge_m_mmac_remove(void *arg, int slot) 41923859Sml29623 { 41933859Sml29623 p_nxge_t nxgep = arg; 41943859Sml29623 nxge_mmac_t *mmac_info; 41953859Sml29623 uint8_t addrn; 41963859Sml29623 uint8_t portn; 41973859Sml29623 int err = 0; 41983859Sml29623 nxge_status_t status; 41993859Sml29623 42003859Sml29623 mutex_enter(nxgep->genlock); 42013859Sml29623 42023859Sml29623 /* 42033859Sml29623 * Make sure that nxge is initialized, if _start() has 42043859Sml29623 * not been called. 42053859Sml29623 */ 42063859Sml29623 if (!(nxgep->drv_state & STATE_HW_INITIALIZED)) { 42073859Sml29623 status = nxge_init(nxgep); 42083859Sml29623 if (status != NXGE_OK) { 42093859Sml29623 mutex_exit(nxgep->genlock); 42103859Sml29623 return (ENXIO); 42113859Sml29623 } 42123859Sml29623 } 42133859Sml29623 42143859Sml29623 mmac_info = &nxgep->nxge_mmac_info; 42153859Sml29623 if (slot < 1 || slot > mmac_info->num_mmac) { 42163859Sml29623 mutex_exit(nxgep->genlock); 42173859Sml29623 return (EINVAL); 42183859Sml29623 } 42193859Sml29623 42203859Sml29623 portn = nxgep->mac.portnum; 42213859Sml29623 if (portn == XMAC_PORT_0 || portn == XMAC_PORT_1) 42223859Sml29623 addrn = (uint8_t)slot - 1; 42233859Sml29623 else 42243859Sml29623 addrn = (uint8_t)slot; 42253859Sml29623 42263859Sml29623 if (mmac_info->mac_pool[slot].flags & MMAC_SLOT_USED) { 42273859Sml29623 if (npi_mac_altaddr_disable(nxgep->npi_handle, portn, addrn) 42286512Ssowmini == NPI_SUCCESS) { 42293859Sml29623 mmac_info->naddrfree++; 42303859Sml29623 mmac_info->mac_pool[slot].flags &= ~MMAC_SLOT_USED; 42313859Sml29623 /* 42323859Sml29623 * Regardless if the MAC we just stopped filtering 42333859Sml29623 * is a user addr or a facory addr, we must set 42343859Sml29623 * the MMAC_VENDOR_ADDR flag if this slot has an 42353859Sml29623 * associated factory MAC to indicate that a factory 42363859Sml29623 * MAC is available. 42373859Sml29623 */ 42383859Sml29623 if (slot <= mmac_info->num_factory_mmac) { 42393859Sml29623 mmac_info->mac_pool[slot].flags 42406512Ssowmini |= MMAC_VENDOR_ADDR; 42413859Sml29623 } 42423859Sml29623 /* 42433859Sml29623 * Clear mac_pool[slot].addr so that kstat shows 0 42443859Sml29623 * alternate MAC address if the slot is not used. 42453859Sml29623 * (But nxge_m_mmac_get returns the factory MAC even 42463859Sml29623 * when the slot is not used!) 42473859Sml29623 */ 42483859Sml29623 bzero(mmac_info->mac_pool[slot].addr, ETHERADDRL); 42493859Sml29623 nxge_mmac_kstat_update(nxgep, slot, B_FALSE); 42503859Sml29623 } else { 42513859Sml29623 err = EIO; 42523859Sml29623 } 42533859Sml29623 } else { 42543859Sml29623 err = EINVAL; 42553859Sml29623 } 42563859Sml29623 42573859Sml29623 mutex_exit(nxgep->genlock); 42583859Sml29623 return (err); 42593859Sml29623 } 42603859Sml29623 42613859Sml29623 /* 42628275SEric Cheng * The callback to query all the factory addresses. naddr must be the same as 42638275SEric Cheng * the number of factory addresses (returned by MAC_CAPAB_MULTIFACTADDR), and 42648275SEric Cheng * mcm_addr is the space allocated for keep all the addresses, whose size is 42658275SEric Cheng * naddr * MAXMACADDRLEN. 42663859Sml29623 */ 42678275SEric Cheng static void 42688275SEric Cheng nxge_m_getfactaddr(void *arg, uint_t naddr, uint8_t *addr) 42693859Sml29623 { 42708275SEric Cheng nxge_t *nxgep = arg; 42718275SEric Cheng nxge_mmac_t *mmac_info; 42728275SEric Cheng int i; 42733859Sml29623 42743859Sml29623 mutex_enter(nxgep->genlock); 42753859Sml29623 42763859Sml29623 mmac_info = &nxgep->nxge_mmac_info; 42778275SEric Cheng ASSERT(naddr == mmac_info->num_factory_mmac); 42788275SEric Cheng 42798275SEric Cheng for (i = 0; i < naddr; i++) { 42808275SEric Cheng bcopy(mmac_info->factory_mac_pool[i + 1], 42818275SEric Cheng addr + i * MAXMACADDRLEN, ETHERADDRL); 42828275SEric Cheng } 42838275SEric Cheng 42843859Sml29623 mutex_exit(nxgep->genlock); 42853859Sml29623 } 42863859Sml29623 42873859Sml29623 42883859Sml29623 static boolean_t 42893859Sml29623 nxge_m_getcapab(void *arg, mac_capab_t cap, void *cap_data) 42903859Sml29623 { 42913859Sml29623 nxge_t *nxgep = arg; 42923859Sml29623 uint32_t *txflags = cap_data; 42933859Sml29623 42943859Sml29623 switch (cap) { 42953859Sml29623 case MAC_CAPAB_HCKSUM: 42966495Sspeer NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 42976611Sml29623 "==> nxge_m_getcapab: checksum %d", nxge_cksum_offload)); 42986611Sml29623 if (nxge_cksum_offload <= 1) { 42996495Sspeer *txflags = HCKSUM_INET_PARTIAL; 43006495Sspeer } 43013859Sml29623 break; 43026495Sspeer 43038275SEric Cheng case MAC_CAPAB_MULTIFACTADDR: { 43048275SEric Cheng mac_capab_multifactaddr_t *mfacp = cap_data; 43058275SEric Cheng 43063859Sml29623 mutex_enter(nxgep->genlock); 43078275SEric Cheng mfacp->mcm_naddr = nxgep->nxge_mmac_info.num_factory_mmac; 43088275SEric Cheng mfacp->mcm_getaddr = nxge_m_getfactaddr; 43093859Sml29623 mutex_exit(nxgep->genlock); 43103859Sml29623 break; 43118275SEric Cheng } 43126495Sspeer 43135770Sml29623 case MAC_CAPAB_LSO: { 43145770Sml29623 mac_capab_lso_t *cap_lso = cap_data; 43155770Sml29623 43166003Sml29623 if (nxgep->soft_lso_enable) { 43176611Sml29623 if (nxge_cksum_offload <= 1) { 43186611Sml29623 cap_lso->lso_flags = LSO_TX_BASIC_TCP_IPV4; 43196611Sml29623 if (nxge_lso_max > NXGE_LSO_MAXLEN) { 43206611Sml29623 nxge_lso_max = NXGE_LSO_MAXLEN; 43216611Sml29623 } 43226611Sml29623 cap_lso->lso_basic_tcp_ipv4.lso_max = 43236611Sml29623 nxge_lso_max; 43245770Sml29623 } 43255770Sml29623 break; 43265770Sml29623 } else { 43275770Sml29623 return (B_FALSE); 43285770Sml29623 } 43295770Sml29623 } 43305770Sml29623 43318275SEric Cheng case MAC_CAPAB_RINGS: { 43328275SEric Cheng mac_capab_rings_t *cap_rings = cap_data; 43338275SEric Cheng p_nxge_hw_pt_cfg_t p_cfgp = &nxgep->pt_config.hw_config; 43348275SEric Cheng 43358275SEric Cheng mutex_enter(nxgep->genlock); 43368275SEric Cheng if (cap_rings->mr_type == MAC_RING_TYPE_RX) { 43378275SEric Cheng cap_rings->mr_group_type = MAC_GROUP_TYPE_DYNAMIC; 43388275SEric Cheng cap_rings->mr_rnum = p_cfgp->max_rdcs; 43398275SEric Cheng cap_rings->mr_rget = nxge_fill_ring; 43408275SEric Cheng cap_rings->mr_gnum = p_cfgp->max_rdc_grpids; 43418275SEric Cheng cap_rings->mr_gget = nxge_hio_group_get; 43428275SEric Cheng cap_rings->mr_gaddring = nxge_group_add_ring; 43438275SEric Cheng cap_rings->mr_gremring = nxge_group_rem_ring; 43448275SEric Cheng 43458275SEric Cheng NXGE_DEBUG_MSG((nxgep, RX_CTL, 43468275SEric Cheng "==> nxge_m_getcapab: rx nrings[%d] ngroups[%d]", 43478275SEric Cheng p_cfgp->max_rdcs, p_cfgp->max_rdc_grpids)); 43488275SEric Cheng } else { 43498275SEric Cheng cap_rings->mr_group_type = MAC_GROUP_TYPE_DYNAMIC; 43508275SEric Cheng cap_rings->mr_rnum = p_cfgp->tdc.count; 43518275SEric Cheng cap_rings->mr_rget = nxge_fill_ring; 43528275SEric Cheng if (isLDOMservice(nxgep)) { 43538275SEric Cheng /* share capable */ 43548275SEric Cheng /* Do not report the default ring: hence -1 */ 43558275SEric Cheng cap_rings->mr_gnum = 43568275SEric Cheng NXGE_MAX_TDC_GROUPS / nxgep->nports - 1; 43578275SEric Cheng } else { 43588275SEric Cheng cap_rings->mr_gnum = 0; 43598275SEric Cheng } 43608275SEric Cheng 43618275SEric Cheng cap_rings->mr_gget = nxge_hio_group_get; 43628275SEric Cheng cap_rings->mr_gaddring = nxge_group_add_ring; 43638275SEric Cheng cap_rings->mr_gremring = nxge_group_rem_ring; 43648275SEric Cheng 43658275SEric Cheng NXGE_DEBUG_MSG((nxgep, TX_CTL, 43668275SEric Cheng "==> nxge_m_getcapab: tx rings # of rings %d", 43678275SEric Cheng p_cfgp->tdc.count)); 43688275SEric Cheng } 43698275SEric Cheng mutex_exit(nxgep->genlock); 43708275SEric Cheng break; 43718275SEric Cheng } 43728275SEric Cheng 43736495Sspeer #if defined(sun4v) 43746495Sspeer case MAC_CAPAB_SHARES: { 43756495Sspeer mac_capab_share_t *mshares = (mac_capab_share_t *)cap_data; 43766495Sspeer 43776495Sspeer /* 43786495Sspeer * Only the service domain driver responds to 43796495Sspeer * this capability request. 43806495Sspeer */ 43818275SEric Cheng mutex_enter(nxgep->genlock); 43826495Sspeer if (isLDOMservice(nxgep)) { 43836495Sspeer mshares->ms_snum = 3; 43846495Sspeer mshares->ms_handle = (void *)nxgep; 43856495Sspeer mshares->ms_salloc = nxge_hio_share_alloc; 43866495Sspeer mshares->ms_sfree = nxge_hio_share_free; 43878275SEric Cheng mshares->ms_sadd = nxge_hio_share_add_group; 43888275SEric Cheng mshares->ms_sremove = nxge_hio_share_rem_group; 43896495Sspeer mshares->ms_squery = nxge_hio_share_query; 43908275SEric Cheng mshares->ms_sbind = nxge_hio_share_bind; 43918275SEric Cheng mshares->ms_sunbind = nxge_hio_share_unbind; 43928275SEric Cheng mutex_exit(nxgep->genlock); 43938275SEric Cheng } else { 43948275SEric Cheng mutex_exit(nxgep->genlock); 43956495Sspeer return (B_FALSE); 43968275SEric Cheng } 43976495Sspeer break; 43986495Sspeer } 43996495Sspeer #endif 44003859Sml29623 default: 44013859Sml29623 return (B_FALSE); 44023859Sml29623 } 44033859Sml29623 return (B_TRUE); 44043859Sml29623 } 44053859Sml29623 44066439Sml29623 static boolean_t 44076439Sml29623 nxge_param_locked(mac_prop_id_t pr_num) 44086439Sml29623 { 44096439Sml29623 /* 44106439Sml29623 * All adv_* parameters are locked (read-only) while 44116439Sml29623 * the device is in any sort of loopback mode ... 44126439Sml29623 */ 44136439Sml29623 switch (pr_num) { 44146789Sam223141 case MAC_PROP_ADV_1000FDX_CAP: 44156789Sam223141 case MAC_PROP_EN_1000FDX_CAP: 44166789Sam223141 case MAC_PROP_ADV_1000HDX_CAP: 44176789Sam223141 case MAC_PROP_EN_1000HDX_CAP: 44186789Sam223141 case MAC_PROP_ADV_100FDX_CAP: 44196789Sam223141 case MAC_PROP_EN_100FDX_CAP: 44206789Sam223141 case MAC_PROP_ADV_100HDX_CAP: 44216789Sam223141 case MAC_PROP_EN_100HDX_CAP: 44226789Sam223141 case MAC_PROP_ADV_10FDX_CAP: 44236789Sam223141 case MAC_PROP_EN_10FDX_CAP: 44246789Sam223141 case MAC_PROP_ADV_10HDX_CAP: 44256789Sam223141 case MAC_PROP_EN_10HDX_CAP: 44266789Sam223141 case MAC_PROP_AUTONEG: 44276789Sam223141 case MAC_PROP_FLOWCTRL: 44286439Sml29623 return (B_TRUE); 44296439Sml29623 } 44306439Sml29623 return (B_FALSE); 44316439Sml29623 } 44326439Sml29623 44336439Sml29623 /* 44346439Sml29623 * callback functions for set/get of properties 44356439Sml29623 */ 44366439Sml29623 static int 44376439Sml29623 nxge_m_setprop(void *barg, const char *pr_name, mac_prop_id_t pr_num, 44386439Sml29623 uint_t pr_valsize, const void *pr_val) 44396439Sml29623 { 44406439Sml29623 nxge_t *nxgep = barg; 44416439Sml29623 p_nxge_param_t param_arr; 44426439Sml29623 p_nxge_stats_t statsp; 44436439Sml29623 int err = 0; 44446439Sml29623 uint8_t val; 44456439Sml29623 uint32_t cur_mtu, new_mtu, old_framesize; 44466439Sml29623 link_flowctrl_t fl; 44476439Sml29623 44486439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, "==> nxge_m_setprop")); 44496439Sml29623 param_arr = nxgep->param_arr; 44506439Sml29623 statsp = nxgep->statsp; 44516439Sml29623 mutex_enter(nxgep->genlock); 44526439Sml29623 if (statsp->port_stats.lb_mode != nxge_lb_normal && 44536439Sml29623 nxge_param_locked(pr_num)) { 44546439Sml29623 /* 44556439Sml29623 * All adv_* parameters are locked (read-only) 44566439Sml29623 * while the device is in any sort of loopback mode. 44576439Sml29623 */ 44586439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 44596439Sml29623 "==> nxge_m_setprop: loopback mode: read only")); 44606439Sml29623 mutex_exit(nxgep->genlock); 44616439Sml29623 return (EBUSY); 44626439Sml29623 } 44636439Sml29623 44646439Sml29623 val = *(uint8_t *)pr_val; 44656439Sml29623 switch (pr_num) { 44666789Sam223141 case MAC_PROP_EN_1000FDX_CAP: 44676439Sml29623 nxgep->param_en_1000fdx = val; 44686439Sml29623 param_arr[param_anar_1000fdx].value = val; 44696439Sml29623 44706439Sml29623 goto reprogram; 44716439Sml29623 44726789Sam223141 case MAC_PROP_EN_100FDX_CAP: 44736439Sml29623 nxgep->param_en_100fdx = val; 44746439Sml29623 param_arr[param_anar_100fdx].value = val; 44756439Sml29623 44766439Sml29623 goto reprogram; 44776439Sml29623 44786789Sam223141 case MAC_PROP_EN_10FDX_CAP: 44796439Sml29623 nxgep->param_en_10fdx = val; 44806439Sml29623 param_arr[param_anar_10fdx].value = val; 44816439Sml29623 44826439Sml29623 goto reprogram; 44836439Sml29623 44846789Sam223141 case MAC_PROP_EN_1000HDX_CAP: 44856789Sam223141 case MAC_PROP_EN_100HDX_CAP: 44866789Sam223141 case MAC_PROP_EN_10HDX_CAP: 44876789Sam223141 case MAC_PROP_ADV_1000FDX_CAP: 44886789Sam223141 case MAC_PROP_ADV_1000HDX_CAP: 44896789Sam223141 case MAC_PROP_ADV_100FDX_CAP: 44906789Sam223141 case MAC_PROP_ADV_100HDX_CAP: 44916789Sam223141 case MAC_PROP_ADV_10FDX_CAP: 44926789Sam223141 case MAC_PROP_ADV_10HDX_CAP: 44936789Sam223141 case MAC_PROP_STATUS: 44946789Sam223141 case MAC_PROP_SPEED: 44956789Sam223141 case MAC_PROP_DUPLEX: 44966439Sml29623 err = EINVAL; /* cannot set read-only properties */ 44976439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 44986439Sml29623 "==> nxge_m_setprop: read only property %d", 44996439Sml29623 pr_num)); 45006439Sml29623 break; 45016439Sml29623 45026789Sam223141 case MAC_PROP_AUTONEG: 45036439Sml29623 param_arr[param_autoneg].value = val; 45046439Sml29623 45056439Sml29623 goto reprogram; 45066439Sml29623 45076789Sam223141 case MAC_PROP_MTU: 45086439Sml29623 cur_mtu = nxgep->mac.default_mtu; 45096439Sml29623 bcopy(pr_val, &new_mtu, sizeof (new_mtu)); 45106439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 45116439Sml29623 "==> nxge_m_setprop: set MTU: %d is_jumbo %d", 45126439Sml29623 new_mtu, nxgep->mac.is_jumbo)); 45136439Sml29623 45146439Sml29623 if (new_mtu == cur_mtu) { 45156439Sml29623 err = 0; 45166439Sml29623 break; 45176439Sml29623 } 45188118SVasumathi.Sundaram@Sun.COM if (nxgep->nxge_mac_state == NXGE_MAC_STARTED) { 45198118SVasumathi.Sundaram@Sun.COM err = EBUSY; 45208118SVasumathi.Sundaram@Sun.COM break; 45218118SVasumathi.Sundaram@Sun.COM } 45226439Sml29623 if (new_mtu < NXGE_DEFAULT_MTU || 45236439Sml29623 new_mtu > NXGE_MAXIMUM_MTU) { 45246439Sml29623 err = EINVAL; 45256439Sml29623 break; 45266439Sml29623 } 45276439Sml29623 45286439Sml29623 if ((new_mtu > NXGE_DEFAULT_MTU) && 45296439Sml29623 !nxgep->mac.is_jumbo) { 45306439Sml29623 err = EINVAL; 45316439Sml29623 break; 45326439Sml29623 } 45336439Sml29623 45346439Sml29623 old_framesize = (uint32_t)nxgep->mac.maxframesize; 45356439Sml29623 nxgep->mac.maxframesize = (uint16_t) 45366439Sml29623 (new_mtu + NXGE_EHEADER_VLAN_CRC); 45376439Sml29623 if (nxge_mac_set_framesize(nxgep)) { 45386444Sml29623 nxgep->mac.maxframesize = 45396444Sml29623 (uint16_t)old_framesize; 45406439Sml29623 err = EINVAL; 45416439Sml29623 break; 45426439Sml29623 } 45436439Sml29623 45446439Sml29623 err = mac_maxsdu_update(nxgep->mach, new_mtu); 45456439Sml29623 if (err) { 45466444Sml29623 nxgep->mac.maxframesize = 45476444Sml29623 (uint16_t)old_framesize; 45486439Sml29623 err = EINVAL; 45496439Sml29623 break; 45506439Sml29623 } 45516439Sml29623 45526439Sml29623 nxgep->mac.default_mtu = new_mtu; 45536439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 45546439Sml29623 "==> nxge_m_setprop: set MTU: %d maxframe %d", 45556439Sml29623 new_mtu, nxgep->mac.maxframesize)); 45566439Sml29623 break; 45576439Sml29623 45586789Sam223141 case MAC_PROP_FLOWCTRL: 45596439Sml29623 bcopy(pr_val, &fl, sizeof (fl)); 45606439Sml29623 switch (fl) { 45616439Sml29623 default: 45626439Sml29623 err = EINVAL; 45636439Sml29623 break; 45646439Sml29623 45656439Sml29623 case LINK_FLOWCTRL_NONE: 45666439Sml29623 param_arr[param_anar_pause].value = 0; 45676439Sml29623 break; 45686439Sml29623 45696439Sml29623 case LINK_FLOWCTRL_RX: 45706439Sml29623 param_arr[param_anar_pause].value = 1; 45716439Sml29623 break; 45726439Sml29623 45736439Sml29623 case LINK_FLOWCTRL_TX: 45746439Sml29623 case LINK_FLOWCTRL_BI: 45756439Sml29623 err = EINVAL; 45766439Sml29623 break; 45776439Sml29623 } 45786439Sml29623 45796439Sml29623 reprogram: 45806439Sml29623 if (err == 0) { 45816439Sml29623 if (!nxge_param_link_update(nxgep)) { 45826439Sml29623 err = EINVAL; 45836439Sml29623 } 45846439Sml29623 } 45856439Sml29623 break; 45866789Sam223141 case MAC_PROP_PRIVATE: 45876439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 45886439Sml29623 "==> nxge_m_setprop: private property")); 45896439Sml29623 err = nxge_set_priv_prop(nxgep, pr_name, pr_valsize, 45906439Sml29623 pr_val); 45916439Sml29623 break; 45926512Ssowmini 45936512Ssowmini default: 45946512Ssowmini err = ENOTSUP; 45956512Ssowmini break; 45966439Sml29623 } 45976439Sml29623 45986439Sml29623 mutex_exit(nxgep->genlock); 45996439Sml29623 46006439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 46016439Sml29623 "<== nxge_m_setprop (return %d)", err)); 46026439Sml29623 return (err); 46036439Sml29623 } 46046439Sml29623 46056439Sml29623 static int 46066439Sml29623 nxge_m_getprop(void *barg, const char *pr_name, mac_prop_id_t pr_num, 46078118SVasumathi.Sundaram@Sun.COM uint_t pr_flags, uint_t pr_valsize, void *pr_val, uint_t *perm) 46086439Sml29623 { 46096439Sml29623 nxge_t *nxgep = barg; 46106439Sml29623 p_nxge_param_t param_arr = nxgep->param_arr; 46116439Sml29623 p_nxge_stats_t statsp = nxgep->statsp; 46126439Sml29623 int err = 0; 46136439Sml29623 link_flowctrl_t fl; 46146439Sml29623 uint64_t tmp = 0; 46156512Ssowmini link_state_t ls; 46166789Sam223141 boolean_t is_default = (pr_flags & MAC_PROP_DEFAULT); 46176439Sml29623 46186439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 46196439Sml29623 "==> nxge_m_getprop: pr_num %d", pr_num)); 46206512Ssowmini 46216512Ssowmini if (pr_valsize == 0) 46226512Ssowmini return (EINVAL); 46236512Ssowmini 46248118SVasumathi.Sundaram@Sun.COM *perm = MAC_PROP_PERM_RW; 46258118SVasumathi.Sundaram@Sun.COM 46266789Sam223141 if ((is_default) && (pr_num != MAC_PROP_PRIVATE)) { 46276512Ssowmini err = nxge_get_def_val(nxgep, pr_num, pr_valsize, pr_val); 46286512Ssowmini return (err); 46296512Ssowmini } 46306512Ssowmini 46316439Sml29623 bzero(pr_val, pr_valsize); 46326439Sml29623 switch (pr_num) { 46336789Sam223141 case MAC_PROP_DUPLEX: 46348118SVasumathi.Sundaram@Sun.COM *perm = MAC_PROP_PERM_READ; 46356439Sml29623 *(uint8_t *)pr_val = statsp->mac_stats.link_duplex; 46366439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 46376439Sml29623 "==> nxge_m_getprop: duplex mode %d", 46386439Sml29623 *(uint8_t *)pr_val)); 46396439Sml29623 break; 46406439Sml29623 46416789Sam223141 case MAC_PROP_SPEED: 46426439Sml29623 if (pr_valsize < sizeof (uint64_t)) 46436439Sml29623 return (EINVAL); 46448118SVasumathi.Sundaram@Sun.COM *perm = MAC_PROP_PERM_READ; 46456439Sml29623 tmp = statsp->mac_stats.link_speed * 1000000ull; 46466439Sml29623 bcopy(&tmp, pr_val, sizeof (tmp)); 46476439Sml29623 break; 46486439Sml29623 46496789Sam223141 case MAC_PROP_STATUS: 46506512Ssowmini if (pr_valsize < sizeof (link_state_t)) 46516439Sml29623 return (EINVAL); 46528118SVasumathi.Sundaram@Sun.COM *perm = MAC_PROP_PERM_READ; 46536512Ssowmini if (!statsp->mac_stats.link_up) 46546512Ssowmini ls = LINK_STATE_DOWN; 46556512Ssowmini else 46566512Ssowmini ls = LINK_STATE_UP; 46576512Ssowmini bcopy(&ls, pr_val, sizeof (ls)); 46586439Sml29623 break; 46596439Sml29623 46606789Sam223141 case MAC_PROP_AUTONEG: 46616439Sml29623 *(uint8_t *)pr_val = 46626439Sml29623 param_arr[param_autoneg].value; 46636439Sml29623 break; 46646439Sml29623 46656789Sam223141 case MAC_PROP_FLOWCTRL: 46666439Sml29623 if (pr_valsize < sizeof (link_flowctrl_t)) 46676439Sml29623 return (EINVAL); 46686439Sml29623 46696439Sml29623 fl = LINK_FLOWCTRL_NONE; 46706439Sml29623 if (param_arr[param_anar_pause].value) { 46716439Sml29623 fl = LINK_FLOWCTRL_RX; 46726439Sml29623 } 46736439Sml29623 bcopy(&fl, pr_val, sizeof (fl)); 46746439Sml29623 break; 46756439Sml29623 46766789Sam223141 case MAC_PROP_ADV_1000FDX_CAP: 46778118SVasumathi.Sundaram@Sun.COM *perm = MAC_PROP_PERM_READ; 46786439Sml29623 *(uint8_t *)pr_val = 46796439Sml29623 param_arr[param_anar_1000fdx].value; 46806439Sml29623 break; 46816439Sml29623 46826789Sam223141 case MAC_PROP_EN_1000FDX_CAP: 46836439Sml29623 *(uint8_t *)pr_val = nxgep->param_en_1000fdx; 46846439Sml29623 break; 46856439Sml29623 46866789Sam223141 case MAC_PROP_ADV_100FDX_CAP: 46878118SVasumathi.Sundaram@Sun.COM *perm = MAC_PROP_PERM_READ; 46886439Sml29623 *(uint8_t *)pr_val = 46896439Sml29623 param_arr[param_anar_100fdx].value; 46906439Sml29623 break; 46916439Sml29623 46926789Sam223141 case MAC_PROP_EN_100FDX_CAP: 46936439Sml29623 *(uint8_t *)pr_val = nxgep->param_en_100fdx; 46946439Sml29623 break; 46956439Sml29623 46966789Sam223141 case MAC_PROP_ADV_10FDX_CAP: 46978118SVasumathi.Sundaram@Sun.COM *perm = MAC_PROP_PERM_READ; 46986439Sml29623 *(uint8_t *)pr_val = 46996439Sml29623 param_arr[param_anar_10fdx].value; 47006439Sml29623 break; 47016439Sml29623 47026789Sam223141 case MAC_PROP_EN_10FDX_CAP: 47036439Sml29623 *(uint8_t *)pr_val = nxgep->param_en_10fdx; 47046439Sml29623 break; 47056439Sml29623 47066789Sam223141 case MAC_PROP_EN_1000HDX_CAP: 47076789Sam223141 case MAC_PROP_EN_100HDX_CAP: 47086789Sam223141 case MAC_PROP_EN_10HDX_CAP: 47096789Sam223141 case MAC_PROP_ADV_1000HDX_CAP: 47106789Sam223141 case MAC_PROP_ADV_100HDX_CAP: 47116789Sam223141 case MAC_PROP_ADV_10HDX_CAP: 47126512Ssowmini err = ENOTSUP; 47136512Ssowmini break; 47146512Ssowmini 47156789Sam223141 case MAC_PROP_PRIVATE: 47166512Ssowmini err = nxge_get_priv_prop(nxgep, pr_name, pr_flags, 47178118SVasumathi.Sundaram@Sun.COM pr_valsize, pr_val, perm); 47186512Ssowmini break; 4719*9514SGirish.Moodalbail@Sun.COM 4720*9514SGirish.Moodalbail@Sun.COM case MAC_PROP_MTU: { 4721*9514SGirish.Moodalbail@Sun.COM mac_propval_range_t range; 4722*9514SGirish.Moodalbail@Sun.COM 4723*9514SGirish.Moodalbail@Sun.COM if (!(pr_flags & MAC_PROP_POSSIBLE)) 4724*9514SGirish.Moodalbail@Sun.COM return (ENOTSUP); 4725*9514SGirish.Moodalbail@Sun.COM if (pr_valsize < sizeof (mac_propval_range_t)) 4726*9514SGirish.Moodalbail@Sun.COM return (EINVAL); 4727*9514SGirish.Moodalbail@Sun.COM range.mpr_count = 1; 4728*9514SGirish.Moodalbail@Sun.COM range.mpr_type = MAC_PROPVAL_UINT32; 4729*9514SGirish.Moodalbail@Sun.COM range.range_uint32[0].mpur_min = 4730*9514SGirish.Moodalbail@Sun.COM range.range_uint32[0].mpur_max = NXGE_DEFAULT_MTU; 4731*9514SGirish.Moodalbail@Sun.COM if (nxgep->mac.is_jumbo) 4732*9514SGirish.Moodalbail@Sun.COM range.range_uint32[0].mpur_max = 4733*9514SGirish.Moodalbail@Sun.COM NXGE_MAXIMUM_MTU; 4734*9514SGirish.Moodalbail@Sun.COM bcopy(&range, pr_val, sizeof (range)); 4735*9514SGirish.Moodalbail@Sun.COM break; 4736*9514SGirish.Moodalbail@Sun.COM } 47376512Ssowmini default: 47386439Sml29623 err = EINVAL; 47396439Sml29623 break; 47406439Sml29623 } 47416439Sml29623 47426439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, "<== nxge_m_getprop")); 47436439Sml29623 47446439Sml29623 return (err); 47456439Sml29623 } 47466439Sml29623 47476439Sml29623 /* ARGSUSED */ 47486439Sml29623 static int 47496439Sml29623 nxge_set_priv_prop(p_nxge_t nxgep, const char *pr_name, uint_t pr_valsize, 47506439Sml29623 const void *pr_val) 47516439Sml29623 { 47526439Sml29623 p_nxge_param_t param_arr = nxgep->param_arr; 47536439Sml29623 int err = 0; 47546439Sml29623 long result; 47556439Sml29623 47566439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 47576439Sml29623 "==> nxge_set_priv_prop: name %s", pr_name)); 47586439Sml29623 47596439Sml29623 if (strcmp(pr_name, "_accept_jumbo") == 0) { 47606439Sml29623 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 47616439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 47626439Sml29623 "<== nxge_set_priv_prop: name %s " 47636439Sml29623 "pr_val %s result %d " 47646439Sml29623 "param %d is_jumbo %d", 47656439Sml29623 pr_name, pr_val, result, 47666439Sml29623 param_arr[param_accept_jumbo].value, 47676439Sml29623 nxgep->mac.is_jumbo)); 47686439Sml29623 47696439Sml29623 if (result > 1 || result < 0) { 47706439Sml29623 err = EINVAL; 47716439Sml29623 } else { 47726439Sml29623 if (nxgep->mac.is_jumbo == 47736439Sml29623 (uint32_t)result) { 47746439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 47756439Sml29623 "no change (%d %d)", 47766439Sml29623 nxgep->mac.is_jumbo, 47776439Sml29623 result)); 47786439Sml29623 return (0); 47796439Sml29623 } 47806439Sml29623 } 47816439Sml29623 47826439Sml29623 param_arr[param_accept_jumbo].value = result; 47836439Sml29623 nxgep->mac.is_jumbo = B_FALSE; 47846439Sml29623 if (result) { 47856439Sml29623 nxgep->mac.is_jumbo = B_TRUE; 47866439Sml29623 } 47876439Sml29623 47886439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 47896439Sml29623 "<== nxge_set_priv_prop: name %s (value %d) is_jumbo %d", 47906439Sml29623 pr_name, result, nxgep->mac.is_jumbo)); 47916439Sml29623 47926439Sml29623 return (err); 47936439Sml29623 } 47946439Sml29623 47956439Sml29623 /* Blanking */ 47966439Sml29623 if (strcmp(pr_name, "_rxdma_intr_time") == 0) { 47976439Sml29623 err = nxge_param_rx_intr_time(nxgep, NULL, NULL, 47986439Sml29623 (char *)pr_val, 47996439Sml29623 (caddr_t)¶m_arr[param_rxdma_intr_time]); 48006439Sml29623 if (err) { 48016439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 48026439Sml29623 "<== nxge_set_priv_prop: " 48036439Sml29623 "unable to set (%s)", pr_name)); 48046439Sml29623 err = EINVAL; 48056439Sml29623 } else { 48066439Sml29623 err = 0; 48076439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 48086439Sml29623 "<== nxge_set_priv_prop: " 48096439Sml29623 "set (%s)", pr_name)); 48106439Sml29623 } 48116439Sml29623 48126439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 48136439Sml29623 "<== nxge_set_priv_prop: name %s (value %d)", 48146439Sml29623 pr_name, result)); 48156439Sml29623 48166439Sml29623 return (err); 48176439Sml29623 } 48186439Sml29623 48196439Sml29623 if (strcmp(pr_name, "_rxdma_intr_pkts") == 0) { 48206439Sml29623 err = nxge_param_rx_intr_pkts(nxgep, NULL, NULL, 48216439Sml29623 (char *)pr_val, 48226439Sml29623 (caddr_t)¶m_arr[param_rxdma_intr_pkts]); 48236439Sml29623 if (err) { 48246439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 48256439Sml29623 "<== nxge_set_priv_prop: " 48266439Sml29623 "unable to set (%s)", pr_name)); 48276439Sml29623 err = EINVAL; 48286439Sml29623 } else { 48296439Sml29623 err = 0; 48306439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 48316439Sml29623 "<== nxge_set_priv_prop: " 48326439Sml29623 "set (%s)", pr_name)); 48336439Sml29623 } 48346439Sml29623 48356439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 48366439Sml29623 "<== nxge_set_priv_prop: name %s (value %d)", 48376439Sml29623 pr_name, result)); 48386439Sml29623 48396439Sml29623 return (err); 48406439Sml29623 } 48416439Sml29623 48426439Sml29623 /* Classification */ 48436439Sml29623 if (strcmp(pr_name, "_class_opt_ipv4_tcp") == 0) { 48446439Sml29623 if (pr_val == NULL) { 48456439Sml29623 err = EINVAL; 48466439Sml29623 return (err); 48476439Sml29623 } 48486439Sml29623 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 48496439Sml29623 48506439Sml29623 err = nxge_param_set_ip_opt(nxgep, NULL, 48516439Sml29623 NULL, (char *)pr_val, 48526439Sml29623 (caddr_t)¶m_arr[param_class_opt_ipv4_tcp]); 48536439Sml29623 48546439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 48556439Sml29623 "<== nxge_set_priv_prop: name %s (value 0x%x)", 48566439Sml29623 pr_name, result)); 48576439Sml29623 48586439Sml29623 return (err); 48596439Sml29623 } 48606439Sml29623 48616439Sml29623 if (strcmp(pr_name, "_class_opt_ipv4_udp") == 0) { 48626439Sml29623 if (pr_val == NULL) { 48636439Sml29623 err = EINVAL; 48646439Sml29623 return (err); 48656439Sml29623 } 48666439Sml29623 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 48676439Sml29623 48686439Sml29623 err = nxge_param_set_ip_opt(nxgep, NULL, 48696439Sml29623 NULL, (char *)pr_val, 48706439Sml29623 (caddr_t)¶m_arr[param_class_opt_ipv4_udp]); 48716439Sml29623 48726439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 48736439Sml29623 "<== nxge_set_priv_prop: name %s (value 0x%x)", 48746439Sml29623 pr_name, result)); 48756439Sml29623 48766439Sml29623 return (err); 48776439Sml29623 } 48786439Sml29623 if (strcmp(pr_name, "_class_opt_ipv4_ah") == 0) { 48796439Sml29623 if (pr_val == NULL) { 48806439Sml29623 err = EINVAL; 48816439Sml29623 return (err); 48826439Sml29623 } 48836439Sml29623 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 48846439Sml29623 48856439Sml29623 err = nxge_param_set_ip_opt(nxgep, NULL, 48866439Sml29623 NULL, (char *)pr_val, 48876439Sml29623 (caddr_t)¶m_arr[param_class_opt_ipv4_ah]); 48886439Sml29623 48896439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 48906439Sml29623 "<== nxge_set_priv_prop: name %s (value 0x%x)", 48916439Sml29623 pr_name, result)); 48926439Sml29623 48936439Sml29623 return (err); 48946439Sml29623 } 48956439Sml29623 if (strcmp(pr_name, "_class_opt_ipv4_sctp") == 0) { 48966439Sml29623 if (pr_val == NULL) { 48976439Sml29623 err = EINVAL; 48986439Sml29623 return (err); 48996439Sml29623 } 49006439Sml29623 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 49016439Sml29623 49026439Sml29623 err = nxge_param_set_ip_opt(nxgep, NULL, 49036439Sml29623 NULL, (char *)pr_val, 49046439Sml29623 (caddr_t)¶m_arr[param_class_opt_ipv4_sctp]); 49056439Sml29623 49066439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 49076439Sml29623 "<== nxge_set_priv_prop: name %s (value 0x%x)", 49086439Sml29623 pr_name, result)); 49096439Sml29623 49106439Sml29623 return (err); 49116439Sml29623 } 49126439Sml29623 49136439Sml29623 if (strcmp(pr_name, "_class_opt_ipv6_tcp") == 0) { 49146439Sml29623 if (pr_val == NULL) { 49156439Sml29623 err = EINVAL; 49166439Sml29623 return (err); 49176439Sml29623 } 49186439Sml29623 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 49196439Sml29623 49206439Sml29623 err = nxge_param_set_ip_opt(nxgep, NULL, 49216439Sml29623 NULL, (char *)pr_val, 49226439Sml29623 (caddr_t)¶m_arr[param_class_opt_ipv6_tcp]); 49236439Sml29623 49246439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 49256439Sml29623 "<== nxge_set_priv_prop: name %s (value 0x%x)", 49266439Sml29623 pr_name, result)); 49276439Sml29623 49286439Sml29623 return (err); 49296439Sml29623 } 49306439Sml29623 49316439Sml29623 if (strcmp(pr_name, "_class_opt_ipv6_udp") == 0) { 49326439Sml29623 if (pr_val == NULL) { 49336439Sml29623 err = EINVAL; 49346439Sml29623 return (err); 49356439Sml29623 } 49366439Sml29623 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 49376439Sml29623 49386439Sml29623 err = nxge_param_set_ip_opt(nxgep, NULL, 49396439Sml29623 NULL, (char *)pr_val, 49406439Sml29623 (caddr_t)¶m_arr[param_class_opt_ipv6_udp]); 49416439Sml29623 49426439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 49436439Sml29623 "<== nxge_set_priv_prop: name %s (value 0x%x)", 49446439Sml29623 pr_name, result)); 49456439Sml29623 49466439Sml29623 return (err); 49476439Sml29623 } 49486439Sml29623 if (strcmp(pr_name, "_class_opt_ipv6_ah") == 0) { 49496439Sml29623 if (pr_val == NULL) { 49506439Sml29623 err = EINVAL; 49516439Sml29623 return (err); 49526439Sml29623 } 49536439Sml29623 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 49546439Sml29623 49556439Sml29623 err = nxge_param_set_ip_opt(nxgep, NULL, 49566439Sml29623 NULL, (char *)pr_val, 49576439Sml29623 (caddr_t)¶m_arr[param_class_opt_ipv6_ah]); 49586439Sml29623 49596439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 49606439Sml29623 "<== nxge_set_priv_prop: name %s (value 0x%x)", 49616439Sml29623 pr_name, result)); 49626439Sml29623 49636439Sml29623 return (err); 49646439Sml29623 } 49656439Sml29623 if (strcmp(pr_name, "_class_opt_ipv6_sctp") == 0) { 49666439Sml29623 if (pr_val == NULL) { 49676439Sml29623 err = EINVAL; 49686439Sml29623 return (err); 49696439Sml29623 } 49706439Sml29623 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 49716439Sml29623 49726439Sml29623 err = nxge_param_set_ip_opt(nxgep, NULL, 49736439Sml29623 NULL, (char *)pr_val, 49746439Sml29623 (caddr_t)¶m_arr[param_class_opt_ipv6_sctp]); 49756439Sml29623 49766439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 49776439Sml29623 "<== nxge_set_priv_prop: name %s (value 0x%x)", 49786439Sml29623 pr_name, result)); 49796439Sml29623 49806439Sml29623 return (err); 49816439Sml29623 } 49826439Sml29623 49836439Sml29623 if (strcmp(pr_name, "_soft_lso_enable") == 0) { 49846439Sml29623 if (pr_val == NULL) { 49856439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 49866439Sml29623 "==> nxge_set_priv_prop: name %s (null)", pr_name)); 49876439Sml29623 err = EINVAL; 49886439Sml29623 return (err); 49896439Sml29623 } 49906439Sml29623 49916439Sml29623 (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 49926439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 49936439Sml29623 "<== nxge_set_priv_prop: name %s " 49946439Sml29623 "(lso %d pr_val %s value %d)", 49956439Sml29623 pr_name, nxgep->soft_lso_enable, pr_val, result)); 49966439Sml29623 49976439Sml29623 if (result > 1 || result < 0) { 49986439Sml29623 err = EINVAL; 49996439Sml29623 } else { 50006439Sml29623 if (nxgep->soft_lso_enable == (uint32_t)result) { 50016439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 50026439Sml29623 "no change (%d %d)", 50036439Sml29623 nxgep->soft_lso_enable, result)); 50046439Sml29623 return (0); 50056439Sml29623 } 50066439Sml29623 } 50076439Sml29623 50086439Sml29623 nxgep->soft_lso_enable = (int)result; 50096439Sml29623 50106439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 50116439Sml29623 "<== nxge_set_priv_prop: name %s (value %d)", 50126439Sml29623 pr_name, result)); 50136439Sml29623 50146439Sml29623 return (err); 50156439Sml29623 } 50166835Syc148097 /* 50176835Syc148097 * Commands like "ndd -set /dev/nxge0 adv_10gfdx_cap 1" cause the 50186835Syc148097 * following code to be executed. 50196835Syc148097 */ 50206512Ssowmini if (strcmp(pr_name, "_adv_10gfdx_cap") == 0) { 50216512Ssowmini err = nxge_param_set_mac(nxgep, NULL, NULL, (char *)pr_val, 50226512Ssowmini (caddr_t)¶m_arr[param_anar_10gfdx]); 50236512Ssowmini return (err); 50246512Ssowmini } 50256512Ssowmini if (strcmp(pr_name, "_adv_pause_cap") == 0) { 50266512Ssowmini err = nxge_param_set_mac(nxgep, NULL, NULL, (char *)pr_val, 50276512Ssowmini (caddr_t)¶m_arr[param_anar_pause]); 50286512Ssowmini return (err); 50296512Ssowmini } 50306439Sml29623 50316439Sml29623 return (EINVAL); 50326439Sml29623 } 50336439Sml29623 50346439Sml29623 static int 50356512Ssowmini nxge_get_priv_prop(p_nxge_t nxgep, const char *pr_name, uint_t pr_flags, 50368118SVasumathi.Sundaram@Sun.COM uint_t pr_valsize, void *pr_val, uint_t *perm) 50376439Sml29623 { 50386439Sml29623 p_nxge_param_t param_arr = nxgep->param_arr; 50396439Sml29623 char valstr[MAXNAMELEN]; 50406439Sml29623 int err = EINVAL; 50416439Sml29623 uint_t strsize; 50426789Sam223141 boolean_t is_default = (pr_flags & MAC_PROP_DEFAULT); 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) { 50496512Ssowmini if (is_default) 50506512Ssowmini return (ENOTSUP); 50518118SVasumathi.Sundaram@Sun.COM *perm = MAC_PROP_PERM_READ; 50526512Ssowmini (void) snprintf(valstr, sizeof (valstr), "%d", 50536512Ssowmini nxgep->function_num); 50546439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 50556439Sml29623 "==> nxge_get_priv_prop: name %s " 50566439Sml29623 "(value %d valstr %s)", 50576439Sml29623 pr_name, nxgep->function_num, valstr)); 50586439Sml29623 50596439Sml29623 err = 0; 50606439Sml29623 goto done; 50616439Sml29623 } 50626439Sml29623 50636439Sml29623 /* Neptune firmware version */ 50646439Sml29623 if (strcmp(pr_name, "_fw_version") == 0) { 50656512Ssowmini if (is_default) 50666512Ssowmini return (ENOTSUP); 50678118SVasumathi.Sundaram@Sun.COM *perm = MAC_PROP_PERM_READ; 50686512Ssowmini (void) snprintf(valstr, sizeof (valstr), "%s", 50696512Ssowmini nxgep->vpd_info.ver); 50706439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 50716439Sml29623 "==> nxge_get_priv_prop: name %s " 50726439Sml29623 "(value %d valstr %s)", 50736439Sml29623 pr_name, nxgep->vpd_info.ver, valstr)); 50746439Sml29623 50756439Sml29623 err = 0; 50766439Sml29623 goto done; 50776439Sml29623 } 50786439Sml29623 50796439Sml29623 /* port PHY mode */ 50806439Sml29623 if (strcmp(pr_name, "_port_mode") == 0) { 50816512Ssowmini if (is_default) 50826512Ssowmini return (ENOTSUP); 50838118SVasumathi.Sundaram@Sun.COM *perm = MAC_PROP_PERM_READ; 50846439Sml29623 switch (nxgep->mac.portmode) { 50856439Sml29623 case PORT_1G_COPPER: 50866512Ssowmini (void) snprintf(valstr, sizeof (valstr), "1G copper %s", 50876439Sml29623 nxgep->hot_swappable_phy ? 50886439Sml29623 "[Hot Swappable]" : ""); 50896439Sml29623 break; 50906439Sml29623 case PORT_1G_FIBER: 50916512Ssowmini (void) snprintf(valstr, sizeof (valstr), "1G fiber %s", 50926439Sml29623 nxgep->hot_swappable_phy ? 50936439Sml29623 "[hot swappable]" : ""); 50946439Sml29623 break; 50956439Sml29623 case PORT_10G_COPPER: 50966512Ssowmini (void) snprintf(valstr, sizeof (valstr), 50976512Ssowmini "10G copper %s", 50986439Sml29623 nxgep->hot_swappable_phy ? 50996439Sml29623 "[hot swappable]" : ""); 51006439Sml29623 break; 51016439Sml29623 case PORT_10G_FIBER: 51026512Ssowmini (void) snprintf(valstr, sizeof (valstr), "10G fiber %s", 51036439Sml29623 nxgep->hot_swappable_phy ? 51046439Sml29623 "[hot swappable]" : ""); 51056439Sml29623 break; 51066439Sml29623 case PORT_10G_SERDES: 51076512Ssowmini (void) snprintf(valstr, sizeof (valstr), 51086512Ssowmini "10G serdes %s", nxgep->hot_swappable_phy ? 51096439Sml29623 "[hot swappable]" : ""); 51106439Sml29623 break; 51116439Sml29623 case PORT_1G_SERDES: 51126512Ssowmini (void) snprintf(valstr, sizeof (valstr), "1G serdes %s", 51136439Sml29623 nxgep->hot_swappable_phy ? 51146439Sml29623 "[hot swappable]" : ""); 51156439Sml29623 break; 51166835Syc148097 case PORT_1G_TN1010: 51176835Syc148097 (void) snprintf(valstr, sizeof (valstr), 51186835Syc148097 "1G TN1010 copper %s", nxgep->hot_swappable_phy ? 51196835Syc148097 "[hot swappable]" : ""); 51206835Syc148097 break; 51216835Syc148097 case PORT_10G_TN1010: 51226835Syc148097 (void) snprintf(valstr, sizeof (valstr), 51236835Syc148097 "10G TN1010 copper %s", nxgep->hot_swappable_phy ? 51246835Syc148097 "[hot swappable]" : ""); 51256835Syc148097 break; 51266439Sml29623 case PORT_1G_RGMII_FIBER: 51276512Ssowmini (void) snprintf(valstr, sizeof (valstr), 51286512Ssowmini "1G rgmii fiber %s", nxgep->hot_swappable_phy ? 51296439Sml29623 "[hot swappable]" : ""); 51306439Sml29623 break; 51316439Sml29623 case PORT_HSP_MODE: 51326512Ssowmini (void) snprintf(valstr, sizeof (valstr), 51336444Sml29623 "phy not present[hot swappable]"); 51346439Sml29623 break; 51356439Sml29623 default: 51366512Ssowmini (void) snprintf(valstr, sizeof (valstr), "unknown %s", 51376439Sml29623 nxgep->hot_swappable_phy ? 51386439Sml29623 "[hot swappable]" : ""); 51396439Sml29623 break; 51406439Sml29623 } 51416439Sml29623 51426439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 51436439Sml29623 "==> nxge_get_priv_prop: name %s (value %s)", 51446439Sml29623 pr_name, valstr)); 51456439Sml29623 51466439Sml29623 err = 0; 51476439Sml29623 goto done; 51486439Sml29623 } 51496439Sml29623 51506439Sml29623 /* Hot swappable PHY */ 51516439Sml29623 if (strcmp(pr_name, "_hot_swap_phy") == 0) { 51526512Ssowmini if (is_default) 51536512Ssowmini return (ENOTSUP); 51548118SVasumathi.Sundaram@Sun.COM *perm = MAC_PROP_PERM_READ; 51556512Ssowmini (void) snprintf(valstr, sizeof (valstr), "%s", 51566439Sml29623 nxgep->hot_swappable_phy ? 51576439Sml29623 "yes" : "no"); 51586439Sml29623 51596439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 51606439Sml29623 "==> nxge_get_priv_prop: name %s " 51616439Sml29623 "(value %d valstr %s)", 51626439Sml29623 pr_name, nxgep->hot_swappable_phy, valstr)); 51636439Sml29623 51646439Sml29623 err = 0; 51656439Sml29623 goto done; 51666439Sml29623 } 51676439Sml29623 51686439Sml29623 51696439Sml29623 /* accept jumbo */ 51706439Sml29623 if (strcmp(pr_name, "_accept_jumbo") == 0) { 51716512Ssowmini if (is_default) 51726512Ssowmini (void) snprintf(valstr, sizeof (valstr), "%d", 0); 51736512Ssowmini else 51746512Ssowmini (void) snprintf(valstr, sizeof (valstr), 51756512Ssowmini "%d", nxgep->mac.is_jumbo); 51766439Sml29623 err = 0; 51776439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 51786439Sml29623 "==> nxge_get_priv_prop: name %s (value %d (%d, %d))", 51796439Sml29623 pr_name, 51806439Sml29623 (uint32_t)param_arr[param_accept_jumbo].value, 51816439Sml29623 nxgep->mac.is_jumbo, 51826439Sml29623 nxge_jumbo_enable)); 51836439Sml29623 51846439Sml29623 goto done; 51856439Sml29623 } 51866439Sml29623 51876439Sml29623 /* Receive Interrupt Blanking Parameters */ 51886439Sml29623 if (strcmp(pr_name, "_rxdma_intr_time") == 0) { 51896512Ssowmini err = 0; 51906512Ssowmini if (is_default) { 51916512Ssowmini (void) snprintf(valstr, sizeof (valstr), 51926512Ssowmini "%d", RXDMA_RCR_TO_DEFAULT); 51936512Ssowmini goto done; 51946512Ssowmini } 51956512Ssowmini 51966512Ssowmini (void) snprintf(valstr, sizeof (valstr), "%d", 51976512Ssowmini nxgep->intr_timeout); 51986439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 51996439Sml29623 "==> nxge_get_priv_prop: name %s (value %d)", 52006439Sml29623 pr_name, 52016439Sml29623 (uint32_t)nxgep->intr_timeout)); 52026439Sml29623 goto done; 52036439Sml29623 } 52046439Sml29623 52056439Sml29623 if (strcmp(pr_name, "_rxdma_intr_pkts") == 0) { 52066512Ssowmini err = 0; 52076512Ssowmini if (is_default) { 52086512Ssowmini (void) snprintf(valstr, sizeof (valstr), 52096512Ssowmini "%d", RXDMA_RCR_PTHRES_DEFAULT); 52106512Ssowmini goto done; 52116512Ssowmini } 52126512Ssowmini (void) snprintf(valstr, sizeof (valstr), "%d", 52136512Ssowmini nxgep->intr_threshold); 52146439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 52156439Sml29623 "==> nxge_get_priv_prop: name %s (value %d)", 52166439Sml29623 pr_name, (uint32_t)nxgep->intr_threshold)); 52176439Sml29623 52186439Sml29623 goto done; 52196439Sml29623 } 52206439Sml29623 52216439Sml29623 /* Classification and Load Distribution Configuration */ 52226439Sml29623 if (strcmp(pr_name, "_class_opt_ipv4_tcp") == 0) { 52236512Ssowmini if (is_default) { 52246512Ssowmini (void) snprintf(valstr, sizeof (valstr), "%x", 52256512Ssowmini NXGE_CLASS_FLOW_GEN_SERVER); 52266512Ssowmini err = 0; 52276512Ssowmini goto done; 52286512Ssowmini } 52296439Sml29623 err = nxge_dld_get_ip_opt(nxgep, 52306439Sml29623 (caddr_t)¶m_arr[param_class_opt_ipv4_tcp]); 52316439Sml29623 52326512Ssowmini (void) snprintf(valstr, sizeof (valstr), "%x", 52336439Sml29623 (int)param_arr[param_class_opt_ipv4_tcp].value); 52346439Sml29623 52356439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 52366439Sml29623 "==> nxge_get_priv_prop: %s", valstr)); 52376439Sml29623 goto done; 52386439Sml29623 } 52396439Sml29623 52406439Sml29623 if (strcmp(pr_name, "_class_opt_ipv4_udp") == 0) { 52416512Ssowmini if (is_default) { 52426512Ssowmini (void) snprintf(valstr, sizeof (valstr), "%x", 52436512Ssowmini NXGE_CLASS_FLOW_GEN_SERVER); 52446512Ssowmini err = 0; 52456512Ssowmini goto done; 52466512Ssowmini } 52476439Sml29623 err = nxge_dld_get_ip_opt(nxgep, 52486439Sml29623 (caddr_t)¶m_arr[param_class_opt_ipv4_udp]); 52496439Sml29623 52506512Ssowmini (void) snprintf(valstr, sizeof (valstr), "%x", 52516439Sml29623 (int)param_arr[param_class_opt_ipv4_udp].value); 52526439Sml29623 52536439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 52546439Sml29623 "==> nxge_get_priv_prop: %s", valstr)); 52556439Sml29623 goto done; 52566439Sml29623 } 52576439Sml29623 if (strcmp(pr_name, "_class_opt_ipv4_ah") == 0) { 52586512Ssowmini if (is_default) { 52596512Ssowmini (void) snprintf(valstr, sizeof (valstr), "%x", 52606512Ssowmini NXGE_CLASS_FLOW_GEN_SERVER); 52616512Ssowmini err = 0; 52626512Ssowmini goto done; 52636512Ssowmini } 52646439Sml29623 err = nxge_dld_get_ip_opt(nxgep, 52656439Sml29623 (caddr_t)¶m_arr[param_class_opt_ipv4_ah]); 52666439Sml29623 52676512Ssowmini (void) snprintf(valstr, sizeof (valstr), "%x", 52686439Sml29623 (int)param_arr[param_class_opt_ipv4_ah].value); 52696439Sml29623 52706439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 52716439Sml29623 "==> nxge_get_priv_prop: %s", valstr)); 52726439Sml29623 goto done; 52736439Sml29623 } 52746439Sml29623 52756439Sml29623 if (strcmp(pr_name, "_class_opt_ipv4_sctp") == 0) { 52766512Ssowmini if (is_default) { 52776512Ssowmini (void) snprintf(valstr, sizeof (valstr), "%x", 52786512Ssowmini NXGE_CLASS_FLOW_GEN_SERVER); 52796512Ssowmini err = 0; 52806512Ssowmini goto done; 52816512Ssowmini } 52826439Sml29623 err = nxge_dld_get_ip_opt(nxgep, 52836439Sml29623 (caddr_t)¶m_arr[param_class_opt_ipv4_sctp]); 52846439Sml29623 52856512Ssowmini (void) snprintf(valstr, sizeof (valstr), "%x", 52866439Sml29623 (int)param_arr[param_class_opt_ipv4_sctp].value); 52876439Sml29623 52886439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 52896439Sml29623 "==> nxge_get_priv_prop: %s", valstr)); 52906439Sml29623 goto done; 52916439Sml29623 } 52926439Sml29623 52936439Sml29623 if (strcmp(pr_name, "_class_opt_ipv6_tcp") == 0) { 52946512Ssowmini if (is_default) { 52956512Ssowmini (void) snprintf(valstr, sizeof (valstr), "%x", 52966512Ssowmini NXGE_CLASS_FLOW_GEN_SERVER); 52976512Ssowmini err = 0; 52986512Ssowmini goto done; 52996512Ssowmini } 53006439Sml29623 err = nxge_dld_get_ip_opt(nxgep, 53016439Sml29623 (caddr_t)¶m_arr[param_class_opt_ipv6_tcp]); 53026439Sml29623 53036512Ssowmini (void) snprintf(valstr, sizeof (valstr), "%x", 53046439Sml29623 (int)param_arr[param_class_opt_ipv6_tcp].value); 53056439Sml29623 53066439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 53076439Sml29623 "==> nxge_get_priv_prop: %s", valstr)); 53086439Sml29623 goto done; 53096439Sml29623 } 53106439Sml29623 53116439Sml29623 if (strcmp(pr_name, "_class_opt_ipv6_udp") == 0) { 53126512Ssowmini if (is_default) { 53136512Ssowmini (void) snprintf(valstr, sizeof (valstr), "%x", 53146512Ssowmini NXGE_CLASS_FLOW_GEN_SERVER); 53156512Ssowmini err = 0; 53166512Ssowmini goto done; 53176512Ssowmini } 53186439Sml29623 err = nxge_dld_get_ip_opt(nxgep, 53196439Sml29623 (caddr_t)¶m_arr[param_class_opt_ipv6_udp]); 53206439Sml29623 53216512Ssowmini (void) snprintf(valstr, sizeof (valstr), "%x", 53226439Sml29623 (int)param_arr[param_class_opt_ipv6_udp].value); 53236439Sml29623 53246439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 53256439Sml29623 "==> nxge_get_priv_prop: %s", valstr)); 53266439Sml29623 goto done; 53276439Sml29623 } 53286439Sml29623 53296439Sml29623 if (strcmp(pr_name, "_class_opt_ipv6_ah") == 0) { 53306512Ssowmini if (is_default) { 53316512Ssowmini (void) snprintf(valstr, sizeof (valstr), "%x", 53326512Ssowmini NXGE_CLASS_FLOW_GEN_SERVER); 53336512Ssowmini err = 0; 53346512Ssowmini goto done; 53356512Ssowmini } 53366439Sml29623 err = nxge_dld_get_ip_opt(nxgep, 53376439Sml29623 (caddr_t)¶m_arr[param_class_opt_ipv6_ah]); 53386439Sml29623 53396512Ssowmini (void) snprintf(valstr, sizeof (valstr), "%x", 53406439Sml29623 (int)param_arr[param_class_opt_ipv6_ah].value); 53416439Sml29623 53426439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 53436439Sml29623 "==> nxge_get_priv_prop: %s", valstr)); 53446439Sml29623 goto done; 53456439Sml29623 } 53466439Sml29623 53476439Sml29623 if (strcmp(pr_name, "_class_opt_ipv6_sctp") == 0) { 53486512Ssowmini if (is_default) { 53496512Ssowmini (void) snprintf(valstr, sizeof (valstr), "%x", 53506512Ssowmini NXGE_CLASS_FLOW_GEN_SERVER); 53516512Ssowmini err = 0; 53526512Ssowmini goto done; 53536512Ssowmini } 53546439Sml29623 err = nxge_dld_get_ip_opt(nxgep, 53556439Sml29623 (caddr_t)¶m_arr[param_class_opt_ipv6_sctp]); 53566439Sml29623 53576512Ssowmini (void) snprintf(valstr, sizeof (valstr), "%x", 53586439Sml29623 (int)param_arr[param_class_opt_ipv6_sctp].value); 53596439Sml29623 53606439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 53616439Sml29623 "==> nxge_get_priv_prop: %s", valstr)); 53626439Sml29623 goto done; 53636439Sml29623 } 53646439Sml29623 53656439Sml29623 /* Software LSO */ 53666439Sml29623 if (strcmp(pr_name, "_soft_lso_enable") == 0) { 53676512Ssowmini if (is_default) { 53686512Ssowmini (void) snprintf(valstr, sizeof (valstr), "%d", 0); 53696512Ssowmini err = 0; 53706512Ssowmini goto done; 53716512Ssowmini } 53726512Ssowmini (void) snprintf(valstr, sizeof (valstr), 53736512Ssowmini "%d", nxgep->soft_lso_enable); 53746439Sml29623 err = 0; 53756439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 53766439Sml29623 "==> nxge_get_priv_prop: name %s (value %d)", 53776439Sml29623 pr_name, nxgep->soft_lso_enable)); 53786439Sml29623 53796439Sml29623 goto done; 53806439Sml29623 } 53816512Ssowmini if (strcmp(pr_name, "_adv_10gfdx_cap") == 0) { 53826512Ssowmini err = 0; 53836512Ssowmini if (is_default || 53846512Ssowmini nxgep->param_arr[param_anar_10gfdx].value != 0) { 53856512Ssowmini (void) snprintf(valstr, sizeof (valstr), "%d", 1); 53866512Ssowmini goto done; 53876512Ssowmini } else { 53886512Ssowmini (void) snprintf(valstr, sizeof (valstr), "%d", 0); 53896512Ssowmini goto done; 53906512Ssowmini } 53916512Ssowmini } 53926512Ssowmini if (strcmp(pr_name, "_adv_pause_cap") == 0) { 53936512Ssowmini err = 0; 53946512Ssowmini if (is_default || 53956512Ssowmini nxgep->param_arr[param_anar_pause].value != 0) { 53966512Ssowmini (void) snprintf(valstr, sizeof (valstr), "%d", 1); 53976512Ssowmini goto done; 53986512Ssowmini } else { 53996512Ssowmini (void) snprintf(valstr, sizeof (valstr), "%d", 0); 54006512Ssowmini goto done; 54016512Ssowmini } 54026512Ssowmini } 54036439Sml29623 54046439Sml29623 done: 54056439Sml29623 if (err == 0) { 54066439Sml29623 strsize = (uint_t)strlen(valstr); 54076439Sml29623 if (pr_valsize < strsize) { 54086439Sml29623 err = ENOBUFS; 54096439Sml29623 } else { 54106439Sml29623 (void) strlcpy(pr_val, valstr, pr_valsize); 54116439Sml29623 } 54126439Sml29623 } 54136439Sml29623 54146439Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_CTL, 54156439Sml29623 "<== nxge_get_priv_prop: return %d", err)); 54166439Sml29623 return (err); 54176439Sml29623 } 54186439Sml29623 54193859Sml29623 /* 54203859Sml29623 * Module loading and removing entry points. 54213859Sml29623 */ 54223859Sml29623 54236705Sml29623 DDI_DEFINE_STREAM_OPS(nxge_dev_ops, nulldev, nulldev, nxge_attach, nxge_detach, 54247656SSherry.Moore@Sun.COM nodev, NULL, D_MP, NULL, nxge_quiesce); 54253859Sml29623 54264977Sraghus #define NXGE_DESC_VER "Sun NIU 10Gb Ethernet" 54273859Sml29623 54283859Sml29623 /* 54293859Sml29623 * Module linkage information for the kernel. 54303859Sml29623 */ 54313859Sml29623 static struct modldrv nxge_modldrv = { 54323859Sml29623 &mod_driverops, 54333859Sml29623 NXGE_DESC_VER, 54343859Sml29623 &nxge_dev_ops 54353859Sml29623 }; 54363859Sml29623 54373859Sml29623 static struct modlinkage modlinkage = { 54383859Sml29623 MODREV_1, (void *) &nxge_modldrv, NULL 54393859Sml29623 }; 54403859Sml29623 54413859Sml29623 int 54423859Sml29623 _init(void) 54433859Sml29623 { 54443859Sml29623 int status; 54453859Sml29623 54463859Sml29623 NXGE_DEBUG_MSG((NULL, MOD_CTL, "==> _init")); 54473859Sml29623 mac_init_ops(&nxge_dev_ops, "nxge"); 54483859Sml29623 status = ddi_soft_state_init(&nxge_list, sizeof (nxge_t), 0); 54493859Sml29623 if (status != 0) { 54503859Sml29623 NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL, 54516512Ssowmini "failed to init device soft state")); 54523859Sml29623 goto _init_exit; 54533859Sml29623 } 54543859Sml29623 status = mod_install(&modlinkage); 54553859Sml29623 if (status != 0) { 54563859Sml29623 ddi_soft_state_fini(&nxge_list); 54573859Sml29623 NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL, "Mod install failed")); 54583859Sml29623 goto _init_exit; 54593859Sml29623 } 54603859Sml29623 54613859Sml29623 MUTEX_INIT(&nxge_common_lock, NULL, MUTEX_DRIVER, NULL); 54623859Sml29623 54633859Sml29623 _init_exit: 54643859Sml29623 NXGE_DEBUG_MSG((NULL, MOD_CTL, "_init status = 0x%X", status)); 54653859Sml29623 54663859Sml29623 return (status); 54673859Sml29623 } 54683859Sml29623 54693859Sml29623 int 54703859Sml29623 _fini(void) 54713859Sml29623 { 54723859Sml29623 int status; 54733859Sml29623 54743859Sml29623 NXGE_DEBUG_MSG((NULL, MOD_CTL, "==> _fini")); 54753859Sml29623 54763859Sml29623 NXGE_DEBUG_MSG((NULL, MOD_CTL, "==> _fini: mod_remove")); 54773859Sml29623 54783859Sml29623 if (nxge_mblks_pending) 54793859Sml29623 return (EBUSY); 54803859Sml29623 54813859Sml29623 status = mod_remove(&modlinkage); 54823859Sml29623 if (status != DDI_SUCCESS) { 54833859Sml29623 NXGE_DEBUG_MSG((NULL, MOD_CTL, 54846512Ssowmini "Module removal failed 0x%08x", 54856512Ssowmini status)); 54863859Sml29623 goto _fini_exit; 54873859Sml29623 } 54883859Sml29623 54893859Sml29623 mac_fini_ops(&nxge_dev_ops); 54903859Sml29623 54913859Sml29623 ddi_soft_state_fini(&nxge_list); 54923859Sml29623 54933859Sml29623 MUTEX_DESTROY(&nxge_common_lock); 54943859Sml29623 _fini_exit: 54953859Sml29623 NXGE_DEBUG_MSG((NULL, MOD_CTL, "_fini status = 0x%08x", status)); 54963859Sml29623 54973859Sml29623 return (status); 54983859Sml29623 } 54993859Sml29623 55003859Sml29623 int 55013859Sml29623 _info(struct modinfo *modinfop) 55023859Sml29623 { 55033859Sml29623 int status; 55043859Sml29623 55053859Sml29623 NXGE_DEBUG_MSG((NULL, MOD_CTL, "==> _info")); 55063859Sml29623 status = mod_info(&modlinkage, modinfop); 55073859Sml29623 NXGE_DEBUG_MSG((NULL, MOD_CTL, " _info status = 0x%X", status)); 55083859Sml29623 55093859Sml29623 return (status); 55103859Sml29623 } 55113859Sml29623 55123859Sml29623 /*ARGSUSED*/ 55138275SEric Cheng static int 55148275SEric Cheng nxge_tx_ring_start(mac_ring_driver_t rdriver, uint64_t mr_gen_num) 55158275SEric Cheng { 55168275SEric Cheng p_nxge_ring_handle_t rhp = (p_nxge_ring_handle_t)rdriver; 55178275SEric Cheng p_nxge_t nxgep = rhp->nxgep; 55188275SEric Cheng uint32_t channel; 55198275SEric Cheng p_tx_ring_t ring; 55208275SEric Cheng 55218275SEric Cheng channel = nxgep->pt_config.hw_config.tdc.start + rhp->index; 55228275SEric Cheng ring = nxgep->tx_rings->rings[channel]; 55238275SEric Cheng 55248275SEric Cheng MUTEX_ENTER(&ring->lock); 55258275SEric Cheng ring->tx_ring_handle = rhp->ring_handle; 55268275SEric Cheng MUTEX_EXIT(&ring->lock); 55278275SEric Cheng 55288275SEric Cheng return (0); 55298275SEric Cheng } 55308275SEric Cheng 55318275SEric Cheng static void 55328275SEric Cheng nxge_tx_ring_stop(mac_ring_driver_t rdriver) 55338275SEric Cheng { 55348275SEric Cheng p_nxge_ring_handle_t rhp = (p_nxge_ring_handle_t)rdriver; 55358275SEric Cheng p_nxge_t nxgep = rhp->nxgep; 55368275SEric Cheng uint32_t channel; 55378275SEric Cheng p_tx_ring_t ring; 55388275SEric Cheng 55398275SEric Cheng channel = nxgep->pt_config.hw_config.tdc.start + rhp->index; 55408275SEric Cheng ring = nxgep->tx_rings->rings[channel]; 55418275SEric Cheng 55428275SEric Cheng MUTEX_ENTER(&ring->lock); 55438275SEric Cheng ring->tx_ring_handle = (mac_ring_handle_t)NULL; 55448275SEric Cheng MUTEX_EXIT(&ring->lock); 55458275SEric Cheng } 55468275SEric Cheng 55478275SEric Cheng static int 55488275SEric Cheng nxge_rx_ring_start(mac_ring_driver_t rdriver, uint64_t mr_gen_num) 55498275SEric Cheng { 55508275SEric Cheng p_nxge_ring_handle_t rhp = (p_nxge_ring_handle_t)rdriver; 55518275SEric Cheng p_nxge_t nxgep = rhp->nxgep; 55528275SEric Cheng uint32_t channel; 55538275SEric Cheng p_rx_rcr_ring_t ring; 55548275SEric Cheng int i; 55558275SEric Cheng 55568275SEric Cheng channel = nxgep->pt_config.hw_config.start_rdc + rhp->index; 55578275SEric Cheng ring = nxgep->rx_rcr_rings->rcr_rings[channel]; 55588275SEric Cheng 55598275SEric Cheng MUTEX_ENTER(&ring->lock); 55608275SEric Cheng 55618275SEric Cheng if (nxgep->rx_channel_started[channel] == B_TRUE) { 55628275SEric Cheng MUTEX_EXIT(&ring->lock); 55638275SEric Cheng return (0); 55648275SEric Cheng } 55658275SEric Cheng 55668275SEric Cheng /* set rcr_ring */ 55678275SEric Cheng for (i = 0; i < nxgep->ldgvp->maxldvs; i++) { 55688275SEric Cheng if ((nxgep->ldgvp->ldvp[i].is_rxdma == 1) && 55698275SEric Cheng (nxgep->ldgvp->ldvp[i].channel == channel)) { 55708275SEric Cheng ring->ldvp = &nxgep->ldgvp->ldvp[i]; 55718275SEric Cheng ring->ldgp = nxgep->ldgvp->ldvp[i].ldgp; 55728275SEric Cheng } 55738275SEric Cheng } 55748275SEric Cheng 55758275SEric Cheng nxgep->rx_channel_started[channel] = B_TRUE; 55768275SEric Cheng ring->rcr_mac_handle = rhp->ring_handle; 55778275SEric Cheng ring->rcr_gen_num = mr_gen_num; 55788275SEric Cheng MUTEX_EXIT(&ring->lock); 55798275SEric Cheng 55808275SEric Cheng return (0); 55818275SEric Cheng } 55828275SEric Cheng 55838275SEric Cheng static void 55848275SEric Cheng nxge_rx_ring_stop(mac_ring_driver_t rdriver) 55858275SEric Cheng { 55868275SEric Cheng p_nxge_ring_handle_t rhp = (p_nxge_ring_handle_t)rdriver; 55878275SEric Cheng p_nxge_t nxgep = rhp->nxgep; 55888275SEric Cheng uint32_t channel; 55898275SEric Cheng p_rx_rcr_ring_t ring; 55908275SEric Cheng 55918275SEric Cheng channel = nxgep->pt_config.hw_config.start_rdc + rhp->index; 55928275SEric Cheng ring = nxgep->rx_rcr_rings->rcr_rings[channel]; 55938275SEric Cheng 55948275SEric Cheng MUTEX_ENTER(&ring->lock); 55958275SEric Cheng nxgep->rx_channel_started[channel] = B_FALSE; 55968275SEric Cheng ring->rcr_mac_handle = NULL; 55978275SEric Cheng MUTEX_EXIT(&ring->lock); 55988275SEric Cheng } 55998275SEric Cheng 56008275SEric Cheng /* 56018275SEric Cheng * Callback funtion for MAC layer to register all rings. 56028275SEric Cheng */ 56038275SEric Cheng static void 56048275SEric Cheng nxge_fill_ring(void *arg, mac_ring_type_t rtype, const int rg_index, 56058275SEric Cheng const int index, mac_ring_info_t *infop, mac_ring_handle_t rh) 56068275SEric Cheng { 56078275SEric Cheng p_nxge_t nxgep = (p_nxge_t)arg; 56088275SEric Cheng p_nxge_hw_pt_cfg_t p_cfgp = &nxgep->pt_config.hw_config; 56098275SEric Cheng 56108275SEric Cheng NXGE_DEBUG_MSG((nxgep, TX_CTL, 56118275SEric Cheng "==> nxge_fill_ring 0x%x index %d", rtype, index)); 56128275SEric Cheng 56138275SEric Cheng switch (rtype) { 56148275SEric Cheng case MAC_RING_TYPE_TX: { 56158275SEric Cheng p_nxge_ring_handle_t rhandlep; 56168275SEric Cheng 56178275SEric Cheng NXGE_DEBUG_MSG((nxgep, TX_CTL, 56188275SEric Cheng "==> nxge_fill_ring (TX) 0x%x index %d ntdcs %d", 56198275SEric Cheng rtype, index, p_cfgp->tdc.count)); 56208275SEric Cheng 56218275SEric Cheng ASSERT((index >= 0) && (index < p_cfgp->tdc.count)); 56228275SEric Cheng rhandlep = &nxgep->tx_ring_handles[index]; 56238275SEric Cheng rhandlep->nxgep = nxgep; 56248275SEric Cheng rhandlep->index = index; 56258275SEric Cheng rhandlep->ring_handle = rh; 56268275SEric Cheng 56278275SEric Cheng infop->mri_driver = (mac_ring_driver_t)rhandlep; 56288275SEric Cheng infop->mri_start = nxge_tx_ring_start; 56298275SEric Cheng infop->mri_stop = nxge_tx_ring_stop; 56308275SEric Cheng infop->mri_tx = nxge_tx_ring_send; 56318275SEric Cheng 56328275SEric Cheng break; 56338275SEric Cheng } 56348275SEric Cheng case MAC_RING_TYPE_RX: { 56358275SEric Cheng p_nxge_ring_handle_t rhandlep; 56368275SEric Cheng int nxge_rindex; 56378275SEric Cheng mac_intr_t nxge_mac_intr; 56388275SEric Cheng 56398275SEric Cheng NXGE_DEBUG_MSG((nxgep, RX_CTL, 56408275SEric Cheng "==> nxge_fill_ring (RX) 0x%x index %d nrdcs %d", 56418275SEric Cheng rtype, index, p_cfgp->max_rdcs)); 56428275SEric Cheng 56438275SEric Cheng /* 56448275SEric Cheng * 'index' is the ring index within the group. 56458275SEric Cheng * Find the ring index in the nxge instance. 56468275SEric Cheng */ 56478275SEric Cheng nxge_rindex = nxge_get_rxring_index(nxgep, rg_index, index); 56488275SEric Cheng 56498275SEric Cheng ASSERT((nxge_rindex >= 0) && (nxge_rindex < p_cfgp->max_rdcs)); 56508275SEric Cheng rhandlep = &nxgep->rx_ring_handles[nxge_rindex]; 56518275SEric Cheng rhandlep->nxgep = nxgep; 56528275SEric Cheng rhandlep->index = nxge_rindex; 56538275SEric Cheng rhandlep->ring_handle = rh; 56548275SEric Cheng 56558275SEric Cheng /* 56568275SEric Cheng * Entrypoint to enable interrupt (disable poll) and 56578275SEric Cheng * disable interrupt (enable poll). 56588275SEric Cheng */ 56598275SEric Cheng nxge_mac_intr.mi_handle = (mac_intr_handle_t)rhandlep; 56608275SEric Cheng nxge_mac_intr.mi_enable = (mac_intr_enable_t)nxge_disable_poll; 56618275SEric Cheng nxge_mac_intr.mi_disable = (mac_intr_disable_t)nxge_enable_poll; 56628275SEric Cheng infop->mri_driver = (mac_ring_driver_t)rhandlep; 56638275SEric Cheng infop->mri_start = nxge_rx_ring_start; 56648275SEric Cheng infop->mri_stop = nxge_rx_ring_stop; 56658275SEric Cheng infop->mri_intr = nxge_mac_intr; /* ??? */ 56668275SEric Cheng infop->mri_poll = nxge_rx_poll; 56678275SEric Cheng 56688275SEric Cheng break; 56698275SEric Cheng } 56708275SEric Cheng default: 56718275SEric Cheng break; 56728275SEric Cheng } 56738275SEric Cheng 56748275SEric Cheng NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_fill_ring 0x%x", 56758275SEric Cheng rtype)); 56768275SEric Cheng } 56778275SEric Cheng 56788275SEric Cheng static void 56798275SEric Cheng nxge_group_add_ring(mac_group_driver_t gh, mac_ring_driver_t rh, 56808275SEric Cheng mac_ring_type_t type) 56818275SEric Cheng { 56828275SEric Cheng nxge_ring_group_t *rgroup = (nxge_ring_group_t *)gh; 56838275SEric Cheng nxge_ring_handle_t *rhandle = (nxge_ring_handle_t *)rh; 56848275SEric Cheng nxge_t *nxge; 56858275SEric Cheng nxge_grp_t *grp; 56868275SEric Cheng nxge_rdc_grp_t *rdc_grp; 56878275SEric Cheng uint16_t channel; /* device-wise ring id */ 56888275SEric Cheng int dev_gindex; 56898275SEric Cheng int rv; 56908275SEric Cheng 56918275SEric Cheng nxge = rgroup->nxgep; 56928275SEric Cheng 56938275SEric Cheng switch (type) { 56948275SEric Cheng case MAC_RING_TYPE_TX: 56958275SEric Cheng /* 56968275SEric Cheng * nxge_grp_dc_add takes a channel number which is a 56978275SEric Cheng * "devise" ring ID. 56988275SEric Cheng */ 56998275SEric Cheng channel = nxge->pt_config.hw_config.tdc.start + rhandle->index; 57008275SEric Cheng 57018275SEric Cheng /* 57028275SEric Cheng * Remove the ring from the default group 57038275SEric Cheng */ 57048275SEric Cheng if (rgroup->gindex != 0) { 57058275SEric Cheng (void) nxge_grp_dc_remove(nxge, VP_BOUND_TX, channel); 57068275SEric Cheng } 57078275SEric Cheng 57088275SEric Cheng /* 57098275SEric Cheng * nxge->tx_set.group[] is an array of groups indexed by 57108275SEric Cheng * a "port" group ID. 57118275SEric Cheng */ 57128275SEric Cheng grp = nxge->tx_set.group[rgroup->gindex]; 57138275SEric Cheng rv = nxge_grp_dc_add(nxge, grp, VP_BOUND_TX, channel); 57148275SEric Cheng if (rv != 0) { 57158275SEric Cheng NXGE_ERROR_MSG((nxge, NXGE_ERR_CTL, 57168275SEric Cheng "nxge_group_add_ring: nxge_grp_dc_add failed")); 57178275SEric Cheng } 57188275SEric Cheng break; 57198275SEric Cheng 57208275SEric Cheng case MAC_RING_TYPE_RX: 57218275SEric Cheng /* 57228275SEric Cheng * nxge->rx_set.group[] is an array of groups indexed by 57238275SEric Cheng * a "port" group ID. 57248275SEric Cheng */ 57258275SEric Cheng grp = nxge->rx_set.group[rgroup->gindex]; 57268275SEric Cheng 57278275SEric Cheng dev_gindex = nxge->pt_config.hw_config.def_mac_rxdma_grpid + 57288275SEric Cheng rgroup->gindex; 57298275SEric Cheng rdc_grp = &nxge->pt_config.rdc_grps[dev_gindex]; 57308275SEric Cheng 57318275SEric Cheng /* 57328275SEric Cheng * nxge_grp_dc_add takes a channel number which is a 57338275SEric Cheng * "devise" ring ID. 57348275SEric Cheng */ 57358275SEric Cheng channel = nxge->pt_config.hw_config.start_rdc + rhandle->index; 57368275SEric Cheng rv = nxge_grp_dc_add(nxge, grp, VP_BOUND_RX, channel); 57378275SEric Cheng if (rv != 0) { 57388275SEric Cheng NXGE_ERROR_MSG((nxge, NXGE_ERR_CTL, 57398275SEric Cheng "nxge_group_add_ring: nxge_grp_dc_add failed")); 57408275SEric Cheng } 57418275SEric Cheng 57428275SEric Cheng rdc_grp->map |= (1 << channel); 57438275SEric Cheng rdc_grp->max_rdcs++; 57448275SEric Cheng 57459047SMichael.Speer@Sun.COM (void) nxge_init_fzc_rdc_tbl(nxge, rdc_grp, rgroup->rdctbl); 57468275SEric Cheng break; 57478275SEric Cheng } 57488275SEric Cheng } 57498275SEric Cheng 57508275SEric Cheng static void 57518275SEric Cheng nxge_group_rem_ring(mac_group_driver_t gh, mac_ring_driver_t rh, 57528275SEric Cheng mac_ring_type_t type) 57538275SEric Cheng { 57548275SEric Cheng nxge_ring_group_t *rgroup = (nxge_ring_group_t *)gh; 57558275SEric Cheng nxge_ring_handle_t *rhandle = (nxge_ring_handle_t *)rh; 57568275SEric Cheng nxge_t *nxge; 57578275SEric Cheng uint16_t channel; /* device-wise ring id */ 57588275SEric Cheng nxge_rdc_grp_t *rdc_grp; 57598275SEric Cheng int dev_gindex; 57608275SEric Cheng 57618275SEric Cheng nxge = rgroup->nxgep; 57628275SEric Cheng 57638275SEric Cheng switch (type) { 57648275SEric Cheng case MAC_RING_TYPE_TX: 57658275SEric Cheng dev_gindex = nxge->pt_config.hw_config.def_mac_txdma_grpid + 57668275SEric Cheng rgroup->gindex; 57678275SEric Cheng channel = nxge->pt_config.hw_config.tdc.start + rhandle->index; 57688275SEric Cheng nxge_grp_dc_remove(nxge, VP_BOUND_TX, channel); 57698275SEric Cheng 57708275SEric Cheng /* 57718275SEric Cheng * Add the ring back to the default group 57728275SEric Cheng */ 57738275SEric Cheng if (rgroup->gindex != 0) { 57748275SEric Cheng nxge_grp_t *grp; 57758275SEric Cheng grp = nxge->tx_set.group[0]; 57768275SEric Cheng (void) nxge_grp_dc_add(nxge, grp, VP_BOUND_TX, channel); 57778275SEric Cheng } 57788275SEric Cheng break; 57798275SEric Cheng 57808275SEric Cheng case MAC_RING_TYPE_RX: 57818275SEric Cheng dev_gindex = nxge->pt_config.hw_config.def_mac_rxdma_grpid + 57828275SEric Cheng rgroup->gindex; 57838275SEric Cheng rdc_grp = &nxge->pt_config.rdc_grps[dev_gindex]; 57848275SEric Cheng channel = rdc_grp->start_rdc + rhandle->index; 57858275SEric Cheng nxge_grp_dc_remove(nxge, VP_BOUND_RX, channel); 57868275SEric Cheng 57878275SEric Cheng rdc_grp->map &= ~(1 << channel); 57888275SEric Cheng rdc_grp->max_rdcs--; 57898275SEric Cheng 57909047SMichael.Speer@Sun.COM (void) nxge_init_fzc_rdc_tbl(nxge, rdc_grp, rgroup->rdctbl); 57918275SEric Cheng break; 57928275SEric Cheng } 57938275SEric Cheng } 57948275SEric Cheng 57958275SEric Cheng 57968275SEric Cheng /*ARGSUSED*/ 57973859Sml29623 static nxge_status_t 57983859Sml29623 nxge_add_intrs(p_nxge_t nxgep) 57993859Sml29623 { 58003859Sml29623 58013859Sml29623 int intr_types; 58023859Sml29623 int type = 0; 58033859Sml29623 int ddi_status = DDI_SUCCESS; 58043859Sml29623 nxge_status_t status = NXGE_OK; 58053859Sml29623 58063859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_add_intrs")); 58073859Sml29623 58083859Sml29623 nxgep->nxge_intr_type.intr_registered = B_FALSE; 58093859Sml29623 nxgep->nxge_intr_type.intr_enabled = B_FALSE; 58103859Sml29623 nxgep->nxge_intr_type.msi_intx_cnt = 0; 58113859Sml29623 nxgep->nxge_intr_type.intr_added = 0; 58123859Sml29623 nxgep->nxge_intr_type.niu_msi_enable = B_FALSE; 58133859Sml29623 nxgep->nxge_intr_type.intr_type = 0; 58143859Sml29623 58153859Sml29623 if (nxgep->niu_type == N2_NIU) { 58163859Sml29623 nxgep->nxge_intr_type.niu_msi_enable = B_TRUE; 58173859Sml29623 } else if (nxge_msi_enable) { 58183859Sml29623 nxgep->nxge_intr_type.niu_msi_enable = B_TRUE; 58193859Sml29623 } 58203859Sml29623 58213859Sml29623 /* Get the supported interrupt types */ 58223859Sml29623 if ((ddi_status = ddi_intr_get_supported_types(nxgep->dip, &intr_types)) 58236512Ssowmini != DDI_SUCCESS) { 58243859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "<== nxge_add_intrs: " 58256512Ssowmini "ddi_intr_get_supported_types failed: status 0x%08x", 58266512Ssowmini ddi_status)); 58273859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 58283859Sml29623 } 58293859Sml29623 nxgep->nxge_intr_type.intr_types = intr_types; 58303859Sml29623 58313859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_add_intrs: " 58326512Ssowmini "ddi_intr_get_supported_types: 0x%08x", intr_types)); 58333859Sml29623 58343859Sml29623 /* 58353859Sml29623 * Solaris MSIX is not supported yet. use MSI for now. 58363859Sml29623 * nxge_msi_enable (1): 58373859Sml29623 * 1 - MSI 2 - MSI-X others - FIXED 58383859Sml29623 */ 58393859Sml29623 switch (nxge_msi_enable) { 58403859Sml29623 default: 58413859Sml29623 type = DDI_INTR_TYPE_FIXED; 58423859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_add_intrs: " 58436512Ssowmini "use fixed (intx emulation) type %08x", 58446512Ssowmini type)); 58453859Sml29623 break; 58463859Sml29623 58473859Sml29623 case 2: 58483859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_add_intrs: " 58496512Ssowmini "ddi_intr_get_supported_types: 0x%08x", intr_types)); 58503859Sml29623 if (intr_types & DDI_INTR_TYPE_MSIX) { 58513859Sml29623 type = DDI_INTR_TYPE_MSIX; 58523859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_add_intrs: " 58536512Ssowmini "ddi_intr_get_supported_types: MSIX 0x%08x", 58546512Ssowmini type)); 58553859Sml29623 } else if (intr_types & DDI_INTR_TYPE_MSI) { 58563859Sml29623 type = DDI_INTR_TYPE_MSI; 58573859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_add_intrs: " 58586512Ssowmini "ddi_intr_get_supported_types: MSI 0x%08x", 58596512Ssowmini type)); 58603859Sml29623 } else if (intr_types & DDI_INTR_TYPE_FIXED) { 58613859Sml29623 type = DDI_INTR_TYPE_FIXED; 58623859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_add_intrs: " 58636512Ssowmini "ddi_intr_get_supported_types: MSXED0x%08x", 58646512Ssowmini type)); 58653859Sml29623 } 58663859Sml29623 break; 58673859Sml29623 58683859Sml29623 case 1: 58693859Sml29623 if (intr_types & DDI_INTR_TYPE_MSI) { 58703859Sml29623 type = DDI_INTR_TYPE_MSI; 58713859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_add_intrs: " 58726512Ssowmini "ddi_intr_get_supported_types: MSI 0x%08x", 58736512Ssowmini type)); 58743859Sml29623 } else if (intr_types & DDI_INTR_TYPE_MSIX) { 58753859Sml29623 type = DDI_INTR_TYPE_MSIX; 58763859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_add_intrs: " 58776512Ssowmini "ddi_intr_get_supported_types: MSIX 0x%08x", 58786512Ssowmini type)); 58793859Sml29623 } else if (intr_types & DDI_INTR_TYPE_FIXED) { 58803859Sml29623 type = DDI_INTR_TYPE_FIXED; 58813859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_add_intrs: " 58826512Ssowmini "ddi_intr_get_supported_types: MSXED0x%08x", 58836512Ssowmini type)); 58843859Sml29623 } 58853859Sml29623 } 58863859Sml29623 58873859Sml29623 nxgep->nxge_intr_type.intr_type = type; 58883859Sml29623 if ((type == DDI_INTR_TYPE_MSIX || type == DDI_INTR_TYPE_MSI || 58896512Ssowmini type == DDI_INTR_TYPE_FIXED) && 58906512Ssowmini nxgep->nxge_intr_type.niu_msi_enable) { 58913859Sml29623 if ((status = nxge_add_intrs_adv(nxgep)) != DDI_SUCCESS) { 58923859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 58936512Ssowmini " nxge_add_intrs: " 58946512Ssowmini " nxge_add_intrs_adv failed: status 0x%08x", 58956512Ssowmini status)); 58963859Sml29623 return (status); 58973859Sml29623 } else { 58983859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_add_intrs: " 58996512Ssowmini "interrupts registered : type %d", type)); 59003859Sml29623 nxgep->nxge_intr_type.intr_registered = B_TRUE; 59013859Sml29623 59023859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 59036512Ssowmini "\nAdded advanced nxge add_intr_adv " 59046512Ssowmini "intr type 0x%x\n", type)); 59053859Sml29623 59063859Sml29623 return (status); 59073859Sml29623 } 59083859Sml29623 } 59093859Sml29623 59103859Sml29623 if (!nxgep->nxge_intr_type.intr_registered) { 59113859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "==> nxge_add_intrs: " 59126512Ssowmini "failed to register interrupts")); 59133859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 59143859Sml29623 } 59153859Sml29623 59163859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_add_intrs")); 59173859Sml29623 return (status); 59183859Sml29623 } 59193859Sml29623 59203859Sml29623 static nxge_status_t 59213859Sml29623 nxge_add_intrs_adv(p_nxge_t nxgep) 59223859Sml29623 { 59233859Sml29623 int intr_type; 59243859Sml29623 p_nxge_intr_t intrp; 59253859Sml29623 59263859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_add_intrs_adv")); 59273859Sml29623 59283859Sml29623 intrp = (p_nxge_intr_t)&nxgep->nxge_intr_type; 59293859Sml29623 intr_type = intrp->intr_type; 59303859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_add_intrs_adv: type 0x%x", 59316512Ssowmini intr_type)); 59323859Sml29623 59333859Sml29623 switch (intr_type) { 59343859Sml29623 case DDI_INTR_TYPE_MSI: /* 0x2 */ 59353859Sml29623 case DDI_INTR_TYPE_MSIX: /* 0x4 */ 59363859Sml29623 return (nxge_add_intrs_adv_type(nxgep, intr_type)); 59373859Sml29623 59383859Sml29623 case DDI_INTR_TYPE_FIXED: /* 0x1 */ 59393859Sml29623 return (nxge_add_intrs_adv_type_fix(nxgep, intr_type)); 59403859Sml29623 59413859Sml29623 default: 59423859Sml29623 return (NXGE_ERROR); 59433859Sml29623 } 59443859Sml29623 } 59453859Sml29623 59463859Sml29623 59473859Sml29623 /*ARGSUSED*/ 59483859Sml29623 static nxge_status_t 59493859Sml29623 nxge_add_intrs_adv_type(p_nxge_t nxgep, uint32_t int_type) 59503859Sml29623 { 59513859Sml29623 dev_info_t *dip = nxgep->dip; 59523859Sml29623 p_nxge_ldg_t ldgp; 59533859Sml29623 p_nxge_intr_t intrp; 59543859Sml29623 uint_t *inthandler; 59553859Sml29623 void *arg1, *arg2; 59563859Sml29623 int behavior; 59575013Sml29623 int nintrs, navail, nrequest; 59583859Sml29623 int nactual, nrequired; 59593859Sml29623 int inum = 0; 59603859Sml29623 int x, y; 59613859Sml29623 int ddi_status = DDI_SUCCESS; 59623859Sml29623 nxge_status_t status = NXGE_OK; 59633859Sml29623 59643859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_add_intrs_adv_type")); 59653859Sml29623 intrp = (p_nxge_intr_t)&nxgep->nxge_intr_type; 59663859Sml29623 intrp->start_inum = 0; 59673859Sml29623 59683859Sml29623 ddi_status = ddi_intr_get_nintrs(dip, int_type, &nintrs); 59693859Sml29623 if ((ddi_status != DDI_SUCCESS) || (nintrs == 0)) { 59703859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 59716512Ssowmini "ddi_intr_get_nintrs() failed, status: 0x%x%, " 59726512Ssowmini "nintrs: %d", ddi_status, nintrs)); 59733859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 59743859Sml29623 } 59753859Sml29623 59763859Sml29623 ddi_status = ddi_intr_get_navail(dip, int_type, &navail); 59773859Sml29623 if ((ddi_status != DDI_SUCCESS) || (navail == 0)) { 59783859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 59796512Ssowmini "ddi_intr_get_navail() failed, status: 0x%x%, " 59806512Ssowmini "nintrs: %d", ddi_status, navail)); 59813859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 59823859Sml29623 } 59833859Sml29623 59843859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, 59856512Ssowmini "ddi_intr_get_navail() returned: nintrs %d, navail %d", 59866512Ssowmini nintrs, navail)); 59873859Sml29623 59885013Sml29623 /* PSARC/2007/453 MSI-X interrupt limit override */ 59895013Sml29623 if (int_type == DDI_INTR_TYPE_MSIX) { 59905013Sml29623 nrequest = nxge_create_msi_property(nxgep); 59915013Sml29623 if (nrequest < navail) { 59925013Sml29623 navail = nrequest; 59935013Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, 59945013Sml29623 "nxge_add_intrs_adv_type: nintrs %d " 59955013Sml29623 "navail %d (nrequest %d)", 59965013Sml29623 nintrs, navail, nrequest)); 59975013Sml29623 } 59985013Sml29623 } 59995013Sml29623 60003859Sml29623 if (int_type == DDI_INTR_TYPE_MSI && !ISP2(navail)) { 60013859Sml29623 /* MSI must be power of 2 */ 60023859Sml29623 if ((navail & 16) == 16) { 60033859Sml29623 navail = 16; 60043859Sml29623 } else if ((navail & 8) == 8) { 60053859Sml29623 navail = 8; 60063859Sml29623 } else if ((navail & 4) == 4) { 60073859Sml29623 navail = 4; 60083859Sml29623 } else if ((navail & 2) == 2) { 60093859Sml29623 navail = 2; 60103859Sml29623 } else { 60113859Sml29623 navail = 1; 60123859Sml29623 } 60133859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, 60146512Ssowmini "ddi_intr_get_navail(): (msi power of 2) nintrs %d, " 60156512Ssowmini "navail %d", nintrs, navail)); 60163859Sml29623 } 60173859Sml29623 60183859Sml29623 behavior = ((int_type == DDI_INTR_TYPE_FIXED) ? DDI_INTR_ALLOC_STRICT : 60196512Ssowmini DDI_INTR_ALLOC_NORMAL); 60203859Sml29623 intrp->intr_size = navail * sizeof (ddi_intr_handle_t); 60213859Sml29623 intrp->htable = kmem_alloc(intrp->intr_size, KM_SLEEP); 60223859Sml29623 ddi_status = ddi_intr_alloc(dip, intrp->htable, int_type, inum, 60236512Ssowmini navail, &nactual, behavior); 60243859Sml29623 if (ddi_status != DDI_SUCCESS || nactual == 0) { 60253859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 60266512Ssowmini " ddi_intr_alloc() failed: %d", 60276512Ssowmini ddi_status)); 60283859Sml29623 kmem_free(intrp->htable, intrp->intr_size); 60293859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 60303859Sml29623 } 60313859Sml29623 60323859Sml29623 if ((ddi_status = ddi_intr_get_pri(intrp->htable[0], 60336512Ssowmini (uint_t *)&intrp->pri)) != DDI_SUCCESS) { 60343859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 60356512Ssowmini " ddi_intr_get_pri() failed: %d", 60366512Ssowmini ddi_status)); 60373859Sml29623 /* Free already allocated interrupts */ 60383859Sml29623 for (y = 0; y < nactual; y++) { 60393859Sml29623 (void) ddi_intr_free(intrp->htable[y]); 60403859Sml29623 } 60413859Sml29623 60423859Sml29623 kmem_free(intrp->htable, intrp->intr_size); 60433859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 60443859Sml29623 } 60453859Sml29623 60463859Sml29623 nrequired = 0; 60473859Sml29623 switch (nxgep->niu_type) { 60483859Sml29623 default: 60493859Sml29623 status = nxge_ldgv_init(nxgep, &nactual, &nrequired); 60503859Sml29623 break; 60513859Sml29623 60523859Sml29623 case N2_NIU: 60533859Sml29623 status = nxge_ldgv_init_n2(nxgep, &nactual, &nrequired); 60543859Sml29623 break; 60553859Sml29623 } 60563859Sml29623 60573859Sml29623 if (status != NXGE_OK) { 60583859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 60596512Ssowmini "nxge_add_intrs_adv_typ:nxge_ldgv_init " 60606512Ssowmini "failed: 0x%x", status)); 60613859Sml29623 /* Free already allocated interrupts */ 60623859Sml29623 for (y = 0; y < nactual; y++) { 60633859Sml29623 (void) ddi_intr_free(intrp->htable[y]); 60643859Sml29623 } 60653859Sml29623 60663859Sml29623 kmem_free(intrp->htable, intrp->intr_size); 60673859Sml29623 return (status); 60683859Sml29623 } 60693859Sml29623 60703859Sml29623 ldgp = nxgep->ldgvp->ldgp; 60713859Sml29623 for (x = 0; x < nrequired; x++, ldgp++) { 60723859Sml29623 ldgp->vector = (uint8_t)x; 60733859Sml29623 ldgp->intdata = SID_DATA(ldgp->func, x); 60743859Sml29623 arg1 = ldgp->ldvp; 60753859Sml29623 arg2 = nxgep; 60763859Sml29623 if (ldgp->nldvs == 1) { 60773859Sml29623 inthandler = (uint_t *)ldgp->ldvp->ldv_intr_handler; 60783859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, 60796512Ssowmini "nxge_add_intrs_adv_type: " 60806512Ssowmini "arg1 0x%x arg2 0x%x: " 60816512Ssowmini "1-1 int handler (entry %d intdata 0x%x)\n", 60826512Ssowmini arg1, arg2, 60836512Ssowmini x, ldgp->intdata)); 60843859Sml29623 } else if (ldgp->nldvs > 1) { 60853859Sml29623 inthandler = (uint_t *)ldgp->sys_intr_handler; 60863859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, 60876512Ssowmini "nxge_add_intrs_adv_type: " 60886512Ssowmini "arg1 0x%x arg2 0x%x: " 60896512Ssowmini "nldevs %d int handler " 60906512Ssowmini "(entry %d intdata 0x%x)\n", 60916512Ssowmini arg1, arg2, 60926512Ssowmini ldgp->nldvs, x, ldgp->intdata)); 60933859Sml29623 } 60943859Sml29623 60953859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, 60966512Ssowmini "==> nxge_add_intrs_adv_type: ddi_add_intr(inum) #%d " 60976512Ssowmini "htable 0x%llx", x, intrp->htable[x])); 60983859Sml29623 60993859Sml29623 if ((ddi_status = ddi_intr_add_handler(intrp->htable[x], 61006512Ssowmini (ddi_intr_handler_t *)inthandler, arg1, arg2)) 61016512Ssowmini != DDI_SUCCESS) { 61023859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 61036512Ssowmini "==> nxge_add_intrs_adv_type: failed #%d " 61046512Ssowmini "status 0x%x", x, ddi_status)); 61053859Sml29623 for (y = 0; y < intrp->intr_added; y++) { 61063859Sml29623 (void) ddi_intr_remove_handler( 61076512Ssowmini intrp->htable[y]); 61083859Sml29623 } 61093859Sml29623 /* Free already allocated intr */ 61103859Sml29623 for (y = 0; y < nactual; y++) { 61113859Sml29623 (void) ddi_intr_free(intrp->htable[y]); 61123859Sml29623 } 61133859Sml29623 kmem_free(intrp->htable, intrp->intr_size); 61143859Sml29623 61153859Sml29623 (void) nxge_ldgv_uninit(nxgep); 61163859Sml29623 61173859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 61183859Sml29623 } 61193859Sml29623 intrp->intr_added++; 61203859Sml29623 } 61213859Sml29623 61223859Sml29623 intrp->msi_intx_cnt = nactual; 61233859Sml29623 61243859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 61256512Ssowmini "Requested: %d, Allowed: %d msi_intx_cnt %d intr_added %d", 61266512Ssowmini navail, nactual, 61276512Ssowmini intrp->msi_intx_cnt, 61286512Ssowmini intrp->intr_added)); 61293859Sml29623 61303859Sml29623 (void) ddi_intr_get_cap(intrp->htable[0], &intrp->intr_cap); 61313859Sml29623 61323859Sml29623 (void) nxge_intr_ldgv_init(nxgep); 61333859Sml29623 61343859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_add_intrs_adv_type")); 61353859Sml29623 61363859Sml29623 return (status); 61373859Sml29623 } 61383859Sml29623 61393859Sml29623 /*ARGSUSED*/ 61403859Sml29623 static nxge_status_t 61413859Sml29623 nxge_add_intrs_adv_type_fix(p_nxge_t nxgep, uint32_t int_type) 61423859Sml29623 { 61433859Sml29623 dev_info_t *dip = nxgep->dip; 61443859Sml29623 p_nxge_ldg_t ldgp; 61453859Sml29623 p_nxge_intr_t intrp; 61463859Sml29623 uint_t *inthandler; 61473859Sml29623 void *arg1, *arg2; 61483859Sml29623 int behavior; 61493859Sml29623 int nintrs, navail; 61503859Sml29623 int nactual, nrequired; 61513859Sml29623 int inum = 0; 61523859Sml29623 int x, y; 61533859Sml29623 int ddi_status = DDI_SUCCESS; 61543859Sml29623 nxge_status_t status = NXGE_OK; 61553859Sml29623 61563859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_add_intrs_adv_type_fix")); 61573859Sml29623 intrp = (p_nxge_intr_t)&nxgep->nxge_intr_type; 61583859Sml29623 intrp->start_inum = 0; 61593859Sml29623 61603859Sml29623 ddi_status = ddi_intr_get_nintrs(dip, int_type, &nintrs); 61613859Sml29623 if ((ddi_status != DDI_SUCCESS) || (nintrs == 0)) { 61623859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, 61636512Ssowmini "ddi_intr_get_nintrs() failed, status: 0x%x%, " 61646512Ssowmini "nintrs: %d", status, nintrs)); 61653859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 61663859Sml29623 } 61673859Sml29623 61683859Sml29623 ddi_status = ddi_intr_get_navail(dip, int_type, &navail); 61693859Sml29623 if ((ddi_status != DDI_SUCCESS) || (navail == 0)) { 61703859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 61716512Ssowmini "ddi_intr_get_navail() failed, status: 0x%x%, " 61726512Ssowmini "nintrs: %d", ddi_status, navail)); 61733859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 61743859Sml29623 } 61753859Sml29623 61763859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, 61776512Ssowmini "ddi_intr_get_navail() returned: nintrs %d, naavail %d", 61786512Ssowmini nintrs, navail)); 61793859Sml29623 61803859Sml29623 behavior = ((int_type == DDI_INTR_TYPE_FIXED) ? DDI_INTR_ALLOC_STRICT : 61816512Ssowmini DDI_INTR_ALLOC_NORMAL); 61823859Sml29623 intrp->intr_size = navail * sizeof (ddi_intr_handle_t); 61833859Sml29623 intrp->htable = kmem_alloc(intrp->intr_size, KM_SLEEP); 61843859Sml29623 ddi_status = ddi_intr_alloc(dip, intrp->htable, int_type, inum, 61856512Ssowmini navail, &nactual, behavior); 61863859Sml29623 if (ddi_status != DDI_SUCCESS || nactual == 0) { 61873859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 61886512Ssowmini " ddi_intr_alloc() failed: %d", 61896512Ssowmini ddi_status)); 61903859Sml29623 kmem_free(intrp->htable, intrp->intr_size); 61913859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 61923859Sml29623 } 61933859Sml29623 61943859Sml29623 if ((ddi_status = ddi_intr_get_pri(intrp->htable[0], 61956512Ssowmini (uint_t *)&intrp->pri)) != DDI_SUCCESS) { 61963859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 61976512Ssowmini " ddi_intr_get_pri() failed: %d", 61986512Ssowmini ddi_status)); 61993859Sml29623 /* Free already allocated interrupts */ 62003859Sml29623 for (y = 0; y < nactual; y++) { 62013859Sml29623 (void) ddi_intr_free(intrp->htable[y]); 62023859Sml29623 } 62033859Sml29623 62043859Sml29623 kmem_free(intrp->htable, intrp->intr_size); 62053859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 62063859Sml29623 } 62073859Sml29623 62083859Sml29623 nrequired = 0; 62093859Sml29623 switch (nxgep->niu_type) { 62103859Sml29623 default: 62113859Sml29623 status = nxge_ldgv_init(nxgep, &nactual, &nrequired); 62123859Sml29623 break; 62133859Sml29623 62143859Sml29623 case N2_NIU: 62153859Sml29623 status = nxge_ldgv_init_n2(nxgep, &nactual, &nrequired); 62163859Sml29623 break; 62173859Sml29623 } 62183859Sml29623 62193859Sml29623 if (status != NXGE_OK) { 62203859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 62216512Ssowmini "nxge_add_intrs_adv_type_fix:nxge_ldgv_init " 62226512Ssowmini "failed: 0x%x", status)); 62233859Sml29623 /* Free already allocated interrupts */ 62243859Sml29623 for (y = 0; y < nactual; y++) { 62253859Sml29623 (void) ddi_intr_free(intrp->htable[y]); 62263859Sml29623 } 62273859Sml29623 62283859Sml29623 kmem_free(intrp->htable, intrp->intr_size); 62293859Sml29623 return (status); 62303859Sml29623 } 62313859Sml29623 62323859Sml29623 ldgp = nxgep->ldgvp->ldgp; 62333859Sml29623 for (x = 0; x < nrequired; x++, ldgp++) { 62343859Sml29623 ldgp->vector = (uint8_t)x; 62353859Sml29623 if (nxgep->niu_type != N2_NIU) { 62363859Sml29623 ldgp->intdata = SID_DATA(ldgp->func, x); 62373859Sml29623 } 62383859Sml29623 62393859Sml29623 arg1 = ldgp->ldvp; 62403859Sml29623 arg2 = nxgep; 62413859Sml29623 if (ldgp->nldvs == 1) { 62423859Sml29623 inthandler = (uint_t *)ldgp->ldvp->ldv_intr_handler; 62433859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, 62446512Ssowmini "nxge_add_intrs_adv_type_fix: " 62456512Ssowmini "1-1 int handler(%d) ldg %d ldv %d " 62466512Ssowmini "arg1 $%p arg2 $%p\n", 62476512Ssowmini x, ldgp->ldg, ldgp->ldvp->ldv, 62486512Ssowmini arg1, arg2)); 62493859Sml29623 } else if (ldgp->nldvs > 1) { 62503859Sml29623 inthandler = (uint_t *)ldgp->sys_intr_handler; 62513859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, 62526512Ssowmini "nxge_add_intrs_adv_type_fix: " 62536512Ssowmini "shared ldv %d int handler(%d) ldv %d ldg %d" 62546512Ssowmini "arg1 0x%016llx arg2 0x%016llx\n", 62556512Ssowmini x, ldgp->nldvs, ldgp->ldg, ldgp->ldvp->ldv, 62566512Ssowmini arg1, arg2)); 62573859Sml29623 } 62583859Sml29623 62593859Sml29623 if ((ddi_status = ddi_intr_add_handler(intrp->htable[x], 62606512Ssowmini (ddi_intr_handler_t *)inthandler, arg1, arg2)) 62616512Ssowmini != DDI_SUCCESS) { 62623859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 62636512Ssowmini "==> nxge_add_intrs_adv_type_fix: failed #%d " 62646512Ssowmini "status 0x%x", x, ddi_status)); 62653859Sml29623 for (y = 0; y < intrp->intr_added; y++) { 62663859Sml29623 (void) ddi_intr_remove_handler( 62676512Ssowmini intrp->htable[y]); 62683859Sml29623 } 62693859Sml29623 for (y = 0; y < nactual; y++) { 62703859Sml29623 (void) ddi_intr_free(intrp->htable[y]); 62713859Sml29623 } 62723859Sml29623 /* Free already allocated intr */ 62733859Sml29623 kmem_free(intrp->htable, intrp->intr_size); 62743859Sml29623 62753859Sml29623 (void) nxge_ldgv_uninit(nxgep); 62763859Sml29623 62773859Sml29623 return (NXGE_ERROR | NXGE_DDI_FAILED); 62783859Sml29623 } 62793859Sml29623 intrp->intr_added++; 62803859Sml29623 } 62813859Sml29623 62823859Sml29623 intrp->msi_intx_cnt = nactual; 62833859Sml29623 62843859Sml29623 (void) ddi_intr_get_cap(intrp->htable[0], &intrp->intr_cap); 62853859Sml29623 62863859Sml29623 status = nxge_intr_ldgv_init(nxgep); 62873859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_add_intrs_adv_type_fix")); 62883859Sml29623 62893859Sml29623 return (status); 62903859Sml29623 } 62913859Sml29623 62923859Sml29623 static void 62933859Sml29623 nxge_remove_intrs(p_nxge_t nxgep) 62943859Sml29623 { 62953859Sml29623 int i, inum; 62963859Sml29623 p_nxge_intr_t intrp; 62973859Sml29623 62983859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_remove_intrs")); 62993859Sml29623 intrp = (p_nxge_intr_t)&nxgep->nxge_intr_type; 63003859Sml29623 if (!intrp->intr_registered) { 63013859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, 63026512Ssowmini "<== nxge_remove_intrs: interrupts not registered")); 63033859Sml29623 return; 63043859Sml29623 } 63053859Sml29623 63063859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_remove_intrs:advanced")); 63073859Sml29623 63083859Sml29623 if (intrp->intr_cap & DDI_INTR_FLAG_BLOCK) { 63093859Sml29623 (void) ddi_intr_block_disable(intrp->htable, 63106512Ssowmini intrp->intr_added); 63113859Sml29623 } else { 63123859Sml29623 for (i = 0; i < intrp->intr_added; i++) { 63133859Sml29623 (void) ddi_intr_disable(intrp->htable[i]); 63143859Sml29623 } 63153859Sml29623 } 63163859Sml29623 63173859Sml29623 for (inum = 0; inum < intrp->intr_added; inum++) { 63183859Sml29623 if (intrp->htable[inum]) { 63193859Sml29623 (void) ddi_intr_remove_handler(intrp->htable[inum]); 63203859Sml29623 } 63213859Sml29623 } 63223859Sml29623 63233859Sml29623 for (inum = 0; inum < intrp->msi_intx_cnt; inum++) { 63243859Sml29623 if (intrp->htable[inum]) { 63253859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 63266512Ssowmini "nxge_remove_intrs: ddi_intr_free inum %d " 63276512Ssowmini "msi_intx_cnt %d intr_added %d", 63286512Ssowmini inum, 63296512Ssowmini intrp->msi_intx_cnt, 63306512Ssowmini intrp->intr_added)); 63313859Sml29623 63323859Sml29623 (void) ddi_intr_free(intrp->htable[inum]); 63333859Sml29623 } 63343859Sml29623 } 63353859Sml29623 63363859Sml29623 kmem_free(intrp->htable, intrp->intr_size); 63373859Sml29623 intrp->intr_registered = B_FALSE; 63383859Sml29623 intrp->intr_enabled = B_FALSE; 63393859Sml29623 intrp->msi_intx_cnt = 0; 63403859Sml29623 intrp->intr_added = 0; 63413859Sml29623 63423859Sml29623 (void) nxge_ldgv_uninit(nxgep); 63433859Sml29623 63445013Sml29623 (void) ddi_prop_remove(DDI_DEV_T_NONE, nxgep->dip, 63455013Sml29623 "#msix-request"); 63465013Sml29623 63473859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_remove_intrs")); 63483859Sml29623 } 63493859Sml29623 63503859Sml29623 /*ARGSUSED*/ 63513859Sml29623 static void 63523859Sml29623 nxge_intrs_enable(p_nxge_t nxgep) 63533859Sml29623 { 63543859Sml29623 p_nxge_intr_t intrp; 63553859Sml29623 int i; 63563859Sml29623 int status; 63573859Sml29623 63583859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_intrs_enable")); 63593859Sml29623 63603859Sml29623 intrp = (p_nxge_intr_t)&nxgep->nxge_intr_type; 63613859Sml29623 63623859Sml29623 if (!intrp->intr_registered) { 63633859Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "<== nxge_intrs_enable: " 63646512Ssowmini "interrupts are not registered")); 63653859Sml29623 return; 63663859Sml29623 } 63673859Sml29623 63683859Sml29623 if (intrp->intr_enabled) { 63693859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, 63706512Ssowmini "<== nxge_intrs_enable: already enabled")); 63713859Sml29623 return; 63723859Sml29623 } 63733859Sml29623 63743859Sml29623 if (intrp->intr_cap & DDI_INTR_FLAG_BLOCK) { 63753859Sml29623 status = ddi_intr_block_enable(intrp->htable, 63766512Ssowmini intrp->intr_added); 63773859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_intrs_enable " 63786512Ssowmini "block enable - status 0x%x total inums #%d\n", 63796512Ssowmini status, intrp->intr_added)); 63803859Sml29623 } else { 63813859Sml29623 for (i = 0; i < intrp->intr_added; i++) { 63823859Sml29623 status = ddi_intr_enable(intrp->htable[i]); 63833859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_intrs_enable " 63846512Ssowmini "ddi_intr_enable:enable - status 0x%x " 63856512Ssowmini "total inums %d enable inum #%d\n", 63866512Ssowmini status, intrp->intr_added, i)); 63873859Sml29623 if (status == DDI_SUCCESS) { 63883859Sml29623 intrp->intr_enabled = B_TRUE; 63893859Sml29623 } 63903859Sml29623 } 63913859Sml29623 } 63923859Sml29623 63933859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_intrs_enable")); 63943859Sml29623 } 63953859Sml29623 63963859Sml29623 /*ARGSUSED*/ 63973859Sml29623 static void 63983859Sml29623 nxge_intrs_disable(p_nxge_t nxgep) 63993859Sml29623 { 64003859Sml29623 p_nxge_intr_t intrp; 64013859Sml29623 int i; 64023859Sml29623 64033859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_intrs_disable")); 64043859Sml29623 64053859Sml29623 intrp = (p_nxge_intr_t)&nxgep->nxge_intr_type; 64063859Sml29623 64073859Sml29623 if (!intrp->intr_registered) { 64083859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_intrs_disable: " 64096512Ssowmini "interrupts are not registered")); 64103859Sml29623 return; 64113859Sml29623 } 64123859Sml29623 64133859Sml29623 if (intrp->intr_cap & DDI_INTR_FLAG_BLOCK) { 64143859Sml29623 (void) ddi_intr_block_disable(intrp->htable, 64156512Ssowmini intrp->intr_added); 64163859Sml29623 } else { 64173859Sml29623 for (i = 0; i < intrp->intr_added; i++) { 64183859Sml29623 (void) ddi_intr_disable(intrp->htable[i]); 64193859Sml29623 } 64203859Sml29623 } 64213859Sml29623 64223859Sml29623 intrp->intr_enabled = B_FALSE; 64233859Sml29623 NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_intrs_disable")); 64243859Sml29623 } 64253859Sml29623 64263859Sml29623 static nxge_status_t 64273859Sml29623 nxge_mac_register(p_nxge_t nxgep) 64283859Sml29623 { 64293859Sml29623 mac_register_t *macp; 64303859Sml29623 int status; 64313859Sml29623 64323859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_mac_register")); 64333859Sml29623 64343859Sml29623 if ((macp = mac_alloc(MAC_VERSION)) == NULL) 64353859Sml29623 return (NXGE_ERROR); 64363859Sml29623 64373859Sml29623 macp->m_type_ident = MAC_PLUGIN_IDENT_ETHER; 64383859Sml29623 macp->m_driver = nxgep; 64393859Sml29623 macp->m_dip = nxgep->dip; 64403859Sml29623 macp->m_src_addr = nxgep->ouraddr.ether_addr_octet; 64413859Sml29623 macp->m_callbacks = &nxge_m_callbacks; 64423859Sml29623 macp->m_min_sdu = 0; 64436439Sml29623 nxgep->mac.default_mtu = nxgep->mac.maxframesize - 64446439Sml29623 NXGE_EHEADER_VLAN_CRC; 64456439Sml29623 macp->m_max_sdu = nxgep->mac.default_mtu; 64465895Syz147064 macp->m_margin = VLAN_TAGSZ; 64476512Ssowmini macp->m_priv_props = nxge_priv_props; 64486512Ssowmini macp->m_priv_prop_count = NXGE_MAX_PRIV_PROPS; 64498275SEric Cheng macp->m_v12n = MAC_VIRT_HIO | MAC_VIRT_LEVEL1 | MAC_VIRT_SERIALIZE; 64503859Sml29623 64516439Sml29623 NXGE_DEBUG_MSG((nxgep, MAC_CTL, 64526439Sml29623 "==> nxge_mac_register: instance %d " 64536439Sml29623 "max_sdu %d margin %d maxframe %d (header %d)", 64546439Sml29623 nxgep->instance, 64556439Sml29623 macp->m_max_sdu, macp->m_margin, 64566439Sml29623 nxgep->mac.maxframesize, 64576439Sml29623 NXGE_EHEADER_VLAN_CRC)); 64586439Sml29623 64593859Sml29623 status = mac_register(macp, &nxgep->mach); 64603859Sml29623 mac_free(macp); 64613859Sml29623 64623859Sml29623 if (status != 0) { 64633859Sml29623 cmn_err(CE_WARN, 64646512Ssowmini "!nxge_mac_register failed (status %d instance %d)", 64656512Ssowmini status, nxgep->instance); 64663859Sml29623 return (NXGE_ERROR); 64673859Sml29623 } 64683859Sml29623 64693859Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_mac_register success " 64706512Ssowmini "(instance %d)", nxgep->instance)); 64713859Sml29623 64723859Sml29623 return (NXGE_OK); 64733859Sml29623 } 64743859Sml29623 64753859Sml29623 void 64763859Sml29623 nxge_err_inject(p_nxge_t nxgep, queue_t *wq, mblk_t *mp) 64773859Sml29623 { 64783859Sml29623 ssize_t size; 64793859Sml29623 mblk_t *nmp; 64803859Sml29623 uint8_t blk_id; 64813859Sml29623 uint8_t chan; 64823859Sml29623 uint32_t err_id; 64833859Sml29623 err_inject_t *eip; 64843859Sml29623 64853859Sml29623 NXGE_DEBUG_MSG((nxgep, STR_CTL, "==> nxge_err_inject")); 64863859Sml29623 64873859Sml29623 size = 1024; 64883859Sml29623 nmp = mp->b_cont; 64893859Sml29623 eip = (err_inject_t *)nmp->b_rptr; 64903859Sml29623 blk_id = eip->blk_id; 64913859Sml29623 err_id = eip->err_id; 64923859Sml29623 chan = eip->chan; 64933859Sml29623 cmn_err(CE_NOTE, "!blk_id = 0x%x\n", blk_id); 64943859Sml29623 cmn_err(CE_NOTE, "!err_id = 0x%x\n", err_id); 64953859Sml29623 cmn_err(CE_NOTE, "!chan = 0x%x\n", chan); 64963859Sml29623 switch (blk_id) { 64973859Sml29623 case MAC_BLK_ID: 64983859Sml29623 break; 64993859Sml29623 case TXMAC_BLK_ID: 65003859Sml29623 break; 65013859Sml29623 case RXMAC_BLK_ID: 65023859Sml29623 break; 65033859Sml29623 case MIF_BLK_ID: 65043859Sml29623 break; 65053859Sml29623 case IPP_BLK_ID: 65063859Sml29623 nxge_ipp_inject_err(nxgep, err_id); 65073859Sml29623 break; 65083859Sml29623 case TXC_BLK_ID: 65093859Sml29623 nxge_txc_inject_err(nxgep, err_id); 65103859Sml29623 break; 65113859Sml29623 case TXDMA_BLK_ID: 65123859Sml29623 nxge_txdma_inject_err(nxgep, err_id, chan); 65133859Sml29623 break; 65143859Sml29623 case RXDMA_BLK_ID: 65153859Sml29623 nxge_rxdma_inject_err(nxgep, err_id, chan); 65163859Sml29623 break; 65173859Sml29623 case ZCP_BLK_ID: 65183859Sml29623 nxge_zcp_inject_err(nxgep, err_id); 65193859Sml29623 break; 65203859Sml29623 case ESPC_BLK_ID: 65213859Sml29623 break; 65223859Sml29623 case FFLP_BLK_ID: 65233859Sml29623 break; 65243859Sml29623 case PHY_BLK_ID: 65253859Sml29623 break; 65263859Sml29623 case ETHER_SERDES_BLK_ID: 65273859Sml29623 break; 65283859Sml29623 case PCIE_SERDES_BLK_ID: 65293859Sml29623 break; 65303859Sml29623 case VIR_BLK_ID: 65313859Sml29623 break; 65323859Sml29623 } 65333859Sml29623 65343859Sml29623 nmp->b_wptr = nmp->b_rptr + size; 65353859Sml29623 NXGE_DEBUG_MSG((nxgep, STR_CTL, "<== nxge_err_inject")); 65363859Sml29623 65373859Sml29623 miocack(wq, mp, (int)size, 0); 65383859Sml29623 } 65393859Sml29623 65403859Sml29623 static int 65413859Sml29623 nxge_init_common_dev(p_nxge_t nxgep) 65423859Sml29623 { 65433859Sml29623 p_nxge_hw_list_t hw_p; 65443859Sml29623 dev_info_t *p_dip; 65453859Sml29623 65463859Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, "==> nxge_init_common_device")); 65473859Sml29623 65483859Sml29623 p_dip = nxgep->p_dip; 65493859Sml29623 MUTEX_ENTER(&nxge_common_lock); 65503859Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, 65516512Ssowmini "==> nxge_init_common_dev:func # %d", 65526512Ssowmini nxgep->function_num)); 65533859Sml29623 /* 65543859Sml29623 * Loop through existing per neptune hardware list. 65553859Sml29623 */ 65563859Sml29623 for (hw_p = nxge_hw_list; hw_p; hw_p = hw_p->next) { 65573859Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, 65586512Ssowmini "==> nxge_init_common_device:func # %d " 65596512Ssowmini "hw_p $%p parent dip $%p", 65606512Ssowmini nxgep->function_num, 65616512Ssowmini hw_p, 65626512Ssowmini p_dip)); 65633859Sml29623 if (hw_p->parent_devp == p_dip) { 65643859Sml29623 nxgep->nxge_hw_p = hw_p; 65653859Sml29623 hw_p->ndevs++; 65663859Sml29623 hw_p->nxge_p[nxgep->function_num] = nxgep; 65673859Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, 65686512Ssowmini "==> nxge_init_common_device:func # %d " 65696512Ssowmini "hw_p $%p parent dip $%p " 65706512Ssowmini "ndevs %d (found)", 65716512Ssowmini nxgep->function_num, 65726512Ssowmini hw_p, 65736512Ssowmini p_dip, 65746512Ssowmini hw_p->ndevs)); 65753859Sml29623 break; 65763859Sml29623 } 65773859Sml29623 } 65783859Sml29623 65793859Sml29623 if (hw_p == NULL) { 65807801SSantwona.Behera@Sun.COM 65817801SSantwona.Behera@Sun.COM char **prop_val; 65827801SSantwona.Behera@Sun.COM uint_t prop_len; 65837801SSantwona.Behera@Sun.COM int i; 65847801SSantwona.Behera@Sun.COM 65853859Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, 65866512Ssowmini "==> nxge_init_common_device:func # %d " 65876512Ssowmini "parent dip $%p (new)", 65886512Ssowmini nxgep->function_num, 65896512Ssowmini p_dip)); 65903859Sml29623 hw_p = kmem_zalloc(sizeof (nxge_hw_list_t), KM_SLEEP); 65913859Sml29623 hw_p->parent_devp = p_dip; 65923859Sml29623 hw_p->magic = NXGE_NEPTUNE_MAGIC; 65933859Sml29623 nxgep->nxge_hw_p = hw_p; 65943859Sml29623 hw_p->ndevs++; 65953859Sml29623 hw_p->nxge_p[nxgep->function_num] = nxgep; 65963859Sml29623 hw_p->next = nxge_hw_list; 65974732Sdavemq if (nxgep->niu_type == N2_NIU) { 65984732Sdavemq hw_p->niu_type = N2_NIU; 65994732Sdavemq hw_p->platform_type = P_NEPTUNE_NIU; 66004732Sdavemq } else { 66014732Sdavemq hw_p->niu_type = NIU_TYPE_NONE; 66024977Sraghus hw_p->platform_type = P_NEPTUNE_NONE; 66034732Sdavemq } 66043859Sml29623 66053859Sml29623 MUTEX_INIT(&hw_p->nxge_cfg_lock, NULL, MUTEX_DRIVER, NULL); 66063859Sml29623 MUTEX_INIT(&hw_p->nxge_tcam_lock, NULL, MUTEX_DRIVER, NULL); 66073859Sml29623 MUTEX_INIT(&hw_p->nxge_vlan_lock, NULL, MUTEX_DRIVER, NULL); 66083859Sml29623 MUTEX_INIT(&hw_p->nxge_mdio_lock, NULL, MUTEX_DRIVER, NULL); 66093859Sml29623 66103859Sml29623 nxge_hw_list = hw_p; 66114732Sdavemq 66127801SSantwona.Behera@Sun.COM if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, nxgep->dip, 0, 66137801SSantwona.Behera@Sun.COM "compatible", &prop_val, &prop_len) == DDI_PROP_SUCCESS) { 66147801SSantwona.Behera@Sun.COM for (i = 0; i < prop_len; i++) { 66157801SSantwona.Behera@Sun.COM if ((strcmp((caddr_t)prop_val[i], 66167801SSantwona.Behera@Sun.COM NXGE_ROCK_COMPATIBLE) == 0)) { 66177801SSantwona.Behera@Sun.COM hw_p->platform_type = P_NEPTUNE_ROCK; 66187801SSantwona.Behera@Sun.COM NXGE_DEBUG_MSG((nxgep, MOD_CTL, 66197801SSantwona.Behera@Sun.COM "ROCK hw_p->platform_type %d", 66207801SSantwona.Behera@Sun.COM hw_p->platform_type)); 66217801SSantwona.Behera@Sun.COM break; 66227801SSantwona.Behera@Sun.COM } 66237801SSantwona.Behera@Sun.COM NXGE_DEBUG_MSG((nxgep, MOD_CTL, 66247801SSantwona.Behera@Sun.COM "nxge_init_common_dev: read compatible" 66257801SSantwona.Behera@Sun.COM " property[%d] val[%s]", 66267801SSantwona.Behera@Sun.COM i, (caddr_t)prop_val[i])); 66277801SSantwona.Behera@Sun.COM } 66287801SSantwona.Behera@Sun.COM } 66297801SSantwona.Behera@Sun.COM 66307801SSantwona.Behera@Sun.COM ddi_prop_free(prop_val); 66317801SSantwona.Behera@Sun.COM 66324732Sdavemq (void) nxge_scan_ports_phy(nxgep, nxge_hw_list); 66333859Sml29623 } 66343859Sml29623 66353859Sml29623 MUTEX_EXIT(&nxge_common_lock); 66364732Sdavemq 66374977Sraghus nxgep->platform_type = hw_p->platform_type; 66387801SSantwona.Behera@Sun.COM NXGE_DEBUG_MSG((nxgep, MOD_CTL, "nxgep->platform_type %d", 66397801SSantwona.Behera@Sun.COM nxgep->platform_type)); 66404732Sdavemq if (nxgep->niu_type != N2_NIU) { 66414732Sdavemq nxgep->niu_type = hw_p->niu_type; 66424732Sdavemq } 66434732Sdavemq 66443859Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, 66456512Ssowmini "==> nxge_init_common_device (nxge_hw_list) $%p", 66466512Ssowmini nxge_hw_list)); 66473859Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, "<== nxge_init_common_device")); 66483859Sml29623 66493859Sml29623 return (NXGE_OK); 66503859Sml29623 } 66513859Sml29623 66523859Sml29623 static void 66533859Sml29623 nxge_uninit_common_dev(p_nxge_t nxgep) 66543859Sml29623 { 66553859Sml29623 p_nxge_hw_list_t hw_p, h_hw_p; 66566801Sspeer p_nxge_dma_pt_cfg_t p_dma_cfgp; 66576801Sspeer p_nxge_hw_pt_cfg_t p_cfgp; 66583859Sml29623 dev_info_t *p_dip; 66593859Sml29623 66603859Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, "==> nxge_uninit_common_device")); 66613859Sml29623 if (nxgep->nxge_hw_p == NULL) { 66623859Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, 66636512Ssowmini "<== nxge_uninit_common_device (no common)")); 66643859Sml29623 return; 66653859Sml29623 } 66663859Sml29623 66673859Sml29623 MUTEX_ENTER(&nxge_common_lock); 66683859Sml29623 h_hw_p = nxge_hw_list; 66693859Sml29623 for (hw_p = nxge_hw_list; hw_p; hw_p = hw_p->next) { 66703859Sml29623 p_dip = hw_p->parent_devp; 66713859Sml29623 if (nxgep->nxge_hw_p == hw_p && 66726512Ssowmini p_dip == nxgep->p_dip && 66736512Ssowmini nxgep->nxge_hw_p->magic == NXGE_NEPTUNE_MAGIC && 66746512Ssowmini hw_p->magic == NXGE_NEPTUNE_MAGIC) { 66753859Sml29623 66763859Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, 66776512Ssowmini "==> nxge_uninit_common_device:func # %d " 66786512Ssowmini "hw_p $%p parent dip $%p " 66796512Ssowmini "ndevs %d (found)", 66806512Ssowmini nxgep->function_num, 66816512Ssowmini hw_p, 66826512Ssowmini p_dip, 66836512Ssowmini hw_p->ndevs)); 66843859Sml29623 66856801Sspeer /* 66866801Sspeer * Release the RDC table, a shared resoruce 66876801Sspeer * of the nxge hardware. The RDC table was 66886801Sspeer * assigned to this instance of nxge in 66896801Sspeer * nxge_use_cfg_dma_config(). 66906801Sspeer */ 66917587SMichael.Speer@Sun.COM if (!isLDOMguest(nxgep)) { 66927587SMichael.Speer@Sun.COM p_dma_cfgp = 66937587SMichael.Speer@Sun.COM (p_nxge_dma_pt_cfg_t)&nxgep->pt_config; 66947587SMichael.Speer@Sun.COM p_cfgp = 66957587SMichael.Speer@Sun.COM (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config; 66967587SMichael.Speer@Sun.COM (void) nxge_fzc_rdc_tbl_unbind(nxgep, 66977587SMichael.Speer@Sun.COM p_cfgp->def_mac_rxdma_grpid); 66987766SMichael.Speer@Sun.COM 66997766SMichael.Speer@Sun.COM /* Cleanup any outstanding groups. */ 67007766SMichael.Speer@Sun.COM nxge_grp_cleanup(nxgep); 67017587SMichael.Speer@Sun.COM } 67026801Sspeer 67033859Sml29623 if (hw_p->ndevs) { 67043859Sml29623 hw_p->ndevs--; 67053859Sml29623 } 67063859Sml29623 hw_p->nxge_p[nxgep->function_num] = NULL; 67073859Sml29623 if (!hw_p->ndevs) { 67083859Sml29623 MUTEX_DESTROY(&hw_p->nxge_vlan_lock); 67093859Sml29623 MUTEX_DESTROY(&hw_p->nxge_tcam_lock); 67103859Sml29623 MUTEX_DESTROY(&hw_p->nxge_cfg_lock); 67113859Sml29623 MUTEX_DESTROY(&hw_p->nxge_mdio_lock); 67123859Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, 67136512Ssowmini "==> nxge_uninit_common_device: " 67146512Ssowmini "func # %d " 67156512Ssowmini "hw_p $%p parent dip $%p " 67166512Ssowmini "ndevs %d (last)", 67176512Ssowmini nxgep->function_num, 67186512Ssowmini hw_p, 67196512Ssowmini p_dip, 67206512Ssowmini hw_p->ndevs)); 67213859Sml29623 67226495Sspeer nxge_hio_uninit(nxgep); 67236495Sspeer 67243859Sml29623 if (hw_p == nxge_hw_list) { 67253859Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, 67266512Ssowmini "==> nxge_uninit_common_device:" 67276512Ssowmini "remove head func # %d " 67286512Ssowmini "hw_p $%p parent dip $%p " 67296512Ssowmini "ndevs %d (head)", 67306512Ssowmini nxgep->function_num, 67316512Ssowmini hw_p, 67326512Ssowmini p_dip, 67336512Ssowmini hw_p->ndevs)); 67343859Sml29623 nxge_hw_list = hw_p->next; 67353859Sml29623 } else { 67363859Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, 67376512Ssowmini "==> nxge_uninit_common_device:" 67386512Ssowmini "remove middle func # %d " 67396512Ssowmini "hw_p $%p parent dip $%p " 67406512Ssowmini "ndevs %d (middle)", 67416512Ssowmini nxgep->function_num, 67426512Ssowmini hw_p, 67436512Ssowmini p_dip, 67446512Ssowmini hw_p->ndevs)); 67453859Sml29623 h_hw_p->next = hw_p->next; 67463859Sml29623 } 67473859Sml29623 67486495Sspeer nxgep->nxge_hw_p = NULL; 67493859Sml29623 KMEM_FREE(hw_p, sizeof (nxge_hw_list_t)); 67503859Sml29623 } 67513859Sml29623 break; 67523859Sml29623 } else { 67533859Sml29623 h_hw_p = hw_p; 67543859Sml29623 } 67553859Sml29623 } 67563859Sml29623 67573859Sml29623 MUTEX_EXIT(&nxge_common_lock); 67583859Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, 67596512Ssowmini "==> nxge_uninit_common_device (nxge_hw_list) $%p", 67606512Ssowmini nxge_hw_list)); 67613859Sml29623 67623859Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, "<= nxge_uninit_common_device")); 67633859Sml29623 } 67644732Sdavemq 67654732Sdavemq /* 67664977Sraghus * Determines the number of ports from the niu_type or the platform type. 67674732Sdavemq * Returns the number of ports, or returns zero on failure. 67684732Sdavemq */ 67694732Sdavemq 67704732Sdavemq int 67714977Sraghus nxge_get_nports(p_nxge_t nxgep) 67724732Sdavemq { 67734732Sdavemq int nports = 0; 67744732Sdavemq 67754977Sraghus switch (nxgep->niu_type) { 67764732Sdavemq case N2_NIU: 67774732Sdavemq case NEPTUNE_2_10GF: 67784732Sdavemq nports = 2; 67794732Sdavemq break; 67804732Sdavemq case NEPTUNE_4_1GC: 67814732Sdavemq case NEPTUNE_2_10GF_2_1GC: 67824732Sdavemq case NEPTUNE_1_10GF_3_1GC: 67834732Sdavemq case NEPTUNE_1_1GC_1_10GF_2_1GC: 67846261Sjoycey case NEPTUNE_2_10GF_2_1GRF: 67854732Sdavemq nports = 4; 67864732Sdavemq break; 67874732Sdavemq default: 67884977Sraghus switch (nxgep->platform_type) { 67894977Sraghus case P_NEPTUNE_NIU: 67904977Sraghus case P_NEPTUNE_ATLAS_2PORT: 67914977Sraghus nports = 2; 67924977Sraghus break; 67934977Sraghus case P_NEPTUNE_ATLAS_4PORT: 67944977Sraghus case P_NEPTUNE_MARAMBA_P0: 67954977Sraghus case P_NEPTUNE_MARAMBA_P1: 67967801SSantwona.Behera@Sun.COM case P_NEPTUNE_ROCK: 67975196Ssbehera case P_NEPTUNE_ALONSO: 67984977Sraghus nports = 4; 67994977Sraghus break; 68004977Sraghus default: 68014977Sraghus break; 68024977Sraghus } 68034732Sdavemq break; 68044732Sdavemq } 68054732Sdavemq 68064732Sdavemq return (nports); 68074732Sdavemq } 68085013Sml29623 68095013Sml29623 /* 68105013Sml29623 * The following two functions are to support 68115013Sml29623 * PSARC/2007/453 MSI-X interrupt limit override. 68125013Sml29623 */ 68135013Sml29623 static int 68145013Sml29623 nxge_create_msi_property(p_nxge_t nxgep) 68155013Sml29623 { 68165013Sml29623 int nmsi; 68175013Sml29623 extern int ncpus; 68185013Sml29623 68195013Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, "==>nxge_create_msi_property")); 68205013Sml29623 68215013Sml29623 switch (nxgep->mac.portmode) { 68225013Sml29623 case PORT_10G_COPPER: 68235013Sml29623 case PORT_10G_FIBER: 68246835Syc148097 case PORT_10G_TN1010: 68255013Sml29623 (void) ddi_prop_create(DDI_DEV_T_NONE, nxgep->dip, 68265013Sml29623 DDI_PROP_CANSLEEP, "#msix-request", NULL, 0); 68275013Sml29623 /* 68285013Sml29623 * The maximum MSI-X requested will be 8. 68298455Stc99174@train * If the # of CPUs is less than 8, we will request 68308455Stc99174@train * # MSI-X based on the # of CPUs (default). 68315013Sml29623 */ 68328455Stc99174@train NXGE_DEBUG_MSG((nxgep, MOD_CTL, 68338455Stc99174@train "==>nxge_create_msi_property (10G): nxge_msix_10g_intrs %d", 68348455Stc99174@train nxge_msix_10g_intrs)); 68358455Stc99174@train if ((nxge_msix_10g_intrs == 0) || 68368455Stc99174@train (nxge_msix_10g_intrs > NXGE_MSIX_MAX_ALLOWED)) { 68375013Sml29623 nmsi = NXGE_MSIX_REQUEST_10G; 68388455Stc99174@train NXGE_DEBUG_MSG((nxgep, MOD_CTL, 68398455Stc99174@train "==>nxge_create_msi_property (10G): reset to 8")); 68405013Sml29623 } else { 68418455Stc99174@train nmsi = nxge_msix_10g_intrs; 68428455Stc99174@train } 68438455Stc99174@train 68448455Stc99174@train /* 68458455Stc99174@train * If # of interrupts requested is 8 (default), 68468455Stc99174@train * the checking of the number of cpus will be 68478455Stc99174@train * be maintained. 68488455Stc99174@train */ 68498455Stc99174@train if ((nmsi == NXGE_MSIX_REQUEST_10G) && 68508455Stc99174@train (ncpus < nmsi)) { 68518455Stc99174@train NXGE_DEBUG_MSG((nxgep, MOD_CTL, 68528455Stc99174@train "==>nxge_create_msi_property (10G): reset to 8")); 68535013Sml29623 nmsi = ncpus; 68545013Sml29623 } 68555013Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, 68565013Sml29623 "==>nxge_create_msi_property(10G): exists 0x%x (nmsi %d)", 68575013Sml29623 ddi_prop_exists(DDI_DEV_T_NONE, nxgep->dip, 68585013Sml29623 DDI_PROP_CANSLEEP, "#msix-request"), nmsi)); 68595013Sml29623 break; 68605013Sml29623 68615013Sml29623 default: 68628455Stc99174@train (void) ddi_prop_create(DDI_DEV_T_NONE, nxgep->dip, 68638455Stc99174@train DDI_PROP_CANSLEEP, "#msix-request", NULL, 0); 68648455Stc99174@train NXGE_DEBUG_MSG((nxgep, MOD_CTL, 68658455Stc99174@train "==>nxge_create_msi_property (1G): nxge_msix_1g_intrs %d", 68668455Stc99174@train nxge_msix_1g_intrs)); 68678455Stc99174@train if ((nxge_msix_1g_intrs == 0) || 68688455Stc99174@train (nxge_msix_1g_intrs > NXGE_MSIX_MAX_ALLOWED)) { 68698455Stc99174@train nmsi = NXGE_MSIX_REQUEST_1G; 68708455Stc99174@train NXGE_DEBUG_MSG((nxgep, MOD_CTL, 68718455Stc99174@train "==>nxge_create_msi_property (1G): reset to 2")); 68728455Stc99174@train } else { 68738455Stc99174@train nmsi = nxge_msix_1g_intrs; 68748455Stc99174@train } 68755013Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, 68765013Sml29623 "==>nxge_create_msi_property(1G): exists 0x%x (nmsi %d)", 68775013Sml29623 ddi_prop_exists(DDI_DEV_T_NONE, nxgep->dip, 68785013Sml29623 DDI_PROP_CANSLEEP, "#msix-request"), nmsi)); 68795013Sml29623 break; 68805013Sml29623 } 68815013Sml29623 68825013Sml29623 NXGE_DEBUG_MSG((nxgep, MOD_CTL, "<==nxge_create_msi_property")); 68835013Sml29623 return (nmsi); 68845013Sml29623 } 68856512Ssowmini 68866512Ssowmini /* ARGSUSED */ 68876512Ssowmini static int 68886512Ssowmini nxge_get_def_val(nxge_t *nxgep, mac_prop_id_t pr_num, uint_t pr_valsize, 68896512Ssowmini void *pr_val) 68906512Ssowmini { 68916512Ssowmini int err = 0; 68926512Ssowmini link_flowctrl_t fl; 68936512Ssowmini 68946512Ssowmini switch (pr_num) { 68956789Sam223141 case MAC_PROP_AUTONEG: 68966512Ssowmini *(uint8_t *)pr_val = 1; 68976512Ssowmini break; 68986789Sam223141 case MAC_PROP_FLOWCTRL: 68996512Ssowmini if (pr_valsize < sizeof (link_flowctrl_t)) 69006512Ssowmini return (EINVAL); 69016512Ssowmini fl = LINK_FLOWCTRL_RX; 69026512Ssowmini bcopy(&fl, pr_val, sizeof (fl)); 69036512Ssowmini break; 69046789Sam223141 case MAC_PROP_ADV_1000FDX_CAP: 69056789Sam223141 case MAC_PROP_EN_1000FDX_CAP: 69066512Ssowmini *(uint8_t *)pr_val = 1; 69076512Ssowmini break; 69086789Sam223141 case MAC_PROP_ADV_100FDX_CAP: 69096789Sam223141 case MAC_PROP_EN_100FDX_CAP: 69106512Ssowmini *(uint8_t *)pr_val = 1; 69116512Ssowmini break; 69126512Ssowmini default: 69136512Ssowmini err = ENOTSUP; 69146512Ssowmini break; 69156512Ssowmini } 69166512Ssowmini return (err); 69176512Ssowmini } 69186705Sml29623 69196705Sml29623 69206705Sml29623 /* 69216705Sml29623 * The following is a software around for the Neptune hardware's 69226705Sml29623 * interrupt bugs; The Neptune hardware may generate spurious interrupts when 69236705Sml29623 * an interrupr handler is removed. 69246705Sml29623 */ 69256705Sml29623 #define NXGE_PCI_PORT_LOGIC_OFFSET 0x98 69266705Sml29623 #define NXGE_PIM_RESET (1ULL << 29) 69276705Sml29623 #define NXGE_GLU_RESET (1ULL << 30) 69286705Sml29623 #define NXGE_NIU_RESET (1ULL << 31) 69296705Sml29623 #define NXGE_PCI_RESET_ALL (NXGE_PIM_RESET | \ 69306705Sml29623 NXGE_GLU_RESET | \ 69316705Sml29623 NXGE_NIU_RESET) 69326705Sml29623 69336705Sml29623 #define NXGE_WAIT_QUITE_TIME 200000 69346705Sml29623 #define NXGE_WAIT_QUITE_RETRY 40 69356705Sml29623 #define NXGE_PCI_RESET_WAIT 1000000 /* one second */ 69366705Sml29623 69376705Sml29623 static void 69386705Sml29623 nxge_niu_peu_reset(p_nxge_t nxgep) 69396705Sml29623 { 69406705Sml29623 uint32_t rvalue; 69416705Sml29623 p_nxge_hw_list_t hw_p; 69426705Sml29623 p_nxge_t fnxgep; 69436705Sml29623 int i, j; 69446705Sml29623 69456705Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_ERR_CTL, "==> nxge_niu_peu_reset")); 69466705Sml29623 if ((hw_p = nxgep->nxge_hw_p) == NULL) { 69476705Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 69486705Sml29623 "==> nxge_niu_peu_reset: NULL hardware pointer")); 69496705Sml29623 return; 69506705Sml29623 } 69516705Sml29623 69526705Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_ERR_CTL, 69536705Sml29623 "==> nxge_niu_peu_reset: flags 0x%x link timer id %d timer id %d", 69546705Sml29623 hw_p->flags, nxgep->nxge_link_poll_timerid, 69556705Sml29623 nxgep->nxge_timerid)); 69566705Sml29623 69576705Sml29623 MUTEX_ENTER(&hw_p->nxge_cfg_lock); 69586705Sml29623 /* 69596705Sml29623 * Make sure other instances from the same hardware 69606705Sml29623 * stop sending PIO and in quiescent state. 69616705Sml29623 */ 69626705Sml29623 for (i = 0; i < NXGE_MAX_PORTS; i++) { 69636705Sml29623 fnxgep = hw_p->nxge_p[i]; 69646705Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_ERR_CTL, 69656705Sml29623 "==> nxge_niu_peu_reset: checking entry %d " 69666705Sml29623 "nxgep $%p", i, fnxgep)); 69676705Sml29623 #ifdef NXGE_DEBUG 69686705Sml29623 if (fnxgep) { 69696705Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_ERR_CTL, 69706705Sml29623 "==> nxge_niu_peu_reset: entry %d (function %d) " 69716705Sml29623 "link timer id %d hw timer id %d", 69726705Sml29623 i, fnxgep->function_num, 69736705Sml29623 fnxgep->nxge_link_poll_timerid, 69746705Sml29623 fnxgep->nxge_timerid)); 69756705Sml29623 } 69766705Sml29623 #endif 69776705Sml29623 if (fnxgep && fnxgep != nxgep && 69786705Sml29623 (fnxgep->nxge_timerid || fnxgep->nxge_link_poll_timerid)) { 69796705Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_ERR_CTL, 69806705Sml29623 "==> nxge_niu_peu_reset: checking $%p " 69816705Sml29623 "(function %d) timer ids", 69826705Sml29623 fnxgep, fnxgep->function_num)); 69836705Sml29623 for (j = 0; j < NXGE_WAIT_QUITE_RETRY; j++) { 69846705Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_ERR_CTL, 69856705Sml29623 "==> nxge_niu_peu_reset: waiting")); 69866705Sml29623 NXGE_DELAY(NXGE_WAIT_QUITE_TIME); 69876705Sml29623 if (!fnxgep->nxge_timerid && 69886705Sml29623 !fnxgep->nxge_link_poll_timerid) { 69896705Sml29623 break; 69906705Sml29623 } 69916705Sml29623 } 69926705Sml29623 NXGE_DELAY(NXGE_WAIT_QUITE_TIME); 69936705Sml29623 if (fnxgep->nxge_timerid || 69946705Sml29623 fnxgep->nxge_link_poll_timerid) { 69956705Sml29623 MUTEX_EXIT(&hw_p->nxge_cfg_lock); 69966705Sml29623 NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, 69976705Sml29623 "<== nxge_niu_peu_reset: cannot reset " 69986705Sml29623 "hardware (devices are still in use)")); 69996705Sml29623 return; 70006705Sml29623 } 70016705Sml29623 } 70026705Sml29623 } 70036705Sml29623 70046705Sml29623 if ((hw_p->flags & COMMON_RESET_NIU_PCI) != COMMON_RESET_NIU_PCI) { 70056705Sml29623 hw_p->flags |= COMMON_RESET_NIU_PCI; 70066705Sml29623 rvalue = pci_config_get32(nxgep->dev_regs->nxge_pciregh, 70076705Sml29623 NXGE_PCI_PORT_LOGIC_OFFSET); 70086705Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_ERR_CTL, 70096705Sml29623 "nxge_niu_peu_reset: read offset 0x%x (%d) " 70106705Sml29623 "(data 0x%x)", 70116705Sml29623 NXGE_PCI_PORT_LOGIC_OFFSET, 70126705Sml29623 NXGE_PCI_PORT_LOGIC_OFFSET, 70136705Sml29623 rvalue)); 70146705Sml29623 70156705Sml29623 rvalue |= NXGE_PCI_RESET_ALL; 70166705Sml29623 pci_config_put32(nxgep->dev_regs->nxge_pciregh, 70176705Sml29623 NXGE_PCI_PORT_LOGIC_OFFSET, rvalue); 70186705Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_ERR_CTL, 70196705Sml29623 "nxge_niu_peu_reset: RESETTING NIU: write NIU reset 0x%x", 70206705Sml29623 rvalue)); 70216705Sml29623 70226705Sml29623 NXGE_DELAY(NXGE_PCI_RESET_WAIT); 70236705Sml29623 } 70246705Sml29623 70256705Sml29623 MUTEX_EXIT(&hw_p->nxge_cfg_lock); 70266705Sml29623 NXGE_DEBUG_MSG((nxgep, NXGE_ERR_CTL, "<== nxge_niu_peu_reset")); 70276705Sml29623 } 70287126Sml29623 70297126Sml29623 static void 70307126Sml29623 nxge_set_pci_replay_timeout(p_nxge_t nxgep) 70317126Sml29623 { 70328275SEric Cheng p_dev_regs_t dev_regs; 70337126Sml29623 uint32_t value; 70347126Sml29623 70357126Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_set_pci_replay_timeout")); 70367126Sml29623 70377126Sml29623 if (!nxge_set_replay_timer) { 70387126Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 70397126Sml29623 "==> nxge_set_pci_replay_timeout: will not change " 70407126Sml29623 "the timeout")); 70417126Sml29623 return; 70427126Sml29623 } 70437126Sml29623 70447126Sml29623 dev_regs = nxgep->dev_regs; 70457126Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 70467126Sml29623 "==> nxge_set_pci_replay_timeout: dev_regs 0x%p pcireg 0x%p", 70477126Sml29623 dev_regs, dev_regs->nxge_pciregh)); 70487126Sml29623 70497126Sml29623 if (dev_regs == NULL || (dev_regs->nxge_pciregh == NULL)) { 70507145Syc148097 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 70517126Sml29623 "==> nxge_set_pci_replay_timeout: NULL dev_regs $%p or " 70527126Sml29623 "no PCI handle", 70537126Sml29623 dev_regs)); 70547126Sml29623 return; 70557126Sml29623 } 70567126Sml29623 value = (pci_config_get32(dev_regs->nxge_pciregh, 70577126Sml29623 PCI_REPLAY_TIMEOUT_CFG_OFFSET) | 70587126Sml29623 (nxge_replay_timeout << PCI_REPLAY_TIMEOUT_SHIFT)); 70597126Sml29623 70607126Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 70617126Sml29623 "nxge_set_pci_replay_timeout: replay timeout value before set 0x%x " 70627126Sml29623 "(timeout value to set 0x%x at offset 0x%x) value 0x%x", 70637126Sml29623 pci_config_get32(dev_regs->nxge_pciregh, 70647126Sml29623 PCI_REPLAY_TIMEOUT_CFG_OFFSET), nxge_replay_timeout, 70657126Sml29623 PCI_REPLAY_TIMEOUT_CFG_OFFSET, value)); 70667126Sml29623 70677126Sml29623 pci_config_put32(dev_regs->nxge_pciregh, PCI_REPLAY_TIMEOUT_CFG_OFFSET, 70687126Sml29623 value); 70697126Sml29623 70707126Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, 70717126Sml29623 "nxge_set_pci_replay_timeout: replay timeout value after set 0x%x", 70727126Sml29623 pci_config_get32(dev_regs->nxge_pciregh, 70737126Sml29623 PCI_REPLAY_TIMEOUT_CFG_OFFSET))); 70747126Sml29623 70757126Sml29623 NXGE_DEBUG_MSG((nxgep, DDI_CTL, "<== nxge_set_pci_replay_timeout")); 70767126Sml29623 } 70777656SSherry.Moore@Sun.COM 70787656SSherry.Moore@Sun.COM /* 70797656SSherry.Moore@Sun.COM * quiesce(9E) entry point. 70807656SSherry.Moore@Sun.COM * 70817656SSherry.Moore@Sun.COM * This function is called when the system is single-threaded at high 70827656SSherry.Moore@Sun.COM * PIL with preemption disabled. Therefore, this function must not be 70837656SSherry.Moore@Sun.COM * blocked. 70847656SSherry.Moore@Sun.COM * 70857656SSherry.Moore@Sun.COM * This function returns DDI_SUCCESS on success, or DDI_FAILURE on failure. 70867656SSherry.Moore@Sun.COM * DDI_FAILURE indicates an error condition and should almost never happen. 70877656SSherry.Moore@Sun.COM */ 70887656SSherry.Moore@Sun.COM static int 70897656SSherry.Moore@Sun.COM nxge_quiesce(dev_info_t *dip) 70907656SSherry.Moore@Sun.COM { 70917656SSherry.Moore@Sun.COM int instance = ddi_get_instance(dip); 70927656SSherry.Moore@Sun.COM p_nxge_t nxgep = (p_nxge_t)ddi_get_soft_state(nxge_list, instance); 70937656SSherry.Moore@Sun.COM 70947656SSherry.Moore@Sun.COM if (nxgep == NULL) 70957656SSherry.Moore@Sun.COM return (DDI_FAILURE); 70967656SSherry.Moore@Sun.COM 70977656SSherry.Moore@Sun.COM /* Turn off debugging */ 70987656SSherry.Moore@Sun.COM nxge_debug_level = NO_DEBUG; 70997656SSherry.Moore@Sun.COM nxgep->nxge_debug_level = NO_DEBUG; 71007656SSherry.Moore@Sun.COM npi_debug_level = NO_DEBUG; 71017656SSherry.Moore@Sun.COM 71027656SSherry.Moore@Sun.COM /* 71037656SSherry.Moore@Sun.COM * Stop link monitor only when linkchkmod is interrupt based 71047656SSherry.Moore@Sun.COM */ 71057656SSherry.Moore@Sun.COM if (nxgep->mac.linkchkmode == LINKCHK_INTR) { 71067656SSherry.Moore@Sun.COM (void) nxge_link_monitor(nxgep, LINK_MONITOR_STOP); 71077656SSherry.Moore@Sun.COM } 71087656SSherry.Moore@Sun.COM 71097656SSherry.Moore@Sun.COM (void) nxge_intr_hw_disable(nxgep); 71107656SSherry.Moore@Sun.COM 71117656SSherry.Moore@Sun.COM /* 71127656SSherry.Moore@Sun.COM * Reset the receive MAC side. 71137656SSherry.Moore@Sun.COM */ 71147656SSherry.Moore@Sun.COM (void) nxge_rx_mac_disable(nxgep); 71157656SSherry.Moore@Sun.COM 71167656SSherry.Moore@Sun.COM /* Disable and soft reset the IPP */ 71177656SSherry.Moore@Sun.COM if (!isLDOMguest(nxgep)) 71187656SSherry.Moore@Sun.COM (void) nxge_ipp_disable(nxgep); 71197656SSherry.Moore@Sun.COM 71207656SSherry.Moore@Sun.COM /* 71217656SSherry.Moore@Sun.COM * Reset the transmit/receive DMA side. 71227656SSherry.Moore@Sun.COM */ 71237656SSherry.Moore@Sun.COM (void) nxge_txdma_hw_mode(nxgep, NXGE_DMA_STOP); 71247656SSherry.Moore@Sun.COM (void) nxge_rxdma_hw_mode(nxgep, NXGE_DMA_STOP); 71257656SSherry.Moore@Sun.COM 71267656SSherry.Moore@Sun.COM /* 71277656SSherry.Moore@Sun.COM * Reset the transmit MAC side. 71287656SSherry.Moore@Sun.COM */ 71297656SSherry.Moore@Sun.COM (void) nxge_tx_mac_disable(nxgep); 71307656SSherry.Moore@Sun.COM 71317656SSherry.Moore@Sun.COM return (DDI_SUCCESS); 71327656SSherry.Moore@Sun.COM } 7133