Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2003 - 2006 NetXen, Inc. |
| 3 | * All rights reserved. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 4 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 9 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 10 | * This program is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 14 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| 18 | * MA 02111-1307, USA. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 19 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 20 | * The full GNU General Public License is included in this distribution |
| 21 | * in the file called LICENSE. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 22 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 23 | * Contact Information: |
| 24 | * info@netxen.com |
| 25 | * NetXen, |
| 26 | * 3965 Freedom Circle, Fourth floor, |
| 27 | * Santa Clara, CA 95054 |
| 28 | * |
| 29 | * |
| 30 | * Main source file for NetXen NIC Driver on Linux |
| 31 | * |
| 32 | */ |
| 33 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 34 | #include <linux/vmalloc.h> |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 35 | #include <linux/highmem.h> |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 36 | #include "netxen_nic_hw.h" |
| 37 | |
| 38 | #include "netxen_nic.h" |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 39 | #include "netxen_nic_phan_reg.h" |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 40 | |
Jeff Garzik | 1494a81 | 2006-11-07 05:12:16 -0500 | [diff] [blame] | 41 | #include <linux/dma-mapping.h> |
Arnaldo Carvalho de Melo | c9bdd4b | 2007-03-12 20:09:15 -0300 | [diff] [blame] | 42 | #include <net/ip.h> |
Jeff Garzik | 1494a81 | 2006-11-07 05:12:16 -0500 | [diff] [blame] | 43 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 44 | MODULE_DESCRIPTION("NetXen Multi port (1/10) Gigabit Network Driver"); |
| 45 | MODULE_LICENSE("GPL"); |
| 46 | MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID); |
| 47 | |
dhananjay@netxen.com | ceded32 | 2007-07-19 14:41:09 +0530 | [diff] [blame] | 48 | char netxen_nic_driver_name[] = "netxen_nic"; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 49 | static char netxen_nic_driver_string[] = "NetXen Network Driver version " |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 50 | NETXEN_NIC_LINUX_VERSIONID; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 51 | |
| 52 | #define NETXEN_NETDEV_WEIGHT 120 |
| 53 | #define NETXEN_ADAPTER_UP_MAGIC 777 |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 54 | #define NETXEN_NIC_PEG_TUNE 0 |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 55 | |
| 56 | /* Local functions to NetXen NIC driver */ |
| 57 | static int __devinit netxen_nic_probe(struct pci_dev *pdev, |
| 58 | const struct pci_device_id *ent); |
| 59 | static void __devexit netxen_nic_remove(struct pci_dev *pdev); |
| 60 | static int netxen_nic_open(struct net_device *netdev); |
| 61 | static int netxen_nic_close(struct net_device *netdev); |
| 62 | static int netxen_nic_xmit_frame(struct sk_buff *, struct net_device *); |
| 63 | static void netxen_tx_timeout(struct net_device *netdev); |
David Howells | 6d5aefb | 2006-12-05 19:36:26 +0000 | [diff] [blame] | 64 | static void netxen_tx_timeout_task(struct work_struct *work); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 65 | static void netxen_watchdog(unsigned long); |
| 66 | static int netxen_handle_int(struct netxen_adapter *, struct net_device *); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 67 | static int netxen_nic_poll(struct napi_struct *napi, int budget); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 68 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 69 | static void netxen_nic_poll_controller(struct net_device *netdev); |
| 70 | #endif |
Jeff Garzik | 1494a81 | 2006-11-07 05:12:16 -0500 | [diff] [blame] | 71 | static irqreturn_t netxen_intr(int irq, void *data); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 72 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 73 | int physical_port[] = {0, 1, 2, 3}; |
| 74 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 75 | /* PCI Device ID Table */ |
| 76 | static struct pci_device_id netxen_pci_tbl[] __devinitdata = { |
| 77 | {PCI_DEVICE(0x4040, 0x0001)}, |
| 78 | {PCI_DEVICE(0x4040, 0x0002)}, |
| 79 | {PCI_DEVICE(0x4040, 0x0003)}, |
| 80 | {PCI_DEVICE(0x4040, 0x0004)}, |
| 81 | {PCI_DEVICE(0x4040, 0x0005)}, |
Amit S. Kale | 0d39073 | 2006-12-18 05:50:59 -0800 | [diff] [blame] | 82 | {PCI_DEVICE(0x4040, 0x0024)}, |
| 83 | {PCI_DEVICE(0x4040, 0x0025)}, |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 84 | {0,} |
| 85 | }; |
| 86 | |
| 87 | MODULE_DEVICE_TABLE(pci, netxen_pci_tbl); |
| 88 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 89 | struct workqueue_struct *netxen_workq; |
| 90 | static void netxen_watchdog(unsigned long); |
| 91 | |
Adrian Bunk | 993fb90 | 2007-11-05 18:07:31 +0100 | [diff] [blame] | 92 | static void netxen_nic_update_cmd_producer(struct netxen_adapter *adapter, |
| 93 | uint32_t crb_producer) |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 94 | { |
| 95 | switch (adapter->portnum) { |
| 96 | case 0: |
| 97 | writel(crb_producer, NETXEN_CRB_NORMALIZE |
| 98 | (adapter, CRB_CMD_PRODUCER_OFFSET)); |
| 99 | return; |
| 100 | case 1: |
| 101 | writel(crb_producer, NETXEN_CRB_NORMALIZE |
| 102 | (adapter, CRB_CMD_PRODUCER_OFFSET_1)); |
| 103 | return; |
| 104 | case 2: |
| 105 | writel(crb_producer, NETXEN_CRB_NORMALIZE |
| 106 | (adapter, CRB_CMD_PRODUCER_OFFSET_2)); |
| 107 | return; |
| 108 | case 3: |
| 109 | writel(crb_producer, NETXEN_CRB_NORMALIZE |
| 110 | (adapter, CRB_CMD_PRODUCER_OFFSET_3)); |
| 111 | return; |
| 112 | default: |
| 113 | printk(KERN_WARNING "We tried to update " |
| 114 | "CRB_CMD_PRODUCER_OFFSET for invalid " |
| 115 | "PCI function id %d\n", |
| 116 | adapter->portnum); |
| 117 | return; |
| 118 | } |
| 119 | } |
| 120 | |
Adrian Bunk | 993fb90 | 2007-11-05 18:07:31 +0100 | [diff] [blame] | 121 | static void netxen_nic_update_cmd_consumer(struct netxen_adapter *adapter, |
| 122 | u32 crb_consumer) |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 123 | { |
| 124 | switch (adapter->portnum) { |
| 125 | case 0: |
| 126 | writel(crb_consumer, NETXEN_CRB_NORMALIZE |
| 127 | (adapter, CRB_CMD_CONSUMER_OFFSET)); |
| 128 | return; |
| 129 | case 1: |
| 130 | writel(crb_consumer, NETXEN_CRB_NORMALIZE |
| 131 | (adapter, CRB_CMD_CONSUMER_OFFSET_1)); |
| 132 | return; |
| 133 | case 2: |
| 134 | writel(crb_consumer, NETXEN_CRB_NORMALIZE |
| 135 | (adapter, CRB_CMD_CONSUMER_OFFSET_2)); |
| 136 | return; |
| 137 | case 3: |
| 138 | writel(crb_consumer, NETXEN_CRB_NORMALIZE |
| 139 | (adapter, CRB_CMD_CONSUMER_OFFSET_3)); |
| 140 | return; |
| 141 | default: |
| 142 | printk(KERN_WARNING "We tried to update " |
| 143 | "CRB_CMD_PRODUCER_OFFSET for invalid " |
| 144 | "PCI function id %d\n", |
| 145 | adapter->portnum); |
| 146 | return; |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | #define ADAPTER_LIST_SIZE 12 |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 151 | |
Dhananjay Phadke | 443be79 | 2008-03-17 19:59:48 -0700 | [diff] [blame^] | 152 | static uint32_t msi_tgt_status[4] = { |
| 153 | ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1, |
| 154 | ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3 |
| 155 | }; |
| 156 | |
| 157 | static uint32_t sw_int_mask[4] = { |
| 158 | CRB_SW_INT_MASK_0, CRB_SW_INT_MASK_1, |
| 159 | CRB_SW_INT_MASK_2, CRB_SW_INT_MASK_3 |
| 160 | }; |
| 161 | |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 162 | static void netxen_nic_disable_int(struct netxen_adapter *adapter) |
| 163 | { |
Dhananjay Phadke | 443be79 | 2008-03-17 19:59:48 -0700 | [diff] [blame^] | 164 | u32 mask = 0x7ff; |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 165 | int retries = 32; |
Dhananjay Phadke | 443be79 | 2008-03-17 19:59:48 -0700 | [diff] [blame^] | 166 | int port = adapter->portnum; |
| 167 | int pci_fn = adapter->ahw.pci_func; |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 168 | |
Dhananjay Phadke | 443be79 | 2008-03-17 19:59:48 -0700 | [diff] [blame^] | 169 | if (adapter->msi_mode != MSI_MODE_MULTIFUNC) { |
| 170 | writel(0x0, NETXEN_CRB_NORMALIZE(adapter, sw_int_mask[port])); |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | if (adapter->intr_scheme != -1 && |
| 174 | adapter->intr_scheme != INTR_SCHEME_PERPORT) |
| 175 | writel(mask,PCI_OFFSET_SECOND_RANGE(adapter, ISR_INT_MASK)); |
| 176 | |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 177 | if (!(adapter->flags & NETXEN_NIC_MSI_ENABLED)) { |
| 178 | do { |
| 179 | writel(0xffffffff, |
| 180 | PCI_OFFSET_SECOND_RANGE(adapter, ISR_INT_TARGET_STATUS)); |
| 181 | mask = readl(pci_base_offset(adapter, ISR_INT_VECTOR)); |
| 182 | if (!(mask & 0x80)) |
| 183 | break; |
| 184 | udelay(10); |
| 185 | } while (--retries); |
| 186 | |
| 187 | if (!retries) { |
| 188 | printk(KERN_NOTICE "%s: Failed to disable interrupt completely\n", |
| 189 | netxen_nic_driver_name); |
| 190 | } |
Dhananjay Phadke | 443be79 | 2008-03-17 19:59:48 -0700 | [diff] [blame^] | 191 | } else { |
| 192 | if (adapter->msi_mode == MSI_MODE_MULTIFUNC) { |
| 193 | writel(0xffffffff, PCI_OFFSET_SECOND_RANGE(adapter, |
| 194 | msi_tgt_status[pci_fn])); |
| 195 | } |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 196 | } |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | static void netxen_nic_enable_int(struct netxen_adapter *adapter) |
| 200 | { |
| 201 | u32 mask; |
Dhananjay Phadke | 443be79 | 2008-03-17 19:59:48 -0700 | [diff] [blame^] | 202 | int port = adapter->portnum; |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 203 | |
| 204 | DPRINTK(1, INFO, "Entered ISR Enable \n"); |
| 205 | |
| 206 | if (adapter->intr_scheme != -1 && |
| 207 | adapter->intr_scheme != INTR_SCHEME_PERPORT) { |
| 208 | switch (adapter->ahw.board_type) { |
| 209 | case NETXEN_NIC_GBE: |
| 210 | mask = 0x77b; |
| 211 | break; |
| 212 | case NETXEN_NIC_XGBE: |
| 213 | mask = 0x77f; |
| 214 | break; |
| 215 | default: |
| 216 | mask = 0x7ff; |
| 217 | break; |
| 218 | } |
| 219 | |
| 220 | writel(mask, PCI_OFFSET_SECOND_RANGE(adapter, ISR_INT_MASK)); |
| 221 | } |
| 222 | |
Dhananjay Phadke | 443be79 | 2008-03-17 19:59:48 -0700 | [diff] [blame^] | 223 | writel(0x1, NETXEN_CRB_NORMALIZE(adapter, sw_int_mask[port])); |
Stephen Hemminger | 4638aef1 | 2007-07-05 16:13:55 -0700 | [diff] [blame] | 224 | |
| 225 | if (!(adapter->flags & NETXEN_NIC_MSI_ENABLED)) { |
| 226 | mask = 0xbff; |
| 227 | if (adapter->intr_scheme != -1 && |
| 228 | adapter->intr_scheme != INTR_SCHEME_PERPORT) { |
| 229 | writel(0X0, NETXEN_CRB_NORMALIZE(adapter, CRB_INT_VECTOR)); |
| 230 | } |
| 231 | writel(mask, |
| 232 | PCI_OFFSET_SECOND_RANGE(adapter, ISR_INT_TARGET_MASK)); |
| 233 | } |
| 234 | |
| 235 | DPRINTK(1, INFO, "Done with enable Int\n"); |
| 236 | } |
| 237 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 238 | /* |
| 239 | * netxen_nic_probe() |
| 240 | * |
| 241 | * The Linux system will invoke this after identifying the vendor ID and |
| 242 | * device Id in the pci_tbl supported by this module. |
| 243 | * |
| 244 | * A quad port card has one operational PCI config space, (function 0), |
| 245 | * which is used to access all four ports. |
| 246 | * |
| 247 | * This routine will initialize the adapter, and setup the global parameters |
| 248 | * along with the port's specific structure. |
| 249 | */ |
| 250 | static int __devinit |
| 251 | netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 252 | { |
| 253 | struct net_device *netdev = NULL; |
| 254 | struct netxen_adapter *adapter = NULL; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 255 | void __iomem *mem_ptr0 = NULL; |
| 256 | void __iomem *mem_ptr1 = NULL; |
| 257 | void __iomem *mem_ptr2 = NULL; |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 258 | unsigned long first_page_group_end; |
| 259 | unsigned long first_page_group_start; |
| 260 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 261 | |
Al Viro | a608ab9c | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 262 | u8 __iomem *db_ptr = NULL; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 263 | unsigned long mem_base, mem_len, db_base, db_len; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 264 | int pci_using_dac, i = 0, err; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 265 | int ring; |
| 266 | struct netxen_recv_context *recv_ctx = NULL; |
| 267 | struct netxen_rcv_desc_ctx *rcv_desc = NULL; |
| 268 | struct netxen_cmd_buffer *cmd_buf_arr = NULL; |
Al Viro | f305f78 | 2007-12-22 19:44:00 +0000 | [diff] [blame] | 269 | __le64 mac_addr[FLASH_NUM_PORTS + 1]; |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 270 | int valid_mac = 0; |
| 271 | u32 val; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 272 | int pci_func_id = PCI_FUNC(pdev->devfn); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 273 | DECLARE_MAC_BUF(mac); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 274 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 275 | printk(KERN_INFO "%s \n", netxen_nic_driver_string); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 276 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 277 | if (pdev->class != 0x020000) { |
Joe Perches | 5bc5142 | 2007-11-19 17:48:24 -0800 | [diff] [blame] | 278 | printk(KERN_ERR"NetXen function %d, class %x will not " |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 279 | "be enabled.\n",pci_func_id, pdev->class); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 280 | return -ENODEV; |
| 281 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 282 | if ((err = pci_enable_device(pdev))) |
| 283 | return err; |
| 284 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { |
| 285 | err = -ENODEV; |
| 286 | goto err_out_disable_pdev; |
| 287 | } |
| 288 | |
| 289 | if ((err = pci_request_regions(pdev, netxen_nic_driver_name))) |
| 290 | goto err_out_disable_pdev; |
| 291 | |
| 292 | pci_set_master(pdev); |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 293 | if (pdev->revision == NX_P2_C1 && |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 294 | (pci_set_dma_mask(pdev, DMA_35BIT_MASK) == 0) && |
| 295 | (pci_set_consistent_dma_mask(pdev, DMA_35BIT_MASK) == 0)) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 296 | pci_using_dac = 1; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 297 | } else { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 298 | if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) || |
| 299 | (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) |
| 300 | goto err_out_free_res; |
| 301 | |
| 302 | pci_using_dac = 0; |
| 303 | } |
| 304 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 305 | |
| 306 | netdev = alloc_etherdev(sizeof(struct netxen_adapter)); |
| 307 | if(!netdev) { |
| 308 | printk(KERN_ERR"%s: Failed to allocate memory for the " |
| 309 | "device block.Check system memory resource" |
| 310 | " usage.\n", netxen_nic_driver_name); |
| 311 | goto err_out_free_res; |
| 312 | } |
| 313 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 314 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 315 | |
| 316 | adapter = netdev->priv; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 317 | |
| 318 | adapter->ahw.pdev = pdev; |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 319 | adapter->ahw.pci_func = pci_func_id; |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 320 | spin_lock_init(&adapter->tx_lock); |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 321 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 322 | /* remap phys address */ |
| 323 | mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */ |
| 324 | mem_len = pci_resource_len(pdev, 0); |
| 325 | |
| 326 | /* 128 Meg of memory */ |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 327 | if (mem_len == NETXEN_PCI_128MB_SIZE) { |
| 328 | mem_ptr0 = ioremap(mem_base, FIRST_PAGE_GROUP_SIZE); |
| 329 | mem_ptr1 = ioremap(mem_base + SECOND_PAGE_GROUP_START, |
| 330 | SECOND_PAGE_GROUP_SIZE); |
| 331 | mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START, |
| 332 | THIRD_PAGE_GROUP_SIZE); |
| 333 | first_page_group_start = FIRST_PAGE_GROUP_START; |
| 334 | first_page_group_end = FIRST_PAGE_GROUP_END; |
| 335 | } else if (mem_len == NETXEN_PCI_32MB_SIZE) { |
| 336 | mem_ptr1 = ioremap(mem_base, SECOND_PAGE_GROUP_SIZE); |
| 337 | mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START - |
| 338 | SECOND_PAGE_GROUP_START, THIRD_PAGE_GROUP_SIZE); |
| 339 | first_page_group_start = 0; |
| 340 | first_page_group_end = 0; |
| 341 | } else { |
Jeff Garzik | 4790654 | 2007-11-23 21:23:36 -0500 | [diff] [blame] | 342 | err = -EIO; |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 343 | goto err_out_free_netdev; |
| 344 | } |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 345 | |
Al Viro | 79ea13c | 2008-01-24 02:06:46 -0800 | [diff] [blame] | 346 | if ((!mem_ptr0 && mem_len == NETXEN_PCI_128MB_SIZE) || |
| 347 | !mem_ptr1 || !mem_ptr2) { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 348 | DPRINTK(ERR, |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 349 | "Cannot remap adapter memory aborting.:" |
| 350 | "0 -> %p, 1 -> %p, 2 -> %p\n", |
| 351 | mem_ptr0, mem_ptr1, mem_ptr2); |
| 352 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 353 | err = -EIO; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 354 | goto err_out_iounmap; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 355 | } |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 356 | db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */ |
| 357 | db_len = pci_resource_len(pdev, 4); |
| 358 | |
| 359 | if (db_len == 0) { |
| 360 | printk(KERN_ERR "%s: doorbell is disabled\n", |
| 361 | netxen_nic_driver_name); |
| 362 | err = -EIO; |
| 363 | goto err_out_iounmap; |
| 364 | } |
| 365 | DPRINTK(INFO, "doorbell ioremap from %lx a size of %lx\n", db_base, |
| 366 | db_len); |
| 367 | |
| 368 | db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES); |
Al Viro | a608ab9c | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 369 | if (!db_ptr) { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 370 | printk(KERN_ERR "%s: Failed to allocate doorbell map.", |
| 371 | netxen_nic_driver_name); |
| 372 | err = -EIO; |
| 373 | goto err_out_iounmap; |
| 374 | } |
| 375 | DPRINTK(INFO, "doorbell ioremaped at %p\n", db_ptr); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 376 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 377 | adapter->ahw.pci_base0 = mem_ptr0; |
| 378 | adapter->ahw.first_page_group_start = first_page_group_start; |
| 379 | adapter->ahw.first_page_group_end = first_page_group_end; |
| 380 | adapter->ahw.pci_base1 = mem_ptr1; |
| 381 | adapter->ahw.pci_base2 = mem_ptr2; |
| 382 | adapter->ahw.db_base = db_ptr; |
| 383 | adapter->ahw.db_len = db_len; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 384 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 385 | adapter->netdev = netdev; |
| 386 | adapter->pdev = pdev; |
dhananjay.phadke@gmail.com | 2d1a3bb | 2007-07-02 00:26:00 +0530 | [diff] [blame] | 387 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 388 | netif_napi_add(netdev, &adapter->napi, |
| 389 | netxen_nic_poll, NETXEN_NETDEV_WEIGHT); |
| 390 | |
dhananjay.phadke@gmail.com | 2d1a3bb | 2007-07-02 00:26:00 +0530 | [diff] [blame] | 391 | /* this will be read from FW later */ |
| 392 | adapter->intr_scheme = -1; |
Dhananjay Phadke | 443be79 | 2008-03-17 19:59:48 -0700 | [diff] [blame^] | 393 | adapter->msi_mode = -1; |
dhananjay.phadke@gmail.com | 2d1a3bb | 2007-07-02 00:26:00 +0530 | [diff] [blame] | 394 | |
| 395 | /* This will be reset for mezz cards */ |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 396 | adapter->portnum = pci_func_id; |
dhananjay.phadke@gmail.com | 2d1a3bb | 2007-07-02 00:26:00 +0530 | [diff] [blame] | 397 | adapter->status &= ~NETXEN_NETDEV_STATUS; |
Dhananjay Phadke | 200eef2 | 2007-09-03 10:33:35 +0530 | [diff] [blame] | 398 | adapter->rx_csum = 1; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 399 | |
| 400 | netdev->open = netxen_nic_open; |
| 401 | netdev->stop = netxen_nic_close; |
| 402 | netdev->hard_start_xmit = netxen_nic_xmit_frame; |
Jeff Garzik | 4790654 | 2007-11-23 21:23:36 -0500 | [diff] [blame] | 403 | netdev->get_stats = netxen_nic_get_stats; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 404 | netdev->set_multicast_list = netxen_nic_set_multi; |
| 405 | netdev->set_mac_address = netxen_nic_set_mac; |
| 406 | netdev->change_mtu = netxen_nic_change_mtu; |
| 407 | netdev->tx_timeout = netxen_tx_timeout; |
| 408 | netdev->watchdog_timeo = HZ; |
| 409 | |
| 410 | netxen_nic_change_mtu(netdev, netdev->mtu); |
| 411 | |
| 412 | SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 413 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 414 | netdev->poll_controller = netxen_nic_poll_controller; |
| 415 | #endif |
| 416 | /* ScatterGather support */ |
| 417 | netdev->features = NETIF_F_SG; |
| 418 | netdev->features |= NETIF_F_IP_CSUM; |
| 419 | netdev->features |= NETIF_F_TSO; |
| 420 | |
| 421 | if (pci_using_dac) |
| 422 | netdev->features |= NETIF_F_HIGHDMA; |
| 423 | |
dhananjay.phadke@gmail.com | 644caee | 2007-07-02 00:25:59 +0530 | [diff] [blame] | 424 | if (pci_enable_msi(pdev)) |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 425 | adapter->flags &= ~NETXEN_NIC_MSI_ENABLED; |
dhananjay.phadke@gmail.com | 644caee | 2007-07-02 00:25:59 +0530 | [diff] [blame] | 426 | else |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 427 | adapter->flags |= NETXEN_NIC_MSI_ENABLED; |
| 428 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 429 | netdev->irq = pdev->irq; |
| 430 | INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task); |
| 431 | |
| 432 | /* |
| 433 | * Set the CRB window to invalid. If any register in window 0 is |
| 434 | * accessed it should set the window to 0 and then reset it to 1. |
| 435 | */ |
| 436 | adapter->curr_window = 255; |
| 437 | |
| 438 | /* initialize the adapter */ |
| 439 | netxen_initialize_adapter_hw(adapter); |
| 440 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 441 | /* |
| 442 | * Adapter in our case is quad port so initialize it before |
| 443 | * initializing the ports |
| 444 | */ |
| 445 | |
| 446 | netxen_initialize_adapter_ops(adapter); |
| 447 | |
| 448 | adapter->max_tx_desc_count = MAX_CMD_DESCRIPTORS_HOST; |
| 449 | if ((adapter->ahw.boardcfg.board_type == NETXEN_BRDTYPE_P2_SB35_4G) || |
Jeff Garzik | 4790654 | 2007-11-23 21:23:36 -0500 | [diff] [blame] | 450 | (adapter->ahw.boardcfg.board_type == |
| 451 | NETXEN_BRDTYPE_P2_SB31_2G)) |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 452 | adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS_1G; |
| 453 | else |
| 454 | adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS; |
| 455 | adapter->max_jumbo_rx_desc_count = MAX_JUMBO_RCV_DESCRIPTORS; |
| 456 | adapter->max_lro_rx_desc_count = MAX_LRO_RCV_DESCRIPTORS; |
| 457 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 458 | cmd_buf_arr = (struct netxen_cmd_buffer *)vmalloc(TX_RINGSIZE); |
| 459 | if (cmd_buf_arr == NULL) { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 460 | printk(KERN_ERR |
| 461 | "%s: Could not allocate cmd_buf_arr memory:%d\n", |
| 462 | netxen_nic_driver_name, (int)TX_RINGSIZE); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 463 | err = -ENOMEM; |
| 464 | goto err_out_free_adapter; |
| 465 | } |
| 466 | memset(cmd_buf_arr, 0, TX_RINGSIZE); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 467 | adapter->cmd_buf_arr = cmd_buf_arr; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 468 | |
| 469 | for (i = 0; i < MAX_RCV_CTX; ++i) { |
| 470 | recv_ctx = &adapter->recv_ctx[i]; |
| 471 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) { |
| 472 | rcv_desc = &recv_ctx->rcv_desc[ring]; |
| 473 | switch (RCV_DESC_TYPE(ring)) { |
| 474 | case RCV_DESC_NORMAL: |
| 475 | rcv_desc->max_rx_desc_count = |
| 476 | adapter->max_rx_desc_count; |
| 477 | rcv_desc->flags = RCV_DESC_NORMAL; |
| 478 | rcv_desc->dma_size = RX_DMA_MAP_LEN; |
| 479 | rcv_desc->skb_size = MAX_RX_BUFFER_LENGTH; |
| 480 | break; |
| 481 | |
| 482 | case RCV_DESC_JUMBO: |
| 483 | rcv_desc->max_rx_desc_count = |
| 484 | adapter->max_jumbo_rx_desc_count; |
| 485 | rcv_desc->flags = RCV_DESC_JUMBO; |
| 486 | rcv_desc->dma_size = RX_JUMBO_DMA_MAP_LEN; |
| 487 | rcv_desc->skb_size = MAX_RX_JUMBO_BUFFER_LENGTH; |
| 488 | break; |
| 489 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 490 | case RCV_RING_LRO: |
| 491 | rcv_desc->max_rx_desc_count = |
| 492 | adapter->max_lro_rx_desc_count; |
| 493 | rcv_desc->flags = RCV_DESC_LRO; |
| 494 | rcv_desc->dma_size = RX_LRO_DMA_MAP_LEN; |
| 495 | rcv_desc->skb_size = MAX_RX_LRO_BUFFER_LENGTH; |
| 496 | break; |
| 497 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 498 | } |
| 499 | rcv_desc->rx_buf_arr = (struct netxen_rx_buffer *) |
| 500 | vmalloc(RCV_BUFFSIZE); |
| 501 | |
| 502 | if (rcv_desc->rx_buf_arr == NULL) { |
Joe Perches | 5bc5142 | 2007-11-19 17:48:24 -0800 | [diff] [blame] | 503 | printk(KERN_ERR "%s: Could not allocate " |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 504 | "rcv_desc->rx_buf_arr memory:%d\n", |
| 505 | netxen_nic_driver_name, |
| 506 | (int)RCV_BUFFSIZE); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 507 | err = -ENOMEM; |
| 508 | goto err_out_free_rx_buffer; |
| 509 | } |
| 510 | memset(rcv_desc->rx_buf_arr, 0, RCV_BUFFSIZE); |
| 511 | } |
| 512 | |
| 513 | } |
| 514 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 515 | netxen_initialize_adapter_sw(adapter); /* initialize the buffers in adapter */ |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 516 | |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 517 | /* Mezz cards have PCI function 0,2,3 enabled */ |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 518 | if ((adapter->ahw.boardcfg.board_type == NETXEN_BRDTYPE_P2_SB31_10G_IMEZ) |
| 519 | && (pci_func_id >= 2)) |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 520 | adapter->portnum = pci_func_id - 2; |
| 521 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 522 | #ifdef CONFIG_IA64 |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 523 | if(adapter->portnum == 0) { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 524 | netxen_pinit_from_rom(adapter, 0); |
| 525 | udelay(500); |
| 526 | netxen_load_firmware(adapter); |
| 527 | } |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 528 | #endif |
| 529 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 530 | init_timer(&adapter->watchdog_timer); |
| 531 | adapter->ahw.xg_linkup = 0; |
| 532 | adapter->watchdog_timer.function = &netxen_watchdog; |
| 533 | adapter->watchdog_timer.data = (unsigned long)adapter; |
David Howells | 6d5aefb | 2006-12-05 19:36:26 +0000 | [diff] [blame] | 534 | INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 535 | adapter->ahw.pdev = pdev; |
| 536 | adapter->proc_cmd_buf_counter = 0; |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 537 | adapter->ahw.revision_id = pdev->revision; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 538 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 539 | /* make sure Window == 1 */ |
| 540 | netxen_nic_pci_change_crbwindow(adapter, 1); |
| 541 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 542 | netxen_nic_update_cmd_producer(adapter, 0); |
| 543 | netxen_nic_update_cmd_consumer(adapter, 0); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 544 | writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_HOST_CMD_ADDR_LO)); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 545 | |
| 546 | if (netxen_is_flash_supported(adapter) == 0 && |
| 547 | netxen_get_flash_mac_addr(adapter, mac_addr) == 0) |
| 548 | valid_mac = 1; |
| 549 | else |
| 550 | valid_mac = 0; |
| 551 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 552 | if (valid_mac) { |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 553 | unsigned char *p = (unsigned char *)&mac_addr[adapter->portnum]; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 554 | netdev->dev_addr[0] = *(p + 5); |
| 555 | netdev->dev_addr[1] = *(p + 4); |
| 556 | netdev->dev_addr[2] = *(p + 3); |
| 557 | netdev->dev_addr[3] = *(p + 2); |
| 558 | netdev->dev_addr[4] = *(p + 1); |
| 559 | netdev->dev_addr[5] = *(p + 0); |
| 560 | |
| 561 | memcpy(netdev->perm_addr, netdev->dev_addr, |
| 562 | netdev->addr_len); |
| 563 | if (!is_valid_ether_addr(netdev->perm_addr)) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 564 | printk(KERN_ERR "%s: Bad MAC address %s.\n", |
| 565 | netxen_nic_driver_name, |
| 566 | print_mac(mac, netdev->dev_addr)); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 567 | } else { |
| 568 | if (adapter->macaddr_set) |
| 569 | adapter->macaddr_set(adapter, |
| 570 | netdev->dev_addr); |
| 571 | } |
| 572 | } |
| 573 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 574 | if (adapter->portnum == 0) { |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 575 | err = netxen_initialize_adapter_offload(adapter); |
Jeff Garzik | 4790654 | 2007-11-23 21:23:36 -0500 | [diff] [blame] | 576 | if (err) |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 577 | goto err_out_free_rx_buffer; |
Jeff Garzik | 4790654 | 2007-11-23 21:23:36 -0500 | [diff] [blame] | 578 | val = readl(NETXEN_CRB_NORMALIZE(adapter, |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 579 | NETXEN_CAM_RAM(0x1fc))); |
| 580 | if (val == 0x55555555) { |
| 581 | /* This is the first boot after power up */ |
dhananjay.phadke@gmail.com | 644caee | 2007-07-02 00:25:59 +0530 | [diff] [blame] | 582 | netxen_nic_read_w0(adapter, NETXEN_PCIE_REG(0x4), &val); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 583 | if (!(val & 0x4)) { |
| 584 | val |= 0x4; |
| 585 | netxen_nic_write_w0(adapter, NETXEN_PCIE_REG(0x4), val); |
| 586 | netxen_nic_read_w0(adapter, NETXEN_PCIE_REG(0x4), &val); |
| 587 | if (!(val & 0x4)) |
| 588 | printk(KERN_ERR "%s: failed to set MSI bit in PCI-e reg\n", |
| 589 | netxen_nic_driver_name); |
| 590 | } |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 591 | val = readl(NETXEN_CRB_NORMALIZE(adapter, |
| 592 | NETXEN_ROMUSB_GLB_SW_RESET)); |
| 593 | printk(KERN_INFO"NetXen: read 0x%08x for reset reg.\n",val); |
| 594 | if (val != 0x80000f) { |
| 595 | /* clear the register for future unloads/loads */ |
dhananjay.phadke@gmail.com | 644caee | 2007-07-02 00:25:59 +0530 | [diff] [blame] | 596 | writel(0, NETXEN_CRB_NORMALIZE(adapter, |
| 597 | NETXEN_CAM_RAM(0x1fc))); |
| 598 | printk(KERN_ERR "ERROR in NetXen HW init sequence.\n"); |
| 599 | err = -ENODEV; |
| 600 | goto err_out_free_dev; |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 601 | } |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 602 | } |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 603 | |
| 604 | /* clear the register for future unloads/loads */ |
| 605 | writel(0, NETXEN_CRB_NORMALIZE(adapter, NETXEN_CAM_RAM(0x1fc))); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 606 | printk(KERN_INFO "State: 0x%0x\n", |
| 607 | readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE))); |
| 608 | |
| 609 | /* |
| 610 | * Tell the hardware our version number. |
| 611 | */ |
Jeff Garzik | 4790654 | 2007-11-23 21:23:36 -0500 | [diff] [blame] | 612 | i = (_NETXEN_NIC_LINUX_MAJOR << 16) |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 613 | | ((_NETXEN_NIC_LINUX_MINOR << 8)) |
| 614 | | (_NETXEN_NIC_LINUX_SUBVERSION); |
| 615 | writel(i, NETXEN_CRB_NORMALIZE(adapter, CRB_DRIVER_VERSION)); |
| 616 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 617 | /* Unlock the HW, prompting the boot sequence */ |
| 618 | writel(1, |
| 619 | NETXEN_CRB_NORMALIZE(adapter, |
| 620 | NETXEN_ROMUSB_GLB_PEGTUNE_DONE)); |
| 621 | /* Handshake with the card before we register the devices. */ |
| 622 | netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 623 | } |
| 624 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 625 | /* |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 626 | * See if the firmware gave us a virtual-physical port mapping. |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 627 | */ |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 628 | i = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_V2P(adapter->portnum))); |
| 629 | if (i != 0x55555555) |
| 630 | physical_port[adapter->portnum] = i; |
| 631 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 632 | netif_carrier_off(netdev); |
| 633 | netif_stop_queue(netdev); |
| 634 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 635 | if ((err = register_netdev(netdev))) { |
| 636 | printk(KERN_ERR "%s: register_netdev failed port #%d" |
| 637 | " aborting\n", netxen_nic_driver_name, |
| 638 | adapter->portnum); |
| 639 | err = -EIO; |
| 640 | goto err_out_free_dev; |
| 641 | } |
| 642 | |
| 643 | pci_set_drvdata(pdev, adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 644 | |
| 645 | switch (adapter->ahw.board_type) { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 646 | case NETXEN_NIC_GBE: |
| 647 | printk(KERN_INFO "%s: QUAD GbE board initialized\n", |
| 648 | netxen_nic_driver_name); |
| 649 | break; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 650 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 651 | case NETXEN_NIC_XGBE: |
Jeff Garzik | 4790654 | 2007-11-23 21:23:36 -0500 | [diff] [blame] | 652 | printk(KERN_INFO "%s: XGbE board initialized\n", |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 653 | netxen_nic_driver_name); |
| 654 | break; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | adapter->driver_mismatch = 0; |
| 658 | |
| 659 | return 0; |
| 660 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 661 | err_out_free_dev: |
| 662 | if (adapter->portnum == 0) |
| 663 | netxen_free_adapter_offload(adapter); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 664 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 665 | err_out_free_rx_buffer: |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 666 | for (i = 0; i < MAX_RCV_CTX; ++i) { |
| 667 | recv_ctx = &adapter->recv_ctx[i]; |
| 668 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) { |
| 669 | rcv_desc = &recv_ctx->rcv_desc[ring]; |
| 670 | if (rcv_desc->rx_buf_arr != NULL) { |
| 671 | vfree(rcv_desc->rx_buf_arr); |
| 672 | rcv_desc->rx_buf_arr = NULL; |
| 673 | } |
| 674 | } |
| 675 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 676 | vfree(cmd_buf_arr); |
| 677 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 678 | err_out_free_adapter: |
| 679 | if (adapter->flags & NETXEN_NIC_MSI_ENABLED) |
| 680 | pci_disable_msi(pdev); |
| 681 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 682 | pci_set_drvdata(pdev, NULL); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 683 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 684 | if (db_ptr) |
| 685 | iounmap(db_ptr); |
| 686 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 687 | err_out_iounmap: |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 688 | if (mem_ptr0) |
| 689 | iounmap(mem_ptr0); |
| 690 | if (mem_ptr1) |
| 691 | iounmap(mem_ptr1); |
| 692 | if (mem_ptr2) |
| 693 | iounmap(mem_ptr2); |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 694 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 695 | err_out_free_netdev: |
| 696 | free_netdev(netdev); |
| 697 | |
| 698 | err_out_free_res: |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 699 | pci_release_regions(pdev); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 700 | |
| 701 | err_out_disable_pdev: |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 702 | pci_disable_device(pdev); |
| 703 | return err; |
| 704 | } |
| 705 | |
| 706 | static void __devexit netxen_nic_remove(struct pci_dev *pdev) |
| 707 | { |
| 708 | struct netxen_adapter *adapter; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 709 | struct net_device *netdev; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 710 | struct netxen_rx_buffer *buffer; |
| 711 | struct netxen_recv_context *recv_ctx; |
| 712 | struct netxen_rcv_desc_ctx *rcv_desc; |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 713 | int i, ctxid, ring; |
| 714 | static int init_firmware_done = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 715 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 716 | adapter = pci_get_drvdata(pdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 717 | if (adapter == NULL) |
| 718 | return; |
| 719 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 720 | netdev = adapter->netdev; |
| 721 | |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 722 | unregister_netdev(netdev); |
| 723 | |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 724 | if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) { |
| 725 | init_firmware_done++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 726 | netxen_free_hw_resources(adapter); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 727 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 728 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 729 | for (ctxid = 0; ctxid < MAX_RCV_CTX; ++ctxid) { |
| 730 | recv_ctx = &adapter->recv_ctx[ctxid]; |
| 731 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) { |
| 732 | rcv_desc = &recv_ctx->rcv_desc[ring]; |
| 733 | for (i = 0; i < rcv_desc->max_rx_desc_count; ++i) { |
| 734 | buffer = &(rcv_desc->rx_buf_arr[i]); |
| 735 | if (buffer->state == NETXEN_BUFFER_FREE) |
| 736 | continue; |
| 737 | pci_unmap_single(pdev, buffer->dma, |
| 738 | rcv_desc->dma_size, |
| 739 | PCI_DMA_FROMDEVICE); |
| 740 | if (buffer->skb != NULL) |
| 741 | dev_kfree_skb_any(buffer->skb); |
| 742 | } |
| 743 | vfree(rcv_desc->rx_buf_arr); |
| 744 | } |
| 745 | } |
| 746 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 747 | vfree(adapter->cmd_buf_arr); |
| 748 | |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 749 | if (adapter->portnum == 0) { |
| 750 | if (init_firmware_done) { |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 751 | i = 100; |
dhananjay@netxen.com | ceded32 | 2007-07-19 14:41:09 +0530 | [diff] [blame] | 752 | do { |
| 753 | if (dma_watchdog_shutdown_request(adapter) == 1) |
| 754 | break; |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 755 | msleep(100); |
dhananjay@netxen.com | ceded32 | 2007-07-19 14:41:09 +0530 | [diff] [blame] | 756 | if (dma_watchdog_shutdown_poll_result(adapter) == 1) |
| 757 | break; |
| 758 | } while (--i); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 759 | |
dhananjay@netxen.com | ceded32 | 2007-07-19 14:41:09 +0530 | [diff] [blame] | 760 | if (i == 0) |
| 761 | printk(KERN_ERR "%s: dma_watchdog_shutdown failed\n", |
| 762 | netdev->name); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 763 | |
| 764 | /* clear the register for future unloads/loads */ |
| 765 | writel(0, NETXEN_CRB_NORMALIZE(adapter, NETXEN_CAM_RAM(0x1fc))); |
| 766 | printk(KERN_INFO "State: 0x%0x\n", |
| 767 | readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE))); |
| 768 | |
| 769 | /* leave the hw in the same state as reboot */ |
| 770 | writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE)); |
dhananjay@netxen.com | ceded32 | 2007-07-19 14:41:09 +0530 | [diff] [blame] | 771 | netxen_pinit_from_rom(adapter, 0); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 772 | msleep(1); |
dhananjay@netxen.com | ceded32 | 2007-07-19 14:41:09 +0530 | [diff] [blame] | 773 | netxen_load_firmware(adapter); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 774 | netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE); |
| 775 | } |
| 776 | |
| 777 | /* clear the register for future unloads/loads */ |
| 778 | writel(0, NETXEN_CRB_NORMALIZE(adapter, NETXEN_CAM_RAM(0x1fc))); |
| 779 | printk(KERN_INFO "State: 0x%0x\n", |
| 780 | readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE))); |
| 781 | |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 782 | i = 100; |
dhananjay@netxen.com | ceded32 | 2007-07-19 14:41:09 +0530 | [diff] [blame] | 783 | do { |
| 784 | if (dma_watchdog_shutdown_request(adapter) == 1) |
| 785 | break; |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 786 | msleep(100); |
dhananjay@netxen.com | ceded32 | 2007-07-19 14:41:09 +0530 | [diff] [blame] | 787 | if (dma_watchdog_shutdown_poll_result(adapter) == 1) |
| 788 | break; |
| 789 | } while (--i); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 790 | |
| 791 | if (i) { |
| 792 | netxen_free_adapter_offload(adapter); |
| 793 | } else { |
dhananjay@netxen.com | ceded32 | 2007-07-19 14:41:09 +0530 | [diff] [blame] | 794 | printk(KERN_ERR "%s: dma_watchdog_shutdown failed\n", |
| 795 | netdev->name); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 796 | } |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 797 | } |
| 798 | |
dhananjay@netxen.com | 3052246 | 2007-08-28 17:23:26 +0530 | [diff] [blame] | 799 | if (adapter->irq) |
| 800 | free_irq(adapter->irq, adapter); |
| 801 | |
| 802 | if (adapter->flags & NETXEN_NIC_MSI_ENABLED) |
| 803 | pci_disable_msi(pdev); |
| 804 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 805 | iounmap(adapter->ahw.db_base); |
| 806 | iounmap(adapter->ahw.pci_base0); |
| 807 | iounmap(adapter->ahw.pci_base1); |
| 808 | iounmap(adapter->ahw.pci_base2); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 809 | |
| 810 | pci_release_regions(pdev); |
dhananjay@netxen.com | 3052246 | 2007-08-28 17:23:26 +0530 | [diff] [blame] | 811 | pci_disable_device(pdev); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 812 | pci_set_drvdata(pdev, NULL); |
| 813 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 814 | free_netdev(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | /* |
| 818 | * Called when a network interface is made active |
| 819 | * @returns 0 on success, negative value on failure |
| 820 | */ |
| 821 | static int netxen_nic_open(struct net_device *netdev) |
| 822 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 823 | struct netxen_adapter *adapter = (struct netxen_adapter *)netdev->priv; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 824 | int err = 0; |
| 825 | int ctx, ring; |
| 826 | |
| 827 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) { |
| 828 | err = netxen_init_firmware(adapter); |
| 829 | if (err != 0) { |
| 830 | printk(KERN_ERR "Failed to init firmware\n"); |
| 831 | return -EIO; |
| 832 | } |
| 833 | netxen_nic_flash_print(adapter); |
| 834 | |
| 835 | /* setup all the resources for the Phantom... */ |
| 836 | /* this include the descriptors for rcv, tx, and status */ |
| 837 | netxen_nic_clear_stats(adapter); |
| 838 | err = netxen_nic_hw_resources(adapter); |
| 839 | if (err) { |
| 840 | printk(KERN_ERR "Error in setting hw resources:%d\n", |
| 841 | err); |
| 842 | return err; |
| 843 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 844 | for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) { |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 845 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 846 | netxen_post_rx_buffers(adapter, ctx, ring); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 847 | } |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 848 | adapter->irq = adapter->ahw.pdev->irq; |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 849 | err = request_irq(adapter->ahw.pdev->irq, netxen_intr, |
Andrew Morton | 1c8e039 | 2007-05-10 22:53:00 -0700 | [diff] [blame] | 850 | IRQF_SHARED|IRQF_SAMPLE_RANDOM, netdev->name, |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 851 | adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 852 | if (err) { |
| 853 | printk(KERN_ERR "request_irq failed with: %d\n", err); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 854 | netxen_free_hw_resources(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 855 | return err; |
| 856 | } |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 857 | |
| 858 | adapter->is_up = NETXEN_ADAPTER_UP_MAGIC; |
| 859 | } |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 860 | if (!adapter->driver_mismatch) |
| 861 | mod_timer(&adapter->watchdog_timer, jiffies); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 862 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 863 | napi_enable(&adapter->napi); |
| 864 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 865 | netxen_nic_enable_int(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 866 | |
| 867 | /* Done here again so that even if phantom sw overwrote it, |
| 868 | * we set it */ |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 869 | if (adapter->init_port |
| 870 | && adapter->init_port(adapter, adapter->portnum) != 0) { |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 871 | del_timer_sync(&adapter->watchdog_timer); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 872 | printk(KERN_ERR "%s: Failed to initialize port %d\n", |
| 873 | netxen_nic_driver_name, adapter->portnum); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 874 | napi_disable(&adapter->napi); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 875 | return -EIO; |
| 876 | } |
dhananjay@netxen.com | 7eec517 | 2007-07-25 20:13:11 +0530 | [diff] [blame] | 877 | if (adapter->macaddr_set) |
| 878 | adapter->macaddr_set(adapter, netdev->dev_addr); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 879 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 880 | netxen_nic_set_link_parameters(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 881 | |
| 882 | netxen_nic_set_multi(netdev); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 883 | if (adapter->set_mtu) |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 884 | adapter->set_mtu(adapter, netdev->mtu); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 885 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 886 | if (!adapter->driver_mismatch) |
| 887 | netif_start_queue(netdev); |
| 888 | |
| 889 | return 0; |
| 890 | } |
| 891 | |
| 892 | /* |
| 893 | * netxen_nic_close - Disables a network interface entry point |
| 894 | */ |
| 895 | static int netxen_nic_close(struct net_device *netdev) |
| 896 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 897 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 898 | int i, j; |
| 899 | struct netxen_cmd_buffer *cmd_buff; |
| 900 | struct netxen_skb_frag *buffrag; |
| 901 | |
| 902 | netif_carrier_off(netdev); |
| 903 | netif_stop_queue(netdev); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 904 | napi_disable(&adapter->napi); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 905 | |
dhananjay@netxen.com | 72b0a7a | 2007-12-26 10:23:56 -0800 | [diff] [blame] | 906 | if (adapter->stop_port) |
| 907 | adapter->stop_port(adapter); |
| 908 | |
dhananjay@netxen.com | e01872af | 2007-07-25 20:13:12 +0530 | [diff] [blame] | 909 | netxen_nic_disable_int(adapter); |
| 910 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 911 | cmd_buff = adapter->cmd_buf_arr; |
| 912 | for (i = 0; i < adapter->max_tx_desc_count; i++) { |
| 913 | buffrag = cmd_buff->frag_array; |
| 914 | if (buffrag->dma) { |
| 915 | pci_unmap_single(adapter->pdev, buffrag->dma, |
| 916 | buffrag->length, PCI_DMA_TODEVICE); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 917 | buffrag->dma = 0ULL; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 918 | } |
| 919 | for (j = 0; j < cmd_buff->frag_count; j++) { |
| 920 | buffrag++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 921 | if (buffrag->dma) { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 922 | pci_unmap_page(adapter->pdev, buffrag->dma, |
Jeff Garzik | 4790654 | 2007-11-23 21:23:36 -0500 | [diff] [blame] | 923 | buffrag->length, |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 924 | PCI_DMA_TODEVICE); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 925 | buffrag->dma = 0ULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 926 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 927 | } |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 928 | /* Free the skb we received in netxen_nic_xmit_frame */ |
| 929 | if (cmd_buff->skb) { |
| 930 | dev_kfree_skb_any(cmd_buff->skb); |
| 931 | cmd_buff->skb = NULL; |
| 932 | } |
| 933 | cmd_buff++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 934 | } |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 935 | if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) { |
| 936 | FLUSH_SCHEDULED_WORK(); |
| 937 | del_timer_sync(&adapter->watchdog_timer); |
| 938 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 939 | |
| 940 | return 0; |
| 941 | } |
| 942 | |
| 943 | static int netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
| 944 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 945 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 946 | struct netxen_hardware_context *hw = &adapter->ahw; |
| 947 | unsigned int first_seg_len = skb->len - skb->data_len; |
| 948 | struct netxen_skb_frag *buffrag; |
| 949 | unsigned int i; |
| 950 | |
| 951 | u32 producer = 0; |
| 952 | u32 saved_producer = 0; |
| 953 | struct cmd_desc_type0 *hwdesc; |
| 954 | int k; |
| 955 | struct netxen_cmd_buffer *pbuf = NULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 956 | static int dropped_packet = 0; |
| 957 | int frag_count; |
| 958 | u32 local_producer = 0; |
| 959 | u32 max_tx_desc_count = 0; |
| 960 | u32 last_cmd_consumer = 0; |
| 961 | int no_of_desc; |
| 962 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 963 | adapter->stats.xmitcalled++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 964 | frag_count = skb_shinfo(skb)->nr_frags + 1; |
| 965 | |
| 966 | if (unlikely(skb->len <= 0)) { |
| 967 | dev_kfree_skb_any(skb); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 968 | adapter->stats.badskblen++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 969 | return NETDEV_TX_OK; |
| 970 | } |
| 971 | |
| 972 | if (frag_count > MAX_BUFFERS_PER_CMD) { |
Joe Perches | 5bc5142 | 2007-11-19 17:48:24 -0800 | [diff] [blame] | 973 | printk("%s: %s netxen_nic_xmit_frame: frag_count (%d) " |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 974 | "too large, can handle only %d frags\n", |
| 975 | netxen_nic_driver_name, netdev->name, |
| 976 | frag_count, MAX_BUFFERS_PER_CMD); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 977 | adapter->stats.txdropped++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 978 | if ((++dropped_packet & 0xff) == 0xff) |
| 979 | printk("%s: %s droppped packets = %d\n", |
| 980 | netxen_nic_driver_name, netdev->name, |
| 981 | dropped_packet); |
| 982 | |
| 983 | return NETDEV_TX_OK; |
| 984 | } |
| 985 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 986 | /* There 4 fragments per descriptor */ |
| 987 | no_of_desc = (frag_count + 3) >> 2; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 988 | if (netdev->features & NETIF_F_TSO) { |
| 989 | if (skb_shinfo(skb)->gso_size > 0) { |
| 990 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 991 | no_of_desc++; |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 992 | if ((ip_hdrlen(skb) + tcp_hdrlen(skb) + |
Arnaldo Carvalho de Melo | c9bdd4b | 2007-03-12 20:09:15 -0300 | [diff] [blame] | 993 | sizeof(struct ethhdr)) > |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 994 | (sizeof(struct cmd_desc_type0) - 2)) { |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 995 | no_of_desc++; |
| 996 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 997 | } |
| 998 | } |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 999 | |
| 1000 | spin_lock_bh(&adapter->tx_lock); |
| 1001 | if (adapter->total_threads >= MAX_XMIT_PRODUCERS) { |
| 1002 | goto out_requeue; |
| 1003 | } |
| 1004 | local_producer = adapter->cmd_producer; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1005 | k = adapter->cmd_producer; |
| 1006 | max_tx_desc_count = adapter->max_tx_desc_count; |
| 1007 | last_cmd_consumer = adapter->last_cmd_consumer; |
| 1008 | if ((k + no_of_desc) >= |
| 1009 | ((last_cmd_consumer <= k) ? last_cmd_consumer + max_tx_desc_count : |
| 1010 | last_cmd_consumer)) { |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 1011 | goto out_requeue; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1012 | } |
| 1013 | k = get_index_range(k, max_tx_desc_count, no_of_desc); |
| 1014 | adapter->cmd_producer = k; |
| 1015 | adapter->total_threads++; |
| 1016 | adapter->num_threads++; |
| 1017 | |
| 1018 | spin_unlock_bh(&adapter->tx_lock); |
| 1019 | /* Copy the descriptors into the hardware */ |
| 1020 | producer = local_producer; |
| 1021 | saved_producer = producer; |
| 1022 | hwdesc = &hw->cmd_desc_head[producer]; |
| 1023 | memset(hwdesc, 0, sizeof(struct cmd_desc_type0)); |
| 1024 | /* Take skb->data itself */ |
| 1025 | pbuf = &adapter->cmd_buf_arr[producer]; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 1026 | if ((netdev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size > 0) { |
Al Viro | a608ab9c | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 1027 | pbuf->mss = skb_shinfo(skb)->gso_size; |
Amit S. Kale | ed33ebe | 2006-12-18 05:53:59 -0800 | [diff] [blame] | 1028 | hwdesc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1029 | } else { |
| 1030 | pbuf->mss = 0; |
| 1031 | hwdesc->mss = 0; |
| 1032 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1033 | pbuf->total_length = skb->len; |
| 1034 | pbuf->skb = skb; |
| 1035 | pbuf->cmd = TX_ETHER_PKT; |
| 1036 | pbuf->frag_count = frag_count; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1037 | pbuf->port = adapter->portnum; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1038 | buffrag = &pbuf->frag_array[0]; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1039 | buffrag->dma = pci_map_single(adapter->pdev, skb->data, first_seg_len, |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1040 | PCI_DMA_TODEVICE); |
| 1041 | buffrag->length = first_seg_len; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1042 | netxen_set_cmd_desc_totallength(hwdesc, skb->len); |
| 1043 | netxen_set_cmd_desc_num_of_buff(hwdesc, frag_count); |
| 1044 | netxen_set_cmd_desc_opcode(hwdesc, TX_ETHER_PKT); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1045 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1046 | netxen_set_cmd_desc_port(hwdesc, adapter->portnum); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1047 | netxen_set_cmd_desc_ctxid(hwdesc, adapter->portnum); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1048 | hwdesc->buffer1_length = cpu_to_le16(first_seg_len); |
| 1049 | hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma); |
| 1050 | |
| 1051 | for (i = 1, k = 1; i < frag_count; i++, k++) { |
| 1052 | struct skb_frag_struct *frag; |
| 1053 | int len, temp_len; |
| 1054 | unsigned long offset; |
| 1055 | dma_addr_t temp_dma; |
| 1056 | |
| 1057 | /* move to next desc. if there is a need */ |
| 1058 | if ((i & 0x3) == 0) { |
| 1059 | k = 0; |
| 1060 | producer = get_next_index(producer, |
| 1061 | adapter->max_tx_desc_count); |
| 1062 | hwdesc = &hw->cmd_desc_head[producer]; |
| 1063 | memset(hwdesc, 0, sizeof(struct cmd_desc_type0)); |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 1064 | pbuf = &adapter->cmd_buf_arr[producer]; |
| 1065 | pbuf->skb = NULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1066 | } |
| 1067 | frag = &skb_shinfo(skb)->frags[i - 1]; |
| 1068 | len = frag->size; |
| 1069 | offset = frag->page_offset; |
| 1070 | |
| 1071 | temp_len = len; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1072 | temp_dma = pci_map_page(adapter->pdev, frag->page, offset, |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1073 | len, PCI_DMA_TODEVICE); |
| 1074 | |
| 1075 | buffrag++; |
| 1076 | buffrag->dma = temp_dma; |
| 1077 | buffrag->length = temp_len; |
| 1078 | |
| 1079 | DPRINTK(INFO, "for loop. i=%d k=%d\n", i, k); |
| 1080 | switch (k) { |
| 1081 | case 0: |
| 1082 | hwdesc->buffer1_length = cpu_to_le16(temp_len); |
| 1083 | hwdesc->addr_buffer1 = cpu_to_le64(temp_dma); |
| 1084 | break; |
| 1085 | case 1: |
| 1086 | hwdesc->buffer2_length = cpu_to_le16(temp_len); |
| 1087 | hwdesc->addr_buffer2 = cpu_to_le64(temp_dma); |
| 1088 | break; |
| 1089 | case 2: |
| 1090 | hwdesc->buffer3_length = cpu_to_le16(temp_len); |
| 1091 | hwdesc->addr_buffer3 = cpu_to_le64(temp_dma); |
| 1092 | break; |
| 1093 | case 3: |
Al Viro | a608ab9c | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 1094 | hwdesc->buffer4_length = cpu_to_le16(temp_len); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1095 | hwdesc->addr_buffer4 = cpu_to_le64(temp_dma); |
| 1096 | break; |
| 1097 | } |
| 1098 | frag++; |
| 1099 | } |
| 1100 | producer = get_next_index(producer, adapter->max_tx_desc_count); |
| 1101 | |
| 1102 | /* might change opcode to TX_TCP_LSO */ |
| 1103 | netxen_tso_check(adapter, &hw->cmd_desc_head[saved_producer], skb); |
| 1104 | |
| 1105 | /* For LSO, we need to copy the MAC/IP/TCP headers into |
| 1106 | * the descriptor ring |
| 1107 | */ |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1108 | if (netxen_get_cmd_desc_opcode(&hw->cmd_desc_head[saved_producer]) |
| 1109 | == TX_TCP_LSO) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1110 | int hdr_len, first_hdr_len, more_hdr; |
| 1111 | hdr_len = hw->cmd_desc_head[saved_producer].total_hdr_length; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1112 | if (hdr_len > (sizeof(struct cmd_desc_type0) - 2)) { |
| 1113 | first_hdr_len = sizeof(struct cmd_desc_type0) - 2; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1114 | more_hdr = 1; |
| 1115 | } else { |
| 1116 | first_hdr_len = hdr_len; |
| 1117 | more_hdr = 0; |
| 1118 | } |
| 1119 | /* copy the MAC/IP/TCP headers to the cmd descriptor list */ |
| 1120 | hwdesc = &hw->cmd_desc_head[producer]; |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 1121 | pbuf = &adapter->cmd_buf_arr[producer]; |
| 1122 | pbuf->skb = NULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1123 | |
| 1124 | /* copy the first 64 bytes */ |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1125 | memcpy(((void *)hwdesc) + 2, |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1126 | (void *)(skb->data), first_hdr_len); |
| 1127 | producer = get_next_index(producer, max_tx_desc_count); |
| 1128 | |
| 1129 | if (more_hdr) { |
| 1130 | hwdesc = &hw->cmd_desc_head[producer]; |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 1131 | pbuf = &adapter->cmd_buf_arr[producer]; |
| 1132 | pbuf->skb = NULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1133 | /* copy the next 64 bytes - should be enough except |
| 1134 | * for pathological case |
| 1135 | */ |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 1136 | skb_copy_from_linear_data_offset(skb, first_hdr_len, |
| 1137 | hwdesc, |
| 1138 | (hdr_len - |
| 1139 | first_hdr_len)); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1140 | producer = get_next_index(producer, max_tx_desc_count); |
| 1141 | } |
| 1142 | } |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1143 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1144 | spin_lock_bh(&adapter->tx_lock); |
Dhananjay Phadke | 5dc1626 | 2007-12-31 10:08:57 -0800 | [diff] [blame] | 1145 | adapter->stats.txbytes += skb->len; |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1146 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1147 | /* Code to update the adapter considering how many producer threads |
| 1148 | are currently working */ |
| 1149 | if ((--adapter->num_threads) == 0) { |
| 1150 | /* This is the last thread */ |
| 1151 | u32 crb_producer = adapter->cmd_producer; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1152 | netxen_nic_update_cmd_producer(adapter, crb_producer); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1153 | wmb(); |
| 1154 | adapter->total_threads = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1155 | } |
| 1156 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1157 | adapter->stats.xmitfinished++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1158 | netdev->trans_start = jiffies; |
| 1159 | |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 1160 | spin_unlock_bh(&adapter->tx_lock); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1161 | return NETDEV_TX_OK; |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 1162 | |
| 1163 | out_requeue: |
| 1164 | netif_stop_queue(netdev); |
| 1165 | adapter->flags |= NETXEN_NETDEV_STATUS; |
| 1166 | |
| 1167 | spin_unlock_bh(&adapter->tx_lock); |
| 1168 | return NETDEV_TX_BUSY; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1169 | } |
| 1170 | |
| 1171 | static void netxen_watchdog(unsigned long v) |
| 1172 | { |
| 1173 | struct netxen_adapter *adapter = (struct netxen_adapter *)v; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1174 | |
| 1175 | SCHEDULE_WORK(&adapter->watchdog_task); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1176 | } |
| 1177 | |
| 1178 | static void netxen_tx_timeout(struct net_device *netdev) |
| 1179 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1180 | struct netxen_adapter *adapter = (struct netxen_adapter *) |
| 1181 | netdev_priv(netdev); |
| 1182 | SCHEDULE_WORK(&adapter->tx_timeout_task); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1183 | } |
| 1184 | |
David Howells | 6d5aefb | 2006-12-05 19:36:26 +0000 | [diff] [blame] | 1185 | static void netxen_tx_timeout_task(struct work_struct *work) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1186 | { |
Jeff Garzik | 4790654 | 2007-11-23 21:23:36 -0500 | [diff] [blame] | 1187 | struct netxen_adapter *adapter = |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1188 | container_of(work, struct netxen_adapter, tx_timeout_task); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1189 | |
| 1190 | printk(KERN_ERR "%s %s: transmit timeout, resetting.\n", |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1191 | netxen_nic_driver_name, adapter->netdev->name); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1192 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1193 | netxen_nic_close(adapter->netdev); |
| 1194 | netxen_nic_open(adapter->netdev); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1195 | adapter->netdev->trans_start = jiffies; |
| 1196 | netif_wake_queue(adapter->netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1197 | } |
| 1198 | |
| 1199 | static int |
| 1200 | netxen_handle_int(struct netxen_adapter *adapter, struct net_device *netdev) |
| 1201 | { |
| 1202 | u32 ret = 0; |
| 1203 | |
| 1204 | DPRINTK(INFO, "Entered handle ISR\n"); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 1205 | adapter->stats.ints++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1206 | |
dhananjay.phadke@gmail.com | 2d1a3bb | 2007-07-02 00:26:00 +0530 | [diff] [blame] | 1207 | netxen_nic_disable_int(adapter); |
| 1208 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1209 | if (netxen_nic_rx_has_work(adapter) || netxen_nic_tx_has_work(adapter)) { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1210 | if (netif_rx_schedule_prep(netdev, &adapter->napi)) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1211 | /* |
| 1212 | * Interrupts are already disabled. |
| 1213 | */ |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1214 | __netif_rx_schedule(netdev, &adapter->napi); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1215 | } else { |
| 1216 | static unsigned int intcount = 0; |
| 1217 | if ((++intcount & 0xfff) == 0xfff) |
dhananjay.phadke@gmail.com | 2d1a3bb | 2007-07-02 00:26:00 +0530 | [diff] [blame] | 1218 | DPRINTK(KERN_ERR |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1219 | "%s: %s interrupt %d while in poll\n", |
| 1220 | netxen_nic_driver_name, netdev->name, |
| 1221 | intcount); |
| 1222 | } |
| 1223 | ret = 1; |
| 1224 | } |
| 1225 | |
| 1226 | if (ret == 0) { |
| 1227 | netxen_nic_enable_int(adapter); |
| 1228 | } |
| 1229 | |
| 1230 | return ret; |
| 1231 | } |
| 1232 | |
| 1233 | /* |
| 1234 | * netxen_intr - Interrupt Handler |
| 1235 | * @irq: interrupt number |
| 1236 | * data points to adapter stucture (which may be handling more than 1 port |
| 1237 | */ |
Jeff Garzik | 1494a81 | 2006-11-07 05:12:16 -0500 | [diff] [blame] | 1238 | irqreturn_t netxen_intr(int irq, void *data) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1239 | { |
Jeff Garzik | 1daec86 | 2007-10-19 03:14:03 -0400 | [diff] [blame] | 1240 | struct netxen_adapter *adapter = data; |
| 1241 | struct net_device *netdev = adapter->netdev; |
dhananjay@netxen.com | e01872af | 2007-07-25 20:13:12 +0530 | [diff] [blame] | 1242 | u32 our_int = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1243 | |
dhananjay@netxen.com | e01872af | 2007-07-25 20:13:12 +0530 | [diff] [blame] | 1244 | if (!(adapter->flags & NETXEN_NIC_MSI_ENABLED)) { |
| 1245 | our_int = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_INT_VECTOR)); |
| 1246 | /* not our interrupt */ |
| 1247 | if ((our_int & (0x80 << adapter->portnum)) == 0) |
| 1248 | return IRQ_NONE; |
| 1249 | } |
| 1250 | |
| 1251 | if (adapter->intr_scheme == INTR_SCHEME_PERPORT) { |
| 1252 | /* claim interrupt */ |
| 1253 | if (!(adapter->flags & NETXEN_NIC_MSI_ENABLED)) { |
| 1254 | writel(our_int & ~((u32)(0x80 << adapter->portnum)), |
| 1255 | NETXEN_CRB_NORMALIZE(adapter, CRB_INT_VECTOR)); |
| 1256 | } |
| 1257 | } |
| 1258 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1259 | if (netif_running(netdev)) |
| 1260 | netxen_handle_int(adapter, netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1261 | |
| 1262 | return IRQ_HANDLED; |
| 1263 | } |
| 1264 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1265 | static int netxen_nic_poll(struct napi_struct *napi, int budget) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1266 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1267 | struct netxen_adapter *adapter = container_of(napi, struct netxen_adapter, napi); |
| 1268 | struct net_device *netdev = adapter->netdev; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1269 | int done = 1; |
| 1270 | int ctx; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1271 | int work_done; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1272 | |
| 1273 | DPRINTK(INFO, "polling for %d descriptors\n", *budget); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1274 | |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 1275 | work_done = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1276 | for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) { |
| 1277 | /* |
| 1278 | * Fairness issue. This will give undue weight to the |
| 1279 | * receive context 0. |
| 1280 | */ |
| 1281 | |
| 1282 | /* |
| 1283 | * To avoid starvation, we give each of our receivers, |
| 1284 | * a fraction of the quota. Sometimes, it might happen that we |
| 1285 | * have enough quota to process every packet, but since all the |
| 1286 | * packets are on one context, it gets only half of the quota, |
| 1287 | * and ends up not processing it. |
| 1288 | */ |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1289 | work_done += netxen_process_rcv_ring(adapter, ctx, |
| 1290 | budget / MAX_RCV_CTX); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1291 | } |
| 1292 | |
David S. Miller | 1706287 | 2008-01-07 20:51:29 -0800 | [diff] [blame] | 1293 | if (work_done >= budget) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1294 | done = 0; |
| 1295 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1296 | if (netxen_process_cmd_ring((unsigned long)adapter) == 0) |
| 1297 | done = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1298 | |
| 1299 | DPRINTK(INFO, "new work_done: %d work_to_do: %d\n", |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 1300 | work_done, work_to_do); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1301 | if (done) { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1302 | netif_rx_complete(netdev, napi); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1303 | netxen_nic_enable_int(adapter); |
| 1304 | } |
| 1305 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1306 | return work_done; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1307 | } |
| 1308 | |
| 1309 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1310 | static void netxen_nic_poll_controller(struct net_device *netdev) |
| 1311 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1312 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1313 | disable_irq(adapter->irq); |
Jeff Garzik | 1494a81 | 2006-11-07 05:12:16 -0500 | [diff] [blame] | 1314 | netxen_intr(adapter->irq, adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1315 | enable_irq(adapter->irq); |
| 1316 | } |
| 1317 | #endif |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1318 | |
| 1319 | static struct pci_driver netxen_driver = { |
| 1320 | .name = netxen_nic_driver_name, |
| 1321 | .id_table = netxen_pci_tbl, |
| 1322 | .probe = netxen_nic_probe, |
| 1323 | .remove = __devexit_p(netxen_nic_remove) |
| 1324 | }; |
| 1325 | |
| 1326 | /* Driver Registration on NetXen card */ |
| 1327 | |
| 1328 | static int __init netxen_init_module(void) |
| 1329 | { |
Al Viro | 79ea13c | 2008-01-24 02:06:46 -0800 | [diff] [blame] | 1330 | if ((netxen_workq = create_singlethread_workqueue("netxen")) == NULL) |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1331 | return -ENOMEM; |
| 1332 | |
Amit S. Kale | 184231b | 2007-01-22 06:52:53 -0800 | [diff] [blame] | 1333 | return pci_register_driver(&netxen_driver); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1334 | } |
| 1335 | |
| 1336 | module_init(netxen_init_module); |
| 1337 | |
| 1338 | static void __exit netxen_exit_module(void) |
| 1339 | { |
| 1340 | /* |
| 1341 | * Wait for some time to allow the dma to drain, if any. |
| 1342 | */ |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 1343 | msleep(100); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1344 | pci_unregister_driver(&netxen_driver); |
Amit S. Kale | 9de0661 | 2007-02-21 06:37:06 -0800 | [diff] [blame] | 1345 | destroy_workqueue(netxen_workq); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | module_exit(netxen_exit_module); |