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