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