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