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