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