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