Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/ixl/if_ixl.c
/****************************************************************************** | /****************************************************************************** | ||||
Copyright (c) 2013-2015, Intel Corporation | Copyright (c) 2013-2017, Intel Corporation | ||||
All rights reserved. | All rights reserved. | ||||
Redistribution and use in source and binary forms, with or without | Redistribution and use in source and binary forms, with or without | ||||
modification, are permitted provided that the following conditions are met: | modification, are permitted provided that the following conditions are met: | ||||
1. Redistributions of source code must retain the above copyright notice, | 1. Redistributions of source code must retain the above copyright notice, | ||||
this list of conditions and the following disclaimer. | this list of conditions and the following disclaimer. | ||||
Show All 15 Lines | /****************************************************************************** | ||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||||
POSSIBILITY OF SUCH DAMAGE. | POSSIBILITY OF SUCH DAMAGE. | ||||
******************************************************************************/ | ******************************************************************************/ | ||||
/*$FreeBSD$*/ | /*$FreeBSD$*/ | ||||
#include "opt_inet.h" | |||||
#include "opt_inet6.h" | |||||
#include "opt_rss.h" | |||||
#include "ixl.h" | #include "ixl.h" | ||||
#include "ixl_pf.h" | #include "ixl_pf.h" | ||||
#ifdef IXL_IW | #include "ifdi_if.h" | ||||
#include "ixl_iw.h" | |||||
#include "ixl_iw_int.h" | |||||
#endif | |||||
#ifdef PCI_IOV | #ifdef PCI_IOV | ||||
#include "ixl_pf_iov.h" | #include "ixl_pf_iov.h" | ||||
#endif | #endif | ||||
/********************************************************************* | /********************************************************************* | ||||
* Driver version | * Driver version | ||||
*********************************************************************/ | *********************************************************************/ | ||||
char ixl_driver_version[] = "1.7.12-k"; | char ixl_driver_version[] = "1.6.6-iflib-k"; | ||||
/********************************************************************* | /********************************************************************* | ||||
* PCI Device ID Table | * PCI Device ID Table | ||||
* | * | ||||
* Used by probe to select devices to load on | * Used by probe to select devices to load on | ||||
* Last field stores an index into ixl_strings | * Last field stores an index into ixl_strings | ||||
* Last entry must be all 0s | * Last entry must be all 0s | ||||
* | * | ||||
* { Vendor ID, Device ID, SubVendor ID, SubDevice ID, String Index } | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, String Index } | ||||
*********************************************************************/ | *********************************************************************/ | ||||
static ixl_vendor_info_t ixl_vendor_info_array[] = | static pci_vendor_info_t ixl_vendor_info_array[] = | ||||
{ | { | ||||
{I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_XL710, 0, 0, 0}, | PVID(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_XL710, "Intel(R) Ethernet Connection 7 Series Driver"), | ||||
{I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_B, 0, 0, 0}, | PVID(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_B, "Intel(R) Ethernet Connection 7 Series Driver"), | ||||
{I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_C, 0, 0, 0}, | PVID(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_C, "Intel(R) Ethernet Connection 7 Series Driver"), | ||||
{I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_A, 0, 0, 0}, | PVID(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_A, "Intel(R) Ethernet Connection 7 Series Driver"), | ||||
{I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_B, 0, 0, 0}, | PVID(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_B, "Intel(R) Ethernet Connection 7 Series Driver"), | ||||
{I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_C, 0, 0, 0}, | PVID(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_C, "Intel(R) Ethernet Connection 7 Series Driver"), | ||||
{I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T, 0, 0, 0}, | PVID(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T, "Intel(R) Ethernet Connection 7 Series Driver"), | ||||
{I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T4, 0, 0, 0}, | PVID(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T4, "Intel(R) Ethernet Connection 7 Series Driver"), | ||||
{I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_X722, 0, 0, 0}, | PVID(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_X722, "Intel(R) Ethernet Connection 7 Series Driver"), | ||||
{I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_X722, 0, 0, 0}, | PVID(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_X722, "Intel(R) Ethernet Connection 7 Series Driver"), | ||||
{I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_X722, 0, 0, 0}, | PVID(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_X722, "Intel(R) Ethernet Connection 7 Series Driver"), | ||||
{I40E_INTEL_VENDOR_ID, I40E_DEV_ID_1G_BASE_T_X722, 0, 0, 0}, | PVID(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_1G_BASE_T_X722, "Intel(R) Ethernet Connection 7 Series Driver"), | ||||
{I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T_X722, 0, 0, 0}, | PVID(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T_X722, "Intel(R) Ethernet Connection 7 Series Driver"), | ||||
{I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_I_X722, 0, 0, 0}, | PVID(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_I_X722, "Intel(R) Ethernet Connection 7 Series Driver"), | ||||
{I40E_INTEL_VENDOR_ID, I40E_DEV_ID_25G_B, 0, 0, 0}, | |||||
{I40E_INTEL_VENDOR_ID, I40E_DEV_ID_25G_SFP28, 0, 0, 0}, | |||||
/* required last entry */ | /* required last entry */ | ||||
{0, 0, 0, 0, 0} | PVID_END | ||||
}; | }; | ||||
/********************************************************************* | /********************************************************************* | ||||
* Table of branding strings | |||||
*********************************************************************/ | |||||
static char *ixl_strings[] = { | |||||
"Intel(R) Ethernet Connection XL710/X722 Driver" | |||||
}; | |||||
/********************************************************************* | |||||
* Function prototypes | * Function prototypes | ||||
*********************************************************************/ | *********************************************************************/ | ||||
static int ixl_probe(device_t); | |||||
static int ixl_attach(device_t); | |||||
static int ixl_detach(device_t); | |||||
static int ixl_shutdown(device_t); | |||||
/*** IFLIB interface ***/ | |||||
static void *ixl_register(device_t dev); | |||||
static int ixl_if_attach_pre(if_ctx_t ctx); | |||||
static int ixl_if_attach_post(if_ctx_t ctx); | |||||
static int ixl_if_detach(if_ctx_t ctx); | |||||
static int ixl_if_shutdown(if_ctx_t ctx); | |||||
static int ixl_if_suspend(if_ctx_t ctx); | |||||
static int ixl_if_resume(if_ctx_t ctx); | |||||
static int ixl_if_msix_intr_assign(if_ctx_t ctx, int msix); | |||||
static void ixl_if_enable_intr(if_ctx_t ctx); | |||||
static void ixl_if_disable_intr(if_ctx_t ctx); | |||||
static int ixl_if_queue_intr_enable(if_ctx_t ctx, uint16_t rxqid); | |||||
static int ixl_if_tx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, uint64_t *paddrs, int ntxqs, int ntxqsets); | |||||
static int ixl_if_rx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, uint64_t *paddrs, int nqs, int nqsets); | |||||
static void ixl_if_queues_free(if_ctx_t ctx); | |||||
static void ixl_if_update_admin_status(if_ctx_t ctx); | |||||
static void ixl_if_multi_set(if_ctx_t ctx); | |||||
static int ixl_if_mtu_set(if_ctx_t ctx, uint32_t mtu); | |||||
static void ixl_if_media_status(if_ctx_t ctx, struct ifmediareq *ifmr); | |||||
static int ixl_if_media_change(if_ctx_t ctx); | |||||
static int ixl_if_promisc_set(if_ctx_t ctx, int flags); | |||||
static void ixl_if_timer(if_ctx_t ctx, uint16_t qid); | |||||
static void ixl_if_vlan_register(if_ctx_t ctx, u16 vtag); | |||||
static void ixl_if_vlan_unregister(if_ctx_t ctx, u16 vtag); | |||||
static uint64_t ixl_if_get_counter(if_ctx_t ctx, ift_counter cnt); | |||||
/*** Other ***/ | |||||
static int ixl_mc_filter_apply(void *arg, struct ifmultiaddr *ifma, int); | |||||
static int ixl_save_pf_tunables(struct ixl_pf *); | static int ixl_save_pf_tunables(struct ixl_pf *); | ||||
static int ixl_attach_get_link_status(struct ixl_pf *); | static int ixl_attach_get_link_status(struct ixl_pf *); | ||||
static int ixl_allocate_pci_resources(struct ixl_pf *); | |||||
/********************************************************************* | /********************************************************************* | ||||
* FreeBSD Device Interface Entry Points | * FreeBSD Device Interface Entry Points | ||||
*********************************************************************/ | *********************************************************************/ | ||||
static device_method_t ixl_methods[] = { | static device_method_t ixl_methods[] = { | ||||
/* Device interface */ | /* Device interface */ | ||||
DEVMETHOD(device_probe, ixl_probe), | DEVMETHOD(device_register, ixl_register), | ||||
DEVMETHOD(device_attach, ixl_attach), | DEVMETHOD(device_probe, iflib_device_probe), | ||||
DEVMETHOD(device_detach, ixl_detach), | DEVMETHOD(device_attach, iflib_device_attach), | ||||
DEVMETHOD(device_shutdown, ixl_shutdown), | DEVMETHOD(device_detach, iflib_device_detach), | ||||
DEVMETHOD(device_shutdown, iflib_device_shutdown), | |||||
#ifdef PCI_IOV | #ifdef PCI_IOV | ||||
DEVMETHOD(pci_iov_init, ixl_iov_init), | DEVMETHOD(pci_iov_init, ixl_iov_init), | ||||
DEVMETHOD(pci_iov_uninit, ixl_iov_uninit), | DEVMETHOD(pci_iov_uninit, ixl_iov_uninit), | ||||
DEVMETHOD(pci_iov_add_vf, ixl_add_vf), | DEVMETHOD(pci_iov_add_vf, ixl_add_vf), | ||||
#endif | #endif | ||||
{0, 0} | DEVMETHOD_END | ||||
}; | }; | ||||
static driver_t ixl_driver = { | static driver_t ixl_driver = { | ||||
"ixl", ixl_methods, sizeof(struct ixl_pf), | "ixl", ixl_methods, sizeof(struct ixl_pf), | ||||
}; | }; | ||||
devclass_t ixl_devclass; | devclass_t ixl_devclass; | ||||
DRIVER_MODULE(ixl, pci, ixl_driver, ixl_devclass, 0, 0); | DRIVER_MODULE(ixl, pci, ixl_driver, ixl_devclass, 0, 0); | ||||
MODULE_VERSION(ixl, 1); | |||||
MODULE_DEPEND(ixl, pci, 1, 1, 1); | MODULE_DEPEND(ixl, pci, 1, 1, 1); | ||||
MODULE_DEPEND(ixl, ether, 1, 1, 1); | MODULE_DEPEND(ixl, ether, 1, 1, 1); | ||||
#if defined(DEV_NETMAP) && __FreeBSD_version >= 1100000 | MODULE_DEPEND(ixl, iflib, 1, 1, 1); | ||||
MODULE_DEPEND(ixl, netmap, 1, 1, 1); | |||||
#endif /* DEV_NETMAP */ | |||||
/* | static device_method_t ixl_if_methods[] = { | ||||
DEVMETHOD(ifdi_attach_pre, ixl_if_attach_pre), | |||||
DEVMETHOD(ifdi_attach_post, ixl_if_attach_post), | |||||
DEVMETHOD(ifdi_detach, ixl_if_detach), | |||||
DEVMETHOD(ifdi_shutdown, ixl_if_shutdown), | |||||
DEVMETHOD(ifdi_suspend, ixl_if_suspend), | |||||
DEVMETHOD(ifdi_resume, ixl_if_resume), | |||||
DEVMETHOD(ifdi_init, ixl_if_init), | |||||
DEVMETHOD(ifdi_stop, ixl_if_stop), | |||||
DEVMETHOD(ifdi_msix_intr_assign, ixl_if_msix_intr_assign), | |||||
DEVMETHOD(ifdi_intr_enable, ixl_if_enable_intr), | |||||
DEVMETHOD(ifdi_intr_disable, ixl_if_disable_intr), | |||||
DEVMETHOD(ifdi_queue_intr_enable, ixl_if_queue_intr_enable), | |||||
DEVMETHOD(ifdi_tx_queues_alloc, ixl_if_tx_queues_alloc), | |||||
DEVMETHOD(ifdi_rx_queues_alloc, ixl_if_rx_queues_alloc), | |||||
DEVMETHOD(ifdi_queues_free, ixl_if_queues_free), | |||||
DEVMETHOD(ifdi_update_admin_status, ixl_if_update_admin_status), | |||||
DEVMETHOD(ifdi_multi_set, ixl_if_multi_set), | |||||
DEVMETHOD(ifdi_mtu_set, ixl_if_mtu_set), | |||||
// DEVMETHOD(ifdi_crcstrip_set, ixl_if_crcstrip_set), | |||||
DEVMETHOD(ifdi_media_status, ixl_if_media_status), | |||||
DEVMETHOD(ifdi_media_change, ixl_if_media_change), | |||||
DEVMETHOD(ifdi_promisc_set, ixl_if_promisc_set), | |||||
DEVMETHOD(ifdi_timer, ixl_if_timer), | |||||
DEVMETHOD(ifdi_vlan_register, ixl_if_vlan_register), | |||||
DEVMETHOD(ifdi_vlan_unregister, ixl_if_vlan_unregister), | |||||
DEVMETHOD(ifdi_get_counter, ixl_if_get_counter), | |||||
DEVMETHOD_END | |||||
}; | |||||
static driver_t ixl_if_driver = { | |||||
"ixl_if", ixl_if_methods, sizeof(struct ixl_pf) | |||||
}; | |||||
/***************************************************************************** | |||||
** TUNEABLE PARAMETERS: | ** TUNEABLE PARAMETERS: | ||||
*/ | *****************************************************************************/ | ||||
static SYSCTL_NODE(_hw, OID_AUTO, ixl, CTLFLAG_RD, 0, | static SYSCTL_NODE(_hw, OID_AUTO, ixl, CTLFLAG_RD, 0, | ||||
"IXL driver parameters"); | "IXL driver parameters"); | ||||
/* | /* | ||||
* MSIX should be the default for best performance, | * MSIX should be the default for best performance, | ||||
* but this allows it to be forced off for testing. | * but this allows it to be forced off for testing. | ||||
*/ | */ | ||||
static int ixl_enable_msix = 1; | static int ixl_enable_msix = 1; | ||||
TUNABLE_INT("hw.ixl.enable_msix", &ixl_enable_msix); | TUNABLE_INT("hw.ixl.enable_msix", &ixl_enable_msix); | ||||
SYSCTL_INT(_hw_ixl, OID_AUTO, enable_msix, CTLFLAG_RDTUN, &ixl_enable_msix, 0, | SYSCTL_INT(_hw_ixl, OID_AUTO, enable_msix, CTLFLAG_RDTUN, &ixl_enable_msix, 0, | ||||
"Enable MSI-X interrupts"); | "Enable MSI-X interrupts"); | ||||
/* | /* | ||||
** Number of descriptors per ring: | ** Number of descriptors per ring: | ||||
** - TX and RX are the same size | ** - TX and RX are the same size | ||||
*/ | */ | ||||
static int ixl_ring_size = IXL_DEFAULT_RING; | static int ixl_ring_size = DEFAULT_RING; | ||||
TUNABLE_INT("hw.ixl.ring_size", &ixl_ring_size); | TUNABLE_INT("hw.ixl.ring_size", &ixl_ring_size); | ||||
SYSCTL_INT(_hw_ixl, OID_AUTO, ring_size, CTLFLAG_RDTUN, | SYSCTL_INT(_hw_ixl, OID_AUTO, ring_size, CTLFLAG_RDTUN, | ||||
&ixl_ring_size, 0, "Descriptor Ring Size"); | &ixl_ring_size, 0, "Descriptor Ring Size"); | ||||
/* | /* | ||||
** This can be set manually, if left as 0 the | ** This can be set manually, if left as 0 the | ||||
** number of queues will be calculated based | ** number of queues will be calculated based | ||||
** on cpus and msix vectors available. | ** on cpus and msix vectors available. | ||||
Show All 24 Lines | SYSCTL_INT(_hw_ixl, OID_AUTO, shared_debug_mask, CTLFLAG_RDTUN, | ||||
&ixl_shared_debug_mask, 0, | &ixl_shared_debug_mask, 0, | ||||
"Display debug statements that are printed in shared code"); | "Display debug statements that are printed in shared code"); | ||||
/* | /* | ||||
** Controls for Interrupt Throttling | ** Controls for Interrupt Throttling | ||||
** - true/false for dynamic adjustment | ** - true/false for dynamic adjustment | ||||
** - default values for static ITR | ** - default values for static ITR | ||||
*/ | */ | ||||
static int ixl_dynamic_rx_itr = 1; | static int ixl_dynamic_rx_itr = 0; | ||||
TUNABLE_INT("hw.ixl.dynamic_rx_itr", &ixl_dynamic_rx_itr); | TUNABLE_INT("hw.ixl.dynamic_rx_itr", &ixl_dynamic_rx_itr); | ||||
SYSCTL_INT(_hw_ixl, OID_AUTO, dynamic_rx_itr, CTLFLAG_RDTUN, | SYSCTL_INT(_hw_ixl, OID_AUTO, dynamic_rx_itr, CTLFLAG_RDTUN, | ||||
&ixl_dynamic_rx_itr, 0, "Dynamic RX Interrupt Rate"); | &ixl_dynamic_rx_itr, 0, "Dynamic RX Interrupt Rate"); | ||||
#if 0 | |||||
static int ixl_dynamic_tx_itr = 1; | static int ixl_dynamic_tx_itr = 1; | ||||
TUNABLE_INT("hw.ixl.dynamic_tx_itr", &ixl_dynamic_tx_itr); | TUNABLE_INT("hw.ixl.dynamic_tx_itr", &ixl_dynamic_tx_itr); | ||||
SYSCTL_INT(_hw_ixl, OID_AUTO, dynamic_tx_itr, CTLFLAG_RDTUN, | SYSCTL_INT(_hw_ixl, OID_AUTO, dynamic_tx_itr, CTLFLAG_RDTUN, | ||||
&ixl_dynamic_tx_itr, 0, "Dynamic TX Interrupt Rate"); | &ixl_dynamic_tx_itr, 0, "Dynamic TX Interrupt Rate"); | ||||
#endif | |||||
static int ixl_rx_itr = IXL_ITR_8K; | static int ixl_rx_itr = IXL_ITR_8K; | ||||
TUNABLE_INT("hw.ixl.rx_itr", &ixl_rx_itr); | TUNABLE_INT("hw.ixl.rx_itr", &ixl_rx_itr); | ||||
SYSCTL_INT(_hw_ixl, OID_AUTO, rx_itr, CTLFLAG_RDTUN, | SYSCTL_INT(_hw_ixl, OID_AUTO, rx_itr, CTLFLAG_RDTUN, | ||||
&ixl_rx_itr, 0, "RX Interrupt Rate"); | &ixl_rx_itr, 0, "RX Interrupt Rate"); | ||||
#if 0 | |||||
static int ixl_tx_itr = IXL_ITR_4K; | static int ixl_tx_itr = IXL_ITR_4K; | ||||
TUNABLE_INT("hw.ixl.tx_itr", &ixl_tx_itr); | TUNABLE_INT("hw.ixl.tx_itr", &ixl_tx_itr); | ||||
SYSCTL_INT(_hw_ixl, OID_AUTO, tx_itr, CTLFLAG_RDTUN, | SYSCTL_INT(_hw_ixl, OID_AUTO, tx_itr, CTLFLAG_RDTUN, | ||||
&ixl_tx_itr, 0, "TX Interrupt Rate"); | &ixl_tx_itr, 0, "TX Interrupt Rate"); | ||||
#ifdef IXL_IW | |||||
int ixl_enable_iwarp = 0; | |||||
TUNABLE_INT("hw.ixl.enable_iwarp", &ixl_enable_iwarp); | |||||
#endif | #endif | ||||
#ifdef DEV_NETMAP | extern struct if_txrx ixl_txrx; | ||||
#define NETMAP_IXL_MAIN /* only bring in one part of the netmap code */ | |||||
#include <dev/netmap/if_ixl_netmap.h> | |||||
#endif /* DEV_NETMAP */ | |||||
/********************************************************************* | static struct if_shared_ctx ixl_sctx_init = { | ||||
* Device identification routine | .isc_magic = IFLIB_MAGIC, | ||||
* | .isc_q_align = PAGE_SIZE,/* max(DBA_ALIGN, PAGE_SIZE) */ | ||||
* ixl_probe determines if the driver should be loaded on | .isc_tx_maxsize = IXL_TSO_SIZE, | ||||
* the hardware based on PCI vendor/device id of the device. | |||||
* | |||||
* return BUS_PROBE_DEFAULT on success, positive on failure | |||||
*********************************************************************/ | |||||
static int | .isc_tx_maxsegsize = PAGE_SIZE, | ||||
ixl_probe(device_t dev) | |||||
{ | |||||
ixl_vendor_info_t *ent; | |||||
u16 pci_vendor_id, pci_device_id; | // TODO: Review the rx_maxsize and rx_maxsegsize params | ||||
u16 pci_subvendor_id, pci_subdevice_id; | // Where are they used in iflib? | ||||
char device_name[256]; | .isc_rx_maxsize = 16384, | ||||
.isc_rx_nsegments = 1, | |||||
.isc_rx_maxsegsize = 16384, | |||||
// TODO: What is isc_nfl for? | |||||
.isc_nfl = 1, | |||||
.isc_ntxqs = 1, | |||||
.isc_nrxqs = 1, | |||||
#if 0 | .isc_admin_intrcnt = 1, | ||||
INIT_DEBUGOUT("ixl_probe: begin"); | .isc_vendor_info = ixl_vendor_info_array, | ||||
#endif | .isc_driver_version = ixl_driver_version, | ||||
pci_vendor_id = pci_get_vendor(dev); | .isc_driver = &ixl_if_driver, | ||||
if (pci_vendor_id != I40E_INTEL_VENDOR_ID) | |||||
return (ENXIO); | |||||
pci_device_id = pci_get_device(dev); | .isc_nrxd_min = {IXL_MIN_RING}, | ||||
pci_subvendor_id = pci_get_subvendor(dev); | .isc_ntxd_min = {IXL_MIN_RING}, | ||||
pci_subdevice_id = pci_get_subdevice(dev); | .isc_nrxd_max = {IXL_MAX_RING}, | ||||
.isc_ntxd_max = {IXL_MAX_RING}, | |||||
.isc_nrxd_default = {DEFAULT_RING}, | |||||
.isc_ntxd_default = {DEFAULT_RING}, | |||||
}; | |||||
ent = ixl_vendor_info_array; | if_shared_ctx_t ixl_sctx = &ixl_sctx_init; | ||||
while (ent->vendor_id != 0) { | |||||
if ((pci_vendor_id == ent->vendor_id) && | |||||
(pci_device_id == ent->device_id) && | |||||
((pci_subvendor_id == ent->subvendor_id) || | /*** Functions ***/ | ||||
(ent->subvendor_id == 0)) && | |||||
((pci_subdevice_id == ent->subdevice_id) || | static void * | ||||
(ent->subdevice_id == 0))) { | ixl_register(device_t dev) | ||||
sprintf(device_name, "%s, Version - %s", | { | ||||
ixl_strings[ent->index], | return (ixl_sctx); | ||||
ixl_driver_version); | |||||
device_set_desc_copy(dev, device_name); | |||||
return (BUS_PROBE_DEFAULT); | |||||
} | } | ||||
ent++; | |||||
} | |||||
return (ENXIO); | |||||
} | |||||
static int | int | ||||
ixl_attach_get_link_status(struct ixl_pf *pf) | ixl_allocate_pci_resources(struct ixl_pf *pf) | ||||
{ | { | ||||
int rid; | |||||
struct i40e_hw *hw = &pf->hw; | struct i40e_hw *hw = &pf->hw; | ||||
device_t dev = pf->dev; | device_t dev = iflib_get_dev(pf->vsi.ctx); | ||||
int error = 0; | |||||
if (((hw->aq.fw_maj_ver == 4) && (hw->aq.fw_min_ver < 33)) || | /* Map BAR0 */ | ||||
(hw->aq.fw_maj_ver < 4)) { | rid = PCIR_BAR(0); | ||||
i40e_msec_delay(75); | pf->pci_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, | ||||
error = i40e_aq_set_link_restart_an(hw, TRUE, NULL); | &rid, RF_ACTIVE); | ||||
if (error) { | |||||
device_printf(dev, "link restart failed, aq_err=%d\n", | |||||
pf->hw.aq.asq_last_status); | |||||
return error; | |||||
} | |||||
} | |||||
/* Determine link state */ | if (!(pf->pci_mem)) { | ||||
hw->phy.get_link_info = TRUE; | device_printf(dev, "Unable to allocate bus resource: PCI memory\n"); | ||||
i40e_get_link_status(hw, &pf->link_up); | return (ENXIO); | ||||
return (0); | |||||
} | } | ||||
/* | /* Save off the PCI information */ | ||||
* Sanity check and save off tunable values. | hw->vendor_id = pci_get_vendor(dev); | ||||
*/ | hw->device_id = pci_get_device(dev); | ||||
static int | hw->revision_id = pci_read_config(dev, PCIR_REVID, 1); | ||||
ixl_save_pf_tunables(struct ixl_pf *pf) | hw->subsystem_vendor_id = | ||||
{ | pci_read_config(dev, PCIR_SUBVEND_0, 2); | ||||
device_t dev = pf->dev; | hw->subsystem_device_id = | ||||
pci_read_config(dev, PCIR_SUBDEV_0, 2); | |||||
/* Save tunable information */ | hw->bus.device = pci_get_slot(dev); | ||||
pf->enable_msix = ixl_enable_msix; | hw->bus.func = pci_get_function(dev); | ||||
pf->max_queues = ixl_max_queues; | |||||
pf->enable_tx_fc_filter = ixl_enable_tx_fc_filter; | |||||
pf->dynamic_rx_itr = ixl_dynamic_rx_itr; | |||||
pf->dynamic_tx_itr = ixl_dynamic_tx_itr; | |||||
pf->dbg_mask = ixl_core_debug_mask; | |||||
pf->hw.debug_mask = ixl_shared_debug_mask; | |||||
if (ixl_ring_size < IXL_MIN_RING | /* Save off register access information */ | ||||
|| ixl_ring_size > IXL_MAX_RING | pf->osdep.mem_bus_space_tag = | ||||
|| ixl_ring_size % IXL_RING_INCREMENT != 0) { | rman_get_bustag(pf->pci_mem); | ||||
device_printf(dev, "Invalid ring_size value of %d set!\n", | pf->osdep.mem_bus_space_handle = | ||||
ixl_ring_size); | rman_get_bushandle(pf->pci_mem); | ||||
device_printf(dev, "ring_size must be between %d and %d, " | pf->osdep.mem_bus_space_size = rman_get_size(pf->pci_mem); | ||||
"inclusive, and must be a multiple of %d\n", | pf->osdep.flush_reg = I40E_GLGEN_STAT; | ||||
IXL_MIN_RING, IXL_MAX_RING, IXL_RING_INCREMENT); | pf->osdep.dev = dev; | ||||
device_printf(dev, "Using default value of %d instead\n", | |||||
IXL_DEFAULT_RING); | |||||
pf->ringsz = IXL_DEFAULT_RING; | |||||
} else | |||||
pf->ringsz = ixl_ring_size; | |||||
if (ixl_tx_itr < 0 || ixl_tx_itr > IXL_MAX_ITR) { | pf->hw.hw_addr = (u8 *) &pf->osdep.mem_bus_space_handle; | ||||
device_printf(dev, "Invalid tx_itr value of %d set!\n", | pf->hw.back = &pf->osdep; | ||||
ixl_tx_itr); | |||||
device_printf(dev, "tx_itr must be between %d and %d, " | |||||
"inclusive\n", | |||||
0, IXL_MAX_ITR); | |||||
device_printf(dev, "Using default value of %d instead\n", | |||||
IXL_ITR_4K); | |||||
pf->tx_itr = IXL_ITR_4K; | |||||
} else | |||||
pf->tx_itr = ixl_tx_itr; | |||||
if (ixl_rx_itr < 0 || ixl_rx_itr > IXL_MAX_ITR) { | |||||
device_printf(dev, "Invalid rx_itr value of %d set!\n", | |||||
ixl_rx_itr); | |||||
device_printf(dev, "rx_itr must be between %d and %d, " | |||||
"inclusive\n", | |||||
0, IXL_MAX_ITR); | |||||
device_printf(dev, "Using default value of %d instead\n", | |||||
IXL_ITR_8K); | |||||
pf->rx_itr = IXL_ITR_8K; | |||||
} else | |||||
pf->rx_itr = ixl_rx_itr; | |||||
return (0); | return (0); | ||||
} | } | ||||
/********************************************************************* | |||||
* Device initialization routine | |||||
* | |||||
* The attach entry point is called when the driver is being loaded. | |||||
* This routine identifies the type of hardware, allocates all resources | |||||
* and initializes the hardware. | |||||
* | |||||
* return 0 on success, positive on failure | |||||
*********************************************************************/ | |||||
static int | static int | ||||
ixl_attach(device_t dev) | ixl_if_attach_pre(if_ctx_t ctx) | ||||
{ | { | ||||
device_t dev; | |||||
struct ixl_pf *pf; | struct ixl_pf *pf; | ||||
struct i40e_hw *hw; | struct i40e_hw *hw; | ||||
struct ixl_vsi *vsi; | struct ixl_vsi *vsi; | ||||
if_softc_ctx_t scctx; | |||||
enum i40e_status_code status; | enum i40e_status_code status; | ||||
int error = 0; | int error = 0; | ||||
INIT_DEBUGOUT("ixl_attach: begin"); | INIT_DEBUGOUT("ixl_if_attach_pre: begin"); | ||||
/* Allocate, clear, and link in our primary soft structure */ | dev = iflib_get_dev(ctx); | ||||
pf = device_get_softc(dev); | pf = iflib_get_softc(ctx); | ||||
pf->dev = pf->osdep.dev = dev; | |||||
hw = &pf->hw; | |||||
hw = &pf->hw; | |||||
/* | /* | ||||
** Note this assumes we have a single embedded VSI, | ** Note this assumes we have a single embedded VSI, | ||||
** this could be enhanced later to allocate multiple | ** this could be enhanced later to allocate multiple | ||||
*/ | */ | ||||
vsi = &pf->vsi; | vsi = &pf->vsi; | ||||
vsi->dev = pf->dev; | vsi->back = pf; | ||||
vsi->hw = &pf->hw; | |||||
vsi->id = 0; | |||||
vsi->num_vlans = 0; | |||||
vsi->ctx = ctx; | |||||
vsi->media = iflib_get_media(ctx); | |||||
vsi->shared = scctx = iflib_get_softc_ctx(ctx); | |||||
pf->dev = dev; | |||||
/* | |||||
* These are the same across all current ixl models | |||||
*/ | |||||
vsi->shared->isc_tx_nsegments = IXL_MAX_TX_SEGS; | |||||
vsi->shared->isc_msix_bar = PCIR_BAR(IXL_MSIX_BAR); | |||||
vsi->shared->isc_tx_tso_segments_max = IXL_MAX_TSO_SEGS; | |||||
vsi->shared->isc_tx_tso_size_max = IXL_TSO_SIZE; | |||||
vsi->shared->isc_tx_tso_segsize_max = PAGE_SIZE; | |||||
/* Save tunable values */ | /* Save tunable values */ | ||||
error = ixl_save_pf_tunables(pf); | error = ixl_save_pf_tunables(pf); | ||||
if (error) | if (error) | ||||
return (error); | return (error); | ||||
/* Core Lock Init*/ | /* | ||||
IXL_PF_LOCK_INIT(pf, device_get_nameunit(dev)); | * TODO: Excoriate mmacy for not documenting what needs to be set in the iflib stuff | ||||
* in attach_pre() | |||||
* Or, in general... | |||||
*/ | |||||
scctx->isc_txqsizes[0] = roundup2(scctx->isc_ntxd[0] | |||||
* sizeof(struct i40e_tx_desc) + sizeof(u32), DBA_ALIGN); | |||||
scctx->isc_rxqsizes[0] = roundup2(scctx->isc_nrxd[0] | |||||
* sizeof(union i40e_32byte_rx_desc), DBA_ALIGN); | |||||
/* XXX: No idea what this does */ | |||||
scctx->isc_max_txqsets = scctx->isc_max_rxqsets = 32; | |||||
/* Set up the timer callout */ | |||||
callout_init_mtx(&pf->timer, &pf->pf_mtx, 0); | |||||
/* Do PCI setup - map BAR0, etc */ | /* Do PCI setup - map BAR0, etc */ | ||||
if (ixl_allocate_pci_resources(pf)) { | if (ixl_allocate_pci_resources(pf)) { | ||||
device_printf(dev, "Allocation of PCI resources failed\n"); | device_printf(dev, "Allocation of PCI resources failed\n"); | ||||
error = ENXIO; | error = ENXIO; | ||||
goto err_out; | goto err_out; | ||||
} | } | ||||
/* Establish a clean starting point */ | /* Establish a clean starting point */ | ||||
Show All 10 Lines | ixl_if_attach_pre(if_ctx_t ctx) | ||||
status = i40e_init_shared_code(hw); | status = i40e_init_shared_code(hw); | ||||
if (status) { | if (status) { | ||||
device_printf(dev, "Unable to initialize shared code, error %s\n", | device_printf(dev, "Unable to initialize shared code, error %s\n", | ||||
i40e_stat_str(hw, status)); | i40e_stat_str(hw, status)); | ||||
error = EIO; | error = EIO; | ||||
goto err_out; | goto err_out; | ||||
} | } | ||||
/* | /* Set admin queue parameters */ | ||||
* Allocate interrupts and figure out number of queues to use | |||||
* for PF interface | |||||
*/ | |||||
pf->msix = ixl_init_msix(pf); | |||||
/* Set up the admin queue */ | |||||
hw->aq.num_arq_entries = IXL_AQ_LEN; | hw->aq.num_arq_entries = IXL_AQ_LEN; | ||||
hw->aq.num_asq_entries = IXL_AQ_LEN; | hw->aq.num_asq_entries = IXL_AQ_LEN; | ||||
hw->aq.arq_buf_size = IXL_AQ_BUF_SZ; | hw->aq.arq_buf_size = IXL_AQ_BUF_SZ; | ||||
hw->aq.asq_buf_size = IXL_AQ_BUF_SZ; | hw->aq.asq_buf_size = IXL_AQ_BUF_SZ; | ||||
/* Set up the admin queue */ | |||||
status = i40e_init_adminq(hw); | status = i40e_init_adminq(hw); | ||||
if (status != 0 && status != I40E_ERR_FIRMWARE_API_VERSION) { | if (status != 0 && status != I40E_ERR_FIRMWARE_API_VERSION) { | ||||
device_printf(dev, "Unable to initialize Admin Queue, error %s\n", | device_printf(dev, "Unable to initialize Admin Queue, error %s\n", | ||||
i40e_stat_str(hw, status)); | i40e_stat_str(hw, status)); | ||||
error = EIO; | error = EIO; | ||||
goto err_out; | goto err_out; | ||||
} | } | ||||
ixl_print_nvm_version(pf); | ixl_print_nvm_version(pf); | ||||
Show All 19 Lines | device_printf(dev, "The driver for the device detected " | ||||
"Please update the NVM image.\n"); | "Please update the NVM image.\n"); | ||||
/* Clear PXE mode */ | /* Clear PXE mode */ | ||||
i40e_clear_pxe_mode(hw); | i40e_clear_pxe_mode(hw); | ||||
/* Get capabilities from the device */ | /* Get capabilities from the device */ | ||||
error = ixl_get_hw_capabilities(pf); | error = ixl_get_hw_capabilities(pf); | ||||
if (error) { | if (error) { | ||||
device_printf(dev, "HW capabilities failure!\n"); | device_printf(dev, "get_hw_capabilities failed: %d\n", | ||||
error); | |||||
goto err_get_cap; | goto err_get_cap; | ||||
} | } | ||||
/* Set up host memory cache */ | /* Set up host memory cache */ | ||||
status = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, | status = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, | ||||
hw->func_caps.num_rx_qp, 0, 0); | hw->func_caps.num_rx_qp, 0, 0); | ||||
if (status) { | if (status) { | ||||
device_printf(dev, "init_lan_hmc failed: %s\n", | device_printf(dev, "init_lan_hmc failed: %s\n", | ||||
i40e_stat_str(hw, status)); | i40e_stat_str(hw, status)); | ||||
goto err_get_cap; | goto err_get_cap; | ||||
} | } | ||||
status = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); | status = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); | ||||
if (status) { | if (status) { | ||||
device_printf(dev, "configure_lan_hmc failed: %s\n", | device_printf(dev, "configure_lan_hmc failed: %s\n", | ||||
i40e_stat_str(hw, status)); | i40e_stat_str(hw, status)); | ||||
goto err_mac_hmc; | goto err_mac_hmc; | ||||
} | } | ||||
/* Init queue allocation manager */ | |||||
error = ixl_pf_qmgr_init(&pf->qmgr, hw->func_caps.num_tx_qp); | |||||
if (error) { | |||||
device_printf(dev, "Failed to init queue manager for PF queues, error %d\n", | |||||
error); | |||||
goto err_mac_hmc; | |||||
} | |||||
/* reserve a contiguous allocation for the PF's VSI */ | |||||
error = ixl_pf_qmgr_alloc_contiguous(&pf->qmgr, vsi->num_queues, &pf->qtag); | |||||
if (error) { | |||||
device_printf(dev, "Failed to reserve queues for PF LAN VSI, error %d\n", | |||||
error); | |||||
goto err_mac_hmc; | |||||
} | |||||
device_printf(dev, "Allocating %d queues for PF LAN VSI; %d queues active\n", | |||||
pf->qtag.num_allocated, pf->qtag.num_active); | |||||
/* Disable LLDP from the firmware for certain NVM versions */ | /* Disable LLDP from the firmware for certain NVM versions */ | ||||
if (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) || | if (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) || | ||||
(pf->hw.aq.fw_maj_ver < 4)) | (pf->hw.aq.fw_maj_ver < 4)) | ||||
i40e_aq_stop_lldp(hw, TRUE, NULL); | i40e_aq_stop_lldp(hw, TRUE, NULL); | ||||
/* Get MAC addresses from hardware */ | /* Get MAC addresses from hardware */ | ||||
i40e_get_mac_addr(hw, hw->mac.addr); | i40e_get_mac_addr(hw, hw->mac.addr); | ||||
error = i40e_validate_mac_addr(hw->mac.addr); | error = i40e_validate_mac_addr(hw->mac.addr); | ||||
if (error) { | if (error) { | ||||
device_printf(dev, "validate_mac_addr failed: %d\n", error); | device_printf(dev, "validate_mac_addr failed: %d\n", error); | ||||
goto err_mac_hmc; | goto err_mac_hmc; | ||||
} | } | ||||
bcopy(hw->mac.addr, hw->mac.perm_addr, ETHER_ADDR_LEN); | bcopy(hw->mac.addr, hw->mac.perm_addr, ETHER_ADDR_LEN); | ||||
iflib_set_mac(ctx, hw->mac.addr); | |||||
i40e_get_port_mac_addr(hw, hw->mac.port_addr); | i40e_get_port_mac_addr(hw, hw->mac.port_addr); | ||||
/* Initialize mac filter list for VSI */ | /* Initialize mac filter list for VSI */ | ||||
SLIST_INIT(&vsi->ftl); | SLIST_INIT(&vsi->ftl); | ||||
/* Set up SW VSI and allocate queue memory and rings */ | /* Fill out more iflib parameters */ | ||||
if (ixl_setup_stations(pf)) { | scctx->isc_txrx = &ixl_txrx; | ||||
device_printf(dev, "setup stations failed!\n"); | vsi->shared->isc_rss_table_size = pf->hw.func_caps.rss_table_size; | ||||
error = ENOMEM; | scctx->isc_tx_csum_flags = CSUM_OFFLOAD; | ||||
goto err_mac_hmc; | scctx->isc_capenable = IXL_CAPS; | ||||
INIT_DEBUGOUT("ixl_if_attach_pre: end"); | |||||
return (0); | |||||
// TODO: Review what needs to be cleaned up when this fails | |||||
err_mac_hmc: | |||||
i40e_shutdown_lan_hmc(hw); | |||||
err_get_cap: | |||||
i40e_shutdown_adminq(hw); | |||||
err_out: | |||||
ixl_free_pci_resources(pf); | |||||
ixl_free_mac_filters(vsi); | |||||
return (error); | |||||
} | } | ||||
static int | |||||
ixl_if_attach_post(if_ctx_t ctx) | |||||
{ | |||||
device_t dev; | |||||
struct ixl_pf *pf; | |||||
struct i40e_hw *hw; | |||||
struct ixl_vsi *vsi; | |||||
int error = 0; | |||||
enum i40e_status_code status; | |||||
INIT_DEBUGOUT("ixl_if_attach_post: begin"); | |||||
dev = iflib_get_dev(ctx); | |||||
vsi = iflib_get_softc(ctx); | |||||
vsi->ifp = iflib_get_ifp(ctx); | |||||
pf = (struct ixl_pf *)vsi; | |||||
hw = &pf->hw; | |||||
/* Setup OS network interface / ifnet */ | /* Setup OS network interface / ifnet */ | ||||
if (ixl_setup_interface(dev, vsi)) { | if (ixl_setup_interface(dev, vsi)) { | ||||
device_printf(dev, "interface setup failed!\n"); | device_printf(dev, "interface setup failed!\n"); | ||||
error = EIO; | error = EIO; | ||||
goto err_late; | goto err_late; | ||||
} | } | ||||
/* Determine link state */ | /* Determine link state */ | ||||
if (ixl_attach_get_link_status(pf)) { | if (ixl_attach_get_link_status(pf)) { | ||||
error = EINVAL; | error = EINVAL; | ||||
goto err_late; | goto err_late; | ||||
} | } | ||||
error = ixl_switch_config(pf); | error = ixl_switch_config(pf); | ||||
if (error) { | if (error) { | ||||
device_printf(dev, "Initial ixl_switch_config() failed: %d\n", | device_printf(dev, "Initial switch config failed: %d\n", error); | ||||
goto err_mac_hmc; | |||||
} | |||||
/* Init queue allocation manager */ | |||||
/* XXX: This init can go in pre or post; allocation must be in post */ | |||||
error = ixl_pf_qmgr_init(&pf->qmgr, hw->func_caps.num_tx_qp); | |||||
if (error) { | |||||
device_printf(dev, "Failed to init queue manager for PF queues, error %d\n", | |||||
error); | error); | ||||
goto err_late; | goto err_mac_hmc; | ||||
} | } | ||||
/* reserve a contiguous allocation for the PF's VSI */ | |||||
/* TODO: Could be refined? */ | |||||
error = ixl_pf_qmgr_alloc_contiguous(&pf->qmgr, | |||||
max(vsi->num_tx_queues, vsi->num_rx_queues), &pf->qtag); | |||||
if (error) { | |||||
device_printf(dev, "Failed to reserve queues for PF LAN VSI, error %d\n", | |||||
error); | |||||
goto err_mac_hmc; | |||||
} | |||||
device_printf(dev, "Allocating %d queues for PF LAN VSI; %d queues active\n", | |||||
pf->qtag.num_allocated, pf->qtag.num_active); | |||||
/* Limit PHY interrupts to link, autoneg, and modules failure */ | /* Limit PHY interrupts to link, autoneg, and modules failure */ | ||||
status = i40e_aq_set_phy_int_mask(hw, IXL_DEFAULT_PHY_INT_MASK, | status = i40e_aq_set_phy_int_mask(hw, IXL_DEFAULT_PHY_INT_MASK, | ||||
NULL); | NULL); | ||||
if (status) { | if (status) { | ||||
device_printf(dev, "i40e_aq_set_phy_mask() failed: err %s," | device_printf(dev, "i40e_aq_set_phy_mask() failed: err %s," | ||||
" aq_err %s\n", i40e_stat_str(hw, status), | " aq_err %s\n", i40e_stat_str(hw, status), | ||||
i40e_aq_str(hw, hw->aq.asq_last_status)); | i40e_aq_str(hw, hw->aq.asq_last_status)); | ||||
goto err_late; | goto err_late; | ||||
} | } | ||||
/* Get the bus configuration and set the shared code's config */ | /* Get the bus configuration and set the shared code */ | ||||
ixl_get_bus_info(pf); | ixl_get_bus_info(hw, dev); | ||||
/* | // TODO: Don't call this in non-MSIX mode | ||||
* In MSI-X mode, initialize the Admin Queue interrupt, | /* Keep admin queue interrupts active while driver is loaded */ | ||||
* so userland tools can communicate with the adapter regardless of | if (pf->enable_msix) | ||||
* the ifnet interface's status. | |||||
*/ | |||||
if (pf->msix > 1) { | |||||
error = ixl_setup_adminq_msix(pf); | |||||
if (error) { | |||||
device_printf(dev, "ixl_setup_adminq_msix() error: %d\n", | |||||
error); | |||||
goto err_late; | |||||
} | |||||
error = ixl_setup_adminq_tq(pf); | |||||
if (error) { | |||||
device_printf(dev, "ixl_setup_adminq_tq() error: %d\n", | |||||
error); | |||||
goto err_late; | |||||
} | |||||
ixl_configure_intr0_msix(pf); | ixl_configure_intr0_msix(pf); | ||||
ixl_enable_intr0(hw); | |||||
error = ixl_setup_queue_msix(vsi); | |||||
if (error) | |||||
device_printf(dev, "ixl_setup_queue_msix() error: %d\n", | |||||
error); | |||||
error = ixl_setup_queue_tqs(vsi); | |||||
if (error) | |||||
device_printf(dev, "ixl_setup_queue_tqs() error: %d\n", | |||||
error); | |||||
} else { | |||||
error = ixl_setup_legacy(pf); | |||||
error = ixl_setup_adminq_tq(pf); | |||||
if (error) { | |||||
device_printf(dev, "ixl_setup_adminq_tq() error: %d\n", | |||||
error); | |||||
goto err_late; | |||||
} | |||||
error = ixl_setup_queue_tqs(vsi); | |||||
if (error) | |||||
device_printf(dev, "ixl_setup_queue_tqs() error: %d\n", | |||||
error); | |||||
} | |||||
if (error) { | |||||
device_printf(dev, "interrupt setup error: %d\n", error); | |||||
} | |||||
/* Set initial advertised speed sysctl value */ | |||||
ixl_get_initial_advertised_speeds(pf); | |||||
/* Initialize statistics & add sysctls */ | /* Initialize statistics & add sysctls */ | ||||
ixl_add_device_sysctls(pf); | ixl_add_device_sysctls(pf); | ||||
ixl_pf_reset_stats(pf); | ixl_pf_reset_stats(pf); | ||||
ixl_update_stats_counters(pf); | ixl_update_stats_counters(pf); | ||||
ixl_add_hw_stats(pf); | ixl_add_hw_stats(pf); | ||||
/* Register for VLAN events */ | /* Set initial advertised speed sysctl value */ | ||||
vsi->vlan_attach = EVENTHANDLER_REGISTER(vlan_config, | ixl_get_initial_advertised_speeds(pf); | ||||
ixl_register_vlan, vsi, EVENTHANDLER_PRI_FIRST); | |||||
vsi->vlan_detach = EVENTHANDLER_REGISTER(vlan_unconfig, | |||||
ixl_unregister_vlan, vsi, EVENTHANDLER_PRI_FIRST); | |||||
#ifdef PCI_IOV | #ifdef PCI_IOV | ||||
ixl_initialize_sriov(pf); | ixl_initialize_sriov(pf); | ||||
#endif | #endif | ||||
INIT_DEBUGOUT("ixl_if_attach_post: end"); | |||||
#ifdef DEV_NETMAP | |||||
ixl_netmap_attach(vsi); | |||||
#endif /* DEV_NETMAP */ | |||||
#ifdef IXL_IW | |||||
if (hw->func_caps.iwarp && ixl_enable_iwarp) { | |||||
pf->iw_enabled = (pf->iw_msix > 0) ? true : false; | |||||
if (pf->iw_enabled) { | |||||
error = ixl_iw_pf_attach(pf); | |||||
if (error) { | |||||
device_printf(dev, | |||||
"interfacing to iwarp driver failed: %d\n", | |||||
error); | |||||
goto err_late; | |||||
} | |||||
} else | |||||
device_printf(dev, | |||||
"iwarp disabled on this device (no msix vectors)\n"); | |||||
} else { | |||||
pf->iw_enabled = false; | |||||
device_printf(dev, "The device is not iWARP enabled\n"); | |||||
} | |||||
#endif | |||||
INIT_DEBUGOUT("ixl_attach: end"); | |||||
return (0); | return (0); | ||||
// TODO: Review what needs to be cleaned up when this fails | |||||
err_late: | err_late: | ||||
if (vsi->ifp != NULL) { | |||||
ether_ifdetach(vsi->ifp); | |||||
if_free(vsi->ifp); | |||||
} | |||||
err_mac_hmc: | err_mac_hmc: | ||||
i40e_shutdown_lan_hmc(hw); | i40e_shutdown_lan_hmc(hw); | ||||
err_get_cap: | |||||
i40e_shutdown_adminq(hw); | i40e_shutdown_adminq(hw); | ||||
err_out: | |||||
ixl_free_pci_resources(pf); | ixl_free_pci_resources(pf); | ||||
ixl_free_vsi(vsi); | ixl_free_mac_filters(vsi); | ||||
IXL_PF_LOCK_DESTROY(pf); | |||||
return (error); | return (error); | ||||
} | } | ||||
/********************************************************************* | |||||
* Device removal routine | |||||
* | |||||
* The detach entry point is called when the driver is being removed. | |||||
* This routine stops the adapter and deallocates all the resources | |||||
* that were allocated for driver operation. | |||||
* | |||||
* return 0 on success, positive on failure | |||||
*********************************************************************/ | |||||
static int | static int | ||||
ixl_detach(device_t dev) | ixl_if_detach(if_ctx_t ctx) | ||||
{ | { | ||||
struct ixl_pf *pf = device_get_softc(dev); | struct ixl_vsi *vsi = iflib_get_softc(ctx); | ||||
struct ixl_pf *pf = vsi->back; | |||||
struct i40e_hw *hw = &pf->hw; | struct i40e_hw *hw = &pf->hw; | ||||
struct ixl_vsi *vsi = &pf->vsi; | i40e_status status; | ||||
enum i40e_status_code status; | #ifdef PCI_IOV | ||||
#if defined(PCI_IOV) || defined(IXL_IW) | |||||
int error; | int error; | ||||
#endif | #endif | ||||
INIT_DEBUGOUT("ixl_detach: begin"); | INIT_DEBUGOUT("ixl_if_detach: begin"); | ||||
/* Make sure VLANS are not using driver */ | |||||
if (vsi->ifp->if_vlantrunk != NULL) { | |||||
device_printf(dev, "Vlan in use, detach first\n"); | |||||
return (EBUSY); | |||||
} | |||||
#ifdef PCI_IOV | #ifdef PCI_IOV | ||||
error = pci_iov_detach(dev); | error = pci_iov_detach(iflib_get_dev(ctx)); | ||||
if (error != 0) { | if (error != 0) { | ||||
device_printf(dev, "SR-IOV in use; detach first.\n"); | device_printf(iflib_get_dev(ctx), "SR-IOV in use; detach first.\n"); | ||||
return (error); | return (error); | ||||
} | } | ||||
#endif | #endif | ||||
ether_ifdetach(vsi->ifp); | |||||
if (vsi->ifp->if_drv_flags & IFF_DRV_RUNNING) | |||||
ixl_stop(pf); | |||||
/* Shutdown LAN HMC */ | /* Shutdown LAN HMC */ | ||||
status = i40e_shutdown_lan_hmc(hw); | status = i40e_shutdown_lan_hmc(hw); | ||||
if (status) | if (status) | ||||
device_printf(dev, | device_printf(iflib_get_dev(ctx), | ||||
"Shutdown LAN HMC failed with code %d\n", status); | "Shutdown LAN HMC failed with code %d\n", status); | ||||
/* Teardown LAN queue resources */ | |||||
ixl_teardown_queue_msix(vsi); | |||||
ixl_free_queue_tqs(vsi); | |||||
/* Shutdown admin queue */ | /* Shutdown admin queue */ | ||||
ixl_disable_intr0(hw); | ixl_disable_adminq(hw); | ||||
ixl_teardown_adminq_msix(pf); | |||||
ixl_free_adminq_tq(pf); | /* Shutdown admin queue */ | ||||
status = i40e_shutdown_adminq(hw); | status = i40e_shutdown_adminq(hw); | ||||
if (status) | if (status) | ||||
device_printf(dev, | device_printf(iflib_get_dev(ctx), | ||||
"Shutdown Admin queue failed with code %d\n", status); | "Shutdown Admin queue failed with code %d\n", status); | ||||
/* Unregister VLAN events */ | ixl_pf_qmgr_destroy(&pf->qmgr); | ||||
if (vsi->vlan_attach != NULL) | ixl_free_pci_resources(pf); | ||||
EVENTHANDLER_DEREGISTER(vlan_config, vsi->vlan_attach); | ixl_free_mac_filters(vsi); | ||||
if (vsi->vlan_detach != NULL) | return (0); | ||||
EVENTHANDLER_DEREGISTER(vlan_unconfig, vsi->vlan_detach); | } | ||||
callout_drain(&pf->timer); | /* TODO: Do shutdown-specific stuff here */ | ||||
static int | |||||
ixl_if_shutdown(if_ctx_t ctx) | |||||
{ | |||||
int error = 0; | |||||
#ifdef IXL_IW | INIT_DEBUGOUT("ixl_if_shutdown: begin"); | ||||
if (ixl_enable_iwarp && pf->iw_enabled) { | |||||
error = ixl_iw_pf_detach(pf); | /* TODO: Call ixl_if_stop()? */ | ||||
if (error == EBUSY) { | |||||
device_printf(dev, "iwarp in use; stop it first.\n"); | /* TODO: Then setup low power mode */ | ||||
return (error); | return (error); | ||||
} | } | ||||
static int | |||||
ixl_if_suspend(if_ctx_t ctx) | |||||
{ | |||||
int error = 0; | |||||
INIT_DEBUGOUT("ixl_if_suspend: begin"); | |||||
/* TODO: Call ixl_if_stop()? */ | |||||
/* TODO: Then setup low power mode */ | |||||
return (error); | |||||
} | } | ||||
static int | |||||
ixl_if_resume(if_ctx_t ctx) | |||||
{ | |||||
struct ifnet *ifp = iflib_get_ifp(ctx); | |||||
INIT_DEBUGOUT("ixl_if_resume: begin"); | |||||
/* Read & clear wake-up registers */ | |||||
/* Required after D3->D0 transition */ | |||||
if (ifp->if_flags & IFF_UP) | |||||
ixl_if_init(ctx); | |||||
return (0); | |||||
} | |||||
void | |||||
ixl_if_init(if_ctx_t ctx) | |||||
{ | |||||
struct ixl_vsi *vsi = iflib_get_softc(ctx); | |||||
struct ixl_pf *pf = vsi->back; | |||||
struct i40e_hw *hw = &pf->hw; | |||||
device_t dev = iflib_get_dev(ctx); | |||||
struct i40e_filter_control_settings filter; | |||||
u8 tmpaddr[ETHER_ADDR_LEN]; | |||||
int ret; | |||||
INIT_DEBUGOUT("ixl_if_init: begin"); | |||||
ixl_if_stop(ctx); | |||||
/* Get the latest mac address... User might use a LAA */ | |||||
bcopy(IF_LLADDR(vsi->ifp), tmpaddr, | |||||
I40E_ETH_LENGTH_OF_ADDRESS); | |||||
if (!cmp_etheraddr(hw->mac.addr, tmpaddr) && | |||||
(i40e_validate_mac_addr(tmpaddr) == I40E_SUCCESS)) { | |||||
ixl_del_filter(vsi, hw->mac.addr, IXL_VLAN_ANY); | |||||
bcopy(tmpaddr, hw->mac.addr, | |||||
I40E_ETH_LENGTH_OF_ADDRESS); | |||||
ret = i40e_aq_mac_address_write(hw, | |||||
I40E_AQC_WRITE_TYPE_LAA_ONLY, | |||||
hw->mac.addr, NULL); | |||||
if (ret) { | |||||
device_printf(dev, "LLA address" | |||||
"change failed!!\n"); | |||||
return; | |||||
} | |||||
} | |||||
ixl_add_filter(vsi, hw->mac.addr, IXL_VLAN_ANY); | |||||
/* Set up the device filtering */ | |||||
bzero(&filter, sizeof(filter)); | |||||
filter.enable_ethtype = TRUE; | |||||
filter.enable_macvlan = TRUE; | |||||
filter.enable_fdir = FALSE; | |||||
filter.hash_lut_size = I40E_HASH_LUT_SIZE_512; | |||||
if (i40e_set_filter_control(hw, &filter)) | |||||
device_printf(dev, "i40e_set_filter_control() failed\n"); | |||||
/* Prepare the VSI: rings, hmc contexts, etc... */ | |||||
if (ixl_initialize_vsi(vsi)) { | |||||
device_printf(dev, "initialize vsi failed!!\n"); | |||||
return; | |||||
} | |||||
/* Set up RSS */ | |||||
ixl_config_rss(pf); | |||||
/* Add protocol filters to list */ | |||||
ixl_init_filters(vsi); | |||||
/* Setup vlan's if needed */ | |||||
ixl_setup_vlan_filters(vsi); | |||||
/* Set up MSI/X routing and the ITR settings */ | |||||
if (pf->enable_msix) { | |||||
ixl_configure_queue_intr_msix(pf); | |||||
ixl_configure_itr(pf); | |||||
} else | |||||
ixl_configure_legacy(pf); | |||||
ixl_enable_rings(vsi); | |||||
// i40e_aq_set_default_vsi(hw, vsi->seid, NULL); | |||||
ixl_reconfigure_filters(vsi); | |||||
/* And now turn on interrupts */ | |||||
// TODO: Something is wrong here... | |||||
ixl_enable_adminq(hw); | |||||
ixl_enable_intr(vsi); | |||||
} | |||||
void | |||||
ixl_if_stop(if_ctx_t ctx) | |||||
{ | |||||
struct ixl_vsi *vsi = iflib_get_softc(ctx); | |||||
struct ixl_pf *pf = (struct ixl_pf *)vsi->back; | |||||
INIT_DEBUGOUT("ixl_if_stop: begin\n"); | |||||
if (pf->num_vfs == 0) | |||||
ixl_disable_intr(vsi); | |||||
else | |||||
ixl_disable_rings_intr(vsi); | |||||
ixl_disable_rings(vsi); | |||||
} | |||||
static int | |||||
ixl_if_msix_intr_assign(if_ctx_t ctx, int msix) | |||||
{ | |||||
struct ixl_vsi *vsi = iflib_get_softc(ctx); | |||||
struct ixl_pf *pf = vsi->back; | |||||
struct ixl_rx_queue *que = vsi->rx_queues; | |||||
struct ixl_tx_queue *tx_que = vsi->tx_queues; | |||||
int err, i, rid, vector = 0; | |||||
char buf[16]; | |||||
/* Admin Que is vector 0*/ | |||||
rid = vector + 1; | |||||
err = iflib_irq_alloc_generic(ctx, &vsi->irq, rid, IFLIB_INTR_ADMIN, | |||||
ixl_msix_adminq, pf, 0, "aq"); | |||||
if (err) { | |||||
iflib_irq_free(ctx, &vsi->irq); | |||||
device_printf(iflib_get_dev(ctx), "Failed to register Admin que handler"); | |||||
return (err); | |||||
} | |||||
pf->admvec = vector; | |||||
++vector; | |||||
iflib_softirq_alloc_generic(ctx, rid, IFLIB_INTR_IOV, pf, 0, "ixl_iov"); | |||||
/* Now set up the stations */ | |||||
for (i = 0; i < vsi->num_rx_queues; i++, vector++, que++) { | |||||
rid = vector + 1; | |||||
snprintf(buf, sizeof(buf), "rxq%d", i); | |||||
err = iflib_irq_alloc_generic(ctx, &que->que_irq, rid, IFLIB_INTR_RX, | |||||
ixl_msix_que, que, que->rxr.me, buf); | |||||
if (err) { | |||||
device_printf(iflib_get_dev(ctx), "Failed to allocate q int %d err: %d", i, err); | |||||
vsi->num_rx_queues = i + 1; | |||||
goto fail; | |||||
} | |||||
que->msix = vector; | |||||
} | |||||
for (i = 0, tx_que = vsi->tx_queues; i < vsi->num_tx_queues; i++, tx_que++) { | |||||
snprintf(buf, sizeof(buf), "txq%d", i); | |||||
rid = que->msix + 1; | |||||
iflib_softirq_alloc_generic(ctx, rid, IFLIB_INTR_TX, tx_que, tx_que->txr.me, buf); | |||||
} | |||||
return (0); | |||||
fail: | |||||
iflib_irq_free(ctx, &vsi->irq); | |||||
que = vsi->rx_queues; | |||||
for (int i = 0; i < vsi->num_rx_queues; i++, que++) | |||||
iflib_irq_free(ctx, &que->que_irq); | |||||
return (err); | |||||
} | |||||
/* Enable all interrupts */ | |||||
static void | |||||
ixl_if_enable_intr(if_ctx_t ctx) | |||||
{ | |||||
struct ixl_vsi *vsi = iflib_get_softc(ctx); | |||||
struct i40e_hw *hw = vsi->hw; | |||||
struct ixl_rx_queue *que = vsi->rx_queues; | |||||
ixl_enable_adminq(hw); | |||||
/* Enable queue interrupts */ | |||||
for (int i = 0; i < vsi->num_rx_queues; i++, que++) | |||||
/* TODO: Queue index parameter is probably wrong */ | |||||
ixl_enable_queue(hw, que->rxr.me); | |||||
} | |||||
/* Disable all interrupts */ | |||||
static void | |||||
ixl_if_disable_intr(if_ctx_t ctx) | |||||
{ | |||||
struct ixl_vsi *vsi = iflib_get_softc(ctx); | |||||
struct i40e_hw *hw = vsi->hw; | |||||
struct ixl_rx_queue *que = vsi->rx_queues; | |||||
ixl_disable_adminq(hw); | |||||
/* Enable queue interrupts */ | |||||
for (int i = 0; i < vsi->num_rx_queues; i++, que++) | |||||
/* TODO: Queue index parameter is probably wrong */ | |||||
ixl_disable_queue(hw, que->rxr.me); | |||||
} | |||||
/* Enable queue interrupt */ | |||||
static int | |||||
ixl_if_queue_intr_enable(if_ctx_t ctx, uint16_t rxqid) | |||||
{ | |||||
struct ixl_vsi *vsi = iflib_get_softc(ctx); | |||||
struct i40e_hw *hw = vsi->hw; | |||||
struct ixl_rx_queue *que = &vsi->rx_queues[rxqid]; | |||||
ixl_enable_queue(hw, que->rxr.me); | |||||
return (0); | |||||
} | |||||
static int | |||||
ixl_if_tx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, uint64_t *paddrs, int ntxqs, int ntxqsets) | |||||
{ | |||||
struct ixl_vsi *vsi = iflib_get_softc(ctx); | |||||
struct ixl_tx_queue *que; | |||||
int i; | |||||
MPASS(vsi->num_tx_queues > 0); | |||||
MPASS(ntxqs == 1); | |||||
MPASS(vsi->num_tx_queues == ntxqsets); | |||||
/* Allocate queue structure memory */ | |||||
if (!(vsi->tx_queues = | |||||
(struct ixl_tx_queue *) malloc(sizeof(struct ixl_tx_queue) *ntxqsets, M_IXL, M_NOWAIT | M_ZERO))) { | |||||
device_printf(iflib_get_dev(ctx), "Unable to allocate TX ring memory\n"); | |||||
return (ENOMEM); | |||||
} | |||||
for (i = 0, que = vsi->tx_queues; i < ntxqsets; i++, que++) { | |||||
struct tx_ring *txr = &que->txr; | |||||
txr->me = i; | |||||
que->vsi = vsi; | |||||
/* get the virtual and physical address of the hardware queues */ | |||||
txr->tail = I40E_QTX_TAIL(txr->me); | |||||
txr->tx_base = (struct i40e_tx_desc *)vaddrs[i]; | |||||
txr->tx_paddr = paddrs[i]; | |||||
txr->que = que; | |||||
} | |||||
// TODO: Do a config_gtask_init for admin queue here? | |||||
// iflib_config_gtask_init(ctx, &adapter->mod_task, ixgbe_handle_mod, "mod_task"); | |||||
device_printf(iflib_get_dev(ctx), "%s: allocated for %d txqs\n", __func__, vsi->num_tx_queues); | |||||
return (0); | |||||
} | |||||
static int | |||||
ixl_if_rx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, uint64_t *paddrs, int nrxqs, int nrxqsets) | |||||
{ | |||||
struct ixl_vsi *vsi = iflib_get_softc(ctx); | |||||
struct ixl_rx_queue *que; | |||||
// if_shared_ctx_t sctx; | |||||
int i; | |||||
MPASS(vsi->num_rx_queues > 0); | |||||
MPASS(nrxqs == 1); | |||||
MPASS(vsi->num_rx_queues == nrxqsets); | |||||
/* Allocate queue structure memory */ | |||||
if (!(vsi->rx_queues = | |||||
(struct ixl_rx_queue *) malloc(sizeof(struct ixl_rx_queue) * | |||||
nrxqsets, M_IXL, M_NOWAIT | M_ZERO))) { | |||||
device_printf(iflib_get_dev(ctx), "Unable to allocate RX ring memory\n"); | |||||
return (ENOMEM); | |||||
} | |||||
for (i = 0, que = vsi->rx_queues; i < nrxqsets; i++, que++) { | |||||
struct rx_ring *rxr = &que->rxr; | |||||
rxr->me = i; | |||||
que->vsi = vsi; | |||||
/* get the virtual and physical address of the hardware queues */ | |||||
rxr->tail = I40E_QRX_TAIL(rxr->me); | |||||
rxr->rx_base = (union i40e_rx_desc *)vaddrs[i]; | |||||
rxr->rx_paddr = paddrs[i]; | |||||
rxr->que = que; | |||||
} | |||||
device_printf(iflib_get_dev(ctx), "%s: allocated for %d rxqs\n", __func__, vsi->num_rx_queues); | |||||
return (0); | |||||
} | |||||
static void | |||||
ixl_if_queues_free(if_ctx_t ctx) | |||||
{ | |||||
struct ixl_vsi *vsi = iflib_get_softc(ctx); | |||||
if (vsi->tx_queues != NULL) { | |||||
free(vsi->tx_queues, M_IXL); | |||||
vsi->tx_queues = NULL; | |||||
} | |||||
if (vsi->rx_queues != NULL) { | |||||
free(vsi->rx_queues, M_IXL); | |||||
vsi->rx_queues = NULL; | |||||
} | |||||
} | |||||
static void | |||||
ixl_if_update_admin_status(if_ctx_t ctx) | |||||
{ | |||||
struct ixl_vsi *vsi = iflib_get_softc(ctx); | |||||
struct ixl_pf *pf = vsi->back; | |||||
struct i40e_hw *hw = &pf->hw; | |||||
struct i40e_arq_event_info event; | |||||
i40e_status ret; | |||||
u32 loop = 0; | |||||
u16 opcode, result; | |||||
/* TODO: Split up | |||||
* - Update admin queue stuff | |||||
* - Update link status | |||||
* - Enqueue aq task | |||||
* - Re-enable admin intr | |||||
*/ | |||||
// TODO: Does this belong here? | |||||
if (pf->state & IXL_PF_STATE_EMPR_RESETTING) { | |||||
/* Flag cleared at end of this function */ | |||||
ixl_handle_empr_reset(pf); | |||||
return; | |||||
} | |||||
event.buf_len = IXL_AQ_BUF_SZ; | |||||
event.msg_buf = malloc(event.buf_len, | |||||
M_IXL, M_NOWAIT | M_ZERO); | |||||
if (!event.msg_buf) { | |||||
printf("Unable to allocate adminq memory\n"); | |||||
return; | |||||
} | |||||
/* clean and process any events */ | |||||
do { | |||||
ret = i40e_clean_arq_element(hw, &event, &result); | |||||
if (ret) | |||||
break; | |||||
opcode = LE16_TO_CPU(event.desc.opcode); | |||||
ixl_dbg(pf, IXL_DBG_AQ, | |||||
"%s: Admin Queue event: %#06x\n", __func__, opcode); | |||||
switch (opcode) { | |||||
case i40e_aqc_opc_get_link_status: | |||||
ixl_link_event(pf, &event); | |||||
// TODO: Replace with admin status event function call? | |||||
//ixl_update_link_status(pf); | |||||
break; | |||||
case i40e_aqc_opc_send_msg_to_pf: | |||||
#ifdef PCI_IOV | |||||
ixl_handle_vf_msg(pf, &event); | |||||
#endif | #endif | ||||
break; | |||||
case i40e_aqc_opc_event_lan_overflow: | |||||
break; | |||||
default: | |||||
#ifdef IXL_DEBUG | |||||
printf("AdminQ unknown event %x\n", opcode); | |||||
#endif | |||||
break; | |||||
} | |||||
#ifdef DEV_NETMAP | } while (result && (loop++ < IXL_ADM_LIMIT)); | ||||
netmap_detach(vsi->ifp); | |||||
#endif /* DEV_NETMAP */ | #if 0 // I'm pretty sure this is unnecessary | ||||
ixl_pf_qmgr_destroy(&pf->qmgr); | reg = rd32(hw, I40E_PFINT_ICR0_ENA); | ||||
ixl_free_pci_resources(pf); | reg |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK; | ||||
bus_generic_detach(dev); | wr32(hw, I40E_PFINT_ICR0_ENA, reg); | ||||
if_free(vsi->ifp); | #endif | ||||
ixl_free_vsi(vsi); | free(event.msg_buf, M_IXL); | ||||
IXL_PF_LOCK_DESTROY(pf); | |||||
/* XXX: This updates the link status */ | |||||
if (pf->link_up) { | |||||
if (vsi->link_active == FALSE) { | |||||
vsi->link_active = TRUE; | |||||
/* should actually be negotiated value */ | |||||
iflib_link_state_change(ctx, LINK_STATE_UP, IF_Gbps(10)); | |||||
#if 0 | |||||
ixgbe_ping_all_vfs(adapter); | |||||
#endif | |||||
} | |||||
} else { /* Link down */ | |||||
if (vsi->link_active == TRUE) { | |||||
vsi->link_active = FALSE; | |||||
iflib_link_state_change(ctx, LINK_STATE_DOWN, 0); | |||||
#if 0 | |||||
ixgbe_ping_all_vfs(adapter); | |||||
#endif | |||||
} | |||||
} | |||||
/* Re-enable link interrupts */ | |||||
// IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_LSC); | |||||
/* | |||||
* If there are still messages to process, reschedule ourselves. | |||||
* Otherwise, re-enable our interrupt and go to sleep. | |||||
*/ | |||||
if (result > 0) | |||||
iflib_admin_intr_deferred(ctx); | |||||
else | |||||
/* TODO: Link/adminq interrupt should be re-enabled in IFDI_LINK_INTR_ENABLE */ | |||||
ixl_enable_intr(vsi); | |||||
} | |||||
static void | |||||
ixl_if_multi_set(if_ctx_t ctx) | |||||
{ | |||||
struct ixl_vsi *vsi = iflib_get_softc(ctx); | |||||
struct i40e_hw *hw = vsi->hw; | |||||
int mcnt = 0, flags; | |||||
IOCTL_DEBUGOUT("ixl_if_multi_set: begin"); | |||||
mcnt = if_multiaddr_count(iflib_get_ifp(ctx), MAX_MULTICAST_ADDR); | |||||
/* delete existing MC filters */ | |||||
ixl_del_multi(vsi); | |||||
if (__predict_false(mcnt == MAX_MULTICAST_ADDR)) { | |||||
i40e_aq_set_vsi_multicast_promiscuous(hw, | |||||
vsi->seid, TRUE, NULL); | |||||
return; | |||||
} | |||||
/* (re-)install filters for all mcast addresses */ | |||||
mcnt = if_multi_apply(iflib_get_ifp(ctx), ixl_mc_filter_apply, vsi); | |||||
if (mcnt > 0) { | |||||
flags = (IXL_FILTER_ADD | IXL_FILTER_USED | IXL_FILTER_MC); | |||||
ixl_add_hw_filters(vsi, flags, mcnt); | |||||
} | |||||
IOCTL_DEBUGOUT("ixl_if_multi_set: end"); | |||||
} | |||||
static int | |||||
ixl_if_mtu_set(if_ctx_t ctx, uint32_t mtu) | |||||
{ | |||||
struct ixl_vsi *vsi = iflib_get_softc(ctx); | |||||
IOCTL_DEBUGOUT("ioctl: SIOCSIFMTU (Set Interface MTU)"); | |||||
if (mtu > IXL_MAX_FRAME - ETHER_HDR_LEN - ETHER_CRC_LEN - | |||||
ETHER_VLAN_ENCAP_LEN) | |||||
return (EINVAL); | |||||
vsi->shared->isc_max_frame_size = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN + | |||||
ETHER_VLAN_ENCAP_LEN; | |||||
return (0); | return (0); | ||||
} | } | ||||
/********************************************************************* | static void | ||||
* | ixl_if_media_status(if_ctx_t ctx, struct ifmediareq *ifmr) | ||||
* Shutdown entry point | { | ||||
* | struct ixl_vsi *vsi = iflib_get_softc(ctx); | ||||
**********************************************************************/ | struct ixl_pf *pf = (struct ixl_pf *)vsi->back; | ||||
struct i40e_hw *hw = &pf->hw; | |||||
INIT_DEBUGOUT("ixl_media_status: begin"); | |||||
hw->phy.get_link_info = TRUE; | |||||
i40e_get_link_status(hw, &pf->link_up); | |||||
ifmr->ifm_status = IFM_AVALID; | |||||
ifmr->ifm_active = IFM_ETHER; | |||||
if (!pf->link_up) { | |||||
return; | |||||
} | |||||
ifmr->ifm_status |= IFM_ACTIVE; | |||||
/* Hardware is always full-duplex */ | |||||
ifmr->ifm_active |= IFM_FDX; | |||||
switch (hw->phy.link_info.phy_type) { | |||||
/* 100 M */ | |||||
case I40E_PHY_TYPE_100BASE_TX: | |||||
ifmr->ifm_active |= IFM_100_TX; | |||||
break; | |||||
/* 1 G */ | |||||
case I40E_PHY_TYPE_1000BASE_T: | |||||
ifmr->ifm_active |= IFM_1000_T; | |||||
break; | |||||
case I40E_PHY_TYPE_1000BASE_SX: | |||||
ifmr->ifm_active |= IFM_1000_SX; | |||||
break; | |||||
case I40E_PHY_TYPE_1000BASE_LX: | |||||
ifmr->ifm_active |= IFM_1000_LX; | |||||
break; | |||||
/* 10 G */ | |||||
case I40E_PHY_TYPE_10GBASE_SFPP_CU: | |||||
ifmr->ifm_active |= IFM_10G_TWINAX; | |||||
break; | |||||
case I40E_PHY_TYPE_10GBASE_SR: | |||||
ifmr->ifm_active |= IFM_10G_SR; | |||||
break; | |||||
case I40E_PHY_TYPE_10GBASE_LR: | |||||
ifmr->ifm_active |= IFM_10G_LR; | |||||
break; | |||||
case I40E_PHY_TYPE_10GBASE_T: | |||||
ifmr->ifm_active |= IFM_10G_T; | |||||
break; | |||||
/* 40 G */ | |||||
case I40E_PHY_TYPE_40GBASE_CR4: | |||||
case I40E_PHY_TYPE_40GBASE_CR4_CU: | |||||
ifmr->ifm_active |= IFM_40G_CR4; | |||||
break; | |||||
case I40E_PHY_TYPE_40GBASE_SR4: | |||||
ifmr->ifm_active |= IFM_40G_SR4; | |||||
break; | |||||
case I40E_PHY_TYPE_40GBASE_LR4: | |||||
ifmr->ifm_active |= IFM_40G_LR4; | |||||
break; | |||||
case I40E_PHY_TYPE_1000BASE_KX: | |||||
ifmr->ifm_active |= IFM_1000_KX; | |||||
break; | |||||
/* ERJ: What's the difference between these? */ | |||||
case I40E_PHY_TYPE_10GBASE_CR1_CU: | |||||
case I40E_PHY_TYPE_10GBASE_CR1: | |||||
ifmr->ifm_active |= IFM_10G_CR1; | |||||
break; | |||||
case I40E_PHY_TYPE_10GBASE_KX4: | |||||
ifmr->ifm_active |= IFM_10G_KX4; | |||||
break; | |||||
case I40E_PHY_TYPE_10GBASE_KR: | |||||
ifmr->ifm_active |= IFM_10G_KR; | |||||
break; | |||||
case I40E_PHY_TYPE_20GBASE_KR2: | |||||
ifmr->ifm_active |= IFM_20G_KR2; | |||||
break; | |||||
case I40E_PHY_TYPE_40GBASE_KR4: | |||||
ifmr->ifm_active |= IFM_40G_KR4; | |||||
break; | |||||
case I40E_PHY_TYPE_XLPPI: | |||||
ifmr->ifm_active |= IFM_40G_XLPPI; | |||||
break; | |||||
default: | |||||
ifmr->ifm_active |= IFM_UNKNOWN; | |||||
break; | |||||
} | |||||
/* Report flow control status as well */ | |||||
if (hw->phy.link_info.an_info & I40E_AQ_LINK_PAUSE_TX) | |||||
ifmr->ifm_active |= IFM_ETH_TXPAUSE; | |||||
if (hw->phy.link_info.an_info & I40E_AQ_LINK_PAUSE_RX) | |||||
ifmr->ifm_active |= IFM_ETH_RXPAUSE; | |||||
} | |||||
static int | static int | ||||
ixl_shutdown(device_t dev) | ixl_if_media_change(if_ctx_t ctx) | ||||
{ | { | ||||
struct ixl_pf *pf = device_get_softc(dev); | struct ifmedia *ifm = iflib_get_media(ctx); | ||||
ixl_stop(pf); | |||||
INIT_DEBUGOUT("ixl_media_change: begin"); | |||||
if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER) | |||||
return (EINVAL); | |||||
if_printf(iflib_get_ifp(ctx), "Media change is currently not supported.\n"); | |||||
return (ENODEV); | |||||
} | |||||
static int | |||||
ixl_if_promisc_set(if_ctx_t ctx, int flags) | |||||
{ | |||||
struct ixl_vsi *vsi = iflib_get_softc(ctx); | |||||
struct ifnet *ifp = iflib_get_ifp(ctx); | |||||
struct i40e_hw *hw = vsi->hw; | |||||
int err; | |||||
bool uni = FALSE, multi = FALSE; | |||||
if (flags & IFF_ALLMULTI || | |||||
if_multiaddr_count(ifp, MAX_MULTICAST_ADDR) == MAX_MULTICAST_ADDR) | |||||
multi = TRUE; | |||||
if (flags & IFF_PROMISC) | |||||
uni = TRUE; | |||||
err = i40e_aq_set_vsi_unicast_promiscuous(hw, | |||||
vsi->seid, uni, NULL, false); | |||||
if (err) | |||||
return (err); | |||||
err = i40e_aq_set_vsi_multicast_promiscuous(hw, | |||||
vsi->seid, multi, NULL); | |||||
return (err); | |||||
} | |||||
static void | |||||
ixl_if_timer(if_ctx_t ctx, uint16_t qid) | |||||
{ | |||||
struct ixl_vsi *vsi = iflib_get_softc(ctx); | |||||
struct ixl_pf *pf = vsi->back; | |||||
struct i40e_hw *hw = &pf->hw; | |||||
struct ixl_tx_queue *que = &vsi->tx_queues[qid]; | |||||
u32 mask; | |||||
/* | |||||
** Check status of the queues | |||||
*/ | |||||
mask = (I40E_PFINT_DYN_CTLN_INTENA_MASK | | |||||
I40E_PFINT_DYN_CTLN_SWINT_TRIG_MASK); | |||||
/* If queue param has outstanding work, trigger sw irq */ | |||||
// TODO: TX queues in iflib don't use HW interrupts; does this do anything? | |||||
if (que->busy) | |||||
wr32(hw, I40E_PFINT_DYN_CTLN(que->txr.me), mask); | |||||
if (qid != 0) | |||||
return; | |||||
/* Fire off the adminq task */ | |||||
iflib_admin_intr_deferred(ctx); | |||||
/* Update stats */ | |||||
ixl_update_stats_counters(pf); | |||||
} | |||||
static void | |||||
ixl_if_vlan_register(if_ctx_t ctx, u16 vtag) | |||||
{ | |||||
struct ixl_vsi *vsi = iflib_get_softc(ctx); | |||||
struct i40e_hw *hw = vsi->hw; | |||||
if ((vtag == 0) || (vtag > 4095)) /* Invalid */ | |||||
return; | |||||
++vsi->num_vlans; | |||||
ixl_add_filter(vsi, hw->mac.addr, vtag); | |||||
} | |||||
static void | |||||
ixl_if_vlan_unregister(if_ctx_t ctx, u16 vtag) | |||||
{ | |||||
struct ixl_vsi *vsi = iflib_get_softc(ctx); | |||||
struct i40e_hw *hw = vsi->hw; | |||||
if ((vtag == 0) || (vtag > 4095)) /* Invalid */ | |||||
return; | |||||
--vsi->num_vlans; | |||||
ixl_del_filter(vsi, hw->mac.addr, vtag); | |||||
} | |||||
static uint64_t | |||||
ixl_if_get_counter(if_ctx_t ctx, ift_counter cnt) | |||||
{ | |||||
struct ixl_vsi *vsi = iflib_get_softc(ctx); | |||||
if_t ifp = iflib_get_ifp(ctx); | |||||
switch (cnt) { | |||||
case IFCOUNTER_IPACKETS: | |||||
return (vsi->ipackets); | |||||
case IFCOUNTER_IERRORS: | |||||
return (vsi->ierrors); | |||||
case IFCOUNTER_OPACKETS: | |||||
return (vsi->opackets); | |||||
case IFCOUNTER_OERRORS: | |||||
return (vsi->oerrors); | |||||
case IFCOUNTER_COLLISIONS: | |||||
/* Collisions are by standard impossible in 40G/10G Ethernet */ | |||||
return (0); | |||||
case IFCOUNTER_IBYTES: | |||||
return (vsi->ibytes); | |||||
case IFCOUNTER_OBYTES: | |||||
return (vsi->obytes); | |||||
case IFCOUNTER_IMCASTS: | |||||
return (vsi->imcasts); | |||||
case IFCOUNTER_OMCASTS: | |||||
return (vsi->omcasts); | |||||
case IFCOUNTER_IQDROPS: | |||||
return (vsi->iqdrops); | |||||
case IFCOUNTER_OQDROPS: | |||||
return (vsi->oqdrops); | |||||
case IFCOUNTER_NOPROTO: | |||||
return (vsi->noproto); | |||||
default: | |||||
return (if_get_counter_default(ifp, cnt)); | |||||
} | |||||
} | |||||
static int | |||||
ixl_mc_filter_apply(void *arg, struct ifmultiaddr *ifma, int count __unused) | |||||
{ | |||||
struct ixl_vsi *vsi = arg; | |||||
if (ifma->ifma_addr->sa_family != AF_LINK) | |||||
return (0); | |||||
ixl_add_mc_filter(vsi, | |||||
(u8*)LLADDR((struct sockaddr_dl *) ifma->ifma_addr)); | |||||
return (1); | |||||
} | |||||
static int | |||||
ixl_save_pf_tunables(struct ixl_pf *pf) | |||||
{ | |||||
device_t dev = pf->dev; | |||||
/* Save tunable information */ | |||||
pf->enable_msix = ixl_enable_msix; | |||||
pf->max_queues = ixl_max_queues; | |||||
pf->ringsz = ixl_ring_size; | |||||
pf->enable_tx_fc_filter = ixl_enable_tx_fc_filter; | |||||
pf->dynamic_rx_itr = ixl_dynamic_rx_itr; | |||||
//pf->dynamic_tx_itr = ixl_dynamic_tx_itr; | |||||
//pf->tx_itr = ixl_tx_itr; | |||||
pf->rx_itr = ixl_rx_itr; | |||||
pf->dbg_mask = ixl_core_debug_mask; | |||||
pf->hw.debug_mask = ixl_shared_debug_mask; | |||||
if (ixl_ring_size < IXL_MIN_RING | |||||
|| ixl_ring_size > IXL_MAX_RING | |||||
|| ixl_ring_size % IXL_RING_INCREMENT != 0) { | |||||
device_printf(dev, "Invalid ring_size value of %d set!\n", | |||||
ixl_ring_size); | |||||
device_printf(dev, "ring_size must be between %d and %d, " | |||||
"inclusive, and must be a multiple of %d\n", | |||||
IXL_MIN_RING, IXL_MAX_RING, IXL_RING_INCREMENT); | |||||
return (EINVAL); | |||||
} | |||||
return (0); | |||||
} | |||||
static int | |||||
ixl_attach_get_link_status(struct ixl_pf *pf) | |||||
{ | |||||
struct i40e_hw *hw = &pf->hw; | |||||
device_t dev = pf->dev; | |||||
int error = 0; | |||||
if (((hw->aq.fw_maj_ver == 4) && (hw->aq.fw_min_ver < 33)) || | |||||
(hw->aq.fw_maj_ver < 4)) { | |||||
i40e_msec_delay(75); | |||||
error = i40e_aq_set_link_restart_an(hw, TRUE, NULL); | |||||
if (error) { | |||||
device_printf(dev, "link restart failed, aq_err=%d\n", | |||||
pf->hw.aq.asq_last_status); | |||||
return error; | |||||
} | |||||
} | |||||
/* Determine link state */ | |||||
hw->phy.get_link_info = TRUE; | |||||
i40e_get_link_status(hw, &pf->link_up); | |||||
return (0); | return (0); | ||||
} | } | ||||