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