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