ixgbe_main.c revision 13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * CDDL HEADER START
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * The contents of this file are subject to the terms of the
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Common Development and Distribution License (the "License").
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * You may not use this file except in compliance with the License.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
193974072f41a843678abf5f61979c748687e66bSherry Moore * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
193974072f41a843678abf5f61979c748687e66bSherry Moore * or http://www.opensolaris.org/os/licensing.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * See the License for the specific language governing permissions
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * and limitations under the License.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
193974072f41a843678abf5f61979c748687e66bSherry Moore * When distributing Covered Code, include this CDDL HEADER in each
193974072f41a843678abf5f61979c748687e66bSherry Moore * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If applicable, add the following below this CDDL HEADER, with the
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * fields enclosed by brackets "[]" replaced with your own identifying
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * information: Portions Copyright [yyyy] [name of copyright owner]
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * CDDL HEADER END
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
193974072f41a843678abf5f61979c748687e66bSherry Moore/*
193974072f41a843678abf5f61979c748687e66bSherry Moore * Copyright(c) 2007-2008 Intel Corporation. All rights reserved.
193974072f41a843678abf5f61979c748687e66bSherry Moore */
193974072f41a843678abf5f61979c748687e66bSherry Moore
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
193974072f41a843678abf5f61979c748687e66bSherry Moore * Use is subject to license terms.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt#include "ixgbe_sw.h"
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
193974072f41a843678abf5f61979c748687e66bSherry Moorestatic char ident[] = "Intel 10Gb Ethernet";
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Local function protoypes
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int ixgbe_register_mac(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int ixgbe_identify_hardware(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int ixgbe_regs_map(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_init_properties(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int ixgbe_init_driver_settings(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_init_locks(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_destroy_locks(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int ixgbe_init(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int ixgbe_chip_start(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_chip_stop(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int ixgbe_reset(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_tx_clean(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic boolean_t ixgbe_tx_drain(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic boolean_t ixgbe_rx_drain(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int ixgbe_alloc_rings(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int ixgbe_init_rings(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_free_rings(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_fini_rings(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_setup_rings(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_setup_rx(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_setup_tx(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_setup_rx_ring(ixgbe_rx_ring_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_setup_tx_ring(ixgbe_tx_ring_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_setup_rss(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_init_unicst(ixgbe_t *);
da14cebe459d3275048785f25bd869cb09b5307fEric Chengstatic int ixgbe_unicst_set(ixgbe_t *, const uint8_t *, int);
da14cebe459d3275048785f25bd869cb09b5307fEric Chengstatic int ixgbe_unicst_find(ixgbe_t *, const uint8_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_setup_multicst(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_get_hw_state(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_get_conf(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int ixgbe_get_prop(ixgbe_t *, char *, int, int, int);
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guostatic void ixgbe_driver_link_check(void *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_local_timer(void *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_arm_watchdog_timer(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_restart_watchdog_timer(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_disable_adapter_interrupts(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_enable_adapter_interrupts(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic boolean_t is_valid_mac_addr(uint8_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic boolean_t ixgbe_stall_check(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic boolean_t ixgbe_set_loopback_mode(ixgbe_t *, uint32_t);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_set_internal_mac_loopback(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic boolean_t ixgbe_find_mac_address(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int ixgbe_alloc_intrs(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int ixgbe_alloc_intr_handles(ixgbe_t *, int);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int ixgbe_add_intr_handlers(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_map_rxring_to_vector(ixgbe_t *, int, int);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_map_txring_to_vector(ixgbe_t *, int, int);
da14cebe459d3275048785f25bd869cb09b5307fEric Chengstatic void ixgbe_setup_ivar(ixgbe_t *, uint16_t, uint8_t);
da14cebe459d3275048785f25bd869cb09b5307fEric Chengstatic void ixgbe_enable_ivar(ixgbe_t *, uint16_t);
da14cebe459d3275048785f25bd869cb09b5307fEric Chengstatic void ixgbe_disable_ivar(ixgbe_t *, uint16_t);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int ixgbe_map_rings_to_vectors(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_setup_adapter_vector(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_rem_intr_handlers(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_rem_intrs(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int ixgbe_enable_intrs(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int ixgbe_disable_intrs(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic uint_t ixgbe_intr_legacy(void *, void *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic uint_t ixgbe_intr_msi(void *, void *);
da14cebe459d3275048785f25bd869cb09b5307fEric Chengstatic uint_t ixgbe_intr_rx_tx(void *, void *);
da14cebe459d3275048785f25bd869cb09b5307fEric Chengstatic uint_t ixgbe_intr_other(void *, void *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_intr_rx_work(ixgbe_rx_ring_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_intr_tx_work(ixgbe_tx_ring_t *);
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guostatic void ixgbe_intr_other_work(ixgbe_t *, uint32_t);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_get_driver_control(struct ixgbe_hw *);
da14cebe459d3275048785f25bd869cb09b5307fEric Chengstatic int ixgbe_addmac(void *, const uint8_t *);
da14cebe459d3275048785f25bd869cb09b5307fEric Chengstatic int ixgbe_remmac(void *, const uint8_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_release_driver_control(struct ixgbe_hw *);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int ixgbe_attach(dev_info_t *, ddi_attach_cmd_t);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int ixgbe_detach(dev_info_t *, ddi_detach_cmd_t);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int ixgbe_resume(dev_info_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int ixgbe_suspend(dev_info_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_unconfigure(dev_info_t *, ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic uint8_t *ixgbe_mc_table_itr(struct ixgbe_hw *, uint8_t **, uint32_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int ixgbe_fm_error_cb(dev_info_t *dip, ddi_fm_error_t *err,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt const void *impl_data);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_fm_init(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_fm_fini(ixgbe_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic struct cb_ops ixgbe_cb_ops = {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nulldev, /* cb_open */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nulldev, /* cb_close */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nodev, /* cb_strategy */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nodev, /* cb_print */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nodev, /* cb_dump */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nodev, /* cb_read */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nodev, /* cb_write */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nodev, /* cb_ioctl */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nodev, /* cb_devmap */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nodev, /* cb_mmap */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nodev, /* cb_segmap */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nochpoll, /* cb_chpoll */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_prop_op, /* cb_prop_op */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt NULL, /* cb_stream */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt D_MP | D_HOTPLUG, /* cb_flag */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt CB_REV, /* cb_rev */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nodev, /* cb_aread */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nodev /* cb_awrite */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt};
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic struct dev_ops ixgbe_dev_ops = {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DEVO_REV, /* devo_rev */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt 0, /* devo_refcnt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt NULL, /* devo_getinfo */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nulldev, /* devo_identify */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nulldev, /* devo_probe */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_attach, /* devo_attach */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_detach, /* devo_detach */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt nodev, /* devo_reset */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &ixgbe_cb_ops, /* devo_cb_ops */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt NULL, /* devo_bus_ops */
193974072f41a843678abf5f61979c748687e66bSherry Moore ddi_power, /* devo_power */
193974072f41a843678abf5f61979c748687e66bSherry Moore ddi_quiesce_not_supported, /* devo_quiesce */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt};
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic struct modldrv ixgbe_modldrv = {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &mod_driverops, /* Type of module. This one is a driver */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ident, /* Discription string */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &ixgbe_dev_ops /* driver ops */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt};
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic struct modlinkage ixgbe_modlinkage = {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt MODREV_1, &ixgbe_modldrv, NULL
9da57d7b0ddd8d73b676ce12c040362132cdd538bt};
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Access attributes for register mapping
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btddi_device_acc_attr_t ixgbe_regs_acc_attr = {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DDI_DEVICE_ATTR_V0,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DDI_STRUCTURE_LE_ACC,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DDI_STRICTORDER_ACC,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DDI_FLAGERR_ACC
9da57d7b0ddd8d73b676ce12c040362132cdd538bt};
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Loopback property
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic lb_property_t lb_normal = {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt normal, "normal", IXGBE_LB_NONE
9da57d7b0ddd8d73b676ce12c040362132cdd538bt};
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic lb_property_t lb_mac = {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt internal, "MAC", IXGBE_LB_INTERNAL_MAC
9da57d7b0ddd8d73b676ce12c040362132cdd538bt};
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt#define IXGBE_M_CALLBACK_FLAGS (MC_IOCTL | MC_GETCAPAB)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic mac_callbacks_t ixgbe_m_callbacks = {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_M_CALLBACK_FLAGS,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_m_stat,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_m_start,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_m_stop,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_m_promisc,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_m_multicst,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng NULL,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt NULL,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_m_ioctl,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_m_getcapab
9da57d7b0ddd8d73b676ce12c040362132cdd538bt};
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo/*
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo * Initialize capabilities of each supported adapter type
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guostatic adapter_info_t ixgbe_82598eb_cap = {
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo 64, /* maximum number of rx queues */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo 1, /* minimum number of rx queues */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo 8, /* default number of rx queues */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo 32, /* maximum number of tx queues */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo 1, /* minimum number of tx queues */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo 8, /* default number of tx queues */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo 18, /* maximum total msix vectors */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo 16, /* maximum number of ring vectors */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo 2, /* maximum number of other vectors */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo IXGBE_EICR_LSC, /* "other" interrupt types handled */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo (IXGBE_FLAG_DCA_CAPABLE /* capability flags */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo | IXGBE_FLAG_RSS_CAPABLE
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo | IXGBE_FLAG_VMDQ_CAPABLE)
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo};
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Module Initialization Functions.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btint
9da57d7b0ddd8d73b676ce12c040362132cdd538bt_init(void)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int status;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mac_init_ops(&ixgbe_dev_ops, MODULE_NAME);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt status = mod_install(&ixgbe_modlinkage);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (status != DDI_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mac_fini_ops(&ixgbe_dev_ops);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (status);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btint
9da57d7b0ddd8d73b676ce12c040362132cdd538bt_fini(void)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int status;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt status = mod_remove(&ixgbe_modlinkage);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (status == DDI_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mac_fini_ops(&ixgbe_dev_ops);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (status);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btint
9da57d7b0ddd8d73b676ce12c040362132cdd538bt_info(struct modinfo *modinfop)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int status;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt status = mod_info(&ixgbe_modlinkage, modinfop);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (status);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_attach - Driver attach.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * This function is the device specific initialization entry
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * point. This entry point is required and must be written.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * The DDI_ATTACH command must be provided in the attach entry
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * point. When attach() is called with cmd set to DDI_ATTACH,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * all normal kernel services (such as kmem_alloc(9F)) are
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * available for use by the driver.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * The attach() function will be called once for each instance
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * of the device on the system with cmd set to DDI_ATTACH.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Until attach() succeeds, the only driver entry points which
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * may be called are open(9E) and getinfo(9E).
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_attach(dev_info_t *devinfo, ddi_attach_cmd_t cmd)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_t *ixgbe;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_osdep *osdep;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_hw *hw;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int instance;
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo char taskqname[32];
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Check the command and perform corresponding operations
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt switch (cmd) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt default:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (DDI_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt case DDI_RESUME:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (ixgbe_resume(devinfo));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt case DDI_ATTACH:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt break;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /* Get the device instance */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt instance = ddi_get_instance(devinfo);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /* Allocate memory for the instance data structure */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe = kmem_zalloc(sizeof (ixgbe_t), KM_SLEEP);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->dip = devinfo;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->instance = instance;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt hw = &ixgbe->hw;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt osdep = &ixgbe->osdep;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt hw->back = osdep;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt osdep->ixgbe = ixgbe;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /* Attach the instance pointer to the dev_info data structure */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_set_driver_private(devinfo, ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Initialize for fma support
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg ixgbe->fm_capabilities = ixgbe_get_prop(ixgbe, PROP_FM_CAPABLE,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt 0, 0x0f, DDI_FM_EREPORT_CAPABLE | DDI_FM_ACCCHK_CAPABLE |
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DDI_FM_DMACHK_CAPABLE | DDI_FM_ERRCB_CAPABLE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_fm_init(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->attach_progress |= ATTACH_PROGRESS_FM_INIT;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Map PCI config space registers
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (pci_config_setup(devinfo, &osdep->cfg_handle) != DDI_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe, "Failed to map PCI configurations");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto attach_fail;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->attach_progress |= ATTACH_PROGRESS_PCI_CONFIG;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Identify the chipset family
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_identify_hardware(ixgbe) != IXGBE_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe, "Failed to identify hardware");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto attach_fail;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Map device registers
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_regs_map(ixgbe) != IXGBE_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe, "Failed to map device registers");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto attach_fail;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->attach_progress |= ATTACH_PROGRESS_REGS_MAP;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Initialize driver parameters
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_init_properties(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->attach_progress |= ATTACH_PROGRESS_PROPS;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocate interrupts
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_alloc_intrs(ixgbe) != IXGBE_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe, "Failed to allocate interrupts");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto attach_fail;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->attach_progress |= ATTACH_PROGRESS_ALLOC_INTR;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocate rx/tx rings based on the ring numbers.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * The actual numbers of rx/tx rings are decided by the number of
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * allocated interrupt vectors, so we should allocate the rings after
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * interrupts are allocated.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_alloc_rings(ixgbe) != IXGBE_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe, "Failed to allocate rx and tx rings");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto attach_fail;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->attach_progress |= ATTACH_PROGRESS_ALLOC_RINGS;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Map rings to interrupt vectors
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_map_rings_to_vectors(ixgbe) != IXGBE_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe, "Failed to map rings to vectors");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto attach_fail;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Add interrupt handlers
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_add_intr_handlers(ixgbe) != IXGBE_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe, "Failed to add interrupt handlers");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto attach_fail;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->attach_progress |= ATTACH_PROGRESS_ADD_INTR;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo /*
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo * Create a taskq for link-status-change
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo (void) sprintf(taskqname, "ixgbe%d_taskq", instance);
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo if ((ixgbe->lsc_taskq = ddi_taskq_create(devinfo, taskqname,
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo 1, TASKQ_DEFAULTPRI, 0)) == NULL) {
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ixgbe_error(ixgbe, "taskq_create failed");
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo goto attach_fail;
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo }
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ixgbe->attach_progress |= ATTACH_PROGRESS_LSC_TASKQ;
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Initialize driver parameters
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_init_driver_settings(ixgbe) != IXGBE_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe, "Failed to initialize driver settings");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto attach_fail;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Initialize mutexes for this device.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Do this before enabling the interrupt handler and
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * register the softint to avoid the condition where
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * interrupt handler can try using uninitialized mutex.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_init_locks(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->attach_progress |= ATTACH_PROGRESS_LOCKS;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Initialize chipset hardware
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_init(ixgbe) != IXGBE_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe, "Failed to initialize adapter");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto attach_fail;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->attach_progress |= ATTACH_PROGRESS_INIT;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_check_acc_handle(ixgbe->osdep.cfg_handle) != DDI_FM_OK) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_fm_service_impact(ixgbe->dip, DDI_SERVICE_LOST);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto attach_fail;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Initialize DMA and hardware settings for rx/tx rings
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_init_rings(ixgbe) != IXGBE_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe, "Failed to initialize rings");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto attach_fail;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->attach_progress |= ATTACH_PROGRESS_INIT_RINGS;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Initialize statistics
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_init_stats(ixgbe) != IXGBE_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe, "Failed to initialize statistics");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto attach_fail;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->attach_progress |= ATTACH_PROGRESS_STATS;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Initialize NDD parameters
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_nd_init(ixgbe) != IXGBE_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe, "Failed to initialize ndd");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto attach_fail;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->attach_progress |= ATTACH_PROGRESS_NDD;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Register the driver to the MAC
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_register_mac(ixgbe) != IXGBE_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe, "Failed to register MAC");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto attach_fail;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo mac_link_update(ixgbe->mac_hdl, LINK_STATE_UNKNOWN);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->attach_progress |= ATTACH_PROGRESS_MAC;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Now that mutex locks are initialized, and the chip is also
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * initialized, enable interrupts.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_enable_intrs(ixgbe) != IXGBE_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe, "Failed to enable DDI interrupts");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto attach_fail;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->attach_progress |= ATTACH_PROGRESS_ENABLE_INTR;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->ixgbe_state |= IXGBE_INITIALIZED;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (DDI_SUCCESS);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btattach_fail:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_unconfigure(devinfo, ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (DDI_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_detach - Driver detach.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * The detach() function is the complement of the attach routine.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If cmd is set to DDI_DETACH, detach() is used to remove the
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * state associated with a given instance of a device node
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * prior to the removal of that instance from the system.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * The detach() function will be called once for each instance
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * of the device for which there has been a successful attach()
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * once there are no longer any opens on the device.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Interrupts routine are disabled, All memory allocated by this
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * driver are freed.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_detach(dev_info_t *devinfo, ddi_detach_cmd_t cmd)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_t *ixgbe;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Check detach command
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt switch (cmd) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt default:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (DDI_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt case DDI_SUSPEND:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (ixgbe_suspend(devinfo));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt case DDI_DETACH:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt break;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Get the pointer to the driver private data structure
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe = (ixgbe_t *)ddi_get_driver_private(devinfo);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe == NULL)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (DDI_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Unregister MAC. If failed, we have to fail the detach
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (mac_unregister(ixgbe->mac_hdl) != 0) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe, "Failed to unregister MAC");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (DDI_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->attach_progress &= ~ATTACH_PROGRESS_MAC;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If the device is still running, it needs to be stopped first.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * This check is necessary because under some specific circumstances,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * the detach routine can be called without stopping the interface
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * first.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(&ixgbe->gen_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->ixgbe_state & IXGBE_STARTED) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->ixgbe_state &= ~IXGBE_STARTED;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_stop(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&ixgbe->gen_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /* Disable and stop the watchdog timer */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_disable_watchdog_timer(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt } else
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&ixgbe->gen_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Check if there are still rx buffers held by the upper layer.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If so, fail the detach.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (!ixgbe_rx_drain(ixgbe))
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (DDI_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Do the remaining unconfigure routines
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_unconfigure(devinfo, ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (DDI_SUCCESS);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_unconfigure(dev_info_t *devinfo, ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Disable interrupt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->attach_progress & ATTACH_PROGRESS_ENABLE_INTR) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) ixgbe_disable_intrs(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Unregister MAC
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->attach_progress & ATTACH_PROGRESS_MAC) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) mac_unregister(ixgbe->mac_hdl);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Free ndd parameters
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->attach_progress & ATTACH_PROGRESS_NDD) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_nd_cleanup(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Free statistics
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->attach_progress & ATTACH_PROGRESS_STATS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt kstat_delete((kstat_t *)ixgbe->ixgbe_ks);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Remove interrupt handlers
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->attach_progress & ATTACH_PROGRESS_ADD_INTR) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_rem_intr_handlers(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo /*
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo * Remove taskq for link-status-change
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo if (ixgbe->attach_progress & ATTACH_PROGRESS_LSC_TASKQ) {
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ddi_taskq_destroy(ixgbe->lsc_taskq);
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo }
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Remove interrupts
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->attach_progress & ATTACH_PROGRESS_ALLOC_INTR) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_rem_intrs(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Remove driver properties
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->attach_progress & ATTACH_PROGRESS_PROPS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) ddi_prop_remove_all(devinfo);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Release the DMA resources of rx/tx rings
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->attach_progress & ATTACH_PROGRESS_INIT_RINGS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_fini_rings(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Stop the chipset
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->attach_progress & ATTACH_PROGRESS_INIT) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(&ixgbe->gen_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_chip_stop(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&ixgbe->gen_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Free register handle
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->attach_progress & ATTACH_PROGRESS_REGS_MAP) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->osdep.reg_handle != NULL)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_regs_map_free(&ixgbe->osdep.reg_handle);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Free PCI config handle
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->attach_progress & ATTACH_PROGRESS_PCI_CONFIG) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->osdep.cfg_handle != NULL)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt pci_config_teardown(&ixgbe->osdep.cfg_handle);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Free locks
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->attach_progress & ATTACH_PROGRESS_LOCKS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_destroy_locks(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Free the rx/tx rings
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->attach_progress & ATTACH_PROGRESS_ALLOC_RINGS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_free_rings(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Unregister FMA capabilities
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->attach_progress & ATTACH_PROGRESS_FM_INIT) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_fm_fini(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Free the driver data structure
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt kmem_free(ixgbe, sizeof (ixgbe_t));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_set_driver_private(devinfo, NULL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_register_mac - Register the driver and its function pointers with
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * the GLD interface.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_register_mac(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_hw *hw = &ixgbe->hw;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mac_register_t *mac;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int status;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if ((mac = mac_alloc(MAC_VERSION)) == NULL)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mac->m_type_ident = MAC_PLUGIN_IDENT_ETHER;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mac->m_driver = ixgbe;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mac->m_dip = ixgbe->dip;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mac->m_src_addr = hw->mac.addr;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mac->m_callbacks = &ixgbe_m_callbacks;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mac->m_min_sdu = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mac->m_max_sdu = ixgbe->default_mtu;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mac->m_margin = VLAN_TAGSZ;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mac->m_v12n = MAC_VIRT_LEVEL1;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt status = mac_register(mac, &ixgbe->mac_hdl);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mac_free(mac);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return ((status == 0) ? IXGBE_SUCCESS : IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_identify_hardware - Identify the type of the chipset.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_identify_hardware(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_hw *hw = &ixgbe->hw;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_osdep *osdep = &ixgbe->osdep;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Get the device id
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt hw->vendor_id =
9da57d7b0ddd8d73b676ce12c040362132cdd538bt pci_config_get16(osdep->cfg_handle, PCI_CONF_VENID);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt hw->device_id =
9da57d7b0ddd8d73b676ce12c040362132cdd538bt pci_config_get16(osdep->cfg_handle, PCI_CONF_DEVID);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt hw->revision_id =
9da57d7b0ddd8d73b676ce12c040362132cdd538bt pci_config_get8(osdep->cfg_handle, PCI_CONF_REVID);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt hw->subsystem_device_id =
9da57d7b0ddd8d73b676ce12c040362132cdd538bt pci_config_get16(osdep->cfg_handle, PCI_CONF_SUBSYSID);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt hw->subsystem_vendor_id =
9da57d7b0ddd8d73b676ce12c040362132cdd538bt pci_config_get16(osdep->cfg_handle, PCI_CONF_SUBVENID);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo /*
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo * Set the mac type of the adapter based on the device id
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo if (ixgbe_set_mac_type(hw) != IXGBE_SUCCESS) {
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo return (IXGBE_FAILURE);
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo }
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo /*
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo * Install adapter capabilities
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo switch (hw->mac.type) {
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo case ixgbe_mac_82598EB:
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ixgbe_log(ixgbe, "identify oplin adapter\n");
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ixgbe->capab = &ixgbe_82598eb_cap;
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo if (ixgbe_get_media_type(hw) == ixgbe_media_type_copper) {
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ixgbe->capab->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ixgbe->capab->other_intr |= IXGBE_EICR_GPI_SDP1;
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo }
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo break;
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo default:
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ixgbe_log(ixgbe,
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo "adapter not supported in ixgbe_identify_hardware(): %d\n",
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo hw->mac.type);
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo return (IXGBE_FAILURE);
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo }
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_SUCCESS);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_regs_map - Map the device registers.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_regs_map(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt dev_info_t *devinfo = ixgbe->dip;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_hw *hw = &ixgbe->hw;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_osdep *osdep = &ixgbe->osdep;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt off_t mem_size;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * First get the size of device registers to be mapped.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ddi_dev_regsize(devinfo, 1, &mem_size) != DDI_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Call ddi_regs_map_setup() to map registers
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if ((ddi_regs_map_setup(devinfo, 1,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (caddr_t *)&hw->hw_addr, 0,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mem_size, &ixgbe_regs_acc_attr,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &osdep->reg_handle)) != DDI_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_SUCCESS);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_init_properties - Initialize driver properties.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_init_properties(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Get conf file properties, including link settings
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * jumbo frames, ring number, descriptor number, etc.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_get_conf(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_init_driver_settings - Initialize driver settings.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * The settings include hardware function pointers, bus information,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * rx/tx rings settings, link state, and any other parameters that
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * need to be setup during driver initialization.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_init_driver_settings(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_hw *hw = &ixgbe->hw;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng dev_info_t *devinfo = ixgbe->dip;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_rx_ring_t *rx_ring;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_tx_ring_t *tx_ring;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint32_t rx_size;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint32_t tx_size;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int i;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Initialize chipset specific hardware function pointers
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_init_shared_code(hw) != IXGBE_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng /*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Get the system page size
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe->sys_page_size = ddi_ptob(devinfo, (ulong_t)1);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Set rx buffer size
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * The IP header alignment room is counted in the calculation.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * The rx buffer size is in unit of 1K that is required by the
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * chipset hardware.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rx_size = ixgbe->max_frame_size + IPHDR_ALIGN_ROOM;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->rx_buf_size = ((rx_size >> 10) +
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ((rx_size & (((uint32_t)1 << 10) - 1)) > 0 ? 1 : 0)) << 10;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Set tx buffer size
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_size = ixgbe->max_frame_size;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->tx_buf_size = ((tx_size >> 10) +
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ((tx_size & (((uint32_t)1 << 10) - 1)) > 0 ? 1 : 0)) << 10;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Initialize rx/tx rings parameters
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < ixgbe->num_rx_rings; i++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rx_ring = &ixgbe->rx_rings[i];
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rx_ring->index = i;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rx_ring->ixgbe = ixgbe;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rx_ring->ring_size = ixgbe->rx_ring_size;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rx_ring->free_list_size = ixgbe->rx_ring_size;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rx_ring->copy_thresh = ixgbe->rx_copy_thresh;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rx_ring->limit_per_intr = ixgbe->rx_limit_per_intr;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < ixgbe->num_tx_rings; i++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring = &ixgbe->tx_rings[i];
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->index = i;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->ixgbe = ixgbe;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->tx_head_wb_enable)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tx_recycle = ixgbe_tx_recycle_head_wb;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt else
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tx_recycle = ixgbe_tx_recycle_legacy;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->ring_size = ixgbe->tx_ring_size;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->free_list_size = ixgbe->tx_ring_size +
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (ixgbe->tx_ring_size >> 1);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->copy_thresh = ixgbe->tx_copy_thresh;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->recycle_thresh = ixgbe->tx_recycle_thresh;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->overload_thresh = ixgbe->tx_overload_thresh;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->resched_thresh = ixgbe->tx_resched_thresh;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Initialize values of interrupt throttling rate
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo for (i = 1; i < MAX_RING_VECTOR; i++)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->intr_throttling[i] = ixgbe->intr_throttling[0];
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * The initial link state should be "unknown"
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->link_state = LINK_STATE_UNKNOWN;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_SUCCESS);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_init_locks - Initialize locks.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_init_locks(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_rx_ring_t *rx_ring;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_tx_ring_t *tx_ring;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int i;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < ixgbe->num_rx_rings; i++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rx_ring = &ixgbe->rx_rings[i];
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_init(&rx_ring->rx_lock, NULL,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt MUTEX_DRIVER, DDI_INTR_PRI(ixgbe->intr_pri));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_init(&rx_ring->recycle_lock, NULL,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt MUTEX_DRIVER, DDI_INTR_PRI(ixgbe->intr_pri));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < ixgbe->num_tx_rings; i++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring = &ixgbe->tx_rings[i];
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_init(&tx_ring->tx_lock, NULL,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt MUTEX_DRIVER, DDI_INTR_PRI(ixgbe->intr_pri));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_init(&tx_ring->recycle_lock, NULL,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt MUTEX_DRIVER, DDI_INTR_PRI(ixgbe->intr_pri));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_init(&tx_ring->tcb_head_lock, NULL,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt MUTEX_DRIVER, DDI_INTR_PRI(ixgbe->intr_pri));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_init(&tx_ring->tcb_tail_lock, NULL,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt MUTEX_DRIVER, DDI_INTR_PRI(ixgbe->intr_pri));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_init(&ixgbe->gen_lock, NULL,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt MUTEX_DRIVER, DDI_INTR_PRI(ixgbe->intr_pri));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_init(&ixgbe->watchdog_lock, NULL,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt MUTEX_DRIVER, DDI_INTR_PRI(ixgbe->intr_pri));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_destroy_locks - Destroy locks.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_destroy_locks(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_rx_ring_t *rx_ring;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_tx_ring_t *tx_ring;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int i;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < ixgbe->num_rx_rings; i++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rx_ring = &ixgbe->rx_rings[i];
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_destroy(&rx_ring->rx_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_destroy(&rx_ring->recycle_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < ixgbe->num_tx_rings; i++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring = &ixgbe->tx_rings[i];
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_destroy(&tx_ring->tx_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_destroy(&tx_ring->recycle_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_destroy(&tx_ring->tcb_head_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_destroy(&tx_ring->tcb_tail_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_destroy(&ixgbe->gen_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_destroy(&ixgbe->watchdog_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_resume(dev_info_t *devinfo)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_t *ixgbe;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe = (ixgbe_t *)ddi_get_driver_private(devinfo);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe == NULL)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (DDI_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(&ixgbe->gen_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->ixgbe_state & IXGBE_STARTED) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_start(ixgbe) != IXGBE_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&ixgbe->gen_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (DDI_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Enable and start the watchdog timer
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_enable_watchdog_timer(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->ixgbe_state &= ~IXGBE_SUSPENDED;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&ixgbe->gen_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (DDI_SUCCESS);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_suspend(dev_info_t *devinfo)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_t *ixgbe;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe = (ixgbe_t *)ddi_get_driver_private(devinfo);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe == NULL)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (DDI_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(&ixgbe->gen_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->ixgbe_state |= IXGBE_SUSPENDED;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_stop(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&ixgbe->gen_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Disable and stop the watchdog timer
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_disable_watchdog_timer(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (DDI_SUCCESS);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_init - Initialize the device.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_init(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_hw *hw = &ixgbe->hw;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(&ixgbe->gen_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Reset chipset to put the hardware in a known state
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * before we try to do anything with the eeprom.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_reset_hw(hw) != IXGBE_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_fm_ereport(ixgbe, DDI_FM_DEVICE_INVAL_STATE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto init_fail;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Need to init eeprom before validating the checksum.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_init_eeprom_params(hw) < 0) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Unable to intitialize the eeprom interface.");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_fm_ereport(ixgbe, DDI_FM_DEVICE_INVAL_STATE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto init_fail;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * NVM validation
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_validate_eeprom_checksum(hw, NULL) < 0) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Some PCI-E parts fail the first check due to
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * the link being in sleep state. Call it again,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * if it fails a second time it's a real issue.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_validate_eeprom_checksum(hw, NULL) < 0) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Invalid NVM checksum. Please contact "
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "the vendor to update the NVM.");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_fm_ereport(ixgbe, DDI_FM_DEVICE_INVAL_STATE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto init_fail;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Setup default flow control thresholds - enable/disable
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * & flow control type is controlled by ixgbe.conf
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt hw->fc.high_water = DEFAULT_FCRTH;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt hw->fc.low_water = DEFAULT_FCRTL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt hw->fc.pause_time = DEFAULT_FCPAUSE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt hw->fc.send_xon = B_TRUE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Don't wait for auto-negotiation to complete
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt hw->phy.autoneg_wait_to_complete = B_FALSE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Initialize link settings
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) ixgbe_driver_setup_link(ixgbe, B_FALSE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Initialize the chipset hardware
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_chip_start(ixgbe) != IXGBE_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_fm_ereport(ixgbe, DDI_FM_DEVICE_INVAL_STATE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto init_fail;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_check_acc_handle(ixgbe->osdep.cfg_handle) != DDI_FM_OK) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto init_fail;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_check_acc_handle(ixgbe->osdep.reg_handle) != DDI_FM_OK) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto init_fail;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&ixgbe->gen_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_SUCCESS);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btinit_fail:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Reset PHY
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) ixgbe_reset_phy(hw);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&ixgbe->gen_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_fm_service_impact(ixgbe->dip, DDI_SERVICE_LOST);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_init_rings - Allocate DMA resources for all rx/tx rings and
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * initialize relevant hardware settings.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_init_rings(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int i;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocate buffers for all the rx/tx rings
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_alloc_dma(ixgbe) != IXGBE_SUCCESS)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Setup the rx/tx rings
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(&ixgbe->gen_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < ixgbe->num_rx_rings; i++)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(&ixgbe->rx_rings[i].rx_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < ixgbe->num_tx_rings; i++)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(&ixgbe->tx_rings[i].tx_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_setup_rings(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = ixgbe->num_tx_rings - 1; i >= 0; i--)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&ixgbe->tx_rings[i].tx_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = ixgbe->num_rx_rings - 1; i >= 0; i--)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&ixgbe->rx_rings[i].rx_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&ixgbe->gen_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_SUCCESS);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_fini_rings - Release DMA resources of all rx/tx rings.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_fini_rings(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Release the DMA/memory resources of rx/tx rings
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_free_dma(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_chip_start - Initialize and start the chipset hardware.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_chip_start(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_hw *hw = &ixgbe->hw;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int i;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(mutex_owned(&ixgbe->gen_lock));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Get the mac address
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * This function should handle SPARC case correctly.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (!ixgbe_find_mac_address(ixgbe)) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe, "Failed to get the mac address");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Validate the mac address
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) ixgbe_init_rx_addrs(hw);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (!is_valid_mac_addr(hw->mac.addr)) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe, "Invalid mac address");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Configure/Initialize hardware
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_init_hw(hw) != IXGBE_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe, "Failed to initialize hardware");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Setup adapter interrupt vectors
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_setup_adapter_vector(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Initialize unicast addresses.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_init_unicst(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Setup and initialize the mctable structures.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_setup_multicst(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Set interrupt throttling rate
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < ixgbe->intr_cnt; i++)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_EITR(i), ixgbe->intr_throttling[i]);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Save the state of the phy
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_get_hw_state(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Make sure driver has control
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_get_driver_control(hw);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_SUCCESS);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_chip_stop - Stop the chipset hardware
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_chip_stop(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_hw *hw = &ixgbe->hw;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(mutex_owned(&ixgbe->gen_lock));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Tell firmware driver is no longer in control
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_release_driver_control(hw);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Reset the chipset
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) ixgbe_reset_hw(hw);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Reset PHY
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) ixgbe_reset_phy(hw);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_reset - Reset the chipset and re-start the driver.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * It involves stopping and re-starting the chipset,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * and re-configuring the rx/tx rings.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_reset(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int i;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(&ixgbe->gen_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(ixgbe->ixgbe_state & IXGBE_STARTED);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->ixgbe_state &= ~IXGBE_STARTED;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Disable the adapter interrupts to stop any rx/tx activities
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * before draining pending data and resetting hardware.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_disable_adapter_interrupts(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Drain the pending transmit packets
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) ixgbe_tx_drain(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < ixgbe->num_rx_rings; i++)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(&ixgbe->rx_rings[i].rx_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < ixgbe->num_tx_rings; i++)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(&ixgbe->tx_rings[i].tx_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Stop the chipset hardware
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_chip_stop(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Clean the pending tx data/resources
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_tx_clean(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Start the chipset hardware
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_chip_start(ixgbe) != IXGBE_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_fm_ereport(ixgbe, DDI_FM_DEVICE_INVAL_STATE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto reset_failure;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_check_acc_handle(ixgbe->osdep.reg_handle) != DDI_FM_OK) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto reset_failure;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Setup the rx/tx rings
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_setup_rings(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Enable adapter interrupts
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * The interrupts must be enabled after the driver state is START
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_enable_adapter_interrupts(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = ixgbe->num_tx_rings - 1; i >= 0; i--)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&ixgbe->tx_rings[i].tx_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = ixgbe->num_rx_rings - 1; i >= 0; i--)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&ixgbe->rx_rings[i].rx_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->ixgbe_state |= IXGBE_STARTED;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&ixgbe->gen_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_SUCCESS);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btreset_failure:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = ixgbe->num_tx_rings - 1; i >= 0; i--)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&ixgbe->tx_rings[i].tx_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = ixgbe->num_rx_rings - 1; i >= 0; i--)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&ixgbe->rx_rings[i].rx_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&ixgbe->gen_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_fm_service_impact(ixgbe->dip, DDI_SERVICE_LOST);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_tx_clean - Clean the pending transmit packets and DMA resources.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_tx_clean(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_tx_ring_t *tx_ring;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_control_block_t *tcb;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt link_list_t pending_list;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint32_t desc_num;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int i, j;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt LINK_LIST_INIT(&pending_list);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < ixgbe->num_tx_rings; i++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring = &ixgbe->tx_rings[i];
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(&tx_ring->recycle_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Clean the pending tx data - the pending packets in the
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * work_list that have no chances to be transmitted again.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * We must ensure the chipset is stopped or the link is down
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * before cleaning the transmit packets.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt desc_num = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (j = 0; j < tx_ring->ring_size; j++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tcb = tx_ring->work_list[j];
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (tcb != NULL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt desc_num += tcb->desc_num;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->work_list[j] = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_free_tcb(tcb);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt LIST_PUSH_TAIL(&pending_list, &tcb->link);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (desc_num > 0) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt atomic_add_32(&tx_ring->tbd_free, desc_num);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(tx_ring->tbd_free == tx_ring->ring_size);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Reset the head and tail pointers of the tbd ring;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Reset the writeback head if it's enable.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tbd_head = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tbd_tail = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->tx_head_wb_enable)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *tx_ring->tbd_head_wb = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(&ixgbe->hw,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_TDH(tx_ring->index), 0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(&ixgbe->hw,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_TDT(tx_ring->index), 0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&tx_ring->recycle_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Add the tx control blocks in the pending list to
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * the free list.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_put_free_list(tx_ring, &pending_list);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_tx_drain - Drain the tx rings to allow pending packets to be
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * transmitted.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic boolean_t
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_tx_drain(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_tx_ring_t *tx_ring;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt boolean_t done;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int i, j;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Wait for a specific time to allow pending tx packets
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * to be transmitted.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Check the counter tbd_free to see if transmission is done.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * No lock protection is needed here.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Return B_TRUE if all pending packets have been transmitted;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Otherwise return B_FALSE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < TX_DRAIN_TIME; i++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt done = B_TRUE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (j = 0; j < ixgbe->num_tx_rings; j++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring = &ixgbe->tx_rings[j];
9da57d7b0ddd8d73b676ce12c040362132cdd538bt done = done &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (tx_ring->tbd_free == tx_ring->ring_size);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (done)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt break;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt msec_delay(1);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (done);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_rx_drain - Wait for all rx buffers to be released by upper layer.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic boolean_t
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_rx_drain(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_rx_ring_t *rx_ring;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt boolean_t done;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int i, j;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Polling the rx free list to check if those rx buffers held by
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * the upper layer are released.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Check the counter rcb_free to see if all pending buffers are
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * released. No lock protection is needed here.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Return B_TRUE if all pending buffers have been released;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Otherwise return B_FALSE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < RX_DRAIN_TIME; i++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt done = B_TRUE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (j = 0; j < ixgbe->num_rx_rings; j++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rx_ring = &ixgbe->rx_rings[j];
9da57d7b0ddd8d73b676ce12c040362132cdd538bt done = done &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (rx_ring->rcb_free == rx_ring->free_list_size);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (done)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt break;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt msec_delay(1);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (done);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_start - Start the driver/chipset.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btint
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_start(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int i;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(mutex_owned(&ixgbe->gen_lock));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < ixgbe->num_rx_rings; i++)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(&ixgbe->rx_rings[i].rx_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < ixgbe->num_tx_rings; i++)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(&ixgbe->tx_rings[i].tx_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Start the chipset hardware
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_chip_start(ixgbe) != IXGBE_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_fm_ereport(ixgbe, DDI_FM_DEVICE_INVAL_STATE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto start_failure;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_check_acc_handle(ixgbe->osdep.reg_handle) != DDI_FM_OK) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto start_failure;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Setup the rx/tx rings
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_setup_rings(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Enable adapter interrupts
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * The interrupts must be enabled after the driver state is START
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_enable_adapter_interrupts(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = ixgbe->num_tx_rings - 1; i >= 0; i--)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&ixgbe->tx_rings[i].tx_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = ixgbe->num_rx_rings - 1; i >= 0; i--)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&ixgbe->rx_rings[i].rx_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_SUCCESS);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btstart_failure:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = ixgbe->num_tx_rings - 1; i >= 0; i--)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&ixgbe->tx_rings[i].tx_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = ixgbe->num_rx_rings - 1; i >= 0; i--)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&ixgbe->rx_rings[i].rx_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_fm_service_impact(ixgbe->dip, DDI_SERVICE_LOST);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_stop - Stop the driver/chipset.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btvoid
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_stop(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int i;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(mutex_owned(&ixgbe->gen_lock));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Disable the adapter interrupts
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_disable_adapter_interrupts(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Drain the pending tx packets
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) ixgbe_tx_drain(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < ixgbe->num_rx_rings; i++)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(&ixgbe->rx_rings[i].rx_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < ixgbe->num_tx_rings; i++)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(&ixgbe->tx_rings[i].tx_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Stop the chipset hardware
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_chip_stop(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_check_acc_handle(ixgbe->osdep.reg_handle) != DDI_FM_OK) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_fm_service_impact(ixgbe->dip, DDI_SERVICE_LOST);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Clean the pending tx data/resources
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_tx_clean(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = ixgbe->num_tx_rings - 1; i >= 0; i--)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&ixgbe->tx_rings[i].tx_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = ixgbe->num_rx_rings - 1; i >= 0; i--)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&ixgbe->rx_rings[i].rx_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_alloc_rings - Allocate memory space for rx/tx rings.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_alloc_rings(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocate memory space for rx rings
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->rx_rings = kmem_zalloc(
9da57d7b0ddd8d73b676ce12c040362132cdd538bt sizeof (ixgbe_rx_ring_t) * ixgbe->num_rx_rings,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt KM_NOSLEEP);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->rx_rings == NULL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocate memory space for tx rings
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->tx_rings = kmem_zalloc(
9da57d7b0ddd8d73b676ce12c040362132cdd538bt sizeof (ixgbe_tx_ring_t) * ixgbe->num_tx_rings,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt KM_NOSLEEP);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->tx_rings == NULL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt kmem_free(ixgbe->rx_rings,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt sizeof (ixgbe_rx_ring_t) * ixgbe->num_rx_rings);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->rx_rings = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng /*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Allocate memory space for rx ring groups
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe->rx_groups = kmem_zalloc(
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng sizeof (ixgbe_rx_group_t) * ixgbe->num_rx_groups,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng KM_NOSLEEP);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (ixgbe->rx_groups == NULL) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng kmem_free(ixgbe->rx_rings,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng sizeof (ixgbe_rx_ring_t) * ixgbe->num_rx_rings);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng kmem_free(ixgbe->tx_rings,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng sizeof (ixgbe_tx_ring_t) * ixgbe->num_tx_rings);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe->rx_rings = NULL;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe->tx_rings = NULL;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng return (IXGBE_FAILURE);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_SUCCESS);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_free_rings - Free the memory space of rx/tx rings.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_free_rings(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->rx_rings != NULL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt kmem_free(ixgbe->rx_rings,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt sizeof (ixgbe_rx_ring_t) * ixgbe->num_rx_rings);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->rx_rings = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->tx_rings != NULL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt kmem_free(ixgbe->tx_rings,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt sizeof (ixgbe_tx_ring_t) * ixgbe->num_tx_rings);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->tx_rings = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (ixgbe->rx_groups != NULL) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng kmem_free(ixgbe->rx_groups,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng sizeof (ixgbe_rx_group_t) * ixgbe->num_rx_groups);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe->rx_groups = NULL;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_setup_rings - Setup rx/tx rings.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_setup_rings(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Setup the rx/tx rings, including the following:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * 1. Setup the descriptor ring and the control block buffers;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * 2. Initialize necessary registers for receive/transmit;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * 3. Initialize software pointers/parameters for receive/transmit;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_setup_rx(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_setup_tx(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_setup_rx_ring(ixgbe_rx_ring_t *rx_ring)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_t *ixgbe = rx_ring->ixgbe;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_hw *hw = &ixgbe->hw;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rx_control_block_t *rcb;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt union ixgbe_adv_rx_desc *rbd;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint32_t size;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint32_t buf_low;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint32_t buf_high;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint32_t reg_val;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int i;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(mutex_owned(&rx_ring->rx_lock));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(mutex_owned(&ixgbe->gen_lock));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < ixgbe->rx_ring_size; i++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rcb = rx_ring->work_list[i];
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rbd = &rx_ring->rbd_ring[i];
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rbd->read.pkt_addr = rcb->rx_buf.dma_address;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rbd->read.hdr_addr = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Initialize the length register
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt size = rx_ring->ring_size * sizeof (union ixgbe_adv_rx_desc);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_RDLEN(rx_ring->index), size);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Initialize the base address registers
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt buf_low = (uint32_t)rx_ring->rbd_area.dma_address;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt buf_high = (uint32_t)(rx_ring->rbd_area.dma_address >> 32);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_RDBAH(rx_ring->index), buf_high);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_RDBAL(rx_ring->index), buf_low);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Setup head & tail pointers
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_RDT(rx_ring->index), rx_ring->ring_size - 1);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_RDH(rx_ring->index), 0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rx_ring->rbd_next = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Note: Considering the case that the chipset is being reset
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * and there are still some buffers held by the upper layer,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * we should not reset the values of rcb_head, rcb_tail and
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * rcb_free if the state is not IXGBE_UNKNOWN.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->ixgbe_state == IXGBE_UNKNOWN) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rx_ring->rcb_head = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rx_ring->rcb_tail = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rx_ring->rcb_free = rx_ring->free_list_size;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Setup the Receive Descriptor Control Register (RXDCTL)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * PTHRESH=32 descriptors (half the internal cache)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * HTHRESH=0 descriptors (to minimize latency on fetch)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * WTHRESH defaults to 1 (writeback each descriptor)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt reg_val = IXGBE_READ_REG(hw, IXGBE_RXDCTL(rx_ring->index));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt reg_val |= IXGBE_RXDCTL_ENABLE; /* enable queue */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt reg_val |= 0x0020; /* pthresh */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(rx_ring->index), reg_val);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Setup the Split and Replication Receive Control Register.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Set the rx buffer size and the advanced descriptor type.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt reg_val = (ixgbe->rx_buf_size >> IXGBE_SRRCTL_BSIZEPKT_SHIFT) |
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(rx_ring->index), reg_val);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_setup_rx(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_rx_ring_t *rx_ring;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_hw *hw = &ixgbe->hw;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe_rx_group_t *rx_group;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint32_t reg_val;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng uint32_t ring_mapping;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int i;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Set filter control in FCTRL to accept broadcast packets and do
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * not pass pause frames to host. Flow control settings are already
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * in this register, so preserve them.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt reg_val = IXGBE_READ_REG(hw, IXGBE_FCTRL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt reg_val |= IXGBE_FCTRL_BAM; /* broadcast accept mode */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt reg_val |= IXGBE_FCTRL_DPF; /* discard pause frames */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_FCTRL, reg_val);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Enable the receive unit. This must be done after filter
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * control is set in FCTRL.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt reg_val = (IXGBE_RXCTRL_RXEN /* Enable Receive Unit */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt | IXGBE_RXCTRL_DMBYPS); /* descriptor monitor bypass */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, reg_val);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_setup_rx_ring must be called after configuring RXCTRL
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < ixgbe->num_rx_rings; i++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rx_ring = &ixgbe->rx_rings[i];
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_setup_rx_ring(rx_ring);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng /*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Setup rx groups.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng for (i = 0; i < ixgbe->num_rx_groups; i++) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng rx_group = &ixgbe->rx_groups[i];
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng rx_group->index = i;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng rx_group->ixgbe = ixgbe;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng /*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Setup the per-ring statistics mapping.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ring_mapping = 0;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng for (i = 0; i < ixgbe->num_rx_rings; i++) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ring_mapping |= (i & 0xF) << (8 * (i & 0x3));
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if ((i & 0x3) == 0x3) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i >> 2), ring_mapping);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ring_mapping = 0;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if ((i & 0x3) != 0x3)
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i >> 2), ring_mapping);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * The Max Frame Size in MHADD will be internally increased by four
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * bytes if the packet has a VLAN field, so includes MTU, ethernet
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * header and frame check sequence.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt reg_val = (ixgbe->default_mtu + sizeof (struct ether_header)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt + ETHERFCSL) << IXGBE_MHADD_MFS_SHIFT;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_MHADD, reg_val);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Setup Jumbo Frame enable bit
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->default_mtu > ETHERMTU) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt reg_val = IXGBE_READ_REG(hw, IXGBE_HLREG0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt reg_val |= IXGBE_HLREG0_JUMBOEN;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_HLREG0, reg_val);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Hardware checksum settings
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->rx_hcksum_enable) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt reg_val = IXGBE_RXCSUM_IPPCSE; /* IP checksum */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, reg_val);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Setup RSS for multiple receive queues
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->num_rx_rings > 1)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_setup_rss(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_setup_tx_ring(ixgbe_tx_ring_t *tx_ring)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_t *ixgbe = tx_ring->ixgbe;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_hw *hw = &ixgbe->hw;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint32_t size;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint32_t buf_low;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint32_t buf_high;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint32_t reg_val;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(mutex_owned(&tx_ring->tx_lock));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(mutex_owned(&ixgbe->gen_lock));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Initialize the length register
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt size = tx_ring->ring_size * sizeof (union ixgbe_adv_tx_desc);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_TDLEN(tx_ring->index), size);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Initialize the base address registers
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt buf_low = (uint32_t)tx_ring->tbd_area.dma_address;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt buf_high = (uint32_t)(tx_ring->tbd_area.dma_address >> 32);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_TDBAL(tx_ring->index), buf_low);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_TDBAH(tx_ring->index), buf_high);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * setup TXDCTL(tx_ring->index)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt reg_val = IXGBE_TXDCTL_ENABLE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(tx_ring->index), reg_val);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Setup head & tail pointers
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_TDH(tx_ring->index), 0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_TDT(tx_ring->index), 0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Setup head write-back
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->tx_head_wb_enable) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * The memory of the head write-back is allocated using
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * the extra tbd beyond the tail of the tbd ring.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tbd_head_wb = (uint32_t *)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ((uintptr_t)tx_ring->tbd_area.address + size);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *tx_ring->tbd_head_wb = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt buf_low = (uint32_t)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (tx_ring->tbd_area.dma_address + size);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt buf_high = (uint32_t)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ((tx_ring->tbd_area.dma_address + size) >> 32);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /* Set the head write-back enable bit */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt buf_low |= IXGBE_TDWBAL_HEAD_WB_ENABLE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_TDWBAL(tx_ring->index), buf_low);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_TDWBAH(tx_ring->index), buf_high);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Turn off relaxed ordering for head write back or it will
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * cause problems with the tx recycling
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt reg_val = IXGBE_READ_REG(hw,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_DCA_TXCTRL(tx_ring->index));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt reg_val &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_DCA_TXCTRL(tx_ring->index), reg_val);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt } else {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tbd_head_wb = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tbd_head = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tbd_tail = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tbd_free = tx_ring->ring_size;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Note: Considering the case that the chipset is being reset,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * and there are still some tcb in the pending list,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * we should not reset the values of tcb_head, tcb_tail and
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * tcb_free if the state is not IXGBE_UNKNOWN.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->ixgbe_state == IXGBE_UNKNOWN) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tcb_head = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tcb_tail = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tcb_free = tx_ring->free_list_size;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
f27d3025d908422c3f6e682964b4f1e2b4834e4agg * Initialize the s/w context structure
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
f27d3025d908422c3f6e682964b4f1e2b4834e4agg bzero(&tx_ring->tx_context, sizeof (ixgbe_tx_context_t));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_setup_tx(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg struct ixgbe_hw *hw = &ixgbe->hw;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_tx_ring_t *tx_ring;
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg uint32_t reg_val;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng uint32_t ring_mapping;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int i;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < ixgbe->num_tx_rings; i++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring = &ixgbe->tx_rings[i];
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_setup_tx_ring(tx_ring);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng /*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Setup the per-ring statistics mapping.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ring_mapping = 0;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng for (i = 0; i < ixgbe->num_tx_rings; i++) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ring_mapping |= (i & 0xF) << (8 * (i & 0x3));
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if ((i & 0x3) == 0x3) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng IXGBE_WRITE_REG(hw, IXGBE_TQSMR(i >> 2), ring_mapping);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ring_mapping = 0;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if ((i & 0x3) != 0x3)
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng IXGBE_WRITE_REG(hw, IXGBE_TQSMR(i >> 2), ring_mapping);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg /*
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg * Enable CRC appending and TX padding (for short tx frames)
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg */
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg reg_val = IXGBE_READ_REG(hw, IXGBE_HLREG0);
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg reg_val |= IXGBE_HLREG0_TXCRCEN | IXGBE_HLREG0_TXPADEN;
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg IXGBE_WRITE_REG(hw, IXGBE_HLREG0, reg_val);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_setup_rss - Setup receive-side scaling feature.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_setup_rss(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_hw *hw = &ixgbe->hw;
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg uint32_t i, mrqc, rxcsum;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint32_t random;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint32_t reta;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Fill out redirection table
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt reta = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < 128; i++) {
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg reta = (reta << 8) | (i % ixgbe->num_rx_rings);
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg if ((i & 3) == 3)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Fill out hash function seeds with a random constant
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < 10; i++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) random_get_pseudo_bytes((uint8_t *)&random,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt sizeof (uint32_t));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), random);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg * Enable RSS & perform hash on these packet types
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mrqc = IXGBE_MRQC_RSSEN |
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_MRQC_RSS_FIELD_IPV4 |
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_MRQC_RSS_FIELD_IPV4_UDP |
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_MRQC_RSS_FIELD_IPV6_EX_TCP |
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_MRQC_RSS_FIELD_IPV6_EX |
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_MRQC_RSS_FIELD_IPV6 |
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_MRQC_RSS_FIELD_IPV6_TCP |
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_MRQC_RSS_FIELD_IPV6_UDP |
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_MRQC_RSS_FIELD_IPV6_EX_UDP;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Disable Packet Checksum to enable RSS for multiple receive queues.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * It is an adapter hardware limitation that Packet Checksum is
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * mutually exclusive with RSS.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rxcsum |= IXGBE_RXCSUM_PCSD;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rxcsum &= ~IXGBE_RXCSUM_IPPCSE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_init_unicst - Initialize the unicast addresses.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_init_unicst(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_hw *hw = &ixgbe->hw;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng uint8_t *mac_addr;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int slot;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Here we should consider two situations:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * 1. Chipset is initialized at the first time,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Clear all the multiple unicast addresses.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * 2. Chipset is reset
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Recover the multiple unicast addresses from the
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * software data structure to the RAR registers.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (!ixgbe->unicst_init) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Initialize the multiple unicast addresses
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->unicst_total = MAX_NUM_UNICAST_ADDRESSES;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe->unicst_avail = ixgbe->unicst_total;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng for (slot = 0; slot < ixgbe->unicst_total; slot++) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mac_addr = ixgbe->unicst_addr[slot].mac.addr;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng bzero(mac_addr, ETHERADDRL);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng (void) ixgbe_set_rar(hw, slot, mac_addr, NULL, NULL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->unicst_addr[slot].mac.set = 0;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->unicst_init = B_TRUE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt } else {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /* Re-configure the RAR registers */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng for (slot = 0; slot < ixgbe->unicst_total; slot++) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mac_addr = ixgbe->unicst_addr[slot].mac.addr;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (ixgbe->unicst_addr[slot].mac.set == 1) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng (void) ixgbe_set_rar(hw, slot, mac_addr,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng NULL, IXGBE_RAH_AV);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng } else {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng bzero(mac_addr, ETHERADDRL);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng (void) ixgbe_set_rar(hw, slot, mac_addr,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng NULL, NULL);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_unicst_set - Set the unicast address to the specified slot.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btint
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_unicst_set(ixgbe_t *ixgbe, const uint8_t *mac_addr,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng int slot)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_hw *hw = &ixgbe->hw;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(mutex_owned(&ixgbe->gen_lock));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Save the unicast address in the software data structure
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt bcopy(mac_addr, ixgbe->unicst_addr[slot].mac.addr, ETHERADDRL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Set the unicast address to the RAR register
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng (void) ixgbe_set_rar(hw, slot, (uint8_t *)mac_addr, NULL, IXGBE_RAH_AV);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_check_acc_handle(ixgbe->osdep.reg_handle) != DDI_FM_OK) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_fm_service_impact(ixgbe->dip, DDI_SERVICE_DEGRADED);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (EIO);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng/*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * ixgbe_unicst_find - Find the slot for the specified unicast address
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng */
da14cebe459d3275048785f25bd869cb09b5307fEric Chengint
da14cebe459d3275048785f25bd869cb09b5307fEric Chengixgbe_unicst_find(ixgbe_t *ixgbe, const uint8_t *mac_addr)
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng{
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng int slot;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ASSERT(mutex_owned(&ixgbe->gen_lock));
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng for (slot = 0; slot < ixgbe->unicst_total; slot++) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (bcmp(ixgbe->unicst_addr[slot].mac.addr,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mac_addr, ETHERADDRL) == 0)
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng return (slot);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng return (-1);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng}
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_multicst_add - Add a multicst address.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btint
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_multicst_add(ixgbe_t *ixgbe, const uint8_t *multiaddr)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(mutex_owned(&ixgbe->gen_lock));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if ((multiaddr[0] & 01) == 0) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (EINVAL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->mcast_count >= MAX_NUM_MULTICAST_ADDRESSES) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (ENOENT);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt bcopy(multiaddr,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &ixgbe->mcast_table[ixgbe->mcast_count], ETHERADDRL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->mcast_count++;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Update the multicast table in the hardware
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_setup_multicst(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_check_acc_handle(ixgbe->osdep.reg_handle) != DDI_FM_OK) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_fm_service_impact(ixgbe->dip, DDI_SERVICE_DEGRADED);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (EIO);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_multicst_remove - Remove a multicst address.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btint
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_multicst_remove(ixgbe_t *ixgbe, const uint8_t *multiaddr)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int i;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(mutex_owned(&ixgbe->gen_lock));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < ixgbe->mcast_count; i++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (bcmp(multiaddr, &ixgbe->mcast_table[i],
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ETHERADDRL) == 0) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i++; i < ixgbe->mcast_count; i++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->mcast_table[i - 1] =
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->mcast_table[i];
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->mcast_count--;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt break;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Update the multicast table in the hardware
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_setup_multicst(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_check_acc_handle(ixgbe->osdep.reg_handle) != DDI_FM_OK) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_fm_service_impact(ixgbe->dip, DDI_SERVICE_DEGRADED);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (EIO);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_setup_multicast - Setup multicast data structures.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * This routine initializes all of the multicast related structures
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * and save them in the hardware registers.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_setup_multicst(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint8_t *mc_addr_list;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint32_t mc_addr_count;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_hw *hw = &ixgbe->hw;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(mutex_owned(&ixgbe->gen_lock));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(ixgbe->mcast_count <= MAX_NUM_MULTICAST_ADDRESSES);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mc_addr_list = (uint8_t *)ixgbe->mcast_table;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mc_addr_count = ixgbe->mcast_count;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Update the multicast addresses to the MTA registers
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) ixgbe_update_mc_addr_list(hw, mc_addr_list, mc_addr_count,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_mc_table_itr);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_get_conf - Get driver configurations set in driver.conf.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * This routine gets user-configured values out of the configuration
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * file ixgbe.conf.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * For each configurable value, there is a minimum, a maximum, and a
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * default.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If user does not configure a value, use the default.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If user configures below the minimum, use the minumum.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If user configures above the maximum, use the maxumum.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_get_conf(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_hw *hw = &ixgbe->hw;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint32_t flow_control;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe driver supports the following user configurations:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Jumbo frame configuration:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * default_mtu
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Ethernet flow control configuration:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * flow_control
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Multiple rings configurations:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * tx_queue_number
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * tx_ring_size
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * rx_queue_number
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * rx_ring_size
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Call ixgbe_get_prop() to get the value for a specific
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * configuration parameter.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Jumbo frame configuration - max_frame_size controls host buffer
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * allocation, so includes MTU, ethernet header, vlan tag and
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * frame check sequence.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->default_mtu = ixgbe_get_prop(ixgbe, PROP_DEFAULT_MTU,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt MIN_MTU, MAX_MTU, DEFAULT_MTU);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->max_frame_size = ixgbe->default_mtu +
9da57d7b0ddd8d73b676ce12c040362132cdd538bt sizeof (struct ether_vlan_header) + ETHERFCSL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Ethernet flow control configuration
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt flow_control = ixgbe_get_prop(ixgbe, PROP_FLOW_CONTROL,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe_fc_none, 3, ixgbe_fc_none);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (flow_control == 3)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt flow_control = ixgbe_fc_default;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt hw->fc.type = flow_control;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Multiple rings configurations
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->num_tx_rings = ixgbe_get_prop(ixgbe, PROP_TX_QUEUE_NUM,
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ixgbe->capab->min_tx_que_num,
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ixgbe->capab->max_tx_que_num,
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ixgbe->capab->def_tx_que_num);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->tx_ring_size = ixgbe_get_prop(ixgbe, PROP_TX_RING_SIZE,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt MIN_TX_RING_SIZE, MAX_TX_RING_SIZE, DEFAULT_TX_RING_SIZE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->num_rx_rings = ixgbe_get_prop(ixgbe, PROP_RX_QUEUE_NUM,
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ixgbe->capab->min_rx_que_num,
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ixgbe->capab->max_rx_que_num,
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ixgbe->capab->def_rx_que_num);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->rx_ring_size = ixgbe_get_prop(ixgbe, PROP_RX_RING_SIZE,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt MIN_RX_RING_SIZE, MAX_RX_RING_SIZE, DEFAULT_RX_RING_SIZE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng /*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Multiple groups configuration
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe->num_rx_groups = ixgbe_get_prop(ixgbe, PROP_RX_GROUP_NUM,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng MIN_RX_GROUP_NUM, MAX_RX_GROUP_NUM, DEFAULT_RX_GROUP_NUM);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe->mr_enable = ixgbe_get_prop(ixgbe, PROP_MR_ENABLE,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng 0, 1, DEFAULT_MR_ENABLE);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (ixgbe->mr_enable == B_FALSE) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe->num_tx_rings = 1;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe->num_rx_rings = 1;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe->num_rx_groups = 1;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Tunable used to force an interrupt type. The only use is
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * for testing of the lesser interrupt types.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * 0 = don't force interrupt type
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * 1 = force interrupt type MSI-X
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * 2 = force interrupt type MSI
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * 3 = force interrupt type Legacy
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->intr_force = ixgbe_get_prop(ixgbe, PROP_INTR_FORCE,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_INTR_NONE, IXGBE_INTR_LEGACY, IXGBE_INTR_NONE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->tx_hcksum_enable = ixgbe_get_prop(ixgbe, PROP_TX_HCKSUM_ENABLE,
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg 0, 1, DEFAULT_TX_HCKSUM_ENABLE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->rx_hcksum_enable = ixgbe_get_prop(ixgbe, PROP_RX_HCKSUM_ENABLE,
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg 0, 1, DEFAULT_RX_HCKSUM_ENABLE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->lso_enable = ixgbe_get_prop(ixgbe, PROP_LSO_ENABLE,
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg 0, 1, DEFAULT_LSO_ENABLE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->tx_head_wb_enable = ixgbe_get_prop(ixgbe, PROP_TX_HEAD_WB_ENABLE,
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg 0, 1, DEFAULT_TX_HEAD_WB_ENABLE);
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg /*
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg * ixgbe LSO needs the tx h/w checksum support.
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg * LSO will be disabled if tx h/w checksum is not
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg * enabled.
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg */
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg if (ixgbe->tx_hcksum_enable == B_FALSE) {
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg ixgbe->lso_enable = B_FALSE;
c971fb7ec0a19c6cd00c5614a94c97f953b6e8b1gg }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->tx_copy_thresh = ixgbe_get_prop(ixgbe, PROP_TX_COPY_THRESHOLD,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt MIN_TX_COPY_THRESHOLD, MAX_TX_COPY_THRESHOLD,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DEFAULT_TX_COPY_THRESHOLD);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->tx_recycle_thresh = ixgbe_get_prop(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt PROP_TX_RECYCLE_THRESHOLD, MIN_TX_RECYCLE_THRESHOLD,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt MAX_TX_RECYCLE_THRESHOLD, DEFAULT_TX_RECYCLE_THRESHOLD);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->tx_overload_thresh = ixgbe_get_prop(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt PROP_TX_OVERLOAD_THRESHOLD, MIN_TX_OVERLOAD_THRESHOLD,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt MAX_TX_OVERLOAD_THRESHOLD, DEFAULT_TX_OVERLOAD_THRESHOLD);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->tx_resched_thresh = ixgbe_get_prop(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt PROP_TX_RESCHED_THRESHOLD, MIN_TX_RESCHED_THRESHOLD,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt MAX_TX_RESCHED_THRESHOLD, DEFAULT_TX_RESCHED_THRESHOLD);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->rx_copy_thresh = ixgbe_get_prop(ixgbe, PROP_RX_COPY_THRESHOLD,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt MIN_RX_COPY_THRESHOLD, MAX_RX_COPY_THRESHOLD,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DEFAULT_RX_COPY_THRESHOLD);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->rx_limit_per_intr = ixgbe_get_prop(ixgbe, PROP_RX_LIMIT_PER_INTR,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt MIN_RX_LIMIT_PER_INTR, MAX_RX_LIMIT_PER_INTR,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DEFAULT_RX_LIMIT_PER_INTR);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->intr_throttling[0] = ixgbe_get_prop(ixgbe, PROP_INTR_THROTTLING,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt MIN_INTR_THROTTLING, MAX_INTR_THROTTLING,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DEFAULT_INTR_THROTTLING);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_get_prop - Get a property value out of the configuration file
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe.conf.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Caller provides the name of the property, a default value, a minimum
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * value, and a maximum value.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Return configured value of the property, with default, minimum and
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * maximum properly applied.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_get_prop(ixgbe_t *ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt char *propname, /* name of the property */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int minval, /* minimum acceptable value */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int maxval, /* maximim acceptable value */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int defval) /* default value */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int value;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Call ddi_prop_get_int() to read the conf settings
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt value = ddi_prop_get_int(DDI_DEV_T_ANY, ixgbe->dip,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DDI_PROP_DONTPASS, propname, defval);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (value > maxval)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt value = maxval;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (value < minval)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt value = minval;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (value);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_driver_setup_link - Using the link properties to setup the link.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btint
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_driver_setup_link(ixgbe_t *ixgbe, boolean_t setup_hw)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_mac_info *mac;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_phy_info *phy;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt boolean_t invalid;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mac = &ixgbe->hw.mac;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt phy = &ixgbe->hw.phy;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt invalid = B_FALSE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->param_adv_autoneg_cap == 1) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mac->autoneg = B_TRUE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt phy->autoneg_advertised = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * No half duplex support with 10Gb parts
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->param_adv_10000fdx_cap == 1)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt phy->autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->param_adv_1000fdx_cap == 1)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt phy->autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->param_adv_100fdx_cap == 1)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt phy->autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (phy->autoneg_advertised == 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt invalid = B_TRUE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt } else {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->hw.mac.autoneg = B_FALSE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (invalid) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_notice(ixgbe, "Invalid link settings. Setup link to "
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "autonegotiation with full link capabilities.");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->hw.mac.autoneg = B_TRUE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (setup_hw) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_setup_link(&ixgbe->hw) != IXGBE_SUCCESS)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_SUCCESS);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo * ixgbe_driver_link_check - Link status processing done in taskq.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guostatic void
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guoixgbe_driver_link_check(void *arg)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ixgbe_t *ixgbe = (ixgbe_t *)arg;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_hw *hw = &ixgbe->hw;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_link_speed speed = IXGBE_LINK_SPEED_UNKNOWN;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt boolean_t link_up = B_FALSE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt boolean_t link_changed = B_FALSE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo mutex_enter(&ixgbe->gen_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo /* check for link, wait the full time */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo (void) ixgbe_check_link(hw, &speed, &link_up, true);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (link_up) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * The Link is up, check whether it was marked as down earlier
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->link_state != LINK_STATE_UP) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt switch (speed) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt case IXGBE_LINK_SPEED_10GB_FULL:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->link_speed = SPEED_10GB;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt break;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt case IXGBE_LINK_SPEED_1GB_FULL:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->link_speed = SPEED_1GB;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt break;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt case IXGBE_LINK_SPEED_100_FULL:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->link_speed = SPEED_100;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->link_duplex = LINK_DUPLEX_FULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->link_state = LINK_STATE_UP;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->link_down_timeout = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt link_changed = B_TRUE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt } else {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->link_state != LINK_STATE_DOWN) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->link_speed = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->link_duplex = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->link_state = LINK_STATE_DOWN;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt link_changed = B_TRUE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->ixgbe_state & IXGBE_STARTED) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->link_down_timeout < MAX_LINK_DOWN_TIMEOUT) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->link_down_timeout++;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt } else if (ixgbe->link_down_timeout ==
9da57d7b0ddd8d73b676ce12c040362132cdd538bt MAX_LINK_DOWN_TIMEOUT) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_tx_clean(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->link_down_timeout++;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo /*
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo * this is only reached after a link-status-change interrupt
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo * so always get new phy state
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ixgbe_get_hw_state(ixgbe);
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo /* re-enable the interrupt, which was automasked */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ixgbe->eims |= IXGBE_EICR_LSC;
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo IXGBE_WRITE_REG(hw, IXGBE_EIMS, ixgbe->eims);
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo mutex_exit(&ixgbe->gen_lock);
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo /* outside the gen_lock */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo if (link_changed) {
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo mac_link_update(ixgbe->mac_hdl, ixgbe->link_state);
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_local_timer - Driver watchdog function.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * This function will handle the transmit stall check, link status check and
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * other routines.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_local_timer(void *arg)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_t *ixgbe = (ixgbe_t *)arg;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_stall_check(ixgbe)) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->reset_count++;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_reset(ixgbe) == IXGBE_SUCCESS)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_fm_service_impact(ixgbe->dip, DDI_SERVICE_RESTORED);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_restart_watchdog_timer(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_stall_check - Check for transmit stall.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * This function checks if the adapter is stalled (in transmit).
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * It is called each time the watchdog timeout is invoked.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If the transmit descriptor reclaim continuously fails,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * the watchdog value will increment by 1. If the watchdog
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * value exceeds the threshold, the ixgbe is assumed to
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * have stalled and need to be reset.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic boolean_t
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_stall_check(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_tx_ring_t *tx_ring;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt boolean_t result;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int i;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->link_state != LINK_STATE_UP)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (B_FALSE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If any tx ring is stalled, we'll reset the chipset
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt result = B_FALSE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < ixgbe->num_tx_rings; i++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring = &ixgbe->tx_rings[i];
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng tx_ring->tx_recycle(tx_ring);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (tx_ring->recycle_fail > 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->stall_watchdog++;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt else
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->stall_watchdog = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (tx_ring->stall_watchdog >= STALL_WATCHDOG_TIMEOUT) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt result = B_TRUE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt break;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (result) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->stall_watchdog = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->recycle_fail = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (result);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * is_valid_mac_addr - Check if the mac address is valid.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic boolean_t
9da57d7b0ddd8d73b676ce12c040362132cdd538btis_valid_mac_addr(uint8_t *mac_addr)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt const uint8_t addr_test1[6] = { 0, 0, 0, 0, 0, 0 };
9da57d7b0ddd8d73b676ce12c040362132cdd538bt const uint8_t addr_test2[6] =
9da57d7b0ddd8d73b676ce12c040362132cdd538bt { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (!(bcmp(addr_test1, mac_addr, ETHERADDRL)) ||
9da57d7b0ddd8d73b676ce12c040362132cdd538bt !(bcmp(addr_test2, mac_addr, ETHERADDRL)))
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (B_FALSE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (B_TRUE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic boolean_t
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_find_mac_address(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt#ifdef __sparc
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_hw *hw = &ixgbe->hw;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uchar_t *bytes;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ether_addr sysaddr;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint_t nelts;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int err;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt boolean_t found = B_FALSE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * The "vendor's factory-set address" may already have
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * been extracted from the chip, but if the property
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * "local-mac-address" is set we use that instead.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * We check whether it looks like an array of 6
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * bytes (which it should, if OBP set it). If we can't
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * make sense of it this way, we'll ignore it.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt err = ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, ixgbe->dip,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DDI_PROP_DONTPASS, "local-mac-address", &bytes, &nelts);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (err == DDI_PROP_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nelts == ETHERADDRL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt while (nelts--)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt hw->mac.addr[nelts] = bytes[nelts];
9da57d7b0ddd8d73b676ce12c040362132cdd538bt found = B_TRUE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_prop_free(bytes);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Look up the OBP property "local-mac-address?". If the user has set
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * 'local-mac-address? = false', use "the system address" instead.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, ixgbe->dip, 0,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "local-mac-address?", &bytes, &nelts) == DDI_PROP_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (strncmp("false", (caddr_t)bytes, (size_t)nelts) == 0) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (localetheraddr(NULL, &sysaddr) != 0) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt bcopy(&sysaddr, hw->mac.addr, ETHERADDRL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt found = B_TRUE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_prop_free(bytes);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Finally(!), if there's a valid "mac-address" property (created
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * if we netbooted from this interface), we must use this instead
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * of any of the above to ensure that the NFS/install server doesn't
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * get confused by the address changing as Solaris takes over!
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt err = ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, ixgbe->dip,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DDI_PROP_DONTPASS, "mac-address", &bytes, &nelts);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (err == DDI_PROP_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (nelts == ETHERADDRL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt while (nelts--)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt hw->mac.addr[nelts] = bytes[nelts];
9da57d7b0ddd8d73b676ce12c040362132cdd538bt found = B_TRUE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_prop_free(bytes);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (found) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt bcopy(hw->mac.addr, hw->mac.perm_addr, ETHERADDRL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (B_TRUE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt#else
9da57d7b0ddd8d73b676ce12c040362132cdd538bt _NOTE(ARGUNUSED(ixgbe));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt#endif
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (B_TRUE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt#pragma inline(ixgbe_arm_watchdog_timer)
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_arm_watchdog_timer(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Fire a watchdog timer
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->watchdog_tid =
9da57d7b0ddd8d73b676ce12c040362132cdd538bt timeout(ixgbe_local_timer,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void *)ixgbe, 1 * drv_usectohz(1000000));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_enable_watchdog_timer - Enable and start the driver watchdog timer.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btvoid
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_enable_watchdog_timer(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(&ixgbe->watchdog_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (!ixgbe->watchdog_enable) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->watchdog_enable = B_TRUE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->watchdog_start = B_TRUE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_arm_watchdog_timer(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&ixgbe->watchdog_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_disable_watchdog_timer - Disable and stop the driver watchdog timer.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btvoid
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_disable_watchdog_timer(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt timeout_id_t tid;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(&ixgbe->watchdog_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->watchdog_enable = B_FALSE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->watchdog_start = B_FALSE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tid = ixgbe->watchdog_tid;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->watchdog_tid = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&ixgbe->watchdog_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (tid != 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) untimeout(tid);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_start_watchdog_timer - Start the driver watchdog timer.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guovoid
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_start_watchdog_timer(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(&ixgbe->watchdog_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->watchdog_enable) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (!ixgbe->watchdog_start) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->watchdog_start = B_TRUE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_arm_watchdog_timer(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&ixgbe->watchdog_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_restart_watchdog_timer - Restart the driver watchdog timer.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_restart_watchdog_timer(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(&ixgbe->watchdog_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->watchdog_start)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_arm_watchdog_timer(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&ixgbe->watchdog_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_stop_watchdog_timer - Stop the driver watchdog timer.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guovoid
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_stop_watchdog_timer(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt timeout_id_t tid;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(&ixgbe->watchdog_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->watchdog_start = B_FALSE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tid = ixgbe->watchdog_tid;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->watchdog_tid = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&ixgbe->watchdog_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (tid != 0)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) untimeout(tid);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_disable_adapter_interrupts - Disable all adapter interrupts.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_disable_adapter_interrupts(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_hw *hw = &ixgbe->hw;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * mask all interrupts off
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_EIMC, 0xffffffff);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * for MSI-X, also disable autoclear
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->intr_type == DDI_INTR_TYPE_MSIX) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_EIAC, 0x0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_FLUSH(hw);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_enable_adapter_interrupts - Enable all hardware interrupts.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_enable_adapter_interrupts(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_hw *hw = &ixgbe->hw;
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo uint32_t eiac, eiam;
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo uint32_t gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo /* interrupt types to enable */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ixgbe->eims = IXGBE_EIMS_ENABLE_MASK; /* shared code default */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ixgbe->eims &= ~IXGBE_EIMS_TCP_TIMER; /* minus tcp timer */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ixgbe->eims |= ixgbe->capab->other_intr; /* "other" interrupt types */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo /* enable automask on "other" causes that this adapter can generate */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo eiam = ixgbe->capab->other_intr;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * msi-x mode
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->intr_type == DDI_INTR_TYPE_MSIX) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /* enable autoclear but not on bits 29:20 */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo eiac = (ixgbe->eims & ~IXGBE_OTHER_INTR);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /* general purpose interrupt enable */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo gpie |= (IXGBE_GPIE_MSIX_MODE
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo | IXGBE_GPIE_PBA_SUPPORT
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo | IXGBE_GPIE_OCD
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo | IXGBE_GPIE_EIAME);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * non-msi-x mode
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt } else {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /* disable autoclear, leave gpie at default */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt eiac = 0;
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo /* general purpose interrupt enable */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo gpie |= IXGBE_GPIE_EIAME;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo /* write to interrupt control registers */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo IXGBE_WRITE_REG(hw, IXGBE_EIMS, ixgbe->eims);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_EIAC, eiac);
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo IXGBE_WRITE_REG(hw, IXGBE_EIAM, eiam);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_FLUSH(hw);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_loopback_ioctl - Loopback support.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btenum ioc_reply
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_loopback_ioctl(ixgbe_t *ixgbe, struct iocblk *iocp, mblk_t *mp)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt lb_info_sz_t *lbsp;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt lb_property_t *lbpp;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint32_t *lbmp;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint32_t size;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint32_t value;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (mp->b_cont == NULL)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IOC_INVAL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt switch (iocp->ioc_cmd) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt default:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IOC_INVAL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt case LB_GET_INFO_SIZE:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt size = sizeof (lb_info_sz_t);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (iocp->ioc_count != size)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IOC_INVAL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt value = sizeof (lb_normal);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt value += sizeof (lb_mac);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt lbsp = (lb_info_sz_t *)(uintptr_t)mp->b_cont->b_rptr;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *lbsp = value;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt break;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt case LB_GET_INFO:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt value = sizeof (lb_normal);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt value += sizeof (lb_mac);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt size = value;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (iocp->ioc_count != size)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IOC_INVAL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt value = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt lbpp = (lb_property_t *)(uintptr_t)mp->b_cont->b_rptr;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt lbpp[value++] = lb_normal;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt lbpp[value++] = lb_mac;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt break;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt case LB_GET_MODE:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt size = sizeof (uint32_t);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (iocp->ioc_count != size)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IOC_INVAL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt lbmp = (uint32_t *)(uintptr_t)mp->b_cont->b_rptr;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *lbmp = ixgbe->loopback_mode;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt break;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt case LB_SET_MODE:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt size = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (iocp->ioc_count != sizeof (uint32_t))
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IOC_INVAL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt lbmp = (uint32_t *)(uintptr_t)mp->b_cont->b_rptr;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (!ixgbe_set_loopback_mode(ixgbe, *lbmp))
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IOC_INVAL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt break;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt iocp->ioc_count = size;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt iocp->ioc_error = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_check_acc_handle(ixgbe->osdep.reg_handle) != DDI_FM_OK) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_fm_service_impact(ixgbe->dip, DDI_SERVICE_DEGRADED);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IOC_INVAL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IOC_REPLY);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_set_loopback_mode - Setup loopback based on the loopback mode.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic boolean_t
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_set_loopback_mode(ixgbe_t *ixgbe, uint32_t mode)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_hw *hw;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (mode == ixgbe->loopback_mode)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (B_TRUE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt hw = &ixgbe->hw;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->loopback_mode = mode;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (mode == IXGBE_LB_NONE) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Reset the chip
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt hw->phy.autoneg_wait_to_complete = B_TRUE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) ixgbe_reset(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt hw->phy.autoneg_wait_to_complete = B_FALSE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (B_TRUE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(&ixgbe->gen_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt switch (mode) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt default:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&ixgbe->gen_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (B_FALSE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt case IXGBE_LB_INTERNAL_MAC:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_set_internal_mac_loopback(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt break;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&ixgbe->gen_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (B_TRUE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_set_internal_mac_loopback - Set the internal MAC loopback mode.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_set_internal_mac_loopback(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_hw *hw;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint32_t reg;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint8_t atlas;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt hw = &ixgbe->hw;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Setup MAC loopback
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt reg = IXGBE_READ_REG(&ixgbe->hw, IXGBE_HLREG0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt reg |= IXGBE_HLREG0_LPBK;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(&ixgbe->hw, IXGBE_HLREG0, reg);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt reg = IXGBE_READ_REG(&ixgbe->hw, IXGBE_AUTOC);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt reg &= ~IXGBE_AUTOC_LMS_MASK;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(&ixgbe->hw, IXGBE_AUTOC, reg);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Disable Atlas Tx lanes to keep packets in loopback and not on wire
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (hw->mac.type == ixgbe_mac_82598EB) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) ixgbe_read_analog_reg8(&ixgbe->hw, IXGBE_ATLAS_PDN_LPBK,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &atlas);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt atlas |= IXGBE_ATLAS_PDN_TX_REG_EN;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) ixgbe_write_analog_reg8(&ixgbe->hw, IXGBE_ATLAS_PDN_LPBK,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt atlas);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) ixgbe_read_analog_reg8(&ixgbe->hw, IXGBE_ATLAS_PDN_10G,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &atlas);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt atlas |= IXGBE_ATLAS_PDN_TX_10G_QL_ALL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) ixgbe_write_analog_reg8(&ixgbe->hw, IXGBE_ATLAS_PDN_10G,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt atlas);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) ixgbe_read_analog_reg8(&ixgbe->hw, IXGBE_ATLAS_PDN_1G,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &atlas);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt atlas |= IXGBE_ATLAS_PDN_TX_1G_QL_ALL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) ixgbe_write_analog_reg8(&ixgbe->hw, IXGBE_ATLAS_PDN_1G,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt atlas);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) ixgbe_read_analog_reg8(&ixgbe->hw, IXGBE_ATLAS_PDN_AN,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &atlas);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt atlas |= IXGBE_ATLAS_PDN_TX_AN_QL_ALL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) ixgbe_write_analog_reg8(&ixgbe->hw, IXGBE_ATLAS_PDN_AN,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt atlas);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt#pragma inline(ixgbe_intr_rx_work)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_intr_rx_work - RX processing of ISR.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_intr_rx_work(ixgbe_rx_ring_t *rx_ring)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mblk_t *mp;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(&rx_ring->rx_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mp = ixgbe_ring_rx(rx_ring, IXGBE_POLL_NULL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&rx_ring->rx_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (mp != NULL)
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mac_rx_ring(rx_ring->ixgbe->mac_hdl, rx_ring->ring_handle, mp,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng rx_ring->ring_gen_num);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt#pragma inline(ixgbe_intr_tx_work)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_intr_tx_work - TX processing of ISR.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_intr_tx_work(ixgbe_tx_ring_t *tx_ring)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Recycle the tx descriptors
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tx_recycle(tx_ring);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Schedule the re-transmit
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (tx_ring->reschedule &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (tx_ring->tbd_free >= tx_ring->resched_thresh)) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->reschedule = B_FALSE;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mac_tx_ring_update(tx_ring->ixgbe->mac_hdl,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng tx_ring->ring_handle);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_DEBUG_STAT(tx_ring->stat_reschedule);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt#pragma inline(ixgbe_intr_other_work)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo * ixgbe_intr_other_work - Process interrupt types other than tx/rx
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guoixgbe_intr_other_work(ixgbe_t *ixgbe, uint32_t eicr)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo * dispatch taskq to handle link status change
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo if (eicr & IXGBE_EICR_LSC) {
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo if ((ddi_taskq_dispatch(ixgbe->lsc_taskq,
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ixgbe_driver_link_check, (void *)ixgbe, DDI_NOSLEEP))
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo != DDI_SUCCESS) {
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ixgbe_log(ixgbe, "Fail to dispatch taskq");
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo }
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo * check for fan failure on adapters with fans
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo if ((ixgbe->capab->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo (eicr & IXGBE_EICR_GPI_SDP1)) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ixgbe_log(ixgbe,
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo "Fan has stopped, replace the adapter\n");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo /* re-enable the interrupt, which was automasked */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ixgbe->eims |= IXGBE_EICR_GPI_SDP1;
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_intr_legacy - Interrupt handler for legacy interrupts.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic uint_t
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_intr_legacy(void *arg1, void *arg2)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_t *ixgbe = (ixgbe_t *)arg1;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_hw *hw = &ixgbe->hw;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_tx_ring_t *tx_ring;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe_rx_ring_t *rx_ring;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint32_t eicr;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mblk_t *mp;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt boolean_t tx_reschedule;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint_t result;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo _NOTE(ARGUNUSED(arg2));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_enter(&ixgbe->gen_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->ixgbe_state & IXGBE_SUSPENDED) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mutex_exit(&ixgbe->gen_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (DDI_INTR_UNCLAIMED);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt mp = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_reschedule = B_FALSE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Any bit set in eicr: claim this interrupt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (eicr) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * For legacy interrupt, we have only one interrupt,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * so we have only one rx ring and one tx ring enabled.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(ixgbe->num_rx_rings == 1);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(ixgbe->num_tx_rings == 1);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * For legacy interrupt, rx rings[0] will use RTxQ[0].
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (eicr & 0x1) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Clean the rx descriptors
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng rx_ring = &ixgbe->rx_rings[0];
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mp = ixgbe_ring_rx(rx_ring, IXGBE_POLL_NULL);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng /*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * For legacy interrupt, tx rings[0] will use RTxQ[1].
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (eicr & 0x2) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Recycle the tx descriptors
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring = &ixgbe->tx_rings[0];
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tx_recycle(tx_ring);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Schedule the re-transmit
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_reschedule = (tx_ring->reschedule &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (tx_ring->tbd_free >= tx_ring->resched_thresh));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo /* any interrupt type other than tx/rx */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo if (eicr & ixgbe->capab->other_intr) {
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ixgbe->eims &= ~(eicr & IXGBE_OTHER_INTR);
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ixgbe_intr_other_work(ixgbe, eicr);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo mutex_exit(&ixgbe->gen_lock);
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo
9da57d7b0ddd8d73b676ce12c040362132cdd538bt result = DDI_INTR_CLAIMED;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt } else {
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo mutex_exit(&ixgbe->gen_lock);
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * No interrupt cause bits set: don't claim this interrupt.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt result = DDI_INTR_UNCLAIMED;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo /* re-enable the interrupts which were automasked */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo IXGBE_WRITE_REG(hw, IXGBE_EIMS, ixgbe->eims);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Do the following work outside of the gen_lock
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (mp != NULL)
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mac_rx_ring(rx_ring->ixgbe->mac_hdl, rx_ring->ring_handle, mp,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng rx_ring->ring_gen_num);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (tx_reschedule) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->reschedule = B_FALSE;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mac_tx_ring_update(ixgbe->mac_hdl, tx_ring->ring_handle);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_DEBUG_STAT(tx_ring->stat_reschedule);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (result);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_intr_msi - Interrupt handler for MSI.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic uint_t
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_intr_msi(void *arg1, void *arg2)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_t *ixgbe = (ixgbe_t *)arg1;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_hw *hw = &ixgbe->hw;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint32_t eicr;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo _NOTE(ARGUNUSED(arg2));
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo
9da57d7b0ddd8d73b676ce12c040362132cdd538bt eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * For MSI interrupt, we have only one vector,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * so we have only one rx ring and one tx ring enabled.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(ixgbe->num_rx_rings == 1);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(ixgbe->num_tx_rings == 1);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * For MSI interrupt, rx rings[0] will use RTxQ[0].
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (eicr & 0x1) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_intr_rx_work(&ixgbe->rx_rings[0]);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng /*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * For MSI interrupt, tx rings[0] will use RTxQ[1].
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (eicr & 0x2) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_intr_tx_work(&ixgbe->tx_rings[0]);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo /* any interrupt type other than tx/rx */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo if (eicr & ixgbe->capab->other_intr) {
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo mutex_enter(&ixgbe->gen_lock);
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ixgbe->eims &= ~(eicr & IXGBE_OTHER_INTR);
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ixgbe_intr_other_work(ixgbe, eicr);
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo mutex_exit(&ixgbe->gen_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo /* re-enable the interrupts which were automasked */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo IXGBE_WRITE_REG(hw, IXGBE_EIMS, ixgbe->eims);
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (DDI_INTR_CLAIMED);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * ixgbe_intr_rx_tx - Interrupt handler for rx and tx.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic uint_t
da14cebe459d3275048785f25bd869cb09b5307fEric Chengixgbe_intr_rx_tx(void *arg1, void *arg2)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe_ring_vector_t *vect = (ixgbe_ring_vector_t *)arg1;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe_t *ixgbe = vect->ixgbe;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng int r_idx = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo _NOTE(ARGUNUSED(arg2));
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Clean each rx ring that has its bit set in the map
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt r_idx = bt_getlowbit(vect->rx_map, 0, (ixgbe->num_rx_rings - 1));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt while (r_idx >= 0) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_intr_rx_work(&ixgbe->rx_rings[r_idx]);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt r_idx = bt_getlowbit(vect->rx_map, (r_idx + 1),
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (ixgbe->num_rx_rings - 1));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng /*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Clean each tx ring that has its bit set in the map
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng r_idx = bt_getlowbit(vect->tx_map, 0, (ixgbe->num_tx_rings - 1));
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng while (r_idx >= 0) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe_intr_tx_work(&ixgbe->tx_rings[r_idx]);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng r_idx = bt_getlowbit(vect->tx_map, (r_idx + 1),
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng (ixgbe->num_tx_rings - 1));
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (DDI_INTR_CLAIMED);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * ixgbe_intr_other - Interrupt handler for other.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Only look for other work if the right bits are set in the
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Interrupt Cause Register.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic uint_t
da14cebe459d3275048785f25bd869cb09b5307fEric Chengixgbe_intr_other(void *arg1, void *arg2)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_t *ixgbe = (ixgbe_t *)arg1;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_hw *hw = &ixgbe->hw;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint32_t eicr;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo _NOTE(ARGUNUSED(arg2));
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo
9da57d7b0ddd8d73b676ce12c040362132cdd538bt eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo * Need check cause bits and only other causes will
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * be processed
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo /* any interrupt type other than tx/rx */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo if (eicr & ixgbe->capab->other_intr) {
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo mutex_enter(&ixgbe->gen_lock);
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ixgbe->eims &= ~(eicr & IXGBE_OTHER_INTR);
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ixgbe_intr_other_work(ixgbe, eicr);
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo mutex_exit(&ixgbe->gen_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo /* re-enable the interrupts which were automasked */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo IXGBE_WRITE_REG(hw, IXGBE_EIMS, ixgbe->eims);
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (DDI_INTR_CLAIMED);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_alloc_intrs - Allocate interrupts for the driver.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Normal sequence is to try MSI-X; if not sucessful, try MSI;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * if not successful, try Legacy.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe->intr_force can be used to force sequence to start with
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * any of the 3 types.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If MSI-X is not used, number of tx/rx rings is forced to 1.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_alloc_intrs(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt dev_info_t *devinfo;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int intr_types;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int rc;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt devinfo = ixgbe->dip;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Get supported interrupt types
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rc = ddi_intr_get_supported_types(devinfo, &intr_types);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (rc != DDI_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_log(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Get supported interrupt types failed: %d", rc);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_DEBUGLOG_1(ixgbe, "Supported interrupt types: %x", intr_types);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->intr_type = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Install MSI-X interrupts
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if ((intr_types & DDI_INTR_TYPE_MSIX) &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (ixgbe->intr_force <= IXGBE_INTR_MSIX)) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rc = ixgbe_alloc_intr_handles(ixgbe, DDI_INTR_TYPE_MSIX);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (rc == IXGBE_SUCCESS)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_SUCCESS);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_log(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Allocate MSI-X failed, trying MSI interrupts...");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * MSI-X not used, force rings and groups to 1
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->num_rx_rings = 1;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe->num_rx_groups = 1;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->num_tx_rings = 1;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_log(ixgbe,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng "MSI-X not used, force rings and groups number to 1");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Install MSI interrupts
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if ((intr_types & DDI_INTR_TYPE_MSI) &&
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (ixgbe->intr_force <= IXGBE_INTR_MSI)) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rc = ixgbe_alloc_intr_handles(ixgbe, DDI_INTR_TYPE_MSI);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (rc == IXGBE_SUCCESS)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_SUCCESS);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_log(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Allocate MSI failed, trying Legacy interrupts...");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Install legacy interrupts
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (intr_types & DDI_INTR_TYPE_FIXED) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rc = ixgbe_alloc_intr_handles(ixgbe, DDI_INTR_TYPE_FIXED);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (rc == IXGBE_SUCCESS)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_SUCCESS);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_log(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Allocate Legacy interrupts failed");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If none of the 3 types succeeded, return failure
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_alloc_intr_handles - Allocate interrupt handles.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * For legacy and MSI, only 1 handle is needed. For MSI-X,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * if fewer than 2 handles are available, return failure.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Upon success, this maps the vectors to rx and tx rings for
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * interrupts.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_alloc_intr_handles(ixgbe_t *ixgbe, int intr_type)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt dev_info_t *devinfo;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int request, count, avail, actual;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng int minimum;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int rc;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt devinfo = ixgbe->dip;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt switch (intr_type) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt case DDI_INTR_TYPE_FIXED:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt request = 1; /* Request 1 legacy interrupt handle */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt minimum = 1;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_DEBUGLOG_0(ixgbe, "interrupt type: legacy");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt break;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt case DDI_INTR_TYPE_MSI:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt request = 1; /* Request 1 MSI interrupt handle */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt minimum = 1;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_DEBUGLOG_0(ixgbe, "interrupt type: MSI");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt break;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt case DDI_INTR_TYPE_MSIX:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Best number of vectors for the adapter is
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * # rx rings + # tx rings + 1 for other.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng request = ixgbe->num_rx_rings + ixgbe->num_tx_rings + 1;
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo if (request > (ixgbe->capab->max_ring_vect + 1))
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo request = ixgbe->capab->max_ring_vect + 1;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt minimum = 2;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_DEBUGLOG_0(ixgbe, "interrupt type: MSI-X");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt break;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt default:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_log(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "invalid call to ixgbe_alloc_intr_handles(): %d\n",
9da57d7b0ddd8d73b676ce12c040362132cdd538bt intr_type);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_DEBUGLOG_2(ixgbe, "interrupt handles requested: %d minimum: %d",
9da57d7b0ddd8d73b676ce12c040362132cdd538bt request, minimum);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Get number of supported interrupts
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rc = ddi_intr_get_nintrs(devinfo, intr_type, &count);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if ((rc != DDI_SUCCESS) || (count < minimum)) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_log(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Get interrupt number failed. Return: %d, count: %d",
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rc, count);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_DEBUGLOG_1(ixgbe, "interrupts supported: %d", count);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Get number of available interrupts
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rc = ddi_intr_get_navail(devinfo, intr_type, &avail);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if ((rc != DDI_SUCCESS) || (avail < minimum)) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_log(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Get interrupt available number failed. "
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Return: %d, available: %d", rc, avail);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_DEBUGLOG_1(ixgbe, "interrupts available: %d", avail);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (avail < request) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_log(ixgbe, "Request %d handles, %d available",
9da57d7b0ddd8d73b676ce12c040362132cdd538bt request, avail);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt request = avail;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt actual = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->intr_cnt = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocate an array of interrupt handles
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->intr_size = request * sizeof (ddi_intr_handle_t);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->htable = kmem_alloc(ixgbe->intr_size, KM_SLEEP);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rc = ddi_intr_alloc(devinfo, ixgbe->htable, intr_type, 0,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt request, &actual, DDI_INTR_ALLOC_NORMAL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (rc != DDI_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_log(ixgbe, "Allocate interrupts failed. "
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "return: %d, request: %d, actual: %d",
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rc, request, actual);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto alloc_handle_fail;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_DEBUGLOG_1(ixgbe, "interrupts actually allocated: %d", actual);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->intr_cnt = actual;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Now we know the actual number of vectors. Here we map the vector
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * to other, rx rings and tx ring.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (actual < minimum) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_log(ixgbe, "Insufficient interrupt handles available: %d",
9da57d7b0ddd8d73b676ce12c040362132cdd538bt actual);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto alloc_handle_fail;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Get priority for first vector, assume remaining are all the same
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rc = ddi_intr_get_pri(ixgbe->htable[0], &ixgbe->intr_pri);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (rc != DDI_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_log(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Get interrupt priority failed: %d", rc);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto alloc_handle_fail;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rc = ddi_intr_get_cap(ixgbe->htable[0], &ixgbe->intr_cap);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (rc != DDI_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_log(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Get interrupt cap failed: %d", rc);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto alloc_handle_fail;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->intr_type = intr_type;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_SUCCESS);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btalloc_handle_fail:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_rem_intrs(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_add_intr_handlers - Add interrupt handlers based on the interrupt type.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Before adding the interrupt handlers, the interrupt vectors have
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * been allocated, and the rx/tx rings have also been allocated.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_add_intr_handlers(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng int vector = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int rc;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt switch (ixgbe->intr_type) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt case DDI_INTR_TYPE_MSIX:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Add interrupt handler for rx and tx rings: vector[0 -
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * (ixgbe->intr_cnt -1)].
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng for (vector = 0; vector < (ixgbe->intr_cnt -1); vector++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * install pointer to vect_map[vector]
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rc = ddi_intr_add_handler(ixgbe->htable[vector],
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng (ddi_intr_handler_t *)ixgbe_intr_rx_tx,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void *)&ixgbe->vect_map[vector], NULL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (rc != DDI_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_log(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Add rx interrupt handler failed. "
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng "return: %d, vector: %d", rc, vector);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (vector--; vector >= 0; vector--) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) ddi_intr_remove_handler(
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->htable[vector]);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng /*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Add interrupt handler for other: vector[ixgbe->intr_cnt -1]
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng rc = ddi_intr_add_handler(ixgbe->htable[vector],
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng (ddi_intr_handler_t *)ixgbe_intr_other,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng (void *)ixgbe, NULL);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (rc != DDI_SUCCESS) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe_log(ixgbe,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng "Add other interrupt handler failed: %d", rc);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
9da57d7b0ddd8d73b676ce12c040362132cdd538bt break;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt case DDI_INTR_TYPE_MSI:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Add interrupt handlers for the only vector
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rc = ddi_intr_add_handler(ixgbe->htable[vector],
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (ddi_intr_handler_t *)ixgbe_intr_msi,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void *)ixgbe, NULL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (rc != DDI_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_log(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Add MSI interrupt handler failed: %d", rc);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt break;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt case DDI_INTR_TYPE_FIXED:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Add interrupt handlers for the only vector
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rc = ddi_intr_add_handler(ixgbe->htable[vector],
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (ddi_intr_handler_t *)ixgbe_intr_legacy,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void *)ixgbe, NULL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (rc != DDI_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_log(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Add legacy interrupt handler failed: %d", rc);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt break;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt default:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ASSERT(vector == (ixgbe->intr_cnt -1));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_SUCCESS);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt#pragma inline(ixgbe_map_rxring_to_vector)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_map_rxring_to_vector - Map given rx ring to given interrupt vector.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_map_rxring_to_vector(ixgbe_t *ixgbe, int r_idx, int v_idx)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->vect_map[v_idx].ixgbe = ixgbe;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Set bit in map
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt BT_SET(ixgbe->vect_map[v_idx].rx_map, r_idx);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Count bits set
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->vect_map[v_idx].rxr_cnt++;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Remember bit position
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe->rx_rings[r_idx].intr_vector = v_idx;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->rx_rings[r_idx].vect_bit = 1 << v_idx;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt#pragma inline(ixgbe_map_txring_to_vector)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_map_txring_to_vector - Map given tx ring to given interrupt vector.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_map_txring_to_vector(ixgbe_t *ixgbe, int t_idx, int v_idx)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->vect_map[v_idx].ixgbe = ixgbe;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Set bit in map
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt BT_SET(ixgbe->vect_map[v_idx].tx_map, t_idx);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Count bits set
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->vect_map[v_idx].txr_cnt++;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Remember bit position
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe->tx_rings[t_idx].intr_vector = v_idx;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->tx_rings[t_idx].vect_bit = 1 << v_idx;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * ixgbe_setup_ivar - Set the given entry in the given interrupt vector
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * allocation register (IVAR).
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
da14cebe459d3275048785f25bd869cb09b5307fEric Chengixgbe_setup_ivar(ixgbe_t *ixgbe, uint16_t intr_alloc_entry, uint8_t msix_vector)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_hw *hw = &ixgbe->hw;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt u32 ivar, index;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt msix_vector |= IXGBE_IVAR_ALLOC_VAL;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng index = (intr_alloc_entry >> 2) & 0x1F;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ivar &= ~(0xFF << (8 * (intr_alloc_entry & 0x3)));
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ivar |= (msix_vector << (8 * (intr_alloc_entry & 0x3)));
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng}
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng/*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * ixgbe_enable_ivar - Enable the given entry by setting the VAL bit of
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * given interrupt vector allocation register (IVAR).
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng */
da14cebe459d3275048785f25bd869cb09b5307fEric Chengstatic void
da14cebe459d3275048785f25bd869cb09b5307fEric Chengixgbe_enable_ivar(ixgbe_t *ixgbe, uint16_t intr_alloc_entry)
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng{
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng struct ixgbe_hw *hw = &ixgbe->hw;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng u32 ivar, index;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng index = (intr_alloc_entry >> 2) & 0x1F;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ivar |= (IXGBE_IVAR_ALLOC_VAL << (8 * (intr_alloc_entry & 0x3)));
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng}
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng/*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * ixgbe_enable_ivar - Disble the given entry by clearing the VAL bit of
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * given interrupt vector allocation register (IVAR).
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng */
da14cebe459d3275048785f25bd869cb09b5307fEric Chengstatic void
da14cebe459d3275048785f25bd869cb09b5307fEric Chengixgbe_disable_ivar(ixgbe_t *ixgbe, uint16_t intr_alloc_entry)
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng{
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng struct ixgbe_hw *hw = &ixgbe->hw;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng u32 ivar, index;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng index = (intr_alloc_entry >> 2) & 0x1F;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ivar &= ~(IXGBE_IVAR_ALLOC_VAL << (8 * (intr_alloc_entry & 0x3)));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_map_rings_to_vectors - Map descriptor rings to interrupt vectors.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * For MSI-X, here will map rx and tx ring to vector[0 - (vectors -1)].
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * The last vector will be used for other interrupt.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_map_rings_to_vectors(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int i, vector = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /* initialize vector map */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt bzero(&ixgbe->vect_map, sizeof (ixgbe->vect_map));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * non-MSI-X case is very simple: rx rings[0] on RTxQ[0],
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * tx rings[0] on RTxQ[1].
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->intr_type != DDI_INTR_TYPE_MSIX) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_map_rxring_to_vector(ixgbe, 0, 0);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe_map_txring_to_vector(ixgbe, 0, 1);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_SUCCESS);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Ring/vector mapping for MSI-X
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Map vectors to rx rings
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng for (i = 0; i < ixgbe->num_rx_rings; i++) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe_map_rxring_to_vector(ixgbe, i, vector);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng vector = (vector +1) % (ixgbe->intr_cnt -1);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Map vectors to tx rings
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng for (i = 0; i < ixgbe->num_tx_rings; i++) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe_map_txring_to_vector(ixgbe, i, vector);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng vector = (vector +1) % (ixgbe->intr_cnt -1);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_SUCCESS);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_setup_adapter_vector - Setup the adapter interrupt vector(s).
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * This relies on ring/vector mapping already set up in the
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * vect_map[] structures
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_setup_adapter_vector(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_hw *hw = &ixgbe->hw;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe_ring_vector_t *vect; /* vector bitmap */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng int r_idx; /* ring index */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng int v_idx; /* vector index */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Clear any previous entries
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (v_idx = 0; v_idx < IXGBE_IVAR_REG_NUM; v_idx++)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_IVAR(v_idx), 0);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * For non MSI-X interrupt, rx rings[0] will use RTxQ[0], and
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * tx rings[0] will use RTxQ[1].
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (ixgbe->intr_type != DDI_INTR_TYPE_MSIX) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe_setup_ivar(ixgbe, IXGBE_IVAR_RX_QUEUE(0), 0);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe_setup_ivar(ixgbe, IXGBE_IVAR_TX_QUEUE(0), 1);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng return;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng /*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * For MSI-X interrupt, "Other" is always on last vector.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe_setup_ivar(ixgbe, IXGBE_IVAR_OTHER_CAUSES_INDEX,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng (ixgbe->intr_cnt - 1));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * For each interrupt vector, populate the IVAR table
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (v_idx = 0; v_idx < ixgbe->intr_cnt; v_idx++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt vect = &ixgbe->vect_map[v_idx];
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * For each rx ring bit set
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt r_idx = bt_getlowbit(vect->rx_map, 0,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (ixgbe->num_rx_rings - 1));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt while (r_idx >= 0) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe_setup_ivar(ixgbe, IXGBE_IVAR_RX_QUEUE(r_idx),
9da57d7b0ddd8d73b676ce12c040362132cdd538bt v_idx);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt r_idx = bt_getlowbit(vect->rx_map, (r_idx + 1),
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (ixgbe->num_rx_rings - 1));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * For each tx ring bit set
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt r_idx = bt_getlowbit(vect->tx_map, 0,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (ixgbe->num_tx_rings - 1));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt while (r_idx >= 0) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe_setup_ivar(ixgbe, IXGBE_IVAR_TX_QUEUE(r_idx),
9da57d7b0ddd8d73b676ce12c040362132cdd538bt v_idx);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt r_idx = bt_getlowbit(vect->tx_map, (r_idx + 1),
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (ixgbe->num_tx_rings - 1));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_rem_intr_handlers - Remove the interrupt handlers.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_rem_intr_handlers(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int i;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int rc;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < ixgbe->intr_cnt; i++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rc = ddi_intr_remove_handler(ixgbe->htable[i]);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (rc != DDI_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_DEBUGLOG_1(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Remove intr handler failed: %d", rc);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_rem_intrs - Remove the allocated interrupts.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_rem_intrs(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int i;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int rc;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < ixgbe->intr_cnt; i++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rc = ddi_intr_free(ixgbe->htable[i]);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (rc != DDI_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_DEBUGLOG_1(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Free intr failed: %d", rc);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt kmem_free(ixgbe->htable, ixgbe->intr_size);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->htable = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_enable_intrs - Enable all the ddi interrupts.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_enable_intrs(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int i;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int rc;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Enable interrupts
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->intr_cap & DDI_INTR_FLAG_BLOCK) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Call ddi_intr_block_enable() for MSI
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rc = ddi_intr_block_enable(ixgbe->htable, ixgbe->intr_cnt);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (rc != DDI_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_log(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Enable block intr failed: %d", rc);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt } else {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Call ddi_intr_enable() for Legacy/MSI non block enable
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < ixgbe->intr_cnt; i++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rc = ddi_intr_enable(ixgbe->htable[i]);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (rc != DDI_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_log(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Enable intr failed: %d", rc);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_SUCCESS);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_disable_intrs - Disable all the interrupts.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_disable_intrs(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int i;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int rc;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Disable all interrupts
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->intr_cap & DDI_INTR_FLAG_BLOCK) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rc = ddi_intr_block_disable(ixgbe->htable, ixgbe->intr_cnt);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (rc != DDI_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_log(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Disable block intr failed: %d", rc);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt } else {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < ixgbe->intr_cnt; i++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rc = ddi_intr_disable(ixgbe->htable[i]);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (rc != DDI_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_log(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Disable intr failed: %d", rc);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_SUCCESS);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_get_hw_state - Get and save parameters related to adapter hardware.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_get_hw_state(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt struct ixgbe_hw *hw = &ixgbe->hw;
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo ixgbe_link_speed speed = IXGBE_LINK_SPEED_UNKNOWN;
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo boolean_t link_up = B_FALSE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint32_t pcs1g_anlp = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint32_t pcs1g_ana = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(mutex_owned(&ixgbe->gen_lock));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->param_lp_1000fdx_cap = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->param_lp_100fdx_cap = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo /* check for link, don't wait */
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo (void) ixgbe_check_link(hw, &speed, &link_up, false);
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo if (link_up) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt pcs1g_anlp = IXGBE_READ_REG(hw, IXGBE_PCS1GANLP);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt pcs1g_ana = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->param_lp_1000fdx_cap =
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (pcs1g_anlp & IXGBE_PCS1GANLP_LPFD) ? 1 : 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->param_lp_100fdx_cap =
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (pcs1g_anlp & IXGBE_PCS1GANLP_LPFD) ? 1 : 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->param_1000fdx_cap = (pcs1g_ana & IXGBE_PCS1GANA_FDC) ? 1 : 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe->param_100fdx_cap = (pcs1g_ana & IXGBE_PCS1GANA_FDC) ? 1 : 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_get_driver_control - Notify that driver is in control of device.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_get_driver_control(struct ixgbe_hw *hw)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint32_t ctrl_ext;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Notify firmware that driver is in control of device
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ctrl_ext |= IXGBE_CTRL_EXT_DRV_LOAD;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_release_driver_control - Notify that driver is no longer in control
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * of device.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_release_driver_control(struct ixgbe_hw *hw)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint32_t ctrl_ext;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Notify firmware that driver is no longer in control of device
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ctrl_ext &= ~IXGBE_CTRL_EXT_DRV_LOAD;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_atomic_reserve - Atomic decrease operation.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btint
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_atomic_reserve(uint32_t *count_p, uint32_t n)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint32_t oldval;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint32_t newval;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ATOMICALLY
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt do {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt oldval = *count_p;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (oldval < n)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (-1);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt newval = oldval - n;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt } while (atomic_cas_32(count_p, oldval, newval) != oldval);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (newval);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_mc_table_itr - Traverse the entries in the multicast table.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic uint8_t *
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_mc_table_itr(struct ixgbe_hw *hw, uint8_t **upd_ptr, uint32_t *vmdq)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint8_t *addr = *upd_ptr;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint8_t *new_ptr;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo _NOTE(ARGUNUSED(hw));
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo _NOTE(ARGUNUSED(vmdq));
13740cb230f19fcbf1a6468d1a6a0ba9a0a09c22Paul Guo
9da57d7b0ddd8d73b676ce12c040362132cdd538bt new_ptr = addr + IXGBE_ETH_LENGTH_OF_ADDRESS;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *upd_ptr = new_ptr;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (addr);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * FMA support
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btint
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_check_acc_handle(ddi_acc_handle_t handle)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_fm_error_t de;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_fm_acc_err_get(handle, &de, DDI_FME_VERSION);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_fm_acc_err_clear(handle, DDI_FME_VERSION);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (de.fme_status);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btint
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_check_dma_handle(ddi_dma_handle_t handle)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_fm_error_t de;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_fm_dma_err_get(handle, &de, DDI_FME_VERSION);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (de.fme_status);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_fm_error_cb - The IO fault service error handling callback function.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_fm_error_cb(dev_info_t *dip, ddi_fm_error_t *err, const void *impl_data)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt _NOTE(ARGUNUSED(impl_data));
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * as the driver can always deal with an error in any dma or
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * access handle, we can just return the fme_status value.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt pci_ereport_post(dip, err, NULL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (err->fme_status);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_fm_init(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_iblock_cookie_t iblk;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int fma_acc_flag, fma_dma_flag;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Only register with IO Fault Services if we have some capability
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->fm_capabilities & DDI_FM_ACCCHK_CAPABLE) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_regs_acc_attr.devacc_attr_access = DDI_FLAGERR_ACC;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt fma_acc_flag = 1;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt } else {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_regs_acc_attr.devacc_attr_access = DDI_DEFAULT_ACC;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt fma_acc_flag = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->fm_capabilities & DDI_FM_DMACHK_CAPABLE) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt fma_dma_flag = 1;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt } else {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt fma_dma_flag = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_set_fma_flags(fma_acc_flag, fma_dma_flag);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->fm_capabilities) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Register capabilities with IO Fault Services
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_fm_init(ixgbe->dip, &ixgbe->fm_capabilities, &iblk);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Initialize pci ereport capabilities if ereport capable
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (DDI_FM_EREPORT_CAP(ixgbe->fm_capabilities) ||
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DDI_FM_ERRCB_CAP(ixgbe->fm_capabilities))
9da57d7b0ddd8d73b676ce12c040362132cdd538bt pci_ereport_setup(ixgbe->dip);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Register error callback if error callback capable
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (DDI_FM_ERRCB_CAP(ixgbe->fm_capabilities))
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_fm_handler_register(ixgbe->dip,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_fm_error_cb, (void*) ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_fm_fini(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Only unregister FMA capabilities if they are registered
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->fm_capabilities) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Release any resources allocated by pci_ereport_setup()
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (DDI_FM_EREPORT_CAP(ixgbe->fm_capabilities) ||
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DDI_FM_ERRCB_CAP(ixgbe->fm_capabilities))
9da57d7b0ddd8d73b676ce12c040362132cdd538bt pci_ereport_teardown(ixgbe->dip);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Un-register error callback if error callback capable
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (DDI_FM_ERRCB_CAP(ixgbe->fm_capabilities))
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_fm_handler_unregister(ixgbe->dip);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Unregister from IO Fault Service
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_fm_fini(ixgbe->dip);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btvoid
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_fm_ereport(ixgbe_t *ixgbe, char *detail)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint64_t ena;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt char buf[FM_MAX_CLASS];
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) snprintf(buf, FM_MAX_CLASS, "%s.%s", DDI_FM_DEVICE, detail);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ena = fm_ena_generate(0, FM_ENA_FMT1);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (DDI_FM_EREPORT_CAP(ixgbe->fm_capabilities)) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_fm_ereport_post(ixgbe->dip, buf, ena, DDI_NOSLEEP,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt FM_VERSION, DATA_TYPE_UINT8, FM_EREPORT_VERS0, NULL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Chengstatic int
da14cebe459d3275048785f25bd869cb09b5307fEric Chengixgbe_ring_start(mac_ring_driver_t rh, uint64_t mr_gen_num)
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng{
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe_rx_ring_t *rx_ring = (ixgbe_rx_ring_t *)rh;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mutex_enter(&rx_ring->rx_lock);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng rx_ring->ring_gen_num = mr_gen_num;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mutex_exit(&rx_ring->rx_lock);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng return (0);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng}
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng/*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Callback funtion for MAC layer to register all rings.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng/* ARGSUSED */
da14cebe459d3275048785f25bd869cb09b5307fEric Chengvoid
da14cebe459d3275048785f25bd869cb09b5307fEric Chengixgbe_fill_ring(void *arg, mac_ring_type_t rtype, const int rg_index,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng const int ring_index, mac_ring_info_t *infop, mac_ring_handle_t rh)
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng{
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe_t *ixgbe = (ixgbe_t *)arg;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mac_intr_t *mintr = &infop->mri_intr;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng switch (rtype) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng case MAC_RING_TYPE_RX: {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ASSERT(rg_index == 0);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ASSERT(ring_index < ixgbe->num_rx_rings);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe_rx_ring_t *rx_ring = &ixgbe->rx_rings[ring_index];
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng rx_ring->ring_handle = rh;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng infop->mri_driver = (mac_ring_driver_t)rx_ring;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng infop->mri_start = ixgbe_ring_start;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng infop->mri_stop = NULL;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng infop->mri_poll = ixgbe_ring_rx_poll;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mintr->mi_handle = (mac_intr_handle_t)rx_ring;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mintr->mi_enable = ixgbe_rx_ring_intr_enable;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mintr->mi_disable = ixgbe_rx_ring_intr_disable;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng break;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng case MAC_RING_TYPE_TX: {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ASSERT(rg_index == -1);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ASSERT(ring_index < ixgbe->num_tx_rings);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe_tx_ring_t *tx_ring = &ixgbe->tx_rings[ring_index];
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng tx_ring->ring_handle = rh;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng infop->mri_driver = (mac_ring_driver_t)tx_ring;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng infop->mri_start = NULL;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng infop->mri_stop = NULL;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng infop->mri_tx = ixgbe_ring_tx;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng break;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng default:
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng break;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng}
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng/*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Callback funtion for MAC layer to register all groups.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng */
da14cebe459d3275048785f25bd869cb09b5307fEric Chengvoid
da14cebe459d3275048785f25bd869cb09b5307fEric Chengixgbe_fill_group(void *arg, mac_ring_type_t rtype, const int index,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mac_group_info_t *infop, mac_group_handle_t gh)
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng{
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe_t *ixgbe = (ixgbe_t *)arg;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng switch (rtype) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng case MAC_RING_TYPE_RX: {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe_rx_group_t *rx_group;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng rx_group = &ixgbe->rx_groups[index];
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng rx_group->group_handle = gh;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng infop->mgi_driver = (mac_group_driver_t)rx_group;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng infop->mgi_start = NULL;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng infop->mgi_stop = NULL;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng infop->mgi_addmac = ixgbe_addmac;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng infop->mgi_remmac = ixgbe_remmac;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng infop->mgi_count = (ixgbe->num_rx_rings / ixgbe->num_rx_groups);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng break;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng case MAC_RING_TYPE_TX:
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng break;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng default:
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng break;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng}
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng/*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Enable interrupt on the specificed rx ring.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng */
da14cebe459d3275048785f25bd869cb09b5307fEric Chengint
da14cebe459d3275048785f25bd869cb09b5307fEric Chengixgbe_rx_ring_intr_enable(mac_intr_handle_t intrh)
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng{
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe_rx_ring_t *rx_ring = (ixgbe_rx_ring_t *)intrh;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe_t *ixgbe = rx_ring->ixgbe;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng int r_idx = rx_ring->index;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng int v_idx = rx_ring->intr_vector;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mutex_enter(&ixgbe->gen_lock);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ASSERT(BT_TEST(ixgbe->vect_map[v_idx].rx_map, r_idx) == 0);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng /*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * To enable interrupt by setting the VAL bit of given interrupt
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * vector allocation register (IVAR).
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe_enable_ivar(ixgbe, IXGBE_IVAR_RX_QUEUE(r_idx));
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng BT_SET(ixgbe->vect_map[v_idx].rx_map, r_idx);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mutex_exit(&ixgbe->gen_lock);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng return (0);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng}
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng/*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Disable interrupt on the specificed rx ring.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng */
da14cebe459d3275048785f25bd869cb09b5307fEric Chengint
da14cebe459d3275048785f25bd869cb09b5307fEric Chengixgbe_rx_ring_intr_disable(mac_intr_handle_t intrh)
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng{
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe_rx_ring_t *rx_ring = (ixgbe_rx_ring_t *)intrh;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe_t *ixgbe = rx_ring->ixgbe;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng int r_idx = rx_ring->index;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng int v_idx = rx_ring->intr_vector;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mutex_enter(&ixgbe->gen_lock);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ASSERT(BT_TEST(ixgbe->vect_map[v_idx].rx_map, r_idx) == 1);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng /*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * To disable interrupt by clearing the VAL bit of given interrupt
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * vector allocation register (IVAR).
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe_disable_ivar(ixgbe, IXGBE_IVAR_RX_QUEUE(r_idx));
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng BT_CLEAR(ixgbe->vect_map[v_idx].rx_map, r_idx);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mutex_exit(&ixgbe->gen_lock);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng return (0);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng}
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng/*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Add a mac address.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng */
da14cebe459d3275048785f25bd869cb09b5307fEric Chengstatic int
da14cebe459d3275048785f25bd869cb09b5307fEric Chengixgbe_addmac(void *arg, const uint8_t *mac_addr)
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng{
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe_rx_group_t *rx_group = (ixgbe_rx_group_t *)arg;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe_t *ixgbe = rx_group->ixgbe;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng int slot;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng int err;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mutex_enter(&ixgbe->gen_lock);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (ixgbe->ixgbe_state & IXGBE_SUSPENDED) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mutex_exit(&ixgbe->gen_lock);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng return (ECANCELED);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (ixgbe->unicst_avail == 0) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng /* no slots available */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mutex_exit(&ixgbe->gen_lock);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng return (ENOSPC);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng for (slot = 0; slot < ixgbe->unicst_total; slot++) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (ixgbe->unicst_addr[slot].mac.set == 0)
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng break;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ASSERT((slot >= 0) && (slot < ixgbe->unicst_total));
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if ((err = ixgbe_unicst_set(ixgbe, mac_addr, slot)) == 0) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe->unicst_addr[slot].mac.set = 1;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe->unicst_avail--;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mutex_exit(&ixgbe->gen_lock);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng return (err);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng}
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng/*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Remove a mac address.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng */
da14cebe459d3275048785f25bd869cb09b5307fEric Chengstatic int
da14cebe459d3275048785f25bd869cb09b5307fEric Chengixgbe_remmac(void *arg, const uint8_t *mac_addr)
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng{
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe_rx_group_t *rx_group = (ixgbe_rx_group_t *)arg;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe_t *ixgbe = rx_group->ixgbe;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng int slot;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng int err;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mutex_enter(&ixgbe->gen_lock);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (ixgbe->ixgbe_state & IXGBE_SUSPENDED) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mutex_exit(&ixgbe->gen_lock);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng return (ECANCELED);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng slot = ixgbe_unicst_find(ixgbe, mac_addr);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (slot == -1) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mutex_exit(&ixgbe->gen_lock);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng return (EINVAL);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (ixgbe->unicst_addr[slot].mac.set == 0) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mutex_exit(&ixgbe->gen_lock);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng return (EINVAL);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng bzero(ixgbe->unicst_addr[slot].mac.addr, ETHERADDRL);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if ((err = ixgbe_unicst_set(ixgbe,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe->unicst_addr[slot].mac.addr, slot)) == 0) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe->unicst_addr[slot].mac.set = 0;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng ixgbe->unicst_avail++;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng }
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng mutex_exit(&ixgbe->gen_lock);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng return (err);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng}