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