193f7848bSJeff Kirsher /*************************************************************************
293f7848bSJeff Kirsher * myri10ge.c: Myricom Myri-10G Ethernet driver.
393f7848bSJeff Kirsher *
493f7848bSJeff Kirsher * Copyright (C) 2005 - 2011 Myricom, Inc.
593f7848bSJeff Kirsher * All rights reserved.
693f7848bSJeff Kirsher *
793f7848bSJeff Kirsher * Redistribution and use in source and binary forms, with or without
893f7848bSJeff Kirsher * modification, are permitted provided that the following conditions
993f7848bSJeff Kirsher * are met:
1093f7848bSJeff Kirsher * 1. Redistributions of source code must retain the above copyright
1193f7848bSJeff Kirsher * notice, this list of conditions and the following disclaimer.
1293f7848bSJeff Kirsher * 2. Redistributions in binary form must reproduce the above copyright
1393f7848bSJeff Kirsher * notice, this list of conditions and the following disclaimer in the
1493f7848bSJeff Kirsher * documentation and/or other materials provided with the distribution.
1593f7848bSJeff Kirsher * 3. Neither the name of Myricom, Inc. nor the names of its contributors
1693f7848bSJeff Kirsher * may be used to endorse or promote products derived from this software
1793f7848bSJeff Kirsher * without specific prior written permission.
1893f7848bSJeff Kirsher *
1993f7848bSJeff Kirsher * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2093f7848bSJeff Kirsher * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2193f7848bSJeff Kirsher * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2293f7848bSJeff Kirsher * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
2393f7848bSJeff Kirsher * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2493f7848bSJeff Kirsher * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2593f7848bSJeff Kirsher * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2693f7848bSJeff Kirsher * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2793f7848bSJeff Kirsher * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2893f7848bSJeff Kirsher * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2993f7848bSJeff Kirsher * POSSIBILITY OF SUCH DAMAGE.
3093f7848bSJeff Kirsher *
3193f7848bSJeff Kirsher *
3293f7848bSJeff Kirsher * If the eeprom on your board is not recent enough, you will need to get a
3393f7848bSJeff Kirsher * newer firmware image at:
3493f7848bSJeff Kirsher * http://www.myri.com/scs/download-Myri10GE.html
3593f7848bSJeff Kirsher *
3693f7848bSJeff Kirsher * Contact Information:
3793f7848bSJeff Kirsher * <help@myri.com>
3893f7848bSJeff Kirsher * Myricom, Inc., 325N Santa Anita Avenue, Arcadia, CA 91006
3993f7848bSJeff Kirsher *************************************************************************/
4093f7848bSJeff Kirsher
4193f7848bSJeff Kirsher #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
4293f7848bSJeff Kirsher
4393f7848bSJeff Kirsher #include <linux/tcp.h>
4493f7848bSJeff Kirsher #include <linux/netdevice.h>
4593f7848bSJeff Kirsher #include <linux/skbuff.h>
4693f7848bSJeff Kirsher #include <linux/string.h>
4793f7848bSJeff Kirsher #include <linux/module.h>
4893f7848bSJeff Kirsher #include <linux/pci.h>
4993f7848bSJeff Kirsher #include <linux/dma-mapping.h>
5093f7848bSJeff Kirsher #include <linux/etherdevice.h>
5193f7848bSJeff Kirsher #include <linux/if_ether.h>
5293f7848bSJeff Kirsher #include <linux/if_vlan.h>
5393f7848bSJeff Kirsher #include <linux/dca.h>
5493f7848bSJeff Kirsher #include <linux/ip.h>
5593f7848bSJeff Kirsher #include <linux/inet.h>
5693f7848bSJeff Kirsher #include <linux/in.h>
5793f7848bSJeff Kirsher #include <linux/ethtool.h>
5893f7848bSJeff Kirsher #include <linux/firmware.h>
5993f7848bSJeff Kirsher #include <linux/delay.h>
6093f7848bSJeff Kirsher #include <linux/timer.h>
6193f7848bSJeff Kirsher #include <linux/vmalloc.h>
6293f7848bSJeff Kirsher #include <linux/crc32.h>
6393f7848bSJeff Kirsher #include <linux/moduleparam.h>
6493f7848bSJeff Kirsher #include <linux/io.h>
6593f7848bSJeff Kirsher #include <linux/log2.h>
6693f7848bSJeff Kirsher #include <linux/slab.h>
6793f7848bSJeff Kirsher #include <linux/prefetch.h>
6893f7848bSJeff Kirsher #include <net/checksum.h>
69*d457a0e3SEric Dumazet #include <net/gso.h>
7093f7848bSJeff Kirsher #include <net/ip.h>
7193f7848bSJeff Kirsher #include <net/tcp.h>
7293f7848bSJeff Kirsher #include <asm/byteorder.h>
7393f7848bSJeff Kirsher #include <asm/processor.h>
7493f7848bSJeff Kirsher
7593f7848bSJeff Kirsher #include "myri10ge_mcp.h"
7693f7848bSJeff Kirsher #include "myri10ge_mcp_gen_header.h"
7793f7848bSJeff Kirsher
7893f7848bSJeff Kirsher #define MYRI10GE_VERSION_STR "1.5.3-1.534"
7993f7848bSJeff Kirsher
8093f7848bSJeff Kirsher MODULE_DESCRIPTION("Myricom 10G driver (10GbE)");
8193f7848bSJeff Kirsher MODULE_AUTHOR("Maintainer: help@myri.com");
8293f7848bSJeff Kirsher MODULE_VERSION(MYRI10GE_VERSION_STR);
8393f7848bSJeff Kirsher MODULE_LICENSE("Dual BSD/GPL");
8493f7848bSJeff Kirsher
8593f7848bSJeff Kirsher #define MYRI10GE_MAX_ETHER_MTU 9014
8693f7848bSJeff Kirsher
8793f7848bSJeff Kirsher #define MYRI10GE_ETH_STOPPED 0
8893f7848bSJeff Kirsher #define MYRI10GE_ETH_STOPPING 1
8993f7848bSJeff Kirsher #define MYRI10GE_ETH_STARTING 2
9093f7848bSJeff Kirsher #define MYRI10GE_ETH_RUNNING 3
9193f7848bSJeff Kirsher #define MYRI10GE_ETH_OPEN_FAILED 4
9293f7848bSJeff Kirsher
9393f7848bSJeff Kirsher #define MYRI10GE_EEPROM_STRINGS_SIZE 256
9493f7848bSJeff Kirsher #define MYRI10GE_MAX_SEND_DESC_TSO ((65536 / 2048) * 2)
9593f7848bSJeff Kirsher
9693f7848bSJeff Kirsher #define MYRI10GE_NO_CONFIRM_DATA htonl(0xffffffff)
9793f7848bSJeff Kirsher #define MYRI10GE_NO_RESPONSE_RESULT 0xffffffff
9893f7848bSJeff Kirsher
9993f7848bSJeff Kirsher #define MYRI10GE_ALLOC_ORDER 0
10093f7848bSJeff Kirsher #define MYRI10GE_ALLOC_SIZE ((1 << MYRI10GE_ALLOC_ORDER) * PAGE_SIZE)
10193f7848bSJeff Kirsher #define MYRI10GE_MAX_FRAGS_PER_FRAME (MYRI10GE_MAX_ETHER_MTU/MYRI10GE_ALLOC_SIZE + 1)
10293f7848bSJeff Kirsher
10393f7848bSJeff Kirsher #define MYRI10GE_MAX_SLICES 32
10493f7848bSJeff Kirsher
10593f7848bSJeff Kirsher struct myri10ge_rx_buffer_state {
10693f7848bSJeff Kirsher struct page *page;
10793f7848bSJeff Kirsher int page_offset;
10893f7848bSJeff Kirsher DEFINE_DMA_UNMAP_ADDR(bus);
10993f7848bSJeff Kirsher DEFINE_DMA_UNMAP_LEN(len);
11093f7848bSJeff Kirsher };
11193f7848bSJeff Kirsher
11293f7848bSJeff Kirsher struct myri10ge_tx_buffer_state {
11393f7848bSJeff Kirsher struct sk_buff *skb;
11493f7848bSJeff Kirsher int last;
11593f7848bSJeff Kirsher DEFINE_DMA_UNMAP_ADDR(bus);
11693f7848bSJeff Kirsher DEFINE_DMA_UNMAP_LEN(len);
11793f7848bSJeff Kirsher };
11893f7848bSJeff Kirsher
11993f7848bSJeff Kirsher struct myri10ge_cmd {
12093f7848bSJeff Kirsher u32 data0;
12193f7848bSJeff Kirsher u32 data1;
12293f7848bSJeff Kirsher u32 data2;
12393f7848bSJeff Kirsher };
12493f7848bSJeff Kirsher
12593f7848bSJeff Kirsher struct myri10ge_rx_buf {
12693f7848bSJeff Kirsher struct mcp_kreq_ether_recv __iomem *lanai; /* lanai ptr for recv ring */
12793f7848bSJeff Kirsher struct mcp_kreq_ether_recv *shadow; /* host shadow of recv ring */
12893f7848bSJeff Kirsher struct myri10ge_rx_buffer_state *info;
12993f7848bSJeff Kirsher struct page *page;
13093f7848bSJeff Kirsher dma_addr_t bus;
13193f7848bSJeff Kirsher int page_offset;
13293f7848bSJeff Kirsher int cnt;
13393f7848bSJeff Kirsher int fill_cnt;
13493f7848bSJeff Kirsher int alloc_fail;
13593f7848bSJeff Kirsher int mask; /* number of rx slots -1 */
13693f7848bSJeff Kirsher int watchdog_needed;
13793f7848bSJeff Kirsher };
13893f7848bSJeff Kirsher
13993f7848bSJeff Kirsher struct myri10ge_tx_buf {
14093f7848bSJeff Kirsher struct mcp_kreq_ether_send __iomem *lanai; /* lanai ptr for sendq */
14193f7848bSJeff Kirsher __be32 __iomem *send_go; /* "go" doorbell ptr */
14293f7848bSJeff Kirsher __be32 __iomem *send_stop; /* "stop" doorbell ptr */
14393f7848bSJeff Kirsher struct mcp_kreq_ether_send *req_list; /* host shadow of sendq */
14493f7848bSJeff Kirsher char *req_bytes;
14593f7848bSJeff Kirsher struct myri10ge_tx_buffer_state *info;
14693f7848bSJeff Kirsher int mask; /* number of transmit slots -1 */
14793f7848bSJeff Kirsher int req ____cacheline_aligned; /* transmit slots submitted */
14893f7848bSJeff Kirsher int pkt_start; /* packets started */
14993f7848bSJeff Kirsher int stop_queue;
15093f7848bSJeff Kirsher int linearized;
15193f7848bSJeff Kirsher int done ____cacheline_aligned; /* transmit slots completed */
15293f7848bSJeff Kirsher int pkt_done; /* packets completed */
15393f7848bSJeff Kirsher int wake_queue;
15493f7848bSJeff Kirsher int queue_active;
15593f7848bSJeff Kirsher };
15693f7848bSJeff Kirsher
15793f7848bSJeff Kirsher struct myri10ge_rx_done {
15893f7848bSJeff Kirsher struct mcp_slot *entry;
15993f7848bSJeff Kirsher dma_addr_t bus;
16093f7848bSJeff Kirsher int cnt;
16193f7848bSJeff Kirsher int idx;
16293f7848bSJeff Kirsher };
16393f7848bSJeff Kirsher
16493f7848bSJeff Kirsher struct myri10ge_slice_netstats {
16593f7848bSJeff Kirsher unsigned long rx_packets;
16693f7848bSJeff Kirsher unsigned long tx_packets;
16793f7848bSJeff Kirsher unsigned long rx_bytes;
16893f7848bSJeff Kirsher unsigned long tx_bytes;
16993f7848bSJeff Kirsher unsigned long rx_dropped;
17093f7848bSJeff Kirsher unsigned long tx_dropped;
17193f7848bSJeff Kirsher };
17293f7848bSJeff Kirsher
17393f7848bSJeff Kirsher struct myri10ge_slice_state {
17493f7848bSJeff Kirsher struct myri10ge_tx_buf tx; /* transmit ring */
17593f7848bSJeff Kirsher struct myri10ge_rx_buf rx_small;
17693f7848bSJeff Kirsher struct myri10ge_rx_buf rx_big;
17793f7848bSJeff Kirsher struct myri10ge_rx_done rx_done;
17893f7848bSJeff Kirsher struct net_device *dev;
17993f7848bSJeff Kirsher struct napi_struct napi;
18093f7848bSJeff Kirsher struct myri10ge_priv *mgp;
18193f7848bSJeff Kirsher struct myri10ge_slice_netstats stats;
18293f7848bSJeff Kirsher __be32 __iomem *irq_claim;
18393f7848bSJeff Kirsher struct mcp_irq_data *fw_stats;
18493f7848bSJeff Kirsher dma_addr_t fw_stats_bus;
18593f7848bSJeff Kirsher int watchdog_tx_done;
18693f7848bSJeff Kirsher int watchdog_tx_req;
18793f7848bSJeff Kirsher int watchdog_rx_done;
18893f7848bSJeff Kirsher int stuck;
18993f7848bSJeff Kirsher #ifdef CONFIG_MYRI10GE_DCA
19093f7848bSJeff Kirsher int cached_dca_tag;
19193f7848bSJeff Kirsher int cpu;
19293f7848bSJeff Kirsher __be32 __iomem *dca_tag;
19393f7848bSJeff Kirsher #endif
19493f7848bSJeff Kirsher char irq_desc[32];
19593f7848bSJeff Kirsher };
19693f7848bSJeff Kirsher
19793f7848bSJeff Kirsher struct myri10ge_priv {
19893f7848bSJeff Kirsher struct myri10ge_slice_state *ss;
19993f7848bSJeff Kirsher int tx_boundary; /* boundary transmits cannot cross */
20093f7848bSJeff Kirsher int num_slices;
20193f7848bSJeff Kirsher int running; /* running? */
20293f7848bSJeff Kirsher int small_bytes;
20393f7848bSJeff Kirsher int big_bytes;
20493f7848bSJeff Kirsher int max_intr_slots;
20593f7848bSJeff Kirsher struct net_device *dev;
20693f7848bSJeff Kirsher u8 __iomem *sram;
20793f7848bSJeff Kirsher int sram_size;
20893f7848bSJeff Kirsher unsigned long board_span;
20993f7848bSJeff Kirsher unsigned long iomem_base;
21093f7848bSJeff Kirsher __be32 __iomem *irq_deassert;
21193f7848bSJeff Kirsher char *mac_addr_string;
21293f7848bSJeff Kirsher struct mcp_cmd_response *cmd;
21393f7848bSJeff Kirsher dma_addr_t cmd_bus;
21493f7848bSJeff Kirsher struct pci_dev *pdev;
21593f7848bSJeff Kirsher int msi_enabled;
21693f7848bSJeff Kirsher int msix_enabled;
21793f7848bSJeff Kirsher struct msix_entry *msix_vectors;
21893f7848bSJeff Kirsher #ifdef CONFIG_MYRI10GE_DCA
21993f7848bSJeff Kirsher int dca_enabled;
22093f7848bSJeff Kirsher int relaxed_order;
22193f7848bSJeff Kirsher #endif
22293f7848bSJeff Kirsher u32 link_state;
22393f7848bSJeff Kirsher unsigned int rdma_tags_available;
22493f7848bSJeff Kirsher int intr_coal_delay;
22593f7848bSJeff Kirsher __be32 __iomem *intr_coal_delay_ptr;
226e4b6c303SLuis R. Rodriguez int wc_cookie;
22793f7848bSJeff Kirsher int down_cnt;
22893f7848bSJeff Kirsher wait_queue_head_t down_wq;
22993f7848bSJeff Kirsher struct work_struct watchdog_work;
23093f7848bSJeff Kirsher struct timer_list watchdog_timer;
23193f7848bSJeff Kirsher int watchdog_resets;
23293f7848bSJeff Kirsher int watchdog_pause;
23393f7848bSJeff Kirsher int pause;
23493f7848bSJeff Kirsher bool fw_name_allocated;
23593f7848bSJeff Kirsher char *fw_name;
23693f7848bSJeff Kirsher char eeprom_strings[MYRI10GE_EEPROM_STRINGS_SIZE];
23793f7848bSJeff Kirsher char *product_code_string;
23893f7848bSJeff Kirsher char fw_version[128];
23993f7848bSJeff Kirsher int fw_ver_major;
24093f7848bSJeff Kirsher int fw_ver_minor;
24193f7848bSJeff Kirsher int fw_ver_tiny;
24293f7848bSJeff Kirsher int adopted_rx_filter_bug;
2431409a932SJoe Perches u8 mac_addr[ETH_ALEN]; /* eeprom mac address */
24493f7848bSJeff Kirsher unsigned long serial_number;
24593f7848bSJeff Kirsher int vendor_specific_offset;
24693f7848bSJeff Kirsher int fw_multicast_support;
24793f7848bSJeff Kirsher u32 features;
24893f7848bSJeff Kirsher u32 max_tso6;
24993f7848bSJeff Kirsher u32 read_dma;
25093f7848bSJeff Kirsher u32 write_dma;
25193f7848bSJeff Kirsher u32 read_write_dma;
25293f7848bSJeff Kirsher u32 link_changes;
25393f7848bSJeff Kirsher u32 msg_enable;
25493f7848bSJeff Kirsher unsigned int board_number;
25593f7848bSJeff Kirsher int rebooted;
25693f7848bSJeff Kirsher };
25793f7848bSJeff Kirsher
25893f7848bSJeff Kirsher static char *myri10ge_fw_unaligned = "myri10ge_ethp_z8e.dat";
25993f7848bSJeff Kirsher static char *myri10ge_fw_aligned = "myri10ge_eth_z8e.dat";
26093f7848bSJeff Kirsher static char *myri10ge_fw_rss_unaligned = "myri10ge_rss_ethp_z8e.dat";
26193f7848bSJeff Kirsher static char *myri10ge_fw_rss_aligned = "myri10ge_rss_eth_z8e.dat";
26293f7848bSJeff Kirsher MODULE_FIRMWARE("myri10ge_ethp_z8e.dat");
26393f7848bSJeff Kirsher MODULE_FIRMWARE("myri10ge_eth_z8e.dat");
26493f7848bSJeff Kirsher MODULE_FIRMWARE("myri10ge_rss_ethp_z8e.dat");
26593f7848bSJeff Kirsher MODULE_FIRMWARE("myri10ge_rss_eth_z8e.dat");
26693f7848bSJeff Kirsher
267b51d23e4SDan Streetman /* Careful: must be accessed under kernel_param_lock() */
26893f7848bSJeff Kirsher static char *myri10ge_fw_name = NULL;
269d3757ba4SJoe Perches module_param(myri10ge_fw_name, charp, 0644);
27093f7848bSJeff Kirsher MODULE_PARM_DESC(myri10ge_fw_name, "Firmware image name");
27193f7848bSJeff Kirsher
27293f7848bSJeff Kirsher #define MYRI10GE_MAX_BOARDS 8
27393f7848bSJeff Kirsher static char *myri10ge_fw_names[MYRI10GE_MAX_BOARDS] =
27493f7848bSJeff Kirsher {[0 ... (MYRI10GE_MAX_BOARDS - 1)] = NULL };
27593f7848bSJeff Kirsher module_param_array_named(myri10ge_fw_names, myri10ge_fw_names, charp, NULL,
27693f7848bSJeff Kirsher 0444);
2771a61a8f1SWei Yongjun MODULE_PARM_DESC(myri10ge_fw_names, "Firmware image names per board");
27893f7848bSJeff Kirsher
27993f7848bSJeff Kirsher static int myri10ge_ecrc_enable = 1;
280d3757ba4SJoe Perches module_param(myri10ge_ecrc_enable, int, 0444);
28193f7848bSJeff Kirsher MODULE_PARM_DESC(myri10ge_ecrc_enable, "Enable Extended CRC on PCI-E");
28293f7848bSJeff Kirsher
28393f7848bSJeff Kirsher static int myri10ge_small_bytes = -1; /* -1 == auto */
284d3757ba4SJoe Perches module_param(myri10ge_small_bytes, int, 0644);
28593f7848bSJeff Kirsher MODULE_PARM_DESC(myri10ge_small_bytes, "Threshold of small packets");
28693f7848bSJeff Kirsher
28793f7848bSJeff Kirsher static int myri10ge_msi = 1; /* enable msi by default */
288d3757ba4SJoe Perches module_param(myri10ge_msi, int, 0644);
28993f7848bSJeff Kirsher MODULE_PARM_DESC(myri10ge_msi, "Enable Message Signalled Interrupts");
29093f7848bSJeff Kirsher
29193f7848bSJeff Kirsher static int myri10ge_intr_coal_delay = 75;
292d3757ba4SJoe Perches module_param(myri10ge_intr_coal_delay, int, 0444);
29393f7848bSJeff Kirsher MODULE_PARM_DESC(myri10ge_intr_coal_delay, "Interrupt coalescing delay");
29493f7848bSJeff Kirsher
29593f7848bSJeff Kirsher static int myri10ge_flow_control = 1;
296d3757ba4SJoe Perches module_param(myri10ge_flow_control, int, 0444);
29793f7848bSJeff Kirsher MODULE_PARM_DESC(myri10ge_flow_control, "Pause parameter");
29893f7848bSJeff Kirsher
29993f7848bSJeff Kirsher static int myri10ge_deassert_wait = 1;
300d3757ba4SJoe Perches module_param(myri10ge_deassert_wait, int, 0644);
30193f7848bSJeff Kirsher MODULE_PARM_DESC(myri10ge_deassert_wait,
30293f7848bSJeff Kirsher "Wait when deasserting legacy interrupts");
30393f7848bSJeff Kirsher
30493f7848bSJeff Kirsher static int myri10ge_force_firmware = 0;
305d3757ba4SJoe Perches module_param(myri10ge_force_firmware, int, 0444);
30693f7848bSJeff Kirsher MODULE_PARM_DESC(myri10ge_force_firmware,
30793f7848bSJeff Kirsher "Force firmware to assume aligned completions");
30893f7848bSJeff Kirsher
30993f7848bSJeff Kirsher static int myri10ge_initial_mtu = MYRI10GE_MAX_ETHER_MTU - ETH_HLEN;
310d3757ba4SJoe Perches module_param(myri10ge_initial_mtu, int, 0444);
31193f7848bSJeff Kirsher MODULE_PARM_DESC(myri10ge_initial_mtu, "Initial MTU");
31293f7848bSJeff Kirsher
31393f7848bSJeff Kirsher static int myri10ge_napi_weight = 64;
314d3757ba4SJoe Perches module_param(myri10ge_napi_weight, int, 0444);
31593f7848bSJeff Kirsher MODULE_PARM_DESC(myri10ge_napi_weight, "Set NAPI weight");
31693f7848bSJeff Kirsher
31793f7848bSJeff Kirsher static int myri10ge_watchdog_timeout = 1;
318d3757ba4SJoe Perches module_param(myri10ge_watchdog_timeout, int, 0444);
31993f7848bSJeff Kirsher MODULE_PARM_DESC(myri10ge_watchdog_timeout, "Set watchdog timeout");
32093f7848bSJeff Kirsher
32193f7848bSJeff Kirsher static int myri10ge_max_irq_loops = 1048576;
322d3757ba4SJoe Perches module_param(myri10ge_max_irq_loops, int, 0444);
32393f7848bSJeff Kirsher MODULE_PARM_DESC(myri10ge_max_irq_loops,
32493f7848bSJeff Kirsher "Set stuck legacy IRQ detection threshold");
32593f7848bSJeff Kirsher
32693f7848bSJeff Kirsher #define MYRI10GE_MSG_DEFAULT NETIF_MSG_LINK
32793f7848bSJeff Kirsher
32893f7848bSJeff Kirsher static int myri10ge_debug = -1; /* defaults above */
32993f7848bSJeff Kirsher module_param(myri10ge_debug, int, 0);
33093f7848bSJeff Kirsher MODULE_PARM_DESC(myri10ge_debug, "Debug level (0=none,...,16=all)");
33193f7848bSJeff Kirsher
33293f7848bSJeff Kirsher static int myri10ge_fill_thresh = 256;
333d3757ba4SJoe Perches module_param(myri10ge_fill_thresh, int, 0644);
33493f7848bSJeff Kirsher MODULE_PARM_DESC(myri10ge_fill_thresh, "Number of empty rx slots allowed");
33593f7848bSJeff Kirsher
33693f7848bSJeff Kirsher static int myri10ge_reset_recover = 1;
33793f7848bSJeff Kirsher
33893f7848bSJeff Kirsher static int myri10ge_max_slices = 1;
339d3757ba4SJoe Perches module_param(myri10ge_max_slices, int, 0444);
34093f7848bSJeff Kirsher MODULE_PARM_DESC(myri10ge_max_slices, "Max tx/rx queues");
34193f7848bSJeff Kirsher
34293f7848bSJeff Kirsher static int myri10ge_rss_hash = MXGEFW_RSS_HASH_TYPE_SRC_DST_PORT;
343d3757ba4SJoe Perches module_param(myri10ge_rss_hash, int, 0444);
34493f7848bSJeff Kirsher MODULE_PARM_DESC(myri10ge_rss_hash, "Type of RSS hashing to do");
34593f7848bSJeff Kirsher
34693f7848bSJeff Kirsher static int myri10ge_dca = 1;
347d3757ba4SJoe Perches module_param(myri10ge_dca, int, 0444);
34893f7848bSJeff Kirsher MODULE_PARM_DESC(myri10ge_dca, "Enable DCA if possible");
34993f7848bSJeff Kirsher
35093f7848bSJeff Kirsher #define MYRI10GE_FW_OFFSET 1024*1024
35193f7848bSJeff Kirsher #define MYRI10GE_HIGHPART_TO_U32(X) \
35293f7848bSJeff Kirsher (sizeof (X) == 8) ? ((u32)((u64)(X) >> 32)) : (0)
35393f7848bSJeff Kirsher #define MYRI10GE_LOWPART_TO_U32(X) ((u32)(X))
35493f7848bSJeff Kirsher
35593f7848bSJeff Kirsher #define myri10ge_pio_copy(to,from,size) __iowrite64_copy(to,from,size/8)
35693f7848bSJeff Kirsher
35793f7848bSJeff Kirsher static void myri10ge_set_multicast_list(struct net_device *dev);
35893f7848bSJeff Kirsher static netdev_tx_t myri10ge_sw_tso(struct sk_buff *skb,
35993f7848bSJeff Kirsher struct net_device *dev);
36093f7848bSJeff Kirsher
put_be32(__be32 val,__be32 __iomem * p)36193f7848bSJeff Kirsher static inline void put_be32(__be32 val, __be32 __iomem * p)
36293f7848bSJeff Kirsher {
36393f7848bSJeff Kirsher __raw_writel((__force __u32) val, (__force void __iomem *)p);
36493f7848bSJeff Kirsher }
36593f7848bSJeff Kirsher
366bc1f4470Sstephen hemminger static void myri10ge_get_stats(struct net_device *dev,
36793f7848bSJeff Kirsher struct rtnl_link_stats64 *stats);
36893f7848bSJeff Kirsher
set_fw_name(struct myri10ge_priv * mgp,char * name,bool allocated)36993f7848bSJeff Kirsher static void set_fw_name(struct myri10ge_priv *mgp, char *name, bool allocated)
37093f7848bSJeff Kirsher {
37193f7848bSJeff Kirsher if (mgp->fw_name_allocated)
37293f7848bSJeff Kirsher kfree(mgp->fw_name);
37393f7848bSJeff Kirsher mgp->fw_name = name;
37493f7848bSJeff Kirsher mgp->fw_name_allocated = allocated;
37593f7848bSJeff Kirsher }
37693f7848bSJeff Kirsher
37793f7848bSJeff Kirsher static int
myri10ge_send_cmd(struct myri10ge_priv * mgp,u32 cmd,struct myri10ge_cmd * data,int atomic)37893f7848bSJeff Kirsher myri10ge_send_cmd(struct myri10ge_priv *mgp, u32 cmd,
37993f7848bSJeff Kirsher struct myri10ge_cmd *data, int atomic)
38093f7848bSJeff Kirsher {
38193f7848bSJeff Kirsher struct mcp_cmd *buf;
38293f7848bSJeff Kirsher char buf_bytes[sizeof(*buf) + 8];
38393f7848bSJeff Kirsher struct mcp_cmd_response *response = mgp->cmd;
38493f7848bSJeff Kirsher char __iomem *cmd_addr = mgp->sram + MXGEFW_ETH_CMD;
38593f7848bSJeff Kirsher u32 dma_low, dma_high, result, value;
38693f7848bSJeff Kirsher int sleep_total = 0;
38793f7848bSJeff Kirsher
38893f7848bSJeff Kirsher /* ensure buf is aligned to 8 bytes */
38993f7848bSJeff Kirsher buf = (struct mcp_cmd *)ALIGN((unsigned long)buf_bytes, 8);
39093f7848bSJeff Kirsher
39193f7848bSJeff Kirsher buf->data0 = htonl(data->data0);
39293f7848bSJeff Kirsher buf->data1 = htonl(data->data1);
39393f7848bSJeff Kirsher buf->data2 = htonl(data->data2);
39493f7848bSJeff Kirsher buf->cmd = htonl(cmd);
39593f7848bSJeff Kirsher dma_low = MYRI10GE_LOWPART_TO_U32(mgp->cmd_bus);
39693f7848bSJeff Kirsher dma_high = MYRI10GE_HIGHPART_TO_U32(mgp->cmd_bus);
39793f7848bSJeff Kirsher
39893f7848bSJeff Kirsher buf->response_addr.low = htonl(dma_low);
39993f7848bSJeff Kirsher buf->response_addr.high = htonl(dma_high);
40093f7848bSJeff Kirsher response->result = htonl(MYRI10GE_NO_RESPONSE_RESULT);
40193f7848bSJeff Kirsher mb();
40293f7848bSJeff Kirsher myri10ge_pio_copy(cmd_addr, buf, sizeof(*buf));
40393f7848bSJeff Kirsher
40493f7848bSJeff Kirsher /* wait up to 15ms. Longest command is the DMA benchmark,
40593f7848bSJeff Kirsher * which is capped at 5ms, but runs from a timeout handler
40693f7848bSJeff Kirsher * that runs every 7.8ms. So a 15ms timeout leaves us with
40793f7848bSJeff Kirsher * a 2.2ms margin
40893f7848bSJeff Kirsher */
40993f7848bSJeff Kirsher if (atomic) {
41093f7848bSJeff Kirsher /* if atomic is set, do not sleep,
41193f7848bSJeff Kirsher * and try to get the completion quickly
41293f7848bSJeff Kirsher * (1ms will be enough for those commands) */
41393f7848bSJeff Kirsher for (sleep_total = 0;
41493f7848bSJeff Kirsher sleep_total < 1000 &&
41593f7848bSJeff Kirsher response->result == htonl(MYRI10GE_NO_RESPONSE_RESULT);
41693f7848bSJeff Kirsher sleep_total += 10) {
41793f7848bSJeff Kirsher udelay(10);
41893f7848bSJeff Kirsher mb();
41993f7848bSJeff Kirsher }
42093f7848bSJeff Kirsher } else {
42193f7848bSJeff Kirsher /* use msleep for most command */
42293f7848bSJeff Kirsher for (sleep_total = 0;
42393f7848bSJeff Kirsher sleep_total < 15 &&
42493f7848bSJeff Kirsher response->result == htonl(MYRI10GE_NO_RESPONSE_RESULT);
42593f7848bSJeff Kirsher sleep_total++)
42693f7848bSJeff Kirsher msleep(1);
42793f7848bSJeff Kirsher }
42893f7848bSJeff Kirsher
42993f7848bSJeff Kirsher result = ntohl(response->result);
43093f7848bSJeff Kirsher value = ntohl(response->data);
43193f7848bSJeff Kirsher if (result != MYRI10GE_NO_RESPONSE_RESULT) {
43293f7848bSJeff Kirsher if (result == 0) {
43393f7848bSJeff Kirsher data->data0 = value;
43493f7848bSJeff Kirsher return 0;
43593f7848bSJeff Kirsher } else if (result == MXGEFW_CMD_UNKNOWN) {
43693f7848bSJeff Kirsher return -ENOSYS;
43793f7848bSJeff Kirsher } else if (result == MXGEFW_CMD_ERROR_UNALIGNED) {
43893f7848bSJeff Kirsher return -E2BIG;
43993f7848bSJeff Kirsher } else if (result == MXGEFW_CMD_ERROR_RANGE &&
44093f7848bSJeff Kirsher cmd == MXGEFW_CMD_ENABLE_RSS_QUEUES &&
44193f7848bSJeff Kirsher (data->
44293f7848bSJeff Kirsher data1 & MXGEFW_SLICE_ENABLE_MULTIPLE_TX_QUEUES) !=
44393f7848bSJeff Kirsher 0) {
44493f7848bSJeff Kirsher return -ERANGE;
44593f7848bSJeff Kirsher } else {
44693f7848bSJeff Kirsher dev_err(&mgp->pdev->dev,
44793f7848bSJeff Kirsher "command %d failed, result = %d\n",
44893f7848bSJeff Kirsher cmd, result);
44993f7848bSJeff Kirsher return -ENXIO;
45093f7848bSJeff Kirsher }
45193f7848bSJeff Kirsher }
45293f7848bSJeff Kirsher
45393f7848bSJeff Kirsher dev_err(&mgp->pdev->dev, "command %d timed out, result = %d\n",
45493f7848bSJeff Kirsher cmd, result);
45593f7848bSJeff Kirsher return -EAGAIN;
45693f7848bSJeff Kirsher }
45793f7848bSJeff Kirsher
45893f7848bSJeff Kirsher /*
45993f7848bSJeff Kirsher * The eeprom strings on the lanaiX have the format
46093f7848bSJeff Kirsher * SN=x\0
46193f7848bSJeff Kirsher * MAC=x:x:x:x:x:x\0
46293f7848bSJeff Kirsher * PT:ddd mmm xx xx:xx:xx xx\0
46393f7848bSJeff Kirsher * PV:ddd mmm xx xx:xx:xx xx\0
46493f7848bSJeff Kirsher */
myri10ge_read_mac_addr(struct myri10ge_priv * mgp)46593f7848bSJeff Kirsher static int myri10ge_read_mac_addr(struct myri10ge_priv *mgp)
46693f7848bSJeff Kirsher {
46793f7848bSJeff Kirsher char *ptr, *limit;
46893f7848bSJeff Kirsher int i;
46993f7848bSJeff Kirsher
47093f7848bSJeff Kirsher ptr = mgp->eeprom_strings;
47193f7848bSJeff Kirsher limit = mgp->eeprom_strings + MYRI10GE_EEPROM_STRINGS_SIZE;
47293f7848bSJeff Kirsher
47393f7848bSJeff Kirsher while (*ptr != '\0' && ptr < limit) {
47493f7848bSJeff Kirsher if (memcmp(ptr, "MAC=", 4) == 0) {
47593f7848bSJeff Kirsher ptr += 4;
47693f7848bSJeff Kirsher mgp->mac_addr_string = ptr;
47793f7848bSJeff Kirsher for (i = 0; i < 6; i++) {
47893f7848bSJeff Kirsher if ((ptr + 2) > limit)
47993f7848bSJeff Kirsher goto abort;
48093f7848bSJeff Kirsher mgp->mac_addr[i] =
48193f7848bSJeff Kirsher simple_strtoul(ptr, &ptr, 16);
48293f7848bSJeff Kirsher ptr += 1;
48393f7848bSJeff Kirsher }
48493f7848bSJeff Kirsher }
48593f7848bSJeff Kirsher if (memcmp(ptr, "PC=", 3) == 0) {
48693f7848bSJeff Kirsher ptr += 3;
48793f7848bSJeff Kirsher mgp->product_code_string = ptr;
48893f7848bSJeff Kirsher }
48993f7848bSJeff Kirsher if (memcmp((const void *)ptr, "SN=", 3) == 0) {
49093f7848bSJeff Kirsher ptr += 3;
49193f7848bSJeff Kirsher mgp->serial_number = simple_strtoul(ptr, &ptr, 10);
49293f7848bSJeff Kirsher }
49393f7848bSJeff Kirsher while (ptr < limit && *ptr++) ;
49493f7848bSJeff Kirsher }
49593f7848bSJeff Kirsher
49693f7848bSJeff Kirsher return 0;
49793f7848bSJeff Kirsher
49893f7848bSJeff Kirsher abort:
49993f7848bSJeff Kirsher dev_err(&mgp->pdev->dev, "failed to parse eeprom_strings\n");
50093f7848bSJeff Kirsher return -ENXIO;
50193f7848bSJeff Kirsher }
50293f7848bSJeff Kirsher
50393f7848bSJeff Kirsher /*
50493f7848bSJeff Kirsher * Enable or disable periodic RDMAs from the host to make certain
50593f7848bSJeff Kirsher * chipsets resend dropped PCIe messages
50693f7848bSJeff Kirsher */
50793f7848bSJeff Kirsher
myri10ge_dummy_rdma(struct myri10ge_priv * mgp,int enable)50893f7848bSJeff Kirsher static void myri10ge_dummy_rdma(struct myri10ge_priv *mgp, int enable)
50993f7848bSJeff Kirsher {
51093f7848bSJeff Kirsher char __iomem *submit;
51193f7848bSJeff Kirsher __be32 buf[16] __attribute__ ((__aligned__(8)));
51293f7848bSJeff Kirsher u32 dma_low, dma_high;
51393f7848bSJeff Kirsher int i;
51493f7848bSJeff Kirsher
51593f7848bSJeff Kirsher /* clear confirmation addr */
51693f7848bSJeff Kirsher mgp->cmd->data = 0;
51793f7848bSJeff Kirsher mb();
51893f7848bSJeff Kirsher
51993f7848bSJeff Kirsher /* send a rdma command to the PCIe engine, and wait for the
52093f7848bSJeff Kirsher * response in the confirmation address. The firmware should
52193f7848bSJeff Kirsher * write a -1 there to indicate it is alive and well
52293f7848bSJeff Kirsher */
52393f7848bSJeff Kirsher dma_low = MYRI10GE_LOWPART_TO_U32(mgp->cmd_bus);
52493f7848bSJeff Kirsher dma_high = MYRI10GE_HIGHPART_TO_U32(mgp->cmd_bus);
52593f7848bSJeff Kirsher
52693f7848bSJeff Kirsher buf[0] = htonl(dma_high); /* confirm addr MSW */
52793f7848bSJeff Kirsher buf[1] = htonl(dma_low); /* confirm addr LSW */
52893f7848bSJeff Kirsher buf[2] = MYRI10GE_NO_CONFIRM_DATA; /* confirm data */
52993f7848bSJeff Kirsher buf[3] = htonl(dma_high); /* dummy addr MSW */
53093f7848bSJeff Kirsher buf[4] = htonl(dma_low); /* dummy addr LSW */
53193f7848bSJeff Kirsher buf[5] = htonl(enable); /* enable? */
53293f7848bSJeff Kirsher
53393f7848bSJeff Kirsher submit = mgp->sram + MXGEFW_BOOT_DUMMY_RDMA;
53493f7848bSJeff Kirsher
53593f7848bSJeff Kirsher myri10ge_pio_copy(submit, &buf, sizeof(buf));
53693f7848bSJeff Kirsher for (i = 0; mgp->cmd->data != MYRI10GE_NO_CONFIRM_DATA && i < 20; i++)
53793f7848bSJeff Kirsher msleep(1);
53893f7848bSJeff Kirsher if (mgp->cmd->data != MYRI10GE_NO_CONFIRM_DATA)
53993f7848bSJeff Kirsher dev_err(&mgp->pdev->dev, "dummy rdma %s failed\n",
54093f7848bSJeff Kirsher (enable ? "enable" : "disable"));
54193f7848bSJeff Kirsher }
54293f7848bSJeff Kirsher
54393f7848bSJeff Kirsher static int
myri10ge_validate_firmware(struct myri10ge_priv * mgp,struct mcp_gen_header * hdr)54493f7848bSJeff Kirsher myri10ge_validate_firmware(struct myri10ge_priv *mgp,
54593f7848bSJeff Kirsher struct mcp_gen_header *hdr)
54693f7848bSJeff Kirsher {
54793f7848bSJeff Kirsher struct device *dev = &mgp->pdev->dev;
54893f7848bSJeff Kirsher
54993f7848bSJeff Kirsher /* check firmware type */
55093f7848bSJeff Kirsher if (ntohl(hdr->mcp_type) != MCP_TYPE_ETH) {
55193f7848bSJeff Kirsher dev_err(dev, "Bad firmware type: 0x%x\n", ntohl(hdr->mcp_type));
55293f7848bSJeff Kirsher return -EINVAL;
55393f7848bSJeff Kirsher }
55493f7848bSJeff Kirsher
55593f7848bSJeff Kirsher /* save firmware version for ethtool */
556a2d40ce7SXu Panda strscpy(mgp->fw_version, hdr->version, sizeof(mgp->fw_version));
55793f7848bSJeff Kirsher
55893f7848bSJeff Kirsher sscanf(mgp->fw_version, "%d.%d.%d", &mgp->fw_ver_major,
55993f7848bSJeff Kirsher &mgp->fw_ver_minor, &mgp->fw_ver_tiny);
56093f7848bSJeff Kirsher
56193f7848bSJeff Kirsher if (!(mgp->fw_ver_major == MXGEFW_VERSION_MAJOR &&
56293f7848bSJeff Kirsher mgp->fw_ver_minor == MXGEFW_VERSION_MINOR)) {
56393f7848bSJeff Kirsher dev_err(dev, "Found firmware version %s\n", mgp->fw_version);
56493f7848bSJeff Kirsher dev_err(dev, "Driver needs %d.%d\n", MXGEFW_VERSION_MAJOR,
56593f7848bSJeff Kirsher MXGEFW_VERSION_MINOR);
56693f7848bSJeff Kirsher return -EINVAL;
56793f7848bSJeff Kirsher }
56893f7848bSJeff Kirsher return 0;
56993f7848bSJeff Kirsher }
57093f7848bSJeff Kirsher
myri10ge_load_hotplug_firmware(struct myri10ge_priv * mgp,u32 * size)57193f7848bSJeff Kirsher static int myri10ge_load_hotplug_firmware(struct myri10ge_priv *mgp, u32 * size)
57293f7848bSJeff Kirsher {
57393f7848bSJeff Kirsher unsigned crc, reread_crc;
57493f7848bSJeff Kirsher const struct firmware *fw;
57593f7848bSJeff Kirsher struct device *dev = &mgp->pdev->dev;
57693f7848bSJeff Kirsher unsigned char *fw_readback;
57793f7848bSJeff Kirsher struct mcp_gen_header *hdr;
57893f7848bSJeff Kirsher size_t hdr_offset;
57993f7848bSJeff Kirsher int status;
58093f7848bSJeff Kirsher unsigned i;
58193f7848bSJeff Kirsher
5821c604f91SColin Ian King if (request_firmware(&fw, mgp->fw_name, dev) < 0) {
58393f7848bSJeff Kirsher dev_err(dev, "Unable to load %s firmware image via hotplug\n",
58493f7848bSJeff Kirsher mgp->fw_name);
58593f7848bSJeff Kirsher status = -EINVAL;
58693f7848bSJeff Kirsher goto abort_with_nothing;
58793f7848bSJeff Kirsher }
58893f7848bSJeff Kirsher
58993f7848bSJeff Kirsher /* check size */
59093f7848bSJeff Kirsher
59193f7848bSJeff Kirsher if (fw->size >= mgp->sram_size - MYRI10GE_FW_OFFSET ||
59293f7848bSJeff Kirsher fw->size < MCP_HEADER_PTR_OFFSET + 4) {
59393f7848bSJeff Kirsher dev_err(dev, "Firmware size invalid:%d\n", (int)fw->size);
59493f7848bSJeff Kirsher status = -EINVAL;
59593f7848bSJeff Kirsher goto abort_with_fw;
59693f7848bSJeff Kirsher }
59793f7848bSJeff Kirsher
59893f7848bSJeff Kirsher /* check id */
59993f7848bSJeff Kirsher hdr_offset = ntohl(*(__be32 *) (fw->data + MCP_HEADER_PTR_OFFSET));
60093f7848bSJeff Kirsher if ((hdr_offset & 3) || hdr_offset + sizeof(*hdr) > fw->size) {
60193f7848bSJeff Kirsher dev_err(dev, "Bad firmware file\n");
60293f7848bSJeff Kirsher status = -EINVAL;
60393f7848bSJeff Kirsher goto abort_with_fw;
60493f7848bSJeff Kirsher }
60593f7848bSJeff Kirsher hdr = (void *)(fw->data + hdr_offset);
60693f7848bSJeff Kirsher
60793f7848bSJeff Kirsher status = myri10ge_validate_firmware(mgp, hdr);
60893f7848bSJeff Kirsher if (status != 0)
60993f7848bSJeff Kirsher goto abort_with_fw;
61093f7848bSJeff Kirsher
61193f7848bSJeff Kirsher crc = crc32(~0, fw->data, fw->size);
61293f7848bSJeff Kirsher for (i = 0; i < fw->size; i += 256) {
61393f7848bSJeff Kirsher myri10ge_pio_copy(mgp->sram + MYRI10GE_FW_OFFSET + i,
61493f7848bSJeff Kirsher fw->data + i,
61593f7848bSJeff Kirsher min(256U, (unsigned)(fw->size - i)));
61693f7848bSJeff Kirsher mb();
61793f7848bSJeff Kirsher readb(mgp->sram);
61893f7848bSJeff Kirsher }
61993f7848bSJeff Kirsher fw_readback = vmalloc(fw->size);
62093f7848bSJeff Kirsher if (!fw_readback) {
62193f7848bSJeff Kirsher status = -ENOMEM;
62293f7848bSJeff Kirsher goto abort_with_fw;
62393f7848bSJeff Kirsher }
62493f7848bSJeff Kirsher /* corruption checking is good for parity recovery and buggy chipset */
62593f7848bSJeff Kirsher memcpy_fromio(fw_readback, mgp->sram + MYRI10GE_FW_OFFSET, fw->size);
62693f7848bSJeff Kirsher reread_crc = crc32(~0, fw_readback, fw->size);
62793f7848bSJeff Kirsher vfree(fw_readback);
62893f7848bSJeff Kirsher if (crc != reread_crc) {
62993f7848bSJeff Kirsher dev_err(dev, "CRC failed(fw-len=%u), got 0x%x (expect 0x%x)\n",
63093f7848bSJeff Kirsher (unsigned)fw->size, reread_crc, crc);
63193f7848bSJeff Kirsher status = -EIO;
63293f7848bSJeff Kirsher goto abort_with_fw;
63393f7848bSJeff Kirsher }
63493f7848bSJeff Kirsher *size = (u32) fw->size;
63593f7848bSJeff Kirsher
63693f7848bSJeff Kirsher abort_with_fw:
63793f7848bSJeff Kirsher release_firmware(fw);
63893f7848bSJeff Kirsher
63993f7848bSJeff Kirsher abort_with_nothing:
64093f7848bSJeff Kirsher return status;
64193f7848bSJeff Kirsher }
64293f7848bSJeff Kirsher
myri10ge_adopt_running_firmware(struct myri10ge_priv * mgp)64393f7848bSJeff Kirsher static int myri10ge_adopt_running_firmware(struct myri10ge_priv *mgp)
64493f7848bSJeff Kirsher {
64593f7848bSJeff Kirsher struct mcp_gen_header *hdr;
64693f7848bSJeff Kirsher struct device *dev = &mgp->pdev->dev;
64793f7848bSJeff Kirsher const size_t bytes = sizeof(struct mcp_gen_header);
64893f7848bSJeff Kirsher size_t hdr_offset;
64993f7848bSJeff Kirsher int status;
65093f7848bSJeff Kirsher
65193f7848bSJeff Kirsher /* find running firmware header */
65293f7848bSJeff Kirsher hdr_offset = swab32(readl(mgp->sram + MCP_HEADER_PTR_OFFSET));
65393f7848bSJeff Kirsher
65493f7848bSJeff Kirsher if ((hdr_offset & 3) || hdr_offset + sizeof(*hdr) > mgp->sram_size) {
65593f7848bSJeff Kirsher dev_err(dev, "Running firmware has bad header offset (%d)\n",
65693f7848bSJeff Kirsher (int)hdr_offset);
65793f7848bSJeff Kirsher return -EIO;
65893f7848bSJeff Kirsher }
65993f7848bSJeff Kirsher
66093f7848bSJeff Kirsher /* copy header of running firmware from SRAM to host memory to
66193f7848bSJeff Kirsher * validate firmware */
66293f7848bSJeff Kirsher hdr = kmalloc(bytes, GFP_KERNEL);
663b2adaca9SJoe Perches if (hdr == NULL)
66493f7848bSJeff Kirsher return -ENOMEM;
665b2adaca9SJoe Perches
66693f7848bSJeff Kirsher memcpy_fromio(hdr, mgp->sram + hdr_offset, bytes);
66793f7848bSJeff Kirsher status = myri10ge_validate_firmware(mgp, hdr);
66893f7848bSJeff Kirsher kfree(hdr);
66993f7848bSJeff Kirsher
67093f7848bSJeff Kirsher /* check to see if adopted firmware has bug where adopting
67193f7848bSJeff Kirsher * it will cause broadcasts to be filtered unless the NIC
67293f7848bSJeff Kirsher * is kept in ALLMULTI mode */
67393f7848bSJeff Kirsher if (mgp->fw_ver_major == 1 && mgp->fw_ver_minor == 4 &&
67493f7848bSJeff Kirsher mgp->fw_ver_tiny >= 4 && mgp->fw_ver_tiny <= 11) {
67593f7848bSJeff Kirsher mgp->adopted_rx_filter_bug = 1;
67693f7848bSJeff Kirsher dev_warn(dev, "Adopting fw %d.%d.%d: "
67793f7848bSJeff Kirsher "working around rx filter bug\n",
67893f7848bSJeff Kirsher mgp->fw_ver_major, mgp->fw_ver_minor,
67993f7848bSJeff Kirsher mgp->fw_ver_tiny);
68093f7848bSJeff Kirsher }
68193f7848bSJeff Kirsher return status;
68293f7848bSJeff Kirsher }
68393f7848bSJeff Kirsher
myri10ge_get_firmware_capabilities(struct myri10ge_priv * mgp)68493f7848bSJeff Kirsher static int myri10ge_get_firmware_capabilities(struct myri10ge_priv *mgp)
68593f7848bSJeff Kirsher {
68693f7848bSJeff Kirsher struct myri10ge_cmd cmd;
68793f7848bSJeff Kirsher int status;
68893f7848bSJeff Kirsher
68993f7848bSJeff Kirsher /* probe for IPv6 TSO support */
69093f7848bSJeff Kirsher mgp->features = NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_TSO;
69193f7848bSJeff Kirsher status = myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_MAX_TSO6_HDR_SIZE,
69293f7848bSJeff Kirsher &cmd, 0);
69393f7848bSJeff Kirsher if (status == 0) {
69493f7848bSJeff Kirsher mgp->max_tso6 = cmd.data0;
69593f7848bSJeff Kirsher mgp->features |= NETIF_F_TSO6;
69693f7848bSJeff Kirsher }
69793f7848bSJeff Kirsher
69893f7848bSJeff Kirsher status = myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_RX_RING_SIZE, &cmd, 0);
69993f7848bSJeff Kirsher if (status != 0) {
70093f7848bSJeff Kirsher dev_err(&mgp->pdev->dev,
70193f7848bSJeff Kirsher "failed MXGEFW_CMD_GET_RX_RING_SIZE\n");
70293f7848bSJeff Kirsher return -ENXIO;
70393f7848bSJeff Kirsher }
70493f7848bSJeff Kirsher
70593f7848bSJeff Kirsher mgp->max_intr_slots = 2 * (cmd.data0 / sizeof(struct mcp_dma_addr));
70693f7848bSJeff Kirsher
70793f7848bSJeff Kirsher return 0;
70893f7848bSJeff Kirsher }
70993f7848bSJeff Kirsher
myri10ge_load_firmware(struct myri10ge_priv * mgp,int adopt)71093f7848bSJeff Kirsher static int myri10ge_load_firmware(struct myri10ge_priv *mgp, int adopt)
71193f7848bSJeff Kirsher {
71293f7848bSJeff Kirsher char __iomem *submit;
71393f7848bSJeff Kirsher __be32 buf[16] __attribute__ ((__aligned__(8)));
71493f7848bSJeff Kirsher u32 dma_low, dma_high, size;
71593f7848bSJeff Kirsher int status, i;
71693f7848bSJeff Kirsher
71793f7848bSJeff Kirsher size = 0;
71893f7848bSJeff Kirsher status = myri10ge_load_hotplug_firmware(mgp, &size);
71993f7848bSJeff Kirsher if (status) {
72093f7848bSJeff Kirsher if (!adopt)
72193f7848bSJeff Kirsher return status;
72293f7848bSJeff Kirsher dev_warn(&mgp->pdev->dev, "hotplug firmware loading failed\n");
72393f7848bSJeff Kirsher
72493f7848bSJeff Kirsher /* Do not attempt to adopt firmware if there
72593f7848bSJeff Kirsher * was a bad crc */
72693f7848bSJeff Kirsher if (status == -EIO)
72793f7848bSJeff Kirsher return status;
72893f7848bSJeff Kirsher
72993f7848bSJeff Kirsher status = myri10ge_adopt_running_firmware(mgp);
73093f7848bSJeff Kirsher if (status != 0) {
73193f7848bSJeff Kirsher dev_err(&mgp->pdev->dev,
73293f7848bSJeff Kirsher "failed to adopt running firmware\n");
73393f7848bSJeff Kirsher return status;
73493f7848bSJeff Kirsher }
73593f7848bSJeff Kirsher dev_info(&mgp->pdev->dev,
73693f7848bSJeff Kirsher "Successfully adopted running firmware\n");
73793f7848bSJeff Kirsher if (mgp->tx_boundary == 4096) {
73893f7848bSJeff Kirsher dev_warn(&mgp->pdev->dev,
73993f7848bSJeff Kirsher "Using firmware currently running on NIC"
74093f7848bSJeff Kirsher ". For optimal\n");
74193f7848bSJeff Kirsher dev_warn(&mgp->pdev->dev,
74293f7848bSJeff Kirsher "performance consider loading optimized "
74393f7848bSJeff Kirsher "firmware\n");
74493f7848bSJeff Kirsher dev_warn(&mgp->pdev->dev, "via hotplug\n");
74593f7848bSJeff Kirsher }
74693f7848bSJeff Kirsher
74793f7848bSJeff Kirsher set_fw_name(mgp, "adopted", false);
74893f7848bSJeff Kirsher mgp->tx_boundary = 2048;
74993f7848bSJeff Kirsher myri10ge_dummy_rdma(mgp, 1);
75093f7848bSJeff Kirsher status = myri10ge_get_firmware_capabilities(mgp);
75193f7848bSJeff Kirsher return status;
75293f7848bSJeff Kirsher }
75393f7848bSJeff Kirsher
75493f7848bSJeff Kirsher /* clear confirmation addr */
75593f7848bSJeff Kirsher mgp->cmd->data = 0;
75693f7848bSJeff Kirsher mb();
75793f7848bSJeff Kirsher
75893f7848bSJeff Kirsher /* send a reload command to the bootstrap MCP, and wait for the
75993f7848bSJeff Kirsher * response in the confirmation address. The firmware should
76093f7848bSJeff Kirsher * write a -1 there to indicate it is alive and well
76193f7848bSJeff Kirsher */
76293f7848bSJeff Kirsher dma_low = MYRI10GE_LOWPART_TO_U32(mgp->cmd_bus);
76393f7848bSJeff Kirsher dma_high = MYRI10GE_HIGHPART_TO_U32(mgp->cmd_bus);
76493f7848bSJeff Kirsher
76593f7848bSJeff Kirsher buf[0] = htonl(dma_high); /* confirm addr MSW */
76693f7848bSJeff Kirsher buf[1] = htonl(dma_low); /* confirm addr LSW */
76793f7848bSJeff Kirsher buf[2] = MYRI10GE_NO_CONFIRM_DATA; /* confirm data */
76893f7848bSJeff Kirsher
76993f7848bSJeff Kirsher /* FIX: All newest firmware should un-protect the bottom of
77093f7848bSJeff Kirsher * the sram before handoff. However, the very first interfaces
77193f7848bSJeff Kirsher * do not. Therefore the handoff copy must skip the first 8 bytes
77293f7848bSJeff Kirsher */
77393f7848bSJeff Kirsher buf[3] = htonl(MYRI10GE_FW_OFFSET + 8); /* where the code starts */
77493f7848bSJeff Kirsher buf[4] = htonl(size - 8); /* length of code */
77593f7848bSJeff Kirsher buf[5] = htonl(8); /* where to copy to */
77693f7848bSJeff Kirsher buf[6] = htonl(0); /* where to jump to */
77793f7848bSJeff Kirsher
77893f7848bSJeff Kirsher submit = mgp->sram + MXGEFW_BOOT_HANDOFF;
77993f7848bSJeff Kirsher
78093f7848bSJeff Kirsher myri10ge_pio_copy(submit, &buf, sizeof(buf));
78193f7848bSJeff Kirsher mb();
78293f7848bSJeff Kirsher msleep(1);
78393f7848bSJeff Kirsher mb();
78493f7848bSJeff Kirsher i = 0;
78593f7848bSJeff Kirsher while (mgp->cmd->data != MYRI10GE_NO_CONFIRM_DATA && i < 9) {
78693f7848bSJeff Kirsher msleep(1 << i);
78793f7848bSJeff Kirsher i++;
78893f7848bSJeff Kirsher }
78993f7848bSJeff Kirsher if (mgp->cmd->data != MYRI10GE_NO_CONFIRM_DATA) {
79093f7848bSJeff Kirsher dev_err(&mgp->pdev->dev, "handoff failed\n");
79193f7848bSJeff Kirsher return -ENXIO;
79293f7848bSJeff Kirsher }
79393f7848bSJeff Kirsher myri10ge_dummy_rdma(mgp, 1);
79493f7848bSJeff Kirsher status = myri10ge_get_firmware_capabilities(mgp);
79593f7848bSJeff Kirsher
79693f7848bSJeff Kirsher return status;
79793f7848bSJeff Kirsher }
79893f7848bSJeff Kirsher
myri10ge_update_mac_address(struct myri10ge_priv * mgp,const u8 * addr)79976660757SJakub Kicinski static int myri10ge_update_mac_address(struct myri10ge_priv *mgp,
80076660757SJakub Kicinski const u8 * addr)
80193f7848bSJeff Kirsher {
80293f7848bSJeff Kirsher struct myri10ge_cmd cmd;
80393f7848bSJeff Kirsher int status;
80493f7848bSJeff Kirsher
80593f7848bSJeff Kirsher cmd.data0 = ((addr[0] << 24) | (addr[1] << 16)
80693f7848bSJeff Kirsher | (addr[2] << 8) | addr[3]);
80793f7848bSJeff Kirsher
80893f7848bSJeff Kirsher cmd.data1 = ((addr[4] << 8) | (addr[5]));
80993f7848bSJeff Kirsher
81093f7848bSJeff Kirsher status = myri10ge_send_cmd(mgp, MXGEFW_SET_MAC_ADDRESS, &cmd, 0);
81193f7848bSJeff Kirsher return status;
81293f7848bSJeff Kirsher }
81393f7848bSJeff Kirsher
myri10ge_change_pause(struct myri10ge_priv * mgp,int pause)81493f7848bSJeff Kirsher static int myri10ge_change_pause(struct myri10ge_priv *mgp, int pause)
81593f7848bSJeff Kirsher {
81693f7848bSJeff Kirsher struct myri10ge_cmd cmd;
81793f7848bSJeff Kirsher int status, ctl;
81893f7848bSJeff Kirsher
81993f7848bSJeff Kirsher ctl = pause ? MXGEFW_ENABLE_FLOW_CONTROL : MXGEFW_DISABLE_FLOW_CONTROL;
82093f7848bSJeff Kirsher status = myri10ge_send_cmd(mgp, ctl, &cmd, 0);
82193f7848bSJeff Kirsher
82293f7848bSJeff Kirsher if (status) {
82393f7848bSJeff Kirsher netdev_err(mgp->dev, "Failed to set flow control mode\n");
82493f7848bSJeff Kirsher return status;
82593f7848bSJeff Kirsher }
82693f7848bSJeff Kirsher mgp->pause = pause;
82793f7848bSJeff Kirsher return 0;
82893f7848bSJeff Kirsher }
82993f7848bSJeff Kirsher
83093f7848bSJeff Kirsher static void
myri10ge_change_promisc(struct myri10ge_priv * mgp,int promisc,int atomic)83193f7848bSJeff Kirsher myri10ge_change_promisc(struct myri10ge_priv *mgp, int promisc, int atomic)
83293f7848bSJeff Kirsher {
83393f7848bSJeff Kirsher struct myri10ge_cmd cmd;
83493f7848bSJeff Kirsher int status, ctl;
83593f7848bSJeff Kirsher
83693f7848bSJeff Kirsher ctl = promisc ? MXGEFW_ENABLE_PROMISC : MXGEFW_DISABLE_PROMISC;
83793f7848bSJeff Kirsher status = myri10ge_send_cmd(mgp, ctl, &cmd, atomic);
83893f7848bSJeff Kirsher if (status)
83993f7848bSJeff Kirsher netdev_err(mgp->dev, "Failed to set promisc mode\n");
84093f7848bSJeff Kirsher }
84193f7848bSJeff Kirsher
myri10ge_dma_test(struct myri10ge_priv * mgp,int test_type)84293f7848bSJeff Kirsher static int myri10ge_dma_test(struct myri10ge_priv *mgp, int test_type)
84393f7848bSJeff Kirsher {
84493f7848bSJeff Kirsher struct myri10ge_cmd cmd;
84593f7848bSJeff Kirsher int status;
84693f7848bSJeff Kirsher u32 len;
84793f7848bSJeff Kirsher struct page *dmatest_page;
84893f7848bSJeff Kirsher dma_addr_t dmatest_bus;
84993f7848bSJeff Kirsher char *test = " ";
85093f7848bSJeff Kirsher
85193f7848bSJeff Kirsher dmatest_page = alloc_page(GFP_KERNEL);
85293f7848bSJeff Kirsher if (!dmatest_page)
85393f7848bSJeff Kirsher return -ENOMEM;
85475bacb6dSChristophe JAILLET dmatest_bus = dma_map_page(&mgp->pdev->dev, dmatest_page, 0,
85575bacb6dSChristophe JAILLET PAGE_SIZE, DMA_BIDIRECTIONAL);
85675bacb6dSChristophe JAILLET if (unlikely(dma_mapping_error(&mgp->pdev->dev, dmatest_bus))) {
85710545937SStanislaw Gruszka __free_page(dmatest_page);
85810545937SStanislaw Gruszka return -ENOMEM;
85910545937SStanislaw Gruszka }
86093f7848bSJeff Kirsher
86193f7848bSJeff Kirsher /* Run a small DMA test.
86293f7848bSJeff Kirsher * The magic multipliers to the length tell the firmware
86393f7848bSJeff Kirsher * to do DMA read, write, or read+write tests. The
86493f7848bSJeff Kirsher * results are returned in cmd.data0. The upper 16
86593f7848bSJeff Kirsher * bits or the return is the number of transfers completed.
86693f7848bSJeff Kirsher * The lower 16 bits is the time in 0.5us ticks that the
86793f7848bSJeff Kirsher * transfers took to complete.
86893f7848bSJeff Kirsher */
86993f7848bSJeff Kirsher
87093f7848bSJeff Kirsher len = mgp->tx_boundary;
87193f7848bSJeff Kirsher
87293f7848bSJeff Kirsher cmd.data0 = MYRI10GE_LOWPART_TO_U32(dmatest_bus);
87393f7848bSJeff Kirsher cmd.data1 = MYRI10GE_HIGHPART_TO_U32(dmatest_bus);
87493f7848bSJeff Kirsher cmd.data2 = len * 0x10000;
87593f7848bSJeff Kirsher status = myri10ge_send_cmd(mgp, test_type, &cmd, 0);
87693f7848bSJeff Kirsher if (status != 0) {
87793f7848bSJeff Kirsher test = "read";
87893f7848bSJeff Kirsher goto abort;
87993f7848bSJeff Kirsher }
88093f7848bSJeff Kirsher mgp->read_dma = ((cmd.data0 >> 16) * len * 2) / (cmd.data0 & 0xffff);
88193f7848bSJeff Kirsher cmd.data0 = MYRI10GE_LOWPART_TO_U32(dmatest_bus);
88293f7848bSJeff Kirsher cmd.data1 = MYRI10GE_HIGHPART_TO_U32(dmatest_bus);
88393f7848bSJeff Kirsher cmd.data2 = len * 0x1;
88493f7848bSJeff Kirsher status = myri10ge_send_cmd(mgp, test_type, &cmd, 0);
88593f7848bSJeff Kirsher if (status != 0) {
88693f7848bSJeff Kirsher test = "write";
88793f7848bSJeff Kirsher goto abort;
88893f7848bSJeff Kirsher }
88993f7848bSJeff Kirsher mgp->write_dma = ((cmd.data0 >> 16) * len * 2) / (cmd.data0 & 0xffff);
89093f7848bSJeff Kirsher
89193f7848bSJeff Kirsher cmd.data0 = MYRI10GE_LOWPART_TO_U32(dmatest_bus);
89293f7848bSJeff Kirsher cmd.data1 = MYRI10GE_HIGHPART_TO_U32(dmatest_bus);
89393f7848bSJeff Kirsher cmd.data2 = len * 0x10001;
89493f7848bSJeff Kirsher status = myri10ge_send_cmd(mgp, test_type, &cmd, 0);
89593f7848bSJeff Kirsher if (status != 0) {
89693f7848bSJeff Kirsher test = "read/write";
89793f7848bSJeff Kirsher goto abort;
89893f7848bSJeff Kirsher }
89993f7848bSJeff Kirsher mgp->read_write_dma = ((cmd.data0 >> 16) * len * 2 * 2) /
90093f7848bSJeff Kirsher (cmd.data0 & 0xffff);
90193f7848bSJeff Kirsher
90293f7848bSJeff Kirsher abort:
90375bacb6dSChristophe JAILLET dma_unmap_page(&mgp->pdev->dev, dmatest_bus, PAGE_SIZE,
90475bacb6dSChristophe JAILLET DMA_BIDIRECTIONAL);
90593f7848bSJeff Kirsher put_page(dmatest_page);
90693f7848bSJeff Kirsher
90793f7848bSJeff Kirsher if (status != 0 && test_type != MXGEFW_CMD_UNALIGNED_TEST)
90893f7848bSJeff Kirsher dev_warn(&mgp->pdev->dev, "DMA %s benchmark failed: %d\n",
90993f7848bSJeff Kirsher test, status);
91093f7848bSJeff Kirsher
91193f7848bSJeff Kirsher return status;
91293f7848bSJeff Kirsher }
91393f7848bSJeff Kirsher
myri10ge_reset(struct myri10ge_priv * mgp)91493f7848bSJeff Kirsher static int myri10ge_reset(struct myri10ge_priv *mgp)
91593f7848bSJeff Kirsher {
91693f7848bSJeff Kirsher struct myri10ge_cmd cmd;
91793f7848bSJeff Kirsher struct myri10ge_slice_state *ss;
91893f7848bSJeff Kirsher int i, status;
91993f7848bSJeff Kirsher size_t bytes;
92093f7848bSJeff Kirsher #ifdef CONFIG_MYRI10GE_DCA
92193f7848bSJeff Kirsher unsigned long dca_tag_off;
92293f7848bSJeff Kirsher #endif
92393f7848bSJeff Kirsher
92493f7848bSJeff Kirsher /* try to send a reset command to the card to see if it
92593f7848bSJeff Kirsher * is alive */
92693f7848bSJeff Kirsher memset(&cmd, 0, sizeof(cmd));
92793f7848bSJeff Kirsher status = myri10ge_send_cmd(mgp, MXGEFW_CMD_RESET, &cmd, 0);
92893f7848bSJeff Kirsher if (status != 0) {
92993f7848bSJeff Kirsher dev_err(&mgp->pdev->dev, "failed reset\n");
93093f7848bSJeff Kirsher return -ENXIO;
93193f7848bSJeff Kirsher }
93293f7848bSJeff Kirsher
93393f7848bSJeff Kirsher (void)myri10ge_dma_test(mgp, MXGEFW_DMA_TEST);
93493f7848bSJeff Kirsher /*
93593f7848bSJeff Kirsher * Use non-ndis mcp_slot (eg, 4 bytes total,
93693f7848bSJeff Kirsher * no toeplitz hash value returned. Older firmware will
93793f7848bSJeff Kirsher * not understand this command, but will use the correct
93893f7848bSJeff Kirsher * sized mcp_slot, so we ignore error returns
93993f7848bSJeff Kirsher */
94093f7848bSJeff Kirsher cmd.data0 = MXGEFW_RSS_MCP_SLOT_TYPE_MIN;
94193f7848bSJeff Kirsher (void)myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_RSS_MCP_SLOT_TYPE, &cmd, 0);
94293f7848bSJeff Kirsher
94393f7848bSJeff Kirsher /* Now exchange information about interrupts */
94493f7848bSJeff Kirsher
94593f7848bSJeff Kirsher bytes = mgp->max_intr_slots * sizeof(*mgp->ss[0].rx_done.entry);
94693f7848bSJeff Kirsher cmd.data0 = (u32) bytes;
94793f7848bSJeff Kirsher status = myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_INTRQ_SIZE, &cmd, 0);
94893f7848bSJeff Kirsher
94993f7848bSJeff Kirsher /*
95093f7848bSJeff Kirsher * Even though we already know how many slices are supported
95193f7848bSJeff Kirsher * via myri10ge_probe_slices() MXGEFW_CMD_GET_MAX_RSS_QUEUES
95293f7848bSJeff Kirsher * has magic side effects, and must be called after a reset.
95393f7848bSJeff Kirsher * It must be called prior to calling any RSS related cmds,
95493f7848bSJeff Kirsher * including assigning an interrupt queue for anything but
95593f7848bSJeff Kirsher * slice 0. It must also be called *after*
95693f7848bSJeff Kirsher * MXGEFW_CMD_SET_INTRQ_SIZE, since the intrq size is used by
95793f7848bSJeff Kirsher * the firmware to compute offsets.
95893f7848bSJeff Kirsher */
95993f7848bSJeff Kirsher
96093f7848bSJeff Kirsher if (mgp->num_slices > 1) {
96193f7848bSJeff Kirsher
96293f7848bSJeff Kirsher /* ask the maximum number of slices it supports */
96393f7848bSJeff Kirsher status = myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_MAX_RSS_QUEUES,
96493f7848bSJeff Kirsher &cmd, 0);
96593f7848bSJeff Kirsher if (status != 0) {
96693f7848bSJeff Kirsher dev_err(&mgp->pdev->dev,
96793f7848bSJeff Kirsher "failed to get number of slices\n");
96893f7848bSJeff Kirsher }
96993f7848bSJeff Kirsher
97093f7848bSJeff Kirsher /*
97193f7848bSJeff Kirsher * MXGEFW_CMD_ENABLE_RSS_QUEUES must be called prior
97293f7848bSJeff Kirsher * to setting up the interrupt queue DMA
97393f7848bSJeff Kirsher */
97493f7848bSJeff Kirsher
97593f7848bSJeff Kirsher cmd.data0 = mgp->num_slices;
97693f7848bSJeff Kirsher cmd.data1 = MXGEFW_SLICE_INTR_MODE_ONE_PER_SLICE;
97793f7848bSJeff Kirsher if (mgp->dev->real_num_tx_queues > 1)
97893f7848bSJeff Kirsher cmd.data1 |= MXGEFW_SLICE_ENABLE_MULTIPLE_TX_QUEUES;
97993f7848bSJeff Kirsher status = myri10ge_send_cmd(mgp, MXGEFW_CMD_ENABLE_RSS_QUEUES,
98093f7848bSJeff Kirsher &cmd, 0);
98193f7848bSJeff Kirsher
98293f7848bSJeff Kirsher /* Firmware older than 1.4.32 only supports multiple
98393f7848bSJeff Kirsher * RX queues, so if we get an error, first retry using a
98493f7848bSJeff Kirsher * single TX queue before giving up */
98593f7848bSJeff Kirsher if (status != 0 && mgp->dev->real_num_tx_queues > 1) {
98693f7848bSJeff Kirsher netif_set_real_num_tx_queues(mgp->dev, 1);
98793f7848bSJeff Kirsher cmd.data0 = mgp->num_slices;
98893f7848bSJeff Kirsher cmd.data1 = MXGEFW_SLICE_INTR_MODE_ONE_PER_SLICE;
98993f7848bSJeff Kirsher status = myri10ge_send_cmd(mgp,
99093f7848bSJeff Kirsher MXGEFW_CMD_ENABLE_RSS_QUEUES,
99193f7848bSJeff Kirsher &cmd, 0);
99293f7848bSJeff Kirsher }
99393f7848bSJeff Kirsher
99493f7848bSJeff Kirsher if (status != 0) {
99593f7848bSJeff Kirsher dev_err(&mgp->pdev->dev,
99693f7848bSJeff Kirsher "failed to set number of slices\n");
99793f7848bSJeff Kirsher
99893f7848bSJeff Kirsher return status;
99993f7848bSJeff Kirsher }
100093f7848bSJeff Kirsher }
100193f7848bSJeff Kirsher for (i = 0; i < mgp->num_slices; i++) {
100293f7848bSJeff Kirsher ss = &mgp->ss[i];
100393f7848bSJeff Kirsher cmd.data0 = MYRI10GE_LOWPART_TO_U32(ss->rx_done.bus);
100493f7848bSJeff Kirsher cmd.data1 = MYRI10GE_HIGHPART_TO_U32(ss->rx_done.bus);
100593f7848bSJeff Kirsher cmd.data2 = i;
100693f7848bSJeff Kirsher status |= myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_INTRQ_DMA,
100793f7848bSJeff Kirsher &cmd, 0);
100893f7848bSJeff Kirsher }
100993f7848bSJeff Kirsher
101093f7848bSJeff Kirsher status |=
101193f7848bSJeff Kirsher myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_IRQ_ACK_OFFSET, &cmd, 0);
101293f7848bSJeff Kirsher for (i = 0; i < mgp->num_slices; i++) {
101393f7848bSJeff Kirsher ss = &mgp->ss[i];
101493f7848bSJeff Kirsher ss->irq_claim =
101593f7848bSJeff Kirsher (__iomem __be32 *) (mgp->sram + cmd.data0 + 8 * i);
101693f7848bSJeff Kirsher }
101793f7848bSJeff Kirsher status |= myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_IRQ_DEASSERT_OFFSET,
101893f7848bSJeff Kirsher &cmd, 0);
101993f7848bSJeff Kirsher mgp->irq_deassert = (__iomem __be32 *) (mgp->sram + cmd.data0);
102093f7848bSJeff Kirsher
102193f7848bSJeff Kirsher status |= myri10ge_send_cmd
102293f7848bSJeff Kirsher (mgp, MXGEFW_CMD_GET_INTR_COAL_DELAY_OFFSET, &cmd, 0);
102393f7848bSJeff Kirsher mgp->intr_coal_delay_ptr = (__iomem __be32 *) (mgp->sram + cmd.data0);
102493f7848bSJeff Kirsher if (status != 0) {
102593f7848bSJeff Kirsher dev_err(&mgp->pdev->dev, "failed set interrupt parameters\n");
102693f7848bSJeff Kirsher return status;
102793f7848bSJeff Kirsher }
102893f7848bSJeff Kirsher put_be32(htonl(mgp->intr_coal_delay), mgp->intr_coal_delay_ptr);
102993f7848bSJeff Kirsher
103093f7848bSJeff Kirsher #ifdef CONFIG_MYRI10GE_DCA
103193f7848bSJeff Kirsher status = myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_DCA_OFFSET, &cmd, 0);
103293f7848bSJeff Kirsher dca_tag_off = cmd.data0;
103393f7848bSJeff Kirsher for (i = 0; i < mgp->num_slices; i++) {
103493f7848bSJeff Kirsher ss = &mgp->ss[i];
103593f7848bSJeff Kirsher if (status == 0) {
103693f7848bSJeff Kirsher ss->dca_tag = (__iomem __be32 *)
103793f7848bSJeff Kirsher (mgp->sram + dca_tag_off + 4 * i);
103893f7848bSJeff Kirsher } else {
103993f7848bSJeff Kirsher ss->dca_tag = NULL;
104093f7848bSJeff Kirsher }
104193f7848bSJeff Kirsher }
104293f7848bSJeff Kirsher #endif /* CONFIG_MYRI10GE_DCA */
104393f7848bSJeff Kirsher
104493f7848bSJeff Kirsher /* reset mcp/driver shared state back to 0 */
104593f7848bSJeff Kirsher
104693f7848bSJeff Kirsher mgp->link_changes = 0;
104793f7848bSJeff Kirsher for (i = 0; i < mgp->num_slices; i++) {
104893f7848bSJeff Kirsher ss = &mgp->ss[i];
104993f7848bSJeff Kirsher
105093f7848bSJeff Kirsher memset(ss->rx_done.entry, 0, bytes);
105193f7848bSJeff Kirsher ss->tx.req = 0;
105293f7848bSJeff Kirsher ss->tx.done = 0;
105393f7848bSJeff Kirsher ss->tx.pkt_start = 0;
105493f7848bSJeff Kirsher ss->tx.pkt_done = 0;
105593f7848bSJeff Kirsher ss->rx_big.cnt = 0;
105693f7848bSJeff Kirsher ss->rx_small.cnt = 0;
105793f7848bSJeff Kirsher ss->rx_done.idx = 0;
105893f7848bSJeff Kirsher ss->rx_done.cnt = 0;
105993f7848bSJeff Kirsher ss->tx.wake_queue = 0;
106093f7848bSJeff Kirsher ss->tx.stop_queue = 0;
106193f7848bSJeff Kirsher }
106293f7848bSJeff Kirsher
106393f7848bSJeff Kirsher status = myri10ge_update_mac_address(mgp, mgp->dev->dev_addr);
106493f7848bSJeff Kirsher myri10ge_change_pause(mgp, mgp->pause);
106593f7848bSJeff Kirsher myri10ge_set_multicast_list(mgp->dev);
106693f7848bSJeff Kirsher return status;
106793f7848bSJeff Kirsher }
106893f7848bSJeff Kirsher
106993f7848bSJeff Kirsher #ifdef CONFIG_MYRI10GE_DCA
myri10ge_toggle_relaxed(struct pci_dev * pdev,int on)107093f7848bSJeff Kirsher static int myri10ge_toggle_relaxed(struct pci_dev *pdev, int on)
107193f7848bSJeff Kirsher {
10729503e255SJiang Liu int ret;
107393f7848bSJeff Kirsher u16 ctl;
107493f7848bSJeff Kirsher
10759503e255SJiang Liu pcie_capability_read_word(pdev, PCI_EXP_DEVCTL, &ctl);
107693f7848bSJeff Kirsher
107793f7848bSJeff Kirsher ret = (ctl & PCI_EXP_DEVCTL_RELAX_EN) >> 4;
107893f7848bSJeff Kirsher if (ret != on) {
107993f7848bSJeff Kirsher ctl &= ~PCI_EXP_DEVCTL_RELAX_EN;
108093f7848bSJeff Kirsher ctl |= (on << 4);
10819503e255SJiang Liu pcie_capability_write_word(pdev, PCI_EXP_DEVCTL, ctl);
108293f7848bSJeff Kirsher }
108393f7848bSJeff Kirsher return ret;
108493f7848bSJeff Kirsher }
108593f7848bSJeff Kirsher
108693f7848bSJeff Kirsher static void
myri10ge_write_dca(struct myri10ge_slice_state * ss,int cpu,int tag)108793f7848bSJeff Kirsher myri10ge_write_dca(struct myri10ge_slice_state *ss, int cpu, int tag)
108893f7848bSJeff Kirsher {
108993f7848bSJeff Kirsher ss->cached_dca_tag = tag;
109093f7848bSJeff Kirsher put_be32(htonl(tag), ss->dca_tag);
109193f7848bSJeff Kirsher }
109293f7848bSJeff Kirsher
myri10ge_update_dca(struct myri10ge_slice_state * ss)109393f7848bSJeff Kirsher static inline void myri10ge_update_dca(struct myri10ge_slice_state *ss)
109493f7848bSJeff Kirsher {
109593f7848bSJeff Kirsher int cpu = get_cpu();
109693f7848bSJeff Kirsher int tag;
109793f7848bSJeff Kirsher
109893f7848bSJeff Kirsher if (cpu != ss->cpu) {
109993f7848bSJeff Kirsher tag = dca3_get_tag(&ss->mgp->pdev->dev, cpu);
110093f7848bSJeff Kirsher if (ss->cached_dca_tag != tag)
110193f7848bSJeff Kirsher myri10ge_write_dca(ss, cpu, tag);
110293f7848bSJeff Kirsher ss->cpu = cpu;
110393f7848bSJeff Kirsher }
110493f7848bSJeff Kirsher put_cpu();
110593f7848bSJeff Kirsher }
110693f7848bSJeff Kirsher
myri10ge_setup_dca(struct myri10ge_priv * mgp)110793f7848bSJeff Kirsher static void myri10ge_setup_dca(struct myri10ge_priv *mgp)
110893f7848bSJeff Kirsher {
110993f7848bSJeff Kirsher int err, i;
111093f7848bSJeff Kirsher struct pci_dev *pdev = mgp->pdev;
111193f7848bSJeff Kirsher
111293f7848bSJeff Kirsher if (mgp->ss[0].dca_tag == NULL || mgp->dca_enabled)
111393f7848bSJeff Kirsher return;
111493f7848bSJeff Kirsher if (!myri10ge_dca) {
111593f7848bSJeff Kirsher dev_err(&pdev->dev, "dca disabled by administrator\n");
111693f7848bSJeff Kirsher return;
111793f7848bSJeff Kirsher }
111893f7848bSJeff Kirsher err = dca_add_requester(&pdev->dev);
111993f7848bSJeff Kirsher if (err) {
112093f7848bSJeff Kirsher if (err != -ENODEV)
112193f7848bSJeff Kirsher dev_err(&pdev->dev,
112293f7848bSJeff Kirsher "dca_add_requester() failed, err=%d\n", err);
112393f7848bSJeff Kirsher return;
112493f7848bSJeff Kirsher }
112593f7848bSJeff Kirsher mgp->relaxed_order = myri10ge_toggle_relaxed(pdev, 0);
112693f7848bSJeff Kirsher mgp->dca_enabled = 1;
112793f7848bSJeff Kirsher for (i = 0; i < mgp->num_slices; i++) {
112893f7848bSJeff Kirsher mgp->ss[i].cpu = -1;
112993f7848bSJeff Kirsher mgp->ss[i].cached_dca_tag = -1;
113093f7848bSJeff Kirsher myri10ge_update_dca(&mgp->ss[i]);
113193f7848bSJeff Kirsher }
113293f7848bSJeff Kirsher }
113393f7848bSJeff Kirsher
myri10ge_teardown_dca(struct myri10ge_priv * mgp)113493f7848bSJeff Kirsher static void myri10ge_teardown_dca(struct myri10ge_priv *mgp)
113593f7848bSJeff Kirsher {
113693f7848bSJeff Kirsher struct pci_dev *pdev = mgp->pdev;
113793f7848bSJeff Kirsher
113893f7848bSJeff Kirsher if (!mgp->dca_enabled)
113993f7848bSJeff Kirsher return;
114093f7848bSJeff Kirsher mgp->dca_enabled = 0;
114193f7848bSJeff Kirsher if (mgp->relaxed_order)
114293f7848bSJeff Kirsher myri10ge_toggle_relaxed(pdev, 1);
114393f7848bSJeff Kirsher dca_remove_requester(&pdev->dev);
114493f7848bSJeff Kirsher }
114593f7848bSJeff Kirsher
myri10ge_notify_dca_device(struct device * dev,void * data)114693f7848bSJeff Kirsher static int myri10ge_notify_dca_device(struct device *dev, void *data)
114793f7848bSJeff Kirsher {
114893f7848bSJeff Kirsher struct myri10ge_priv *mgp;
114993f7848bSJeff Kirsher unsigned long event;
115093f7848bSJeff Kirsher
115193f7848bSJeff Kirsher mgp = dev_get_drvdata(dev);
115293f7848bSJeff Kirsher event = *(unsigned long *)data;
115393f7848bSJeff Kirsher
115493f7848bSJeff Kirsher if (event == DCA_PROVIDER_ADD)
115593f7848bSJeff Kirsher myri10ge_setup_dca(mgp);
115693f7848bSJeff Kirsher else if (event == DCA_PROVIDER_REMOVE)
115793f7848bSJeff Kirsher myri10ge_teardown_dca(mgp);
115893f7848bSJeff Kirsher return 0;
115993f7848bSJeff Kirsher }
116093f7848bSJeff Kirsher #endif /* CONFIG_MYRI10GE_DCA */
116193f7848bSJeff Kirsher
116293f7848bSJeff Kirsher static inline void
myri10ge_submit_8rx(struct mcp_kreq_ether_recv __iomem * dst,struct mcp_kreq_ether_recv * src)116393f7848bSJeff Kirsher myri10ge_submit_8rx(struct mcp_kreq_ether_recv __iomem * dst,
116493f7848bSJeff Kirsher struct mcp_kreq_ether_recv *src)
116593f7848bSJeff Kirsher {
116693f7848bSJeff Kirsher __be32 low;
116793f7848bSJeff Kirsher
116893f7848bSJeff Kirsher low = src->addr_low;
116993f7848bSJeff Kirsher src->addr_low = htonl(DMA_BIT_MASK(32));
117093f7848bSJeff Kirsher myri10ge_pio_copy(dst, src, 4 * sizeof(*src));
117193f7848bSJeff Kirsher mb();
117293f7848bSJeff Kirsher myri10ge_pio_copy(dst + 4, src + 4, 4 * sizeof(*src));
117393f7848bSJeff Kirsher mb();
117493f7848bSJeff Kirsher src->addr_low = low;
117593f7848bSJeff Kirsher put_be32(low, &dst->addr_low);
117693f7848bSJeff Kirsher mb();
117793f7848bSJeff Kirsher }
117893f7848bSJeff Kirsher
117993f7848bSJeff Kirsher static void
myri10ge_alloc_rx_pages(struct myri10ge_priv * mgp,struct myri10ge_rx_buf * rx,int bytes,int watchdog)118093f7848bSJeff Kirsher myri10ge_alloc_rx_pages(struct myri10ge_priv *mgp, struct myri10ge_rx_buf *rx,
118193f7848bSJeff Kirsher int bytes, int watchdog)
118293f7848bSJeff Kirsher {
118393f7848bSJeff Kirsher struct page *page;
118410545937SStanislaw Gruszka dma_addr_t bus;
118593f7848bSJeff Kirsher int idx;
118693f7848bSJeff Kirsher #if MYRI10GE_ALLOC_SIZE > 4096
118793f7848bSJeff Kirsher int end_offset;
118893f7848bSJeff Kirsher #endif
118993f7848bSJeff Kirsher
119093f7848bSJeff Kirsher if (unlikely(rx->watchdog_needed && !watchdog))
119193f7848bSJeff Kirsher return;
119293f7848bSJeff Kirsher
119393f7848bSJeff Kirsher /* try to refill entire ring */
119493f7848bSJeff Kirsher while (rx->fill_cnt != (rx->cnt + rx->mask + 1)) {
119593f7848bSJeff Kirsher idx = rx->fill_cnt & rx->mask;
119693f7848bSJeff Kirsher if (rx->page_offset + bytes <= MYRI10GE_ALLOC_SIZE) {
119793f7848bSJeff Kirsher /* we can use part of previous page */
119893f7848bSJeff Kirsher get_page(rx->page);
119993f7848bSJeff Kirsher } else {
120093f7848bSJeff Kirsher /* we need a new page */
120193f7848bSJeff Kirsher page =
120293f7848bSJeff Kirsher alloc_pages(GFP_ATOMIC | __GFP_COMP,
120393f7848bSJeff Kirsher MYRI10GE_ALLOC_ORDER);
120493f7848bSJeff Kirsher if (unlikely(page == NULL)) {
120593f7848bSJeff Kirsher if (rx->fill_cnt - rx->cnt < 16)
120693f7848bSJeff Kirsher rx->watchdog_needed = 1;
120793f7848bSJeff Kirsher return;
120893f7848bSJeff Kirsher }
120910545937SStanislaw Gruszka
121075bacb6dSChristophe JAILLET bus = dma_map_page(&mgp->pdev->dev, page, 0,
121193f7848bSJeff Kirsher MYRI10GE_ALLOC_SIZE,
121275bacb6dSChristophe JAILLET DMA_FROM_DEVICE);
121375bacb6dSChristophe JAILLET if (unlikely(dma_mapping_error(&mgp->pdev->dev, bus))) {
121410545937SStanislaw Gruszka __free_pages(page, MYRI10GE_ALLOC_ORDER);
121510545937SStanislaw Gruszka if (rx->fill_cnt - rx->cnt < 16)
121610545937SStanislaw Gruszka rx->watchdog_needed = 1;
121710545937SStanislaw Gruszka return;
121810545937SStanislaw Gruszka }
121910545937SStanislaw Gruszka
122010545937SStanislaw Gruszka rx->page = page;
122110545937SStanislaw Gruszka rx->page_offset = 0;
122210545937SStanislaw Gruszka rx->bus = bus;
122310545937SStanislaw Gruszka
122493f7848bSJeff Kirsher }
122593f7848bSJeff Kirsher rx->info[idx].page = rx->page;
122693f7848bSJeff Kirsher rx->info[idx].page_offset = rx->page_offset;
122793f7848bSJeff Kirsher /* note that this is the address of the start of the
122893f7848bSJeff Kirsher * page */
122993f7848bSJeff Kirsher dma_unmap_addr_set(&rx->info[idx], bus, rx->bus);
123093f7848bSJeff Kirsher rx->shadow[idx].addr_low =
123193f7848bSJeff Kirsher htonl(MYRI10GE_LOWPART_TO_U32(rx->bus) + rx->page_offset);
123293f7848bSJeff Kirsher rx->shadow[idx].addr_high =
123393f7848bSJeff Kirsher htonl(MYRI10GE_HIGHPART_TO_U32(rx->bus));
123493f7848bSJeff Kirsher
123593f7848bSJeff Kirsher /* start next packet on a cacheline boundary */
123693f7848bSJeff Kirsher rx->page_offset += SKB_DATA_ALIGN(bytes);
123793f7848bSJeff Kirsher
123893f7848bSJeff Kirsher #if MYRI10GE_ALLOC_SIZE > 4096
123993f7848bSJeff Kirsher /* don't cross a 4KB boundary */
124093f7848bSJeff Kirsher end_offset = rx->page_offset + bytes - 1;
124193f7848bSJeff Kirsher if ((unsigned)(rx->page_offset ^ end_offset) > 4095)
124293f7848bSJeff Kirsher rx->page_offset = end_offset & ~4095;
124393f7848bSJeff Kirsher #endif
124493f7848bSJeff Kirsher rx->fill_cnt++;
124593f7848bSJeff Kirsher
124693f7848bSJeff Kirsher /* copy 8 descriptors to the firmware at a time */
124793f7848bSJeff Kirsher if ((idx & 7) == 7) {
124893f7848bSJeff Kirsher myri10ge_submit_8rx(&rx->lanai[idx - 7],
124993f7848bSJeff Kirsher &rx->shadow[idx - 7]);
125093f7848bSJeff Kirsher }
125193f7848bSJeff Kirsher }
125293f7848bSJeff Kirsher }
125393f7848bSJeff Kirsher
125493f7848bSJeff Kirsher static inline void
myri10ge_unmap_rx_page(struct pci_dev * pdev,struct myri10ge_rx_buffer_state * info,int bytes)125593f7848bSJeff Kirsher myri10ge_unmap_rx_page(struct pci_dev *pdev,
125693f7848bSJeff Kirsher struct myri10ge_rx_buffer_state *info, int bytes)
125793f7848bSJeff Kirsher {
125893f7848bSJeff Kirsher /* unmap the recvd page if we're the only or last user of it */
125993f7848bSJeff Kirsher if (bytes >= MYRI10GE_ALLOC_SIZE / 2 ||
126093f7848bSJeff Kirsher (info->page_offset + 2 * bytes) > MYRI10GE_ALLOC_SIZE) {
126175bacb6dSChristophe JAILLET dma_unmap_page(&pdev->dev, (dma_unmap_addr(info, bus)
126293f7848bSJeff Kirsher & ~(MYRI10GE_ALLOC_SIZE - 1)),
126375bacb6dSChristophe JAILLET MYRI10GE_ALLOC_SIZE, DMA_FROM_DEVICE);
126493f7848bSJeff Kirsher }
126593f7848bSJeff Kirsher }
126693f7848bSJeff Kirsher
12671b4c44e6SAndrew Gallatin /*
12681b4c44e6SAndrew Gallatin * GRO does not support acceleration of tagged vlan frames, and
12691b4c44e6SAndrew Gallatin * this NIC does not support vlan tag offload, so we must pop
12701b4c44e6SAndrew Gallatin * the tag ourselves to be able to achieve GRO performance that
12711b4c44e6SAndrew Gallatin * is comparable to LRO.
12721b4c44e6SAndrew Gallatin */
12731b4c44e6SAndrew Gallatin
12741b4c44e6SAndrew Gallatin static inline void
myri10ge_vlan_rx(struct net_device * dev,void * addr,struct sk_buff * skb)12751b4c44e6SAndrew Gallatin myri10ge_vlan_rx(struct net_device *dev, void *addr, struct sk_buff *skb)
12761b4c44e6SAndrew Gallatin {
12771b4c44e6SAndrew Gallatin u8 *va;
12781b4c44e6SAndrew Gallatin struct vlan_ethhdr *veh;
1279d7840976SMatthew Wilcox (Oracle) skb_frag_t *frag;
12801b4c44e6SAndrew Gallatin __wsum vsum;
12811b4c44e6SAndrew Gallatin
12821b4c44e6SAndrew Gallatin va = addr;
12831b4c44e6SAndrew Gallatin va += MXGEFW_PAD;
12841b4c44e6SAndrew Gallatin veh = (struct vlan_ethhdr *)va;
1285f646968fSPatrick McHardy if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) ==
1286f646968fSPatrick McHardy NETIF_F_HW_VLAN_CTAG_RX &&
128730828d2bSAndrew Gallatin veh->h_vlan_proto == htons(ETH_P_8021Q)) {
12881b4c44e6SAndrew Gallatin /* fixup csum if needed */
12891b4c44e6SAndrew Gallatin if (skb->ip_summed == CHECKSUM_COMPLETE) {
12901b4c44e6SAndrew Gallatin vsum = csum_partial(va + ETH_HLEN, VLAN_HLEN, 0);
12911b4c44e6SAndrew Gallatin skb->csum = csum_sub(skb->csum, vsum);
12921b4c44e6SAndrew Gallatin }
12931b4c44e6SAndrew Gallatin /* pop tag */
129486a9bad3SPatrick McHardy __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), ntohs(veh->h_vlan_TCI));
12951b4c44e6SAndrew Gallatin memmove(va + VLAN_HLEN, va, 2 * ETH_ALEN);
12961b4c44e6SAndrew Gallatin skb->len -= VLAN_HLEN;
12971b4c44e6SAndrew Gallatin skb->data_len -= VLAN_HLEN;
12981b4c44e6SAndrew Gallatin frag = skb_shinfo(skb)->frags;
1299b54c9d5bSJonathan Lemon skb_frag_off_add(frag, VLAN_HLEN);
1300b54c9d5bSJonathan Lemon skb_frag_size_sub(frag, VLAN_HLEN);
13011b4c44e6SAndrew Gallatin }
13021b4c44e6SAndrew Gallatin }
13031b4c44e6SAndrew Gallatin
13040dde8026SHyong-Youb Kim #define MYRI10GE_HLEN 64 /* Bytes to copy from page to skb linear memory */
13050dde8026SHyong-Youb Kim
130693f7848bSJeff Kirsher static inline int
myri10ge_rx_done(struct myri10ge_slice_state * ss,int len,__wsum csum)13074ca3221fSAndrew Gallatin myri10ge_rx_done(struct myri10ge_slice_state *ss, int len, __wsum csum)
130893f7848bSJeff Kirsher {
130993f7848bSJeff Kirsher struct myri10ge_priv *mgp = ss->mgp;
131093f7848bSJeff Kirsher struct sk_buff *skb;
1311d7840976SMatthew Wilcox (Oracle) skb_frag_t *rx_frags;
131293f7848bSJeff Kirsher struct myri10ge_rx_buf *rx;
13134ca3221fSAndrew Gallatin int i, idx, remainder, bytes;
131493f7848bSJeff Kirsher struct pci_dev *pdev = mgp->pdev;
131593f7848bSJeff Kirsher struct net_device *dev = mgp->dev;
131693f7848bSJeff Kirsher u8 *va;
131793f7848bSJeff Kirsher
131893f7848bSJeff Kirsher if (len <= mgp->small_bytes) {
131993f7848bSJeff Kirsher rx = &ss->rx_small;
132093f7848bSJeff Kirsher bytes = mgp->small_bytes;
132193f7848bSJeff Kirsher } else {
132293f7848bSJeff Kirsher rx = &ss->rx_big;
132393f7848bSJeff Kirsher bytes = mgp->big_bytes;
132493f7848bSJeff Kirsher }
132593f7848bSJeff Kirsher
132693f7848bSJeff Kirsher len += MXGEFW_PAD;
132793f7848bSJeff Kirsher idx = rx->cnt & rx->mask;
132893f7848bSJeff Kirsher va = page_address(rx->info[idx].page) + rx->info[idx].page_offset;
132993f7848bSJeff Kirsher prefetch(va);
13304ca3221fSAndrew Gallatin
13314ca3221fSAndrew Gallatin skb = napi_get_frags(&ss->napi);
13324ca3221fSAndrew Gallatin if (unlikely(skb == NULL)) {
13334ca3221fSAndrew Gallatin ss->stats.rx_dropped++;
13344ca3221fSAndrew Gallatin for (i = 0, remainder = len; remainder > 0; i++) {
13354ca3221fSAndrew Gallatin myri10ge_unmap_rx_page(pdev, &rx->info[idx], bytes);
13364ca3221fSAndrew Gallatin put_page(rx->info[idx].page);
13374ca3221fSAndrew Gallatin rx->cnt++;
13384ca3221fSAndrew Gallatin idx = rx->cnt & rx->mask;
13394ca3221fSAndrew Gallatin remainder -= MYRI10GE_ALLOC_SIZE;
13404ca3221fSAndrew Gallatin }
13414ca3221fSAndrew Gallatin return 0;
13424ca3221fSAndrew Gallatin }
13434ca3221fSAndrew Gallatin rx_frags = skb_shinfo(skb)->frags;
1344d7840976SMatthew Wilcox (Oracle) /* Fill skb_frag_t(s) with data from our receive */
134593f7848bSJeff Kirsher for (i = 0, remainder = len; remainder > 0; i++) {
134693f7848bSJeff Kirsher myri10ge_unmap_rx_page(pdev, &rx->info[idx], bytes);
13474ca3221fSAndrew Gallatin skb_fill_page_desc(skb, i, rx->info[idx].page,
13484ca3221fSAndrew Gallatin rx->info[idx].page_offset,
13494ca3221fSAndrew Gallatin remainder < MYRI10GE_ALLOC_SIZE ?
13504ca3221fSAndrew Gallatin remainder : MYRI10GE_ALLOC_SIZE);
135193f7848bSJeff Kirsher rx->cnt++;
135293f7848bSJeff Kirsher idx = rx->cnt & rx->mask;
135393f7848bSJeff Kirsher remainder -= MYRI10GE_ALLOC_SIZE;
135493f7848bSJeff Kirsher }
135593f7848bSJeff Kirsher
13564ca3221fSAndrew Gallatin /* remove padding */
1357b54c9d5bSJonathan Lemon skb_frag_off_add(&rx_frags[0], MXGEFW_PAD);
1358d7840976SMatthew Wilcox (Oracle) skb_frag_size_sub(&rx_frags[0], MXGEFW_PAD);
135993f7848bSJeff Kirsher len -= MXGEFW_PAD;
136093f7848bSJeff Kirsher
13614ca3221fSAndrew Gallatin skb->len = len;
13624ca3221fSAndrew Gallatin skb->data_len = len;
13634ca3221fSAndrew Gallatin skb->truesize += len;
13644ca3221fSAndrew Gallatin if (dev->features & NETIF_F_RXCSUM) {
13654ca3221fSAndrew Gallatin skb->ip_summed = CHECKSUM_COMPLETE;
13664ca3221fSAndrew Gallatin skb->csum = csum;
136793f7848bSJeff Kirsher }
13681b4c44e6SAndrew Gallatin myri10ge_vlan_rx(mgp->dev, va, skb);
136993f7848bSJeff Kirsher skb_record_rx_queue(skb, ss - &mgp->ss[0]);
137093f7848bSJeff Kirsher
13714ca3221fSAndrew Gallatin napi_gro_frags(&ss->napi);
13720dde8026SHyong-Youb Kim
137393f7848bSJeff Kirsher return 1;
137493f7848bSJeff Kirsher }
137593f7848bSJeff Kirsher
137693f7848bSJeff Kirsher static inline void
myri10ge_tx_done(struct myri10ge_slice_state * ss,int mcp_index)137793f7848bSJeff Kirsher myri10ge_tx_done(struct myri10ge_slice_state *ss, int mcp_index)
137893f7848bSJeff Kirsher {
137993f7848bSJeff Kirsher struct pci_dev *pdev = ss->mgp->pdev;
138093f7848bSJeff Kirsher struct myri10ge_tx_buf *tx = &ss->tx;
138193f7848bSJeff Kirsher struct netdev_queue *dev_queue;
138293f7848bSJeff Kirsher struct sk_buff *skb;
138393f7848bSJeff Kirsher int idx, len;
138493f7848bSJeff Kirsher
138593f7848bSJeff Kirsher while (tx->pkt_done != mcp_index) {
138693f7848bSJeff Kirsher idx = tx->done & tx->mask;
138793f7848bSJeff Kirsher skb = tx->info[idx].skb;
138893f7848bSJeff Kirsher
138993f7848bSJeff Kirsher /* Mark as free */
139093f7848bSJeff Kirsher tx->info[idx].skb = NULL;
139193f7848bSJeff Kirsher if (tx->info[idx].last) {
139293f7848bSJeff Kirsher tx->pkt_done++;
139393f7848bSJeff Kirsher tx->info[idx].last = 0;
139493f7848bSJeff Kirsher }
139593f7848bSJeff Kirsher tx->done++;
139693f7848bSJeff Kirsher len = dma_unmap_len(&tx->info[idx], len);
139793f7848bSJeff Kirsher dma_unmap_len_set(&tx->info[idx], len, 0);
139893f7848bSJeff Kirsher if (skb) {
139993f7848bSJeff Kirsher ss->stats.tx_bytes += skb->len;
140093f7848bSJeff Kirsher ss->stats.tx_packets++;
14015fbc136bSYang Wei dev_consume_skb_irq(skb);
140293f7848bSJeff Kirsher if (len)
140375bacb6dSChristophe JAILLET dma_unmap_single(&pdev->dev,
140493f7848bSJeff Kirsher dma_unmap_addr(&tx->info[idx],
140593f7848bSJeff Kirsher bus), len,
140675bacb6dSChristophe JAILLET DMA_TO_DEVICE);
140793f7848bSJeff Kirsher } else {
140893f7848bSJeff Kirsher if (len)
140975bacb6dSChristophe JAILLET dma_unmap_page(&pdev->dev,
141093f7848bSJeff Kirsher dma_unmap_addr(&tx->info[idx],
141193f7848bSJeff Kirsher bus), len,
141275bacb6dSChristophe JAILLET DMA_TO_DEVICE);
141393f7848bSJeff Kirsher }
141493f7848bSJeff Kirsher }
141593f7848bSJeff Kirsher
141693f7848bSJeff Kirsher dev_queue = netdev_get_tx_queue(ss->dev, ss - ss->mgp->ss);
141793f7848bSJeff Kirsher /*
141893f7848bSJeff Kirsher * Make a minimal effort to prevent the NIC from polling an
141993f7848bSJeff Kirsher * idle tx queue. If we can't get the lock we leave the queue
142093f7848bSJeff Kirsher * active. In this case, either a thread was about to start
142193f7848bSJeff Kirsher * using the queue anyway, or we lost a race and the NIC will
142293f7848bSJeff Kirsher * waste some of its resources polling an inactive queue for a
142393f7848bSJeff Kirsher * while.
142493f7848bSJeff Kirsher */
142593f7848bSJeff Kirsher
142693f7848bSJeff Kirsher if ((ss->mgp->dev->real_num_tx_queues > 1) &&
142793f7848bSJeff Kirsher __netif_tx_trylock(dev_queue)) {
142893f7848bSJeff Kirsher if (tx->req == tx->done) {
142993f7848bSJeff Kirsher tx->queue_active = 0;
143093f7848bSJeff Kirsher put_be32(htonl(1), tx->send_stop);
143193f7848bSJeff Kirsher mb();
143293f7848bSJeff Kirsher }
143393f7848bSJeff Kirsher __netif_tx_unlock(dev_queue);
143493f7848bSJeff Kirsher }
143593f7848bSJeff Kirsher
143693f7848bSJeff Kirsher /* start the queue if we've stopped it */
143793f7848bSJeff Kirsher if (netif_tx_queue_stopped(dev_queue) &&
143893f7848bSJeff Kirsher tx->req - tx->done < (tx->mask >> 1) &&
143993f7848bSJeff Kirsher ss->mgp->running == MYRI10GE_ETH_RUNNING) {
144093f7848bSJeff Kirsher tx->wake_queue++;
144193f7848bSJeff Kirsher netif_tx_wake_queue(dev_queue);
144293f7848bSJeff Kirsher }
144393f7848bSJeff Kirsher }
144493f7848bSJeff Kirsher
144593f7848bSJeff Kirsher static inline int
myri10ge_clean_rx_done(struct myri10ge_slice_state * ss,int budget)144693f7848bSJeff Kirsher myri10ge_clean_rx_done(struct myri10ge_slice_state *ss, int budget)
144793f7848bSJeff Kirsher {
144893f7848bSJeff Kirsher struct myri10ge_rx_done *rx_done = &ss->rx_done;
144993f7848bSJeff Kirsher struct myri10ge_priv *mgp = ss->mgp;
145093f7848bSJeff Kirsher unsigned long rx_bytes = 0;
145193f7848bSJeff Kirsher unsigned long rx_packets = 0;
145293f7848bSJeff Kirsher unsigned long rx_ok;
145393f7848bSJeff Kirsher int idx = rx_done->idx;
145493f7848bSJeff Kirsher int cnt = rx_done->cnt;
145593f7848bSJeff Kirsher int work_done = 0;
145693f7848bSJeff Kirsher u16 length;
145793f7848bSJeff Kirsher __wsum checksum;
145893f7848bSJeff Kirsher
145993f7848bSJeff Kirsher while (rx_done->entry[idx].length != 0 && work_done < budget) {
146093f7848bSJeff Kirsher length = ntohs(rx_done->entry[idx].length);
146193f7848bSJeff Kirsher rx_done->entry[idx].length = 0;
146293f7848bSJeff Kirsher checksum = csum_unfold(rx_done->entry[idx].checksum);
14634ca3221fSAndrew Gallatin rx_ok = myri10ge_rx_done(ss, length, checksum);
146493f7848bSJeff Kirsher rx_packets += rx_ok;
146593f7848bSJeff Kirsher rx_bytes += rx_ok * (unsigned long)length;
146693f7848bSJeff Kirsher cnt++;
146793f7848bSJeff Kirsher idx = cnt & (mgp->max_intr_slots - 1);
146893f7848bSJeff Kirsher work_done++;
146993f7848bSJeff Kirsher }
147093f7848bSJeff Kirsher rx_done->idx = idx;
147193f7848bSJeff Kirsher rx_done->cnt = cnt;
147293f7848bSJeff Kirsher ss->stats.rx_packets += rx_packets;
147393f7848bSJeff Kirsher ss->stats.rx_bytes += rx_bytes;
147493f7848bSJeff Kirsher
147593f7848bSJeff Kirsher /* restock receive rings if needed */
147693f7848bSJeff Kirsher if (ss->rx_small.fill_cnt - ss->rx_small.cnt < myri10ge_fill_thresh)
147793f7848bSJeff Kirsher myri10ge_alloc_rx_pages(mgp, &ss->rx_small,
147893f7848bSJeff Kirsher mgp->small_bytes + MXGEFW_PAD, 0);
147993f7848bSJeff Kirsher if (ss->rx_big.fill_cnt - ss->rx_big.cnt < myri10ge_fill_thresh)
148093f7848bSJeff Kirsher myri10ge_alloc_rx_pages(mgp, &ss->rx_big, mgp->big_bytes, 0);
148193f7848bSJeff Kirsher
148293f7848bSJeff Kirsher return work_done;
148393f7848bSJeff Kirsher }
148493f7848bSJeff Kirsher
myri10ge_check_statblock(struct myri10ge_priv * mgp)148593f7848bSJeff Kirsher static inline void myri10ge_check_statblock(struct myri10ge_priv *mgp)
148693f7848bSJeff Kirsher {
148793f7848bSJeff Kirsher struct mcp_irq_data *stats = mgp->ss[0].fw_stats;
148893f7848bSJeff Kirsher
148993f7848bSJeff Kirsher if (unlikely(stats->stats_updated)) {
149093f7848bSJeff Kirsher unsigned link_up = ntohl(stats->link_up);
149193f7848bSJeff Kirsher if (mgp->link_state != link_up) {
149293f7848bSJeff Kirsher mgp->link_state = link_up;
149393f7848bSJeff Kirsher
149493f7848bSJeff Kirsher if (mgp->link_state == MXGEFW_LINK_UP) {
149593f7848bSJeff Kirsher netif_info(mgp, link, mgp->dev, "link up\n");
149693f7848bSJeff Kirsher netif_carrier_on(mgp->dev);
149793f7848bSJeff Kirsher mgp->link_changes++;
149893f7848bSJeff Kirsher } else {
149993f7848bSJeff Kirsher netif_info(mgp, link, mgp->dev, "link %s\n",
150093f7848bSJeff Kirsher (link_up == MXGEFW_LINK_MYRINET ?
150193f7848bSJeff Kirsher "mismatch (Myrinet detected)" :
150293f7848bSJeff Kirsher "down"));
150393f7848bSJeff Kirsher netif_carrier_off(mgp->dev);
150493f7848bSJeff Kirsher mgp->link_changes++;
150593f7848bSJeff Kirsher }
150693f7848bSJeff Kirsher }
150793f7848bSJeff Kirsher if (mgp->rdma_tags_available !=
150893f7848bSJeff Kirsher ntohl(stats->rdma_tags_available)) {
150993f7848bSJeff Kirsher mgp->rdma_tags_available =
151093f7848bSJeff Kirsher ntohl(stats->rdma_tags_available);
151193f7848bSJeff Kirsher netdev_warn(mgp->dev, "RDMA timed out! %d tags left\n",
151293f7848bSJeff Kirsher mgp->rdma_tags_available);
151393f7848bSJeff Kirsher }
151493f7848bSJeff Kirsher mgp->down_cnt += stats->link_down;
151593f7848bSJeff Kirsher if (stats->link_down)
151693f7848bSJeff Kirsher wake_up(&mgp->down_wq);
151793f7848bSJeff Kirsher }
151893f7848bSJeff Kirsher }
151993f7848bSJeff Kirsher
myri10ge_poll(struct napi_struct * napi,int budget)152093f7848bSJeff Kirsher static int myri10ge_poll(struct napi_struct *napi, int budget)
152193f7848bSJeff Kirsher {
152293f7848bSJeff Kirsher struct myri10ge_slice_state *ss =
152393f7848bSJeff Kirsher container_of(napi, struct myri10ge_slice_state, napi);
152493f7848bSJeff Kirsher int work_done;
152593f7848bSJeff Kirsher
152693f7848bSJeff Kirsher #ifdef CONFIG_MYRI10GE_DCA
152793f7848bSJeff Kirsher if (ss->mgp->dca_enabled)
152893f7848bSJeff Kirsher myri10ge_update_dca(ss);
152993f7848bSJeff Kirsher #endif
153093f7848bSJeff Kirsher /* process as many rx events as NAPI will allow */
153193f7848bSJeff Kirsher work_done = myri10ge_clean_rx_done(ss, budget);
153293f7848bSJeff Kirsher
153393f7848bSJeff Kirsher if (work_done < budget) {
15346ad20165SEric Dumazet napi_complete_done(napi, work_done);
153593f7848bSJeff Kirsher put_be32(htonl(3), ss->irq_claim);
153693f7848bSJeff Kirsher }
153793f7848bSJeff Kirsher return work_done;
153893f7848bSJeff Kirsher }
153993f7848bSJeff Kirsher
myri10ge_intr(int irq,void * arg)154093f7848bSJeff Kirsher static irqreturn_t myri10ge_intr(int irq, void *arg)
154193f7848bSJeff Kirsher {
154293f7848bSJeff Kirsher struct myri10ge_slice_state *ss = arg;
154393f7848bSJeff Kirsher struct myri10ge_priv *mgp = ss->mgp;
154493f7848bSJeff Kirsher struct mcp_irq_data *stats = ss->fw_stats;
154593f7848bSJeff Kirsher struct myri10ge_tx_buf *tx = &ss->tx;
154693f7848bSJeff Kirsher u32 send_done_count;
154793f7848bSJeff Kirsher int i;
154893f7848bSJeff Kirsher
154993f7848bSJeff Kirsher /* an interrupt on a non-zero receive-only slice is implicitly
155093f7848bSJeff Kirsher * valid since MSI-X irqs are not shared */
155193f7848bSJeff Kirsher if ((mgp->dev->real_num_tx_queues == 1) && (ss != mgp->ss)) {
155293f7848bSJeff Kirsher napi_schedule(&ss->napi);
155393f7848bSJeff Kirsher return IRQ_HANDLED;
155493f7848bSJeff Kirsher }
155593f7848bSJeff Kirsher
155693f7848bSJeff Kirsher /* make sure it is our IRQ, and that the DMA has finished */
155793f7848bSJeff Kirsher if (unlikely(!stats->valid))
155893f7848bSJeff Kirsher return IRQ_NONE;
155993f7848bSJeff Kirsher
156093f7848bSJeff Kirsher /* low bit indicates receives are present, so schedule
156193f7848bSJeff Kirsher * napi poll handler */
156293f7848bSJeff Kirsher if (stats->valid & 1)
156393f7848bSJeff Kirsher napi_schedule(&ss->napi);
156493f7848bSJeff Kirsher
156593f7848bSJeff Kirsher if (!mgp->msi_enabled && !mgp->msix_enabled) {
156693f7848bSJeff Kirsher put_be32(0, mgp->irq_deassert);
156793f7848bSJeff Kirsher if (!myri10ge_deassert_wait)
156893f7848bSJeff Kirsher stats->valid = 0;
156993f7848bSJeff Kirsher mb();
157093f7848bSJeff Kirsher } else
157193f7848bSJeff Kirsher stats->valid = 0;
157293f7848bSJeff Kirsher
157393f7848bSJeff Kirsher /* Wait for IRQ line to go low, if using INTx */
157493f7848bSJeff Kirsher i = 0;
157593f7848bSJeff Kirsher while (1) {
157693f7848bSJeff Kirsher i++;
157793f7848bSJeff Kirsher /* check for transmit completes and receives */
157893f7848bSJeff Kirsher send_done_count = ntohl(stats->send_done_count);
157993f7848bSJeff Kirsher if (send_done_count != tx->pkt_done)
158093f7848bSJeff Kirsher myri10ge_tx_done(ss, (int)send_done_count);
158193f7848bSJeff Kirsher if (unlikely(i > myri10ge_max_irq_loops)) {
158293f7848bSJeff Kirsher netdev_warn(mgp->dev, "irq stuck?\n");
158393f7848bSJeff Kirsher stats->valid = 0;
158493f7848bSJeff Kirsher schedule_work(&mgp->watchdog_work);
158593f7848bSJeff Kirsher }
158693f7848bSJeff Kirsher if (likely(stats->valid == 0))
158793f7848bSJeff Kirsher break;
158893f7848bSJeff Kirsher cpu_relax();
158993f7848bSJeff Kirsher barrier();
159093f7848bSJeff Kirsher }
159193f7848bSJeff Kirsher
159293f7848bSJeff Kirsher /* Only slice 0 updates stats */
159393f7848bSJeff Kirsher if (ss == mgp->ss)
159493f7848bSJeff Kirsher myri10ge_check_statblock(mgp);
159593f7848bSJeff Kirsher
159693f7848bSJeff Kirsher put_be32(htonl(3), ss->irq_claim + 1);
159793f7848bSJeff Kirsher return IRQ_HANDLED;
159893f7848bSJeff Kirsher }
159993f7848bSJeff Kirsher
160093f7848bSJeff Kirsher static int
myri10ge_get_link_ksettings(struct net_device * netdev,struct ethtool_link_ksettings * cmd)1601cf901656SPhilippe Reynes myri10ge_get_link_ksettings(struct net_device *netdev,
1602cf901656SPhilippe Reynes struct ethtool_link_ksettings *cmd)
160393f7848bSJeff Kirsher {
160493f7848bSJeff Kirsher struct myri10ge_priv *mgp = netdev_priv(netdev);
160593f7848bSJeff Kirsher char *ptr;
160693f7848bSJeff Kirsher int i;
160793f7848bSJeff Kirsher
1608cf901656SPhilippe Reynes cmd->base.autoneg = AUTONEG_DISABLE;
1609cf901656SPhilippe Reynes cmd->base.speed = SPEED_10000;
1610cf901656SPhilippe Reynes cmd->base.duplex = DUPLEX_FULL;
161193f7848bSJeff Kirsher
161293f7848bSJeff Kirsher /*
161393f7848bSJeff Kirsher * parse the product code to deterimine the interface type
161493f7848bSJeff Kirsher * (CX4, XFP, Quad Ribbon Fiber) by looking at the character
161593f7848bSJeff Kirsher * after the 3rd dash in the driver's cached copy of the
161693f7848bSJeff Kirsher * EEPROM's product code string.
161793f7848bSJeff Kirsher */
161893f7848bSJeff Kirsher ptr = mgp->product_code_string;
161993f7848bSJeff Kirsher if (ptr == NULL) {
162093f7848bSJeff Kirsher netdev_err(netdev, "Missing product code\n");
162193f7848bSJeff Kirsher return 0;
162293f7848bSJeff Kirsher }
162393f7848bSJeff Kirsher for (i = 0; i < 3; i++, ptr++) {
162493f7848bSJeff Kirsher ptr = strchr(ptr, '-');
162593f7848bSJeff Kirsher if (ptr == NULL) {
162693f7848bSJeff Kirsher netdev_err(netdev, "Invalid product code %s\n",
162793f7848bSJeff Kirsher mgp->product_code_string);
162893f7848bSJeff Kirsher return 0;
162993f7848bSJeff Kirsher }
163093f7848bSJeff Kirsher }
163193f7848bSJeff Kirsher if (*ptr == '2')
163293f7848bSJeff Kirsher ptr++;
163393f7848bSJeff Kirsher if (*ptr == 'R' || *ptr == 'Q' || *ptr == 'S') {
163493f7848bSJeff Kirsher /* We've found either an XFP, quad ribbon fiber, or SFP+ */
1635cf901656SPhilippe Reynes cmd->base.port = PORT_FIBRE;
1636cf901656SPhilippe Reynes ethtool_link_ksettings_add_link_mode(cmd, supported, FIBRE);
1637cf901656SPhilippe Reynes ethtool_link_ksettings_add_link_mode(cmd, advertising, FIBRE);
163893f7848bSJeff Kirsher } else {
1639cf901656SPhilippe Reynes cmd->base.port = PORT_OTHER;
164093f7848bSJeff Kirsher }
164193f7848bSJeff Kirsher
164293f7848bSJeff Kirsher return 0;
164393f7848bSJeff Kirsher }
164493f7848bSJeff Kirsher
164593f7848bSJeff Kirsher static void
myri10ge_get_drvinfo(struct net_device * netdev,struct ethtool_drvinfo * info)164693f7848bSJeff Kirsher myri10ge_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *info)
164793f7848bSJeff Kirsher {
164893f7848bSJeff Kirsher struct myri10ge_priv *mgp = netdev_priv(netdev);
164993f7848bSJeff Kirsher
1650f029c781SWolfram Sang strscpy(info->driver, "myri10ge", sizeof(info->driver));
1651f029c781SWolfram Sang strscpy(info->version, MYRI10GE_VERSION_STR, sizeof(info->version));
1652f029c781SWolfram Sang strscpy(info->fw_version, mgp->fw_version, sizeof(info->fw_version));
1653f029c781SWolfram Sang strscpy(info->bus_info, pci_name(mgp->pdev), sizeof(info->bus_info));
165493f7848bSJeff Kirsher }
165593f7848bSJeff Kirsher
myri10ge_get_coalesce(struct net_device * netdev,struct ethtool_coalesce * coal,struct kernel_ethtool_coalesce * kernel_coal,struct netlink_ext_ack * extack)1656f3ccfda1SYufeng Mo static int myri10ge_get_coalesce(struct net_device *netdev,
1657f3ccfda1SYufeng Mo struct ethtool_coalesce *coal,
1658f3ccfda1SYufeng Mo struct kernel_ethtool_coalesce *kernel_coal,
1659f3ccfda1SYufeng Mo struct netlink_ext_ack *extack)
166093f7848bSJeff Kirsher {
166193f7848bSJeff Kirsher struct myri10ge_priv *mgp = netdev_priv(netdev);
166293f7848bSJeff Kirsher
166393f7848bSJeff Kirsher coal->rx_coalesce_usecs = mgp->intr_coal_delay;
166493f7848bSJeff Kirsher return 0;
166593f7848bSJeff Kirsher }
166693f7848bSJeff Kirsher
myri10ge_set_coalesce(struct net_device * netdev,struct ethtool_coalesce * coal,struct kernel_ethtool_coalesce * kernel_coal,struct netlink_ext_ack * extack)1667f3ccfda1SYufeng Mo static int myri10ge_set_coalesce(struct net_device *netdev,
1668f3ccfda1SYufeng Mo struct ethtool_coalesce *coal,
1669f3ccfda1SYufeng Mo struct kernel_ethtool_coalesce *kernel_coal,
1670f3ccfda1SYufeng Mo struct netlink_ext_ack *extack)
167193f7848bSJeff Kirsher {
167293f7848bSJeff Kirsher struct myri10ge_priv *mgp = netdev_priv(netdev);
167393f7848bSJeff Kirsher
167493f7848bSJeff Kirsher mgp->intr_coal_delay = coal->rx_coalesce_usecs;
167593f7848bSJeff Kirsher put_be32(htonl(mgp->intr_coal_delay), mgp->intr_coal_delay_ptr);
167693f7848bSJeff Kirsher return 0;
167793f7848bSJeff Kirsher }
167893f7848bSJeff Kirsher
167993f7848bSJeff Kirsher static void
myri10ge_get_pauseparam(struct net_device * netdev,struct ethtool_pauseparam * pause)168093f7848bSJeff Kirsher myri10ge_get_pauseparam(struct net_device *netdev,
168193f7848bSJeff Kirsher struct ethtool_pauseparam *pause)
168293f7848bSJeff Kirsher {
168393f7848bSJeff Kirsher struct myri10ge_priv *mgp = netdev_priv(netdev);
168493f7848bSJeff Kirsher
168593f7848bSJeff Kirsher pause->autoneg = 0;
168693f7848bSJeff Kirsher pause->rx_pause = mgp->pause;
168793f7848bSJeff Kirsher pause->tx_pause = mgp->pause;
168893f7848bSJeff Kirsher }
168993f7848bSJeff Kirsher
169093f7848bSJeff Kirsher static int
myri10ge_set_pauseparam(struct net_device * netdev,struct ethtool_pauseparam * pause)169193f7848bSJeff Kirsher myri10ge_set_pauseparam(struct net_device *netdev,
169293f7848bSJeff Kirsher struct ethtool_pauseparam *pause)
169393f7848bSJeff Kirsher {
169493f7848bSJeff Kirsher struct myri10ge_priv *mgp = netdev_priv(netdev);
169593f7848bSJeff Kirsher
169693f7848bSJeff Kirsher if (pause->tx_pause != mgp->pause)
169793f7848bSJeff Kirsher return myri10ge_change_pause(mgp, pause->tx_pause);
169893f7848bSJeff Kirsher if (pause->rx_pause != mgp->pause)
169993f7848bSJeff Kirsher return myri10ge_change_pause(mgp, pause->rx_pause);
170093f7848bSJeff Kirsher if (pause->autoneg != 0)
170193f7848bSJeff Kirsher return -EINVAL;
170293f7848bSJeff Kirsher return 0;
170393f7848bSJeff Kirsher }
170493f7848bSJeff Kirsher
170593f7848bSJeff Kirsher static void
myri10ge_get_ringparam(struct net_device * netdev,struct ethtool_ringparam * ring,struct kernel_ethtool_ringparam * kernel_ring,struct netlink_ext_ack * extack)170693f7848bSJeff Kirsher myri10ge_get_ringparam(struct net_device *netdev,
170774624944SHao Chen struct ethtool_ringparam *ring,
170874624944SHao Chen struct kernel_ethtool_ringparam *kernel_ring,
170974624944SHao Chen struct netlink_ext_ack *extack)
171093f7848bSJeff Kirsher {
171193f7848bSJeff Kirsher struct myri10ge_priv *mgp = netdev_priv(netdev);
171293f7848bSJeff Kirsher
171393f7848bSJeff Kirsher ring->rx_mini_max_pending = mgp->ss[0].rx_small.mask + 1;
171493f7848bSJeff Kirsher ring->rx_max_pending = mgp->ss[0].rx_big.mask + 1;
171593f7848bSJeff Kirsher ring->rx_jumbo_max_pending = 0;
171693f7848bSJeff Kirsher ring->tx_max_pending = mgp->ss[0].tx.mask + 1;
171793f7848bSJeff Kirsher ring->rx_mini_pending = ring->rx_mini_max_pending;
171893f7848bSJeff Kirsher ring->rx_pending = ring->rx_max_pending;
171993f7848bSJeff Kirsher ring->rx_jumbo_pending = ring->rx_jumbo_max_pending;
172093f7848bSJeff Kirsher ring->tx_pending = ring->tx_max_pending;
172193f7848bSJeff Kirsher }
172293f7848bSJeff Kirsher
172393f7848bSJeff Kirsher static const char myri10ge_gstrings_main_stats[][ETH_GSTRING_LEN] = {
172493f7848bSJeff Kirsher "rx_packets", "tx_packets", "rx_bytes", "tx_bytes", "rx_errors",
172593f7848bSJeff Kirsher "tx_errors", "rx_dropped", "tx_dropped", "multicast", "collisions",
172693f7848bSJeff Kirsher "rx_length_errors", "rx_over_errors", "rx_crc_errors",
172793f7848bSJeff Kirsher "rx_frame_errors", "rx_fifo_errors", "rx_missed_errors",
172893f7848bSJeff Kirsher "tx_aborted_errors", "tx_carrier_errors", "tx_fifo_errors",
172993f7848bSJeff Kirsher "tx_heartbeat_errors", "tx_window_errors",
173093f7848bSJeff Kirsher /* device-specific stats */
1731e4b6c303SLuis R. Rodriguez "tx_boundary", "irq", "MSI", "MSIX",
173293f7848bSJeff Kirsher "read_dma_bw_MBs", "write_dma_bw_MBs", "read_write_dma_bw_MBs",
173393f7848bSJeff Kirsher "serial_number", "watchdog_resets",
173493f7848bSJeff Kirsher #ifdef CONFIG_MYRI10GE_DCA
173593f7848bSJeff Kirsher "dca_capable_firmware", "dca_device_present",
173693f7848bSJeff Kirsher #endif
173793f7848bSJeff Kirsher "link_changes", "link_up", "dropped_link_overflow",
173893f7848bSJeff Kirsher "dropped_link_error_or_filtered",
173993f7848bSJeff Kirsher "dropped_pause", "dropped_bad_phy", "dropped_bad_crc32",
174093f7848bSJeff Kirsher "dropped_unicast_filtered", "dropped_multicast_filtered",
174193f7848bSJeff Kirsher "dropped_runt", "dropped_overrun", "dropped_no_small_buffer",
174293f7848bSJeff Kirsher "dropped_no_big_buffer"
174393f7848bSJeff Kirsher };
174493f7848bSJeff Kirsher
174593f7848bSJeff Kirsher static const char myri10ge_gstrings_slice_stats[][ETH_GSTRING_LEN] = {
174693f7848bSJeff Kirsher "----------- slice ---------",
174793f7848bSJeff Kirsher "tx_pkt_start", "tx_pkt_done", "tx_req", "tx_done",
174893f7848bSJeff Kirsher "rx_small_cnt", "rx_big_cnt",
174993f7848bSJeff Kirsher "wake_queue", "stop_queue", "tx_linearized",
175093f7848bSJeff Kirsher };
175193f7848bSJeff Kirsher
175293f7848bSJeff Kirsher #define MYRI10GE_NET_STATS_LEN 21
175393f7848bSJeff Kirsher #define MYRI10GE_MAIN_STATS_LEN ARRAY_SIZE(myri10ge_gstrings_main_stats)
175493f7848bSJeff Kirsher #define MYRI10GE_SLICE_STATS_LEN ARRAY_SIZE(myri10ge_gstrings_slice_stats)
175593f7848bSJeff Kirsher
175693f7848bSJeff Kirsher static void
myri10ge_get_strings(struct net_device * netdev,u32 stringset,u8 * data)175793f7848bSJeff Kirsher myri10ge_get_strings(struct net_device *netdev, u32 stringset, u8 * data)
175893f7848bSJeff Kirsher {
175993f7848bSJeff Kirsher struct myri10ge_priv *mgp = netdev_priv(netdev);
176093f7848bSJeff Kirsher int i;
176193f7848bSJeff Kirsher
176293f7848bSJeff Kirsher switch (stringset) {
176393f7848bSJeff Kirsher case ETH_SS_STATS:
176493f7848bSJeff Kirsher memcpy(data, *myri10ge_gstrings_main_stats,
176593f7848bSJeff Kirsher sizeof(myri10ge_gstrings_main_stats));
176693f7848bSJeff Kirsher data += sizeof(myri10ge_gstrings_main_stats);
176793f7848bSJeff Kirsher for (i = 0; i < mgp->num_slices; i++) {
176893f7848bSJeff Kirsher memcpy(data, *myri10ge_gstrings_slice_stats,
176993f7848bSJeff Kirsher sizeof(myri10ge_gstrings_slice_stats));
177093f7848bSJeff Kirsher data += sizeof(myri10ge_gstrings_slice_stats);
177193f7848bSJeff Kirsher }
177293f7848bSJeff Kirsher break;
177393f7848bSJeff Kirsher }
177493f7848bSJeff Kirsher }
177593f7848bSJeff Kirsher
myri10ge_get_sset_count(struct net_device * netdev,int sset)177693f7848bSJeff Kirsher static int myri10ge_get_sset_count(struct net_device *netdev, int sset)
177793f7848bSJeff Kirsher {
177893f7848bSJeff Kirsher struct myri10ge_priv *mgp = netdev_priv(netdev);
177993f7848bSJeff Kirsher
178093f7848bSJeff Kirsher switch (sset) {
178193f7848bSJeff Kirsher case ETH_SS_STATS:
178293f7848bSJeff Kirsher return MYRI10GE_MAIN_STATS_LEN +
178393f7848bSJeff Kirsher mgp->num_slices * MYRI10GE_SLICE_STATS_LEN;
178493f7848bSJeff Kirsher default:
178593f7848bSJeff Kirsher return -EOPNOTSUPP;
178693f7848bSJeff Kirsher }
178793f7848bSJeff Kirsher }
178893f7848bSJeff Kirsher
178993f7848bSJeff Kirsher static void
myri10ge_get_ethtool_stats(struct net_device * netdev,struct ethtool_stats * stats,u64 * data)179093f7848bSJeff Kirsher myri10ge_get_ethtool_stats(struct net_device *netdev,
179193f7848bSJeff Kirsher struct ethtool_stats *stats, u64 * data)
179293f7848bSJeff Kirsher {
179393f7848bSJeff Kirsher struct myri10ge_priv *mgp = netdev_priv(netdev);
179493f7848bSJeff Kirsher struct myri10ge_slice_state *ss;
179593f7848bSJeff Kirsher struct rtnl_link_stats64 link_stats;
179693f7848bSJeff Kirsher int slice;
179793f7848bSJeff Kirsher int i;
179893f7848bSJeff Kirsher
179993f7848bSJeff Kirsher /* force stats update */
180093f7848bSJeff Kirsher memset(&link_stats, 0, sizeof(link_stats));
180193f7848bSJeff Kirsher (void)myri10ge_get_stats(netdev, &link_stats);
180293f7848bSJeff Kirsher for (i = 0; i < MYRI10GE_NET_STATS_LEN; i++)
180393f7848bSJeff Kirsher data[i] = ((u64 *)&link_stats)[i];
180493f7848bSJeff Kirsher
180593f7848bSJeff Kirsher data[i++] = (unsigned int)mgp->tx_boundary;
180693f7848bSJeff Kirsher data[i++] = (unsigned int)mgp->pdev->irq;
180793f7848bSJeff Kirsher data[i++] = (unsigned int)mgp->msi_enabled;
180893f7848bSJeff Kirsher data[i++] = (unsigned int)mgp->msix_enabled;
180993f7848bSJeff Kirsher data[i++] = (unsigned int)mgp->read_dma;
181093f7848bSJeff Kirsher data[i++] = (unsigned int)mgp->write_dma;
181193f7848bSJeff Kirsher data[i++] = (unsigned int)mgp->read_write_dma;
181293f7848bSJeff Kirsher data[i++] = (unsigned int)mgp->serial_number;
181393f7848bSJeff Kirsher data[i++] = (unsigned int)mgp->watchdog_resets;
181493f7848bSJeff Kirsher #ifdef CONFIG_MYRI10GE_DCA
181593f7848bSJeff Kirsher data[i++] = (unsigned int)(mgp->ss[0].dca_tag != NULL);
181693f7848bSJeff Kirsher data[i++] = (unsigned int)(mgp->dca_enabled);
181793f7848bSJeff Kirsher #endif
181893f7848bSJeff Kirsher data[i++] = (unsigned int)mgp->link_changes;
181993f7848bSJeff Kirsher
182093f7848bSJeff Kirsher /* firmware stats are useful only in the first slice */
182193f7848bSJeff Kirsher ss = &mgp->ss[0];
182293f7848bSJeff Kirsher data[i++] = (unsigned int)ntohl(ss->fw_stats->link_up);
182393f7848bSJeff Kirsher data[i++] = (unsigned int)ntohl(ss->fw_stats->dropped_link_overflow);
182493f7848bSJeff Kirsher data[i++] =
182593f7848bSJeff Kirsher (unsigned int)ntohl(ss->fw_stats->dropped_link_error_or_filtered);
182693f7848bSJeff Kirsher data[i++] = (unsigned int)ntohl(ss->fw_stats->dropped_pause);
182793f7848bSJeff Kirsher data[i++] = (unsigned int)ntohl(ss->fw_stats->dropped_bad_phy);
182893f7848bSJeff Kirsher data[i++] = (unsigned int)ntohl(ss->fw_stats->dropped_bad_crc32);
182993f7848bSJeff Kirsher data[i++] = (unsigned int)ntohl(ss->fw_stats->dropped_unicast_filtered);
183093f7848bSJeff Kirsher data[i++] =
183193f7848bSJeff Kirsher (unsigned int)ntohl(ss->fw_stats->dropped_multicast_filtered);
183293f7848bSJeff Kirsher data[i++] = (unsigned int)ntohl(ss->fw_stats->dropped_runt);
183393f7848bSJeff Kirsher data[i++] = (unsigned int)ntohl(ss->fw_stats->dropped_overrun);
183493f7848bSJeff Kirsher data[i++] = (unsigned int)ntohl(ss->fw_stats->dropped_no_small_buffer);
183593f7848bSJeff Kirsher data[i++] = (unsigned int)ntohl(ss->fw_stats->dropped_no_big_buffer);
183693f7848bSJeff Kirsher
183793f7848bSJeff Kirsher for (slice = 0; slice < mgp->num_slices; slice++) {
183893f7848bSJeff Kirsher ss = &mgp->ss[slice];
183993f7848bSJeff Kirsher data[i++] = slice;
184093f7848bSJeff Kirsher data[i++] = (unsigned int)ss->tx.pkt_start;
184193f7848bSJeff Kirsher data[i++] = (unsigned int)ss->tx.pkt_done;
184293f7848bSJeff Kirsher data[i++] = (unsigned int)ss->tx.req;
184393f7848bSJeff Kirsher data[i++] = (unsigned int)ss->tx.done;
184493f7848bSJeff Kirsher data[i++] = (unsigned int)ss->rx_small.cnt;
184593f7848bSJeff Kirsher data[i++] = (unsigned int)ss->rx_big.cnt;
184693f7848bSJeff Kirsher data[i++] = (unsigned int)ss->tx.wake_queue;
184793f7848bSJeff Kirsher data[i++] = (unsigned int)ss->tx.stop_queue;
184893f7848bSJeff Kirsher data[i++] = (unsigned int)ss->tx.linearized;
184993f7848bSJeff Kirsher }
185093f7848bSJeff Kirsher }
185193f7848bSJeff Kirsher
myri10ge_set_msglevel(struct net_device * netdev,u32 value)185293f7848bSJeff Kirsher static void myri10ge_set_msglevel(struct net_device *netdev, u32 value)
185393f7848bSJeff Kirsher {
185493f7848bSJeff Kirsher struct myri10ge_priv *mgp = netdev_priv(netdev);
185593f7848bSJeff Kirsher mgp->msg_enable = value;
185693f7848bSJeff Kirsher }
185793f7848bSJeff Kirsher
myri10ge_get_msglevel(struct net_device * netdev)185893f7848bSJeff Kirsher static u32 myri10ge_get_msglevel(struct net_device *netdev)
185993f7848bSJeff Kirsher {
186093f7848bSJeff Kirsher struct myri10ge_priv *mgp = netdev_priv(netdev);
186193f7848bSJeff Kirsher return mgp->msg_enable;
186293f7848bSJeff Kirsher }
186393f7848bSJeff Kirsher
186493f7848bSJeff Kirsher /*
186593f7848bSJeff Kirsher * Use a low-level command to change the LED behavior. Rather than
186693f7848bSJeff Kirsher * blinking (which is the normal case), when identify is used, the
186793f7848bSJeff Kirsher * yellow LED turns solid.
186893f7848bSJeff Kirsher */
myri10ge_led(struct myri10ge_priv * mgp,int on)186993f7848bSJeff Kirsher static int myri10ge_led(struct myri10ge_priv *mgp, int on)
187093f7848bSJeff Kirsher {
187193f7848bSJeff Kirsher struct mcp_gen_header *hdr;
187293f7848bSJeff Kirsher struct device *dev = &mgp->pdev->dev;
187393f7848bSJeff Kirsher size_t hdr_off, pattern_off, hdr_len;
187493f7848bSJeff Kirsher u32 pattern = 0xfffffffe;
187593f7848bSJeff Kirsher
187693f7848bSJeff Kirsher /* find running firmware header */
187793f7848bSJeff Kirsher hdr_off = swab32(readl(mgp->sram + MCP_HEADER_PTR_OFFSET));
187893f7848bSJeff Kirsher if ((hdr_off & 3) || hdr_off + sizeof(*hdr) > mgp->sram_size) {
187993f7848bSJeff Kirsher dev_err(dev, "Running firmware has bad header offset (%d)\n",
188093f7848bSJeff Kirsher (int)hdr_off);
188193f7848bSJeff Kirsher return -EIO;
188293f7848bSJeff Kirsher }
188393f7848bSJeff Kirsher hdr_len = swab32(readl(mgp->sram + hdr_off +
188493f7848bSJeff Kirsher offsetof(struct mcp_gen_header, header_length)));
188593f7848bSJeff Kirsher pattern_off = hdr_off + offsetof(struct mcp_gen_header, led_pattern);
188693f7848bSJeff Kirsher if (pattern_off >= (hdr_len + hdr_off)) {
188793f7848bSJeff Kirsher dev_info(dev, "Firmware does not support LED identification\n");
188893f7848bSJeff Kirsher return -EINVAL;
188993f7848bSJeff Kirsher }
189093f7848bSJeff Kirsher if (!on)
189193f7848bSJeff Kirsher pattern = swab32(readl(mgp->sram + pattern_off + 4));
189259e955edSAndrew Gallatin writel(swab32(pattern), mgp->sram + pattern_off);
189393f7848bSJeff Kirsher return 0;
189493f7848bSJeff Kirsher }
189593f7848bSJeff Kirsher
189693f7848bSJeff Kirsher static int
myri10ge_phys_id(struct net_device * netdev,enum ethtool_phys_id_state state)189793f7848bSJeff Kirsher myri10ge_phys_id(struct net_device *netdev, enum ethtool_phys_id_state state)
189893f7848bSJeff Kirsher {
189993f7848bSJeff Kirsher struct myri10ge_priv *mgp = netdev_priv(netdev);
190093f7848bSJeff Kirsher int rc;
190193f7848bSJeff Kirsher
190293f7848bSJeff Kirsher switch (state) {
190393f7848bSJeff Kirsher case ETHTOOL_ID_ACTIVE:
190493f7848bSJeff Kirsher rc = myri10ge_led(mgp, 1);
190593f7848bSJeff Kirsher break;
190693f7848bSJeff Kirsher
190793f7848bSJeff Kirsher case ETHTOOL_ID_INACTIVE:
190893f7848bSJeff Kirsher rc = myri10ge_led(mgp, 0);
190993f7848bSJeff Kirsher break;
191093f7848bSJeff Kirsher
191193f7848bSJeff Kirsher default:
191293f7848bSJeff Kirsher rc = -EINVAL;
191393f7848bSJeff Kirsher }
191493f7848bSJeff Kirsher
191593f7848bSJeff Kirsher return rc;
191693f7848bSJeff Kirsher }
191793f7848bSJeff Kirsher
191893f7848bSJeff Kirsher static const struct ethtool_ops myri10ge_ethtool_ops = {
1919930129d9SJakub Kicinski .supported_coalesce_params = ETHTOOL_COALESCE_RX_USECS,
192093f7848bSJeff Kirsher .get_drvinfo = myri10ge_get_drvinfo,
192193f7848bSJeff Kirsher .get_coalesce = myri10ge_get_coalesce,
192293f7848bSJeff Kirsher .set_coalesce = myri10ge_set_coalesce,
192393f7848bSJeff Kirsher .get_pauseparam = myri10ge_get_pauseparam,
192493f7848bSJeff Kirsher .set_pauseparam = myri10ge_set_pauseparam,
192593f7848bSJeff Kirsher .get_ringparam = myri10ge_get_ringparam,
192693f7848bSJeff Kirsher .get_link = ethtool_op_get_link,
192793f7848bSJeff Kirsher .get_strings = myri10ge_get_strings,
192893f7848bSJeff Kirsher .get_sset_count = myri10ge_get_sset_count,
192993f7848bSJeff Kirsher .get_ethtool_stats = myri10ge_get_ethtool_stats,
193093f7848bSJeff Kirsher .set_msglevel = myri10ge_set_msglevel,
193193f7848bSJeff Kirsher .get_msglevel = myri10ge_get_msglevel,
193293f7848bSJeff Kirsher .set_phys_id = myri10ge_phys_id,
1933cf901656SPhilippe Reynes .get_link_ksettings = myri10ge_get_link_ksettings,
193493f7848bSJeff Kirsher };
193593f7848bSJeff Kirsher
myri10ge_allocate_rings(struct myri10ge_slice_state * ss)193693f7848bSJeff Kirsher static int myri10ge_allocate_rings(struct myri10ge_slice_state *ss)
193793f7848bSJeff Kirsher {
193893f7848bSJeff Kirsher struct myri10ge_priv *mgp = ss->mgp;
193993f7848bSJeff Kirsher struct myri10ge_cmd cmd;
194093f7848bSJeff Kirsher struct net_device *dev = mgp->dev;
194193f7848bSJeff Kirsher int tx_ring_size, rx_ring_size;
194293f7848bSJeff Kirsher int tx_ring_entries, rx_ring_entries;
194393f7848bSJeff Kirsher int i, slice, status;
194493f7848bSJeff Kirsher size_t bytes;
194593f7848bSJeff Kirsher
194693f7848bSJeff Kirsher /* get ring sizes */
194793f7848bSJeff Kirsher slice = ss - mgp->ss;
194893f7848bSJeff Kirsher cmd.data0 = slice;
194993f7848bSJeff Kirsher status = myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_SEND_RING_SIZE, &cmd, 0);
195093f7848bSJeff Kirsher tx_ring_size = cmd.data0;
195193f7848bSJeff Kirsher cmd.data0 = slice;
195293f7848bSJeff Kirsher status |= myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_RX_RING_SIZE, &cmd, 0);
195393f7848bSJeff Kirsher if (status != 0)
195493f7848bSJeff Kirsher return status;
195593f7848bSJeff Kirsher rx_ring_size = cmd.data0;
195693f7848bSJeff Kirsher
195793f7848bSJeff Kirsher tx_ring_entries = tx_ring_size / sizeof(struct mcp_kreq_ether_send);
195893f7848bSJeff Kirsher rx_ring_entries = rx_ring_size / sizeof(struct mcp_dma_addr);
195993f7848bSJeff Kirsher ss->tx.mask = tx_ring_entries - 1;
196093f7848bSJeff Kirsher ss->rx_small.mask = ss->rx_big.mask = rx_ring_entries - 1;
196193f7848bSJeff Kirsher
196293f7848bSJeff Kirsher status = -ENOMEM;
196393f7848bSJeff Kirsher
196493f7848bSJeff Kirsher /* allocate the host shadow rings */
196593f7848bSJeff Kirsher
196693f7848bSJeff Kirsher bytes = 8 + (MYRI10GE_MAX_SEND_DESC_TSO + 4)
196793f7848bSJeff Kirsher * sizeof(*ss->tx.req_list);
196893f7848bSJeff Kirsher ss->tx.req_bytes = kzalloc(bytes, GFP_KERNEL);
196993f7848bSJeff Kirsher if (ss->tx.req_bytes == NULL)
197093f7848bSJeff Kirsher goto abort_with_nothing;
197193f7848bSJeff Kirsher
197293f7848bSJeff Kirsher /* ensure req_list entries are aligned to 8 bytes */
197393f7848bSJeff Kirsher ss->tx.req_list = (struct mcp_kreq_ether_send *)
197493f7848bSJeff Kirsher ALIGN((unsigned long)ss->tx.req_bytes, 8);
197593f7848bSJeff Kirsher ss->tx.queue_active = 0;
197693f7848bSJeff Kirsher
197793f7848bSJeff Kirsher bytes = rx_ring_entries * sizeof(*ss->rx_small.shadow);
197893f7848bSJeff Kirsher ss->rx_small.shadow = kzalloc(bytes, GFP_KERNEL);
197993f7848bSJeff Kirsher if (ss->rx_small.shadow == NULL)
198093f7848bSJeff Kirsher goto abort_with_tx_req_bytes;
198193f7848bSJeff Kirsher
198293f7848bSJeff Kirsher bytes = rx_ring_entries * sizeof(*ss->rx_big.shadow);
198393f7848bSJeff Kirsher ss->rx_big.shadow = kzalloc(bytes, GFP_KERNEL);
198493f7848bSJeff Kirsher if (ss->rx_big.shadow == NULL)
198593f7848bSJeff Kirsher goto abort_with_rx_small_shadow;
198693f7848bSJeff Kirsher
198793f7848bSJeff Kirsher /* allocate the host info rings */
198893f7848bSJeff Kirsher
198993f7848bSJeff Kirsher bytes = tx_ring_entries * sizeof(*ss->tx.info);
199093f7848bSJeff Kirsher ss->tx.info = kzalloc(bytes, GFP_KERNEL);
199193f7848bSJeff Kirsher if (ss->tx.info == NULL)
199293f7848bSJeff Kirsher goto abort_with_rx_big_shadow;
199393f7848bSJeff Kirsher
199493f7848bSJeff Kirsher bytes = rx_ring_entries * sizeof(*ss->rx_small.info);
199593f7848bSJeff Kirsher ss->rx_small.info = kzalloc(bytes, GFP_KERNEL);
199693f7848bSJeff Kirsher if (ss->rx_small.info == NULL)
199793f7848bSJeff Kirsher goto abort_with_tx_info;
199893f7848bSJeff Kirsher
199993f7848bSJeff Kirsher bytes = rx_ring_entries * sizeof(*ss->rx_big.info);
200093f7848bSJeff Kirsher ss->rx_big.info = kzalloc(bytes, GFP_KERNEL);
200193f7848bSJeff Kirsher if (ss->rx_big.info == NULL)
200293f7848bSJeff Kirsher goto abort_with_rx_small_info;
200393f7848bSJeff Kirsher
200493f7848bSJeff Kirsher /* Fill the receive rings */
200593f7848bSJeff Kirsher ss->rx_big.cnt = 0;
200693f7848bSJeff Kirsher ss->rx_small.cnt = 0;
200793f7848bSJeff Kirsher ss->rx_big.fill_cnt = 0;
200893f7848bSJeff Kirsher ss->rx_small.fill_cnt = 0;
200993f7848bSJeff Kirsher ss->rx_small.page_offset = MYRI10GE_ALLOC_SIZE;
201093f7848bSJeff Kirsher ss->rx_big.page_offset = MYRI10GE_ALLOC_SIZE;
201193f7848bSJeff Kirsher ss->rx_small.watchdog_needed = 0;
201293f7848bSJeff Kirsher ss->rx_big.watchdog_needed = 0;
201393f7848bSJeff Kirsher if (mgp->small_bytes == 0) {
201493f7848bSJeff Kirsher ss->rx_small.fill_cnt = ss->rx_small.mask + 1;
201593f7848bSJeff Kirsher } else {
201693f7848bSJeff Kirsher myri10ge_alloc_rx_pages(mgp, &ss->rx_small,
201793f7848bSJeff Kirsher mgp->small_bytes + MXGEFW_PAD, 0);
201893f7848bSJeff Kirsher }
201993f7848bSJeff Kirsher
202093f7848bSJeff Kirsher if (ss->rx_small.fill_cnt < ss->rx_small.mask + 1) {
202193f7848bSJeff Kirsher netdev_err(dev, "slice-%d: alloced only %d small bufs\n",
202293f7848bSJeff Kirsher slice, ss->rx_small.fill_cnt);
202393f7848bSJeff Kirsher goto abort_with_rx_small_ring;
202493f7848bSJeff Kirsher }
202593f7848bSJeff Kirsher
202693f7848bSJeff Kirsher myri10ge_alloc_rx_pages(mgp, &ss->rx_big, mgp->big_bytes, 0);
202793f7848bSJeff Kirsher if (ss->rx_big.fill_cnt < ss->rx_big.mask + 1) {
202893f7848bSJeff Kirsher netdev_err(dev, "slice-%d: alloced only %d big bufs\n",
202993f7848bSJeff Kirsher slice, ss->rx_big.fill_cnt);
203093f7848bSJeff Kirsher goto abort_with_rx_big_ring;
203193f7848bSJeff Kirsher }
203293f7848bSJeff Kirsher
203393f7848bSJeff Kirsher return 0;
203493f7848bSJeff Kirsher
203593f7848bSJeff Kirsher abort_with_rx_big_ring:
203693f7848bSJeff Kirsher for (i = ss->rx_big.cnt; i < ss->rx_big.fill_cnt; i++) {
203793f7848bSJeff Kirsher int idx = i & ss->rx_big.mask;
203893f7848bSJeff Kirsher myri10ge_unmap_rx_page(mgp->pdev, &ss->rx_big.info[idx],
203993f7848bSJeff Kirsher mgp->big_bytes);
204093f7848bSJeff Kirsher put_page(ss->rx_big.info[idx].page);
204193f7848bSJeff Kirsher }
204293f7848bSJeff Kirsher
204393f7848bSJeff Kirsher abort_with_rx_small_ring:
204493f7848bSJeff Kirsher if (mgp->small_bytes == 0)
204593f7848bSJeff Kirsher ss->rx_small.fill_cnt = ss->rx_small.cnt;
204693f7848bSJeff Kirsher for (i = ss->rx_small.cnt; i < ss->rx_small.fill_cnt; i++) {
204793f7848bSJeff Kirsher int idx = i & ss->rx_small.mask;
204893f7848bSJeff Kirsher myri10ge_unmap_rx_page(mgp->pdev, &ss->rx_small.info[idx],
204993f7848bSJeff Kirsher mgp->small_bytes + MXGEFW_PAD);
205093f7848bSJeff Kirsher put_page(ss->rx_small.info[idx].page);
205193f7848bSJeff Kirsher }
205293f7848bSJeff Kirsher
205393f7848bSJeff Kirsher kfree(ss->rx_big.info);
205493f7848bSJeff Kirsher
205593f7848bSJeff Kirsher abort_with_rx_small_info:
205693f7848bSJeff Kirsher kfree(ss->rx_small.info);
205793f7848bSJeff Kirsher
205893f7848bSJeff Kirsher abort_with_tx_info:
205993f7848bSJeff Kirsher kfree(ss->tx.info);
206093f7848bSJeff Kirsher
206193f7848bSJeff Kirsher abort_with_rx_big_shadow:
206293f7848bSJeff Kirsher kfree(ss->rx_big.shadow);
206393f7848bSJeff Kirsher
206493f7848bSJeff Kirsher abort_with_rx_small_shadow:
206593f7848bSJeff Kirsher kfree(ss->rx_small.shadow);
206693f7848bSJeff Kirsher
206793f7848bSJeff Kirsher abort_with_tx_req_bytes:
206893f7848bSJeff Kirsher kfree(ss->tx.req_bytes);
206993f7848bSJeff Kirsher ss->tx.req_bytes = NULL;
207093f7848bSJeff Kirsher ss->tx.req_list = NULL;
207193f7848bSJeff Kirsher
207293f7848bSJeff Kirsher abort_with_nothing:
207393f7848bSJeff Kirsher return status;
207493f7848bSJeff Kirsher }
207593f7848bSJeff Kirsher
myri10ge_free_rings(struct myri10ge_slice_state * ss)207693f7848bSJeff Kirsher static void myri10ge_free_rings(struct myri10ge_slice_state *ss)
207793f7848bSJeff Kirsher {
207893f7848bSJeff Kirsher struct myri10ge_priv *mgp = ss->mgp;
207993f7848bSJeff Kirsher struct sk_buff *skb;
208093f7848bSJeff Kirsher struct myri10ge_tx_buf *tx;
208193f7848bSJeff Kirsher int i, len, idx;
208293f7848bSJeff Kirsher
208393f7848bSJeff Kirsher /* If not allocated, skip it */
208493f7848bSJeff Kirsher if (ss->tx.req_list == NULL)
208593f7848bSJeff Kirsher return;
208693f7848bSJeff Kirsher
208793f7848bSJeff Kirsher for (i = ss->rx_big.cnt; i < ss->rx_big.fill_cnt; i++) {
208893f7848bSJeff Kirsher idx = i & ss->rx_big.mask;
208993f7848bSJeff Kirsher if (i == ss->rx_big.fill_cnt - 1)
209093f7848bSJeff Kirsher ss->rx_big.info[idx].page_offset = MYRI10GE_ALLOC_SIZE;
209193f7848bSJeff Kirsher myri10ge_unmap_rx_page(mgp->pdev, &ss->rx_big.info[idx],
209293f7848bSJeff Kirsher mgp->big_bytes);
209393f7848bSJeff Kirsher put_page(ss->rx_big.info[idx].page);
209493f7848bSJeff Kirsher }
209593f7848bSJeff Kirsher
209693f7848bSJeff Kirsher if (mgp->small_bytes == 0)
209793f7848bSJeff Kirsher ss->rx_small.fill_cnt = ss->rx_small.cnt;
209893f7848bSJeff Kirsher for (i = ss->rx_small.cnt; i < ss->rx_small.fill_cnt; i++) {
209993f7848bSJeff Kirsher idx = i & ss->rx_small.mask;
210093f7848bSJeff Kirsher if (i == ss->rx_small.fill_cnt - 1)
210193f7848bSJeff Kirsher ss->rx_small.info[idx].page_offset =
210293f7848bSJeff Kirsher MYRI10GE_ALLOC_SIZE;
210393f7848bSJeff Kirsher myri10ge_unmap_rx_page(mgp->pdev, &ss->rx_small.info[idx],
210493f7848bSJeff Kirsher mgp->small_bytes + MXGEFW_PAD);
210593f7848bSJeff Kirsher put_page(ss->rx_small.info[idx].page);
210693f7848bSJeff Kirsher }
210793f7848bSJeff Kirsher tx = &ss->tx;
210893f7848bSJeff Kirsher while (tx->done != tx->req) {
210993f7848bSJeff Kirsher idx = tx->done & tx->mask;
211093f7848bSJeff Kirsher skb = tx->info[idx].skb;
211193f7848bSJeff Kirsher
211293f7848bSJeff Kirsher /* Mark as free */
211393f7848bSJeff Kirsher tx->info[idx].skb = NULL;
211493f7848bSJeff Kirsher tx->done++;
211593f7848bSJeff Kirsher len = dma_unmap_len(&tx->info[idx], len);
211693f7848bSJeff Kirsher dma_unmap_len_set(&tx->info[idx], len, 0);
211793f7848bSJeff Kirsher if (skb) {
211893f7848bSJeff Kirsher ss->stats.tx_dropped++;
211993f7848bSJeff Kirsher dev_kfree_skb_any(skb);
212093f7848bSJeff Kirsher if (len)
212175bacb6dSChristophe JAILLET dma_unmap_single(&mgp->pdev->dev,
212293f7848bSJeff Kirsher dma_unmap_addr(&tx->info[idx],
212393f7848bSJeff Kirsher bus), len,
212475bacb6dSChristophe JAILLET DMA_TO_DEVICE);
212593f7848bSJeff Kirsher } else {
212693f7848bSJeff Kirsher if (len)
212775bacb6dSChristophe JAILLET dma_unmap_page(&mgp->pdev->dev,
212893f7848bSJeff Kirsher dma_unmap_addr(&tx->info[idx],
212993f7848bSJeff Kirsher bus), len,
213075bacb6dSChristophe JAILLET DMA_TO_DEVICE);
213193f7848bSJeff Kirsher }
213293f7848bSJeff Kirsher }
213393f7848bSJeff Kirsher kfree(ss->rx_big.info);
213493f7848bSJeff Kirsher
213593f7848bSJeff Kirsher kfree(ss->rx_small.info);
213693f7848bSJeff Kirsher
213793f7848bSJeff Kirsher kfree(ss->tx.info);
213893f7848bSJeff Kirsher
213993f7848bSJeff Kirsher kfree(ss->rx_big.shadow);
214093f7848bSJeff Kirsher
214193f7848bSJeff Kirsher kfree(ss->rx_small.shadow);
214293f7848bSJeff Kirsher
214393f7848bSJeff Kirsher kfree(ss->tx.req_bytes);
214493f7848bSJeff Kirsher ss->tx.req_bytes = NULL;
214593f7848bSJeff Kirsher ss->tx.req_list = NULL;
214693f7848bSJeff Kirsher }
214793f7848bSJeff Kirsher
myri10ge_request_irq(struct myri10ge_priv * mgp)214893f7848bSJeff Kirsher static int myri10ge_request_irq(struct myri10ge_priv *mgp)
214993f7848bSJeff Kirsher {
215093f7848bSJeff Kirsher struct pci_dev *pdev = mgp->pdev;
215193f7848bSJeff Kirsher struct myri10ge_slice_state *ss;
215293f7848bSJeff Kirsher struct net_device *netdev = mgp->dev;
215393f7848bSJeff Kirsher int i;
215493f7848bSJeff Kirsher int status;
215593f7848bSJeff Kirsher
215693f7848bSJeff Kirsher mgp->msi_enabled = 0;
215793f7848bSJeff Kirsher mgp->msix_enabled = 0;
215893f7848bSJeff Kirsher status = 0;
215993f7848bSJeff Kirsher if (myri10ge_msi) {
216093f7848bSJeff Kirsher if (mgp->num_slices > 1) {
21610729cc0cSAlexander Gordeev status = pci_enable_msix_range(pdev, mgp->msix_vectors,
21620729cc0cSAlexander Gordeev mgp->num_slices, mgp->num_slices);
21630729cc0cSAlexander Gordeev if (status < 0) {
216493f7848bSJeff Kirsher dev_err(&pdev->dev,
216593f7848bSJeff Kirsher "Error %d setting up MSI-X\n", status);
216693f7848bSJeff Kirsher return status;
216793f7848bSJeff Kirsher }
21680729cc0cSAlexander Gordeev mgp->msix_enabled = 1;
216993f7848bSJeff Kirsher }
217093f7848bSJeff Kirsher if (mgp->msix_enabled == 0) {
217193f7848bSJeff Kirsher status = pci_enable_msi(pdev);
217293f7848bSJeff Kirsher if (status != 0) {
217393f7848bSJeff Kirsher dev_err(&pdev->dev,
217493f7848bSJeff Kirsher "Error %d setting up MSI; falling back to xPIC\n",
217593f7848bSJeff Kirsher status);
217693f7848bSJeff Kirsher } else {
217793f7848bSJeff Kirsher mgp->msi_enabled = 1;
217893f7848bSJeff Kirsher }
217993f7848bSJeff Kirsher }
218093f7848bSJeff Kirsher }
218193f7848bSJeff Kirsher if (mgp->msix_enabled) {
218293f7848bSJeff Kirsher for (i = 0; i < mgp->num_slices; i++) {
218393f7848bSJeff Kirsher ss = &mgp->ss[i];
218493f7848bSJeff Kirsher snprintf(ss->irq_desc, sizeof(ss->irq_desc),
218593f7848bSJeff Kirsher "%s:slice-%d", netdev->name, i);
218693f7848bSJeff Kirsher status = request_irq(mgp->msix_vectors[i].vector,
218793f7848bSJeff Kirsher myri10ge_intr, 0, ss->irq_desc,
218893f7848bSJeff Kirsher ss);
218993f7848bSJeff Kirsher if (status != 0) {
219093f7848bSJeff Kirsher dev_err(&pdev->dev,
219193f7848bSJeff Kirsher "slice %d failed to allocate IRQ\n", i);
219293f7848bSJeff Kirsher i--;
219393f7848bSJeff Kirsher while (i >= 0) {
219493f7848bSJeff Kirsher free_irq(mgp->msix_vectors[i].vector,
219593f7848bSJeff Kirsher &mgp->ss[i]);
219693f7848bSJeff Kirsher i--;
219793f7848bSJeff Kirsher }
219893f7848bSJeff Kirsher pci_disable_msix(pdev);
219993f7848bSJeff Kirsher return status;
220093f7848bSJeff Kirsher }
220193f7848bSJeff Kirsher }
220293f7848bSJeff Kirsher } else {
220393f7848bSJeff Kirsher status = request_irq(pdev->irq, myri10ge_intr, IRQF_SHARED,
220493f7848bSJeff Kirsher mgp->dev->name, &mgp->ss[0]);
220593f7848bSJeff Kirsher if (status != 0) {
220693f7848bSJeff Kirsher dev_err(&pdev->dev, "failed to allocate IRQ\n");
220793f7848bSJeff Kirsher if (mgp->msi_enabled)
220893f7848bSJeff Kirsher pci_disable_msi(pdev);
220993f7848bSJeff Kirsher }
221093f7848bSJeff Kirsher }
221193f7848bSJeff Kirsher return status;
221293f7848bSJeff Kirsher }
221393f7848bSJeff Kirsher
myri10ge_free_irq(struct myri10ge_priv * mgp)221493f7848bSJeff Kirsher static void myri10ge_free_irq(struct myri10ge_priv *mgp)
221593f7848bSJeff Kirsher {
221693f7848bSJeff Kirsher struct pci_dev *pdev = mgp->pdev;
221793f7848bSJeff Kirsher int i;
221893f7848bSJeff Kirsher
221993f7848bSJeff Kirsher if (mgp->msix_enabled) {
222093f7848bSJeff Kirsher for (i = 0; i < mgp->num_slices; i++)
222193f7848bSJeff Kirsher free_irq(mgp->msix_vectors[i].vector, &mgp->ss[i]);
222293f7848bSJeff Kirsher } else {
222393f7848bSJeff Kirsher free_irq(pdev->irq, &mgp->ss[0]);
222493f7848bSJeff Kirsher }
222593f7848bSJeff Kirsher if (mgp->msi_enabled)
222693f7848bSJeff Kirsher pci_disable_msi(pdev);
222793f7848bSJeff Kirsher if (mgp->msix_enabled)
222893f7848bSJeff Kirsher pci_disable_msix(pdev);
222993f7848bSJeff Kirsher }
223093f7848bSJeff Kirsher
myri10ge_get_txrx(struct myri10ge_priv * mgp,int slice)223193f7848bSJeff Kirsher static int myri10ge_get_txrx(struct myri10ge_priv *mgp, int slice)
223293f7848bSJeff Kirsher {
223393f7848bSJeff Kirsher struct myri10ge_cmd cmd;
223493f7848bSJeff Kirsher struct myri10ge_slice_state *ss;
223593f7848bSJeff Kirsher int status;
223693f7848bSJeff Kirsher
223793f7848bSJeff Kirsher ss = &mgp->ss[slice];
223893f7848bSJeff Kirsher status = 0;
223993f7848bSJeff Kirsher if (slice == 0 || (mgp->dev->real_num_tx_queues > 1)) {
224093f7848bSJeff Kirsher cmd.data0 = slice;
224193f7848bSJeff Kirsher status = myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_SEND_OFFSET,
224293f7848bSJeff Kirsher &cmd, 0);
224393f7848bSJeff Kirsher ss->tx.lanai = (struct mcp_kreq_ether_send __iomem *)
224493f7848bSJeff Kirsher (mgp->sram + cmd.data0);
224593f7848bSJeff Kirsher }
224693f7848bSJeff Kirsher cmd.data0 = slice;
224793f7848bSJeff Kirsher status |= myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_SMALL_RX_OFFSET,
224893f7848bSJeff Kirsher &cmd, 0);
224993f7848bSJeff Kirsher ss->rx_small.lanai = (struct mcp_kreq_ether_recv __iomem *)
225093f7848bSJeff Kirsher (mgp->sram + cmd.data0);
225193f7848bSJeff Kirsher
225293f7848bSJeff Kirsher cmd.data0 = slice;
225393f7848bSJeff Kirsher status |= myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_BIG_RX_OFFSET, &cmd, 0);
225493f7848bSJeff Kirsher ss->rx_big.lanai = (struct mcp_kreq_ether_recv __iomem *)
225593f7848bSJeff Kirsher (mgp->sram + cmd.data0);
225693f7848bSJeff Kirsher
225793f7848bSJeff Kirsher ss->tx.send_go = (__iomem __be32 *)
225893f7848bSJeff Kirsher (mgp->sram + MXGEFW_ETH_SEND_GO + 64 * slice);
225993f7848bSJeff Kirsher ss->tx.send_stop = (__iomem __be32 *)
226093f7848bSJeff Kirsher (mgp->sram + MXGEFW_ETH_SEND_STOP + 64 * slice);
226193f7848bSJeff Kirsher return status;
226293f7848bSJeff Kirsher
226393f7848bSJeff Kirsher }
226493f7848bSJeff Kirsher
myri10ge_set_stats(struct myri10ge_priv * mgp,int slice)226593f7848bSJeff Kirsher static int myri10ge_set_stats(struct myri10ge_priv *mgp, int slice)
226693f7848bSJeff Kirsher {
226793f7848bSJeff Kirsher struct myri10ge_cmd cmd;
226893f7848bSJeff Kirsher struct myri10ge_slice_state *ss;
226993f7848bSJeff Kirsher int status;
227093f7848bSJeff Kirsher
227193f7848bSJeff Kirsher ss = &mgp->ss[slice];
227293f7848bSJeff Kirsher cmd.data0 = MYRI10GE_LOWPART_TO_U32(ss->fw_stats_bus);
227393f7848bSJeff Kirsher cmd.data1 = MYRI10GE_HIGHPART_TO_U32(ss->fw_stats_bus);
227493f7848bSJeff Kirsher cmd.data2 = sizeof(struct mcp_irq_data) | (slice << 16);
227593f7848bSJeff Kirsher status = myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_STATS_DMA_V2, &cmd, 0);
227693f7848bSJeff Kirsher if (status == -ENOSYS) {
227793f7848bSJeff Kirsher dma_addr_t bus = ss->fw_stats_bus;
227893f7848bSJeff Kirsher if (slice != 0)
227993f7848bSJeff Kirsher return -EINVAL;
228093f7848bSJeff Kirsher bus += offsetof(struct mcp_irq_data, send_done_count);
228193f7848bSJeff Kirsher cmd.data0 = MYRI10GE_LOWPART_TO_U32(bus);
228293f7848bSJeff Kirsher cmd.data1 = MYRI10GE_HIGHPART_TO_U32(bus);
228393f7848bSJeff Kirsher status = myri10ge_send_cmd(mgp,
228493f7848bSJeff Kirsher MXGEFW_CMD_SET_STATS_DMA_OBSOLETE,
228593f7848bSJeff Kirsher &cmd, 0);
228693f7848bSJeff Kirsher /* Firmware cannot support multicast without STATS_DMA_V2 */
228793f7848bSJeff Kirsher mgp->fw_multicast_support = 0;
228893f7848bSJeff Kirsher } else {
228993f7848bSJeff Kirsher mgp->fw_multicast_support = 1;
229093f7848bSJeff Kirsher }
229193f7848bSJeff Kirsher return 0;
229293f7848bSJeff Kirsher }
229393f7848bSJeff Kirsher
myri10ge_open(struct net_device * dev)229493f7848bSJeff Kirsher static int myri10ge_open(struct net_device *dev)
229593f7848bSJeff Kirsher {
229693f7848bSJeff Kirsher struct myri10ge_slice_state *ss;
229793f7848bSJeff Kirsher struct myri10ge_priv *mgp = netdev_priv(dev);
229893f7848bSJeff Kirsher struct myri10ge_cmd cmd;
229993f7848bSJeff Kirsher int i, status, big_pow2, slice;
230059e955edSAndrew Gallatin u8 __iomem *itable;
230193f7848bSJeff Kirsher
230293f7848bSJeff Kirsher if (mgp->running != MYRI10GE_ETH_STOPPED)
230393f7848bSJeff Kirsher return -EBUSY;
230493f7848bSJeff Kirsher
230593f7848bSJeff Kirsher mgp->running = MYRI10GE_ETH_STARTING;
230693f7848bSJeff Kirsher status = myri10ge_reset(mgp);
230793f7848bSJeff Kirsher if (status != 0) {
230893f7848bSJeff Kirsher netdev_err(dev, "failed reset\n");
230993f7848bSJeff Kirsher goto abort_with_nothing;
231093f7848bSJeff Kirsher }
231193f7848bSJeff Kirsher
231293f7848bSJeff Kirsher if (mgp->num_slices > 1) {
231393f7848bSJeff Kirsher cmd.data0 = mgp->num_slices;
231493f7848bSJeff Kirsher cmd.data1 = MXGEFW_SLICE_INTR_MODE_ONE_PER_SLICE;
231593f7848bSJeff Kirsher if (mgp->dev->real_num_tx_queues > 1)
231693f7848bSJeff Kirsher cmd.data1 |= MXGEFW_SLICE_ENABLE_MULTIPLE_TX_QUEUES;
231793f7848bSJeff Kirsher status = myri10ge_send_cmd(mgp, MXGEFW_CMD_ENABLE_RSS_QUEUES,
231893f7848bSJeff Kirsher &cmd, 0);
231993f7848bSJeff Kirsher if (status != 0) {
232093f7848bSJeff Kirsher netdev_err(dev, "failed to set number of slices\n");
232193f7848bSJeff Kirsher goto abort_with_nothing;
232293f7848bSJeff Kirsher }
232393f7848bSJeff Kirsher /* setup the indirection table */
232493f7848bSJeff Kirsher cmd.data0 = mgp->num_slices;
232593f7848bSJeff Kirsher status = myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_RSS_TABLE_SIZE,
232693f7848bSJeff Kirsher &cmd, 0);
232793f7848bSJeff Kirsher
232893f7848bSJeff Kirsher status |= myri10ge_send_cmd(mgp,
232993f7848bSJeff Kirsher MXGEFW_CMD_GET_RSS_TABLE_OFFSET,
233093f7848bSJeff Kirsher &cmd, 0);
233193f7848bSJeff Kirsher if (status != 0) {
233293f7848bSJeff Kirsher netdev_err(dev, "failed to setup rss tables\n");
233393f7848bSJeff Kirsher goto abort_with_nothing;
233493f7848bSJeff Kirsher }
233593f7848bSJeff Kirsher
233693f7848bSJeff Kirsher /* just enable an identity mapping */
233793f7848bSJeff Kirsher itable = mgp->sram + cmd.data0;
233893f7848bSJeff Kirsher for (i = 0; i < mgp->num_slices; i++)
233993f7848bSJeff Kirsher __raw_writeb(i, &itable[i]);
234093f7848bSJeff Kirsher
234193f7848bSJeff Kirsher cmd.data0 = 1;
234293f7848bSJeff Kirsher cmd.data1 = myri10ge_rss_hash;
234393f7848bSJeff Kirsher status = myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_RSS_ENABLE,
234493f7848bSJeff Kirsher &cmd, 0);
234593f7848bSJeff Kirsher if (status != 0) {
234693f7848bSJeff Kirsher netdev_err(dev, "failed to enable slices\n");
234793f7848bSJeff Kirsher goto abort_with_nothing;
234893f7848bSJeff Kirsher }
234993f7848bSJeff Kirsher }
235093f7848bSJeff Kirsher
235193f7848bSJeff Kirsher status = myri10ge_request_irq(mgp);
235293f7848bSJeff Kirsher if (status != 0)
235393f7848bSJeff Kirsher goto abort_with_nothing;
235493f7848bSJeff Kirsher
235593f7848bSJeff Kirsher /* decide what small buffer size to use. For good TCP rx
235693f7848bSJeff Kirsher * performance, it is important to not receive 1514 byte
235793f7848bSJeff Kirsher * frames into jumbo buffers, as it confuses the socket buffer
235893f7848bSJeff Kirsher * accounting code, leading to drops and erratic performance.
235993f7848bSJeff Kirsher */
236093f7848bSJeff Kirsher
236193f7848bSJeff Kirsher if (dev->mtu <= ETH_DATA_LEN)
236293f7848bSJeff Kirsher /* enough for a TCP header */
236393f7848bSJeff Kirsher mgp->small_bytes = (128 > SMP_CACHE_BYTES)
236493f7848bSJeff Kirsher ? (128 - MXGEFW_PAD)
236593f7848bSJeff Kirsher : (SMP_CACHE_BYTES - MXGEFW_PAD);
236693f7848bSJeff Kirsher else
236793f7848bSJeff Kirsher /* enough for a vlan encapsulated ETH_DATA_LEN frame */
236893f7848bSJeff Kirsher mgp->small_bytes = VLAN_ETH_FRAME_LEN;
236993f7848bSJeff Kirsher
237093f7848bSJeff Kirsher /* Override the small buffer size? */
237193f7848bSJeff Kirsher if (myri10ge_small_bytes >= 0)
237293f7848bSJeff Kirsher mgp->small_bytes = myri10ge_small_bytes;
237393f7848bSJeff Kirsher
237493f7848bSJeff Kirsher /* Firmware needs the big buff size as a power of 2. Lie and
237593f7848bSJeff Kirsher * tell him the buffer is larger, because we only use 1
237693f7848bSJeff Kirsher * buffer/pkt, and the mtu will prevent overruns.
237793f7848bSJeff Kirsher */
237893f7848bSJeff Kirsher big_pow2 = dev->mtu + ETH_HLEN + VLAN_HLEN + MXGEFW_PAD;
237993f7848bSJeff Kirsher if (big_pow2 < MYRI10GE_ALLOC_SIZE / 2) {
238093f7848bSJeff Kirsher while (!is_power_of_2(big_pow2))
238193f7848bSJeff Kirsher big_pow2++;
238293f7848bSJeff Kirsher mgp->big_bytes = dev->mtu + ETH_HLEN + VLAN_HLEN + MXGEFW_PAD;
238393f7848bSJeff Kirsher } else {
238493f7848bSJeff Kirsher big_pow2 = MYRI10GE_ALLOC_SIZE;
238593f7848bSJeff Kirsher mgp->big_bytes = big_pow2;
238693f7848bSJeff Kirsher }
238793f7848bSJeff Kirsher
238893f7848bSJeff Kirsher /* setup the per-slice data structures */
238993f7848bSJeff Kirsher for (slice = 0; slice < mgp->num_slices; slice++) {
239093f7848bSJeff Kirsher ss = &mgp->ss[slice];
239193f7848bSJeff Kirsher
239293f7848bSJeff Kirsher status = myri10ge_get_txrx(mgp, slice);
239393f7848bSJeff Kirsher if (status != 0) {
239493f7848bSJeff Kirsher netdev_err(dev, "failed to get ring sizes or locations\n");
239593f7848bSJeff Kirsher goto abort_with_rings;
239693f7848bSJeff Kirsher }
239793f7848bSJeff Kirsher status = myri10ge_allocate_rings(ss);
239893f7848bSJeff Kirsher if (status != 0)
239993f7848bSJeff Kirsher goto abort_with_rings;
240093f7848bSJeff Kirsher
240193f7848bSJeff Kirsher /* only firmware which supports multiple TX queues
240293f7848bSJeff Kirsher * supports setting up the tx stats on non-zero
240393f7848bSJeff Kirsher * slices */
240493f7848bSJeff Kirsher if (slice == 0 || mgp->dev->real_num_tx_queues > 1)
240593f7848bSJeff Kirsher status = myri10ge_set_stats(mgp, slice);
240693f7848bSJeff Kirsher if (status) {
240793f7848bSJeff Kirsher netdev_err(dev, "Couldn't set stats DMA\n");
240893f7848bSJeff Kirsher goto abort_with_rings;
240993f7848bSJeff Kirsher }
241093f7848bSJeff Kirsher
241193f7848bSJeff Kirsher /* must happen prior to any irq */
241293f7848bSJeff Kirsher napi_enable(&(ss)->napi);
241393f7848bSJeff Kirsher }
241493f7848bSJeff Kirsher
241593f7848bSJeff Kirsher /* now give firmware buffers sizes, and MTU */
241693f7848bSJeff Kirsher cmd.data0 = dev->mtu + ETH_HLEN + VLAN_HLEN;
241793f7848bSJeff Kirsher status = myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_MTU, &cmd, 0);
241893f7848bSJeff Kirsher cmd.data0 = mgp->small_bytes;
241993f7848bSJeff Kirsher status |=
242093f7848bSJeff Kirsher myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_SMALL_BUFFER_SIZE, &cmd, 0);
242193f7848bSJeff Kirsher cmd.data0 = big_pow2;
242293f7848bSJeff Kirsher status |=
242393f7848bSJeff Kirsher myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_BIG_BUFFER_SIZE, &cmd, 0);
242493f7848bSJeff Kirsher if (status) {
242593f7848bSJeff Kirsher netdev_err(dev, "Couldn't set buffer sizes\n");
242693f7848bSJeff Kirsher goto abort_with_rings;
242793f7848bSJeff Kirsher }
242893f7848bSJeff Kirsher
242993f7848bSJeff Kirsher /*
243093f7848bSJeff Kirsher * Set Linux style TSO mode; this is needed only on newer
243193f7848bSJeff Kirsher * firmware versions. Older versions default to Linux
243293f7848bSJeff Kirsher * style TSO
243393f7848bSJeff Kirsher */
243493f7848bSJeff Kirsher cmd.data0 = 0;
243593f7848bSJeff Kirsher status = myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_TSO_MODE, &cmd, 0);
243693f7848bSJeff Kirsher if (status && status != -ENOSYS) {
243793f7848bSJeff Kirsher netdev_err(dev, "Couldn't set TSO mode\n");
243893f7848bSJeff Kirsher goto abort_with_rings;
243993f7848bSJeff Kirsher }
244093f7848bSJeff Kirsher
244193f7848bSJeff Kirsher mgp->link_state = ~0U;
244293f7848bSJeff Kirsher mgp->rdma_tags_available = 15;
244393f7848bSJeff Kirsher
244493f7848bSJeff Kirsher status = myri10ge_send_cmd(mgp, MXGEFW_CMD_ETHERNET_UP, &cmd, 0);
244593f7848bSJeff Kirsher if (status) {
244693f7848bSJeff Kirsher netdev_err(dev, "Couldn't bring up link\n");
244793f7848bSJeff Kirsher goto abort_with_rings;
244893f7848bSJeff Kirsher }
244993f7848bSJeff Kirsher
245093f7848bSJeff Kirsher mgp->running = MYRI10GE_ETH_RUNNING;
245193f7848bSJeff Kirsher mgp->watchdog_timer.expires = jiffies + myri10ge_watchdog_timeout * HZ;
245293f7848bSJeff Kirsher add_timer(&mgp->watchdog_timer);
245393f7848bSJeff Kirsher netif_tx_wake_all_queues(dev);
245493f7848bSJeff Kirsher
245593f7848bSJeff Kirsher return 0;
245693f7848bSJeff Kirsher
245793f7848bSJeff Kirsher abort_with_rings:
245893f7848bSJeff Kirsher while (slice) {
245993f7848bSJeff Kirsher slice--;
246093f7848bSJeff Kirsher napi_disable(&mgp->ss[slice].napi);
246193f7848bSJeff Kirsher }
246293f7848bSJeff Kirsher for (i = 0; i < mgp->num_slices; i++)
246393f7848bSJeff Kirsher myri10ge_free_rings(&mgp->ss[i]);
246493f7848bSJeff Kirsher
246593f7848bSJeff Kirsher myri10ge_free_irq(mgp);
246693f7848bSJeff Kirsher
246793f7848bSJeff Kirsher abort_with_nothing:
246893f7848bSJeff Kirsher mgp->running = MYRI10GE_ETH_STOPPED;
246993f7848bSJeff Kirsher return -ENOMEM;
247093f7848bSJeff Kirsher }
247193f7848bSJeff Kirsher
myri10ge_close(struct net_device * dev)247293f7848bSJeff Kirsher static int myri10ge_close(struct net_device *dev)
247393f7848bSJeff Kirsher {
247493f7848bSJeff Kirsher struct myri10ge_priv *mgp = netdev_priv(dev);
247593f7848bSJeff Kirsher struct myri10ge_cmd cmd;
247693f7848bSJeff Kirsher int status, old_down_cnt;
247793f7848bSJeff Kirsher int i;
247893f7848bSJeff Kirsher
247993f7848bSJeff Kirsher if (mgp->running != MYRI10GE_ETH_RUNNING)
248093f7848bSJeff Kirsher return 0;
248193f7848bSJeff Kirsher
248293f7848bSJeff Kirsher if (mgp->ss[0].tx.req_bytes == NULL)
248393f7848bSJeff Kirsher return 0;
248493f7848bSJeff Kirsher
248593f7848bSJeff Kirsher del_timer_sync(&mgp->watchdog_timer);
248693f7848bSJeff Kirsher mgp->running = MYRI10GE_ETH_STOPPING;
2487362108b5SEric Dumazet for (i = 0; i < mgp->num_slices; i++)
248893f7848bSJeff Kirsher napi_disable(&mgp->ss[i].napi);
2489362108b5SEric Dumazet
249093f7848bSJeff Kirsher netif_carrier_off(dev);
249193f7848bSJeff Kirsher
249293f7848bSJeff Kirsher netif_tx_stop_all_queues(dev);
249393f7848bSJeff Kirsher if (mgp->rebooted == 0) {
249493f7848bSJeff Kirsher old_down_cnt = mgp->down_cnt;
249593f7848bSJeff Kirsher mb();
249693f7848bSJeff Kirsher status =
249793f7848bSJeff Kirsher myri10ge_send_cmd(mgp, MXGEFW_CMD_ETHERNET_DOWN, &cmd, 0);
249893f7848bSJeff Kirsher if (status)
249993f7848bSJeff Kirsher netdev_err(dev, "Couldn't bring down link\n");
250093f7848bSJeff Kirsher
250193f7848bSJeff Kirsher wait_event_timeout(mgp->down_wq, old_down_cnt != mgp->down_cnt,
250293f7848bSJeff Kirsher HZ);
250393f7848bSJeff Kirsher if (old_down_cnt == mgp->down_cnt)
250493f7848bSJeff Kirsher netdev_err(dev, "never got down irq\n");
250593f7848bSJeff Kirsher }
250693f7848bSJeff Kirsher netif_tx_disable(dev);
250793f7848bSJeff Kirsher myri10ge_free_irq(mgp);
250893f7848bSJeff Kirsher for (i = 0; i < mgp->num_slices; i++)
250993f7848bSJeff Kirsher myri10ge_free_rings(&mgp->ss[i]);
251093f7848bSJeff Kirsher
251193f7848bSJeff Kirsher mgp->running = MYRI10GE_ETH_STOPPED;
251293f7848bSJeff Kirsher return 0;
251393f7848bSJeff Kirsher }
251493f7848bSJeff Kirsher
251593f7848bSJeff Kirsher /* copy an array of struct mcp_kreq_ether_send's to the mcp. Copy
251693f7848bSJeff Kirsher * backwards one at a time and handle ring wraps */
251793f7848bSJeff Kirsher
251893f7848bSJeff Kirsher static inline void
myri10ge_submit_req_backwards(struct myri10ge_tx_buf * tx,struct mcp_kreq_ether_send * src,int cnt)251993f7848bSJeff Kirsher myri10ge_submit_req_backwards(struct myri10ge_tx_buf *tx,
252093f7848bSJeff Kirsher struct mcp_kreq_ether_send *src, int cnt)
252193f7848bSJeff Kirsher {
252293f7848bSJeff Kirsher int idx, starting_slot;
252393f7848bSJeff Kirsher starting_slot = tx->req;
252493f7848bSJeff Kirsher while (cnt > 1) {
252593f7848bSJeff Kirsher cnt--;
252693f7848bSJeff Kirsher idx = (starting_slot + cnt) & tx->mask;
252793f7848bSJeff Kirsher myri10ge_pio_copy(&tx->lanai[idx], &src[cnt], sizeof(*src));
252893f7848bSJeff Kirsher mb();
252993f7848bSJeff Kirsher }
253093f7848bSJeff Kirsher }
253193f7848bSJeff Kirsher
253293f7848bSJeff Kirsher /*
253393f7848bSJeff Kirsher * copy an array of struct mcp_kreq_ether_send's to the mcp. Copy
253493f7848bSJeff Kirsher * at most 32 bytes at a time, so as to avoid involving the software
253593f7848bSJeff Kirsher * pio handler in the nic. We re-write the first segment's flags
253693f7848bSJeff Kirsher * to mark them valid only after writing the entire chain.
253793f7848bSJeff Kirsher */
253893f7848bSJeff Kirsher
253993f7848bSJeff Kirsher static inline void
myri10ge_submit_req(struct myri10ge_tx_buf * tx,struct mcp_kreq_ether_send * src,int cnt)254093f7848bSJeff Kirsher myri10ge_submit_req(struct myri10ge_tx_buf *tx, struct mcp_kreq_ether_send *src,
254193f7848bSJeff Kirsher int cnt)
254293f7848bSJeff Kirsher {
254393f7848bSJeff Kirsher int idx, i;
254493f7848bSJeff Kirsher struct mcp_kreq_ether_send __iomem *dstp, *dst;
254593f7848bSJeff Kirsher struct mcp_kreq_ether_send *srcp;
254693f7848bSJeff Kirsher u8 last_flags;
254793f7848bSJeff Kirsher
254893f7848bSJeff Kirsher idx = tx->req & tx->mask;
254993f7848bSJeff Kirsher
255093f7848bSJeff Kirsher last_flags = src->flags;
255193f7848bSJeff Kirsher src->flags = 0;
255293f7848bSJeff Kirsher mb();
255393f7848bSJeff Kirsher dst = dstp = &tx->lanai[idx];
255493f7848bSJeff Kirsher srcp = src;
255593f7848bSJeff Kirsher
255693f7848bSJeff Kirsher if ((idx + cnt) < tx->mask) {
255793f7848bSJeff Kirsher for (i = 0; i < (cnt - 1); i += 2) {
255893f7848bSJeff Kirsher myri10ge_pio_copy(dstp, srcp, 2 * sizeof(*src));
255993f7848bSJeff Kirsher mb(); /* force write every 32 bytes */
256093f7848bSJeff Kirsher srcp += 2;
256193f7848bSJeff Kirsher dstp += 2;
256293f7848bSJeff Kirsher }
256393f7848bSJeff Kirsher } else {
256493f7848bSJeff Kirsher /* submit all but the first request, and ensure
256593f7848bSJeff Kirsher * that it is submitted below */
256693f7848bSJeff Kirsher myri10ge_submit_req_backwards(tx, src, cnt);
256793f7848bSJeff Kirsher i = 0;
256893f7848bSJeff Kirsher }
256993f7848bSJeff Kirsher if (i < cnt) {
257093f7848bSJeff Kirsher /* submit the first request */
257193f7848bSJeff Kirsher myri10ge_pio_copy(dstp, srcp, sizeof(*src));
257293f7848bSJeff Kirsher mb(); /* barrier before setting valid flag */
257393f7848bSJeff Kirsher }
257493f7848bSJeff Kirsher
257593f7848bSJeff Kirsher /* re-write the last 32-bits with the valid flags */
257693f7848bSJeff Kirsher src->flags = last_flags;
257793f7848bSJeff Kirsher put_be32(*((__be32 *) src + 3), (__be32 __iomem *) dst + 3);
257893f7848bSJeff Kirsher tx->req += cnt;
257993f7848bSJeff Kirsher mb();
258093f7848bSJeff Kirsher }
258193f7848bSJeff Kirsher
myri10ge_unmap_tx_dma(struct myri10ge_priv * mgp,struct myri10ge_tx_buf * tx,int idx)258210545937SStanislaw Gruszka static void myri10ge_unmap_tx_dma(struct myri10ge_priv *mgp,
258310545937SStanislaw Gruszka struct myri10ge_tx_buf *tx, int idx)
258410545937SStanislaw Gruszka {
258510545937SStanislaw Gruszka unsigned int len;
258610545937SStanislaw Gruszka int last_idx;
258710545937SStanislaw Gruszka
258810545937SStanislaw Gruszka /* Free any DMA resources we've alloced and clear out the skb slot */
258910545937SStanislaw Gruszka last_idx = (idx + 1) & tx->mask;
259010545937SStanislaw Gruszka idx = tx->req & tx->mask;
259110545937SStanislaw Gruszka do {
259210545937SStanislaw Gruszka len = dma_unmap_len(&tx->info[idx], len);
259310545937SStanislaw Gruszka if (len) {
259410545937SStanislaw Gruszka if (tx->info[idx].skb != NULL)
259575bacb6dSChristophe JAILLET dma_unmap_single(&mgp->pdev->dev,
259610545937SStanislaw Gruszka dma_unmap_addr(&tx->info[idx],
259710545937SStanislaw Gruszka bus), len,
259875bacb6dSChristophe JAILLET DMA_TO_DEVICE);
259910545937SStanislaw Gruszka else
260075bacb6dSChristophe JAILLET dma_unmap_page(&mgp->pdev->dev,
260110545937SStanislaw Gruszka dma_unmap_addr(&tx->info[idx],
260210545937SStanislaw Gruszka bus), len,
260375bacb6dSChristophe JAILLET DMA_TO_DEVICE);
260410545937SStanislaw Gruszka dma_unmap_len_set(&tx->info[idx], len, 0);
260510545937SStanislaw Gruszka tx->info[idx].skb = NULL;
260610545937SStanislaw Gruszka }
260710545937SStanislaw Gruszka idx = (idx + 1) & tx->mask;
260810545937SStanislaw Gruszka } while (idx != last_idx);
260910545937SStanislaw Gruszka }
261010545937SStanislaw Gruszka
261193f7848bSJeff Kirsher /*
261293f7848bSJeff Kirsher * Transmit a packet. We need to split the packet so that a single
261393f7848bSJeff Kirsher * segment does not cross myri10ge->tx_boundary, so this makes segment
261493f7848bSJeff Kirsher * counting tricky. So rather than try to count segments up front, we
261593f7848bSJeff Kirsher * just give up if there are too few segments to hold a reasonably
261693f7848bSJeff Kirsher * fragmented packet currently available. If we run
261793f7848bSJeff Kirsher * out of segments while preparing a packet for DMA, we just linearize
261893f7848bSJeff Kirsher * it and try again.
261993f7848bSJeff Kirsher */
262093f7848bSJeff Kirsher
myri10ge_xmit(struct sk_buff * skb,struct net_device * dev)262193f7848bSJeff Kirsher static netdev_tx_t myri10ge_xmit(struct sk_buff *skb,
262293f7848bSJeff Kirsher struct net_device *dev)
262393f7848bSJeff Kirsher {
262493f7848bSJeff Kirsher struct myri10ge_priv *mgp = netdev_priv(dev);
262593f7848bSJeff Kirsher struct myri10ge_slice_state *ss;
262693f7848bSJeff Kirsher struct mcp_kreq_ether_send *req;
262793f7848bSJeff Kirsher struct myri10ge_tx_buf *tx;
2628d7840976SMatthew Wilcox (Oracle) skb_frag_t *frag;
262993f7848bSJeff Kirsher struct netdev_queue *netdev_queue;
263093f7848bSJeff Kirsher dma_addr_t bus;
263193f7848bSJeff Kirsher u32 low;
263293f7848bSJeff Kirsher __be32 high_swapped;
263393f7848bSJeff Kirsher unsigned int len;
263410545937SStanislaw Gruszka int idx, avail, frag_cnt, frag_idx, count, mss, max_segments;
263593f7848bSJeff Kirsher u16 pseudo_hdr_offset, cksum_offset, queue;
263693f7848bSJeff Kirsher int cum_len, seglen, boundary, rdma_count;
263793f7848bSJeff Kirsher u8 flags, odd_flag;
263893f7848bSJeff Kirsher
263993f7848bSJeff Kirsher queue = skb_get_queue_mapping(skb);
264093f7848bSJeff Kirsher ss = &mgp->ss[queue];
264193f7848bSJeff Kirsher netdev_queue = netdev_get_tx_queue(mgp->dev, queue);
264293f7848bSJeff Kirsher tx = &ss->tx;
264393f7848bSJeff Kirsher
264493f7848bSJeff Kirsher again:
264593f7848bSJeff Kirsher req = tx->req_list;
264693f7848bSJeff Kirsher avail = tx->mask - 1 - (tx->req - tx->done);
264793f7848bSJeff Kirsher
264893f7848bSJeff Kirsher mss = 0;
264993f7848bSJeff Kirsher max_segments = MXGEFW_MAX_SEND_DESC;
265093f7848bSJeff Kirsher
265193f7848bSJeff Kirsher if (skb_is_gso(skb)) {
265293f7848bSJeff Kirsher mss = skb_shinfo(skb)->gso_size;
265393f7848bSJeff Kirsher max_segments = MYRI10GE_MAX_SEND_DESC_TSO;
265493f7848bSJeff Kirsher }
265593f7848bSJeff Kirsher
265693f7848bSJeff Kirsher if ((unlikely(avail < max_segments))) {
265793f7848bSJeff Kirsher /* we are out of transmit resources */
265893f7848bSJeff Kirsher tx->stop_queue++;
265993f7848bSJeff Kirsher netif_tx_stop_queue(netdev_queue);
266093f7848bSJeff Kirsher return NETDEV_TX_BUSY;
266193f7848bSJeff Kirsher }
266293f7848bSJeff Kirsher
266393f7848bSJeff Kirsher /* Setup checksum offloading, if needed */
266493f7848bSJeff Kirsher cksum_offset = 0;
266593f7848bSJeff Kirsher pseudo_hdr_offset = 0;
266693f7848bSJeff Kirsher odd_flag = 0;
266793f7848bSJeff Kirsher flags = (MXGEFW_FLAGS_NO_TSO | MXGEFW_FLAGS_FIRST);
266893f7848bSJeff Kirsher if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
266993f7848bSJeff Kirsher cksum_offset = skb_checksum_start_offset(skb);
267093f7848bSJeff Kirsher pseudo_hdr_offset = cksum_offset + skb->csum_offset;
267193f7848bSJeff Kirsher /* If the headers are excessively large, then we must
267293f7848bSJeff Kirsher * fall back to a software checksum */
267393f7848bSJeff Kirsher if (unlikely(!mss && (cksum_offset > 255 ||
267493f7848bSJeff Kirsher pseudo_hdr_offset > 127))) {
267593f7848bSJeff Kirsher if (skb_checksum_help(skb))
267693f7848bSJeff Kirsher goto drop;
267793f7848bSJeff Kirsher cksum_offset = 0;
267893f7848bSJeff Kirsher pseudo_hdr_offset = 0;
267993f7848bSJeff Kirsher } else {
268093f7848bSJeff Kirsher odd_flag = MXGEFW_FLAGS_ALIGN_ODD;
268193f7848bSJeff Kirsher flags |= MXGEFW_FLAGS_CKSUM;
268293f7848bSJeff Kirsher }
268393f7848bSJeff Kirsher }
268493f7848bSJeff Kirsher
268593f7848bSJeff Kirsher cum_len = 0;
268693f7848bSJeff Kirsher
268793f7848bSJeff Kirsher if (mss) { /* TSO */
268893f7848bSJeff Kirsher /* this removes any CKSUM flag from before */
268993f7848bSJeff Kirsher flags = (MXGEFW_FLAGS_TSO_HDR | MXGEFW_FLAGS_FIRST);
269093f7848bSJeff Kirsher
269193f7848bSJeff Kirsher /* negative cum_len signifies to the
269293f7848bSJeff Kirsher * send loop that we are still in the
269393f7848bSJeff Kirsher * header portion of the TSO packet.
269493f7848bSJeff Kirsher * TSO header can be at most 1KB long */
2695504148feSEric Dumazet cum_len = -skb_tcp_all_headers(skb);
269693f7848bSJeff Kirsher
269793f7848bSJeff Kirsher /* for IPv6 TSO, the checksum offset stores the
269893f7848bSJeff Kirsher * TCP header length, to save the firmware from
269993f7848bSJeff Kirsher * the need to parse the headers */
270093f7848bSJeff Kirsher if (skb_is_gso_v6(skb)) {
270193f7848bSJeff Kirsher cksum_offset = tcp_hdrlen(skb);
270293f7848bSJeff Kirsher /* Can only handle headers <= max_tso6 long */
270393f7848bSJeff Kirsher if (unlikely(-cum_len > mgp->max_tso6))
270493f7848bSJeff Kirsher return myri10ge_sw_tso(skb, dev);
270593f7848bSJeff Kirsher }
270693f7848bSJeff Kirsher /* for TSO, pseudo_hdr_offset holds mss.
270793f7848bSJeff Kirsher * The firmware figures out where to put
270893f7848bSJeff Kirsher * the checksum by parsing the header. */
270993f7848bSJeff Kirsher pseudo_hdr_offset = mss;
271093f7848bSJeff Kirsher } else
271193f7848bSJeff Kirsher /* Mark small packets, and pad out tiny packets */
271293f7848bSJeff Kirsher if (skb->len <= MXGEFW_SEND_SMALL_SIZE) {
271393f7848bSJeff Kirsher flags |= MXGEFW_FLAGS_SMALL;
271493f7848bSJeff Kirsher
271593f7848bSJeff Kirsher /* pad frames to at least ETH_ZLEN bytes */
2716b0b9f333SAlexander Duyck if (eth_skb_pad(skb)) {
271793f7848bSJeff Kirsher /* The packet is gone, so we must
271893f7848bSJeff Kirsher * return 0 */
271993f7848bSJeff Kirsher ss->stats.tx_dropped += 1;
272093f7848bSJeff Kirsher return NETDEV_TX_OK;
272193f7848bSJeff Kirsher }
272293f7848bSJeff Kirsher }
272393f7848bSJeff Kirsher
272493f7848bSJeff Kirsher /* map the skb for DMA */
272593f7848bSJeff Kirsher len = skb_headlen(skb);
272675bacb6dSChristophe JAILLET bus = dma_map_single(&mgp->pdev->dev, skb->data, len, DMA_TO_DEVICE);
272775bacb6dSChristophe JAILLET if (unlikely(dma_mapping_error(&mgp->pdev->dev, bus)))
272810545937SStanislaw Gruszka goto drop;
272910545937SStanislaw Gruszka
273093f7848bSJeff Kirsher idx = tx->req & tx->mask;
273193f7848bSJeff Kirsher tx->info[idx].skb = skb;
273293f7848bSJeff Kirsher dma_unmap_addr_set(&tx->info[idx], bus, bus);
273393f7848bSJeff Kirsher dma_unmap_len_set(&tx->info[idx], len, len);
273493f7848bSJeff Kirsher
273593f7848bSJeff Kirsher frag_cnt = skb_shinfo(skb)->nr_frags;
273693f7848bSJeff Kirsher frag_idx = 0;
273793f7848bSJeff Kirsher count = 0;
273893f7848bSJeff Kirsher rdma_count = 0;
273993f7848bSJeff Kirsher
274093f7848bSJeff Kirsher /* "rdma_count" is the number of RDMAs belonging to the
274193f7848bSJeff Kirsher * current packet BEFORE the current send request. For
274293f7848bSJeff Kirsher * non-TSO packets, this is equal to "count".
274393f7848bSJeff Kirsher * For TSO packets, rdma_count needs to be reset
274493f7848bSJeff Kirsher * to 0 after a segment cut.
274593f7848bSJeff Kirsher *
274693f7848bSJeff Kirsher * The rdma_count field of the send request is
274793f7848bSJeff Kirsher * the number of RDMAs of the packet starting at
274893f7848bSJeff Kirsher * that request. For TSO send requests with one ore more cuts
274993f7848bSJeff Kirsher * in the middle, this is the number of RDMAs starting
275093f7848bSJeff Kirsher * after the last cut in the request. All previous
275193f7848bSJeff Kirsher * segments before the last cut implicitly have 1 RDMA.
275293f7848bSJeff Kirsher *
275393f7848bSJeff Kirsher * Since the number of RDMAs is not known beforehand,
275493f7848bSJeff Kirsher * it must be filled-in retroactively - after each
275593f7848bSJeff Kirsher * segmentation cut or at the end of the entire packet.
275693f7848bSJeff Kirsher */
275793f7848bSJeff Kirsher
275893f7848bSJeff Kirsher while (1) {
275993f7848bSJeff Kirsher /* Break the SKB or Fragment up into pieces which
276093f7848bSJeff Kirsher * do not cross mgp->tx_boundary */
276193f7848bSJeff Kirsher low = MYRI10GE_LOWPART_TO_U32(bus);
276293f7848bSJeff Kirsher high_swapped = htonl(MYRI10GE_HIGHPART_TO_U32(bus));
276393f7848bSJeff Kirsher while (len) {
276493f7848bSJeff Kirsher u8 flags_next;
276593f7848bSJeff Kirsher int cum_len_next;
276693f7848bSJeff Kirsher
276793f7848bSJeff Kirsher if (unlikely(count == max_segments))
276893f7848bSJeff Kirsher goto abort_linearize;
276993f7848bSJeff Kirsher
277093f7848bSJeff Kirsher boundary =
277193f7848bSJeff Kirsher (low + mgp->tx_boundary) & ~(mgp->tx_boundary - 1);
277293f7848bSJeff Kirsher seglen = boundary - low;
277393f7848bSJeff Kirsher if (seglen > len)
277493f7848bSJeff Kirsher seglen = len;
277593f7848bSJeff Kirsher flags_next = flags & ~MXGEFW_FLAGS_FIRST;
277693f7848bSJeff Kirsher cum_len_next = cum_len + seglen;
277793f7848bSJeff Kirsher if (mss) { /* TSO */
277893f7848bSJeff Kirsher (req - rdma_count)->rdma_count = rdma_count + 1;
277993f7848bSJeff Kirsher
278093f7848bSJeff Kirsher if (likely(cum_len >= 0)) { /* payload */
278193f7848bSJeff Kirsher int next_is_first, chop;
278293f7848bSJeff Kirsher
278393f7848bSJeff Kirsher chop = (cum_len_next > mss);
278493f7848bSJeff Kirsher cum_len_next = cum_len_next % mss;
278593f7848bSJeff Kirsher next_is_first = (cum_len_next == 0);
278693f7848bSJeff Kirsher flags |= chop * MXGEFW_FLAGS_TSO_CHOP;
278793f7848bSJeff Kirsher flags_next |= next_is_first *
278893f7848bSJeff Kirsher MXGEFW_FLAGS_FIRST;
278993f7848bSJeff Kirsher rdma_count |= -(chop | next_is_first);
279059e955edSAndrew Gallatin rdma_count += chop & ~next_is_first;
279193f7848bSJeff Kirsher } else if (likely(cum_len_next >= 0)) { /* header ends */
279293f7848bSJeff Kirsher int small;
279393f7848bSJeff Kirsher
279493f7848bSJeff Kirsher rdma_count = -1;
279593f7848bSJeff Kirsher cum_len_next = 0;
279693f7848bSJeff Kirsher seglen = -cum_len;
279793f7848bSJeff Kirsher small = (mss <= MXGEFW_SEND_SMALL_SIZE);
279893f7848bSJeff Kirsher flags_next = MXGEFW_FLAGS_TSO_PLD |
279993f7848bSJeff Kirsher MXGEFW_FLAGS_FIRST |
280093f7848bSJeff Kirsher (small * MXGEFW_FLAGS_SMALL);
280193f7848bSJeff Kirsher }
280293f7848bSJeff Kirsher }
280393f7848bSJeff Kirsher req->addr_high = high_swapped;
280493f7848bSJeff Kirsher req->addr_low = htonl(low);
280593f7848bSJeff Kirsher req->pseudo_hdr_offset = htons(pseudo_hdr_offset);
280693f7848bSJeff Kirsher req->pad = 0; /* complete solid 16-byte block; does this matter? */
280793f7848bSJeff Kirsher req->rdma_count = 1;
280893f7848bSJeff Kirsher req->length = htons(seglen);
280993f7848bSJeff Kirsher req->cksum_offset = cksum_offset;
281093f7848bSJeff Kirsher req->flags = flags | ((cum_len & 1) * odd_flag);
281193f7848bSJeff Kirsher
281293f7848bSJeff Kirsher low += seglen;
281393f7848bSJeff Kirsher len -= seglen;
281493f7848bSJeff Kirsher cum_len = cum_len_next;
281593f7848bSJeff Kirsher flags = flags_next;
281693f7848bSJeff Kirsher req++;
281793f7848bSJeff Kirsher count++;
281893f7848bSJeff Kirsher rdma_count++;
281993f7848bSJeff Kirsher if (cksum_offset != 0 && !(mss && skb_is_gso_v6(skb))) {
282093f7848bSJeff Kirsher if (unlikely(cksum_offset > seglen))
282193f7848bSJeff Kirsher cksum_offset -= seglen;
282293f7848bSJeff Kirsher else
282393f7848bSJeff Kirsher cksum_offset = 0;
282493f7848bSJeff Kirsher }
282593f7848bSJeff Kirsher }
282693f7848bSJeff Kirsher if (frag_idx == frag_cnt)
282793f7848bSJeff Kirsher break;
282893f7848bSJeff Kirsher
282993f7848bSJeff Kirsher /* map next fragment for DMA */
283093f7848bSJeff Kirsher frag = &skb_shinfo(skb)->frags[frag_idx];
283193f7848bSJeff Kirsher frag_idx++;
28329e903e08SEric Dumazet len = skb_frag_size(frag);
28335dc3e196SIan Campbell bus = skb_frag_dma_map(&mgp->pdev->dev, frag, 0, len,
28345d6bcdfeSIan Campbell DMA_TO_DEVICE);
283575bacb6dSChristophe JAILLET if (unlikely(dma_mapping_error(&mgp->pdev->dev, bus))) {
283610545937SStanislaw Gruszka myri10ge_unmap_tx_dma(mgp, tx, idx);
283710545937SStanislaw Gruszka goto drop;
283810545937SStanislaw Gruszka }
283910545937SStanislaw Gruszka idx = (count + tx->req) & tx->mask;
284093f7848bSJeff Kirsher dma_unmap_addr_set(&tx->info[idx], bus, bus);
284193f7848bSJeff Kirsher dma_unmap_len_set(&tx->info[idx], len, len);
284293f7848bSJeff Kirsher }
284393f7848bSJeff Kirsher
284493f7848bSJeff Kirsher (req - rdma_count)->rdma_count = rdma_count;
284593f7848bSJeff Kirsher if (mss)
284693f7848bSJeff Kirsher do {
284793f7848bSJeff Kirsher req--;
284893f7848bSJeff Kirsher req->flags |= MXGEFW_FLAGS_TSO_LAST;
284993f7848bSJeff Kirsher } while (!(req->flags & (MXGEFW_FLAGS_TSO_CHOP |
285093f7848bSJeff Kirsher MXGEFW_FLAGS_FIRST)));
285193f7848bSJeff Kirsher idx = ((count - 1) + tx->req) & tx->mask;
285293f7848bSJeff Kirsher tx->info[idx].last = 1;
285393f7848bSJeff Kirsher myri10ge_submit_req(tx, tx->req_list, count);
285493f7848bSJeff Kirsher /* if using multiple tx queues, make sure NIC polls the
285593f7848bSJeff Kirsher * current slice */
285693f7848bSJeff Kirsher if ((mgp->dev->real_num_tx_queues > 1) && tx->queue_active == 0) {
285793f7848bSJeff Kirsher tx->queue_active = 1;
285893f7848bSJeff Kirsher put_be32(htonl(1), tx->send_go);
285993f7848bSJeff Kirsher mb();
286093f7848bSJeff Kirsher }
286193f7848bSJeff Kirsher tx->pkt_start++;
286293f7848bSJeff Kirsher if ((avail - count) < MXGEFW_MAX_SEND_DESC) {
286393f7848bSJeff Kirsher tx->stop_queue++;
286493f7848bSJeff Kirsher netif_tx_stop_queue(netdev_queue);
286593f7848bSJeff Kirsher }
286693f7848bSJeff Kirsher return NETDEV_TX_OK;
286793f7848bSJeff Kirsher
286893f7848bSJeff Kirsher abort_linearize:
286910545937SStanislaw Gruszka myri10ge_unmap_tx_dma(mgp, tx, idx);
287093f7848bSJeff Kirsher
287193f7848bSJeff Kirsher if (skb_is_gso(skb)) {
287293f7848bSJeff Kirsher netdev_err(mgp->dev, "TSO but wanted to linearize?!?!?\n");
287393f7848bSJeff Kirsher goto drop;
287493f7848bSJeff Kirsher }
287593f7848bSJeff Kirsher
287693f7848bSJeff Kirsher if (skb_linearize(skb))
287793f7848bSJeff Kirsher goto drop;
287893f7848bSJeff Kirsher
287993f7848bSJeff Kirsher tx->linearized++;
288093f7848bSJeff Kirsher goto again;
288193f7848bSJeff Kirsher
288293f7848bSJeff Kirsher drop:
288393f7848bSJeff Kirsher dev_kfree_skb_any(skb);
288493f7848bSJeff Kirsher ss->stats.tx_dropped += 1;
288593f7848bSJeff Kirsher return NETDEV_TX_OK;
288693f7848bSJeff Kirsher
288793f7848bSJeff Kirsher }
288893f7848bSJeff Kirsher
myri10ge_sw_tso(struct sk_buff * skb,struct net_device * dev)288993f7848bSJeff Kirsher static netdev_tx_t myri10ge_sw_tso(struct sk_buff *skb,
289093f7848bSJeff Kirsher struct net_device *dev)
289193f7848bSJeff Kirsher {
2892536577f3SJason A. Donenfeld struct sk_buff *segs, *curr, *next;
289393f7848bSJeff Kirsher struct myri10ge_priv *mgp = netdev_priv(dev);
289493f7848bSJeff Kirsher struct myri10ge_slice_state *ss;
289593f7848bSJeff Kirsher netdev_tx_t status;
289693f7848bSJeff Kirsher
289793f7848bSJeff Kirsher segs = skb_gso_segment(skb, dev->features & ~NETIF_F_TSO6);
289893f7848bSJeff Kirsher if (IS_ERR(segs))
289993f7848bSJeff Kirsher goto drop;
290093f7848bSJeff Kirsher
2901536577f3SJason A. Donenfeld skb_list_walk_safe(segs, curr, next) {
2902536577f3SJason A. Donenfeld skb_mark_not_on_list(curr);
290393f7848bSJeff Kirsher status = myri10ge_xmit(curr, dev);
290493f7848bSJeff Kirsher if (status != 0) {
290593f7848bSJeff Kirsher dev_kfree_skb_any(curr);
2906b423e54bSXiaomeng Tong skb_list_walk_safe(next, curr, next) {
290793f7848bSJeff Kirsher curr->next = NULL;
2908b423e54bSXiaomeng Tong dev_kfree_skb_any(curr);
290993f7848bSJeff Kirsher }
291093f7848bSJeff Kirsher goto drop;
291193f7848bSJeff Kirsher }
291293f7848bSJeff Kirsher }
291393f7848bSJeff Kirsher dev_kfree_skb_any(skb);
291493f7848bSJeff Kirsher return NETDEV_TX_OK;
291593f7848bSJeff Kirsher
291693f7848bSJeff Kirsher drop:
291793f7848bSJeff Kirsher ss = &mgp->ss[skb_get_queue_mapping(skb)];
291893f7848bSJeff Kirsher dev_kfree_skb_any(skb);
291993f7848bSJeff Kirsher ss->stats.tx_dropped += 1;
292093f7848bSJeff Kirsher return NETDEV_TX_OK;
292193f7848bSJeff Kirsher }
292293f7848bSJeff Kirsher
myri10ge_get_stats(struct net_device * dev,struct rtnl_link_stats64 * stats)2923bc1f4470Sstephen hemminger static void myri10ge_get_stats(struct net_device *dev,
292493f7848bSJeff Kirsher struct rtnl_link_stats64 *stats)
292593f7848bSJeff Kirsher {
292693f7848bSJeff Kirsher const struct myri10ge_priv *mgp = netdev_priv(dev);
292793f7848bSJeff Kirsher const struct myri10ge_slice_netstats *slice_stats;
292893f7848bSJeff Kirsher int i;
292993f7848bSJeff Kirsher
293093f7848bSJeff Kirsher for (i = 0; i < mgp->num_slices; i++) {
293193f7848bSJeff Kirsher slice_stats = &mgp->ss[i].stats;
293293f7848bSJeff Kirsher stats->rx_packets += slice_stats->rx_packets;
293393f7848bSJeff Kirsher stats->tx_packets += slice_stats->tx_packets;
293493f7848bSJeff Kirsher stats->rx_bytes += slice_stats->rx_bytes;
293593f7848bSJeff Kirsher stats->tx_bytes += slice_stats->tx_bytes;
293693f7848bSJeff Kirsher stats->rx_dropped += slice_stats->rx_dropped;
293793f7848bSJeff Kirsher stats->tx_dropped += slice_stats->tx_dropped;
293893f7848bSJeff Kirsher }
293993f7848bSJeff Kirsher }
294093f7848bSJeff Kirsher
myri10ge_set_multicast_list(struct net_device * dev)294193f7848bSJeff Kirsher static void myri10ge_set_multicast_list(struct net_device *dev)
294293f7848bSJeff Kirsher {
294393f7848bSJeff Kirsher struct myri10ge_priv *mgp = netdev_priv(dev);
294493f7848bSJeff Kirsher struct myri10ge_cmd cmd;
294593f7848bSJeff Kirsher struct netdev_hw_addr *ha;
294693f7848bSJeff Kirsher __be32 data[2] = { 0, 0 };
294793f7848bSJeff Kirsher int err;
294893f7848bSJeff Kirsher
294993f7848bSJeff Kirsher /* can be called from atomic contexts,
295093f7848bSJeff Kirsher * pass 1 to force atomicity in myri10ge_send_cmd() */
295193f7848bSJeff Kirsher myri10ge_change_promisc(mgp, dev->flags & IFF_PROMISC, 1);
295293f7848bSJeff Kirsher
295393f7848bSJeff Kirsher /* This firmware is known to not support multicast */
295493f7848bSJeff Kirsher if (!mgp->fw_multicast_support)
295593f7848bSJeff Kirsher return;
295693f7848bSJeff Kirsher
295793f7848bSJeff Kirsher /* Disable multicast filtering */
295893f7848bSJeff Kirsher
295993f7848bSJeff Kirsher err = myri10ge_send_cmd(mgp, MXGEFW_ENABLE_ALLMULTI, &cmd, 1);
296093f7848bSJeff Kirsher if (err != 0) {
296193f7848bSJeff Kirsher netdev_err(dev, "Failed MXGEFW_ENABLE_ALLMULTI, error status: %d\n",
296293f7848bSJeff Kirsher err);
296393f7848bSJeff Kirsher goto abort;
296493f7848bSJeff Kirsher }
296593f7848bSJeff Kirsher
296693f7848bSJeff Kirsher if ((dev->flags & IFF_ALLMULTI) || mgp->adopted_rx_filter_bug) {
296793f7848bSJeff Kirsher /* request to disable multicast filtering, so quit here */
296893f7848bSJeff Kirsher return;
296993f7848bSJeff Kirsher }
297093f7848bSJeff Kirsher
297193f7848bSJeff Kirsher /* Flush the filters */
297293f7848bSJeff Kirsher
297393f7848bSJeff Kirsher err = myri10ge_send_cmd(mgp, MXGEFW_LEAVE_ALL_MULTICAST_GROUPS,
297493f7848bSJeff Kirsher &cmd, 1);
297593f7848bSJeff Kirsher if (err != 0) {
297693f7848bSJeff Kirsher netdev_err(dev, "Failed MXGEFW_LEAVE_ALL_MULTICAST_GROUPS, error status: %d\n",
297793f7848bSJeff Kirsher err);
297893f7848bSJeff Kirsher goto abort;
297993f7848bSJeff Kirsher }
298093f7848bSJeff Kirsher
298193f7848bSJeff Kirsher /* Walk the multicast list, and add each address */
298293f7848bSJeff Kirsher netdev_for_each_mc_addr(ha, dev) {
2983d458cdf7SJoe Perches memcpy(data, &ha->addr, ETH_ALEN);
298493f7848bSJeff Kirsher cmd.data0 = ntohl(data[0]);
298593f7848bSJeff Kirsher cmd.data1 = ntohl(data[1]);
298693f7848bSJeff Kirsher err = myri10ge_send_cmd(mgp, MXGEFW_JOIN_MULTICAST_GROUP,
298793f7848bSJeff Kirsher &cmd, 1);
298893f7848bSJeff Kirsher
298993f7848bSJeff Kirsher if (err != 0) {
299093f7848bSJeff Kirsher netdev_err(dev, "Failed MXGEFW_JOIN_MULTICAST_GROUP, error status:%d %pM\n",
299193f7848bSJeff Kirsher err, ha->addr);
299293f7848bSJeff Kirsher goto abort;
299393f7848bSJeff Kirsher }
299493f7848bSJeff Kirsher }
299593f7848bSJeff Kirsher /* Enable multicast filtering */
299693f7848bSJeff Kirsher err = myri10ge_send_cmd(mgp, MXGEFW_DISABLE_ALLMULTI, &cmd, 1);
299793f7848bSJeff Kirsher if (err != 0) {
299893f7848bSJeff Kirsher netdev_err(dev, "Failed MXGEFW_DISABLE_ALLMULTI, error status: %d\n",
299993f7848bSJeff Kirsher err);
300093f7848bSJeff Kirsher goto abort;
300193f7848bSJeff Kirsher }
300293f7848bSJeff Kirsher
300393f7848bSJeff Kirsher return;
300493f7848bSJeff Kirsher
300593f7848bSJeff Kirsher abort:
300693f7848bSJeff Kirsher return;
300793f7848bSJeff Kirsher }
300893f7848bSJeff Kirsher
myri10ge_set_mac_address(struct net_device * dev,void * addr)300993f7848bSJeff Kirsher static int myri10ge_set_mac_address(struct net_device *dev, void *addr)
301093f7848bSJeff Kirsher {
301193f7848bSJeff Kirsher struct sockaddr *sa = addr;
301293f7848bSJeff Kirsher struct myri10ge_priv *mgp = netdev_priv(dev);
301393f7848bSJeff Kirsher int status;
301493f7848bSJeff Kirsher
301593f7848bSJeff Kirsher if (!is_valid_ether_addr(sa->sa_data))
301693f7848bSJeff Kirsher return -EADDRNOTAVAIL;
301793f7848bSJeff Kirsher
301893f7848bSJeff Kirsher status = myri10ge_update_mac_address(mgp, sa->sa_data);
301993f7848bSJeff Kirsher if (status != 0) {
302093f7848bSJeff Kirsher netdev_err(dev, "changing mac address failed with %d\n",
302193f7848bSJeff Kirsher status);
302293f7848bSJeff Kirsher return status;
302393f7848bSJeff Kirsher }
302493f7848bSJeff Kirsher
302593f7848bSJeff Kirsher /* change the dev structure */
3026a96d317fSJakub Kicinski eth_hw_addr_set(dev, sa->sa_data);
302793f7848bSJeff Kirsher return 0;
302893f7848bSJeff Kirsher }
302993f7848bSJeff Kirsher
myri10ge_change_mtu(struct net_device * dev,int new_mtu)303093f7848bSJeff Kirsher static int myri10ge_change_mtu(struct net_device *dev, int new_mtu)
303193f7848bSJeff Kirsher {
303293f7848bSJeff Kirsher struct myri10ge_priv *mgp = netdev_priv(dev);
303393f7848bSJeff Kirsher
303493f7848bSJeff Kirsher netdev_info(dev, "changing mtu from %d to %d\n", dev->mtu, new_mtu);
303593f7848bSJeff Kirsher if (mgp->running) {
303693f7848bSJeff Kirsher /* if we change the mtu on an active device, we must
303793f7848bSJeff Kirsher * reset the device so the firmware sees the change */
303893f7848bSJeff Kirsher myri10ge_close(dev);
303993f7848bSJeff Kirsher dev->mtu = new_mtu;
304093f7848bSJeff Kirsher myri10ge_open(dev);
304193f7848bSJeff Kirsher } else
304293f7848bSJeff Kirsher dev->mtu = new_mtu;
304393f7848bSJeff Kirsher
304470841488SDing Xiang return 0;
304593f7848bSJeff Kirsher }
304693f7848bSJeff Kirsher
304793f7848bSJeff Kirsher /*
304893f7848bSJeff Kirsher * Enable ECRC to align PCI-E Completion packets on an 8-byte boundary.
304993f7848bSJeff Kirsher * Only do it if the bridge is a root port since we don't want to disturb
305093f7848bSJeff Kirsher * any other device, except if forced with myri10ge_ecrc_enable > 1.
305193f7848bSJeff Kirsher */
305293f7848bSJeff Kirsher
myri10ge_enable_ecrc(struct myri10ge_priv * mgp)305393f7848bSJeff Kirsher static void myri10ge_enable_ecrc(struct myri10ge_priv *mgp)
305493f7848bSJeff Kirsher {
305593f7848bSJeff Kirsher struct pci_dev *bridge = mgp->pdev->bus->self;
305693f7848bSJeff Kirsher struct device *dev = &mgp->pdev->dev;
305793f7848bSJeff Kirsher int cap;
305893f7848bSJeff Kirsher unsigned err_cap;
305993f7848bSJeff Kirsher int ret;
306093f7848bSJeff Kirsher
306193f7848bSJeff Kirsher if (!myri10ge_ecrc_enable || !bridge)
306293f7848bSJeff Kirsher return;
306393f7848bSJeff Kirsher
306493f7848bSJeff Kirsher /* check that the bridge is a root port */
30659503e255SJiang Liu if (pci_pcie_type(bridge) != PCI_EXP_TYPE_ROOT_PORT) {
306693f7848bSJeff Kirsher if (myri10ge_ecrc_enable > 1) {
306793f7848bSJeff Kirsher struct pci_dev *prev_bridge, *old_bridge = bridge;
306893f7848bSJeff Kirsher
306993f7848bSJeff Kirsher /* Walk the hierarchy up to the root port
307093f7848bSJeff Kirsher * where ECRC has to be enabled */
307193f7848bSJeff Kirsher do {
307293f7848bSJeff Kirsher prev_bridge = bridge;
307393f7848bSJeff Kirsher bridge = bridge->bus->self;
307493f7848bSJeff Kirsher if (!bridge || prev_bridge == bridge) {
307593f7848bSJeff Kirsher dev_err(dev,
307693f7848bSJeff Kirsher "Failed to find root port"
307793f7848bSJeff Kirsher " to force ECRC\n");
307893f7848bSJeff Kirsher return;
307993f7848bSJeff Kirsher }
30809503e255SJiang Liu } while (pci_pcie_type(bridge) !=
30819503e255SJiang Liu PCI_EXP_TYPE_ROOT_PORT);
308293f7848bSJeff Kirsher
308393f7848bSJeff Kirsher dev_info(dev,
308493f7848bSJeff Kirsher "Forcing ECRC on non-root port %s"
308593f7848bSJeff Kirsher " (enabling on root port %s)\n",
308693f7848bSJeff Kirsher pci_name(old_bridge), pci_name(bridge));
308793f7848bSJeff Kirsher } else {
308893f7848bSJeff Kirsher dev_err(dev,
308993f7848bSJeff Kirsher "Not enabling ECRC on non-root port %s\n",
309093f7848bSJeff Kirsher pci_name(bridge));
309193f7848bSJeff Kirsher return;
309293f7848bSJeff Kirsher }
309393f7848bSJeff Kirsher }
309493f7848bSJeff Kirsher
309593f7848bSJeff Kirsher cap = pci_find_ext_capability(bridge, PCI_EXT_CAP_ID_ERR);
309693f7848bSJeff Kirsher if (!cap)
309793f7848bSJeff Kirsher return;
309893f7848bSJeff Kirsher
309993f7848bSJeff Kirsher ret = pci_read_config_dword(bridge, cap + PCI_ERR_CAP, &err_cap);
310093f7848bSJeff Kirsher if (ret) {
310193f7848bSJeff Kirsher dev_err(dev, "failed reading ext-conf-space of %s\n",
310293f7848bSJeff Kirsher pci_name(bridge));
310393f7848bSJeff Kirsher dev_err(dev, "\t pci=nommconf in use? "
310493f7848bSJeff Kirsher "or buggy/incomplete/absent ACPI MCFG attr?\n");
310593f7848bSJeff Kirsher return;
310693f7848bSJeff Kirsher }
310793f7848bSJeff Kirsher if (!(err_cap & PCI_ERR_CAP_ECRC_GENC))
310893f7848bSJeff Kirsher return;
310993f7848bSJeff Kirsher
311093f7848bSJeff Kirsher err_cap |= PCI_ERR_CAP_ECRC_GENE;
311193f7848bSJeff Kirsher pci_write_config_dword(bridge, cap + PCI_ERR_CAP, err_cap);
311293f7848bSJeff Kirsher dev_info(dev, "Enabled ECRC on upstream bridge %s\n", pci_name(bridge));
311393f7848bSJeff Kirsher }
311493f7848bSJeff Kirsher
311593f7848bSJeff Kirsher /*
311693f7848bSJeff Kirsher * The Lanai Z8E PCI-E interface achieves higher Read-DMA throughput
311793f7848bSJeff Kirsher * when the PCI-E Completion packets are aligned on an 8-byte
311893f7848bSJeff Kirsher * boundary. Some PCI-E chip sets always align Completion packets; on
311993f7848bSJeff Kirsher * the ones that do not, the alignment can be enforced by enabling
312093f7848bSJeff Kirsher * ECRC generation (if supported).
312193f7848bSJeff Kirsher *
312293f7848bSJeff Kirsher * When PCI-E Completion packets are not aligned, it is actually more
312393f7848bSJeff Kirsher * efficient to limit Read-DMA transactions to 2KB, rather than 4KB.
312493f7848bSJeff Kirsher *
312593f7848bSJeff Kirsher * If the driver can neither enable ECRC nor verify that it has
312693f7848bSJeff Kirsher * already been enabled, then it must use a firmware image which works
312793f7848bSJeff Kirsher * around unaligned completion packets (myri10ge_rss_ethp_z8e.dat), and it
312893f7848bSJeff Kirsher * should also ensure that it never gives the device a Read-DMA which is
312993f7848bSJeff Kirsher * larger than 2KB by setting the tx_boundary to 2KB. If ECRC is
313093f7848bSJeff Kirsher * enabled, then the driver should use the aligned (myri10ge_rss_eth_z8e.dat)
313193f7848bSJeff Kirsher * firmware image, and set tx_boundary to 4KB.
313293f7848bSJeff Kirsher */
313393f7848bSJeff Kirsher
myri10ge_firmware_probe(struct myri10ge_priv * mgp)313493f7848bSJeff Kirsher static void myri10ge_firmware_probe(struct myri10ge_priv *mgp)
313593f7848bSJeff Kirsher {
313693f7848bSJeff Kirsher struct pci_dev *pdev = mgp->pdev;
313793f7848bSJeff Kirsher struct device *dev = &pdev->dev;
313893f7848bSJeff Kirsher int status;
313993f7848bSJeff Kirsher
314093f7848bSJeff Kirsher mgp->tx_boundary = 4096;
314193f7848bSJeff Kirsher /*
314293f7848bSJeff Kirsher * Verify the max read request size was set to 4KB
314393f7848bSJeff Kirsher * before trying the test with 4KB.
314493f7848bSJeff Kirsher */
314593f7848bSJeff Kirsher status = pcie_get_readrq(pdev);
314693f7848bSJeff Kirsher if (status < 0) {
314793f7848bSJeff Kirsher dev_err(dev, "Couldn't read max read req size: %d\n", status);
314893f7848bSJeff Kirsher goto abort;
314993f7848bSJeff Kirsher }
315093f7848bSJeff Kirsher if (status != 4096) {
315193f7848bSJeff Kirsher dev_warn(dev, "Max Read Request size != 4096 (%d)\n", status);
315293f7848bSJeff Kirsher mgp->tx_boundary = 2048;
315393f7848bSJeff Kirsher }
315493f7848bSJeff Kirsher /*
315593f7848bSJeff Kirsher * load the optimized firmware (which assumes aligned PCIe
315693f7848bSJeff Kirsher * completions) in order to see if it works on this host.
315793f7848bSJeff Kirsher */
315893f7848bSJeff Kirsher set_fw_name(mgp, myri10ge_fw_aligned, false);
315993f7848bSJeff Kirsher status = myri10ge_load_firmware(mgp, 1);
316093f7848bSJeff Kirsher if (status != 0) {
316193f7848bSJeff Kirsher goto abort;
316293f7848bSJeff Kirsher }
316393f7848bSJeff Kirsher
316493f7848bSJeff Kirsher /*
316593f7848bSJeff Kirsher * Enable ECRC if possible
316693f7848bSJeff Kirsher */
316793f7848bSJeff Kirsher myri10ge_enable_ecrc(mgp);
316893f7848bSJeff Kirsher
316993f7848bSJeff Kirsher /*
317093f7848bSJeff Kirsher * Run a DMA test which watches for unaligned completions and
317193f7848bSJeff Kirsher * aborts on the first one seen.
317293f7848bSJeff Kirsher */
317393f7848bSJeff Kirsher
317493f7848bSJeff Kirsher status = myri10ge_dma_test(mgp, MXGEFW_CMD_UNALIGNED_TEST);
317593f7848bSJeff Kirsher if (status == 0)
317693f7848bSJeff Kirsher return; /* keep the aligned firmware */
317793f7848bSJeff Kirsher
317893f7848bSJeff Kirsher if (status != -E2BIG)
317993f7848bSJeff Kirsher dev_warn(dev, "DMA test failed: %d\n", status);
318093f7848bSJeff Kirsher if (status == -ENOSYS)
318193f7848bSJeff Kirsher dev_warn(dev, "Falling back to ethp! "
318293f7848bSJeff Kirsher "Please install up to date fw\n");
318393f7848bSJeff Kirsher abort:
318493f7848bSJeff Kirsher /* fall back to using the unaligned firmware */
318593f7848bSJeff Kirsher mgp->tx_boundary = 2048;
318693f7848bSJeff Kirsher set_fw_name(mgp, myri10ge_fw_unaligned, false);
318793f7848bSJeff Kirsher }
318893f7848bSJeff Kirsher
myri10ge_select_firmware(struct myri10ge_priv * mgp)318993f7848bSJeff Kirsher static void myri10ge_select_firmware(struct myri10ge_priv *mgp)
319093f7848bSJeff Kirsher {
319193f7848bSJeff Kirsher int overridden = 0;
319293f7848bSJeff Kirsher
319393f7848bSJeff Kirsher if (myri10ge_force_firmware == 0) {
31949503e255SJiang Liu int link_width;
319593f7848bSJeff Kirsher u16 lnk;
319693f7848bSJeff Kirsher
31979503e255SJiang Liu pcie_capability_read_word(mgp->pdev, PCI_EXP_LNKSTA, &lnk);
319893f7848bSJeff Kirsher link_width = (lnk >> 4) & 0x3f;
319993f7848bSJeff Kirsher
320093f7848bSJeff Kirsher /* Check to see if Link is less than 8 or if the
320193f7848bSJeff Kirsher * upstream bridge is known to provide aligned
320293f7848bSJeff Kirsher * completions */
320393f7848bSJeff Kirsher if (link_width < 8) {
320493f7848bSJeff Kirsher dev_info(&mgp->pdev->dev, "PCIE x%d Link\n",
320593f7848bSJeff Kirsher link_width);
320693f7848bSJeff Kirsher mgp->tx_boundary = 4096;
320793f7848bSJeff Kirsher set_fw_name(mgp, myri10ge_fw_aligned, false);
320893f7848bSJeff Kirsher } else {
320993f7848bSJeff Kirsher myri10ge_firmware_probe(mgp);
321093f7848bSJeff Kirsher }
321193f7848bSJeff Kirsher } else {
321293f7848bSJeff Kirsher if (myri10ge_force_firmware == 1) {
321393f7848bSJeff Kirsher dev_info(&mgp->pdev->dev,
321493f7848bSJeff Kirsher "Assuming aligned completions (forced)\n");
321593f7848bSJeff Kirsher mgp->tx_boundary = 4096;
321693f7848bSJeff Kirsher set_fw_name(mgp, myri10ge_fw_aligned, false);
321793f7848bSJeff Kirsher } else {
321893f7848bSJeff Kirsher dev_info(&mgp->pdev->dev,
321993f7848bSJeff Kirsher "Assuming unaligned completions (forced)\n");
322093f7848bSJeff Kirsher mgp->tx_boundary = 2048;
322193f7848bSJeff Kirsher set_fw_name(mgp, myri10ge_fw_unaligned, false);
322293f7848bSJeff Kirsher }
322393f7848bSJeff Kirsher }
322493f7848bSJeff Kirsher
3225b51d23e4SDan Streetman kernel_param_lock(THIS_MODULE);
322693f7848bSJeff Kirsher if (myri10ge_fw_name != NULL) {
322793f7848bSJeff Kirsher char *fw_name = kstrdup(myri10ge_fw_name, GFP_KERNEL);
322893f7848bSJeff Kirsher if (fw_name) {
322993f7848bSJeff Kirsher overridden = 1;
323093f7848bSJeff Kirsher set_fw_name(mgp, fw_name, true);
323193f7848bSJeff Kirsher }
323293f7848bSJeff Kirsher }
3233b51d23e4SDan Streetman kernel_param_unlock(THIS_MODULE);
323493f7848bSJeff Kirsher
323593f7848bSJeff Kirsher if (mgp->board_number < MYRI10GE_MAX_BOARDS &&
323693f7848bSJeff Kirsher myri10ge_fw_names[mgp->board_number] != NULL &&
323793f7848bSJeff Kirsher strlen(myri10ge_fw_names[mgp->board_number])) {
323893f7848bSJeff Kirsher set_fw_name(mgp, myri10ge_fw_names[mgp->board_number], false);
323993f7848bSJeff Kirsher overridden = 1;
324093f7848bSJeff Kirsher }
324193f7848bSJeff Kirsher if (overridden)
324293f7848bSJeff Kirsher dev_info(&mgp->pdev->dev, "overriding firmware to %s\n",
324393f7848bSJeff Kirsher mgp->fw_name);
324493f7848bSJeff Kirsher }
324593f7848bSJeff Kirsher
myri10ge_mask_surprise_down(struct pci_dev * pdev)324693f7848bSJeff Kirsher static void myri10ge_mask_surprise_down(struct pci_dev *pdev)
324793f7848bSJeff Kirsher {
324893f7848bSJeff Kirsher struct pci_dev *bridge = pdev->bus->self;
324993f7848bSJeff Kirsher int cap;
325093f7848bSJeff Kirsher u32 mask;
325193f7848bSJeff Kirsher
325293f7848bSJeff Kirsher if (bridge == NULL)
325393f7848bSJeff Kirsher return;
325493f7848bSJeff Kirsher
325593f7848bSJeff Kirsher cap = pci_find_ext_capability(bridge, PCI_EXT_CAP_ID_ERR);
325693f7848bSJeff Kirsher if (cap) {
325793f7848bSJeff Kirsher /* a sram parity error can cause a surprise link
325893f7848bSJeff Kirsher * down; since we expect and can recover from sram
325993f7848bSJeff Kirsher * parity errors, mask surprise link down events */
326093f7848bSJeff Kirsher pci_read_config_dword(bridge, cap + PCI_ERR_UNCOR_MASK, &mask);
326193f7848bSJeff Kirsher mask |= 0x20;
326293f7848bSJeff Kirsher pci_write_config_dword(bridge, cap + PCI_ERR_UNCOR_MASK, mask);
326393f7848bSJeff Kirsher }
326493f7848bSJeff Kirsher }
326593f7848bSJeff Kirsher
myri10ge_suspend(struct device * dev)32660c17ac54SVaibhav Gupta static int __maybe_unused myri10ge_suspend(struct device *dev)
326793f7848bSJeff Kirsher {
326893f7848bSJeff Kirsher struct myri10ge_priv *mgp;
326993f7848bSJeff Kirsher struct net_device *netdev;
327093f7848bSJeff Kirsher
32710c17ac54SVaibhav Gupta mgp = dev_get_drvdata(dev);
327293f7848bSJeff Kirsher if (mgp == NULL)
327393f7848bSJeff Kirsher return -EINVAL;
327493f7848bSJeff Kirsher netdev = mgp->dev;
327593f7848bSJeff Kirsher
327693f7848bSJeff Kirsher netif_device_detach(netdev);
327793f7848bSJeff Kirsher if (netif_running(netdev)) {
327893f7848bSJeff Kirsher netdev_info(netdev, "closing\n");
327993f7848bSJeff Kirsher rtnl_lock();
328093f7848bSJeff Kirsher myri10ge_close(netdev);
328193f7848bSJeff Kirsher rtnl_unlock();
328293f7848bSJeff Kirsher }
328393f7848bSJeff Kirsher myri10ge_dummy_rdma(mgp, 0);
328493f7848bSJeff Kirsher
32850c17ac54SVaibhav Gupta return 0;
328693f7848bSJeff Kirsher }
328793f7848bSJeff Kirsher
myri10ge_resume(struct device * dev)32880c17ac54SVaibhav Gupta static int __maybe_unused myri10ge_resume(struct device *dev)
328993f7848bSJeff Kirsher {
32900c17ac54SVaibhav Gupta struct pci_dev *pdev = to_pci_dev(dev);
329193f7848bSJeff Kirsher struct myri10ge_priv *mgp;
329293f7848bSJeff Kirsher struct net_device *netdev;
329393f7848bSJeff Kirsher int status;
329493f7848bSJeff Kirsher u16 vendor;
329593f7848bSJeff Kirsher
329693f7848bSJeff Kirsher mgp = pci_get_drvdata(pdev);
329793f7848bSJeff Kirsher if (mgp == NULL)
329893f7848bSJeff Kirsher return -EINVAL;
329993f7848bSJeff Kirsher netdev = mgp->dev;
330093f7848bSJeff Kirsher msleep(5); /* give card time to respond */
330193f7848bSJeff Kirsher pci_read_config_word(mgp->pdev, PCI_VENDOR_ID, &vendor);
330293f7848bSJeff Kirsher if (vendor == 0xffff) {
330393f7848bSJeff Kirsher netdev_err(mgp->dev, "device disappeared!\n");
330493f7848bSJeff Kirsher return -EIO;
330593f7848bSJeff Kirsher }
330693f7848bSJeff Kirsher
330793f7848bSJeff Kirsher myri10ge_reset(mgp);
330893f7848bSJeff Kirsher myri10ge_dummy_rdma(mgp, 1);
330993f7848bSJeff Kirsher
331093f7848bSJeff Kirsher if (netif_running(netdev)) {
331193f7848bSJeff Kirsher rtnl_lock();
331293f7848bSJeff Kirsher status = myri10ge_open(netdev);
331393f7848bSJeff Kirsher rtnl_unlock();
331493f7848bSJeff Kirsher if (status != 0)
331593f7848bSJeff Kirsher goto abort_with_enabled;
331693f7848bSJeff Kirsher
331793f7848bSJeff Kirsher }
331893f7848bSJeff Kirsher netif_device_attach(netdev);
331993f7848bSJeff Kirsher
332093f7848bSJeff Kirsher return 0;
332193f7848bSJeff Kirsher
332293f7848bSJeff Kirsher abort_with_enabled:
332393f7848bSJeff Kirsher return -EIO;
332493f7848bSJeff Kirsher }
332593f7848bSJeff Kirsher
myri10ge_read_reboot(struct myri10ge_priv * mgp)332693f7848bSJeff Kirsher static u32 myri10ge_read_reboot(struct myri10ge_priv *mgp)
332793f7848bSJeff Kirsher {
332893f7848bSJeff Kirsher struct pci_dev *pdev = mgp->pdev;
332993f7848bSJeff Kirsher int vs = mgp->vendor_specific_offset;
333093f7848bSJeff Kirsher u32 reboot;
333193f7848bSJeff Kirsher
333293f7848bSJeff Kirsher /*enter read32 mode */
333393f7848bSJeff Kirsher pci_write_config_byte(pdev, vs + 0x10, 0x3);
333493f7848bSJeff Kirsher
333593f7848bSJeff Kirsher /*read REBOOT_STATUS (0xfffffff0) */
333693f7848bSJeff Kirsher pci_write_config_dword(pdev, vs + 0x18, 0xfffffff0);
333793f7848bSJeff Kirsher pci_read_config_dword(pdev, vs + 0x14, &reboot);
333893f7848bSJeff Kirsher return reboot;
333993f7848bSJeff Kirsher }
334093f7848bSJeff Kirsher
334193f7848bSJeff Kirsher static void
myri10ge_check_slice(struct myri10ge_slice_state * ss,int * reset_needed,int * busy_slice_cnt,u32 rx_pause_cnt)334293f7848bSJeff Kirsher myri10ge_check_slice(struct myri10ge_slice_state *ss, int *reset_needed,
334393f7848bSJeff Kirsher int *busy_slice_cnt, u32 rx_pause_cnt)
334493f7848bSJeff Kirsher {
334593f7848bSJeff Kirsher struct myri10ge_priv *mgp = ss->mgp;
334693f7848bSJeff Kirsher int slice = ss - mgp->ss;
334793f7848bSJeff Kirsher
334893f7848bSJeff Kirsher if (ss->tx.req != ss->tx.done &&
334993f7848bSJeff Kirsher ss->tx.done == ss->watchdog_tx_done &&
335093f7848bSJeff Kirsher ss->watchdog_tx_req != ss->watchdog_tx_done) {
335193f7848bSJeff Kirsher /* nic seems like it might be stuck.. */
335293f7848bSJeff Kirsher if (rx_pause_cnt != mgp->watchdog_pause) {
335393f7848bSJeff Kirsher if (net_ratelimit())
335493f7848bSJeff Kirsher netdev_warn(mgp->dev, "slice %d: TX paused, "
335593f7848bSJeff Kirsher "check link partner\n", slice);
335693f7848bSJeff Kirsher } else {
335793f7848bSJeff Kirsher netdev_warn(mgp->dev,
335893f7848bSJeff Kirsher "slice %d: TX stuck %d %d %d %d %d %d\n",
335993f7848bSJeff Kirsher slice, ss->tx.queue_active, ss->tx.req,
336093f7848bSJeff Kirsher ss->tx.done, ss->tx.pkt_start,
336193f7848bSJeff Kirsher ss->tx.pkt_done,
336293f7848bSJeff Kirsher (int)ntohl(mgp->ss[slice].fw_stats->
336393f7848bSJeff Kirsher send_done_count));
336493f7848bSJeff Kirsher *reset_needed = 1;
336593f7848bSJeff Kirsher ss->stuck = 1;
336693f7848bSJeff Kirsher }
336793f7848bSJeff Kirsher }
336893f7848bSJeff Kirsher if (ss->watchdog_tx_done != ss->tx.done ||
336993f7848bSJeff Kirsher ss->watchdog_rx_done != ss->rx_done.cnt) {
337093f7848bSJeff Kirsher *busy_slice_cnt += 1;
337193f7848bSJeff Kirsher }
337293f7848bSJeff Kirsher ss->watchdog_tx_done = ss->tx.done;
337393f7848bSJeff Kirsher ss->watchdog_tx_req = ss->tx.req;
337493f7848bSJeff Kirsher ss->watchdog_rx_done = ss->rx_done.cnt;
337593f7848bSJeff Kirsher }
337693f7848bSJeff Kirsher
337793f7848bSJeff Kirsher /*
337893f7848bSJeff Kirsher * This watchdog is used to check whether the board has suffered
337993f7848bSJeff Kirsher * from a parity error and needs to be recovered.
338093f7848bSJeff Kirsher */
myri10ge_watchdog(struct work_struct * work)338193f7848bSJeff Kirsher static void myri10ge_watchdog(struct work_struct *work)
338293f7848bSJeff Kirsher {
338393f7848bSJeff Kirsher struct myri10ge_priv *mgp =
338493f7848bSJeff Kirsher container_of(work, struct myri10ge_priv, watchdog_work);
338593f7848bSJeff Kirsher struct myri10ge_slice_state *ss;
338693f7848bSJeff Kirsher u32 reboot, rx_pause_cnt;
338793f7848bSJeff Kirsher int status, rebooted;
338893f7848bSJeff Kirsher int i;
338993f7848bSJeff Kirsher int reset_needed = 0;
339093f7848bSJeff Kirsher int busy_slice_cnt = 0;
339193f7848bSJeff Kirsher u16 cmd, vendor;
339293f7848bSJeff Kirsher
339393f7848bSJeff Kirsher mgp->watchdog_resets++;
339493f7848bSJeff Kirsher pci_read_config_word(mgp->pdev, PCI_COMMAND, &cmd);
339593f7848bSJeff Kirsher rebooted = 0;
339693f7848bSJeff Kirsher if ((cmd & PCI_COMMAND_MASTER) == 0) {
339793f7848bSJeff Kirsher /* Bus master DMA disabled? Check to see
339893f7848bSJeff Kirsher * if the card rebooted due to a parity error
339993f7848bSJeff Kirsher * For now, just report it */
340093f7848bSJeff Kirsher reboot = myri10ge_read_reboot(mgp);
340193f7848bSJeff Kirsher netdev_err(mgp->dev, "NIC rebooted (0x%x),%s resetting\n",
340293f7848bSJeff Kirsher reboot, myri10ge_reset_recover ? "" : " not");
340393f7848bSJeff Kirsher if (myri10ge_reset_recover == 0)
340493f7848bSJeff Kirsher return;
340593f7848bSJeff Kirsher rtnl_lock();
340693f7848bSJeff Kirsher mgp->rebooted = 1;
340793f7848bSJeff Kirsher rebooted = 1;
340893f7848bSJeff Kirsher myri10ge_close(mgp->dev);
340993f7848bSJeff Kirsher myri10ge_reset_recover--;
341093f7848bSJeff Kirsher mgp->rebooted = 0;
341193f7848bSJeff Kirsher /*
341293f7848bSJeff Kirsher * A rebooted nic will come back with config space as
341393f7848bSJeff Kirsher * it was after power was applied to PCIe bus.
341493f7848bSJeff Kirsher * Attempt to restore config space which was saved
341593f7848bSJeff Kirsher * when the driver was loaded, or the last time the
341693f7848bSJeff Kirsher * nic was resumed from power saving mode.
341793f7848bSJeff Kirsher */
341893f7848bSJeff Kirsher pci_restore_state(mgp->pdev);
341993f7848bSJeff Kirsher
342093f7848bSJeff Kirsher /* save state again for accounting reasons */
342193f7848bSJeff Kirsher pci_save_state(mgp->pdev);
342293f7848bSJeff Kirsher
342393f7848bSJeff Kirsher } else {
342493f7848bSJeff Kirsher /* if we get back -1's from our slot, perhaps somebody
342593f7848bSJeff Kirsher * powered off our card. Don't try to reset it in
342693f7848bSJeff Kirsher * this case */
342793f7848bSJeff Kirsher if (cmd == 0xffff) {
342893f7848bSJeff Kirsher pci_read_config_word(mgp->pdev, PCI_VENDOR_ID, &vendor);
342993f7848bSJeff Kirsher if (vendor == 0xffff) {
343093f7848bSJeff Kirsher netdev_err(mgp->dev, "device disappeared!\n");
343193f7848bSJeff Kirsher return;
343293f7848bSJeff Kirsher }
343393f7848bSJeff Kirsher }
343493f7848bSJeff Kirsher /* Perhaps it is a software error. See if stuck slice
343593f7848bSJeff Kirsher * has recovered, reset if not */
343693f7848bSJeff Kirsher rx_pause_cnt = ntohl(mgp->ss[0].fw_stats->dropped_pause);
343793f7848bSJeff Kirsher for (i = 0; i < mgp->num_slices; i++) {
343893f7848bSJeff Kirsher ss = mgp->ss;
343993f7848bSJeff Kirsher if (ss->stuck) {
344093f7848bSJeff Kirsher myri10ge_check_slice(ss, &reset_needed,
344193f7848bSJeff Kirsher &busy_slice_cnt,
344293f7848bSJeff Kirsher rx_pause_cnt);
344393f7848bSJeff Kirsher ss->stuck = 0;
344493f7848bSJeff Kirsher }
344593f7848bSJeff Kirsher }
344693f7848bSJeff Kirsher if (!reset_needed) {
344793f7848bSJeff Kirsher netdev_dbg(mgp->dev, "not resetting\n");
344893f7848bSJeff Kirsher return;
344993f7848bSJeff Kirsher }
345093f7848bSJeff Kirsher
345193f7848bSJeff Kirsher netdev_err(mgp->dev, "device timeout, resetting\n");
345293f7848bSJeff Kirsher }
345393f7848bSJeff Kirsher
345493f7848bSJeff Kirsher if (!rebooted) {
345593f7848bSJeff Kirsher rtnl_lock();
345693f7848bSJeff Kirsher myri10ge_close(mgp->dev);
345793f7848bSJeff Kirsher }
345893f7848bSJeff Kirsher status = myri10ge_load_firmware(mgp, 1);
345993f7848bSJeff Kirsher if (status != 0)
346093f7848bSJeff Kirsher netdev_err(mgp->dev, "failed to load firmware\n");
346193f7848bSJeff Kirsher else
346293f7848bSJeff Kirsher myri10ge_open(mgp->dev);
346393f7848bSJeff Kirsher rtnl_unlock();
346493f7848bSJeff Kirsher }
346593f7848bSJeff Kirsher
346693f7848bSJeff Kirsher /*
346793f7848bSJeff Kirsher * We use our own timer routine rather than relying upon
346893f7848bSJeff Kirsher * netdev->tx_timeout because we have a very large hardware transmit
346993f7848bSJeff Kirsher * queue. Due to the large queue, the netdev->tx_timeout function
347093f7848bSJeff Kirsher * cannot detect a NIC with a parity error in a timely fashion if the
347193f7848bSJeff Kirsher * NIC is lightly loaded.
347293f7848bSJeff Kirsher */
myri10ge_watchdog_timer(struct timer_list * t)3473e99e88a9SKees Cook static void myri10ge_watchdog_timer(struct timer_list *t)
347493f7848bSJeff Kirsher {
347593f7848bSJeff Kirsher struct myri10ge_priv *mgp;
347693f7848bSJeff Kirsher struct myri10ge_slice_state *ss;
347793f7848bSJeff Kirsher int i, reset_needed, busy_slice_cnt;
347893f7848bSJeff Kirsher u32 rx_pause_cnt;
347993f7848bSJeff Kirsher u16 cmd;
348093f7848bSJeff Kirsher
3481e99e88a9SKees Cook mgp = from_timer(mgp, t, watchdog_timer);
348293f7848bSJeff Kirsher
348393f7848bSJeff Kirsher rx_pause_cnt = ntohl(mgp->ss[0].fw_stats->dropped_pause);
348493f7848bSJeff Kirsher busy_slice_cnt = 0;
348593f7848bSJeff Kirsher for (i = 0, reset_needed = 0;
348693f7848bSJeff Kirsher i < mgp->num_slices && reset_needed == 0; ++i) {
348793f7848bSJeff Kirsher
348893f7848bSJeff Kirsher ss = &mgp->ss[i];
348993f7848bSJeff Kirsher if (ss->rx_small.watchdog_needed) {
349093f7848bSJeff Kirsher myri10ge_alloc_rx_pages(mgp, &ss->rx_small,
349193f7848bSJeff Kirsher mgp->small_bytes + MXGEFW_PAD,
349293f7848bSJeff Kirsher 1);
349393f7848bSJeff Kirsher if (ss->rx_small.fill_cnt - ss->rx_small.cnt >=
349493f7848bSJeff Kirsher myri10ge_fill_thresh)
349593f7848bSJeff Kirsher ss->rx_small.watchdog_needed = 0;
349693f7848bSJeff Kirsher }
349793f7848bSJeff Kirsher if (ss->rx_big.watchdog_needed) {
349893f7848bSJeff Kirsher myri10ge_alloc_rx_pages(mgp, &ss->rx_big,
349993f7848bSJeff Kirsher mgp->big_bytes, 1);
350093f7848bSJeff Kirsher if (ss->rx_big.fill_cnt - ss->rx_big.cnt >=
350193f7848bSJeff Kirsher myri10ge_fill_thresh)
350293f7848bSJeff Kirsher ss->rx_big.watchdog_needed = 0;
350393f7848bSJeff Kirsher }
350493f7848bSJeff Kirsher myri10ge_check_slice(ss, &reset_needed, &busy_slice_cnt,
350593f7848bSJeff Kirsher rx_pause_cnt);
350693f7848bSJeff Kirsher }
350793f7848bSJeff Kirsher /* if we've sent or received no traffic, poll the NIC to
350893f7848bSJeff Kirsher * ensure it is still there. Otherwise, we risk not noticing
350993f7848bSJeff Kirsher * an error in a timely fashion */
351093f7848bSJeff Kirsher if (busy_slice_cnt == 0) {
351193f7848bSJeff Kirsher pci_read_config_word(mgp->pdev, PCI_COMMAND, &cmd);
351293f7848bSJeff Kirsher if ((cmd & PCI_COMMAND_MASTER) == 0) {
351393f7848bSJeff Kirsher reset_needed = 1;
351493f7848bSJeff Kirsher }
351593f7848bSJeff Kirsher }
351693f7848bSJeff Kirsher mgp->watchdog_pause = rx_pause_cnt;
351793f7848bSJeff Kirsher
351893f7848bSJeff Kirsher if (reset_needed) {
351993f7848bSJeff Kirsher schedule_work(&mgp->watchdog_work);
352093f7848bSJeff Kirsher } else {
352193f7848bSJeff Kirsher /* rearm timer */
352293f7848bSJeff Kirsher mod_timer(&mgp->watchdog_timer,
352393f7848bSJeff Kirsher jiffies + myri10ge_watchdog_timeout * HZ);
352493f7848bSJeff Kirsher }
352593f7848bSJeff Kirsher }
352693f7848bSJeff Kirsher
myri10ge_free_slices(struct myri10ge_priv * mgp)352793f7848bSJeff Kirsher static void myri10ge_free_slices(struct myri10ge_priv *mgp)
352893f7848bSJeff Kirsher {
352993f7848bSJeff Kirsher struct myri10ge_slice_state *ss;
353093f7848bSJeff Kirsher struct pci_dev *pdev = mgp->pdev;
353193f7848bSJeff Kirsher size_t bytes;
353293f7848bSJeff Kirsher int i;
353393f7848bSJeff Kirsher
353493f7848bSJeff Kirsher if (mgp->ss == NULL)
353593f7848bSJeff Kirsher return;
353693f7848bSJeff Kirsher
353793f7848bSJeff Kirsher for (i = 0; i < mgp->num_slices; i++) {
353893f7848bSJeff Kirsher ss = &mgp->ss[i];
353993f7848bSJeff Kirsher if (ss->rx_done.entry != NULL) {
354093f7848bSJeff Kirsher bytes = mgp->max_intr_slots *
354193f7848bSJeff Kirsher sizeof(*ss->rx_done.entry);
354293f7848bSJeff Kirsher dma_free_coherent(&pdev->dev, bytes,
354393f7848bSJeff Kirsher ss->rx_done.entry, ss->rx_done.bus);
354493f7848bSJeff Kirsher ss->rx_done.entry = NULL;
354593f7848bSJeff Kirsher }
354693f7848bSJeff Kirsher if (ss->fw_stats != NULL) {
354793f7848bSJeff Kirsher bytes = sizeof(*ss->fw_stats);
354893f7848bSJeff Kirsher dma_free_coherent(&pdev->dev, bytes,
354993f7848bSJeff Kirsher ss->fw_stats, ss->fw_stats_bus);
355093f7848bSJeff Kirsher ss->fw_stats = NULL;
355193f7848bSJeff Kirsher }
35525198d545SJakub Kicinski __netif_napi_del(&ss->napi);
355393f7848bSJeff Kirsher }
35540dde8026SHyong-Youb Kim /* Wait till napi structs are no longer used, and then free ss. */
35555198d545SJakub Kicinski synchronize_net();
355693f7848bSJeff Kirsher kfree(mgp->ss);
355793f7848bSJeff Kirsher mgp->ss = NULL;
355893f7848bSJeff Kirsher }
355993f7848bSJeff Kirsher
myri10ge_alloc_slices(struct myri10ge_priv * mgp)356093f7848bSJeff Kirsher static int myri10ge_alloc_slices(struct myri10ge_priv *mgp)
356193f7848bSJeff Kirsher {
356293f7848bSJeff Kirsher struct myri10ge_slice_state *ss;
356393f7848bSJeff Kirsher struct pci_dev *pdev = mgp->pdev;
356493f7848bSJeff Kirsher size_t bytes;
356593f7848bSJeff Kirsher int i;
356693f7848bSJeff Kirsher
356793f7848bSJeff Kirsher bytes = sizeof(*mgp->ss) * mgp->num_slices;
356893f7848bSJeff Kirsher mgp->ss = kzalloc(bytes, GFP_KERNEL);
356993f7848bSJeff Kirsher if (mgp->ss == NULL) {
357093f7848bSJeff Kirsher return -ENOMEM;
357193f7848bSJeff Kirsher }
357293f7848bSJeff Kirsher
357393f7848bSJeff Kirsher for (i = 0; i < mgp->num_slices; i++) {
357493f7848bSJeff Kirsher ss = &mgp->ss[i];
357593f7848bSJeff Kirsher bytes = mgp->max_intr_slots * sizeof(*ss->rx_done.entry);
3576750afb08SLuis Chamberlain ss->rx_done.entry = dma_alloc_coherent(&pdev->dev, bytes,
357793f7848bSJeff Kirsher &ss->rx_done.bus,
3578ede23fa8SJoe Perches GFP_KERNEL);
357993f7848bSJeff Kirsher if (ss->rx_done.entry == NULL)
358093f7848bSJeff Kirsher goto abort;
358193f7848bSJeff Kirsher bytes = sizeof(*ss->fw_stats);
358293f7848bSJeff Kirsher ss->fw_stats = dma_alloc_coherent(&pdev->dev, bytes,
358393f7848bSJeff Kirsher &ss->fw_stats_bus,
358493f7848bSJeff Kirsher GFP_KERNEL);
358593f7848bSJeff Kirsher if (ss->fw_stats == NULL)
358693f7848bSJeff Kirsher goto abort;
358793f7848bSJeff Kirsher ss->mgp = mgp;
358893f7848bSJeff Kirsher ss->dev = mgp->dev;
3589b707b89fSJakub Kicinski netif_napi_add_weight(ss->dev, &ss->napi, myri10ge_poll,
359093f7848bSJeff Kirsher myri10ge_napi_weight);
359193f7848bSJeff Kirsher }
359293f7848bSJeff Kirsher return 0;
359393f7848bSJeff Kirsher abort:
359493f7848bSJeff Kirsher myri10ge_free_slices(mgp);
359593f7848bSJeff Kirsher return -ENOMEM;
359693f7848bSJeff Kirsher }
359793f7848bSJeff Kirsher
359893f7848bSJeff Kirsher /*
359993f7848bSJeff Kirsher * This function determines the number of slices supported.
360093f7848bSJeff Kirsher * The number slices is the minimum of the number of CPUS,
360193f7848bSJeff Kirsher * the number of MSI-X irqs supported, the number of slices
360293f7848bSJeff Kirsher * supported by the firmware
360393f7848bSJeff Kirsher */
myri10ge_probe_slices(struct myri10ge_priv * mgp)360493f7848bSJeff Kirsher static void myri10ge_probe_slices(struct myri10ge_priv *mgp)
360593f7848bSJeff Kirsher {
360693f7848bSJeff Kirsher struct myri10ge_cmd cmd;
360793f7848bSJeff Kirsher struct pci_dev *pdev = mgp->pdev;
360893f7848bSJeff Kirsher char *old_fw;
360993f7848bSJeff Kirsher bool old_allocated;
361040b29562SYijing Wang int i, status, ncpus;
361193f7848bSJeff Kirsher
361293f7848bSJeff Kirsher mgp->num_slices = 1;
361398f2d21fSYuval Mintz ncpus = netif_get_num_default_rss_queues();
361493f7848bSJeff Kirsher
361540b29562SYijing Wang if (myri10ge_max_slices == 1 || !pdev->msix_cap ||
361693f7848bSJeff Kirsher (myri10ge_max_slices == -1 && ncpus < 2))
361793f7848bSJeff Kirsher return;
361893f7848bSJeff Kirsher
361993f7848bSJeff Kirsher /* try to load the slice aware rss firmware */
362093f7848bSJeff Kirsher old_fw = mgp->fw_name;
362193f7848bSJeff Kirsher old_allocated = mgp->fw_name_allocated;
362293f7848bSJeff Kirsher /* don't free old_fw if we override it. */
362393f7848bSJeff Kirsher mgp->fw_name_allocated = false;
362493f7848bSJeff Kirsher
362593f7848bSJeff Kirsher if (myri10ge_fw_name != NULL) {
362693f7848bSJeff Kirsher dev_info(&mgp->pdev->dev, "overriding rss firmware to %s\n",
362793f7848bSJeff Kirsher myri10ge_fw_name);
362893f7848bSJeff Kirsher set_fw_name(mgp, myri10ge_fw_name, false);
362993f7848bSJeff Kirsher } else if (old_fw == myri10ge_fw_aligned)
363093f7848bSJeff Kirsher set_fw_name(mgp, myri10ge_fw_rss_aligned, false);
363193f7848bSJeff Kirsher else
363293f7848bSJeff Kirsher set_fw_name(mgp, myri10ge_fw_rss_unaligned, false);
363393f7848bSJeff Kirsher status = myri10ge_load_firmware(mgp, 0);
363493f7848bSJeff Kirsher if (status != 0) {
363593f7848bSJeff Kirsher dev_info(&pdev->dev, "Rss firmware not found\n");
363693f7848bSJeff Kirsher if (old_allocated)
363793f7848bSJeff Kirsher kfree(old_fw);
363893f7848bSJeff Kirsher return;
363993f7848bSJeff Kirsher }
364093f7848bSJeff Kirsher
364193f7848bSJeff Kirsher /* hit the board with a reset to ensure it is alive */
364293f7848bSJeff Kirsher memset(&cmd, 0, sizeof(cmd));
364393f7848bSJeff Kirsher status = myri10ge_send_cmd(mgp, MXGEFW_CMD_RESET, &cmd, 0);
364493f7848bSJeff Kirsher if (status != 0) {
364593f7848bSJeff Kirsher dev_err(&mgp->pdev->dev, "failed reset\n");
364693f7848bSJeff Kirsher goto abort_with_fw;
364793f7848bSJeff Kirsher }
364893f7848bSJeff Kirsher
364993f7848bSJeff Kirsher mgp->max_intr_slots = cmd.data0 / sizeof(struct mcp_slot);
365093f7848bSJeff Kirsher
365193f7848bSJeff Kirsher /* tell it the size of the interrupt queues */
365293f7848bSJeff Kirsher cmd.data0 = mgp->max_intr_slots * sizeof(struct mcp_slot);
365393f7848bSJeff Kirsher status = myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_INTRQ_SIZE, &cmd, 0);
365493f7848bSJeff Kirsher if (status != 0) {
365593f7848bSJeff Kirsher dev_err(&mgp->pdev->dev, "failed MXGEFW_CMD_SET_INTRQ_SIZE\n");
365693f7848bSJeff Kirsher goto abort_with_fw;
365793f7848bSJeff Kirsher }
365893f7848bSJeff Kirsher
365993f7848bSJeff Kirsher /* ask the maximum number of slices it supports */
366093f7848bSJeff Kirsher status = myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_MAX_RSS_QUEUES, &cmd, 0);
366193f7848bSJeff Kirsher if (status != 0)
366293f7848bSJeff Kirsher goto abort_with_fw;
366393f7848bSJeff Kirsher else
366493f7848bSJeff Kirsher mgp->num_slices = cmd.data0;
366593f7848bSJeff Kirsher
366693f7848bSJeff Kirsher /* Only allow multiple slices if MSI-X is usable */
366793f7848bSJeff Kirsher if (!myri10ge_msi) {
366893f7848bSJeff Kirsher goto abort_with_fw;
366993f7848bSJeff Kirsher }
367093f7848bSJeff Kirsher
367193f7848bSJeff Kirsher /* if the admin did not specify a limit to how many
367293f7848bSJeff Kirsher * slices we should use, cap it automatically to the
367393f7848bSJeff Kirsher * number of CPUs currently online */
367493f7848bSJeff Kirsher if (myri10ge_max_slices == -1)
367593f7848bSJeff Kirsher myri10ge_max_slices = ncpus;
367693f7848bSJeff Kirsher
367793f7848bSJeff Kirsher if (mgp->num_slices > myri10ge_max_slices)
367893f7848bSJeff Kirsher mgp->num_slices = myri10ge_max_slices;
367993f7848bSJeff Kirsher
368093f7848bSJeff Kirsher /* Now try to allocate as many MSI-X vectors as we have
368193f7848bSJeff Kirsher * slices. We give up on MSI-X if we can only get a single
368293f7848bSJeff Kirsher * vector. */
368393f7848bSJeff Kirsher
368493f7848bSJeff Kirsher mgp->msix_vectors = kcalloc(mgp->num_slices, sizeof(*mgp->msix_vectors),
368593f7848bSJeff Kirsher GFP_KERNEL);
368693f7848bSJeff Kirsher if (mgp->msix_vectors == NULL)
36870729cc0cSAlexander Gordeev goto no_msix;
368893f7848bSJeff Kirsher for (i = 0; i < mgp->num_slices; i++) {
368993f7848bSJeff Kirsher mgp->msix_vectors[i].entry = i;
369093f7848bSJeff Kirsher }
369193f7848bSJeff Kirsher
369293f7848bSJeff Kirsher while (mgp->num_slices > 1) {
36930729cc0cSAlexander Gordeev mgp->num_slices = rounddown_pow_of_two(mgp->num_slices);
369493f7848bSJeff Kirsher if (mgp->num_slices == 1)
36950729cc0cSAlexander Gordeev goto no_msix;
36960729cc0cSAlexander Gordeev status = pci_enable_msix_range(pdev,
36970729cc0cSAlexander Gordeev mgp->msix_vectors,
36980729cc0cSAlexander Gordeev mgp->num_slices,
369993f7848bSJeff Kirsher mgp->num_slices);
37000729cc0cSAlexander Gordeev if (status < 0)
37010729cc0cSAlexander Gordeev goto no_msix;
37020729cc0cSAlexander Gordeev
370393f7848bSJeff Kirsher pci_disable_msix(pdev);
37040729cc0cSAlexander Gordeev
37050729cc0cSAlexander Gordeev if (status == mgp->num_slices) {
370693f7848bSJeff Kirsher if (old_allocated)
370793f7848bSJeff Kirsher kfree(old_fw);
370893f7848bSJeff Kirsher return;
37090729cc0cSAlexander Gordeev } else {
371093f7848bSJeff Kirsher mgp->num_slices = status;
37110729cc0cSAlexander Gordeev }
371293f7848bSJeff Kirsher }
371393f7848bSJeff Kirsher
37140729cc0cSAlexander Gordeev no_msix:
371593f7848bSJeff Kirsher if (mgp->msix_vectors != NULL) {
371693f7848bSJeff Kirsher kfree(mgp->msix_vectors);
371793f7848bSJeff Kirsher mgp->msix_vectors = NULL;
371893f7848bSJeff Kirsher }
371993f7848bSJeff Kirsher
372093f7848bSJeff Kirsher abort_with_fw:
372193f7848bSJeff Kirsher mgp->num_slices = 1;
372293f7848bSJeff Kirsher set_fw_name(mgp, old_fw, old_allocated);
372393f7848bSJeff Kirsher myri10ge_load_firmware(mgp, 0);
372493f7848bSJeff Kirsher }
372593f7848bSJeff Kirsher
372693f7848bSJeff Kirsher static const struct net_device_ops myri10ge_netdev_ops = {
372793f7848bSJeff Kirsher .ndo_open = myri10ge_open,
372893f7848bSJeff Kirsher .ndo_stop = myri10ge_close,
372993f7848bSJeff Kirsher .ndo_start_xmit = myri10ge_xmit,
373093f7848bSJeff Kirsher .ndo_get_stats64 = myri10ge_get_stats,
373193f7848bSJeff Kirsher .ndo_validate_addr = eth_validate_addr,
373293f7848bSJeff Kirsher .ndo_change_mtu = myri10ge_change_mtu,
3733afc4b13dSJiri Pirko .ndo_set_rx_mode = myri10ge_set_multicast_list,
373493f7848bSJeff Kirsher .ndo_set_mac_address = myri10ge_set_mac_address,
373593f7848bSJeff Kirsher };
373693f7848bSJeff Kirsher
myri10ge_probe(struct pci_dev * pdev,const struct pci_device_id * ent)373793f7848bSJeff Kirsher static int myri10ge_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
373893f7848bSJeff Kirsher {
373993f7848bSJeff Kirsher struct net_device *netdev;
374093f7848bSJeff Kirsher struct myri10ge_priv *mgp;
374193f7848bSJeff Kirsher struct device *dev = &pdev->dev;
374293f7848bSJeff Kirsher int status = -ENXIO;
374393f7848bSJeff Kirsher unsigned hdr_offset, ss_offset;
374493f7848bSJeff Kirsher static int board_number;
374593f7848bSJeff Kirsher
374693f7848bSJeff Kirsher netdev = alloc_etherdev_mq(sizeof(*mgp), MYRI10GE_MAX_SLICES);
374741de8d4cSJoe Perches if (netdev == NULL)
374893f7848bSJeff Kirsher return -ENOMEM;
374993f7848bSJeff Kirsher
375093f7848bSJeff Kirsher SET_NETDEV_DEV(netdev, &pdev->dev);
375193f7848bSJeff Kirsher
375293f7848bSJeff Kirsher mgp = netdev_priv(netdev);
375393f7848bSJeff Kirsher mgp->dev = netdev;
375493f7848bSJeff Kirsher mgp->pdev = pdev;
375593f7848bSJeff Kirsher mgp->pause = myri10ge_flow_control;
375693f7848bSJeff Kirsher mgp->intr_coal_delay = myri10ge_intr_coal_delay;
375793f7848bSJeff Kirsher mgp->msg_enable = netif_msg_init(myri10ge_debug, MYRI10GE_MSG_DEFAULT);
375893f7848bSJeff Kirsher mgp->board_number = board_number;
375993f7848bSJeff Kirsher init_waitqueue_head(&mgp->down_wq);
376093f7848bSJeff Kirsher
376193f7848bSJeff Kirsher if (pci_enable_device(pdev)) {
376293f7848bSJeff Kirsher dev_err(&pdev->dev, "pci_enable_device call failed\n");
376393f7848bSJeff Kirsher status = -ENODEV;
376493f7848bSJeff Kirsher goto abort_with_netdev;
376593f7848bSJeff Kirsher }
376693f7848bSJeff Kirsher
376793f7848bSJeff Kirsher /* Find the vendor-specific cap so we can check
376893f7848bSJeff Kirsher * the reboot register later on */
376993f7848bSJeff Kirsher mgp->vendor_specific_offset
377093f7848bSJeff Kirsher = pci_find_capability(pdev, PCI_CAP_ID_VNDR);
377193f7848bSJeff Kirsher
377293f7848bSJeff Kirsher /* Set our max read request to 4KB */
377393f7848bSJeff Kirsher status = pcie_set_readrq(pdev, 4096);
377493f7848bSJeff Kirsher if (status != 0) {
377593f7848bSJeff Kirsher dev_err(&pdev->dev, "Error %d writing PCI_EXP_DEVCTL\n",
377693f7848bSJeff Kirsher status);
377793f7848bSJeff Kirsher goto abort_with_enabled;
377893f7848bSJeff Kirsher }
377993f7848bSJeff Kirsher
378093f7848bSJeff Kirsher myri10ge_mask_surprise_down(pdev);
378193f7848bSJeff Kirsher pci_set_master(pdev);
378275bacb6dSChristophe JAILLET status = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
378393f7848bSJeff Kirsher if (status != 0) {
378493f7848bSJeff Kirsher dev_err(&pdev->dev, "Error %d setting DMA mask\n", status);
378593f7848bSJeff Kirsher goto abort_with_enabled;
378693f7848bSJeff Kirsher }
378793f7848bSJeff Kirsher mgp->cmd = dma_alloc_coherent(&pdev->dev, sizeof(*mgp->cmd),
378893f7848bSJeff Kirsher &mgp->cmd_bus, GFP_KERNEL);
3789f12e77caSJulia Lawall if (!mgp->cmd) {
3790f12e77caSJulia Lawall status = -ENOMEM;
379193f7848bSJeff Kirsher goto abort_with_enabled;
3792f12e77caSJulia Lawall }
379393f7848bSJeff Kirsher
379493f7848bSJeff Kirsher mgp->board_span = pci_resource_len(pdev, 0);
379593f7848bSJeff Kirsher mgp->iomem_base = pci_resource_start(pdev, 0);
3796e4b6c303SLuis R. Rodriguez mgp->wc_cookie = arch_phys_wc_add(mgp->iomem_base, mgp->board_span);
379793f7848bSJeff Kirsher mgp->sram = ioremap_wc(mgp->iomem_base, mgp->board_span);
379893f7848bSJeff Kirsher if (mgp->sram == NULL) {
379993f7848bSJeff Kirsher dev_err(&pdev->dev, "ioremap failed for %ld bytes at 0x%lx\n",
380093f7848bSJeff Kirsher mgp->board_span, mgp->iomem_base);
380193f7848bSJeff Kirsher status = -ENXIO;
380293f7848bSJeff Kirsher goto abort_with_mtrr;
380393f7848bSJeff Kirsher }
380493f7848bSJeff Kirsher hdr_offset =
380559e955edSAndrew Gallatin swab32(readl(mgp->sram + MCP_HEADER_PTR_OFFSET)) & 0xffffc;
380693f7848bSJeff Kirsher ss_offset = hdr_offset + offsetof(struct mcp_gen_header, string_specs);
380759e955edSAndrew Gallatin mgp->sram_size = swab32(readl(mgp->sram + ss_offset));
380893f7848bSJeff Kirsher if (mgp->sram_size > mgp->board_span ||
380993f7848bSJeff Kirsher mgp->sram_size <= MYRI10GE_FW_OFFSET) {
381093f7848bSJeff Kirsher dev_err(&pdev->dev,
381193f7848bSJeff Kirsher "invalid sram_size %dB or board span %ldB\n",
381293f7848bSJeff Kirsher mgp->sram_size, mgp->board_span);
3813f336d0b9SJiapeng Chong status = -EINVAL;
381493f7848bSJeff Kirsher goto abort_with_ioremap;
381593f7848bSJeff Kirsher }
381693f7848bSJeff Kirsher memcpy_fromio(mgp->eeprom_strings,
381793f7848bSJeff Kirsher mgp->sram + mgp->sram_size, MYRI10GE_EEPROM_STRINGS_SIZE);
381893f7848bSJeff Kirsher memset(mgp->eeprom_strings + MYRI10GE_EEPROM_STRINGS_SIZE - 2, 0, 2);
381993f7848bSJeff Kirsher status = myri10ge_read_mac_addr(mgp);
382093f7848bSJeff Kirsher if (status)
382193f7848bSJeff Kirsher goto abort_with_ioremap;
382293f7848bSJeff Kirsher
3823562ef98aSJakub Kicinski eth_hw_addr_set(netdev, mgp->mac_addr);
382493f7848bSJeff Kirsher
382593f7848bSJeff Kirsher myri10ge_select_firmware(mgp);
382693f7848bSJeff Kirsher
382793f7848bSJeff Kirsher status = myri10ge_load_firmware(mgp, 1);
382893f7848bSJeff Kirsher if (status != 0) {
382993f7848bSJeff Kirsher dev_err(&pdev->dev, "failed to load firmware\n");
383093f7848bSJeff Kirsher goto abort_with_ioremap;
383193f7848bSJeff Kirsher }
383293f7848bSJeff Kirsher myri10ge_probe_slices(mgp);
383393f7848bSJeff Kirsher status = myri10ge_alloc_slices(mgp);
383493f7848bSJeff Kirsher if (status != 0) {
383593f7848bSJeff Kirsher dev_err(&pdev->dev, "failed to alloc slice state\n");
383693f7848bSJeff Kirsher goto abort_with_firmware;
383793f7848bSJeff Kirsher }
383893f7848bSJeff Kirsher netif_set_real_num_tx_queues(netdev, mgp->num_slices);
383993f7848bSJeff Kirsher netif_set_real_num_rx_queues(netdev, mgp->num_slices);
384093f7848bSJeff Kirsher status = myri10ge_reset(mgp);
384193f7848bSJeff Kirsher if (status != 0) {
384293f7848bSJeff Kirsher dev_err(&pdev->dev, "failed reset\n");
384393f7848bSJeff Kirsher goto abort_with_slices;
384493f7848bSJeff Kirsher }
384593f7848bSJeff Kirsher #ifdef CONFIG_MYRI10GE_DCA
384693f7848bSJeff Kirsher myri10ge_setup_dca(mgp);
384793f7848bSJeff Kirsher #endif
384893f7848bSJeff Kirsher pci_set_drvdata(pdev, mgp);
384944770e11SJarod Wilson
385044770e11SJarod Wilson /* MTU range: 68 - 9000 */
385144770e11SJarod Wilson netdev->min_mtu = ETH_MIN_MTU;
385244770e11SJarod Wilson netdev->max_mtu = MYRI10GE_MAX_ETHER_MTU - ETH_HLEN;
385344770e11SJarod Wilson
385444770e11SJarod Wilson if (myri10ge_initial_mtu > netdev->max_mtu)
385544770e11SJarod Wilson myri10ge_initial_mtu = netdev->max_mtu;
385644770e11SJarod Wilson if (myri10ge_initial_mtu < netdev->min_mtu)
385744770e11SJarod Wilson myri10ge_initial_mtu = netdev->min_mtu;
385844770e11SJarod Wilson
385944770e11SJarod Wilson netdev->mtu = myri10ge_initial_mtu;
386093f7848bSJeff Kirsher
386193f7848bSJeff Kirsher netdev->netdev_ops = &myri10ge_netdev_ops;
38624ca3221fSAndrew Gallatin netdev->hw_features = mgp->features | NETIF_F_RXCSUM;
38631b4c44e6SAndrew Gallatin
3864f646968fSPatrick McHardy /* fake NETIF_F_HW_VLAN_CTAG_RX for good GRO performance */
3865f646968fSPatrick McHardy netdev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX;
38661b4c44e6SAndrew Gallatin
386721ef11eaSChristophe JAILLET netdev->features = netdev->hw_features | NETIF_F_HIGHDMA;
386893f7848bSJeff Kirsher
386993f7848bSJeff Kirsher netdev->vlan_features |= mgp->features;
387093f7848bSJeff Kirsher if (mgp->fw_ver_tiny < 37)
387193f7848bSJeff Kirsher netdev->vlan_features &= ~NETIF_F_TSO6;
387293f7848bSJeff Kirsher if (mgp->fw_ver_tiny < 32)
387393f7848bSJeff Kirsher netdev->vlan_features &= ~NETIF_F_TSO;
387493f7848bSJeff Kirsher
387593f7848bSJeff Kirsher /* make sure we can get an irq, and that MSI can be
3876a7425458SFrancois Romieu * setup (if available). */
387793f7848bSJeff Kirsher status = myri10ge_request_irq(mgp);
387893f7848bSJeff Kirsher if (status != 0)
387920fb7c7aSWenwen Wang goto abort_with_slices;
388093f7848bSJeff Kirsher myri10ge_free_irq(mgp);
388193f7848bSJeff Kirsher
388293f7848bSJeff Kirsher /* Save configuration space to be restored if the
388393f7848bSJeff Kirsher * nic resets due to a parity error */
388493f7848bSJeff Kirsher pci_save_state(pdev);
388593f7848bSJeff Kirsher
388693f7848bSJeff Kirsher /* Setup the watchdog timer */
3887e99e88a9SKees Cook timer_setup(&mgp->watchdog_timer, myri10ge_watchdog_timer, 0);
388893f7848bSJeff Kirsher
38897ad24ea4SWilfried Klaebe netdev->ethtool_ops = &myri10ge_ethtool_ops;
389093f7848bSJeff Kirsher INIT_WORK(&mgp->watchdog_work, myri10ge_watchdog);
389193f7848bSJeff Kirsher status = register_netdev(netdev);
389293f7848bSJeff Kirsher if (status != 0) {
389393f7848bSJeff Kirsher dev_err(&pdev->dev, "register_netdev failed: %d\n", status);
389493f7848bSJeff Kirsher goto abort_with_state;
389593f7848bSJeff Kirsher }
389693f7848bSJeff Kirsher if (mgp->msix_enabled)
3897e4b6c303SLuis R. Rodriguez dev_info(dev, "%d MSI-X IRQs, tx bndry %d, fw %s, MTRR %s, WC Enabled\n",
389893f7848bSJeff Kirsher mgp->num_slices, mgp->tx_boundary, mgp->fw_name,
3899e4b6c303SLuis R. Rodriguez (mgp->wc_cookie > 0 ? "Enabled" : "Disabled"));
390093f7848bSJeff Kirsher else
3901e4b6c303SLuis R. Rodriguez dev_info(dev, "%s IRQ %d, tx bndry %d, fw %s, MTRR %s, WC Enabled\n",
390293f7848bSJeff Kirsher mgp->msi_enabled ? "MSI" : "xPIC",
3903a7425458SFrancois Romieu pdev->irq, mgp->tx_boundary, mgp->fw_name,
3904e4b6c303SLuis R. Rodriguez (mgp->wc_cookie > 0 ? "Enabled" : "Disabled"));
390593f7848bSJeff Kirsher
390693f7848bSJeff Kirsher board_number++;
390793f7848bSJeff Kirsher return 0;
390893f7848bSJeff Kirsher
390993f7848bSJeff Kirsher abort_with_state:
391093f7848bSJeff Kirsher pci_restore_state(pdev);
391193f7848bSJeff Kirsher
391293f7848bSJeff Kirsher abort_with_slices:
391393f7848bSJeff Kirsher myri10ge_free_slices(mgp);
391493f7848bSJeff Kirsher
391593f7848bSJeff Kirsher abort_with_firmware:
3916d83b950dSChristophe JAILLET kfree(mgp->msix_vectors);
391793f7848bSJeff Kirsher myri10ge_dummy_rdma(mgp, 0);
391893f7848bSJeff Kirsher
391993f7848bSJeff Kirsher abort_with_ioremap:
392093f7848bSJeff Kirsher if (mgp->mac_addr_string != NULL)
392193f7848bSJeff Kirsher dev_err(&pdev->dev,
392293f7848bSJeff Kirsher "myri10ge_probe() failed: MAC=%s, SN=%ld\n",
392393f7848bSJeff Kirsher mgp->mac_addr_string, mgp->serial_number);
392493f7848bSJeff Kirsher iounmap(mgp->sram);
392593f7848bSJeff Kirsher
392693f7848bSJeff Kirsher abort_with_mtrr:
3927e4b6c303SLuis R. Rodriguez arch_phys_wc_del(mgp->wc_cookie);
392893f7848bSJeff Kirsher dma_free_coherent(&pdev->dev, sizeof(*mgp->cmd),
392993f7848bSJeff Kirsher mgp->cmd, mgp->cmd_bus);
393093f7848bSJeff Kirsher
393193f7848bSJeff Kirsher abort_with_enabled:
393293f7848bSJeff Kirsher pci_disable_device(pdev);
393393f7848bSJeff Kirsher
393493f7848bSJeff Kirsher abort_with_netdev:
393593f7848bSJeff Kirsher set_fw_name(mgp, NULL, false);
393693f7848bSJeff Kirsher free_netdev(netdev);
393793f7848bSJeff Kirsher return status;
393893f7848bSJeff Kirsher }
393993f7848bSJeff Kirsher
394093f7848bSJeff Kirsher /*
394193f7848bSJeff Kirsher * myri10ge_remove
394293f7848bSJeff Kirsher *
394393f7848bSJeff Kirsher * Does what is necessary to shutdown one Myrinet device. Called
394493f7848bSJeff Kirsher * once for each Myrinet card by the kernel when a module is
394593f7848bSJeff Kirsher * unloaded.
394693f7848bSJeff Kirsher */
myri10ge_remove(struct pci_dev * pdev)394793f7848bSJeff Kirsher static void myri10ge_remove(struct pci_dev *pdev)
394893f7848bSJeff Kirsher {
394993f7848bSJeff Kirsher struct myri10ge_priv *mgp;
395093f7848bSJeff Kirsher struct net_device *netdev;
395193f7848bSJeff Kirsher
395293f7848bSJeff Kirsher mgp = pci_get_drvdata(pdev);
395393f7848bSJeff Kirsher if (mgp == NULL)
395493f7848bSJeff Kirsher return;
395593f7848bSJeff Kirsher
395693f7848bSJeff Kirsher cancel_work_sync(&mgp->watchdog_work);
395793f7848bSJeff Kirsher netdev = mgp->dev;
395893f7848bSJeff Kirsher unregister_netdev(netdev);
395993f7848bSJeff Kirsher
396093f7848bSJeff Kirsher #ifdef CONFIG_MYRI10GE_DCA
396193f7848bSJeff Kirsher myri10ge_teardown_dca(mgp);
396293f7848bSJeff Kirsher #endif
396393f7848bSJeff Kirsher myri10ge_dummy_rdma(mgp, 0);
396493f7848bSJeff Kirsher
396593f7848bSJeff Kirsher /* avoid a memory leak */
396693f7848bSJeff Kirsher pci_restore_state(pdev);
396793f7848bSJeff Kirsher
396893f7848bSJeff Kirsher iounmap(mgp->sram);
3969e4b6c303SLuis R. Rodriguez arch_phys_wc_del(mgp->wc_cookie);
397093f7848bSJeff Kirsher myri10ge_free_slices(mgp);
397193f7848bSJeff Kirsher kfree(mgp->msix_vectors);
397293f7848bSJeff Kirsher dma_free_coherent(&pdev->dev, sizeof(*mgp->cmd),
397393f7848bSJeff Kirsher mgp->cmd, mgp->cmd_bus);
397493f7848bSJeff Kirsher
397593f7848bSJeff Kirsher set_fw_name(mgp, NULL, false);
397693f7848bSJeff Kirsher free_netdev(netdev);
397793f7848bSJeff Kirsher pci_disable_device(pdev);
397893f7848bSJeff Kirsher }
397993f7848bSJeff Kirsher
398093f7848bSJeff Kirsher #define PCI_DEVICE_ID_MYRICOM_MYRI10GE_Z8E 0x0008
398193f7848bSJeff Kirsher #define PCI_DEVICE_ID_MYRICOM_MYRI10GE_Z8E_9 0x0009
398293f7848bSJeff Kirsher
39839baa3c34SBenoit Taine static const struct pci_device_id myri10ge_pci_tbl[] = {
398493f7848bSJeff Kirsher {PCI_DEVICE(PCI_VENDOR_ID_MYRICOM, PCI_DEVICE_ID_MYRICOM_MYRI10GE_Z8E)},
398593f7848bSJeff Kirsher {PCI_DEVICE
398693f7848bSJeff Kirsher (PCI_VENDOR_ID_MYRICOM, PCI_DEVICE_ID_MYRICOM_MYRI10GE_Z8E_9)},
398793f7848bSJeff Kirsher {0},
398893f7848bSJeff Kirsher };
398993f7848bSJeff Kirsher
399093f7848bSJeff Kirsher MODULE_DEVICE_TABLE(pci, myri10ge_pci_tbl);
399193f7848bSJeff Kirsher
39920c17ac54SVaibhav Gupta static SIMPLE_DEV_PM_OPS(myri10ge_pm_ops, myri10ge_suspend, myri10ge_resume);
39930c17ac54SVaibhav Gupta
399493f7848bSJeff Kirsher static struct pci_driver myri10ge_driver = {
399593f7848bSJeff Kirsher .name = "myri10ge",
399693f7848bSJeff Kirsher .probe = myri10ge_probe,
399793f7848bSJeff Kirsher .remove = myri10ge_remove,
399893f7848bSJeff Kirsher .id_table = myri10ge_pci_tbl,
39990c17ac54SVaibhav Gupta .driver.pm = &myri10ge_pm_ops,
400093f7848bSJeff Kirsher };
400193f7848bSJeff Kirsher
400293f7848bSJeff Kirsher #ifdef CONFIG_MYRI10GE_DCA
400393f7848bSJeff Kirsher static int
myri10ge_notify_dca(struct notifier_block * nb,unsigned long event,void * p)400493f7848bSJeff Kirsher myri10ge_notify_dca(struct notifier_block *nb, unsigned long event, void *p)
400593f7848bSJeff Kirsher {
400693f7848bSJeff Kirsher int err = driver_for_each_device(&myri10ge_driver.driver,
400793f7848bSJeff Kirsher NULL, &event,
400893f7848bSJeff Kirsher myri10ge_notify_dca_device);
400993f7848bSJeff Kirsher
401093f7848bSJeff Kirsher if (err)
401193f7848bSJeff Kirsher return NOTIFY_BAD;
401293f7848bSJeff Kirsher return NOTIFY_DONE;
401393f7848bSJeff Kirsher }
401493f7848bSJeff Kirsher
401593f7848bSJeff Kirsher static struct notifier_block myri10ge_dca_notifier = {
401693f7848bSJeff Kirsher .notifier_call = myri10ge_notify_dca,
401793f7848bSJeff Kirsher .next = NULL,
401893f7848bSJeff Kirsher .priority = 0,
401993f7848bSJeff Kirsher };
402093f7848bSJeff Kirsher #endif /* CONFIG_MYRI10GE_DCA */
402193f7848bSJeff Kirsher
myri10ge_init_module(void)402293f7848bSJeff Kirsher static __init int myri10ge_init_module(void)
402393f7848bSJeff Kirsher {
402493f7848bSJeff Kirsher pr_info("Version %s\n", MYRI10GE_VERSION_STR);
402593f7848bSJeff Kirsher
402693f7848bSJeff Kirsher if (myri10ge_rss_hash > MXGEFW_RSS_HASH_TYPE_MAX) {
402793f7848bSJeff Kirsher pr_err("Illegal rssh hash type %d, defaulting to source port\n",
402893f7848bSJeff Kirsher myri10ge_rss_hash);
402993f7848bSJeff Kirsher myri10ge_rss_hash = MXGEFW_RSS_HASH_TYPE_SRC_PORT;
403093f7848bSJeff Kirsher }
403193f7848bSJeff Kirsher #ifdef CONFIG_MYRI10GE_DCA
403293f7848bSJeff Kirsher dca_register_notify(&myri10ge_dca_notifier);
403393f7848bSJeff Kirsher #endif
403493f7848bSJeff Kirsher if (myri10ge_max_slices > MYRI10GE_MAX_SLICES)
403593f7848bSJeff Kirsher myri10ge_max_slices = MYRI10GE_MAX_SLICES;
403693f7848bSJeff Kirsher
403793f7848bSJeff Kirsher return pci_register_driver(&myri10ge_driver);
403893f7848bSJeff Kirsher }
403993f7848bSJeff Kirsher
404093f7848bSJeff Kirsher module_init(myri10ge_init_module);
404193f7848bSJeff Kirsher
myri10ge_cleanup_module(void)404293f7848bSJeff Kirsher static __exit void myri10ge_cleanup_module(void)
404393f7848bSJeff Kirsher {
404493f7848bSJeff Kirsher #ifdef CONFIG_MYRI10GE_DCA
404593f7848bSJeff Kirsher dca_unregister_notify(&myri10ge_dca_notifier);
404693f7848bSJeff Kirsher #endif
404793f7848bSJeff Kirsher pci_unregister_driver(&myri10ge_driver);
404893f7848bSJeff Kirsher }
404993f7848bSJeff Kirsher
405093f7848bSJeff Kirsher module_exit(myri10ge_cleanup_module);
4051