Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1 | /* Broadcom NetXtreme-C/E network driver. |
| 2 | * |
Michael Chan | 11f15ed | 2016-04-05 14:08:55 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2016 Broadcom Corporation |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation. |
| 8 | */ |
| 9 | |
| 10 | #include <linux/module.h> |
| 11 | |
| 12 | #include <linux/stringify.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/timer.h> |
| 15 | #include <linux/errno.h> |
| 16 | #include <linux/ioport.h> |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/vmalloc.h> |
| 19 | #include <linux/interrupt.h> |
| 20 | #include <linux/pci.h> |
| 21 | #include <linux/netdevice.h> |
| 22 | #include <linux/etherdevice.h> |
| 23 | #include <linux/skbuff.h> |
| 24 | #include <linux/dma-mapping.h> |
| 25 | #include <linux/bitops.h> |
| 26 | #include <linux/io.h> |
| 27 | #include <linux/irq.h> |
| 28 | #include <linux/delay.h> |
| 29 | #include <asm/byteorder.h> |
| 30 | #include <asm/page.h> |
| 31 | #include <linux/time.h> |
| 32 | #include <linux/mii.h> |
| 33 | #include <linux/if.h> |
| 34 | #include <linux/if_vlan.h> |
Rob Swindell | 5ac67d8 | 2016-09-19 03:58:03 -0400 | [diff] [blame] | 35 | #include <linux/rtc.h> |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 36 | #include <net/ip.h> |
| 37 | #include <net/tcp.h> |
| 38 | #include <net/udp.h> |
| 39 | #include <net/checksum.h> |
| 40 | #include <net/ip6_checksum.h> |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 41 | #include <net/udp_tunnel.h> |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 42 | #include <linux/workqueue.h> |
| 43 | #include <linux/prefetch.h> |
| 44 | #include <linux/cache.h> |
| 45 | #include <linux/log2.h> |
| 46 | #include <linux/aer.h> |
| 47 | #include <linux/bitmap.h> |
| 48 | #include <linux/cpu_rmap.h> |
| 49 | |
| 50 | #include "bnxt_hsi.h" |
| 51 | #include "bnxt.h" |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 52 | #include "bnxt_ulp.h" |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 53 | #include "bnxt_sriov.h" |
| 54 | #include "bnxt_ethtool.h" |
Michael Chan | 7df4ae9 | 2016-12-02 21:17:17 -0500 | [diff] [blame] | 55 | #include "bnxt_dcb.h" |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 56 | |
| 57 | #define BNXT_TX_TIMEOUT (5 * HZ) |
| 58 | |
| 59 | static const char version[] = |
| 60 | "Broadcom NetXtreme-C/E driver " DRV_MODULE_NAME " v" DRV_MODULE_VERSION "\n"; |
| 61 | |
| 62 | MODULE_LICENSE("GPL"); |
| 63 | MODULE_DESCRIPTION("Broadcom BCM573xx network driver"); |
| 64 | MODULE_VERSION(DRV_MODULE_VERSION); |
| 65 | |
| 66 | #define BNXT_RX_OFFSET (NET_SKB_PAD + NET_IP_ALIGN) |
| 67 | #define BNXT_RX_DMA_OFFSET NET_SKB_PAD |
| 68 | #define BNXT_RX_COPY_THRESH 256 |
| 69 | |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 70 | #define BNXT_TX_PUSH_THRESH 164 |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 71 | |
| 72 | enum board_idx { |
David Christensen | fbc9a52 | 2015-12-27 18:19:29 -0500 | [diff] [blame] | 73 | BCM57301, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 74 | BCM57302, |
| 75 | BCM57304, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 76 | BCM57417_NPAR, |
Prashant Sreedharan | fa853dd | 2016-07-18 07:15:25 -0400 | [diff] [blame] | 77 | BCM58700, |
Michael Chan | b24eb6a | 2016-06-13 02:25:36 -0400 | [diff] [blame] | 78 | BCM57311, |
| 79 | BCM57312, |
David Christensen | fbc9a52 | 2015-12-27 18:19:29 -0500 | [diff] [blame] | 80 | BCM57402, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 81 | BCM57404, |
| 82 | BCM57406, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 83 | BCM57402_NPAR, |
| 84 | BCM57407, |
Michael Chan | b24eb6a | 2016-06-13 02:25:36 -0400 | [diff] [blame] | 85 | BCM57412, |
| 86 | BCM57414, |
| 87 | BCM57416, |
| 88 | BCM57417, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 89 | BCM57412_NPAR, |
Michael Chan | 5049e33 | 2016-05-15 03:04:50 -0400 | [diff] [blame] | 90 | BCM57314, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 91 | BCM57417_SFP, |
| 92 | BCM57416_SFP, |
| 93 | BCM57404_NPAR, |
| 94 | BCM57406_NPAR, |
| 95 | BCM57407_SFP, |
Michael Chan | adbc830 | 2016-09-19 03:58:01 -0400 | [diff] [blame] | 96 | BCM57407_NPAR, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 97 | BCM57414_NPAR, |
| 98 | BCM57416_NPAR, |
Michael Chan | adbc830 | 2016-09-19 03:58:01 -0400 | [diff] [blame] | 99 | NETXTREME_E_VF, |
| 100 | NETXTREME_C_VF, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | /* indexed by enum above */ |
| 104 | static const struct { |
| 105 | char *name; |
| 106 | } board_info[] = { |
Michael Chan | adbc830 | 2016-09-19 03:58:01 -0400 | [diff] [blame] | 107 | { "Broadcom BCM57301 NetXtreme-C 10Gb Ethernet" }, |
| 108 | { "Broadcom BCM57302 NetXtreme-C 10Gb/25Gb Ethernet" }, |
| 109 | { "Broadcom BCM57304 NetXtreme-C 10Gb/25Gb/40Gb/50Gb Ethernet" }, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 110 | { "Broadcom BCM57417 NetXtreme-E Ethernet Partition" }, |
Michael Chan | adbc830 | 2016-09-19 03:58:01 -0400 | [diff] [blame] | 111 | { "Broadcom BCM58700 Nitro 1Gb/2.5Gb/10Gb Ethernet" }, |
| 112 | { "Broadcom BCM57311 NetXtreme-C 10Gb Ethernet" }, |
| 113 | { "Broadcom BCM57312 NetXtreme-C 10Gb/25Gb Ethernet" }, |
| 114 | { "Broadcom BCM57402 NetXtreme-E 10Gb Ethernet" }, |
| 115 | { "Broadcom BCM57404 NetXtreme-E 10Gb/25Gb Ethernet" }, |
| 116 | { "Broadcom BCM57406 NetXtreme-E 10GBase-T Ethernet" }, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 117 | { "Broadcom BCM57402 NetXtreme-E Ethernet Partition" }, |
Michael Chan | adbc830 | 2016-09-19 03:58:01 -0400 | [diff] [blame] | 118 | { "Broadcom BCM57407 NetXtreme-E 10GBase-T Ethernet" }, |
| 119 | { "Broadcom BCM57412 NetXtreme-E 10Gb Ethernet" }, |
| 120 | { "Broadcom BCM57414 NetXtreme-E 10Gb/25Gb Ethernet" }, |
| 121 | { "Broadcom BCM57416 NetXtreme-E 10GBase-T Ethernet" }, |
| 122 | { "Broadcom BCM57417 NetXtreme-E 10GBase-T Ethernet" }, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 123 | { "Broadcom BCM57412 NetXtreme-E Ethernet Partition" }, |
Michael Chan | adbc830 | 2016-09-19 03:58:01 -0400 | [diff] [blame] | 124 | { "Broadcom BCM57314 NetXtreme-C 10Gb/25Gb/40Gb/50Gb Ethernet" }, |
| 125 | { "Broadcom BCM57417 NetXtreme-E 10Gb/25Gb Ethernet" }, |
| 126 | { "Broadcom BCM57416 NetXtreme-E 10Gb Ethernet" }, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 127 | { "Broadcom BCM57404 NetXtreme-E Ethernet Partition" }, |
| 128 | { "Broadcom BCM57406 NetXtreme-E Ethernet Partition" }, |
Michael Chan | adbc830 | 2016-09-19 03:58:01 -0400 | [diff] [blame] | 129 | { "Broadcom BCM57407 NetXtreme-E 25Gb Ethernet" }, |
| 130 | { "Broadcom BCM57407 NetXtreme-E Ethernet Partition" }, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 131 | { "Broadcom BCM57414 NetXtreme-E Ethernet Partition" }, |
| 132 | { "Broadcom BCM57416 NetXtreme-E Ethernet Partition" }, |
Michael Chan | adbc830 | 2016-09-19 03:58:01 -0400 | [diff] [blame] | 133 | { "Broadcom NetXtreme-E Ethernet Virtual Function" }, |
| 134 | { "Broadcom NetXtreme-C Ethernet Virtual Function" }, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | static const struct pci_device_id bnxt_pci_tbl[] = { |
Michael Chan | adbc830 | 2016-09-19 03:58:01 -0400 | [diff] [blame] | 138 | { PCI_VDEVICE(BROADCOM, 0x16c0), .driver_data = BCM57417_NPAR }, |
David Christensen | fbc9a52 | 2015-12-27 18:19:29 -0500 | [diff] [blame] | 139 | { PCI_VDEVICE(BROADCOM, 0x16c8), .driver_data = BCM57301 }, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 140 | { PCI_VDEVICE(BROADCOM, 0x16c9), .driver_data = BCM57302 }, |
| 141 | { PCI_VDEVICE(BROADCOM, 0x16ca), .driver_data = BCM57304 }, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 142 | { PCI_VDEVICE(BROADCOM, 0x16cc), .driver_data = BCM57417_NPAR }, |
Prashant Sreedharan | fa853dd | 2016-07-18 07:15:25 -0400 | [diff] [blame] | 143 | { PCI_VDEVICE(BROADCOM, 0x16cd), .driver_data = BCM58700 }, |
Michael Chan | b24eb6a | 2016-06-13 02:25:36 -0400 | [diff] [blame] | 144 | { PCI_VDEVICE(BROADCOM, 0x16ce), .driver_data = BCM57311 }, |
| 145 | { PCI_VDEVICE(BROADCOM, 0x16cf), .driver_data = BCM57312 }, |
David Christensen | fbc9a52 | 2015-12-27 18:19:29 -0500 | [diff] [blame] | 146 | { PCI_VDEVICE(BROADCOM, 0x16d0), .driver_data = BCM57402 }, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 147 | { PCI_VDEVICE(BROADCOM, 0x16d1), .driver_data = BCM57404 }, |
| 148 | { PCI_VDEVICE(BROADCOM, 0x16d2), .driver_data = BCM57406 }, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 149 | { PCI_VDEVICE(BROADCOM, 0x16d4), .driver_data = BCM57402_NPAR }, |
| 150 | { PCI_VDEVICE(BROADCOM, 0x16d5), .driver_data = BCM57407 }, |
Michael Chan | b24eb6a | 2016-06-13 02:25:36 -0400 | [diff] [blame] | 151 | { PCI_VDEVICE(BROADCOM, 0x16d6), .driver_data = BCM57412 }, |
| 152 | { PCI_VDEVICE(BROADCOM, 0x16d7), .driver_data = BCM57414 }, |
| 153 | { PCI_VDEVICE(BROADCOM, 0x16d8), .driver_data = BCM57416 }, |
| 154 | { PCI_VDEVICE(BROADCOM, 0x16d9), .driver_data = BCM57417 }, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 155 | { PCI_VDEVICE(BROADCOM, 0x16de), .driver_data = BCM57412_NPAR }, |
Michael Chan | 5049e33 | 2016-05-15 03:04:50 -0400 | [diff] [blame] | 156 | { PCI_VDEVICE(BROADCOM, 0x16df), .driver_data = BCM57314 }, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 157 | { PCI_VDEVICE(BROADCOM, 0x16e2), .driver_data = BCM57417_SFP }, |
| 158 | { PCI_VDEVICE(BROADCOM, 0x16e3), .driver_data = BCM57416_SFP }, |
| 159 | { PCI_VDEVICE(BROADCOM, 0x16e7), .driver_data = BCM57404_NPAR }, |
| 160 | { PCI_VDEVICE(BROADCOM, 0x16e8), .driver_data = BCM57406_NPAR }, |
| 161 | { PCI_VDEVICE(BROADCOM, 0x16e9), .driver_data = BCM57407_SFP }, |
Michael Chan | adbc830 | 2016-09-19 03:58:01 -0400 | [diff] [blame] | 162 | { PCI_VDEVICE(BROADCOM, 0x16ea), .driver_data = BCM57407_NPAR }, |
| 163 | { PCI_VDEVICE(BROADCOM, 0x16eb), .driver_data = BCM57412_NPAR }, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 164 | { PCI_VDEVICE(BROADCOM, 0x16ec), .driver_data = BCM57414_NPAR }, |
Michael Chan | adbc830 | 2016-09-19 03:58:01 -0400 | [diff] [blame] | 165 | { PCI_VDEVICE(BROADCOM, 0x16ed), .driver_data = BCM57414_NPAR }, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 166 | { PCI_VDEVICE(BROADCOM, 0x16ee), .driver_data = BCM57416_NPAR }, |
Michael Chan | adbc830 | 2016-09-19 03:58:01 -0400 | [diff] [blame] | 167 | { PCI_VDEVICE(BROADCOM, 0x16ef), .driver_data = BCM57416_NPAR }, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 168 | #ifdef CONFIG_BNXT_SRIOV |
Michael Chan | adbc830 | 2016-09-19 03:58:01 -0400 | [diff] [blame] | 169 | { PCI_VDEVICE(BROADCOM, 0x16c1), .driver_data = NETXTREME_E_VF }, |
| 170 | { PCI_VDEVICE(BROADCOM, 0x16cb), .driver_data = NETXTREME_C_VF }, |
| 171 | { PCI_VDEVICE(BROADCOM, 0x16d3), .driver_data = NETXTREME_E_VF }, |
| 172 | { PCI_VDEVICE(BROADCOM, 0x16dc), .driver_data = NETXTREME_E_VF }, |
| 173 | { PCI_VDEVICE(BROADCOM, 0x16e1), .driver_data = NETXTREME_C_VF }, |
| 174 | { PCI_VDEVICE(BROADCOM, 0x16e5), .driver_data = NETXTREME_C_VF }, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 175 | #endif |
| 176 | { 0 } |
| 177 | }; |
| 178 | |
| 179 | MODULE_DEVICE_TABLE(pci, bnxt_pci_tbl); |
| 180 | |
| 181 | static const u16 bnxt_vf_req_snif[] = { |
| 182 | HWRM_FUNC_CFG, |
| 183 | HWRM_PORT_PHY_QCFG, |
| 184 | HWRM_CFA_L2_FILTER_ALLOC, |
| 185 | }; |
| 186 | |
Michael Chan | 25be862 | 2016-04-05 14:09:00 -0400 | [diff] [blame] | 187 | static const u16 bnxt_async_events_arr[] = { |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 188 | ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE, |
| 189 | ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD, |
| 190 | ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED, |
| 191 | ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE, |
| 192 | ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE, |
Michael Chan | 25be862 | 2016-04-05 14:09:00 -0400 | [diff] [blame] | 193 | }; |
| 194 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 195 | static bool bnxt_vf_pciid(enum board_idx idx) |
| 196 | { |
Michael Chan | adbc830 | 2016-09-19 03:58:01 -0400 | [diff] [blame] | 197 | return (idx == NETXTREME_C_VF || idx == NETXTREME_E_VF); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | #define DB_CP_REARM_FLAGS (DB_KEY_CP | DB_IDX_VALID) |
| 201 | #define DB_CP_FLAGS (DB_KEY_CP | DB_IDX_VALID | DB_IRQ_DIS) |
| 202 | #define DB_CP_IRQ_DIS_FLAGS (DB_KEY_CP | DB_IRQ_DIS) |
| 203 | |
| 204 | #define BNXT_CP_DB_REARM(db, raw_cons) \ |
| 205 | writel(DB_CP_REARM_FLAGS | RING_CMP(raw_cons), db) |
| 206 | |
| 207 | #define BNXT_CP_DB(db, raw_cons) \ |
| 208 | writel(DB_CP_FLAGS | RING_CMP(raw_cons), db) |
| 209 | |
| 210 | #define BNXT_CP_DB_IRQ_DIS(db) \ |
| 211 | writel(DB_CP_IRQ_DIS_FLAGS, db) |
| 212 | |
| 213 | static inline u32 bnxt_tx_avail(struct bnxt *bp, struct bnxt_tx_ring_info *txr) |
| 214 | { |
| 215 | /* Tell compiler to fetch tx indices from memory. */ |
| 216 | barrier(); |
| 217 | |
| 218 | return bp->tx_ring_size - |
| 219 | ((txr->tx_prod - txr->tx_cons) & bp->tx_ring_mask); |
| 220 | } |
| 221 | |
| 222 | static const u16 bnxt_lhint_arr[] = { |
| 223 | TX_BD_FLAGS_LHINT_512_AND_SMALLER, |
| 224 | TX_BD_FLAGS_LHINT_512_TO_1023, |
| 225 | TX_BD_FLAGS_LHINT_1024_TO_2047, |
| 226 | TX_BD_FLAGS_LHINT_1024_TO_2047, |
| 227 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 228 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 229 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 230 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 231 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 232 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 233 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 234 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 235 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 236 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 237 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 238 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 239 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 240 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 241 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 242 | }; |
| 243 | |
| 244 | static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 245 | { |
| 246 | struct bnxt *bp = netdev_priv(dev); |
| 247 | struct tx_bd *txbd; |
| 248 | struct tx_bd_ext *txbd1; |
| 249 | struct netdev_queue *txq; |
| 250 | int i; |
| 251 | dma_addr_t mapping; |
| 252 | unsigned int length, pad = 0; |
| 253 | u32 len, free_size, vlan_tag_flags, cfa_action, flags; |
| 254 | u16 prod, last_frag; |
| 255 | struct pci_dev *pdev = bp->pdev; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 256 | struct bnxt_tx_ring_info *txr; |
| 257 | struct bnxt_sw_tx_bd *tx_buf; |
| 258 | |
| 259 | i = skb_get_queue_mapping(skb); |
| 260 | if (unlikely(i >= bp->tx_nr_rings)) { |
| 261 | dev_kfree_skb_any(skb); |
| 262 | return NETDEV_TX_OK; |
| 263 | } |
| 264 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 265 | txr = &bp->tx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 266 | txq = netdev_get_tx_queue(dev, i); |
| 267 | prod = txr->tx_prod; |
| 268 | |
| 269 | free_size = bnxt_tx_avail(bp, txr); |
| 270 | if (unlikely(free_size < skb_shinfo(skb)->nr_frags + 2)) { |
| 271 | netif_tx_stop_queue(txq); |
| 272 | return NETDEV_TX_BUSY; |
| 273 | } |
| 274 | |
| 275 | length = skb->len; |
| 276 | len = skb_headlen(skb); |
| 277 | last_frag = skb_shinfo(skb)->nr_frags; |
| 278 | |
| 279 | txbd = &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)]; |
| 280 | |
| 281 | txbd->tx_bd_opaque = prod; |
| 282 | |
| 283 | tx_buf = &txr->tx_buf_ring[prod]; |
| 284 | tx_buf->skb = skb; |
| 285 | tx_buf->nr_frags = last_frag; |
| 286 | |
| 287 | vlan_tag_flags = 0; |
| 288 | cfa_action = 0; |
| 289 | if (skb_vlan_tag_present(skb)) { |
| 290 | vlan_tag_flags = TX_BD_CFA_META_KEY_VLAN | |
| 291 | skb_vlan_tag_get(skb); |
| 292 | /* Currently supports 8021Q, 8021AD vlan offloads |
| 293 | * QINQ1, QINQ2, QINQ3 vlan headers are deprecated |
| 294 | */ |
| 295 | if (skb->vlan_proto == htons(ETH_P_8021Q)) |
| 296 | vlan_tag_flags |= 1 << TX_BD_CFA_META_TPID_SHIFT; |
| 297 | } |
| 298 | |
| 299 | if (free_size == bp->tx_ring_size && length <= bp->tx_push_thresh) { |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 300 | struct tx_push_buffer *tx_push_buf = txr->tx_push; |
| 301 | struct tx_push_bd *tx_push = &tx_push_buf->push_bd; |
| 302 | struct tx_bd_ext *tx_push1 = &tx_push->txbd2; |
| 303 | void *pdata = tx_push_buf->data; |
| 304 | u64 *end; |
| 305 | int j, push_len; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 306 | |
| 307 | /* Set COAL_NOW to be ready quickly for the next push */ |
| 308 | tx_push->tx_bd_len_flags_type = |
| 309 | cpu_to_le32((length << TX_BD_LEN_SHIFT) | |
| 310 | TX_BD_TYPE_LONG_TX_BD | |
| 311 | TX_BD_FLAGS_LHINT_512_AND_SMALLER | |
| 312 | TX_BD_FLAGS_COAL_NOW | |
| 313 | TX_BD_FLAGS_PACKET_END | |
| 314 | (2 << TX_BD_FLAGS_BD_CNT_SHIFT)); |
| 315 | |
| 316 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
| 317 | tx_push1->tx_bd_hsize_lflags = |
| 318 | cpu_to_le32(TX_BD_FLAGS_TCP_UDP_CHKSUM); |
| 319 | else |
| 320 | tx_push1->tx_bd_hsize_lflags = 0; |
| 321 | |
| 322 | tx_push1->tx_bd_cfa_meta = cpu_to_le32(vlan_tag_flags); |
| 323 | tx_push1->tx_bd_cfa_action = cpu_to_le32(cfa_action); |
| 324 | |
Michael Chan | fbb0fa8 | 2016-02-22 02:10:26 -0500 | [diff] [blame] | 325 | end = pdata + length; |
| 326 | end = PTR_ALIGN(end, 8) - 1; |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 327 | *end = 0; |
| 328 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 329 | skb_copy_from_linear_data(skb, pdata, len); |
| 330 | pdata += len; |
| 331 | for (j = 0; j < last_frag; j++) { |
| 332 | skb_frag_t *frag = &skb_shinfo(skb)->frags[j]; |
| 333 | void *fptr; |
| 334 | |
| 335 | fptr = skb_frag_address_safe(frag); |
| 336 | if (!fptr) |
| 337 | goto normal_tx; |
| 338 | |
| 339 | memcpy(pdata, fptr, skb_frag_size(frag)); |
| 340 | pdata += skb_frag_size(frag); |
| 341 | } |
| 342 | |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 343 | txbd->tx_bd_len_flags_type = tx_push->tx_bd_len_flags_type; |
| 344 | txbd->tx_bd_haddr = txr->data_mapping; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 345 | prod = NEXT_TX(prod); |
| 346 | txbd = &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)]; |
| 347 | memcpy(txbd, tx_push1, sizeof(*txbd)); |
| 348 | prod = NEXT_TX(prod); |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 349 | tx_push->doorbell = |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 350 | cpu_to_le32(DB_KEY_TX_PUSH | DB_LONG_TX_PUSH | prod); |
| 351 | txr->tx_prod = prod; |
| 352 | |
Michael Chan | b9a8460 | 2016-06-06 02:37:14 -0400 | [diff] [blame] | 353 | tx_buf->is_push = 1; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 354 | netdev_tx_sent_queue(txq, skb->len); |
Michael Chan | b9a8460 | 2016-06-06 02:37:14 -0400 | [diff] [blame] | 355 | wmb(); /* Sync is_push and byte queue before pushing data */ |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 356 | |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 357 | push_len = (length + sizeof(*tx_push) + 7) / 8; |
| 358 | if (push_len > 16) { |
| 359 | __iowrite64_copy(txr->tx_doorbell, tx_push_buf, 16); |
Michael Chan | 9d13744 | 2016-09-05 01:57:35 -0400 | [diff] [blame] | 360 | __iowrite32_copy(txr->tx_doorbell + 4, tx_push_buf + 1, |
| 361 | (push_len - 16) << 1); |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 362 | } else { |
| 363 | __iowrite64_copy(txr->tx_doorbell, tx_push_buf, |
| 364 | push_len); |
| 365 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 366 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 367 | goto tx_done; |
| 368 | } |
| 369 | |
| 370 | normal_tx: |
| 371 | if (length < BNXT_MIN_PKT_SIZE) { |
| 372 | pad = BNXT_MIN_PKT_SIZE - length; |
| 373 | if (skb_pad(skb, pad)) { |
| 374 | /* SKB already freed. */ |
| 375 | tx_buf->skb = NULL; |
| 376 | return NETDEV_TX_OK; |
| 377 | } |
| 378 | length = BNXT_MIN_PKT_SIZE; |
| 379 | } |
| 380 | |
| 381 | mapping = dma_map_single(&pdev->dev, skb->data, len, DMA_TO_DEVICE); |
| 382 | |
| 383 | if (unlikely(dma_mapping_error(&pdev->dev, mapping))) { |
| 384 | dev_kfree_skb_any(skb); |
| 385 | tx_buf->skb = NULL; |
| 386 | return NETDEV_TX_OK; |
| 387 | } |
| 388 | |
| 389 | dma_unmap_addr_set(tx_buf, mapping, mapping); |
| 390 | flags = (len << TX_BD_LEN_SHIFT) | TX_BD_TYPE_LONG_TX_BD | |
| 391 | ((last_frag + 2) << TX_BD_FLAGS_BD_CNT_SHIFT); |
| 392 | |
| 393 | txbd->tx_bd_haddr = cpu_to_le64(mapping); |
| 394 | |
| 395 | prod = NEXT_TX(prod); |
| 396 | txbd1 = (struct tx_bd_ext *) |
| 397 | &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)]; |
| 398 | |
| 399 | txbd1->tx_bd_hsize_lflags = 0; |
| 400 | if (skb_is_gso(skb)) { |
| 401 | u32 hdr_len; |
| 402 | |
| 403 | if (skb->encapsulation) |
| 404 | hdr_len = skb_inner_network_offset(skb) + |
| 405 | skb_inner_network_header_len(skb) + |
| 406 | inner_tcp_hdrlen(skb); |
| 407 | else |
| 408 | hdr_len = skb_transport_offset(skb) + |
| 409 | tcp_hdrlen(skb); |
| 410 | |
| 411 | txbd1->tx_bd_hsize_lflags = cpu_to_le32(TX_BD_FLAGS_LSO | |
| 412 | TX_BD_FLAGS_T_IPID | |
| 413 | (hdr_len << (TX_BD_HSIZE_SHIFT - 1))); |
| 414 | length = skb_shinfo(skb)->gso_size; |
| 415 | txbd1->tx_bd_mss = cpu_to_le32(length); |
| 416 | length += hdr_len; |
| 417 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 418 | txbd1->tx_bd_hsize_lflags = |
| 419 | cpu_to_le32(TX_BD_FLAGS_TCP_UDP_CHKSUM); |
| 420 | txbd1->tx_bd_mss = 0; |
| 421 | } |
| 422 | |
| 423 | length >>= 9; |
| 424 | flags |= bnxt_lhint_arr[length]; |
| 425 | txbd->tx_bd_len_flags_type = cpu_to_le32(flags); |
| 426 | |
| 427 | txbd1->tx_bd_cfa_meta = cpu_to_le32(vlan_tag_flags); |
| 428 | txbd1->tx_bd_cfa_action = cpu_to_le32(cfa_action); |
| 429 | for (i = 0; i < last_frag; i++) { |
| 430 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 431 | |
| 432 | prod = NEXT_TX(prod); |
| 433 | txbd = &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)]; |
| 434 | |
| 435 | len = skb_frag_size(frag); |
| 436 | mapping = skb_frag_dma_map(&pdev->dev, frag, 0, len, |
| 437 | DMA_TO_DEVICE); |
| 438 | |
| 439 | if (unlikely(dma_mapping_error(&pdev->dev, mapping))) |
| 440 | goto tx_dma_error; |
| 441 | |
| 442 | tx_buf = &txr->tx_buf_ring[prod]; |
| 443 | dma_unmap_addr_set(tx_buf, mapping, mapping); |
| 444 | |
| 445 | txbd->tx_bd_haddr = cpu_to_le64(mapping); |
| 446 | |
| 447 | flags = len << TX_BD_LEN_SHIFT; |
| 448 | txbd->tx_bd_len_flags_type = cpu_to_le32(flags); |
| 449 | } |
| 450 | |
| 451 | flags &= ~TX_BD_LEN; |
| 452 | txbd->tx_bd_len_flags_type = |
| 453 | cpu_to_le32(((len + pad) << TX_BD_LEN_SHIFT) | flags | |
| 454 | TX_BD_FLAGS_PACKET_END); |
| 455 | |
| 456 | netdev_tx_sent_queue(txq, skb->len); |
| 457 | |
| 458 | /* Sync BD data before updating doorbell */ |
| 459 | wmb(); |
| 460 | |
| 461 | prod = NEXT_TX(prod); |
| 462 | txr->tx_prod = prod; |
| 463 | |
| 464 | writel(DB_KEY_TX | prod, txr->tx_doorbell); |
| 465 | writel(DB_KEY_TX | prod, txr->tx_doorbell); |
| 466 | |
| 467 | tx_done: |
| 468 | |
| 469 | mmiowb(); |
| 470 | |
| 471 | if (unlikely(bnxt_tx_avail(bp, txr) <= MAX_SKB_FRAGS + 1)) { |
| 472 | netif_tx_stop_queue(txq); |
| 473 | |
| 474 | /* netif_tx_stop_queue() must be done before checking |
| 475 | * tx index in bnxt_tx_avail() below, because in |
| 476 | * bnxt_tx_int(), we update tx index before checking for |
| 477 | * netif_tx_queue_stopped(). |
| 478 | */ |
| 479 | smp_mb(); |
| 480 | if (bnxt_tx_avail(bp, txr) > bp->tx_wake_thresh) |
| 481 | netif_tx_wake_queue(txq); |
| 482 | } |
| 483 | return NETDEV_TX_OK; |
| 484 | |
| 485 | tx_dma_error: |
| 486 | last_frag = i; |
| 487 | |
| 488 | /* start back at beginning and unmap skb */ |
| 489 | prod = txr->tx_prod; |
| 490 | tx_buf = &txr->tx_buf_ring[prod]; |
| 491 | tx_buf->skb = NULL; |
| 492 | dma_unmap_single(&pdev->dev, dma_unmap_addr(tx_buf, mapping), |
| 493 | skb_headlen(skb), PCI_DMA_TODEVICE); |
| 494 | prod = NEXT_TX(prod); |
| 495 | |
| 496 | /* unmap remaining mapped pages */ |
| 497 | for (i = 0; i < last_frag; i++) { |
| 498 | prod = NEXT_TX(prod); |
| 499 | tx_buf = &txr->tx_buf_ring[prod]; |
| 500 | dma_unmap_page(&pdev->dev, dma_unmap_addr(tx_buf, mapping), |
| 501 | skb_frag_size(&skb_shinfo(skb)->frags[i]), |
| 502 | PCI_DMA_TODEVICE); |
| 503 | } |
| 504 | |
| 505 | dev_kfree_skb_any(skb); |
| 506 | return NETDEV_TX_OK; |
| 507 | } |
| 508 | |
| 509 | static void bnxt_tx_int(struct bnxt *bp, struct bnxt_napi *bnapi, int nr_pkts) |
| 510 | { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 511 | struct bnxt_tx_ring_info *txr = bnapi->tx_ring; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 512 | int index = txr - &bp->tx_ring[0]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 513 | struct netdev_queue *txq = netdev_get_tx_queue(bp->dev, index); |
| 514 | u16 cons = txr->tx_cons; |
| 515 | struct pci_dev *pdev = bp->pdev; |
| 516 | int i; |
| 517 | unsigned int tx_bytes = 0; |
| 518 | |
| 519 | for (i = 0; i < nr_pkts; i++) { |
| 520 | struct bnxt_sw_tx_bd *tx_buf; |
| 521 | struct sk_buff *skb; |
| 522 | int j, last; |
| 523 | |
| 524 | tx_buf = &txr->tx_buf_ring[cons]; |
| 525 | cons = NEXT_TX(cons); |
| 526 | skb = tx_buf->skb; |
| 527 | tx_buf->skb = NULL; |
| 528 | |
| 529 | if (tx_buf->is_push) { |
| 530 | tx_buf->is_push = 0; |
| 531 | goto next_tx_int; |
| 532 | } |
| 533 | |
| 534 | dma_unmap_single(&pdev->dev, dma_unmap_addr(tx_buf, mapping), |
| 535 | skb_headlen(skb), PCI_DMA_TODEVICE); |
| 536 | last = tx_buf->nr_frags; |
| 537 | |
| 538 | for (j = 0; j < last; j++) { |
| 539 | cons = NEXT_TX(cons); |
| 540 | tx_buf = &txr->tx_buf_ring[cons]; |
| 541 | dma_unmap_page( |
| 542 | &pdev->dev, |
| 543 | dma_unmap_addr(tx_buf, mapping), |
| 544 | skb_frag_size(&skb_shinfo(skb)->frags[j]), |
| 545 | PCI_DMA_TODEVICE); |
| 546 | } |
| 547 | |
| 548 | next_tx_int: |
| 549 | cons = NEXT_TX(cons); |
| 550 | |
| 551 | tx_bytes += skb->len; |
| 552 | dev_kfree_skb_any(skb); |
| 553 | } |
| 554 | |
| 555 | netdev_tx_completed_queue(txq, nr_pkts, tx_bytes); |
| 556 | txr->tx_cons = cons; |
| 557 | |
| 558 | /* Need to make the tx_cons update visible to bnxt_start_xmit() |
| 559 | * before checking for netif_tx_queue_stopped(). Without the |
| 560 | * memory barrier, there is a small possibility that bnxt_start_xmit() |
| 561 | * will miss it and cause the queue to be stopped forever. |
| 562 | */ |
| 563 | smp_mb(); |
| 564 | |
| 565 | if (unlikely(netif_tx_queue_stopped(txq)) && |
| 566 | (bnxt_tx_avail(bp, txr) > bp->tx_wake_thresh)) { |
| 567 | __netif_tx_lock(txq, smp_processor_id()); |
| 568 | if (netif_tx_queue_stopped(txq) && |
| 569 | bnxt_tx_avail(bp, txr) > bp->tx_wake_thresh && |
| 570 | txr->dev_state != BNXT_DEV_STATE_CLOSING) |
| 571 | netif_tx_wake_queue(txq); |
| 572 | __netif_tx_unlock(txq); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | static inline u8 *__bnxt_alloc_rx_data(struct bnxt *bp, dma_addr_t *mapping, |
| 577 | gfp_t gfp) |
| 578 | { |
| 579 | u8 *data; |
| 580 | struct pci_dev *pdev = bp->pdev; |
| 581 | |
| 582 | data = kmalloc(bp->rx_buf_size, gfp); |
| 583 | if (!data) |
| 584 | return NULL; |
| 585 | |
Michael Chan | b3dba77 | 2017-02-06 16:55:35 -0500 | [diff] [blame^] | 586 | *mapping = dma_map_single(&pdev->dev, data + bp->rx_dma_offset, |
Michael Chan | 745fc05 | 2017-02-06 16:55:34 -0500 | [diff] [blame] | 587 | bp->rx_buf_use_size, bp->rx_dir); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 588 | |
| 589 | if (dma_mapping_error(&pdev->dev, *mapping)) { |
| 590 | kfree(data); |
| 591 | data = NULL; |
| 592 | } |
| 593 | return data; |
| 594 | } |
| 595 | |
| 596 | static inline int bnxt_alloc_rx_data(struct bnxt *bp, |
| 597 | struct bnxt_rx_ring_info *rxr, |
| 598 | u16 prod, gfp_t gfp) |
| 599 | { |
| 600 | struct rx_bd *rxbd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)]; |
| 601 | struct bnxt_sw_rx_bd *rx_buf = &rxr->rx_buf_ring[prod]; |
| 602 | u8 *data; |
| 603 | dma_addr_t mapping; |
| 604 | |
| 605 | data = __bnxt_alloc_rx_data(bp, &mapping, gfp); |
| 606 | if (!data) |
| 607 | return -ENOMEM; |
| 608 | |
| 609 | rx_buf->data = data; |
Michael Chan | b3dba77 | 2017-02-06 16:55:35 -0500 | [diff] [blame^] | 610 | rx_buf->data_ptr = data + bp->rx_offset; |
Michael Chan | 11cd119 | 2017-02-06 16:55:33 -0500 | [diff] [blame] | 611 | rx_buf->mapping = mapping; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 612 | |
| 613 | rxbd->rx_bd_haddr = cpu_to_le64(mapping); |
| 614 | |
| 615 | return 0; |
| 616 | } |
| 617 | |
| 618 | static void bnxt_reuse_rx_data(struct bnxt_rx_ring_info *rxr, u16 cons, |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 619 | void *data) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 620 | { |
| 621 | u16 prod = rxr->rx_prod; |
| 622 | struct bnxt_sw_rx_bd *cons_rx_buf, *prod_rx_buf; |
| 623 | struct rx_bd *cons_bd, *prod_bd; |
| 624 | |
| 625 | prod_rx_buf = &rxr->rx_buf_ring[prod]; |
| 626 | cons_rx_buf = &rxr->rx_buf_ring[cons]; |
| 627 | |
| 628 | prod_rx_buf->data = data; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 629 | prod_rx_buf->data_ptr = cons_rx_buf->data_ptr; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 630 | |
Michael Chan | 11cd119 | 2017-02-06 16:55:33 -0500 | [diff] [blame] | 631 | prod_rx_buf->mapping = cons_rx_buf->mapping; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 632 | |
| 633 | prod_bd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)]; |
| 634 | cons_bd = &rxr->rx_desc_ring[RX_RING(cons)][RX_IDX(cons)]; |
| 635 | |
| 636 | prod_bd->rx_bd_haddr = cons_bd->rx_bd_haddr; |
| 637 | } |
| 638 | |
| 639 | static inline u16 bnxt_find_next_agg_idx(struct bnxt_rx_ring_info *rxr, u16 idx) |
| 640 | { |
| 641 | u16 next, max = rxr->rx_agg_bmap_size; |
| 642 | |
| 643 | next = find_next_zero_bit(rxr->rx_agg_bmap, max, idx); |
| 644 | if (next >= max) |
| 645 | next = find_first_zero_bit(rxr->rx_agg_bmap, max); |
| 646 | return next; |
| 647 | } |
| 648 | |
| 649 | static inline int bnxt_alloc_rx_page(struct bnxt *bp, |
| 650 | struct bnxt_rx_ring_info *rxr, |
| 651 | u16 prod, gfp_t gfp) |
| 652 | { |
| 653 | struct rx_bd *rxbd = |
| 654 | &rxr->rx_agg_desc_ring[RX_RING(prod)][RX_IDX(prod)]; |
| 655 | struct bnxt_sw_rx_agg_bd *rx_agg_buf; |
| 656 | struct pci_dev *pdev = bp->pdev; |
| 657 | struct page *page; |
| 658 | dma_addr_t mapping; |
| 659 | u16 sw_prod = rxr->rx_sw_agg_prod; |
Michael Chan | 89d0a06 | 2016-04-25 02:30:51 -0400 | [diff] [blame] | 660 | unsigned int offset = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 661 | |
Michael Chan | 89d0a06 | 2016-04-25 02:30:51 -0400 | [diff] [blame] | 662 | if (PAGE_SIZE > BNXT_RX_PAGE_SIZE) { |
| 663 | page = rxr->rx_page; |
| 664 | if (!page) { |
| 665 | page = alloc_page(gfp); |
| 666 | if (!page) |
| 667 | return -ENOMEM; |
| 668 | rxr->rx_page = page; |
| 669 | rxr->rx_page_offset = 0; |
| 670 | } |
| 671 | offset = rxr->rx_page_offset; |
| 672 | rxr->rx_page_offset += BNXT_RX_PAGE_SIZE; |
| 673 | if (rxr->rx_page_offset == PAGE_SIZE) |
| 674 | rxr->rx_page = NULL; |
| 675 | else |
| 676 | get_page(page); |
| 677 | } else { |
| 678 | page = alloc_page(gfp); |
| 679 | if (!page) |
| 680 | return -ENOMEM; |
| 681 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 682 | |
Michael Chan | 89d0a06 | 2016-04-25 02:30:51 -0400 | [diff] [blame] | 683 | mapping = dma_map_page(&pdev->dev, page, offset, BNXT_RX_PAGE_SIZE, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 684 | PCI_DMA_FROMDEVICE); |
| 685 | if (dma_mapping_error(&pdev->dev, mapping)) { |
| 686 | __free_page(page); |
| 687 | return -EIO; |
| 688 | } |
| 689 | |
| 690 | if (unlikely(test_bit(sw_prod, rxr->rx_agg_bmap))) |
| 691 | sw_prod = bnxt_find_next_agg_idx(rxr, sw_prod); |
| 692 | |
| 693 | __set_bit(sw_prod, rxr->rx_agg_bmap); |
| 694 | rx_agg_buf = &rxr->rx_agg_ring[sw_prod]; |
| 695 | rxr->rx_sw_agg_prod = NEXT_RX_AGG(sw_prod); |
| 696 | |
| 697 | rx_agg_buf->page = page; |
Michael Chan | 89d0a06 | 2016-04-25 02:30:51 -0400 | [diff] [blame] | 698 | rx_agg_buf->offset = offset; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 699 | rx_agg_buf->mapping = mapping; |
| 700 | rxbd->rx_bd_haddr = cpu_to_le64(mapping); |
| 701 | rxbd->rx_bd_opaque = sw_prod; |
| 702 | return 0; |
| 703 | } |
| 704 | |
| 705 | static void bnxt_reuse_rx_agg_bufs(struct bnxt_napi *bnapi, u16 cp_cons, |
| 706 | u32 agg_bufs) |
| 707 | { |
| 708 | struct bnxt *bp = bnapi->bp; |
| 709 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 710 | struct bnxt_rx_ring_info *rxr = bnapi->rx_ring; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 711 | u16 prod = rxr->rx_agg_prod; |
| 712 | u16 sw_prod = rxr->rx_sw_agg_prod; |
| 713 | u32 i; |
| 714 | |
| 715 | for (i = 0; i < agg_bufs; i++) { |
| 716 | u16 cons; |
| 717 | struct rx_agg_cmp *agg; |
| 718 | struct bnxt_sw_rx_agg_bd *cons_rx_buf, *prod_rx_buf; |
| 719 | struct rx_bd *prod_bd; |
| 720 | struct page *page; |
| 721 | |
| 722 | agg = (struct rx_agg_cmp *) |
| 723 | &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; |
| 724 | cons = agg->rx_agg_cmp_opaque; |
| 725 | __clear_bit(cons, rxr->rx_agg_bmap); |
| 726 | |
| 727 | if (unlikely(test_bit(sw_prod, rxr->rx_agg_bmap))) |
| 728 | sw_prod = bnxt_find_next_agg_idx(rxr, sw_prod); |
| 729 | |
| 730 | __set_bit(sw_prod, rxr->rx_agg_bmap); |
| 731 | prod_rx_buf = &rxr->rx_agg_ring[sw_prod]; |
| 732 | cons_rx_buf = &rxr->rx_agg_ring[cons]; |
| 733 | |
| 734 | /* It is possible for sw_prod to be equal to cons, so |
| 735 | * set cons_rx_buf->page to NULL first. |
| 736 | */ |
| 737 | page = cons_rx_buf->page; |
| 738 | cons_rx_buf->page = NULL; |
| 739 | prod_rx_buf->page = page; |
Michael Chan | 89d0a06 | 2016-04-25 02:30:51 -0400 | [diff] [blame] | 740 | prod_rx_buf->offset = cons_rx_buf->offset; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 741 | |
| 742 | prod_rx_buf->mapping = cons_rx_buf->mapping; |
| 743 | |
| 744 | prod_bd = &rxr->rx_agg_desc_ring[RX_RING(prod)][RX_IDX(prod)]; |
| 745 | |
| 746 | prod_bd->rx_bd_haddr = cpu_to_le64(cons_rx_buf->mapping); |
| 747 | prod_bd->rx_bd_opaque = sw_prod; |
| 748 | |
| 749 | prod = NEXT_RX_AGG(prod); |
| 750 | sw_prod = NEXT_RX_AGG(sw_prod); |
| 751 | cp_cons = NEXT_CMP(cp_cons); |
| 752 | } |
| 753 | rxr->rx_agg_prod = prod; |
| 754 | rxr->rx_sw_agg_prod = sw_prod; |
| 755 | } |
| 756 | |
| 757 | static struct sk_buff *bnxt_rx_skb(struct bnxt *bp, |
| 758 | struct bnxt_rx_ring_info *rxr, u16 cons, |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 759 | void *data, u8 *data_ptr, |
| 760 | dma_addr_t dma_addr, |
| 761 | unsigned int offset_and_len) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 762 | { |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 763 | u16 prod = rxr->rx_prod; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 764 | struct sk_buff *skb; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 765 | int err; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 766 | |
| 767 | err = bnxt_alloc_rx_data(bp, rxr, prod, GFP_ATOMIC); |
| 768 | if (unlikely(err)) { |
| 769 | bnxt_reuse_rx_data(rxr, cons, data); |
| 770 | return NULL; |
| 771 | } |
| 772 | |
| 773 | skb = build_skb(data, 0); |
| 774 | dma_unmap_single(&bp->pdev->dev, dma_addr, bp->rx_buf_use_size, |
Michael Chan | 745fc05 | 2017-02-06 16:55:34 -0500 | [diff] [blame] | 775 | bp->rx_dir); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 776 | if (!skb) { |
| 777 | kfree(data); |
| 778 | return NULL; |
| 779 | } |
| 780 | |
Michael Chan | b3dba77 | 2017-02-06 16:55:35 -0500 | [diff] [blame^] | 781 | skb_reserve(skb, bp->rx_offset); |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 782 | skb_put(skb, offset_and_len & 0xffff); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 783 | return skb; |
| 784 | } |
| 785 | |
| 786 | static struct sk_buff *bnxt_rx_pages(struct bnxt *bp, struct bnxt_napi *bnapi, |
| 787 | struct sk_buff *skb, u16 cp_cons, |
| 788 | u32 agg_bufs) |
| 789 | { |
| 790 | struct pci_dev *pdev = bp->pdev; |
| 791 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 792 | struct bnxt_rx_ring_info *rxr = bnapi->rx_ring; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 793 | u16 prod = rxr->rx_agg_prod; |
| 794 | u32 i; |
| 795 | |
| 796 | for (i = 0; i < agg_bufs; i++) { |
| 797 | u16 cons, frag_len; |
| 798 | struct rx_agg_cmp *agg; |
| 799 | struct bnxt_sw_rx_agg_bd *cons_rx_buf; |
| 800 | struct page *page; |
| 801 | dma_addr_t mapping; |
| 802 | |
| 803 | agg = (struct rx_agg_cmp *) |
| 804 | &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; |
| 805 | cons = agg->rx_agg_cmp_opaque; |
| 806 | frag_len = (le32_to_cpu(agg->rx_agg_cmp_len_flags_type) & |
| 807 | RX_AGG_CMP_LEN) >> RX_AGG_CMP_LEN_SHIFT; |
| 808 | |
| 809 | cons_rx_buf = &rxr->rx_agg_ring[cons]; |
Michael Chan | 89d0a06 | 2016-04-25 02:30:51 -0400 | [diff] [blame] | 810 | skb_fill_page_desc(skb, i, cons_rx_buf->page, |
| 811 | cons_rx_buf->offset, frag_len); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 812 | __clear_bit(cons, rxr->rx_agg_bmap); |
| 813 | |
| 814 | /* It is possible for bnxt_alloc_rx_page() to allocate |
| 815 | * a sw_prod index that equals the cons index, so we |
| 816 | * need to clear the cons entry now. |
| 817 | */ |
Michael Chan | 11cd119 | 2017-02-06 16:55:33 -0500 | [diff] [blame] | 818 | mapping = cons_rx_buf->mapping; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 819 | page = cons_rx_buf->page; |
| 820 | cons_rx_buf->page = NULL; |
| 821 | |
| 822 | if (bnxt_alloc_rx_page(bp, rxr, prod, GFP_ATOMIC) != 0) { |
| 823 | struct skb_shared_info *shinfo; |
| 824 | unsigned int nr_frags; |
| 825 | |
| 826 | shinfo = skb_shinfo(skb); |
| 827 | nr_frags = --shinfo->nr_frags; |
| 828 | __skb_frag_set_page(&shinfo->frags[nr_frags], NULL); |
| 829 | |
| 830 | dev_kfree_skb(skb); |
| 831 | |
| 832 | cons_rx_buf->page = page; |
| 833 | |
| 834 | /* Update prod since possibly some pages have been |
| 835 | * allocated already. |
| 836 | */ |
| 837 | rxr->rx_agg_prod = prod; |
| 838 | bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs - i); |
| 839 | return NULL; |
| 840 | } |
| 841 | |
Michael Chan | 2839f28 | 2016-04-25 02:30:50 -0400 | [diff] [blame] | 842 | dma_unmap_page(&pdev->dev, mapping, BNXT_RX_PAGE_SIZE, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 843 | PCI_DMA_FROMDEVICE); |
| 844 | |
| 845 | skb->data_len += frag_len; |
| 846 | skb->len += frag_len; |
| 847 | skb->truesize += PAGE_SIZE; |
| 848 | |
| 849 | prod = NEXT_RX_AGG(prod); |
| 850 | cp_cons = NEXT_CMP(cp_cons); |
| 851 | } |
| 852 | rxr->rx_agg_prod = prod; |
| 853 | return skb; |
| 854 | } |
| 855 | |
| 856 | static int bnxt_agg_bufs_valid(struct bnxt *bp, struct bnxt_cp_ring_info *cpr, |
| 857 | u8 agg_bufs, u32 *raw_cons) |
| 858 | { |
| 859 | u16 last; |
| 860 | struct rx_agg_cmp *agg; |
| 861 | |
| 862 | *raw_cons = ADV_RAW_CMP(*raw_cons, agg_bufs); |
| 863 | last = RING_CMP(*raw_cons); |
| 864 | agg = (struct rx_agg_cmp *) |
| 865 | &cpr->cp_desc_ring[CP_RING(last)][CP_IDX(last)]; |
| 866 | return RX_AGG_CMP_VALID(agg, *raw_cons); |
| 867 | } |
| 868 | |
| 869 | static inline struct sk_buff *bnxt_copy_skb(struct bnxt_napi *bnapi, u8 *data, |
| 870 | unsigned int len, |
| 871 | dma_addr_t mapping) |
| 872 | { |
| 873 | struct bnxt *bp = bnapi->bp; |
| 874 | struct pci_dev *pdev = bp->pdev; |
| 875 | struct sk_buff *skb; |
| 876 | |
| 877 | skb = napi_alloc_skb(&bnapi->napi, len); |
| 878 | if (!skb) |
| 879 | return NULL; |
| 880 | |
Michael Chan | 745fc05 | 2017-02-06 16:55:34 -0500 | [diff] [blame] | 881 | dma_sync_single_for_cpu(&pdev->dev, mapping, bp->rx_copy_thresh, |
| 882 | bp->rx_dir); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 883 | |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 884 | memcpy(skb->data - NET_IP_ALIGN, data - NET_IP_ALIGN, |
| 885 | len + NET_IP_ALIGN); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 886 | |
Michael Chan | 745fc05 | 2017-02-06 16:55:34 -0500 | [diff] [blame] | 887 | dma_sync_single_for_device(&pdev->dev, mapping, bp->rx_copy_thresh, |
| 888 | bp->rx_dir); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 889 | |
| 890 | skb_put(skb, len); |
| 891 | return skb; |
| 892 | } |
| 893 | |
Michael Chan | fa7e281 | 2016-05-10 19:18:00 -0400 | [diff] [blame] | 894 | static int bnxt_discard_rx(struct bnxt *bp, struct bnxt_napi *bnapi, |
| 895 | u32 *raw_cons, void *cmp) |
| 896 | { |
| 897 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 898 | struct rx_cmp *rxcmp = cmp; |
| 899 | u32 tmp_raw_cons = *raw_cons; |
| 900 | u8 cmp_type, agg_bufs = 0; |
| 901 | |
| 902 | cmp_type = RX_CMP_TYPE(rxcmp); |
| 903 | |
| 904 | if (cmp_type == CMP_TYPE_RX_L2_CMP) { |
| 905 | agg_bufs = (le32_to_cpu(rxcmp->rx_cmp_misc_v1) & |
| 906 | RX_CMP_AGG_BUFS) >> |
| 907 | RX_CMP_AGG_BUFS_SHIFT; |
| 908 | } else if (cmp_type == CMP_TYPE_RX_L2_TPA_END_CMP) { |
| 909 | struct rx_tpa_end_cmp *tpa_end = cmp; |
| 910 | |
| 911 | agg_bufs = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) & |
| 912 | RX_TPA_END_CMP_AGG_BUFS) >> |
| 913 | RX_TPA_END_CMP_AGG_BUFS_SHIFT; |
| 914 | } |
| 915 | |
| 916 | if (agg_bufs) { |
| 917 | if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, &tmp_raw_cons)) |
| 918 | return -EBUSY; |
| 919 | } |
| 920 | *raw_cons = tmp_raw_cons; |
| 921 | return 0; |
| 922 | } |
| 923 | |
| 924 | static void bnxt_sched_reset(struct bnxt *bp, struct bnxt_rx_ring_info *rxr) |
| 925 | { |
| 926 | if (!rxr->bnapi->in_reset) { |
| 927 | rxr->bnapi->in_reset = true; |
| 928 | set_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event); |
| 929 | schedule_work(&bp->sp_task); |
| 930 | } |
| 931 | rxr->rx_next_cons = 0xffff; |
| 932 | } |
| 933 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 934 | static void bnxt_tpa_start(struct bnxt *bp, struct bnxt_rx_ring_info *rxr, |
| 935 | struct rx_tpa_start_cmp *tpa_start, |
| 936 | struct rx_tpa_start_cmp_ext *tpa_start1) |
| 937 | { |
| 938 | u8 agg_id = TPA_START_AGG_ID(tpa_start); |
| 939 | u16 cons, prod; |
| 940 | struct bnxt_tpa_info *tpa_info; |
| 941 | struct bnxt_sw_rx_bd *cons_rx_buf, *prod_rx_buf; |
| 942 | struct rx_bd *prod_bd; |
| 943 | dma_addr_t mapping; |
| 944 | |
| 945 | cons = tpa_start->rx_tpa_start_cmp_opaque; |
| 946 | prod = rxr->rx_prod; |
| 947 | cons_rx_buf = &rxr->rx_buf_ring[cons]; |
| 948 | prod_rx_buf = &rxr->rx_buf_ring[prod]; |
| 949 | tpa_info = &rxr->rx_tpa[agg_id]; |
| 950 | |
Michael Chan | fa7e281 | 2016-05-10 19:18:00 -0400 | [diff] [blame] | 951 | if (unlikely(cons != rxr->rx_next_cons)) { |
| 952 | bnxt_sched_reset(bp, rxr); |
| 953 | return; |
| 954 | } |
| 955 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 956 | prod_rx_buf->data = tpa_info->data; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 957 | prod_rx_buf->data_ptr = tpa_info->data_ptr; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 958 | |
| 959 | mapping = tpa_info->mapping; |
Michael Chan | 11cd119 | 2017-02-06 16:55:33 -0500 | [diff] [blame] | 960 | prod_rx_buf->mapping = mapping; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 961 | |
| 962 | prod_bd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)]; |
| 963 | |
| 964 | prod_bd->rx_bd_haddr = cpu_to_le64(mapping); |
| 965 | |
| 966 | tpa_info->data = cons_rx_buf->data; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 967 | tpa_info->data_ptr = cons_rx_buf->data_ptr; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 968 | cons_rx_buf->data = NULL; |
Michael Chan | 11cd119 | 2017-02-06 16:55:33 -0500 | [diff] [blame] | 969 | tpa_info->mapping = cons_rx_buf->mapping; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 970 | |
| 971 | tpa_info->len = |
| 972 | le32_to_cpu(tpa_start->rx_tpa_start_cmp_len_flags_type) >> |
| 973 | RX_TPA_START_CMP_LEN_SHIFT; |
| 974 | if (likely(TPA_START_HASH_VALID(tpa_start))) { |
| 975 | u32 hash_type = TPA_START_HASH_TYPE(tpa_start); |
| 976 | |
| 977 | tpa_info->hash_type = PKT_HASH_TYPE_L4; |
| 978 | tpa_info->gso_type = SKB_GSO_TCPV4; |
| 979 | /* RSS profiles 1 and 3 with extract code 0 for inner 4-tuple */ |
| 980 | if (hash_type == 3) |
| 981 | tpa_info->gso_type = SKB_GSO_TCPV6; |
| 982 | tpa_info->rss_hash = |
| 983 | le32_to_cpu(tpa_start->rx_tpa_start_cmp_rss_hash); |
| 984 | } else { |
| 985 | tpa_info->hash_type = PKT_HASH_TYPE_NONE; |
| 986 | tpa_info->gso_type = 0; |
| 987 | if (netif_msg_rx_err(bp)) |
| 988 | netdev_warn(bp->dev, "TPA packet without valid hash\n"); |
| 989 | } |
| 990 | tpa_info->flags2 = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_flags2); |
| 991 | tpa_info->metadata = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_metadata); |
Michael Chan | 94758f8 | 2016-06-13 02:25:35 -0400 | [diff] [blame] | 992 | tpa_info->hdr_info = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_hdr_info); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 993 | |
| 994 | rxr->rx_prod = NEXT_RX(prod); |
| 995 | cons = NEXT_RX(cons); |
Michael Chan | 376a5b8 | 2016-05-10 19:17:59 -0400 | [diff] [blame] | 996 | rxr->rx_next_cons = NEXT_RX(cons); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 997 | cons_rx_buf = &rxr->rx_buf_ring[cons]; |
| 998 | |
| 999 | bnxt_reuse_rx_data(rxr, cons, cons_rx_buf->data); |
| 1000 | rxr->rx_prod = NEXT_RX(rxr->rx_prod); |
| 1001 | cons_rx_buf->data = NULL; |
| 1002 | } |
| 1003 | |
| 1004 | static void bnxt_abort_tpa(struct bnxt *bp, struct bnxt_napi *bnapi, |
| 1005 | u16 cp_cons, u32 agg_bufs) |
| 1006 | { |
| 1007 | if (agg_bufs) |
| 1008 | bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs); |
| 1009 | } |
| 1010 | |
Michael Chan | 94758f8 | 2016-06-13 02:25:35 -0400 | [diff] [blame] | 1011 | static struct sk_buff *bnxt_gro_func_5731x(struct bnxt_tpa_info *tpa_info, |
| 1012 | int payload_off, int tcp_ts, |
| 1013 | struct sk_buff *skb) |
| 1014 | { |
| 1015 | #ifdef CONFIG_INET |
| 1016 | struct tcphdr *th; |
| 1017 | int len, nw_off; |
| 1018 | u16 outer_ip_off, inner_ip_off, inner_mac_off; |
| 1019 | u32 hdr_info = tpa_info->hdr_info; |
| 1020 | bool loopback = false; |
| 1021 | |
| 1022 | inner_ip_off = BNXT_TPA_INNER_L3_OFF(hdr_info); |
| 1023 | inner_mac_off = BNXT_TPA_INNER_L2_OFF(hdr_info); |
| 1024 | outer_ip_off = BNXT_TPA_OUTER_L3_OFF(hdr_info); |
| 1025 | |
| 1026 | /* If the packet is an internal loopback packet, the offsets will |
| 1027 | * have an extra 4 bytes. |
| 1028 | */ |
| 1029 | if (inner_mac_off == 4) { |
| 1030 | loopback = true; |
| 1031 | } else if (inner_mac_off > 4) { |
| 1032 | __be16 proto = *((__be16 *)(skb->data + inner_ip_off - |
| 1033 | ETH_HLEN - 2)); |
| 1034 | |
| 1035 | /* We only support inner iPv4/ipv6. If we don't see the |
| 1036 | * correct protocol ID, it must be a loopback packet where |
| 1037 | * the offsets are off by 4. |
| 1038 | */ |
Dan Carpenter | 09a7636 | 2016-07-07 11:23:09 +0300 | [diff] [blame] | 1039 | if (proto != htons(ETH_P_IP) && proto != htons(ETH_P_IPV6)) |
Michael Chan | 94758f8 | 2016-06-13 02:25:35 -0400 | [diff] [blame] | 1040 | loopback = true; |
| 1041 | } |
| 1042 | if (loopback) { |
| 1043 | /* internal loopback packet, subtract all offsets by 4 */ |
| 1044 | inner_ip_off -= 4; |
| 1045 | inner_mac_off -= 4; |
| 1046 | outer_ip_off -= 4; |
| 1047 | } |
| 1048 | |
| 1049 | nw_off = inner_ip_off - ETH_HLEN; |
| 1050 | skb_set_network_header(skb, nw_off); |
| 1051 | if (tpa_info->flags2 & RX_TPA_START_CMP_FLAGS2_IP_TYPE) { |
| 1052 | struct ipv6hdr *iph = ipv6_hdr(skb); |
| 1053 | |
| 1054 | skb_set_transport_header(skb, nw_off + sizeof(struct ipv6hdr)); |
| 1055 | len = skb->len - skb_transport_offset(skb); |
| 1056 | th = tcp_hdr(skb); |
| 1057 | th->check = ~tcp_v6_check(len, &iph->saddr, &iph->daddr, 0); |
| 1058 | } else { |
| 1059 | struct iphdr *iph = ip_hdr(skb); |
| 1060 | |
| 1061 | skb_set_transport_header(skb, nw_off + sizeof(struct iphdr)); |
| 1062 | len = skb->len - skb_transport_offset(skb); |
| 1063 | th = tcp_hdr(skb); |
| 1064 | th->check = ~tcp_v4_check(len, iph->saddr, iph->daddr, 0); |
| 1065 | } |
| 1066 | |
| 1067 | if (inner_mac_off) { /* tunnel */ |
| 1068 | struct udphdr *uh = NULL; |
| 1069 | __be16 proto = *((__be16 *)(skb->data + outer_ip_off - |
| 1070 | ETH_HLEN - 2)); |
| 1071 | |
| 1072 | if (proto == htons(ETH_P_IP)) { |
| 1073 | struct iphdr *iph = (struct iphdr *)skb->data; |
| 1074 | |
| 1075 | if (iph->protocol == IPPROTO_UDP) |
| 1076 | uh = (struct udphdr *)(iph + 1); |
| 1077 | } else { |
| 1078 | struct ipv6hdr *iph = (struct ipv6hdr *)skb->data; |
| 1079 | |
| 1080 | if (iph->nexthdr == IPPROTO_UDP) |
| 1081 | uh = (struct udphdr *)(iph + 1); |
| 1082 | } |
| 1083 | if (uh) { |
| 1084 | if (uh->check) |
| 1085 | skb_shinfo(skb)->gso_type |= |
| 1086 | SKB_GSO_UDP_TUNNEL_CSUM; |
| 1087 | else |
| 1088 | skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL; |
| 1089 | } |
| 1090 | } |
| 1091 | #endif |
| 1092 | return skb; |
| 1093 | } |
| 1094 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1095 | #define BNXT_IPV4_HDR_SIZE (sizeof(struct iphdr) + sizeof(struct tcphdr)) |
| 1096 | #define BNXT_IPV6_HDR_SIZE (sizeof(struct ipv6hdr) + sizeof(struct tcphdr)) |
| 1097 | |
Michael Chan | 309369c | 2016-06-13 02:25:34 -0400 | [diff] [blame] | 1098 | static struct sk_buff *bnxt_gro_func_5730x(struct bnxt_tpa_info *tpa_info, |
| 1099 | int payload_off, int tcp_ts, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1100 | struct sk_buff *skb) |
| 1101 | { |
Michael Chan | d1611c3 | 2015-10-25 22:27:57 -0400 | [diff] [blame] | 1102 | #ifdef CONFIG_INET |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1103 | struct tcphdr *th; |
Michael Chan | 719ca81 | 2017-01-17 22:07:19 -0500 | [diff] [blame] | 1104 | int len, nw_off, tcp_opt_len = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1105 | |
Michael Chan | 309369c | 2016-06-13 02:25:34 -0400 | [diff] [blame] | 1106 | if (tcp_ts) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1107 | tcp_opt_len = 12; |
| 1108 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1109 | if (tpa_info->gso_type == SKB_GSO_TCPV4) { |
| 1110 | struct iphdr *iph; |
| 1111 | |
| 1112 | nw_off = payload_off - BNXT_IPV4_HDR_SIZE - tcp_opt_len - |
| 1113 | ETH_HLEN; |
| 1114 | skb_set_network_header(skb, nw_off); |
| 1115 | iph = ip_hdr(skb); |
| 1116 | skb_set_transport_header(skb, nw_off + sizeof(struct iphdr)); |
| 1117 | len = skb->len - skb_transport_offset(skb); |
| 1118 | th = tcp_hdr(skb); |
| 1119 | th->check = ~tcp_v4_check(len, iph->saddr, iph->daddr, 0); |
| 1120 | } else if (tpa_info->gso_type == SKB_GSO_TCPV6) { |
| 1121 | struct ipv6hdr *iph; |
| 1122 | |
| 1123 | nw_off = payload_off - BNXT_IPV6_HDR_SIZE - tcp_opt_len - |
| 1124 | ETH_HLEN; |
| 1125 | skb_set_network_header(skb, nw_off); |
| 1126 | iph = ipv6_hdr(skb); |
| 1127 | skb_set_transport_header(skb, nw_off + sizeof(struct ipv6hdr)); |
| 1128 | len = skb->len - skb_transport_offset(skb); |
| 1129 | th = tcp_hdr(skb); |
| 1130 | th->check = ~tcp_v6_check(len, &iph->saddr, &iph->daddr, 0); |
| 1131 | } else { |
| 1132 | dev_kfree_skb_any(skb); |
| 1133 | return NULL; |
| 1134 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1135 | |
| 1136 | if (nw_off) { /* tunnel */ |
| 1137 | struct udphdr *uh = NULL; |
| 1138 | |
| 1139 | if (skb->protocol == htons(ETH_P_IP)) { |
| 1140 | struct iphdr *iph = (struct iphdr *)skb->data; |
| 1141 | |
| 1142 | if (iph->protocol == IPPROTO_UDP) |
| 1143 | uh = (struct udphdr *)(iph + 1); |
| 1144 | } else { |
| 1145 | struct ipv6hdr *iph = (struct ipv6hdr *)skb->data; |
| 1146 | |
| 1147 | if (iph->nexthdr == IPPROTO_UDP) |
| 1148 | uh = (struct udphdr *)(iph + 1); |
| 1149 | } |
| 1150 | if (uh) { |
| 1151 | if (uh->check) |
| 1152 | skb_shinfo(skb)->gso_type |= |
| 1153 | SKB_GSO_UDP_TUNNEL_CSUM; |
| 1154 | else |
| 1155 | skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL; |
| 1156 | } |
| 1157 | } |
| 1158 | #endif |
| 1159 | return skb; |
| 1160 | } |
| 1161 | |
Michael Chan | 309369c | 2016-06-13 02:25:34 -0400 | [diff] [blame] | 1162 | static inline struct sk_buff *bnxt_gro_skb(struct bnxt *bp, |
| 1163 | struct bnxt_tpa_info *tpa_info, |
| 1164 | struct rx_tpa_end_cmp *tpa_end, |
| 1165 | struct rx_tpa_end_cmp_ext *tpa_end1, |
| 1166 | struct sk_buff *skb) |
| 1167 | { |
| 1168 | #ifdef CONFIG_INET |
| 1169 | int payload_off; |
| 1170 | u16 segs; |
| 1171 | |
| 1172 | segs = TPA_END_TPA_SEGS(tpa_end); |
| 1173 | if (segs == 1) |
| 1174 | return skb; |
| 1175 | |
| 1176 | NAPI_GRO_CB(skb)->count = segs; |
| 1177 | skb_shinfo(skb)->gso_size = |
| 1178 | le32_to_cpu(tpa_end1->rx_tpa_end_cmp_seg_len); |
| 1179 | skb_shinfo(skb)->gso_type = tpa_info->gso_type; |
| 1180 | payload_off = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) & |
| 1181 | RX_TPA_END_CMP_PAYLOAD_OFFSET) >> |
| 1182 | RX_TPA_END_CMP_PAYLOAD_OFFSET_SHIFT; |
| 1183 | skb = bp->gro_func(tpa_info, payload_off, TPA_END_GRO_TS(tpa_end), skb); |
Michael Chan | 5910906 | 2016-12-29 12:13:35 -0500 | [diff] [blame] | 1184 | if (likely(skb)) |
| 1185 | tcp_gro_complete(skb); |
Michael Chan | 309369c | 2016-06-13 02:25:34 -0400 | [diff] [blame] | 1186 | #endif |
| 1187 | return skb; |
| 1188 | } |
| 1189 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1190 | static inline struct sk_buff *bnxt_tpa_end(struct bnxt *bp, |
| 1191 | struct bnxt_napi *bnapi, |
| 1192 | u32 *raw_cons, |
| 1193 | struct rx_tpa_end_cmp *tpa_end, |
| 1194 | struct rx_tpa_end_cmp_ext *tpa_end1, |
| 1195 | bool *agg_event) |
| 1196 | { |
| 1197 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 1198 | struct bnxt_rx_ring_info *rxr = bnapi->rx_ring; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1199 | u8 agg_id = TPA_END_AGG_ID(tpa_end); |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1200 | u8 *data_ptr, agg_bufs; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1201 | u16 cp_cons = RING_CMP(*raw_cons); |
| 1202 | unsigned int len; |
| 1203 | struct bnxt_tpa_info *tpa_info; |
| 1204 | dma_addr_t mapping; |
| 1205 | struct sk_buff *skb; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1206 | void *data; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1207 | |
Michael Chan | fa7e281 | 2016-05-10 19:18:00 -0400 | [diff] [blame] | 1208 | if (unlikely(bnapi->in_reset)) { |
| 1209 | int rc = bnxt_discard_rx(bp, bnapi, raw_cons, tpa_end); |
| 1210 | |
| 1211 | if (rc < 0) |
| 1212 | return ERR_PTR(-EBUSY); |
| 1213 | return NULL; |
| 1214 | } |
| 1215 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1216 | tpa_info = &rxr->rx_tpa[agg_id]; |
| 1217 | data = tpa_info->data; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1218 | data_ptr = tpa_info->data_ptr; |
| 1219 | prefetch(data_ptr); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1220 | len = tpa_info->len; |
| 1221 | mapping = tpa_info->mapping; |
| 1222 | |
| 1223 | agg_bufs = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) & |
| 1224 | RX_TPA_END_CMP_AGG_BUFS) >> RX_TPA_END_CMP_AGG_BUFS_SHIFT; |
| 1225 | |
| 1226 | if (agg_bufs) { |
| 1227 | if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, raw_cons)) |
| 1228 | return ERR_PTR(-EBUSY); |
| 1229 | |
| 1230 | *agg_event = true; |
| 1231 | cp_cons = NEXT_CMP(cp_cons); |
| 1232 | } |
| 1233 | |
| 1234 | if (unlikely(agg_bufs > MAX_SKB_FRAGS)) { |
| 1235 | bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs); |
| 1236 | netdev_warn(bp->dev, "TPA frags %d exceeded MAX_SKB_FRAGS %d\n", |
| 1237 | agg_bufs, (int)MAX_SKB_FRAGS); |
| 1238 | return NULL; |
| 1239 | } |
| 1240 | |
| 1241 | if (len <= bp->rx_copy_thresh) { |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1242 | skb = bnxt_copy_skb(bnapi, data_ptr, len, mapping); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1243 | if (!skb) { |
| 1244 | bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs); |
| 1245 | return NULL; |
| 1246 | } |
| 1247 | } else { |
| 1248 | u8 *new_data; |
| 1249 | dma_addr_t new_mapping; |
| 1250 | |
| 1251 | new_data = __bnxt_alloc_rx_data(bp, &new_mapping, GFP_ATOMIC); |
| 1252 | if (!new_data) { |
| 1253 | bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs); |
| 1254 | return NULL; |
| 1255 | } |
| 1256 | |
| 1257 | tpa_info->data = new_data; |
Michael Chan | b3dba77 | 2017-02-06 16:55:35 -0500 | [diff] [blame^] | 1258 | tpa_info->data_ptr = new_data + bp->rx_offset; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1259 | tpa_info->mapping = new_mapping; |
| 1260 | |
| 1261 | skb = build_skb(data, 0); |
| 1262 | dma_unmap_single(&bp->pdev->dev, mapping, bp->rx_buf_use_size, |
Michael Chan | 745fc05 | 2017-02-06 16:55:34 -0500 | [diff] [blame] | 1263 | bp->rx_dir); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1264 | |
| 1265 | if (!skb) { |
| 1266 | kfree(data); |
| 1267 | bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs); |
| 1268 | return NULL; |
| 1269 | } |
Michael Chan | b3dba77 | 2017-02-06 16:55:35 -0500 | [diff] [blame^] | 1270 | skb_reserve(skb, bp->rx_offset); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1271 | skb_put(skb, len); |
| 1272 | } |
| 1273 | |
| 1274 | if (agg_bufs) { |
| 1275 | skb = bnxt_rx_pages(bp, bnapi, skb, cp_cons, agg_bufs); |
| 1276 | if (!skb) { |
| 1277 | /* Page reuse already handled by bnxt_rx_pages(). */ |
| 1278 | return NULL; |
| 1279 | } |
| 1280 | } |
| 1281 | skb->protocol = eth_type_trans(skb, bp->dev); |
| 1282 | |
| 1283 | if (tpa_info->hash_type != PKT_HASH_TYPE_NONE) |
| 1284 | skb_set_hash(skb, tpa_info->rss_hash, tpa_info->hash_type); |
| 1285 | |
Michael Chan | 8852ddb | 2016-06-06 02:37:16 -0400 | [diff] [blame] | 1286 | if ((tpa_info->flags2 & RX_CMP_FLAGS2_META_FORMAT_VLAN) && |
| 1287 | (skb->dev->features & NETIF_F_HW_VLAN_CTAG_RX)) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1288 | u16 vlan_proto = tpa_info->metadata >> |
| 1289 | RX_CMP_FLAGS2_METADATA_TPID_SFT; |
Michael Chan | 8852ddb | 2016-06-06 02:37:16 -0400 | [diff] [blame] | 1290 | u16 vtag = tpa_info->metadata & RX_CMP_FLAGS2_METADATA_VID_MASK; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1291 | |
Michael Chan | 8852ddb | 2016-06-06 02:37:16 -0400 | [diff] [blame] | 1292 | __vlan_hwaccel_put_tag(skb, htons(vlan_proto), vtag); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1293 | } |
| 1294 | |
| 1295 | skb_checksum_none_assert(skb); |
| 1296 | if (likely(tpa_info->flags2 & RX_TPA_START_CMP_FLAGS2_L4_CS_CALC)) { |
| 1297 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 1298 | skb->csum_level = |
| 1299 | (tpa_info->flags2 & RX_CMP_FLAGS2_T_L4_CS_CALC) >> 3; |
| 1300 | } |
| 1301 | |
| 1302 | if (TPA_END_GRO(tpa_end)) |
Michael Chan | 309369c | 2016-06-13 02:25:34 -0400 | [diff] [blame] | 1303 | skb = bnxt_gro_skb(bp, tpa_info, tpa_end, tpa_end1, skb); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1304 | |
| 1305 | return skb; |
| 1306 | } |
| 1307 | |
| 1308 | /* returns the following: |
| 1309 | * 1 - 1 packet successfully received |
| 1310 | * 0 - successful TPA_START, packet not completed yet |
| 1311 | * -EBUSY - completion ring does not have all the agg buffers yet |
| 1312 | * -ENOMEM - packet aborted due to out of memory |
| 1313 | * -EIO - packet aborted due to hw error indicated in BD |
| 1314 | */ |
| 1315 | static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_napi *bnapi, u32 *raw_cons, |
| 1316 | bool *agg_event) |
| 1317 | { |
| 1318 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 1319 | struct bnxt_rx_ring_info *rxr = bnapi->rx_ring; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1320 | struct net_device *dev = bp->dev; |
| 1321 | struct rx_cmp *rxcmp; |
| 1322 | struct rx_cmp_ext *rxcmp1; |
| 1323 | u32 tmp_raw_cons = *raw_cons; |
| 1324 | u16 cons, prod, cp_cons = RING_CMP(tmp_raw_cons); |
| 1325 | struct bnxt_sw_rx_bd *rx_buf; |
| 1326 | unsigned int len; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1327 | u8 *data_ptr, agg_bufs, cmp_type; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1328 | dma_addr_t dma_addr; |
| 1329 | struct sk_buff *skb; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1330 | void *data; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1331 | int rc = 0; |
| 1332 | |
| 1333 | rxcmp = (struct rx_cmp *) |
| 1334 | &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; |
| 1335 | |
| 1336 | tmp_raw_cons = NEXT_RAW_CMP(tmp_raw_cons); |
| 1337 | cp_cons = RING_CMP(tmp_raw_cons); |
| 1338 | rxcmp1 = (struct rx_cmp_ext *) |
| 1339 | &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; |
| 1340 | |
| 1341 | if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons)) |
| 1342 | return -EBUSY; |
| 1343 | |
| 1344 | cmp_type = RX_CMP_TYPE(rxcmp); |
| 1345 | |
| 1346 | prod = rxr->rx_prod; |
| 1347 | |
| 1348 | if (cmp_type == CMP_TYPE_RX_L2_TPA_START_CMP) { |
| 1349 | bnxt_tpa_start(bp, rxr, (struct rx_tpa_start_cmp *)rxcmp, |
| 1350 | (struct rx_tpa_start_cmp_ext *)rxcmp1); |
| 1351 | |
| 1352 | goto next_rx_no_prod; |
| 1353 | |
| 1354 | } else if (cmp_type == CMP_TYPE_RX_L2_TPA_END_CMP) { |
| 1355 | skb = bnxt_tpa_end(bp, bnapi, &tmp_raw_cons, |
| 1356 | (struct rx_tpa_end_cmp *)rxcmp, |
| 1357 | (struct rx_tpa_end_cmp_ext *)rxcmp1, |
| 1358 | agg_event); |
| 1359 | |
| 1360 | if (unlikely(IS_ERR(skb))) |
| 1361 | return -EBUSY; |
| 1362 | |
| 1363 | rc = -ENOMEM; |
| 1364 | if (likely(skb)) { |
| 1365 | skb_record_rx_queue(skb, bnapi->index); |
Michael Chan | b356a2e | 2016-12-29 12:13:31 -0500 | [diff] [blame] | 1366 | napi_gro_receive(&bnapi->napi, skb); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1367 | rc = 1; |
| 1368 | } |
| 1369 | goto next_rx_no_prod; |
| 1370 | } |
| 1371 | |
| 1372 | cons = rxcmp->rx_cmp_opaque; |
| 1373 | rx_buf = &rxr->rx_buf_ring[cons]; |
| 1374 | data = rx_buf->data; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1375 | data_ptr = rx_buf->data_ptr; |
Michael Chan | fa7e281 | 2016-05-10 19:18:00 -0400 | [diff] [blame] | 1376 | if (unlikely(cons != rxr->rx_next_cons)) { |
| 1377 | int rc1 = bnxt_discard_rx(bp, bnapi, raw_cons, rxcmp); |
| 1378 | |
| 1379 | bnxt_sched_reset(bp, rxr); |
| 1380 | return rc1; |
| 1381 | } |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1382 | prefetch(data_ptr); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1383 | |
| 1384 | agg_bufs = (le32_to_cpu(rxcmp->rx_cmp_misc_v1) & RX_CMP_AGG_BUFS) >> |
| 1385 | RX_CMP_AGG_BUFS_SHIFT; |
| 1386 | |
| 1387 | if (agg_bufs) { |
| 1388 | if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, &tmp_raw_cons)) |
| 1389 | return -EBUSY; |
| 1390 | |
| 1391 | cp_cons = NEXT_CMP(cp_cons); |
| 1392 | *agg_event = true; |
| 1393 | } |
| 1394 | |
| 1395 | rx_buf->data = NULL; |
| 1396 | if (rxcmp1->rx_cmp_cfa_code_errors_v2 & RX_CMP_L2_ERRORS) { |
| 1397 | bnxt_reuse_rx_data(rxr, cons, data); |
| 1398 | if (agg_bufs) |
| 1399 | bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs); |
| 1400 | |
| 1401 | rc = -EIO; |
| 1402 | goto next_rx; |
| 1403 | } |
| 1404 | |
| 1405 | len = le32_to_cpu(rxcmp->rx_cmp_len_flags_type) >> RX_CMP_LEN_SHIFT; |
Michael Chan | 11cd119 | 2017-02-06 16:55:33 -0500 | [diff] [blame] | 1406 | dma_addr = rx_buf->mapping; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1407 | |
| 1408 | if (len <= bp->rx_copy_thresh) { |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1409 | skb = bnxt_copy_skb(bnapi, data_ptr, len, dma_addr); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1410 | bnxt_reuse_rx_data(rxr, cons, data); |
| 1411 | if (!skb) { |
| 1412 | rc = -ENOMEM; |
| 1413 | goto next_rx; |
| 1414 | } |
| 1415 | } else { |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1416 | skb = bp->rx_skb_func(bp, rxr, cons, data, data_ptr, dma_addr, |
| 1417 | len); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1418 | if (!skb) { |
| 1419 | rc = -ENOMEM; |
| 1420 | goto next_rx; |
| 1421 | } |
| 1422 | } |
| 1423 | |
| 1424 | if (agg_bufs) { |
| 1425 | skb = bnxt_rx_pages(bp, bnapi, skb, cp_cons, agg_bufs); |
| 1426 | if (!skb) { |
| 1427 | rc = -ENOMEM; |
| 1428 | goto next_rx; |
| 1429 | } |
| 1430 | } |
| 1431 | |
| 1432 | if (RX_CMP_HASH_VALID(rxcmp)) { |
| 1433 | u32 hash_type = RX_CMP_HASH_TYPE(rxcmp); |
| 1434 | enum pkt_hash_types type = PKT_HASH_TYPE_L4; |
| 1435 | |
| 1436 | /* RSS profiles 1 and 3 with extract code 0 for inner 4-tuple */ |
| 1437 | if (hash_type != 1 && hash_type != 3) |
| 1438 | type = PKT_HASH_TYPE_L3; |
| 1439 | skb_set_hash(skb, le32_to_cpu(rxcmp->rx_cmp_rss_hash), type); |
| 1440 | } |
| 1441 | |
| 1442 | skb->protocol = eth_type_trans(skb, dev); |
| 1443 | |
Michael Chan | 8852ddb | 2016-06-06 02:37:16 -0400 | [diff] [blame] | 1444 | if ((rxcmp1->rx_cmp_flags2 & |
| 1445 | cpu_to_le32(RX_CMP_FLAGS2_META_FORMAT_VLAN)) && |
| 1446 | (skb->dev->features & NETIF_F_HW_VLAN_CTAG_RX)) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1447 | u32 meta_data = le32_to_cpu(rxcmp1->rx_cmp_meta_data); |
Michael Chan | 8852ddb | 2016-06-06 02:37:16 -0400 | [diff] [blame] | 1448 | u16 vtag = meta_data & RX_CMP_FLAGS2_METADATA_VID_MASK; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1449 | u16 vlan_proto = meta_data >> RX_CMP_FLAGS2_METADATA_TPID_SFT; |
| 1450 | |
Michael Chan | 8852ddb | 2016-06-06 02:37:16 -0400 | [diff] [blame] | 1451 | __vlan_hwaccel_put_tag(skb, htons(vlan_proto), vtag); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1452 | } |
| 1453 | |
| 1454 | skb_checksum_none_assert(skb); |
| 1455 | if (RX_CMP_L4_CS_OK(rxcmp1)) { |
| 1456 | if (dev->features & NETIF_F_RXCSUM) { |
| 1457 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 1458 | skb->csum_level = RX_CMP_ENCAP(rxcmp1); |
| 1459 | } |
| 1460 | } else { |
Satish Baddipadige | 665e350 | 2015-12-27 18:19:21 -0500 | [diff] [blame] | 1461 | if (rxcmp1->rx_cmp_cfa_code_errors_v2 & RX_CMP_L4_CS_ERR_BITS) { |
| 1462 | if (dev->features & NETIF_F_RXCSUM) |
| 1463 | cpr->rx_l4_csum_errors++; |
| 1464 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | skb_record_rx_queue(skb, bnapi->index); |
Michael Chan | b356a2e | 2016-12-29 12:13:31 -0500 | [diff] [blame] | 1468 | napi_gro_receive(&bnapi->napi, skb); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1469 | rc = 1; |
| 1470 | |
| 1471 | next_rx: |
| 1472 | rxr->rx_prod = NEXT_RX(prod); |
Michael Chan | 376a5b8 | 2016-05-10 19:17:59 -0400 | [diff] [blame] | 1473 | rxr->rx_next_cons = NEXT_RX(cons); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1474 | |
| 1475 | next_rx_no_prod: |
| 1476 | *raw_cons = tmp_raw_cons; |
| 1477 | |
| 1478 | return rc; |
| 1479 | } |
| 1480 | |
Michael Chan | 4bb13ab | 2016-04-05 14:09:01 -0400 | [diff] [blame] | 1481 | #define BNXT_GET_EVENT_PORT(data) \ |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 1482 | ((data) & \ |
| 1483 | ASYNC_EVENT_CMPL_PORT_CONN_NOT_ALLOWED_EVENT_DATA1_PORT_ID_MASK) |
Michael Chan | 4bb13ab | 2016-04-05 14:09:01 -0400 | [diff] [blame] | 1484 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1485 | static int bnxt_async_event_process(struct bnxt *bp, |
| 1486 | struct hwrm_async_event_cmpl *cmpl) |
| 1487 | { |
| 1488 | u16 event_id = le16_to_cpu(cmpl->event_id); |
| 1489 | |
| 1490 | /* TODO CHIMP_FW: Define event id's for link change, error etc */ |
| 1491 | switch (event_id) { |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 1492 | case ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE: { |
Michael Chan | 8cbde11 | 2016-04-11 04:11:14 -0400 | [diff] [blame] | 1493 | u32 data1 = le32_to_cpu(cmpl->event_data1); |
| 1494 | struct bnxt_link_info *link_info = &bp->link_info; |
| 1495 | |
| 1496 | if (BNXT_VF(bp)) |
| 1497 | goto async_event_process_exit; |
| 1498 | if (data1 & 0x20000) { |
| 1499 | u16 fw_speed = link_info->force_link_speed; |
| 1500 | u32 speed = bnxt_fw_to_ethtool_speed(fw_speed); |
| 1501 | |
| 1502 | netdev_warn(bp->dev, "Link speed %d no longer supported\n", |
| 1503 | speed); |
| 1504 | } |
Michael Chan | 286ef9d | 2016-11-16 21:13:08 -0500 | [diff] [blame] | 1505 | set_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT, &bp->sp_event); |
Michael Chan | 8cbde11 | 2016-04-11 04:11:14 -0400 | [diff] [blame] | 1506 | /* fall thru */ |
| 1507 | } |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 1508 | case ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE: |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1509 | set_bit(BNXT_LINK_CHNG_SP_EVENT, &bp->sp_event); |
Jeffrey Huang | 1924136 | 2016-02-26 04:00:00 -0500 | [diff] [blame] | 1510 | break; |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 1511 | case ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD: |
Jeffrey Huang | 1924136 | 2016-02-26 04:00:00 -0500 | [diff] [blame] | 1512 | set_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT, &bp->sp_event); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1513 | break; |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 1514 | case ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED: { |
Michael Chan | 4bb13ab | 2016-04-05 14:09:01 -0400 | [diff] [blame] | 1515 | u32 data1 = le32_to_cpu(cmpl->event_data1); |
| 1516 | u16 port_id = BNXT_GET_EVENT_PORT(data1); |
| 1517 | |
| 1518 | if (BNXT_VF(bp)) |
| 1519 | break; |
| 1520 | |
| 1521 | if (bp->pf.port_id != port_id) |
| 1522 | break; |
| 1523 | |
Michael Chan | 4bb13ab | 2016-04-05 14:09:01 -0400 | [diff] [blame] | 1524 | set_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT, &bp->sp_event); |
| 1525 | break; |
| 1526 | } |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 1527 | case ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE: |
Michael Chan | fc0f192 | 2016-06-13 02:25:30 -0400 | [diff] [blame] | 1528 | if (BNXT_PF(bp)) |
| 1529 | goto async_event_process_exit; |
| 1530 | set_bit(BNXT_RESET_TASK_SILENT_SP_EVENT, &bp->sp_event); |
| 1531 | break; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1532 | default: |
Jeffrey Huang | 1924136 | 2016-02-26 04:00:00 -0500 | [diff] [blame] | 1533 | goto async_event_process_exit; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1534 | } |
Jeffrey Huang | 1924136 | 2016-02-26 04:00:00 -0500 | [diff] [blame] | 1535 | schedule_work(&bp->sp_task); |
| 1536 | async_event_process_exit: |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 1537 | bnxt_ulp_async_events(bp, cmpl); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1538 | return 0; |
| 1539 | } |
| 1540 | |
| 1541 | static int bnxt_hwrm_handler(struct bnxt *bp, struct tx_cmp *txcmp) |
| 1542 | { |
| 1543 | u16 cmpl_type = TX_CMP_TYPE(txcmp), vf_id, seq_id; |
| 1544 | struct hwrm_cmpl *h_cmpl = (struct hwrm_cmpl *)txcmp; |
| 1545 | struct hwrm_fwd_req_cmpl *fwd_req_cmpl = |
| 1546 | (struct hwrm_fwd_req_cmpl *)txcmp; |
| 1547 | |
| 1548 | switch (cmpl_type) { |
| 1549 | case CMPL_BASE_TYPE_HWRM_DONE: |
| 1550 | seq_id = le16_to_cpu(h_cmpl->sequence_id); |
| 1551 | if (seq_id == bp->hwrm_intr_seq_id) |
| 1552 | bp->hwrm_intr_seq_id = HWRM_SEQ_ID_INVALID; |
| 1553 | else |
| 1554 | netdev_err(bp->dev, "Invalid hwrm seq id %d\n", seq_id); |
| 1555 | break; |
| 1556 | |
| 1557 | case CMPL_BASE_TYPE_HWRM_FWD_REQ: |
| 1558 | vf_id = le16_to_cpu(fwd_req_cmpl->source_id); |
| 1559 | |
| 1560 | if ((vf_id < bp->pf.first_vf_id) || |
| 1561 | (vf_id >= bp->pf.first_vf_id + bp->pf.active_vfs)) { |
| 1562 | netdev_err(bp->dev, "Msg contains invalid VF id %x\n", |
| 1563 | vf_id); |
| 1564 | return -EINVAL; |
| 1565 | } |
| 1566 | |
| 1567 | set_bit(vf_id - bp->pf.first_vf_id, bp->pf.vf_event_bmap); |
| 1568 | set_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT, &bp->sp_event); |
| 1569 | schedule_work(&bp->sp_task); |
| 1570 | break; |
| 1571 | |
| 1572 | case CMPL_BASE_TYPE_HWRM_ASYNC_EVENT: |
| 1573 | bnxt_async_event_process(bp, |
| 1574 | (struct hwrm_async_event_cmpl *)txcmp); |
| 1575 | |
| 1576 | default: |
| 1577 | break; |
| 1578 | } |
| 1579 | |
| 1580 | return 0; |
| 1581 | } |
| 1582 | |
| 1583 | static irqreturn_t bnxt_msix(int irq, void *dev_instance) |
| 1584 | { |
| 1585 | struct bnxt_napi *bnapi = dev_instance; |
| 1586 | struct bnxt *bp = bnapi->bp; |
| 1587 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 1588 | u32 cons = RING_CMP(cpr->cp_raw_cons); |
| 1589 | |
| 1590 | prefetch(&cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]); |
| 1591 | napi_schedule(&bnapi->napi); |
| 1592 | return IRQ_HANDLED; |
| 1593 | } |
| 1594 | |
| 1595 | static inline int bnxt_has_work(struct bnxt *bp, struct bnxt_cp_ring_info *cpr) |
| 1596 | { |
| 1597 | u32 raw_cons = cpr->cp_raw_cons; |
| 1598 | u16 cons = RING_CMP(raw_cons); |
| 1599 | struct tx_cmp *txcmp; |
| 1600 | |
| 1601 | txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]; |
| 1602 | |
| 1603 | return TX_CMP_VALID(txcmp, raw_cons); |
| 1604 | } |
| 1605 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1606 | static irqreturn_t bnxt_inta(int irq, void *dev_instance) |
| 1607 | { |
| 1608 | struct bnxt_napi *bnapi = dev_instance; |
| 1609 | struct bnxt *bp = bnapi->bp; |
| 1610 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 1611 | u32 cons = RING_CMP(cpr->cp_raw_cons); |
| 1612 | u32 int_status; |
| 1613 | |
| 1614 | prefetch(&cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]); |
| 1615 | |
| 1616 | if (!bnxt_has_work(bp, cpr)) { |
Jeffrey Huang | 1180949 | 2015-11-05 16:25:49 -0500 | [diff] [blame] | 1617 | int_status = readl(bp->bar0 + BNXT_CAG_REG_LEGACY_INT_STATUS); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1618 | /* return if erroneous interrupt */ |
| 1619 | if (!(int_status & (0x10000 << cpr->cp_ring_struct.fw_ring_id))) |
| 1620 | return IRQ_NONE; |
| 1621 | } |
| 1622 | |
| 1623 | /* disable ring IRQ */ |
| 1624 | BNXT_CP_DB_IRQ_DIS(cpr->cp_doorbell); |
| 1625 | |
| 1626 | /* Return here if interrupt is shared and is disabled. */ |
| 1627 | if (unlikely(atomic_read(&bp->intr_sem) != 0)) |
| 1628 | return IRQ_HANDLED; |
| 1629 | |
| 1630 | napi_schedule(&bnapi->napi); |
| 1631 | return IRQ_HANDLED; |
| 1632 | } |
| 1633 | |
| 1634 | static int bnxt_poll_work(struct bnxt *bp, struct bnxt_napi *bnapi, int budget) |
| 1635 | { |
| 1636 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 1637 | u32 raw_cons = cpr->cp_raw_cons; |
| 1638 | u32 cons; |
| 1639 | int tx_pkts = 0; |
| 1640 | int rx_pkts = 0; |
| 1641 | bool rx_event = false; |
| 1642 | bool agg_event = false; |
| 1643 | struct tx_cmp *txcmp; |
| 1644 | |
| 1645 | while (1) { |
| 1646 | int rc; |
| 1647 | |
| 1648 | cons = RING_CMP(raw_cons); |
| 1649 | txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]; |
| 1650 | |
| 1651 | if (!TX_CMP_VALID(txcmp, raw_cons)) |
| 1652 | break; |
| 1653 | |
Michael Chan | 67a95e2 | 2016-05-04 16:56:43 -0400 | [diff] [blame] | 1654 | /* The valid test of the entry must be done first before |
| 1655 | * reading any further. |
| 1656 | */ |
Michael Chan | b67daab | 2016-05-15 03:04:51 -0400 | [diff] [blame] | 1657 | dma_rmb(); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1658 | if (TX_CMP_TYPE(txcmp) == CMP_TYPE_TX_L2_CMP) { |
| 1659 | tx_pkts++; |
| 1660 | /* return full budget so NAPI will complete. */ |
| 1661 | if (unlikely(tx_pkts > bp->tx_wake_thresh)) |
| 1662 | rx_pkts = budget; |
| 1663 | } else if ((TX_CMP_TYPE(txcmp) & 0x30) == 0x10) { |
| 1664 | rc = bnxt_rx_pkt(bp, bnapi, &raw_cons, &agg_event); |
| 1665 | if (likely(rc >= 0)) |
| 1666 | rx_pkts += rc; |
| 1667 | else if (rc == -EBUSY) /* partial completion */ |
| 1668 | break; |
| 1669 | rx_event = true; |
| 1670 | } else if (unlikely((TX_CMP_TYPE(txcmp) == |
| 1671 | CMPL_BASE_TYPE_HWRM_DONE) || |
| 1672 | (TX_CMP_TYPE(txcmp) == |
| 1673 | CMPL_BASE_TYPE_HWRM_FWD_REQ) || |
| 1674 | (TX_CMP_TYPE(txcmp) == |
| 1675 | CMPL_BASE_TYPE_HWRM_ASYNC_EVENT))) { |
| 1676 | bnxt_hwrm_handler(bp, txcmp); |
| 1677 | } |
| 1678 | raw_cons = NEXT_RAW_CMP(raw_cons); |
| 1679 | |
| 1680 | if (rx_pkts == budget) |
| 1681 | break; |
| 1682 | } |
| 1683 | |
| 1684 | cpr->cp_raw_cons = raw_cons; |
| 1685 | /* ACK completion ring before freeing tx ring and producing new |
| 1686 | * buffers in rx/agg rings to prevent overflowing the completion |
| 1687 | * ring. |
| 1688 | */ |
| 1689 | BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons); |
| 1690 | |
| 1691 | if (tx_pkts) |
| 1692 | bnxt_tx_int(bp, bnapi, tx_pkts); |
| 1693 | |
| 1694 | if (rx_event) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 1695 | struct bnxt_rx_ring_info *rxr = bnapi->rx_ring; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1696 | |
| 1697 | writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell); |
| 1698 | writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell); |
| 1699 | if (agg_event) { |
| 1700 | writel(DB_KEY_RX | rxr->rx_agg_prod, |
| 1701 | rxr->rx_agg_doorbell); |
| 1702 | writel(DB_KEY_RX | rxr->rx_agg_prod, |
| 1703 | rxr->rx_agg_doorbell); |
| 1704 | } |
| 1705 | } |
| 1706 | return rx_pkts; |
| 1707 | } |
| 1708 | |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 1709 | static int bnxt_poll_nitroa0(struct napi_struct *napi, int budget) |
| 1710 | { |
| 1711 | struct bnxt_napi *bnapi = container_of(napi, struct bnxt_napi, napi); |
| 1712 | struct bnxt *bp = bnapi->bp; |
| 1713 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 1714 | struct bnxt_rx_ring_info *rxr = bnapi->rx_ring; |
| 1715 | struct tx_cmp *txcmp; |
| 1716 | struct rx_cmp_ext *rxcmp1; |
| 1717 | u32 cp_cons, tmp_raw_cons; |
| 1718 | u32 raw_cons = cpr->cp_raw_cons; |
| 1719 | u32 rx_pkts = 0; |
| 1720 | bool agg_event = false; |
| 1721 | |
| 1722 | while (1) { |
| 1723 | int rc; |
| 1724 | |
| 1725 | cp_cons = RING_CMP(raw_cons); |
| 1726 | txcmp = &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; |
| 1727 | |
| 1728 | if (!TX_CMP_VALID(txcmp, raw_cons)) |
| 1729 | break; |
| 1730 | |
| 1731 | if ((TX_CMP_TYPE(txcmp) & 0x30) == 0x10) { |
| 1732 | tmp_raw_cons = NEXT_RAW_CMP(raw_cons); |
| 1733 | cp_cons = RING_CMP(tmp_raw_cons); |
| 1734 | rxcmp1 = (struct rx_cmp_ext *) |
| 1735 | &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; |
| 1736 | |
| 1737 | if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons)) |
| 1738 | break; |
| 1739 | |
| 1740 | /* force an error to recycle the buffer */ |
| 1741 | rxcmp1->rx_cmp_cfa_code_errors_v2 |= |
| 1742 | cpu_to_le32(RX_CMPL_ERRORS_CRC_ERROR); |
| 1743 | |
| 1744 | rc = bnxt_rx_pkt(bp, bnapi, &raw_cons, &agg_event); |
| 1745 | if (likely(rc == -EIO)) |
| 1746 | rx_pkts++; |
| 1747 | else if (rc == -EBUSY) /* partial completion */ |
| 1748 | break; |
| 1749 | } else if (unlikely(TX_CMP_TYPE(txcmp) == |
| 1750 | CMPL_BASE_TYPE_HWRM_DONE)) { |
| 1751 | bnxt_hwrm_handler(bp, txcmp); |
| 1752 | } else { |
| 1753 | netdev_err(bp->dev, |
| 1754 | "Invalid completion received on special ring\n"); |
| 1755 | } |
| 1756 | raw_cons = NEXT_RAW_CMP(raw_cons); |
| 1757 | |
| 1758 | if (rx_pkts == budget) |
| 1759 | break; |
| 1760 | } |
| 1761 | |
| 1762 | cpr->cp_raw_cons = raw_cons; |
| 1763 | BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons); |
| 1764 | writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell); |
| 1765 | writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell); |
| 1766 | |
| 1767 | if (agg_event) { |
| 1768 | writel(DB_KEY_RX | rxr->rx_agg_prod, rxr->rx_agg_doorbell); |
| 1769 | writel(DB_KEY_RX | rxr->rx_agg_prod, rxr->rx_agg_doorbell); |
| 1770 | } |
| 1771 | |
| 1772 | if (!bnxt_has_work(bp, cpr) && rx_pkts < budget) { |
Eric Dumazet | 6ad2016 | 2017-01-30 08:22:01 -0800 | [diff] [blame] | 1773 | napi_complete_done(napi, rx_pkts); |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 1774 | BNXT_CP_DB_REARM(cpr->cp_doorbell, cpr->cp_raw_cons); |
| 1775 | } |
| 1776 | return rx_pkts; |
| 1777 | } |
| 1778 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1779 | static int bnxt_poll(struct napi_struct *napi, int budget) |
| 1780 | { |
| 1781 | struct bnxt_napi *bnapi = container_of(napi, struct bnxt_napi, napi); |
| 1782 | struct bnxt *bp = bnapi->bp; |
| 1783 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 1784 | int work_done = 0; |
| 1785 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1786 | while (1) { |
| 1787 | work_done += bnxt_poll_work(bp, bnapi, budget - work_done); |
| 1788 | |
| 1789 | if (work_done >= budget) |
| 1790 | break; |
| 1791 | |
| 1792 | if (!bnxt_has_work(bp, cpr)) { |
Michael Chan | e7b9569 | 2016-12-29 12:13:32 -0500 | [diff] [blame] | 1793 | if (napi_complete_done(napi, work_done)) |
| 1794 | BNXT_CP_DB_REARM(cpr->cp_doorbell, |
| 1795 | cpr->cp_raw_cons); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1796 | break; |
| 1797 | } |
| 1798 | } |
| 1799 | mmiowb(); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1800 | return work_done; |
| 1801 | } |
| 1802 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1803 | static void bnxt_free_tx_skbs(struct bnxt *bp) |
| 1804 | { |
| 1805 | int i, max_idx; |
| 1806 | struct pci_dev *pdev = bp->pdev; |
| 1807 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 1808 | if (!bp->tx_ring) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1809 | return; |
| 1810 | |
| 1811 | max_idx = bp->tx_nr_pages * TX_DESC_CNT; |
| 1812 | for (i = 0; i < bp->tx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 1813 | struct bnxt_tx_ring_info *txr = &bp->tx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1814 | int j; |
| 1815 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1816 | for (j = 0; j < max_idx;) { |
| 1817 | struct bnxt_sw_tx_bd *tx_buf = &txr->tx_buf_ring[j]; |
| 1818 | struct sk_buff *skb = tx_buf->skb; |
| 1819 | int k, last; |
| 1820 | |
| 1821 | if (!skb) { |
| 1822 | j++; |
| 1823 | continue; |
| 1824 | } |
| 1825 | |
| 1826 | tx_buf->skb = NULL; |
| 1827 | |
| 1828 | if (tx_buf->is_push) { |
| 1829 | dev_kfree_skb(skb); |
| 1830 | j += 2; |
| 1831 | continue; |
| 1832 | } |
| 1833 | |
| 1834 | dma_unmap_single(&pdev->dev, |
| 1835 | dma_unmap_addr(tx_buf, mapping), |
| 1836 | skb_headlen(skb), |
| 1837 | PCI_DMA_TODEVICE); |
| 1838 | |
| 1839 | last = tx_buf->nr_frags; |
| 1840 | j += 2; |
Michael Chan | d612a57 | 2016-01-28 03:11:22 -0500 | [diff] [blame] | 1841 | for (k = 0; k < last; k++, j++) { |
| 1842 | int ring_idx = j & bp->tx_ring_mask; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1843 | skb_frag_t *frag = &skb_shinfo(skb)->frags[k]; |
| 1844 | |
Michael Chan | d612a57 | 2016-01-28 03:11:22 -0500 | [diff] [blame] | 1845 | tx_buf = &txr->tx_buf_ring[ring_idx]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1846 | dma_unmap_page( |
| 1847 | &pdev->dev, |
| 1848 | dma_unmap_addr(tx_buf, mapping), |
| 1849 | skb_frag_size(frag), PCI_DMA_TODEVICE); |
| 1850 | } |
| 1851 | dev_kfree_skb(skb); |
| 1852 | } |
| 1853 | netdev_tx_reset_queue(netdev_get_tx_queue(bp->dev, i)); |
| 1854 | } |
| 1855 | } |
| 1856 | |
| 1857 | static void bnxt_free_rx_skbs(struct bnxt *bp) |
| 1858 | { |
| 1859 | int i, max_idx, max_agg_idx; |
| 1860 | struct pci_dev *pdev = bp->pdev; |
| 1861 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 1862 | if (!bp->rx_ring) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1863 | return; |
| 1864 | |
| 1865 | max_idx = bp->rx_nr_pages * RX_DESC_CNT; |
| 1866 | max_agg_idx = bp->rx_agg_nr_pages * RX_DESC_CNT; |
| 1867 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 1868 | struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1869 | int j; |
| 1870 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1871 | if (rxr->rx_tpa) { |
| 1872 | for (j = 0; j < MAX_TPA; j++) { |
| 1873 | struct bnxt_tpa_info *tpa_info = |
| 1874 | &rxr->rx_tpa[j]; |
| 1875 | u8 *data = tpa_info->data; |
| 1876 | |
| 1877 | if (!data) |
| 1878 | continue; |
| 1879 | |
Michael Chan | 745fc05 | 2017-02-06 16:55:34 -0500 | [diff] [blame] | 1880 | dma_unmap_single(&pdev->dev, tpa_info->mapping, |
| 1881 | bp->rx_buf_use_size, |
| 1882 | bp->rx_dir); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1883 | |
| 1884 | tpa_info->data = NULL; |
| 1885 | |
| 1886 | kfree(data); |
| 1887 | } |
| 1888 | } |
| 1889 | |
| 1890 | for (j = 0; j < max_idx; j++) { |
| 1891 | struct bnxt_sw_rx_bd *rx_buf = &rxr->rx_buf_ring[j]; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1892 | void *data = rx_buf->data; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1893 | |
| 1894 | if (!data) |
| 1895 | continue; |
| 1896 | |
Michael Chan | 11cd119 | 2017-02-06 16:55:33 -0500 | [diff] [blame] | 1897 | dma_unmap_single(&pdev->dev, rx_buf->mapping, |
Michael Chan | 745fc05 | 2017-02-06 16:55:34 -0500 | [diff] [blame] | 1898 | bp->rx_buf_use_size, bp->rx_dir); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1899 | |
| 1900 | rx_buf->data = NULL; |
| 1901 | |
| 1902 | kfree(data); |
| 1903 | } |
| 1904 | |
| 1905 | for (j = 0; j < max_agg_idx; j++) { |
| 1906 | struct bnxt_sw_rx_agg_bd *rx_agg_buf = |
| 1907 | &rxr->rx_agg_ring[j]; |
| 1908 | struct page *page = rx_agg_buf->page; |
| 1909 | |
| 1910 | if (!page) |
| 1911 | continue; |
| 1912 | |
Michael Chan | 11cd119 | 2017-02-06 16:55:33 -0500 | [diff] [blame] | 1913 | dma_unmap_page(&pdev->dev, rx_agg_buf->mapping, |
Michael Chan | 2839f28 | 2016-04-25 02:30:50 -0400 | [diff] [blame] | 1914 | BNXT_RX_PAGE_SIZE, PCI_DMA_FROMDEVICE); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1915 | |
| 1916 | rx_agg_buf->page = NULL; |
| 1917 | __clear_bit(j, rxr->rx_agg_bmap); |
| 1918 | |
| 1919 | __free_page(page); |
| 1920 | } |
Michael Chan | 89d0a06 | 2016-04-25 02:30:51 -0400 | [diff] [blame] | 1921 | if (rxr->rx_page) { |
| 1922 | __free_page(rxr->rx_page); |
| 1923 | rxr->rx_page = NULL; |
| 1924 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1925 | } |
| 1926 | } |
| 1927 | |
| 1928 | static void bnxt_free_skbs(struct bnxt *bp) |
| 1929 | { |
| 1930 | bnxt_free_tx_skbs(bp); |
| 1931 | bnxt_free_rx_skbs(bp); |
| 1932 | } |
| 1933 | |
| 1934 | static void bnxt_free_ring(struct bnxt *bp, struct bnxt_ring_struct *ring) |
| 1935 | { |
| 1936 | struct pci_dev *pdev = bp->pdev; |
| 1937 | int i; |
| 1938 | |
| 1939 | for (i = 0; i < ring->nr_pages; i++) { |
| 1940 | if (!ring->pg_arr[i]) |
| 1941 | continue; |
| 1942 | |
| 1943 | dma_free_coherent(&pdev->dev, ring->page_size, |
| 1944 | ring->pg_arr[i], ring->dma_arr[i]); |
| 1945 | |
| 1946 | ring->pg_arr[i] = NULL; |
| 1947 | } |
| 1948 | if (ring->pg_tbl) { |
| 1949 | dma_free_coherent(&pdev->dev, ring->nr_pages * 8, |
| 1950 | ring->pg_tbl, ring->pg_tbl_map); |
| 1951 | ring->pg_tbl = NULL; |
| 1952 | } |
| 1953 | if (ring->vmem_size && *ring->vmem) { |
| 1954 | vfree(*ring->vmem); |
| 1955 | *ring->vmem = NULL; |
| 1956 | } |
| 1957 | } |
| 1958 | |
| 1959 | static int bnxt_alloc_ring(struct bnxt *bp, struct bnxt_ring_struct *ring) |
| 1960 | { |
| 1961 | int i; |
| 1962 | struct pci_dev *pdev = bp->pdev; |
| 1963 | |
| 1964 | if (ring->nr_pages > 1) { |
| 1965 | ring->pg_tbl = dma_alloc_coherent(&pdev->dev, |
| 1966 | ring->nr_pages * 8, |
| 1967 | &ring->pg_tbl_map, |
| 1968 | GFP_KERNEL); |
| 1969 | if (!ring->pg_tbl) |
| 1970 | return -ENOMEM; |
| 1971 | } |
| 1972 | |
| 1973 | for (i = 0; i < ring->nr_pages; i++) { |
| 1974 | ring->pg_arr[i] = dma_alloc_coherent(&pdev->dev, |
| 1975 | ring->page_size, |
| 1976 | &ring->dma_arr[i], |
| 1977 | GFP_KERNEL); |
| 1978 | if (!ring->pg_arr[i]) |
| 1979 | return -ENOMEM; |
| 1980 | |
| 1981 | if (ring->nr_pages > 1) |
| 1982 | ring->pg_tbl[i] = cpu_to_le64(ring->dma_arr[i]); |
| 1983 | } |
| 1984 | |
| 1985 | if (ring->vmem_size) { |
| 1986 | *ring->vmem = vzalloc(ring->vmem_size); |
| 1987 | if (!(*ring->vmem)) |
| 1988 | return -ENOMEM; |
| 1989 | } |
| 1990 | return 0; |
| 1991 | } |
| 1992 | |
| 1993 | static void bnxt_free_rx_rings(struct bnxt *bp) |
| 1994 | { |
| 1995 | int i; |
| 1996 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 1997 | if (!bp->rx_ring) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1998 | return; |
| 1999 | |
| 2000 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2001 | struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2002 | struct bnxt_ring_struct *ring; |
| 2003 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2004 | kfree(rxr->rx_tpa); |
| 2005 | rxr->rx_tpa = NULL; |
| 2006 | |
| 2007 | kfree(rxr->rx_agg_bmap); |
| 2008 | rxr->rx_agg_bmap = NULL; |
| 2009 | |
| 2010 | ring = &rxr->rx_ring_struct; |
| 2011 | bnxt_free_ring(bp, ring); |
| 2012 | |
| 2013 | ring = &rxr->rx_agg_ring_struct; |
| 2014 | bnxt_free_ring(bp, ring); |
| 2015 | } |
| 2016 | } |
| 2017 | |
| 2018 | static int bnxt_alloc_rx_rings(struct bnxt *bp) |
| 2019 | { |
| 2020 | int i, rc, agg_rings = 0, tpa_rings = 0; |
| 2021 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2022 | if (!bp->rx_ring) |
| 2023 | return -ENOMEM; |
| 2024 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2025 | if (bp->flags & BNXT_FLAG_AGG_RINGS) |
| 2026 | agg_rings = 1; |
| 2027 | |
| 2028 | if (bp->flags & BNXT_FLAG_TPA) |
| 2029 | tpa_rings = 1; |
| 2030 | |
| 2031 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2032 | struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2033 | struct bnxt_ring_struct *ring; |
| 2034 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2035 | ring = &rxr->rx_ring_struct; |
| 2036 | |
| 2037 | rc = bnxt_alloc_ring(bp, ring); |
| 2038 | if (rc) |
| 2039 | return rc; |
| 2040 | |
| 2041 | if (agg_rings) { |
| 2042 | u16 mem_size; |
| 2043 | |
| 2044 | ring = &rxr->rx_agg_ring_struct; |
| 2045 | rc = bnxt_alloc_ring(bp, ring); |
| 2046 | if (rc) |
| 2047 | return rc; |
| 2048 | |
| 2049 | rxr->rx_agg_bmap_size = bp->rx_agg_ring_mask + 1; |
| 2050 | mem_size = rxr->rx_agg_bmap_size / 8; |
| 2051 | rxr->rx_agg_bmap = kzalloc(mem_size, GFP_KERNEL); |
| 2052 | if (!rxr->rx_agg_bmap) |
| 2053 | return -ENOMEM; |
| 2054 | |
| 2055 | if (tpa_rings) { |
| 2056 | rxr->rx_tpa = kcalloc(MAX_TPA, |
| 2057 | sizeof(struct bnxt_tpa_info), |
| 2058 | GFP_KERNEL); |
| 2059 | if (!rxr->rx_tpa) |
| 2060 | return -ENOMEM; |
| 2061 | } |
| 2062 | } |
| 2063 | } |
| 2064 | return 0; |
| 2065 | } |
| 2066 | |
| 2067 | static void bnxt_free_tx_rings(struct bnxt *bp) |
| 2068 | { |
| 2069 | int i; |
| 2070 | struct pci_dev *pdev = bp->pdev; |
| 2071 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2072 | if (!bp->tx_ring) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2073 | return; |
| 2074 | |
| 2075 | for (i = 0; i < bp->tx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2076 | struct bnxt_tx_ring_info *txr = &bp->tx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2077 | struct bnxt_ring_struct *ring; |
| 2078 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2079 | if (txr->tx_push) { |
| 2080 | dma_free_coherent(&pdev->dev, bp->tx_push_size, |
| 2081 | txr->tx_push, txr->tx_push_mapping); |
| 2082 | txr->tx_push = NULL; |
| 2083 | } |
| 2084 | |
| 2085 | ring = &txr->tx_ring_struct; |
| 2086 | |
| 2087 | bnxt_free_ring(bp, ring); |
| 2088 | } |
| 2089 | } |
| 2090 | |
| 2091 | static int bnxt_alloc_tx_rings(struct bnxt *bp) |
| 2092 | { |
| 2093 | int i, j, rc; |
| 2094 | struct pci_dev *pdev = bp->pdev; |
| 2095 | |
| 2096 | bp->tx_push_size = 0; |
| 2097 | if (bp->tx_push_thresh) { |
| 2098 | int push_size; |
| 2099 | |
| 2100 | push_size = L1_CACHE_ALIGN(sizeof(struct tx_push_bd) + |
| 2101 | bp->tx_push_thresh); |
| 2102 | |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 2103 | if (push_size > 256) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2104 | push_size = 0; |
| 2105 | bp->tx_push_thresh = 0; |
| 2106 | } |
| 2107 | |
| 2108 | bp->tx_push_size = push_size; |
| 2109 | } |
| 2110 | |
| 2111 | for (i = 0, j = 0; i < bp->tx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2112 | struct bnxt_tx_ring_info *txr = &bp->tx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2113 | struct bnxt_ring_struct *ring; |
| 2114 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2115 | ring = &txr->tx_ring_struct; |
| 2116 | |
| 2117 | rc = bnxt_alloc_ring(bp, ring); |
| 2118 | if (rc) |
| 2119 | return rc; |
| 2120 | |
| 2121 | if (bp->tx_push_size) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2122 | dma_addr_t mapping; |
| 2123 | |
| 2124 | /* One pre-allocated DMA buffer to backup |
| 2125 | * TX push operation |
| 2126 | */ |
| 2127 | txr->tx_push = dma_alloc_coherent(&pdev->dev, |
| 2128 | bp->tx_push_size, |
| 2129 | &txr->tx_push_mapping, |
| 2130 | GFP_KERNEL); |
| 2131 | |
| 2132 | if (!txr->tx_push) |
| 2133 | return -ENOMEM; |
| 2134 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2135 | mapping = txr->tx_push_mapping + |
| 2136 | sizeof(struct tx_push_bd); |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 2137 | txr->data_mapping = cpu_to_le64(mapping); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2138 | |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 2139 | memset(txr->tx_push, 0, sizeof(struct tx_push_bd)); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2140 | } |
| 2141 | ring->queue_id = bp->q_info[j].queue_id; |
| 2142 | if (i % bp->tx_nr_rings_per_tc == (bp->tx_nr_rings_per_tc - 1)) |
| 2143 | j++; |
| 2144 | } |
| 2145 | return 0; |
| 2146 | } |
| 2147 | |
| 2148 | static void bnxt_free_cp_rings(struct bnxt *bp) |
| 2149 | { |
| 2150 | int i; |
| 2151 | |
| 2152 | if (!bp->bnapi) |
| 2153 | return; |
| 2154 | |
| 2155 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 2156 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 2157 | struct bnxt_cp_ring_info *cpr; |
| 2158 | struct bnxt_ring_struct *ring; |
| 2159 | |
| 2160 | if (!bnapi) |
| 2161 | continue; |
| 2162 | |
| 2163 | cpr = &bnapi->cp_ring; |
| 2164 | ring = &cpr->cp_ring_struct; |
| 2165 | |
| 2166 | bnxt_free_ring(bp, ring); |
| 2167 | } |
| 2168 | } |
| 2169 | |
| 2170 | static int bnxt_alloc_cp_rings(struct bnxt *bp) |
| 2171 | { |
| 2172 | int i, rc; |
| 2173 | |
| 2174 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 2175 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 2176 | struct bnxt_cp_ring_info *cpr; |
| 2177 | struct bnxt_ring_struct *ring; |
| 2178 | |
| 2179 | if (!bnapi) |
| 2180 | continue; |
| 2181 | |
| 2182 | cpr = &bnapi->cp_ring; |
| 2183 | ring = &cpr->cp_ring_struct; |
| 2184 | |
| 2185 | rc = bnxt_alloc_ring(bp, ring); |
| 2186 | if (rc) |
| 2187 | return rc; |
| 2188 | } |
| 2189 | return 0; |
| 2190 | } |
| 2191 | |
| 2192 | static void bnxt_init_ring_struct(struct bnxt *bp) |
| 2193 | { |
| 2194 | int i; |
| 2195 | |
| 2196 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 2197 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 2198 | struct bnxt_cp_ring_info *cpr; |
| 2199 | struct bnxt_rx_ring_info *rxr; |
| 2200 | struct bnxt_tx_ring_info *txr; |
| 2201 | struct bnxt_ring_struct *ring; |
| 2202 | |
| 2203 | if (!bnapi) |
| 2204 | continue; |
| 2205 | |
| 2206 | cpr = &bnapi->cp_ring; |
| 2207 | ring = &cpr->cp_ring_struct; |
| 2208 | ring->nr_pages = bp->cp_nr_pages; |
| 2209 | ring->page_size = HW_CMPD_RING_SIZE; |
| 2210 | ring->pg_arr = (void **)cpr->cp_desc_ring; |
| 2211 | ring->dma_arr = cpr->cp_desc_mapping; |
| 2212 | ring->vmem_size = 0; |
| 2213 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2214 | rxr = bnapi->rx_ring; |
Michael Chan | 3b2b7d9 | 2016-01-02 23:45:00 -0500 | [diff] [blame] | 2215 | if (!rxr) |
| 2216 | goto skip_rx; |
| 2217 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2218 | ring = &rxr->rx_ring_struct; |
| 2219 | ring->nr_pages = bp->rx_nr_pages; |
| 2220 | ring->page_size = HW_RXBD_RING_SIZE; |
| 2221 | ring->pg_arr = (void **)rxr->rx_desc_ring; |
| 2222 | ring->dma_arr = rxr->rx_desc_mapping; |
| 2223 | ring->vmem_size = SW_RXBD_RING_SIZE * bp->rx_nr_pages; |
| 2224 | ring->vmem = (void **)&rxr->rx_buf_ring; |
| 2225 | |
| 2226 | ring = &rxr->rx_agg_ring_struct; |
| 2227 | ring->nr_pages = bp->rx_agg_nr_pages; |
| 2228 | ring->page_size = HW_RXBD_RING_SIZE; |
| 2229 | ring->pg_arr = (void **)rxr->rx_agg_desc_ring; |
| 2230 | ring->dma_arr = rxr->rx_agg_desc_mapping; |
| 2231 | ring->vmem_size = SW_RXBD_AGG_RING_SIZE * bp->rx_agg_nr_pages; |
| 2232 | ring->vmem = (void **)&rxr->rx_agg_ring; |
| 2233 | |
Michael Chan | 3b2b7d9 | 2016-01-02 23:45:00 -0500 | [diff] [blame] | 2234 | skip_rx: |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2235 | txr = bnapi->tx_ring; |
Michael Chan | 3b2b7d9 | 2016-01-02 23:45:00 -0500 | [diff] [blame] | 2236 | if (!txr) |
| 2237 | continue; |
| 2238 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2239 | ring = &txr->tx_ring_struct; |
| 2240 | ring->nr_pages = bp->tx_nr_pages; |
| 2241 | ring->page_size = HW_RXBD_RING_SIZE; |
| 2242 | ring->pg_arr = (void **)txr->tx_desc_ring; |
| 2243 | ring->dma_arr = txr->tx_desc_mapping; |
| 2244 | ring->vmem_size = SW_TXBD_RING_SIZE * bp->tx_nr_pages; |
| 2245 | ring->vmem = (void **)&txr->tx_buf_ring; |
| 2246 | } |
| 2247 | } |
| 2248 | |
| 2249 | static void bnxt_init_rxbd_pages(struct bnxt_ring_struct *ring, u32 type) |
| 2250 | { |
| 2251 | int i; |
| 2252 | u32 prod; |
| 2253 | struct rx_bd **rx_buf_ring; |
| 2254 | |
| 2255 | rx_buf_ring = (struct rx_bd **)ring->pg_arr; |
| 2256 | for (i = 0, prod = 0; i < ring->nr_pages; i++) { |
| 2257 | int j; |
| 2258 | struct rx_bd *rxbd; |
| 2259 | |
| 2260 | rxbd = rx_buf_ring[i]; |
| 2261 | if (!rxbd) |
| 2262 | continue; |
| 2263 | |
| 2264 | for (j = 0; j < RX_DESC_CNT; j++, rxbd++, prod++) { |
| 2265 | rxbd->rx_bd_len_flags_type = cpu_to_le32(type); |
| 2266 | rxbd->rx_bd_opaque = prod; |
| 2267 | } |
| 2268 | } |
| 2269 | } |
| 2270 | |
| 2271 | static int bnxt_init_one_rx_ring(struct bnxt *bp, int ring_nr) |
| 2272 | { |
| 2273 | struct net_device *dev = bp->dev; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2274 | struct bnxt_rx_ring_info *rxr; |
| 2275 | struct bnxt_ring_struct *ring; |
| 2276 | u32 prod, type; |
| 2277 | int i; |
| 2278 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2279 | type = (bp->rx_buf_use_size << RX_BD_LEN_SHIFT) | |
| 2280 | RX_BD_TYPE_RX_PACKET_BD | RX_BD_FLAGS_EOP; |
| 2281 | |
| 2282 | if (NET_IP_ALIGN == 2) |
| 2283 | type |= RX_BD_FLAGS_SOP; |
| 2284 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2285 | rxr = &bp->rx_ring[ring_nr]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2286 | ring = &rxr->rx_ring_struct; |
| 2287 | bnxt_init_rxbd_pages(ring, type); |
| 2288 | |
| 2289 | prod = rxr->rx_prod; |
| 2290 | for (i = 0; i < bp->rx_ring_size; i++) { |
| 2291 | if (bnxt_alloc_rx_data(bp, rxr, prod, GFP_KERNEL) != 0) { |
| 2292 | netdev_warn(dev, "init'ed rx ring %d with %d/%d skbs only\n", |
| 2293 | ring_nr, i, bp->rx_ring_size); |
| 2294 | break; |
| 2295 | } |
| 2296 | prod = NEXT_RX(prod); |
| 2297 | } |
| 2298 | rxr->rx_prod = prod; |
| 2299 | ring->fw_ring_id = INVALID_HW_RING_ID; |
| 2300 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 2301 | ring = &rxr->rx_agg_ring_struct; |
| 2302 | ring->fw_ring_id = INVALID_HW_RING_ID; |
| 2303 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2304 | if (!(bp->flags & BNXT_FLAG_AGG_RINGS)) |
| 2305 | return 0; |
| 2306 | |
Michael Chan | 2839f28 | 2016-04-25 02:30:50 -0400 | [diff] [blame] | 2307 | type = ((u32)BNXT_RX_PAGE_SIZE << RX_BD_LEN_SHIFT) | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2308 | RX_BD_TYPE_RX_AGG_BD | RX_BD_FLAGS_SOP; |
| 2309 | |
| 2310 | bnxt_init_rxbd_pages(ring, type); |
| 2311 | |
| 2312 | prod = rxr->rx_agg_prod; |
| 2313 | for (i = 0; i < bp->rx_agg_ring_size; i++) { |
| 2314 | if (bnxt_alloc_rx_page(bp, rxr, prod, GFP_KERNEL) != 0) { |
| 2315 | netdev_warn(dev, "init'ed rx ring %d with %d/%d pages only\n", |
| 2316 | ring_nr, i, bp->rx_ring_size); |
| 2317 | break; |
| 2318 | } |
| 2319 | prod = NEXT_RX_AGG(prod); |
| 2320 | } |
| 2321 | rxr->rx_agg_prod = prod; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2322 | |
| 2323 | if (bp->flags & BNXT_FLAG_TPA) { |
| 2324 | if (rxr->rx_tpa) { |
| 2325 | u8 *data; |
| 2326 | dma_addr_t mapping; |
| 2327 | |
| 2328 | for (i = 0; i < MAX_TPA; i++) { |
| 2329 | data = __bnxt_alloc_rx_data(bp, &mapping, |
| 2330 | GFP_KERNEL); |
| 2331 | if (!data) |
| 2332 | return -ENOMEM; |
| 2333 | |
| 2334 | rxr->rx_tpa[i].data = data; |
Michael Chan | b3dba77 | 2017-02-06 16:55:35 -0500 | [diff] [blame^] | 2335 | rxr->rx_tpa[i].data_ptr = data + bp->rx_offset; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2336 | rxr->rx_tpa[i].mapping = mapping; |
| 2337 | } |
| 2338 | } else { |
| 2339 | netdev_err(bp->dev, "No resource allocated for LRO/GRO\n"); |
| 2340 | return -ENOMEM; |
| 2341 | } |
| 2342 | } |
| 2343 | |
| 2344 | return 0; |
| 2345 | } |
| 2346 | |
| 2347 | static int bnxt_init_rx_rings(struct bnxt *bp) |
| 2348 | { |
| 2349 | int i, rc = 0; |
| 2350 | |
Michael Chan | b3dba77 | 2017-02-06 16:55:35 -0500 | [diff] [blame^] | 2351 | bp->rx_offset = BNXT_RX_OFFSET; |
| 2352 | bp->rx_dma_offset = BNXT_RX_DMA_OFFSET; |
| 2353 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2354 | for (i = 0; i < bp->rx_nr_rings; i++) { |
| 2355 | rc = bnxt_init_one_rx_ring(bp, i); |
| 2356 | if (rc) |
| 2357 | break; |
| 2358 | } |
| 2359 | |
| 2360 | return rc; |
| 2361 | } |
| 2362 | |
| 2363 | static int bnxt_init_tx_rings(struct bnxt *bp) |
| 2364 | { |
| 2365 | u16 i; |
| 2366 | |
| 2367 | bp->tx_wake_thresh = max_t(int, bp->tx_ring_size / 2, |
| 2368 | MAX_SKB_FRAGS + 1); |
| 2369 | |
| 2370 | for (i = 0; i < bp->tx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2371 | struct bnxt_tx_ring_info *txr = &bp->tx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2372 | struct bnxt_ring_struct *ring = &txr->tx_ring_struct; |
| 2373 | |
| 2374 | ring->fw_ring_id = INVALID_HW_RING_ID; |
| 2375 | } |
| 2376 | |
| 2377 | return 0; |
| 2378 | } |
| 2379 | |
| 2380 | static void bnxt_free_ring_grps(struct bnxt *bp) |
| 2381 | { |
| 2382 | kfree(bp->grp_info); |
| 2383 | bp->grp_info = NULL; |
| 2384 | } |
| 2385 | |
| 2386 | static int bnxt_init_ring_grps(struct bnxt *bp, bool irq_re_init) |
| 2387 | { |
| 2388 | int i; |
| 2389 | |
| 2390 | if (irq_re_init) { |
| 2391 | bp->grp_info = kcalloc(bp->cp_nr_rings, |
| 2392 | sizeof(struct bnxt_ring_grp_info), |
| 2393 | GFP_KERNEL); |
| 2394 | if (!bp->grp_info) |
| 2395 | return -ENOMEM; |
| 2396 | } |
| 2397 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 2398 | if (irq_re_init) |
| 2399 | bp->grp_info[i].fw_stats_ctx = INVALID_HW_RING_ID; |
| 2400 | bp->grp_info[i].fw_grp_id = INVALID_HW_RING_ID; |
| 2401 | bp->grp_info[i].rx_fw_ring_id = INVALID_HW_RING_ID; |
| 2402 | bp->grp_info[i].agg_fw_ring_id = INVALID_HW_RING_ID; |
| 2403 | bp->grp_info[i].cp_fw_ring_id = INVALID_HW_RING_ID; |
| 2404 | } |
| 2405 | return 0; |
| 2406 | } |
| 2407 | |
| 2408 | static void bnxt_free_vnics(struct bnxt *bp) |
| 2409 | { |
| 2410 | kfree(bp->vnic_info); |
| 2411 | bp->vnic_info = NULL; |
| 2412 | bp->nr_vnics = 0; |
| 2413 | } |
| 2414 | |
| 2415 | static int bnxt_alloc_vnics(struct bnxt *bp) |
| 2416 | { |
| 2417 | int num_vnics = 1; |
| 2418 | |
| 2419 | #ifdef CONFIG_RFS_ACCEL |
| 2420 | if (bp->flags & BNXT_FLAG_RFS) |
| 2421 | num_vnics += bp->rx_nr_rings; |
| 2422 | #endif |
| 2423 | |
Prashant Sreedharan | dc52c6c | 2016-07-18 07:15:24 -0400 | [diff] [blame] | 2424 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 2425 | num_vnics++; |
| 2426 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2427 | bp->vnic_info = kcalloc(num_vnics, sizeof(struct bnxt_vnic_info), |
| 2428 | GFP_KERNEL); |
| 2429 | if (!bp->vnic_info) |
| 2430 | return -ENOMEM; |
| 2431 | |
| 2432 | bp->nr_vnics = num_vnics; |
| 2433 | return 0; |
| 2434 | } |
| 2435 | |
| 2436 | static void bnxt_init_vnics(struct bnxt *bp) |
| 2437 | { |
| 2438 | int i; |
| 2439 | |
| 2440 | for (i = 0; i < bp->nr_vnics; i++) { |
| 2441 | struct bnxt_vnic_info *vnic = &bp->vnic_info[i]; |
| 2442 | |
| 2443 | vnic->fw_vnic_id = INVALID_HW_RING_ID; |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 2444 | vnic->fw_rss_cos_lb_ctx[0] = INVALID_HW_RING_ID; |
| 2445 | vnic->fw_rss_cos_lb_ctx[1] = INVALID_HW_RING_ID; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2446 | vnic->fw_l2_ctx_id = INVALID_HW_RING_ID; |
| 2447 | |
| 2448 | if (bp->vnic_info[i].rss_hash_key) { |
| 2449 | if (i == 0) |
| 2450 | prandom_bytes(vnic->rss_hash_key, |
| 2451 | HW_HASH_KEY_SIZE); |
| 2452 | else |
| 2453 | memcpy(vnic->rss_hash_key, |
| 2454 | bp->vnic_info[0].rss_hash_key, |
| 2455 | HW_HASH_KEY_SIZE); |
| 2456 | } |
| 2457 | } |
| 2458 | } |
| 2459 | |
| 2460 | static int bnxt_calc_nr_ring_pages(u32 ring_size, int desc_per_pg) |
| 2461 | { |
| 2462 | int pages; |
| 2463 | |
| 2464 | pages = ring_size / desc_per_pg; |
| 2465 | |
| 2466 | if (!pages) |
| 2467 | return 1; |
| 2468 | |
| 2469 | pages++; |
| 2470 | |
| 2471 | while (pages & (pages - 1)) |
| 2472 | pages++; |
| 2473 | |
| 2474 | return pages; |
| 2475 | } |
| 2476 | |
| 2477 | static void bnxt_set_tpa_flags(struct bnxt *bp) |
| 2478 | { |
| 2479 | bp->flags &= ~BNXT_FLAG_TPA; |
Michael Chan | 341138c | 2017-01-13 01:32:01 -0500 | [diff] [blame] | 2480 | if (bp->flags & BNXT_FLAG_NO_AGG_RINGS) |
| 2481 | return; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2482 | if (bp->dev->features & NETIF_F_LRO) |
| 2483 | bp->flags |= BNXT_FLAG_LRO; |
Michael Chan | 94758f8 | 2016-06-13 02:25:35 -0400 | [diff] [blame] | 2484 | if (bp->dev->features & NETIF_F_GRO) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2485 | bp->flags |= BNXT_FLAG_GRO; |
| 2486 | } |
| 2487 | |
| 2488 | /* bp->rx_ring_size, bp->tx_ring_size, dev->mtu, BNXT_FLAG_{G|L}RO flags must |
| 2489 | * be set on entry. |
| 2490 | */ |
| 2491 | void bnxt_set_ring_params(struct bnxt *bp) |
| 2492 | { |
| 2493 | u32 ring_size, rx_size, rx_space; |
| 2494 | u32 agg_factor = 0, agg_ring_size = 0; |
| 2495 | |
| 2496 | /* 8 for CRC and VLAN */ |
| 2497 | rx_size = SKB_DATA_ALIGN(bp->dev->mtu + ETH_HLEN + NET_IP_ALIGN + 8); |
| 2498 | |
| 2499 | rx_space = rx_size + NET_SKB_PAD + |
| 2500 | SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); |
| 2501 | |
| 2502 | bp->rx_copy_thresh = BNXT_RX_COPY_THRESH; |
| 2503 | ring_size = bp->rx_ring_size; |
| 2504 | bp->rx_agg_ring_size = 0; |
| 2505 | bp->rx_agg_nr_pages = 0; |
| 2506 | |
| 2507 | if (bp->flags & BNXT_FLAG_TPA) |
Michael Chan | 2839f28 | 2016-04-25 02:30:50 -0400 | [diff] [blame] | 2508 | agg_factor = min_t(u32, 4, 65536 / BNXT_RX_PAGE_SIZE); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2509 | |
| 2510 | bp->flags &= ~BNXT_FLAG_JUMBO; |
Michael Chan | bdbd1eb | 2016-12-29 12:13:43 -0500 | [diff] [blame] | 2511 | if (rx_space > PAGE_SIZE && !(bp->flags & BNXT_FLAG_NO_AGG_RINGS)) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2512 | u32 jumbo_factor; |
| 2513 | |
| 2514 | bp->flags |= BNXT_FLAG_JUMBO; |
| 2515 | jumbo_factor = PAGE_ALIGN(bp->dev->mtu - 40) >> PAGE_SHIFT; |
| 2516 | if (jumbo_factor > agg_factor) |
| 2517 | agg_factor = jumbo_factor; |
| 2518 | } |
| 2519 | agg_ring_size = ring_size * agg_factor; |
| 2520 | |
| 2521 | if (agg_ring_size) { |
| 2522 | bp->rx_agg_nr_pages = bnxt_calc_nr_ring_pages(agg_ring_size, |
| 2523 | RX_DESC_CNT); |
| 2524 | if (bp->rx_agg_nr_pages > MAX_RX_AGG_PAGES) { |
| 2525 | u32 tmp = agg_ring_size; |
| 2526 | |
| 2527 | bp->rx_agg_nr_pages = MAX_RX_AGG_PAGES; |
| 2528 | agg_ring_size = MAX_RX_AGG_PAGES * RX_DESC_CNT - 1; |
| 2529 | netdev_warn(bp->dev, "rx agg ring size %d reduced to %d.\n", |
| 2530 | tmp, agg_ring_size); |
| 2531 | } |
| 2532 | bp->rx_agg_ring_size = agg_ring_size; |
| 2533 | bp->rx_agg_ring_mask = (bp->rx_agg_nr_pages * RX_DESC_CNT) - 1; |
| 2534 | rx_size = SKB_DATA_ALIGN(BNXT_RX_COPY_THRESH + NET_IP_ALIGN); |
| 2535 | rx_space = rx_size + NET_SKB_PAD + |
| 2536 | SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); |
| 2537 | } |
| 2538 | |
| 2539 | bp->rx_buf_use_size = rx_size; |
| 2540 | bp->rx_buf_size = rx_space; |
| 2541 | |
| 2542 | bp->rx_nr_pages = bnxt_calc_nr_ring_pages(ring_size, RX_DESC_CNT); |
| 2543 | bp->rx_ring_mask = (bp->rx_nr_pages * RX_DESC_CNT) - 1; |
| 2544 | |
| 2545 | ring_size = bp->tx_ring_size; |
| 2546 | bp->tx_nr_pages = bnxt_calc_nr_ring_pages(ring_size, TX_DESC_CNT); |
| 2547 | bp->tx_ring_mask = (bp->tx_nr_pages * TX_DESC_CNT) - 1; |
| 2548 | |
| 2549 | ring_size = bp->rx_ring_size * (2 + agg_factor) + bp->tx_ring_size; |
| 2550 | bp->cp_ring_size = ring_size; |
| 2551 | |
| 2552 | bp->cp_nr_pages = bnxt_calc_nr_ring_pages(ring_size, CP_DESC_CNT); |
| 2553 | if (bp->cp_nr_pages > MAX_CP_PAGES) { |
| 2554 | bp->cp_nr_pages = MAX_CP_PAGES; |
| 2555 | bp->cp_ring_size = MAX_CP_PAGES * CP_DESC_CNT - 1; |
| 2556 | netdev_warn(bp->dev, "completion ring size %d reduced to %d.\n", |
| 2557 | ring_size, bp->cp_ring_size); |
| 2558 | } |
| 2559 | bp->cp_bit = bp->cp_nr_pages * CP_DESC_CNT; |
| 2560 | bp->cp_ring_mask = bp->cp_bit - 1; |
| 2561 | } |
| 2562 | |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 2563 | static int bnxt_set_rx_skb_mode(struct bnxt *bp) |
| 2564 | { |
Michael Chan | 745fc05 | 2017-02-06 16:55:34 -0500 | [diff] [blame] | 2565 | bp->rx_dir = DMA_FROM_DEVICE; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 2566 | bp->rx_skb_func = bnxt_rx_skb; |
| 2567 | return 0; |
| 2568 | } |
| 2569 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2570 | static void bnxt_free_vnic_attributes(struct bnxt *bp) |
| 2571 | { |
| 2572 | int i; |
| 2573 | struct bnxt_vnic_info *vnic; |
| 2574 | struct pci_dev *pdev = bp->pdev; |
| 2575 | |
| 2576 | if (!bp->vnic_info) |
| 2577 | return; |
| 2578 | |
| 2579 | for (i = 0; i < bp->nr_vnics; i++) { |
| 2580 | vnic = &bp->vnic_info[i]; |
| 2581 | |
| 2582 | kfree(vnic->fw_grp_ids); |
| 2583 | vnic->fw_grp_ids = NULL; |
| 2584 | |
| 2585 | kfree(vnic->uc_list); |
| 2586 | vnic->uc_list = NULL; |
| 2587 | |
| 2588 | if (vnic->mc_list) { |
| 2589 | dma_free_coherent(&pdev->dev, vnic->mc_list_size, |
| 2590 | vnic->mc_list, vnic->mc_list_mapping); |
| 2591 | vnic->mc_list = NULL; |
| 2592 | } |
| 2593 | |
| 2594 | if (vnic->rss_table) { |
| 2595 | dma_free_coherent(&pdev->dev, PAGE_SIZE, |
| 2596 | vnic->rss_table, |
| 2597 | vnic->rss_table_dma_addr); |
| 2598 | vnic->rss_table = NULL; |
| 2599 | } |
| 2600 | |
| 2601 | vnic->rss_hash_key = NULL; |
| 2602 | vnic->flags = 0; |
| 2603 | } |
| 2604 | } |
| 2605 | |
| 2606 | static int bnxt_alloc_vnic_attributes(struct bnxt *bp) |
| 2607 | { |
| 2608 | int i, rc = 0, size; |
| 2609 | struct bnxt_vnic_info *vnic; |
| 2610 | struct pci_dev *pdev = bp->pdev; |
| 2611 | int max_rings; |
| 2612 | |
| 2613 | for (i = 0; i < bp->nr_vnics; i++) { |
| 2614 | vnic = &bp->vnic_info[i]; |
| 2615 | |
| 2616 | if (vnic->flags & BNXT_VNIC_UCAST_FLAG) { |
| 2617 | int mem_size = (BNXT_MAX_UC_ADDRS - 1) * ETH_ALEN; |
| 2618 | |
| 2619 | if (mem_size > 0) { |
| 2620 | vnic->uc_list = kmalloc(mem_size, GFP_KERNEL); |
| 2621 | if (!vnic->uc_list) { |
| 2622 | rc = -ENOMEM; |
| 2623 | goto out; |
| 2624 | } |
| 2625 | } |
| 2626 | } |
| 2627 | |
| 2628 | if (vnic->flags & BNXT_VNIC_MCAST_FLAG) { |
| 2629 | vnic->mc_list_size = BNXT_MAX_MC_ADDRS * ETH_ALEN; |
| 2630 | vnic->mc_list = |
| 2631 | dma_alloc_coherent(&pdev->dev, |
| 2632 | vnic->mc_list_size, |
| 2633 | &vnic->mc_list_mapping, |
| 2634 | GFP_KERNEL); |
| 2635 | if (!vnic->mc_list) { |
| 2636 | rc = -ENOMEM; |
| 2637 | goto out; |
| 2638 | } |
| 2639 | } |
| 2640 | |
| 2641 | if (vnic->flags & BNXT_VNIC_RSS_FLAG) |
| 2642 | max_rings = bp->rx_nr_rings; |
| 2643 | else |
| 2644 | max_rings = 1; |
| 2645 | |
| 2646 | vnic->fw_grp_ids = kcalloc(max_rings, sizeof(u16), GFP_KERNEL); |
| 2647 | if (!vnic->fw_grp_ids) { |
| 2648 | rc = -ENOMEM; |
| 2649 | goto out; |
| 2650 | } |
| 2651 | |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 2652 | if ((bp->flags & BNXT_FLAG_NEW_RSS_CAP) && |
| 2653 | !(vnic->flags & BNXT_VNIC_RSS_FLAG)) |
| 2654 | continue; |
| 2655 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2656 | /* Allocate rss table and hash key */ |
| 2657 | vnic->rss_table = dma_alloc_coherent(&pdev->dev, PAGE_SIZE, |
| 2658 | &vnic->rss_table_dma_addr, |
| 2659 | GFP_KERNEL); |
| 2660 | if (!vnic->rss_table) { |
| 2661 | rc = -ENOMEM; |
| 2662 | goto out; |
| 2663 | } |
| 2664 | |
| 2665 | size = L1_CACHE_ALIGN(HW_HASH_INDEX_SIZE * sizeof(u16)); |
| 2666 | |
| 2667 | vnic->rss_hash_key = ((void *)vnic->rss_table) + size; |
| 2668 | vnic->rss_hash_key_dma_addr = vnic->rss_table_dma_addr + size; |
| 2669 | } |
| 2670 | return 0; |
| 2671 | |
| 2672 | out: |
| 2673 | return rc; |
| 2674 | } |
| 2675 | |
| 2676 | static void bnxt_free_hwrm_resources(struct bnxt *bp) |
| 2677 | { |
| 2678 | struct pci_dev *pdev = bp->pdev; |
| 2679 | |
| 2680 | dma_free_coherent(&pdev->dev, PAGE_SIZE, bp->hwrm_cmd_resp_addr, |
| 2681 | bp->hwrm_cmd_resp_dma_addr); |
| 2682 | |
| 2683 | bp->hwrm_cmd_resp_addr = NULL; |
| 2684 | if (bp->hwrm_dbg_resp_addr) { |
| 2685 | dma_free_coherent(&pdev->dev, HWRM_DBG_REG_BUF_SIZE, |
| 2686 | bp->hwrm_dbg_resp_addr, |
| 2687 | bp->hwrm_dbg_resp_dma_addr); |
| 2688 | |
| 2689 | bp->hwrm_dbg_resp_addr = NULL; |
| 2690 | } |
| 2691 | } |
| 2692 | |
| 2693 | static int bnxt_alloc_hwrm_resources(struct bnxt *bp) |
| 2694 | { |
| 2695 | struct pci_dev *pdev = bp->pdev; |
| 2696 | |
| 2697 | bp->hwrm_cmd_resp_addr = dma_alloc_coherent(&pdev->dev, PAGE_SIZE, |
| 2698 | &bp->hwrm_cmd_resp_dma_addr, |
| 2699 | GFP_KERNEL); |
| 2700 | if (!bp->hwrm_cmd_resp_addr) |
| 2701 | return -ENOMEM; |
| 2702 | bp->hwrm_dbg_resp_addr = dma_alloc_coherent(&pdev->dev, |
| 2703 | HWRM_DBG_REG_BUF_SIZE, |
| 2704 | &bp->hwrm_dbg_resp_dma_addr, |
| 2705 | GFP_KERNEL); |
| 2706 | if (!bp->hwrm_dbg_resp_addr) |
| 2707 | netdev_warn(bp->dev, "fail to alloc debug register dma mem\n"); |
| 2708 | |
| 2709 | return 0; |
| 2710 | } |
| 2711 | |
| 2712 | static void bnxt_free_stats(struct bnxt *bp) |
| 2713 | { |
| 2714 | u32 size, i; |
| 2715 | struct pci_dev *pdev = bp->pdev; |
| 2716 | |
Michael Chan | 3bdf56c | 2016-03-07 15:38:45 -0500 | [diff] [blame] | 2717 | if (bp->hw_rx_port_stats) { |
| 2718 | dma_free_coherent(&pdev->dev, bp->hw_port_stats_size, |
| 2719 | bp->hw_rx_port_stats, |
| 2720 | bp->hw_rx_port_stats_map); |
| 2721 | bp->hw_rx_port_stats = NULL; |
| 2722 | bp->flags &= ~BNXT_FLAG_PORT_STATS; |
| 2723 | } |
| 2724 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2725 | if (!bp->bnapi) |
| 2726 | return; |
| 2727 | |
| 2728 | size = sizeof(struct ctx_hw_stats); |
| 2729 | |
| 2730 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 2731 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 2732 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 2733 | |
| 2734 | if (cpr->hw_stats) { |
| 2735 | dma_free_coherent(&pdev->dev, size, cpr->hw_stats, |
| 2736 | cpr->hw_stats_map); |
| 2737 | cpr->hw_stats = NULL; |
| 2738 | } |
| 2739 | } |
| 2740 | } |
| 2741 | |
| 2742 | static int bnxt_alloc_stats(struct bnxt *bp) |
| 2743 | { |
| 2744 | u32 size, i; |
| 2745 | struct pci_dev *pdev = bp->pdev; |
| 2746 | |
| 2747 | size = sizeof(struct ctx_hw_stats); |
| 2748 | |
| 2749 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 2750 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 2751 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 2752 | |
| 2753 | cpr->hw_stats = dma_alloc_coherent(&pdev->dev, size, |
| 2754 | &cpr->hw_stats_map, |
| 2755 | GFP_KERNEL); |
| 2756 | if (!cpr->hw_stats) |
| 2757 | return -ENOMEM; |
| 2758 | |
| 2759 | cpr->hw_stats_ctx_id = INVALID_STATS_CTX_ID; |
| 2760 | } |
Michael Chan | 3bdf56c | 2016-03-07 15:38:45 -0500 | [diff] [blame] | 2761 | |
Prashant Sreedharan | 3e8060f | 2016-07-18 07:15:20 -0400 | [diff] [blame] | 2762 | if (BNXT_PF(bp) && bp->chip_num != CHIP_NUM_58700) { |
Michael Chan | 3bdf56c | 2016-03-07 15:38:45 -0500 | [diff] [blame] | 2763 | bp->hw_port_stats_size = sizeof(struct rx_port_stats) + |
| 2764 | sizeof(struct tx_port_stats) + 1024; |
| 2765 | |
| 2766 | bp->hw_rx_port_stats = |
| 2767 | dma_alloc_coherent(&pdev->dev, bp->hw_port_stats_size, |
| 2768 | &bp->hw_rx_port_stats_map, |
| 2769 | GFP_KERNEL); |
| 2770 | if (!bp->hw_rx_port_stats) |
| 2771 | return -ENOMEM; |
| 2772 | |
| 2773 | bp->hw_tx_port_stats = (void *)(bp->hw_rx_port_stats + 1) + |
| 2774 | 512; |
| 2775 | bp->hw_tx_port_stats_map = bp->hw_rx_port_stats_map + |
| 2776 | sizeof(struct rx_port_stats) + 512; |
| 2777 | bp->flags |= BNXT_FLAG_PORT_STATS; |
| 2778 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2779 | return 0; |
| 2780 | } |
| 2781 | |
| 2782 | static void bnxt_clear_ring_indices(struct bnxt *bp) |
| 2783 | { |
| 2784 | int i; |
| 2785 | |
| 2786 | if (!bp->bnapi) |
| 2787 | return; |
| 2788 | |
| 2789 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 2790 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 2791 | struct bnxt_cp_ring_info *cpr; |
| 2792 | struct bnxt_rx_ring_info *rxr; |
| 2793 | struct bnxt_tx_ring_info *txr; |
| 2794 | |
| 2795 | if (!bnapi) |
| 2796 | continue; |
| 2797 | |
| 2798 | cpr = &bnapi->cp_ring; |
| 2799 | cpr->cp_raw_cons = 0; |
| 2800 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2801 | txr = bnapi->tx_ring; |
Michael Chan | 3b2b7d9 | 2016-01-02 23:45:00 -0500 | [diff] [blame] | 2802 | if (txr) { |
| 2803 | txr->tx_prod = 0; |
| 2804 | txr->tx_cons = 0; |
| 2805 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2806 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2807 | rxr = bnapi->rx_ring; |
Michael Chan | 3b2b7d9 | 2016-01-02 23:45:00 -0500 | [diff] [blame] | 2808 | if (rxr) { |
| 2809 | rxr->rx_prod = 0; |
| 2810 | rxr->rx_agg_prod = 0; |
| 2811 | rxr->rx_sw_agg_prod = 0; |
Michael Chan | 376a5b8 | 2016-05-10 19:17:59 -0400 | [diff] [blame] | 2812 | rxr->rx_next_cons = 0; |
Michael Chan | 3b2b7d9 | 2016-01-02 23:45:00 -0500 | [diff] [blame] | 2813 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2814 | } |
| 2815 | } |
| 2816 | |
| 2817 | static void bnxt_free_ntp_fltrs(struct bnxt *bp, bool irq_reinit) |
| 2818 | { |
| 2819 | #ifdef CONFIG_RFS_ACCEL |
| 2820 | int i; |
| 2821 | |
| 2822 | /* Under rtnl_lock and all our NAPIs have been disabled. It's |
| 2823 | * safe to delete the hash table. |
| 2824 | */ |
| 2825 | for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) { |
| 2826 | struct hlist_head *head; |
| 2827 | struct hlist_node *tmp; |
| 2828 | struct bnxt_ntuple_filter *fltr; |
| 2829 | |
| 2830 | head = &bp->ntp_fltr_hash_tbl[i]; |
| 2831 | hlist_for_each_entry_safe(fltr, tmp, head, hash) { |
| 2832 | hlist_del(&fltr->hash); |
| 2833 | kfree(fltr); |
| 2834 | } |
| 2835 | } |
| 2836 | if (irq_reinit) { |
| 2837 | kfree(bp->ntp_fltr_bmap); |
| 2838 | bp->ntp_fltr_bmap = NULL; |
| 2839 | } |
| 2840 | bp->ntp_fltr_count = 0; |
| 2841 | #endif |
| 2842 | } |
| 2843 | |
| 2844 | static int bnxt_alloc_ntp_fltrs(struct bnxt *bp) |
| 2845 | { |
| 2846 | #ifdef CONFIG_RFS_ACCEL |
| 2847 | int i, rc = 0; |
| 2848 | |
| 2849 | if (!(bp->flags & BNXT_FLAG_RFS)) |
| 2850 | return 0; |
| 2851 | |
| 2852 | for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) |
| 2853 | INIT_HLIST_HEAD(&bp->ntp_fltr_hash_tbl[i]); |
| 2854 | |
| 2855 | bp->ntp_fltr_count = 0; |
| 2856 | bp->ntp_fltr_bmap = kzalloc(BITS_TO_LONGS(BNXT_NTP_FLTR_MAX_FLTR), |
| 2857 | GFP_KERNEL); |
| 2858 | |
| 2859 | if (!bp->ntp_fltr_bmap) |
| 2860 | rc = -ENOMEM; |
| 2861 | |
| 2862 | return rc; |
| 2863 | #else |
| 2864 | return 0; |
| 2865 | #endif |
| 2866 | } |
| 2867 | |
| 2868 | static void bnxt_free_mem(struct bnxt *bp, bool irq_re_init) |
| 2869 | { |
| 2870 | bnxt_free_vnic_attributes(bp); |
| 2871 | bnxt_free_tx_rings(bp); |
| 2872 | bnxt_free_rx_rings(bp); |
| 2873 | bnxt_free_cp_rings(bp); |
| 2874 | bnxt_free_ntp_fltrs(bp, irq_re_init); |
| 2875 | if (irq_re_init) { |
| 2876 | bnxt_free_stats(bp); |
| 2877 | bnxt_free_ring_grps(bp); |
| 2878 | bnxt_free_vnics(bp); |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2879 | kfree(bp->tx_ring); |
| 2880 | bp->tx_ring = NULL; |
| 2881 | kfree(bp->rx_ring); |
| 2882 | bp->rx_ring = NULL; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2883 | kfree(bp->bnapi); |
| 2884 | bp->bnapi = NULL; |
| 2885 | } else { |
| 2886 | bnxt_clear_ring_indices(bp); |
| 2887 | } |
| 2888 | } |
| 2889 | |
| 2890 | static int bnxt_alloc_mem(struct bnxt *bp, bool irq_re_init) |
| 2891 | { |
Michael Chan | 01657bc | 2016-01-02 23:45:03 -0500 | [diff] [blame] | 2892 | int i, j, rc, size, arr_size; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2893 | void *bnapi; |
| 2894 | |
| 2895 | if (irq_re_init) { |
| 2896 | /* Allocate bnapi mem pointer array and mem block for |
| 2897 | * all queues |
| 2898 | */ |
| 2899 | arr_size = L1_CACHE_ALIGN(sizeof(struct bnxt_napi *) * |
| 2900 | bp->cp_nr_rings); |
| 2901 | size = L1_CACHE_ALIGN(sizeof(struct bnxt_napi)); |
| 2902 | bnapi = kzalloc(arr_size + size * bp->cp_nr_rings, GFP_KERNEL); |
| 2903 | if (!bnapi) |
| 2904 | return -ENOMEM; |
| 2905 | |
| 2906 | bp->bnapi = bnapi; |
| 2907 | bnapi += arr_size; |
| 2908 | for (i = 0; i < bp->cp_nr_rings; i++, bnapi += size) { |
| 2909 | bp->bnapi[i] = bnapi; |
| 2910 | bp->bnapi[i]->index = i; |
| 2911 | bp->bnapi[i]->bp = bp; |
| 2912 | } |
| 2913 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2914 | bp->rx_ring = kcalloc(bp->rx_nr_rings, |
| 2915 | sizeof(struct bnxt_rx_ring_info), |
| 2916 | GFP_KERNEL); |
| 2917 | if (!bp->rx_ring) |
| 2918 | return -ENOMEM; |
| 2919 | |
| 2920 | for (i = 0; i < bp->rx_nr_rings; i++) { |
| 2921 | bp->rx_ring[i].bnapi = bp->bnapi[i]; |
| 2922 | bp->bnapi[i]->rx_ring = &bp->rx_ring[i]; |
| 2923 | } |
| 2924 | |
| 2925 | bp->tx_ring = kcalloc(bp->tx_nr_rings, |
| 2926 | sizeof(struct bnxt_tx_ring_info), |
| 2927 | GFP_KERNEL); |
| 2928 | if (!bp->tx_ring) |
| 2929 | return -ENOMEM; |
| 2930 | |
Michael Chan | 01657bc | 2016-01-02 23:45:03 -0500 | [diff] [blame] | 2931 | if (bp->flags & BNXT_FLAG_SHARED_RINGS) |
| 2932 | j = 0; |
| 2933 | else |
| 2934 | j = bp->rx_nr_rings; |
| 2935 | |
| 2936 | for (i = 0; i < bp->tx_nr_rings; i++, j++) { |
| 2937 | bp->tx_ring[i].bnapi = bp->bnapi[j]; |
| 2938 | bp->bnapi[j]->tx_ring = &bp->tx_ring[i]; |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2939 | } |
| 2940 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2941 | rc = bnxt_alloc_stats(bp); |
| 2942 | if (rc) |
| 2943 | goto alloc_mem_err; |
| 2944 | |
| 2945 | rc = bnxt_alloc_ntp_fltrs(bp); |
| 2946 | if (rc) |
| 2947 | goto alloc_mem_err; |
| 2948 | |
| 2949 | rc = bnxt_alloc_vnics(bp); |
| 2950 | if (rc) |
| 2951 | goto alloc_mem_err; |
| 2952 | } |
| 2953 | |
| 2954 | bnxt_init_ring_struct(bp); |
| 2955 | |
| 2956 | rc = bnxt_alloc_rx_rings(bp); |
| 2957 | if (rc) |
| 2958 | goto alloc_mem_err; |
| 2959 | |
| 2960 | rc = bnxt_alloc_tx_rings(bp); |
| 2961 | if (rc) |
| 2962 | goto alloc_mem_err; |
| 2963 | |
| 2964 | rc = bnxt_alloc_cp_rings(bp); |
| 2965 | if (rc) |
| 2966 | goto alloc_mem_err; |
| 2967 | |
| 2968 | bp->vnic_info[0].flags |= BNXT_VNIC_RSS_FLAG | BNXT_VNIC_MCAST_FLAG | |
| 2969 | BNXT_VNIC_UCAST_FLAG; |
| 2970 | rc = bnxt_alloc_vnic_attributes(bp); |
| 2971 | if (rc) |
| 2972 | goto alloc_mem_err; |
| 2973 | return 0; |
| 2974 | |
| 2975 | alloc_mem_err: |
| 2976 | bnxt_free_mem(bp, true); |
| 2977 | return rc; |
| 2978 | } |
| 2979 | |
Michael Chan | 9d8bc09 | 2016-12-29 12:13:33 -0500 | [diff] [blame] | 2980 | static void bnxt_disable_int(struct bnxt *bp) |
| 2981 | { |
| 2982 | int i; |
| 2983 | |
| 2984 | if (!bp->bnapi) |
| 2985 | return; |
| 2986 | |
| 2987 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 2988 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 2989 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 2990 | |
| 2991 | BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons); |
| 2992 | } |
| 2993 | } |
| 2994 | |
| 2995 | static void bnxt_disable_int_sync(struct bnxt *bp) |
| 2996 | { |
| 2997 | int i; |
| 2998 | |
| 2999 | atomic_inc(&bp->intr_sem); |
| 3000 | |
| 3001 | bnxt_disable_int(bp); |
| 3002 | for (i = 0; i < bp->cp_nr_rings; i++) |
| 3003 | synchronize_irq(bp->irq_tbl[i].vector); |
| 3004 | } |
| 3005 | |
| 3006 | static void bnxt_enable_int(struct bnxt *bp) |
| 3007 | { |
| 3008 | int i; |
| 3009 | |
| 3010 | atomic_set(&bp->intr_sem, 0); |
| 3011 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 3012 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 3013 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 3014 | |
| 3015 | BNXT_CP_DB_REARM(cpr->cp_doorbell, cpr->cp_raw_cons); |
| 3016 | } |
| 3017 | } |
| 3018 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3019 | void bnxt_hwrm_cmd_hdr_init(struct bnxt *bp, void *request, u16 req_type, |
| 3020 | u16 cmpl_ring, u16 target_id) |
| 3021 | { |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3022 | struct input *req = request; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3023 | |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3024 | req->req_type = cpu_to_le16(req_type); |
| 3025 | req->cmpl_ring = cpu_to_le16(cmpl_ring); |
| 3026 | req->target_id = cpu_to_le16(target_id); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3027 | req->resp_addr = cpu_to_le64(bp->hwrm_cmd_resp_dma_addr); |
| 3028 | } |
| 3029 | |
Michael Chan | fbfbc48 | 2016-02-26 04:00:07 -0500 | [diff] [blame] | 3030 | static int bnxt_hwrm_do_send_msg(struct bnxt *bp, void *msg, u32 msg_len, |
| 3031 | int timeout, bool silent) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3032 | { |
Michael Chan | a11fa2b | 2016-05-15 03:04:47 -0400 | [diff] [blame] | 3033 | int i, intr_process, rc, tmo_count; |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3034 | struct input *req = msg; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3035 | u32 *data = msg; |
| 3036 | __le32 *resp_len, *valid; |
| 3037 | u16 cp_ring_id, len = 0; |
| 3038 | struct hwrm_err_output *resp = bp->hwrm_cmd_resp_addr; |
| 3039 | |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3040 | req->seq_id = cpu_to_le16(bp->hwrm_cmd_seq++); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3041 | memset(resp, 0, PAGE_SIZE); |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3042 | cp_ring_id = le16_to_cpu(req->cmpl_ring); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3043 | intr_process = (cp_ring_id == INVALID_HW_RING_ID) ? 0 : 1; |
| 3044 | |
| 3045 | /* Write request msg to hwrm channel */ |
| 3046 | __iowrite32_copy(bp->bar0, data, msg_len / 4); |
| 3047 | |
Michael Chan | e6ef269 | 2016-03-28 19:46:05 -0400 | [diff] [blame] | 3048 | for (i = msg_len; i < BNXT_HWRM_MAX_REQ_LEN; i += 4) |
Michael Chan | d79979a | 2016-01-07 19:56:57 -0500 | [diff] [blame] | 3049 | writel(0, bp->bar0 + i); |
| 3050 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3051 | /* currently supports only one outstanding message */ |
| 3052 | if (intr_process) |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3053 | bp->hwrm_intr_seq_id = le16_to_cpu(req->seq_id); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3054 | |
| 3055 | /* Ring channel doorbell */ |
| 3056 | writel(1, bp->bar0 + 0x100); |
| 3057 | |
Michael Chan | ff4fe81 | 2016-02-26 04:00:04 -0500 | [diff] [blame] | 3058 | if (!timeout) |
| 3059 | timeout = DFLT_HWRM_CMD_TIMEOUT; |
| 3060 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3061 | i = 0; |
Michael Chan | a11fa2b | 2016-05-15 03:04:47 -0400 | [diff] [blame] | 3062 | tmo_count = timeout * 40; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3063 | if (intr_process) { |
| 3064 | /* Wait until hwrm response cmpl interrupt is processed */ |
| 3065 | while (bp->hwrm_intr_seq_id != HWRM_SEQ_ID_INVALID && |
Michael Chan | a11fa2b | 2016-05-15 03:04:47 -0400 | [diff] [blame] | 3066 | i++ < tmo_count) { |
| 3067 | usleep_range(25, 40); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3068 | } |
| 3069 | |
| 3070 | if (bp->hwrm_intr_seq_id != HWRM_SEQ_ID_INVALID) { |
| 3071 | netdev_err(bp->dev, "Resp cmpl intr err msg: 0x%x\n", |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3072 | le16_to_cpu(req->req_type)); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3073 | return -1; |
| 3074 | } |
| 3075 | } else { |
| 3076 | /* Check if response len is updated */ |
| 3077 | resp_len = bp->hwrm_cmd_resp_addr + HWRM_RESP_LEN_OFFSET; |
Michael Chan | a11fa2b | 2016-05-15 03:04:47 -0400 | [diff] [blame] | 3078 | for (i = 0; i < tmo_count; i++) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3079 | len = (le32_to_cpu(*resp_len) & HWRM_RESP_LEN_MASK) >> |
| 3080 | HWRM_RESP_LEN_SFT; |
| 3081 | if (len) |
| 3082 | break; |
Michael Chan | a11fa2b | 2016-05-15 03:04:47 -0400 | [diff] [blame] | 3083 | usleep_range(25, 40); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3084 | } |
| 3085 | |
Michael Chan | a11fa2b | 2016-05-15 03:04:47 -0400 | [diff] [blame] | 3086 | if (i >= tmo_count) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3087 | netdev_err(bp->dev, "Error (timeout: %d) msg {0x%x 0x%x} len:%d\n", |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3088 | timeout, le16_to_cpu(req->req_type), |
Michael Chan | 8578d6c | 2016-05-15 03:04:48 -0400 | [diff] [blame] | 3089 | le16_to_cpu(req->seq_id), len); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3090 | return -1; |
| 3091 | } |
| 3092 | |
| 3093 | /* Last word of resp contains valid bit */ |
| 3094 | valid = bp->hwrm_cmd_resp_addr + len - 4; |
Michael Chan | a11fa2b | 2016-05-15 03:04:47 -0400 | [diff] [blame] | 3095 | for (i = 0; i < 5; i++) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3096 | if (le32_to_cpu(*valid) & HWRM_RESP_VALID_MASK) |
| 3097 | break; |
Michael Chan | a11fa2b | 2016-05-15 03:04:47 -0400 | [diff] [blame] | 3098 | udelay(1); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3099 | } |
| 3100 | |
Michael Chan | a11fa2b | 2016-05-15 03:04:47 -0400 | [diff] [blame] | 3101 | if (i >= 5) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3102 | netdev_err(bp->dev, "Error (timeout: %d) msg {0x%x 0x%x} len:%d v:%d\n", |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3103 | timeout, le16_to_cpu(req->req_type), |
| 3104 | le16_to_cpu(req->seq_id), len, *valid); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3105 | return -1; |
| 3106 | } |
| 3107 | } |
| 3108 | |
| 3109 | rc = le16_to_cpu(resp->error_code); |
Michael Chan | fbfbc48 | 2016-02-26 04:00:07 -0500 | [diff] [blame] | 3110 | if (rc && !silent) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3111 | netdev_err(bp->dev, "hwrm req_type 0x%x seq id 0x%x error 0x%x\n", |
| 3112 | le16_to_cpu(resp->req_type), |
| 3113 | le16_to_cpu(resp->seq_id), rc); |
Michael Chan | fbfbc48 | 2016-02-26 04:00:07 -0500 | [diff] [blame] | 3114 | return rc; |
| 3115 | } |
| 3116 | |
| 3117 | int _hwrm_send_message(struct bnxt *bp, void *msg, u32 msg_len, int timeout) |
| 3118 | { |
| 3119 | return bnxt_hwrm_do_send_msg(bp, msg, msg_len, timeout, false); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3120 | } |
| 3121 | |
| 3122 | int hwrm_send_message(struct bnxt *bp, void *msg, u32 msg_len, int timeout) |
| 3123 | { |
| 3124 | int rc; |
| 3125 | |
| 3126 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3127 | rc = _hwrm_send_message(bp, msg, msg_len, timeout); |
| 3128 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3129 | return rc; |
| 3130 | } |
| 3131 | |
Michael Chan | 90e20921 | 2016-02-26 04:00:08 -0500 | [diff] [blame] | 3132 | int hwrm_send_message_silent(struct bnxt *bp, void *msg, u32 msg_len, |
| 3133 | int timeout) |
| 3134 | { |
| 3135 | int rc; |
| 3136 | |
| 3137 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3138 | rc = bnxt_hwrm_do_send_msg(bp, msg, msg_len, timeout, true); |
| 3139 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3140 | return rc; |
| 3141 | } |
| 3142 | |
Michael Chan | a1653b1 | 2016-12-07 00:26:20 -0500 | [diff] [blame] | 3143 | int bnxt_hwrm_func_rgtr_async_events(struct bnxt *bp, unsigned long *bmap, |
| 3144 | int bmap_size) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3145 | { |
| 3146 | struct hwrm_func_drv_rgtr_input req = {0}; |
Michael Chan | 25be862 | 2016-04-05 14:09:00 -0400 | [diff] [blame] | 3147 | DECLARE_BITMAP(async_events_bmap, 256); |
| 3148 | u32 *events = (u32 *)async_events_bmap; |
Michael Chan | a1653b1 | 2016-12-07 00:26:20 -0500 | [diff] [blame] | 3149 | int i; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3150 | |
| 3151 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_RGTR, -1, -1); |
| 3152 | |
| 3153 | req.enables = |
Michael Chan | a1653b1 | 2016-12-07 00:26:20 -0500 | [diff] [blame] | 3154 | cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_ASYNC_EVENT_FWD); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3155 | |
Michael Chan | 25be862 | 2016-04-05 14:09:00 -0400 | [diff] [blame] | 3156 | memset(async_events_bmap, 0, sizeof(async_events_bmap)); |
| 3157 | for (i = 0; i < ARRAY_SIZE(bnxt_async_events_arr); i++) |
| 3158 | __set_bit(bnxt_async_events_arr[i], async_events_bmap); |
| 3159 | |
Michael Chan | a1653b1 | 2016-12-07 00:26:20 -0500 | [diff] [blame] | 3160 | if (bmap && bmap_size) { |
| 3161 | for (i = 0; i < bmap_size; i++) { |
| 3162 | if (test_bit(i, bmap)) |
| 3163 | __set_bit(i, async_events_bmap); |
| 3164 | } |
| 3165 | } |
| 3166 | |
Michael Chan | 25be862 | 2016-04-05 14:09:00 -0400 | [diff] [blame] | 3167 | for (i = 0; i < 8; i++) |
| 3168 | req.async_event_fwd[i] |= cpu_to_le32(events[i]); |
| 3169 | |
Michael Chan | a1653b1 | 2016-12-07 00:26:20 -0500 | [diff] [blame] | 3170 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3171 | } |
| 3172 | |
| 3173 | static int bnxt_hwrm_func_drv_rgtr(struct bnxt *bp) |
| 3174 | { |
| 3175 | struct hwrm_func_drv_rgtr_input req = {0}; |
| 3176 | |
| 3177 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_RGTR, -1, -1); |
| 3178 | |
| 3179 | req.enables = |
| 3180 | cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_OS_TYPE | |
| 3181 | FUNC_DRV_RGTR_REQ_ENABLES_VER); |
| 3182 | |
Michael Chan | 11f15ed | 2016-04-05 14:08:55 -0400 | [diff] [blame] | 3183 | req.os_type = cpu_to_le16(FUNC_DRV_RGTR_REQ_OS_TYPE_LINUX); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3184 | req.ver_maj = DRV_VER_MAJ; |
| 3185 | req.ver_min = DRV_VER_MIN; |
| 3186 | req.ver_upd = DRV_VER_UPD; |
| 3187 | |
| 3188 | if (BNXT_PF(bp)) { |
Michael Chan | de68f5de | 2015-12-09 19:35:41 -0500 | [diff] [blame] | 3189 | DECLARE_BITMAP(vf_req_snif_bmap, 256); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3190 | u32 *data = (u32 *)vf_req_snif_bmap; |
Michael Chan | a1653b1 | 2016-12-07 00:26:20 -0500 | [diff] [blame] | 3191 | int i; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3192 | |
Michael Chan | de68f5de | 2015-12-09 19:35:41 -0500 | [diff] [blame] | 3193 | memset(vf_req_snif_bmap, 0, sizeof(vf_req_snif_bmap)); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3194 | for (i = 0; i < ARRAY_SIZE(bnxt_vf_req_snif); i++) |
| 3195 | __set_bit(bnxt_vf_req_snif[i], vf_req_snif_bmap); |
| 3196 | |
Michael Chan | de68f5de | 2015-12-09 19:35:41 -0500 | [diff] [blame] | 3197 | for (i = 0; i < 8; i++) |
| 3198 | req.vf_req_fwd[i] = cpu_to_le32(data[i]); |
| 3199 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3200 | req.enables |= |
| 3201 | cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_VF_REQ_FWD); |
| 3202 | } |
| 3203 | |
| 3204 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3205 | } |
| 3206 | |
Jeffrey Huang | be58a0d | 2015-12-27 18:19:18 -0500 | [diff] [blame] | 3207 | static int bnxt_hwrm_func_drv_unrgtr(struct bnxt *bp) |
| 3208 | { |
| 3209 | struct hwrm_func_drv_unrgtr_input req = {0}; |
| 3210 | |
| 3211 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_UNRGTR, -1, -1); |
| 3212 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3213 | } |
| 3214 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3215 | static int bnxt_hwrm_tunnel_dst_port_free(struct bnxt *bp, u8 tunnel_type) |
| 3216 | { |
| 3217 | u32 rc = 0; |
| 3218 | struct hwrm_tunnel_dst_port_free_input req = {0}; |
| 3219 | |
| 3220 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_TUNNEL_DST_PORT_FREE, -1, -1); |
| 3221 | req.tunnel_type = tunnel_type; |
| 3222 | |
| 3223 | switch (tunnel_type) { |
| 3224 | case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN: |
| 3225 | req.tunnel_dst_port_id = bp->vxlan_fw_dst_port_id; |
| 3226 | break; |
| 3227 | case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE: |
| 3228 | req.tunnel_dst_port_id = bp->nge_fw_dst_port_id; |
| 3229 | break; |
| 3230 | default: |
| 3231 | break; |
| 3232 | } |
| 3233 | |
| 3234 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3235 | if (rc) |
| 3236 | netdev_err(bp->dev, "hwrm_tunnel_dst_port_free failed. rc:%d\n", |
| 3237 | rc); |
| 3238 | return rc; |
| 3239 | } |
| 3240 | |
| 3241 | static int bnxt_hwrm_tunnel_dst_port_alloc(struct bnxt *bp, __be16 port, |
| 3242 | u8 tunnel_type) |
| 3243 | { |
| 3244 | u32 rc = 0; |
| 3245 | struct hwrm_tunnel_dst_port_alloc_input req = {0}; |
| 3246 | struct hwrm_tunnel_dst_port_alloc_output *resp = bp->hwrm_cmd_resp_addr; |
| 3247 | |
| 3248 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_TUNNEL_DST_PORT_ALLOC, -1, -1); |
| 3249 | |
| 3250 | req.tunnel_type = tunnel_type; |
| 3251 | req.tunnel_dst_port_val = port; |
| 3252 | |
| 3253 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3254 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3255 | if (rc) { |
| 3256 | netdev_err(bp->dev, "hwrm_tunnel_dst_port_alloc failed. rc:%d\n", |
| 3257 | rc); |
| 3258 | goto err_out; |
| 3259 | } |
| 3260 | |
Christophe Jaillet | 57aac71 | 2016-11-22 06:14:40 +0100 | [diff] [blame] | 3261 | switch (tunnel_type) { |
| 3262 | case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_VXLAN: |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3263 | bp->vxlan_fw_dst_port_id = resp->tunnel_dst_port_id; |
Christophe Jaillet | 57aac71 | 2016-11-22 06:14:40 +0100 | [diff] [blame] | 3264 | break; |
| 3265 | case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_GENEVE: |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3266 | bp->nge_fw_dst_port_id = resp->tunnel_dst_port_id; |
Christophe Jaillet | 57aac71 | 2016-11-22 06:14:40 +0100 | [diff] [blame] | 3267 | break; |
| 3268 | default: |
| 3269 | break; |
| 3270 | } |
| 3271 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3272 | err_out: |
| 3273 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3274 | return rc; |
| 3275 | } |
| 3276 | |
| 3277 | static int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt *bp, u16 vnic_id) |
| 3278 | { |
| 3279 | struct hwrm_cfa_l2_set_rx_mask_input req = {0}; |
| 3280 | struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id]; |
| 3281 | |
| 3282 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_L2_SET_RX_MASK, -1, -1); |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 3283 | req.vnic_id = cpu_to_le32(vnic->fw_vnic_id); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3284 | |
| 3285 | req.num_mc_entries = cpu_to_le32(vnic->mc_list_count); |
| 3286 | req.mc_tbl_addr = cpu_to_le64(vnic->mc_list_mapping); |
| 3287 | req.mask = cpu_to_le32(vnic->rx_mask); |
| 3288 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3289 | } |
| 3290 | |
| 3291 | #ifdef CONFIG_RFS_ACCEL |
| 3292 | static int bnxt_hwrm_cfa_ntuple_filter_free(struct bnxt *bp, |
| 3293 | struct bnxt_ntuple_filter *fltr) |
| 3294 | { |
| 3295 | struct hwrm_cfa_ntuple_filter_free_input req = {0}; |
| 3296 | |
| 3297 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_NTUPLE_FILTER_FREE, -1, -1); |
| 3298 | req.ntuple_filter_id = fltr->filter_id; |
| 3299 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3300 | } |
| 3301 | |
| 3302 | #define BNXT_NTP_FLTR_FLAGS \ |
| 3303 | (CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_L2_FILTER_ID | \ |
| 3304 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_ETHERTYPE | \ |
| 3305 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_MACADDR | \ |
| 3306 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IPADDR_TYPE | \ |
| 3307 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR | \ |
| 3308 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR_MASK | \ |
| 3309 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR | \ |
| 3310 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR_MASK | \ |
| 3311 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IP_PROTOCOL | \ |
| 3312 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT | \ |
| 3313 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT_MASK | \ |
| 3314 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT | \ |
| 3315 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT_MASK | \ |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 3316 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_ID) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3317 | |
| 3318 | static int bnxt_hwrm_cfa_ntuple_filter_alloc(struct bnxt *bp, |
| 3319 | struct bnxt_ntuple_filter *fltr) |
| 3320 | { |
| 3321 | int rc = 0; |
| 3322 | struct hwrm_cfa_ntuple_filter_alloc_input req = {0}; |
| 3323 | struct hwrm_cfa_ntuple_filter_alloc_output *resp = |
| 3324 | bp->hwrm_cmd_resp_addr; |
| 3325 | struct flow_keys *keys = &fltr->fkeys; |
| 3326 | struct bnxt_vnic_info *vnic = &bp->vnic_info[fltr->rxq + 1]; |
| 3327 | |
| 3328 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_NTUPLE_FILTER_ALLOC, -1, -1); |
Michael Chan | a54c4d7 | 2016-07-25 12:33:35 -0400 | [diff] [blame] | 3329 | req.l2_filter_id = bp->vnic_info[0].fw_l2_filter_id[fltr->l2_fltr_idx]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3330 | |
| 3331 | req.enables = cpu_to_le32(BNXT_NTP_FLTR_FLAGS); |
| 3332 | |
| 3333 | req.ethertype = htons(ETH_P_IP); |
| 3334 | memcpy(req.src_macaddr, fltr->src_mac_addr, ETH_ALEN); |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 3335 | req.ip_addr_type = CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV4; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3336 | req.ip_protocol = keys->basic.ip_proto; |
| 3337 | |
Michael Chan | dda0e74 | 2016-12-29 12:13:40 -0500 | [diff] [blame] | 3338 | if (keys->basic.n_proto == htons(ETH_P_IPV6)) { |
| 3339 | int i; |
| 3340 | |
| 3341 | req.ethertype = htons(ETH_P_IPV6); |
| 3342 | req.ip_addr_type = |
| 3343 | CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV6; |
| 3344 | *(struct in6_addr *)&req.src_ipaddr[0] = |
| 3345 | keys->addrs.v6addrs.src; |
| 3346 | *(struct in6_addr *)&req.dst_ipaddr[0] = |
| 3347 | keys->addrs.v6addrs.dst; |
| 3348 | for (i = 0; i < 4; i++) { |
| 3349 | req.src_ipaddr_mask[i] = cpu_to_be32(0xffffffff); |
| 3350 | req.dst_ipaddr_mask[i] = cpu_to_be32(0xffffffff); |
| 3351 | } |
| 3352 | } else { |
| 3353 | req.src_ipaddr[0] = keys->addrs.v4addrs.src; |
| 3354 | req.src_ipaddr_mask[0] = cpu_to_be32(0xffffffff); |
| 3355 | req.dst_ipaddr[0] = keys->addrs.v4addrs.dst; |
| 3356 | req.dst_ipaddr_mask[0] = cpu_to_be32(0xffffffff); |
| 3357 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3358 | |
| 3359 | req.src_port = keys->ports.src; |
| 3360 | req.src_port_mask = cpu_to_be16(0xffff); |
| 3361 | req.dst_port = keys->ports.dst; |
| 3362 | req.dst_port_mask = cpu_to_be16(0xffff); |
| 3363 | |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 3364 | req.dst_id = cpu_to_le16(vnic->fw_vnic_id); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3365 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3366 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3367 | if (!rc) |
| 3368 | fltr->filter_id = resp->ntuple_filter_id; |
| 3369 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3370 | return rc; |
| 3371 | } |
| 3372 | #endif |
| 3373 | |
| 3374 | static int bnxt_hwrm_set_vnic_filter(struct bnxt *bp, u16 vnic_id, u16 idx, |
| 3375 | u8 *mac_addr) |
| 3376 | { |
| 3377 | u32 rc = 0; |
| 3378 | struct hwrm_cfa_l2_filter_alloc_input req = {0}; |
| 3379 | struct hwrm_cfa_l2_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr; |
| 3380 | |
| 3381 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_L2_FILTER_ALLOC, -1, -1); |
Prashant Sreedharan | dc52c6c | 2016-07-18 07:15:24 -0400 | [diff] [blame] | 3382 | req.flags = cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_PATH_RX); |
| 3383 | if (!BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 3384 | req.flags |= |
| 3385 | cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_OUTERMOST); |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 3386 | req.dst_id = cpu_to_le16(bp->vnic_info[vnic_id].fw_vnic_id); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3387 | req.enables = |
| 3388 | cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR | |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 3389 | CFA_L2_FILTER_ALLOC_REQ_ENABLES_DST_ID | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3390 | CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR_MASK); |
| 3391 | memcpy(req.l2_addr, mac_addr, ETH_ALEN); |
| 3392 | req.l2_addr_mask[0] = 0xff; |
| 3393 | req.l2_addr_mask[1] = 0xff; |
| 3394 | req.l2_addr_mask[2] = 0xff; |
| 3395 | req.l2_addr_mask[3] = 0xff; |
| 3396 | req.l2_addr_mask[4] = 0xff; |
| 3397 | req.l2_addr_mask[5] = 0xff; |
| 3398 | |
| 3399 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3400 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3401 | if (!rc) |
| 3402 | bp->vnic_info[vnic_id].fw_l2_filter_id[idx] = |
| 3403 | resp->l2_filter_id; |
| 3404 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3405 | return rc; |
| 3406 | } |
| 3407 | |
| 3408 | static int bnxt_hwrm_clear_vnic_filter(struct bnxt *bp) |
| 3409 | { |
| 3410 | u16 i, j, num_of_vnics = 1; /* only vnic 0 supported */ |
| 3411 | int rc = 0; |
| 3412 | |
| 3413 | /* Any associated ntuple filters will also be cleared by firmware. */ |
| 3414 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3415 | for (i = 0; i < num_of_vnics; i++) { |
| 3416 | struct bnxt_vnic_info *vnic = &bp->vnic_info[i]; |
| 3417 | |
| 3418 | for (j = 0; j < vnic->uc_filter_count; j++) { |
| 3419 | struct hwrm_cfa_l2_filter_free_input req = {0}; |
| 3420 | |
| 3421 | bnxt_hwrm_cmd_hdr_init(bp, &req, |
| 3422 | HWRM_CFA_L2_FILTER_FREE, -1, -1); |
| 3423 | |
| 3424 | req.l2_filter_id = vnic->fw_l2_filter_id[j]; |
| 3425 | |
| 3426 | rc = _hwrm_send_message(bp, &req, sizeof(req), |
| 3427 | HWRM_CMD_TIMEOUT); |
| 3428 | } |
| 3429 | vnic->uc_filter_count = 0; |
| 3430 | } |
| 3431 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3432 | |
| 3433 | return rc; |
| 3434 | } |
| 3435 | |
| 3436 | static int bnxt_hwrm_vnic_set_tpa(struct bnxt *bp, u16 vnic_id, u32 tpa_flags) |
| 3437 | { |
| 3438 | struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id]; |
| 3439 | struct hwrm_vnic_tpa_cfg_input req = {0}; |
| 3440 | |
| 3441 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_TPA_CFG, -1, -1); |
| 3442 | |
| 3443 | if (tpa_flags) { |
| 3444 | u16 mss = bp->dev->mtu - 40; |
| 3445 | u32 nsegs, n, segs = 0, flags; |
| 3446 | |
| 3447 | flags = VNIC_TPA_CFG_REQ_FLAGS_TPA | |
| 3448 | VNIC_TPA_CFG_REQ_FLAGS_ENCAP_TPA | |
| 3449 | VNIC_TPA_CFG_REQ_FLAGS_RSC_WND_UPDATE | |
| 3450 | VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_ECN | |
| 3451 | VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_SAME_GRE_SEQ; |
| 3452 | if (tpa_flags & BNXT_FLAG_GRO) |
| 3453 | flags |= VNIC_TPA_CFG_REQ_FLAGS_GRO; |
| 3454 | |
| 3455 | req.flags = cpu_to_le32(flags); |
| 3456 | |
| 3457 | req.enables = |
| 3458 | cpu_to_le32(VNIC_TPA_CFG_REQ_ENABLES_MAX_AGG_SEGS | |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 3459 | VNIC_TPA_CFG_REQ_ENABLES_MAX_AGGS | |
| 3460 | VNIC_TPA_CFG_REQ_ENABLES_MIN_AGG_LEN); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3461 | |
| 3462 | /* Number of segs are log2 units, and first packet is not |
| 3463 | * included as part of this units. |
| 3464 | */ |
Michael Chan | 2839f28 | 2016-04-25 02:30:50 -0400 | [diff] [blame] | 3465 | if (mss <= BNXT_RX_PAGE_SIZE) { |
| 3466 | n = BNXT_RX_PAGE_SIZE / mss; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3467 | nsegs = (MAX_SKB_FRAGS - 1) * n; |
| 3468 | } else { |
Michael Chan | 2839f28 | 2016-04-25 02:30:50 -0400 | [diff] [blame] | 3469 | n = mss / BNXT_RX_PAGE_SIZE; |
| 3470 | if (mss & (BNXT_RX_PAGE_SIZE - 1)) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3471 | n++; |
| 3472 | nsegs = (MAX_SKB_FRAGS - n) / n; |
| 3473 | } |
| 3474 | |
| 3475 | segs = ilog2(nsegs); |
| 3476 | req.max_agg_segs = cpu_to_le16(segs); |
| 3477 | req.max_aggs = cpu_to_le16(VNIC_TPA_CFG_REQ_MAX_AGGS_MAX); |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 3478 | |
| 3479 | req.min_agg_len = cpu_to_le32(512); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3480 | } |
| 3481 | req.vnic_id = cpu_to_le16(vnic->fw_vnic_id); |
| 3482 | |
| 3483 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3484 | } |
| 3485 | |
| 3486 | static int bnxt_hwrm_vnic_set_rss(struct bnxt *bp, u16 vnic_id, bool set_rss) |
| 3487 | { |
| 3488 | u32 i, j, max_rings; |
| 3489 | struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id]; |
| 3490 | struct hwrm_vnic_rss_cfg_input req = {0}; |
| 3491 | |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 3492 | if (vnic->fw_rss_cos_lb_ctx[0] == INVALID_HW_RING_ID) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3493 | return 0; |
| 3494 | |
| 3495 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_CFG, -1, -1); |
| 3496 | if (set_rss) { |
Michael Chan | 87da7f7 | 2016-11-16 21:13:09 -0500 | [diff] [blame] | 3497 | req.hash_type = cpu_to_le32(bp->rss_hash_cfg); |
Prashant Sreedharan | dc52c6c | 2016-07-18 07:15:24 -0400 | [diff] [blame] | 3498 | if (vnic->flags & BNXT_VNIC_RSS_FLAG) { |
| 3499 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 3500 | max_rings = bp->rx_nr_rings - 1; |
| 3501 | else |
| 3502 | max_rings = bp->rx_nr_rings; |
| 3503 | } else { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3504 | max_rings = 1; |
Prashant Sreedharan | dc52c6c | 2016-07-18 07:15:24 -0400 | [diff] [blame] | 3505 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3506 | |
| 3507 | /* Fill the RSS indirection table with ring group ids */ |
| 3508 | for (i = 0, j = 0; i < HW_HASH_INDEX_SIZE; i++, j++) { |
| 3509 | if (j == max_rings) |
| 3510 | j = 0; |
| 3511 | vnic->rss_table[i] = cpu_to_le16(vnic->fw_grp_ids[j]); |
| 3512 | } |
| 3513 | |
| 3514 | req.ring_grp_tbl_addr = cpu_to_le64(vnic->rss_table_dma_addr); |
| 3515 | req.hash_key_tbl_addr = |
| 3516 | cpu_to_le64(vnic->rss_hash_key_dma_addr); |
| 3517 | } |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 3518 | req.rss_ctx_idx = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[0]); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3519 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3520 | } |
| 3521 | |
| 3522 | static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, u16 vnic_id) |
| 3523 | { |
| 3524 | struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id]; |
| 3525 | struct hwrm_vnic_plcmodes_cfg_input req = {0}; |
| 3526 | |
| 3527 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_PLCMODES_CFG, -1, -1); |
| 3528 | req.flags = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT | |
| 3529 | VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV4 | |
| 3530 | VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6); |
| 3531 | req.enables = |
| 3532 | cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID | |
| 3533 | VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID); |
| 3534 | /* thresholds not implemented in firmware yet */ |
| 3535 | req.jumbo_thresh = cpu_to_le16(bp->rx_copy_thresh); |
| 3536 | req.hds_threshold = cpu_to_le16(bp->rx_copy_thresh); |
| 3537 | req.vnic_id = cpu_to_le32(vnic->fw_vnic_id); |
| 3538 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3539 | } |
| 3540 | |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 3541 | static void bnxt_hwrm_vnic_ctx_free_one(struct bnxt *bp, u16 vnic_id, |
| 3542 | u16 ctx_idx) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3543 | { |
| 3544 | struct hwrm_vnic_rss_cos_lb_ctx_free_input req = {0}; |
| 3545 | |
| 3546 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_COS_LB_CTX_FREE, -1, -1); |
| 3547 | req.rss_cos_lb_ctx_id = |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 3548 | cpu_to_le16(bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx]); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3549 | |
| 3550 | hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 3551 | bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx] = INVALID_HW_RING_ID; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3552 | } |
| 3553 | |
| 3554 | static void bnxt_hwrm_vnic_ctx_free(struct bnxt *bp) |
| 3555 | { |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 3556 | int i, j; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3557 | |
| 3558 | for (i = 0; i < bp->nr_vnics; i++) { |
| 3559 | struct bnxt_vnic_info *vnic = &bp->vnic_info[i]; |
| 3560 | |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 3561 | for (j = 0; j < BNXT_MAX_CTX_PER_VNIC; j++) { |
| 3562 | if (vnic->fw_rss_cos_lb_ctx[j] != INVALID_HW_RING_ID) |
| 3563 | bnxt_hwrm_vnic_ctx_free_one(bp, i, j); |
| 3564 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3565 | } |
| 3566 | bp->rsscos_nr_ctxs = 0; |
| 3567 | } |
| 3568 | |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 3569 | static int bnxt_hwrm_vnic_ctx_alloc(struct bnxt *bp, u16 vnic_id, u16 ctx_idx) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3570 | { |
| 3571 | int rc; |
| 3572 | struct hwrm_vnic_rss_cos_lb_ctx_alloc_input req = {0}; |
| 3573 | struct hwrm_vnic_rss_cos_lb_ctx_alloc_output *resp = |
| 3574 | bp->hwrm_cmd_resp_addr; |
| 3575 | |
| 3576 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_COS_LB_CTX_ALLOC, -1, |
| 3577 | -1); |
| 3578 | |
| 3579 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3580 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3581 | if (!rc) |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 3582 | bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx] = |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3583 | le16_to_cpu(resp->rss_cos_lb_ctx_id); |
| 3584 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3585 | |
| 3586 | return rc; |
| 3587 | } |
| 3588 | |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 3589 | int bnxt_hwrm_vnic_cfg(struct bnxt *bp, u16 vnic_id) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3590 | { |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3591 | unsigned int ring = 0, grp_idx; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3592 | struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id]; |
| 3593 | struct hwrm_vnic_cfg_input req = {0}; |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 3594 | u16 def_vlan = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3595 | |
| 3596 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_CFG, -1, -1); |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 3597 | |
Prashant Sreedharan | dc52c6c | 2016-07-18 07:15:24 -0400 | [diff] [blame] | 3598 | req.enables = cpu_to_le32(VNIC_CFG_REQ_ENABLES_DFLT_RING_GRP); |
| 3599 | /* Only RSS support for now TBD: COS & LB */ |
| 3600 | if (vnic->fw_rss_cos_lb_ctx[0] != INVALID_HW_RING_ID) { |
| 3601 | req.rss_rule = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[0]); |
| 3602 | req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE | |
| 3603 | VNIC_CFG_REQ_ENABLES_MRU); |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 3604 | } else if (vnic->flags & BNXT_VNIC_RFS_NEW_RSS_FLAG) { |
| 3605 | req.rss_rule = |
| 3606 | cpu_to_le16(bp->vnic_info[0].fw_rss_cos_lb_ctx[0]); |
| 3607 | req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE | |
| 3608 | VNIC_CFG_REQ_ENABLES_MRU); |
| 3609 | req.flags |= cpu_to_le32(VNIC_CFG_REQ_FLAGS_RSS_DFLT_CR_MODE); |
Prashant Sreedharan | dc52c6c | 2016-07-18 07:15:24 -0400 | [diff] [blame] | 3610 | } else { |
| 3611 | req.rss_rule = cpu_to_le16(0xffff); |
| 3612 | } |
| 3613 | |
| 3614 | if (BNXT_CHIP_TYPE_NITRO_A0(bp) && |
| 3615 | (vnic->fw_rss_cos_lb_ctx[0] != INVALID_HW_RING_ID)) { |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 3616 | req.cos_rule = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[1]); |
| 3617 | req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_COS_RULE); |
| 3618 | } else { |
| 3619 | req.cos_rule = cpu_to_le16(0xffff); |
| 3620 | } |
| 3621 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3622 | if (vnic->flags & BNXT_VNIC_RSS_FLAG) |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3623 | ring = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3624 | else if (vnic->flags & BNXT_VNIC_RFS_FLAG) |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3625 | ring = vnic_id - 1; |
Prashant Sreedharan | 7659519 | 2016-07-18 07:15:22 -0400 | [diff] [blame] | 3626 | else if ((vnic_id == 1) && BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 3627 | ring = bp->rx_nr_rings - 1; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3628 | |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3629 | grp_idx = bp->rx_ring[ring].bnapi->index; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3630 | req.vnic_id = cpu_to_le16(vnic->fw_vnic_id); |
| 3631 | req.dflt_ring_grp = cpu_to_le16(bp->grp_info[grp_idx].fw_grp_id); |
| 3632 | |
| 3633 | req.lb_rule = cpu_to_le16(0xffff); |
| 3634 | req.mru = cpu_to_le16(bp->dev->mtu + ETH_HLEN + ETH_FCS_LEN + |
| 3635 | VLAN_HLEN); |
| 3636 | |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 3637 | #ifdef CONFIG_BNXT_SRIOV |
| 3638 | if (BNXT_VF(bp)) |
| 3639 | def_vlan = bp->vf.vlan; |
| 3640 | #endif |
| 3641 | if ((bp->flags & BNXT_FLAG_STRIP_VLAN) || def_vlan) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3642 | req.flags |= cpu_to_le32(VNIC_CFG_REQ_FLAGS_VLAN_STRIP_MODE); |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 3643 | if (!vnic_id && bnxt_ulp_registered(bp->edev, BNXT_ROCE_ULP)) |
| 3644 | req.flags |= |
| 3645 | cpu_to_le32(VNIC_CFG_REQ_FLAGS_ROCE_DUAL_VNIC_MODE); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3646 | |
| 3647 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3648 | } |
| 3649 | |
| 3650 | static int bnxt_hwrm_vnic_free_one(struct bnxt *bp, u16 vnic_id) |
| 3651 | { |
| 3652 | u32 rc = 0; |
| 3653 | |
| 3654 | if (bp->vnic_info[vnic_id].fw_vnic_id != INVALID_HW_RING_ID) { |
| 3655 | struct hwrm_vnic_free_input req = {0}; |
| 3656 | |
| 3657 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_FREE, -1, -1); |
| 3658 | req.vnic_id = |
| 3659 | cpu_to_le32(bp->vnic_info[vnic_id].fw_vnic_id); |
| 3660 | |
| 3661 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3662 | if (rc) |
| 3663 | return rc; |
| 3664 | bp->vnic_info[vnic_id].fw_vnic_id = INVALID_HW_RING_ID; |
| 3665 | } |
| 3666 | return rc; |
| 3667 | } |
| 3668 | |
| 3669 | static void bnxt_hwrm_vnic_free(struct bnxt *bp) |
| 3670 | { |
| 3671 | u16 i; |
| 3672 | |
| 3673 | for (i = 0; i < bp->nr_vnics; i++) |
| 3674 | bnxt_hwrm_vnic_free_one(bp, i); |
| 3675 | } |
| 3676 | |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3677 | static int bnxt_hwrm_vnic_alloc(struct bnxt *bp, u16 vnic_id, |
| 3678 | unsigned int start_rx_ring_idx, |
| 3679 | unsigned int nr_rings) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3680 | { |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3681 | int rc = 0; |
| 3682 | unsigned int i, j, grp_idx, end_idx = start_rx_ring_idx + nr_rings; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3683 | struct hwrm_vnic_alloc_input req = {0}; |
| 3684 | struct hwrm_vnic_alloc_output *resp = bp->hwrm_cmd_resp_addr; |
| 3685 | |
| 3686 | /* map ring groups to this vnic */ |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3687 | for (i = start_rx_ring_idx, j = 0; i < end_idx; i++, j++) { |
| 3688 | grp_idx = bp->rx_ring[i].bnapi->index; |
| 3689 | if (bp->grp_info[grp_idx].fw_grp_id == INVALID_HW_RING_ID) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3690 | netdev_err(bp->dev, "Not enough ring groups avail:%x req:%x\n", |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3691 | j, nr_rings); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3692 | break; |
| 3693 | } |
| 3694 | bp->vnic_info[vnic_id].fw_grp_ids[j] = |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3695 | bp->grp_info[grp_idx].fw_grp_id; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3696 | } |
| 3697 | |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 3698 | bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[0] = INVALID_HW_RING_ID; |
| 3699 | bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[1] = INVALID_HW_RING_ID; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3700 | if (vnic_id == 0) |
| 3701 | req.flags = cpu_to_le32(VNIC_ALLOC_REQ_FLAGS_DEFAULT); |
| 3702 | |
| 3703 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_ALLOC, -1, -1); |
| 3704 | |
| 3705 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3706 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3707 | if (!rc) |
| 3708 | bp->vnic_info[vnic_id].fw_vnic_id = le32_to_cpu(resp->vnic_id); |
| 3709 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3710 | return rc; |
| 3711 | } |
| 3712 | |
Michael Chan | 8fdefd6 | 2016-12-29 12:13:36 -0500 | [diff] [blame] | 3713 | static int bnxt_hwrm_vnic_qcaps(struct bnxt *bp) |
| 3714 | { |
| 3715 | struct hwrm_vnic_qcaps_output *resp = bp->hwrm_cmd_resp_addr; |
| 3716 | struct hwrm_vnic_qcaps_input req = {0}; |
| 3717 | int rc; |
| 3718 | |
| 3719 | if (bp->hwrm_spec_code < 0x10600) |
| 3720 | return 0; |
| 3721 | |
| 3722 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_QCAPS, -1, -1); |
| 3723 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3724 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3725 | if (!rc) { |
| 3726 | if (resp->flags & |
| 3727 | cpu_to_le32(VNIC_QCAPS_RESP_FLAGS_RSS_DFLT_CR_CAP)) |
| 3728 | bp->flags |= BNXT_FLAG_NEW_RSS_CAP; |
| 3729 | } |
| 3730 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3731 | return rc; |
| 3732 | } |
| 3733 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3734 | static int bnxt_hwrm_ring_grp_alloc(struct bnxt *bp) |
| 3735 | { |
| 3736 | u16 i; |
| 3737 | u32 rc = 0; |
| 3738 | |
| 3739 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3740 | for (i = 0; i < bp->rx_nr_rings; i++) { |
| 3741 | struct hwrm_ring_grp_alloc_input req = {0}; |
| 3742 | struct hwrm_ring_grp_alloc_output *resp = |
| 3743 | bp->hwrm_cmd_resp_addr; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3744 | unsigned int grp_idx = bp->rx_ring[i].bnapi->index; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3745 | |
| 3746 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_GRP_ALLOC, -1, -1); |
| 3747 | |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3748 | req.cr = cpu_to_le16(bp->grp_info[grp_idx].cp_fw_ring_id); |
| 3749 | req.rr = cpu_to_le16(bp->grp_info[grp_idx].rx_fw_ring_id); |
| 3750 | req.ar = cpu_to_le16(bp->grp_info[grp_idx].agg_fw_ring_id); |
| 3751 | req.sc = cpu_to_le16(bp->grp_info[grp_idx].fw_stats_ctx); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3752 | |
| 3753 | rc = _hwrm_send_message(bp, &req, sizeof(req), |
| 3754 | HWRM_CMD_TIMEOUT); |
| 3755 | if (rc) |
| 3756 | break; |
| 3757 | |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3758 | bp->grp_info[grp_idx].fw_grp_id = |
| 3759 | le32_to_cpu(resp->ring_group_id); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3760 | } |
| 3761 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3762 | return rc; |
| 3763 | } |
| 3764 | |
| 3765 | static int bnxt_hwrm_ring_grp_free(struct bnxt *bp) |
| 3766 | { |
| 3767 | u16 i; |
| 3768 | u32 rc = 0; |
| 3769 | struct hwrm_ring_grp_free_input req = {0}; |
| 3770 | |
| 3771 | if (!bp->grp_info) |
| 3772 | return 0; |
| 3773 | |
| 3774 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_GRP_FREE, -1, -1); |
| 3775 | |
| 3776 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3777 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 3778 | if (bp->grp_info[i].fw_grp_id == INVALID_HW_RING_ID) |
| 3779 | continue; |
| 3780 | req.ring_group_id = |
| 3781 | cpu_to_le32(bp->grp_info[i].fw_grp_id); |
| 3782 | |
| 3783 | rc = _hwrm_send_message(bp, &req, sizeof(req), |
| 3784 | HWRM_CMD_TIMEOUT); |
| 3785 | if (rc) |
| 3786 | break; |
| 3787 | bp->grp_info[i].fw_grp_id = INVALID_HW_RING_ID; |
| 3788 | } |
| 3789 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3790 | return rc; |
| 3791 | } |
| 3792 | |
| 3793 | static int hwrm_ring_alloc_send_msg(struct bnxt *bp, |
| 3794 | struct bnxt_ring_struct *ring, |
| 3795 | u32 ring_type, u32 map_index, |
| 3796 | u32 stats_ctx_id) |
| 3797 | { |
| 3798 | int rc = 0, err = 0; |
| 3799 | struct hwrm_ring_alloc_input req = {0}; |
| 3800 | struct hwrm_ring_alloc_output *resp = bp->hwrm_cmd_resp_addr; |
| 3801 | u16 ring_id; |
| 3802 | |
| 3803 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_ALLOC, -1, -1); |
| 3804 | |
| 3805 | req.enables = 0; |
| 3806 | if (ring->nr_pages > 1) { |
| 3807 | req.page_tbl_addr = cpu_to_le64(ring->pg_tbl_map); |
| 3808 | /* Page size is in log2 units */ |
| 3809 | req.page_size = BNXT_PAGE_SHIFT; |
| 3810 | req.page_tbl_depth = 1; |
| 3811 | } else { |
| 3812 | req.page_tbl_addr = cpu_to_le64(ring->dma_arr[0]); |
| 3813 | } |
| 3814 | req.fbo = 0; |
| 3815 | /* Association of ring index with doorbell index and MSIX number */ |
| 3816 | req.logical_id = cpu_to_le16(map_index); |
| 3817 | |
| 3818 | switch (ring_type) { |
| 3819 | case HWRM_RING_ALLOC_TX: |
| 3820 | req.ring_type = RING_ALLOC_REQ_RING_TYPE_TX; |
| 3821 | /* Association of transmit ring with completion ring */ |
| 3822 | req.cmpl_ring_id = |
| 3823 | cpu_to_le16(bp->grp_info[map_index].cp_fw_ring_id); |
| 3824 | req.length = cpu_to_le32(bp->tx_ring_mask + 1); |
| 3825 | req.stat_ctx_id = cpu_to_le32(stats_ctx_id); |
| 3826 | req.queue_id = cpu_to_le16(ring->queue_id); |
| 3827 | break; |
| 3828 | case HWRM_RING_ALLOC_RX: |
| 3829 | req.ring_type = RING_ALLOC_REQ_RING_TYPE_RX; |
| 3830 | req.length = cpu_to_le32(bp->rx_ring_mask + 1); |
| 3831 | break; |
| 3832 | case HWRM_RING_ALLOC_AGG: |
| 3833 | req.ring_type = RING_ALLOC_REQ_RING_TYPE_RX; |
| 3834 | req.length = cpu_to_le32(bp->rx_agg_ring_mask + 1); |
| 3835 | break; |
| 3836 | case HWRM_RING_ALLOC_CMPL: |
| 3837 | req.ring_type = RING_ALLOC_REQ_RING_TYPE_CMPL; |
| 3838 | req.length = cpu_to_le32(bp->cp_ring_mask + 1); |
| 3839 | if (bp->flags & BNXT_FLAG_USING_MSIX) |
| 3840 | req.int_mode = RING_ALLOC_REQ_INT_MODE_MSIX; |
| 3841 | break; |
| 3842 | default: |
| 3843 | netdev_err(bp->dev, "hwrm alloc invalid ring type %d\n", |
| 3844 | ring_type); |
| 3845 | return -1; |
| 3846 | } |
| 3847 | |
| 3848 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3849 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3850 | err = le16_to_cpu(resp->error_code); |
| 3851 | ring_id = le16_to_cpu(resp->ring_id); |
| 3852 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3853 | |
| 3854 | if (rc || err) { |
| 3855 | switch (ring_type) { |
| 3856 | case RING_FREE_REQ_RING_TYPE_CMPL: |
| 3857 | netdev_err(bp->dev, "hwrm_ring_alloc cp failed. rc:%x err:%x\n", |
| 3858 | rc, err); |
| 3859 | return -1; |
| 3860 | |
| 3861 | case RING_FREE_REQ_RING_TYPE_RX: |
| 3862 | netdev_err(bp->dev, "hwrm_ring_alloc rx failed. rc:%x err:%x\n", |
| 3863 | rc, err); |
| 3864 | return -1; |
| 3865 | |
| 3866 | case RING_FREE_REQ_RING_TYPE_TX: |
| 3867 | netdev_err(bp->dev, "hwrm_ring_alloc tx failed. rc:%x err:%x\n", |
| 3868 | rc, err); |
| 3869 | return -1; |
| 3870 | |
| 3871 | default: |
| 3872 | netdev_err(bp->dev, "Invalid ring\n"); |
| 3873 | return -1; |
| 3874 | } |
| 3875 | } |
| 3876 | ring->fw_ring_id = ring_id; |
| 3877 | return rc; |
| 3878 | } |
| 3879 | |
Michael Chan | 486b5c2 | 2016-12-29 12:13:42 -0500 | [diff] [blame] | 3880 | static int bnxt_hwrm_set_async_event_cr(struct bnxt *bp, int idx) |
| 3881 | { |
| 3882 | int rc; |
| 3883 | |
| 3884 | if (BNXT_PF(bp)) { |
| 3885 | struct hwrm_func_cfg_input req = {0}; |
| 3886 | |
| 3887 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1); |
| 3888 | req.fid = cpu_to_le16(0xffff); |
| 3889 | req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_ASYNC_EVENT_CR); |
| 3890 | req.async_event_cr = cpu_to_le16(idx); |
| 3891 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3892 | } else { |
| 3893 | struct hwrm_func_vf_cfg_input req = {0}; |
| 3894 | |
| 3895 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_VF_CFG, -1, -1); |
| 3896 | req.enables = |
| 3897 | cpu_to_le32(FUNC_VF_CFG_REQ_ENABLES_ASYNC_EVENT_CR); |
| 3898 | req.async_event_cr = cpu_to_le16(idx); |
| 3899 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3900 | } |
| 3901 | return rc; |
| 3902 | } |
| 3903 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3904 | static int bnxt_hwrm_ring_alloc(struct bnxt *bp) |
| 3905 | { |
| 3906 | int i, rc = 0; |
| 3907 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 3908 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 3909 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 3910 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 3911 | struct bnxt_ring_struct *ring = &cpr->cp_ring_struct; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3912 | |
Prashant Sreedharan | 33e52d8 | 2016-03-28 19:46:04 -0400 | [diff] [blame] | 3913 | cpr->cp_doorbell = bp->bar1 + i * 0x80; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 3914 | rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_CMPL, i, |
| 3915 | INVALID_STATS_CTX_ID); |
| 3916 | if (rc) |
| 3917 | goto err_out; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 3918 | BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons); |
| 3919 | bp->grp_info[i].cp_fw_ring_id = ring->fw_ring_id; |
Michael Chan | 486b5c2 | 2016-12-29 12:13:42 -0500 | [diff] [blame] | 3920 | |
| 3921 | if (!i) { |
| 3922 | rc = bnxt_hwrm_set_async_event_cr(bp, ring->fw_ring_id); |
| 3923 | if (rc) |
| 3924 | netdev_warn(bp->dev, "Failed to set async event completion ring.\n"); |
| 3925 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3926 | } |
| 3927 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 3928 | for (i = 0; i < bp->tx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 3929 | struct bnxt_tx_ring_info *txr = &bp->tx_ring[i]; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 3930 | struct bnxt_ring_struct *ring = &txr->tx_ring_struct; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3931 | u32 map_idx = txr->bnapi->index; |
| 3932 | u16 fw_stats_ctx = bp->grp_info[map_idx].fw_stats_ctx; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3933 | |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3934 | rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_TX, |
| 3935 | map_idx, fw_stats_ctx); |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 3936 | if (rc) |
| 3937 | goto err_out; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3938 | txr->tx_doorbell = bp->bar1 + map_idx * 0x80; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3939 | } |
| 3940 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 3941 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 3942 | struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i]; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 3943 | struct bnxt_ring_struct *ring = &rxr->rx_ring_struct; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3944 | u32 map_idx = rxr->bnapi->index; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3945 | |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3946 | rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_RX, |
| 3947 | map_idx, INVALID_STATS_CTX_ID); |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 3948 | if (rc) |
| 3949 | goto err_out; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3950 | rxr->rx_doorbell = bp->bar1 + map_idx * 0x80; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 3951 | writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell); |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3952 | bp->grp_info[map_idx].rx_fw_ring_id = ring->fw_ring_id; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3953 | } |
| 3954 | |
| 3955 | if (bp->flags & BNXT_FLAG_AGG_RINGS) { |
| 3956 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 3957 | struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3958 | struct bnxt_ring_struct *ring = |
| 3959 | &rxr->rx_agg_ring_struct; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3960 | u32 grp_idx = rxr->bnapi->index; |
| 3961 | u32 map_idx = grp_idx + bp->rx_nr_rings; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3962 | |
| 3963 | rc = hwrm_ring_alloc_send_msg(bp, ring, |
| 3964 | HWRM_RING_ALLOC_AGG, |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3965 | map_idx, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3966 | INVALID_STATS_CTX_ID); |
| 3967 | if (rc) |
| 3968 | goto err_out; |
| 3969 | |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3970 | rxr->rx_agg_doorbell = bp->bar1 + map_idx * 0x80; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3971 | writel(DB_KEY_RX | rxr->rx_agg_prod, |
| 3972 | rxr->rx_agg_doorbell); |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3973 | bp->grp_info[grp_idx].agg_fw_ring_id = ring->fw_ring_id; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3974 | } |
| 3975 | } |
| 3976 | err_out: |
| 3977 | return rc; |
| 3978 | } |
| 3979 | |
| 3980 | static int hwrm_ring_free_send_msg(struct bnxt *bp, |
| 3981 | struct bnxt_ring_struct *ring, |
| 3982 | u32 ring_type, int cmpl_ring_id) |
| 3983 | { |
| 3984 | int rc; |
| 3985 | struct hwrm_ring_free_input req = {0}; |
| 3986 | struct hwrm_ring_free_output *resp = bp->hwrm_cmd_resp_addr; |
| 3987 | u16 error_code; |
| 3988 | |
Prashant Sreedharan | 74608fc | 2016-01-28 03:11:20 -0500 | [diff] [blame] | 3989 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_FREE, cmpl_ring_id, -1); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3990 | req.ring_type = ring_type; |
| 3991 | req.ring_id = cpu_to_le16(ring->fw_ring_id); |
| 3992 | |
| 3993 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3994 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3995 | error_code = le16_to_cpu(resp->error_code); |
| 3996 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3997 | |
| 3998 | if (rc || error_code) { |
| 3999 | switch (ring_type) { |
| 4000 | case RING_FREE_REQ_RING_TYPE_CMPL: |
| 4001 | netdev_err(bp->dev, "hwrm_ring_free cp failed. rc:%d\n", |
| 4002 | rc); |
| 4003 | return rc; |
| 4004 | case RING_FREE_REQ_RING_TYPE_RX: |
| 4005 | netdev_err(bp->dev, "hwrm_ring_free rx failed. rc:%d\n", |
| 4006 | rc); |
| 4007 | return rc; |
| 4008 | case RING_FREE_REQ_RING_TYPE_TX: |
| 4009 | netdev_err(bp->dev, "hwrm_ring_free tx failed. rc:%d\n", |
| 4010 | rc); |
| 4011 | return rc; |
| 4012 | default: |
| 4013 | netdev_err(bp->dev, "Invalid ring\n"); |
| 4014 | return -1; |
| 4015 | } |
| 4016 | } |
| 4017 | return 0; |
| 4018 | } |
| 4019 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4020 | static void bnxt_hwrm_ring_free(struct bnxt *bp, bool close_path) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4021 | { |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4022 | int i; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4023 | |
| 4024 | if (!bp->bnapi) |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4025 | return; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4026 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4027 | for (i = 0; i < bp->tx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 4028 | struct bnxt_tx_ring_info *txr = &bp->tx_ring[i]; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4029 | struct bnxt_ring_struct *ring = &txr->tx_ring_struct; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4030 | u32 grp_idx = txr->bnapi->index; |
| 4031 | u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4032 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4033 | if (ring->fw_ring_id != INVALID_HW_RING_ID) { |
| 4034 | hwrm_ring_free_send_msg(bp, ring, |
| 4035 | RING_FREE_REQ_RING_TYPE_TX, |
| 4036 | close_path ? cmpl_ring_id : |
| 4037 | INVALID_HW_RING_ID); |
| 4038 | ring->fw_ring_id = INVALID_HW_RING_ID; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4039 | } |
| 4040 | } |
| 4041 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4042 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 4043 | struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i]; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4044 | struct bnxt_ring_struct *ring = &rxr->rx_ring_struct; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4045 | u32 grp_idx = rxr->bnapi->index; |
| 4046 | u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4047 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4048 | if (ring->fw_ring_id != INVALID_HW_RING_ID) { |
| 4049 | hwrm_ring_free_send_msg(bp, ring, |
| 4050 | RING_FREE_REQ_RING_TYPE_RX, |
| 4051 | close_path ? cmpl_ring_id : |
| 4052 | INVALID_HW_RING_ID); |
| 4053 | ring->fw_ring_id = INVALID_HW_RING_ID; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4054 | bp->grp_info[grp_idx].rx_fw_ring_id = |
| 4055 | INVALID_HW_RING_ID; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4056 | } |
| 4057 | } |
| 4058 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4059 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 4060 | struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i]; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4061 | struct bnxt_ring_struct *ring = &rxr->rx_agg_ring_struct; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4062 | u32 grp_idx = rxr->bnapi->index; |
| 4063 | u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4064 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4065 | if (ring->fw_ring_id != INVALID_HW_RING_ID) { |
| 4066 | hwrm_ring_free_send_msg(bp, ring, |
| 4067 | RING_FREE_REQ_RING_TYPE_RX, |
| 4068 | close_path ? cmpl_ring_id : |
| 4069 | INVALID_HW_RING_ID); |
| 4070 | ring->fw_ring_id = INVALID_HW_RING_ID; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4071 | bp->grp_info[grp_idx].agg_fw_ring_id = |
| 4072 | INVALID_HW_RING_ID; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4073 | } |
| 4074 | } |
| 4075 | |
Michael Chan | 9d8bc09 | 2016-12-29 12:13:33 -0500 | [diff] [blame] | 4076 | /* The completion rings are about to be freed. After that the |
| 4077 | * IRQ doorbell will not work anymore. So we need to disable |
| 4078 | * IRQ here. |
| 4079 | */ |
| 4080 | bnxt_disable_int_sync(bp); |
| 4081 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4082 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 4083 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 4084 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 4085 | struct bnxt_ring_struct *ring = &cpr->cp_ring_struct; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4086 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4087 | if (ring->fw_ring_id != INVALID_HW_RING_ID) { |
| 4088 | hwrm_ring_free_send_msg(bp, ring, |
| 4089 | RING_FREE_REQ_RING_TYPE_CMPL, |
| 4090 | INVALID_HW_RING_ID); |
| 4091 | ring->fw_ring_id = INVALID_HW_RING_ID; |
| 4092 | bp->grp_info[i].cp_fw_ring_id = INVALID_HW_RING_ID; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4093 | } |
| 4094 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4095 | } |
| 4096 | |
Michael Chan | 391be5c | 2016-12-29 12:13:41 -0500 | [diff] [blame] | 4097 | /* Caller must hold bp->hwrm_cmd_lock */ |
| 4098 | int __bnxt_hwrm_get_tx_rings(struct bnxt *bp, u16 fid, int *tx_rings) |
| 4099 | { |
| 4100 | struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr; |
| 4101 | struct hwrm_func_qcfg_input req = {0}; |
| 4102 | int rc; |
| 4103 | |
| 4104 | if (bp->hwrm_spec_code < 0x10601) |
| 4105 | return 0; |
| 4106 | |
| 4107 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCFG, -1, -1); |
| 4108 | req.fid = cpu_to_le16(fid); |
| 4109 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4110 | if (!rc) |
| 4111 | *tx_rings = le16_to_cpu(resp->alloc_tx_rings); |
| 4112 | |
| 4113 | return rc; |
| 4114 | } |
| 4115 | |
| 4116 | int bnxt_hwrm_reserve_tx_rings(struct bnxt *bp, int *tx_rings) |
| 4117 | { |
| 4118 | struct hwrm_func_cfg_input req = {0}; |
| 4119 | int rc; |
| 4120 | |
| 4121 | if (bp->hwrm_spec_code < 0x10601) |
| 4122 | return 0; |
| 4123 | |
| 4124 | if (BNXT_VF(bp)) |
| 4125 | return 0; |
| 4126 | |
| 4127 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1); |
| 4128 | req.fid = cpu_to_le16(0xffff); |
| 4129 | req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_NUM_TX_RINGS); |
| 4130 | req.num_tx_rings = cpu_to_le16(*tx_rings); |
| 4131 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4132 | if (rc) |
| 4133 | return rc; |
| 4134 | |
| 4135 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4136 | rc = __bnxt_hwrm_get_tx_rings(bp, 0xffff, tx_rings); |
| 4137 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4138 | return rc; |
| 4139 | } |
| 4140 | |
Michael Chan | bb053f5 | 2016-02-26 04:00:02 -0500 | [diff] [blame] | 4141 | static void bnxt_hwrm_set_coal_params(struct bnxt *bp, u32 max_bufs, |
| 4142 | u32 buf_tmrs, u16 flags, |
| 4143 | struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *req) |
| 4144 | { |
| 4145 | req->flags = cpu_to_le16(flags); |
| 4146 | req->num_cmpl_dma_aggr = cpu_to_le16((u16)max_bufs); |
| 4147 | req->num_cmpl_dma_aggr_during_int = cpu_to_le16(max_bufs >> 16); |
| 4148 | req->cmpl_aggr_dma_tmr = cpu_to_le16((u16)buf_tmrs); |
| 4149 | req->cmpl_aggr_dma_tmr_during_int = cpu_to_le16(buf_tmrs >> 16); |
| 4150 | /* Minimum time between 2 interrupts set to buf_tmr x 2 */ |
| 4151 | req->int_lat_tmr_min = cpu_to_le16((u16)buf_tmrs * 2); |
| 4152 | req->int_lat_tmr_max = cpu_to_le16((u16)buf_tmrs * 4); |
| 4153 | req->num_cmpl_aggr_int = cpu_to_le16((u16)max_bufs * 4); |
| 4154 | } |
| 4155 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4156 | int bnxt_hwrm_set_coal(struct bnxt *bp) |
| 4157 | { |
| 4158 | int i, rc = 0; |
Michael Chan | dfc9c94 | 2016-02-26 04:00:03 -0500 | [diff] [blame] | 4159 | struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req_rx = {0}, |
| 4160 | req_tx = {0}, *req; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4161 | u16 max_buf, max_buf_irq; |
| 4162 | u16 buf_tmr, buf_tmr_irq; |
| 4163 | u32 flags; |
| 4164 | |
Michael Chan | dfc9c94 | 2016-02-26 04:00:03 -0500 | [diff] [blame] | 4165 | bnxt_hwrm_cmd_hdr_init(bp, &req_rx, |
| 4166 | HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1); |
| 4167 | bnxt_hwrm_cmd_hdr_init(bp, &req_tx, |
| 4168 | HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4169 | |
Michael Chan | dfb5b89 | 2016-02-26 04:00:01 -0500 | [diff] [blame] | 4170 | /* Each rx completion (2 records) should be DMAed immediately. |
| 4171 | * DMA 1/4 of the completion buffers at a time. |
| 4172 | */ |
| 4173 | max_buf = min_t(u16, bp->rx_coal_bufs / 4, 2); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4174 | /* max_buf must not be zero */ |
| 4175 | max_buf = clamp_t(u16, max_buf, 1, 63); |
Michael Chan | dfb5b89 | 2016-02-26 04:00:01 -0500 | [diff] [blame] | 4176 | max_buf_irq = clamp_t(u16, bp->rx_coal_bufs_irq, 1, 63); |
| 4177 | buf_tmr = BNXT_USEC_TO_COAL_TIMER(bp->rx_coal_ticks); |
| 4178 | /* buf timer set to 1/4 of interrupt timer */ |
| 4179 | buf_tmr = max_t(u16, buf_tmr / 4, 1); |
| 4180 | buf_tmr_irq = BNXT_USEC_TO_COAL_TIMER(bp->rx_coal_ticks_irq); |
| 4181 | buf_tmr_irq = max_t(u16, buf_tmr_irq, 1); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4182 | |
| 4183 | flags = RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_TIMER_RESET; |
| 4184 | |
| 4185 | /* RING_IDLE generates more IRQs for lower latency. Enable it only |
| 4186 | * if coal_ticks is less than 25 us. |
| 4187 | */ |
Michael Chan | dfb5b89 | 2016-02-26 04:00:01 -0500 | [diff] [blame] | 4188 | if (bp->rx_coal_ticks < 25) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4189 | flags |= RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_RING_IDLE; |
| 4190 | |
Michael Chan | bb053f5 | 2016-02-26 04:00:02 -0500 | [diff] [blame] | 4191 | bnxt_hwrm_set_coal_params(bp, max_buf_irq << 16 | max_buf, |
Michael Chan | dfc9c94 | 2016-02-26 04:00:03 -0500 | [diff] [blame] | 4192 | buf_tmr_irq << 16 | buf_tmr, flags, &req_rx); |
| 4193 | |
| 4194 | /* max_buf must not be zero */ |
| 4195 | max_buf = clamp_t(u16, bp->tx_coal_bufs, 1, 63); |
| 4196 | max_buf_irq = clamp_t(u16, bp->tx_coal_bufs_irq, 1, 63); |
| 4197 | buf_tmr = BNXT_USEC_TO_COAL_TIMER(bp->tx_coal_ticks); |
| 4198 | /* buf timer set to 1/4 of interrupt timer */ |
| 4199 | buf_tmr = max_t(u16, buf_tmr / 4, 1); |
| 4200 | buf_tmr_irq = BNXT_USEC_TO_COAL_TIMER(bp->tx_coal_ticks_irq); |
| 4201 | buf_tmr_irq = max_t(u16, buf_tmr_irq, 1); |
| 4202 | |
| 4203 | flags = RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_TIMER_RESET; |
| 4204 | bnxt_hwrm_set_coal_params(bp, max_buf_irq << 16 | max_buf, |
| 4205 | buf_tmr_irq << 16 | buf_tmr, flags, &req_tx); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4206 | |
| 4207 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4208 | for (i = 0; i < bp->cp_nr_rings; i++) { |
Michael Chan | dfc9c94 | 2016-02-26 04:00:03 -0500 | [diff] [blame] | 4209 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4210 | |
Michael Chan | dfc9c94 | 2016-02-26 04:00:03 -0500 | [diff] [blame] | 4211 | req = &req_rx; |
| 4212 | if (!bnapi->rx_ring) |
| 4213 | req = &req_tx; |
| 4214 | req->ring_id = cpu_to_le16(bp->grp_info[i].cp_fw_ring_id); |
| 4215 | |
| 4216 | rc = _hwrm_send_message(bp, req, sizeof(*req), |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4217 | HWRM_CMD_TIMEOUT); |
| 4218 | if (rc) |
| 4219 | break; |
| 4220 | } |
| 4221 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4222 | return rc; |
| 4223 | } |
| 4224 | |
| 4225 | static int bnxt_hwrm_stat_ctx_free(struct bnxt *bp) |
| 4226 | { |
| 4227 | int rc = 0, i; |
| 4228 | struct hwrm_stat_ctx_free_input req = {0}; |
| 4229 | |
| 4230 | if (!bp->bnapi) |
| 4231 | return 0; |
| 4232 | |
Prashant Sreedharan | 3e8060f | 2016-07-18 07:15:20 -0400 | [diff] [blame] | 4233 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 4234 | return 0; |
| 4235 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4236 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_STAT_CTX_FREE, -1, -1); |
| 4237 | |
| 4238 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4239 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 4240 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 4241 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 4242 | |
| 4243 | if (cpr->hw_stats_ctx_id != INVALID_STATS_CTX_ID) { |
| 4244 | req.stat_ctx_id = cpu_to_le32(cpr->hw_stats_ctx_id); |
| 4245 | |
| 4246 | rc = _hwrm_send_message(bp, &req, sizeof(req), |
| 4247 | HWRM_CMD_TIMEOUT); |
| 4248 | if (rc) |
| 4249 | break; |
| 4250 | |
| 4251 | cpr->hw_stats_ctx_id = INVALID_STATS_CTX_ID; |
| 4252 | } |
| 4253 | } |
| 4254 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4255 | return rc; |
| 4256 | } |
| 4257 | |
| 4258 | static int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp) |
| 4259 | { |
| 4260 | int rc = 0, i; |
| 4261 | struct hwrm_stat_ctx_alloc_input req = {0}; |
| 4262 | struct hwrm_stat_ctx_alloc_output *resp = bp->hwrm_cmd_resp_addr; |
| 4263 | |
Prashant Sreedharan | 3e8060f | 2016-07-18 07:15:20 -0400 | [diff] [blame] | 4264 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 4265 | return 0; |
| 4266 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4267 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_STAT_CTX_ALLOC, -1, -1); |
| 4268 | |
Michael Chan | 51f3078 | 2016-07-01 18:46:29 -0400 | [diff] [blame] | 4269 | req.update_period_ms = cpu_to_le32(bp->stats_coal_ticks / 1000); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4270 | |
| 4271 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4272 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 4273 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 4274 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 4275 | |
| 4276 | req.stats_dma_addr = cpu_to_le64(cpr->hw_stats_map); |
| 4277 | |
| 4278 | rc = _hwrm_send_message(bp, &req, sizeof(req), |
| 4279 | HWRM_CMD_TIMEOUT); |
| 4280 | if (rc) |
| 4281 | break; |
| 4282 | |
| 4283 | cpr->hw_stats_ctx_id = le32_to_cpu(resp->stat_ctx_id); |
| 4284 | |
| 4285 | bp->grp_info[i].fw_stats_ctx = cpr->hw_stats_ctx_id; |
| 4286 | } |
| 4287 | mutex_unlock(&bp->hwrm_cmd_lock); |
Pan Bian | 89aa844 | 2016-12-03 17:56:17 +0800 | [diff] [blame] | 4288 | return rc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4289 | } |
| 4290 | |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 4291 | static int bnxt_hwrm_func_qcfg(struct bnxt *bp) |
| 4292 | { |
| 4293 | struct hwrm_func_qcfg_input req = {0}; |
Satish Baddipadige | 567b2ab | 2016-06-13 02:25:31 -0400 | [diff] [blame] | 4294 | struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr; |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 4295 | int rc; |
| 4296 | |
| 4297 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCFG, -1, -1); |
| 4298 | req.fid = cpu_to_le16(0xffff); |
| 4299 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4300 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4301 | if (rc) |
| 4302 | goto func_qcfg_exit; |
| 4303 | |
| 4304 | #ifdef CONFIG_BNXT_SRIOV |
| 4305 | if (BNXT_VF(bp)) { |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 4306 | struct bnxt_vf_info *vf = &bp->vf; |
| 4307 | |
| 4308 | vf->vlan = le16_to_cpu(resp->vlan) & VLAN_VID_MASK; |
| 4309 | } |
| 4310 | #endif |
Satish Baddipadige | 567b2ab | 2016-06-13 02:25:31 -0400 | [diff] [blame] | 4311 | switch (resp->port_partition_type) { |
| 4312 | case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_0: |
| 4313 | case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_5: |
| 4314 | case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR2_0: |
| 4315 | bp->port_partition_type = resp->port_partition_type; |
| 4316 | break; |
| 4317 | } |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 4318 | |
| 4319 | func_qcfg_exit: |
| 4320 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4321 | return rc; |
| 4322 | } |
| 4323 | |
Michael Chan | 7b08f66 | 2016-12-07 00:26:18 -0500 | [diff] [blame] | 4324 | static int bnxt_hwrm_func_qcaps(struct bnxt *bp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4325 | { |
| 4326 | int rc = 0; |
| 4327 | struct hwrm_func_qcaps_input req = {0}; |
| 4328 | struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr; |
| 4329 | |
| 4330 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCAPS, -1, -1); |
| 4331 | req.fid = cpu_to_le16(0xffff); |
| 4332 | |
| 4333 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4334 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4335 | if (rc) |
| 4336 | goto hwrm_func_qcaps_exit; |
| 4337 | |
Michael Chan | e4060d3 | 2016-12-07 00:26:19 -0500 | [diff] [blame] | 4338 | if (resp->flags & cpu_to_le32(FUNC_QCAPS_RESP_FLAGS_ROCE_V1_SUPPORTED)) |
| 4339 | bp->flags |= BNXT_FLAG_ROCEV1_CAP; |
| 4340 | if (resp->flags & cpu_to_le32(FUNC_QCAPS_RESP_FLAGS_ROCE_V2_SUPPORTED)) |
| 4341 | bp->flags |= BNXT_FLAG_ROCEV2_CAP; |
| 4342 | |
Michael Chan | 7cc5a20 | 2016-09-19 03:58:05 -0400 | [diff] [blame] | 4343 | bp->tx_push_thresh = 0; |
| 4344 | if (resp->flags & |
| 4345 | cpu_to_le32(FUNC_QCAPS_RESP_FLAGS_PUSH_MODE_SUPPORTED)) |
| 4346 | bp->tx_push_thresh = BNXT_TX_PUSH_THRESH; |
| 4347 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4348 | if (BNXT_PF(bp)) { |
| 4349 | struct bnxt_pf_info *pf = &bp->pf; |
| 4350 | |
| 4351 | pf->fw_fid = le16_to_cpu(resp->fid); |
| 4352 | pf->port_id = le16_to_cpu(resp->port_id); |
Michael Chan | 87027db | 2016-07-01 18:46:28 -0400 | [diff] [blame] | 4353 | bp->dev->dev_port = pf->port_id; |
Michael Chan | 11f15ed | 2016-04-05 14:08:55 -0400 | [diff] [blame] | 4354 | memcpy(pf->mac_addr, resp->mac_address, ETH_ALEN); |
Jeffrey Huang | bdd4347 | 2015-12-02 01:54:07 -0500 | [diff] [blame] | 4355 | memcpy(bp->dev->dev_addr, pf->mac_addr, ETH_ALEN); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4356 | pf->max_rsscos_ctxs = le16_to_cpu(resp->max_rsscos_ctx); |
| 4357 | pf->max_cp_rings = le16_to_cpu(resp->max_cmpl_rings); |
| 4358 | pf->max_tx_rings = le16_to_cpu(resp->max_tx_rings); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4359 | pf->max_rx_rings = le16_to_cpu(resp->max_rx_rings); |
Michael Chan | b72d4a6 | 2015-12-27 18:19:27 -0500 | [diff] [blame] | 4360 | pf->max_hw_ring_grps = le32_to_cpu(resp->max_hw_ring_grps); |
| 4361 | if (!pf->max_hw_ring_grps) |
| 4362 | pf->max_hw_ring_grps = pf->max_tx_rings; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4363 | pf->max_l2_ctxs = le16_to_cpu(resp->max_l2_ctxs); |
| 4364 | pf->max_vnics = le16_to_cpu(resp->max_vnics); |
| 4365 | pf->max_stat_ctxs = le16_to_cpu(resp->max_stat_ctx); |
| 4366 | pf->first_vf_id = le16_to_cpu(resp->first_vf_id); |
| 4367 | pf->max_vfs = le16_to_cpu(resp->max_vfs); |
| 4368 | pf->max_encap_records = le32_to_cpu(resp->max_encap_records); |
| 4369 | pf->max_decap_records = le32_to_cpu(resp->max_decap_records); |
| 4370 | pf->max_tx_em_flows = le32_to_cpu(resp->max_tx_em_flows); |
| 4371 | pf->max_tx_wm_flows = le32_to_cpu(resp->max_tx_wm_flows); |
| 4372 | pf->max_rx_em_flows = le32_to_cpu(resp->max_rx_em_flows); |
| 4373 | pf->max_rx_wm_flows = le32_to_cpu(resp->max_rx_wm_flows); |
| 4374 | } else { |
Michael Chan | 379a80a | 2015-10-23 15:06:19 -0400 | [diff] [blame] | 4375 | #ifdef CONFIG_BNXT_SRIOV |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4376 | struct bnxt_vf_info *vf = &bp->vf; |
| 4377 | |
| 4378 | vf->fw_fid = le16_to_cpu(resp->fid); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4379 | |
| 4380 | vf->max_rsscos_ctxs = le16_to_cpu(resp->max_rsscos_ctx); |
| 4381 | vf->max_cp_rings = le16_to_cpu(resp->max_cmpl_rings); |
| 4382 | vf->max_tx_rings = le16_to_cpu(resp->max_tx_rings); |
| 4383 | vf->max_rx_rings = le16_to_cpu(resp->max_rx_rings); |
Michael Chan | b72d4a6 | 2015-12-27 18:19:27 -0500 | [diff] [blame] | 4384 | vf->max_hw_ring_grps = le32_to_cpu(resp->max_hw_ring_grps); |
| 4385 | if (!vf->max_hw_ring_grps) |
| 4386 | vf->max_hw_ring_grps = vf->max_tx_rings; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4387 | vf->max_l2_ctxs = le16_to_cpu(resp->max_l2_ctxs); |
| 4388 | vf->max_vnics = le16_to_cpu(resp->max_vnics); |
| 4389 | vf->max_stat_ctxs = le16_to_cpu(resp->max_stat_ctx); |
Michael Chan | 7cc5a20 | 2016-09-19 03:58:05 -0400 | [diff] [blame] | 4390 | |
| 4391 | memcpy(vf->mac_addr, resp->mac_address, ETH_ALEN); |
Michael Chan | 001154e | 2016-09-19 03:58:06 -0400 | [diff] [blame] | 4392 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4393 | |
| 4394 | if (is_valid_ether_addr(vf->mac_addr)) { |
Michael Chan | 7cc5a20 | 2016-09-19 03:58:05 -0400 | [diff] [blame] | 4395 | /* overwrite netdev dev_adr with admin VF MAC */ |
| 4396 | memcpy(bp->dev->dev_addr, vf->mac_addr, ETH_ALEN); |
Michael Chan | 001154e | 2016-09-19 03:58:06 -0400 | [diff] [blame] | 4397 | } else { |
Michael Chan | 7cc5a20 | 2016-09-19 03:58:05 -0400 | [diff] [blame] | 4398 | random_ether_addr(bp->dev->dev_addr); |
Michael Chan | 001154e | 2016-09-19 03:58:06 -0400 | [diff] [blame] | 4399 | rc = bnxt_approve_mac(bp, bp->dev->dev_addr); |
| 4400 | } |
| 4401 | return rc; |
Michael Chan | 379a80a | 2015-10-23 15:06:19 -0400 | [diff] [blame] | 4402 | #endif |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4403 | } |
| 4404 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4405 | hwrm_func_qcaps_exit: |
| 4406 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4407 | return rc; |
| 4408 | } |
| 4409 | |
| 4410 | static int bnxt_hwrm_func_reset(struct bnxt *bp) |
| 4411 | { |
| 4412 | struct hwrm_func_reset_input req = {0}; |
| 4413 | |
| 4414 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_RESET, -1, -1); |
| 4415 | req.enables = 0; |
| 4416 | |
| 4417 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_RESET_TIMEOUT); |
| 4418 | } |
| 4419 | |
| 4420 | static int bnxt_hwrm_queue_qportcfg(struct bnxt *bp) |
| 4421 | { |
| 4422 | int rc = 0; |
| 4423 | struct hwrm_queue_qportcfg_input req = {0}; |
| 4424 | struct hwrm_queue_qportcfg_output *resp = bp->hwrm_cmd_resp_addr; |
| 4425 | u8 i, *qptr; |
| 4426 | |
| 4427 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_QUEUE_QPORTCFG, -1, -1); |
| 4428 | |
| 4429 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4430 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4431 | if (rc) |
| 4432 | goto qportcfg_exit; |
| 4433 | |
| 4434 | if (!resp->max_configurable_queues) { |
| 4435 | rc = -EINVAL; |
| 4436 | goto qportcfg_exit; |
| 4437 | } |
| 4438 | bp->max_tc = resp->max_configurable_queues; |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 4439 | bp->max_lltc = resp->max_configurable_lossless_queues; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4440 | if (bp->max_tc > BNXT_MAX_QUEUE) |
| 4441 | bp->max_tc = BNXT_MAX_QUEUE; |
| 4442 | |
Michael Chan | 441cabb | 2016-09-19 03:58:02 -0400 | [diff] [blame] | 4443 | if (resp->queue_cfg_info & QUEUE_QPORTCFG_RESP_QUEUE_CFG_INFO_ASYM_CFG) |
| 4444 | bp->max_tc = 1; |
| 4445 | |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 4446 | if (bp->max_lltc > bp->max_tc) |
| 4447 | bp->max_lltc = bp->max_tc; |
| 4448 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4449 | qptr = &resp->queue_id0; |
| 4450 | for (i = 0; i < bp->max_tc; i++) { |
| 4451 | bp->q_info[i].queue_id = *qptr++; |
| 4452 | bp->q_info[i].queue_profile = *qptr++; |
| 4453 | } |
| 4454 | |
| 4455 | qportcfg_exit: |
| 4456 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4457 | return rc; |
| 4458 | } |
| 4459 | |
| 4460 | static int bnxt_hwrm_ver_get(struct bnxt *bp) |
| 4461 | { |
| 4462 | int rc; |
| 4463 | struct hwrm_ver_get_input req = {0}; |
| 4464 | struct hwrm_ver_get_output *resp = bp->hwrm_cmd_resp_addr; |
| 4465 | |
Michael Chan | e6ef269 | 2016-03-28 19:46:05 -0400 | [diff] [blame] | 4466 | bp->hwrm_max_req_len = HWRM_MAX_REQ_LEN; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4467 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VER_GET, -1, -1); |
| 4468 | req.hwrm_intf_maj = HWRM_VERSION_MAJOR; |
| 4469 | req.hwrm_intf_min = HWRM_VERSION_MINOR; |
| 4470 | req.hwrm_intf_upd = HWRM_VERSION_UPDATE; |
| 4471 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4472 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4473 | if (rc) |
| 4474 | goto hwrm_ver_get_exit; |
| 4475 | |
| 4476 | memcpy(&bp->ver_resp, resp, sizeof(struct hwrm_ver_get_output)); |
| 4477 | |
Michael Chan | 11f15ed | 2016-04-05 14:08:55 -0400 | [diff] [blame] | 4478 | bp->hwrm_spec_code = resp->hwrm_intf_maj << 16 | |
| 4479 | resp->hwrm_intf_min << 8 | resp->hwrm_intf_upd; |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 4480 | if (resp->hwrm_intf_maj < 1) { |
| 4481 | netdev_warn(bp->dev, "HWRM interface %d.%d.%d is older than 1.0.0.\n", |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4482 | resp->hwrm_intf_maj, resp->hwrm_intf_min, |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 4483 | resp->hwrm_intf_upd); |
| 4484 | netdev_warn(bp->dev, "Please update firmware with HWRM interface 1.0.0 or newer.\n"); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4485 | } |
Rob Swindell | 3ebf6f0 | 2016-02-26 04:00:06 -0500 | [diff] [blame] | 4486 | snprintf(bp->fw_ver_str, BC_HWRM_STR_LEN, "%d.%d.%d/%d.%d.%d", |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4487 | resp->hwrm_fw_maj, resp->hwrm_fw_min, resp->hwrm_fw_bld, |
| 4488 | resp->hwrm_intf_maj, resp->hwrm_intf_min, resp->hwrm_intf_upd); |
| 4489 | |
Michael Chan | ff4fe81 | 2016-02-26 04:00:04 -0500 | [diff] [blame] | 4490 | bp->hwrm_cmd_timeout = le16_to_cpu(resp->def_req_timeout); |
| 4491 | if (!bp->hwrm_cmd_timeout) |
| 4492 | bp->hwrm_cmd_timeout = DFLT_HWRM_CMD_TIMEOUT; |
| 4493 | |
Michael Chan | e6ef269 | 2016-03-28 19:46:05 -0400 | [diff] [blame] | 4494 | if (resp->hwrm_intf_maj >= 1) |
| 4495 | bp->hwrm_max_req_len = le16_to_cpu(resp->max_req_win_len); |
| 4496 | |
Michael Chan | 659c805 | 2016-06-13 02:25:33 -0400 | [diff] [blame] | 4497 | bp->chip_num = le16_to_cpu(resp->chip_num); |
Prashant Sreedharan | 3e8060f | 2016-07-18 07:15:20 -0400 | [diff] [blame] | 4498 | if (bp->chip_num == CHIP_NUM_58700 && !resp->chip_rev && |
| 4499 | !resp->chip_metal) |
| 4500 | bp->flags |= BNXT_FLAG_CHIP_NITRO_A0; |
Michael Chan | 659c805 | 2016-06-13 02:25:33 -0400 | [diff] [blame] | 4501 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4502 | hwrm_ver_get_exit: |
| 4503 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4504 | return rc; |
| 4505 | } |
| 4506 | |
Rob Swindell | 5ac67d8 | 2016-09-19 03:58:03 -0400 | [diff] [blame] | 4507 | int bnxt_hwrm_fw_set_time(struct bnxt *bp) |
| 4508 | { |
Rob Swindell | 878786d | 2016-09-20 03:36:33 -0400 | [diff] [blame] | 4509 | #if IS_ENABLED(CONFIG_RTC_LIB) |
Rob Swindell | 5ac67d8 | 2016-09-19 03:58:03 -0400 | [diff] [blame] | 4510 | struct hwrm_fw_set_time_input req = {0}; |
| 4511 | struct rtc_time tm; |
| 4512 | struct timeval tv; |
| 4513 | |
| 4514 | if (bp->hwrm_spec_code < 0x10400) |
| 4515 | return -EOPNOTSUPP; |
| 4516 | |
| 4517 | do_gettimeofday(&tv); |
| 4518 | rtc_time_to_tm(tv.tv_sec, &tm); |
| 4519 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_SET_TIME, -1, -1); |
| 4520 | req.year = cpu_to_le16(1900 + tm.tm_year); |
| 4521 | req.month = 1 + tm.tm_mon; |
| 4522 | req.day = tm.tm_mday; |
| 4523 | req.hour = tm.tm_hour; |
| 4524 | req.minute = tm.tm_min; |
| 4525 | req.second = tm.tm_sec; |
| 4526 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
Rob Swindell | 878786d | 2016-09-20 03:36:33 -0400 | [diff] [blame] | 4527 | #else |
| 4528 | return -EOPNOTSUPP; |
| 4529 | #endif |
Rob Swindell | 5ac67d8 | 2016-09-19 03:58:03 -0400 | [diff] [blame] | 4530 | } |
| 4531 | |
Michael Chan | 3bdf56c | 2016-03-07 15:38:45 -0500 | [diff] [blame] | 4532 | static int bnxt_hwrm_port_qstats(struct bnxt *bp) |
| 4533 | { |
| 4534 | int rc; |
| 4535 | struct bnxt_pf_info *pf = &bp->pf; |
| 4536 | struct hwrm_port_qstats_input req = {0}; |
| 4537 | |
| 4538 | if (!(bp->flags & BNXT_FLAG_PORT_STATS)) |
| 4539 | return 0; |
| 4540 | |
| 4541 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_QSTATS, -1, -1); |
| 4542 | req.port_id = cpu_to_le16(pf->port_id); |
| 4543 | req.tx_stat_host_addr = cpu_to_le64(bp->hw_tx_port_stats_map); |
| 4544 | req.rx_stat_host_addr = cpu_to_le64(bp->hw_rx_port_stats_map); |
| 4545 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4546 | return rc; |
| 4547 | } |
| 4548 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4549 | static void bnxt_hwrm_free_tunnel_ports(struct bnxt *bp) |
| 4550 | { |
| 4551 | if (bp->vxlan_port_cnt) { |
| 4552 | bnxt_hwrm_tunnel_dst_port_free( |
| 4553 | bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN); |
| 4554 | } |
| 4555 | bp->vxlan_port_cnt = 0; |
| 4556 | if (bp->nge_port_cnt) { |
| 4557 | bnxt_hwrm_tunnel_dst_port_free( |
| 4558 | bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE); |
| 4559 | } |
| 4560 | bp->nge_port_cnt = 0; |
| 4561 | } |
| 4562 | |
| 4563 | static int bnxt_set_tpa(struct bnxt *bp, bool set_tpa) |
| 4564 | { |
| 4565 | int rc, i; |
| 4566 | u32 tpa_flags = 0; |
| 4567 | |
| 4568 | if (set_tpa) |
| 4569 | tpa_flags = bp->flags & BNXT_FLAG_TPA; |
| 4570 | for (i = 0; i < bp->nr_vnics; i++) { |
| 4571 | rc = bnxt_hwrm_vnic_set_tpa(bp, i, tpa_flags); |
| 4572 | if (rc) { |
| 4573 | netdev_err(bp->dev, "hwrm vnic set tpa failure rc for vnic %d: %x\n", |
| 4574 | rc, i); |
| 4575 | return rc; |
| 4576 | } |
| 4577 | } |
| 4578 | return 0; |
| 4579 | } |
| 4580 | |
| 4581 | static void bnxt_hwrm_clear_vnic_rss(struct bnxt *bp) |
| 4582 | { |
| 4583 | int i; |
| 4584 | |
| 4585 | for (i = 0; i < bp->nr_vnics; i++) |
| 4586 | bnxt_hwrm_vnic_set_rss(bp, i, false); |
| 4587 | } |
| 4588 | |
| 4589 | static void bnxt_hwrm_resource_free(struct bnxt *bp, bool close_path, |
| 4590 | bool irq_re_init) |
| 4591 | { |
| 4592 | if (bp->vnic_info) { |
| 4593 | bnxt_hwrm_clear_vnic_filter(bp); |
| 4594 | /* clear all RSS setting before free vnic ctx */ |
| 4595 | bnxt_hwrm_clear_vnic_rss(bp); |
| 4596 | bnxt_hwrm_vnic_ctx_free(bp); |
| 4597 | /* before free the vnic, undo the vnic tpa settings */ |
| 4598 | if (bp->flags & BNXT_FLAG_TPA) |
| 4599 | bnxt_set_tpa(bp, false); |
| 4600 | bnxt_hwrm_vnic_free(bp); |
| 4601 | } |
| 4602 | bnxt_hwrm_ring_free(bp, close_path); |
| 4603 | bnxt_hwrm_ring_grp_free(bp); |
| 4604 | if (irq_re_init) { |
| 4605 | bnxt_hwrm_stat_ctx_free(bp); |
| 4606 | bnxt_hwrm_free_tunnel_ports(bp); |
| 4607 | } |
| 4608 | } |
| 4609 | |
| 4610 | static int bnxt_setup_vnic(struct bnxt *bp, u16 vnic_id) |
| 4611 | { |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 4612 | struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4613 | int rc; |
| 4614 | |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 4615 | if (vnic->flags & BNXT_VNIC_RFS_NEW_RSS_FLAG) |
| 4616 | goto skip_rss_ctx; |
| 4617 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4618 | /* allocate context for vnic */ |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 4619 | rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic_id, 0); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4620 | if (rc) { |
| 4621 | netdev_err(bp->dev, "hwrm vnic %d alloc failure rc: %x\n", |
| 4622 | vnic_id, rc); |
| 4623 | goto vnic_setup_err; |
| 4624 | } |
| 4625 | bp->rsscos_nr_ctxs++; |
| 4626 | |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 4627 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) { |
| 4628 | rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic_id, 1); |
| 4629 | if (rc) { |
| 4630 | netdev_err(bp->dev, "hwrm vnic %d cos ctx alloc failure rc: %x\n", |
| 4631 | vnic_id, rc); |
| 4632 | goto vnic_setup_err; |
| 4633 | } |
| 4634 | bp->rsscos_nr_ctxs++; |
| 4635 | } |
| 4636 | |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 4637 | skip_rss_ctx: |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4638 | /* configure default vnic, ring grp */ |
| 4639 | rc = bnxt_hwrm_vnic_cfg(bp, vnic_id); |
| 4640 | if (rc) { |
| 4641 | netdev_err(bp->dev, "hwrm vnic %d cfg failure rc: %x\n", |
| 4642 | vnic_id, rc); |
| 4643 | goto vnic_setup_err; |
| 4644 | } |
| 4645 | |
| 4646 | /* Enable RSS hashing on vnic */ |
| 4647 | rc = bnxt_hwrm_vnic_set_rss(bp, vnic_id, true); |
| 4648 | if (rc) { |
| 4649 | netdev_err(bp->dev, "hwrm vnic %d set rss failure rc: %x\n", |
| 4650 | vnic_id, rc); |
| 4651 | goto vnic_setup_err; |
| 4652 | } |
| 4653 | |
| 4654 | if (bp->flags & BNXT_FLAG_AGG_RINGS) { |
| 4655 | rc = bnxt_hwrm_vnic_set_hds(bp, vnic_id); |
| 4656 | if (rc) { |
| 4657 | netdev_err(bp->dev, "hwrm vnic %d set hds failure rc: %x\n", |
| 4658 | vnic_id, rc); |
| 4659 | } |
| 4660 | } |
| 4661 | |
| 4662 | vnic_setup_err: |
| 4663 | return rc; |
| 4664 | } |
| 4665 | |
| 4666 | static int bnxt_alloc_rfs_vnics(struct bnxt *bp) |
| 4667 | { |
| 4668 | #ifdef CONFIG_RFS_ACCEL |
| 4669 | int i, rc = 0; |
| 4670 | |
| 4671 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 4672 | struct bnxt_vnic_info *vnic; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4673 | u16 vnic_id = i + 1; |
| 4674 | u16 ring_id = i; |
| 4675 | |
| 4676 | if (vnic_id >= bp->nr_vnics) |
| 4677 | break; |
| 4678 | |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 4679 | vnic = &bp->vnic_info[vnic_id]; |
| 4680 | vnic->flags |= BNXT_VNIC_RFS_FLAG; |
| 4681 | if (bp->flags & BNXT_FLAG_NEW_RSS_CAP) |
| 4682 | vnic->flags |= BNXT_VNIC_RFS_NEW_RSS_FLAG; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4683 | rc = bnxt_hwrm_vnic_alloc(bp, vnic_id, ring_id, 1); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4684 | if (rc) { |
| 4685 | netdev_err(bp->dev, "hwrm vnic %d alloc failure rc: %x\n", |
| 4686 | vnic_id, rc); |
| 4687 | break; |
| 4688 | } |
| 4689 | rc = bnxt_setup_vnic(bp, vnic_id); |
| 4690 | if (rc) |
| 4691 | break; |
| 4692 | } |
| 4693 | return rc; |
| 4694 | #else |
| 4695 | return 0; |
| 4696 | #endif |
| 4697 | } |
| 4698 | |
Michael Chan | 17c71ac | 2016-07-01 18:46:27 -0400 | [diff] [blame] | 4699 | /* Allow PF and VF with default VLAN to be in promiscuous mode */ |
| 4700 | static bool bnxt_promisc_ok(struct bnxt *bp) |
| 4701 | { |
| 4702 | #ifdef CONFIG_BNXT_SRIOV |
| 4703 | if (BNXT_VF(bp) && !bp->vf.vlan) |
| 4704 | return false; |
| 4705 | #endif |
| 4706 | return true; |
| 4707 | } |
| 4708 | |
Prashant Sreedharan | dc52c6c | 2016-07-18 07:15:24 -0400 | [diff] [blame] | 4709 | static int bnxt_setup_nitroa0_vnic(struct bnxt *bp) |
| 4710 | { |
| 4711 | unsigned int rc = 0; |
| 4712 | |
| 4713 | rc = bnxt_hwrm_vnic_alloc(bp, 1, bp->rx_nr_rings - 1, 1); |
| 4714 | if (rc) { |
| 4715 | netdev_err(bp->dev, "Cannot allocate special vnic for NS2 A0: %x\n", |
| 4716 | rc); |
| 4717 | return rc; |
| 4718 | } |
| 4719 | |
| 4720 | rc = bnxt_hwrm_vnic_cfg(bp, 1); |
| 4721 | if (rc) { |
| 4722 | netdev_err(bp->dev, "Cannot allocate special vnic for NS2 A0: %x\n", |
| 4723 | rc); |
| 4724 | return rc; |
| 4725 | } |
| 4726 | return rc; |
| 4727 | } |
| 4728 | |
Michael Chan | b664f00 | 2015-12-02 01:54:08 -0500 | [diff] [blame] | 4729 | static int bnxt_cfg_rx_mode(struct bnxt *); |
Michael Chan | 7d2837d | 2016-05-04 16:56:44 -0400 | [diff] [blame] | 4730 | static bool bnxt_mc_list_updated(struct bnxt *, u32 *); |
Michael Chan | b664f00 | 2015-12-02 01:54:08 -0500 | [diff] [blame] | 4731 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4732 | static int bnxt_init_chip(struct bnxt *bp, bool irq_re_init) |
| 4733 | { |
Michael Chan | 7d2837d | 2016-05-04 16:56:44 -0400 | [diff] [blame] | 4734 | struct bnxt_vnic_info *vnic = &bp->vnic_info[0]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4735 | int rc = 0; |
Prashant Sreedharan | 7659519 | 2016-07-18 07:15:22 -0400 | [diff] [blame] | 4736 | unsigned int rx_nr_rings = bp->rx_nr_rings; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4737 | |
| 4738 | if (irq_re_init) { |
| 4739 | rc = bnxt_hwrm_stat_ctx_alloc(bp); |
| 4740 | if (rc) { |
| 4741 | netdev_err(bp->dev, "hwrm stat ctx alloc failure rc: %x\n", |
| 4742 | rc); |
| 4743 | goto err_out; |
| 4744 | } |
| 4745 | } |
| 4746 | |
| 4747 | rc = bnxt_hwrm_ring_alloc(bp); |
| 4748 | if (rc) { |
| 4749 | netdev_err(bp->dev, "hwrm ring alloc failure rc: %x\n", rc); |
| 4750 | goto err_out; |
| 4751 | } |
| 4752 | |
| 4753 | rc = bnxt_hwrm_ring_grp_alloc(bp); |
| 4754 | if (rc) { |
| 4755 | netdev_err(bp->dev, "hwrm_ring_grp alloc failure: %x\n", rc); |
| 4756 | goto err_out; |
| 4757 | } |
| 4758 | |
Prashant Sreedharan | 7659519 | 2016-07-18 07:15:22 -0400 | [diff] [blame] | 4759 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 4760 | rx_nr_rings--; |
| 4761 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4762 | /* default vnic 0 */ |
Prashant Sreedharan | 7659519 | 2016-07-18 07:15:22 -0400 | [diff] [blame] | 4763 | rc = bnxt_hwrm_vnic_alloc(bp, 0, 0, rx_nr_rings); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4764 | if (rc) { |
| 4765 | netdev_err(bp->dev, "hwrm vnic alloc failure rc: %x\n", rc); |
| 4766 | goto err_out; |
| 4767 | } |
| 4768 | |
| 4769 | rc = bnxt_setup_vnic(bp, 0); |
| 4770 | if (rc) |
| 4771 | goto err_out; |
| 4772 | |
| 4773 | if (bp->flags & BNXT_FLAG_RFS) { |
| 4774 | rc = bnxt_alloc_rfs_vnics(bp); |
| 4775 | if (rc) |
| 4776 | goto err_out; |
| 4777 | } |
| 4778 | |
| 4779 | if (bp->flags & BNXT_FLAG_TPA) { |
| 4780 | rc = bnxt_set_tpa(bp, true); |
| 4781 | if (rc) |
| 4782 | goto err_out; |
| 4783 | } |
| 4784 | |
| 4785 | if (BNXT_VF(bp)) |
| 4786 | bnxt_update_vf_mac(bp); |
| 4787 | |
| 4788 | /* Filter for default vnic 0 */ |
| 4789 | rc = bnxt_hwrm_set_vnic_filter(bp, 0, 0, bp->dev->dev_addr); |
| 4790 | if (rc) { |
| 4791 | netdev_err(bp->dev, "HWRM vnic filter failure rc: %x\n", rc); |
| 4792 | goto err_out; |
| 4793 | } |
Michael Chan | 7d2837d | 2016-05-04 16:56:44 -0400 | [diff] [blame] | 4794 | vnic->uc_filter_count = 1; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4795 | |
Michael Chan | 7d2837d | 2016-05-04 16:56:44 -0400 | [diff] [blame] | 4796 | vnic->rx_mask = CFA_L2_SET_RX_MASK_REQ_MASK_BCAST; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4797 | |
Michael Chan | 17c71ac | 2016-07-01 18:46:27 -0400 | [diff] [blame] | 4798 | if ((bp->dev->flags & IFF_PROMISC) && bnxt_promisc_ok(bp)) |
Michael Chan | 7d2837d | 2016-05-04 16:56:44 -0400 | [diff] [blame] | 4799 | vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS; |
| 4800 | |
| 4801 | if (bp->dev->flags & IFF_ALLMULTI) { |
| 4802 | vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST; |
| 4803 | vnic->mc_list_count = 0; |
| 4804 | } else { |
| 4805 | u32 mask = 0; |
| 4806 | |
| 4807 | bnxt_mc_list_updated(bp, &mask); |
| 4808 | vnic->rx_mask |= mask; |
| 4809 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4810 | |
Michael Chan | b664f00 | 2015-12-02 01:54:08 -0500 | [diff] [blame] | 4811 | rc = bnxt_cfg_rx_mode(bp); |
| 4812 | if (rc) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4813 | goto err_out; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4814 | |
| 4815 | rc = bnxt_hwrm_set_coal(bp); |
| 4816 | if (rc) |
| 4817 | netdev_warn(bp->dev, "HWRM set coalescing failure rc: %x\n", |
Prashant Sreedharan | dc52c6c | 2016-07-18 07:15:24 -0400 | [diff] [blame] | 4818 | rc); |
| 4819 | |
| 4820 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) { |
| 4821 | rc = bnxt_setup_nitroa0_vnic(bp); |
| 4822 | if (rc) |
| 4823 | netdev_err(bp->dev, "Special vnic setup failure for NS2 A0 rc: %x\n", |
| 4824 | rc); |
| 4825 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4826 | |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 4827 | if (BNXT_VF(bp)) { |
| 4828 | bnxt_hwrm_func_qcfg(bp); |
| 4829 | netdev_update_features(bp->dev); |
| 4830 | } |
| 4831 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4832 | return 0; |
| 4833 | |
| 4834 | err_out: |
| 4835 | bnxt_hwrm_resource_free(bp, 0, true); |
| 4836 | |
| 4837 | return rc; |
| 4838 | } |
| 4839 | |
| 4840 | static int bnxt_shutdown_nic(struct bnxt *bp, bool irq_re_init) |
| 4841 | { |
| 4842 | bnxt_hwrm_resource_free(bp, 1, irq_re_init); |
| 4843 | return 0; |
| 4844 | } |
| 4845 | |
| 4846 | static int bnxt_init_nic(struct bnxt *bp, bool irq_re_init) |
| 4847 | { |
| 4848 | bnxt_init_rx_rings(bp); |
| 4849 | bnxt_init_tx_rings(bp); |
| 4850 | bnxt_init_ring_grps(bp, irq_re_init); |
| 4851 | bnxt_init_vnics(bp); |
| 4852 | |
| 4853 | return bnxt_init_chip(bp, irq_re_init); |
| 4854 | } |
| 4855 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4856 | static int bnxt_set_real_num_queues(struct bnxt *bp) |
| 4857 | { |
| 4858 | int rc; |
| 4859 | struct net_device *dev = bp->dev; |
| 4860 | |
| 4861 | rc = netif_set_real_num_tx_queues(dev, bp->tx_nr_rings); |
| 4862 | if (rc) |
| 4863 | return rc; |
| 4864 | |
| 4865 | rc = netif_set_real_num_rx_queues(dev, bp->rx_nr_rings); |
| 4866 | if (rc) |
| 4867 | return rc; |
| 4868 | |
| 4869 | #ifdef CONFIG_RFS_ACCEL |
Michael Chan | 45019a1 | 2015-12-27 18:19:22 -0500 | [diff] [blame] | 4870 | if (bp->flags & BNXT_FLAG_RFS) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4871 | dev->rx_cpu_rmap = alloc_irq_cpu_rmap(bp->rx_nr_rings); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4872 | #endif |
| 4873 | |
| 4874 | return rc; |
| 4875 | } |
| 4876 | |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 4877 | static int bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max, |
| 4878 | bool shared) |
| 4879 | { |
| 4880 | int _rx = *rx, _tx = *tx; |
| 4881 | |
| 4882 | if (shared) { |
| 4883 | *rx = min_t(int, _rx, max); |
| 4884 | *tx = min_t(int, _tx, max); |
| 4885 | } else { |
| 4886 | if (max < 2) |
| 4887 | return -ENOMEM; |
| 4888 | |
| 4889 | while (_rx + _tx > max) { |
| 4890 | if (_rx > _tx && _rx > 1) |
| 4891 | _rx--; |
| 4892 | else if (_tx > 1) |
| 4893 | _tx--; |
| 4894 | } |
| 4895 | *rx = _rx; |
| 4896 | *tx = _tx; |
| 4897 | } |
| 4898 | return 0; |
| 4899 | } |
| 4900 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 4901 | static void bnxt_setup_msix(struct bnxt *bp) |
| 4902 | { |
| 4903 | const int len = sizeof(bp->irq_tbl[0].name); |
| 4904 | struct net_device *dev = bp->dev; |
| 4905 | int tcs, i; |
| 4906 | |
| 4907 | tcs = netdev_get_num_tc(dev); |
| 4908 | if (tcs > 1) { |
| 4909 | bp->tx_nr_rings_per_tc = bp->tx_nr_rings / tcs; |
| 4910 | if (bp->tx_nr_rings_per_tc == 0) { |
| 4911 | netdev_reset_tc(dev); |
| 4912 | bp->tx_nr_rings_per_tc = bp->tx_nr_rings; |
| 4913 | } else { |
| 4914 | int i, off, count; |
| 4915 | |
| 4916 | bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tcs; |
| 4917 | for (i = 0; i < tcs; i++) { |
| 4918 | count = bp->tx_nr_rings_per_tc; |
| 4919 | off = i * count; |
| 4920 | netdev_set_tc_queue(dev, i, count, off); |
| 4921 | } |
| 4922 | } |
| 4923 | } |
| 4924 | |
| 4925 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 4926 | char *attr; |
| 4927 | |
| 4928 | if (bp->flags & BNXT_FLAG_SHARED_RINGS) |
| 4929 | attr = "TxRx"; |
| 4930 | else if (i < bp->rx_nr_rings) |
| 4931 | attr = "rx"; |
| 4932 | else |
| 4933 | attr = "tx"; |
| 4934 | |
| 4935 | snprintf(bp->irq_tbl[i].name, len, "%s-%s-%d", dev->name, attr, |
| 4936 | i); |
| 4937 | bp->irq_tbl[i].handler = bnxt_msix; |
| 4938 | } |
| 4939 | } |
| 4940 | |
| 4941 | static void bnxt_setup_inta(struct bnxt *bp) |
| 4942 | { |
| 4943 | const int len = sizeof(bp->irq_tbl[0].name); |
| 4944 | |
| 4945 | if (netdev_get_num_tc(bp->dev)) |
| 4946 | netdev_reset_tc(bp->dev); |
| 4947 | |
| 4948 | snprintf(bp->irq_tbl[0].name, len, "%s-%s-%d", bp->dev->name, "TxRx", |
| 4949 | 0); |
| 4950 | bp->irq_tbl[0].handler = bnxt_inta; |
| 4951 | } |
| 4952 | |
| 4953 | static int bnxt_setup_int_mode(struct bnxt *bp) |
| 4954 | { |
| 4955 | int rc; |
| 4956 | |
| 4957 | if (bp->flags & BNXT_FLAG_USING_MSIX) |
| 4958 | bnxt_setup_msix(bp); |
| 4959 | else |
| 4960 | bnxt_setup_inta(bp); |
| 4961 | |
| 4962 | rc = bnxt_set_real_num_queues(bp); |
| 4963 | return rc; |
| 4964 | } |
| 4965 | |
Michael Chan | b742995 | 2017-01-13 01:32:00 -0500 | [diff] [blame] | 4966 | #ifdef CONFIG_RFS_ACCEL |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 4967 | static unsigned int bnxt_get_max_func_rss_ctxs(struct bnxt *bp) |
| 4968 | { |
| 4969 | #if defined(CONFIG_BNXT_SRIOV) |
| 4970 | if (BNXT_VF(bp)) |
| 4971 | return bp->vf.max_rsscos_ctxs; |
| 4972 | #endif |
| 4973 | return bp->pf.max_rsscos_ctxs; |
| 4974 | } |
| 4975 | |
| 4976 | static unsigned int bnxt_get_max_func_vnics(struct bnxt *bp) |
| 4977 | { |
| 4978 | #if defined(CONFIG_BNXT_SRIOV) |
| 4979 | if (BNXT_VF(bp)) |
| 4980 | return bp->vf.max_vnics; |
| 4981 | #endif |
| 4982 | return bp->pf.max_vnics; |
| 4983 | } |
Michael Chan | b742995 | 2017-01-13 01:32:00 -0500 | [diff] [blame] | 4984 | #endif |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 4985 | |
Michael Chan | e4060d3 | 2016-12-07 00:26:19 -0500 | [diff] [blame] | 4986 | unsigned int bnxt_get_max_func_stat_ctxs(struct bnxt *bp) |
| 4987 | { |
| 4988 | #if defined(CONFIG_BNXT_SRIOV) |
| 4989 | if (BNXT_VF(bp)) |
| 4990 | return bp->vf.max_stat_ctxs; |
| 4991 | #endif |
| 4992 | return bp->pf.max_stat_ctxs; |
| 4993 | } |
| 4994 | |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 4995 | void bnxt_set_max_func_stat_ctxs(struct bnxt *bp, unsigned int max) |
| 4996 | { |
| 4997 | #if defined(CONFIG_BNXT_SRIOV) |
| 4998 | if (BNXT_VF(bp)) |
| 4999 | bp->vf.max_stat_ctxs = max; |
| 5000 | else |
| 5001 | #endif |
| 5002 | bp->pf.max_stat_ctxs = max; |
| 5003 | } |
| 5004 | |
Michael Chan | e4060d3 | 2016-12-07 00:26:19 -0500 | [diff] [blame] | 5005 | unsigned int bnxt_get_max_func_cp_rings(struct bnxt *bp) |
| 5006 | { |
| 5007 | #if defined(CONFIG_BNXT_SRIOV) |
| 5008 | if (BNXT_VF(bp)) |
| 5009 | return bp->vf.max_cp_rings; |
| 5010 | #endif |
| 5011 | return bp->pf.max_cp_rings; |
| 5012 | } |
| 5013 | |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 5014 | void bnxt_set_max_func_cp_rings(struct bnxt *bp, unsigned int max) |
| 5015 | { |
| 5016 | #if defined(CONFIG_BNXT_SRIOV) |
| 5017 | if (BNXT_VF(bp)) |
| 5018 | bp->vf.max_cp_rings = max; |
| 5019 | else |
| 5020 | #endif |
| 5021 | bp->pf.max_cp_rings = max; |
| 5022 | } |
| 5023 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5024 | static unsigned int bnxt_get_max_func_irqs(struct bnxt *bp) |
| 5025 | { |
| 5026 | #if defined(CONFIG_BNXT_SRIOV) |
| 5027 | if (BNXT_VF(bp)) |
| 5028 | return bp->vf.max_irqs; |
| 5029 | #endif |
| 5030 | return bp->pf.max_irqs; |
| 5031 | } |
| 5032 | |
Michael Chan | 33c2657 | 2016-12-07 00:26:15 -0500 | [diff] [blame] | 5033 | void bnxt_set_max_func_irqs(struct bnxt *bp, unsigned int max_irqs) |
| 5034 | { |
| 5035 | #if defined(CONFIG_BNXT_SRIOV) |
| 5036 | if (BNXT_VF(bp)) |
| 5037 | bp->vf.max_irqs = max_irqs; |
| 5038 | else |
| 5039 | #endif |
| 5040 | bp->pf.max_irqs = max_irqs; |
| 5041 | } |
| 5042 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5043 | static int bnxt_init_msix(struct bnxt *bp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5044 | { |
Michael Chan | 01657bc | 2016-01-02 23:45:03 -0500 | [diff] [blame] | 5045 | int i, total_vecs, rc = 0, min = 1; |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5046 | struct msix_entry *msix_ent; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5047 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5048 | total_vecs = bnxt_get_max_func_irqs(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5049 | msix_ent = kcalloc(total_vecs, sizeof(struct msix_entry), GFP_KERNEL); |
| 5050 | if (!msix_ent) |
| 5051 | return -ENOMEM; |
| 5052 | |
| 5053 | for (i = 0; i < total_vecs; i++) { |
| 5054 | msix_ent[i].entry = i; |
| 5055 | msix_ent[i].vector = 0; |
| 5056 | } |
| 5057 | |
Michael Chan | 01657bc | 2016-01-02 23:45:03 -0500 | [diff] [blame] | 5058 | if (!(bp->flags & BNXT_FLAG_SHARED_RINGS)) |
| 5059 | min = 2; |
| 5060 | |
| 5061 | total_vecs = pci_enable_msix_range(bp->pdev, msix_ent, min, total_vecs); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5062 | if (total_vecs < 0) { |
| 5063 | rc = -ENODEV; |
| 5064 | goto msix_setup_exit; |
| 5065 | } |
| 5066 | |
| 5067 | bp->irq_tbl = kcalloc(total_vecs, sizeof(struct bnxt_irq), GFP_KERNEL); |
| 5068 | if (bp->irq_tbl) { |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5069 | for (i = 0; i < total_vecs; i++) |
| 5070 | bp->irq_tbl[i].vector = msix_ent[i].vector; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5071 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5072 | bp->total_irqs = total_vecs; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5073 | /* Trim rings based upon num of vectors allocated */ |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 5074 | rc = bnxt_trim_rings(bp, &bp->rx_nr_rings, &bp->tx_nr_rings, |
Michael Chan | 01657bc | 2016-01-02 23:45:03 -0500 | [diff] [blame] | 5075 | total_vecs, min == 1); |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 5076 | if (rc) |
| 5077 | goto msix_setup_exit; |
| 5078 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5079 | bp->tx_nr_rings_per_tc = bp->tx_nr_rings; |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5080 | bp->cp_nr_rings = (min == 1) ? |
| 5081 | max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) : |
| 5082 | bp->tx_nr_rings + bp->rx_nr_rings; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5083 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5084 | } else { |
| 5085 | rc = -ENOMEM; |
| 5086 | goto msix_setup_exit; |
| 5087 | } |
| 5088 | bp->flags |= BNXT_FLAG_USING_MSIX; |
| 5089 | kfree(msix_ent); |
| 5090 | return 0; |
| 5091 | |
| 5092 | msix_setup_exit: |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5093 | netdev_err(bp->dev, "bnxt_init_msix err: %x\n", rc); |
| 5094 | kfree(bp->irq_tbl); |
| 5095 | bp->irq_tbl = NULL; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5096 | pci_disable_msix(bp->pdev); |
| 5097 | kfree(msix_ent); |
| 5098 | return rc; |
| 5099 | } |
| 5100 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5101 | static int bnxt_init_inta(struct bnxt *bp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5102 | { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5103 | bp->irq_tbl = kcalloc(1, sizeof(struct bnxt_irq), GFP_KERNEL); |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5104 | if (!bp->irq_tbl) |
| 5105 | return -ENOMEM; |
| 5106 | |
| 5107 | bp->total_irqs = 1; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5108 | bp->rx_nr_rings = 1; |
| 5109 | bp->tx_nr_rings = 1; |
| 5110 | bp->cp_nr_rings = 1; |
| 5111 | bp->tx_nr_rings_per_tc = bp->tx_nr_rings; |
Michael Chan | 01657bc | 2016-01-02 23:45:03 -0500 | [diff] [blame] | 5112 | bp->flags |= BNXT_FLAG_SHARED_RINGS; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5113 | bp->irq_tbl[0].vector = bp->pdev->irq; |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5114 | return 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5115 | } |
| 5116 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5117 | static int bnxt_init_int_mode(struct bnxt *bp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5118 | { |
| 5119 | int rc = 0; |
| 5120 | |
| 5121 | if (bp->flags & BNXT_FLAG_MSIX_CAP) |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5122 | rc = bnxt_init_msix(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5123 | |
Michael Chan | 1fa72e2 | 2016-04-25 02:30:49 -0400 | [diff] [blame] | 5124 | if (!(bp->flags & BNXT_FLAG_USING_MSIX) && BNXT_PF(bp)) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5125 | /* fallback to INTA */ |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5126 | rc = bnxt_init_inta(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5127 | } |
| 5128 | return rc; |
| 5129 | } |
| 5130 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5131 | static void bnxt_clear_int_mode(struct bnxt *bp) |
| 5132 | { |
| 5133 | if (bp->flags & BNXT_FLAG_USING_MSIX) |
| 5134 | pci_disable_msix(bp->pdev); |
| 5135 | |
| 5136 | kfree(bp->irq_tbl); |
| 5137 | bp->irq_tbl = NULL; |
| 5138 | bp->flags &= ~BNXT_FLAG_USING_MSIX; |
| 5139 | } |
| 5140 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5141 | static void bnxt_free_irq(struct bnxt *bp) |
| 5142 | { |
| 5143 | struct bnxt_irq *irq; |
| 5144 | int i; |
| 5145 | |
| 5146 | #ifdef CONFIG_RFS_ACCEL |
| 5147 | free_irq_cpu_rmap(bp->dev->rx_cpu_rmap); |
| 5148 | bp->dev->rx_cpu_rmap = NULL; |
| 5149 | #endif |
| 5150 | if (!bp->irq_tbl) |
| 5151 | return; |
| 5152 | |
| 5153 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 5154 | irq = &bp->irq_tbl[i]; |
| 5155 | if (irq->requested) |
| 5156 | free_irq(irq->vector, bp->bnapi[i]); |
| 5157 | irq->requested = 0; |
| 5158 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5159 | } |
| 5160 | |
| 5161 | static int bnxt_request_irq(struct bnxt *bp) |
| 5162 | { |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 5163 | int i, j, rc = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5164 | unsigned long flags = 0; |
| 5165 | #ifdef CONFIG_RFS_ACCEL |
| 5166 | struct cpu_rmap *rmap = bp->dev->rx_cpu_rmap; |
| 5167 | #endif |
| 5168 | |
| 5169 | if (!(bp->flags & BNXT_FLAG_USING_MSIX)) |
| 5170 | flags = IRQF_SHARED; |
| 5171 | |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 5172 | for (i = 0, j = 0; i < bp->cp_nr_rings; i++) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5173 | struct bnxt_irq *irq = &bp->irq_tbl[i]; |
| 5174 | #ifdef CONFIG_RFS_ACCEL |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 5175 | if (rmap && bp->bnapi[i]->rx_ring) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5176 | rc = irq_cpu_rmap_add(rmap, irq->vector); |
| 5177 | if (rc) |
| 5178 | netdev_warn(bp->dev, "failed adding irq rmap for ring %d\n", |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 5179 | j); |
| 5180 | j++; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5181 | } |
| 5182 | #endif |
| 5183 | rc = request_irq(irq->vector, irq->handler, flags, irq->name, |
| 5184 | bp->bnapi[i]); |
| 5185 | if (rc) |
| 5186 | break; |
| 5187 | |
| 5188 | irq->requested = 1; |
| 5189 | } |
| 5190 | return rc; |
| 5191 | } |
| 5192 | |
| 5193 | static void bnxt_del_napi(struct bnxt *bp) |
| 5194 | { |
| 5195 | int i; |
| 5196 | |
| 5197 | if (!bp->bnapi) |
| 5198 | return; |
| 5199 | |
| 5200 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 5201 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 5202 | |
| 5203 | napi_hash_del(&bnapi->napi); |
| 5204 | netif_napi_del(&bnapi->napi); |
| 5205 | } |
Eric Dumazet | e5f6f56 | 2016-11-16 06:31:52 -0800 | [diff] [blame] | 5206 | /* We called napi_hash_del() before netif_napi_del(), we need |
| 5207 | * to respect an RCU grace period before freeing napi structures. |
| 5208 | */ |
| 5209 | synchronize_net(); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5210 | } |
| 5211 | |
| 5212 | static void bnxt_init_napi(struct bnxt *bp) |
| 5213 | { |
| 5214 | int i; |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 5215 | unsigned int cp_nr_rings = bp->cp_nr_rings; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5216 | struct bnxt_napi *bnapi; |
| 5217 | |
| 5218 | if (bp->flags & BNXT_FLAG_USING_MSIX) { |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 5219 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 5220 | cp_nr_rings--; |
| 5221 | for (i = 0; i < cp_nr_rings; i++) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5222 | bnapi = bp->bnapi[i]; |
| 5223 | netif_napi_add(bp->dev, &bnapi->napi, |
| 5224 | bnxt_poll, 64); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5225 | } |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 5226 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) { |
| 5227 | bnapi = bp->bnapi[cp_nr_rings]; |
| 5228 | netif_napi_add(bp->dev, &bnapi->napi, |
| 5229 | bnxt_poll_nitroa0, 64); |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 5230 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5231 | } else { |
| 5232 | bnapi = bp->bnapi[0]; |
| 5233 | netif_napi_add(bp->dev, &bnapi->napi, bnxt_poll, 64); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5234 | } |
| 5235 | } |
| 5236 | |
| 5237 | static void bnxt_disable_napi(struct bnxt *bp) |
| 5238 | { |
| 5239 | int i; |
| 5240 | |
| 5241 | if (!bp->bnapi) |
| 5242 | return; |
| 5243 | |
Michael Chan | b356a2e | 2016-12-29 12:13:31 -0500 | [diff] [blame] | 5244 | for (i = 0; i < bp->cp_nr_rings; i++) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5245 | napi_disable(&bp->bnapi[i]->napi); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5246 | } |
| 5247 | |
| 5248 | static void bnxt_enable_napi(struct bnxt *bp) |
| 5249 | { |
| 5250 | int i; |
| 5251 | |
| 5252 | for (i = 0; i < bp->cp_nr_rings; i++) { |
Michael Chan | fa7e281 | 2016-05-10 19:18:00 -0400 | [diff] [blame] | 5253 | bp->bnapi[i]->in_reset = false; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5254 | napi_enable(&bp->bnapi[i]->napi); |
| 5255 | } |
| 5256 | } |
| 5257 | |
Michael Chan | 7df4ae9 | 2016-12-02 21:17:17 -0500 | [diff] [blame] | 5258 | void bnxt_tx_disable(struct bnxt *bp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5259 | { |
| 5260 | int i; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5261 | struct bnxt_tx_ring_info *txr; |
| 5262 | struct netdev_queue *txq; |
| 5263 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 5264 | if (bp->tx_ring) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5265 | for (i = 0; i < bp->tx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 5266 | txr = &bp->tx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5267 | txq = netdev_get_tx_queue(bp->dev, i); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5268 | txr->dev_state = BNXT_DEV_STATE_CLOSING; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5269 | } |
| 5270 | } |
| 5271 | /* Stop all TX queues */ |
| 5272 | netif_tx_disable(bp->dev); |
| 5273 | netif_carrier_off(bp->dev); |
| 5274 | } |
| 5275 | |
Michael Chan | 7df4ae9 | 2016-12-02 21:17:17 -0500 | [diff] [blame] | 5276 | void bnxt_tx_enable(struct bnxt *bp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5277 | { |
| 5278 | int i; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5279 | struct bnxt_tx_ring_info *txr; |
| 5280 | struct netdev_queue *txq; |
| 5281 | |
| 5282 | for (i = 0; i < bp->tx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 5283 | txr = &bp->tx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5284 | txq = netdev_get_tx_queue(bp->dev, i); |
| 5285 | txr->dev_state = 0; |
| 5286 | } |
| 5287 | netif_tx_wake_all_queues(bp->dev); |
| 5288 | if (bp->link_info.link_up) |
| 5289 | netif_carrier_on(bp->dev); |
| 5290 | } |
| 5291 | |
| 5292 | static void bnxt_report_link(struct bnxt *bp) |
| 5293 | { |
| 5294 | if (bp->link_info.link_up) { |
| 5295 | const char *duplex; |
| 5296 | const char *flow_ctrl; |
| 5297 | u16 speed; |
| 5298 | |
| 5299 | netif_carrier_on(bp->dev); |
| 5300 | if (bp->link_info.duplex == BNXT_LINK_DUPLEX_FULL) |
| 5301 | duplex = "full"; |
| 5302 | else |
| 5303 | duplex = "half"; |
| 5304 | if (bp->link_info.pause == BNXT_LINK_PAUSE_BOTH) |
| 5305 | flow_ctrl = "ON - receive & transmit"; |
| 5306 | else if (bp->link_info.pause == BNXT_LINK_PAUSE_TX) |
| 5307 | flow_ctrl = "ON - transmit"; |
| 5308 | else if (bp->link_info.pause == BNXT_LINK_PAUSE_RX) |
| 5309 | flow_ctrl = "ON - receive"; |
| 5310 | else |
| 5311 | flow_ctrl = "none"; |
| 5312 | speed = bnxt_fw_to_ethtool_speed(bp->link_info.link_speed); |
| 5313 | netdev_info(bp->dev, "NIC Link is Up, %d Mbps %s duplex, Flow control: %s\n", |
| 5314 | speed, duplex, flow_ctrl); |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 5315 | if (bp->flags & BNXT_FLAG_EEE_CAP) |
| 5316 | netdev_info(bp->dev, "EEE is %s\n", |
| 5317 | bp->eee.eee_active ? "active" : |
| 5318 | "not active"); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5319 | } else { |
| 5320 | netif_carrier_off(bp->dev); |
| 5321 | netdev_err(bp->dev, "NIC Link is Down\n"); |
| 5322 | } |
| 5323 | } |
| 5324 | |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 5325 | static int bnxt_hwrm_phy_qcaps(struct bnxt *bp) |
| 5326 | { |
| 5327 | int rc = 0; |
| 5328 | struct hwrm_port_phy_qcaps_input req = {0}; |
| 5329 | struct hwrm_port_phy_qcaps_output *resp = bp->hwrm_cmd_resp_addr; |
Michael Chan | 93ed811 | 2016-06-13 02:25:37 -0400 | [diff] [blame] | 5330 | struct bnxt_link_info *link_info = &bp->link_info; |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 5331 | |
| 5332 | if (bp->hwrm_spec_code < 0x10201) |
| 5333 | return 0; |
| 5334 | |
| 5335 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCAPS, -1, -1); |
| 5336 | |
| 5337 | mutex_lock(&bp->hwrm_cmd_lock); |
| 5338 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5339 | if (rc) |
| 5340 | goto hwrm_phy_qcaps_exit; |
| 5341 | |
| 5342 | if (resp->eee_supported & PORT_PHY_QCAPS_RESP_EEE_SUPPORTED) { |
| 5343 | struct ethtool_eee *eee = &bp->eee; |
| 5344 | u16 fw_speeds = le16_to_cpu(resp->supported_speeds_eee_mode); |
| 5345 | |
| 5346 | bp->flags |= BNXT_FLAG_EEE_CAP; |
| 5347 | eee->supported = _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0); |
| 5348 | bp->lpi_tmr_lo = le32_to_cpu(resp->tx_lpi_timer_low) & |
| 5349 | PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_LOW_MASK; |
| 5350 | bp->lpi_tmr_hi = le32_to_cpu(resp->valid_tx_lpi_timer_high) & |
| 5351 | PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_HIGH_MASK; |
| 5352 | } |
Michael Chan | 93ed811 | 2016-06-13 02:25:37 -0400 | [diff] [blame] | 5353 | link_info->support_auto_speeds = |
| 5354 | le16_to_cpu(resp->supported_speeds_auto_mode); |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 5355 | |
| 5356 | hwrm_phy_qcaps_exit: |
| 5357 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 5358 | return rc; |
| 5359 | } |
| 5360 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5361 | static int bnxt_update_link(struct bnxt *bp, bool chng_link_state) |
| 5362 | { |
| 5363 | int rc = 0; |
| 5364 | struct bnxt_link_info *link_info = &bp->link_info; |
| 5365 | struct hwrm_port_phy_qcfg_input req = {0}; |
| 5366 | struct hwrm_port_phy_qcfg_output *resp = bp->hwrm_cmd_resp_addr; |
| 5367 | u8 link_up = link_info->link_up; |
Michael Chan | 286ef9d | 2016-11-16 21:13:08 -0500 | [diff] [blame] | 5368 | u16 diff; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5369 | |
| 5370 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCFG, -1, -1); |
| 5371 | |
| 5372 | mutex_lock(&bp->hwrm_cmd_lock); |
| 5373 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5374 | if (rc) { |
| 5375 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 5376 | return rc; |
| 5377 | } |
| 5378 | |
| 5379 | memcpy(&link_info->phy_qcfg_resp, resp, sizeof(*resp)); |
| 5380 | link_info->phy_link_status = resp->link; |
| 5381 | link_info->duplex = resp->duplex; |
| 5382 | link_info->pause = resp->pause; |
| 5383 | link_info->auto_mode = resp->auto_mode; |
| 5384 | link_info->auto_pause_setting = resp->auto_pause; |
Michael Chan | 3277360 | 2016-03-07 15:38:42 -0500 | [diff] [blame] | 5385 | link_info->lp_pause = resp->link_partner_adv_pause; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5386 | link_info->force_pause_setting = resp->force_pause; |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 5387 | link_info->duplex_setting = resp->duplex; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5388 | if (link_info->phy_link_status == BNXT_LINK_LINK) |
| 5389 | link_info->link_speed = le16_to_cpu(resp->link_speed); |
| 5390 | else |
| 5391 | link_info->link_speed = 0; |
| 5392 | link_info->force_link_speed = le16_to_cpu(resp->force_link_speed); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5393 | link_info->support_speeds = le16_to_cpu(resp->support_speeds); |
| 5394 | link_info->auto_link_speeds = le16_to_cpu(resp->auto_link_speed_mask); |
Michael Chan | 3277360 | 2016-03-07 15:38:42 -0500 | [diff] [blame] | 5395 | link_info->lp_auto_link_speeds = |
| 5396 | le16_to_cpu(resp->link_partner_adv_speeds); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5397 | link_info->preemphasis = le32_to_cpu(resp->preemphasis); |
| 5398 | link_info->phy_ver[0] = resp->phy_maj; |
| 5399 | link_info->phy_ver[1] = resp->phy_min; |
| 5400 | link_info->phy_ver[2] = resp->phy_bld; |
| 5401 | link_info->media_type = resp->media_type; |
Michael Chan | 03efbec | 2016-04-11 04:11:11 -0400 | [diff] [blame] | 5402 | link_info->phy_type = resp->phy_type; |
Michael Chan | 11f15ed | 2016-04-05 14:08:55 -0400 | [diff] [blame] | 5403 | link_info->transceiver = resp->xcvr_pkg_type; |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 5404 | link_info->phy_addr = resp->eee_config_phy_addr & |
| 5405 | PORT_PHY_QCFG_RESP_PHY_ADDR_MASK; |
Ajit Khaparde | 42ee18f | 2016-05-15 03:04:44 -0400 | [diff] [blame] | 5406 | link_info->module_status = resp->module_status; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5407 | |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 5408 | if (bp->flags & BNXT_FLAG_EEE_CAP) { |
| 5409 | struct ethtool_eee *eee = &bp->eee; |
| 5410 | u16 fw_speeds; |
| 5411 | |
| 5412 | eee->eee_active = 0; |
| 5413 | if (resp->eee_config_phy_addr & |
| 5414 | PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ACTIVE) { |
| 5415 | eee->eee_active = 1; |
| 5416 | fw_speeds = le16_to_cpu( |
| 5417 | resp->link_partner_adv_eee_link_speed_mask); |
| 5418 | eee->lp_advertised = |
| 5419 | _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0); |
| 5420 | } |
| 5421 | |
| 5422 | /* Pull initial EEE config */ |
| 5423 | if (!chng_link_state) { |
| 5424 | if (resp->eee_config_phy_addr & |
| 5425 | PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ENABLED) |
| 5426 | eee->eee_enabled = 1; |
| 5427 | |
| 5428 | fw_speeds = le16_to_cpu(resp->adv_eee_link_speed_mask); |
| 5429 | eee->advertised = |
| 5430 | _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0); |
| 5431 | |
| 5432 | if (resp->eee_config_phy_addr & |
| 5433 | PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_TX_LPI) { |
| 5434 | __le32 tmr; |
| 5435 | |
| 5436 | eee->tx_lpi_enabled = 1; |
| 5437 | tmr = resp->xcvr_identifier_type_tx_lpi_timer; |
| 5438 | eee->tx_lpi_timer = le32_to_cpu(tmr) & |
| 5439 | PORT_PHY_QCFG_RESP_TX_LPI_TIMER_MASK; |
| 5440 | } |
| 5441 | } |
| 5442 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5443 | /* TODO: need to add more logic to report VF link */ |
| 5444 | if (chng_link_state) { |
| 5445 | if (link_info->phy_link_status == BNXT_LINK_LINK) |
| 5446 | link_info->link_up = 1; |
| 5447 | else |
| 5448 | link_info->link_up = 0; |
| 5449 | if (link_up != link_info->link_up) |
| 5450 | bnxt_report_link(bp); |
| 5451 | } else { |
| 5452 | /* alwasy link down if not require to update link state */ |
| 5453 | link_info->link_up = 0; |
| 5454 | } |
| 5455 | mutex_unlock(&bp->hwrm_cmd_lock); |
Michael Chan | 286ef9d | 2016-11-16 21:13:08 -0500 | [diff] [blame] | 5456 | |
| 5457 | diff = link_info->support_auto_speeds ^ link_info->advertising; |
| 5458 | if ((link_info->support_auto_speeds | diff) != |
| 5459 | link_info->support_auto_speeds) { |
| 5460 | /* An advertised speed is no longer supported, so we need to |
Michael Chan | 0eaa24b | 2017-01-25 02:55:08 -0500 | [diff] [blame] | 5461 | * update the advertisement settings. Caller holds RTNL |
| 5462 | * so we can modify link settings. |
Michael Chan | 286ef9d | 2016-11-16 21:13:08 -0500 | [diff] [blame] | 5463 | */ |
Michael Chan | 286ef9d | 2016-11-16 21:13:08 -0500 | [diff] [blame] | 5464 | link_info->advertising = link_info->support_auto_speeds; |
Michael Chan | 0eaa24b | 2017-01-25 02:55:08 -0500 | [diff] [blame] | 5465 | if (link_info->autoneg & BNXT_AUTONEG_SPEED) |
Michael Chan | 286ef9d | 2016-11-16 21:13:08 -0500 | [diff] [blame] | 5466 | bnxt_hwrm_set_link_setting(bp, true, false); |
Michael Chan | 286ef9d | 2016-11-16 21:13:08 -0500 | [diff] [blame] | 5467 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5468 | return 0; |
| 5469 | } |
| 5470 | |
Michael Chan | 10289be | 2016-05-15 03:04:49 -0400 | [diff] [blame] | 5471 | static void bnxt_get_port_module_status(struct bnxt *bp) |
| 5472 | { |
| 5473 | struct bnxt_link_info *link_info = &bp->link_info; |
| 5474 | struct hwrm_port_phy_qcfg_output *resp = &link_info->phy_qcfg_resp; |
| 5475 | u8 module_status; |
| 5476 | |
| 5477 | if (bnxt_update_link(bp, true)) |
| 5478 | return; |
| 5479 | |
| 5480 | module_status = link_info->module_status; |
| 5481 | switch (module_status) { |
| 5482 | case PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX: |
| 5483 | case PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN: |
| 5484 | case PORT_PHY_QCFG_RESP_MODULE_STATUS_WARNINGMSG: |
| 5485 | netdev_warn(bp->dev, "Unqualified SFP+ module detected on port %d\n", |
| 5486 | bp->pf.port_id); |
| 5487 | if (bp->hwrm_spec_code >= 0x10201) { |
| 5488 | netdev_warn(bp->dev, "Module part number %s\n", |
| 5489 | resp->phy_vendor_partnumber); |
| 5490 | } |
| 5491 | if (module_status == PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX) |
| 5492 | netdev_warn(bp->dev, "TX is disabled\n"); |
| 5493 | if (module_status == PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN) |
| 5494 | netdev_warn(bp->dev, "SFP+ module is shutdown\n"); |
| 5495 | } |
| 5496 | } |
| 5497 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5498 | static void |
| 5499 | bnxt_hwrm_set_pause_common(struct bnxt *bp, struct hwrm_port_phy_cfg_input *req) |
| 5500 | { |
| 5501 | if (bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL) { |
Michael Chan | c9ee951 | 2016-04-05 14:08:56 -0400 | [diff] [blame] | 5502 | if (bp->hwrm_spec_code >= 0x10201) |
| 5503 | req->auto_pause = |
| 5504 | PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5505 | if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_RX) |
| 5506 | req->auto_pause |= PORT_PHY_CFG_REQ_AUTO_PAUSE_RX; |
| 5507 | if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_TX) |
Michael Chan | 49b5c7a | 2016-03-28 19:46:06 -0400 | [diff] [blame] | 5508 | req->auto_pause |= PORT_PHY_CFG_REQ_AUTO_PAUSE_TX; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5509 | req->enables |= |
| 5510 | cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE); |
| 5511 | } else { |
| 5512 | if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_RX) |
| 5513 | req->force_pause |= PORT_PHY_CFG_REQ_FORCE_PAUSE_RX; |
| 5514 | if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_TX) |
| 5515 | req->force_pause |= PORT_PHY_CFG_REQ_FORCE_PAUSE_TX; |
| 5516 | req->enables |= |
| 5517 | cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_FORCE_PAUSE); |
Michael Chan | c9ee951 | 2016-04-05 14:08:56 -0400 | [diff] [blame] | 5518 | if (bp->hwrm_spec_code >= 0x10201) { |
| 5519 | req->auto_pause = req->force_pause; |
| 5520 | req->enables |= cpu_to_le32( |
| 5521 | PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE); |
| 5522 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5523 | } |
| 5524 | } |
| 5525 | |
| 5526 | static void bnxt_hwrm_set_link_common(struct bnxt *bp, |
| 5527 | struct hwrm_port_phy_cfg_input *req) |
| 5528 | { |
| 5529 | u8 autoneg = bp->link_info.autoneg; |
| 5530 | u16 fw_link_speed = bp->link_info.req_link_speed; |
Michael Chan | 68515a1 | 2016-12-29 12:13:34 -0500 | [diff] [blame] | 5531 | u16 advertising = bp->link_info.advertising; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5532 | |
| 5533 | if (autoneg & BNXT_AUTONEG_SPEED) { |
| 5534 | req->auto_mode |= |
Michael Chan | 11f15ed | 2016-04-05 14:08:55 -0400 | [diff] [blame] | 5535 | PORT_PHY_CFG_REQ_AUTO_MODE_SPEED_MASK; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5536 | |
| 5537 | req->enables |= cpu_to_le32( |
| 5538 | PORT_PHY_CFG_REQ_ENABLES_AUTO_LINK_SPEED_MASK); |
| 5539 | req->auto_link_speed_mask = cpu_to_le16(advertising); |
| 5540 | |
| 5541 | req->enables |= cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_MODE); |
| 5542 | req->flags |= |
| 5543 | cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESTART_AUTONEG); |
| 5544 | } else { |
| 5545 | req->force_link_speed = cpu_to_le16(fw_link_speed); |
| 5546 | req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE); |
| 5547 | } |
| 5548 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5549 | /* tell chimp that the setting takes effect immediately */ |
| 5550 | req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESET_PHY); |
| 5551 | } |
| 5552 | |
| 5553 | int bnxt_hwrm_set_pause(struct bnxt *bp) |
| 5554 | { |
| 5555 | struct hwrm_port_phy_cfg_input req = {0}; |
| 5556 | int rc; |
| 5557 | |
| 5558 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1); |
| 5559 | bnxt_hwrm_set_pause_common(bp, &req); |
| 5560 | |
| 5561 | if ((bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL) || |
| 5562 | bp->link_info.force_link_chng) |
| 5563 | bnxt_hwrm_set_link_common(bp, &req); |
| 5564 | |
| 5565 | mutex_lock(&bp->hwrm_cmd_lock); |
| 5566 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5567 | if (!rc && !(bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL)) { |
| 5568 | /* since changing of pause setting doesn't trigger any link |
| 5569 | * change event, the driver needs to update the current pause |
| 5570 | * result upon successfully return of the phy_cfg command |
| 5571 | */ |
| 5572 | bp->link_info.pause = |
| 5573 | bp->link_info.force_pause_setting = bp->link_info.req_flow_ctrl; |
| 5574 | bp->link_info.auto_pause_setting = 0; |
| 5575 | if (!bp->link_info.force_link_chng) |
| 5576 | bnxt_report_link(bp); |
| 5577 | } |
| 5578 | bp->link_info.force_link_chng = false; |
| 5579 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 5580 | return rc; |
| 5581 | } |
| 5582 | |
Michael Chan | 939f7f0 | 2016-04-05 14:08:58 -0400 | [diff] [blame] | 5583 | static void bnxt_hwrm_set_eee(struct bnxt *bp, |
| 5584 | struct hwrm_port_phy_cfg_input *req) |
| 5585 | { |
| 5586 | struct ethtool_eee *eee = &bp->eee; |
| 5587 | |
| 5588 | if (eee->eee_enabled) { |
| 5589 | u16 eee_speeds; |
| 5590 | u32 flags = PORT_PHY_CFG_REQ_FLAGS_EEE_ENABLE; |
| 5591 | |
| 5592 | if (eee->tx_lpi_enabled) |
| 5593 | flags |= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_ENABLE; |
| 5594 | else |
| 5595 | flags |= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_DISABLE; |
| 5596 | |
| 5597 | req->flags |= cpu_to_le32(flags); |
| 5598 | eee_speeds = bnxt_get_fw_auto_link_speeds(eee->advertised); |
| 5599 | req->eee_link_speed_mask = cpu_to_le16(eee_speeds); |
| 5600 | req->tx_lpi_timer = cpu_to_le32(eee->tx_lpi_timer); |
| 5601 | } else { |
| 5602 | req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_EEE_DISABLE); |
| 5603 | } |
| 5604 | } |
| 5605 | |
| 5606 | int bnxt_hwrm_set_link_setting(struct bnxt *bp, bool set_pause, bool set_eee) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5607 | { |
| 5608 | struct hwrm_port_phy_cfg_input req = {0}; |
| 5609 | |
| 5610 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1); |
| 5611 | if (set_pause) |
| 5612 | bnxt_hwrm_set_pause_common(bp, &req); |
| 5613 | |
| 5614 | bnxt_hwrm_set_link_common(bp, &req); |
Michael Chan | 939f7f0 | 2016-04-05 14:08:58 -0400 | [diff] [blame] | 5615 | |
| 5616 | if (set_eee) |
| 5617 | bnxt_hwrm_set_eee(bp, &req); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5618 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5619 | } |
| 5620 | |
Michael Chan | 33f7d55 | 2016-04-11 04:11:12 -0400 | [diff] [blame] | 5621 | static int bnxt_hwrm_shutdown_link(struct bnxt *bp) |
| 5622 | { |
| 5623 | struct hwrm_port_phy_cfg_input req = {0}; |
| 5624 | |
Satish Baddipadige | 567b2ab | 2016-06-13 02:25:31 -0400 | [diff] [blame] | 5625 | if (!BNXT_SINGLE_PF(bp)) |
Michael Chan | 33f7d55 | 2016-04-11 04:11:12 -0400 | [diff] [blame] | 5626 | return 0; |
| 5627 | |
| 5628 | if (pci_num_vf(bp->pdev)) |
| 5629 | return 0; |
| 5630 | |
| 5631 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1); |
Michael Chan | 16d663a | 2016-11-16 21:13:07 -0500 | [diff] [blame] | 5632 | req.flags = cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE_LINK_DWN); |
Michael Chan | 33f7d55 | 2016-04-11 04:11:12 -0400 | [diff] [blame] | 5633 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5634 | } |
| 5635 | |
Michael Chan | 5ad2cbe | 2017-01-13 01:32:03 -0500 | [diff] [blame] | 5636 | static int bnxt_hwrm_port_led_qcaps(struct bnxt *bp) |
| 5637 | { |
| 5638 | struct hwrm_port_led_qcaps_output *resp = bp->hwrm_cmd_resp_addr; |
| 5639 | struct hwrm_port_led_qcaps_input req = {0}; |
| 5640 | struct bnxt_pf_info *pf = &bp->pf; |
| 5641 | int rc; |
| 5642 | |
| 5643 | if (BNXT_VF(bp) || bp->hwrm_spec_code < 0x10601) |
| 5644 | return 0; |
| 5645 | |
| 5646 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_LED_QCAPS, -1, -1); |
| 5647 | req.port_id = cpu_to_le16(pf->port_id); |
| 5648 | mutex_lock(&bp->hwrm_cmd_lock); |
| 5649 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5650 | if (rc) { |
| 5651 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 5652 | return rc; |
| 5653 | } |
| 5654 | if (resp->num_leds > 0 && resp->num_leds < BNXT_MAX_LED) { |
| 5655 | int i; |
| 5656 | |
| 5657 | bp->num_leds = resp->num_leds; |
| 5658 | memcpy(bp->leds, &resp->led0_id, sizeof(bp->leds[0]) * |
| 5659 | bp->num_leds); |
| 5660 | for (i = 0; i < bp->num_leds; i++) { |
| 5661 | struct bnxt_led_info *led = &bp->leds[i]; |
| 5662 | __le16 caps = led->led_state_caps; |
| 5663 | |
| 5664 | if (!led->led_group_id || |
| 5665 | !BNXT_LED_ALT_BLINK_CAP(caps)) { |
| 5666 | bp->num_leds = 0; |
| 5667 | break; |
| 5668 | } |
| 5669 | } |
| 5670 | } |
| 5671 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 5672 | return 0; |
| 5673 | } |
| 5674 | |
Michael Chan | 939f7f0 | 2016-04-05 14:08:58 -0400 | [diff] [blame] | 5675 | static bool bnxt_eee_config_ok(struct bnxt *bp) |
| 5676 | { |
| 5677 | struct ethtool_eee *eee = &bp->eee; |
| 5678 | struct bnxt_link_info *link_info = &bp->link_info; |
| 5679 | |
| 5680 | if (!(bp->flags & BNXT_FLAG_EEE_CAP)) |
| 5681 | return true; |
| 5682 | |
| 5683 | if (eee->eee_enabled) { |
| 5684 | u32 advertising = |
| 5685 | _bnxt_fw_to_ethtool_adv_spds(link_info->advertising, 0); |
| 5686 | |
| 5687 | if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) { |
| 5688 | eee->eee_enabled = 0; |
| 5689 | return false; |
| 5690 | } |
| 5691 | if (eee->advertised & ~advertising) { |
| 5692 | eee->advertised = advertising & eee->supported; |
| 5693 | return false; |
| 5694 | } |
| 5695 | } |
| 5696 | return true; |
| 5697 | } |
| 5698 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5699 | static int bnxt_update_phy_setting(struct bnxt *bp) |
| 5700 | { |
| 5701 | int rc; |
| 5702 | bool update_link = false; |
| 5703 | bool update_pause = false; |
Michael Chan | 939f7f0 | 2016-04-05 14:08:58 -0400 | [diff] [blame] | 5704 | bool update_eee = false; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5705 | struct bnxt_link_info *link_info = &bp->link_info; |
| 5706 | |
| 5707 | rc = bnxt_update_link(bp, true); |
| 5708 | if (rc) { |
| 5709 | netdev_err(bp->dev, "failed to update link (rc: %x)\n", |
| 5710 | rc); |
| 5711 | return rc; |
| 5712 | } |
| 5713 | if ((link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) && |
Michael Chan | c9ee951 | 2016-04-05 14:08:56 -0400 | [diff] [blame] | 5714 | (link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH) != |
| 5715 | link_info->req_flow_ctrl) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5716 | update_pause = true; |
| 5717 | if (!(link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) && |
| 5718 | link_info->force_pause_setting != link_info->req_flow_ctrl) |
| 5719 | update_pause = true; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5720 | if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) { |
| 5721 | if (BNXT_AUTO_MODE(link_info->auto_mode)) |
| 5722 | update_link = true; |
| 5723 | if (link_info->req_link_speed != link_info->force_link_speed) |
| 5724 | update_link = true; |
Michael Chan | de73018 | 2016-02-19 19:43:20 -0500 | [diff] [blame] | 5725 | if (link_info->req_duplex != link_info->duplex_setting) |
| 5726 | update_link = true; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5727 | } else { |
| 5728 | if (link_info->auto_mode == BNXT_LINK_AUTO_NONE) |
| 5729 | update_link = true; |
| 5730 | if (link_info->advertising != link_info->auto_link_speeds) |
| 5731 | update_link = true; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5732 | } |
| 5733 | |
Michael Chan | 16d663a | 2016-11-16 21:13:07 -0500 | [diff] [blame] | 5734 | /* The last close may have shutdown the link, so need to call |
| 5735 | * PHY_CFG to bring it back up. |
| 5736 | */ |
| 5737 | if (!netif_carrier_ok(bp->dev)) |
| 5738 | update_link = true; |
| 5739 | |
Michael Chan | 939f7f0 | 2016-04-05 14:08:58 -0400 | [diff] [blame] | 5740 | if (!bnxt_eee_config_ok(bp)) |
| 5741 | update_eee = true; |
| 5742 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5743 | if (update_link) |
Michael Chan | 939f7f0 | 2016-04-05 14:08:58 -0400 | [diff] [blame] | 5744 | rc = bnxt_hwrm_set_link_setting(bp, update_pause, update_eee); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5745 | else if (update_pause) |
| 5746 | rc = bnxt_hwrm_set_pause(bp); |
| 5747 | if (rc) { |
| 5748 | netdev_err(bp->dev, "failed to update phy setting (rc: %x)\n", |
| 5749 | rc); |
| 5750 | return rc; |
| 5751 | } |
| 5752 | |
| 5753 | return rc; |
| 5754 | } |
| 5755 | |
Jeffrey Huang | 1180949 | 2015-11-05 16:25:49 -0500 | [diff] [blame] | 5756 | /* Common routine to pre-map certain register block to different GRC window. |
| 5757 | * A PF has 16 4K windows and a VF has 4 4K windows. However, only 15 windows |
| 5758 | * in PF and 3 windows in VF that can be customized to map in different |
| 5759 | * register blocks. |
| 5760 | */ |
| 5761 | static void bnxt_preset_reg_win(struct bnxt *bp) |
| 5762 | { |
| 5763 | if (BNXT_PF(bp)) { |
| 5764 | /* CAG registers map to GRC window #4 */ |
| 5765 | writel(BNXT_CAG_REG_BASE, |
| 5766 | bp->bar0 + BNXT_GRCPF_REG_WINDOW_BASE_OUT + 12); |
| 5767 | } |
| 5768 | } |
| 5769 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5770 | static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init) |
| 5771 | { |
| 5772 | int rc = 0; |
| 5773 | |
Jeffrey Huang | 1180949 | 2015-11-05 16:25:49 -0500 | [diff] [blame] | 5774 | bnxt_preset_reg_win(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5775 | netif_carrier_off(bp->dev); |
| 5776 | if (irq_re_init) { |
| 5777 | rc = bnxt_setup_int_mode(bp); |
| 5778 | if (rc) { |
| 5779 | netdev_err(bp->dev, "bnxt_setup_int_mode err: %x\n", |
| 5780 | rc); |
| 5781 | return rc; |
| 5782 | } |
| 5783 | } |
| 5784 | if ((bp->flags & BNXT_FLAG_RFS) && |
| 5785 | !(bp->flags & BNXT_FLAG_USING_MSIX)) { |
| 5786 | /* disable RFS if falling back to INTA */ |
| 5787 | bp->dev->hw_features &= ~NETIF_F_NTUPLE; |
| 5788 | bp->flags &= ~BNXT_FLAG_RFS; |
| 5789 | } |
| 5790 | |
| 5791 | rc = bnxt_alloc_mem(bp, irq_re_init); |
| 5792 | if (rc) { |
| 5793 | netdev_err(bp->dev, "bnxt_alloc_mem err: %x\n", rc); |
| 5794 | goto open_err_free_mem; |
| 5795 | } |
| 5796 | |
| 5797 | if (irq_re_init) { |
| 5798 | bnxt_init_napi(bp); |
| 5799 | rc = bnxt_request_irq(bp); |
| 5800 | if (rc) { |
| 5801 | netdev_err(bp->dev, "bnxt_request_irq err: %x\n", rc); |
| 5802 | goto open_err; |
| 5803 | } |
| 5804 | } |
| 5805 | |
| 5806 | bnxt_enable_napi(bp); |
| 5807 | |
| 5808 | rc = bnxt_init_nic(bp, irq_re_init); |
| 5809 | if (rc) { |
| 5810 | netdev_err(bp->dev, "bnxt_init_nic err: %x\n", rc); |
| 5811 | goto open_err; |
| 5812 | } |
| 5813 | |
| 5814 | if (link_re_init) { |
| 5815 | rc = bnxt_update_phy_setting(bp); |
| 5816 | if (rc) |
Michael Chan | ba41d46 | 2016-02-19 19:43:21 -0500 | [diff] [blame] | 5817 | netdev_warn(bp->dev, "failed to update phy settings\n"); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5818 | } |
| 5819 | |
Alexander Duyck | 7cdd5fc | 2016-06-16 12:21:36 -0700 | [diff] [blame] | 5820 | if (irq_re_init) |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 5821 | udp_tunnel_get_rx_info(bp->dev); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5822 | |
Michael Chan | caefe52 | 2015-12-09 19:35:42 -0500 | [diff] [blame] | 5823 | set_bit(BNXT_STATE_OPEN, &bp->state); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5824 | bnxt_enable_int(bp); |
| 5825 | /* Enable TX queues */ |
| 5826 | bnxt_tx_enable(bp); |
| 5827 | mod_timer(&bp->timer, jiffies + bp->current_interval); |
Michael Chan | 10289be | 2016-05-15 03:04:49 -0400 | [diff] [blame] | 5828 | /* Poll link status and check for SFP+ module status */ |
| 5829 | bnxt_get_port_module_status(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5830 | |
| 5831 | return 0; |
| 5832 | |
| 5833 | open_err: |
| 5834 | bnxt_disable_napi(bp); |
| 5835 | bnxt_del_napi(bp); |
| 5836 | |
| 5837 | open_err_free_mem: |
| 5838 | bnxt_free_skbs(bp); |
| 5839 | bnxt_free_irq(bp); |
| 5840 | bnxt_free_mem(bp, true); |
| 5841 | return rc; |
| 5842 | } |
| 5843 | |
| 5844 | /* rtnl_lock held */ |
| 5845 | int bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init) |
| 5846 | { |
| 5847 | int rc = 0; |
| 5848 | |
| 5849 | rc = __bnxt_open_nic(bp, irq_re_init, link_re_init); |
| 5850 | if (rc) { |
| 5851 | netdev_err(bp->dev, "nic open fail (rc: %x)\n", rc); |
| 5852 | dev_close(bp->dev); |
| 5853 | } |
| 5854 | return rc; |
| 5855 | } |
| 5856 | |
| 5857 | static int bnxt_open(struct net_device *dev) |
| 5858 | { |
| 5859 | struct bnxt *bp = netdev_priv(dev); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5860 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5861 | return __bnxt_open_nic(bp, true, true); |
| 5862 | } |
| 5863 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5864 | int bnxt_close_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init) |
| 5865 | { |
| 5866 | int rc = 0; |
| 5867 | |
| 5868 | #ifdef CONFIG_BNXT_SRIOV |
| 5869 | if (bp->sriov_cfg) { |
| 5870 | rc = wait_event_interruptible_timeout(bp->sriov_cfg_wait, |
| 5871 | !bp->sriov_cfg, |
| 5872 | BNXT_SRIOV_CFG_WAIT_TMO); |
| 5873 | if (rc) |
| 5874 | netdev_warn(bp->dev, "timeout waiting for SRIOV config operation to complete!\n"); |
| 5875 | } |
| 5876 | #endif |
| 5877 | /* Change device state to avoid TX queue wake up's */ |
| 5878 | bnxt_tx_disable(bp); |
| 5879 | |
Michael Chan | caefe52 | 2015-12-09 19:35:42 -0500 | [diff] [blame] | 5880 | clear_bit(BNXT_STATE_OPEN, &bp->state); |
Michael Chan | 4cebdce | 2015-12-09 19:35:43 -0500 | [diff] [blame] | 5881 | smp_mb__after_atomic(); |
| 5882 | while (test_bit(BNXT_STATE_IN_SP_TASK, &bp->state)) |
| 5883 | msleep(20); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5884 | |
Michael Chan | 9d8bc09 | 2016-12-29 12:13:33 -0500 | [diff] [blame] | 5885 | /* Flush rings and and disable interrupts */ |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5886 | bnxt_shutdown_nic(bp, irq_re_init); |
| 5887 | |
| 5888 | /* TODO CHIMP_FW: Link/PHY related cleanup if (link_re_init) */ |
| 5889 | |
| 5890 | bnxt_disable_napi(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5891 | del_timer_sync(&bp->timer); |
| 5892 | bnxt_free_skbs(bp); |
| 5893 | |
| 5894 | if (irq_re_init) { |
| 5895 | bnxt_free_irq(bp); |
| 5896 | bnxt_del_napi(bp); |
| 5897 | } |
| 5898 | bnxt_free_mem(bp, irq_re_init); |
| 5899 | return rc; |
| 5900 | } |
| 5901 | |
| 5902 | static int bnxt_close(struct net_device *dev) |
| 5903 | { |
| 5904 | struct bnxt *bp = netdev_priv(dev); |
| 5905 | |
| 5906 | bnxt_close_nic(bp, true, true); |
Michael Chan | 33f7d55 | 2016-04-11 04:11:12 -0400 | [diff] [blame] | 5907 | bnxt_hwrm_shutdown_link(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5908 | return 0; |
| 5909 | } |
| 5910 | |
| 5911 | /* rtnl_lock held */ |
| 5912 | static int bnxt_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 5913 | { |
| 5914 | switch (cmd) { |
| 5915 | case SIOCGMIIPHY: |
| 5916 | /* fallthru */ |
| 5917 | case SIOCGMIIREG: { |
| 5918 | if (!netif_running(dev)) |
| 5919 | return -EAGAIN; |
| 5920 | |
| 5921 | return 0; |
| 5922 | } |
| 5923 | |
| 5924 | case SIOCSMIIREG: |
| 5925 | if (!netif_running(dev)) |
| 5926 | return -EAGAIN; |
| 5927 | |
| 5928 | return 0; |
| 5929 | |
| 5930 | default: |
| 5931 | /* do nothing */ |
| 5932 | break; |
| 5933 | } |
| 5934 | return -EOPNOTSUPP; |
| 5935 | } |
| 5936 | |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 5937 | static void |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5938 | bnxt_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) |
| 5939 | { |
| 5940 | u32 i; |
| 5941 | struct bnxt *bp = netdev_priv(dev); |
| 5942 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5943 | if (!bp->bnapi) |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 5944 | return; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5945 | |
| 5946 | /* TODO check if we need to synchronize with bnxt_close path */ |
| 5947 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 5948 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 5949 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 5950 | struct ctx_hw_stats *hw_stats = cpr->hw_stats; |
| 5951 | |
| 5952 | stats->rx_packets += le64_to_cpu(hw_stats->rx_ucast_pkts); |
| 5953 | stats->rx_packets += le64_to_cpu(hw_stats->rx_mcast_pkts); |
| 5954 | stats->rx_packets += le64_to_cpu(hw_stats->rx_bcast_pkts); |
| 5955 | |
| 5956 | stats->tx_packets += le64_to_cpu(hw_stats->tx_ucast_pkts); |
| 5957 | stats->tx_packets += le64_to_cpu(hw_stats->tx_mcast_pkts); |
| 5958 | stats->tx_packets += le64_to_cpu(hw_stats->tx_bcast_pkts); |
| 5959 | |
| 5960 | stats->rx_bytes += le64_to_cpu(hw_stats->rx_ucast_bytes); |
| 5961 | stats->rx_bytes += le64_to_cpu(hw_stats->rx_mcast_bytes); |
| 5962 | stats->rx_bytes += le64_to_cpu(hw_stats->rx_bcast_bytes); |
| 5963 | |
| 5964 | stats->tx_bytes += le64_to_cpu(hw_stats->tx_ucast_bytes); |
| 5965 | stats->tx_bytes += le64_to_cpu(hw_stats->tx_mcast_bytes); |
| 5966 | stats->tx_bytes += le64_to_cpu(hw_stats->tx_bcast_bytes); |
| 5967 | |
| 5968 | stats->rx_missed_errors += |
| 5969 | le64_to_cpu(hw_stats->rx_discard_pkts); |
| 5970 | |
| 5971 | stats->multicast += le64_to_cpu(hw_stats->rx_mcast_pkts); |
| 5972 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5973 | stats->tx_dropped += le64_to_cpu(hw_stats->tx_drop_pkts); |
| 5974 | } |
| 5975 | |
Michael Chan | 9947f83 | 2016-03-07 15:38:46 -0500 | [diff] [blame] | 5976 | if (bp->flags & BNXT_FLAG_PORT_STATS) { |
| 5977 | struct rx_port_stats *rx = bp->hw_rx_port_stats; |
| 5978 | struct tx_port_stats *tx = bp->hw_tx_port_stats; |
| 5979 | |
| 5980 | stats->rx_crc_errors = le64_to_cpu(rx->rx_fcs_err_frames); |
| 5981 | stats->rx_frame_errors = le64_to_cpu(rx->rx_align_err_frames); |
| 5982 | stats->rx_length_errors = le64_to_cpu(rx->rx_undrsz_frames) + |
| 5983 | le64_to_cpu(rx->rx_ovrsz_frames) + |
| 5984 | le64_to_cpu(rx->rx_runt_frames); |
| 5985 | stats->rx_errors = le64_to_cpu(rx->rx_false_carrier_frames) + |
| 5986 | le64_to_cpu(rx->rx_jbr_frames); |
| 5987 | stats->collisions = le64_to_cpu(tx->tx_total_collisions); |
| 5988 | stats->tx_fifo_errors = le64_to_cpu(tx->tx_fifo_underruns); |
| 5989 | stats->tx_errors = le64_to_cpu(tx->tx_err); |
| 5990 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5991 | } |
| 5992 | |
| 5993 | static bool bnxt_mc_list_updated(struct bnxt *bp, u32 *rx_mask) |
| 5994 | { |
| 5995 | struct net_device *dev = bp->dev; |
| 5996 | struct bnxt_vnic_info *vnic = &bp->vnic_info[0]; |
| 5997 | struct netdev_hw_addr *ha; |
| 5998 | u8 *haddr; |
| 5999 | int mc_count = 0; |
| 6000 | bool update = false; |
| 6001 | int off = 0; |
| 6002 | |
| 6003 | netdev_for_each_mc_addr(ha, dev) { |
| 6004 | if (mc_count >= BNXT_MAX_MC_ADDRS) { |
| 6005 | *rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST; |
| 6006 | vnic->mc_list_count = 0; |
| 6007 | return false; |
| 6008 | } |
| 6009 | haddr = ha->addr; |
| 6010 | if (!ether_addr_equal(haddr, vnic->mc_list + off)) { |
| 6011 | memcpy(vnic->mc_list + off, haddr, ETH_ALEN); |
| 6012 | update = true; |
| 6013 | } |
| 6014 | off += ETH_ALEN; |
| 6015 | mc_count++; |
| 6016 | } |
| 6017 | if (mc_count) |
| 6018 | *rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_MCAST; |
| 6019 | |
| 6020 | if (mc_count != vnic->mc_list_count) { |
| 6021 | vnic->mc_list_count = mc_count; |
| 6022 | update = true; |
| 6023 | } |
| 6024 | return update; |
| 6025 | } |
| 6026 | |
| 6027 | static bool bnxt_uc_list_updated(struct bnxt *bp) |
| 6028 | { |
| 6029 | struct net_device *dev = bp->dev; |
| 6030 | struct bnxt_vnic_info *vnic = &bp->vnic_info[0]; |
| 6031 | struct netdev_hw_addr *ha; |
| 6032 | int off = 0; |
| 6033 | |
| 6034 | if (netdev_uc_count(dev) != (vnic->uc_filter_count - 1)) |
| 6035 | return true; |
| 6036 | |
| 6037 | netdev_for_each_uc_addr(ha, dev) { |
| 6038 | if (!ether_addr_equal(ha->addr, vnic->uc_list + off)) |
| 6039 | return true; |
| 6040 | |
| 6041 | off += ETH_ALEN; |
| 6042 | } |
| 6043 | return false; |
| 6044 | } |
| 6045 | |
| 6046 | static void bnxt_set_rx_mode(struct net_device *dev) |
| 6047 | { |
| 6048 | struct bnxt *bp = netdev_priv(dev); |
| 6049 | struct bnxt_vnic_info *vnic = &bp->vnic_info[0]; |
| 6050 | u32 mask = vnic->rx_mask; |
| 6051 | bool mc_update = false; |
| 6052 | bool uc_update; |
| 6053 | |
| 6054 | if (!netif_running(dev)) |
| 6055 | return; |
| 6056 | |
| 6057 | mask &= ~(CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS | |
| 6058 | CFA_L2_SET_RX_MASK_REQ_MASK_MCAST | |
| 6059 | CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST); |
| 6060 | |
Michael Chan | 17c71ac | 2016-07-01 18:46:27 -0400 | [diff] [blame] | 6061 | if ((dev->flags & IFF_PROMISC) && bnxt_promisc_ok(bp)) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6062 | mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS; |
| 6063 | |
| 6064 | uc_update = bnxt_uc_list_updated(bp); |
| 6065 | |
| 6066 | if (dev->flags & IFF_ALLMULTI) { |
| 6067 | mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST; |
| 6068 | vnic->mc_list_count = 0; |
| 6069 | } else { |
| 6070 | mc_update = bnxt_mc_list_updated(bp, &mask); |
| 6071 | } |
| 6072 | |
| 6073 | if (mask != vnic->rx_mask || uc_update || mc_update) { |
| 6074 | vnic->rx_mask = mask; |
| 6075 | |
| 6076 | set_bit(BNXT_RX_MASK_SP_EVENT, &bp->sp_event); |
| 6077 | schedule_work(&bp->sp_task); |
| 6078 | } |
| 6079 | } |
| 6080 | |
Michael Chan | b664f00 | 2015-12-02 01:54:08 -0500 | [diff] [blame] | 6081 | static int bnxt_cfg_rx_mode(struct bnxt *bp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6082 | { |
| 6083 | struct net_device *dev = bp->dev; |
| 6084 | struct bnxt_vnic_info *vnic = &bp->vnic_info[0]; |
| 6085 | struct netdev_hw_addr *ha; |
| 6086 | int i, off = 0, rc; |
| 6087 | bool uc_update; |
| 6088 | |
| 6089 | netif_addr_lock_bh(dev); |
| 6090 | uc_update = bnxt_uc_list_updated(bp); |
| 6091 | netif_addr_unlock_bh(dev); |
| 6092 | |
| 6093 | if (!uc_update) |
| 6094 | goto skip_uc; |
| 6095 | |
| 6096 | mutex_lock(&bp->hwrm_cmd_lock); |
| 6097 | for (i = 1; i < vnic->uc_filter_count; i++) { |
| 6098 | struct hwrm_cfa_l2_filter_free_input req = {0}; |
| 6099 | |
| 6100 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_L2_FILTER_FREE, -1, |
| 6101 | -1); |
| 6102 | |
| 6103 | req.l2_filter_id = vnic->fw_l2_filter_id[i]; |
| 6104 | |
| 6105 | rc = _hwrm_send_message(bp, &req, sizeof(req), |
| 6106 | HWRM_CMD_TIMEOUT); |
| 6107 | } |
| 6108 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 6109 | |
| 6110 | vnic->uc_filter_count = 1; |
| 6111 | |
| 6112 | netif_addr_lock_bh(dev); |
| 6113 | if (netdev_uc_count(dev) > (BNXT_MAX_UC_ADDRS - 1)) { |
| 6114 | vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS; |
| 6115 | } else { |
| 6116 | netdev_for_each_uc_addr(ha, dev) { |
| 6117 | memcpy(vnic->uc_list + off, ha->addr, ETH_ALEN); |
| 6118 | off += ETH_ALEN; |
| 6119 | vnic->uc_filter_count++; |
| 6120 | } |
| 6121 | } |
| 6122 | netif_addr_unlock_bh(dev); |
| 6123 | |
| 6124 | for (i = 1, off = 0; i < vnic->uc_filter_count; i++, off += ETH_ALEN) { |
| 6125 | rc = bnxt_hwrm_set_vnic_filter(bp, 0, i, vnic->uc_list + off); |
| 6126 | if (rc) { |
| 6127 | netdev_err(bp->dev, "HWRM vnic filter failure rc: %x\n", |
| 6128 | rc); |
| 6129 | vnic->uc_filter_count = i; |
Michael Chan | b664f00 | 2015-12-02 01:54:08 -0500 | [diff] [blame] | 6130 | return rc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6131 | } |
| 6132 | } |
| 6133 | |
| 6134 | skip_uc: |
| 6135 | rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, 0); |
| 6136 | if (rc) |
| 6137 | netdev_err(bp->dev, "HWRM cfa l2 rx mask failure rc: %x\n", |
| 6138 | rc); |
Michael Chan | b664f00 | 2015-12-02 01:54:08 -0500 | [diff] [blame] | 6139 | |
| 6140 | return rc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6141 | } |
| 6142 | |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 6143 | /* If the chip and firmware supports RFS */ |
| 6144 | static bool bnxt_rfs_supported(struct bnxt *bp) |
| 6145 | { |
| 6146 | if (BNXT_PF(bp) && !BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 6147 | return true; |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 6148 | if (bp->flags & BNXT_FLAG_NEW_RSS_CAP) |
| 6149 | return true; |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 6150 | return false; |
| 6151 | } |
| 6152 | |
| 6153 | /* If runtime conditions support RFS */ |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 6154 | static bool bnxt_rfs_capable(struct bnxt *bp) |
| 6155 | { |
| 6156 | #ifdef CONFIG_RFS_ACCEL |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 6157 | int vnics, max_vnics, max_rss_ctxs; |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 6158 | |
| 6159 | if (BNXT_VF(bp) || !(bp->flags & BNXT_FLAG_MSIX_CAP)) |
| 6160 | return false; |
| 6161 | |
| 6162 | vnics = 1 + bp->rx_nr_rings; |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 6163 | max_vnics = bnxt_get_max_func_vnics(bp); |
| 6164 | max_rss_ctxs = bnxt_get_max_func_rss_ctxs(bp); |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 6165 | |
| 6166 | /* RSS contexts not a limiting factor */ |
| 6167 | if (bp->flags & BNXT_FLAG_NEW_RSS_CAP) |
| 6168 | max_rss_ctxs = max_vnics; |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 6169 | if (vnics > max_vnics || vnics > max_rss_ctxs) { |
Vasundhara Volam | a230490 | 2016-07-25 12:33:36 -0400 | [diff] [blame] | 6170 | netdev_warn(bp->dev, |
| 6171 | "Not enough resources to support NTUPLE filters, enough resources for up to %d rx rings\n", |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 6172 | min(max_rss_ctxs - 1, max_vnics - 1)); |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 6173 | return false; |
Vasundhara Volam | a230490 | 2016-07-25 12:33:36 -0400 | [diff] [blame] | 6174 | } |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 6175 | |
| 6176 | return true; |
| 6177 | #else |
| 6178 | return false; |
| 6179 | #endif |
| 6180 | } |
| 6181 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6182 | static netdev_features_t bnxt_fix_features(struct net_device *dev, |
| 6183 | netdev_features_t features) |
| 6184 | { |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 6185 | struct bnxt *bp = netdev_priv(dev); |
| 6186 | |
Vasundhara Volam | a230490 | 2016-07-25 12:33:36 -0400 | [diff] [blame] | 6187 | if ((features & NETIF_F_NTUPLE) && !bnxt_rfs_capable(bp)) |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 6188 | features &= ~NETIF_F_NTUPLE; |
Michael Chan | 5a9f6b2 | 2016-06-06 02:37:15 -0400 | [diff] [blame] | 6189 | |
| 6190 | /* Both CTAG and STAG VLAN accelaration on the RX side have to be |
| 6191 | * turned on or off together. |
| 6192 | */ |
| 6193 | if ((features & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX)) != |
| 6194 | (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX)) { |
| 6195 | if (dev->features & NETIF_F_HW_VLAN_CTAG_RX) |
| 6196 | features &= ~(NETIF_F_HW_VLAN_CTAG_RX | |
| 6197 | NETIF_F_HW_VLAN_STAG_RX); |
| 6198 | else |
| 6199 | features |= NETIF_F_HW_VLAN_CTAG_RX | |
| 6200 | NETIF_F_HW_VLAN_STAG_RX; |
| 6201 | } |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 6202 | #ifdef CONFIG_BNXT_SRIOV |
| 6203 | if (BNXT_VF(bp)) { |
| 6204 | if (bp->vf.vlan) { |
| 6205 | features &= ~(NETIF_F_HW_VLAN_CTAG_RX | |
| 6206 | NETIF_F_HW_VLAN_STAG_RX); |
| 6207 | } |
| 6208 | } |
| 6209 | #endif |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6210 | return features; |
| 6211 | } |
| 6212 | |
| 6213 | static int bnxt_set_features(struct net_device *dev, netdev_features_t features) |
| 6214 | { |
| 6215 | struct bnxt *bp = netdev_priv(dev); |
| 6216 | u32 flags = bp->flags; |
| 6217 | u32 changes; |
| 6218 | int rc = 0; |
| 6219 | bool re_init = false; |
| 6220 | bool update_tpa = false; |
| 6221 | |
| 6222 | flags &= ~BNXT_FLAG_ALL_CONFIG_FEATS; |
Prashant Sreedharan | 3e8060f | 2016-07-18 07:15:20 -0400 | [diff] [blame] | 6223 | if ((features & NETIF_F_GRO) && !BNXT_CHIP_TYPE_NITRO_A0(bp)) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6224 | flags |= BNXT_FLAG_GRO; |
| 6225 | if (features & NETIF_F_LRO) |
| 6226 | flags |= BNXT_FLAG_LRO; |
| 6227 | |
Michael Chan | bdbd1eb | 2016-12-29 12:13:43 -0500 | [diff] [blame] | 6228 | if (bp->flags & BNXT_FLAG_NO_AGG_RINGS) |
| 6229 | flags &= ~BNXT_FLAG_TPA; |
| 6230 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6231 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 6232 | flags |= BNXT_FLAG_STRIP_VLAN; |
| 6233 | |
| 6234 | if (features & NETIF_F_NTUPLE) |
| 6235 | flags |= BNXT_FLAG_RFS; |
| 6236 | |
| 6237 | changes = flags ^ bp->flags; |
| 6238 | if (changes & BNXT_FLAG_TPA) { |
| 6239 | update_tpa = true; |
| 6240 | if ((bp->flags & BNXT_FLAG_TPA) == 0 || |
| 6241 | (flags & BNXT_FLAG_TPA) == 0) |
| 6242 | re_init = true; |
| 6243 | } |
| 6244 | |
| 6245 | if (changes & ~BNXT_FLAG_TPA) |
| 6246 | re_init = true; |
| 6247 | |
| 6248 | if (flags != bp->flags) { |
| 6249 | u32 old_flags = bp->flags; |
| 6250 | |
| 6251 | bp->flags = flags; |
| 6252 | |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 6253 | if (!test_bit(BNXT_STATE_OPEN, &bp->state)) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6254 | if (update_tpa) |
| 6255 | bnxt_set_ring_params(bp); |
| 6256 | return rc; |
| 6257 | } |
| 6258 | |
| 6259 | if (re_init) { |
| 6260 | bnxt_close_nic(bp, false, false); |
| 6261 | if (update_tpa) |
| 6262 | bnxt_set_ring_params(bp); |
| 6263 | |
| 6264 | return bnxt_open_nic(bp, false, false); |
| 6265 | } |
| 6266 | if (update_tpa) { |
| 6267 | rc = bnxt_set_tpa(bp, |
| 6268 | (flags & BNXT_FLAG_TPA) ? |
| 6269 | true : false); |
| 6270 | if (rc) |
| 6271 | bp->flags = old_flags; |
| 6272 | } |
| 6273 | } |
| 6274 | return rc; |
| 6275 | } |
| 6276 | |
Michael Chan | 9f55459 | 2016-01-02 23:44:58 -0500 | [diff] [blame] | 6277 | static void bnxt_dump_tx_sw_state(struct bnxt_napi *bnapi) |
| 6278 | { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 6279 | struct bnxt_tx_ring_info *txr = bnapi->tx_ring; |
Michael Chan | 9f55459 | 2016-01-02 23:44:58 -0500 | [diff] [blame] | 6280 | int i = bnapi->index; |
| 6281 | |
Michael Chan | 3b2b7d9 | 2016-01-02 23:45:00 -0500 | [diff] [blame] | 6282 | if (!txr) |
| 6283 | return; |
| 6284 | |
Michael Chan | 9f55459 | 2016-01-02 23:44:58 -0500 | [diff] [blame] | 6285 | netdev_info(bnapi->bp->dev, "[%d]: tx{fw_ring: %d prod: %x cons: %x}\n", |
| 6286 | i, txr->tx_ring_struct.fw_ring_id, txr->tx_prod, |
| 6287 | txr->tx_cons); |
| 6288 | } |
| 6289 | |
| 6290 | static void bnxt_dump_rx_sw_state(struct bnxt_napi *bnapi) |
| 6291 | { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 6292 | struct bnxt_rx_ring_info *rxr = bnapi->rx_ring; |
Michael Chan | 9f55459 | 2016-01-02 23:44:58 -0500 | [diff] [blame] | 6293 | int i = bnapi->index; |
| 6294 | |
Michael Chan | 3b2b7d9 | 2016-01-02 23:45:00 -0500 | [diff] [blame] | 6295 | if (!rxr) |
| 6296 | return; |
| 6297 | |
Michael Chan | 9f55459 | 2016-01-02 23:44:58 -0500 | [diff] [blame] | 6298 | netdev_info(bnapi->bp->dev, "[%d]: rx{fw_ring: %d prod: %x} rx_agg{fw_ring: %d agg_prod: %x sw_agg_prod: %x}\n", |
| 6299 | i, rxr->rx_ring_struct.fw_ring_id, rxr->rx_prod, |
| 6300 | rxr->rx_agg_ring_struct.fw_ring_id, rxr->rx_agg_prod, |
| 6301 | rxr->rx_sw_agg_prod); |
| 6302 | } |
| 6303 | |
| 6304 | static void bnxt_dump_cp_sw_state(struct bnxt_napi *bnapi) |
| 6305 | { |
| 6306 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 6307 | int i = bnapi->index; |
| 6308 | |
| 6309 | netdev_info(bnapi->bp->dev, "[%d]: cp{fw_ring: %d raw_cons: %x}\n", |
| 6310 | i, cpr->cp_ring_struct.fw_ring_id, cpr->cp_raw_cons); |
| 6311 | } |
| 6312 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6313 | static void bnxt_dbg_dump_states(struct bnxt *bp) |
| 6314 | { |
| 6315 | int i; |
| 6316 | struct bnxt_napi *bnapi; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6317 | |
| 6318 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 6319 | bnapi = bp->bnapi[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6320 | if (netif_msg_drv(bp)) { |
Michael Chan | 9f55459 | 2016-01-02 23:44:58 -0500 | [diff] [blame] | 6321 | bnxt_dump_tx_sw_state(bnapi); |
| 6322 | bnxt_dump_rx_sw_state(bnapi); |
| 6323 | bnxt_dump_cp_sw_state(bnapi); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6324 | } |
| 6325 | } |
| 6326 | } |
| 6327 | |
Michael Chan | 6988bd9 | 2016-06-13 02:25:29 -0400 | [diff] [blame] | 6328 | static void bnxt_reset_task(struct bnxt *bp, bool silent) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6329 | { |
Michael Chan | 6988bd9 | 2016-06-13 02:25:29 -0400 | [diff] [blame] | 6330 | if (!silent) |
| 6331 | bnxt_dbg_dump_states(bp); |
Michael Chan | 028de14 | 2015-12-09 19:35:44 -0500 | [diff] [blame] | 6332 | if (netif_running(bp->dev)) { |
| 6333 | bnxt_close_nic(bp, false, false); |
| 6334 | bnxt_open_nic(bp, false, false); |
| 6335 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6336 | } |
| 6337 | |
| 6338 | static void bnxt_tx_timeout(struct net_device *dev) |
| 6339 | { |
| 6340 | struct bnxt *bp = netdev_priv(dev); |
| 6341 | |
| 6342 | netdev_err(bp->dev, "TX timeout detected, starting reset task!\n"); |
| 6343 | set_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event); |
| 6344 | schedule_work(&bp->sp_task); |
| 6345 | } |
| 6346 | |
| 6347 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 6348 | static void bnxt_poll_controller(struct net_device *dev) |
| 6349 | { |
| 6350 | struct bnxt *bp = netdev_priv(dev); |
| 6351 | int i; |
| 6352 | |
| 6353 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 6354 | struct bnxt_irq *irq = &bp->irq_tbl[i]; |
| 6355 | |
| 6356 | disable_irq(irq->vector); |
| 6357 | irq->handler(irq->vector, bp->bnapi[i]); |
| 6358 | enable_irq(irq->vector); |
| 6359 | } |
| 6360 | } |
| 6361 | #endif |
| 6362 | |
| 6363 | static void bnxt_timer(unsigned long data) |
| 6364 | { |
| 6365 | struct bnxt *bp = (struct bnxt *)data; |
| 6366 | struct net_device *dev = bp->dev; |
| 6367 | |
| 6368 | if (!netif_running(dev)) |
| 6369 | return; |
| 6370 | |
| 6371 | if (atomic_read(&bp->intr_sem) != 0) |
| 6372 | goto bnxt_restart_timer; |
| 6373 | |
Michael Chan | 3bdf56c | 2016-03-07 15:38:45 -0500 | [diff] [blame] | 6374 | if (bp->link_info.link_up && (bp->flags & BNXT_FLAG_PORT_STATS)) { |
| 6375 | set_bit(BNXT_PERIODIC_STATS_SP_EVENT, &bp->sp_event); |
| 6376 | schedule_work(&bp->sp_task); |
| 6377 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6378 | bnxt_restart_timer: |
| 6379 | mod_timer(&bp->timer, jiffies + bp->current_interval); |
| 6380 | } |
| 6381 | |
Michael Chan | a551ee9 | 2017-01-25 02:55:07 -0500 | [diff] [blame] | 6382 | static void bnxt_rtnl_lock_sp(struct bnxt *bp) |
Michael Chan | 6988bd9 | 2016-06-13 02:25:29 -0400 | [diff] [blame] | 6383 | { |
Michael Chan | a551ee9 | 2017-01-25 02:55:07 -0500 | [diff] [blame] | 6384 | /* We are called from bnxt_sp_task which has BNXT_STATE_IN_SP_TASK |
| 6385 | * set. If the device is being closed, bnxt_close() may be holding |
Michael Chan | 6988bd9 | 2016-06-13 02:25:29 -0400 | [diff] [blame] | 6386 | * rtnl() and waiting for BNXT_STATE_IN_SP_TASK to clear. So we |
| 6387 | * must clear BNXT_STATE_IN_SP_TASK before holding rtnl(). |
| 6388 | */ |
| 6389 | clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state); |
| 6390 | rtnl_lock(); |
Michael Chan | a551ee9 | 2017-01-25 02:55:07 -0500 | [diff] [blame] | 6391 | } |
| 6392 | |
| 6393 | static void bnxt_rtnl_unlock_sp(struct bnxt *bp) |
| 6394 | { |
Michael Chan | 6988bd9 | 2016-06-13 02:25:29 -0400 | [diff] [blame] | 6395 | set_bit(BNXT_STATE_IN_SP_TASK, &bp->state); |
| 6396 | rtnl_unlock(); |
| 6397 | } |
| 6398 | |
Michael Chan | a551ee9 | 2017-01-25 02:55:07 -0500 | [diff] [blame] | 6399 | /* Only called from bnxt_sp_task() */ |
| 6400 | static void bnxt_reset(struct bnxt *bp, bool silent) |
| 6401 | { |
| 6402 | bnxt_rtnl_lock_sp(bp); |
| 6403 | if (test_bit(BNXT_STATE_OPEN, &bp->state)) |
| 6404 | bnxt_reset_task(bp, silent); |
| 6405 | bnxt_rtnl_unlock_sp(bp); |
| 6406 | } |
| 6407 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6408 | static void bnxt_cfg_ntp_filters(struct bnxt *); |
| 6409 | |
| 6410 | static void bnxt_sp_task(struct work_struct *work) |
| 6411 | { |
| 6412 | struct bnxt *bp = container_of(work, struct bnxt, sp_task); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6413 | |
Michael Chan | 4cebdce | 2015-12-09 19:35:43 -0500 | [diff] [blame] | 6414 | set_bit(BNXT_STATE_IN_SP_TASK, &bp->state); |
| 6415 | smp_mb__after_atomic(); |
| 6416 | if (!test_bit(BNXT_STATE_OPEN, &bp->state)) { |
| 6417 | clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6418 | return; |
Michael Chan | 4cebdce | 2015-12-09 19:35:43 -0500 | [diff] [blame] | 6419 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6420 | |
| 6421 | if (test_and_clear_bit(BNXT_RX_MASK_SP_EVENT, &bp->sp_event)) |
| 6422 | bnxt_cfg_rx_mode(bp); |
| 6423 | |
| 6424 | if (test_and_clear_bit(BNXT_RX_NTP_FLTR_SP_EVENT, &bp->sp_event)) |
| 6425 | bnxt_cfg_ntp_filters(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6426 | if (test_and_clear_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT, &bp->sp_event)) |
| 6427 | bnxt_hwrm_exec_fwd_req(bp); |
| 6428 | if (test_and_clear_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT, &bp->sp_event)) { |
| 6429 | bnxt_hwrm_tunnel_dst_port_alloc( |
| 6430 | bp, bp->vxlan_port, |
| 6431 | TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN); |
| 6432 | } |
| 6433 | if (test_and_clear_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT, &bp->sp_event)) { |
| 6434 | bnxt_hwrm_tunnel_dst_port_free( |
| 6435 | bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN); |
| 6436 | } |
Alexander Duyck | 7cdd5fc | 2016-06-16 12:21:36 -0700 | [diff] [blame] | 6437 | if (test_and_clear_bit(BNXT_GENEVE_ADD_PORT_SP_EVENT, &bp->sp_event)) { |
| 6438 | bnxt_hwrm_tunnel_dst_port_alloc( |
| 6439 | bp, bp->nge_port, |
| 6440 | TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE); |
| 6441 | } |
| 6442 | if (test_and_clear_bit(BNXT_GENEVE_DEL_PORT_SP_EVENT, &bp->sp_event)) { |
| 6443 | bnxt_hwrm_tunnel_dst_port_free( |
| 6444 | bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE); |
| 6445 | } |
Michael Chan | 3bdf56c | 2016-03-07 15:38:45 -0500 | [diff] [blame] | 6446 | if (test_and_clear_bit(BNXT_PERIODIC_STATS_SP_EVENT, &bp->sp_event)) |
| 6447 | bnxt_hwrm_port_qstats(bp); |
| 6448 | |
Michael Chan | a551ee9 | 2017-01-25 02:55:07 -0500 | [diff] [blame] | 6449 | /* These functions below will clear BNXT_STATE_IN_SP_TASK. They |
| 6450 | * must be the last functions to be called before exiting. |
| 6451 | */ |
Michael Chan | 0eaa24b | 2017-01-25 02:55:08 -0500 | [diff] [blame] | 6452 | if (test_and_clear_bit(BNXT_LINK_CHNG_SP_EVENT, &bp->sp_event)) { |
| 6453 | int rc = 0; |
| 6454 | |
| 6455 | if (test_and_clear_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT, |
| 6456 | &bp->sp_event)) |
| 6457 | bnxt_hwrm_phy_qcaps(bp); |
| 6458 | |
| 6459 | bnxt_rtnl_lock_sp(bp); |
| 6460 | if (test_bit(BNXT_STATE_OPEN, &bp->state)) |
| 6461 | rc = bnxt_update_link(bp, true); |
| 6462 | bnxt_rtnl_unlock_sp(bp); |
| 6463 | if (rc) |
| 6464 | netdev_err(bp->dev, "SP task can't update link (rc: %x)\n", |
| 6465 | rc); |
| 6466 | } |
Michael Chan | 90c694b | 2017-01-25 02:55:09 -0500 | [diff] [blame] | 6467 | if (test_and_clear_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT, &bp->sp_event)) { |
| 6468 | bnxt_rtnl_lock_sp(bp); |
| 6469 | if (test_bit(BNXT_STATE_OPEN, &bp->state)) |
| 6470 | bnxt_get_port_module_status(bp); |
| 6471 | bnxt_rtnl_unlock_sp(bp); |
| 6472 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6473 | if (test_and_clear_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event)) |
| 6474 | bnxt_reset(bp, false); |
| 6475 | |
| 6476 | if (test_and_clear_bit(BNXT_RESET_TASK_SILENT_SP_EVENT, &bp->sp_event)) |
| 6477 | bnxt_reset(bp, true); |
| 6478 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6479 | smp_mb__before_atomic(); |
| 6480 | clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state); |
| 6481 | } |
| 6482 | |
| 6483 | static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev) |
| 6484 | { |
| 6485 | int rc; |
| 6486 | struct bnxt *bp = netdev_priv(dev); |
| 6487 | |
| 6488 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 6489 | |
| 6490 | /* enable device (incl. PCI PM wakeup), and bus-mastering */ |
| 6491 | rc = pci_enable_device(pdev); |
| 6492 | if (rc) { |
| 6493 | dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n"); |
| 6494 | goto init_err; |
| 6495 | } |
| 6496 | |
| 6497 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { |
| 6498 | dev_err(&pdev->dev, |
| 6499 | "Cannot find PCI device base address, aborting\n"); |
| 6500 | rc = -ENODEV; |
| 6501 | goto init_err_disable; |
| 6502 | } |
| 6503 | |
| 6504 | rc = pci_request_regions(pdev, DRV_MODULE_NAME); |
| 6505 | if (rc) { |
| 6506 | dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting\n"); |
| 6507 | goto init_err_disable; |
| 6508 | } |
| 6509 | |
| 6510 | if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)) != 0 && |
| 6511 | dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)) != 0) { |
| 6512 | dev_err(&pdev->dev, "System does not support DMA, aborting\n"); |
| 6513 | goto init_err_disable; |
| 6514 | } |
| 6515 | |
| 6516 | pci_set_master(pdev); |
| 6517 | |
| 6518 | bp->dev = dev; |
| 6519 | bp->pdev = pdev; |
| 6520 | |
| 6521 | bp->bar0 = pci_ioremap_bar(pdev, 0); |
| 6522 | if (!bp->bar0) { |
| 6523 | dev_err(&pdev->dev, "Cannot map device registers, aborting\n"); |
| 6524 | rc = -ENOMEM; |
| 6525 | goto init_err_release; |
| 6526 | } |
| 6527 | |
| 6528 | bp->bar1 = pci_ioremap_bar(pdev, 2); |
| 6529 | if (!bp->bar1) { |
| 6530 | dev_err(&pdev->dev, "Cannot map doorbell registers, aborting\n"); |
| 6531 | rc = -ENOMEM; |
| 6532 | goto init_err_release; |
| 6533 | } |
| 6534 | |
| 6535 | bp->bar2 = pci_ioremap_bar(pdev, 4); |
| 6536 | if (!bp->bar2) { |
| 6537 | dev_err(&pdev->dev, "Cannot map bar4 registers, aborting\n"); |
| 6538 | rc = -ENOMEM; |
| 6539 | goto init_err_release; |
| 6540 | } |
| 6541 | |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 6542 | pci_enable_pcie_error_reporting(pdev); |
| 6543 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6544 | INIT_WORK(&bp->sp_task, bnxt_sp_task); |
| 6545 | |
| 6546 | spin_lock_init(&bp->ntp_fltr_lock); |
| 6547 | |
| 6548 | bp->rx_ring_size = BNXT_DEFAULT_RX_RING_SIZE; |
| 6549 | bp->tx_ring_size = BNXT_DEFAULT_TX_RING_SIZE; |
| 6550 | |
Michael Chan | dfb5b89 | 2016-02-26 04:00:01 -0500 | [diff] [blame] | 6551 | /* tick values in micro seconds */ |
Michael Chan | dfc9c94 | 2016-02-26 04:00:03 -0500 | [diff] [blame] | 6552 | bp->rx_coal_ticks = 12; |
| 6553 | bp->rx_coal_bufs = 30; |
Michael Chan | dfb5b89 | 2016-02-26 04:00:01 -0500 | [diff] [blame] | 6554 | bp->rx_coal_ticks_irq = 1; |
| 6555 | bp->rx_coal_bufs_irq = 2; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6556 | |
Michael Chan | dfc9c94 | 2016-02-26 04:00:03 -0500 | [diff] [blame] | 6557 | bp->tx_coal_ticks = 25; |
| 6558 | bp->tx_coal_bufs = 30; |
| 6559 | bp->tx_coal_ticks_irq = 2; |
| 6560 | bp->tx_coal_bufs_irq = 2; |
| 6561 | |
Michael Chan | 51f3078 | 2016-07-01 18:46:29 -0400 | [diff] [blame] | 6562 | bp->stats_coal_ticks = BNXT_DEF_STATS_COAL_TICKS; |
| 6563 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6564 | init_timer(&bp->timer); |
| 6565 | bp->timer.data = (unsigned long)bp; |
| 6566 | bp->timer.function = bnxt_timer; |
| 6567 | bp->current_interval = BNXT_TIMER_INTERVAL; |
| 6568 | |
Michael Chan | caefe52 | 2015-12-09 19:35:42 -0500 | [diff] [blame] | 6569 | clear_bit(BNXT_STATE_OPEN, &bp->state); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6570 | |
| 6571 | return 0; |
| 6572 | |
| 6573 | init_err_release: |
| 6574 | if (bp->bar2) { |
| 6575 | pci_iounmap(pdev, bp->bar2); |
| 6576 | bp->bar2 = NULL; |
| 6577 | } |
| 6578 | |
| 6579 | if (bp->bar1) { |
| 6580 | pci_iounmap(pdev, bp->bar1); |
| 6581 | bp->bar1 = NULL; |
| 6582 | } |
| 6583 | |
| 6584 | if (bp->bar0) { |
| 6585 | pci_iounmap(pdev, bp->bar0); |
| 6586 | bp->bar0 = NULL; |
| 6587 | } |
| 6588 | |
| 6589 | pci_release_regions(pdev); |
| 6590 | |
| 6591 | init_err_disable: |
| 6592 | pci_disable_device(pdev); |
| 6593 | |
| 6594 | init_err: |
| 6595 | return rc; |
| 6596 | } |
| 6597 | |
| 6598 | /* rtnl_lock held */ |
| 6599 | static int bnxt_change_mac_addr(struct net_device *dev, void *p) |
| 6600 | { |
| 6601 | struct sockaddr *addr = p; |
Jeffrey Huang | 1fc2cfd | 2015-12-02 01:54:06 -0500 | [diff] [blame] | 6602 | struct bnxt *bp = netdev_priv(dev); |
| 6603 | int rc = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6604 | |
| 6605 | if (!is_valid_ether_addr(addr->sa_data)) |
| 6606 | return -EADDRNOTAVAIL; |
| 6607 | |
Michael Chan | 84c33dd | 2016-04-11 04:11:13 -0400 | [diff] [blame] | 6608 | rc = bnxt_approve_mac(bp, addr->sa_data); |
| 6609 | if (rc) |
| 6610 | return rc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6611 | |
Jeffrey Huang | 1fc2cfd | 2015-12-02 01:54:06 -0500 | [diff] [blame] | 6612 | if (ether_addr_equal(addr->sa_data, dev->dev_addr)) |
| 6613 | return 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6614 | |
Jeffrey Huang | 1fc2cfd | 2015-12-02 01:54:06 -0500 | [diff] [blame] | 6615 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
| 6616 | if (netif_running(dev)) { |
| 6617 | bnxt_close_nic(bp, false, false); |
| 6618 | rc = bnxt_open_nic(bp, false, false); |
| 6619 | } |
| 6620 | |
| 6621 | return rc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6622 | } |
| 6623 | |
| 6624 | /* rtnl_lock held */ |
| 6625 | static int bnxt_change_mtu(struct net_device *dev, int new_mtu) |
| 6626 | { |
| 6627 | struct bnxt *bp = netdev_priv(dev); |
| 6628 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6629 | if (netif_running(dev)) |
| 6630 | bnxt_close_nic(bp, false, false); |
| 6631 | |
| 6632 | dev->mtu = new_mtu; |
| 6633 | bnxt_set_ring_params(bp); |
| 6634 | |
| 6635 | if (netif_running(dev)) |
| 6636 | return bnxt_open_nic(bp, false, false); |
| 6637 | |
| 6638 | return 0; |
| 6639 | } |
| 6640 | |
Michael Chan | c5e3deb | 2016-12-02 21:17:15 -0500 | [diff] [blame] | 6641 | int bnxt_setup_mq_tc(struct net_device *dev, u8 tc) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6642 | { |
| 6643 | struct bnxt *bp = netdev_priv(dev); |
Michael Chan | 3ffb6a3 | 2016-11-11 00:11:42 -0500 | [diff] [blame] | 6644 | bool sh = false; |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 6645 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6646 | if (tc > bp->max_tc) { |
| 6647 | netdev_err(dev, "too many traffic classes requested: %d Max supported is %d\n", |
| 6648 | tc, bp->max_tc); |
| 6649 | return -EINVAL; |
| 6650 | } |
| 6651 | |
| 6652 | if (netdev_get_num_tc(dev) == tc) |
| 6653 | return 0; |
| 6654 | |
Michael Chan | 3ffb6a3 | 2016-11-11 00:11:42 -0500 | [diff] [blame] | 6655 | if (bp->flags & BNXT_FLAG_SHARED_RINGS) |
| 6656 | sh = true; |
| 6657 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6658 | if (tc) { |
Michael Chan | 391be5c | 2016-12-29 12:13:41 -0500 | [diff] [blame] | 6659 | int max_rx_rings, max_tx_rings, req_tx_rings, rsv_tx_rings, rc; |
Michael Chan | 01657bc | 2016-01-02 23:45:03 -0500 | [diff] [blame] | 6660 | |
Michael Chan | 391be5c | 2016-12-29 12:13:41 -0500 | [diff] [blame] | 6661 | req_tx_rings = bp->tx_nr_rings_per_tc * tc; |
Michael Chan | 01657bc | 2016-01-02 23:45:03 -0500 | [diff] [blame] | 6662 | rc = bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, sh); |
Michael Chan | 391be5c | 2016-12-29 12:13:41 -0500 | [diff] [blame] | 6663 | if (rc || req_tx_rings > max_tx_rings) |
| 6664 | return -ENOMEM; |
| 6665 | |
| 6666 | rsv_tx_rings = req_tx_rings; |
| 6667 | if (bnxt_hwrm_reserve_tx_rings(bp, &rsv_tx_rings) || |
| 6668 | rsv_tx_rings < req_tx_rings) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6669 | return -ENOMEM; |
| 6670 | } |
| 6671 | |
| 6672 | /* Needs to close the device and do hw resource re-allocations */ |
| 6673 | if (netif_running(bp->dev)) |
| 6674 | bnxt_close_nic(bp, true, false); |
| 6675 | |
| 6676 | if (tc) { |
| 6677 | bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tc; |
| 6678 | netdev_set_num_tc(dev, tc); |
| 6679 | } else { |
| 6680 | bp->tx_nr_rings = bp->tx_nr_rings_per_tc; |
| 6681 | netdev_reset_tc(dev); |
| 6682 | } |
Michael Chan | 3ffb6a3 | 2016-11-11 00:11:42 -0500 | [diff] [blame] | 6683 | bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) : |
| 6684 | bp->tx_nr_rings + bp->rx_nr_rings; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6685 | bp->num_stat_ctxs = bp->cp_nr_rings; |
| 6686 | |
| 6687 | if (netif_running(bp->dev)) |
| 6688 | return bnxt_open_nic(bp, true, false); |
| 6689 | |
| 6690 | return 0; |
| 6691 | } |
| 6692 | |
Michael Chan | c5e3deb | 2016-12-02 21:17:15 -0500 | [diff] [blame] | 6693 | static int bnxt_setup_tc(struct net_device *dev, u32 handle, __be16 proto, |
| 6694 | struct tc_to_netdev *ntc) |
| 6695 | { |
| 6696 | if (ntc->type != TC_SETUP_MQPRIO) |
| 6697 | return -EINVAL; |
| 6698 | |
| 6699 | return bnxt_setup_mq_tc(dev, ntc->tc); |
| 6700 | } |
| 6701 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6702 | #ifdef CONFIG_RFS_ACCEL |
| 6703 | static bool bnxt_fltr_match(struct bnxt_ntuple_filter *f1, |
| 6704 | struct bnxt_ntuple_filter *f2) |
| 6705 | { |
| 6706 | struct flow_keys *keys1 = &f1->fkeys; |
| 6707 | struct flow_keys *keys2 = &f2->fkeys; |
| 6708 | |
| 6709 | if (keys1->addrs.v4addrs.src == keys2->addrs.v4addrs.src && |
| 6710 | keys1->addrs.v4addrs.dst == keys2->addrs.v4addrs.dst && |
| 6711 | keys1->ports.ports == keys2->ports.ports && |
| 6712 | keys1->basic.ip_proto == keys2->basic.ip_proto && |
| 6713 | keys1->basic.n_proto == keys2->basic.n_proto && |
Michael Chan | a54c4d7 | 2016-07-25 12:33:35 -0400 | [diff] [blame] | 6714 | ether_addr_equal(f1->src_mac_addr, f2->src_mac_addr) && |
| 6715 | ether_addr_equal(f1->dst_mac_addr, f2->dst_mac_addr)) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6716 | return true; |
| 6717 | |
| 6718 | return false; |
| 6719 | } |
| 6720 | |
| 6721 | static int bnxt_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb, |
| 6722 | u16 rxq_index, u32 flow_id) |
| 6723 | { |
| 6724 | struct bnxt *bp = netdev_priv(dev); |
| 6725 | struct bnxt_ntuple_filter *fltr, *new_fltr; |
| 6726 | struct flow_keys *fkeys; |
| 6727 | struct ethhdr *eth = (struct ethhdr *)skb_mac_header(skb); |
Michael Chan | a54c4d7 | 2016-07-25 12:33:35 -0400 | [diff] [blame] | 6728 | int rc = 0, idx, bit_id, l2_idx = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6729 | struct hlist_head *head; |
| 6730 | |
| 6731 | if (skb->encapsulation) |
| 6732 | return -EPROTONOSUPPORT; |
| 6733 | |
Michael Chan | a54c4d7 | 2016-07-25 12:33:35 -0400 | [diff] [blame] | 6734 | if (!ether_addr_equal(dev->dev_addr, eth->h_dest)) { |
| 6735 | struct bnxt_vnic_info *vnic = &bp->vnic_info[0]; |
| 6736 | int off = 0, j; |
| 6737 | |
| 6738 | netif_addr_lock_bh(dev); |
| 6739 | for (j = 0; j < vnic->uc_filter_count; j++, off += ETH_ALEN) { |
| 6740 | if (ether_addr_equal(eth->h_dest, |
| 6741 | vnic->uc_list + off)) { |
| 6742 | l2_idx = j + 1; |
| 6743 | break; |
| 6744 | } |
| 6745 | } |
| 6746 | netif_addr_unlock_bh(dev); |
| 6747 | if (!l2_idx) |
| 6748 | return -EINVAL; |
| 6749 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6750 | new_fltr = kzalloc(sizeof(*new_fltr), GFP_ATOMIC); |
| 6751 | if (!new_fltr) |
| 6752 | return -ENOMEM; |
| 6753 | |
| 6754 | fkeys = &new_fltr->fkeys; |
| 6755 | if (!skb_flow_dissect_flow_keys(skb, fkeys, 0)) { |
| 6756 | rc = -EPROTONOSUPPORT; |
| 6757 | goto err_free; |
| 6758 | } |
| 6759 | |
Michael Chan | dda0e74 | 2016-12-29 12:13:40 -0500 | [diff] [blame] | 6760 | if ((fkeys->basic.n_proto != htons(ETH_P_IP) && |
| 6761 | fkeys->basic.n_proto != htons(ETH_P_IPV6)) || |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6762 | ((fkeys->basic.ip_proto != IPPROTO_TCP) && |
| 6763 | (fkeys->basic.ip_proto != IPPROTO_UDP))) { |
| 6764 | rc = -EPROTONOSUPPORT; |
| 6765 | goto err_free; |
| 6766 | } |
Michael Chan | dda0e74 | 2016-12-29 12:13:40 -0500 | [diff] [blame] | 6767 | if (fkeys->basic.n_proto == htons(ETH_P_IPV6) && |
| 6768 | bp->hwrm_spec_code < 0x10601) { |
| 6769 | rc = -EPROTONOSUPPORT; |
| 6770 | goto err_free; |
| 6771 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6772 | |
Michael Chan | a54c4d7 | 2016-07-25 12:33:35 -0400 | [diff] [blame] | 6773 | memcpy(new_fltr->dst_mac_addr, eth->h_dest, ETH_ALEN); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6774 | memcpy(new_fltr->src_mac_addr, eth->h_source, ETH_ALEN); |
| 6775 | |
| 6776 | idx = skb_get_hash_raw(skb) & BNXT_NTP_FLTR_HASH_MASK; |
| 6777 | head = &bp->ntp_fltr_hash_tbl[idx]; |
| 6778 | rcu_read_lock(); |
| 6779 | hlist_for_each_entry_rcu(fltr, head, hash) { |
| 6780 | if (bnxt_fltr_match(fltr, new_fltr)) { |
| 6781 | rcu_read_unlock(); |
| 6782 | rc = 0; |
| 6783 | goto err_free; |
| 6784 | } |
| 6785 | } |
| 6786 | rcu_read_unlock(); |
| 6787 | |
| 6788 | spin_lock_bh(&bp->ntp_fltr_lock); |
Michael Chan | 84e86b9 | 2015-11-05 16:25:50 -0500 | [diff] [blame] | 6789 | bit_id = bitmap_find_free_region(bp->ntp_fltr_bmap, |
| 6790 | BNXT_NTP_FLTR_MAX_FLTR, 0); |
| 6791 | if (bit_id < 0) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6792 | spin_unlock_bh(&bp->ntp_fltr_lock); |
| 6793 | rc = -ENOMEM; |
| 6794 | goto err_free; |
| 6795 | } |
| 6796 | |
Michael Chan | 84e86b9 | 2015-11-05 16:25:50 -0500 | [diff] [blame] | 6797 | new_fltr->sw_id = (u16)bit_id; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6798 | new_fltr->flow_id = flow_id; |
Michael Chan | a54c4d7 | 2016-07-25 12:33:35 -0400 | [diff] [blame] | 6799 | new_fltr->l2_fltr_idx = l2_idx; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6800 | new_fltr->rxq = rxq_index; |
| 6801 | hlist_add_head_rcu(&new_fltr->hash, head); |
| 6802 | bp->ntp_fltr_count++; |
| 6803 | spin_unlock_bh(&bp->ntp_fltr_lock); |
| 6804 | |
| 6805 | set_bit(BNXT_RX_NTP_FLTR_SP_EVENT, &bp->sp_event); |
| 6806 | schedule_work(&bp->sp_task); |
| 6807 | |
| 6808 | return new_fltr->sw_id; |
| 6809 | |
| 6810 | err_free: |
| 6811 | kfree(new_fltr); |
| 6812 | return rc; |
| 6813 | } |
| 6814 | |
| 6815 | static void bnxt_cfg_ntp_filters(struct bnxt *bp) |
| 6816 | { |
| 6817 | int i; |
| 6818 | |
| 6819 | for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) { |
| 6820 | struct hlist_head *head; |
| 6821 | struct hlist_node *tmp; |
| 6822 | struct bnxt_ntuple_filter *fltr; |
| 6823 | int rc; |
| 6824 | |
| 6825 | head = &bp->ntp_fltr_hash_tbl[i]; |
| 6826 | hlist_for_each_entry_safe(fltr, tmp, head, hash) { |
| 6827 | bool del = false; |
| 6828 | |
| 6829 | if (test_bit(BNXT_FLTR_VALID, &fltr->state)) { |
| 6830 | if (rps_may_expire_flow(bp->dev, fltr->rxq, |
| 6831 | fltr->flow_id, |
| 6832 | fltr->sw_id)) { |
| 6833 | bnxt_hwrm_cfa_ntuple_filter_free(bp, |
| 6834 | fltr); |
| 6835 | del = true; |
| 6836 | } |
| 6837 | } else { |
| 6838 | rc = bnxt_hwrm_cfa_ntuple_filter_alloc(bp, |
| 6839 | fltr); |
| 6840 | if (rc) |
| 6841 | del = true; |
| 6842 | else |
| 6843 | set_bit(BNXT_FLTR_VALID, &fltr->state); |
| 6844 | } |
| 6845 | |
| 6846 | if (del) { |
| 6847 | spin_lock_bh(&bp->ntp_fltr_lock); |
| 6848 | hlist_del_rcu(&fltr->hash); |
| 6849 | bp->ntp_fltr_count--; |
| 6850 | spin_unlock_bh(&bp->ntp_fltr_lock); |
| 6851 | synchronize_rcu(); |
| 6852 | clear_bit(fltr->sw_id, bp->ntp_fltr_bmap); |
| 6853 | kfree(fltr); |
| 6854 | } |
| 6855 | } |
| 6856 | } |
Jeffrey Huang | 1924136 | 2016-02-26 04:00:00 -0500 | [diff] [blame] | 6857 | if (test_and_clear_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT, &bp->sp_event)) |
| 6858 | netdev_info(bp->dev, "Receive PF driver unload event!"); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6859 | } |
| 6860 | |
| 6861 | #else |
| 6862 | |
| 6863 | static void bnxt_cfg_ntp_filters(struct bnxt *bp) |
| 6864 | { |
| 6865 | } |
| 6866 | |
| 6867 | #endif /* CONFIG_RFS_ACCEL */ |
| 6868 | |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 6869 | static void bnxt_udp_tunnel_add(struct net_device *dev, |
| 6870 | struct udp_tunnel_info *ti) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6871 | { |
| 6872 | struct bnxt *bp = netdev_priv(dev); |
| 6873 | |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 6874 | if (ti->sa_family != AF_INET6 && ti->sa_family != AF_INET) |
| 6875 | return; |
| 6876 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6877 | if (!netif_running(dev)) |
| 6878 | return; |
| 6879 | |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 6880 | switch (ti->type) { |
| 6881 | case UDP_TUNNEL_TYPE_VXLAN: |
| 6882 | if (bp->vxlan_port_cnt && bp->vxlan_port != ti->port) |
| 6883 | return; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6884 | |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 6885 | bp->vxlan_port_cnt++; |
| 6886 | if (bp->vxlan_port_cnt == 1) { |
| 6887 | bp->vxlan_port = ti->port; |
| 6888 | set_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT, &bp->sp_event); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6889 | schedule_work(&bp->sp_task); |
| 6890 | } |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 6891 | break; |
Alexander Duyck | 7cdd5fc | 2016-06-16 12:21:36 -0700 | [diff] [blame] | 6892 | case UDP_TUNNEL_TYPE_GENEVE: |
| 6893 | if (bp->nge_port_cnt && bp->nge_port != ti->port) |
| 6894 | return; |
| 6895 | |
| 6896 | bp->nge_port_cnt++; |
| 6897 | if (bp->nge_port_cnt == 1) { |
| 6898 | bp->nge_port = ti->port; |
| 6899 | set_bit(BNXT_GENEVE_ADD_PORT_SP_EVENT, &bp->sp_event); |
| 6900 | } |
| 6901 | break; |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 6902 | default: |
| 6903 | return; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6904 | } |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 6905 | |
| 6906 | schedule_work(&bp->sp_task); |
| 6907 | } |
| 6908 | |
| 6909 | static void bnxt_udp_tunnel_del(struct net_device *dev, |
| 6910 | struct udp_tunnel_info *ti) |
| 6911 | { |
| 6912 | struct bnxt *bp = netdev_priv(dev); |
| 6913 | |
| 6914 | if (ti->sa_family != AF_INET6 && ti->sa_family != AF_INET) |
| 6915 | return; |
| 6916 | |
| 6917 | if (!netif_running(dev)) |
| 6918 | return; |
| 6919 | |
| 6920 | switch (ti->type) { |
| 6921 | case UDP_TUNNEL_TYPE_VXLAN: |
| 6922 | if (!bp->vxlan_port_cnt || bp->vxlan_port != ti->port) |
| 6923 | return; |
| 6924 | bp->vxlan_port_cnt--; |
| 6925 | |
| 6926 | if (bp->vxlan_port_cnt != 0) |
| 6927 | return; |
| 6928 | |
| 6929 | set_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT, &bp->sp_event); |
| 6930 | break; |
Alexander Duyck | 7cdd5fc | 2016-06-16 12:21:36 -0700 | [diff] [blame] | 6931 | case UDP_TUNNEL_TYPE_GENEVE: |
| 6932 | if (!bp->nge_port_cnt || bp->nge_port != ti->port) |
| 6933 | return; |
| 6934 | bp->nge_port_cnt--; |
| 6935 | |
| 6936 | if (bp->nge_port_cnt != 0) |
| 6937 | return; |
| 6938 | |
| 6939 | set_bit(BNXT_GENEVE_DEL_PORT_SP_EVENT, &bp->sp_event); |
| 6940 | break; |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 6941 | default: |
| 6942 | return; |
| 6943 | } |
| 6944 | |
| 6945 | schedule_work(&bp->sp_task); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6946 | } |
| 6947 | |
| 6948 | static const struct net_device_ops bnxt_netdev_ops = { |
| 6949 | .ndo_open = bnxt_open, |
| 6950 | .ndo_start_xmit = bnxt_start_xmit, |
| 6951 | .ndo_stop = bnxt_close, |
| 6952 | .ndo_get_stats64 = bnxt_get_stats64, |
| 6953 | .ndo_set_rx_mode = bnxt_set_rx_mode, |
| 6954 | .ndo_do_ioctl = bnxt_ioctl, |
| 6955 | .ndo_validate_addr = eth_validate_addr, |
| 6956 | .ndo_set_mac_address = bnxt_change_mac_addr, |
| 6957 | .ndo_change_mtu = bnxt_change_mtu, |
| 6958 | .ndo_fix_features = bnxt_fix_features, |
| 6959 | .ndo_set_features = bnxt_set_features, |
| 6960 | .ndo_tx_timeout = bnxt_tx_timeout, |
| 6961 | #ifdef CONFIG_BNXT_SRIOV |
| 6962 | .ndo_get_vf_config = bnxt_get_vf_config, |
| 6963 | .ndo_set_vf_mac = bnxt_set_vf_mac, |
| 6964 | .ndo_set_vf_vlan = bnxt_set_vf_vlan, |
| 6965 | .ndo_set_vf_rate = bnxt_set_vf_bw, |
| 6966 | .ndo_set_vf_link_state = bnxt_set_vf_link_state, |
| 6967 | .ndo_set_vf_spoofchk = bnxt_set_vf_spoofchk, |
| 6968 | #endif |
| 6969 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 6970 | .ndo_poll_controller = bnxt_poll_controller, |
| 6971 | #endif |
| 6972 | .ndo_setup_tc = bnxt_setup_tc, |
| 6973 | #ifdef CONFIG_RFS_ACCEL |
| 6974 | .ndo_rx_flow_steer = bnxt_rx_flow_steer, |
| 6975 | #endif |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 6976 | .ndo_udp_tunnel_add = bnxt_udp_tunnel_add, |
| 6977 | .ndo_udp_tunnel_del = bnxt_udp_tunnel_del, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6978 | }; |
| 6979 | |
| 6980 | static void bnxt_remove_one(struct pci_dev *pdev) |
| 6981 | { |
| 6982 | struct net_device *dev = pci_get_drvdata(pdev); |
| 6983 | struct bnxt *bp = netdev_priv(dev); |
| 6984 | |
| 6985 | if (BNXT_PF(bp)) |
| 6986 | bnxt_sriov_disable(bp); |
| 6987 | |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 6988 | pci_disable_pcie_error_reporting(pdev); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6989 | unregister_netdev(dev); |
| 6990 | cancel_work_sync(&bp->sp_task); |
| 6991 | bp->sp_event = 0; |
| 6992 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 6993 | bnxt_clear_int_mode(bp); |
Jeffrey Huang | be58a0d | 2015-12-27 18:19:18 -0500 | [diff] [blame] | 6994 | bnxt_hwrm_func_drv_unrgtr(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6995 | bnxt_free_hwrm_resources(bp); |
Michael Chan | 7df4ae9 | 2016-12-02 21:17:17 -0500 | [diff] [blame] | 6996 | bnxt_dcb_free(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6997 | pci_iounmap(pdev, bp->bar2); |
| 6998 | pci_iounmap(pdev, bp->bar1); |
| 6999 | pci_iounmap(pdev, bp->bar0); |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 7000 | kfree(bp->edev); |
| 7001 | bp->edev = NULL; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7002 | free_netdev(dev); |
| 7003 | |
| 7004 | pci_release_regions(pdev); |
| 7005 | pci_disable_device(pdev); |
| 7006 | } |
| 7007 | |
| 7008 | static int bnxt_probe_phy(struct bnxt *bp) |
| 7009 | { |
| 7010 | int rc = 0; |
| 7011 | struct bnxt_link_info *link_info = &bp->link_info; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7012 | |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 7013 | rc = bnxt_hwrm_phy_qcaps(bp); |
| 7014 | if (rc) { |
| 7015 | netdev_err(bp->dev, "Probe phy can't get phy capabilities (rc: %x)\n", |
| 7016 | rc); |
| 7017 | return rc; |
| 7018 | } |
| 7019 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7020 | rc = bnxt_update_link(bp, false); |
| 7021 | if (rc) { |
| 7022 | netdev_err(bp->dev, "Probe phy can't update link (rc: %x)\n", |
| 7023 | rc); |
| 7024 | return rc; |
| 7025 | } |
| 7026 | |
Michael Chan | 93ed811 | 2016-06-13 02:25:37 -0400 | [diff] [blame] | 7027 | /* Older firmware does not have supported_auto_speeds, so assume |
| 7028 | * that all supported speeds can be autonegotiated. |
| 7029 | */ |
| 7030 | if (link_info->auto_link_speeds && !link_info->support_auto_speeds) |
| 7031 | link_info->support_auto_speeds = link_info->support_speeds; |
| 7032 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7033 | /*initialize the ethool setting copy with NVM settings */ |
Michael Chan | 0d8abf0 | 2016-02-10 17:33:47 -0500 | [diff] [blame] | 7034 | if (BNXT_AUTO_MODE(link_info->auto_mode)) { |
Michael Chan | c9ee951 | 2016-04-05 14:08:56 -0400 | [diff] [blame] | 7035 | link_info->autoneg = BNXT_AUTONEG_SPEED; |
| 7036 | if (bp->hwrm_spec_code >= 0x10201) { |
| 7037 | if (link_info->auto_pause_setting & |
| 7038 | PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE) |
| 7039 | link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL; |
| 7040 | } else { |
| 7041 | link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL; |
| 7042 | } |
Michael Chan | 0d8abf0 | 2016-02-10 17:33:47 -0500 | [diff] [blame] | 7043 | link_info->advertising = link_info->auto_link_speeds; |
Michael Chan | 0d8abf0 | 2016-02-10 17:33:47 -0500 | [diff] [blame] | 7044 | } else { |
| 7045 | link_info->req_link_speed = link_info->force_link_speed; |
| 7046 | link_info->req_duplex = link_info->duplex_setting; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7047 | } |
Michael Chan | c9ee951 | 2016-04-05 14:08:56 -0400 | [diff] [blame] | 7048 | if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) |
| 7049 | link_info->req_flow_ctrl = |
| 7050 | link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH; |
| 7051 | else |
| 7052 | link_info->req_flow_ctrl = link_info->force_pause_setting; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7053 | return rc; |
| 7054 | } |
| 7055 | |
| 7056 | static int bnxt_get_max_irq(struct pci_dev *pdev) |
| 7057 | { |
| 7058 | u16 ctrl; |
| 7059 | |
| 7060 | if (!pdev->msix_cap) |
| 7061 | return 1; |
| 7062 | |
| 7063 | pci_read_config_word(pdev, pdev->msix_cap + PCI_MSIX_FLAGS, &ctrl); |
| 7064 | return (ctrl & PCI_MSIX_FLAGS_QSIZE) + 1; |
| 7065 | } |
| 7066 | |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 7067 | static void _bnxt_get_max_rings(struct bnxt *bp, int *max_rx, int *max_tx, |
| 7068 | int *max_cp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7069 | { |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 7070 | int max_ring_grps = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7071 | |
Michael Chan | 379a80a | 2015-10-23 15:06:19 -0400 | [diff] [blame] | 7072 | #ifdef CONFIG_BNXT_SRIOV |
Arnd Bergmann | 415b6f1 | 2016-01-12 16:05:08 +0100 | [diff] [blame] | 7073 | if (!BNXT_PF(bp)) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7074 | *max_tx = bp->vf.max_tx_rings; |
| 7075 | *max_rx = bp->vf.max_rx_rings; |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 7076 | *max_cp = min_t(int, bp->vf.max_irqs, bp->vf.max_cp_rings); |
| 7077 | *max_cp = min_t(int, *max_cp, bp->vf.max_stat_ctxs); |
Michael Chan | b72d4a6 | 2015-12-27 18:19:27 -0500 | [diff] [blame] | 7078 | max_ring_grps = bp->vf.max_hw_ring_grps; |
Arnd Bergmann | 415b6f1 | 2016-01-12 16:05:08 +0100 | [diff] [blame] | 7079 | } else |
Michael Chan | 379a80a | 2015-10-23 15:06:19 -0400 | [diff] [blame] | 7080 | #endif |
Arnd Bergmann | 415b6f1 | 2016-01-12 16:05:08 +0100 | [diff] [blame] | 7081 | { |
| 7082 | *max_tx = bp->pf.max_tx_rings; |
| 7083 | *max_rx = bp->pf.max_rx_rings; |
| 7084 | *max_cp = min_t(int, bp->pf.max_irqs, bp->pf.max_cp_rings); |
| 7085 | *max_cp = min_t(int, *max_cp, bp->pf.max_stat_ctxs); |
| 7086 | max_ring_grps = bp->pf.max_hw_ring_grps; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7087 | } |
Prashant Sreedharan | 7659519 | 2016-07-18 07:15:22 -0400 | [diff] [blame] | 7088 | if (BNXT_CHIP_TYPE_NITRO_A0(bp) && BNXT_PF(bp)) { |
| 7089 | *max_cp -= 1; |
| 7090 | *max_rx -= 2; |
| 7091 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7092 | if (bp->flags & BNXT_FLAG_AGG_RINGS) |
| 7093 | *max_rx >>= 1; |
Michael Chan | b72d4a6 | 2015-12-27 18:19:27 -0500 | [diff] [blame] | 7094 | *max_rx = min_t(int, *max_rx, max_ring_grps); |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 7095 | } |
| 7096 | |
| 7097 | int bnxt_get_max_rings(struct bnxt *bp, int *max_rx, int *max_tx, bool shared) |
| 7098 | { |
| 7099 | int rx, tx, cp; |
| 7100 | |
| 7101 | _bnxt_get_max_rings(bp, &rx, &tx, &cp); |
| 7102 | if (!rx || !tx || !cp) |
| 7103 | return -ENOMEM; |
| 7104 | |
| 7105 | *max_rx = rx; |
| 7106 | *max_tx = tx; |
| 7107 | return bnxt_trim_rings(bp, max_rx, max_tx, cp, shared); |
| 7108 | } |
| 7109 | |
Michael Chan | e4060d3 | 2016-12-07 00:26:19 -0500 | [diff] [blame] | 7110 | static int bnxt_get_dflt_rings(struct bnxt *bp, int *max_rx, int *max_tx, |
| 7111 | bool shared) |
| 7112 | { |
| 7113 | int rc; |
| 7114 | |
| 7115 | rc = bnxt_get_max_rings(bp, max_rx, max_tx, shared); |
Michael Chan | bdbd1eb | 2016-12-29 12:13:43 -0500 | [diff] [blame] | 7116 | if (rc && (bp->flags & BNXT_FLAG_AGG_RINGS)) { |
| 7117 | /* Not enough rings, try disabling agg rings. */ |
| 7118 | bp->flags &= ~BNXT_FLAG_AGG_RINGS; |
| 7119 | rc = bnxt_get_max_rings(bp, max_rx, max_tx, shared); |
| 7120 | if (rc) |
| 7121 | return rc; |
| 7122 | bp->flags |= BNXT_FLAG_NO_AGG_RINGS; |
| 7123 | bp->dev->hw_features &= ~NETIF_F_LRO; |
| 7124 | bp->dev->features &= ~NETIF_F_LRO; |
| 7125 | bnxt_set_ring_params(bp); |
| 7126 | } |
Michael Chan | e4060d3 | 2016-12-07 00:26:19 -0500 | [diff] [blame] | 7127 | |
| 7128 | if (bp->flags & BNXT_FLAG_ROCE_CAP) { |
| 7129 | int max_cp, max_stat, max_irq; |
| 7130 | |
| 7131 | /* Reserve minimum resources for RoCE */ |
| 7132 | max_cp = bnxt_get_max_func_cp_rings(bp); |
| 7133 | max_stat = bnxt_get_max_func_stat_ctxs(bp); |
| 7134 | max_irq = bnxt_get_max_func_irqs(bp); |
| 7135 | if (max_cp <= BNXT_MIN_ROCE_CP_RINGS || |
| 7136 | max_irq <= BNXT_MIN_ROCE_CP_RINGS || |
| 7137 | max_stat <= BNXT_MIN_ROCE_STAT_CTXS) |
| 7138 | return 0; |
| 7139 | |
| 7140 | max_cp -= BNXT_MIN_ROCE_CP_RINGS; |
| 7141 | max_irq -= BNXT_MIN_ROCE_CP_RINGS; |
| 7142 | max_stat -= BNXT_MIN_ROCE_STAT_CTXS; |
| 7143 | max_cp = min_t(int, max_cp, max_irq); |
| 7144 | max_cp = min_t(int, max_cp, max_stat); |
| 7145 | rc = bnxt_trim_rings(bp, max_rx, max_tx, max_cp, shared); |
| 7146 | if (rc) |
| 7147 | rc = 0; |
| 7148 | } |
| 7149 | return rc; |
| 7150 | } |
| 7151 | |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 7152 | static int bnxt_set_dflt_rings(struct bnxt *bp) |
| 7153 | { |
| 7154 | int dflt_rings, max_rx_rings, max_tx_rings, rc; |
| 7155 | bool sh = true; |
| 7156 | |
| 7157 | if (sh) |
| 7158 | bp->flags |= BNXT_FLAG_SHARED_RINGS; |
| 7159 | dflt_rings = netif_get_num_default_rss_queues(); |
Michael Chan | e4060d3 | 2016-12-07 00:26:19 -0500 | [diff] [blame] | 7160 | rc = bnxt_get_dflt_rings(bp, &max_rx_rings, &max_tx_rings, sh); |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 7161 | if (rc) |
| 7162 | return rc; |
| 7163 | bp->rx_nr_rings = min_t(int, dflt_rings, max_rx_rings); |
| 7164 | bp->tx_nr_rings_per_tc = min_t(int, dflt_rings, max_tx_rings); |
Michael Chan | 391be5c | 2016-12-29 12:13:41 -0500 | [diff] [blame] | 7165 | |
| 7166 | rc = bnxt_hwrm_reserve_tx_rings(bp, &bp->tx_nr_rings_per_tc); |
| 7167 | if (rc) |
| 7168 | netdev_warn(bp->dev, "Unable to reserve tx rings\n"); |
| 7169 | |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 7170 | bp->tx_nr_rings = bp->tx_nr_rings_per_tc; |
| 7171 | bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) : |
| 7172 | bp->tx_nr_rings + bp->rx_nr_rings; |
| 7173 | bp->num_stat_ctxs = bp->cp_nr_rings; |
Prashant Sreedharan | 7659519 | 2016-07-18 07:15:22 -0400 | [diff] [blame] | 7174 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) { |
| 7175 | bp->rx_nr_rings++; |
| 7176 | bp->cp_nr_rings++; |
| 7177 | } |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 7178 | return rc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7179 | } |
| 7180 | |
Michael Chan | 7b08f66 | 2016-12-07 00:26:18 -0500 | [diff] [blame] | 7181 | void bnxt_restore_pf_fw_resources(struct bnxt *bp) |
| 7182 | { |
| 7183 | ASSERT_RTNL(); |
| 7184 | bnxt_hwrm_func_qcaps(bp); |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 7185 | bnxt_subtract_ulp_resources(bp, BNXT_ROCE_ULP); |
Michael Chan | 7b08f66 | 2016-12-07 00:26:18 -0500 | [diff] [blame] | 7186 | } |
| 7187 | |
Ajit Khaparde | 90c4f78 | 2016-05-15 03:04:45 -0400 | [diff] [blame] | 7188 | static void bnxt_parse_log_pcie_link(struct bnxt *bp) |
| 7189 | { |
| 7190 | enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN; |
| 7191 | enum pci_bus_speed speed = PCI_SPEED_UNKNOWN; |
| 7192 | |
| 7193 | if (pcie_get_minimum_link(bp->pdev, &speed, &width) || |
| 7194 | speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) |
| 7195 | netdev_info(bp->dev, "Failed to determine PCIe Link Info\n"); |
| 7196 | else |
| 7197 | netdev_info(bp->dev, "PCIe: Speed %s Width x%d\n", |
| 7198 | speed == PCIE_SPEED_2_5GT ? "2.5GT/s" : |
| 7199 | speed == PCIE_SPEED_5_0GT ? "5.0GT/s" : |
| 7200 | speed == PCIE_SPEED_8_0GT ? "8.0GT/s" : |
| 7201 | "Unknown", width); |
| 7202 | } |
| 7203 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7204 | static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 7205 | { |
| 7206 | static int version_printed; |
| 7207 | struct net_device *dev; |
| 7208 | struct bnxt *bp; |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 7209 | int rc, max_irqs; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7210 | |
Prashant Sreedharan | fa853dd | 2016-07-18 07:15:25 -0400 | [diff] [blame] | 7211 | if (pdev->device == 0x16cd && pci_is_bridge(pdev)) |
| 7212 | return -ENODEV; |
| 7213 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7214 | if (version_printed++ == 0) |
| 7215 | pr_info("%s", version); |
| 7216 | |
| 7217 | max_irqs = bnxt_get_max_irq(pdev); |
| 7218 | dev = alloc_etherdev_mq(sizeof(*bp), max_irqs); |
| 7219 | if (!dev) |
| 7220 | return -ENOMEM; |
| 7221 | |
| 7222 | bp = netdev_priv(dev); |
| 7223 | |
| 7224 | if (bnxt_vf_pciid(ent->driver_data)) |
| 7225 | bp->flags |= BNXT_FLAG_VF; |
| 7226 | |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 7227 | if (pdev->msix_cap) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7228 | bp->flags |= BNXT_FLAG_MSIX_CAP; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7229 | |
| 7230 | rc = bnxt_init_board(pdev, dev); |
| 7231 | if (rc < 0) |
| 7232 | goto init_err_free; |
| 7233 | |
| 7234 | dev->netdev_ops = &bnxt_netdev_ops; |
| 7235 | dev->watchdog_timeo = BNXT_TX_TIMEOUT; |
| 7236 | dev->ethtool_ops = &bnxt_ethtool_ops; |
| 7237 | |
| 7238 | pci_set_drvdata(pdev, dev); |
| 7239 | |
Prashant Sreedharan | 3e8060f | 2016-07-18 07:15:20 -0400 | [diff] [blame] | 7240 | rc = bnxt_alloc_hwrm_resources(bp); |
| 7241 | if (rc) |
| 7242 | goto init_err; |
| 7243 | |
| 7244 | mutex_init(&bp->hwrm_cmd_lock); |
| 7245 | rc = bnxt_hwrm_ver_get(bp); |
| 7246 | if (rc) |
| 7247 | goto init_err; |
| 7248 | |
Rob Swindell | 5ac67d8 | 2016-09-19 03:58:03 -0400 | [diff] [blame] | 7249 | bnxt_hwrm_fw_set_time(bp); |
| 7250 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7251 | dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG | |
| 7252 | NETIF_F_TSO | NETIF_F_TSO6 | |
| 7253 | NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_GRE | |
Tom Herbert | 7e13318 | 2016-05-18 09:06:10 -0700 | [diff] [blame] | 7254 | NETIF_F_GSO_IPXIP4 | |
Alexander Duyck | 152971e | 2016-05-02 09:38:55 -0700 | [diff] [blame] | 7255 | NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_GSO_GRE_CSUM | |
| 7256 | NETIF_F_GSO_PARTIAL | NETIF_F_RXHASH | |
Prashant Sreedharan | 3e8060f | 2016-07-18 07:15:20 -0400 | [diff] [blame] | 7257 | NETIF_F_RXCSUM | NETIF_F_GRO; |
| 7258 | |
| 7259 | if (!BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 7260 | dev->hw_features |= NETIF_F_LRO; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7261 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7262 | dev->hw_enc_features = |
| 7263 | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG | |
| 7264 | NETIF_F_TSO | NETIF_F_TSO6 | |
| 7265 | NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_GRE | |
Alexander Duyck | 152971e | 2016-05-02 09:38:55 -0700 | [diff] [blame] | 7266 | NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_GSO_GRE_CSUM | |
Tom Herbert | 7e13318 | 2016-05-18 09:06:10 -0700 | [diff] [blame] | 7267 | NETIF_F_GSO_IPXIP4 | NETIF_F_GSO_PARTIAL; |
Alexander Duyck | 152971e | 2016-05-02 09:38:55 -0700 | [diff] [blame] | 7268 | dev->gso_partial_features = NETIF_F_GSO_UDP_TUNNEL_CSUM | |
| 7269 | NETIF_F_GSO_GRE_CSUM; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7270 | dev->vlan_features = dev->hw_features | NETIF_F_HIGHDMA; |
| 7271 | dev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX | |
| 7272 | NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_STAG_TX; |
| 7273 | dev->features |= dev->hw_features | NETIF_F_HIGHDMA; |
| 7274 | dev->priv_flags |= IFF_UNICAST_FLT; |
| 7275 | |
Jarod Wilson | e1c6dcc | 2016-10-17 15:54:04 -0400 | [diff] [blame] | 7276 | /* MTU range: 60 - 9500 */ |
| 7277 | dev->min_mtu = ETH_ZLEN; |
| 7278 | dev->max_mtu = 9500; |
| 7279 | |
Michael Chan | 7df4ae9 | 2016-12-02 21:17:17 -0500 | [diff] [blame] | 7280 | bnxt_dcb_init(bp); |
| 7281 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7282 | #ifdef CONFIG_BNXT_SRIOV |
| 7283 | init_waitqueue_head(&bp->sriov_cfg_wait); |
| 7284 | #endif |
Michael Chan | 309369c | 2016-06-13 02:25:34 -0400 | [diff] [blame] | 7285 | bp->gro_func = bnxt_gro_func_5730x; |
Michael Chan | 94758f8 | 2016-06-13 02:25:35 -0400 | [diff] [blame] | 7286 | if (BNXT_CHIP_NUM_57X1X(bp->chip_num)) |
| 7287 | bp->gro_func = bnxt_gro_func_5731x; |
Michael Chan | 309369c | 2016-06-13 02:25:34 -0400 | [diff] [blame] | 7288 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7289 | rc = bnxt_hwrm_func_drv_rgtr(bp); |
| 7290 | if (rc) |
| 7291 | goto init_err; |
| 7292 | |
Michael Chan | a1653b1 | 2016-12-07 00:26:20 -0500 | [diff] [blame] | 7293 | rc = bnxt_hwrm_func_rgtr_async_events(bp, NULL, 0); |
| 7294 | if (rc) |
| 7295 | goto init_err; |
| 7296 | |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 7297 | bp->ulp_probe = bnxt_ulp_probe; |
| 7298 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7299 | /* Get the MAX capabilities for this function */ |
| 7300 | rc = bnxt_hwrm_func_qcaps(bp); |
| 7301 | if (rc) { |
| 7302 | netdev_err(bp->dev, "hwrm query capability failure rc: %x\n", |
| 7303 | rc); |
| 7304 | rc = -1; |
| 7305 | goto init_err; |
| 7306 | } |
| 7307 | |
| 7308 | rc = bnxt_hwrm_queue_qportcfg(bp); |
| 7309 | if (rc) { |
| 7310 | netdev_err(bp->dev, "hwrm query qportcfg failure rc: %x\n", |
| 7311 | rc); |
| 7312 | rc = -1; |
| 7313 | goto init_err; |
| 7314 | } |
| 7315 | |
Satish Baddipadige | 567b2ab | 2016-06-13 02:25:31 -0400 | [diff] [blame] | 7316 | bnxt_hwrm_func_qcfg(bp); |
Michael Chan | 5ad2cbe | 2017-01-13 01:32:03 -0500 | [diff] [blame] | 7317 | bnxt_hwrm_port_led_qcaps(bp); |
Satish Baddipadige | 567b2ab | 2016-06-13 02:25:31 -0400 | [diff] [blame] | 7318 | |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 7319 | bnxt_set_rx_skb_mode(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7320 | bnxt_set_tpa_flags(bp); |
| 7321 | bnxt_set_ring_params(bp); |
Michael Chan | 33c2657 | 2016-12-07 00:26:15 -0500 | [diff] [blame] | 7322 | bnxt_set_max_func_irqs(bp, max_irqs); |
Michael Chan | bdbd1eb | 2016-12-29 12:13:43 -0500 | [diff] [blame] | 7323 | rc = bnxt_set_dflt_rings(bp); |
| 7324 | if (rc) { |
| 7325 | netdev_err(bp->dev, "Not enough rings available.\n"); |
| 7326 | rc = -ENOMEM; |
| 7327 | goto init_err; |
| 7328 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7329 | |
Michael Chan | 87da7f7 | 2016-11-16 21:13:09 -0500 | [diff] [blame] | 7330 | /* Default RSS hash cfg. */ |
| 7331 | bp->rss_hash_cfg = VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4 | |
| 7332 | VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4 | |
| 7333 | VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6 | |
| 7334 | VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6; |
| 7335 | if (!BNXT_CHIP_NUM_57X0X(bp->chip_num) && |
| 7336 | !BNXT_CHIP_TYPE_NITRO_A0(bp) && |
| 7337 | bp->hwrm_spec_code >= 0x10501) { |
| 7338 | bp->flags |= BNXT_FLAG_UDP_RSS_CAP; |
| 7339 | bp->rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4 | |
| 7340 | VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6; |
| 7341 | } |
| 7342 | |
Michael Chan | 8fdefd6 | 2016-12-29 12:13:36 -0500 | [diff] [blame] | 7343 | bnxt_hwrm_vnic_qcaps(bp); |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 7344 | if (bnxt_rfs_supported(bp)) { |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 7345 | dev->hw_features |= NETIF_F_NTUPLE; |
| 7346 | if (bnxt_rfs_capable(bp)) { |
| 7347 | bp->flags |= BNXT_FLAG_RFS; |
| 7348 | dev->features |= NETIF_F_NTUPLE; |
| 7349 | } |
| 7350 | } |
| 7351 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7352 | if (dev->hw_features & NETIF_F_HW_VLAN_CTAG_RX) |
| 7353 | bp->flags |= BNXT_FLAG_STRIP_VLAN; |
| 7354 | |
| 7355 | rc = bnxt_probe_phy(bp); |
| 7356 | if (rc) |
| 7357 | goto init_err; |
| 7358 | |
Michael Chan | aa8ed02 | 2016-12-07 00:26:17 -0500 | [diff] [blame] | 7359 | rc = bnxt_hwrm_func_reset(bp); |
| 7360 | if (rc) |
| 7361 | goto init_err; |
| 7362 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 7363 | rc = bnxt_init_int_mode(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7364 | if (rc) |
| 7365 | goto init_err; |
| 7366 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 7367 | rc = register_netdev(dev); |
| 7368 | if (rc) |
| 7369 | goto init_err_clr_int; |
| 7370 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7371 | netdev_info(dev, "%s found at mem %lx, node addr %pM\n", |
| 7372 | board_info[ent->driver_data].name, |
| 7373 | (long)pci_resource_start(pdev, 0), dev->dev_addr); |
| 7374 | |
Ajit Khaparde | 90c4f78 | 2016-05-15 03:04:45 -0400 | [diff] [blame] | 7375 | bnxt_parse_log_pcie_link(bp); |
| 7376 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7377 | return 0; |
| 7378 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 7379 | init_err_clr_int: |
| 7380 | bnxt_clear_int_mode(bp); |
| 7381 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7382 | init_err: |
| 7383 | pci_iounmap(pdev, bp->bar0); |
| 7384 | pci_release_regions(pdev); |
| 7385 | pci_disable_device(pdev); |
| 7386 | |
| 7387 | init_err_free: |
| 7388 | free_netdev(dev); |
| 7389 | return rc; |
| 7390 | } |
| 7391 | |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 7392 | /** |
| 7393 | * bnxt_io_error_detected - called when PCI error is detected |
| 7394 | * @pdev: Pointer to PCI device |
| 7395 | * @state: The current pci connection state |
| 7396 | * |
| 7397 | * This function is called after a PCI bus error affecting |
| 7398 | * this device has been detected. |
| 7399 | */ |
| 7400 | static pci_ers_result_t bnxt_io_error_detected(struct pci_dev *pdev, |
| 7401 | pci_channel_state_t state) |
| 7402 | { |
| 7403 | struct net_device *netdev = pci_get_drvdata(pdev); |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 7404 | struct bnxt *bp = netdev_priv(netdev); |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 7405 | |
| 7406 | netdev_info(netdev, "PCI I/O error detected\n"); |
| 7407 | |
| 7408 | rtnl_lock(); |
| 7409 | netif_device_detach(netdev); |
| 7410 | |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 7411 | bnxt_ulp_stop(bp); |
| 7412 | |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 7413 | if (state == pci_channel_io_perm_failure) { |
| 7414 | rtnl_unlock(); |
| 7415 | return PCI_ERS_RESULT_DISCONNECT; |
| 7416 | } |
| 7417 | |
| 7418 | if (netif_running(netdev)) |
| 7419 | bnxt_close(netdev); |
| 7420 | |
| 7421 | pci_disable_device(pdev); |
| 7422 | rtnl_unlock(); |
| 7423 | |
| 7424 | /* Request a slot slot reset. */ |
| 7425 | return PCI_ERS_RESULT_NEED_RESET; |
| 7426 | } |
| 7427 | |
| 7428 | /** |
| 7429 | * bnxt_io_slot_reset - called after the pci bus has been reset. |
| 7430 | * @pdev: Pointer to PCI device |
| 7431 | * |
| 7432 | * Restart the card from scratch, as if from a cold-boot. |
| 7433 | * At this point, the card has exprienced a hard reset, |
| 7434 | * followed by fixups by BIOS, and has its config space |
| 7435 | * set up identically to what it was at cold boot. |
| 7436 | */ |
| 7437 | static pci_ers_result_t bnxt_io_slot_reset(struct pci_dev *pdev) |
| 7438 | { |
| 7439 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 7440 | struct bnxt *bp = netdev_priv(netdev); |
| 7441 | int err = 0; |
| 7442 | pci_ers_result_t result = PCI_ERS_RESULT_DISCONNECT; |
| 7443 | |
| 7444 | netdev_info(bp->dev, "PCI Slot Reset\n"); |
| 7445 | |
| 7446 | rtnl_lock(); |
| 7447 | |
| 7448 | if (pci_enable_device(pdev)) { |
| 7449 | dev_err(&pdev->dev, |
| 7450 | "Cannot re-enable PCI device after reset.\n"); |
| 7451 | } else { |
| 7452 | pci_set_master(pdev); |
| 7453 | |
Michael Chan | aa8ed02 | 2016-12-07 00:26:17 -0500 | [diff] [blame] | 7454 | err = bnxt_hwrm_func_reset(bp); |
| 7455 | if (!err && netif_running(netdev)) |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 7456 | err = bnxt_open(netdev); |
| 7457 | |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 7458 | if (!err) { |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 7459 | result = PCI_ERS_RESULT_RECOVERED; |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 7460 | bnxt_ulp_start(bp); |
| 7461 | } |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 7462 | } |
| 7463 | |
| 7464 | if (result != PCI_ERS_RESULT_RECOVERED && netif_running(netdev)) |
| 7465 | dev_close(netdev); |
| 7466 | |
| 7467 | rtnl_unlock(); |
| 7468 | |
| 7469 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 7470 | if (err) { |
| 7471 | dev_err(&pdev->dev, |
| 7472 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", |
| 7473 | err); /* non-fatal, continue */ |
| 7474 | } |
| 7475 | |
| 7476 | return PCI_ERS_RESULT_RECOVERED; |
| 7477 | } |
| 7478 | |
| 7479 | /** |
| 7480 | * bnxt_io_resume - called when traffic can start flowing again. |
| 7481 | * @pdev: Pointer to PCI device |
| 7482 | * |
| 7483 | * This callback is called when the error recovery driver tells |
| 7484 | * us that its OK to resume normal operation. |
| 7485 | */ |
| 7486 | static void bnxt_io_resume(struct pci_dev *pdev) |
| 7487 | { |
| 7488 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 7489 | |
| 7490 | rtnl_lock(); |
| 7491 | |
| 7492 | netif_device_attach(netdev); |
| 7493 | |
| 7494 | rtnl_unlock(); |
| 7495 | } |
| 7496 | |
| 7497 | static const struct pci_error_handlers bnxt_err_handler = { |
| 7498 | .error_detected = bnxt_io_error_detected, |
| 7499 | .slot_reset = bnxt_io_slot_reset, |
| 7500 | .resume = bnxt_io_resume |
| 7501 | }; |
| 7502 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7503 | static struct pci_driver bnxt_pci_driver = { |
| 7504 | .name = DRV_MODULE_NAME, |
| 7505 | .id_table = bnxt_pci_tbl, |
| 7506 | .probe = bnxt_init_one, |
| 7507 | .remove = bnxt_remove_one, |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 7508 | .err_handler = &bnxt_err_handler, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7509 | #if defined(CONFIG_BNXT_SRIOV) |
| 7510 | .sriov_configure = bnxt_sriov_configure, |
| 7511 | #endif |
| 7512 | }; |
| 7513 | |
| 7514 | module_pci_driver(bnxt_pci_driver); |