1aa43c215SJeff Kirsher /* 2aa43c215SJeff Kirsher * QLogic qlcnic NIC Driver 3aa43c215SJeff Kirsher * Copyright (c) 2009-2010 QLogic Corporation 4aa43c215SJeff Kirsher * 5aa43c215SJeff Kirsher * See LICENSE.qlcnic for copyright and licensing details. 6aa43c215SJeff Kirsher */ 7aa43c215SJeff Kirsher 8aa43c215SJeff Kirsher #include <linux/slab.h> 9aa43c215SJeff Kirsher #include <linux/vmalloc.h> 10aa43c215SJeff Kirsher #include <linux/interrupt.h> 11aa43c215SJeff Kirsher 12aa43c215SJeff Kirsher #include "qlcnic.h" 13aa43c215SJeff Kirsher 14aa43c215SJeff Kirsher #include <linux/swab.h> 15aa43c215SJeff Kirsher #include <linux/dma-mapping.h> 16aa43c215SJeff Kirsher #include <net/ip.h> 17aa43c215SJeff Kirsher #include <linux/ipv6.h> 18aa43c215SJeff Kirsher #include <linux/inetdevice.h> 19aa43c215SJeff Kirsher #include <linux/sysfs.h> 20aa43c215SJeff Kirsher #include <linux/aer.h> 21aa43c215SJeff Kirsher #include <linux/log2.h> 22aa43c215SJeff Kirsher 23aa43c215SJeff Kirsher MODULE_DESCRIPTION("QLogic 1/10 GbE Converged/Intelligent Ethernet Driver"); 24aa43c215SJeff Kirsher MODULE_LICENSE("GPL"); 25aa43c215SJeff Kirsher MODULE_VERSION(QLCNIC_LINUX_VERSIONID); 26aa43c215SJeff Kirsher MODULE_FIRMWARE(QLCNIC_UNIFIED_ROMIMAGE_NAME); 27aa43c215SJeff Kirsher 28aa43c215SJeff Kirsher char qlcnic_driver_name[] = "qlcnic"; 29aa43c215SJeff Kirsher static const char qlcnic_driver_string[] = "QLogic 1/10 GbE " 30aa43c215SJeff Kirsher "Converged/Intelligent Ethernet Driver v" QLCNIC_LINUX_VERSIONID; 31aa43c215SJeff Kirsher 32aa43c215SJeff Kirsher static struct workqueue_struct *qlcnic_wq; 33aa43c215SJeff Kirsher static int qlcnic_mac_learn; 34aa43c215SJeff Kirsher module_param(qlcnic_mac_learn, int, 0444); 35aa43c215SJeff Kirsher MODULE_PARM_DESC(qlcnic_mac_learn, "Mac Filter (0=disabled, 1=enabled)"); 36aa43c215SJeff Kirsher 37aa43c215SJeff Kirsher static int use_msi = 1; 38aa43c215SJeff Kirsher module_param(use_msi, int, 0444); 39aa43c215SJeff Kirsher MODULE_PARM_DESC(use_msi, "MSI interrupt (0=disabled, 1=enabled"); 40aa43c215SJeff Kirsher 41aa43c215SJeff Kirsher static int use_msi_x = 1; 42aa43c215SJeff Kirsher module_param(use_msi_x, int, 0444); 43aa43c215SJeff Kirsher MODULE_PARM_DESC(use_msi_x, "MSI-X interrupt (0=disabled, 1=enabled"); 44aa43c215SJeff Kirsher 45aa43c215SJeff Kirsher static int auto_fw_reset = 1; 46aa43c215SJeff Kirsher module_param(auto_fw_reset, int, 0644); 47aa43c215SJeff Kirsher MODULE_PARM_DESC(auto_fw_reset, "Auto firmware reset (0=disabled, 1=enabled"); 48aa43c215SJeff Kirsher 49aa43c215SJeff Kirsher static int load_fw_file; 50aa43c215SJeff Kirsher module_param(load_fw_file, int, 0444); 51aa43c215SJeff Kirsher MODULE_PARM_DESC(load_fw_file, "Load firmware from (0=flash, 1=file"); 52aa43c215SJeff Kirsher 53aa43c215SJeff Kirsher static int qlcnic_config_npars; 54aa43c215SJeff Kirsher module_param(qlcnic_config_npars, int, 0444); 55aa43c215SJeff Kirsher MODULE_PARM_DESC(qlcnic_config_npars, "Configure NPARs (0=disabled, 1=enabled"); 56aa43c215SJeff Kirsher 57aa43c215SJeff Kirsher static int __devinit qlcnic_probe(struct pci_dev *pdev, 58aa43c215SJeff Kirsher const struct pci_device_id *ent); 59aa43c215SJeff Kirsher static void __devexit qlcnic_remove(struct pci_dev *pdev); 60aa43c215SJeff Kirsher static int qlcnic_open(struct net_device *netdev); 61aa43c215SJeff Kirsher static int qlcnic_close(struct net_device *netdev); 62aa43c215SJeff Kirsher static void qlcnic_tx_timeout(struct net_device *netdev); 63aa43c215SJeff Kirsher static void qlcnic_attach_work(struct work_struct *work); 64aa43c215SJeff Kirsher static void qlcnic_fwinit_work(struct work_struct *work); 65aa43c215SJeff Kirsher static void qlcnic_fw_poll_work(struct work_struct *work); 66aa43c215SJeff Kirsher static void qlcnic_schedule_work(struct qlcnic_adapter *adapter, 67aa43c215SJeff Kirsher work_func_t func, int delay); 68aa43c215SJeff Kirsher static void qlcnic_cancel_fw_work(struct qlcnic_adapter *adapter); 69aa43c215SJeff Kirsher static int qlcnic_poll(struct napi_struct *napi, int budget); 70aa43c215SJeff Kirsher static int qlcnic_rx_poll(struct napi_struct *napi, int budget); 71aa43c215SJeff Kirsher #ifdef CONFIG_NET_POLL_CONTROLLER 72aa43c215SJeff Kirsher static void qlcnic_poll_controller(struct net_device *netdev); 73aa43c215SJeff Kirsher #endif 74aa43c215SJeff Kirsher 75aa43c215SJeff Kirsher static void qlcnic_create_sysfs_entries(struct qlcnic_adapter *adapter); 76aa43c215SJeff Kirsher static void qlcnic_remove_sysfs_entries(struct qlcnic_adapter *adapter); 77aa43c215SJeff Kirsher static void qlcnic_create_diag_entries(struct qlcnic_adapter *adapter); 78aa43c215SJeff Kirsher static void qlcnic_remove_diag_entries(struct qlcnic_adapter *adapter); 79aa43c215SJeff Kirsher 80aa43c215SJeff Kirsher static void qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding); 81aa43c215SJeff Kirsher static void qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8); 82aa43c215SJeff Kirsher static int qlcnic_can_start_firmware(struct qlcnic_adapter *adapter); 83aa43c215SJeff Kirsher 84aa43c215SJeff Kirsher static irqreturn_t qlcnic_tmp_intr(int irq, void *data); 85aa43c215SJeff Kirsher static irqreturn_t qlcnic_intr(int irq, void *data); 86aa43c215SJeff Kirsher static irqreturn_t qlcnic_msi_intr(int irq, void *data); 87aa43c215SJeff Kirsher static irqreturn_t qlcnic_msix_intr(int irq, void *data); 88aa43c215SJeff Kirsher 89aa43c215SJeff Kirsher static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev); 90aa43c215SJeff Kirsher static void qlcnic_restore_indev_addr(struct net_device *dev, unsigned long); 91aa43c215SJeff Kirsher static int qlcnic_start_firmware(struct qlcnic_adapter *); 92aa43c215SJeff Kirsher 93aa43c215SJeff Kirsher static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter); 94aa43c215SJeff Kirsher static void qlcnic_dev_set_npar_ready(struct qlcnic_adapter *); 95aa43c215SJeff Kirsher static int qlcnicvf_config_led(struct qlcnic_adapter *, u32, u32); 96aa43c215SJeff Kirsher static int qlcnicvf_config_bridged_mode(struct qlcnic_adapter *, u32); 97aa43c215SJeff Kirsher static int qlcnicvf_start_firmware(struct qlcnic_adapter *); 98aa43c215SJeff Kirsher static void qlcnic_set_netdev_features(struct qlcnic_adapter *, 99aa43c215SJeff Kirsher struct qlcnic_esw_func_cfg *); 100aa43c215SJeff Kirsher static void qlcnic_vlan_rx_add(struct net_device *, u16); 101aa43c215SJeff Kirsher static void qlcnic_vlan_rx_del(struct net_device *, u16); 102aa43c215SJeff Kirsher 103aa43c215SJeff Kirsher /* PCI Device ID Table */ 104aa43c215SJeff Kirsher #define ENTRY(device) \ 105aa43c215SJeff Kirsher {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, (device)), \ 106aa43c215SJeff Kirsher .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0} 107aa43c215SJeff Kirsher 108aa43c215SJeff Kirsher #define PCI_DEVICE_ID_QLOGIC_QLE824X 0x8020 109aa43c215SJeff Kirsher 110aa43c215SJeff Kirsher static DEFINE_PCI_DEVICE_TABLE(qlcnic_pci_tbl) = { 111aa43c215SJeff Kirsher ENTRY(PCI_DEVICE_ID_QLOGIC_QLE824X), 112aa43c215SJeff Kirsher {0,} 113aa43c215SJeff Kirsher }; 114aa43c215SJeff Kirsher 115aa43c215SJeff Kirsher MODULE_DEVICE_TABLE(pci, qlcnic_pci_tbl); 116aa43c215SJeff Kirsher 117aa43c215SJeff Kirsher 118aa43c215SJeff Kirsher inline void 119aa43c215SJeff Kirsher qlcnic_update_cmd_producer(struct qlcnic_adapter *adapter, 120aa43c215SJeff Kirsher struct qlcnic_host_tx_ring *tx_ring) 121aa43c215SJeff Kirsher { 122aa43c215SJeff Kirsher writel(tx_ring->producer, tx_ring->crb_cmd_producer); 123aa43c215SJeff Kirsher } 124aa43c215SJeff Kirsher 125aa43c215SJeff Kirsher static const u32 msi_tgt_status[8] = { 126aa43c215SJeff Kirsher ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1, 127aa43c215SJeff Kirsher ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3, 128aa43c215SJeff Kirsher ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5, 129aa43c215SJeff Kirsher ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7 130aa43c215SJeff Kirsher }; 131aa43c215SJeff Kirsher 132aa43c215SJeff Kirsher static const 133aa43c215SJeff Kirsher struct qlcnic_legacy_intr_set legacy_intr[] = QLCNIC_LEGACY_INTR_CONFIG; 134aa43c215SJeff Kirsher 135aa43c215SJeff Kirsher static inline void qlcnic_disable_int(struct qlcnic_host_sds_ring *sds_ring) 136aa43c215SJeff Kirsher { 137aa43c215SJeff Kirsher writel(0, sds_ring->crb_intr_mask); 138aa43c215SJeff Kirsher } 139aa43c215SJeff Kirsher 140aa43c215SJeff Kirsher static inline void qlcnic_enable_int(struct qlcnic_host_sds_ring *sds_ring) 141aa43c215SJeff Kirsher { 142aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = sds_ring->adapter; 143aa43c215SJeff Kirsher 144aa43c215SJeff Kirsher writel(0x1, sds_ring->crb_intr_mask); 145aa43c215SJeff Kirsher 146aa43c215SJeff Kirsher if (!QLCNIC_IS_MSI_FAMILY(adapter)) 147aa43c215SJeff Kirsher writel(0xfbff, adapter->tgt_mask_reg); 148aa43c215SJeff Kirsher } 149aa43c215SJeff Kirsher 150aa43c215SJeff Kirsher static int 151aa43c215SJeff Kirsher qlcnic_alloc_sds_rings(struct qlcnic_recv_context *recv_ctx, int count) 152aa43c215SJeff Kirsher { 153aa43c215SJeff Kirsher int size = sizeof(struct qlcnic_host_sds_ring) * count; 154aa43c215SJeff Kirsher 155aa43c215SJeff Kirsher recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL); 156aa43c215SJeff Kirsher 157aa43c215SJeff Kirsher return recv_ctx->sds_rings == NULL; 158aa43c215SJeff Kirsher } 159aa43c215SJeff Kirsher 160aa43c215SJeff Kirsher static void 161aa43c215SJeff Kirsher qlcnic_free_sds_rings(struct qlcnic_recv_context *recv_ctx) 162aa43c215SJeff Kirsher { 163aa43c215SJeff Kirsher if (recv_ctx->sds_rings != NULL) 164aa43c215SJeff Kirsher kfree(recv_ctx->sds_rings); 165aa43c215SJeff Kirsher 166aa43c215SJeff Kirsher recv_ctx->sds_rings = NULL; 167aa43c215SJeff Kirsher } 168aa43c215SJeff Kirsher 169aa43c215SJeff Kirsher static int 170aa43c215SJeff Kirsher qlcnic_napi_add(struct qlcnic_adapter *adapter, struct net_device *netdev) 171aa43c215SJeff Kirsher { 172aa43c215SJeff Kirsher int ring; 173aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring; 174aa43c215SJeff Kirsher struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; 175aa43c215SJeff Kirsher 176aa43c215SJeff Kirsher if (qlcnic_alloc_sds_rings(recv_ctx, adapter->max_sds_rings)) 177aa43c215SJeff Kirsher return -ENOMEM; 178aa43c215SJeff Kirsher 179aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_sds_rings; ring++) { 180aa43c215SJeff Kirsher sds_ring = &recv_ctx->sds_rings[ring]; 181aa43c215SJeff Kirsher 182aa43c215SJeff Kirsher if (ring == adapter->max_sds_rings - 1) 183aa43c215SJeff Kirsher netif_napi_add(netdev, &sds_ring->napi, qlcnic_poll, 184aa43c215SJeff Kirsher QLCNIC_NETDEV_WEIGHT/adapter->max_sds_rings); 185aa43c215SJeff Kirsher else 186aa43c215SJeff Kirsher netif_napi_add(netdev, &sds_ring->napi, 187aa43c215SJeff Kirsher qlcnic_rx_poll, QLCNIC_NETDEV_WEIGHT*2); 188aa43c215SJeff Kirsher } 189aa43c215SJeff Kirsher 190aa43c215SJeff Kirsher return 0; 191aa43c215SJeff Kirsher } 192aa43c215SJeff Kirsher 193aa43c215SJeff Kirsher static void 194aa43c215SJeff Kirsher qlcnic_napi_del(struct qlcnic_adapter *adapter) 195aa43c215SJeff Kirsher { 196aa43c215SJeff Kirsher int ring; 197aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring; 198aa43c215SJeff Kirsher struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; 199aa43c215SJeff Kirsher 200aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_sds_rings; ring++) { 201aa43c215SJeff Kirsher sds_ring = &recv_ctx->sds_rings[ring]; 202aa43c215SJeff Kirsher netif_napi_del(&sds_ring->napi); 203aa43c215SJeff Kirsher } 204aa43c215SJeff Kirsher 205aa43c215SJeff Kirsher qlcnic_free_sds_rings(adapter->recv_ctx); 206aa43c215SJeff Kirsher } 207aa43c215SJeff Kirsher 208aa43c215SJeff Kirsher static void 209aa43c215SJeff Kirsher qlcnic_napi_enable(struct qlcnic_adapter *adapter) 210aa43c215SJeff Kirsher { 211aa43c215SJeff Kirsher int ring; 212aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring; 213aa43c215SJeff Kirsher struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; 214aa43c215SJeff Kirsher 215aa43c215SJeff Kirsher if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) 216aa43c215SJeff Kirsher return; 217aa43c215SJeff Kirsher 218aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_sds_rings; ring++) { 219aa43c215SJeff Kirsher sds_ring = &recv_ctx->sds_rings[ring]; 220aa43c215SJeff Kirsher napi_enable(&sds_ring->napi); 221aa43c215SJeff Kirsher qlcnic_enable_int(sds_ring); 222aa43c215SJeff Kirsher } 223aa43c215SJeff Kirsher } 224aa43c215SJeff Kirsher 225aa43c215SJeff Kirsher static void 226aa43c215SJeff Kirsher qlcnic_napi_disable(struct qlcnic_adapter *adapter) 227aa43c215SJeff Kirsher { 228aa43c215SJeff Kirsher int ring; 229aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring; 230aa43c215SJeff Kirsher struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; 231aa43c215SJeff Kirsher 232aa43c215SJeff Kirsher if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) 233aa43c215SJeff Kirsher return; 234aa43c215SJeff Kirsher 235aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_sds_rings; ring++) { 236aa43c215SJeff Kirsher sds_ring = &recv_ctx->sds_rings[ring]; 237aa43c215SJeff Kirsher qlcnic_disable_int(sds_ring); 238aa43c215SJeff Kirsher napi_synchronize(&sds_ring->napi); 239aa43c215SJeff Kirsher napi_disable(&sds_ring->napi); 240aa43c215SJeff Kirsher } 241aa43c215SJeff Kirsher } 242aa43c215SJeff Kirsher 243aa43c215SJeff Kirsher static void qlcnic_clear_stats(struct qlcnic_adapter *adapter) 244aa43c215SJeff Kirsher { 245aa43c215SJeff Kirsher memset(&adapter->stats, 0, sizeof(adapter->stats)); 246aa43c215SJeff Kirsher } 247aa43c215SJeff Kirsher 248aa43c215SJeff Kirsher static void qlcnic_set_msix_bit(struct pci_dev *pdev, int enable) 249aa43c215SJeff Kirsher { 250aa43c215SJeff Kirsher u32 control; 251aa43c215SJeff Kirsher int pos; 252aa43c215SJeff Kirsher 253aa43c215SJeff Kirsher pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX); 254aa43c215SJeff Kirsher if (pos) { 255aa43c215SJeff Kirsher pci_read_config_dword(pdev, pos, &control); 256aa43c215SJeff Kirsher if (enable) 257aa43c215SJeff Kirsher control |= PCI_MSIX_FLAGS_ENABLE; 258aa43c215SJeff Kirsher else 259aa43c215SJeff Kirsher control = 0; 260aa43c215SJeff Kirsher pci_write_config_dword(pdev, pos, control); 261aa43c215SJeff Kirsher } 262aa43c215SJeff Kirsher } 263aa43c215SJeff Kirsher 264aa43c215SJeff Kirsher static void qlcnic_init_msix_entries(struct qlcnic_adapter *adapter, int count) 265aa43c215SJeff Kirsher { 266aa43c215SJeff Kirsher int i; 267aa43c215SJeff Kirsher 268aa43c215SJeff Kirsher for (i = 0; i < count; i++) 269aa43c215SJeff Kirsher adapter->msix_entries[i].entry = i; 270aa43c215SJeff Kirsher } 271aa43c215SJeff Kirsher 272aa43c215SJeff Kirsher static int 273aa43c215SJeff Kirsher qlcnic_read_mac_addr(struct qlcnic_adapter *adapter) 274aa43c215SJeff Kirsher { 275aa43c215SJeff Kirsher u8 mac_addr[ETH_ALEN]; 276aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 277aa43c215SJeff Kirsher struct pci_dev *pdev = adapter->pdev; 278aa43c215SJeff Kirsher 279aa43c215SJeff Kirsher if (qlcnic_get_mac_address(adapter, mac_addr) != 0) 280aa43c215SJeff Kirsher return -EIO; 281aa43c215SJeff Kirsher 282aa43c215SJeff Kirsher memcpy(netdev->dev_addr, mac_addr, ETH_ALEN); 283aa43c215SJeff Kirsher memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len); 284aa43c215SJeff Kirsher memcpy(adapter->mac_addr, netdev->dev_addr, netdev->addr_len); 285aa43c215SJeff Kirsher 286aa43c215SJeff Kirsher /* set station address */ 287aa43c215SJeff Kirsher 288aa43c215SJeff Kirsher if (!is_valid_ether_addr(netdev->perm_addr)) 289aa43c215SJeff Kirsher dev_warn(&pdev->dev, "Bad MAC address %pM.\n", 290aa43c215SJeff Kirsher netdev->dev_addr); 291aa43c215SJeff Kirsher 292aa43c215SJeff Kirsher return 0; 293aa43c215SJeff Kirsher } 294aa43c215SJeff Kirsher 295aa43c215SJeff Kirsher static int qlcnic_set_mac(struct net_device *netdev, void *p) 296aa43c215SJeff Kirsher { 297aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 298aa43c215SJeff Kirsher struct sockaddr *addr = p; 299aa43c215SJeff Kirsher 300aa43c215SJeff Kirsher if ((adapter->flags & QLCNIC_MAC_OVERRIDE_DISABLED)) 301aa43c215SJeff Kirsher return -EOPNOTSUPP; 302aa43c215SJeff Kirsher 303aa43c215SJeff Kirsher if (!is_valid_ether_addr(addr->sa_data)) 304aa43c215SJeff Kirsher return -EINVAL; 305aa43c215SJeff Kirsher 306aa43c215SJeff Kirsher if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) { 307aa43c215SJeff Kirsher netif_device_detach(netdev); 308aa43c215SJeff Kirsher qlcnic_napi_disable(adapter); 309aa43c215SJeff Kirsher } 310aa43c215SJeff Kirsher 311aa43c215SJeff Kirsher memcpy(adapter->mac_addr, addr->sa_data, netdev->addr_len); 312aa43c215SJeff Kirsher memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); 313aa43c215SJeff Kirsher qlcnic_set_multi(adapter->netdev); 314aa43c215SJeff Kirsher 315aa43c215SJeff Kirsher if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) { 316aa43c215SJeff Kirsher netif_device_attach(netdev); 317aa43c215SJeff Kirsher qlcnic_napi_enable(adapter); 318aa43c215SJeff Kirsher } 319aa43c215SJeff Kirsher return 0; 320aa43c215SJeff Kirsher } 321aa43c215SJeff Kirsher 322aa43c215SJeff Kirsher static const struct net_device_ops qlcnic_netdev_ops = { 323aa43c215SJeff Kirsher .ndo_open = qlcnic_open, 324aa43c215SJeff Kirsher .ndo_stop = qlcnic_close, 325aa43c215SJeff Kirsher .ndo_start_xmit = qlcnic_xmit_frame, 326aa43c215SJeff Kirsher .ndo_get_stats = qlcnic_get_stats, 327aa43c215SJeff Kirsher .ndo_validate_addr = eth_validate_addr, 328afc4b13dSJiri Pirko .ndo_set_rx_mode = qlcnic_set_multi, 329aa43c215SJeff Kirsher .ndo_set_mac_address = qlcnic_set_mac, 330aa43c215SJeff Kirsher .ndo_change_mtu = qlcnic_change_mtu, 331aa43c215SJeff Kirsher .ndo_fix_features = qlcnic_fix_features, 332aa43c215SJeff Kirsher .ndo_set_features = qlcnic_set_features, 333aa43c215SJeff Kirsher .ndo_tx_timeout = qlcnic_tx_timeout, 334aa43c215SJeff Kirsher .ndo_vlan_rx_add_vid = qlcnic_vlan_rx_add, 335aa43c215SJeff Kirsher .ndo_vlan_rx_kill_vid = qlcnic_vlan_rx_del, 336aa43c215SJeff Kirsher #ifdef CONFIG_NET_POLL_CONTROLLER 337aa43c215SJeff Kirsher .ndo_poll_controller = qlcnic_poll_controller, 338aa43c215SJeff Kirsher #endif 339aa43c215SJeff Kirsher }; 340aa43c215SJeff Kirsher 341aa43c215SJeff Kirsher static struct qlcnic_nic_template qlcnic_ops = { 342aa43c215SJeff Kirsher .config_bridged_mode = qlcnic_config_bridged_mode, 343aa43c215SJeff Kirsher .config_led = qlcnic_config_led, 344aa43c215SJeff Kirsher .start_firmware = qlcnic_start_firmware 345aa43c215SJeff Kirsher }; 346aa43c215SJeff Kirsher 347aa43c215SJeff Kirsher static struct qlcnic_nic_template qlcnic_vf_ops = { 348aa43c215SJeff Kirsher .config_bridged_mode = qlcnicvf_config_bridged_mode, 349aa43c215SJeff Kirsher .config_led = qlcnicvf_config_led, 350aa43c215SJeff Kirsher .start_firmware = qlcnicvf_start_firmware 351aa43c215SJeff Kirsher }; 352aa43c215SJeff Kirsher 353aa43c215SJeff Kirsher static int qlcnic_enable_msix(struct qlcnic_adapter *adapter, u32 num_msix) 354aa43c215SJeff Kirsher { 355aa43c215SJeff Kirsher struct pci_dev *pdev = adapter->pdev; 356aa43c215SJeff Kirsher int err = -1; 357aa43c215SJeff Kirsher 358aa43c215SJeff Kirsher adapter->max_sds_rings = 1; 359aa43c215SJeff Kirsher adapter->flags &= ~(QLCNIC_MSI_ENABLED | QLCNIC_MSIX_ENABLED); 360aa43c215SJeff Kirsher qlcnic_set_msix_bit(pdev, 0); 361aa43c215SJeff Kirsher 362aa43c215SJeff Kirsher if (adapter->msix_supported) { 363aa43c215SJeff Kirsher enable_msix: 364aa43c215SJeff Kirsher qlcnic_init_msix_entries(adapter, num_msix); 365aa43c215SJeff Kirsher err = pci_enable_msix(pdev, adapter->msix_entries, num_msix); 366aa43c215SJeff Kirsher if (err == 0) { 367aa43c215SJeff Kirsher adapter->flags |= QLCNIC_MSIX_ENABLED; 368aa43c215SJeff Kirsher qlcnic_set_msix_bit(pdev, 1); 369aa43c215SJeff Kirsher 370aa43c215SJeff Kirsher adapter->max_sds_rings = num_msix; 371aa43c215SJeff Kirsher 372aa43c215SJeff Kirsher dev_info(&pdev->dev, "using msi-x interrupts\n"); 373aa43c215SJeff Kirsher return err; 374aa43c215SJeff Kirsher } 375aa43c215SJeff Kirsher if (err > 0) { 376aa43c215SJeff Kirsher num_msix = rounddown_pow_of_two(err); 377aa43c215SJeff Kirsher if (num_msix) 378aa43c215SJeff Kirsher goto enable_msix; 379aa43c215SJeff Kirsher } 380aa43c215SJeff Kirsher } 381aa43c215SJeff Kirsher return err; 382aa43c215SJeff Kirsher } 383aa43c215SJeff Kirsher 384aa43c215SJeff Kirsher 385aa43c215SJeff Kirsher static void qlcnic_enable_msi_legacy(struct qlcnic_adapter *adapter) 386aa43c215SJeff Kirsher { 387aa43c215SJeff Kirsher const struct qlcnic_legacy_intr_set *legacy_intrp; 388aa43c215SJeff Kirsher struct pci_dev *pdev = adapter->pdev; 389aa43c215SJeff Kirsher 390aa43c215SJeff Kirsher if (use_msi && !pci_enable_msi(pdev)) { 391aa43c215SJeff Kirsher adapter->flags |= QLCNIC_MSI_ENABLED; 392aa43c215SJeff Kirsher adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter, 393aa43c215SJeff Kirsher msi_tgt_status[adapter->ahw->pci_func]); 394aa43c215SJeff Kirsher dev_info(&pdev->dev, "using msi interrupts\n"); 395aa43c215SJeff Kirsher adapter->msix_entries[0].vector = pdev->irq; 396aa43c215SJeff Kirsher return; 397aa43c215SJeff Kirsher } 398aa43c215SJeff Kirsher 399aa43c215SJeff Kirsher legacy_intrp = &legacy_intr[adapter->ahw->pci_func]; 400aa43c215SJeff Kirsher 401aa43c215SJeff Kirsher adapter->int_vec_bit = legacy_intrp->int_vec_bit; 402aa43c215SJeff Kirsher adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter, 403aa43c215SJeff Kirsher legacy_intrp->tgt_status_reg); 404aa43c215SJeff Kirsher adapter->tgt_mask_reg = qlcnic_get_ioaddr(adapter, 405aa43c215SJeff Kirsher legacy_intrp->tgt_mask_reg); 406aa43c215SJeff Kirsher adapter->isr_int_vec = qlcnic_get_ioaddr(adapter, ISR_INT_VECTOR); 407aa43c215SJeff Kirsher 408aa43c215SJeff Kirsher adapter->crb_int_state_reg = qlcnic_get_ioaddr(adapter, 409aa43c215SJeff Kirsher ISR_INT_STATE_REG); 410aa43c215SJeff Kirsher dev_info(&pdev->dev, "using legacy interrupts\n"); 411aa43c215SJeff Kirsher adapter->msix_entries[0].vector = pdev->irq; 412aa43c215SJeff Kirsher } 413aa43c215SJeff Kirsher 414aa43c215SJeff Kirsher static void 415aa43c215SJeff Kirsher qlcnic_setup_intr(struct qlcnic_adapter *adapter) 416aa43c215SJeff Kirsher { 417aa43c215SJeff Kirsher int num_msix; 418aa43c215SJeff Kirsher 419aa43c215SJeff Kirsher if (adapter->msix_supported) { 420aa43c215SJeff Kirsher num_msix = rounddown_pow_of_two(min_t(int, num_online_cpus(), 421aa43c215SJeff Kirsher QLCNIC_DEF_NUM_STS_DESC_RINGS)); 422aa43c215SJeff Kirsher } else 423aa43c215SJeff Kirsher num_msix = 1; 424aa43c215SJeff Kirsher 425aa43c215SJeff Kirsher if (!qlcnic_enable_msix(adapter, num_msix)) 426aa43c215SJeff Kirsher return; 427aa43c215SJeff Kirsher 428aa43c215SJeff Kirsher qlcnic_enable_msi_legacy(adapter); 429aa43c215SJeff Kirsher } 430aa43c215SJeff Kirsher 431aa43c215SJeff Kirsher static void 432aa43c215SJeff Kirsher qlcnic_teardown_intr(struct qlcnic_adapter *adapter) 433aa43c215SJeff Kirsher { 434aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_MSIX_ENABLED) 435aa43c215SJeff Kirsher pci_disable_msix(adapter->pdev); 436aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_MSI_ENABLED) 437aa43c215SJeff Kirsher pci_disable_msi(adapter->pdev); 438aa43c215SJeff Kirsher } 439aa43c215SJeff Kirsher 440aa43c215SJeff Kirsher static void 441aa43c215SJeff Kirsher qlcnic_cleanup_pci_map(struct qlcnic_adapter *adapter) 442aa43c215SJeff Kirsher { 443aa43c215SJeff Kirsher if (adapter->ahw->pci_base0 != NULL) 444aa43c215SJeff Kirsher iounmap(adapter->ahw->pci_base0); 445aa43c215SJeff Kirsher } 446aa43c215SJeff Kirsher 447aa43c215SJeff Kirsher static int 448aa43c215SJeff Kirsher qlcnic_init_pci_info(struct qlcnic_adapter *adapter) 449aa43c215SJeff Kirsher { 450aa43c215SJeff Kirsher struct qlcnic_pci_info *pci_info; 451aa43c215SJeff Kirsher int i, ret = 0; 452aa43c215SJeff Kirsher u8 pfn; 453aa43c215SJeff Kirsher 454aa43c215SJeff Kirsher pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL); 455aa43c215SJeff Kirsher if (!pci_info) 456aa43c215SJeff Kirsher return -ENOMEM; 457aa43c215SJeff Kirsher 458aa43c215SJeff Kirsher adapter->npars = kzalloc(sizeof(struct qlcnic_npar_info) * 459aa43c215SJeff Kirsher QLCNIC_MAX_PCI_FUNC, GFP_KERNEL); 460aa43c215SJeff Kirsher if (!adapter->npars) { 461aa43c215SJeff Kirsher ret = -ENOMEM; 462aa43c215SJeff Kirsher goto err_pci_info; 463aa43c215SJeff Kirsher } 464aa43c215SJeff Kirsher 465aa43c215SJeff Kirsher adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) * 466aa43c215SJeff Kirsher QLCNIC_NIU_MAX_XG_PORTS, GFP_KERNEL); 467aa43c215SJeff Kirsher if (!adapter->eswitch) { 468aa43c215SJeff Kirsher ret = -ENOMEM; 469aa43c215SJeff Kirsher goto err_npars; 470aa43c215SJeff Kirsher } 471aa43c215SJeff Kirsher 472aa43c215SJeff Kirsher ret = qlcnic_get_pci_info(adapter, pci_info); 473aa43c215SJeff Kirsher if (ret) 474aa43c215SJeff Kirsher goto err_eswitch; 475aa43c215SJeff Kirsher 476aa43c215SJeff Kirsher for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { 477aa43c215SJeff Kirsher pfn = pci_info[i].id; 478aa43c215SJeff Kirsher if (pfn > QLCNIC_MAX_PCI_FUNC) { 479aa43c215SJeff Kirsher ret = QL_STATUS_INVALID_PARAM; 480aa43c215SJeff Kirsher goto err_eswitch; 481aa43c215SJeff Kirsher } 482aa43c215SJeff Kirsher adapter->npars[pfn].active = (u8)pci_info[i].active; 483aa43c215SJeff Kirsher adapter->npars[pfn].type = (u8)pci_info[i].type; 484aa43c215SJeff Kirsher adapter->npars[pfn].phy_port = (u8)pci_info[i].default_port; 485aa43c215SJeff Kirsher adapter->npars[pfn].min_bw = pci_info[i].tx_min_bw; 486aa43c215SJeff Kirsher adapter->npars[pfn].max_bw = pci_info[i].tx_max_bw; 487aa43c215SJeff Kirsher } 488aa43c215SJeff Kirsher 489aa43c215SJeff Kirsher for (i = 0; i < QLCNIC_NIU_MAX_XG_PORTS; i++) 490aa43c215SJeff Kirsher adapter->eswitch[i].flags |= QLCNIC_SWITCH_ENABLE; 491aa43c215SJeff Kirsher 492aa43c215SJeff Kirsher kfree(pci_info); 493aa43c215SJeff Kirsher return 0; 494aa43c215SJeff Kirsher 495aa43c215SJeff Kirsher err_eswitch: 496aa43c215SJeff Kirsher kfree(adapter->eswitch); 497aa43c215SJeff Kirsher adapter->eswitch = NULL; 498aa43c215SJeff Kirsher err_npars: 499aa43c215SJeff Kirsher kfree(adapter->npars); 500aa43c215SJeff Kirsher adapter->npars = NULL; 501aa43c215SJeff Kirsher err_pci_info: 502aa43c215SJeff Kirsher kfree(pci_info); 503aa43c215SJeff Kirsher 504aa43c215SJeff Kirsher return ret; 505aa43c215SJeff Kirsher } 506aa43c215SJeff Kirsher 507aa43c215SJeff Kirsher static int 508aa43c215SJeff Kirsher qlcnic_set_function_modes(struct qlcnic_adapter *adapter) 509aa43c215SJeff Kirsher { 510aa43c215SJeff Kirsher u8 id; 511aa43c215SJeff Kirsher u32 ref_count; 512aa43c215SJeff Kirsher int i, ret = 1; 513aa43c215SJeff Kirsher u32 data = QLCNIC_MGMT_FUNC; 514aa43c215SJeff Kirsher void __iomem *priv_op = adapter->ahw->pci_base0 + QLCNIC_DRV_OP_MODE; 515aa43c215SJeff Kirsher 516aa43c215SJeff Kirsher /* If other drivers are not in use set their privilege level */ 517aa43c215SJeff Kirsher ref_count = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE); 518aa43c215SJeff Kirsher ret = qlcnic_api_lock(adapter); 519aa43c215SJeff Kirsher if (ret) 520aa43c215SJeff Kirsher goto err_lock; 521aa43c215SJeff Kirsher 522aa43c215SJeff Kirsher if (qlcnic_config_npars) { 523aa43c215SJeff Kirsher for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { 524aa43c215SJeff Kirsher id = i; 525aa43c215SJeff Kirsher if (adapter->npars[i].type != QLCNIC_TYPE_NIC || 526aa43c215SJeff Kirsher id == adapter->ahw->pci_func) 527aa43c215SJeff Kirsher continue; 528aa43c215SJeff Kirsher data |= (qlcnic_config_npars & 529aa43c215SJeff Kirsher QLC_DEV_SET_DRV(0xf, id)); 530aa43c215SJeff Kirsher } 531aa43c215SJeff Kirsher } else { 532aa43c215SJeff Kirsher data = readl(priv_op); 533aa43c215SJeff Kirsher data = (data & ~QLC_DEV_SET_DRV(0xf, adapter->ahw->pci_func)) | 534aa43c215SJeff Kirsher (QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC, 535aa43c215SJeff Kirsher adapter->ahw->pci_func)); 536aa43c215SJeff Kirsher } 537aa43c215SJeff Kirsher writel(data, priv_op); 538aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 539aa43c215SJeff Kirsher err_lock: 540aa43c215SJeff Kirsher return ret; 541aa43c215SJeff Kirsher } 542aa43c215SJeff Kirsher 543aa43c215SJeff Kirsher static void 544aa43c215SJeff Kirsher qlcnic_check_vf(struct qlcnic_adapter *adapter) 545aa43c215SJeff Kirsher { 546aa43c215SJeff Kirsher void __iomem *msix_base_addr; 547aa43c215SJeff Kirsher void __iomem *priv_op; 548aa43c215SJeff Kirsher u32 func; 549aa43c215SJeff Kirsher u32 msix_base; 550aa43c215SJeff Kirsher u32 op_mode, priv_level; 551aa43c215SJeff Kirsher 552aa43c215SJeff Kirsher /* Determine FW API version */ 553aa43c215SJeff Kirsher adapter->fw_hal_version = readl(adapter->ahw->pci_base0 + 554aa43c215SJeff Kirsher QLCNIC_FW_API); 555aa43c215SJeff Kirsher 556aa43c215SJeff Kirsher /* Find PCI function number */ 557aa43c215SJeff Kirsher pci_read_config_dword(adapter->pdev, QLCNIC_MSIX_TABLE_OFFSET, &func); 558aa43c215SJeff Kirsher msix_base_addr = adapter->ahw->pci_base0 + QLCNIC_MSIX_BASE; 559aa43c215SJeff Kirsher msix_base = readl(msix_base_addr); 560aa43c215SJeff Kirsher func = (func - msix_base)/QLCNIC_MSIX_TBL_PGSIZE; 561aa43c215SJeff Kirsher adapter->ahw->pci_func = func; 562aa43c215SJeff Kirsher 563aa43c215SJeff Kirsher /* Determine function privilege level */ 564aa43c215SJeff Kirsher priv_op = adapter->ahw->pci_base0 + QLCNIC_DRV_OP_MODE; 565aa43c215SJeff Kirsher op_mode = readl(priv_op); 566aa43c215SJeff Kirsher if (op_mode == QLC_DEV_DRV_DEFAULT) 567aa43c215SJeff Kirsher priv_level = QLCNIC_MGMT_FUNC; 568aa43c215SJeff Kirsher else 569aa43c215SJeff Kirsher priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func); 570aa43c215SJeff Kirsher 571aa43c215SJeff Kirsher if (priv_level == QLCNIC_NON_PRIV_FUNC) { 572aa43c215SJeff Kirsher adapter->op_mode = QLCNIC_NON_PRIV_FUNC; 573aa43c215SJeff Kirsher dev_info(&adapter->pdev->dev, 574aa43c215SJeff Kirsher "HAL Version: %d Non Privileged function\n", 575aa43c215SJeff Kirsher adapter->fw_hal_version); 576aa43c215SJeff Kirsher adapter->nic_ops = &qlcnic_vf_ops; 577aa43c215SJeff Kirsher } else 578aa43c215SJeff Kirsher adapter->nic_ops = &qlcnic_ops; 579aa43c215SJeff Kirsher } 580aa43c215SJeff Kirsher 581aa43c215SJeff Kirsher static int 582aa43c215SJeff Kirsher qlcnic_setup_pci_map(struct qlcnic_adapter *adapter) 583aa43c215SJeff Kirsher { 584aa43c215SJeff Kirsher void __iomem *mem_ptr0 = NULL; 585aa43c215SJeff Kirsher resource_size_t mem_base; 586aa43c215SJeff Kirsher unsigned long mem_len, pci_len0 = 0; 587aa43c215SJeff Kirsher 588aa43c215SJeff Kirsher struct pci_dev *pdev = adapter->pdev; 589aa43c215SJeff Kirsher 590aa43c215SJeff Kirsher /* remap phys address */ 591aa43c215SJeff Kirsher mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */ 592aa43c215SJeff Kirsher mem_len = pci_resource_len(pdev, 0); 593aa43c215SJeff Kirsher 594aa43c215SJeff Kirsher if (mem_len == QLCNIC_PCI_2MB_SIZE) { 595aa43c215SJeff Kirsher 596aa43c215SJeff Kirsher mem_ptr0 = pci_ioremap_bar(pdev, 0); 597aa43c215SJeff Kirsher if (mem_ptr0 == NULL) { 598aa43c215SJeff Kirsher dev_err(&pdev->dev, "failed to map PCI bar 0\n"); 599aa43c215SJeff Kirsher return -EIO; 600aa43c215SJeff Kirsher } 601aa43c215SJeff Kirsher pci_len0 = mem_len; 602aa43c215SJeff Kirsher } else { 603aa43c215SJeff Kirsher return -EIO; 604aa43c215SJeff Kirsher } 605aa43c215SJeff Kirsher 606aa43c215SJeff Kirsher dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20)); 607aa43c215SJeff Kirsher 608aa43c215SJeff Kirsher adapter->ahw->pci_base0 = mem_ptr0; 609aa43c215SJeff Kirsher adapter->ahw->pci_len0 = pci_len0; 610aa43c215SJeff Kirsher 611aa43c215SJeff Kirsher qlcnic_check_vf(adapter); 612aa43c215SJeff Kirsher 613aa43c215SJeff Kirsher adapter->ahw->ocm_win_crb = qlcnic_get_ioaddr(adapter, 614aa43c215SJeff Kirsher QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG( 615aa43c215SJeff Kirsher adapter->ahw->pci_func))); 616aa43c215SJeff Kirsher 617aa43c215SJeff Kirsher return 0; 618aa43c215SJeff Kirsher } 619aa43c215SJeff Kirsher 620aa43c215SJeff Kirsher static void get_brd_name(struct qlcnic_adapter *adapter, char *name) 621aa43c215SJeff Kirsher { 622aa43c215SJeff Kirsher struct pci_dev *pdev = adapter->pdev; 623aa43c215SJeff Kirsher int i, found = 0; 624aa43c215SJeff Kirsher 625aa43c215SJeff Kirsher for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) { 626aa43c215SJeff Kirsher if (qlcnic_boards[i].vendor == pdev->vendor && 627aa43c215SJeff Kirsher qlcnic_boards[i].device == pdev->device && 628aa43c215SJeff Kirsher qlcnic_boards[i].sub_vendor == pdev->subsystem_vendor && 629aa43c215SJeff Kirsher qlcnic_boards[i].sub_device == pdev->subsystem_device) { 630aa43c215SJeff Kirsher sprintf(name, "%pM: %s" , 631aa43c215SJeff Kirsher adapter->mac_addr, 632aa43c215SJeff Kirsher qlcnic_boards[i].short_name); 633aa43c215SJeff Kirsher found = 1; 634aa43c215SJeff Kirsher break; 635aa43c215SJeff Kirsher } 636aa43c215SJeff Kirsher 637aa43c215SJeff Kirsher } 638aa43c215SJeff Kirsher 639aa43c215SJeff Kirsher if (!found) 640aa43c215SJeff Kirsher sprintf(name, "%pM Gigabit Ethernet", adapter->mac_addr); 641aa43c215SJeff Kirsher } 642aa43c215SJeff Kirsher 643aa43c215SJeff Kirsher static void 644aa43c215SJeff Kirsher qlcnic_check_options(struct qlcnic_adapter *adapter) 645aa43c215SJeff Kirsher { 646aa43c215SJeff Kirsher u32 fw_major, fw_minor, fw_build, prev_fw_version; 647aa43c215SJeff Kirsher struct pci_dev *pdev = adapter->pdev; 648aa43c215SJeff Kirsher struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump; 649aa43c215SJeff Kirsher 650aa43c215SJeff Kirsher prev_fw_version = adapter->fw_version; 651aa43c215SJeff Kirsher 652aa43c215SJeff Kirsher fw_major = QLCRD32(adapter, QLCNIC_FW_VERSION_MAJOR); 653aa43c215SJeff Kirsher fw_minor = QLCRD32(adapter, QLCNIC_FW_VERSION_MINOR); 654aa43c215SJeff Kirsher fw_build = QLCRD32(adapter, QLCNIC_FW_VERSION_SUB); 655aa43c215SJeff Kirsher 656aa43c215SJeff Kirsher adapter->fw_version = QLCNIC_VERSION_CODE(fw_major, fw_minor, fw_build); 657aa43c215SJeff Kirsher 658aa43c215SJeff Kirsher if (adapter->op_mode != QLCNIC_NON_PRIV_FUNC) { 659aa43c215SJeff Kirsher if (fw_dump->tmpl_hdr == NULL || 660aa43c215SJeff Kirsher adapter->fw_version > prev_fw_version) { 661aa43c215SJeff Kirsher if (fw_dump->tmpl_hdr) 662aa43c215SJeff Kirsher vfree(fw_dump->tmpl_hdr); 663aa43c215SJeff Kirsher if (!qlcnic_fw_cmd_get_minidump_temp(adapter)) 664aa43c215SJeff Kirsher dev_info(&pdev->dev, 665aa43c215SJeff Kirsher "Supports FW dump capability\n"); 666aa43c215SJeff Kirsher } 667aa43c215SJeff Kirsher } 668aa43c215SJeff Kirsher 669aa43c215SJeff Kirsher dev_info(&pdev->dev, "firmware v%d.%d.%d\n", 670aa43c215SJeff Kirsher fw_major, fw_minor, fw_build); 671aa43c215SJeff Kirsher if (adapter->ahw->port_type == QLCNIC_XGBE) { 672aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_ESWITCH_ENABLED) { 673aa43c215SJeff Kirsher adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_VF; 674aa43c215SJeff Kirsher adapter->max_rxd = MAX_RCV_DESCRIPTORS_VF; 675aa43c215SJeff Kirsher } else { 676aa43c215SJeff Kirsher adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G; 677aa43c215SJeff Kirsher adapter->max_rxd = MAX_RCV_DESCRIPTORS_10G; 678aa43c215SJeff Kirsher } 679aa43c215SJeff Kirsher 680aa43c215SJeff Kirsher adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G; 681aa43c215SJeff Kirsher adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G; 682aa43c215SJeff Kirsher 683aa43c215SJeff Kirsher } else if (adapter->ahw->port_type == QLCNIC_GBE) { 684aa43c215SJeff Kirsher adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G; 685aa43c215SJeff Kirsher adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G; 686aa43c215SJeff Kirsher adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G; 687aa43c215SJeff Kirsher adapter->max_rxd = MAX_RCV_DESCRIPTORS_1G; 688aa43c215SJeff Kirsher } 689aa43c215SJeff Kirsher 690aa43c215SJeff Kirsher adapter->msix_supported = !!use_msi_x; 691aa43c215SJeff Kirsher 692aa43c215SJeff Kirsher adapter->num_txd = MAX_CMD_DESCRIPTORS; 693aa43c215SJeff Kirsher 694aa43c215SJeff Kirsher adapter->max_rds_rings = MAX_RDS_RINGS; 695aa43c215SJeff Kirsher } 696aa43c215SJeff Kirsher 697aa43c215SJeff Kirsher static int 698aa43c215SJeff Kirsher qlcnic_initialize_nic(struct qlcnic_adapter *adapter) 699aa43c215SJeff Kirsher { 700aa43c215SJeff Kirsher int err; 701aa43c215SJeff Kirsher struct qlcnic_info nic_info; 702aa43c215SJeff Kirsher 703aa43c215SJeff Kirsher err = qlcnic_get_nic_info(adapter, &nic_info, adapter->ahw->pci_func); 704aa43c215SJeff Kirsher if (err) 705aa43c215SJeff Kirsher return err; 706aa43c215SJeff Kirsher 707aa43c215SJeff Kirsher adapter->physical_port = (u8)nic_info.phys_port; 708aa43c215SJeff Kirsher adapter->switch_mode = nic_info.switch_mode; 709aa43c215SJeff Kirsher adapter->max_tx_ques = nic_info.max_tx_ques; 710aa43c215SJeff Kirsher adapter->max_rx_ques = nic_info.max_rx_ques; 711aa43c215SJeff Kirsher adapter->capabilities = nic_info.capabilities; 712aa43c215SJeff Kirsher adapter->max_mac_filters = nic_info.max_mac_filters; 713aa43c215SJeff Kirsher adapter->max_mtu = nic_info.max_mtu; 714aa43c215SJeff Kirsher 715aa43c215SJeff Kirsher if (adapter->capabilities & BIT_6) 716aa43c215SJeff Kirsher adapter->flags |= QLCNIC_ESWITCH_ENABLED; 717aa43c215SJeff Kirsher else 718aa43c215SJeff Kirsher adapter->flags &= ~QLCNIC_ESWITCH_ENABLED; 719aa43c215SJeff Kirsher 720aa43c215SJeff Kirsher return err; 721aa43c215SJeff Kirsher } 722aa43c215SJeff Kirsher 723aa43c215SJeff Kirsher static void 724aa43c215SJeff Kirsher qlcnic_set_vlan_config(struct qlcnic_adapter *adapter, 725aa43c215SJeff Kirsher struct qlcnic_esw_func_cfg *esw_cfg) 726aa43c215SJeff Kirsher { 727aa43c215SJeff Kirsher if (esw_cfg->discard_tagged) 728aa43c215SJeff Kirsher adapter->flags &= ~QLCNIC_TAGGING_ENABLED; 729aa43c215SJeff Kirsher else 730aa43c215SJeff Kirsher adapter->flags |= QLCNIC_TAGGING_ENABLED; 731aa43c215SJeff Kirsher 732aa43c215SJeff Kirsher if (esw_cfg->vlan_id) 733aa43c215SJeff Kirsher adapter->pvid = esw_cfg->vlan_id; 734aa43c215SJeff Kirsher else 735aa43c215SJeff Kirsher adapter->pvid = 0; 736aa43c215SJeff Kirsher } 737aa43c215SJeff Kirsher 738aa43c215SJeff Kirsher static void 739aa43c215SJeff Kirsher qlcnic_vlan_rx_add(struct net_device *netdev, u16 vid) 740aa43c215SJeff Kirsher { 741aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 742aa43c215SJeff Kirsher set_bit(vid, adapter->vlans); 743aa43c215SJeff Kirsher } 744aa43c215SJeff Kirsher 745aa43c215SJeff Kirsher static void 746aa43c215SJeff Kirsher qlcnic_vlan_rx_del(struct net_device *netdev, u16 vid) 747aa43c215SJeff Kirsher { 748aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 749aa43c215SJeff Kirsher 750aa43c215SJeff Kirsher qlcnic_restore_indev_addr(netdev, NETDEV_DOWN); 751aa43c215SJeff Kirsher clear_bit(vid, adapter->vlans); 752aa43c215SJeff Kirsher } 753aa43c215SJeff Kirsher 754aa43c215SJeff Kirsher static void 755aa43c215SJeff Kirsher qlcnic_set_eswitch_port_features(struct qlcnic_adapter *adapter, 756aa43c215SJeff Kirsher struct qlcnic_esw_func_cfg *esw_cfg) 757aa43c215SJeff Kirsher { 758aa43c215SJeff Kirsher adapter->flags &= ~(QLCNIC_MACSPOOF | QLCNIC_MAC_OVERRIDE_DISABLED | 759aa43c215SJeff Kirsher QLCNIC_PROMISC_DISABLED); 760aa43c215SJeff Kirsher 761aa43c215SJeff Kirsher if (esw_cfg->mac_anti_spoof) 762aa43c215SJeff Kirsher adapter->flags |= QLCNIC_MACSPOOF; 763aa43c215SJeff Kirsher 764aa43c215SJeff Kirsher if (!esw_cfg->mac_override) 765aa43c215SJeff Kirsher adapter->flags |= QLCNIC_MAC_OVERRIDE_DISABLED; 766aa43c215SJeff Kirsher 767aa43c215SJeff Kirsher if (!esw_cfg->promisc_mode) 768aa43c215SJeff Kirsher adapter->flags |= QLCNIC_PROMISC_DISABLED; 769aa43c215SJeff Kirsher 770aa43c215SJeff Kirsher qlcnic_set_netdev_features(adapter, esw_cfg); 771aa43c215SJeff Kirsher } 772aa43c215SJeff Kirsher 773aa43c215SJeff Kirsher static int 774aa43c215SJeff Kirsher qlcnic_set_eswitch_port_config(struct qlcnic_adapter *adapter) 775aa43c215SJeff Kirsher { 776aa43c215SJeff Kirsher struct qlcnic_esw_func_cfg esw_cfg; 777aa43c215SJeff Kirsher 778aa43c215SJeff Kirsher if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) 779aa43c215SJeff Kirsher return 0; 780aa43c215SJeff Kirsher 781aa43c215SJeff Kirsher esw_cfg.pci_func = adapter->ahw->pci_func; 782aa43c215SJeff Kirsher if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg)) 783aa43c215SJeff Kirsher return -EIO; 784aa43c215SJeff Kirsher qlcnic_set_vlan_config(adapter, &esw_cfg); 785aa43c215SJeff Kirsher qlcnic_set_eswitch_port_features(adapter, &esw_cfg); 786aa43c215SJeff Kirsher 787aa43c215SJeff Kirsher return 0; 788aa43c215SJeff Kirsher } 789aa43c215SJeff Kirsher 790aa43c215SJeff Kirsher static void 791aa43c215SJeff Kirsher qlcnic_set_netdev_features(struct qlcnic_adapter *adapter, 792aa43c215SJeff Kirsher struct qlcnic_esw_func_cfg *esw_cfg) 793aa43c215SJeff Kirsher { 794aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 795aa43c215SJeff Kirsher unsigned long features, vlan_features; 796aa43c215SJeff Kirsher 797aa43c215SJeff Kirsher features = (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM | 798aa43c215SJeff Kirsher NETIF_F_IPV6_CSUM | NETIF_F_GRO); 799aa43c215SJeff Kirsher vlan_features = (NETIF_F_SG | NETIF_F_IP_CSUM | 800aa43c215SJeff Kirsher NETIF_F_IPV6_CSUM | NETIF_F_HW_VLAN_FILTER); 801aa43c215SJeff Kirsher 802aa43c215SJeff Kirsher if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO) { 803aa43c215SJeff Kirsher features |= (NETIF_F_TSO | NETIF_F_TSO6); 804aa43c215SJeff Kirsher vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6); 805aa43c215SJeff Kirsher } 806aa43c215SJeff Kirsher 807aa43c215SJeff Kirsher if (netdev->features & NETIF_F_LRO) 808aa43c215SJeff Kirsher features |= NETIF_F_LRO; 809aa43c215SJeff Kirsher 810aa43c215SJeff Kirsher if (esw_cfg->offload_flags & BIT_0) { 811aa43c215SJeff Kirsher netdev->features |= features; 812aa43c215SJeff Kirsher if (!(esw_cfg->offload_flags & BIT_1)) 813aa43c215SJeff Kirsher netdev->features &= ~NETIF_F_TSO; 814aa43c215SJeff Kirsher if (!(esw_cfg->offload_flags & BIT_2)) 815aa43c215SJeff Kirsher netdev->features &= ~NETIF_F_TSO6; 816aa43c215SJeff Kirsher } else { 817aa43c215SJeff Kirsher netdev->features &= ~features; 818aa43c215SJeff Kirsher } 819aa43c215SJeff Kirsher 820aa43c215SJeff Kirsher netdev->vlan_features = (features & vlan_features); 821aa43c215SJeff Kirsher } 822aa43c215SJeff Kirsher 823aa43c215SJeff Kirsher static int 824aa43c215SJeff Kirsher qlcnic_check_eswitch_mode(struct qlcnic_adapter *adapter) 825aa43c215SJeff Kirsher { 826aa43c215SJeff Kirsher void __iomem *priv_op; 827aa43c215SJeff Kirsher u32 op_mode, priv_level; 828aa43c215SJeff Kirsher int err = 0; 829aa43c215SJeff Kirsher 830aa43c215SJeff Kirsher err = qlcnic_initialize_nic(adapter); 831aa43c215SJeff Kirsher if (err) 832aa43c215SJeff Kirsher return err; 833aa43c215SJeff Kirsher 834aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_ADAPTER_INITIALIZED) 835aa43c215SJeff Kirsher return 0; 836aa43c215SJeff Kirsher 837aa43c215SJeff Kirsher priv_op = adapter->ahw->pci_base0 + QLCNIC_DRV_OP_MODE; 838aa43c215SJeff Kirsher op_mode = readl(priv_op); 839aa43c215SJeff Kirsher priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func); 840aa43c215SJeff Kirsher 841aa43c215SJeff Kirsher if (op_mode == QLC_DEV_DRV_DEFAULT) 842aa43c215SJeff Kirsher priv_level = QLCNIC_MGMT_FUNC; 843aa43c215SJeff Kirsher else 844aa43c215SJeff Kirsher priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func); 845aa43c215SJeff Kirsher 846aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_ESWITCH_ENABLED) { 847aa43c215SJeff Kirsher if (priv_level == QLCNIC_MGMT_FUNC) { 848aa43c215SJeff Kirsher adapter->op_mode = QLCNIC_MGMT_FUNC; 849aa43c215SJeff Kirsher err = qlcnic_init_pci_info(adapter); 850aa43c215SJeff Kirsher if (err) 851aa43c215SJeff Kirsher return err; 852aa43c215SJeff Kirsher /* Set privilege level for other functions */ 853aa43c215SJeff Kirsher qlcnic_set_function_modes(adapter); 854aa43c215SJeff Kirsher dev_info(&adapter->pdev->dev, 855aa43c215SJeff Kirsher "HAL Version: %d, Management function\n", 856aa43c215SJeff Kirsher adapter->fw_hal_version); 857aa43c215SJeff Kirsher } else if (priv_level == QLCNIC_PRIV_FUNC) { 858aa43c215SJeff Kirsher adapter->op_mode = QLCNIC_PRIV_FUNC; 859aa43c215SJeff Kirsher dev_info(&adapter->pdev->dev, 860aa43c215SJeff Kirsher "HAL Version: %d, Privileged function\n", 861aa43c215SJeff Kirsher adapter->fw_hal_version); 862aa43c215SJeff Kirsher } 863aa43c215SJeff Kirsher } 864aa43c215SJeff Kirsher 865aa43c215SJeff Kirsher adapter->flags |= QLCNIC_ADAPTER_INITIALIZED; 866aa43c215SJeff Kirsher 867aa43c215SJeff Kirsher return err; 868aa43c215SJeff Kirsher } 869aa43c215SJeff Kirsher 870aa43c215SJeff Kirsher static int 871aa43c215SJeff Kirsher qlcnic_set_default_offload_settings(struct qlcnic_adapter *adapter) 872aa43c215SJeff Kirsher { 873aa43c215SJeff Kirsher struct qlcnic_esw_func_cfg esw_cfg; 874aa43c215SJeff Kirsher struct qlcnic_npar_info *npar; 875aa43c215SJeff Kirsher u8 i; 876aa43c215SJeff Kirsher 877aa43c215SJeff Kirsher if (adapter->need_fw_reset) 878aa43c215SJeff Kirsher return 0; 879aa43c215SJeff Kirsher 880aa43c215SJeff Kirsher for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { 881aa43c215SJeff Kirsher if (adapter->npars[i].type != QLCNIC_TYPE_NIC) 882aa43c215SJeff Kirsher continue; 883aa43c215SJeff Kirsher memset(&esw_cfg, 0, sizeof(struct qlcnic_esw_func_cfg)); 884aa43c215SJeff Kirsher esw_cfg.pci_func = i; 885aa43c215SJeff Kirsher esw_cfg.offload_flags = BIT_0; 886aa43c215SJeff Kirsher esw_cfg.mac_override = BIT_0; 887aa43c215SJeff Kirsher esw_cfg.promisc_mode = BIT_0; 888aa43c215SJeff Kirsher if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO) 889aa43c215SJeff Kirsher esw_cfg.offload_flags |= (BIT_1 | BIT_2); 890aa43c215SJeff Kirsher if (qlcnic_config_switch_port(adapter, &esw_cfg)) 891aa43c215SJeff Kirsher return -EIO; 892aa43c215SJeff Kirsher npar = &adapter->npars[i]; 893aa43c215SJeff Kirsher npar->pvid = esw_cfg.vlan_id; 894aa43c215SJeff Kirsher npar->mac_override = esw_cfg.mac_override; 895aa43c215SJeff Kirsher npar->mac_anti_spoof = esw_cfg.mac_anti_spoof; 896aa43c215SJeff Kirsher npar->discard_tagged = esw_cfg.discard_tagged; 897aa43c215SJeff Kirsher npar->promisc_mode = esw_cfg.promisc_mode; 898aa43c215SJeff Kirsher npar->offload_flags = esw_cfg.offload_flags; 899aa43c215SJeff Kirsher } 900aa43c215SJeff Kirsher 901aa43c215SJeff Kirsher return 0; 902aa43c215SJeff Kirsher } 903aa43c215SJeff Kirsher 904aa43c215SJeff Kirsher static int 905aa43c215SJeff Kirsher qlcnic_reset_eswitch_config(struct qlcnic_adapter *adapter, 906aa43c215SJeff Kirsher struct qlcnic_npar_info *npar, int pci_func) 907aa43c215SJeff Kirsher { 908aa43c215SJeff Kirsher struct qlcnic_esw_func_cfg esw_cfg; 909aa43c215SJeff Kirsher esw_cfg.op_mode = QLCNIC_PORT_DEFAULTS; 910aa43c215SJeff Kirsher esw_cfg.pci_func = pci_func; 911aa43c215SJeff Kirsher esw_cfg.vlan_id = npar->pvid; 912aa43c215SJeff Kirsher esw_cfg.mac_override = npar->mac_override; 913aa43c215SJeff Kirsher esw_cfg.discard_tagged = npar->discard_tagged; 914aa43c215SJeff Kirsher esw_cfg.mac_anti_spoof = npar->mac_anti_spoof; 915aa43c215SJeff Kirsher esw_cfg.offload_flags = npar->offload_flags; 916aa43c215SJeff Kirsher esw_cfg.promisc_mode = npar->promisc_mode; 917aa43c215SJeff Kirsher if (qlcnic_config_switch_port(adapter, &esw_cfg)) 918aa43c215SJeff Kirsher return -EIO; 919aa43c215SJeff Kirsher 920aa43c215SJeff Kirsher esw_cfg.op_mode = QLCNIC_ADD_VLAN; 921aa43c215SJeff Kirsher if (qlcnic_config_switch_port(adapter, &esw_cfg)) 922aa43c215SJeff Kirsher return -EIO; 923aa43c215SJeff Kirsher 924aa43c215SJeff Kirsher return 0; 925aa43c215SJeff Kirsher } 926aa43c215SJeff Kirsher 927aa43c215SJeff Kirsher static int 928aa43c215SJeff Kirsher qlcnic_reset_npar_config(struct qlcnic_adapter *adapter) 929aa43c215SJeff Kirsher { 930aa43c215SJeff Kirsher int i, err; 931aa43c215SJeff Kirsher struct qlcnic_npar_info *npar; 932aa43c215SJeff Kirsher struct qlcnic_info nic_info; 933aa43c215SJeff Kirsher 934aa43c215SJeff Kirsher if (!adapter->need_fw_reset) 935aa43c215SJeff Kirsher return 0; 936aa43c215SJeff Kirsher 937aa43c215SJeff Kirsher /* Set the NPAR config data after FW reset */ 938aa43c215SJeff Kirsher for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { 939aa43c215SJeff Kirsher npar = &adapter->npars[i]; 940aa43c215SJeff Kirsher if (npar->type != QLCNIC_TYPE_NIC) 941aa43c215SJeff Kirsher continue; 942aa43c215SJeff Kirsher err = qlcnic_get_nic_info(adapter, &nic_info, i); 943aa43c215SJeff Kirsher if (err) 944aa43c215SJeff Kirsher return err; 945aa43c215SJeff Kirsher nic_info.min_tx_bw = npar->min_bw; 946aa43c215SJeff Kirsher nic_info.max_tx_bw = npar->max_bw; 947aa43c215SJeff Kirsher err = qlcnic_set_nic_info(adapter, &nic_info); 948aa43c215SJeff Kirsher if (err) 949aa43c215SJeff Kirsher return err; 950aa43c215SJeff Kirsher 951aa43c215SJeff Kirsher if (npar->enable_pm) { 952aa43c215SJeff Kirsher err = qlcnic_config_port_mirroring(adapter, 953aa43c215SJeff Kirsher npar->dest_npar, 1, i); 954aa43c215SJeff Kirsher if (err) 955aa43c215SJeff Kirsher return err; 956aa43c215SJeff Kirsher } 957aa43c215SJeff Kirsher err = qlcnic_reset_eswitch_config(adapter, npar, i); 958aa43c215SJeff Kirsher if (err) 959aa43c215SJeff Kirsher return err; 960aa43c215SJeff Kirsher } 961aa43c215SJeff Kirsher return 0; 962aa43c215SJeff Kirsher } 963aa43c215SJeff Kirsher 964aa43c215SJeff Kirsher static int qlcnic_check_npar_opertional(struct qlcnic_adapter *adapter) 965aa43c215SJeff Kirsher { 966aa43c215SJeff Kirsher u8 npar_opt_timeo = QLCNIC_DEV_NPAR_OPER_TIMEO; 967aa43c215SJeff Kirsher u32 npar_state; 968aa43c215SJeff Kirsher 969aa43c215SJeff Kirsher if (adapter->op_mode == QLCNIC_MGMT_FUNC) 970aa43c215SJeff Kirsher return 0; 971aa43c215SJeff Kirsher 972aa43c215SJeff Kirsher npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE); 973aa43c215SJeff Kirsher while (npar_state != QLCNIC_DEV_NPAR_OPER && --npar_opt_timeo) { 974aa43c215SJeff Kirsher msleep(1000); 975aa43c215SJeff Kirsher npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE); 976aa43c215SJeff Kirsher } 977aa43c215SJeff Kirsher if (!npar_opt_timeo) { 978aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, 979aa43c215SJeff Kirsher "Waiting for NPAR state to opertional timeout\n"); 980aa43c215SJeff Kirsher return -EIO; 981aa43c215SJeff Kirsher } 982aa43c215SJeff Kirsher return 0; 983aa43c215SJeff Kirsher } 984aa43c215SJeff Kirsher 985aa43c215SJeff Kirsher static int 986aa43c215SJeff Kirsher qlcnic_set_mgmt_operations(struct qlcnic_adapter *adapter) 987aa43c215SJeff Kirsher { 988aa43c215SJeff Kirsher int err; 989aa43c215SJeff Kirsher 990aa43c215SJeff Kirsher if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) || 991aa43c215SJeff Kirsher adapter->op_mode != QLCNIC_MGMT_FUNC) 992aa43c215SJeff Kirsher return 0; 993aa43c215SJeff Kirsher 994aa43c215SJeff Kirsher err = qlcnic_set_default_offload_settings(adapter); 995aa43c215SJeff Kirsher if (err) 996aa43c215SJeff Kirsher return err; 997aa43c215SJeff Kirsher 998aa43c215SJeff Kirsher err = qlcnic_reset_npar_config(adapter); 999aa43c215SJeff Kirsher if (err) 1000aa43c215SJeff Kirsher return err; 1001aa43c215SJeff Kirsher 1002aa43c215SJeff Kirsher qlcnic_dev_set_npar_ready(adapter); 1003aa43c215SJeff Kirsher 1004aa43c215SJeff Kirsher return err; 1005aa43c215SJeff Kirsher } 1006aa43c215SJeff Kirsher 1007aa43c215SJeff Kirsher static int 1008aa43c215SJeff Kirsher qlcnic_start_firmware(struct qlcnic_adapter *adapter) 1009aa43c215SJeff Kirsher { 1010aa43c215SJeff Kirsher int err; 1011aa43c215SJeff Kirsher 1012aa43c215SJeff Kirsher err = qlcnic_can_start_firmware(adapter); 1013aa43c215SJeff Kirsher if (err < 0) 1014aa43c215SJeff Kirsher return err; 1015aa43c215SJeff Kirsher else if (!err) 1016aa43c215SJeff Kirsher goto check_fw_status; 1017aa43c215SJeff Kirsher 1018aa43c215SJeff Kirsher if (load_fw_file) 1019aa43c215SJeff Kirsher qlcnic_request_firmware(adapter); 1020aa43c215SJeff Kirsher else { 1021aa43c215SJeff Kirsher err = qlcnic_check_flash_fw_ver(adapter); 1022aa43c215SJeff Kirsher if (err) 1023aa43c215SJeff Kirsher goto err_out; 1024aa43c215SJeff Kirsher 1025aa43c215SJeff Kirsher adapter->fw_type = QLCNIC_FLASH_ROMIMAGE; 1026aa43c215SJeff Kirsher } 1027aa43c215SJeff Kirsher 1028aa43c215SJeff Kirsher err = qlcnic_need_fw_reset(adapter); 1029aa43c215SJeff Kirsher if (err == 0) 1030aa43c215SJeff Kirsher goto check_fw_status; 1031aa43c215SJeff Kirsher 1032aa43c215SJeff Kirsher err = qlcnic_pinit_from_rom(adapter); 1033aa43c215SJeff Kirsher if (err) 1034aa43c215SJeff Kirsher goto err_out; 1035aa43c215SJeff Kirsher 1036aa43c215SJeff Kirsher err = qlcnic_load_firmware(adapter); 1037aa43c215SJeff Kirsher if (err) 1038aa43c215SJeff Kirsher goto err_out; 1039aa43c215SJeff Kirsher 1040aa43c215SJeff Kirsher qlcnic_release_firmware(adapter); 1041aa43c215SJeff Kirsher QLCWR32(adapter, CRB_DRIVER_VERSION, QLCNIC_DRIVER_VERSION); 1042aa43c215SJeff Kirsher 1043aa43c215SJeff Kirsher check_fw_status: 1044aa43c215SJeff Kirsher err = qlcnic_check_fw_status(adapter); 1045aa43c215SJeff Kirsher if (err) 1046aa43c215SJeff Kirsher goto err_out; 1047aa43c215SJeff Kirsher 1048aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_READY); 1049aa43c215SJeff Kirsher qlcnic_idc_debug_info(adapter, 1); 1050aa43c215SJeff Kirsher 1051aa43c215SJeff Kirsher err = qlcnic_check_eswitch_mode(adapter); 1052aa43c215SJeff Kirsher if (err) { 1053aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, 1054aa43c215SJeff Kirsher "Memory allocation failed for eswitch\n"); 1055aa43c215SJeff Kirsher goto err_out; 1056aa43c215SJeff Kirsher } 1057aa43c215SJeff Kirsher err = qlcnic_set_mgmt_operations(adapter); 1058aa43c215SJeff Kirsher if (err) 1059aa43c215SJeff Kirsher goto err_out; 1060aa43c215SJeff Kirsher 1061aa43c215SJeff Kirsher qlcnic_check_options(adapter); 1062aa43c215SJeff Kirsher adapter->need_fw_reset = 0; 1063aa43c215SJeff Kirsher 1064aa43c215SJeff Kirsher qlcnic_release_firmware(adapter); 1065aa43c215SJeff Kirsher return 0; 1066aa43c215SJeff Kirsher 1067aa43c215SJeff Kirsher err_out: 1068aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED); 1069aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, "Device state set to failed\n"); 1070aa43c215SJeff Kirsher 1071aa43c215SJeff Kirsher qlcnic_release_firmware(adapter); 1072aa43c215SJeff Kirsher return err; 1073aa43c215SJeff Kirsher } 1074aa43c215SJeff Kirsher 1075aa43c215SJeff Kirsher static int 1076aa43c215SJeff Kirsher qlcnic_request_irq(struct qlcnic_adapter *adapter) 1077aa43c215SJeff Kirsher { 1078aa43c215SJeff Kirsher irq_handler_t handler; 1079aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring; 1080aa43c215SJeff Kirsher int err, ring; 1081aa43c215SJeff Kirsher 1082aa43c215SJeff Kirsher unsigned long flags = 0; 1083aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 1084aa43c215SJeff Kirsher struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; 1085aa43c215SJeff Kirsher 1086aa43c215SJeff Kirsher if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) { 1087aa43c215SJeff Kirsher handler = qlcnic_tmp_intr; 1088aa43c215SJeff Kirsher if (!QLCNIC_IS_MSI_FAMILY(adapter)) 1089aa43c215SJeff Kirsher flags |= IRQF_SHARED; 1090aa43c215SJeff Kirsher 1091aa43c215SJeff Kirsher } else { 1092aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_MSIX_ENABLED) 1093aa43c215SJeff Kirsher handler = qlcnic_msix_intr; 1094aa43c215SJeff Kirsher else if (adapter->flags & QLCNIC_MSI_ENABLED) 1095aa43c215SJeff Kirsher handler = qlcnic_msi_intr; 1096aa43c215SJeff Kirsher else { 1097aa43c215SJeff Kirsher flags |= IRQF_SHARED; 1098aa43c215SJeff Kirsher handler = qlcnic_intr; 1099aa43c215SJeff Kirsher } 1100aa43c215SJeff Kirsher } 1101aa43c215SJeff Kirsher adapter->irq = netdev->irq; 1102aa43c215SJeff Kirsher 1103aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_sds_rings; ring++) { 1104aa43c215SJeff Kirsher sds_ring = &recv_ctx->sds_rings[ring]; 1105aa43c215SJeff Kirsher sprintf(sds_ring->name, "%s[%d]", netdev->name, ring); 1106aa43c215SJeff Kirsher err = request_irq(sds_ring->irq, handler, 1107aa43c215SJeff Kirsher flags, sds_ring->name, sds_ring); 1108aa43c215SJeff Kirsher if (err) 1109aa43c215SJeff Kirsher return err; 1110aa43c215SJeff Kirsher } 1111aa43c215SJeff Kirsher 1112aa43c215SJeff Kirsher return 0; 1113aa43c215SJeff Kirsher } 1114aa43c215SJeff Kirsher 1115aa43c215SJeff Kirsher static void 1116aa43c215SJeff Kirsher qlcnic_free_irq(struct qlcnic_adapter *adapter) 1117aa43c215SJeff Kirsher { 1118aa43c215SJeff Kirsher int ring; 1119aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring; 1120aa43c215SJeff Kirsher 1121aa43c215SJeff Kirsher struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; 1122aa43c215SJeff Kirsher 1123aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_sds_rings; ring++) { 1124aa43c215SJeff Kirsher sds_ring = &recv_ctx->sds_rings[ring]; 1125aa43c215SJeff Kirsher free_irq(sds_ring->irq, sds_ring); 1126aa43c215SJeff Kirsher } 1127aa43c215SJeff Kirsher } 1128aa43c215SJeff Kirsher 1129aa43c215SJeff Kirsher static int 1130aa43c215SJeff Kirsher __qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev) 1131aa43c215SJeff Kirsher { 1132aa43c215SJeff Kirsher int ring; 1133aa43c215SJeff Kirsher struct qlcnic_host_rds_ring *rds_ring; 1134aa43c215SJeff Kirsher 1135aa43c215SJeff Kirsher if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) 1136aa43c215SJeff Kirsher return -EIO; 1137aa43c215SJeff Kirsher 1138aa43c215SJeff Kirsher if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) 1139aa43c215SJeff Kirsher return 0; 1140aa43c215SJeff Kirsher if (qlcnic_set_eswitch_port_config(adapter)) 1141aa43c215SJeff Kirsher return -EIO; 1142aa43c215SJeff Kirsher 1143aa43c215SJeff Kirsher if (qlcnic_fw_create_ctx(adapter)) 1144aa43c215SJeff Kirsher return -EIO; 1145aa43c215SJeff Kirsher 1146aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_rds_rings; ring++) { 1147aa43c215SJeff Kirsher rds_ring = &adapter->recv_ctx->rds_rings[ring]; 1148aa43c215SJeff Kirsher qlcnic_post_rx_buffers(adapter, rds_ring); 1149aa43c215SJeff Kirsher } 1150aa43c215SJeff Kirsher 1151aa43c215SJeff Kirsher qlcnic_set_multi(netdev); 1152aa43c215SJeff Kirsher qlcnic_fw_cmd_set_mtu(adapter, netdev->mtu); 1153aa43c215SJeff Kirsher 1154aa43c215SJeff Kirsher adapter->ahw->linkup = 0; 1155aa43c215SJeff Kirsher 1156aa43c215SJeff Kirsher if (adapter->max_sds_rings > 1) 1157aa43c215SJeff Kirsher qlcnic_config_rss(adapter, 1); 1158aa43c215SJeff Kirsher 1159aa43c215SJeff Kirsher qlcnic_config_intr_coalesce(adapter); 1160aa43c215SJeff Kirsher 1161aa43c215SJeff Kirsher if (netdev->features & NETIF_F_LRO) 1162aa43c215SJeff Kirsher qlcnic_config_hw_lro(adapter, QLCNIC_LRO_ENABLED); 1163aa43c215SJeff Kirsher 1164aa43c215SJeff Kirsher qlcnic_napi_enable(adapter); 1165aa43c215SJeff Kirsher 1166aa43c215SJeff Kirsher qlcnic_linkevent_request(adapter, 1); 1167aa43c215SJeff Kirsher 1168aa43c215SJeff Kirsher adapter->reset_context = 0; 1169aa43c215SJeff Kirsher set_bit(__QLCNIC_DEV_UP, &adapter->state); 1170aa43c215SJeff Kirsher return 0; 1171aa43c215SJeff Kirsher } 1172aa43c215SJeff Kirsher 1173aa43c215SJeff Kirsher /* Usage: During resume and firmware recovery module.*/ 1174aa43c215SJeff Kirsher 1175aa43c215SJeff Kirsher static int 1176aa43c215SJeff Kirsher qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev) 1177aa43c215SJeff Kirsher { 1178aa43c215SJeff Kirsher int err = 0; 1179aa43c215SJeff Kirsher 1180aa43c215SJeff Kirsher rtnl_lock(); 1181aa43c215SJeff Kirsher if (netif_running(netdev)) 1182aa43c215SJeff Kirsher err = __qlcnic_up(adapter, netdev); 1183aa43c215SJeff Kirsher rtnl_unlock(); 1184aa43c215SJeff Kirsher 1185aa43c215SJeff Kirsher return err; 1186aa43c215SJeff Kirsher } 1187aa43c215SJeff Kirsher 1188aa43c215SJeff Kirsher static void 1189aa43c215SJeff Kirsher __qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev) 1190aa43c215SJeff Kirsher { 1191aa43c215SJeff Kirsher if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) 1192aa43c215SJeff Kirsher return; 1193aa43c215SJeff Kirsher 1194aa43c215SJeff Kirsher if (!test_and_clear_bit(__QLCNIC_DEV_UP, &adapter->state)) 1195aa43c215SJeff Kirsher return; 1196aa43c215SJeff Kirsher 1197aa43c215SJeff Kirsher smp_mb(); 1198aa43c215SJeff Kirsher spin_lock(&adapter->tx_clean_lock); 1199aa43c215SJeff Kirsher netif_carrier_off(netdev); 1200aa43c215SJeff Kirsher netif_tx_disable(netdev); 1201aa43c215SJeff Kirsher 1202aa43c215SJeff Kirsher qlcnic_free_mac_list(adapter); 1203aa43c215SJeff Kirsher 1204aa43c215SJeff Kirsher if (adapter->fhash.fnum) 1205aa43c215SJeff Kirsher qlcnic_delete_lb_filters(adapter); 1206aa43c215SJeff Kirsher 1207aa43c215SJeff Kirsher qlcnic_nic_set_promisc(adapter, QLCNIC_NIU_NON_PROMISC_MODE); 1208aa43c215SJeff Kirsher 1209aa43c215SJeff Kirsher qlcnic_napi_disable(adapter); 1210aa43c215SJeff Kirsher 1211aa43c215SJeff Kirsher qlcnic_fw_destroy_ctx(adapter); 1212aa43c215SJeff Kirsher 1213aa43c215SJeff Kirsher qlcnic_reset_rx_buffers_list(adapter); 1214aa43c215SJeff Kirsher qlcnic_release_tx_buffers(adapter); 1215aa43c215SJeff Kirsher spin_unlock(&adapter->tx_clean_lock); 1216aa43c215SJeff Kirsher } 1217aa43c215SJeff Kirsher 1218aa43c215SJeff Kirsher /* Usage: During suspend and firmware recovery module */ 1219aa43c215SJeff Kirsher 1220aa43c215SJeff Kirsher static void 1221aa43c215SJeff Kirsher qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev) 1222aa43c215SJeff Kirsher { 1223aa43c215SJeff Kirsher rtnl_lock(); 1224aa43c215SJeff Kirsher if (netif_running(netdev)) 1225aa43c215SJeff Kirsher __qlcnic_down(adapter, netdev); 1226aa43c215SJeff Kirsher rtnl_unlock(); 1227aa43c215SJeff Kirsher 1228aa43c215SJeff Kirsher } 1229aa43c215SJeff Kirsher 1230aa43c215SJeff Kirsher static int 1231aa43c215SJeff Kirsher qlcnic_attach(struct qlcnic_adapter *adapter) 1232aa43c215SJeff Kirsher { 1233aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 1234aa43c215SJeff Kirsher struct pci_dev *pdev = adapter->pdev; 1235aa43c215SJeff Kirsher int err; 1236aa43c215SJeff Kirsher 1237aa43c215SJeff Kirsher if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) 1238aa43c215SJeff Kirsher return 0; 1239aa43c215SJeff Kirsher 1240aa43c215SJeff Kirsher err = qlcnic_napi_add(adapter, netdev); 1241aa43c215SJeff Kirsher if (err) 1242aa43c215SJeff Kirsher return err; 1243aa43c215SJeff Kirsher 1244aa43c215SJeff Kirsher err = qlcnic_alloc_sw_resources(adapter); 1245aa43c215SJeff Kirsher if (err) { 1246aa43c215SJeff Kirsher dev_err(&pdev->dev, "Error in setting sw resources\n"); 1247aa43c215SJeff Kirsher goto err_out_napi_del; 1248aa43c215SJeff Kirsher } 1249aa43c215SJeff Kirsher 1250aa43c215SJeff Kirsher err = qlcnic_alloc_hw_resources(adapter); 1251aa43c215SJeff Kirsher if (err) { 1252aa43c215SJeff Kirsher dev_err(&pdev->dev, "Error in setting hw resources\n"); 1253aa43c215SJeff Kirsher goto err_out_free_sw; 1254aa43c215SJeff Kirsher } 1255aa43c215SJeff Kirsher 1256aa43c215SJeff Kirsher err = qlcnic_request_irq(adapter); 1257aa43c215SJeff Kirsher if (err) { 1258aa43c215SJeff Kirsher dev_err(&pdev->dev, "failed to setup interrupt\n"); 1259aa43c215SJeff Kirsher goto err_out_free_hw; 1260aa43c215SJeff Kirsher } 1261aa43c215SJeff Kirsher 1262aa43c215SJeff Kirsher qlcnic_create_sysfs_entries(adapter); 1263aa43c215SJeff Kirsher 1264aa43c215SJeff Kirsher adapter->is_up = QLCNIC_ADAPTER_UP_MAGIC; 1265aa43c215SJeff Kirsher return 0; 1266aa43c215SJeff Kirsher 1267aa43c215SJeff Kirsher err_out_free_hw: 1268aa43c215SJeff Kirsher qlcnic_free_hw_resources(adapter); 1269aa43c215SJeff Kirsher err_out_free_sw: 1270aa43c215SJeff Kirsher qlcnic_free_sw_resources(adapter); 1271aa43c215SJeff Kirsher err_out_napi_del: 1272aa43c215SJeff Kirsher qlcnic_napi_del(adapter); 1273aa43c215SJeff Kirsher return err; 1274aa43c215SJeff Kirsher } 1275aa43c215SJeff Kirsher 1276aa43c215SJeff Kirsher static void 1277aa43c215SJeff Kirsher qlcnic_detach(struct qlcnic_adapter *adapter) 1278aa43c215SJeff Kirsher { 1279aa43c215SJeff Kirsher if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) 1280aa43c215SJeff Kirsher return; 1281aa43c215SJeff Kirsher 1282aa43c215SJeff Kirsher qlcnic_remove_sysfs_entries(adapter); 1283aa43c215SJeff Kirsher 1284aa43c215SJeff Kirsher qlcnic_free_hw_resources(adapter); 1285aa43c215SJeff Kirsher qlcnic_release_rx_buffers(adapter); 1286aa43c215SJeff Kirsher qlcnic_free_irq(adapter); 1287aa43c215SJeff Kirsher qlcnic_napi_del(adapter); 1288aa43c215SJeff Kirsher qlcnic_free_sw_resources(adapter); 1289aa43c215SJeff Kirsher 1290aa43c215SJeff Kirsher adapter->is_up = 0; 1291aa43c215SJeff Kirsher } 1292aa43c215SJeff Kirsher 1293aa43c215SJeff Kirsher void qlcnic_diag_free_res(struct net_device *netdev, int max_sds_rings) 1294aa43c215SJeff Kirsher { 1295aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 1296aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring; 1297aa43c215SJeff Kirsher int ring; 1298aa43c215SJeff Kirsher 1299aa43c215SJeff Kirsher clear_bit(__QLCNIC_DEV_UP, &adapter->state); 1300aa43c215SJeff Kirsher if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) { 1301aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_sds_rings; ring++) { 1302aa43c215SJeff Kirsher sds_ring = &adapter->recv_ctx->sds_rings[ring]; 1303aa43c215SJeff Kirsher qlcnic_disable_int(sds_ring); 1304aa43c215SJeff Kirsher } 1305aa43c215SJeff Kirsher } 1306aa43c215SJeff Kirsher 1307aa43c215SJeff Kirsher qlcnic_fw_destroy_ctx(adapter); 1308aa43c215SJeff Kirsher 1309aa43c215SJeff Kirsher qlcnic_detach(adapter); 1310aa43c215SJeff Kirsher 1311aa43c215SJeff Kirsher adapter->diag_test = 0; 1312aa43c215SJeff Kirsher adapter->max_sds_rings = max_sds_rings; 1313aa43c215SJeff Kirsher 1314aa43c215SJeff Kirsher if (qlcnic_attach(adapter)) 1315aa43c215SJeff Kirsher goto out; 1316aa43c215SJeff Kirsher 1317aa43c215SJeff Kirsher if (netif_running(netdev)) 1318aa43c215SJeff Kirsher __qlcnic_up(adapter, netdev); 1319aa43c215SJeff Kirsher out: 1320aa43c215SJeff Kirsher netif_device_attach(netdev); 1321aa43c215SJeff Kirsher } 1322aa43c215SJeff Kirsher 1323aa43c215SJeff Kirsher static int qlcnic_alloc_adapter_resources(struct qlcnic_adapter *adapter) 1324aa43c215SJeff Kirsher { 1325aa43c215SJeff Kirsher int err = 0; 1326aa43c215SJeff Kirsher adapter->ahw = kzalloc(sizeof(struct qlcnic_hardware_context), 1327aa43c215SJeff Kirsher GFP_KERNEL); 1328aa43c215SJeff Kirsher if (!adapter->ahw) { 1329aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, 1330aa43c215SJeff Kirsher "Failed to allocate recv ctx resources for adapter\n"); 1331aa43c215SJeff Kirsher err = -ENOMEM; 1332aa43c215SJeff Kirsher goto err_out; 1333aa43c215SJeff Kirsher } 1334aa43c215SJeff Kirsher adapter->recv_ctx = kzalloc(sizeof(struct qlcnic_recv_context), 1335aa43c215SJeff Kirsher GFP_KERNEL); 1336aa43c215SJeff Kirsher if (!adapter->recv_ctx) { 1337aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, 1338aa43c215SJeff Kirsher "Failed to allocate recv ctx resources for adapter\n"); 1339aa43c215SJeff Kirsher kfree(adapter->ahw); 1340aa43c215SJeff Kirsher adapter->ahw = NULL; 1341aa43c215SJeff Kirsher err = -ENOMEM; 1342aa43c215SJeff Kirsher goto err_out; 1343aa43c215SJeff Kirsher } 1344aa43c215SJeff Kirsher /* Initialize interrupt coalesce parameters */ 1345aa43c215SJeff Kirsher adapter->ahw->coal.flag = QLCNIC_INTR_DEFAULT; 1346aa43c215SJeff Kirsher adapter->ahw->coal.rx_time_us = QLCNIC_DEFAULT_INTR_COALESCE_RX_TIME_US; 1347aa43c215SJeff Kirsher adapter->ahw->coal.rx_packets = QLCNIC_DEFAULT_INTR_COALESCE_RX_PACKETS; 1348aa43c215SJeff Kirsher err_out: 1349aa43c215SJeff Kirsher return err; 1350aa43c215SJeff Kirsher } 1351aa43c215SJeff Kirsher 1352aa43c215SJeff Kirsher static void qlcnic_free_adapter_resources(struct qlcnic_adapter *adapter) 1353aa43c215SJeff Kirsher { 1354aa43c215SJeff Kirsher kfree(adapter->recv_ctx); 1355aa43c215SJeff Kirsher adapter->recv_ctx = NULL; 1356aa43c215SJeff Kirsher 1357aa43c215SJeff Kirsher if (adapter->ahw->fw_dump.tmpl_hdr) { 1358aa43c215SJeff Kirsher vfree(adapter->ahw->fw_dump.tmpl_hdr); 1359aa43c215SJeff Kirsher adapter->ahw->fw_dump.tmpl_hdr = NULL; 1360aa43c215SJeff Kirsher } 1361aa43c215SJeff Kirsher kfree(adapter->ahw); 1362aa43c215SJeff Kirsher adapter->ahw = NULL; 1363aa43c215SJeff Kirsher } 1364aa43c215SJeff Kirsher 1365aa43c215SJeff Kirsher int qlcnic_diag_alloc_res(struct net_device *netdev, int test) 1366aa43c215SJeff Kirsher { 1367aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 1368aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring; 1369aa43c215SJeff Kirsher struct qlcnic_host_rds_ring *rds_ring; 1370aa43c215SJeff Kirsher int ring; 1371aa43c215SJeff Kirsher int ret; 1372aa43c215SJeff Kirsher 1373aa43c215SJeff Kirsher netif_device_detach(netdev); 1374aa43c215SJeff Kirsher 1375aa43c215SJeff Kirsher if (netif_running(netdev)) 1376aa43c215SJeff Kirsher __qlcnic_down(adapter, netdev); 1377aa43c215SJeff Kirsher 1378aa43c215SJeff Kirsher qlcnic_detach(adapter); 1379aa43c215SJeff Kirsher 1380aa43c215SJeff Kirsher adapter->max_sds_rings = 1; 1381aa43c215SJeff Kirsher adapter->diag_test = test; 1382aa43c215SJeff Kirsher 1383aa43c215SJeff Kirsher ret = qlcnic_attach(adapter); 1384aa43c215SJeff Kirsher if (ret) { 1385aa43c215SJeff Kirsher netif_device_attach(netdev); 1386aa43c215SJeff Kirsher return ret; 1387aa43c215SJeff Kirsher } 1388aa43c215SJeff Kirsher 1389aa43c215SJeff Kirsher ret = qlcnic_fw_create_ctx(adapter); 1390aa43c215SJeff Kirsher if (ret) { 1391aa43c215SJeff Kirsher qlcnic_detach(adapter); 1392aa43c215SJeff Kirsher netif_device_attach(netdev); 1393aa43c215SJeff Kirsher return ret; 1394aa43c215SJeff Kirsher } 1395aa43c215SJeff Kirsher 1396aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_rds_rings; ring++) { 1397aa43c215SJeff Kirsher rds_ring = &adapter->recv_ctx->rds_rings[ring]; 1398aa43c215SJeff Kirsher qlcnic_post_rx_buffers(adapter, rds_ring); 1399aa43c215SJeff Kirsher } 1400aa43c215SJeff Kirsher 1401aa43c215SJeff Kirsher if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) { 1402aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_sds_rings; ring++) { 1403aa43c215SJeff Kirsher sds_ring = &adapter->recv_ctx->sds_rings[ring]; 1404aa43c215SJeff Kirsher qlcnic_enable_int(sds_ring); 1405aa43c215SJeff Kirsher } 1406aa43c215SJeff Kirsher } 1407aa43c215SJeff Kirsher 1408aa43c215SJeff Kirsher if (adapter->diag_test == QLCNIC_LOOPBACK_TEST) { 1409aa43c215SJeff Kirsher adapter->ahw->loopback_state = 0; 1410aa43c215SJeff Kirsher qlcnic_linkevent_request(adapter, 1); 1411aa43c215SJeff Kirsher } 1412aa43c215SJeff Kirsher 1413aa43c215SJeff Kirsher set_bit(__QLCNIC_DEV_UP, &adapter->state); 1414aa43c215SJeff Kirsher 1415aa43c215SJeff Kirsher return 0; 1416aa43c215SJeff Kirsher } 1417aa43c215SJeff Kirsher 1418aa43c215SJeff Kirsher /* Reset context in hardware only */ 1419aa43c215SJeff Kirsher static int 1420aa43c215SJeff Kirsher qlcnic_reset_hw_context(struct qlcnic_adapter *adapter) 1421aa43c215SJeff Kirsher { 1422aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 1423aa43c215SJeff Kirsher 1424aa43c215SJeff Kirsher if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) 1425aa43c215SJeff Kirsher return -EBUSY; 1426aa43c215SJeff Kirsher 1427aa43c215SJeff Kirsher netif_device_detach(netdev); 1428aa43c215SJeff Kirsher 1429aa43c215SJeff Kirsher qlcnic_down(adapter, netdev); 1430aa43c215SJeff Kirsher 1431aa43c215SJeff Kirsher qlcnic_up(adapter, netdev); 1432aa43c215SJeff Kirsher 1433aa43c215SJeff Kirsher netif_device_attach(netdev); 1434aa43c215SJeff Kirsher 1435aa43c215SJeff Kirsher clear_bit(__QLCNIC_RESETTING, &adapter->state); 1436aa43c215SJeff Kirsher return 0; 1437aa43c215SJeff Kirsher } 1438aa43c215SJeff Kirsher 1439aa43c215SJeff Kirsher int 1440aa43c215SJeff Kirsher qlcnic_reset_context(struct qlcnic_adapter *adapter) 1441aa43c215SJeff Kirsher { 1442aa43c215SJeff Kirsher int err = 0; 1443aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 1444aa43c215SJeff Kirsher 1445aa43c215SJeff Kirsher if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) 1446aa43c215SJeff Kirsher return -EBUSY; 1447aa43c215SJeff Kirsher 1448aa43c215SJeff Kirsher if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) { 1449aa43c215SJeff Kirsher 1450aa43c215SJeff Kirsher netif_device_detach(netdev); 1451aa43c215SJeff Kirsher 1452aa43c215SJeff Kirsher if (netif_running(netdev)) 1453aa43c215SJeff Kirsher __qlcnic_down(adapter, netdev); 1454aa43c215SJeff Kirsher 1455aa43c215SJeff Kirsher qlcnic_detach(adapter); 1456aa43c215SJeff Kirsher 1457aa43c215SJeff Kirsher if (netif_running(netdev)) { 1458aa43c215SJeff Kirsher err = qlcnic_attach(adapter); 1459aa43c215SJeff Kirsher if (!err) 1460aa43c215SJeff Kirsher __qlcnic_up(adapter, netdev); 1461aa43c215SJeff Kirsher } 1462aa43c215SJeff Kirsher 1463aa43c215SJeff Kirsher netif_device_attach(netdev); 1464aa43c215SJeff Kirsher } 1465aa43c215SJeff Kirsher 1466aa43c215SJeff Kirsher clear_bit(__QLCNIC_RESETTING, &adapter->state); 1467aa43c215SJeff Kirsher return err; 1468aa43c215SJeff Kirsher } 1469aa43c215SJeff Kirsher 1470aa43c215SJeff Kirsher static int 1471aa43c215SJeff Kirsher qlcnic_setup_netdev(struct qlcnic_adapter *adapter, 1472aa43c215SJeff Kirsher struct net_device *netdev, u8 pci_using_dac) 1473aa43c215SJeff Kirsher { 1474aa43c215SJeff Kirsher int err; 1475aa43c215SJeff Kirsher struct pci_dev *pdev = adapter->pdev; 1476aa43c215SJeff Kirsher 1477aa43c215SJeff Kirsher adapter->mc_enabled = 0; 1478aa43c215SJeff Kirsher adapter->max_mc_count = 38; 1479aa43c215SJeff Kirsher 1480aa43c215SJeff Kirsher netdev->netdev_ops = &qlcnic_netdev_ops; 1481aa43c215SJeff Kirsher netdev->watchdog_timeo = 5*HZ; 1482aa43c215SJeff Kirsher 1483aa43c215SJeff Kirsher qlcnic_change_mtu(netdev, netdev->mtu); 1484aa43c215SJeff Kirsher 1485aa43c215SJeff Kirsher SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_ops); 1486aa43c215SJeff Kirsher 1487aa43c215SJeff Kirsher netdev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | 1488aa43c215SJeff Kirsher NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM; 1489aa43c215SJeff Kirsher 1490aa43c215SJeff Kirsher if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO) 1491aa43c215SJeff Kirsher netdev->hw_features |= NETIF_F_TSO | NETIF_F_TSO6; 1492aa43c215SJeff Kirsher if (pci_using_dac) 1493aa43c215SJeff Kirsher netdev->hw_features |= NETIF_F_HIGHDMA; 1494aa43c215SJeff Kirsher 1495aa43c215SJeff Kirsher netdev->vlan_features = netdev->hw_features; 1496aa43c215SJeff Kirsher 1497aa43c215SJeff Kirsher if (adapter->capabilities & QLCNIC_FW_CAPABILITY_FVLANTX) 1498aa43c215SJeff Kirsher netdev->hw_features |= NETIF_F_HW_VLAN_TX; 1499aa43c215SJeff Kirsher if (adapter->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO) 1500aa43c215SJeff Kirsher netdev->hw_features |= NETIF_F_LRO; 1501aa43c215SJeff Kirsher 1502aa43c215SJeff Kirsher netdev->features |= netdev->hw_features | 1503aa43c215SJeff Kirsher NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER; 1504aa43c215SJeff Kirsher 1505aa43c215SJeff Kirsher netdev->irq = adapter->msix_entries[0].vector; 1506aa43c215SJeff Kirsher 1507aa43c215SJeff Kirsher err = register_netdev(netdev); 1508aa43c215SJeff Kirsher if (err) { 1509aa43c215SJeff Kirsher dev_err(&pdev->dev, "failed to register net device\n"); 1510aa43c215SJeff Kirsher return err; 1511aa43c215SJeff Kirsher } 1512aa43c215SJeff Kirsher 1513aa43c215SJeff Kirsher return 0; 1514aa43c215SJeff Kirsher } 1515aa43c215SJeff Kirsher 1516aa43c215SJeff Kirsher static int qlcnic_set_dma_mask(struct pci_dev *pdev, u8 *pci_using_dac) 1517aa43c215SJeff Kirsher { 1518aa43c215SJeff Kirsher if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && 1519aa43c215SJeff Kirsher !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) 1520aa43c215SJeff Kirsher *pci_using_dac = 1; 1521aa43c215SJeff Kirsher else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) && 1522aa43c215SJeff Kirsher !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) 1523aa43c215SJeff Kirsher *pci_using_dac = 0; 1524aa43c215SJeff Kirsher else { 1525aa43c215SJeff Kirsher dev_err(&pdev->dev, "Unable to set DMA mask, aborting\n"); 1526aa43c215SJeff Kirsher return -EIO; 1527aa43c215SJeff Kirsher } 1528aa43c215SJeff Kirsher 1529aa43c215SJeff Kirsher return 0; 1530aa43c215SJeff Kirsher } 1531aa43c215SJeff Kirsher 1532aa43c215SJeff Kirsher static int 1533aa43c215SJeff Kirsher qlcnic_alloc_msix_entries(struct qlcnic_adapter *adapter, u16 count) 1534aa43c215SJeff Kirsher { 1535aa43c215SJeff Kirsher adapter->msix_entries = kcalloc(count, sizeof(struct msix_entry), 1536aa43c215SJeff Kirsher GFP_KERNEL); 1537aa43c215SJeff Kirsher 1538aa43c215SJeff Kirsher if (adapter->msix_entries) 1539aa43c215SJeff Kirsher return 0; 1540aa43c215SJeff Kirsher 1541aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, "failed allocating msix_entries\n"); 1542aa43c215SJeff Kirsher return -ENOMEM; 1543aa43c215SJeff Kirsher } 1544aa43c215SJeff Kirsher 1545aa43c215SJeff Kirsher static int __devinit 1546aa43c215SJeff Kirsher qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 1547aa43c215SJeff Kirsher { 1548aa43c215SJeff Kirsher struct net_device *netdev = NULL; 1549aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = NULL; 1550aa43c215SJeff Kirsher int err; 1551aa43c215SJeff Kirsher uint8_t revision_id; 1552aa43c215SJeff Kirsher uint8_t pci_using_dac; 1553aa43c215SJeff Kirsher char brd_name[QLCNIC_MAX_BOARD_NAME_LEN]; 1554aa43c215SJeff Kirsher 1555aa43c215SJeff Kirsher err = pci_enable_device(pdev); 1556aa43c215SJeff Kirsher if (err) 1557aa43c215SJeff Kirsher return err; 1558aa43c215SJeff Kirsher 1559aa43c215SJeff Kirsher if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { 1560aa43c215SJeff Kirsher err = -ENODEV; 1561aa43c215SJeff Kirsher goto err_out_disable_pdev; 1562aa43c215SJeff Kirsher } 1563aa43c215SJeff Kirsher 1564aa43c215SJeff Kirsher err = qlcnic_set_dma_mask(pdev, &pci_using_dac); 1565aa43c215SJeff Kirsher if (err) 1566aa43c215SJeff Kirsher goto err_out_disable_pdev; 1567aa43c215SJeff Kirsher 1568aa43c215SJeff Kirsher err = pci_request_regions(pdev, qlcnic_driver_name); 1569aa43c215SJeff Kirsher if (err) 1570aa43c215SJeff Kirsher goto err_out_disable_pdev; 1571aa43c215SJeff Kirsher 1572aa43c215SJeff Kirsher pci_set_master(pdev); 1573aa43c215SJeff Kirsher pci_enable_pcie_error_reporting(pdev); 1574aa43c215SJeff Kirsher 1575aa43c215SJeff Kirsher netdev = alloc_etherdev(sizeof(struct qlcnic_adapter)); 1576aa43c215SJeff Kirsher if (!netdev) { 1577aa43c215SJeff Kirsher dev_err(&pdev->dev, "failed to allocate net_device\n"); 1578aa43c215SJeff Kirsher err = -ENOMEM; 1579aa43c215SJeff Kirsher goto err_out_free_res; 1580aa43c215SJeff Kirsher } 1581aa43c215SJeff Kirsher 1582aa43c215SJeff Kirsher SET_NETDEV_DEV(netdev, &pdev->dev); 1583aa43c215SJeff Kirsher 1584aa43c215SJeff Kirsher adapter = netdev_priv(netdev); 1585aa43c215SJeff Kirsher adapter->netdev = netdev; 1586aa43c215SJeff Kirsher adapter->pdev = pdev; 1587aa43c215SJeff Kirsher 1588aa43c215SJeff Kirsher if (qlcnic_alloc_adapter_resources(adapter)) 1589aa43c215SJeff Kirsher goto err_out_free_netdev; 1590aa43c215SJeff Kirsher 1591aa43c215SJeff Kirsher adapter->dev_rst_time = jiffies; 1592aa43c215SJeff Kirsher revision_id = pdev->revision; 1593aa43c215SJeff Kirsher adapter->ahw->revision_id = revision_id; 1594aa43c215SJeff Kirsher adapter->mac_learn = qlcnic_mac_learn; 1595aa43c215SJeff Kirsher 1596aa43c215SJeff Kirsher rwlock_init(&adapter->ahw->crb_lock); 1597aa43c215SJeff Kirsher mutex_init(&adapter->ahw->mem_lock); 1598aa43c215SJeff Kirsher 1599aa43c215SJeff Kirsher spin_lock_init(&adapter->tx_clean_lock); 1600aa43c215SJeff Kirsher INIT_LIST_HEAD(&adapter->mac_list); 1601aa43c215SJeff Kirsher 1602aa43c215SJeff Kirsher err = qlcnic_setup_pci_map(adapter); 1603aa43c215SJeff Kirsher if (err) 1604aa43c215SJeff Kirsher goto err_out_free_hw; 1605aa43c215SJeff Kirsher 1606aa43c215SJeff Kirsher /* This will be reset for mezz cards */ 1607aa43c215SJeff Kirsher adapter->portnum = adapter->ahw->pci_func; 1608aa43c215SJeff Kirsher 1609aa43c215SJeff Kirsher err = qlcnic_get_board_info(adapter); 1610aa43c215SJeff Kirsher if (err) { 1611aa43c215SJeff Kirsher dev_err(&pdev->dev, "Error getting board config info.\n"); 1612aa43c215SJeff Kirsher goto err_out_iounmap; 1613aa43c215SJeff Kirsher } 1614aa43c215SJeff Kirsher 1615aa43c215SJeff Kirsher err = qlcnic_setup_idc_param(adapter); 1616aa43c215SJeff Kirsher if (err) 1617aa43c215SJeff Kirsher goto err_out_iounmap; 1618aa43c215SJeff Kirsher 1619aa43c215SJeff Kirsher adapter->flags |= QLCNIC_NEED_FLR; 1620aa43c215SJeff Kirsher 1621aa43c215SJeff Kirsher err = adapter->nic_ops->start_firmware(adapter); 1622aa43c215SJeff Kirsher if (err) { 1623aa43c215SJeff Kirsher dev_err(&pdev->dev, "Loading fw failed.Please Reboot\n"); 1624aa43c215SJeff Kirsher goto err_out_decr_ref; 1625aa43c215SJeff Kirsher } 1626aa43c215SJeff Kirsher 1627aa43c215SJeff Kirsher if (qlcnic_read_mac_addr(adapter)) 1628aa43c215SJeff Kirsher dev_warn(&pdev->dev, "failed to read mac addr\n"); 1629aa43c215SJeff Kirsher 1630aa43c215SJeff Kirsher if (adapter->portnum == 0) { 1631aa43c215SJeff Kirsher get_brd_name(adapter, brd_name); 1632aa43c215SJeff Kirsher 1633aa43c215SJeff Kirsher pr_info("%s: %s Board Chip rev 0x%x\n", 1634aa43c215SJeff Kirsher module_name(THIS_MODULE), 1635aa43c215SJeff Kirsher brd_name, adapter->ahw->revision_id); 1636aa43c215SJeff Kirsher } 1637aa43c215SJeff Kirsher 1638aa43c215SJeff Kirsher qlcnic_clear_stats(adapter); 1639aa43c215SJeff Kirsher 1640aa43c215SJeff Kirsher err = qlcnic_alloc_msix_entries(adapter, adapter->max_rx_ques); 1641aa43c215SJeff Kirsher if (err) 1642aa43c215SJeff Kirsher goto err_out_decr_ref; 1643aa43c215SJeff Kirsher 1644aa43c215SJeff Kirsher qlcnic_setup_intr(adapter); 1645aa43c215SJeff Kirsher 1646aa43c215SJeff Kirsher err = qlcnic_setup_netdev(adapter, netdev, pci_using_dac); 1647aa43c215SJeff Kirsher if (err) 1648aa43c215SJeff Kirsher goto err_out_disable_msi; 1649aa43c215SJeff Kirsher 1650aa43c215SJeff Kirsher pci_set_drvdata(pdev, adapter); 1651aa43c215SJeff Kirsher 1652aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY); 1653aa43c215SJeff Kirsher 1654aa43c215SJeff Kirsher switch (adapter->ahw->port_type) { 1655aa43c215SJeff Kirsher case QLCNIC_GBE: 1656aa43c215SJeff Kirsher dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n", 1657aa43c215SJeff Kirsher adapter->netdev->name); 1658aa43c215SJeff Kirsher break; 1659aa43c215SJeff Kirsher case QLCNIC_XGBE: 1660aa43c215SJeff Kirsher dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n", 1661aa43c215SJeff Kirsher adapter->netdev->name); 1662aa43c215SJeff Kirsher break; 1663aa43c215SJeff Kirsher } 1664aa43c215SJeff Kirsher 1665aa43c215SJeff Kirsher if (adapter->mac_learn) 1666aa43c215SJeff Kirsher qlcnic_alloc_lb_filters_mem(adapter); 1667aa43c215SJeff Kirsher 1668aa43c215SJeff Kirsher qlcnic_create_diag_entries(adapter); 1669aa43c215SJeff Kirsher 1670aa43c215SJeff Kirsher return 0; 1671aa43c215SJeff Kirsher 1672aa43c215SJeff Kirsher err_out_disable_msi: 1673aa43c215SJeff Kirsher qlcnic_teardown_intr(adapter); 1674aa43c215SJeff Kirsher kfree(adapter->msix_entries); 1675aa43c215SJeff Kirsher 1676aa43c215SJeff Kirsher err_out_decr_ref: 1677aa43c215SJeff Kirsher qlcnic_clr_all_drv_state(adapter, 0); 1678aa43c215SJeff Kirsher 1679aa43c215SJeff Kirsher err_out_iounmap: 1680aa43c215SJeff Kirsher qlcnic_cleanup_pci_map(adapter); 1681aa43c215SJeff Kirsher 1682aa43c215SJeff Kirsher err_out_free_hw: 1683aa43c215SJeff Kirsher qlcnic_free_adapter_resources(adapter); 1684aa43c215SJeff Kirsher 1685aa43c215SJeff Kirsher err_out_free_netdev: 1686aa43c215SJeff Kirsher free_netdev(netdev); 1687aa43c215SJeff Kirsher 1688aa43c215SJeff Kirsher err_out_free_res: 1689aa43c215SJeff Kirsher pci_release_regions(pdev); 1690aa43c215SJeff Kirsher 1691aa43c215SJeff Kirsher err_out_disable_pdev: 1692aa43c215SJeff Kirsher pci_set_drvdata(pdev, NULL); 1693aa43c215SJeff Kirsher pci_disable_device(pdev); 1694aa43c215SJeff Kirsher return err; 1695aa43c215SJeff Kirsher } 1696aa43c215SJeff Kirsher 1697aa43c215SJeff Kirsher static void __devexit qlcnic_remove(struct pci_dev *pdev) 1698aa43c215SJeff Kirsher { 1699aa43c215SJeff Kirsher struct qlcnic_adapter *adapter; 1700aa43c215SJeff Kirsher struct net_device *netdev; 1701aa43c215SJeff Kirsher 1702aa43c215SJeff Kirsher adapter = pci_get_drvdata(pdev); 1703aa43c215SJeff Kirsher if (adapter == NULL) 1704aa43c215SJeff Kirsher return; 1705aa43c215SJeff Kirsher 1706aa43c215SJeff Kirsher netdev = adapter->netdev; 1707aa43c215SJeff Kirsher 1708aa43c215SJeff Kirsher qlcnic_cancel_fw_work(adapter); 1709aa43c215SJeff Kirsher 1710aa43c215SJeff Kirsher unregister_netdev(netdev); 1711aa43c215SJeff Kirsher 1712aa43c215SJeff Kirsher qlcnic_detach(adapter); 1713aa43c215SJeff Kirsher 1714aa43c215SJeff Kirsher if (adapter->npars != NULL) 1715aa43c215SJeff Kirsher kfree(adapter->npars); 1716aa43c215SJeff Kirsher if (adapter->eswitch != NULL) 1717aa43c215SJeff Kirsher kfree(adapter->eswitch); 1718aa43c215SJeff Kirsher 1719aa43c215SJeff Kirsher qlcnic_clr_all_drv_state(adapter, 0); 1720aa43c215SJeff Kirsher 1721aa43c215SJeff Kirsher clear_bit(__QLCNIC_RESETTING, &adapter->state); 1722aa43c215SJeff Kirsher 1723aa43c215SJeff Kirsher qlcnic_free_lb_filters_mem(adapter); 1724aa43c215SJeff Kirsher 1725aa43c215SJeff Kirsher qlcnic_teardown_intr(adapter); 1726aa43c215SJeff Kirsher kfree(adapter->msix_entries); 1727aa43c215SJeff Kirsher 1728aa43c215SJeff Kirsher qlcnic_remove_diag_entries(adapter); 1729aa43c215SJeff Kirsher 1730aa43c215SJeff Kirsher qlcnic_cleanup_pci_map(adapter); 1731aa43c215SJeff Kirsher 1732aa43c215SJeff Kirsher qlcnic_release_firmware(adapter); 1733aa43c215SJeff Kirsher 1734aa43c215SJeff Kirsher pci_disable_pcie_error_reporting(pdev); 1735aa43c215SJeff Kirsher pci_release_regions(pdev); 1736aa43c215SJeff Kirsher pci_disable_device(pdev); 1737aa43c215SJeff Kirsher pci_set_drvdata(pdev, NULL); 1738aa43c215SJeff Kirsher 1739aa43c215SJeff Kirsher qlcnic_free_adapter_resources(adapter); 1740aa43c215SJeff Kirsher free_netdev(netdev); 1741aa43c215SJeff Kirsher } 1742aa43c215SJeff Kirsher static int __qlcnic_shutdown(struct pci_dev *pdev) 1743aa43c215SJeff Kirsher { 1744aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); 1745aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 1746aa43c215SJeff Kirsher int retval; 1747aa43c215SJeff Kirsher 1748aa43c215SJeff Kirsher netif_device_detach(netdev); 1749aa43c215SJeff Kirsher 1750aa43c215SJeff Kirsher qlcnic_cancel_fw_work(adapter); 1751aa43c215SJeff Kirsher 1752aa43c215SJeff Kirsher if (netif_running(netdev)) 1753aa43c215SJeff Kirsher qlcnic_down(adapter, netdev); 1754aa43c215SJeff Kirsher 1755aa43c215SJeff Kirsher qlcnic_clr_all_drv_state(adapter, 0); 1756aa43c215SJeff Kirsher 1757aa43c215SJeff Kirsher clear_bit(__QLCNIC_RESETTING, &adapter->state); 1758aa43c215SJeff Kirsher 1759aa43c215SJeff Kirsher retval = pci_save_state(pdev); 1760aa43c215SJeff Kirsher if (retval) 1761aa43c215SJeff Kirsher return retval; 1762aa43c215SJeff Kirsher 1763aa43c215SJeff Kirsher if (qlcnic_wol_supported(adapter)) { 1764aa43c215SJeff Kirsher pci_enable_wake(pdev, PCI_D3cold, 1); 1765aa43c215SJeff Kirsher pci_enable_wake(pdev, PCI_D3hot, 1); 1766aa43c215SJeff Kirsher } 1767aa43c215SJeff Kirsher 1768aa43c215SJeff Kirsher return 0; 1769aa43c215SJeff Kirsher } 1770aa43c215SJeff Kirsher 1771aa43c215SJeff Kirsher static void qlcnic_shutdown(struct pci_dev *pdev) 1772aa43c215SJeff Kirsher { 1773aa43c215SJeff Kirsher if (__qlcnic_shutdown(pdev)) 1774aa43c215SJeff Kirsher return; 1775aa43c215SJeff Kirsher 1776aa43c215SJeff Kirsher pci_disable_device(pdev); 1777aa43c215SJeff Kirsher } 1778aa43c215SJeff Kirsher 1779aa43c215SJeff Kirsher #ifdef CONFIG_PM 1780aa43c215SJeff Kirsher static int 1781aa43c215SJeff Kirsher qlcnic_suspend(struct pci_dev *pdev, pm_message_t state) 1782aa43c215SJeff Kirsher { 1783aa43c215SJeff Kirsher int retval; 1784aa43c215SJeff Kirsher 1785aa43c215SJeff Kirsher retval = __qlcnic_shutdown(pdev); 1786aa43c215SJeff Kirsher if (retval) 1787aa43c215SJeff Kirsher return retval; 1788aa43c215SJeff Kirsher 1789aa43c215SJeff Kirsher pci_set_power_state(pdev, pci_choose_state(pdev, state)); 1790aa43c215SJeff Kirsher return 0; 1791aa43c215SJeff Kirsher } 1792aa43c215SJeff Kirsher 1793aa43c215SJeff Kirsher static int 1794aa43c215SJeff Kirsher qlcnic_resume(struct pci_dev *pdev) 1795aa43c215SJeff Kirsher { 1796aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); 1797aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 1798aa43c215SJeff Kirsher int err; 1799aa43c215SJeff Kirsher 1800aa43c215SJeff Kirsher err = pci_enable_device(pdev); 1801aa43c215SJeff Kirsher if (err) 1802aa43c215SJeff Kirsher return err; 1803aa43c215SJeff Kirsher 1804aa43c215SJeff Kirsher pci_set_power_state(pdev, PCI_D0); 1805aa43c215SJeff Kirsher pci_set_master(pdev); 1806aa43c215SJeff Kirsher pci_restore_state(pdev); 1807aa43c215SJeff Kirsher 1808aa43c215SJeff Kirsher err = adapter->nic_ops->start_firmware(adapter); 1809aa43c215SJeff Kirsher if (err) { 1810aa43c215SJeff Kirsher dev_err(&pdev->dev, "failed to start firmware\n"); 1811aa43c215SJeff Kirsher return err; 1812aa43c215SJeff Kirsher } 1813aa43c215SJeff Kirsher 1814aa43c215SJeff Kirsher if (netif_running(netdev)) { 1815aa43c215SJeff Kirsher err = qlcnic_up(adapter, netdev); 1816aa43c215SJeff Kirsher if (err) 1817aa43c215SJeff Kirsher goto done; 1818aa43c215SJeff Kirsher 1819aa43c215SJeff Kirsher qlcnic_restore_indev_addr(netdev, NETDEV_UP); 1820aa43c215SJeff Kirsher } 1821aa43c215SJeff Kirsher done: 1822aa43c215SJeff Kirsher netif_device_attach(netdev); 1823aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY); 1824aa43c215SJeff Kirsher return 0; 1825aa43c215SJeff Kirsher } 1826aa43c215SJeff Kirsher #endif 1827aa43c215SJeff Kirsher 1828aa43c215SJeff Kirsher static int qlcnic_open(struct net_device *netdev) 1829aa43c215SJeff Kirsher { 1830aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 1831aa43c215SJeff Kirsher int err; 1832aa43c215SJeff Kirsher 1833aa43c215SJeff Kirsher netif_carrier_off(netdev); 1834aa43c215SJeff Kirsher 1835aa43c215SJeff Kirsher err = qlcnic_attach(adapter); 1836aa43c215SJeff Kirsher if (err) 1837aa43c215SJeff Kirsher return err; 1838aa43c215SJeff Kirsher 1839aa43c215SJeff Kirsher err = __qlcnic_up(adapter, netdev); 1840aa43c215SJeff Kirsher if (err) 1841aa43c215SJeff Kirsher goto err_out; 1842aa43c215SJeff Kirsher 1843aa43c215SJeff Kirsher netif_start_queue(netdev); 1844aa43c215SJeff Kirsher 1845aa43c215SJeff Kirsher return 0; 1846aa43c215SJeff Kirsher 1847aa43c215SJeff Kirsher err_out: 1848aa43c215SJeff Kirsher qlcnic_detach(adapter); 1849aa43c215SJeff Kirsher return err; 1850aa43c215SJeff Kirsher } 1851aa43c215SJeff Kirsher 1852aa43c215SJeff Kirsher /* 1853aa43c215SJeff Kirsher * qlcnic_close - Disables a network interface entry point 1854aa43c215SJeff Kirsher */ 1855aa43c215SJeff Kirsher static int qlcnic_close(struct net_device *netdev) 1856aa43c215SJeff Kirsher { 1857aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 1858aa43c215SJeff Kirsher 1859aa43c215SJeff Kirsher __qlcnic_down(adapter, netdev); 1860aa43c215SJeff Kirsher return 0; 1861aa43c215SJeff Kirsher } 1862aa43c215SJeff Kirsher 1863aa43c215SJeff Kirsher void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter) 1864aa43c215SJeff Kirsher { 1865aa43c215SJeff Kirsher void *head; 1866aa43c215SJeff Kirsher int i; 1867aa43c215SJeff Kirsher 1868aa43c215SJeff Kirsher if (adapter->fhash.fmax && adapter->fhash.fhead) 1869aa43c215SJeff Kirsher return; 1870aa43c215SJeff Kirsher 1871aa43c215SJeff Kirsher spin_lock_init(&adapter->mac_learn_lock); 1872aa43c215SJeff Kirsher 1873aa43c215SJeff Kirsher head = kcalloc(QLCNIC_LB_MAX_FILTERS, sizeof(struct hlist_head), 1874aa43c215SJeff Kirsher GFP_KERNEL); 1875aa43c215SJeff Kirsher if (!head) 1876aa43c215SJeff Kirsher return; 1877aa43c215SJeff Kirsher 1878aa43c215SJeff Kirsher adapter->fhash.fmax = QLCNIC_LB_MAX_FILTERS; 1879aa43c215SJeff Kirsher adapter->fhash.fhead = head; 1880aa43c215SJeff Kirsher 1881aa43c215SJeff Kirsher for (i = 0; i < adapter->fhash.fmax; i++) 1882aa43c215SJeff Kirsher INIT_HLIST_HEAD(&adapter->fhash.fhead[i]); 1883aa43c215SJeff Kirsher } 1884aa43c215SJeff Kirsher 1885aa43c215SJeff Kirsher static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter) 1886aa43c215SJeff Kirsher { 1887aa43c215SJeff Kirsher if (adapter->fhash.fmax && adapter->fhash.fhead) 1888aa43c215SJeff Kirsher kfree(adapter->fhash.fhead); 1889aa43c215SJeff Kirsher 1890aa43c215SJeff Kirsher adapter->fhash.fhead = NULL; 1891aa43c215SJeff Kirsher adapter->fhash.fmax = 0; 1892aa43c215SJeff Kirsher } 1893aa43c215SJeff Kirsher 1894aa43c215SJeff Kirsher static void qlcnic_change_filter(struct qlcnic_adapter *adapter, 1895aa43c215SJeff Kirsher u64 uaddr, __le16 vlan_id, struct qlcnic_host_tx_ring *tx_ring) 1896aa43c215SJeff Kirsher { 1897aa43c215SJeff Kirsher struct cmd_desc_type0 *hwdesc; 1898aa43c215SJeff Kirsher struct qlcnic_nic_req *req; 1899aa43c215SJeff Kirsher struct qlcnic_mac_req *mac_req; 1900aa43c215SJeff Kirsher struct qlcnic_vlan_req *vlan_req; 1901aa43c215SJeff Kirsher u32 producer; 1902aa43c215SJeff Kirsher u64 word; 1903aa43c215SJeff Kirsher 1904aa43c215SJeff Kirsher producer = tx_ring->producer; 1905aa43c215SJeff Kirsher hwdesc = &tx_ring->desc_head[tx_ring->producer]; 1906aa43c215SJeff Kirsher 1907aa43c215SJeff Kirsher req = (struct qlcnic_nic_req *)hwdesc; 1908aa43c215SJeff Kirsher memset(req, 0, sizeof(struct qlcnic_nic_req)); 1909aa43c215SJeff Kirsher req->qhdr = cpu_to_le64(QLCNIC_REQUEST << 23); 1910aa43c215SJeff Kirsher 1911aa43c215SJeff Kirsher word = QLCNIC_MAC_EVENT | ((u64)(adapter->portnum) << 16); 1912aa43c215SJeff Kirsher req->req_hdr = cpu_to_le64(word); 1913aa43c215SJeff Kirsher 1914aa43c215SJeff Kirsher mac_req = (struct qlcnic_mac_req *)&(req->words[0]); 1915aa43c215SJeff Kirsher mac_req->op = vlan_id ? QLCNIC_MAC_VLAN_ADD : QLCNIC_MAC_ADD; 1916aa43c215SJeff Kirsher memcpy(mac_req->mac_addr, &uaddr, ETH_ALEN); 1917aa43c215SJeff Kirsher 1918aa43c215SJeff Kirsher vlan_req = (struct qlcnic_vlan_req *)&req->words[1]; 1919aa43c215SJeff Kirsher vlan_req->vlan_id = vlan_id; 1920aa43c215SJeff Kirsher 1921aa43c215SJeff Kirsher tx_ring->producer = get_next_index(producer, tx_ring->num_desc); 1922aa43c215SJeff Kirsher smp_mb(); 1923aa43c215SJeff Kirsher } 1924aa43c215SJeff Kirsher 1925aa43c215SJeff Kirsher #define QLCNIC_MAC_HASH(MAC)\ 1926aa43c215SJeff Kirsher ((((MAC) & 0x70000) >> 0x10) | (((MAC) & 0x70000000000ULL) >> 0x25)) 1927aa43c215SJeff Kirsher 1928aa43c215SJeff Kirsher static void 1929aa43c215SJeff Kirsher qlcnic_send_filter(struct qlcnic_adapter *adapter, 1930aa43c215SJeff Kirsher struct qlcnic_host_tx_ring *tx_ring, 1931aa43c215SJeff Kirsher struct cmd_desc_type0 *first_desc, 1932aa43c215SJeff Kirsher struct sk_buff *skb) 1933aa43c215SJeff Kirsher { 1934aa43c215SJeff Kirsher struct ethhdr *phdr = (struct ethhdr *)(skb->data); 1935aa43c215SJeff Kirsher struct qlcnic_filter *fil, *tmp_fil; 1936aa43c215SJeff Kirsher struct hlist_node *tmp_hnode, *n; 1937aa43c215SJeff Kirsher struct hlist_head *head; 1938aa43c215SJeff Kirsher u64 src_addr = 0; 1939aa43c215SJeff Kirsher __le16 vlan_id = 0; 1940aa43c215SJeff Kirsher u8 hindex; 1941aa43c215SJeff Kirsher 1942aa43c215SJeff Kirsher if (!compare_ether_addr(phdr->h_source, adapter->mac_addr)) 1943aa43c215SJeff Kirsher return; 1944aa43c215SJeff Kirsher 1945aa43c215SJeff Kirsher if (adapter->fhash.fnum >= adapter->fhash.fmax) 1946aa43c215SJeff Kirsher return; 1947aa43c215SJeff Kirsher 1948aa43c215SJeff Kirsher /* Only NPAR capable devices support vlan based learning*/ 1949aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_ESWITCH_ENABLED) 1950aa43c215SJeff Kirsher vlan_id = first_desc->vlan_TCI; 1951aa43c215SJeff Kirsher memcpy(&src_addr, phdr->h_source, ETH_ALEN); 1952aa43c215SJeff Kirsher hindex = QLCNIC_MAC_HASH(src_addr) & (QLCNIC_LB_MAX_FILTERS - 1); 1953aa43c215SJeff Kirsher head = &(adapter->fhash.fhead[hindex]); 1954aa43c215SJeff Kirsher 1955aa43c215SJeff Kirsher hlist_for_each_entry_safe(tmp_fil, tmp_hnode, n, head, fnode) { 1956aa43c215SJeff Kirsher if (!memcmp(tmp_fil->faddr, &src_addr, ETH_ALEN) && 1957aa43c215SJeff Kirsher tmp_fil->vlan_id == vlan_id) { 1958aa43c215SJeff Kirsher 1959aa43c215SJeff Kirsher if (jiffies > 1960aa43c215SJeff Kirsher (QLCNIC_READD_AGE * HZ + tmp_fil->ftime)) 1961aa43c215SJeff Kirsher qlcnic_change_filter(adapter, src_addr, vlan_id, 1962aa43c215SJeff Kirsher tx_ring); 1963aa43c215SJeff Kirsher tmp_fil->ftime = jiffies; 1964aa43c215SJeff Kirsher return; 1965aa43c215SJeff Kirsher } 1966aa43c215SJeff Kirsher } 1967aa43c215SJeff Kirsher 1968aa43c215SJeff Kirsher fil = kzalloc(sizeof(struct qlcnic_filter), GFP_ATOMIC); 1969aa43c215SJeff Kirsher if (!fil) 1970aa43c215SJeff Kirsher return; 1971aa43c215SJeff Kirsher 1972aa43c215SJeff Kirsher qlcnic_change_filter(adapter, src_addr, vlan_id, tx_ring); 1973aa43c215SJeff Kirsher 1974aa43c215SJeff Kirsher fil->ftime = jiffies; 1975aa43c215SJeff Kirsher fil->vlan_id = vlan_id; 1976aa43c215SJeff Kirsher memcpy(fil->faddr, &src_addr, ETH_ALEN); 1977aa43c215SJeff Kirsher spin_lock(&adapter->mac_learn_lock); 1978aa43c215SJeff Kirsher hlist_add_head(&(fil->fnode), head); 1979aa43c215SJeff Kirsher adapter->fhash.fnum++; 1980aa43c215SJeff Kirsher spin_unlock(&adapter->mac_learn_lock); 1981aa43c215SJeff Kirsher } 1982aa43c215SJeff Kirsher 1983aa43c215SJeff Kirsher static int 1984aa43c215SJeff Kirsher qlcnic_tx_pkt(struct qlcnic_adapter *adapter, 1985aa43c215SJeff Kirsher struct cmd_desc_type0 *first_desc, 1986aa43c215SJeff Kirsher struct sk_buff *skb) 1987aa43c215SJeff Kirsher { 1988aa43c215SJeff Kirsher u8 opcode = 0, hdr_len = 0; 1989aa43c215SJeff Kirsher u16 flags = 0, vlan_tci = 0; 1990aa43c215SJeff Kirsher int copied, offset, copy_len; 1991aa43c215SJeff Kirsher struct cmd_desc_type0 *hwdesc; 1992aa43c215SJeff Kirsher struct vlan_ethhdr *vh; 1993aa43c215SJeff Kirsher struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring; 1994aa43c215SJeff Kirsher u16 protocol = ntohs(skb->protocol); 1995aa43c215SJeff Kirsher u32 producer = tx_ring->producer; 1996aa43c215SJeff Kirsher 1997aa43c215SJeff Kirsher if (protocol == ETH_P_8021Q) { 1998aa43c215SJeff Kirsher vh = (struct vlan_ethhdr *)skb->data; 1999aa43c215SJeff Kirsher flags = FLAGS_VLAN_TAGGED; 2000aa43c215SJeff Kirsher vlan_tci = vh->h_vlan_TCI; 2001aa43c215SJeff Kirsher } else if (vlan_tx_tag_present(skb)) { 2002aa43c215SJeff Kirsher flags = FLAGS_VLAN_OOB; 2003aa43c215SJeff Kirsher vlan_tci = vlan_tx_tag_get(skb); 2004aa43c215SJeff Kirsher } 2005aa43c215SJeff Kirsher if (unlikely(adapter->pvid)) { 2006aa43c215SJeff Kirsher if (vlan_tci && !(adapter->flags & QLCNIC_TAGGING_ENABLED)) 2007aa43c215SJeff Kirsher return -EIO; 2008aa43c215SJeff Kirsher if (vlan_tci && (adapter->flags & QLCNIC_TAGGING_ENABLED)) 2009aa43c215SJeff Kirsher goto set_flags; 2010aa43c215SJeff Kirsher 2011aa43c215SJeff Kirsher flags = FLAGS_VLAN_OOB; 2012aa43c215SJeff Kirsher vlan_tci = adapter->pvid; 2013aa43c215SJeff Kirsher } 2014aa43c215SJeff Kirsher set_flags: 2015aa43c215SJeff Kirsher qlcnic_set_tx_vlan_tci(first_desc, vlan_tci); 2016aa43c215SJeff Kirsher qlcnic_set_tx_flags_opcode(first_desc, flags, opcode); 2017aa43c215SJeff Kirsher 2018aa43c215SJeff Kirsher if (*(skb->data) & BIT_0) { 2019aa43c215SJeff Kirsher flags |= BIT_0; 2020aa43c215SJeff Kirsher memcpy(&first_desc->eth_addr, skb->data, ETH_ALEN); 2021aa43c215SJeff Kirsher } 2022aa43c215SJeff Kirsher opcode = TX_ETHER_PKT; 2023aa43c215SJeff Kirsher if ((adapter->netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) && 2024aa43c215SJeff Kirsher skb_shinfo(skb)->gso_size > 0) { 2025aa43c215SJeff Kirsher 2026aa43c215SJeff Kirsher hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); 2027aa43c215SJeff Kirsher 2028aa43c215SJeff Kirsher first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size); 2029aa43c215SJeff Kirsher first_desc->total_hdr_length = hdr_len; 2030aa43c215SJeff Kirsher 2031aa43c215SJeff Kirsher opcode = (protocol == ETH_P_IPV6) ? TX_TCP_LSO6 : TX_TCP_LSO; 2032aa43c215SJeff Kirsher 2033aa43c215SJeff Kirsher /* For LSO, we need to copy the MAC/IP/TCP headers into 2034aa43c215SJeff Kirsher * the descriptor ring */ 2035aa43c215SJeff Kirsher copied = 0; 2036aa43c215SJeff Kirsher offset = 2; 2037aa43c215SJeff Kirsher 2038aa43c215SJeff Kirsher if (flags & FLAGS_VLAN_OOB) { 2039aa43c215SJeff Kirsher first_desc->total_hdr_length += VLAN_HLEN; 2040aa43c215SJeff Kirsher first_desc->tcp_hdr_offset = VLAN_HLEN; 2041aa43c215SJeff Kirsher first_desc->ip_hdr_offset = VLAN_HLEN; 2042aa43c215SJeff Kirsher /* Only in case of TSO on vlan device */ 2043aa43c215SJeff Kirsher flags |= FLAGS_VLAN_TAGGED; 2044aa43c215SJeff Kirsher 2045aa43c215SJeff Kirsher /* Create a TSO vlan header template for firmware */ 2046aa43c215SJeff Kirsher 2047aa43c215SJeff Kirsher hwdesc = &tx_ring->desc_head[producer]; 2048aa43c215SJeff Kirsher tx_ring->cmd_buf_arr[producer].skb = NULL; 2049aa43c215SJeff Kirsher 2050aa43c215SJeff Kirsher copy_len = min((int)sizeof(struct cmd_desc_type0) - 2051aa43c215SJeff Kirsher offset, hdr_len + VLAN_HLEN); 2052aa43c215SJeff Kirsher 2053aa43c215SJeff Kirsher vh = (struct vlan_ethhdr *)((char *) hwdesc + 2); 2054aa43c215SJeff Kirsher skb_copy_from_linear_data(skb, vh, 12); 2055aa43c215SJeff Kirsher vh->h_vlan_proto = htons(ETH_P_8021Q); 2056aa43c215SJeff Kirsher vh->h_vlan_TCI = htons(vlan_tci); 2057aa43c215SJeff Kirsher 2058aa43c215SJeff Kirsher skb_copy_from_linear_data_offset(skb, 12, 2059aa43c215SJeff Kirsher (char *)vh + 16, copy_len - 16); 2060aa43c215SJeff Kirsher 2061aa43c215SJeff Kirsher copied = copy_len - VLAN_HLEN; 2062aa43c215SJeff Kirsher offset = 0; 2063aa43c215SJeff Kirsher 2064aa43c215SJeff Kirsher producer = get_next_index(producer, tx_ring->num_desc); 2065aa43c215SJeff Kirsher } 2066aa43c215SJeff Kirsher 2067aa43c215SJeff Kirsher while (copied < hdr_len) { 2068aa43c215SJeff Kirsher 2069aa43c215SJeff Kirsher copy_len = min((int)sizeof(struct cmd_desc_type0) - 2070aa43c215SJeff Kirsher offset, (hdr_len - copied)); 2071aa43c215SJeff Kirsher 2072aa43c215SJeff Kirsher hwdesc = &tx_ring->desc_head[producer]; 2073aa43c215SJeff Kirsher tx_ring->cmd_buf_arr[producer].skb = NULL; 2074aa43c215SJeff Kirsher 2075aa43c215SJeff Kirsher skb_copy_from_linear_data_offset(skb, copied, 2076aa43c215SJeff Kirsher (char *) hwdesc + offset, copy_len); 2077aa43c215SJeff Kirsher 2078aa43c215SJeff Kirsher copied += copy_len; 2079aa43c215SJeff Kirsher offset = 0; 2080aa43c215SJeff Kirsher 2081aa43c215SJeff Kirsher producer = get_next_index(producer, tx_ring->num_desc); 2082aa43c215SJeff Kirsher } 2083aa43c215SJeff Kirsher 2084aa43c215SJeff Kirsher tx_ring->producer = producer; 2085aa43c215SJeff Kirsher smp_mb(); 2086aa43c215SJeff Kirsher adapter->stats.lso_frames++; 2087aa43c215SJeff Kirsher 2088aa43c215SJeff Kirsher } else if (skb->ip_summed == CHECKSUM_PARTIAL) { 2089aa43c215SJeff Kirsher u8 l4proto; 2090aa43c215SJeff Kirsher 2091aa43c215SJeff Kirsher if (protocol == ETH_P_IP) { 2092aa43c215SJeff Kirsher l4proto = ip_hdr(skb)->protocol; 2093aa43c215SJeff Kirsher 2094aa43c215SJeff Kirsher if (l4proto == IPPROTO_TCP) 2095aa43c215SJeff Kirsher opcode = TX_TCP_PKT; 2096aa43c215SJeff Kirsher else if (l4proto == IPPROTO_UDP) 2097aa43c215SJeff Kirsher opcode = TX_UDP_PKT; 2098aa43c215SJeff Kirsher } else if (protocol == ETH_P_IPV6) { 2099aa43c215SJeff Kirsher l4proto = ipv6_hdr(skb)->nexthdr; 2100aa43c215SJeff Kirsher 2101aa43c215SJeff Kirsher if (l4proto == IPPROTO_TCP) 2102aa43c215SJeff Kirsher opcode = TX_TCPV6_PKT; 2103aa43c215SJeff Kirsher else if (l4proto == IPPROTO_UDP) 2104aa43c215SJeff Kirsher opcode = TX_UDPV6_PKT; 2105aa43c215SJeff Kirsher } 2106aa43c215SJeff Kirsher } 2107aa43c215SJeff Kirsher first_desc->tcp_hdr_offset += skb_transport_offset(skb); 2108aa43c215SJeff Kirsher first_desc->ip_hdr_offset += skb_network_offset(skb); 2109aa43c215SJeff Kirsher qlcnic_set_tx_flags_opcode(first_desc, flags, opcode); 2110aa43c215SJeff Kirsher 2111aa43c215SJeff Kirsher return 0; 2112aa43c215SJeff Kirsher } 2113aa43c215SJeff Kirsher 2114aa43c215SJeff Kirsher static int 2115aa43c215SJeff Kirsher qlcnic_map_tx_skb(struct pci_dev *pdev, 2116aa43c215SJeff Kirsher struct sk_buff *skb, struct qlcnic_cmd_buffer *pbuf) 2117aa43c215SJeff Kirsher { 2118aa43c215SJeff Kirsher struct qlcnic_skb_frag *nf; 2119aa43c215SJeff Kirsher struct skb_frag_struct *frag; 2120aa43c215SJeff Kirsher int i, nr_frags; 2121aa43c215SJeff Kirsher dma_addr_t map; 2122aa43c215SJeff Kirsher 2123aa43c215SJeff Kirsher nr_frags = skb_shinfo(skb)->nr_frags; 2124aa43c215SJeff Kirsher nf = &pbuf->frag_array[0]; 2125aa43c215SJeff Kirsher 2126aa43c215SJeff Kirsher map = pci_map_single(pdev, skb->data, 2127aa43c215SJeff Kirsher skb_headlen(skb), PCI_DMA_TODEVICE); 2128aa43c215SJeff Kirsher if (pci_dma_mapping_error(pdev, map)) 2129aa43c215SJeff Kirsher goto out_err; 2130aa43c215SJeff Kirsher 2131aa43c215SJeff Kirsher nf->dma = map; 2132aa43c215SJeff Kirsher nf->length = skb_headlen(skb); 2133aa43c215SJeff Kirsher 2134aa43c215SJeff Kirsher for (i = 0; i < nr_frags; i++) { 2135aa43c215SJeff Kirsher frag = &skb_shinfo(skb)->frags[i]; 2136aa43c215SJeff Kirsher nf = &pbuf->frag_array[i+1]; 2137aa43c215SJeff Kirsher 21389e903e08SEric Dumazet map = skb_frag_dma_map(&pdev->dev, frag, 0, skb_frag_size(frag), 21395d6bcdfeSIan Campbell DMA_TO_DEVICE); 21405d6bcdfeSIan Campbell if (dma_mapping_error(&pdev->dev, map)) 2141aa43c215SJeff Kirsher goto unwind; 2142aa43c215SJeff Kirsher 2143aa43c215SJeff Kirsher nf->dma = map; 21449e903e08SEric Dumazet nf->length = skb_frag_size(frag); 2145aa43c215SJeff Kirsher } 2146aa43c215SJeff Kirsher 2147aa43c215SJeff Kirsher return 0; 2148aa43c215SJeff Kirsher 2149aa43c215SJeff Kirsher unwind: 2150aa43c215SJeff Kirsher while (--i >= 0) { 2151aa43c215SJeff Kirsher nf = &pbuf->frag_array[i+1]; 2152aa43c215SJeff Kirsher pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE); 2153aa43c215SJeff Kirsher } 2154aa43c215SJeff Kirsher 2155aa43c215SJeff Kirsher nf = &pbuf->frag_array[0]; 2156aa43c215SJeff Kirsher pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE); 2157aa43c215SJeff Kirsher 2158aa43c215SJeff Kirsher out_err: 2159aa43c215SJeff Kirsher return -ENOMEM; 2160aa43c215SJeff Kirsher } 2161aa43c215SJeff Kirsher 2162aa43c215SJeff Kirsher static void 2163aa43c215SJeff Kirsher qlcnic_unmap_buffers(struct pci_dev *pdev, struct sk_buff *skb, 2164aa43c215SJeff Kirsher struct qlcnic_cmd_buffer *pbuf) 2165aa43c215SJeff Kirsher { 2166aa43c215SJeff Kirsher struct qlcnic_skb_frag *nf = &pbuf->frag_array[0]; 2167aa43c215SJeff Kirsher int nr_frags = skb_shinfo(skb)->nr_frags; 2168aa43c215SJeff Kirsher int i; 2169aa43c215SJeff Kirsher 2170aa43c215SJeff Kirsher for (i = 0; i < nr_frags; i++) { 2171aa43c215SJeff Kirsher nf = &pbuf->frag_array[i+1]; 2172aa43c215SJeff Kirsher pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE); 2173aa43c215SJeff Kirsher } 2174aa43c215SJeff Kirsher 2175aa43c215SJeff Kirsher nf = &pbuf->frag_array[0]; 2176aa43c215SJeff Kirsher pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE); 2177aa43c215SJeff Kirsher pbuf->skb = NULL; 2178aa43c215SJeff Kirsher } 2179aa43c215SJeff Kirsher 2180aa43c215SJeff Kirsher static inline void 2181aa43c215SJeff Kirsher qlcnic_clear_cmddesc(u64 *desc) 2182aa43c215SJeff Kirsher { 2183aa43c215SJeff Kirsher desc[0] = 0ULL; 2184aa43c215SJeff Kirsher desc[2] = 0ULL; 2185aa43c215SJeff Kirsher desc[7] = 0ULL; 2186aa43c215SJeff Kirsher } 2187aa43c215SJeff Kirsher 2188aa43c215SJeff Kirsher netdev_tx_t 2189aa43c215SJeff Kirsher qlcnic_xmit_frame(struct sk_buff *skb, struct net_device *netdev) 2190aa43c215SJeff Kirsher { 2191aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 2192aa43c215SJeff Kirsher struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring; 2193aa43c215SJeff Kirsher struct qlcnic_cmd_buffer *pbuf; 2194aa43c215SJeff Kirsher struct qlcnic_skb_frag *buffrag; 2195aa43c215SJeff Kirsher struct cmd_desc_type0 *hwdesc, *first_desc; 2196aa43c215SJeff Kirsher struct pci_dev *pdev; 2197aa43c215SJeff Kirsher struct ethhdr *phdr; 2198aa43c215SJeff Kirsher int delta = 0; 2199aa43c215SJeff Kirsher int i, k; 2200aa43c215SJeff Kirsher 2201aa43c215SJeff Kirsher u32 producer; 2202aa43c215SJeff Kirsher int frag_count; 2203aa43c215SJeff Kirsher u32 num_txd = tx_ring->num_desc; 2204aa43c215SJeff Kirsher 2205aa43c215SJeff Kirsher if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) { 2206aa43c215SJeff Kirsher netif_stop_queue(netdev); 2207aa43c215SJeff Kirsher return NETDEV_TX_BUSY; 2208aa43c215SJeff Kirsher } 2209aa43c215SJeff Kirsher 2210aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_MACSPOOF) { 2211aa43c215SJeff Kirsher phdr = (struct ethhdr *)skb->data; 2212aa43c215SJeff Kirsher if (compare_ether_addr(phdr->h_source, 2213aa43c215SJeff Kirsher adapter->mac_addr)) 2214aa43c215SJeff Kirsher goto drop_packet; 2215aa43c215SJeff Kirsher } 2216aa43c215SJeff Kirsher 2217aa43c215SJeff Kirsher frag_count = skb_shinfo(skb)->nr_frags + 1; 2218aa43c215SJeff Kirsher /* 14 frags supported for normal packet and 2219aa43c215SJeff Kirsher * 32 frags supported for TSO packet 2220aa43c215SJeff Kirsher */ 2221aa43c215SJeff Kirsher if (!skb_is_gso(skb) && frag_count > QLCNIC_MAX_FRAGS_PER_TX) { 2222aa43c215SJeff Kirsher 2223aa43c215SJeff Kirsher for (i = 0; i < (frag_count - QLCNIC_MAX_FRAGS_PER_TX); i++) 22249e903e08SEric Dumazet delta += skb_frag_size(&skb_shinfo(skb)->frags[i]); 2225aa43c215SJeff Kirsher 2226aa43c215SJeff Kirsher if (!__pskb_pull_tail(skb, delta)) 2227aa43c215SJeff Kirsher goto drop_packet; 2228aa43c215SJeff Kirsher 2229aa43c215SJeff Kirsher frag_count = 1 + skb_shinfo(skb)->nr_frags; 2230aa43c215SJeff Kirsher } 2231aa43c215SJeff Kirsher 2232aa43c215SJeff Kirsher if (unlikely(qlcnic_tx_avail(tx_ring) <= TX_STOP_THRESH)) { 2233aa43c215SJeff Kirsher netif_stop_queue(netdev); 2234aa43c215SJeff Kirsher if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH) 2235aa43c215SJeff Kirsher netif_start_queue(netdev); 2236aa43c215SJeff Kirsher else { 2237aa43c215SJeff Kirsher adapter->stats.xmit_off++; 2238aa43c215SJeff Kirsher return NETDEV_TX_BUSY; 2239aa43c215SJeff Kirsher } 2240aa43c215SJeff Kirsher } 2241aa43c215SJeff Kirsher 2242aa43c215SJeff Kirsher producer = tx_ring->producer; 2243aa43c215SJeff Kirsher pbuf = &tx_ring->cmd_buf_arr[producer]; 2244aa43c215SJeff Kirsher 2245aa43c215SJeff Kirsher pdev = adapter->pdev; 2246aa43c215SJeff Kirsher 2247aa43c215SJeff Kirsher first_desc = hwdesc = &tx_ring->desc_head[producer]; 2248aa43c215SJeff Kirsher qlcnic_clear_cmddesc((u64 *)hwdesc); 2249aa43c215SJeff Kirsher 2250aa43c215SJeff Kirsher if (qlcnic_map_tx_skb(pdev, skb, pbuf)) { 2251aa43c215SJeff Kirsher adapter->stats.tx_dma_map_error++; 2252aa43c215SJeff Kirsher goto drop_packet; 2253aa43c215SJeff Kirsher } 2254aa43c215SJeff Kirsher 2255aa43c215SJeff Kirsher pbuf->skb = skb; 2256aa43c215SJeff Kirsher pbuf->frag_count = frag_count; 2257aa43c215SJeff Kirsher 2258aa43c215SJeff Kirsher qlcnic_set_tx_frags_len(first_desc, frag_count, skb->len); 2259aa43c215SJeff Kirsher qlcnic_set_tx_port(first_desc, adapter->portnum); 2260aa43c215SJeff Kirsher 2261aa43c215SJeff Kirsher for (i = 0; i < frag_count; i++) { 2262aa43c215SJeff Kirsher 2263aa43c215SJeff Kirsher k = i % 4; 2264aa43c215SJeff Kirsher 2265aa43c215SJeff Kirsher if ((k == 0) && (i > 0)) { 2266aa43c215SJeff Kirsher /* move to next desc.*/ 2267aa43c215SJeff Kirsher producer = get_next_index(producer, num_txd); 2268aa43c215SJeff Kirsher hwdesc = &tx_ring->desc_head[producer]; 2269aa43c215SJeff Kirsher qlcnic_clear_cmddesc((u64 *)hwdesc); 2270aa43c215SJeff Kirsher tx_ring->cmd_buf_arr[producer].skb = NULL; 2271aa43c215SJeff Kirsher } 2272aa43c215SJeff Kirsher 2273aa43c215SJeff Kirsher buffrag = &pbuf->frag_array[i]; 2274aa43c215SJeff Kirsher 2275aa43c215SJeff Kirsher hwdesc->buffer_length[k] = cpu_to_le16(buffrag->length); 2276aa43c215SJeff Kirsher switch (k) { 2277aa43c215SJeff Kirsher case 0: 2278aa43c215SJeff Kirsher hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma); 2279aa43c215SJeff Kirsher break; 2280aa43c215SJeff Kirsher case 1: 2281aa43c215SJeff Kirsher hwdesc->addr_buffer2 = cpu_to_le64(buffrag->dma); 2282aa43c215SJeff Kirsher break; 2283aa43c215SJeff Kirsher case 2: 2284aa43c215SJeff Kirsher hwdesc->addr_buffer3 = cpu_to_le64(buffrag->dma); 2285aa43c215SJeff Kirsher break; 2286aa43c215SJeff Kirsher case 3: 2287aa43c215SJeff Kirsher hwdesc->addr_buffer4 = cpu_to_le64(buffrag->dma); 2288aa43c215SJeff Kirsher break; 2289aa43c215SJeff Kirsher } 2290aa43c215SJeff Kirsher } 2291aa43c215SJeff Kirsher 2292aa43c215SJeff Kirsher tx_ring->producer = get_next_index(producer, num_txd); 2293aa43c215SJeff Kirsher smp_mb(); 2294aa43c215SJeff Kirsher 2295aa43c215SJeff Kirsher if (unlikely(qlcnic_tx_pkt(adapter, first_desc, skb))) 2296aa43c215SJeff Kirsher goto unwind_buff; 2297aa43c215SJeff Kirsher 2298aa43c215SJeff Kirsher if (adapter->mac_learn) 2299aa43c215SJeff Kirsher qlcnic_send_filter(adapter, tx_ring, first_desc, skb); 2300aa43c215SJeff Kirsher 2301aa43c215SJeff Kirsher adapter->stats.txbytes += skb->len; 2302aa43c215SJeff Kirsher adapter->stats.xmitcalled++; 2303aa43c215SJeff Kirsher 2304aa43c215SJeff Kirsher qlcnic_update_cmd_producer(adapter, tx_ring); 2305aa43c215SJeff Kirsher 2306aa43c215SJeff Kirsher return NETDEV_TX_OK; 2307aa43c215SJeff Kirsher 2308aa43c215SJeff Kirsher unwind_buff: 2309aa43c215SJeff Kirsher qlcnic_unmap_buffers(pdev, skb, pbuf); 2310aa43c215SJeff Kirsher drop_packet: 2311aa43c215SJeff Kirsher adapter->stats.txdropped++; 2312aa43c215SJeff Kirsher dev_kfree_skb_any(skb); 2313aa43c215SJeff Kirsher return NETDEV_TX_OK; 2314aa43c215SJeff Kirsher } 2315aa43c215SJeff Kirsher 2316aa43c215SJeff Kirsher static int qlcnic_check_temp(struct qlcnic_adapter *adapter) 2317aa43c215SJeff Kirsher { 2318aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 2319aa43c215SJeff Kirsher u32 temp, temp_state, temp_val; 2320aa43c215SJeff Kirsher int rv = 0; 2321aa43c215SJeff Kirsher 2322aa43c215SJeff Kirsher temp = QLCRD32(adapter, CRB_TEMP_STATE); 2323aa43c215SJeff Kirsher 2324aa43c215SJeff Kirsher temp_state = qlcnic_get_temp_state(temp); 2325aa43c215SJeff Kirsher temp_val = qlcnic_get_temp_val(temp); 2326aa43c215SJeff Kirsher 2327aa43c215SJeff Kirsher if (temp_state == QLCNIC_TEMP_PANIC) { 2328aa43c215SJeff Kirsher dev_err(&netdev->dev, 2329aa43c215SJeff Kirsher "Device temperature %d degrees C exceeds" 2330aa43c215SJeff Kirsher " maximum allowed. Hardware has been shut down.\n", 2331aa43c215SJeff Kirsher temp_val); 2332aa43c215SJeff Kirsher rv = 1; 2333aa43c215SJeff Kirsher } else if (temp_state == QLCNIC_TEMP_WARN) { 2334aa43c215SJeff Kirsher if (adapter->temp == QLCNIC_TEMP_NORMAL) { 2335aa43c215SJeff Kirsher dev_err(&netdev->dev, 2336aa43c215SJeff Kirsher "Device temperature %d degrees C " 2337aa43c215SJeff Kirsher "exceeds operating range." 2338aa43c215SJeff Kirsher " Immediate action needed.\n", 2339aa43c215SJeff Kirsher temp_val); 2340aa43c215SJeff Kirsher } 2341aa43c215SJeff Kirsher } else { 2342aa43c215SJeff Kirsher if (adapter->temp == QLCNIC_TEMP_WARN) { 2343aa43c215SJeff Kirsher dev_info(&netdev->dev, 2344aa43c215SJeff Kirsher "Device temperature is now %d degrees C" 2345aa43c215SJeff Kirsher " in normal range.\n", temp_val); 2346aa43c215SJeff Kirsher } 2347aa43c215SJeff Kirsher } 2348aa43c215SJeff Kirsher adapter->temp = temp_state; 2349aa43c215SJeff Kirsher return rv; 2350aa43c215SJeff Kirsher } 2351aa43c215SJeff Kirsher 2352aa43c215SJeff Kirsher void qlcnic_advert_link_change(struct qlcnic_adapter *adapter, int linkup) 2353aa43c215SJeff Kirsher { 2354aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 2355aa43c215SJeff Kirsher 2356aa43c215SJeff Kirsher if (adapter->ahw->linkup && !linkup) { 2357aa43c215SJeff Kirsher netdev_info(netdev, "NIC Link is down\n"); 2358aa43c215SJeff Kirsher adapter->ahw->linkup = 0; 2359aa43c215SJeff Kirsher if (netif_running(netdev)) { 2360aa43c215SJeff Kirsher netif_carrier_off(netdev); 2361aa43c215SJeff Kirsher netif_stop_queue(netdev); 2362aa43c215SJeff Kirsher } 2363aa43c215SJeff Kirsher } else if (!adapter->ahw->linkup && linkup) { 2364aa43c215SJeff Kirsher netdev_info(netdev, "NIC Link is up\n"); 2365aa43c215SJeff Kirsher adapter->ahw->linkup = 1; 2366aa43c215SJeff Kirsher if (netif_running(netdev)) { 2367aa43c215SJeff Kirsher netif_carrier_on(netdev); 2368aa43c215SJeff Kirsher netif_wake_queue(netdev); 2369aa43c215SJeff Kirsher } 2370aa43c215SJeff Kirsher } 2371aa43c215SJeff Kirsher } 2372aa43c215SJeff Kirsher 2373aa43c215SJeff Kirsher static void qlcnic_tx_timeout(struct net_device *netdev) 2374aa43c215SJeff Kirsher { 2375aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 2376aa43c215SJeff Kirsher 2377aa43c215SJeff Kirsher if (test_bit(__QLCNIC_RESETTING, &adapter->state)) 2378aa43c215SJeff Kirsher return; 2379aa43c215SJeff Kirsher 2380aa43c215SJeff Kirsher dev_err(&netdev->dev, "transmit timeout, resetting.\n"); 2381aa43c215SJeff Kirsher 2382aa43c215SJeff Kirsher if (++adapter->tx_timeo_cnt >= QLCNIC_MAX_TX_TIMEOUTS) 2383aa43c215SJeff Kirsher adapter->need_fw_reset = 1; 2384aa43c215SJeff Kirsher else 2385aa43c215SJeff Kirsher adapter->reset_context = 1; 2386aa43c215SJeff Kirsher } 2387aa43c215SJeff Kirsher 2388aa43c215SJeff Kirsher static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev) 2389aa43c215SJeff Kirsher { 2390aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 2391aa43c215SJeff Kirsher struct net_device_stats *stats = &netdev->stats; 2392aa43c215SJeff Kirsher 2393aa43c215SJeff Kirsher stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts; 2394aa43c215SJeff Kirsher stats->tx_packets = adapter->stats.xmitfinished; 2395aa43c215SJeff Kirsher stats->rx_bytes = adapter->stats.rxbytes + adapter->stats.lrobytes; 2396aa43c215SJeff Kirsher stats->tx_bytes = adapter->stats.txbytes; 2397aa43c215SJeff Kirsher stats->rx_dropped = adapter->stats.rxdropped; 2398aa43c215SJeff Kirsher stats->tx_dropped = adapter->stats.txdropped; 2399aa43c215SJeff Kirsher 2400aa43c215SJeff Kirsher return stats; 2401aa43c215SJeff Kirsher } 2402aa43c215SJeff Kirsher 2403aa43c215SJeff Kirsher static irqreturn_t qlcnic_clear_legacy_intr(struct qlcnic_adapter *adapter) 2404aa43c215SJeff Kirsher { 2405aa43c215SJeff Kirsher u32 status; 2406aa43c215SJeff Kirsher 2407aa43c215SJeff Kirsher status = readl(adapter->isr_int_vec); 2408aa43c215SJeff Kirsher 2409aa43c215SJeff Kirsher if (!(status & adapter->int_vec_bit)) 2410aa43c215SJeff Kirsher return IRQ_NONE; 2411aa43c215SJeff Kirsher 2412aa43c215SJeff Kirsher /* check interrupt state machine, to be sure */ 2413aa43c215SJeff Kirsher status = readl(adapter->crb_int_state_reg); 2414aa43c215SJeff Kirsher if (!ISR_LEGACY_INT_TRIGGERED(status)) 2415aa43c215SJeff Kirsher return IRQ_NONE; 2416aa43c215SJeff Kirsher 2417aa43c215SJeff Kirsher writel(0xffffffff, adapter->tgt_status_reg); 2418aa43c215SJeff Kirsher /* read twice to ensure write is flushed */ 2419aa43c215SJeff Kirsher readl(adapter->isr_int_vec); 2420aa43c215SJeff Kirsher readl(adapter->isr_int_vec); 2421aa43c215SJeff Kirsher 2422aa43c215SJeff Kirsher return IRQ_HANDLED; 2423aa43c215SJeff Kirsher } 2424aa43c215SJeff Kirsher 2425aa43c215SJeff Kirsher static irqreturn_t qlcnic_tmp_intr(int irq, void *data) 2426aa43c215SJeff Kirsher { 2427aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring = data; 2428aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = sds_ring->adapter; 2429aa43c215SJeff Kirsher 2430aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_MSIX_ENABLED) 2431aa43c215SJeff Kirsher goto done; 2432aa43c215SJeff Kirsher else if (adapter->flags & QLCNIC_MSI_ENABLED) { 2433aa43c215SJeff Kirsher writel(0xffffffff, adapter->tgt_status_reg); 2434aa43c215SJeff Kirsher goto done; 2435aa43c215SJeff Kirsher } 2436aa43c215SJeff Kirsher 2437aa43c215SJeff Kirsher if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE) 2438aa43c215SJeff Kirsher return IRQ_NONE; 2439aa43c215SJeff Kirsher 2440aa43c215SJeff Kirsher done: 2441aa43c215SJeff Kirsher adapter->diag_cnt++; 2442aa43c215SJeff Kirsher qlcnic_enable_int(sds_ring); 2443aa43c215SJeff Kirsher return IRQ_HANDLED; 2444aa43c215SJeff Kirsher } 2445aa43c215SJeff Kirsher 2446aa43c215SJeff Kirsher static irqreturn_t qlcnic_intr(int irq, void *data) 2447aa43c215SJeff Kirsher { 2448aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring = data; 2449aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = sds_ring->adapter; 2450aa43c215SJeff Kirsher 2451aa43c215SJeff Kirsher if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE) 2452aa43c215SJeff Kirsher return IRQ_NONE; 2453aa43c215SJeff Kirsher 2454aa43c215SJeff Kirsher napi_schedule(&sds_ring->napi); 2455aa43c215SJeff Kirsher 2456aa43c215SJeff Kirsher return IRQ_HANDLED; 2457aa43c215SJeff Kirsher } 2458aa43c215SJeff Kirsher 2459aa43c215SJeff Kirsher static irqreturn_t qlcnic_msi_intr(int irq, void *data) 2460aa43c215SJeff Kirsher { 2461aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring = data; 2462aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = sds_ring->adapter; 2463aa43c215SJeff Kirsher 2464aa43c215SJeff Kirsher /* clear interrupt */ 2465aa43c215SJeff Kirsher writel(0xffffffff, adapter->tgt_status_reg); 2466aa43c215SJeff Kirsher 2467aa43c215SJeff Kirsher napi_schedule(&sds_ring->napi); 2468aa43c215SJeff Kirsher return IRQ_HANDLED; 2469aa43c215SJeff Kirsher } 2470aa43c215SJeff Kirsher 2471aa43c215SJeff Kirsher static irqreturn_t qlcnic_msix_intr(int irq, void *data) 2472aa43c215SJeff Kirsher { 2473aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring = data; 2474aa43c215SJeff Kirsher 2475aa43c215SJeff Kirsher napi_schedule(&sds_ring->napi); 2476aa43c215SJeff Kirsher return IRQ_HANDLED; 2477aa43c215SJeff Kirsher } 2478aa43c215SJeff Kirsher 2479aa43c215SJeff Kirsher static int qlcnic_process_cmd_ring(struct qlcnic_adapter *adapter) 2480aa43c215SJeff Kirsher { 2481aa43c215SJeff Kirsher u32 sw_consumer, hw_consumer; 2482aa43c215SJeff Kirsher int count = 0, i; 2483aa43c215SJeff Kirsher struct qlcnic_cmd_buffer *buffer; 2484aa43c215SJeff Kirsher struct pci_dev *pdev = adapter->pdev; 2485aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 2486aa43c215SJeff Kirsher struct qlcnic_skb_frag *frag; 2487aa43c215SJeff Kirsher int done; 2488aa43c215SJeff Kirsher struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring; 2489aa43c215SJeff Kirsher 2490aa43c215SJeff Kirsher if (!spin_trylock(&adapter->tx_clean_lock)) 2491aa43c215SJeff Kirsher return 1; 2492aa43c215SJeff Kirsher 2493aa43c215SJeff Kirsher sw_consumer = tx_ring->sw_consumer; 2494aa43c215SJeff Kirsher hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer)); 2495aa43c215SJeff Kirsher 2496aa43c215SJeff Kirsher while (sw_consumer != hw_consumer) { 2497aa43c215SJeff Kirsher buffer = &tx_ring->cmd_buf_arr[sw_consumer]; 2498aa43c215SJeff Kirsher if (buffer->skb) { 2499aa43c215SJeff Kirsher frag = &buffer->frag_array[0]; 2500aa43c215SJeff Kirsher pci_unmap_single(pdev, frag->dma, frag->length, 2501aa43c215SJeff Kirsher PCI_DMA_TODEVICE); 2502aa43c215SJeff Kirsher frag->dma = 0ULL; 2503aa43c215SJeff Kirsher for (i = 1; i < buffer->frag_count; i++) { 2504aa43c215SJeff Kirsher frag++; 2505aa43c215SJeff Kirsher pci_unmap_page(pdev, frag->dma, frag->length, 2506aa43c215SJeff Kirsher PCI_DMA_TODEVICE); 2507aa43c215SJeff Kirsher frag->dma = 0ULL; 2508aa43c215SJeff Kirsher } 2509aa43c215SJeff Kirsher 2510aa43c215SJeff Kirsher adapter->stats.xmitfinished++; 2511aa43c215SJeff Kirsher dev_kfree_skb_any(buffer->skb); 2512aa43c215SJeff Kirsher buffer->skb = NULL; 2513aa43c215SJeff Kirsher } 2514aa43c215SJeff Kirsher 2515aa43c215SJeff Kirsher sw_consumer = get_next_index(sw_consumer, tx_ring->num_desc); 2516aa43c215SJeff Kirsher if (++count >= MAX_STATUS_HANDLE) 2517aa43c215SJeff Kirsher break; 2518aa43c215SJeff Kirsher } 2519aa43c215SJeff Kirsher 2520aa43c215SJeff Kirsher if (count && netif_running(netdev)) { 2521aa43c215SJeff Kirsher tx_ring->sw_consumer = sw_consumer; 2522aa43c215SJeff Kirsher 2523aa43c215SJeff Kirsher smp_mb(); 2524aa43c215SJeff Kirsher 2525aa43c215SJeff Kirsher if (netif_queue_stopped(netdev) && netif_carrier_ok(netdev)) { 2526aa43c215SJeff Kirsher if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH) { 2527aa43c215SJeff Kirsher netif_wake_queue(netdev); 2528aa43c215SJeff Kirsher adapter->stats.xmit_on++; 2529aa43c215SJeff Kirsher } 2530aa43c215SJeff Kirsher } 2531aa43c215SJeff Kirsher adapter->tx_timeo_cnt = 0; 2532aa43c215SJeff Kirsher } 2533aa43c215SJeff Kirsher /* 2534aa43c215SJeff Kirsher * If everything is freed up to consumer then check if the ring is full 2535aa43c215SJeff Kirsher * If the ring is full then check if more needs to be freed and 2536aa43c215SJeff Kirsher * schedule the call back again. 2537aa43c215SJeff Kirsher * 2538aa43c215SJeff Kirsher * This happens when there are 2 CPUs. One could be freeing and the 2539aa43c215SJeff Kirsher * other filling it. If the ring is full when we get out of here and 2540aa43c215SJeff Kirsher * the card has already interrupted the host then the host can miss the 2541aa43c215SJeff Kirsher * interrupt. 2542aa43c215SJeff Kirsher * 2543aa43c215SJeff Kirsher * There is still a possible race condition and the host could miss an 2544aa43c215SJeff Kirsher * interrupt. The card has to take care of this. 2545aa43c215SJeff Kirsher */ 2546aa43c215SJeff Kirsher hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer)); 2547aa43c215SJeff Kirsher done = (sw_consumer == hw_consumer); 2548aa43c215SJeff Kirsher spin_unlock(&adapter->tx_clean_lock); 2549aa43c215SJeff Kirsher 2550aa43c215SJeff Kirsher return done; 2551aa43c215SJeff Kirsher } 2552aa43c215SJeff Kirsher 2553aa43c215SJeff Kirsher static int qlcnic_poll(struct napi_struct *napi, int budget) 2554aa43c215SJeff Kirsher { 2555aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring = 2556aa43c215SJeff Kirsher container_of(napi, struct qlcnic_host_sds_ring, napi); 2557aa43c215SJeff Kirsher 2558aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = sds_ring->adapter; 2559aa43c215SJeff Kirsher 2560aa43c215SJeff Kirsher int tx_complete; 2561aa43c215SJeff Kirsher int work_done; 2562aa43c215SJeff Kirsher 2563aa43c215SJeff Kirsher tx_complete = qlcnic_process_cmd_ring(adapter); 2564aa43c215SJeff Kirsher 2565aa43c215SJeff Kirsher work_done = qlcnic_process_rcv_ring(sds_ring, budget); 2566aa43c215SJeff Kirsher 2567aa43c215SJeff Kirsher if ((work_done < budget) && tx_complete) { 2568aa43c215SJeff Kirsher napi_complete(&sds_ring->napi); 2569aa43c215SJeff Kirsher if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) 2570aa43c215SJeff Kirsher qlcnic_enable_int(sds_ring); 2571aa43c215SJeff Kirsher } 2572aa43c215SJeff Kirsher 2573aa43c215SJeff Kirsher return work_done; 2574aa43c215SJeff Kirsher } 2575aa43c215SJeff Kirsher 2576aa43c215SJeff Kirsher static int qlcnic_rx_poll(struct napi_struct *napi, int budget) 2577aa43c215SJeff Kirsher { 2578aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring = 2579aa43c215SJeff Kirsher container_of(napi, struct qlcnic_host_sds_ring, napi); 2580aa43c215SJeff Kirsher 2581aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = sds_ring->adapter; 2582aa43c215SJeff Kirsher int work_done; 2583aa43c215SJeff Kirsher 2584aa43c215SJeff Kirsher work_done = qlcnic_process_rcv_ring(sds_ring, budget); 2585aa43c215SJeff Kirsher 2586aa43c215SJeff Kirsher if (work_done < budget) { 2587aa43c215SJeff Kirsher napi_complete(&sds_ring->napi); 2588aa43c215SJeff Kirsher if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) 2589aa43c215SJeff Kirsher qlcnic_enable_int(sds_ring); 2590aa43c215SJeff Kirsher } 2591aa43c215SJeff Kirsher 2592aa43c215SJeff Kirsher return work_done; 2593aa43c215SJeff Kirsher } 2594aa43c215SJeff Kirsher 2595aa43c215SJeff Kirsher #ifdef CONFIG_NET_POLL_CONTROLLER 2596aa43c215SJeff Kirsher static void qlcnic_poll_controller(struct net_device *netdev) 2597aa43c215SJeff Kirsher { 2598aa43c215SJeff Kirsher int ring; 2599aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring; 2600aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 2601aa43c215SJeff Kirsher struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; 2602aa43c215SJeff Kirsher 2603aa43c215SJeff Kirsher disable_irq(adapter->irq); 2604aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_sds_rings; ring++) { 2605aa43c215SJeff Kirsher sds_ring = &recv_ctx->sds_rings[ring]; 2606aa43c215SJeff Kirsher qlcnic_intr(adapter->irq, sds_ring); 2607aa43c215SJeff Kirsher } 2608aa43c215SJeff Kirsher enable_irq(adapter->irq); 2609aa43c215SJeff Kirsher } 2610aa43c215SJeff Kirsher #endif 2611aa43c215SJeff Kirsher 2612aa43c215SJeff Kirsher static void 2613aa43c215SJeff Kirsher qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding) 2614aa43c215SJeff Kirsher { 2615aa43c215SJeff Kirsher u32 val; 2616aa43c215SJeff Kirsher 2617aa43c215SJeff Kirsher val = adapter->portnum & 0xf; 2618aa43c215SJeff Kirsher val |= encoding << 7; 2619aa43c215SJeff Kirsher val |= (jiffies - adapter->dev_rst_time) << 8; 2620aa43c215SJeff Kirsher 2621aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DRV_SCRATCH, val); 2622aa43c215SJeff Kirsher adapter->dev_rst_time = jiffies; 2623aa43c215SJeff Kirsher } 2624aa43c215SJeff Kirsher 2625aa43c215SJeff Kirsher static int 2626aa43c215SJeff Kirsher qlcnic_set_drv_state(struct qlcnic_adapter *adapter, u8 state) 2627aa43c215SJeff Kirsher { 2628aa43c215SJeff Kirsher u32 val; 2629aa43c215SJeff Kirsher 2630aa43c215SJeff Kirsher WARN_ON(state != QLCNIC_DEV_NEED_RESET && 2631aa43c215SJeff Kirsher state != QLCNIC_DEV_NEED_QUISCENT); 2632aa43c215SJeff Kirsher 2633aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2634aa43c215SJeff Kirsher return -EIO; 2635aa43c215SJeff Kirsher 2636aa43c215SJeff Kirsher val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); 2637aa43c215SJeff Kirsher 2638aa43c215SJeff Kirsher if (state == QLCNIC_DEV_NEED_RESET) 2639aa43c215SJeff Kirsher QLC_DEV_SET_RST_RDY(val, adapter->portnum); 2640aa43c215SJeff Kirsher else if (state == QLCNIC_DEV_NEED_QUISCENT) 2641aa43c215SJeff Kirsher QLC_DEV_SET_QSCNT_RDY(val, adapter->portnum); 2642aa43c215SJeff Kirsher 2643aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); 2644aa43c215SJeff Kirsher 2645aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2646aa43c215SJeff Kirsher 2647aa43c215SJeff Kirsher return 0; 2648aa43c215SJeff Kirsher } 2649aa43c215SJeff Kirsher 2650aa43c215SJeff Kirsher static int 2651aa43c215SJeff Kirsher qlcnic_clr_drv_state(struct qlcnic_adapter *adapter) 2652aa43c215SJeff Kirsher { 2653aa43c215SJeff Kirsher u32 val; 2654aa43c215SJeff Kirsher 2655aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2656aa43c215SJeff Kirsher return -EBUSY; 2657aa43c215SJeff Kirsher 2658aa43c215SJeff Kirsher val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); 2659aa43c215SJeff Kirsher QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum); 2660aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); 2661aa43c215SJeff Kirsher 2662aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2663aa43c215SJeff Kirsher 2664aa43c215SJeff Kirsher return 0; 2665aa43c215SJeff Kirsher } 2666aa43c215SJeff Kirsher 2667aa43c215SJeff Kirsher static void 2668aa43c215SJeff Kirsher qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8 failed) 2669aa43c215SJeff Kirsher { 2670aa43c215SJeff Kirsher u32 val; 2671aa43c215SJeff Kirsher 2672aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2673aa43c215SJeff Kirsher goto err; 2674aa43c215SJeff Kirsher 2675aa43c215SJeff Kirsher val = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE); 2676aa43c215SJeff Kirsher QLC_DEV_CLR_REF_CNT(val, adapter->portnum); 2677aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val); 2678aa43c215SJeff Kirsher 2679aa43c215SJeff Kirsher if (failed) { 2680aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED); 2681aa43c215SJeff Kirsher dev_info(&adapter->pdev->dev, 2682aa43c215SJeff Kirsher "Device state set to Failed. Please Reboot\n"); 2683aa43c215SJeff Kirsher } else if (!(val & 0x11111111)) 2684aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_COLD); 2685aa43c215SJeff Kirsher 2686aa43c215SJeff Kirsher val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); 2687aa43c215SJeff Kirsher QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum); 2688aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); 2689aa43c215SJeff Kirsher 2690aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2691aa43c215SJeff Kirsher err: 2692aa43c215SJeff Kirsher adapter->fw_fail_cnt = 0; 2693aa43c215SJeff Kirsher adapter->flags &= ~QLCNIC_FW_HANG; 2694aa43c215SJeff Kirsher clear_bit(__QLCNIC_START_FW, &adapter->state); 2695aa43c215SJeff Kirsher clear_bit(__QLCNIC_RESETTING, &adapter->state); 2696aa43c215SJeff Kirsher } 2697aa43c215SJeff Kirsher 2698aa43c215SJeff Kirsher /* Grab api lock, before checking state */ 2699aa43c215SJeff Kirsher static int 2700aa43c215SJeff Kirsher qlcnic_check_drv_state(struct qlcnic_adapter *adapter) 2701aa43c215SJeff Kirsher { 2702aa43c215SJeff Kirsher int act, state, active_mask; 2703aa43c215SJeff Kirsher 2704aa43c215SJeff Kirsher state = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); 2705aa43c215SJeff Kirsher act = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE); 2706aa43c215SJeff Kirsher 2707aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_FW_RESET_OWNER) { 2708aa43c215SJeff Kirsher active_mask = (~(1 << (adapter->ahw->pci_func * 4))); 2709aa43c215SJeff Kirsher act = act & active_mask; 2710aa43c215SJeff Kirsher } 2711aa43c215SJeff Kirsher 2712aa43c215SJeff Kirsher if (((state & 0x11111111) == (act & 0x11111111)) || 2713aa43c215SJeff Kirsher ((act & 0x11111111) == ((state >> 1) & 0x11111111))) 2714aa43c215SJeff Kirsher return 0; 2715aa43c215SJeff Kirsher else 2716aa43c215SJeff Kirsher return 1; 2717aa43c215SJeff Kirsher } 2718aa43c215SJeff Kirsher 2719aa43c215SJeff Kirsher static int qlcnic_check_idc_ver(struct qlcnic_adapter *adapter) 2720aa43c215SJeff Kirsher { 2721aa43c215SJeff Kirsher u32 val = QLCRD32(adapter, QLCNIC_CRB_DRV_IDC_VER); 2722aa43c215SJeff Kirsher 2723aa43c215SJeff Kirsher if (val != QLCNIC_DRV_IDC_VER) { 2724aa43c215SJeff Kirsher dev_warn(&adapter->pdev->dev, "IDC Version mismatch, driver's" 2725aa43c215SJeff Kirsher " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER, val); 2726aa43c215SJeff Kirsher } 2727aa43c215SJeff Kirsher 2728aa43c215SJeff Kirsher return 0; 2729aa43c215SJeff Kirsher } 2730aa43c215SJeff Kirsher 2731aa43c215SJeff Kirsher static int 2732aa43c215SJeff Kirsher qlcnic_can_start_firmware(struct qlcnic_adapter *adapter) 2733aa43c215SJeff Kirsher { 2734aa43c215SJeff Kirsher u32 val, prev_state; 2735aa43c215SJeff Kirsher u8 dev_init_timeo = adapter->dev_init_timeo; 2736aa43c215SJeff Kirsher u8 portnum = adapter->portnum; 2737aa43c215SJeff Kirsher u8 ret; 2738aa43c215SJeff Kirsher 2739aa43c215SJeff Kirsher if (test_and_clear_bit(__QLCNIC_START_FW, &adapter->state)) 2740aa43c215SJeff Kirsher return 1; 2741aa43c215SJeff Kirsher 2742aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2743aa43c215SJeff Kirsher return -1; 2744aa43c215SJeff Kirsher 2745aa43c215SJeff Kirsher val = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE); 2746aa43c215SJeff Kirsher if (!(val & (1 << (portnum * 4)))) { 2747aa43c215SJeff Kirsher QLC_DEV_SET_REF_CNT(val, portnum); 2748aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val); 2749aa43c215SJeff Kirsher } 2750aa43c215SJeff Kirsher 2751aa43c215SJeff Kirsher prev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); 2752aa43c215SJeff Kirsher QLCDB(adapter, HW, "Device state = %u\n", prev_state); 2753aa43c215SJeff Kirsher 2754aa43c215SJeff Kirsher switch (prev_state) { 2755aa43c215SJeff Kirsher case QLCNIC_DEV_COLD: 2756aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_INITIALIZING); 2757aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DRV_IDC_VER, QLCNIC_DRV_IDC_VER); 2758aa43c215SJeff Kirsher qlcnic_idc_debug_info(adapter, 0); 2759aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2760aa43c215SJeff Kirsher return 1; 2761aa43c215SJeff Kirsher 2762aa43c215SJeff Kirsher case QLCNIC_DEV_READY: 2763aa43c215SJeff Kirsher ret = qlcnic_check_idc_ver(adapter); 2764aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2765aa43c215SJeff Kirsher return ret; 2766aa43c215SJeff Kirsher 2767aa43c215SJeff Kirsher case QLCNIC_DEV_NEED_RESET: 2768aa43c215SJeff Kirsher val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); 2769aa43c215SJeff Kirsher QLC_DEV_SET_RST_RDY(val, portnum); 2770aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); 2771aa43c215SJeff Kirsher break; 2772aa43c215SJeff Kirsher 2773aa43c215SJeff Kirsher case QLCNIC_DEV_NEED_QUISCENT: 2774aa43c215SJeff Kirsher val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); 2775aa43c215SJeff Kirsher QLC_DEV_SET_QSCNT_RDY(val, portnum); 2776aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); 2777aa43c215SJeff Kirsher break; 2778aa43c215SJeff Kirsher 2779aa43c215SJeff Kirsher case QLCNIC_DEV_FAILED: 2780aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, "Device in failed state.\n"); 2781aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2782aa43c215SJeff Kirsher return -1; 2783aa43c215SJeff Kirsher 2784aa43c215SJeff Kirsher case QLCNIC_DEV_INITIALIZING: 2785aa43c215SJeff Kirsher case QLCNIC_DEV_QUISCENT: 2786aa43c215SJeff Kirsher break; 2787aa43c215SJeff Kirsher } 2788aa43c215SJeff Kirsher 2789aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2790aa43c215SJeff Kirsher 2791aa43c215SJeff Kirsher do { 2792aa43c215SJeff Kirsher msleep(1000); 2793aa43c215SJeff Kirsher prev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); 2794aa43c215SJeff Kirsher 2795aa43c215SJeff Kirsher if (prev_state == QLCNIC_DEV_QUISCENT) 2796aa43c215SJeff Kirsher continue; 2797aa43c215SJeff Kirsher } while ((prev_state != QLCNIC_DEV_READY) && --dev_init_timeo); 2798aa43c215SJeff Kirsher 2799aa43c215SJeff Kirsher if (!dev_init_timeo) { 2800aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, 2801aa43c215SJeff Kirsher "Waiting for device to initialize timeout\n"); 2802aa43c215SJeff Kirsher return -1; 2803aa43c215SJeff Kirsher } 2804aa43c215SJeff Kirsher 2805aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2806aa43c215SJeff Kirsher return -1; 2807aa43c215SJeff Kirsher 2808aa43c215SJeff Kirsher val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); 2809aa43c215SJeff Kirsher QLC_DEV_CLR_RST_QSCNT(val, portnum); 2810aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); 2811aa43c215SJeff Kirsher 2812aa43c215SJeff Kirsher ret = qlcnic_check_idc_ver(adapter); 2813aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2814aa43c215SJeff Kirsher 2815aa43c215SJeff Kirsher return ret; 2816aa43c215SJeff Kirsher } 2817aa43c215SJeff Kirsher 2818aa43c215SJeff Kirsher static void 2819aa43c215SJeff Kirsher qlcnic_fwinit_work(struct work_struct *work) 2820aa43c215SJeff Kirsher { 2821aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = container_of(work, 2822aa43c215SJeff Kirsher struct qlcnic_adapter, fw_work.work); 2823aa43c215SJeff Kirsher u32 dev_state = 0xf; 2824aa43c215SJeff Kirsher u32 val; 2825aa43c215SJeff Kirsher 2826aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2827aa43c215SJeff Kirsher goto err_ret; 2828aa43c215SJeff Kirsher 2829aa43c215SJeff Kirsher dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); 2830aa43c215SJeff Kirsher if (dev_state == QLCNIC_DEV_QUISCENT || 2831aa43c215SJeff Kirsher dev_state == QLCNIC_DEV_NEED_QUISCENT) { 2832aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2833aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_fwinit_work, 2834aa43c215SJeff Kirsher FW_POLL_DELAY * 2); 2835aa43c215SJeff Kirsher return; 2836aa43c215SJeff Kirsher } 2837aa43c215SJeff Kirsher 2838aa43c215SJeff Kirsher if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC) { 2839aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2840aa43c215SJeff Kirsher goto wait_npar; 2841aa43c215SJeff Kirsher } 2842aa43c215SJeff Kirsher 2843aa43c215SJeff Kirsher if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) { 2844aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, "Reset:Failed to get ack %d sec\n", 2845aa43c215SJeff Kirsher adapter->reset_ack_timeo); 2846aa43c215SJeff Kirsher goto skip_ack_check; 2847aa43c215SJeff Kirsher } 2848aa43c215SJeff Kirsher 2849aa43c215SJeff Kirsher if (!qlcnic_check_drv_state(adapter)) { 2850aa43c215SJeff Kirsher skip_ack_check: 2851aa43c215SJeff Kirsher dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); 2852aa43c215SJeff Kirsher 2853aa43c215SJeff Kirsher if (dev_state == QLCNIC_DEV_NEED_RESET) { 2854aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, 2855aa43c215SJeff Kirsher QLCNIC_DEV_INITIALIZING); 2856aa43c215SJeff Kirsher set_bit(__QLCNIC_START_FW, &adapter->state); 2857aa43c215SJeff Kirsher QLCDB(adapter, DRV, "Restarting fw\n"); 2858aa43c215SJeff Kirsher qlcnic_idc_debug_info(adapter, 0); 2859aa43c215SJeff Kirsher val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); 2860aa43c215SJeff Kirsher QLC_DEV_SET_RST_RDY(val, adapter->portnum); 2861aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); 2862aa43c215SJeff Kirsher } 2863aa43c215SJeff Kirsher 2864aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2865aa43c215SJeff Kirsher 2866aa43c215SJeff Kirsher rtnl_lock(); 2867aa43c215SJeff Kirsher if (adapter->ahw->fw_dump.enable && 2868aa43c215SJeff Kirsher (adapter->flags & QLCNIC_FW_RESET_OWNER)) { 2869aa43c215SJeff Kirsher QLCDB(adapter, DRV, "Take FW dump\n"); 2870aa43c215SJeff Kirsher qlcnic_dump_fw(adapter); 2871aa43c215SJeff Kirsher adapter->flags |= QLCNIC_FW_HANG; 2872aa43c215SJeff Kirsher } 2873aa43c215SJeff Kirsher rtnl_unlock(); 2874aa43c215SJeff Kirsher 2875aa43c215SJeff Kirsher adapter->flags &= ~QLCNIC_FW_RESET_OWNER; 2876aa43c215SJeff Kirsher if (!adapter->nic_ops->start_firmware(adapter)) { 2877aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_attach_work, 0); 2878aa43c215SJeff Kirsher adapter->fw_wait_cnt = 0; 2879aa43c215SJeff Kirsher return; 2880aa43c215SJeff Kirsher } 2881aa43c215SJeff Kirsher goto err_ret; 2882aa43c215SJeff Kirsher } 2883aa43c215SJeff Kirsher 2884aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2885aa43c215SJeff Kirsher 2886aa43c215SJeff Kirsher wait_npar: 2887aa43c215SJeff Kirsher dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); 2888aa43c215SJeff Kirsher QLCDB(adapter, HW, "Func waiting: Device state=%u\n", dev_state); 2889aa43c215SJeff Kirsher 2890aa43c215SJeff Kirsher switch (dev_state) { 2891aa43c215SJeff Kirsher case QLCNIC_DEV_READY: 2892aa43c215SJeff Kirsher if (!adapter->nic_ops->start_firmware(adapter)) { 2893aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_attach_work, 0); 2894aa43c215SJeff Kirsher adapter->fw_wait_cnt = 0; 2895aa43c215SJeff Kirsher return; 2896aa43c215SJeff Kirsher } 2897aa43c215SJeff Kirsher case QLCNIC_DEV_FAILED: 2898aa43c215SJeff Kirsher break; 2899aa43c215SJeff Kirsher default: 2900aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, 2901aa43c215SJeff Kirsher qlcnic_fwinit_work, FW_POLL_DELAY); 2902aa43c215SJeff Kirsher return; 2903aa43c215SJeff Kirsher } 2904aa43c215SJeff Kirsher 2905aa43c215SJeff Kirsher err_ret: 2906aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, "Fwinit work failed state=%u " 2907aa43c215SJeff Kirsher "fw_wait_cnt=%u\n", dev_state, adapter->fw_wait_cnt); 2908aa43c215SJeff Kirsher netif_device_attach(adapter->netdev); 2909aa43c215SJeff Kirsher qlcnic_clr_all_drv_state(adapter, 0); 2910aa43c215SJeff Kirsher } 2911aa43c215SJeff Kirsher 2912aa43c215SJeff Kirsher static void 2913aa43c215SJeff Kirsher qlcnic_detach_work(struct work_struct *work) 2914aa43c215SJeff Kirsher { 2915aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = container_of(work, 2916aa43c215SJeff Kirsher struct qlcnic_adapter, fw_work.work); 2917aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 2918aa43c215SJeff Kirsher u32 status; 2919aa43c215SJeff Kirsher 2920aa43c215SJeff Kirsher netif_device_detach(netdev); 2921aa43c215SJeff Kirsher 2922aa43c215SJeff Kirsher /* Dont grab rtnl lock during Quiscent mode */ 2923aa43c215SJeff Kirsher if (adapter->dev_state == QLCNIC_DEV_NEED_QUISCENT) { 2924aa43c215SJeff Kirsher if (netif_running(netdev)) 2925aa43c215SJeff Kirsher __qlcnic_down(adapter, netdev); 2926aa43c215SJeff Kirsher } else 2927aa43c215SJeff Kirsher qlcnic_down(adapter, netdev); 2928aa43c215SJeff Kirsher 2929aa43c215SJeff Kirsher status = QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS1); 2930aa43c215SJeff Kirsher 293144f65b29SSony Chacko if (status & QLCNIC_RCODE_FATAL_ERROR) { 293244f65b29SSony Chacko dev_err(&adapter->pdev->dev, 293344f65b29SSony Chacko "Detaching the device: peg halt status1=0x%x\n", 293444f65b29SSony Chacko status); 2935aa43c215SJeff Kirsher 293644f65b29SSony Chacko if (QLCNIC_FWERROR_CODE(status) == QLCNIC_FWERROR_FAN_FAILURE) { 293744f65b29SSony Chacko dev_err(&adapter->pdev->dev, 293844f65b29SSony Chacko "On board active cooling fan failed. " 293944f65b29SSony Chacko "Device has been halted.\n"); 294044f65b29SSony Chacko dev_err(&adapter->pdev->dev, 294144f65b29SSony Chacko "Replace the adapter.\n"); 294244f65b29SSony Chacko } 294344f65b29SSony Chacko 2944aa43c215SJeff Kirsher goto err_ret; 294544f65b29SSony Chacko } 294644f65b29SSony Chacko 294744f65b29SSony Chacko if (adapter->temp == QLCNIC_TEMP_PANIC) { 294844f65b29SSony Chacko dev_err(&adapter->pdev->dev, "Detaching the device: temp=%d\n", 294944f65b29SSony Chacko adapter->temp); 295044f65b29SSony Chacko goto err_ret; 295144f65b29SSony Chacko } 295244f65b29SSony Chacko 2953aa43c215SJeff Kirsher /* Dont ack if this instance is the reset owner */ 2954aa43c215SJeff Kirsher if (!(adapter->flags & QLCNIC_FW_RESET_OWNER)) { 295544f65b29SSony Chacko if (qlcnic_set_drv_state(adapter, adapter->dev_state)) { 295644f65b29SSony Chacko dev_err(&adapter->pdev->dev, 295744f65b29SSony Chacko "Failed to set driver state," 295844f65b29SSony Chacko "detaching the device.\n"); 2959aa43c215SJeff Kirsher goto err_ret; 2960aa43c215SJeff Kirsher } 296144f65b29SSony Chacko } 2962aa43c215SJeff Kirsher 2963aa43c215SJeff Kirsher adapter->fw_wait_cnt = 0; 2964aa43c215SJeff Kirsher 2965aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_fwinit_work, FW_POLL_DELAY); 2966aa43c215SJeff Kirsher 2967aa43c215SJeff Kirsher return; 2968aa43c215SJeff Kirsher 2969aa43c215SJeff Kirsher err_ret: 2970aa43c215SJeff Kirsher netif_device_attach(netdev); 2971aa43c215SJeff Kirsher qlcnic_clr_all_drv_state(adapter, 1); 2972aa43c215SJeff Kirsher } 2973aa43c215SJeff Kirsher 2974aa43c215SJeff Kirsher /*Transit NPAR state to NON Operational */ 2975aa43c215SJeff Kirsher static void 2976aa43c215SJeff Kirsher qlcnic_set_npar_non_operational(struct qlcnic_adapter *adapter) 2977aa43c215SJeff Kirsher { 2978aa43c215SJeff Kirsher u32 state; 2979aa43c215SJeff Kirsher 2980aa43c215SJeff Kirsher state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE); 2981aa43c215SJeff Kirsher if (state == QLCNIC_DEV_NPAR_NON_OPER) 2982aa43c215SJeff Kirsher return; 2983aa43c215SJeff Kirsher 2984aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2985aa43c215SJeff Kirsher return; 2986aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_NON_OPER); 2987aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2988aa43c215SJeff Kirsher } 2989aa43c215SJeff Kirsher 2990aa43c215SJeff Kirsher /*Transit to RESET state from READY state only */ 2991aa43c215SJeff Kirsher void 2992aa43c215SJeff Kirsher qlcnic_dev_request_reset(struct qlcnic_adapter *adapter) 2993aa43c215SJeff Kirsher { 2994aa43c215SJeff Kirsher u32 state; 2995aa43c215SJeff Kirsher 2996aa43c215SJeff Kirsher adapter->need_fw_reset = 1; 2997aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2998aa43c215SJeff Kirsher return; 2999aa43c215SJeff Kirsher 3000aa43c215SJeff Kirsher state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); 3001aa43c215SJeff Kirsher 3002aa43c215SJeff Kirsher if (state == QLCNIC_DEV_READY) { 3003aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_NEED_RESET); 3004aa43c215SJeff Kirsher adapter->flags |= QLCNIC_FW_RESET_OWNER; 3005aa43c215SJeff Kirsher QLCDB(adapter, DRV, "NEED_RESET state set\n"); 3006aa43c215SJeff Kirsher qlcnic_idc_debug_info(adapter, 0); 3007aa43c215SJeff Kirsher } 3008aa43c215SJeff Kirsher 3009aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_NON_OPER); 3010aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 3011aa43c215SJeff Kirsher } 3012aa43c215SJeff Kirsher 3013aa43c215SJeff Kirsher /* Transit to NPAR READY state from NPAR NOT READY state */ 3014aa43c215SJeff Kirsher static void 3015aa43c215SJeff Kirsher qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter) 3016aa43c215SJeff Kirsher { 3017aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 3018aa43c215SJeff Kirsher return; 3019aa43c215SJeff Kirsher 3020aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_OPER); 3021aa43c215SJeff Kirsher QLCDB(adapter, DRV, "NPAR operational state set\n"); 3022aa43c215SJeff Kirsher 3023aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 3024aa43c215SJeff Kirsher } 3025aa43c215SJeff Kirsher 3026aa43c215SJeff Kirsher static void 3027aa43c215SJeff Kirsher qlcnic_schedule_work(struct qlcnic_adapter *adapter, 3028aa43c215SJeff Kirsher work_func_t func, int delay) 3029aa43c215SJeff Kirsher { 3030aa43c215SJeff Kirsher if (test_bit(__QLCNIC_AER, &adapter->state)) 3031aa43c215SJeff Kirsher return; 3032aa43c215SJeff Kirsher 3033aa43c215SJeff Kirsher INIT_DELAYED_WORK(&adapter->fw_work, func); 3034aa43c215SJeff Kirsher queue_delayed_work(qlcnic_wq, &adapter->fw_work, 3035aa43c215SJeff Kirsher round_jiffies_relative(delay)); 3036aa43c215SJeff Kirsher } 3037aa43c215SJeff Kirsher 3038aa43c215SJeff Kirsher static void 3039aa43c215SJeff Kirsher qlcnic_cancel_fw_work(struct qlcnic_adapter *adapter) 3040aa43c215SJeff Kirsher { 3041aa43c215SJeff Kirsher while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) 3042aa43c215SJeff Kirsher msleep(10); 3043aa43c215SJeff Kirsher 3044aa43c215SJeff Kirsher cancel_delayed_work_sync(&adapter->fw_work); 3045aa43c215SJeff Kirsher } 3046aa43c215SJeff Kirsher 3047aa43c215SJeff Kirsher static void 3048aa43c215SJeff Kirsher qlcnic_attach_work(struct work_struct *work) 3049aa43c215SJeff Kirsher { 3050aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = container_of(work, 3051aa43c215SJeff Kirsher struct qlcnic_adapter, fw_work.work); 3052aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 3053aa43c215SJeff Kirsher u32 npar_state; 3054aa43c215SJeff Kirsher 3055aa43c215SJeff Kirsher if (adapter->op_mode != QLCNIC_MGMT_FUNC) { 3056aa43c215SJeff Kirsher npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE); 3057aa43c215SJeff Kirsher if (adapter->fw_wait_cnt++ > QLCNIC_DEV_NPAR_OPER_TIMEO) 3058aa43c215SJeff Kirsher qlcnic_clr_all_drv_state(adapter, 0); 3059aa43c215SJeff Kirsher else if (npar_state != QLCNIC_DEV_NPAR_OPER) 3060aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_attach_work, 3061aa43c215SJeff Kirsher FW_POLL_DELAY); 3062aa43c215SJeff Kirsher else 3063aa43c215SJeff Kirsher goto attach; 3064aa43c215SJeff Kirsher QLCDB(adapter, DRV, "Waiting for NPAR state to operational\n"); 3065aa43c215SJeff Kirsher return; 3066aa43c215SJeff Kirsher } 3067aa43c215SJeff Kirsher attach: 3068aa43c215SJeff Kirsher if (netif_running(netdev)) { 3069aa43c215SJeff Kirsher if (qlcnic_up(adapter, netdev)) 3070aa43c215SJeff Kirsher goto done; 3071aa43c215SJeff Kirsher 3072aa43c215SJeff Kirsher qlcnic_restore_indev_addr(netdev, NETDEV_UP); 3073aa43c215SJeff Kirsher } 3074aa43c215SJeff Kirsher 3075aa43c215SJeff Kirsher done: 3076aa43c215SJeff Kirsher netif_device_attach(netdev); 3077aa43c215SJeff Kirsher adapter->fw_fail_cnt = 0; 3078aa43c215SJeff Kirsher adapter->flags &= ~QLCNIC_FW_HANG; 3079aa43c215SJeff Kirsher clear_bit(__QLCNIC_RESETTING, &adapter->state); 3080aa43c215SJeff Kirsher 3081aa43c215SJeff Kirsher if (!qlcnic_clr_drv_state(adapter)) 3082aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, 3083aa43c215SJeff Kirsher FW_POLL_DELAY); 3084aa43c215SJeff Kirsher } 3085aa43c215SJeff Kirsher 3086aa43c215SJeff Kirsher static int 3087aa43c215SJeff Kirsher qlcnic_check_health(struct qlcnic_adapter *adapter) 3088aa43c215SJeff Kirsher { 3089aa43c215SJeff Kirsher u32 state = 0, heartbeat; 3090853d4bcaSAmeen Rahman u32 peg_status; 3091aa43c215SJeff Kirsher 3092aa43c215SJeff Kirsher if (qlcnic_check_temp(adapter)) 3093aa43c215SJeff Kirsher goto detach; 3094aa43c215SJeff Kirsher 3095aa43c215SJeff Kirsher if (adapter->need_fw_reset) 3096aa43c215SJeff Kirsher qlcnic_dev_request_reset(adapter); 3097aa43c215SJeff Kirsher 3098aa43c215SJeff Kirsher state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); 3099aa43c215SJeff Kirsher if (state == QLCNIC_DEV_NEED_RESET) { 3100aa43c215SJeff Kirsher qlcnic_set_npar_non_operational(adapter); 3101aa43c215SJeff Kirsher adapter->need_fw_reset = 1; 3102aa43c215SJeff Kirsher } else if (state == QLCNIC_DEV_NEED_QUISCENT) 3103aa43c215SJeff Kirsher goto detach; 3104aa43c215SJeff Kirsher 3105aa43c215SJeff Kirsher heartbeat = QLCRD32(adapter, QLCNIC_PEG_ALIVE_COUNTER); 3106aa43c215SJeff Kirsher if (heartbeat != adapter->heartbeat) { 3107aa43c215SJeff Kirsher adapter->heartbeat = heartbeat; 3108aa43c215SJeff Kirsher adapter->fw_fail_cnt = 0; 3109aa43c215SJeff Kirsher if (adapter->need_fw_reset) 3110aa43c215SJeff Kirsher goto detach; 3111aa43c215SJeff Kirsher 3112aa43c215SJeff Kirsher if (adapter->reset_context && auto_fw_reset) { 3113aa43c215SJeff Kirsher qlcnic_reset_hw_context(adapter); 3114aa43c215SJeff Kirsher adapter->netdev->trans_start = jiffies; 3115aa43c215SJeff Kirsher } 3116aa43c215SJeff Kirsher 3117aa43c215SJeff Kirsher return 0; 3118aa43c215SJeff Kirsher } 3119aa43c215SJeff Kirsher 3120aa43c215SJeff Kirsher if (++adapter->fw_fail_cnt < FW_FAIL_THRESH) 3121aa43c215SJeff Kirsher return 0; 3122aa43c215SJeff Kirsher 3123aa43c215SJeff Kirsher adapter->flags |= QLCNIC_FW_HANG; 3124aa43c215SJeff Kirsher 3125aa43c215SJeff Kirsher qlcnic_dev_request_reset(adapter); 3126aa43c215SJeff Kirsher 3127aa43c215SJeff Kirsher if (auto_fw_reset) 3128aa43c215SJeff Kirsher clear_bit(__QLCNIC_FW_ATTACHED, &adapter->state); 3129aa43c215SJeff Kirsher 3130853d4bcaSAmeen Rahman dev_err(&adapter->pdev->dev, "firmware hang detected\n"); 3131853d4bcaSAmeen Rahman dev_err(&adapter->pdev->dev, "Dumping hw/fw registers\n" 3132aa43c215SJeff Kirsher "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n" 3133aa43c215SJeff Kirsher "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n" 3134aa43c215SJeff Kirsher "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n" 3135aa43c215SJeff Kirsher "PEG_NET_4_PC: 0x%x\n", 3136aa43c215SJeff Kirsher QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS1), 3137aa43c215SJeff Kirsher QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS2), 3138aa43c215SJeff Kirsher QLCRD32(adapter, QLCNIC_CRB_PEG_NET_0 + 0x3c), 3139aa43c215SJeff Kirsher QLCRD32(adapter, QLCNIC_CRB_PEG_NET_1 + 0x3c), 3140aa43c215SJeff Kirsher QLCRD32(adapter, QLCNIC_CRB_PEG_NET_2 + 0x3c), 3141aa43c215SJeff Kirsher QLCRD32(adapter, QLCNIC_CRB_PEG_NET_3 + 0x3c), 3142aa43c215SJeff Kirsher QLCRD32(adapter, QLCNIC_CRB_PEG_NET_4 + 0x3c)); 3143853d4bcaSAmeen Rahman peg_status = QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS1); 3144853d4bcaSAmeen Rahman if (LSW(MSB(peg_status)) == 0x67) 3145853d4bcaSAmeen Rahman dev_err(&adapter->pdev->dev, 3146853d4bcaSAmeen Rahman "Firmware aborted with error code 0x00006700. " 3147853d4bcaSAmeen Rahman "Device is being reset.\n"); 3148aa43c215SJeff Kirsher detach: 3149aa43c215SJeff Kirsher adapter->dev_state = (state == QLCNIC_DEV_NEED_QUISCENT) ? state : 3150aa43c215SJeff Kirsher QLCNIC_DEV_NEED_RESET; 3151aa43c215SJeff Kirsher 3152aa43c215SJeff Kirsher if (auto_fw_reset && 3153aa43c215SJeff Kirsher !test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) { 3154aa43c215SJeff Kirsher 3155aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_detach_work, 0); 3156aa43c215SJeff Kirsher QLCDB(adapter, DRV, "fw recovery scheduled.\n"); 3157aa43c215SJeff Kirsher } 3158aa43c215SJeff Kirsher 3159aa43c215SJeff Kirsher return 1; 3160aa43c215SJeff Kirsher } 3161aa43c215SJeff Kirsher 3162aa43c215SJeff Kirsher static void 3163aa43c215SJeff Kirsher qlcnic_fw_poll_work(struct work_struct *work) 3164aa43c215SJeff Kirsher { 3165aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = container_of(work, 3166aa43c215SJeff Kirsher struct qlcnic_adapter, fw_work.work); 3167aa43c215SJeff Kirsher 3168aa43c215SJeff Kirsher if (test_bit(__QLCNIC_RESETTING, &adapter->state)) 3169aa43c215SJeff Kirsher goto reschedule; 3170aa43c215SJeff Kirsher 3171aa43c215SJeff Kirsher 3172aa43c215SJeff Kirsher if (qlcnic_check_health(adapter)) 3173aa43c215SJeff Kirsher return; 3174aa43c215SJeff Kirsher 3175aa43c215SJeff Kirsher if (adapter->fhash.fnum) 3176aa43c215SJeff Kirsher qlcnic_prune_lb_filters(adapter); 3177aa43c215SJeff Kirsher 3178aa43c215SJeff Kirsher reschedule: 3179aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY); 3180aa43c215SJeff Kirsher } 3181aa43c215SJeff Kirsher 3182aa43c215SJeff Kirsher static int qlcnic_is_first_func(struct pci_dev *pdev) 3183aa43c215SJeff Kirsher { 3184aa43c215SJeff Kirsher struct pci_dev *oth_pdev; 3185aa43c215SJeff Kirsher int val = pdev->devfn; 3186aa43c215SJeff Kirsher 3187aa43c215SJeff Kirsher while (val-- > 0) { 3188aa43c215SJeff Kirsher oth_pdev = pci_get_domain_bus_and_slot(pci_domain_nr 3189aa43c215SJeff Kirsher (pdev->bus), pdev->bus->number, 3190aa43c215SJeff Kirsher PCI_DEVFN(PCI_SLOT(pdev->devfn), val)); 3191aa43c215SJeff Kirsher if (!oth_pdev) 3192aa43c215SJeff Kirsher continue; 3193aa43c215SJeff Kirsher 3194aa43c215SJeff Kirsher if (oth_pdev->current_state != PCI_D3cold) { 3195aa43c215SJeff Kirsher pci_dev_put(oth_pdev); 3196aa43c215SJeff Kirsher return 0; 3197aa43c215SJeff Kirsher } 3198aa43c215SJeff Kirsher pci_dev_put(oth_pdev); 3199aa43c215SJeff Kirsher } 3200aa43c215SJeff Kirsher return 1; 3201aa43c215SJeff Kirsher } 3202aa43c215SJeff Kirsher 3203aa43c215SJeff Kirsher static int qlcnic_attach_func(struct pci_dev *pdev) 3204aa43c215SJeff Kirsher { 3205aa43c215SJeff Kirsher int err, first_func; 3206aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); 3207aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 3208aa43c215SJeff Kirsher 3209aa43c215SJeff Kirsher pdev->error_state = pci_channel_io_normal; 3210aa43c215SJeff Kirsher 3211aa43c215SJeff Kirsher err = pci_enable_device(pdev); 3212aa43c215SJeff Kirsher if (err) 3213aa43c215SJeff Kirsher return err; 3214aa43c215SJeff Kirsher 3215aa43c215SJeff Kirsher pci_set_power_state(pdev, PCI_D0); 3216aa43c215SJeff Kirsher pci_set_master(pdev); 3217aa43c215SJeff Kirsher pci_restore_state(pdev); 3218aa43c215SJeff Kirsher 3219aa43c215SJeff Kirsher first_func = qlcnic_is_first_func(pdev); 3220aa43c215SJeff Kirsher 3221aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 3222aa43c215SJeff Kirsher return -EINVAL; 3223aa43c215SJeff Kirsher 3224aa43c215SJeff Kirsher if (adapter->op_mode != QLCNIC_NON_PRIV_FUNC && first_func) { 3225aa43c215SJeff Kirsher adapter->need_fw_reset = 1; 3226aa43c215SJeff Kirsher set_bit(__QLCNIC_START_FW, &adapter->state); 3227aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_INITIALIZING); 3228aa43c215SJeff Kirsher QLCDB(adapter, DRV, "Restarting fw\n"); 3229aa43c215SJeff Kirsher } 3230aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 3231aa43c215SJeff Kirsher 3232aa43c215SJeff Kirsher err = adapter->nic_ops->start_firmware(adapter); 3233aa43c215SJeff Kirsher if (err) 3234aa43c215SJeff Kirsher return err; 3235aa43c215SJeff Kirsher 3236aa43c215SJeff Kirsher qlcnic_clr_drv_state(adapter); 3237aa43c215SJeff Kirsher qlcnic_setup_intr(adapter); 3238aa43c215SJeff Kirsher 3239aa43c215SJeff Kirsher if (netif_running(netdev)) { 3240aa43c215SJeff Kirsher err = qlcnic_attach(adapter); 3241aa43c215SJeff Kirsher if (err) { 3242aa43c215SJeff Kirsher qlcnic_clr_all_drv_state(adapter, 1); 3243aa43c215SJeff Kirsher clear_bit(__QLCNIC_AER, &adapter->state); 3244aa43c215SJeff Kirsher netif_device_attach(netdev); 3245aa43c215SJeff Kirsher return err; 3246aa43c215SJeff Kirsher } 3247aa43c215SJeff Kirsher 3248aa43c215SJeff Kirsher err = qlcnic_up(adapter, netdev); 3249aa43c215SJeff Kirsher if (err) 3250aa43c215SJeff Kirsher goto done; 3251aa43c215SJeff Kirsher 3252aa43c215SJeff Kirsher qlcnic_restore_indev_addr(netdev, NETDEV_UP); 3253aa43c215SJeff Kirsher } 3254aa43c215SJeff Kirsher done: 3255aa43c215SJeff Kirsher netif_device_attach(netdev); 3256aa43c215SJeff Kirsher return err; 3257aa43c215SJeff Kirsher } 3258aa43c215SJeff Kirsher 3259aa43c215SJeff Kirsher static pci_ers_result_t qlcnic_io_error_detected(struct pci_dev *pdev, 3260aa43c215SJeff Kirsher pci_channel_state_t state) 3261aa43c215SJeff Kirsher { 3262aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); 3263aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 3264aa43c215SJeff Kirsher 3265aa43c215SJeff Kirsher if (state == pci_channel_io_perm_failure) 3266aa43c215SJeff Kirsher return PCI_ERS_RESULT_DISCONNECT; 3267aa43c215SJeff Kirsher 3268aa43c215SJeff Kirsher if (state == pci_channel_io_normal) 3269aa43c215SJeff Kirsher return PCI_ERS_RESULT_RECOVERED; 3270aa43c215SJeff Kirsher 3271aa43c215SJeff Kirsher set_bit(__QLCNIC_AER, &adapter->state); 3272aa43c215SJeff Kirsher netif_device_detach(netdev); 3273aa43c215SJeff Kirsher 3274aa43c215SJeff Kirsher cancel_delayed_work_sync(&adapter->fw_work); 3275aa43c215SJeff Kirsher 3276aa43c215SJeff Kirsher if (netif_running(netdev)) 3277aa43c215SJeff Kirsher qlcnic_down(adapter, netdev); 3278aa43c215SJeff Kirsher 3279aa43c215SJeff Kirsher qlcnic_detach(adapter); 3280aa43c215SJeff Kirsher qlcnic_teardown_intr(adapter); 3281aa43c215SJeff Kirsher 3282aa43c215SJeff Kirsher clear_bit(__QLCNIC_RESETTING, &adapter->state); 3283aa43c215SJeff Kirsher 3284aa43c215SJeff Kirsher pci_save_state(pdev); 3285aa43c215SJeff Kirsher pci_disable_device(pdev); 3286aa43c215SJeff Kirsher 3287aa43c215SJeff Kirsher return PCI_ERS_RESULT_NEED_RESET; 3288aa43c215SJeff Kirsher } 3289aa43c215SJeff Kirsher 3290aa43c215SJeff Kirsher static pci_ers_result_t qlcnic_io_slot_reset(struct pci_dev *pdev) 3291aa43c215SJeff Kirsher { 3292aa43c215SJeff Kirsher return qlcnic_attach_func(pdev) ? PCI_ERS_RESULT_DISCONNECT : 3293aa43c215SJeff Kirsher PCI_ERS_RESULT_RECOVERED; 3294aa43c215SJeff Kirsher } 3295aa43c215SJeff Kirsher 3296aa43c215SJeff Kirsher static void qlcnic_io_resume(struct pci_dev *pdev) 3297aa43c215SJeff Kirsher { 3298aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); 3299aa43c215SJeff Kirsher 3300aa43c215SJeff Kirsher pci_cleanup_aer_uncorrect_error_status(pdev); 3301aa43c215SJeff Kirsher 3302aa43c215SJeff Kirsher if (QLCRD32(adapter, QLCNIC_CRB_DEV_STATE) == QLCNIC_DEV_READY && 3303aa43c215SJeff Kirsher test_and_clear_bit(__QLCNIC_AER, &adapter->state)) 3304aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, 3305aa43c215SJeff Kirsher FW_POLL_DELAY); 3306aa43c215SJeff Kirsher } 3307aa43c215SJeff Kirsher 3308aa43c215SJeff Kirsher static int 3309aa43c215SJeff Kirsher qlcnicvf_start_firmware(struct qlcnic_adapter *adapter) 3310aa43c215SJeff Kirsher { 3311aa43c215SJeff Kirsher int err; 3312aa43c215SJeff Kirsher 3313aa43c215SJeff Kirsher err = qlcnic_can_start_firmware(adapter); 3314aa43c215SJeff Kirsher if (err) 3315aa43c215SJeff Kirsher return err; 3316aa43c215SJeff Kirsher 3317aa43c215SJeff Kirsher err = qlcnic_check_npar_opertional(adapter); 3318aa43c215SJeff Kirsher if (err) 3319aa43c215SJeff Kirsher return err; 3320aa43c215SJeff Kirsher 3321aa43c215SJeff Kirsher err = qlcnic_initialize_nic(adapter); 3322aa43c215SJeff Kirsher if (err) 3323aa43c215SJeff Kirsher return err; 3324aa43c215SJeff Kirsher 3325aa43c215SJeff Kirsher qlcnic_check_options(adapter); 3326aa43c215SJeff Kirsher 3327aa43c215SJeff Kirsher err = qlcnic_set_eswitch_port_config(adapter); 3328aa43c215SJeff Kirsher if (err) 3329aa43c215SJeff Kirsher return err; 3330aa43c215SJeff Kirsher 3331aa43c215SJeff Kirsher adapter->need_fw_reset = 0; 3332aa43c215SJeff Kirsher 3333aa43c215SJeff Kirsher return err; 3334aa43c215SJeff Kirsher } 3335aa43c215SJeff Kirsher 3336aa43c215SJeff Kirsher static int 3337aa43c215SJeff Kirsher qlcnicvf_config_bridged_mode(struct qlcnic_adapter *adapter, u32 enable) 3338aa43c215SJeff Kirsher { 3339aa43c215SJeff Kirsher return -EOPNOTSUPP; 3340aa43c215SJeff Kirsher } 3341aa43c215SJeff Kirsher 3342aa43c215SJeff Kirsher static int 3343aa43c215SJeff Kirsher qlcnicvf_config_led(struct qlcnic_adapter *adapter, u32 state, u32 rate) 3344aa43c215SJeff Kirsher { 3345aa43c215SJeff Kirsher return -EOPNOTSUPP; 3346aa43c215SJeff Kirsher } 3347aa43c215SJeff Kirsher 3348aa43c215SJeff Kirsher static ssize_t 3349aa43c215SJeff Kirsher qlcnic_store_bridged_mode(struct device *dev, 3350aa43c215SJeff Kirsher struct device_attribute *attr, const char *buf, size_t len) 3351aa43c215SJeff Kirsher { 3352aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3353aa43c215SJeff Kirsher unsigned long new; 3354aa43c215SJeff Kirsher int ret = -EINVAL; 3355aa43c215SJeff Kirsher 3356aa43c215SJeff Kirsher if (!(adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG)) 3357aa43c215SJeff Kirsher goto err_out; 3358aa43c215SJeff Kirsher 3359aa43c215SJeff Kirsher if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) 3360aa43c215SJeff Kirsher goto err_out; 3361aa43c215SJeff Kirsher 3362aa43c215SJeff Kirsher if (strict_strtoul(buf, 2, &new)) 3363aa43c215SJeff Kirsher goto err_out; 3364aa43c215SJeff Kirsher 3365aa43c215SJeff Kirsher if (!adapter->nic_ops->config_bridged_mode(adapter, !!new)) 3366aa43c215SJeff Kirsher ret = len; 3367aa43c215SJeff Kirsher 3368aa43c215SJeff Kirsher err_out: 3369aa43c215SJeff Kirsher return ret; 3370aa43c215SJeff Kirsher } 3371aa43c215SJeff Kirsher 3372aa43c215SJeff Kirsher static ssize_t 3373aa43c215SJeff Kirsher qlcnic_show_bridged_mode(struct device *dev, 3374aa43c215SJeff Kirsher struct device_attribute *attr, char *buf) 3375aa43c215SJeff Kirsher { 3376aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3377aa43c215SJeff Kirsher int bridged_mode = 0; 3378aa43c215SJeff Kirsher 3379aa43c215SJeff Kirsher if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG) 3380aa43c215SJeff Kirsher bridged_mode = !!(adapter->flags & QLCNIC_BRIDGE_ENABLED); 3381aa43c215SJeff Kirsher 3382aa43c215SJeff Kirsher return sprintf(buf, "%d\n", bridged_mode); 3383aa43c215SJeff Kirsher } 3384aa43c215SJeff Kirsher 3385aa43c215SJeff Kirsher static struct device_attribute dev_attr_bridged_mode = { 3386aa43c215SJeff Kirsher .attr = {.name = "bridged_mode", .mode = (S_IRUGO | S_IWUSR)}, 3387aa43c215SJeff Kirsher .show = qlcnic_show_bridged_mode, 3388aa43c215SJeff Kirsher .store = qlcnic_store_bridged_mode, 3389aa43c215SJeff Kirsher }; 3390aa43c215SJeff Kirsher 3391aa43c215SJeff Kirsher static ssize_t 3392aa43c215SJeff Kirsher qlcnic_store_diag_mode(struct device *dev, 3393aa43c215SJeff Kirsher struct device_attribute *attr, const char *buf, size_t len) 3394aa43c215SJeff Kirsher { 3395aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3396aa43c215SJeff Kirsher unsigned long new; 3397aa43c215SJeff Kirsher 3398aa43c215SJeff Kirsher if (strict_strtoul(buf, 2, &new)) 3399aa43c215SJeff Kirsher return -EINVAL; 3400aa43c215SJeff Kirsher 3401aa43c215SJeff Kirsher if (!!new != !!(adapter->flags & QLCNIC_DIAG_ENABLED)) 3402aa43c215SJeff Kirsher adapter->flags ^= QLCNIC_DIAG_ENABLED; 3403aa43c215SJeff Kirsher 3404aa43c215SJeff Kirsher return len; 3405aa43c215SJeff Kirsher } 3406aa43c215SJeff Kirsher 3407aa43c215SJeff Kirsher static ssize_t 3408aa43c215SJeff Kirsher qlcnic_show_diag_mode(struct device *dev, 3409aa43c215SJeff Kirsher struct device_attribute *attr, char *buf) 3410aa43c215SJeff Kirsher { 3411aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3412aa43c215SJeff Kirsher 3413aa43c215SJeff Kirsher return sprintf(buf, "%d\n", 3414aa43c215SJeff Kirsher !!(adapter->flags & QLCNIC_DIAG_ENABLED)); 3415aa43c215SJeff Kirsher } 3416aa43c215SJeff Kirsher 3417aa43c215SJeff Kirsher static struct device_attribute dev_attr_diag_mode = { 3418aa43c215SJeff Kirsher .attr = {.name = "diag_mode", .mode = (S_IRUGO | S_IWUSR)}, 3419aa43c215SJeff Kirsher .show = qlcnic_show_diag_mode, 3420aa43c215SJeff Kirsher .store = qlcnic_store_diag_mode, 3421aa43c215SJeff Kirsher }; 3422aa43c215SJeff Kirsher 3423aa43c215SJeff Kirsher int qlcnic_validate_max_rss(struct net_device *netdev, u8 max_hw, u8 val) 3424aa43c215SJeff Kirsher { 3425aa43c215SJeff Kirsher if (!use_msi_x && !use_msi) { 3426aa43c215SJeff Kirsher netdev_info(netdev, "no msix or msi support, hence no rss\n"); 3427aa43c215SJeff Kirsher return -EINVAL; 3428aa43c215SJeff Kirsher } 3429aa43c215SJeff Kirsher 3430aa43c215SJeff Kirsher if ((val > max_hw) || (val < 2) || !is_power_of_2(val)) { 3431aa43c215SJeff Kirsher netdev_info(netdev, "rss_ring valid range [2 - %x] in " 3432aa43c215SJeff Kirsher " powers of 2\n", max_hw); 3433aa43c215SJeff Kirsher return -EINVAL; 3434aa43c215SJeff Kirsher } 3435aa43c215SJeff Kirsher return 0; 3436aa43c215SJeff Kirsher 3437aa43c215SJeff Kirsher } 3438aa43c215SJeff Kirsher 3439aa43c215SJeff Kirsher int qlcnic_set_max_rss(struct qlcnic_adapter *adapter, u8 data) 3440aa43c215SJeff Kirsher { 3441aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 3442aa43c215SJeff Kirsher int err = 0; 3443aa43c215SJeff Kirsher 3444aa43c215SJeff Kirsher if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) 3445aa43c215SJeff Kirsher return -EBUSY; 3446aa43c215SJeff Kirsher 3447aa43c215SJeff Kirsher netif_device_detach(netdev); 3448aa43c215SJeff Kirsher if (netif_running(netdev)) 3449aa43c215SJeff Kirsher __qlcnic_down(adapter, netdev); 3450aa43c215SJeff Kirsher qlcnic_detach(adapter); 3451aa43c215SJeff Kirsher qlcnic_teardown_intr(adapter); 3452aa43c215SJeff Kirsher 3453aa43c215SJeff Kirsher if (qlcnic_enable_msix(adapter, data)) { 3454aa43c215SJeff Kirsher netdev_info(netdev, "failed setting max_rss; rss disabled\n"); 3455aa43c215SJeff Kirsher qlcnic_enable_msi_legacy(adapter); 3456aa43c215SJeff Kirsher } 3457aa43c215SJeff Kirsher 3458aa43c215SJeff Kirsher if (netif_running(netdev)) { 3459aa43c215SJeff Kirsher err = qlcnic_attach(adapter); 3460aa43c215SJeff Kirsher if (err) 3461aa43c215SJeff Kirsher goto done; 3462aa43c215SJeff Kirsher err = __qlcnic_up(adapter, netdev); 3463aa43c215SJeff Kirsher if (err) 3464aa43c215SJeff Kirsher goto done; 3465aa43c215SJeff Kirsher qlcnic_restore_indev_addr(netdev, NETDEV_UP); 3466aa43c215SJeff Kirsher } 3467aa43c215SJeff Kirsher done: 3468aa43c215SJeff Kirsher netif_device_attach(netdev); 3469aa43c215SJeff Kirsher clear_bit(__QLCNIC_RESETTING, &adapter->state); 3470aa43c215SJeff Kirsher return err; 3471aa43c215SJeff Kirsher } 3472aa43c215SJeff Kirsher 3473aa43c215SJeff Kirsher static int 3474728a98b8SSucheta Chakraborty qlcnic_validate_beacon(struct qlcnic_adapter *adapter, u16 beacon, u8 *state, 3475728a98b8SSucheta Chakraborty u8 *rate) 3476728a98b8SSucheta Chakraborty { 3477728a98b8SSucheta Chakraborty *rate = LSB(beacon); 3478728a98b8SSucheta Chakraborty *state = MSB(beacon); 3479728a98b8SSucheta Chakraborty 3480728a98b8SSucheta Chakraborty QLCDB(adapter, DRV, "rate %x state %x\n", *rate, *state); 3481728a98b8SSucheta Chakraborty 3482728a98b8SSucheta Chakraborty if (!*state) { 3483728a98b8SSucheta Chakraborty *rate = __QLCNIC_MAX_LED_RATE; 3484728a98b8SSucheta Chakraborty return 0; 3485728a98b8SSucheta Chakraborty } else if (*state > __QLCNIC_MAX_LED_STATE) 3486728a98b8SSucheta Chakraborty return -EINVAL; 3487728a98b8SSucheta Chakraborty 3488728a98b8SSucheta Chakraborty if ((!*rate) || (*rate > __QLCNIC_MAX_LED_RATE)) 3489728a98b8SSucheta Chakraborty return -EINVAL; 3490728a98b8SSucheta Chakraborty 3491728a98b8SSucheta Chakraborty return 0; 3492728a98b8SSucheta Chakraborty } 3493728a98b8SSucheta Chakraborty 3494728a98b8SSucheta Chakraborty static ssize_t 3495728a98b8SSucheta Chakraborty qlcnic_store_beacon(struct device *dev, 3496728a98b8SSucheta Chakraborty struct device_attribute *attr, const char *buf, size_t len) 3497728a98b8SSucheta Chakraborty { 3498728a98b8SSucheta Chakraborty struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3499728a98b8SSucheta Chakraborty int max_sds_rings = adapter->max_sds_rings; 3500728a98b8SSucheta Chakraborty int dev_down = 0; 3501728a98b8SSucheta Chakraborty u16 beacon; 3502728a98b8SSucheta Chakraborty u8 b_state, b_rate; 3503728a98b8SSucheta Chakraborty int err; 3504728a98b8SSucheta Chakraborty 3505728a98b8SSucheta Chakraborty if (len != sizeof(u16)) 3506728a98b8SSucheta Chakraborty return QL_STATUS_INVALID_PARAM; 3507728a98b8SSucheta Chakraborty 3508728a98b8SSucheta Chakraborty memcpy(&beacon, buf, sizeof(u16)); 3509728a98b8SSucheta Chakraborty err = qlcnic_validate_beacon(adapter, beacon, &b_state, &b_rate); 3510728a98b8SSucheta Chakraborty if (err) 3511728a98b8SSucheta Chakraborty return err; 3512728a98b8SSucheta Chakraborty 3513728a98b8SSucheta Chakraborty if (adapter->ahw->beacon_state == b_state) 3514728a98b8SSucheta Chakraborty return len; 3515728a98b8SSucheta Chakraborty 3516728a98b8SSucheta Chakraborty if (!adapter->ahw->beacon_state) 3517728a98b8SSucheta Chakraborty if (test_and_set_bit(__QLCNIC_LED_ENABLE, &adapter->state)) 3518728a98b8SSucheta Chakraborty return -EBUSY; 3519728a98b8SSucheta Chakraborty 3520728a98b8SSucheta Chakraborty if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) { 3521728a98b8SSucheta Chakraborty if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) 3522728a98b8SSucheta Chakraborty return -EIO; 3523728a98b8SSucheta Chakraborty err = qlcnic_diag_alloc_res(adapter->netdev, QLCNIC_LED_TEST); 3524728a98b8SSucheta Chakraborty if (err) { 3525728a98b8SSucheta Chakraborty clear_bit(__QLCNIC_RESETTING, &adapter->state); 3526728a98b8SSucheta Chakraborty clear_bit(__QLCNIC_LED_ENABLE, &adapter->state); 3527728a98b8SSucheta Chakraborty return err; 3528728a98b8SSucheta Chakraborty } 3529728a98b8SSucheta Chakraborty dev_down = 1; 3530728a98b8SSucheta Chakraborty } 3531728a98b8SSucheta Chakraborty 3532728a98b8SSucheta Chakraborty err = qlcnic_config_led(adapter, b_state, b_rate); 3533728a98b8SSucheta Chakraborty 3534728a98b8SSucheta Chakraborty if (!err) { 3535728a98b8SSucheta Chakraborty adapter->ahw->beacon_state = b_state; 3536728a98b8SSucheta Chakraborty err = len; 3537728a98b8SSucheta Chakraborty } 3538728a98b8SSucheta Chakraborty 3539728a98b8SSucheta Chakraborty if (dev_down) { 3540728a98b8SSucheta Chakraborty qlcnic_diag_free_res(adapter->netdev, max_sds_rings); 3541728a98b8SSucheta Chakraborty clear_bit(__QLCNIC_RESETTING, &adapter->state); 3542728a98b8SSucheta Chakraborty } 3543728a98b8SSucheta Chakraborty 3544728a98b8SSucheta Chakraborty if (!b_state) 3545728a98b8SSucheta Chakraborty clear_bit(__QLCNIC_LED_ENABLE, &adapter->state); 3546728a98b8SSucheta Chakraborty 3547728a98b8SSucheta Chakraborty return err; 3548728a98b8SSucheta Chakraborty } 3549728a98b8SSucheta Chakraborty 3550728a98b8SSucheta Chakraborty static ssize_t 3551728a98b8SSucheta Chakraborty qlcnic_show_beacon(struct device *dev, 3552728a98b8SSucheta Chakraborty struct device_attribute *attr, char *buf) 3553728a98b8SSucheta Chakraborty { 3554728a98b8SSucheta Chakraborty struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3555728a98b8SSucheta Chakraborty 3556728a98b8SSucheta Chakraborty return sprintf(buf, "%d\n", adapter->ahw->beacon_state); 3557728a98b8SSucheta Chakraborty } 3558728a98b8SSucheta Chakraborty 3559728a98b8SSucheta Chakraborty static struct device_attribute dev_attr_beacon = { 3560728a98b8SSucheta Chakraborty .attr = {.name = "beacon", .mode = (S_IRUGO | S_IWUSR)}, 3561728a98b8SSucheta Chakraborty .show = qlcnic_show_beacon, 3562728a98b8SSucheta Chakraborty .store = qlcnic_store_beacon, 3563728a98b8SSucheta Chakraborty }; 3564728a98b8SSucheta Chakraborty 3565728a98b8SSucheta Chakraborty static int 3566aa43c215SJeff Kirsher qlcnic_sysfs_validate_crb(struct qlcnic_adapter *adapter, 3567aa43c215SJeff Kirsher loff_t offset, size_t size) 3568aa43c215SJeff Kirsher { 3569aa43c215SJeff Kirsher size_t crb_size = 4; 3570aa43c215SJeff Kirsher 3571aa43c215SJeff Kirsher if (!(adapter->flags & QLCNIC_DIAG_ENABLED)) 3572aa43c215SJeff Kirsher return -EIO; 3573aa43c215SJeff Kirsher 3574aa43c215SJeff Kirsher if (offset < QLCNIC_PCI_CRBSPACE) { 3575aa43c215SJeff Kirsher if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM, 3576aa43c215SJeff Kirsher QLCNIC_PCI_CAMQM_END)) 3577aa43c215SJeff Kirsher crb_size = 8; 3578aa43c215SJeff Kirsher else 3579aa43c215SJeff Kirsher return -EINVAL; 3580aa43c215SJeff Kirsher } 3581aa43c215SJeff Kirsher 3582aa43c215SJeff Kirsher if ((size != crb_size) || (offset & (crb_size-1))) 3583aa43c215SJeff Kirsher return -EINVAL; 3584aa43c215SJeff Kirsher 3585aa43c215SJeff Kirsher return 0; 3586aa43c215SJeff Kirsher } 3587aa43c215SJeff Kirsher 3588aa43c215SJeff Kirsher static ssize_t 3589aa43c215SJeff Kirsher qlcnic_sysfs_read_crb(struct file *filp, struct kobject *kobj, 3590aa43c215SJeff Kirsher struct bin_attribute *attr, 3591aa43c215SJeff Kirsher char *buf, loff_t offset, size_t size) 3592aa43c215SJeff Kirsher { 3593aa43c215SJeff Kirsher struct device *dev = container_of(kobj, struct device, kobj); 3594aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3595aa43c215SJeff Kirsher u32 data; 3596aa43c215SJeff Kirsher u64 qmdata; 3597aa43c215SJeff Kirsher int ret; 3598aa43c215SJeff Kirsher 3599aa43c215SJeff Kirsher ret = qlcnic_sysfs_validate_crb(adapter, offset, size); 3600aa43c215SJeff Kirsher if (ret != 0) 3601aa43c215SJeff Kirsher return ret; 3602aa43c215SJeff Kirsher 3603aa43c215SJeff Kirsher if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM, QLCNIC_PCI_CAMQM_END)) { 3604aa43c215SJeff Kirsher qlcnic_pci_camqm_read_2M(adapter, offset, &qmdata); 3605aa43c215SJeff Kirsher memcpy(buf, &qmdata, size); 3606aa43c215SJeff Kirsher } else { 3607aa43c215SJeff Kirsher data = QLCRD32(adapter, offset); 3608aa43c215SJeff Kirsher memcpy(buf, &data, size); 3609aa43c215SJeff Kirsher } 3610aa43c215SJeff Kirsher return size; 3611aa43c215SJeff Kirsher } 3612aa43c215SJeff Kirsher 3613aa43c215SJeff Kirsher static ssize_t 3614aa43c215SJeff Kirsher qlcnic_sysfs_write_crb(struct file *filp, struct kobject *kobj, 3615aa43c215SJeff Kirsher struct bin_attribute *attr, 3616aa43c215SJeff Kirsher char *buf, loff_t offset, size_t size) 3617aa43c215SJeff Kirsher { 3618aa43c215SJeff Kirsher struct device *dev = container_of(kobj, struct device, kobj); 3619aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3620aa43c215SJeff Kirsher u32 data; 3621aa43c215SJeff Kirsher u64 qmdata; 3622aa43c215SJeff Kirsher int ret; 3623aa43c215SJeff Kirsher 3624aa43c215SJeff Kirsher ret = qlcnic_sysfs_validate_crb(adapter, offset, size); 3625aa43c215SJeff Kirsher if (ret != 0) 3626aa43c215SJeff Kirsher return ret; 3627aa43c215SJeff Kirsher 3628aa43c215SJeff Kirsher if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM, QLCNIC_PCI_CAMQM_END)) { 3629aa43c215SJeff Kirsher memcpy(&qmdata, buf, size); 3630aa43c215SJeff Kirsher qlcnic_pci_camqm_write_2M(adapter, offset, qmdata); 3631aa43c215SJeff Kirsher } else { 3632aa43c215SJeff Kirsher memcpy(&data, buf, size); 3633aa43c215SJeff Kirsher QLCWR32(adapter, offset, data); 3634aa43c215SJeff Kirsher } 3635aa43c215SJeff Kirsher return size; 3636aa43c215SJeff Kirsher } 3637aa43c215SJeff Kirsher 3638aa43c215SJeff Kirsher static int 3639aa43c215SJeff Kirsher qlcnic_sysfs_validate_mem(struct qlcnic_adapter *adapter, 3640aa43c215SJeff Kirsher loff_t offset, size_t size) 3641aa43c215SJeff Kirsher { 3642aa43c215SJeff Kirsher if (!(adapter->flags & QLCNIC_DIAG_ENABLED)) 3643aa43c215SJeff Kirsher return -EIO; 3644aa43c215SJeff Kirsher 3645aa43c215SJeff Kirsher if ((size != 8) || (offset & 0x7)) 3646aa43c215SJeff Kirsher return -EIO; 3647aa43c215SJeff Kirsher 3648aa43c215SJeff Kirsher return 0; 3649aa43c215SJeff Kirsher } 3650aa43c215SJeff Kirsher 3651aa43c215SJeff Kirsher static ssize_t 3652aa43c215SJeff Kirsher qlcnic_sysfs_read_mem(struct file *filp, struct kobject *kobj, 3653aa43c215SJeff Kirsher struct bin_attribute *attr, 3654aa43c215SJeff Kirsher char *buf, loff_t offset, size_t size) 3655aa43c215SJeff Kirsher { 3656aa43c215SJeff Kirsher struct device *dev = container_of(kobj, struct device, kobj); 3657aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3658aa43c215SJeff Kirsher u64 data; 3659aa43c215SJeff Kirsher int ret; 3660aa43c215SJeff Kirsher 3661aa43c215SJeff Kirsher ret = qlcnic_sysfs_validate_mem(adapter, offset, size); 3662aa43c215SJeff Kirsher if (ret != 0) 3663aa43c215SJeff Kirsher return ret; 3664aa43c215SJeff Kirsher 3665aa43c215SJeff Kirsher if (qlcnic_pci_mem_read_2M(adapter, offset, &data)) 3666aa43c215SJeff Kirsher return -EIO; 3667aa43c215SJeff Kirsher 3668aa43c215SJeff Kirsher memcpy(buf, &data, size); 3669aa43c215SJeff Kirsher 3670aa43c215SJeff Kirsher return size; 3671aa43c215SJeff Kirsher } 3672aa43c215SJeff Kirsher 3673aa43c215SJeff Kirsher static ssize_t 3674aa43c215SJeff Kirsher qlcnic_sysfs_write_mem(struct file *filp, struct kobject *kobj, 3675aa43c215SJeff Kirsher struct bin_attribute *attr, 3676aa43c215SJeff Kirsher char *buf, loff_t offset, size_t size) 3677aa43c215SJeff Kirsher { 3678aa43c215SJeff Kirsher struct device *dev = container_of(kobj, struct device, kobj); 3679aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3680aa43c215SJeff Kirsher u64 data; 3681aa43c215SJeff Kirsher int ret; 3682aa43c215SJeff Kirsher 3683aa43c215SJeff Kirsher ret = qlcnic_sysfs_validate_mem(adapter, offset, size); 3684aa43c215SJeff Kirsher if (ret != 0) 3685aa43c215SJeff Kirsher return ret; 3686aa43c215SJeff Kirsher 3687aa43c215SJeff Kirsher memcpy(&data, buf, size); 3688aa43c215SJeff Kirsher 3689aa43c215SJeff Kirsher if (qlcnic_pci_mem_write_2M(adapter, offset, data)) 3690aa43c215SJeff Kirsher return -EIO; 3691aa43c215SJeff Kirsher 3692aa43c215SJeff Kirsher return size; 3693aa43c215SJeff Kirsher } 3694aa43c215SJeff Kirsher 3695aa43c215SJeff Kirsher static struct bin_attribute bin_attr_crb = { 3696aa43c215SJeff Kirsher .attr = {.name = "crb", .mode = (S_IRUGO | S_IWUSR)}, 3697aa43c215SJeff Kirsher .size = 0, 3698aa43c215SJeff Kirsher .read = qlcnic_sysfs_read_crb, 3699aa43c215SJeff Kirsher .write = qlcnic_sysfs_write_crb, 3700aa43c215SJeff Kirsher }; 3701aa43c215SJeff Kirsher 3702aa43c215SJeff Kirsher static struct bin_attribute bin_attr_mem = { 3703aa43c215SJeff Kirsher .attr = {.name = "mem", .mode = (S_IRUGO | S_IWUSR)}, 3704aa43c215SJeff Kirsher .size = 0, 3705aa43c215SJeff Kirsher .read = qlcnic_sysfs_read_mem, 3706aa43c215SJeff Kirsher .write = qlcnic_sysfs_write_mem, 3707aa43c215SJeff Kirsher }; 3708aa43c215SJeff Kirsher 3709aa43c215SJeff Kirsher static int 3710aa43c215SJeff Kirsher validate_pm_config(struct qlcnic_adapter *adapter, 3711aa43c215SJeff Kirsher struct qlcnic_pm_func_cfg *pm_cfg, int count) 3712aa43c215SJeff Kirsher { 3713aa43c215SJeff Kirsher 3714aa43c215SJeff Kirsher u8 src_pci_func, s_esw_id, d_esw_id; 3715aa43c215SJeff Kirsher u8 dest_pci_func; 3716aa43c215SJeff Kirsher int i; 3717aa43c215SJeff Kirsher 3718aa43c215SJeff Kirsher for (i = 0; i < count; i++) { 3719aa43c215SJeff Kirsher src_pci_func = pm_cfg[i].pci_func; 3720aa43c215SJeff Kirsher dest_pci_func = pm_cfg[i].dest_npar; 3721aa43c215SJeff Kirsher if (src_pci_func >= QLCNIC_MAX_PCI_FUNC 3722aa43c215SJeff Kirsher || dest_pci_func >= QLCNIC_MAX_PCI_FUNC) 3723aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3724aa43c215SJeff Kirsher 3725aa43c215SJeff Kirsher if (adapter->npars[src_pci_func].type != QLCNIC_TYPE_NIC) 3726aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3727aa43c215SJeff Kirsher 3728aa43c215SJeff Kirsher if (adapter->npars[dest_pci_func].type != QLCNIC_TYPE_NIC) 3729aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3730aa43c215SJeff Kirsher 3731aa43c215SJeff Kirsher s_esw_id = adapter->npars[src_pci_func].phy_port; 3732aa43c215SJeff Kirsher d_esw_id = adapter->npars[dest_pci_func].phy_port; 3733aa43c215SJeff Kirsher 3734aa43c215SJeff Kirsher if (s_esw_id != d_esw_id) 3735aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3736aa43c215SJeff Kirsher 3737aa43c215SJeff Kirsher } 3738aa43c215SJeff Kirsher return 0; 3739aa43c215SJeff Kirsher 3740aa43c215SJeff Kirsher } 3741aa43c215SJeff Kirsher 3742aa43c215SJeff Kirsher static ssize_t 3743aa43c215SJeff Kirsher qlcnic_sysfs_write_pm_config(struct file *filp, struct kobject *kobj, 3744aa43c215SJeff Kirsher struct bin_attribute *attr, char *buf, loff_t offset, size_t size) 3745aa43c215SJeff Kirsher { 3746aa43c215SJeff Kirsher struct device *dev = container_of(kobj, struct device, kobj); 3747aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3748aa43c215SJeff Kirsher struct qlcnic_pm_func_cfg *pm_cfg; 3749aa43c215SJeff Kirsher u32 id, action, pci_func; 3750aa43c215SJeff Kirsher int count, rem, i, ret; 3751aa43c215SJeff Kirsher 3752aa43c215SJeff Kirsher count = size / sizeof(struct qlcnic_pm_func_cfg); 3753aa43c215SJeff Kirsher rem = size % sizeof(struct qlcnic_pm_func_cfg); 3754aa43c215SJeff Kirsher if (rem) 3755aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3756aa43c215SJeff Kirsher 3757aa43c215SJeff Kirsher pm_cfg = (struct qlcnic_pm_func_cfg *) buf; 3758aa43c215SJeff Kirsher 3759aa43c215SJeff Kirsher ret = validate_pm_config(adapter, pm_cfg, count); 3760aa43c215SJeff Kirsher if (ret) 3761aa43c215SJeff Kirsher return ret; 3762aa43c215SJeff Kirsher for (i = 0; i < count; i++) { 3763aa43c215SJeff Kirsher pci_func = pm_cfg[i].pci_func; 3764aa43c215SJeff Kirsher action = !!pm_cfg[i].action; 3765aa43c215SJeff Kirsher id = adapter->npars[pci_func].phy_port; 3766aa43c215SJeff Kirsher ret = qlcnic_config_port_mirroring(adapter, id, 3767aa43c215SJeff Kirsher action, pci_func); 3768aa43c215SJeff Kirsher if (ret) 3769aa43c215SJeff Kirsher return ret; 3770aa43c215SJeff Kirsher } 3771aa43c215SJeff Kirsher 3772aa43c215SJeff Kirsher for (i = 0; i < count; i++) { 3773aa43c215SJeff Kirsher pci_func = pm_cfg[i].pci_func; 3774aa43c215SJeff Kirsher id = adapter->npars[pci_func].phy_port; 3775aa43c215SJeff Kirsher adapter->npars[pci_func].enable_pm = !!pm_cfg[i].action; 3776aa43c215SJeff Kirsher adapter->npars[pci_func].dest_npar = id; 3777aa43c215SJeff Kirsher } 3778aa43c215SJeff Kirsher return size; 3779aa43c215SJeff Kirsher } 3780aa43c215SJeff Kirsher 3781aa43c215SJeff Kirsher static ssize_t 3782aa43c215SJeff Kirsher qlcnic_sysfs_read_pm_config(struct file *filp, struct kobject *kobj, 3783aa43c215SJeff Kirsher struct bin_attribute *attr, char *buf, loff_t offset, size_t size) 3784aa43c215SJeff Kirsher { 3785aa43c215SJeff Kirsher struct device *dev = container_of(kobj, struct device, kobj); 3786aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3787aa43c215SJeff Kirsher struct qlcnic_pm_func_cfg pm_cfg[QLCNIC_MAX_PCI_FUNC]; 3788aa43c215SJeff Kirsher int i; 3789aa43c215SJeff Kirsher 3790aa43c215SJeff Kirsher if (size != sizeof(pm_cfg)) 3791aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3792aa43c215SJeff Kirsher 3793aa43c215SJeff Kirsher for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { 3794aa43c215SJeff Kirsher if (adapter->npars[i].type != QLCNIC_TYPE_NIC) 3795aa43c215SJeff Kirsher continue; 3796aa43c215SJeff Kirsher pm_cfg[i].action = adapter->npars[i].enable_pm; 3797aa43c215SJeff Kirsher pm_cfg[i].dest_npar = 0; 3798aa43c215SJeff Kirsher pm_cfg[i].pci_func = i; 3799aa43c215SJeff Kirsher } 3800aa43c215SJeff Kirsher memcpy(buf, &pm_cfg, size); 3801aa43c215SJeff Kirsher 3802aa43c215SJeff Kirsher return size; 3803aa43c215SJeff Kirsher } 3804aa43c215SJeff Kirsher 3805aa43c215SJeff Kirsher static int 3806aa43c215SJeff Kirsher validate_esw_config(struct qlcnic_adapter *adapter, 3807aa43c215SJeff Kirsher struct qlcnic_esw_func_cfg *esw_cfg, int count) 3808aa43c215SJeff Kirsher { 3809aa43c215SJeff Kirsher u32 op_mode; 3810aa43c215SJeff Kirsher u8 pci_func; 3811aa43c215SJeff Kirsher int i; 3812aa43c215SJeff Kirsher 3813aa43c215SJeff Kirsher op_mode = readl(adapter->ahw->pci_base0 + QLCNIC_DRV_OP_MODE); 3814aa43c215SJeff Kirsher 3815aa43c215SJeff Kirsher for (i = 0; i < count; i++) { 3816aa43c215SJeff Kirsher pci_func = esw_cfg[i].pci_func; 3817aa43c215SJeff Kirsher if (pci_func >= QLCNIC_MAX_PCI_FUNC) 3818aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3819aa43c215SJeff Kirsher 3820aa43c215SJeff Kirsher if (adapter->op_mode == QLCNIC_MGMT_FUNC) 3821aa43c215SJeff Kirsher if (adapter->npars[pci_func].type != QLCNIC_TYPE_NIC) 3822aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3823aa43c215SJeff Kirsher 3824aa43c215SJeff Kirsher switch (esw_cfg[i].op_mode) { 3825aa43c215SJeff Kirsher case QLCNIC_PORT_DEFAULTS: 3826aa43c215SJeff Kirsher if (QLC_DEV_GET_DRV(op_mode, pci_func) != 3827aa43c215SJeff Kirsher QLCNIC_NON_PRIV_FUNC) { 3828aa43c215SJeff Kirsher if (esw_cfg[i].mac_anti_spoof != 0) 3829aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3830aa43c215SJeff Kirsher if (esw_cfg[i].mac_override != 1) 3831aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3832aa43c215SJeff Kirsher if (esw_cfg[i].promisc_mode != 1) 3833aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3834aa43c215SJeff Kirsher } 3835aa43c215SJeff Kirsher break; 3836aa43c215SJeff Kirsher case QLCNIC_ADD_VLAN: 3837aa43c215SJeff Kirsher if (!IS_VALID_VLAN(esw_cfg[i].vlan_id)) 3838aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3839aa43c215SJeff Kirsher if (!esw_cfg[i].op_type) 3840aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3841aa43c215SJeff Kirsher break; 3842aa43c215SJeff Kirsher case QLCNIC_DEL_VLAN: 3843aa43c215SJeff Kirsher if (!esw_cfg[i].op_type) 3844aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3845aa43c215SJeff Kirsher break; 3846aa43c215SJeff Kirsher default: 3847aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3848aa43c215SJeff Kirsher } 3849aa43c215SJeff Kirsher } 3850aa43c215SJeff Kirsher return 0; 3851aa43c215SJeff Kirsher } 3852aa43c215SJeff Kirsher 3853aa43c215SJeff Kirsher static ssize_t 3854aa43c215SJeff Kirsher qlcnic_sysfs_write_esw_config(struct file *file, struct kobject *kobj, 3855aa43c215SJeff Kirsher struct bin_attribute *attr, char *buf, loff_t offset, size_t size) 3856aa43c215SJeff Kirsher { 3857aa43c215SJeff Kirsher struct device *dev = container_of(kobj, struct device, kobj); 3858aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3859aa43c215SJeff Kirsher struct qlcnic_esw_func_cfg *esw_cfg; 3860aa43c215SJeff Kirsher struct qlcnic_npar_info *npar; 3861aa43c215SJeff Kirsher int count, rem, i, ret; 3862aa43c215SJeff Kirsher u8 pci_func, op_mode = 0; 3863aa43c215SJeff Kirsher 3864aa43c215SJeff Kirsher count = size / sizeof(struct qlcnic_esw_func_cfg); 3865aa43c215SJeff Kirsher rem = size % sizeof(struct qlcnic_esw_func_cfg); 3866aa43c215SJeff Kirsher if (rem) 3867aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3868aa43c215SJeff Kirsher 3869aa43c215SJeff Kirsher esw_cfg = (struct qlcnic_esw_func_cfg *) buf; 3870aa43c215SJeff Kirsher ret = validate_esw_config(adapter, esw_cfg, count); 3871aa43c215SJeff Kirsher if (ret) 3872aa43c215SJeff Kirsher return ret; 3873aa43c215SJeff Kirsher 3874aa43c215SJeff Kirsher for (i = 0; i < count; i++) { 3875aa43c215SJeff Kirsher if (adapter->op_mode == QLCNIC_MGMT_FUNC) 3876aa43c215SJeff Kirsher if (qlcnic_config_switch_port(adapter, &esw_cfg[i])) 3877aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3878aa43c215SJeff Kirsher 3879aa43c215SJeff Kirsher if (adapter->ahw->pci_func != esw_cfg[i].pci_func) 3880aa43c215SJeff Kirsher continue; 3881aa43c215SJeff Kirsher 3882aa43c215SJeff Kirsher op_mode = esw_cfg[i].op_mode; 3883aa43c215SJeff Kirsher qlcnic_get_eswitch_port_config(adapter, &esw_cfg[i]); 3884aa43c215SJeff Kirsher esw_cfg[i].op_mode = op_mode; 3885aa43c215SJeff Kirsher esw_cfg[i].pci_func = adapter->ahw->pci_func; 3886aa43c215SJeff Kirsher 3887aa43c215SJeff Kirsher switch (esw_cfg[i].op_mode) { 3888aa43c215SJeff Kirsher case QLCNIC_PORT_DEFAULTS: 3889aa43c215SJeff Kirsher qlcnic_set_eswitch_port_features(adapter, &esw_cfg[i]); 3890aa43c215SJeff Kirsher break; 3891aa43c215SJeff Kirsher case QLCNIC_ADD_VLAN: 3892aa43c215SJeff Kirsher qlcnic_set_vlan_config(adapter, &esw_cfg[i]); 3893aa43c215SJeff Kirsher break; 3894aa43c215SJeff Kirsher case QLCNIC_DEL_VLAN: 3895aa43c215SJeff Kirsher esw_cfg[i].vlan_id = 0; 3896aa43c215SJeff Kirsher qlcnic_set_vlan_config(adapter, &esw_cfg[i]); 3897aa43c215SJeff Kirsher break; 3898aa43c215SJeff Kirsher } 3899aa43c215SJeff Kirsher } 3900aa43c215SJeff Kirsher 3901aa43c215SJeff Kirsher if (adapter->op_mode != QLCNIC_MGMT_FUNC) 3902aa43c215SJeff Kirsher goto out; 3903aa43c215SJeff Kirsher 3904aa43c215SJeff Kirsher for (i = 0; i < count; i++) { 3905aa43c215SJeff Kirsher pci_func = esw_cfg[i].pci_func; 3906aa43c215SJeff Kirsher npar = &adapter->npars[pci_func]; 3907aa43c215SJeff Kirsher switch (esw_cfg[i].op_mode) { 3908aa43c215SJeff Kirsher case QLCNIC_PORT_DEFAULTS: 3909aa43c215SJeff Kirsher npar->promisc_mode = esw_cfg[i].promisc_mode; 3910aa43c215SJeff Kirsher npar->mac_override = esw_cfg[i].mac_override; 3911aa43c215SJeff Kirsher npar->offload_flags = esw_cfg[i].offload_flags; 3912aa43c215SJeff Kirsher npar->mac_anti_spoof = esw_cfg[i].mac_anti_spoof; 3913aa43c215SJeff Kirsher npar->discard_tagged = esw_cfg[i].discard_tagged; 3914aa43c215SJeff Kirsher break; 3915aa43c215SJeff Kirsher case QLCNIC_ADD_VLAN: 3916aa43c215SJeff Kirsher npar->pvid = esw_cfg[i].vlan_id; 3917aa43c215SJeff Kirsher break; 3918aa43c215SJeff Kirsher case QLCNIC_DEL_VLAN: 3919aa43c215SJeff Kirsher npar->pvid = 0; 3920aa43c215SJeff Kirsher break; 3921aa43c215SJeff Kirsher } 3922aa43c215SJeff Kirsher } 3923aa43c215SJeff Kirsher out: 3924aa43c215SJeff Kirsher return size; 3925aa43c215SJeff Kirsher } 3926aa43c215SJeff Kirsher 3927aa43c215SJeff Kirsher static ssize_t 3928aa43c215SJeff Kirsher qlcnic_sysfs_read_esw_config(struct file *file, struct kobject *kobj, 3929aa43c215SJeff Kirsher struct bin_attribute *attr, char *buf, loff_t offset, size_t size) 3930aa43c215SJeff Kirsher { 3931aa43c215SJeff Kirsher struct device *dev = container_of(kobj, struct device, kobj); 3932aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3933aa43c215SJeff Kirsher struct qlcnic_esw_func_cfg esw_cfg[QLCNIC_MAX_PCI_FUNC]; 3934aa43c215SJeff Kirsher u8 i; 3935aa43c215SJeff Kirsher 3936aa43c215SJeff Kirsher if (size != sizeof(esw_cfg)) 3937aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3938aa43c215SJeff Kirsher 3939aa43c215SJeff Kirsher for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { 3940aa43c215SJeff Kirsher if (adapter->npars[i].type != QLCNIC_TYPE_NIC) 3941aa43c215SJeff Kirsher continue; 3942aa43c215SJeff Kirsher esw_cfg[i].pci_func = i; 3943aa43c215SJeff Kirsher if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg[i])) 3944aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3945aa43c215SJeff Kirsher } 3946aa43c215SJeff Kirsher memcpy(buf, &esw_cfg, size); 3947aa43c215SJeff Kirsher 3948aa43c215SJeff Kirsher return size; 3949aa43c215SJeff Kirsher } 3950aa43c215SJeff Kirsher 3951aa43c215SJeff Kirsher static int 3952aa43c215SJeff Kirsher validate_npar_config(struct qlcnic_adapter *adapter, 3953aa43c215SJeff Kirsher struct qlcnic_npar_func_cfg *np_cfg, int count) 3954aa43c215SJeff Kirsher { 3955aa43c215SJeff Kirsher u8 pci_func, i; 3956aa43c215SJeff Kirsher 3957aa43c215SJeff Kirsher for (i = 0; i < count; i++) { 3958aa43c215SJeff Kirsher pci_func = np_cfg[i].pci_func; 3959aa43c215SJeff Kirsher if (pci_func >= QLCNIC_MAX_PCI_FUNC) 3960aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3961aa43c215SJeff Kirsher 3962aa43c215SJeff Kirsher if (adapter->npars[pci_func].type != QLCNIC_TYPE_NIC) 3963aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3964aa43c215SJeff Kirsher 3965aa43c215SJeff Kirsher if (!IS_VALID_BW(np_cfg[i].min_bw) || 3966aa43c215SJeff Kirsher !IS_VALID_BW(np_cfg[i].max_bw)) 3967aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3968aa43c215SJeff Kirsher } 3969aa43c215SJeff Kirsher return 0; 3970aa43c215SJeff Kirsher } 3971aa43c215SJeff Kirsher 3972aa43c215SJeff Kirsher static ssize_t 3973aa43c215SJeff Kirsher qlcnic_sysfs_write_npar_config(struct file *file, struct kobject *kobj, 3974aa43c215SJeff Kirsher struct bin_attribute *attr, char *buf, loff_t offset, size_t size) 3975aa43c215SJeff Kirsher { 3976aa43c215SJeff Kirsher struct device *dev = container_of(kobj, struct device, kobj); 3977aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3978aa43c215SJeff Kirsher struct qlcnic_info nic_info; 3979aa43c215SJeff Kirsher struct qlcnic_npar_func_cfg *np_cfg; 3980aa43c215SJeff Kirsher int i, count, rem, ret; 3981aa43c215SJeff Kirsher u8 pci_func; 3982aa43c215SJeff Kirsher 3983aa43c215SJeff Kirsher count = size / sizeof(struct qlcnic_npar_func_cfg); 3984aa43c215SJeff Kirsher rem = size % sizeof(struct qlcnic_npar_func_cfg); 3985aa43c215SJeff Kirsher if (rem) 3986aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3987aa43c215SJeff Kirsher 3988aa43c215SJeff Kirsher np_cfg = (struct qlcnic_npar_func_cfg *) buf; 3989aa43c215SJeff Kirsher ret = validate_npar_config(adapter, np_cfg, count); 3990aa43c215SJeff Kirsher if (ret) 3991aa43c215SJeff Kirsher return ret; 3992aa43c215SJeff Kirsher 3993aa43c215SJeff Kirsher for (i = 0; i < count ; i++) { 3994aa43c215SJeff Kirsher pci_func = np_cfg[i].pci_func; 3995aa43c215SJeff Kirsher ret = qlcnic_get_nic_info(adapter, &nic_info, pci_func); 3996aa43c215SJeff Kirsher if (ret) 3997aa43c215SJeff Kirsher return ret; 3998aa43c215SJeff Kirsher nic_info.pci_func = pci_func; 3999aa43c215SJeff Kirsher nic_info.min_tx_bw = np_cfg[i].min_bw; 4000aa43c215SJeff Kirsher nic_info.max_tx_bw = np_cfg[i].max_bw; 4001aa43c215SJeff Kirsher ret = qlcnic_set_nic_info(adapter, &nic_info); 4002aa43c215SJeff Kirsher if (ret) 4003aa43c215SJeff Kirsher return ret; 4004aa43c215SJeff Kirsher adapter->npars[i].min_bw = nic_info.min_tx_bw; 4005aa43c215SJeff Kirsher adapter->npars[i].max_bw = nic_info.max_tx_bw; 4006aa43c215SJeff Kirsher } 4007aa43c215SJeff Kirsher 4008aa43c215SJeff Kirsher return size; 4009aa43c215SJeff Kirsher 4010aa43c215SJeff Kirsher } 4011aa43c215SJeff Kirsher static ssize_t 4012aa43c215SJeff Kirsher qlcnic_sysfs_read_npar_config(struct file *file, struct kobject *kobj, 4013aa43c215SJeff Kirsher struct bin_attribute *attr, char *buf, loff_t offset, size_t size) 4014aa43c215SJeff Kirsher { 4015aa43c215SJeff Kirsher struct device *dev = container_of(kobj, struct device, kobj); 4016aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 4017aa43c215SJeff Kirsher struct qlcnic_info nic_info; 4018aa43c215SJeff Kirsher struct qlcnic_npar_func_cfg np_cfg[QLCNIC_MAX_PCI_FUNC]; 4019aa43c215SJeff Kirsher int i, ret; 4020aa43c215SJeff Kirsher 4021aa43c215SJeff Kirsher if (size != sizeof(np_cfg)) 4022aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 4023aa43c215SJeff Kirsher 4024aa43c215SJeff Kirsher for (i = 0; i < QLCNIC_MAX_PCI_FUNC ; i++) { 4025aa43c215SJeff Kirsher if (adapter->npars[i].type != QLCNIC_TYPE_NIC) 4026aa43c215SJeff Kirsher continue; 4027aa43c215SJeff Kirsher ret = qlcnic_get_nic_info(adapter, &nic_info, i); 4028aa43c215SJeff Kirsher if (ret) 4029aa43c215SJeff Kirsher return ret; 4030aa43c215SJeff Kirsher 4031aa43c215SJeff Kirsher np_cfg[i].pci_func = i; 4032aa43c215SJeff Kirsher np_cfg[i].op_mode = (u8)nic_info.op_mode; 4033aa43c215SJeff Kirsher np_cfg[i].port_num = nic_info.phys_port; 4034aa43c215SJeff Kirsher np_cfg[i].fw_capab = nic_info.capabilities; 4035aa43c215SJeff Kirsher np_cfg[i].min_bw = nic_info.min_tx_bw ; 4036aa43c215SJeff Kirsher np_cfg[i].max_bw = nic_info.max_tx_bw; 4037aa43c215SJeff Kirsher np_cfg[i].max_tx_queues = nic_info.max_tx_ques; 4038aa43c215SJeff Kirsher np_cfg[i].max_rx_queues = nic_info.max_rx_ques; 4039aa43c215SJeff Kirsher } 4040aa43c215SJeff Kirsher memcpy(buf, &np_cfg, size); 4041aa43c215SJeff Kirsher return size; 4042aa43c215SJeff Kirsher } 4043aa43c215SJeff Kirsher 4044aa43c215SJeff Kirsher static ssize_t 4045aa43c215SJeff Kirsher qlcnic_sysfs_get_port_stats(struct file *file, struct kobject *kobj, 4046aa43c215SJeff Kirsher struct bin_attribute *attr, char *buf, loff_t offset, size_t size) 4047aa43c215SJeff Kirsher { 4048aa43c215SJeff Kirsher struct device *dev = container_of(kobj, struct device, kobj); 4049aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 4050aa43c215SJeff Kirsher struct qlcnic_esw_statistics port_stats; 4051aa43c215SJeff Kirsher int ret; 4052aa43c215SJeff Kirsher 4053aa43c215SJeff Kirsher if (size != sizeof(struct qlcnic_esw_statistics)) 4054aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 4055aa43c215SJeff Kirsher 4056aa43c215SJeff Kirsher if (offset >= QLCNIC_MAX_PCI_FUNC) 4057aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 4058aa43c215SJeff Kirsher 4059aa43c215SJeff Kirsher memset(&port_stats, 0, size); 4060aa43c215SJeff Kirsher ret = qlcnic_get_port_stats(adapter, offset, QLCNIC_QUERY_RX_COUNTER, 4061aa43c215SJeff Kirsher &port_stats.rx); 4062aa43c215SJeff Kirsher if (ret) 4063aa43c215SJeff Kirsher return ret; 4064aa43c215SJeff Kirsher 4065aa43c215SJeff Kirsher ret = qlcnic_get_port_stats(adapter, offset, QLCNIC_QUERY_TX_COUNTER, 4066aa43c215SJeff Kirsher &port_stats.tx); 4067aa43c215SJeff Kirsher if (ret) 4068aa43c215SJeff Kirsher return ret; 4069aa43c215SJeff Kirsher 4070aa43c215SJeff Kirsher memcpy(buf, &port_stats, size); 4071aa43c215SJeff Kirsher return size; 4072aa43c215SJeff Kirsher } 4073aa43c215SJeff Kirsher 4074aa43c215SJeff Kirsher static ssize_t 4075aa43c215SJeff Kirsher qlcnic_sysfs_get_esw_stats(struct file *file, struct kobject *kobj, 4076aa43c215SJeff Kirsher struct bin_attribute *attr, char *buf, loff_t offset, size_t size) 4077aa43c215SJeff Kirsher { 4078aa43c215SJeff Kirsher struct device *dev = container_of(kobj, struct device, kobj); 4079aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 4080aa43c215SJeff Kirsher struct qlcnic_esw_statistics esw_stats; 4081aa43c215SJeff Kirsher int ret; 4082aa43c215SJeff Kirsher 4083aa43c215SJeff Kirsher if (size != sizeof(struct qlcnic_esw_statistics)) 4084aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 4085aa43c215SJeff Kirsher 4086aa43c215SJeff Kirsher if (offset >= QLCNIC_NIU_MAX_XG_PORTS) 4087aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 4088aa43c215SJeff Kirsher 4089aa43c215SJeff Kirsher memset(&esw_stats, 0, size); 4090aa43c215SJeff Kirsher ret = qlcnic_get_eswitch_stats(adapter, offset, QLCNIC_QUERY_RX_COUNTER, 4091aa43c215SJeff Kirsher &esw_stats.rx); 4092aa43c215SJeff Kirsher if (ret) 4093aa43c215SJeff Kirsher return ret; 4094aa43c215SJeff Kirsher 4095aa43c215SJeff Kirsher ret = qlcnic_get_eswitch_stats(adapter, offset, QLCNIC_QUERY_TX_COUNTER, 4096aa43c215SJeff Kirsher &esw_stats.tx); 4097aa43c215SJeff Kirsher if (ret) 4098aa43c215SJeff Kirsher return ret; 4099aa43c215SJeff Kirsher 4100aa43c215SJeff Kirsher memcpy(buf, &esw_stats, size); 4101aa43c215SJeff Kirsher return size; 4102aa43c215SJeff Kirsher } 4103aa43c215SJeff Kirsher 4104aa43c215SJeff Kirsher static ssize_t 4105aa43c215SJeff Kirsher qlcnic_sysfs_clear_esw_stats(struct file *file, struct kobject *kobj, 4106aa43c215SJeff Kirsher struct bin_attribute *attr, char *buf, loff_t offset, size_t size) 4107aa43c215SJeff Kirsher { 4108aa43c215SJeff Kirsher struct device *dev = container_of(kobj, struct device, kobj); 4109aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 4110aa43c215SJeff Kirsher int ret; 4111aa43c215SJeff Kirsher 4112aa43c215SJeff Kirsher if (offset >= QLCNIC_NIU_MAX_XG_PORTS) 4113aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 4114aa43c215SJeff Kirsher 4115aa43c215SJeff Kirsher ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_ESWITCH, offset, 4116aa43c215SJeff Kirsher QLCNIC_QUERY_RX_COUNTER); 4117aa43c215SJeff Kirsher if (ret) 4118aa43c215SJeff Kirsher return ret; 4119aa43c215SJeff Kirsher 4120aa43c215SJeff Kirsher ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_ESWITCH, offset, 4121aa43c215SJeff Kirsher QLCNIC_QUERY_TX_COUNTER); 4122aa43c215SJeff Kirsher if (ret) 4123aa43c215SJeff Kirsher return ret; 4124aa43c215SJeff Kirsher 4125aa43c215SJeff Kirsher return size; 4126aa43c215SJeff Kirsher } 4127aa43c215SJeff Kirsher 4128aa43c215SJeff Kirsher static ssize_t 4129aa43c215SJeff Kirsher qlcnic_sysfs_clear_port_stats(struct file *file, struct kobject *kobj, 4130aa43c215SJeff Kirsher struct bin_attribute *attr, char *buf, loff_t offset, size_t size) 4131aa43c215SJeff Kirsher { 4132aa43c215SJeff Kirsher 4133aa43c215SJeff Kirsher struct device *dev = container_of(kobj, struct device, kobj); 4134aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 4135aa43c215SJeff Kirsher int ret; 4136aa43c215SJeff Kirsher 4137aa43c215SJeff Kirsher if (offset >= QLCNIC_MAX_PCI_FUNC) 4138aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 4139aa43c215SJeff Kirsher 4140aa43c215SJeff Kirsher ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_PORT, offset, 4141aa43c215SJeff Kirsher QLCNIC_QUERY_RX_COUNTER); 4142aa43c215SJeff Kirsher if (ret) 4143aa43c215SJeff Kirsher return ret; 4144aa43c215SJeff Kirsher 4145aa43c215SJeff Kirsher ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_PORT, offset, 4146aa43c215SJeff Kirsher QLCNIC_QUERY_TX_COUNTER); 4147aa43c215SJeff Kirsher if (ret) 4148aa43c215SJeff Kirsher return ret; 4149aa43c215SJeff Kirsher 4150aa43c215SJeff Kirsher return size; 4151aa43c215SJeff Kirsher } 4152aa43c215SJeff Kirsher 4153aa43c215SJeff Kirsher static ssize_t 4154aa43c215SJeff Kirsher qlcnic_sysfs_read_pci_config(struct file *file, struct kobject *kobj, 4155aa43c215SJeff Kirsher struct bin_attribute *attr, char *buf, loff_t offset, size_t size) 4156aa43c215SJeff Kirsher { 4157aa43c215SJeff Kirsher struct device *dev = container_of(kobj, struct device, kobj); 4158aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 4159aa43c215SJeff Kirsher struct qlcnic_pci_func_cfg pci_cfg[QLCNIC_MAX_PCI_FUNC]; 4160aa43c215SJeff Kirsher struct qlcnic_pci_info *pci_info; 4161aa43c215SJeff Kirsher int i, ret; 4162aa43c215SJeff Kirsher 4163aa43c215SJeff Kirsher if (size != sizeof(pci_cfg)) 4164aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 4165aa43c215SJeff Kirsher 4166aa43c215SJeff Kirsher pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL); 4167aa43c215SJeff Kirsher if (!pci_info) 4168aa43c215SJeff Kirsher return -ENOMEM; 4169aa43c215SJeff Kirsher 4170aa43c215SJeff Kirsher ret = qlcnic_get_pci_info(adapter, pci_info); 4171aa43c215SJeff Kirsher if (ret) { 4172aa43c215SJeff Kirsher kfree(pci_info); 4173aa43c215SJeff Kirsher return ret; 4174aa43c215SJeff Kirsher } 4175aa43c215SJeff Kirsher 4176aa43c215SJeff Kirsher for (i = 0; i < QLCNIC_MAX_PCI_FUNC ; i++) { 4177aa43c215SJeff Kirsher pci_cfg[i].pci_func = pci_info[i].id; 4178aa43c215SJeff Kirsher pci_cfg[i].func_type = pci_info[i].type; 4179aa43c215SJeff Kirsher pci_cfg[i].port_num = pci_info[i].default_port; 4180aa43c215SJeff Kirsher pci_cfg[i].min_bw = pci_info[i].tx_min_bw; 4181aa43c215SJeff Kirsher pci_cfg[i].max_bw = pci_info[i].tx_max_bw; 4182aa43c215SJeff Kirsher memcpy(&pci_cfg[i].def_mac_addr, &pci_info[i].mac, ETH_ALEN); 4183aa43c215SJeff Kirsher } 4184aa43c215SJeff Kirsher memcpy(buf, &pci_cfg, size); 4185aa43c215SJeff Kirsher kfree(pci_info); 4186aa43c215SJeff Kirsher return size; 4187aa43c215SJeff Kirsher } 4188aa43c215SJeff Kirsher static struct bin_attribute bin_attr_npar_config = { 4189aa43c215SJeff Kirsher .attr = {.name = "npar_config", .mode = (S_IRUGO | S_IWUSR)}, 4190aa43c215SJeff Kirsher .size = 0, 4191aa43c215SJeff Kirsher .read = qlcnic_sysfs_read_npar_config, 4192aa43c215SJeff Kirsher .write = qlcnic_sysfs_write_npar_config, 4193aa43c215SJeff Kirsher }; 4194aa43c215SJeff Kirsher 4195aa43c215SJeff Kirsher static struct bin_attribute bin_attr_pci_config = { 4196aa43c215SJeff Kirsher .attr = {.name = "pci_config", .mode = (S_IRUGO | S_IWUSR)}, 4197aa43c215SJeff Kirsher .size = 0, 4198aa43c215SJeff Kirsher .read = qlcnic_sysfs_read_pci_config, 4199aa43c215SJeff Kirsher .write = NULL, 4200aa43c215SJeff Kirsher }; 4201aa43c215SJeff Kirsher 4202aa43c215SJeff Kirsher static struct bin_attribute bin_attr_port_stats = { 4203aa43c215SJeff Kirsher .attr = {.name = "port_stats", .mode = (S_IRUGO | S_IWUSR)}, 4204aa43c215SJeff Kirsher .size = 0, 4205aa43c215SJeff Kirsher .read = qlcnic_sysfs_get_port_stats, 4206aa43c215SJeff Kirsher .write = qlcnic_sysfs_clear_port_stats, 4207aa43c215SJeff Kirsher }; 4208aa43c215SJeff Kirsher 4209aa43c215SJeff Kirsher static struct bin_attribute bin_attr_esw_stats = { 4210aa43c215SJeff Kirsher .attr = {.name = "esw_stats", .mode = (S_IRUGO | S_IWUSR)}, 4211aa43c215SJeff Kirsher .size = 0, 4212aa43c215SJeff Kirsher .read = qlcnic_sysfs_get_esw_stats, 4213aa43c215SJeff Kirsher .write = qlcnic_sysfs_clear_esw_stats, 4214aa43c215SJeff Kirsher }; 4215aa43c215SJeff Kirsher 4216aa43c215SJeff Kirsher static struct bin_attribute bin_attr_esw_config = { 4217aa43c215SJeff Kirsher .attr = {.name = "esw_config", .mode = (S_IRUGO | S_IWUSR)}, 4218aa43c215SJeff Kirsher .size = 0, 4219aa43c215SJeff Kirsher .read = qlcnic_sysfs_read_esw_config, 4220aa43c215SJeff Kirsher .write = qlcnic_sysfs_write_esw_config, 4221aa43c215SJeff Kirsher }; 4222aa43c215SJeff Kirsher 4223aa43c215SJeff Kirsher static struct bin_attribute bin_attr_pm_config = { 4224aa43c215SJeff Kirsher .attr = {.name = "pm_config", .mode = (S_IRUGO | S_IWUSR)}, 4225aa43c215SJeff Kirsher .size = 0, 4226aa43c215SJeff Kirsher .read = qlcnic_sysfs_read_pm_config, 4227aa43c215SJeff Kirsher .write = qlcnic_sysfs_write_pm_config, 4228aa43c215SJeff Kirsher }; 4229aa43c215SJeff Kirsher 4230aa43c215SJeff Kirsher static void 4231aa43c215SJeff Kirsher qlcnic_create_sysfs_entries(struct qlcnic_adapter *adapter) 4232aa43c215SJeff Kirsher { 4233aa43c215SJeff Kirsher struct device *dev = &adapter->pdev->dev; 4234aa43c215SJeff Kirsher 4235aa43c215SJeff Kirsher if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG) 4236aa43c215SJeff Kirsher if (device_create_file(dev, &dev_attr_bridged_mode)) 4237aa43c215SJeff Kirsher dev_warn(dev, 4238aa43c215SJeff Kirsher "failed to create bridged_mode sysfs entry\n"); 4239aa43c215SJeff Kirsher } 4240aa43c215SJeff Kirsher 4241aa43c215SJeff Kirsher static void 4242aa43c215SJeff Kirsher qlcnic_remove_sysfs_entries(struct qlcnic_adapter *adapter) 4243aa43c215SJeff Kirsher { 4244aa43c215SJeff Kirsher struct device *dev = &adapter->pdev->dev; 4245aa43c215SJeff Kirsher 4246aa43c215SJeff Kirsher if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG) 4247aa43c215SJeff Kirsher device_remove_file(dev, &dev_attr_bridged_mode); 4248aa43c215SJeff Kirsher } 4249aa43c215SJeff Kirsher 4250aa43c215SJeff Kirsher static void 4251aa43c215SJeff Kirsher qlcnic_create_diag_entries(struct qlcnic_adapter *adapter) 4252aa43c215SJeff Kirsher { 4253aa43c215SJeff Kirsher struct device *dev = &adapter->pdev->dev; 4254aa43c215SJeff Kirsher 4255aa43c215SJeff Kirsher if (device_create_bin_file(dev, &bin_attr_port_stats)) 4256aa43c215SJeff Kirsher dev_info(dev, "failed to create port stats sysfs entry"); 4257aa43c215SJeff Kirsher 4258aa43c215SJeff Kirsher if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC) 4259aa43c215SJeff Kirsher return; 4260aa43c215SJeff Kirsher if (device_create_file(dev, &dev_attr_diag_mode)) 4261aa43c215SJeff Kirsher dev_info(dev, "failed to create diag_mode sysfs entry\n"); 4262728a98b8SSucheta Chakraborty if (device_create_file(dev, &dev_attr_beacon)) 4263728a98b8SSucheta Chakraborty dev_info(dev, "failed to create beacon sysfs entry"); 4264aa43c215SJeff Kirsher if (device_create_bin_file(dev, &bin_attr_crb)) 4265aa43c215SJeff Kirsher dev_info(dev, "failed to create crb sysfs entry\n"); 4266aa43c215SJeff Kirsher if (device_create_bin_file(dev, &bin_attr_mem)) 4267aa43c215SJeff Kirsher dev_info(dev, "failed to create mem sysfs entry\n"); 4268aa43c215SJeff Kirsher if (device_create_bin_file(dev, &bin_attr_pci_config)) 4269aa43c215SJeff Kirsher dev_info(dev, "failed to create pci config sysfs entry"); 4270aa43c215SJeff Kirsher if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) 4271aa43c215SJeff Kirsher return; 4272aa43c215SJeff Kirsher if (device_create_bin_file(dev, &bin_attr_esw_config)) 4273aa43c215SJeff Kirsher dev_info(dev, "failed to create esw config sysfs entry"); 4274aa43c215SJeff Kirsher if (adapter->op_mode != QLCNIC_MGMT_FUNC) 4275aa43c215SJeff Kirsher return; 4276aa43c215SJeff Kirsher if (device_create_bin_file(dev, &bin_attr_npar_config)) 4277aa43c215SJeff Kirsher dev_info(dev, "failed to create npar config sysfs entry"); 4278aa43c215SJeff Kirsher if (device_create_bin_file(dev, &bin_attr_pm_config)) 4279aa43c215SJeff Kirsher dev_info(dev, "failed to create pm config sysfs entry"); 4280aa43c215SJeff Kirsher if (device_create_bin_file(dev, &bin_attr_esw_stats)) 4281aa43c215SJeff Kirsher dev_info(dev, "failed to create eswitch stats sysfs entry"); 4282aa43c215SJeff Kirsher } 4283aa43c215SJeff Kirsher 4284aa43c215SJeff Kirsher static void 4285aa43c215SJeff Kirsher qlcnic_remove_diag_entries(struct qlcnic_adapter *adapter) 4286aa43c215SJeff Kirsher { 4287aa43c215SJeff Kirsher struct device *dev = &adapter->pdev->dev; 4288aa43c215SJeff Kirsher 4289aa43c215SJeff Kirsher device_remove_bin_file(dev, &bin_attr_port_stats); 4290aa43c215SJeff Kirsher 4291aa43c215SJeff Kirsher if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC) 4292aa43c215SJeff Kirsher return; 4293aa43c215SJeff Kirsher device_remove_file(dev, &dev_attr_diag_mode); 4294728a98b8SSucheta Chakraborty device_remove_file(dev, &dev_attr_beacon); 4295aa43c215SJeff Kirsher device_remove_bin_file(dev, &bin_attr_crb); 4296aa43c215SJeff Kirsher device_remove_bin_file(dev, &bin_attr_mem); 4297aa43c215SJeff Kirsher device_remove_bin_file(dev, &bin_attr_pci_config); 4298aa43c215SJeff Kirsher if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) 4299aa43c215SJeff Kirsher return; 4300aa43c215SJeff Kirsher device_remove_bin_file(dev, &bin_attr_esw_config); 4301aa43c215SJeff Kirsher if (adapter->op_mode != QLCNIC_MGMT_FUNC) 4302aa43c215SJeff Kirsher return; 4303aa43c215SJeff Kirsher device_remove_bin_file(dev, &bin_attr_npar_config); 4304aa43c215SJeff Kirsher device_remove_bin_file(dev, &bin_attr_pm_config); 4305aa43c215SJeff Kirsher device_remove_bin_file(dev, &bin_attr_esw_stats); 4306aa43c215SJeff Kirsher } 4307aa43c215SJeff Kirsher 4308aa43c215SJeff Kirsher #ifdef CONFIG_INET 4309aa43c215SJeff Kirsher 4310aa43c215SJeff Kirsher #define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops) 4311aa43c215SJeff Kirsher 4312aa43c215SJeff Kirsher static void 4313aa43c215SJeff Kirsher qlcnic_config_indev_addr(struct qlcnic_adapter *adapter, 4314aa43c215SJeff Kirsher struct net_device *dev, unsigned long event) 4315aa43c215SJeff Kirsher { 4316aa43c215SJeff Kirsher struct in_device *indev; 4317aa43c215SJeff Kirsher 4318aa43c215SJeff Kirsher indev = in_dev_get(dev); 4319aa43c215SJeff Kirsher if (!indev) 4320aa43c215SJeff Kirsher return; 4321aa43c215SJeff Kirsher 4322aa43c215SJeff Kirsher for_ifa(indev) { 4323aa43c215SJeff Kirsher switch (event) { 4324aa43c215SJeff Kirsher case NETDEV_UP: 4325aa43c215SJeff Kirsher qlcnic_config_ipaddr(adapter, 4326aa43c215SJeff Kirsher ifa->ifa_address, QLCNIC_IP_UP); 4327aa43c215SJeff Kirsher break; 4328aa43c215SJeff Kirsher case NETDEV_DOWN: 4329aa43c215SJeff Kirsher qlcnic_config_ipaddr(adapter, 4330aa43c215SJeff Kirsher ifa->ifa_address, QLCNIC_IP_DOWN); 4331aa43c215SJeff Kirsher break; 4332aa43c215SJeff Kirsher default: 4333aa43c215SJeff Kirsher break; 4334aa43c215SJeff Kirsher } 4335aa43c215SJeff Kirsher } endfor_ifa(indev); 4336aa43c215SJeff Kirsher 4337aa43c215SJeff Kirsher in_dev_put(indev); 4338aa43c215SJeff Kirsher } 4339aa43c215SJeff Kirsher 4340aa43c215SJeff Kirsher static void 4341aa43c215SJeff Kirsher qlcnic_restore_indev_addr(struct net_device *netdev, unsigned long event) 4342aa43c215SJeff Kirsher { 4343aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 4344aa43c215SJeff Kirsher struct net_device *dev; 4345aa43c215SJeff Kirsher u16 vid; 4346aa43c215SJeff Kirsher 4347aa43c215SJeff Kirsher qlcnic_config_indev_addr(adapter, netdev, event); 4348aa43c215SJeff Kirsher 4349aa43c215SJeff Kirsher for_each_set_bit(vid, adapter->vlans, VLAN_N_VID) { 4350aa43c215SJeff Kirsher dev = __vlan_find_dev_deep(netdev, vid); 4351aa43c215SJeff Kirsher if (!dev) 4352aa43c215SJeff Kirsher continue; 4353aa43c215SJeff Kirsher qlcnic_config_indev_addr(adapter, dev, event); 4354aa43c215SJeff Kirsher } 4355aa43c215SJeff Kirsher } 4356aa43c215SJeff Kirsher 4357aa43c215SJeff Kirsher static int qlcnic_netdev_event(struct notifier_block *this, 4358aa43c215SJeff Kirsher unsigned long event, void *ptr) 4359aa43c215SJeff Kirsher { 4360aa43c215SJeff Kirsher struct qlcnic_adapter *adapter; 4361aa43c215SJeff Kirsher struct net_device *dev = (struct net_device *)ptr; 4362aa43c215SJeff Kirsher 4363aa43c215SJeff Kirsher recheck: 4364aa43c215SJeff Kirsher if (dev == NULL) 4365aa43c215SJeff Kirsher goto done; 4366aa43c215SJeff Kirsher 4367aa43c215SJeff Kirsher if (dev->priv_flags & IFF_802_1Q_VLAN) { 4368aa43c215SJeff Kirsher dev = vlan_dev_real_dev(dev); 4369aa43c215SJeff Kirsher goto recheck; 4370aa43c215SJeff Kirsher } 4371aa43c215SJeff Kirsher 4372aa43c215SJeff Kirsher if (!is_qlcnic_netdev(dev)) 4373aa43c215SJeff Kirsher goto done; 4374aa43c215SJeff Kirsher 4375aa43c215SJeff Kirsher adapter = netdev_priv(dev); 4376aa43c215SJeff Kirsher 4377aa43c215SJeff Kirsher if (!adapter) 4378aa43c215SJeff Kirsher goto done; 4379aa43c215SJeff Kirsher 4380aa43c215SJeff Kirsher if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) 4381aa43c215SJeff Kirsher goto done; 4382aa43c215SJeff Kirsher 4383aa43c215SJeff Kirsher qlcnic_config_indev_addr(adapter, dev, event); 4384aa43c215SJeff Kirsher done: 4385aa43c215SJeff Kirsher return NOTIFY_DONE; 4386aa43c215SJeff Kirsher } 4387aa43c215SJeff Kirsher 4388aa43c215SJeff Kirsher static int 4389aa43c215SJeff Kirsher qlcnic_inetaddr_event(struct notifier_block *this, 4390aa43c215SJeff Kirsher unsigned long event, void *ptr) 4391aa43c215SJeff Kirsher { 4392aa43c215SJeff Kirsher struct qlcnic_adapter *adapter; 4393aa43c215SJeff Kirsher struct net_device *dev; 4394aa43c215SJeff Kirsher 4395aa43c215SJeff Kirsher struct in_ifaddr *ifa = (struct in_ifaddr *)ptr; 4396aa43c215SJeff Kirsher 4397aa43c215SJeff Kirsher dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL; 4398aa43c215SJeff Kirsher 4399aa43c215SJeff Kirsher recheck: 4400aa43c215SJeff Kirsher if (dev == NULL) 4401aa43c215SJeff Kirsher goto done; 4402aa43c215SJeff Kirsher 4403aa43c215SJeff Kirsher if (dev->priv_flags & IFF_802_1Q_VLAN) { 4404aa43c215SJeff Kirsher dev = vlan_dev_real_dev(dev); 4405aa43c215SJeff Kirsher goto recheck; 4406aa43c215SJeff Kirsher } 4407aa43c215SJeff Kirsher 4408aa43c215SJeff Kirsher if (!is_qlcnic_netdev(dev)) 4409aa43c215SJeff Kirsher goto done; 4410aa43c215SJeff Kirsher 4411aa43c215SJeff Kirsher adapter = netdev_priv(dev); 4412aa43c215SJeff Kirsher 4413aa43c215SJeff Kirsher if (!adapter) 4414aa43c215SJeff Kirsher goto done; 4415aa43c215SJeff Kirsher 4416aa43c215SJeff Kirsher if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) 4417aa43c215SJeff Kirsher goto done; 4418aa43c215SJeff Kirsher 4419aa43c215SJeff Kirsher switch (event) { 4420aa43c215SJeff Kirsher case NETDEV_UP: 4421aa43c215SJeff Kirsher qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_UP); 4422aa43c215SJeff Kirsher break; 4423aa43c215SJeff Kirsher case NETDEV_DOWN: 4424aa43c215SJeff Kirsher qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_DOWN); 4425aa43c215SJeff Kirsher break; 4426aa43c215SJeff Kirsher default: 4427aa43c215SJeff Kirsher break; 4428aa43c215SJeff Kirsher } 4429aa43c215SJeff Kirsher 4430aa43c215SJeff Kirsher done: 4431aa43c215SJeff Kirsher return NOTIFY_DONE; 4432aa43c215SJeff Kirsher } 4433aa43c215SJeff Kirsher 4434aa43c215SJeff Kirsher static struct notifier_block qlcnic_netdev_cb = { 4435aa43c215SJeff Kirsher .notifier_call = qlcnic_netdev_event, 4436aa43c215SJeff Kirsher }; 4437aa43c215SJeff Kirsher 4438aa43c215SJeff Kirsher static struct notifier_block qlcnic_inetaddr_cb = { 4439aa43c215SJeff Kirsher .notifier_call = qlcnic_inetaddr_event, 4440aa43c215SJeff Kirsher }; 4441aa43c215SJeff Kirsher #else 4442aa43c215SJeff Kirsher static void 4443aa43c215SJeff Kirsher qlcnic_restore_indev_addr(struct net_device *dev, unsigned long event) 4444aa43c215SJeff Kirsher { } 4445aa43c215SJeff Kirsher #endif 4446aa43c215SJeff Kirsher static struct pci_error_handlers qlcnic_err_handler = { 4447aa43c215SJeff Kirsher .error_detected = qlcnic_io_error_detected, 4448aa43c215SJeff Kirsher .slot_reset = qlcnic_io_slot_reset, 4449aa43c215SJeff Kirsher .resume = qlcnic_io_resume, 4450aa43c215SJeff Kirsher }; 4451aa43c215SJeff Kirsher 4452aa43c215SJeff Kirsher static struct pci_driver qlcnic_driver = { 4453aa43c215SJeff Kirsher .name = qlcnic_driver_name, 4454aa43c215SJeff Kirsher .id_table = qlcnic_pci_tbl, 4455aa43c215SJeff Kirsher .probe = qlcnic_probe, 4456aa43c215SJeff Kirsher .remove = __devexit_p(qlcnic_remove), 4457aa43c215SJeff Kirsher #ifdef CONFIG_PM 4458aa43c215SJeff Kirsher .suspend = qlcnic_suspend, 4459aa43c215SJeff Kirsher .resume = qlcnic_resume, 4460aa43c215SJeff Kirsher #endif 4461aa43c215SJeff Kirsher .shutdown = qlcnic_shutdown, 4462aa43c215SJeff Kirsher .err_handler = &qlcnic_err_handler 4463aa43c215SJeff Kirsher 4464aa43c215SJeff Kirsher }; 4465aa43c215SJeff Kirsher 4466aa43c215SJeff Kirsher static int __init qlcnic_init_module(void) 4467aa43c215SJeff Kirsher { 4468aa43c215SJeff Kirsher int ret; 4469aa43c215SJeff Kirsher 4470aa43c215SJeff Kirsher printk(KERN_INFO "%s\n", qlcnic_driver_string); 4471aa43c215SJeff Kirsher 4472aa43c215SJeff Kirsher qlcnic_wq = create_singlethread_workqueue("qlcnic"); 4473aa43c215SJeff Kirsher if (qlcnic_wq == NULL) { 4474aa43c215SJeff Kirsher printk(KERN_ERR "qlcnic: cannot create workqueue\n"); 4475aa43c215SJeff Kirsher return -ENOMEM; 4476aa43c215SJeff Kirsher } 4477aa43c215SJeff Kirsher 4478aa43c215SJeff Kirsher #ifdef CONFIG_INET 4479aa43c215SJeff Kirsher register_netdevice_notifier(&qlcnic_netdev_cb); 4480aa43c215SJeff Kirsher register_inetaddr_notifier(&qlcnic_inetaddr_cb); 4481aa43c215SJeff Kirsher #endif 4482aa43c215SJeff Kirsher 4483aa43c215SJeff Kirsher ret = pci_register_driver(&qlcnic_driver); 4484aa43c215SJeff Kirsher if (ret) { 4485aa43c215SJeff Kirsher #ifdef CONFIG_INET 4486aa43c215SJeff Kirsher unregister_inetaddr_notifier(&qlcnic_inetaddr_cb); 4487aa43c215SJeff Kirsher unregister_netdevice_notifier(&qlcnic_netdev_cb); 4488aa43c215SJeff Kirsher #endif 4489aa43c215SJeff Kirsher destroy_workqueue(qlcnic_wq); 4490aa43c215SJeff Kirsher } 4491aa43c215SJeff Kirsher 4492aa43c215SJeff Kirsher return ret; 4493aa43c215SJeff Kirsher } 4494aa43c215SJeff Kirsher 4495aa43c215SJeff Kirsher module_init(qlcnic_init_module); 4496aa43c215SJeff Kirsher 4497aa43c215SJeff Kirsher static void __exit qlcnic_exit_module(void) 4498aa43c215SJeff Kirsher { 4499aa43c215SJeff Kirsher 4500aa43c215SJeff Kirsher pci_unregister_driver(&qlcnic_driver); 4501aa43c215SJeff Kirsher 4502aa43c215SJeff Kirsher #ifdef CONFIG_INET 4503aa43c215SJeff Kirsher unregister_inetaddr_notifier(&qlcnic_inetaddr_cb); 4504aa43c215SJeff Kirsher unregister_netdevice_notifier(&qlcnic_netdev_cb); 4505aa43c215SJeff Kirsher #endif 4506aa43c215SJeff Kirsher destroy_workqueue(qlcnic_wq); 4507aa43c215SJeff Kirsher } 4508aa43c215SJeff Kirsher 4509aa43c215SJeff Kirsher module_exit(qlcnic_exit_module); 4510