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