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