Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1 | /************************************************************************* |
| 2 | * myri10ge.c: Myricom Myri-10G Ethernet driver. |
| 3 | * |
Jon Mason | 3bea123 | 2011-06-27 05:05:07 +0000 | [diff] [blame] | 4 | * Copyright (C) 2005 - 2011 Myricom, Inc. |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 5 | * All rights reserved. |
| 6 | * |
| 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions |
| 9 | * are met: |
| 10 | * 1. Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in the |
| 14 | * documentation and/or other materials provided with the distribution. |
| 15 | * 3. Neither the name of Myricom, Inc. nor the names of its contributors |
| 16 | * may be used to endorse or promote products derived from this software |
| 17 | * without specific prior written permission. |
| 18 | * |
Brice Goglin | 4a2e612 | 2007-02-27 17:18:40 +0100 | [diff] [blame] | 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
Brice Goglin | 4a2e612 | 2007-02-27 17:18:40 +0100 | [diff] [blame] | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 29 | * POSSIBILITY OF SUCH DAMAGE. |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 30 | * |
| 31 | * |
| 32 | * If the eeprom on your board is not recent enough, you will need to get a |
| 33 | * newer firmware image at: |
| 34 | * http://www.myri.com/scs/download-Myri10GE.html |
| 35 | * |
| 36 | * Contact Information: |
| 37 | * <help@myri.com> |
| 38 | * Myricom, Inc., 325N Santa Anita Avenue, Arcadia, CA 91006 |
| 39 | *************************************************************************/ |
| 40 | |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 41 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 42 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 43 | #include <linux/tcp.h> |
| 44 | #include <linux/netdevice.h> |
| 45 | #include <linux/skbuff.h> |
| 46 | #include <linux/string.h> |
| 47 | #include <linux/module.h> |
| 48 | #include <linux/pci.h> |
Brice Goglin | b10c066 | 2006-06-08 10:25:00 -0400 | [diff] [blame] | 49 | #include <linux/dma-mapping.h> |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 50 | #include <linux/etherdevice.h> |
| 51 | #include <linux/if_ether.h> |
| 52 | #include <linux/if_vlan.h> |
Brice Goglin | 981813d | 2008-05-09 02:22:16 +0200 | [diff] [blame] | 53 | #include <linux/dca.h> |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 54 | #include <linux/ip.h> |
| 55 | #include <linux/inet.h> |
| 56 | #include <linux/in.h> |
| 57 | #include <linux/ethtool.h> |
| 58 | #include <linux/firmware.h> |
| 59 | #include <linux/delay.h> |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 60 | #include <linux/timer.h> |
| 61 | #include <linux/vmalloc.h> |
| 62 | #include <linux/crc32.h> |
| 63 | #include <linux/moduleparam.h> |
| 64 | #include <linux/io.h> |
vignesh babu | 199126a | 2007-07-09 11:50:22 -0700 | [diff] [blame] | 65 | #include <linux/log2.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 66 | #include <linux/slab.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 67 | #include <linux/prefetch.h> |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 68 | #include <net/checksum.h> |
Andrew Gallatin | 1e6e934 | 2007-09-17 11:37:42 -0700 | [diff] [blame] | 69 | #include <net/ip.h> |
| 70 | #include <net/tcp.h> |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 71 | #include <asm/byteorder.h> |
| 72 | #include <asm/io.h> |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 73 | #include <asm/processor.h> |
| 74 | #ifdef CONFIG_MTRR |
| 75 | #include <asm/mtrr.h> |
| 76 | #endif |
| 77 | |
| 78 | #include "myri10ge_mcp.h" |
| 79 | #include "myri10ge_mcp_gen_header.h" |
| 80 | |
Jon Mason | 3bea123 | 2011-06-27 05:05:07 +0000 | [diff] [blame] | 81 | #define MYRI10GE_VERSION_STR "1.5.3-1.534" |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 82 | |
| 83 | MODULE_DESCRIPTION("Myricom 10G driver (10GbE)"); |
| 84 | MODULE_AUTHOR("Maintainer: help@myri.com"); |
| 85 | MODULE_VERSION(MYRI10GE_VERSION_STR); |
| 86 | MODULE_LICENSE("Dual BSD/GPL"); |
| 87 | |
| 88 | #define MYRI10GE_MAX_ETHER_MTU 9014 |
| 89 | |
| 90 | #define MYRI10GE_ETH_STOPPED 0 |
| 91 | #define MYRI10GE_ETH_STOPPING 1 |
| 92 | #define MYRI10GE_ETH_STARTING 2 |
| 93 | #define MYRI10GE_ETH_RUNNING 3 |
| 94 | #define MYRI10GE_ETH_OPEN_FAILED 4 |
| 95 | |
| 96 | #define MYRI10GE_EEPROM_STRINGS_SIZE 256 |
| 97 | #define MYRI10GE_MAX_SEND_DESC_TSO ((65536 / 2048) * 2) |
| 98 | |
Al Viro | 40f6cff | 2006-11-20 13:48:32 -0500 | [diff] [blame] | 99 | #define MYRI10GE_NO_CONFIRM_DATA htonl(0xffffffff) |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 100 | #define MYRI10GE_NO_RESPONSE_RESULT 0xffffffff |
| 101 | |
Brice Goglin | dd50f33 | 2006-12-11 11:25:09 +0100 | [diff] [blame] | 102 | #define MYRI10GE_ALLOC_ORDER 0 |
| 103 | #define MYRI10GE_ALLOC_SIZE ((1 << MYRI10GE_ALLOC_ORDER) * PAGE_SIZE) |
| 104 | #define MYRI10GE_MAX_FRAGS_PER_FRAME (MYRI10GE_MAX_ETHER_MTU/MYRI10GE_ALLOC_SIZE + 1) |
| 105 | |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 106 | #define MYRI10GE_MAX_SLICES 32 |
| 107 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 108 | struct myri10ge_rx_buffer_state { |
Brice Goglin | dd50f33 | 2006-12-11 11:25:09 +0100 | [diff] [blame] | 109 | struct page *page; |
| 110 | int page_offset; |
FUJITA Tomonori | c755b4b | 2010-04-12 14:32:10 +0000 | [diff] [blame] | 111 | DEFINE_DMA_UNMAP_ADDR(bus); |
| 112 | DEFINE_DMA_UNMAP_LEN(len); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | struct myri10ge_tx_buffer_state { |
| 116 | struct sk_buff *skb; |
| 117 | int last; |
FUJITA Tomonori | c755b4b | 2010-04-12 14:32:10 +0000 | [diff] [blame] | 118 | DEFINE_DMA_UNMAP_ADDR(bus); |
| 119 | DEFINE_DMA_UNMAP_LEN(len); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | struct myri10ge_cmd { |
| 123 | u32 data0; |
| 124 | u32 data1; |
| 125 | u32 data2; |
| 126 | }; |
| 127 | |
| 128 | struct myri10ge_rx_buf { |
| 129 | struct mcp_kreq_ether_recv __iomem *lanai; /* lanai ptr for recv ring */ |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 130 | struct mcp_kreq_ether_recv *shadow; /* host shadow of recv ring */ |
| 131 | struct myri10ge_rx_buffer_state *info; |
Brice Goglin | dd50f33 | 2006-12-11 11:25:09 +0100 | [diff] [blame] | 132 | struct page *page; |
| 133 | dma_addr_t bus; |
| 134 | int page_offset; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 135 | int cnt; |
Brice Goglin | dd50f33 | 2006-12-11 11:25:09 +0100 | [diff] [blame] | 136 | int fill_cnt; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 137 | int alloc_fail; |
| 138 | int mask; /* number of rx slots -1 */ |
Brice Goglin | dd50f33 | 2006-12-11 11:25:09 +0100 | [diff] [blame] | 139 | int watchdog_needed; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 140 | }; |
| 141 | |
| 142 | struct myri10ge_tx_buf { |
| 143 | struct mcp_kreq_ether_send __iomem *lanai; /* lanai ptr for sendq */ |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 144 | __be32 __iomem *send_go; /* "go" doorbell ptr */ |
| 145 | __be32 __iomem *send_stop; /* "stop" doorbell ptr */ |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 146 | struct mcp_kreq_ether_send *req_list; /* host shadow of sendq */ |
| 147 | char *req_bytes; |
| 148 | struct myri10ge_tx_buffer_state *info; |
| 149 | int mask; /* number of transmit slots -1 */ |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 150 | int req ____cacheline_aligned; /* transmit slots submitted */ |
| 151 | int pkt_start; /* packets started */ |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 152 | int stop_queue; |
| 153 | int linearized; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 154 | int done ____cacheline_aligned; /* transmit slots completed */ |
| 155 | int pkt_done; /* packets completed */ |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 156 | int wake_queue; |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 157 | int queue_active; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 158 | }; |
| 159 | |
| 160 | struct myri10ge_rx_done { |
| 161 | struct mcp_slot *entry; |
| 162 | dma_addr_t bus; |
| 163 | int cnt; |
| 164 | int idx; |
| 165 | }; |
| 166 | |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 167 | struct myri10ge_slice_netstats { |
| 168 | unsigned long rx_packets; |
| 169 | unsigned long tx_packets; |
| 170 | unsigned long rx_bytes; |
| 171 | unsigned long tx_bytes; |
| 172 | unsigned long rx_dropped; |
| 173 | unsigned long tx_dropped; |
| 174 | }; |
| 175 | |
| 176 | struct myri10ge_slice_state { |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 177 | struct myri10ge_tx_buf tx; /* transmit ring */ |
| 178 | struct myri10ge_rx_buf rx_small; |
| 179 | struct myri10ge_rx_buf rx_big; |
| 180 | struct myri10ge_rx_done rx_done; |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 181 | struct net_device *dev; |
| 182 | struct napi_struct napi; |
| 183 | struct myri10ge_priv *mgp; |
| 184 | struct myri10ge_slice_netstats stats; |
| 185 | __be32 __iomem *irq_claim; |
| 186 | struct mcp_irq_data *fw_stats; |
| 187 | dma_addr_t fw_stats_bus; |
| 188 | int watchdog_tx_done; |
| 189 | int watchdog_tx_req; |
Brice Goglin | d023421 | 2009-08-07 10:44:22 +0000 | [diff] [blame] | 190 | int watchdog_rx_done; |
Jon Mason | c689b81 | 2011-06-27 17:57:28 +0000 | [diff] [blame] | 191 | int stuck; |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 192 | #ifdef CONFIG_MYRI10GE_DCA |
Brice Goglin | 981813d | 2008-05-09 02:22:16 +0200 | [diff] [blame] | 193 | int cached_dca_tag; |
| 194 | int cpu; |
| 195 | __be32 __iomem *dca_tag; |
| 196 | #endif |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 197 | char irq_desc[32]; |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 198 | }; |
| 199 | |
| 200 | struct myri10ge_priv { |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 201 | struct myri10ge_slice_state *ss; |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 202 | int tx_boundary; /* boundary transmits cannot cross */ |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 203 | int num_slices; |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 204 | int running; /* running? */ |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 205 | int small_bytes; |
Brice Goglin | dd50f33 | 2006-12-11 11:25:09 +0100 | [diff] [blame] | 206 | int big_bytes; |
Brice Goglin | fa0a90d | 2008-05-09 02:20:25 +0200 | [diff] [blame] | 207 | int max_intr_slots; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 208 | struct net_device *dev; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 209 | u8 __iomem *sram; |
| 210 | int sram_size; |
| 211 | unsigned long board_span; |
| 212 | unsigned long iomem_base; |
Al Viro | 40f6cff | 2006-11-20 13:48:32 -0500 | [diff] [blame] | 213 | __be32 __iomem *irq_deassert; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 214 | char *mac_addr_string; |
| 215 | struct mcp_cmd_response *cmd; |
| 216 | dma_addr_t cmd_bus; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 217 | struct pci_dev *pdev; |
| 218 | int msi_enabled; |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 219 | int msix_enabled; |
| 220 | struct msix_entry *msix_vectors; |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 221 | #ifdef CONFIG_MYRI10GE_DCA |
Brice Goglin | 981813d | 2008-05-09 02:22:16 +0200 | [diff] [blame] | 222 | int dca_enabled; |
Andrew Gallatin | ef09aad | 2010-09-28 08:13:12 +0000 | [diff] [blame] | 223 | int relaxed_order; |
Brice Goglin | 981813d | 2008-05-09 02:22:16 +0200 | [diff] [blame] | 224 | #endif |
Al Viro | 66341ff | 2007-12-22 18:56:43 +0000 | [diff] [blame] | 225 | u32 link_state; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 226 | unsigned int rdma_tags_available; |
| 227 | int intr_coal_delay; |
Al Viro | 40f6cff | 2006-11-20 13:48:32 -0500 | [diff] [blame] | 228 | __be32 __iomem *intr_coal_delay_ptr; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 229 | int mtrr; |
Brice Goglin | 276e26c | 2007-03-07 20:02:32 +0100 | [diff] [blame] | 230 | int wc_enabled; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 231 | int down_cnt; |
| 232 | wait_queue_head_t down_wq; |
| 233 | struct work_struct watchdog_work; |
| 234 | struct timer_list watchdog_timer; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 235 | int watchdog_resets; |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 236 | int watchdog_pause; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 237 | int pause; |
Rusty Russell | 7d35103 | 2010-08-11 23:04:31 -0600 | [diff] [blame] | 238 | bool fw_name_allocated; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 239 | char *fw_name; |
| 240 | char eeprom_strings[MYRI10GE_EEPROM_STRINGS_SIZE]; |
Brice Goglin | c0bf880 | 2008-05-09 02:18:24 +0200 | [diff] [blame] | 241 | char *product_code_string; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 242 | char fw_version[128]; |
Brice Goglin | 9dc6f0e | 2007-02-21 18:05:17 +0100 | [diff] [blame] | 243 | int fw_ver_major; |
| 244 | int fw_ver_minor; |
| 245 | int fw_ver_tiny; |
| 246 | int adopted_rx_filter_bug; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 247 | u8 mac_addr[6]; /* eeprom mac address */ |
| 248 | unsigned long serial_number; |
| 249 | int vendor_specific_offset; |
Brice Goglin | 85a7ea1 | 2006-08-21 17:36:56 -0400 | [diff] [blame] | 250 | int fw_multicast_support; |
Michał Mirosław | 04ed3e7 | 2011-01-24 15:32:47 -0800 | [diff] [blame] | 251 | u32 features; |
Brice Goglin | 4f93fde | 2007-10-13 12:34:01 +0200 | [diff] [blame] | 252 | u32 max_tso6; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 253 | u32 read_dma; |
| 254 | u32 write_dma; |
| 255 | u32 read_write_dma; |
Brice Goglin | c58ac5c | 2006-08-21 17:36:49 -0400 | [diff] [blame] | 256 | u32 link_changes; |
| 257 | u32 msg_enable; |
Brice Goglin | 2d90b0a | 2009-04-16 02:24:59 +0000 | [diff] [blame] | 258 | unsigned int board_number; |
Brice Goglin | d023421 | 2009-08-07 10:44:22 +0000 | [diff] [blame] | 259 | int rebooted; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 260 | }; |
| 261 | |
| 262 | static char *myri10ge_fw_unaligned = "myri10ge_ethp_z8e.dat"; |
| 263 | static char *myri10ge_fw_aligned = "myri10ge_eth_z8e.dat"; |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 264 | static char *myri10ge_fw_rss_unaligned = "myri10ge_rss_ethp_z8e.dat"; |
| 265 | static char *myri10ge_fw_rss_aligned = "myri10ge_rss_eth_z8e.dat"; |
Ben Hutchings | b9721d5 | 2009-11-07 11:54:44 +0000 | [diff] [blame] | 266 | MODULE_FIRMWARE("myri10ge_ethp_z8e.dat"); |
| 267 | MODULE_FIRMWARE("myri10ge_eth_z8e.dat"); |
| 268 | MODULE_FIRMWARE("myri10ge_rss_ethp_z8e.dat"); |
| 269 | MODULE_FIRMWARE("myri10ge_rss_eth_z8e.dat"); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 270 | |
Rusty Russell | 7d35103 | 2010-08-11 23:04:31 -0600 | [diff] [blame] | 271 | /* Careful: must be accessed under kparam_block_sysfs_write */ |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 272 | static char *myri10ge_fw_name = NULL; |
| 273 | module_param(myri10ge_fw_name, charp, S_IRUGO | S_IWUSR); |
Brice Goglin | d1ce3a0 | 2008-05-09 02:16:53 +0200 | [diff] [blame] | 274 | MODULE_PARM_DESC(myri10ge_fw_name, "Firmware image name"); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 275 | |
Brice Goglin | 2d90b0a | 2009-04-16 02:24:59 +0000 | [diff] [blame] | 276 | #define MYRI10GE_MAX_BOARDS 8 |
| 277 | static char *myri10ge_fw_names[MYRI10GE_MAX_BOARDS] = |
Andrew Gallatin | 7fe624f | 2009-04-17 15:45:15 -0700 | [diff] [blame] | 278 | {[0 ... (MYRI10GE_MAX_BOARDS - 1)] = NULL }; |
Brice Goglin | 2d90b0a | 2009-04-16 02:24:59 +0000 | [diff] [blame] | 279 | module_param_array_named(myri10ge_fw_names, myri10ge_fw_names, charp, NULL, |
| 280 | 0444); |
| 281 | MODULE_PARM_DESC(myri10ge_fw_name, "Firmware image names per board"); |
| 282 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 283 | static int myri10ge_ecrc_enable = 1; |
| 284 | module_param(myri10ge_ecrc_enable, int, S_IRUGO); |
Brice Goglin | d1ce3a0 | 2008-05-09 02:16:53 +0200 | [diff] [blame] | 285 | MODULE_PARM_DESC(myri10ge_ecrc_enable, "Enable Extended CRC on PCI-E"); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 286 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 287 | static int myri10ge_small_bytes = -1; /* -1 == auto */ |
| 288 | module_param(myri10ge_small_bytes, int, S_IRUGO | S_IWUSR); |
Brice Goglin | d1ce3a0 | 2008-05-09 02:16:53 +0200 | [diff] [blame] | 289 | MODULE_PARM_DESC(myri10ge_small_bytes, "Threshold of small packets"); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 290 | |
| 291 | static int myri10ge_msi = 1; /* enable msi by default */ |
Brice Goglin | 3621cec | 2006-12-18 11:51:22 +0100 | [diff] [blame] | 292 | module_param(myri10ge_msi, int, S_IRUGO | S_IWUSR); |
Brice Goglin | d1ce3a0 | 2008-05-09 02:16:53 +0200 | [diff] [blame] | 293 | MODULE_PARM_DESC(myri10ge_msi, "Enable Message Signalled Interrupts"); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 294 | |
Brice Goglin | f761fae | 2007-03-21 19:45:56 +0100 | [diff] [blame] | 295 | static int myri10ge_intr_coal_delay = 75; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 296 | module_param(myri10ge_intr_coal_delay, int, S_IRUGO); |
Brice Goglin | d1ce3a0 | 2008-05-09 02:16:53 +0200 | [diff] [blame] | 297 | MODULE_PARM_DESC(myri10ge_intr_coal_delay, "Interrupt coalescing delay"); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 298 | |
| 299 | static int myri10ge_flow_control = 1; |
| 300 | module_param(myri10ge_flow_control, int, S_IRUGO); |
Brice Goglin | d1ce3a0 | 2008-05-09 02:16:53 +0200 | [diff] [blame] | 301 | MODULE_PARM_DESC(myri10ge_flow_control, "Pause parameter"); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 302 | |
| 303 | static int myri10ge_deassert_wait = 1; |
| 304 | module_param(myri10ge_deassert_wait, int, S_IRUGO | S_IWUSR); |
| 305 | MODULE_PARM_DESC(myri10ge_deassert_wait, |
Brice Goglin | d1ce3a0 | 2008-05-09 02:16:53 +0200 | [diff] [blame] | 306 | "Wait when deasserting legacy interrupts"); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 307 | |
| 308 | static int myri10ge_force_firmware = 0; |
| 309 | module_param(myri10ge_force_firmware, int, S_IRUGO); |
| 310 | MODULE_PARM_DESC(myri10ge_force_firmware, |
Brice Goglin | d1ce3a0 | 2008-05-09 02:16:53 +0200 | [diff] [blame] | 311 | "Force firmware to assume aligned completions"); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 312 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 313 | static int myri10ge_initial_mtu = MYRI10GE_MAX_ETHER_MTU - ETH_HLEN; |
| 314 | module_param(myri10ge_initial_mtu, int, S_IRUGO); |
Brice Goglin | d1ce3a0 | 2008-05-09 02:16:53 +0200 | [diff] [blame] | 315 | MODULE_PARM_DESC(myri10ge_initial_mtu, "Initial MTU"); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 316 | |
| 317 | static int myri10ge_napi_weight = 64; |
| 318 | module_param(myri10ge_napi_weight, int, S_IRUGO); |
Brice Goglin | d1ce3a0 | 2008-05-09 02:16:53 +0200 | [diff] [blame] | 319 | MODULE_PARM_DESC(myri10ge_napi_weight, "Set NAPI weight"); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 320 | |
| 321 | static int myri10ge_watchdog_timeout = 1; |
| 322 | module_param(myri10ge_watchdog_timeout, int, S_IRUGO); |
Brice Goglin | d1ce3a0 | 2008-05-09 02:16:53 +0200 | [diff] [blame] | 323 | MODULE_PARM_DESC(myri10ge_watchdog_timeout, "Set watchdog timeout"); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 324 | |
| 325 | static int myri10ge_max_irq_loops = 1048576; |
| 326 | module_param(myri10ge_max_irq_loops, int, S_IRUGO); |
| 327 | MODULE_PARM_DESC(myri10ge_max_irq_loops, |
Brice Goglin | d1ce3a0 | 2008-05-09 02:16:53 +0200 | [diff] [blame] | 328 | "Set stuck legacy IRQ detection threshold"); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 329 | |
Brice Goglin | c58ac5c | 2006-08-21 17:36:49 -0400 | [diff] [blame] | 330 | #define MYRI10GE_MSG_DEFAULT NETIF_MSG_LINK |
| 331 | |
| 332 | static int myri10ge_debug = -1; /* defaults above */ |
| 333 | module_param(myri10ge_debug, int, 0); |
| 334 | MODULE_PARM_DESC(myri10ge_debug, "Debug level (0=none,...,16=all)"); |
| 335 | |
Brice Goglin | dd50f33 | 2006-12-11 11:25:09 +0100 | [diff] [blame] | 336 | static int myri10ge_fill_thresh = 256; |
| 337 | module_param(myri10ge_fill_thresh, int, S_IRUGO | S_IWUSR); |
Brice Goglin | d1ce3a0 | 2008-05-09 02:16:53 +0200 | [diff] [blame] | 338 | MODULE_PARM_DESC(myri10ge_fill_thresh, "Number of empty rx slots allowed"); |
Brice Goglin | dd50f33 | 2006-12-11 11:25:09 +0100 | [diff] [blame] | 339 | |
Brice Goglin | f181137 | 2007-06-11 20:26:31 +0200 | [diff] [blame] | 340 | static int myri10ge_reset_recover = 1; |
| 341 | |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 342 | static int myri10ge_max_slices = 1; |
| 343 | module_param(myri10ge_max_slices, int, S_IRUGO); |
| 344 | MODULE_PARM_DESC(myri10ge_max_slices, "Max tx/rx queues"); |
| 345 | |
Brice Goglin | 4b860ab | 2009-12-08 20:24:35 -0800 | [diff] [blame] | 346 | static int myri10ge_rss_hash = MXGEFW_RSS_HASH_TYPE_SRC_DST_PORT; |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 347 | module_param(myri10ge_rss_hash, int, S_IRUGO); |
| 348 | MODULE_PARM_DESC(myri10ge_rss_hash, "Type of RSS hashing to do"); |
| 349 | |
Brice Goglin | 981813d | 2008-05-09 02:22:16 +0200 | [diff] [blame] | 350 | static int myri10ge_dca = 1; |
| 351 | module_param(myri10ge_dca, int, S_IRUGO); |
| 352 | MODULE_PARM_DESC(myri10ge_dca, "Enable DCA if possible"); |
| 353 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 354 | #define MYRI10GE_FW_OFFSET 1024*1024 |
| 355 | #define MYRI10GE_HIGHPART_TO_U32(X) \ |
| 356 | (sizeof (X) == 8) ? ((u32)((u64)(X) >> 32)) : (0) |
| 357 | #define MYRI10GE_LOWPART_TO_U32(X) ((u32)(X)) |
| 358 | |
| 359 | #define myri10ge_pio_copy(to,from,size) __iowrite64_copy(to,from,size/8) |
| 360 | |
Brice Goglin | 2f76216 | 2007-05-07 23:50:37 +0200 | [diff] [blame] | 361 | static void myri10ge_set_multicast_list(struct net_device *dev); |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 362 | static netdev_tx_t myri10ge_sw_tso(struct sk_buff *skb, |
| 363 | struct net_device *dev); |
Brice Goglin | 2f76216 | 2007-05-07 23:50:37 +0200 | [diff] [blame] | 364 | |
Brice Goglin | 6250223 | 2006-12-11 11:24:37 +0100 | [diff] [blame] | 365 | static inline void put_be32(__be32 val, __be32 __iomem * p) |
Al Viro | 40f6cff | 2006-11-20 13:48:32 -0500 | [diff] [blame] | 366 | { |
Brice Goglin | 6250223 | 2006-12-11 11:24:37 +0100 | [diff] [blame] | 367 | __raw_writel((__force __u32) val, (__force void __iomem *)p); |
Al Viro | 40f6cff | 2006-11-20 13:48:32 -0500 | [diff] [blame] | 368 | } |
| 369 | |
stephen hemminger | c5f7ef7 | 2011-06-08 14:54:03 +0000 | [diff] [blame] | 370 | static struct rtnl_link_stats64 *myri10ge_get_stats(struct net_device *dev, |
| 371 | struct rtnl_link_stats64 *stats); |
Brice Goglin | 5908182 | 2009-04-16 02:23:56 +0000 | [diff] [blame] | 372 | |
Rusty Russell | 7d35103 | 2010-08-11 23:04:31 -0600 | [diff] [blame] | 373 | static void set_fw_name(struct myri10ge_priv *mgp, char *name, bool allocated) |
| 374 | { |
| 375 | if (mgp->fw_name_allocated) |
| 376 | kfree(mgp->fw_name); |
| 377 | mgp->fw_name = name; |
| 378 | mgp->fw_name_allocated = allocated; |
| 379 | } |
| 380 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 381 | static int |
| 382 | myri10ge_send_cmd(struct myri10ge_priv *mgp, u32 cmd, |
| 383 | struct myri10ge_cmd *data, int atomic) |
| 384 | { |
| 385 | struct mcp_cmd *buf; |
| 386 | char buf_bytes[sizeof(*buf) + 8]; |
| 387 | struct mcp_cmd_response *response = mgp->cmd; |
Brice Goglin | e700f9f | 2006-08-14 17:52:54 -0400 | [diff] [blame] | 388 | char __iomem *cmd_addr = mgp->sram + MXGEFW_ETH_CMD; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 389 | u32 dma_low, dma_high, result, value; |
| 390 | int sleep_total = 0; |
| 391 | |
| 392 | /* ensure buf is aligned to 8 bytes */ |
| 393 | buf = (struct mcp_cmd *)ALIGN((unsigned long)buf_bytes, 8); |
| 394 | |
| 395 | buf->data0 = htonl(data->data0); |
| 396 | buf->data1 = htonl(data->data1); |
| 397 | buf->data2 = htonl(data->data2); |
| 398 | buf->cmd = htonl(cmd); |
| 399 | dma_low = MYRI10GE_LOWPART_TO_U32(mgp->cmd_bus); |
| 400 | dma_high = MYRI10GE_HIGHPART_TO_U32(mgp->cmd_bus); |
| 401 | |
| 402 | buf->response_addr.low = htonl(dma_low); |
| 403 | buf->response_addr.high = htonl(dma_high); |
Al Viro | 40f6cff | 2006-11-20 13:48:32 -0500 | [diff] [blame] | 404 | response->result = htonl(MYRI10GE_NO_RESPONSE_RESULT); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 405 | mb(); |
| 406 | myri10ge_pio_copy(cmd_addr, buf, sizeof(*buf)); |
| 407 | |
| 408 | /* wait up to 15ms. Longest command is the DMA benchmark, |
| 409 | * which is capped at 5ms, but runs from a timeout handler |
| 410 | * that runs every 7.8ms. So a 15ms timeout leaves us with |
| 411 | * a 2.2ms margin |
| 412 | */ |
| 413 | if (atomic) { |
| 414 | /* if atomic is set, do not sleep, |
| 415 | * and try to get the completion quickly |
| 416 | * (1ms will be enough for those commands) */ |
| 417 | for (sleep_total = 0; |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 418 | sleep_total < 1000 && |
| 419 | response->result == htonl(MYRI10GE_NO_RESPONSE_RESULT); |
Brice Goglin | bd2db0c | 2008-05-09 02:18:45 +0200 | [diff] [blame] | 420 | sleep_total += 10) { |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 421 | udelay(10); |
Brice Goglin | bd2db0c | 2008-05-09 02:18:45 +0200 | [diff] [blame] | 422 | mb(); |
| 423 | } |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 424 | } else { |
| 425 | /* use msleep for most command */ |
| 426 | for (sleep_total = 0; |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 427 | sleep_total < 15 && |
| 428 | response->result == htonl(MYRI10GE_NO_RESPONSE_RESULT); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 429 | sleep_total++) |
| 430 | msleep(1); |
| 431 | } |
| 432 | |
| 433 | result = ntohl(response->result); |
| 434 | value = ntohl(response->data); |
| 435 | if (result != MYRI10GE_NO_RESPONSE_RESULT) { |
| 436 | if (result == 0) { |
| 437 | data->data0 = value; |
| 438 | return 0; |
Brice Goglin | 85a7ea1 | 2006-08-21 17:36:56 -0400 | [diff] [blame] | 439 | } else if (result == MXGEFW_CMD_UNKNOWN) { |
| 440 | return -ENOSYS; |
Brice Goglin | 5443e9e | 2007-05-07 23:52:22 +0200 | [diff] [blame] | 441 | } else if (result == MXGEFW_CMD_ERROR_UNALIGNED) { |
| 442 | return -E2BIG; |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 443 | } else if (result == MXGEFW_CMD_ERROR_RANGE && |
| 444 | cmd == MXGEFW_CMD_ENABLE_RSS_QUEUES && |
| 445 | (data-> |
| 446 | data1 & MXGEFW_SLICE_ENABLE_MULTIPLE_TX_QUEUES) != |
| 447 | 0) { |
| 448 | return -ERANGE; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 449 | } else { |
| 450 | dev_err(&mgp->pdev->dev, |
| 451 | "command %d failed, result = %d\n", |
| 452 | cmd, result); |
| 453 | return -ENXIO; |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | dev_err(&mgp->pdev->dev, "command %d timed out, result = %d\n", |
| 458 | cmd, result); |
| 459 | return -EAGAIN; |
| 460 | } |
| 461 | |
| 462 | /* |
| 463 | * The eeprom strings on the lanaiX have the format |
| 464 | * SN=x\0 |
| 465 | * MAC=x:x:x:x:x:x\0 |
| 466 | * PT:ddd mmm xx xx:xx:xx xx\0 |
| 467 | * PV:ddd mmm xx xx:xx:xx xx\0 |
| 468 | */ |
| 469 | static int myri10ge_read_mac_addr(struct myri10ge_priv *mgp) |
| 470 | { |
| 471 | char *ptr, *limit; |
| 472 | int i; |
| 473 | |
| 474 | ptr = mgp->eeprom_strings; |
| 475 | limit = mgp->eeprom_strings + MYRI10GE_EEPROM_STRINGS_SIZE; |
| 476 | |
| 477 | while (*ptr != '\0' && ptr < limit) { |
| 478 | if (memcmp(ptr, "MAC=", 4) == 0) { |
| 479 | ptr += 4; |
| 480 | mgp->mac_addr_string = ptr; |
| 481 | for (i = 0; i < 6; i++) { |
| 482 | if ((ptr + 2) > limit) |
| 483 | goto abort; |
| 484 | mgp->mac_addr[i] = |
| 485 | simple_strtoul(ptr, &ptr, 16); |
| 486 | ptr += 1; |
| 487 | } |
| 488 | } |
Brice Goglin | c0bf880 | 2008-05-09 02:18:24 +0200 | [diff] [blame] | 489 | if (memcmp(ptr, "PC=", 3) == 0) { |
| 490 | ptr += 3; |
| 491 | mgp->product_code_string = ptr; |
| 492 | } |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 493 | if (memcmp((const void *)ptr, "SN=", 3) == 0) { |
| 494 | ptr += 3; |
| 495 | mgp->serial_number = simple_strtoul(ptr, &ptr, 10); |
| 496 | } |
| 497 | while (ptr < limit && *ptr++) ; |
| 498 | } |
| 499 | |
| 500 | return 0; |
| 501 | |
| 502 | abort: |
| 503 | dev_err(&mgp->pdev->dev, "failed to parse eeprom_strings\n"); |
| 504 | return -ENXIO; |
| 505 | } |
| 506 | |
| 507 | /* |
| 508 | * Enable or disable periodic RDMAs from the host to make certain |
| 509 | * chipsets resend dropped PCIe messages |
| 510 | */ |
| 511 | |
| 512 | static void myri10ge_dummy_rdma(struct myri10ge_priv *mgp, int enable) |
| 513 | { |
| 514 | char __iomem *submit; |
Brice Goglin | f8fd57c | 2008-05-09 02:17:37 +0200 | [diff] [blame] | 515 | __be32 buf[16] __attribute__ ((__aligned__(8))); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 516 | u32 dma_low, dma_high; |
| 517 | int i; |
| 518 | |
| 519 | /* clear confirmation addr */ |
| 520 | mgp->cmd->data = 0; |
| 521 | mb(); |
| 522 | |
| 523 | /* send a rdma command to the PCIe engine, and wait for the |
| 524 | * response in the confirmation address. The firmware should |
| 525 | * write a -1 there to indicate it is alive and well |
| 526 | */ |
| 527 | dma_low = MYRI10GE_LOWPART_TO_U32(mgp->cmd_bus); |
| 528 | dma_high = MYRI10GE_HIGHPART_TO_U32(mgp->cmd_bus); |
| 529 | |
| 530 | buf[0] = htonl(dma_high); /* confirm addr MSW */ |
| 531 | buf[1] = htonl(dma_low); /* confirm addr LSW */ |
Al Viro | 40f6cff | 2006-11-20 13:48:32 -0500 | [diff] [blame] | 532 | buf[2] = MYRI10GE_NO_CONFIRM_DATA; /* confirm data */ |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 533 | buf[3] = htonl(dma_high); /* dummy addr MSW */ |
| 534 | buf[4] = htonl(dma_low); /* dummy addr LSW */ |
| 535 | buf[5] = htonl(enable); /* enable? */ |
| 536 | |
Brice Goglin | e700f9f | 2006-08-14 17:52:54 -0400 | [diff] [blame] | 537 | submit = mgp->sram + MXGEFW_BOOT_DUMMY_RDMA; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 538 | |
| 539 | myri10ge_pio_copy(submit, &buf, sizeof(buf)); |
| 540 | for (i = 0; mgp->cmd->data != MYRI10GE_NO_CONFIRM_DATA && i < 20; i++) |
| 541 | msleep(1); |
| 542 | if (mgp->cmd->data != MYRI10GE_NO_CONFIRM_DATA) |
| 543 | dev_err(&mgp->pdev->dev, "dummy rdma %s failed\n", |
| 544 | (enable ? "enable" : "disable")); |
| 545 | } |
| 546 | |
| 547 | static int |
| 548 | myri10ge_validate_firmware(struct myri10ge_priv *mgp, |
| 549 | struct mcp_gen_header *hdr) |
| 550 | { |
| 551 | struct device *dev = &mgp->pdev->dev; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 552 | |
| 553 | /* check firmware type */ |
| 554 | if (ntohl(hdr->mcp_type) != MCP_TYPE_ETH) { |
| 555 | dev_err(dev, "Bad firmware type: 0x%x\n", ntohl(hdr->mcp_type)); |
| 556 | return -EINVAL; |
| 557 | } |
| 558 | |
| 559 | /* save firmware version for ethtool */ |
| 560 | strncpy(mgp->fw_version, hdr->version, sizeof(mgp->fw_version)); |
| 561 | |
Brice Goglin | 9dc6f0e | 2007-02-21 18:05:17 +0100 | [diff] [blame] | 562 | sscanf(mgp->fw_version, "%d.%d.%d", &mgp->fw_ver_major, |
| 563 | &mgp->fw_ver_minor, &mgp->fw_ver_tiny); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 564 | |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 565 | if (!(mgp->fw_ver_major == MXGEFW_VERSION_MAJOR && |
| 566 | mgp->fw_ver_minor == MXGEFW_VERSION_MINOR)) { |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 567 | dev_err(dev, "Found firmware version %s\n", mgp->fw_version); |
| 568 | dev_err(dev, "Driver needs %d.%d\n", MXGEFW_VERSION_MAJOR, |
| 569 | MXGEFW_VERSION_MINOR); |
| 570 | return -EINVAL; |
| 571 | } |
| 572 | return 0; |
| 573 | } |
| 574 | |
| 575 | static int myri10ge_load_hotplug_firmware(struct myri10ge_priv *mgp, u32 * size) |
| 576 | { |
| 577 | unsigned crc, reread_crc; |
| 578 | const struct firmware *fw; |
| 579 | struct device *dev = &mgp->pdev->dev; |
David Woodhouse | b0d31d6 | 2008-05-24 00:00:07 +0100 | [diff] [blame] | 580 | unsigned char *fw_readback; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 581 | struct mcp_gen_header *hdr; |
| 582 | size_t hdr_offset; |
| 583 | int status; |
Brice Goglin | e454358 | 2006-07-30 00:14:09 -0400 | [diff] [blame] | 584 | unsigned i; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 585 | |
| 586 | if ((status = request_firmware(&fw, mgp->fw_name, dev)) < 0) { |
| 587 | dev_err(dev, "Unable to load %s firmware image via hotplug\n", |
| 588 | mgp->fw_name); |
| 589 | status = -EINVAL; |
| 590 | goto abort_with_nothing; |
| 591 | } |
| 592 | |
| 593 | /* check size */ |
| 594 | |
| 595 | if (fw->size >= mgp->sram_size - MYRI10GE_FW_OFFSET || |
| 596 | fw->size < MCP_HEADER_PTR_OFFSET + 4) { |
| 597 | dev_err(dev, "Firmware size invalid:%d\n", (int)fw->size); |
| 598 | status = -EINVAL; |
| 599 | goto abort_with_fw; |
| 600 | } |
| 601 | |
| 602 | /* check id */ |
Al Viro | 40f6cff | 2006-11-20 13:48:32 -0500 | [diff] [blame] | 603 | hdr_offset = ntohl(*(__be32 *) (fw->data + MCP_HEADER_PTR_OFFSET)); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 604 | if ((hdr_offset & 3) || hdr_offset + sizeof(*hdr) > fw->size) { |
| 605 | dev_err(dev, "Bad firmware file\n"); |
| 606 | status = -EINVAL; |
| 607 | goto abort_with_fw; |
| 608 | } |
| 609 | hdr = (void *)(fw->data + hdr_offset); |
| 610 | |
| 611 | status = myri10ge_validate_firmware(mgp, hdr); |
| 612 | if (status != 0) |
| 613 | goto abort_with_fw; |
| 614 | |
| 615 | crc = crc32(~0, fw->data, fw->size); |
Brice Goglin | e454358 | 2006-07-30 00:14:09 -0400 | [diff] [blame] | 616 | for (i = 0; i < fw->size; i += 256) { |
| 617 | myri10ge_pio_copy(mgp->sram + MYRI10GE_FW_OFFSET + i, |
| 618 | fw->data + i, |
| 619 | min(256U, (unsigned)(fw->size - i))); |
| 620 | mb(); |
| 621 | readb(mgp->sram); |
Brice Goglin | b10c066 | 2006-06-08 10:25:00 -0400 | [diff] [blame] | 622 | } |
David Woodhouse | b0d31d6 | 2008-05-24 00:00:07 +0100 | [diff] [blame] | 623 | fw_readback = vmalloc(fw->size); |
| 624 | if (!fw_readback) { |
| 625 | status = -ENOMEM; |
| 626 | goto abort_with_fw; |
| 627 | } |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 628 | /* corruption checking is good for parity recovery and buggy chipset */ |
David Woodhouse | b0d31d6 | 2008-05-24 00:00:07 +0100 | [diff] [blame] | 629 | memcpy_fromio(fw_readback, mgp->sram + MYRI10GE_FW_OFFSET, fw->size); |
| 630 | reread_crc = crc32(~0, fw_readback, fw->size); |
| 631 | vfree(fw_readback); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 632 | if (crc != reread_crc) { |
| 633 | dev_err(dev, "CRC failed(fw-len=%u), got 0x%x (expect 0x%x)\n", |
| 634 | (unsigned)fw->size, reread_crc, crc); |
| 635 | status = -EIO; |
| 636 | goto abort_with_fw; |
| 637 | } |
| 638 | *size = (u32) fw->size; |
| 639 | |
| 640 | abort_with_fw: |
| 641 | release_firmware(fw); |
| 642 | |
| 643 | abort_with_nothing: |
| 644 | return status; |
| 645 | } |
| 646 | |
| 647 | static int myri10ge_adopt_running_firmware(struct myri10ge_priv *mgp) |
| 648 | { |
| 649 | struct mcp_gen_header *hdr; |
| 650 | struct device *dev = &mgp->pdev->dev; |
| 651 | const size_t bytes = sizeof(struct mcp_gen_header); |
| 652 | size_t hdr_offset; |
| 653 | int status; |
| 654 | |
| 655 | /* find running firmware header */ |
Al Viro | 66341ff | 2007-12-22 18:56:43 +0000 | [diff] [blame] | 656 | hdr_offset = swab32(readl(mgp->sram + MCP_HEADER_PTR_OFFSET)); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 657 | |
| 658 | if ((hdr_offset & 3) || hdr_offset + sizeof(*hdr) > mgp->sram_size) { |
| 659 | dev_err(dev, "Running firmware has bad header offset (%d)\n", |
| 660 | (int)hdr_offset); |
| 661 | return -EIO; |
| 662 | } |
| 663 | |
| 664 | /* copy header of running firmware from SRAM to host memory to |
| 665 | * validate firmware */ |
| 666 | hdr = kmalloc(bytes, GFP_KERNEL); |
| 667 | if (hdr == NULL) { |
| 668 | dev_err(dev, "could not malloc firmware hdr\n"); |
| 669 | return -ENOMEM; |
| 670 | } |
| 671 | memcpy_fromio(hdr, mgp->sram + hdr_offset, bytes); |
| 672 | status = myri10ge_validate_firmware(mgp, hdr); |
| 673 | kfree(hdr); |
Brice Goglin | 9dc6f0e | 2007-02-21 18:05:17 +0100 | [diff] [blame] | 674 | |
| 675 | /* check to see if adopted firmware has bug where adopting |
| 676 | * it will cause broadcasts to be filtered unless the NIC |
| 677 | * is kept in ALLMULTI mode */ |
| 678 | if (mgp->fw_ver_major == 1 && mgp->fw_ver_minor == 4 && |
| 679 | mgp->fw_ver_tiny >= 4 && mgp->fw_ver_tiny <= 11) { |
| 680 | mgp->adopted_rx_filter_bug = 1; |
| 681 | dev_warn(dev, "Adopting fw %d.%d.%d: " |
| 682 | "working around rx filter bug\n", |
| 683 | mgp->fw_ver_major, mgp->fw_ver_minor, |
| 684 | mgp->fw_ver_tiny); |
| 685 | } |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 686 | return status; |
| 687 | } |
| 688 | |
Adrian Bunk | 0178ec3 | 2008-05-20 00:53:00 +0300 | [diff] [blame] | 689 | static int myri10ge_get_firmware_capabilities(struct myri10ge_priv *mgp) |
Brice Goglin | fa0a90d | 2008-05-09 02:20:25 +0200 | [diff] [blame] | 690 | { |
| 691 | struct myri10ge_cmd cmd; |
| 692 | int status; |
| 693 | |
| 694 | /* probe for IPv6 TSO support */ |
| 695 | mgp->features = NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_TSO; |
| 696 | status = myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_MAX_TSO6_HDR_SIZE, |
| 697 | &cmd, 0); |
| 698 | if (status == 0) { |
| 699 | mgp->max_tso6 = cmd.data0; |
| 700 | mgp->features |= NETIF_F_TSO6; |
| 701 | } |
| 702 | |
| 703 | status = myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_RX_RING_SIZE, &cmd, 0); |
| 704 | if (status != 0) { |
| 705 | dev_err(&mgp->pdev->dev, |
| 706 | "failed MXGEFW_CMD_GET_RX_RING_SIZE\n"); |
| 707 | return -ENXIO; |
| 708 | } |
| 709 | |
| 710 | mgp->max_intr_slots = 2 * (cmd.data0 / sizeof(struct mcp_dma_addr)); |
| 711 | |
| 712 | return 0; |
| 713 | } |
| 714 | |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 715 | static int myri10ge_load_firmware(struct myri10ge_priv *mgp, int adopt) |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 716 | { |
| 717 | char __iomem *submit; |
Brice Goglin | f8fd57c | 2008-05-09 02:17:37 +0200 | [diff] [blame] | 718 | __be32 buf[16] __attribute__ ((__aligned__(8))); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 719 | u32 dma_low, dma_high, size; |
| 720 | int status, i; |
| 721 | |
Brice Goglin | b10c066 | 2006-06-08 10:25:00 -0400 | [diff] [blame] | 722 | size = 0; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 723 | status = myri10ge_load_hotplug_firmware(mgp, &size); |
| 724 | if (status) { |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 725 | if (!adopt) |
| 726 | return status; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 727 | dev_warn(&mgp->pdev->dev, "hotplug firmware loading failed\n"); |
| 728 | |
| 729 | /* Do not attempt to adopt firmware if there |
| 730 | * was a bad crc */ |
| 731 | if (status == -EIO) |
| 732 | return status; |
| 733 | |
| 734 | status = myri10ge_adopt_running_firmware(mgp); |
| 735 | if (status != 0) { |
| 736 | dev_err(&mgp->pdev->dev, |
| 737 | "failed to adopt running firmware\n"); |
| 738 | return status; |
| 739 | } |
| 740 | dev_info(&mgp->pdev->dev, |
| 741 | "Successfully adopted running firmware\n"); |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 742 | if (mgp->tx_boundary == 4096) { |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 743 | dev_warn(&mgp->pdev->dev, |
| 744 | "Using firmware currently running on NIC" |
| 745 | ". For optimal\n"); |
| 746 | dev_warn(&mgp->pdev->dev, |
| 747 | "performance consider loading optimized " |
| 748 | "firmware\n"); |
| 749 | dev_warn(&mgp->pdev->dev, "via hotplug\n"); |
| 750 | } |
| 751 | |
Rusty Russell | 7d35103 | 2010-08-11 23:04:31 -0600 | [diff] [blame] | 752 | set_fw_name(mgp, "adopted", false); |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 753 | mgp->tx_boundary = 2048; |
Brice Goglin | fa0a90d | 2008-05-09 02:20:25 +0200 | [diff] [blame] | 754 | myri10ge_dummy_rdma(mgp, 1); |
| 755 | status = myri10ge_get_firmware_capabilities(mgp); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 756 | return status; |
| 757 | } |
| 758 | |
| 759 | /* clear confirmation addr */ |
| 760 | mgp->cmd->data = 0; |
| 761 | mb(); |
| 762 | |
| 763 | /* send a reload command to the bootstrap MCP, and wait for the |
| 764 | * response in the confirmation address. The firmware should |
| 765 | * write a -1 there to indicate it is alive and well |
| 766 | */ |
| 767 | dma_low = MYRI10GE_LOWPART_TO_U32(mgp->cmd_bus); |
| 768 | dma_high = MYRI10GE_HIGHPART_TO_U32(mgp->cmd_bus); |
| 769 | |
| 770 | buf[0] = htonl(dma_high); /* confirm addr MSW */ |
| 771 | buf[1] = htonl(dma_low); /* confirm addr LSW */ |
Al Viro | 40f6cff | 2006-11-20 13:48:32 -0500 | [diff] [blame] | 772 | buf[2] = MYRI10GE_NO_CONFIRM_DATA; /* confirm data */ |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 773 | |
| 774 | /* FIX: All newest firmware should un-protect the bottom of |
| 775 | * the sram before handoff. However, the very first interfaces |
| 776 | * do not. Therefore the handoff copy must skip the first 8 bytes |
| 777 | */ |
| 778 | buf[3] = htonl(MYRI10GE_FW_OFFSET + 8); /* where the code starts */ |
| 779 | buf[4] = htonl(size - 8); /* length of code */ |
| 780 | buf[5] = htonl(8); /* where to copy to */ |
| 781 | buf[6] = htonl(0); /* where to jump to */ |
| 782 | |
Brice Goglin | e700f9f | 2006-08-14 17:52:54 -0400 | [diff] [blame] | 783 | submit = mgp->sram + MXGEFW_BOOT_HANDOFF; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 784 | |
| 785 | myri10ge_pio_copy(submit, &buf, sizeof(buf)); |
| 786 | mb(); |
| 787 | msleep(1); |
| 788 | mb(); |
| 789 | i = 0; |
Brice Goglin | d93ca2a | 2008-05-09 02:17:16 +0200 | [diff] [blame] | 790 | while (mgp->cmd->data != MYRI10GE_NO_CONFIRM_DATA && i < 9) { |
| 791 | msleep(1 << i); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 792 | i++; |
| 793 | } |
| 794 | if (mgp->cmd->data != MYRI10GE_NO_CONFIRM_DATA) { |
| 795 | dev_err(&mgp->pdev->dev, "handoff failed\n"); |
| 796 | return -ENXIO; |
| 797 | } |
Brice Goglin | 9a71db7 | 2006-07-21 15:49:32 -0400 | [diff] [blame] | 798 | myri10ge_dummy_rdma(mgp, 1); |
Brice Goglin | fa0a90d | 2008-05-09 02:20:25 +0200 | [diff] [blame] | 799 | status = myri10ge_get_firmware_capabilities(mgp); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 800 | |
Brice Goglin | fa0a90d | 2008-05-09 02:20:25 +0200 | [diff] [blame] | 801 | return status; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | static int myri10ge_update_mac_address(struct myri10ge_priv *mgp, u8 * addr) |
| 805 | { |
| 806 | struct myri10ge_cmd cmd; |
| 807 | int status; |
| 808 | |
| 809 | cmd.data0 = ((addr[0] << 24) | (addr[1] << 16) |
| 810 | | (addr[2] << 8) | addr[3]); |
| 811 | |
| 812 | cmd.data1 = ((addr[4] << 8) | (addr[5])); |
| 813 | |
| 814 | status = myri10ge_send_cmd(mgp, MXGEFW_SET_MAC_ADDRESS, &cmd, 0); |
| 815 | return status; |
| 816 | } |
| 817 | |
| 818 | static int myri10ge_change_pause(struct myri10ge_priv *mgp, int pause) |
| 819 | { |
| 820 | struct myri10ge_cmd cmd; |
| 821 | int status, ctl; |
| 822 | |
| 823 | ctl = pause ? MXGEFW_ENABLE_FLOW_CONTROL : MXGEFW_DISABLE_FLOW_CONTROL; |
| 824 | status = myri10ge_send_cmd(mgp, ctl, &cmd, 0); |
| 825 | |
| 826 | if (status) { |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 827 | netdev_err(mgp->dev, "Failed to set flow control mode\n"); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 828 | return status; |
| 829 | } |
| 830 | mgp->pause = pause; |
| 831 | return 0; |
| 832 | } |
| 833 | |
| 834 | static void |
| 835 | myri10ge_change_promisc(struct myri10ge_priv *mgp, int promisc, int atomic) |
| 836 | { |
| 837 | struct myri10ge_cmd cmd; |
| 838 | int status, ctl; |
| 839 | |
| 840 | ctl = promisc ? MXGEFW_ENABLE_PROMISC : MXGEFW_DISABLE_PROMISC; |
| 841 | status = myri10ge_send_cmd(mgp, ctl, &cmd, atomic); |
| 842 | if (status) |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 843 | netdev_err(mgp->dev, "Failed to set promisc mode\n"); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 844 | } |
| 845 | |
Brice Goglin | 0d6ac25 | 2007-05-07 23:51:45 +0200 | [diff] [blame] | 846 | static int myri10ge_dma_test(struct myri10ge_priv *mgp, int test_type) |
| 847 | { |
| 848 | struct myri10ge_cmd cmd; |
| 849 | int status; |
| 850 | u32 len; |
| 851 | struct page *dmatest_page; |
| 852 | dma_addr_t dmatest_bus; |
| 853 | char *test = " "; |
| 854 | |
| 855 | dmatest_page = alloc_page(GFP_KERNEL); |
| 856 | if (!dmatest_page) |
| 857 | return -ENOMEM; |
| 858 | dmatest_bus = pci_map_page(mgp->pdev, dmatest_page, 0, PAGE_SIZE, |
| 859 | DMA_BIDIRECTIONAL); |
| 860 | |
| 861 | /* Run a small DMA test. |
| 862 | * The magic multipliers to the length tell the firmware |
| 863 | * to do DMA read, write, or read+write tests. The |
| 864 | * results are returned in cmd.data0. The upper 16 |
| 865 | * bits or the return is the number of transfers completed. |
| 866 | * The lower 16 bits is the time in 0.5us ticks that the |
| 867 | * transfers took to complete. |
| 868 | */ |
| 869 | |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 870 | len = mgp->tx_boundary; |
Brice Goglin | 0d6ac25 | 2007-05-07 23:51:45 +0200 | [diff] [blame] | 871 | |
| 872 | cmd.data0 = MYRI10GE_LOWPART_TO_U32(dmatest_bus); |
| 873 | cmd.data1 = MYRI10GE_HIGHPART_TO_U32(dmatest_bus); |
| 874 | cmd.data2 = len * 0x10000; |
| 875 | status = myri10ge_send_cmd(mgp, test_type, &cmd, 0); |
| 876 | if (status != 0) { |
| 877 | test = "read"; |
| 878 | goto abort; |
| 879 | } |
| 880 | mgp->read_dma = ((cmd.data0 >> 16) * len * 2) / (cmd.data0 & 0xffff); |
| 881 | cmd.data0 = MYRI10GE_LOWPART_TO_U32(dmatest_bus); |
| 882 | cmd.data1 = MYRI10GE_HIGHPART_TO_U32(dmatest_bus); |
| 883 | cmd.data2 = len * 0x1; |
| 884 | status = myri10ge_send_cmd(mgp, test_type, &cmd, 0); |
| 885 | if (status != 0) { |
| 886 | test = "write"; |
| 887 | goto abort; |
| 888 | } |
| 889 | mgp->write_dma = ((cmd.data0 >> 16) * len * 2) / (cmd.data0 & 0xffff); |
| 890 | |
| 891 | cmd.data0 = MYRI10GE_LOWPART_TO_U32(dmatest_bus); |
| 892 | cmd.data1 = MYRI10GE_HIGHPART_TO_U32(dmatest_bus); |
| 893 | cmd.data2 = len * 0x10001; |
| 894 | status = myri10ge_send_cmd(mgp, test_type, &cmd, 0); |
| 895 | if (status != 0) { |
| 896 | test = "read/write"; |
| 897 | goto abort; |
| 898 | } |
| 899 | mgp->read_write_dma = ((cmd.data0 >> 16) * len * 2 * 2) / |
| 900 | (cmd.data0 & 0xffff); |
| 901 | |
| 902 | abort: |
| 903 | pci_unmap_page(mgp->pdev, dmatest_bus, PAGE_SIZE, DMA_BIDIRECTIONAL); |
| 904 | put_page(dmatest_page); |
| 905 | |
| 906 | if (status != 0 && test_type != MXGEFW_CMD_UNALIGNED_TEST) |
| 907 | dev_warn(&mgp->pdev->dev, "DMA %s benchmark failed: %d\n", |
| 908 | test, status); |
| 909 | |
| 910 | return status; |
| 911 | } |
| 912 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 913 | static int myri10ge_reset(struct myri10ge_priv *mgp) |
| 914 | { |
| 915 | struct myri10ge_cmd cmd; |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 916 | struct myri10ge_slice_state *ss; |
| 917 | int i, status; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 918 | size_t bytes; |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 919 | #ifdef CONFIG_MYRI10GE_DCA |
Brice Goglin | 981813d | 2008-05-09 02:22:16 +0200 | [diff] [blame] | 920 | unsigned long dca_tag_off; |
| 921 | #endif |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 922 | |
| 923 | /* try to send a reset command to the card to see if it |
| 924 | * is alive */ |
| 925 | memset(&cmd, 0, sizeof(cmd)); |
| 926 | status = myri10ge_send_cmd(mgp, MXGEFW_CMD_RESET, &cmd, 0); |
| 927 | if (status != 0) { |
| 928 | dev_err(&mgp->pdev->dev, "failed reset\n"); |
| 929 | return -ENXIO; |
| 930 | } |
Brice Goglin | 0d6ac25 | 2007-05-07 23:51:45 +0200 | [diff] [blame] | 931 | |
| 932 | (void)myri10ge_dma_test(mgp, MXGEFW_DMA_TEST); |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 933 | /* |
| 934 | * Use non-ndis mcp_slot (eg, 4 bytes total, |
| 935 | * no toeplitz hash value returned. Older firmware will |
| 936 | * not understand this command, but will use the correct |
| 937 | * sized mcp_slot, so we ignore error returns |
| 938 | */ |
| 939 | cmd.data0 = MXGEFW_RSS_MCP_SLOT_TYPE_MIN; |
| 940 | (void)myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_RSS_MCP_SLOT_TYPE, &cmd, 0); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 941 | |
| 942 | /* Now exchange information about interrupts */ |
| 943 | |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 944 | bytes = mgp->max_intr_slots * sizeof(*mgp->ss[0].rx_done.entry); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 945 | cmd.data0 = (u32) bytes; |
| 946 | status = myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_INTRQ_SIZE, &cmd, 0); |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 947 | |
| 948 | /* |
| 949 | * Even though we already know how many slices are supported |
| 950 | * via myri10ge_probe_slices() MXGEFW_CMD_GET_MAX_RSS_QUEUES |
| 951 | * has magic side effects, and must be called after a reset. |
| 952 | * It must be called prior to calling any RSS related cmds, |
| 953 | * including assigning an interrupt queue for anything but |
| 954 | * slice 0. It must also be called *after* |
| 955 | * MXGEFW_CMD_SET_INTRQ_SIZE, since the intrq size is used by |
| 956 | * the firmware to compute offsets. |
| 957 | */ |
| 958 | |
| 959 | if (mgp->num_slices > 1) { |
| 960 | |
| 961 | /* ask the maximum number of slices it supports */ |
| 962 | status = myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_MAX_RSS_QUEUES, |
| 963 | &cmd, 0); |
| 964 | if (status != 0) { |
| 965 | dev_err(&mgp->pdev->dev, |
| 966 | "failed to get number of slices\n"); |
| 967 | } |
| 968 | |
| 969 | /* |
| 970 | * MXGEFW_CMD_ENABLE_RSS_QUEUES must be called prior |
| 971 | * to setting up the interrupt queue DMA |
| 972 | */ |
| 973 | |
| 974 | cmd.data0 = mgp->num_slices; |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 975 | cmd.data1 = MXGEFW_SLICE_INTR_MODE_ONE_PER_SLICE; |
| 976 | if (mgp->dev->real_num_tx_queues > 1) |
| 977 | cmd.data1 |= MXGEFW_SLICE_ENABLE_MULTIPLE_TX_QUEUES; |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 978 | status = myri10ge_send_cmd(mgp, MXGEFW_CMD_ENABLE_RSS_QUEUES, |
| 979 | &cmd, 0); |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 980 | |
| 981 | /* Firmware older than 1.4.32 only supports multiple |
| 982 | * RX queues, so if we get an error, first retry using a |
| 983 | * single TX queue before giving up */ |
| 984 | if (status != 0 && mgp->dev->real_num_tx_queues > 1) { |
Ben Hutchings | c992026 | 2010-09-27 08:30:34 +0000 | [diff] [blame] | 985 | netif_set_real_num_tx_queues(mgp->dev, 1); |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 986 | cmd.data0 = mgp->num_slices; |
| 987 | cmd.data1 = MXGEFW_SLICE_INTR_MODE_ONE_PER_SLICE; |
| 988 | status = myri10ge_send_cmd(mgp, |
| 989 | MXGEFW_CMD_ENABLE_RSS_QUEUES, |
| 990 | &cmd, 0); |
| 991 | } |
| 992 | |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 993 | if (status != 0) { |
| 994 | dev_err(&mgp->pdev->dev, |
| 995 | "failed to set number of slices\n"); |
| 996 | |
| 997 | return status; |
| 998 | } |
| 999 | } |
| 1000 | for (i = 0; i < mgp->num_slices; i++) { |
| 1001 | ss = &mgp->ss[i]; |
| 1002 | cmd.data0 = MYRI10GE_LOWPART_TO_U32(ss->rx_done.bus); |
| 1003 | cmd.data1 = MYRI10GE_HIGHPART_TO_U32(ss->rx_done.bus); |
| 1004 | cmd.data2 = i; |
| 1005 | status |= myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_INTRQ_DMA, |
| 1006 | &cmd, 0); |
Joe Perches | 6403eab | 2011-06-03 11:51:20 +0000 | [diff] [blame] | 1007 | } |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1008 | |
| 1009 | status |= |
| 1010 | myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_IRQ_ACK_OFFSET, &cmd, 0); |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 1011 | for (i = 0; i < mgp->num_slices; i++) { |
| 1012 | ss = &mgp->ss[i]; |
| 1013 | ss->irq_claim = |
| 1014 | (__iomem __be32 *) (mgp->sram + cmd.data0 + 8 * i); |
| 1015 | } |
Brice Goglin | df30a74 | 2006-12-18 11:50:40 +0100 | [diff] [blame] | 1016 | status |= myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_IRQ_DEASSERT_OFFSET, |
| 1017 | &cmd, 0); |
| 1018 | mgp->irq_deassert = (__iomem __be32 *) (mgp->sram + cmd.data0); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1019 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1020 | status |= myri10ge_send_cmd |
| 1021 | (mgp, MXGEFW_CMD_GET_INTR_COAL_DELAY_OFFSET, &cmd, 0); |
Al Viro | 40f6cff | 2006-11-20 13:48:32 -0500 | [diff] [blame] | 1022 | mgp->intr_coal_delay_ptr = (__iomem __be32 *) (mgp->sram + cmd.data0); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1023 | if (status != 0) { |
| 1024 | dev_err(&mgp->pdev->dev, "failed set interrupt parameters\n"); |
| 1025 | return status; |
| 1026 | } |
Al Viro | 40f6cff | 2006-11-20 13:48:32 -0500 | [diff] [blame] | 1027 | put_be32(htonl(mgp->intr_coal_delay), mgp->intr_coal_delay_ptr); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1028 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1029 | #ifdef CONFIG_MYRI10GE_DCA |
Brice Goglin | 981813d | 2008-05-09 02:22:16 +0200 | [diff] [blame] | 1030 | status = myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_DCA_OFFSET, &cmd, 0); |
| 1031 | dca_tag_off = cmd.data0; |
| 1032 | for (i = 0; i < mgp->num_slices; i++) { |
| 1033 | ss = &mgp->ss[i]; |
| 1034 | if (status == 0) { |
| 1035 | ss->dca_tag = (__iomem __be32 *) |
| 1036 | (mgp->sram + dca_tag_off + 4 * i); |
| 1037 | } else { |
| 1038 | ss->dca_tag = NULL; |
| 1039 | } |
| 1040 | } |
Brice Goglin | 4ee2ac5 | 2008-11-23 15:49:28 -0800 | [diff] [blame] | 1041 | #endif /* CONFIG_MYRI10GE_DCA */ |
Brice Goglin | 981813d | 2008-05-09 02:22:16 +0200 | [diff] [blame] | 1042 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1043 | /* reset mcp/driver shared state back to 0 */ |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 1044 | |
Brice Goglin | c58ac5c | 2006-08-21 17:36:49 -0400 | [diff] [blame] | 1045 | mgp->link_changes = 0; |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 1046 | for (i = 0; i < mgp->num_slices; i++) { |
| 1047 | ss = &mgp->ss[i]; |
| 1048 | |
| 1049 | memset(ss->rx_done.entry, 0, bytes); |
| 1050 | ss->tx.req = 0; |
| 1051 | ss->tx.done = 0; |
| 1052 | ss->tx.pkt_start = 0; |
| 1053 | ss->tx.pkt_done = 0; |
| 1054 | ss->rx_big.cnt = 0; |
| 1055 | ss->rx_small.cnt = 0; |
| 1056 | ss->rx_done.idx = 0; |
| 1057 | ss->rx_done.cnt = 0; |
| 1058 | ss->tx.wake_queue = 0; |
| 1059 | ss->tx.stop_queue = 0; |
| 1060 | } |
| 1061 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1062 | status = myri10ge_update_mac_address(mgp, mgp->dev->dev_addr); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1063 | myri10ge_change_pause(mgp, mgp->pause); |
Brice Goglin | 2f76216 | 2007-05-07 23:50:37 +0200 | [diff] [blame] | 1064 | myri10ge_set_multicast_list(mgp->dev); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1065 | return status; |
| 1066 | } |
| 1067 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1068 | #ifdef CONFIG_MYRI10GE_DCA |
Andrew Gallatin | ef09aad | 2010-09-28 08:13:12 +0000 | [diff] [blame] | 1069 | static int myri10ge_toggle_relaxed(struct pci_dev *pdev, int on) |
| 1070 | { |
Jiang Liu | 9503e25 | 2012-07-24 17:20:22 +0800 | [diff] [blame] | 1071 | int ret; |
Andrew Gallatin | ef09aad | 2010-09-28 08:13:12 +0000 | [diff] [blame] | 1072 | u16 ctl; |
| 1073 | |
Jiang Liu | 9503e25 | 2012-07-24 17:20:22 +0800 | [diff] [blame] | 1074 | pcie_capability_read_word(pdev, PCI_EXP_DEVCTL, &ctl); |
Jon Mason | b3b6ae2 | 2011-06-27 10:56:41 +0000 | [diff] [blame] | 1075 | |
Andrew Gallatin | ef09aad | 2010-09-28 08:13:12 +0000 | [diff] [blame] | 1076 | ret = (ctl & PCI_EXP_DEVCTL_RELAX_EN) >> 4; |
| 1077 | if (ret != on) { |
| 1078 | ctl &= ~PCI_EXP_DEVCTL_RELAX_EN; |
| 1079 | ctl |= (on << 4); |
Jiang Liu | 9503e25 | 2012-07-24 17:20:22 +0800 | [diff] [blame] | 1080 | pcie_capability_write_word(pdev, PCI_EXP_DEVCTL, ctl); |
Andrew Gallatin | ef09aad | 2010-09-28 08:13:12 +0000 | [diff] [blame] | 1081 | } |
| 1082 | return ret; |
| 1083 | } |
| 1084 | |
Brice Goglin | 981813d | 2008-05-09 02:22:16 +0200 | [diff] [blame] | 1085 | static void |
| 1086 | myri10ge_write_dca(struct myri10ge_slice_state *ss, int cpu, int tag) |
| 1087 | { |
Brice Goglin | 981813d | 2008-05-09 02:22:16 +0200 | [diff] [blame] | 1088 | ss->cached_dca_tag = tag; |
| 1089 | put_be32(htonl(tag), ss->dca_tag); |
| 1090 | } |
| 1091 | |
| 1092 | static inline void myri10ge_update_dca(struct myri10ge_slice_state *ss) |
| 1093 | { |
| 1094 | int cpu = get_cpu(); |
| 1095 | int tag; |
| 1096 | |
| 1097 | if (cpu != ss->cpu) { |
Andrew Gallatin | ef09aad | 2010-09-28 08:13:12 +0000 | [diff] [blame] | 1098 | tag = dca3_get_tag(&ss->mgp->pdev->dev, cpu); |
Brice Goglin | 981813d | 2008-05-09 02:22:16 +0200 | [diff] [blame] | 1099 | if (ss->cached_dca_tag != tag) |
| 1100 | myri10ge_write_dca(ss, cpu, tag); |
Andrew Gallatin | ef09aad | 2010-09-28 08:13:12 +0000 | [diff] [blame] | 1101 | ss->cpu = cpu; |
Brice Goglin | 981813d | 2008-05-09 02:22:16 +0200 | [diff] [blame] | 1102 | } |
| 1103 | put_cpu(); |
| 1104 | } |
| 1105 | |
| 1106 | static void myri10ge_setup_dca(struct myri10ge_priv *mgp) |
| 1107 | { |
| 1108 | int err, i; |
| 1109 | struct pci_dev *pdev = mgp->pdev; |
| 1110 | |
| 1111 | if (mgp->ss[0].dca_tag == NULL || mgp->dca_enabled) |
| 1112 | return; |
| 1113 | if (!myri10ge_dca) { |
| 1114 | dev_err(&pdev->dev, "dca disabled by administrator\n"); |
| 1115 | return; |
| 1116 | } |
| 1117 | err = dca_add_requester(&pdev->dev); |
| 1118 | if (err) { |
Brice Goglin | 330554c | 2008-09-12 19:47:26 +0200 | [diff] [blame] | 1119 | if (err != -ENODEV) |
| 1120 | dev_err(&pdev->dev, |
| 1121 | "dca_add_requester() failed, err=%d\n", err); |
Brice Goglin | 981813d | 2008-05-09 02:22:16 +0200 | [diff] [blame] | 1122 | return; |
| 1123 | } |
Andrew Gallatin | ef09aad | 2010-09-28 08:13:12 +0000 | [diff] [blame] | 1124 | mgp->relaxed_order = myri10ge_toggle_relaxed(pdev, 0); |
Brice Goglin | 981813d | 2008-05-09 02:22:16 +0200 | [diff] [blame] | 1125 | mgp->dca_enabled = 1; |
Andrew Gallatin | ef09aad | 2010-09-28 08:13:12 +0000 | [diff] [blame] | 1126 | for (i = 0; i < mgp->num_slices; i++) { |
| 1127 | mgp->ss[i].cpu = -1; |
| 1128 | mgp->ss[i].cached_dca_tag = -1; |
| 1129 | myri10ge_update_dca(&mgp->ss[i]); |
Jon Mason | b3b6ae2 | 2011-06-27 10:56:41 +0000 | [diff] [blame] | 1130 | } |
Brice Goglin | 981813d | 2008-05-09 02:22:16 +0200 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | static void myri10ge_teardown_dca(struct myri10ge_priv *mgp) |
| 1134 | { |
| 1135 | struct pci_dev *pdev = mgp->pdev; |
Brice Goglin | 981813d | 2008-05-09 02:22:16 +0200 | [diff] [blame] | 1136 | |
| 1137 | if (!mgp->dca_enabled) |
| 1138 | return; |
| 1139 | mgp->dca_enabled = 0; |
Andrew Gallatin | ef09aad | 2010-09-28 08:13:12 +0000 | [diff] [blame] | 1140 | if (mgp->relaxed_order) |
| 1141 | myri10ge_toggle_relaxed(pdev, 1); |
Jon Mason | b3b6ae2 | 2011-06-27 10:56:41 +0000 | [diff] [blame] | 1142 | dca_remove_requester(&pdev->dev); |
Brice Goglin | 981813d | 2008-05-09 02:22:16 +0200 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | static int myri10ge_notify_dca_device(struct device *dev, void *data) |
| 1146 | { |
| 1147 | struct myri10ge_priv *mgp; |
| 1148 | unsigned long event; |
| 1149 | |
| 1150 | mgp = dev_get_drvdata(dev); |
| 1151 | event = *(unsigned long *)data; |
| 1152 | |
| 1153 | if (event == DCA_PROVIDER_ADD) |
| 1154 | myri10ge_setup_dca(mgp); |
| 1155 | else if (event == DCA_PROVIDER_REMOVE) |
| 1156 | myri10ge_teardown_dca(mgp); |
| 1157 | return 0; |
| 1158 | } |
Brice Goglin | 4ee2ac5 | 2008-11-23 15:49:28 -0800 | [diff] [blame] | 1159 | #endif /* CONFIG_MYRI10GE_DCA */ |
Brice Goglin | 981813d | 2008-05-09 02:22:16 +0200 | [diff] [blame] | 1160 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1161 | static inline void |
| 1162 | myri10ge_submit_8rx(struct mcp_kreq_ether_recv __iomem * dst, |
| 1163 | struct mcp_kreq_ether_recv *src) |
| 1164 | { |
Al Viro | 40f6cff | 2006-11-20 13:48:32 -0500 | [diff] [blame] | 1165 | __be32 low; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1166 | |
| 1167 | low = src->addr_low; |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 1168 | src->addr_low = htonl(DMA_BIT_MASK(32)); |
Brice Goglin | e67bda5 | 2006-12-05 17:26:27 +0100 | [diff] [blame] | 1169 | myri10ge_pio_copy(dst, src, 4 * sizeof(*src)); |
| 1170 | mb(); |
| 1171 | myri10ge_pio_copy(dst + 4, src + 4, 4 * sizeof(*src)); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1172 | mb(); |
| 1173 | src->addr_low = low; |
Al Viro | 40f6cff | 2006-11-20 13:48:32 -0500 | [diff] [blame] | 1174 | put_be32(low, &dst->addr_low); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1175 | mb(); |
| 1176 | } |
| 1177 | |
Al Viro | 40f6cff | 2006-11-20 13:48:32 -0500 | [diff] [blame] | 1178 | static inline void myri10ge_vlan_ip_csum(struct sk_buff *skb, __wsum hw_csum) |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1179 | { |
| 1180 | struct vlan_hdr *vh = (struct vlan_hdr *)(skb->data); |
| 1181 | |
Al Viro | 40f6cff | 2006-11-20 13:48:32 -0500 | [diff] [blame] | 1182 | if ((skb->protocol == htons(ETH_P_8021Q)) && |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1183 | (vh->h_vlan_encapsulated_proto == htons(ETH_P_IP) || |
| 1184 | vh->h_vlan_encapsulated_proto == htons(ETH_P_IPV6))) { |
| 1185 | skb->csum = hw_csum; |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 1186 | skb->ip_summed = CHECKSUM_COMPLETE; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1187 | } |
| 1188 | } |
| 1189 | |
Brice Goglin | dd50f33 | 2006-12-11 11:25:09 +0100 | [diff] [blame] | 1190 | static void |
| 1191 | myri10ge_alloc_rx_pages(struct myri10ge_priv *mgp, struct myri10ge_rx_buf *rx, |
| 1192 | int bytes, int watchdog) |
| 1193 | { |
| 1194 | struct page *page; |
| 1195 | int idx; |
Brice Goglin | 2a3f279 | 2010-02-24 12:11:19 +0000 | [diff] [blame] | 1196 | #if MYRI10GE_ALLOC_SIZE > 4096 |
| 1197 | int end_offset; |
| 1198 | #endif |
Brice Goglin | dd50f33 | 2006-12-11 11:25:09 +0100 | [diff] [blame] | 1199 | |
| 1200 | if (unlikely(rx->watchdog_needed && !watchdog)) |
| 1201 | return; |
| 1202 | |
| 1203 | /* try to refill entire ring */ |
| 1204 | while (rx->fill_cnt != (rx->cnt + rx->mask + 1)) { |
| 1205 | idx = rx->fill_cnt & rx->mask; |
Brice Goglin | ae8509b | 2007-04-10 21:21:08 +0200 | [diff] [blame] | 1206 | if (rx->page_offset + bytes <= MYRI10GE_ALLOC_SIZE) { |
Brice Goglin | dd50f33 | 2006-12-11 11:25:09 +0100 | [diff] [blame] | 1207 | /* we can use part of previous page */ |
| 1208 | get_page(rx->page); |
| 1209 | } else { |
| 1210 | /* we need a new page */ |
| 1211 | page = |
| 1212 | alloc_pages(GFP_ATOMIC | __GFP_COMP, |
| 1213 | MYRI10GE_ALLOC_ORDER); |
| 1214 | if (unlikely(page == NULL)) { |
| 1215 | if (rx->fill_cnt - rx->cnt < 16) |
| 1216 | rx->watchdog_needed = 1; |
| 1217 | return; |
| 1218 | } |
| 1219 | rx->page = page; |
| 1220 | rx->page_offset = 0; |
| 1221 | rx->bus = pci_map_page(mgp->pdev, page, 0, |
| 1222 | MYRI10GE_ALLOC_SIZE, |
| 1223 | PCI_DMA_FROMDEVICE); |
| 1224 | } |
| 1225 | rx->info[idx].page = rx->page; |
| 1226 | rx->info[idx].page_offset = rx->page_offset; |
| 1227 | /* note that this is the address of the start of the |
| 1228 | * page */ |
FUJITA Tomonori | c755b4b | 2010-04-12 14:32:10 +0000 | [diff] [blame] | 1229 | dma_unmap_addr_set(&rx->info[idx], bus, rx->bus); |
Brice Goglin | dd50f33 | 2006-12-11 11:25:09 +0100 | [diff] [blame] | 1230 | rx->shadow[idx].addr_low = |
| 1231 | htonl(MYRI10GE_LOWPART_TO_U32(rx->bus) + rx->page_offset); |
| 1232 | rx->shadow[idx].addr_high = |
| 1233 | htonl(MYRI10GE_HIGHPART_TO_U32(rx->bus)); |
| 1234 | |
| 1235 | /* start next packet on a cacheline boundary */ |
| 1236 | rx->page_offset += SKB_DATA_ALIGN(bytes); |
Brice Goglin | ae8509b | 2007-04-10 21:21:08 +0200 | [diff] [blame] | 1237 | |
| 1238 | #if MYRI10GE_ALLOC_SIZE > 4096 |
| 1239 | /* don't cross a 4KB boundary */ |
Brice Goglin | 2a3f279 | 2010-02-24 12:11:19 +0000 | [diff] [blame] | 1240 | end_offset = rx->page_offset + bytes - 1; |
| 1241 | if ((unsigned)(rx->page_offset ^ end_offset) > 4095) |
| 1242 | rx->page_offset = end_offset & ~4095; |
Brice Goglin | ae8509b | 2007-04-10 21:21:08 +0200 | [diff] [blame] | 1243 | #endif |
Brice Goglin | dd50f33 | 2006-12-11 11:25:09 +0100 | [diff] [blame] | 1244 | rx->fill_cnt++; |
| 1245 | |
| 1246 | /* copy 8 descriptors to the firmware at a time */ |
| 1247 | if ((idx & 7) == 7) { |
Brice Goglin | e454e7e | 2008-07-21 10:25:50 +0200 | [diff] [blame] | 1248 | myri10ge_submit_8rx(&rx->lanai[idx - 7], |
| 1249 | &rx->shadow[idx - 7]); |
Brice Goglin | dd50f33 | 2006-12-11 11:25:09 +0100 | [diff] [blame] | 1250 | } |
| 1251 | } |
| 1252 | } |
| 1253 | |
| 1254 | static inline void |
| 1255 | myri10ge_unmap_rx_page(struct pci_dev *pdev, |
| 1256 | struct myri10ge_rx_buffer_state *info, int bytes) |
| 1257 | { |
| 1258 | /* unmap the recvd page if we're the only or last user of it */ |
| 1259 | if (bytes >= MYRI10GE_ALLOC_SIZE / 2 || |
| 1260 | (info->page_offset + 2 * bytes) > MYRI10GE_ALLOC_SIZE) { |
FUJITA Tomonori | c755b4b | 2010-04-12 14:32:10 +0000 | [diff] [blame] | 1261 | pci_unmap_page(pdev, (dma_unmap_addr(info, bus) |
Brice Goglin | dd50f33 | 2006-12-11 11:25:09 +0100 | [diff] [blame] | 1262 | & ~(MYRI10GE_ALLOC_SIZE - 1)), |
| 1263 | MYRI10GE_ALLOC_SIZE, PCI_DMA_FROMDEVICE); |
| 1264 | } |
| 1265 | } |
| 1266 | |
Andrew Gallatin | 1b4c44e | 2012-11-30 08:31:59 +0000 | [diff] [blame] | 1267 | /* |
| 1268 | * GRO does not support acceleration of tagged vlan frames, and |
| 1269 | * this NIC does not support vlan tag offload, so we must pop |
| 1270 | * the tag ourselves to be able to achieve GRO performance that |
| 1271 | * is comparable to LRO. |
| 1272 | */ |
| 1273 | |
| 1274 | static inline void |
| 1275 | myri10ge_vlan_rx(struct net_device *dev, void *addr, struct sk_buff *skb) |
| 1276 | { |
| 1277 | u8 *va; |
| 1278 | struct vlan_ethhdr *veh; |
| 1279 | struct skb_frag_struct *frag; |
| 1280 | __wsum vsum; |
| 1281 | |
| 1282 | va = addr; |
| 1283 | va += MXGEFW_PAD; |
| 1284 | veh = (struct vlan_ethhdr *)va; |
| 1285 | if ((dev->features & NETIF_F_HW_VLAN_RX) == NETIF_F_HW_VLAN_RX && |
Andrew Gallatin | 30828d2 | 2012-11-30 12:31:26 +0000 | [diff] [blame] | 1286 | veh->h_vlan_proto == htons(ETH_P_8021Q)) { |
Andrew Gallatin | 1b4c44e | 2012-11-30 08:31:59 +0000 | [diff] [blame] | 1287 | /* fixup csum if needed */ |
| 1288 | if (skb->ip_summed == CHECKSUM_COMPLETE) { |
| 1289 | vsum = csum_partial(va + ETH_HLEN, VLAN_HLEN, 0); |
| 1290 | skb->csum = csum_sub(skb->csum, vsum); |
| 1291 | } |
| 1292 | /* pop tag */ |
| 1293 | __vlan_hwaccel_put_tag(skb, ntohs(veh->h_vlan_TCI)); |
| 1294 | memmove(va + VLAN_HLEN, va, 2 * ETH_ALEN); |
| 1295 | skb->len -= VLAN_HLEN; |
| 1296 | skb->data_len -= VLAN_HLEN; |
| 1297 | frag = skb_shinfo(skb)->frags; |
| 1298 | frag->page_offset += VLAN_HLEN; |
| 1299 | skb_frag_size_set(frag, skb_frag_size(frag) - VLAN_HLEN); |
| 1300 | } |
| 1301 | } |
| 1302 | |
Brice Goglin | dd50f33 | 2006-12-11 11:25:09 +0100 | [diff] [blame] | 1303 | static inline int |
Andrew Gallatin | 4ca3221 | 2012-11-30 08:31:58 +0000 | [diff] [blame] | 1304 | myri10ge_rx_done(struct myri10ge_slice_state *ss, int len, __wsum csum) |
Brice Goglin | dd50f33 | 2006-12-11 11:25:09 +0100 | [diff] [blame] | 1305 | { |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1306 | struct myri10ge_priv *mgp = ss->mgp; |
Brice Goglin | dd50f33 | 2006-12-11 11:25:09 +0100 | [diff] [blame] | 1307 | struct sk_buff *skb; |
Andrew Gallatin | 4ca3221 | 2012-11-30 08:31:58 +0000 | [diff] [blame] | 1308 | struct skb_frag_struct *rx_frags; |
Stanislaw Gruszka | b3cd965 | 2011-03-25 01:21:51 +0000 | [diff] [blame] | 1309 | struct myri10ge_rx_buf *rx; |
Andrew Gallatin | 4ca3221 | 2012-11-30 08:31:58 +0000 | [diff] [blame] | 1310 | int i, idx, remainder, bytes; |
Brice Goglin | dd50f33 | 2006-12-11 11:25:09 +0100 | [diff] [blame] | 1311 | struct pci_dev *pdev = mgp->pdev; |
| 1312 | struct net_device *dev = mgp->dev; |
| 1313 | u8 *va; |
| 1314 | |
Stanislaw Gruszka | b3cd965 | 2011-03-25 01:21:51 +0000 | [diff] [blame] | 1315 | if (len <= mgp->small_bytes) { |
| 1316 | rx = &ss->rx_small; |
| 1317 | bytes = mgp->small_bytes; |
| 1318 | } else { |
| 1319 | rx = &ss->rx_big; |
| 1320 | bytes = mgp->big_bytes; |
| 1321 | } |
| 1322 | |
Brice Goglin | dd50f33 | 2006-12-11 11:25:09 +0100 | [diff] [blame] | 1323 | len += MXGEFW_PAD; |
| 1324 | idx = rx->cnt & rx->mask; |
| 1325 | va = page_address(rx->info[idx].page) + rx->info[idx].page_offset; |
| 1326 | prefetch(va); |
Andrew Gallatin | 4ca3221 | 2012-11-30 08:31:58 +0000 | [diff] [blame] | 1327 | |
| 1328 | skb = napi_get_frags(&ss->napi); |
| 1329 | if (unlikely(skb == NULL)) { |
| 1330 | ss->stats.rx_dropped++; |
| 1331 | for (i = 0, remainder = len; remainder > 0; i++) { |
| 1332 | myri10ge_unmap_rx_page(pdev, &rx->info[idx], bytes); |
| 1333 | put_page(rx->info[idx].page); |
| 1334 | rx->cnt++; |
| 1335 | idx = rx->cnt & rx->mask; |
| 1336 | remainder -= MYRI10GE_ALLOC_SIZE; |
| 1337 | } |
| 1338 | return 0; |
| 1339 | } |
| 1340 | rx_frags = skb_shinfo(skb)->frags; |
Brice Goglin | dd50f33 | 2006-12-11 11:25:09 +0100 | [diff] [blame] | 1341 | /* Fill skb_frag_struct(s) with data from our receive */ |
| 1342 | for (i = 0, remainder = len; remainder > 0; i++) { |
| 1343 | myri10ge_unmap_rx_page(pdev, &rx->info[idx], bytes); |
Andrew Gallatin | 4ca3221 | 2012-11-30 08:31:58 +0000 | [diff] [blame] | 1344 | skb_fill_page_desc(skb, i, rx->info[idx].page, |
| 1345 | rx->info[idx].page_offset, |
| 1346 | remainder < MYRI10GE_ALLOC_SIZE ? |
| 1347 | remainder : MYRI10GE_ALLOC_SIZE); |
Brice Goglin | dd50f33 | 2006-12-11 11:25:09 +0100 | [diff] [blame] | 1348 | rx->cnt++; |
| 1349 | idx = rx->cnt & rx->mask; |
| 1350 | remainder -= MYRI10GE_ALLOC_SIZE; |
| 1351 | } |
| 1352 | |
Andrew Gallatin | 4ca3221 | 2012-11-30 08:31:58 +0000 | [diff] [blame] | 1353 | /* remove padding */ |
| 1354 | rx_frags[0].page_offset += MXGEFW_PAD; |
| 1355 | rx_frags[0].size -= MXGEFW_PAD; |
| 1356 | len -= MXGEFW_PAD; |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 1357 | |
Andrew Gallatin | 4ca3221 | 2012-11-30 08:31:58 +0000 | [diff] [blame] | 1358 | skb->len = len; |
| 1359 | skb->data_len = len; |
| 1360 | skb->truesize += len; |
| 1361 | if (dev->features & NETIF_F_RXCSUM) { |
| 1362 | skb->ip_summed = CHECKSUM_COMPLETE; |
| 1363 | skb->csum = csum; |
Andrew Gallatin | 1e6e934 | 2007-09-17 11:37:42 -0700 | [diff] [blame] | 1364 | } |
Andrew Gallatin | 1b4c44e | 2012-11-30 08:31:59 +0000 | [diff] [blame] | 1365 | myri10ge_vlan_rx(mgp->dev, va, skb); |
David S. Miller | 0c8dfc8 | 2009-01-27 16:22:32 -0800 | [diff] [blame] | 1366 | skb_record_rx_queue(skb, ss - &mgp->ss[0]); |
Brice Goglin | dd50f33 | 2006-12-11 11:25:09 +0100 | [diff] [blame] | 1367 | |
Andrew Gallatin | 4ca3221 | 2012-11-30 08:31:58 +0000 | [diff] [blame] | 1368 | napi_gro_frags(&ss->napi); |
Brice Goglin | dd50f33 | 2006-12-11 11:25:09 +0100 | [diff] [blame] | 1369 | return 1; |
| 1370 | } |
| 1371 | |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1372 | static inline void |
| 1373 | myri10ge_tx_done(struct myri10ge_slice_state *ss, int mcp_index) |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1374 | { |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1375 | struct pci_dev *pdev = ss->mgp->pdev; |
| 1376 | struct myri10ge_tx_buf *tx = &ss->tx; |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 1377 | struct netdev_queue *dev_queue; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1378 | struct sk_buff *skb; |
| 1379 | int idx, len; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1380 | |
| 1381 | while (tx->pkt_done != mcp_index) { |
| 1382 | idx = tx->done & tx->mask; |
| 1383 | skb = tx->info[idx].skb; |
| 1384 | |
| 1385 | /* Mark as free */ |
| 1386 | tx->info[idx].skb = NULL; |
| 1387 | if (tx->info[idx].last) { |
| 1388 | tx->pkt_done++; |
| 1389 | tx->info[idx].last = 0; |
| 1390 | } |
| 1391 | tx->done++; |
FUJITA Tomonori | c755b4b | 2010-04-12 14:32:10 +0000 | [diff] [blame] | 1392 | len = dma_unmap_len(&tx->info[idx], len); |
| 1393 | dma_unmap_len_set(&tx->info[idx], len, 0); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1394 | if (skb) { |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1395 | ss->stats.tx_bytes += skb->len; |
| 1396 | ss->stats.tx_packets++; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1397 | dev_kfree_skb_irq(skb); |
| 1398 | if (len) |
| 1399 | pci_unmap_single(pdev, |
FUJITA Tomonori | c755b4b | 2010-04-12 14:32:10 +0000 | [diff] [blame] | 1400 | dma_unmap_addr(&tx->info[idx], |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1401 | bus), len, |
| 1402 | PCI_DMA_TODEVICE); |
| 1403 | } else { |
| 1404 | if (len) |
| 1405 | pci_unmap_page(pdev, |
FUJITA Tomonori | c755b4b | 2010-04-12 14:32:10 +0000 | [diff] [blame] | 1406 | dma_unmap_addr(&tx->info[idx], |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1407 | bus), len, |
| 1408 | PCI_DMA_TODEVICE); |
| 1409 | } |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1410 | } |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 1411 | |
| 1412 | dev_queue = netdev_get_tx_queue(ss->dev, ss - ss->mgp->ss); |
| 1413 | /* |
| 1414 | * Make a minimal effort to prevent the NIC from polling an |
| 1415 | * idle tx queue. If we can't get the lock we leave the queue |
| 1416 | * active. In this case, either a thread was about to start |
| 1417 | * using the queue anyway, or we lost a race and the NIC will |
| 1418 | * waste some of its resources polling an inactive queue for a |
| 1419 | * while. |
| 1420 | */ |
| 1421 | |
| 1422 | if ((ss->mgp->dev->real_num_tx_queues > 1) && |
| 1423 | __netif_tx_trylock(dev_queue)) { |
| 1424 | if (tx->req == tx->done) { |
| 1425 | tx->queue_active = 0; |
| 1426 | put_be32(htonl(1), tx->send_stop); |
Brice Goglin | 8c2f5fa | 2008-11-10 13:58:41 +0100 | [diff] [blame] | 1427 | mb(); |
Brice Goglin | 6824a10 | 2008-10-30 08:59:33 +0100 | [diff] [blame] | 1428 | mmiowb(); |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 1429 | } |
| 1430 | __netif_tx_unlock(dev_queue); |
| 1431 | } |
| 1432 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1433 | /* start the queue if we've stopped it */ |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 1434 | if (netif_tx_queue_stopped(dev_queue) && |
Jon Mason | 3b20b2d | 2011-06-27 05:05:00 +0000 | [diff] [blame] | 1435 | tx->req - tx->done < (tx->mask >> 1) && |
| 1436 | ss->mgp->running == MYRI10GE_ETH_RUNNING) { |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1437 | tx->wake_queue++; |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 1438 | netif_tx_wake_queue(dev_queue); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1439 | } |
| 1440 | } |
| 1441 | |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1442 | static inline int |
| 1443 | myri10ge_clean_rx_done(struct myri10ge_slice_state *ss, int budget) |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1444 | { |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1445 | struct myri10ge_rx_done *rx_done = &ss->rx_done; |
| 1446 | struct myri10ge_priv *mgp = ss->mgp; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1447 | unsigned long rx_bytes = 0; |
| 1448 | unsigned long rx_packets = 0; |
| 1449 | unsigned long rx_ok; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1450 | int idx = rx_done->idx; |
| 1451 | int cnt = rx_done->cnt; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1452 | int work_done = 0; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1453 | u16 length; |
Al Viro | 40f6cff | 2006-11-20 13:48:32 -0500 | [diff] [blame] | 1454 | __wsum checksum; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1455 | |
Andrew Gallatin | c956a24 | 2007-10-31 17:40:06 -0400 | [diff] [blame] | 1456 | while (rx_done->entry[idx].length != 0 && work_done < budget) { |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1457 | length = ntohs(rx_done->entry[idx].length); |
| 1458 | rx_done->entry[idx].length = 0; |
Al Viro | 40f6cff | 2006-11-20 13:48:32 -0500 | [diff] [blame] | 1459 | checksum = csum_unfold(rx_done->entry[idx].checksum); |
Andrew Gallatin | 4ca3221 | 2012-11-30 08:31:58 +0000 | [diff] [blame] | 1460 | rx_ok = myri10ge_rx_done(ss, length, checksum); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1461 | rx_packets += rx_ok; |
| 1462 | rx_bytes += rx_ok * (unsigned long)length; |
| 1463 | cnt++; |
Brice Goglin | 014377a | 2008-05-09 02:20:47 +0200 | [diff] [blame] | 1464 | idx = cnt & (mgp->max_intr_slots - 1); |
Andrew Gallatin | c956a24 | 2007-10-31 17:40:06 -0400 | [diff] [blame] | 1465 | work_done++; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1466 | } |
| 1467 | rx_done->idx = idx; |
| 1468 | rx_done->cnt = cnt; |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1469 | ss->stats.rx_packets += rx_packets; |
| 1470 | ss->stats.rx_bytes += rx_bytes; |
Brice Goglin | c7dab99 | 2006-12-11 11:25:42 +0100 | [diff] [blame] | 1471 | |
| 1472 | /* restock receive rings if needed */ |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1473 | if (ss->rx_small.fill_cnt - ss->rx_small.cnt < myri10ge_fill_thresh) |
| 1474 | myri10ge_alloc_rx_pages(mgp, &ss->rx_small, |
Brice Goglin | c7dab99 | 2006-12-11 11:25:42 +0100 | [diff] [blame] | 1475 | mgp->small_bytes + MXGEFW_PAD, 0); |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1476 | if (ss->rx_big.fill_cnt - ss->rx_big.cnt < myri10ge_fill_thresh) |
| 1477 | myri10ge_alloc_rx_pages(mgp, &ss->rx_big, mgp->big_bytes, 0); |
Brice Goglin | c7dab99 | 2006-12-11 11:25:42 +0100 | [diff] [blame] | 1478 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1479 | return work_done; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1480 | } |
| 1481 | |
| 1482 | static inline void myri10ge_check_statblock(struct myri10ge_priv *mgp) |
| 1483 | { |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 1484 | struct mcp_irq_data *stats = mgp->ss[0].fw_stats; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1485 | |
| 1486 | if (unlikely(stats->stats_updated)) { |
Brice Goglin | 798a95d | 2007-06-11 20:26:50 +0200 | [diff] [blame] | 1487 | unsigned link_up = ntohl(stats->link_up); |
| 1488 | if (mgp->link_state != link_up) { |
| 1489 | mgp->link_state = link_up; |
| 1490 | |
| 1491 | if (mgp->link_state == MXGEFW_LINK_UP) { |
Jon Mason | b3b6ae2 | 2011-06-27 10:56:41 +0000 | [diff] [blame] | 1492 | netif_info(mgp, link, mgp->dev, "link up\n"); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1493 | netif_carrier_on(mgp->dev); |
Brice Goglin | c58ac5c | 2006-08-21 17:36:49 -0400 | [diff] [blame] | 1494 | mgp->link_changes++; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1495 | } else { |
Jon Mason | b3b6ae2 | 2011-06-27 10:56:41 +0000 | [diff] [blame] | 1496 | netif_info(mgp, link, mgp->dev, "link %s\n", |
| 1497 | (link_up == MXGEFW_LINK_MYRINET ? |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 1498 | "mismatch (Myrinet detected)" : |
Jon Mason | b3b6ae2 | 2011-06-27 10:56:41 +0000 | [diff] [blame] | 1499 | "down")); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1500 | netif_carrier_off(mgp->dev); |
Brice Goglin | c58ac5c | 2006-08-21 17:36:49 -0400 | [diff] [blame] | 1501 | mgp->link_changes++; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1502 | } |
| 1503 | } |
| 1504 | if (mgp->rdma_tags_available != |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1505 | ntohl(stats->rdma_tags_available)) { |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1506 | mgp->rdma_tags_available = |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1507 | ntohl(stats->rdma_tags_available); |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 1508 | netdev_warn(mgp->dev, "RDMA timed out! %d tags left\n", |
| 1509 | mgp->rdma_tags_available); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1510 | } |
| 1511 | mgp->down_cnt += stats->link_down; |
| 1512 | if (stats->link_down) |
| 1513 | wake_up(&mgp->down_wq); |
| 1514 | } |
| 1515 | } |
| 1516 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1517 | static int myri10ge_poll(struct napi_struct *napi, int budget) |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1518 | { |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1519 | struct myri10ge_slice_state *ss = |
| 1520 | container_of(napi, struct myri10ge_slice_state, napi); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1521 | int work_done; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1522 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1523 | #ifdef CONFIG_MYRI10GE_DCA |
Brice Goglin | 981813d | 2008-05-09 02:22:16 +0200 | [diff] [blame] | 1524 | if (ss->mgp->dca_enabled) |
| 1525 | myri10ge_update_dca(ss); |
| 1526 | #endif |
| 1527 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1528 | /* process as many rx events as NAPI will allow */ |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1529 | work_done = myri10ge_clean_rx_done(ss, budget); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1530 | |
David S. Miller | 4ec2411 | 2008-01-07 20:48:21 -0800 | [diff] [blame] | 1531 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1532 | napi_complete(napi); |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1533 | put_be32(htonl(3), ss->irq_claim); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1534 | } |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1535 | return work_done; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1536 | } |
| 1537 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1538 | static irqreturn_t myri10ge_intr(int irq, void *arg) |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1539 | { |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1540 | struct myri10ge_slice_state *ss = arg; |
| 1541 | struct myri10ge_priv *mgp = ss->mgp; |
| 1542 | struct mcp_irq_data *stats = ss->fw_stats; |
| 1543 | struct myri10ge_tx_buf *tx = &ss->tx; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1544 | u32 send_done_count; |
| 1545 | int i; |
| 1546 | |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 1547 | /* an interrupt on a non-zero receive-only slice is implicitly |
| 1548 | * valid since MSI-X irqs are not shared */ |
| 1549 | if ((mgp->dev->real_num_tx_queues == 1) && (ss != mgp->ss)) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1550 | napi_schedule(&ss->napi); |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 1551 | return IRQ_HANDLED; |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 1552 | } |
| 1553 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1554 | /* make sure it is our IRQ, and that the DMA has finished */ |
| 1555 | if (unlikely(!stats->valid)) |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 1556 | return IRQ_NONE; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1557 | |
| 1558 | /* low bit indicates receives are present, so schedule |
| 1559 | * napi poll handler */ |
| 1560 | if (stats->valid & 1) |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1561 | napi_schedule(&ss->napi); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1562 | |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 1563 | if (!mgp->msi_enabled && !mgp->msix_enabled) { |
Al Viro | 40f6cff | 2006-11-20 13:48:32 -0500 | [diff] [blame] | 1564 | put_be32(0, mgp->irq_deassert); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1565 | if (!myri10ge_deassert_wait) |
| 1566 | stats->valid = 0; |
| 1567 | mb(); |
| 1568 | } else |
| 1569 | stats->valid = 0; |
| 1570 | |
| 1571 | /* Wait for IRQ line to go low, if using INTx */ |
| 1572 | i = 0; |
| 1573 | while (1) { |
| 1574 | i++; |
| 1575 | /* check for transmit completes and receives */ |
| 1576 | send_done_count = ntohl(stats->send_done_count); |
| 1577 | if (send_done_count != tx->pkt_done) |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1578 | myri10ge_tx_done(ss, (int)send_done_count); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1579 | if (unlikely(i > myri10ge_max_irq_loops)) { |
Jon Mason | b3b6ae2 | 2011-06-27 10:56:41 +0000 | [diff] [blame] | 1580 | netdev_warn(mgp->dev, "irq stuck?\n"); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1581 | stats->valid = 0; |
| 1582 | schedule_work(&mgp->watchdog_work); |
| 1583 | } |
| 1584 | if (likely(stats->valid == 0)) |
| 1585 | break; |
| 1586 | cpu_relax(); |
| 1587 | barrier(); |
| 1588 | } |
| 1589 | |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 1590 | /* Only slice 0 updates stats */ |
| 1591 | if (ss == mgp->ss) |
| 1592 | myri10ge_check_statblock(mgp); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1593 | |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1594 | put_be32(htonl(3), ss->irq_claim + 1); |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 1595 | return IRQ_HANDLED; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1596 | } |
| 1597 | |
| 1598 | static int |
| 1599 | myri10ge_get_settings(struct net_device *netdev, struct ethtool_cmd *cmd) |
| 1600 | { |
Brice Goglin | c0bf880 | 2008-05-09 02:18:24 +0200 | [diff] [blame] | 1601 | struct myri10ge_priv *mgp = netdev_priv(netdev); |
| 1602 | char *ptr; |
| 1603 | int i; |
| 1604 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1605 | cmd->autoneg = AUTONEG_DISABLE; |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 1606 | ethtool_cmd_speed_set(cmd, SPEED_10000); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1607 | cmd->duplex = DUPLEX_FULL; |
Brice Goglin | c0bf880 | 2008-05-09 02:18:24 +0200 | [diff] [blame] | 1608 | |
| 1609 | /* |
| 1610 | * parse the product code to deterimine the interface type |
| 1611 | * (CX4, XFP, Quad Ribbon Fiber) by looking at the character |
| 1612 | * after the 3rd dash in the driver's cached copy of the |
| 1613 | * EEPROM's product code string. |
| 1614 | */ |
| 1615 | ptr = mgp->product_code_string; |
| 1616 | if (ptr == NULL) { |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 1617 | netdev_err(netdev, "Missing product code\n"); |
Brice Goglin | c0bf880 | 2008-05-09 02:18:24 +0200 | [diff] [blame] | 1618 | return 0; |
| 1619 | } |
| 1620 | for (i = 0; i < 3; i++, ptr++) { |
| 1621 | ptr = strchr(ptr, '-'); |
| 1622 | if (ptr == NULL) { |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 1623 | netdev_err(netdev, "Invalid product code %s\n", |
| 1624 | mgp->product_code_string); |
Brice Goglin | c0bf880 | 2008-05-09 02:18:24 +0200 | [diff] [blame] | 1625 | return 0; |
| 1626 | } |
| 1627 | } |
Brice Goglin | 196f17e | 2009-10-22 21:43:43 -0700 | [diff] [blame] | 1628 | if (*ptr == '2') |
| 1629 | ptr++; |
| 1630 | if (*ptr == 'R' || *ptr == 'Q' || *ptr == 'S') { |
| 1631 | /* We've found either an XFP, quad ribbon fiber, or SFP+ */ |
Brice Goglin | c0bf880 | 2008-05-09 02:18:24 +0200 | [diff] [blame] | 1632 | cmd->port = PORT_FIBRE; |
Brice Goglin | 196f17e | 2009-10-22 21:43:43 -0700 | [diff] [blame] | 1633 | cmd->supported |= SUPPORTED_FIBRE; |
| 1634 | cmd->advertising |= ADVERTISED_FIBRE; |
| 1635 | } else { |
| 1636 | cmd->port = PORT_OTHER; |
Brice Goglin | c0bf880 | 2008-05-09 02:18:24 +0200 | [diff] [blame] | 1637 | } |
Brice Goglin | 196f17e | 2009-10-22 21:43:43 -0700 | [diff] [blame] | 1638 | if (*ptr == 'R' || *ptr == 'S') |
| 1639 | cmd->transceiver = XCVR_EXTERNAL; |
| 1640 | else |
| 1641 | cmd->transceiver = XCVR_INTERNAL; |
| 1642 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1643 | return 0; |
| 1644 | } |
| 1645 | |
| 1646 | static void |
| 1647 | myri10ge_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *info) |
| 1648 | { |
| 1649 | struct myri10ge_priv *mgp = netdev_priv(netdev); |
| 1650 | |
| 1651 | strlcpy(info->driver, "myri10ge", sizeof(info->driver)); |
| 1652 | strlcpy(info->version, MYRI10GE_VERSION_STR, sizeof(info->version)); |
| 1653 | strlcpy(info->fw_version, mgp->fw_version, sizeof(info->fw_version)); |
| 1654 | strlcpy(info->bus_info, pci_name(mgp->pdev), sizeof(info->bus_info)); |
| 1655 | } |
| 1656 | |
| 1657 | static int |
| 1658 | myri10ge_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coal) |
| 1659 | { |
| 1660 | struct myri10ge_priv *mgp = netdev_priv(netdev); |
Brice Goglin | 99f5f87 | 2008-05-09 02:19:08 +0200 | [diff] [blame] | 1661 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1662 | coal->rx_coalesce_usecs = mgp->intr_coal_delay; |
| 1663 | return 0; |
| 1664 | } |
| 1665 | |
| 1666 | static int |
| 1667 | myri10ge_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coal) |
| 1668 | { |
| 1669 | struct myri10ge_priv *mgp = netdev_priv(netdev); |
| 1670 | |
| 1671 | mgp->intr_coal_delay = coal->rx_coalesce_usecs; |
Al Viro | 40f6cff | 2006-11-20 13:48:32 -0500 | [diff] [blame] | 1672 | put_be32(htonl(mgp->intr_coal_delay), mgp->intr_coal_delay_ptr); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1673 | return 0; |
| 1674 | } |
| 1675 | |
| 1676 | static void |
| 1677 | myri10ge_get_pauseparam(struct net_device *netdev, |
| 1678 | struct ethtool_pauseparam *pause) |
| 1679 | { |
| 1680 | struct myri10ge_priv *mgp = netdev_priv(netdev); |
| 1681 | |
| 1682 | pause->autoneg = 0; |
| 1683 | pause->rx_pause = mgp->pause; |
| 1684 | pause->tx_pause = mgp->pause; |
| 1685 | } |
| 1686 | |
| 1687 | static int |
| 1688 | myri10ge_set_pauseparam(struct net_device *netdev, |
| 1689 | struct ethtool_pauseparam *pause) |
| 1690 | { |
| 1691 | struct myri10ge_priv *mgp = netdev_priv(netdev); |
| 1692 | |
| 1693 | if (pause->tx_pause != mgp->pause) |
| 1694 | return myri10ge_change_pause(mgp, pause->tx_pause); |
| 1695 | if (pause->rx_pause != mgp->pause) |
Brice Goglin | 2488f56 | 2010-04-07 22:23:45 -0700 | [diff] [blame] | 1696 | return myri10ge_change_pause(mgp, pause->rx_pause); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1697 | if (pause->autoneg != 0) |
| 1698 | return -EINVAL; |
| 1699 | return 0; |
| 1700 | } |
| 1701 | |
| 1702 | static void |
| 1703 | myri10ge_get_ringparam(struct net_device *netdev, |
| 1704 | struct ethtool_ringparam *ring) |
| 1705 | { |
| 1706 | struct myri10ge_priv *mgp = netdev_priv(netdev); |
| 1707 | |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 1708 | ring->rx_mini_max_pending = mgp->ss[0].rx_small.mask + 1; |
| 1709 | ring->rx_max_pending = mgp->ss[0].rx_big.mask + 1; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1710 | ring->rx_jumbo_max_pending = 0; |
Brice Goglin | 6498be3 | 2009-04-16 17:56:57 -0700 | [diff] [blame] | 1711 | ring->tx_max_pending = mgp->ss[0].tx.mask + 1; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1712 | ring->rx_mini_pending = ring->rx_mini_max_pending; |
| 1713 | ring->rx_pending = ring->rx_max_pending; |
| 1714 | ring->rx_jumbo_pending = ring->rx_jumbo_max_pending; |
| 1715 | ring->tx_pending = ring->tx_max_pending; |
| 1716 | } |
| 1717 | |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1718 | static const char myri10ge_gstrings_main_stats[][ETH_GSTRING_LEN] = { |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1719 | "rx_packets", "tx_packets", "rx_bytes", "tx_bytes", "rx_errors", |
| 1720 | "tx_errors", "rx_dropped", "tx_dropped", "multicast", "collisions", |
| 1721 | "rx_length_errors", "rx_over_errors", "rx_crc_errors", |
| 1722 | "rx_frame_errors", "rx_fifo_errors", "rx_missed_errors", |
| 1723 | "tx_aborted_errors", "tx_carrier_errors", "tx_fifo_errors", |
| 1724 | "tx_heartbeat_errors", "tx_window_errors", |
| 1725 | /* device-specific stats */ |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 1726 | "tx_boundary", "WC", "irq", "MSI", "MSIX", |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1727 | "read_dma_bw_MBs", "write_dma_bw_MBs", "read_write_dma_bw_MBs", |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1728 | "serial_number", "watchdog_resets", |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1729 | #ifdef CONFIG_MYRI10GE_DCA |
Brice Goglin | 9a6b3b5 | 2008-09-12 19:48:06 +0200 | [diff] [blame] | 1730 | "dca_capable_firmware", "dca_device_present", |
Brice Goglin | 981813d | 2008-05-09 02:22:16 +0200 | [diff] [blame] | 1731 | #endif |
Brice Goglin | c58ac5c | 2006-08-21 17:36:49 -0400 | [diff] [blame] | 1732 | "link_changes", "link_up", "dropped_link_overflow", |
Brice Goglin | cee505d | 2007-05-07 23:49:25 +0200 | [diff] [blame] | 1733 | "dropped_link_error_or_filtered", |
| 1734 | "dropped_pause", "dropped_bad_phy", "dropped_bad_crc32", |
| 1735 | "dropped_unicast_filtered", "dropped_multicast_filtered", |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1736 | "dropped_runt", "dropped_overrun", "dropped_no_small_buffer", |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1737 | "dropped_no_big_buffer" |
| 1738 | }; |
| 1739 | |
| 1740 | static const char myri10ge_gstrings_slice_stats[][ETH_GSTRING_LEN] = { |
| 1741 | "----------- slice ---------", |
| 1742 | "tx_pkt_start", "tx_pkt_done", "tx_req", "tx_done", |
| 1743 | "rx_small_cnt", "rx_big_cnt", |
Jon Mason | b3b6ae2 | 2011-06-27 10:56:41 +0000 | [diff] [blame] | 1744 | "wake_queue", "stop_queue", "tx_linearized", |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1745 | }; |
| 1746 | |
| 1747 | #define MYRI10GE_NET_STATS_LEN 21 |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1748 | #define MYRI10GE_MAIN_STATS_LEN ARRAY_SIZE(myri10ge_gstrings_main_stats) |
| 1749 | #define MYRI10GE_SLICE_STATS_LEN ARRAY_SIZE(myri10ge_gstrings_slice_stats) |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1750 | |
| 1751 | static void |
| 1752 | myri10ge_get_strings(struct net_device *netdev, u32 stringset, u8 * data) |
| 1753 | { |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 1754 | struct myri10ge_priv *mgp = netdev_priv(netdev); |
| 1755 | int i; |
| 1756 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1757 | switch (stringset) { |
| 1758 | case ETH_SS_STATS: |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1759 | memcpy(data, *myri10ge_gstrings_main_stats, |
| 1760 | sizeof(myri10ge_gstrings_main_stats)); |
| 1761 | data += sizeof(myri10ge_gstrings_main_stats); |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 1762 | for (i = 0; i < mgp->num_slices; i++) { |
| 1763 | memcpy(data, *myri10ge_gstrings_slice_stats, |
| 1764 | sizeof(myri10ge_gstrings_slice_stats)); |
| 1765 | data += sizeof(myri10ge_gstrings_slice_stats); |
| 1766 | } |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1767 | break; |
| 1768 | } |
| 1769 | } |
| 1770 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1771 | static int myri10ge_get_sset_count(struct net_device *netdev, int sset) |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1772 | { |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 1773 | struct myri10ge_priv *mgp = netdev_priv(netdev); |
| 1774 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1775 | switch (sset) { |
| 1776 | case ETH_SS_STATS: |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 1777 | return MYRI10GE_MAIN_STATS_LEN + |
| 1778 | mgp->num_slices * MYRI10GE_SLICE_STATS_LEN; |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1779 | default: |
| 1780 | return -EOPNOTSUPP; |
| 1781 | } |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1782 | } |
| 1783 | |
| 1784 | static void |
| 1785 | myri10ge_get_ethtool_stats(struct net_device *netdev, |
| 1786 | struct ethtool_stats *stats, u64 * data) |
| 1787 | { |
| 1788 | struct myri10ge_priv *mgp = netdev_priv(netdev); |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1789 | struct myri10ge_slice_state *ss; |
stephen hemminger | c5f7ef7 | 2011-06-08 14:54:03 +0000 | [diff] [blame] | 1790 | struct rtnl_link_stats64 link_stats; |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 1791 | int slice; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1792 | int i; |
| 1793 | |
Brice Goglin | 5908182 | 2009-04-16 02:23:56 +0000 | [diff] [blame] | 1794 | /* force stats update */ |
Eric Dumazet | 306ff6e | 2011-06-19 20:07:46 +0000 | [diff] [blame] | 1795 | memset(&link_stats, 0, sizeof(link_stats)); |
stephen hemminger | c5f7ef7 | 2011-06-08 14:54:03 +0000 | [diff] [blame] | 1796 | (void)myri10ge_get_stats(netdev, &link_stats); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1797 | for (i = 0; i < MYRI10GE_NET_STATS_LEN; i++) |
stephen hemminger | c5f7ef7 | 2011-06-08 14:54:03 +0000 | [diff] [blame] | 1798 | data[i] = ((u64 *)&link_stats)[i]; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1799 | |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1800 | data[i++] = (unsigned int)mgp->tx_boundary; |
Brice Goglin | 276e26c | 2007-03-07 20:02:32 +0100 | [diff] [blame] | 1801 | data[i++] = (unsigned int)mgp->wc_enabled; |
Brice Goglin | 2c1a108 | 2006-07-03 18:16:46 -0400 | [diff] [blame] | 1802 | data[i++] = (unsigned int)mgp->pdev->irq; |
| 1803 | data[i++] = (unsigned int)mgp->msi_enabled; |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 1804 | data[i++] = (unsigned int)mgp->msix_enabled; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1805 | data[i++] = (unsigned int)mgp->read_dma; |
| 1806 | data[i++] = (unsigned int)mgp->write_dma; |
| 1807 | data[i++] = (unsigned int)mgp->read_write_dma; |
| 1808 | data[i++] = (unsigned int)mgp->serial_number; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1809 | data[i++] = (unsigned int)mgp->watchdog_resets; |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1810 | #ifdef CONFIG_MYRI10GE_DCA |
Brice Goglin | 981813d | 2008-05-09 02:22:16 +0200 | [diff] [blame] | 1811 | data[i++] = (unsigned int)(mgp->ss[0].dca_tag != NULL); |
| 1812 | data[i++] = (unsigned int)(mgp->dca_enabled); |
| 1813 | #endif |
Brice Goglin | c58ac5c | 2006-08-21 17:36:49 -0400 | [diff] [blame] | 1814 | data[i++] = (unsigned int)mgp->link_changes; |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1815 | |
| 1816 | /* firmware stats are useful only in the first slice */ |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 1817 | ss = &mgp->ss[0]; |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1818 | data[i++] = (unsigned int)ntohl(ss->fw_stats->link_up); |
| 1819 | data[i++] = (unsigned int)ntohl(ss->fw_stats->dropped_link_overflow); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1820 | data[i++] = |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1821 | (unsigned int)ntohl(ss->fw_stats->dropped_link_error_or_filtered); |
| 1822 | data[i++] = (unsigned int)ntohl(ss->fw_stats->dropped_pause); |
| 1823 | data[i++] = (unsigned int)ntohl(ss->fw_stats->dropped_bad_phy); |
| 1824 | data[i++] = (unsigned int)ntohl(ss->fw_stats->dropped_bad_crc32); |
| 1825 | data[i++] = (unsigned int)ntohl(ss->fw_stats->dropped_unicast_filtered); |
Brice Goglin | cee505d | 2007-05-07 23:49:25 +0200 | [diff] [blame] | 1826 | data[i++] = |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1827 | (unsigned int)ntohl(ss->fw_stats->dropped_multicast_filtered); |
| 1828 | data[i++] = (unsigned int)ntohl(ss->fw_stats->dropped_runt); |
| 1829 | data[i++] = (unsigned int)ntohl(ss->fw_stats->dropped_overrun); |
| 1830 | data[i++] = (unsigned int)ntohl(ss->fw_stats->dropped_no_small_buffer); |
| 1831 | data[i++] = (unsigned int)ntohl(ss->fw_stats->dropped_no_big_buffer); |
| 1832 | |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 1833 | for (slice = 0; slice < mgp->num_slices; slice++) { |
| 1834 | ss = &mgp->ss[slice]; |
| 1835 | data[i++] = slice; |
| 1836 | data[i++] = (unsigned int)ss->tx.pkt_start; |
| 1837 | data[i++] = (unsigned int)ss->tx.pkt_done; |
| 1838 | data[i++] = (unsigned int)ss->tx.req; |
| 1839 | data[i++] = (unsigned int)ss->tx.done; |
| 1840 | data[i++] = (unsigned int)ss->rx_small.cnt; |
| 1841 | data[i++] = (unsigned int)ss->rx_big.cnt; |
| 1842 | data[i++] = (unsigned int)ss->tx.wake_queue; |
| 1843 | data[i++] = (unsigned int)ss->tx.stop_queue; |
| 1844 | data[i++] = (unsigned int)ss->tx.linearized; |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 1845 | } |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1846 | } |
| 1847 | |
Brice Goglin | c58ac5c | 2006-08-21 17:36:49 -0400 | [diff] [blame] | 1848 | static void myri10ge_set_msglevel(struct net_device *netdev, u32 value) |
| 1849 | { |
| 1850 | struct myri10ge_priv *mgp = netdev_priv(netdev); |
| 1851 | mgp->msg_enable = value; |
| 1852 | } |
| 1853 | |
| 1854 | static u32 myri10ge_get_msglevel(struct net_device *netdev) |
| 1855 | { |
| 1856 | struct myri10ge_priv *mgp = netdev_priv(netdev); |
| 1857 | return mgp->msg_enable; |
| 1858 | } |
| 1859 | |
Jon Mason | 5dcd846 | 2011-06-27 05:05:04 +0000 | [diff] [blame] | 1860 | /* |
| 1861 | * Use a low-level command to change the LED behavior. Rather than |
| 1862 | * blinking (which is the normal case), when identify is used, the |
| 1863 | * yellow LED turns solid. |
| 1864 | */ |
| 1865 | static int myri10ge_led(struct myri10ge_priv *mgp, int on) |
| 1866 | { |
| 1867 | struct mcp_gen_header *hdr; |
| 1868 | struct device *dev = &mgp->pdev->dev; |
| 1869 | size_t hdr_off, pattern_off, hdr_len; |
| 1870 | u32 pattern = 0xfffffffe; |
| 1871 | |
| 1872 | /* find running firmware header */ |
| 1873 | hdr_off = swab32(readl(mgp->sram + MCP_HEADER_PTR_OFFSET)); |
| 1874 | if ((hdr_off & 3) || hdr_off + sizeof(*hdr) > mgp->sram_size) { |
| 1875 | dev_err(dev, "Running firmware has bad header offset (%d)\n", |
| 1876 | (int)hdr_off); |
| 1877 | return -EIO; |
| 1878 | } |
| 1879 | hdr_len = swab32(readl(mgp->sram + hdr_off + |
| 1880 | offsetof(struct mcp_gen_header, header_length))); |
| 1881 | pattern_off = hdr_off + offsetof(struct mcp_gen_header, led_pattern); |
| 1882 | if (pattern_off >= (hdr_len + hdr_off)) { |
| 1883 | dev_info(dev, "Firmware does not support LED identification\n"); |
| 1884 | return -EINVAL; |
| 1885 | } |
| 1886 | if (!on) |
| 1887 | pattern = swab32(readl(mgp->sram + pattern_off + 4)); |
Andrew Gallatin | 59e955e | 2012-12-04 10:17:15 +0000 | [diff] [blame] | 1888 | writel(swab32(pattern), mgp->sram + pattern_off); |
Jon Mason | 5dcd846 | 2011-06-27 05:05:04 +0000 | [diff] [blame] | 1889 | return 0; |
| 1890 | } |
| 1891 | |
| 1892 | static int |
| 1893 | myri10ge_phys_id(struct net_device *netdev, enum ethtool_phys_id_state state) |
| 1894 | { |
| 1895 | struct myri10ge_priv *mgp = netdev_priv(netdev); |
| 1896 | int rc; |
| 1897 | |
| 1898 | switch (state) { |
| 1899 | case ETHTOOL_ID_ACTIVE: |
| 1900 | rc = myri10ge_led(mgp, 1); |
| 1901 | break; |
| 1902 | |
| 1903 | case ETHTOOL_ID_INACTIVE: |
| 1904 | rc = myri10ge_led(mgp, 0); |
| 1905 | break; |
| 1906 | |
| 1907 | default: |
| 1908 | rc = -EINVAL; |
| 1909 | } |
| 1910 | |
| 1911 | return rc; |
| 1912 | } |
| 1913 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 1914 | static const struct ethtool_ops myri10ge_ethtool_ops = { |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1915 | .get_settings = myri10ge_get_settings, |
| 1916 | .get_drvinfo = myri10ge_get_drvinfo, |
| 1917 | .get_coalesce = myri10ge_get_coalesce, |
| 1918 | .set_coalesce = myri10ge_set_coalesce, |
| 1919 | .get_pauseparam = myri10ge_get_pauseparam, |
| 1920 | .set_pauseparam = myri10ge_set_pauseparam, |
| 1921 | .get_ringparam = myri10ge_get_ringparam, |
Brice Goglin | 6ffdd07 | 2007-05-30 21:13:59 +0200 | [diff] [blame] | 1922 | .get_link = ethtool_op_get_link, |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1923 | .get_strings = myri10ge_get_strings, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1924 | .get_sset_count = myri10ge_get_sset_count, |
Brice Goglin | c58ac5c | 2006-08-21 17:36:49 -0400 | [diff] [blame] | 1925 | .get_ethtool_stats = myri10ge_get_ethtool_stats, |
| 1926 | .set_msglevel = myri10ge_set_msglevel, |
Brice Goglin | 3a0c7d2 | 2009-05-19 10:15:32 +0000 | [diff] [blame] | 1927 | .get_msglevel = myri10ge_get_msglevel, |
Jon Mason | 5dcd846 | 2011-06-27 05:05:04 +0000 | [diff] [blame] | 1928 | .set_phys_id = myri10ge_phys_id, |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1929 | }; |
| 1930 | |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1931 | static int myri10ge_allocate_rings(struct myri10ge_slice_state *ss) |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1932 | { |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1933 | struct myri10ge_priv *mgp = ss->mgp; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1934 | struct myri10ge_cmd cmd; |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1935 | struct net_device *dev = mgp->dev; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1936 | int tx_ring_size, rx_ring_size; |
| 1937 | int tx_ring_entries, rx_ring_entries; |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 1938 | int i, slice, status; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1939 | size_t bytes; |
| 1940 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1941 | /* get ring sizes */ |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 1942 | slice = ss - mgp->ss; |
| 1943 | cmd.data0 = slice; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1944 | status = myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_SEND_RING_SIZE, &cmd, 0); |
| 1945 | tx_ring_size = cmd.data0; |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 1946 | cmd.data0 = slice; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1947 | status |= myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_RX_RING_SIZE, &cmd, 0); |
Brice Goglin | 355c726 | 2007-03-07 19:59:52 +0100 | [diff] [blame] | 1948 | if (status != 0) |
| 1949 | return status; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1950 | rx_ring_size = cmd.data0; |
| 1951 | |
| 1952 | tx_ring_entries = tx_ring_size / sizeof(struct mcp_kreq_ether_send); |
| 1953 | rx_ring_entries = rx_ring_size / sizeof(struct mcp_dma_addr); |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1954 | ss->tx.mask = tx_ring_entries - 1; |
| 1955 | ss->rx_small.mask = ss->rx_big.mask = rx_ring_entries - 1; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1956 | |
Brice Goglin | 355c726 | 2007-03-07 19:59:52 +0100 | [diff] [blame] | 1957 | status = -ENOMEM; |
| 1958 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1959 | /* allocate the host shadow rings */ |
| 1960 | |
| 1961 | bytes = 8 + (MYRI10GE_MAX_SEND_DESC_TSO + 4) |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1962 | * sizeof(*ss->tx.req_list); |
| 1963 | ss->tx.req_bytes = kzalloc(bytes, GFP_KERNEL); |
| 1964 | if (ss->tx.req_bytes == NULL) |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1965 | goto abort_with_nothing; |
| 1966 | |
| 1967 | /* ensure req_list entries are aligned to 8 bytes */ |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1968 | ss->tx.req_list = (struct mcp_kreq_ether_send *) |
| 1969 | ALIGN((unsigned long)ss->tx.req_bytes, 8); |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 1970 | ss->tx.queue_active = 0; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1971 | |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1972 | bytes = rx_ring_entries * sizeof(*ss->rx_small.shadow); |
| 1973 | ss->rx_small.shadow = kzalloc(bytes, GFP_KERNEL); |
| 1974 | if (ss->rx_small.shadow == NULL) |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1975 | goto abort_with_tx_req_bytes; |
| 1976 | |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1977 | bytes = rx_ring_entries * sizeof(*ss->rx_big.shadow); |
| 1978 | ss->rx_big.shadow = kzalloc(bytes, GFP_KERNEL); |
| 1979 | if (ss->rx_big.shadow == NULL) |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1980 | goto abort_with_rx_small_shadow; |
| 1981 | |
| 1982 | /* allocate the host info rings */ |
| 1983 | |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1984 | bytes = tx_ring_entries * sizeof(*ss->tx.info); |
| 1985 | ss->tx.info = kzalloc(bytes, GFP_KERNEL); |
| 1986 | if (ss->tx.info == NULL) |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1987 | goto abort_with_rx_big_shadow; |
| 1988 | |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1989 | bytes = rx_ring_entries * sizeof(*ss->rx_small.info); |
| 1990 | ss->rx_small.info = kzalloc(bytes, GFP_KERNEL); |
| 1991 | if (ss->rx_small.info == NULL) |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1992 | goto abort_with_tx_info; |
| 1993 | |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 1994 | bytes = rx_ring_entries * sizeof(*ss->rx_big.info); |
| 1995 | ss->rx_big.info = kzalloc(bytes, GFP_KERNEL); |
| 1996 | if (ss->rx_big.info == NULL) |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 1997 | goto abort_with_rx_small_info; |
| 1998 | |
| 1999 | /* Fill the receive rings */ |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2000 | ss->rx_big.cnt = 0; |
| 2001 | ss->rx_small.cnt = 0; |
| 2002 | ss->rx_big.fill_cnt = 0; |
| 2003 | ss->rx_small.fill_cnt = 0; |
| 2004 | ss->rx_small.page_offset = MYRI10GE_ALLOC_SIZE; |
| 2005 | ss->rx_big.page_offset = MYRI10GE_ALLOC_SIZE; |
| 2006 | ss->rx_small.watchdog_needed = 0; |
| 2007 | ss->rx_big.watchdog_needed = 0; |
Jon Mason | 4b47638 | 2011-06-27 05:05:03 +0000 | [diff] [blame] | 2008 | if (mgp->small_bytes == 0) { |
| 2009 | ss->rx_small.fill_cnt = ss->rx_small.mask + 1; |
| 2010 | } else { |
| 2011 | myri10ge_alloc_rx_pages(mgp, &ss->rx_small, |
| 2012 | mgp->small_bytes + MXGEFW_PAD, 0); |
| 2013 | } |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2014 | |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2015 | if (ss->rx_small.fill_cnt < ss->rx_small.mask + 1) { |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 2016 | netdev_err(dev, "slice-%d: alloced only %d small bufs\n", |
| 2017 | slice, ss->rx_small.fill_cnt); |
Brice Goglin | c7dab99 | 2006-12-11 11:25:42 +0100 | [diff] [blame] | 2018 | goto abort_with_rx_small_ring; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2019 | } |
| 2020 | |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2021 | myri10ge_alloc_rx_pages(mgp, &ss->rx_big, mgp->big_bytes, 0); |
| 2022 | if (ss->rx_big.fill_cnt < ss->rx_big.mask + 1) { |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 2023 | netdev_err(dev, "slice-%d: alloced only %d big bufs\n", |
| 2024 | slice, ss->rx_big.fill_cnt); |
Brice Goglin | c7dab99 | 2006-12-11 11:25:42 +0100 | [diff] [blame] | 2025 | goto abort_with_rx_big_ring; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2026 | } |
| 2027 | |
| 2028 | return 0; |
| 2029 | |
| 2030 | abort_with_rx_big_ring: |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2031 | for (i = ss->rx_big.cnt; i < ss->rx_big.fill_cnt; i++) { |
| 2032 | int idx = i & ss->rx_big.mask; |
| 2033 | myri10ge_unmap_rx_page(mgp->pdev, &ss->rx_big.info[idx], |
Brice Goglin | c7dab99 | 2006-12-11 11:25:42 +0100 | [diff] [blame] | 2034 | mgp->big_bytes); |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2035 | put_page(ss->rx_big.info[idx].page); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2036 | } |
| 2037 | |
| 2038 | abort_with_rx_small_ring: |
Jon Mason | 4b47638 | 2011-06-27 05:05:03 +0000 | [diff] [blame] | 2039 | if (mgp->small_bytes == 0) |
| 2040 | ss->rx_small.fill_cnt = ss->rx_small.cnt; |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2041 | for (i = ss->rx_small.cnt; i < ss->rx_small.fill_cnt; i++) { |
| 2042 | int idx = i & ss->rx_small.mask; |
| 2043 | myri10ge_unmap_rx_page(mgp->pdev, &ss->rx_small.info[idx], |
Brice Goglin | c7dab99 | 2006-12-11 11:25:42 +0100 | [diff] [blame] | 2044 | mgp->small_bytes + MXGEFW_PAD); |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2045 | put_page(ss->rx_small.info[idx].page); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2046 | } |
Brice Goglin | c7dab99 | 2006-12-11 11:25:42 +0100 | [diff] [blame] | 2047 | |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2048 | kfree(ss->rx_big.info); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2049 | |
| 2050 | abort_with_rx_small_info: |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2051 | kfree(ss->rx_small.info); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2052 | |
| 2053 | abort_with_tx_info: |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2054 | kfree(ss->tx.info); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2055 | |
| 2056 | abort_with_rx_big_shadow: |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2057 | kfree(ss->rx_big.shadow); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2058 | |
| 2059 | abort_with_rx_small_shadow: |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2060 | kfree(ss->rx_small.shadow); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2061 | |
| 2062 | abort_with_tx_req_bytes: |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2063 | kfree(ss->tx.req_bytes); |
| 2064 | ss->tx.req_bytes = NULL; |
| 2065 | ss->tx.req_list = NULL; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2066 | |
| 2067 | abort_with_nothing: |
| 2068 | return status; |
| 2069 | } |
| 2070 | |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2071 | static void myri10ge_free_rings(struct myri10ge_slice_state *ss) |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2072 | { |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2073 | struct myri10ge_priv *mgp = ss->mgp; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2074 | struct sk_buff *skb; |
| 2075 | struct myri10ge_tx_buf *tx; |
| 2076 | int i, len, idx; |
| 2077 | |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 2078 | /* If not allocated, skip it */ |
| 2079 | if (ss->tx.req_list == NULL) |
| 2080 | return; |
| 2081 | |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2082 | for (i = ss->rx_big.cnt; i < ss->rx_big.fill_cnt; i++) { |
| 2083 | idx = i & ss->rx_big.mask; |
| 2084 | if (i == ss->rx_big.fill_cnt - 1) |
| 2085 | ss->rx_big.info[idx].page_offset = MYRI10GE_ALLOC_SIZE; |
| 2086 | myri10ge_unmap_rx_page(mgp->pdev, &ss->rx_big.info[idx], |
Brice Goglin | c7dab99 | 2006-12-11 11:25:42 +0100 | [diff] [blame] | 2087 | mgp->big_bytes); |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2088 | put_page(ss->rx_big.info[idx].page); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2089 | } |
| 2090 | |
Jon Mason | 4b47638 | 2011-06-27 05:05:03 +0000 | [diff] [blame] | 2091 | if (mgp->small_bytes == 0) |
| 2092 | ss->rx_small.fill_cnt = ss->rx_small.cnt; |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2093 | for (i = ss->rx_small.cnt; i < ss->rx_small.fill_cnt; i++) { |
| 2094 | idx = i & ss->rx_small.mask; |
| 2095 | if (i == ss->rx_small.fill_cnt - 1) |
| 2096 | ss->rx_small.info[idx].page_offset = |
Brice Goglin | c7dab99 | 2006-12-11 11:25:42 +0100 | [diff] [blame] | 2097 | MYRI10GE_ALLOC_SIZE; |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2098 | myri10ge_unmap_rx_page(mgp->pdev, &ss->rx_small.info[idx], |
Brice Goglin | c7dab99 | 2006-12-11 11:25:42 +0100 | [diff] [blame] | 2099 | mgp->small_bytes + MXGEFW_PAD); |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2100 | put_page(ss->rx_small.info[idx].page); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2101 | } |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2102 | tx = &ss->tx; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2103 | while (tx->done != tx->req) { |
| 2104 | idx = tx->done & tx->mask; |
| 2105 | skb = tx->info[idx].skb; |
| 2106 | |
| 2107 | /* Mark as free */ |
| 2108 | tx->info[idx].skb = NULL; |
| 2109 | tx->done++; |
FUJITA Tomonori | c755b4b | 2010-04-12 14:32:10 +0000 | [diff] [blame] | 2110 | len = dma_unmap_len(&tx->info[idx], len); |
| 2111 | dma_unmap_len_set(&tx->info[idx], len, 0); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2112 | if (skb) { |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2113 | ss->stats.tx_dropped++; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2114 | dev_kfree_skb_any(skb); |
| 2115 | if (len) |
| 2116 | pci_unmap_single(mgp->pdev, |
FUJITA Tomonori | c755b4b | 2010-04-12 14:32:10 +0000 | [diff] [blame] | 2117 | dma_unmap_addr(&tx->info[idx], |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2118 | bus), len, |
| 2119 | PCI_DMA_TODEVICE); |
| 2120 | } else { |
| 2121 | if (len) |
| 2122 | pci_unmap_page(mgp->pdev, |
FUJITA Tomonori | c755b4b | 2010-04-12 14:32:10 +0000 | [diff] [blame] | 2123 | dma_unmap_addr(&tx->info[idx], |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2124 | bus), len, |
| 2125 | PCI_DMA_TODEVICE); |
| 2126 | } |
| 2127 | } |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2128 | kfree(ss->rx_big.info); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2129 | |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2130 | kfree(ss->rx_small.info); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2131 | |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2132 | kfree(ss->tx.info); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2133 | |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2134 | kfree(ss->rx_big.shadow); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2135 | |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2136 | kfree(ss->rx_small.shadow); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2137 | |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2138 | kfree(ss->tx.req_bytes); |
| 2139 | ss->tx.req_bytes = NULL; |
| 2140 | ss->tx.req_list = NULL; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2141 | } |
| 2142 | |
Brice Goglin | df30a74 | 2006-12-18 11:50:40 +0100 | [diff] [blame] | 2143 | static int myri10ge_request_irq(struct myri10ge_priv *mgp) |
| 2144 | { |
| 2145 | struct pci_dev *pdev = mgp->pdev; |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 2146 | struct myri10ge_slice_state *ss; |
| 2147 | struct net_device *netdev = mgp->dev; |
| 2148 | int i; |
Brice Goglin | df30a74 | 2006-12-18 11:50:40 +0100 | [diff] [blame] | 2149 | int status; |
| 2150 | |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 2151 | mgp->msi_enabled = 0; |
| 2152 | mgp->msix_enabled = 0; |
| 2153 | status = 0; |
Brice Goglin | df30a74 | 2006-12-18 11:50:40 +0100 | [diff] [blame] | 2154 | if (myri10ge_msi) { |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 2155 | if (mgp->num_slices > 1) { |
| 2156 | status = |
| 2157 | pci_enable_msix(pdev, mgp->msix_vectors, |
| 2158 | mgp->num_slices); |
| 2159 | if (status == 0) { |
| 2160 | mgp->msix_enabled = 1; |
| 2161 | } else { |
| 2162 | dev_err(&pdev->dev, |
| 2163 | "Error %d setting up MSI-X\n", status); |
| 2164 | return status; |
| 2165 | } |
| 2166 | } |
| 2167 | if (mgp->msix_enabled == 0) { |
| 2168 | status = pci_enable_msi(pdev); |
| 2169 | if (status != 0) { |
| 2170 | dev_err(&pdev->dev, |
| 2171 | "Error %d setting up MSI; falling back to xPIC\n", |
| 2172 | status); |
| 2173 | } else { |
| 2174 | mgp->msi_enabled = 1; |
| 2175 | } |
| 2176 | } |
Brice Goglin | df30a74 | 2006-12-18 11:50:40 +0100 | [diff] [blame] | 2177 | } |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 2178 | if (mgp->msix_enabled) { |
| 2179 | for (i = 0; i < mgp->num_slices; i++) { |
| 2180 | ss = &mgp->ss[i]; |
| 2181 | snprintf(ss->irq_desc, sizeof(ss->irq_desc), |
| 2182 | "%s:slice-%d", netdev->name, i); |
| 2183 | status = request_irq(mgp->msix_vectors[i].vector, |
| 2184 | myri10ge_intr, 0, ss->irq_desc, |
| 2185 | ss); |
| 2186 | if (status != 0) { |
| 2187 | dev_err(&pdev->dev, |
| 2188 | "slice %d failed to allocate IRQ\n", i); |
| 2189 | i--; |
| 2190 | while (i >= 0) { |
| 2191 | free_irq(mgp->msix_vectors[i].vector, |
| 2192 | &mgp->ss[i]); |
| 2193 | i--; |
| 2194 | } |
| 2195 | pci_disable_msix(pdev); |
| 2196 | return status; |
| 2197 | } |
| 2198 | } |
| 2199 | } else { |
| 2200 | status = request_irq(pdev->irq, myri10ge_intr, IRQF_SHARED, |
| 2201 | mgp->dev->name, &mgp->ss[0]); |
| 2202 | if (status != 0) { |
| 2203 | dev_err(&pdev->dev, "failed to allocate IRQ\n"); |
| 2204 | if (mgp->msi_enabled) |
| 2205 | pci_disable_msi(pdev); |
| 2206 | } |
Brice Goglin | df30a74 | 2006-12-18 11:50:40 +0100 | [diff] [blame] | 2207 | } |
| 2208 | return status; |
| 2209 | } |
| 2210 | |
| 2211 | static void myri10ge_free_irq(struct myri10ge_priv *mgp) |
| 2212 | { |
| 2213 | struct pci_dev *pdev = mgp->pdev; |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 2214 | int i; |
Brice Goglin | df30a74 | 2006-12-18 11:50:40 +0100 | [diff] [blame] | 2215 | |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 2216 | if (mgp->msix_enabled) { |
| 2217 | for (i = 0; i < mgp->num_slices; i++) |
| 2218 | free_irq(mgp->msix_vectors[i].vector, &mgp->ss[i]); |
| 2219 | } else { |
| 2220 | free_irq(pdev->irq, &mgp->ss[0]); |
| 2221 | } |
Brice Goglin | df30a74 | 2006-12-18 11:50:40 +0100 | [diff] [blame] | 2222 | if (mgp->msi_enabled) |
| 2223 | pci_disable_msi(pdev); |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 2224 | if (mgp->msix_enabled) |
| 2225 | pci_disable_msix(pdev); |
Brice Goglin | df30a74 | 2006-12-18 11:50:40 +0100 | [diff] [blame] | 2226 | } |
| 2227 | |
Brice Goglin | 7792973 | 2008-05-09 02:21:10 +0200 | [diff] [blame] | 2228 | static int myri10ge_get_txrx(struct myri10ge_priv *mgp, int slice) |
| 2229 | { |
| 2230 | struct myri10ge_cmd cmd; |
| 2231 | struct myri10ge_slice_state *ss; |
| 2232 | int status; |
| 2233 | |
| 2234 | ss = &mgp->ss[slice]; |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 2235 | status = 0; |
| 2236 | if (slice == 0 || (mgp->dev->real_num_tx_queues > 1)) { |
| 2237 | cmd.data0 = slice; |
| 2238 | status = myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_SEND_OFFSET, |
| 2239 | &cmd, 0); |
| 2240 | ss->tx.lanai = (struct mcp_kreq_ether_send __iomem *) |
| 2241 | (mgp->sram + cmd.data0); |
| 2242 | } |
Brice Goglin | 7792973 | 2008-05-09 02:21:10 +0200 | [diff] [blame] | 2243 | cmd.data0 = slice; |
| 2244 | status |= myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_SMALL_RX_OFFSET, |
| 2245 | &cmd, 0); |
| 2246 | ss->rx_small.lanai = (struct mcp_kreq_ether_recv __iomem *) |
| 2247 | (mgp->sram + cmd.data0); |
| 2248 | |
| 2249 | cmd.data0 = slice; |
| 2250 | status |= myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_BIG_RX_OFFSET, &cmd, 0); |
| 2251 | ss->rx_big.lanai = (struct mcp_kreq_ether_recv __iomem *) |
| 2252 | (mgp->sram + cmd.data0); |
| 2253 | |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 2254 | ss->tx.send_go = (__iomem __be32 *) |
| 2255 | (mgp->sram + MXGEFW_ETH_SEND_GO + 64 * slice); |
| 2256 | ss->tx.send_stop = (__iomem __be32 *) |
| 2257 | (mgp->sram + MXGEFW_ETH_SEND_STOP + 64 * slice); |
Brice Goglin | 7792973 | 2008-05-09 02:21:10 +0200 | [diff] [blame] | 2258 | return status; |
| 2259 | |
| 2260 | } |
| 2261 | |
| 2262 | static int myri10ge_set_stats(struct myri10ge_priv *mgp, int slice) |
| 2263 | { |
| 2264 | struct myri10ge_cmd cmd; |
| 2265 | struct myri10ge_slice_state *ss; |
| 2266 | int status; |
| 2267 | |
| 2268 | ss = &mgp->ss[slice]; |
| 2269 | cmd.data0 = MYRI10GE_LOWPART_TO_U32(ss->fw_stats_bus); |
| 2270 | cmd.data1 = MYRI10GE_HIGHPART_TO_U32(ss->fw_stats_bus); |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 2271 | cmd.data2 = sizeof(struct mcp_irq_data) | (slice << 16); |
Brice Goglin | 7792973 | 2008-05-09 02:21:10 +0200 | [diff] [blame] | 2272 | status = myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_STATS_DMA_V2, &cmd, 0); |
| 2273 | if (status == -ENOSYS) { |
| 2274 | dma_addr_t bus = ss->fw_stats_bus; |
| 2275 | if (slice != 0) |
| 2276 | return -EINVAL; |
| 2277 | bus += offsetof(struct mcp_irq_data, send_done_count); |
| 2278 | cmd.data0 = MYRI10GE_LOWPART_TO_U32(bus); |
| 2279 | cmd.data1 = MYRI10GE_HIGHPART_TO_U32(bus); |
| 2280 | status = myri10ge_send_cmd(mgp, |
| 2281 | MXGEFW_CMD_SET_STATS_DMA_OBSOLETE, |
| 2282 | &cmd, 0); |
| 2283 | /* Firmware cannot support multicast without STATS_DMA_V2 */ |
| 2284 | mgp->fw_multicast_support = 0; |
| 2285 | } else { |
| 2286 | mgp->fw_multicast_support = 1; |
| 2287 | } |
| 2288 | return 0; |
| 2289 | } |
Brice Goglin | 7792973 | 2008-05-09 02:21:10 +0200 | [diff] [blame] | 2290 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2291 | static int myri10ge_open(struct net_device *dev) |
| 2292 | { |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 2293 | struct myri10ge_slice_state *ss; |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2294 | struct myri10ge_priv *mgp = netdev_priv(dev); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2295 | struct myri10ge_cmd cmd; |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 2296 | int i, status, big_pow2, slice; |
Andrew Gallatin | 59e955e | 2012-12-04 10:17:15 +0000 | [diff] [blame] | 2297 | u8 __iomem *itable; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2298 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2299 | if (mgp->running != MYRI10GE_ETH_STOPPED) |
| 2300 | return -EBUSY; |
| 2301 | |
| 2302 | mgp->running = MYRI10GE_ETH_STARTING; |
| 2303 | status = myri10ge_reset(mgp); |
| 2304 | if (status != 0) { |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 2305 | netdev_err(dev, "failed reset\n"); |
Brice Goglin | df30a74 | 2006-12-18 11:50:40 +0100 | [diff] [blame] | 2306 | goto abort_with_nothing; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2307 | } |
| 2308 | |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 2309 | if (mgp->num_slices > 1) { |
| 2310 | cmd.data0 = mgp->num_slices; |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 2311 | cmd.data1 = MXGEFW_SLICE_INTR_MODE_ONE_PER_SLICE; |
| 2312 | if (mgp->dev->real_num_tx_queues > 1) |
| 2313 | cmd.data1 |= MXGEFW_SLICE_ENABLE_MULTIPLE_TX_QUEUES; |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 2314 | status = myri10ge_send_cmd(mgp, MXGEFW_CMD_ENABLE_RSS_QUEUES, |
| 2315 | &cmd, 0); |
| 2316 | if (status != 0) { |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 2317 | netdev_err(dev, "failed to set number of slices\n"); |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 2318 | goto abort_with_nothing; |
| 2319 | } |
| 2320 | /* setup the indirection table */ |
| 2321 | cmd.data0 = mgp->num_slices; |
| 2322 | status = myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_RSS_TABLE_SIZE, |
| 2323 | &cmd, 0); |
| 2324 | |
| 2325 | status |= myri10ge_send_cmd(mgp, |
| 2326 | MXGEFW_CMD_GET_RSS_TABLE_OFFSET, |
| 2327 | &cmd, 0); |
| 2328 | if (status != 0) { |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 2329 | netdev_err(dev, "failed to setup rss tables\n"); |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 2330 | goto abort_with_nothing; |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 2331 | } |
| 2332 | |
| 2333 | /* just enable an identity mapping */ |
| 2334 | itable = mgp->sram + cmd.data0; |
| 2335 | for (i = 0; i < mgp->num_slices; i++) |
| 2336 | __raw_writeb(i, &itable[i]); |
| 2337 | |
| 2338 | cmd.data0 = 1; |
| 2339 | cmd.data1 = myri10ge_rss_hash; |
| 2340 | status = myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_RSS_ENABLE, |
| 2341 | &cmd, 0); |
| 2342 | if (status != 0) { |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 2343 | netdev_err(dev, "failed to enable slices\n"); |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 2344 | goto abort_with_nothing; |
| 2345 | } |
| 2346 | } |
| 2347 | |
Brice Goglin | df30a74 | 2006-12-18 11:50:40 +0100 | [diff] [blame] | 2348 | status = myri10ge_request_irq(mgp); |
| 2349 | if (status != 0) |
| 2350 | goto abort_with_nothing; |
| 2351 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2352 | /* decide what small buffer size to use. For good TCP rx |
| 2353 | * performance, it is important to not receive 1514 byte |
| 2354 | * frames into jumbo buffers, as it confuses the socket buffer |
| 2355 | * accounting code, leading to drops and erratic performance. |
| 2356 | */ |
| 2357 | |
| 2358 | if (dev->mtu <= ETH_DATA_LEN) |
Brice Goglin | c7dab99 | 2006-12-11 11:25:42 +0100 | [diff] [blame] | 2359 | /* enough for a TCP header */ |
| 2360 | mgp->small_bytes = (128 > SMP_CACHE_BYTES) |
| 2361 | ? (128 - MXGEFW_PAD) |
| 2362 | : (SMP_CACHE_BYTES - MXGEFW_PAD); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2363 | else |
Brice Goglin | de3c450 | 2006-12-11 11:26:38 +0100 | [diff] [blame] | 2364 | /* enough for a vlan encapsulated ETH_DATA_LEN frame */ |
| 2365 | mgp->small_bytes = VLAN_ETH_FRAME_LEN; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2366 | |
| 2367 | /* Override the small buffer size? */ |
Jon Mason | 4b47638 | 2011-06-27 05:05:03 +0000 | [diff] [blame] | 2368 | if (myri10ge_small_bytes >= 0) |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2369 | mgp->small_bytes = myri10ge_small_bytes; |
| 2370 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2371 | /* Firmware needs the big buff size as a power of 2. Lie and |
| 2372 | * tell him the buffer is larger, because we only use 1 |
| 2373 | * buffer/pkt, and the mtu will prevent overruns. |
| 2374 | */ |
Brice Goglin | 13348be | 2006-12-11 11:27:19 +0100 | [diff] [blame] | 2375 | big_pow2 = dev->mtu + ETH_HLEN + VLAN_HLEN + MXGEFW_PAD; |
Brice Goglin | c7dab99 | 2006-12-11 11:25:42 +0100 | [diff] [blame] | 2376 | if (big_pow2 < MYRI10GE_ALLOC_SIZE / 2) { |
vignesh babu | 199126a | 2007-07-09 11:50:22 -0700 | [diff] [blame] | 2377 | while (!is_power_of_2(big_pow2)) |
Brice Goglin | c7dab99 | 2006-12-11 11:25:42 +0100 | [diff] [blame] | 2378 | big_pow2++; |
Brice Goglin | 13348be | 2006-12-11 11:27:19 +0100 | [diff] [blame] | 2379 | mgp->big_bytes = dev->mtu + ETH_HLEN + VLAN_HLEN + MXGEFW_PAD; |
Brice Goglin | c7dab99 | 2006-12-11 11:25:42 +0100 | [diff] [blame] | 2380 | } else { |
| 2381 | big_pow2 = MYRI10GE_ALLOC_SIZE; |
| 2382 | mgp->big_bytes = big_pow2; |
| 2383 | } |
| 2384 | |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 2385 | /* setup the per-slice data structures */ |
| 2386 | for (slice = 0; slice < mgp->num_slices; slice++) { |
| 2387 | ss = &mgp->ss[slice]; |
| 2388 | |
| 2389 | status = myri10ge_get_txrx(mgp, slice); |
| 2390 | if (status != 0) { |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 2391 | netdev_err(dev, "failed to get ring sizes or locations\n"); |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 2392 | goto abort_with_rings; |
| 2393 | } |
| 2394 | status = myri10ge_allocate_rings(ss); |
| 2395 | if (status != 0) |
| 2396 | goto abort_with_rings; |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 2397 | |
| 2398 | /* only firmware which supports multiple TX queues |
| 2399 | * supports setting up the tx stats on non-zero |
| 2400 | * slices */ |
| 2401 | if (slice == 0 || mgp->dev->real_num_tx_queues > 1) |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 2402 | status = myri10ge_set_stats(mgp, slice); |
| 2403 | if (status) { |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 2404 | netdev_err(dev, "Couldn't set stats DMA\n"); |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 2405 | goto abort_with_rings; |
| 2406 | } |
| 2407 | |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 2408 | /* must happen prior to any irq */ |
| 2409 | napi_enable(&(ss)->napi); |
| 2410 | } |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2411 | |
| 2412 | /* now give firmware buffers sizes, and MTU */ |
| 2413 | cmd.data0 = dev->mtu + ETH_HLEN + VLAN_HLEN; |
| 2414 | status = myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_MTU, &cmd, 0); |
| 2415 | cmd.data0 = mgp->small_bytes; |
| 2416 | status |= |
| 2417 | myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_SMALL_BUFFER_SIZE, &cmd, 0); |
| 2418 | cmd.data0 = big_pow2; |
| 2419 | status |= |
| 2420 | myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_BIG_BUFFER_SIZE, &cmd, 0); |
| 2421 | if (status) { |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 2422 | netdev_err(dev, "Couldn't set buffer sizes\n"); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2423 | goto abort_with_rings; |
| 2424 | } |
| 2425 | |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 2426 | /* |
| 2427 | * Set Linux style TSO mode; this is needed only on newer |
| 2428 | * firmware versions. Older versions default to Linux |
| 2429 | * style TSO |
| 2430 | */ |
| 2431 | cmd.data0 = 0; |
| 2432 | status = myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_TSO_MODE, &cmd, 0); |
| 2433 | if (status && status != -ENOSYS) { |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 2434 | netdev_err(dev, "Couldn't set TSO mode\n"); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2435 | goto abort_with_rings; |
| 2436 | } |
| 2437 | |
Al Viro | 66341ff | 2007-12-22 18:56:43 +0000 | [diff] [blame] | 2438 | mgp->link_state = ~0U; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2439 | mgp->rdma_tags_available = 15; |
| 2440 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2441 | status = myri10ge_send_cmd(mgp, MXGEFW_CMD_ETHERNET_UP, &cmd, 0); |
| 2442 | if (status) { |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 2443 | netdev_err(dev, "Couldn't bring up link\n"); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2444 | goto abort_with_rings; |
| 2445 | } |
| 2446 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2447 | mgp->running = MYRI10GE_ETH_RUNNING; |
| 2448 | mgp->watchdog_timer.expires = jiffies + myri10ge_watchdog_timeout * HZ; |
| 2449 | add_timer(&mgp->watchdog_timer); |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 2450 | netif_tx_wake_all_queues(dev); |
| 2451 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2452 | return 0; |
| 2453 | |
| 2454 | abort_with_rings: |
Brice Goglin | 051d36f | 2008-10-20 13:54:12 +0200 | [diff] [blame] | 2455 | while (slice) { |
| 2456 | slice--; |
| 2457 | napi_disable(&mgp->ss[slice].napi); |
| 2458 | } |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 2459 | for (i = 0; i < mgp->num_slices; i++) |
| 2460 | myri10ge_free_rings(&mgp->ss[i]); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2461 | |
Brice Goglin | df30a74 | 2006-12-18 11:50:40 +0100 | [diff] [blame] | 2462 | myri10ge_free_irq(mgp); |
| 2463 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2464 | abort_with_nothing: |
| 2465 | mgp->running = MYRI10GE_ETH_STOPPED; |
| 2466 | return -ENOMEM; |
| 2467 | } |
| 2468 | |
| 2469 | static int myri10ge_close(struct net_device *dev) |
| 2470 | { |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2471 | struct myri10ge_priv *mgp = netdev_priv(dev); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2472 | struct myri10ge_cmd cmd; |
| 2473 | int status, old_down_cnt; |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 2474 | int i; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2475 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2476 | if (mgp->running != MYRI10GE_ETH_RUNNING) |
| 2477 | return 0; |
| 2478 | |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 2479 | if (mgp->ss[0].tx.req_bytes == NULL) |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2480 | return 0; |
| 2481 | |
| 2482 | del_timer_sync(&mgp->watchdog_timer); |
| 2483 | mgp->running = MYRI10GE_ETH_STOPPING; |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 2484 | for (i = 0; i < mgp->num_slices; i++) { |
| 2485 | napi_disable(&mgp->ss[i].napi); |
| 2486 | } |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2487 | netif_carrier_off(dev); |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 2488 | |
| 2489 | netif_tx_stop_all_queues(dev); |
Brice Goglin | d023421 | 2009-08-07 10:44:22 +0000 | [diff] [blame] | 2490 | if (mgp->rebooted == 0) { |
| 2491 | old_down_cnt = mgp->down_cnt; |
| 2492 | mb(); |
| 2493 | status = |
| 2494 | myri10ge_send_cmd(mgp, MXGEFW_CMD_ETHERNET_DOWN, &cmd, 0); |
| 2495 | if (status) |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 2496 | netdev_err(dev, "Couldn't bring down link\n"); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2497 | |
Brice Goglin | d023421 | 2009-08-07 10:44:22 +0000 | [diff] [blame] | 2498 | wait_event_timeout(mgp->down_wq, old_down_cnt != mgp->down_cnt, |
| 2499 | HZ); |
| 2500 | if (old_down_cnt == mgp->down_cnt) |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 2501 | netdev_err(dev, "never got down irq\n"); |
Brice Goglin | d023421 | 2009-08-07 10:44:22 +0000 | [diff] [blame] | 2502 | } |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2503 | netif_tx_disable(dev); |
Brice Goglin | df30a74 | 2006-12-18 11:50:40 +0100 | [diff] [blame] | 2504 | myri10ge_free_irq(mgp); |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 2505 | for (i = 0; i < mgp->num_slices; i++) |
| 2506 | myri10ge_free_rings(&mgp->ss[i]); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2507 | |
| 2508 | mgp->running = MYRI10GE_ETH_STOPPED; |
| 2509 | return 0; |
| 2510 | } |
| 2511 | |
| 2512 | /* copy an array of struct mcp_kreq_ether_send's to the mcp. Copy |
| 2513 | * backwards one at a time and handle ring wraps */ |
| 2514 | |
| 2515 | static inline void |
| 2516 | myri10ge_submit_req_backwards(struct myri10ge_tx_buf *tx, |
| 2517 | struct mcp_kreq_ether_send *src, int cnt) |
| 2518 | { |
| 2519 | int idx, starting_slot; |
| 2520 | starting_slot = tx->req; |
| 2521 | while (cnt > 1) { |
| 2522 | cnt--; |
| 2523 | idx = (starting_slot + cnt) & tx->mask; |
| 2524 | myri10ge_pio_copy(&tx->lanai[idx], &src[cnt], sizeof(*src)); |
| 2525 | mb(); |
| 2526 | } |
| 2527 | } |
| 2528 | |
| 2529 | /* |
| 2530 | * copy an array of struct mcp_kreq_ether_send's to the mcp. Copy |
| 2531 | * at most 32 bytes at a time, so as to avoid involving the software |
| 2532 | * pio handler in the nic. We re-write the first segment's flags |
| 2533 | * to mark them valid only after writing the entire chain. |
| 2534 | */ |
| 2535 | |
| 2536 | static inline void |
| 2537 | myri10ge_submit_req(struct myri10ge_tx_buf *tx, struct mcp_kreq_ether_send *src, |
| 2538 | int cnt) |
| 2539 | { |
| 2540 | int idx, i; |
| 2541 | struct mcp_kreq_ether_send __iomem *dstp, *dst; |
| 2542 | struct mcp_kreq_ether_send *srcp; |
| 2543 | u8 last_flags; |
| 2544 | |
| 2545 | idx = tx->req & tx->mask; |
| 2546 | |
| 2547 | last_flags = src->flags; |
| 2548 | src->flags = 0; |
| 2549 | mb(); |
| 2550 | dst = dstp = &tx->lanai[idx]; |
| 2551 | srcp = src; |
| 2552 | |
| 2553 | if ((idx + cnt) < tx->mask) { |
| 2554 | for (i = 0; i < (cnt - 1); i += 2) { |
| 2555 | myri10ge_pio_copy(dstp, srcp, 2 * sizeof(*src)); |
| 2556 | mb(); /* force write every 32 bytes */ |
| 2557 | srcp += 2; |
| 2558 | dstp += 2; |
| 2559 | } |
| 2560 | } else { |
| 2561 | /* submit all but the first request, and ensure |
| 2562 | * that it is submitted below */ |
| 2563 | myri10ge_submit_req_backwards(tx, src, cnt); |
| 2564 | i = 0; |
| 2565 | } |
| 2566 | if (i < cnt) { |
| 2567 | /* submit the first request */ |
| 2568 | myri10ge_pio_copy(dstp, srcp, sizeof(*src)); |
| 2569 | mb(); /* barrier before setting valid flag */ |
| 2570 | } |
| 2571 | |
| 2572 | /* re-write the last 32-bits with the valid flags */ |
| 2573 | src->flags = last_flags; |
Al Viro | 40f6cff | 2006-11-20 13:48:32 -0500 | [diff] [blame] | 2574 | put_be32(*((__be32 *) src + 3), (__be32 __iomem *) dst + 3); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2575 | tx->req += cnt; |
| 2576 | mb(); |
| 2577 | } |
| 2578 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2579 | /* |
| 2580 | * Transmit a packet. We need to split the packet so that a single |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2581 | * segment does not cross myri10ge->tx_boundary, so this makes segment |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2582 | * counting tricky. So rather than try to count segments up front, we |
| 2583 | * just give up if there are too few segments to hold a reasonably |
| 2584 | * fragmented packet currently available. If we run |
| 2585 | * out of segments while preparing a packet for DMA, we just linearize |
| 2586 | * it and try again. |
| 2587 | */ |
| 2588 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 2589 | static netdev_tx_t myri10ge_xmit(struct sk_buff *skb, |
| 2590 | struct net_device *dev) |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2591 | { |
| 2592 | struct myri10ge_priv *mgp = netdev_priv(dev); |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2593 | struct myri10ge_slice_state *ss; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2594 | struct mcp_kreq_ether_send *req; |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2595 | struct myri10ge_tx_buf *tx; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2596 | struct skb_frag_struct *frag; |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 2597 | struct netdev_queue *netdev_queue; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2598 | dma_addr_t bus; |
Al Viro | 40f6cff | 2006-11-20 13:48:32 -0500 | [diff] [blame] | 2599 | u32 low; |
| 2600 | __be32 high_swapped; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2601 | unsigned int len; |
| 2602 | int idx, last_idx, avail, frag_cnt, frag_idx, count, mss, max_segments; |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 2603 | u16 pseudo_hdr_offset, cksum_offset, queue; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2604 | int cum_len, seglen, boundary, rdma_count; |
| 2605 | u8 flags, odd_flag; |
| 2606 | |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 2607 | queue = skb_get_queue_mapping(skb); |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 2608 | ss = &mgp->ss[queue]; |
| 2609 | netdev_queue = netdev_get_tx_queue(mgp->dev, queue); |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2610 | tx = &ss->tx; |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 2611 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2612 | again: |
| 2613 | req = tx->req_list; |
| 2614 | avail = tx->mask - 1 - (tx->req - tx->done); |
| 2615 | |
| 2616 | mss = 0; |
| 2617 | max_segments = MXGEFW_MAX_SEND_DESC; |
| 2618 | |
Brice Goglin | 917690c | 2007-03-27 21:54:53 +0200 | [diff] [blame] | 2619 | if (skb_is_gso(skb)) { |
Herbert Xu | 7967168 | 2006-06-22 02:40:14 -0700 | [diff] [blame] | 2620 | mss = skb_shinfo(skb)->gso_size; |
Brice Goglin | 917690c | 2007-03-27 21:54:53 +0200 | [diff] [blame] | 2621 | max_segments = MYRI10GE_MAX_SEND_DESC_TSO; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2622 | } |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2623 | |
| 2624 | if ((unlikely(avail < max_segments))) { |
| 2625 | /* we are out of transmit resources */ |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2626 | tx->stop_queue++; |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 2627 | netif_tx_stop_queue(netdev_queue); |
Patrick McHardy | 5b54814 | 2009-06-12 06:22:29 +0000 | [diff] [blame] | 2628 | return NETDEV_TX_BUSY; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2629 | } |
| 2630 | |
| 2631 | /* Setup checksum offloading, if needed */ |
| 2632 | cksum_offset = 0; |
| 2633 | pseudo_hdr_offset = 0; |
| 2634 | odd_flag = 0; |
| 2635 | flags = (MXGEFW_FLAGS_NO_TSO | MXGEFW_FLAGS_FIRST); |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 2636 | if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) { |
Michał Mirosław | 0d0b167 | 2010-12-14 15:24:08 +0000 | [diff] [blame] | 2637 | cksum_offset = skb_checksum_start_offset(skb); |
Al Viro | ff1dcad | 2006-11-20 18:07:29 -0800 | [diff] [blame] | 2638 | pseudo_hdr_offset = cksum_offset + skb->csum_offset; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2639 | /* If the headers are excessively large, then we must |
| 2640 | * fall back to a software checksum */ |
Brice Goglin | 4f93fde | 2007-10-13 12:34:01 +0200 | [diff] [blame] | 2641 | if (unlikely(!mss && (cksum_offset > 255 || |
| 2642 | pseudo_hdr_offset > 127))) { |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 2643 | if (skb_checksum_help(skb)) |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2644 | goto drop; |
| 2645 | cksum_offset = 0; |
| 2646 | pseudo_hdr_offset = 0; |
| 2647 | } else { |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2648 | odd_flag = MXGEFW_FLAGS_ALIGN_ODD; |
| 2649 | flags |= MXGEFW_FLAGS_CKSUM; |
| 2650 | } |
| 2651 | } |
| 2652 | |
| 2653 | cum_len = 0; |
| 2654 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2655 | if (mss) { /* TSO */ |
| 2656 | /* this removes any CKSUM flag from before */ |
| 2657 | flags = (MXGEFW_FLAGS_TSO_HDR | MXGEFW_FLAGS_FIRST); |
| 2658 | |
| 2659 | /* negative cum_len signifies to the |
| 2660 | * send loop that we are still in the |
| 2661 | * header portion of the TSO packet. |
Brice Goglin | 4f93fde | 2007-10-13 12:34:01 +0200 | [diff] [blame] | 2662 | * TSO header can be at most 1KB long */ |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 2663 | cum_len = -(skb_transport_offset(skb) + tcp_hdrlen(skb)); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2664 | |
Brice Goglin | 4f93fde | 2007-10-13 12:34:01 +0200 | [diff] [blame] | 2665 | /* for IPv6 TSO, the checksum offset stores the |
| 2666 | * TCP header length, to save the firmware from |
| 2667 | * the need to parse the headers */ |
| 2668 | if (skb_is_gso_v6(skb)) { |
| 2669 | cksum_offset = tcp_hdrlen(skb); |
| 2670 | /* Can only handle headers <= max_tso6 long */ |
| 2671 | if (unlikely(-cum_len > mgp->max_tso6)) |
| 2672 | return myri10ge_sw_tso(skb, dev); |
| 2673 | } |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2674 | /* for TSO, pseudo_hdr_offset holds mss. |
| 2675 | * The firmware figures out where to put |
| 2676 | * the checksum by parsing the header. */ |
Al Viro | 40f6cff | 2006-11-20 13:48:32 -0500 | [diff] [blame] | 2677 | pseudo_hdr_offset = mss; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2678 | } else |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2679 | /* Mark small packets, and pad out tiny packets */ |
| 2680 | if (skb->len <= MXGEFW_SEND_SMALL_SIZE) { |
| 2681 | flags |= MXGEFW_FLAGS_SMALL; |
| 2682 | |
| 2683 | /* pad frames to at least ETH_ZLEN bytes */ |
| 2684 | if (unlikely(skb->len < ETH_ZLEN)) { |
Herbert Xu | 5b057c6 | 2006-06-23 02:06:41 -0700 | [diff] [blame] | 2685 | if (skb_padto(skb, ETH_ZLEN)) { |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2686 | /* The packet is gone, so we must |
| 2687 | * return 0 */ |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2688 | ss->stats.tx_dropped += 1; |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 2689 | return NETDEV_TX_OK; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2690 | } |
| 2691 | /* adjust the len to account for the zero pad |
| 2692 | * so that the nic can know how long it is */ |
| 2693 | skb->len = ETH_ZLEN; |
| 2694 | } |
| 2695 | } |
| 2696 | |
| 2697 | /* map the skb for DMA */ |
Eric Dumazet | e743d31 | 2010-04-14 15:59:40 -0700 | [diff] [blame] | 2698 | len = skb_headlen(skb); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2699 | idx = tx->req & tx->mask; |
| 2700 | tx->info[idx].skb = skb; |
| 2701 | bus = pci_map_single(mgp->pdev, skb->data, len, PCI_DMA_TODEVICE); |
FUJITA Tomonori | c755b4b | 2010-04-12 14:32:10 +0000 | [diff] [blame] | 2702 | dma_unmap_addr_set(&tx->info[idx], bus, bus); |
| 2703 | dma_unmap_len_set(&tx->info[idx], len, len); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2704 | |
| 2705 | frag_cnt = skb_shinfo(skb)->nr_frags; |
| 2706 | frag_idx = 0; |
| 2707 | count = 0; |
| 2708 | rdma_count = 0; |
| 2709 | |
| 2710 | /* "rdma_count" is the number of RDMAs belonging to the |
| 2711 | * current packet BEFORE the current send request. For |
| 2712 | * non-TSO packets, this is equal to "count". |
| 2713 | * For TSO packets, rdma_count needs to be reset |
| 2714 | * to 0 after a segment cut. |
| 2715 | * |
| 2716 | * The rdma_count field of the send request is |
| 2717 | * the number of RDMAs of the packet starting at |
| 2718 | * that request. For TSO send requests with one ore more cuts |
| 2719 | * in the middle, this is the number of RDMAs starting |
| 2720 | * after the last cut in the request. All previous |
| 2721 | * segments before the last cut implicitly have 1 RDMA. |
| 2722 | * |
| 2723 | * Since the number of RDMAs is not known beforehand, |
| 2724 | * it must be filled-in retroactively - after each |
| 2725 | * segmentation cut or at the end of the entire packet. |
| 2726 | */ |
| 2727 | |
| 2728 | while (1) { |
| 2729 | /* Break the SKB or Fragment up into pieces which |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2730 | * do not cross mgp->tx_boundary */ |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2731 | low = MYRI10GE_LOWPART_TO_U32(bus); |
| 2732 | high_swapped = htonl(MYRI10GE_HIGHPART_TO_U32(bus)); |
| 2733 | while (len) { |
| 2734 | u8 flags_next; |
| 2735 | int cum_len_next; |
| 2736 | |
| 2737 | if (unlikely(count == max_segments)) |
| 2738 | goto abort_linearize; |
| 2739 | |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2740 | boundary = |
| 2741 | (low + mgp->tx_boundary) & ~(mgp->tx_boundary - 1); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2742 | seglen = boundary - low; |
| 2743 | if (seglen > len) |
| 2744 | seglen = len; |
| 2745 | flags_next = flags & ~MXGEFW_FLAGS_FIRST; |
| 2746 | cum_len_next = cum_len + seglen; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2747 | if (mss) { /* TSO */ |
| 2748 | (req - rdma_count)->rdma_count = rdma_count + 1; |
| 2749 | |
| 2750 | if (likely(cum_len >= 0)) { /* payload */ |
| 2751 | int next_is_first, chop; |
| 2752 | |
| 2753 | chop = (cum_len_next > mss); |
| 2754 | cum_len_next = cum_len_next % mss; |
| 2755 | next_is_first = (cum_len_next == 0); |
| 2756 | flags |= chop * MXGEFW_FLAGS_TSO_CHOP; |
| 2757 | flags_next |= next_is_first * |
| 2758 | MXGEFW_FLAGS_FIRST; |
| 2759 | rdma_count |= -(chop | next_is_first); |
Andrew Gallatin | 59e955e | 2012-12-04 10:17:15 +0000 | [diff] [blame] | 2760 | rdma_count += chop & ~next_is_first; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2761 | } else if (likely(cum_len_next >= 0)) { /* header ends */ |
| 2762 | int small; |
| 2763 | |
| 2764 | rdma_count = -1; |
| 2765 | cum_len_next = 0; |
| 2766 | seglen = -cum_len; |
| 2767 | small = (mss <= MXGEFW_SEND_SMALL_SIZE); |
| 2768 | flags_next = MXGEFW_FLAGS_TSO_PLD | |
| 2769 | MXGEFW_FLAGS_FIRST | |
| 2770 | (small * MXGEFW_FLAGS_SMALL); |
| 2771 | } |
| 2772 | } |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2773 | req->addr_high = high_swapped; |
| 2774 | req->addr_low = htonl(low); |
Al Viro | 40f6cff | 2006-11-20 13:48:32 -0500 | [diff] [blame] | 2775 | req->pseudo_hdr_offset = htons(pseudo_hdr_offset); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2776 | req->pad = 0; /* complete solid 16-byte block; does this matter? */ |
| 2777 | req->rdma_count = 1; |
| 2778 | req->length = htons(seglen); |
| 2779 | req->cksum_offset = cksum_offset; |
| 2780 | req->flags = flags | ((cum_len & 1) * odd_flag); |
| 2781 | |
| 2782 | low += seglen; |
| 2783 | len -= seglen; |
| 2784 | cum_len = cum_len_next; |
| 2785 | flags = flags_next; |
| 2786 | req++; |
| 2787 | count++; |
| 2788 | rdma_count++; |
Brice Goglin | 4f93fde | 2007-10-13 12:34:01 +0200 | [diff] [blame] | 2789 | if (cksum_offset != 0 && !(mss && skb_is_gso_v6(skb))) { |
| 2790 | if (unlikely(cksum_offset > seglen)) |
| 2791 | cksum_offset -= seglen; |
| 2792 | else |
| 2793 | cksum_offset = 0; |
| 2794 | } |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2795 | } |
| 2796 | if (frag_idx == frag_cnt) |
| 2797 | break; |
| 2798 | |
| 2799 | /* map next fragment for DMA */ |
| 2800 | idx = (count + tx->req) & tx->mask; |
| 2801 | frag = &skb_shinfo(skb)->frags[frag_idx]; |
| 2802 | frag_idx++; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 2803 | len = skb_frag_size(frag); |
Ian Campbell | 5dc3e19 | 2011-10-05 00:28:50 +0000 | [diff] [blame] | 2804 | bus = skb_frag_dma_map(&mgp->pdev->dev, frag, 0, len, |
Ian Campbell | 5d6bcdf | 2011-10-06 11:10:48 +0100 | [diff] [blame] | 2805 | DMA_TO_DEVICE); |
FUJITA Tomonori | c755b4b | 2010-04-12 14:32:10 +0000 | [diff] [blame] | 2806 | dma_unmap_addr_set(&tx->info[idx], bus, bus); |
| 2807 | dma_unmap_len_set(&tx->info[idx], len, len); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2808 | } |
| 2809 | |
| 2810 | (req - rdma_count)->rdma_count = rdma_count; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2811 | if (mss) |
| 2812 | do { |
| 2813 | req--; |
| 2814 | req->flags |= MXGEFW_FLAGS_TSO_LAST; |
| 2815 | } while (!(req->flags & (MXGEFW_FLAGS_TSO_CHOP | |
| 2816 | MXGEFW_FLAGS_FIRST))); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2817 | idx = ((count - 1) + tx->req) & tx->mask; |
| 2818 | tx->info[idx].last = 1; |
Brice Goglin | e454e7e | 2008-07-21 10:25:50 +0200 | [diff] [blame] | 2819 | myri10ge_submit_req(tx, tx->req_list, count); |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 2820 | /* if using multiple tx queues, make sure NIC polls the |
| 2821 | * current slice */ |
| 2822 | if ((mgp->dev->real_num_tx_queues > 1) && tx->queue_active == 0) { |
| 2823 | tx->queue_active = 1; |
| 2824 | put_be32(htonl(1), tx->send_go); |
Brice Goglin | 8c2f5fa | 2008-11-10 13:58:41 +0100 | [diff] [blame] | 2825 | mb(); |
Brice Goglin | 6824a10 | 2008-10-30 08:59:33 +0100 | [diff] [blame] | 2826 | mmiowb(); |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 2827 | } |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2828 | tx->pkt_start++; |
| 2829 | if ((avail - count) < MXGEFW_MAX_SEND_DESC) { |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2830 | tx->stop_queue++; |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 2831 | netif_tx_stop_queue(netdev_queue); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2832 | } |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 2833 | return NETDEV_TX_OK; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2834 | |
| 2835 | abort_linearize: |
| 2836 | /* Free any DMA resources we've alloced and clear out the skb |
| 2837 | * slot so as to not trip up assertions, and to avoid a |
| 2838 | * double-free if linearizing fails */ |
| 2839 | |
| 2840 | last_idx = (idx + 1) & tx->mask; |
| 2841 | idx = tx->req & tx->mask; |
| 2842 | tx->info[idx].skb = NULL; |
| 2843 | do { |
FUJITA Tomonori | c755b4b | 2010-04-12 14:32:10 +0000 | [diff] [blame] | 2844 | len = dma_unmap_len(&tx->info[idx], len); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2845 | if (len) { |
| 2846 | if (tx->info[idx].skb != NULL) |
| 2847 | pci_unmap_single(mgp->pdev, |
FUJITA Tomonori | c755b4b | 2010-04-12 14:32:10 +0000 | [diff] [blame] | 2848 | dma_unmap_addr(&tx->info[idx], |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2849 | bus), len, |
| 2850 | PCI_DMA_TODEVICE); |
| 2851 | else |
| 2852 | pci_unmap_page(mgp->pdev, |
FUJITA Tomonori | c755b4b | 2010-04-12 14:32:10 +0000 | [diff] [blame] | 2853 | dma_unmap_addr(&tx->info[idx], |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2854 | bus), len, |
| 2855 | PCI_DMA_TODEVICE); |
FUJITA Tomonori | c755b4b | 2010-04-12 14:32:10 +0000 | [diff] [blame] | 2856 | dma_unmap_len_set(&tx->info[idx], len, 0); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2857 | tx->info[idx].skb = NULL; |
| 2858 | } |
| 2859 | idx = (idx + 1) & tx->mask; |
| 2860 | } while (idx != last_idx); |
Herbert Xu | 89114af | 2006-07-08 13:34:32 -0700 | [diff] [blame] | 2861 | if (skb_is_gso(skb)) { |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 2862 | netdev_err(mgp->dev, "TSO but wanted to linearize?!?!?\n"); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2863 | goto drop; |
| 2864 | } |
| 2865 | |
Andrew Morton | bec0e85 | 2006-06-22 14:47:19 -0700 | [diff] [blame] | 2866 | if (skb_linearize(skb)) |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2867 | goto drop; |
| 2868 | |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2869 | tx->linearized++; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2870 | goto again; |
| 2871 | |
| 2872 | drop: |
| 2873 | dev_kfree_skb_any(skb); |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2874 | ss->stats.tx_dropped += 1; |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 2875 | return NETDEV_TX_OK; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2876 | |
| 2877 | } |
| 2878 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 2879 | static netdev_tx_t myri10ge_sw_tso(struct sk_buff *skb, |
| 2880 | struct net_device *dev) |
Brice Goglin | 4f93fde | 2007-10-13 12:34:01 +0200 | [diff] [blame] | 2881 | { |
| 2882 | struct sk_buff *segs, *curr; |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2883 | struct myri10ge_priv *mgp = netdev_priv(dev); |
Brice Goglin | d6279c8 | 2008-11-20 01:50:04 -0800 | [diff] [blame] | 2884 | struct myri10ge_slice_state *ss; |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 2885 | netdev_tx_t status; |
Brice Goglin | 4f93fde | 2007-10-13 12:34:01 +0200 | [diff] [blame] | 2886 | |
| 2887 | segs = skb_gso_segment(skb, dev->features & ~NETIF_F_TSO6); |
Hirofumi Nakagawa | 801678c | 2008-04-29 01:03:09 -0700 | [diff] [blame] | 2888 | if (IS_ERR(segs)) |
Brice Goglin | 4f93fde | 2007-10-13 12:34:01 +0200 | [diff] [blame] | 2889 | goto drop; |
| 2890 | |
| 2891 | while (segs) { |
| 2892 | curr = segs; |
| 2893 | segs = segs->next; |
| 2894 | curr->next = NULL; |
| 2895 | status = myri10ge_xmit(curr, dev); |
| 2896 | if (status != 0) { |
| 2897 | dev_kfree_skb_any(curr); |
| 2898 | if (segs != NULL) { |
| 2899 | curr = segs; |
| 2900 | segs = segs->next; |
| 2901 | curr->next = NULL; |
| 2902 | dev_kfree_skb_any(segs); |
| 2903 | } |
| 2904 | goto drop; |
| 2905 | } |
| 2906 | } |
| 2907 | dev_kfree_skb_any(skb); |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 2908 | return NETDEV_TX_OK; |
Brice Goglin | 4f93fde | 2007-10-13 12:34:01 +0200 | [diff] [blame] | 2909 | |
| 2910 | drop: |
Brice Goglin | d6279c8 | 2008-11-20 01:50:04 -0800 | [diff] [blame] | 2911 | ss = &mgp->ss[skb_get_queue_mapping(skb)]; |
Brice Goglin | 4f93fde | 2007-10-13 12:34:01 +0200 | [diff] [blame] | 2912 | dev_kfree_skb_any(skb); |
Brice Goglin | d6279c8 | 2008-11-20 01:50:04 -0800 | [diff] [blame] | 2913 | ss->stats.tx_dropped += 1; |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 2914 | return NETDEV_TX_OK; |
Brice Goglin | 4f93fde | 2007-10-13 12:34:01 +0200 | [diff] [blame] | 2915 | } |
| 2916 | |
stephen hemminger | c5f7ef7 | 2011-06-08 14:54:03 +0000 | [diff] [blame] | 2917 | static struct rtnl_link_stats64 *myri10ge_get_stats(struct net_device *dev, |
| 2918 | struct rtnl_link_stats64 *stats) |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2919 | { |
Eric Dumazet | 306ff6e | 2011-06-19 20:07:46 +0000 | [diff] [blame] | 2920 | const struct myri10ge_priv *mgp = netdev_priv(dev); |
| 2921 | const struct myri10ge_slice_netstats *slice_stats; |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 2922 | int i; |
| 2923 | |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 2924 | for (i = 0; i < mgp->num_slices; i++) { |
| 2925 | slice_stats = &mgp->ss[i].stats; |
| 2926 | stats->rx_packets += slice_stats->rx_packets; |
| 2927 | stats->tx_packets += slice_stats->tx_packets; |
| 2928 | stats->rx_bytes += slice_stats->rx_bytes; |
| 2929 | stats->tx_bytes += slice_stats->tx_bytes; |
| 2930 | stats->rx_dropped += slice_stats->rx_dropped; |
| 2931 | stats->tx_dropped += slice_stats->tx_dropped; |
| 2932 | } |
| 2933 | return stats; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2934 | } |
| 2935 | |
| 2936 | static void myri10ge_set_multicast_list(struct net_device *dev) |
| 2937 | { |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 2938 | struct myri10ge_priv *mgp = netdev_priv(dev); |
Brice Goglin | 85a7ea1 | 2006-08-21 17:36:56 -0400 | [diff] [blame] | 2939 | struct myri10ge_cmd cmd; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2940 | struct netdev_hw_addr *ha; |
Brice Goglin | 6250223 | 2006-12-11 11:24:37 +0100 | [diff] [blame] | 2941 | __be32 data[2] = { 0, 0 }; |
Brice Goglin | 85a7ea1 | 2006-08-21 17:36:56 -0400 | [diff] [blame] | 2942 | int err; |
| 2943 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 2944 | /* can be called from atomic contexts, |
| 2945 | * pass 1 to force atomicity in myri10ge_send_cmd() */ |
Brice Goglin | 85a7ea1 | 2006-08-21 17:36:56 -0400 | [diff] [blame] | 2946 | myri10ge_change_promisc(mgp, dev->flags & IFF_PROMISC, 1); |
| 2947 | |
| 2948 | /* This firmware is known to not support multicast */ |
Brice Goglin | 2f76216 | 2007-05-07 23:50:37 +0200 | [diff] [blame] | 2949 | if (!mgp->fw_multicast_support) |
Brice Goglin | 85a7ea1 | 2006-08-21 17:36:56 -0400 | [diff] [blame] | 2950 | return; |
| 2951 | |
| 2952 | /* Disable multicast filtering */ |
| 2953 | |
| 2954 | err = myri10ge_send_cmd(mgp, MXGEFW_ENABLE_ALLMULTI, &cmd, 1); |
| 2955 | if (err != 0) { |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 2956 | netdev_err(dev, "Failed MXGEFW_ENABLE_ALLMULTI, error status: %d\n", |
| 2957 | err); |
Brice Goglin | 85a7ea1 | 2006-08-21 17:36:56 -0400 | [diff] [blame] | 2958 | goto abort; |
| 2959 | } |
| 2960 | |
Brice Goglin | 2f76216 | 2007-05-07 23:50:37 +0200 | [diff] [blame] | 2961 | if ((dev->flags & IFF_ALLMULTI) || mgp->adopted_rx_filter_bug) { |
Brice Goglin | 85a7ea1 | 2006-08-21 17:36:56 -0400 | [diff] [blame] | 2962 | /* request to disable multicast filtering, so quit here */ |
| 2963 | return; |
| 2964 | } |
| 2965 | |
| 2966 | /* Flush the filters */ |
| 2967 | |
| 2968 | err = myri10ge_send_cmd(mgp, MXGEFW_LEAVE_ALL_MULTICAST_GROUPS, |
| 2969 | &cmd, 1); |
| 2970 | if (err != 0) { |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 2971 | netdev_err(dev, "Failed MXGEFW_LEAVE_ALL_MULTICAST_GROUPS, error status: %d\n", |
| 2972 | err); |
Brice Goglin | 85a7ea1 | 2006-08-21 17:36:56 -0400 | [diff] [blame] | 2973 | goto abort; |
| 2974 | } |
| 2975 | |
| 2976 | /* Walk the multicast list, and add each address */ |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2977 | netdev_for_each_mc_addr(ha, dev) { |
| 2978 | memcpy(data, &ha->addr, 6); |
Al Viro | 40f6cff | 2006-11-20 13:48:32 -0500 | [diff] [blame] | 2979 | cmd.data0 = ntohl(data[0]); |
| 2980 | cmd.data1 = ntohl(data[1]); |
Brice Goglin | 85a7ea1 | 2006-08-21 17:36:56 -0400 | [diff] [blame] | 2981 | err = myri10ge_send_cmd(mgp, MXGEFW_JOIN_MULTICAST_GROUP, |
| 2982 | &cmd, 1); |
| 2983 | |
| 2984 | if (err != 0) { |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 2985 | netdev_err(dev, "Failed MXGEFW_JOIN_MULTICAST_GROUP, error status:%d %pM\n", |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2986 | err, ha->addr); |
Brice Goglin | 85a7ea1 | 2006-08-21 17:36:56 -0400 | [diff] [blame] | 2987 | goto abort; |
| 2988 | } |
| 2989 | } |
| 2990 | /* Enable multicast filtering */ |
| 2991 | err = myri10ge_send_cmd(mgp, MXGEFW_DISABLE_ALLMULTI, &cmd, 1); |
| 2992 | if (err != 0) { |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 2993 | netdev_err(dev, "Failed MXGEFW_DISABLE_ALLMULTI, error status: %d\n", |
| 2994 | err); |
Brice Goglin | 85a7ea1 | 2006-08-21 17:36:56 -0400 | [diff] [blame] | 2995 | goto abort; |
| 2996 | } |
| 2997 | |
| 2998 | return; |
| 2999 | |
| 3000 | abort: |
| 3001 | return; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3002 | } |
| 3003 | |
| 3004 | static int myri10ge_set_mac_address(struct net_device *dev, void *addr) |
| 3005 | { |
| 3006 | struct sockaddr *sa = addr; |
| 3007 | struct myri10ge_priv *mgp = netdev_priv(dev); |
| 3008 | int status; |
| 3009 | |
| 3010 | if (!is_valid_ether_addr(sa->sa_data)) |
| 3011 | return -EADDRNOTAVAIL; |
| 3012 | |
| 3013 | status = myri10ge_update_mac_address(mgp, sa->sa_data); |
| 3014 | if (status != 0) { |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 3015 | netdev_err(dev, "changing mac address failed with %d\n", |
| 3016 | status); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3017 | return status; |
| 3018 | } |
| 3019 | |
| 3020 | /* change the dev structure */ |
| 3021 | memcpy(dev->dev_addr, sa->sa_data, 6); |
| 3022 | return 0; |
| 3023 | } |
| 3024 | |
| 3025 | static int myri10ge_change_mtu(struct net_device *dev, int new_mtu) |
| 3026 | { |
| 3027 | struct myri10ge_priv *mgp = netdev_priv(dev); |
| 3028 | int error = 0; |
| 3029 | |
| 3030 | if ((new_mtu < 68) || (ETH_HLEN + new_mtu > MYRI10GE_MAX_ETHER_MTU)) { |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 3031 | netdev_err(dev, "new mtu (%d) is not valid\n", new_mtu); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3032 | return -EINVAL; |
| 3033 | } |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 3034 | netdev_info(dev, "changing mtu from %d to %d\n", dev->mtu, new_mtu); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3035 | if (mgp->running) { |
| 3036 | /* if we change the mtu on an active device, we must |
| 3037 | * reset the device so the firmware sees the change */ |
| 3038 | myri10ge_close(dev); |
| 3039 | dev->mtu = new_mtu; |
| 3040 | myri10ge_open(dev); |
| 3041 | } else |
| 3042 | dev->mtu = new_mtu; |
| 3043 | |
| 3044 | return error; |
| 3045 | } |
| 3046 | |
| 3047 | /* |
| 3048 | * Enable ECRC to align PCI-E Completion packets on an 8-byte boundary. |
| 3049 | * Only do it if the bridge is a root port since we don't want to disturb |
| 3050 | * any other device, except if forced with myri10ge_ecrc_enable > 1. |
| 3051 | */ |
| 3052 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3053 | static void myri10ge_enable_ecrc(struct myri10ge_priv *mgp) |
| 3054 | { |
| 3055 | struct pci_dev *bridge = mgp->pdev->bus->self; |
| 3056 | struct device *dev = &mgp->pdev->dev; |
Jon Mason | effd1ed | 2011-06-27 05:05:05 +0000 | [diff] [blame] | 3057 | int cap; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3058 | unsigned err_cap; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3059 | int ret; |
| 3060 | |
| 3061 | if (!myri10ge_ecrc_enable || !bridge) |
| 3062 | return; |
| 3063 | |
| 3064 | /* check that the bridge is a root port */ |
Jiang Liu | 9503e25 | 2012-07-24 17:20:22 +0800 | [diff] [blame] | 3065 | if (pci_pcie_type(bridge) != PCI_EXP_TYPE_ROOT_PORT) { |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3066 | if (myri10ge_ecrc_enable > 1) { |
Brice Goglin | eca3fd8 | 2008-05-09 02:19:29 +0200 | [diff] [blame] | 3067 | struct pci_dev *prev_bridge, *old_bridge = bridge; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3068 | |
| 3069 | /* Walk the hierarchy up to the root port |
| 3070 | * where ECRC has to be enabled */ |
| 3071 | do { |
Brice Goglin | eca3fd8 | 2008-05-09 02:19:29 +0200 | [diff] [blame] | 3072 | prev_bridge = bridge; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3073 | bridge = bridge->bus->self; |
Brice Goglin | eca3fd8 | 2008-05-09 02:19:29 +0200 | [diff] [blame] | 3074 | if (!bridge || prev_bridge == bridge) { |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3075 | dev_err(dev, |
| 3076 | "Failed to find root port" |
| 3077 | " to force ECRC\n"); |
| 3078 | return; |
| 3079 | } |
Jiang Liu | 9503e25 | 2012-07-24 17:20:22 +0800 | [diff] [blame] | 3080 | } while (pci_pcie_type(bridge) != |
| 3081 | PCI_EXP_TYPE_ROOT_PORT); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3082 | |
| 3083 | dev_info(dev, |
| 3084 | "Forcing ECRC on non-root port %s" |
| 3085 | " (enabling on root port %s)\n", |
| 3086 | pci_name(old_bridge), pci_name(bridge)); |
| 3087 | } else { |
| 3088 | dev_err(dev, |
| 3089 | "Not enabling ECRC on non-root port %s\n", |
| 3090 | pci_name(bridge)); |
| 3091 | return; |
| 3092 | } |
| 3093 | } |
| 3094 | |
| 3095 | cap = pci_find_ext_capability(bridge, PCI_EXT_CAP_ID_ERR); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3096 | if (!cap) |
| 3097 | return; |
| 3098 | |
| 3099 | ret = pci_read_config_dword(bridge, cap + PCI_ERR_CAP, &err_cap); |
| 3100 | if (ret) { |
| 3101 | dev_err(dev, "failed reading ext-conf-space of %s\n", |
| 3102 | pci_name(bridge)); |
| 3103 | dev_err(dev, "\t pci=nommconf in use? " |
| 3104 | "or buggy/incomplete/absent ACPI MCFG attr?\n"); |
| 3105 | return; |
| 3106 | } |
| 3107 | if (!(err_cap & PCI_ERR_CAP_ECRC_GENC)) |
| 3108 | return; |
| 3109 | |
| 3110 | err_cap |= PCI_ERR_CAP_ECRC_GENE; |
| 3111 | pci_write_config_dword(bridge, cap + PCI_ERR_CAP, err_cap); |
| 3112 | dev_info(dev, "Enabled ECRC on upstream bridge %s\n", pci_name(bridge)); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3113 | } |
| 3114 | |
| 3115 | /* |
| 3116 | * The Lanai Z8E PCI-E interface achieves higher Read-DMA throughput |
| 3117 | * when the PCI-E Completion packets are aligned on an 8-byte |
| 3118 | * boundary. Some PCI-E chip sets always align Completion packets; on |
| 3119 | * the ones that do not, the alignment can be enforced by enabling |
| 3120 | * ECRC generation (if supported). |
| 3121 | * |
| 3122 | * When PCI-E Completion packets are not aligned, it is actually more |
| 3123 | * efficient to limit Read-DMA transactions to 2KB, rather than 4KB. |
| 3124 | * |
| 3125 | * If the driver can neither enable ECRC nor verify that it has |
| 3126 | * already been enabled, then it must use a firmware image which works |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 3127 | * around unaligned completion packets (myri10ge_rss_ethp_z8e.dat), and it |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3128 | * should also ensure that it never gives the device a Read-DMA which is |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 3129 | * larger than 2KB by setting the tx_boundary to 2KB. If ECRC is |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 3130 | * enabled, then the driver should use the aligned (myri10ge_rss_eth_z8e.dat) |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 3131 | * firmware image, and set tx_boundary to 4KB. |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3132 | */ |
| 3133 | |
Brice Goglin | 5443e9e | 2007-05-07 23:52:22 +0200 | [diff] [blame] | 3134 | static void myri10ge_firmware_probe(struct myri10ge_priv *mgp) |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3135 | { |
Brice Goglin | 5443e9e | 2007-05-07 23:52:22 +0200 | [diff] [blame] | 3136 | struct pci_dev *pdev = mgp->pdev; |
| 3137 | struct device *dev = &pdev->dev; |
Brice Goglin | 302d242 | 2007-08-24 08:57:17 +0200 | [diff] [blame] | 3138 | int status; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3139 | |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 3140 | mgp->tx_boundary = 4096; |
Brice Goglin | 5443e9e | 2007-05-07 23:52:22 +0200 | [diff] [blame] | 3141 | /* |
| 3142 | * Verify the max read request size was set to 4KB |
| 3143 | * before trying the test with 4KB. |
| 3144 | */ |
Brice Goglin | 302d242 | 2007-08-24 08:57:17 +0200 | [diff] [blame] | 3145 | status = pcie_get_readrq(pdev); |
| 3146 | if (status < 0) { |
Brice Goglin | 5443e9e | 2007-05-07 23:52:22 +0200 | [diff] [blame] | 3147 | dev_err(dev, "Couldn't read max read req size: %d\n", status); |
| 3148 | goto abort; |
| 3149 | } |
Brice Goglin | 302d242 | 2007-08-24 08:57:17 +0200 | [diff] [blame] | 3150 | if (status != 4096) { |
| 3151 | dev_warn(dev, "Max Read Request size != 4096 (%d)\n", status); |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 3152 | mgp->tx_boundary = 2048; |
Brice Goglin | 5443e9e | 2007-05-07 23:52:22 +0200 | [diff] [blame] | 3153 | } |
| 3154 | /* |
| 3155 | * load the optimized firmware (which assumes aligned PCIe |
| 3156 | * completions) in order to see if it works on this host. |
| 3157 | */ |
Rusty Russell | 7d35103 | 2010-08-11 23:04:31 -0600 | [diff] [blame] | 3158 | set_fw_name(mgp, myri10ge_fw_aligned, false); |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 3159 | status = myri10ge_load_firmware(mgp, 1); |
Brice Goglin | 5443e9e | 2007-05-07 23:52:22 +0200 | [diff] [blame] | 3160 | if (status != 0) { |
| 3161 | goto abort; |
| 3162 | } |
| 3163 | |
| 3164 | /* |
| 3165 | * Enable ECRC if possible |
| 3166 | */ |
| 3167 | myri10ge_enable_ecrc(mgp); |
| 3168 | |
| 3169 | /* |
| 3170 | * Run a DMA test which watches for unaligned completions and |
| 3171 | * aborts on the first one seen. |
| 3172 | */ |
| 3173 | |
| 3174 | status = myri10ge_dma_test(mgp, MXGEFW_CMD_UNALIGNED_TEST); |
| 3175 | if (status == 0) |
| 3176 | return; /* keep the aligned firmware */ |
| 3177 | |
| 3178 | if (status != -E2BIG) |
| 3179 | dev_warn(dev, "DMA test failed: %d\n", status); |
| 3180 | if (status == -ENOSYS) |
| 3181 | dev_warn(dev, "Falling back to ethp! " |
| 3182 | "Please install up to date fw\n"); |
| 3183 | abort: |
| 3184 | /* fall back to using the unaligned firmware */ |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 3185 | mgp->tx_boundary = 2048; |
Rusty Russell | 7d35103 | 2010-08-11 23:04:31 -0600 | [diff] [blame] | 3186 | set_fw_name(mgp, myri10ge_fw_unaligned, false); |
Brice Goglin | 5443e9e | 2007-05-07 23:52:22 +0200 | [diff] [blame] | 3187 | } |
| 3188 | |
| 3189 | static void myri10ge_select_firmware(struct myri10ge_priv *mgp) |
| 3190 | { |
Brice Goglin | 2d90b0a | 2009-04-16 02:24:59 +0000 | [diff] [blame] | 3191 | int overridden = 0; |
| 3192 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3193 | if (myri10ge_force_firmware == 0) { |
Jiang Liu | 9503e25 | 2012-07-24 17:20:22 +0800 | [diff] [blame] | 3194 | int link_width; |
Brice Goglin | ce7f936 | 2006-08-31 01:32:59 -0400 | [diff] [blame] | 3195 | u16 lnk; |
| 3196 | |
Jiang Liu | 9503e25 | 2012-07-24 17:20:22 +0800 | [diff] [blame] | 3197 | pcie_capability_read_word(mgp->pdev, PCI_EXP_LNKSTA, &lnk); |
Brice Goglin | ce7f936 | 2006-08-31 01:32:59 -0400 | [diff] [blame] | 3198 | link_width = (lnk >> 4) & 0x3f; |
| 3199 | |
Brice Goglin | ce7f936 | 2006-08-31 01:32:59 -0400 | [diff] [blame] | 3200 | /* Check to see if Link is less than 8 or if the |
| 3201 | * upstream bridge is known to provide aligned |
| 3202 | * completions */ |
| 3203 | if (link_width < 8) { |
| 3204 | dev_info(&mgp->pdev->dev, "PCIE x%d Link\n", |
| 3205 | link_width); |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 3206 | mgp->tx_boundary = 4096; |
Rusty Russell | 7d35103 | 2010-08-11 23:04:31 -0600 | [diff] [blame] | 3207 | set_fw_name(mgp, myri10ge_fw_aligned, false); |
Brice Goglin | 5443e9e | 2007-05-07 23:52:22 +0200 | [diff] [blame] | 3208 | } else { |
| 3209 | myri10ge_firmware_probe(mgp); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3210 | } |
| 3211 | } else { |
| 3212 | if (myri10ge_force_firmware == 1) { |
| 3213 | dev_info(&mgp->pdev->dev, |
| 3214 | "Assuming aligned completions (forced)\n"); |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 3215 | mgp->tx_boundary = 4096; |
Rusty Russell | 7d35103 | 2010-08-11 23:04:31 -0600 | [diff] [blame] | 3216 | set_fw_name(mgp, myri10ge_fw_aligned, false); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3217 | } else { |
| 3218 | dev_info(&mgp->pdev->dev, |
| 3219 | "Assuming unaligned completions (forced)\n"); |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 3220 | mgp->tx_boundary = 2048; |
Rusty Russell | 7d35103 | 2010-08-11 23:04:31 -0600 | [diff] [blame] | 3221 | set_fw_name(mgp, myri10ge_fw_unaligned, false); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3222 | } |
| 3223 | } |
Rusty Russell | 7d35103 | 2010-08-11 23:04:31 -0600 | [diff] [blame] | 3224 | |
| 3225 | kparam_block_sysfs_write(myri10ge_fw_name); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3226 | if (myri10ge_fw_name != NULL) { |
Rusty Russell | 7d35103 | 2010-08-11 23:04:31 -0600 | [diff] [blame] | 3227 | char *fw_name = kstrdup(myri10ge_fw_name, GFP_KERNEL); |
| 3228 | if (fw_name) { |
| 3229 | overridden = 1; |
| 3230 | set_fw_name(mgp, fw_name, true); |
| 3231 | } |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3232 | } |
Rusty Russell | 7d35103 | 2010-08-11 23:04:31 -0600 | [diff] [blame] | 3233 | kparam_unblock_sysfs_write(myri10ge_fw_name); |
| 3234 | |
Brice Goglin | 2d90b0a | 2009-04-16 02:24:59 +0000 | [diff] [blame] | 3235 | if (mgp->board_number < MYRI10GE_MAX_BOARDS && |
| 3236 | myri10ge_fw_names[mgp->board_number] != NULL && |
| 3237 | strlen(myri10ge_fw_names[mgp->board_number])) { |
Rusty Russell | 7d35103 | 2010-08-11 23:04:31 -0600 | [diff] [blame] | 3238 | set_fw_name(mgp, myri10ge_fw_names[mgp->board_number], false); |
Brice Goglin | 2d90b0a | 2009-04-16 02:24:59 +0000 | [diff] [blame] | 3239 | overridden = 1; |
| 3240 | } |
| 3241 | if (overridden) |
| 3242 | dev_info(&mgp->pdev->dev, "overriding firmware to %s\n", |
| 3243 | mgp->fw_name); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3244 | } |
| 3245 | |
Jon Mason | 7539a61 | 2011-06-27 05:05:01 +0000 | [diff] [blame] | 3246 | static void myri10ge_mask_surprise_down(struct pci_dev *pdev) |
| 3247 | { |
| 3248 | struct pci_dev *bridge = pdev->bus->self; |
| 3249 | int cap; |
| 3250 | u32 mask; |
| 3251 | |
| 3252 | if (bridge == NULL) |
| 3253 | return; |
| 3254 | |
| 3255 | cap = pci_find_ext_capability(bridge, PCI_EXT_CAP_ID_ERR); |
| 3256 | if (cap) { |
| 3257 | /* a sram parity error can cause a surprise link |
| 3258 | * down; since we expect and can recover from sram |
| 3259 | * parity errors, mask surprise link down events */ |
| 3260 | pci_read_config_dword(bridge, cap + PCI_ERR_UNCOR_MASK, &mask); |
| 3261 | mask |= 0x20; |
| 3262 | pci_write_config_dword(bridge, cap + PCI_ERR_UNCOR_MASK, mask); |
| 3263 | } |
| 3264 | } |
| 3265 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3266 | #ifdef CONFIG_PM |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3267 | static int myri10ge_suspend(struct pci_dev *pdev, pm_message_t state) |
| 3268 | { |
| 3269 | struct myri10ge_priv *mgp; |
| 3270 | struct net_device *netdev; |
| 3271 | |
| 3272 | mgp = pci_get_drvdata(pdev); |
| 3273 | if (mgp == NULL) |
| 3274 | return -EINVAL; |
| 3275 | netdev = mgp->dev; |
| 3276 | |
| 3277 | netif_device_detach(netdev); |
| 3278 | if (netif_running(netdev)) { |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 3279 | netdev_info(netdev, "closing\n"); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3280 | rtnl_lock(); |
| 3281 | myri10ge_close(netdev); |
| 3282 | rtnl_unlock(); |
| 3283 | } |
| 3284 | myri10ge_dummy_rdma(mgp, 0); |
Brice Goglin | 83f6e15 | 2006-12-18 11:52:02 +0100 | [diff] [blame] | 3285 | pci_save_state(pdev); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3286 | pci_disable_device(pdev); |
Brice Goglin | 1a63e84 | 2006-12-18 11:52:34 +0100 | [diff] [blame] | 3287 | |
| 3288 | return pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3289 | } |
| 3290 | |
| 3291 | static int myri10ge_resume(struct pci_dev *pdev) |
| 3292 | { |
| 3293 | struct myri10ge_priv *mgp; |
| 3294 | struct net_device *netdev; |
| 3295 | int status; |
| 3296 | u16 vendor; |
| 3297 | |
| 3298 | mgp = pci_get_drvdata(pdev); |
| 3299 | if (mgp == NULL) |
| 3300 | return -EINVAL; |
| 3301 | netdev = mgp->dev; |
| 3302 | pci_set_power_state(pdev, 0); /* zeros conf space as a side effect */ |
| 3303 | msleep(5); /* give card time to respond */ |
| 3304 | pci_read_config_word(mgp->pdev, PCI_VENDOR_ID, &vendor); |
| 3305 | if (vendor == 0xffff) { |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 3306 | netdev_err(mgp->dev, "device disappeared!\n"); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3307 | return -EIO; |
| 3308 | } |
Brice Goglin | 83f6e15 | 2006-12-18 11:52:02 +0100 | [diff] [blame] | 3309 | |
Jon Mason | 1d3c16a | 2010-11-30 17:43:26 -0600 | [diff] [blame] | 3310 | pci_restore_state(pdev); |
Brice Goglin | 4c2248c | 2006-07-09 21:10:18 -0400 | [diff] [blame] | 3311 | |
| 3312 | status = pci_enable_device(pdev); |
Brice Goglin | 1a63e84 | 2006-12-18 11:52:34 +0100 | [diff] [blame] | 3313 | if (status) { |
Brice Goglin | 4c2248c | 2006-07-09 21:10:18 -0400 | [diff] [blame] | 3314 | dev_err(&pdev->dev, "failed to enable device\n"); |
Brice Goglin | 1a63e84 | 2006-12-18 11:52:34 +0100 | [diff] [blame] | 3315 | return status; |
Brice Goglin | 4c2248c | 2006-07-09 21:10:18 -0400 | [diff] [blame] | 3316 | } |
| 3317 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3318 | pci_set_master(pdev); |
| 3319 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3320 | myri10ge_reset(mgp); |
Brice Goglin | 013b68b | 2006-08-09 00:07:53 -0400 | [diff] [blame] | 3321 | myri10ge_dummy_rdma(mgp, 1); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3322 | |
| 3323 | /* Save configuration space to be restored if the |
| 3324 | * nic resets due to a parity error */ |
Brice Goglin | 83f6e15 | 2006-12-18 11:52:02 +0100 | [diff] [blame] | 3325 | pci_save_state(pdev); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3326 | |
| 3327 | if (netif_running(netdev)) { |
| 3328 | rtnl_lock(); |
Brice Goglin | df30a74 | 2006-12-18 11:50:40 +0100 | [diff] [blame] | 3329 | status = myri10ge_open(netdev); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3330 | rtnl_unlock(); |
Brice Goglin | df30a74 | 2006-12-18 11:50:40 +0100 | [diff] [blame] | 3331 | if (status != 0) |
| 3332 | goto abort_with_enabled; |
| 3333 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3334 | } |
| 3335 | netif_device_attach(netdev); |
| 3336 | |
| 3337 | return 0; |
| 3338 | |
Brice Goglin | 4c2248c | 2006-07-09 21:10:18 -0400 | [diff] [blame] | 3339 | abort_with_enabled: |
| 3340 | pci_disable_device(pdev); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3341 | return -EIO; |
| 3342 | |
| 3343 | } |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3344 | #endif /* CONFIG_PM */ |
| 3345 | |
| 3346 | static u32 myri10ge_read_reboot(struct myri10ge_priv *mgp) |
| 3347 | { |
| 3348 | struct pci_dev *pdev = mgp->pdev; |
| 3349 | int vs = mgp->vendor_specific_offset; |
| 3350 | u32 reboot; |
| 3351 | |
| 3352 | /*enter read32 mode */ |
| 3353 | pci_write_config_byte(pdev, vs + 0x10, 0x3); |
| 3354 | |
| 3355 | /*read REBOOT_STATUS (0xfffffff0) */ |
| 3356 | pci_write_config_dword(pdev, vs + 0x18, 0xfffffff0); |
| 3357 | pci_read_config_dword(pdev, vs + 0x14, &reboot); |
| 3358 | return reboot; |
| 3359 | } |
| 3360 | |
Jon Mason | c689b81 | 2011-06-27 17:57:28 +0000 | [diff] [blame] | 3361 | static void |
| 3362 | myri10ge_check_slice(struct myri10ge_slice_state *ss, int *reset_needed, |
| 3363 | int *busy_slice_cnt, u32 rx_pause_cnt) |
| 3364 | { |
| 3365 | struct myri10ge_priv *mgp = ss->mgp; |
| 3366 | int slice = ss - mgp->ss; |
| 3367 | |
| 3368 | if (ss->tx.req != ss->tx.done && |
| 3369 | ss->tx.done == ss->watchdog_tx_done && |
| 3370 | ss->watchdog_tx_req != ss->watchdog_tx_done) { |
| 3371 | /* nic seems like it might be stuck.. */ |
| 3372 | if (rx_pause_cnt != mgp->watchdog_pause) { |
| 3373 | if (net_ratelimit()) |
| 3374 | netdev_warn(mgp->dev, "slice %d: TX paused, " |
| 3375 | "check link partner\n", slice); |
| 3376 | } else { |
| 3377 | netdev_warn(mgp->dev, |
| 3378 | "slice %d: TX stuck %d %d %d %d %d %d\n", |
| 3379 | slice, ss->tx.queue_active, ss->tx.req, |
| 3380 | ss->tx.done, ss->tx.pkt_start, |
| 3381 | ss->tx.pkt_done, |
| 3382 | (int)ntohl(mgp->ss[slice].fw_stats-> |
| 3383 | send_done_count)); |
| 3384 | *reset_needed = 1; |
| 3385 | ss->stuck = 1; |
| 3386 | } |
| 3387 | } |
| 3388 | if (ss->watchdog_tx_done != ss->tx.done || |
| 3389 | ss->watchdog_rx_done != ss->rx_done.cnt) { |
| 3390 | *busy_slice_cnt += 1; |
| 3391 | } |
| 3392 | ss->watchdog_tx_done = ss->tx.done; |
| 3393 | ss->watchdog_tx_req = ss->tx.req; |
| 3394 | ss->watchdog_rx_done = ss->rx_done.cnt; |
| 3395 | } |
| 3396 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3397 | /* |
| 3398 | * This watchdog is used to check whether the board has suffered |
| 3399 | * from a parity error and needs to be recovered. |
| 3400 | */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3401 | static void myri10ge_watchdog(struct work_struct *work) |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3402 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3403 | struct myri10ge_priv *mgp = |
Brice Goglin | 6250223 | 2006-12-11 11:24:37 +0100 | [diff] [blame] | 3404 | container_of(work, struct myri10ge_priv, watchdog_work); |
Jon Mason | c689b81 | 2011-06-27 17:57:28 +0000 | [diff] [blame] | 3405 | struct myri10ge_slice_state *ss; |
| 3406 | u32 reboot, rx_pause_cnt; |
Brice Goglin | d023421 | 2009-08-07 10:44:22 +0000 | [diff] [blame] | 3407 | int status, rebooted; |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 3408 | int i; |
Jon Mason | c689b81 | 2011-06-27 17:57:28 +0000 | [diff] [blame] | 3409 | int reset_needed = 0; |
| 3410 | int busy_slice_cnt = 0; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3411 | u16 cmd, vendor; |
| 3412 | |
| 3413 | mgp->watchdog_resets++; |
| 3414 | pci_read_config_word(mgp->pdev, PCI_COMMAND, &cmd); |
Brice Goglin | d023421 | 2009-08-07 10:44:22 +0000 | [diff] [blame] | 3415 | rebooted = 0; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3416 | if ((cmd & PCI_COMMAND_MASTER) == 0) { |
| 3417 | /* Bus master DMA disabled? Check to see |
| 3418 | * if the card rebooted due to a parity error |
| 3419 | * For now, just report it */ |
| 3420 | reboot = myri10ge_read_reboot(mgp); |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 3421 | netdev_err(mgp->dev, "NIC rebooted (0x%x),%s resetting\n", |
Jon Mason | c689b81 | 2011-06-27 17:57:28 +0000 | [diff] [blame] | 3422 | reboot, myri10ge_reset_recover ? "" : " not"); |
Brice Goglin | f181137 | 2007-06-11 20:26:31 +0200 | [diff] [blame] | 3423 | if (myri10ge_reset_recover == 0) |
| 3424 | return; |
Brice Goglin | d023421 | 2009-08-07 10:44:22 +0000 | [diff] [blame] | 3425 | rtnl_lock(); |
| 3426 | mgp->rebooted = 1; |
| 3427 | rebooted = 1; |
| 3428 | myri10ge_close(mgp->dev); |
Brice Goglin | f181137 | 2007-06-11 20:26:31 +0200 | [diff] [blame] | 3429 | myri10ge_reset_recover--; |
Brice Goglin | d023421 | 2009-08-07 10:44:22 +0000 | [diff] [blame] | 3430 | mgp->rebooted = 0; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3431 | /* |
| 3432 | * A rebooted nic will come back with config space as |
| 3433 | * it was after power was applied to PCIe bus. |
| 3434 | * Attempt to restore config space which was saved |
| 3435 | * when the driver was loaded, or the last time the |
| 3436 | * nic was resumed from power saving mode. |
| 3437 | */ |
Brice Goglin | 83f6e15 | 2006-12-18 11:52:02 +0100 | [diff] [blame] | 3438 | pci_restore_state(mgp->pdev); |
Brice Goglin | 7adda30 | 2006-12-18 11:50:00 +0100 | [diff] [blame] | 3439 | |
| 3440 | /* save state again for accounting reasons */ |
Brice Goglin | 83f6e15 | 2006-12-18 11:52:02 +0100 | [diff] [blame] | 3441 | pci_save_state(mgp->pdev); |
Brice Goglin | 7adda30 | 2006-12-18 11:50:00 +0100 | [diff] [blame] | 3442 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3443 | } else { |
| 3444 | /* if we get back -1's from our slot, perhaps somebody |
| 3445 | * powered off our card. Don't try to reset it in |
| 3446 | * this case */ |
| 3447 | if (cmd == 0xffff) { |
| 3448 | pci_read_config_word(mgp->pdev, PCI_VENDOR_ID, &vendor); |
| 3449 | if (vendor == 0xffff) { |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 3450 | netdev_err(mgp->dev, "device disappeared!\n"); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3451 | return; |
| 3452 | } |
| 3453 | } |
Jon Mason | c689b81 | 2011-06-27 17:57:28 +0000 | [diff] [blame] | 3454 | /* Perhaps it is a software error. See if stuck slice |
| 3455 | * has recovered, reset if not */ |
| 3456 | rx_pause_cnt = ntohl(mgp->ss[0].fw_stats->dropped_pause); |
| 3457 | for (i = 0; i < mgp->num_slices; i++) { |
| 3458 | ss = mgp->ss; |
| 3459 | if (ss->stuck) { |
| 3460 | myri10ge_check_slice(ss, &reset_needed, |
| 3461 | &busy_slice_cnt, |
| 3462 | rx_pause_cnt); |
| 3463 | ss->stuck = 0; |
| 3464 | } |
| 3465 | } |
| 3466 | if (!reset_needed) { |
| 3467 | netdev_dbg(mgp->dev, "not resetting\n"); |
| 3468 | return; |
| 3469 | } |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3470 | |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 3471 | netdev_err(mgp->dev, "device timeout, resetting\n"); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3472 | } |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 3473 | |
Brice Goglin | d023421 | 2009-08-07 10:44:22 +0000 | [diff] [blame] | 3474 | if (!rebooted) { |
| 3475 | rtnl_lock(); |
| 3476 | myri10ge_close(mgp->dev); |
| 3477 | } |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 3478 | status = myri10ge_load_firmware(mgp, 1); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3479 | if (status != 0) |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 3480 | netdev_err(mgp->dev, "failed to load firmware\n"); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3481 | else |
| 3482 | myri10ge_open(mgp->dev); |
| 3483 | rtnl_unlock(); |
| 3484 | } |
| 3485 | |
| 3486 | /* |
| 3487 | * We use our own timer routine rather than relying upon |
| 3488 | * netdev->tx_timeout because we have a very large hardware transmit |
| 3489 | * queue. Due to the large queue, the netdev->tx_timeout function |
| 3490 | * cannot detect a NIC with a parity error in a timely fashion if the |
| 3491 | * NIC is lightly loaded. |
| 3492 | */ |
| 3493 | static void myri10ge_watchdog_timer(unsigned long arg) |
| 3494 | { |
| 3495 | struct myri10ge_priv *mgp; |
Brice Goglin | b53bef8 | 2008-05-09 02:20:03 +0200 | [diff] [blame] | 3496 | struct myri10ge_slice_state *ss; |
Brice Goglin | d023421 | 2009-08-07 10:44:22 +0000 | [diff] [blame] | 3497 | int i, reset_needed, busy_slice_cnt; |
Brice Goglin | 626fda9 | 2007-08-09 09:02:14 +0200 | [diff] [blame] | 3498 | u32 rx_pause_cnt; |
Brice Goglin | d023421 | 2009-08-07 10:44:22 +0000 | [diff] [blame] | 3499 | u16 cmd; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3500 | |
| 3501 | mgp = (struct myri10ge_priv *)arg; |
Brice Goglin | c7dab99 | 2006-12-11 11:25:42 +0100 | [diff] [blame] | 3502 | |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 3503 | rx_pause_cnt = ntohl(mgp->ss[0].fw_stats->dropped_pause); |
Brice Goglin | d023421 | 2009-08-07 10:44:22 +0000 | [diff] [blame] | 3504 | busy_slice_cnt = 0; |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 3505 | for (i = 0, reset_needed = 0; |
| 3506 | i < mgp->num_slices && reset_needed == 0; ++i) { |
Brice Goglin | c7dab99 | 2006-12-11 11:25:42 +0100 | [diff] [blame] | 3507 | |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 3508 | ss = &mgp->ss[i]; |
| 3509 | if (ss->rx_small.watchdog_needed) { |
| 3510 | myri10ge_alloc_rx_pages(mgp, &ss->rx_small, |
| 3511 | mgp->small_bytes + MXGEFW_PAD, |
| 3512 | 1); |
| 3513 | if (ss->rx_small.fill_cnt - ss->rx_small.cnt >= |
| 3514 | myri10ge_fill_thresh) |
| 3515 | ss->rx_small.watchdog_needed = 0; |
Brice Goglin | 626fda9 | 2007-08-09 09:02:14 +0200 | [diff] [blame] | 3516 | } |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 3517 | if (ss->rx_big.watchdog_needed) { |
| 3518 | myri10ge_alloc_rx_pages(mgp, &ss->rx_big, |
| 3519 | mgp->big_bytes, 1); |
| 3520 | if (ss->rx_big.fill_cnt - ss->rx_big.cnt >= |
| 3521 | myri10ge_fill_thresh) |
| 3522 | ss->rx_big.watchdog_needed = 0; |
| 3523 | } |
Jon Mason | c689b81 | 2011-06-27 17:57:28 +0000 | [diff] [blame] | 3524 | myri10ge_check_slice(ss, &reset_needed, &busy_slice_cnt, |
| 3525 | rx_pause_cnt); |
Brice Goglin | d023421 | 2009-08-07 10:44:22 +0000 | [diff] [blame] | 3526 | } |
| 3527 | /* if we've sent or received no traffic, poll the NIC to |
| 3528 | * ensure it is still there. Otherwise, we risk not noticing |
| 3529 | * an error in a timely fashion */ |
| 3530 | if (busy_slice_cnt == 0) { |
| 3531 | pci_read_config_word(mgp->pdev, PCI_COMMAND, &cmd); |
| 3532 | if ((cmd & PCI_COMMAND_MASTER) == 0) { |
| 3533 | reset_needed = 1; |
| 3534 | } |
Brice Goglin | 626fda9 | 2007-08-09 09:02:14 +0200 | [diff] [blame] | 3535 | } |
Brice Goglin | 626fda9 | 2007-08-09 09:02:14 +0200 | [diff] [blame] | 3536 | mgp->watchdog_pause = rx_pause_cnt; |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 3537 | |
| 3538 | if (reset_needed) { |
| 3539 | schedule_work(&mgp->watchdog_work); |
| 3540 | } else { |
| 3541 | /* rearm timer */ |
| 3542 | mod_timer(&mgp->watchdog_timer, |
| 3543 | jiffies + myri10ge_watchdog_timeout * HZ); |
| 3544 | } |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3545 | } |
| 3546 | |
Brice Goglin | 7792973 | 2008-05-09 02:21:10 +0200 | [diff] [blame] | 3547 | static void myri10ge_free_slices(struct myri10ge_priv *mgp) |
| 3548 | { |
| 3549 | struct myri10ge_slice_state *ss; |
| 3550 | struct pci_dev *pdev = mgp->pdev; |
| 3551 | size_t bytes; |
| 3552 | int i; |
| 3553 | |
| 3554 | if (mgp->ss == NULL) |
| 3555 | return; |
| 3556 | |
| 3557 | for (i = 0; i < mgp->num_slices; i++) { |
| 3558 | ss = &mgp->ss[i]; |
| 3559 | if (ss->rx_done.entry != NULL) { |
| 3560 | bytes = mgp->max_intr_slots * |
| 3561 | sizeof(*ss->rx_done.entry); |
| 3562 | dma_free_coherent(&pdev->dev, bytes, |
| 3563 | ss->rx_done.entry, ss->rx_done.bus); |
| 3564 | ss->rx_done.entry = NULL; |
| 3565 | } |
| 3566 | if (ss->fw_stats != NULL) { |
| 3567 | bytes = sizeof(*ss->fw_stats); |
| 3568 | dma_free_coherent(&pdev->dev, bytes, |
| 3569 | ss->fw_stats, ss->fw_stats_bus); |
| 3570 | ss->fw_stats = NULL; |
| 3571 | } |
Jon Mason | b3b6ae2 | 2011-06-27 10:56:41 +0000 | [diff] [blame] | 3572 | netif_napi_del(&ss->napi); |
Brice Goglin | 7792973 | 2008-05-09 02:21:10 +0200 | [diff] [blame] | 3573 | } |
| 3574 | kfree(mgp->ss); |
| 3575 | mgp->ss = NULL; |
| 3576 | } |
| 3577 | |
| 3578 | static int myri10ge_alloc_slices(struct myri10ge_priv *mgp) |
| 3579 | { |
| 3580 | struct myri10ge_slice_state *ss; |
| 3581 | struct pci_dev *pdev = mgp->pdev; |
| 3582 | size_t bytes; |
| 3583 | int i; |
| 3584 | |
| 3585 | bytes = sizeof(*mgp->ss) * mgp->num_slices; |
| 3586 | mgp->ss = kzalloc(bytes, GFP_KERNEL); |
| 3587 | if (mgp->ss == NULL) { |
| 3588 | return -ENOMEM; |
| 3589 | } |
| 3590 | |
| 3591 | for (i = 0; i < mgp->num_slices; i++) { |
| 3592 | ss = &mgp->ss[i]; |
| 3593 | bytes = mgp->max_intr_slots * sizeof(*ss->rx_done.entry); |
| 3594 | ss->rx_done.entry = dma_alloc_coherent(&pdev->dev, bytes, |
| 3595 | &ss->rx_done.bus, |
| 3596 | GFP_KERNEL); |
| 3597 | if (ss->rx_done.entry == NULL) |
| 3598 | goto abort; |
| 3599 | memset(ss->rx_done.entry, 0, bytes); |
| 3600 | bytes = sizeof(*ss->fw_stats); |
| 3601 | ss->fw_stats = dma_alloc_coherent(&pdev->dev, bytes, |
| 3602 | &ss->fw_stats_bus, |
| 3603 | GFP_KERNEL); |
| 3604 | if (ss->fw_stats == NULL) |
| 3605 | goto abort; |
| 3606 | ss->mgp = mgp; |
| 3607 | ss->dev = mgp->dev; |
| 3608 | netif_napi_add(ss->dev, &ss->napi, myri10ge_poll, |
| 3609 | myri10ge_napi_weight); |
| 3610 | } |
| 3611 | return 0; |
| 3612 | abort: |
| 3613 | myri10ge_free_slices(mgp); |
| 3614 | return -ENOMEM; |
| 3615 | } |
| 3616 | |
| 3617 | /* |
| 3618 | * This function determines the number of slices supported. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3619 | * The number slices is the minimum of the number of CPUS, |
Brice Goglin | 7792973 | 2008-05-09 02:21:10 +0200 | [diff] [blame] | 3620 | * the number of MSI-X irqs supported, the number of slices |
| 3621 | * supported by the firmware |
| 3622 | */ |
| 3623 | static void myri10ge_probe_slices(struct myri10ge_priv *mgp) |
| 3624 | { |
| 3625 | struct myri10ge_cmd cmd; |
| 3626 | struct pci_dev *pdev = mgp->pdev; |
| 3627 | char *old_fw; |
Rusty Russell | 7d35103 | 2010-08-11 23:04:31 -0600 | [diff] [blame] | 3628 | bool old_allocated; |
Brice Goglin | 7792973 | 2008-05-09 02:21:10 +0200 | [diff] [blame] | 3629 | int i, status, ncpus, msix_cap; |
| 3630 | |
| 3631 | mgp->num_slices = 1; |
| 3632 | msix_cap = pci_find_capability(pdev, PCI_CAP_ID_MSIX); |
Yuval Mintz | 98f2d21 | 2012-07-01 03:18:56 +0000 | [diff] [blame] | 3633 | ncpus = netif_get_num_default_rss_queues(); |
Brice Goglin | 7792973 | 2008-05-09 02:21:10 +0200 | [diff] [blame] | 3634 | |
| 3635 | if (myri10ge_max_slices == 1 || msix_cap == 0 || |
| 3636 | (myri10ge_max_slices == -1 && ncpus < 2)) |
| 3637 | return; |
| 3638 | |
| 3639 | /* try to load the slice aware rss firmware */ |
| 3640 | old_fw = mgp->fw_name; |
Rusty Russell | 7d35103 | 2010-08-11 23:04:31 -0600 | [diff] [blame] | 3641 | old_allocated = mgp->fw_name_allocated; |
| 3642 | /* don't free old_fw if we override it. */ |
| 3643 | mgp->fw_name_allocated = false; |
| 3644 | |
Brice Goglin | 13b2738 | 2008-08-13 21:05:52 +0200 | [diff] [blame] | 3645 | if (myri10ge_fw_name != NULL) { |
| 3646 | dev_info(&mgp->pdev->dev, "overriding rss firmware to %s\n", |
| 3647 | myri10ge_fw_name); |
Rusty Russell | 7d35103 | 2010-08-11 23:04:31 -0600 | [diff] [blame] | 3648 | set_fw_name(mgp, myri10ge_fw_name, false); |
Brice Goglin | 13b2738 | 2008-08-13 21:05:52 +0200 | [diff] [blame] | 3649 | } else if (old_fw == myri10ge_fw_aligned) |
Rusty Russell | 7d35103 | 2010-08-11 23:04:31 -0600 | [diff] [blame] | 3650 | set_fw_name(mgp, myri10ge_fw_rss_aligned, false); |
Brice Goglin | 7792973 | 2008-05-09 02:21:10 +0200 | [diff] [blame] | 3651 | else |
Rusty Russell | 7d35103 | 2010-08-11 23:04:31 -0600 | [diff] [blame] | 3652 | set_fw_name(mgp, myri10ge_fw_rss_unaligned, false); |
Brice Goglin | 7792973 | 2008-05-09 02:21:10 +0200 | [diff] [blame] | 3653 | status = myri10ge_load_firmware(mgp, 0); |
| 3654 | if (status != 0) { |
| 3655 | dev_info(&pdev->dev, "Rss firmware not found\n"); |
Rusty Russell | 7d35103 | 2010-08-11 23:04:31 -0600 | [diff] [blame] | 3656 | if (old_allocated) |
| 3657 | kfree(old_fw); |
Brice Goglin | 7792973 | 2008-05-09 02:21:10 +0200 | [diff] [blame] | 3658 | return; |
| 3659 | } |
| 3660 | |
| 3661 | /* hit the board with a reset to ensure it is alive */ |
| 3662 | memset(&cmd, 0, sizeof(cmd)); |
| 3663 | status = myri10ge_send_cmd(mgp, MXGEFW_CMD_RESET, &cmd, 0); |
| 3664 | if (status != 0) { |
| 3665 | dev_err(&mgp->pdev->dev, "failed reset\n"); |
| 3666 | goto abort_with_fw; |
Brice Goglin | 7792973 | 2008-05-09 02:21:10 +0200 | [diff] [blame] | 3667 | } |
| 3668 | |
| 3669 | mgp->max_intr_slots = cmd.data0 / sizeof(struct mcp_slot); |
| 3670 | |
| 3671 | /* tell it the size of the interrupt queues */ |
| 3672 | cmd.data0 = mgp->max_intr_slots * sizeof(struct mcp_slot); |
| 3673 | status = myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_INTRQ_SIZE, &cmd, 0); |
| 3674 | if (status != 0) { |
| 3675 | dev_err(&mgp->pdev->dev, "failed MXGEFW_CMD_SET_INTRQ_SIZE\n"); |
| 3676 | goto abort_with_fw; |
| 3677 | } |
| 3678 | |
| 3679 | /* ask the maximum number of slices it supports */ |
| 3680 | status = myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_MAX_RSS_QUEUES, &cmd, 0); |
| 3681 | if (status != 0) |
| 3682 | goto abort_with_fw; |
| 3683 | else |
| 3684 | mgp->num_slices = cmd.data0; |
| 3685 | |
| 3686 | /* Only allow multiple slices if MSI-X is usable */ |
| 3687 | if (!myri10ge_msi) { |
| 3688 | goto abort_with_fw; |
| 3689 | } |
| 3690 | |
| 3691 | /* if the admin did not specify a limit to how many |
| 3692 | * slices we should use, cap it automatically to the |
| 3693 | * number of CPUs currently online */ |
| 3694 | if (myri10ge_max_slices == -1) |
| 3695 | myri10ge_max_slices = ncpus; |
| 3696 | |
| 3697 | if (mgp->num_slices > myri10ge_max_slices) |
| 3698 | mgp->num_slices = myri10ge_max_slices; |
| 3699 | |
| 3700 | /* Now try to allocate as many MSI-X vectors as we have |
| 3701 | * slices. We give up on MSI-X if we can only get a single |
| 3702 | * vector. */ |
| 3703 | |
Joe Perches | baeb2ff | 2010-08-11 07:02:48 +0000 | [diff] [blame] | 3704 | mgp->msix_vectors = kcalloc(mgp->num_slices, sizeof(*mgp->msix_vectors), |
| 3705 | GFP_KERNEL); |
Brice Goglin | 7792973 | 2008-05-09 02:21:10 +0200 | [diff] [blame] | 3706 | if (mgp->msix_vectors == NULL) |
| 3707 | goto disable_msix; |
| 3708 | for (i = 0; i < mgp->num_slices; i++) { |
| 3709 | mgp->msix_vectors[i].entry = i; |
| 3710 | } |
| 3711 | |
| 3712 | while (mgp->num_slices > 1) { |
| 3713 | /* make sure it is a power of two */ |
| 3714 | while (!is_power_of_2(mgp->num_slices)) |
| 3715 | mgp->num_slices--; |
| 3716 | if (mgp->num_slices == 1) |
| 3717 | goto disable_msix; |
| 3718 | status = pci_enable_msix(pdev, mgp->msix_vectors, |
| 3719 | mgp->num_slices); |
| 3720 | if (status == 0) { |
| 3721 | pci_disable_msix(pdev); |
Rusty Russell | 7d35103 | 2010-08-11 23:04:31 -0600 | [diff] [blame] | 3722 | if (old_allocated) |
| 3723 | kfree(old_fw); |
Brice Goglin | 7792973 | 2008-05-09 02:21:10 +0200 | [diff] [blame] | 3724 | return; |
| 3725 | } |
| 3726 | if (status > 0) |
| 3727 | mgp->num_slices = status; |
| 3728 | else |
| 3729 | goto disable_msix; |
| 3730 | } |
| 3731 | |
| 3732 | disable_msix: |
| 3733 | if (mgp->msix_vectors != NULL) { |
| 3734 | kfree(mgp->msix_vectors); |
| 3735 | mgp->msix_vectors = NULL; |
| 3736 | } |
| 3737 | |
| 3738 | abort_with_fw: |
| 3739 | mgp->num_slices = 1; |
Rusty Russell | 7d35103 | 2010-08-11 23:04:31 -0600 | [diff] [blame] | 3740 | set_fw_name(mgp, old_fw, old_allocated); |
Brice Goglin | 7792973 | 2008-05-09 02:21:10 +0200 | [diff] [blame] | 3741 | myri10ge_load_firmware(mgp, 0); |
| 3742 | } |
Brice Goglin | 7792973 | 2008-05-09 02:21:10 +0200 | [diff] [blame] | 3743 | |
Stephen Hemminger | 8126089 | 2008-11-21 17:30:35 -0800 | [diff] [blame] | 3744 | static const struct net_device_ops myri10ge_netdev_ops = { |
| 3745 | .ndo_open = myri10ge_open, |
| 3746 | .ndo_stop = myri10ge_close, |
| 3747 | .ndo_start_xmit = myri10ge_xmit, |
stephen hemminger | c5f7ef7 | 2011-06-08 14:54:03 +0000 | [diff] [blame] | 3748 | .ndo_get_stats64 = myri10ge_get_stats, |
Stephen Hemminger | 8126089 | 2008-11-21 17:30:35 -0800 | [diff] [blame] | 3749 | .ndo_validate_addr = eth_validate_addr, |
| 3750 | .ndo_change_mtu = myri10ge_change_mtu, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 3751 | .ndo_set_rx_mode = myri10ge_set_multicast_list, |
Stephen Hemminger | 8126089 | 2008-11-21 17:30:35 -0800 | [diff] [blame] | 3752 | .ndo_set_mac_address = myri10ge_set_mac_address, |
| 3753 | }; |
| 3754 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3755 | static int myri10ge_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 3756 | { |
| 3757 | struct net_device *netdev; |
| 3758 | struct myri10ge_priv *mgp; |
| 3759 | struct device *dev = &pdev->dev; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3760 | int i; |
| 3761 | int status = -ENXIO; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3762 | int dac_enabled; |
Brice Goglin | 00b5e50 | 2008-11-20 01:50:28 -0800 | [diff] [blame] | 3763 | unsigned hdr_offset, ss_offset; |
Brice Goglin | 2d90b0a | 2009-04-16 02:24:59 +0000 | [diff] [blame] | 3764 | static int board_number; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3765 | |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 3766 | netdev = alloc_etherdev_mq(sizeof(*mgp), MYRI10GE_MAX_SLICES); |
Joe Perches | 41de8d4 | 2012-01-29 13:47:52 +0000 | [diff] [blame] | 3767 | if (netdev == NULL) |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3768 | return -ENOMEM; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3769 | |
Maik Hampel | b245fb6 | 2007-06-28 17:07:26 +0200 | [diff] [blame] | 3770 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 3771 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3772 | mgp = netdev_priv(netdev); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3773 | mgp->dev = netdev; |
| 3774 | mgp->pdev = pdev; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3775 | mgp->pause = myri10ge_flow_control; |
| 3776 | mgp->intr_coal_delay = myri10ge_intr_coal_delay; |
Brice Goglin | c58ac5c | 2006-08-21 17:36:49 -0400 | [diff] [blame] | 3777 | mgp->msg_enable = netif_msg_init(myri10ge_debug, MYRI10GE_MSG_DEFAULT); |
Brice Goglin | 2d90b0a | 2009-04-16 02:24:59 +0000 | [diff] [blame] | 3778 | mgp->board_number = board_number; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3779 | init_waitqueue_head(&mgp->down_wq); |
| 3780 | |
| 3781 | if (pci_enable_device(pdev)) { |
| 3782 | dev_err(&pdev->dev, "pci_enable_device call failed\n"); |
| 3783 | status = -ENODEV; |
| 3784 | goto abort_with_netdev; |
| 3785 | } |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3786 | |
| 3787 | /* Find the vendor-specific cap so we can check |
| 3788 | * the reboot register later on */ |
| 3789 | mgp->vendor_specific_offset |
| 3790 | = pci_find_capability(pdev, PCI_CAP_ID_VNDR); |
| 3791 | |
| 3792 | /* Set our max read request to 4KB */ |
Brice Goglin | 302d242 | 2007-08-24 08:57:17 +0200 | [diff] [blame] | 3793 | status = pcie_set_readrq(pdev, 4096); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3794 | if (status != 0) { |
| 3795 | dev_err(&pdev->dev, "Error %d writing PCI_EXP_DEVCTL\n", |
| 3796 | status); |
Brice Goglin | e3fd553 | 2009-01-17 08:27:19 +0000 | [diff] [blame] | 3797 | goto abort_with_enabled; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3798 | } |
| 3799 | |
Jon Mason | 7539a61 | 2011-06-27 05:05:01 +0000 | [diff] [blame] | 3800 | myri10ge_mask_surprise_down(pdev); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3801 | pci_set_master(pdev); |
| 3802 | dac_enabled = 1; |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 3803 | status = pci_set_dma_mask(pdev, DMA_BIT_MASK(64)); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3804 | if (status != 0) { |
| 3805 | dac_enabled = 0; |
| 3806 | dev_err(&pdev->dev, |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 3807 | "64-bit pci address mask was refused, " |
| 3808 | "trying 32-bit\n"); |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 3809 | status = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3810 | } |
| 3811 | if (status != 0) { |
| 3812 | dev_err(&pdev->dev, "Error %d setting DMA mask\n", status); |
Brice Goglin | e3fd553 | 2009-01-17 08:27:19 +0000 | [diff] [blame] | 3813 | goto abort_with_enabled; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3814 | } |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 3815 | (void)pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)); |
Brice Goglin | b10c066 | 2006-06-08 10:25:00 -0400 | [diff] [blame] | 3816 | mgp->cmd = dma_alloc_coherent(&pdev->dev, sizeof(*mgp->cmd), |
| 3817 | &mgp->cmd_bus, GFP_KERNEL); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3818 | if (mgp->cmd == NULL) |
Brice Goglin | e3fd553 | 2009-01-17 08:27:19 +0000 | [diff] [blame] | 3819 | goto abort_with_enabled; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3820 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3821 | mgp->board_span = pci_resource_len(pdev, 0); |
| 3822 | mgp->iomem_base = pci_resource_start(pdev, 0); |
| 3823 | mgp->mtrr = -1; |
Brice Goglin | 276e26c | 2007-03-07 20:02:32 +0100 | [diff] [blame] | 3824 | mgp->wc_enabled = 0; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3825 | #ifdef CONFIG_MTRR |
| 3826 | mgp->mtrr = mtrr_add(mgp->iomem_base, mgp->board_span, |
| 3827 | MTRR_TYPE_WRCOMB, 1); |
Brice Goglin | 276e26c | 2007-03-07 20:02:32 +0100 | [diff] [blame] | 3828 | if (mgp->mtrr >= 0) |
| 3829 | mgp->wc_enabled = 1; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3830 | #endif |
Brice Goglin | c7f8099 | 2008-07-21 10:26:25 +0200 | [diff] [blame] | 3831 | mgp->sram = ioremap_wc(mgp->iomem_base, mgp->board_span); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3832 | if (mgp->sram == NULL) { |
| 3833 | dev_err(&pdev->dev, "ioremap failed for %ld bytes at 0x%lx\n", |
| 3834 | mgp->board_span, mgp->iomem_base); |
| 3835 | status = -ENXIO; |
Brice Goglin | c7f8099 | 2008-07-21 10:26:25 +0200 | [diff] [blame] | 3836 | goto abort_with_mtrr; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3837 | } |
Brice Goglin | 00b5e50 | 2008-11-20 01:50:28 -0800 | [diff] [blame] | 3838 | hdr_offset = |
Andrew Gallatin | 59e955e | 2012-12-04 10:17:15 +0000 | [diff] [blame] | 3839 | swab32(readl(mgp->sram + MCP_HEADER_PTR_OFFSET)) & 0xffffc; |
Brice Goglin | 00b5e50 | 2008-11-20 01:50:28 -0800 | [diff] [blame] | 3840 | ss_offset = hdr_offset + offsetof(struct mcp_gen_header, string_specs); |
Andrew Gallatin | 59e955e | 2012-12-04 10:17:15 +0000 | [diff] [blame] | 3841 | mgp->sram_size = swab32(readl(mgp->sram + ss_offset)); |
Brice Goglin | 00b5e50 | 2008-11-20 01:50:28 -0800 | [diff] [blame] | 3842 | if (mgp->sram_size > mgp->board_span || |
| 3843 | mgp->sram_size <= MYRI10GE_FW_OFFSET) { |
| 3844 | dev_err(&pdev->dev, |
| 3845 | "invalid sram_size %dB or board span %ldB\n", |
| 3846 | mgp->sram_size, mgp->board_span); |
| 3847 | goto abort_with_ioremap; |
| 3848 | } |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3849 | memcpy_fromio(mgp->eeprom_strings, |
Brice Goglin | 00b5e50 | 2008-11-20 01:50:28 -0800 | [diff] [blame] | 3850 | mgp->sram + mgp->sram_size, MYRI10GE_EEPROM_STRINGS_SIZE); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3851 | memset(mgp->eeprom_strings + MYRI10GE_EEPROM_STRINGS_SIZE - 2, 0, 2); |
| 3852 | status = myri10ge_read_mac_addr(mgp); |
| 3853 | if (status) |
| 3854 | goto abort_with_ioremap; |
| 3855 | |
| 3856 | for (i = 0; i < ETH_ALEN; i++) |
| 3857 | netdev->dev_addr[i] = mgp->mac_addr[i]; |
| 3858 | |
Brice Goglin | 5443e9e | 2007-05-07 23:52:22 +0200 | [diff] [blame] | 3859 | myri10ge_select_firmware(mgp); |
| 3860 | |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 3861 | status = myri10ge_load_firmware(mgp, 1); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3862 | if (status != 0) { |
| 3863 | dev_err(&pdev->dev, "failed to load firmware\n"); |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 3864 | goto abort_with_ioremap; |
| 3865 | } |
| 3866 | myri10ge_probe_slices(mgp); |
| 3867 | status = myri10ge_alloc_slices(mgp); |
| 3868 | if (status != 0) { |
| 3869 | dev_err(&pdev->dev, "failed to alloc slice state\n"); |
| 3870 | goto abort_with_firmware; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3871 | } |
Ben Hutchings | c992026 | 2010-09-27 08:30:34 +0000 | [diff] [blame] | 3872 | netif_set_real_num_tx_queues(netdev, mgp->num_slices); |
| 3873 | netif_set_real_num_rx_queues(netdev, mgp->num_slices); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3874 | status = myri10ge_reset(mgp); |
| 3875 | if (status != 0) { |
| 3876 | dev_err(&pdev->dev, "failed reset\n"); |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 3877 | goto abort_with_slices; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3878 | } |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 3879 | #ifdef CONFIG_MYRI10GE_DCA |
Brice Goglin | 981813d | 2008-05-09 02:22:16 +0200 | [diff] [blame] | 3880 | myri10ge_setup_dca(mgp); |
| 3881 | #endif |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3882 | pci_set_drvdata(pdev, mgp); |
| 3883 | if ((myri10ge_initial_mtu + ETH_HLEN) > MYRI10GE_MAX_ETHER_MTU) |
| 3884 | myri10ge_initial_mtu = MYRI10GE_MAX_ETHER_MTU - ETH_HLEN; |
| 3885 | if ((myri10ge_initial_mtu + ETH_HLEN) < 68) |
| 3886 | myri10ge_initial_mtu = 68; |
Stephen Hemminger | 8126089 | 2008-11-21 17:30:35 -0800 | [diff] [blame] | 3887 | |
| 3888 | netdev->netdev_ops = &myri10ge_netdev_ops; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3889 | netdev->mtu = myri10ge_initial_mtu; |
Andrew Gallatin | 4ca3221 | 2012-11-30 08:31:58 +0000 | [diff] [blame] | 3890 | netdev->hw_features = mgp->features | NETIF_F_RXCSUM; |
Andrew Gallatin | 1b4c44e | 2012-11-30 08:31:59 +0000 | [diff] [blame] | 3891 | |
| 3892 | /* fake NETIF_F_HW_VLAN_RX for good GRO performance */ |
| 3893 | netdev->hw_features |= NETIF_F_HW_VLAN_RX; |
| 3894 | |
Michał Mirosław | 47c2cdf | 2011-04-15 04:50:50 +0000 | [diff] [blame] | 3895 | netdev->features = netdev->hw_features; |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 3896 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3897 | if (dac_enabled) |
| 3898 | netdev->features |= NETIF_F_HIGHDMA; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3899 | |
Brice Goglin | dddc045 | 2009-05-24 05:27:59 +0000 | [diff] [blame] | 3900 | netdev->vlan_features |= mgp->features; |
| 3901 | if (mgp->fw_ver_tiny < 37) |
| 3902 | netdev->vlan_features &= ~NETIF_F_TSO6; |
| 3903 | if (mgp->fw_ver_tiny < 32) |
| 3904 | netdev->vlan_features &= ~NETIF_F_TSO; |
| 3905 | |
Brice Goglin | 21d05db | 2007-01-09 21:05:04 +0100 | [diff] [blame] | 3906 | /* make sure we can get an irq, and that MSI can be |
Francois Romieu | a742545 | 2012-03-23 18:51:20 +0100 | [diff] [blame] | 3907 | * setup (if available). */ |
Brice Goglin | 21d05db | 2007-01-09 21:05:04 +0100 | [diff] [blame] | 3908 | status = myri10ge_request_irq(mgp); |
| 3909 | if (status != 0) |
| 3910 | goto abort_with_firmware; |
Brice Goglin | 21d05db | 2007-01-09 21:05:04 +0100 | [diff] [blame] | 3911 | myri10ge_free_irq(mgp); |
| 3912 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3913 | /* Save configuration space to be restored if the |
| 3914 | * nic resets due to a parity error */ |
Brice Goglin | 83f6e15 | 2006-12-18 11:52:02 +0100 | [diff] [blame] | 3915 | pci_save_state(pdev); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3916 | |
| 3917 | /* Setup the watchdog timer */ |
| 3918 | setup_timer(&mgp->watchdog_timer, myri10ge_watchdog_timer, |
| 3919 | (unsigned long)mgp); |
| 3920 | |
| 3921 | SET_ETHTOOL_OPS(netdev, &myri10ge_ethtool_ops); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3922 | INIT_WORK(&mgp->watchdog_work, myri10ge_watchdog); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3923 | status = register_netdev(netdev); |
| 3924 | if (status != 0) { |
| 3925 | dev_err(&pdev->dev, "register_netdev failed: %d\n", status); |
Brice Goglin | 7adda30 | 2006-12-18 11:50:00 +0100 | [diff] [blame] | 3926 | goto abort_with_state; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3927 | } |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 3928 | if (mgp->msix_enabled) |
| 3929 | dev_info(dev, "%d MSI-X IRQs, tx bndry %d, fw %s, WC %s\n", |
| 3930 | mgp->num_slices, mgp->tx_boundary, mgp->fw_name, |
| 3931 | (mgp->wc_enabled ? "Enabled" : "Disabled")); |
| 3932 | else |
| 3933 | dev_info(dev, "%s IRQ %d, tx bndry %d, fw %s, WC %s\n", |
| 3934 | mgp->msi_enabled ? "MSI" : "xPIC", |
Francois Romieu | a742545 | 2012-03-23 18:51:20 +0100 | [diff] [blame] | 3935 | pdev->irq, mgp->tx_boundary, mgp->fw_name, |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 3936 | (mgp->wc_enabled ? "Enabled" : "Disabled")); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3937 | |
Brice Goglin | 2d90b0a | 2009-04-16 02:24:59 +0000 | [diff] [blame] | 3938 | board_number++; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3939 | return 0; |
| 3940 | |
Brice Goglin | 7adda30 | 2006-12-18 11:50:00 +0100 | [diff] [blame] | 3941 | abort_with_state: |
Brice Goglin | 83f6e15 | 2006-12-18 11:52:02 +0100 | [diff] [blame] | 3942 | pci_restore_state(pdev); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3943 | |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 3944 | abort_with_slices: |
| 3945 | myri10ge_free_slices(mgp); |
| 3946 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3947 | abort_with_firmware: |
| 3948 | myri10ge_dummy_rdma(mgp, 0); |
| 3949 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3950 | abort_with_ioremap: |
Brice Goglin | 0f84001 | 2009-01-05 18:16:14 -0800 | [diff] [blame] | 3951 | if (mgp->mac_addr_string != NULL) |
| 3952 | dev_err(&pdev->dev, |
| 3953 | "myri10ge_probe() failed: MAC=%s, SN=%ld\n", |
| 3954 | mgp->mac_addr_string, mgp->serial_number); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3955 | iounmap(mgp->sram); |
| 3956 | |
Brice Goglin | c7f8099 | 2008-07-21 10:26:25 +0200 | [diff] [blame] | 3957 | abort_with_mtrr: |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3958 | #ifdef CONFIG_MTRR |
| 3959 | if (mgp->mtrr >= 0) |
| 3960 | mtrr_del(mgp->mtrr, mgp->iomem_base, mgp->board_span); |
| 3961 | #endif |
Brice Goglin | b10c066 | 2006-06-08 10:25:00 -0400 | [diff] [blame] | 3962 | dma_free_coherent(&pdev->dev, sizeof(*mgp->cmd), |
| 3963 | mgp->cmd, mgp->cmd_bus); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3964 | |
Brice Goglin | e3fd553 | 2009-01-17 08:27:19 +0000 | [diff] [blame] | 3965 | abort_with_enabled: |
| 3966 | pci_disable_device(pdev); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3967 | |
Brice Goglin | e3fd553 | 2009-01-17 08:27:19 +0000 | [diff] [blame] | 3968 | abort_with_netdev: |
Rusty Russell | 7d35103 | 2010-08-11 23:04:31 -0600 | [diff] [blame] | 3969 | set_fw_name(mgp, NULL, false); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3970 | free_netdev(netdev); |
| 3971 | return status; |
| 3972 | } |
| 3973 | |
| 3974 | /* |
| 3975 | * myri10ge_remove |
| 3976 | * |
| 3977 | * Does what is necessary to shutdown one Myrinet device. Called |
| 3978 | * once for each Myrinet card by the kernel when a module is |
| 3979 | * unloaded. |
| 3980 | */ |
| 3981 | static void myri10ge_remove(struct pci_dev *pdev) |
| 3982 | { |
| 3983 | struct myri10ge_priv *mgp; |
| 3984 | struct net_device *netdev; |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3985 | |
| 3986 | mgp = pci_get_drvdata(pdev); |
| 3987 | if (mgp == NULL) |
| 3988 | return; |
| 3989 | |
Tejun Heo | 23f333a | 2010-12-12 16:45:14 +0100 | [diff] [blame] | 3990 | cancel_work_sync(&mgp->watchdog_work); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3991 | netdev = mgp->dev; |
| 3992 | unregister_netdev(netdev); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3993 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 3994 | #ifdef CONFIG_MYRI10GE_DCA |
Brice Goglin | 981813d | 2008-05-09 02:22:16 +0200 | [diff] [blame] | 3995 | myri10ge_teardown_dca(mgp); |
| 3996 | #endif |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 3997 | myri10ge_dummy_rdma(mgp, 0); |
| 3998 | |
Brice Goglin | 7adda30 | 2006-12-18 11:50:00 +0100 | [diff] [blame] | 3999 | /* avoid a memory leak */ |
Brice Goglin | 83f6e15 | 2006-12-18 11:52:02 +0100 | [diff] [blame] | 4000 | pci_restore_state(pdev); |
Brice Goglin | 7adda30 | 2006-12-18 11:50:00 +0100 | [diff] [blame] | 4001 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 4002 | iounmap(mgp->sram); |
| 4003 | |
| 4004 | #ifdef CONFIG_MTRR |
| 4005 | if (mgp->mtrr >= 0) |
| 4006 | mtrr_del(mgp->mtrr, mgp->iomem_base, mgp->board_span); |
| 4007 | #endif |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 4008 | myri10ge_free_slices(mgp); |
| 4009 | if (mgp->msix_vectors != NULL) |
| 4010 | kfree(mgp->msix_vectors); |
Brice Goglin | b10c066 | 2006-06-08 10:25:00 -0400 | [diff] [blame] | 4011 | dma_free_coherent(&pdev->dev, sizeof(*mgp->cmd), |
| 4012 | mgp->cmd, mgp->cmd_bus); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 4013 | |
Rusty Russell | 7d35103 | 2010-08-11 23:04:31 -0600 | [diff] [blame] | 4014 | set_fw_name(mgp, NULL, false); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 4015 | free_netdev(netdev); |
Brice Goglin | e3fd553 | 2009-01-17 08:27:19 +0000 | [diff] [blame] | 4016 | pci_disable_device(pdev); |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 4017 | pci_set_drvdata(pdev, NULL); |
| 4018 | } |
| 4019 | |
Brice Goglin | b10c066 | 2006-06-08 10:25:00 -0400 | [diff] [blame] | 4020 | #define PCI_DEVICE_ID_MYRICOM_MYRI10GE_Z8E 0x0008 |
Brice Goglin | a07bc1f | 2007-09-14 00:40:14 +0200 | [diff] [blame] | 4021 | #define PCI_DEVICE_ID_MYRICOM_MYRI10GE_Z8E_9 0x0009 |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 4022 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 4023 | static DEFINE_PCI_DEVICE_TABLE(myri10ge_pci_tbl) = { |
Brice Goglin | b10c066 | 2006-06-08 10:25:00 -0400 | [diff] [blame] | 4024 | {PCI_DEVICE(PCI_VENDOR_ID_MYRICOM, PCI_DEVICE_ID_MYRICOM_MYRI10GE_Z8E)}, |
Brice Goglin | a07bc1f | 2007-09-14 00:40:14 +0200 | [diff] [blame] | 4025 | {PCI_DEVICE |
| 4026 | (PCI_VENDOR_ID_MYRICOM, PCI_DEVICE_ID_MYRICOM_MYRI10GE_Z8E_9)}, |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 4027 | {0}, |
| 4028 | }; |
| 4029 | |
Brice Goglin | 9713107 | 2009-04-16 02:29:22 +0000 | [diff] [blame] | 4030 | MODULE_DEVICE_TABLE(pci, myri10ge_pci_tbl); |
| 4031 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 4032 | static struct pci_driver myri10ge_driver = { |
| 4033 | .name = "myri10ge", |
| 4034 | .probe = myri10ge_probe, |
| 4035 | .remove = myri10ge_remove, |
| 4036 | .id_table = myri10ge_pci_tbl, |
| 4037 | #ifdef CONFIG_PM |
| 4038 | .suspend = myri10ge_suspend, |
| 4039 | .resume = myri10ge_resume, |
| 4040 | #endif |
| 4041 | }; |
| 4042 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4043 | #ifdef CONFIG_MYRI10GE_DCA |
Brice Goglin | 981813d | 2008-05-09 02:22:16 +0200 | [diff] [blame] | 4044 | static int |
| 4045 | myri10ge_notify_dca(struct notifier_block *nb, unsigned long event, void *p) |
| 4046 | { |
| 4047 | int err = driver_for_each_device(&myri10ge_driver.driver, |
| 4048 | NULL, &event, |
| 4049 | myri10ge_notify_dca_device); |
| 4050 | |
| 4051 | if (err) |
| 4052 | return NOTIFY_BAD; |
| 4053 | return NOTIFY_DONE; |
| 4054 | } |
| 4055 | |
| 4056 | static struct notifier_block myri10ge_dca_notifier = { |
| 4057 | .notifier_call = myri10ge_notify_dca, |
| 4058 | .next = NULL, |
| 4059 | .priority = 0, |
| 4060 | }; |
Brice Goglin | 4ee2ac5 | 2008-11-23 15:49:28 -0800 | [diff] [blame] | 4061 | #endif /* CONFIG_MYRI10GE_DCA */ |
Brice Goglin | 981813d | 2008-05-09 02:22:16 +0200 | [diff] [blame] | 4062 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 4063 | static __init int myri10ge_init_module(void) |
| 4064 | { |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 4065 | pr_info("Version %s\n", MYRI10GE_VERSION_STR); |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 4066 | |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 4067 | if (myri10ge_rss_hash > MXGEFW_RSS_HASH_TYPE_MAX) { |
Joe Perches | 78ca90e | 2010-02-22 16:56:58 +0000 | [diff] [blame] | 4068 | pr_err("Illegal rssh hash type %d, defaulting to source port\n", |
| 4069 | myri10ge_rss_hash); |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 4070 | myri10ge_rss_hash = MXGEFW_RSS_HASH_TYPE_SRC_PORT; |
| 4071 | } |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4072 | #ifdef CONFIG_MYRI10GE_DCA |
Brice Goglin | 981813d | 2008-05-09 02:22:16 +0200 | [diff] [blame] | 4073 | dca_register_notify(&myri10ge_dca_notifier); |
| 4074 | #endif |
Brice Goglin | 236bb5e6 | 2008-09-28 15:34:21 +0000 | [diff] [blame] | 4075 | if (myri10ge_max_slices > MYRI10GE_MAX_SLICES) |
| 4076 | myri10ge_max_slices = MYRI10GE_MAX_SLICES; |
Brice Goglin | 0dcffac | 2008-05-09 02:21:49 +0200 | [diff] [blame] | 4077 | |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 4078 | return pci_register_driver(&myri10ge_driver); |
| 4079 | } |
| 4080 | |
| 4081 | module_init(myri10ge_init_module); |
| 4082 | |
| 4083 | static __exit void myri10ge_cleanup_module(void) |
| 4084 | { |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4085 | #ifdef CONFIG_MYRI10GE_DCA |
Brice Goglin | 981813d | 2008-05-09 02:22:16 +0200 | [diff] [blame] | 4086 | dca_unregister_notify(&myri10ge_dca_notifier); |
| 4087 | #endif |
Brice Goglin | 0da34b6 | 2006-05-23 06:10:15 -0400 | [diff] [blame] | 4088 | pci_unregister_driver(&myri10ge_driver); |
| 4089 | } |
| 4090 | |
| 4091 | module_exit(myri10ge_cleanup_module); |