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 | |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 576 | static struct page *__bnxt_alloc_rx_page(struct bnxt *bp, dma_addr_t *mapping, |
| 577 | gfp_t gfp) |
| 578 | { |
| 579 | struct device *dev = &bp->pdev->dev; |
| 580 | struct page *page; |
| 581 | |
| 582 | page = alloc_page(gfp); |
| 583 | if (!page) |
| 584 | return NULL; |
| 585 | |
| 586 | *mapping = dma_map_page(dev, page, 0, PAGE_SIZE, bp->rx_dir); |
| 587 | if (dma_mapping_error(dev, *mapping)) { |
| 588 | __free_page(page); |
| 589 | return NULL; |
| 590 | } |
| 591 | *mapping += bp->rx_dma_offset; |
| 592 | return page; |
| 593 | } |
| 594 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 595 | static inline u8 *__bnxt_alloc_rx_data(struct bnxt *bp, dma_addr_t *mapping, |
| 596 | gfp_t gfp) |
| 597 | { |
| 598 | u8 *data; |
| 599 | struct pci_dev *pdev = bp->pdev; |
| 600 | |
| 601 | data = kmalloc(bp->rx_buf_size, gfp); |
| 602 | if (!data) |
| 603 | return NULL; |
| 604 | |
Michael Chan | b3dba77 | 2017-02-06 16:55:35 -0500 | [diff] [blame] | 605 | *mapping = dma_map_single(&pdev->dev, data + bp->rx_dma_offset, |
Michael Chan | 745fc05 | 2017-02-06 16:55:34 -0500 | [diff] [blame] | 606 | bp->rx_buf_use_size, bp->rx_dir); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 607 | |
| 608 | if (dma_mapping_error(&pdev->dev, *mapping)) { |
| 609 | kfree(data); |
| 610 | data = NULL; |
| 611 | } |
| 612 | return data; |
| 613 | } |
| 614 | |
| 615 | static inline int bnxt_alloc_rx_data(struct bnxt *bp, |
| 616 | struct bnxt_rx_ring_info *rxr, |
| 617 | u16 prod, gfp_t gfp) |
| 618 | { |
| 619 | struct rx_bd *rxbd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)]; |
| 620 | struct bnxt_sw_rx_bd *rx_buf = &rxr->rx_buf_ring[prod]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 621 | dma_addr_t mapping; |
| 622 | |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 623 | if (BNXT_RX_PAGE_MODE(bp)) { |
| 624 | struct page *page = __bnxt_alloc_rx_page(bp, &mapping, gfp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 625 | |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 626 | if (!page) |
| 627 | return -ENOMEM; |
| 628 | |
| 629 | rx_buf->data = page; |
| 630 | rx_buf->data_ptr = page_address(page) + bp->rx_offset; |
| 631 | } else { |
| 632 | u8 *data = __bnxt_alloc_rx_data(bp, &mapping, gfp); |
| 633 | |
| 634 | if (!data) |
| 635 | return -ENOMEM; |
| 636 | |
| 637 | rx_buf->data = data; |
| 638 | rx_buf->data_ptr = data + bp->rx_offset; |
| 639 | } |
Michael Chan | 11cd119 | 2017-02-06 16:55:33 -0500 | [diff] [blame] | 640 | rx_buf->mapping = mapping; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 641 | |
| 642 | rxbd->rx_bd_haddr = cpu_to_le64(mapping); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 643 | return 0; |
| 644 | } |
| 645 | |
| 646 | 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] | 647 | void *data) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 648 | { |
| 649 | u16 prod = rxr->rx_prod; |
| 650 | struct bnxt_sw_rx_bd *cons_rx_buf, *prod_rx_buf; |
| 651 | struct rx_bd *cons_bd, *prod_bd; |
| 652 | |
| 653 | prod_rx_buf = &rxr->rx_buf_ring[prod]; |
| 654 | cons_rx_buf = &rxr->rx_buf_ring[cons]; |
| 655 | |
| 656 | prod_rx_buf->data = data; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 657 | prod_rx_buf->data_ptr = cons_rx_buf->data_ptr; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 658 | |
Michael Chan | 11cd119 | 2017-02-06 16:55:33 -0500 | [diff] [blame] | 659 | prod_rx_buf->mapping = cons_rx_buf->mapping; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 660 | |
| 661 | prod_bd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)]; |
| 662 | cons_bd = &rxr->rx_desc_ring[RX_RING(cons)][RX_IDX(cons)]; |
| 663 | |
| 664 | prod_bd->rx_bd_haddr = cons_bd->rx_bd_haddr; |
| 665 | } |
| 666 | |
| 667 | static inline u16 bnxt_find_next_agg_idx(struct bnxt_rx_ring_info *rxr, u16 idx) |
| 668 | { |
| 669 | u16 next, max = rxr->rx_agg_bmap_size; |
| 670 | |
| 671 | next = find_next_zero_bit(rxr->rx_agg_bmap, max, idx); |
| 672 | if (next >= max) |
| 673 | next = find_first_zero_bit(rxr->rx_agg_bmap, max); |
| 674 | return next; |
| 675 | } |
| 676 | |
| 677 | static inline int bnxt_alloc_rx_page(struct bnxt *bp, |
| 678 | struct bnxt_rx_ring_info *rxr, |
| 679 | u16 prod, gfp_t gfp) |
| 680 | { |
| 681 | struct rx_bd *rxbd = |
| 682 | &rxr->rx_agg_desc_ring[RX_RING(prod)][RX_IDX(prod)]; |
| 683 | struct bnxt_sw_rx_agg_bd *rx_agg_buf; |
| 684 | struct pci_dev *pdev = bp->pdev; |
| 685 | struct page *page; |
| 686 | dma_addr_t mapping; |
| 687 | u16 sw_prod = rxr->rx_sw_agg_prod; |
Michael Chan | 89d0a06 | 2016-04-25 02:30:51 -0400 | [diff] [blame] | 688 | unsigned int offset = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 689 | |
Michael Chan | 89d0a06 | 2016-04-25 02:30:51 -0400 | [diff] [blame] | 690 | if (PAGE_SIZE > BNXT_RX_PAGE_SIZE) { |
| 691 | page = rxr->rx_page; |
| 692 | if (!page) { |
| 693 | page = alloc_page(gfp); |
| 694 | if (!page) |
| 695 | return -ENOMEM; |
| 696 | rxr->rx_page = page; |
| 697 | rxr->rx_page_offset = 0; |
| 698 | } |
| 699 | offset = rxr->rx_page_offset; |
| 700 | rxr->rx_page_offset += BNXT_RX_PAGE_SIZE; |
| 701 | if (rxr->rx_page_offset == PAGE_SIZE) |
| 702 | rxr->rx_page = NULL; |
| 703 | else |
| 704 | get_page(page); |
| 705 | } else { |
| 706 | page = alloc_page(gfp); |
| 707 | if (!page) |
| 708 | return -ENOMEM; |
| 709 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 710 | |
Michael Chan | 89d0a06 | 2016-04-25 02:30:51 -0400 | [diff] [blame] | 711 | mapping = dma_map_page(&pdev->dev, page, offset, BNXT_RX_PAGE_SIZE, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 712 | PCI_DMA_FROMDEVICE); |
| 713 | if (dma_mapping_error(&pdev->dev, mapping)) { |
| 714 | __free_page(page); |
| 715 | return -EIO; |
| 716 | } |
| 717 | |
| 718 | if (unlikely(test_bit(sw_prod, rxr->rx_agg_bmap))) |
| 719 | sw_prod = bnxt_find_next_agg_idx(rxr, sw_prod); |
| 720 | |
| 721 | __set_bit(sw_prod, rxr->rx_agg_bmap); |
| 722 | rx_agg_buf = &rxr->rx_agg_ring[sw_prod]; |
| 723 | rxr->rx_sw_agg_prod = NEXT_RX_AGG(sw_prod); |
| 724 | |
| 725 | rx_agg_buf->page = page; |
Michael Chan | 89d0a06 | 2016-04-25 02:30:51 -0400 | [diff] [blame] | 726 | rx_agg_buf->offset = offset; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 727 | rx_agg_buf->mapping = mapping; |
| 728 | rxbd->rx_bd_haddr = cpu_to_le64(mapping); |
| 729 | rxbd->rx_bd_opaque = sw_prod; |
| 730 | return 0; |
| 731 | } |
| 732 | |
| 733 | static void bnxt_reuse_rx_agg_bufs(struct bnxt_napi *bnapi, u16 cp_cons, |
| 734 | u32 agg_bufs) |
| 735 | { |
| 736 | struct bnxt *bp = bnapi->bp; |
| 737 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 738 | struct bnxt_rx_ring_info *rxr = bnapi->rx_ring; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 739 | u16 prod = rxr->rx_agg_prod; |
| 740 | u16 sw_prod = rxr->rx_sw_agg_prod; |
| 741 | u32 i; |
| 742 | |
| 743 | for (i = 0; i < agg_bufs; i++) { |
| 744 | u16 cons; |
| 745 | struct rx_agg_cmp *agg; |
| 746 | struct bnxt_sw_rx_agg_bd *cons_rx_buf, *prod_rx_buf; |
| 747 | struct rx_bd *prod_bd; |
| 748 | struct page *page; |
| 749 | |
| 750 | agg = (struct rx_agg_cmp *) |
| 751 | &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; |
| 752 | cons = agg->rx_agg_cmp_opaque; |
| 753 | __clear_bit(cons, rxr->rx_agg_bmap); |
| 754 | |
| 755 | if (unlikely(test_bit(sw_prod, rxr->rx_agg_bmap))) |
| 756 | sw_prod = bnxt_find_next_agg_idx(rxr, sw_prod); |
| 757 | |
| 758 | __set_bit(sw_prod, rxr->rx_agg_bmap); |
| 759 | prod_rx_buf = &rxr->rx_agg_ring[sw_prod]; |
| 760 | cons_rx_buf = &rxr->rx_agg_ring[cons]; |
| 761 | |
| 762 | /* It is possible for sw_prod to be equal to cons, so |
| 763 | * set cons_rx_buf->page to NULL first. |
| 764 | */ |
| 765 | page = cons_rx_buf->page; |
| 766 | cons_rx_buf->page = NULL; |
| 767 | prod_rx_buf->page = page; |
Michael Chan | 89d0a06 | 2016-04-25 02:30:51 -0400 | [diff] [blame] | 768 | prod_rx_buf->offset = cons_rx_buf->offset; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 769 | |
| 770 | prod_rx_buf->mapping = cons_rx_buf->mapping; |
| 771 | |
| 772 | prod_bd = &rxr->rx_agg_desc_ring[RX_RING(prod)][RX_IDX(prod)]; |
| 773 | |
| 774 | prod_bd->rx_bd_haddr = cpu_to_le64(cons_rx_buf->mapping); |
| 775 | prod_bd->rx_bd_opaque = sw_prod; |
| 776 | |
| 777 | prod = NEXT_RX_AGG(prod); |
| 778 | sw_prod = NEXT_RX_AGG(sw_prod); |
| 779 | cp_cons = NEXT_CMP(cp_cons); |
| 780 | } |
| 781 | rxr->rx_agg_prod = prod; |
| 782 | rxr->rx_sw_agg_prod = sw_prod; |
| 783 | } |
| 784 | |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 785 | static struct sk_buff *bnxt_rx_page_skb(struct bnxt *bp, |
| 786 | struct bnxt_rx_ring_info *rxr, |
| 787 | u16 cons, void *data, u8 *data_ptr, |
| 788 | dma_addr_t dma_addr, |
| 789 | unsigned int offset_and_len) |
| 790 | { |
| 791 | unsigned int payload = offset_and_len >> 16; |
| 792 | unsigned int len = offset_and_len & 0xffff; |
| 793 | struct skb_frag_struct *frag; |
| 794 | struct page *page = data; |
| 795 | u16 prod = rxr->rx_prod; |
| 796 | struct sk_buff *skb; |
| 797 | int off, err; |
| 798 | |
| 799 | err = bnxt_alloc_rx_data(bp, rxr, prod, GFP_ATOMIC); |
| 800 | if (unlikely(err)) { |
| 801 | bnxt_reuse_rx_data(rxr, cons, data); |
| 802 | return NULL; |
| 803 | } |
| 804 | dma_addr -= bp->rx_dma_offset; |
| 805 | dma_unmap_page(&bp->pdev->dev, dma_addr, PAGE_SIZE, bp->rx_dir); |
| 806 | |
| 807 | if (unlikely(!payload)) |
| 808 | payload = eth_get_headlen(data_ptr, len); |
| 809 | |
| 810 | skb = napi_alloc_skb(&rxr->bnapi->napi, payload); |
| 811 | if (!skb) { |
| 812 | __free_page(page); |
| 813 | return NULL; |
| 814 | } |
| 815 | |
| 816 | off = (void *)data_ptr - page_address(page); |
| 817 | skb_add_rx_frag(skb, 0, page, off, len, PAGE_SIZE); |
| 818 | memcpy(skb->data - NET_IP_ALIGN, data_ptr - NET_IP_ALIGN, |
| 819 | payload + NET_IP_ALIGN); |
| 820 | |
| 821 | frag = &skb_shinfo(skb)->frags[0]; |
| 822 | skb_frag_size_sub(frag, payload); |
| 823 | frag->page_offset += payload; |
| 824 | skb->data_len -= payload; |
| 825 | skb->tail += payload; |
| 826 | |
| 827 | return skb; |
| 828 | } |
| 829 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 830 | static struct sk_buff *bnxt_rx_skb(struct bnxt *bp, |
| 831 | struct bnxt_rx_ring_info *rxr, u16 cons, |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 832 | void *data, u8 *data_ptr, |
| 833 | dma_addr_t dma_addr, |
| 834 | unsigned int offset_and_len) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 835 | { |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 836 | u16 prod = rxr->rx_prod; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 837 | struct sk_buff *skb; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 838 | int err; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 839 | |
| 840 | err = bnxt_alloc_rx_data(bp, rxr, prod, GFP_ATOMIC); |
| 841 | if (unlikely(err)) { |
| 842 | bnxt_reuse_rx_data(rxr, cons, data); |
| 843 | return NULL; |
| 844 | } |
| 845 | |
| 846 | skb = build_skb(data, 0); |
| 847 | 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] | 848 | bp->rx_dir); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 849 | if (!skb) { |
| 850 | kfree(data); |
| 851 | return NULL; |
| 852 | } |
| 853 | |
Michael Chan | b3dba77 | 2017-02-06 16:55:35 -0500 | [diff] [blame] | 854 | skb_reserve(skb, bp->rx_offset); |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 855 | skb_put(skb, offset_and_len & 0xffff); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 856 | return skb; |
| 857 | } |
| 858 | |
| 859 | static struct sk_buff *bnxt_rx_pages(struct bnxt *bp, struct bnxt_napi *bnapi, |
| 860 | struct sk_buff *skb, u16 cp_cons, |
| 861 | u32 agg_bufs) |
| 862 | { |
| 863 | struct pci_dev *pdev = bp->pdev; |
| 864 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 865 | struct bnxt_rx_ring_info *rxr = bnapi->rx_ring; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 866 | u16 prod = rxr->rx_agg_prod; |
| 867 | u32 i; |
| 868 | |
| 869 | for (i = 0; i < agg_bufs; i++) { |
| 870 | u16 cons, frag_len; |
| 871 | struct rx_agg_cmp *agg; |
| 872 | struct bnxt_sw_rx_agg_bd *cons_rx_buf; |
| 873 | struct page *page; |
| 874 | dma_addr_t mapping; |
| 875 | |
| 876 | agg = (struct rx_agg_cmp *) |
| 877 | &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; |
| 878 | cons = agg->rx_agg_cmp_opaque; |
| 879 | frag_len = (le32_to_cpu(agg->rx_agg_cmp_len_flags_type) & |
| 880 | RX_AGG_CMP_LEN) >> RX_AGG_CMP_LEN_SHIFT; |
| 881 | |
| 882 | cons_rx_buf = &rxr->rx_agg_ring[cons]; |
Michael Chan | 89d0a06 | 2016-04-25 02:30:51 -0400 | [diff] [blame] | 883 | skb_fill_page_desc(skb, i, cons_rx_buf->page, |
| 884 | cons_rx_buf->offset, frag_len); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 885 | __clear_bit(cons, rxr->rx_agg_bmap); |
| 886 | |
| 887 | /* It is possible for bnxt_alloc_rx_page() to allocate |
| 888 | * a sw_prod index that equals the cons index, so we |
| 889 | * need to clear the cons entry now. |
| 890 | */ |
Michael Chan | 11cd119 | 2017-02-06 16:55:33 -0500 | [diff] [blame] | 891 | mapping = cons_rx_buf->mapping; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 892 | page = cons_rx_buf->page; |
| 893 | cons_rx_buf->page = NULL; |
| 894 | |
| 895 | if (bnxt_alloc_rx_page(bp, rxr, prod, GFP_ATOMIC) != 0) { |
| 896 | struct skb_shared_info *shinfo; |
| 897 | unsigned int nr_frags; |
| 898 | |
| 899 | shinfo = skb_shinfo(skb); |
| 900 | nr_frags = --shinfo->nr_frags; |
| 901 | __skb_frag_set_page(&shinfo->frags[nr_frags], NULL); |
| 902 | |
| 903 | dev_kfree_skb(skb); |
| 904 | |
| 905 | cons_rx_buf->page = page; |
| 906 | |
| 907 | /* Update prod since possibly some pages have been |
| 908 | * allocated already. |
| 909 | */ |
| 910 | rxr->rx_agg_prod = prod; |
| 911 | bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs - i); |
| 912 | return NULL; |
| 913 | } |
| 914 | |
Michael Chan | 2839f28 | 2016-04-25 02:30:50 -0400 | [diff] [blame] | 915 | dma_unmap_page(&pdev->dev, mapping, BNXT_RX_PAGE_SIZE, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 916 | PCI_DMA_FROMDEVICE); |
| 917 | |
| 918 | skb->data_len += frag_len; |
| 919 | skb->len += frag_len; |
| 920 | skb->truesize += PAGE_SIZE; |
| 921 | |
| 922 | prod = NEXT_RX_AGG(prod); |
| 923 | cp_cons = NEXT_CMP(cp_cons); |
| 924 | } |
| 925 | rxr->rx_agg_prod = prod; |
| 926 | return skb; |
| 927 | } |
| 928 | |
| 929 | static int bnxt_agg_bufs_valid(struct bnxt *bp, struct bnxt_cp_ring_info *cpr, |
| 930 | u8 agg_bufs, u32 *raw_cons) |
| 931 | { |
| 932 | u16 last; |
| 933 | struct rx_agg_cmp *agg; |
| 934 | |
| 935 | *raw_cons = ADV_RAW_CMP(*raw_cons, agg_bufs); |
| 936 | last = RING_CMP(*raw_cons); |
| 937 | agg = (struct rx_agg_cmp *) |
| 938 | &cpr->cp_desc_ring[CP_RING(last)][CP_IDX(last)]; |
| 939 | return RX_AGG_CMP_VALID(agg, *raw_cons); |
| 940 | } |
| 941 | |
| 942 | static inline struct sk_buff *bnxt_copy_skb(struct bnxt_napi *bnapi, u8 *data, |
| 943 | unsigned int len, |
| 944 | dma_addr_t mapping) |
| 945 | { |
| 946 | struct bnxt *bp = bnapi->bp; |
| 947 | struct pci_dev *pdev = bp->pdev; |
| 948 | struct sk_buff *skb; |
| 949 | |
| 950 | skb = napi_alloc_skb(&bnapi->napi, len); |
| 951 | if (!skb) |
| 952 | return NULL; |
| 953 | |
Michael Chan | 745fc05 | 2017-02-06 16:55:34 -0500 | [diff] [blame] | 954 | dma_sync_single_for_cpu(&pdev->dev, mapping, bp->rx_copy_thresh, |
| 955 | bp->rx_dir); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 956 | |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 957 | memcpy(skb->data - NET_IP_ALIGN, data - NET_IP_ALIGN, |
| 958 | len + NET_IP_ALIGN); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 959 | |
Michael Chan | 745fc05 | 2017-02-06 16:55:34 -0500 | [diff] [blame] | 960 | dma_sync_single_for_device(&pdev->dev, mapping, bp->rx_copy_thresh, |
| 961 | bp->rx_dir); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 962 | |
| 963 | skb_put(skb, len); |
| 964 | return skb; |
| 965 | } |
| 966 | |
Michael Chan | fa7e281 | 2016-05-10 19:18:00 -0400 | [diff] [blame] | 967 | static int bnxt_discard_rx(struct bnxt *bp, struct bnxt_napi *bnapi, |
| 968 | u32 *raw_cons, void *cmp) |
| 969 | { |
| 970 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 971 | struct rx_cmp *rxcmp = cmp; |
| 972 | u32 tmp_raw_cons = *raw_cons; |
| 973 | u8 cmp_type, agg_bufs = 0; |
| 974 | |
| 975 | cmp_type = RX_CMP_TYPE(rxcmp); |
| 976 | |
| 977 | if (cmp_type == CMP_TYPE_RX_L2_CMP) { |
| 978 | agg_bufs = (le32_to_cpu(rxcmp->rx_cmp_misc_v1) & |
| 979 | RX_CMP_AGG_BUFS) >> |
| 980 | RX_CMP_AGG_BUFS_SHIFT; |
| 981 | } else if (cmp_type == CMP_TYPE_RX_L2_TPA_END_CMP) { |
| 982 | struct rx_tpa_end_cmp *tpa_end = cmp; |
| 983 | |
| 984 | agg_bufs = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) & |
| 985 | RX_TPA_END_CMP_AGG_BUFS) >> |
| 986 | RX_TPA_END_CMP_AGG_BUFS_SHIFT; |
| 987 | } |
| 988 | |
| 989 | if (agg_bufs) { |
| 990 | if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, &tmp_raw_cons)) |
| 991 | return -EBUSY; |
| 992 | } |
| 993 | *raw_cons = tmp_raw_cons; |
| 994 | return 0; |
| 995 | } |
| 996 | |
| 997 | static void bnxt_sched_reset(struct bnxt *bp, struct bnxt_rx_ring_info *rxr) |
| 998 | { |
| 999 | if (!rxr->bnapi->in_reset) { |
| 1000 | rxr->bnapi->in_reset = true; |
| 1001 | set_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event); |
| 1002 | schedule_work(&bp->sp_task); |
| 1003 | } |
| 1004 | rxr->rx_next_cons = 0xffff; |
| 1005 | } |
| 1006 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1007 | static void bnxt_tpa_start(struct bnxt *bp, struct bnxt_rx_ring_info *rxr, |
| 1008 | struct rx_tpa_start_cmp *tpa_start, |
| 1009 | struct rx_tpa_start_cmp_ext *tpa_start1) |
| 1010 | { |
| 1011 | u8 agg_id = TPA_START_AGG_ID(tpa_start); |
| 1012 | u16 cons, prod; |
| 1013 | struct bnxt_tpa_info *tpa_info; |
| 1014 | struct bnxt_sw_rx_bd *cons_rx_buf, *prod_rx_buf; |
| 1015 | struct rx_bd *prod_bd; |
| 1016 | dma_addr_t mapping; |
| 1017 | |
| 1018 | cons = tpa_start->rx_tpa_start_cmp_opaque; |
| 1019 | prod = rxr->rx_prod; |
| 1020 | cons_rx_buf = &rxr->rx_buf_ring[cons]; |
| 1021 | prod_rx_buf = &rxr->rx_buf_ring[prod]; |
| 1022 | tpa_info = &rxr->rx_tpa[agg_id]; |
| 1023 | |
Michael Chan | fa7e281 | 2016-05-10 19:18:00 -0400 | [diff] [blame] | 1024 | if (unlikely(cons != rxr->rx_next_cons)) { |
| 1025 | bnxt_sched_reset(bp, rxr); |
| 1026 | return; |
| 1027 | } |
| 1028 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1029 | prod_rx_buf->data = tpa_info->data; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1030 | prod_rx_buf->data_ptr = tpa_info->data_ptr; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1031 | |
| 1032 | mapping = tpa_info->mapping; |
Michael Chan | 11cd119 | 2017-02-06 16:55:33 -0500 | [diff] [blame] | 1033 | prod_rx_buf->mapping = mapping; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1034 | |
| 1035 | prod_bd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)]; |
| 1036 | |
| 1037 | prod_bd->rx_bd_haddr = cpu_to_le64(mapping); |
| 1038 | |
| 1039 | tpa_info->data = cons_rx_buf->data; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1040 | tpa_info->data_ptr = cons_rx_buf->data_ptr; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1041 | cons_rx_buf->data = NULL; |
Michael Chan | 11cd119 | 2017-02-06 16:55:33 -0500 | [diff] [blame] | 1042 | tpa_info->mapping = cons_rx_buf->mapping; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1043 | |
| 1044 | tpa_info->len = |
| 1045 | le32_to_cpu(tpa_start->rx_tpa_start_cmp_len_flags_type) >> |
| 1046 | RX_TPA_START_CMP_LEN_SHIFT; |
| 1047 | if (likely(TPA_START_HASH_VALID(tpa_start))) { |
| 1048 | u32 hash_type = TPA_START_HASH_TYPE(tpa_start); |
| 1049 | |
| 1050 | tpa_info->hash_type = PKT_HASH_TYPE_L4; |
| 1051 | tpa_info->gso_type = SKB_GSO_TCPV4; |
| 1052 | /* RSS profiles 1 and 3 with extract code 0 for inner 4-tuple */ |
| 1053 | if (hash_type == 3) |
| 1054 | tpa_info->gso_type = SKB_GSO_TCPV6; |
| 1055 | tpa_info->rss_hash = |
| 1056 | le32_to_cpu(tpa_start->rx_tpa_start_cmp_rss_hash); |
| 1057 | } else { |
| 1058 | tpa_info->hash_type = PKT_HASH_TYPE_NONE; |
| 1059 | tpa_info->gso_type = 0; |
| 1060 | if (netif_msg_rx_err(bp)) |
| 1061 | netdev_warn(bp->dev, "TPA packet without valid hash\n"); |
| 1062 | } |
| 1063 | tpa_info->flags2 = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_flags2); |
| 1064 | 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] | 1065 | 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] | 1066 | |
| 1067 | rxr->rx_prod = NEXT_RX(prod); |
| 1068 | cons = NEXT_RX(cons); |
Michael Chan | 376a5b8 | 2016-05-10 19:17:59 -0400 | [diff] [blame] | 1069 | rxr->rx_next_cons = NEXT_RX(cons); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1070 | cons_rx_buf = &rxr->rx_buf_ring[cons]; |
| 1071 | |
| 1072 | bnxt_reuse_rx_data(rxr, cons, cons_rx_buf->data); |
| 1073 | rxr->rx_prod = NEXT_RX(rxr->rx_prod); |
| 1074 | cons_rx_buf->data = NULL; |
| 1075 | } |
| 1076 | |
| 1077 | static void bnxt_abort_tpa(struct bnxt *bp, struct bnxt_napi *bnapi, |
| 1078 | u16 cp_cons, u32 agg_bufs) |
| 1079 | { |
| 1080 | if (agg_bufs) |
| 1081 | bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs); |
| 1082 | } |
| 1083 | |
Michael Chan | 94758f8 | 2016-06-13 02:25:35 -0400 | [diff] [blame] | 1084 | static struct sk_buff *bnxt_gro_func_5731x(struct bnxt_tpa_info *tpa_info, |
| 1085 | int payload_off, int tcp_ts, |
| 1086 | struct sk_buff *skb) |
| 1087 | { |
| 1088 | #ifdef CONFIG_INET |
| 1089 | struct tcphdr *th; |
| 1090 | int len, nw_off; |
| 1091 | u16 outer_ip_off, inner_ip_off, inner_mac_off; |
| 1092 | u32 hdr_info = tpa_info->hdr_info; |
| 1093 | bool loopback = false; |
| 1094 | |
| 1095 | inner_ip_off = BNXT_TPA_INNER_L3_OFF(hdr_info); |
| 1096 | inner_mac_off = BNXT_TPA_INNER_L2_OFF(hdr_info); |
| 1097 | outer_ip_off = BNXT_TPA_OUTER_L3_OFF(hdr_info); |
| 1098 | |
| 1099 | /* If the packet is an internal loopback packet, the offsets will |
| 1100 | * have an extra 4 bytes. |
| 1101 | */ |
| 1102 | if (inner_mac_off == 4) { |
| 1103 | loopback = true; |
| 1104 | } else if (inner_mac_off > 4) { |
| 1105 | __be16 proto = *((__be16 *)(skb->data + inner_ip_off - |
| 1106 | ETH_HLEN - 2)); |
| 1107 | |
| 1108 | /* We only support inner iPv4/ipv6. If we don't see the |
| 1109 | * correct protocol ID, it must be a loopback packet where |
| 1110 | * the offsets are off by 4. |
| 1111 | */ |
Dan Carpenter | 09a7636 | 2016-07-07 11:23:09 +0300 | [diff] [blame] | 1112 | if (proto != htons(ETH_P_IP) && proto != htons(ETH_P_IPV6)) |
Michael Chan | 94758f8 | 2016-06-13 02:25:35 -0400 | [diff] [blame] | 1113 | loopback = true; |
| 1114 | } |
| 1115 | if (loopback) { |
| 1116 | /* internal loopback packet, subtract all offsets by 4 */ |
| 1117 | inner_ip_off -= 4; |
| 1118 | inner_mac_off -= 4; |
| 1119 | outer_ip_off -= 4; |
| 1120 | } |
| 1121 | |
| 1122 | nw_off = inner_ip_off - ETH_HLEN; |
| 1123 | skb_set_network_header(skb, nw_off); |
| 1124 | if (tpa_info->flags2 & RX_TPA_START_CMP_FLAGS2_IP_TYPE) { |
| 1125 | struct ipv6hdr *iph = ipv6_hdr(skb); |
| 1126 | |
| 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 | struct iphdr *iph = ip_hdr(skb); |
| 1133 | |
| 1134 | skb_set_transport_header(skb, nw_off + sizeof(struct iphdr)); |
| 1135 | len = skb->len - skb_transport_offset(skb); |
| 1136 | th = tcp_hdr(skb); |
| 1137 | th->check = ~tcp_v4_check(len, iph->saddr, iph->daddr, 0); |
| 1138 | } |
| 1139 | |
| 1140 | if (inner_mac_off) { /* tunnel */ |
| 1141 | struct udphdr *uh = NULL; |
| 1142 | __be16 proto = *((__be16 *)(skb->data + outer_ip_off - |
| 1143 | ETH_HLEN - 2)); |
| 1144 | |
| 1145 | if (proto == htons(ETH_P_IP)) { |
| 1146 | struct iphdr *iph = (struct iphdr *)skb->data; |
| 1147 | |
| 1148 | if (iph->protocol == IPPROTO_UDP) |
| 1149 | uh = (struct udphdr *)(iph + 1); |
| 1150 | } else { |
| 1151 | struct ipv6hdr *iph = (struct ipv6hdr *)skb->data; |
| 1152 | |
| 1153 | if (iph->nexthdr == IPPROTO_UDP) |
| 1154 | uh = (struct udphdr *)(iph + 1); |
| 1155 | } |
| 1156 | if (uh) { |
| 1157 | if (uh->check) |
| 1158 | skb_shinfo(skb)->gso_type |= |
| 1159 | SKB_GSO_UDP_TUNNEL_CSUM; |
| 1160 | else |
| 1161 | skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL; |
| 1162 | } |
| 1163 | } |
| 1164 | #endif |
| 1165 | return skb; |
| 1166 | } |
| 1167 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1168 | #define BNXT_IPV4_HDR_SIZE (sizeof(struct iphdr) + sizeof(struct tcphdr)) |
| 1169 | #define BNXT_IPV6_HDR_SIZE (sizeof(struct ipv6hdr) + sizeof(struct tcphdr)) |
| 1170 | |
Michael Chan | 309369c | 2016-06-13 02:25:34 -0400 | [diff] [blame] | 1171 | static struct sk_buff *bnxt_gro_func_5730x(struct bnxt_tpa_info *tpa_info, |
| 1172 | int payload_off, int tcp_ts, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1173 | struct sk_buff *skb) |
| 1174 | { |
Michael Chan | d1611c3 | 2015-10-25 22:27:57 -0400 | [diff] [blame] | 1175 | #ifdef CONFIG_INET |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1176 | struct tcphdr *th; |
Michael Chan | 719ca81 | 2017-01-17 22:07:19 -0500 | [diff] [blame] | 1177 | int len, nw_off, tcp_opt_len = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1178 | |
Michael Chan | 309369c | 2016-06-13 02:25:34 -0400 | [diff] [blame] | 1179 | if (tcp_ts) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1180 | tcp_opt_len = 12; |
| 1181 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1182 | if (tpa_info->gso_type == SKB_GSO_TCPV4) { |
| 1183 | struct iphdr *iph; |
| 1184 | |
| 1185 | nw_off = payload_off - BNXT_IPV4_HDR_SIZE - tcp_opt_len - |
| 1186 | ETH_HLEN; |
| 1187 | skb_set_network_header(skb, nw_off); |
| 1188 | iph = ip_hdr(skb); |
| 1189 | skb_set_transport_header(skb, nw_off + sizeof(struct iphdr)); |
| 1190 | len = skb->len - skb_transport_offset(skb); |
| 1191 | th = tcp_hdr(skb); |
| 1192 | th->check = ~tcp_v4_check(len, iph->saddr, iph->daddr, 0); |
| 1193 | } else if (tpa_info->gso_type == SKB_GSO_TCPV6) { |
| 1194 | struct ipv6hdr *iph; |
| 1195 | |
| 1196 | nw_off = payload_off - BNXT_IPV6_HDR_SIZE - tcp_opt_len - |
| 1197 | ETH_HLEN; |
| 1198 | skb_set_network_header(skb, nw_off); |
| 1199 | iph = ipv6_hdr(skb); |
| 1200 | skb_set_transport_header(skb, nw_off + sizeof(struct ipv6hdr)); |
| 1201 | len = skb->len - skb_transport_offset(skb); |
| 1202 | th = tcp_hdr(skb); |
| 1203 | th->check = ~tcp_v6_check(len, &iph->saddr, &iph->daddr, 0); |
| 1204 | } else { |
| 1205 | dev_kfree_skb_any(skb); |
| 1206 | return NULL; |
| 1207 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1208 | |
| 1209 | if (nw_off) { /* tunnel */ |
| 1210 | struct udphdr *uh = NULL; |
| 1211 | |
| 1212 | if (skb->protocol == htons(ETH_P_IP)) { |
| 1213 | struct iphdr *iph = (struct iphdr *)skb->data; |
| 1214 | |
| 1215 | if (iph->protocol == IPPROTO_UDP) |
| 1216 | uh = (struct udphdr *)(iph + 1); |
| 1217 | } else { |
| 1218 | struct ipv6hdr *iph = (struct ipv6hdr *)skb->data; |
| 1219 | |
| 1220 | if (iph->nexthdr == IPPROTO_UDP) |
| 1221 | uh = (struct udphdr *)(iph + 1); |
| 1222 | } |
| 1223 | if (uh) { |
| 1224 | if (uh->check) |
| 1225 | skb_shinfo(skb)->gso_type |= |
| 1226 | SKB_GSO_UDP_TUNNEL_CSUM; |
| 1227 | else |
| 1228 | skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL; |
| 1229 | } |
| 1230 | } |
| 1231 | #endif |
| 1232 | return skb; |
| 1233 | } |
| 1234 | |
Michael Chan | 309369c | 2016-06-13 02:25:34 -0400 | [diff] [blame] | 1235 | static inline struct sk_buff *bnxt_gro_skb(struct bnxt *bp, |
| 1236 | struct bnxt_tpa_info *tpa_info, |
| 1237 | struct rx_tpa_end_cmp *tpa_end, |
| 1238 | struct rx_tpa_end_cmp_ext *tpa_end1, |
| 1239 | struct sk_buff *skb) |
| 1240 | { |
| 1241 | #ifdef CONFIG_INET |
| 1242 | int payload_off; |
| 1243 | u16 segs; |
| 1244 | |
| 1245 | segs = TPA_END_TPA_SEGS(tpa_end); |
| 1246 | if (segs == 1) |
| 1247 | return skb; |
| 1248 | |
| 1249 | NAPI_GRO_CB(skb)->count = segs; |
| 1250 | skb_shinfo(skb)->gso_size = |
| 1251 | le32_to_cpu(tpa_end1->rx_tpa_end_cmp_seg_len); |
| 1252 | skb_shinfo(skb)->gso_type = tpa_info->gso_type; |
| 1253 | payload_off = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) & |
| 1254 | RX_TPA_END_CMP_PAYLOAD_OFFSET) >> |
| 1255 | RX_TPA_END_CMP_PAYLOAD_OFFSET_SHIFT; |
| 1256 | 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] | 1257 | if (likely(skb)) |
| 1258 | tcp_gro_complete(skb); |
Michael Chan | 309369c | 2016-06-13 02:25:34 -0400 | [diff] [blame] | 1259 | #endif |
| 1260 | return skb; |
| 1261 | } |
| 1262 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1263 | static inline struct sk_buff *bnxt_tpa_end(struct bnxt *bp, |
| 1264 | struct bnxt_napi *bnapi, |
| 1265 | u32 *raw_cons, |
| 1266 | struct rx_tpa_end_cmp *tpa_end, |
| 1267 | struct rx_tpa_end_cmp_ext *tpa_end1, |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame^] | 1268 | u8 *event) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1269 | { |
| 1270 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 1271 | struct bnxt_rx_ring_info *rxr = bnapi->rx_ring; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1272 | u8 agg_id = TPA_END_AGG_ID(tpa_end); |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1273 | u8 *data_ptr, agg_bufs; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1274 | u16 cp_cons = RING_CMP(*raw_cons); |
| 1275 | unsigned int len; |
| 1276 | struct bnxt_tpa_info *tpa_info; |
| 1277 | dma_addr_t mapping; |
| 1278 | struct sk_buff *skb; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1279 | void *data; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1280 | |
Michael Chan | fa7e281 | 2016-05-10 19:18:00 -0400 | [diff] [blame] | 1281 | if (unlikely(bnapi->in_reset)) { |
| 1282 | int rc = bnxt_discard_rx(bp, bnapi, raw_cons, tpa_end); |
| 1283 | |
| 1284 | if (rc < 0) |
| 1285 | return ERR_PTR(-EBUSY); |
| 1286 | return NULL; |
| 1287 | } |
| 1288 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1289 | tpa_info = &rxr->rx_tpa[agg_id]; |
| 1290 | data = tpa_info->data; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1291 | data_ptr = tpa_info->data_ptr; |
| 1292 | prefetch(data_ptr); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1293 | len = tpa_info->len; |
| 1294 | mapping = tpa_info->mapping; |
| 1295 | |
| 1296 | agg_bufs = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) & |
| 1297 | RX_TPA_END_CMP_AGG_BUFS) >> RX_TPA_END_CMP_AGG_BUFS_SHIFT; |
| 1298 | |
| 1299 | if (agg_bufs) { |
| 1300 | if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, raw_cons)) |
| 1301 | return ERR_PTR(-EBUSY); |
| 1302 | |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame^] | 1303 | *event |= BNXT_AGG_EVENT; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1304 | cp_cons = NEXT_CMP(cp_cons); |
| 1305 | } |
| 1306 | |
| 1307 | if (unlikely(agg_bufs > MAX_SKB_FRAGS)) { |
| 1308 | bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs); |
| 1309 | netdev_warn(bp->dev, "TPA frags %d exceeded MAX_SKB_FRAGS %d\n", |
| 1310 | agg_bufs, (int)MAX_SKB_FRAGS); |
| 1311 | return NULL; |
| 1312 | } |
| 1313 | |
| 1314 | if (len <= bp->rx_copy_thresh) { |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1315 | skb = bnxt_copy_skb(bnapi, data_ptr, len, mapping); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1316 | if (!skb) { |
| 1317 | bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs); |
| 1318 | return NULL; |
| 1319 | } |
| 1320 | } else { |
| 1321 | u8 *new_data; |
| 1322 | dma_addr_t new_mapping; |
| 1323 | |
| 1324 | new_data = __bnxt_alloc_rx_data(bp, &new_mapping, GFP_ATOMIC); |
| 1325 | if (!new_data) { |
| 1326 | bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs); |
| 1327 | return NULL; |
| 1328 | } |
| 1329 | |
| 1330 | tpa_info->data = new_data; |
Michael Chan | b3dba77 | 2017-02-06 16:55:35 -0500 | [diff] [blame] | 1331 | tpa_info->data_ptr = new_data + bp->rx_offset; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1332 | tpa_info->mapping = new_mapping; |
| 1333 | |
| 1334 | skb = build_skb(data, 0); |
| 1335 | dma_unmap_single(&bp->pdev->dev, mapping, bp->rx_buf_use_size, |
Michael Chan | 745fc05 | 2017-02-06 16:55:34 -0500 | [diff] [blame] | 1336 | bp->rx_dir); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1337 | |
| 1338 | if (!skb) { |
| 1339 | kfree(data); |
| 1340 | bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs); |
| 1341 | return NULL; |
| 1342 | } |
Michael Chan | b3dba77 | 2017-02-06 16:55:35 -0500 | [diff] [blame] | 1343 | skb_reserve(skb, bp->rx_offset); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1344 | skb_put(skb, len); |
| 1345 | } |
| 1346 | |
| 1347 | if (agg_bufs) { |
| 1348 | skb = bnxt_rx_pages(bp, bnapi, skb, cp_cons, agg_bufs); |
| 1349 | if (!skb) { |
| 1350 | /* Page reuse already handled by bnxt_rx_pages(). */ |
| 1351 | return NULL; |
| 1352 | } |
| 1353 | } |
| 1354 | skb->protocol = eth_type_trans(skb, bp->dev); |
| 1355 | |
| 1356 | if (tpa_info->hash_type != PKT_HASH_TYPE_NONE) |
| 1357 | skb_set_hash(skb, tpa_info->rss_hash, tpa_info->hash_type); |
| 1358 | |
Michael Chan | 8852ddb | 2016-06-06 02:37:16 -0400 | [diff] [blame] | 1359 | if ((tpa_info->flags2 & RX_CMP_FLAGS2_META_FORMAT_VLAN) && |
| 1360 | (skb->dev->features & NETIF_F_HW_VLAN_CTAG_RX)) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1361 | u16 vlan_proto = tpa_info->metadata >> |
| 1362 | RX_CMP_FLAGS2_METADATA_TPID_SFT; |
Michael Chan | 8852ddb | 2016-06-06 02:37:16 -0400 | [diff] [blame] | 1363 | u16 vtag = tpa_info->metadata & RX_CMP_FLAGS2_METADATA_VID_MASK; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1364 | |
Michael Chan | 8852ddb | 2016-06-06 02:37:16 -0400 | [diff] [blame] | 1365 | __vlan_hwaccel_put_tag(skb, htons(vlan_proto), vtag); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1366 | } |
| 1367 | |
| 1368 | skb_checksum_none_assert(skb); |
| 1369 | if (likely(tpa_info->flags2 & RX_TPA_START_CMP_FLAGS2_L4_CS_CALC)) { |
| 1370 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 1371 | skb->csum_level = |
| 1372 | (tpa_info->flags2 & RX_CMP_FLAGS2_T_L4_CS_CALC) >> 3; |
| 1373 | } |
| 1374 | |
| 1375 | if (TPA_END_GRO(tpa_end)) |
Michael Chan | 309369c | 2016-06-13 02:25:34 -0400 | [diff] [blame] | 1376 | skb = bnxt_gro_skb(bp, tpa_info, tpa_end, tpa_end1, skb); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1377 | |
| 1378 | return skb; |
| 1379 | } |
| 1380 | |
| 1381 | /* returns the following: |
| 1382 | * 1 - 1 packet successfully received |
| 1383 | * 0 - successful TPA_START, packet not completed yet |
| 1384 | * -EBUSY - completion ring does not have all the agg buffers yet |
| 1385 | * -ENOMEM - packet aborted due to out of memory |
| 1386 | * -EIO - packet aborted due to hw error indicated in BD |
| 1387 | */ |
| 1388 | static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_napi *bnapi, u32 *raw_cons, |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame^] | 1389 | u8 *event) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1390 | { |
| 1391 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 1392 | struct bnxt_rx_ring_info *rxr = bnapi->rx_ring; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1393 | struct net_device *dev = bp->dev; |
| 1394 | struct rx_cmp *rxcmp; |
| 1395 | struct rx_cmp_ext *rxcmp1; |
| 1396 | u32 tmp_raw_cons = *raw_cons; |
| 1397 | u16 cons, prod, cp_cons = RING_CMP(tmp_raw_cons); |
| 1398 | struct bnxt_sw_rx_bd *rx_buf; |
| 1399 | unsigned int len; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1400 | u8 *data_ptr, agg_bufs, cmp_type; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1401 | dma_addr_t dma_addr; |
| 1402 | struct sk_buff *skb; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1403 | void *data; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1404 | int rc = 0; |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 1405 | u32 misc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1406 | |
| 1407 | rxcmp = (struct rx_cmp *) |
| 1408 | &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; |
| 1409 | |
| 1410 | tmp_raw_cons = NEXT_RAW_CMP(tmp_raw_cons); |
| 1411 | cp_cons = RING_CMP(tmp_raw_cons); |
| 1412 | rxcmp1 = (struct rx_cmp_ext *) |
| 1413 | &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; |
| 1414 | |
| 1415 | if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons)) |
| 1416 | return -EBUSY; |
| 1417 | |
| 1418 | cmp_type = RX_CMP_TYPE(rxcmp); |
| 1419 | |
| 1420 | prod = rxr->rx_prod; |
| 1421 | |
| 1422 | if (cmp_type == CMP_TYPE_RX_L2_TPA_START_CMP) { |
| 1423 | bnxt_tpa_start(bp, rxr, (struct rx_tpa_start_cmp *)rxcmp, |
| 1424 | (struct rx_tpa_start_cmp_ext *)rxcmp1); |
| 1425 | |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame^] | 1426 | *event |= BNXT_RX_EVENT; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1427 | goto next_rx_no_prod; |
| 1428 | |
| 1429 | } else if (cmp_type == CMP_TYPE_RX_L2_TPA_END_CMP) { |
| 1430 | skb = bnxt_tpa_end(bp, bnapi, &tmp_raw_cons, |
| 1431 | (struct rx_tpa_end_cmp *)rxcmp, |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame^] | 1432 | (struct rx_tpa_end_cmp_ext *)rxcmp1, event); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1433 | |
| 1434 | if (unlikely(IS_ERR(skb))) |
| 1435 | return -EBUSY; |
| 1436 | |
| 1437 | rc = -ENOMEM; |
| 1438 | if (likely(skb)) { |
| 1439 | skb_record_rx_queue(skb, bnapi->index); |
Michael Chan | b356a2e | 2016-12-29 12:13:31 -0500 | [diff] [blame] | 1440 | napi_gro_receive(&bnapi->napi, skb); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1441 | rc = 1; |
| 1442 | } |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame^] | 1443 | *event |= BNXT_RX_EVENT; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1444 | goto next_rx_no_prod; |
| 1445 | } |
| 1446 | |
| 1447 | cons = rxcmp->rx_cmp_opaque; |
| 1448 | rx_buf = &rxr->rx_buf_ring[cons]; |
| 1449 | data = rx_buf->data; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1450 | data_ptr = rx_buf->data_ptr; |
Michael Chan | fa7e281 | 2016-05-10 19:18:00 -0400 | [diff] [blame] | 1451 | if (unlikely(cons != rxr->rx_next_cons)) { |
| 1452 | int rc1 = bnxt_discard_rx(bp, bnapi, raw_cons, rxcmp); |
| 1453 | |
| 1454 | bnxt_sched_reset(bp, rxr); |
| 1455 | return rc1; |
| 1456 | } |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1457 | prefetch(data_ptr); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1458 | |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 1459 | misc = le32_to_cpu(rxcmp->rx_cmp_misc_v1); |
| 1460 | agg_bufs = (misc & RX_CMP_AGG_BUFS) >> RX_CMP_AGG_BUFS_SHIFT; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1461 | |
| 1462 | if (agg_bufs) { |
| 1463 | if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, &tmp_raw_cons)) |
| 1464 | return -EBUSY; |
| 1465 | |
| 1466 | cp_cons = NEXT_CMP(cp_cons); |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame^] | 1467 | *event |= BNXT_AGG_EVENT; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1468 | } |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame^] | 1469 | *event |= BNXT_RX_EVENT; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1470 | |
| 1471 | rx_buf->data = NULL; |
| 1472 | if (rxcmp1->rx_cmp_cfa_code_errors_v2 & RX_CMP_L2_ERRORS) { |
| 1473 | bnxt_reuse_rx_data(rxr, cons, data); |
| 1474 | if (agg_bufs) |
| 1475 | bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs); |
| 1476 | |
| 1477 | rc = -EIO; |
| 1478 | goto next_rx; |
| 1479 | } |
| 1480 | |
| 1481 | 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] | 1482 | dma_addr = rx_buf->mapping; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1483 | |
| 1484 | if (len <= bp->rx_copy_thresh) { |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1485 | skb = bnxt_copy_skb(bnapi, data_ptr, len, dma_addr); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1486 | bnxt_reuse_rx_data(rxr, cons, data); |
| 1487 | if (!skb) { |
| 1488 | rc = -ENOMEM; |
| 1489 | goto next_rx; |
| 1490 | } |
| 1491 | } else { |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 1492 | u32 payload; |
| 1493 | |
| 1494 | payload = misc & RX_CMP_PAYLOAD_OFFSET; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1495 | skb = bp->rx_skb_func(bp, rxr, cons, data, data_ptr, dma_addr, |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 1496 | payload | len); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1497 | if (!skb) { |
| 1498 | rc = -ENOMEM; |
| 1499 | goto next_rx; |
| 1500 | } |
| 1501 | } |
| 1502 | |
| 1503 | if (agg_bufs) { |
| 1504 | skb = bnxt_rx_pages(bp, bnapi, skb, cp_cons, agg_bufs); |
| 1505 | if (!skb) { |
| 1506 | rc = -ENOMEM; |
| 1507 | goto next_rx; |
| 1508 | } |
| 1509 | } |
| 1510 | |
| 1511 | if (RX_CMP_HASH_VALID(rxcmp)) { |
| 1512 | u32 hash_type = RX_CMP_HASH_TYPE(rxcmp); |
| 1513 | enum pkt_hash_types type = PKT_HASH_TYPE_L4; |
| 1514 | |
| 1515 | /* RSS profiles 1 and 3 with extract code 0 for inner 4-tuple */ |
| 1516 | if (hash_type != 1 && hash_type != 3) |
| 1517 | type = PKT_HASH_TYPE_L3; |
| 1518 | skb_set_hash(skb, le32_to_cpu(rxcmp->rx_cmp_rss_hash), type); |
| 1519 | } |
| 1520 | |
| 1521 | skb->protocol = eth_type_trans(skb, dev); |
| 1522 | |
Michael Chan | 8852ddb | 2016-06-06 02:37:16 -0400 | [diff] [blame] | 1523 | if ((rxcmp1->rx_cmp_flags2 & |
| 1524 | cpu_to_le32(RX_CMP_FLAGS2_META_FORMAT_VLAN)) && |
| 1525 | (skb->dev->features & NETIF_F_HW_VLAN_CTAG_RX)) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1526 | u32 meta_data = le32_to_cpu(rxcmp1->rx_cmp_meta_data); |
Michael Chan | 8852ddb | 2016-06-06 02:37:16 -0400 | [diff] [blame] | 1527 | u16 vtag = meta_data & RX_CMP_FLAGS2_METADATA_VID_MASK; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1528 | u16 vlan_proto = meta_data >> RX_CMP_FLAGS2_METADATA_TPID_SFT; |
| 1529 | |
Michael Chan | 8852ddb | 2016-06-06 02:37:16 -0400 | [diff] [blame] | 1530 | __vlan_hwaccel_put_tag(skb, htons(vlan_proto), vtag); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1531 | } |
| 1532 | |
| 1533 | skb_checksum_none_assert(skb); |
| 1534 | if (RX_CMP_L4_CS_OK(rxcmp1)) { |
| 1535 | if (dev->features & NETIF_F_RXCSUM) { |
| 1536 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 1537 | skb->csum_level = RX_CMP_ENCAP(rxcmp1); |
| 1538 | } |
| 1539 | } else { |
Satish Baddipadige | 665e350 | 2015-12-27 18:19:21 -0500 | [diff] [blame] | 1540 | if (rxcmp1->rx_cmp_cfa_code_errors_v2 & RX_CMP_L4_CS_ERR_BITS) { |
| 1541 | if (dev->features & NETIF_F_RXCSUM) |
| 1542 | cpr->rx_l4_csum_errors++; |
| 1543 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1544 | } |
| 1545 | |
| 1546 | skb_record_rx_queue(skb, bnapi->index); |
Michael Chan | b356a2e | 2016-12-29 12:13:31 -0500 | [diff] [blame] | 1547 | napi_gro_receive(&bnapi->napi, skb); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1548 | rc = 1; |
| 1549 | |
| 1550 | next_rx: |
| 1551 | rxr->rx_prod = NEXT_RX(prod); |
Michael Chan | 376a5b8 | 2016-05-10 19:17:59 -0400 | [diff] [blame] | 1552 | rxr->rx_next_cons = NEXT_RX(cons); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1553 | |
| 1554 | next_rx_no_prod: |
| 1555 | *raw_cons = tmp_raw_cons; |
| 1556 | |
| 1557 | return rc; |
| 1558 | } |
| 1559 | |
Michael Chan | 4bb13ab | 2016-04-05 14:09:01 -0400 | [diff] [blame] | 1560 | #define BNXT_GET_EVENT_PORT(data) \ |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 1561 | ((data) & \ |
| 1562 | ASYNC_EVENT_CMPL_PORT_CONN_NOT_ALLOWED_EVENT_DATA1_PORT_ID_MASK) |
Michael Chan | 4bb13ab | 2016-04-05 14:09:01 -0400 | [diff] [blame] | 1563 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1564 | static int bnxt_async_event_process(struct bnxt *bp, |
| 1565 | struct hwrm_async_event_cmpl *cmpl) |
| 1566 | { |
| 1567 | u16 event_id = le16_to_cpu(cmpl->event_id); |
| 1568 | |
| 1569 | /* TODO CHIMP_FW: Define event id's for link change, error etc */ |
| 1570 | switch (event_id) { |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 1571 | case ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE: { |
Michael Chan | 8cbde11 | 2016-04-11 04:11:14 -0400 | [diff] [blame] | 1572 | u32 data1 = le32_to_cpu(cmpl->event_data1); |
| 1573 | struct bnxt_link_info *link_info = &bp->link_info; |
| 1574 | |
| 1575 | if (BNXT_VF(bp)) |
| 1576 | goto async_event_process_exit; |
| 1577 | if (data1 & 0x20000) { |
| 1578 | u16 fw_speed = link_info->force_link_speed; |
| 1579 | u32 speed = bnxt_fw_to_ethtool_speed(fw_speed); |
| 1580 | |
| 1581 | netdev_warn(bp->dev, "Link speed %d no longer supported\n", |
| 1582 | speed); |
| 1583 | } |
Michael Chan | 286ef9d | 2016-11-16 21:13:08 -0500 | [diff] [blame] | 1584 | set_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT, &bp->sp_event); |
Michael Chan | 8cbde11 | 2016-04-11 04:11:14 -0400 | [diff] [blame] | 1585 | /* fall thru */ |
| 1586 | } |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 1587 | case ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE: |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1588 | set_bit(BNXT_LINK_CHNG_SP_EVENT, &bp->sp_event); |
Jeffrey Huang | 1924136 | 2016-02-26 04:00:00 -0500 | [diff] [blame] | 1589 | break; |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 1590 | case ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD: |
Jeffrey Huang | 1924136 | 2016-02-26 04:00:00 -0500 | [diff] [blame] | 1591 | set_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT, &bp->sp_event); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1592 | break; |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 1593 | case ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED: { |
Michael Chan | 4bb13ab | 2016-04-05 14:09:01 -0400 | [diff] [blame] | 1594 | u32 data1 = le32_to_cpu(cmpl->event_data1); |
| 1595 | u16 port_id = BNXT_GET_EVENT_PORT(data1); |
| 1596 | |
| 1597 | if (BNXT_VF(bp)) |
| 1598 | break; |
| 1599 | |
| 1600 | if (bp->pf.port_id != port_id) |
| 1601 | break; |
| 1602 | |
Michael Chan | 4bb13ab | 2016-04-05 14:09:01 -0400 | [diff] [blame] | 1603 | set_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT, &bp->sp_event); |
| 1604 | break; |
| 1605 | } |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 1606 | case ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE: |
Michael Chan | fc0f192 | 2016-06-13 02:25:30 -0400 | [diff] [blame] | 1607 | if (BNXT_PF(bp)) |
| 1608 | goto async_event_process_exit; |
| 1609 | set_bit(BNXT_RESET_TASK_SILENT_SP_EVENT, &bp->sp_event); |
| 1610 | break; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1611 | default: |
Jeffrey Huang | 1924136 | 2016-02-26 04:00:00 -0500 | [diff] [blame] | 1612 | goto async_event_process_exit; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1613 | } |
Jeffrey Huang | 1924136 | 2016-02-26 04:00:00 -0500 | [diff] [blame] | 1614 | schedule_work(&bp->sp_task); |
| 1615 | async_event_process_exit: |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 1616 | bnxt_ulp_async_events(bp, cmpl); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1617 | return 0; |
| 1618 | } |
| 1619 | |
| 1620 | static int bnxt_hwrm_handler(struct bnxt *bp, struct tx_cmp *txcmp) |
| 1621 | { |
| 1622 | u16 cmpl_type = TX_CMP_TYPE(txcmp), vf_id, seq_id; |
| 1623 | struct hwrm_cmpl *h_cmpl = (struct hwrm_cmpl *)txcmp; |
| 1624 | struct hwrm_fwd_req_cmpl *fwd_req_cmpl = |
| 1625 | (struct hwrm_fwd_req_cmpl *)txcmp; |
| 1626 | |
| 1627 | switch (cmpl_type) { |
| 1628 | case CMPL_BASE_TYPE_HWRM_DONE: |
| 1629 | seq_id = le16_to_cpu(h_cmpl->sequence_id); |
| 1630 | if (seq_id == bp->hwrm_intr_seq_id) |
| 1631 | bp->hwrm_intr_seq_id = HWRM_SEQ_ID_INVALID; |
| 1632 | else |
| 1633 | netdev_err(bp->dev, "Invalid hwrm seq id %d\n", seq_id); |
| 1634 | break; |
| 1635 | |
| 1636 | case CMPL_BASE_TYPE_HWRM_FWD_REQ: |
| 1637 | vf_id = le16_to_cpu(fwd_req_cmpl->source_id); |
| 1638 | |
| 1639 | if ((vf_id < bp->pf.first_vf_id) || |
| 1640 | (vf_id >= bp->pf.first_vf_id + bp->pf.active_vfs)) { |
| 1641 | netdev_err(bp->dev, "Msg contains invalid VF id %x\n", |
| 1642 | vf_id); |
| 1643 | return -EINVAL; |
| 1644 | } |
| 1645 | |
| 1646 | set_bit(vf_id - bp->pf.first_vf_id, bp->pf.vf_event_bmap); |
| 1647 | set_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT, &bp->sp_event); |
| 1648 | schedule_work(&bp->sp_task); |
| 1649 | break; |
| 1650 | |
| 1651 | case CMPL_BASE_TYPE_HWRM_ASYNC_EVENT: |
| 1652 | bnxt_async_event_process(bp, |
| 1653 | (struct hwrm_async_event_cmpl *)txcmp); |
| 1654 | |
| 1655 | default: |
| 1656 | break; |
| 1657 | } |
| 1658 | |
| 1659 | return 0; |
| 1660 | } |
| 1661 | |
| 1662 | static irqreturn_t bnxt_msix(int irq, void *dev_instance) |
| 1663 | { |
| 1664 | struct bnxt_napi *bnapi = dev_instance; |
| 1665 | struct bnxt *bp = bnapi->bp; |
| 1666 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 1667 | u32 cons = RING_CMP(cpr->cp_raw_cons); |
| 1668 | |
| 1669 | prefetch(&cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]); |
| 1670 | napi_schedule(&bnapi->napi); |
| 1671 | return IRQ_HANDLED; |
| 1672 | } |
| 1673 | |
| 1674 | static inline int bnxt_has_work(struct bnxt *bp, struct bnxt_cp_ring_info *cpr) |
| 1675 | { |
| 1676 | u32 raw_cons = cpr->cp_raw_cons; |
| 1677 | u16 cons = RING_CMP(raw_cons); |
| 1678 | struct tx_cmp *txcmp; |
| 1679 | |
| 1680 | txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]; |
| 1681 | |
| 1682 | return TX_CMP_VALID(txcmp, raw_cons); |
| 1683 | } |
| 1684 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1685 | static irqreturn_t bnxt_inta(int irq, void *dev_instance) |
| 1686 | { |
| 1687 | struct bnxt_napi *bnapi = dev_instance; |
| 1688 | struct bnxt *bp = bnapi->bp; |
| 1689 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 1690 | u32 cons = RING_CMP(cpr->cp_raw_cons); |
| 1691 | u32 int_status; |
| 1692 | |
| 1693 | prefetch(&cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]); |
| 1694 | |
| 1695 | if (!bnxt_has_work(bp, cpr)) { |
Jeffrey Huang | 1180949 | 2015-11-05 16:25:49 -0500 | [diff] [blame] | 1696 | int_status = readl(bp->bar0 + BNXT_CAG_REG_LEGACY_INT_STATUS); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1697 | /* return if erroneous interrupt */ |
| 1698 | if (!(int_status & (0x10000 << cpr->cp_ring_struct.fw_ring_id))) |
| 1699 | return IRQ_NONE; |
| 1700 | } |
| 1701 | |
| 1702 | /* disable ring IRQ */ |
| 1703 | BNXT_CP_DB_IRQ_DIS(cpr->cp_doorbell); |
| 1704 | |
| 1705 | /* Return here if interrupt is shared and is disabled. */ |
| 1706 | if (unlikely(atomic_read(&bp->intr_sem) != 0)) |
| 1707 | return IRQ_HANDLED; |
| 1708 | |
| 1709 | napi_schedule(&bnapi->napi); |
| 1710 | return IRQ_HANDLED; |
| 1711 | } |
| 1712 | |
| 1713 | static int bnxt_poll_work(struct bnxt *bp, struct bnxt_napi *bnapi, int budget) |
| 1714 | { |
| 1715 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 1716 | u32 raw_cons = cpr->cp_raw_cons; |
| 1717 | u32 cons; |
| 1718 | int tx_pkts = 0; |
| 1719 | int rx_pkts = 0; |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame^] | 1720 | u8 event = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1721 | struct tx_cmp *txcmp; |
| 1722 | |
| 1723 | while (1) { |
| 1724 | int rc; |
| 1725 | |
| 1726 | cons = RING_CMP(raw_cons); |
| 1727 | txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]; |
| 1728 | |
| 1729 | if (!TX_CMP_VALID(txcmp, raw_cons)) |
| 1730 | break; |
| 1731 | |
Michael Chan | 67a95e2 | 2016-05-04 16:56:43 -0400 | [diff] [blame] | 1732 | /* The valid test of the entry must be done first before |
| 1733 | * reading any further. |
| 1734 | */ |
Michael Chan | b67daab | 2016-05-15 03:04:51 -0400 | [diff] [blame] | 1735 | dma_rmb(); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1736 | if (TX_CMP_TYPE(txcmp) == CMP_TYPE_TX_L2_CMP) { |
| 1737 | tx_pkts++; |
| 1738 | /* return full budget so NAPI will complete. */ |
| 1739 | if (unlikely(tx_pkts > bp->tx_wake_thresh)) |
| 1740 | rx_pkts = budget; |
| 1741 | } else if ((TX_CMP_TYPE(txcmp) & 0x30) == 0x10) { |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame^] | 1742 | rc = bnxt_rx_pkt(bp, bnapi, &raw_cons, &event); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1743 | if (likely(rc >= 0)) |
| 1744 | rx_pkts += rc; |
| 1745 | else if (rc == -EBUSY) /* partial completion */ |
| 1746 | break; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1747 | } else if (unlikely((TX_CMP_TYPE(txcmp) == |
| 1748 | CMPL_BASE_TYPE_HWRM_DONE) || |
| 1749 | (TX_CMP_TYPE(txcmp) == |
| 1750 | CMPL_BASE_TYPE_HWRM_FWD_REQ) || |
| 1751 | (TX_CMP_TYPE(txcmp) == |
| 1752 | CMPL_BASE_TYPE_HWRM_ASYNC_EVENT))) { |
| 1753 | bnxt_hwrm_handler(bp, txcmp); |
| 1754 | } |
| 1755 | raw_cons = NEXT_RAW_CMP(raw_cons); |
| 1756 | |
| 1757 | if (rx_pkts == budget) |
| 1758 | break; |
| 1759 | } |
| 1760 | |
| 1761 | cpr->cp_raw_cons = raw_cons; |
| 1762 | /* ACK completion ring before freeing tx ring and producing new |
| 1763 | * buffers in rx/agg rings to prevent overflowing the completion |
| 1764 | * ring. |
| 1765 | */ |
| 1766 | BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons); |
| 1767 | |
| 1768 | if (tx_pkts) |
| 1769 | bnxt_tx_int(bp, bnapi, tx_pkts); |
| 1770 | |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame^] | 1771 | if (event & BNXT_RX_EVENT) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 1772 | struct bnxt_rx_ring_info *rxr = bnapi->rx_ring; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1773 | |
| 1774 | writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell); |
| 1775 | writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell); |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame^] | 1776 | if (event & BNXT_AGG_EVENT) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1777 | writel(DB_KEY_RX | rxr->rx_agg_prod, |
| 1778 | rxr->rx_agg_doorbell); |
| 1779 | writel(DB_KEY_RX | rxr->rx_agg_prod, |
| 1780 | rxr->rx_agg_doorbell); |
| 1781 | } |
| 1782 | } |
| 1783 | return rx_pkts; |
| 1784 | } |
| 1785 | |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 1786 | static int bnxt_poll_nitroa0(struct napi_struct *napi, int budget) |
| 1787 | { |
| 1788 | struct bnxt_napi *bnapi = container_of(napi, struct bnxt_napi, napi); |
| 1789 | struct bnxt *bp = bnapi->bp; |
| 1790 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 1791 | struct bnxt_rx_ring_info *rxr = bnapi->rx_ring; |
| 1792 | struct tx_cmp *txcmp; |
| 1793 | struct rx_cmp_ext *rxcmp1; |
| 1794 | u32 cp_cons, tmp_raw_cons; |
| 1795 | u32 raw_cons = cpr->cp_raw_cons; |
| 1796 | u32 rx_pkts = 0; |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame^] | 1797 | u8 event = 0; |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 1798 | |
| 1799 | while (1) { |
| 1800 | int rc; |
| 1801 | |
| 1802 | cp_cons = RING_CMP(raw_cons); |
| 1803 | txcmp = &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; |
| 1804 | |
| 1805 | if (!TX_CMP_VALID(txcmp, raw_cons)) |
| 1806 | break; |
| 1807 | |
| 1808 | if ((TX_CMP_TYPE(txcmp) & 0x30) == 0x10) { |
| 1809 | tmp_raw_cons = NEXT_RAW_CMP(raw_cons); |
| 1810 | cp_cons = RING_CMP(tmp_raw_cons); |
| 1811 | rxcmp1 = (struct rx_cmp_ext *) |
| 1812 | &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; |
| 1813 | |
| 1814 | if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons)) |
| 1815 | break; |
| 1816 | |
| 1817 | /* force an error to recycle the buffer */ |
| 1818 | rxcmp1->rx_cmp_cfa_code_errors_v2 |= |
| 1819 | cpu_to_le32(RX_CMPL_ERRORS_CRC_ERROR); |
| 1820 | |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame^] | 1821 | rc = bnxt_rx_pkt(bp, bnapi, &raw_cons, &event); |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 1822 | if (likely(rc == -EIO)) |
| 1823 | rx_pkts++; |
| 1824 | else if (rc == -EBUSY) /* partial completion */ |
| 1825 | break; |
| 1826 | } else if (unlikely(TX_CMP_TYPE(txcmp) == |
| 1827 | CMPL_BASE_TYPE_HWRM_DONE)) { |
| 1828 | bnxt_hwrm_handler(bp, txcmp); |
| 1829 | } else { |
| 1830 | netdev_err(bp->dev, |
| 1831 | "Invalid completion received on special ring\n"); |
| 1832 | } |
| 1833 | raw_cons = NEXT_RAW_CMP(raw_cons); |
| 1834 | |
| 1835 | if (rx_pkts == budget) |
| 1836 | break; |
| 1837 | } |
| 1838 | |
| 1839 | cpr->cp_raw_cons = raw_cons; |
| 1840 | BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons); |
| 1841 | writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell); |
| 1842 | writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell); |
| 1843 | |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame^] | 1844 | if (event & BNXT_AGG_EVENT) { |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 1845 | writel(DB_KEY_RX | rxr->rx_agg_prod, rxr->rx_agg_doorbell); |
| 1846 | writel(DB_KEY_RX | rxr->rx_agg_prod, rxr->rx_agg_doorbell); |
| 1847 | } |
| 1848 | |
| 1849 | if (!bnxt_has_work(bp, cpr) && rx_pkts < budget) { |
Eric Dumazet | 6ad2016 | 2017-01-30 08:22:01 -0800 | [diff] [blame] | 1850 | napi_complete_done(napi, rx_pkts); |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 1851 | BNXT_CP_DB_REARM(cpr->cp_doorbell, cpr->cp_raw_cons); |
| 1852 | } |
| 1853 | return rx_pkts; |
| 1854 | } |
| 1855 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1856 | static int bnxt_poll(struct napi_struct *napi, int budget) |
| 1857 | { |
| 1858 | struct bnxt_napi *bnapi = container_of(napi, struct bnxt_napi, napi); |
| 1859 | struct bnxt *bp = bnapi->bp; |
| 1860 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 1861 | int work_done = 0; |
| 1862 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1863 | while (1) { |
| 1864 | work_done += bnxt_poll_work(bp, bnapi, budget - work_done); |
| 1865 | |
| 1866 | if (work_done >= budget) |
| 1867 | break; |
| 1868 | |
| 1869 | if (!bnxt_has_work(bp, cpr)) { |
Michael Chan | e7b9569 | 2016-12-29 12:13:32 -0500 | [diff] [blame] | 1870 | if (napi_complete_done(napi, work_done)) |
| 1871 | BNXT_CP_DB_REARM(cpr->cp_doorbell, |
| 1872 | cpr->cp_raw_cons); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1873 | break; |
| 1874 | } |
| 1875 | } |
| 1876 | mmiowb(); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1877 | return work_done; |
| 1878 | } |
| 1879 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1880 | static void bnxt_free_tx_skbs(struct bnxt *bp) |
| 1881 | { |
| 1882 | int i, max_idx; |
| 1883 | struct pci_dev *pdev = bp->pdev; |
| 1884 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 1885 | if (!bp->tx_ring) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1886 | return; |
| 1887 | |
| 1888 | max_idx = bp->tx_nr_pages * TX_DESC_CNT; |
| 1889 | for (i = 0; i < bp->tx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 1890 | struct bnxt_tx_ring_info *txr = &bp->tx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1891 | int j; |
| 1892 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1893 | for (j = 0; j < max_idx;) { |
| 1894 | struct bnxt_sw_tx_bd *tx_buf = &txr->tx_buf_ring[j]; |
| 1895 | struct sk_buff *skb = tx_buf->skb; |
| 1896 | int k, last; |
| 1897 | |
| 1898 | if (!skb) { |
| 1899 | j++; |
| 1900 | continue; |
| 1901 | } |
| 1902 | |
| 1903 | tx_buf->skb = NULL; |
| 1904 | |
| 1905 | if (tx_buf->is_push) { |
| 1906 | dev_kfree_skb(skb); |
| 1907 | j += 2; |
| 1908 | continue; |
| 1909 | } |
| 1910 | |
| 1911 | dma_unmap_single(&pdev->dev, |
| 1912 | dma_unmap_addr(tx_buf, mapping), |
| 1913 | skb_headlen(skb), |
| 1914 | PCI_DMA_TODEVICE); |
| 1915 | |
| 1916 | last = tx_buf->nr_frags; |
| 1917 | j += 2; |
Michael Chan | d612a57 | 2016-01-28 03:11:22 -0500 | [diff] [blame] | 1918 | for (k = 0; k < last; k++, j++) { |
| 1919 | int ring_idx = j & bp->tx_ring_mask; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1920 | skb_frag_t *frag = &skb_shinfo(skb)->frags[k]; |
| 1921 | |
Michael Chan | d612a57 | 2016-01-28 03:11:22 -0500 | [diff] [blame] | 1922 | tx_buf = &txr->tx_buf_ring[ring_idx]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1923 | dma_unmap_page( |
| 1924 | &pdev->dev, |
| 1925 | dma_unmap_addr(tx_buf, mapping), |
| 1926 | skb_frag_size(frag), PCI_DMA_TODEVICE); |
| 1927 | } |
| 1928 | dev_kfree_skb(skb); |
| 1929 | } |
| 1930 | netdev_tx_reset_queue(netdev_get_tx_queue(bp->dev, i)); |
| 1931 | } |
| 1932 | } |
| 1933 | |
| 1934 | static void bnxt_free_rx_skbs(struct bnxt *bp) |
| 1935 | { |
| 1936 | int i, max_idx, max_agg_idx; |
| 1937 | struct pci_dev *pdev = bp->pdev; |
| 1938 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 1939 | if (!bp->rx_ring) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1940 | return; |
| 1941 | |
| 1942 | max_idx = bp->rx_nr_pages * RX_DESC_CNT; |
| 1943 | max_agg_idx = bp->rx_agg_nr_pages * RX_DESC_CNT; |
| 1944 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 1945 | struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1946 | int j; |
| 1947 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1948 | if (rxr->rx_tpa) { |
| 1949 | for (j = 0; j < MAX_TPA; j++) { |
| 1950 | struct bnxt_tpa_info *tpa_info = |
| 1951 | &rxr->rx_tpa[j]; |
| 1952 | u8 *data = tpa_info->data; |
| 1953 | |
| 1954 | if (!data) |
| 1955 | continue; |
| 1956 | |
Michael Chan | 745fc05 | 2017-02-06 16:55:34 -0500 | [diff] [blame] | 1957 | dma_unmap_single(&pdev->dev, tpa_info->mapping, |
| 1958 | bp->rx_buf_use_size, |
| 1959 | bp->rx_dir); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1960 | |
| 1961 | tpa_info->data = NULL; |
| 1962 | |
| 1963 | kfree(data); |
| 1964 | } |
| 1965 | } |
| 1966 | |
| 1967 | for (j = 0; j < max_idx; j++) { |
| 1968 | struct bnxt_sw_rx_bd *rx_buf = &rxr->rx_buf_ring[j]; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1969 | void *data = rx_buf->data; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1970 | |
| 1971 | if (!data) |
| 1972 | continue; |
| 1973 | |
Michael Chan | 11cd119 | 2017-02-06 16:55:33 -0500 | [diff] [blame] | 1974 | dma_unmap_single(&pdev->dev, rx_buf->mapping, |
Michael Chan | 745fc05 | 2017-02-06 16:55:34 -0500 | [diff] [blame] | 1975 | bp->rx_buf_use_size, bp->rx_dir); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1976 | |
| 1977 | rx_buf->data = NULL; |
| 1978 | |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 1979 | if (BNXT_RX_PAGE_MODE(bp)) |
| 1980 | __free_page(data); |
| 1981 | else |
| 1982 | kfree(data); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1983 | } |
| 1984 | |
| 1985 | for (j = 0; j < max_agg_idx; j++) { |
| 1986 | struct bnxt_sw_rx_agg_bd *rx_agg_buf = |
| 1987 | &rxr->rx_agg_ring[j]; |
| 1988 | struct page *page = rx_agg_buf->page; |
| 1989 | |
| 1990 | if (!page) |
| 1991 | continue; |
| 1992 | |
Michael Chan | 11cd119 | 2017-02-06 16:55:33 -0500 | [diff] [blame] | 1993 | dma_unmap_page(&pdev->dev, rx_agg_buf->mapping, |
Michael Chan | 2839f28 | 2016-04-25 02:30:50 -0400 | [diff] [blame] | 1994 | BNXT_RX_PAGE_SIZE, PCI_DMA_FROMDEVICE); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1995 | |
| 1996 | rx_agg_buf->page = NULL; |
| 1997 | __clear_bit(j, rxr->rx_agg_bmap); |
| 1998 | |
| 1999 | __free_page(page); |
| 2000 | } |
Michael Chan | 89d0a06 | 2016-04-25 02:30:51 -0400 | [diff] [blame] | 2001 | if (rxr->rx_page) { |
| 2002 | __free_page(rxr->rx_page); |
| 2003 | rxr->rx_page = NULL; |
| 2004 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2005 | } |
| 2006 | } |
| 2007 | |
| 2008 | static void bnxt_free_skbs(struct bnxt *bp) |
| 2009 | { |
| 2010 | bnxt_free_tx_skbs(bp); |
| 2011 | bnxt_free_rx_skbs(bp); |
| 2012 | } |
| 2013 | |
| 2014 | static void bnxt_free_ring(struct bnxt *bp, struct bnxt_ring_struct *ring) |
| 2015 | { |
| 2016 | struct pci_dev *pdev = bp->pdev; |
| 2017 | int i; |
| 2018 | |
| 2019 | for (i = 0; i < ring->nr_pages; i++) { |
| 2020 | if (!ring->pg_arr[i]) |
| 2021 | continue; |
| 2022 | |
| 2023 | dma_free_coherent(&pdev->dev, ring->page_size, |
| 2024 | ring->pg_arr[i], ring->dma_arr[i]); |
| 2025 | |
| 2026 | ring->pg_arr[i] = NULL; |
| 2027 | } |
| 2028 | if (ring->pg_tbl) { |
| 2029 | dma_free_coherent(&pdev->dev, ring->nr_pages * 8, |
| 2030 | ring->pg_tbl, ring->pg_tbl_map); |
| 2031 | ring->pg_tbl = NULL; |
| 2032 | } |
| 2033 | if (ring->vmem_size && *ring->vmem) { |
| 2034 | vfree(*ring->vmem); |
| 2035 | *ring->vmem = NULL; |
| 2036 | } |
| 2037 | } |
| 2038 | |
| 2039 | static int bnxt_alloc_ring(struct bnxt *bp, struct bnxt_ring_struct *ring) |
| 2040 | { |
| 2041 | int i; |
| 2042 | struct pci_dev *pdev = bp->pdev; |
| 2043 | |
| 2044 | if (ring->nr_pages > 1) { |
| 2045 | ring->pg_tbl = dma_alloc_coherent(&pdev->dev, |
| 2046 | ring->nr_pages * 8, |
| 2047 | &ring->pg_tbl_map, |
| 2048 | GFP_KERNEL); |
| 2049 | if (!ring->pg_tbl) |
| 2050 | return -ENOMEM; |
| 2051 | } |
| 2052 | |
| 2053 | for (i = 0; i < ring->nr_pages; i++) { |
| 2054 | ring->pg_arr[i] = dma_alloc_coherent(&pdev->dev, |
| 2055 | ring->page_size, |
| 2056 | &ring->dma_arr[i], |
| 2057 | GFP_KERNEL); |
| 2058 | if (!ring->pg_arr[i]) |
| 2059 | return -ENOMEM; |
| 2060 | |
| 2061 | if (ring->nr_pages > 1) |
| 2062 | ring->pg_tbl[i] = cpu_to_le64(ring->dma_arr[i]); |
| 2063 | } |
| 2064 | |
| 2065 | if (ring->vmem_size) { |
| 2066 | *ring->vmem = vzalloc(ring->vmem_size); |
| 2067 | if (!(*ring->vmem)) |
| 2068 | return -ENOMEM; |
| 2069 | } |
| 2070 | return 0; |
| 2071 | } |
| 2072 | |
| 2073 | static void bnxt_free_rx_rings(struct bnxt *bp) |
| 2074 | { |
| 2075 | int i; |
| 2076 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2077 | if (!bp->rx_ring) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2078 | return; |
| 2079 | |
| 2080 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2081 | struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2082 | struct bnxt_ring_struct *ring; |
| 2083 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2084 | kfree(rxr->rx_tpa); |
| 2085 | rxr->rx_tpa = NULL; |
| 2086 | |
| 2087 | kfree(rxr->rx_agg_bmap); |
| 2088 | rxr->rx_agg_bmap = NULL; |
| 2089 | |
| 2090 | ring = &rxr->rx_ring_struct; |
| 2091 | bnxt_free_ring(bp, ring); |
| 2092 | |
| 2093 | ring = &rxr->rx_agg_ring_struct; |
| 2094 | bnxt_free_ring(bp, ring); |
| 2095 | } |
| 2096 | } |
| 2097 | |
| 2098 | static int bnxt_alloc_rx_rings(struct bnxt *bp) |
| 2099 | { |
| 2100 | int i, rc, agg_rings = 0, tpa_rings = 0; |
| 2101 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2102 | if (!bp->rx_ring) |
| 2103 | return -ENOMEM; |
| 2104 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2105 | if (bp->flags & BNXT_FLAG_AGG_RINGS) |
| 2106 | agg_rings = 1; |
| 2107 | |
| 2108 | if (bp->flags & BNXT_FLAG_TPA) |
| 2109 | tpa_rings = 1; |
| 2110 | |
| 2111 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2112 | struct bnxt_rx_ring_info *rxr = &bp->rx_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 = &rxr->rx_ring_struct; |
| 2116 | |
| 2117 | rc = bnxt_alloc_ring(bp, ring); |
| 2118 | if (rc) |
| 2119 | return rc; |
| 2120 | |
| 2121 | if (agg_rings) { |
| 2122 | u16 mem_size; |
| 2123 | |
| 2124 | ring = &rxr->rx_agg_ring_struct; |
| 2125 | rc = bnxt_alloc_ring(bp, ring); |
| 2126 | if (rc) |
| 2127 | return rc; |
| 2128 | |
| 2129 | rxr->rx_agg_bmap_size = bp->rx_agg_ring_mask + 1; |
| 2130 | mem_size = rxr->rx_agg_bmap_size / 8; |
| 2131 | rxr->rx_agg_bmap = kzalloc(mem_size, GFP_KERNEL); |
| 2132 | if (!rxr->rx_agg_bmap) |
| 2133 | return -ENOMEM; |
| 2134 | |
| 2135 | if (tpa_rings) { |
| 2136 | rxr->rx_tpa = kcalloc(MAX_TPA, |
| 2137 | sizeof(struct bnxt_tpa_info), |
| 2138 | GFP_KERNEL); |
| 2139 | if (!rxr->rx_tpa) |
| 2140 | return -ENOMEM; |
| 2141 | } |
| 2142 | } |
| 2143 | } |
| 2144 | return 0; |
| 2145 | } |
| 2146 | |
| 2147 | static void bnxt_free_tx_rings(struct bnxt *bp) |
| 2148 | { |
| 2149 | int i; |
| 2150 | struct pci_dev *pdev = bp->pdev; |
| 2151 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2152 | if (!bp->tx_ring) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2153 | return; |
| 2154 | |
| 2155 | for (i = 0; i < bp->tx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2156 | struct bnxt_tx_ring_info *txr = &bp->tx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2157 | struct bnxt_ring_struct *ring; |
| 2158 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2159 | if (txr->tx_push) { |
| 2160 | dma_free_coherent(&pdev->dev, bp->tx_push_size, |
| 2161 | txr->tx_push, txr->tx_push_mapping); |
| 2162 | txr->tx_push = NULL; |
| 2163 | } |
| 2164 | |
| 2165 | ring = &txr->tx_ring_struct; |
| 2166 | |
| 2167 | bnxt_free_ring(bp, ring); |
| 2168 | } |
| 2169 | } |
| 2170 | |
| 2171 | static int bnxt_alloc_tx_rings(struct bnxt *bp) |
| 2172 | { |
| 2173 | int i, j, rc; |
| 2174 | struct pci_dev *pdev = bp->pdev; |
| 2175 | |
| 2176 | bp->tx_push_size = 0; |
| 2177 | if (bp->tx_push_thresh) { |
| 2178 | int push_size; |
| 2179 | |
| 2180 | push_size = L1_CACHE_ALIGN(sizeof(struct tx_push_bd) + |
| 2181 | bp->tx_push_thresh); |
| 2182 | |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 2183 | if (push_size > 256) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2184 | push_size = 0; |
| 2185 | bp->tx_push_thresh = 0; |
| 2186 | } |
| 2187 | |
| 2188 | bp->tx_push_size = push_size; |
| 2189 | } |
| 2190 | |
| 2191 | for (i = 0, j = 0; i < bp->tx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2192 | struct bnxt_tx_ring_info *txr = &bp->tx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2193 | struct bnxt_ring_struct *ring; |
| 2194 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2195 | ring = &txr->tx_ring_struct; |
| 2196 | |
| 2197 | rc = bnxt_alloc_ring(bp, ring); |
| 2198 | if (rc) |
| 2199 | return rc; |
| 2200 | |
| 2201 | if (bp->tx_push_size) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2202 | dma_addr_t mapping; |
| 2203 | |
| 2204 | /* One pre-allocated DMA buffer to backup |
| 2205 | * TX push operation |
| 2206 | */ |
| 2207 | txr->tx_push = dma_alloc_coherent(&pdev->dev, |
| 2208 | bp->tx_push_size, |
| 2209 | &txr->tx_push_mapping, |
| 2210 | GFP_KERNEL); |
| 2211 | |
| 2212 | if (!txr->tx_push) |
| 2213 | return -ENOMEM; |
| 2214 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2215 | mapping = txr->tx_push_mapping + |
| 2216 | sizeof(struct tx_push_bd); |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 2217 | txr->data_mapping = cpu_to_le64(mapping); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2218 | |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 2219 | memset(txr->tx_push, 0, sizeof(struct tx_push_bd)); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2220 | } |
| 2221 | ring->queue_id = bp->q_info[j].queue_id; |
| 2222 | if (i % bp->tx_nr_rings_per_tc == (bp->tx_nr_rings_per_tc - 1)) |
| 2223 | j++; |
| 2224 | } |
| 2225 | return 0; |
| 2226 | } |
| 2227 | |
| 2228 | static void bnxt_free_cp_rings(struct bnxt *bp) |
| 2229 | { |
| 2230 | int i; |
| 2231 | |
| 2232 | if (!bp->bnapi) |
| 2233 | return; |
| 2234 | |
| 2235 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 2236 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 2237 | struct bnxt_cp_ring_info *cpr; |
| 2238 | struct bnxt_ring_struct *ring; |
| 2239 | |
| 2240 | if (!bnapi) |
| 2241 | continue; |
| 2242 | |
| 2243 | cpr = &bnapi->cp_ring; |
| 2244 | ring = &cpr->cp_ring_struct; |
| 2245 | |
| 2246 | bnxt_free_ring(bp, ring); |
| 2247 | } |
| 2248 | } |
| 2249 | |
| 2250 | static int bnxt_alloc_cp_rings(struct bnxt *bp) |
| 2251 | { |
| 2252 | int i, rc; |
| 2253 | |
| 2254 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 2255 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 2256 | struct bnxt_cp_ring_info *cpr; |
| 2257 | struct bnxt_ring_struct *ring; |
| 2258 | |
| 2259 | if (!bnapi) |
| 2260 | continue; |
| 2261 | |
| 2262 | cpr = &bnapi->cp_ring; |
| 2263 | ring = &cpr->cp_ring_struct; |
| 2264 | |
| 2265 | rc = bnxt_alloc_ring(bp, ring); |
| 2266 | if (rc) |
| 2267 | return rc; |
| 2268 | } |
| 2269 | return 0; |
| 2270 | } |
| 2271 | |
| 2272 | static void bnxt_init_ring_struct(struct bnxt *bp) |
| 2273 | { |
| 2274 | int i; |
| 2275 | |
| 2276 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 2277 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 2278 | struct bnxt_cp_ring_info *cpr; |
| 2279 | struct bnxt_rx_ring_info *rxr; |
| 2280 | struct bnxt_tx_ring_info *txr; |
| 2281 | struct bnxt_ring_struct *ring; |
| 2282 | |
| 2283 | if (!bnapi) |
| 2284 | continue; |
| 2285 | |
| 2286 | cpr = &bnapi->cp_ring; |
| 2287 | ring = &cpr->cp_ring_struct; |
| 2288 | ring->nr_pages = bp->cp_nr_pages; |
| 2289 | ring->page_size = HW_CMPD_RING_SIZE; |
| 2290 | ring->pg_arr = (void **)cpr->cp_desc_ring; |
| 2291 | ring->dma_arr = cpr->cp_desc_mapping; |
| 2292 | ring->vmem_size = 0; |
| 2293 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2294 | rxr = bnapi->rx_ring; |
Michael Chan | 3b2b7d9 | 2016-01-02 23:45:00 -0500 | [diff] [blame] | 2295 | if (!rxr) |
| 2296 | goto skip_rx; |
| 2297 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2298 | ring = &rxr->rx_ring_struct; |
| 2299 | ring->nr_pages = bp->rx_nr_pages; |
| 2300 | ring->page_size = HW_RXBD_RING_SIZE; |
| 2301 | ring->pg_arr = (void **)rxr->rx_desc_ring; |
| 2302 | ring->dma_arr = rxr->rx_desc_mapping; |
| 2303 | ring->vmem_size = SW_RXBD_RING_SIZE * bp->rx_nr_pages; |
| 2304 | ring->vmem = (void **)&rxr->rx_buf_ring; |
| 2305 | |
| 2306 | ring = &rxr->rx_agg_ring_struct; |
| 2307 | ring->nr_pages = bp->rx_agg_nr_pages; |
| 2308 | ring->page_size = HW_RXBD_RING_SIZE; |
| 2309 | ring->pg_arr = (void **)rxr->rx_agg_desc_ring; |
| 2310 | ring->dma_arr = rxr->rx_agg_desc_mapping; |
| 2311 | ring->vmem_size = SW_RXBD_AGG_RING_SIZE * bp->rx_agg_nr_pages; |
| 2312 | ring->vmem = (void **)&rxr->rx_agg_ring; |
| 2313 | |
Michael Chan | 3b2b7d9 | 2016-01-02 23:45:00 -0500 | [diff] [blame] | 2314 | skip_rx: |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2315 | txr = bnapi->tx_ring; |
Michael Chan | 3b2b7d9 | 2016-01-02 23:45:00 -0500 | [diff] [blame] | 2316 | if (!txr) |
| 2317 | continue; |
| 2318 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2319 | ring = &txr->tx_ring_struct; |
| 2320 | ring->nr_pages = bp->tx_nr_pages; |
| 2321 | ring->page_size = HW_RXBD_RING_SIZE; |
| 2322 | ring->pg_arr = (void **)txr->tx_desc_ring; |
| 2323 | ring->dma_arr = txr->tx_desc_mapping; |
| 2324 | ring->vmem_size = SW_TXBD_RING_SIZE * bp->tx_nr_pages; |
| 2325 | ring->vmem = (void **)&txr->tx_buf_ring; |
| 2326 | } |
| 2327 | } |
| 2328 | |
| 2329 | static void bnxt_init_rxbd_pages(struct bnxt_ring_struct *ring, u32 type) |
| 2330 | { |
| 2331 | int i; |
| 2332 | u32 prod; |
| 2333 | struct rx_bd **rx_buf_ring; |
| 2334 | |
| 2335 | rx_buf_ring = (struct rx_bd **)ring->pg_arr; |
| 2336 | for (i = 0, prod = 0; i < ring->nr_pages; i++) { |
| 2337 | int j; |
| 2338 | struct rx_bd *rxbd; |
| 2339 | |
| 2340 | rxbd = rx_buf_ring[i]; |
| 2341 | if (!rxbd) |
| 2342 | continue; |
| 2343 | |
| 2344 | for (j = 0; j < RX_DESC_CNT; j++, rxbd++, prod++) { |
| 2345 | rxbd->rx_bd_len_flags_type = cpu_to_le32(type); |
| 2346 | rxbd->rx_bd_opaque = prod; |
| 2347 | } |
| 2348 | } |
| 2349 | } |
| 2350 | |
| 2351 | static int bnxt_init_one_rx_ring(struct bnxt *bp, int ring_nr) |
| 2352 | { |
| 2353 | struct net_device *dev = bp->dev; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2354 | struct bnxt_rx_ring_info *rxr; |
| 2355 | struct bnxt_ring_struct *ring; |
| 2356 | u32 prod, type; |
| 2357 | int i; |
| 2358 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2359 | type = (bp->rx_buf_use_size << RX_BD_LEN_SHIFT) | |
| 2360 | RX_BD_TYPE_RX_PACKET_BD | RX_BD_FLAGS_EOP; |
| 2361 | |
| 2362 | if (NET_IP_ALIGN == 2) |
| 2363 | type |= RX_BD_FLAGS_SOP; |
| 2364 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2365 | rxr = &bp->rx_ring[ring_nr]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2366 | ring = &rxr->rx_ring_struct; |
| 2367 | bnxt_init_rxbd_pages(ring, type); |
| 2368 | |
| 2369 | prod = rxr->rx_prod; |
| 2370 | for (i = 0; i < bp->rx_ring_size; i++) { |
| 2371 | if (bnxt_alloc_rx_data(bp, rxr, prod, GFP_KERNEL) != 0) { |
| 2372 | netdev_warn(dev, "init'ed rx ring %d with %d/%d skbs only\n", |
| 2373 | ring_nr, i, bp->rx_ring_size); |
| 2374 | break; |
| 2375 | } |
| 2376 | prod = NEXT_RX(prod); |
| 2377 | } |
| 2378 | rxr->rx_prod = prod; |
| 2379 | ring->fw_ring_id = INVALID_HW_RING_ID; |
| 2380 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 2381 | ring = &rxr->rx_agg_ring_struct; |
| 2382 | ring->fw_ring_id = INVALID_HW_RING_ID; |
| 2383 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2384 | if (!(bp->flags & BNXT_FLAG_AGG_RINGS)) |
| 2385 | return 0; |
| 2386 | |
Michael Chan | 2839f28 | 2016-04-25 02:30:50 -0400 | [diff] [blame] | 2387 | type = ((u32)BNXT_RX_PAGE_SIZE << RX_BD_LEN_SHIFT) | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2388 | RX_BD_TYPE_RX_AGG_BD | RX_BD_FLAGS_SOP; |
| 2389 | |
| 2390 | bnxt_init_rxbd_pages(ring, type); |
| 2391 | |
| 2392 | prod = rxr->rx_agg_prod; |
| 2393 | for (i = 0; i < bp->rx_agg_ring_size; i++) { |
| 2394 | if (bnxt_alloc_rx_page(bp, rxr, prod, GFP_KERNEL) != 0) { |
| 2395 | netdev_warn(dev, "init'ed rx ring %d with %d/%d pages only\n", |
| 2396 | ring_nr, i, bp->rx_ring_size); |
| 2397 | break; |
| 2398 | } |
| 2399 | prod = NEXT_RX_AGG(prod); |
| 2400 | } |
| 2401 | rxr->rx_agg_prod = prod; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2402 | |
| 2403 | if (bp->flags & BNXT_FLAG_TPA) { |
| 2404 | if (rxr->rx_tpa) { |
| 2405 | u8 *data; |
| 2406 | dma_addr_t mapping; |
| 2407 | |
| 2408 | for (i = 0; i < MAX_TPA; i++) { |
| 2409 | data = __bnxt_alloc_rx_data(bp, &mapping, |
| 2410 | GFP_KERNEL); |
| 2411 | if (!data) |
| 2412 | return -ENOMEM; |
| 2413 | |
| 2414 | rxr->rx_tpa[i].data = data; |
Michael Chan | b3dba77 | 2017-02-06 16:55:35 -0500 | [diff] [blame] | 2415 | rxr->rx_tpa[i].data_ptr = data + bp->rx_offset; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2416 | rxr->rx_tpa[i].mapping = mapping; |
| 2417 | } |
| 2418 | } else { |
| 2419 | netdev_err(bp->dev, "No resource allocated for LRO/GRO\n"); |
| 2420 | return -ENOMEM; |
| 2421 | } |
| 2422 | } |
| 2423 | |
| 2424 | return 0; |
| 2425 | } |
| 2426 | |
| 2427 | static int bnxt_init_rx_rings(struct bnxt *bp) |
| 2428 | { |
| 2429 | int i, rc = 0; |
| 2430 | |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 2431 | if (BNXT_RX_PAGE_MODE(bp)) { |
| 2432 | bp->rx_offset = NET_IP_ALIGN; |
| 2433 | bp->rx_dma_offset = 0; |
| 2434 | } else { |
| 2435 | bp->rx_offset = BNXT_RX_OFFSET; |
| 2436 | bp->rx_dma_offset = BNXT_RX_DMA_OFFSET; |
| 2437 | } |
Michael Chan | b3dba77 | 2017-02-06 16:55:35 -0500 | [diff] [blame] | 2438 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2439 | for (i = 0; i < bp->rx_nr_rings; i++) { |
| 2440 | rc = bnxt_init_one_rx_ring(bp, i); |
| 2441 | if (rc) |
| 2442 | break; |
| 2443 | } |
| 2444 | |
| 2445 | return rc; |
| 2446 | } |
| 2447 | |
| 2448 | static int bnxt_init_tx_rings(struct bnxt *bp) |
| 2449 | { |
| 2450 | u16 i; |
| 2451 | |
| 2452 | bp->tx_wake_thresh = max_t(int, bp->tx_ring_size / 2, |
| 2453 | MAX_SKB_FRAGS + 1); |
| 2454 | |
| 2455 | for (i = 0; i < bp->tx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2456 | struct bnxt_tx_ring_info *txr = &bp->tx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2457 | struct bnxt_ring_struct *ring = &txr->tx_ring_struct; |
| 2458 | |
| 2459 | ring->fw_ring_id = INVALID_HW_RING_ID; |
| 2460 | } |
| 2461 | |
| 2462 | return 0; |
| 2463 | } |
| 2464 | |
| 2465 | static void bnxt_free_ring_grps(struct bnxt *bp) |
| 2466 | { |
| 2467 | kfree(bp->grp_info); |
| 2468 | bp->grp_info = NULL; |
| 2469 | } |
| 2470 | |
| 2471 | static int bnxt_init_ring_grps(struct bnxt *bp, bool irq_re_init) |
| 2472 | { |
| 2473 | int i; |
| 2474 | |
| 2475 | if (irq_re_init) { |
| 2476 | bp->grp_info = kcalloc(bp->cp_nr_rings, |
| 2477 | sizeof(struct bnxt_ring_grp_info), |
| 2478 | GFP_KERNEL); |
| 2479 | if (!bp->grp_info) |
| 2480 | return -ENOMEM; |
| 2481 | } |
| 2482 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 2483 | if (irq_re_init) |
| 2484 | bp->grp_info[i].fw_stats_ctx = INVALID_HW_RING_ID; |
| 2485 | bp->grp_info[i].fw_grp_id = INVALID_HW_RING_ID; |
| 2486 | bp->grp_info[i].rx_fw_ring_id = INVALID_HW_RING_ID; |
| 2487 | bp->grp_info[i].agg_fw_ring_id = INVALID_HW_RING_ID; |
| 2488 | bp->grp_info[i].cp_fw_ring_id = INVALID_HW_RING_ID; |
| 2489 | } |
| 2490 | return 0; |
| 2491 | } |
| 2492 | |
| 2493 | static void bnxt_free_vnics(struct bnxt *bp) |
| 2494 | { |
| 2495 | kfree(bp->vnic_info); |
| 2496 | bp->vnic_info = NULL; |
| 2497 | bp->nr_vnics = 0; |
| 2498 | } |
| 2499 | |
| 2500 | static int bnxt_alloc_vnics(struct bnxt *bp) |
| 2501 | { |
| 2502 | int num_vnics = 1; |
| 2503 | |
| 2504 | #ifdef CONFIG_RFS_ACCEL |
| 2505 | if (bp->flags & BNXT_FLAG_RFS) |
| 2506 | num_vnics += bp->rx_nr_rings; |
| 2507 | #endif |
| 2508 | |
Prashant Sreedharan | dc52c6c | 2016-07-18 07:15:24 -0400 | [diff] [blame] | 2509 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 2510 | num_vnics++; |
| 2511 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2512 | bp->vnic_info = kcalloc(num_vnics, sizeof(struct bnxt_vnic_info), |
| 2513 | GFP_KERNEL); |
| 2514 | if (!bp->vnic_info) |
| 2515 | return -ENOMEM; |
| 2516 | |
| 2517 | bp->nr_vnics = num_vnics; |
| 2518 | return 0; |
| 2519 | } |
| 2520 | |
| 2521 | static void bnxt_init_vnics(struct bnxt *bp) |
| 2522 | { |
| 2523 | int i; |
| 2524 | |
| 2525 | for (i = 0; i < bp->nr_vnics; i++) { |
| 2526 | struct bnxt_vnic_info *vnic = &bp->vnic_info[i]; |
| 2527 | |
| 2528 | vnic->fw_vnic_id = INVALID_HW_RING_ID; |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 2529 | vnic->fw_rss_cos_lb_ctx[0] = INVALID_HW_RING_ID; |
| 2530 | vnic->fw_rss_cos_lb_ctx[1] = INVALID_HW_RING_ID; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2531 | vnic->fw_l2_ctx_id = INVALID_HW_RING_ID; |
| 2532 | |
| 2533 | if (bp->vnic_info[i].rss_hash_key) { |
| 2534 | if (i == 0) |
| 2535 | prandom_bytes(vnic->rss_hash_key, |
| 2536 | HW_HASH_KEY_SIZE); |
| 2537 | else |
| 2538 | memcpy(vnic->rss_hash_key, |
| 2539 | bp->vnic_info[0].rss_hash_key, |
| 2540 | HW_HASH_KEY_SIZE); |
| 2541 | } |
| 2542 | } |
| 2543 | } |
| 2544 | |
| 2545 | static int bnxt_calc_nr_ring_pages(u32 ring_size, int desc_per_pg) |
| 2546 | { |
| 2547 | int pages; |
| 2548 | |
| 2549 | pages = ring_size / desc_per_pg; |
| 2550 | |
| 2551 | if (!pages) |
| 2552 | return 1; |
| 2553 | |
| 2554 | pages++; |
| 2555 | |
| 2556 | while (pages & (pages - 1)) |
| 2557 | pages++; |
| 2558 | |
| 2559 | return pages; |
| 2560 | } |
| 2561 | |
| 2562 | static void bnxt_set_tpa_flags(struct bnxt *bp) |
| 2563 | { |
| 2564 | bp->flags &= ~BNXT_FLAG_TPA; |
Michael Chan | 341138c | 2017-01-13 01:32:01 -0500 | [diff] [blame] | 2565 | if (bp->flags & BNXT_FLAG_NO_AGG_RINGS) |
| 2566 | return; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2567 | if (bp->dev->features & NETIF_F_LRO) |
| 2568 | bp->flags |= BNXT_FLAG_LRO; |
Michael Chan | 94758f8 | 2016-06-13 02:25:35 -0400 | [diff] [blame] | 2569 | if (bp->dev->features & NETIF_F_GRO) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2570 | bp->flags |= BNXT_FLAG_GRO; |
| 2571 | } |
| 2572 | |
| 2573 | /* bp->rx_ring_size, bp->tx_ring_size, dev->mtu, BNXT_FLAG_{G|L}RO flags must |
| 2574 | * be set on entry. |
| 2575 | */ |
| 2576 | void bnxt_set_ring_params(struct bnxt *bp) |
| 2577 | { |
| 2578 | u32 ring_size, rx_size, rx_space; |
| 2579 | u32 agg_factor = 0, agg_ring_size = 0; |
| 2580 | |
| 2581 | /* 8 for CRC and VLAN */ |
| 2582 | rx_size = SKB_DATA_ALIGN(bp->dev->mtu + ETH_HLEN + NET_IP_ALIGN + 8); |
| 2583 | |
| 2584 | rx_space = rx_size + NET_SKB_PAD + |
| 2585 | SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); |
| 2586 | |
| 2587 | bp->rx_copy_thresh = BNXT_RX_COPY_THRESH; |
| 2588 | ring_size = bp->rx_ring_size; |
| 2589 | bp->rx_agg_ring_size = 0; |
| 2590 | bp->rx_agg_nr_pages = 0; |
| 2591 | |
| 2592 | if (bp->flags & BNXT_FLAG_TPA) |
Michael Chan | 2839f28 | 2016-04-25 02:30:50 -0400 | [diff] [blame] | 2593 | agg_factor = min_t(u32, 4, 65536 / BNXT_RX_PAGE_SIZE); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2594 | |
| 2595 | bp->flags &= ~BNXT_FLAG_JUMBO; |
Michael Chan | bdbd1eb | 2016-12-29 12:13:43 -0500 | [diff] [blame] | 2596 | if (rx_space > PAGE_SIZE && !(bp->flags & BNXT_FLAG_NO_AGG_RINGS)) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2597 | u32 jumbo_factor; |
| 2598 | |
| 2599 | bp->flags |= BNXT_FLAG_JUMBO; |
| 2600 | jumbo_factor = PAGE_ALIGN(bp->dev->mtu - 40) >> PAGE_SHIFT; |
| 2601 | if (jumbo_factor > agg_factor) |
| 2602 | agg_factor = jumbo_factor; |
| 2603 | } |
| 2604 | agg_ring_size = ring_size * agg_factor; |
| 2605 | |
| 2606 | if (agg_ring_size) { |
| 2607 | bp->rx_agg_nr_pages = bnxt_calc_nr_ring_pages(agg_ring_size, |
| 2608 | RX_DESC_CNT); |
| 2609 | if (bp->rx_agg_nr_pages > MAX_RX_AGG_PAGES) { |
| 2610 | u32 tmp = agg_ring_size; |
| 2611 | |
| 2612 | bp->rx_agg_nr_pages = MAX_RX_AGG_PAGES; |
| 2613 | agg_ring_size = MAX_RX_AGG_PAGES * RX_DESC_CNT - 1; |
| 2614 | netdev_warn(bp->dev, "rx agg ring size %d reduced to %d.\n", |
| 2615 | tmp, agg_ring_size); |
| 2616 | } |
| 2617 | bp->rx_agg_ring_size = agg_ring_size; |
| 2618 | bp->rx_agg_ring_mask = (bp->rx_agg_nr_pages * RX_DESC_CNT) - 1; |
| 2619 | rx_size = SKB_DATA_ALIGN(BNXT_RX_COPY_THRESH + NET_IP_ALIGN); |
| 2620 | rx_space = rx_size + NET_SKB_PAD + |
| 2621 | SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); |
| 2622 | } |
| 2623 | |
| 2624 | bp->rx_buf_use_size = rx_size; |
| 2625 | bp->rx_buf_size = rx_space; |
| 2626 | |
| 2627 | bp->rx_nr_pages = bnxt_calc_nr_ring_pages(ring_size, RX_DESC_CNT); |
| 2628 | bp->rx_ring_mask = (bp->rx_nr_pages * RX_DESC_CNT) - 1; |
| 2629 | |
| 2630 | ring_size = bp->tx_ring_size; |
| 2631 | bp->tx_nr_pages = bnxt_calc_nr_ring_pages(ring_size, TX_DESC_CNT); |
| 2632 | bp->tx_ring_mask = (bp->tx_nr_pages * TX_DESC_CNT) - 1; |
| 2633 | |
| 2634 | ring_size = bp->rx_ring_size * (2 + agg_factor) + bp->tx_ring_size; |
| 2635 | bp->cp_ring_size = ring_size; |
| 2636 | |
| 2637 | bp->cp_nr_pages = bnxt_calc_nr_ring_pages(ring_size, CP_DESC_CNT); |
| 2638 | if (bp->cp_nr_pages > MAX_CP_PAGES) { |
| 2639 | bp->cp_nr_pages = MAX_CP_PAGES; |
| 2640 | bp->cp_ring_size = MAX_CP_PAGES * CP_DESC_CNT - 1; |
| 2641 | netdev_warn(bp->dev, "completion ring size %d reduced to %d.\n", |
| 2642 | ring_size, bp->cp_ring_size); |
| 2643 | } |
| 2644 | bp->cp_bit = bp->cp_nr_pages * CP_DESC_CNT; |
| 2645 | bp->cp_ring_mask = bp->cp_bit - 1; |
| 2646 | } |
| 2647 | |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 2648 | int bnxt_set_rx_skb_mode(struct bnxt *bp, bool page_mode) |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 2649 | { |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 2650 | if (page_mode) { |
| 2651 | if (bp->dev->mtu > BNXT_MAX_PAGE_MODE_MTU) |
| 2652 | return -EOPNOTSUPP; |
| 2653 | bp->dev->max_mtu = BNXT_MAX_PAGE_MODE_MTU; |
| 2654 | bp->flags &= ~BNXT_FLAG_AGG_RINGS; |
| 2655 | bp->flags |= BNXT_FLAG_NO_AGG_RINGS | BNXT_FLAG_RX_PAGE_MODE; |
| 2656 | bp->dev->hw_features &= ~NETIF_F_LRO; |
| 2657 | bp->dev->features &= ~NETIF_F_LRO; |
| 2658 | bp->rx_dir = DMA_BIDIRECTIONAL; |
| 2659 | bp->rx_skb_func = bnxt_rx_page_skb; |
| 2660 | } else { |
| 2661 | bp->dev->max_mtu = BNXT_MAX_MTU; |
| 2662 | bp->flags &= ~BNXT_FLAG_RX_PAGE_MODE; |
| 2663 | bp->rx_dir = DMA_FROM_DEVICE; |
| 2664 | bp->rx_skb_func = bnxt_rx_skb; |
| 2665 | } |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 2666 | return 0; |
| 2667 | } |
| 2668 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2669 | static void bnxt_free_vnic_attributes(struct bnxt *bp) |
| 2670 | { |
| 2671 | int i; |
| 2672 | struct bnxt_vnic_info *vnic; |
| 2673 | struct pci_dev *pdev = bp->pdev; |
| 2674 | |
| 2675 | if (!bp->vnic_info) |
| 2676 | return; |
| 2677 | |
| 2678 | for (i = 0; i < bp->nr_vnics; i++) { |
| 2679 | vnic = &bp->vnic_info[i]; |
| 2680 | |
| 2681 | kfree(vnic->fw_grp_ids); |
| 2682 | vnic->fw_grp_ids = NULL; |
| 2683 | |
| 2684 | kfree(vnic->uc_list); |
| 2685 | vnic->uc_list = NULL; |
| 2686 | |
| 2687 | if (vnic->mc_list) { |
| 2688 | dma_free_coherent(&pdev->dev, vnic->mc_list_size, |
| 2689 | vnic->mc_list, vnic->mc_list_mapping); |
| 2690 | vnic->mc_list = NULL; |
| 2691 | } |
| 2692 | |
| 2693 | if (vnic->rss_table) { |
| 2694 | dma_free_coherent(&pdev->dev, PAGE_SIZE, |
| 2695 | vnic->rss_table, |
| 2696 | vnic->rss_table_dma_addr); |
| 2697 | vnic->rss_table = NULL; |
| 2698 | } |
| 2699 | |
| 2700 | vnic->rss_hash_key = NULL; |
| 2701 | vnic->flags = 0; |
| 2702 | } |
| 2703 | } |
| 2704 | |
| 2705 | static int bnxt_alloc_vnic_attributes(struct bnxt *bp) |
| 2706 | { |
| 2707 | int i, rc = 0, size; |
| 2708 | struct bnxt_vnic_info *vnic; |
| 2709 | struct pci_dev *pdev = bp->pdev; |
| 2710 | int max_rings; |
| 2711 | |
| 2712 | for (i = 0; i < bp->nr_vnics; i++) { |
| 2713 | vnic = &bp->vnic_info[i]; |
| 2714 | |
| 2715 | if (vnic->flags & BNXT_VNIC_UCAST_FLAG) { |
| 2716 | int mem_size = (BNXT_MAX_UC_ADDRS - 1) * ETH_ALEN; |
| 2717 | |
| 2718 | if (mem_size > 0) { |
| 2719 | vnic->uc_list = kmalloc(mem_size, GFP_KERNEL); |
| 2720 | if (!vnic->uc_list) { |
| 2721 | rc = -ENOMEM; |
| 2722 | goto out; |
| 2723 | } |
| 2724 | } |
| 2725 | } |
| 2726 | |
| 2727 | if (vnic->flags & BNXT_VNIC_MCAST_FLAG) { |
| 2728 | vnic->mc_list_size = BNXT_MAX_MC_ADDRS * ETH_ALEN; |
| 2729 | vnic->mc_list = |
| 2730 | dma_alloc_coherent(&pdev->dev, |
| 2731 | vnic->mc_list_size, |
| 2732 | &vnic->mc_list_mapping, |
| 2733 | GFP_KERNEL); |
| 2734 | if (!vnic->mc_list) { |
| 2735 | rc = -ENOMEM; |
| 2736 | goto out; |
| 2737 | } |
| 2738 | } |
| 2739 | |
| 2740 | if (vnic->flags & BNXT_VNIC_RSS_FLAG) |
| 2741 | max_rings = bp->rx_nr_rings; |
| 2742 | else |
| 2743 | max_rings = 1; |
| 2744 | |
| 2745 | vnic->fw_grp_ids = kcalloc(max_rings, sizeof(u16), GFP_KERNEL); |
| 2746 | if (!vnic->fw_grp_ids) { |
| 2747 | rc = -ENOMEM; |
| 2748 | goto out; |
| 2749 | } |
| 2750 | |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 2751 | if ((bp->flags & BNXT_FLAG_NEW_RSS_CAP) && |
| 2752 | !(vnic->flags & BNXT_VNIC_RSS_FLAG)) |
| 2753 | continue; |
| 2754 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2755 | /* Allocate rss table and hash key */ |
| 2756 | vnic->rss_table = dma_alloc_coherent(&pdev->dev, PAGE_SIZE, |
| 2757 | &vnic->rss_table_dma_addr, |
| 2758 | GFP_KERNEL); |
| 2759 | if (!vnic->rss_table) { |
| 2760 | rc = -ENOMEM; |
| 2761 | goto out; |
| 2762 | } |
| 2763 | |
| 2764 | size = L1_CACHE_ALIGN(HW_HASH_INDEX_SIZE * sizeof(u16)); |
| 2765 | |
| 2766 | vnic->rss_hash_key = ((void *)vnic->rss_table) + size; |
| 2767 | vnic->rss_hash_key_dma_addr = vnic->rss_table_dma_addr + size; |
| 2768 | } |
| 2769 | return 0; |
| 2770 | |
| 2771 | out: |
| 2772 | return rc; |
| 2773 | } |
| 2774 | |
| 2775 | static void bnxt_free_hwrm_resources(struct bnxt *bp) |
| 2776 | { |
| 2777 | struct pci_dev *pdev = bp->pdev; |
| 2778 | |
| 2779 | dma_free_coherent(&pdev->dev, PAGE_SIZE, bp->hwrm_cmd_resp_addr, |
| 2780 | bp->hwrm_cmd_resp_dma_addr); |
| 2781 | |
| 2782 | bp->hwrm_cmd_resp_addr = NULL; |
| 2783 | if (bp->hwrm_dbg_resp_addr) { |
| 2784 | dma_free_coherent(&pdev->dev, HWRM_DBG_REG_BUF_SIZE, |
| 2785 | bp->hwrm_dbg_resp_addr, |
| 2786 | bp->hwrm_dbg_resp_dma_addr); |
| 2787 | |
| 2788 | bp->hwrm_dbg_resp_addr = NULL; |
| 2789 | } |
| 2790 | } |
| 2791 | |
| 2792 | static int bnxt_alloc_hwrm_resources(struct bnxt *bp) |
| 2793 | { |
| 2794 | struct pci_dev *pdev = bp->pdev; |
| 2795 | |
| 2796 | bp->hwrm_cmd_resp_addr = dma_alloc_coherent(&pdev->dev, PAGE_SIZE, |
| 2797 | &bp->hwrm_cmd_resp_dma_addr, |
| 2798 | GFP_KERNEL); |
| 2799 | if (!bp->hwrm_cmd_resp_addr) |
| 2800 | return -ENOMEM; |
| 2801 | bp->hwrm_dbg_resp_addr = dma_alloc_coherent(&pdev->dev, |
| 2802 | HWRM_DBG_REG_BUF_SIZE, |
| 2803 | &bp->hwrm_dbg_resp_dma_addr, |
| 2804 | GFP_KERNEL); |
| 2805 | if (!bp->hwrm_dbg_resp_addr) |
| 2806 | netdev_warn(bp->dev, "fail to alloc debug register dma mem\n"); |
| 2807 | |
| 2808 | return 0; |
| 2809 | } |
| 2810 | |
| 2811 | static void bnxt_free_stats(struct bnxt *bp) |
| 2812 | { |
| 2813 | u32 size, i; |
| 2814 | struct pci_dev *pdev = bp->pdev; |
| 2815 | |
Michael Chan | 3bdf56c | 2016-03-07 15:38:45 -0500 | [diff] [blame] | 2816 | if (bp->hw_rx_port_stats) { |
| 2817 | dma_free_coherent(&pdev->dev, bp->hw_port_stats_size, |
| 2818 | bp->hw_rx_port_stats, |
| 2819 | bp->hw_rx_port_stats_map); |
| 2820 | bp->hw_rx_port_stats = NULL; |
| 2821 | bp->flags &= ~BNXT_FLAG_PORT_STATS; |
| 2822 | } |
| 2823 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2824 | if (!bp->bnapi) |
| 2825 | return; |
| 2826 | |
| 2827 | size = sizeof(struct ctx_hw_stats); |
| 2828 | |
| 2829 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 2830 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 2831 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 2832 | |
| 2833 | if (cpr->hw_stats) { |
| 2834 | dma_free_coherent(&pdev->dev, size, cpr->hw_stats, |
| 2835 | cpr->hw_stats_map); |
| 2836 | cpr->hw_stats = NULL; |
| 2837 | } |
| 2838 | } |
| 2839 | } |
| 2840 | |
| 2841 | static int bnxt_alloc_stats(struct bnxt *bp) |
| 2842 | { |
| 2843 | u32 size, i; |
| 2844 | struct pci_dev *pdev = bp->pdev; |
| 2845 | |
| 2846 | size = sizeof(struct ctx_hw_stats); |
| 2847 | |
| 2848 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 2849 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 2850 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 2851 | |
| 2852 | cpr->hw_stats = dma_alloc_coherent(&pdev->dev, size, |
| 2853 | &cpr->hw_stats_map, |
| 2854 | GFP_KERNEL); |
| 2855 | if (!cpr->hw_stats) |
| 2856 | return -ENOMEM; |
| 2857 | |
| 2858 | cpr->hw_stats_ctx_id = INVALID_STATS_CTX_ID; |
| 2859 | } |
Michael Chan | 3bdf56c | 2016-03-07 15:38:45 -0500 | [diff] [blame] | 2860 | |
Prashant Sreedharan | 3e8060f | 2016-07-18 07:15:20 -0400 | [diff] [blame] | 2861 | if (BNXT_PF(bp) && bp->chip_num != CHIP_NUM_58700) { |
Michael Chan | 3bdf56c | 2016-03-07 15:38:45 -0500 | [diff] [blame] | 2862 | bp->hw_port_stats_size = sizeof(struct rx_port_stats) + |
| 2863 | sizeof(struct tx_port_stats) + 1024; |
| 2864 | |
| 2865 | bp->hw_rx_port_stats = |
| 2866 | dma_alloc_coherent(&pdev->dev, bp->hw_port_stats_size, |
| 2867 | &bp->hw_rx_port_stats_map, |
| 2868 | GFP_KERNEL); |
| 2869 | if (!bp->hw_rx_port_stats) |
| 2870 | return -ENOMEM; |
| 2871 | |
| 2872 | bp->hw_tx_port_stats = (void *)(bp->hw_rx_port_stats + 1) + |
| 2873 | 512; |
| 2874 | bp->hw_tx_port_stats_map = bp->hw_rx_port_stats_map + |
| 2875 | sizeof(struct rx_port_stats) + 512; |
| 2876 | bp->flags |= BNXT_FLAG_PORT_STATS; |
| 2877 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2878 | return 0; |
| 2879 | } |
| 2880 | |
| 2881 | static void bnxt_clear_ring_indices(struct bnxt *bp) |
| 2882 | { |
| 2883 | int i; |
| 2884 | |
| 2885 | if (!bp->bnapi) |
| 2886 | return; |
| 2887 | |
| 2888 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 2889 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 2890 | struct bnxt_cp_ring_info *cpr; |
| 2891 | struct bnxt_rx_ring_info *rxr; |
| 2892 | struct bnxt_tx_ring_info *txr; |
| 2893 | |
| 2894 | if (!bnapi) |
| 2895 | continue; |
| 2896 | |
| 2897 | cpr = &bnapi->cp_ring; |
| 2898 | cpr->cp_raw_cons = 0; |
| 2899 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2900 | txr = bnapi->tx_ring; |
Michael Chan | 3b2b7d9 | 2016-01-02 23:45:00 -0500 | [diff] [blame] | 2901 | if (txr) { |
| 2902 | txr->tx_prod = 0; |
| 2903 | txr->tx_cons = 0; |
| 2904 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2905 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2906 | rxr = bnapi->rx_ring; |
Michael Chan | 3b2b7d9 | 2016-01-02 23:45:00 -0500 | [diff] [blame] | 2907 | if (rxr) { |
| 2908 | rxr->rx_prod = 0; |
| 2909 | rxr->rx_agg_prod = 0; |
| 2910 | rxr->rx_sw_agg_prod = 0; |
Michael Chan | 376a5b8 | 2016-05-10 19:17:59 -0400 | [diff] [blame] | 2911 | rxr->rx_next_cons = 0; |
Michael Chan | 3b2b7d9 | 2016-01-02 23:45:00 -0500 | [diff] [blame] | 2912 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2913 | } |
| 2914 | } |
| 2915 | |
| 2916 | static void bnxt_free_ntp_fltrs(struct bnxt *bp, bool irq_reinit) |
| 2917 | { |
| 2918 | #ifdef CONFIG_RFS_ACCEL |
| 2919 | int i; |
| 2920 | |
| 2921 | /* Under rtnl_lock and all our NAPIs have been disabled. It's |
| 2922 | * safe to delete the hash table. |
| 2923 | */ |
| 2924 | for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) { |
| 2925 | struct hlist_head *head; |
| 2926 | struct hlist_node *tmp; |
| 2927 | struct bnxt_ntuple_filter *fltr; |
| 2928 | |
| 2929 | head = &bp->ntp_fltr_hash_tbl[i]; |
| 2930 | hlist_for_each_entry_safe(fltr, tmp, head, hash) { |
| 2931 | hlist_del(&fltr->hash); |
| 2932 | kfree(fltr); |
| 2933 | } |
| 2934 | } |
| 2935 | if (irq_reinit) { |
| 2936 | kfree(bp->ntp_fltr_bmap); |
| 2937 | bp->ntp_fltr_bmap = NULL; |
| 2938 | } |
| 2939 | bp->ntp_fltr_count = 0; |
| 2940 | #endif |
| 2941 | } |
| 2942 | |
| 2943 | static int bnxt_alloc_ntp_fltrs(struct bnxt *bp) |
| 2944 | { |
| 2945 | #ifdef CONFIG_RFS_ACCEL |
| 2946 | int i, rc = 0; |
| 2947 | |
| 2948 | if (!(bp->flags & BNXT_FLAG_RFS)) |
| 2949 | return 0; |
| 2950 | |
| 2951 | for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) |
| 2952 | INIT_HLIST_HEAD(&bp->ntp_fltr_hash_tbl[i]); |
| 2953 | |
| 2954 | bp->ntp_fltr_count = 0; |
| 2955 | bp->ntp_fltr_bmap = kzalloc(BITS_TO_LONGS(BNXT_NTP_FLTR_MAX_FLTR), |
| 2956 | GFP_KERNEL); |
| 2957 | |
| 2958 | if (!bp->ntp_fltr_bmap) |
| 2959 | rc = -ENOMEM; |
| 2960 | |
| 2961 | return rc; |
| 2962 | #else |
| 2963 | return 0; |
| 2964 | #endif |
| 2965 | } |
| 2966 | |
| 2967 | static void bnxt_free_mem(struct bnxt *bp, bool irq_re_init) |
| 2968 | { |
| 2969 | bnxt_free_vnic_attributes(bp); |
| 2970 | bnxt_free_tx_rings(bp); |
| 2971 | bnxt_free_rx_rings(bp); |
| 2972 | bnxt_free_cp_rings(bp); |
| 2973 | bnxt_free_ntp_fltrs(bp, irq_re_init); |
| 2974 | if (irq_re_init) { |
| 2975 | bnxt_free_stats(bp); |
| 2976 | bnxt_free_ring_grps(bp); |
| 2977 | bnxt_free_vnics(bp); |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2978 | kfree(bp->tx_ring); |
| 2979 | bp->tx_ring = NULL; |
| 2980 | kfree(bp->rx_ring); |
| 2981 | bp->rx_ring = NULL; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2982 | kfree(bp->bnapi); |
| 2983 | bp->bnapi = NULL; |
| 2984 | } else { |
| 2985 | bnxt_clear_ring_indices(bp); |
| 2986 | } |
| 2987 | } |
| 2988 | |
| 2989 | static int bnxt_alloc_mem(struct bnxt *bp, bool irq_re_init) |
| 2990 | { |
Michael Chan | 01657bc | 2016-01-02 23:45:03 -0500 | [diff] [blame] | 2991 | int i, j, rc, size, arr_size; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2992 | void *bnapi; |
| 2993 | |
| 2994 | if (irq_re_init) { |
| 2995 | /* Allocate bnapi mem pointer array and mem block for |
| 2996 | * all queues |
| 2997 | */ |
| 2998 | arr_size = L1_CACHE_ALIGN(sizeof(struct bnxt_napi *) * |
| 2999 | bp->cp_nr_rings); |
| 3000 | size = L1_CACHE_ALIGN(sizeof(struct bnxt_napi)); |
| 3001 | bnapi = kzalloc(arr_size + size * bp->cp_nr_rings, GFP_KERNEL); |
| 3002 | if (!bnapi) |
| 3003 | return -ENOMEM; |
| 3004 | |
| 3005 | bp->bnapi = bnapi; |
| 3006 | bnapi += arr_size; |
| 3007 | for (i = 0; i < bp->cp_nr_rings; i++, bnapi += size) { |
| 3008 | bp->bnapi[i] = bnapi; |
| 3009 | bp->bnapi[i]->index = i; |
| 3010 | bp->bnapi[i]->bp = bp; |
| 3011 | } |
| 3012 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 3013 | bp->rx_ring = kcalloc(bp->rx_nr_rings, |
| 3014 | sizeof(struct bnxt_rx_ring_info), |
| 3015 | GFP_KERNEL); |
| 3016 | if (!bp->rx_ring) |
| 3017 | return -ENOMEM; |
| 3018 | |
| 3019 | for (i = 0; i < bp->rx_nr_rings; i++) { |
| 3020 | bp->rx_ring[i].bnapi = bp->bnapi[i]; |
| 3021 | bp->bnapi[i]->rx_ring = &bp->rx_ring[i]; |
| 3022 | } |
| 3023 | |
| 3024 | bp->tx_ring = kcalloc(bp->tx_nr_rings, |
| 3025 | sizeof(struct bnxt_tx_ring_info), |
| 3026 | GFP_KERNEL); |
| 3027 | if (!bp->tx_ring) |
| 3028 | return -ENOMEM; |
| 3029 | |
Michael Chan | 01657bc | 2016-01-02 23:45:03 -0500 | [diff] [blame] | 3030 | if (bp->flags & BNXT_FLAG_SHARED_RINGS) |
| 3031 | j = 0; |
| 3032 | else |
| 3033 | j = bp->rx_nr_rings; |
| 3034 | |
| 3035 | for (i = 0; i < bp->tx_nr_rings; i++, j++) { |
| 3036 | bp->tx_ring[i].bnapi = bp->bnapi[j]; |
| 3037 | bp->bnapi[j]->tx_ring = &bp->tx_ring[i]; |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 3038 | } |
| 3039 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3040 | rc = bnxt_alloc_stats(bp); |
| 3041 | if (rc) |
| 3042 | goto alloc_mem_err; |
| 3043 | |
| 3044 | rc = bnxt_alloc_ntp_fltrs(bp); |
| 3045 | if (rc) |
| 3046 | goto alloc_mem_err; |
| 3047 | |
| 3048 | rc = bnxt_alloc_vnics(bp); |
| 3049 | if (rc) |
| 3050 | goto alloc_mem_err; |
| 3051 | } |
| 3052 | |
| 3053 | bnxt_init_ring_struct(bp); |
| 3054 | |
| 3055 | rc = bnxt_alloc_rx_rings(bp); |
| 3056 | if (rc) |
| 3057 | goto alloc_mem_err; |
| 3058 | |
| 3059 | rc = bnxt_alloc_tx_rings(bp); |
| 3060 | if (rc) |
| 3061 | goto alloc_mem_err; |
| 3062 | |
| 3063 | rc = bnxt_alloc_cp_rings(bp); |
| 3064 | if (rc) |
| 3065 | goto alloc_mem_err; |
| 3066 | |
| 3067 | bp->vnic_info[0].flags |= BNXT_VNIC_RSS_FLAG | BNXT_VNIC_MCAST_FLAG | |
| 3068 | BNXT_VNIC_UCAST_FLAG; |
| 3069 | rc = bnxt_alloc_vnic_attributes(bp); |
| 3070 | if (rc) |
| 3071 | goto alloc_mem_err; |
| 3072 | return 0; |
| 3073 | |
| 3074 | alloc_mem_err: |
| 3075 | bnxt_free_mem(bp, true); |
| 3076 | return rc; |
| 3077 | } |
| 3078 | |
Michael Chan | 9d8bc09 | 2016-12-29 12:13:33 -0500 | [diff] [blame] | 3079 | static void bnxt_disable_int(struct bnxt *bp) |
| 3080 | { |
| 3081 | int i; |
| 3082 | |
| 3083 | if (!bp->bnapi) |
| 3084 | return; |
| 3085 | |
| 3086 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 3087 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 3088 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 3089 | |
| 3090 | BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons); |
| 3091 | } |
| 3092 | } |
| 3093 | |
| 3094 | static void bnxt_disable_int_sync(struct bnxt *bp) |
| 3095 | { |
| 3096 | int i; |
| 3097 | |
| 3098 | atomic_inc(&bp->intr_sem); |
| 3099 | |
| 3100 | bnxt_disable_int(bp); |
| 3101 | for (i = 0; i < bp->cp_nr_rings; i++) |
| 3102 | synchronize_irq(bp->irq_tbl[i].vector); |
| 3103 | } |
| 3104 | |
| 3105 | static void bnxt_enable_int(struct bnxt *bp) |
| 3106 | { |
| 3107 | int i; |
| 3108 | |
| 3109 | atomic_set(&bp->intr_sem, 0); |
| 3110 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 3111 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 3112 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 3113 | |
| 3114 | BNXT_CP_DB_REARM(cpr->cp_doorbell, cpr->cp_raw_cons); |
| 3115 | } |
| 3116 | } |
| 3117 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3118 | void bnxt_hwrm_cmd_hdr_init(struct bnxt *bp, void *request, u16 req_type, |
| 3119 | u16 cmpl_ring, u16 target_id) |
| 3120 | { |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3121 | struct input *req = request; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3122 | |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3123 | req->req_type = cpu_to_le16(req_type); |
| 3124 | req->cmpl_ring = cpu_to_le16(cmpl_ring); |
| 3125 | req->target_id = cpu_to_le16(target_id); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3126 | req->resp_addr = cpu_to_le64(bp->hwrm_cmd_resp_dma_addr); |
| 3127 | } |
| 3128 | |
Michael Chan | fbfbc48 | 2016-02-26 04:00:07 -0500 | [diff] [blame] | 3129 | static int bnxt_hwrm_do_send_msg(struct bnxt *bp, void *msg, u32 msg_len, |
| 3130 | int timeout, bool silent) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3131 | { |
Michael Chan | a11fa2b | 2016-05-15 03:04:47 -0400 | [diff] [blame] | 3132 | int i, intr_process, rc, tmo_count; |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3133 | struct input *req = msg; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3134 | u32 *data = msg; |
| 3135 | __le32 *resp_len, *valid; |
| 3136 | u16 cp_ring_id, len = 0; |
| 3137 | struct hwrm_err_output *resp = bp->hwrm_cmd_resp_addr; |
| 3138 | |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3139 | req->seq_id = cpu_to_le16(bp->hwrm_cmd_seq++); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3140 | memset(resp, 0, PAGE_SIZE); |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3141 | cp_ring_id = le16_to_cpu(req->cmpl_ring); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3142 | intr_process = (cp_ring_id == INVALID_HW_RING_ID) ? 0 : 1; |
| 3143 | |
| 3144 | /* Write request msg to hwrm channel */ |
| 3145 | __iowrite32_copy(bp->bar0, data, msg_len / 4); |
| 3146 | |
Michael Chan | e6ef269 | 2016-03-28 19:46:05 -0400 | [diff] [blame] | 3147 | for (i = msg_len; i < BNXT_HWRM_MAX_REQ_LEN; i += 4) |
Michael Chan | d79979a | 2016-01-07 19:56:57 -0500 | [diff] [blame] | 3148 | writel(0, bp->bar0 + i); |
| 3149 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3150 | /* currently supports only one outstanding message */ |
| 3151 | if (intr_process) |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3152 | bp->hwrm_intr_seq_id = le16_to_cpu(req->seq_id); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3153 | |
| 3154 | /* Ring channel doorbell */ |
| 3155 | writel(1, bp->bar0 + 0x100); |
| 3156 | |
Michael Chan | ff4fe81 | 2016-02-26 04:00:04 -0500 | [diff] [blame] | 3157 | if (!timeout) |
| 3158 | timeout = DFLT_HWRM_CMD_TIMEOUT; |
| 3159 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3160 | i = 0; |
Michael Chan | a11fa2b | 2016-05-15 03:04:47 -0400 | [diff] [blame] | 3161 | tmo_count = timeout * 40; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3162 | if (intr_process) { |
| 3163 | /* Wait until hwrm response cmpl interrupt is processed */ |
| 3164 | while (bp->hwrm_intr_seq_id != HWRM_SEQ_ID_INVALID && |
Michael Chan | a11fa2b | 2016-05-15 03:04:47 -0400 | [diff] [blame] | 3165 | i++ < tmo_count) { |
| 3166 | usleep_range(25, 40); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3167 | } |
| 3168 | |
| 3169 | if (bp->hwrm_intr_seq_id != HWRM_SEQ_ID_INVALID) { |
| 3170 | netdev_err(bp->dev, "Resp cmpl intr err msg: 0x%x\n", |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3171 | le16_to_cpu(req->req_type)); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3172 | return -1; |
| 3173 | } |
| 3174 | } else { |
| 3175 | /* Check if response len is updated */ |
| 3176 | resp_len = bp->hwrm_cmd_resp_addr + HWRM_RESP_LEN_OFFSET; |
Michael Chan | a11fa2b | 2016-05-15 03:04:47 -0400 | [diff] [blame] | 3177 | for (i = 0; i < tmo_count; i++) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3178 | len = (le32_to_cpu(*resp_len) & HWRM_RESP_LEN_MASK) >> |
| 3179 | HWRM_RESP_LEN_SFT; |
| 3180 | if (len) |
| 3181 | break; |
Michael Chan | a11fa2b | 2016-05-15 03:04:47 -0400 | [diff] [blame] | 3182 | usleep_range(25, 40); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3183 | } |
| 3184 | |
Michael Chan | a11fa2b | 2016-05-15 03:04:47 -0400 | [diff] [blame] | 3185 | if (i >= tmo_count) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3186 | 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] | 3187 | timeout, le16_to_cpu(req->req_type), |
Michael Chan | 8578d6c | 2016-05-15 03:04:48 -0400 | [diff] [blame] | 3188 | le16_to_cpu(req->seq_id), len); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3189 | return -1; |
| 3190 | } |
| 3191 | |
| 3192 | /* Last word of resp contains valid bit */ |
| 3193 | valid = bp->hwrm_cmd_resp_addr + len - 4; |
Michael Chan | a11fa2b | 2016-05-15 03:04:47 -0400 | [diff] [blame] | 3194 | for (i = 0; i < 5; i++) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3195 | if (le32_to_cpu(*valid) & HWRM_RESP_VALID_MASK) |
| 3196 | break; |
Michael Chan | a11fa2b | 2016-05-15 03:04:47 -0400 | [diff] [blame] | 3197 | udelay(1); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3198 | } |
| 3199 | |
Michael Chan | a11fa2b | 2016-05-15 03:04:47 -0400 | [diff] [blame] | 3200 | if (i >= 5) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3201 | 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] | 3202 | timeout, le16_to_cpu(req->req_type), |
| 3203 | le16_to_cpu(req->seq_id), len, *valid); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3204 | return -1; |
| 3205 | } |
| 3206 | } |
| 3207 | |
| 3208 | rc = le16_to_cpu(resp->error_code); |
Michael Chan | fbfbc48 | 2016-02-26 04:00:07 -0500 | [diff] [blame] | 3209 | if (rc && !silent) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3210 | netdev_err(bp->dev, "hwrm req_type 0x%x seq id 0x%x error 0x%x\n", |
| 3211 | le16_to_cpu(resp->req_type), |
| 3212 | le16_to_cpu(resp->seq_id), rc); |
Michael Chan | fbfbc48 | 2016-02-26 04:00:07 -0500 | [diff] [blame] | 3213 | return rc; |
| 3214 | } |
| 3215 | |
| 3216 | int _hwrm_send_message(struct bnxt *bp, void *msg, u32 msg_len, int timeout) |
| 3217 | { |
| 3218 | return bnxt_hwrm_do_send_msg(bp, msg, msg_len, timeout, false); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3219 | } |
| 3220 | |
| 3221 | int hwrm_send_message(struct bnxt *bp, void *msg, u32 msg_len, int timeout) |
| 3222 | { |
| 3223 | int rc; |
| 3224 | |
| 3225 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3226 | rc = _hwrm_send_message(bp, msg, msg_len, timeout); |
| 3227 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3228 | return rc; |
| 3229 | } |
| 3230 | |
Michael Chan | 90e20921 | 2016-02-26 04:00:08 -0500 | [diff] [blame] | 3231 | int hwrm_send_message_silent(struct bnxt *bp, void *msg, u32 msg_len, |
| 3232 | int timeout) |
| 3233 | { |
| 3234 | int rc; |
| 3235 | |
| 3236 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3237 | rc = bnxt_hwrm_do_send_msg(bp, msg, msg_len, timeout, true); |
| 3238 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3239 | return rc; |
| 3240 | } |
| 3241 | |
Michael Chan | a1653b1 | 2016-12-07 00:26:20 -0500 | [diff] [blame] | 3242 | int bnxt_hwrm_func_rgtr_async_events(struct bnxt *bp, unsigned long *bmap, |
| 3243 | int bmap_size) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3244 | { |
| 3245 | struct hwrm_func_drv_rgtr_input req = {0}; |
Michael Chan | 25be862 | 2016-04-05 14:09:00 -0400 | [diff] [blame] | 3246 | DECLARE_BITMAP(async_events_bmap, 256); |
| 3247 | u32 *events = (u32 *)async_events_bmap; |
Michael Chan | a1653b1 | 2016-12-07 00:26:20 -0500 | [diff] [blame] | 3248 | int i; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3249 | |
| 3250 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_RGTR, -1, -1); |
| 3251 | |
| 3252 | req.enables = |
Michael Chan | a1653b1 | 2016-12-07 00:26:20 -0500 | [diff] [blame] | 3253 | cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_ASYNC_EVENT_FWD); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3254 | |
Michael Chan | 25be862 | 2016-04-05 14:09:00 -0400 | [diff] [blame] | 3255 | memset(async_events_bmap, 0, sizeof(async_events_bmap)); |
| 3256 | for (i = 0; i < ARRAY_SIZE(bnxt_async_events_arr); i++) |
| 3257 | __set_bit(bnxt_async_events_arr[i], async_events_bmap); |
| 3258 | |
Michael Chan | a1653b1 | 2016-12-07 00:26:20 -0500 | [diff] [blame] | 3259 | if (bmap && bmap_size) { |
| 3260 | for (i = 0; i < bmap_size; i++) { |
| 3261 | if (test_bit(i, bmap)) |
| 3262 | __set_bit(i, async_events_bmap); |
| 3263 | } |
| 3264 | } |
| 3265 | |
Michael Chan | 25be862 | 2016-04-05 14:09:00 -0400 | [diff] [blame] | 3266 | for (i = 0; i < 8; i++) |
| 3267 | req.async_event_fwd[i] |= cpu_to_le32(events[i]); |
| 3268 | |
Michael Chan | a1653b1 | 2016-12-07 00:26:20 -0500 | [diff] [blame] | 3269 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3270 | } |
| 3271 | |
| 3272 | static int bnxt_hwrm_func_drv_rgtr(struct bnxt *bp) |
| 3273 | { |
| 3274 | struct hwrm_func_drv_rgtr_input req = {0}; |
| 3275 | |
| 3276 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_RGTR, -1, -1); |
| 3277 | |
| 3278 | req.enables = |
| 3279 | cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_OS_TYPE | |
| 3280 | FUNC_DRV_RGTR_REQ_ENABLES_VER); |
| 3281 | |
Michael Chan | 11f15ed | 2016-04-05 14:08:55 -0400 | [diff] [blame] | 3282 | 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] | 3283 | req.ver_maj = DRV_VER_MAJ; |
| 3284 | req.ver_min = DRV_VER_MIN; |
| 3285 | req.ver_upd = DRV_VER_UPD; |
| 3286 | |
| 3287 | if (BNXT_PF(bp)) { |
Michael Chan | de68f5de | 2015-12-09 19:35:41 -0500 | [diff] [blame] | 3288 | DECLARE_BITMAP(vf_req_snif_bmap, 256); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3289 | u32 *data = (u32 *)vf_req_snif_bmap; |
Michael Chan | a1653b1 | 2016-12-07 00:26:20 -0500 | [diff] [blame] | 3290 | int i; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3291 | |
Michael Chan | de68f5de | 2015-12-09 19:35:41 -0500 | [diff] [blame] | 3292 | memset(vf_req_snif_bmap, 0, sizeof(vf_req_snif_bmap)); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3293 | for (i = 0; i < ARRAY_SIZE(bnxt_vf_req_snif); i++) |
| 3294 | __set_bit(bnxt_vf_req_snif[i], vf_req_snif_bmap); |
| 3295 | |
Michael Chan | de68f5de | 2015-12-09 19:35:41 -0500 | [diff] [blame] | 3296 | for (i = 0; i < 8; i++) |
| 3297 | req.vf_req_fwd[i] = cpu_to_le32(data[i]); |
| 3298 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3299 | req.enables |= |
| 3300 | cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_VF_REQ_FWD); |
| 3301 | } |
| 3302 | |
| 3303 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3304 | } |
| 3305 | |
Jeffrey Huang | be58a0d | 2015-12-27 18:19:18 -0500 | [diff] [blame] | 3306 | static int bnxt_hwrm_func_drv_unrgtr(struct bnxt *bp) |
| 3307 | { |
| 3308 | struct hwrm_func_drv_unrgtr_input req = {0}; |
| 3309 | |
| 3310 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_UNRGTR, -1, -1); |
| 3311 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3312 | } |
| 3313 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3314 | static int bnxt_hwrm_tunnel_dst_port_free(struct bnxt *bp, u8 tunnel_type) |
| 3315 | { |
| 3316 | u32 rc = 0; |
| 3317 | struct hwrm_tunnel_dst_port_free_input req = {0}; |
| 3318 | |
| 3319 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_TUNNEL_DST_PORT_FREE, -1, -1); |
| 3320 | req.tunnel_type = tunnel_type; |
| 3321 | |
| 3322 | switch (tunnel_type) { |
| 3323 | case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN: |
| 3324 | req.tunnel_dst_port_id = bp->vxlan_fw_dst_port_id; |
| 3325 | break; |
| 3326 | case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE: |
| 3327 | req.tunnel_dst_port_id = bp->nge_fw_dst_port_id; |
| 3328 | break; |
| 3329 | default: |
| 3330 | break; |
| 3331 | } |
| 3332 | |
| 3333 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3334 | if (rc) |
| 3335 | netdev_err(bp->dev, "hwrm_tunnel_dst_port_free failed. rc:%d\n", |
| 3336 | rc); |
| 3337 | return rc; |
| 3338 | } |
| 3339 | |
| 3340 | static int bnxt_hwrm_tunnel_dst_port_alloc(struct bnxt *bp, __be16 port, |
| 3341 | u8 tunnel_type) |
| 3342 | { |
| 3343 | u32 rc = 0; |
| 3344 | struct hwrm_tunnel_dst_port_alloc_input req = {0}; |
| 3345 | struct hwrm_tunnel_dst_port_alloc_output *resp = bp->hwrm_cmd_resp_addr; |
| 3346 | |
| 3347 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_TUNNEL_DST_PORT_ALLOC, -1, -1); |
| 3348 | |
| 3349 | req.tunnel_type = tunnel_type; |
| 3350 | req.tunnel_dst_port_val = port; |
| 3351 | |
| 3352 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3353 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3354 | if (rc) { |
| 3355 | netdev_err(bp->dev, "hwrm_tunnel_dst_port_alloc failed. rc:%d\n", |
| 3356 | rc); |
| 3357 | goto err_out; |
| 3358 | } |
| 3359 | |
Christophe Jaillet | 57aac71 | 2016-11-22 06:14:40 +0100 | [diff] [blame] | 3360 | switch (tunnel_type) { |
| 3361 | case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_VXLAN: |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3362 | bp->vxlan_fw_dst_port_id = resp->tunnel_dst_port_id; |
Christophe Jaillet | 57aac71 | 2016-11-22 06:14:40 +0100 | [diff] [blame] | 3363 | break; |
| 3364 | case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_GENEVE: |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3365 | bp->nge_fw_dst_port_id = resp->tunnel_dst_port_id; |
Christophe Jaillet | 57aac71 | 2016-11-22 06:14:40 +0100 | [diff] [blame] | 3366 | break; |
| 3367 | default: |
| 3368 | break; |
| 3369 | } |
| 3370 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3371 | err_out: |
| 3372 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3373 | return rc; |
| 3374 | } |
| 3375 | |
| 3376 | static int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt *bp, u16 vnic_id) |
| 3377 | { |
| 3378 | struct hwrm_cfa_l2_set_rx_mask_input req = {0}; |
| 3379 | struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id]; |
| 3380 | |
| 3381 | 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] | 3382 | req.vnic_id = cpu_to_le32(vnic->fw_vnic_id); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3383 | |
| 3384 | req.num_mc_entries = cpu_to_le32(vnic->mc_list_count); |
| 3385 | req.mc_tbl_addr = cpu_to_le64(vnic->mc_list_mapping); |
| 3386 | req.mask = cpu_to_le32(vnic->rx_mask); |
| 3387 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3388 | } |
| 3389 | |
| 3390 | #ifdef CONFIG_RFS_ACCEL |
| 3391 | static int bnxt_hwrm_cfa_ntuple_filter_free(struct bnxt *bp, |
| 3392 | struct bnxt_ntuple_filter *fltr) |
| 3393 | { |
| 3394 | struct hwrm_cfa_ntuple_filter_free_input req = {0}; |
| 3395 | |
| 3396 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_NTUPLE_FILTER_FREE, -1, -1); |
| 3397 | req.ntuple_filter_id = fltr->filter_id; |
| 3398 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3399 | } |
| 3400 | |
| 3401 | #define BNXT_NTP_FLTR_FLAGS \ |
| 3402 | (CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_L2_FILTER_ID | \ |
| 3403 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_ETHERTYPE | \ |
| 3404 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_MACADDR | \ |
| 3405 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IPADDR_TYPE | \ |
| 3406 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR | \ |
| 3407 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR_MASK | \ |
| 3408 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR | \ |
| 3409 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR_MASK | \ |
| 3410 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IP_PROTOCOL | \ |
| 3411 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT | \ |
| 3412 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT_MASK | \ |
| 3413 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT | \ |
| 3414 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT_MASK | \ |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 3415 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_ID) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3416 | |
| 3417 | static int bnxt_hwrm_cfa_ntuple_filter_alloc(struct bnxt *bp, |
| 3418 | struct bnxt_ntuple_filter *fltr) |
| 3419 | { |
| 3420 | int rc = 0; |
| 3421 | struct hwrm_cfa_ntuple_filter_alloc_input req = {0}; |
| 3422 | struct hwrm_cfa_ntuple_filter_alloc_output *resp = |
| 3423 | bp->hwrm_cmd_resp_addr; |
| 3424 | struct flow_keys *keys = &fltr->fkeys; |
| 3425 | struct bnxt_vnic_info *vnic = &bp->vnic_info[fltr->rxq + 1]; |
| 3426 | |
| 3427 | 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] | 3428 | 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] | 3429 | |
| 3430 | req.enables = cpu_to_le32(BNXT_NTP_FLTR_FLAGS); |
| 3431 | |
| 3432 | req.ethertype = htons(ETH_P_IP); |
| 3433 | memcpy(req.src_macaddr, fltr->src_mac_addr, ETH_ALEN); |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 3434 | 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] | 3435 | req.ip_protocol = keys->basic.ip_proto; |
| 3436 | |
Michael Chan | dda0e74 | 2016-12-29 12:13:40 -0500 | [diff] [blame] | 3437 | if (keys->basic.n_proto == htons(ETH_P_IPV6)) { |
| 3438 | int i; |
| 3439 | |
| 3440 | req.ethertype = htons(ETH_P_IPV6); |
| 3441 | req.ip_addr_type = |
| 3442 | CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV6; |
| 3443 | *(struct in6_addr *)&req.src_ipaddr[0] = |
| 3444 | keys->addrs.v6addrs.src; |
| 3445 | *(struct in6_addr *)&req.dst_ipaddr[0] = |
| 3446 | keys->addrs.v6addrs.dst; |
| 3447 | for (i = 0; i < 4; i++) { |
| 3448 | req.src_ipaddr_mask[i] = cpu_to_be32(0xffffffff); |
| 3449 | req.dst_ipaddr_mask[i] = cpu_to_be32(0xffffffff); |
| 3450 | } |
| 3451 | } else { |
| 3452 | req.src_ipaddr[0] = keys->addrs.v4addrs.src; |
| 3453 | req.src_ipaddr_mask[0] = cpu_to_be32(0xffffffff); |
| 3454 | req.dst_ipaddr[0] = keys->addrs.v4addrs.dst; |
| 3455 | req.dst_ipaddr_mask[0] = cpu_to_be32(0xffffffff); |
| 3456 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3457 | |
| 3458 | req.src_port = keys->ports.src; |
| 3459 | req.src_port_mask = cpu_to_be16(0xffff); |
| 3460 | req.dst_port = keys->ports.dst; |
| 3461 | req.dst_port_mask = cpu_to_be16(0xffff); |
| 3462 | |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 3463 | req.dst_id = cpu_to_le16(vnic->fw_vnic_id); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3464 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3465 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3466 | if (!rc) |
| 3467 | fltr->filter_id = resp->ntuple_filter_id; |
| 3468 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3469 | return rc; |
| 3470 | } |
| 3471 | #endif |
| 3472 | |
| 3473 | static int bnxt_hwrm_set_vnic_filter(struct bnxt *bp, u16 vnic_id, u16 idx, |
| 3474 | u8 *mac_addr) |
| 3475 | { |
| 3476 | u32 rc = 0; |
| 3477 | struct hwrm_cfa_l2_filter_alloc_input req = {0}; |
| 3478 | struct hwrm_cfa_l2_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr; |
| 3479 | |
| 3480 | 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] | 3481 | req.flags = cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_PATH_RX); |
| 3482 | if (!BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 3483 | req.flags |= |
| 3484 | cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_OUTERMOST); |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 3485 | 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] | 3486 | req.enables = |
| 3487 | cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR | |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 3488 | CFA_L2_FILTER_ALLOC_REQ_ENABLES_DST_ID | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3489 | CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR_MASK); |
| 3490 | memcpy(req.l2_addr, mac_addr, ETH_ALEN); |
| 3491 | req.l2_addr_mask[0] = 0xff; |
| 3492 | req.l2_addr_mask[1] = 0xff; |
| 3493 | req.l2_addr_mask[2] = 0xff; |
| 3494 | req.l2_addr_mask[3] = 0xff; |
| 3495 | req.l2_addr_mask[4] = 0xff; |
| 3496 | req.l2_addr_mask[5] = 0xff; |
| 3497 | |
| 3498 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3499 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3500 | if (!rc) |
| 3501 | bp->vnic_info[vnic_id].fw_l2_filter_id[idx] = |
| 3502 | resp->l2_filter_id; |
| 3503 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3504 | return rc; |
| 3505 | } |
| 3506 | |
| 3507 | static int bnxt_hwrm_clear_vnic_filter(struct bnxt *bp) |
| 3508 | { |
| 3509 | u16 i, j, num_of_vnics = 1; /* only vnic 0 supported */ |
| 3510 | int rc = 0; |
| 3511 | |
| 3512 | /* Any associated ntuple filters will also be cleared by firmware. */ |
| 3513 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3514 | for (i = 0; i < num_of_vnics; i++) { |
| 3515 | struct bnxt_vnic_info *vnic = &bp->vnic_info[i]; |
| 3516 | |
| 3517 | for (j = 0; j < vnic->uc_filter_count; j++) { |
| 3518 | struct hwrm_cfa_l2_filter_free_input req = {0}; |
| 3519 | |
| 3520 | bnxt_hwrm_cmd_hdr_init(bp, &req, |
| 3521 | HWRM_CFA_L2_FILTER_FREE, -1, -1); |
| 3522 | |
| 3523 | req.l2_filter_id = vnic->fw_l2_filter_id[j]; |
| 3524 | |
| 3525 | rc = _hwrm_send_message(bp, &req, sizeof(req), |
| 3526 | HWRM_CMD_TIMEOUT); |
| 3527 | } |
| 3528 | vnic->uc_filter_count = 0; |
| 3529 | } |
| 3530 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3531 | |
| 3532 | return rc; |
| 3533 | } |
| 3534 | |
| 3535 | static int bnxt_hwrm_vnic_set_tpa(struct bnxt *bp, u16 vnic_id, u32 tpa_flags) |
| 3536 | { |
| 3537 | struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id]; |
| 3538 | struct hwrm_vnic_tpa_cfg_input req = {0}; |
| 3539 | |
| 3540 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_TPA_CFG, -1, -1); |
| 3541 | |
| 3542 | if (tpa_flags) { |
| 3543 | u16 mss = bp->dev->mtu - 40; |
| 3544 | u32 nsegs, n, segs = 0, flags; |
| 3545 | |
| 3546 | flags = VNIC_TPA_CFG_REQ_FLAGS_TPA | |
| 3547 | VNIC_TPA_CFG_REQ_FLAGS_ENCAP_TPA | |
| 3548 | VNIC_TPA_CFG_REQ_FLAGS_RSC_WND_UPDATE | |
| 3549 | VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_ECN | |
| 3550 | VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_SAME_GRE_SEQ; |
| 3551 | if (tpa_flags & BNXT_FLAG_GRO) |
| 3552 | flags |= VNIC_TPA_CFG_REQ_FLAGS_GRO; |
| 3553 | |
| 3554 | req.flags = cpu_to_le32(flags); |
| 3555 | |
| 3556 | req.enables = |
| 3557 | cpu_to_le32(VNIC_TPA_CFG_REQ_ENABLES_MAX_AGG_SEGS | |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 3558 | VNIC_TPA_CFG_REQ_ENABLES_MAX_AGGS | |
| 3559 | VNIC_TPA_CFG_REQ_ENABLES_MIN_AGG_LEN); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3560 | |
| 3561 | /* Number of segs are log2 units, and first packet is not |
| 3562 | * included as part of this units. |
| 3563 | */ |
Michael Chan | 2839f28 | 2016-04-25 02:30:50 -0400 | [diff] [blame] | 3564 | if (mss <= BNXT_RX_PAGE_SIZE) { |
| 3565 | n = BNXT_RX_PAGE_SIZE / mss; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3566 | nsegs = (MAX_SKB_FRAGS - 1) * n; |
| 3567 | } else { |
Michael Chan | 2839f28 | 2016-04-25 02:30:50 -0400 | [diff] [blame] | 3568 | n = mss / BNXT_RX_PAGE_SIZE; |
| 3569 | if (mss & (BNXT_RX_PAGE_SIZE - 1)) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3570 | n++; |
| 3571 | nsegs = (MAX_SKB_FRAGS - n) / n; |
| 3572 | } |
| 3573 | |
| 3574 | segs = ilog2(nsegs); |
| 3575 | req.max_agg_segs = cpu_to_le16(segs); |
| 3576 | 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] | 3577 | |
| 3578 | req.min_agg_len = cpu_to_le32(512); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3579 | } |
| 3580 | req.vnic_id = cpu_to_le16(vnic->fw_vnic_id); |
| 3581 | |
| 3582 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3583 | } |
| 3584 | |
| 3585 | static int bnxt_hwrm_vnic_set_rss(struct bnxt *bp, u16 vnic_id, bool set_rss) |
| 3586 | { |
| 3587 | u32 i, j, max_rings; |
| 3588 | struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id]; |
| 3589 | struct hwrm_vnic_rss_cfg_input req = {0}; |
| 3590 | |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 3591 | if (vnic->fw_rss_cos_lb_ctx[0] == INVALID_HW_RING_ID) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3592 | return 0; |
| 3593 | |
| 3594 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_CFG, -1, -1); |
| 3595 | if (set_rss) { |
Michael Chan | 87da7f7 | 2016-11-16 21:13:09 -0500 | [diff] [blame] | 3596 | req.hash_type = cpu_to_le32(bp->rss_hash_cfg); |
Prashant Sreedharan | dc52c6c | 2016-07-18 07:15:24 -0400 | [diff] [blame] | 3597 | if (vnic->flags & BNXT_VNIC_RSS_FLAG) { |
| 3598 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 3599 | max_rings = bp->rx_nr_rings - 1; |
| 3600 | else |
| 3601 | max_rings = bp->rx_nr_rings; |
| 3602 | } else { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3603 | max_rings = 1; |
Prashant Sreedharan | dc52c6c | 2016-07-18 07:15:24 -0400 | [diff] [blame] | 3604 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3605 | |
| 3606 | /* Fill the RSS indirection table with ring group ids */ |
| 3607 | for (i = 0, j = 0; i < HW_HASH_INDEX_SIZE; i++, j++) { |
| 3608 | if (j == max_rings) |
| 3609 | j = 0; |
| 3610 | vnic->rss_table[i] = cpu_to_le16(vnic->fw_grp_ids[j]); |
| 3611 | } |
| 3612 | |
| 3613 | req.ring_grp_tbl_addr = cpu_to_le64(vnic->rss_table_dma_addr); |
| 3614 | req.hash_key_tbl_addr = |
| 3615 | cpu_to_le64(vnic->rss_hash_key_dma_addr); |
| 3616 | } |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 3617 | 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] | 3618 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3619 | } |
| 3620 | |
| 3621 | static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, u16 vnic_id) |
| 3622 | { |
| 3623 | struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id]; |
| 3624 | struct hwrm_vnic_plcmodes_cfg_input req = {0}; |
| 3625 | |
| 3626 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_PLCMODES_CFG, -1, -1); |
| 3627 | req.flags = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT | |
| 3628 | VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV4 | |
| 3629 | VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6); |
| 3630 | req.enables = |
| 3631 | cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID | |
| 3632 | VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID); |
| 3633 | /* thresholds not implemented in firmware yet */ |
| 3634 | req.jumbo_thresh = cpu_to_le16(bp->rx_copy_thresh); |
| 3635 | req.hds_threshold = cpu_to_le16(bp->rx_copy_thresh); |
| 3636 | req.vnic_id = cpu_to_le32(vnic->fw_vnic_id); |
| 3637 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3638 | } |
| 3639 | |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 3640 | static void bnxt_hwrm_vnic_ctx_free_one(struct bnxt *bp, u16 vnic_id, |
| 3641 | u16 ctx_idx) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3642 | { |
| 3643 | struct hwrm_vnic_rss_cos_lb_ctx_free_input req = {0}; |
| 3644 | |
| 3645 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_COS_LB_CTX_FREE, -1, -1); |
| 3646 | req.rss_cos_lb_ctx_id = |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 3647 | 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] | 3648 | |
| 3649 | hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 3650 | 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] | 3651 | } |
| 3652 | |
| 3653 | static void bnxt_hwrm_vnic_ctx_free(struct bnxt *bp) |
| 3654 | { |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 3655 | int i, j; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3656 | |
| 3657 | for (i = 0; i < bp->nr_vnics; i++) { |
| 3658 | struct bnxt_vnic_info *vnic = &bp->vnic_info[i]; |
| 3659 | |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 3660 | for (j = 0; j < BNXT_MAX_CTX_PER_VNIC; j++) { |
| 3661 | if (vnic->fw_rss_cos_lb_ctx[j] != INVALID_HW_RING_ID) |
| 3662 | bnxt_hwrm_vnic_ctx_free_one(bp, i, j); |
| 3663 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3664 | } |
| 3665 | bp->rsscos_nr_ctxs = 0; |
| 3666 | } |
| 3667 | |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 3668 | 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] | 3669 | { |
| 3670 | int rc; |
| 3671 | struct hwrm_vnic_rss_cos_lb_ctx_alloc_input req = {0}; |
| 3672 | struct hwrm_vnic_rss_cos_lb_ctx_alloc_output *resp = |
| 3673 | bp->hwrm_cmd_resp_addr; |
| 3674 | |
| 3675 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_COS_LB_CTX_ALLOC, -1, |
| 3676 | -1); |
| 3677 | |
| 3678 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3679 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3680 | if (!rc) |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 3681 | bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx] = |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3682 | le16_to_cpu(resp->rss_cos_lb_ctx_id); |
| 3683 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3684 | |
| 3685 | return rc; |
| 3686 | } |
| 3687 | |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 3688 | int bnxt_hwrm_vnic_cfg(struct bnxt *bp, u16 vnic_id) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3689 | { |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3690 | unsigned int ring = 0, grp_idx; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3691 | struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id]; |
| 3692 | struct hwrm_vnic_cfg_input req = {0}; |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 3693 | u16 def_vlan = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3694 | |
| 3695 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_CFG, -1, -1); |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 3696 | |
Prashant Sreedharan | dc52c6c | 2016-07-18 07:15:24 -0400 | [diff] [blame] | 3697 | req.enables = cpu_to_le32(VNIC_CFG_REQ_ENABLES_DFLT_RING_GRP); |
| 3698 | /* Only RSS support for now TBD: COS & LB */ |
| 3699 | if (vnic->fw_rss_cos_lb_ctx[0] != INVALID_HW_RING_ID) { |
| 3700 | req.rss_rule = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[0]); |
| 3701 | req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE | |
| 3702 | VNIC_CFG_REQ_ENABLES_MRU); |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 3703 | } else if (vnic->flags & BNXT_VNIC_RFS_NEW_RSS_FLAG) { |
| 3704 | req.rss_rule = |
| 3705 | cpu_to_le16(bp->vnic_info[0].fw_rss_cos_lb_ctx[0]); |
| 3706 | req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE | |
| 3707 | VNIC_CFG_REQ_ENABLES_MRU); |
| 3708 | 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] | 3709 | } else { |
| 3710 | req.rss_rule = cpu_to_le16(0xffff); |
| 3711 | } |
| 3712 | |
| 3713 | if (BNXT_CHIP_TYPE_NITRO_A0(bp) && |
| 3714 | (vnic->fw_rss_cos_lb_ctx[0] != INVALID_HW_RING_ID)) { |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 3715 | req.cos_rule = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[1]); |
| 3716 | req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_COS_RULE); |
| 3717 | } else { |
| 3718 | req.cos_rule = cpu_to_le16(0xffff); |
| 3719 | } |
| 3720 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3721 | if (vnic->flags & BNXT_VNIC_RSS_FLAG) |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3722 | ring = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3723 | else if (vnic->flags & BNXT_VNIC_RFS_FLAG) |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3724 | ring = vnic_id - 1; |
Prashant Sreedharan | 7659519 | 2016-07-18 07:15:22 -0400 | [diff] [blame] | 3725 | else if ((vnic_id == 1) && BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 3726 | ring = bp->rx_nr_rings - 1; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3727 | |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3728 | grp_idx = bp->rx_ring[ring].bnapi->index; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3729 | req.vnic_id = cpu_to_le16(vnic->fw_vnic_id); |
| 3730 | req.dflt_ring_grp = cpu_to_le16(bp->grp_info[grp_idx].fw_grp_id); |
| 3731 | |
| 3732 | req.lb_rule = cpu_to_le16(0xffff); |
| 3733 | req.mru = cpu_to_le16(bp->dev->mtu + ETH_HLEN + ETH_FCS_LEN + |
| 3734 | VLAN_HLEN); |
| 3735 | |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 3736 | #ifdef CONFIG_BNXT_SRIOV |
| 3737 | if (BNXT_VF(bp)) |
| 3738 | def_vlan = bp->vf.vlan; |
| 3739 | #endif |
| 3740 | if ((bp->flags & BNXT_FLAG_STRIP_VLAN) || def_vlan) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3741 | req.flags |= cpu_to_le32(VNIC_CFG_REQ_FLAGS_VLAN_STRIP_MODE); |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 3742 | if (!vnic_id && bnxt_ulp_registered(bp->edev, BNXT_ROCE_ULP)) |
| 3743 | req.flags |= |
| 3744 | cpu_to_le32(VNIC_CFG_REQ_FLAGS_ROCE_DUAL_VNIC_MODE); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3745 | |
| 3746 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3747 | } |
| 3748 | |
| 3749 | static int bnxt_hwrm_vnic_free_one(struct bnxt *bp, u16 vnic_id) |
| 3750 | { |
| 3751 | u32 rc = 0; |
| 3752 | |
| 3753 | if (bp->vnic_info[vnic_id].fw_vnic_id != INVALID_HW_RING_ID) { |
| 3754 | struct hwrm_vnic_free_input req = {0}; |
| 3755 | |
| 3756 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_FREE, -1, -1); |
| 3757 | req.vnic_id = |
| 3758 | cpu_to_le32(bp->vnic_info[vnic_id].fw_vnic_id); |
| 3759 | |
| 3760 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3761 | if (rc) |
| 3762 | return rc; |
| 3763 | bp->vnic_info[vnic_id].fw_vnic_id = INVALID_HW_RING_ID; |
| 3764 | } |
| 3765 | return rc; |
| 3766 | } |
| 3767 | |
| 3768 | static void bnxt_hwrm_vnic_free(struct bnxt *bp) |
| 3769 | { |
| 3770 | u16 i; |
| 3771 | |
| 3772 | for (i = 0; i < bp->nr_vnics; i++) |
| 3773 | bnxt_hwrm_vnic_free_one(bp, i); |
| 3774 | } |
| 3775 | |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3776 | static int bnxt_hwrm_vnic_alloc(struct bnxt *bp, u16 vnic_id, |
| 3777 | unsigned int start_rx_ring_idx, |
| 3778 | unsigned int nr_rings) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3779 | { |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3780 | int rc = 0; |
| 3781 | 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] | 3782 | struct hwrm_vnic_alloc_input req = {0}; |
| 3783 | struct hwrm_vnic_alloc_output *resp = bp->hwrm_cmd_resp_addr; |
| 3784 | |
| 3785 | /* map ring groups to this vnic */ |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3786 | for (i = start_rx_ring_idx, j = 0; i < end_idx; i++, j++) { |
| 3787 | grp_idx = bp->rx_ring[i].bnapi->index; |
| 3788 | 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] | 3789 | 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] | 3790 | j, nr_rings); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3791 | break; |
| 3792 | } |
| 3793 | bp->vnic_info[vnic_id].fw_grp_ids[j] = |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3794 | bp->grp_info[grp_idx].fw_grp_id; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3795 | } |
| 3796 | |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 3797 | bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[0] = INVALID_HW_RING_ID; |
| 3798 | 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] | 3799 | if (vnic_id == 0) |
| 3800 | req.flags = cpu_to_le32(VNIC_ALLOC_REQ_FLAGS_DEFAULT); |
| 3801 | |
| 3802 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_ALLOC, -1, -1); |
| 3803 | |
| 3804 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3805 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3806 | if (!rc) |
| 3807 | bp->vnic_info[vnic_id].fw_vnic_id = le32_to_cpu(resp->vnic_id); |
| 3808 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3809 | return rc; |
| 3810 | } |
| 3811 | |
Michael Chan | 8fdefd6 | 2016-12-29 12:13:36 -0500 | [diff] [blame] | 3812 | static int bnxt_hwrm_vnic_qcaps(struct bnxt *bp) |
| 3813 | { |
| 3814 | struct hwrm_vnic_qcaps_output *resp = bp->hwrm_cmd_resp_addr; |
| 3815 | struct hwrm_vnic_qcaps_input req = {0}; |
| 3816 | int rc; |
| 3817 | |
| 3818 | if (bp->hwrm_spec_code < 0x10600) |
| 3819 | return 0; |
| 3820 | |
| 3821 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_QCAPS, -1, -1); |
| 3822 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3823 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3824 | if (!rc) { |
| 3825 | if (resp->flags & |
| 3826 | cpu_to_le32(VNIC_QCAPS_RESP_FLAGS_RSS_DFLT_CR_CAP)) |
| 3827 | bp->flags |= BNXT_FLAG_NEW_RSS_CAP; |
| 3828 | } |
| 3829 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3830 | return rc; |
| 3831 | } |
| 3832 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3833 | static int bnxt_hwrm_ring_grp_alloc(struct bnxt *bp) |
| 3834 | { |
| 3835 | u16 i; |
| 3836 | u32 rc = 0; |
| 3837 | |
| 3838 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3839 | for (i = 0; i < bp->rx_nr_rings; i++) { |
| 3840 | struct hwrm_ring_grp_alloc_input req = {0}; |
| 3841 | struct hwrm_ring_grp_alloc_output *resp = |
| 3842 | bp->hwrm_cmd_resp_addr; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3843 | unsigned int grp_idx = bp->rx_ring[i].bnapi->index; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3844 | |
| 3845 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_GRP_ALLOC, -1, -1); |
| 3846 | |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3847 | req.cr = cpu_to_le16(bp->grp_info[grp_idx].cp_fw_ring_id); |
| 3848 | req.rr = cpu_to_le16(bp->grp_info[grp_idx].rx_fw_ring_id); |
| 3849 | req.ar = cpu_to_le16(bp->grp_info[grp_idx].agg_fw_ring_id); |
| 3850 | 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] | 3851 | |
| 3852 | rc = _hwrm_send_message(bp, &req, sizeof(req), |
| 3853 | HWRM_CMD_TIMEOUT); |
| 3854 | if (rc) |
| 3855 | break; |
| 3856 | |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 3857 | bp->grp_info[grp_idx].fw_grp_id = |
| 3858 | le32_to_cpu(resp->ring_group_id); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3859 | } |
| 3860 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3861 | return rc; |
| 3862 | } |
| 3863 | |
| 3864 | static int bnxt_hwrm_ring_grp_free(struct bnxt *bp) |
| 3865 | { |
| 3866 | u16 i; |
| 3867 | u32 rc = 0; |
| 3868 | struct hwrm_ring_grp_free_input req = {0}; |
| 3869 | |
| 3870 | if (!bp->grp_info) |
| 3871 | return 0; |
| 3872 | |
| 3873 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_GRP_FREE, -1, -1); |
| 3874 | |
| 3875 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3876 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 3877 | if (bp->grp_info[i].fw_grp_id == INVALID_HW_RING_ID) |
| 3878 | continue; |
| 3879 | req.ring_group_id = |
| 3880 | cpu_to_le32(bp->grp_info[i].fw_grp_id); |
| 3881 | |
| 3882 | rc = _hwrm_send_message(bp, &req, sizeof(req), |
| 3883 | HWRM_CMD_TIMEOUT); |
| 3884 | if (rc) |
| 3885 | break; |
| 3886 | bp->grp_info[i].fw_grp_id = INVALID_HW_RING_ID; |
| 3887 | } |
| 3888 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3889 | return rc; |
| 3890 | } |
| 3891 | |
| 3892 | static int hwrm_ring_alloc_send_msg(struct bnxt *bp, |
| 3893 | struct bnxt_ring_struct *ring, |
| 3894 | u32 ring_type, u32 map_index, |
| 3895 | u32 stats_ctx_id) |
| 3896 | { |
| 3897 | int rc = 0, err = 0; |
| 3898 | struct hwrm_ring_alloc_input req = {0}; |
| 3899 | struct hwrm_ring_alloc_output *resp = bp->hwrm_cmd_resp_addr; |
| 3900 | u16 ring_id; |
| 3901 | |
| 3902 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_ALLOC, -1, -1); |
| 3903 | |
| 3904 | req.enables = 0; |
| 3905 | if (ring->nr_pages > 1) { |
| 3906 | req.page_tbl_addr = cpu_to_le64(ring->pg_tbl_map); |
| 3907 | /* Page size is in log2 units */ |
| 3908 | req.page_size = BNXT_PAGE_SHIFT; |
| 3909 | req.page_tbl_depth = 1; |
| 3910 | } else { |
| 3911 | req.page_tbl_addr = cpu_to_le64(ring->dma_arr[0]); |
| 3912 | } |
| 3913 | req.fbo = 0; |
| 3914 | /* Association of ring index with doorbell index and MSIX number */ |
| 3915 | req.logical_id = cpu_to_le16(map_index); |
| 3916 | |
| 3917 | switch (ring_type) { |
| 3918 | case HWRM_RING_ALLOC_TX: |
| 3919 | req.ring_type = RING_ALLOC_REQ_RING_TYPE_TX; |
| 3920 | /* Association of transmit ring with completion ring */ |
| 3921 | req.cmpl_ring_id = |
| 3922 | cpu_to_le16(bp->grp_info[map_index].cp_fw_ring_id); |
| 3923 | req.length = cpu_to_le32(bp->tx_ring_mask + 1); |
| 3924 | req.stat_ctx_id = cpu_to_le32(stats_ctx_id); |
| 3925 | req.queue_id = cpu_to_le16(ring->queue_id); |
| 3926 | break; |
| 3927 | case HWRM_RING_ALLOC_RX: |
| 3928 | req.ring_type = RING_ALLOC_REQ_RING_TYPE_RX; |
| 3929 | req.length = cpu_to_le32(bp->rx_ring_mask + 1); |
| 3930 | break; |
| 3931 | case HWRM_RING_ALLOC_AGG: |
| 3932 | req.ring_type = RING_ALLOC_REQ_RING_TYPE_RX; |
| 3933 | req.length = cpu_to_le32(bp->rx_agg_ring_mask + 1); |
| 3934 | break; |
| 3935 | case HWRM_RING_ALLOC_CMPL: |
| 3936 | req.ring_type = RING_ALLOC_REQ_RING_TYPE_CMPL; |
| 3937 | req.length = cpu_to_le32(bp->cp_ring_mask + 1); |
| 3938 | if (bp->flags & BNXT_FLAG_USING_MSIX) |
| 3939 | req.int_mode = RING_ALLOC_REQ_INT_MODE_MSIX; |
| 3940 | break; |
| 3941 | default: |
| 3942 | netdev_err(bp->dev, "hwrm alloc invalid ring type %d\n", |
| 3943 | ring_type); |
| 3944 | return -1; |
| 3945 | } |
| 3946 | |
| 3947 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3948 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3949 | err = le16_to_cpu(resp->error_code); |
| 3950 | ring_id = le16_to_cpu(resp->ring_id); |
| 3951 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3952 | |
| 3953 | if (rc || err) { |
| 3954 | switch (ring_type) { |
| 3955 | case RING_FREE_REQ_RING_TYPE_CMPL: |
| 3956 | netdev_err(bp->dev, "hwrm_ring_alloc cp failed. rc:%x err:%x\n", |
| 3957 | rc, err); |
| 3958 | return -1; |
| 3959 | |
| 3960 | case RING_FREE_REQ_RING_TYPE_RX: |
| 3961 | netdev_err(bp->dev, "hwrm_ring_alloc rx failed. rc:%x err:%x\n", |
| 3962 | rc, err); |
| 3963 | return -1; |
| 3964 | |
| 3965 | case RING_FREE_REQ_RING_TYPE_TX: |
| 3966 | netdev_err(bp->dev, "hwrm_ring_alloc tx failed. rc:%x err:%x\n", |
| 3967 | rc, err); |
| 3968 | return -1; |
| 3969 | |
| 3970 | default: |
| 3971 | netdev_err(bp->dev, "Invalid ring\n"); |
| 3972 | return -1; |
| 3973 | } |
| 3974 | } |
| 3975 | ring->fw_ring_id = ring_id; |
| 3976 | return rc; |
| 3977 | } |
| 3978 | |
Michael Chan | 486b5c2 | 2016-12-29 12:13:42 -0500 | [diff] [blame] | 3979 | static int bnxt_hwrm_set_async_event_cr(struct bnxt *bp, int idx) |
| 3980 | { |
| 3981 | int rc; |
| 3982 | |
| 3983 | if (BNXT_PF(bp)) { |
| 3984 | struct hwrm_func_cfg_input req = {0}; |
| 3985 | |
| 3986 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1); |
| 3987 | req.fid = cpu_to_le16(0xffff); |
| 3988 | req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_ASYNC_EVENT_CR); |
| 3989 | req.async_event_cr = cpu_to_le16(idx); |
| 3990 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3991 | } else { |
| 3992 | struct hwrm_func_vf_cfg_input req = {0}; |
| 3993 | |
| 3994 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_VF_CFG, -1, -1); |
| 3995 | req.enables = |
| 3996 | cpu_to_le32(FUNC_VF_CFG_REQ_ENABLES_ASYNC_EVENT_CR); |
| 3997 | req.async_event_cr = cpu_to_le16(idx); |
| 3998 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3999 | } |
| 4000 | return rc; |
| 4001 | } |
| 4002 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4003 | static int bnxt_hwrm_ring_alloc(struct bnxt *bp) |
| 4004 | { |
| 4005 | int i, rc = 0; |
| 4006 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4007 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 4008 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 4009 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 4010 | struct bnxt_ring_struct *ring = &cpr->cp_ring_struct; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4011 | |
Prashant Sreedharan | 33e52d8 | 2016-03-28 19:46:04 -0400 | [diff] [blame] | 4012 | cpr->cp_doorbell = bp->bar1 + i * 0x80; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4013 | rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_CMPL, i, |
| 4014 | INVALID_STATS_CTX_ID); |
| 4015 | if (rc) |
| 4016 | goto err_out; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4017 | BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons); |
| 4018 | bp->grp_info[i].cp_fw_ring_id = ring->fw_ring_id; |
Michael Chan | 486b5c2 | 2016-12-29 12:13:42 -0500 | [diff] [blame] | 4019 | |
| 4020 | if (!i) { |
| 4021 | rc = bnxt_hwrm_set_async_event_cr(bp, ring->fw_ring_id); |
| 4022 | if (rc) |
| 4023 | netdev_warn(bp->dev, "Failed to set async event completion ring.\n"); |
| 4024 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4025 | } |
| 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 map_idx = txr->bnapi->index; |
| 4031 | u16 fw_stats_ctx = bp->grp_info[map_idx].fw_stats_ctx; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4032 | |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4033 | rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_TX, |
| 4034 | map_idx, fw_stats_ctx); |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4035 | if (rc) |
| 4036 | goto err_out; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4037 | txr->tx_doorbell = bp->bar1 + map_idx * 0x80; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4038 | } |
| 4039 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4040 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 4041 | struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i]; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4042 | struct bnxt_ring_struct *ring = &rxr->rx_ring_struct; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4043 | u32 map_idx = rxr->bnapi->index; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4044 | |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4045 | rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_RX, |
| 4046 | map_idx, INVALID_STATS_CTX_ID); |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4047 | if (rc) |
| 4048 | goto err_out; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4049 | rxr->rx_doorbell = bp->bar1 + map_idx * 0x80; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4050 | writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell); |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4051 | 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] | 4052 | } |
| 4053 | |
| 4054 | if (bp->flags & BNXT_FLAG_AGG_RINGS) { |
| 4055 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 4056 | struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4057 | struct bnxt_ring_struct *ring = |
| 4058 | &rxr->rx_agg_ring_struct; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4059 | u32 grp_idx = rxr->bnapi->index; |
| 4060 | u32 map_idx = grp_idx + bp->rx_nr_rings; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4061 | |
| 4062 | rc = hwrm_ring_alloc_send_msg(bp, ring, |
| 4063 | HWRM_RING_ALLOC_AGG, |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4064 | map_idx, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4065 | INVALID_STATS_CTX_ID); |
| 4066 | if (rc) |
| 4067 | goto err_out; |
| 4068 | |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4069 | rxr->rx_agg_doorbell = bp->bar1 + map_idx * 0x80; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4070 | writel(DB_KEY_RX | rxr->rx_agg_prod, |
| 4071 | rxr->rx_agg_doorbell); |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4072 | 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] | 4073 | } |
| 4074 | } |
| 4075 | err_out: |
| 4076 | return rc; |
| 4077 | } |
| 4078 | |
| 4079 | static int hwrm_ring_free_send_msg(struct bnxt *bp, |
| 4080 | struct bnxt_ring_struct *ring, |
| 4081 | u32 ring_type, int cmpl_ring_id) |
| 4082 | { |
| 4083 | int rc; |
| 4084 | struct hwrm_ring_free_input req = {0}; |
| 4085 | struct hwrm_ring_free_output *resp = bp->hwrm_cmd_resp_addr; |
| 4086 | u16 error_code; |
| 4087 | |
Prashant Sreedharan | 74608fc | 2016-01-28 03:11:20 -0500 | [diff] [blame] | 4088 | 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] | 4089 | req.ring_type = ring_type; |
| 4090 | req.ring_id = cpu_to_le16(ring->fw_ring_id); |
| 4091 | |
| 4092 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4093 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4094 | error_code = le16_to_cpu(resp->error_code); |
| 4095 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4096 | |
| 4097 | if (rc || error_code) { |
| 4098 | switch (ring_type) { |
| 4099 | case RING_FREE_REQ_RING_TYPE_CMPL: |
| 4100 | netdev_err(bp->dev, "hwrm_ring_free cp failed. rc:%d\n", |
| 4101 | rc); |
| 4102 | return rc; |
| 4103 | case RING_FREE_REQ_RING_TYPE_RX: |
| 4104 | netdev_err(bp->dev, "hwrm_ring_free rx failed. rc:%d\n", |
| 4105 | rc); |
| 4106 | return rc; |
| 4107 | case RING_FREE_REQ_RING_TYPE_TX: |
| 4108 | netdev_err(bp->dev, "hwrm_ring_free tx failed. rc:%d\n", |
| 4109 | rc); |
| 4110 | return rc; |
| 4111 | default: |
| 4112 | netdev_err(bp->dev, "Invalid ring\n"); |
| 4113 | return -1; |
| 4114 | } |
| 4115 | } |
| 4116 | return 0; |
| 4117 | } |
| 4118 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4119 | static void bnxt_hwrm_ring_free(struct bnxt *bp, bool close_path) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4120 | { |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4121 | int i; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4122 | |
| 4123 | if (!bp->bnapi) |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4124 | return; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4125 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4126 | for (i = 0; i < bp->tx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 4127 | struct bnxt_tx_ring_info *txr = &bp->tx_ring[i]; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4128 | struct bnxt_ring_struct *ring = &txr->tx_ring_struct; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4129 | u32 grp_idx = txr->bnapi->index; |
| 4130 | 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] | 4131 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4132 | if (ring->fw_ring_id != INVALID_HW_RING_ID) { |
| 4133 | hwrm_ring_free_send_msg(bp, ring, |
| 4134 | RING_FREE_REQ_RING_TYPE_TX, |
| 4135 | close_path ? cmpl_ring_id : |
| 4136 | INVALID_HW_RING_ID); |
| 4137 | ring->fw_ring_id = INVALID_HW_RING_ID; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4138 | } |
| 4139 | } |
| 4140 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4141 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 4142 | struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i]; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4143 | struct bnxt_ring_struct *ring = &rxr->rx_ring_struct; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4144 | u32 grp_idx = rxr->bnapi->index; |
| 4145 | 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] | 4146 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4147 | if (ring->fw_ring_id != INVALID_HW_RING_ID) { |
| 4148 | hwrm_ring_free_send_msg(bp, ring, |
| 4149 | RING_FREE_REQ_RING_TYPE_RX, |
| 4150 | close_path ? cmpl_ring_id : |
| 4151 | INVALID_HW_RING_ID); |
| 4152 | ring->fw_ring_id = INVALID_HW_RING_ID; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4153 | bp->grp_info[grp_idx].rx_fw_ring_id = |
| 4154 | INVALID_HW_RING_ID; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4155 | } |
| 4156 | } |
| 4157 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4158 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 4159 | struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i]; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4160 | struct bnxt_ring_struct *ring = &rxr->rx_agg_ring_struct; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4161 | u32 grp_idx = rxr->bnapi->index; |
| 4162 | 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] | 4163 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4164 | if (ring->fw_ring_id != INVALID_HW_RING_ID) { |
| 4165 | hwrm_ring_free_send_msg(bp, ring, |
| 4166 | RING_FREE_REQ_RING_TYPE_RX, |
| 4167 | close_path ? cmpl_ring_id : |
| 4168 | INVALID_HW_RING_ID); |
| 4169 | ring->fw_ring_id = INVALID_HW_RING_ID; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4170 | bp->grp_info[grp_idx].agg_fw_ring_id = |
| 4171 | INVALID_HW_RING_ID; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4172 | } |
| 4173 | } |
| 4174 | |
Michael Chan | 9d8bc09 | 2016-12-29 12:13:33 -0500 | [diff] [blame] | 4175 | /* The completion rings are about to be freed. After that the |
| 4176 | * IRQ doorbell will not work anymore. So we need to disable |
| 4177 | * IRQ here. |
| 4178 | */ |
| 4179 | bnxt_disable_int_sync(bp); |
| 4180 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4181 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 4182 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 4183 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 4184 | struct bnxt_ring_struct *ring = &cpr->cp_ring_struct; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4185 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4186 | if (ring->fw_ring_id != INVALID_HW_RING_ID) { |
| 4187 | hwrm_ring_free_send_msg(bp, ring, |
| 4188 | RING_FREE_REQ_RING_TYPE_CMPL, |
| 4189 | INVALID_HW_RING_ID); |
| 4190 | ring->fw_ring_id = INVALID_HW_RING_ID; |
| 4191 | bp->grp_info[i].cp_fw_ring_id = INVALID_HW_RING_ID; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4192 | } |
| 4193 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4194 | } |
| 4195 | |
Michael Chan | 391be5c | 2016-12-29 12:13:41 -0500 | [diff] [blame] | 4196 | /* Caller must hold bp->hwrm_cmd_lock */ |
| 4197 | int __bnxt_hwrm_get_tx_rings(struct bnxt *bp, u16 fid, int *tx_rings) |
| 4198 | { |
| 4199 | struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr; |
| 4200 | struct hwrm_func_qcfg_input req = {0}; |
| 4201 | int rc; |
| 4202 | |
| 4203 | if (bp->hwrm_spec_code < 0x10601) |
| 4204 | return 0; |
| 4205 | |
| 4206 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCFG, -1, -1); |
| 4207 | req.fid = cpu_to_le16(fid); |
| 4208 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4209 | if (!rc) |
| 4210 | *tx_rings = le16_to_cpu(resp->alloc_tx_rings); |
| 4211 | |
| 4212 | return rc; |
| 4213 | } |
| 4214 | |
| 4215 | int bnxt_hwrm_reserve_tx_rings(struct bnxt *bp, int *tx_rings) |
| 4216 | { |
| 4217 | struct hwrm_func_cfg_input req = {0}; |
| 4218 | int rc; |
| 4219 | |
| 4220 | if (bp->hwrm_spec_code < 0x10601) |
| 4221 | return 0; |
| 4222 | |
| 4223 | if (BNXT_VF(bp)) |
| 4224 | return 0; |
| 4225 | |
| 4226 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1); |
| 4227 | req.fid = cpu_to_le16(0xffff); |
| 4228 | req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_NUM_TX_RINGS); |
| 4229 | req.num_tx_rings = cpu_to_le16(*tx_rings); |
| 4230 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4231 | if (rc) |
| 4232 | return rc; |
| 4233 | |
| 4234 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4235 | rc = __bnxt_hwrm_get_tx_rings(bp, 0xffff, tx_rings); |
| 4236 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4237 | return rc; |
| 4238 | } |
| 4239 | |
Michael Chan | bb053f5 | 2016-02-26 04:00:02 -0500 | [diff] [blame] | 4240 | static void bnxt_hwrm_set_coal_params(struct bnxt *bp, u32 max_bufs, |
| 4241 | u32 buf_tmrs, u16 flags, |
| 4242 | struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *req) |
| 4243 | { |
| 4244 | req->flags = cpu_to_le16(flags); |
| 4245 | req->num_cmpl_dma_aggr = cpu_to_le16((u16)max_bufs); |
| 4246 | req->num_cmpl_dma_aggr_during_int = cpu_to_le16(max_bufs >> 16); |
| 4247 | req->cmpl_aggr_dma_tmr = cpu_to_le16((u16)buf_tmrs); |
| 4248 | req->cmpl_aggr_dma_tmr_during_int = cpu_to_le16(buf_tmrs >> 16); |
| 4249 | /* Minimum time between 2 interrupts set to buf_tmr x 2 */ |
| 4250 | req->int_lat_tmr_min = cpu_to_le16((u16)buf_tmrs * 2); |
| 4251 | req->int_lat_tmr_max = cpu_to_le16((u16)buf_tmrs * 4); |
| 4252 | req->num_cmpl_aggr_int = cpu_to_le16((u16)max_bufs * 4); |
| 4253 | } |
| 4254 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4255 | int bnxt_hwrm_set_coal(struct bnxt *bp) |
| 4256 | { |
| 4257 | int i, rc = 0; |
Michael Chan | dfc9c94 | 2016-02-26 04:00:03 -0500 | [diff] [blame] | 4258 | struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req_rx = {0}, |
| 4259 | req_tx = {0}, *req; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4260 | u16 max_buf, max_buf_irq; |
| 4261 | u16 buf_tmr, buf_tmr_irq; |
| 4262 | u32 flags; |
| 4263 | |
Michael Chan | dfc9c94 | 2016-02-26 04:00:03 -0500 | [diff] [blame] | 4264 | bnxt_hwrm_cmd_hdr_init(bp, &req_rx, |
| 4265 | HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1); |
| 4266 | bnxt_hwrm_cmd_hdr_init(bp, &req_tx, |
| 4267 | HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4268 | |
Michael Chan | dfb5b89 | 2016-02-26 04:00:01 -0500 | [diff] [blame] | 4269 | /* Each rx completion (2 records) should be DMAed immediately. |
| 4270 | * DMA 1/4 of the completion buffers at a time. |
| 4271 | */ |
| 4272 | max_buf = min_t(u16, bp->rx_coal_bufs / 4, 2); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4273 | /* max_buf must not be zero */ |
| 4274 | max_buf = clamp_t(u16, max_buf, 1, 63); |
Michael Chan | dfb5b89 | 2016-02-26 04:00:01 -0500 | [diff] [blame] | 4275 | max_buf_irq = clamp_t(u16, bp->rx_coal_bufs_irq, 1, 63); |
| 4276 | buf_tmr = BNXT_USEC_TO_COAL_TIMER(bp->rx_coal_ticks); |
| 4277 | /* buf timer set to 1/4 of interrupt timer */ |
| 4278 | buf_tmr = max_t(u16, buf_tmr / 4, 1); |
| 4279 | buf_tmr_irq = BNXT_USEC_TO_COAL_TIMER(bp->rx_coal_ticks_irq); |
| 4280 | buf_tmr_irq = max_t(u16, buf_tmr_irq, 1); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4281 | |
| 4282 | flags = RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_TIMER_RESET; |
| 4283 | |
| 4284 | /* RING_IDLE generates more IRQs for lower latency. Enable it only |
| 4285 | * if coal_ticks is less than 25 us. |
| 4286 | */ |
Michael Chan | dfb5b89 | 2016-02-26 04:00:01 -0500 | [diff] [blame] | 4287 | if (bp->rx_coal_ticks < 25) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4288 | flags |= RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_RING_IDLE; |
| 4289 | |
Michael Chan | bb053f5 | 2016-02-26 04:00:02 -0500 | [diff] [blame] | 4290 | bnxt_hwrm_set_coal_params(bp, max_buf_irq << 16 | max_buf, |
Michael Chan | dfc9c94 | 2016-02-26 04:00:03 -0500 | [diff] [blame] | 4291 | buf_tmr_irq << 16 | buf_tmr, flags, &req_rx); |
| 4292 | |
| 4293 | /* max_buf must not be zero */ |
| 4294 | max_buf = clamp_t(u16, bp->tx_coal_bufs, 1, 63); |
| 4295 | max_buf_irq = clamp_t(u16, bp->tx_coal_bufs_irq, 1, 63); |
| 4296 | buf_tmr = BNXT_USEC_TO_COAL_TIMER(bp->tx_coal_ticks); |
| 4297 | /* buf timer set to 1/4 of interrupt timer */ |
| 4298 | buf_tmr = max_t(u16, buf_tmr / 4, 1); |
| 4299 | buf_tmr_irq = BNXT_USEC_TO_COAL_TIMER(bp->tx_coal_ticks_irq); |
| 4300 | buf_tmr_irq = max_t(u16, buf_tmr_irq, 1); |
| 4301 | |
| 4302 | flags = RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_TIMER_RESET; |
| 4303 | bnxt_hwrm_set_coal_params(bp, max_buf_irq << 16 | max_buf, |
| 4304 | buf_tmr_irq << 16 | buf_tmr, flags, &req_tx); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4305 | |
| 4306 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4307 | for (i = 0; i < bp->cp_nr_rings; i++) { |
Michael Chan | dfc9c94 | 2016-02-26 04:00:03 -0500 | [diff] [blame] | 4308 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4309 | |
Michael Chan | dfc9c94 | 2016-02-26 04:00:03 -0500 | [diff] [blame] | 4310 | req = &req_rx; |
| 4311 | if (!bnapi->rx_ring) |
| 4312 | req = &req_tx; |
| 4313 | req->ring_id = cpu_to_le16(bp->grp_info[i].cp_fw_ring_id); |
| 4314 | |
| 4315 | rc = _hwrm_send_message(bp, req, sizeof(*req), |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4316 | HWRM_CMD_TIMEOUT); |
| 4317 | if (rc) |
| 4318 | break; |
| 4319 | } |
| 4320 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4321 | return rc; |
| 4322 | } |
| 4323 | |
| 4324 | static int bnxt_hwrm_stat_ctx_free(struct bnxt *bp) |
| 4325 | { |
| 4326 | int rc = 0, i; |
| 4327 | struct hwrm_stat_ctx_free_input req = {0}; |
| 4328 | |
| 4329 | if (!bp->bnapi) |
| 4330 | return 0; |
| 4331 | |
Prashant Sreedharan | 3e8060f | 2016-07-18 07:15:20 -0400 | [diff] [blame] | 4332 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 4333 | return 0; |
| 4334 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4335 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_STAT_CTX_FREE, -1, -1); |
| 4336 | |
| 4337 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4338 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 4339 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 4340 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 4341 | |
| 4342 | if (cpr->hw_stats_ctx_id != INVALID_STATS_CTX_ID) { |
| 4343 | req.stat_ctx_id = cpu_to_le32(cpr->hw_stats_ctx_id); |
| 4344 | |
| 4345 | rc = _hwrm_send_message(bp, &req, sizeof(req), |
| 4346 | HWRM_CMD_TIMEOUT); |
| 4347 | if (rc) |
| 4348 | break; |
| 4349 | |
| 4350 | cpr->hw_stats_ctx_id = INVALID_STATS_CTX_ID; |
| 4351 | } |
| 4352 | } |
| 4353 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4354 | return rc; |
| 4355 | } |
| 4356 | |
| 4357 | static int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp) |
| 4358 | { |
| 4359 | int rc = 0, i; |
| 4360 | struct hwrm_stat_ctx_alloc_input req = {0}; |
| 4361 | struct hwrm_stat_ctx_alloc_output *resp = bp->hwrm_cmd_resp_addr; |
| 4362 | |
Prashant Sreedharan | 3e8060f | 2016-07-18 07:15:20 -0400 | [diff] [blame] | 4363 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 4364 | return 0; |
| 4365 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4366 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_STAT_CTX_ALLOC, -1, -1); |
| 4367 | |
Michael Chan | 51f3078 | 2016-07-01 18:46:29 -0400 | [diff] [blame] | 4368 | req.update_period_ms = cpu_to_le32(bp->stats_coal_ticks / 1000); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4369 | |
| 4370 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4371 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 4372 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 4373 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 4374 | |
| 4375 | req.stats_dma_addr = cpu_to_le64(cpr->hw_stats_map); |
| 4376 | |
| 4377 | rc = _hwrm_send_message(bp, &req, sizeof(req), |
| 4378 | HWRM_CMD_TIMEOUT); |
| 4379 | if (rc) |
| 4380 | break; |
| 4381 | |
| 4382 | cpr->hw_stats_ctx_id = le32_to_cpu(resp->stat_ctx_id); |
| 4383 | |
| 4384 | bp->grp_info[i].fw_stats_ctx = cpr->hw_stats_ctx_id; |
| 4385 | } |
| 4386 | mutex_unlock(&bp->hwrm_cmd_lock); |
Pan Bian | 89aa844 | 2016-12-03 17:56:17 +0800 | [diff] [blame] | 4387 | return rc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4388 | } |
| 4389 | |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 4390 | static int bnxt_hwrm_func_qcfg(struct bnxt *bp) |
| 4391 | { |
| 4392 | struct hwrm_func_qcfg_input req = {0}; |
Satish Baddipadige | 567b2ab | 2016-06-13 02:25:31 -0400 | [diff] [blame] | 4393 | struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr; |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 4394 | int rc; |
| 4395 | |
| 4396 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCFG, -1, -1); |
| 4397 | req.fid = cpu_to_le16(0xffff); |
| 4398 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4399 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4400 | if (rc) |
| 4401 | goto func_qcfg_exit; |
| 4402 | |
| 4403 | #ifdef CONFIG_BNXT_SRIOV |
| 4404 | if (BNXT_VF(bp)) { |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 4405 | struct bnxt_vf_info *vf = &bp->vf; |
| 4406 | |
| 4407 | vf->vlan = le16_to_cpu(resp->vlan) & VLAN_VID_MASK; |
| 4408 | } |
| 4409 | #endif |
Satish Baddipadige | 567b2ab | 2016-06-13 02:25:31 -0400 | [diff] [blame] | 4410 | switch (resp->port_partition_type) { |
| 4411 | case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_0: |
| 4412 | case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_5: |
| 4413 | case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR2_0: |
| 4414 | bp->port_partition_type = resp->port_partition_type; |
| 4415 | break; |
| 4416 | } |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 4417 | |
| 4418 | func_qcfg_exit: |
| 4419 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4420 | return rc; |
| 4421 | } |
| 4422 | |
Michael Chan | 7b08f66 | 2016-12-07 00:26:18 -0500 | [diff] [blame] | 4423 | static int bnxt_hwrm_func_qcaps(struct bnxt *bp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4424 | { |
| 4425 | int rc = 0; |
| 4426 | struct hwrm_func_qcaps_input req = {0}; |
| 4427 | struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr; |
| 4428 | |
| 4429 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCAPS, -1, -1); |
| 4430 | req.fid = cpu_to_le16(0xffff); |
| 4431 | |
| 4432 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4433 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4434 | if (rc) |
| 4435 | goto hwrm_func_qcaps_exit; |
| 4436 | |
Michael Chan | e4060d3 | 2016-12-07 00:26:19 -0500 | [diff] [blame] | 4437 | if (resp->flags & cpu_to_le32(FUNC_QCAPS_RESP_FLAGS_ROCE_V1_SUPPORTED)) |
| 4438 | bp->flags |= BNXT_FLAG_ROCEV1_CAP; |
| 4439 | if (resp->flags & cpu_to_le32(FUNC_QCAPS_RESP_FLAGS_ROCE_V2_SUPPORTED)) |
| 4440 | bp->flags |= BNXT_FLAG_ROCEV2_CAP; |
| 4441 | |
Michael Chan | 7cc5a20 | 2016-09-19 03:58:05 -0400 | [diff] [blame] | 4442 | bp->tx_push_thresh = 0; |
| 4443 | if (resp->flags & |
| 4444 | cpu_to_le32(FUNC_QCAPS_RESP_FLAGS_PUSH_MODE_SUPPORTED)) |
| 4445 | bp->tx_push_thresh = BNXT_TX_PUSH_THRESH; |
| 4446 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4447 | if (BNXT_PF(bp)) { |
| 4448 | struct bnxt_pf_info *pf = &bp->pf; |
| 4449 | |
| 4450 | pf->fw_fid = le16_to_cpu(resp->fid); |
| 4451 | pf->port_id = le16_to_cpu(resp->port_id); |
Michael Chan | 87027db | 2016-07-01 18:46:28 -0400 | [diff] [blame] | 4452 | bp->dev->dev_port = pf->port_id; |
Michael Chan | 11f15ed | 2016-04-05 14:08:55 -0400 | [diff] [blame] | 4453 | memcpy(pf->mac_addr, resp->mac_address, ETH_ALEN); |
Jeffrey Huang | bdd4347 | 2015-12-02 01:54:07 -0500 | [diff] [blame] | 4454 | memcpy(bp->dev->dev_addr, pf->mac_addr, ETH_ALEN); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4455 | pf->max_rsscos_ctxs = le16_to_cpu(resp->max_rsscos_ctx); |
| 4456 | pf->max_cp_rings = le16_to_cpu(resp->max_cmpl_rings); |
| 4457 | pf->max_tx_rings = le16_to_cpu(resp->max_tx_rings); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4458 | pf->max_rx_rings = le16_to_cpu(resp->max_rx_rings); |
Michael Chan | b72d4a6 | 2015-12-27 18:19:27 -0500 | [diff] [blame] | 4459 | pf->max_hw_ring_grps = le32_to_cpu(resp->max_hw_ring_grps); |
| 4460 | if (!pf->max_hw_ring_grps) |
| 4461 | pf->max_hw_ring_grps = pf->max_tx_rings; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4462 | pf->max_l2_ctxs = le16_to_cpu(resp->max_l2_ctxs); |
| 4463 | pf->max_vnics = le16_to_cpu(resp->max_vnics); |
| 4464 | pf->max_stat_ctxs = le16_to_cpu(resp->max_stat_ctx); |
| 4465 | pf->first_vf_id = le16_to_cpu(resp->first_vf_id); |
| 4466 | pf->max_vfs = le16_to_cpu(resp->max_vfs); |
| 4467 | pf->max_encap_records = le32_to_cpu(resp->max_encap_records); |
| 4468 | pf->max_decap_records = le32_to_cpu(resp->max_decap_records); |
| 4469 | pf->max_tx_em_flows = le32_to_cpu(resp->max_tx_em_flows); |
| 4470 | pf->max_tx_wm_flows = le32_to_cpu(resp->max_tx_wm_flows); |
| 4471 | pf->max_rx_em_flows = le32_to_cpu(resp->max_rx_em_flows); |
| 4472 | pf->max_rx_wm_flows = le32_to_cpu(resp->max_rx_wm_flows); |
| 4473 | } else { |
Michael Chan | 379a80a | 2015-10-23 15:06:19 -0400 | [diff] [blame] | 4474 | #ifdef CONFIG_BNXT_SRIOV |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4475 | struct bnxt_vf_info *vf = &bp->vf; |
| 4476 | |
| 4477 | vf->fw_fid = le16_to_cpu(resp->fid); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4478 | |
| 4479 | vf->max_rsscos_ctxs = le16_to_cpu(resp->max_rsscos_ctx); |
| 4480 | vf->max_cp_rings = le16_to_cpu(resp->max_cmpl_rings); |
| 4481 | vf->max_tx_rings = le16_to_cpu(resp->max_tx_rings); |
| 4482 | vf->max_rx_rings = le16_to_cpu(resp->max_rx_rings); |
Michael Chan | b72d4a6 | 2015-12-27 18:19:27 -0500 | [diff] [blame] | 4483 | vf->max_hw_ring_grps = le32_to_cpu(resp->max_hw_ring_grps); |
| 4484 | if (!vf->max_hw_ring_grps) |
| 4485 | vf->max_hw_ring_grps = vf->max_tx_rings; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4486 | vf->max_l2_ctxs = le16_to_cpu(resp->max_l2_ctxs); |
| 4487 | vf->max_vnics = le16_to_cpu(resp->max_vnics); |
| 4488 | vf->max_stat_ctxs = le16_to_cpu(resp->max_stat_ctx); |
Michael Chan | 7cc5a20 | 2016-09-19 03:58:05 -0400 | [diff] [blame] | 4489 | |
| 4490 | memcpy(vf->mac_addr, resp->mac_address, ETH_ALEN); |
Michael Chan | 001154e | 2016-09-19 03:58:06 -0400 | [diff] [blame] | 4491 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4492 | |
| 4493 | if (is_valid_ether_addr(vf->mac_addr)) { |
Michael Chan | 7cc5a20 | 2016-09-19 03:58:05 -0400 | [diff] [blame] | 4494 | /* overwrite netdev dev_adr with admin VF MAC */ |
| 4495 | memcpy(bp->dev->dev_addr, vf->mac_addr, ETH_ALEN); |
Michael Chan | 001154e | 2016-09-19 03:58:06 -0400 | [diff] [blame] | 4496 | } else { |
Michael Chan | 7cc5a20 | 2016-09-19 03:58:05 -0400 | [diff] [blame] | 4497 | random_ether_addr(bp->dev->dev_addr); |
Michael Chan | 001154e | 2016-09-19 03:58:06 -0400 | [diff] [blame] | 4498 | rc = bnxt_approve_mac(bp, bp->dev->dev_addr); |
| 4499 | } |
| 4500 | return rc; |
Michael Chan | 379a80a | 2015-10-23 15:06:19 -0400 | [diff] [blame] | 4501 | #endif |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4502 | } |
| 4503 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4504 | hwrm_func_qcaps_exit: |
| 4505 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4506 | return rc; |
| 4507 | } |
| 4508 | |
| 4509 | static int bnxt_hwrm_func_reset(struct bnxt *bp) |
| 4510 | { |
| 4511 | struct hwrm_func_reset_input req = {0}; |
| 4512 | |
| 4513 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_RESET, -1, -1); |
| 4514 | req.enables = 0; |
| 4515 | |
| 4516 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_RESET_TIMEOUT); |
| 4517 | } |
| 4518 | |
| 4519 | static int bnxt_hwrm_queue_qportcfg(struct bnxt *bp) |
| 4520 | { |
| 4521 | int rc = 0; |
| 4522 | struct hwrm_queue_qportcfg_input req = {0}; |
| 4523 | struct hwrm_queue_qportcfg_output *resp = bp->hwrm_cmd_resp_addr; |
| 4524 | u8 i, *qptr; |
| 4525 | |
| 4526 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_QUEUE_QPORTCFG, -1, -1); |
| 4527 | |
| 4528 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4529 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4530 | if (rc) |
| 4531 | goto qportcfg_exit; |
| 4532 | |
| 4533 | if (!resp->max_configurable_queues) { |
| 4534 | rc = -EINVAL; |
| 4535 | goto qportcfg_exit; |
| 4536 | } |
| 4537 | bp->max_tc = resp->max_configurable_queues; |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 4538 | bp->max_lltc = resp->max_configurable_lossless_queues; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4539 | if (bp->max_tc > BNXT_MAX_QUEUE) |
| 4540 | bp->max_tc = BNXT_MAX_QUEUE; |
| 4541 | |
Michael Chan | 441cabb | 2016-09-19 03:58:02 -0400 | [diff] [blame] | 4542 | if (resp->queue_cfg_info & QUEUE_QPORTCFG_RESP_QUEUE_CFG_INFO_ASYM_CFG) |
| 4543 | bp->max_tc = 1; |
| 4544 | |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 4545 | if (bp->max_lltc > bp->max_tc) |
| 4546 | bp->max_lltc = bp->max_tc; |
| 4547 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4548 | qptr = &resp->queue_id0; |
| 4549 | for (i = 0; i < bp->max_tc; i++) { |
| 4550 | bp->q_info[i].queue_id = *qptr++; |
| 4551 | bp->q_info[i].queue_profile = *qptr++; |
| 4552 | } |
| 4553 | |
| 4554 | qportcfg_exit: |
| 4555 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4556 | return rc; |
| 4557 | } |
| 4558 | |
| 4559 | static int bnxt_hwrm_ver_get(struct bnxt *bp) |
| 4560 | { |
| 4561 | int rc; |
| 4562 | struct hwrm_ver_get_input req = {0}; |
| 4563 | struct hwrm_ver_get_output *resp = bp->hwrm_cmd_resp_addr; |
| 4564 | |
Michael Chan | e6ef269 | 2016-03-28 19:46:05 -0400 | [diff] [blame] | 4565 | bp->hwrm_max_req_len = HWRM_MAX_REQ_LEN; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4566 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VER_GET, -1, -1); |
| 4567 | req.hwrm_intf_maj = HWRM_VERSION_MAJOR; |
| 4568 | req.hwrm_intf_min = HWRM_VERSION_MINOR; |
| 4569 | req.hwrm_intf_upd = HWRM_VERSION_UPDATE; |
| 4570 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4571 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4572 | if (rc) |
| 4573 | goto hwrm_ver_get_exit; |
| 4574 | |
| 4575 | memcpy(&bp->ver_resp, resp, sizeof(struct hwrm_ver_get_output)); |
| 4576 | |
Michael Chan | 11f15ed | 2016-04-05 14:08:55 -0400 | [diff] [blame] | 4577 | bp->hwrm_spec_code = resp->hwrm_intf_maj << 16 | |
| 4578 | resp->hwrm_intf_min << 8 | resp->hwrm_intf_upd; |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 4579 | if (resp->hwrm_intf_maj < 1) { |
| 4580 | 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] | 4581 | resp->hwrm_intf_maj, resp->hwrm_intf_min, |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 4582 | resp->hwrm_intf_upd); |
| 4583 | 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] | 4584 | } |
Rob Swindell | 3ebf6f0 | 2016-02-26 04:00:06 -0500 | [diff] [blame] | 4585 | 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] | 4586 | resp->hwrm_fw_maj, resp->hwrm_fw_min, resp->hwrm_fw_bld, |
| 4587 | resp->hwrm_intf_maj, resp->hwrm_intf_min, resp->hwrm_intf_upd); |
| 4588 | |
Michael Chan | ff4fe81 | 2016-02-26 04:00:04 -0500 | [diff] [blame] | 4589 | bp->hwrm_cmd_timeout = le16_to_cpu(resp->def_req_timeout); |
| 4590 | if (!bp->hwrm_cmd_timeout) |
| 4591 | bp->hwrm_cmd_timeout = DFLT_HWRM_CMD_TIMEOUT; |
| 4592 | |
Michael Chan | e6ef269 | 2016-03-28 19:46:05 -0400 | [diff] [blame] | 4593 | if (resp->hwrm_intf_maj >= 1) |
| 4594 | bp->hwrm_max_req_len = le16_to_cpu(resp->max_req_win_len); |
| 4595 | |
Michael Chan | 659c805 | 2016-06-13 02:25:33 -0400 | [diff] [blame] | 4596 | bp->chip_num = le16_to_cpu(resp->chip_num); |
Prashant Sreedharan | 3e8060f | 2016-07-18 07:15:20 -0400 | [diff] [blame] | 4597 | if (bp->chip_num == CHIP_NUM_58700 && !resp->chip_rev && |
| 4598 | !resp->chip_metal) |
| 4599 | bp->flags |= BNXT_FLAG_CHIP_NITRO_A0; |
Michael Chan | 659c805 | 2016-06-13 02:25:33 -0400 | [diff] [blame] | 4600 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4601 | hwrm_ver_get_exit: |
| 4602 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4603 | return rc; |
| 4604 | } |
| 4605 | |
Rob Swindell | 5ac67d8 | 2016-09-19 03:58:03 -0400 | [diff] [blame] | 4606 | int bnxt_hwrm_fw_set_time(struct bnxt *bp) |
| 4607 | { |
Rob Swindell | 878786d | 2016-09-20 03:36:33 -0400 | [diff] [blame] | 4608 | #if IS_ENABLED(CONFIG_RTC_LIB) |
Rob Swindell | 5ac67d8 | 2016-09-19 03:58:03 -0400 | [diff] [blame] | 4609 | struct hwrm_fw_set_time_input req = {0}; |
| 4610 | struct rtc_time tm; |
| 4611 | struct timeval tv; |
| 4612 | |
| 4613 | if (bp->hwrm_spec_code < 0x10400) |
| 4614 | return -EOPNOTSUPP; |
| 4615 | |
| 4616 | do_gettimeofday(&tv); |
| 4617 | rtc_time_to_tm(tv.tv_sec, &tm); |
| 4618 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_SET_TIME, -1, -1); |
| 4619 | req.year = cpu_to_le16(1900 + tm.tm_year); |
| 4620 | req.month = 1 + tm.tm_mon; |
| 4621 | req.day = tm.tm_mday; |
| 4622 | req.hour = tm.tm_hour; |
| 4623 | req.minute = tm.tm_min; |
| 4624 | req.second = tm.tm_sec; |
| 4625 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
Rob Swindell | 878786d | 2016-09-20 03:36:33 -0400 | [diff] [blame] | 4626 | #else |
| 4627 | return -EOPNOTSUPP; |
| 4628 | #endif |
Rob Swindell | 5ac67d8 | 2016-09-19 03:58:03 -0400 | [diff] [blame] | 4629 | } |
| 4630 | |
Michael Chan | 3bdf56c | 2016-03-07 15:38:45 -0500 | [diff] [blame] | 4631 | static int bnxt_hwrm_port_qstats(struct bnxt *bp) |
| 4632 | { |
| 4633 | int rc; |
| 4634 | struct bnxt_pf_info *pf = &bp->pf; |
| 4635 | struct hwrm_port_qstats_input req = {0}; |
| 4636 | |
| 4637 | if (!(bp->flags & BNXT_FLAG_PORT_STATS)) |
| 4638 | return 0; |
| 4639 | |
| 4640 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_QSTATS, -1, -1); |
| 4641 | req.port_id = cpu_to_le16(pf->port_id); |
| 4642 | req.tx_stat_host_addr = cpu_to_le64(bp->hw_tx_port_stats_map); |
| 4643 | req.rx_stat_host_addr = cpu_to_le64(bp->hw_rx_port_stats_map); |
| 4644 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4645 | return rc; |
| 4646 | } |
| 4647 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4648 | static void bnxt_hwrm_free_tunnel_ports(struct bnxt *bp) |
| 4649 | { |
| 4650 | if (bp->vxlan_port_cnt) { |
| 4651 | bnxt_hwrm_tunnel_dst_port_free( |
| 4652 | bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN); |
| 4653 | } |
| 4654 | bp->vxlan_port_cnt = 0; |
| 4655 | if (bp->nge_port_cnt) { |
| 4656 | bnxt_hwrm_tunnel_dst_port_free( |
| 4657 | bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE); |
| 4658 | } |
| 4659 | bp->nge_port_cnt = 0; |
| 4660 | } |
| 4661 | |
| 4662 | static int bnxt_set_tpa(struct bnxt *bp, bool set_tpa) |
| 4663 | { |
| 4664 | int rc, i; |
| 4665 | u32 tpa_flags = 0; |
| 4666 | |
| 4667 | if (set_tpa) |
| 4668 | tpa_flags = bp->flags & BNXT_FLAG_TPA; |
| 4669 | for (i = 0; i < bp->nr_vnics; i++) { |
| 4670 | rc = bnxt_hwrm_vnic_set_tpa(bp, i, tpa_flags); |
| 4671 | if (rc) { |
| 4672 | netdev_err(bp->dev, "hwrm vnic set tpa failure rc for vnic %d: %x\n", |
| 4673 | rc, i); |
| 4674 | return rc; |
| 4675 | } |
| 4676 | } |
| 4677 | return 0; |
| 4678 | } |
| 4679 | |
| 4680 | static void bnxt_hwrm_clear_vnic_rss(struct bnxt *bp) |
| 4681 | { |
| 4682 | int i; |
| 4683 | |
| 4684 | for (i = 0; i < bp->nr_vnics; i++) |
| 4685 | bnxt_hwrm_vnic_set_rss(bp, i, false); |
| 4686 | } |
| 4687 | |
| 4688 | static void bnxt_hwrm_resource_free(struct bnxt *bp, bool close_path, |
| 4689 | bool irq_re_init) |
| 4690 | { |
| 4691 | if (bp->vnic_info) { |
| 4692 | bnxt_hwrm_clear_vnic_filter(bp); |
| 4693 | /* clear all RSS setting before free vnic ctx */ |
| 4694 | bnxt_hwrm_clear_vnic_rss(bp); |
| 4695 | bnxt_hwrm_vnic_ctx_free(bp); |
| 4696 | /* before free the vnic, undo the vnic tpa settings */ |
| 4697 | if (bp->flags & BNXT_FLAG_TPA) |
| 4698 | bnxt_set_tpa(bp, false); |
| 4699 | bnxt_hwrm_vnic_free(bp); |
| 4700 | } |
| 4701 | bnxt_hwrm_ring_free(bp, close_path); |
| 4702 | bnxt_hwrm_ring_grp_free(bp); |
| 4703 | if (irq_re_init) { |
| 4704 | bnxt_hwrm_stat_ctx_free(bp); |
| 4705 | bnxt_hwrm_free_tunnel_ports(bp); |
| 4706 | } |
| 4707 | } |
| 4708 | |
| 4709 | static int bnxt_setup_vnic(struct bnxt *bp, u16 vnic_id) |
| 4710 | { |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 4711 | struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4712 | int rc; |
| 4713 | |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 4714 | if (vnic->flags & BNXT_VNIC_RFS_NEW_RSS_FLAG) |
| 4715 | goto skip_rss_ctx; |
| 4716 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4717 | /* allocate context for vnic */ |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 4718 | rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic_id, 0); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4719 | if (rc) { |
| 4720 | netdev_err(bp->dev, "hwrm vnic %d alloc failure rc: %x\n", |
| 4721 | vnic_id, rc); |
| 4722 | goto vnic_setup_err; |
| 4723 | } |
| 4724 | bp->rsscos_nr_ctxs++; |
| 4725 | |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 4726 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) { |
| 4727 | rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic_id, 1); |
| 4728 | if (rc) { |
| 4729 | netdev_err(bp->dev, "hwrm vnic %d cos ctx alloc failure rc: %x\n", |
| 4730 | vnic_id, rc); |
| 4731 | goto vnic_setup_err; |
| 4732 | } |
| 4733 | bp->rsscos_nr_ctxs++; |
| 4734 | } |
| 4735 | |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 4736 | skip_rss_ctx: |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4737 | /* configure default vnic, ring grp */ |
| 4738 | rc = bnxt_hwrm_vnic_cfg(bp, vnic_id); |
| 4739 | if (rc) { |
| 4740 | netdev_err(bp->dev, "hwrm vnic %d cfg failure rc: %x\n", |
| 4741 | vnic_id, rc); |
| 4742 | goto vnic_setup_err; |
| 4743 | } |
| 4744 | |
| 4745 | /* Enable RSS hashing on vnic */ |
| 4746 | rc = bnxt_hwrm_vnic_set_rss(bp, vnic_id, true); |
| 4747 | if (rc) { |
| 4748 | netdev_err(bp->dev, "hwrm vnic %d set rss failure rc: %x\n", |
| 4749 | vnic_id, rc); |
| 4750 | goto vnic_setup_err; |
| 4751 | } |
| 4752 | |
| 4753 | if (bp->flags & BNXT_FLAG_AGG_RINGS) { |
| 4754 | rc = bnxt_hwrm_vnic_set_hds(bp, vnic_id); |
| 4755 | if (rc) { |
| 4756 | netdev_err(bp->dev, "hwrm vnic %d set hds failure rc: %x\n", |
| 4757 | vnic_id, rc); |
| 4758 | } |
| 4759 | } |
| 4760 | |
| 4761 | vnic_setup_err: |
| 4762 | return rc; |
| 4763 | } |
| 4764 | |
| 4765 | static int bnxt_alloc_rfs_vnics(struct bnxt *bp) |
| 4766 | { |
| 4767 | #ifdef CONFIG_RFS_ACCEL |
| 4768 | int i, rc = 0; |
| 4769 | |
| 4770 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 4771 | struct bnxt_vnic_info *vnic; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4772 | u16 vnic_id = i + 1; |
| 4773 | u16 ring_id = i; |
| 4774 | |
| 4775 | if (vnic_id >= bp->nr_vnics) |
| 4776 | break; |
| 4777 | |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 4778 | vnic = &bp->vnic_info[vnic_id]; |
| 4779 | vnic->flags |= BNXT_VNIC_RFS_FLAG; |
| 4780 | if (bp->flags & BNXT_FLAG_NEW_RSS_CAP) |
| 4781 | vnic->flags |= BNXT_VNIC_RFS_NEW_RSS_FLAG; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4782 | rc = bnxt_hwrm_vnic_alloc(bp, vnic_id, ring_id, 1); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4783 | if (rc) { |
| 4784 | netdev_err(bp->dev, "hwrm vnic %d alloc failure rc: %x\n", |
| 4785 | vnic_id, rc); |
| 4786 | break; |
| 4787 | } |
| 4788 | rc = bnxt_setup_vnic(bp, vnic_id); |
| 4789 | if (rc) |
| 4790 | break; |
| 4791 | } |
| 4792 | return rc; |
| 4793 | #else |
| 4794 | return 0; |
| 4795 | #endif |
| 4796 | } |
| 4797 | |
Michael Chan | 17c71ac | 2016-07-01 18:46:27 -0400 | [diff] [blame] | 4798 | /* Allow PF and VF with default VLAN to be in promiscuous mode */ |
| 4799 | static bool bnxt_promisc_ok(struct bnxt *bp) |
| 4800 | { |
| 4801 | #ifdef CONFIG_BNXT_SRIOV |
| 4802 | if (BNXT_VF(bp) && !bp->vf.vlan) |
| 4803 | return false; |
| 4804 | #endif |
| 4805 | return true; |
| 4806 | } |
| 4807 | |
Prashant Sreedharan | dc52c6c | 2016-07-18 07:15:24 -0400 | [diff] [blame] | 4808 | static int bnxt_setup_nitroa0_vnic(struct bnxt *bp) |
| 4809 | { |
| 4810 | unsigned int rc = 0; |
| 4811 | |
| 4812 | rc = bnxt_hwrm_vnic_alloc(bp, 1, bp->rx_nr_rings - 1, 1); |
| 4813 | if (rc) { |
| 4814 | netdev_err(bp->dev, "Cannot allocate special vnic for NS2 A0: %x\n", |
| 4815 | rc); |
| 4816 | return rc; |
| 4817 | } |
| 4818 | |
| 4819 | rc = bnxt_hwrm_vnic_cfg(bp, 1); |
| 4820 | if (rc) { |
| 4821 | netdev_err(bp->dev, "Cannot allocate special vnic for NS2 A0: %x\n", |
| 4822 | rc); |
| 4823 | return rc; |
| 4824 | } |
| 4825 | return rc; |
| 4826 | } |
| 4827 | |
Michael Chan | b664f00 | 2015-12-02 01:54:08 -0500 | [diff] [blame] | 4828 | static int bnxt_cfg_rx_mode(struct bnxt *); |
Michael Chan | 7d2837d | 2016-05-04 16:56:44 -0400 | [diff] [blame] | 4829 | static bool bnxt_mc_list_updated(struct bnxt *, u32 *); |
Michael Chan | b664f00 | 2015-12-02 01:54:08 -0500 | [diff] [blame] | 4830 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4831 | static int bnxt_init_chip(struct bnxt *bp, bool irq_re_init) |
| 4832 | { |
Michael Chan | 7d2837d | 2016-05-04 16:56:44 -0400 | [diff] [blame] | 4833 | struct bnxt_vnic_info *vnic = &bp->vnic_info[0]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4834 | int rc = 0; |
Prashant Sreedharan | 7659519 | 2016-07-18 07:15:22 -0400 | [diff] [blame] | 4835 | unsigned int rx_nr_rings = bp->rx_nr_rings; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4836 | |
| 4837 | if (irq_re_init) { |
| 4838 | rc = bnxt_hwrm_stat_ctx_alloc(bp); |
| 4839 | if (rc) { |
| 4840 | netdev_err(bp->dev, "hwrm stat ctx alloc failure rc: %x\n", |
| 4841 | rc); |
| 4842 | goto err_out; |
| 4843 | } |
| 4844 | } |
| 4845 | |
| 4846 | rc = bnxt_hwrm_ring_alloc(bp); |
| 4847 | if (rc) { |
| 4848 | netdev_err(bp->dev, "hwrm ring alloc failure rc: %x\n", rc); |
| 4849 | goto err_out; |
| 4850 | } |
| 4851 | |
| 4852 | rc = bnxt_hwrm_ring_grp_alloc(bp); |
| 4853 | if (rc) { |
| 4854 | netdev_err(bp->dev, "hwrm_ring_grp alloc failure: %x\n", rc); |
| 4855 | goto err_out; |
| 4856 | } |
| 4857 | |
Prashant Sreedharan | 7659519 | 2016-07-18 07:15:22 -0400 | [diff] [blame] | 4858 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 4859 | rx_nr_rings--; |
| 4860 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4861 | /* default vnic 0 */ |
Prashant Sreedharan | 7659519 | 2016-07-18 07:15:22 -0400 | [diff] [blame] | 4862 | rc = bnxt_hwrm_vnic_alloc(bp, 0, 0, rx_nr_rings); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4863 | if (rc) { |
| 4864 | netdev_err(bp->dev, "hwrm vnic alloc failure rc: %x\n", rc); |
| 4865 | goto err_out; |
| 4866 | } |
| 4867 | |
| 4868 | rc = bnxt_setup_vnic(bp, 0); |
| 4869 | if (rc) |
| 4870 | goto err_out; |
| 4871 | |
| 4872 | if (bp->flags & BNXT_FLAG_RFS) { |
| 4873 | rc = bnxt_alloc_rfs_vnics(bp); |
| 4874 | if (rc) |
| 4875 | goto err_out; |
| 4876 | } |
| 4877 | |
| 4878 | if (bp->flags & BNXT_FLAG_TPA) { |
| 4879 | rc = bnxt_set_tpa(bp, true); |
| 4880 | if (rc) |
| 4881 | goto err_out; |
| 4882 | } |
| 4883 | |
| 4884 | if (BNXT_VF(bp)) |
| 4885 | bnxt_update_vf_mac(bp); |
| 4886 | |
| 4887 | /* Filter for default vnic 0 */ |
| 4888 | rc = bnxt_hwrm_set_vnic_filter(bp, 0, 0, bp->dev->dev_addr); |
| 4889 | if (rc) { |
| 4890 | netdev_err(bp->dev, "HWRM vnic filter failure rc: %x\n", rc); |
| 4891 | goto err_out; |
| 4892 | } |
Michael Chan | 7d2837d | 2016-05-04 16:56:44 -0400 | [diff] [blame] | 4893 | vnic->uc_filter_count = 1; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4894 | |
Michael Chan | 7d2837d | 2016-05-04 16:56:44 -0400 | [diff] [blame] | 4895 | vnic->rx_mask = CFA_L2_SET_RX_MASK_REQ_MASK_BCAST; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4896 | |
Michael Chan | 17c71ac | 2016-07-01 18:46:27 -0400 | [diff] [blame] | 4897 | if ((bp->dev->flags & IFF_PROMISC) && bnxt_promisc_ok(bp)) |
Michael Chan | 7d2837d | 2016-05-04 16:56:44 -0400 | [diff] [blame] | 4898 | vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS; |
| 4899 | |
| 4900 | if (bp->dev->flags & IFF_ALLMULTI) { |
| 4901 | vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST; |
| 4902 | vnic->mc_list_count = 0; |
| 4903 | } else { |
| 4904 | u32 mask = 0; |
| 4905 | |
| 4906 | bnxt_mc_list_updated(bp, &mask); |
| 4907 | vnic->rx_mask |= mask; |
| 4908 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4909 | |
Michael Chan | b664f00 | 2015-12-02 01:54:08 -0500 | [diff] [blame] | 4910 | rc = bnxt_cfg_rx_mode(bp); |
| 4911 | if (rc) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4912 | goto err_out; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4913 | |
| 4914 | rc = bnxt_hwrm_set_coal(bp); |
| 4915 | if (rc) |
| 4916 | netdev_warn(bp->dev, "HWRM set coalescing failure rc: %x\n", |
Prashant Sreedharan | dc52c6c | 2016-07-18 07:15:24 -0400 | [diff] [blame] | 4917 | rc); |
| 4918 | |
| 4919 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) { |
| 4920 | rc = bnxt_setup_nitroa0_vnic(bp); |
| 4921 | if (rc) |
| 4922 | netdev_err(bp->dev, "Special vnic setup failure for NS2 A0 rc: %x\n", |
| 4923 | rc); |
| 4924 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4925 | |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 4926 | if (BNXT_VF(bp)) { |
| 4927 | bnxt_hwrm_func_qcfg(bp); |
| 4928 | netdev_update_features(bp->dev); |
| 4929 | } |
| 4930 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4931 | return 0; |
| 4932 | |
| 4933 | err_out: |
| 4934 | bnxt_hwrm_resource_free(bp, 0, true); |
| 4935 | |
| 4936 | return rc; |
| 4937 | } |
| 4938 | |
| 4939 | static int bnxt_shutdown_nic(struct bnxt *bp, bool irq_re_init) |
| 4940 | { |
| 4941 | bnxt_hwrm_resource_free(bp, 1, irq_re_init); |
| 4942 | return 0; |
| 4943 | } |
| 4944 | |
| 4945 | static int bnxt_init_nic(struct bnxt *bp, bool irq_re_init) |
| 4946 | { |
| 4947 | bnxt_init_rx_rings(bp); |
| 4948 | bnxt_init_tx_rings(bp); |
| 4949 | bnxt_init_ring_grps(bp, irq_re_init); |
| 4950 | bnxt_init_vnics(bp); |
| 4951 | |
| 4952 | return bnxt_init_chip(bp, irq_re_init); |
| 4953 | } |
| 4954 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4955 | static int bnxt_set_real_num_queues(struct bnxt *bp) |
| 4956 | { |
| 4957 | int rc; |
| 4958 | struct net_device *dev = bp->dev; |
| 4959 | |
| 4960 | rc = netif_set_real_num_tx_queues(dev, bp->tx_nr_rings); |
| 4961 | if (rc) |
| 4962 | return rc; |
| 4963 | |
| 4964 | rc = netif_set_real_num_rx_queues(dev, bp->rx_nr_rings); |
| 4965 | if (rc) |
| 4966 | return rc; |
| 4967 | |
| 4968 | #ifdef CONFIG_RFS_ACCEL |
Michael Chan | 45019a1 | 2015-12-27 18:19:22 -0500 | [diff] [blame] | 4969 | if (bp->flags & BNXT_FLAG_RFS) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4970 | dev->rx_cpu_rmap = alloc_irq_cpu_rmap(bp->rx_nr_rings); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4971 | #endif |
| 4972 | |
| 4973 | return rc; |
| 4974 | } |
| 4975 | |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 4976 | static int bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max, |
| 4977 | bool shared) |
| 4978 | { |
| 4979 | int _rx = *rx, _tx = *tx; |
| 4980 | |
| 4981 | if (shared) { |
| 4982 | *rx = min_t(int, _rx, max); |
| 4983 | *tx = min_t(int, _tx, max); |
| 4984 | } else { |
| 4985 | if (max < 2) |
| 4986 | return -ENOMEM; |
| 4987 | |
| 4988 | while (_rx + _tx > max) { |
| 4989 | if (_rx > _tx && _rx > 1) |
| 4990 | _rx--; |
| 4991 | else if (_tx > 1) |
| 4992 | _tx--; |
| 4993 | } |
| 4994 | *rx = _rx; |
| 4995 | *tx = _tx; |
| 4996 | } |
| 4997 | return 0; |
| 4998 | } |
| 4999 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5000 | static void bnxt_setup_msix(struct bnxt *bp) |
| 5001 | { |
| 5002 | const int len = sizeof(bp->irq_tbl[0].name); |
| 5003 | struct net_device *dev = bp->dev; |
| 5004 | int tcs, i; |
| 5005 | |
| 5006 | tcs = netdev_get_num_tc(dev); |
| 5007 | if (tcs > 1) { |
| 5008 | bp->tx_nr_rings_per_tc = bp->tx_nr_rings / tcs; |
| 5009 | if (bp->tx_nr_rings_per_tc == 0) { |
| 5010 | netdev_reset_tc(dev); |
| 5011 | bp->tx_nr_rings_per_tc = bp->tx_nr_rings; |
| 5012 | } else { |
| 5013 | int i, off, count; |
| 5014 | |
| 5015 | bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tcs; |
| 5016 | for (i = 0; i < tcs; i++) { |
| 5017 | count = bp->tx_nr_rings_per_tc; |
| 5018 | off = i * count; |
| 5019 | netdev_set_tc_queue(dev, i, count, off); |
| 5020 | } |
| 5021 | } |
| 5022 | } |
| 5023 | |
| 5024 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 5025 | char *attr; |
| 5026 | |
| 5027 | if (bp->flags & BNXT_FLAG_SHARED_RINGS) |
| 5028 | attr = "TxRx"; |
| 5029 | else if (i < bp->rx_nr_rings) |
| 5030 | attr = "rx"; |
| 5031 | else |
| 5032 | attr = "tx"; |
| 5033 | |
| 5034 | snprintf(bp->irq_tbl[i].name, len, "%s-%s-%d", dev->name, attr, |
| 5035 | i); |
| 5036 | bp->irq_tbl[i].handler = bnxt_msix; |
| 5037 | } |
| 5038 | } |
| 5039 | |
| 5040 | static void bnxt_setup_inta(struct bnxt *bp) |
| 5041 | { |
| 5042 | const int len = sizeof(bp->irq_tbl[0].name); |
| 5043 | |
| 5044 | if (netdev_get_num_tc(bp->dev)) |
| 5045 | netdev_reset_tc(bp->dev); |
| 5046 | |
| 5047 | snprintf(bp->irq_tbl[0].name, len, "%s-%s-%d", bp->dev->name, "TxRx", |
| 5048 | 0); |
| 5049 | bp->irq_tbl[0].handler = bnxt_inta; |
| 5050 | } |
| 5051 | |
| 5052 | static int bnxt_setup_int_mode(struct bnxt *bp) |
| 5053 | { |
| 5054 | int rc; |
| 5055 | |
| 5056 | if (bp->flags & BNXT_FLAG_USING_MSIX) |
| 5057 | bnxt_setup_msix(bp); |
| 5058 | else |
| 5059 | bnxt_setup_inta(bp); |
| 5060 | |
| 5061 | rc = bnxt_set_real_num_queues(bp); |
| 5062 | return rc; |
| 5063 | } |
| 5064 | |
Michael Chan | b742995 | 2017-01-13 01:32:00 -0500 | [diff] [blame] | 5065 | #ifdef CONFIG_RFS_ACCEL |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 5066 | static unsigned int bnxt_get_max_func_rss_ctxs(struct bnxt *bp) |
| 5067 | { |
| 5068 | #if defined(CONFIG_BNXT_SRIOV) |
| 5069 | if (BNXT_VF(bp)) |
| 5070 | return bp->vf.max_rsscos_ctxs; |
| 5071 | #endif |
| 5072 | return bp->pf.max_rsscos_ctxs; |
| 5073 | } |
| 5074 | |
| 5075 | static unsigned int bnxt_get_max_func_vnics(struct bnxt *bp) |
| 5076 | { |
| 5077 | #if defined(CONFIG_BNXT_SRIOV) |
| 5078 | if (BNXT_VF(bp)) |
| 5079 | return bp->vf.max_vnics; |
| 5080 | #endif |
| 5081 | return bp->pf.max_vnics; |
| 5082 | } |
Michael Chan | b742995 | 2017-01-13 01:32:00 -0500 | [diff] [blame] | 5083 | #endif |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 5084 | |
Michael Chan | e4060d3 | 2016-12-07 00:26:19 -0500 | [diff] [blame] | 5085 | unsigned int bnxt_get_max_func_stat_ctxs(struct bnxt *bp) |
| 5086 | { |
| 5087 | #if defined(CONFIG_BNXT_SRIOV) |
| 5088 | if (BNXT_VF(bp)) |
| 5089 | return bp->vf.max_stat_ctxs; |
| 5090 | #endif |
| 5091 | return bp->pf.max_stat_ctxs; |
| 5092 | } |
| 5093 | |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 5094 | void bnxt_set_max_func_stat_ctxs(struct bnxt *bp, unsigned int max) |
| 5095 | { |
| 5096 | #if defined(CONFIG_BNXT_SRIOV) |
| 5097 | if (BNXT_VF(bp)) |
| 5098 | bp->vf.max_stat_ctxs = max; |
| 5099 | else |
| 5100 | #endif |
| 5101 | bp->pf.max_stat_ctxs = max; |
| 5102 | } |
| 5103 | |
Michael Chan | e4060d3 | 2016-12-07 00:26:19 -0500 | [diff] [blame] | 5104 | unsigned int bnxt_get_max_func_cp_rings(struct bnxt *bp) |
| 5105 | { |
| 5106 | #if defined(CONFIG_BNXT_SRIOV) |
| 5107 | if (BNXT_VF(bp)) |
| 5108 | return bp->vf.max_cp_rings; |
| 5109 | #endif |
| 5110 | return bp->pf.max_cp_rings; |
| 5111 | } |
| 5112 | |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 5113 | void bnxt_set_max_func_cp_rings(struct bnxt *bp, unsigned int max) |
| 5114 | { |
| 5115 | #if defined(CONFIG_BNXT_SRIOV) |
| 5116 | if (BNXT_VF(bp)) |
| 5117 | bp->vf.max_cp_rings = max; |
| 5118 | else |
| 5119 | #endif |
| 5120 | bp->pf.max_cp_rings = max; |
| 5121 | } |
| 5122 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5123 | static unsigned int bnxt_get_max_func_irqs(struct bnxt *bp) |
| 5124 | { |
| 5125 | #if defined(CONFIG_BNXT_SRIOV) |
| 5126 | if (BNXT_VF(bp)) |
| 5127 | return bp->vf.max_irqs; |
| 5128 | #endif |
| 5129 | return bp->pf.max_irqs; |
| 5130 | } |
| 5131 | |
Michael Chan | 33c2657 | 2016-12-07 00:26:15 -0500 | [diff] [blame] | 5132 | void bnxt_set_max_func_irqs(struct bnxt *bp, unsigned int max_irqs) |
| 5133 | { |
| 5134 | #if defined(CONFIG_BNXT_SRIOV) |
| 5135 | if (BNXT_VF(bp)) |
| 5136 | bp->vf.max_irqs = max_irqs; |
| 5137 | else |
| 5138 | #endif |
| 5139 | bp->pf.max_irqs = max_irqs; |
| 5140 | } |
| 5141 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5142 | static int bnxt_init_msix(struct bnxt *bp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5143 | { |
Michael Chan | 01657bc | 2016-01-02 23:45:03 -0500 | [diff] [blame] | 5144 | int i, total_vecs, rc = 0, min = 1; |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5145 | struct msix_entry *msix_ent; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5146 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5147 | total_vecs = bnxt_get_max_func_irqs(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5148 | msix_ent = kcalloc(total_vecs, sizeof(struct msix_entry), GFP_KERNEL); |
| 5149 | if (!msix_ent) |
| 5150 | return -ENOMEM; |
| 5151 | |
| 5152 | for (i = 0; i < total_vecs; i++) { |
| 5153 | msix_ent[i].entry = i; |
| 5154 | msix_ent[i].vector = 0; |
| 5155 | } |
| 5156 | |
Michael Chan | 01657bc | 2016-01-02 23:45:03 -0500 | [diff] [blame] | 5157 | if (!(bp->flags & BNXT_FLAG_SHARED_RINGS)) |
| 5158 | min = 2; |
| 5159 | |
| 5160 | 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] | 5161 | if (total_vecs < 0) { |
| 5162 | rc = -ENODEV; |
| 5163 | goto msix_setup_exit; |
| 5164 | } |
| 5165 | |
| 5166 | bp->irq_tbl = kcalloc(total_vecs, sizeof(struct bnxt_irq), GFP_KERNEL); |
| 5167 | if (bp->irq_tbl) { |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5168 | for (i = 0; i < total_vecs; i++) |
| 5169 | bp->irq_tbl[i].vector = msix_ent[i].vector; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5170 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5171 | bp->total_irqs = total_vecs; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5172 | /* Trim rings based upon num of vectors allocated */ |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 5173 | 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] | 5174 | total_vecs, min == 1); |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 5175 | if (rc) |
| 5176 | goto msix_setup_exit; |
| 5177 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5178 | bp->tx_nr_rings_per_tc = bp->tx_nr_rings; |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5179 | bp->cp_nr_rings = (min == 1) ? |
| 5180 | max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) : |
| 5181 | bp->tx_nr_rings + bp->rx_nr_rings; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5182 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5183 | } else { |
| 5184 | rc = -ENOMEM; |
| 5185 | goto msix_setup_exit; |
| 5186 | } |
| 5187 | bp->flags |= BNXT_FLAG_USING_MSIX; |
| 5188 | kfree(msix_ent); |
| 5189 | return 0; |
| 5190 | |
| 5191 | msix_setup_exit: |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5192 | netdev_err(bp->dev, "bnxt_init_msix err: %x\n", rc); |
| 5193 | kfree(bp->irq_tbl); |
| 5194 | bp->irq_tbl = NULL; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5195 | pci_disable_msix(bp->pdev); |
| 5196 | kfree(msix_ent); |
| 5197 | return rc; |
| 5198 | } |
| 5199 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5200 | static int bnxt_init_inta(struct bnxt *bp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5201 | { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5202 | bp->irq_tbl = kcalloc(1, sizeof(struct bnxt_irq), GFP_KERNEL); |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5203 | if (!bp->irq_tbl) |
| 5204 | return -ENOMEM; |
| 5205 | |
| 5206 | bp->total_irqs = 1; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5207 | bp->rx_nr_rings = 1; |
| 5208 | bp->tx_nr_rings = 1; |
| 5209 | bp->cp_nr_rings = 1; |
| 5210 | bp->tx_nr_rings_per_tc = bp->tx_nr_rings; |
Michael Chan | 01657bc | 2016-01-02 23:45:03 -0500 | [diff] [blame] | 5211 | bp->flags |= BNXT_FLAG_SHARED_RINGS; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5212 | bp->irq_tbl[0].vector = bp->pdev->irq; |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5213 | return 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5214 | } |
| 5215 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5216 | static int bnxt_init_int_mode(struct bnxt *bp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5217 | { |
| 5218 | int rc = 0; |
| 5219 | |
| 5220 | if (bp->flags & BNXT_FLAG_MSIX_CAP) |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5221 | rc = bnxt_init_msix(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5222 | |
Michael Chan | 1fa72e2 | 2016-04-25 02:30:49 -0400 | [diff] [blame] | 5223 | if (!(bp->flags & BNXT_FLAG_USING_MSIX) && BNXT_PF(bp)) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5224 | /* fallback to INTA */ |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5225 | rc = bnxt_init_inta(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5226 | } |
| 5227 | return rc; |
| 5228 | } |
| 5229 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5230 | static void bnxt_clear_int_mode(struct bnxt *bp) |
| 5231 | { |
| 5232 | if (bp->flags & BNXT_FLAG_USING_MSIX) |
| 5233 | pci_disable_msix(bp->pdev); |
| 5234 | |
| 5235 | kfree(bp->irq_tbl); |
| 5236 | bp->irq_tbl = NULL; |
| 5237 | bp->flags &= ~BNXT_FLAG_USING_MSIX; |
| 5238 | } |
| 5239 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5240 | static void bnxt_free_irq(struct bnxt *bp) |
| 5241 | { |
| 5242 | struct bnxt_irq *irq; |
| 5243 | int i; |
| 5244 | |
| 5245 | #ifdef CONFIG_RFS_ACCEL |
| 5246 | free_irq_cpu_rmap(bp->dev->rx_cpu_rmap); |
| 5247 | bp->dev->rx_cpu_rmap = NULL; |
| 5248 | #endif |
| 5249 | if (!bp->irq_tbl) |
| 5250 | return; |
| 5251 | |
| 5252 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 5253 | irq = &bp->irq_tbl[i]; |
| 5254 | if (irq->requested) |
| 5255 | free_irq(irq->vector, bp->bnapi[i]); |
| 5256 | irq->requested = 0; |
| 5257 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5258 | } |
| 5259 | |
| 5260 | static int bnxt_request_irq(struct bnxt *bp) |
| 5261 | { |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 5262 | int i, j, rc = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5263 | unsigned long flags = 0; |
| 5264 | #ifdef CONFIG_RFS_ACCEL |
| 5265 | struct cpu_rmap *rmap = bp->dev->rx_cpu_rmap; |
| 5266 | #endif |
| 5267 | |
| 5268 | if (!(bp->flags & BNXT_FLAG_USING_MSIX)) |
| 5269 | flags = IRQF_SHARED; |
| 5270 | |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 5271 | for (i = 0, j = 0; i < bp->cp_nr_rings; i++) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5272 | struct bnxt_irq *irq = &bp->irq_tbl[i]; |
| 5273 | #ifdef CONFIG_RFS_ACCEL |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 5274 | if (rmap && bp->bnapi[i]->rx_ring) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5275 | rc = irq_cpu_rmap_add(rmap, irq->vector); |
| 5276 | if (rc) |
| 5277 | netdev_warn(bp->dev, "failed adding irq rmap for ring %d\n", |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 5278 | j); |
| 5279 | j++; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5280 | } |
| 5281 | #endif |
| 5282 | rc = request_irq(irq->vector, irq->handler, flags, irq->name, |
| 5283 | bp->bnapi[i]); |
| 5284 | if (rc) |
| 5285 | break; |
| 5286 | |
| 5287 | irq->requested = 1; |
| 5288 | } |
| 5289 | return rc; |
| 5290 | } |
| 5291 | |
| 5292 | static void bnxt_del_napi(struct bnxt *bp) |
| 5293 | { |
| 5294 | int i; |
| 5295 | |
| 5296 | if (!bp->bnapi) |
| 5297 | return; |
| 5298 | |
| 5299 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 5300 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 5301 | |
| 5302 | napi_hash_del(&bnapi->napi); |
| 5303 | netif_napi_del(&bnapi->napi); |
| 5304 | } |
Eric Dumazet | e5f6f56 | 2016-11-16 06:31:52 -0800 | [diff] [blame] | 5305 | /* We called napi_hash_del() before netif_napi_del(), we need |
| 5306 | * to respect an RCU grace period before freeing napi structures. |
| 5307 | */ |
| 5308 | synchronize_net(); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5309 | } |
| 5310 | |
| 5311 | static void bnxt_init_napi(struct bnxt *bp) |
| 5312 | { |
| 5313 | int i; |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 5314 | unsigned int cp_nr_rings = bp->cp_nr_rings; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5315 | struct bnxt_napi *bnapi; |
| 5316 | |
| 5317 | if (bp->flags & BNXT_FLAG_USING_MSIX) { |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 5318 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 5319 | cp_nr_rings--; |
| 5320 | for (i = 0; i < cp_nr_rings; i++) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5321 | bnapi = bp->bnapi[i]; |
| 5322 | netif_napi_add(bp->dev, &bnapi->napi, |
| 5323 | bnxt_poll, 64); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5324 | } |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 5325 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) { |
| 5326 | bnapi = bp->bnapi[cp_nr_rings]; |
| 5327 | netif_napi_add(bp->dev, &bnapi->napi, |
| 5328 | bnxt_poll_nitroa0, 64); |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 5329 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5330 | } else { |
| 5331 | bnapi = bp->bnapi[0]; |
| 5332 | netif_napi_add(bp->dev, &bnapi->napi, bnxt_poll, 64); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5333 | } |
| 5334 | } |
| 5335 | |
| 5336 | static void bnxt_disable_napi(struct bnxt *bp) |
| 5337 | { |
| 5338 | int i; |
| 5339 | |
| 5340 | if (!bp->bnapi) |
| 5341 | return; |
| 5342 | |
Michael Chan | b356a2e | 2016-12-29 12:13:31 -0500 | [diff] [blame] | 5343 | for (i = 0; i < bp->cp_nr_rings; i++) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5344 | napi_disable(&bp->bnapi[i]->napi); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5345 | } |
| 5346 | |
| 5347 | static void bnxt_enable_napi(struct bnxt *bp) |
| 5348 | { |
| 5349 | int i; |
| 5350 | |
| 5351 | for (i = 0; i < bp->cp_nr_rings; i++) { |
Michael Chan | fa7e281 | 2016-05-10 19:18:00 -0400 | [diff] [blame] | 5352 | bp->bnapi[i]->in_reset = false; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5353 | napi_enable(&bp->bnapi[i]->napi); |
| 5354 | } |
| 5355 | } |
| 5356 | |
Michael Chan | 7df4ae9 | 2016-12-02 21:17:17 -0500 | [diff] [blame] | 5357 | void bnxt_tx_disable(struct bnxt *bp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5358 | { |
| 5359 | int i; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5360 | struct bnxt_tx_ring_info *txr; |
| 5361 | struct netdev_queue *txq; |
| 5362 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 5363 | if (bp->tx_ring) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5364 | for (i = 0; i < bp->tx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 5365 | txr = &bp->tx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5366 | txq = netdev_get_tx_queue(bp->dev, i); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5367 | txr->dev_state = BNXT_DEV_STATE_CLOSING; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5368 | } |
| 5369 | } |
| 5370 | /* Stop all TX queues */ |
| 5371 | netif_tx_disable(bp->dev); |
| 5372 | netif_carrier_off(bp->dev); |
| 5373 | } |
| 5374 | |
Michael Chan | 7df4ae9 | 2016-12-02 21:17:17 -0500 | [diff] [blame] | 5375 | void bnxt_tx_enable(struct bnxt *bp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5376 | { |
| 5377 | int i; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5378 | struct bnxt_tx_ring_info *txr; |
| 5379 | struct netdev_queue *txq; |
| 5380 | |
| 5381 | for (i = 0; i < bp->tx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 5382 | txr = &bp->tx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5383 | txq = netdev_get_tx_queue(bp->dev, i); |
| 5384 | txr->dev_state = 0; |
| 5385 | } |
| 5386 | netif_tx_wake_all_queues(bp->dev); |
| 5387 | if (bp->link_info.link_up) |
| 5388 | netif_carrier_on(bp->dev); |
| 5389 | } |
| 5390 | |
| 5391 | static void bnxt_report_link(struct bnxt *bp) |
| 5392 | { |
| 5393 | if (bp->link_info.link_up) { |
| 5394 | const char *duplex; |
| 5395 | const char *flow_ctrl; |
| 5396 | u16 speed; |
| 5397 | |
| 5398 | netif_carrier_on(bp->dev); |
| 5399 | if (bp->link_info.duplex == BNXT_LINK_DUPLEX_FULL) |
| 5400 | duplex = "full"; |
| 5401 | else |
| 5402 | duplex = "half"; |
| 5403 | if (bp->link_info.pause == BNXT_LINK_PAUSE_BOTH) |
| 5404 | flow_ctrl = "ON - receive & transmit"; |
| 5405 | else if (bp->link_info.pause == BNXT_LINK_PAUSE_TX) |
| 5406 | flow_ctrl = "ON - transmit"; |
| 5407 | else if (bp->link_info.pause == BNXT_LINK_PAUSE_RX) |
| 5408 | flow_ctrl = "ON - receive"; |
| 5409 | else |
| 5410 | flow_ctrl = "none"; |
| 5411 | speed = bnxt_fw_to_ethtool_speed(bp->link_info.link_speed); |
| 5412 | netdev_info(bp->dev, "NIC Link is Up, %d Mbps %s duplex, Flow control: %s\n", |
| 5413 | speed, duplex, flow_ctrl); |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 5414 | if (bp->flags & BNXT_FLAG_EEE_CAP) |
| 5415 | netdev_info(bp->dev, "EEE is %s\n", |
| 5416 | bp->eee.eee_active ? "active" : |
| 5417 | "not active"); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5418 | } else { |
| 5419 | netif_carrier_off(bp->dev); |
| 5420 | netdev_err(bp->dev, "NIC Link is Down\n"); |
| 5421 | } |
| 5422 | } |
| 5423 | |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 5424 | static int bnxt_hwrm_phy_qcaps(struct bnxt *bp) |
| 5425 | { |
| 5426 | int rc = 0; |
| 5427 | struct hwrm_port_phy_qcaps_input req = {0}; |
| 5428 | struct hwrm_port_phy_qcaps_output *resp = bp->hwrm_cmd_resp_addr; |
Michael Chan | 93ed811 | 2016-06-13 02:25:37 -0400 | [diff] [blame] | 5429 | struct bnxt_link_info *link_info = &bp->link_info; |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 5430 | |
| 5431 | if (bp->hwrm_spec_code < 0x10201) |
| 5432 | return 0; |
| 5433 | |
| 5434 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCAPS, -1, -1); |
| 5435 | |
| 5436 | mutex_lock(&bp->hwrm_cmd_lock); |
| 5437 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5438 | if (rc) |
| 5439 | goto hwrm_phy_qcaps_exit; |
| 5440 | |
| 5441 | if (resp->eee_supported & PORT_PHY_QCAPS_RESP_EEE_SUPPORTED) { |
| 5442 | struct ethtool_eee *eee = &bp->eee; |
| 5443 | u16 fw_speeds = le16_to_cpu(resp->supported_speeds_eee_mode); |
| 5444 | |
| 5445 | bp->flags |= BNXT_FLAG_EEE_CAP; |
| 5446 | eee->supported = _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0); |
| 5447 | bp->lpi_tmr_lo = le32_to_cpu(resp->tx_lpi_timer_low) & |
| 5448 | PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_LOW_MASK; |
| 5449 | bp->lpi_tmr_hi = le32_to_cpu(resp->valid_tx_lpi_timer_high) & |
| 5450 | PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_HIGH_MASK; |
| 5451 | } |
Michael Chan | 93ed811 | 2016-06-13 02:25:37 -0400 | [diff] [blame] | 5452 | link_info->support_auto_speeds = |
| 5453 | le16_to_cpu(resp->supported_speeds_auto_mode); |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 5454 | |
| 5455 | hwrm_phy_qcaps_exit: |
| 5456 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 5457 | return rc; |
| 5458 | } |
| 5459 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5460 | static int bnxt_update_link(struct bnxt *bp, bool chng_link_state) |
| 5461 | { |
| 5462 | int rc = 0; |
| 5463 | struct bnxt_link_info *link_info = &bp->link_info; |
| 5464 | struct hwrm_port_phy_qcfg_input req = {0}; |
| 5465 | struct hwrm_port_phy_qcfg_output *resp = bp->hwrm_cmd_resp_addr; |
| 5466 | u8 link_up = link_info->link_up; |
Michael Chan | 286ef9d | 2016-11-16 21:13:08 -0500 | [diff] [blame] | 5467 | u16 diff; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5468 | |
| 5469 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCFG, -1, -1); |
| 5470 | |
| 5471 | mutex_lock(&bp->hwrm_cmd_lock); |
| 5472 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5473 | if (rc) { |
| 5474 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 5475 | return rc; |
| 5476 | } |
| 5477 | |
| 5478 | memcpy(&link_info->phy_qcfg_resp, resp, sizeof(*resp)); |
| 5479 | link_info->phy_link_status = resp->link; |
| 5480 | link_info->duplex = resp->duplex; |
| 5481 | link_info->pause = resp->pause; |
| 5482 | link_info->auto_mode = resp->auto_mode; |
| 5483 | link_info->auto_pause_setting = resp->auto_pause; |
Michael Chan | 3277360 | 2016-03-07 15:38:42 -0500 | [diff] [blame] | 5484 | link_info->lp_pause = resp->link_partner_adv_pause; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5485 | link_info->force_pause_setting = resp->force_pause; |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 5486 | link_info->duplex_setting = resp->duplex; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5487 | if (link_info->phy_link_status == BNXT_LINK_LINK) |
| 5488 | link_info->link_speed = le16_to_cpu(resp->link_speed); |
| 5489 | else |
| 5490 | link_info->link_speed = 0; |
| 5491 | link_info->force_link_speed = le16_to_cpu(resp->force_link_speed); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5492 | link_info->support_speeds = le16_to_cpu(resp->support_speeds); |
| 5493 | 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] | 5494 | link_info->lp_auto_link_speeds = |
| 5495 | le16_to_cpu(resp->link_partner_adv_speeds); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5496 | link_info->preemphasis = le32_to_cpu(resp->preemphasis); |
| 5497 | link_info->phy_ver[0] = resp->phy_maj; |
| 5498 | link_info->phy_ver[1] = resp->phy_min; |
| 5499 | link_info->phy_ver[2] = resp->phy_bld; |
| 5500 | link_info->media_type = resp->media_type; |
Michael Chan | 03efbec | 2016-04-11 04:11:11 -0400 | [diff] [blame] | 5501 | link_info->phy_type = resp->phy_type; |
Michael Chan | 11f15ed | 2016-04-05 14:08:55 -0400 | [diff] [blame] | 5502 | link_info->transceiver = resp->xcvr_pkg_type; |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 5503 | link_info->phy_addr = resp->eee_config_phy_addr & |
| 5504 | PORT_PHY_QCFG_RESP_PHY_ADDR_MASK; |
Ajit Khaparde | 42ee18f | 2016-05-15 03:04:44 -0400 | [diff] [blame] | 5505 | link_info->module_status = resp->module_status; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5506 | |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 5507 | if (bp->flags & BNXT_FLAG_EEE_CAP) { |
| 5508 | struct ethtool_eee *eee = &bp->eee; |
| 5509 | u16 fw_speeds; |
| 5510 | |
| 5511 | eee->eee_active = 0; |
| 5512 | if (resp->eee_config_phy_addr & |
| 5513 | PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ACTIVE) { |
| 5514 | eee->eee_active = 1; |
| 5515 | fw_speeds = le16_to_cpu( |
| 5516 | resp->link_partner_adv_eee_link_speed_mask); |
| 5517 | eee->lp_advertised = |
| 5518 | _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0); |
| 5519 | } |
| 5520 | |
| 5521 | /* Pull initial EEE config */ |
| 5522 | if (!chng_link_state) { |
| 5523 | if (resp->eee_config_phy_addr & |
| 5524 | PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ENABLED) |
| 5525 | eee->eee_enabled = 1; |
| 5526 | |
| 5527 | fw_speeds = le16_to_cpu(resp->adv_eee_link_speed_mask); |
| 5528 | eee->advertised = |
| 5529 | _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0); |
| 5530 | |
| 5531 | if (resp->eee_config_phy_addr & |
| 5532 | PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_TX_LPI) { |
| 5533 | __le32 tmr; |
| 5534 | |
| 5535 | eee->tx_lpi_enabled = 1; |
| 5536 | tmr = resp->xcvr_identifier_type_tx_lpi_timer; |
| 5537 | eee->tx_lpi_timer = le32_to_cpu(tmr) & |
| 5538 | PORT_PHY_QCFG_RESP_TX_LPI_TIMER_MASK; |
| 5539 | } |
| 5540 | } |
| 5541 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5542 | /* TODO: need to add more logic to report VF link */ |
| 5543 | if (chng_link_state) { |
| 5544 | if (link_info->phy_link_status == BNXT_LINK_LINK) |
| 5545 | link_info->link_up = 1; |
| 5546 | else |
| 5547 | link_info->link_up = 0; |
| 5548 | if (link_up != link_info->link_up) |
| 5549 | bnxt_report_link(bp); |
| 5550 | } else { |
| 5551 | /* alwasy link down if not require to update link state */ |
| 5552 | link_info->link_up = 0; |
| 5553 | } |
| 5554 | mutex_unlock(&bp->hwrm_cmd_lock); |
Michael Chan | 286ef9d | 2016-11-16 21:13:08 -0500 | [diff] [blame] | 5555 | |
| 5556 | diff = link_info->support_auto_speeds ^ link_info->advertising; |
| 5557 | if ((link_info->support_auto_speeds | diff) != |
| 5558 | link_info->support_auto_speeds) { |
| 5559 | /* An advertised speed is no longer supported, so we need to |
Michael Chan | 0eaa24b | 2017-01-25 02:55:08 -0500 | [diff] [blame] | 5560 | * update the advertisement settings. Caller holds RTNL |
| 5561 | * so we can modify link settings. |
Michael Chan | 286ef9d | 2016-11-16 21:13:08 -0500 | [diff] [blame] | 5562 | */ |
Michael Chan | 286ef9d | 2016-11-16 21:13:08 -0500 | [diff] [blame] | 5563 | link_info->advertising = link_info->support_auto_speeds; |
Michael Chan | 0eaa24b | 2017-01-25 02:55:08 -0500 | [diff] [blame] | 5564 | if (link_info->autoneg & BNXT_AUTONEG_SPEED) |
Michael Chan | 286ef9d | 2016-11-16 21:13:08 -0500 | [diff] [blame] | 5565 | bnxt_hwrm_set_link_setting(bp, true, false); |
Michael Chan | 286ef9d | 2016-11-16 21:13:08 -0500 | [diff] [blame] | 5566 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5567 | return 0; |
| 5568 | } |
| 5569 | |
Michael Chan | 10289be | 2016-05-15 03:04:49 -0400 | [diff] [blame] | 5570 | static void bnxt_get_port_module_status(struct bnxt *bp) |
| 5571 | { |
| 5572 | struct bnxt_link_info *link_info = &bp->link_info; |
| 5573 | struct hwrm_port_phy_qcfg_output *resp = &link_info->phy_qcfg_resp; |
| 5574 | u8 module_status; |
| 5575 | |
| 5576 | if (bnxt_update_link(bp, true)) |
| 5577 | return; |
| 5578 | |
| 5579 | module_status = link_info->module_status; |
| 5580 | switch (module_status) { |
| 5581 | case PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX: |
| 5582 | case PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN: |
| 5583 | case PORT_PHY_QCFG_RESP_MODULE_STATUS_WARNINGMSG: |
| 5584 | netdev_warn(bp->dev, "Unqualified SFP+ module detected on port %d\n", |
| 5585 | bp->pf.port_id); |
| 5586 | if (bp->hwrm_spec_code >= 0x10201) { |
| 5587 | netdev_warn(bp->dev, "Module part number %s\n", |
| 5588 | resp->phy_vendor_partnumber); |
| 5589 | } |
| 5590 | if (module_status == PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX) |
| 5591 | netdev_warn(bp->dev, "TX is disabled\n"); |
| 5592 | if (module_status == PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN) |
| 5593 | netdev_warn(bp->dev, "SFP+ module is shutdown\n"); |
| 5594 | } |
| 5595 | } |
| 5596 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5597 | static void |
| 5598 | bnxt_hwrm_set_pause_common(struct bnxt *bp, struct hwrm_port_phy_cfg_input *req) |
| 5599 | { |
| 5600 | if (bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL) { |
Michael Chan | c9ee951 | 2016-04-05 14:08:56 -0400 | [diff] [blame] | 5601 | if (bp->hwrm_spec_code >= 0x10201) |
| 5602 | req->auto_pause = |
| 5603 | PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5604 | if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_RX) |
| 5605 | req->auto_pause |= PORT_PHY_CFG_REQ_AUTO_PAUSE_RX; |
| 5606 | if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_TX) |
Michael Chan | 49b5c7a | 2016-03-28 19:46:06 -0400 | [diff] [blame] | 5607 | req->auto_pause |= PORT_PHY_CFG_REQ_AUTO_PAUSE_TX; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5608 | req->enables |= |
| 5609 | cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE); |
| 5610 | } else { |
| 5611 | if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_RX) |
| 5612 | req->force_pause |= PORT_PHY_CFG_REQ_FORCE_PAUSE_RX; |
| 5613 | if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_TX) |
| 5614 | req->force_pause |= PORT_PHY_CFG_REQ_FORCE_PAUSE_TX; |
| 5615 | req->enables |= |
| 5616 | cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_FORCE_PAUSE); |
Michael Chan | c9ee951 | 2016-04-05 14:08:56 -0400 | [diff] [blame] | 5617 | if (bp->hwrm_spec_code >= 0x10201) { |
| 5618 | req->auto_pause = req->force_pause; |
| 5619 | req->enables |= cpu_to_le32( |
| 5620 | PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE); |
| 5621 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5622 | } |
| 5623 | } |
| 5624 | |
| 5625 | static void bnxt_hwrm_set_link_common(struct bnxt *bp, |
| 5626 | struct hwrm_port_phy_cfg_input *req) |
| 5627 | { |
| 5628 | u8 autoneg = bp->link_info.autoneg; |
| 5629 | u16 fw_link_speed = bp->link_info.req_link_speed; |
Michael Chan | 68515a1 | 2016-12-29 12:13:34 -0500 | [diff] [blame] | 5630 | u16 advertising = bp->link_info.advertising; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5631 | |
| 5632 | if (autoneg & BNXT_AUTONEG_SPEED) { |
| 5633 | req->auto_mode |= |
Michael Chan | 11f15ed | 2016-04-05 14:08:55 -0400 | [diff] [blame] | 5634 | PORT_PHY_CFG_REQ_AUTO_MODE_SPEED_MASK; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5635 | |
| 5636 | req->enables |= cpu_to_le32( |
| 5637 | PORT_PHY_CFG_REQ_ENABLES_AUTO_LINK_SPEED_MASK); |
| 5638 | req->auto_link_speed_mask = cpu_to_le16(advertising); |
| 5639 | |
| 5640 | req->enables |= cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_MODE); |
| 5641 | req->flags |= |
| 5642 | cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESTART_AUTONEG); |
| 5643 | } else { |
| 5644 | req->force_link_speed = cpu_to_le16(fw_link_speed); |
| 5645 | req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE); |
| 5646 | } |
| 5647 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5648 | /* tell chimp that the setting takes effect immediately */ |
| 5649 | req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESET_PHY); |
| 5650 | } |
| 5651 | |
| 5652 | int bnxt_hwrm_set_pause(struct bnxt *bp) |
| 5653 | { |
| 5654 | struct hwrm_port_phy_cfg_input req = {0}; |
| 5655 | int rc; |
| 5656 | |
| 5657 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1); |
| 5658 | bnxt_hwrm_set_pause_common(bp, &req); |
| 5659 | |
| 5660 | if ((bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL) || |
| 5661 | bp->link_info.force_link_chng) |
| 5662 | bnxt_hwrm_set_link_common(bp, &req); |
| 5663 | |
| 5664 | mutex_lock(&bp->hwrm_cmd_lock); |
| 5665 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5666 | if (!rc && !(bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL)) { |
| 5667 | /* since changing of pause setting doesn't trigger any link |
| 5668 | * change event, the driver needs to update the current pause |
| 5669 | * result upon successfully return of the phy_cfg command |
| 5670 | */ |
| 5671 | bp->link_info.pause = |
| 5672 | bp->link_info.force_pause_setting = bp->link_info.req_flow_ctrl; |
| 5673 | bp->link_info.auto_pause_setting = 0; |
| 5674 | if (!bp->link_info.force_link_chng) |
| 5675 | bnxt_report_link(bp); |
| 5676 | } |
| 5677 | bp->link_info.force_link_chng = false; |
| 5678 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 5679 | return rc; |
| 5680 | } |
| 5681 | |
Michael Chan | 939f7f0 | 2016-04-05 14:08:58 -0400 | [diff] [blame] | 5682 | static void bnxt_hwrm_set_eee(struct bnxt *bp, |
| 5683 | struct hwrm_port_phy_cfg_input *req) |
| 5684 | { |
| 5685 | struct ethtool_eee *eee = &bp->eee; |
| 5686 | |
| 5687 | if (eee->eee_enabled) { |
| 5688 | u16 eee_speeds; |
| 5689 | u32 flags = PORT_PHY_CFG_REQ_FLAGS_EEE_ENABLE; |
| 5690 | |
| 5691 | if (eee->tx_lpi_enabled) |
| 5692 | flags |= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_ENABLE; |
| 5693 | else |
| 5694 | flags |= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_DISABLE; |
| 5695 | |
| 5696 | req->flags |= cpu_to_le32(flags); |
| 5697 | eee_speeds = bnxt_get_fw_auto_link_speeds(eee->advertised); |
| 5698 | req->eee_link_speed_mask = cpu_to_le16(eee_speeds); |
| 5699 | req->tx_lpi_timer = cpu_to_le32(eee->tx_lpi_timer); |
| 5700 | } else { |
| 5701 | req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_EEE_DISABLE); |
| 5702 | } |
| 5703 | } |
| 5704 | |
| 5705 | 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] | 5706 | { |
| 5707 | struct hwrm_port_phy_cfg_input req = {0}; |
| 5708 | |
| 5709 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1); |
| 5710 | if (set_pause) |
| 5711 | bnxt_hwrm_set_pause_common(bp, &req); |
| 5712 | |
| 5713 | bnxt_hwrm_set_link_common(bp, &req); |
Michael Chan | 939f7f0 | 2016-04-05 14:08:58 -0400 | [diff] [blame] | 5714 | |
| 5715 | if (set_eee) |
| 5716 | bnxt_hwrm_set_eee(bp, &req); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5717 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5718 | } |
| 5719 | |
Michael Chan | 33f7d55 | 2016-04-11 04:11:12 -0400 | [diff] [blame] | 5720 | static int bnxt_hwrm_shutdown_link(struct bnxt *bp) |
| 5721 | { |
| 5722 | struct hwrm_port_phy_cfg_input req = {0}; |
| 5723 | |
Satish Baddipadige | 567b2ab | 2016-06-13 02:25:31 -0400 | [diff] [blame] | 5724 | if (!BNXT_SINGLE_PF(bp)) |
Michael Chan | 33f7d55 | 2016-04-11 04:11:12 -0400 | [diff] [blame] | 5725 | return 0; |
| 5726 | |
| 5727 | if (pci_num_vf(bp->pdev)) |
| 5728 | return 0; |
| 5729 | |
| 5730 | 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] | 5731 | 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] | 5732 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5733 | } |
| 5734 | |
Michael Chan | 5ad2cbe | 2017-01-13 01:32:03 -0500 | [diff] [blame] | 5735 | static int bnxt_hwrm_port_led_qcaps(struct bnxt *bp) |
| 5736 | { |
| 5737 | struct hwrm_port_led_qcaps_output *resp = bp->hwrm_cmd_resp_addr; |
| 5738 | struct hwrm_port_led_qcaps_input req = {0}; |
| 5739 | struct bnxt_pf_info *pf = &bp->pf; |
| 5740 | int rc; |
| 5741 | |
| 5742 | if (BNXT_VF(bp) || bp->hwrm_spec_code < 0x10601) |
| 5743 | return 0; |
| 5744 | |
| 5745 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_LED_QCAPS, -1, -1); |
| 5746 | req.port_id = cpu_to_le16(pf->port_id); |
| 5747 | mutex_lock(&bp->hwrm_cmd_lock); |
| 5748 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5749 | if (rc) { |
| 5750 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 5751 | return rc; |
| 5752 | } |
| 5753 | if (resp->num_leds > 0 && resp->num_leds < BNXT_MAX_LED) { |
| 5754 | int i; |
| 5755 | |
| 5756 | bp->num_leds = resp->num_leds; |
| 5757 | memcpy(bp->leds, &resp->led0_id, sizeof(bp->leds[0]) * |
| 5758 | bp->num_leds); |
| 5759 | for (i = 0; i < bp->num_leds; i++) { |
| 5760 | struct bnxt_led_info *led = &bp->leds[i]; |
| 5761 | __le16 caps = led->led_state_caps; |
| 5762 | |
| 5763 | if (!led->led_group_id || |
| 5764 | !BNXT_LED_ALT_BLINK_CAP(caps)) { |
| 5765 | bp->num_leds = 0; |
| 5766 | break; |
| 5767 | } |
| 5768 | } |
| 5769 | } |
| 5770 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 5771 | return 0; |
| 5772 | } |
| 5773 | |
Michael Chan | 939f7f0 | 2016-04-05 14:08:58 -0400 | [diff] [blame] | 5774 | static bool bnxt_eee_config_ok(struct bnxt *bp) |
| 5775 | { |
| 5776 | struct ethtool_eee *eee = &bp->eee; |
| 5777 | struct bnxt_link_info *link_info = &bp->link_info; |
| 5778 | |
| 5779 | if (!(bp->flags & BNXT_FLAG_EEE_CAP)) |
| 5780 | return true; |
| 5781 | |
| 5782 | if (eee->eee_enabled) { |
| 5783 | u32 advertising = |
| 5784 | _bnxt_fw_to_ethtool_adv_spds(link_info->advertising, 0); |
| 5785 | |
| 5786 | if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) { |
| 5787 | eee->eee_enabled = 0; |
| 5788 | return false; |
| 5789 | } |
| 5790 | if (eee->advertised & ~advertising) { |
| 5791 | eee->advertised = advertising & eee->supported; |
| 5792 | return false; |
| 5793 | } |
| 5794 | } |
| 5795 | return true; |
| 5796 | } |
| 5797 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5798 | static int bnxt_update_phy_setting(struct bnxt *bp) |
| 5799 | { |
| 5800 | int rc; |
| 5801 | bool update_link = false; |
| 5802 | bool update_pause = false; |
Michael Chan | 939f7f0 | 2016-04-05 14:08:58 -0400 | [diff] [blame] | 5803 | bool update_eee = false; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5804 | struct bnxt_link_info *link_info = &bp->link_info; |
| 5805 | |
| 5806 | rc = bnxt_update_link(bp, true); |
| 5807 | if (rc) { |
| 5808 | netdev_err(bp->dev, "failed to update link (rc: %x)\n", |
| 5809 | rc); |
| 5810 | return rc; |
| 5811 | } |
| 5812 | if ((link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) && |
Michael Chan | c9ee951 | 2016-04-05 14:08:56 -0400 | [diff] [blame] | 5813 | (link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH) != |
| 5814 | link_info->req_flow_ctrl) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5815 | update_pause = true; |
| 5816 | if (!(link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) && |
| 5817 | link_info->force_pause_setting != link_info->req_flow_ctrl) |
| 5818 | update_pause = true; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5819 | if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) { |
| 5820 | if (BNXT_AUTO_MODE(link_info->auto_mode)) |
| 5821 | update_link = true; |
| 5822 | if (link_info->req_link_speed != link_info->force_link_speed) |
| 5823 | update_link = true; |
Michael Chan | de73018 | 2016-02-19 19:43:20 -0500 | [diff] [blame] | 5824 | if (link_info->req_duplex != link_info->duplex_setting) |
| 5825 | update_link = true; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5826 | } else { |
| 5827 | if (link_info->auto_mode == BNXT_LINK_AUTO_NONE) |
| 5828 | update_link = true; |
| 5829 | if (link_info->advertising != link_info->auto_link_speeds) |
| 5830 | update_link = true; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5831 | } |
| 5832 | |
Michael Chan | 16d663a | 2016-11-16 21:13:07 -0500 | [diff] [blame] | 5833 | /* The last close may have shutdown the link, so need to call |
| 5834 | * PHY_CFG to bring it back up. |
| 5835 | */ |
| 5836 | if (!netif_carrier_ok(bp->dev)) |
| 5837 | update_link = true; |
| 5838 | |
Michael Chan | 939f7f0 | 2016-04-05 14:08:58 -0400 | [diff] [blame] | 5839 | if (!bnxt_eee_config_ok(bp)) |
| 5840 | update_eee = true; |
| 5841 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5842 | if (update_link) |
Michael Chan | 939f7f0 | 2016-04-05 14:08:58 -0400 | [diff] [blame] | 5843 | rc = bnxt_hwrm_set_link_setting(bp, update_pause, update_eee); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5844 | else if (update_pause) |
| 5845 | rc = bnxt_hwrm_set_pause(bp); |
| 5846 | if (rc) { |
| 5847 | netdev_err(bp->dev, "failed to update phy setting (rc: %x)\n", |
| 5848 | rc); |
| 5849 | return rc; |
| 5850 | } |
| 5851 | |
| 5852 | return rc; |
| 5853 | } |
| 5854 | |
Jeffrey Huang | 1180949 | 2015-11-05 16:25:49 -0500 | [diff] [blame] | 5855 | /* Common routine to pre-map certain register block to different GRC window. |
| 5856 | * A PF has 16 4K windows and a VF has 4 4K windows. However, only 15 windows |
| 5857 | * in PF and 3 windows in VF that can be customized to map in different |
| 5858 | * register blocks. |
| 5859 | */ |
| 5860 | static void bnxt_preset_reg_win(struct bnxt *bp) |
| 5861 | { |
| 5862 | if (BNXT_PF(bp)) { |
| 5863 | /* CAG registers map to GRC window #4 */ |
| 5864 | writel(BNXT_CAG_REG_BASE, |
| 5865 | bp->bar0 + BNXT_GRCPF_REG_WINDOW_BASE_OUT + 12); |
| 5866 | } |
| 5867 | } |
| 5868 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5869 | static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init) |
| 5870 | { |
| 5871 | int rc = 0; |
| 5872 | |
Jeffrey Huang | 1180949 | 2015-11-05 16:25:49 -0500 | [diff] [blame] | 5873 | bnxt_preset_reg_win(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5874 | netif_carrier_off(bp->dev); |
| 5875 | if (irq_re_init) { |
| 5876 | rc = bnxt_setup_int_mode(bp); |
| 5877 | if (rc) { |
| 5878 | netdev_err(bp->dev, "bnxt_setup_int_mode err: %x\n", |
| 5879 | rc); |
| 5880 | return rc; |
| 5881 | } |
| 5882 | } |
| 5883 | if ((bp->flags & BNXT_FLAG_RFS) && |
| 5884 | !(bp->flags & BNXT_FLAG_USING_MSIX)) { |
| 5885 | /* disable RFS if falling back to INTA */ |
| 5886 | bp->dev->hw_features &= ~NETIF_F_NTUPLE; |
| 5887 | bp->flags &= ~BNXT_FLAG_RFS; |
| 5888 | } |
| 5889 | |
| 5890 | rc = bnxt_alloc_mem(bp, irq_re_init); |
| 5891 | if (rc) { |
| 5892 | netdev_err(bp->dev, "bnxt_alloc_mem err: %x\n", rc); |
| 5893 | goto open_err_free_mem; |
| 5894 | } |
| 5895 | |
| 5896 | if (irq_re_init) { |
| 5897 | bnxt_init_napi(bp); |
| 5898 | rc = bnxt_request_irq(bp); |
| 5899 | if (rc) { |
| 5900 | netdev_err(bp->dev, "bnxt_request_irq err: %x\n", rc); |
| 5901 | goto open_err; |
| 5902 | } |
| 5903 | } |
| 5904 | |
| 5905 | bnxt_enable_napi(bp); |
| 5906 | |
| 5907 | rc = bnxt_init_nic(bp, irq_re_init); |
| 5908 | if (rc) { |
| 5909 | netdev_err(bp->dev, "bnxt_init_nic err: %x\n", rc); |
| 5910 | goto open_err; |
| 5911 | } |
| 5912 | |
| 5913 | if (link_re_init) { |
| 5914 | rc = bnxt_update_phy_setting(bp); |
| 5915 | if (rc) |
Michael Chan | ba41d46 | 2016-02-19 19:43:21 -0500 | [diff] [blame] | 5916 | netdev_warn(bp->dev, "failed to update phy settings\n"); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5917 | } |
| 5918 | |
Alexander Duyck | 7cdd5fc | 2016-06-16 12:21:36 -0700 | [diff] [blame] | 5919 | if (irq_re_init) |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 5920 | udp_tunnel_get_rx_info(bp->dev); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5921 | |
Michael Chan | caefe52 | 2015-12-09 19:35:42 -0500 | [diff] [blame] | 5922 | set_bit(BNXT_STATE_OPEN, &bp->state); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5923 | bnxt_enable_int(bp); |
| 5924 | /* Enable TX queues */ |
| 5925 | bnxt_tx_enable(bp); |
| 5926 | mod_timer(&bp->timer, jiffies + bp->current_interval); |
Michael Chan | 10289be | 2016-05-15 03:04:49 -0400 | [diff] [blame] | 5927 | /* Poll link status and check for SFP+ module status */ |
| 5928 | bnxt_get_port_module_status(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5929 | |
| 5930 | return 0; |
| 5931 | |
| 5932 | open_err: |
| 5933 | bnxt_disable_napi(bp); |
| 5934 | bnxt_del_napi(bp); |
| 5935 | |
| 5936 | open_err_free_mem: |
| 5937 | bnxt_free_skbs(bp); |
| 5938 | bnxt_free_irq(bp); |
| 5939 | bnxt_free_mem(bp, true); |
| 5940 | return rc; |
| 5941 | } |
| 5942 | |
| 5943 | /* rtnl_lock held */ |
| 5944 | int bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init) |
| 5945 | { |
| 5946 | int rc = 0; |
| 5947 | |
| 5948 | rc = __bnxt_open_nic(bp, irq_re_init, link_re_init); |
| 5949 | if (rc) { |
| 5950 | netdev_err(bp->dev, "nic open fail (rc: %x)\n", rc); |
| 5951 | dev_close(bp->dev); |
| 5952 | } |
| 5953 | return rc; |
| 5954 | } |
| 5955 | |
| 5956 | static int bnxt_open(struct net_device *dev) |
| 5957 | { |
| 5958 | struct bnxt *bp = netdev_priv(dev); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5959 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5960 | return __bnxt_open_nic(bp, true, true); |
| 5961 | } |
| 5962 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5963 | int bnxt_close_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init) |
| 5964 | { |
| 5965 | int rc = 0; |
| 5966 | |
| 5967 | #ifdef CONFIG_BNXT_SRIOV |
| 5968 | if (bp->sriov_cfg) { |
| 5969 | rc = wait_event_interruptible_timeout(bp->sriov_cfg_wait, |
| 5970 | !bp->sriov_cfg, |
| 5971 | BNXT_SRIOV_CFG_WAIT_TMO); |
| 5972 | if (rc) |
| 5973 | netdev_warn(bp->dev, "timeout waiting for SRIOV config operation to complete!\n"); |
| 5974 | } |
| 5975 | #endif |
| 5976 | /* Change device state to avoid TX queue wake up's */ |
| 5977 | bnxt_tx_disable(bp); |
| 5978 | |
Michael Chan | caefe52 | 2015-12-09 19:35:42 -0500 | [diff] [blame] | 5979 | clear_bit(BNXT_STATE_OPEN, &bp->state); |
Michael Chan | 4cebdce | 2015-12-09 19:35:43 -0500 | [diff] [blame] | 5980 | smp_mb__after_atomic(); |
| 5981 | while (test_bit(BNXT_STATE_IN_SP_TASK, &bp->state)) |
| 5982 | msleep(20); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5983 | |
Michael Chan | 9d8bc09 | 2016-12-29 12:13:33 -0500 | [diff] [blame] | 5984 | /* Flush rings and and disable interrupts */ |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5985 | bnxt_shutdown_nic(bp, irq_re_init); |
| 5986 | |
| 5987 | /* TODO CHIMP_FW: Link/PHY related cleanup if (link_re_init) */ |
| 5988 | |
| 5989 | bnxt_disable_napi(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5990 | del_timer_sync(&bp->timer); |
| 5991 | bnxt_free_skbs(bp); |
| 5992 | |
| 5993 | if (irq_re_init) { |
| 5994 | bnxt_free_irq(bp); |
| 5995 | bnxt_del_napi(bp); |
| 5996 | } |
| 5997 | bnxt_free_mem(bp, irq_re_init); |
| 5998 | return rc; |
| 5999 | } |
| 6000 | |
| 6001 | static int bnxt_close(struct net_device *dev) |
| 6002 | { |
| 6003 | struct bnxt *bp = netdev_priv(dev); |
| 6004 | |
| 6005 | bnxt_close_nic(bp, true, true); |
Michael Chan | 33f7d55 | 2016-04-11 04:11:12 -0400 | [diff] [blame] | 6006 | bnxt_hwrm_shutdown_link(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6007 | return 0; |
| 6008 | } |
| 6009 | |
| 6010 | /* rtnl_lock held */ |
| 6011 | static int bnxt_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 6012 | { |
| 6013 | switch (cmd) { |
| 6014 | case SIOCGMIIPHY: |
| 6015 | /* fallthru */ |
| 6016 | case SIOCGMIIREG: { |
| 6017 | if (!netif_running(dev)) |
| 6018 | return -EAGAIN; |
| 6019 | |
| 6020 | return 0; |
| 6021 | } |
| 6022 | |
| 6023 | case SIOCSMIIREG: |
| 6024 | if (!netif_running(dev)) |
| 6025 | return -EAGAIN; |
| 6026 | |
| 6027 | return 0; |
| 6028 | |
| 6029 | default: |
| 6030 | /* do nothing */ |
| 6031 | break; |
| 6032 | } |
| 6033 | return -EOPNOTSUPP; |
| 6034 | } |
| 6035 | |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 6036 | static void |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6037 | bnxt_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) |
| 6038 | { |
| 6039 | u32 i; |
| 6040 | struct bnxt *bp = netdev_priv(dev); |
| 6041 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6042 | if (!bp->bnapi) |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 6043 | return; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6044 | |
| 6045 | /* TODO check if we need to synchronize with bnxt_close path */ |
| 6046 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 6047 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 6048 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 6049 | struct ctx_hw_stats *hw_stats = cpr->hw_stats; |
| 6050 | |
| 6051 | stats->rx_packets += le64_to_cpu(hw_stats->rx_ucast_pkts); |
| 6052 | stats->rx_packets += le64_to_cpu(hw_stats->rx_mcast_pkts); |
| 6053 | stats->rx_packets += le64_to_cpu(hw_stats->rx_bcast_pkts); |
| 6054 | |
| 6055 | stats->tx_packets += le64_to_cpu(hw_stats->tx_ucast_pkts); |
| 6056 | stats->tx_packets += le64_to_cpu(hw_stats->tx_mcast_pkts); |
| 6057 | stats->tx_packets += le64_to_cpu(hw_stats->tx_bcast_pkts); |
| 6058 | |
| 6059 | stats->rx_bytes += le64_to_cpu(hw_stats->rx_ucast_bytes); |
| 6060 | stats->rx_bytes += le64_to_cpu(hw_stats->rx_mcast_bytes); |
| 6061 | stats->rx_bytes += le64_to_cpu(hw_stats->rx_bcast_bytes); |
| 6062 | |
| 6063 | stats->tx_bytes += le64_to_cpu(hw_stats->tx_ucast_bytes); |
| 6064 | stats->tx_bytes += le64_to_cpu(hw_stats->tx_mcast_bytes); |
| 6065 | stats->tx_bytes += le64_to_cpu(hw_stats->tx_bcast_bytes); |
| 6066 | |
| 6067 | stats->rx_missed_errors += |
| 6068 | le64_to_cpu(hw_stats->rx_discard_pkts); |
| 6069 | |
| 6070 | stats->multicast += le64_to_cpu(hw_stats->rx_mcast_pkts); |
| 6071 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6072 | stats->tx_dropped += le64_to_cpu(hw_stats->tx_drop_pkts); |
| 6073 | } |
| 6074 | |
Michael Chan | 9947f83 | 2016-03-07 15:38:46 -0500 | [diff] [blame] | 6075 | if (bp->flags & BNXT_FLAG_PORT_STATS) { |
| 6076 | struct rx_port_stats *rx = bp->hw_rx_port_stats; |
| 6077 | struct tx_port_stats *tx = bp->hw_tx_port_stats; |
| 6078 | |
| 6079 | stats->rx_crc_errors = le64_to_cpu(rx->rx_fcs_err_frames); |
| 6080 | stats->rx_frame_errors = le64_to_cpu(rx->rx_align_err_frames); |
| 6081 | stats->rx_length_errors = le64_to_cpu(rx->rx_undrsz_frames) + |
| 6082 | le64_to_cpu(rx->rx_ovrsz_frames) + |
| 6083 | le64_to_cpu(rx->rx_runt_frames); |
| 6084 | stats->rx_errors = le64_to_cpu(rx->rx_false_carrier_frames) + |
| 6085 | le64_to_cpu(rx->rx_jbr_frames); |
| 6086 | stats->collisions = le64_to_cpu(tx->tx_total_collisions); |
| 6087 | stats->tx_fifo_errors = le64_to_cpu(tx->tx_fifo_underruns); |
| 6088 | stats->tx_errors = le64_to_cpu(tx->tx_err); |
| 6089 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6090 | } |
| 6091 | |
| 6092 | static bool bnxt_mc_list_updated(struct bnxt *bp, u32 *rx_mask) |
| 6093 | { |
| 6094 | struct net_device *dev = bp->dev; |
| 6095 | struct bnxt_vnic_info *vnic = &bp->vnic_info[0]; |
| 6096 | struct netdev_hw_addr *ha; |
| 6097 | u8 *haddr; |
| 6098 | int mc_count = 0; |
| 6099 | bool update = false; |
| 6100 | int off = 0; |
| 6101 | |
| 6102 | netdev_for_each_mc_addr(ha, dev) { |
| 6103 | if (mc_count >= BNXT_MAX_MC_ADDRS) { |
| 6104 | *rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST; |
| 6105 | vnic->mc_list_count = 0; |
| 6106 | return false; |
| 6107 | } |
| 6108 | haddr = ha->addr; |
| 6109 | if (!ether_addr_equal(haddr, vnic->mc_list + off)) { |
| 6110 | memcpy(vnic->mc_list + off, haddr, ETH_ALEN); |
| 6111 | update = true; |
| 6112 | } |
| 6113 | off += ETH_ALEN; |
| 6114 | mc_count++; |
| 6115 | } |
| 6116 | if (mc_count) |
| 6117 | *rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_MCAST; |
| 6118 | |
| 6119 | if (mc_count != vnic->mc_list_count) { |
| 6120 | vnic->mc_list_count = mc_count; |
| 6121 | update = true; |
| 6122 | } |
| 6123 | return update; |
| 6124 | } |
| 6125 | |
| 6126 | static bool bnxt_uc_list_updated(struct bnxt *bp) |
| 6127 | { |
| 6128 | struct net_device *dev = bp->dev; |
| 6129 | struct bnxt_vnic_info *vnic = &bp->vnic_info[0]; |
| 6130 | struct netdev_hw_addr *ha; |
| 6131 | int off = 0; |
| 6132 | |
| 6133 | if (netdev_uc_count(dev) != (vnic->uc_filter_count - 1)) |
| 6134 | return true; |
| 6135 | |
| 6136 | netdev_for_each_uc_addr(ha, dev) { |
| 6137 | if (!ether_addr_equal(ha->addr, vnic->uc_list + off)) |
| 6138 | return true; |
| 6139 | |
| 6140 | off += ETH_ALEN; |
| 6141 | } |
| 6142 | return false; |
| 6143 | } |
| 6144 | |
| 6145 | static void bnxt_set_rx_mode(struct net_device *dev) |
| 6146 | { |
| 6147 | struct bnxt *bp = netdev_priv(dev); |
| 6148 | struct bnxt_vnic_info *vnic = &bp->vnic_info[0]; |
| 6149 | u32 mask = vnic->rx_mask; |
| 6150 | bool mc_update = false; |
| 6151 | bool uc_update; |
| 6152 | |
| 6153 | if (!netif_running(dev)) |
| 6154 | return; |
| 6155 | |
| 6156 | mask &= ~(CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS | |
| 6157 | CFA_L2_SET_RX_MASK_REQ_MASK_MCAST | |
| 6158 | CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST); |
| 6159 | |
Michael Chan | 17c71ac | 2016-07-01 18:46:27 -0400 | [diff] [blame] | 6160 | if ((dev->flags & IFF_PROMISC) && bnxt_promisc_ok(bp)) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6161 | mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS; |
| 6162 | |
| 6163 | uc_update = bnxt_uc_list_updated(bp); |
| 6164 | |
| 6165 | if (dev->flags & IFF_ALLMULTI) { |
| 6166 | mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST; |
| 6167 | vnic->mc_list_count = 0; |
| 6168 | } else { |
| 6169 | mc_update = bnxt_mc_list_updated(bp, &mask); |
| 6170 | } |
| 6171 | |
| 6172 | if (mask != vnic->rx_mask || uc_update || mc_update) { |
| 6173 | vnic->rx_mask = mask; |
| 6174 | |
| 6175 | set_bit(BNXT_RX_MASK_SP_EVENT, &bp->sp_event); |
| 6176 | schedule_work(&bp->sp_task); |
| 6177 | } |
| 6178 | } |
| 6179 | |
Michael Chan | b664f00 | 2015-12-02 01:54:08 -0500 | [diff] [blame] | 6180 | static int bnxt_cfg_rx_mode(struct bnxt *bp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6181 | { |
| 6182 | struct net_device *dev = bp->dev; |
| 6183 | struct bnxt_vnic_info *vnic = &bp->vnic_info[0]; |
| 6184 | struct netdev_hw_addr *ha; |
| 6185 | int i, off = 0, rc; |
| 6186 | bool uc_update; |
| 6187 | |
| 6188 | netif_addr_lock_bh(dev); |
| 6189 | uc_update = bnxt_uc_list_updated(bp); |
| 6190 | netif_addr_unlock_bh(dev); |
| 6191 | |
| 6192 | if (!uc_update) |
| 6193 | goto skip_uc; |
| 6194 | |
| 6195 | mutex_lock(&bp->hwrm_cmd_lock); |
| 6196 | for (i = 1; i < vnic->uc_filter_count; i++) { |
| 6197 | struct hwrm_cfa_l2_filter_free_input req = {0}; |
| 6198 | |
| 6199 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_L2_FILTER_FREE, -1, |
| 6200 | -1); |
| 6201 | |
| 6202 | req.l2_filter_id = vnic->fw_l2_filter_id[i]; |
| 6203 | |
| 6204 | rc = _hwrm_send_message(bp, &req, sizeof(req), |
| 6205 | HWRM_CMD_TIMEOUT); |
| 6206 | } |
| 6207 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 6208 | |
| 6209 | vnic->uc_filter_count = 1; |
| 6210 | |
| 6211 | netif_addr_lock_bh(dev); |
| 6212 | if (netdev_uc_count(dev) > (BNXT_MAX_UC_ADDRS - 1)) { |
| 6213 | vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS; |
| 6214 | } else { |
| 6215 | netdev_for_each_uc_addr(ha, dev) { |
| 6216 | memcpy(vnic->uc_list + off, ha->addr, ETH_ALEN); |
| 6217 | off += ETH_ALEN; |
| 6218 | vnic->uc_filter_count++; |
| 6219 | } |
| 6220 | } |
| 6221 | netif_addr_unlock_bh(dev); |
| 6222 | |
| 6223 | for (i = 1, off = 0; i < vnic->uc_filter_count; i++, off += ETH_ALEN) { |
| 6224 | rc = bnxt_hwrm_set_vnic_filter(bp, 0, i, vnic->uc_list + off); |
| 6225 | if (rc) { |
| 6226 | netdev_err(bp->dev, "HWRM vnic filter failure rc: %x\n", |
| 6227 | rc); |
| 6228 | vnic->uc_filter_count = i; |
Michael Chan | b664f00 | 2015-12-02 01:54:08 -0500 | [diff] [blame] | 6229 | return rc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6230 | } |
| 6231 | } |
| 6232 | |
| 6233 | skip_uc: |
| 6234 | rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, 0); |
| 6235 | if (rc) |
| 6236 | netdev_err(bp->dev, "HWRM cfa l2 rx mask failure rc: %x\n", |
| 6237 | rc); |
Michael Chan | b664f00 | 2015-12-02 01:54:08 -0500 | [diff] [blame] | 6238 | |
| 6239 | return rc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6240 | } |
| 6241 | |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 6242 | /* If the chip and firmware supports RFS */ |
| 6243 | static bool bnxt_rfs_supported(struct bnxt *bp) |
| 6244 | { |
| 6245 | if (BNXT_PF(bp) && !BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 6246 | return true; |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 6247 | if (bp->flags & BNXT_FLAG_NEW_RSS_CAP) |
| 6248 | return true; |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 6249 | return false; |
| 6250 | } |
| 6251 | |
| 6252 | /* If runtime conditions support RFS */ |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 6253 | static bool bnxt_rfs_capable(struct bnxt *bp) |
| 6254 | { |
| 6255 | #ifdef CONFIG_RFS_ACCEL |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 6256 | int vnics, max_vnics, max_rss_ctxs; |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 6257 | |
| 6258 | if (BNXT_VF(bp) || !(bp->flags & BNXT_FLAG_MSIX_CAP)) |
| 6259 | return false; |
| 6260 | |
| 6261 | vnics = 1 + bp->rx_nr_rings; |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 6262 | max_vnics = bnxt_get_max_func_vnics(bp); |
| 6263 | max_rss_ctxs = bnxt_get_max_func_rss_ctxs(bp); |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 6264 | |
| 6265 | /* RSS contexts not a limiting factor */ |
| 6266 | if (bp->flags & BNXT_FLAG_NEW_RSS_CAP) |
| 6267 | max_rss_ctxs = max_vnics; |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 6268 | if (vnics > max_vnics || vnics > max_rss_ctxs) { |
Vasundhara Volam | a230490 | 2016-07-25 12:33:36 -0400 | [diff] [blame] | 6269 | netdev_warn(bp->dev, |
| 6270 | "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] | 6271 | min(max_rss_ctxs - 1, max_vnics - 1)); |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 6272 | return false; |
Vasundhara Volam | a230490 | 2016-07-25 12:33:36 -0400 | [diff] [blame] | 6273 | } |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 6274 | |
| 6275 | return true; |
| 6276 | #else |
| 6277 | return false; |
| 6278 | #endif |
| 6279 | } |
| 6280 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6281 | static netdev_features_t bnxt_fix_features(struct net_device *dev, |
| 6282 | netdev_features_t features) |
| 6283 | { |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 6284 | struct bnxt *bp = netdev_priv(dev); |
| 6285 | |
Vasundhara Volam | a230490 | 2016-07-25 12:33:36 -0400 | [diff] [blame] | 6286 | if ((features & NETIF_F_NTUPLE) && !bnxt_rfs_capable(bp)) |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 6287 | features &= ~NETIF_F_NTUPLE; |
Michael Chan | 5a9f6b2 | 2016-06-06 02:37:15 -0400 | [diff] [blame] | 6288 | |
| 6289 | /* Both CTAG and STAG VLAN accelaration on the RX side have to be |
| 6290 | * turned on or off together. |
| 6291 | */ |
| 6292 | if ((features & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX)) != |
| 6293 | (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX)) { |
| 6294 | if (dev->features & NETIF_F_HW_VLAN_CTAG_RX) |
| 6295 | features &= ~(NETIF_F_HW_VLAN_CTAG_RX | |
| 6296 | NETIF_F_HW_VLAN_STAG_RX); |
| 6297 | else |
| 6298 | features |= NETIF_F_HW_VLAN_CTAG_RX | |
| 6299 | NETIF_F_HW_VLAN_STAG_RX; |
| 6300 | } |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 6301 | #ifdef CONFIG_BNXT_SRIOV |
| 6302 | if (BNXT_VF(bp)) { |
| 6303 | if (bp->vf.vlan) { |
| 6304 | features &= ~(NETIF_F_HW_VLAN_CTAG_RX | |
| 6305 | NETIF_F_HW_VLAN_STAG_RX); |
| 6306 | } |
| 6307 | } |
| 6308 | #endif |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6309 | return features; |
| 6310 | } |
| 6311 | |
| 6312 | static int bnxt_set_features(struct net_device *dev, netdev_features_t features) |
| 6313 | { |
| 6314 | struct bnxt *bp = netdev_priv(dev); |
| 6315 | u32 flags = bp->flags; |
| 6316 | u32 changes; |
| 6317 | int rc = 0; |
| 6318 | bool re_init = false; |
| 6319 | bool update_tpa = false; |
| 6320 | |
| 6321 | flags &= ~BNXT_FLAG_ALL_CONFIG_FEATS; |
Prashant Sreedharan | 3e8060f | 2016-07-18 07:15:20 -0400 | [diff] [blame] | 6322 | if ((features & NETIF_F_GRO) && !BNXT_CHIP_TYPE_NITRO_A0(bp)) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6323 | flags |= BNXT_FLAG_GRO; |
| 6324 | if (features & NETIF_F_LRO) |
| 6325 | flags |= BNXT_FLAG_LRO; |
| 6326 | |
Michael Chan | bdbd1eb | 2016-12-29 12:13:43 -0500 | [diff] [blame] | 6327 | if (bp->flags & BNXT_FLAG_NO_AGG_RINGS) |
| 6328 | flags &= ~BNXT_FLAG_TPA; |
| 6329 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6330 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 6331 | flags |= BNXT_FLAG_STRIP_VLAN; |
| 6332 | |
| 6333 | if (features & NETIF_F_NTUPLE) |
| 6334 | flags |= BNXT_FLAG_RFS; |
| 6335 | |
| 6336 | changes = flags ^ bp->flags; |
| 6337 | if (changes & BNXT_FLAG_TPA) { |
| 6338 | update_tpa = true; |
| 6339 | if ((bp->flags & BNXT_FLAG_TPA) == 0 || |
| 6340 | (flags & BNXT_FLAG_TPA) == 0) |
| 6341 | re_init = true; |
| 6342 | } |
| 6343 | |
| 6344 | if (changes & ~BNXT_FLAG_TPA) |
| 6345 | re_init = true; |
| 6346 | |
| 6347 | if (flags != bp->flags) { |
| 6348 | u32 old_flags = bp->flags; |
| 6349 | |
| 6350 | bp->flags = flags; |
| 6351 | |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 6352 | if (!test_bit(BNXT_STATE_OPEN, &bp->state)) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6353 | if (update_tpa) |
| 6354 | bnxt_set_ring_params(bp); |
| 6355 | return rc; |
| 6356 | } |
| 6357 | |
| 6358 | if (re_init) { |
| 6359 | bnxt_close_nic(bp, false, false); |
| 6360 | if (update_tpa) |
| 6361 | bnxt_set_ring_params(bp); |
| 6362 | |
| 6363 | return bnxt_open_nic(bp, false, false); |
| 6364 | } |
| 6365 | if (update_tpa) { |
| 6366 | rc = bnxt_set_tpa(bp, |
| 6367 | (flags & BNXT_FLAG_TPA) ? |
| 6368 | true : false); |
| 6369 | if (rc) |
| 6370 | bp->flags = old_flags; |
| 6371 | } |
| 6372 | } |
| 6373 | return rc; |
| 6374 | } |
| 6375 | |
Michael Chan | 9f55459 | 2016-01-02 23:44:58 -0500 | [diff] [blame] | 6376 | static void bnxt_dump_tx_sw_state(struct bnxt_napi *bnapi) |
| 6377 | { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 6378 | struct bnxt_tx_ring_info *txr = bnapi->tx_ring; |
Michael Chan | 9f55459 | 2016-01-02 23:44:58 -0500 | [diff] [blame] | 6379 | int i = bnapi->index; |
| 6380 | |
Michael Chan | 3b2b7d9 | 2016-01-02 23:45:00 -0500 | [diff] [blame] | 6381 | if (!txr) |
| 6382 | return; |
| 6383 | |
Michael Chan | 9f55459 | 2016-01-02 23:44:58 -0500 | [diff] [blame] | 6384 | netdev_info(bnapi->bp->dev, "[%d]: tx{fw_ring: %d prod: %x cons: %x}\n", |
| 6385 | i, txr->tx_ring_struct.fw_ring_id, txr->tx_prod, |
| 6386 | txr->tx_cons); |
| 6387 | } |
| 6388 | |
| 6389 | static void bnxt_dump_rx_sw_state(struct bnxt_napi *bnapi) |
| 6390 | { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 6391 | struct bnxt_rx_ring_info *rxr = bnapi->rx_ring; |
Michael Chan | 9f55459 | 2016-01-02 23:44:58 -0500 | [diff] [blame] | 6392 | int i = bnapi->index; |
| 6393 | |
Michael Chan | 3b2b7d9 | 2016-01-02 23:45:00 -0500 | [diff] [blame] | 6394 | if (!rxr) |
| 6395 | return; |
| 6396 | |
Michael Chan | 9f55459 | 2016-01-02 23:44:58 -0500 | [diff] [blame] | 6397 | 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", |
| 6398 | i, rxr->rx_ring_struct.fw_ring_id, rxr->rx_prod, |
| 6399 | rxr->rx_agg_ring_struct.fw_ring_id, rxr->rx_agg_prod, |
| 6400 | rxr->rx_sw_agg_prod); |
| 6401 | } |
| 6402 | |
| 6403 | static void bnxt_dump_cp_sw_state(struct bnxt_napi *bnapi) |
| 6404 | { |
| 6405 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 6406 | int i = bnapi->index; |
| 6407 | |
| 6408 | netdev_info(bnapi->bp->dev, "[%d]: cp{fw_ring: %d raw_cons: %x}\n", |
| 6409 | i, cpr->cp_ring_struct.fw_ring_id, cpr->cp_raw_cons); |
| 6410 | } |
| 6411 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6412 | static void bnxt_dbg_dump_states(struct bnxt *bp) |
| 6413 | { |
| 6414 | int i; |
| 6415 | struct bnxt_napi *bnapi; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6416 | |
| 6417 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 6418 | bnapi = bp->bnapi[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6419 | if (netif_msg_drv(bp)) { |
Michael Chan | 9f55459 | 2016-01-02 23:44:58 -0500 | [diff] [blame] | 6420 | bnxt_dump_tx_sw_state(bnapi); |
| 6421 | bnxt_dump_rx_sw_state(bnapi); |
| 6422 | bnxt_dump_cp_sw_state(bnapi); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6423 | } |
| 6424 | } |
| 6425 | } |
| 6426 | |
Michael Chan | 6988bd9 | 2016-06-13 02:25:29 -0400 | [diff] [blame] | 6427 | static void bnxt_reset_task(struct bnxt *bp, bool silent) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6428 | { |
Michael Chan | 6988bd9 | 2016-06-13 02:25:29 -0400 | [diff] [blame] | 6429 | if (!silent) |
| 6430 | bnxt_dbg_dump_states(bp); |
Michael Chan | 028de14 | 2015-12-09 19:35:44 -0500 | [diff] [blame] | 6431 | if (netif_running(bp->dev)) { |
| 6432 | bnxt_close_nic(bp, false, false); |
| 6433 | bnxt_open_nic(bp, false, false); |
| 6434 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6435 | } |
| 6436 | |
| 6437 | static void bnxt_tx_timeout(struct net_device *dev) |
| 6438 | { |
| 6439 | struct bnxt *bp = netdev_priv(dev); |
| 6440 | |
| 6441 | netdev_err(bp->dev, "TX timeout detected, starting reset task!\n"); |
| 6442 | set_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event); |
| 6443 | schedule_work(&bp->sp_task); |
| 6444 | } |
| 6445 | |
| 6446 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 6447 | static void bnxt_poll_controller(struct net_device *dev) |
| 6448 | { |
| 6449 | struct bnxt *bp = netdev_priv(dev); |
| 6450 | int i; |
| 6451 | |
| 6452 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 6453 | struct bnxt_irq *irq = &bp->irq_tbl[i]; |
| 6454 | |
| 6455 | disable_irq(irq->vector); |
| 6456 | irq->handler(irq->vector, bp->bnapi[i]); |
| 6457 | enable_irq(irq->vector); |
| 6458 | } |
| 6459 | } |
| 6460 | #endif |
| 6461 | |
| 6462 | static void bnxt_timer(unsigned long data) |
| 6463 | { |
| 6464 | struct bnxt *bp = (struct bnxt *)data; |
| 6465 | struct net_device *dev = bp->dev; |
| 6466 | |
| 6467 | if (!netif_running(dev)) |
| 6468 | return; |
| 6469 | |
| 6470 | if (atomic_read(&bp->intr_sem) != 0) |
| 6471 | goto bnxt_restart_timer; |
| 6472 | |
Michael Chan | 3bdf56c | 2016-03-07 15:38:45 -0500 | [diff] [blame] | 6473 | if (bp->link_info.link_up && (bp->flags & BNXT_FLAG_PORT_STATS)) { |
| 6474 | set_bit(BNXT_PERIODIC_STATS_SP_EVENT, &bp->sp_event); |
| 6475 | schedule_work(&bp->sp_task); |
| 6476 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6477 | bnxt_restart_timer: |
| 6478 | mod_timer(&bp->timer, jiffies + bp->current_interval); |
| 6479 | } |
| 6480 | |
Michael Chan | a551ee9 | 2017-01-25 02:55:07 -0500 | [diff] [blame] | 6481 | static void bnxt_rtnl_lock_sp(struct bnxt *bp) |
Michael Chan | 6988bd9 | 2016-06-13 02:25:29 -0400 | [diff] [blame] | 6482 | { |
Michael Chan | a551ee9 | 2017-01-25 02:55:07 -0500 | [diff] [blame] | 6483 | /* We are called from bnxt_sp_task which has BNXT_STATE_IN_SP_TASK |
| 6484 | * set. If the device is being closed, bnxt_close() may be holding |
Michael Chan | 6988bd9 | 2016-06-13 02:25:29 -0400 | [diff] [blame] | 6485 | * rtnl() and waiting for BNXT_STATE_IN_SP_TASK to clear. So we |
| 6486 | * must clear BNXT_STATE_IN_SP_TASK before holding rtnl(). |
| 6487 | */ |
| 6488 | clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state); |
| 6489 | rtnl_lock(); |
Michael Chan | a551ee9 | 2017-01-25 02:55:07 -0500 | [diff] [blame] | 6490 | } |
| 6491 | |
| 6492 | static void bnxt_rtnl_unlock_sp(struct bnxt *bp) |
| 6493 | { |
Michael Chan | 6988bd9 | 2016-06-13 02:25:29 -0400 | [diff] [blame] | 6494 | set_bit(BNXT_STATE_IN_SP_TASK, &bp->state); |
| 6495 | rtnl_unlock(); |
| 6496 | } |
| 6497 | |
Michael Chan | a551ee9 | 2017-01-25 02:55:07 -0500 | [diff] [blame] | 6498 | /* Only called from bnxt_sp_task() */ |
| 6499 | static void bnxt_reset(struct bnxt *bp, bool silent) |
| 6500 | { |
| 6501 | bnxt_rtnl_lock_sp(bp); |
| 6502 | if (test_bit(BNXT_STATE_OPEN, &bp->state)) |
| 6503 | bnxt_reset_task(bp, silent); |
| 6504 | bnxt_rtnl_unlock_sp(bp); |
| 6505 | } |
| 6506 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6507 | static void bnxt_cfg_ntp_filters(struct bnxt *); |
| 6508 | |
| 6509 | static void bnxt_sp_task(struct work_struct *work) |
| 6510 | { |
| 6511 | struct bnxt *bp = container_of(work, struct bnxt, sp_task); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6512 | |
Michael Chan | 4cebdce | 2015-12-09 19:35:43 -0500 | [diff] [blame] | 6513 | set_bit(BNXT_STATE_IN_SP_TASK, &bp->state); |
| 6514 | smp_mb__after_atomic(); |
| 6515 | if (!test_bit(BNXT_STATE_OPEN, &bp->state)) { |
| 6516 | clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6517 | return; |
Michael Chan | 4cebdce | 2015-12-09 19:35:43 -0500 | [diff] [blame] | 6518 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6519 | |
| 6520 | if (test_and_clear_bit(BNXT_RX_MASK_SP_EVENT, &bp->sp_event)) |
| 6521 | bnxt_cfg_rx_mode(bp); |
| 6522 | |
| 6523 | if (test_and_clear_bit(BNXT_RX_NTP_FLTR_SP_EVENT, &bp->sp_event)) |
| 6524 | bnxt_cfg_ntp_filters(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6525 | if (test_and_clear_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT, &bp->sp_event)) |
| 6526 | bnxt_hwrm_exec_fwd_req(bp); |
| 6527 | if (test_and_clear_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT, &bp->sp_event)) { |
| 6528 | bnxt_hwrm_tunnel_dst_port_alloc( |
| 6529 | bp, bp->vxlan_port, |
| 6530 | TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN); |
| 6531 | } |
| 6532 | if (test_and_clear_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT, &bp->sp_event)) { |
| 6533 | bnxt_hwrm_tunnel_dst_port_free( |
| 6534 | bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN); |
| 6535 | } |
Alexander Duyck | 7cdd5fc | 2016-06-16 12:21:36 -0700 | [diff] [blame] | 6536 | if (test_and_clear_bit(BNXT_GENEVE_ADD_PORT_SP_EVENT, &bp->sp_event)) { |
| 6537 | bnxt_hwrm_tunnel_dst_port_alloc( |
| 6538 | bp, bp->nge_port, |
| 6539 | TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE); |
| 6540 | } |
| 6541 | if (test_and_clear_bit(BNXT_GENEVE_DEL_PORT_SP_EVENT, &bp->sp_event)) { |
| 6542 | bnxt_hwrm_tunnel_dst_port_free( |
| 6543 | bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE); |
| 6544 | } |
Michael Chan | 3bdf56c | 2016-03-07 15:38:45 -0500 | [diff] [blame] | 6545 | if (test_and_clear_bit(BNXT_PERIODIC_STATS_SP_EVENT, &bp->sp_event)) |
| 6546 | bnxt_hwrm_port_qstats(bp); |
| 6547 | |
Michael Chan | a551ee9 | 2017-01-25 02:55:07 -0500 | [diff] [blame] | 6548 | /* These functions below will clear BNXT_STATE_IN_SP_TASK. They |
| 6549 | * must be the last functions to be called before exiting. |
| 6550 | */ |
Michael Chan | 0eaa24b | 2017-01-25 02:55:08 -0500 | [diff] [blame] | 6551 | if (test_and_clear_bit(BNXT_LINK_CHNG_SP_EVENT, &bp->sp_event)) { |
| 6552 | int rc = 0; |
| 6553 | |
| 6554 | if (test_and_clear_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT, |
| 6555 | &bp->sp_event)) |
| 6556 | bnxt_hwrm_phy_qcaps(bp); |
| 6557 | |
| 6558 | bnxt_rtnl_lock_sp(bp); |
| 6559 | if (test_bit(BNXT_STATE_OPEN, &bp->state)) |
| 6560 | rc = bnxt_update_link(bp, true); |
| 6561 | bnxt_rtnl_unlock_sp(bp); |
| 6562 | if (rc) |
| 6563 | netdev_err(bp->dev, "SP task can't update link (rc: %x)\n", |
| 6564 | rc); |
| 6565 | } |
Michael Chan | 90c694b | 2017-01-25 02:55:09 -0500 | [diff] [blame] | 6566 | if (test_and_clear_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT, &bp->sp_event)) { |
| 6567 | bnxt_rtnl_lock_sp(bp); |
| 6568 | if (test_bit(BNXT_STATE_OPEN, &bp->state)) |
| 6569 | bnxt_get_port_module_status(bp); |
| 6570 | bnxt_rtnl_unlock_sp(bp); |
| 6571 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6572 | if (test_and_clear_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event)) |
| 6573 | bnxt_reset(bp, false); |
| 6574 | |
| 6575 | if (test_and_clear_bit(BNXT_RESET_TASK_SILENT_SP_EVENT, &bp->sp_event)) |
| 6576 | bnxt_reset(bp, true); |
| 6577 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6578 | smp_mb__before_atomic(); |
| 6579 | clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state); |
| 6580 | } |
| 6581 | |
| 6582 | static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev) |
| 6583 | { |
| 6584 | int rc; |
| 6585 | struct bnxt *bp = netdev_priv(dev); |
| 6586 | |
| 6587 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 6588 | |
| 6589 | /* enable device (incl. PCI PM wakeup), and bus-mastering */ |
| 6590 | rc = pci_enable_device(pdev); |
| 6591 | if (rc) { |
| 6592 | dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n"); |
| 6593 | goto init_err; |
| 6594 | } |
| 6595 | |
| 6596 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { |
| 6597 | dev_err(&pdev->dev, |
| 6598 | "Cannot find PCI device base address, aborting\n"); |
| 6599 | rc = -ENODEV; |
| 6600 | goto init_err_disable; |
| 6601 | } |
| 6602 | |
| 6603 | rc = pci_request_regions(pdev, DRV_MODULE_NAME); |
| 6604 | if (rc) { |
| 6605 | dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting\n"); |
| 6606 | goto init_err_disable; |
| 6607 | } |
| 6608 | |
| 6609 | if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)) != 0 && |
| 6610 | dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)) != 0) { |
| 6611 | dev_err(&pdev->dev, "System does not support DMA, aborting\n"); |
| 6612 | goto init_err_disable; |
| 6613 | } |
| 6614 | |
| 6615 | pci_set_master(pdev); |
| 6616 | |
| 6617 | bp->dev = dev; |
| 6618 | bp->pdev = pdev; |
| 6619 | |
| 6620 | bp->bar0 = pci_ioremap_bar(pdev, 0); |
| 6621 | if (!bp->bar0) { |
| 6622 | dev_err(&pdev->dev, "Cannot map device registers, aborting\n"); |
| 6623 | rc = -ENOMEM; |
| 6624 | goto init_err_release; |
| 6625 | } |
| 6626 | |
| 6627 | bp->bar1 = pci_ioremap_bar(pdev, 2); |
| 6628 | if (!bp->bar1) { |
| 6629 | dev_err(&pdev->dev, "Cannot map doorbell registers, aborting\n"); |
| 6630 | rc = -ENOMEM; |
| 6631 | goto init_err_release; |
| 6632 | } |
| 6633 | |
| 6634 | bp->bar2 = pci_ioremap_bar(pdev, 4); |
| 6635 | if (!bp->bar2) { |
| 6636 | dev_err(&pdev->dev, "Cannot map bar4 registers, aborting\n"); |
| 6637 | rc = -ENOMEM; |
| 6638 | goto init_err_release; |
| 6639 | } |
| 6640 | |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 6641 | pci_enable_pcie_error_reporting(pdev); |
| 6642 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6643 | INIT_WORK(&bp->sp_task, bnxt_sp_task); |
| 6644 | |
| 6645 | spin_lock_init(&bp->ntp_fltr_lock); |
| 6646 | |
| 6647 | bp->rx_ring_size = BNXT_DEFAULT_RX_RING_SIZE; |
| 6648 | bp->tx_ring_size = BNXT_DEFAULT_TX_RING_SIZE; |
| 6649 | |
Michael Chan | dfb5b89 | 2016-02-26 04:00:01 -0500 | [diff] [blame] | 6650 | /* tick values in micro seconds */ |
Michael Chan | dfc9c94 | 2016-02-26 04:00:03 -0500 | [diff] [blame] | 6651 | bp->rx_coal_ticks = 12; |
| 6652 | bp->rx_coal_bufs = 30; |
Michael Chan | dfb5b89 | 2016-02-26 04:00:01 -0500 | [diff] [blame] | 6653 | bp->rx_coal_ticks_irq = 1; |
| 6654 | bp->rx_coal_bufs_irq = 2; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6655 | |
Michael Chan | dfc9c94 | 2016-02-26 04:00:03 -0500 | [diff] [blame] | 6656 | bp->tx_coal_ticks = 25; |
| 6657 | bp->tx_coal_bufs = 30; |
| 6658 | bp->tx_coal_ticks_irq = 2; |
| 6659 | bp->tx_coal_bufs_irq = 2; |
| 6660 | |
Michael Chan | 51f3078 | 2016-07-01 18:46:29 -0400 | [diff] [blame] | 6661 | bp->stats_coal_ticks = BNXT_DEF_STATS_COAL_TICKS; |
| 6662 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6663 | init_timer(&bp->timer); |
| 6664 | bp->timer.data = (unsigned long)bp; |
| 6665 | bp->timer.function = bnxt_timer; |
| 6666 | bp->current_interval = BNXT_TIMER_INTERVAL; |
| 6667 | |
Michael Chan | caefe52 | 2015-12-09 19:35:42 -0500 | [diff] [blame] | 6668 | clear_bit(BNXT_STATE_OPEN, &bp->state); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6669 | |
| 6670 | return 0; |
| 6671 | |
| 6672 | init_err_release: |
| 6673 | if (bp->bar2) { |
| 6674 | pci_iounmap(pdev, bp->bar2); |
| 6675 | bp->bar2 = NULL; |
| 6676 | } |
| 6677 | |
| 6678 | if (bp->bar1) { |
| 6679 | pci_iounmap(pdev, bp->bar1); |
| 6680 | bp->bar1 = NULL; |
| 6681 | } |
| 6682 | |
| 6683 | if (bp->bar0) { |
| 6684 | pci_iounmap(pdev, bp->bar0); |
| 6685 | bp->bar0 = NULL; |
| 6686 | } |
| 6687 | |
| 6688 | pci_release_regions(pdev); |
| 6689 | |
| 6690 | init_err_disable: |
| 6691 | pci_disable_device(pdev); |
| 6692 | |
| 6693 | init_err: |
| 6694 | return rc; |
| 6695 | } |
| 6696 | |
| 6697 | /* rtnl_lock held */ |
| 6698 | static int bnxt_change_mac_addr(struct net_device *dev, void *p) |
| 6699 | { |
| 6700 | struct sockaddr *addr = p; |
Jeffrey Huang | 1fc2cfd | 2015-12-02 01:54:06 -0500 | [diff] [blame] | 6701 | struct bnxt *bp = netdev_priv(dev); |
| 6702 | int rc = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6703 | |
| 6704 | if (!is_valid_ether_addr(addr->sa_data)) |
| 6705 | return -EADDRNOTAVAIL; |
| 6706 | |
Michael Chan | 84c33dd | 2016-04-11 04:11:13 -0400 | [diff] [blame] | 6707 | rc = bnxt_approve_mac(bp, addr->sa_data); |
| 6708 | if (rc) |
| 6709 | return rc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6710 | |
Jeffrey Huang | 1fc2cfd | 2015-12-02 01:54:06 -0500 | [diff] [blame] | 6711 | if (ether_addr_equal(addr->sa_data, dev->dev_addr)) |
| 6712 | return 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6713 | |
Jeffrey Huang | 1fc2cfd | 2015-12-02 01:54:06 -0500 | [diff] [blame] | 6714 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
| 6715 | if (netif_running(dev)) { |
| 6716 | bnxt_close_nic(bp, false, false); |
| 6717 | rc = bnxt_open_nic(bp, false, false); |
| 6718 | } |
| 6719 | |
| 6720 | return rc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6721 | } |
| 6722 | |
| 6723 | /* rtnl_lock held */ |
| 6724 | static int bnxt_change_mtu(struct net_device *dev, int new_mtu) |
| 6725 | { |
| 6726 | struct bnxt *bp = netdev_priv(dev); |
| 6727 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6728 | if (netif_running(dev)) |
| 6729 | bnxt_close_nic(bp, false, false); |
| 6730 | |
| 6731 | dev->mtu = new_mtu; |
| 6732 | bnxt_set_ring_params(bp); |
| 6733 | |
| 6734 | if (netif_running(dev)) |
| 6735 | return bnxt_open_nic(bp, false, false); |
| 6736 | |
| 6737 | return 0; |
| 6738 | } |
| 6739 | |
Michael Chan | c5e3deb | 2016-12-02 21:17:15 -0500 | [diff] [blame] | 6740 | int bnxt_setup_mq_tc(struct net_device *dev, u8 tc) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6741 | { |
| 6742 | struct bnxt *bp = netdev_priv(dev); |
Michael Chan | 3ffb6a3 | 2016-11-11 00:11:42 -0500 | [diff] [blame] | 6743 | bool sh = false; |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 6744 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6745 | if (tc > bp->max_tc) { |
| 6746 | netdev_err(dev, "too many traffic classes requested: %d Max supported is %d\n", |
| 6747 | tc, bp->max_tc); |
| 6748 | return -EINVAL; |
| 6749 | } |
| 6750 | |
| 6751 | if (netdev_get_num_tc(dev) == tc) |
| 6752 | return 0; |
| 6753 | |
Michael Chan | 3ffb6a3 | 2016-11-11 00:11:42 -0500 | [diff] [blame] | 6754 | if (bp->flags & BNXT_FLAG_SHARED_RINGS) |
| 6755 | sh = true; |
| 6756 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6757 | if (tc) { |
Michael Chan | 391be5c | 2016-12-29 12:13:41 -0500 | [diff] [blame] | 6758 | 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] | 6759 | |
Michael Chan | 391be5c | 2016-12-29 12:13:41 -0500 | [diff] [blame] | 6760 | req_tx_rings = bp->tx_nr_rings_per_tc * tc; |
Michael Chan | 01657bc | 2016-01-02 23:45:03 -0500 | [diff] [blame] | 6761 | 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] | 6762 | if (rc || req_tx_rings > max_tx_rings) |
| 6763 | return -ENOMEM; |
| 6764 | |
| 6765 | rsv_tx_rings = req_tx_rings; |
| 6766 | if (bnxt_hwrm_reserve_tx_rings(bp, &rsv_tx_rings) || |
| 6767 | rsv_tx_rings < req_tx_rings) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6768 | return -ENOMEM; |
| 6769 | } |
| 6770 | |
| 6771 | /* Needs to close the device and do hw resource re-allocations */ |
| 6772 | if (netif_running(bp->dev)) |
| 6773 | bnxt_close_nic(bp, true, false); |
| 6774 | |
| 6775 | if (tc) { |
| 6776 | bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tc; |
| 6777 | netdev_set_num_tc(dev, tc); |
| 6778 | } else { |
| 6779 | bp->tx_nr_rings = bp->tx_nr_rings_per_tc; |
| 6780 | netdev_reset_tc(dev); |
| 6781 | } |
Michael Chan | 3ffb6a3 | 2016-11-11 00:11:42 -0500 | [diff] [blame] | 6782 | bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) : |
| 6783 | bp->tx_nr_rings + bp->rx_nr_rings; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6784 | bp->num_stat_ctxs = bp->cp_nr_rings; |
| 6785 | |
| 6786 | if (netif_running(bp->dev)) |
| 6787 | return bnxt_open_nic(bp, true, false); |
| 6788 | |
| 6789 | return 0; |
| 6790 | } |
| 6791 | |
Michael Chan | c5e3deb | 2016-12-02 21:17:15 -0500 | [diff] [blame] | 6792 | static int bnxt_setup_tc(struct net_device *dev, u32 handle, __be16 proto, |
| 6793 | struct tc_to_netdev *ntc) |
| 6794 | { |
| 6795 | if (ntc->type != TC_SETUP_MQPRIO) |
| 6796 | return -EINVAL; |
| 6797 | |
| 6798 | return bnxt_setup_mq_tc(dev, ntc->tc); |
| 6799 | } |
| 6800 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6801 | #ifdef CONFIG_RFS_ACCEL |
| 6802 | static bool bnxt_fltr_match(struct bnxt_ntuple_filter *f1, |
| 6803 | struct bnxt_ntuple_filter *f2) |
| 6804 | { |
| 6805 | struct flow_keys *keys1 = &f1->fkeys; |
| 6806 | struct flow_keys *keys2 = &f2->fkeys; |
| 6807 | |
| 6808 | if (keys1->addrs.v4addrs.src == keys2->addrs.v4addrs.src && |
| 6809 | keys1->addrs.v4addrs.dst == keys2->addrs.v4addrs.dst && |
| 6810 | keys1->ports.ports == keys2->ports.ports && |
| 6811 | keys1->basic.ip_proto == keys2->basic.ip_proto && |
| 6812 | keys1->basic.n_proto == keys2->basic.n_proto && |
Michael Chan | a54c4d7 | 2016-07-25 12:33:35 -0400 | [diff] [blame] | 6813 | ether_addr_equal(f1->src_mac_addr, f2->src_mac_addr) && |
| 6814 | ether_addr_equal(f1->dst_mac_addr, f2->dst_mac_addr)) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6815 | return true; |
| 6816 | |
| 6817 | return false; |
| 6818 | } |
| 6819 | |
| 6820 | static int bnxt_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb, |
| 6821 | u16 rxq_index, u32 flow_id) |
| 6822 | { |
| 6823 | struct bnxt *bp = netdev_priv(dev); |
| 6824 | struct bnxt_ntuple_filter *fltr, *new_fltr; |
| 6825 | struct flow_keys *fkeys; |
| 6826 | struct ethhdr *eth = (struct ethhdr *)skb_mac_header(skb); |
Michael Chan | a54c4d7 | 2016-07-25 12:33:35 -0400 | [diff] [blame] | 6827 | int rc = 0, idx, bit_id, l2_idx = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6828 | struct hlist_head *head; |
| 6829 | |
| 6830 | if (skb->encapsulation) |
| 6831 | return -EPROTONOSUPPORT; |
| 6832 | |
Michael Chan | a54c4d7 | 2016-07-25 12:33:35 -0400 | [diff] [blame] | 6833 | if (!ether_addr_equal(dev->dev_addr, eth->h_dest)) { |
| 6834 | struct bnxt_vnic_info *vnic = &bp->vnic_info[0]; |
| 6835 | int off = 0, j; |
| 6836 | |
| 6837 | netif_addr_lock_bh(dev); |
| 6838 | for (j = 0; j < vnic->uc_filter_count; j++, off += ETH_ALEN) { |
| 6839 | if (ether_addr_equal(eth->h_dest, |
| 6840 | vnic->uc_list + off)) { |
| 6841 | l2_idx = j + 1; |
| 6842 | break; |
| 6843 | } |
| 6844 | } |
| 6845 | netif_addr_unlock_bh(dev); |
| 6846 | if (!l2_idx) |
| 6847 | return -EINVAL; |
| 6848 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6849 | new_fltr = kzalloc(sizeof(*new_fltr), GFP_ATOMIC); |
| 6850 | if (!new_fltr) |
| 6851 | return -ENOMEM; |
| 6852 | |
| 6853 | fkeys = &new_fltr->fkeys; |
| 6854 | if (!skb_flow_dissect_flow_keys(skb, fkeys, 0)) { |
| 6855 | rc = -EPROTONOSUPPORT; |
| 6856 | goto err_free; |
| 6857 | } |
| 6858 | |
Michael Chan | dda0e74 | 2016-12-29 12:13:40 -0500 | [diff] [blame] | 6859 | if ((fkeys->basic.n_proto != htons(ETH_P_IP) && |
| 6860 | fkeys->basic.n_proto != htons(ETH_P_IPV6)) || |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6861 | ((fkeys->basic.ip_proto != IPPROTO_TCP) && |
| 6862 | (fkeys->basic.ip_proto != IPPROTO_UDP))) { |
| 6863 | rc = -EPROTONOSUPPORT; |
| 6864 | goto err_free; |
| 6865 | } |
Michael Chan | dda0e74 | 2016-12-29 12:13:40 -0500 | [diff] [blame] | 6866 | if (fkeys->basic.n_proto == htons(ETH_P_IPV6) && |
| 6867 | bp->hwrm_spec_code < 0x10601) { |
| 6868 | rc = -EPROTONOSUPPORT; |
| 6869 | goto err_free; |
| 6870 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6871 | |
Michael Chan | a54c4d7 | 2016-07-25 12:33:35 -0400 | [diff] [blame] | 6872 | memcpy(new_fltr->dst_mac_addr, eth->h_dest, ETH_ALEN); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6873 | memcpy(new_fltr->src_mac_addr, eth->h_source, ETH_ALEN); |
| 6874 | |
| 6875 | idx = skb_get_hash_raw(skb) & BNXT_NTP_FLTR_HASH_MASK; |
| 6876 | head = &bp->ntp_fltr_hash_tbl[idx]; |
| 6877 | rcu_read_lock(); |
| 6878 | hlist_for_each_entry_rcu(fltr, head, hash) { |
| 6879 | if (bnxt_fltr_match(fltr, new_fltr)) { |
| 6880 | rcu_read_unlock(); |
| 6881 | rc = 0; |
| 6882 | goto err_free; |
| 6883 | } |
| 6884 | } |
| 6885 | rcu_read_unlock(); |
| 6886 | |
| 6887 | spin_lock_bh(&bp->ntp_fltr_lock); |
Michael Chan | 84e86b9 | 2015-11-05 16:25:50 -0500 | [diff] [blame] | 6888 | bit_id = bitmap_find_free_region(bp->ntp_fltr_bmap, |
| 6889 | BNXT_NTP_FLTR_MAX_FLTR, 0); |
| 6890 | if (bit_id < 0) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6891 | spin_unlock_bh(&bp->ntp_fltr_lock); |
| 6892 | rc = -ENOMEM; |
| 6893 | goto err_free; |
| 6894 | } |
| 6895 | |
Michael Chan | 84e86b9 | 2015-11-05 16:25:50 -0500 | [diff] [blame] | 6896 | new_fltr->sw_id = (u16)bit_id; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6897 | new_fltr->flow_id = flow_id; |
Michael Chan | a54c4d7 | 2016-07-25 12:33:35 -0400 | [diff] [blame] | 6898 | new_fltr->l2_fltr_idx = l2_idx; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6899 | new_fltr->rxq = rxq_index; |
| 6900 | hlist_add_head_rcu(&new_fltr->hash, head); |
| 6901 | bp->ntp_fltr_count++; |
| 6902 | spin_unlock_bh(&bp->ntp_fltr_lock); |
| 6903 | |
| 6904 | set_bit(BNXT_RX_NTP_FLTR_SP_EVENT, &bp->sp_event); |
| 6905 | schedule_work(&bp->sp_task); |
| 6906 | |
| 6907 | return new_fltr->sw_id; |
| 6908 | |
| 6909 | err_free: |
| 6910 | kfree(new_fltr); |
| 6911 | return rc; |
| 6912 | } |
| 6913 | |
| 6914 | static void bnxt_cfg_ntp_filters(struct bnxt *bp) |
| 6915 | { |
| 6916 | int i; |
| 6917 | |
| 6918 | for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) { |
| 6919 | struct hlist_head *head; |
| 6920 | struct hlist_node *tmp; |
| 6921 | struct bnxt_ntuple_filter *fltr; |
| 6922 | int rc; |
| 6923 | |
| 6924 | head = &bp->ntp_fltr_hash_tbl[i]; |
| 6925 | hlist_for_each_entry_safe(fltr, tmp, head, hash) { |
| 6926 | bool del = false; |
| 6927 | |
| 6928 | if (test_bit(BNXT_FLTR_VALID, &fltr->state)) { |
| 6929 | if (rps_may_expire_flow(bp->dev, fltr->rxq, |
| 6930 | fltr->flow_id, |
| 6931 | fltr->sw_id)) { |
| 6932 | bnxt_hwrm_cfa_ntuple_filter_free(bp, |
| 6933 | fltr); |
| 6934 | del = true; |
| 6935 | } |
| 6936 | } else { |
| 6937 | rc = bnxt_hwrm_cfa_ntuple_filter_alloc(bp, |
| 6938 | fltr); |
| 6939 | if (rc) |
| 6940 | del = true; |
| 6941 | else |
| 6942 | set_bit(BNXT_FLTR_VALID, &fltr->state); |
| 6943 | } |
| 6944 | |
| 6945 | if (del) { |
| 6946 | spin_lock_bh(&bp->ntp_fltr_lock); |
| 6947 | hlist_del_rcu(&fltr->hash); |
| 6948 | bp->ntp_fltr_count--; |
| 6949 | spin_unlock_bh(&bp->ntp_fltr_lock); |
| 6950 | synchronize_rcu(); |
| 6951 | clear_bit(fltr->sw_id, bp->ntp_fltr_bmap); |
| 6952 | kfree(fltr); |
| 6953 | } |
| 6954 | } |
| 6955 | } |
Jeffrey Huang | 1924136 | 2016-02-26 04:00:00 -0500 | [diff] [blame] | 6956 | if (test_and_clear_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT, &bp->sp_event)) |
| 6957 | netdev_info(bp->dev, "Receive PF driver unload event!"); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6958 | } |
| 6959 | |
| 6960 | #else |
| 6961 | |
| 6962 | static void bnxt_cfg_ntp_filters(struct bnxt *bp) |
| 6963 | { |
| 6964 | } |
| 6965 | |
| 6966 | #endif /* CONFIG_RFS_ACCEL */ |
| 6967 | |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 6968 | static void bnxt_udp_tunnel_add(struct net_device *dev, |
| 6969 | struct udp_tunnel_info *ti) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6970 | { |
| 6971 | struct bnxt *bp = netdev_priv(dev); |
| 6972 | |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 6973 | if (ti->sa_family != AF_INET6 && ti->sa_family != AF_INET) |
| 6974 | return; |
| 6975 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6976 | if (!netif_running(dev)) |
| 6977 | return; |
| 6978 | |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 6979 | switch (ti->type) { |
| 6980 | case UDP_TUNNEL_TYPE_VXLAN: |
| 6981 | if (bp->vxlan_port_cnt && bp->vxlan_port != ti->port) |
| 6982 | return; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6983 | |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 6984 | bp->vxlan_port_cnt++; |
| 6985 | if (bp->vxlan_port_cnt == 1) { |
| 6986 | bp->vxlan_port = ti->port; |
| 6987 | set_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT, &bp->sp_event); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6988 | schedule_work(&bp->sp_task); |
| 6989 | } |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 6990 | break; |
Alexander Duyck | 7cdd5fc | 2016-06-16 12:21:36 -0700 | [diff] [blame] | 6991 | case UDP_TUNNEL_TYPE_GENEVE: |
| 6992 | if (bp->nge_port_cnt && bp->nge_port != ti->port) |
| 6993 | return; |
| 6994 | |
| 6995 | bp->nge_port_cnt++; |
| 6996 | if (bp->nge_port_cnt == 1) { |
| 6997 | bp->nge_port = ti->port; |
| 6998 | set_bit(BNXT_GENEVE_ADD_PORT_SP_EVENT, &bp->sp_event); |
| 6999 | } |
| 7000 | break; |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 7001 | default: |
| 7002 | return; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7003 | } |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 7004 | |
| 7005 | schedule_work(&bp->sp_task); |
| 7006 | } |
| 7007 | |
| 7008 | static void bnxt_udp_tunnel_del(struct net_device *dev, |
| 7009 | struct udp_tunnel_info *ti) |
| 7010 | { |
| 7011 | struct bnxt *bp = netdev_priv(dev); |
| 7012 | |
| 7013 | if (ti->sa_family != AF_INET6 && ti->sa_family != AF_INET) |
| 7014 | return; |
| 7015 | |
| 7016 | if (!netif_running(dev)) |
| 7017 | return; |
| 7018 | |
| 7019 | switch (ti->type) { |
| 7020 | case UDP_TUNNEL_TYPE_VXLAN: |
| 7021 | if (!bp->vxlan_port_cnt || bp->vxlan_port != ti->port) |
| 7022 | return; |
| 7023 | bp->vxlan_port_cnt--; |
| 7024 | |
| 7025 | if (bp->vxlan_port_cnt != 0) |
| 7026 | return; |
| 7027 | |
| 7028 | set_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT, &bp->sp_event); |
| 7029 | break; |
Alexander Duyck | 7cdd5fc | 2016-06-16 12:21:36 -0700 | [diff] [blame] | 7030 | case UDP_TUNNEL_TYPE_GENEVE: |
| 7031 | if (!bp->nge_port_cnt || bp->nge_port != ti->port) |
| 7032 | return; |
| 7033 | bp->nge_port_cnt--; |
| 7034 | |
| 7035 | if (bp->nge_port_cnt != 0) |
| 7036 | return; |
| 7037 | |
| 7038 | set_bit(BNXT_GENEVE_DEL_PORT_SP_EVENT, &bp->sp_event); |
| 7039 | break; |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 7040 | default: |
| 7041 | return; |
| 7042 | } |
| 7043 | |
| 7044 | schedule_work(&bp->sp_task); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7045 | } |
| 7046 | |
| 7047 | static const struct net_device_ops bnxt_netdev_ops = { |
| 7048 | .ndo_open = bnxt_open, |
| 7049 | .ndo_start_xmit = bnxt_start_xmit, |
| 7050 | .ndo_stop = bnxt_close, |
| 7051 | .ndo_get_stats64 = bnxt_get_stats64, |
| 7052 | .ndo_set_rx_mode = bnxt_set_rx_mode, |
| 7053 | .ndo_do_ioctl = bnxt_ioctl, |
| 7054 | .ndo_validate_addr = eth_validate_addr, |
| 7055 | .ndo_set_mac_address = bnxt_change_mac_addr, |
| 7056 | .ndo_change_mtu = bnxt_change_mtu, |
| 7057 | .ndo_fix_features = bnxt_fix_features, |
| 7058 | .ndo_set_features = bnxt_set_features, |
| 7059 | .ndo_tx_timeout = bnxt_tx_timeout, |
| 7060 | #ifdef CONFIG_BNXT_SRIOV |
| 7061 | .ndo_get_vf_config = bnxt_get_vf_config, |
| 7062 | .ndo_set_vf_mac = bnxt_set_vf_mac, |
| 7063 | .ndo_set_vf_vlan = bnxt_set_vf_vlan, |
| 7064 | .ndo_set_vf_rate = bnxt_set_vf_bw, |
| 7065 | .ndo_set_vf_link_state = bnxt_set_vf_link_state, |
| 7066 | .ndo_set_vf_spoofchk = bnxt_set_vf_spoofchk, |
| 7067 | #endif |
| 7068 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7069 | .ndo_poll_controller = bnxt_poll_controller, |
| 7070 | #endif |
| 7071 | .ndo_setup_tc = bnxt_setup_tc, |
| 7072 | #ifdef CONFIG_RFS_ACCEL |
| 7073 | .ndo_rx_flow_steer = bnxt_rx_flow_steer, |
| 7074 | #endif |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 7075 | .ndo_udp_tunnel_add = bnxt_udp_tunnel_add, |
| 7076 | .ndo_udp_tunnel_del = bnxt_udp_tunnel_del, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7077 | }; |
| 7078 | |
| 7079 | static void bnxt_remove_one(struct pci_dev *pdev) |
| 7080 | { |
| 7081 | struct net_device *dev = pci_get_drvdata(pdev); |
| 7082 | struct bnxt *bp = netdev_priv(dev); |
| 7083 | |
| 7084 | if (BNXT_PF(bp)) |
| 7085 | bnxt_sriov_disable(bp); |
| 7086 | |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 7087 | pci_disable_pcie_error_reporting(pdev); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7088 | unregister_netdev(dev); |
| 7089 | cancel_work_sync(&bp->sp_task); |
| 7090 | bp->sp_event = 0; |
| 7091 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 7092 | bnxt_clear_int_mode(bp); |
Jeffrey Huang | be58a0d | 2015-12-27 18:19:18 -0500 | [diff] [blame] | 7093 | bnxt_hwrm_func_drv_unrgtr(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7094 | bnxt_free_hwrm_resources(bp); |
Michael Chan | 7df4ae9 | 2016-12-02 21:17:17 -0500 | [diff] [blame] | 7095 | bnxt_dcb_free(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7096 | pci_iounmap(pdev, bp->bar2); |
| 7097 | pci_iounmap(pdev, bp->bar1); |
| 7098 | pci_iounmap(pdev, bp->bar0); |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 7099 | kfree(bp->edev); |
| 7100 | bp->edev = NULL; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7101 | free_netdev(dev); |
| 7102 | |
| 7103 | pci_release_regions(pdev); |
| 7104 | pci_disable_device(pdev); |
| 7105 | } |
| 7106 | |
| 7107 | static int bnxt_probe_phy(struct bnxt *bp) |
| 7108 | { |
| 7109 | int rc = 0; |
| 7110 | struct bnxt_link_info *link_info = &bp->link_info; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7111 | |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 7112 | rc = bnxt_hwrm_phy_qcaps(bp); |
| 7113 | if (rc) { |
| 7114 | netdev_err(bp->dev, "Probe phy can't get phy capabilities (rc: %x)\n", |
| 7115 | rc); |
| 7116 | return rc; |
| 7117 | } |
| 7118 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7119 | rc = bnxt_update_link(bp, false); |
| 7120 | if (rc) { |
| 7121 | netdev_err(bp->dev, "Probe phy can't update link (rc: %x)\n", |
| 7122 | rc); |
| 7123 | return rc; |
| 7124 | } |
| 7125 | |
Michael Chan | 93ed811 | 2016-06-13 02:25:37 -0400 | [diff] [blame] | 7126 | /* Older firmware does not have supported_auto_speeds, so assume |
| 7127 | * that all supported speeds can be autonegotiated. |
| 7128 | */ |
| 7129 | if (link_info->auto_link_speeds && !link_info->support_auto_speeds) |
| 7130 | link_info->support_auto_speeds = link_info->support_speeds; |
| 7131 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7132 | /*initialize the ethool setting copy with NVM settings */ |
Michael Chan | 0d8abf0 | 2016-02-10 17:33:47 -0500 | [diff] [blame] | 7133 | if (BNXT_AUTO_MODE(link_info->auto_mode)) { |
Michael Chan | c9ee951 | 2016-04-05 14:08:56 -0400 | [diff] [blame] | 7134 | link_info->autoneg = BNXT_AUTONEG_SPEED; |
| 7135 | if (bp->hwrm_spec_code >= 0x10201) { |
| 7136 | if (link_info->auto_pause_setting & |
| 7137 | PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE) |
| 7138 | link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL; |
| 7139 | } else { |
| 7140 | link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL; |
| 7141 | } |
Michael Chan | 0d8abf0 | 2016-02-10 17:33:47 -0500 | [diff] [blame] | 7142 | link_info->advertising = link_info->auto_link_speeds; |
Michael Chan | 0d8abf0 | 2016-02-10 17:33:47 -0500 | [diff] [blame] | 7143 | } else { |
| 7144 | link_info->req_link_speed = link_info->force_link_speed; |
| 7145 | link_info->req_duplex = link_info->duplex_setting; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7146 | } |
Michael Chan | c9ee951 | 2016-04-05 14:08:56 -0400 | [diff] [blame] | 7147 | if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) |
| 7148 | link_info->req_flow_ctrl = |
| 7149 | link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH; |
| 7150 | else |
| 7151 | link_info->req_flow_ctrl = link_info->force_pause_setting; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7152 | return rc; |
| 7153 | } |
| 7154 | |
| 7155 | static int bnxt_get_max_irq(struct pci_dev *pdev) |
| 7156 | { |
| 7157 | u16 ctrl; |
| 7158 | |
| 7159 | if (!pdev->msix_cap) |
| 7160 | return 1; |
| 7161 | |
| 7162 | pci_read_config_word(pdev, pdev->msix_cap + PCI_MSIX_FLAGS, &ctrl); |
| 7163 | return (ctrl & PCI_MSIX_FLAGS_QSIZE) + 1; |
| 7164 | } |
| 7165 | |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 7166 | static void _bnxt_get_max_rings(struct bnxt *bp, int *max_rx, int *max_tx, |
| 7167 | int *max_cp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7168 | { |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 7169 | int max_ring_grps = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7170 | |
Michael Chan | 379a80a | 2015-10-23 15:06:19 -0400 | [diff] [blame] | 7171 | #ifdef CONFIG_BNXT_SRIOV |
Arnd Bergmann | 415b6f1 | 2016-01-12 16:05:08 +0100 | [diff] [blame] | 7172 | if (!BNXT_PF(bp)) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7173 | *max_tx = bp->vf.max_tx_rings; |
| 7174 | *max_rx = bp->vf.max_rx_rings; |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 7175 | *max_cp = min_t(int, bp->vf.max_irqs, bp->vf.max_cp_rings); |
| 7176 | *max_cp = min_t(int, *max_cp, bp->vf.max_stat_ctxs); |
Michael Chan | b72d4a6 | 2015-12-27 18:19:27 -0500 | [diff] [blame] | 7177 | max_ring_grps = bp->vf.max_hw_ring_grps; |
Arnd Bergmann | 415b6f1 | 2016-01-12 16:05:08 +0100 | [diff] [blame] | 7178 | } else |
Michael Chan | 379a80a | 2015-10-23 15:06:19 -0400 | [diff] [blame] | 7179 | #endif |
Arnd Bergmann | 415b6f1 | 2016-01-12 16:05:08 +0100 | [diff] [blame] | 7180 | { |
| 7181 | *max_tx = bp->pf.max_tx_rings; |
| 7182 | *max_rx = bp->pf.max_rx_rings; |
| 7183 | *max_cp = min_t(int, bp->pf.max_irqs, bp->pf.max_cp_rings); |
| 7184 | *max_cp = min_t(int, *max_cp, bp->pf.max_stat_ctxs); |
| 7185 | max_ring_grps = bp->pf.max_hw_ring_grps; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7186 | } |
Prashant Sreedharan | 7659519 | 2016-07-18 07:15:22 -0400 | [diff] [blame] | 7187 | if (BNXT_CHIP_TYPE_NITRO_A0(bp) && BNXT_PF(bp)) { |
| 7188 | *max_cp -= 1; |
| 7189 | *max_rx -= 2; |
| 7190 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7191 | if (bp->flags & BNXT_FLAG_AGG_RINGS) |
| 7192 | *max_rx >>= 1; |
Michael Chan | b72d4a6 | 2015-12-27 18:19:27 -0500 | [diff] [blame] | 7193 | *max_rx = min_t(int, *max_rx, max_ring_grps); |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 7194 | } |
| 7195 | |
| 7196 | int bnxt_get_max_rings(struct bnxt *bp, int *max_rx, int *max_tx, bool shared) |
| 7197 | { |
| 7198 | int rx, tx, cp; |
| 7199 | |
| 7200 | _bnxt_get_max_rings(bp, &rx, &tx, &cp); |
| 7201 | if (!rx || !tx || !cp) |
| 7202 | return -ENOMEM; |
| 7203 | |
| 7204 | *max_rx = rx; |
| 7205 | *max_tx = tx; |
| 7206 | return bnxt_trim_rings(bp, max_rx, max_tx, cp, shared); |
| 7207 | } |
| 7208 | |
Michael Chan | e4060d3 | 2016-12-07 00:26:19 -0500 | [diff] [blame] | 7209 | static int bnxt_get_dflt_rings(struct bnxt *bp, int *max_rx, int *max_tx, |
| 7210 | bool shared) |
| 7211 | { |
| 7212 | int rc; |
| 7213 | |
| 7214 | rc = bnxt_get_max_rings(bp, max_rx, max_tx, shared); |
Michael Chan | bdbd1eb | 2016-12-29 12:13:43 -0500 | [diff] [blame] | 7215 | if (rc && (bp->flags & BNXT_FLAG_AGG_RINGS)) { |
| 7216 | /* Not enough rings, try disabling agg rings. */ |
| 7217 | bp->flags &= ~BNXT_FLAG_AGG_RINGS; |
| 7218 | rc = bnxt_get_max_rings(bp, max_rx, max_tx, shared); |
| 7219 | if (rc) |
| 7220 | return rc; |
| 7221 | bp->flags |= BNXT_FLAG_NO_AGG_RINGS; |
| 7222 | bp->dev->hw_features &= ~NETIF_F_LRO; |
| 7223 | bp->dev->features &= ~NETIF_F_LRO; |
| 7224 | bnxt_set_ring_params(bp); |
| 7225 | } |
Michael Chan | e4060d3 | 2016-12-07 00:26:19 -0500 | [diff] [blame] | 7226 | |
| 7227 | if (bp->flags & BNXT_FLAG_ROCE_CAP) { |
| 7228 | int max_cp, max_stat, max_irq; |
| 7229 | |
| 7230 | /* Reserve minimum resources for RoCE */ |
| 7231 | max_cp = bnxt_get_max_func_cp_rings(bp); |
| 7232 | max_stat = bnxt_get_max_func_stat_ctxs(bp); |
| 7233 | max_irq = bnxt_get_max_func_irqs(bp); |
| 7234 | if (max_cp <= BNXT_MIN_ROCE_CP_RINGS || |
| 7235 | max_irq <= BNXT_MIN_ROCE_CP_RINGS || |
| 7236 | max_stat <= BNXT_MIN_ROCE_STAT_CTXS) |
| 7237 | return 0; |
| 7238 | |
| 7239 | max_cp -= BNXT_MIN_ROCE_CP_RINGS; |
| 7240 | max_irq -= BNXT_MIN_ROCE_CP_RINGS; |
| 7241 | max_stat -= BNXT_MIN_ROCE_STAT_CTXS; |
| 7242 | max_cp = min_t(int, max_cp, max_irq); |
| 7243 | max_cp = min_t(int, max_cp, max_stat); |
| 7244 | rc = bnxt_trim_rings(bp, max_rx, max_tx, max_cp, shared); |
| 7245 | if (rc) |
| 7246 | rc = 0; |
| 7247 | } |
| 7248 | return rc; |
| 7249 | } |
| 7250 | |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 7251 | static int bnxt_set_dflt_rings(struct bnxt *bp) |
| 7252 | { |
| 7253 | int dflt_rings, max_rx_rings, max_tx_rings, rc; |
| 7254 | bool sh = true; |
| 7255 | |
| 7256 | if (sh) |
| 7257 | bp->flags |= BNXT_FLAG_SHARED_RINGS; |
| 7258 | dflt_rings = netif_get_num_default_rss_queues(); |
Michael Chan | e4060d3 | 2016-12-07 00:26:19 -0500 | [diff] [blame] | 7259 | 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] | 7260 | if (rc) |
| 7261 | return rc; |
| 7262 | bp->rx_nr_rings = min_t(int, dflt_rings, max_rx_rings); |
| 7263 | 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] | 7264 | |
| 7265 | rc = bnxt_hwrm_reserve_tx_rings(bp, &bp->tx_nr_rings_per_tc); |
| 7266 | if (rc) |
| 7267 | netdev_warn(bp->dev, "Unable to reserve tx rings\n"); |
| 7268 | |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 7269 | bp->tx_nr_rings = bp->tx_nr_rings_per_tc; |
| 7270 | bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) : |
| 7271 | bp->tx_nr_rings + bp->rx_nr_rings; |
| 7272 | bp->num_stat_ctxs = bp->cp_nr_rings; |
Prashant Sreedharan | 7659519 | 2016-07-18 07:15:22 -0400 | [diff] [blame] | 7273 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) { |
| 7274 | bp->rx_nr_rings++; |
| 7275 | bp->cp_nr_rings++; |
| 7276 | } |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 7277 | return rc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7278 | } |
| 7279 | |
Michael Chan | 7b08f66 | 2016-12-07 00:26:18 -0500 | [diff] [blame] | 7280 | void bnxt_restore_pf_fw_resources(struct bnxt *bp) |
| 7281 | { |
| 7282 | ASSERT_RTNL(); |
| 7283 | bnxt_hwrm_func_qcaps(bp); |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 7284 | bnxt_subtract_ulp_resources(bp, BNXT_ROCE_ULP); |
Michael Chan | 7b08f66 | 2016-12-07 00:26:18 -0500 | [diff] [blame] | 7285 | } |
| 7286 | |
Ajit Khaparde | 90c4f78 | 2016-05-15 03:04:45 -0400 | [diff] [blame] | 7287 | static void bnxt_parse_log_pcie_link(struct bnxt *bp) |
| 7288 | { |
| 7289 | enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN; |
| 7290 | enum pci_bus_speed speed = PCI_SPEED_UNKNOWN; |
| 7291 | |
| 7292 | if (pcie_get_minimum_link(bp->pdev, &speed, &width) || |
| 7293 | speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) |
| 7294 | netdev_info(bp->dev, "Failed to determine PCIe Link Info\n"); |
| 7295 | else |
| 7296 | netdev_info(bp->dev, "PCIe: Speed %s Width x%d\n", |
| 7297 | speed == PCIE_SPEED_2_5GT ? "2.5GT/s" : |
| 7298 | speed == PCIE_SPEED_5_0GT ? "5.0GT/s" : |
| 7299 | speed == PCIE_SPEED_8_0GT ? "8.0GT/s" : |
| 7300 | "Unknown", width); |
| 7301 | } |
| 7302 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7303 | static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 7304 | { |
| 7305 | static int version_printed; |
| 7306 | struct net_device *dev; |
| 7307 | struct bnxt *bp; |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 7308 | int rc, max_irqs; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7309 | |
Prashant Sreedharan | fa853dd | 2016-07-18 07:15:25 -0400 | [diff] [blame] | 7310 | if (pdev->device == 0x16cd && pci_is_bridge(pdev)) |
| 7311 | return -ENODEV; |
| 7312 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7313 | if (version_printed++ == 0) |
| 7314 | pr_info("%s", version); |
| 7315 | |
| 7316 | max_irqs = bnxt_get_max_irq(pdev); |
| 7317 | dev = alloc_etherdev_mq(sizeof(*bp), max_irqs); |
| 7318 | if (!dev) |
| 7319 | return -ENOMEM; |
| 7320 | |
| 7321 | bp = netdev_priv(dev); |
| 7322 | |
| 7323 | if (bnxt_vf_pciid(ent->driver_data)) |
| 7324 | bp->flags |= BNXT_FLAG_VF; |
| 7325 | |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 7326 | if (pdev->msix_cap) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7327 | bp->flags |= BNXT_FLAG_MSIX_CAP; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7328 | |
| 7329 | rc = bnxt_init_board(pdev, dev); |
| 7330 | if (rc < 0) |
| 7331 | goto init_err_free; |
| 7332 | |
| 7333 | dev->netdev_ops = &bnxt_netdev_ops; |
| 7334 | dev->watchdog_timeo = BNXT_TX_TIMEOUT; |
| 7335 | dev->ethtool_ops = &bnxt_ethtool_ops; |
| 7336 | |
| 7337 | pci_set_drvdata(pdev, dev); |
| 7338 | |
Prashant Sreedharan | 3e8060f | 2016-07-18 07:15:20 -0400 | [diff] [blame] | 7339 | rc = bnxt_alloc_hwrm_resources(bp); |
| 7340 | if (rc) |
| 7341 | goto init_err; |
| 7342 | |
| 7343 | mutex_init(&bp->hwrm_cmd_lock); |
| 7344 | rc = bnxt_hwrm_ver_get(bp); |
| 7345 | if (rc) |
| 7346 | goto init_err; |
| 7347 | |
Rob Swindell | 5ac67d8 | 2016-09-19 03:58:03 -0400 | [diff] [blame] | 7348 | bnxt_hwrm_fw_set_time(bp); |
| 7349 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7350 | dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG | |
| 7351 | NETIF_F_TSO | NETIF_F_TSO6 | |
| 7352 | NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_GRE | |
Tom Herbert | 7e13318 | 2016-05-18 09:06:10 -0700 | [diff] [blame] | 7353 | NETIF_F_GSO_IPXIP4 | |
Alexander Duyck | 152971e | 2016-05-02 09:38:55 -0700 | [diff] [blame] | 7354 | NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_GSO_GRE_CSUM | |
| 7355 | NETIF_F_GSO_PARTIAL | NETIF_F_RXHASH | |
Prashant Sreedharan | 3e8060f | 2016-07-18 07:15:20 -0400 | [diff] [blame] | 7356 | NETIF_F_RXCSUM | NETIF_F_GRO; |
| 7357 | |
| 7358 | if (!BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 7359 | dev->hw_features |= NETIF_F_LRO; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7360 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7361 | dev->hw_enc_features = |
| 7362 | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG | |
| 7363 | NETIF_F_TSO | NETIF_F_TSO6 | |
| 7364 | NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_GRE | |
Alexander Duyck | 152971e | 2016-05-02 09:38:55 -0700 | [diff] [blame] | 7365 | NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_GSO_GRE_CSUM | |
Tom Herbert | 7e13318 | 2016-05-18 09:06:10 -0700 | [diff] [blame] | 7366 | NETIF_F_GSO_IPXIP4 | NETIF_F_GSO_PARTIAL; |
Alexander Duyck | 152971e | 2016-05-02 09:38:55 -0700 | [diff] [blame] | 7367 | dev->gso_partial_features = NETIF_F_GSO_UDP_TUNNEL_CSUM | |
| 7368 | NETIF_F_GSO_GRE_CSUM; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7369 | dev->vlan_features = dev->hw_features | NETIF_F_HIGHDMA; |
| 7370 | dev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX | |
| 7371 | NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_STAG_TX; |
| 7372 | dev->features |= dev->hw_features | NETIF_F_HIGHDMA; |
| 7373 | dev->priv_flags |= IFF_UNICAST_FLT; |
| 7374 | |
Jarod Wilson | e1c6dcc | 2016-10-17 15:54:04 -0400 | [diff] [blame] | 7375 | /* MTU range: 60 - 9500 */ |
| 7376 | dev->min_mtu = ETH_ZLEN; |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 7377 | dev->max_mtu = BNXT_MAX_MTU; |
Jarod Wilson | e1c6dcc | 2016-10-17 15:54:04 -0400 | [diff] [blame] | 7378 | |
Michael Chan | 7df4ae9 | 2016-12-02 21:17:17 -0500 | [diff] [blame] | 7379 | bnxt_dcb_init(bp); |
| 7380 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7381 | #ifdef CONFIG_BNXT_SRIOV |
| 7382 | init_waitqueue_head(&bp->sriov_cfg_wait); |
| 7383 | #endif |
Michael Chan | 309369c | 2016-06-13 02:25:34 -0400 | [diff] [blame] | 7384 | bp->gro_func = bnxt_gro_func_5730x; |
Michael Chan | 94758f8 | 2016-06-13 02:25:35 -0400 | [diff] [blame] | 7385 | if (BNXT_CHIP_NUM_57X1X(bp->chip_num)) |
| 7386 | bp->gro_func = bnxt_gro_func_5731x; |
Michael Chan | 309369c | 2016-06-13 02:25:34 -0400 | [diff] [blame] | 7387 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7388 | rc = bnxt_hwrm_func_drv_rgtr(bp); |
| 7389 | if (rc) |
| 7390 | goto init_err; |
| 7391 | |
Michael Chan | a1653b1 | 2016-12-07 00:26:20 -0500 | [diff] [blame] | 7392 | rc = bnxt_hwrm_func_rgtr_async_events(bp, NULL, 0); |
| 7393 | if (rc) |
| 7394 | goto init_err; |
| 7395 | |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 7396 | bp->ulp_probe = bnxt_ulp_probe; |
| 7397 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7398 | /* Get the MAX capabilities for this function */ |
| 7399 | rc = bnxt_hwrm_func_qcaps(bp); |
| 7400 | if (rc) { |
| 7401 | netdev_err(bp->dev, "hwrm query capability failure rc: %x\n", |
| 7402 | rc); |
| 7403 | rc = -1; |
| 7404 | goto init_err; |
| 7405 | } |
| 7406 | |
| 7407 | rc = bnxt_hwrm_queue_qportcfg(bp); |
| 7408 | if (rc) { |
| 7409 | netdev_err(bp->dev, "hwrm query qportcfg failure rc: %x\n", |
| 7410 | rc); |
| 7411 | rc = -1; |
| 7412 | goto init_err; |
| 7413 | } |
| 7414 | |
Satish Baddipadige | 567b2ab | 2016-06-13 02:25:31 -0400 | [diff] [blame] | 7415 | bnxt_hwrm_func_qcfg(bp); |
Michael Chan | 5ad2cbe | 2017-01-13 01:32:03 -0500 | [diff] [blame] | 7416 | bnxt_hwrm_port_led_qcaps(bp); |
Satish Baddipadige | 567b2ab | 2016-06-13 02:25:31 -0400 | [diff] [blame] | 7417 | |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 7418 | bnxt_set_rx_skb_mode(bp, false); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7419 | bnxt_set_tpa_flags(bp); |
| 7420 | bnxt_set_ring_params(bp); |
Michael Chan | 33c2657 | 2016-12-07 00:26:15 -0500 | [diff] [blame] | 7421 | bnxt_set_max_func_irqs(bp, max_irqs); |
Michael Chan | bdbd1eb | 2016-12-29 12:13:43 -0500 | [diff] [blame] | 7422 | rc = bnxt_set_dflt_rings(bp); |
| 7423 | if (rc) { |
| 7424 | netdev_err(bp->dev, "Not enough rings available.\n"); |
| 7425 | rc = -ENOMEM; |
| 7426 | goto init_err; |
| 7427 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7428 | |
Michael Chan | 87da7f7 | 2016-11-16 21:13:09 -0500 | [diff] [blame] | 7429 | /* Default RSS hash cfg. */ |
| 7430 | bp->rss_hash_cfg = VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4 | |
| 7431 | VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4 | |
| 7432 | VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6 | |
| 7433 | VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6; |
| 7434 | if (!BNXT_CHIP_NUM_57X0X(bp->chip_num) && |
| 7435 | !BNXT_CHIP_TYPE_NITRO_A0(bp) && |
| 7436 | bp->hwrm_spec_code >= 0x10501) { |
| 7437 | bp->flags |= BNXT_FLAG_UDP_RSS_CAP; |
| 7438 | bp->rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4 | |
| 7439 | VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6; |
| 7440 | } |
| 7441 | |
Michael Chan | 8fdefd6 | 2016-12-29 12:13:36 -0500 | [diff] [blame] | 7442 | bnxt_hwrm_vnic_qcaps(bp); |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 7443 | if (bnxt_rfs_supported(bp)) { |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 7444 | dev->hw_features |= NETIF_F_NTUPLE; |
| 7445 | if (bnxt_rfs_capable(bp)) { |
| 7446 | bp->flags |= BNXT_FLAG_RFS; |
| 7447 | dev->features |= NETIF_F_NTUPLE; |
| 7448 | } |
| 7449 | } |
| 7450 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7451 | if (dev->hw_features & NETIF_F_HW_VLAN_CTAG_RX) |
| 7452 | bp->flags |= BNXT_FLAG_STRIP_VLAN; |
| 7453 | |
| 7454 | rc = bnxt_probe_phy(bp); |
| 7455 | if (rc) |
| 7456 | goto init_err; |
| 7457 | |
Michael Chan | aa8ed02 | 2016-12-07 00:26:17 -0500 | [diff] [blame] | 7458 | rc = bnxt_hwrm_func_reset(bp); |
| 7459 | if (rc) |
| 7460 | goto init_err; |
| 7461 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 7462 | rc = bnxt_init_int_mode(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7463 | if (rc) |
| 7464 | goto init_err; |
| 7465 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 7466 | rc = register_netdev(dev); |
| 7467 | if (rc) |
| 7468 | goto init_err_clr_int; |
| 7469 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7470 | netdev_info(dev, "%s found at mem %lx, node addr %pM\n", |
| 7471 | board_info[ent->driver_data].name, |
| 7472 | (long)pci_resource_start(pdev, 0), dev->dev_addr); |
| 7473 | |
Ajit Khaparde | 90c4f78 | 2016-05-15 03:04:45 -0400 | [diff] [blame] | 7474 | bnxt_parse_log_pcie_link(bp); |
| 7475 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7476 | return 0; |
| 7477 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 7478 | init_err_clr_int: |
| 7479 | bnxt_clear_int_mode(bp); |
| 7480 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7481 | init_err: |
| 7482 | pci_iounmap(pdev, bp->bar0); |
| 7483 | pci_release_regions(pdev); |
| 7484 | pci_disable_device(pdev); |
| 7485 | |
| 7486 | init_err_free: |
| 7487 | free_netdev(dev); |
| 7488 | return rc; |
| 7489 | } |
| 7490 | |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 7491 | /** |
| 7492 | * bnxt_io_error_detected - called when PCI error is detected |
| 7493 | * @pdev: Pointer to PCI device |
| 7494 | * @state: The current pci connection state |
| 7495 | * |
| 7496 | * This function is called after a PCI bus error affecting |
| 7497 | * this device has been detected. |
| 7498 | */ |
| 7499 | static pci_ers_result_t bnxt_io_error_detected(struct pci_dev *pdev, |
| 7500 | pci_channel_state_t state) |
| 7501 | { |
| 7502 | struct net_device *netdev = pci_get_drvdata(pdev); |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 7503 | struct bnxt *bp = netdev_priv(netdev); |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 7504 | |
| 7505 | netdev_info(netdev, "PCI I/O error detected\n"); |
| 7506 | |
| 7507 | rtnl_lock(); |
| 7508 | netif_device_detach(netdev); |
| 7509 | |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 7510 | bnxt_ulp_stop(bp); |
| 7511 | |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 7512 | if (state == pci_channel_io_perm_failure) { |
| 7513 | rtnl_unlock(); |
| 7514 | return PCI_ERS_RESULT_DISCONNECT; |
| 7515 | } |
| 7516 | |
| 7517 | if (netif_running(netdev)) |
| 7518 | bnxt_close(netdev); |
| 7519 | |
| 7520 | pci_disable_device(pdev); |
| 7521 | rtnl_unlock(); |
| 7522 | |
| 7523 | /* Request a slot slot reset. */ |
| 7524 | return PCI_ERS_RESULT_NEED_RESET; |
| 7525 | } |
| 7526 | |
| 7527 | /** |
| 7528 | * bnxt_io_slot_reset - called after the pci bus has been reset. |
| 7529 | * @pdev: Pointer to PCI device |
| 7530 | * |
| 7531 | * Restart the card from scratch, as if from a cold-boot. |
| 7532 | * At this point, the card has exprienced a hard reset, |
| 7533 | * followed by fixups by BIOS, and has its config space |
| 7534 | * set up identically to what it was at cold boot. |
| 7535 | */ |
| 7536 | static pci_ers_result_t bnxt_io_slot_reset(struct pci_dev *pdev) |
| 7537 | { |
| 7538 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 7539 | struct bnxt *bp = netdev_priv(netdev); |
| 7540 | int err = 0; |
| 7541 | pci_ers_result_t result = PCI_ERS_RESULT_DISCONNECT; |
| 7542 | |
| 7543 | netdev_info(bp->dev, "PCI Slot Reset\n"); |
| 7544 | |
| 7545 | rtnl_lock(); |
| 7546 | |
| 7547 | if (pci_enable_device(pdev)) { |
| 7548 | dev_err(&pdev->dev, |
| 7549 | "Cannot re-enable PCI device after reset.\n"); |
| 7550 | } else { |
| 7551 | pci_set_master(pdev); |
| 7552 | |
Michael Chan | aa8ed02 | 2016-12-07 00:26:17 -0500 | [diff] [blame] | 7553 | err = bnxt_hwrm_func_reset(bp); |
| 7554 | if (!err && netif_running(netdev)) |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 7555 | err = bnxt_open(netdev); |
| 7556 | |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 7557 | if (!err) { |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 7558 | result = PCI_ERS_RESULT_RECOVERED; |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 7559 | bnxt_ulp_start(bp); |
| 7560 | } |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 7561 | } |
| 7562 | |
| 7563 | if (result != PCI_ERS_RESULT_RECOVERED && netif_running(netdev)) |
| 7564 | dev_close(netdev); |
| 7565 | |
| 7566 | rtnl_unlock(); |
| 7567 | |
| 7568 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 7569 | if (err) { |
| 7570 | dev_err(&pdev->dev, |
| 7571 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", |
| 7572 | err); /* non-fatal, continue */ |
| 7573 | } |
| 7574 | |
| 7575 | return PCI_ERS_RESULT_RECOVERED; |
| 7576 | } |
| 7577 | |
| 7578 | /** |
| 7579 | * bnxt_io_resume - called when traffic can start flowing again. |
| 7580 | * @pdev: Pointer to PCI device |
| 7581 | * |
| 7582 | * This callback is called when the error recovery driver tells |
| 7583 | * us that its OK to resume normal operation. |
| 7584 | */ |
| 7585 | static void bnxt_io_resume(struct pci_dev *pdev) |
| 7586 | { |
| 7587 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 7588 | |
| 7589 | rtnl_lock(); |
| 7590 | |
| 7591 | netif_device_attach(netdev); |
| 7592 | |
| 7593 | rtnl_unlock(); |
| 7594 | } |
| 7595 | |
| 7596 | static const struct pci_error_handlers bnxt_err_handler = { |
| 7597 | .error_detected = bnxt_io_error_detected, |
| 7598 | .slot_reset = bnxt_io_slot_reset, |
| 7599 | .resume = bnxt_io_resume |
| 7600 | }; |
| 7601 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7602 | static struct pci_driver bnxt_pci_driver = { |
| 7603 | .name = DRV_MODULE_NAME, |
| 7604 | .id_table = bnxt_pci_tbl, |
| 7605 | .probe = bnxt_init_one, |
| 7606 | .remove = bnxt_remove_one, |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 7607 | .err_handler = &bnxt_err_handler, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7608 | #if defined(CONFIG_BNXT_SRIOV) |
| 7609 | .sriov_configure = bnxt_sriov_configure, |
| 7610 | #endif |
| 7611 | }; |
| 7612 | |
| 7613 | module_pci_driver(bnxt_pci_driver); |