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 *); 1008e586137SJiri Pirko static int qlcnic_vlan_rx_add(struct net_device *, u16); 1018e586137SJiri Pirko static int 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)) 304504f9b5aSDanny Kukawka return -EADDRNOTAVAIL; 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 7388e586137SJiri Pirko static int 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); 7438e586137SJiri Pirko return 0; 744aa43c215SJeff Kirsher } 745aa43c215SJeff Kirsher 7468e586137SJiri Pirko static int 747aa43c215SJeff Kirsher qlcnic_vlan_rx_del(struct net_device *netdev, u16 vid) 748aa43c215SJeff Kirsher { 749aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 750aa43c215SJeff Kirsher 751aa43c215SJeff Kirsher qlcnic_restore_indev_addr(netdev, NETDEV_DOWN); 752aa43c215SJeff Kirsher clear_bit(vid, adapter->vlans); 7538e586137SJiri Pirko return 0; 754aa43c215SJeff Kirsher } 755aa43c215SJeff Kirsher 756aa43c215SJeff Kirsher static void 757aa43c215SJeff Kirsher qlcnic_set_eswitch_port_features(struct qlcnic_adapter *adapter, 758aa43c215SJeff Kirsher struct qlcnic_esw_func_cfg *esw_cfg) 759aa43c215SJeff Kirsher { 760aa43c215SJeff Kirsher adapter->flags &= ~(QLCNIC_MACSPOOF | QLCNIC_MAC_OVERRIDE_DISABLED | 761aa43c215SJeff Kirsher QLCNIC_PROMISC_DISABLED); 762aa43c215SJeff Kirsher 763aa43c215SJeff Kirsher if (esw_cfg->mac_anti_spoof) 764aa43c215SJeff Kirsher adapter->flags |= QLCNIC_MACSPOOF; 765aa43c215SJeff Kirsher 766aa43c215SJeff Kirsher if (!esw_cfg->mac_override) 767aa43c215SJeff Kirsher adapter->flags |= QLCNIC_MAC_OVERRIDE_DISABLED; 768aa43c215SJeff Kirsher 769aa43c215SJeff Kirsher if (!esw_cfg->promisc_mode) 770aa43c215SJeff Kirsher adapter->flags |= QLCNIC_PROMISC_DISABLED; 771aa43c215SJeff Kirsher 772aa43c215SJeff Kirsher qlcnic_set_netdev_features(adapter, esw_cfg); 773aa43c215SJeff Kirsher } 774aa43c215SJeff Kirsher 775aa43c215SJeff Kirsher static int 776aa43c215SJeff Kirsher qlcnic_set_eswitch_port_config(struct qlcnic_adapter *adapter) 777aa43c215SJeff Kirsher { 778aa43c215SJeff Kirsher struct qlcnic_esw_func_cfg esw_cfg; 779aa43c215SJeff Kirsher 780aa43c215SJeff Kirsher if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) 781aa43c215SJeff Kirsher return 0; 782aa43c215SJeff Kirsher 783aa43c215SJeff Kirsher esw_cfg.pci_func = adapter->ahw->pci_func; 784aa43c215SJeff Kirsher if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg)) 785aa43c215SJeff Kirsher return -EIO; 786aa43c215SJeff Kirsher qlcnic_set_vlan_config(adapter, &esw_cfg); 787aa43c215SJeff Kirsher qlcnic_set_eswitch_port_features(adapter, &esw_cfg); 788aa43c215SJeff Kirsher 789aa43c215SJeff Kirsher return 0; 790aa43c215SJeff Kirsher } 791aa43c215SJeff Kirsher 792aa43c215SJeff Kirsher static void 793aa43c215SJeff Kirsher qlcnic_set_netdev_features(struct qlcnic_adapter *adapter, 794aa43c215SJeff Kirsher struct qlcnic_esw_func_cfg *esw_cfg) 795aa43c215SJeff Kirsher { 796aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 797c8f44affSMichał Mirosław netdev_features_t features, vlan_features; 798aa43c215SJeff Kirsher 799aa43c215SJeff Kirsher features = (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM | 800aa43c215SJeff Kirsher NETIF_F_IPV6_CSUM | NETIF_F_GRO); 801aa43c215SJeff Kirsher vlan_features = (NETIF_F_SG | NETIF_F_IP_CSUM | 802aa43c215SJeff Kirsher NETIF_F_IPV6_CSUM | NETIF_F_HW_VLAN_FILTER); 803aa43c215SJeff Kirsher 804aa43c215SJeff Kirsher if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO) { 805aa43c215SJeff Kirsher features |= (NETIF_F_TSO | NETIF_F_TSO6); 806aa43c215SJeff Kirsher vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6); 807aa43c215SJeff Kirsher } 808aa43c215SJeff Kirsher 809aa43c215SJeff Kirsher if (netdev->features & NETIF_F_LRO) 810aa43c215SJeff Kirsher features |= NETIF_F_LRO; 811aa43c215SJeff Kirsher 812aa43c215SJeff Kirsher if (esw_cfg->offload_flags & BIT_0) { 813aa43c215SJeff Kirsher netdev->features |= features; 814aa43c215SJeff Kirsher if (!(esw_cfg->offload_flags & BIT_1)) 815aa43c215SJeff Kirsher netdev->features &= ~NETIF_F_TSO; 816aa43c215SJeff Kirsher if (!(esw_cfg->offload_flags & BIT_2)) 817aa43c215SJeff Kirsher netdev->features &= ~NETIF_F_TSO6; 818aa43c215SJeff Kirsher } else { 819aa43c215SJeff Kirsher netdev->features &= ~features; 820aa43c215SJeff Kirsher } 821aa43c215SJeff Kirsher 822aa43c215SJeff Kirsher netdev->vlan_features = (features & vlan_features); 823aa43c215SJeff Kirsher } 824aa43c215SJeff Kirsher 825aa43c215SJeff Kirsher static int 826aa43c215SJeff Kirsher qlcnic_check_eswitch_mode(struct qlcnic_adapter *adapter) 827aa43c215SJeff Kirsher { 828aa43c215SJeff Kirsher void __iomem *priv_op; 829aa43c215SJeff Kirsher u32 op_mode, priv_level; 830aa43c215SJeff Kirsher int err = 0; 831aa43c215SJeff Kirsher 832aa43c215SJeff Kirsher err = qlcnic_initialize_nic(adapter); 833aa43c215SJeff Kirsher if (err) 834aa43c215SJeff Kirsher return err; 835aa43c215SJeff Kirsher 836aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_ADAPTER_INITIALIZED) 837aa43c215SJeff Kirsher return 0; 838aa43c215SJeff Kirsher 839aa43c215SJeff Kirsher priv_op = adapter->ahw->pci_base0 + QLCNIC_DRV_OP_MODE; 840aa43c215SJeff Kirsher op_mode = readl(priv_op); 841aa43c215SJeff Kirsher priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func); 842aa43c215SJeff Kirsher 843aa43c215SJeff Kirsher if (op_mode == QLC_DEV_DRV_DEFAULT) 844aa43c215SJeff Kirsher priv_level = QLCNIC_MGMT_FUNC; 845aa43c215SJeff Kirsher else 846aa43c215SJeff Kirsher priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func); 847aa43c215SJeff Kirsher 848aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_ESWITCH_ENABLED) { 849aa43c215SJeff Kirsher if (priv_level == QLCNIC_MGMT_FUNC) { 850aa43c215SJeff Kirsher adapter->op_mode = QLCNIC_MGMT_FUNC; 851aa43c215SJeff Kirsher err = qlcnic_init_pci_info(adapter); 852aa43c215SJeff Kirsher if (err) 853aa43c215SJeff Kirsher return err; 854aa43c215SJeff Kirsher /* Set privilege level for other functions */ 855aa43c215SJeff Kirsher qlcnic_set_function_modes(adapter); 856aa43c215SJeff Kirsher dev_info(&adapter->pdev->dev, 857aa43c215SJeff Kirsher "HAL Version: %d, Management function\n", 858aa43c215SJeff Kirsher adapter->fw_hal_version); 859aa43c215SJeff Kirsher } else if (priv_level == QLCNIC_PRIV_FUNC) { 860aa43c215SJeff Kirsher adapter->op_mode = QLCNIC_PRIV_FUNC; 861aa43c215SJeff Kirsher dev_info(&adapter->pdev->dev, 862aa43c215SJeff Kirsher "HAL Version: %d, Privileged function\n", 863aa43c215SJeff Kirsher adapter->fw_hal_version); 864aa43c215SJeff Kirsher } 865aa43c215SJeff Kirsher } 866aa43c215SJeff Kirsher 867aa43c215SJeff Kirsher adapter->flags |= QLCNIC_ADAPTER_INITIALIZED; 868aa43c215SJeff Kirsher 869aa43c215SJeff Kirsher return err; 870aa43c215SJeff Kirsher } 871aa43c215SJeff Kirsher 872aa43c215SJeff Kirsher static int 873aa43c215SJeff Kirsher qlcnic_set_default_offload_settings(struct qlcnic_adapter *adapter) 874aa43c215SJeff Kirsher { 875aa43c215SJeff Kirsher struct qlcnic_esw_func_cfg esw_cfg; 876aa43c215SJeff Kirsher struct qlcnic_npar_info *npar; 877aa43c215SJeff Kirsher u8 i; 878aa43c215SJeff Kirsher 879aa43c215SJeff Kirsher if (adapter->need_fw_reset) 880aa43c215SJeff Kirsher return 0; 881aa43c215SJeff Kirsher 882aa43c215SJeff Kirsher for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { 883aa43c215SJeff Kirsher if (adapter->npars[i].type != QLCNIC_TYPE_NIC) 884aa43c215SJeff Kirsher continue; 885aa43c215SJeff Kirsher memset(&esw_cfg, 0, sizeof(struct qlcnic_esw_func_cfg)); 886aa43c215SJeff Kirsher esw_cfg.pci_func = i; 887aa43c215SJeff Kirsher esw_cfg.offload_flags = BIT_0; 888aa43c215SJeff Kirsher esw_cfg.mac_override = BIT_0; 889aa43c215SJeff Kirsher esw_cfg.promisc_mode = BIT_0; 890aa43c215SJeff Kirsher if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO) 891aa43c215SJeff Kirsher esw_cfg.offload_flags |= (BIT_1 | BIT_2); 892aa43c215SJeff Kirsher if (qlcnic_config_switch_port(adapter, &esw_cfg)) 893aa43c215SJeff Kirsher return -EIO; 894aa43c215SJeff Kirsher npar = &adapter->npars[i]; 895aa43c215SJeff Kirsher npar->pvid = esw_cfg.vlan_id; 896aa43c215SJeff Kirsher npar->mac_override = esw_cfg.mac_override; 897aa43c215SJeff Kirsher npar->mac_anti_spoof = esw_cfg.mac_anti_spoof; 898aa43c215SJeff Kirsher npar->discard_tagged = esw_cfg.discard_tagged; 899aa43c215SJeff Kirsher npar->promisc_mode = esw_cfg.promisc_mode; 900aa43c215SJeff Kirsher npar->offload_flags = esw_cfg.offload_flags; 901aa43c215SJeff Kirsher } 902aa43c215SJeff Kirsher 903aa43c215SJeff Kirsher return 0; 904aa43c215SJeff Kirsher } 905aa43c215SJeff Kirsher 906aa43c215SJeff Kirsher static int 907aa43c215SJeff Kirsher qlcnic_reset_eswitch_config(struct qlcnic_adapter *adapter, 908aa43c215SJeff Kirsher struct qlcnic_npar_info *npar, int pci_func) 909aa43c215SJeff Kirsher { 910aa43c215SJeff Kirsher struct qlcnic_esw_func_cfg esw_cfg; 911aa43c215SJeff Kirsher esw_cfg.op_mode = QLCNIC_PORT_DEFAULTS; 912aa43c215SJeff Kirsher esw_cfg.pci_func = pci_func; 913aa43c215SJeff Kirsher esw_cfg.vlan_id = npar->pvid; 914aa43c215SJeff Kirsher esw_cfg.mac_override = npar->mac_override; 915aa43c215SJeff Kirsher esw_cfg.discard_tagged = npar->discard_tagged; 916aa43c215SJeff Kirsher esw_cfg.mac_anti_spoof = npar->mac_anti_spoof; 917aa43c215SJeff Kirsher esw_cfg.offload_flags = npar->offload_flags; 918aa43c215SJeff Kirsher esw_cfg.promisc_mode = npar->promisc_mode; 919aa43c215SJeff Kirsher if (qlcnic_config_switch_port(adapter, &esw_cfg)) 920aa43c215SJeff Kirsher return -EIO; 921aa43c215SJeff Kirsher 922aa43c215SJeff Kirsher esw_cfg.op_mode = QLCNIC_ADD_VLAN; 923aa43c215SJeff Kirsher if (qlcnic_config_switch_port(adapter, &esw_cfg)) 924aa43c215SJeff Kirsher return -EIO; 925aa43c215SJeff Kirsher 926aa43c215SJeff Kirsher return 0; 927aa43c215SJeff Kirsher } 928aa43c215SJeff Kirsher 929aa43c215SJeff Kirsher static int 930aa43c215SJeff Kirsher qlcnic_reset_npar_config(struct qlcnic_adapter *adapter) 931aa43c215SJeff Kirsher { 932aa43c215SJeff Kirsher int i, err; 933aa43c215SJeff Kirsher struct qlcnic_npar_info *npar; 934aa43c215SJeff Kirsher struct qlcnic_info nic_info; 935aa43c215SJeff Kirsher 936aa43c215SJeff Kirsher if (!adapter->need_fw_reset) 937aa43c215SJeff Kirsher return 0; 938aa43c215SJeff Kirsher 939aa43c215SJeff Kirsher /* Set the NPAR config data after FW reset */ 940aa43c215SJeff Kirsher for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { 941aa43c215SJeff Kirsher npar = &adapter->npars[i]; 942aa43c215SJeff Kirsher if (npar->type != QLCNIC_TYPE_NIC) 943aa43c215SJeff Kirsher continue; 944aa43c215SJeff Kirsher err = qlcnic_get_nic_info(adapter, &nic_info, i); 945aa43c215SJeff Kirsher if (err) 946aa43c215SJeff Kirsher return err; 947aa43c215SJeff Kirsher nic_info.min_tx_bw = npar->min_bw; 948aa43c215SJeff Kirsher nic_info.max_tx_bw = npar->max_bw; 949aa43c215SJeff Kirsher err = qlcnic_set_nic_info(adapter, &nic_info); 950aa43c215SJeff Kirsher if (err) 951aa43c215SJeff Kirsher return err; 952aa43c215SJeff Kirsher 953aa43c215SJeff Kirsher if (npar->enable_pm) { 954aa43c215SJeff Kirsher err = qlcnic_config_port_mirroring(adapter, 955aa43c215SJeff Kirsher npar->dest_npar, 1, i); 956aa43c215SJeff Kirsher if (err) 957aa43c215SJeff Kirsher return err; 958aa43c215SJeff Kirsher } 959aa43c215SJeff Kirsher err = qlcnic_reset_eswitch_config(adapter, npar, i); 960aa43c215SJeff Kirsher if (err) 961aa43c215SJeff Kirsher return err; 962aa43c215SJeff Kirsher } 963aa43c215SJeff Kirsher return 0; 964aa43c215SJeff Kirsher } 965aa43c215SJeff Kirsher 966aa43c215SJeff Kirsher static int qlcnic_check_npar_opertional(struct qlcnic_adapter *adapter) 967aa43c215SJeff Kirsher { 968aa43c215SJeff Kirsher u8 npar_opt_timeo = QLCNIC_DEV_NPAR_OPER_TIMEO; 969aa43c215SJeff Kirsher u32 npar_state; 970aa43c215SJeff Kirsher 971aa43c215SJeff Kirsher if (adapter->op_mode == QLCNIC_MGMT_FUNC) 972aa43c215SJeff Kirsher return 0; 973aa43c215SJeff Kirsher 974aa43c215SJeff Kirsher npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE); 975aa43c215SJeff Kirsher while (npar_state != QLCNIC_DEV_NPAR_OPER && --npar_opt_timeo) { 976aa43c215SJeff Kirsher msleep(1000); 977aa43c215SJeff Kirsher npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE); 978aa43c215SJeff Kirsher } 979aa43c215SJeff Kirsher if (!npar_opt_timeo) { 980aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, 981aa43c215SJeff Kirsher "Waiting for NPAR state to opertional timeout\n"); 982aa43c215SJeff Kirsher return -EIO; 983aa43c215SJeff Kirsher } 984aa43c215SJeff Kirsher return 0; 985aa43c215SJeff Kirsher } 986aa43c215SJeff Kirsher 987aa43c215SJeff Kirsher static int 988aa43c215SJeff Kirsher qlcnic_set_mgmt_operations(struct qlcnic_adapter *adapter) 989aa43c215SJeff Kirsher { 990aa43c215SJeff Kirsher int err; 991aa43c215SJeff Kirsher 992aa43c215SJeff Kirsher if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) || 993aa43c215SJeff Kirsher adapter->op_mode != QLCNIC_MGMT_FUNC) 994aa43c215SJeff Kirsher return 0; 995aa43c215SJeff Kirsher 996aa43c215SJeff Kirsher err = qlcnic_set_default_offload_settings(adapter); 997aa43c215SJeff Kirsher if (err) 998aa43c215SJeff Kirsher return err; 999aa43c215SJeff Kirsher 1000aa43c215SJeff Kirsher err = qlcnic_reset_npar_config(adapter); 1001aa43c215SJeff Kirsher if (err) 1002aa43c215SJeff Kirsher return err; 1003aa43c215SJeff Kirsher 1004aa43c215SJeff Kirsher qlcnic_dev_set_npar_ready(adapter); 1005aa43c215SJeff Kirsher 1006aa43c215SJeff Kirsher return err; 1007aa43c215SJeff Kirsher } 1008aa43c215SJeff Kirsher 1009aa43c215SJeff Kirsher static int 1010aa43c215SJeff Kirsher qlcnic_start_firmware(struct qlcnic_adapter *adapter) 1011aa43c215SJeff Kirsher { 1012aa43c215SJeff Kirsher int err; 1013aa43c215SJeff Kirsher 1014aa43c215SJeff Kirsher err = qlcnic_can_start_firmware(adapter); 1015aa43c215SJeff Kirsher if (err < 0) 1016aa43c215SJeff Kirsher return err; 1017aa43c215SJeff Kirsher else if (!err) 1018aa43c215SJeff Kirsher goto check_fw_status; 1019aa43c215SJeff Kirsher 1020aa43c215SJeff Kirsher if (load_fw_file) 1021aa43c215SJeff Kirsher qlcnic_request_firmware(adapter); 1022aa43c215SJeff Kirsher else { 1023aa43c215SJeff Kirsher err = qlcnic_check_flash_fw_ver(adapter); 1024aa43c215SJeff Kirsher if (err) 1025aa43c215SJeff Kirsher goto err_out; 1026aa43c215SJeff Kirsher 1027aa43c215SJeff Kirsher adapter->fw_type = QLCNIC_FLASH_ROMIMAGE; 1028aa43c215SJeff Kirsher } 1029aa43c215SJeff Kirsher 1030aa43c215SJeff Kirsher err = qlcnic_need_fw_reset(adapter); 1031aa43c215SJeff Kirsher if (err == 0) 1032aa43c215SJeff Kirsher goto check_fw_status; 1033aa43c215SJeff Kirsher 1034aa43c215SJeff Kirsher err = qlcnic_pinit_from_rom(adapter); 1035aa43c215SJeff Kirsher if (err) 1036aa43c215SJeff Kirsher goto err_out; 1037aa43c215SJeff Kirsher 1038aa43c215SJeff Kirsher err = qlcnic_load_firmware(adapter); 1039aa43c215SJeff Kirsher if (err) 1040aa43c215SJeff Kirsher goto err_out; 1041aa43c215SJeff Kirsher 1042aa43c215SJeff Kirsher qlcnic_release_firmware(adapter); 1043aa43c215SJeff Kirsher QLCWR32(adapter, CRB_DRIVER_VERSION, QLCNIC_DRIVER_VERSION); 1044aa43c215SJeff Kirsher 1045aa43c215SJeff Kirsher check_fw_status: 1046aa43c215SJeff Kirsher err = qlcnic_check_fw_status(adapter); 1047aa43c215SJeff Kirsher if (err) 1048aa43c215SJeff Kirsher goto err_out; 1049aa43c215SJeff Kirsher 1050aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_READY); 1051aa43c215SJeff Kirsher qlcnic_idc_debug_info(adapter, 1); 1052aa43c215SJeff Kirsher 1053aa43c215SJeff Kirsher err = qlcnic_check_eswitch_mode(adapter); 1054aa43c215SJeff Kirsher if (err) { 1055aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, 1056aa43c215SJeff Kirsher "Memory allocation failed for eswitch\n"); 1057aa43c215SJeff Kirsher goto err_out; 1058aa43c215SJeff Kirsher } 1059aa43c215SJeff Kirsher err = qlcnic_set_mgmt_operations(adapter); 1060aa43c215SJeff Kirsher if (err) 1061aa43c215SJeff Kirsher goto err_out; 1062aa43c215SJeff Kirsher 1063aa43c215SJeff Kirsher qlcnic_check_options(adapter); 1064aa43c215SJeff Kirsher adapter->need_fw_reset = 0; 1065aa43c215SJeff Kirsher 1066aa43c215SJeff Kirsher qlcnic_release_firmware(adapter); 1067aa43c215SJeff Kirsher return 0; 1068aa43c215SJeff Kirsher 1069aa43c215SJeff Kirsher err_out: 1070aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED); 1071aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, "Device state set to failed\n"); 1072aa43c215SJeff Kirsher 1073aa43c215SJeff Kirsher qlcnic_release_firmware(adapter); 1074aa43c215SJeff Kirsher return err; 1075aa43c215SJeff Kirsher } 1076aa43c215SJeff Kirsher 1077aa43c215SJeff Kirsher static int 1078aa43c215SJeff Kirsher qlcnic_request_irq(struct qlcnic_adapter *adapter) 1079aa43c215SJeff Kirsher { 1080aa43c215SJeff Kirsher irq_handler_t handler; 1081aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring; 1082aa43c215SJeff Kirsher int err, ring; 1083aa43c215SJeff Kirsher 1084aa43c215SJeff Kirsher unsigned long flags = 0; 1085aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 1086aa43c215SJeff Kirsher struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; 1087aa43c215SJeff Kirsher 1088aa43c215SJeff Kirsher if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) { 1089aa43c215SJeff Kirsher handler = qlcnic_tmp_intr; 1090aa43c215SJeff Kirsher if (!QLCNIC_IS_MSI_FAMILY(adapter)) 1091aa43c215SJeff Kirsher flags |= IRQF_SHARED; 1092aa43c215SJeff Kirsher 1093aa43c215SJeff Kirsher } else { 1094aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_MSIX_ENABLED) 1095aa43c215SJeff Kirsher handler = qlcnic_msix_intr; 1096aa43c215SJeff Kirsher else if (adapter->flags & QLCNIC_MSI_ENABLED) 1097aa43c215SJeff Kirsher handler = qlcnic_msi_intr; 1098aa43c215SJeff Kirsher else { 1099aa43c215SJeff Kirsher flags |= IRQF_SHARED; 1100aa43c215SJeff Kirsher handler = qlcnic_intr; 1101aa43c215SJeff Kirsher } 1102aa43c215SJeff Kirsher } 1103aa43c215SJeff Kirsher adapter->irq = netdev->irq; 1104aa43c215SJeff Kirsher 1105aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_sds_rings; ring++) { 1106aa43c215SJeff Kirsher sds_ring = &recv_ctx->sds_rings[ring]; 1107aa43c215SJeff Kirsher sprintf(sds_ring->name, "%s[%d]", netdev->name, ring); 1108aa43c215SJeff Kirsher err = request_irq(sds_ring->irq, handler, 1109aa43c215SJeff Kirsher flags, sds_ring->name, sds_ring); 1110aa43c215SJeff Kirsher if (err) 1111aa43c215SJeff Kirsher return err; 1112aa43c215SJeff Kirsher } 1113aa43c215SJeff Kirsher 1114aa43c215SJeff Kirsher return 0; 1115aa43c215SJeff Kirsher } 1116aa43c215SJeff Kirsher 1117aa43c215SJeff Kirsher static void 1118aa43c215SJeff Kirsher qlcnic_free_irq(struct qlcnic_adapter *adapter) 1119aa43c215SJeff Kirsher { 1120aa43c215SJeff Kirsher int ring; 1121aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring; 1122aa43c215SJeff Kirsher 1123aa43c215SJeff Kirsher struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; 1124aa43c215SJeff Kirsher 1125aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_sds_rings; ring++) { 1126aa43c215SJeff Kirsher sds_ring = &recv_ctx->sds_rings[ring]; 1127aa43c215SJeff Kirsher free_irq(sds_ring->irq, sds_ring); 1128aa43c215SJeff Kirsher } 1129aa43c215SJeff Kirsher } 1130aa43c215SJeff Kirsher 1131aa43c215SJeff Kirsher static int 1132aa43c215SJeff Kirsher __qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev) 1133aa43c215SJeff Kirsher { 1134aa43c215SJeff Kirsher int ring; 1135aa43c215SJeff Kirsher struct qlcnic_host_rds_ring *rds_ring; 1136aa43c215SJeff Kirsher 1137aa43c215SJeff Kirsher if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) 1138aa43c215SJeff Kirsher return -EIO; 1139aa43c215SJeff Kirsher 1140aa43c215SJeff Kirsher if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) 1141aa43c215SJeff Kirsher return 0; 1142aa43c215SJeff Kirsher if (qlcnic_set_eswitch_port_config(adapter)) 1143aa43c215SJeff Kirsher return -EIO; 1144aa43c215SJeff Kirsher 1145aa43c215SJeff Kirsher if (qlcnic_fw_create_ctx(adapter)) 1146aa43c215SJeff Kirsher return -EIO; 1147aa43c215SJeff Kirsher 1148aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_rds_rings; ring++) { 1149aa43c215SJeff Kirsher rds_ring = &adapter->recv_ctx->rds_rings[ring]; 1150aa43c215SJeff Kirsher qlcnic_post_rx_buffers(adapter, rds_ring); 1151aa43c215SJeff Kirsher } 1152aa43c215SJeff Kirsher 1153aa43c215SJeff Kirsher qlcnic_set_multi(netdev); 1154aa43c215SJeff Kirsher qlcnic_fw_cmd_set_mtu(adapter, netdev->mtu); 1155aa43c215SJeff Kirsher 1156aa43c215SJeff Kirsher adapter->ahw->linkup = 0; 1157aa43c215SJeff Kirsher 1158aa43c215SJeff Kirsher if (adapter->max_sds_rings > 1) 1159aa43c215SJeff Kirsher qlcnic_config_rss(adapter, 1); 1160aa43c215SJeff Kirsher 1161aa43c215SJeff Kirsher qlcnic_config_intr_coalesce(adapter); 1162aa43c215SJeff Kirsher 1163aa43c215SJeff Kirsher if (netdev->features & NETIF_F_LRO) 1164aa43c215SJeff Kirsher qlcnic_config_hw_lro(adapter, QLCNIC_LRO_ENABLED); 1165aa43c215SJeff Kirsher 1166aa43c215SJeff Kirsher qlcnic_napi_enable(adapter); 1167aa43c215SJeff Kirsher 1168aa43c215SJeff Kirsher qlcnic_linkevent_request(adapter, 1); 1169aa43c215SJeff Kirsher 1170aa43c215SJeff Kirsher adapter->reset_context = 0; 1171aa43c215SJeff Kirsher set_bit(__QLCNIC_DEV_UP, &adapter->state); 1172aa43c215SJeff Kirsher return 0; 1173aa43c215SJeff Kirsher } 1174aa43c215SJeff Kirsher 1175aa43c215SJeff Kirsher /* Usage: During resume and firmware recovery module.*/ 1176aa43c215SJeff Kirsher 1177aa43c215SJeff Kirsher static int 1178aa43c215SJeff Kirsher qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev) 1179aa43c215SJeff Kirsher { 1180aa43c215SJeff Kirsher int err = 0; 1181aa43c215SJeff Kirsher 1182aa43c215SJeff Kirsher rtnl_lock(); 1183aa43c215SJeff Kirsher if (netif_running(netdev)) 1184aa43c215SJeff Kirsher err = __qlcnic_up(adapter, netdev); 1185aa43c215SJeff Kirsher rtnl_unlock(); 1186aa43c215SJeff Kirsher 1187aa43c215SJeff Kirsher return err; 1188aa43c215SJeff Kirsher } 1189aa43c215SJeff Kirsher 1190aa43c215SJeff Kirsher static void 1191aa43c215SJeff Kirsher __qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev) 1192aa43c215SJeff Kirsher { 1193aa43c215SJeff Kirsher if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) 1194aa43c215SJeff Kirsher return; 1195aa43c215SJeff Kirsher 1196aa43c215SJeff Kirsher if (!test_and_clear_bit(__QLCNIC_DEV_UP, &adapter->state)) 1197aa43c215SJeff Kirsher return; 1198aa43c215SJeff Kirsher 1199aa43c215SJeff Kirsher smp_mb(); 1200aa43c215SJeff Kirsher spin_lock(&adapter->tx_clean_lock); 1201aa43c215SJeff Kirsher netif_carrier_off(netdev); 1202aa43c215SJeff Kirsher netif_tx_disable(netdev); 1203aa43c215SJeff Kirsher 1204aa43c215SJeff Kirsher qlcnic_free_mac_list(adapter); 1205aa43c215SJeff Kirsher 1206aa43c215SJeff Kirsher if (adapter->fhash.fnum) 1207aa43c215SJeff Kirsher qlcnic_delete_lb_filters(adapter); 1208aa43c215SJeff Kirsher 1209aa43c215SJeff Kirsher qlcnic_nic_set_promisc(adapter, QLCNIC_NIU_NON_PROMISC_MODE); 1210aa43c215SJeff Kirsher 1211aa43c215SJeff Kirsher qlcnic_napi_disable(adapter); 1212aa43c215SJeff Kirsher 1213aa43c215SJeff Kirsher qlcnic_fw_destroy_ctx(adapter); 1214aa43c215SJeff Kirsher 1215aa43c215SJeff Kirsher qlcnic_reset_rx_buffers_list(adapter); 1216aa43c215SJeff Kirsher qlcnic_release_tx_buffers(adapter); 1217aa43c215SJeff Kirsher spin_unlock(&adapter->tx_clean_lock); 1218aa43c215SJeff Kirsher } 1219aa43c215SJeff Kirsher 1220aa43c215SJeff Kirsher /* Usage: During suspend and firmware recovery module */ 1221aa43c215SJeff Kirsher 1222aa43c215SJeff Kirsher static void 1223aa43c215SJeff Kirsher qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev) 1224aa43c215SJeff Kirsher { 1225aa43c215SJeff Kirsher rtnl_lock(); 1226aa43c215SJeff Kirsher if (netif_running(netdev)) 1227aa43c215SJeff Kirsher __qlcnic_down(adapter, netdev); 1228aa43c215SJeff Kirsher rtnl_unlock(); 1229aa43c215SJeff Kirsher 1230aa43c215SJeff Kirsher } 1231aa43c215SJeff Kirsher 1232aa43c215SJeff Kirsher static int 1233aa43c215SJeff Kirsher qlcnic_attach(struct qlcnic_adapter *adapter) 1234aa43c215SJeff Kirsher { 1235aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 1236aa43c215SJeff Kirsher struct pci_dev *pdev = adapter->pdev; 1237aa43c215SJeff Kirsher int err; 1238aa43c215SJeff Kirsher 1239aa43c215SJeff Kirsher if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) 1240aa43c215SJeff Kirsher return 0; 1241aa43c215SJeff Kirsher 1242aa43c215SJeff Kirsher err = qlcnic_napi_add(adapter, netdev); 1243aa43c215SJeff Kirsher if (err) 1244aa43c215SJeff Kirsher return err; 1245aa43c215SJeff Kirsher 1246aa43c215SJeff Kirsher err = qlcnic_alloc_sw_resources(adapter); 1247aa43c215SJeff Kirsher if (err) { 1248aa43c215SJeff Kirsher dev_err(&pdev->dev, "Error in setting sw resources\n"); 1249aa43c215SJeff Kirsher goto err_out_napi_del; 1250aa43c215SJeff Kirsher } 1251aa43c215SJeff Kirsher 1252aa43c215SJeff Kirsher err = qlcnic_alloc_hw_resources(adapter); 1253aa43c215SJeff Kirsher if (err) { 1254aa43c215SJeff Kirsher dev_err(&pdev->dev, "Error in setting hw resources\n"); 1255aa43c215SJeff Kirsher goto err_out_free_sw; 1256aa43c215SJeff Kirsher } 1257aa43c215SJeff Kirsher 1258aa43c215SJeff Kirsher err = qlcnic_request_irq(adapter); 1259aa43c215SJeff Kirsher if (err) { 1260aa43c215SJeff Kirsher dev_err(&pdev->dev, "failed to setup interrupt\n"); 1261aa43c215SJeff Kirsher goto err_out_free_hw; 1262aa43c215SJeff Kirsher } 1263aa43c215SJeff Kirsher 1264aa43c215SJeff Kirsher qlcnic_create_sysfs_entries(adapter); 1265aa43c215SJeff Kirsher 1266aa43c215SJeff Kirsher adapter->is_up = QLCNIC_ADAPTER_UP_MAGIC; 1267aa43c215SJeff Kirsher return 0; 1268aa43c215SJeff Kirsher 1269aa43c215SJeff Kirsher err_out_free_hw: 1270aa43c215SJeff Kirsher qlcnic_free_hw_resources(adapter); 1271aa43c215SJeff Kirsher err_out_free_sw: 1272aa43c215SJeff Kirsher qlcnic_free_sw_resources(adapter); 1273aa43c215SJeff Kirsher err_out_napi_del: 1274aa43c215SJeff Kirsher qlcnic_napi_del(adapter); 1275aa43c215SJeff Kirsher return err; 1276aa43c215SJeff Kirsher } 1277aa43c215SJeff Kirsher 1278aa43c215SJeff Kirsher static void 1279aa43c215SJeff Kirsher qlcnic_detach(struct qlcnic_adapter *adapter) 1280aa43c215SJeff Kirsher { 1281aa43c215SJeff Kirsher if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) 1282aa43c215SJeff Kirsher return; 1283aa43c215SJeff Kirsher 1284aa43c215SJeff Kirsher qlcnic_remove_sysfs_entries(adapter); 1285aa43c215SJeff Kirsher 1286aa43c215SJeff Kirsher qlcnic_free_hw_resources(adapter); 1287aa43c215SJeff Kirsher qlcnic_release_rx_buffers(adapter); 1288aa43c215SJeff Kirsher qlcnic_free_irq(adapter); 1289aa43c215SJeff Kirsher qlcnic_napi_del(adapter); 1290aa43c215SJeff Kirsher qlcnic_free_sw_resources(adapter); 1291aa43c215SJeff Kirsher 1292aa43c215SJeff Kirsher adapter->is_up = 0; 1293aa43c215SJeff Kirsher } 1294aa43c215SJeff Kirsher 1295aa43c215SJeff Kirsher void qlcnic_diag_free_res(struct net_device *netdev, int max_sds_rings) 1296aa43c215SJeff Kirsher { 1297aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 1298aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring; 1299aa43c215SJeff Kirsher int ring; 1300aa43c215SJeff Kirsher 1301aa43c215SJeff Kirsher clear_bit(__QLCNIC_DEV_UP, &adapter->state); 1302aa43c215SJeff Kirsher if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) { 1303aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_sds_rings; ring++) { 1304aa43c215SJeff Kirsher sds_ring = &adapter->recv_ctx->sds_rings[ring]; 1305aa43c215SJeff Kirsher qlcnic_disable_int(sds_ring); 1306aa43c215SJeff Kirsher } 1307aa43c215SJeff Kirsher } 1308aa43c215SJeff Kirsher 1309aa43c215SJeff Kirsher qlcnic_fw_destroy_ctx(adapter); 1310aa43c215SJeff Kirsher 1311aa43c215SJeff Kirsher qlcnic_detach(adapter); 1312aa43c215SJeff Kirsher 1313aa43c215SJeff Kirsher adapter->diag_test = 0; 1314aa43c215SJeff Kirsher adapter->max_sds_rings = max_sds_rings; 1315aa43c215SJeff Kirsher 1316aa43c215SJeff Kirsher if (qlcnic_attach(adapter)) 1317aa43c215SJeff Kirsher goto out; 1318aa43c215SJeff Kirsher 1319aa43c215SJeff Kirsher if (netif_running(netdev)) 1320aa43c215SJeff Kirsher __qlcnic_up(adapter, netdev); 1321aa43c215SJeff Kirsher out: 1322aa43c215SJeff Kirsher netif_device_attach(netdev); 1323aa43c215SJeff Kirsher } 1324aa43c215SJeff Kirsher 1325aa43c215SJeff Kirsher static int qlcnic_alloc_adapter_resources(struct qlcnic_adapter *adapter) 1326aa43c215SJeff Kirsher { 1327aa43c215SJeff Kirsher int err = 0; 1328aa43c215SJeff Kirsher adapter->ahw = kzalloc(sizeof(struct qlcnic_hardware_context), 1329aa43c215SJeff Kirsher GFP_KERNEL); 1330aa43c215SJeff Kirsher if (!adapter->ahw) { 1331aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, 1332aa43c215SJeff Kirsher "Failed to allocate recv ctx resources for adapter\n"); 1333aa43c215SJeff Kirsher err = -ENOMEM; 1334aa43c215SJeff Kirsher goto err_out; 1335aa43c215SJeff Kirsher } 1336aa43c215SJeff Kirsher adapter->recv_ctx = kzalloc(sizeof(struct qlcnic_recv_context), 1337aa43c215SJeff Kirsher GFP_KERNEL); 1338aa43c215SJeff Kirsher if (!adapter->recv_ctx) { 1339aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, 1340aa43c215SJeff Kirsher "Failed to allocate recv ctx resources for adapter\n"); 1341aa43c215SJeff Kirsher kfree(adapter->ahw); 1342aa43c215SJeff Kirsher adapter->ahw = NULL; 1343aa43c215SJeff Kirsher err = -ENOMEM; 1344aa43c215SJeff Kirsher goto err_out; 1345aa43c215SJeff Kirsher } 1346aa43c215SJeff Kirsher /* Initialize interrupt coalesce parameters */ 1347aa43c215SJeff Kirsher adapter->ahw->coal.flag = QLCNIC_INTR_DEFAULT; 1348aa43c215SJeff Kirsher adapter->ahw->coal.rx_time_us = QLCNIC_DEFAULT_INTR_COALESCE_RX_TIME_US; 1349aa43c215SJeff Kirsher adapter->ahw->coal.rx_packets = QLCNIC_DEFAULT_INTR_COALESCE_RX_PACKETS; 1350aa43c215SJeff Kirsher err_out: 1351aa43c215SJeff Kirsher return err; 1352aa43c215SJeff Kirsher } 1353aa43c215SJeff Kirsher 1354aa43c215SJeff Kirsher static void qlcnic_free_adapter_resources(struct qlcnic_adapter *adapter) 1355aa43c215SJeff Kirsher { 1356aa43c215SJeff Kirsher kfree(adapter->recv_ctx); 1357aa43c215SJeff Kirsher adapter->recv_ctx = NULL; 1358aa43c215SJeff Kirsher 1359aa43c215SJeff Kirsher if (adapter->ahw->fw_dump.tmpl_hdr) { 1360aa43c215SJeff Kirsher vfree(adapter->ahw->fw_dump.tmpl_hdr); 1361aa43c215SJeff Kirsher adapter->ahw->fw_dump.tmpl_hdr = NULL; 1362aa43c215SJeff Kirsher } 1363aa43c215SJeff Kirsher kfree(adapter->ahw); 1364aa43c215SJeff Kirsher adapter->ahw = NULL; 1365aa43c215SJeff Kirsher } 1366aa43c215SJeff Kirsher 1367aa43c215SJeff Kirsher int qlcnic_diag_alloc_res(struct net_device *netdev, int test) 1368aa43c215SJeff Kirsher { 1369aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 1370aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring; 1371aa43c215SJeff Kirsher struct qlcnic_host_rds_ring *rds_ring; 1372aa43c215SJeff Kirsher int ring; 1373aa43c215SJeff Kirsher int ret; 1374aa43c215SJeff Kirsher 1375aa43c215SJeff Kirsher netif_device_detach(netdev); 1376aa43c215SJeff Kirsher 1377aa43c215SJeff Kirsher if (netif_running(netdev)) 1378aa43c215SJeff Kirsher __qlcnic_down(adapter, netdev); 1379aa43c215SJeff Kirsher 1380aa43c215SJeff Kirsher qlcnic_detach(adapter); 1381aa43c215SJeff Kirsher 1382aa43c215SJeff Kirsher adapter->max_sds_rings = 1; 1383aa43c215SJeff Kirsher adapter->diag_test = test; 1384aa43c215SJeff Kirsher 1385aa43c215SJeff Kirsher ret = qlcnic_attach(adapter); 1386aa43c215SJeff Kirsher if (ret) { 1387aa43c215SJeff Kirsher netif_device_attach(netdev); 1388aa43c215SJeff Kirsher return ret; 1389aa43c215SJeff Kirsher } 1390aa43c215SJeff Kirsher 1391aa43c215SJeff Kirsher ret = qlcnic_fw_create_ctx(adapter); 1392aa43c215SJeff Kirsher if (ret) { 1393aa43c215SJeff Kirsher qlcnic_detach(adapter); 1394aa43c215SJeff Kirsher netif_device_attach(netdev); 1395aa43c215SJeff Kirsher return ret; 1396aa43c215SJeff Kirsher } 1397aa43c215SJeff Kirsher 1398aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_rds_rings; ring++) { 1399aa43c215SJeff Kirsher rds_ring = &adapter->recv_ctx->rds_rings[ring]; 1400aa43c215SJeff Kirsher qlcnic_post_rx_buffers(adapter, rds_ring); 1401aa43c215SJeff Kirsher } 1402aa43c215SJeff Kirsher 1403aa43c215SJeff Kirsher if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) { 1404aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_sds_rings; ring++) { 1405aa43c215SJeff Kirsher sds_ring = &adapter->recv_ctx->sds_rings[ring]; 1406aa43c215SJeff Kirsher qlcnic_enable_int(sds_ring); 1407aa43c215SJeff Kirsher } 1408aa43c215SJeff Kirsher } 1409aa43c215SJeff Kirsher 1410aa43c215SJeff Kirsher if (adapter->diag_test == QLCNIC_LOOPBACK_TEST) { 1411aa43c215SJeff Kirsher adapter->ahw->loopback_state = 0; 1412aa43c215SJeff Kirsher qlcnic_linkevent_request(adapter, 1); 1413aa43c215SJeff Kirsher } 1414aa43c215SJeff Kirsher 1415aa43c215SJeff Kirsher set_bit(__QLCNIC_DEV_UP, &adapter->state); 1416aa43c215SJeff Kirsher 1417aa43c215SJeff Kirsher return 0; 1418aa43c215SJeff Kirsher } 1419aa43c215SJeff Kirsher 1420aa43c215SJeff Kirsher /* Reset context in hardware only */ 1421aa43c215SJeff Kirsher static int 1422aa43c215SJeff Kirsher qlcnic_reset_hw_context(struct qlcnic_adapter *adapter) 1423aa43c215SJeff Kirsher { 1424aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 1425aa43c215SJeff Kirsher 1426aa43c215SJeff Kirsher if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) 1427aa43c215SJeff Kirsher return -EBUSY; 1428aa43c215SJeff Kirsher 1429aa43c215SJeff Kirsher netif_device_detach(netdev); 1430aa43c215SJeff Kirsher 1431aa43c215SJeff Kirsher qlcnic_down(adapter, netdev); 1432aa43c215SJeff Kirsher 1433aa43c215SJeff Kirsher qlcnic_up(adapter, netdev); 1434aa43c215SJeff Kirsher 1435aa43c215SJeff Kirsher netif_device_attach(netdev); 1436aa43c215SJeff Kirsher 1437aa43c215SJeff Kirsher clear_bit(__QLCNIC_RESETTING, &adapter->state); 1438aa43c215SJeff Kirsher return 0; 1439aa43c215SJeff Kirsher } 1440aa43c215SJeff Kirsher 1441aa43c215SJeff Kirsher int 1442aa43c215SJeff Kirsher qlcnic_reset_context(struct qlcnic_adapter *adapter) 1443aa43c215SJeff Kirsher { 1444aa43c215SJeff Kirsher int err = 0; 1445aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 1446aa43c215SJeff Kirsher 1447aa43c215SJeff Kirsher if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) 1448aa43c215SJeff Kirsher return -EBUSY; 1449aa43c215SJeff Kirsher 1450aa43c215SJeff Kirsher if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) { 1451aa43c215SJeff Kirsher 1452aa43c215SJeff Kirsher netif_device_detach(netdev); 1453aa43c215SJeff Kirsher 1454aa43c215SJeff Kirsher if (netif_running(netdev)) 1455aa43c215SJeff Kirsher __qlcnic_down(adapter, netdev); 1456aa43c215SJeff Kirsher 1457aa43c215SJeff Kirsher qlcnic_detach(adapter); 1458aa43c215SJeff Kirsher 1459aa43c215SJeff Kirsher if (netif_running(netdev)) { 1460aa43c215SJeff Kirsher err = qlcnic_attach(adapter); 14611d5c88e3SAnirban Chakraborty if (!err) { 1462aa43c215SJeff Kirsher __qlcnic_up(adapter, netdev); 14631d5c88e3SAnirban Chakraborty qlcnic_restore_indev_addr(netdev, NETDEV_UP); 14641d5c88e3SAnirban Chakraborty } 1465aa43c215SJeff Kirsher } 1466aa43c215SJeff Kirsher 1467aa43c215SJeff Kirsher netif_device_attach(netdev); 1468aa43c215SJeff Kirsher } 1469aa43c215SJeff Kirsher 1470aa43c215SJeff Kirsher clear_bit(__QLCNIC_RESETTING, &adapter->state); 1471aa43c215SJeff Kirsher return err; 1472aa43c215SJeff Kirsher } 1473aa43c215SJeff Kirsher 1474aa43c215SJeff Kirsher static int 1475aa43c215SJeff Kirsher qlcnic_setup_netdev(struct qlcnic_adapter *adapter, 1476aa43c215SJeff Kirsher struct net_device *netdev, u8 pci_using_dac) 1477aa43c215SJeff Kirsher { 1478aa43c215SJeff Kirsher int err; 1479aa43c215SJeff Kirsher struct pci_dev *pdev = adapter->pdev; 1480aa43c215SJeff Kirsher 1481aa43c215SJeff Kirsher adapter->mc_enabled = 0; 1482aa43c215SJeff Kirsher adapter->max_mc_count = 38; 1483aa43c215SJeff Kirsher 1484aa43c215SJeff Kirsher netdev->netdev_ops = &qlcnic_netdev_ops; 1485aa43c215SJeff Kirsher netdev->watchdog_timeo = 5*HZ; 1486aa43c215SJeff Kirsher 1487aa43c215SJeff Kirsher qlcnic_change_mtu(netdev, netdev->mtu); 1488aa43c215SJeff Kirsher 1489aa43c215SJeff Kirsher SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_ops); 1490aa43c215SJeff Kirsher 1491aa43c215SJeff Kirsher netdev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | 1492aa43c215SJeff Kirsher NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM; 1493aa43c215SJeff Kirsher 1494aa43c215SJeff Kirsher if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO) 1495aa43c215SJeff Kirsher netdev->hw_features |= NETIF_F_TSO | NETIF_F_TSO6; 1496aa43c215SJeff Kirsher if (pci_using_dac) 1497aa43c215SJeff Kirsher netdev->hw_features |= NETIF_F_HIGHDMA; 1498aa43c215SJeff Kirsher 1499aa43c215SJeff Kirsher netdev->vlan_features = netdev->hw_features; 1500aa43c215SJeff Kirsher 1501aa43c215SJeff Kirsher if (adapter->capabilities & QLCNIC_FW_CAPABILITY_FVLANTX) 1502aa43c215SJeff Kirsher netdev->hw_features |= NETIF_F_HW_VLAN_TX; 1503aa43c215SJeff Kirsher if (adapter->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO) 1504aa43c215SJeff Kirsher netdev->hw_features |= NETIF_F_LRO; 1505aa43c215SJeff Kirsher 1506aa43c215SJeff Kirsher netdev->features |= netdev->hw_features | 1507aa43c215SJeff Kirsher NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER; 1508aa43c215SJeff Kirsher 1509aa43c215SJeff Kirsher netdev->irq = adapter->msix_entries[0].vector; 1510aa43c215SJeff Kirsher 1511aa43c215SJeff Kirsher err = register_netdev(netdev); 1512aa43c215SJeff Kirsher if (err) { 1513aa43c215SJeff Kirsher dev_err(&pdev->dev, "failed to register net device\n"); 1514aa43c215SJeff Kirsher return err; 1515aa43c215SJeff Kirsher } 1516aa43c215SJeff Kirsher 1517aa43c215SJeff Kirsher return 0; 1518aa43c215SJeff Kirsher } 1519aa43c215SJeff Kirsher 1520aa43c215SJeff Kirsher static int qlcnic_set_dma_mask(struct pci_dev *pdev, u8 *pci_using_dac) 1521aa43c215SJeff Kirsher { 1522aa43c215SJeff Kirsher if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && 1523aa43c215SJeff Kirsher !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) 1524aa43c215SJeff Kirsher *pci_using_dac = 1; 1525aa43c215SJeff Kirsher else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) && 1526aa43c215SJeff Kirsher !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) 1527aa43c215SJeff Kirsher *pci_using_dac = 0; 1528aa43c215SJeff Kirsher else { 1529aa43c215SJeff Kirsher dev_err(&pdev->dev, "Unable to set DMA mask, aborting\n"); 1530aa43c215SJeff Kirsher return -EIO; 1531aa43c215SJeff Kirsher } 1532aa43c215SJeff Kirsher 1533aa43c215SJeff Kirsher return 0; 1534aa43c215SJeff Kirsher } 1535aa43c215SJeff Kirsher 1536aa43c215SJeff Kirsher static int 1537aa43c215SJeff Kirsher qlcnic_alloc_msix_entries(struct qlcnic_adapter *adapter, u16 count) 1538aa43c215SJeff Kirsher { 1539aa43c215SJeff Kirsher adapter->msix_entries = kcalloc(count, sizeof(struct msix_entry), 1540aa43c215SJeff Kirsher GFP_KERNEL); 1541aa43c215SJeff Kirsher 1542aa43c215SJeff Kirsher if (adapter->msix_entries) 1543aa43c215SJeff Kirsher return 0; 1544aa43c215SJeff Kirsher 1545aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, "failed allocating msix_entries\n"); 1546aa43c215SJeff Kirsher return -ENOMEM; 1547aa43c215SJeff Kirsher } 1548aa43c215SJeff Kirsher 1549aa43c215SJeff Kirsher static int __devinit 1550aa43c215SJeff Kirsher qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 1551aa43c215SJeff Kirsher { 1552aa43c215SJeff Kirsher struct net_device *netdev = NULL; 1553aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = NULL; 1554aa43c215SJeff Kirsher int err; 1555aa43c215SJeff Kirsher uint8_t revision_id; 1556aa43c215SJeff Kirsher uint8_t pci_using_dac; 1557aa43c215SJeff Kirsher char brd_name[QLCNIC_MAX_BOARD_NAME_LEN]; 1558aa43c215SJeff Kirsher 1559aa43c215SJeff Kirsher err = pci_enable_device(pdev); 1560aa43c215SJeff Kirsher if (err) 1561aa43c215SJeff Kirsher return err; 1562aa43c215SJeff Kirsher 1563aa43c215SJeff Kirsher if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { 1564aa43c215SJeff Kirsher err = -ENODEV; 1565aa43c215SJeff Kirsher goto err_out_disable_pdev; 1566aa43c215SJeff Kirsher } 1567aa43c215SJeff Kirsher 1568aa43c215SJeff Kirsher err = qlcnic_set_dma_mask(pdev, &pci_using_dac); 1569aa43c215SJeff Kirsher if (err) 1570aa43c215SJeff Kirsher goto err_out_disable_pdev; 1571aa43c215SJeff Kirsher 1572aa43c215SJeff Kirsher err = pci_request_regions(pdev, qlcnic_driver_name); 1573aa43c215SJeff Kirsher if (err) 1574aa43c215SJeff Kirsher goto err_out_disable_pdev; 1575aa43c215SJeff Kirsher 1576aa43c215SJeff Kirsher pci_set_master(pdev); 1577aa43c215SJeff Kirsher pci_enable_pcie_error_reporting(pdev); 1578aa43c215SJeff Kirsher 1579aa43c215SJeff Kirsher netdev = alloc_etherdev(sizeof(struct qlcnic_adapter)); 1580aa43c215SJeff Kirsher if (!netdev) { 1581aa43c215SJeff Kirsher err = -ENOMEM; 1582aa43c215SJeff Kirsher goto err_out_free_res; 1583aa43c215SJeff Kirsher } 1584aa43c215SJeff Kirsher 1585aa43c215SJeff Kirsher SET_NETDEV_DEV(netdev, &pdev->dev); 1586aa43c215SJeff Kirsher 1587aa43c215SJeff Kirsher adapter = netdev_priv(netdev); 1588aa43c215SJeff Kirsher adapter->netdev = netdev; 1589aa43c215SJeff Kirsher adapter->pdev = pdev; 1590aa43c215SJeff Kirsher 1591aa43c215SJeff Kirsher if (qlcnic_alloc_adapter_resources(adapter)) 1592aa43c215SJeff Kirsher goto err_out_free_netdev; 1593aa43c215SJeff Kirsher 1594aa43c215SJeff Kirsher adapter->dev_rst_time = jiffies; 1595aa43c215SJeff Kirsher revision_id = pdev->revision; 1596aa43c215SJeff Kirsher adapter->ahw->revision_id = revision_id; 1597aa43c215SJeff Kirsher adapter->mac_learn = qlcnic_mac_learn; 1598aa43c215SJeff Kirsher 1599aa43c215SJeff Kirsher rwlock_init(&adapter->ahw->crb_lock); 1600aa43c215SJeff Kirsher mutex_init(&adapter->ahw->mem_lock); 1601aa43c215SJeff Kirsher 1602aa43c215SJeff Kirsher spin_lock_init(&adapter->tx_clean_lock); 1603aa43c215SJeff Kirsher INIT_LIST_HEAD(&adapter->mac_list); 1604aa43c215SJeff Kirsher 1605aa43c215SJeff Kirsher err = qlcnic_setup_pci_map(adapter); 1606aa43c215SJeff Kirsher if (err) 1607aa43c215SJeff Kirsher goto err_out_free_hw; 1608aa43c215SJeff Kirsher 1609aa43c215SJeff Kirsher /* This will be reset for mezz cards */ 1610aa43c215SJeff Kirsher adapter->portnum = adapter->ahw->pci_func; 1611aa43c215SJeff Kirsher 1612aa43c215SJeff Kirsher err = qlcnic_get_board_info(adapter); 1613aa43c215SJeff Kirsher if (err) { 1614aa43c215SJeff Kirsher dev_err(&pdev->dev, "Error getting board config info.\n"); 1615aa43c215SJeff Kirsher goto err_out_iounmap; 1616aa43c215SJeff Kirsher } 1617aa43c215SJeff Kirsher 1618aa43c215SJeff Kirsher err = qlcnic_setup_idc_param(adapter); 1619aa43c215SJeff Kirsher if (err) 1620aa43c215SJeff Kirsher goto err_out_iounmap; 1621aa43c215SJeff Kirsher 1622aa43c215SJeff Kirsher adapter->flags |= QLCNIC_NEED_FLR; 1623aa43c215SJeff Kirsher 1624aa43c215SJeff Kirsher err = adapter->nic_ops->start_firmware(adapter); 1625aa43c215SJeff Kirsher if (err) { 1626aa43c215SJeff Kirsher dev_err(&pdev->dev, "Loading fw failed.Please Reboot\n"); 1627aa43c215SJeff Kirsher goto err_out_decr_ref; 1628aa43c215SJeff Kirsher } 1629aa43c215SJeff Kirsher 1630aa43c215SJeff Kirsher if (qlcnic_read_mac_addr(adapter)) 1631aa43c215SJeff Kirsher dev_warn(&pdev->dev, "failed to read mac addr\n"); 1632aa43c215SJeff Kirsher 1633aa43c215SJeff Kirsher if (adapter->portnum == 0) { 1634aa43c215SJeff Kirsher get_brd_name(adapter, brd_name); 1635aa43c215SJeff Kirsher 1636aa43c215SJeff Kirsher pr_info("%s: %s Board Chip rev 0x%x\n", 1637aa43c215SJeff Kirsher module_name(THIS_MODULE), 1638aa43c215SJeff Kirsher brd_name, adapter->ahw->revision_id); 1639aa43c215SJeff Kirsher } 1640aa43c215SJeff Kirsher 1641aa43c215SJeff Kirsher qlcnic_clear_stats(adapter); 1642aa43c215SJeff Kirsher 1643aa43c215SJeff Kirsher err = qlcnic_alloc_msix_entries(adapter, adapter->max_rx_ques); 1644aa43c215SJeff Kirsher if (err) 1645aa43c215SJeff Kirsher goto err_out_decr_ref; 1646aa43c215SJeff Kirsher 1647aa43c215SJeff Kirsher qlcnic_setup_intr(adapter); 1648aa43c215SJeff Kirsher 1649aa43c215SJeff Kirsher err = qlcnic_setup_netdev(adapter, netdev, pci_using_dac); 1650aa43c215SJeff Kirsher if (err) 1651aa43c215SJeff Kirsher goto err_out_disable_msi; 1652aa43c215SJeff Kirsher 1653aa43c215SJeff Kirsher pci_set_drvdata(pdev, adapter); 1654aa43c215SJeff Kirsher 1655aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY); 1656aa43c215SJeff Kirsher 1657aa43c215SJeff Kirsher switch (adapter->ahw->port_type) { 1658aa43c215SJeff Kirsher case QLCNIC_GBE: 1659aa43c215SJeff Kirsher dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n", 1660aa43c215SJeff Kirsher adapter->netdev->name); 1661aa43c215SJeff Kirsher break; 1662aa43c215SJeff Kirsher case QLCNIC_XGBE: 1663aa43c215SJeff Kirsher dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n", 1664aa43c215SJeff Kirsher adapter->netdev->name); 1665aa43c215SJeff Kirsher break; 1666aa43c215SJeff Kirsher } 1667aa43c215SJeff Kirsher 1668aa43c215SJeff Kirsher if (adapter->mac_learn) 1669aa43c215SJeff Kirsher qlcnic_alloc_lb_filters_mem(adapter); 1670aa43c215SJeff Kirsher 1671aa43c215SJeff Kirsher qlcnic_create_diag_entries(adapter); 1672aa43c215SJeff Kirsher 1673aa43c215SJeff Kirsher return 0; 1674aa43c215SJeff Kirsher 1675aa43c215SJeff Kirsher err_out_disable_msi: 1676aa43c215SJeff Kirsher qlcnic_teardown_intr(adapter); 1677aa43c215SJeff Kirsher kfree(adapter->msix_entries); 1678aa43c215SJeff Kirsher 1679aa43c215SJeff Kirsher err_out_decr_ref: 1680aa43c215SJeff Kirsher qlcnic_clr_all_drv_state(adapter, 0); 1681aa43c215SJeff Kirsher 1682aa43c215SJeff Kirsher err_out_iounmap: 1683aa43c215SJeff Kirsher qlcnic_cleanup_pci_map(adapter); 1684aa43c215SJeff Kirsher 1685aa43c215SJeff Kirsher err_out_free_hw: 1686aa43c215SJeff Kirsher qlcnic_free_adapter_resources(adapter); 1687aa43c215SJeff Kirsher 1688aa43c215SJeff Kirsher err_out_free_netdev: 1689aa43c215SJeff Kirsher free_netdev(netdev); 1690aa43c215SJeff Kirsher 1691aa43c215SJeff Kirsher err_out_free_res: 1692aa43c215SJeff Kirsher pci_release_regions(pdev); 1693aa43c215SJeff Kirsher 1694aa43c215SJeff Kirsher err_out_disable_pdev: 1695aa43c215SJeff Kirsher pci_set_drvdata(pdev, NULL); 1696aa43c215SJeff Kirsher pci_disable_device(pdev); 1697aa43c215SJeff Kirsher return err; 1698aa43c215SJeff Kirsher } 1699aa43c215SJeff Kirsher 1700aa43c215SJeff Kirsher static void __devexit qlcnic_remove(struct pci_dev *pdev) 1701aa43c215SJeff Kirsher { 1702aa43c215SJeff Kirsher struct qlcnic_adapter *adapter; 1703aa43c215SJeff Kirsher struct net_device *netdev; 1704aa43c215SJeff Kirsher 1705aa43c215SJeff Kirsher adapter = pci_get_drvdata(pdev); 1706aa43c215SJeff Kirsher if (adapter == NULL) 1707aa43c215SJeff Kirsher return; 1708aa43c215SJeff Kirsher 1709aa43c215SJeff Kirsher netdev = adapter->netdev; 1710aa43c215SJeff Kirsher 1711aa43c215SJeff Kirsher qlcnic_cancel_fw_work(adapter); 1712aa43c215SJeff Kirsher 1713aa43c215SJeff Kirsher unregister_netdev(netdev); 1714aa43c215SJeff Kirsher 1715aa43c215SJeff Kirsher qlcnic_detach(adapter); 1716aa43c215SJeff Kirsher 1717aa43c215SJeff Kirsher if (adapter->npars != NULL) 1718aa43c215SJeff Kirsher kfree(adapter->npars); 1719aa43c215SJeff Kirsher if (adapter->eswitch != NULL) 1720aa43c215SJeff Kirsher kfree(adapter->eswitch); 1721aa43c215SJeff Kirsher 1722aa43c215SJeff Kirsher qlcnic_clr_all_drv_state(adapter, 0); 1723aa43c215SJeff Kirsher 1724aa43c215SJeff Kirsher clear_bit(__QLCNIC_RESETTING, &adapter->state); 1725aa43c215SJeff Kirsher 1726aa43c215SJeff Kirsher qlcnic_free_lb_filters_mem(adapter); 1727aa43c215SJeff Kirsher 1728aa43c215SJeff Kirsher qlcnic_teardown_intr(adapter); 1729aa43c215SJeff Kirsher kfree(adapter->msix_entries); 1730aa43c215SJeff Kirsher 1731aa43c215SJeff Kirsher qlcnic_remove_diag_entries(adapter); 1732aa43c215SJeff Kirsher 1733aa43c215SJeff Kirsher qlcnic_cleanup_pci_map(adapter); 1734aa43c215SJeff Kirsher 1735aa43c215SJeff Kirsher qlcnic_release_firmware(adapter); 1736aa43c215SJeff Kirsher 1737aa43c215SJeff Kirsher pci_disable_pcie_error_reporting(pdev); 1738aa43c215SJeff Kirsher pci_release_regions(pdev); 1739aa43c215SJeff Kirsher pci_disable_device(pdev); 1740aa43c215SJeff Kirsher pci_set_drvdata(pdev, NULL); 1741aa43c215SJeff Kirsher 1742aa43c215SJeff Kirsher qlcnic_free_adapter_resources(adapter); 1743aa43c215SJeff Kirsher free_netdev(netdev); 1744aa43c215SJeff Kirsher } 1745aa43c215SJeff Kirsher static int __qlcnic_shutdown(struct pci_dev *pdev) 1746aa43c215SJeff Kirsher { 1747aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); 1748aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 1749aa43c215SJeff Kirsher int retval; 1750aa43c215SJeff Kirsher 1751aa43c215SJeff Kirsher netif_device_detach(netdev); 1752aa43c215SJeff Kirsher 1753aa43c215SJeff Kirsher qlcnic_cancel_fw_work(adapter); 1754aa43c215SJeff Kirsher 1755aa43c215SJeff Kirsher if (netif_running(netdev)) 1756aa43c215SJeff Kirsher qlcnic_down(adapter, netdev); 1757aa43c215SJeff Kirsher 1758aa43c215SJeff Kirsher qlcnic_clr_all_drv_state(adapter, 0); 1759aa43c215SJeff Kirsher 1760aa43c215SJeff Kirsher clear_bit(__QLCNIC_RESETTING, &adapter->state); 1761aa43c215SJeff Kirsher 1762aa43c215SJeff Kirsher retval = pci_save_state(pdev); 1763aa43c215SJeff Kirsher if (retval) 1764aa43c215SJeff Kirsher return retval; 1765aa43c215SJeff Kirsher 1766aa43c215SJeff Kirsher if (qlcnic_wol_supported(adapter)) { 1767aa43c215SJeff Kirsher pci_enable_wake(pdev, PCI_D3cold, 1); 1768aa43c215SJeff Kirsher pci_enable_wake(pdev, PCI_D3hot, 1); 1769aa43c215SJeff Kirsher } 1770aa43c215SJeff Kirsher 1771aa43c215SJeff Kirsher return 0; 1772aa43c215SJeff Kirsher } 1773aa43c215SJeff Kirsher 1774aa43c215SJeff Kirsher static void qlcnic_shutdown(struct pci_dev *pdev) 1775aa43c215SJeff Kirsher { 1776aa43c215SJeff Kirsher if (__qlcnic_shutdown(pdev)) 1777aa43c215SJeff Kirsher return; 1778aa43c215SJeff Kirsher 1779aa43c215SJeff Kirsher pci_disable_device(pdev); 1780aa43c215SJeff Kirsher } 1781aa43c215SJeff Kirsher 1782aa43c215SJeff Kirsher #ifdef CONFIG_PM 1783aa43c215SJeff Kirsher static int 1784aa43c215SJeff Kirsher qlcnic_suspend(struct pci_dev *pdev, pm_message_t state) 1785aa43c215SJeff Kirsher { 1786aa43c215SJeff Kirsher int retval; 1787aa43c215SJeff Kirsher 1788aa43c215SJeff Kirsher retval = __qlcnic_shutdown(pdev); 1789aa43c215SJeff Kirsher if (retval) 1790aa43c215SJeff Kirsher return retval; 1791aa43c215SJeff Kirsher 1792aa43c215SJeff Kirsher pci_set_power_state(pdev, pci_choose_state(pdev, state)); 1793aa43c215SJeff Kirsher return 0; 1794aa43c215SJeff Kirsher } 1795aa43c215SJeff Kirsher 1796aa43c215SJeff Kirsher static int 1797aa43c215SJeff Kirsher qlcnic_resume(struct pci_dev *pdev) 1798aa43c215SJeff Kirsher { 1799aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); 1800aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 1801aa43c215SJeff Kirsher int err; 1802aa43c215SJeff Kirsher 1803aa43c215SJeff Kirsher err = pci_enable_device(pdev); 1804aa43c215SJeff Kirsher if (err) 1805aa43c215SJeff Kirsher return err; 1806aa43c215SJeff Kirsher 1807aa43c215SJeff Kirsher pci_set_power_state(pdev, PCI_D0); 1808aa43c215SJeff Kirsher pci_set_master(pdev); 1809aa43c215SJeff Kirsher pci_restore_state(pdev); 1810aa43c215SJeff Kirsher 1811aa43c215SJeff Kirsher err = adapter->nic_ops->start_firmware(adapter); 1812aa43c215SJeff Kirsher if (err) { 1813aa43c215SJeff Kirsher dev_err(&pdev->dev, "failed to start firmware\n"); 1814aa43c215SJeff Kirsher return err; 1815aa43c215SJeff Kirsher } 1816aa43c215SJeff Kirsher 1817aa43c215SJeff Kirsher if (netif_running(netdev)) { 1818aa43c215SJeff Kirsher err = qlcnic_up(adapter, netdev); 1819aa43c215SJeff Kirsher if (err) 1820aa43c215SJeff Kirsher goto done; 1821aa43c215SJeff Kirsher 1822aa43c215SJeff Kirsher qlcnic_restore_indev_addr(netdev, NETDEV_UP); 1823aa43c215SJeff Kirsher } 1824aa43c215SJeff Kirsher done: 1825aa43c215SJeff Kirsher netif_device_attach(netdev); 1826aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY); 1827aa43c215SJeff Kirsher return 0; 1828aa43c215SJeff Kirsher } 1829aa43c215SJeff Kirsher #endif 1830aa43c215SJeff Kirsher 1831aa43c215SJeff Kirsher static int qlcnic_open(struct net_device *netdev) 1832aa43c215SJeff Kirsher { 1833aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 1834aa43c215SJeff Kirsher int err; 1835aa43c215SJeff Kirsher 1836aa43c215SJeff Kirsher netif_carrier_off(netdev); 1837aa43c215SJeff Kirsher 1838aa43c215SJeff Kirsher err = qlcnic_attach(adapter); 1839aa43c215SJeff Kirsher if (err) 1840aa43c215SJeff Kirsher return err; 1841aa43c215SJeff Kirsher 1842aa43c215SJeff Kirsher err = __qlcnic_up(adapter, netdev); 1843aa43c215SJeff Kirsher if (err) 1844aa43c215SJeff Kirsher goto err_out; 1845aa43c215SJeff Kirsher 1846aa43c215SJeff Kirsher netif_start_queue(netdev); 1847aa43c215SJeff Kirsher 1848aa43c215SJeff Kirsher return 0; 1849aa43c215SJeff Kirsher 1850aa43c215SJeff Kirsher err_out: 1851aa43c215SJeff Kirsher qlcnic_detach(adapter); 1852aa43c215SJeff Kirsher return err; 1853aa43c215SJeff Kirsher } 1854aa43c215SJeff Kirsher 1855aa43c215SJeff Kirsher /* 1856aa43c215SJeff Kirsher * qlcnic_close - Disables a network interface entry point 1857aa43c215SJeff Kirsher */ 1858aa43c215SJeff Kirsher static int qlcnic_close(struct net_device *netdev) 1859aa43c215SJeff Kirsher { 1860aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 1861aa43c215SJeff Kirsher 1862aa43c215SJeff Kirsher __qlcnic_down(adapter, netdev); 1863aa43c215SJeff Kirsher return 0; 1864aa43c215SJeff Kirsher } 1865aa43c215SJeff Kirsher 1866aa43c215SJeff Kirsher void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter) 1867aa43c215SJeff Kirsher { 1868aa43c215SJeff Kirsher void *head; 1869aa43c215SJeff Kirsher int i; 1870aa43c215SJeff Kirsher 1871aa43c215SJeff Kirsher if (adapter->fhash.fmax && adapter->fhash.fhead) 1872aa43c215SJeff Kirsher return; 1873aa43c215SJeff Kirsher 1874aa43c215SJeff Kirsher spin_lock_init(&adapter->mac_learn_lock); 1875aa43c215SJeff Kirsher 1876aa43c215SJeff Kirsher head = kcalloc(QLCNIC_LB_MAX_FILTERS, sizeof(struct hlist_head), 1877aa43c215SJeff Kirsher GFP_KERNEL); 1878aa43c215SJeff Kirsher if (!head) 1879aa43c215SJeff Kirsher return; 1880aa43c215SJeff Kirsher 1881aa43c215SJeff Kirsher adapter->fhash.fmax = QLCNIC_LB_MAX_FILTERS; 1882aa43c215SJeff Kirsher adapter->fhash.fhead = head; 1883aa43c215SJeff Kirsher 1884aa43c215SJeff Kirsher for (i = 0; i < adapter->fhash.fmax; i++) 1885aa43c215SJeff Kirsher INIT_HLIST_HEAD(&adapter->fhash.fhead[i]); 1886aa43c215SJeff Kirsher } 1887aa43c215SJeff Kirsher 1888aa43c215SJeff Kirsher static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter) 1889aa43c215SJeff Kirsher { 1890aa43c215SJeff Kirsher if (adapter->fhash.fmax && adapter->fhash.fhead) 1891aa43c215SJeff Kirsher kfree(adapter->fhash.fhead); 1892aa43c215SJeff Kirsher 1893aa43c215SJeff Kirsher adapter->fhash.fhead = NULL; 1894aa43c215SJeff Kirsher adapter->fhash.fmax = 0; 1895aa43c215SJeff Kirsher } 1896aa43c215SJeff Kirsher 1897aa43c215SJeff Kirsher static void qlcnic_change_filter(struct qlcnic_adapter *adapter, 1898aa43c215SJeff Kirsher u64 uaddr, __le16 vlan_id, struct qlcnic_host_tx_ring *tx_ring) 1899aa43c215SJeff Kirsher { 1900aa43c215SJeff Kirsher struct cmd_desc_type0 *hwdesc; 1901aa43c215SJeff Kirsher struct qlcnic_nic_req *req; 1902aa43c215SJeff Kirsher struct qlcnic_mac_req *mac_req; 1903aa43c215SJeff Kirsher struct qlcnic_vlan_req *vlan_req; 1904aa43c215SJeff Kirsher u32 producer; 1905aa43c215SJeff Kirsher u64 word; 1906aa43c215SJeff Kirsher 1907aa43c215SJeff Kirsher producer = tx_ring->producer; 1908aa43c215SJeff Kirsher hwdesc = &tx_ring->desc_head[tx_ring->producer]; 1909aa43c215SJeff Kirsher 1910aa43c215SJeff Kirsher req = (struct qlcnic_nic_req *)hwdesc; 1911aa43c215SJeff Kirsher memset(req, 0, sizeof(struct qlcnic_nic_req)); 1912aa43c215SJeff Kirsher req->qhdr = cpu_to_le64(QLCNIC_REQUEST << 23); 1913aa43c215SJeff Kirsher 1914aa43c215SJeff Kirsher word = QLCNIC_MAC_EVENT | ((u64)(adapter->portnum) << 16); 1915aa43c215SJeff Kirsher req->req_hdr = cpu_to_le64(word); 1916aa43c215SJeff Kirsher 1917aa43c215SJeff Kirsher mac_req = (struct qlcnic_mac_req *)&(req->words[0]); 1918aa43c215SJeff Kirsher mac_req->op = vlan_id ? QLCNIC_MAC_VLAN_ADD : QLCNIC_MAC_ADD; 1919aa43c215SJeff Kirsher memcpy(mac_req->mac_addr, &uaddr, ETH_ALEN); 1920aa43c215SJeff Kirsher 1921aa43c215SJeff Kirsher vlan_req = (struct qlcnic_vlan_req *)&req->words[1]; 1922aa43c215SJeff Kirsher vlan_req->vlan_id = vlan_id; 1923aa43c215SJeff Kirsher 1924aa43c215SJeff Kirsher tx_ring->producer = get_next_index(producer, tx_ring->num_desc); 1925aa43c215SJeff Kirsher smp_mb(); 1926aa43c215SJeff Kirsher } 1927aa43c215SJeff Kirsher 1928aa43c215SJeff Kirsher #define QLCNIC_MAC_HASH(MAC)\ 1929aa43c215SJeff Kirsher ((((MAC) & 0x70000) >> 0x10) | (((MAC) & 0x70000000000ULL) >> 0x25)) 1930aa43c215SJeff Kirsher 1931aa43c215SJeff Kirsher static void 1932aa43c215SJeff Kirsher qlcnic_send_filter(struct qlcnic_adapter *adapter, 1933aa43c215SJeff Kirsher struct qlcnic_host_tx_ring *tx_ring, 1934aa43c215SJeff Kirsher struct cmd_desc_type0 *first_desc, 1935aa43c215SJeff Kirsher struct sk_buff *skb) 1936aa43c215SJeff Kirsher { 1937aa43c215SJeff Kirsher struct ethhdr *phdr = (struct ethhdr *)(skb->data); 1938aa43c215SJeff Kirsher struct qlcnic_filter *fil, *tmp_fil; 1939aa43c215SJeff Kirsher struct hlist_node *tmp_hnode, *n; 1940aa43c215SJeff Kirsher struct hlist_head *head; 1941aa43c215SJeff Kirsher u64 src_addr = 0; 1942aa43c215SJeff Kirsher __le16 vlan_id = 0; 1943aa43c215SJeff Kirsher u8 hindex; 1944aa43c215SJeff Kirsher 1945aa43c215SJeff Kirsher if (!compare_ether_addr(phdr->h_source, adapter->mac_addr)) 1946aa43c215SJeff Kirsher return; 1947aa43c215SJeff Kirsher 1948aa43c215SJeff Kirsher if (adapter->fhash.fnum >= adapter->fhash.fmax) 1949aa43c215SJeff Kirsher return; 1950aa43c215SJeff Kirsher 1951aa43c215SJeff Kirsher /* Only NPAR capable devices support vlan based learning*/ 1952aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_ESWITCH_ENABLED) 1953aa43c215SJeff Kirsher vlan_id = first_desc->vlan_TCI; 1954aa43c215SJeff Kirsher memcpy(&src_addr, phdr->h_source, ETH_ALEN); 1955aa43c215SJeff Kirsher hindex = QLCNIC_MAC_HASH(src_addr) & (QLCNIC_LB_MAX_FILTERS - 1); 1956aa43c215SJeff Kirsher head = &(adapter->fhash.fhead[hindex]); 1957aa43c215SJeff Kirsher 1958aa43c215SJeff Kirsher hlist_for_each_entry_safe(tmp_fil, tmp_hnode, n, head, fnode) { 1959aa43c215SJeff Kirsher if (!memcmp(tmp_fil->faddr, &src_addr, ETH_ALEN) && 1960aa43c215SJeff Kirsher tmp_fil->vlan_id == vlan_id) { 1961aa43c215SJeff Kirsher 1962aa43c215SJeff Kirsher if (jiffies > 1963aa43c215SJeff Kirsher (QLCNIC_READD_AGE * HZ + tmp_fil->ftime)) 1964aa43c215SJeff Kirsher qlcnic_change_filter(adapter, src_addr, vlan_id, 1965aa43c215SJeff Kirsher tx_ring); 1966aa43c215SJeff Kirsher tmp_fil->ftime = jiffies; 1967aa43c215SJeff Kirsher return; 1968aa43c215SJeff Kirsher } 1969aa43c215SJeff Kirsher } 1970aa43c215SJeff Kirsher 1971aa43c215SJeff Kirsher fil = kzalloc(sizeof(struct qlcnic_filter), GFP_ATOMIC); 1972aa43c215SJeff Kirsher if (!fil) 1973aa43c215SJeff Kirsher return; 1974aa43c215SJeff Kirsher 1975aa43c215SJeff Kirsher qlcnic_change_filter(adapter, src_addr, vlan_id, tx_ring); 1976aa43c215SJeff Kirsher 1977aa43c215SJeff Kirsher fil->ftime = jiffies; 1978aa43c215SJeff Kirsher fil->vlan_id = vlan_id; 1979aa43c215SJeff Kirsher memcpy(fil->faddr, &src_addr, ETH_ALEN); 1980aa43c215SJeff Kirsher spin_lock(&adapter->mac_learn_lock); 1981aa43c215SJeff Kirsher hlist_add_head(&(fil->fnode), head); 1982aa43c215SJeff Kirsher adapter->fhash.fnum++; 1983aa43c215SJeff Kirsher spin_unlock(&adapter->mac_learn_lock); 1984aa43c215SJeff Kirsher } 1985aa43c215SJeff Kirsher 1986aa43c215SJeff Kirsher static int 1987aa43c215SJeff Kirsher qlcnic_tx_pkt(struct qlcnic_adapter *adapter, 1988aa43c215SJeff Kirsher struct cmd_desc_type0 *first_desc, 1989aa43c215SJeff Kirsher struct sk_buff *skb) 1990aa43c215SJeff Kirsher { 1991aa43c215SJeff Kirsher u8 opcode = 0, hdr_len = 0; 1992aa43c215SJeff Kirsher u16 flags = 0, vlan_tci = 0; 1993aa43c215SJeff Kirsher int copied, offset, copy_len; 1994aa43c215SJeff Kirsher struct cmd_desc_type0 *hwdesc; 1995aa43c215SJeff Kirsher struct vlan_ethhdr *vh; 1996aa43c215SJeff Kirsher struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring; 1997aa43c215SJeff Kirsher u16 protocol = ntohs(skb->protocol); 1998aa43c215SJeff Kirsher u32 producer = tx_ring->producer; 1999aa43c215SJeff Kirsher 2000aa43c215SJeff Kirsher if (protocol == ETH_P_8021Q) { 2001aa43c215SJeff Kirsher vh = (struct vlan_ethhdr *)skb->data; 2002aa43c215SJeff Kirsher flags = FLAGS_VLAN_TAGGED; 2003aa43c215SJeff Kirsher vlan_tci = vh->h_vlan_TCI; 2004aa43c215SJeff Kirsher } else if (vlan_tx_tag_present(skb)) { 2005aa43c215SJeff Kirsher flags = FLAGS_VLAN_OOB; 2006aa43c215SJeff Kirsher vlan_tci = vlan_tx_tag_get(skb); 2007aa43c215SJeff Kirsher } 2008aa43c215SJeff Kirsher if (unlikely(adapter->pvid)) { 2009aa43c215SJeff Kirsher if (vlan_tci && !(adapter->flags & QLCNIC_TAGGING_ENABLED)) 2010aa43c215SJeff Kirsher return -EIO; 2011aa43c215SJeff Kirsher if (vlan_tci && (adapter->flags & QLCNIC_TAGGING_ENABLED)) 2012aa43c215SJeff Kirsher goto set_flags; 2013aa43c215SJeff Kirsher 2014aa43c215SJeff Kirsher flags = FLAGS_VLAN_OOB; 2015aa43c215SJeff Kirsher vlan_tci = adapter->pvid; 2016aa43c215SJeff Kirsher } 2017aa43c215SJeff Kirsher set_flags: 2018aa43c215SJeff Kirsher qlcnic_set_tx_vlan_tci(first_desc, vlan_tci); 2019aa43c215SJeff Kirsher qlcnic_set_tx_flags_opcode(first_desc, flags, opcode); 2020aa43c215SJeff Kirsher 2021aa43c215SJeff Kirsher if (*(skb->data) & BIT_0) { 2022aa43c215SJeff Kirsher flags |= BIT_0; 2023aa43c215SJeff Kirsher memcpy(&first_desc->eth_addr, skb->data, ETH_ALEN); 2024aa43c215SJeff Kirsher } 2025aa43c215SJeff Kirsher opcode = TX_ETHER_PKT; 2026aa43c215SJeff Kirsher if ((adapter->netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) && 2027aa43c215SJeff Kirsher skb_shinfo(skb)->gso_size > 0) { 2028aa43c215SJeff Kirsher 2029aa43c215SJeff Kirsher hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); 2030aa43c215SJeff Kirsher 2031aa43c215SJeff Kirsher first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size); 2032aa43c215SJeff Kirsher first_desc->total_hdr_length = hdr_len; 2033aa43c215SJeff Kirsher 2034aa43c215SJeff Kirsher opcode = (protocol == ETH_P_IPV6) ? TX_TCP_LSO6 : TX_TCP_LSO; 2035aa43c215SJeff Kirsher 2036aa43c215SJeff Kirsher /* For LSO, we need to copy the MAC/IP/TCP headers into 2037aa43c215SJeff Kirsher * the descriptor ring */ 2038aa43c215SJeff Kirsher copied = 0; 2039aa43c215SJeff Kirsher offset = 2; 2040aa43c215SJeff Kirsher 2041aa43c215SJeff Kirsher if (flags & FLAGS_VLAN_OOB) { 2042aa43c215SJeff Kirsher first_desc->total_hdr_length += VLAN_HLEN; 2043aa43c215SJeff Kirsher first_desc->tcp_hdr_offset = VLAN_HLEN; 2044aa43c215SJeff Kirsher first_desc->ip_hdr_offset = VLAN_HLEN; 2045aa43c215SJeff Kirsher /* Only in case of TSO on vlan device */ 2046aa43c215SJeff Kirsher flags |= FLAGS_VLAN_TAGGED; 2047aa43c215SJeff Kirsher 2048aa43c215SJeff Kirsher /* Create a TSO vlan header template for firmware */ 2049aa43c215SJeff Kirsher 2050aa43c215SJeff Kirsher hwdesc = &tx_ring->desc_head[producer]; 2051aa43c215SJeff Kirsher tx_ring->cmd_buf_arr[producer].skb = NULL; 2052aa43c215SJeff Kirsher 2053aa43c215SJeff Kirsher copy_len = min((int)sizeof(struct cmd_desc_type0) - 2054aa43c215SJeff Kirsher offset, hdr_len + VLAN_HLEN); 2055aa43c215SJeff Kirsher 2056aa43c215SJeff Kirsher vh = (struct vlan_ethhdr *)((char *) hwdesc + 2); 2057aa43c215SJeff Kirsher skb_copy_from_linear_data(skb, vh, 12); 2058aa43c215SJeff Kirsher vh->h_vlan_proto = htons(ETH_P_8021Q); 2059aa43c215SJeff Kirsher vh->h_vlan_TCI = htons(vlan_tci); 2060aa43c215SJeff Kirsher 2061aa43c215SJeff Kirsher skb_copy_from_linear_data_offset(skb, 12, 2062aa43c215SJeff Kirsher (char *)vh + 16, copy_len - 16); 2063aa43c215SJeff Kirsher 2064aa43c215SJeff Kirsher copied = copy_len - VLAN_HLEN; 2065aa43c215SJeff Kirsher offset = 0; 2066aa43c215SJeff Kirsher 2067aa43c215SJeff Kirsher producer = get_next_index(producer, tx_ring->num_desc); 2068aa43c215SJeff Kirsher } 2069aa43c215SJeff Kirsher 2070aa43c215SJeff Kirsher while (copied < hdr_len) { 2071aa43c215SJeff Kirsher 2072aa43c215SJeff Kirsher copy_len = min((int)sizeof(struct cmd_desc_type0) - 2073aa43c215SJeff Kirsher offset, (hdr_len - copied)); 2074aa43c215SJeff Kirsher 2075aa43c215SJeff Kirsher hwdesc = &tx_ring->desc_head[producer]; 2076aa43c215SJeff Kirsher tx_ring->cmd_buf_arr[producer].skb = NULL; 2077aa43c215SJeff Kirsher 2078aa43c215SJeff Kirsher skb_copy_from_linear_data_offset(skb, copied, 2079aa43c215SJeff Kirsher (char *) hwdesc + offset, copy_len); 2080aa43c215SJeff Kirsher 2081aa43c215SJeff Kirsher copied += copy_len; 2082aa43c215SJeff Kirsher offset = 0; 2083aa43c215SJeff Kirsher 2084aa43c215SJeff Kirsher producer = get_next_index(producer, tx_ring->num_desc); 2085aa43c215SJeff Kirsher } 2086aa43c215SJeff Kirsher 2087aa43c215SJeff Kirsher tx_ring->producer = producer; 2088aa43c215SJeff Kirsher smp_mb(); 2089aa43c215SJeff Kirsher adapter->stats.lso_frames++; 2090aa43c215SJeff Kirsher 2091aa43c215SJeff Kirsher } else if (skb->ip_summed == CHECKSUM_PARTIAL) { 2092aa43c215SJeff Kirsher u8 l4proto; 2093aa43c215SJeff Kirsher 2094aa43c215SJeff Kirsher if (protocol == ETH_P_IP) { 2095aa43c215SJeff Kirsher l4proto = ip_hdr(skb)->protocol; 2096aa43c215SJeff Kirsher 2097aa43c215SJeff Kirsher if (l4proto == IPPROTO_TCP) 2098aa43c215SJeff Kirsher opcode = TX_TCP_PKT; 2099aa43c215SJeff Kirsher else if (l4proto == IPPROTO_UDP) 2100aa43c215SJeff Kirsher opcode = TX_UDP_PKT; 2101aa43c215SJeff Kirsher } else if (protocol == ETH_P_IPV6) { 2102aa43c215SJeff Kirsher l4proto = ipv6_hdr(skb)->nexthdr; 2103aa43c215SJeff Kirsher 2104aa43c215SJeff Kirsher if (l4proto == IPPROTO_TCP) 2105aa43c215SJeff Kirsher opcode = TX_TCPV6_PKT; 2106aa43c215SJeff Kirsher else if (l4proto == IPPROTO_UDP) 2107aa43c215SJeff Kirsher opcode = TX_UDPV6_PKT; 2108aa43c215SJeff Kirsher } 2109aa43c215SJeff Kirsher } 2110aa43c215SJeff Kirsher first_desc->tcp_hdr_offset += skb_transport_offset(skb); 2111aa43c215SJeff Kirsher first_desc->ip_hdr_offset += skb_network_offset(skb); 2112aa43c215SJeff Kirsher qlcnic_set_tx_flags_opcode(first_desc, flags, opcode); 2113aa43c215SJeff Kirsher 2114aa43c215SJeff Kirsher return 0; 2115aa43c215SJeff Kirsher } 2116aa43c215SJeff Kirsher 2117aa43c215SJeff Kirsher static int 2118aa43c215SJeff Kirsher qlcnic_map_tx_skb(struct pci_dev *pdev, 2119aa43c215SJeff Kirsher struct sk_buff *skb, struct qlcnic_cmd_buffer *pbuf) 2120aa43c215SJeff Kirsher { 2121aa43c215SJeff Kirsher struct qlcnic_skb_frag *nf; 2122aa43c215SJeff Kirsher struct skb_frag_struct *frag; 2123aa43c215SJeff Kirsher int i, nr_frags; 2124aa43c215SJeff Kirsher dma_addr_t map; 2125aa43c215SJeff Kirsher 2126aa43c215SJeff Kirsher nr_frags = skb_shinfo(skb)->nr_frags; 2127aa43c215SJeff Kirsher nf = &pbuf->frag_array[0]; 2128aa43c215SJeff Kirsher 2129aa43c215SJeff Kirsher map = pci_map_single(pdev, skb->data, 2130aa43c215SJeff Kirsher skb_headlen(skb), PCI_DMA_TODEVICE); 2131aa43c215SJeff Kirsher if (pci_dma_mapping_error(pdev, map)) 2132aa43c215SJeff Kirsher goto out_err; 2133aa43c215SJeff Kirsher 2134aa43c215SJeff Kirsher nf->dma = map; 2135aa43c215SJeff Kirsher nf->length = skb_headlen(skb); 2136aa43c215SJeff Kirsher 2137aa43c215SJeff Kirsher for (i = 0; i < nr_frags; i++) { 2138aa43c215SJeff Kirsher frag = &skb_shinfo(skb)->frags[i]; 2139aa43c215SJeff Kirsher nf = &pbuf->frag_array[i+1]; 2140aa43c215SJeff Kirsher 21419e903e08SEric Dumazet map = skb_frag_dma_map(&pdev->dev, frag, 0, skb_frag_size(frag), 21425d6bcdfeSIan Campbell DMA_TO_DEVICE); 21435d6bcdfeSIan Campbell if (dma_mapping_error(&pdev->dev, map)) 2144aa43c215SJeff Kirsher goto unwind; 2145aa43c215SJeff Kirsher 2146aa43c215SJeff Kirsher nf->dma = map; 21479e903e08SEric Dumazet nf->length = skb_frag_size(frag); 2148aa43c215SJeff Kirsher } 2149aa43c215SJeff Kirsher 2150aa43c215SJeff Kirsher return 0; 2151aa43c215SJeff Kirsher 2152aa43c215SJeff Kirsher unwind: 2153aa43c215SJeff Kirsher while (--i >= 0) { 2154aa43c215SJeff Kirsher nf = &pbuf->frag_array[i+1]; 2155aa43c215SJeff Kirsher pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE); 2156aa43c215SJeff Kirsher } 2157aa43c215SJeff Kirsher 2158aa43c215SJeff Kirsher nf = &pbuf->frag_array[0]; 2159aa43c215SJeff Kirsher pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE); 2160aa43c215SJeff Kirsher 2161aa43c215SJeff Kirsher out_err: 2162aa43c215SJeff Kirsher return -ENOMEM; 2163aa43c215SJeff Kirsher } 2164aa43c215SJeff Kirsher 2165aa43c215SJeff Kirsher static void 2166aa43c215SJeff Kirsher qlcnic_unmap_buffers(struct pci_dev *pdev, struct sk_buff *skb, 2167aa43c215SJeff Kirsher struct qlcnic_cmd_buffer *pbuf) 2168aa43c215SJeff Kirsher { 2169aa43c215SJeff Kirsher struct qlcnic_skb_frag *nf = &pbuf->frag_array[0]; 2170aa43c215SJeff Kirsher int nr_frags = skb_shinfo(skb)->nr_frags; 2171aa43c215SJeff Kirsher int i; 2172aa43c215SJeff Kirsher 2173aa43c215SJeff Kirsher for (i = 0; i < nr_frags; i++) { 2174aa43c215SJeff Kirsher nf = &pbuf->frag_array[i+1]; 2175aa43c215SJeff Kirsher pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE); 2176aa43c215SJeff Kirsher } 2177aa43c215SJeff Kirsher 2178aa43c215SJeff Kirsher nf = &pbuf->frag_array[0]; 2179aa43c215SJeff Kirsher pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE); 2180aa43c215SJeff Kirsher pbuf->skb = NULL; 2181aa43c215SJeff Kirsher } 2182aa43c215SJeff Kirsher 2183aa43c215SJeff Kirsher static inline void 2184aa43c215SJeff Kirsher qlcnic_clear_cmddesc(u64 *desc) 2185aa43c215SJeff Kirsher { 2186aa43c215SJeff Kirsher desc[0] = 0ULL; 2187aa43c215SJeff Kirsher desc[2] = 0ULL; 2188aa43c215SJeff Kirsher desc[7] = 0ULL; 2189aa43c215SJeff Kirsher } 2190aa43c215SJeff Kirsher 2191aa43c215SJeff Kirsher netdev_tx_t 2192aa43c215SJeff Kirsher qlcnic_xmit_frame(struct sk_buff *skb, struct net_device *netdev) 2193aa43c215SJeff Kirsher { 2194aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 2195aa43c215SJeff Kirsher struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring; 2196aa43c215SJeff Kirsher struct qlcnic_cmd_buffer *pbuf; 2197aa43c215SJeff Kirsher struct qlcnic_skb_frag *buffrag; 2198aa43c215SJeff Kirsher struct cmd_desc_type0 *hwdesc, *first_desc; 2199aa43c215SJeff Kirsher struct pci_dev *pdev; 2200aa43c215SJeff Kirsher struct ethhdr *phdr; 2201aa43c215SJeff Kirsher int delta = 0; 2202aa43c215SJeff Kirsher int i, k; 2203aa43c215SJeff Kirsher 2204aa43c215SJeff Kirsher u32 producer; 2205aa43c215SJeff Kirsher int frag_count; 2206aa43c215SJeff Kirsher u32 num_txd = tx_ring->num_desc; 2207aa43c215SJeff Kirsher 2208aa43c215SJeff Kirsher if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) { 2209aa43c215SJeff Kirsher netif_stop_queue(netdev); 2210aa43c215SJeff Kirsher return NETDEV_TX_BUSY; 2211aa43c215SJeff Kirsher } 2212aa43c215SJeff Kirsher 2213aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_MACSPOOF) { 2214aa43c215SJeff Kirsher phdr = (struct ethhdr *)skb->data; 2215aa43c215SJeff Kirsher if (compare_ether_addr(phdr->h_source, 2216aa43c215SJeff Kirsher adapter->mac_addr)) 2217aa43c215SJeff Kirsher goto drop_packet; 2218aa43c215SJeff Kirsher } 2219aa43c215SJeff Kirsher 2220aa43c215SJeff Kirsher frag_count = skb_shinfo(skb)->nr_frags + 1; 2221aa43c215SJeff Kirsher /* 14 frags supported for normal packet and 2222aa43c215SJeff Kirsher * 32 frags supported for TSO packet 2223aa43c215SJeff Kirsher */ 2224aa43c215SJeff Kirsher if (!skb_is_gso(skb) && frag_count > QLCNIC_MAX_FRAGS_PER_TX) { 2225aa43c215SJeff Kirsher 2226aa43c215SJeff Kirsher for (i = 0; i < (frag_count - QLCNIC_MAX_FRAGS_PER_TX); i++) 22279e903e08SEric Dumazet delta += skb_frag_size(&skb_shinfo(skb)->frags[i]); 2228aa43c215SJeff Kirsher 2229aa43c215SJeff Kirsher if (!__pskb_pull_tail(skb, delta)) 2230aa43c215SJeff Kirsher goto drop_packet; 2231aa43c215SJeff Kirsher 2232aa43c215SJeff Kirsher frag_count = 1 + skb_shinfo(skb)->nr_frags; 2233aa43c215SJeff Kirsher } 2234aa43c215SJeff Kirsher 2235aa43c215SJeff Kirsher if (unlikely(qlcnic_tx_avail(tx_ring) <= TX_STOP_THRESH)) { 2236aa43c215SJeff Kirsher netif_stop_queue(netdev); 2237aa43c215SJeff Kirsher if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH) 2238aa43c215SJeff Kirsher netif_start_queue(netdev); 2239aa43c215SJeff Kirsher else { 2240aa43c215SJeff Kirsher adapter->stats.xmit_off++; 2241aa43c215SJeff Kirsher return NETDEV_TX_BUSY; 2242aa43c215SJeff Kirsher } 2243aa43c215SJeff Kirsher } 2244aa43c215SJeff Kirsher 2245aa43c215SJeff Kirsher producer = tx_ring->producer; 2246aa43c215SJeff Kirsher pbuf = &tx_ring->cmd_buf_arr[producer]; 2247aa43c215SJeff Kirsher 2248aa43c215SJeff Kirsher pdev = adapter->pdev; 2249aa43c215SJeff Kirsher 2250aa43c215SJeff Kirsher first_desc = hwdesc = &tx_ring->desc_head[producer]; 2251aa43c215SJeff Kirsher qlcnic_clear_cmddesc((u64 *)hwdesc); 2252aa43c215SJeff Kirsher 2253aa43c215SJeff Kirsher if (qlcnic_map_tx_skb(pdev, skb, pbuf)) { 2254aa43c215SJeff Kirsher adapter->stats.tx_dma_map_error++; 2255aa43c215SJeff Kirsher goto drop_packet; 2256aa43c215SJeff Kirsher } 2257aa43c215SJeff Kirsher 2258aa43c215SJeff Kirsher pbuf->skb = skb; 2259aa43c215SJeff Kirsher pbuf->frag_count = frag_count; 2260aa43c215SJeff Kirsher 2261aa43c215SJeff Kirsher qlcnic_set_tx_frags_len(first_desc, frag_count, skb->len); 2262aa43c215SJeff Kirsher qlcnic_set_tx_port(first_desc, adapter->portnum); 2263aa43c215SJeff Kirsher 2264aa43c215SJeff Kirsher for (i = 0; i < frag_count; i++) { 2265aa43c215SJeff Kirsher 2266aa43c215SJeff Kirsher k = i % 4; 2267aa43c215SJeff Kirsher 2268aa43c215SJeff Kirsher if ((k == 0) && (i > 0)) { 2269aa43c215SJeff Kirsher /* move to next desc.*/ 2270aa43c215SJeff Kirsher producer = get_next_index(producer, num_txd); 2271aa43c215SJeff Kirsher hwdesc = &tx_ring->desc_head[producer]; 2272aa43c215SJeff Kirsher qlcnic_clear_cmddesc((u64 *)hwdesc); 2273aa43c215SJeff Kirsher tx_ring->cmd_buf_arr[producer].skb = NULL; 2274aa43c215SJeff Kirsher } 2275aa43c215SJeff Kirsher 2276aa43c215SJeff Kirsher buffrag = &pbuf->frag_array[i]; 2277aa43c215SJeff Kirsher 2278aa43c215SJeff Kirsher hwdesc->buffer_length[k] = cpu_to_le16(buffrag->length); 2279aa43c215SJeff Kirsher switch (k) { 2280aa43c215SJeff Kirsher case 0: 2281aa43c215SJeff Kirsher hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma); 2282aa43c215SJeff Kirsher break; 2283aa43c215SJeff Kirsher case 1: 2284aa43c215SJeff Kirsher hwdesc->addr_buffer2 = cpu_to_le64(buffrag->dma); 2285aa43c215SJeff Kirsher break; 2286aa43c215SJeff Kirsher case 2: 2287aa43c215SJeff Kirsher hwdesc->addr_buffer3 = cpu_to_le64(buffrag->dma); 2288aa43c215SJeff Kirsher break; 2289aa43c215SJeff Kirsher case 3: 2290aa43c215SJeff Kirsher hwdesc->addr_buffer4 = cpu_to_le64(buffrag->dma); 2291aa43c215SJeff Kirsher break; 2292aa43c215SJeff Kirsher } 2293aa43c215SJeff Kirsher } 2294aa43c215SJeff Kirsher 2295aa43c215SJeff Kirsher tx_ring->producer = get_next_index(producer, num_txd); 2296aa43c215SJeff Kirsher smp_mb(); 2297aa43c215SJeff Kirsher 2298aa43c215SJeff Kirsher if (unlikely(qlcnic_tx_pkt(adapter, first_desc, skb))) 2299aa43c215SJeff Kirsher goto unwind_buff; 2300aa43c215SJeff Kirsher 2301aa43c215SJeff Kirsher if (adapter->mac_learn) 2302aa43c215SJeff Kirsher qlcnic_send_filter(adapter, tx_ring, first_desc, skb); 2303aa43c215SJeff Kirsher 2304aa43c215SJeff Kirsher adapter->stats.txbytes += skb->len; 2305aa43c215SJeff Kirsher adapter->stats.xmitcalled++; 2306aa43c215SJeff Kirsher 2307aa43c215SJeff Kirsher qlcnic_update_cmd_producer(adapter, tx_ring); 2308aa43c215SJeff Kirsher 2309aa43c215SJeff Kirsher return NETDEV_TX_OK; 2310aa43c215SJeff Kirsher 2311aa43c215SJeff Kirsher unwind_buff: 2312aa43c215SJeff Kirsher qlcnic_unmap_buffers(pdev, skb, pbuf); 2313aa43c215SJeff Kirsher drop_packet: 2314aa43c215SJeff Kirsher adapter->stats.txdropped++; 2315aa43c215SJeff Kirsher dev_kfree_skb_any(skb); 2316aa43c215SJeff Kirsher return NETDEV_TX_OK; 2317aa43c215SJeff Kirsher } 2318aa43c215SJeff Kirsher 2319aa43c215SJeff Kirsher static int qlcnic_check_temp(struct qlcnic_adapter *adapter) 2320aa43c215SJeff Kirsher { 2321aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 2322aa43c215SJeff Kirsher u32 temp, temp_state, temp_val; 2323aa43c215SJeff Kirsher int rv = 0; 2324aa43c215SJeff Kirsher 2325aa43c215SJeff Kirsher temp = QLCRD32(adapter, CRB_TEMP_STATE); 2326aa43c215SJeff Kirsher 2327aa43c215SJeff Kirsher temp_state = qlcnic_get_temp_state(temp); 2328aa43c215SJeff Kirsher temp_val = qlcnic_get_temp_val(temp); 2329aa43c215SJeff Kirsher 2330aa43c215SJeff Kirsher if (temp_state == QLCNIC_TEMP_PANIC) { 2331aa43c215SJeff Kirsher dev_err(&netdev->dev, 2332aa43c215SJeff Kirsher "Device temperature %d degrees C exceeds" 2333aa43c215SJeff Kirsher " maximum allowed. Hardware has been shut down.\n", 2334aa43c215SJeff Kirsher temp_val); 2335aa43c215SJeff Kirsher rv = 1; 2336aa43c215SJeff Kirsher } else if (temp_state == QLCNIC_TEMP_WARN) { 2337aa43c215SJeff Kirsher if (adapter->temp == QLCNIC_TEMP_NORMAL) { 2338aa43c215SJeff Kirsher dev_err(&netdev->dev, 2339aa43c215SJeff Kirsher "Device temperature %d degrees C " 2340aa43c215SJeff Kirsher "exceeds operating range." 2341aa43c215SJeff Kirsher " Immediate action needed.\n", 2342aa43c215SJeff Kirsher temp_val); 2343aa43c215SJeff Kirsher } 2344aa43c215SJeff Kirsher } else { 2345aa43c215SJeff Kirsher if (adapter->temp == QLCNIC_TEMP_WARN) { 2346aa43c215SJeff Kirsher dev_info(&netdev->dev, 2347aa43c215SJeff Kirsher "Device temperature is now %d degrees C" 2348aa43c215SJeff Kirsher " in normal range.\n", temp_val); 2349aa43c215SJeff Kirsher } 2350aa43c215SJeff Kirsher } 2351aa43c215SJeff Kirsher adapter->temp = temp_state; 2352aa43c215SJeff Kirsher return rv; 2353aa43c215SJeff Kirsher } 2354aa43c215SJeff Kirsher 2355aa43c215SJeff Kirsher void qlcnic_advert_link_change(struct qlcnic_adapter *adapter, int linkup) 2356aa43c215SJeff Kirsher { 2357aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 2358aa43c215SJeff Kirsher 2359aa43c215SJeff Kirsher if (adapter->ahw->linkup && !linkup) { 2360aa43c215SJeff Kirsher netdev_info(netdev, "NIC Link is down\n"); 2361aa43c215SJeff Kirsher adapter->ahw->linkup = 0; 2362aa43c215SJeff Kirsher if (netif_running(netdev)) { 2363aa43c215SJeff Kirsher netif_carrier_off(netdev); 2364aa43c215SJeff Kirsher netif_stop_queue(netdev); 2365aa43c215SJeff Kirsher } 2366aa43c215SJeff Kirsher } else if (!adapter->ahw->linkup && linkup) { 2367aa43c215SJeff Kirsher netdev_info(netdev, "NIC Link is up\n"); 2368aa43c215SJeff Kirsher adapter->ahw->linkup = 1; 2369aa43c215SJeff Kirsher if (netif_running(netdev)) { 2370aa43c215SJeff Kirsher netif_carrier_on(netdev); 2371aa43c215SJeff Kirsher netif_wake_queue(netdev); 2372aa43c215SJeff Kirsher } 2373aa43c215SJeff Kirsher } 2374aa43c215SJeff Kirsher } 2375aa43c215SJeff Kirsher 2376aa43c215SJeff Kirsher static void qlcnic_tx_timeout(struct net_device *netdev) 2377aa43c215SJeff Kirsher { 2378aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 2379aa43c215SJeff Kirsher 2380aa43c215SJeff Kirsher if (test_bit(__QLCNIC_RESETTING, &adapter->state)) 2381aa43c215SJeff Kirsher return; 2382aa43c215SJeff Kirsher 2383aa43c215SJeff Kirsher dev_err(&netdev->dev, "transmit timeout, resetting.\n"); 2384aa43c215SJeff Kirsher 2385aa43c215SJeff Kirsher if (++adapter->tx_timeo_cnt >= QLCNIC_MAX_TX_TIMEOUTS) 2386aa43c215SJeff Kirsher adapter->need_fw_reset = 1; 2387aa43c215SJeff Kirsher else 2388aa43c215SJeff Kirsher adapter->reset_context = 1; 2389aa43c215SJeff Kirsher } 2390aa43c215SJeff Kirsher 2391aa43c215SJeff Kirsher static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev) 2392aa43c215SJeff Kirsher { 2393aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 2394aa43c215SJeff Kirsher struct net_device_stats *stats = &netdev->stats; 2395aa43c215SJeff Kirsher 2396aa43c215SJeff Kirsher stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts; 2397aa43c215SJeff Kirsher stats->tx_packets = adapter->stats.xmitfinished; 2398aa43c215SJeff Kirsher stats->rx_bytes = adapter->stats.rxbytes + adapter->stats.lrobytes; 2399aa43c215SJeff Kirsher stats->tx_bytes = adapter->stats.txbytes; 2400aa43c215SJeff Kirsher stats->rx_dropped = adapter->stats.rxdropped; 2401aa43c215SJeff Kirsher stats->tx_dropped = adapter->stats.txdropped; 2402aa43c215SJeff Kirsher 2403aa43c215SJeff Kirsher return stats; 2404aa43c215SJeff Kirsher } 2405aa43c215SJeff Kirsher 2406aa43c215SJeff Kirsher static irqreturn_t qlcnic_clear_legacy_intr(struct qlcnic_adapter *adapter) 2407aa43c215SJeff Kirsher { 2408aa43c215SJeff Kirsher u32 status; 2409aa43c215SJeff Kirsher 2410aa43c215SJeff Kirsher status = readl(adapter->isr_int_vec); 2411aa43c215SJeff Kirsher 2412aa43c215SJeff Kirsher if (!(status & adapter->int_vec_bit)) 2413aa43c215SJeff Kirsher return IRQ_NONE; 2414aa43c215SJeff Kirsher 2415aa43c215SJeff Kirsher /* check interrupt state machine, to be sure */ 2416aa43c215SJeff Kirsher status = readl(adapter->crb_int_state_reg); 2417aa43c215SJeff Kirsher if (!ISR_LEGACY_INT_TRIGGERED(status)) 2418aa43c215SJeff Kirsher return IRQ_NONE; 2419aa43c215SJeff Kirsher 2420aa43c215SJeff Kirsher writel(0xffffffff, adapter->tgt_status_reg); 2421aa43c215SJeff Kirsher /* read twice to ensure write is flushed */ 2422aa43c215SJeff Kirsher readl(adapter->isr_int_vec); 2423aa43c215SJeff Kirsher readl(adapter->isr_int_vec); 2424aa43c215SJeff Kirsher 2425aa43c215SJeff Kirsher return IRQ_HANDLED; 2426aa43c215SJeff Kirsher } 2427aa43c215SJeff Kirsher 2428aa43c215SJeff Kirsher static irqreturn_t qlcnic_tmp_intr(int irq, void *data) 2429aa43c215SJeff Kirsher { 2430aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring = data; 2431aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = sds_ring->adapter; 2432aa43c215SJeff Kirsher 2433aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_MSIX_ENABLED) 2434aa43c215SJeff Kirsher goto done; 2435aa43c215SJeff Kirsher else if (adapter->flags & QLCNIC_MSI_ENABLED) { 2436aa43c215SJeff Kirsher writel(0xffffffff, adapter->tgt_status_reg); 2437aa43c215SJeff Kirsher goto done; 2438aa43c215SJeff Kirsher } 2439aa43c215SJeff Kirsher 2440aa43c215SJeff Kirsher if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE) 2441aa43c215SJeff Kirsher return IRQ_NONE; 2442aa43c215SJeff Kirsher 2443aa43c215SJeff Kirsher done: 2444aa43c215SJeff Kirsher adapter->diag_cnt++; 2445aa43c215SJeff Kirsher qlcnic_enable_int(sds_ring); 2446aa43c215SJeff Kirsher return IRQ_HANDLED; 2447aa43c215SJeff Kirsher } 2448aa43c215SJeff Kirsher 2449aa43c215SJeff Kirsher static irqreturn_t qlcnic_intr(int irq, void *data) 2450aa43c215SJeff Kirsher { 2451aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring = data; 2452aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = sds_ring->adapter; 2453aa43c215SJeff Kirsher 2454aa43c215SJeff Kirsher if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE) 2455aa43c215SJeff Kirsher return IRQ_NONE; 2456aa43c215SJeff Kirsher 2457aa43c215SJeff Kirsher napi_schedule(&sds_ring->napi); 2458aa43c215SJeff Kirsher 2459aa43c215SJeff Kirsher return IRQ_HANDLED; 2460aa43c215SJeff Kirsher } 2461aa43c215SJeff Kirsher 2462aa43c215SJeff Kirsher static irqreturn_t qlcnic_msi_intr(int irq, void *data) 2463aa43c215SJeff Kirsher { 2464aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring = data; 2465aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = sds_ring->adapter; 2466aa43c215SJeff Kirsher 2467aa43c215SJeff Kirsher /* clear interrupt */ 2468aa43c215SJeff Kirsher writel(0xffffffff, adapter->tgt_status_reg); 2469aa43c215SJeff Kirsher 2470aa43c215SJeff Kirsher napi_schedule(&sds_ring->napi); 2471aa43c215SJeff Kirsher return IRQ_HANDLED; 2472aa43c215SJeff Kirsher } 2473aa43c215SJeff Kirsher 2474aa43c215SJeff Kirsher static irqreturn_t qlcnic_msix_intr(int irq, void *data) 2475aa43c215SJeff Kirsher { 2476aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring = data; 2477aa43c215SJeff Kirsher 2478aa43c215SJeff Kirsher napi_schedule(&sds_ring->napi); 2479aa43c215SJeff Kirsher return IRQ_HANDLED; 2480aa43c215SJeff Kirsher } 2481aa43c215SJeff Kirsher 2482aa43c215SJeff Kirsher static int qlcnic_process_cmd_ring(struct qlcnic_adapter *adapter) 2483aa43c215SJeff Kirsher { 2484aa43c215SJeff Kirsher u32 sw_consumer, hw_consumer; 2485aa43c215SJeff Kirsher int count = 0, i; 2486aa43c215SJeff Kirsher struct qlcnic_cmd_buffer *buffer; 2487aa43c215SJeff Kirsher struct pci_dev *pdev = adapter->pdev; 2488aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 2489aa43c215SJeff Kirsher struct qlcnic_skb_frag *frag; 2490aa43c215SJeff Kirsher int done; 2491aa43c215SJeff Kirsher struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring; 2492aa43c215SJeff Kirsher 2493aa43c215SJeff Kirsher if (!spin_trylock(&adapter->tx_clean_lock)) 2494aa43c215SJeff Kirsher return 1; 2495aa43c215SJeff Kirsher 2496aa43c215SJeff Kirsher sw_consumer = tx_ring->sw_consumer; 2497aa43c215SJeff Kirsher hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer)); 2498aa43c215SJeff Kirsher 2499aa43c215SJeff Kirsher while (sw_consumer != hw_consumer) { 2500aa43c215SJeff Kirsher buffer = &tx_ring->cmd_buf_arr[sw_consumer]; 2501aa43c215SJeff Kirsher if (buffer->skb) { 2502aa43c215SJeff Kirsher frag = &buffer->frag_array[0]; 2503aa43c215SJeff Kirsher pci_unmap_single(pdev, frag->dma, frag->length, 2504aa43c215SJeff Kirsher PCI_DMA_TODEVICE); 2505aa43c215SJeff Kirsher frag->dma = 0ULL; 2506aa43c215SJeff Kirsher for (i = 1; i < buffer->frag_count; i++) { 2507aa43c215SJeff Kirsher frag++; 2508aa43c215SJeff Kirsher pci_unmap_page(pdev, frag->dma, frag->length, 2509aa43c215SJeff Kirsher PCI_DMA_TODEVICE); 2510aa43c215SJeff Kirsher frag->dma = 0ULL; 2511aa43c215SJeff Kirsher } 2512aa43c215SJeff Kirsher 2513aa43c215SJeff Kirsher adapter->stats.xmitfinished++; 2514aa43c215SJeff Kirsher dev_kfree_skb_any(buffer->skb); 2515aa43c215SJeff Kirsher buffer->skb = NULL; 2516aa43c215SJeff Kirsher } 2517aa43c215SJeff Kirsher 2518aa43c215SJeff Kirsher sw_consumer = get_next_index(sw_consumer, tx_ring->num_desc); 2519aa43c215SJeff Kirsher if (++count >= MAX_STATUS_HANDLE) 2520aa43c215SJeff Kirsher break; 2521aa43c215SJeff Kirsher } 2522aa43c215SJeff Kirsher 2523aa43c215SJeff Kirsher if (count && netif_running(netdev)) { 2524aa43c215SJeff Kirsher tx_ring->sw_consumer = sw_consumer; 2525aa43c215SJeff Kirsher 2526aa43c215SJeff Kirsher smp_mb(); 2527aa43c215SJeff Kirsher 2528aa43c215SJeff Kirsher if (netif_queue_stopped(netdev) && netif_carrier_ok(netdev)) { 2529aa43c215SJeff Kirsher if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH) { 2530aa43c215SJeff Kirsher netif_wake_queue(netdev); 2531aa43c215SJeff Kirsher adapter->stats.xmit_on++; 2532aa43c215SJeff Kirsher } 2533aa43c215SJeff Kirsher } 2534aa43c215SJeff Kirsher adapter->tx_timeo_cnt = 0; 2535aa43c215SJeff Kirsher } 2536aa43c215SJeff Kirsher /* 2537aa43c215SJeff Kirsher * If everything is freed up to consumer then check if the ring is full 2538aa43c215SJeff Kirsher * If the ring is full then check if more needs to be freed and 2539aa43c215SJeff Kirsher * schedule the call back again. 2540aa43c215SJeff Kirsher * 2541aa43c215SJeff Kirsher * This happens when there are 2 CPUs. One could be freeing and the 2542aa43c215SJeff Kirsher * other filling it. If the ring is full when we get out of here and 2543aa43c215SJeff Kirsher * the card has already interrupted the host then the host can miss the 2544aa43c215SJeff Kirsher * interrupt. 2545aa43c215SJeff Kirsher * 2546aa43c215SJeff Kirsher * There is still a possible race condition and the host could miss an 2547aa43c215SJeff Kirsher * interrupt. The card has to take care of this. 2548aa43c215SJeff Kirsher */ 2549aa43c215SJeff Kirsher hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer)); 2550aa43c215SJeff Kirsher done = (sw_consumer == hw_consumer); 2551aa43c215SJeff Kirsher spin_unlock(&adapter->tx_clean_lock); 2552aa43c215SJeff Kirsher 2553aa43c215SJeff Kirsher return done; 2554aa43c215SJeff Kirsher } 2555aa43c215SJeff Kirsher 2556aa43c215SJeff Kirsher static int qlcnic_poll(struct napi_struct *napi, int budget) 2557aa43c215SJeff Kirsher { 2558aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring = 2559aa43c215SJeff Kirsher container_of(napi, struct qlcnic_host_sds_ring, napi); 2560aa43c215SJeff Kirsher 2561aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = sds_ring->adapter; 2562aa43c215SJeff Kirsher 2563aa43c215SJeff Kirsher int tx_complete; 2564aa43c215SJeff Kirsher int work_done; 2565aa43c215SJeff Kirsher 2566aa43c215SJeff Kirsher tx_complete = qlcnic_process_cmd_ring(adapter); 2567aa43c215SJeff Kirsher 2568aa43c215SJeff Kirsher work_done = qlcnic_process_rcv_ring(sds_ring, budget); 2569aa43c215SJeff Kirsher 2570aa43c215SJeff Kirsher if ((work_done < budget) && tx_complete) { 2571aa43c215SJeff Kirsher napi_complete(&sds_ring->napi); 2572aa43c215SJeff Kirsher if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) 2573aa43c215SJeff Kirsher qlcnic_enable_int(sds_ring); 2574aa43c215SJeff Kirsher } 2575aa43c215SJeff Kirsher 2576aa43c215SJeff Kirsher return work_done; 2577aa43c215SJeff Kirsher } 2578aa43c215SJeff Kirsher 2579aa43c215SJeff Kirsher static int qlcnic_rx_poll(struct napi_struct *napi, int budget) 2580aa43c215SJeff Kirsher { 2581aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring = 2582aa43c215SJeff Kirsher container_of(napi, struct qlcnic_host_sds_ring, napi); 2583aa43c215SJeff Kirsher 2584aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = sds_ring->adapter; 2585aa43c215SJeff Kirsher int work_done; 2586aa43c215SJeff Kirsher 2587aa43c215SJeff Kirsher work_done = qlcnic_process_rcv_ring(sds_ring, budget); 2588aa43c215SJeff Kirsher 2589aa43c215SJeff Kirsher if (work_done < budget) { 2590aa43c215SJeff Kirsher napi_complete(&sds_ring->napi); 2591aa43c215SJeff Kirsher if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) 2592aa43c215SJeff Kirsher qlcnic_enable_int(sds_ring); 2593aa43c215SJeff Kirsher } 2594aa43c215SJeff Kirsher 2595aa43c215SJeff Kirsher return work_done; 2596aa43c215SJeff Kirsher } 2597aa43c215SJeff Kirsher 2598aa43c215SJeff Kirsher #ifdef CONFIG_NET_POLL_CONTROLLER 2599aa43c215SJeff Kirsher static void qlcnic_poll_controller(struct net_device *netdev) 2600aa43c215SJeff Kirsher { 2601aa43c215SJeff Kirsher int ring; 2602aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring; 2603aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 2604aa43c215SJeff Kirsher struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; 2605aa43c215SJeff Kirsher 2606aa43c215SJeff Kirsher disable_irq(adapter->irq); 2607aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_sds_rings; ring++) { 2608aa43c215SJeff Kirsher sds_ring = &recv_ctx->sds_rings[ring]; 2609aa43c215SJeff Kirsher qlcnic_intr(adapter->irq, sds_ring); 2610aa43c215SJeff Kirsher } 2611aa43c215SJeff Kirsher enable_irq(adapter->irq); 2612aa43c215SJeff Kirsher } 2613aa43c215SJeff Kirsher #endif 2614aa43c215SJeff Kirsher 2615aa43c215SJeff Kirsher static void 2616aa43c215SJeff Kirsher qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding) 2617aa43c215SJeff Kirsher { 2618aa43c215SJeff Kirsher u32 val; 2619aa43c215SJeff Kirsher 2620aa43c215SJeff Kirsher val = adapter->portnum & 0xf; 2621aa43c215SJeff Kirsher val |= encoding << 7; 2622aa43c215SJeff Kirsher val |= (jiffies - adapter->dev_rst_time) << 8; 2623aa43c215SJeff Kirsher 2624aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DRV_SCRATCH, val); 2625aa43c215SJeff Kirsher adapter->dev_rst_time = jiffies; 2626aa43c215SJeff Kirsher } 2627aa43c215SJeff Kirsher 2628aa43c215SJeff Kirsher static int 2629aa43c215SJeff Kirsher qlcnic_set_drv_state(struct qlcnic_adapter *adapter, u8 state) 2630aa43c215SJeff Kirsher { 2631aa43c215SJeff Kirsher u32 val; 2632aa43c215SJeff Kirsher 2633aa43c215SJeff Kirsher WARN_ON(state != QLCNIC_DEV_NEED_RESET && 2634aa43c215SJeff Kirsher state != QLCNIC_DEV_NEED_QUISCENT); 2635aa43c215SJeff Kirsher 2636aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2637aa43c215SJeff Kirsher return -EIO; 2638aa43c215SJeff Kirsher 2639aa43c215SJeff Kirsher val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); 2640aa43c215SJeff Kirsher 2641aa43c215SJeff Kirsher if (state == QLCNIC_DEV_NEED_RESET) 2642aa43c215SJeff Kirsher QLC_DEV_SET_RST_RDY(val, adapter->portnum); 2643aa43c215SJeff Kirsher else if (state == QLCNIC_DEV_NEED_QUISCENT) 2644aa43c215SJeff Kirsher QLC_DEV_SET_QSCNT_RDY(val, adapter->portnum); 2645aa43c215SJeff Kirsher 2646aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); 2647aa43c215SJeff Kirsher 2648aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2649aa43c215SJeff Kirsher 2650aa43c215SJeff Kirsher return 0; 2651aa43c215SJeff Kirsher } 2652aa43c215SJeff Kirsher 2653aa43c215SJeff Kirsher static int 2654aa43c215SJeff Kirsher qlcnic_clr_drv_state(struct qlcnic_adapter *adapter) 2655aa43c215SJeff Kirsher { 2656aa43c215SJeff Kirsher u32 val; 2657aa43c215SJeff Kirsher 2658aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2659aa43c215SJeff Kirsher return -EBUSY; 2660aa43c215SJeff Kirsher 2661aa43c215SJeff Kirsher val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); 2662aa43c215SJeff Kirsher QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum); 2663aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); 2664aa43c215SJeff Kirsher 2665aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2666aa43c215SJeff Kirsher 2667aa43c215SJeff Kirsher return 0; 2668aa43c215SJeff Kirsher } 2669aa43c215SJeff Kirsher 2670aa43c215SJeff Kirsher static void 2671aa43c215SJeff Kirsher qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8 failed) 2672aa43c215SJeff Kirsher { 2673aa43c215SJeff Kirsher u32 val; 2674aa43c215SJeff Kirsher 2675aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2676aa43c215SJeff Kirsher goto err; 2677aa43c215SJeff Kirsher 2678aa43c215SJeff Kirsher val = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE); 2679aa43c215SJeff Kirsher QLC_DEV_CLR_REF_CNT(val, adapter->portnum); 2680aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val); 2681aa43c215SJeff Kirsher 2682aa43c215SJeff Kirsher if (failed) { 2683aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED); 2684aa43c215SJeff Kirsher dev_info(&adapter->pdev->dev, 2685aa43c215SJeff Kirsher "Device state set to Failed. Please Reboot\n"); 2686aa43c215SJeff Kirsher } else if (!(val & 0x11111111)) 2687aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_COLD); 2688aa43c215SJeff Kirsher 2689aa43c215SJeff Kirsher val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); 2690aa43c215SJeff Kirsher QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum); 2691aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); 2692aa43c215SJeff Kirsher 2693aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2694aa43c215SJeff Kirsher err: 2695aa43c215SJeff Kirsher adapter->fw_fail_cnt = 0; 2696aa43c215SJeff Kirsher adapter->flags &= ~QLCNIC_FW_HANG; 2697aa43c215SJeff Kirsher clear_bit(__QLCNIC_START_FW, &adapter->state); 2698aa43c215SJeff Kirsher clear_bit(__QLCNIC_RESETTING, &adapter->state); 2699aa43c215SJeff Kirsher } 2700aa43c215SJeff Kirsher 2701aa43c215SJeff Kirsher /* Grab api lock, before checking state */ 2702aa43c215SJeff Kirsher static int 2703aa43c215SJeff Kirsher qlcnic_check_drv_state(struct qlcnic_adapter *adapter) 2704aa43c215SJeff Kirsher { 2705aa43c215SJeff Kirsher int act, state, active_mask; 2706aa43c215SJeff Kirsher 2707aa43c215SJeff Kirsher state = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); 2708aa43c215SJeff Kirsher act = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE); 2709aa43c215SJeff Kirsher 2710aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_FW_RESET_OWNER) { 2711aa43c215SJeff Kirsher active_mask = (~(1 << (adapter->ahw->pci_func * 4))); 2712aa43c215SJeff Kirsher act = act & active_mask; 2713aa43c215SJeff Kirsher } 2714aa43c215SJeff Kirsher 2715aa43c215SJeff Kirsher if (((state & 0x11111111) == (act & 0x11111111)) || 2716aa43c215SJeff Kirsher ((act & 0x11111111) == ((state >> 1) & 0x11111111))) 2717aa43c215SJeff Kirsher return 0; 2718aa43c215SJeff Kirsher else 2719aa43c215SJeff Kirsher return 1; 2720aa43c215SJeff Kirsher } 2721aa43c215SJeff Kirsher 2722aa43c215SJeff Kirsher static int qlcnic_check_idc_ver(struct qlcnic_adapter *adapter) 2723aa43c215SJeff Kirsher { 2724aa43c215SJeff Kirsher u32 val = QLCRD32(adapter, QLCNIC_CRB_DRV_IDC_VER); 2725aa43c215SJeff Kirsher 2726aa43c215SJeff Kirsher if (val != QLCNIC_DRV_IDC_VER) { 2727aa43c215SJeff Kirsher dev_warn(&adapter->pdev->dev, "IDC Version mismatch, driver's" 2728aa43c215SJeff Kirsher " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER, val); 2729aa43c215SJeff Kirsher } 2730aa43c215SJeff Kirsher 2731aa43c215SJeff Kirsher return 0; 2732aa43c215SJeff Kirsher } 2733aa43c215SJeff Kirsher 2734aa43c215SJeff Kirsher static int 2735aa43c215SJeff Kirsher qlcnic_can_start_firmware(struct qlcnic_adapter *adapter) 2736aa43c215SJeff Kirsher { 2737aa43c215SJeff Kirsher u32 val, prev_state; 2738aa43c215SJeff Kirsher u8 dev_init_timeo = adapter->dev_init_timeo; 2739aa43c215SJeff Kirsher u8 portnum = adapter->portnum; 2740aa43c215SJeff Kirsher u8 ret; 2741aa43c215SJeff Kirsher 2742aa43c215SJeff Kirsher if (test_and_clear_bit(__QLCNIC_START_FW, &adapter->state)) 2743aa43c215SJeff Kirsher return 1; 2744aa43c215SJeff Kirsher 2745aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2746aa43c215SJeff Kirsher return -1; 2747aa43c215SJeff Kirsher 2748aa43c215SJeff Kirsher val = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE); 2749aa43c215SJeff Kirsher if (!(val & (1 << (portnum * 4)))) { 2750aa43c215SJeff Kirsher QLC_DEV_SET_REF_CNT(val, portnum); 2751aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val); 2752aa43c215SJeff Kirsher } 2753aa43c215SJeff Kirsher 2754aa43c215SJeff Kirsher prev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); 2755aa43c215SJeff Kirsher QLCDB(adapter, HW, "Device state = %u\n", prev_state); 2756aa43c215SJeff Kirsher 2757aa43c215SJeff Kirsher switch (prev_state) { 2758aa43c215SJeff Kirsher case QLCNIC_DEV_COLD: 2759aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_INITIALIZING); 2760aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DRV_IDC_VER, QLCNIC_DRV_IDC_VER); 2761aa43c215SJeff Kirsher qlcnic_idc_debug_info(adapter, 0); 2762aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2763aa43c215SJeff Kirsher return 1; 2764aa43c215SJeff Kirsher 2765aa43c215SJeff Kirsher case QLCNIC_DEV_READY: 2766aa43c215SJeff Kirsher ret = qlcnic_check_idc_ver(adapter); 2767aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2768aa43c215SJeff Kirsher return ret; 2769aa43c215SJeff Kirsher 2770aa43c215SJeff Kirsher case QLCNIC_DEV_NEED_RESET: 2771aa43c215SJeff Kirsher val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); 2772aa43c215SJeff Kirsher QLC_DEV_SET_RST_RDY(val, portnum); 2773aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); 2774aa43c215SJeff Kirsher break; 2775aa43c215SJeff Kirsher 2776aa43c215SJeff Kirsher case QLCNIC_DEV_NEED_QUISCENT: 2777aa43c215SJeff Kirsher val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); 2778aa43c215SJeff Kirsher QLC_DEV_SET_QSCNT_RDY(val, portnum); 2779aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); 2780aa43c215SJeff Kirsher break; 2781aa43c215SJeff Kirsher 2782aa43c215SJeff Kirsher case QLCNIC_DEV_FAILED: 2783aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, "Device in failed state.\n"); 2784aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2785aa43c215SJeff Kirsher return -1; 2786aa43c215SJeff Kirsher 2787aa43c215SJeff Kirsher case QLCNIC_DEV_INITIALIZING: 2788aa43c215SJeff Kirsher case QLCNIC_DEV_QUISCENT: 2789aa43c215SJeff Kirsher break; 2790aa43c215SJeff Kirsher } 2791aa43c215SJeff Kirsher 2792aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2793aa43c215SJeff Kirsher 2794aa43c215SJeff Kirsher do { 2795aa43c215SJeff Kirsher msleep(1000); 2796aa43c215SJeff Kirsher prev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); 2797aa43c215SJeff Kirsher 2798aa43c215SJeff Kirsher if (prev_state == QLCNIC_DEV_QUISCENT) 2799aa43c215SJeff Kirsher continue; 2800aa43c215SJeff Kirsher } while ((prev_state != QLCNIC_DEV_READY) && --dev_init_timeo); 2801aa43c215SJeff Kirsher 2802aa43c215SJeff Kirsher if (!dev_init_timeo) { 2803aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, 2804aa43c215SJeff Kirsher "Waiting for device to initialize timeout\n"); 2805aa43c215SJeff Kirsher return -1; 2806aa43c215SJeff Kirsher } 2807aa43c215SJeff Kirsher 2808aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2809aa43c215SJeff Kirsher return -1; 2810aa43c215SJeff Kirsher 2811aa43c215SJeff Kirsher val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); 2812aa43c215SJeff Kirsher QLC_DEV_CLR_RST_QSCNT(val, portnum); 2813aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); 2814aa43c215SJeff Kirsher 2815aa43c215SJeff Kirsher ret = qlcnic_check_idc_ver(adapter); 2816aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2817aa43c215SJeff Kirsher 2818aa43c215SJeff Kirsher return ret; 2819aa43c215SJeff Kirsher } 2820aa43c215SJeff Kirsher 2821aa43c215SJeff Kirsher static void 2822aa43c215SJeff Kirsher qlcnic_fwinit_work(struct work_struct *work) 2823aa43c215SJeff Kirsher { 2824aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = container_of(work, 2825aa43c215SJeff Kirsher struct qlcnic_adapter, fw_work.work); 2826aa43c215SJeff Kirsher u32 dev_state = 0xf; 2827aa43c215SJeff Kirsher u32 val; 2828aa43c215SJeff Kirsher 2829aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2830aa43c215SJeff Kirsher goto err_ret; 2831aa43c215SJeff Kirsher 2832aa43c215SJeff Kirsher dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); 2833aa43c215SJeff Kirsher if (dev_state == QLCNIC_DEV_QUISCENT || 2834aa43c215SJeff Kirsher dev_state == QLCNIC_DEV_NEED_QUISCENT) { 2835aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2836aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_fwinit_work, 2837aa43c215SJeff Kirsher FW_POLL_DELAY * 2); 2838aa43c215SJeff Kirsher return; 2839aa43c215SJeff Kirsher } 2840aa43c215SJeff Kirsher 2841aa43c215SJeff Kirsher if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC) { 2842aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2843aa43c215SJeff Kirsher goto wait_npar; 2844aa43c215SJeff Kirsher } 2845aa43c215SJeff Kirsher 284616e3cf73SSritej Velaga if (dev_state == QLCNIC_DEV_INITIALIZING || 284716e3cf73SSritej Velaga dev_state == QLCNIC_DEV_READY) { 284816e3cf73SSritej Velaga dev_info(&adapter->pdev->dev, "Detected state change from " 284916e3cf73SSritej Velaga "DEV_NEED_RESET, skipping ack check\n"); 285016e3cf73SSritej Velaga goto skip_ack_check; 285116e3cf73SSritej Velaga } 285216e3cf73SSritej Velaga 2853aa43c215SJeff Kirsher if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) { 285416e3cf73SSritej Velaga dev_info(&adapter->pdev->dev, "Reset:Failed to get ack %d sec\n", 2855aa43c215SJeff Kirsher adapter->reset_ack_timeo); 2856aa43c215SJeff Kirsher goto skip_ack_check; 2857aa43c215SJeff Kirsher } 2858aa43c215SJeff Kirsher 2859aa43c215SJeff Kirsher if (!qlcnic_check_drv_state(adapter)) { 2860aa43c215SJeff Kirsher skip_ack_check: 2861aa43c215SJeff Kirsher dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); 2862aa43c215SJeff Kirsher 2863aa43c215SJeff Kirsher if (dev_state == QLCNIC_DEV_NEED_RESET) { 2864aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, 2865aa43c215SJeff Kirsher QLCNIC_DEV_INITIALIZING); 2866aa43c215SJeff Kirsher set_bit(__QLCNIC_START_FW, &adapter->state); 2867aa43c215SJeff Kirsher QLCDB(adapter, DRV, "Restarting fw\n"); 2868aa43c215SJeff Kirsher qlcnic_idc_debug_info(adapter, 0); 2869aa43c215SJeff Kirsher val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); 2870aa43c215SJeff Kirsher QLC_DEV_SET_RST_RDY(val, adapter->portnum); 2871aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); 2872aa43c215SJeff Kirsher } 2873aa43c215SJeff Kirsher 2874aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2875aa43c215SJeff Kirsher 2876aa43c215SJeff Kirsher rtnl_lock(); 2877aa43c215SJeff Kirsher if (adapter->ahw->fw_dump.enable && 2878aa43c215SJeff Kirsher (adapter->flags & QLCNIC_FW_RESET_OWNER)) { 2879aa43c215SJeff Kirsher QLCDB(adapter, DRV, "Take FW dump\n"); 2880aa43c215SJeff Kirsher qlcnic_dump_fw(adapter); 2881aa43c215SJeff Kirsher adapter->flags |= QLCNIC_FW_HANG; 2882aa43c215SJeff Kirsher } 2883aa43c215SJeff Kirsher rtnl_unlock(); 2884aa43c215SJeff Kirsher 2885aa43c215SJeff Kirsher adapter->flags &= ~QLCNIC_FW_RESET_OWNER; 2886aa43c215SJeff Kirsher if (!adapter->nic_ops->start_firmware(adapter)) { 2887aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_attach_work, 0); 2888aa43c215SJeff Kirsher adapter->fw_wait_cnt = 0; 2889aa43c215SJeff Kirsher return; 2890aa43c215SJeff Kirsher } 2891aa43c215SJeff Kirsher goto err_ret; 2892aa43c215SJeff Kirsher } 2893aa43c215SJeff Kirsher 2894aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2895aa43c215SJeff Kirsher 2896aa43c215SJeff Kirsher wait_npar: 2897aa43c215SJeff Kirsher dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); 2898aa43c215SJeff Kirsher QLCDB(adapter, HW, "Func waiting: Device state=%u\n", dev_state); 2899aa43c215SJeff Kirsher 2900aa43c215SJeff Kirsher switch (dev_state) { 2901aa43c215SJeff Kirsher case QLCNIC_DEV_READY: 2902aa43c215SJeff Kirsher if (!adapter->nic_ops->start_firmware(adapter)) { 2903aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_attach_work, 0); 2904aa43c215SJeff Kirsher adapter->fw_wait_cnt = 0; 2905aa43c215SJeff Kirsher return; 2906aa43c215SJeff Kirsher } 2907aa43c215SJeff Kirsher case QLCNIC_DEV_FAILED: 2908aa43c215SJeff Kirsher break; 2909aa43c215SJeff Kirsher default: 2910aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, 2911aa43c215SJeff Kirsher qlcnic_fwinit_work, FW_POLL_DELAY); 2912aa43c215SJeff Kirsher return; 2913aa43c215SJeff Kirsher } 2914aa43c215SJeff Kirsher 2915aa43c215SJeff Kirsher err_ret: 2916aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, "Fwinit work failed state=%u " 2917aa43c215SJeff Kirsher "fw_wait_cnt=%u\n", dev_state, adapter->fw_wait_cnt); 2918aa43c215SJeff Kirsher netif_device_attach(adapter->netdev); 2919aa43c215SJeff Kirsher qlcnic_clr_all_drv_state(adapter, 0); 2920aa43c215SJeff Kirsher } 2921aa43c215SJeff Kirsher 2922aa43c215SJeff Kirsher static void 2923aa43c215SJeff Kirsher qlcnic_detach_work(struct work_struct *work) 2924aa43c215SJeff Kirsher { 2925aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = container_of(work, 2926aa43c215SJeff Kirsher struct qlcnic_adapter, fw_work.work); 2927aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 2928aa43c215SJeff Kirsher u32 status; 2929aa43c215SJeff Kirsher 2930aa43c215SJeff Kirsher netif_device_detach(netdev); 2931aa43c215SJeff Kirsher 2932aa43c215SJeff Kirsher /* Dont grab rtnl lock during Quiscent mode */ 2933aa43c215SJeff Kirsher if (adapter->dev_state == QLCNIC_DEV_NEED_QUISCENT) { 2934aa43c215SJeff Kirsher if (netif_running(netdev)) 2935aa43c215SJeff Kirsher __qlcnic_down(adapter, netdev); 2936aa43c215SJeff Kirsher } else 2937aa43c215SJeff Kirsher qlcnic_down(adapter, netdev); 2938aa43c215SJeff Kirsher 2939aa43c215SJeff Kirsher status = QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS1); 2940aa43c215SJeff Kirsher 294144f65b29SSony Chacko if (status & QLCNIC_RCODE_FATAL_ERROR) { 294244f65b29SSony Chacko dev_err(&adapter->pdev->dev, 294344f65b29SSony Chacko "Detaching the device: peg halt status1=0x%x\n", 294444f65b29SSony Chacko status); 2945aa43c215SJeff Kirsher 294644f65b29SSony Chacko if (QLCNIC_FWERROR_CODE(status) == QLCNIC_FWERROR_FAN_FAILURE) { 294744f65b29SSony Chacko dev_err(&adapter->pdev->dev, 294844f65b29SSony Chacko "On board active cooling fan failed. " 294944f65b29SSony Chacko "Device has been halted.\n"); 295044f65b29SSony Chacko dev_err(&adapter->pdev->dev, 295144f65b29SSony Chacko "Replace the adapter.\n"); 295244f65b29SSony Chacko } 295344f65b29SSony Chacko 2954aa43c215SJeff Kirsher goto err_ret; 295544f65b29SSony Chacko } 295644f65b29SSony Chacko 295744f65b29SSony Chacko if (adapter->temp == QLCNIC_TEMP_PANIC) { 295844f65b29SSony Chacko dev_err(&adapter->pdev->dev, "Detaching the device: temp=%d\n", 295944f65b29SSony Chacko adapter->temp); 296044f65b29SSony Chacko goto err_ret; 296144f65b29SSony Chacko } 296244f65b29SSony Chacko 2963aa43c215SJeff Kirsher /* Dont ack if this instance is the reset owner */ 2964aa43c215SJeff Kirsher if (!(adapter->flags & QLCNIC_FW_RESET_OWNER)) { 296544f65b29SSony Chacko if (qlcnic_set_drv_state(adapter, adapter->dev_state)) { 296644f65b29SSony Chacko dev_err(&adapter->pdev->dev, 296744f65b29SSony Chacko "Failed to set driver state," 296844f65b29SSony Chacko "detaching the device.\n"); 2969aa43c215SJeff Kirsher goto err_ret; 2970aa43c215SJeff Kirsher } 297144f65b29SSony Chacko } 2972aa43c215SJeff Kirsher 2973aa43c215SJeff Kirsher adapter->fw_wait_cnt = 0; 2974aa43c215SJeff Kirsher 2975aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_fwinit_work, FW_POLL_DELAY); 2976aa43c215SJeff Kirsher 2977aa43c215SJeff Kirsher return; 2978aa43c215SJeff Kirsher 2979aa43c215SJeff Kirsher err_ret: 2980aa43c215SJeff Kirsher netif_device_attach(netdev); 2981aa43c215SJeff Kirsher qlcnic_clr_all_drv_state(adapter, 1); 2982aa43c215SJeff Kirsher } 2983aa43c215SJeff Kirsher 2984aa43c215SJeff Kirsher /*Transit NPAR state to NON Operational */ 2985aa43c215SJeff Kirsher static void 2986aa43c215SJeff Kirsher qlcnic_set_npar_non_operational(struct qlcnic_adapter *adapter) 2987aa43c215SJeff Kirsher { 2988aa43c215SJeff Kirsher u32 state; 2989aa43c215SJeff Kirsher 2990aa43c215SJeff Kirsher state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE); 2991aa43c215SJeff Kirsher if (state == QLCNIC_DEV_NPAR_NON_OPER) 2992aa43c215SJeff Kirsher return; 2993aa43c215SJeff Kirsher 2994aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2995aa43c215SJeff Kirsher return; 2996aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_NON_OPER); 2997aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2998aa43c215SJeff Kirsher } 2999aa43c215SJeff Kirsher 3000aa43c215SJeff Kirsher /*Transit to RESET state from READY state only */ 3001aa43c215SJeff Kirsher void 3002aa43c215SJeff Kirsher qlcnic_dev_request_reset(struct qlcnic_adapter *adapter) 3003aa43c215SJeff Kirsher { 3004646779f1SSritej Velaga u32 state, xg_val = 0, gb_val = 0; 3005aa43c215SJeff Kirsher 3006646779f1SSritej Velaga qlcnic_xg_set_xg0_mask(xg_val); 3007646779f1SSritej Velaga qlcnic_xg_set_xg1_mask(xg_val); 3008646779f1SSritej Velaga QLCWR32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, xg_val); 3009646779f1SSritej Velaga qlcnic_gb_set_gb0_mask(gb_val); 3010646779f1SSritej Velaga qlcnic_gb_set_gb1_mask(gb_val); 3011646779f1SSritej Velaga qlcnic_gb_set_gb2_mask(gb_val); 3012646779f1SSritej Velaga qlcnic_gb_set_gb3_mask(gb_val); 3013646779f1SSritej Velaga QLCWR32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, gb_val); 3014646779f1SSritej Velaga dev_info(&adapter->pdev->dev, "Pause control frames disabled" 3015646779f1SSritej Velaga " on all ports\n"); 3016aa43c215SJeff Kirsher adapter->need_fw_reset = 1; 3017aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 3018aa43c215SJeff Kirsher return; 3019aa43c215SJeff Kirsher 3020aa43c215SJeff Kirsher state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); 3021aa43c215SJeff Kirsher 3022aa43c215SJeff Kirsher if (state == QLCNIC_DEV_READY) { 3023aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_NEED_RESET); 3024aa43c215SJeff Kirsher adapter->flags |= QLCNIC_FW_RESET_OWNER; 3025aa43c215SJeff Kirsher QLCDB(adapter, DRV, "NEED_RESET state set\n"); 3026aa43c215SJeff Kirsher qlcnic_idc_debug_info(adapter, 0); 3027aa43c215SJeff Kirsher } 3028aa43c215SJeff Kirsher 3029aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_NON_OPER); 3030aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 3031aa43c215SJeff Kirsher } 3032aa43c215SJeff Kirsher 3033aa43c215SJeff Kirsher /* Transit to NPAR READY state from NPAR NOT READY state */ 3034aa43c215SJeff Kirsher static void 3035aa43c215SJeff Kirsher qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter) 3036aa43c215SJeff Kirsher { 3037aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 3038aa43c215SJeff Kirsher return; 3039aa43c215SJeff Kirsher 3040aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_OPER); 3041aa43c215SJeff Kirsher QLCDB(adapter, DRV, "NPAR operational state set\n"); 3042aa43c215SJeff Kirsher 3043aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 3044aa43c215SJeff Kirsher } 3045aa43c215SJeff Kirsher 3046aa43c215SJeff Kirsher static void 3047aa43c215SJeff Kirsher qlcnic_schedule_work(struct qlcnic_adapter *adapter, 3048aa43c215SJeff Kirsher work_func_t func, int delay) 3049aa43c215SJeff Kirsher { 3050aa43c215SJeff Kirsher if (test_bit(__QLCNIC_AER, &adapter->state)) 3051aa43c215SJeff Kirsher return; 3052aa43c215SJeff Kirsher 3053aa43c215SJeff Kirsher INIT_DELAYED_WORK(&adapter->fw_work, func); 3054aa43c215SJeff Kirsher queue_delayed_work(qlcnic_wq, &adapter->fw_work, 3055aa43c215SJeff Kirsher round_jiffies_relative(delay)); 3056aa43c215SJeff Kirsher } 3057aa43c215SJeff Kirsher 3058aa43c215SJeff Kirsher static void 3059aa43c215SJeff Kirsher qlcnic_cancel_fw_work(struct qlcnic_adapter *adapter) 3060aa43c215SJeff Kirsher { 3061aa43c215SJeff Kirsher while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) 3062aa43c215SJeff Kirsher msleep(10); 3063aa43c215SJeff Kirsher 3064aa43c215SJeff Kirsher cancel_delayed_work_sync(&adapter->fw_work); 3065aa43c215SJeff Kirsher } 3066aa43c215SJeff Kirsher 3067aa43c215SJeff Kirsher static void 3068aa43c215SJeff Kirsher qlcnic_attach_work(struct work_struct *work) 3069aa43c215SJeff Kirsher { 3070aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = container_of(work, 3071aa43c215SJeff Kirsher struct qlcnic_adapter, fw_work.work); 3072aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 3073aa43c215SJeff Kirsher u32 npar_state; 3074aa43c215SJeff Kirsher 3075aa43c215SJeff Kirsher if (adapter->op_mode != QLCNIC_MGMT_FUNC) { 3076aa43c215SJeff Kirsher npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE); 3077aa43c215SJeff Kirsher if (adapter->fw_wait_cnt++ > QLCNIC_DEV_NPAR_OPER_TIMEO) 3078aa43c215SJeff Kirsher qlcnic_clr_all_drv_state(adapter, 0); 3079aa43c215SJeff Kirsher else if (npar_state != QLCNIC_DEV_NPAR_OPER) 3080aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_attach_work, 3081aa43c215SJeff Kirsher FW_POLL_DELAY); 3082aa43c215SJeff Kirsher else 3083aa43c215SJeff Kirsher goto attach; 3084aa43c215SJeff Kirsher QLCDB(adapter, DRV, "Waiting for NPAR state to operational\n"); 3085aa43c215SJeff Kirsher return; 3086aa43c215SJeff Kirsher } 3087aa43c215SJeff Kirsher attach: 3088aa43c215SJeff Kirsher if (netif_running(netdev)) { 3089aa43c215SJeff Kirsher if (qlcnic_up(adapter, netdev)) 3090aa43c215SJeff Kirsher goto done; 3091aa43c215SJeff Kirsher 3092aa43c215SJeff Kirsher qlcnic_restore_indev_addr(netdev, NETDEV_UP); 3093aa43c215SJeff Kirsher } 3094aa43c215SJeff Kirsher 3095aa43c215SJeff Kirsher done: 3096aa43c215SJeff Kirsher netif_device_attach(netdev); 3097aa43c215SJeff Kirsher adapter->fw_fail_cnt = 0; 3098aa43c215SJeff Kirsher adapter->flags &= ~QLCNIC_FW_HANG; 3099aa43c215SJeff Kirsher clear_bit(__QLCNIC_RESETTING, &adapter->state); 3100aa43c215SJeff Kirsher 3101aa43c215SJeff Kirsher if (!qlcnic_clr_drv_state(adapter)) 3102aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, 3103aa43c215SJeff Kirsher FW_POLL_DELAY); 3104aa43c215SJeff Kirsher } 3105aa43c215SJeff Kirsher 3106aa43c215SJeff Kirsher static int 3107aa43c215SJeff Kirsher qlcnic_check_health(struct qlcnic_adapter *adapter) 3108aa43c215SJeff Kirsher { 3109aa43c215SJeff Kirsher u32 state = 0, heartbeat; 3110853d4bcaSAmeen Rahman u32 peg_status; 3111aa43c215SJeff Kirsher 3112aa43c215SJeff Kirsher if (qlcnic_check_temp(adapter)) 3113aa43c215SJeff Kirsher goto detach; 3114aa43c215SJeff Kirsher 3115aa43c215SJeff Kirsher if (adapter->need_fw_reset) 3116aa43c215SJeff Kirsher qlcnic_dev_request_reset(adapter); 3117aa43c215SJeff Kirsher 3118aa43c215SJeff Kirsher state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); 3119aa43c215SJeff Kirsher if (state == QLCNIC_DEV_NEED_RESET) { 3120aa43c215SJeff Kirsher qlcnic_set_npar_non_operational(adapter); 3121aa43c215SJeff Kirsher adapter->need_fw_reset = 1; 3122aa43c215SJeff Kirsher } else if (state == QLCNIC_DEV_NEED_QUISCENT) 3123aa43c215SJeff Kirsher goto detach; 3124aa43c215SJeff Kirsher 3125aa43c215SJeff Kirsher heartbeat = QLCRD32(adapter, QLCNIC_PEG_ALIVE_COUNTER); 3126aa43c215SJeff Kirsher if (heartbeat != adapter->heartbeat) { 3127aa43c215SJeff Kirsher adapter->heartbeat = heartbeat; 3128aa43c215SJeff Kirsher adapter->fw_fail_cnt = 0; 3129aa43c215SJeff Kirsher if (adapter->need_fw_reset) 3130aa43c215SJeff Kirsher goto detach; 3131aa43c215SJeff Kirsher 3132aa43c215SJeff Kirsher if (adapter->reset_context && auto_fw_reset) { 3133aa43c215SJeff Kirsher qlcnic_reset_hw_context(adapter); 3134aa43c215SJeff Kirsher adapter->netdev->trans_start = jiffies; 3135aa43c215SJeff Kirsher } 3136aa43c215SJeff Kirsher 3137aa43c215SJeff Kirsher return 0; 3138aa43c215SJeff Kirsher } 3139aa43c215SJeff Kirsher 3140aa43c215SJeff Kirsher if (++adapter->fw_fail_cnt < FW_FAIL_THRESH) 3141aa43c215SJeff Kirsher return 0; 3142aa43c215SJeff Kirsher 3143aa43c215SJeff Kirsher adapter->flags |= QLCNIC_FW_HANG; 3144aa43c215SJeff Kirsher 3145aa43c215SJeff Kirsher qlcnic_dev_request_reset(adapter); 3146aa43c215SJeff Kirsher 3147aa43c215SJeff Kirsher if (auto_fw_reset) 3148aa43c215SJeff Kirsher clear_bit(__QLCNIC_FW_ATTACHED, &adapter->state); 3149aa43c215SJeff Kirsher 3150853d4bcaSAmeen Rahman dev_err(&adapter->pdev->dev, "firmware hang detected\n"); 3151853d4bcaSAmeen Rahman dev_err(&adapter->pdev->dev, "Dumping hw/fw registers\n" 3152aa43c215SJeff Kirsher "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n" 3153aa43c215SJeff Kirsher "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n" 3154aa43c215SJeff Kirsher "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n" 3155aa43c215SJeff Kirsher "PEG_NET_4_PC: 0x%x\n", 3156aa43c215SJeff Kirsher QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS1), 3157aa43c215SJeff Kirsher QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS2), 3158aa43c215SJeff Kirsher QLCRD32(adapter, QLCNIC_CRB_PEG_NET_0 + 0x3c), 3159aa43c215SJeff Kirsher QLCRD32(adapter, QLCNIC_CRB_PEG_NET_1 + 0x3c), 3160aa43c215SJeff Kirsher QLCRD32(adapter, QLCNIC_CRB_PEG_NET_2 + 0x3c), 3161aa43c215SJeff Kirsher QLCRD32(adapter, QLCNIC_CRB_PEG_NET_3 + 0x3c), 3162aa43c215SJeff Kirsher QLCRD32(adapter, QLCNIC_CRB_PEG_NET_4 + 0x3c)); 3163853d4bcaSAmeen Rahman peg_status = QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS1); 316497048a1fSSritej Velaga if (QLCNIC_FWERROR_CODE(peg_status) == 0x67) 3165853d4bcaSAmeen Rahman dev_err(&adapter->pdev->dev, 3166853d4bcaSAmeen Rahman "Firmware aborted with error code 0x00006700. " 3167853d4bcaSAmeen Rahman "Device is being reset.\n"); 3168aa43c215SJeff Kirsher detach: 3169aa43c215SJeff Kirsher adapter->dev_state = (state == QLCNIC_DEV_NEED_QUISCENT) ? state : 3170aa43c215SJeff Kirsher QLCNIC_DEV_NEED_RESET; 3171aa43c215SJeff Kirsher 3172aa43c215SJeff Kirsher if (auto_fw_reset && 3173aa43c215SJeff Kirsher !test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) { 3174aa43c215SJeff Kirsher 3175aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_detach_work, 0); 3176aa43c215SJeff Kirsher QLCDB(adapter, DRV, "fw recovery scheduled.\n"); 3177aa43c215SJeff Kirsher } 3178aa43c215SJeff Kirsher 3179aa43c215SJeff Kirsher return 1; 3180aa43c215SJeff Kirsher } 3181aa43c215SJeff Kirsher 3182aa43c215SJeff Kirsher static void 3183aa43c215SJeff Kirsher qlcnic_fw_poll_work(struct work_struct *work) 3184aa43c215SJeff Kirsher { 3185aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = container_of(work, 3186aa43c215SJeff Kirsher struct qlcnic_adapter, fw_work.work); 3187aa43c215SJeff Kirsher 3188aa43c215SJeff Kirsher if (test_bit(__QLCNIC_RESETTING, &adapter->state)) 3189aa43c215SJeff Kirsher goto reschedule; 3190aa43c215SJeff Kirsher 3191aa43c215SJeff Kirsher 3192aa43c215SJeff Kirsher if (qlcnic_check_health(adapter)) 3193aa43c215SJeff Kirsher return; 3194aa43c215SJeff Kirsher 3195aa43c215SJeff Kirsher if (adapter->fhash.fnum) 3196aa43c215SJeff Kirsher qlcnic_prune_lb_filters(adapter); 3197aa43c215SJeff Kirsher 3198aa43c215SJeff Kirsher reschedule: 3199aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY); 3200aa43c215SJeff Kirsher } 3201aa43c215SJeff Kirsher 3202aa43c215SJeff Kirsher static int qlcnic_is_first_func(struct pci_dev *pdev) 3203aa43c215SJeff Kirsher { 3204aa43c215SJeff Kirsher struct pci_dev *oth_pdev; 3205aa43c215SJeff Kirsher int val = pdev->devfn; 3206aa43c215SJeff Kirsher 3207aa43c215SJeff Kirsher while (val-- > 0) { 3208aa43c215SJeff Kirsher oth_pdev = pci_get_domain_bus_and_slot(pci_domain_nr 3209aa43c215SJeff Kirsher (pdev->bus), pdev->bus->number, 3210aa43c215SJeff Kirsher PCI_DEVFN(PCI_SLOT(pdev->devfn), val)); 3211aa43c215SJeff Kirsher if (!oth_pdev) 3212aa43c215SJeff Kirsher continue; 3213aa43c215SJeff Kirsher 3214aa43c215SJeff Kirsher if (oth_pdev->current_state != PCI_D3cold) { 3215aa43c215SJeff Kirsher pci_dev_put(oth_pdev); 3216aa43c215SJeff Kirsher return 0; 3217aa43c215SJeff Kirsher } 3218aa43c215SJeff Kirsher pci_dev_put(oth_pdev); 3219aa43c215SJeff Kirsher } 3220aa43c215SJeff Kirsher return 1; 3221aa43c215SJeff Kirsher } 3222aa43c215SJeff Kirsher 3223aa43c215SJeff Kirsher static int qlcnic_attach_func(struct pci_dev *pdev) 3224aa43c215SJeff Kirsher { 3225aa43c215SJeff Kirsher int err, first_func; 3226aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); 3227aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 3228aa43c215SJeff Kirsher 3229aa43c215SJeff Kirsher pdev->error_state = pci_channel_io_normal; 3230aa43c215SJeff Kirsher 3231aa43c215SJeff Kirsher err = pci_enable_device(pdev); 3232aa43c215SJeff Kirsher if (err) 3233aa43c215SJeff Kirsher return err; 3234aa43c215SJeff Kirsher 3235aa43c215SJeff Kirsher pci_set_power_state(pdev, PCI_D0); 3236aa43c215SJeff Kirsher pci_set_master(pdev); 3237aa43c215SJeff Kirsher pci_restore_state(pdev); 3238aa43c215SJeff Kirsher 3239aa43c215SJeff Kirsher first_func = qlcnic_is_first_func(pdev); 3240aa43c215SJeff Kirsher 3241aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 3242aa43c215SJeff Kirsher return -EINVAL; 3243aa43c215SJeff Kirsher 3244aa43c215SJeff Kirsher if (adapter->op_mode != QLCNIC_NON_PRIV_FUNC && first_func) { 3245aa43c215SJeff Kirsher adapter->need_fw_reset = 1; 3246aa43c215SJeff Kirsher set_bit(__QLCNIC_START_FW, &adapter->state); 3247aa43c215SJeff Kirsher QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_INITIALIZING); 3248aa43c215SJeff Kirsher QLCDB(adapter, DRV, "Restarting fw\n"); 3249aa43c215SJeff Kirsher } 3250aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 3251aa43c215SJeff Kirsher 3252aa43c215SJeff Kirsher err = adapter->nic_ops->start_firmware(adapter); 3253aa43c215SJeff Kirsher if (err) 3254aa43c215SJeff Kirsher return err; 3255aa43c215SJeff Kirsher 3256aa43c215SJeff Kirsher qlcnic_clr_drv_state(adapter); 3257aa43c215SJeff Kirsher qlcnic_setup_intr(adapter); 3258aa43c215SJeff Kirsher 3259aa43c215SJeff Kirsher if (netif_running(netdev)) { 3260aa43c215SJeff Kirsher err = qlcnic_attach(adapter); 3261aa43c215SJeff Kirsher if (err) { 3262aa43c215SJeff Kirsher qlcnic_clr_all_drv_state(adapter, 1); 3263aa43c215SJeff Kirsher clear_bit(__QLCNIC_AER, &adapter->state); 3264aa43c215SJeff Kirsher netif_device_attach(netdev); 3265aa43c215SJeff Kirsher return err; 3266aa43c215SJeff Kirsher } 3267aa43c215SJeff Kirsher 3268aa43c215SJeff Kirsher err = qlcnic_up(adapter, netdev); 3269aa43c215SJeff Kirsher if (err) 3270aa43c215SJeff Kirsher goto done; 3271aa43c215SJeff Kirsher 3272aa43c215SJeff Kirsher qlcnic_restore_indev_addr(netdev, NETDEV_UP); 3273aa43c215SJeff Kirsher } 3274aa43c215SJeff Kirsher done: 3275aa43c215SJeff Kirsher netif_device_attach(netdev); 3276aa43c215SJeff Kirsher return err; 3277aa43c215SJeff Kirsher } 3278aa43c215SJeff Kirsher 3279aa43c215SJeff Kirsher static pci_ers_result_t qlcnic_io_error_detected(struct pci_dev *pdev, 3280aa43c215SJeff Kirsher pci_channel_state_t state) 3281aa43c215SJeff Kirsher { 3282aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); 3283aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 3284aa43c215SJeff Kirsher 3285aa43c215SJeff Kirsher if (state == pci_channel_io_perm_failure) 3286aa43c215SJeff Kirsher return PCI_ERS_RESULT_DISCONNECT; 3287aa43c215SJeff Kirsher 3288aa43c215SJeff Kirsher if (state == pci_channel_io_normal) 3289aa43c215SJeff Kirsher return PCI_ERS_RESULT_RECOVERED; 3290aa43c215SJeff Kirsher 3291aa43c215SJeff Kirsher set_bit(__QLCNIC_AER, &adapter->state); 3292aa43c215SJeff Kirsher netif_device_detach(netdev); 3293aa43c215SJeff Kirsher 3294aa43c215SJeff Kirsher cancel_delayed_work_sync(&adapter->fw_work); 3295aa43c215SJeff Kirsher 3296aa43c215SJeff Kirsher if (netif_running(netdev)) 3297aa43c215SJeff Kirsher qlcnic_down(adapter, netdev); 3298aa43c215SJeff Kirsher 3299aa43c215SJeff Kirsher qlcnic_detach(adapter); 3300aa43c215SJeff Kirsher qlcnic_teardown_intr(adapter); 3301aa43c215SJeff Kirsher 3302aa43c215SJeff Kirsher clear_bit(__QLCNIC_RESETTING, &adapter->state); 3303aa43c215SJeff Kirsher 3304aa43c215SJeff Kirsher pci_save_state(pdev); 3305aa43c215SJeff Kirsher pci_disable_device(pdev); 3306aa43c215SJeff Kirsher 3307aa43c215SJeff Kirsher return PCI_ERS_RESULT_NEED_RESET; 3308aa43c215SJeff Kirsher } 3309aa43c215SJeff Kirsher 3310aa43c215SJeff Kirsher static pci_ers_result_t qlcnic_io_slot_reset(struct pci_dev *pdev) 3311aa43c215SJeff Kirsher { 3312aa43c215SJeff Kirsher return qlcnic_attach_func(pdev) ? PCI_ERS_RESULT_DISCONNECT : 3313aa43c215SJeff Kirsher PCI_ERS_RESULT_RECOVERED; 3314aa43c215SJeff Kirsher } 3315aa43c215SJeff Kirsher 3316aa43c215SJeff Kirsher static void qlcnic_io_resume(struct pci_dev *pdev) 3317aa43c215SJeff Kirsher { 3318aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); 3319aa43c215SJeff Kirsher 3320aa43c215SJeff Kirsher pci_cleanup_aer_uncorrect_error_status(pdev); 3321aa43c215SJeff Kirsher 3322aa43c215SJeff Kirsher if (QLCRD32(adapter, QLCNIC_CRB_DEV_STATE) == QLCNIC_DEV_READY && 3323aa43c215SJeff Kirsher test_and_clear_bit(__QLCNIC_AER, &adapter->state)) 3324aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, 3325aa43c215SJeff Kirsher FW_POLL_DELAY); 3326aa43c215SJeff Kirsher } 3327aa43c215SJeff Kirsher 3328aa43c215SJeff Kirsher static int 3329aa43c215SJeff Kirsher qlcnicvf_start_firmware(struct qlcnic_adapter *adapter) 3330aa43c215SJeff Kirsher { 3331aa43c215SJeff Kirsher int err; 3332aa43c215SJeff Kirsher 3333aa43c215SJeff Kirsher err = qlcnic_can_start_firmware(adapter); 3334aa43c215SJeff Kirsher if (err) 3335aa43c215SJeff Kirsher return err; 3336aa43c215SJeff Kirsher 3337aa43c215SJeff Kirsher err = qlcnic_check_npar_opertional(adapter); 3338aa43c215SJeff Kirsher if (err) 3339aa43c215SJeff Kirsher return err; 3340aa43c215SJeff Kirsher 3341aa43c215SJeff Kirsher err = qlcnic_initialize_nic(adapter); 3342aa43c215SJeff Kirsher if (err) 3343aa43c215SJeff Kirsher return err; 3344aa43c215SJeff Kirsher 3345aa43c215SJeff Kirsher qlcnic_check_options(adapter); 3346aa43c215SJeff Kirsher 3347aa43c215SJeff Kirsher err = qlcnic_set_eswitch_port_config(adapter); 3348aa43c215SJeff Kirsher if (err) 3349aa43c215SJeff Kirsher return err; 3350aa43c215SJeff Kirsher 3351aa43c215SJeff Kirsher adapter->need_fw_reset = 0; 3352aa43c215SJeff Kirsher 3353aa43c215SJeff Kirsher return err; 3354aa43c215SJeff Kirsher } 3355aa43c215SJeff Kirsher 3356aa43c215SJeff Kirsher static int 3357aa43c215SJeff Kirsher qlcnicvf_config_bridged_mode(struct qlcnic_adapter *adapter, u32 enable) 3358aa43c215SJeff Kirsher { 3359aa43c215SJeff Kirsher return -EOPNOTSUPP; 3360aa43c215SJeff Kirsher } 3361aa43c215SJeff Kirsher 3362aa43c215SJeff Kirsher static int 3363aa43c215SJeff Kirsher qlcnicvf_config_led(struct qlcnic_adapter *adapter, u32 state, u32 rate) 3364aa43c215SJeff Kirsher { 3365aa43c215SJeff Kirsher return -EOPNOTSUPP; 3366aa43c215SJeff Kirsher } 3367aa43c215SJeff Kirsher 3368aa43c215SJeff Kirsher static ssize_t 3369aa43c215SJeff Kirsher qlcnic_store_bridged_mode(struct device *dev, 3370aa43c215SJeff Kirsher struct device_attribute *attr, const char *buf, size_t len) 3371aa43c215SJeff Kirsher { 3372aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3373aa43c215SJeff Kirsher unsigned long new; 3374aa43c215SJeff Kirsher int ret = -EINVAL; 3375aa43c215SJeff Kirsher 3376aa43c215SJeff Kirsher if (!(adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG)) 3377aa43c215SJeff Kirsher goto err_out; 3378aa43c215SJeff Kirsher 3379aa43c215SJeff Kirsher if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) 3380aa43c215SJeff Kirsher goto err_out; 3381aa43c215SJeff Kirsher 3382aa43c215SJeff Kirsher if (strict_strtoul(buf, 2, &new)) 3383aa43c215SJeff Kirsher goto err_out; 3384aa43c215SJeff Kirsher 3385aa43c215SJeff Kirsher if (!adapter->nic_ops->config_bridged_mode(adapter, !!new)) 3386aa43c215SJeff Kirsher ret = len; 3387aa43c215SJeff Kirsher 3388aa43c215SJeff Kirsher err_out: 3389aa43c215SJeff Kirsher return ret; 3390aa43c215SJeff Kirsher } 3391aa43c215SJeff Kirsher 3392aa43c215SJeff Kirsher static ssize_t 3393aa43c215SJeff Kirsher qlcnic_show_bridged_mode(struct device *dev, 3394aa43c215SJeff Kirsher struct device_attribute *attr, char *buf) 3395aa43c215SJeff Kirsher { 3396aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3397aa43c215SJeff Kirsher int bridged_mode = 0; 3398aa43c215SJeff Kirsher 3399aa43c215SJeff Kirsher if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG) 3400aa43c215SJeff Kirsher bridged_mode = !!(adapter->flags & QLCNIC_BRIDGE_ENABLED); 3401aa43c215SJeff Kirsher 3402aa43c215SJeff Kirsher return sprintf(buf, "%d\n", bridged_mode); 3403aa43c215SJeff Kirsher } 3404aa43c215SJeff Kirsher 3405aa43c215SJeff Kirsher static struct device_attribute dev_attr_bridged_mode = { 3406aa43c215SJeff Kirsher .attr = {.name = "bridged_mode", .mode = (S_IRUGO | S_IWUSR)}, 3407aa43c215SJeff Kirsher .show = qlcnic_show_bridged_mode, 3408aa43c215SJeff Kirsher .store = qlcnic_store_bridged_mode, 3409aa43c215SJeff Kirsher }; 3410aa43c215SJeff Kirsher 3411aa43c215SJeff Kirsher static ssize_t 3412aa43c215SJeff Kirsher qlcnic_store_diag_mode(struct device *dev, 3413aa43c215SJeff Kirsher struct device_attribute *attr, const char *buf, size_t len) 3414aa43c215SJeff Kirsher { 3415aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3416aa43c215SJeff Kirsher unsigned long new; 3417aa43c215SJeff Kirsher 3418aa43c215SJeff Kirsher if (strict_strtoul(buf, 2, &new)) 3419aa43c215SJeff Kirsher return -EINVAL; 3420aa43c215SJeff Kirsher 3421aa43c215SJeff Kirsher if (!!new != !!(adapter->flags & QLCNIC_DIAG_ENABLED)) 3422aa43c215SJeff Kirsher adapter->flags ^= QLCNIC_DIAG_ENABLED; 3423aa43c215SJeff Kirsher 3424aa43c215SJeff Kirsher return len; 3425aa43c215SJeff Kirsher } 3426aa43c215SJeff Kirsher 3427aa43c215SJeff Kirsher static ssize_t 3428aa43c215SJeff Kirsher qlcnic_show_diag_mode(struct device *dev, 3429aa43c215SJeff Kirsher struct device_attribute *attr, char *buf) 3430aa43c215SJeff Kirsher { 3431aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3432aa43c215SJeff Kirsher 3433aa43c215SJeff Kirsher return sprintf(buf, "%d\n", 3434aa43c215SJeff Kirsher !!(adapter->flags & QLCNIC_DIAG_ENABLED)); 3435aa43c215SJeff Kirsher } 3436aa43c215SJeff Kirsher 3437aa43c215SJeff Kirsher static struct device_attribute dev_attr_diag_mode = { 3438aa43c215SJeff Kirsher .attr = {.name = "diag_mode", .mode = (S_IRUGO | S_IWUSR)}, 3439aa43c215SJeff Kirsher .show = qlcnic_show_diag_mode, 3440aa43c215SJeff Kirsher .store = qlcnic_store_diag_mode, 3441aa43c215SJeff Kirsher }; 3442aa43c215SJeff Kirsher 3443aa43c215SJeff Kirsher int qlcnic_validate_max_rss(struct net_device *netdev, u8 max_hw, u8 val) 3444aa43c215SJeff Kirsher { 3445aa43c215SJeff Kirsher if (!use_msi_x && !use_msi) { 3446aa43c215SJeff Kirsher netdev_info(netdev, "no msix or msi support, hence no rss\n"); 3447aa43c215SJeff Kirsher return -EINVAL; 3448aa43c215SJeff Kirsher } 3449aa43c215SJeff Kirsher 3450aa43c215SJeff Kirsher if ((val > max_hw) || (val < 2) || !is_power_of_2(val)) { 3451aa43c215SJeff Kirsher netdev_info(netdev, "rss_ring valid range [2 - %x] in " 3452aa43c215SJeff Kirsher " powers of 2\n", max_hw); 3453aa43c215SJeff Kirsher return -EINVAL; 3454aa43c215SJeff Kirsher } 3455aa43c215SJeff Kirsher return 0; 3456aa43c215SJeff Kirsher 3457aa43c215SJeff Kirsher } 3458aa43c215SJeff Kirsher 3459aa43c215SJeff Kirsher int qlcnic_set_max_rss(struct qlcnic_adapter *adapter, u8 data) 3460aa43c215SJeff Kirsher { 3461aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 3462aa43c215SJeff Kirsher int err = 0; 3463aa43c215SJeff Kirsher 3464aa43c215SJeff Kirsher if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) 3465aa43c215SJeff Kirsher return -EBUSY; 3466aa43c215SJeff Kirsher 3467aa43c215SJeff Kirsher netif_device_detach(netdev); 3468aa43c215SJeff Kirsher if (netif_running(netdev)) 3469aa43c215SJeff Kirsher __qlcnic_down(adapter, netdev); 3470aa43c215SJeff Kirsher qlcnic_detach(adapter); 3471aa43c215SJeff Kirsher qlcnic_teardown_intr(adapter); 3472aa43c215SJeff Kirsher 3473aa43c215SJeff Kirsher if (qlcnic_enable_msix(adapter, data)) { 3474aa43c215SJeff Kirsher netdev_info(netdev, "failed setting max_rss; rss disabled\n"); 3475aa43c215SJeff Kirsher qlcnic_enable_msi_legacy(adapter); 3476aa43c215SJeff Kirsher } 3477aa43c215SJeff Kirsher 3478aa43c215SJeff Kirsher if (netif_running(netdev)) { 3479aa43c215SJeff Kirsher err = qlcnic_attach(adapter); 3480aa43c215SJeff Kirsher if (err) 3481aa43c215SJeff Kirsher goto done; 3482aa43c215SJeff Kirsher err = __qlcnic_up(adapter, netdev); 3483aa43c215SJeff Kirsher if (err) 3484aa43c215SJeff Kirsher goto done; 3485aa43c215SJeff Kirsher qlcnic_restore_indev_addr(netdev, NETDEV_UP); 3486aa43c215SJeff Kirsher } 3487aa43c215SJeff Kirsher done: 3488aa43c215SJeff Kirsher netif_device_attach(netdev); 3489aa43c215SJeff Kirsher clear_bit(__QLCNIC_RESETTING, &adapter->state); 3490aa43c215SJeff Kirsher return err; 3491aa43c215SJeff Kirsher } 3492aa43c215SJeff Kirsher 3493aa43c215SJeff Kirsher static int 3494728a98b8SSucheta Chakraborty qlcnic_validate_beacon(struct qlcnic_adapter *adapter, u16 beacon, u8 *state, 3495728a98b8SSucheta Chakraborty u8 *rate) 3496728a98b8SSucheta Chakraborty { 3497728a98b8SSucheta Chakraborty *rate = LSB(beacon); 3498728a98b8SSucheta Chakraborty *state = MSB(beacon); 3499728a98b8SSucheta Chakraborty 3500728a98b8SSucheta Chakraborty QLCDB(adapter, DRV, "rate %x state %x\n", *rate, *state); 3501728a98b8SSucheta Chakraborty 3502728a98b8SSucheta Chakraborty if (!*state) { 3503728a98b8SSucheta Chakraborty *rate = __QLCNIC_MAX_LED_RATE; 3504728a98b8SSucheta Chakraborty return 0; 3505728a98b8SSucheta Chakraborty } else if (*state > __QLCNIC_MAX_LED_STATE) 3506728a98b8SSucheta Chakraborty return -EINVAL; 3507728a98b8SSucheta Chakraborty 3508728a98b8SSucheta Chakraborty if ((!*rate) || (*rate > __QLCNIC_MAX_LED_RATE)) 3509728a98b8SSucheta Chakraborty return -EINVAL; 3510728a98b8SSucheta Chakraborty 3511728a98b8SSucheta Chakraborty return 0; 3512728a98b8SSucheta Chakraborty } 3513728a98b8SSucheta Chakraborty 3514728a98b8SSucheta Chakraborty static ssize_t 3515728a98b8SSucheta Chakraborty qlcnic_store_beacon(struct device *dev, 3516728a98b8SSucheta Chakraborty struct device_attribute *attr, const char *buf, size_t len) 3517728a98b8SSucheta Chakraborty { 3518728a98b8SSucheta Chakraborty struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3519728a98b8SSucheta Chakraborty int max_sds_rings = adapter->max_sds_rings; 3520728a98b8SSucheta Chakraborty u16 beacon; 3521728a98b8SSucheta Chakraborty u8 b_state, b_rate; 3522728a98b8SSucheta Chakraborty int err; 3523728a98b8SSucheta Chakraborty 352410ee0faeSSucheta Chakraborty if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC) { 352510ee0faeSSucheta Chakraborty dev_warn(dev, "LED test not supported for non " 352610ee0faeSSucheta Chakraborty "privilege function\n"); 352710ee0faeSSucheta Chakraborty return -EOPNOTSUPP; 352810ee0faeSSucheta Chakraborty } 352910ee0faeSSucheta Chakraborty 3530728a98b8SSucheta Chakraborty if (len != sizeof(u16)) 3531728a98b8SSucheta Chakraborty return QL_STATUS_INVALID_PARAM; 3532728a98b8SSucheta Chakraborty 3533728a98b8SSucheta Chakraborty memcpy(&beacon, buf, sizeof(u16)); 3534728a98b8SSucheta Chakraborty err = qlcnic_validate_beacon(adapter, beacon, &b_state, &b_rate); 3535728a98b8SSucheta Chakraborty if (err) 3536728a98b8SSucheta Chakraborty return err; 3537728a98b8SSucheta Chakraborty 3538728a98b8SSucheta Chakraborty if (adapter->ahw->beacon_state == b_state) 3539728a98b8SSucheta Chakraborty return len; 3540728a98b8SSucheta Chakraborty 354110ee0faeSSucheta Chakraborty rtnl_lock(); 354210ee0faeSSucheta Chakraborty 3543728a98b8SSucheta Chakraborty if (!adapter->ahw->beacon_state) 354410ee0faeSSucheta Chakraborty if (test_and_set_bit(__QLCNIC_LED_ENABLE, &adapter->state)) { 354510ee0faeSSucheta Chakraborty rtnl_unlock(); 3546728a98b8SSucheta Chakraborty return -EBUSY; 354710ee0faeSSucheta Chakraborty } 354810ee0faeSSucheta Chakraborty 354910ee0faeSSucheta Chakraborty if (test_bit(__QLCNIC_RESETTING, &adapter->state)) { 355010ee0faeSSucheta Chakraborty err = -EIO; 355110ee0faeSSucheta Chakraborty goto out; 355210ee0faeSSucheta Chakraborty } 3553728a98b8SSucheta Chakraborty 3554728a98b8SSucheta Chakraborty if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) { 3555728a98b8SSucheta Chakraborty err = qlcnic_diag_alloc_res(adapter->netdev, QLCNIC_LED_TEST); 355610ee0faeSSucheta Chakraborty if (err) 355710ee0faeSSucheta Chakraborty goto out; 355810ee0faeSSucheta Chakraborty set_bit(__QLCNIC_DIAG_RES_ALLOC, &adapter->state); 3559728a98b8SSucheta Chakraborty } 3560728a98b8SSucheta Chakraborty 3561728a98b8SSucheta Chakraborty err = qlcnic_config_led(adapter, b_state, b_rate); 3562728a98b8SSucheta Chakraborty 3563728a98b8SSucheta Chakraborty if (!err) { 3564728a98b8SSucheta Chakraborty err = len; 356510ee0faeSSucheta Chakraborty adapter->ahw->beacon_state = b_state; 3566728a98b8SSucheta Chakraborty } 3567728a98b8SSucheta Chakraborty 356810ee0faeSSucheta Chakraborty if (test_and_clear_bit(__QLCNIC_DIAG_RES_ALLOC, &adapter->state)) 3569728a98b8SSucheta Chakraborty qlcnic_diag_free_res(adapter->netdev, max_sds_rings); 3570728a98b8SSucheta Chakraborty 357110ee0faeSSucheta Chakraborty out: 357210ee0faeSSucheta Chakraborty if (!adapter->ahw->beacon_state) 3573728a98b8SSucheta Chakraborty clear_bit(__QLCNIC_LED_ENABLE, &adapter->state); 357410ee0faeSSucheta Chakraborty rtnl_unlock(); 3575728a98b8SSucheta Chakraborty 3576728a98b8SSucheta Chakraborty return err; 3577728a98b8SSucheta Chakraborty } 3578728a98b8SSucheta Chakraborty 3579728a98b8SSucheta Chakraborty static ssize_t 3580728a98b8SSucheta Chakraborty qlcnic_show_beacon(struct device *dev, 3581728a98b8SSucheta Chakraborty struct device_attribute *attr, char *buf) 3582728a98b8SSucheta Chakraborty { 3583728a98b8SSucheta Chakraborty struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3584728a98b8SSucheta Chakraborty 3585728a98b8SSucheta Chakraborty return sprintf(buf, "%d\n", adapter->ahw->beacon_state); 3586728a98b8SSucheta Chakraborty } 3587728a98b8SSucheta Chakraborty 3588728a98b8SSucheta Chakraborty static struct device_attribute dev_attr_beacon = { 3589728a98b8SSucheta Chakraborty .attr = {.name = "beacon", .mode = (S_IRUGO | S_IWUSR)}, 3590728a98b8SSucheta Chakraborty .show = qlcnic_show_beacon, 3591728a98b8SSucheta Chakraborty .store = qlcnic_store_beacon, 3592728a98b8SSucheta Chakraborty }; 3593728a98b8SSucheta Chakraborty 3594728a98b8SSucheta Chakraborty static int 3595aa43c215SJeff Kirsher qlcnic_sysfs_validate_crb(struct qlcnic_adapter *adapter, 3596aa43c215SJeff Kirsher loff_t offset, size_t size) 3597aa43c215SJeff Kirsher { 3598aa43c215SJeff Kirsher size_t crb_size = 4; 3599aa43c215SJeff Kirsher 3600aa43c215SJeff Kirsher if (!(adapter->flags & QLCNIC_DIAG_ENABLED)) 3601aa43c215SJeff Kirsher return -EIO; 3602aa43c215SJeff Kirsher 3603aa43c215SJeff Kirsher if (offset < QLCNIC_PCI_CRBSPACE) { 3604aa43c215SJeff Kirsher if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM, 3605aa43c215SJeff Kirsher QLCNIC_PCI_CAMQM_END)) 3606aa43c215SJeff Kirsher crb_size = 8; 3607aa43c215SJeff Kirsher else 3608aa43c215SJeff Kirsher return -EINVAL; 3609aa43c215SJeff Kirsher } 3610aa43c215SJeff Kirsher 3611aa43c215SJeff Kirsher if ((size != crb_size) || (offset & (crb_size-1))) 3612aa43c215SJeff Kirsher return -EINVAL; 3613aa43c215SJeff Kirsher 3614aa43c215SJeff Kirsher return 0; 3615aa43c215SJeff Kirsher } 3616aa43c215SJeff Kirsher 3617aa43c215SJeff Kirsher static ssize_t 3618aa43c215SJeff Kirsher qlcnic_sysfs_read_crb(struct file *filp, struct kobject *kobj, 3619aa43c215SJeff Kirsher struct bin_attribute *attr, 3620aa43c215SJeff Kirsher char *buf, loff_t offset, size_t size) 3621aa43c215SJeff Kirsher { 3622aa43c215SJeff Kirsher struct device *dev = container_of(kobj, struct device, kobj); 3623aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3624aa43c215SJeff Kirsher u32 data; 3625aa43c215SJeff Kirsher u64 qmdata; 3626aa43c215SJeff Kirsher int ret; 3627aa43c215SJeff Kirsher 3628aa43c215SJeff Kirsher ret = qlcnic_sysfs_validate_crb(adapter, offset, size); 3629aa43c215SJeff Kirsher if (ret != 0) 3630aa43c215SJeff Kirsher return ret; 3631aa43c215SJeff Kirsher 3632aa43c215SJeff Kirsher if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM, QLCNIC_PCI_CAMQM_END)) { 3633aa43c215SJeff Kirsher qlcnic_pci_camqm_read_2M(adapter, offset, &qmdata); 3634aa43c215SJeff Kirsher memcpy(buf, &qmdata, size); 3635aa43c215SJeff Kirsher } else { 3636aa43c215SJeff Kirsher data = QLCRD32(adapter, offset); 3637aa43c215SJeff Kirsher memcpy(buf, &data, size); 3638aa43c215SJeff Kirsher } 3639aa43c215SJeff Kirsher return size; 3640aa43c215SJeff Kirsher } 3641aa43c215SJeff Kirsher 3642aa43c215SJeff Kirsher static ssize_t 3643aa43c215SJeff Kirsher qlcnic_sysfs_write_crb(struct file *filp, struct kobject *kobj, 3644aa43c215SJeff Kirsher struct bin_attribute *attr, 3645aa43c215SJeff Kirsher char *buf, loff_t offset, size_t size) 3646aa43c215SJeff Kirsher { 3647aa43c215SJeff Kirsher struct device *dev = container_of(kobj, struct device, kobj); 3648aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3649aa43c215SJeff Kirsher u32 data; 3650aa43c215SJeff Kirsher u64 qmdata; 3651aa43c215SJeff Kirsher int ret; 3652aa43c215SJeff Kirsher 3653aa43c215SJeff Kirsher ret = qlcnic_sysfs_validate_crb(adapter, offset, size); 3654aa43c215SJeff Kirsher if (ret != 0) 3655aa43c215SJeff Kirsher return ret; 3656aa43c215SJeff Kirsher 3657aa43c215SJeff Kirsher if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM, QLCNIC_PCI_CAMQM_END)) { 3658aa43c215SJeff Kirsher memcpy(&qmdata, buf, size); 3659aa43c215SJeff Kirsher qlcnic_pci_camqm_write_2M(adapter, offset, qmdata); 3660aa43c215SJeff Kirsher } else { 3661aa43c215SJeff Kirsher memcpy(&data, buf, size); 3662aa43c215SJeff Kirsher QLCWR32(adapter, offset, data); 3663aa43c215SJeff Kirsher } 3664aa43c215SJeff Kirsher return size; 3665aa43c215SJeff Kirsher } 3666aa43c215SJeff Kirsher 3667aa43c215SJeff Kirsher static int 3668aa43c215SJeff Kirsher qlcnic_sysfs_validate_mem(struct qlcnic_adapter *adapter, 3669aa43c215SJeff Kirsher loff_t offset, size_t size) 3670aa43c215SJeff Kirsher { 3671aa43c215SJeff Kirsher if (!(adapter->flags & QLCNIC_DIAG_ENABLED)) 3672aa43c215SJeff Kirsher return -EIO; 3673aa43c215SJeff Kirsher 3674aa43c215SJeff Kirsher if ((size != 8) || (offset & 0x7)) 3675aa43c215SJeff Kirsher return -EIO; 3676aa43c215SJeff Kirsher 3677aa43c215SJeff Kirsher return 0; 3678aa43c215SJeff Kirsher } 3679aa43c215SJeff Kirsher 3680aa43c215SJeff Kirsher static ssize_t 3681aa43c215SJeff Kirsher qlcnic_sysfs_read_mem(struct file *filp, struct kobject *kobj, 3682aa43c215SJeff Kirsher struct bin_attribute *attr, 3683aa43c215SJeff Kirsher char *buf, loff_t offset, size_t size) 3684aa43c215SJeff Kirsher { 3685aa43c215SJeff Kirsher struct device *dev = container_of(kobj, struct device, kobj); 3686aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3687aa43c215SJeff Kirsher u64 data; 3688aa43c215SJeff Kirsher int ret; 3689aa43c215SJeff Kirsher 3690aa43c215SJeff Kirsher ret = qlcnic_sysfs_validate_mem(adapter, offset, size); 3691aa43c215SJeff Kirsher if (ret != 0) 3692aa43c215SJeff Kirsher return ret; 3693aa43c215SJeff Kirsher 3694aa43c215SJeff Kirsher if (qlcnic_pci_mem_read_2M(adapter, offset, &data)) 3695aa43c215SJeff Kirsher return -EIO; 3696aa43c215SJeff Kirsher 3697aa43c215SJeff Kirsher memcpy(buf, &data, size); 3698aa43c215SJeff Kirsher 3699aa43c215SJeff Kirsher return size; 3700aa43c215SJeff Kirsher } 3701aa43c215SJeff Kirsher 3702aa43c215SJeff Kirsher static ssize_t 3703aa43c215SJeff Kirsher qlcnic_sysfs_write_mem(struct file *filp, struct kobject *kobj, 3704aa43c215SJeff Kirsher struct bin_attribute *attr, 3705aa43c215SJeff Kirsher char *buf, loff_t offset, size_t size) 3706aa43c215SJeff Kirsher { 3707aa43c215SJeff Kirsher struct device *dev = container_of(kobj, struct device, kobj); 3708aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3709aa43c215SJeff Kirsher u64 data; 3710aa43c215SJeff Kirsher int ret; 3711aa43c215SJeff Kirsher 3712aa43c215SJeff Kirsher ret = qlcnic_sysfs_validate_mem(adapter, offset, size); 3713aa43c215SJeff Kirsher if (ret != 0) 3714aa43c215SJeff Kirsher return ret; 3715aa43c215SJeff Kirsher 3716aa43c215SJeff Kirsher memcpy(&data, buf, size); 3717aa43c215SJeff Kirsher 3718aa43c215SJeff Kirsher if (qlcnic_pci_mem_write_2M(adapter, offset, data)) 3719aa43c215SJeff Kirsher return -EIO; 3720aa43c215SJeff Kirsher 3721aa43c215SJeff Kirsher return size; 3722aa43c215SJeff Kirsher } 3723aa43c215SJeff Kirsher 3724aa43c215SJeff Kirsher static struct bin_attribute bin_attr_crb = { 3725aa43c215SJeff Kirsher .attr = {.name = "crb", .mode = (S_IRUGO | S_IWUSR)}, 3726aa43c215SJeff Kirsher .size = 0, 3727aa43c215SJeff Kirsher .read = qlcnic_sysfs_read_crb, 3728aa43c215SJeff Kirsher .write = qlcnic_sysfs_write_crb, 3729aa43c215SJeff Kirsher }; 3730aa43c215SJeff Kirsher 3731aa43c215SJeff Kirsher static struct bin_attribute bin_attr_mem = { 3732aa43c215SJeff Kirsher .attr = {.name = "mem", .mode = (S_IRUGO | S_IWUSR)}, 3733aa43c215SJeff Kirsher .size = 0, 3734aa43c215SJeff Kirsher .read = qlcnic_sysfs_read_mem, 3735aa43c215SJeff Kirsher .write = qlcnic_sysfs_write_mem, 3736aa43c215SJeff Kirsher }; 3737aa43c215SJeff Kirsher 3738aa43c215SJeff Kirsher static int 3739aa43c215SJeff Kirsher validate_pm_config(struct qlcnic_adapter *adapter, 3740aa43c215SJeff Kirsher struct qlcnic_pm_func_cfg *pm_cfg, int count) 3741aa43c215SJeff Kirsher { 3742aa43c215SJeff Kirsher 3743aa43c215SJeff Kirsher u8 src_pci_func, s_esw_id, d_esw_id; 3744aa43c215SJeff Kirsher u8 dest_pci_func; 3745aa43c215SJeff Kirsher int i; 3746aa43c215SJeff Kirsher 3747aa43c215SJeff Kirsher for (i = 0; i < count; i++) { 3748aa43c215SJeff Kirsher src_pci_func = pm_cfg[i].pci_func; 3749aa43c215SJeff Kirsher dest_pci_func = pm_cfg[i].dest_npar; 3750aa43c215SJeff Kirsher if (src_pci_func >= QLCNIC_MAX_PCI_FUNC 3751aa43c215SJeff Kirsher || dest_pci_func >= QLCNIC_MAX_PCI_FUNC) 3752aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3753aa43c215SJeff Kirsher 3754aa43c215SJeff Kirsher if (adapter->npars[src_pci_func].type != QLCNIC_TYPE_NIC) 3755aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3756aa43c215SJeff Kirsher 3757aa43c215SJeff Kirsher if (adapter->npars[dest_pci_func].type != QLCNIC_TYPE_NIC) 3758aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3759aa43c215SJeff Kirsher 3760aa43c215SJeff Kirsher s_esw_id = adapter->npars[src_pci_func].phy_port; 3761aa43c215SJeff Kirsher d_esw_id = adapter->npars[dest_pci_func].phy_port; 3762aa43c215SJeff Kirsher 3763aa43c215SJeff Kirsher if (s_esw_id != d_esw_id) 3764aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3765aa43c215SJeff Kirsher 3766aa43c215SJeff Kirsher } 3767aa43c215SJeff Kirsher return 0; 3768aa43c215SJeff Kirsher 3769aa43c215SJeff Kirsher } 3770aa43c215SJeff Kirsher 3771aa43c215SJeff Kirsher static ssize_t 3772aa43c215SJeff Kirsher qlcnic_sysfs_write_pm_config(struct file *filp, struct kobject *kobj, 3773aa43c215SJeff Kirsher struct bin_attribute *attr, char *buf, loff_t offset, size_t size) 3774aa43c215SJeff Kirsher { 3775aa43c215SJeff Kirsher struct device *dev = container_of(kobj, struct device, kobj); 3776aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3777aa43c215SJeff Kirsher struct qlcnic_pm_func_cfg *pm_cfg; 3778aa43c215SJeff Kirsher u32 id, action, pci_func; 3779aa43c215SJeff Kirsher int count, rem, i, ret; 3780aa43c215SJeff Kirsher 3781aa43c215SJeff Kirsher count = size / sizeof(struct qlcnic_pm_func_cfg); 3782aa43c215SJeff Kirsher rem = size % sizeof(struct qlcnic_pm_func_cfg); 3783aa43c215SJeff Kirsher if (rem) 3784aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3785aa43c215SJeff Kirsher 3786aa43c215SJeff Kirsher pm_cfg = (struct qlcnic_pm_func_cfg *) buf; 3787aa43c215SJeff Kirsher 3788aa43c215SJeff Kirsher ret = validate_pm_config(adapter, pm_cfg, count); 3789aa43c215SJeff Kirsher if (ret) 3790aa43c215SJeff Kirsher return ret; 3791aa43c215SJeff Kirsher for (i = 0; i < count; i++) { 3792aa43c215SJeff Kirsher pci_func = pm_cfg[i].pci_func; 3793aa43c215SJeff Kirsher action = !!pm_cfg[i].action; 3794aa43c215SJeff Kirsher id = adapter->npars[pci_func].phy_port; 3795aa43c215SJeff Kirsher ret = qlcnic_config_port_mirroring(adapter, id, 3796aa43c215SJeff Kirsher action, pci_func); 3797aa43c215SJeff Kirsher if (ret) 3798aa43c215SJeff Kirsher return ret; 3799aa43c215SJeff Kirsher } 3800aa43c215SJeff Kirsher 3801aa43c215SJeff Kirsher for (i = 0; i < count; i++) { 3802aa43c215SJeff Kirsher pci_func = pm_cfg[i].pci_func; 3803aa43c215SJeff Kirsher id = adapter->npars[pci_func].phy_port; 3804aa43c215SJeff Kirsher adapter->npars[pci_func].enable_pm = !!pm_cfg[i].action; 3805aa43c215SJeff Kirsher adapter->npars[pci_func].dest_npar = id; 3806aa43c215SJeff Kirsher } 3807aa43c215SJeff Kirsher return size; 3808aa43c215SJeff Kirsher } 3809aa43c215SJeff Kirsher 3810aa43c215SJeff Kirsher static ssize_t 3811aa43c215SJeff Kirsher qlcnic_sysfs_read_pm_config(struct file *filp, struct kobject *kobj, 3812aa43c215SJeff Kirsher struct bin_attribute *attr, char *buf, loff_t offset, size_t size) 3813aa43c215SJeff Kirsher { 3814aa43c215SJeff Kirsher struct device *dev = container_of(kobj, struct device, kobj); 3815aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3816aa43c215SJeff Kirsher struct qlcnic_pm_func_cfg pm_cfg[QLCNIC_MAX_PCI_FUNC]; 3817aa43c215SJeff Kirsher int i; 3818aa43c215SJeff Kirsher 3819aa43c215SJeff Kirsher if (size != sizeof(pm_cfg)) 3820aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3821aa43c215SJeff Kirsher 3822aa43c215SJeff Kirsher for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { 3823aa43c215SJeff Kirsher if (adapter->npars[i].type != QLCNIC_TYPE_NIC) 3824aa43c215SJeff Kirsher continue; 3825aa43c215SJeff Kirsher pm_cfg[i].action = adapter->npars[i].enable_pm; 3826aa43c215SJeff Kirsher pm_cfg[i].dest_npar = 0; 3827aa43c215SJeff Kirsher pm_cfg[i].pci_func = i; 3828aa43c215SJeff Kirsher } 3829aa43c215SJeff Kirsher memcpy(buf, &pm_cfg, size); 3830aa43c215SJeff Kirsher 3831aa43c215SJeff Kirsher return size; 3832aa43c215SJeff Kirsher } 3833aa43c215SJeff Kirsher 3834aa43c215SJeff Kirsher static int 3835aa43c215SJeff Kirsher validate_esw_config(struct qlcnic_adapter *adapter, 3836aa43c215SJeff Kirsher struct qlcnic_esw_func_cfg *esw_cfg, int count) 3837aa43c215SJeff Kirsher { 3838aa43c215SJeff Kirsher u32 op_mode; 3839aa43c215SJeff Kirsher u8 pci_func; 3840aa43c215SJeff Kirsher int i; 3841aa43c215SJeff Kirsher 3842aa43c215SJeff Kirsher op_mode = readl(adapter->ahw->pci_base0 + QLCNIC_DRV_OP_MODE); 3843aa43c215SJeff Kirsher 3844aa43c215SJeff Kirsher for (i = 0; i < count; i++) { 3845aa43c215SJeff Kirsher pci_func = esw_cfg[i].pci_func; 3846aa43c215SJeff Kirsher if (pci_func >= QLCNIC_MAX_PCI_FUNC) 3847aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3848aa43c215SJeff Kirsher 3849aa43c215SJeff Kirsher if (adapter->op_mode == QLCNIC_MGMT_FUNC) 3850aa43c215SJeff Kirsher if (adapter->npars[pci_func].type != QLCNIC_TYPE_NIC) 3851aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3852aa43c215SJeff Kirsher 3853aa43c215SJeff Kirsher switch (esw_cfg[i].op_mode) { 3854aa43c215SJeff Kirsher case QLCNIC_PORT_DEFAULTS: 3855aa43c215SJeff Kirsher if (QLC_DEV_GET_DRV(op_mode, pci_func) != 3856aa43c215SJeff Kirsher QLCNIC_NON_PRIV_FUNC) { 3857aa43c215SJeff Kirsher if (esw_cfg[i].mac_anti_spoof != 0) 3858aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3859aa43c215SJeff Kirsher if (esw_cfg[i].mac_override != 1) 3860aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3861aa43c215SJeff Kirsher if (esw_cfg[i].promisc_mode != 1) 3862aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3863aa43c215SJeff Kirsher } 3864aa43c215SJeff Kirsher break; 3865aa43c215SJeff Kirsher case QLCNIC_ADD_VLAN: 3866aa43c215SJeff Kirsher if (!IS_VALID_VLAN(esw_cfg[i].vlan_id)) 3867aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3868aa43c215SJeff Kirsher if (!esw_cfg[i].op_type) 3869aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3870aa43c215SJeff Kirsher break; 3871aa43c215SJeff Kirsher case QLCNIC_DEL_VLAN: 3872aa43c215SJeff Kirsher if (!esw_cfg[i].op_type) 3873aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3874aa43c215SJeff Kirsher break; 3875aa43c215SJeff Kirsher default: 3876aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3877aa43c215SJeff Kirsher } 3878aa43c215SJeff Kirsher } 3879aa43c215SJeff Kirsher return 0; 3880aa43c215SJeff Kirsher } 3881aa43c215SJeff Kirsher 3882aa43c215SJeff Kirsher static ssize_t 3883aa43c215SJeff Kirsher qlcnic_sysfs_write_esw_config(struct file *file, struct kobject *kobj, 3884aa43c215SJeff Kirsher struct bin_attribute *attr, char *buf, loff_t offset, size_t size) 3885aa43c215SJeff Kirsher { 3886aa43c215SJeff Kirsher struct device *dev = container_of(kobj, struct device, kobj); 3887aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3888aa43c215SJeff Kirsher struct qlcnic_esw_func_cfg *esw_cfg; 3889aa43c215SJeff Kirsher struct qlcnic_npar_info *npar; 3890aa43c215SJeff Kirsher int count, rem, i, ret; 3891aa43c215SJeff Kirsher u8 pci_func, op_mode = 0; 3892aa43c215SJeff Kirsher 3893aa43c215SJeff Kirsher count = size / sizeof(struct qlcnic_esw_func_cfg); 3894aa43c215SJeff Kirsher rem = size % sizeof(struct qlcnic_esw_func_cfg); 3895aa43c215SJeff Kirsher if (rem) 3896aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3897aa43c215SJeff Kirsher 3898aa43c215SJeff Kirsher esw_cfg = (struct qlcnic_esw_func_cfg *) buf; 3899aa43c215SJeff Kirsher ret = validate_esw_config(adapter, esw_cfg, count); 3900aa43c215SJeff Kirsher if (ret) 3901aa43c215SJeff Kirsher return ret; 3902aa43c215SJeff Kirsher 3903aa43c215SJeff Kirsher for (i = 0; i < count; i++) { 3904aa43c215SJeff Kirsher if (adapter->op_mode == QLCNIC_MGMT_FUNC) 3905aa43c215SJeff Kirsher if (qlcnic_config_switch_port(adapter, &esw_cfg[i])) 3906aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3907aa43c215SJeff Kirsher 3908aa43c215SJeff Kirsher if (adapter->ahw->pci_func != esw_cfg[i].pci_func) 3909aa43c215SJeff Kirsher continue; 3910aa43c215SJeff Kirsher 3911aa43c215SJeff Kirsher op_mode = esw_cfg[i].op_mode; 3912aa43c215SJeff Kirsher qlcnic_get_eswitch_port_config(adapter, &esw_cfg[i]); 3913aa43c215SJeff Kirsher esw_cfg[i].op_mode = op_mode; 3914aa43c215SJeff Kirsher esw_cfg[i].pci_func = adapter->ahw->pci_func; 3915aa43c215SJeff Kirsher 3916aa43c215SJeff Kirsher switch (esw_cfg[i].op_mode) { 3917aa43c215SJeff Kirsher case QLCNIC_PORT_DEFAULTS: 3918aa43c215SJeff Kirsher qlcnic_set_eswitch_port_features(adapter, &esw_cfg[i]); 3919aa43c215SJeff Kirsher break; 3920aa43c215SJeff Kirsher case QLCNIC_ADD_VLAN: 3921aa43c215SJeff Kirsher qlcnic_set_vlan_config(adapter, &esw_cfg[i]); 3922aa43c215SJeff Kirsher break; 3923aa43c215SJeff Kirsher case QLCNIC_DEL_VLAN: 3924aa43c215SJeff Kirsher esw_cfg[i].vlan_id = 0; 3925aa43c215SJeff Kirsher qlcnic_set_vlan_config(adapter, &esw_cfg[i]); 3926aa43c215SJeff Kirsher break; 3927aa43c215SJeff Kirsher } 3928aa43c215SJeff Kirsher } 3929aa43c215SJeff Kirsher 3930aa43c215SJeff Kirsher if (adapter->op_mode != QLCNIC_MGMT_FUNC) 3931aa43c215SJeff Kirsher goto out; 3932aa43c215SJeff Kirsher 3933aa43c215SJeff Kirsher for (i = 0; i < count; i++) { 3934aa43c215SJeff Kirsher pci_func = esw_cfg[i].pci_func; 3935aa43c215SJeff Kirsher npar = &adapter->npars[pci_func]; 3936aa43c215SJeff Kirsher switch (esw_cfg[i].op_mode) { 3937aa43c215SJeff Kirsher case QLCNIC_PORT_DEFAULTS: 3938aa43c215SJeff Kirsher npar->promisc_mode = esw_cfg[i].promisc_mode; 3939aa43c215SJeff Kirsher npar->mac_override = esw_cfg[i].mac_override; 3940aa43c215SJeff Kirsher npar->offload_flags = esw_cfg[i].offload_flags; 3941aa43c215SJeff Kirsher npar->mac_anti_spoof = esw_cfg[i].mac_anti_spoof; 3942aa43c215SJeff Kirsher npar->discard_tagged = esw_cfg[i].discard_tagged; 3943aa43c215SJeff Kirsher break; 3944aa43c215SJeff Kirsher case QLCNIC_ADD_VLAN: 3945aa43c215SJeff Kirsher npar->pvid = esw_cfg[i].vlan_id; 3946aa43c215SJeff Kirsher break; 3947aa43c215SJeff Kirsher case QLCNIC_DEL_VLAN: 3948aa43c215SJeff Kirsher npar->pvid = 0; 3949aa43c215SJeff Kirsher break; 3950aa43c215SJeff Kirsher } 3951aa43c215SJeff Kirsher } 3952aa43c215SJeff Kirsher out: 3953aa43c215SJeff Kirsher return size; 3954aa43c215SJeff Kirsher } 3955aa43c215SJeff Kirsher 3956aa43c215SJeff Kirsher static ssize_t 3957aa43c215SJeff Kirsher qlcnic_sysfs_read_esw_config(struct file *file, struct kobject *kobj, 3958aa43c215SJeff Kirsher struct bin_attribute *attr, char *buf, loff_t offset, size_t size) 3959aa43c215SJeff Kirsher { 3960aa43c215SJeff Kirsher struct device *dev = container_of(kobj, struct device, kobj); 3961aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3962aa43c215SJeff Kirsher struct qlcnic_esw_func_cfg esw_cfg[QLCNIC_MAX_PCI_FUNC]; 3963aa43c215SJeff Kirsher u8 i; 3964aa43c215SJeff Kirsher 3965aa43c215SJeff Kirsher if (size != sizeof(esw_cfg)) 3966aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3967aa43c215SJeff Kirsher 3968aa43c215SJeff Kirsher for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { 3969aa43c215SJeff Kirsher if (adapter->npars[i].type != QLCNIC_TYPE_NIC) 3970aa43c215SJeff Kirsher continue; 3971aa43c215SJeff Kirsher esw_cfg[i].pci_func = i; 3972aa43c215SJeff Kirsher if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg[i])) 3973aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3974aa43c215SJeff Kirsher } 3975aa43c215SJeff Kirsher memcpy(buf, &esw_cfg, size); 3976aa43c215SJeff Kirsher 3977aa43c215SJeff Kirsher return size; 3978aa43c215SJeff Kirsher } 3979aa43c215SJeff Kirsher 3980aa43c215SJeff Kirsher static int 3981aa43c215SJeff Kirsher validate_npar_config(struct qlcnic_adapter *adapter, 3982aa43c215SJeff Kirsher struct qlcnic_npar_func_cfg *np_cfg, int count) 3983aa43c215SJeff Kirsher { 3984aa43c215SJeff Kirsher u8 pci_func, i; 3985aa43c215SJeff Kirsher 3986aa43c215SJeff Kirsher for (i = 0; i < count; i++) { 3987aa43c215SJeff Kirsher pci_func = np_cfg[i].pci_func; 3988aa43c215SJeff Kirsher if (pci_func >= QLCNIC_MAX_PCI_FUNC) 3989aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3990aa43c215SJeff Kirsher 3991aa43c215SJeff Kirsher if (adapter->npars[pci_func].type != QLCNIC_TYPE_NIC) 3992aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3993aa43c215SJeff Kirsher 3994aa43c215SJeff Kirsher if (!IS_VALID_BW(np_cfg[i].min_bw) || 3995aa43c215SJeff Kirsher !IS_VALID_BW(np_cfg[i].max_bw)) 3996aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 3997aa43c215SJeff Kirsher } 3998aa43c215SJeff Kirsher return 0; 3999aa43c215SJeff Kirsher } 4000aa43c215SJeff Kirsher 4001aa43c215SJeff Kirsher static ssize_t 4002aa43c215SJeff Kirsher qlcnic_sysfs_write_npar_config(struct file *file, struct kobject *kobj, 4003aa43c215SJeff Kirsher struct bin_attribute *attr, char *buf, loff_t offset, size_t size) 4004aa43c215SJeff Kirsher { 4005aa43c215SJeff Kirsher struct device *dev = container_of(kobj, struct device, kobj); 4006aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 4007aa43c215SJeff Kirsher struct qlcnic_info nic_info; 4008aa43c215SJeff Kirsher struct qlcnic_npar_func_cfg *np_cfg; 4009aa43c215SJeff Kirsher int i, count, rem, ret; 4010aa43c215SJeff Kirsher u8 pci_func; 4011aa43c215SJeff Kirsher 4012aa43c215SJeff Kirsher count = size / sizeof(struct qlcnic_npar_func_cfg); 4013aa43c215SJeff Kirsher rem = size % sizeof(struct qlcnic_npar_func_cfg); 4014aa43c215SJeff Kirsher if (rem) 4015aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 4016aa43c215SJeff Kirsher 4017aa43c215SJeff Kirsher np_cfg = (struct qlcnic_npar_func_cfg *) buf; 4018aa43c215SJeff Kirsher ret = validate_npar_config(adapter, np_cfg, count); 4019aa43c215SJeff Kirsher if (ret) 4020aa43c215SJeff Kirsher return ret; 4021aa43c215SJeff Kirsher 4022aa43c215SJeff Kirsher for (i = 0; i < count ; i++) { 4023aa43c215SJeff Kirsher pci_func = np_cfg[i].pci_func; 4024aa43c215SJeff Kirsher ret = qlcnic_get_nic_info(adapter, &nic_info, pci_func); 4025aa43c215SJeff Kirsher if (ret) 4026aa43c215SJeff Kirsher return ret; 4027aa43c215SJeff Kirsher nic_info.pci_func = pci_func; 4028aa43c215SJeff Kirsher nic_info.min_tx_bw = np_cfg[i].min_bw; 4029aa43c215SJeff Kirsher nic_info.max_tx_bw = np_cfg[i].max_bw; 4030aa43c215SJeff Kirsher ret = qlcnic_set_nic_info(adapter, &nic_info); 4031aa43c215SJeff Kirsher if (ret) 4032aa43c215SJeff Kirsher return ret; 4033aa43c215SJeff Kirsher adapter->npars[i].min_bw = nic_info.min_tx_bw; 4034aa43c215SJeff Kirsher adapter->npars[i].max_bw = nic_info.max_tx_bw; 4035aa43c215SJeff Kirsher } 4036aa43c215SJeff Kirsher 4037aa43c215SJeff Kirsher return size; 4038aa43c215SJeff Kirsher 4039aa43c215SJeff Kirsher } 4040aa43c215SJeff Kirsher static ssize_t 4041aa43c215SJeff Kirsher qlcnic_sysfs_read_npar_config(struct file *file, struct kobject *kobj, 4042aa43c215SJeff Kirsher struct bin_attribute *attr, char *buf, loff_t offset, size_t size) 4043aa43c215SJeff Kirsher { 4044aa43c215SJeff Kirsher struct device *dev = container_of(kobj, struct device, kobj); 4045aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 4046aa43c215SJeff Kirsher struct qlcnic_info nic_info; 4047aa43c215SJeff Kirsher struct qlcnic_npar_func_cfg np_cfg[QLCNIC_MAX_PCI_FUNC]; 4048aa43c215SJeff Kirsher int i, ret; 4049aa43c215SJeff Kirsher 4050aa43c215SJeff Kirsher if (size != sizeof(np_cfg)) 4051aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 4052aa43c215SJeff Kirsher 4053aa43c215SJeff Kirsher for (i = 0; i < QLCNIC_MAX_PCI_FUNC ; i++) { 4054aa43c215SJeff Kirsher if (adapter->npars[i].type != QLCNIC_TYPE_NIC) 4055aa43c215SJeff Kirsher continue; 4056aa43c215SJeff Kirsher ret = qlcnic_get_nic_info(adapter, &nic_info, i); 4057aa43c215SJeff Kirsher if (ret) 4058aa43c215SJeff Kirsher return ret; 4059aa43c215SJeff Kirsher 4060aa43c215SJeff Kirsher np_cfg[i].pci_func = i; 4061aa43c215SJeff Kirsher np_cfg[i].op_mode = (u8)nic_info.op_mode; 4062aa43c215SJeff Kirsher np_cfg[i].port_num = nic_info.phys_port; 4063aa43c215SJeff Kirsher np_cfg[i].fw_capab = nic_info.capabilities; 4064aa43c215SJeff Kirsher np_cfg[i].min_bw = nic_info.min_tx_bw ; 4065aa43c215SJeff Kirsher np_cfg[i].max_bw = nic_info.max_tx_bw; 4066aa43c215SJeff Kirsher np_cfg[i].max_tx_queues = nic_info.max_tx_ques; 4067aa43c215SJeff Kirsher np_cfg[i].max_rx_queues = nic_info.max_rx_ques; 4068aa43c215SJeff Kirsher } 4069aa43c215SJeff Kirsher memcpy(buf, &np_cfg, size); 4070aa43c215SJeff Kirsher return size; 4071aa43c215SJeff Kirsher } 4072aa43c215SJeff Kirsher 4073aa43c215SJeff Kirsher static ssize_t 4074aa43c215SJeff Kirsher qlcnic_sysfs_get_port_stats(struct file *file, struct kobject *kobj, 4075aa43c215SJeff Kirsher struct bin_attribute *attr, char *buf, loff_t offset, size_t size) 4076aa43c215SJeff Kirsher { 4077aa43c215SJeff Kirsher struct device *dev = container_of(kobj, struct device, kobj); 4078aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 4079aa43c215SJeff Kirsher struct qlcnic_esw_statistics port_stats; 4080aa43c215SJeff Kirsher int ret; 4081aa43c215SJeff Kirsher 4082aa43c215SJeff Kirsher if (size != sizeof(struct qlcnic_esw_statistics)) 4083aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 4084aa43c215SJeff Kirsher 4085aa43c215SJeff Kirsher if (offset >= QLCNIC_MAX_PCI_FUNC) 4086aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 4087aa43c215SJeff Kirsher 4088aa43c215SJeff Kirsher memset(&port_stats, 0, size); 4089aa43c215SJeff Kirsher ret = qlcnic_get_port_stats(adapter, offset, QLCNIC_QUERY_RX_COUNTER, 4090aa43c215SJeff Kirsher &port_stats.rx); 4091aa43c215SJeff Kirsher if (ret) 4092aa43c215SJeff Kirsher return ret; 4093aa43c215SJeff Kirsher 4094aa43c215SJeff Kirsher ret = qlcnic_get_port_stats(adapter, offset, QLCNIC_QUERY_TX_COUNTER, 4095aa43c215SJeff Kirsher &port_stats.tx); 4096aa43c215SJeff Kirsher if (ret) 4097aa43c215SJeff Kirsher return ret; 4098aa43c215SJeff Kirsher 4099aa43c215SJeff Kirsher memcpy(buf, &port_stats, size); 4100aa43c215SJeff Kirsher return size; 4101aa43c215SJeff Kirsher } 4102aa43c215SJeff Kirsher 4103aa43c215SJeff Kirsher static ssize_t 4104aa43c215SJeff Kirsher qlcnic_sysfs_get_esw_stats(struct file *file, struct kobject *kobj, 4105aa43c215SJeff Kirsher struct bin_attribute *attr, char *buf, loff_t offset, size_t size) 4106aa43c215SJeff Kirsher { 4107aa43c215SJeff Kirsher struct device *dev = container_of(kobj, struct device, kobj); 4108aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 4109aa43c215SJeff Kirsher struct qlcnic_esw_statistics esw_stats; 4110aa43c215SJeff Kirsher int ret; 4111aa43c215SJeff Kirsher 4112aa43c215SJeff Kirsher if (size != sizeof(struct qlcnic_esw_statistics)) 4113aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 4114aa43c215SJeff Kirsher 4115aa43c215SJeff Kirsher if (offset >= QLCNIC_NIU_MAX_XG_PORTS) 4116aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 4117aa43c215SJeff Kirsher 4118aa43c215SJeff Kirsher memset(&esw_stats, 0, size); 4119aa43c215SJeff Kirsher ret = qlcnic_get_eswitch_stats(adapter, offset, QLCNIC_QUERY_RX_COUNTER, 4120aa43c215SJeff Kirsher &esw_stats.rx); 4121aa43c215SJeff Kirsher if (ret) 4122aa43c215SJeff Kirsher return ret; 4123aa43c215SJeff Kirsher 4124aa43c215SJeff Kirsher ret = qlcnic_get_eswitch_stats(adapter, offset, QLCNIC_QUERY_TX_COUNTER, 4125aa43c215SJeff Kirsher &esw_stats.tx); 4126aa43c215SJeff Kirsher if (ret) 4127aa43c215SJeff Kirsher return ret; 4128aa43c215SJeff Kirsher 4129aa43c215SJeff Kirsher memcpy(buf, &esw_stats, size); 4130aa43c215SJeff Kirsher return size; 4131aa43c215SJeff Kirsher } 4132aa43c215SJeff Kirsher 4133aa43c215SJeff Kirsher static ssize_t 4134aa43c215SJeff Kirsher qlcnic_sysfs_clear_esw_stats(struct file *file, struct kobject *kobj, 4135aa43c215SJeff Kirsher struct bin_attribute *attr, char *buf, loff_t offset, size_t size) 4136aa43c215SJeff Kirsher { 4137aa43c215SJeff Kirsher struct device *dev = container_of(kobj, struct device, kobj); 4138aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 4139aa43c215SJeff Kirsher int ret; 4140aa43c215SJeff Kirsher 4141aa43c215SJeff Kirsher if (offset >= QLCNIC_NIU_MAX_XG_PORTS) 4142aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 4143aa43c215SJeff Kirsher 4144aa43c215SJeff Kirsher ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_ESWITCH, offset, 4145aa43c215SJeff Kirsher QLCNIC_QUERY_RX_COUNTER); 4146aa43c215SJeff Kirsher if (ret) 4147aa43c215SJeff Kirsher return ret; 4148aa43c215SJeff Kirsher 4149aa43c215SJeff Kirsher ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_ESWITCH, offset, 4150aa43c215SJeff Kirsher QLCNIC_QUERY_TX_COUNTER); 4151aa43c215SJeff Kirsher if (ret) 4152aa43c215SJeff Kirsher return ret; 4153aa43c215SJeff Kirsher 4154aa43c215SJeff Kirsher return size; 4155aa43c215SJeff Kirsher } 4156aa43c215SJeff Kirsher 4157aa43c215SJeff Kirsher static ssize_t 4158aa43c215SJeff Kirsher qlcnic_sysfs_clear_port_stats(struct file *file, struct kobject *kobj, 4159aa43c215SJeff Kirsher struct bin_attribute *attr, char *buf, loff_t offset, size_t size) 4160aa43c215SJeff Kirsher { 4161aa43c215SJeff Kirsher 4162aa43c215SJeff Kirsher struct device *dev = container_of(kobj, struct device, kobj); 4163aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 4164aa43c215SJeff Kirsher int ret; 4165aa43c215SJeff Kirsher 4166aa43c215SJeff Kirsher if (offset >= QLCNIC_MAX_PCI_FUNC) 4167aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 4168aa43c215SJeff Kirsher 4169aa43c215SJeff Kirsher ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_PORT, offset, 4170aa43c215SJeff Kirsher QLCNIC_QUERY_RX_COUNTER); 4171aa43c215SJeff Kirsher if (ret) 4172aa43c215SJeff Kirsher return ret; 4173aa43c215SJeff Kirsher 4174aa43c215SJeff Kirsher ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_PORT, offset, 4175aa43c215SJeff Kirsher QLCNIC_QUERY_TX_COUNTER); 4176aa43c215SJeff Kirsher if (ret) 4177aa43c215SJeff Kirsher return ret; 4178aa43c215SJeff Kirsher 4179aa43c215SJeff Kirsher return size; 4180aa43c215SJeff Kirsher } 4181aa43c215SJeff Kirsher 4182aa43c215SJeff Kirsher static ssize_t 4183aa43c215SJeff Kirsher qlcnic_sysfs_read_pci_config(struct file *file, struct kobject *kobj, 4184aa43c215SJeff Kirsher struct bin_attribute *attr, char *buf, loff_t offset, size_t size) 4185aa43c215SJeff Kirsher { 4186aa43c215SJeff Kirsher struct device *dev = container_of(kobj, struct device, kobj); 4187aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 4188aa43c215SJeff Kirsher struct qlcnic_pci_func_cfg pci_cfg[QLCNIC_MAX_PCI_FUNC]; 4189aa43c215SJeff Kirsher struct qlcnic_pci_info *pci_info; 4190aa43c215SJeff Kirsher int i, ret; 4191aa43c215SJeff Kirsher 4192aa43c215SJeff Kirsher if (size != sizeof(pci_cfg)) 4193aa43c215SJeff Kirsher return QL_STATUS_INVALID_PARAM; 4194aa43c215SJeff Kirsher 4195aa43c215SJeff Kirsher pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL); 4196aa43c215SJeff Kirsher if (!pci_info) 4197aa43c215SJeff Kirsher return -ENOMEM; 4198aa43c215SJeff Kirsher 4199aa43c215SJeff Kirsher ret = qlcnic_get_pci_info(adapter, pci_info); 4200aa43c215SJeff Kirsher if (ret) { 4201aa43c215SJeff Kirsher kfree(pci_info); 4202aa43c215SJeff Kirsher return ret; 4203aa43c215SJeff Kirsher } 4204aa43c215SJeff Kirsher 4205aa43c215SJeff Kirsher for (i = 0; i < QLCNIC_MAX_PCI_FUNC ; i++) { 4206aa43c215SJeff Kirsher pci_cfg[i].pci_func = pci_info[i].id; 4207aa43c215SJeff Kirsher pci_cfg[i].func_type = pci_info[i].type; 4208aa43c215SJeff Kirsher pci_cfg[i].port_num = pci_info[i].default_port; 4209aa43c215SJeff Kirsher pci_cfg[i].min_bw = pci_info[i].tx_min_bw; 4210aa43c215SJeff Kirsher pci_cfg[i].max_bw = pci_info[i].tx_max_bw; 4211aa43c215SJeff Kirsher memcpy(&pci_cfg[i].def_mac_addr, &pci_info[i].mac, ETH_ALEN); 4212aa43c215SJeff Kirsher } 4213aa43c215SJeff Kirsher memcpy(buf, &pci_cfg, size); 4214aa43c215SJeff Kirsher kfree(pci_info); 4215aa43c215SJeff Kirsher return size; 4216aa43c215SJeff Kirsher } 4217aa43c215SJeff Kirsher static struct bin_attribute bin_attr_npar_config = { 4218aa43c215SJeff Kirsher .attr = {.name = "npar_config", .mode = (S_IRUGO | S_IWUSR)}, 4219aa43c215SJeff Kirsher .size = 0, 4220aa43c215SJeff Kirsher .read = qlcnic_sysfs_read_npar_config, 4221aa43c215SJeff Kirsher .write = qlcnic_sysfs_write_npar_config, 4222aa43c215SJeff Kirsher }; 4223aa43c215SJeff Kirsher 4224aa43c215SJeff Kirsher static struct bin_attribute bin_attr_pci_config = { 4225aa43c215SJeff Kirsher .attr = {.name = "pci_config", .mode = (S_IRUGO | S_IWUSR)}, 4226aa43c215SJeff Kirsher .size = 0, 4227aa43c215SJeff Kirsher .read = qlcnic_sysfs_read_pci_config, 4228aa43c215SJeff Kirsher .write = NULL, 4229aa43c215SJeff Kirsher }; 4230aa43c215SJeff Kirsher 4231aa43c215SJeff Kirsher static struct bin_attribute bin_attr_port_stats = { 4232aa43c215SJeff Kirsher .attr = {.name = "port_stats", .mode = (S_IRUGO | S_IWUSR)}, 4233aa43c215SJeff Kirsher .size = 0, 4234aa43c215SJeff Kirsher .read = qlcnic_sysfs_get_port_stats, 4235aa43c215SJeff Kirsher .write = qlcnic_sysfs_clear_port_stats, 4236aa43c215SJeff Kirsher }; 4237aa43c215SJeff Kirsher 4238aa43c215SJeff Kirsher static struct bin_attribute bin_attr_esw_stats = { 4239aa43c215SJeff Kirsher .attr = {.name = "esw_stats", .mode = (S_IRUGO | S_IWUSR)}, 4240aa43c215SJeff Kirsher .size = 0, 4241aa43c215SJeff Kirsher .read = qlcnic_sysfs_get_esw_stats, 4242aa43c215SJeff Kirsher .write = qlcnic_sysfs_clear_esw_stats, 4243aa43c215SJeff Kirsher }; 4244aa43c215SJeff Kirsher 4245aa43c215SJeff Kirsher static struct bin_attribute bin_attr_esw_config = { 4246aa43c215SJeff Kirsher .attr = {.name = "esw_config", .mode = (S_IRUGO | S_IWUSR)}, 4247aa43c215SJeff Kirsher .size = 0, 4248aa43c215SJeff Kirsher .read = qlcnic_sysfs_read_esw_config, 4249aa43c215SJeff Kirsher .write = qlcnic_sysfs_write_esw_config, 4250aa43c215SJeff Kirsher }; 4251aa43c215SJeff Kirsher 4252aa43c215SJeff Kirsher static struct bin_attribute bin_attr_pm_config = { 4253aa43c215SJeff Kirsher .attr = {.name = "pm_config", .mode = (S_IRUGO | S_IWUSR)}, 4254aa43c215SJeff Kirsher .size = 0, 4255aa43c215SJeff Kirsher .read = qlcnic_sysfs_read_pm_config, 4256aa43c215SJeff Kirsher .write = qlcnic_sysfs_write_pm_config, 4257aa43c215SJeff Kirsher }; 4258aa43c215SJeff Kirsher 4259aa43c215SJeff Kirsher static void 4260aa43c215SJeff Kirsher qlcnic_create_sysfs_entries(struct qlcnic_adapter *adapter) 4261aa43c215SJeff Kirsher { 4262aa43c215SJeff Kirsher struct device *dev = &adapter->pdev->dev; 4263aa43c215SJeff Kirsher 4264aa43c215SJeff Kirsher if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG) 4265aa43c215SJeff Kirsher if (device_create_file(dev, &dev_attr_bridged_mode)) 4266aa43c215SJeff Kirsher dev_warn(dev, 4267aa43c215SJeff Kirsher "failed to create bridged_mode sysfs entry\n"); 4268aa43c215SJeff Kirsher } 4269aa43c215SJeff Kirsher 4270aa43c215SJeff Kirsher static void 4271aa43c215SJeff Kirsher qlcnic_remove_sysfs_entries(struct qlcnic_adapter *adapter) 4272aa43c215SJeff Kirsher { 4273aa43c215SJeff Kirsher struct device *dev = &adapter->pdev->dev; 4274aa43c215SJeff Kirsher 4275aa43c215SJeff Kirsher if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG) 4276aa43c215SJeff Kirsher device_remove_file(dev, &dev_attr_bridged_mode); 4277aa43c215SJeff Kirsher } 4278aa43c215SJeff Kirsher 4279aa43c215SJeff Kirsher static void 4280aa43c215SJeff Kirsher qlcnic_create_diag_entries(struct qlcnic_adapter *adapter) 4281aa43c215SJeff Kirsher { 4282aa43c215SJeff Kirsher struct device *dev = &adapter->pdev->dev; 4283aa43c215SJeff Kirsher 4284aa43c215SJeff Kirsher if (device_create_bin_file(dev, &bin_attr_port_stats)) 4285aa43c215SJeff Kirsher dev_info(dev, "failed to create port stats sysfs entry"); 4286aa43c215SJeff Kirsher 4287aa43c215SJeff Kirsher if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC) 4288aa43c215SJeff Kirsher return; 4289aa43c215SJeff Kirsher if (device_create_file(dev, &dev_attr_diag_mode)) 4290aa43c215SJeff Kirsher dev_info(dev, "failed to create diag_mode sysfs entry\n"); 4291728a98b8SSucheta Chakraborty if (device_create_file(dev, &dev_attr_beacon)) 4292728a98b8SSucheta Chakraborty dev_info(dev, "failed to create beacon sysfs entry"); 4293aa43c215SJeff Kirsher if (device_create_bin_file(dev, &bin_attr_crb)) 4294aa43c215SJeff Kirsher dev_info(dev, "failed to create crb sysfs entry\n"); 4295aa43c215SJeff Kirsher if (device_create_bin_file(dev, &bin_attr_mem)) 4296aa43c215SJeff Kirsher dev_info(dev, "failed to create mem sysfs entry\n"); 4297aa43c215SJeff Kirsher if (device_create_bin_file(dev, &bin_attr_pci_config)) 4298aa43c215SJeff Kirsher dev_info(dev, "failed to create pci config sysfs entry"); 4299aa43c215SJeff Kirsher if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) 4300aa43c215SJeff Kirsher return; 4301aa43c215SJeff Kirsher if (device_create_bin_file(dev, &bin_attr_esw_config)) 4302aa43c215SJeff Kirsher dev_info(dev, "failed to create esw config sysfs entry"); 4303aa43c215SJeff Kirsher if (adapter->op_mode != QLCNIC_MGMT_FUNC) 4304aa43c215SJeff Kirsher return; 4305aa43c215SJeff Kirsher if (device_create_bin_file(dev, &bin_attr_npar_config)) 4306aa43c215SJeff Kirsher dev_info(dev, "failed to create npar config sysfs entry"); 4307aa43c215SJeff Kirsher if (device_create_bin_file(dev, &bin_attr_pm_config)) 4308aa43c215SJeff Kirsher dev_info(dev, "failed to create pm config sysfs entry"); 4309aa43c215SJeff Kirsher if (device_create_bin_file(dev, &bin_attr_esw_stats)) 4310aa43c215SJeff Kirsher dev_info(dev, "failed to create eswitch stats sysfs entry"); 4311aa43c215SJeff Kirsher } 4312aa43c215SJeff Kirsher 4313aa43c215SJeff Kirsher static void 4314aa43c215SJeff Kirsher qlcnic_remove_diag_entries(struct qlcnic_adapter *adapter) 4315aa43c215SJeff Kirsher { 4316aa43c215SJeff Kirsher struct device *dev = &adapter->pdev->dev; 4317aa43c215SJeff Kirsher 4318aa43c215SJeff Kirsher device_remove_bin_file(dev, &bin_attr_port_stats); 4319aa43c215SJeff Kirsher 4320aa43c215SJeff Kirsher if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC) 4321aa43c215SJeff Kirsher return; 4322aa43c215SJeff Kirsher device_remove_file(dev, &dev_attr_diag_mode); 4323728a98b8SSucheta Chakraborty device_remove_file(dev, &dev_attr_beacon); 4324aa43c215SJeff Kirsher device_remove_bin_file(dev, &bin_attr_crb); 4325aa43c215SJeff Kirsher device_remove_bin_file(dev, &bin_attr_mem); 4326aa43c215SJeff Kirsher device_remove_bin_file(dev, &bin_attr_pci_config); 4327aa43c215SJeff Kirsher if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) 4328aa43c215SJeff Kirsher return; 4329aa43c215SJeff Kirsher device_remove_bin_file(dev, &bin_attr_esw_config); 4330aa43c215SJeff Kirsher if (adapter->op_mode != QLCNIC_MGMT_FUNC) 4331aa43c215SJeff Kirsher return; 4332aa43c215SJeff Kirsher device_remove_bin_file(dev, &bin_attr_npar_config); 4333aa43c215SJeff Kirsher device_remove_bin_file(dev, &bin_attr_pm_config); 4334aa43c215SJeff Kirsher device_remove_bin_file(dev, &bin_attr_esw_stats); 4335aa43c215SJeff Kirsher } 4336aa43c215SJeff Kirsher 4337aa43c215SJeff Kirsher #ifdef CONFIG_INET 4338aa43c215SJeff Kirsher 4339aa43c215SJeff Kirsher #define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops) 4340aa43c215SJeff Kirsher 4341aa43c215SJeff Kirsher static void 4342aa43c215SJeff Kirsher qlcnic_config_indev_addr(struct qlcnic_adapter *adapter, 4343aa43c215SJeff Kirsher struct net_device *dev, unsigned long event) 4344aa43c215SJeff Kirsher { 4345aa43c215SJeff Kirsher struct in_device *indev; 4346aa43c215SJeff Kirsher 4347aa43c215SJeff Kirsher indev = in_dev_get(dev); 4348aa43c215SJeff Kirsher if (!indev) 4349aa43c215SJeff Kirsher return; 4350aa43c215SJeff Kirsher 4351aa43c215SJeff Kirsher for_ifa(indev) { 4352aa43c215SJeff Kirsher switch (event) { 4353aa43c215SJeff Kirsher case NETDEV_UP: 4354aa43c215SJeff Kirsher qlcnic_config_ipaddr(adapter, 4355aa43c215SJeff Kirsher ifa->ifa_address, QLCNIC_IP_UP); 4356aa43c215SJeff Kirsher break; 4357aa43c215SJeff Kirsher case NETDEV_DOWN: 4358aa43c215SJeff Kirsher qlcnic_config_ipaddr(adapter, 4359aa43c215SJeff Kirsher ifa->ifa_address, QLCNIC_IP_DOWN); 4360aa43c215SJeff Kirsher break; 4361aa43c215SJeff Kirsher default: 4362aa43c215SJeff Kirsher break; 4363aa43c215SJeff Kirsher } 4364aa43c215SJeff Kirsher } endfor_ifa(indev); 4365aa43c215SJeff Kirsher 4366aa43c215SJeff Kirsher in_dev_put(indev); 4367aa43c215SJeff Kirsher } 4368aa43c215SJeff Kirsher 4369aa43c215SJeff Kirsher static void 4370aa43c215SJeff Kirsher qlcnic_restore_indev_addr(struct net_device *netdev, unsigned long event) 4371aa43c215SJeff Kirsher { 4372aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 4373aa43c215SJeff Kirsher struct net_device *dev; 4374aa43c215SJeff Kirsher u16 vid; 4375aa43c215SJeff Kirsher 4376aa43c215SJeff Kirsher qlcnic_config_indev_addr(adapter, netdev, event); 4377aa43c215SJeff Kirsher 4378aa43c215SJeff Kirsher for_each_set_bit(vid, adapter->vlans, VLAN_N_VID) { 4379aa43c215SJeff Kirsher dev = __vlan_find_dev_deep(netdev, vid); 4380aa43c215SJeff Kirsher if (!dev) 4381aa43c215SJeff Kirsher continue; 4382aa43c215SJeff Kirsher qlcnic_config_indev_addr(adapter, dev, event); 4383aa43c215SJeff Kirsher } 4384aa43c215SJeff Kirsher } 4385aa43c215SJeff Kirsher 4386aa43c215SJeff Kirsher static int qlcnic_netdev_event(struct notifier_block *this, 4387aa43c215SJeff Kirsher unsigned long event, void *ptr) 4388aa43c215SJeff Kirsher { 4389aa43c215SJeff Kirsher struct qlcnic_adapter *adapter; 4390aa43c215SJeff Kirsher struct net_device *dev = (struct net_device *)ptr; 4391aa43c215SJeff Kirsher 4392aa43c215SJeff Kirsher recheck: 4393aa43c215SJeff Kirsher if (dev == NULL) 4394aa43c215SJeff Kirsher goto done; 4395aa43c215SJeff Kirsher 4396aa43c215SJeff Kirsher if (dev->priv_flags & IFF_802_1Q_VLAN) { 4397aa43c215SJeff Kirsher dev = vlan_dev_real_dev(dev); 4398aa43c215SJeff Kirsher goto recheck; 4399aa43c215SJeff Kirsher } 4400aa43c215SJeff Kirsher 4401aa43c215SJeff Kirsher if (!is_qlcnic_netdev(dev)) 4402aa43c215SJeff Kirsher goto done; 4403aa43c215SJeff Kirsher 4404aa43c215SJeff Kirsher adapter = netdev_priv(dev); 4405aa43c215SJeff Kirsher 4406aa43c215SJeff Kirsher if (!adapter) 4407aa43c215SJeff Kirsher goto done; 4408aa43c215SJeff Kirsher 4409aa43c215SJeff Kirsher if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) 4410aa43c215SJeff Kirsher goto done; 4411aa43c215SJeff Kirsher 4412aa43c215SJeff Kirsher qlcnic_config_indev_addr(adapter, dev, event); 4413aa43c215SJeff Kirsher done: 4414aa43c215SJeff Kirsher return NOTIFY_DONE; 4415aa43c215SJeff Kirsher } 4416aa43c215SJeff Kirsher 4417aa43c215SJeff Kirsher static int 4418aa43c215SJeff Kirsher qlcnic_inetaddr_event(struct notifier_block *this, 4419aa43c215SJeff Kirsher unsigned long event, void *ptr) 4420aa43c215SJeff Kirsher { 4421aa43c215SJeff Kirsher struct qlcnic_adapter *adapter; 4422aa43c215SJeff Kirsher struct net_device *dev; 4423aa43c215SJeff Kirsher 4424aa43c215SJeff Kirsher struct in_ifaddr *ifa = (struct in_ifaddr *)ptr; 4425aa43c215SJeff Kirsher 4426aa43c215SJeff Kirsher dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL; 4427aa43c215SJeff Kirsher 4428aa43c215SJeff Kirsher recheck: 4429aa43c215SJeff Kirsher if (dev == NULL) 4430aa43c215SJeff Kirsher goto done; 4431aa43c215SJeff Kirsher 4432aa43c215SJeff Kirsher if (dev->priv_flags & IFF_802_1Q_VLAN) { 4433aa43c215SJeff Kirsher dev = vlan_dev_real_dev(dev); 4434aa43c215SJeff Kirsher goto recheck; 4435aa43c215SJeff Kirsher } 4436aa43c215SJeff Kirsher 4437aa43c215SJeff Kirsher if (!is_qlcnic_netdev(dev)) 4438aa43c215SJeff Kirsher goto done; 4439aa43c215SJeff Kirsher 4440aa43c215SJeff Kirsher adapter = netdev_priv(dev); 4441aa43c215SJeff Kirsher 4442aa43c215SJeff Kirsher if (!adapter) 4443aa43c215SJeff Kirsher goto done; 4444aa43c215SJeff Kirsher 4445aa43c215SJeff Kirsher if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) 4446aa43c215SJeff Kirsher goto done; 4447aa43c215SJeff Kirsher 4448aa43c215SJeff Kirsher switch (event) { 4449aa43c215SJeff Kirsher case NETDEV_UP: 4450aa43c215SJeff Kirsher qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_UP); 4451aa43c215SJeff Kirsher break; 4452aa43c215SJeff Kirsher case NETDEV_DOWN: 4453aa43c215SJeff Kirsher qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_DOWN); 4454aa43c215SJeff Kirsher break; 4455aa43c215SJeff Kirsher default: 4456aa43c215SJeff Kirsher break; 4457aa43c215SJeff Kirsher } 4458aa43c215SJeff Kirsher 4459aa43c215SJeff Kirsher done: 4460aa43c215SJeff Kirsher return NOTIFY_DONE; 4461aa43c215SJeff Kirsher } 4462aa43c215SJeff Kirsher 4463aa43c215SJeff Kirsher static struct notifier_block qlcnic_netdev_cb = { 4464aa43c215SJeff Kirsher .notifier_call = qlcnic_netdev_event, 4465aa43c215SJeff Kirsher }; 4466aa43c215SJeff Kirsher 4467aa43c215SJeff Kirsher static struct notifier_block qlcnic_inetaddr_cb = { 4468aa43c215SJeff Kirsher .notifier_call = qlcnic_inetaddr_event, 4469aa43c215SJeff Kirsher }; 4470aa43c215SJeff Kirsher #else 4471aa43c215SJeff Kirsher static void 4472aa43c215SJeff Kirsher qlcnic_restore_indev_addr(struct net_device *dev, unsigned long event) 4473aa43c215SJeff Kirsher { } 4474aa43c215SJeff Kirsher #endif 4475aa43c215SJeff Kirsher static struct pci_error_handlers qlcnic_err_handler = { 4476aa43c215SJeff Kirsher .error_detected = qlcnic_io_error_detected, 4477aa43c215SJeff Kirsher .slot_reset = qlcnic_io_slot_reset, 4478aa43c215SJeff Kirsher .resume = qlcnic_io_resume, 4479aa43c215SJeff Kirsher }; 4480aa43c215SJeff Kirsher 4481aa43c215SJeff Kirsher static struct pci_driver qlcnic_driver = { 4482aa43c215SJeff Kirsher .name = qlcnic_driver_name, 4483aa43c215SJeff Kirsher .id_table = qlcnic_pci_tbl, 4484aa43c215SJeff Kirsher .probe = qlcnic_probe, 4485aa43c215SJeff Kirsher .remove = __devexit_p(qlcnic_remove), 4486aa43c215SJeff Kirsher #ifdef CONFIG_PM 4487aa43c215SJeff Kirsher .suspend = qlcnic_suspend, 4488aa43c215SJeff Kirsher .resume = qlcnic_resume, 4489aa43c215SJeff Kirsher #endif 4490aa43c215SJeff Kirsher .shutdown = qlcnic_shutdown, 4491aa43c215SJeff Kirsher .err_handler = &qlcnic_err_handler 4492aa43c215SJeff Kirsher 4493aa43c215SJeff Kirsher }; 4494aa43c215SJeff Kirsher 4495aa43c215SJeff Kirsher static int __init qlcnic_init_module(void) 4496aa43c215SJeff Kirsher { 4497aa43c215SJeff Kirsher int ret; 4498aa43c215SJeff Kirsher 4499aa43c215SJeff Kirsher printk(KERN_INFO "%s\n", qlcnic_driver_string); 4500aa43c215SJeff Kirsher 4501aa43c215SJeff Kirsher qlcnic_wq = create_singlethread_workqueue("qlcnic"); 4502aa43c215SJeff Kirsher if (qlcnic_wq == NULL) { 4503aa43c215SJeff Kirsher printk(KERN_ERR "qlcnic: cannot create workqueue\n"); 4504aa43c215SJeff Kirsher return -ENOMEM; 4505aa43c215SJeff Kirsher } 4506aa43c215SJeff Kirsher 4507aa43c215SJeff Kirsher #ifdef CONFIG_INET 4508aa43c215SJeff Kirsher register_netdevice_notifier(&qlcnic_netdev_cb); 4509aa43c215SJeff Kirsher register_inetaddr_notifier(&qlcnic_inetaddr_cb); 4510aa43c215SJeff Kirsher #endif 4511aa43c215SJeff Kirsher 4512aa43c215SJeff Kirsher ret = pci_register_driver(&qlcnic_driver); 4513aa43c215SJeff Kirsher if (ret) { 4514aa43c215SJeff Kirsher #ifdef CONFIG_INET 4515aa43c215SJeff Kirsher unregister_inetaddr_notifier(&qlcnic_inetaddr_cb); 4516aa43c215SJeff Kirsher unregister_netdevice_notifier(&qlcnic_netdev_cb); 4517aa43c215SJeff Kirsher #endif 4518aa43c215SJeff Kirsher destroy_workqueue(qlcnic_wq); 4519aa43c215SJeff Kirsher } 4520aa43c215SJeff Kirsher 4521aa43c215SJeff Kirsher return ret; 4522aa43c215SJeff Kirsher } 4523aa43c215SJeff Kirsher 4524aa43c215SJeff Kirsher module_init(qlcnic_init_module); 4525aa43c215SJeff Kirsher 4526aa43c215SJeff Kirsher static void __exit qlcnic_exit_module(void) 4527aa43c215SJeff Kirsher { 4528aa43c215SJeff Kirsher 4529aa43c215SJeff Kirsher pci_unregister_driver(&qlcnic_driver); 4530aa43c215SJeff Kirsher 4531aa43c215SJeff Kirsher #ifdef CONFIG_INET 4532aa43c215SJeff Kirsher unregister_inetaddr_notifier(&qlcnic_inetaddr_cb); 4533aa43c215SJeff Kirsher unregister_netdevice_notifier(&qlcnic_netdev_cb); 4534aa43c215SJeff Kirsher #endif 4535aa43c215SJeff Kirsher destroy_workqueue(qlcnic_wq); 4536aa43c215SJeff Kirsher } 4537aa43c215SJeff Kirsher 4538aa43c215SJeff Kirsher module_exit(qlcnic_exit_module); 4539