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 | b155513 | 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 | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 126 | void |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 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 | a608ab9 | 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 | a608ab9 | 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; |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 719 | if (NX_IS_REVISION_P3(revision_id)) |
| 720 | netdev->set_multicast_list = netxen_p3_nic_set_multi; |
| 721 | else |
| 722 | netdev->set_multicast_list = netxen_p2_nic_set_multi; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 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 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 847 | } /* first_driver */ |
| 848 | |
| 849 | netxen_nic_flash_print(adapter); |
| 850 | |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame^] | 851 | if (NX_IS_REVISION_P3(revision_id)) { |
| 852 | adapter->hw_read_wx(adapter, |
| 853 | NETXEN_MIU_MN_CONTROL, &val, 4); |
| 854 | adapter->ahw.cut_through = (val & 0x4) ? 1 : 0; |
| 855 | dev_info(&pdev->dev, "firmware running in %s mode\n", |
| 856 | adapter->ahw.cut_through ? "cut through" : "legacy"); |
| 857 | } |
| 858 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 859 | /* |
| 860 | * See if the firmware gave us a virtual-physical port mapping. |
| 861 | */ |
| 862 | adapter->physical_port = adapter->portnum; |
| 863 | i = adapter->pci_read_normalize(adapter, CRB_V2P(adapter->portnum)); |
| 864 | if (i != 0x55555555) |
| 865 | adapter->physical_port = i; |
| 866 | |
| 867 | adapter->flags &= ~(NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED); |
| 868 | |
| 869 | netxen_set_msix_bit(pdev, 0); |
| 870 | |
| 871 | if (NX_IS_REVISION_P3(revision_id)) { |
| 872 | if ((mem_len != NETXEN_PCI_128MB_SIZE) && |
| 873 | mem_len != NETXEN_PCI_2MB_SIZE) |
| 874 | adapter->msix_supported = 0; |
| 875 | } |
| 876 | |
| 877 | if (adapter->msix_supported) { |
| 878 | |
| 879 | netxen_init_msix_entries(adapter); |
| 880 | |
| 881 | if (pci_enable_msix(pdev, adapter->msix_entries, |
| 882 | MSIX_ENTRIES_PER_ADAPTER)) |
| 883 | goto request_msi; |
| 884 | |
| 885 | adapter->flags |= NETXEN_NIC_MSIX_ENABLED; |
| 886 | netxen_set_msix_bit(pdev, 1); |
| 887 | dev_info(&pdev->dev, "using msi-x interrupts\n"); |
| 888 | |
| 889 | } else { |
| 890 | request_msi: |
| 891 | if (use_msi && !pci_enable_msi(pdev)) { |
| 892 | adapter->flags |= NETXEN_NIC_MSI_ENABLED; |
| 893 | dev_info(&pdev->dev, "using msi interrupts\n"); |
| 894 | } else |
| 895 | dev_info(&pdev->dev, "using legacy interrupts\n"); |
| 896 | } |
| 897 | |
| 898 | if (adapter->flags & NETXEN_NIC_MSIX_ENABLED) |
| 899 | netdev->irq = adapter->msix_entries[0].vector; |
| 900 | else |
| 901 | netdev->irq = pdev->irq; |
| 902 | |
| 903 | err = netxen_receive_peg_ready(adapter); |
| 904 | if (err) |
| 905 | goto err_out_disable_msi; |
| 906 | |
| 907 | init_timer(&adapter->watchdog_timer); |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 908 | adapter->ahw.linkup = 0; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 909 | adapter->watchdog_timer.function = &netxen_watchdog; |
| 910 | adapter->watchdog_timer.data = (unsigned long)adapter; |
| 911 | INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task); |
| 912 | INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task); |
| 913 | |
| 914 | if (netxen_is_flash_supported(adapter) == 0 && |
| 915 | netxen_get_flash_mac_addr(adapter, mac_addr) == 0) { |
| 916 | unsigned char *p; |
| 917 | |
| 918 | p = (unsigned char *)&mac_addr[adapter->portnum]; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 919 | netdev->dev_addr[0] = *(p + 5); |
| 920 | netdev->dev_addr[1] = *(p + 4); |
| 921 | netdev->dev_addr[2] = *(p + 3); |
| 922 | netdev->dev_addr[3] = *(p + 2); |
| 923 | netdev->dev_addr[4] = *(p + 1); |
| 924 | netdev->dev_addr[5] = *(p + 0); |
| 925 | |
| 926 | memcpy(netdev->perm_addr, netdev->dev_addr, |
| 927 | netdev->addr_len); |
| 928 | if (!is_valid_ether_addr(netdev->perm_addr)) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 929 | printk(KERN_ERR "%s: Bad MAC address %s.\n", |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 930 | netxen_nic_driver_name, |
| 931 | print_mac(mac, netdev->dev_addr)); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 932 | } else { |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 933 | adapter->macaddr_set(adapter, netdev->dev_addr); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 934 | } |
| 935 | } |
| 936 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 937 | netif_carrier_off(netdev); |
| 938 | netif_stop_queue(netdev); |
| 939 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 940 | if ((err = register_netdev(netdev))) { |
| 941 | printk(KERN_ERR "%s: register_netdev failed port #%d" |
| 942 | " aborting\n", netxen_nic_driver_name, |
| 943 | adapter->portnum); |
| 944 | err = -EIO; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 945 | goto err_out_disable_msi; |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | pci_set_drvdata(pdev, adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 949 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 950 | switch (adapter->ahw.board_type) { |
| 951 | case NETXEN_NIC_GBE: |
| 952 | dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n", |
| 953 | adapter->netdev->name); |
| 954 | break; |
| 955 | case NETXEN_NIC_XGBE: |
| 956 | dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n", |
| 957 | adapter->netdev->name); |
| 958 | break; |
| 959 | } |
| 960 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 961 | return 0; |
| 962 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 963 | err_out_disable_msi: |
| 964 | if (adapter->flags & NETXEN_NIC_MSIX_ENABLED) |
| 965 | pci_disable_msix(pdev); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 966 | if (adapter->flags & NETXEN_NIC_MSI_ENABLED) |
| 967 | pci_disable_msi(pdev); |
| 968 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 969 | if (first_driver) |
| 970 | netxen_free_adapter_offload(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 971 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 972 | err_out_iounmap: |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 973 | if (db_ptr) |
| 974 | iounmap(db_ptr); |
| 975 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 976 | if (mem_ptr0) |
| 977 | iounmap(mem_ptr0); |
| 978 | if (mem_ptr1) |
| 979 | iounmap(mem_ptr1); |
| 980 | if (mem_ptr2) |
| 981 | iounmap(mem_ptr2); |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 982 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 983 | err_out_free_netdev: |
| 984 | free_netdev(netdev); |
| 985 | |
| 986 | err_out_free_res: |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 987 | pci_release_regions(pdev); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 988 | |
| 989 | err_out_disable_pdev: |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 990 | pci_set_drvdata(pdev, NULL); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 991 | pci_disable_device(pdev); |
| 992 | return err; |
| 993 | } |
| 994 | |
| 995 | static void __devexit netxen_nic_remove(struct pci_dev *pdev) |
| 996 | { |
| 997 | struct netxen_adapter *adapter; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 998 | struct net_device *netdev; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 999 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1000 | adapter = pci_get_drvdata(pdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1001 | if (adapter == NULL) |
| 1002 | return; |
| 1003 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1004 | netdev = adapter->netdev; |
| 1005 | |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 1006 | unregister_netdev(netdev); |
| 1007 | |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 1008 | if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1009 | netxen_free_hw_resources(adapter); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1010 | netxen_free_sw_resources(adapter); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 1011 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1012 | |
Dhananjay Phadke | 439b454 | 2008-06-15 22:59:46 -0700 | [diff] [blame] | 1013 | if (adapter->portnum == 0) |
| 1014 | netxen_free_adapter_offload(adapter); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 1015 | |
dhananjay@netxen.com | 3052246 | 2007-08-28 17:23:26 +0530 | [diff] [blame] | 1016 | if (adapter->irq) |
| 1017 | free_irq(adapter->irq, adapter); |
| 1018 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1019 | if (adapter->flags & NETXEN_NIC_MSIX_ENABLED) |
| 1020 | pci_disable_msix(pdev); |
dhananjay@netxen.com | 3052246 | 2007-08-28 17:23:26 +0530 | [diff] [blame] | 1021 | if (adapter->flags & NETXEN_NIC_MSI_ENABLED) |
| 1022 | pci_disable_msi(pdev); |
| 1023 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1024 | iounmap(adapter->ahw.db_base); |
| 1025 | iounmap(adapter->ahw.pci_base0); |
| 1026 | iounmap(adapter->ahw.pci_base1); |
| 1027 | iounmap(adapter->ahw.pci_base2); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 1028 | |
| 1029 | pci_release_regions(pdev); |
dhananjay@netxen.com | 3052246 | 2007-08-28 17:23:26 +0530 | [diff] [blame] | 1030 | pci_disable_device(pdev); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 1031 | pci_set_drvdata(pdev, NULL); |
| 1032 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1033 | free_netdev(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | /* |
| 1037 | * Called when a network interface is made active |
| 1038 | * @returns 0 on success, negative value on failure |
| 1039 | */ |
| 1040 | static int netxen_nic_open(struct net_device *netdev) |
| 1041 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1042 | struct netxen_adapter *adapter = (struct netxen_adapter *)netdev->priv; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1043 | int err = 0; |
| 1044 | int ctx, ring; |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1045 | irq_handler_t handler; |
| 1046 | unsigned long flags = IRQF_SAMPLE_RANDOM; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1047 | |
Dhananjay Phadke | dcd56fd | 2008-06-15 22:59:45 -0700 | [diff] [blame] | 1048 | if (adapter->driver_mismatch) |
| 1049 | return -EIO; |
| 1050 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1051 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) { |
| 1052 | err = netxen_init_firmware(adapter); |
| 1053 | if (err != 0) { |
| 1054 | printk(KERN_ERR "Failed to init firmware\n"); |
| 1055 | return -EIO; |
| 1056 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1057 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1058 | err = netxen_alloc_sw_resources(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1059 | if (err) { |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1060 | printk(KERN_ERR "%s: Error in setting sw resources\n", |
| 1061 | netdev->name); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1062 | return err; |
| 1063 | } |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1064 | |
| 1065 | netxen_nic_clear_stats(adapter); |
| 1066 | |
| 1067 | err = netxen_alloc_hw_resources(adapter); |
| 1068 | if (err) { |
| 1069 | printk(KERN_ERR "%s: Error in setting hw resources\n", |
| 1070 | netdev->name); |
| 1071 | goto err_out_free_sw; |
| 1072 | } |
| 1073 | |
| 1074 | if (adapter->fw_major < 4) { |
| 1075 | adapter->crb_addr_cmd_producer = |
| 1076 | crb_cmd_producer[adapter->portnum]; |
| 1077 | adapter->crb_addr_cmd_consumer = |
| 1078 | crb_cmd_consumer[adapter->portnum]; |
| 1079 | } |
| 1080 | |
| 1081 | netxen_nic_update_cmd_producer(adapter, 0); |
| 1082 | netxen_nic_update_cmd_consumer(adapter, 0); |
| 1083 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1084 | for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) { |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 1085 | for (ring = 0; ring < adapter->max_rds_rings; ring++) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1086 | netxen_post_rx_buffers(adapter, ctx, ring); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1087 | } |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1088 | if (NETXEN_IS_MSI_FAMILY(adapter)) |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1089 | handler = netxen_msi_intr; |
| 1090 | else { |
| 1091 | flags |= IRQF_SHARED; |
| 1092 | handler = netxen_intr; |
| 1093 | } |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1094 | adapter->irq = netdev->irq; |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1095 | err = request_irq(adapter->irq, handler, |
| 1096 | flags, netdev->name, adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1097 | if (err) { |
| 1098 | printk(KERN_ERR "request_irq failed with: %d\n", err); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1099 | goto err_out_free_hw; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1100 | } |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1101 | |
| 1102 | adapter->is_up = NETXEN_ADAPTER_UP_MAGIC; |
| 1103 | } |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1104 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1105 | /* Done here again so that even if phantom sw overwrote it, |
| 1106 | * we set it */ |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 1107 | err = adapter->init_port(adapter, adapter->physical_port); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1108 | if (err) { |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 1109 | printk(KERN_ERR "%s: Failed to initialize port %d\n", |
| 1110 | netxen_nic_driver_name, adapter->portnum); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1111 | goto err_out_free_irq; |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 1112 | } |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1113 | adapter->macaddr_set(adapter, netdev->dev_addr); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 1114 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1115 | netxen_nic_set_link_parameters(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1116 | |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 1117 | netdev->set_multicast_list(netdev); |
| 1118 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) |
| 1119 | nx_fw_cmd_set_mtu(adapter, netdev->mtu); |
| 1120 | else |
| 1121 | adapter->set_mtu(adapter, netdev->mtu); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1122 | |
Dhananjay Phadke | dcd56fd | 2008-06-15 22:59:45 -0700 | [diff] [blame] | 1123 | mod_timer(&adapter->watchdog_timer, jiffies); |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1124 | |
| 1125 | napi_enable(&adapter->napi); |
| 1126 | netxen_nic_enable_int(adapter); |
| 1127 | |
Dhananjay Phadke | dcd56fd | 2008-06-15 22:59:45 -0700 | [diff] [blame] | 1128 | netif_start_queue(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1129 | |
| 1130 | return 0; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1131 | |
| 1132 | err_out_free_irq: |
| 1133 | free_irq(adapter->irq, adapter); |
| 1134 | err_out_free_hw: |
| 1135 | netxen_free_hw_resources(adapter); |
| 1136 | err_out_free_sw: |
| 1137 | netxen_free_sw_resources(adapter); |
| 1138 | return err; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | /* |
| 1142 | * netxen_nic_close - Disables a network interface entry point |
| 1143 | */ |
| 1144 | static int netxen_nic_close(struct net_device *netdev) |
| 1145 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1146 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1147 | |
| 1148 | netif_carrier_off(netdev); |
| 1149 | netif_stop_queue(netdev); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1150 | napi_disable(&adapter->napi); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1151 | |
dhananjay@netxen.com | 72b0a7a | 2007-12-26 10:23:56 -0800 | [diff] [blame] | 1152 | if (adapter->stop_port) |
| 1153 | adapter->stop_port(adapter); |
| 1154 | |
dhananjay@netxen.com | e01872af | 2007-07-25 20:13:12 +0530 | [diff] [blame] | 1155 | netxen_nic_disable_int(adapter); |
| 1156 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1157 | netxen_release_tx_buffers(adapter); |
| 1158 | |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 1159 | if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) { |
| 1160 | FLUSH_SCHEDULED_WORK(); |
| 1161 | del_timer_sync(&adapter->watchdog_timer); |
| 1162 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1163 | |
| 1164 | return 0; |
| 1165 | } |
| 1166 | |
| 1167 | static int netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
| 1168 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1169 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1170 | struct netxen_hardware_context *hw = &adapter->ahw; |
| 1171 | unsigned int first_seg_len = skb->len - skb->data_len; |
| 1172 | struct netxen_skb_frag *buffrag; |
| 1173 | unsigned int i; |
| 1174 | |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1175 | u32 producer, consumer; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1176 | u32 saved_producer = 0; |
| 1177 | struct cmd_desc_type0 *hwdesc; |
| 1178 | int k; |
| 1179 | struct netxen_cmd_buffer *pbuf = NULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1180 | int frag_count; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1181 | int no_of_desc; |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1182 | u32 num_txd = adapter->max_tx_desc_count; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1183 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1184 | frag_count = skb_shinfo(skb)->nr_frags + 1; |
| 1185 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1186 | /* There 4 fragments per descriptor */ |
| 1187 | no_of_desc = (frag_count + 3) >> 2; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 1188 | if (netdev->features & NETIF_F_TSO) { |
| 1189 | if (skb_shinfo(skb)->gso_size > 0) { |
| 1190 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1191 | no_of_desc++; |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 1192 | if ((ip_hdrlen(skb) + tcp_hdrlen(skb) + |
Arnaldo Carvalho de Melo | c9bdd4b | 2007-03-12 20:09:15 -0300 | [diff] [blame] | 1193 | sizeof(struct ethhdr)) > |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1194 | (sizeof(struct cmd_desc_type0) - 2)) { |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 1195 | no_of_desc++; |
| 1196 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1197 | } |
| 1198 | } |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 1199 | |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1200 | producer = adapter->cmd_producer; |
| 1201 | smp_mb(); |
| 1202 | consumer = adapter->last_cmd_consumer; |
| 1203 | if ((no_of_desc+2) > find_diff_among(producer, consumer, num_txd)) { |
| 1204 | netif_stop_queue(netdev); |
| 1205 | smp_mb(); |
| 1206 | return NETDEV_TX_BUSY; |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 1207 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1208 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1209 | /* Copy the descriptors into the hardware */ |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1210 | saved_producer = producer; |
| 1211 | hwdesc = &hw->cmd_desc_head[producer]; |
| 1212 | memset(hwdesc, 0, sizeof(struct cmd_desc_type0)); |
| 1213 | /* Take skb->data itself */ |
| 1214 | pbuf = &adapter->cmd_buf_arr[producer]; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 1215 | if ((netdev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size > 0) { |
Al Viro | a608ab9 | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 1216 | pbuf->mss = skb_shinfo(skb)->gso_size; |
Amit S. Kale | ed33ebe | 2006-12-18 05:53:59 -0800 | [diff] [blame] | 1217 | hwdesc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1218 | } else { |
| 1219 | pbuf->mss = 0; |
| 1220 | hwdesc->mss = 0; |
| 1221 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1222 | pbuf->total_length = skb->len; |
| 1223 | pbuf->skb = skb; |
| 1224 | pbuf->cmd = TX_ETHER_PKT; |
| 1225 | pbuf->frag_count = frag_count; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1226 | pbuf->port = adapter->portnum; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1227 | buffrag = &pbuf->frag_array[0]; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1228 | 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] | 1229 | PCI_DMA_TODEVICE); |
| 1230 | buffrag->length = first_seg_len; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1231 | netxen_set_cmd_desc_totallength(hwdesc, skb->len); |
| 1232 | netxen_set_cmd_desc_num_of_buff(hwdesc, frag_count); |
| 1233 | netxen_set_cmd_desc_opcode(hwdesc, TX_ETHER_PKT); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1234 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1235 | netxen_set_cmd_desc_port(hwdesc, adapter->portnum); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1236 | netxen_set_cmd_desc_ctxid(hwdesc, adapter->portnum); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1237 | hwdesc->buffer1_length = cpu_to_le16(first_seg_len); |
| 1238 | hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma); |
| 1239 | |
| 1240 | for (i = 1, k = 1; i < frag_count; i++, k++) { |
| 1241 | struct skb_frag_struct *frag; |
| 1242 | int len, temp_len; |
| 1243 | unsigned long offset; |
| 1244 | dma_addr_t temp_dma; |
| 1245 | |
| 1246 | /* move to next desc. if there is a need */ |
| 1247 | if ((i & 0x3) == 0) { |
| 1248 | k = 0; |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1249 | producer = get_next_index(producer, num_txd); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1250 | hwdesc = &hw->cmd_desc_head[producer]; |
| 1251 | memset(hwdesc, 0, sizeof(struct cmd_desc_type0)); |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 1252 | pbuf = &adapter->cmd_buf_arr[producer]; |
| 1253 | pbuf->skb = NULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1254 | } |
| 1255 | frag = &skb_shinfo(skb)->frags[i - 1]; |
| 1256 | len = frag->size; |
| 1257 | offset = frag->page_offset; |
| 1258 | |
| 1259 | temp_len = len; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1260 | temp_dma = pci_map_page(adapter->pdev, frag->page, offset, |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1261 | len, PCI_DMA_TODEVICE); |
| 1262 | |
| 1263 | buffrag++; |
| 1264 | buffrag->dma = temp_dma; |
| 1265 | buffrag->length = temp_len; |
| 1266 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1267 | switch (k) { |
| 1268 | case 0: |
| 1269 | hwdesc->buffer1_length = cpu_to_le16(temp_len); |
| 1270 | hwdesc->addr_buffer1 = cpu_to_le64(temp_dma); |
| 1271 | break; |
| 1272 | case 1: |
| 1273 | hwdesc->buffer2_length = cpu_to_le16(temp_len); |
| 1274 | hwdesc->addr_buffer2 = cpu_to_le64(temp_dma); |
| 1275 | break; |
| 1276 | case 2: |
| 1277 | hwdesc->buffer3_length = cpu_to_le16(temp_len); |
| 1278 | hwdesc->addr_buffer3 = cpu_to_le64(temp_dma); |
| 1279 | break; |
| 1280 | case 3: |
Al Viro | a608ab9 | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 1281 | hwdesc->buffer4_length = cpu_to_le16(temp_len); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1282 | hwdesc->addr_buffer4 = cpu_to_le64(temp_dma); |
| 1283 | break; |
| 1284 | } |
| 1285 | frag++; |
| 1286 | } |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1287 | producer = get_next_index(producer, num_txd); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1288 | |
| 1289 | /* might change opcode to TX_TCP_LSO */ |
| 1290 | netxen_tso_check(adapter, &hw->cmd_desc_head[saved_producer], skb); |
| 1291 | |
| 1292 | /* For LSO, we need to copy the MAC/IP/TCP headers into |
| 1293 | * the descriptor ring |
| 1294 | */ |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1295 | if (netxen_get_cmd_desc_opcode(&hw->cmd_desc_head[saved_producer]) |
| 1296 | == TX_TCP_LSO) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1297 | int hdr_len, first_hdr_len, more_hdr; |
| 1298 | hdr_len = hw->cmd_desc_head[saved_producer].total_hdr_length; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1299 | if (hdr_len > (sizeof(struct cmd_desc_type0) - 2)) { |
| 1300 | first_hdr_len = sizeof(struct cmd_desc_type0) - 2; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1301 | more_hdr = 1; |
| 1302 | } else { |
| 1303 | first_hdr_len = hdr_len; |
| 1304 | more_hdr = 0; |
| 1305 | } |
| 1306 | /* copy the MAC/IP/TCP headers to the cmd descriptor list */ |
| 1307 | hwdesc = &hw->cmd_desc_head[producer]; |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 1308 | pbuf = &adapter->cmd_buf_arr[producer]; |
| 1309 | pbuf->skb = NULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1310 | |
| 1311 | /* copy the first 64 bytes */ |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1312 | memcpy(((void *)hwdesc) + 2, |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1313 | (void *)(skb->data), first_hdr_len); |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1314 | producer = get_next_index(producer, num_txd); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1315 | |
| 1316 | if (more_hdr) { |
| 1317 | hwdesc = &hw->cmd_desc_head[producer]; |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 1318 | pbuf = &adapter->cmd_buf_arr[producer]; |
| 1319 | pbuf->skb = NULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1320 | /* copy the next 64 bytes - should be enough except |
| 1321 | * for pathological case |
| 1322 | */ |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 1323 | skb_copy_from_linear_data_offset(skb, first_hdr_len, |
| 1324 | hwdesc, |
| 1325 | (hdr_len - |
| 1326 | first_hdr_len)); |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1327 | producer = get_next_index(producer, num_txd); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1328 | } |
| 1329 | } |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1330 | |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1331 | adapter->cmd_producer = producer; |
Dhananjay Phadke | 5dc1626 | 2007-12-31 10:08:57 -0800 | [diff] [blame] | 1332 | adapter->stats.txbytes += skb->len; |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1333 | |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1334 | netxen_nic_update_cmd_producer(adapter, adapter->cmd_producer); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1335 | |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1336 | adapter->stats.xmitcalled++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1337 | netdev->trans_start = jiffies; |
| 1338 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1339 | return NETDEV_TX_OK; |
| 1340 | } |
| 1341 | |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1342 | static int netxen_nic_check_temp(struct netxen_adapter *adapter) |
| 1343 | { |
| 1344 | struct net_device *netdev = adapter->netdev; |
| 1345 | uint32_t temp, temp_state, temp_val; |
| 1346 | int rv = 0; |
| 1347 | |
| 1348 | temp = adapter->pci_read_normalize(adapter, CRB_TEMP_STATE); |
| 1349 | |
| 1350 | temp_state = nx_get_temp_state(temp); |
| 1351 | temp_val = nx_get_temp_val(temp); |
| 1352 | |
| 1353 | if (temp_state == NX_TEMP_PANIC) { |
| 1354 | printk(KERN_ALERT |
| 1355 | "%s: Device temperature %d degrees C exceeds" |
| 1356 | " maximum allowed. Hardware has been shut down.\n", |
| 1357 | netxen_nic_driver_name, temp_val); |
| 1358 | |
| 1359 | netif_carrier_off(netdev); |
| 1360 | netif_stop_queue(netdev); |
| 1361 | rv = 1; |
| 1362 | } else if (temp_state == NX_TEMP_WARN) { |
| 1363 | if (adapter->temp == NX_TEMP_NORMAL) { |
| 1364 | printk(KERN_ALERT |
| 1365 | "%s: Device temperature %d degrees C " |
| 1366 | "exceeds operating range." |
| 1367 | " Immediate action needed.\n", |
| 1368 | netxen_nic_driver_name, temp_val); |
| 1369 | } |
| 1370 | } else { |
| 1371 | if (adapter->temp == NX_TEMP_WARN) { |
| 1372 | printk(KERN_INFO |
| 1373 | "%s: Device temperature is now %d degrees C" |
| 1374 | " in normal range.\n", netxen_nic_driver_name, |
| 1375 | temp_val); |
| 1376 | } |
| 1377 | } |
| 1378 | adapter->temp = temp_state; |
| 1379 | return rv; |
| 1380 | } |
| 1381 | |
| 1382 | static void netxen_nic_handle_phy_intr(struct netxen_adapter *adapter) |
| 1383 | { |
| 1384 | struct net_device *netdev = adapter->netdev; |
| 1385 | u32 val, port, linkup; |
| 1386 | |
| 1387 | port = adapter->physical_port; |
| 1388 | |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 1389 | if (adapter->ahw.board_type == NETXEN_NIC_GBE) { |
| 1390 | val = adapter->pci_read_normalize(adapter, CRB_XG_STATE); |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1391 | linkup = (val >> port) & 1; |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 1392 | } else { |
| 1393 | if (adapter->fw_major < 4) { |
| 1394 | val = adapter->pci_read_normalize(adapter, |
| 1395 | CRB_XG_STATE); |
| 1396 | val = (val >> port*8) & 0xff; |
| 1397 | linkup = (val == XG_LINK_UP); |
| 1398 | } else { |
| 1399 | val = adapter->pci_read_normalize(adapter, |
| 1400 | CRB_XG_STATE_P3); |
| 1401 | val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val); |
| 1402 | linkup = (val == XG_LINK_UP_P3); |
| 1403 | } |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1404 | } |
| 1405 | |
| 1406 | if (adapter->ahw.linkup && !linkup) { |
| 1407 | printk(KERN_INFO "%s: %s NIC Link is down\n", |
| 1408 | netxen_nic_driver_name, netdev->name); |
| 1409 | adapter->ahw.linkup = 0; |
| 1410 | if (netif_running(netdev)) { |
| 1411 | netif_carrier_off(netdev); |
| 1412 | netif_stop_queue(netdev); |
| 1413 | } |
| 1414 | } else if (!adapter->ahw.linkup && linkup) { |
| 1415 | printk(KERN_INFO "%s: %s NIC Link is up\n", |
| 1416 | netxen_nic_driver_name, netdev->name); |
| 1417 | adapter->ahw.linkup = 1; |
| 1418 | if (netif_running(netdev)) { |
| 1419 | netif_carrier_on(netdev); |
| 1420 | netif_wake_queue(netdev); |
| 1421 | } |
| 1422 | } |
| 1423 | } |
| 1424 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1425 | static void netxen_watchdog(unsigned long v) |
| 1426 | { |
| 1427 | struct netxen_adapter *adapter = (struct netxen_adapter *)v; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1428 | |
| 1429 | SCHEDULE_WORK(&adapter->watchdog_task); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1430 | } |
| 1431 | |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1432 | void netxen_watchdog_task(struct work_struct *work) |
| 1433 | { |
| 1434 | struct netxen_adapter *adapter = |
| 1435 | container_of(work, struct netxen_adapter, watchdog_task); |
| 1436 | |
| 1437 | if ((adapter->portnum == 0) && netxen_nic_check_temp(adapter)) |
| 1438 | return; |
| 1439 | |
| 1440 | netxen_nic_handle_phy_intr(adapter); |
| 1441 | |
| 1442 | mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ); |
| 1443 | } |
| 1444 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1445 | static void netxen_tx_timeout(struct net_device *netdev) |
| 1446 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1447 | struct netxen_adapter *adapter = (struct netxen_adapter *) |
| 1448 | netdev_priv(netdev); |
| 1449 | SCHEDULE_WORK(&adapter->tx_timeout_task); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1450 | } |
| 1451 | |
David Howells | 6d5aefb | 2006-12-05 19:36:26 +0000 | [diff] [blame] | 1452 | static void netxen_tx_timeout_task(struct work_struct *work) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1453 | { |
Jeff Garzik | 4790654 | 2007-11-23 21:23:36 -0500 | [diff] [blame] | 1454 | struct netxen_adapter *adapter = |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1455 | container_of(work, struct netxen_adapter, tx_timeout_task); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1456 | |
| 1457 | printk(KERN_ERR "%s %s: transmit timeout, resetting.\n", |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1458 | netxen_nic_driver_name, adapter->netdev->name); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1459 | |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1460 | netxen_nic_disable_int(adapter); |
| 1461 | napi_disable(&adapter->napi); |
| 1462 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1463 | adapter->netdev->trans_start = jiffies; |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1464 | |
| 1465 | napi_enable(&adapter->napi); |
| 1466 | netxen_nic_enable_int(adapter); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1467 | netif_wake_queue(adapter->netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1468 | } |
| 1469 | |
Dhananjay Phadke | a97342f | 2008-07-21 19:44:05 -0700 | [diff] [blame] | 1470 | /* |
| 1471 | * netxen_nic_get_stats - Get System Network Statistics |
| 1472 | * @netdev: network interface device structure |
| 1473 | */ |
| 1474 | struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev) |
| 1475 | { |
| 1476 | struct netxen_adapter *adapter = netdev_priv(netdev); |
| 1477 | struct net_device_stats *stats = &adapter->net_stats; |
| 1478 | |
| 1479 | memset(stats, 0, sizeof(*stats)); |
| 1480 | |
| 1481 | /* total packets received */ |
| 1482 | stats->rx_packets = adapter->stats.no_rcv; |
| 1483 | /* total packets transmitted */ |
| 1484 | stats->tx_packets = adapter->stats.xmitedframes + |
| 1485 | adapter->stats.xmitfinished; |
| 1486 | /* total bytes received */ |
| 1487 | stats->rx_bytes = adapter->stats.rxbytes; |
| 1488 | /* total bytes transmitted */ |
| 1489 | stats->tx_bytes = adapter->stats.txbytes; |
| 1490 | /* bad packets received */ |
| 1491 | stats->rx_errors = adapter->stats.rcvdbadskb; |
| 1492 | /* packet transmit problems */ |
| 1493 | stats->tx_errors = adapter->stats.nocmddescriptor; |
| 1494 | /* no space in linux buffers */ |
| 1495 | stats->rx_dropped = adapter->stats.rxdropped; |
| 1496 | /* no space available in linux */ |
| 1497 | stats->tx_dropped = adapter->stats.txdropped; |
| 1498 | |
| 1499 | return stats; |
| 1500 | } |
| 1501 | |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1502 | static inline void |
| 1503 | netxen_handle_int(struct netxen_adapter *adapter) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1504 | { |
dhananjay.phadke@gmail.com | 2d1a3bb | 2007-07-02 00:26:00 +0530 | [diff] [blame] | 1505 | netxen_nic_disable_int(adapter); |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1506 | napi_schedule(&adapter->napi); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1507 | } |
| 1508 | |
Dhananjay Phadke | e4c93c8 | 2008-07-21 19:44:02 -0700 | [diff] [blame] | 1509 | static irqreturn_t netxen_intr(int irq, void *data) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1510 | { |
Jeff Garzik | 1daec86 | 2007-10-19 03:14:03 -0400 | [diff] [blame] | 1511 | struct netxen_adapter *adapter = data; |
dhananjay@netxen.com | e01872af | 2007-07-25 20:13:12 +0530 | [diff] [blame] | 1512 | u32 our_int = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1513 | |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1514 | our_int = adapter->pci_read_normalize(adapter, CRB_INT_VECTOR); |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1515 | /* not our interrupt */ |
| 1516 | if ((our_int & (0x80 << adapter->portnum)) == 0) |
| 1517 | return IRQ_NONE; |
dhananjay@netxen.com | e01872af | 2007-07-25 20:13:12 +0530 | [diff] [blame] | 1518 | |
| 1519 | if (adapter->intr_scheme == INTR_SCHEME_PERPORT) { |
| 1520 | /* claim interrupt */ |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1521 | adapter->pci_write_normalize(adapter, CRB_INT_VECTOR, |
| 1522 | our_int & ~((u32)(0x80 << adapter->portnum))); |
dhananjay@netxen.com | e01872af | 2007-07-25 20:13:12 +0530 | [diff] [blame] | 1523 | } |
| 1524 | |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1525 | netxen_handle_int(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1526 | |
| 1527 | return IRQ_HANDLED; |
| 1528 | } |
| 1529 | |
Dhananjay Phadke | e4c93c8 | 2008-07-21 19:44:02 -0700 | [diff] [blame] | 1530 | static irqreturn_t netxen_msi_intr(int irq, void *data) |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1531 | { |
| 1532 | struct netxen_adapter *adapter = data; |
| 1533 | |
| 1534 | netxen_handle_int(adapter); |
| 1535 | return IRQ_HANDLED; |
| 1536 | } |
| 1537 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1538 | static int netxen_nic_poll(struct napi_struct *napi, int budget) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1539 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1540 | struct netxen_adapter *adapter = container_of(napi, struct netxen_adapter, napi); |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1541 | int tx_complete; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1542 | int ctx; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1543 | int work_done; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1544 | |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1545 | tx_complete = netxen_process_cmd_ring(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1546 | |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 1547 | work_done = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1548 | for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) { |
| 1549 | /* |
| 1550 | * Fairness issue. This will give undue weight to the |
| 1551 | * receive context 0. |
| 1552 | */ |
| 1553 | |
| 1554 | /* |
| 1555 | * To avoid starvation, we give each of our receivers, |
| 1556 | * a fraction of the quota. Sometimes, it might happen that we |
| 1557 | * have enough quota to process every packet, but since all the |
| 1558 | * packets are on one context, it gets only half of the quota, |
| 1559 | * and ends up not processing it. |
| 1560 | */ |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1561 | work_done += netxen_process_rcv_ring(adapter, ctx, |
| 1562 | budget / MAX_RCV_CTX); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1563 | } |
| 1564 | |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1565 | if ((work_done < budget) && tx_complete) { |
| 1566 | netif_rx_complete(adapter->netdev, &adapter->napi); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1567 | netxen_nic_enable_int(adapter); |
| 1568 | } |
| 1569 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1570 | return work_done; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1571 | } |
| 1572 | |
| 1573 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1574 | static void netxen_nic_poll_controller(struct net_device *netdev) |
| 1575 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1576 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1577 | disable_irq(adapter->irq); |
Jeff Garzik | 1494a81 | 2006-11-07 05:12:16 -0500 | [diff] [blame] | 1578 | netxen_intr(adapter->irq, adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1579 | enable_irq(adapter->irq); |
| 1580 | } |
| 1581 | #endif |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1582 | |
| 1583 | static struct pci_driver netxen_driver = { |
| 1584 | .name = netxen_nic_driver_name, |
| 1585 | .id_table = netxen_pci_tbl, |
| 1586 | .probe = netxen_nic_probe, |
| 1587 | .remove = __devexit_p(netxen_nic_remove) |
| 1588 | }; |
| 1589 | |
| 1590 | /* Driver Registration on NetXen card */ |
| 1591 | |
| 1592 | static int __init netxen_init_module(void) |
| 1593 | { |
Al Viro | 79ea13c | 2008-01-24 02:06:46 -0800 | [diff] [blame] | 1594 | if ((netxen_workq = create_singlethread_workqueue("netxen")) == NULL) |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1595 | return -ENOMEM; |
| 1596 | |
Amit S. Kale | 184231b | 2007-01-22 06:52:53 -0800 | [diff] [blame] | 1597 | return pci_register_driver(&netxen_driver); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1598 | } |
| 1599 | |
| 1600 | module_init(netxen_init_module); |
| 1601 | |
| 1602 | static void __exit netxen_exit_module(void) |
| 1603 | { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1604 | pci_unregister_driver(&netxen_driver); |
Amit S. Kale | 9de0661 | 2007-02-21 06:37:06 -0800 | [diff] [blame] | 1605 | destroy_workqueue(netxen_workq); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1606 | } |
| 1607 | |
| 1608 | module_exit(netxen_exit_module); |