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