Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2003 - 2006 NetXen, Inc. |
| 3 | * All rights reserved. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 4 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 9 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 10 | * This program is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 14 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| 18 | * MA 02111-1307, USA. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 19 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 20 | * The full GNU General Public License is included in this distribution |
| 21 | * in the file called LICENSE. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 22 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 23 | * Contact Information: |
| 24 | * info@netxen.com |
| 25 | * NetXen, |
| 26 | * 3965 Freedom Circle, Fourth floor, |
| 27 | * Santa Clara, CA 95054 |
| 28 | * |
| 29 | * |
| 30 | * Main source file for NetXen NIC Driver on Linux |
| 31 | * |
| 32 | */ |
| 33 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 34 | #include <linux/vmalloc.h> |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 35 | #include <linux/highmem.h> |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 36 | #include "netxen_nic_hw.h" |
| 37 | |
| 38 | #include "netxen_nic.h" |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 39 | #include "netxen_nic_phan_reg.h" |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 40 | |
Jeff Garzik | 1494a81 | 2006-11-07 05:12:16 -0500 | [diff] [blame] | 41 | #include <linux/dma-mapping.h> |
Arnaldo Carvalho de Melo | c9bdd4b | 2007-03-12 20:09:15 -0300 | [diff] [blame] | 42 | #include <net/ip.h> |
Jeff Garzik | 1494a81 | 2006-11-07 05:12:16 -0500 | [diff] [blame] | 43 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 44 | MODULE_DESCRIPTION("NetXen Multi port (1/10) Gigabit Network Driver"); |
| 45 | MODULE_LICENSE("GPL"); |
| 46 | MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID); |
| 47 | |
dhananjay@netxen.com | ceded32 | 2007-07-19 14:41:09 +0530 | [diff] [blame] | 48 | char netxen_nic_driver_name[] = "netxen_nic"; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 49 | static char netxen_nic_driver_string[] = "NetXen Network Driver version " |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 50 | NETXEN_NIC_LINUX_VERSIONID; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 51 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 52 | static int port_mode = NETXEN_PORT_MODE_AUTO_NEG; |
| 53 | |
| 54 | /* Default to restricted 1G auto-neg mode */ |
| 55 | static int wol_port_mode = 5; |
| 56 | |
| 57 | static int use_msi = 1; |
| 58 | |
| 59 | static int use_msi_x = 1; |
| 60 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 61 | #define NETXEN_NETDEV_WEIGHT 120 |
| 62 | #define NETXEN_ADAPTER_UP_MAGIC 777 |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 63 | #define NETXEN_NIC_PEG_TUNE 0 |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 64 | |
| 65 | /* Local functions to NetXen NIC driver */ |
| 66 | static int __devinit netxen_nic_probe(struct pci_dev *pdev, |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 67 | const struct pci_device_id *ent); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 68 | static void __devexit netxen_nic_remove(struct pci_dev *pdev); |
| 69 | static int netxen_nic_open(struct net_device *netdev); |
| 70 | static int netxen_nic_close(struct net_device *netdev); |
| 71 | static int netxen_nic_xmit_frame(struct sk_buff *, struct net_device *); |
| 72 | static void netxen_tx_timeout(struct net_device *netdev); |
David Howells | 6d5aefb | 2006-12-05 19:36:26 +0000 | [diff] [blame] | 73 | static void netxen_tx_timeout_task(struct work_struct *work); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 74 | static void netxen_watchdog(unsigned long); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 75 | static int netxen_nic_poll(struct napi_struct *napi, int budget); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 76 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 77 | static void netxen_nic_poll_controller(struct net_device *netdev); |
| 78 | #endif |
Jeff Garzik | 1494a81 | 2006-11-07 05:12:16 -0500 | [diff] [blame] | 79 | static irqreturn_t netxen_intr(int irq, void *data); |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 80 | static irqreturn_t netxen_msi_intr(int irq, void *data); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 81 | |
| 82 | /* PCI Device ID Table */ |
Al Viro | 70081ac | 2008-06-23 02:04:50 +0100 | [diff] [blame] | 83 | #define ENTRY(device) \ |
| 84 | {PCI_DEVICE(0x4040, (device)), \ |
| 85 | .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0} |
| 86 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 87 | static struct pci_device_id netxen_pci_tbl[] __devinitdata = { |
Al Viro | 70081ac | 2008-06-23 02:04:50 +0100 | [diff] [blame] | 88 | ENTRY(0x0001), |
| 89 | ENTRY(0x0002), |
| 90 | ENTRY(0x0003), |
| 91 | ENTRY(0x0004), |
| 92 | ENTRY(0x0005), |
| 93 | ENTRY(0x0024), |
| 94 | ENTRY(0x0025), |
Dhananjay Phadke | e4c93c8 | 2008-07-21 19:44:02 -0700 | [diff] [blame] | 95 | ENTRY(0x0100), |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 96 | {0,} |
| 97 | }; |
| 98 | |
| 99 | MODULE_DEVICE_TABLE(pci, netxen_pci_tbl); |
| 100 | |
Adrian Bunk | b1555130 | 2008-03-31 02:22:18 +0300 | [diff] [blame] | 101 | /* |
| 102 | * In netxen_nic_down(), we must wait for any pending callback requests into |
| 103 | * netxen_watchdog_task() to complete; eg otherwise the watchdog_timer could be |
| 104 | * reenabled right after it is deleted in netxen_nic_down(). |
| 105 | * FLUSH_SCHEDULED_WORK() does this synchronization. |
| 106 | * |
| 107 | * Normally, schedule_work()/flush_scheduled_work() could have worked, but |
| 108 | * netxen_nic_close() is invoked with kernel rtnl lock held. netif_carrier_off() |
| 109 | * call in netxen_nic_close() triggers a schedule_work(&linkwatch_work), and a |
| 110 | * subsequent call to flush_scheduled_work() in netxen_nic_down() would cause |
| 111 | * linkwatch_event() to be executed which also attempts to acquire the rtnl |
| 112 | * lock thus causing a deadlock. |
| 113 | */ |
| 114 | |
| 115 | static struct workqueue_struct *netxen_workq; |
| 116 | #define SCHEDULE_WORK(tp) queue_work(netxen_workq, tp) |
| 117 | #define FLUSH_SCHEDULED_WORK() flush_workqueue(netxen_workq) |
| 118 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 119 | static void netxen_watchdog(unsigned long); |
| 120 | |
Dhananjay Phadke | 7830b22 | 2008-07-21 19:44:00 -0700 | [diff] [blame] | 121 | static uint32_t crb_cmd_producer[4] = { |
| 122 | CRB_CMD_PRODUCER_OFFSET, CRB_CMD_PRODUCER_OFFSET_1, |
| 123 | CRB_CMD_PRODUCER_OFFSET_2, CRB_CMD_PRODUCER_OFFSET_3 |
| 124 | }; |
| 125 | |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 126 | static inline void |
| 127 | netxen_nic_update_cmd_producer(struct netxen_adapter *adapter, |
| 128 | uint32_t crb_producer) |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 129 | { |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 130 | adapter->pci_write_normalize(adapter, |
| 131 | adapter->crb_addr_cmd_producer, crb_producer); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Dhananjay Phadke | 7830b22 | 2008-07-21 19:44:00 -0700 | [diff] [blame] | 134 | static uint32_t crb_cmd_consumer[4] = { |
| 135 | CRB_CMD_CONSUMER_OFFSET, CRB_CMD_CONSUMER_OFFSET_1, |
| 136 | CRB_CMD_CONSUMER_OFFSET_2, CRB_CMD_CONSUMER_OFFSET_3 |
| 137 | }; |
| 138 | |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 139 | static inline void |
| 140 | netxen_nic_update_cmd_consumer(struct netxen_adapter *adapter, |
| 141 | u32 crb_consumer) |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 142 | { |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 143 | adapter->pci_write_normalize(adapter, |
| 144 | adapter->crb_addr_cmd_consumer, crb_consumer); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 147 | static uint32_t msi_tgt_status[8] = { |
Dhananjay Phadke | 443be79 | 2008-03-17 19:59:48 -0700 | [diff] [blame] | 148 | ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1, |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 149 | ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3, |
| 150 | ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5, |
| 151 | ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7 |
Dhananjay Phadke | 443be79 | 2008-03-17 19:59:48 -0700 | [diff] [blame] | 152 | }; |
| 153 | |
| 154 | static uint32_t sw_int_mask[4] = { |
| 155 | CRB_SW_INT_MASK_0, CRB_SW_INT_MASK_1, |
| 156 | CRB_SW_INT_MASK_2, CRB_SW_INT_MASK_3 |
| 157 | }; |
| 158 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 159 | static struct netxen_legacy_intr_set legacy_intr[] = NX_LEGACY_INTR_CONFIG; |
| 160 | |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 161 | static void netxen_nic_disable_int(struct netxen_adapter *adapter) |
| 162 | { |
Dhananjay Phadke | 443be79 | 2008-03-17 19:59:48 -0700 | [diff] [blame] | 163 | u32 mask = 0x7ff; |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 164 | int retries = 32; |
Dhananjay Phadke | 443be79 | 2008-03-17 19:59:48 -0700 | [diff] [blame] | 165 | int port = adapter->portnum; |
| 166 | int pci_fn = adapter->ahw.pci_func; |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 167 | |
Jeff Garzik | f0c88f9 | 2008-03-25 23:53:24 -0400 | [diff] [blame] | 168 | if (adapter->msi_mode != MSI_MODE_MULTIFUNC) |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 169 | adapter->pci_write_normalize(adapter, sw_int_mask[port], 0); |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 170 | |
| 171 | if (adapter->intr_scheme != -1 && |
| 172 | adapter->intr_scheme != INTR_SCHEME_PERPORT) |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 173 | adapter->pci_write_immediate(adapter, ISR_INT_MASK, mask); |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 174 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 175 | if (!NETXEN_IS_MSI_FAMILY(adapter)) { |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 176 | do { |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 177 | adapter->pci_write_immediate(adapter, |
| 178 | ISR_INT_TARGET_STATUS, 0xffffffff); |
| 179 | mask = adapter->pci_read_immediate(adapter, |
| 180 | ISR_INT_VECTOR); |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 181 | if (!(mask & 0x80)) |
| 182 | break; |
| 183 | udelay(10); |
| 184 | } while (--retries); |
| 185 | |
| 186 | if (!retries) { |
| 187 | printk(KERN_NOTICE "%s: Failed to disable interrupt completely\n", |
| 188 | netxen_nic_driver_name); |
| 189 | } |
Dhananjay Phadke | 443be79 | 2008-03-17 19:59:48 -0700 | [diff] [blame] | 190 | } else { |
| 191 | if (adapter->msi_mode == MSI_MODE_MULTIFUNC) { |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 192 | adapter->pci_write_immediate(adapter, |
| 193 | msi_tgt_status[pci_fn], 0xffffffff); |
Dhananjay Phadke | 443be79 | 2008-03-17 19:59:48 -0700 | [diff] [blame] | 194 | } |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 195 | } |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | static void netxen_nic_enable_int(struct netxen_adapter *adapter) |
| 199 | { |
| 200 | u32 mask; |
Dhananjay Phadke | 443be79 | 2008-03-17 19:59:48 -0700 | [diff] [blame] | 201 | int port = adapter->portnum; |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 202 | |
| 203 | DPRINTK(1, INFO, "Entered ISR Enable \n"); |
| 204 | |
| 205 | if (adapter->intr_scheme != -1 && |
| 206 | adapter->intr_scheme != INTR_SCHEME_PERPORT) { |
| 207 | switch (adapter->ahw.board_type) { |
| 208 | case NETXEN_NIC_GBE: |
| 209 | mask = 0x77b; |
| 210 | break; |
| 211 | case NETXEN_NIC_XGBE: |
| 212 | mask = 0x77f; |
| 213 | break; |
| 214 | default: |
| 215 | mask = 0x7ff; |
| 216 | break; |
| 217 | } |
| 218 | |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 219 | adapter->pci_write_immediate(adapter, ISR_INT_MASK, mask); |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 222 | adapter->pci_write_normalize(adapter, sw_int_mask[port], 0x1); |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 223 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 224 | if (!NETXEN_IS_MSI_FAMILY(adapter)) { |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 225 | mask = 0xbff; |
| 226 | if (adapter->intr_scheme != -1 && |
| 227 | adapter->intr_scheme != INTR_SCHEME_PERPORT) { |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 228 | adapter->pci_write_normalize(adapter, |
| 229 | CRB_INT_VECTOR, 0); |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 230 | } |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 231 | adapter->pci_write_immediate(adapter, |
| 232 | ISR_INT_TARGET_MASK, mask); |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | DPRINTK(1, INFO, "Done with enable Int\n"); |
| 236 | } |
| 237 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 238 | static int nx_set_dma_mask(struct netxen_adapter *adapter, uint8_t revision_id) |
| 239 | { |
| 240 | struct pci_dev *pdev = adapter->pdev; |
| 241 | int err; |
| 242 | uint64_t mask; |
| 243 | |
| 244 | #ifdef CONFIG_IA64 |
| 245 | adapter->dma_mask = DMA_32BIT_MASK; |
| 246 | #else |
| 247 | if (revision_id >= NX_P3_B0) { |
| 248 | /* should go to DMA_64BIT_MASK */ |
| 249 | adapter->dma_mask = DMA_39BIT_MASK; |
| 250 | mask = DMA_39BIT_MASK; |
| 251 | } else if (revision_id == NX_P3_A2) { |
| 252 | adapter->dma_mask = DMA_39BIT_MASK; |
| 253 | mask = DMA_39BIT_MASK; |
| 254 | } else if (revision_id == NX_P2_C1) { |
| 255 | adapter->dma_mask = DMA_35BIT_MASK; |
| 256 | mask = DMA_35BIT_MASK; |
| 257 | } else { |
| 258 | adapter->dma_mask = DMA_32BIT_MASK; |
| 259 | mask = DMA_32BIT_MASK; |
| 260 | goto set_32_bit_mask; |
| 261 | } |
| 262 | |
| 263 | /* |
| 264 | * Consistent DMA mask is set to 32 bit because it cannot be set to |
| 265 | * 35 bits. For P3 also leave it at 32 bits for now. Only the rings |
| 266 | * come off this pool. |
| 267 | */ |
| 268 | if (pci_set_dma_mask(pdev, mask) == 0 && |
| 269 | pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK) == 0) { |
| 270 | adapter->pci_using_dac = 1; |
| 271 | return 0; |
| 272 | } |
| 273 | #endif /* CONFIG_IA64 */ |
| 274 | |
| 275 | set_32_bit_mask: |
| 276 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
| 277 | if (!err) |
| 278 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
| 279 | if (err) { |
| 280 | DPRINTK(ERR, "No usable DMA configuration, aborting:%d\n", err); |
| 281 | return err; |
| 282 | } |
| 283 | |
| 284 | adapter->pci_using_dac = 0; |
| 285 | return 0; |
| 286 | } |
| 287 | |
| 288 | static void netxen_check_options(struct netxen_adapter *adapter) |
| 289 | { |
| 290 | switch (adapter->ahw.boardcfg.board_type) { |
| 291 | case NETXEN_BRDTYPE_P3_HMEZ: |
| 292 | case NETXEN_BRDTYPE_P3_XG_LOM: |
| 293 | case NETXEN_BRDTYPE_P3_10G_CX4: |
| 294 | case NETXEN_BRDTYPE_P3_10G_CX4_LP: |
| 295 | case NETXEN_BRDTYPE_P3_IMEZ: |
| 296 | case NETXEN_BRDTYPE_P3_10G_SFP_PLUS: |
| 297 | case NETXEN_BRDTYPE_P3_10G_XFP: |
| 298 | case NETXEN_BRDTYPE_P3_10000_BASE_T: |
| 299 | adapter->msix_supported = !!use_msi_x; |
| 300 | adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_10G; |
| 301 | break; |
| 302 | |
| 303 | case NETXEN_BRDTYPE_P2_SB31_10G: |
| 304 | case NETXEN_BRDTYPE_P2_SB31_10G_CX4: |
| 305 | case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ: |
| 306 | case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ: |
| 307 | adapter->msix_supported = 0; |
| 308 | adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_10G; |
| 309 | break; |
| 310 | |
| 311 | case NETXEN_BRDTYPE_P3_REF_QG: |
| 312 | case NETXEN_BRDTYPE_P3_4_GB: |
| 313 | case NETXEN_BRDTYPE_P3_4_GB_MM: |
| 314 | case NETXEN_BRDTYPE_P2_SB35_4G: |
| 315 | case NETXEN_BRDTYPE_P2_SB31_2G: |
| 316 | adapter->msix_supported = 0; |
| 317 | adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_1G; |
| 318 | break; |
| 319 | |
| 320 | default: |
| 321 | adapter->msix_supported = 0; |
| 322 | adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_1G; |
| 323 | |
| 324 | printk(KERN_WARNING "Unknown board type(0x%x)\n", |
| 325 | adapter->ahw.boardcfg.board_type); |
| 326 | break; |
| 327 | } |
| 328 | |
| 329 | adapter->max_tx_desc_count = MAX_CMD_DESCRIPTORS_HOST; |
| 330 | adapter->max_jumbo_rx_desc_count = MAX_JUMBO_RCV_DESCRIPTORS; |
| 331 | adapter->max_lro_rx_desc_count = MAX_LRO_RCV_DESCRIPTORS; |
| 332 | |
| 333 | adapter->max_possible_rss_rings = 1; |
| 334 | return; |
| 335 | } |
| 336 | |
| 337 | static int |
| 338 | netxen_check_hw_init(struct netxen_adapter *adapter, int first_boot) |
| 339 | { |
| 340 | int ret = 0; |
| 341 | |
| 342 | if (first_boot == 0x55555555) { |
| 343 | /* This is the first boot after power up */ |
| 344 | |
| 345 | /* PCI bus master workaround */ |
| 346 | adapter->hw_read_wx(adapter, |
| 347 | NETXEN_PCIE_REG(0x4), &first_boot, 4); |
| 348 | if (!(first_boot & 0x4)) { |
| 349 | first_boot |= 0x4; |
| 350 | adapter->hw_write_wx(adapter, |
| 351 | NETXEN_PCIE_REG(0x4), &first_boot, 4); |
| 352 | adapter->hw_read_wx(adapter, |
| 353 | NETXEN_PCIE_REG(0x4), &first_boot, 4); |
| 354 | } |
| 355 | |
| 356 | /* This is the first boot after power up */ |
| 357 | adapter->hw_read_wx(adapter, |
| 358 | NETXEN_ROMUSB_GLB_SW_RESET, &first_boot, 4); |
| 359 | if (first_boot != 0x80000f) { |
| 360 | /* clear the register for future unloads/loads */ |
| 361 | adapter->pci_write_normalize(adapter, |
| 362 | NETXEN_CAM_RAM(0x1fc), 0); |
| 363 | ret = -1; |
| 364 | } |
| 365 | |
| 366 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { |
| 367 | /* Start P2 boot loader */ |
| 368 | adapter->pci_write_normalize(adapter, |
| 369 | NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC); |
| 370 | adapter->pci_write_normalize(adapter, |
| 371 | NETXEN_ROMUSB_GLB_PEGTUNE_DONE, 1); |
| 372 | } |
| 373 | } |
| 374 | return ret; |
| 375 | } |
| 376 | |
| 377 | static void netxen_set_port_mode(struct netxen_adapter *adapter) |
| 378 | { |
| 379 | u32 val, data; |
| 380 | |
| 381 | val = adapter->ahw.boardcfg.board_type; |
| 382 | if ((val == NETXEN_BRDTYPE_P3_HMEZ) || |
| 383 | (val == NETXEN_BRDTYPE_P3_XG_LOM)) { |
| 384 | if (port_mode == NETXEN_PORT_MODE_802_3_AP) { |
| 385 | data = NETXEN_PORT_MODE_802_3_AP; |
| 386 | adapter->hw_write_wx(adapter, |
| 387 | NETXEN_PORT_MODE_ADDR, &data, 4); |
| 388 | } else if (port_mode == NETXEN_PORT_MODE_XG) { |
| 389 | data = NETXEN_PORT_MODE_XG; |
| 390 | adapter->hw_write_wx(adapter, |
| 391 | NETXEN_PORT_MODE_ADDR, &data, 4); |
| 392 | } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_1G) { |
| 393 | data = NETXEN_PORT_MODE_AUTO_NEG_1G; |
| 394 | adapter->hw_write_wx(adapter, |
| 395 | NETXEN_PORT_MODE_ADDR, &data, 4); |
| 396 | } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_XG) { |
| 397 | data = NETXEN_PORT_MODE_AUTO_NEG_XG; |
| 398 | adapter->hw_write_wx(adapter, |
| 399 | NETXEN_PORT_MODE_ADDR, &data, 4); |
| 400 | } else { |
| 401 | data = NETXEN_PORT_MODE_AUTO_NEG; |
| 402 | adapter->hw_write_wx(adapter, |
| 403 | NETXEN_PORT_MODE_ADDR, &data, 4); |
| 404 | } |
| 405 | |
| 406 | if ((wol_port_mode != NETXEN_PORT_MODE_802_3_AP) && |
| 407 | (wol_port_mode != NETXEN_PORT_MODE_XG) && |
| 408 | (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_1G) && |
| 409 | (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_XG)) { |
| 410 | wol_port_mode = NETXEN_PORT_MODE_AUTO_NEG; |
| 411 | } |
| 412 | adapter->hw_write_wx(adapter, NETXEN_WOL_PORT_MODE, |
| 413 | &wol_port_mode, 4); |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | #define PCI_CAP_ID_GEN 0x10 |
| 418 | |
| 419 | static void netxen_pcie_strap_init(struct netxen_adapter *adapter) |
| 420 | { |
| 421 | u32 pdevfuncsave; |
| 422 | u32 c8c9value = 0; |
| 423 | u32 chicken = 0; |
| 424 | u32 control = 0; |
| 425 | int i, pos; |
| 426 | struct pci_dev *pdev; |
| 427 | |
| 428 | pdev = pci_get_device(0x1166, 0x0140, NULL); |
| 429 | if (pdev) { |
| 430 | pci_dev_put(pdev); |
| 431 | adapter->hw_read_wx(adapter, |
| 432 | NETXEN_PCIE_REG(PCIE_TGT_SPLIT_CHICKEN), &chicken, 4); |
| 433 | chicken |= 0x4000; |
| 434 | adapter->hw_write_wx(adapter, |
| 435 | NETXEN_PCIE_REG(PCIE_TGT_SPLIT_CHICKEN), &chicken, 4); |
| 436 | } |
| 437 | |
| 438 | pdev = adapter->pdev; |
| 439 | |
| 440 | adapter->hw_read_wx(adapter, |
| 441 | NETXEN_PCIE_REG(PCIE_CHICKEN3), &chicken, 4); |
| 442 | /* clear chicken3.25:24 */ |
| 443 | chicken &= 0xFCFFFFFF; |
| 444 | /* |
| 445 | * if gen1 and B0, set F1020 - if gen 2, do nothing |
| 446 | * if gen2 set to F1000 |
| 447 | */ |
| 448 | pos = pci_find_capability(pdev, PCI_CAP_ID_GEN); |
| 449 | if (pos == 0xC0) { |
| 450 | pci_read_config_dword(pdev, pos + 0x10, &control); |
| 451 | if ((control & 0x000F0000) != 0x00020000) { |
| 452 | /* set chicken3.24 if gen1 */ |
| 453 | chicken |= 0x01000000; |
| 454 | } |
| 455 | printk(KERN_INFO "%s Gen2 strapping detected\n", |
| 456 | netxen_nic_driver_name); |
| 457 | c8c9value = 0xF1000; |
| 458 | } else { |
| 459 | /* set chicken3.24 if gen1 */ |
| 460 | chicken |= 0x01000000; |
| 461 | printk(KERN_INFO "%s Gen1 strapping detected\n", |
| 462 | netxen_nic_driver_name); |
| 463 | if (adapter->ahw.revision_id == NX_P3_B0) |
| 464 | c8c9value = 0xF1020; |
| 465 | else |
| 466 | c8c9value = 0; |
| 467 | |
| 468 | } |
| 469 | adapter->hw_write_wx(adapter, |
| 470 | NETXEN_PCIE_REG(PCIE_CHICKEN3), &chicken, 4); |
| 471 | |
| 472 | if (!c8c9value) |
| 473 | return; |
| 474 | |
| 475 | pdevfuncsave = pdev->devfn; |
| 476 | if (pdevfuncsave & 0x07) |
| 477 | return; |
| 478 | |
| 479 | for (i = 0; i < 8; i++) { |
| 480 | pci_read_config_dword(pdev, pos + 8, &control); |
| 481 | pci_read_config_dword(pdev, pos + 8, &control); |
| 482 | pci_write_config_dword(pdev, pos + 8, c8c9value); |
| 483 | pdev->devfn++; |
| 484 | } |
| 485 | pdev->devfn = pdevfuncsave; |
| 486 | } |
| 487 | |
| 488 | static void netxen_set_msix_bit(struct pci_dev *pdev, int enable) |
| 489 | { |
| 490 | u32 control; |
| 491 | int pos; |
| 492 | |
| 493 | pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX); |
| 494 | if (pos) { |
| 495 | pci_read_config_dword(pdev, pos, &control); |
| 496 | if (enable) |
| 497 | control |= PCI_MSIX_FLAGS_ENABLE; |
| 498 | else |
| 499 | control = 0; |
| 500 | pci_write_config_dword(pdev, pos, control); |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | static void netxen_init_msix_entries(struct netxen_adapter *adapter) |
| 505 | { |
| 506 | int i; |
| 507 | |
| 508 | for (i = 0; i < MSIX_ENTRIES_PER_ADAPTER; i++) |
| 509 | adapter->msix_entries[i].entry = i; |
| 510 | } |
| 511 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 512 | /* |
| 513 | * netxen_nic_probe() |
| 514 | * |
| 515 | * The Linux system will invoke this after identifying the vendor ID and |
| 516 | * device Id in the pci_tbl supported by this module. |
| 517 | * |
| 518 | * A quad port card has one operational PCI config space, (function 0), |
| 519 | * which is used to access all four ports. |
| 520 | * |
| 521 | * This routine will initialize the adapter, and setup the global parameters |
| 522 | * along with the port's specific structure. |
| 523 | */ |
| 524 | static int __devinit |
| 525 | netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 526 | { |
| 527 | struct net_device *netdev = NULL; |
| 528 | struct netxen_adapter *adapter = NULL; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 529 | void __iomem *mem_ptr0 = NULL; |
| 530 | void __iomem *mem_ptr1 = NULL; |
| 531 | void __iomem *mem_ptr2 = NULL; |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 532 | unsigned long first_page_group_end; |
| 533 | unsigned long first_page_group_start; |
| 534 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 535 | |
Al Viro | a608ab9c | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 536 | u8 __iomem *db_ptr = NULL; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 537 | unsigned long mem_base, mem_len, db_base, db_len, pci_len0 = 0; |
| 538 | int i = 0, err; |
| 539 | int first_driver, first_boot; |
Al Viro | f305f78 | 2007-12-22 19:44:00 +0000 | [diff] [blame] | 540 | __le64 mac_addr[FLASH_NUM_PORTS + 1]; |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 541 | u32 val; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 542 | int pci_func_id = PCI_FUNC(pdev->devfn); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 543 | DECLARE_MAC_BUF(mac); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 544 | struct netxen_legacy_intr_set *legacy_intrp; |
| 545 | uint8_t revision_id; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 546 | |
Dhananjay Phadke | dcd56fd | 2008-06-15 22:59:45 -0700 | [diff] [blame] | 547 | if (pci_func_id == 0) |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 548 | printk(KERN_INFO "%s\n", netxen_nic_driver_string); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 549 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 550 | if (pdev->class != 0x020000) { |
Dhananjay Phadke | dcd56fd | 2008-06-15 22:59:45 -0700 | [diff] [blame] | 551 | printk(KERN_DEBUG "NetXen function %d, class %x will not " |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 552 | "be enabled.\n",pci_func_id, pdev->class); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 553 | return -ENODEV; |
| 554 | } |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 555 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 556 | if ((err = pci_enable_device(pdev))) |
| 557 | return err; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 558 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 559 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { |
| 560 | err = -ENODEV; |
| 561 | goto err_out_disable_pdev; |
| 562 | } |
| 563 | |
| 564 | if ((err = pci_request_regions(pdev, netxen_nic_driver_name))) |
| 565 | goto err_out_disable_pdev; |
| 566 | |
| 567 | pci_set_master(pdev); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 568 | |
| 569 | netdev = alloc_etherdev(sizeof(struct netxen_adapter)); |
| 570 | if(!netdev) { |
| 571 | printk(KERN_ERR"%s: Failed to allocate memory for the " |
| 572 | "device block.Check system memory resource" |
| 573 | " usage.\n", netxen_nic_driver_name); |
| 574 | goto err_out_free_res; |
| 575 | } |
| 576 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 577 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 578 | |
| 579 | adapter = netdev->priv; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 580 | adapter->netdev = netdev; |
| 581 | adapter->pdev = pdev; |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 582 | adapter->ahw.pci_func = pci_func_id; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 583 | |
| 584 | revision_id = pdev->revision; |
| 585 | adapter->ahw.revision_id = revision_id; |
| 586 | |
| 587 | err = nx_set_dma_mask(adapter, revision_id); |
| 588 | if (err) |
| 589 | goto err_out_free_netdev; |
| 590 | |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 591 | rwlock_init(&adapter->adapter_lock); |
| 592 | adapter->ahw.qdr_sn_window = -1; |
| 593 | adapter->ahw.ddr_mn_window = -1; |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 594 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 595 | /* remap phys address */ |
| 596 | mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */ |
| 597 | mem_len = pci_resource_len(pdev, 0); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 598 | pci_len0 = 0; |
| 599 | |
| 600 | adapter->hw_write_wx = netxen_nic_hw_write_wx_128M; |
| 601 | adapter->hw_read_wx = netxen_nic_hw_read_wx_128M; |
| 602 | adapter->pci_read_immediate = netxen_nic_pci_read_immediate_128M; |
| 603 | adapter->pci_write_immediate = netxen_nic_pci_write_immediate_128M; |
| 604 | adapter->pci_read_normalize = netxen_nic_pci_read_normalize_128M; |
| 605 | adapter->pci_write_normalize = netxen_nic_pci_write_normalize_128M; |
| 606 | adapter->pci_set_window = netxen_nic_pci_set_window_128M; |
| 607 | adapter->pci_mem_read = netxen_nic_pci_mem_read_128M; |
| 608 | adapter->pci_mem_write = netxen_nic_pci_mem_write_128M; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 609 | |
| 610 | /* 128 Meg of memory */ |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 611 | if (mem_len == NETXEN_PCI_128MB_SIZE) { |
| 612 | mem_ptr0 = ioremap(mem_base, FIRST_PAGE_GROUP_SIZE); |
| 613 | mem_ptr1 = ioremap(mem_base + SECOND_PAGE_GROUP_START, |
| 614 | SECOND_PAGE_GROUP_SIZE); |
| 615 | mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START, |
| 616 | THIRD_PAGE_GROUP_SIZE); |
| 617 | first_page_group_start = FIRST_PAGE_GROUP_START; |
| 618 | first_page_group_end = FIRST_PAGE_GROUP_END; |
| 619 | } else if (mem_len == NETXEN_PCI_32MB_SIZE) { |
| 620 | mem_ptr1 = ioremap(mem_base, SECOND_PAGE_GROUP_SIZE); |
| 621 | mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START - |
| 622 | SECOND_PAGE_GROUP_START, THIRD_PAGE_GROUP_SIZE); |
| 623 | first_page_group_start = 0; |
| 624 | first_page_group_end = 0; |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 625 | } else if (mem_len == NETXEN_PCI_2MB_SIZE) { |
| 626 | adapter->hw_write_wx = netxen_nic_hw_write_wx_2M; |
| 627 | adapter->hw_read_wx = netxen_nic_hw_read_wx_2M; |
| 628 | adapter->pci_read_immediate = netxen_nic_pci_read_immediate_2M; |
| 629 | adapter->pci_write_immediate = |
| 630 | netxen_nic_pci_write_immediate_2M; |
| 631 | adapter->pci_read_normalize = netxen_nic_pci_read_normalize_2M; |
| 632 | adapter->pci_write_normalize = |
| 633 | netxen_nic_pci_write_normalize_2M; |
| 634 | adapter->pci_set_window = netxen_nic_pci_set_window_2M; |
| 635 | adapter->pci_mem_read = netxen_nic_pci_mem_read_2M; |
| 636 | adapter->pci_mem_write = netxen_nic_pci_mem_write_2M; |
| 637 | |
| 638 | mem_ptr0 = ioremap(mem_base, mem_len); |
| 639 | pci_len0 = mem_len; |
| 640 | first_page_group_start = 0; |
| 641 | first_page_group_end = 0; |
| 642 | |
| 643 | adapter->ahw.ddr_mn_window = 0; |
| 644 | adapter->ahw.qdr_sn_window = 0; |
| 645 | |
| 646 | adapter->ahw.mn_win_crb = 0x100000 + PCIX_MN_WINDOW + |
| 647 | (pci_func_id * 0x20); |
| 648 | adapter->ahw.ms_win_crb = 0x100000 + PCIX_SN_WINDOW; |
| 649 | if (pci_func_id < 4) |
| 650 | adapter->ahw.ms_win_crb += (pci_func_id * 0x20); |
| 651 | else |
| 652 | adapter->ahw.ms_win_crb += |
| 653 | 0xA0 + ((pci_func_id - 4) * 0x10); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 654 | } else { |
Jeff Garzik | 4790654 | 2007-11-23 21:23:36 -0500 | [diff] [blame] | 655 | err = -EIO; |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 656 | goto err_out_free_netdev; |
| 657 | } |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 658 | |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 659 | dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20)); |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 660 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 661 | db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */ |
| 662 | db_len = pci_resource_len(pdev, 4); |
| 663 | |
| 664 | if (db_len == 0) { |
| 665 | printk(KERN_ERR "%s: doorbell is disabled\n", |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 666 | netxen_nic_driver_name); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 667 | err = -EIO; |
| 668 | goto err_out_iounmap; |
| 669 | } |
| 670 | DPRINTK(INFO, "doorbell ioremap from %lx a size of %lx\n", db_base, |
| 671 | db_len); |
| 672 | |
| 673 | db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES); |
Al Viro | a608ab9c | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 674 | if (!db_ptr) { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 675 | printk(KERN_ERR "%s: Failed to allocate doorbell map.", |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 676 | netxen_nic_driver_name); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 677 | err = -EIO; |
| 678 | goto err_out_iounmap; |
| 679 | } |
| 680 | DPRINTK(INFO, "doorbell ioremaped at %p\n", db_ptr); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 681 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 682 | adapter->ahw.pci_base0 = mem_ptr0; |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 683 | adapter->ahw.pci_len0 = pci_len0; |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 684 | adapter->ahw.first_page_group_start = first_page_group_start; |
| 685 | adapter->ahw.first_page_group_end = first_page_group_end; |
| 686 | adapter->ahw.pci_base1 = mem_ptr1; |
| 687 | adapter->ahw.pci_base2 = mem_ptr2; |
| 688 | adapter->ahw.db_base = db_ptr; |
| 689 | adapter->ahw.db_len = db_len; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 690 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 691 | netif_napi_add(netdev, &adapter->napi, |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 692 | netxen_nic_poll, NETXEN_NETDEV_WEIGHT); |
| 693 | |
| 694 | if (revision_id >= NX_P3_B0) |
| 695 | legacy_intrp = &legacy_intr[pci_func_id]; |
| 696 | else |
| 697 | legacy_intrp = &legacy_intr[0]; |
| 698 | |
| 699 | adapter->legacy_intr.int_vec_bit = legacy_intrp->int_vec_bit; |
| 700 | adapter->legacy_intr.tgt_status_reg = legacy_intrp->tgt_status_reg; |
| 701 | adapter->legacy_intr.tgt_mask_reg = legacy_intrp->tgt_mask_reg; |
| 702 | adapter->legacy_intr.pci_int_reg = legacy_intrp->pci_int_reg; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 703 | |
dhananjay.phadke@gmail.com | 2d1a3bb | 2007-07-02 00:26:00 +0530 | [diff] [blame] | 704 | /* this will be read from FW later */ |
| 705 | adapter->intr_scheme = -1; |
Dhananjay Phadke | 443be79 | 2008-03-17 19:59:48 -0700 | [diff] [blame] | 706 | adapter->msi_mode = -1; |
dhananjay.phadke@gmail.com | 2d1a3bb | 2007-07-02 00:26:00 +0530 | [diff] [blame] | 707 | |
| 708 | /* This will be reset for mezz cards */ |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 709 | adapter->portnum = pci_func_id; |
dhananjay.phadke@gmail.com | 2d1a3bb | 2007-07-02 00:26:00 +0530 | [diff] [blame] | 710 | adapter->status &= ~NETXEN_NETDEV_STATUS; |
Dhananjay Phadke | 200eef2 | 2007-09-03 10:33:35 +0530 | [diff] [blame] | 711 | adapter->rx_csum = 1; |
Dhananjay Phadke | 623621b | 2008-07-21 19:44:01 -0700 | [diff] [blame] | 712 | adapter->mc_enabled = 0; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 713 | if (NX_IS_REVISION_P3(revision_id)) |
| 714 | adapter->max_mc_count = 38; |
| 715 | else |
| 716 | adapter->max_mc_count = 16; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 717 | |
| 718 | netdev->open = netxen_nic_open; |
| 719 | netdev->stop = netxen_nic_close; |
| 720 | netdev->hard_start_xmit = netxen_nic_xmit_frame; |
Jeff Garzik | 4790654 | 2007-11-23 21:23:36 -0500 | [diff] [blame] | 721 | netdev->get_stats = netxen_nic_get_stats; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 722 | netdev->set_multicast_list = netxen_nic_set_multi; |
| 723 | netdev->set_mac_address = netxen_nic_set_mac; |
| 724 | netdev->change_mtu = netxen_nic_change_mtu; |
| 725 | netdev->tx_timeout = netxen_tx_timeout; |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 726 | netdev->watchdog_timeo = 2*HZ; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 727 | |
| 728 | netxen_nic_change_mtu(netdev, netdev->mtu); |
| 729 | |
| 730 | SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 731 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 732 | netdev->poll_controller = netxen_nic_poll_controller; |
| 733 | #endif |
| 734 | /* ScatterGather support */ |
| 735 | netdev->features = NETIF_F_SG; |
| 736 | netdev->features |= NETIF_F_IP_CSUM; |
| 737 | netdev->features |= NETIF_F_TSO; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 738 | if (NX_IS_REVISION_P3(revision_id)) |
| 739 | netdev->features |= NETIF_F_TSO6; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 740 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 741 | if (adapter->pci_using_dac) |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 742 | netdev->features |= NETIF_F_HIGHDMA; |
| 743 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 744 | /* |
| 745 | * Set the CRB window to invalid. If any register in window 0 is |
| 746 | * accessed it should set the window to 0 and then reset it to 1. |
| 747 | */ |
| 748 | adapter->curr_window = 255; |
| 749 | |
Dhananjay Phadke | dcd56fd | 2008-06-15 22:59:45 -0700 | [diff] [blame] | 750 | if (netxen_nic_get_board_info(adapter) != 0) { |
| 751 | printk("%s: Error getting board config info.\n", |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 752 | netxen_nic_driver_name); |
Dhananjay Phadke | dcd56fd | 2008-06-15 22:59:45 -0700 | [diff] [blame] | 753 | err = -EIO; |
| 754 | goto err_out_iounmap; |
| 755 | } |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 756 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 757 | netxen_initialize_adapter_ops(adapter); |
| 758 | |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 759 | /* Mezz cards have PCI function 0,2,3 enabled */ |
Dhananjay Phadke | dc515f2 | 2008-06-15 22:59:43 -0700 | [diff] [blame] | 760 | switch (adapter->ahw.boardcfg.board_type) { |
| 761 | case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ: |
| 762 | case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ: |
| 763 | if (pci_func_id >= 2) |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 764 | adapter->portnum = pci_func_id - 2; |
Dhananjay Phadke | dc515f2 | 2008-06-15 22:59:43 -0700 | [diff] [blame] | 765 | break; |
| 766 | default: |
| 767 | break; |
| 768 | } |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 769 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 770 | /* |
| 771 | * This call will setup various max rx/tx counts. |
| 772 | * It must be done before any buffer/ring allocations. |
| 773 | */ |
| 774 | netxen_check_options(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 775 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 776 | first_driver = 0; |
| 777 | if (NX_IS_REVISION_P3(revision_id)) { |
| 778 | if (adapter->ahw.pci_func == 0) |
| 779 | first_driver = 1; |
| 780 | } else { |
| 781 | if (adapter->portnum == 0) |
| 782 | first_driver = 1; |
| 783 | } |
Dhananjay Phadke | 7830b22 | 2008-07-21 19:44:00 -0700 | [diff] [blame] | 784 | adapter->crb_addr_cmd_producer = crb_cmd_producer[adapter->portnum]; |
| 785 | adapter->crb_addr_cmd_consumer = crb_cmd_consumer[adapter->portnum]; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 786 | netxen_nic_update_cmd_producer(adapter, 0); |
| 787 | netxen_nic_update_cmd_consumer(adapter, 0); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 788 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 789 | if (first_driver) { |
| 790 | first_boot = adapter->pci_read_normalize(adapter, |
| 791 | NETXEN_CAM_RAM(0x1fc)); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 792 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 793 | err = netxen_check_hw_init(adapter, first_boot); |
| 794 | if (err) { |
| 795 | printk(KERN_ERR "%s: error in init HW init sequence\n", |
| 796 | netxen_nic_driver_name); |
| 797 | goto err_out_iounmap; |
| 798 | } |
| 799 | |
| 800 | if (NX_IS_REVISION_P3(revision_id)) |
| 801 | netxen_set_port_mode(adapter); |
| 802 | |
| 803 | if (first_boot != 0x55555555) { |
| 804 | adapter->pci_write_normalize(adapter, |
| 805 | CRB_CMDPEG_STATE, 0); |
| 806 | netxen_pinit_from_rom(adapter, 0); |
| 807 | msleep(1); |
| 808 | netxen_load_firmware(adapter); |
| 809 | } |
| 810 | |
| 811 | if (NX_IS_REVISION_P3(revision_id)) |
| 812 | netxen_pcie_strap_init(adapter); |
| 813 | |
| 814 | if (NX_IS_REVISION_P2(revision_id)) { |
| 815 | |
| 816 | /* Initialize multicast addr pool owners */ |
| 817 | val = 0x7654; |
| 818 | if (adapter->ahw.board_type == NETXEN_NIC_XGBE) |
| 819 | val |= 0x0f000000; |
| 820 | netxen_crb_writelit_adapter(adapter, |
| 821 | NETXEN_MAC_ADDR_CNTL_REG, val); |
| 822 | |
| 823 | } |
| 824 | |
| 825 | if ((first_boot == 0x55555555) && |
| 826 | (NX_IS_REVISION_P2(revision_id))) { |
| 827 | /* Unlock the HW, prompting the boot sequence */ |
| 828 | adapter->pci_write_normalize(adapter, |
| 829 | NETXEN_ROMUSB_GLB_PEGTUNE_DONE, 1); |
| 830 | } |
| 831 | |
| 832 | err = netxen_initialize_adapter_offload(adapter); |
| 833 | if (err) |
| 834 | goto err_out_iounmap; |
| 835 | |
| 836 | /* |
| 837 | * Tell the hardware our version number. |
| 838 | */ |
| 839 | i = (_NETXEN_NIC_LINUX_MAJOR << 16) |
| 840 | | ((_NETXEN_NIC_LINUX_MINOR << 8)) |
| 841 | | (_NETXEN_NIC_LINUX_SUBVERSION); |
| 842 | adapter->pci_write_normalize(adapter, CRB_DRIVER_VERSION, i); |
| 843 | |
| 844 | /* Handshake with the card before we register the devices. */ |
| 845 | netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE); |
| 846 | |
| 847 | if (NX_IS_REVISION_P3(revision_id)) { |
| 848 | adapter->hw_read_wx(adapter, |
| 849 | NETXEN_MIU_MN_CONTROL, &val, 4); |
| 850 | adapter->ahw.cut_through = (val & 0x4) ? 1 : 0; |
| 851 | dev_info(&pdev->dev, "firmware running in %s mode\n", |
| 852 | adapter->ahw.cut_through ? "cut through" : "legacy"); |
| 853 | } |
| 854 | } /* first_driver */ |
| 855 | |
| 856 | netxen_nic_flash_print(adapter); |
| 857 | |
| 858 | /* |
| 859 | * See if the firmware gave us a virtual-physical port mapping. |
| 860 | */ |
| 861 | adapter->physical_port = adapter->portnum; |
| 862 | i = adapter->pci_read_normalize(adapter, CRB_V2P(adapter->portnum)); |
| 863 | if (i != 0x55555555) |
| 864 | adapter->physical_port = i; |
| 865 | |
| 866 | adapter->flags &= ~(NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED); |
| 867 | |
| 868 | netxen_set_msix_bit(pdev, 0); |
| 869 | |
| 870 | if (NX_IS_REVISION_P3(revision_id)) { |
| 871 | if ((mem_len != NETXEN_PCI_128MB_SIZE) && |
| 872 | mem_len != NETXEN_PCI_2MB_SIZE) |
| 873 | adapter->msix_supported = 0; |
| 874 | } |
| 875 | |
| 876 | if (adapter->msix_supported) { |
| 877 | |
| 878 | netxen_init_msix_entries(adapter); |
| 879 | |
| 880 | if (pci_enable_msix(pdev, adapter->msix_entries, |
| 881 | MSIX_ENTRIES_PER_ADAPTER)) |
| 882 | goto request_msi; |
| 883 | |
| 884 | adapter->flags |= NETXEN_NIC_MSIX_ENABLED; |
| 885 | netxen_set_msix_bit(pdev, 1); |
| 886 | dev_info(&pdev->dev, "using msi-x interrupts\n"); |
| 887 | |
| 888 | } else { |
| 889 | request_msi: |
| 890 | if (use_msi && !pci_enable_msi(pdev)) { |
| 891 | adapter->flags |= NETXEN_NIC_MSI_ENABLED; |
| 892 | dev_info(&pdev->dev, "using msi interrupts\n"); |
| 893 | } else |
| 894 | dev_info(&pdev->dev, "using legacy interrupts\n"); |
| 895 | } |
| 896 | |
| 897 | if (adapter->flags & NETXEN_NIC_MSIX_ENABLED) |
| 898 | netdev->irq = adapter->msix_entries[0].vector; |
| 899 | else |
| 900 | netdev->irq = pdev->irq; |
| 901 | |
| 902 | err = netxen_receive_peg_ready(adapter); |
| 903 | if (err) |
| 904 | goto err_out_disable_msi; |
| 905 | |
| 906 | init_timer(&adapter->watchdog_timer); |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame^] | 907 | adapter->ahw.linkup = 0; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 908 | adapter->watchdog_timer.function = &netxen_watchdog; |
| 909 | adapter->watchdog_timer.data = (unsigned long)adapter; |
| 910 | INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task); |
| 911 | INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task); |
| 912 | |
| 913 | if (netxen_is_flash_supported(adapter) == 0 && |
| 914 | netxen_get_flash_mac_addr(adapter, mac_addr) == 0) { |
| 915 | unsigned char *p; |
| 916 | |
| 917 | p = (unsigned char *)&mac_addr[adapter->portnum]; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 918 | netdev->dev_addr[0] = *(p + 5); |
| 919 | netdev->dev_addr[1] = *(p + 4); |
| 920 | netdev->dev_addr[2] = *(p + 3); |
| 921 | netdev->dev_addr[3] = *(p + 2); |
| 922 | netdev->dev_addr[4] = *(p + 1); |
| 923 | netdev->dev_addr[5] = *(p + 0); |
| 924 | |
| 925 | memcpy(netdev->perm_addr, netdev->dev_addr, |
| 926 | netdev->addr_len); |
| 927 | if (!is_valid_ether_addr(netdev->perm_addr)) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 928 | printk(KERN_ERR "%s: Bad MAC address %s.\n", |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 929 | netxen_nic_driver_name, |
| 930 | print_mac(mac, netdev->dev_addr)); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 931 | } else { |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 932 | adapter->macaddr_set(adapter, netdev->dev_addr); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 933 | } |
| 934 | } |
| 935 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 936 | netif_carrier_off(netdev); |
| 937 | netif_stop_queue(netdev); |
| 938 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 939 | if ((err = register_netdev(netdev))) { |
| 940 | printk(KERN_ERR "%s: register_netdev failed port #%d" |
| 941 | " aborting\n", netxen_nic_driver_name, |
| 942 | adapter->portnum); |
| 943 | err = -EIO; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 944 | goto err_out_disable_msi; |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | pci_set_drvdata(pdev, adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 948 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 949 | switch (adapter->ahw.board_type) { |
| 950 | case NETXEN_NIC_GBE: |
| 951 | dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n", |
| 952 | adapter->netdev->name); |
| 953 | break; |
| 954 | case NETXEN_NIC_XGBE: |
| 955 | dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n", |
| 956 | adapter->netdev->name); |
| 957 | break; |
| 958 | } |
| 959 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 960 | return 0; |
| 961 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 962 | err_out_disable_msi: |
| 963 | if (adapter->flags & NETXEN_NIC_MSIX_ENABLED) |
| 964 | pci_disable_msix(pdev); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 965 | if (adapter->flags & NETXEN_NIC_MSI_ENABLED) |
| 966 | pci_disable_msi(pdev); |
| 967 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 968 | if (first_driver) |
| 969 | netxen_free_adapter_offload(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 970 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 971 | err_out_iounmap: |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 972 | if (db_ptr) |
| 973 | iounmap(db_ptr); |
| 974 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 975 | if (mem_ptr0) |
| 976 | iounmap(mem_ptr0); |
| 977 | if (mem_ptr1) |
| 978 | iounmap(mem_ptr1); |
| 979 | if (mem_ptr2) |
| 980 | iounmap(mem_ptr2); |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 981 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 982 | err_out_free_netdev: |
| 983 | free_netdev(netdev); |
| 984 | |
| 985 | err_out_free_res: |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 986 | pci_release_regions(pdev); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 987 | |
| 988 | err_out_disable_pdev: |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 989 | pci_set_drvdata(pdev, NULL); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 990 | pci_disable_device(pdev); |
| 991 | return err; |
| 992 | } |
| 993 | |
| 994 | static void __devexit netxen_nic_remove(struct pci_dev *pdev) |
| 995 | { |
| 996 | struct netxen_adapter *adapter; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 997 | struct net_device *netdev; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 998 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 999 | adapter = pci_get_drvdata(pdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1000 | if (adapter == NULL) |
| 1001 | return; |
| 1002 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1003 | netdev = adapter->netdev; |
| 1004 | |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 1005 | unregister_netdev(netdev); |
| 1006 | |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 1007 | if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1008 | netxen_free_hw_resources(adapter); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1009 | netxen_free_sw_resources(adapter); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 1010 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1011 | |
Dhananjay Phadke | 439b454 | 2008-06-15 22:59:46 -0700 | [diff] [blame] | 1012 | if (adapter->portnum == 0) |
| 1013 | netxen_free_adapter_offload(adapter); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 1014 | |
dhananjay@netxen.com | 3052246 | 2007-08-28 17:23:26 +0530 | [diff] [blame] | 1015 | if (adapter->irq) |
| 1016 | free_irq(adapter->irq, adapter); |
| 1017 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1018 | if (adapter->flags & NETXEN_NIC_MSIX_ENABLED) |
| 1019 | pci_disable_msix(pdev); |
dhananjay@netxen.com | 3052246 | 2007-08-28 17:23:26 +0530 | [diff] [blame] | 1020 | if (adapter->flags & NETXEN_NIC_MSI_ENABLED) |
| 1021 | pci_disable_msi(pdev); |
| 1022 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1023 | iounmap(adapter->ahw.db_base); |
| 1024 | iounmap(adapter->ahw.pci_base0); |
| 1025 | iounmap(adapter->ahw.pci_base1); |
| 1026 | iounmap(adapter->ahw.pci_base2); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 1027 | |
| 1028 | pci_release_regions(pdev); |
dhananjay@netxen.com | 3052246 | 2007-08-28 17:23:26 +0530 | [diff] [blame] | 1029 | pci_disable_device(pdev); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 1030 | pci_set_drvdata(pdev, NULL); |
| 1031 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1032 | free_netdev(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | /* |
| 1036 | * Called when a network interface is made active |
| 1037 | * @returns 0 on success, negative value on failure |
| 1038 | */ |
| 1039 | static int netxen_nic_open(struct net_device *netdev) |
| 1040 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1041 | struct netxen_adapter *adapter = (struct netxen_adapter *)netdev->priv; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1042 | int err = 0; |
| 1043 | int ctx, ring; |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1044 | irq_handler_t handler; |
| 1045 | unsigned long flags = IRQF_SAMPLE_RANDOM; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1046 | |
Dhananjay Phadke | dcd56fd | 2008-06-15 22:59:45 -0700 | [diff] [blame] | 1047 | if (adapter->driver_mismatch) |
| 1048 | return -EIO; |
| 1049 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1050 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) { |
| 1051 | err = netxen_init_firmware(adapter); |
| 1052 | if (err != 0) { |
| 1053 | printk(KERN_ERR "Failed to init firmware\n"); |
| 1054 | return -EIO; |
| 1055 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1056 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1057 | err = netxen_alloc_sw_resources(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1058 | if (err) { |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1059 | printk(KERN_ERR "%s: Error in setting sw resources\n", |
| 1060 | netdev->name); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1061 | return err; |
| 1062 | } |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1063 | |
| 1064 | netxen_nic_clear_stats(adapter); |
| 1065 | |
| 1066 | err = netxen_alloc_hw_resources(adapter); |
| 1067 | if (err) { |
| 1068 | printk(KERN_ERR "%s: Error in setting hw resources\n", |
| 1069 | netdev->name); |
| 1070 | goto err_out_free_sw; |
| 1071 | } |
| 1072 | |
| 1073 | if (adapter->fw_major < 4) { |
| 1074 | adapter->crb_addr_cmd_producer = |
| 1075 | crb_cmd_producer[adapter->portnum]; |
| 1076 | adapter->crb_addr_cmd_consumer = |
| 1077 | crb_cmd_consumer[adapter->portnum]; |
| 1078 | } |
| 1079 | |
| 1080 | netxen_nic_update_cmd_producer(adapter, 0); |
| 1081 | netxen_nic_update_cmd_consumer(adapter, 0); |
| 1082 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1083 | for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) { |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 1084 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1085 | netxen_post_rx_buffers(adapter, ctx, ring); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1086 | } |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1087 | if (NETXEN_IS_MSI_FAMILY(adapter)) |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1088 | handler = netxen_msi_intr; |
| 1089 | else { |
| 1090 | flags |= IRQF_SHARED; |
| 1091 | handler = netxen_intr; |
| 1092 | } |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1093 | adapter->irq = netdev->irq; |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1094 | err = request_irq(adapter->irq, handler, |
| 1095 | flags, netdev->name, adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1096 | if (err) { |
| 1097 | printk(KERN_ERR "request_irq failed with: %d\n", err); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1098 | goto err_out_free_hw; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1099 | } |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1100 | |
| 1101 | adapter->is_up = NETXEN_ADAPTER_UP_MAGIC; |
| 1102 | } |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1103 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1104 | /* Done here again so that even if phantom sw overwrote it, |
| 1105 | * we set it */ |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1106 | err = adapter->init_port(adapter, adapter->portnum); |
| 1107 | if (err) { |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 1108 | printk(KERN_ERR "%s: Failed to initialize port %d\n", |
| 1109 | netxen_nic_driver_name, adapter->portnum); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1110 | goto err_out_free_irq; |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 1111 | } |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1112 | adapter->macaddr_set(adapter, netdev->dev_addr); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 1113 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1114 | netxen_nic_set_link_parameters(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1115 | |
| 1116 | netxen_nic_set_multi(netdev); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1117 | adapter->set_mtu(adapter, netdev->mtu); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1118 | |
Dhananjay Phadke | dcd56fd | 2008-06-15 22:59:45 -0700 | [diff] [blame] | 1119 | mod_timer(&adapter->watchdog_timer, jiffies); |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1120 | |
| 1121 | napi_enable(&adapter->napi); |
| 1122 | netxen_nic_enable_int(adapter); |
| 1123 | |
Dhananjay Phadke | dcd56fd | 2008-06-15 22:59:45 -0700 | [diff] [blame] | 1124 | netif_start_queue(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1125 | |
| 1126 | return 0; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1127 | |
| 1128 | err_out_free_irq: |
| 1129 | free_irq(adapter->irq, adapter); |
| 1130 | err_out_free_hw: |
| 1131 | netxen_free_hw_resources(adapter); |
| 1132 | err_out_free_sw: |
| 1133 | netxen_free_sw_resources(adapter); |
| 1134 | return err; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | /* |
| 1138 | * netxen_nic_close - Disables a network interface entry point |
| 1139 | */ |
| 1140 | static int netxen_nic_close(struct net_device *netdev) |
| 1141 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1142 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1143 | |
| 1144 | netif_carrier_off(netdev); |
| 1145 | netif_stop_queue(netdev); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1146 | napi_disable(&adapter->napi); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1147 | |
dhananjay@netxen.com | 72b0a7a | 2007-12-26 10:23:56 -0800 | [diff] [blame] | 1148 | if (adapter->stop_port) |
| 1149 | adapter->stop_port(adapter); |
| 1150 | |
dhananjay@netxen.com | e01872af | 2007-07-25 20:13:12 +0530 | [diff] [blame] | 1151 | netxen_nic_disable_int(adapter); |
| 1152 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1153 | netxen_release_tx_buffers(adapter); |
| 1154 | |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 1155 | if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) { |
| 1156 | FLUSH_SCHEDULED_WORK(); |
| 1157 | del_timer_sync(&adapter->watchdog_timer); |
| 1158 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1159 | |
| 1160 | return 0; |
| 1161 | } |
| 1162 | |
| 1163 | static int netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
| 1164 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1165 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1166 | struct netxen_hardware_context *hw = &adapter->ahw; |
| 1167 | unsigned int first_seg_len = skb->len - skb->data_len; |
| 1168 | struct netxen_skb_frag *buffrag; |
| 1169 | unsigned int i; |
| 1170 | |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1171 | u32 producer, consumer; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1172 | u32 saved_producer = 0; |
| 1173 | struct cmd_desc_type0 *hwdesc; |
| 1174 | int k; |
| 1175 | struct netxen_cmd_buffer *pbuf = NULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1176 | int frag_count; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1177 | int no_of_desc; |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1178 | u32 num_txd = adapter->max_tx_desc_count; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1179 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1180 | frag_count = skb_shinfo(skb)->nr_frags + 1; |
| 1181 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1182 | /* There 4 fragments per descriptor */ |
| 1183 | no_of_desc = (frag_count + 3) >> 2; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 1184 | if (netdev->features & NETIF_F_TSO) { |
| 1185 | if (skb_shinfo(skb)->gso_size > 0) { |
| 1186 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1187 | no_of_desc++; |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 1188 | if ((ip_hdrlen(skb) + tcp_hdrlen(skb) + |
Arnaldo Carvalho de Melo | c9bdd4b | 2007-03-12 20:09:15 -0300 | [diff] [blame] | 1189 | sizeof(struct ethhdr)) > |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1190 | (sizeof(struct cmd_desc_type0) - 2)) { |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 1191 | no_of_desc++; |
| 1192 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1193 | } |
| 1194 | } |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 1195 | |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1196 | producer = adapter->cmd_producer; |
| 1197 | smp_mb(); |
| 1198 | consumer = adapter->last_cmd_consumer; |
| 1199 | if ((no_of_desc+2) > find_diff_among(producer, consumer, num_txd)) { |
| 1200 | netif_stop_queue(netdev); |
| 1201 | smp_mb(); |
| 1202 | return NETDEV_TX_BUSY; |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 1203 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1204 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1205 | /* Copy the descriptors into the hardware */ |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1206 | saved_producer = producer; |
| 1207 | hwdesc = &hw->cmd_desc_head[producer]; |
| 1208 | memset(hwdesc, 0, sizeof(struct cmd_desc_type0)); |
| 1209 | /* Take skb->data itself */ |
| 1210 | pbuf = &adapter->cmd_buf_arr[producer]; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 1211 | if ((netdev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size > 0) { |
Al Viro | a608ab9c | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 1212 | pbuf->mss = skb_shinfo(skb)->gso_size; |
Amit S. Kale | ed33ebe | 2006-12-18 05:53:59 -0800 | [diff] [blame] | 1213 | hwdesc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1214 | } else { |
| 1215 | pbuf->mss = 0; |
| 1216 | hwdesc->mss = 0; |
| 1217 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1218 | pbuf->total_length = skb->len; |
| 1219 | pbuf->skb = skb; |
| 1220 | pbuf->cmd = TX_ETHER_PKT; |
| 1221 | pbuf->frag_count = frag_count; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1222 | pbuf->port = adapter->portnum; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1223 | buffrag = &pbuf->frag_array[0]; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1224 | buffrag->dma = pci_map_single(adapter->pdev, skb->data, first_seg_len, |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1225 | PCI_DMA_TODEVICE); |
| 1226 | buffrag->length = first_seg_len; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1227 | netxen_set_cmd_desc_totallength(hwdesc, skb->len); |
| 1228 | netxen_set_cmd_desc_num_of_buff(hwdesc, frag_count); |
| 1229 | netxen_set_cmd_desc_opcode(hwdesc, TX_ETHER_PKT); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1230 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1231 | netxen_set_cmd_desc_port(hwdesc, adapter->portnum); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1232 | netxen_set_cmd_desc_ctxid(hwdesc, adapter->portnum); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1233 | hwdesc->buffer1_length = cpu_to_le16(first_seg_len); |
| 1234 | hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma); |
| 1235 | |
| 1236 | for (i = 1, k = 1; i < frag_count; i++, k++) { |
| 1237 | struct skb_frag_struct *frag; |
| 1238 | int len, temp_len; |
| 1239 | unsigned long offset; |
| 1240 | dma_addr_t temp_dma; |
| 1241 | |
| 1242 | /* move to next desc. if there is a need */ |
| 1243 | if ((i & 0x3) == 0) { |
| 1244 | k = 0; |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1245 | producer = get_next_index(producer, num_txd); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1246 | hwdesc = &hw->cmd_desc_head[producer]; |
| 1247 | memset(hwdesc, 0, sizeof(struct cmd_desc_type0)); |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 1248 | pbuf = &adapter->cmd_buf_arr[producer]; |
| 1249 | pbuf->skb = NULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1250 | } |
| 1251 | frag = &skb_shinfo(skb)->frags[i - 1]; |
| 1252 | len = frag->size; |
| 1253 | offset = frag->page_offset; |
| 1254 | |
| 1255 | temp_len = len; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1256 | temp_dma = pci_map_page(adapter->pdev, frag->page, offset, |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1257 | len, PCI_DMA_TODEVICE); |
| 1258 | |
| 1259 | buffrag++; |
| 1260 | buffrag->dma = temp_dma; |
| 1261 | buffrag->length = temp_len; |
| 1262 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1263 | switch (k) { |
| 1264 | case 0: |
| 1265 | hwdesc->buffer1_length = cpu_to_le16(temp_len); |
| 1266 | hwdesc->addr_buffer1 = cpu_to_le64(temp_dma); |
| 1267 | break; |
| 1268 | case 1: |
| 1269 | hwdesc->buffer2_length = cpu_to_le16(temp_len); |
| 1270 | hwdesc->addr_buffer2 = cpu_to_le64(temp_dma); |
| 1271 | break; |
| 1272 | case 2: |
| 1273 | hwdesc->buffer3_length = cpu_to_le16(temp_len); |
| 1274 | hwdesc->addr_buffer3 = cpu_to_le64(temp_dma); |
| 1275 | break; |
| 1276 | case 3: |
Al Viro | a608ab9c | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 1277 | hwdesc->buffer4_length = cpu_to_le16(temp_len); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1278 | hwdesc->addr_buffer4 = cpu_to_le64(temp_dma); |
| 1279 | break; |
| 1280 | } |
| 1281 | frag++; |
| 1282 | } |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1283 | producer = get_next_index(producer, num_txd); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1284 | |
| 1285 | /* might change opcode to TX_TCP_LSO */ |
| 1286 | netxen_tso_check(adapter, &hw->cmd_desc_head[saved_producer], skb); |
| 1287 | |
| 1288 | /* For LSO, we need to copy the MAC/IP/TCP headers into |
| 1289 | * the descriptor ring |
| 1290 | */ |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1291 | if (netxen_get_cmd_desc_opcode(&hw->cmd_desc_head[saved_producer]) |
| 1292 | == TX_TCP_LSO) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1293 | int hdr_len, first_hdr_len, more_hdr; |
| 1294 | hdr_len = hw->cmd_desc_head[saved_producer].total_hdr_length; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1295 | if (hdr_len > (sizeof(struct cmd_desc_type0) - 2)) { |
| 1296 | first_hdr_len = sizeof(struct cmd_desc_type0) - 2; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1297 | more_hdr = 1; |
| 1298 | } else { |
| 1299 | first_hdr_len = hdr_len; |
| 1300 | more_hdr = 0; |
| 1301 | } |
| 1302 | /* copy the MAC/IP/TCP headers to the cmd descriptor list */ |
| 1303 | hwdesc = &hw->cmd_desc_head[producer]; |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 1304 | pbuf = &adapter->cmd_buf_arr[producer]; |
| 1305 | pbuf->skb = NULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1306 | |
| 1307 | /* copy the first 64 bytes */ |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1308 | memcpy(((void *)hwdesc) + 2, |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1309 | (void *)(skb->data), first_hdr_len); |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1310 | producer = get_next_index(producer, num_txd); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1311 | |
| 1312 | if (more_hdr) { |
| 1313 | hwdesc = &hw->cmd_desc_head[producer]; |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 1314 | pbuf = &adapter->cmd_buf_arr[producer]; |
| 1315 | pbuf->skb = NULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1316 | /* copy the next 64 bytes - should be enough except |
| 1317 | * for pathological case |
| 1318 | */ |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 1319 | skb_copy_from_linear_data_offset(skb, first_hdr_len, |
| 1320 | hwdesc, |
| 1321 | (hdr_len - |
| 1322 | first_hdr_len)); |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1323 | producer = get_next_index(producer, num_txd); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1324 | } |
| 1325 | } |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1326 | |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1327 | adapter->cmd_producer = producer; |
Dhananjay Phadke | 5dc1626 | 2007-12-31 10:08:57 -0800 | [diff] [blame] | 1328 | adapter->stats.txbytes += skb->len; |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1329 | |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1330 | netxen_nic_update_cmd_producer(adapter, adapter->cmd_producer); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1331 | |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1332 | adapter->stats.xmitcalled++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1333 | netdev->trans_start = jiffies; |
| 1334 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1335 | return NETDEV_TX_OK; |
| 1336 | } |
| 1337 | |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame^] | 1338 | static int netxen_nic_check_temp(struct netxen_adapter *adapter) |
| 1339 | { |
| 1340 | struct net_device *netdev = adapter->netdev; |
| 1341 | uint32_t temp, temp_state, temp_val; |
| 1342 | int rv = 0; |
| 1343 | |
| 1344 | temp = adapter->pci_read_normalize(adapter, CRB_TEMP_STATE); |
| 1345 | |
| 1346 | temp_state = nx_get_temp_state(temp); |
| 1347 | temp_val = nx_get_temp_val(temp); |
| 1348 | |
| 1349 | if (temp_state == NX_TEMP_PANIC) { |
| 1350 | printk(KERN_ALERT |
| 1351 | "%s: Device temperature %d degrees C exceeds" |
| 1352 | " maximum allowed. Hardware has been shut down.\n", |
| 1353 | netxen_nic_driver_name, temp_val); |
| 1354 | |
| 1355 | netif_carrier_off(netdev); |
| 1356 | netif_stop_queue(netdev); |
| 1357 | rv = 1; |
| 1358 | } else if (temp_state == NX_TEMP_WARN) { |
| 1359 | if (adapter->temp == NX_TEMP_NORMAL) { |
| 1360 | printk(KERN_ALERT |
| 1361 | "%s: Device temperature %d degrees C " |
| 1362 | "exceeds operating range." |
| 1363 | " Immediate action needed.\n", |
| 1364 | netxen_nic_driver_name, temp_val); |
| 1365 | } |
| 1366 | } else { |
| 1367 | if (adapter->temp == NX_TEMP_WARN) { |
| 1368 | printk(KERN_INFO |
| 1369 | "%s: Device temperature is now %d degrees C" |
| 1370 | " in normal range.\n", netxen_nic_driver_name, |
| 1371 | temp_val); |
| 1372 | } |
| 1373 | } |
| 1374 | adapter->temp = temp_state; |
| 1375 | return rv; |
| 1376 | } |
| 1377 | |
| 1378 | static void netxen_nic_handle_phy_intr(struct netxen_adapter *adapter) |
| 1379 | { |
| 1380 | struct net_device *netdev = adapter->netdev; |
| 1381 | u32 val, port, linkup; |
| 1382 | |
| 1383 | port = adapter->physical_port; |
| 1384 | |
| 1385 | val = adapter->pci_read_normalize(adapter, CRB_XG_STATE); |
| 1386 | if (adapter->ahw.board_type == NETXEN_NIC_GBE) |
| 1387 | linkup = (val >> port) & 1; |
| 1388 | else { |
| 1389 | val = (val >> port*8) & 0xff; |
| 1390 | linkup = (val == XG_LINK_UP); |
| 1391 | } |
| 1392 | |
| 1393 | if (adapter->ahw.linkup && !linkup) { |
| 1394 | printk(KERN_INFO "%s: %s NIC Link is down\n", |
| 1395 | netxen_nic_driver_name, netdev->name); |
| 1396 | adapter->ahw.linkup = 0; |
| 1397 | if (netif_running(netdev)) { |
| 1398 | netif_carrier_off(netdev); |
| 1399 | netif_stop_queue(netdev); |
| 1400 | } |
| 1401 | } else if (!adapter->ahw.linkup && linkup) { |
| 1402 | printk(KERN_INFO "%s: %s NIC Link is up\n", |
| 1403 | netxen_nic_driver_name, netdev->name); |
| 1404 | adapter->ahw.linkup = 1; |
| 1405 | if (netif_running(netdev)) { |
| 1406 | netif_carrier_on(netdev); |
| 1407 | netif_wake_queue(netdev); |
| 1408 | } |
| 1409 | } |
| 1410 | } |
| 1411 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1412 | static void netxen_watchdog(unsigned long v) |
| 1413 | { |
| 1414 | struct netxen_adapter *adapter = (struct netxen_adapter *)v; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1415 | |
| 1416 | SCHEDULE_WORK(&adapter->watchdog_task); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1417 | } |
| 1418 | |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame^] | 1419 | void netxen_watchdog_task(struct work_struct *work) |
| 1420 | { |
| 1421 | struct netxen_adapter *adapter = |
| 1422 | container_of(work, struct netxen_adapter, watchdog_task); |
| 1423 | |
| 1424 | if ((adapter->portnum == 0) && netxen_nic_check_temp(adapter)) |
| 1425 | return; |
| 1426 | |
| 1427 | netxen_nic_handle_phy_intr(adapter); |
| 1428 | |
| 1429 | mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ); |
| 1430 | } |
| 1431 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1432 | static void netxen_tx_timeout(struct net_device *netdev) |
| 1433 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1434 | struct netxen_adapter *adapter = (struct netxen_adapter *) |
| 1435 | netdev_priv(netdev); |
| 1436 | SCHEDULE_WORK(&adapter->tx_timeout_task); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1437 | } |
| 1438 | |
David Howells | 6d5aefb | 2006-12-05 19:36:26 +0000 | [diff] [blame] | 1439 | static void netxen_tx_timeout_task(struct work_struct *work) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1440 | { |
Jeff Garzik | 4790654 | 2007-11-23 21:23:36 -0500 | [diff] [blame] | 1441 | struct netxen_adapter *adapter = |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1442 | container_of(work, struct netxen_adapter, tx_timeout_task); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1443 | |
| 1444 | printk(KERN_ERR "%s %s: transmit timeout, resetting.\n", |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1445 | netxen_nic_driver_name, adapter->netdev->name); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1446 | |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1447 | netxen_nic_disable_int(adapter); |
| 1448 | napi_disable(&adapter->napi); |
| 1449 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1450 | adapter->netdev->trans_start = jiffies; |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1451 | |
| 1452 | napi_enable(&adapter->napi); |
| 1453 | netxen_nic_enable_int(adapter); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1454 | netif_wake_queue(adapter->netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1455 | } |
| 1456 | |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame^] | 1457 | /* |
| 1458 | * netxen_nic_get_stats - Get System Network Statistics |
| 1459 | * @netdev: network interface device structure |
| 1460 | */ |
| 1461 | struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev) |
| 1462 | { |
| 1463 | struct netxen_adapter *adapter = netdev_priv(netdev); |
| 1464 | struct net_device_stats *stats = &adapter->net_stats; |
| 1465 | |
| 1466 | memset(stats, 0, sizeof(*stats)); |
| 1467 | |
| 1468 | /* total packets received */ |
| 1469 | stats->rx_packets = adapter->stats.no_rcv; |
| 1470 | /* total packets transmitted */ |
| 1471 | stats->tx_packets = adapter->stats.xmitedframes + |
| 1472 | adapter->stats.xmitfinished; |
| 1473 | /* total bytes received */ |
| 1474 | stats->rx_bytes = adapter->stats.rxbytes; |
| 1475 | /* total bytes transmitted */ |
| 1476 | stats->tx_bytes = adapter->stats.txbytes; |
| 1477 | /* bad packets received */ |
| 1478 | stats->rx_errors = adapter->stats.rcvdbadskb; |
| 1479 | /* packet transmit problems */ |
| 1480 | stats->tx_errors = adapter->stats.nocmddescriptor; |
| 1481 | /* no space in linux buffers */ |
| 1482 | stats->rx_dropped = adapter->stats.rxdropped; |
| 1483 | /* no space available in linux */ |
| 1484 | stats->tx_dropped = adapter->stats.txdropped; |
| 1485 | |
| 1486 | return stats; |
| 1487 | } |
| 1488 | |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1489 | static inline void |
| 1490 | netxen_handle_int(struct netxen_adapter *adapter) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1491 | { |
dhananjay.phadke@gmail.com | 2d1a3bb | 2007-07-02 00:26:00 +0530 | [diff] [blame] | 1492 | netxen_nic_disable_int(adapter); |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1493 | napi_schedule(&adapter->napi); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1494 | } |
| 1495 | |
Dhananjay Phadke | e4c93c8 | 2008-07-21 19:44:02 -0700 | [diff] [blame] | 1496 | static irqreturn_t netxen_intr(int irq, void *data) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1497 | { |
Jeff Garzik | 1daec86 | 2007-10-19 03:14:03 -0400 | [diff] [blame] | 1498 | struct netxen_adapter *adapter = data; |
dhananjay@netxen.com | e01872af | 2007-07-25 20:13:12 +0530 | [diff] [blame] | 1499 | u32 our_int = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1500 | |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1501 | our_int = adapter->pci_read_normalize(adapter, CRB_INT_VECTOR); |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1502 | /* not our interrupt */ |
| 1503 | if ((our_int & (0x80 << adapter->portnum)) == 0) |
| 1504 | return IRQ_NONE; |
dhananjay@netxen.com | e01872af | 2007-07-25 20:13:12 +0530 | [diff] [blame] | 1505 | |
| 1506 | if (adapter->intr_scheme == INTR_SCHEME_PERPORT) { |
| 1507 | /* claim interrupt */ |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1508 | adapter->pci_write_normalize(adapter, CRB_INT_VECTOR, |
| 1509 | our_int & ~((u32)(0x80 << adapter->portnum))); |
dhananjay@netxen.com | e01872af | 2007-07-25 20:13:12 +0530 | [diff] [blame] | 1510 | } |
| 1511 | |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1512 | netxen_handle_int(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1513 | |
| 1514 | return IRQ_HANDLED; |
| 1515 | } |
| 1516 | |
Dhananjay Phadke | e4c93c8 | 2008-07-21 19:44:02 -0700 | [diff] [blame] | 1517 | static irqreturn_t netxen_msi_intr(int irq, void *data) |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1518 | { |
| 1519 | struct netxen_adapter *adapter = data; |
| 1520 | |
| 1521 | netxen_handle_int(adapter); |
| 1522 | return IRQ_HANDLED; |
| 1523 | } |
| 1524 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1525 | static int netxen_nic_poll(struct napi_struct *napi, int budget) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1526 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1527 | struct netxen_adapter *adapter = container_of(napi, struct netxen_adapter, napi); |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1528 | int tx_complete; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1529 | int ctx; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1530 | int work_done; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1531 | |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1532 | tx_complete = netxen_process_cmd_ring(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1533 | |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 1534 | work_done = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1535 | for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) { |
| 1536 | /* |
| 1537 | * Fairness issue. This will give undue weight to the |
| 1538 | * receive context 0. |
| 1539 | */ |
| 1540 | |
| 1541 | /* |
| 1542 | * To avoid starvation, we give each of our receivers, |
| 1543 | * a fraction of the quota. Sometimes, it might happen that we |
| 1544 | * have enough quota to process every packet, but since all the |
| 1545 | * packets are on one context, it gets only half of the quota, |
| 1546 | * and ends up not processing it. |
| 1547 | */ |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1548 | work_done += netxen_process_rcv_ring(adapter, ctx, |
| 1549 | budget / MAX_RCV_CTX); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1550 | } |
| 1551 | |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1552 | if ((work_done < budget) && tx_complete) { |
| 1553 | netif_rx_complete(adapter->netdev, &adapter->napi); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1554 | netxen_nic_enable_int(adapter); |
| 1555 | } |
| 1556 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1557 | return work_done; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1558 | } |
| 1559 | |
| 1560 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1561 | static void netxen_nic_poll_controller(struct net_device *netdev) |
| 1562 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1563 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1564 | disable_irq(adapter->irq); |
Jeff Garzik | 1494a81 | 2006-11-07 05:12:16 -0500 | [diff] [blame] | 1565 | netxen_intr(adapter->irq, adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1566 | enable_irq(adapter->irq); |
| 1567 | } |
| 1568 | #endif |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1569 | |
| 1570 | static struct pci_driver netxen_driver = { |
| 1571 | .name = netxen_nic_driver_name, |
| 1572 | .id_table = netxen_pci_tbl, |
| 1573 | .probe = netxen_nic_probe, |
| 1574 | .remove = __devexit_p(netxen_nic_remove) |
| 1575 | }; |
| 1576 | |
| 1577 | /* Driver Registration on NetXen card */ |
| 1578 | |
| 1579 | static int __init netxen_init_module(void) |
| 1580 | { |
Al Viro | 79ea13c | 2008-01-24 02:06:46 -0800 | [diff] [blame] | 1581 | if ((netxen_workq = create_singlethread_workqueue("netxen")) == NULL) |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1582 | return -ENOMEM; |
| 1583 | |
Amit S. Kale | 184231b | 2007-01-22 06:52:53 -0800 | [diff] [blame] | 1584 | return pci_register_driver(&netxen_driver); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1585 | } |
| 1586 | |
| 1587 | module_init(netxen_init_module); |
| 1588 | |
| 1589 | static void __exit netxen_exit_module(void) |
| 1590 | { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1591 | pci_unregister_driver(&netxen_driver); |
Amit S. Kale | 9de0661 | 2007-02-21 06:37:06 -0800 | [diff] [blame] | 1592 | destroy_workqueue(netxen_workq); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1593 | } |
| 1594 | |
| 1595 | module_exit(netxen_exit_module); |