49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * Copyright (c) 2008-2016 Solarflare Communications Inc.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * All rights reserved.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * Redistribution and use in source and binary forms, with or without
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * modification, are permitted provided that the following conditions are met:
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * 1. Redistributions of source code must retain the above copyright notice,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * this list of conditions and the following disclaimer.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * 2. Redistributions in binary form must reproduce the above copyright notice,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * this list of conditions and the following disclaimer in the documentation
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * and/or other materials provided with the distribution.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * The views and conclusions contained in the software and documentation are
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * those of the authors and should not be interpreted as representing official
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * policies, either expressed or implied, of the FreeBSD Project.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore/* Receive queue TRIM default polling interval (in microseconds) */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore/* Broadcast address */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amoreuint8_t sfxge_brdcst[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * By default modinfo will display lines truncated to 80 characters and so just
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * show 32 characters of our sfxge_ident string.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amoreconst char sfxge_ident[] = "Solarflare 10Gb/40Gb Ethernet";
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amoreconst char sfxge_version[] = SFXGE_VERSION_STRING;
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore const efx_nic_cfg_t *encp = efx_nic_cfg_get(sp->s_enp);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore (void) snprintf(sp->s_cfg_kstat.buf.sck_mac, 64,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore "%02X:%02X:%02X:%02X:%02X:%02X",
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore encp->enc_mac_addr[0], encp->enc_mac_addr[1],
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore encp->enc_mac_addr[2], encp->enc_mac_addr[3],
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore encp->enc_mac_addr[4], encp->enc_mac_addr[5]);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Allocate the object */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore mutex_init(&(sp->s_state_lock), NULL, MUTEX_DRIVER, NULL);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Get property values */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore sp->s_mtu = ddi_prop_get_int(DDI_DEV_T_ANY, sp->s_dip,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore sp->s_action_on_hw_err = ddi_prop_get_int(DDI_DEV_T_ANY, sp->s_dip,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore DDI_PROP_DONTPASS, "action_on_hw_err", SFXGE_RECOVER);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore rxq_size = ddi_prop_get_int(DDI_DEV_T_ANY, sp->s_dip,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore DDI_PROP_DONTPASS, "rxq_size", SFXGE_DEFAULT_RXQ_SIZE);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore rxq_size = min(rxq_size, EFX_RXQ_MAXNDESCS);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore sp->s_rxq_size = (uint16_t)max(rxq_size, EFX_RXQ_MINNDESCS);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Configure polling interval for queue refill/trim */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore rxq_poll_usec = ddi_prop_get_int(DDI_DEV_T_ANY, sp->s_dip,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore DDI_PROP_DONTPASS, "rxq_poll_usec", SFXGE_RX_QPOLL_USEC);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore sp->s_mcdi_logging = ddi_prop_get_int(DDI_DEV_T_ANY, sp->s_dip,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Create a taskq */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore sp->s_tqp = ddi_taskq_create(dip, "tq", 1, TASKQ_DEFAULTPRI, 0);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Check and initialize PCI configuration space */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Map the device registers */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Create the NIC object */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore mutex_init(&(sp->s_nic_lock), NULL, MUTEX_DRIVER, NULL);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((rc = efx_nic_create(sp->s_family, (efsys_identifier_t *)sp,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore &(sp->s_bar), &(sp->s_nic_lock), &enp)) != 0)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Initialize MCDI to talk to the Microcontroller */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Probe the NIC and build the configuration data area */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore sfxge_pcie_check_link(sp, 8, 3); /* PCI 8x Gen3 */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore sfxge_pcie_check_link(sp, 8, 2); /* PCI 8x Gen2 */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore mutex_init(&(sp->s_tx_flush_lock), NULL, MUTEX_DRIVER,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore cv_init(&(sp->s_tx_flush_kv), NULL, CV_DRIVER, NULL);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Clear property values */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Free the soft state */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amoresfxge_start_locked(sfxge_t *sp, boolean_t restart)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Start a new epoch (allow fresh MCDI requests to succeed) */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((rc = sfxge_mac_start(sp, restart)) != 0)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Notify any change of MTU */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Stop event processing - must be after rx_stop see sfxge_rx_qpoll() */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore sfxge_intr_stop(sp); /* cope with late flush/soft events until here */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* logging on entry is in sfxge_restart_dispatch */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* inform the OS that the link is down - may trigger IPMP failover */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if (sp->s_hw_err && sp->s_action_on_hw_err != SFXGE_INVISIBLE) {
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Stop processing */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if (sp->s_hw_err && sp->s_action_on_hw_err == SFXGE_LEAVE_DEAD) {
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore "NIC error - interface is"
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore " being left permanently DOWN per driver config");
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore (void) atomic_swap_32(&(sp->s_nested_restarts), 0);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Start processing */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((rc = sfxge_start_locked(sp, B_TRUE)) != 0)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore (void) atomic_swap_32(&(sp->s_nested_restarts), 0);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore dev_err(sp->s_dip, CE_WARN, SFXGE_CMN_ERR "NIC restart complete");
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore SFXGE_CMN_ERR "FATAL ERROR: NIC restart failed rc=%d", rc);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore (void) atomic_swap_32(&(sp->s_nested_restarts), 0);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amoresfxge_restart_dispatch(sfxge_t *sp, uint_t cflags, sfxge_hw_err_t hw_err,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if (atomic_inc_32_nv(&(sp->s_nested_restarts)) > 1) {
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* A restart is currently in progress */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore DTRACE_PROBE2(sfxge_restart_dispatch, sfxge_hw_err_t, hw_err, char *,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore dev_err(sp->s_dip, CE_WARN, SFXGE_CMN_ERR "NIC restart due to %s:%d",
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* If cflags == DDI_SLEEP then guaranteed to succeed */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore return (ddi_taskq_dispatch(sp->s_tqp, _sfxge_restart, sp, cflags));
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * In SFC bug 19834 it was noted that a mblk passed up to STREAMS
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * could be reused for transmit and sit in the sfxge_tx_packet_cache.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * This call to empty the TX deferred packet list may result in
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * rx_loaned reducing.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore while (--index >= 0) {
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Need to wait for desballoc free_func callback */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore ASSERT3U(sp->s_state, ==, SFXGE_INITIALIZED);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Destroy the NIC object */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Unmap the device registers */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Tear down PCI configuration space */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Destroy the taskq */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Clear property values */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Free the soft state */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amoresfxge_ioctl(sfxge_t *sp, queue_t *wq, mblk_t *mp)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * single concurrent IOCTL
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * serialized from sfxge_create, _destroy, _(re)start, _stop
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* if in multiple fragments pull it up to one linear buffer */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((rc = sfxge_nvram_ioctl(sp, snip)) != 0)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore sfxge_mcdi_ioc_t *smip = (sfxge_mcdi_ioc_t *)mp->b_cont->b_rptr;
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((rc = sfxge_mcdi2_ioctl(sp, smip)) != 0)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* sp->s_state_lock held */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore (void) sfxge_restart_dispatch(sp, DDI_SLEEP, SFXGE_HW_OK,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore "NIC_RESET_IOC", 0);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore sfxge_vpd_ioc_t *svip = (sfxge_vpd_ioc_t *)mp->b_cont->b_rptr;
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * Wait for any tasks that may be accessing GLD functions
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * This may end up waiting for multiple nic_resets
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * as it needs to be outside of s_state_lock for sfxge_restart()
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* The entire structure is the acknowledgement */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* no data returned */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore ASSERT3U(sp->s_state, ==, SFXGE_INITIALIZED);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore ASSERT3U(sp->s_state, ==, SFXGE_REGISTERED);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Wait for any tasks that may be accessing GLD functions */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore_sfxge_vpd_kstat_init(sfxge_t *sp, caddr_t vpd, size_t size, efx_vpd_tag_t tag,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore sfxge_vpd_kstat_t *svkp = &(sp->s_vpd_kstat);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore evvp->evv_keyword = EFX_VPD_KEYWORD(keyword[0], keyword[1]);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if (efx_vpd_get(enp, vpd, size, evvp) != 0) {
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore bcopy(unknown, evvp->evv_value, evvp->evv_length);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore kstat_named_init(knp, (char *)keyword, KSTAT_DATA_STRING);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore kstat_named_setstr(knp, (char *)evvp->evv_value);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore svkp->svk_ksp->ks_data_size += sizeof (*evvp);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore sfxge_vpd_kstat_t *svkp = &(sp->s_vpd_kstat);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore (void) snprintf(name, MAXNAMELEN - 1, "%s_vpd", ddi_driver_name(dip));
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Get a copy of the VPD space */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((vpd = kmem_zalloc(size, KM_NOSLEEP)) == NULL) {
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((svkp->svk_vv = kmem_zalloc(sizeof (efx_vpd_value_t) *
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((rc = efx_vpd_read(enp, vpd, size)) != 0)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((ksp = kstat_create((char *)ddi_driver_name(dip),
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore ddi_get_instance(dip), name, "vpd", KSTAT_TYPE_NAMED, SFXGE_VPD_MAX,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore _sfxge_vpd_kstat_init(sp, vpd, size, EFX_VPD_ID, "ID", SFXGE_VPD_ID);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore _sfxge_vpd_kstat_init(sp, vpd, size, EFX_VPD_RO, "PN", SFXGE_VPD_PN);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore _sfxge_vpd_kstat_init(sp, vpd, size, EFX_VPD_RO, "SN", SFXGE_VPD_SN);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore _sfxge_vpd_kstat_init(sp, vpd, size, EFX_VPD_RO, "EC", SFXGE_VPD_EC);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore _sfxge_vpd_kstat_init(sp, vpd, size, EFX_VPD_RO, "MN", SFXGE_VPD_MN);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore _sfxge_vpd_kstat_init(sp, vpd, size, EFX_VPD_RO, "VD", SFXGE_VPD_VD);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore _sfxge_vpd_kstat_init(sp, vpd, size, EFX_VPD_RO, "VE", SFXGE_VPD_VE);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore kmem_free(svkp->svk_vv, sizeof (efx_vpd_value_t) * SFXGE_VPD_MAX);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore sfxge_vpd_kstat_t *svkp = &(sp->s_vpd_kstat);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* NOTE: VPD support is optional, so kstats might not be registered */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Create the set */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore (void) snprintf(name, MAXNAMELEN - 1, "%s_cfg", ddi_driver_name(dip));
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((ksp = kstat_create((char *)ddi_driver_name(dip),
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore ddi_get_instance(dip), name, "cfg", KSTAT_TYPE_NAMED,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore sizeof (sckp->kstat) / sizeof (kstat_named_t),
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore kstat_named_init(&(sckp->kstat.sck_mac), "mac", KSTAT_DATA_STRING);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore kstat_named_setstr(&(sckp->kstat.sck_mac), sckp->buf.sck_mac);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore ksp->ks_data_size += sizeof (sckp->buf.sck_mac);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore kstat_named_init(&(sckp->kstat.sck_version), "version",
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore kstat_named_setstr(&(sckp->kstat.sck_version), sfxge_version);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore ksp->ks_data_size += sizeof (sfxge_version);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore bzero(&(sp->s_cfg_kstat), sizeof (sfxge_cfg_kstat_t));
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Start processing */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amoresfxge_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((sp = ddi_get_driver_private(dip)) == NULL)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Create the soft state */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Create the configuration kstats */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Create the VPD kstats */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Register the interface */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Announce ourselves in the system log */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Destroy the VPD kstats */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Destroy the configuration kstats */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Destroy the soft state */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Stop processing */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amoresfxge_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Wait for any pending restarts to complete */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * IOCTLs from utilites can cause GLD mc_start() (SFXGE_STARTED state)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * And mc_stop() may not occur until detach time and race. SFC bug 19855
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * Holding the lock seems to be enough - the log message is not seen
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore "STREAMS detach when STARTED");
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore ASSERT3U(sp->s_state, ==, SFXGE_REGISTERED);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Unregister the interface */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Destroy the VPD kstats */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Destroy the configuration kstats */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * Destroy the soft state - this might fail until rx_loaned packets that
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * have been passed up the STREAMS stack are returned
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'AmoreDDI_DEFINE_STREAM_OPS(sfxge_dev_ops, nulldev, nulldev, sfxge_attach,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore sfxge_detach, nulldev, NULL, D_MP, NULL, NULL);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amorestatic struct modlinkage sfxge_modlinkage = {
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore mutex_init(&sfxge_global_lock, NULL, MUTEX_DRIVER, NULL);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Create tables for CPU, core, cache and chip counts */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore sfxge_cpu = kmem_zalloc(sizeof (unsigned int) * NCPU, KM_SLEEP);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore mac_init_ops(&sfxge_dev_ops, SFXGE_DRIVER_NAME);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((rc = mod_install(&sfxge_modlinkage)) != 0)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore kmem_free(sfxge_cpu, sizeof (unsigned int) * NCPU);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((rc = mod_remove(&sfxge_modlinkage)) != 0)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Destroy tables */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore kmem_free(sfxge_cpu, sizeof (unsigned int) * NCPU);