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