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