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