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