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); |
| 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 | } |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 515 | val = readl(NETXEN_CRB_NORMALIZE(adapter, |
| 516 | NETXEN_ROMUSB_GLB_SW_RESET)); |
| 517 | printk(KERN_INFO"NetXen: read 0x%08x for reset reg.\n",val); |
| 518 | if (val != 0x80000f) { |
| 519 | /* clear the register for future unloads/loads */ |
dhananjay.phadke@gmail.com | 644caee | 2007-07-02 00:25:59 +0530 | [diff] [blame] | 520 | writel(0, NETXEN_CRB_NORMALIZE(adapter, |
| 521 | NETXEN_CAM_RAM(0x1fc))); |
| 522 | printk(KERN_ERR "ERROR in NetXen HW init sequence.\n"); |
| 523 | err = -ENODEV; |
| 524 | goto err_out_free_dev; |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 525 | } |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 526 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 527 | /* clear the register for future unloads/loads */ |
| 528 | writel(0, NETXEN_CRB_NORMALIZE(adapter, |
| 529 | NETXEN_CAM_RAM(0x1fc))); |
| 530 | } |
| 531 | printk(KERN_INFO "State: 0x%0x\n", |
| 532 | readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE))); |
| 533 | |
| 534 | /* |
| 535 | * Tell the hardware our version number. |
| 536 | */ |
| 537 | i = (_NETXEN_NIC_LINUX_MAJOR << 16) |
| 538 | | ((_NETXEN_NIC_LINUX_MINOR << 8)) |
| 539 | | (_NETXEN_NIC_LINUX_SUBVERSION); |
| 540 | writel(i, NETXEN_CRB_NORMALIZE(adapter, CRB_DRIVER_VERSION)); |
| 541 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 542 | /* Unlock the HW, prompting the boot sequence */ |
| 543 | writel(1, |
| 544 | NETXEN_CRB_NORMALIZE(adapter, |
| 545 | NETXEN_ROMUSB_GLB_PEGTUNE_DONE)); |
| 546 | /* Handshake with the card before we register the devices. */ |
| 547 | netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE); |
Mithlesh Thukral | 3e2face | 2007-06-07 04:33:02 -0700 | [diff] [blame] | 548 | |
| 549 | /* leave the hw in the same state as reboot */ |
| 550 | writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE)); |
| 551 | netxen_pinit_from_rom(adapter, 0); |
| 552 | udelay(500); |
| 553 | netxen_load_firmware(adapter); |
| 554 | netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 555 | } |
| 556 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 557 | /* |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 558 | * See if the firmware gave us a virtual-physical port mapping. |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 559 | */ |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 560 | i = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_V2P(adapter->portnum))); |
| 561 | if (i != 0x55555555) |
| 562 | physical_port[adapter->portnum] = i; |
| 563 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 564 | netif_carrier_off(netdev); |
| 565 | netif_stop_queue(netdev); |
| 566 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 567 | if ((err = register_netdev(netdev))) { |
| 568 | printk(KERN_ERR "%s: register_netdev failed port #%d" |
| 569 | " aborting\n", netxen_nic_driver_name, |
| 570 | adapter->portnum); |
| 571 | err = -EIO; |
| 572 | goto err_out_free_dev; |
| 573 | } |
| 574 | |
| 575 | pci_set_drvdata(pdev, adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 576 | |
| 577 | switch (adapter->ahw.board_type) { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 578 | case NETXEN_NIC_GBE: |
| 579 | printk(KERN_INFO "%s: QUAD GbE board initialized\n", |
| 580 | netxen_nic_driver_name); |
| 581 | break; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 582 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 583 | case NETXEN_NIC_XGBE: |
| 584 | printk(KERN_INFO "%s: XGbE board initialized\n", |
| 585 | netxen_nic_driver_name); |
| 586 | break; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | adapter->driver_mismatch = 0; |
| 590 | |
| 591 | return 0; |
| 592 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 593 | err_out_free_dev: |
| 594 | if (adapter->portnum == 0) |
| 595 | netxen_free_adapter_offload(adapter); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 596 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 597 | err_out_free_rx_buffer: |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 598 | for (i = 0; i < MAX_RCV_CTX; ++i) { |
| 599 | recv_ctx = &adapter->recv_ctx[i]; |
| 600 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) { |
| 601 | rcv_desc = &recv_ctx->rcv_desc[ring]; |
| 602 | if (rcv_desc->rx_buf_arr != NULL) { |
| 603 | vfree(rcv_desc->rx_buf_arr); |
| 604 | rcv_desc->rx_buf_arr = NULL; |
| 605 | } |
| 606 | } |
| 607 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 608 | vfree(cmd_buf_arr); |
| 609 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 610 | err_out_free_adapter: |
| 611 | if (adapter->flags & NETXEN_NIC_MSI_ENABLED) |
| 612 | pci_disable_msi(pdev); |
| 613 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 614 | pci_set_drvdata(pdev, NULL); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 615 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 616 | if (db_ptr) |
| 617 | iounmap(db_ptr); |
| 618 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 619 | err_out_iounmap: |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 620 | if (mem_ptr0) |
| 621 | iounmap(mem_ptr0); |
| 622 | if (mem_ptr1) |
| 623 | iounmap(mem_ptr1); |
| 624 | if (mem_ptr2) |
| 625 | iounmap(mem_ptr2); |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 626 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 627 | err_out_free_netdev: |
| 628 | free_netdev(netdev); |
| 629 | |
| 630 | err_out_free_res: |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 631 | pci_release_regions(pdev); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 632 | |
| 633 | err_out_disable_pdev: |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 634 | pci_disable_device(pdev); |
| 635 | return err; |
| 636 | } |
| 637 | |
| 638 | static void __devexit netxen_nic_remove(struct pci_dev *pdev) |
| 639 | { |
| 640 | struct netxen_adapter *adapter; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 641 | struct net_device *netdev; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 642 | struct netxen_rx_buffer *buffer; |
| 643 | struct netxen_recv_context *recv_ctx; |
| 644 | struct netxen_rcv_desc_ctx *rcv_desc; |
| 645 | int i; |
| 646 | int ctxid, ring; |
| 647 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 648 | adapter = pci_get_drvdata(pdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 649 | if (adapter == NULL) |
| 650 | return; |
| 651 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 652 | netdev = adapter->netdev; |
| 653 | |
| 654 | netxen_nic_disable_int(adapter); |
| 655 | if (adapter->irq) |
| 656 | free_irq(adapter->irq, adapter); |
| 657 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 658 | if (adapter->stop_port) |
| 659 | adapter->stop_port(adapter); |
| 660 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 661 | if ((adapter->flags & NETXEN_NIC_MSI_ENABLED)) |
| 662 | pci_disable_msi(pdev); |
| 663 | |
| 664 | if (adapter->portnum == 0) |
| 665 | netxen_free_adapter_offload(adapter); |
| 666 | |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 667 | if(adapter->portnum == 0) { |
| 668 | /* leave the hw in the same state as reboot */ |
| 669 | writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE)); |
| 670 | netxen_pinit_from_rom(adapter, 0); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 671 | udelay(500); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 672 | netxen_load_firmware(adapter); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 673 | netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 674 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 675 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 676 | if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) |
| 677 | netxen_free_hw_resources(adapter); |
| 678 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 679 | for (ctxid = 0; ctxid < MAX_RCV_CTX; ++ctxid) { |
| 680 | recv_ctx = &adapter->recv_ctx[ctxid]; |
| 681 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) { |
| 682 | rcv_desc = &recv_ctx->rcv_desc[ring]; |
| 683 | for (i = 0; i < rcv_desc->max_rx_desc_count; ++i) { |
| 684 | buffer = &(rcv_desc->rx_buf_arr[i]); |
| 685 | if (buffer->state == NETXEN_BUFFER_FREE) |
| 686 | continue; |
| 687 | pci_unmap_single(pdev, buffer->dma, |
| 688 | rcv_desc->dma_size, |
| 689 | PCI_DMA_FROMDEVICE); |
| 690 | if (buffer->skb != NULL) |
| 691 | dev_kfree_skb_any(buffer->skb); |
| 692 | } |
| 693 | vfree(rcv_desc->rx_buf_arr); |
| 694 | } |
| 695 | } |
| 696 | |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 697 | unregister_netdev(netdev); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 698 | |
| 699 | vfree(adapter->cmd_buf_arr); |
| 700 | |
| 701 | iounmap(adapter->ahw.db_base); |
| 702 | iounmap(adapter->ahw.pci_base0); |
| 703 | iounmap(adapter->ahw.pci_base1); |
| 704 | iounmap(adapter->ahw.pci_base2); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 705 | |
| 706 | pci_release_regions(pdev); |
| 707 | pci_disable_device(pdev); |
| 708 | pci_set_drvdata(pdev, NULL); |
| 709 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 710 | free_netdev(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | /* |
| 714 | * Called when a network interface is made active |
| 715 | * @returns 0 on success, negative value on failure |
| 716 | */ |
| 717 | static int netxen_nic_open(struct net_device *netdev) |
| 718 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 719 | struct netxen_adapter *adapter = (struct netxen_adapter *)netdev->priv; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 720 | int err = 0; |
| 721 | int ctx, ring; |
| 722 | |
| 723 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) { |
| 724 | err = netxen_init_firmware(adapter); |
| 725 | if (err != 0) { |
| 726 | printk(KERN_ERR "Failed to init firmware\n"); |
| 727 | return -EIO; |
| 728 | } |
| 729 | netxen_nic_flash_print(adapter); |
| 730 | |
| 731 | /* setup all the resources for the Phantom... */ |
| 732 | /* this include the descriptors for rcv, tx, and status */ |
| 733 | netxen_nic_clear_stats(adapter); |
| 734 | err = netxen_nic_hw_resources(adapter); |
| 735 | if (err) { |
| 736 | printk(KERN_ERR "Error in setting hw resources:%d\n", |
| 737 | err); |
| 738 | return err; |
| 739 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 740 | for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) { |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 741 | for (ring = 0; ring < NUM_RCV_DESC_RINGS; ring++) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 742 | netxen_post_rx_buffers(adapter, ctx, ring); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 743 | } |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 744 | adapter->irq = adapter->ahw.pdev->irq; |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 745 | err = request_irq(adapter->ahw.pdev->irq, netxen_intr, |
Andrew Morton | 1c8e039 | 2007-05-10 22:53:00 -0700 | [diff] [blame] | 746 | IRQF_SHARED|IRQF_SAMPLE_RANDOM, netdev->name, |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 747 | adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 748 | if (err) { |
| 749 | printk(KERN_ERR "request_irq failed with: %d\n", err); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 750 | netxen_free_hw_resources(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 751 | return err; |
| 752 | } |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 753 | |
| 754 | adapter->is_up = NETXEN_ADAPTER_UP_MAGIC; |
| 755 | } |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 756 | if (!adapter->driver_mismatch) |
| 757 | mod_timer(&adapter->watchdog_timer, jiffies); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 758 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 759 | netxen_nic_enable_int(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 760 | |
| 761 | /* Done here again so that even if phantom sw overwrote it, |
| 762 | * we set it */ |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 763 | if (adapter->macaddr_set) |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 764 | adapter->macaddr_set(adapter, netdev->dev_addr); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 765 | if (adapter->init_port |
| 766 | && adapter->init_port(adapter, adapter->portnum) != 0) { |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 767 | del_timer_sync(&adapter->watchdog_timer); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 768 | printk(KERN_ERR "%s: Failed to initialize port %d\n", |
| 769 | netxen_nic_driver_name, adapter->portnum); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 770 | return -EIO; |
| 771 | } |
| 772 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 773 | netxen_nic_set_link_parameters(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 774 | |
| 775 | netxen_nic_set_multi(netdev); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 776 | if (adapter->set_mtu) |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 777 | adapter->set_mtu(adapter, netdev->mtu); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 778 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 779 | if (!adapter->driver_mismatch) |
| 780 | netif_start_queue(netdev); |
| 781 | |
| 782 | return 0; |
| 783 | } |
| 784 | |
| 785 | /* |
| 786 | * netxen_nic_close - Disables a network interface entry point |
| 787 | */ |
| 788 | static int netxen_nic_close(struct net_device *netdev) |
| 789 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 790 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 791 | int i, j; |
| 792 | struct netxen_cmd_buffer *cmd_buff; |
| 793 | struct netxen_skb_frag *buffrag; |
| 794 | |
| 795 | netif_carrier_off(netdev); |
| 796 | netif_stop_queue(netdev); |
| 797 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 798 | cmd_buff = adapter->cmd_buf_arr; |
| 799 | for (i = 0; i < adapter->max_tx_desc_count; i++) { |
| 800 | buffrag = cmd_buff->frag_array; |
| 801 | if (buffrag->dma) { |
| 802 | pci_unmap_single(adapter->pdev, buffrag->dma, |
| 803 | buffrag->length, PCI_DMA_TODEVICE); |
| 804 | buffrag->dma = (u64) NULL; |
| 805 | } |
| 806 | for (j = 0; j < cmd_buff->frag_count; j++) { |
| 807 | buffrag++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 808 | if (buffrag->dma) { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 809 | pci_unmap_page(adapter->pdev, buffrag->dma, |
| 810 | buffrag->length, |
| 811 | PCI_DMA_TODEVICE); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 812 | buffrag->dma = (u64) NULL; |
| 813 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 814 | } |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 815 | /* Free the skb we received in netxen_nic_xmit_frame */ |
| 816 | if (cmd_buff->skb) { |
| 817 | dev_kfree_skb_any(cmd_buff->skb); |
| 818 | cmd_buff->skb = NULL; |
| 819 | } |
| 820 | cmd_buff++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 821 | } |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 822 | FLUSH_SCHEDULED_WORK(); |
| 823 | del_timer_sync(&adapter->watchdog_timer); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 824 | |
| 825 | return 0; |
| 826 | } |
| 827 | |
| 828 | static int netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
| 829 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 830 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 831 | struct netxen_hardware_context *hw = &adapter->ahw; |
| 832 | unsigned int first_seg_len = skb->len - skb->data_len; |
| 833 | struct netxen_skb_frag *buffrag; |
| 834 | unsigned int i; |
| 835 | |
| 836 | u32 producer = 0; |
| 837 | u32 saved_producer = 0; |
| 838 | struct cmd_desc_type0 *hwdesc; |
| 839 | int k; |
| 840 | struct netxen_cmd_buffer *pbuf = NULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 841 | static int dropped_packet = 0; |
| 842 | int frag_count; |
| 843 | u32 local_producer = 0; |
| 844 | u32 max_tx_desc_count = 0; |
| 845 | u32 last_cmd_consumer = 0; |
| 846 | int no_of_desc; |
| 847 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 848 | adapter->stats.xmitcalled++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 849 | frag_count = skb_shinfo(skb)->nr_frags + 1; |
| 850 | |
| 851 | if (unlikely(skb->len <= 0)) { |
| 852 | dev_kfree_skb_any(skb); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 853 | adapter->stats.badskblen++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 854 | return NETDEV_TX_OK; |
| 855 | } |
| 856 | |
| 857 | if (frag_count > MAX_BUFFERS_PER_CMD) { |
| 858 | printk("%s: %s netxen_nic_xmit_frame: frag_count (%d)" |
| 859 | "too large, can handle only %d frags\n", |
| 860 | netxen_nic_driver_name, netdev->name, |
| 861 | frag_count, MAX_BUFFERS_PER_CMD); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 862 | adapter->stats.txdropped++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 863 | if ((++dropped_packet & 0xff) == 0xff) |
| 864 | printk("%s: %s droppped packets = %d\n", |
| 865 | netxen_nic_driver_name, netdev->name, |
| 866 | dropped_packet); |
| 867 | |
| 868 | return NETDEV_TX_OK; |
| 869 | } |
| 870 | |
| 871 | /* |
| 872 | * Everything is set up. Now, we just need to transmit it out. |
| 873 | * Note that we have to copy the contents of buffer over to |
| 874 | * right place. Later on, this can be optimized out by de-coupling the |
| 875 | * producer index from the buffer index. |
| 876 | */ |
| 877 | retry_getting_window: |
| 878 | spin_lock_bh(&adapter->tx_lock); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 879 | if (adapter->total_threads >= MAX_XMIT_PRODUCERS) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 880 | spin_unlock_bh(&adapter->tx_lock); |
| 881 | /* |
| 882 | * Yield CPU |
| 883 | */ |
| 884 | if (!in_atomic()) |
| 885 | schedule(); |
| 886 | else { |
| 887 | for (i = 0; i < 20; i++) |
| 888 | cpu_relax(); /*This a nop instr on i386 */ |
| 889 | } |
| 890 | goto retry_getting_window; |
| 891 | } |
| 892 | local_producer = adapter->cmd_producer; |
| 893 | /* There 4 fragments per descriptor */ |
| 894 | no_of_desc = (frag_count + 3) >> 2; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 895 | if (netdev->features & NETIF_F_TSO) { |
| 896 | if (skb_shinfo(skb)->gso_size > 0) { |
| 897 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 898 | no_of_desc++; |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 899 | if ((ip_hdrlen(skb) + tcp_hdrlen(skb) + |
Arnaldo Carvalho de Melo | c9bdd4b | 2007-03-12 20:09:15 -0300 | [diff] [blame] | 900 | sizeof(struct ethhdr)) > |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 901 | (sizeof(struct cmd_desc_type0) - 2)) { |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 902 | no_of_desc++; |
| 903 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 904 | } |
| 905 | } |
| 906 | k = adapter->cmd_producer; |
| 907 | max_tx_desc_count = adapter->max_tx_desc_count; |
| 908 | last_cmd_consumer = adapter->last_cmd_consumer; |
| 909 | if ((k + no_of_desc) >= |
| 910 | ((last_cmd_consumer <= k) ? last_cmd_consumer + max_tx_desc_count : |
| 911 | last_cmd_consumer)) { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 912 | netif_stop_queue(netdev); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 913 | adapter->flags |= NETXEN_NETDEV_STATUS; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 914 | spin_unlock_bh(&adapter->tx_lock); |
| 915 | return NETDEV_TX_BUSY; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 916 | } |
| 917 | k = get_index_range(k, max_tx_desc_count, no_of_desc); |
| 918 | adapter->cmd_producer = k; |
| 919 | adapter->total_threads++; |
| 920 | adapter->num_threads++; |
| 921 | |
| 922 | spin_unlock_bh(&adapter->tx_lock); |
| 923 | /* Copy the descriptors into the hardware */ |
| 924 | producer = local_producer; |
| 925 | saved_producer = producer; |
| 926 | hwdesc = &hw->cmd_desc_head[producer]; |
| 927 | memset(hwdesc, 0, sizeof(struct cmd_desc_type0)); |
| 928 | /* Take skb->data itself */ |
| 929 | pbuf = &adapter->cmd_buf_arr[producer]; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 930 | if ((netdev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size > 0) { |
Al Viro | a608ab9c | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 931 | pbuf->mss = skb_shinfo(skb)->gso_size; |
Amit S. Kale | ed33ebe | 2006-12-18 05:53:59 -0800 | [diff] [blame] | 932 | hwdesc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 933 | } else { |
| 934 | pbuf->mss = 0; |
| 935 | hwdesc->mss = 0; |
| 936 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 937 | pbuf->total_length = skb->len; |
| 938 | pbuf->skb = skb; |
| 939 | pbuf->cmd = TX_ETHER_PKT; |
| 940 | pbuf->frag_count = frag_count; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 941 | pbuf->port = adapter->portnum; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 942 | buffrag = &pbuf->frag_array[0]; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 943 | 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] | 944 | PCI_DMA_TODEVICE); |
| 945 | buffrag->length = first_seg_len; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 946 | netxen_set_cmd_desc_totallength(hwdesc, skb->len); |
| 947 | netxen_set_cmd_desc_num_of_buff(hwdesc, frag_count); |
| 948 | netxen_set_cmd_desc_opcode(hwdesc, TX_ETHER_PKT); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 949 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 950 | netxen_set_cmd_desc_port(hwdesc, adapter->portnum); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 951 | netxen_set_cmd_desc_ctxid(hwdesc, adapter->portnum); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 952 | hwdesc->buffer1_length = cpu_to_le16(first_seg_len); |
| 953 | hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma); |
| 954 | |
| 955 | for (i = 1, k = 1; i < frag_count; i++, k++) { |
| 956 | struct skb_frag_struct *frag; |
| 957 | int len, temp_len; |
| 958 | unsigned long offset; |
| 959 | dma_addr_t temp_dma; |
| 960 | |
| 961 | /* move to next desc. if there is a need */ |
| 962 | if ((i & 0x3) == 0) { |
| 963 | k = 0; |
| 964 | producer = get_next_index(producer, |
| 965 | adapter->max_tx_desc_count); |
| 966 | hwdesc = &hw->cmd_desc_head[producer]; |
| 967 | memset(hwdesc, 0, sizeof(struct cmd_desc_type0)); |
| 968 | } |
| 969 | frag = &skb_shinfo(skb)->frags[i - 1]; |
| 970 | len = frag->size; |
| 971 | offset = frag->page_offset; |
| 972 | |
| 973 | temp_len = len; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 974 | temp_dma = pci_map_page(adapter->pdev, frag->page, offset, |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 975 | len, PCI_DMA_TODEVICE); |
| 976 | |
| 977 | buffrag++; |
| 978 | buffrag->dma = temp_dma; |
| 979 | buffrag->length = temp_len; |
| 980 | |
| 981 | DPRINTK(INFO, "for loop. i=%d k=%d\n", i, k); |
| 982 | switch (k) { |
| 983 | case 0: |
| 984 | hwdesc->buffer1_length = cpu_to_le16(temp_len); |
| 985 | hwdesc->addr_buffer1 = cpu_to_le64(temp_dma); |
| 986 | break; |
| 987 | case 1: |
| 988 | hwdesc->buffer2_length = cpu_to_le16(temp_len); |
| 989 | hwdesc->addr_buffer2 = cpu_to_le64(temp_dma); |
| 990 | break; |
| 991 | case 2: |
| 992 | hwdesc->buffer3_length = cpu_to_le16(temp_len); |
| 993 | hwdesc->addr_buffer3 = cpu_to_le64(temp_dma); |
| 994 | break; |
| 995 | case 3: |
Al Viro | a608ab9c | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 996 | hwdesc->buffer4_length = cpu_to_le16(temp_len); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 997 | hwdesc->addr_buffer4 = cpu_to_le64(temp_dma); |
| 998 | break; |
| 999 | } |
| 1000 | frag++; |
| 1001 | } |
| 1002 | producer = get_next_index(producer, adapter->max_tx_desc_count); |
| 1003 | |
| 1004 | /* might change opcode to TX_TCP_LSO */ |
| 1005 | netxen_tso_check(adapter, &hw->cmd_desc_head[saved_producer], skb); |
| 1006 | |
| 1007 | /* For LSO, we need to copy the MAC/IP/TCP headers into |
| 1008 | * the descriptor ring |
| 1009 | */ |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1010 | if (netxen_get_cmd_desc_opcode(&hw->cmd_desc_head[saved_producer]) |
| 1011 | == TX_TCP_LSO) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1012 | int hdr_len, first_hdr_len, more_hdr; |
| 1013 | hdr_len = hw->cmd_desc_head[saved_producer].total_hdr_length; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1014 | if (hdr_len > (sizeof(struct cmd_desc_type0) - 2)) { |
| 1015 | first_hdr_len = sizeof(struct cmd_desc_type0) - 2; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1016 | more_hdr = 1; |
| 1017 | } else { |
| 1018 | first_hdr_len = hdr_len; |
| 1019 | more_hdr = 0; |
| 1020 | } |
| 1021 | /* copy the MAC/IP/TCP headers to the cmd descriptor list */ |
| 1022 | hwdesc = &hw->cmd_desc_head[producer]; |
| 1023 | |
| 1024 | /* copy the first 64 bytes */ |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1025 | memcpy(((void *)hwdesc) + 2, |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1026 | (void *)(skb->data), first_hdr_len); |
| 1027 | producer = get_next_index(producer, max_tx_desc_count); |
| 1028 | |
| 1029 | if (more_hdr) { |
| 1030 | hwdesc = &hw->cmd_desc_head[producer]; |
| 1031 | /* copy the next 64 bytes - should be enough except |
| 1032 | * for pathological case |
| 1033 | */ |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 1034 | skb_copy_from_linear_data_offset(skb, first_hdr_len, |
| 1035 | hwdesc, |
| 1036 | (hdr_len - |
| 1037 | first_hdr_len)); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1038 | producer = get_next_index(producer, max_tx_desc_count); |
| 1039 | } |
| 1040 | } |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1041 | |
| 1042 | i = netxen_get_cmd_desc_totallength(&hw->cmd_desc_head[saved_producer]); |
| 1043 | |
| 1044 | hw->cmd_desc_head[saved_producer].flags_opcode = |
| 1045 | cpu_to_le16(hw->cmd_desc_head[saved_producer].flags_opcode); |
| 1046 | hw->cmd_desc_head[saved_producer].num_of_buffers_total_length = |
| 1047 | cpu_to_le32(hw->cmd_desc_head[saved_producer]. |
| 1048 | num_of_buffers_total_length); |
| 1049 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1050 | spin_lock_bh(&adapter->tx_lock); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1051 | adapter->stats.txbytes += i; |
| 1052 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1053 | /* Code to update the adapter considering how many producer threads |
| 1054 | are currently working */ |
| 1055 | if ((--adapter->num_threads) == 0) { |
| 1056 | /* This is the last thread */ |
| 1057 | u32 crb_producer = adapter->cmd_producer; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1058 | netxen_nic_update_cmd_producer(adapter, crb_producer); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1059 | wmb(); |
| 1060 | adapter->total_threads = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1061 | } |
| 1062 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1063 | adapter->stats.xmitfinished++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1064 | spin_unlock_bh(&adapter->tx_lock); |
| 1065 | |
| 1066 | netdev->trans_start = jiffies; |
| 1067 | |
| 1068 | DPRINTK(INFO, "wrote CMD producer %x to phantom\n", producer); |
| 1069 | |
| 1070 | DPRINTK(INFO, "Done. Send\n"); |
| 1071 | return NETDEV_TX_OK; |
| 1072 | } |
| 1073 | |
| 1074 | static void netxen_watchdog(unsigned long v) |
| 1075 | { |
| 1076 | struct netxen_adapter *adapter = (struct netxen_adapter *)v; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1077 | |
| 1078 | SCHEDULE_WORK(&adapter->watchdog_task); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | static void netxen_tx_timeout(struct net_device *netdev) |
| 1082 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1083 | struct netxen_adapter *adapter = (struct netxen_adapter *) |
| 1084 | netdev_priv(netdev); |
| 1085 | SCHEDULE_WORK(&adapter->tx_timeout_task); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1086 | } |
| 1087 | |
David Howells | 6d5aefb | 2006-12-05 19:36:26 +0000 | [diff] [blame] | 1088 | static void netxen_tx_timeout_task(struct work_struct *work) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1089 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1090 | struct netxen_adapter *adapter = |
| 1091 | container_of(work, struct netxen_adapter, tx_timeout_task); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1092 | unsigned long flags; |
| 1093 | |
| 1094 | printk(KERN_ERR "%s %s: transmit timeout, resetting.\n", |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1095 | netxen_nic_driver_name, adapter->netdev->name); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1096 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1097 | spin_lock_irqsave(&adapter->lock, flags); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1098 | netxen_nic_close(adapter->netdev); |
| 1099 | netxen_nic_open(adapter->netdev); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1100 | spin_unlock_irqrestore(&adapter->lock, flags); |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 1101 | adapter->netdev->trans_start = jiffies; |
| 1102 | netif_wake_queue(adapter->netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | static int |
| 1106 | netxen_handle_int(struct netxen_adapter *adapter, struct net_device *netdev) |
| 1107 | { |
| 1108 | u32 ret = 0; |
dhananjay.phadke@gmail.com | 2d1a3bb | 2007-07-02 00:26:00 +0530 | [diff] [blame^] | 1109 | u32 our_int = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1110 | |
| 1111 | DPRINTK(INFO, "Entered handle ISR\n"); |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 1112 | adapter->stats.ints++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1113 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1114 | if (!(adapter->flags & NETXEN_NIC_MSI_ENABLED)) { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1115 | our_int = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_INT_VECTOR)); |
| 1116 | /* not our interrupt */ |
| 1117 | if ((our_int & (0x80 << adapter->portnum)) == 0) |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1118 | return ret; |
dhananjay.phadke@gmail.com | 2d1a3bb | 2007-07-02 00:26:00 +0530 | [diff] [blame^] | 1119 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1120 | |
dhananjay.phadke@gmail.com | 2d1a3bb | 2007-07-02 00:26:00 +0530 | [diff] [blame^] | 1121 | netxen_nic_disable_int(adapter); |
| 1122 | |
| 1123 | if (adapter->intr_scheme == INTR_SCHEME_PERPORT) { |
| 1124 | /* claim interrupt */ |
| 1125 | if (!(adapter->flags & NETXEN_NIC_MSI_ENABLED)) { |
| 1126 | writel(our_int & ~((u32)(0x80 << adapter->portnum)), |
| 1127 | NETXEN_CRB_NORMALIZE(adapter, CRB_INT_VECTOR)); |
| 1128 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1129 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1130 | |
| 1131 | if (netxen_nic_rx_has_work(adapter) || netxen_nic_tx_has_work(adapter)) { |
| 1132 | if (netif_rx_schedule_prep(netdev)) { |
| 1133 | /* |
| 1134 | * Interrupts are already disabled. |
| 1135 | */ |
| 1136 | __netif_rx_schedule(netdev); |
| 1137 | } else { |
| 1138 | static unsigned int intcount = 0; |
| 1139 | if ((++intcount & 0xfff) == 0xfff) |
dhananjay.phadke@gmail.com | 2d1a3bb | 2007-07-02 00:26:00 +0530 | [diff] [blame^] | 1140 | DPRINTK(KERN_ERR |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1141 | "%s: %s interrupt %d while in poll\n", |
| 1142 | netxen_nic_driver_name, netdev->name, |
| 1143 | intcount); |
| 1144 | } |
| 1145 | ret = 1; |
| 1146 | } |
| 1147 | |
| 1148 | if (ret == 0) { |
| 1149 | netxen_nic_enable_int(adapter); |
| 1150 | } |
| 1151 | |
| 1152 | return ret; |
| 1153 | } |
| 1154 | |
| 1155 | /* |
| 1156 | * netxen_intr - Interrupt Handler |
| 1157 | * @irq: interrupt number |
| 1158 | * data points to adapter stucture (which may be handling more than 1 port |
| 1159 | */ |
Jeff Garzik | 1494a81 | 2006-11-07 05:12:16 -0500 | [diff] [blame] | 1160 | irqreturn_t netxen_intr(int irq, void *data) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1161 | { |
| 1162 | struct netxen_adapter *adapter; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1163 | struct net_device *netdev; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1164 | |
| 1165 | if (unlikely(!irq)) { |
| 1166 | return IRQ_NONE; /* Not our interrupt */ |
| 1167 | } |
| 1168 | |
| 1169 | adapter = (struct netxen_adapter *)data; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1170 | netdev = adapter->netdev; |
| 1171 | /* process our status queue (for all 4 ports) */ |
| 1172 | if (netif_running(netdev)) |
| 1173 | netxen_handle_int(adapter, netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1174 | |
| 1175 | return IRQ_HANDLED; |
| 1176 | } |
| 1177 | |
| 1178 | static int netxen_nic_poll(struct net_device *netdev, int *budget) |
| 1179 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1180 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1181 | int work_to_do = min(*budget, netdev->quota); |
| 1182 | int done = 1; |
| 1183 | int ctx; |
| 1184 | int this_work_done; |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 1185 | int work_done = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1186 | |
| 1187 | DPRINTK(INFO, "polling for %d descriptors\n", *budget); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1188 | |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 1189 | work_done = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1190 | for (ctx = 0; ctx < MAX_RCV_CTX; ++ctx) { |
| 1191 | /* |
| 1192 | * Fairness issue. This will give undue weight to the |
| 1193 | * receive context 0. |
| 1194 | */ |
| 1195 | |
| 1196 | /* |
| 1197 | * To avoid starvation, we give each of our receivers, |
| 1198 | * a fraction of the quota. Sometimes, it might happen that we |
| 1199 | * have enough quota to process every packet, but since all the |
| 1200 | * packets are on one context, it gets only half of the quota, |
| 1201 | * and ends up not processing it. |
| 1202 | */ |
| 1203 | this_work_done = netxen_process_rcv_ring(adapter, ctx, |
| 1204 | work_to_do / |
| 1205 | MAX_RCV_CTX); |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 1206 | work_done += this_work_done; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1207 | } |
| 1208 | |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 1209 | netdev->quota -= work_done; |
| 1210 | *budget -= work_done; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1211 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1212 | 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] | 1213 | done = 0; |
| 1214 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1215 | if (netxen_process_cmd_ring((unsigned long)adapter) == 0) |
| 1216 | done = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1217 | |
| 1218 | DPRINTK(INFO, "new work_done: %d work_to_do: %d\n", |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 1219 | work_done, work_to_do); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1220 | if (done) { |
| 1221 | netif_rx_complete(netdev); |
| 1222 | netxen_nic_enable_int(adapter); |
| 1223 | } |
| 1224 | |
Amit S. Kale | edf9016 | 2006-11-29 08:58:11 -0800 | [diff] [blame] | 1225 | return !done; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1226 | } |
| 1227 | |
| 1228 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1229 | static void netxen_nic_poll_controller(struct net_device *netdev) |
| 1230 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1231 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1232 | disable_irq(adapter->irq); |
Jeff Garzik | 1494a81 | 2006-11-07 05:12:16 -0500 | [diff] [blame] | 1233 | netxen_intr(adapter->irq, adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1234 | enable_irq(adapter->irq); |
| 1235 | } |
| 1236 | #endif |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1237 | |
| 1238 | static struct pci_driver netxen_driver = { |
| 1239 | .name = netxen_nic_driver_name, |
| 1240 | .id_table = netxen_pci_tbl, |
| 1241 | .probe = netxen_nic_probe, |
| 1242 | .remove = __devexit_p(netxen_nic_remove) |
| 1243 | }; |
| 1244 | |
| 1245 | /* Driver Registration on NetXen card */ |
| 1246 | |
| 1247 | static int __init netxen_init_module(void) |
| 1248 | { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1249 | if ((netxen_workq = create_singlethread_workqueue("netxen")) == 0) |
| 1250 | return -ENOMEM; |
| 1251 | |
Amit S. Kale | 184231b | 2007-01-22 06:52:53 -0800 | [diff] [blame] | 1252 | return pci_register_driver(&netxen_driver); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1253 | } |
| 1254 | |
| 1255 | module_init(netxen_init_module); |
| 1256 | |
| 1257 | static void __exit netxen_exit_module(void) |
| 1258 | { |
| 1259 | /* |
| 1260 | * Wait for some time to allow the dma to drain, if any. |
| 1261 | */ |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1262 | pci_unregister_driver(&netxen_driver); |
Amit S. Kale | 9de0661 | 2007-02-21 06:37:06 -0800 | [diff] [blame] | 1263 | destroy_workqueue(netxen_workq); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1264 | } |
| 1265 | |
| 1266 | module_exit(netxen_exit_module); |