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