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