1a6a5580cSJeff Kirsher /* 2a6a5580cSJeff Kirsher * Copyright 2008-2010 Cisco Systems, Inc. All rights reserved. 3a6a5580cSJeff Kirsher * Copyright 2007 Nuova Systems, Inc. All rights reserved. 4a6a5580cSJeff Kirsher * 5a6a5580cSJeff Kirsher * This program is free software; you may redistribute it and/or modify 6a6a5580cSJeff Kirsher * it under the terms of the GNU General Public License as published by 7a6a5580cSJeff Kirsher * the Free Software Foundation; version 2 of the License. 8a6a5580cSJeff Kirsher * 9a6a5580cSJeff Kirsher * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 10a6a5580cSJeff Kirsher * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 11a6a5580cSJeff Kirsher * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 12a6a5580cSJeff Kirsher * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 13a6a5580cSJeff Kirsher * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 14a6a5580cSJeff Kirsher * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 15a6a5580cSJeff Kirsher * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 16a6a5580cSJeff Kirsher * SOFTWARE. 17a6a5580cSJeff Kirsher * 18a6a5580cSJeff Kirsher */ 19a6a5580cSJeff Kirsher 20a6a5580cSJeff Kirsher #include <linux/module.h> 21a6a5580cSJeff Kirsher #include <linux/kernel.h> 22a6a5580cSJeff Kirsher #include <linux/string.h> 23a6a5580cSJeff Kirsher #include <linux/errno.h> 24a6a5580cSJeff Kirsher #include <linux/types.h> 25a6a5580cSJeff Kirsher #include <linux/init.h> 26a6a5580cSJeff Kirsher #include <linux/interrupt.h> 27a6a5580cSJeff Kirsher #include <linux/workqueue.h> 28a6a5580cSJeff Kirsher #include <linux/pci.h> 29a6a5580cSJeff Kirsher #include <linux/netdevice.h> 30a6a5580cSJeff Kirsher #include <linux/etherdevice.h> 31a6a5580cSJeff Kirsher #include <linux/if_ether.h> 32a6a5580cSJeff Kirsher #include <linux/if_vlan.h> 33a6a5580cSJeff Kirsher #include <linux/ethtool.h> 34a6a5580cSJeff Kirsher #include <linux/in.h> 35a6a5580cSJeff Kirsher #include <linux/ip.h> 36a6a5580cSJeff Kirsher #include <linux/ipv6.h> 37a6a5580cSJeff Kirsher #include <linux/tcp.h> 38a6a5580cSJeff Kirsher #include <linux/rtnetlink.h> 39a6a5580cSJeff Kirsher #include <linux/prefetch.h> 40a6a5580cSJeff Kirsher #include <net/ip6_checksum.h> 41a6a5580cSJeff Kirsher 42a6a5580cSJeff Kirsher #include "cq_enet_desc.h" 43a6a5580cSJeff Kirsher #include "vnic_dev.h" 44a6a5580cSJeff Kirsher #include "vnic_intr.h" 45a6a5580cSJeff Kirsher #include "vnic_stats.h" 46a6a5580cSJeff Kirsher #include "vnic_vic.h" 47a6a5580cSJeff Kirsher #include "enic_res.h" 48a6a5580cSJeff Kirsher #include "enic.h" 49a6a5580cSJeff Kirsher #include "enic_dev.h" 50a6a5580cSJeff Kirsher #include "enic_pp.h" 51a6a5580cSJeff Kirsher 52a6a5580cSJeff Kirsher #define ENIC_NOTIFY_TIMER_PERIOD (2 * HZ) 53a6a5580cSJeff Kirsher #define WQ_ENET_MAX_DESC_LEN (1 << WQ_ENET_LEN_BITS) 54a6a5580cSJeff Kirsher #define MAX_TSO (1 << 16) 55a6a5580cSJeff Kirsher #define ENIC_DESC_MAX_SPLITS (MAX_TSO / WQ_ENET_MAX_DESC_LEN + 1) 56a6a5580cSJeff Kirsher 57a6a5580cSJeff Kirsher #define PCI_DEVICE_ID_CISCO_VIC_ENET 0x0043 /* ethernet vnic */ 58a6a5580cSJeff Kirsher #define PCI_DEVICE_ID_CISCO_VIC_ENET_DYN 0x0044 /* enet dynamic vnic */ 59a6a5580cSJeff Kirsher 60a6a5580cSJeff Kirsher /* Supported devices */ 61a6a5580cSJeff Kirsher static DEFINE_PCI_DEVICE_TABLE(enic_id_table) = { 62a6a5580cSJeff Kirsher { PCI_VDEVICE(CISCO, PCI_DEVICE_ID_CISCO_VIC_ENET) }, 63a6a5580cSJeff Kirsher { PCI_VDEVICE(CISCO, PCI_DEVICE_ID_CISCO_VIC_ENET_DYN) }, 64a6a5580cSJeff Kirsher { 0, } /* end of table */ 65a6a5580cSJeff Kirsher }; 66a6a5580cSJeff Kirsher 67a6a5580cSJeff Kirsher MODULE_DESCRIPTION(DRV_DESCRIPTION); 68a6a5580cSJeff Kirsher MODULE_AUTHOR("Scott Feldman <scofeldm@cisco.com>"); 69a6a5580cSJeff Kirsher MODULE_LICENSE("GPL"); 70a6a5580cSJeff Kirsher MODULE_VERSION(DRV_VERSION); 71a6a5580cSJeff Kirsher MODULE_DEVICE_TABLE(pci, enic_id_table); 72a6a5580cSJeff Kirsher 73a6a5580cSJeff Kirsher struct enic_stat { 74a6a5580cSJeff Kirsher char name[ETH_GSTRING_LEN]; 75a6a5580cSJeff Kirsher unsigned int offset; 76a6a5580cSJeff Kirsher }; 77a6a5580cSJeff Kirsher 78a6a5580cSJeff Kirsher #define ENIC_TX_STAT(stat) \ 79a6a5580cSJeff Kirsher { .name = #stat, .offset = offsetof(struct vnic_tx_stats, stat) / 8 } 80a6a5580cSJeff Kirsher #define ENIC_RX_STAT(stat) \ 81a6a5580cSJeff Kirsher { .name = #stat, .offset = offsetof(struct vnic_rx_stats, stat) / 8 } 82a6a5580cSJeff Kirsher 83a6a5580cSJeff Kirsher static const struct enic_stat enic_tx_stats[] = { 84a6a5580cSJeff Kirsher ENIC_TX_STAT(tx_frames_ok), 85a6a5580cSJeff Kirsher ENIC_TX_STAT(tx_unicast_frames_ok), 86a6a5580cSJeff Kirsher ENIC_TX_STAT(tx_multicast_frames_ok), 87a6a5580cSJeff Kirsher ENIC_TX_STAT(tx_broadcast_frames_ok), 88a6a5580cSJeff Kirsher ENIC_TX_STAT(tx_bytes_ok), 89a6a5580cSJeff Kirsher ENIC_TX_STAT(tx_unicast_bytes_ok), 90a6a5580cSJeff Kirsher ENIC_TX_STAT(tx_multicast_bytes_ok), 91a6a5580cSJeff Kirsher ENIC_TX_STAT(tx_broadcast_bytes_ok), 92a6a5580cSJeff Kirsher ENIC_TX_STAT(tx_drops), 93a6a5580cSJeff Kirsher ENIC_TX_STAT(tx_errors), 94a6a5580cSJeff Kirsher ENIC_TX_STAT(tx_tso), 95a6a5580cSJeff Kirsher }; 96a6a5580cSJeff Kirsher 97a6a5580cSJeff Kirsher static const struct enic_stat enic_rx_stats[] = { 98a6a5580cSJeff Kirsher ENIC_RX_STAT(rx_frames_ok), 99a6a5580cSJeff Kirsher ENIC_RX_STAT(rx_frames_total), 100a6a5580cSJeff Kirsher ENIC_RX_STAT(rx_unicast_frames_ok), 101a6a5580cSJeff Kirsher ENIC_RX_STAT(rx_multicast_frames_ok), 102a6a5580cSJeff Kirsher ENIC_RX_STAT(rx_broadcast_frames_ok), 103a6a5580cSJeff Kirsher ENIC_RX_STAT(rx_bytes_ok), 104a6a5580cSJeff Kirsher ENIC_RX_STAT(rx_unicast_bytes_ok), 105a6a5580cSJeff Kirsher ENIC_RX_STAT(rx_multicast_bytes_ok), 106a6a5580cSJeff Kirsher ENIC_RX_STAT(rx_broadcast_bytes_ok), 107a6a5580cSJeff Kirsher ENIC_RX_STAT(rx_drop), 108a6a5580cSJeff Kirsher ENIC_RX_STAT(rx_no_bufs), 109a6a5580cSJeff Kirsher ENIC_RX_STAT(rx_errors), 110a6a5580cSJeff Kirsher ENIC_RX_STAT(rx_rss), 111a6a5580cSJeff Kirsher ENIC_RX_STAT(rx_crc_errors), 112a6a5580cSJeff Kirsher ENIC_RX_STAT(rx_frames_64), 113a6a5580cSJeff Kirsher ENIC_RX_STAT(rx_frames_127), 114a6a5580cSJeff Kirsher ENIC_RX_STAT(rx_frames_255), 115a6a5580cSJeff Kirsher ENIC_RX_STAT(rx_frames_511), 116a6a5580cSJeff Kirsher ENIC_RX_STAT(rx_frames_1023), 117a6a5580cSJeff Kirsher ENIC_RX_STAT(rx_frames_1518), 118a6a5580cSJeff Kirsher ENIC_RX_STAT(rx_frames_to_max), 119a6a5580cSJeff Kirsher }; 120a6a5580cSJeff Kirsher 121a6a5580cSJeff Kirsher static const unsigned int enic_n_tx_stats = ARRAY_SIZE(enic_tx_stats); 122a6a5580cSJeff Kirsher static const unsigned int enic_n_rx_stats = ARRAY_SIZE(enic_rx_stats); 123a6a5580cSJeff Kirsher 124a6a5580cSJeff Kirsher static int enic_is_dynamic(struct enic *enic) 125a6a5580cSJeff Kirsher { 126a6a5580cSJeff Kirsher return enic->pdev->device == PCI_DEVICE_ID_CISCO_VIC_ENET_DYN; 127a6a5580cSJeff Kirsher } 128a6a5580cSJeff Kirsher 129a6a5580cSJeff Kirsher static inline unsigned int enic_cq_rq(struct enic *enic, unsigned int rq) 130a6a5580cSJeff Kirsher { 131a6a5580cSJeff Kirsher return rq; 132a6a5580cSJeff Kirsher } 133a6a5580cSJeff Kirsher 134a6a5580cSJeff Kirsher static inline unsigned int enic_cq_wq(struct enic *enic, unsigned int wq) 135a6a5580cSJeff Kirsher { 136a6a5580cSJeff Kirsher return enic->rq_count + wq; 137a6a5580cSJeff Kirsher } 138a6a5580cSJeff Kirsher 139a6a5580cSJeff Kirsher static inline unsigned int enic_legacy_io_intr(void) 140a6a5580cSJeff Kirsher { 141a6a5580cSJeff Kirsher return 0; 142a6a5580cSJeff Kirsher } 143a6a5580cSJeff Kirsher 144a6a5580cSJeff Kirsher static inline unsigned int enic_legacy_err_intr(void) 145a6a5580cSJeff Kirsher { 146a6a5580cSJeff Kirsher return 1; 147a6a5580cSJeff Kirsher } 148a6a5580cSJeff Kirsher 149a6a5580cSJeff Kirsher static inline unsigned int enic_legacy_notify_intr(void) 150a6a5580cSJeff Kirsher { 151a6a5580cSJeff Kirsher return 2; 152a6a5580cSJeff Kirsher } 153a6a5580cSJeff Kirsher 154a6a5580cSJeff Kirsher static inline unsigned int enic_msix_rq_intr(struct enic *enic, unsigned int rq) 155a6a5580cSJeff Kirsher { 156a6a5580cSJeff Kirsher return enic->cq[enic_cq_rq(enic, rq)].interrupt_offset; 157a6a5580cSJeff Kirsher } 158a6a5580cSJeff Kirsher 159a6a5580cSJeff Kirsher static inline unsigned int enic_msix_wq_intr(struct enic *enic, unsigned int wq) 160a6a5580cSJeff Kirsher { 161a6a5580cSJeff Kirsher return enic->cq[enic_cq_wq(enic, wq)].interrupt_offset; 162a6a5580cSJeff Kirsher } 163a6a5580cSJeff Kirsher 164a6a5580cSJeff Kirsher static inline unsigned int enic_msix_err_intr(struct enic *enic) 165a6a5580cSJeff Kirsher { 166a6a5580cSJeff Kirsher return enic->rq_count + enic->wq_count; 167a6a5580cSJeff Kirsher } 168a6a5580cSJeff Kirsher 169a6a5580cSJeff Kirsher static inline unsigned int enic_msix_notify_intr(struct enic *enic) 170a6a5580cSJeff Kirsher { 171a6a5580cSJeff Kirsher return enic->rq_count + enic->wq_count + 1; 172a6a5580cSJeff Kirsher } 173a6a5580cSJeff Kirsher 174a6a5580cSJeff Kirsher static int enic_get_settings(struct net_device *netdev, 175a6a5580cSJeff Kirsher struct ethtool_cmd *ecmd) 176a6a5580cSJeff Kirsher { 177a6a5580cSJeff Kirsher struct enic *enic = netdev_priv(netdev); 178a6a5580cSJeff Kirsher 179a6a5580cSJeff Kirsher ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE); 180a6a5580cSJeff Kirsher ecmd->advertising = (ADVERTISED_10000baseT_Full | ADVERTISED_FIBRE); 181a6a5580cSJeff Kirsher ecmd->port = PORT_FIBRE; 182a6a5580cSJeff Kirsher ecmd->transceiver = XCVR_EXTERNAL; 183a6a5580cSJeff Kirsher 184a6a5580cSJeff Kirsher if (netif_carrier_ok(netdev)) { 185a6a5580cSJeff Kirsher ethtool_cmd_speed_set(ecmd, vnic_dev_port_speed(enic->vdev)); 186a6a5580cSJeff Kirsher ecmd->duplex = DUPLEX_FULL; 187a6a5580cSJeff Kirsher } else { 188a6a5580cSJeff Kirsher ethtool_cmd_speed_set(ecmd, -1); 189a6a5580cSJeff Kirsher ecmd->duplex = -1; 190a6a5580cSJeff Kirsher } 191a6a5580cSJeff Kirsher 192a6a5580cSJeff Kirsher ecmd->autoneg = AUTONEG_DISABLE; 193a6a5580cSJeff Kirsher 194a6a5580cSJeff Kirsher return 0; 195a6a5580cSJeff Kirsher } 196a6a5580cSJeff Kirsher 197a6a5580cSJeff Kirsher static void enic_get_drvinfo(struct net_device *netdev, 198a6a5580cSJeff Kirsher struct ethtool_drvinfo *drvinfo) 199a6a5580cSJeff Kirsher { 200a6a5580cSJeff Kirsher struct enic *enic = netdev_priv(netdev); 201a6a5580cSJeff Kirsher struct vnic_devcmd_fw_info *fw_info; 202a6a5580cSJeff Kirsher 203a6a5580cSJeff Kirsher enic_dev_fw_info(enic, &fw_info); 204a6a5580cSJeff Kirsher 205a6a5580cSJeff Kirsher strncpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver)); 206a6a5580cSJeff Kirsher strncpy(drvinfo->version, DRV_VERSION, sizeof(drvinfo->version)); 207a6a5580cSJeff Kirsher strncpy(drvinfo->fw_version, fw_info->fw_version, 208a6a5580cSJeff Kirsher sizeof(drvinfo->fw_version)); 209a6a5580cSJeff Kirsher strncpy(drvinfo->bus_info, pci_name(enic->pdev), 210a6a5580cSJeff Kirsher sizeof(drvinfo->bus_info)); 211a6a5580cSJeff Kirsher } 212a6a5580cSJeff Kirsher 213a6a5580cSJeff Kirsher static void enic_get_strings(struct net_device *netdev, u32 stringset, u8 *data) 214a6a5580cSJeff Kirsher { 215a6a5580cSJeff Kirsher unsigned int i; 216a6a5580cSJeff Kirsher 217a6a5580cSJeff Kirsher switch (stringset) { 218a6a5580cSJeff Kirsher case ETH_SS_STATS: 219a6a5580cSJeff Kirsher for (i = 0; i < enic_n_tx_stats; i++) { 220a6a5580cSJeff Kirsher memcpy(data, enic_tx_stats[i].name, ETH_GSTRING_LEN); 221a6a5580cSJeff Kirsher data += ETH_GSTRING_LEN; 222a6a5580cSJeff Kirsher } 223a6a5580cSJeff Kirsher for (i = 0; i < enic_n_rx_stats; i++) { 224a6a5580cSJeff Kirsher memcpy(data, enic_rx_stats[i].name, ETH_GSTRING_LEN); 225a6a5580cSJeff Kirsher data += ETH_GSTRING_LEN; 226a6a5580cSJeff Kirsher } 227a6a5580cSJeff Kirsher break; 228a6a5580cSJeff Kirsher } 229a6a5580cSJeff Kirsher } 230a6a5580cSJeff Kirsher 231a6a5580cSJeff Kirsher static int enic_get_sset_count(struct net_device *netdev, int sset) 232a6a5580cSJeff Kirsher { 233a6a5580cSJeff Kirsher switch (sset) { 234a6a5580cSJeff Kirsher case ETH_SS_STATS: 235a6a5580cSJeff Kirsher return enic_n_tx_stats + enic_n_rx_stats; 236a6a5580cSJeff Kirsher default: 237a6a5580cSJeff Kirsher return -EOPNOTSUPP; 238a6a5580cSJeff Kirsher } 239a6a5580cSJeff Kirsher } 240a6a5580cSJeff Kirsher 241a6a5580cSJeff Kirsher static void enic_get_ethtool_stats(struct net_device *netdev, 242a6a5580cSJeff Kirsher struct ethtool_stats *stats, u64 *data) 243a6a5580cSJeff Kirsher { 244a6a5580cSJeff Kirsher struct enic *enic = netdev_priv(netdev); 245a6a5580cSJeff Kirsher struct vnic_stats *vstats; 246a6a5580cSJeff Kirsher unsigned int i; 247a6a5580cSJeff Kirsher 248a6a5580cSJeff Kirsher enic_dev_stats_dump(enic, &vstats); 249a6a5580cSJeff Kirsher 250a6a5580cSJeff Kirsher for (i = 0; i < enic_n_tx_stats; i++) 251a6a5580cSJeff Kirsher *(data++) = ((u64 *)&vstats->tx)[enic_tx_stats[i].offset]; 252a6a5580cSJeff Kirsher for (i = 0; i < enic_n_rx_stats; i++) 253a6a5580cSJeff Kirsher *(data++) = ((u64 *)&vstats->rx)[enic_rx_stats[i].offset]; 254a6a5580cSJeff Kirsher } 255a6a5580cSJeff Kirsher 256a6a5580cSJeff Kirsher static u32 enic_get_msglevel(struct net_device *netdev) 257a6a5580cSJeff Kirsher { 258a6a5580cSJeff Kirsher struct enic *enic = netdev_priv(netdev); 259a6a5580cSJeff Kirsher return enic->msg_enable; 260a6a5580cSJeff Kirsher } 261a6a5580cSJeff Kirsher 262a6a5580cSJeff Kirsher static void enic_set_msglevel(struct net_device *netdev, u32 value) 263a6a5580cSJeff Kirsher { 264a6a5580cSJeff Kirsher struct enic *enic = netdev_priv(netdev); 265a6a5580cSJeff Kirsher enic->msg_enable = value; 266a6a5580cSJeff Kirsher } 267a6a5580cSJeff Kirsher 268a6a5580cSJeff Kirsher static int enic_get_coalesce(struct net_device *netdev, 269a6a5580cSJeff Kirsher struct ethtool_coalesce *ecmd) 270a6a5580cSJeff Kirsher { 271a6a5580cSJeff Kirsher struct enic *enic = netdev_priv(netdev); 272a6a5580cSJeff Kirsher 273a6a5580cSJeff Kirsher ecmd->tx_coalesce_usecs = enic->tx_coalesce_usecs; 274a6a5580cSJeff Kirsher ecmd->rx_coalesce_usecs = enic->rx_coalesce_usecs; 275a6a5580cSJeff Kirsher 276a6a5580cSJeff Kirsher return 0; 277a6a5580cSJeff Kirsher } 278a6a5580cSJeff Kirsher 279a6a5580cSJeff Kirsher static int enic_set_coalesce(struct net_device *netdev, 280a6a5580cSJeff Kirsher struct ethtool_coalesce *ecmd) 281a6a5580cSJeff Kirsher { 282a6a5580cSJeff Kirsher struct enic *enic = netdev_priv(netdev); 283a6a5580cSJeff Kirsher u32 tx_coalesce_usecs; 284a6a5580cSJeff Kirsher u32 rx_coalesce_usecs; 285a6a5580cSJeff Kirsher unsigned int i, intr; 286a6a5580cSJeff Kirsher 287a6a5580cSJeff Kirsher tx_coalesce_usecs = min_t(u32, ecmd->tx_coalesce_usecs, 288a6a5580cSJeff Kirsher vnic_dev_get_intr_coal_timer_max(enic->vdev)); 289a6a5580cSJeff Kirsher rx_coalesce_usecs = min_t(u32, ecmd->rx_coalesce_usecs, 290a6a5580cSJeff Kirsher vnic_dev_get_intr_coal_timer_max(enic->vdev)); 291a6a5580cSJeff Kirsher 292a6a5580cSJeff Kirsher switch (vnic_dev_get_intr_mode(enic->vdev)) { 293a6a5580cSJeff Kirsher case VNIC_DEV_INTR_MODE_INTX: 294a6a5580cSJeff Kirsher if (tx_coalesce_usecs != rx_coalesce_usecs) 295a6a5580cSJeff Kirsher return -EINVAL; 296a6a5580cSJeff Kirsher 297a6a5580cSJeff Kirsher intr = enic_legacy_io_intr(); 298a6a5580cSJeff Kirsher vnic_intr_coalescing_timer_set(&enic->intr[intr], 299a6a5580cSJeff Kirsher tx_coalesce_usecs); 300a6a5580cSJeff Kirsher break; 301a6a5580cSJeff Kirsher case VNIC_DEV_INTR_MODE_MSI: 302a6a5580cSJeff Kirsher if (tx_coalesce_usecs != rx_coalesce_usecs) 303a6a5580cSJeff Kirsher return -EINVAL; 304a6a5580cSJeff Kirsher 305a6a5580cSJeff Kirsher vnic_intr_coalescing_timer_set(&enic->intr[0], 306a6a5580cSJeff Kirsher tx_coalesce_usecs); 307a6a5580cSJeff Kirsher break; 308a6a5580cSJeff Kirsher case VNIC_DEV_INTR_MODE_MSIX: 309a6a5580cSJeff Kirsher for (i = 0; i < enic->wq_count; i++) { 310a6a5580cSJeff Kirsher intr = enic_msix_wq_intr(enic, i); 311a6a5580cSJeff Kirsher vnic_intr_coalescing_timer_set(&enic->intr[intr], 312a6a5580cSJeff Kirsher tx_coalesce_usecs); 313a6a5580cSJeff Kirsher } 314a6a5580cSJeff Kirsher 315a6a5580cSJeff Kirsher for (i = 0; i < enic->rq_count; i++) { 316a6a5580cSJeff Kirsher intr = enic_msix_rq_intr(enic, i); 317a6a5580cSJeff Kirsher vnic_intr_coalescing_timer_set(&enic->intr[intr], 318a6a5580cSJeff Kirsher rx_coalesce_usecs); 319a6a5580cSJeff Kirsher } 320a6a5580cSJeff Kirsher 321a6a5580cSJeff Kirsher break; 322a6a5580cSJeff Kirsher default: 323a6a5580cSJeff Kirsher break; 324a6a5580cSJeff Kirsher } 325a6a5580cSJeff Kirsher 326a6a5580cSJeff Kirsher enic->tx_coalesce_usecs = tx_coalesce_usecs; 327a6a5580cSJeff Kirsher enic->rx_coalesce_usecs = rx_coalesce_usecs; 328a6a5580cSJeff Kirsher 329a6a5580cSJeff Kirsher return 0; 330a6a5580cSJeff Kirsher } 331a6a5580cSJeff Kirsher 332a6a5580cSJeff Kirsher static const struct ethtool_ops enic_ethtool_ops = { 333a6a5580cSJeff Kirsher .get_settings = enic_get_settings, 334a6a5580cSJeff Kirsher .get_drvinfo = enic_get_drvinfo, 335a6a5580cSJeff Kirsher .get_msglevel = enic_get_msglevel, 336a6a5580cSJeff Kirsher .set_msglevel = enic_set_msglevel, 337a6a5580cSJeff Kirsher .get_link = ethtool_op_get_link, 338a6a5580cSJeff Kirsher .get_strings = enic_get_strings, 339a6a5580cSJeff Kirsher .get_sset_count = enic_get_sset_count, 340a6a5580cSJeff Kirsher .get_ethtool_stats = enic_get_ethtool_stats, 341a6a5580cSJeff Kirsher .get_coalesce = enic_get_coalesce, 342a6a5580cSJeff Kirsher .set_coalesce = enic_set_coalesce, 343a6a5580cSJeff Kirsher }; 344a6a5580cSJeff Kirsher 345a6a5580cSJeff Kirsher static void enic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf) 346a6a5580cSJeff Kirsher { 347a6a5580cSJeff Kirsher struct enic *enic = vnic_dev_priv(wq->vdev); 348a6a5580cSJeff Kirsher 349a6a5580cSJeff Kirsher if (buf->sop) 350a6a5580cSJeff Kirsher pci_unmap_single(enic->pdev, buf->dma_addr, 351a6a5580cSJeff Kirsher buf->len, PCI_DMA_TODEVICE); 352a6a5580cSJeff Kirsher else 353a6a5580cSJeff Kirsher pci_unmap_page(enic->pdev, buf->dma_addr, 354a6a5580cSJeff Kirsher buf->len, PCI_DMA_TODEVICE); 355a6a5580cSJeff Kirsher 356a6a5580cSJeff Kirsher if (buf->os_buf) 357a6a5580cSJeff Kirsher dev_kfree_skb_any(buf->os_buf); 358a6a5580cSJeff Kirsher } 359a6a5580cSJeff Kirsher 360a6a5580cSJeff Kirsher static void enic_wq_free_buf(struct vnic_wq *wq, 361a6a5580cSJeff Kirsher struct cq_desc *cq_desc, struct vnic_wq_buf *buf, void *opaque) 362a6a5580cSJeff Kirsher { 363a6a5580cSJeff Kirsher enic_free_wq_buf(wq, buf); 364a6a5580cSJeff Kirsher } 365a6a5580cSJeff Kirsher 366a6a5580cSJeff Kirsher static int enic_wq_service(struct vnic_dev *vdev, struct cq_desc *cq_desc, 367a6a5580cSJeff Kirsher u8 type, u16 q_number, u16 completed_index, void *opaque) 368a6a5580cSJeff Kirsher { 369a6a5580cSJeff Kirsher struct enic *enic = vnic_dev_priv(vdev); 370a6a5580cSJeff Kirsher 371a6a5580cSJeff Kirsher spin_lock(&enic->wq_lock[q_number]); 372a6a5580cSJeff Kirsher 373a6a5580cSJeff Kirsher vnic_wq_service(&enic->wq[q_number], cq_desc, 374a6a5580cSJeff Kirsher completed_index, enic_wq_free_buf, 375a6a5580cSJeff Kirsher opaque); 376a6a5580cSJeff Kirsher 377a6a5580cSJeff Kirsher if (netif_queue_stopped(enic->netdev) && 378a6a5580cSJeff Kirsher vnic_wq_desc_avail(&enic->wq[q_number]) >= 379a6a5580cSJeff Kirsher (MAX_SKB_FRAGS + ENIC_DESC_MAX_SPLITS)) 380a6a5580cSJeff Kirsher netif_wake_queue(enic->netdev); 381a6a5580cSJeff Kirsher 382a6a5580cSJeff Kirsher spin_unlock(&enic->wq_lock[q_number]); 383a6a5580cSJeff Kirsher 384a6a5580cSJeff Kirsher return 0; 385a6a5580cSJeff Kirsher } 386a6a5580cSJeff Kirsher 387a6a5580cSJeff Kirsher static void enic_log_q_error(struct enic *enic) 388a6a5580cSJeff Kirsher { 389a6a5580cSJeff Kirsher unsigned int i; 390a6a5580cSJeff Kirsher u32 error_status; 391a6a5580cSJeff Kirsher 392a6a5580cSJeff Kirsher for (i = 0; i < enic->wq_count; i++) { 393a6a5580cSJeff Kirsher error_status = vnic_wq_error_status(&enic->wq[i]); 394a6a5580cSJeff Kirsher if (error_status) 395a6a5580cSJeff Kirsher netdev_err(enic->netdev, "WQ[%d] error_status %d\n", 396a6a5580cSJeff Kirsher i, error_status); 397a6a5580cSJeff Kirsher } 398a6a5580cSJeff Kirsher 399a6a5580cSJeff Kirsher for (i = 0; i < enic->rq_count; i++) { 400a6a5580cSJeff Kirsher error_status = vnic_rq_error_status(&enic->rq[i]); 401a6a5580cSJeff Kirsher if (error_status) 402a6a5580cSJeff Kirsher netdev_err(enic->netdev, "RQ[%d] error_status %d\n", 403a6a5580cSJeff Kirsher i, error_status); 404a6a5580cSJeff Kirsher } 405a6a5580cSJeff Kirsher } 406a6a5580cSJeff Kirsher 407a6a5580cSJeff Kirsher static void enic_msglvl_check(struct enic *enic) 408a6a5580cSJeff Kirsher { 409a6a5580cSJeff Kirsher u32 msg_enable = vnic_dev_msg_lvl(enic->vdev); 410a6a5580cSJeff Kirsher 411a6a5580cSJeff Kirsher if (msg_enable != enic->msg_enable) { 412a6a5580cSJeff Kirsher netdev_info(enic->netdev, "msg lvl changed from 0x%x to 0x%x\n", 413a6a5580cSJeff Kirsher enic->msg_enable, msg_enable); 414a6a5580cSJeff Kirsher enic->msg_enable = msg_enable; 415a6a5580cSJeff Kirsher } 416a6a5580cSJeff Kirsher } 417a6a5580cSJeff Kirsher 418a6a5580cSJeff Kirsher static void enic_mtu_check(struct enic *enic) 419a6a5580cSJeff Kirsher { 420a6a5580cSJeff Kirsher u32 mtu = vnic_dev_mtu(enic->vdev); 421a6a5580cSJeff Kirsher struct net_device *netdev = enic->netdev; 422a6a5580cSJeff Kirsher 423a6a5580cSJeff Kirsher if (mtu && mtu != enic->port_mtu) { 424a6a5580cSJeff Kirsher enic->port_mtu = mtu; 425a6a5580cSJeff Kirsher if (enic_is_dynamic(enic)) { 426a6a5580cSJeff Kirsher mtu = max_t(int, ENIC_MIN_MTU, 427a6a5580cSJeff Kirsher min_t(int, ENIC_MAX_MTU, mtu)); 428a6a5580cSJeff Kirsher if (mtu != netdev->mtu) 429a6a5580cSJeff Kirsher schedule_work(&enic->change_mtu_work); 430a6a5580cSJeff Kirsher } else { 431a6a5580cSJeff Kirsher if (mtu < netdev->mtu) 432a6a5580cSJeff Kirsher netdev_warn(netdev, 433a6a5580cSJeff Kirsher "interface MTU (%d) set higher " 434a6a5580cSJeff Kirsher "than switch port MTU (%d)\n", 435a6a5580cSJeff Kirsher netdev->mtu, mtu); 436a6a5580cSJeff Kirsher } 437a6a5580cSJeff Kirsher } 438a6a5580cSJeff Kirsher } 439a6a5580cSJeff Kirsher 440a6a5580cSJeff Kirsher static void enic_link_check(struct enic *enic) 441a6a5580cSJeff Kirsher { 442a6a5580cSJeff Kirsher int link_status = vnic_dev_link_status(enic->vdev); 443a6a5580cSJeff Kirsher int carrier_ok = netif_carrier_ok(enic->netdev); 444a6a5580cSJeff Kirsher 445a6a5580cSJeff Kirsher if (link_status && !carrier_ok) { 446a6a5580cSJeff Kirsher netdev_info(enic->netdev, "Link UP\n"); 447a6a5580cSJeff Kirsher netif_carrier_on(enic->netdev); 448a6a5580cSJeff Kirsher } else if (!link_status && carrier_ok) { 449a6a5580cSJeff Kirsher netdev_info(enic->netdev, "Link DOWN\n"); 450a6a5580cSJeff Kirsher netif_carrier_off(enic->netdev); 451a6a5580cSJeff Kirsher } 452a6a5580cSJeff Kirsher } 453a6a5580cSJeff Kirsher 454a6a5580cSJeff Kirsher static void enic_notify_check(struct enic *enic) 455a6a5580cSJeff Kirsher { 456a6a5580cSJeff Kirsher enic_msglvl_check(enic); 457a6a5580cSJeff Kirsher enic_mtu_check(enic); 458a6a5580cSJeff Kirsher enic_link_check(enic); 459a6a5580cSJeff Kirsher } 460a6a5580cSJeff Kirsher 461a6a5580cSJeff Kirsher #define ENIC_TEST_INTR(pba, i) (pba & (1 << i)) 462a6a5580cSJeff Kirsher 463a6a5580cSJeff Kirsher static irqreturn_t enic_isr_legacy(int irq, void *data) 464a6a5580cSJeff Kirsher { 465a6a5580cSJeff Kirsher struct net_device *netdev = data; 466a6a5580cSJeff Kirsher struct enic *enic = netdev_priv(netdev); 467a6a5580cSJeff Kirsher unsigned int io_intr = enic_legacy_io_intr(); 468a6a5580cSJeff Kirsher unsigned int err_intr = enic_legacy_err_intr(); 469a6a5580cSJeff Kirsher unsigned int notify_intr = enic_legacy_notify_intr(); 470a6a5580cSJeff Kirsher u32 pba; 471a6a5580cSJeff Kirsher 472a6a5580cSJeff Kirsher vnic_intr_mask(&enic->intr[io_intr]); 473a6a5580cSJeff Kirsher 474a6a5580cSJeff Kirsher pba = vnic_intr_legacy_pba(enic->legacy_pba); 475a6a5580cSJeff Kirsher if (!pba) { 476a6a5580cSJeff Kirsher vnic_intr_unmask(&enic->intr[io_intr]); 477a6a5580cSJeff Kirsher return IRQ_NONE; /* not our interrupt */ 478a6a5580cSJeff Kirsher } 479a6a5580cSJeff Kirsher 480a6a5580cSJeff Kirsher if (ENIC_TEST_INTR(pba, notify_intr)) { 481a6a5580cSJeff Kirsher vnic_intr_return_all_credits(&enic->intr[notify_intr]); 482a6a5580cSJeff Kirsher enic_notify_check(enic); 483a6a5580cSJeff Kirsher } 484a6a5580cSJeff Kirsher 485a6a5580cSJeff Kirsher if (ENIC_TEST_INTR(pba, err_intr)) { 486a6a5580cSJeff Kirsher vnic_intr_return_all_credits(&enic->intr[err_intr]); 487a6a5580cSJeff Kirsher enic_log_q_error(enic); 488a6a5580cSJeff Kirsher /* schedule recovery from WQ/RQ error */ 489a6a5580cSJeff Kirsher schedule_work(&enic->reset); 490a6a5580cSJeff Kirsher return IRQ_HANDLED; 491a6a5580cSJeff Kirsher } 492a6a5580cSJeff Kirsher 493a6a5580cSJeff Kirsher if (ENIC_TEST_INTR(pba, io_intr)) { 494a6a5580cSJeff Kirsher if (napi_schedule_prep(&enic->napi[0])) 495a6a5580cSJeff Kirsher __napi_schedule(&enic->napi[0]); 496a6a5580cSJeff Kirsher } else { 497a6a5580cSJeff Kirsher vnic_intr_unmask(&enic->intr[io_intr]); 498a6a5580cSJeff Kirsher } 499a6a5580cSJeff Kirsher 500a6a5580cSJeff Kirsher return IRQ_HANDLED; 501a6a5580cSJeff Kirsher } 502a6a5580cSJeff Kirsher 503a6a5580cSJeff Kirsher static irqreturn_t enic_isr_msi(int irq, void *data) 504a6a5580cSJeff Kirsher { 505a6a5580cSJeff Kirsher struct enic *enic = data; 506a6a5580cSJeff Kirsher 507a6a5580cSJeff Kirsher /* With MSI, there is no sharing of interrupts, so this is 508a6a5580cSJeff Kirsher * our interrupt and there is no need to ack it. The device 509a6a5580cSJeff Kirsher * is not providing per-vector masking, so the OS will not 510a6a5580cSJeff Kirsher * write to PCI config space to mask/unmask the interrupt. 511a6a5580cSJeff Kirsher * We're using mask_on_assertion for MSI, so the device 512a6a5580cSJeff Kirsher * automatically masks the interrupt when the interrupt is 513a6a5580cSJeff Kirsher * generated. Later, when exiting polling, the interrupt 514a6a5580cSJeff Kirsher * will be unmasked (see enic_poll). 515a6a5580cSJeff Kirsher * 516a6a5580cSJeff Kirsher * Also, the device uses the same PCIe Traffic Class (TC) 517a6a5580cSJeff Kirsher * for Memory Write data and MSI, so there are no ordering 518a6a5580cSJeff Kirsher * issues; the MSI will always arrive at the Root Complex 519a6a5580cSJeff Kirsher * _after_ corresponding Memory Writes (i.e. descriptor 520a6a5580cSJeff Kirsher * writes). 521a6a5580cSJeff Kirsher */ 522a6a5580cSJeff Kirsher 523a6a5580cSJeff Kirsher napi_schedule(&enic->napi[0]); 524a6a5580cSJeff Kirsher 525a6a5580cSJeff Kirsher return IRQ_HANDLED; 526a6a5580cSJeff Kirsher } 527a6a5580cSJeff Kirsher 528a6a5580cSJeff Kirsher static irqreturn_t enic_isr_msix_rq(int irq, void *data) 529a6a5580cSJeff Kirsher { 530a6a5580cSJeff Kirsher struct napi_struct *napi = data; 531a6a5580cSJeff Kirsher 532a6a5580cSJeff Kirsher /* schedule NAPI polling for RQ cleanup */ 533a6a5580cSJeff Kirsher napi_schedule(napi); 534a6a5580cSJeff Kirsher 535a6a5580cSJeff Kirsher return IRQ_HANDLED; 536a6a5580cSJeff Kirsher } 537a6a5580cSJeff Kirsher 538a6a5580cSJeff Kirsher static irqreturn_t enic_isr_msix_wq(int irq, void *data) 539a6a5580cSJeff Kirsher { 540a6a5580cSJeff Kirsher struct enic *enic = data; 541a6a5580cSJeff Kirsher unsigned int cq = enic_cq_wq(enic, 0); 542a6a5580cSJeff Kirsher unsigned int intr = enic_msix_wq_intr(enic, 0); 543a6a5580cSJeff Kirsher unsigned int wq_work_to_do = -1; /* no limit */ 544a6a5580cSJeff Kirsher unsigned int wq_work_done; 545a6a5580cSJeff Kirsher 546a6a5580cSJeff Kirsher wq_work_done = vnic_cq_service(&enic->cq[cq], 547a6a5580cSJeff Kirsher wq_work_to_do, enic_wq_service, NULL); 548a6a5580cSJeff Kirsher 549a6a5580cSJeff Kirsher vnic_intr_return_credits(&enic->intr[intr], 550a6a5580cSJeff Kirsher wq_work_done, 551a6a5580cSJeff Kirsher 1 /* unmask intr */, 552a6a5580cSJeff Kirsher 1 /* reset intr timer */); 553a6a5580cSJeff Kirsher 554a6a5580cSJeff Kirsher return IRQ_HANDLED; 555a6a5580cSJeff Kirsher } 556a6a5580cSJeff Kirsher 557a6a5580cSJeff Kirsher static irqreturn_t enic_isr_msix_err(int irq, void *data) 558a6a5580cSJeff Kirsher { 559a6a5580cSJeff Kirsher struct enic *enic = data; 560a6a5580cSJeff Kirsher unsigned int intr = enic_msix_err_intr(enic); 561a6a5580cSJeff Kirsher 562a6a5580cSJeff Kirsher vnic_intr_return_all_credits(&enic->intr[intr]); 563a6a5580cSJeff Kirsher 564a6a5580cSJeff Kirsher enic_log_q_error(enic); 565a6a5580cSJeff Kirsher 566a6a5580cSJeff Kirsher /* schedule recovery from WQ/RQ error */ 567a6a5580cSJeff Kirsher schedule_work(&enic->reset); 568a6a5580cSJeff Kirsher 569a6a5580cSJeff Kirsher return IRQ_HANDLED; 570a6a5580cSJeff Kirsher } 571a6a5580cSJeff Kirsher 572a6a5580cSJeff Kirsher static irqreturn_t enic_isr_msix_notify(int irq, void *data) 573a6a5580cSJeff Kirsher { 574a6a5580cSJeff Kirsher struct enic *enic = data; 575a6a5580cSJeff Kirsher unsigned int intr = enic_msix_notify_intr(enic); 576a6a5580cSJeff Kirsher 577a6a5580cSJeff Kirsher vnic_intr_return_all_credits(&enic->intr[intr]); 578a6a5580cSJeff Kirsher enic_notify_check(enic); 579a6a5580cSJeff Kirsher 580a6a5580cSJeff Kirsher return IRQ_HANDLED; 581a6a5580cSJeff Kirsher } 582a6a5580cSJeff Kirsher 583a6a5580cSJeff Kirsher static inline void enic_queue_wq_skb_cont(struct enic *enic, 584a6a5580cSJeff Kirsher struct vnic_wq *wq, struct sk_buff *skb, 585a6a5580cSJeff Kirsher unsigned int len_left, int loopback) 586a6a5580cSJeff Kirsher { 587a6a5580cSJeff Kirsher skb_frag_t *frag; 588a6a5580cSJeff Kirsher 589a6a5580cSJeff Kirsher /* Queue additional data fragments */ 590a6a5580cSJeff Kirsher for (frag = skb_shinfo(skb)->frags; len_left; frag++) { 591a6a5580cSJeff Kirsher len_left -= frag->size; 592a6a5580cSJeff Kirsher enic_queue_wq_desc_cont(wq, skb, 593a6a5580cSJeff Kirsher pci_map_page(enic->pdev, frag->page, 594a6a5580cSJeff Kirsher frag->page_offset, frag->size, 595a6a5580cSJeff Kirsher PCI_DMA_TODEVICE), 596a6a5580cSJeff Kirsher frag->size, 597a6a5580cSJeff Kirsher (len_left == 0), /* EOP? */ 598a6a5580cSJeff Kirsher loopback); 599a6a5580cSJeff Kirsher } 600a6a5580cSJeff Kirsher } 601a6a5580cSJeff Kirsher 602a6a5580cSJeff Kirsher static inline void enic_queue_wq_skb_vlan(struct enic *enic, 603a6a5580cSJeff Kirsher struct vnic_wq *wq, struct sk_buff *skb, 604a6a5580cSJeff Kirsher int vlan_tag_insert, unsigned int vlan_tag, int loopback) 605a6a5580cSJeff Kirsher { 606a6a5580cSJeff Kirsher unsigned int head_len = skb_headlen(skb); 607a6a5580cSJeff Kirsher unsigned int len_left = skb->len - head_len; 608a6a5580cSJeff Kirsher int eop = (len_left == 0); 609a6a5580cSJeff Kirsher 610a6a5580cSJeff Kirsher /* Queue the main skb fragment. The fragments are no larger 611a6a5580cSJeff Kirsher * than max MTU(9000)+ETH_HDR_LEN(14) bytes, which is less 612a6a5580cSJeff Kirsher * than WQ_ENET_MAX_DESC_LEN length. So only one descriptor 613a6a5580cSJeff Kirsher * per fragment is queued. 614a6a5580cSJeff Kirsher */ 615a6a5580cSJeff Kirsher enic_queue_wq_desc(wq, skb, 616a6a5580cSJeff Kirsher pci_map_single(enic->pdev, skb->data, 617a6a5580cSJeff Kirsher head_len, PCI_DMA_TODEVICE), 618a6a5580cSJeff Kirsher head_len, 619a6a5580cSJeff Kirsher vlan_tag_insert, vlan_tag, 620a6a5580cSJeff Kirsher eop, loopback); 621a6a5580cSJeff Kirsher 622a6a5580cSJeff Kirsher if (!eop) 623a6a5580cSJeff Kirsher enic_queue_wq_skb_cont(enic, wq, skb, len_left, loopback); 624a6a5580cSJeff Kirsher } 625a6a5580cSJeff Kirsher 626a6a5580cSJeff Kirsher static inline void enic_queue_wq_skb_csum_l4(struct enic *enic, 627a6a5580cSJeff Kirsher struct vnic_wq *wq, struct sk_buff *skb, 628a6a5580cSJeff Kirsher int vlan_tag_insert, unsigned int vlan_tag, int loopback) 629a6a5580cSJeff Kirsher { 630a6a5580cSJeff Kirsher unsigned int head_len = skb_headlen(skb); 631a6a5580cSJeff Kirsher unsigned int len_left = skb->len - head_len; 632a6a5580cSJeff Kirsher unsigned int hdr_len = skb_checksum_start_offset(skb); 633a6a5580cSJeff Kirsher unsigned int csum_offset = hdr_len + skb->csum_offset; 634a6a5580cSJeff Kirsher int eop = (len_left == 0); 635a6a5580cSJeff Kirsher 636a6a5580cSJeff Kirsher /* Queue the main skb fragment. The fragments are no larger 637a6a5580cSJeff Kirsher * than max MTU(9000)+ETH_HDR_LEN(14) bytes, which is less 638a6a5580cSJeff Kirsher * than WQ_ENET_MAX_DESC_LEN length. So only one descriptor 639a6a5580cSJeff Kirsher * per fragment is queued. 640a6a5580cSJeff Kirsher */ 641a6a5580cSJeff Kirsher enic_queue_wq_desc_csum_l4(wq, skb, 642a6a5580cSJeff Kirsher pci_map_single(enic->pdev, skb->data, 643a6a5580cSJeff Kirsher head_len, PCI_DMA_TODEVICE), 644a6a5580cSJeff Kirsher head_len, 645a6a5580cSJeff Kirsher csum_offset, 646a6a5580cSJeff Kirsher hdr_len, 647a6a5580cSJeff Kirsher vlan_tag_insert, vlan_tag, 648a6a5580cSJeff Kirsher eop, loopback); 649a6a5580cSJeff Kirsher 650a6a5580cSJeff Kirsher if (!eop) 651a6a5580cSJeff Kirsher enic_queue_wq_skb_cont(enic, wq, skb, len_left, loopback); 652a6a5580cSJeff Kirsher } 653a6a5580cSJeff Kirsher 654a6a5580cSJeff Kirsher static inline void enic_queue_wq_skb_tso(struct enic *enic, 655a6a5580cSJeff Kirsher struct vnic_wq *wq, struct sk_buff *skb, unsigned int mss, 656a6a5580cSJeff Kirsher int vlan_tag_insert, unsigned int vlan_tag, int loopback) 657a6a5580cSJeff Kirsher { 658a6a5580cSJeff Kirsher unsigned int frag_len_left = skb_headlen(skb); 659a6a5580cSJeff Kirsher unsigned int len_left = skb->len - frag_len_left; 660a6a5580cSJeff Kirsher unsigned int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); 661a6a5580cSJeff Kirsher int eop = (len_left == 0); 662a6a5580cSJeff Kirsher unsigned int len; 663a6a5580cSJeff Kirsher dma_addr_t dma_addr; 664a6a5580cSJeff Kirsher unsigned int offset = 0; 665a6a5580cSJeff Kirsher skb_frag_t *frag; 666a6a5580cSJeff Kirsher 667a6a5580cSJeff Kirsher /* Preload TCP csum field with IP pseudo hdr calculated 668a6a5580cSJeff Kirsher * with IP length set to zero. HW will later add in length 669a6a5580cSJeff Kirsher * to each TCP segment resulting from the TSO. 670a6a5580cSJeff Kirsher */ 671a6a5580cSJeff Kirsher 672a6a5580cSJeff Kirsher if (skb->protocol == cpu_to_be16(ETH_P_IP)) { 673a6a5580cSJeff Kirsher ip_hdr(skb)->check = 0; 674a6a5580cSJeff Kirsher tcp_hdr(skb)->check = ~csum_tcpudp_magic(ip_hdr(skb)->saddr, 675a6a5580cSJeff Kirsher ip_hdr(skb)->daddr, 0, IPPROTO_TCP, 0); 676a6a5580cSJeff Kirsher } else if (skb->protocol == cpu_to_be16(ETH_P_IPV6)) { 677a6a5580cSJeff Kirsher tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, 678a6a5580cSJeff Kirsher &ipv6_hdr(skb)->daddr, 0, IPPROTO_TCP, 0); 679a6a5580cSJeff Kirsher } 680a6a5580cSJeff Kirsher 681a6a5580cSJeff Kirsher /* Queue WQ_ENET_MAX_DESC_LEN length descriptors 682a6a5580cSJeff Kirsher * for the main skb fragment 683a6a5580cSJeff Kirsher */ 684a6a5580cSJeff Kirsher while (frag_len_left) { 685a6a5580cSJeff Kirsher len = min(frag_len_left, (unsigned int)WQ_ENET_MAX_DESC_LEN); 686a6a5580cSJeff Kirsher dma_addr = pci_map_single(enic->pdev, skb->data + offset, 687a6a5580cSJeff Kirsher len, PCI_DMA_TODEVICE); 688a6a5580cSJeff Kirsher enic_queue_wq_desc_tso(wq, skb, 689a6a5580cSJeff Kirsher dma_addr, 690a6a5580cSJeff Kirsher len, 691a6a5580cSJeff Kirsher mss, hdr_len, 692a6a5580cSJeff Kirsher vlan_tag_insert, vlan_tag, 693a6a5580cSJeff Kirsher eop && (len == frag_len_left), loopback); 694a6a5580cSJeff Kirsher frag_len_left -= len; 695a6a5580cSJeff Kirsher offset += len; 696a6a5580cSJeff Kirsher } 697a6a5580cSJeff Kirsher 698a6a5580cSJeff Kirsher if (eop) 699a6a5580cSJeff Kirsher return; 700a6a5580cSJeff Kirsher 701a6a5580cSJeff Kirsher /* Queue WQ_ENET_MAX_DESC_LEN length descriptors 702a6a5580cSJeff Kirsher * for additional data fragments 703a6a5580cSJeff Kirsher */ 704a6a5580cSJeff Kirsher for (frag = skb_shinfo(skb)->frags; len_left; frag++) { 705a6a5580cSJeff Kirsher len_left -= frag->size; 706a6a5580cSJeff Kirsher frag_len_left = frag->size; 707a6a5580cSJeff Kirsher offset = frag->page_offset; 708a6a5580cSJeff Kirsher 709a6a5580cSJeff Kirsher while (frag_len_left) { 710a6a5580cSJeff Kirsher len = min(frag_len_left, 711a6a5580cSJeff Kirsher (unsigned int)WQ_ENET_MAX_DESC_LEN); 712a6a5580cSJeff Kirsher dma_addr = pci_map_page(enic->pdev, frag->page, 713a6a5580cSJeff Kirsher offset, len, 714a6a5580cSJeff Kirsher PCI_DMA_TODEVICE); 715a6a5580cSJeff Kirsher enic_queue_wq_desc_cont(wq, skb, 716a6a5580cSJeff Kirsher dma_addr, 717a6a5580cSJeff Kirsher len, 718a6a5580cSJeff Kirsher (len_left == 0) && 719a6a5580cSJeff Kirsher (len == frag_len_left), /* EOP? */ 720a6a5580cSJeff Kirsher loopback); 721a6a5580cSJeff Kirsher frag_len_left -= len; 722a6a5580cSJeff Kirsher offset += len; 723a6a5580cSJeff Kirsher } 724a6a5580cSJeff Kirsher } 725a6a5580cSJeff Kirsher } 726a6a5580cSJeff Kirsher 727a6a5580cSJeff Kirsher static inline void enic_queue_wq_skb(struct enic *enic, 728a6a5580cSJeff Kirsher struct vnic_wq *wq, struct sk_buff *skb) 729a6a5580cSJeff Kirsher { 730a6a5580cSJeff Kirsher unsigned int mss = skb_shinfo(skb)->gso_size; 731a6a5580cSJeff Kirsher unsigned int vlan_tag = 0; 732a6a5580cSJeff Kirsher int vlan_tag_insert = 0; 733a6a5580cSJeff Kirsher int loopback = 0; 734a6a5580cSJeff Kirsher 735a6a5580cSJeff Kirsher if (vlan_tx_tag_present(skb)) { 736a6a5580cSJeff Kirsher /* VLAN tag from trunking driver */ 737a6a5580cSJeff Kirsher vlan_tag_insert = 1; 738a6a5580cSJeff Kirsher vlan_tag = vlan_tx_tag_get(skb); 739a6a5580cSJeff Kirsher } else if (enic->loop_enable) { 740a6a5580cSJeff Kirsher vlan_tag = enic->loop_tag; 741a6a5580cSJeff Kirsher loopback = 1; 742a6a5580cSJeff Kirsher } 743a6a5580cSJeff Kirsher 744a6a5580cSJeff Kirsher if (mss) 745a6a5580cSJeff Kirsher enic_queue_wq_skb_tso(enic, wq, skb, mss, 746a6a5580cSJeff Kirsher vlan_tag_insert, vlan_tag, loopback); 747a6a5580cSJeff Kirsher else if (skb->ip_summed == CHECKSUM_PARTIAL) 748a6a5580cSJeff Kirsher enic_queue_wq_skb_csum_l4(enic, wq, skb, 749a6a5580cSJeff Kirsher vlan_tag_insert, vlan_tag, loopback); 750a6a5580cSJeff Kirsher else 751a6a5580cSJeff Kirsher enic_queue_wq_skb_vlan(enic, wq, skb, 752a6a5580cSJeff Kirsher vlan_tag_insert, vlan_tag, loopback); 753a6a5580cSJeff Kirsher } 754a6a5580cSJeff Kirsher 755a6a5580cSJeff Kirsher /* netif_tx_lock held, process context with BHs disabled, or BH */ 756a6a5580cSJeff Kirsher static netdev_tx_t enic_hard_start_xmit(struct sk_buff *skb, 757a6a5580cSJeff Kirsher struct net_device *netdev) 758a6a5580cSJeff Kirsher { 759a6a5580cSJeff Kirsher struct enic *enic = netdev_priv(netdev); 760a6a5580cSJeff Kirsher struct vnic_wq *wq = &enic->wq[0]; 761a6a5580cSJeff Kirsher unsigned long flags; 762a6a5580cSJeff Kirsher 763a6a5580cSJeff Kirsher if (skb->len <= 0) { 764a6a5580cSJeff Kirsher dev_kfree_skb(skb); 765a6a5580cSJeff Kirsher return NETDEV_TX_OK; 766a6a5580cSJeff Kirsher } 767a6a5580cSJeff Kirsher 768a6a5580cSJeff Kirsher /* Non-TSO sends must fit within ENIC_NON_TSO_MAX_DESC descs, 769a6a5580cSJeff Kirsher * which is very likely. In the off chance it's going to take 770a6a5580cSJeff Kirsher * more than * ENIC_NON_TSO_MAX_DESC, linearize the skb. 771a6a5580cSJeff Kirsher */ 772a6a5580cSJeff Kirsher 773a6a5580cSJeff Kirsher if (skb_shinfo(skb)->gso_size == 0 && 774a6a5580cSJeff Kirsher skb_shinfo(skb)->nr_frags + 1 > ENIC_NON_TSO_MAX_DESC && 775a6a5580cSJeff Kirsher skb_linearize(skb)) { 776a6a5580cSJeff Kirsher dev_kfree_skb(skb); 777a6a5580cSJeff Kirsher return NETDEV_TX_OK; 778a6a5580cSJeff Kirsher } 779a6a5580cSJeff Kirsher 780a6a5580cSJeff Kirsher spin_lock_irqsave(&enic->wq_lock[0], flags); 781a6a5580cSJeff Kirsher 782a6a5580cSJeff Kirsher if (vnic_wq_desc_avail(wq) < 783a6a5580cSJeff Kirsher skb_shinfo(skb)->nr_frags + ENIC_DESC_MAX_SPLITS) { 784a6a5580cSJeff Kirsher netif_stop_queue(netdev); 785a6a5580cSJeff Kirsher /* This is a hard error, log it */ 786a6a5580cSJeff Kirsher netdev_err(netdev, "BUG! Tx ring full when queue awake!\n"); 787a6a5580cSJeff Kirsher spin_unlock_irqrestore(&enic->wq_lock[0], flags); 788a6a5580cSJeff Kirsher return NETDEV_TX_BUSY; 789a6a5580cSJeff Kirsher } 790a6a5580cSJeff Kirsher 791a6a5580cSJeff Kirsher enic_queue_wq_skb(enic, wq, skb); 792a6a5580cSJeff Kirsher 793a6a5580cSJeff Kirsher if (vnic_wq_desc_avail(wq) < MAX_SKB_FRAGS + ENIC_DESC_MAX_SPLITS) 794a6a5580cSJeff Kirsher netif_stop_queue(netdev); 795a6a5580cSJeff Kirsher 796a6a5580cSJeff Kirsher spin_unlock_irqrestore(&enic->wq_lock[0], flags); 797a6a5580cSJeff Kirsher 798a6a5580cSJeff Kirsher return NETDEV_TX_OK; 799a6a5580cSJeff Kirsher } 800a6a5580cSJeff Kirsher 801a6a5580cSJeff Kirsher /* dev_base_lock rwlock held, nominally process context */ 802a6a5580cSJeff Kirsher static struct rtnl_link_stats64 *enic_get_stats(struct net_device *netdev, 803a6a5580cSJeff Kirsher struct rtnl_link_stats64 *net_stats) 804a6a5580cSJeff Kirsher { 805a6a5580cSJeff Kirsher struct enic *enic = netdev_priv(netdev); 806a6a5580cSJeff Kirsher struct vnic_stats *stats; 807a6a5580cSJeff Kirsher 808a6a5580cSJeff Kirsher enic_dev_stats_dump(enic, &stats); 809a6a5580cSJeff Kirsher 810a6a5580cSJeff Kirsher net_stats->tx_packets = stats->tx.tx_frames_ok; 811a6a5580cSJeff Kirsher net_stats->tx_bytes = stats->tx.tx_bytes_ok; 812a6a5580cSJeff Kirsher net_stats->tx_errors = stats->tx.tx_errors; 813a6a5580cSJeff Kirsher net_stats->tx_dropped = stats->tx.tx_drops; 814a6a5580cSJeff Kirsher 815a6a5580cSJeff Kirsher net_stats->rx_packets = stats->rx.rx_frames_ok; 816a6a5580cSJeff Kirsher net_stats->rx_bytes = stats->rx.rx_bytes_ok; 817a6a5580cSJeff Kirsher net_stats->rx_errors = stats->rx.rx_errors; 818a6a5580cSJeff Kirsher net_stats->multicast = stats->rx.rx_multicast_frames_ok; 819a6a5580cSJeff Kirsher net_stats->rx_over_errors = enic->rq_truncated_pkts; 820a6a5580cSJeff Kirsher net_stats->rx_crc_errors = enic->rq_bad_fcs; 821a6a5580cSJeff Kirsher net_stats->rx_dropped = stats->rx.rx_no_bufs + stats->rx.rx_drop; 822a6a5580cSJeff Kirsher 823a6a5580cSJeff Kirsher return net_stats; 824a6a5580cSJeff Kirsher } 825a6a5580cSJeff Kirsher 826a6a5580cSJeff Kirsher void enic_reset_addr_lists(struct enic *enic) 827a6a5580cSJeff Kirsher { 828a6a5580cSJeff Kirsher enic->mc_count = 0; 829a6a5580cSJeff Kirsher enic->uc_count = 0; 830a6a5580cSJeff Kirsher enic->flags = 0; 831a6a5580cSJeff Kirsher } 832a6a5580cSJeff Kirsher 833a6a5580cSJeff Kirsher static int enic_set_mac_addr(struct net_device *netdev, char *addr) 834a6a5580cSJeff Kirsher { 835a6a5580cSJeff Kirsher struct enic *enic = netdev_priv(netdev); 836a6a5580cSJeff Kirsher 837a6a5580cSJeff Kirsher if (enic_is_dynamic(enic)) { 838a6a5580cSJeff Kirsher if (!is_valid_ether_addr(addr) && !is_zero_ether_addr(addr)) 839a6a5580cSJeff Kirsher return -EADDRNOTAVAIL; 840a6a5580cSJeff Kirsher } else { 841a6a5580cSJeff Kirsher if (!is_valid_ether_addr(addr)) 842a6a5580cSJeff Kirsher return -EADDRNOTAVAIL; 843a6a5580cSJeff Kirsher } 844a6a5580cSJeff Kirsher 845a6a5580cSJeff Kirsher memcpy(netdev->dev_addr, addr, netdev->addr_len); 846a6a5580cSJeff Kirsher 847a6a5580cSJeff Kirsher return 0; 848a6a5580cSJeff Kirsher } 849a6a5580cSJeff Kirsher 850a6a5580cSJeff Kirsher static int enic_set_mac_address_dynamic(struct net_device *netdev, void *p) 851a6a5580cSJeff Kirsher { 852a6a5580cSJeff Kirsher struct enic *enic = netdev_priv(netdev); 853a6a5580cSJeff Kirsher struct sockaddr *saddr = p; 854a6a5580cSJeff Kirsher char *addr = saddr->sa_data; 855a6a5580cSJeff Kirsher int err; 856a6a5580cSJeff Kirsher 857a6a5580cSJeff Kirsher if (netif_running(enic->netdev)) { 858a6a5580cSJeff Kirsher err = enic_dev_del_station_addr(enic); 859a6a5580cSJeff Kirsher if (err) 860a6a5580cSJeff Kirsher return err; 861a6a5580cSJeff Kirsher } 862a6a5580cSJeff Kirsher 863a6a5580cSJeff Kirsher err = enic_set_mac_addr(netdev, addr); 864a6a5580cSJeff Kirsher if (err) 865a6a5580cSJeff Kirsher return err; 866a6a5580cSJeff Kirsher 867a6a5580cSJeff Kirsher if (netif_running(enic->netdev)) { 868a6a5580cSJeff Kirsher err = enic_dev_add_station_addr(enic); 869a6a5580cSJeff Kirsher if (err) 870a6a5580cSJeff Kirsher return err; 871a6a5580cSJeff Kirsher } 872a6a5580cSJeff Kirsher 873a6a5580cSJeff Kirsher return err; 874a6a5580cSJeff Kirsher } 875a6a5580cSJeff Kirsher 876a6a5580cSJeff Kirsher static int enic_set_mac_address(struct net_device *netdev, void *p) 877a6a5580cSJeff Kirsher { 878a6a5580cSJeff Kirsher struct sockaddr *saddr = p; 879a6a5580cSJeff Kirsher char *addr = saddr->sa_data; 880a6a5580cSJeff Kirsher struct enic *enic = netdev_priv(netdev); 881a6a5580cSJeff Kirsher int err; 882a6a5580cSJeff Kirsher 883a6a5580cSJeff Kirsher err = enic_dev_del_station_addr(enic); 884a6a5580cSJeff Kirsher if (err) 885a6a5580cSJeff Kirsher return err; 886a6a5580cSJeff Kirsher 887a6a5580cSJeff Kirsher err = enic_set_mac_addr(netdev, addr); 888a6a5580cSJeff Kirsher if (err) 889a6a5580cSJeff Kirsher return err; 890a6a5580cSJeff Kirsher 891a6a5580cSJeff Kirsher return enic_dev_add_station_addr(enic); 892a6a5580cSJeff Kirsher } 893a6a5580cSJeff Kirsher 894a6a5580cSJeff Kirsher static void enic_update_multicast_addr_list(struct enic *enic) 895a6a5580cSJeff Kirsher { 896a6a5580cSJeff Kirsher struct net_device *netdev = enic->netdev; 897a6a5580cSJeff Kirsher struct netdev_hw_addr *ha; 898a6a5580cSJeff Kirsher unsigned int mc_count = netdev_mc_count(netdev); 899a6a5580cSJeff Kirsher u8 mc_addr[ENIC_MULTICAST_PERFECT_FILTERS][ETH_ALEN]; 900a6a5580cSJeff Kirsher unsigned int i, j; 901a6a5580cSJeff Kirsher 902a6a5580cSJeff Kirsher if (mc_count > ENIC_MULTICAST_PERFECT_FILTERS) { 903a6a5580cSJeff Kirsher netdev_warn(netdev, "Registering only %d out of %d " 904a6a5580cSJeff Kirsher "multicast addresses\n", 905a6a5580cSJeff Kirsher ENIC_MULTICAST_PERFECT_FILTERS, mc_count); 906a6a5580cSJeff Kirsher mc_count = ENIC_MULTICAST_PERFECT_FILTERS; 907a6a5580cSJeff Kirsher } 908a6a5580cSJeff Kirsher 909a6a5580cSJeff Kirsher /* Is there an easier way? Trying to minimize to 910a6a5580cSJeff Kirsher * calls to add/del multicast addrs. We keep the 911a6a5580cSJeff Kirsher * addrs from the last call in enic->mc_addr and 912a6a5580cSJeff Kirsher * look for changes to add/del. 913a6a5580cSJeff Kirsher */ 914a6a5580cSJeff Kirsher 915a6a5580cSJeff Kirsher i = 0; 916a6a5580cSJeff Kirsher netdev_for_each_mc_addr(ha, netdev) { 917a6a5580cSJeff Kirsher if (i == mc_count) 918a6a5580cSJeff Kirsher break; 919a6a5580cSJeff Kirsher memcpy(mc_addr[i++], ha->addr, ETH_ALEN); 920a6a5580cSJeff Kirsher } 921a6a5580cSJeff Kirsher 922a6a5580cSJeff Kirsher for (i = 0; i < enic->mc_count; i++) { 923a6a5580cSJeff Kirsher for (j = 0; j < mc_count; j++) 924a6a5580cSJeff Kirsher if (compare_ether_addr(enic->mc_addr[i], 925a6a5580cSJeff Kirsher mc_addr[j]) == 0) 926a6a5580cSJeff Kirsher break; 927a6a5580cSJeff Kirsher if (j == mc_count) 928a6a5580cSJeff Kirsher enic_dev_del_addr(enic, enic->mc_addr[i]); 929a6a5580cSJeff Kirsher } 930a6a5580cSJeff Kirsher 931a6a5580cSJeff Kirsher for (i = 0; i < mc_count; i++) { 932a6a5580cSJeff Kirsher for (j = 0; j < enic->mc_count; j++) 933a6a5580cSJeff Kirsher if (compare_ether_addr(mc_addr[i], 934a6a5580cSJeff Kirsher enic->mc_addr[j]) == 0) 935a6a5580cSJeff Kirsher break; 936a6a5580cSJeff Kirsher if (j == enic->mc_count) 937a6a5580cSJeff Kirsher enic_dev_add_addr(enic, mc_addr[i]); 938a6a5580cSJeff Kirsher } 939a6a5580cSJeff Kirsher 940a6a5580cSJeff Kirsher /* Save the list to compare against next time 941a6a5580cSJeff Kirsher */ 942a6a5580cSJeff Kirsher 943a6a5580cSJeff Kirsher for (i = 0; i < mc_count; i++) 944a6a5580cSJeff Kirsher memcpy(enic->mc_addr[i], mc_addr[i], ETH_ALEN); 945a6a5580cSJeff Kirsher 946a6a5580cSJeff Kirsher enic->mc_count = mc_count; 947a6a5580cSJeff Kirsher } 948a6a5580cSJeff Kirsher 949a6a5580cSJeff Kirsher static void enic_update_unicast_addr_list(struct enic *enic) 950a6a5580cSJeff Kirsher { 951a6a5580cSJeff Kirsher struct net_device *netdev = enic->netdev; 952a6a5580cSJeff Kirsher struct netdev_hw_addr *ha; 953a6a5580cSJeff Kirsher unsigned int uc_count = netdev_uc_count(netdev); 954a6a5580cSJeff Kirsher u8 uc_addr[ENIC_UNICAST_PERFECT_FILTERS][ETH_ALEN]; 955a6a5580cSJeff Kirsher unsigned int i, j; 956a6a5580cSJeff Kirsher 957a6a5580cSJeff Kirsher if (uc_count > ENIC_UNICAST_PERFECT_FILTERS) { 958a6a5580cSJeff Kirsher netdev_warn(netdev, "Registering only %d out of %d " 959a6a5580cSJeff Kirsher "unicast addresses\n", 960a6a5580cSJeff Kirsher ENIC_UNICAST_PERFECT_FILTERS, uc_count); 961a6a5580cSJeff Kirsher uc_count = ENIC_UNICAST_PERFECT_FILTERS; 962a6a5580cSJeff Kirsher } 963a6a5580cSJeff Kirsher 964a6a5580cSJeff Kirsher /* Is there an easier way? Trying to minimize to 965a6a5580cSJeff Kirsher * calls to add/del unicast addrs. We keep the 966a6a5580cSJeff Kirsher * addrs from the last call in enic->uc_addr and 967a6a5580cSJeff Kirsher * look for changes to add/del. 968a6a5580cSJeff Kirsher */ 969a6a5580cSJeff Kirsher 970a6a5580cSJeff Kirsher i = 0; 971a6a5580cSJeff Kirsher netdev_for_each_uc_addr(ha, netdev) { 972a6a5580cSJeff Kirsher if (i == uc_count) 973a6a5580cSJeff Kirsher break; 974a6a5580cSJeff Kirsher memcpy(uc_addr[i++], ha->addr, ETH_ALEN); 975a6a5580cSJeff Kirsher } 976a6a5580cSJeff Kirsher 977a6a5580cSJeff Kirsher for (i = 0; i < enic->uc_count; i++) { 978a6a5580cSJeff Kirsher for (j = 0; j < uc_count; j++) 979a6a5580cSJeff Kirsher if (compare_ether_addr(enic->uc_addr[i], 980a6a5580cSJeff Kirsher uc_addr[j]) == 0) 981a6a5580cSJeff Kirsher break; 982a6a5580cSJeff Kirsher if (j == uc_count) 983a6a5580cSJeff Kirsher enic_dev_del_addr(enic, enic->uc_addr[i]); 984a6a5580cSJeff Kirsher } 985a6a5580cSJeff Kirsher 986a6a5580cSJeff Kirsher for (i = 0; i < uc_count; i++) { 987a6a5580cSJeff Kirsher for (j = 0; j < enic->uc_count; j++) 988a6a5580cSJeff Kirsher if (compare_ether_addr(uc_addr[i], 989a6a5580cSJeff Kirsher enic->uc_addr[j]) == 0) 990a6a5580cSJeff Kirsher break; 991a6a5580cSJeff Kirsher if (j == enic->uc_count) 992a6a5580cSJeff Kirsher enic_dev_add_addr(enic, uc_addr[i]); 993a6a5580cSJeff Kirsher } 994a6a5580cSJeff Kirsher 995a6a5580cSJeff Kirsher /* Save the list to compare against next time 996a6a5580cSJeff Kirsher */ 997a6a5580cSJeff Kirsher 998a6a5580cSJeff Kirsher for (i = 0; i < uc_count; i++) 999a6a5580cSJeff Kirsher memcpy(enic->uc_addr[i], uc_addr[i], ETH_ALEN); 1000a6a5580cSJeff Kirsher 1001a6a5580cSJeff Kirsher enic->uc_count = uc_count; 1002a6a5580cSJeff Kirsher } 1003a6a5580cSJeff Kirsher 1004a6a5580cSJeff Kirsher /* netif_tx_lock held, BHs disabled */ 1005a6a5580cSJeff Kirsher static void enic_set_rx_mode(struct net_device *netdev) 1006a6a5580cSJeff Kirsher { 1007a6a5580cSJeff Kirsher struct enic *enic = netdev_priv(netdev); 1008a6a5580cSJeff Kirsher int directed = 1; 1009a6a5580cSJeff Kirsher int multicast = (netdev->flags & IFF_MULTICAST) ? 1 : 0; 1010a6a5580cSJeff Kirsher int broadcast = (netdev->flags & IFF_BROADCAST) ? 1 : 0; 1011a6a5580cSJeff Kirsher int promisc = (netdev->flags & IFF_PROMISC) || 1012a6a5580cSJeff Kirsher netdev_uc_count(netdev) > ENIC_UNICAST_PERFECT_FILTERS; 1013a6a5580cSJeff Kirsher int allmulti = (netdev->flags & IFF_ALLMULTI) || 1014a6a5580cSJeff Kirsher netdev_mc_count(netdev) > ENIC_MULTICAST_PERFECT_FILTERS; 1015a6a5580cSJeff Kirsher unsigned int flags = netdev->flags | 1016a6a5580cSJeff Kirsher (allmulti ? IFF_ALLMULTI : 0) | 1017a6a5580cSJeff Kirsher (promisc ? IFF_PROMISC : 0); 1018a6a5580cSJeff Kirsher 1019a6a5580cSJeff Kirsher if (enic->flags != flags) { 1020a6a5580cSJeff Kirsher enic->flags = flags; 1021a6a5580cSJeff Kirsher enic_dev_packet_filter(enic, directed, 1022a6a5580cSJeff Kirsher multicast, broadcast, promisc, allmulti); 1023a6a5580cSJeff Kirsher } 1024a6a5580cSJeff Kirsher 1025a6a5580cSJeff Kirsher if (!promisc) { 1026a6a5580cSJeff Kirsher enic_update_unicast_addr_list(enic); 1027a6a5580cSJeff Kirsher if (!allmulti) 1028a6a5580cSJeff Kirsher enic_update_multicast_addr_list(enic); 1029a6a5580cSJeff Kirsher } 1030a6a5580cSJeff Kirsher } 1031a6a5580cSJeff Kirsher 1032a6a5580cSJeff Kirsher /* netif_tx_lock held, BHs disabled */ 1033a6a5580cSJeff Kirsher static void enic_tx_timeout(struct net_device *netdev) 1034a6a5580cSJeff Kirsher { 1035a6a5580cSJeff Kirsher struct enic *enic = netdev_priv(netdev); 1036a6a5580cSJeff Kirsher schedule_work(&enic->reset); 1037a6a5580cSJeff Kirsher } 1038a6a5580cSJeff Kirsher 1039a6a5580cSJeff Kirsher static int enic_set_vf_mac(struct net_device *netdev, int vf, u8 *mac) 1040a6a5580cSJeff Kirsher { 1041a6a5580cSJeff Kirsher struct enic *enic = netdev_priv(netdev); 1042a6a5580cSJeff Kirsher 1043a6a5580cSJeff Kirsher if (vf != PORT_SELF_VF) 1044a6a5580cSJeff Kirsher return -EOPNOTSUPP; 1045a6a5580cSJeff Kirsher 1046a6a5580cSJeff Kirsher /* Ignore the vf argument for now. We can assume the request 1047a6a5580cSJeff Kirsher * is coming on a vf. 1048a6a5580cSJeff Kirsher */ 1049a6a5580cSJeff Kirsher if (is_valid_ether_addr(mac)) { 1050a6a5580cSJeff Kirsher memcpy(enic->pp.vf_mac, mac, ETH_ALEN); 1051a6a5580cSJeff Kirsher return 0; 1052a6a5580cSJeff Kirsher } else 1053a6a5580cSJeff Kirsher return -EINVAL; 1054a6a5580cSJeff Kirsher } 1055a6a5580cSJeff Kirsher 1056a6a5580cSJeff Kirsher static int enic_set_vf_port(struct net_device *netdev, int vf, 1057a6a5580cSJeff Kirsher struct nlattr *port[]) 1058a6a5580cSJeff Kirsher { 1059a6a5580cSJeff Kirsher struct enic *enic = netdev_priv(netdev); 1060a6a5580cSJeff Kirsher struct enic_port_profile prev_pp; 1061a6a5580cSJeff Kirsher int err = 0, restore_pp = 1; 1062a6a5580cSJeff Kirsher 1063a6a5580cSJeff Kirsher /* don't support VFs, yet */ 1064a6a5580cSJeff Kirsher if (vf != PORT_SELF_VF) 1065a6a5580cSJeff Kirsher return -EOPNOTSUPP; 1066a6a5580cSJeff Kirsher 1067a6a5580cSJeff Kirsher if (!port[IFLA_PORT_REQUEST]) 1068a6a5580cSJeff Kirsher return -EOPNOTSUPP; 1069a6a5580cSJeff Kirsher 1070a6a5580cSJeff Kirsher memcpy(&prev_pp, &enic->pp, sizeof(enic->pp)); 1071a6a5580cSJeff Kirsher memset(&enic->pp, 0, sizeof(enic->pp)); 1072a6a5580cSJeff Kirsher 1073a6a5580cSJeff Kirsher enic->pp.set |= ENIC_SET_REQUEST; 1074a6a5580cSJeff Kirsher enic->pp.request = nla_get_u8(port[IFLA_PORT_REQUEST]); 1075a6a5580cSJeff Kirsher 1076a6a5580cSJeff Kirsher if (port[IFLA_PORT_PROFILE]) { 1077a6a5580cSJeff Kirsher enic->pp.set |= ENIC_SET_NAME; 1078a6a5580cSJeff Kirsher memcpy(enic->pp.name, nla_data(port[IFLA_PORT_PROFILE]), 1079a6a5580cSJeff Kirsher PORT_PROFILE_MAX); 1080a6a5580cSJeff Kirsher } 1081a6a5580cSJeff Kirsher 1082a6a5580cSJeff Kirsher if (port[IFLA_PORT_INSTANCE_UUID]) { 1083a6a5580cSJeff Kirsher enic->pp.set |= ENIC_SET_INSTANCE; 1084a6a5580cSJeff Kirsher memcpy(enic->pp.instance_uuid, 1085a6a5580cSJeff Kirsher nla_data(port[IFLA_PORT_INSTANCE_UUID]), PORT_UUID_MAX); 1086a6a5580cSJeff Kirsher } 1087a6a5580cSJeff Kirsher 1088a6a5580cSJeff Kirsher if (port[IFLA_PORT_HOST_UUID]) { 1089a6a5580cSJeff Kirsher enic->pp.set |= ENIC_SET_HOST; 1090a6a5580cSJeff Kirsher memcpy(enic->pp.host_uuid, 1091a6a5580cSJeff Kirsher nla_data(port[IFLA_PORT_HOST_UUID]), PORT_UUID_MAX); 1092a6a5580cSJeff Kirsher } 1093a6a5580cSJeff Kirsher 1094a6a5580cSJeff Kirsher /* Special case handling: mac came from IFLA_VF_MAC */ 1095a6a5580cSJeff Kirsher if (!is_zero_ether_addr(prev_pp.vf_mac)) 1096a6a5580cSJeff Kirsher memcpy(enic->pp.mac_addr, prev_pp.vf_mac, ETH_ALEN); 1097a6a5580cSJeff Kirsher 1098a6a5580cSJeff Kirsher if (is_zero_ether_addr(netdev->dev_addr)) 1099a6a5580cSJeff Kirsher random_ether_addr(netdev->dev_addr); 1100a6a5580cSJeff Kirsher 1101a6a5580cSJeff Kirsher err = enic_process_set_pp_request(enic, &prev_pp, &restore_pp); 1102a6a5580cSJeff Kirsher if (err) { 1103a6a5580cSJeff Kirsher if (restore_pp) { 1104a6a5580cSJeff Kirsher /* Things are still the way they were: Implicit 1105a6a5580cSJeff Kirsher * DISASSOCIATE failed 1106a6a5580cSJeff Kirsher */ 1107a6a5580cSJeff Kirsher memcpy(&enic->pp, &prev_pp, sizeof(enic->pp)); 1108a6a5580cSJeff Kirsher } else { 1109a6a5580cSJeff Kirsher memset(&enic->pp, 0, sizeof(enic->pp)); 1110a6a5580cSJeff Kirsher memset(netdev->dev_addr, 0, ETH_ALEN); 1111a6a5580cSJeff Kirsher } 1112a6a5580cSJeff Kirsher } else { 1113a6a5580cSJeff Kirsher /* Set flag to indicate that the port assoc/disassoc 1114a6a5580cSJeff Kirsher * request has been sent out to fw 1115a6a5580cSJeff Kirsher */ 1116a6a5580cSJeff Kirsher enic->pp.set |= ENIC_PORT_REQUEST_APPLIED; 1117a6a5580cSJeff Kirsher 1118a6a5580cSJeff Kirsher /* If DISASSOCIATE, clean up all assigned/saved macaddresses */ 1119a6a5580cSJeff Kirsher if (enic->pp.request == PORT_REQUEST_DISASSOCIATE) { 1120a6a5580cSJeff Kirsher memset(enic->pp.mac_addr, 0, ETH_ALEN); 1121a6a5580cSJeff Kirsher memset(netdev->dev_addr, 0, ETH_ALEN); 1122a6a5580cSJeff Kirsher } 1123a6a5580cSJeff Kirsher } 1124a6a5580cSJeff Kirsher 1125a6a5580cSJeff Kirsher memset(enic->pp.vf_mac, 0, ETH_ALEN); 1126a6a5580cSJeff Kirsher 1127a6a5580cSJeff Kirsher return err; 1128a6a5580cSJeff Kirsher } 1129a6a5580cSJeff Kirsher 1130a6a5580cSJeff Kirsher static int enic_get_vf_port(struct net_device *netdev, int vf, 1131a6a5580cSJeff Kirsher struct sk_buff *skb) 1132a6a5580cSJeff Kirsher { 1133a6a5580cSJeff Kirsher struct enic *enic = netdev_priv(netdev); 1134a6a5580cSJeff Kirsher u16 response = PORT_PROFILE_RESPONSE_SUCCESS; 1135a6a5580cSJeff Kirsher int err; 1136a6a5580cSJeff Kirsher 1137a6a5580cSJeff Kirsher if (!(enic->pp.set & ENIC_PORT_REQUEST_APPLIED)) 1138a6a5580cSJeff Kirsher return -ENODATA; 1139a6a5580cSJeff Kirsher 1140a6a5580cSJeff Kirsher err = enic_process_get_pp_request(enic, enic->pp.request, &response); 1141a6a5580cSJeff Kirsher if (err) 1142a6a5580cSJeff Kirsher return err; 1143a6a5580cSJeff Kirsher 1144a6a5580cSJeff Kirsher NLA_PUT_U16(skb, IFLA_PORT_REQUEST, enic->pp.request); 1145a6a5580cSJeff Kirsher NLA_PUT_U16(skb, IFLA_PORT_RESPONSE, response); 1146a6a5580cSJeff Kirsher if (enic->pp.set & ENIC_SET_NAME) 1147a6a5580cSJeff Kirsher NLA_PUT(skb, IFLA_PORT_PROFILE, PORT_PROFILE_MAX, 1148a6a5580cSJeff Kirsher enic->pp.name); 1149a6a5580cSJeff Kirsher if (enic->pp.set & ENIC_SET_INSTANCE) 1150a6a5580cSJeff Kirsher NLA_PUT(skb, IFLA_PORT_INSTANCE_UUID, PORT_UUID_MAX, 1151a6a5580cSJeff Kirsher enic->pp.instance_uuid); 1152a6a5580cSJeff Kirsher if (enic->pp.set & ENIC_SET_HOST) 1153a6a5580cSJeff Kirsher NLA_PUT(skb, IFLA_PORT_HOST_UUID, PORT_UUID_MAX, 1154a6a5580cSJeff Kirsher enic->pp.host_uuid); 1155a6a5580cSJeff Kirsher 1156a6a5580cSJeff Kirsher return 0; 1157a6a5580cSJeff Kirsher 1158a6a5580cSJeff Kirsher nla_put_failure: 1159a6a5580cSJeff Kirsher return -EMSGSIZE; 1160a6a5580cSJeff Kirsher } 1161a6a5580cSJeff Kirsher 1162a6a5580cSJeff Kirsher static void enic_free_rq_buf(struct vnic_rq *rq, struct vnic_rq_buf *buf) 1163a6a5580cSJeff Kirsher { 1164a6a5580cSJeff Kirsher struct enic *enic = vnic_dev_priv(rq->vdev); 1165a6a5580cSJeff Kirsher 1166a6a5580cSJeff Kirsher if (!buf->os_buf) 1167a6a5580cSJeff Kirsher return; 1168a6a5580cSJeff Kirsher 1169a6a5580cSJeff Kirsher pci_unmap_single(enic->pdev, buf->dma_addr, 1170a6a5580cSJeff Kirsher buf->len, PCI_DMA_FROMDEVICE); 1171a6a5580cSJeff Kirsher dev_kfree_skb_any(buf->os_buf); 1172a6a5580cSJeff Kirsher } 1173a6a5580cSJeff Kirsher 1174a6a5580cSJeff Kirsher static int enic_rq_alloc_buf(struct vnic_rq *rq) 1175a6a5580cSJeff Kirsher { 1176a6a5580cSJeff Kirsher struct enic *enic = vnic_dev_priv(rq->vdev); 1177a6a5580cSJeff Kirsher struct net_device *netdev = enic->netdev; 1178a6a5580cSJeff Kirsher struct sk_buff *skb; 1179a6a5580cSJeff Kirsher unsigned int len = netdev->mtu + VLAN_ETH_HLEN; 1180a6a5580cSJeff Kirsher unsigned int os_buf_index = 0; 1181a6a5580cSJeff Kirsher dma_addr_t dma_addr; 1182a6a5580cSJeff Kirsher 1183a6a5580cSJeff Kirsher skb = netdev_alloc_skb_ip_align(netdev, len); 1184a6a5580cSJeff Kirsher if (!skb) 1185a6a5580cSJeff Kirsher return -ENOMEM; 1186a6a5580cSJeff Kirsher 1187a6a5580cSJeff Kirsher dma_addr = pci_map_single(enic->pdev, skb->data, 1188a6a5580cSJeff Kirsher len, PCI_DMA_FROMDEVICE); 1189a6a5580cSJeff Kirsher 1190a6a5580cSJeff Kirsher enic_queue_rq_desc(rq, skb, os_buf_index, 1191a6a5580cSJeff Kirsher dma_addr, len); 1192a6a5580cSJeff Kirsher 1193a6a5580cSJeff Kirsher return 0; 1194a6a5580cSJeff Kirsher } 1195a6a5580cSJeff Kirsher 1196a6a5580cSJeff Kirsher static void enic_rq_indicate_buf(struct vnic_rq *rq, 1197a6a5580cSJeff Kirsher struct cq_desc *cq_desc, struct vnic_rq_buf *buf, 1198a6a5580cSJeff Kirsher int skipped, void *opaque) 1199a6a5580cSJeff Kirsher { 1200a6a5580cSJeff Kirsher struct enic *enic = vnic_dev_priv(rq->vdev); 1201a6a5580cSJeff Kirsher struct net_device *netdev = enic->netdev; 1202a6a5580cSJeff Kirsher struct sk_buff *skb; 1203a6a5580cSJeff Kirsher 1204a6a5580cSJeff Kirsher u8 type, color, eop, sop, ingress_port, vlan_stripped; 1205a6a5580cSJeff Kirsher u8 fcoe, fcoe_sof, fcoe_fc_crc_ok, fcoe_enc_error, fcoe_eof; 1206a6a5580cSJeff Kirsher u8 tcp_udp_csum_ok, udp, tcp, ipv4_csum_ok; 1207a6a5580cSJeff Kirsher u8 ipv6, ipv4, ipv4_fragment, fcs_ok, rss_type, csum_not_calc; 1208a6a5580cSJeff Kirsher u8 packet_error; 1209a6a5580cSJeff Kirsher u16 q_number, completed_index, bytes_written, vlan_tci, checksum; 1210a6a5580cSJeff Kirsher u32 rss_hash; 1211a6a5580cSJeff Kirsher 1212a6a5580cSJeff Kirsher if (skipped) 1213a6a5580cSJeff Kirsher return; 1214a6a5580cSJeff Kirsher 1215a6a5580cSJeff Kirsher skb = buf->os_buf; 1216a6a5580cSJeff Kirsher prefetch(skb->data - NET_IP_ALIGN); 1217a6a5580cSJeff Kirsher pci_unmap_single(enic->pdev, buf->dma_addr, 1218a6a5580cSJeff Kirsher buf->len, PCI_DMA_FROMDEVICE); 1219a6a5580cSJeff Kirsher 1220a6a5580cSJeff Kirsher cq_enet_rq_desc_dec((struct cq_enet_rq_desc *)cq_desc, 1221a6a5580cSJeff Kirsher &type, &color, &q_number, &completed_index, 1222a6a5580cSJeff Kirsher &ingress_port, &fcoe, &eop, &sop, &rss_type, 1223a6a5580cSJeff Kirsher &csum_not_calc, &rss_hash, &bytes_written, 1224a6a5580cSJeff Kirsher &packet_error, &vlan_stripped, &vlan_tci, &checksum, 1225a6a5580cSJeff Kirsher &fcoe_sof, &fcoe_fc_crc_ok, &fcoe_enc_error, 1226a6a5580cSJeff Kirsher &fcoe_eof, &tcp_udp_csum_ok, &udp, &tcp, 1227a6a5580cSJeff Kirsher &ipv4_csum_ok, &ipv6, &ipv4, &ipv4_fragment, 1228a6a5580cSJeff Kirsher &fcs_ok); 1229a6a5580cSJeff Kirsher 1230a6a5580cSJeff Kirsher if (packet_error) { 1231a6a5580cSJeff Kirsher 1232a6a5580cSJeff Kirsher if (!fcs_ok) { 1233a6a5580cSJeff Kirsher if (bytes_written > 0) 1234a6a5580cSJeff Kirsher enic->rq_bad_fcs++; 1235a6a5580cSJeff Kirsher else if (bytes_written == 0) 1236a6a5580cSJeff Kirsher enic->rq_truncated_pkts++; 1237a6a5580cSJeff Kirsher } 1238a6a5580cSJeff Kirsher 1239a6a5580cSJeff Kirsher dev_kfree_skb_any(skb); 1240a6a5580cSJeff Kirsher 1241a6a5580cSJeff Kirsher return; 1242a6a5580cSJeff Kirsher } 1243a6a5580cSJeff Kirsher 1244a6a5580cSJeff Kirsher if (eop && bytes_written > 0) { 1245a6a5580cSJeff Kirsher 1246a6a5580cSJeff Kirsher /* Good receive 1247a6a5580cSJeff Kirsher */ 1248a6a5580cSJeff Kirsher 1249a6a5580cSJeff Kirsher skb_put(skb, bytes_written); 1250a6a5580cSJeff Kirsher skb->protocol = eth_type_trans(skb, netdev); 1251a6a5580cSJeff Kirsher 1252a6a5580cSJeff Kirsher if ((netdev->features & NETIF_F_RXCSUM) && !csum_not_calc) { 1253a6a5580cSJeff Kirsher skb->csum = htons(checksum); 1254a6a5580cSJeff Kirsher skb->ip_summed = CHECKSUM_COMPLETE; 1255a6a5580cSJeff Kirsher } 1256a6a5580cSJeff Kirsher 1257a6a5580cSJeff Kirsher skb->dev = netdev; 1258a6a5580cSJeff Kirsher 1259a6a5580cSJeff Kirsher if (vlan_stripped) 1260a6a5580cSJeff Kirsher __vlan_hwaccel_put_tag(skb, vlan_tci); 1261a6a5580cSJeff Kirsher 1262a6a5580cSJeff Kirsher if (netdev->features & NETIF_F_GRO) 1263a6a5580cSJeff Kirsher napi_gro_receive(&enic->napi[q_number], skb); 1264a6a5580cSJeff Kirsher else 1265a6a5580cSJeff Kirsher netif_receive_skb(skb); 1266a6a5580cSJeff Kirsher } else { 1267a6a5580cSJeff Kirsher 1268a6a5580cSJeff Kirsher /* Buffer overflow 1269a6a5580cSJeff Kirsher */ 1270a6a5580cSJeff Kirsher 1271a6a5580cSJeff Kirsher dev_kfree_skb_any(skb); 1272a6a5580cSJeff Kirsher } 1273a6a5580cSJeff Kirsher } 1274a6a5580cSJeff Kirsher 1275a6a5580cSJeff Kirsher static int enic_rq_service(struct vnic_dev *vdev, struct cq_desc *cq_desc, 1276a6a5580cSJeff Kirsher u8 type, u16 q_number, u16 completed_index, void *opaque) 1277a6a5580cSJeff Kirsher { 1278a6a5580cSJeff Kirsher struct enic *enic = vnic_dev_priv(vdev); 1279a6a5580cSJeff Kirsher 1280a6a5580cSJeff Kirsher vnic_rq_service(&enic->rq[q_number], cq_desc, 1281a6a5580cSJeff Kirsher completed_index, VNIC_RQ_RETURN_DESC, 1282a6a5580cSJeff Kirsher enic_rq_indicate_buf, opaque); 1283a6a5580cSJeff Kirsher 1284a6a5580cSJeff Kirsher return 0; 1285a6a5580cSJeff Kirsher } 1286a6a5580cSJeff Kirsher 1287a6a5580cSJeff Kirsher static int enic_poll(struct napi_struct *napi, int budget) 1288a6a5580cSJeff Kirsher { 1289a6a5580cSJeff Kirsher struct net_device *netdev = napi->dev; 1290a6a5580cSJeff Kirsher struct enic *enic = netdev_priv(netdev); 1291a6a5580cSJeff Kirsher unsigned int cq_rq = enic_cq_rq(enic, 0); 1292a6a5580cSJeff Kirsher unsigned int cq_wq = enic_cq_wq(enic, 0); 1293a6a5580cSJeff Kirsher unsigned int intr = enic_legacy_io_intr(); 1294a6a5580cSJeff Kirsher unsigned int rq_work_to_do = budget; 1295a6a5580cSJeff Kirsher unsigned int wq_work_to_do = -1; /* no limit */ 1296a6a5580cSJeff Kirsher unsigned int work_done, rq_work_done, wq_work_done; 1297a6a5580cSJeff Kirsher int err; 1298a6a5580cSJeff Kirsher 1299a6a5580cSJeff Kirsher /* Service RQ (first) and WQ 1300a6a5580cSJeff Kirsher */ 1301a6a5580cSJeff Kirsher 1302a6a5580cSJeff Kirsher rq_work_done = vnic_cq_service(&enic->cq[cq_rq], 1303a6a5580cSJeff Kirsher rq_work_to_do, enic_rq_service, NULL); 1304a6a5580cSJeff Kirsher 1305a6a5580cSJeff Kirsher wq_work_done = vnic_cq_service(&enic->cq[cq_wq], 1306a6a5580cSJeff Kirsher wq_work_to_do, enic_wq_service, NULL); 1307a6a5580cSJeff Kirsher 1308a6a5580cSJeff Kirsher /* Accumulate intr event credits for this polling 1309a6a5580cSJeff Kirsher * cycle. An intr event is the completion of a 1310a6a5580cSJeff Kirsher * a WQ or RQ packet. 1311a6a5580cSJeff Kirsher */ 1312a6a5580cSJeff Kirsher 1313a6a5580cSJeff Kirsher work_done = rq_work_done + wq_work_done; 1314a6a5580cSJeff Kirsher 1315a6a5580cSJeff Kirsher if (work_done > 0) 1316a6a5580cSJeff Kirsher vnic_intr_return_credits(&enic->intr[intr], 1317a6a5580cSJeff Kirsher work_done, 1318a6a5580cSJeff Kirsher 0 /* don't unmask intr */, 1319a6a5580cSJeff Kirsher 0 /* don't reset intr timer */); 1320a6a5580cSJeff Kirsher 1321a6a5580cSJeff Kirsher err = vnic_rq_fill(&enic->rq[0], enic_rq_alloc_buf); 1322a6a5580cSJeff Kirsher 1323a6a5580cSJeff Kirsher /* Buffer allocation failed. Stay in polling 1324a6a5580cSJeff Kirsher * mode so we can try to fill the ring again. 1325a6a5580cSJeff Kirsher */ 1326a6a5580cSJeff Kirsher 1327a6a5580cSJeff Kirsher if (err) 1328a6a5580cSJeff Kirsher rq_work_done = rq_work_to_do; 1329a6a5580cSJeff Kirsher 1330a6a5580cSJeff Kirsher if (rq_work_done < rq_work_to_do) { 1331a6a5580cSJeff Kirsher 1332a6a5580cSJeff Kirsher /* Some work done, but not enough to stay in polling, 1333a6a5580cSJeff Kirsher * exit polling 1334a6a5580cSJeff Kirsher */ 1335a6a5580cSJeff Kirsher 1336a6a5580cSJeff Kirsher napi_complete(napi); 1337a6a5580cSJeff Kirsher vnic_intr_unmask(&enic->intr[intr]); 1338a6a5580cSJeff Kirsher } 1339a6a5580cSJeff Kirsher 1340a6a5580cSJeff Kirsher return rq_work_done; 1341a6a5580cSJeff Kirsher } 1342a6a5580cSJeff Kirsher 1343a6a5580cSJeff Kirsher static int enic_poll_msix(struct napi_struct *napi, int budget) 1344a6a5580cSJeff Kirsher { 1345a6a5580cSJeff Kirsher struct net_device *netdev = napi->dev; 1346a6a5580cSJeff Kirsher struct enic *enic = netdev_priv(netdev); 1347a6a5580cSJeff Kirsher unsigned int rq = (napi - &enic->napi[0]); 1348a6a5580cSJeff Kirsher unsigned int cq = enic_cq_rq(enic, rq); 1349a6a5580cSJeff Kirsher unsigned int intr = enic_msix_rq_intr(enic, rq); 1350a6a5580cSJeff Kirsher unsigned int work_to_do = budget; 1351a6a5580cSJeff Kirsher unsigned int work_done; 1352a6a5580cSJeff Kirsher int err; 1353a6a5580cSJeff Kirsher 1354a6a5580cSJeff Kirsher /* Service RQ 1355a6a5580cSJeff Kirsher */ 1356a6a5580cSJeff Kirsher 1357a6a5580cSJeff Kirsher work_done = vnic_cq_service(&enic->cq[cq], 1358a6a5580cSJeff Kirsher work_to_do, enic_rq_service, NULL); 1359a6a5580cSJeff Kirsher 1360a6a5580cSJeff Kirsher /* Return intr event credits for this polling 1361a6a5580cSJeff Kirsher * cycle. An intr event is the completion of a 1362a6a5580cSJeff Kirsher * RQ packet. 1363a6a5580cSJeff Kirsher */ 1364a6a5580cSJeff Kirsher 1365a6a5580cSJeff Kirsher if (work_done > 0) 1366a6a5580cSJeff Kirsher vnic_intr_return_credits(&enic->intr[intr], 1367a6a5580cSJeff Kirsher work_done, 1368a6a5580cSJeff Kirsher 0 /* don't unmask intr */, 1369a6a5580cSJeff Kirsher 0 /* don't reset intr timer */); 1370a6a5580cSJeff Kirsher 1371a6a5580cSJeff Kirsher err = vnic_rq_fill(&enic->rq[rq], enic_rq_alloc_buf); 1372a6a5580cSJeff Kirsher 1373a6a5580cSJeff Kirsher /* Buffer allocation failed. Stay in polling mode 1374a6a5580cSJeff Kirsher * so we can try to fill the ring again. 1375a6a5580cSJeff Kirsher */ 1376a6a5580cSJeff Kirsher 1377a6a5580cSJeff Kirsher if (err) 1378a6a5580cSJeff Kirsher work_done = work_to_do; 1379a6a5580cSJeff Kirsher 1380a6a5580cSJeff Kirsher if (work_done < work_to_do) { 1381a6a5580cSJeff Kirsher 1382a6a5580cSJeff Kirsher /* Some work done, but not enough to stay in polling, 1383a6a5580cSJeff Kirsher * exit polling 1384a6a5580cSJeff Kirsher */ 1385a6a5580cSJeff Kirsher 1386a6a5580cSJeff Kirsher napi_complete(napi); 1387a6a5580cSJeff Kirsher vnic_intr_unmask(&enic->intr[intr]); 1388a6a5580cSJeff Kirsher } 1389a6a5580cSJeff Kirsher 1390a6a5580cSJeff Kirsher return work_done; 1391a6a5580cSJeff Kirsher } 1392a6a5580cSJeff Kirsher 1393a6a5580cSJeff Kirsher static void enic_notify_timer(unsigned long data) 1394a6a5580cSJeff Kirsher { 1395a6a5580cSJeff Kirsher struct enic *enic = (struct enic *)data; 1396a6a5580cSJeff Kirsher 1397a6a5580cSJeff Kirsher enic_notify_check(enic); 1398a6a5580cSJeff Kirsher 1399a6a5580cSJeff Kirsher mod_timer(&enic->notify_timer, 1400a6a5580cSJeff Kirsher round_jiffies(jiffies + ENIC_NOTIFY_TIMER_PERIOD)); 1401a6a5580cSJeff Kirsher } 1402a6a5580cSJeff Kirsher 1403a6a5580cSJeff Kirsher static void enic_free_intr(struct enic *enic) 1404a6a5580cSJeff Kirsher { 1405a6a5580cSJeff Kirsher struct net_device *netdev = enic->netdev; 1406a6a5580cSJeff Kirsher unsigned int i; 1407a6a5580cSJeff Kirsher 1408a6a5580cSJeff Kirsher switch (vnic_dev_get_intr_mode(enic->vdev)) { 1409a6a5580cSJeff Kirsher case VNIC_DEV_INTR_MODE_INTX: 1410a6a5580cSJeff Kirsher free_irq(enic->pdev->irq, netdev); 1411a6a5580cSJeff Kirsher break; 1412a6a5580cSJeff Kirsher case VNIC_DEV_INTR_MODE_MSI: 1413a6a5580cSJeff Kirsher free_irq(enic->pdev->irq, enic); 1414a6a5580cSJeff Kirsher break; 1415a6a5580cSJeff Kirsher case VNIC_DEV_INTR_MODE_MSIX: 1416a6a5580cSJeff Kirsher for (i = 0; i < ARRAY_SIZE(enic->msix); i++) 1417a6a5580cSJeff Kirsher if (enic->msix[i].requested) 1418a6a5580cSJeff Kirsher free_irq(enic->msix_entry[i].vector, 1419a6a5580cSJeff Kirsher enic->msix[i].devid); 1420a6a5580cSJeff Kirsher break; 1421a6a5580cSJeff Kirsher default: 1422a6a5580cSJeff Kirsher break; 1423a6a5580cSJeff Kirsher } 1424a6a5580cSJeff Kirsher } 1425a6a5580cSJeff Kirsher 1426a6a5580cSJeff Kirsher static int enic_request_intr(struct enic *enic) 1427a6a5580cSJeff Kirsher { 1428a6a5580cSJeff Kirsher struct net_device *netdev = enic->netdev; 1429a6a5580cSJeff Kirsher unsigned int i, intr; 1430a6a5580cSJeff Kirsher int err = 0; 1431a6a5580cSJeff Kirsher 1432a6a5580cSJeff Kirsher switch (vnic_dev_get_intr_mode(enic->vdev)) { 1433a6a5580cSJeff Kirsher 1434a6a5580cSJeff Kirsher case VNIC_DEV_INTR_MODE_INTX: 1435a6a5580cSJeff Kirsher 1436a6a5580cSJeff Kirsher err = request_irq(enic->pdev->irq, enic_isr_legacy, 1437a6a5580cSJeff Kirsher IRQF_SHARED, netdev->name, netdev); 1438a6a5580cSJeff Kirsher break; 1439a6a5580cSJeff Kirsher 1440a6a5580cSJeff Kirsher case VNIC_DEV_INTR_MODE_MSI: 1441a6a5580cSJeff Kirsher 1442a6a5580cSJeff Kirsher err = request_irq(enic->pdev->irq, enic_isr_msi, 1443a6a5580cSJeff Kirsher 0, netdev->name, enic); 1444a6a5580cSJeff Kirsher break; 1445a6a5580cSJeff Kirsher 1446a6a5580cSJeff Kirsher case VNIC_DEV_INTR_MODE_MSIX: 1447a6a5580cSJeff Kirsher 1448a6a5580cSJeff Kirsher for (i = 0; i < enic->rq_count; i++) { 1449a6a5580cSJeff Kirsher intr = enic_msix_rq_intr(enic, i); 1450a6a5580cSJeff Kirsher sprintf(enic->msix[intr].devname, 1451a6a5580cSJeff Kirsher "%.11s-rx-%d", netdev->name, i); 1452a6a5580cSJeff Kirsher enic->msix[intr].isr = enic_isr_msix_rq; 1453a6a5580cSJeff Kirsher enic->msix[intr].devid = &enic->napi[i]; 1454a6a5580cSJeff Kirsher } 1455a6a5580cSJeff Kirsher 1456a6a5580cSJeff Kirsher for (i = 0; i < enic->wq_count; i++) { 1457a6a5580cSJeff Kirsher intr = enic_msix_wq_intr(enic, i); 1458a6a5580cSJeff Kirsher sprintf(enic->msix[intr].devname, 1459a6a5580cSJeff Kirsher "%.11s-tx-%d", netdev->name, i); 1460a6a5580cSJeff Kirsher enic->msix[intr].isr = enic_isr_msix_wq; 1461a6a5580cSJeff Kirsher enic->msix[intr].devid = enic; 1462a6a5580cSJeff Kirsher } 1463a6a5580cSJeff Kirsher 1464a6a5580cSJeff Kirsher intr = enic_msix_err_intr(enic); 1465a6a5580cSJeff Kirsher sprintf(enic->msix[intr].devname, 1466a6a5580cSJeff Kirsher "%.11s-err", netdev->name); 1467a6a5580cSJeff Kirsher enic->msix[intr].isr = enic_isr_msix_err; 1468a6a5580cSJeff Kirsher enic->msix[intr].devid = enic; 1469a6a5580cSJeff Kirsher 1470a6a5580cSJeff Kirsher intr = enic_msix_notify_intr(enic); 1471a6a5580cSJeff Kirsher sprintf(enic->msix[intr].devname, 1472a6a5580cSJeff Kirsher "%.11s-notify", netdev->name); 1473a6a5580cSJeff Kirsher enic->msix[intr].isr = enic_isr_msix_notify; 1474a6a5580cSJeff Kirsher enic->msix[intr].devid = enic; 1475a6a5580cSJeff Kirsher 1476a6a5580cSJeff Kirsher for (i = 0; i < ARRAY_SIZE(enic->msix); i++) 1477a6a5580cSJeff Kirsher enic->msix[i].requested = 0; 1478a6a5580cSJeff Kirsher 1479a6a5580cSJeff Kirsher for (i = 0; i < enic->intr_count; i++) { 1480a6a5580cSJeff Kirsher err = request_irq(enic->msix_entry[i].vector, 1481a6a5580cSJeff Kirsher enic->msix[i].isr, 0, 1482a6a5580cSJeff Kirsher enic->msix[i].devname, 1483a6a5580cSJeff Kirsher enic->msix[i].devid); 1484a6a5580cSJeff Kirsher if (err) { 1485a6a5580cSJeff Kirsher enic_free_intr(enic); 1486a6a5580cSJeff Kirsher break; 1487a6a5580cSJeff Kirsher } 1488a6a5580cSJeff Kirsher enic->msix[i].requested = 1; 1489a6a5580cSJeff Kirsher } 1490a6a5580cSJeff Kirsher 1491a6a5580cSJeff Kirsher break; 1492a6a5580cSJeff Kirsher 1493a6a5580cSJeff Kirsher default: 1494a6a5580cSJeff Kirsher break; 1495a6a5580cSJeff Kirsher } 1496a6a5580cSJeff Kirsher 1497a6a5580cSJeff Kirsher return err; 1498a6a5580cSJeff Kirsher } 1499a6a5580cSJeff Kirsher 1500a6a5580cSJeff Kirsher static void enic_synchronize_irqs(struct enic *enic) 1501a6a5580cSJeff Kirsher { 1502a6a5580cSJeff Kirsher unsigned int i; 1503a6a5580cSJeff Kirsher 1504a6a5580cSJeff Kirsher switch (vnic_dev_get_intr_mode(enic->vdev)) { 1505a6a5580cSJeff Kirsher case VNIC_DEV_INTR_MODE_INTX: 1506a6a5580cSJeff Kirsher case VNIC_DEV_INTR_MODE_MSI: 1507a6a5580cSJeff Kirsher synchronize_irq(enic->pdev->irq); 1508a6a5580cSJeff Kirsher break; 1509a6a5580cSJeff Kirsher case VNIC_DEV_INTR_MODE_MSIX: 1510a6a5580cSJeff Kirsher for (i = 0; i < enic->intr_count; i++) 1511a6a5580cSJeff Kirsher synchronize_irq(enic->msix_entry[i].vector); 1512a6a5580cSJeff Kirsher break; 1513a6a5580cSJeff Kirsher default: 1514a6a5580cSJeff Kirsher break; 1515a6a5580cSJeff Kirsher } 1516a6a5580cSJeff Kirsher } 1517a6a5580cSJeff Kirsher 1518a6a5580cSJeff Kirsher static int enic_dev_notify_set(struct enic *enic) 1519a6a5580cSJeff Kirsher { 1520a6a5580cSJeff Kirsher int err; 1521a6a5580cSJeff Kirsher 1522a6a5580cSJeff Kirsher spin_lock(&enic->devcmd_lock); 1523a6a5580cSJeff Kirsher switch (vnic_dev_get_intr_mode(enic->vdev)) { 1524a6a5580cSJeff Kirsher case VNIC_DEV_INTR_MODE_INTX: 1525a6a5580cSJeff Kirsher err = vnic_dev_notify_set(enic->vdev, 1526a6a5580cSJeff Kirsher enic_legacy_notify_intr()); 1527a6a5580cSJeff Kirsher break; 1528a6a5580cSJeff Kirsher case VNIC_DEV_INTR_MODE_MSIX: 1529a6a5580cSJeff Kirsher err = vnic_dev_notify_set(enic->vdev, 1530a6a5580cSJeff Kirsher enic_msix_notify_intr(enic)); 1531a6a5580cSJeff Kirsher break; 1532a6a5580cSJeff Kirsher default: 1533a6a5580cSJeff Kirsher err = vnic_dev_notify_set(enic->vdev, -1 /* no intr */); 1534a6a5580cSJeff Kirsher break; 1535a6a5580cSJeff Kirsher } 1536a6a5580cSJeff Kirsher spin_unlock(&enic->devcmd_lock); 1537a6a5580cSJeff Kirsher 1538a6a5580cSJeff Kirsher return err; 1539a6a5580cSJeff Kirsher } 1540a6a5580cSJeff Kirsher 1541a6a5580cSJeff Kirsher static void enic_notify_timer_start(struct enic *enic) 1542a6a5580cSJeff Kirsher { 1543a6a5580cSJeff Kirsher switch (vnic_dev_get_intr_mode(enic->vdev)) { 1544a6a5580cSJeff Kirsher case VNIC_DEV_INTR_MODE_MSI: 1545a6a5580cSJeff Kirsher mod_timer(&enic->notify_timer, jiffies); 1546a6a5580cSJeff Kirsher break; 1547a6a5580cSJeff Kirsher default: 1548a6a5580cSJeff Kirsher /* Using intr for notification for INTx/MSI-X */ 1549a6a5580cSJeff Kirsher break; 1550a6a5580cSJeff Kirsher } 1551a6a5580cSJeff Kirsher } 1552a6a5580cSJeff Kirsher 1553a6a5580cSJeff Kirsher /* rtnl lock is held, process context */ 1554a6a5580cSJeff Kirsher static int enic_open(struct net_device *netdev) 1555a6a5580cSJeff Kirsher { 1556a6a5580cSJeff Kirsher struct enic *enic = netdev_priv(netdev); 1557a6a5580cSJeff Kirsher unsigned int i; 1558a6a5580cSJeff Kirsher int err; 1559a6a5580cSJeff Kirsher 1560a6a5580cSJeff Kirsher err = enic_request_intr(enic); 1561a6a5580cSJeff Kirsher if (err) { 1562a6a5580cSJeff Kirsher netdev_err(netdev, "Unable to request irq.\n"); 1563a6a5580cSJeff Kirsher return err; 1564a6a5580cSJeff Kirsher } 1565a6a5580cSJeff Kirsher 1566a6a5580cSJeff Kirsher err = enic_dev_notify_set(enic); 1567a6a5580cSJeff Kirsher if (err) { 1568a6a5580cSJeff Kirsher netdev_err(netdev, 1569a6a5580cSJeff Kirsher "Failed to alloc notify buffer, aborting.\n"); 1570a6a5580cSJeff Kirsher goto err_out_free_intr; 1571a6a5580cSJeff Kirsher } 1572a6a5580cSJeff Kirsher 1573a6a5580cSJeff Kirsher for (i = 0; i < enic->rq_count; i++) { 1574a6a5580cSJeff Kirsher vnic_rq_fill(&enic->rq[i], enic_rq_alloc_buf); 1575a6a5580cSJeff Kirsher /* Need at least one buffer on ring to get going */ 1576a6a5580cSJeff Kirsher if (vnic_rq_desc_used(&enic->rq[i]) == 0) { 1577a6a5580cSJeff Kirsher netdev_err(netdev, "Unable to alloc receive buffers\n"); 1578a6a5580cSJeff Kirsher err = -ENOMEM; 1579a6a5580cSJeff Kirsher goto err_out_notify_unset; 1580a6a5580cSJeff Kirsher } 1581a6a5580cSJeff Kirsher } 1582a6a5580cSJeff Kirsher 1583a6a5580cSJeff Kirsher for (i = 0; i < enic->wq_count; i++) 1584a6a5580cSJeff Kirsher vnic_wq_enable(&enic->wq[i]); 1585a6a5580cSJeff Kirsher for (i = 0; i < enic->rq_count; i++) 1586a6a5580cSJeff Kirsher vnic_rq_enable(&enic->rq[i]); 1587a6a5580cSJeff Kirsher 1588a6a5580cSJeff Kirsher if (enic_is_dynamic(enic) && !is_zero_ether_addr(enic->pp.mac_addr)) 1589a6a5580cSJeff Kirsher enic_dev_add_addr(enic, enic->pp.mac_addr); 1590a6a5580cSJeff Kirsher else 1591a6a5580cSJeff Kirsher enic_dev_add_station_addr(enic); 1592a6a5580cSJeff Kirsher enic_set_rx_mode(netdev); 1593a6a5580cSJeff Kirsher 1594a6a5580cSJeff Kirsher netif_wake_queue(netdev); 1595a6a5580cSJeff Kirsher 1596a6a5580cSJeff Kirsher for (i = 0; i < enic->rq_count; i++) 1597a6a5580cSJeff Kirsher napi_enable(&enic->napi[i]); 1598a6a5580cSJeff Kirsher 1599a6a5580cSJeff Kirsher enic_dev_enable(enic); 1600a6a5580cSJeff Kirsher 1601a6a5580cSJeff Kirsher for (i = 0; i < enic->intr_count; i++) 1602a6a5580cSJeff Kirsher vnic_intr_unmask(&enic->intr[i]); 1603a6a5580cSJeff Kirsher 1604a6a5580cSJeff Kirsher enic_notify_timer_start(enic); 1605a6a5580cSJeff Kirsher 1606a6a5580cSJeff Kirsher return 0; 1607a6a5580cSJeff Kirsher 1608a6a5580cSJeff Kirsher err_out_notify_unset: 1609a6a5580cSJeff Kirsher enic_dev_notify_unset(enic); 1610a6a5580cSJeff Kirsher err_out_free_intr: 1611a6a5580cSJeff Kirsher enic_free_intr(enic); 1612a6a5580cSJeff Kirsher 1613a6a5580cSJeff Kirsher return err; 1614a6a5580cSJeff Kirsher } 1615a6a5580cSJeff Kirsher 1616a6a5580cSJeff Kirsher /* rtnl lock is held, process context */ 1617a6a5580cSJeff Kirsher static int enic_stop(struct net_device *netdev) 1618a6a5580cSJeff Kirsher { 1619a6a5580cSJeff Kirsher struct enic *enic = netdev_priv(netdev); 1620a6a5580cSJeff Kirsher unsigned int i; 1621a6a5580cSJeff Kirsher int err; 1622a6a5580cSJeff Kirsher 1623a6a5580cSJeff Kirsher for (i = 0; i < enic->intr_count; i++) { 1624a6a5580cSJeff Kirsher vnic_intr_mask(&enic->intr[i]); 1625a6a5580cSJeff Kirsher (void)vnic_intr_masked(&enic->intr[i]); /* flush write */ 1626a6a5580cSJeff Kirsher } 1627a6a5580cSJeff Kirsher 1628a6a5580cSJeff Kirsher enic_synchronize_irqs(enic); 1629a6a5580cSJeff Kirsher 1630a6a5580cSJeff Kirsher del_timer_sync(&enic->notify_timer); 1631a6a5580cSJeff Kirsher 1632a6a5580cSJeff Kirsher enic_dev_disable(enic); 1633a6a5580cSJeff Kirsher 1634a6a5580cSJeff Kirsher for (i = 0; i < enic->rq_count; i++) 1635a6a5580cSJeff Kirsher napi_disable(&enic->napi[i]); 1636a6a5580cSJeff Kirsher 1637a6a5580cSJeff Kirsher netif_carrier_off(netdev); 1638a6a5580cSJeff Kirsher netif_tx_disable(netdev); 1639a6a5580cSJeff Kirsher if (enic_is_dynamic(enic) && !is_zero_ether_addr(enic->pp.mac_addr)) 1640a6a5580cSJeff Kirsher enic_dev_del_addr(enic, enic->pp.mac_addr); 1641a6a5580cSJeff Kirsher else 1642a6a5580cSJeff Kirsher enic_dev_del_station_addr(enic); 1643a6a5580cSJeff Kirsher 1644a6a5580cSJeff Kirsher for (i = 0; i < enic->wq_count; i++) { 1645a6a5580cSJeff Kirsher err = vnic_wq_disable(&enic->wq[i]); 1646a6a5580cSJeff Kirsher if (err) 1647a6a5580cSJeff Kirsher return err; 1648a6a5580cSJeff Kirsher } 1649a6a5580cSJeff Kirsher for (i = 0; i < enic->rq_count; i++) { 1650a6a5580cSJeff Kirsher err = vnic_rq_disable(&enic->rq[i]); 1651a6a5580cSJeff Kirsher if (err) 1652a6a5580cSJeff Kirsher return err; 1653a6a5580cSJeff Kirsher } 1654a6a5580cSJeff Kirsher 1655a6a5580cSJeff Kirsher enic_dev_notify_unset(enic); 1656a6a5580cSJeff Kirsher enic_free_intr(enic); 1657a6a5580cSJeff Kirsher 1658a6a5580cSJeff Kirsher for (i = 0; i < enic->wq_count; i++) 1659a6a5580cSJeff Kirsher vnic_wq_clean(&enic->wq[i], enic_free_wq_buf); 1660a6a5580cSJeff Kirsher for (i = 0; i < enic->rq_count; i++) 1661a6a5580cSJeff Kirsher vnic_rq_clean(&enic->rq[i], enic_free_rq_buf); 1662a6a5580cSJeff Kirsher for (i = 0; i < enic->cq_count; i++) 1663a6a5580cSJeff Kirsher vnic_cq_clean(&enic->cq[i]); 1664a6a5580cSJeff Kirsher for (i = 0; i < enic->intr_count; i++) 1665a6a5580cSJeff Kirsher vnic_intr_clean(&enic->intr[i]); 1666a6a5580cSJeff Kirsher 1667a6a5580cSJeff Kirsher return 0; 1668a6a5580cSJeff Kirsher } 1669a6a5580cSJeff Kirsher 1670a6a5580cSJeff Kirsher static int enic_change_mtu(struct net_device *netdev, int new_mtu) 1671a6a5580cSJeff Kirsher { 1672a6a5580cSJeff Kirsher struct enic *enic = netdev_priv(netdev); 1673a6a5580cSJeff Kirsher int running = netif_running(netdev); 1674a6a5580cSJeff Kirsher 1675a6a5580cSJeff Kirsher if (new_mtu < ENIC_MIN_MTU || new_mtu > ENIC_MAX_MTU) 1676a6a5580cSJeff Kirsher return -EINVAL; 1677a6a5580cSJeff Kirsher 1678a6a5580cSJeff Kirsher if (enic_is_dynamic(enic)) 1679a6a5580cSJeff Kirsher return -EOPNOTSUPP; 1680a6a5580cSJeff Kirsher 1681a6a5580cSJeff Kirsher if (running) 1682a6a5580cSJeff Kirsher enic_stop(netdev); 1683a6a5580cSJeff Kirsher 1684a6a5580cSJeff Kirsher netdev->mtu = new_mtu; 1685a6a5580cSJeff Kirsher 1686a6a5580cSJeff Kirsher if (netdev->mtu > enic->port_mtu) 1687a6a5580cSJeff Kirsher netdev_warn(netdev, 1688a6a5580cSJeff Kirsher "interface MTU (%d) set higher than port MTU (%d)\n", 1689a6a5580cSJeff Kirsher netdev->mtu, enic->port_mtu); 1690a6a5580cSJeff Kirsher 1691a6a5580cSJeff Kirsher if (running) 1692a6a5580cSJeff Kirsher enic_open(netdev); 1693a6a5580cSJeff Kirsher 1694a6a5580cSJeff Kirsher return 0; 1695a6a5580cSJeff Kirsher } 1696a6a5580cSJeff Kirsher 1697a6a5580cSJeff Kirsher static void enic_change_mtu_work(struct work_struct *work) 1698a6a5580cSJeff Kirsher { 1699a6a5580cSJeff Kirsher struct enic *enic = container_of(work, struct enic, change_mtu_work); 1700a6a5580cSJeff Kirsher struct net_device *netdev = enic->netdev; 1701a6a5580cSJeff Kirsher int new_mtu = vnic_dev_mtu(enic->vdev); 1702a6a5580cSJeff Kirsher int err; 1703a6a5580cSJeff Kirsher unsigned int i; 1704a6a5580cSJeff Kirsher 1705a6a5580cSJeff Kirsher new_mtu = max_t(int, ENIC_MIN_MTU, min_t(int, ENIC_MAX_MTU, new_mtu)); 1706a6a5580cSJeff Kirsher 1707a6a5580cSJeff Kirsher rtnl_lock(); 1708a6a5580cSJeff Kirsher 1709a6a5580cSJeff Kirsher /* Stop RQ */ 1710a6a5580cSJeff Kirsher del_timer_sync(&enic->notify_timer); 1711a6a5580cSJeff Kirsher 1712a6a5580cSJeff Kirsher for (i = 0; i < enic->rq_count; i++) 1713a6a5580cSJeff Kirsher napi_disable(&enic->napi[i]); 1714a6a5580cSJeff Kirsher 1715a6a5580cSJeff Kirsher vnic_intr_mask(&enic->intr[0]); 1716a6a5580cSJeff Kirsher enic_synchronize_irqs(enic); 1717a6a5580cSJeff Kirsher err = vnic_rq_disable(&enic->rq[0]); 1718a6a5580cSJeff Kirsher if (err) { 1719a6a5580cSJeff Kirsher netdev_err(netdev, "Unable to disable RQ.\n"); 1720a6a5580cSJeff Kirsher return; 1721a6a5580cSJeff Kirsher } 1722a6a5580cSJeff Kirsher vnic_rq_clean(&enic->rq[0], enic_free_rq_buf); 1723a6a5580cSJeff Kirsher vnic_cq_clean(&enic->cq[0]); 1724a6a5580cSJeff Kirsher vnic_intr_clean(&enic->intr[0]); 1725a6a5580cSJeff Kirsher 1726a6a5580cSJeff Kirsher /* Fill RQ with new_mtu-sized buffers */ 1727a6a5580cSJeff Kirsher netdev->mtu = new_mtu; 1728a6a5580cSJeff Kirsher vnic_rq_fill(&enic->rq[0], enic_rq_alloc_buf); 1729a6a5580cSJeff Kirsher /* Need at least one buffer on ring to get going */ 1730a6a5580cSJeff Kirsher if (vnic_rq_desc_used(&enic->rq[0]) == 0) { 1731a6a5580cSJeff Kirsher netdev_err(netdev, "Unable to alloc receive buffers.\n"); 1732a6a5580cSJeff Kirsher return; 1733a6a5580cSJeff Kirsher } 1734a6a5580cSJeff Kirsher 1735a6a5580cSJeff Kirsher /* Start RQ */ 1736a6a5580cSJeff Kirsher vnic_rq_enable(&enic->rq[0]); 1737a6a5580cSJeff Kirsher napi_enable(&enic->napi[0]); 1738a6a5580cSJeff Kirsher vnic_intr_unmask(&enic->intr[0]); 1739a6a5580cSJeff Kirsher enic_notify_timer_start(enic); 1740a6a5580cSJeff Kirsher 1741a6a5580cSJeff Kirsher rtnl_unlock(); 1742a6a5580cSJeff Kirsher 1743a6a5580cSJeff Kirsher netdev_info(netdev, "interface MTU set as %d\n", netdev->mtu); 1744a6a5580cSJeff Kirsher } 1745a6a5580cSJeff Kirsher 1746a6a5580cSJeff Kirsher #ifdef CONFIG_NET_POLL_CONTROLLER 1747a6a5580cSJeff Kirsher static void enic_poll_controller(struct net_device *netdev) 1748a6a5580cSJeff Kirsher { 1749a6a5580cSJeff Kirsher struct enic *enic = netdev_priv(netdev); 1750a6a5580cSJeff Kirsher struct vnic_dev *vdev = enic->vdev; 1751a6a5580cSJeff Kirsher unsigned int i, intr; 1752a6a5580cSJeff Kirsher 1753a6a5580cSJeff Kirsher switch (vnic_dev_get_intr_mode(vdev)) { 1754a6a5580cSJeff Kirsher case VNIC_DEV_INTR_MODE_MSIX: 1755a6a5580cSJeff Kirsher for (i = 0; i < enic->rq_count; i++) { 1756a6a5580cSJeff Kirsher intr = enic_msix_rq_intr(enic, i); 1757a6a5580cSJeff Kirsher enic_isr_msix_rq(enic->msix_entry[intr].vector, 1758a6a5580cSJeff Kirsher &enic->napi[i]); 1759a6a5580cSJeff Kirsher } 1760a6a5580cSJeff Kirsher 1761a6a5580cSJeff Kirsher for (i = 0; i < enic->wq_count; i++) { 1762a6a5580cSJeff Kirsher intr = enic_msix_wq_intr(enic, i); 1763a6a5580cSJeff Kirsher enic_isr_msix_wq(enic->msix_entry[intr].vector, enic); 1764a6a5580cSJeff Kirsher } 1765a6a5580cSJeff Kirsher 1766a6a5580cSJeff Kirsher break; 1767a6a5580cSJeff Kirsher case VNIC_DEV_INTR_MODE_MSI: 1768a6a5580cSJeff Kirsher enic_isr_msi(enic->pdev->irq, enic); 1769a6a5580cSJeff Kirsher break; 1770a6a5580cSJeff Kirsher case VNIC_DEV_INTR_MODE_INTX: 1771a6a5580cSJeff Kirsher enic_isr_legacy(enic->pdev->irq, netdev); 1772a6a5580cSJeff Kirsher break; 1773a6a5580cSJeff Kirsher default: 1774a6a5580cSJeff Kirsher break; 1775a6a5580cSJeff Kirsher } 1776a6a5580cSJeff Kirsher } 1777a6a5580cSJeff Kirsher #endif 1778a6a5580cSJeff Kirsher 1779a6a5580cSJeff Kirsher static int enic_dev_wait(struct vnic_dev *vdev, 1780a6a5580cSJeff Kirsher int (*start)(struct vnic_dev *, int), 1781a6a5580cSJeff Kirsher int (*finished)(struct vnic_dev *, int *), 1782a6a5580cSJeff Kirsher int arg) 1783a6a5580cSJeff Kirsher { 1784a6a5580cSJeff Kirsher unsigned long time; 1785a6a5580cSJeff Kirsher int done; 1786a6a5580cSJeff Kirsher int err; 1787a6a5580cSJeff Kirsher 1788a6a5580cSJeff Kirsher BUG_ON(in_interrupt()); 1789a6a5580cSJeff Kirsher 1790a6a5580cSJeff Kirsher err = start(vdev, arg); 1791a6a5580cSJeff Kirsher if (err) 1792a6a5580cSJeff Kirsher return err; 1793a6a5580cSJeff Kirsher 1794a6a5580cSJeff Kirsher /* Wait for func to complete...2 seconds max 1795a6a5580cSJeff Kirsher */ 1796a6a5580cSJeff Kirsher 1797a6a5580cSJeff Kirsher time = jiffies + (HZ * 2); 1798a6a5580cSJeff Kirsher do { 1799a6a5580cSJeff Kirsher 1800a6a5580cSJeff Kirsher err = finished(vdev, &done); 1801a6a5580cSJeff Kirsher if (err) 1802a6a5580cSJeff Kirsher return err; 1803a6a5580cSJeff Kirsher 1804a6a5580cSJeff Kirsher if (done) 1805a6a5580cSJeff Kirsher return 0; 1806a6a5580cSJeff Kirsher 1807a6a5580cSJeff Kirsher schedule_timeout_uninterruptible(HZ / 10); 1808a6a5580cSJeff Kirsher 1809a6a5580cSJeff Kirsher } while (time_after(time, jiffies)); 1810a6a5580cSJeff Kirsher 1811a6a5580cSJeff Kirsher return -ETIMEDOUT; 1812a6a5580cSJeff Kirsher } 1813a6a5580cSJeff Kirsher 1814a6a5580cSJeff Kirsher static int enic_dev_open(struct enic *enic) 1815a6a5580cSJeff Kirsher { 1816a6a5580cSJeff Kirsher int err; 1817a6a5580cSJeff Kirsher 1818a6a5580cSJeff Kirsher err = enic_dev_wait(enic->vdev, vnic_dev_open, 1819a6a5580cSJeff Kirsher vnic_dev_open_done, 0); 1820a6a5580cSJeff Kirsher if (err) 1821a6a5580cSJeff Kirsher dev_err(enic_get_dev(enic), "vNIC device open failed, err %d\n", 1822a6a5580cSJeff Kirsher err); 1823a6a5580cSJeff Kirsher 1824a6a5580cSJeff Kirsher return err; 1825a6a5580cSJeff Kirsher } 1826a6a5580cSJeff Kirsher 1827a6a5580cSJeff Kirsher static int enic_dev_hang_reset(struct enic *enic) 1828a6a5580cSJeff Kirsher { 1829a6a5580cSJeff Kirsher int err; 1830a6a5580cSJeff Kirsher 1831a6a5580cSJeff Kirsher err = enic_dev_wait(enic->vdev, vnic_dev_hang_reset, 1832a6a5580cSJeff Kirsher vnic_dev_hang_reset_done, 0); 1833a6a5580cSJeff Kirsher if (err) 1834a6a5580cSJeff Kirsher netdev_err(enic->netdev, "vNIC hang reset failed, err %d\n", 1835a6a5580cSJeff Kirsher err); 1836a6a5580cSJeff Kirsher 1837a6a5580cSJeff Kirsher return err; 1838a6a5580cSJeff Kirsher } 1839a6a5580cSJeff Kirsher 1840a6a5580cSJeff Kirsher static int enic_set_rsskey(struct enic *enic) 1841a6a5580cSJeff Kirsher { 1842a6a5580cSJeff Kirsher dma_addr_t rss_key_buf_pa; 1843a6a5580cSJeff Kirsher union vnic_rss_key *rss_key_buf_va = NULL; 1844a6a5580cSJeff Kirsher union vnic_rss_key rss_key = { 1845a6a5580cSJeff Kirsher .key[0].b = {85, 67, 83, 97, 119, 101, 115, 111, 109, 101}, 1846a6a5580cSJeff Kirsher .key[1].b = {80, 65, 76, 79, 117, 110, 105, 113, 117, 101}, 1847a6a5580cSJeff Kirsher .key[2].b = {76, 73, 78, 85, 88, 114, 111, 99, 107, 115}, 1848a6a5580cSJeff Kirsher .key[3].b = {69, 78, 73, 67, 105, 115, 99, 111, 111, 108}, 1849a6a5580cSJeff Kirsher }; 1850a6a5580cSJeff Kirsher int err; 1851a6a5580cSJeff Kirsher 1852a6a5580cSJeff Kirsher rss_key_buf_va = pci_alloc_consistent(enic->pdev, 1853a6a5580cSJeff Kirsher sizeof(union vnic_rss_key), &rss_key_buf_pa); 1854a6a5580cSJeff Kirsher if (!rss_key_buf_va) 1855a6a5580cSJeff Kirsher return -ENOMEM; 1856a6a5580cSJeff Kirsher 1857a6a5580cSJeff Kirsher memcpy(rss_key_buf_va, &rss_key, sizeof(union vnic_rss_key)); 1858a6a5580cSJeff Kirsher 1859a6a5580cSJeff Kirsher spin_lock(&enic->devcmd_lock); 1860a6a5580cSJeff Kirsher err = enic_set_rss_key(enic, 1861a6a5580cSJeff Kirsher rss_key_buf_pa, 1862a6a5580cSJeff Kirsher sizeof(union vnic_rss_key)); 1863a6a5580cSJeff Kirsher spin_unlock(&enic->devcmd_lock); 1864a6a5580cSJeff Kirsher 1865a6a5580cSJeff Kirsher pci_free_consistent(enic->pdev, sizeof(union vnic_rss_key), 1866a6a5580cSJeff Kirsher rss_key_buf_va, rss_key_buf_pa); 1867a6a5580cSJeff Kirsher 1868a6a5580cSJeff Kirsher return err; 1869a6a5580cSJeff Kirsher } 1870a6a5580cSJeff Kirsher 1871a6a5580cSJeff Kirsher static int enic_set_rsscpu(struct enic *enic, u8 rss_hash_bits) 1872a6a5580cSJeff Kirsher { 1873a6a5580cSJeff Kirsher dma_addr_t rss_cpu_buf_pa; 1874a6a5580cSJeff Kirsher union vnic_rss_cpu *rss_cpu_buf_va = NULL; 1875a6a5580cSJeff Kirsher unsigned int i; 1876a6a5580cSJeff Kirsher int err; 1877a6a5580cSJeff Kirsher 1878a6a5580cSJeff Kirsher rss_cpu_buf_va = pci_alloc_consistent(enic->pdev, 1879a6a5580cSJeff Kirsher sizeof(union vnic_rss_cpu), &rss_cpu_buf_pa); 1880a6a5580cSJeff Kirsher if (!rss_cpu_buf_va) 1881a6a5580cSJeff Kirsher return -ENOMEM; 1882a6a5580cSJeff Kirsher 1883a6a5580cSJeff Kirsher for (i = 0; i < (1 << rss_hash_bits); i++) 1884a6a5580cSJeff Kirsher (*rss_cpu_buf_va).cpu[i/4].b[i%4] = i % enic->rq_count; 1885a6a5580cSJeff Kirsher 1886a6a5580cSJeff Kirsher spin_lock(&enic->devcmd_lock); 1887a6a5580cSJeff Kirsher err = enic_set_rss_cpu(enic, 1888a6a5580cSJeff Kirsher rss_cpu_buf_pa, 1889a6a5580cSJeff Kirsher sizeof(union vnic_rss_cpu)); 1890a6a5580cSJeff Kirsher spin_unlock(&enic->devcmd_lock); 1891a6a5580cSJeff Kirsher 1892a6a5580cSJeff Kirsher pci_free_consistent(enic->pdev, sizeof(union vnic_rss_cpu), 1893a6a5580cSJeff Kirsher rss_cpu_buf_va, rss_cpu_buf_pa); 1894a6a5580cSJeff Kirsher 1895a6a5580cSJeff Kirsher return err; 1896a6a5580cSJeff Kirsher } 1897a6a5580cSJeff Kirsher 1898a6a5580cSJeff Kirsher static int enic_set_niccfg(struct enic *enic, u8 rss_default_cpu, 1899a6a5580cSJeff Kirsher u8 rss_hash_type, u8 rss_hash_bits, u8 rss_base_cpu, u8 rss_enable) 1900a6a5580cSJeff Kirsher { 1901a6a5580cSJeff Kirsher const u8 tso_ipid_split_en = 0; 1902a6a5580cSJeff Kirsher const u8 ig_vlan_strip_en = 1; 1903a6a5580cSJeff Kirsher int err; 1904a6a5580cSJeff Kirsher 1905a6a5580cSJeff Kirsher /* Enable VLAN tag stripping. 1906a6a5580cSJeff Kirsher */ 1907a6a5580cSJeff Kirsher 1908a6a5580cSJeff Kirsher spin_lock(&enic->devcmd_lock); 1909a6a5580cSJeff Kirsher err = enic_set_nic_cfg(enic, 1910a6a5580cSJeff Kirsher rss_default_cpu, rss_hash_type, 1911a6a5580cSJeff Kirsher rss_hash_bits, rss_base_cpu, 1912a6a5580cSJeff Kirsher rss_enable, tso_ipid_split_en, 1913a6a5580cSJeff Kirsher ig_vlan_strip_en); 1914a6a5580cSJeff Kirsher spin_unlock(&enic->devcmd_lock); 1915a6a5580cSJeff Kirsher 1916a6a5580cSJeff Kirsher return err; 1917a6a5580cSJeff Kirsher } 1918a6a5580cSJeff Kirsher 1919a6a5580cSJeff Kirsher static int enic_set_rss_nic_cfg(struct enic *enic) 1920a6a5580cSJeff Kirsher { 1921a6a5580cSJeff Kirsher struct device *dev = enic_get_dev(enic); 1922a6a5580cSJeff Kirsher const u8 rss_default_cpu = 0; 1923a6a5580cSJeff Kirsher const u8 rss_hash_type = NIC_CFG_RSS_HASH_TYPE_IPV4 | 1924a6a5580cSJeff Kirsher NIC_CFG_RSS_HASH_TYPE_TCP_IPV4 | 1925a6a5580cSJeff Kirsher NIC_CFG_RSS_HASH_TYPE_IPV6 | 1926a6a5580cSJeff Kirsher NIC_CFG_RSS_HASH_TYPE_TCP_IPV6; 1927a6a5580cSJeff Kirsher const u8 rss_hash_bits = 7; 1928a6a5580cSJeff Kirsher const u8 rss_base_cpu = 0; 1929a6a5580cSJeff Kirsher u8 rss_enable = ENIC_SETTING(enic, RSS) && (enic->rq_count > 1); 1930a6a5580cSJeff Kirsher 1931a6a5580cSJeff Kirsher if (rss_enable) { 1932a6a5580cSJeff Kirsher if (!enic_set_rsskey(enic)) { 1933a6a5580cSJeff Kirsher if (enic_set_rsscpu(enic, rss_hash_bits)) { 1934a6a5580cSJeff Kirsher rss_enable = 0; 1935a6a5580cSJeff Kirsher dev_warn(dev, "RSS disabled, " 1936a6a5580cSJeff Kirsher "Failed to set RSS cpu indirection table."); 1937a6a5580cSJeff Kirsher } 1938a6a5580cSJeff Kirsher } else { 1939a6a5580cSJeff Kirsher rss_enable = 0; 1940a6a5580cSJeff Kirsher dev_warn(dev, "RSS disabled, Failed to set RSS key.\n"); 1941a6a5580cSJeff Kirsher } 1942a6a5580cSJeff Kirsher } 1943a6a5580cSJeff Kirsher 1944a6a5580cSJeff Kirsher return enic_set_niccfg(enic, rss_default_cpu, rss_hash_type, 1945a6a5580cSJeff Kirsher rss_hash_bits, rss_base_cpu, rss_enable); 1946a6a5580cSJeff Kirsher } 1947a6a5580cSJeff Kirsher 1948a6a5580cSJeff Kirsher static void enic_reset(struct work_struct *work) 1949a6a5580cSJeff Kirsher { 1950a6a5580cSJeff Kirsher struct enic *enic = container_of(work, struct enic, reset); 1951a6a5580cSJeff Kirsher 1952a6a5580cSJeff Kirsher if (!netif_running(enic->netdev)) 1953a6a5580cSJeff Kirsher return; 1954a6a5580cSJeff Kirsher 1955a6a5580cSJeff Kirsher rtnl_lock(); 1956a6a5580cSJeff Kirsher 1957a6a5580cSJeff Kirsher enic_dev_hang_notify(enic); 1958a6a5580cSJeff Kirsher enic_stop(enic->netdev); 1959a6a5580cSJeff Kirsher enic_dev_hang_reset(enic); 1960a6a5580cSJeff Kirsher enic_reset_addr_lists(enic); 1961a6a5580cSJeff Kirsher enic_init_vnic_resources(enic); 1962a6a5580cSJeff Kirsher enic_set_rss_nic_cfg(enic); 1963a6a5580cSJeff Kirsher enic_dev_set_ig_vlan_rewrite_mode(enic); 1964a6a5580cSJeff Kirsher enic_open(enic->netdev); 1965a6a5580cSJeff Kirsher 1966a6a5580cSJeff Kirsher rtnl_unlock(); 1967a6a5580cSJeff Kirsher } 1968a6a5580cSJeff Kirsher 1969a6a5580cSJeff Kirsher static int enic_set_intr_mode(struct enic *enic) 1970a6a5580cSJeff Kirsher { 1971a6a5580cSJeff Kirsher unsigned int n = min_t(unsigned int, enic->rq_count, ENIC_RQ_MAX); 1972a6a5580cSJeff Kirsher unsigned int m = min_t(unsigned int, enic->wq_count, ENIC_WQ_MAX); 1973a6a5580cSJeff Kirsher unsigned int i; 1974a6a5580cSJeff Kirsher 1975a6a5580cSJeff Kirsher /* Set interrupt mode (INTx, MSI, MSI-X) depending 1976a6a5580cSJeff Kirsher * on system capabilities. 1977a6a5580cSJeff Kirsher * 1978a6a5580cSJeff Kirsher * Try MSI-X first 1979a6a5580cSJeff Kirsher * 1980a6a5580cSJeff Kirsher * We need n RQs, m WQs, n+m CQs, and n+m+2 INTRs 1981a6a5580cSJeff Kirsher * (the second to last INTR is used for WQ/RQ errors) 1982a6a5580cSJeff Kirsher * (the last INTR is used for notifications) 1983a6a5580cSJeff Kirsher */ 1984a6a5580cSJeff Kirsher 1985a6a5580cSJeff Kirsher BUG_ON(ARRAY_SIZE(enic->msix_entry) < n + m + 2); 1986a6a5580cSJeff Kirsher for (i = 0; i < n + m + 2; i++) 1987a6a5580cSJeff Kirsher enic->msix_entry[i].entry = i; 1988a6a5580cSJeff Kirsher 1989a6a5580cSJeff Kirsher /* Use multiple RQs if RSS is enabled 1990a6a5580cSJeff Kirsher */ 1991a6a5580cSJeff Kirsher 1992a6a5580cSJeff Kirsher if (ENIC_SETTING(enic, RSS) && 1993a6a5580cSJeff Kirsher enic->config.intr_mode < 1 && 1994a6a5580cSJeff Kirsher enic->rq_count >= n && 1995a6a5580cSJeff Kirsher enic->wq_count >= m && 1996a6a5580cSJeff Kirsher enic->cq_count >= n + m && 1997a6a5580cSJeff Kirsher enic->intr_count >= n + m + 2) { 1998a6a5580cSJeff Kirsher 1999a6a5580cSJeff Kirsher if (!pci_enable_msix(enic->pdev, enic->msix_entry, n + m + 2)) { 2000a6a5580cSJeff Kirsher 2001a6a5580cSJeff Kirsher enic->rq_count = n; 2002a6a5580cSJeff Kirsher enic->wq_count = m; 2003a6a5580cSJeff Kirsher enic->cq_count = n + m; 2004a6a5580cSJeff Kirsher enic->intr_count = n + m + 2; 2005a6a5580cSJeff Kirsher 2006a6a5580cSJeff Kirsher vnic_dev_set_intr_mode(enic->vdev, 2007a6a5580cSJeff Kirsher VNIC_DEV_INTR_MODE_MSIX); 2008a6a5580cSJeff Kirsher 2009a6a5580cSJeff Kirsher return 0; 2010a6a5580cSJeff Kirsher } 2011a6a5580cSJeff Kirsher } 2012a6a5580cSJeff Kirsher 2013a6a5580cSJeff Kirsher if (enic->config.intr_mode < 1 && 2014a6a5580cSJeff Kirsher enic->rq_count >= 1 && 2015a6a5580cSJeff Kirsher enic->wq_count >= m && 2016a6a5580cSJeff Kirsher enic->cq_count >= 1 + m && 2017a6a5580cSJeff Kirsher enic->intr_count >= 1 + m + 2) { 2018a6a5580cSJeff Kirsher if (!pci_enable_msix(enic->pdev, enic->msix_entry, 1 + m + 2)) { 2019a6a5580cSJeff Kirsher 2020a6a5580cSJeff Kirsher enic->rq_count = 1; 2021a6a5580cSJeff Kirsher enic->wq_count = m; 2022a6a5580cSJeff Kirsher enic->cq_count = 1 + m; 2023a6a5580cSJeff Kirsher enic->intr_count = 1 + m + 2; 2024a6a5580cSJeff Kirsher 2025a6a5580cSJeff Kirsher vnic_dev_set_intr_mode(enic->vdev, 2026a6a5580cSJeff Kirsher VNIC_DEV_INTR_MODE_MSIX); 2027a6a5580cSJeff Kirsher 2028a6a5580cSJeff Kirsher return 0; 2029a6a5580cSJeff Kirsher } 2030a6a5580cSJeff Kirsher } 2031a6a5580cSJeff Kirsher 2032a6a5580cSJeff Kirsher /* Next try MSI 2033a6a5580cSJeff Kirsher * 2034a6a5580cSJeff Kirsher * We need 1 RQ, 1 WQ, 2 CQs, and 1 INTR 2035a6a5580cSJeff Kirsher */ 2036a6a5580cSJeff Kirsher 2037a6a5580cSJeff Kirsher if (enic->config.intr_mode < 2 && 2038a6a5580cSJeff Kirsher enic->rq_count >= 1 && 2039a6a5580cSJeff Kirsher enic->wq_count >= 1 && 2040a6a5580cSJeff Kirsher enic->cq_count >= 2 && 2041a6a5580cSJeff Kirsher enic->intr_count >= 1 && 2042a6a5580cSJeff Kirsher !pci_enable_msi(enic->pdev)) { 2043a6a5580cSJeff Kirsher 2044a6a5580cSJeff Kirsher enic->rq_count = 1; 2045a6a5580cSJeff Kirsher enic->wq_count = 1; 2046a6a5580cSJeff Kirsher enic->cq_count = 2; 2047a6a5580cSJeff Kirsher enic->intr_count = 1; 2048a6a5580cSJeff Kirsher 2049a6a5580cSJeff Kirsher vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_MSI); 2050a6a5580cSJeff Kirsher 2051a6a5580cSJeff Kirsher return 0; 2052a6a5580cSJeff Kirsher } 2053a6a5580cSJeff Kirsher 2054a6a5580cSJeff Kirsher /* Next try INTx 2055a6a5580cSJeff Kirsher * 2056a6a5580cSJeff Kirsher * We need 1 RQ, 1 WQ, 2 CQs, and 3 INTRs 2057a6a5580cSJeff Kirsher * (the first INTR is used for WQ/RQ) 2058a6a5580cSJeff Kirsher * (the second INTR is used for WQ/RQ errors) 2059a6a5580cSJeff Kirsher * (the last INTR is used for notifications) 2060a6a5580cSJeff Kirsher */ 2061a6a5580cSJeff Kirsher 2062a6a5580cSJeff Kirsher if (enic->config.intr_mode < 3 && 2063a6a5580cSJeff Kirsher enic->rq_count >= 1 && 2064a6a5580cSJeff Kirsher enic->wq_count >= 1 && 2065a6a5580cSJeff Kirsher enic->cq_count >= 2 && 2066a6a5580cSJeff Kirsher enic->intr_count >= 3) { 2067a6a5580cSJeff Kirsher 2068a6a5580cSJeff Kirsher enic->rq_count = 1; 2069a6a5580cSJeff Kirsher enic->wq_count = 1; 2070a6a5580cSJeff Kirsher enic->cq_count = 2; 2071a6a5580cSJeff Kirsher enic->intr_count = 3; 2072a6a5580cSJeff Kirsher 2073a6a5580cSJeff Kirsher vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_INTX); 2074a6a5580cSJeff Kirsher 2075a6a5580cSJeff Kirsher return 0; 2076a6a5580cSJeff Kirsher } 2077a6a5580cSJeff Kirsher 2078a6a5580cSJeff Kirsher vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_UNKNOWN); 2079a6a5580cSJeff Kirsher 2080a6a5580cSJeff Kirsher return -EINVAL; 2081a6a5580cSJeff Kirsher } 2082a6a5580cSJeff Kirsher 2083a6a5580cSJeff Kirsher static void enic_clear_intr_mode(struct enic *enic) 2084a6a5580cSJeff Kirsher { 2085a6a5580cSJeff Kirsher switch (vnic_dev_get_intr_mode(enic->vdev)) { 2086a6a5580cSJeff Kirsher case VNIC_DEV_INTR_MODE_MSIX: 2087a6a5580cSJeff Kirsher pci_disable_msix(enic->pdev); 2088a6a5580cSJeff Kirsher break; 2089a6a5580cSJeff Kirsher case VNIC_DEV_INTR_MODE_MSI: 2090a6a5580cSJeff Kirsher pci_disable_msi(enic->pdev); 2091a6a5580cSJeff Kirsher break; 2092a6a5580cSJeff Kirsher default: 2093a6a5580cSJeff Kirsher break; 2094a6a5580cSJeff Kirsher } 2095a6a5580cSJeff Kirsher 2096a6a5580cSJeff Kirsher vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_UNKNOWN); 2097a6a5580cSJeff Kirsher } 2098a6a5580cSJeff Kirsher 2099a6a5580cSJeff Kirsher static const struct net_device_ops enic_netdev_dynamic_ops = { 2100a6a5580cSJeff Kirsher .ndo_open = enic_open, 2101a6a5580cSJeff Kirsher .ndo_stop = enic_stop, 2102a6a5580cSJeff Kirsher .ndo_start_xmit = enic_hard_start_xmit, 2103a6a5580cSJeff Kirsher .ndo_get_stats64 = enic_get_stats, 2104a6a5580cSJeff Kirsher .ndo_validate_addr = eth_validate_addr, 2105a6a5580cSJeff Kirsher .ndo_set_rx_mode = enic_set_rx_mode, 2106a6a5580cSJeff Kirsher .ndo_set_multicast_list = enic_set_rx_mode, 2107a6a5580cSJeff Kirsher .ndo_set_mac_address = enic_set_mac_address_dynamic, 2108a6a5580cSJeff Kirsher .ndo_change_mtu = enic_change_mtu, 2109a6a5580cSJeff Kirsher .ndo_vlan_rx_add_vid = enic_vlan_rx_add_vid, 2110a6a5580cSJeff Kirsher .ndo_vlan_rx_kill_vid = enic_vlan_rx_kill_vid, 2111a6a5580cSJeff Kirsher .ndo_tx_timeout = enic_tx_timeout, 2112a6a5580cSJeff Kirsher .ndo_set_vf_port = enic_set_vf_port, 2113a6a5580cSJeff Kirsher .ndo_get_vf_port = enic_get_vf_port, 2114a6a5580cSJeff Kirsher .ndo_set_vf_mac = enic_set_vf_mac, 2115a6a5580cSJeff Kirsher #ifdef CONFIG_NET_POLL_CONTROLLER 2116a6a5580cSJeff Kirsher .ndo_poll_controller = enic_poll_controller, 2117a6a5580cSJeff Kirsher #endif 2118a6a5580cSJeff Kirsher }; 2119a6a5580cSJeff Kirsher 2120a6a5580cSJeff Kirsher static const struct net_device_ops enic_netdev_ops = { 2121a6a5580cSJeff Kirsher .ndo_open = enic_open, 2122a6a5580cSJeff Kirsher .ndo_stop = enic_stop, 2123a6a5580cSJeff Kirsher .ndo_start_xmit = enic_hard_start_xmit, 2124a6a5580cSJeff Kirsher .ndo_get_stats64 = enic_get_stats, 2125a6a5580cSJeff Kirsher .ndo_validate_addr = eth_validate_addr, 2126a6a5580cSJeff Kirsher .ndo_set_mac_address = enic_set_mac_address, 2127a6a5580cSJeff Kirsher .ndo_set_rx_mode = enic_set_rx_mode, 2128a6a5580cSJeff Kirsher .ndo_set_multicast_list = enic_set_rx_mode, 2129a6a5580cSJeff Kirsher .ndo_change_mtu = enic_change_mtu, 2130a6a5580cSJeff Kirsher .ndo_vlan_rx_add_vid = enic_vlan_rx_add_vid, 2131a6a5580cSJeff Kirsher .ndo_vlan_rx_kill_vid = enic_vlan_rx_kill_vid, 2132a6a5580cSJeff Kirsher .ndo_tx_timeout = enic_tx_timeout, 2133a6a5580cSJeff Kirsher #ifdef CONFIG_NET_POLL_CONTROLLER 2134a6a5580cSJeff Kirsher .ndo_poll_controller = enic_poll_controller, 2135a6a5580cSJeff Kirsher #endif 2136a6a5580cSJeff Kirsher }; 2137a6a5580cSJeff Kirsher 2138a6a5580cSJeff Kirsher static void enic_dev_deinit(struct enic *enic) 2139a6a5580cSJeff Kirsher { 2140a6a5580cSJeff Kirsher unsigned int i; 2141a6a5580cSJeff Kirsher 2142a6a5580cSJeff Kirsher for (i = 0; i < enic->rq_count; i++) 2143a6a5580cSJeff Kirsher netif_napi_del(&enic->napi[i]); 2144a6a5580cSJeff Kirsher 2145a6a5580cSJeff Kirsher enic_free_vnic_resources(enic); 2146a6a5580cSJeff Kirsher enic_clear_intr_mode(enic); 2147a6a5580cSJeff Kirsher } 2148a6a5580cSJeff Kirsher 2149a6a5580cSJeff Kirsher static int enic_dev_init(struct enic *enic) 2150a6a5580cSJeff Kirsher { 2151a6a5580cSJeff Kirsher struct device *dev = enic_get_dev(enic); 2152a6a5580cSJeff Kirsher struct net_device *netdev = enic->netdev; 2153a6a5580cSJeff Kirsher unsigned int i; 2154a6a5580cSJeff Kirsher int err; 2155a6a5580cSJeff Kirsher 2156a6a5580cSJeff Kirsher /* Get interrupt coalesce timer info */ 2157a6a5580cSJeff Kirsher err = enic_dev_intr_coal_timer_info(enic); 2158a6a5580cSJeff Kirsher if (err) { 2159a6a5580cSJeff Kirsher dev_warn(dev, "Using default conversion factor for " 2160a6a5580cSJeff Kirsher "interrupt coalesce timer\n"); 2161a6a5580cSJeff Kirsher vnic_dev_intr_coal_timer_info_default(enic->vdev); 2162a6a5580cSJeff Kirsher } 2163a6a5580cSJeff Kirsher 2164a6a5580cSJeff Kirsher /* Get vNIC configuration 2165a6a5580cSJeff Kirsher */ 2166a6a5580cSJeff Kirsher 2167a6a5580cSJeff Kirsher err = enic_get_vnic_config(enic); 2168a6a5580cSJeff Kirsher if (err) { 2169a6a5580cSJeff Kirsher dev_err(dev, "Get vNIC configuration failed, aborting\n"); 2170a6a5580cSJeff Kirsher return err; 2171a6a5580cSJeff Kirsher } 2172a6a5580cSJeff Kirsher 2173a6a5580cSJeff Kirsher /* Get available resource counts 2174a6a5580cSJeff Kirsher */ 2175a6a5580cSJeff Kirsher 2176a6a5580cSJeff Kirsher enic_get_res_counts(enic); 2177a6a5580cSJeff Kirsher 2178a6a5580cSJeff Kirsher /* Set interrupt mode based on resource counts and system 2179a6a5580cSJeff Kirsher * capabilities 2180a6a5580cSJeff Kirsher */ 2181a6a5580cSJeff Kirsher 2182a6a5580cSJeff Kirsher err = enic_set_intr_mode(enic); 2183a6a5580cSJeff Kirsher if (err) { 2184a6a5580cSJeff Kirsher dev_err(dev, "Failed to set intr mode based on resource " 2185a6a5580cSJeff Kirsher "counts and system capabilities, aborting\n"); 2186a6a5580cSJeff Kirsher return err; 2187a6a5580cSJeff Kirsher } 2188a6a5580cSJeff Kirsher 2189a6a5580cSJeff Kirsher /* Allocate and configure vNIC resources 2190a6a5580cSJeff Kirsher */ 2191a6a5580cSJeff Kirsher 2192a6a5580cSJeff Kirsher err = enic_alloc_vnic_resources(enic); 2193a6a5580cSJeff Kirsher if (err) { 2194a6a5580cSJeff Kirsher dev_err(dev, "Failed to alloc vNIC resources, aborting\n"); 2195a6a5580cSJeff Kirsher goto err_out_free_vnic_resources; 2196a6a5580cSJeff Kirsher } 2197a6a5580cSJeff Kirsher 2198a6a5580cSJeff Kirsher enic_init_vnic_resources(enic); 2199a6a5580cSJeff Kirsher 2200a6a5580cSJeff Kirsher err = enic_set_rss_nic_cfg(enic); 2201a6a5580cSJeff Kirsher if (err) { 2202a6a5580cSJeff Kirsher dev_err(dev, "Failed to config nic, aborting\n"); 2203a6a5580cSJeff Kirsher goto err_out_free_vnic_resources; 2204a6a5580cSJeff Kirsher } 2205a6a5580cSJeff Kirsher 2206a6a5580cSJeff Kirsher switch (vnic_dev_get_intr_mode(enic->vdev)) { 2207a6a5580cSJeff Kirsher default: 2208a6a5580cSJeff Kirsher netif_napi_add(netdev, &enic->napi[0], enic_poll, 64); 2209a6a5580cSJeff Kirsher break; 2210a6a5580cSJeff Kirsher case VNIC_DEV_INTR_MODE_MSIX: 2211a6a5580cSJeff Kirsher for (i = 0; i < enic->rq_count; i++) 2212a6a5580cSJeff Kirsher netif_napi_add(netdev, &enic->napi[i], 2213a6a5580cSJeff Kirsher enic_poll_msix, 64); 2214a6a5580cSJeff Kirsher break; 2215a6a5580cSJeff Kirsher } 2216a6a5580cSJeff Kirsher 2217a6a5580cSJeff Kirsher return 0; 2218a6a5580cSJeff Kirsher 2219a6a5580cSJeff Kirsher err_out_free_vnic_resources: 2220a6a5580cSJeff Kirsher enic_clear_intr_mode(enic); 2221a6a5580cSJeff Kirsher enic_free_vnic_resources(enic); 2222a6a5580cSJeff Kirsher 2223a6a5580cSJeff Kirsher return err; 2224a6a5580cSJeff Kirsher } 2225a6a5580cSJeff Kirsher 2226a6a5580cSJeff Kirsher static void enic_iounmap(struct enic *enic) 2227a6a5580cSJeff Kirsher { 2228a6a5580cSJeff Kirsher unsigned int i; 2229a6a5580cSJeff Kirsher 2230a6a5580cSJeff Kirsher for (i = 0; i < ARRAY_SIZE(enic->bar); i++) 2231a6a5580cSJeff Kirsher if (enic->bar[i].vaddr) 2232a6a5580cSJeff Kirsher iounmap(enic->bar[i].vaddr); 2233a6a5580cSJeff Kirsher } 2234a6a5580cSJeff Kirsher 2235a6a5580cSJeff Kirsher static int __devinit enic_probe(struct pci_dev *pdev, 2236a6a5580cSJeff Kirsher const struct pci_device_id *ent) 2237a6a5580cSJeff Kirsher { 2238a6a5580cSJeff Kirsher struct device *dev = &pdev->dev; 2239a6a5580cSJeff Kirsher struct net_device *netdev; 2240a6a5580cSJeff Kirsher struct enic *enic; 2241a6a5580cSJeff Kirsher int using_dac = 0; 2242a6a5580cSJeff Kirsher unsigned int i; 2243a6a5580cSJeff Kirsher int err; 2244a6a5580cSJeff Kirsher 2245a6a5580cSJeff Kirsher /* Allocate net device structure and initialize. Private 2246a6a5580cSJeff Kirsher * instance data is initialized to zero. 2247a6a5580cSJeff Kirsher */ 2248a6a5580cSJeff Kirsher 2249a6a5580cSJeff Kirsher netdev = alloc_etherdev(sizeof(struct enic)); 2250a6a5580cSJeff Kirsher if (!netdev) { 2251a6a5580cSJeff Kirsher pr_err("Etherdev alloc failed, aborting\n"); 2252a6a5580cSJeff Kirsher return -ENOMEM; 2253a6a5580cSJeff Kirsher } 2254a6a5580cSJeff Kirsher 2255a6a5580cSJeff Kirsher pci_set_drvdata(pdev, netdev); 2256a6a5580cSJeff Kirsher 2257a6a5580cSJeff Kirsher SET_NETDEV_DEV(netdev, &pdev->dev); 2258a6a5580cSJeff Kirsher 2259a6a5580cSJeff Kirsher enic = netdev_priv(netdev); 2260a6a5580cSJeff Kirsher enic->netdev = netdev; 2261a6a5580cSJeff Kirsher enic->pdev = pdev; 2262a6a5580cSJeff Kirsher 2263a6a5580cSJeff Kirsher /* Setup PCI resources 2264a6a5580cSJeff Kirsher */ 2265a6a5580cSJeff Kirsher 2266a6a5580cSJeff Kirsher err = pci_enable_device_mem(pdev); 2267a6a5580cSJeff Kirsher if (err) { 2268a6a5580cSJeff Kirsher dev_err(dev, "Cannot enable PCI device, aborting\n"); 2269a6a5580cSJeff Kirsher goto err_out_free_netdev; 2270a6a5580cSJeff Kirsher } 2271a6a5580cSJeff Kirsher 2272a6a5580cSJeff Kirsher err = pci_request_regions(pdev, DRV_NAME); 2273a6a5580cSJeff Kirsher if (err) { 2274a6a5580cSJeff Kirsher dev_err(dev, "Cannot request PCI regions, aborting\n"); 2275a6a5580cSJeff Kirsher goto err_out_disable_device; 2276a6a5580cSJeff Kirsher } 2277a6a5580cSJeff Kirsher 2278a6a5580cSJeff Kirsher pci_set_master(pdev); 2279a6a5580cSJeff Kirsher 2280a6a5580cSJeff Kirsher /* Query PCI controller on system for DMA addressing 2281a6a5580cSJeff Kirsher * limitation for the device. Try 40-bit first, and 2282a6a5580cSJeff Kirsher * fail to 32-bit. 2283a6a5580cSJeff Kirsher */ 2284a6a5580cSJeff Kirsher 2285a6a5580cSJeff Kirsher err = pci_set_dma_mask(pdev, DMA_BIT_MASK(40)); 2286a6a5580cSJeff Kirsher if (err) { 2287a6a5580cSJeff Kirsher err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); 2288a6a5580cSJeff Kirsher if (err) { 2289a6a5580cSJeff Kirsher dev_err(dev, "No usable DMA configuration, aborting\n"); 2290a6a5580cSJeff Kirsher goto err_out_release_regions; 2291a6a5580cSJeff Kirsher } 2292a6a5580cSJeff Kirsher err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); 2293a6a5580cSJeff Kirsher if (err) { 2294a6a5580cSJeff Kirsher dev_err(dev, "Unable to obtain %u-bit DMA " 2295a6a5580cSJeff Kirsher "for consistent allocations, aborting\n", 32); 2296a6a5580cSJeff Kirsher goto err_out_release_regions; 2297a6a5580cSJeff Kirsher } 2298a6a5580cSJeff Kirsher } else { 2299a6a5580cSJeff Kirsher err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(40)); 2300a6a5580cSJeff Kirsher if (err) { 2301a6a5580cSJeff Kirsher dev_err(dev, "Unable to obtain %u-bit DMA " 2302a6a5580cSJeff Kirsher "for consistent allocations, aborting\n", 40); 2303a6a5580cSJeff Kirsher goto err_out_release_regions; 2304a6a5580cSJeff Kirsher } 2305a6a5580cSJeff Kirsher using_dac = 1; 2306a6a5580cSJeff Kirsher } 2307a6a5580cSJeff Kirsher 2308a6a5580cSJeff Kirsher /* Map vNIC resources from BAR0-5 2309a6a5580cSJeff Kirsher */ 2310a6a5580cSJeff Kirsher 2311a6a5580cSJeff Kirsher for (i = 0; i < ARRAY_SIZE(enic->bar); i++) { 2312a6a5580cSJeff Kirsher if (!(pci_resource_flags(pdev, i) & IORESOURCE_MEM)) 2313a6a5580cSJeff Kirsher continue; 2314a6a5580cSJeff Kirsher enic->bar[i].len = pci_resource_len(pdev, i); 2315a6a5580cSJeff Kirsher enic->bar[i].vaddr = pci_iomap(pdev, i, enic->bar[i].len); 2316a6a5580cSJeff Kirsher if (!enic->bar[i].vaddr) { 2317a6a5580cSJeff Kirsher dev_err(dev, "Cannot memory-map BAR %d, aborting\n", i); 2318a6a5580cSJeff Kirsher err = -ENODEV; 2319a6a5580cSJeff Kirsher goto err_out_iounmap; 2320a6a5580cSJeff Kirsher } 2321a6a5580cSJeff Kirsher enic->bar[i].bus_addr = pci_resource_start(pdev, i); 2322a6a5580cSJeff Kirsher } 2323a6a5580cSJeff Kirsher 2324a6a5580cSJeff Kirsher /* Register vNIC device 2325a6a5580cSJeff Kirsher */ 2326a6a5580cSJeff Kirsher 2327a6a5580cSJeff Kirsher enic->vdev = vnic_dev_register(NULL, enic, pdev, enic->bar, 2328a6a5580cSJeff Kirsher ARRAY_SIZE(enic->bar)); 2329a6a5580cSJeff Kirsher if (!enic->vdev) { 2330a6a5580cSJeff Kirsher dev_err(dev, "vNIC registration failed, aborting\n"); 2331a6a5580cSJeff Kirsher err = -ENODEV; 2332a6a5580cSJeff Kirsher goto err_out_iounmap; 2333a6a5580cSJeff Kirsher } 2334a6a5580cSJeff Kirsher 2335a6a5580cSJeff Kirsher /* Issue device open to get device in known state 2336a6a5580cSJeff Kirsher */ 2337a6a5580cSJeff Kirsher 2338a6a5580cSJeff Kirsher err = enic_dev_open(enic); 2339a6a5580cSJeff Kirsher if (err) { 2340a6a5580cSJeff Kirsher dev_err(dev, "vNIC dev open failed, aborting\n"); 2341a6a5580cSJeff Kirsher goto err_out_vnic_unregister; 2342a6a5580cSJeff Kirsher } 2343a6a5580cSJeff Kirsher 2344a6a5580cSJeff Kirsher /* Setup devcmd lock 2345a6a5580cSJeff Kirsher */ 2346a6a5580cSJeff Kirsher 2347a6a5580cSJeff Kirsher spin_lock_init(&enic->devcmd_lock); 2348a6a5580cSJeff Kirsher 2349a6a5580cSJeff Kirsher /* 2350a6a5580cSJeff Kirsher * Set ingress vlan rewrite mode before vnic initialization 2351a6a5580cSJeff Kirsher */ 2352a6a5580cSJeff Kirsher 2353a6a5580cSJeff Kirsher err = enic_dev_set_ig_vlan_rewrite_mode(enic); 2354a6a5580cSJeff Kirsher if (err) { 2355a6a5580cSJeff Kirsher dev_err(dev, 2356a6a5580cSJeff Kirsher "Failed to set ingress vlan rewrite mode, aborting.\n"); 2357a6a5580cSJeff Kirsher goto err_out_dev_close; 2358a6a5580cSJeff Kirsher } 2359a6a5580cSJeff Kirsher 2360a6a5580cSJeff Kirsher /* Issue device init to initialize the vnic-to-switch link. 2361a6a5580cSJeff Kirsher * We'll start with carrier off and wait for link UP 2362a6a5580cSJeff Kirsher * notification later to turn on carrier. We don't need 2363a6a5580cSJeff Kirsher * to wait here for the vnic-to-switch link initialization 2364a6a5580cSJeff Kirsher * to complete; link UP notification is the indication that 2365a6a5580cSJeff Kirsher * the process is complete. 2366a6a5580cSJeff Kirsher */ 2367a6a5580cSJeff Kirsher 2368a6a5580cSJeff Kirsher netif_carrier_off(netdev); 2369a6a5580cSJeff Kirsher 2370a6a5580cSJeff Kirsher /* Do not call dev_init for a dynamic vnic. 2371a6a5580cSJeff Kirsher * For a dynamic vnic, init_prov_info will be 2372a6a5580cSJeff Kirsher * called later by an upper layer. 2373a6a5580cSJeff Kirsher */ 2374a6a5580cSJeff Kirsher 2375a6a5580cSJeff Kirsher if (!enic_is_dynamic(enic)) { 2376a6a5580cSJeff Kirsher err = vnic_dev_init(enic->vdev, 0); 2377a6a5580cSJeff Kirsher if (err) { 2378a6a5580cSJeff Kirsher dev_err(dev, "vNIC dev init failed, aborting\n"); 2379a6a5580cSJeff Kirsher goto err_out_dev_close; 2380a6a5580cSJeff Kirsher } 2381a6a5580cSJeff Kirsher } 2382a6a5580cSJeff Kirsher 2383a6a5580cSJeff Kirsher err = enic_dev_init(enic); 2384a6a5580cSJeff Kirsher if (err) { 2385a6a5580cSJeff Kirsher dev_err(dev, "Device initialization failed, aborting\n"); 2386a6a5580cSJeff Kirsher goto err_out_dev_close; 2387a6a5580cSJeff Kirsher } 2388a6a5580cSJeff Kirsher 2389a6a5580cSJeff Kirsher /* Setup notification timer, HW reset task, and wq locks 2390a6a5580cSJeff Kirsher */ 2391a6a5580cSJeff Kirsher 2392a6a5580cSJeff Kirsher init_timer(&enic->notify_timer); 2393a6a5580cSJeff Kirsher enic->notify_timer.function = enic_notify_timer; 2394a6a5580cSJeff Kirsher enic->notify_timer.data = (unsigned long)enic; 2395a6a5580cSJeff Kirsher 2396a6a5580cSJeff Kirsher INIT_WORK(&enic->reset, enic_reset); 2397a6a5580cSJeff Kirsher INIT_WORK(&enic->change_mtu_work, enic_change_mtu_work); 2398a6a5580cSJeff Kirsher 2399a6a5580cSJeff Kirsher for (i = 0; i < enic->wq_count; i++) 2400a6a5580cSJeff Kirsher spin_lock_init(&enic->wq_lock[i]); 2401a6a5580cSJeff Kirsher 2402a6a5580cSJeff Kirsher /* Register net device 2403a6a5580cSJeff Kirsher */ 2404a6a5580cSJeff Kirsher 2405a6a5580cSJeff Kirsher enic->port_mtu = enic->config.mtu; 2406a6a5580cSJeff Kirsher (void)enic_change_mtu(netdev, enic->port_mtu); 2407a6a5580cSJeff Kirsher 2408a6a5580cSJeff Kirsher err = enic_set_mac_addr(netdev, enic->mac_addr); 2409a6a5580cSJeff Kirsher if (err) { 2410a6a5580cSJeff Kirsher dev_err(dev, "Invalid MAC address, aborting\n"); 2411a6a5580cSJeff Kirsher goto err_out_dev_deinit; 2412a6a5580cSJeff Kirsher } 2413a6a5580cSJeff Kirsher 2414a6a5580cSJeff Kirsher enic->tx_coalesce_usecs = enic->config.intr_timer_usec; 2415a6a5580cSJeff Kirsher enic->rx_coalesce_usecs = enic->tx_coalesce_usecs; 2416a6a5580cSJeff Kirsher 2417a6a5580cSJeff Kirsher if (enic_is_dynamic(enic)) 2418a6a5580cSJeff Kirsher netdev->netdev_ops = &enic_netdev_dynamic_ops; 2419a6a5580cSJeff Kirsher else 2420a6a5580cSJeff Kirsher netdev->netdev_ops = &enic_netdev_ops; 2421a6a5580cSJeff Kirsher 2422a6a5580cSJeff Kirsher netdev->watchdog_timeo = 2 * HZ; 2423a6a5580cSJeff Kirsher netdev->ethtool_ops = &enic_ethtool_ops; 2424a6a5580cSJeff Kirsher 2425a6a5580cSJeff Kirsher netdev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; 2426a6a5580cSJeff Kirsher if (ENIC_SETTING(enic, LOOP)) { 2427a6a5580cSJeff Kirsher netdev->features &= ~NETIF_F_HW_VLAN_TX; 2428a6a5580cSJeff Kirsher enic->loop_enable = 1; 2429a6a5580cSJeff Kirsher enic->loop_tag = enic->config.loop_tag; 2430a6a5580cSJeff Kirsher dev_info(dev, "loopback tag=0x%04x\n", enic->loop_tag); 2431a6a5580cSJeff Kirsher } 2432a6a5580cSJeff Kirsher if (ENIC_SETTING(enic, TXCSUM)) 2433a6a5580cSJeff Kirsher netdev->hw_features |= NETIF_F_SG | NETIF_F_HW_CSUM; 2434a6a5580cSJeff Kirsher if (ENIC_SETTING(enic, TSO)) 2435a6a5580cSJeff Kirsher netdev->hw_features |= NETIF_F_TSO | 2436a6a5580cSJeff Kirsher NETIF_F_TSO6 | NETIF_F_TSO_ECN; 2437a6a5580cSJeff Kirsher if (ENIC_SETTING(enic, RXCSUM)) 2438a6a5580cSJeff Kirsher netdev->hw_features |= NETIF_F_RXCSUM; 2439a6a5580cSJeff Kirsher 2440a6a5580cSJeff Kirsher netdev->features |= netdev->hw_features; 2441a6a5580cSJeff Kirsher 2442a6a5580cSJeff Kirsher if (using_dac) 2443a6a5580cSJeff Kirsher netdev->features |= NETIF_F_HIGHDMA; 2444a6a5580cSJeff Kirsher 2445a6a5580cSJeff Kirsher err = register_netdev(netdev); 2446a6a5580cSJeff Kirsher if (err) { 2447a6a5580cSJeff Kirsher dev_err(dev, "Cannot register net device, aborting\n"); 2448a6a5580cSJeff Kirsher goto err_out_dev_deinit; 2449a6a5580cSJeff Kirsher } 2450a6a5580cSJeff Kirsher 2451a6a5580cSJeff Kirsher return 0; 2452a6a5580cSJeff Kirsher 2453a6a5580cSJeff Kirsher err_out_dev_deinit: 2454a6a5580cSJeff Kirsher enic_dev_deinit(enic); 2455a6a5580cSJeff Kirsher err_out_dev_close: 2456a6a5580cSJeff Kirsher vnic_dev_close(enic->vdev); 2457a6a5580cSJeff Kirsher err_out_vnic_unregister: 2458a6a5580cSJeff Kirsher vnic_dev_unregister(enic->vdev); 2459a6a5580cSJeff Kirsher err_out_iounmap: 2460a6a5580cSJeff Kirsher enic_iounmap(enic); 2461a6a5580cSJeff Kirsher err_out_release_regions: 2462a6a5580cSJeff Kirsher pci_release_regions(pdev); 2463a6a5580cSJeff Kirsher err_out_disable_device: 2464a6a5580cSJeff Kirsher pci_disable_device(pdev); 2465a6a5580cSJeff Kirsher err_out_free_netdev: 2466a6a5580cSJeff Kirsher pci_set_drvdata(pdev, NULL); 2467a6a5580cSJeff Kirsher free_netdev(netdev); 2468a6a5580cSJeff Kirsher 2469a6a5580cSJeff Kirsher return err; 2470a6a5580cSJeff Kirsher } 2471a6a5580cSJeff Kirsher 2472a6a5580cSJeff Kirsher static void __devexit enic_remove(struct pci_dev *pdev) 2473a6a5580cSJeff Kirsher { 2474a6a5580cSJeff Kirsher struct net_device *netdev = pci_get_drvdata(pdev); 2475a6a5580cSJeff Kirsher 2476a6a5580cSJeff Kirsher if (netdev) { 2477a6a5580cSJeff Kirsher struct enic *enic = netdev_priv(netdev); 2478a6a5580cSJeff Kirsher 2479a6a5580cSJeff Kirsher cancel_work_sync(&enic->reset); 2480a6a5580cSJeff Kirsher cancel_work_sync(&enic->change_mtu_work); 2481a6a5580cSJeff Kirsher unregister_netdev(netdev); 2482a6a5580cSJeff Kirsher enic_dev_deinit(enic); 2483a6a5580cSJeff Kirsher vnic_dev_close(enic->vdev); 2484a6a5580cSJeff Kirsher vnic_dev_unregister(enic->vdev); 2485a6a5580cSJeff Kirsher enic_iounmap(enic); 2486a6a5580cSJeff Kirsher pci_release_regions(pdev); 2487a6a5580cSJeff Kirsher pci_disable_device(pdev); 2488a6a5580cSJeff Kirsher pci_set_drvdata(pdev, NULL); 2489a6a5580cSJeff Kirsher free_netdev(netdev); 2490a6a5580cSJeff Kirsher } 2491a6a5580cSJeff Kirsher } 2492a6a5580cSJeff Kirsher 2493a6a5580cSJeff Kirsher static struct pci_driver enic_driver = { 2494a6a5580cSJeff Kirsher .name = DRV_NAME, 2495a6a5580cSJeff Kirsher .id_table = enic_id_table, 2496a6a5580cSJeff Kirsher .probe = enic_probe, 2497a6a5580cSJeff Kirsher .remove = __devexit_p(enic_remove), 2498a6a5580cSJeff Kirsher }; 2499a6a5580cSJeff Kirsher 2500a6a5580cSJeff Kirsher static int __init enic_init_module(void) 2501a6a5580cSJeff Kirsher { 2502a6a5580cSJeff Kirsher pr_info("%s, ver %s\n", DRV_DESCRIPTION, DRV_VERSION); 2503a6a5580cSJeff Kirsher 2504a6a5580cSJeff Kirsher return pci_register_driver(&enic_driver); 2505a6a5580cSJeff Kirsher } 2506a6a5580cSJeff Kirsher 2507a6a5580cSJeff Kirsher static void __exit enic_cleanup_module(void) 2508a6a5580cSJeff Kirsher { 2509a6a5580cSJeff Kirsher pci_unregister_driver(&enic_driver); 2510a6a5580cSJeff Kirsher } 2511a6a5580cSJeff Kirsher 2512a6a5580cSJeff Kirsher module_init(enic_init_module); 2513a6a5580cSJeff Kirsher module_exit(enic_cleanup_module); 2514