blob: dc10a9a2af1bb4e9218119882af2c92106258cbe [file] [log] [blame]
Michael Chanc0c050c2015-10-22 16:01:17 -04001/* Broadcom NetXtreme-C/E network driver.
2 *
Michael Chan11f15ed2016-04-05 14:08:55 -04003 * Copyright (c) 2014-2016 Broadcom Corporation
Michael Chanbac9a7e2017-02-12 19:18:10 -05004 * Copyright (c) 2016-2017 Broadcom Limited
Michael Chanc0c050c2015-10-22 16:01:17 -04005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation.
9 */
10
11#include <linux/module.h>
12
13#include <linux/stringify.h>
14#include <linux/kernel.h>
15#include <linux/timer.h>
16#include <linux/errno.h>
17#include <linux/ioport.h>
18#include <linux/slab.h>
19#include <linux/vmalloc.h>
20#include <linux/interrupt.h>
21#include <linux/pci.h>
22#include <linux/netdevice.h>
23#include <linux/etherdevice.h>
24#include <linux/skbuff.h>
25#include <linux/dma-mapping.h>
26#include <linux/bitops.h>
27#include <linux/io.h>
28#include <linux/irq.h>
29#include <linux/delay.h>
30#include <asm/byteorder.h>
31#include <asm/page.h>
32#include <linux/time.h>
33#include <linux/mii.h>
34#include <linux/if.h>
35#include <linux/if_vlan.h>
Rob Swindell5ac67d82016-09-19 03:58:03 -040036#include <linux/rtc.h>
Michael Chanc6d30e82017-02-06 16:55:42 -050037#include <linux/bpf.h>
Michael Chanc0c050c2015-10-22 16:01:17 -040038#include <net/ip.h>
39#include <net/tcp.h>
40#include <net/udp.h>
41#include <net/checksum.h>
42#include <net/ip6_checksum.h>
Alexander Duyckad51b8e2016-06-16 12:21:19 -070043#include <net/udp_tunnel.h>
Michael Chanc0c050c2015-10-22 16:01:17 -040044#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"
Michael Chana588e452016-12-07 00:26:21 -050054#include "bnxt_ulp.h"
Michael Chanc0c050c2015-10-22 16:01:17 -040055#include "bnxt_sriov.h"
56#include "bnxt_ethtool.h"
Michael Chan7df4ae92016-12-02 21:17:17 -050057#include "bnxt_dcb.h"
Michael Chanc6d30e82017-02-06 16:55:42 -050058#include "bnxt_xdp.h"
Michael Chanc0c050c2015-10-22 16:01:17 -040059
60#define BNXT_TX_TIMEOUT (5 * HZ)
61
62static const char version[] =
63 "Broadcom NetXtreme-C/E driver " DRV_MODULE_NAME " v" DRV_MODULE_VERSION "\n";
64
65MODULE_LICENSE("GPL");
66MODULE_DESCRIPTION("Broadcom BCM573xx network driver");
67MODULE_VERSION(DRV_MODULE_VERSION);
68
69#define BNXT_RX_OFFSET (NET_SKB_PAD + NET_IP_ALIGN)
70#define BNXT_RX_DMA_OFFSET NET_SKB_PAD
71#define BNXT_RX_COPY_THRESH 256
72
Michael Chan4419dbe2016-02-10 17:33:49 -050073#define BNXT_TX_PUSH_THRESH 164
Michael Chanc0c050c2015-10-22 16:01:17 -040074
75enum board_idx {
David Christensenfbc9a522015-12-27 18:19:29 -050076 BCM57301,
Michael Chanc0c050c2015-10-22 16:01:17 -040077 BCM57302,
78 BCM57304,
Michael Chan1f681682016-07-25 12:33:37 -040079 BCM57417_NPAR,
Prashant Sreedharanfa853dd2016-07-18 07:15:25 -040080 BCM58700,
Michael Chanb24eb6a2016-06-13 02:25:36 -040081 BCM57311,
82 BCM57312,
David Christensenfbc9a522015-12-27 18:19:29 -050083 BCM57402,
Michael Chanc0c050c2015-10-22 16:01:17 -040084 BCM57404,
85 BCM57406,
Michael Chan1f681682016-07-25 12:33:37 -040086 BCM57402_NPAR,
87 BCM57407,
Michael Chanb24eb6a2016-06-13 02:25:36 -040088 BCM57412,
89 BCM57414,
90 BCM57416,
91 BCM57417,
Michael Chan1f681682016-07-25 12:33:37 -040092 BCM57412_NPAR,
Michael Chan5049e332016-05-15 03:04:50 -040093 BCM57314,
Michael Chan1f681682016-07-25 12:33:37 -040094 BCM57417_SFP,
95 BCM57416_SFP,
96 BCM57404_NPAR,
97 BCM57406_NPAR,
98 BCM57407_SFP,
Michael Chanadbc8302016-09-19 03:58:01 -040099 BCM57407_NPAR,
Michael Chan1f681682016-07-25 12:33:37 -0400100 BCM57414_NPAR,
101 BCM57416_NPAR,
Deepak Khungar32b40792017-02-12 19:18:18 -0500102 BCM57452,
103 BCM57454,
Michael Chanadbc8302016-09-19 03:58:01 -0400104 NETXTREME_E_VF,
105 NETXTREME_C_VF,
Michael Chanc0c050c2015-10-22 16:01:17 -0400106};
107
108/* indexed by enum above */
109static const struct {
110 char *name;
111} board_info[] = {
Michael Chanadbc8302016-09-19 03:58:01 -0400112 { "Broadcom BCM57301 NetXtreme-C 10Gb Ethernet" },
113 { "Broadcom BCM57302 NetXtreme-C 10Gb/25Gb Ethernet" },
114 { "Broadcom BCM57304 NetXtreme-C 10Gb/25Gb/40Gb/50Gb Ethernet" },
Michael Chan1f681682016-07-25 12:33:37 -0400115 { "Broadcom BCM57417 NetXtreme-E Ethernet Partition" },
Michael Chanadbc8302016-09-19 03:58:01 -0400116 { "Broadcom BCM58700 Nitro 1Gb/2.5Gb/10Gb Ethernet" },
117 { "Broadcom BCM57311 NetXtreme-C 10Gb Ethernet" },
118 { "Broadcom BCM57312 NetXtreme-C 10Gb/25Gb Ethernet" },
119 { "Broadcom BCM57402 NetXtreme-E 10Gb Ethernet" },
120 { "Broadcom BCM57404 NetXtreme-E 10Gb/25Gb Ethernet" },
121 { "Broadcom BCM57406 NetXtreme-E 10GBase-T Ethernet" },
Michael Chan1f681682016-07-25 12:33:37 -0400122 { "Broadcom BCM57402 NetXtreme-E Ethernet Partition" },
Michael Chanadbc8302016-09-19 03:58:01 -0400123 { "Broadcom BCM57407 NetXtreme-E 10GBase-T Ethernet" },
124 { "Broadcom BCM57412 NetXtreme-E 10Gb Ethernet" },
125 { "Broadcom BCM57414 NetXtreme-E 10Gb/25Gb Ethernet" },
126 { "Broadcom BCM57416 NetXtreme-E 10GBase-T Ethernet" },
127 { "Broadcom BCM57417 NetXtreme-E 10GBase-T Ethernet" },
Michael Chan1f681682016-07-25 12:33:37 -0400128 { "Broadcom BCM57412 NetXtreme-E Ethernet Partition" },
Michael Chanadbc8302016-09-19 03:58:01 -0400129 { "Broadcom BCM57314 NetXtreme-C 10Gb/25Gb/40Gb/50Gb Ethernet" },
130 { "Broadcom BCM57417 NetXtreme-E 10Gb/25Gb Ethernet" },
131 { "Broadcom BCM57416 NetXtreme-E 10Gb Ethernet" },
Michael Chan1f681682016-07-25 12:33:37 -0400132 { "Broadcom BCM57404 NetXtreme-E Ethernet Partition" },
133 { "Broadcom BCM57406 NetXtreme-E Ethernet Partition" },
Michael Chanadbc8302016-09-19 03:58:01 -0400134 { "Broadcom BCM57407 NetXtreme-E 25Gb Ethernet" },
135 { "Broadcom BCM57407 NetXtreme-E Ethernet Partition" },
Michael Chan1f681682016-07-25 12:33:37 -0400136 { "Broadcom BCM57414 NetXtreme-E Ethernet Partition" },
137 { "Broadcom BCM57416 NetXtreme-E Ethernet Partition" },
Deepak Khungar32b40792017-02-12 19:18:18 -0500138 { "Broadcom BCM57452 NetXtreme-E 10Gb/25Gb/40Gb/50Gb Ethernet" },
139 { "Broadcom BCM57454 NetXtreme-E 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" },
Michael Chanadbc8302016-09-19 03:58:01 -0400140 { "Broadcom NetXtreme-E Ethernet Virtual Function" },
141 { "Broadcom NetXtreme-C Ethernet Virtual Function" },
Michael Chanc0c050c2015-10-22 16:01:17 -0400142};
143
144static const struct pci_device_id bnxt_pci_tbl[] = {
Michael Chanadbc8302016-09-19 03:58:01 -0400145 { PCI_VDEVICE(BROADCOM, 0x16c0), .driver_data = BCM57417_NPAR },
David Christensenfbc9a522015-12-27 18:19:29 -0500146 { PCI_VDEVICE(BROADCOM, 0x16c8), .driver_data = BCM57301 },
Michael Chanc0c050c2015-10-22 16:01:17 -0400147 { PCI_VDEVICE(BROADCOM, 0x16c9), .driver_data = BCM57302 },
148 { PCI_VDEVICE(BROADCOM, 0x16ca), .driver_data = BCM57304 },
Michael Chan1f681682016-07-25 12:33:37 -0400149 { PCI_VDEVICE(BROADCOM, 0x16cc), .driver_data = BCM57417_NPAR },
Prashant Sreedharanfa853dd2016-07-18 07:15:25 -0400150 { PCI_VDEVICE(BROADCOM, 0x16cd), .driver_data = BCM58700 },
Michael Chanb24eb6a2016-06-13 02:25:36 -0400151 { PCI_VDEVICE(BROADCOM, 0x16ce), .driver_data = BCM57311 },
152 { PCI_VDEVICE(BROADCOM, 0x16cf), .driver_data = BCM57312 },
David Christensenfbc9a522015-12-27 18:19:29 -0500153 { PCI_VDEVICE(BROADCOM, 0x16d0), .driver_data = BCM57402 },
Michael Chanc0c050c2015-10-22 16:01:17 -0400154 { PCI_VDEVICE(BROADCOM, 0x16d1), .driver_data = BCM57404 },
155 { PCI_VDEVICE(BROADCOM, 0x16d2), .driver_data = BCM57406 },
Michael Chan1f681682016-07-25 12:33:37 -0400156 { PCI_VDEVICE(BROADCOM, 0x16d4), .driver_data = BCM57402_NPAR },
157 { PCI_VDEVICE(BROADCOM, 0x16d5), .driver_data = BCM57407 },
Michael Chanb24eb6a2016-06-13 02:25:36 -0400158 { PCI_VDEVICE(BROADCOM, 0x16d6), .driver_data = BCM57412 },
159 { PCI_VDEVICE(BROADCOM, 0x16d7), .driver_data = BCM57414 },
160 { PCI_VDEVICE(BROADCOM, 0x16d8), .driver_data = BCM57416 },
161 { PCI_VDEVICE(BROADCOM, 0x16d9), .driver_data = BCM57417 },
Michael Chan1f681682016-07-25 12:33:37 -0400162 { PCI_VDEVICE(BROADCOM, 0x16de), .driver_data = BCM57412_NPAR },
Michael Chan5049e332016-05-15 03:04:50 -0400163 { PCI_VDEVICE(BROADCOM, 0x16df), .driver_data = BCM57314 },
Michael Chan1f681682016-07-25 12:33:37 -0400164 { PCI_VDEVICE(BROADCOM, 0x16e2), .driver_data = BCM57417_SFP },
165 { PCI_VDEVICE(BROADCOM, 0x16e3), .driver_data = BCM57416_SFP },
166 { PCI_VDEVICE(BROADCOM, 0x16e7), .driver_data = BCM57404_NPAR },
167 { PCI_VDEVICE(BROADCOM, 0x16e8), .driver_data = BCM57406_NPAR },
168 { PCI_VDEVICE(BROADCOM, 0x16e9), .driver_data = BCM57407_SFP },
Michael Chanadbc8302016-09-19 03:58:01 -0400169 { PCI_VDEVICE(BROADCOM, 0x16ea), .driver_data = BCM57407_NPAR },
170 { PCI_VDEVICE(BROADCOM, 0x16eb), .driver_data = BCM57412_NPAR },
Michael Chan1f681682016-07-25 12:33:37 -0400171 { PCI_VDEVICE(BROADCOM, 0x16ec), .driver_data = BCM57414_NPAR },
Michael Chanadbc8302016-09-19 03:58:01 -0400172 { PCI_VDEVICE(BROADCOM, 0x16ed), .driver_data = BCM57414_NPAR },
Michael Chan1f681682016-07-25 12:33:37 -0400173 { PCI_VDEVICE(BROADCOM, 0x16ee), .driver_data = BCM57416_NPAR },
Michael Chanadbc8302016-09-19 03:58:01 -0400174 { PCI_VDEVICE(BROADCOM, 0x16ef), .driver_data = BCM57416_NPAR },
Deepak Khungar32b40792017-02-12 19:18:18 -0500175 { PCI_VDEVICE(BROADCOM, 0x16f1), .driver_data = BCM57452 },
176 { PCI_VDEVICE(BROADCOM, 0x1614), .driver_data = BCM57454 },
Michael Chanc0c050c2015-10-22 16:01:17 -0400177#ifdef CONFIG_BNXT_SRIOV
Deepak Khungarc7ef35e2017-05-29 19:06:05 -0400178 { PCI_VDEVICE(BROADCOM, 0x1606), .driver_data = NETXTREME_E_VF },
179 { PCI_VDEVICE(BROADCOM, 0x1609), .driver_data = NETXTREME_E_VF },
Michael Chanadbc8302016-09-19 03:58:01 -0400180 { PCI_VDEVICE(BROADCOM, 0x16c1), .driver_data = NETXTREME_E_VF },
181 { PCI_VDEVICE(BROADCOM, 0x16cb), .driver_data = NETXTREME_C_VF },
182 { PCI_VDEVICE(BROADCOM, 0x16d3), .driver_data = NETXTREME_E_VF },
183 { PCI_VDEVICE(BROADCOM, 0x16dc), .driver_data = NETXTREME_E_VF },
184 { PCI_VDEVICE(BROADCOM, 0x16e1), .driver_data = NETXTREME_C_VF },
185 { PCI_VDEVICE(BROADCOM, 0x16e5), .driver_data = NETXTREME_C_VF },
Michael Chanc0c050c2015-10-22 16:01:17 -0400186#endif
187 { 0 }
188};
189
190MODULE_DEVICE_TABLE(pci, bnxt_pci_tbl);
191
192static const u16 bnxt_vf_req_snif[] = {
193 HWRM_FUNC_CFG,
194 HWRM_PORT_PHY_QCFG,
195 HWRM_CFA_L2_FILTER_ALLOC,
196};
197
Michael Chan25be8622016-04-05 14:09:00 -0400198static const u16 bnxt_async_events_arr[] = {
Michael Chan87c374d2016-12-02 21:17:16 -0500199 ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE,
200 ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD,
201 ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED,
202 ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE,
203 ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE,
Michael Chan25be8622016-04-05 14:09:00 -0400204};
205
Michael Chanc0c050c2015-10-22 16:01:17 -0400206static bool bnxt_vf_pciid(enum board_idx idx)
207{
Michael Chanadbc8302016-09-19 03:58:01 -0400208 return (idx == NETXTREME_C_VF || idx == NETXTREME_E_VF);
Michael Chanc0c050c2015-10-22 16:01:17 -0400209}
210
211#define DB_CP_REARM_FLAGS (DB_KEY_CP | DB_IDX_VALID)
212#define DB_CP_FLAGS (DB_KEY_CP | DB_IDX_VALID | DB_IRQ_DIS)
213#define DB_CP_IRQ_DIS_FLAGS (DB_KEY_CP | DB_IRQ_DIS)
214
215#define BNXT_CP_DB_REARM(db, raw_cons) \
216 writel(DB_CP_REARM_FLAGS | RING_CMP(raw_cons), db)
217
218#define BNXT_CP_DB(db, raw_cons) \
219 writel(DB_CP_FLAGS | RING_CMP(raw_cons), db)
220
221#define BNXT_CP_DB_IRQ_DIS(db) \
222 writel(DB_CP_IRQ_DIS_FLAGS, db)
223
Michael Chan38413402017-02-06 16:55:43 -0500224const u16 bnxt_lhint_arr[] = {
Michael Chanc0c050c2015-10-22 16:01:17 -0400225 TX_BD_FLAGS_LHINT_512_AND_SMALLER,
226 TX_BD_FLAGS_LHINT_512_TO_1023,
227 TX_BD_FLAGS_LHINT_1024_TO_2047,
228 TX_BD_FLAGS_LHINT_1024_TO_2047,
229 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
230 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
231 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
232 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
233 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
234 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
235 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
236 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
237 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
238 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
239 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
240 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
241 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
242 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
243 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
244};
245
246static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
247{
248 struct bnxt *bp = netdev_priv(dev);
249 struct tx_bd *txbd;
250 struct tx_bd_ext *txbd1;
251 struct netdev_queue *txq;
252 int i;
253 dma_addr_t mapping;
254 unsigned int length, pad = 0;
255 u32 len, free_size, vlan_tag_flags, cfa_action, flags;
256 u16 prod, last_frag;
257 struct pci_dev *pdev = bp->pdev;
Michael Chanc0c050c2015-10-22 16:01:17 -0400258 struct bnxt_tx_ring_info *txr;
259 struct bnxt_sw_tx_bd *tx_buf;
260
261 i = skb_get_queue_mapping(skb);
262 if (unlikely(i >= bp->tx_nr_rings)) {
263 dev_kfree_skb_any(skb);
264 return NETDEV_TX_OK;
265 }
266
Michael Chanc0c050c2015-10-22 16:01:17 -0400267 txq = netdev_get_tx_queue(dev, i);
Michael Chana960dec2017-02-06 16:55:39 -0500268 txr = &bp->tx_ring[bp->tx_ring_map[i]];
Michael Chanc0c050c2015-10-22 16:01:17 -0400269 prod = txr->tx_prod;
270
271 free_size = bnxt_tx_avail(bp, txr);
272 if (unlikely(free_size < skb_shinfo(skb)->nr_frags + 2)) {
273 netif_tx_stop_queue(txq);
274 return NETDEV_TX_BUSY;
275 }
276
277 length = skb->len;
278 len = skb_headlen(skb);
279 last_frag = skb_shinfo(skb)->nr_frags;
280
281 txbd = &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)];
282
283 txbd->tx_bd_opaque = prod;
284
285 tx_buf = &txr->tx_buf_ring[prod];
286 tx_buf->skb = skb;
287 tx_buf->nr_frags = last_frag;
288
289 vlan_tag_flags = 0;
290 cfa_action = 0;
291 if (skb_vlan_tag_present(skb)) {
292 vlan_tag_flags = TX_BD_CFA_META_KEY_VLAN |
293 skb_vlan_tag_get(skb);
294 /* Currently supports 8021Q, 8021AD vlan offloads
295 * QINQ1, QINQ2, QINQ3 vlan headers are deprecated
296 */
297 if (skb->vlan_proto == htons(ETH_P_8021Q))
298 vlan_tag_flags |= 1 << TX_BD_CFA_META_TPID_SHIFT;
299 }
300
301 if (free_size == bp->tx_ring_size && length <= bp->tx_push_thresh) {
Michael Chan4419dbe2016-02-10 17:33:49 -0500302 struct tx_push_buffer *tx_push_buf = txr->tx_push;
303 struct tx_push_bd *tx_push = &tx_push_buf->push_bd;
304 struct tx_bd_ext *tx_push1 = &tx_push->txbd2;
305 void *pdata = tx_push_buf->data;
306 u64 *end;
307 int j, push_len;
Michael Chanc0c050c2015-10-22 16:01:17 -0400308
309 /* Set COAL_NOW to be ready quickly for the next push */
310 tx_push->tx_bd_len_flags_type =
311 cpu_to_le32((length << TX_BD_LEN_SHIFT) |
312 TX_BD_TYPE_LONG_TX_BD |
313 TX_BD_FLAGS_LHINT_512_AND_SMALLER |
314 TX_BD_FLAGS_COAL_NOW |
315 TX_BD_FLAGS_PACKET_END |
316 (2 << TX_BD_FLAGS_BD_CNT_SHIFT));
317
318 if (skb->ip_summed == CHECKSUM_PARTIAL)
319 tx_push1->tx_bd_hsize_lflags =
320 cpu_to_le32(TX_BD_FLAGS_TCP_UDP_CHKSUM);
321 else
322 tx_push1->tx_bd_hsize_lflags = 0;
323
324 tx_push1->tx_bd_cfa_meta = cpu_to_le32(vlan_tag_flags);
325 tx_push1->tx_bd_cfa_action = cpu_to_le32(cfa_action);
326
Michael Chanfbb0fa82016-02-22 02:10:26 -0500327 end = pdata + length;
328 end = PTR_ALIGN(end, 8) - 1;
Michael Chan4419dbe2016-02-10 17:33:49 -0500329 *end = 0;
330
Michael Chanc0c050c2015-10-22 16:01:17 -0400331 skb_copy_from_linear_data(skb, pdata, len);
332 pdata += len;
333 for (j = 0; j < last_frag; j++) {
334 skb_frag_t *frag = &skb_shinfo(skb)->frags[j];
335 void *fptr;
336
337 fptr = skb_frag_address_safe(frag);
338 if (!fptr)
339 goto normal_tx;
340
341 memcpy(pdata, fptr, skb_frag_size(frag));
342 pdata += skb_frag_size(frag);
343 }
344
Michael Chan4419dbe2016-02-10 17:33:49 -0500345 txbd->tx_bd_len_flags_type = tx_push->tx_bd_len_flags_type;
346 txbd->tx_bd_haddr = txr->data_mapping;
Michael Chanc0c050c2015-10-22 16:01:17 -0400347 prod = NEXT_TX(prod);
348 txbd = &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)];
349 memcpy(txbd, tx_push1, sizeof(*txbd));
350 prod = NEXT_TX(prod);
Michael Chan4419dbe2016-02-10 17:33:49 -0500351 tx_push->doorbell =
Michael Chanc0c050c2015-10-22 16:01:17 -0400352 cpu_to_le32(DB_KEY_TX_PUSH | DB_LONG_TX_PUSH | prod);
353 txr->tx_prod = prod;
354
Michael Chanb9a84602016-06-06 02:37:14 -0400355 tx_buf->is_push = 1;
Michael Chanc0c050c2015-10-22 16:01:17 -0400356 netdev_tx_sent_queue(txq, skb->len);
Michael Chanb9a84602016-06-06 02:37:14 -0400357 wmb(); /* Sync is_push and byte queue before pushing data */
Michael Chanc0c050c2015-10-22 16:01:17 -0400358
Michael Chan4419dbe2016-02-10 17:33:49 -0500359 push_len = (length + sizeof(*tx_push) + 7) / 8;
360 if (push_len > 16) {
361 __iowrite64_copy(txr->tx_doorbell, tx_push_buf, 16);
Michael Chan9d137442016-09-05 01:57:35 -0400362 __iowrite32_copy(txr->tx_doorbell + 4, tx_push_buf + 1,
363 (push_len - 16) << 1);
Michael Chan4419dbe2016-02-10 17:33:49 -0500364 } else {
365 __iowrite64_copy(txr->tx_doorbell, tx_push_buf,
366 push_len);
367 }
Michael Chanc0c050c2015-10-22 16:01:17 -0400368
Michael Chanc0c050c2015-10-22 16:01:17 -0400369 goto tx_done;
370 }
371
372normal_tx:
373 if (length < BNXT_MIN_PKT_SIZE) {
374 pad = BNXT_MIN_PKT_SIZE - length;
375 if (skb_pad(skb, pad)) {
376 /* SKB already freed. */
377 tx_buf->skb = NULL;
378 return NETDEV_TX_OK;
379 }
380 length = BNXT_MIN_PKT_SIZE;
381 }
382
383 mapping = dma_map_single(&pdev->dev, skb->data, len, DMA_TO_DEVICE);
384
385 if (unlikely(dma_mapping_error(&pdev->dev, mapping))) {
386 dev_kfree_skb_any(skb);
387 tx_buf->skb = NULL;
388 return NETDEV_TX_OK;
389 }
390
391 dma_unmap_addr_set(tx_buf, mapping, mapping);
392 flags = (len << TX_BD_LEN_SHIFT) | TX_BD_TYPE_LONG_TX_BD |
393 ((last_frag + 2) << TX_BD_FLAGS_BD_CNT_SHIFT);
394
395 txbd->tx_bd_haddr = cpu_to_le64(mapping);
396
397 prod = NEXT_TX(prod);
398 txbd1 = (struct tx_bd_ext *)
399 &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)];
400
401 txbd1->tx_bd_hsize_lflags = 0;
402 if (skb_is_gso(skb)) {
403 u32 hdr_len;
404
405 if (skb->encapsulation)
406 hdr_len = skb_inner_network_offset(skb) +
407 skb_inner_network_header_len(skb) +
408 inner_tcp_hdrlen(skb);
409 else
410 hdr_len = skb_transport_offset(skb) +
411 tcp_hdrlen(skb);
412
413 txbd1->tx_bd_hsize_lflags = cpu_to_le32(TX_BD_FLAGS_LSO |
414 TX_BD_FLAGS_T_IPID |
415 (hdr_len << (TX_BD_HSIZE_SHIFT - 1)));
416 length = skb_shinfo(skb)->gso_size;
417 txbd1->tx_bd_mss = cpu_to_le32(length);
418 length += hdr_len;
419 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
420 txbd1->tx_bd_hsize_lflags =
421 cpu_to_le32(TX_BD_FLAGS_TCP_UDP_CHKSUM);
422 txbd1->tx_bd_mss = 0;
423 }
424
425 length >>= 9;
426 flags |= bnxt_lhint_arr[length];
427 txbd->tx_bd_len_flags_type = cpu_to_le32(flags);
428
429 txbd1->tx_bd_cfa_meta = cpu_to_le32(vlan_tag_flags);
430 txbd1->tx_bd_cfa_action = cpu_to_le32(cfa_action);
431 for (i = 0; i < last_frag; i++) {
432 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
433
434 prod = NEXT_TX(prod);
435 txbd = &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)];
436
437 len = skb_frag_size(frag);
438 mapping = skb_frag_dma_map(&pdev->dev, frag, 0, len,
439 DMA_TO_DEVICE);
440
441 if (unlikely(dma_mapping_error(&pdev->dev, mapping)))
442 goto tx_dma_error;
443
444 tx_buf = &txr->tx_buf_ring[prod];
445 dma_unmap_addr_set(tx_buf, mapping, mapping);
446
447 txbd->tx_bd_haddr = cpu_to_le64(mapping);
448
449 flags = len << TX_BD_LEN_SHIFT;
450 txbd->tx_bd_len_flags_type = cpu_to_le32(flags);
451 }
452
453 flags &= ~TX_BD_LEN;
454 txbd->tx_bd_len_flags_type =
455 cpu_to_le32(((len + pad) << TX_BD_LEN_SHIFT) | flags |
456 TX_BD_FLAGS_PACKET_END);
457
458 netdev_tx_sent_queue(txq, skb->len);
459
460 /* Sync BD data before updating doorbell */
461 wmb();
462
463 prod = NEXT_TX(prod);
464 txr->tx_prod = prod;
465
466 writel(DB_KEY_TX | prod, txr->tx_doorbell);
467 writel(DB_KEY_TX | prod, txr->tx_doorbell);
468
469tx_done:
470
471 mmiowb();
472
473 if (unlikely(bnxt_tx_avail(bp, txr) <= MAX_SKB_FRAGS + 1)) {
474 netif_tx_stop_queue(txq);
475
476 /* netif_tx_stop_queue() must be done before checking
477 * tx index in bnxt_tx_avail() below, because in
478 * bnxt_tx_int(), we update tx index before checking for
479 * netif_tx_queue_stopped().
480 */
481 smp_mb();
482 if (bnxt_tx_avail(bp, txr) > bp->tx_wake_thresh)
483 netif_tx_wake_queue(txq);
484 }
485 return NETDEV_TX_OK;
486
487tx_dma_error:
488 last_frag = i;
489
490 /* start back at beginning and unmap skb */
491 prod = txr->tx_prod;
492 tx_buf = &txr->tx_buf_ring[prod];
493 tx_buf->skb = NULL;
494 dma_unmap_single(&pdev->dev, dma_unmap_addr(tx_buf, mapping),
495 skb_headlen(skb), PCI_DMA_TODEVICE);
496 prod = NEXT_TX(prod);
497
498 /* unmap remaining mapped pages */
499 for (i = 0; i < last_frag; i++) {
500 prod = NEXT_TX(prod);
501 tx_buf = &txr->tx_buf_ring[prod];
502 dma_unmap_page(&pdev->dev, dma_unmap_addr(tx_buf, mapping),
503 skb_frag_size(&skb_shinfo(skb)->frags[i]),
504 PCI_DMA_TODEVICE);
505 }
506
507 dev_kfree_skb_any(skb);
508 return NETDEV_TX_OK;
509}
510
511static void bnxt_tx_int(struct bnxt *bp, struct bnxt_napi *bnapi, int nr_pkts)
512{
Michael Chanb6ab4b02016-01-02 23:44:59 -0500513 struct bnxt_tx_ring_info *txr = bnapi->tx_ring;
Michael Chana960dec2017-02-06 16:55:39 -0500514 struct netdev_queue *txq = netdev_get_tx_queue(bp->dev, txr->txq_index);
Michael Chanc0c050c2015-10-22 16:01:17 -0400515 u16 cons = txr->tx_cons;
516 struct pci_dev *pdev = bp->pdev;
517 int i;
518 unsigned int tx_bytes = 0;
519
520 for (i = 0; i < nr_pkts; i++) {
521 struct bnxt_sw_tx_bd *tx_buf;
522 struct sk_buff *skb;
523 int j, last;
524
525 tx_buf = &txr->tx_buf_ring[cons];
526 cons = NEXT_TX(cons);
527 skb = tx_buf->skb;
528 tx_buf->skb = NULL;
529
530 if (tx_buf->is_push) {
531 tx_buf->is_push = 0;
532 goto next_tx_int;
533 }
534
535 dma_unmap_single(&pdev->dev, dma_unmap_addr(tx_buf, mapping),
536 skb_headlen(skb), PCI_DMA_TODEVICE);
537 last = tx_buf->nr_frags;
538
539 for (j = 0; j < last; j++) {
540 cons = NEXT_TX(cons);
541 tx_buf = &txr->tx_buf_ring[cons];
542 dma_unmap_page(
543 &pdev->dev,
544 dma_unmap_addr(tx_buf, mapping),
545 skb_frag_size(&skb_shinfo(skb)->frags[j]),
546 PCI_DMA_TODEVICE);
547 }
548
549next_tx_int:
550 cons = NEXT_TX(cons);
551
552 tx_bytes += skb->len;
553 dev_kfree_skb_any(skb);
554 }
555
556 netdev_tx_completed_queue(txq, nr_pkts, tx_bytes);
557 txr->tx_cons = cons;
558
559 /* Need to make the tx_cons update visible to bnxt_start_xmit()
560 * before checking for netif_tx_queue_stopped(). Without the
561 * memory barrier, there is a small possibility that bnxt_start_xmit()
562 * will miss it and cause the queue to be stopped forever.
563 */
564 smp_mb();
565
566 if (unlikely(netif_tx_queue_stopped(txq)) &&
567 (bnxt_tx_avail(bp, txr) > bp->tx_wake_thresh)) {
568 __netif_tx_lock(txq, smp_processor_id());
569 if (netif_tx_queue_stopped(txq) &&
570 bnxt_tx_avail(bp, txr) > bp->tx_wake_thresh &&
571 txr->dev_state != BNXT_DEV_STATE_CLOSING)
572 netif_tx_wake_queue(txq);
573 __netif_tx_unlock(txq);
574 }
575}
576
Michael Chanc61fb992017-02-06 16:55:36 -0500577static struct page *__bnxt_alloc_rx_page(struct bnxt *bp, dma_addr_t *mapping,
578 gfp_t gfp)
579{
580 struct device *dev = &bp->pdev->dev;
581 struct page *page;
582
583 page = alloc_page(gfp);
584 if (!page)
585 return NULL;
586
Shannon Nelsonc519fe92017-05-09 18:30:12 -0700587 *mapping = dma_map_page_attrs(dev, page, 0, PAGE_SIZE, bp->rx_dir,
588 DMA_ATTR_WEAK_ORDERING);
Michael Chanc61fb992017-02-06 16:55:36 -0500589 if (dma_mapping_error(dev, *mapping)) {
590 __free_page(page);
591 return NULL;
592 }
593 *mapping += bp->rx_dma_offset;
594 return page;
595}
596
Michael Chanc0c050c2015-10-22 16:01:17 -0400597static inline u8 *__bnxt_alloc_rx_data(struct bnxt *bp, dma_addr_t *mapping,
598 gfp_t gfp)
599{
600 u8 *data;
601 struct pci_dev *pdev = bp->pdev;
602
603 data = kmalloc(bp->rx_buf_size, gfp);
604 if (!data)
605 return NULL;
606
Shannon Nelsonc519fe92017-05-09 18:30:12 -0700607 *mapping = dma_map_single_attrs(&pdev->dev, data + bp->rx_dma_offset,
608 bp->rx_buf_use_size, bp->rx_dir,
609 DMA_ATTR_WEAK_ORDERING);
Michael Chanc0c050c2015-10-22 16:01:17 -0400610
611 if (dma_mapping_error(&pdev->dev, *mapping)) {
612 kfree(data);
613 data = NULL;
614 }
615 return data;
616}
617
Michael Chan38413402017-02-06 16:55:43 -0500618int bnxt_alloc_rx_data(struct bnxt *bp, struct bnxt_rx_ring_info *rxr,
619 u16 prod, gfp_t gfp)
Michael Chanc0c050c2015-10-22 16:01:17 -0400620{
621 struct rx_bd *rxbd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)];
622 struct bnxt_sw_rx_bd *rx_buf = &rxr->rx_buf_ring[prod];
Michael Chanc0c050c2015-10-22 16:01:17 -0400623 dma_addr_t mapping;
624
Michael Chanc61fb992017-02-06 16:55:36 -0500625 if (BNXT_RX_PAGE_MODE(bp)) {
626 struct page *page = __bnxt_alloc_rx_page(bp, &mapping, gfp);
Michael Chanc0c050c2015-10-22 16:01:17 -0400627
Michael Chanc61fb992017-02-06 16:55:36 -0500628 if (!page)
629 return -ENOMEM;
630
631 rx_buf->data = page;
632 rx_buf->data_ptr = page_address(page) + bp->rx_offset;
633 } else {
634 u8 *data = __bnxt_alloc_rx_data(bp, &mapping, gfp);
635
636 if (!data)
637 return -ENOMEM;
638
639 rx_buf->data = data;
640 rx_buf->data_ptr = data + bp->rx_offset;
641 }
Michael Chan11cd1192017-02-06 16:55:33 -0500642 rx_buf->mapping = mapping;
Michael Chanc0c050c2015-10-22 16:01:17 -0400643
644 rxbd->rx_bd_haddr = cpu_to_le64(mapping);
Michael Chanc0c050c2015-10-22 16:01:17 -0400645 return 0;
646}
647
Michael Chanc6d30e82017-02-06 16:55:42 -0500648void bnxt_reuse_rx_data(struct bnxt_rx_ring_info *rxr, u16 cons, void *data)
Michael Chanc0c050c2015-10-22 16:01:17 -0400649{
650 u16 prod = rxr->rx_prod;
651 struct bnxt_sw_rx_bd *cons_rx_buf, *prod_rx_buf;
652 struct rx_bd *cons_bd, *prod_bd;
653
654 prod_rx_buf = &rxr->rx_buf_ring[prod];
655 cons_rx_buf = &rxr->rx_buf_ring[cons];
656
657 prod_rx_buf->data = data;
Michael Chan6bb19472017-02-06 16:55:32 -0500658 prod_rx_buf->data_ptr = cons_rx_buf->data_ptr;
Michael Chanc0c050c2015-10-22 16:01:17 -0400659
Michael Chan11cd1192017-02-06 16:55:33 -0500660 prod_rx_buf->mapping = cons_rx_buf->mapping;
Michael Chanc0c050c2015-10-22 16:01:17 -0400661
662 prod_bd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)];
663 cons_bd = &rxr->rx_desc_ring[RX_RING(cons)][RX_IDX(cons)];
664
665 prod_bd->rx_bd_haddr = cons_bd->rx_bd_haddr;
666}
667
668static inline u16 bnxt_find_next_agg_idx(struct bnxt_rx_ring_info *rxr, u16 idx)
669{
670 u16 next, max = rxr->rx_agg_bmap_size;
671
672 next = find_next_zero_bit(rxr->rx_agg_bmap, max, idx);
673 if (next >= max)
674 next = find_first_zero_bit(rxr->rx_agg_bmap, max);
675 return next;
676}
677
678static inline int bnxt_alloc_rx_page(struct bnxt *bp,
679 struct bnxt_rx_ring_info *rxr,
680 u16 prod, gfp_t gfp)
681{
682 struct rx_bd *rxbd =
683 &rxr->rx_agg_desc_ring[RX_RING(prod)][RX_IDX(prod)];
684 struct bnxt_sw_rx_agg_bd *rx_agg_buf;
685 struct pci_dev *pdev = bp->pdev;
686 struct page *page;
687 dma_addr_t mapping;
688 u16 sw_prod = rxr->rx_sw_agg_prod;
Michael Chan89d0a062016-04-25 02:30:51 -0400689 unsigned int offset = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -0400690
Michael Chan89d0a062016-04-25 02:30:51 -0400691 if (PAGE_SIZE > BNXT_RX_PAGE_SIZE) {
692 page = rxr->rx_page;
693 if (!page) {
694 page = alloc_page(gfp);
695 if (!page)
696 return -ENOMEM;
697 rxr->rx_page = page;
698 rxr->rx_page_offset = 0;
699 }
700 offset = rxr->rx_page_offset;
701 rxr->rx_page_offset += BNXT_RX_PAGE_SIZE;
702 if (rxr->rx_page_offset == PAGE_SIZE)
703 rxr->rx_page = NULL;
704 else
705 get_page(page);
706 } else {
707 page = alloc_page(gfp);
708 if (!page)
709 return -ENOMEM;
710 }
Michael Chanc0c050c2015-10-22 16:01:17 -0400711
Shannon Nelsonc519fe92017-05-09 18:30:12 -0700712 mapping = dma_map_page_attrs(&pdev->dev, page, offset,
713 BNXT_RX_PAGE_SIZE, PCI_DMA_FROMDEVICE,
714 DMA_ATTR_WEAK_ORDERING);
Michael Chanc0c050c2015-10-22 16:01:17 -0400715 if (dma_mapping_error(&pdev->dev, mapping)) {
716 __free_page(page);
717 return -EIO;
718 }
719
720 if (unlikely(test_bit(sw_prod, rxr->rx_agg_bmap)))
721 sw_prod = bnxt_find_next_agg_idx(rxr, sw_prod);
722
723 __set_bit(sw_prod, rxr->rx_agg_bmap);
724 rx_agg_buf = &rxr->rx_agg_ring[sw_prod];
725 rxr->rx_sw_agg_prod = NEXT_RX_AGG(sw_prod);
726
727 rx_agg_buf->page = page;
Michael Chan89d0a062016-04-25 02:30:51 -0400728 rx_agg_buf->offset = offset;
Michael Chanc0c050c2015-10-22 16:01:17 -0400729 rx_agg_buf->mapping = mapping;
730 rxbd->rx_bd_haddr = cpu_to_le64(mapping);
731 rxbd->rx_bd_opaque = sw_prod;
732 return 0;
733}
734
735static void bnxt_reuse_rx_agg_bufs(struct bnxt_napi *bnapi, u16 cp_cons,
736 u32 agg_bufs)
737{
738 struct bnxt *bp = bnapi->bp;
739 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
Michael Chanb6ab4b02016-01-02 23:44:59 -0500740 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
Michael Chanc0c050c2015-10-22 16:01:17 -0400741 u16 prod = rxr->rx_agg_prod;
742 u16 sw_prod = rxr->rx_sw_agg_prod;
743 u32 i;
744
745 for (i = 0; i < agg_bufs; i++) {
746 u16 cons;
747 struct rx_agg_cmp *agg;
748 struct bnxt_sw_rx_agg_bd *cons_rx_buf, *prod_rx_buf;
749 struct rx_bd *prod_bd;
750 struct page *page;
751
752 agg = (struct rx_agg_cmp *)
753 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
754 cons = agg->rx_agg_cmp_opaque;
755 __clear_bit(cons, rxr->rx_agg_bmap);
756
757 if (unlikely(test_bit(sw_prod, rxr->rx_agg_bmap)))
758 sw_prod = bnxt_find_next_agg_idx(rxr, sw_prod);
759
760 __set_bit(sw_prod, rxr->rx_agg_bmap);
761 prod_rx_buf = &rxr->rx_agg_ring[sw_prod];
762 cons_rx_buf = &rxr->rx_agg_ring[cons];
763
764 /* It is possible for sw_prod to be equal to cons, so
765 * set cons_rx_buf->page to NULL first.
766 */
767 page = cons_rx_buf->page;
768 cons_rx_buf->page = NULL;
769 prod_rx_buf->page = page;
Michael Chan89d0a062016-04-25 02:30:51 -0400770 prod_rx_buf->offset = cons_rx_buf->offset;
Michael Chanc0c050c2015-10-22 16:01:17 -0400771
772 prod_rx_buf->mapping = cons_rx_buf->mapping;
773
774 prod_bd = &rxr->rx_agg_desc_ring[RX_RING(prod)][RX_IDX(prod)];
775
776 prod_bd->rx_bd_haddr = cpu_to_le64(cons_rx_buf->mapping);
777 prod_bd->rx_bd_opaque = sw_prod;
778
779 prod = NEXT_RX_AGG(prod);
780 sw_prod = NEXT_RX_AGG(sw_prod);
781 cp_cons = NEXT_CMP(cp_cons);
782 }
783 rxr->rx_agg_prod = prod;
784 rxr->rx_sw_agg_prod = sw_prod;
785}
786
Michael Chanc61fb992017-02-06 16:55:36 -0500787static struct sk_buff *bnxt_rx_page_skb(struct bnxt *bp,
788 struct bnxt_rx_ring_info *rxr,
789 u16 cons, void *data, u8 *data_ptr,
790 dma_addr_t dma_addr,
791 unsigned int offset_and_len)
792{
793 unsigned int payload = offset_and_len >> 16;
794 unsigned int len = offset_and_len & 0xffff;
795 struct skb_frag_struct *frag;
796 struct page *page = data;
797 u16 prod = rxr->rx_prod;
798 struct sk_buff *skb;
799 int off, err;
800
801 err = bnxt_alloc_rx_data(bp, rxr, prod, GFP_ATOMIC);
802 if (unlikely(err)) {
803 bnxt_reuse_rx_data(rxr, cons, data);
804 return NULL;
805 }
806 dma_addr -= bp->rx_dma_offset;
Shannon Nelsonc519fe92017-05-09 18:30:12 -0700807 dma_unmap_page_attrs(&bp->pdev->dev, dma_addr, PAGE_SIZE, bp->rx_dir,
808 DMA_ATTR_WEAK_ORDERING);
Michael Chanc61fb992017-02-06 16:55:36 -0500809
810 if (unlikely(!payload))
811 payload = eth_get_headlen(data_ptr, len);
812
813 skb = napi_alloc_skb(&rxr->bnapi->napi, payload);
814 if (!skb) {
815 __free_page(page);
816 return NULL;
817 }
818
819 off = (void *)data_ptr - page_address(page);
820 skb_add_rx_frag(skb, 0, page, off, len, PAGE_SIZE);
821 memcpy(skb->data - NET_IP_ALIGN, data_ptr - NET_IP_ALIGN,
822 payload + NET_IP_ALIGN);
823
824 frag = &skb_shinfo(skb)->frags[0];
825 skb_frag_size_sub(frag, payload);
826 frag->page_offset += payload;
827 skb->data_len -= payload;
828 skb->tail += payload;
829
830 return skb;
831}
832
Michael Chanc0c050c2015-10-22 16:01:17 -0400833static struct sk_buff *bnxt_rx_skb(struct bnxt *bp,
834 struct bnxt_rx_ring_info *rxr, u16 cons,
Michael Chan6bb19472017-02-06 16:55:32 -0500835 void *data, u8 *data_ptr,
836 dma_addr_t dma_addr,
837 unsigned int offset_and_len)
Michael Chanc0c050c2015-10-22 16:01:17 -0400838{
Michael Chan6bb19472017-02-06 16:55:32 -0500839 u16 prod = rxr->rx_prod;
Michael Chanc0c050c2015-10-22 16:01:17 -0400840 struct sk_buff *skb;
Michael Chan6bb19472017-02-06 16:55:32 -0500841 int err;
Michael Chanc0c050c2015-10-22 16:01:17 -0400842
843 err = bnxt_alloc_rx_data(bp, rxr, prod, GFP_ATOMIC);
844 if (unlikely(err)) {
845 bnxt_reuse_rx_data(rxr, cons, data);
846 return NULL;
847 }
848
849 skb = build_skb(data, 0);
Shannon Nelsonc519fe92017-05-09 18:30:12 -0700850 dma_unmap_single_attrs(&bp->pdev->dev, dma_addr, bp->rx_buf_use_size,
851 bp->rx_dir, DMA_ATTR_WEAK_ORDERING);
Michael Chanc0c050c2015-10-22 16:01:17 -0400852 if (!skb) {
853 kfree(data);
854 return NULL;
855 }
856
Michael Chanb3dba772017-02-06 16:55:35 -0500857 skb_reserve(skb, bp->rx_offset);
Michael Chan6bb19472017-02-06 16:55:32 -0500858 skb_put(skb, offset_and_len & 0xffff);
Michael Chanc0c050c2015-10-22 16:01:17 -0400859 return skb;
860}
861
862static struct sk_buff *bnxt_rx_pages(struct bnxt *bp, struct bnxt_napi *bnapi,
863 struct sk_buff *skb, u16 cp_cons,
864 u32 agg_bufs)
865{
866 struct pci_dev *pdev = bp->pdev;
867 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
Michael Chanb6ab4b02016-01-02 23:44:59 -0500868 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
Michael Chanc0c050c2015-10-22 16:01:17 -0400869 u16 prod = rxr->rx_agg_prod;
870 u32 i;
871
872 for (i = 0; i < agg_bufs; i++) {
873 u16 cons, frag_len;
874 struct rx_agg_cmp *agg;
875 struct bnxt_sw_rx_agg_bd *cons_rx_buf;
876 struct page *page;
877 dma_addr_t mapping;
878
879 agg = (struct rx_agg_cmp *)
880 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
881 cons = agg->rx_agg_cmp_opaque;
882 frag_len = (le32_to_cpu(agg->rx_agg_cmp_len_flags_type) &
883 RX_AGG_CMP_LEN) >> RX_AGG_CMP_LEN_SHIFT;
884
885 cons_rx_buf = &rxr->rx_agg_ring[cons];
Michael Chan89d0a062016-04-25 02:30:51 -0400886 skb_fill_page_desc(skb, i, cons_rx_buf->page,
887 cons_rx_buf->offset, frag_len);
Michael Chanc0c050c2015-10-22 16:01:17 -0400888 __clear_bit(cons, rxr->rx_agg_bmap);
889
890 /* It is possible for bnxt_alloc_rx_page() to allocate
891 * a sw_prod index that equals the cons index, so we
892 * need to clear the cons entry now.
893 */
Michael Chan11cd1192017-02-06 16:55:33 -0500894 mapping = cons_rx_buf->mapping;
Michael Chanc0c050c2015-10-22 16:01:17 -0400895 page = cons_rx_buf->page;
896 cons_rx_buf->page = NULL;
897
898 if (bnxt_alloc_rx_page(bp, rxr, prod, GFP_ATOMIC) != 0) {
899 struct skb_shared_info *shinfo;
900 unsigned int nr_frags;
901
902 shinfo = skb_shinfo(skb);
903 nr_frags = --shinfo->nr_frags;
904 __skb_frag_set_page(&shinfo->frags[nr_frags], NULL);
905
906 dev_kfree_skb(skb);
907
908 cons_rx_buf->page = page;
909
910 /* Update prod since possibly some pages have been
911 * allocated already.
912 */
913 rxr->rx_agg_prod = prod;
914 bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs - i);
915 return NULL;
916 }
917
Shannon Nelsonc519fe92017-05-09 18:30:12 -0700918 dma_unmap_page_attrs(&pdev->dev, mapping, BNXT_RX_PAGE_SIZE,
919 PCI_DMA_FROMDEVICE,
920 DMA_ATTR_WEAK_ORDERING);
Michael Chanc0c050c2015-10-22 16:01:17 -0400921
922 skb->data_len += frag_len;
923 skb->len += frag_len;
924 skb->truesize += PAGE_SIZE;
925
926 prod = NEXT_RX_AGG(prod);
927 cp_cons = NEXT_CMP(cp_cons);
928 }
929 rxr->rx_agg_prod = prod;
930 return skb;
931}
932
933static int bnxt_agg_bufs_valid(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
934 u8 agg_bufs, u32 *raw_cons)
935{
936 u16 last;
937 struct rx_agg_cmp *agg;
938
939 *raw_cons = ADV_RAW_CMP(*raw_cons, agg_bufs);
940 last = RING_CMP(*raw_cons);
941 agg = (struct rx_agg_cmp *)
942 &cpr->cp_desc_ring[CP_RING(last)][CP_IDX(last)];
943 return RX_AGG_CMP_VALID(agg, *raw_cons);
944}
945
946static inline struct sk_buff *bnxt_copy_skb(struct bnxt_napi *bnapi, u8 *data,
947 unsigned int len,
948 dma_addr_t mapping)
949{
950 struct bnxt *bp = bnapi->bp;
951 struct pci_dev *pdev = bp->pdev;
952 struct sk_buff *skb;
953
954 skb = napi_alloc_skb(&bnapi->napi, len);
955 if (!skb)
956 return NULL;
957
Michael Chan745fc052017-02-06 16:55:34 -0500958 dma_sync_single_for_cpu(&pdev->dev, mapping, bp->rx_copy_thresh,
959 bp->rx_dir);
Michael Chanc0c050c2015-10-22 16:01:17 -0400960
Michael Chan6bb19472017-02-06 16:55:32 -0500961 memcpy(skb->data - NET_IP_ALIGN, data - NET_IP_ALIGN,
962 len + NET_IP_ALIGN);
Michael Chanc0c050c2015-10-22 16:01:17 -0400963
Michael Chan745fc052017-02-06 16:55:34 -0500964 dma_sync_single_for_device(&pdev->dev, mapping, bp->rx_copy_thresh,
965 bp->rx_dir);
Michael Chanc0c050c2015-10-22 16:01:17 -0400966
967 skb_put(skb, len);
968 return skb;
969}
970
Michael Chanfa7e2812016-05-10 19:18:00 -0400971static int bnxt_discard_rx(struct bnxt *bp, struct bnxt_napi *bnapi,
972 u32 *raw_cons, void *cmp)
973{
974 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
975 struct rx_cmp *rxcmp = cmp;
976 u32 tmp_raw_cons = *raw_cons;
977 u8 cmp_type, agg_bufs = 0;
978
979 cmp_type = RX_CMP_TYPE(rxcmp);
980
981 if (cmp_type == CMP_TYPE_RX_L2_CMP) {
982 agg_bufs = (le32_to_cpu(rxcmp->rx_cmp_misc_v1) &
983 RX_CMP_AGG_BUFS) >>
984 RX_CMP_AGG_BUFS_SHIFT;
985 } else if (cmp_type == CMP_TYPE_RX_L2_TPA_END_CMP) {
986 struct rx_tpa_end_cmp *tpa_end = cmp;
987
988 agg_bufs = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) &
989 RX_TPA_END_CMP_AGG_BUFS) >>
990 RX_TPA_END_CMP_AGG_BUFS_SHIFT;
991 }
992
993 if (agg_bufs) {
994 if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, &tmp_raw_cons))
995 return -EBUSY;
996 }
997 *raw_cons = tmp_raw_cons;
998 return 0;
999}
1000
1001static void bnxt_sched_reset(struct bnxt *bp, struct bnxt_rx_ring_info *rxr)
1002{
1003 if (!rxr->bnapi->in_reset) {
1004 rxr->bnapi->in_reset = true;
1005 set_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event);
1006 schedule_work(&bp->sp_task);
1007 }
1008 rxr->rx_next_cons = 0xffff;
1009}
1010
Michael Chanc0c050c2015-10-22 16:01:17 -04001011static void bnxt_tpa_start(struct bnxt *bp, struct bnxt_rx_ring_info *rxr,
1012 struct rx_tpa_start_cmp *tpa_start,
1013 struct rx_tpa_start_cmp_ext *tpa_start1)
1014{
1015 u8 agg_id = TPA_START_AGG_ID(tpa_start);
1016 u16 cons, prod;
1017 struct bnxt_tpa_info *tpa_info;
1018 struct bnxt_sw_rx_bd *cons_rx_buf, *prod_rx_buf;
1019 struct rx_bd *prod_bd;
1020 dma_addr_t mapping;
1021
1022 cons = tpa_start->rx_tpa_start_cmp_opaque;
1023 prod = rxr->rx_prod;
1024 cons_rx_buf = &rxr->rx_buf_ring[cons];
1025 prod_rx_buf = &rxr->rx_buf_ring[prod];
1026 tpa_info = &rxr->rx_tpa[agg_id];
1027
Michael Chanfa7e2812016-05-10 19:18:00 -04001028 if (unlikely(cons != rxr->rx_next_cons)) {
1029 bnxt_sched_reset(bp, rxr);
1030 return;
1031 }
1032
Michael Chanc0c050c2015-10-22 16:01:17 -04001033 prod_rx_buf->data = tpa_info->data;
Michael Chan6bb19472017-02-06 16:55:32 -05001034 prod_rx_buf->data_ptr = tpa_info->data_ptr;
Michael Chanc0c050c2015-10-22 16:01:17 -04001035
1036 mapping = tpa_info->mapping;
Michael Chan11cd1192017-02-06 16:55:33 -05001037 prod_rx_buf->mapping = mapping;
Michael Chanc0c050c2015-10-22 16:01:17 -04001038
1039 prod_bd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)];
1040
1041 prod_bd->rx_bd_haddr = cpu_to_le64(mapping);
1042
1043 tpa_info->data = cons_rx_buf->data;
Michael Chan6bb19472017-02-06 16:55:32 -05001044 tpa_info->data_ptr = cons_rx_buf->data_ptr;
Michael Chanc0c050c2015-10-22 16:01:17 -04001045 cons_rx_buf->data = NULL;
Michael Chan11cd1192017-02-06 16:55:33 -05001046 tpa_info->mapping = cons_rx_buf->mapping;
Michael Chanc0c050c2015-10-22 16:01:17 -04001047
1048 tpa_info->len =
1049 le32_to_cpu(tpa_start->rx_tpa_start_cmp_len_flags_type) >>
1050 RX_TPA_START_CMP_LEN_SHIFT;
1051 if (likely(TPA_START_HASH_VALID(tpa_start))) {
1052 u32 hash_type = TPA_START_HASH_TYPE(tpa_start);
1053
1054 tpa_info->hash_type = PKT_HASH_TYPE_L4;
1055 tpa_info->gso_type = SKB_GSO_TCPV4;
1056 /* RSS profiles 1 and 3 with extract code 0 for inner 4-tuple */
1057 if (hash_type == 3)
1058 tpa_info->gso_type = SKB_GSO_TCPV6;
1059 tpa_info->rss_hash =
1060 le32_to_cpu(tpa_start->rx_tpa_start_cmp_rss_hash);
1061 } else {
1062 tpa_info->hash_type = PKT_HASH_TYPE_NONE;
1063 tpa_info->gso_type = 0;
1064 if (netif_msg_rx_err(bp))
1065 netdev_warn(bp->dev, "TPA packet without valid hash\n");
1066 }
1067 tpa_info->flags2 = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_flags2);
1068 tpa_info->metadata = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_metadata);
Michael Chan94758f82016-06-13 02:25:35 -04001069 tpa_info->hdr_info = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_hdr_info);
Michael Chanc0c050c2015-10-22 16:01:17 -04001070
1071 rxr->rx_prod = NEXT_RX(prod);
1072 cons = NEXT_RX(cons);
Michael Chan376a5b82016-05-10 19:17:59 -04001073 rxr->rx_next_cons = NEXT_RX(cons);
Michael Chanc0c050c2015-10-22 16:01:17 -04001074 cons_rx_buf = &rxr->rx_buf_ring[cons];
1075
1076 bnxt_reuse_rx_data(rxr, cons, cons_rx_buf->data);
1077 rxr->rx_prod = NEXT_RX(rxr->rx_prod);
1078 cons_rx_buf->data = NULL;
1079}
1080
1081static void bnxt_abort_tpa(struct bnxt *bp, struct bnxt_napi *bnapi,
1082 u16 cp_cons, u32 agg_bufs)
1083{
1084 if (agg_bufs)
1085 bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs);
1086}
1087
Michael Chan94758f82016-06-13 02:25:35 -04001088static struct sk_buff *bnxt_gro_func_5731x(struct bnxt_tpa_info *tpa_info,
1089 int payload_off, int tcp_ts,
1090 struct sk_buff *skb)
1091{
1092#ifdef CONFIG_INET
1093 struct tcphdr *th;
1094 int len, nw_off;
1095 u16 outer_ip_off, inner_ip_off, inner_mac_off;
1096 u32 hdr_info = tpa_info->hdr_info;
1097 bool loopback = false;
1098
1099 inner_ip_off = BNXT_TPA_INNER_L3_OFF(hdr_info);
1100 inner_mac_off = BNXT_TPA_INNER_L2_OFF(hdr_info);
1101 outer_ip_off = BNXT_TPA_OUTER_L3_OFF(hdr_info);
1102
1103 /* If the packet is an internal loopback packet, the offsets will
1104 * have an extra 4 bytes.
1105 */
1106 if (inner_mac_off == 4) {
1107 loopback = true;
1108 } else if (inner_mac_off > 4) {
1109 __be16 proto = *((__be16 *)(skb->data + inner_ip_off -
1110 ETH_HLEN - 2));
1111
1112 /* We only support inner iPv4/ipv6. If we don't see the
1113 * correct protocol ID, it must be a loopback packet where
1114 * the offsets are off by 4.
1115 */
Dan Carpenter09a76362016-07-07 11:23:09 +03001116 if (proto != htons(ETH_P_IP) && proto != htons(ETH_P_IPV6))
Michael Chan94758f82016-06-13 02:25:35 -04001117 loopback = true;
1118 }
1119 if (loopback) {
1120 /* internal loopback packet, subtract all offsets by 4 */
1121 inner_ip_off -= 4;
1122 inner_mac_off -= 4;
1123 outer_ip_off -= 4;
1124 }
1125
1126 nw_off = inner_ip_off - ETH_HLEN;
1127 skb_set_network_header(skb, nw_off);
1128 if (tpa_info->flags2 & RX_TPA_START_CMP_FLAGS2_IP_TYPE) {
1129 struct ipv6hdr *iph = ipv6_hdr(skb);
1130
1131 skb_set_transport_header(skb, nw_off + sizeof(struct ipv6hdr));
1132 len = skb->len - skb_transport_offset(skb);
1133 th = tcp_hdr(skb);
1134 th->check = ~tcp_v6_check(len, &iph->saddr, &iph->daddr, 0);
1135 } else {
1136 struct iphdr *iph = ip_hdr(skb);
1137
1138 skb_set_transport_header(skb, nw_off + sizeof(struct iphdr));
1139 len = skb->len - skb_transport_offset(skb);
1140 th = tcp_hdr(skb);
1141 th->check = ~tcp_v4_check(len, iph->saddr, iph->daddr, 0);
1142 }
1143
1144 if (inner_mac_off) { /* tunnel */
1145 struct udphdr *uh = NULL;
1146 __be16 proto = *((__be16 *)(skb->data + outer_ip_off -
1147 ETH_HLEN - 2));
1148
1149 if (proto == htons(ETH_P_IP)) {
1150 struct iphdr *iph = (struct iphdr *)skb->data;
1151
1152 if (iph->protocol == IPPROTO_UDP)
1153 uh = (struct udphdr *)(iph + 1);
1154 } else {
1155 struct ipv6hdr *iph = (struct ipv6hdr *)skb->data;
1156
1157 if (iph->nexthdr == IPPROTO_UDP)
1158 uh = (struct udphdr *)(iph + 1);
1159 }
1160 if (uh) {
1161 if (uh->check)
1162 skb_shinfo(skb)->gso_type |=
1163 SKB_GSO_UDP_TUNNEL_CSUM;
1164 else
1165 skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL;
1166 }
1167 }
1168#endif
1169 return skb;
1170}
1171
Michael Chanc0c050c2015-10-22 16:01:17 -04001172#define BNXT_IPV4_HDR_SIZE (sizeof(struct iphdr) + sizeof(struct tcphdr))
1173#define BNXT_IPV6_HDR_SIZE (sizeof(struct ipv6hdr) + sizeof(struct tcphdr))
1174
Michael Chan309369c2016-06-13 02:25:34 -04001175static struct sk_buff *bnxt_gro_func_5730x(struct bnxt_tpa_info *tpa_info,
1176 int payload_off, int tcp_ts,
Michael Chanc0c050c2015-10-22 16:01:17 -04001177 struct sk_buff *skb)
1178{
Michael Chand1611c32015-10-25 22:27:57 -04001179#ifdef CONFIG_INET
Michael Chanc0c050c2015-10-22 16:01:17 -04001180 struct tcphdr *th;
Michael Chan719ca812017-01-17 22:07:19 -05001181 int len, nw_off, tcp_opt_len = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04001182
Michael Chan309369c2016-06-13 02:25:34 -04001183 if (tcp_ts)
Michael Chanc0c050c2015-10-22 16:01:17 -04001184 tcp_opt_len = 12;
1185
Michael Chanc0c050c2015-10-22 16:01:17 -04001186 if (tpa_info->gso_type == SKB_GSO_TCPV4) {
1187 struct iphdr *iph;
1188
1189 nw_off = payload_off - BNXT_IPV4_HDR_SIZE - tcp_opt_len -
1190 ETH_HLEN;
1191 skb_set_network_header(skb, nw_off);
1192 iph = ip_hdr(skb);
1193 skb_set_transport_header(skb, nw_off + sizeof(struct iphdr));
1194 len = skb->len - skb_transport_offset(skb);
1195 th = tcp_hdr(skb);
1196 th->check = ~tcp_v4_check(len, iph->saddr, iph->daddr, 0);
1197 } else if (tpa_info->gso_type == SKB_GSO_TCPV6) {
1198 struct ipv6hdr *iph;
1199
1200 nw_off = payload_off - BNXT_IPV6_HDR_SIZE - tcp_opt_len -
1201 ETH_HLEN;
1202 skb_set_network_header(skb, nw_off);
1203 iph = ipv6_hdr(skb);
1204 skb_set_transport_header(skb, nw_off + sizeof(struct ipv6hdr));
1205 len = skb->len - skb_transport_offset(skb);
1206 th = tcp_hdr(skb);
1207 th->check = ~tcp_v6_check(len, &iph->saddr, &iph->daddr, 0);
1208 } else {
1209 dev_kfree_skb_any(skb);
1210 return NULL;
1211 }
Michael Chanc0c050c2015-10-22 16:01:17 -04001212
1213 if (nw_off) { /* tunnel */
1214 struct udphdr *uh = NULL;
1215
1216 if (skb->protocol == htons(ETH_P_IP)) {
1217 struct iphdr *iph = (struct iphdr *)skb->data;
1218
1219 if (iph->protocol == IPPROTO_UDP)
1220 uh = (struct udphdr *)(iph + 1);
1221 } else {
1222 struct ipv6hdr *iph = (struct ipv6hdr *)skb->data;
1223
1224 if (iph->nexthdr == IPPROTO_UDP)
1225 uh = (struct udphdr *)(iph + 1);
1226 }
1227 if (uh) {
1228 if (uh->check)
1229 skb_shinfo(skb)->gso_type |=
1230 SKB_GSO_UDP_TUNNEL_CSUM;
1231 else
1232 skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL;
1233 }
1234 }
1235#endif
1236 return skb;
1237}
1238
Michael Chan309369c2016-06-13 02:25:34 -04001239static inline struct sk_buff *bnxt_gro_skb(struct bnxt *bp,
1240 struct bnxt_tpa_info *tpa_info,
1241 struct rx_tpa_end_cmp *tpa_end,
1242 struct rx_tpa_end_cmp_ext *tpa_end1,
1243 struct sk_buff *skb)
1244{
1245#ifdef CONFIG_INET
1246 int payload_off;
1247 u16 segs;
1248
1249 segs = TPA_END_TPA_SEGS(tpa_end);
1250 if (segs == 1)
1251 return skb;
1252
1253 NAPI_GRO_CB(skb)->count = segs;
1254 skb_shinfo(skb)->gso_size =
1255 le32_to_cpu(tpa_end1->rx_tpa_end_cmp_seg_len);
1256 skb_shinfo(skb)->gso_type = tpa_info->gso_type;
1257 payload_off = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) &
1258 RX_TPA_END_CMP_PAYLOAD_OFFSET) >>
1259 RX_TPA_END_CMP_PAYLOAD_OFFSET_SHIFT;
1260 skb = bp->gro_func(tpa_info, payload_off, TPA_END_GRO_TS(tpa_end), skb);
Michael Chan59109062016-12-29 12:13:35 -05001261 if (likely(skb))
1262 tcp_gro_complete(skb);
Michael Chan309369c2016-06-13 02:25:34 -04001263#endif
1264 return skb;
1265}
1266
Michael Chanc0c050c2015-10-22 16:01:17 -04001267static inline struct sk_buff *bnxt_tpa_end(struct bnxt *bp,
1268 struct bnxt_napi *bnapi,
1269 u32 *raw_cons,
1270 struct rx_tpa_end_cmp *tpa_end,
1271 struct rx_tpa_end_cmp_ext *tpa_end1,
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001272 u8 *event)
Michael Chanc0c050c2015-10-22 16:01:17 -04001273{
1274 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
Michael Chanb6ab4b02016-01-02 23:44:59 -05001275 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
Michael Chanc0c050c2015-10-22 16:01:17 -04001276 u8 agg_id = TPA_END_AGG_ID(tpa_end);
Michael Chan6bb19472017-02-06 16:55:32 -05001277 u8 *data_ptr, agg_bufs;
Michael Chanc0c050c2015-10-22 16:01:17 -04001278 u16 cp_cons = RING_CMP(*raw_cons);
1279 unsigned int len;
1280 struct bnxt_tpa_info *tpa_info;
1281 dma_addr_t mapping;
1282 struct sk_buff *skb;
Michael Chan6bb19472017-02-06 16:55:32 -05001283 void *data;
Michael Chanc0c050c2015-10-22 16:01:17 -04001284
Michael Chanfa7e2812016-05-10 19:18:00 -04001285 if (unlikely(bnapi->in_reset)) {
1286 int rc = bnxt_discard_rx(bp, bnapi, raw_cons, tpa_end);
1287
1288 if (rc < 0)
1289 return ERR_PTR(-EBUSY);
1290 return NULL;
1291 }
1292
Michael Chanc0c050c2015-10-22 16:01:17 -04001293 tpa_info = &rxr->rx_tpa[agg_id];
1294 data = tpa_info->data;
Michael Chan6bb19472017-02-06 16:55:32 -05001295 data_ptr = tpa_info->data_ptr;
1296 prefetch(data_ptr);
Michael Chanc0c050c2015-10-22 16:01:17 -04001297 len = tpa_info->len;
1298 mapping = tpa_info->mapping;
1299
1300 agg_bufs = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) &
1301 RX_TPA_END_CMP_AGG_BUFS) >> RX_TPA_END_CMP_AGG_BUFS_SHIFT;
1302
1303 if (agg_bufs) {
1304 if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, raw_cons))
1305 return ERR_PTR(-EBUSY);
1306
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001307 *event |= BNXT_AGG_EVENT;
Michael Chanc0c050c2015-10-22 16:01:17 -04001308 cp_cons = NEXT_CMP(cp_cons);
1309 }
1310
1311 if (unlikely(agg_bufs > MAX_SKB_FRAGS)) {
1312 bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs);
1313 netdev_warn(bp->dev, "TPA frags %d exceeded MAX_SKB_FRAGS %d\n",
1314 agg_bufs, (int)MAX_SKB_FRAGS);
1315 return NULL;
1316 }
1317
1318 if (len <= bp->rx_copy_thresh) {
Michael Chan6bb19472017-02-06 16:55:32 -05001319 skb = bnxt_copy_skb(bnapi, data_ptr, len, mapping);
Michael Chanc0c050c2015-10-22 16:01:17 -04001320 if (!skb) {
1321 bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs);
1322 return NULL;
1323 }
1324 } else {
1325 u8 *new_data;
1326 dma_addr_t new_mapping;
1327
1328 new_data = __bnxt_alloc_rx_data(bp, &new_mapping, GFP_ATOMIC);
1329 if (!new_data) {
1330 bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs);
1331 return NULL;
1332 }
1333
1334 tpa_info->data = new_data;
Michael Chanb3dba772017-02-06 16:55:35 -05001335 tpa_info->data_ptr = new_data + bp->rx_offset;
Michael Chanc0c050c2015-10-22 16:01:17 -04001336 tpa_info->mapping = new_mapping;
1337
1338 skb = build_skb(data, 0);
Shannon Nelsonc519fe92017-05-09 18:30:12 -07001339 dma_unmap_single_attrs(&bp->pdev->dev, mapping,
1340 bp->rx_buf_use_size, bp->rx_dir,
1341 DMA_ATTR_WEAK_ORDERING);
Michael Chanc0c050c2015-10-22 16:01:17 -04001342
1343 if (!skb) {
1344 kfree(data);
1345 bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs);
1346 return NULL;
1347 }
Michael Chanb3dba772017-02-06 16:55:35 -05001348 skb_reserve(skb, bp->rx_offset);
Michael Chanc0c050c2015-10-22 16:01:17 -04001349 skb_put(skb, len);
1350 }
1351
1352 if (agg_bufs) {
1353 skb = bnxt_rx_pages(bp, bnapi, skb, cp_cons, agg_bufs);
1354 if (!skb) {
1355 /* Page reuse already handled by bnxt_rx_pages(). */
1356 return NULL;
1357 }
1358 }
1359 skb->protocol = eth_type_trans(skb, bp->dev);
1360
1361 if (tpa_info->hash_type != PKT_HASH_TYPE_NONE)
1362 skb_set_hash(skb, tpa_info->rss_hash, tpa_info->hash_type);
1363
Michael Chan8852ddb2016-06-06 02:37:16 -04001364 if ((tpa_info->flags2 & RX_CMP_FLAGS2_META_FORMAT_VLAN) &&
1365 (skb->dev->features & NETIF_F_HW_VLAN_CTAG_RX)) {
Michael Chanc0c050c2015-10-22 16:01:17 -04001366 u16 vlan_proto = tpa_info->metadata >>
1367 RX_CMP_FLAGS2_METADATA_TPID_SFT;
Michael Chan8852ddb2016-06-06 02:37:16 -04001368 u16 vtag = tpa_info->metadata & RX_CMP_FLAGS2_METADATA_VID_MASK;
Michael Chanc0c050c2015-10-22 16:01:17 -04001369
Michael Chan8852ddb2016-06-06 02:37:16 -04001370 __vlan_hwaccel_put_tag(skb, htons(vlan_proto), vtag);
Michael Chanc0c050c2015-10-22 16:01:17 -04001371 }
1372
1373 skb_checksum_none_assert(skb);
1374 if (likely(tpa_info->flags2 & RX_TPA_START_CMP_FLAGS2_L4_CS_CALC)) {
1375 skb->ip_summed = CHECKSUM_UNNECESSARY;
1376 skb->csum_level =
1377 (tpa_info->flags2 & RX_CMP_FLAGS2_T_L4_CS_CALC) >> 3;
1378 }
1379
1380 if (TPA_END_GRO(tpa_end))
Michael Chan309369c2016-06-13 02:25:34 -04001381 skb = bnxt_gro_skb(bp, tpa_info, tpa_end, tpa_end1, skb);
Michael Chanc0c050c2015-10-22 16:01:17 -04001382
1383 return skb;
1384}
1385
1386/* returns the following:
1387 * 1 - 1 packet successfully received
1388 * 0 - successful TPA_START, packet not completed yet
1389 * -EBUSY - completion ring does not have all the agg buffers yet
1390 * -ENOMEM - packet aborted due to out of memory
1391 * -EIO - packet aborted due to hw error indicated in BD
1392 */
1393static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_napi *bnapi, u32 *raw_cons,
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001394 u8 *event)
Michael Chanc0c050c2015-10-22 16:01:17 -04001395{
1396 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
Michael Chanb6ab4b02016-01-02 23:44:59 -05001397 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
Michael Chanc0c050c2015-10-22 16:01:17 -04001398 struct net_device *dev = bp->dev;
1399 struct rx_cmp *rxcmp;
1400 struct rx_cmp_ext *rxcmp1;
1401 u32 tmp_raw_cons = *raw_cons;
1402 u16 cons, prod, cp_cons = RING_CMP(tmp_raw_cons);
1403 struct bnxt_sw_rx_bd *rx_buf;
1404 unsigned int len;
Michael Chan6bb19472017-02-06 16:55:32 -05001405 u8 *data_ptr, agg_bufs, cmp_type;
Michael Chanc0c050c2015-10-22 16:01:17 -04001406 dma_addr_t dma_addr;
1407 struct sk_buff *skb;
Michael Chan6bb19472017-02-06 16:55:32 -05001408 void *data;
Michael Chanc0c050c2015-10-22 16:01:17 -04001409 int rc = 0;
Michael Chanc61fb992017-02-06 16:55:36 -05001410 u32 misc;
Michael Chanc0c050c2015-10-22 16:01:17 -04001411
1412 rxcmp = (struct rx_cmp *)
1413 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
1414
1415 tmp_raw_cons = NEXT_RAW_CMP(tmp_raw_cons);
1416 cp_cons = RING_CMP(tmp_raw_cons);
1417 rxcmp1 = (struct rx_cmp_ext *)
1418 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
1419
1420 if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons))
1421 return -EBUSY;
1422
1423 cmp_type = RX_CMP_TYPE(rxcmp);
1424
1425 prod = rxr->rx_prod;
1426
1427 if (cmp_type == CMP_TYPE_RX_L2_TPA_START_CMP) {
1428 bnxt_tpa_start(bp, rxr, (struct rx_tpa_start_cmp *)rxcmp,
1429 (struct rx_tpa_start_cmp_ext *)rxcmp1);
1430
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001431 *event |= BNXT_RX_EVENT;
Michael Chanc0c050c2015-10-22 16:01:17 -04001432 goto next_rx_no_prod;
1433
1434 } else if (cmp_type == CMP_TYPE_RX_L2_TPA_END_CMP) {
1435 skb = bnxt_tpa_end(bp, bnapi, &tmp_raw_cons,
1436 (struct rx_tpa_end_cmp *)rxcmp,
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001437 (struct rx_tpa_end_cmp_ext *)rxcmp1, event);
Michael Chanc0c050c2015-10-22 16:01:17 -04001438
1439 if (unlikely(IS_ERR(skb)))
1440 return -EBUSY;
1441
1442 rc = -ENOMEM;
1443 if (likely(skb)) {
1444 skb_record_rx_queue(skb, bnapi->index);
Michael Chanb356a2e2016-12-29 12:13:31 -05001445 napi_gro_receive(&bnapi->napi, skb);
Michael Chanc0c050c2015-10-22 16:01:17 -04001446 rc = 1;
1447 }
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001448 *event |= BNXT_RX_EVENT;
Michael Chanc0c050c2015-10-22 16:01:17 -04001449 goto next_rx_no_prod;
1450 }
1451
1452 cons = rxcmp->rx_cmp_opaque;
1453 rx_buf = &rxr->rx_buf_ring[cons];
1454 data = rx_buf->data;
Michael Chan6bb19472017-02-06 16:55:32 -05001455 data_ptr = rx_buf->data_ptr;
Michael Chanfa7e2812016-05-10 19:18:00 -04001456 if (unlikely(cons != rxr->rx_next_cons)) {
1457 int rc1 = bnxt_discard_rx(bp, bnapi, raw_cons, rxcmp);
1458
1459 bnxt_sched_reset(bp, rxr);
1460 return rc1;
1461 }
Michael Chan6bb19472017-02-06 16:55:32 -05001462 prefetch(data_ptr);
Michael Chanc0c050c2015-10-22 16:01:17 -04001463
Michael Chanc61fb992017-02-06 16:55:36 -05001464 misc = le32_to_cpu(rxcmp->rx_cmp_misc_v1);
1465 agg_bufs = (misc & RX_CMP_AGG_BUFS) >> RX_CMP_AGG_BUFS_SHIFT;
Michael Chanc0c050c2015-10-22 16:01:17 -04001466
1467 if (agg_bufs) {
1468 if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, &tmp_raw_cons))
1469 return -EBUSY;
1470
1471 cp_cons = NEXT_CMP(cp_cons);
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001472 *event |= BNXT_AGG_EVENT;
Michael Chanc0c050c2015-10-22 16:01:17 -04001473 }
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001474 *event |= BNXT_RX_EVENT;
Michael Chanc0c050c2015-10-22 16:01:17 -04001475
1476 rx_buf->data = NULL;
1477 if (rxcmp1->rx_cmp_cfa_code_errors_v2 & RX_CMP_L2_ERRORS) {
1478 bnxt_reuse_rx_data(rxr, cons, data);
1479 if (agg_bufs)
1480 bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs);
1481
1482 rc = -EIO;
1483 goto next_rx;
1484 }
1485
1486 len = le32_to_cpu(rxcmp->rx_cmp_len_flags_type) >> RX_CMP_LEN_SHIFT;
Michael Chan11cd1192017-02-06 16:55:33 -05001487 dma_addr = rx_buf->mapping;
Michael Chanc0c050c2015-10-22 16:01:17 -04001488
Michael Chanc6d30e82017-02-06 16:55:42 -05001489 if (bnxt_rx_xdp(bp, rxr, cons, data, &data_ptr, &len, event)) {
1490 rc = 1;
1491 goto next_rx;
1492 }
1493
Michael Chanc0c050c2015-10-22 16:01:17 -04001494 if (len <= bp->rx_copy_thresh) {
Michael Chan6bb19472017-02-06 16:55:32 -05001495 skb = bnxt_copy_skb(bnapi, data_ptr, len, dma_addr);
Michael Chanc0c050c2015-10-22 16:01:17 -04001496 bnxt_reuse_rx_data(rxr, cons, data);
1497 if (!skb) {
1498 rc = -ENOMEM;
1499 goto next_rx;
1500 }
1501 } else {
Michael Chanc61fb992017-02-06 16:55:36 -05001502 u32 payload;
1503
Michael Chanc6d30e82017-02-06 16:55:42 -05001504 if (rx_buf->data_ptr == data_ptr)
1505 payload = misc & RX_CMP_PAYLOAD_OFFSET;
1506 else
1507 payload = 0;
Michael Chan6bb19472017-02-06 16:55:32 -05001508 skb = bp->rx_skb_func(bp, rxr, cons, data, data_ptr, dma_addr,
Michael Chanc61fb992017-02-06 16:55:36 -05001509 payload | len);
Michael Chanc0c050c2015-10-22 16:01:17 -04001510 if (!skb) {
1511 rc = -ENOMEM;
1512 goto next_rx;
1513 }
1514 }
1515
1516 if (agg_bufs) {
1517 skb = bnxt_rx_pages(bp, bnapi, skb, cp_cons, agg_bufs);
1518 if (!skb) {
1519 rc = -ENOMEM;
1520 goto next_rx;
1521 }
1522 }
1523
1524 if (RX_CMP_HASH_VALID(rxcmp)) {
1525 u32 hash_type = RX_CMP_HASH_TYPE(rxcmp);
1526 enum pkt_hash_types type = PKT_HASH_TYPE_L4;
1527
1528 /* RSS profiles 1 and 3 with extract code 0 for inner 4-tuple */
1529 if (hash_type != 1 && hash_type != 3)
1530 type = PKT_HASH_TYPE_L3;
1531 skb_set_hash(skb, le32_to_cpu(rxcmp->rx_cmp_rss_hash), type);
1532 }
1533
1534 skb->protocol = eth_type_trans(skb, dev);
1535
Michael Chan8852ddb2016-06-06 02:37:16 -04001536 if ((rxcmp1->rx_cmp_flags2 &
1537 cpu_to_le32(RX_CMP_FLAGS2_META_FORMAT_VLAN)) &&
1538 (skb->dev->features & NETIF_F_HW_VLAN_CTAG_RX)) {
Michael Chanc0c050c2015-10-22 16:01:17 -04001539 u32 meta_data = le32_to_cpu(rxcmp1->rx_cmp_meta_data);
Michael Chan8852ddb2016-06-06 02:37:16 -04001540 u16 vtag = meta_data & RX_CMP_FLAGS2_METADATA_VID_MASK;
Michael Chanc0c050c2015-10-22 16:01:17 -04001541 u16 vlan_proto = meta_data >> RX_CMP_FLAGS2_METADATA_TPID_SFT;
1542
Michael Chan8852ddb2016-06-06 02:37:16 -04001543 __vlan_hwaccel_put_tag(skb, htons(vlan_proto), vtag);
Michael Chanc0c050c2015-10-22 16:01:17 -04001544 }
1545
1546 skb_checksum_none_assert(skb);
1547 if (RX_CMP_L4_CS_OK(rxcmp1)) {
1548 if (dev->features & NETIF_F_RXCSUM) {
1549 skb->ip_summed = CHECKSUM_UNNECESSARY;
1550 skb->csum_level = RX_CMP_ENCAP(rxcmp1);
1551 }
1552 } else {
Satish Baddipadige665e3502015-12-27 18:19:21 -05001553 if (rxcmp1->rx_cmp_cfa_code_errors_v2 & RX_CMP_L4_CS_ERR_BITS) {
1554 if (dev->features & NETIF_F_RXCSUM)
1555 cpr->rx_l4_csum_errors++;
1556 }
Michael Chanc0c050c2015-10-22 16:01:17 -04001557 }
1558
1559 skb_record_rx_queue(skb, bnapi->index);
Michael Chanb356a2e2016-12-29 12:13:31 -05001560 napi_gro_receive(&bnapi->napi, skb);
Michael Chanc0c050c2015-10-22 16:01:17 -04001561 rc = 1;
1562
1563next_rx:
1564 rxr->rx_prod = NEXT_RX(prod);
Michael Chan376a5b82016-05-10 19:17:59 -04001565 rxr->rx_next_cons = NEXT_RX(cons);
Michael Chanc0c050c2015-10-22 16:01:17 -04001566
1567next_rx_no_prod:
1568 *raw_cons = tmp_raw_cons;
1569
1570 return rc;
1571}
1572
Michael Chan4bb13ab2016-04-05 14:09:01 -04001573#define BNXT_GET_EVENT_PORT(data) \
Michael Chan87c374d2016-12-02 21:17:16 -05001574 ((data) & \
1575 ASYNC_EVENT_CMPL_PORT_CONN_NOT_ALLOWED_EVENT_DATA1_PORT_ID_MASK)
Michael Chan4bb13ab2016-04-05 14:09:01 -04001576
Michael Chanc0c050c2015-10-22 16:01:17 -04001577static int bnxt_async_event_process(struct bnxt *bp,
1578 struct hwrm_async_event_cmpl *cmpl)
1579{
1580 u16 event_id = le16_to_cpu(cmpl->event_id);
1581
1582 /* TODO CHIMP_FW: Define event id's for link change, error etc */
1583 switch (event_id) {
Michael Chan87c374d2016-12-02 21:17:16 -05001584 case ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE: {
Michael Chan8cbde112016-04-11 04:11:14 -04001585 u32 data1 = le32_to_cpu(cmpl->event_data1);
1586 struct bnxt_link_info *link_info = &bp->link_info;
1587
1588 if (BNXT_VF(bp))
1589 goto async_event_process_exit;
1590 if (data1 & 0x20000) {
1591 u16 fw_speed = link_info->force_link_speed;
1592 u32 speed = bnxt_fw_to_ethtool_speed(fw_speed);
1593
1594 netdev_warn(bp->dev, "Link speed %d no longer supported\n",
1595 speed);
1596 }
Michael Chan286ef9d2016-11-16 21:13:08 -05001597 set_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT, &bp->sp_event);
Michael Chan8cbde112016-04-11 04:11:14 -04001598 /* fall thru */
1599 }
Michael Chan87c374d2016-12-02 21:17:16 -05001600 case ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE:
Michael Chanc0c050c2015-10-22 16:01:17 -04001601 set_bit(BNXT_LINK_CHNG_SP_EVENT, &bp->sp_event);
Jeffrey Huang19241362016-02-26 04:00:00 -05001602 break;
Michael Chan87c374d2016-12-02 21:17:16 -05001603 case ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD:
Jeffrey Huang19241362016-02-26 04:00:00 -05001604 set_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT, &bp->sp_event);
Michael Chanc0c050c2015-10-22 16:01:17 -04001605 break;
Michael Chan87c374d2016-12-02 21:17:16 -05001606 case ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED: {
Michael Chan4bb13ab2016-04-05 14:09:01 -04001607 u32 data1 = le32_to_cpu(cmpl->event_data1);
1608 u16 port_id = BNXT_GET_EVENT_PORT(data1);
1609
1610 if (BNXT_VF(bp))
1611 break;
1612
1613 if (bp->pf.port_id != port_id)
1614 break;
1615
Michael Chan4bb13ab2016-04-05 14:09:01 -04001616 set_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT, &bp->sp_event);
1617 break;
1618 }
Michael Chan87c374d2016-12-02 21:17:16 -05001619 case ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE:
Michael Chanfc0f1922016-06-13 02:25:30 -04001620 if (BNXT_PF(bp))
1621 goto async_event_process_exit;
1622 set_bit(BNXT_RESET_TASK_SILENT_SP_EVENT, &bp->sp_event);
1623 break;
Michael Chanc0c050c2015-10-22 16:01:17 -04001624 default:
Jeffrey Huang19241362016-02-26 04:00:00 -05001625 goto async_event_process_exit;
Michael Chanc0c050c2015-10-22 16:01:17 -04001626 }
Jeffrey Huang19241362016-02-26 04:00:00 -05001627 schedule_work(&bp->sp_task);
1628async_event_process_exit:
Michael Chana588e452016-12-07 00:26:21 -05001629 bnxt_ulp_async_events(bp, cmpl);
Michael Chanc0c050c2015-10-22 16:01:17 -04001630 return 0;
1631}
1632
1633static int bnxt_hwrm_handler(struct bnxt *bp, struct tx_cmp *txcmp)
1634{
1635 u16 cmpl_type = TX_CMP_TYPE(txcmp), vf_id, seq_id;
1636 struct hwrm_cmpl *h_cmpl = (struct hwrm_cmpl *)txcmp;
1637 struct hwrm_fwd_req_cmpl *fwd_req_cmpl =
1638 (struct hwrm_fwd_req_cmpl *)txcmp;
1639
1640 switch (cmpl_type) {
1641 case CMPL_BASE_TYPE_HWRM_DONE:
1642 seq_id = le16_to_cpu(h_cmpl->sequence_id);
1643 if (seq_id == bp->hwrm_intr_seq_id)
1644 bp->hwrm_intr_seq_id = HWRM_SEQ_ID_INVALID;
1645 else
1646 netdev_err(bp->dev, "Invalid hwrm seq id %d\n", seq_id);
1647 break;
1648
1649 case CMPL_BASE_TYPE_HWRM_FWD_REQ:
1650 vf_id = le16_to_cpu(fwd_req_cmpl->source_id);
1651
1652 if ((vf_id < bp->pf.first_vf_id) ||
1653 (vf_id >= bp->pf.first_vf_id + bp->pf.active_vfs)) {
1654 netdev_err(bp->dev, "Msg contains invalid VF id %x\n",
1655 vf_id);
1656 return -EINVAL;
1657 }
1658
1659 set_bit(vf_id - bp->pf.first_vf_id, bp->pf.vf_event_bmap);
1660 set_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT, &bp->sp_event);
1661 schedule_work(&bp->sp_task);
1662 break;
1663
1664 case CMPL_BASE_TYPE_HWRM_ASYNC_EVENT:
1665 bnxt_async_event_process(bp,
1666 (struct hwrm_async_event_cmpl *)txcmp);
1667
1668 default:
1669 break;
1670 }
1671
1672 return 0;
1673}
1674
1675static irqreturn_t bnxt_msix(int irq, void *dev_instance)
1676{
1677 struct bnxt_napi *bnapi = dev_instance;
1678 struct bnxt *bp = bnapi->bp;
1679 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1680 u32 cons = RING_CMP(cpr->cp_raw_cons);
1681
1682 prefetch(&cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]);
1683 napi_schedule(&bnapi->napi);
1684 return IRQ_HANDLED;
1685}
1686
1687static inline int bnxt_has_work(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
1688{
1689 u32 raw_cons = cpr->cp_raw_cons;
1690 u16 cons = RING_CMP(raw_cons);
1691 struct tx_cmp *txcmp;
1692
1693 txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)];
1694
1695 return TX_CMP_VALID(txcmp, raw_cons);
1696}
1697
Michael Chanc0c050c2015-10-22 16:01:17 -04001698static irqreturn_t bnxt_inta(int irq, void *dev_instance)
1699{
1700 struct bnxt_napi *bnapi = dev_instance;
1701 struct bnxt *bp = bnapi->bp;
1702 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1703 u32 cons = RING_CMP(cpr->cp_raw_cons);
1704 u32 int_status;
1705
1706 prefetch(&cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]);
1707
1708 if (!bnxt_has_work(bp, cpr)) {
Jeffrey Huang11809492015-11-05 16:25:49 -05001709 int_status = readl(bp->bar0 + BNXT_CAG_REG_LEGACY_INT_STATUS);
Michael Chanc0c050c2015-10-22 16:01:17 -04001710 /* return if erroneous interrupt */
1711 if (!(int_status & (0x10000 << cpr->cp_ring_struct.fw_ring_id)))
1712 return IRQ_NONE;
1713 }
1714
1715 /* disable ring IRQ */
1716 BNXT_CP_DB_IRQ_DIS(cpr->cp_doorbell);
1717
1718 /* Return here if interrupt is shared and is disabled. */
1719 if (unlikely(atomic_read(&bp->intr_sem) != 0))
1720 return IRQ_HANDLED;
1721
1722 napi_schedule(&bnapi->napi);
1723 return IRQ_HANDLED;
1724}
1725
1726static int bnxt_poll_work(struct bnxt *bp, struct bnxt_napi *bnapi, int budget)
1727{
1728 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1729 u32 raw_cons = cpr->cp_raw_cons;
1730 u32 cons;
1731 int tx_pkts = 0;
1732 int rx_pkts = 0;
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001733 u8 event = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04001734 struct tx_cmp *txcmp;
1735
1736 while (1) {
1737 int rc;
1738
1739 cons = RING_CMP(raw_cons);
1740 txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)];
1741
1742 if (!TX_CMP_VALID(txcmp, raw_cons))
1743 break;
1744
Michael Chan67a95e22016-05-04 16:56:43 -04001745 /* The valid test of the entry must be done first before
1746 * reading any further.
1747 */
Michael Chanb67daab2016-05-15 03:04:51 -04001748 dma_rmb();
Michael Chanc0c050c2015-10-22 16:01:17 -04001749 if (TX_CMP_TYPE(txcmp) == CMP_TYPE_TX_L2_CMP) {
1750 tx_pkts++;
1751 /* return full budget so NAPI will complete. */
1752 if (unlikely(tx_pkts > bp->tx_wake_thresh))
1753 rx_pkts = budget;
1754 } else if ((TX_CMP_TYPE(txcmp) & 0x30) == 0x10) {
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001755 rc = bnxt_rx_pkt(bp, bnapi, &raw_cons, &event);
Michael Chanc0c050c2015-10-22 16:01:17 -04001756 if (likely(rc >= 0))
1757 rx_pkts += rc;
1758 else if (rc == -EBUSY) /* partial completion */
1759 break;
Michael Chanc0c050c2015-10-22 16:01:17 -04001760 } else if (unlikely((TX_CMP_TYPE(txcmp) ==
1761 CMPL_BASE_TYPE_HWRM_DONE) ||
1762 (TX_CMP_TYPE(txcmp) ==
1763 CMPL_BASE_TYPE_HWRM_FWD_REQ) ||
1764 (TX_CMP_TYPE(txcmp) ==
1765 CMPL_BASE_TYPE_HWRM_ASYNC_EVENT))) {
1766 bnxt_hwrm_handler(bp, txcmp);
1767 }
1768 raw_cons = NEXT_RAW_CMP(raw_cons);
1769
1770 if (rx_pkts == budget)
1771 break;
1772 }
1773
Michael Chan38413402017-02-06 16:55:43 -05001774 if (event & BNXT_TX_EVENT) {
1775 struct bnxt_tx_ring_info *txr = bnapi->tx_ring;
1776 void __iomem *db = txr->tx_doorbell;
1777 u16 prod = txr->tx_prod;
1778
1779 /* Sync BD data before updating doorbell */
1780 wmb();
1781
1782 writel(DB_KEY_TX | prod, db);
1783 writel(DB_KEY_TX | prod, db);
1784 }
1785
Michael Chanc0c050c2015-10-22 16:01:17 -04001786 cpr->cp_raw_cons = raw_cons;
1787 /* ACK completion ring before freeing tx ring and producing new
1788 * buffers in rx/agg rings to prevent overflowing the completion
1789 * ring.
1790 */
1791 BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
1792
1793 if (tx_pkts)
Michael Chanfa3e93e2017-02-06 16:55:41 -05001794 bnapi->tx_int(bp, bnapi, tx_pkts);
Michael Chanc0c050c2015-10-22 16:01:17 -04001795
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001796 if (event & BNXT_RX_EVENT) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05001797 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
Michael Chanc0c050c2015-10-22 16:01:17 -04001798
1799 writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell);
1800 writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell);
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001801 if (event & BNXT_AGG_EVENT) {
Michael Chanc0c050c2015-10-22 16:01:17 -04001802 writel(DB_KEY_RX | rxr->rx_agg_prod,
1803 rxr->rx_agg_doorbell);
1804 writel(DB_KEY_RX | rxr->rx_agg_prod,
1805 rxr->rx_agg_doorbell);
1806 }
1807 }
1808 return rx_pkts;
1809}
1810
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04001811static int bnxt_poll_nitroa0(struct napi_struct *napi, int budget)
1812{
1813 struct bnxt_napi *bnapi = container_of(napi, struct bnxt_napi, napi);
1814 struct bnxt *bp = bnapi->bp;
1815 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1816 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
1817 struct tx_cmp *txcmp;
1818 struct rx_cmp_ext *rxcmp1;
1819 u32 cp_cons, tmp_raw_cons;
1820 u32 raw_cons = cpr->cp_raw_cons;
1821 u32 rx_pkts = 0;
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001822 u8 event = 0;
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04001823
1824 while (1) {
1825 int rc;
1826
1827 cp_cons = RING_CMP(raw_cons);
1828 txcmp = &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
1829
1830 if (!TX_CMP_VALID(txcmp, raw_cons))
1831 break;
1832
1833 if ((TX_CMP_TYPE(txcmp) & 0x30) == 0x10) {
1834 tmp_raw_cons = NEXT_RAW_CMP(raw_cons);
1835 cp_cons = RING_CMP(tmp_raw_cons);
1836 rxcmp1 = (struct rx_cmp_ext *)
1837 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
1838
1839 if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons))
1840 break;
1841
1842 /* force an error to recycle the buffer */
1843 rxcmp1->rx_cmp_cfa_code_errors_v2 |=
1844 cpu_to_le32(RX_CMPL_ERRORS_CRC_ERROR);
1845
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001846 rc = bnxt_rx_pkt(bp, bnapi, &raw_cons, &event);
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04001847 if (likely(rc == -EIO))
1848 rx_pkts++;
1849 else if (rc == -EBUSY) /* partial completion */
1850 break;
1851 } else if (unlikely(TX_CMP_TYPE(txcmp) ==
1852 CMPL_BASE_TYPE_HWRM_DONE)) {
1853 bnxt_hwrm_handler(bp, txcmp);
1854 } else {
1855 netdev_err(bp->dev,
1856 "Invalid completion received on special ring\n");
1857 }
1858 raw_cons = NEXT_RAW_CMP(raw_cons);
1859
1860 if (rx_pkts == budget)
1861 break;
1862 }
1863
1864 cpr->cp_raw_cons = raw_cons;
1865 BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
1866 writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell);
1867 writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell);
1868
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001869 if (event & BNXT_AGG_EVENT) {
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04001870 writel(DB_KEY_RX | rxr->rx_agg_prod, rxr->rx_agg_doorbell);
1871 writel(DB_KEY_RX | rxr->rx_agg_prod, rxr->rx_agg_doorbell);
1872 }
1873
1874 if (!bnxt_has_work(bp, cpr) && rx_pkts < budget) {
Eric Dumazet6ad20162017-01-30 08:22:01 -08001875 napi_complete_done(napi, rx_pkts);
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04001876 BNXT_CP_DB_REARM(cpr->cp_doorbell, cpr->cp_raw_cons);
1877 }
1878 return rx_pkts;
1879}
1880
Michael Chanc0c050c2015-10-22 16:01:17 -04001881static int bnxt_poll(struct napi_struct *napi, int budget)
1882{
1883 struct bnxt_napi *bnapi = container_of(napi, struct bnxt_napi, napi);
1884 struct bnxt *bp = bnapi->bp;
1885 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1886 int work_done = 0;
1887
Michael Chanc0c050c2015-10-22 16:01:17 -04001888 while (1) {
1889 work_done += bnxt_poll_work(bp, bnapi, budget - work_done);
1890
1891 if (work_done >= budget)
1892 break;
1893
1894 if (!bnxt_has_work(bp, cpr)) {
Michael Chane7b95692016-12-29 12:13:32 -05001895 if (napi_complete_done(napi, work_done))
1896 BNXT_CP_DB_REARM(cpr->cp_doorbell,
1897 cpr->cp_raw_cons);
Michael Chanc0c050c2015-10-22 16:01:17 -04001898 break;
1899 }
1900 }
1901 mmiowb();
Michael Chanc0c050c2015-10-22 16:01:17 -04001902 return work_done;
1903}
1904
Michael Chanc0c050c2015-10-22 16:01:17 -04001905static void bnxt_free_tx_skbs(struct bnxt *bp)
1906{
1907 int i, max_idx;
1908 struct pci_dev *pdev = bp->pdev;
1909
Michael Chanb6ab4b02016-01-02 23:44:59 -05001910 if (!bp->tx_ring)
Michael Chanc0c050c2015-10-22 16:01:17 -04001911 return;
1912
1913 max_idx = bp->tx_nr_pages * TX_DESC_CNT;
1914 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05001915 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04001916 int j;
1917
Michael Chanc0c050c2015-10-22 16:01:17 -04001918 for (j = 0; j < max_idx;) {
1919 struct bnxt_sw_tx_bd *tx_buf = &txr->tx_buf_ring[j];
1920 struct sk_buff *skb = tx_buf->skb;
1921 int k, last;
1922
1923 if (!skb) {
1924 j++;
1925 continue;
1926 }
1927
1928 tx_buf->skb = NULL;
1929
1930 if (tx_buf->is_push) {
1931 dev_kfree_skb(skb);
1932 j += 2;
1933 continue;
1934 }
1935
1936 dma_unmap_single(&pdev->dev,
1937 dma_unmap_addr(tx_buf, mapping),
1938 skb_headlen(skb),
1939 PCI_DMA_TODEVICE);
1940
1941 last = tx_buf->nr_frags;
1942 j += 2;
Michael Chand612a572016-01-28 03:11:22 -05001943 for (k = 0; k < last; k++, j++) {
1944 int ring_idx = j & bp->tx_ring_mask;
Michael Chanc0c050c2015-10-22 16:01:17 -04001945 skb_frag_t *frag = &skb_shinfo(skb)->frags[k];
1946
Michael Chand612a572016-01-28 03:11:22 -05001947 tx_buf = &txr->tx_buf_ring[ring_idx];
Michael Chanc0c050c2015-10-22 16:01:17 -04001948 dma_unmap_page(
1949 &pdev->dev,
1950 dma_unmap_addr(tx_buf, mapping),
1951 skb_frag_size(frag), PCI_DMA_TODEVICE);
1952 }
1953 dev_kfree_skb(skb);
1954 }
1955 netdev_tx_reset_queue(netdev_get_tx_queue(bp->dev, i));
1956 }
1957}
1958
1959static void bnxt_free_rx_skbs(struct bnxt *bp)
1960{
1961 int i, max_idx, max_agg_idx;
1962 struct pci_dev *pdev = bp->pdev;
1963
Michael Chanb6ab4b02016-01-02 23:44:59 -05001964 if (!bp->rx_ring)
Michael Chanc0c050c2015-10-22 16:01:17 -04001965 return;
1966
1967 max_idx = bp->rx_nr_pages * RX_DESC_CNT;
1968 max_agg_idx = bp->rx_agg_nr_pages * RX_DESC_CNT;
1969 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05001970 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04001971 int j;
1972
Michael Chanc0c050c2015-10-22 16:01:17 -04001973 if (rxr->rx_tpa) {
1974 for (j = 0; j < MAX_TPA; j++) {
1975 struct bnxt_tpa_info *tpa_info =
1976 &rxr->rx_tpa[j];
1977 u8 *data = tpa_info->data;
1978
1979 if (!data)
1980 continue;
1981
Shannon Nelsonc519fe92017-05-09 18:30:12 -07001982 dma_unmap_single_attrs(&pdev->dev,
1983 tpa_info->mapping,
1984 bp->rx_buf_use_size,
1985 bp->rx_dir,
1986 DMA_ATTR_WEAK_ORDERING);
Michael Chanc0c050c2015-10-22 16:01:17 -04001987
1988 tpa_info->data = NULL;
1989
1990 kfree(data);
1991 }
1992 }
1993
1994 for (j = 0; j < max_idx; j++) {
1995 struct bnxt_sw_rx_bd *rx_buf = &rxr->rx_buf_ring[j];
Michael Chan3ed3a832017-03-28 19:47:31 -04001996 dma_addr_t mapping = rx_buf->mapping;
Michael Chan6bb19472017-02-06 16:55:32 -05001997 void *data = rx_buf->data;
Michael Chanc0c050c2015-10-22 16:01:17 -04001998
1999 if (!data)
2000 continue;
2001
Michael Chanc0c050c2015-10-22 16:01:17 -04002002 rx_buf->data = NULL;
2003
Michael Chan3ed3a832017-03-28 19:47:31 -04002004 if (BNXT_RX_PAGE_MODE(bp)) {
2005 mapping -= bp->rx_dma_offset;
Shannon Nelsonc519fe92017-05-09 18:30:12 -07002006 dma_unmap_page_attrs(&pdev->dev, mapping,
2007 PAGE_SIZE, bp->rx_dir,
2008 DMA_ATTR_WEAK_ORDERING);
Michael Chanc61fb992017-02-06 16:55:36 -05002009 __free_page(data);
Michael Chan3ed3a832017-03-28 19:47:31 -04002010 } else {
Shannon Nelsonc519fe92017-05-09 18:30:12 -07002011 dma_unmap_single_attrs(&pdev->dev, mapping,
2012 bp->rx_buf_use_size,
2013 bp->rx_dir,
2014 DMA_ATTR_WEAK_ORDERING);
Michael Chanc61fb992017-02-06 16:55:36 -05002015 kfree(data);
Michael Chan3ed3a832017-03-28 19:47:31 -04002016 }
Michael Chanc0c050c2015-10-22 16:01:17 -04002017 }
2018
2019 for (j = 0; j < max_agg_idx; j++) {
2020 struct bnxt_sw_rx_agg_bd *rx_agg_buf =
2021 &rxr->rx_agg_ring[j];
2022 struct page *page = rx_agg_buf->page;
2023
2024 if (!page)
2025 continue;
2026
Shannon Nelsonc519fe92017-05-09 18:30:12 -07002027 dma_unmap_page_attrs(&pdev->dev, rx_agg_buf->mapping,
2028 BNXT_RX_PAGE_SIZE,
2029 PCI_DMA_FROMDEVICE,
2030 DMA_ATTR_WEAK_ORDERING);
Michael Chanc0c050c2015-10-22 16:01:17 -04002031
2032 rx_agg_buf->page = NULL;
2033 __clear_bit(j, rxr->rx_agg_bmap);
2034
2035 __free_page(page);
2036 }
Michael Chan89d0a062016-04-25 02:30:51 -04002037 if (rxr->rx_page) {
2038 __free_page(rxr->rx_page);
2039 rxr->rx_page = NULL;
2040 }
Michael Chanc0c050c2015-10-22 16:01:17 -04002041 }
2042}
2043
2044static void bnxt_free_skbs(struct bnxt *bp)
2045{
2046 bnxt_free_tx_skbs(bp);
2047 bnxt_free_rx_skbs(bp);
2048}
2049
2050static void bnxt_free_ring(struct bnxt *bp, struct bnxt_ring_struct *ring)
2051{
2052 struct pci_dev *pdev = bp->pdev;
2053 int i;
2054
2055 for (i = 0; i < ring->nr_pages; i++) {
2056 if (!ring->pg_arr[i])
2057 continue;
2058
2059 dma_free_coherent(&pdev->dev, ring->page_size,
2060 ring->pg_arr[i], ring->dma_arr[i]);
2061
2062 ring->pg_arr[i] = NULL;
2063 }
2064 if (ring->pg_tbl) {
2065 dma_free_coherent(&pdev->dev, ring->nr_pages * 8,
2066 ring->pg_tbl, ring->pg_tbl_map);
2067 ring->pg_tbl = NULL;
2068 }
2069 if (ring->vmem_size && *ring->vmem) {
2070 vfree(*ring->vmem);
2071 *ring->vmem = NULL;
2072 }
2073}
2074
2075static int bnxt_alloc_ring(struct bnxt *bp, struct bnxt_ring_struct *ring)
2076{
2077 int i;
2078 struct pci_dev *pdev = bp->pdev;
2079
2080 if (ring->nr_pages > 1) {
2081 ring->pg_tbl = dma_alloc_coherent(&pdev->dev,
2082 ring->nr_pages * 8,
2083 &ring->pg_tbl_map,
2084 GFP_KERNEL);
2085 if (!ring->pg_tbl)
2086 return -ENOMEM;
2087 }
2088
2089 for (i = 0; i < ring->nr_pages; i++) {
2090 ring->pg_arr[i] = dma_alloc_coherent(&pdev->dev,
2091 ring->page_size,
2092 &ring->dma_arr[i],
2093 GFP_KERNEL);
2094 if (!ring->pg_arr[i])
2095 return -ENOMEM;
2096
2097 if (ring->nr_pages > 1)
2098 ring->pg_tbl[i] = cpu_to_le64(ring->dma_arr[i]);
2099 }
2100
2101 if (ring->vmem_size) {
2102 *ring->vmem = vzalloc(ring->vmem_size);
2103 if (!(*ring->vmem))
2104 return -ENOMEM;
2105 }
2106 return 0;
2107}
2108
2109static void bnxt_free_rx_rings(struct bnxt *bp)
2110{
2111 int i;
2112
Michael Chanb6ab4b02016-01-02 23:44:59 -05002113 if (!bp->rx_ring)
Michael Chanc0c050c2015-10-22 16:01:17 -04002114 return;
2115
2116 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05002117 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04002118 struct bnxt_ring_struct *ring;
2119
Michael Chanc6d30e82017-02-06 16:55:42 -05002120 if (rxr->xdp_prog)
2121 bpf_prog_put(rxr->xdp_prog);
2122
Michael Chanc0c050c2015-10-22 16:01:17 -04002123 kfree(rxr->rx_tpa);
2124 rxr->rx_tpa = NULL;
2125
2126 kfree(rxr->rx_agg_bmap);
2127 rxr->rx_agg_bmap = NULL;
2128
2129 ring = &rxr->rx_ring_struct;
2130 bnxt_free_ring(bp, ring);
2131
2132 ring = &rxr->rx_agg_ring_struct;
2133 bnxt_free_ring(bp, ring);
2134 }
2135}
2136
2137static int bnxt_alloc_rx_rings(struct bnxt *bp)
2138{
2139 int i, rc, agg_rings = 0, tpa_rings = 0;
2140
Michael Chanb6ab4b02016-01-02 23:44:59 -05002141 if (!bp->rx_ring)
2142 return -ENOMEM;
2143
Michael Chanc0c050c2015-10-22 16:01:17 -04002144 if (bp->flags & BNXT_FLAG_AGG_RINGS)
2145 agg_rings = 1;
2146
2147 if (bp->flags & BNXT_FLAG_TPA)
2148 tpa_rings = 1;
2149
2150 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05002151 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04002152 struct bnxt_ring_struct *ring;
2153
Michael Chanc0c050c2015-10-22 16:01:17 -04002154 ring = &rxr->rx_ring_struct;
2155
2156 rc = bnxt_alloc_ring(bp, ring);
2157 if (rc)
2158 return rc;
2159
2160 if (agg_rings) {
2161 u16 mem_size;
2162
2163 ring = &rxr->rx_agg_ring_struct;
2164 rc = bnxt_alloc_ring(bp, ring);
2165 if (rc)
2166 return rc;
2167
2168 rxr->rx_agg_bmap_size = bp->rx_agg_ring_mask + 1;
2169 mem_size = rxr->rx_agg_bmap_size / 8;
2170 rxr->rx_agg_bmap = kzalloc(mem_size, GFP_KERNEL);
2171 if (!rxr->rx_agg_bmap)
2172 return -ENOMEM;
2173
2174 if (tpa_rings) {
2175 rxr->rx_tpa = kcalloc(MAX_TPA,
2176 sizeof(struct bnxt_tpa_info),
2177 GFP_KERNEL);
2178 if (!rxr->rx_tpa)
2179 return -ENOMEM;
2180 }
2181 }
2182 }
2183 return 0;
2184}
2185
2186static void bnxt_free_tx_rings(struct bnxt *bp)
2187{
2188 int i;
2189 struct pci_dev *pdev = bp->pdev;
2190
Michael Chanb6ab4b02016-01-02 23:44:59 -05002191 if (!bp->tx_ring)
Michael Chanc0c050c2015-10-22 16:01:17 -04002192 return;
2193
2194 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05002195 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04002196 struct bnxt_ring_struct *ring;
2197
Michael Chanc0c050c2015-10-22 16:01:17 -04002198 if (txr->tx_push) {
2199 dma_free_coherent(&pdev->dev, bp->tx_push_size,
2200 txr->tx_push, txr->tx_push_mapping);
2201 txr->tx_push = NULL;
2202 }
2203
2204 ring = &txr->tx_ring_struct;
2205
2206 bnxt_free_ring(bp, ring);
2207 }
2208}
2209
2210static int bnxt_alloc_tx_rings(struct bnxt *bp)
2211{
2212 int i, j, rc;
2213 struct pci_dev *pdev = bp->pdev;
2214
2215 bp->tx_push_size = 0;
2216 if (bp->tx_push_thresh) {
2217 int push_size;
2218
2219 push_size = L1_CACHE_ALIGN(sizeof(struct tx_push_bd) +
2220 bp->tx_push_thresh);
2221
Michael Chan4419dbe2016-02-10 17:33:49 -05002222 if (push_size > 256) {
Michael Chanc0c050c2015-10-22 16:01:17 -04002223 push_size = 0;
2224 bp->tx_push_thresh = 0;
2225 }
2226
2227 bp->tx_push_size = push_size;
2228 }
2229
2230 for (i = 0, j = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05002231 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04002232 struct bnxt_ring_struct *ring;
2233
Michael Chanc0c050c2015-10-22 16:01:17 -04002234 ring = &txr->tx_ring_struct;
2235
2236 rc = bnxt_alloc_ring(bp, ring);
2237 if (rc)
2238 return rc;
2239
2240 if (bp->tx_push_size) {
Michael Chanc0c050c2015-10-22 16:01:17 -04002241 dma_addr_t mapping;
2242
2243 /* One pre-allocated DMA buffer to backup
2244 * TX push operation
2245 */
2246 txr->tx_push = dma_alloc_coherent(&pdev->dev,
2247 bp->tx_push_size,
2248 &txr->tx_push_mapping,
2249 GFP_KERNEL);
2250
2251 if (!txr->tx_push)
2252 return -ENOMEM;
2253
Michael Chanc0c050c2015-10-22 16:01:17 -04002254 mapping = txr->tx_push_mapping +
2255 sizeof(struct tx_push_bd);
Michael Chan4419dbe2016-02-10 17:33:49 -05002256 txr->data_mapping = cpu_to_le64(mapping);
Michael Chanc0c050c2015-10-22 16:01:17 -04002257
Michael Chan4419dbe2016-02-10 17:33:49 -05002258 memset(txr->tx_push, 0, sizeof(struct tx_push_bd));
Michael Chanc0c050c2015-10-22 16:01:17 -04002259 }
2260 ring->queue_id = bp->q_info[j].queue_id;
Michael Chan5f449242017-02-06 16:55:40 -05002261 if (i < bp->tx_nr_rings_xdp)
2262 continue;
Michael Chanc0c050c2015-10-22 16:01:17 -04002263 if (i % bp->tx_nr_rings_per_tc == (bp->tx_nr_rings_per_tc - 1))
2264 j++;
2265 }
2266 return 0;
2267}
2268
2269static void bnxt_free_cp_rings(struct bnxt *bp)
2270{
2271 int i;
2272
2273 if (!bp->bnapi)
2274 return;
2275
2276 for (i = 0; i < bp->cp_nr_rings; i++) {
2277 struct bnxt_napi *bnapi = bp->bnapi[i];
2278 struct bnxt_cp_ring_info *cpr;
2279 struct bnxt_ring_struct *ring;
2280
2281 if (!bnapi)
2282 continue;
2283
2284 cpr = &bnapi->cp_ring;
2285 ring = &cpr->cp_ring_struct;
2286
2287 bnxt_free_ring(bp, ring);
2288 }
2289}
2290
2291static int bnxt_alloc_cp_rings(struct bnxt *bp)
2292{
2293 int i, rc;
2294
2295 for (i = 0; i < bp->cp_nr_rings; i++) {
2296 struct bnxt_napi *bnapi = bp->bnapi[i];
2297 struct bnxt_cp_ring_info *cpr;
2298 struct bnxt_ring_struct *ring;
2299
2300 if (!bnapi)
2301 continue;
2302
2303 cpr = &bnapi->cp_ring;
2304 ring = &cpr->cp_ring_struct;
2305
2306 rc = bnxt_alloc_ring(bp, ring);
2307 if (rc)
2308 return rc;
2309 }
2310 return 0;
2311}
2312
2313static void bnxt_init_ring_struct(struct bnxt *bp)
2314{
2315 int i;
2316
2317 for (i = 0; i < bp->cp_nr_rings; i++) {
2318 struct bnxt_napi *bnapi = bp->bnapi[i];
2319 struct bnxt_cp_ring_info *cpr;
2320 struct bnxt_rx_ring_info *rxr;
2321 struct bnxt_tx_ring_info *txr;
2322 struct bnxt_ring_struct *ring;
2323
2324 if (!bnapi)
2325 continue;
2326
2327 cpr = &bnapi->cp_ring;
2328 ring = &cpr->cp_ring_struct;
2329 ring->nr_pages = bp->cp_nr_pages;
2330 ring->page_size = HW_CMPD_RING_SIZE;
2331 ring->pg_arr = (void **)cpr->cp_desc_ring;
2332 ring->dma_arr = cpr->cp_desc_mapping;
2333 ring->vmem_size = 0;
2334
Michael Chanb6ab4b02016-01-02 23:44:59 -05002335 rxr = bnapi->rx_ring;
Michael Chan3b2b7d92016-01-02 23:45:00 -05002336 if (!rxr)
2337 goto skip_rx;
2338
Michael Chanc0c050c2015-10-22 16:01:17 -04002339 ring = &rxr->rx_ring_struct;
2340 ring->nr_pages = bp->rx_nr_pages;
2341 ring->page_size = HW_RXBD_RING_SIZE;
2342 ring->pg_arr = (void **)rxr->rx_desc_ring;
2343 ring->dma_arr = rxr->rx_desc_mapping;
2344 ring->vmem_size = SW_RXBD_RING_SIZE * bp->rx_nr_pages;
2345 ring->vmem = (void **)&rxr->rx_buf_ring;
2346
2347 ring = &rxr->rx_agg_ring_struct;
2348 ring->nr_pages = bp->rx_agg_nr_pages;
2349 ring->page_size = HW_RXBD_RING_SIZE;
2350 ring->pg_arr = (void **)rxr->rx_agg_desc_ring;
2351 ring->dma_arr = rxr->rx_agg_desc_mapping;
2352 ring->vmem_size = SW_RXBD_AGG_RING_SIZE * bp->rx_agg_nr_pages;
2353 ring->vmem = (void **)&rxr->rx_agg_ring;
2354
Michael Chan3b2b7d92016-01-02 23:45:00 -05002355skip_rx:
Michael Chanb6ab4b02016-01-02 23:44:59 -05002356 txr = bnapi->tx_ring;
Michael Chan3b2b7d92016-01-02 23:45:00 -05002357 if (!txr)
2358 continue;
2359
Michael Chanc0c050c2015-10-22 16:01:17 -04002360 ring = &txr->tx_ring_struct;
2361 ring->nr_pages = bp->tx_nr_pages;
2362 ring->page_size = HW_RXBD_RING_SIZE;
2363 ring->pg_arr = (void **)txr->tx_desc_ring;
2364 ring->dma_arr = txr->tx_desc_mapping;
2365 ring->vmem_size = SW_TXBD_RING_SIZE * bp->tx_nr_pages;
2366 ring->vmem = (void **)&txr->tx_buf_ring;
2367 }
2368}
2369
2370static void bnxt_init_rxbd_pages(struct bnxt_ring_struct *ring, u32 type)
2371{
2372 int i;
2373 u32 prod;
2374 struct rx_bd **rx_buf_ring;
2375
2376 rx_buf_ring = (struct rx_bd **)ring->pg_arr;
2377 for (i = 0, prod = 0; i < ring->nr_pages; i++) {
2378 int j;
2379 struct rx_bd *rxbd;
2380
2381 rxbd = rx_buf_ring[i];
2382 if (!rxbd)
2383 continue;
2384
2385 for (j = 0; j < RX_DESC_CNT; j++, rxbd++, prod++) {
2386 rxbd->rx_bd_len_flags_type = cpu_to_le32(type);
2387 rxbd->rx_bd_opaque = prod;
2388 }
2389 }
2390}
2391
2392static int bnxt_init_one_rx_ring(struct bnxt *bp, int ring_nr)
2393{
2394 struct net_device *dev = bp->dev;
Michael Chanc0c050c2015-10-22 16:01:17 -04002395 struct bnxt_rx_ring_info *rxr;
2396 struct bnxt_ring_struct *ring;
2397 u32 prod, type;
2398 int i;
2399
Michael Chanc0c050c2015-10-22 16:01:17 -04002400 type = (bp->rx_buf_use_size << RX_BD_LEN_SHIFT) |
2401 RX_BD_TYPE_RX_PACKET_BD | RX_BD_FLAGS_EOP;
2402
2403 if (NET_IP_ALIGN == 2)
2404 type |= RX_BD_FLAGS_SOP;
2405
Michael Chanb6ab4b02016-01-02 23:44:59 -05002406 rxr = &bp->rx_ring[ring_nr];
Michael Chanc0c050c2015-10-22 16:01:17 -04002407 ring = &rxr->rx_ring_struct;
2408 bnxt_init_rxbd_pages(ring, type);
2409
Michael Chanc6d30e82017-02-06 16:55:42 -05002410 if (BNXT_RX_PAGE_MODE(bp) && bp->xdp_prog) {
2411 rxr->xdp_prog = bpf_prog_add(bp->xdp_prog, 1);
2412 if (IS_ERR(rxr->xdp_prog)) {
2413 int rc = PTR_ERR(rxr->xdp_prog);
2414
2415 rxr->xdp_prog = NULL;
2416 return rc;
2417 }
2418 }
Michael Chanc0c050c2015-10-22 16:01:17 -04002419 prod = rxr->rx_prod;
2420 for (i = 0; i < bp->rx_ring_size; i++) {
2421 if (bnxt_alloc_rx_data(bp, rxr, prod, GFP_KERNEL) != 0) {
2422 netdev_warn(dev, "init'ed rx ring %d with %d/%d skbs only\n",
2423 ring_nr, i, bp->rx_ring_size);
2424 break;
2425 }
2426 prod = NEXT_RX(prod);
2427 }
2428 rxr->rx_prod = prod;
2429 ring->fw_ring_id = INVALID_HW_RING_ID;
2430
Michael Chanedd0c2c2015-12-27 18:19:19 -05002431 ring = &rxr->rx_agg_ring_struct;
2432 ring->fw_ring_id = INVALID_HW_RING_ID;
2433
Michael Chanc0c050c2015-10-22 16:01:17 -04002434 if (!(bp->flags & BNXT_FLAG_AGG_RINGS))
2435 return 0;
2436
Michael Chan2839f282016-04-25 02:30:50 -04002437 type = ((u32)BNXT_RX_PAGE_SIZE << RX_BD_LEN_SHIFT) |
Michael Chanc0c050c2015-10-22 16:01:17 -04002438 RX_BD_TYPE_RX_AGG_BD | RX_BD_FLAGS_SOP;
2439
2440 bnxt_init_rxbd_pages(ring, type);
2441
2442 prod = rxr->rx_agg_prod;
2443 for (i = 0; i < bp->rx_agg_ring_size; i++) {
2444 if (bnxt_alloc_rx_page(bp, rxr, prod, GFP_KERNEL) != 0) {
2445 netdev_warn(dev, "init'ed rx ring %d with %d/%d pages only\n",
2446 ring_nr, i, bp->rx_ring_size);
2447 break;
2448 }
2449 prod = NEXT_RX_AGG(prod);
2450 }
2451 rxr->rx_agg_prod = prod;
Michael Chanc0c050c2015-10-22 16:01:17 -04002452
2453 if (bp->flags & BNXT_FLAG_TPA) {
2454 if (rxr->rx_tpa) {
2455 u8 *data;
2456 dma_addr_t mapping;
2457
2458 for (i = 0; i < MAX_TPA; i++) {
2459 data = __bnxt_alloc_rx_data(bp, &mapping,
2460 GFP_KERNEL);
2461 if (!data)
2462 return -ENOMEM;
2463
2464 rxr->rx_tpa[i].data = data;
Michael Chanb3dba772017-02-06 16:55:35 -05002465 rxr->rx_tpa[i].data_ptr = data + bp->rx_offset;
Michael Chanc0c050c2015-10-22 16:01:17 -04002466 rxr->rx_tpa[i].mapping = mapping;
2467 }
2468 } else {
2469 netdev_err(bp->dev, "No resource allocated for LRO/GRO\n");
2470 return -ENOMEM;
2471 }
2472 }
2473
2474 return 0;
2475}
2476
Sankar Patchineelam22479252017-03-28 19:47:29 -04002477static void bnxt_init_cp_rings(struct bnxt *bp)
2478{
2479 int i;
2480
2481 for (i = 0; i < bp->cp_nr_rings; i++) {
2482 struct bnxt_cp_ring_info *cpr = &bp->bnapi[i]->cp_ring;
2483 struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
2484
2485 ring->fw_ring_id = INVALID_HW_RING_ID;
2486 }
2487}
2488
Michael Chanc0c050c2015-10-22 16:01:17 -04002489static int bnxt_init_rx_rings(struct bnxt *bp)
2490{
2491 int i, rc = 0;
2492
Michael Chanc61fb992017-02-06 16:55:36 -05002493 if (BNXT_RX_PAGE_MODE(bp)) {
Michael Chanc6d30e82017-02-06 16:55:42 -05002494 bp->rx_offset = NET_IP_ALIGN + XDP_PACKET_HEADROOM;
2495 bp->rx_dma_offset = XDP_PACKET_HEADROOM;
Michael Chanc61fb992017-02-06 16:55:36 -05002496 } else {
2497 bp->rx_offset = BNXT_RX_OFFSET;
2498 bp->rx_dma_offset = BNXT_RX_DMA_OFFSET;
2499 }
Michael Chanb3dba772017-02-06 16:55:35 -05002500
Michael Chanc0c050c2015-10-22 16:01:17 -04002501 for (i = 0; i < bp->rx_nr_rings; i++) {
2502 rc = bnxt_init_one_rx_ring(bp, i);
2503 if (rc)
2504 break;
2505 }
2506
2507 return rc;
2508}
2509
2510static int bnxt_init_tx_rings(struct bnxt *bp)
2511{
2512 u16 i;
2513
2514 bp->tx_wake_thresh = max_t(int, bp->tx_ring_size / 2,
2515 MAX_SKB_FRAGS + 1);
2516
2517 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05002518 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04002519 struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
2520
2521 ring->fw_ring_id = INVALID_HW_RING_ID;
2522 }
2523
2524 return 0;
2525}
2526
2527static void bnxt_free_ring_grps(struct bnxt *bp)
2528{
2529 kfree(bp->grp_info);
2530 bp->grp_info = NULL;
2531}
2532
2533static int bnxt_init_ring_grps(struct bnxt *bp, bool irq_re_init)
2534{
2535 int i;
2536
2537 if (irq_re_init) {
2538 bp->grp_info = kcalloc(bp->cp_nr_rings,
2539 sizeof(struct bnxt_ring_grp_info),
2540 GFP_KERNEL);
2541 if (!bp->grp_info)
2542 return -ENOMEM;
2543 }
2544 for (i = 0; i < bp->cp_nr_rings; i++) {
2545 if (irq_re_init)
2546 bp->grp_info[i].fw_stats_ctx = INVALID_HW_RING_ID;
2547 bp->grp_info[i].fw_grp_id = INVALID_HW_RING_ID;
2548 bp->grp_info[i].rx_fw_ring_id = INVALID_HW_RING_ID;
2549 bp->grp_info[i].agg_fw_ring_id = INVALID_HW_RING_ID;
2550 bp->grp_info[i].cp_fw_ring_id = INVALID_HW_RING_ID;
2551 }
2552 return 0;
2553}
2554
2555static void bnxt_free_vnics(struct bnxt *bp)
2556{
2557 kfree(bp->vnic_info);
2558 bp->vnic_info = NULL;
2559 bp->nr_vnics = 0;
2560}
2561
2562static int bnxt_alloc_vnics(struct bnxt *bp)
2563{
2564 int num_vnics = 1;
2565
2566#ifdef CONFIG_RFS_ACCEL
2567 if (bp->flags & BNXT_FLAG_RFS)
2568 num_vnics += bp->rx_nr_rings;
2569#endif
2570
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04002571 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
2572 num_vnics++;
2573
Michael Chanc0c050c2015-10-22 16:01:17 -04002574 bp->vnic_info = kcalloc(num_vnics, sizeof(struct bnxt_vnic_info),
2575 GFP_KERNEL);
2576 if (!bp->vnic_info)
2577 return -ENOMEM;
2578
2579 bp->nr_vnics = num_vnics;
2580 return 0;
2581}
2582
2583static void bnxt_init_vnics(struct bnxt *bp)
2584{
2585 int i;
2586
2587 for (i = 0; i < bp->nr_vnics; i++) {
2588 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
2589
2590 vnic->fw_vnic_id = INVALID_HW_RING_ID;
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04002591 vnic->fw_rss_cos_lb_ctx[0] = INVALID_HW_RING_ID;
2592 vnic->fw_rss_cos_lb_ctx[1] = INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04002593 vnic->fw_l2_ctx_id = INVALID_HW_RING_ID;
2594
2595 if (bp->vnic_info[i].rss_hash_key) {
2596 if (i == 0)
2597 prandom_bytes(vnic->rss_hash_key,
2598 HW_HASH_KEY_SIZE);
2599 else
2600 memcpy(vnic->rss_hash_key,
2601 bp->vnic_info[0].rss_hash_key,
2602 HW_HASH_KEY_SIZE);
2603 }
2604 }
2605}
2606
2607static int bnxt_calc_nr_ring_pages(u32 ring_size, int desc_per_pg)
2608{
2609 int pages;
2610
2611 pages = ring_size / desc_per_pg;
2612
2613 if (!pages)
2614 return 1;
2615
2616 pages++;
2617
2618 while (pages & (pages - 1))
2619 pages++;
2620
2621 return pages;
2622}
2623
Michael Chanc6d30e82017-02-06 16:55:42 -05002624void bnxt_set_tpa_flags(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04002625{
2626 bp->flags &= ~BNXT_FLAG_TPA;
Michael Chan341138c2017-01-13 01:32:01 -05002627 if (bp->flags & BNXT_FLAG_NO_AGG_RINGS)
2628 return;
Michael Chanc0c050c2015-10-22 16:01:17 -04002629 if (bp->dev->features & NETIF_F_LRO)
2630 bp->flags |= BNXT_FLAG_LRO;
Michael Chan94758f82016-06-13 02:25:35 -04002631 if (bp->dev->features & NETIF_F_GRO)
Michael Chanc0c050c2015-10-22 16:01:17 -04002632 bp->flags |= BNXT_FLAG_GRO;
2633}
2634
2635/* bp->rx_ring_size, bp->tx_ring_size, dev->mtu, BNXT_FLAG_{G|L}RO flags must
2636 * be set on entry.
2637 */
2638void bnxt_set_ring_params(struct bnxt *bp)
2639{
2640 u32 ring_size, rx_size, rx_space;
2641 u32 agg_factor = 0, agg_ring_size = 0;
2642
2643 /* 8 for CRC and VLAN */
2644 rx_size = SKB_DATA_ALIGN(bp->dev->mtu + ETH_HLEN + NET_IP_ALIGN + 8);
2645
2646 rx_space = rx_size + NET_SKB_PAD +
2647 SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
2648
2649 bp->rx_copy_thresh = BNXT_RX_COPY_THRESH;
2650 ring_size = bp->rx_ring_size;
2651 bp->rx_agg_ring_size = 0;
2652 bp->rx_agg_nr_pages = 0;
2653
2654 if (bp->flags & BNXT_FLAG_TPA)
Michael Chan2839f282016-04-25 02:30:50 -04002655 agg_factor = min_t(u32, 4, 65536 / BNXT_RX_PAGE_SIZE);
Michael Chanc0c050c2015-10-22 16:01:17 -04002656
2657 bp->flags &= ~BNXT_FLAG_JUMBO;
Michael Chanbdbd1eb2016-12-29 12:13:43 -05002658 if (rx_space > PAGE_SIZE && !(bp->flags & BNXT_FLAG_NO_AGG_RINGS)) {
Michael Chanc0c050c2015-10-22 16:01:17 -04002659 u32 jumbo_factor;
2660
2661 bp->flags |= BNXT_FLAG_JUMBO;
2662 jumbo_factor = PAGE_ALIGN(bp->dev->mtu - 40) >> PAGE_SHIFT;
2663 if (jumbo_factor > agg_factor)
2664 agg_factor = jumbo_factor;
2665 }
2666 agg_ring_size = ring_size * agg_factor;
2667
2668 if (agg_ring_size) {
2669 bp->rx_agg_nr_pages = bnxt_calc_nr_ring_pages(agg_ring_size,
2670 RX_DESC_CNT);
2671 if (bp->rx_agg_nr_pages > MAX_RX_AGG_PAGES) {
2672 u32 tmp = agg_ring_size;
2673
2674 bp->rx_agg_nr_pages = MAX_RX_AGG_PAGES;
2675 agg_ring_size = MAX_RX_AGG_PAGES * RX_DESC_CNT - 1;
2676 netdev_warn(bp->dev, "rx agg ring size %d reduced to %d.\n",
2677 tmp, agg_ring_size);
2678 }
2679 bp->rx_agg_ring_size = agg_ring_size;
2680 bp->rx_agg_ring_mask = (bp->rx_agg_nr_pages * RX_DESC_CNT) - 1;
2681 rx_size = SKB_DATA_ALIGN(BNXT_RX_COPY_THRESH + NET_IP_ALIGN);
2682 rx_space = rx_size + NET_SKB_PAD +
2683 SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
2684 }
2685
2686 bp->rx_buf_use_size = rx_size;
2687 bp->rx_buf_size = rx_space;
2688
2689 bp->rx_nr_pages = bnxt_calc_nr_ring_pages(ring_size, RX_DESC_CNT);
2690 bp->rx_ring_mask = (bp->rx_nr_pages * RX_DESC_CNT) - 1;
2691
2692 ring_size = bp->tx_ring_size;
2693 bp->tx_nr_pages = bnxt_calc_nr_ring_pages(ring_size, TX_DESC_CNT);
2694 bp->tx_ring_mask = (bp->tx_nr_pages * TX_DESC_CNT) - 1;
2695
2696 ring_size = bp->rx_ring_size * (2 + agg_factor) + bp->tx_ring_size;
2697 bp->cp_ring_size = ring_size;
2698
2699 bp->cp_nr_pages = bnxt_calc_nr_ring_pages(ring_size, CP_DESC_CNT);
2700 if (bp->cp_nr_pages > MAX_CP_PAGES) {
2701 bp->cp_nr_pages = MAX_CP_PAGES;
2702 bp->cp_ring_size = MAX_CP_PAGES * CP_DESC_CNT - 1;
2703 netdev_warn(bp->dev, "completion ring size %d reduced to %d.\n",
2704 ring_size, bp->cp_ring_size);
2705 }
2706 bp->cp_bit = bp->cp_nr_pages * CP_DESC_CNT;
2707 bp->cp_ring_mask = bp->cp_bit - 1;
2708}
2709
Michael Chanc61fb992017-02-06 16:55:36 -05002710int bnxt_set_rx_skb_mode(struct bnxt *bp, bool page_mode)
Michael Chan6bb19472017-02-06 16:55:32 -05002711{
Michael Chanc61fb992017-02-06 16:55:36 -05002712 if (page_mode) {
2713 if (bp->dev->mtu > BNXT_MAX_PAGE_MODE_MTU)
2714 return -EOPNOTSUPP;
2715 bp->dev->max_mtu = BNXT_MAX_PAGE_MODE_MTU;
2716 bp->flags &= ~BNXT_FLAG_AGG_RINGS;
2717 bp->flags |= BNXT_FLAG_NO_AGG_RINGS | BNXT_FLAG_RX_PAGE_MODE;
2718 bp->dev->hw_features &= ~NETIF_F_LRO;
2719 bp->dev->features &= ~NETIF_F_LRO;
2720 bp->rx_dir = DMA_BIDIRECTIONAL;
2721 bp->rx_skb_func = bnxt_rx_page_skb;
2722 } else {
2723 bp->dev->max_mtu = BNXT_MAX_MTU;
2724 bp->flags &= ~BNXT_FLAG_RX_PAGE_MODE;
2725 bp->rx_dir = DMA_FROM_DEVICE;
2726 bp->rx_skb_func = bnxt_rx_skb;
2727 }
Michael Chan6bb19472017-02-06 16:55:32 -05002728 return 0;
2729}
2730
Michael Chanc0c050c2015-10-22 16:01:17 -04002731static void bnxt_free_vnic_attributes(struct bnxt *bp)
2732{
2733 int i;
2734 struct bnxt_vnic_info *vnic;
2735 struct pci_dev *pdev = bp->pdev;
2736
2737 if (!bp->vnic_info)
2738 return;
2739
2740 for (i = 0; i < bp->nr_vnics; i++) {
2741 vnic = &bp->vnic_info[i];
2742
2743 kfree(vnic->fw_grp_ids);
2744 vnic->fw_grp_ids = NULL;
2745
2746 kfree(vnic->uc_list);
2747 vnic->uc_list = NULL;
2748
2749 if (vnic->mc_list) {
2750 dma_free_coherent(&pdev->dev, vnic->mc_list_size,
2751 vnic->mc_list, vnic->mc_list_mapping);
2752 vnic->mc_list = NULL;
2753 }
2754
2755 if (vnic->rss_table) {
2756 dma_free_coherent(&pdev->dev, PAGE_SIZE,
2757 vnic->rss_table,
2758 vnic->rss_table_dma_addr);
2759 vnic->rss_table = NULL;
2760 }
2761
2762 vnic->rss_hash_key = NULL;
2763 vnic->flags = 0;
2764 }
2765}
2766
2767static int bnxt_alloc_vnic_attributes(struct bnxt *bp)
2768{
2769 int i, rc = 0, size;
2770 struct bnxt_vnic_info *vnic;
2771 struct pci_dev *pdev = bp->pdev;
2772 int max_rings;
2773
2774 for (i = 0; i < bp->nr_vnics; i++) {
2775 vnic = &bp->vnic_info[i];
2776
2777 if (vnic->flags & BNXT_VNIC_UCAST_FLAG) {
2778 int mem_size = (BNXT_MAX_UC_ADDRS - 1) * ETH_ALEN;
2779
2780 if (mem_size > 0) {
2781 vnic->uc_list = kmalloc(mem_size, GFP_KERNEL);
2782 if (!vnic->uc_list) {
2783 rc = -ENOMEM;
2784 goto out;
2785 }
2786 }
2787 }
2788
2789 if (vnic->flags & BNXT_VNIC_MCAST_FLAG) {
2790 vnic->mc_list_size = BNXT_MAX_MC_ADDRS * ETH_ALEN;
2791 vnic->mc_list =
2792 dma_alloc_coherent(&pdev->dev,
2793 vnic->mc_list_size,
2794 &vnic->mc_list_mapping,
2795 GFP_KERNEL);
2796 if (!vnic->mc_list) {
2797 rc = -ENOMEM;
2798 goto out;
2799 }
2800 }
2801
2802 if (vnic->flags & BNXT_VNIC_RSS_FLAG)
2803 max_rings = bp->rx_nr_rings;
2804 else
2805 max_rings = 1;
2806
2807 vnic->fw_grp_ids = kcalloc(max_rings, sizeof(u16), GFP_KERNEL);
2808 if (!vnic->fw_grp_ids) {
2809 rc = -ENOMEM;
2810 goto out;
2811 }
2812
Michael Chanae10ae72016-12-29 12:13:38 -05002813 if ((bp->flags & BNXT_FLAG_NEW_RSS_CAP) &&
2814 !(vnic->flags & BNXT_VNIC_RSS_FLAG))
2815 continue;
2816
Michael Chanc0c050c2015-10-22 16:01:17 -04002817 /* Allocate rss table and hash key */
2818 vnic->rss_table = dma_alloc_coherent(&pdev->dev, PAGE_SIZE,
2819 &vnic->rss_table_dma_addr,
2820 GFP_KERNEL);
2821 if (!vnic->rss_table) {
2822 rc = -ENOMEM;
2823 goto out;
2824 }
2825
2826 size = L1_CACHE_ALIGN(HW_HASH_INDEX_SIZE * sizeof(u16));
2827
2828 vnic->rss_hash_key = ((void *)vnic->rss_table) + size;
2829 vnic->rss_hash_key_dma_addr = vnic->rss_table_dma_addr + size;
2830 }
2831 return 0;
2832
2833out:
2834 return rc;
2835}
2836
2837static void bnxt_free_hwrm_resources(struct bnxt *bp)
2838{
2839 struct pci_dev *pdev = bp->pdev;
2840
2841 dma_free_coherent(&pdev->dev, PAGE_SIZE, bp->hwrm_cmd_resp_addr,
2842 bp->hwrm_cmd_resp_dma_addr);
2843
2844 bp->hwrm_cmd_resp_addr = NULL;
2845 if (bp->hwrm_dbg_resp_addr) {
2846 dma_free_coherent(&pdev->dev, HWRM_DBG_REG_BUF_SIZE,
2847 bp->hwrm_dbg_resp_addr,
2848 bp->hwrm_dbg_resp_dma_addr);
2849
2850 bp->hwrm_dbg_resp_addr = NULL;
2851 }
2852}
2853
2854static int bnxt_alloc_hwrm_resources(struct bnxt *bp)
2855{
2856 struct pci_dev *pdev = bp->pdev;
2857
2858 bp->hwrm_cmd_resp_addr = dma_alloc_coherent(&pdev->dev, PAGE_SIZE,
2859 &bp->hwrm_cmd_resp_dma_addr,
2860 GFP_KERNEL);
2861 if (!bp->hwrm_cmd_resp_addr)
2862 return -ENOMEM;
2863 bp->hwrm_dbg_resp_addr = dma_alloc_coherent(&pdev->dev,
2864 HWRM_DBG_REG_BUF_SIZE,
2865 &bp->hwrm_dbg_resp_dma_addr,
2866 GFP_KERNEL);
2867 if (!bp->hwrm_dbg_resp_addr)
2868 netdev_warn(bp->dev, "fail to alloc debug register dma mem\n");
2869
2870 return 0;
2871}
2872
Deepak Khungare605db82017-05-29 19:06:04 -04002873static void bnxt_free_hwrm_short_cmd_req(struct bnxt *bp)
2874{
2875 if (bp->hwrm_short_cmd_req_addr) {
2876 struct pci_dev *pdev = bp->pdev;
2877
2878 dma_free_coherent(&pdev->dev, BNXT_HWRM_MAX_REQ_LEN,
2879 bp->hwrm_short_cmd_req_addr,
2880 bp->hwrm_short_cmd_req_dma_addr);
2881 bp->hwrm_short_cmd_req_addr = NULL;
2882 }
2883}
2884
2885static int bnxt_alloc_hwrm_short_cmd_req(struct bnxt *bp)
2886{
2887 struct pci_dev *pdev = bp->pdev;
2888
2889 bp->hwrm_short_cmd_req_addr =
2890 dma_alloc_coherent(&pdev->dev, BNXT_HWRM_MAX_REQ_LEN,
2891 &bp->hwrm_short_cmd_req_dma_addr,
2892 GFP_KERNEL);
2893 if (!bp->hwrm_short_cmd_req_addr)
2894 return -ENOMEM;
2895
2896 return 0;
2897}
2898
Michael Chanc0c050c2015-10-22 16:01:17 -04002899static void bnxt_free_stats(struct bnxt *bp)
2900{
2901 u32 size, i;
2902 struct pci_dev *pdev = bp->pdev;
2903
Michael Chan3bdf56c2016-03-07 15:38:45 -05002904 if (bp->hw_rx_port_stats) {
2905 dma_free_coherent(&pdev->dev, bp->hw_port_stats_size,
2906 bp->hw_rx_port_stats,
2907 bp->hw_rx_port_stats_map);
2908 bp->hw_rx_port_stats = NULL;
2909 bp->flags &= ~BNXT_FLAG_PORT_STATS;
2910 }
2911
Michael Chanc0c050c2015-10-22 16:01:17 -04002912 if (!bp->bnapi)
2913 return;
2914
2915 size = sizeof(struct ctx_hw_stats);
2916
2917 for (i = 0; i < bp->cp_nr_rings; i++) {
2918 struct bnxt_napi *bnapi = bp->bnapi[i];
2919 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
2920
2921 if (cpr->hw_stats) {
2922 dma_free_coherent(&pdev->dev, size, cpr->hw_stats,
2923 cpr->hw_stats_map);
2924 cpr->hw_stats = NULL;
2925 }
2926 }
2927}
2928
2929static int bnxt_alloc_stats(struct bnxt *bp)
2930{
2931 u32 size, i;
2932 struct pci_dev *pdev = bp->pdev;
2933
2934 size = sizeof(struct ctx_hw_stats);
2935
2936 for (i = 0; i < bp->cp_nr_rings; i++) {
2937 struct bnxt_napi *bnapi = bp->bnapi[i];
2938 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
2939
2940 cpr->hw_stats = dma_alloc_coherent(&pdev->dev, size,
2941 &cpr->hw_stats_map,
2942 GFP_KERNEL);
2943 if (!cpr->hw_stats)
2944 return -ENOMEM;
2945
2946 cpr->hw_stats_ctx_id = INVALID_STATS_CTX_ID;
2947 }
Michael Chan3bdf56c2016-03-07 15:38:45 -05002948
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04002949 if (BNXT_PF(bp) && bp->chip_num != CHIP_NUM_58700) {
Michael Chan3bdf56c2016-03-07 15:38:45 -05002950 bp->hw_port_stats_size = sizeof(struct rx_port_stats) +
2951 sizeof(struct tx_port_stats) + 1024;
2952
2953 bp->hw_rx_port_stats =
2954 dma_alloc_coherent(&pdev->dev, bp->hw_port_stats_size,
2955 &bp->hw_rx_port_stats_map,
2956 GFP_KERNEL);
2957 if (!bp->hw_rx_port_stats)
2958 return -ENOMEM;
2959
2960 bp->hw_tx_port_stats = (void *)(bp->hw_rx_port_stats + 1) +
2961 512;
2962 bp->hw_tx_port_stats_map = bp->hw_rx_port_stats_map +
2963 sizeof(struct rx_port_stats) + 512;
2964 bp->flags |= BNXT_FLAG_PORT_STATS;
2965 }
Michael Chanc0c050c2015-10-22 16:01:17 -04002966 return 0;
2967}
2968
2969static void bnxt_clear_ring_indices(struct bnxt *bp)
2970{
2971 int i;
2972
2973 if (!bp->bnapi)
2974 return;
2975
2976 for (i = 0; i < bp->cp_nr_rings; i++) {
2977 struct bnxt_napi *bnapi = bp->bnapi[i];
2978 struct bnxt_cp_ring_info *cpr;
2979 struct bnxt_rx_ring_info *rxr;
2980 struct bnxt_tx_ring_info *txr;
2981
2982 if (!bnapi)
2983 continue;
2984
2985 cpr = &bnapi->cp_ring;
2986 cpr->cp_raw_cons = 0;
2987
Michael Chanb6ab4b02016-01-02 23:44:59 -05002988 txr = bnapi->tx_ring;
Michael Chan3b2b7d92016-01-02 23:45:00 -05002989 if (txr) {
2990 txr->tx_prod = 0;
2991 txr->tx_cons = 0;
2992 }
Michael Chanc0c050c2015-10-22 16:01:17 -04002993
Michael Chanb6ab4b02016-01-02 23:44:59 -05002994 rxr = bnapi->rx_ring;
Michael Chan3b2b7d92016-01-02 23:45:00 -05002995 if (rxr) {
2996 rxr->rx_prod = 0;
2997 rxr->rx_agg_prod = 0;
2998 rxr->rx_sw_agg_prod = 0;
Michael Chan376a5b82016-05-10 19:17:59 -04002999 rxr->rx_next_cons = 0;
Michael Chan3b2b7d92016-01-02 23:45:00 -05003000 }
Michael Chanc0c050c2015-10-22 16:01:17 -04003001 }
3002}
3003
3004static void bnxt_free_ntp_fltrs(struct bnxt *bp, bool irq_reinit)
3005{
3006#ifdef CONFIG_RFS_ACCEL
3007 int i;
3008
3009 /* Under rtnl_lock and all our NAPIs have been disabled. It's
3010 * safe to delete the hash table.
3011 */
3012 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
3013 struct hlist_head *head;
3014 struct hlist_node *tmp;
3015 struct bnxt_ntuple_filter *fltr;
3016
3017 head = &bp->ntp_fltr_hash_tbl[i];
3018 hlist_for_each_entry_safe(fltr, tmp, head, hash) {
3019 hlist_del(&fltr->hash);
3020 kfree(fltr);
3021 }
3022 }
3023 if (irq_reinit) {
3024 kfree(bp->ntp_fltr_bmap);
3025 bp->ntp_fltr_bmap = NULL;
3026 }
3027 bp->ntp_fltr_count = 0;
3028#endif
3029}
3030
3031static int bnxt_alloc_ntp_fltrs(struct bnxt *bp)
3032{
3033#ifdef CONFIG_RFS_ACCEL
3034 int i, rc = 0;
3035
3036 if (!(bp->flags & BNXT_FLAG_RFS))
3037 return 0;
3038
3039 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++)
3040 INIT_HLIST_HEAD(&bp->ntp_fltr_hash_tbl[i]);
3041
3042 bp->ntp_fltr_count = 0;
Dan Carpenterac45bd92017-05-06 03:49:01 +03003043 bp->ntp_fltr_bmap = kcalloc(BITS_TO_LONGS(BNXT_NTP_FLTR_MAX_FLTR),
3044 sizeof(long),
Michael Chanc0c050c2015-10-22 16:01:17 -04003045 GFP_KERNEL);
3046
3047 if (!bp->ntp_fltr_bmap)
3048 rc = -ENOMEM;
3049
3050 return rc;
3051#else
3052 return 0;
3053#endif
3054}
3055
3056static void bnxt_free_mem(struct bnxt *bp, bool irq_re_init)
3057{
3058 bnxt_free_vnic_attributes(bp);
3059 bnxt_free_tx_rings(bp);
3060 bnxt_free_rx_rings(bp);
3061 bnxt_free_cp_rings(bp);
3062 bnxt_free_ntp_fltrs(bp, irq_re_init);
3063 if (irq_re_init) {
3064 bnxt_free_stats(bp);
3065 bnxt_free_ring_grps(bp);
3066 bnxt_free_vnics(bp);
Michael Chana960dec2017-02-06 16:55:39 -05003067 kfree(bp->tx_ring_map);
3068 bp->tx_ring_map = NULL;
Michael Chanb6ab4b02016-01-02 23:44:59 -05003069 kfree(bp->tx_ring);
3070 bp->tx_ring = NULL;
3071 kfree(bp->rx_ring);
3072 bp->rx_ring = NULL;
Michael Chanc0c050c2015-10-22 16:01:17 -04003073 kfree(bp->bnapi);
3074 bp->bnapi = NULL;
3075 } else {
3076 bnxt_clear_ring_indices(bp);
3077 }
3078}
3079
3080static int bnxt_alloc_mem(struct bnxt *bp, bool irq_re_init)
3081{
Michael Chan01657bc2016-01-02 23:45:03 -05003082 int i, j, rc, size, arr_size;
Michael Chanc0c050c2015-10-22 16:01:17 -04003083 void *bnapi;
3084
3085 if (irq_re_init) {
3086 /* Allocate bnapi mem pointer array and mem block for
3087 * all queues
3088 */
3089 arr_size = L1_CACHE_ALIGN(sizeof(struct bnxt_napi *) *
3090 bp->cp_nr_rings);
3091 size = L1_CACHE_ALIGN(sizeof(struct bnxt_napi));
3092 bnapi = kzalloc(arr_size + size * bp->cp_nr_rings, GFP_KERNEL);
3093 if (!bnapi)
3094 return -ENOMEM;
3095
3096 bp->bnapi = bnapi;
3097 bnapi += arr_size;
3098 for (i = 0; i < bp->cp_nr_rings; i++, bnapi += size) {
3099 bp->bnapi[i] = bnapi;
3100 bp->bnapi[i]->index = i;
3101 bp->bnapi[i]->bp = bp;
3102 }
3103
Michael Chanb6ab4b02016-01-02 23:44:59 -05003104 bp->rx_ring = kcalloc(bp->rx_nr_rings,
3105 sizeof(struct bnxt_rx_ring_info),
3106 GFP_KERNEL);
3107 if (!bp->rx_ring)
3108 return -ENOMEM;
3109
3110 for (i = 0; i < bp->rx_nr_rings; i++) {
3111 bp->rx_ring[i].bnapi = bp->bnapi[i];
3112 bp->bnapi[i]->rx_ring = &bp->rx_ring[i];
3113 }
3114
3115 bp->tx_ring = kcalloc(bp->tx_nr_rings,
3116 sizeof(struct bnxt_tx_ring_info),
3117 GFP_KERNEL);
3118 if (!bp->tx_ring)
3119 return -ENOMEM;
3120
Michael Chana960dec2017-02-06 16:55:39 -05003121 bp->tx_ring_map = kcalloc(bp->tx_nr_rings, sizeof(u16),
3122 GFP_KERNEL);
3123
3124 if (!bp->tx_ring_map)
3125 return -ENOMEM;
3126
Michael Chan01657bc2016-01-02 23:45:03 -05003127 if (bp->flags & BNXT_FLAG_SHARED_RINGS)
3128 j = 0;
3129 else
3130 j = bp->rx_nr_rings;
3131
3132 for (i = 0; i < bp->tx_nr_rings; i++, j++) {
3133 bp->tx_ring[i].bnapi = bp->bnapi[j];
3134 bp->bnapi[j]->tx_ring = &bp->tx_ring[i];
Michael Chan5f449242017-02-06 16:55:40 -05003135 bp->tx_ring_map[i] = bp->tx_nr_rings_xdp + i;
Michael Chan38413402017-02-06 16:55:43 -05003136 if (i >= bp->tx_nr_rings_xdp) {
Michael Chan5f449242017-02-06 16:55:40 -05003137 bp->tx_ring[i].txq_index = i -
3138 bp->tx_nr_rings_xdp;
Michael Chan38413402017-02-06 16:55:43 -05003139 bp->bnapi[j]->tx_int = bnxt_tx_int;
3140 } else {
Michael Chanfa3e93e2017-02-06 16:55:41 -05003141 bp->bnapi[j]->flags |= BNXT_NAPI_FLAG_XDP;
Michael Chan38413402017-02-06 16:55:43 -05003142 bp->bnapi[j]->tx_int = bnxt_tx_int_xdp;
3143 }
Michael Chanb6ab4b02016-01-02 23:44:59 -05003144 }
3145
Michael Chanc0c050c2015-10-22 16:01:17 -04003146 rc = bnxt_alloc_stats(bp);
3147 if (rc)
3148 goto alloc_mem_err;
3149
3150 rc = bnxt_alloc_ntp_fltrs(bp);
3151 if (rc)
3152 goto alloc_mem_err;
3153
3154 rc = bnxt_alloc_vnics(bp);
3155 if (rc)
3156 goto alloc_mem_err;
3157 }
3158
3159 bnxt_init_ring_struct(bp);
3160
3161 rc = bnxt_alloc_rx_rings(bp);
3162 if (rc)
3163 goto alloc_mem_err;
3164
3165 rc = bnxt_alloc_tx_rings(bp);
3166 if (rc)
3167 goto alloc_mem_err;
3168
3169 rc = bnxt_alloc_cp_rings(bp);
3170 if (rc)
3171 goto alloc_mem_err;
3172
3173 bp->vnic_info[0].flags |= BNXT_VNIC_RSS_FLAG | BNXT_VNIC_MCAST_FLAG |
3174 BNXT_VNIC_UCAST_FLAG;
3175 rc = bnxt_alloc_vnic_attributes(bp);
3176 if (rc)
3177 goto alloc_mem_err;
3178 return 0;
3179
3180alloc_mem_err:
3181 bnxt_free_mem(bp, true);
3182 return rc;
3183}
3184
Michael Chan9d8bc092016-12-29 12:13:33 -05003185static void bnxt_disable_int(struct bnxt *bp)
3186{
3187 int i;
3188
3189 if (!bp->bnapi)
3190 return;
3191
3192 for (i = 0; i < bp->cp_nr_rings; i++) {
3193 struct bnxt_napi *bnapi = bp->bnapi[i];
3194 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
Michael Chandaf1f1e2017-02-20 19:25:17 -05003195 struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
Michael Chan9d8bc092016-12-29 12:13:33 -05003196
Michael Chandaf1f1e2017-02-20 19:25:17 -05003197 if (ring->fw_ring_id != INVALID_HW_RING_ID)
3198 BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
Michael Chan9d8bc092016-12-29 12:13:33 -05003199 }
3200}
3201
3202static void bnxt_disable_int_sync(struct bnxt *bp)
3203{
3204 int i;
3205
3206 atomic_inc(&bp->intr_sem);
3207
3208 bnxt_disable_int(bp);
3209 for (i = 0; i < bp->cp_nr_rings; i++)
3210 synchronize_irq(bp->irq_tbl[i].vector);
3211}
3212
3213static void bnxt_enable_int(struct bnxt *bp)
3214{
3215 int i;
3216
3217 atomic_set(&bp->intr_sem, 0);
3218 for (i = 0; i < bp->cp_nr_rings; i++) {
3219 struct bnxt_napi *bnapi = bp->bnapi[i];
3220 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
3221
3222 BNXT_CP_DB_REARM(cpr->cp_doorbell, cpr->cp_raw_cons);
3223 }
3224}
3225
Michael Chanc0c050c2015-10-22 16:01:17 -04003226void bnxt_hwrm_cmd_hdr_init(struct bnxt *bp, void *request, u16 req_type,
3227 u16 cmpl_ring, u16 target_id)
3228{
Michael Chana8643e12016-02-26 04:00:05 -05003229 struct input *req = request;
Michael Chanc0c050c2015-10-22 16:01:17 -04003230
Michael Chana8643e12016-02-26 04:00:05 -05003231 req->req_type = cpu_to_le16(req_type);
3232 req->cmpl_ring = cpu_to_le16(cmpl_ring);
3233 req->target_id = cpu_to_le16(target_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04003234 req->resp_addr = cpu_to_le64(bp->hwrm_cmd_resp_dma_addr);
3235}
3236
Michael Chanfbfbc482016-02-26 04:00:07 -05003237static int bnxt_hwrm_do_send_msg(struct bnxt *bp, void *msg, u32 msg_len,
3238 int timeout, bool silent)
Michael Chanc0c050c2015-10-22 16:01:17 -04003239{
Michael Chana11fa2b2016-05-15 03:04:47 -04003240 int i, intr_process, rc, tmo_count;
Michael Chana8643e12016-02-26 04:00:05 -05003241 struct input *req = msg;
Michael Chanc0c050c2015-10-22 16:01:17 -04003242 u32 *data = msg;
3243 __le32 *resp_len, *valid;
3244 u16 cp_ring_id, len = 0;
3245 struct hwrm_err_output *resp = bp->hwrm_cmd_resp_addr;
Deepak Khungare605db82017-05-29 19:06:04 -04003246 u16 max_req_len = BNXT_HWRM_MAX_REQ_LEN;
Michael Chanc0c050c2015-10-22 16:01:17 -04003247
Michael Chana8643e12016-02-26 04:00:05 -05003248 req->seq_id = cpu_to_le16(bp->hwrm_cmd_seq++);
Michael Chanc0c050c2015-10-22 16:01:17 -04003249 memset(resp, 0, PAGE_SIZE);
Michael Chana8643e12016-02-26 04:00:05 -05003250 cp_ring_id = le16_to_cpu(req->cmpl_ring);
Michael Chanc0c050c2015-10-22 16:01:17 -04003251 intr_process = (cp_ring_id == INVALID_HW_RING_ID) ? 0 : 1;
3252
Deepak Khungare605db82017-05-29 19:06:04 -04003253 if (bp->flags & BNXT_FLAG_SHORT_CMD) {
3254 void *short_cmd_req = bp->hwrm_short_cmd_req_addr;
3255 struct hwrm_short_input short_input = {0};
3256
3257 memcpy(short_cmd_req, req, msg_len);
3258 memset(short_cmd_req + msg_len, 0, BNXT_HWRM_MAX_REQ_LEN -
3259 msg_len);
3260
3261 short_input.req_type = req->req_type;
3262 short_input.signature =
3263 cpu_to_le16(SHORT_REQ_SIGNATURE_SHORT_CMD);
3264 short_input.size = cpu_to_le16(msg_len);
3265 short_input.req_addr =
3266 cpu_to_le64(bp->hwrm_short_cmd_req_dma_addr);
3267
3268 data = (u32 *)&short_input;
3269 msg_len = sizeof(short_input);
3270
3271 /* Sync memory write before updating doorbell */
3272 wmb();
3273
3274 max_req_len = BNXT_HWRM_SHORT_REQ_LEN;
3275 }
3276
Michael Chanc0c050c2015-10-22 16:01:17 -04003277 /* Write request msg to hwrm channel */
3278 __iowrite32_copy(bp->bar0, data, msg_len / 4);
3279
Deepak Khungare605db82017-05-29 19:06:04 -04003280 for (i = msg_len; i < max_req_len; i += 4)
Michael Chand79979a2016-01-07 19:56:57 -05003281 writel(0, bp->bar0 + i);
3282
Michael Chanc0c050c2015-10-22 16:01:17 -04003283 /* currently supports only one outstanding message */
3284 if (intr_process)
Michael Chana8643e12016-02-26 04:00:05 -05003285 bp->hwrm_intr_seq_id = le16_to_cpu(req->seq_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04003286
3287 /* Ring channel doorbell */
3288 writel(1, bp->bar0 + 0x100);
3289
Michael Chanff4fe812016-02-26 04:00:04 -05003290 if (!timeout)
3291 timeout = DFLT_HWRM_CMD_TIMEOUT;
3292
Michael Chanc0c050c2015-10-22 16:01:17 -04003293 i = 0;
Michael Chana11fa2b2016-05-15 03:04:47 -04003294 tmo_count = timeout * 40;
Michael Chanc0c050c2015-10-22 16:01:17 -04003295 if (intr_process) {
3296 /* Wait until hwrm response cmpl interrupt is processed */
3297 while (bp->hwrm_intr_seq_id != HWRM_SEQ_ID_INVALID &&
Michael Chana11fa2b2016-05-15 03:04:47 -04003298 i++ < tmo_count) {
3299 usleep_range(25, 40);
Michael Chanc0c050c2015-10-22 16:01:17 -04003300 }
3301
3302 if (bp->hwrm_intr_seq_id != HWRM_SEQ_ID_INVALID) {
3303 netdev_err(bp->dev, "Resp cmpl intr err msg: 0x%x\n",
Michael Chana8643e12016-02-26 04:00:05 -05003304 le16_to_cpu(req->req_type));
Michael Chanc0c050c2015-10-22 16:01:17 -04003305 return -1;
3306 }
3307 } else {
3308 /* Check if response len is updated */
3309 resp_len = bp->hwrm_cmd_resp_addr + HWRM_RESP_LEN_OFFSET;
Michael Chana11fa2b2016-05-15 03:04:47 -04003310 for (i = 0; i < tmo_count; i++) {
Michael Chanc0c050c2015-10-22 16:01:17 -04003311 len = (le32_to_cpu(*resp_len) & HWRM_RESP_LEN_MASK) >>
3312 HWRM_RESP_LEN_SFT;
3313 if (len)
3314 break;
Michael Chana11fa2b2016-05-15 03:04:47 -04003315 usleep_range(25, 40);
Michael Chanc0c050c2015-10-22 16:01:17 -04003316 }
3317
Michael Chana11fa2b2016-05-15 03:04:47 -04003318 if (i >= tmo_count) {
Michael Chanc0c050c2015-10-22 16:01:17 -04003319 netdev_err(bp->dev, "Error (timeout: %d) msg {0x%x 0x%x} len:%d\n",
Michael Chana8643e12016-02-26 04:00:05 -05003320 timeout, le16_to_cpu(req->req_type),
Michael Chan8578d6c2016-05-15 03:04:48 -04003321 le16_to_cpu(req->seq_id), len);
Michael Chanc0c050c2015-10-22 16:01:17 -04003322 return -1;
3323 }
3324
3325 /* Last word of resp contains valid bit */
3326 valid = bp->hwrm_cmd_resp_addr + len - 4;
Michael Chana11fa2b2016-05-15 03:04:47 -04003327 for (i = 0; i < 5; i++) {
Michael Chanc0c050c2015-10-22 16:01:17 -04003328 if (le32_to_cpu(*valid) & HWRM_RESP_VALID_MASK)
3329 break;
Michael Chana11fa2b2016-05-15 03:04:47 -04003330 udelay(1);
Michael Chanc0c050c2015-10-22 16:01:17 -04003331 }
3332
Michael Chana11fa2b2016-05-15 03:04:47 -04003333 if (i >= 5) {
Michael Chanc0c050c2015-10-22 16:01:17 -04003334 netdev_err(bp->dev, "Error (timeout: %d) msg {0x%x 0x%x} len:%d v:%d\n",
Michael Chana8643e12016-02-26 04:00:05 -05003335 timeout, le16_to_cpu(req->req_type),
3336 le16_to_cpu(req->seq_id), len, *valid);
Michael Chanc0c050c2015-10-22 16:01:17 -04003337 return -1;
3338 }
3339 }
3340
3341 rc = le16_to_cpu(resp->error_code);
Michael Chanfbfbc482016-02-26 04:00:07 -05003342 if (rc && !silent)
Michael Chanc0c050c2015-10-22 16:01:17 -04003343 netdev_err(bp->dev, "hwrm req_type 0x%x seq id 0x%x error 0x%x\n",
3344 le16_to_cpu(resp->req_type),
3345 le16_to_cpu(resp->seq_id), rc);
Michael Chanfbfbc482016-02-26 04:00:07 -05003346 return rc;
3347}
3348
3349int _hwrm_send_message(struct bnxt *bp, void *msg, u32 msg_len, int timeout)
3350{
3351 return bnxt_hwrm_do_send_msg(bp, msg, msg_len, timeout, false);
Michael Chanc0c050c2015-10-22 16:01:17 -04003352}
3353
3354int hwrm_send_message(struct bnxt *bp, void *msg, u32 msg_len, int timeout)
3355{
3356 int rc;
3357
3358 mutex_lock(&bp->hwrm_cmd_lock);
3359 rc = _hwrm_send_message(bp, msg, msg_len, timeout);
3360 mutex_unlock(&bp->hwrm_cmd_lock);
3361 return rc;
3362}
3363
Michael Chan90e209212016-02-26 04:00:08 -05003364int hwrm_send_message_silent(struct bnxt *bp, void *msg, u32 msg_len,
3365 int timeout)
3366{
3367 int rc;
3368
3369 mutex_lock(&bp->hwrm_cmd_lock);
3370 rc = bnxt_hwrm_do_send_msg(bp, msg, msg_len, timeout, true);
3371 mutex_unlock(&bp->hwrm_cmd_lock);
3372 return rc;
3373}
3374
Michael Chana1653b12016-12-07 00:26:20 -05003375int bnxt_hwrm_func_rgtr_async_events(struct bnxt *bp, unsigned long *bmap,
3376 int bmap_size)
Michael Chanc0c050c2015-10-22 16:01:17 -04003377{
3378 struct hwrm_func_drv_rgtr_input req = {0};
Michael Chan25be8622016-04-05 14:09:00 -04003379 DECLARE_BITMAP(async_events_bmap, 256);
3380 u32 *events = (u32 *)async_events_bmap;
Michael Chana1653b12016-12-07 00:26:20 -05003381 int i;
Michael Chanc0c050c2015-10-22 16:01:17 -04003382
3383 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_RGTR, -1, -1);
3384
3385 req.enables =
Michael Chana1653b12016-12-07 00:26:20 -05003386 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_ASYNC_EVENT_FWD);
Michael Chanc0c050c2015-10-22 16:01:17 -04003387
Michael Chan25be8622016-04-05 14:09:00 -04003388 memset(async_events_bmap, 0, sizeof(async_events_bmap));
3389 for (i = 0; i < ARRAY_SIZE(bnxt_async_events_arr); i++)
3390 __set_bit(bnxt_async_events_arr[i], async_events_bmap);
3391
Michael Chana1653b12016-12-07 00:26:20 -05003392 if (bmap && bmap_size) {
3393 for (i = 0; i < bmap_size; i++) {
3394 if (test_bit(i, bmap))
3395 __set_bit(i, async_events_bmap);
3396 }
3397 }
3398
Michael Chan25be8622016-04-05 14:09:00 -04003399 for (i = 0; i < 8; i++)
3400 req.async_event_fwd[i] |= cpu_to_le32(events[i]);
3401
Michael Chana1653b12016-12-07 00:26:20 -05003402 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3403}
3404
3405static int bnxt_hwrm_func_drv_rgtr(struct bnxt *bp)
3406{
3407 struct hwrm_func_drv_rgtr_input req = {0};
3408
3409 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_RGTR, -1, -1);
3410
3411 req.enables =
3412 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_OS_TYPE |
3413 FUNC_DRV_RGTR_REQ_ENABLES_VER);
3414
Michael Chan11f15ed2016-04-05 14:08:55 -04003415 req.os_type = cpu_to_le16(FUNC_DRV_RGTR_REQ_OS_TYPE_LINUX);
Michael Chanc0c050c2015-10-22 16:01:17 -04003416 req.ver_maj = DRV_VER_MAJ;
3417 req.ver_min = DRV_VER_MIN;
3418 req.ver_upd = DRV_VER_UPD;
3419
3420 if (BNXT_PF(bp)) {
Michael Chande68f5de2015-12-09 19:35:41 -05003421 DECLARE_BITMAP(vf_req_snif_bmap, 256);
Michael Chanc0c050c2015-10-22 16:01:17 -04003422 u32 *data = (u32 *)vf_req_snif_bmap;
Michael Chana1653b12016-12-07 00:26:20 -05003423 int i;
Michael Chanc0c050c2015-10-22 16:01:17 -04003424
Michael Chande68f5de2015-12-09 19:35:41 -05003425 memset(vf_req_snif_bmap, 0, sizeof(vf_req_snif_bmap));
Michael Chanc0c050c2015-10-22 16:01:17 -04003426 for (i = 0; i < ARRAY_SIZE(bnxt_vf_req_snif); i++)
3427 __set_bit(bnxt_vf_req_snif[i], vf_req_snif_bmap);
3428
Michael Chande68f5de2015-12-09 19:35:41 -05003429 for (i = 0; i < 8; i++)
3430 req.vf_req_fwd[i] = cpu_to_le32(data[i]);
3431
Michael Chanc0c050c2015-10-22 16:01:17 -04003432 req.enables |=
3433 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_VF_REQ_FWD);
3434 }
3435
3436 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3437}
3438
Jeffrey Huangbe58a0d2015-12-27 18:19:18 -05003439static int bnxt_hwrm_func_drv_unrgtr(struct bnxt *bp)
3440{
3441 struct hwrm_func_drv_unrgtr_input req = {0};
3442
3443 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_UNRGTR, -1, -1);
3444 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3445}
3446
Michael Chanc0c050c2015-10-22 16:01:17 -04003447static int bnxt_hwrm_tunnel_dst_port_free(struct bnxt *bp, u8 tunnel_type)
3448{
3449 u32 rc = 0;
3450 struct hwrm_tunnel_dst_port_free_input req = {0};
3451
3452 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_TUNNEL_DST_PORT_FREE, -1, -1);
3453 req.tunnel_type = tunnel_type;
3454
3455 switch (tunnel_type) {
3456 case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN:
3457 req.tunnel_dst_port_id = bp->vxlan_fw_dst_port_id;
3458 break;
3459 case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE:
3460 req.tunnel_dst_port_id = bp->nge_fw_dst_port_id;
3461 break;
3462 default:
3463 break;
3464 }
3465
3466 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3467 if (rc)
3468 netdev_err(bp->dev, "hwrm_tunnel_dst_port_free failed. rc:%d\n",
3469 rc);
3470 return rc;
3471}
3472
3473static int bnxt_hwrm_tunnel_dst_port_alloc(struct bnxt *bp, __be16 port,
3474 u8 tunnel_type)
3475{
3476 u32 rc = 0;
3477 struct hwrm_tunnel_dst_port_alloc_input req = {0};
3478 struct hwrm_tunnel_dst_port_alloc_output *resp = bp->hwrm_cmd_resp_addr;
3479
3480 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_TUNNEL_DST_PORT_ALLOC, -1, -1);
3481
3482 req.tunnel_type = tunnel_type;
3483 req.tunnel_dst_port_val = port;
3484
3485 mutex_lock(&bp->hwrm_cmd_lock);
3486 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3487 if (rc) {
3488 netdev_err(bp->dev, "hwrm_tunnel_dst_port_alloc failed. rc:%d\n",
3489 rc);
3490 goto err_out;
3491 }
3492
Christophe Jaillet57aac712016-11-22 06:14:40 +01003493 switch (tunnel_type) {
3494 case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_VXLAN:
Michael Chanc0c050c2015-10-22 16:01:17 -04003495 bp->vxlan_fw_dst_port_id = resp->tunnel_dst_port_id;
Christophe Jaillet57aac712016-11-22 06:14:40 +01003496 break;
3497 case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_GENEVE:
Michael Chanc0c050c2015-10-22 16:01:17 -04003498 bp->nge_fw_dst_port_id = resp->tunnel_dst_port_id;
Christophe Jaillet57aac712016-11-22 06:14:40 +01003499 break;
3500 default:
3501 break;
3502 }
3503
Michael Chanc0c050c2015-10-22 16:01:17 -04003504err_out:
3505 mutex_unlock(&bp->hwrm_cmd_lock);
3506 return rc;
3507}
3508
3509static int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt *bp, u16 vnic_id)
3510{
3511 struct hwrm_cfa_l2_set_rx_mask_input req = {0};
3512 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
3513
3514 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_L2_SET_RX_MASK, -1, -1);
Michael Chanc1935542015-12-27 18:19:28 -05003515 req.vnic_id = cpu_to_le32(vnic->fw_vnic_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04003516
3517 req.num_mc_entries = cpu_to_le32(vnic->mc_list_count);
3518 req.mc_tbl_addr = cpu_to_le64(vnic->mc_list_mapping);
3519 req.mask = cpu_to_le32(vnic->rx_mask);
3520 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3521}
3522
3523#ifdef CONFIG_RFS_ACCEL
3524static int bnxt_hwrm_cfa_ntuple_filter_free(struct bnxt *bp,
3525 struct bnxt_ntuple_filter *fltr)
3526{
3527 struct hwrm_cfa_ntuple_filter_free_input req = {0};
3528
3529 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_NTUPLE_FILTER_FREE, -1, -1);
3530 req.ntuple_filter_id = fltr->filter_id;
3531 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3532}
3533
3534#define BNXT_NTP_FLTR_FLAGS \
3535 (CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_L2_FILTER_ID | \
3536 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_ETHERTYPE | \
3537 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_MACADDR | \
3538 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IPADDR_TYPE | \
3539 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR | \
3540 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR_MASK | \
3541 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR | \
3542 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR_MASK | \
3543 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IP_PROTOCOL | \
3544 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT | \
3545 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT_MASK | \
3546 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT | \
3547 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT_MASK | \
Michael Chanc1935542015-12-27 18:19:28 -05003548 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_ID)
Michael Chanc0c050c2015-10-22 16:01:17 -04003549
Michael Chan61aad722017-02-12 19:18:14 -05003550#define BNXT_NTP_TUNNEL_FLTR_FLAG \
3551 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_TUNNEL_TYPE
3552
Michael Chanc0c050c2015-10-22 16:01:17 -04003553static int bnxt_hwrm_cfa_ntuple_filter_alloc(struct bnxt *bp,
3554 struct bnxt_ntuple_filter *fltr)
3555{
3556 int rc = 0;
3557 struct hwrm_cfa_ntuple_filter_alloc_input req = {0};
3558 struct hwrm_cfa_ntuple_filter_alloc_output *resp =
3559 bp->hwrm_cmd_resp_addr;
3560 struct flow_keys *keys = &fltr->fkeys;
3561 struct bnxt_vnic_info *vnic = &bp->vnic_info[fltr->rxq + 1];
3562
3563 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_NTUPLE_FILTER_ALLOC, -1, -1);
Michael Chana54c4d72016-07-25 12:33:35 -04003564 req.l2_filter_id = bp->vnic_info[0].fw_l2_filter_id[fltr->l2_fltr_idx];
Michael Chanc0c050c2015-10-22 16:01:17 -04003565
3566 req.enables = cpu_to_le32(BNXT_NTP_FLTR_FLAGS);
3567
3568 req.ethertype = htons(ETH_P_IP);
3569 memcpy(req.src_macaddr, fltr->src_mac_addr, ETH_ALEN);
Michael Chanc1935542015-12-27 18:19:28 -05003570 req.ip_addr_type = CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV4;
Michael Chanc0c050c2015-10-22 16:01:17 -04003571 req.ip_protocol = keys->basic.ip_proto;
3572
Michael Chandda0e742016-12-29 12:13:40 -05003573 if (keys->basic.n_proto == htons(ETH_P_IPV6)) {
3574 int i;
3575
3576 req.ethertype = htons(ETH_P_IPV6);
3577 req.ip_addr_type =
3578 CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV6;
3579 *(struct in6_addr *)&req.src_ipaddr[0] =
3580 keys->addrs.v6addrs.src;
3581 *(struct in6_addr *)&req.dst_ipaddr[0] =
3582 keys->addrs.v6addrs.dst;
3583 for (i = 0; i < 4; i++) {
3584 req.src_ipaddr_mask[i] = cpu_to_be32(0xffffffff);
3585 req.dst_ipaddr_mask[i] = cpu_to_be32(0xffffffff);
3586 }
3587 } else {
3588 req.src_ipaddr[0] = keys->addrs.v4addrs.src;
3589 req.src_ipaddr_mask[0] = cpu_to_be32(0xffffffff);
3590 req.dst_ipaddr[0] = keys->addrs.v4addrs.dst;
3591 req.dst_ipaddr_mask[0] = cpu_to_be32(0xffffffff);
3592 }
Michael Chan61aad722017-02-12 19:18:14 -05003593 if (keys->control.flags & FLOW_DIS_ENCAPSULATION) {
3594 req.enables |= cpu_to_le32(BNXT_NTP_TUNNEL_FLTR_FLAG);
3595 req.tunnel_type =
3596 CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_ANYTUNNEL;
3597 }
Michael Chanc0c050c2015-10-22 16:01:17 -04003598
3599 req.src_port = keys->ports.src;
3600 req.src_port_mask = cpu_to_be16(0xffff);
3601 req.dst_port = keys->ports.dst;
3602 req.dst_port_mask = cpu_to_be16(0xffff);
3603
Michael Chanc1935542015-12-27 18:19:28 -05003604 req.dst_id = cpu_to_le16(vnic->fw_vnic_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04003605 mutex_lock(&bp->hwrm_cmd_lock);
3606 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3607 if (!rc)
3608 fltr->filter_id = resp->ntuple_filter_id;
3609 mutex_unlock(&bp->hwrm_cmd_lock);
3610 return rc;
3611}
3612#endif
3613
3614static int bnxt_hwrm_set_vnic_filter(struct bnxt *bp, u16 vnic_id, u16 idx,
3615 u8 *mac_addr)
3616{
3617 u32 rc = 0;
3618 struct hwrm_cfa_l2_filter_alloc_input req = {0};
3619 struct hwrm_cfa_l2_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr;
3620
3621 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_L2_FILTER_ALLOC, -1, -1);
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04003622 req.flags = cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_PATH_RX);
3623 if (!BNXT_CHIP_TYPE_NITRO_A0(bp))
3624 req.flags |=
3625 cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_OUTERMOST);
Michael Chanc1935542015-12-27 18:19:28 -05003626 req.dst_id = cpu_to_le16(bp->vnic_info[vnic_id].fw_vnic_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04003627 req.enables =
3628 cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR |
Michael Chanc1935542015-12-27 18:19:28 -05003629 CFA_L2_FILTER_ALLOC_REQ_ENABLES_DST_ID |
Michael Chanc0c050c2015-10-22 16:01:17 -04003630 CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR_MASK);
3631 memcpy(req.l2_addr, mac_addr, ETH_ALEN);
3632 req.l2_addr_mask[0] = 0xff;
3633 req.l2_addr_mask[1] = 0xff;
3634 req.l2_addr_mask[2] = 0xff;
3635 req.l2_addr_mask[3] = 0xff;
3636 req.l2_addr_mask[4] = 0xff;
3637 req.l2_addr_mask[5] = 0xff;
3638
3639 mutex_lock(&bp->hwrm_cmd_lock);
3640 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3641 if (!rc)
3642 bp->vnic_info[vnic_id].fw_l2_filter_id[idx] =
3643 resp->l2_filter_id;
3644 mutex_unlock(&bp->hwrm_cmd_lock);
3645 return rc;
3646}
3647
3648static int bnxt_hwrm_clear_vnic_filter(struct bnxt *bp)
3649{
3650 u16 i, j, num_of_vnics = 1; /* only vnic 0 supported */
3651 int rc = 0;
3652
3653 /* Any associated ntuple filters will also be cleared by firmware. */
3654 mutex_lock(&bp->hwrm_cmd_lock);
3655 for (i = 0; i < num_of_vnics; i++) {
3656 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
3657
3658 for (j = 0; j < vnic->uc_filter_count; j++) {
3659 struct hwrm_cfa_l2_filter_free_input req = {0};
3660
3661 bnxt_hwrm_cmd_hdr_init(bp, &req,
3662 HWRM_CFA_L2_FILTER_FREE, -1, -1);
3663
3664 req.l2_filter_id = vnic->fw_l2_filter_id[j];
3665
3666 rc = _hwrm_send_message(bp, &req, sizeof(req),
3667 HWRM_CMD_TIMEOUT);
3668 }
3669 vnic->uc_filter_count = 0;
3670 }
3671 mutex_unlock(&bp->hwrm_cmd_lock);
3672
3673 return rc;
3674}
3675
3676static int bnxt_hwrm_vnic_set_tpa(struct bnxt *bp, u16 vnic_id, u32 tpa_flags)
3677{
3678 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
3679 struct hwrm_vnic_tpa_cfg_input req = {0};
3680
3681 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_TPA_CFG, -1, -1);
3682
3683 if (tpa_flags) {
3684 u16 mss = bp->dev->mtu - 40;
3685 u32 nsegs, n, segs = 0, flags;
3686
3687 flags = VNIC_TPA_CFG_REQ_FLAGS_TPA |
3688 VNIC_TPA_CFG_REQ_FLAGS_ENCAP_TPA |
3689 VNIC_TPA_CFG_REQ_FLAGS_RSC_WND_UPDATE |
3690 VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_ECN |
3691 VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_SAME_GRE_SEQ;
3692 if (tpa_flags & BNXT_FLAG_GRO)
3693 flags |= VNIC_TPA_CFG_REQ_FLAGS_GRO;
3694
3695 req.flags = cpu_to_le32(flags);
3696
3697 req.enables =
3698 cpu_to_le32(VNIC_TPA_CFG_REQ_ENABLES_MAX_AGG_SEGS |
Michael Chanc1935542015-12-27 18:19:28 -05003699 VNIC_TPA_CFG_REQ_ENABLES_MAX_AGGS |
3700 VNIC_TPA_CFG_REQ_ENABLES_MIN_AGG_LEN);
Michael Chanc0c050c2015-10-22 16:01:17 -04003701
3702 /* Number of segs are log2 units, and first packet is not
3703 * included as part of this units.
3704 */
Michael Chan2839f282016-04-25 02:30:50 -04003705 if (mss <= BNXT_RX_PAGE_SIZE) {
3706 n = BNXT_RX_PAGE_SIZE / mss;
Michael Chanc0c050c2015-10-22 16:01:17 -04003707 nsegs = (MAX_SKB_FRAGS - 1) * n;
3708 } else {
Michael Chan2839f282016-04-25 02:30:50 -04003709 n = mss / BNXT_RX_PAGE_SIZE;
3710 if (mss & (BNXT_RX_PAGE_SIZE - 1))
Michael Chanc0c050c2015-10-22 16:01:17 -04003711 n++;
3712 nsegs = (MAX_SKB_FRAGS - n) / n;
3713 }
3714
3715 segs = ilog2(nsegs);
3716 req.max_agg_segs = cpu_to_le16(segs);
3717 req.max_aggs = cpu_to_le16(VNIC_TPA_CFG_REQ_MAX_AGGS_MAX);
Michael Chanc1935542015-12-27 18:19:28 -05003718
3719 req.min_agg_len = cpu_to_le32(512);
Michael Chanc0c050c2015-10-22 16:01:17 -04003720 }
3721 req.vnic_id = cpu_to_le16(vnic->fw_vnic_id);
3722
3723 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3724}
3725
3726static int bnxt_hwrm_vnic_set_rss(struct bnxt *bp, u16 vnic_id, bool set_rss)
3727{
3728 u32 i, j, max_rings;
3729 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
3730 struct hwrm_vnic_rss_cfg_input req = {0};
3731
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04003732 if (vnic->fw_rss_cos_lb_ctx[0] == INVALID_HW_RING_ID)
Michael Chanc0c050c2015-10-22 16:01:17 -04003733 return 0;
3734
3735 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_CFG, -1, -1);
3736 if (set_rss) {
Michael Chan87da7f72016-11-16 21:13:09 -05003737 req.hash_type = cpu_to_le32(bp->rss_hash_cfg);
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04003738 if (vnic->flags & BNXT_VNIC_RSS_FLAG) {
3739 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
3740 max_rings = bp->rx_nr_rings - 1;
3741 else
3742 max_rings = bp->rx_nr_rings;
3743 } else {
Michael Chanc0c050c2015-10-22 16:01:17 -04003744 max_rings = 1;
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04003745 }
Michael Chanc0c050c2015-10-22 16:01:17 -04003746
3747 /* Fill the RSS indirection table with ring group ids */
3748 for (i = 0, j = 0; i < HW_HASH_INDEX_SIZE; i++, j++) {
3749 if (j == max_rings)
3750 j = 0;
3751 vnic->rss_table[i] = cpu_to_le16(vnic->fw_grp_ids[j]);
3752 }
3753
3754 req.ring_grp_tbl_addr = cpu_to_le64(vnic->rss_table_dma_addr);
3755 req.hash_key_tbl_addr =
3756 cpu_to_le64(vnic->rss_hash_key_dma_addr);
3757 }
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04003758 req.rss_ctx_idx = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[0]);
Michael Chanc0c050c2015-10-22 16:01:17 -04003759 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3760}
3761
3762static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, u16 vnic_id)
3763{
3764 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
3765 struct hwrm_vnic_plcmodes_cfg_input req = {0};
3766
3767 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_PLCMODES_CFG, -1, -1);
3768 req.flags = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT |
3769 VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV4 |
3770 VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6);
3771 req.enables =
3772 cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID |
3773 VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID);
3774 /* thresholds not implemented in firmware yet */
3775 req.jumbo_thresh = cpu_to_le16(bp->rx_copy_thresh);
3776 req.hds_threshold = cpu_to_le16(bp->rx_copy_thresh);
3777 req.vnic_id = cpu_to_le32(vnic->fw_vnic_id);
3778 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3779}
3780
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04003781static void bnxt_hwrm_vnic_ctx_free_one(struct bnxt *bp, u16 vnic_id,
3782 u16 ctx_idx)
Michael Chanc0c050c2015-10-22 16:01:17 -04003783{
3784 struct hwrm_vnic_rss_cos_lb_ctx_free_input req = {0};
3785
3786 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_COS_LB_CTX_FREE, -1, -1);
3787 req.rss_cos_lb_ctx_id =
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04003788 cpu_to_le16(bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx]);
Michael Chanc0c050c2015-10-22 16:01:17 -04003789
3790 hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04003791 bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx] = INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04003792}
3793
3794static void bnxt_hwrm_vnic_ctx_free(struct bnxt *bp)
3795{
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04003796 int i, j;
Michael Chanc0c050c2015-10-22 16:01:17 -04003797
3798 for (i = 0; i < bp->nr_vnics; i++) {
3799 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
3800
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04003801 for (j = 0; j < BNXT_MAX_CTX_PER_VNIC; j++) {
3802 if (vnic->fw_rss_cos_lb_ctx[j] != INVALID_HW_RING_ID)
3803 bnxt_hwrm_vnic_ctx_free_one(bp, i, j);
3804 }
Michael Chanc0c050c2015-10-22 16:01:17 -04003805 }
3806 bp->rsscos_nr_ctxs = 0;
3807}
3808
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04003809static int bnxt_hwrm_vnic_ctx_alloc(struct bnxt *bp, u16 vnic_id, u16 ctx_idx)
Michael Chanc0c050c2015-10-22 16:01:17 -04003810{
3811 int rc;
3812 struct hwrm_vnic_rss_cos_lb_ctx_alloc_input req = {0};
3813 struct hwrm_vnic_rss_cos_lb_ctx_alloc_output *resp =
3814 bp->hwrm_cmd_resp_addr;
3815
3816 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_COS_LB_CTX_ALLOC, -1,
3817 -1);
3818
3819 mutex_lock(&bp->hwrm_cmd_lock);
3820 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3821 if (!rc)
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04003822 bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx] =
Michael Chanc0c050c2015-10-22 16:01:17 -04003823 le16_to_cpu(resp->rss_cos_lb_ctx_id);
3824 mutex_unlock(&bp->hwrm_cmd_lock);
3825
3826 return rc;
3827}
3828
Michael Chana588e452016-12-07 00:26:21 -05003829int bnxt_hwrm_vnic_cfg(struct bnxt *bp, u16 vnic_id)
Michael Chanc0c050c2015-10-22 16:01:17 -04003830{
Michael Chanb81a90d2016-01-02 23:45:01 -05003831 unsigned int ring = 0, grp_idx;
Michael Chanc0c050c2015-10-22 16:01:17 -04003832 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
3833 struct hwrm_vnic_cfg_input req = {0};
Michael Chancf6645f2016-06-13 02:25:28 -04003834 u16 def_vlan = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04003835
3836 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_CFG, -1, -1);
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04003837
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04003838 req.enables = cpu_to_le32(VNIC_CFG_REQ_ENABLES_DFLT_RING_GRP);
3839 /* Only RSS support for now TBD: COS & LB */
3840 if (vnic->fw_rss_cos_lb_ctx[0] != INVALID_HW_RING_ID) {
3841 req.rss_rule = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[0]);
3842 req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE |
3843 VNIC_CFG_REQ_ENABLES_MRU);
Michael Chanae10ae72016-12-29 12:13:38 -05003844 } else if (vnic->flags & BNXT_VNIC_RFS_NEW_RSS_FLAG) {
3845 req.rss_rule =
3846 cpu_to_le16(bp->vnic_info[0].fw_rss_cos_lb_ctx[0]);
3847 req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE |
3848 VNIC_CFG_REQ_ENABLES_MRU);
3849 req.flags |= cpu_to_le32(VNIC_CFG_REQ_FLAGS_RSS_DFLT_CR_MODE);
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04003850 } else {
3851 req.rss_rule = cpu_to_le16(0xffff);
3852 }
3853
3854 if (BNXT_CHIP_TYPE_NITRO_A0(bp) &&
3855 (vnic->fw_rss_cos_lb_ctx[0] != INVALID_HW_RING_ID)) {
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04003856 req.cos_rule = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[1]);
3857 req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_COS_RULE);
3858 } else {
3859 req.cos_rule = cpu_to_le16(0xffff);
3860 }
3861
Michael Chanc0c050c2015-10-22 16:01:17 -04003862 if (vnic->flags & BNXT_VNIC_RSS_FLAG)
Michael Chanb81a90d2016-01-02 23:45:01 -05003863 ring = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04003864 else if (vnic->flags & BNXT_VNIC_RFS_FLAG)
Michael Chanb81a90d2016-01-02 23:45:01 -05003865 ring = vnic_id - 1;
Prashant Sreedharan76595192016-07-18 07:15:22 -04003866 else if ((vnic_id == 1) && BNXT_CHIP_TYPE_NITRO_A0(bp))
3867 ring = bp->rx_nr_rings - 1;
Michael Chanc0c050c2015-10-22 16:01:17 -04003868
Michael Chanb81a90d2016-01-02 23:45:01 -05003869 grp_idx = bp->rx_ring[ring].bnapi->index;
Michael Chanc0c050c2015-10-22 16:01:17 -04003870 req.vnic_id = cpu_to_le16(vnic->fw_vnic_id);
3871 req.dflt_ring_grp = cpu_to_le16(bp->grp_info[grp_idx].fw_grp_id);
3872
3873 req.lb_rule = cpu_to_le16(0xffff);
3874 req.mru = cpu_to_le16(bp->dev->mtu + ETH_HLEN + ETH_FCS_LEN +
3875 VLAN_HLEN);
3876
Michael Chancf6645f2016-06-13 02:25:28 -04003877#ifdef CONFIG_BNXT_SRIOV
3878 if (BNXT_VF(bp))
3879 def_vlan = bp->vf.vlan;
3880#endif
3881 if ((bp->flags & BNXT_FLAG_STRIP_VLAN) || def_vlan)
Michael Chanc0c050c2015-10-22 16:01:17 -04003882 req.flags |= cpu_to_le32(VNIC_CFG_REQ_FLAGS_VLAN_STRIP_MODE);
Michael Chana588e452016-12-07 00:26:21 -05003883 if (!vnic_id && bnxt_ulp_registered(bp->edev, BNXT_ROCE_ULP))
3884 req.flags |=
3885 cpu_to_le32(VNIC_CFG_REQ_FLAGS_ROCE_DUAL_VNIC_MODE);
Michael Chanc0c050c2015-10-22 16:01:17 -04003886
3887 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3888}
3889
3890static int bnxt_hwrm_vnic_free_one(struct bnxt *bp, u16 vnic_id)
3891{
3892 u32 rc = 0;
3893
3894 if (bp->vnic_info[vnic_id].fw_vnic_id != INVALID_HW_RING_ID) {
3895 struct hwrm_vnic_free_input req = {0};
3896
3897 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_FREE, -1, -1);
3898 req.vnic_id =
3899 cpu_to_le32(bp->vnic_info[vnic_id].fw_vnic_id);
3900
3901 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3902 if (rc)
3903 return rc;
3904 bp->vnic_info[vnic_id].fw_vnic_id = INVALID_HW_RING_ID;
3905 }
3906 return rc;
3907}
3908
3909static void bnxt_hwrm_vnic_free(struct bnxt *bp)
3910{
3911 u16 i;
3912
3913 for (i = 0; i < bp->nr_vnics; i++)
3914 bnxt_hwrm_vnic_free_one(bp, i);
3915}
3916
Michael Chanb81a90d2016-01-02 23:45:01 -05003917static int bnxt_hwrm_vnic_alloc(struct bnxt *bp, u16 vnic_id,
3918 unsigned int start_rx_ring_idx,
3919 unsigned int nr_rings)
Michael Chanc0c050c2015-10-22 16:01:17 -04003920{
Michael Chanb81a90d2016-01-02 23:45:01 -05003921 int rc = 0;
3922 unsigned int i, j, grp_idx, end_idx = start_rx_ring_idx + nr_rings;
Michael Chanc0c050c2015-10-22 16:01:17 -04003923 struct hwrm_vnic_alloc_input req = {0};
3924 struct hwrm_vnic_alloc_output *resp = bp->hwrm_cmd_resp_addr;
3925
3926 /* map ring groups to this vnic */
Michael Chanb81a90d2016-01-02 23:45:01 -05003927 for (i = start_rx_ring_idx, j = 0; i < end_idx; i++, j++) {
3928 grp_idx = bp->rx_ring[i].bnapi->index;
3929 if (bp->grp_info[grp_idx].fw_grp_id == INVALID_HW_RING_ID) {
Michael Chanc0c050c2015-10-22 16:01:17 -04003930 netdev_err(bp->dev, "Not enough ring groups avail:%x req:%x\n",
Michael Chanb81a90d2016-01-02 23:45:01 -05003931 j, nr_rings);
Michael Chanc0c050c2015-10-22 16:01:17 -04003932 break;
3933 }
3934 bp->vnic_info[vnic_id].fw_grp_ids[j] =
Michael Chanb81a90d2016-01-02 23:45:01 -05003935 bp->grp_info[grp_idx].fw_grp_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04003936 }
3937
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04003938 bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[0] = INVALID_HW_RING_ID;
3939 bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[1] = INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04003940 if (vnic_id == 0)
3941 req.flags = cpu_to_le32(VNIC_ALLOC_REQ_FLAGS_DEFAULT);
3942
3943 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_ALLOC, -1, -1);
3944
3945 mutex_lock(&bp->hwrm_cmd_lock);
3946 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3947 if (!rc)
3948 bp->vnic_info[vnic_id].fw_vnic_id = le32_to_cpu(resp->vnic_id);
3949 mutex_unlock(&bp->hwrm_cmd_lock);
3950 return rc;
3951}
3952
Michael Chan8fdefd62016-12-29 12:13:36 -05003953static int bnxt_hwrm_vnic_qcaps(struct bnxt *bp)
3954{
3955 struct hwrm_vnic_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
3956 struct hwrm_vnic_qcaps_input req = {0};
3957 int rc;
3958
3959 if (bp->hwrm_spec_code < 0x10600)
3960 return 0;
3961
3962 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_QCAPS, -1, -1);
3963 mutex_lock(&bp->hwrm_cmd_lock);
3964 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3965 if (!rc) {
3966 if (resp->flags &
3967 cpu_to_le32(VNIC_QCAPS_RESP_FLAGS_RSS_DFLT_CR_CAP))
3968 bp->flags |= BNXT_FLAG_NEW_RSS_CAP;
3969 }
3970 mutex_unlock(&bp->hwrm_cmd_lock);
3971 return rc;
3972}
3973
Michael Chanc0c050c2015-10-22 16:01:17 -04003974static int bnxt_hwrm_ring_grp_alloc(struct bnxt *bp)
3975{
3976 u16 i;
3977 u32 rc = 0;
3978
3979 mutex_lock(&bp->hwrm_cmd_lock);
3980 for (i = 0; i < bp->rx_nr_rings; i++) {
3981 struct hwrm_ring_grp_alloc_input req = {0};
3982 struct hwrm_ring_grp_alloc_output *resp =
3983 bp->hwrm_cmd_resp_addr;
Michael Chanb81a90d2016-01-02 23:45:01 -05003984 unsigned int grp_idx = bp->rx_ring[i].bnapi->index;
Michael Chanc0c050c2015-10-22 16:01:17 -04003985
3986 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_GRP_ALLOC, -1, -1);
3987
Michael Chanb81a90d2016-01-02 23:45:01 -05003988 req.cr = cpu_to_le16(bp->grp_info[grp_idx].cp_fw_ring_id);
3989 req.rr = cpu_to_le16(bp->grp_info[grp_idx].rx_fw_ring_id);
3990 req.ar = cpu_to_le16(bp->grp_info[grp_idx].agg_fw_ring_id);
3991 req.sc = cpu_to_le16(bp->grp_info[grp_idx].fw_stats_ctx);
Michael Chanc0c050c2015-10-22 16:01:17 -04003992
3993 rc = _hwrm_send_message(bp, &req, sizeof(req),
3994 HWRM_CMD_TIMEOUT);
3995 if (rc)
3996 break;
3997
Michael Chanb81a90d2016-01-02 23:45:01 -05003998 bp->grp_info[grp_idx].fw_grp_id =
3999 le32_to_cpu(resp->ring_group_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04004000 }
4001 mutex_unlock(&bp->hwrm_cmd_lock);
4002 return rc;
4003}
4004
4005static int bnxt_hwrm_ring_grp_free(struct bnxt *bp)
4006{
4007 u16 i;
4008 u32 rc = 0;
4009 struct hwrm_ring_grp_free_input req = {0};
4010
4011 if (!bp->grp_info)
4012 return 0;
4013
4014 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_GRP_FREE, -1, -1);
4015
4016 mutex_lock(&bp->hwrm_cmd_lock);
4017 for (i = 0; i < bp->cp_nr_rings; i++) {
4018 if (bp->grp_info[i].fw_grp_id == INVALID_HW_RING_ID)
4019 continue;
4020 req.ring_group_id =
4021 cpu_to_le32(bp->grp_info[i].fw_grp_id);
4022
4023 rc = _hwrm_send_message(bp, &req, sizeof(req),
4024 HWRM_CMD_TIMEOUT);
4025 if (rc)
4026 break;
4027 bp->grp_info[i].fw_grp_id = INVALID_HW_RING_ID;
4028 }
4029 mutex_unlock(&bp->hwrm_cmd_lock);
4030 return rc;
4031}
4032
4033static int hwrm_ring_alloc_send_msg(struct bnxt *bp,
4034 struct bnxt_ring_struct *ring,
4035 u32 ring_type, u32 map_index,
4036 u32 stats_ctx_id)
4037{
4038 int rc = 0, err = 0;
4039 struct hwrm_ring_alloc_input req = {0};
4040 struct hwrm_ring_alloc_output *resp = bp->hwrm_cmd_resp_addr;
4041 u16 ring_id;
4042
4043 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_ALLOC, -1, -1);
4044
4045 req.enables = 0;
4046 if (ring->nr_pages > 1) {
4047 req.page_tbl_addr = cpu_to_le64(ring->pg_tbl_map);
4048 /* Page size is in log2 units */
4049 req.page_size = BNXT_PAGE_SHIFT;
4050 req.page_tbl_depth = 1;
4051 } else {
4052 req.page_tbl_addr = cpu_to_le64(ring->dma_arr[0]);
4053 }
4054 req.fbo = 0;
4055 /* Association of ring index with doorbell index and MSIX number */
4056 req.logical_id = cpu_to_le16(map_index);
4057
4058 switch (ring_type) {
4059 case HWRM_RING_ALLOC_TX:
4060 req.ring_type = RING_ALLOC_REQ_RING_TYPE_TX;
4061 /* Association of transmit ring with completion ring */
4062 req.cmpl_ring_id =
4063 cpu_to_le16(bp->grp_info[map_index].cp_fw_ring_id);
4064 req.length = cpu_to_le32(bp->tx_ring_mask + 1);
4065 req.stat_ctx_id = cpu_to_le32(stats_ctx_id);
4066 req.queue_id = cpu_to_le16(ring->queue_id);
4067 break;
4068 case HWRM_RING_ALLOC_RX:
4069 req.ring_type = RING_ALLOC_REQ_RING_TYPE_RX;
4070 req.length = cpu_to_le32(bp->rx_ring_mask + 1);
4071 break;
4072 case HWRM_RING_ALLOC_AGG:
4073 req.ring_type = RING_ALLOC_REQ_RING_TYPE_RX;
4074 req.length = cpu_to_le32(bp->rx_agg_ring_mask + 1);
4075 break;
4076 case HWRM_RING_ALLOC_CMPL:
Michael Chanbac9a7e2017-02-12 19:18:10 -05004077 req.ring_type = RING_ALLOC_REQ_RING_TYPE_L2_CMPL;
Michael Chanc0c050c2015-10-22 16:01:17 -04004078 req.length = cpu_to_le32(bp->cp_ring_mask + 1);
4079 if (bp->flags & BNXT_FLAG_USING_MSIX)
4080 req.int_mode = RING_ALLOC_REQ_INT_MODE_MSIX;
4081 break;
4082 default:
4083 netdev_err(bp->dev, "hwrm alloc invalid ring type %d\n",
4084 ring_type);
4085 return -1;
4086 }
4087
4088 mutex_lock(&bp->hwrm_cmd_lock);
4089 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4090 err = le16_to_cpu(resp->error_code);
4091 ring_id = le16_to_cpu(resp->ring_id);
4092 mutex_unlock(&bp->hwrm_cmd_lock);
4093
4094 if (rc || err) {
4095 switch (ring_type) {
Michael Chanbac9a7e2017-02-12 19:18:10 -05004096 case RING_FREE_REQ_RING_TYPE_L2_CMPL:
Michael Chanc0c050c2015-10-22 16:01:17 -04004097 netdev_err(bp->dev, "hwrm_ring_alloc cp failed. rc:%x err:%x\n",
4098 rc, err);
4099 return -1;
4100
4101 case RING_FREE_REQ_RING_TYPE_RX:
4102 netdev_err(bp->dev, "hwrm_ring_alloc rx failed. rc:%x err:%x\n",
4103 rc, err);
4104 return -1;
4105
4106 case RING_FREE_REQ_RING_TYPE_TX:
4107 netdev_err(bp->dev, "hwrm_ring_alloc tx failed. rc:%x err:%x\n",
4108 rc, err);
4109 return -1;
4110
4111 default:
4112 netdev_err(bp->dev, "Invalid ring\n");
4113 return -1;
4114 }
4115 }
4116 ring->fw_ring_id = ring_id;
4117 return rc;
4118}
4119
Michael Chan486b5c22016-12-29 12:13:42 -05004120static int bnxt_hwrm_set_async_event_cr(struct bnxt *bp, int idx)
4121{
4122 int rc;
4123
4124 if (BNXT_PF(bp)) {
4125 struct hwrm_func_cfg_input req = {0};
4126
4127 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1);
4128 req.fid = cpu_to_le16(0xffff);
4129 req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_ASYNC_EVENT_CR);
4130 req.async_event_cr = cpu_to_le16(idx);
4131 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4132 } else {
4133 struct hwrm_func_vf_cfg_input req = {0};
4134
4135 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_VF_CFG, -1, -1);
4136 req.enables =
4137 cpu_to_le32(FUNC_VF_CFG_REQ_ENABLES_ASYNC_EVENT_CR);
4138 req.async_event_cr = cpu_to_le16(idx);
4139 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4140 }
4141 return rc;
4142}
4143
Michael Chanc0c050c2015-10-22 16:01:17 -04004144static int bnxt_hwrm_ring_alloc(struct bnxt *bp)
4145{
4146 int i, rc = 0;
4147
Michael Chanedd0c2c2015-12-27 18:19:19 -05004148 for (i = 0; i < bp->cp_nr_rings; i++) {
4149 struct bnxt_napi *bnapi = bp->bnapi[i];
4150 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
4151 struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
Michael Chanc0c050c2015-10-22 16:01:17 -04004152
Prashant Sreedharan33e52d82016-03-28 19:46:04 -04004153 cpr->cp_doorbell = bp->bar1 + i * 0x80;
Michael Chanedd0c2c2015-12-27 18:19:19 -05004154 rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_CMPL, i,
4155 INVALID_STATS_CTX_ID);
4156 if (rc)
4157 goto err_out;
Michael Chanedd0c2c2015-12-27 18:19:19 -05004158 BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
4159 bp->grp_info[i].cp_fw_ring_id = ring->fw_ring_id;
Michael Chan486b5c22016-12-29 12:13:42 -05004160
4161 if (!i) {
4162 rc = bnxt_hwrm_set_async_event_cr(bp, ring->fw_ring_id);
4163 if (rc)
4164 netdev_warn(bp->dev, "Failed to set async event completion ring.\n");
4165 }
Michael Chanc0c050c2015-10-22 16:01:17 -04004166 }
4167
Michael Chanedd0c2c2015-12-27 18:19:19 -05004168 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05004169 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
Michael Chanedd0c2c2015-12-27 18:19:19 -05004170 struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
Michael Chanb81a90d2016-01-02 23:45:01 -05004171 u32 map_idx = txr->bnapi->index;
4172 u16 fw_stats_ctx = bp->grp_info[map_idx].fw_stats_ctx;
Michael Chanc0c050c2015-10-22 16:01:17 -04004173
Michael Chanb81a90d2016-01-02 23:45:01 -05004174 rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_TX,
4175 map_idx, fw_stats_ctx);
Michael Chanedd0c2c2015-12-27 18:19:19 -05004176 if (rc)
4177 goto err_out;
Michael Chanb81a90d2016-01-02 23:45:01 -05004178 txr->tx_doorbell = bp->bar1 + map_idx * 0x80;
Michael Chanc0c050c2015-10-22 16:01:17 -04004179 }
4180
Michael Chanedd0c2c2015-12-27 18:19:19 -05004181 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05004182 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
Michael Chanedd0c2c2015-12-27 18:19:19 -05004183 struct bnxt_ring_struct *ring = &rxr->rx_ring_struct;
Michael Chanb81a90d2016-01-02 23:45:01 -05004184 u32 map_idx = rxr->bnapi->index;
Michael Chanc0c050c2015-10-22 16:01:17 -04004185
Michael Chanb81a90d2016-01-02 23:45:01 -05004186 rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_RX,
4187 map_idx, INVALID_STATS_CTX_ID);
Michael Chanedd0c2c2015-12-27 18:19:19 -05004188 if (rc)
4189 goto err_out;
Michael Chanb81a90d2016-01-02 23:45:01 -05004190 rxr->rx_doorbell = bp->bar1 + map_idx * 0x80;
Michael Chanedd0c2c2015-12-27 18:19:19 -05004191 writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell);
Michael Chanb81a90d2016-01-02 23:45:01 -05004192 bp->grp_info[map_idx].rx_fw_ring_id = ring->fw_ring_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04004193 }
4194
4195 if (bp->flags & BNXT_FLAG_AGG_RINGS) {
4196 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05004197 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04004198 struct bnxt_ring_struct *ring =
4199 &rxr->rx_agg_ring_struct;
Michael Chanb81a90d2016-01-02 23:45:01 -05004200 u32 grp_idx = rxr->bnapi->index;
4201 u32 map_idx = grp_idx + bp->rx_nr_rings;
Michael Chanc0c050c2015-10-22 16:01:17 -04004202
4203 rc = hwrm_ring_alloc_send_msg(bp, ring,
4204 HWRM_RING_ALLOC_AGG,
Michael Chanb81a90d2016-01-02 23:45:01 -05004205 map_idx,
Michael Chanc0c050c2015-10-22 16:01:17 -04004206 INVALID_STATS_CTX_ID);
4207 if (rc)
4208 goto err_out;
4209
Michael Chanb81a90d2016-01-02 23:45:01 -05004210 rxr->rx_agg_doorbell = bp->bar1 + map_idx * 0x80;
Michael Chanc0c050c2015-10-22 16:01:17 -04004211 writel(DB_KEY_RX | rxr->rx_agg_prod,
4212 rxr->rx_agg_doorbell);
Michael Chanb81a90d2016-01-02 23:45:01 -05004213 bp->grp_info[grp_idx].agg_fw_ring_id = ring->fw_ring_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04004214 }
4215 }
4216err_out:
4217 return rc;
4218}
4219
4220static int hwrm_ring_free_send_msg(struct bnxt *bp,
4221 struct bnxt_ring_struct *ring,
4222 u32 ring_type, int cmpl_ring_id)
4223{
4224 int rc;
4225 struct hwrm_ring_free_input req = {0};
4226 struct hwrm_ring_free_output *resp = bp->hwrm_cmd_resp_addr;
4227 u16 error_code;
4228
Prashant Sreedharan74608fc2016-01-28 03:11:20 -05004229 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_FREE, cmpl_ring_id, -1);
Michael Chanc0c050c2015-10-22 16:01:17 -04004230 req.ring_type = ring_type;
4231 req.ring_id = cpu_to_le16(ring->fw_ring_id);
4232
4233 mutex_lock(&bp->hwrm_cmd_lock);
4234 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4235 error_code = le16_to_cpu(resp->error_code);
4236 mutex_unlock(&bp->hwrm_cmd_lock);
4237
4238 if (rc || error_code) {
4239 switch (ring_type) {
Michael Chanbac9a7e2017-02-12 19:18:10 -05004240 case RING_FREE_REQ_RING_TYPE_L2_CMPL:
Michael Chanc0c050c2015-10-22 16:01:17 -04004241 netdev_err(bp->dev, "hwrm_ring_free cp failed. rc:%d\n",
4242 rc);
4243 return rc;
4244 case RING_FREE_REQ_RING_TYPE_RX:
4245 netdev_err(bp->dev, "hwrm_ring_free rx failed. rc:%d\n",
4246 rc);
4247 return rc;
4248 case RING_FREE_REQ_RING_TYPE_TX:
4249 netdev_err(bp->dev, "hwrm_ring_free tx failed. rc:%d\n",
4250 rc);
4251 return rc;
4252 default:
4253 netdev_err(bp->dev, "Invalid ring\n");
4254 return -1;
4255 }
4256 }
4257 return 0;
4258}
4259
Michael Chanedd0c2c2015-12-27 18:19:19 -05004260static void bnxt_hwrm_ring_free(struct bnxt *bp, bool close_path)
Michael Chanc0c050c2015-10-22 16:01:17 -04004261{
Michael Chanedd0c2c2015-12-27 18:19:19 -05004262 int i;
Michael Chanc0c050c2015-10-22 16:01:17 -04004263
4264 if (!bp->bnapi)
Michael Chanedd0c2c2015-12-27 18:19:19 -05004265 return;
Michael Chanc0c050c2015-10-22 16:01:17 -04004266
Michael Chanedd0c2c2015-12-27 18:19:19 -05004267 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05004268 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
Michael Chanedd0c2c2015-12-27 18:19:19 -05004269 struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
Michael Chanb81a90d2016-01-02 23:45:01 -05004270 u32 grp_idx = txr->bnapi->index;
4271 u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04004272
Michael Chanedd0c2c2015-12-27 18:19:19 -05004273 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
4274 hwrm_ring_free_send_msg(bp, ring,
4275 RING_FREE_REQ_RING_TYPE_TX,
4276 close_path ? cmpl_ring_id :
4277 INVALID_HW_RING_ID);
4278 ring->fw_ring_id = INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04004279 }
4280 }
4281
Michael Chanedd0c2c2015-12-27 18:19:19 -05004282 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05004283 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
Michael Chanedd0c2c2015-12-27 18:19:19 -05004284 struct bnxt_ring_struct *ring = &rxr->rx_ring_struct;
Michael Chanb81a90d2016-01-02 23:45:01 -05004285 u32 grp_idx = rxr->bnapi->index;
4286 u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04004287
Michael Chanedd0c2c2015-12-27 18:19:19 -05004288 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
4289 hwrm_ring_free_send_msg(bp, ring,
4290 RING_FREE_REQ_RING_TYPE_RX,
4291 close_path ? cmpl_ring_id :
4292 INVALID_HW_RING_ID);
4293 ring->fw_ring_id = INVALID_HW_RING_ID;
Michael Chanb81a90d2016-01-02 23:45:01 -05004294 bp->grp_info[grp_idx].rx_fw_ring_id =
4295 INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04004296 }
4297 }
4298
Michael Chanedd0c2c2015-12-27 18:19:19 -05004299 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05004300 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
Michael Chanedd0c2c2015-12-27 18:19:19 -05004301 struct bnxt_ring_struct *ring = &rxr->rx_agg_ring_struct;
Michael Chanb81a90d2016-01-02 23:45:01 -05004302 u32 grp_idx = rxr->bnapi->index;
4303 u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04004304
Michael Chanedd0c2c2015-12-27 18:19:19 -05004305 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
4306 hwrm_ring_free_send_msg(bp, ring,
4307 RING_FREE_REQ_RING_TYPE_RX,
4308 close_path ? cmpl_ring_id :
4309 INVALID_HW_RING_ID);
4310 ring->fw_ring_id = INVALID_HW_RING_ID;
Michael Chanb81a90d2016-01-02 23:45:01 -05004311 bp->grp_info[grp_idx].agg_fw_ring_id =
4312 INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04004313 }
4314 }
4315
Michael Chan9d8bc092016-12-29 12:13:33 -05004316 /* The completion rings are about to be freed. After that the
4317 * IRQ doorbell will not work anymore. So we need to disable
4318 * IRQ here.
4319 */
4320 bnxt_disable_int_sync(bp);
4321
Michael Chanedd0c2c2015-12-27 18:19:19 -05004322 for (i = 0; i < bp->cp_nr_rings; i++) {
4323 struct bnxt_napi *bnapi = bp->bnapi[i];
4324 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
4325 struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
Michael Chanc0c050c2015-10-22 16:01:17 -04004326
Michael Chanedd0c2c2015-12-27 18:19:19 -05004327 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
4328 hwrm_ring_free_send_msg(bp, ring,
Michael Chanbac9a7e2017-02-12 19:18:10 -05004329 RING_FREE_REQ_RING_TYPE_L2_CMPL,
Michael Chanedd0c2c2015-12-27 18:19:19 -05004330 INVALID_HW_RING_ID);
4331 ring->fw_ring_id = INVALID_HW_RING_ID;
4332 bp->grp_info[i].cp_fw_ring_id = INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04004333 }
4334 }
Michael Chanc0c050c2015-10-22 16:01:17 -04004335}
4336
Michael Chan391be5c2016-12-29 12:13:41 -05004337/* Caller must hold bp->hwrm_cmd_lock */
4338int __bnxt_hwrm_get_tx_rings(struct bnxt *bp, u16 fid, int *tx_rings)
4339{
4340 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
4341 struct hwrm_func_qcfg_input req = {0};
4342 int rc;
4343
4344 if (bp->hwrm_spec_code < 0x10601)
4345 return 0;
4346
4347 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCFG, -1, -1);
4348 req.fid = cpu_to_le16(fid);
4349 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4350 if (!rc)
4351 *tx_rings = le16_to_cpu(resp->alloc_tx_rings);
4352
4353 return rc;
4354}
4355
Michael Chand1e79252017-02-06 16:55:38 -05004356static int bnxt_hwrm_reserve_tx_rings(struct bnxt *bp, int *tx_rings)
Michael Chan391be5c2016-12-29 12:13:41 -05004357{
4358 struct hwrm_func_cfg_input req = {0};
4359 int rc;
4360
4361 if (bp->hwrm_spec_code < 0x10601)
4362 return 0;
4363
4364 if (BNXT_VF(bp))
4365 return 0;
4366
4367 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1);
4368 req.fid = cpu_to_le16(0xffff);
4369 req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_NUM_TX_RINGS);
4370 req.num_tx_rings = cpu_to_le16(*tx_rings);
4371 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4372 if (rc)
4373 return rc;
4374
4375 mutex_lock(&bp->hwrm_cmd_lock);
4376 rc = __bnxt_hwrm_get_tx_rings(bp, 0xffff, tx_rings);
4377 mutex_unlock(&bp->hwrm_cmd_lock);
4378 return rc;
4379}
4380
Michael Chanbb053f52016-02-26 04:00:02 -05004381static void bnxt_hwrm_set_coal_params(struct bnxt *bp, u32 max_bufs,
4382 u32 buf_tmrs, u16 flags,
4383 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *req)
4384{
4385 req->flags = cpu_to_le16(flags);
4386 req->num_cmpl_dma_aggr = cpu_to_le16((u16)max_bufs);
4387 req->num_cmpl_dma_aggr_during_int = cpu_to_le16(max_bufs >> 16);
4388 req->cmpl_aggr_dma_tmr = cpu_to_le16((u16)buf_tmrs);
4389 req->cmpl_aggr_dma_tmr_during_int = cpu_to_le16(buf_tmrs >> 16);
4390 /* Minimum time between 2 interrupts set to buf_tmr x 2 */
4391 req->int_lat_tmr_min = cpu_to_le16((u16)buf_tmrs * 2);
4392 req->int_lat_tmr_max = cpu_to_le16((u16)buf_tmrs * 4);
4393 req->num_cmpl_aggr_int = cpu_to_le16((u16)max_bufs * 4);
4394}
4395
Michael Chanc0c050c2015-10-22 16:01:17 -04004396int bnxt_hwrm_set_coal(struct bnxt *bp)
4397{
4398 int i, rc = 0;
Michael Chandfc9c942016-02-26 04:00:03 -05004399 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req_rx = {0},
4400 req_tx = {0}, *req;
Michael Chanc0c050c2015-10-22 16:01:17 -04004401 u16 max_buf, max_buf_irq;
4402 u16 buf_tmr, buf_tmr_irq;
4403 u32 flags;
4404
Michael Chandfc9c942016-02-26 04:00:03 -05004405 bnxt_hwrm_cmd_hdr_init(bp, &req_rx,
4406 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1);
4407 bnxt_hwrm_cmd_hdr_init(bp, &req_tx,
4408 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1);
Michael Chanc0c050c2015-10-22 16:01:17 -04004409
Michael Chandfb5b892016-02-26 04:00:01 -05004410 /* Each rx completion (2 records) should be DMAed immediately.
4411 * DMA 1/4 of the completion buffers at a time.
4412 */
4413 max_buf = min_t(u16, bp->rx_coal_bufs / 4, 2);
Michael Chanc0c050c2015-10-22 16:01:17 -04004414 /* max_buf must not be zero */
4415 max_buf = clamp_t(u16, max_buf, 1, 63);
Michael Chandfb5b892016-02-26 04:00:01 -05004416 max_buf_irq = clamp_t(u16, bp->rx_coal_bufs_irq, 1, 63);
4417 buf_tmr = BNXT_USEC_TO_COAL_TIMER(bp->rx_coal_ticks);
4418 /* buf timer set to 1/4 of interrupt timer */
4419 buf_tmr = max_t(u16, buf_tmr / 4, 1);
4420 buf_tmr_irq = BNXT_USEC_TO_COAL_TIMER(bp->rx_coal_ticks_irq);
4421 buf_tmr_irq = max_t(u16, buf_tmr_irq, 1);
Michael Chanc0c050c2015-10-22 16:01:17 -04004422
4423 flags = RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_TIMER_RESET;
4424
4425 /* RING_IDLE generates more IRQs for lower latency. Enable it only
4426 * if coal_ticks is less than 25 us.
4427 */
Michael Chandfb5b892016-02-26 04:00:01 -05004428 if (bp->rx_coal_ticks < 25)
Michael Chanc0c050c2015-10-22 16:01:17 -04004429 flags |= RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_RING_IDLE;
4430
Michael Chanbb053f52016-02-26 04:00:02 -05004431 bnxt_hwrm_set_coal_params(bp, max_buf_irq << 16 | max_buf,
Michael Chandfc9c942016-02-26 04:00:03 -05004432 buf_tmr_irq << 16 | buf_tmr, flags, &req_rx);
4433
4434 /* max_buf must not be zero */
4435 max_buf = clamp_t(u16, bp->tx_coal_bufs, 1, 63);
4436 max_buf_irq = clamp_t(u16, bp->tx_coal_bufs_irq, 1, 63);
4437 buf_tmr = BNXT_USEC_TO_COAL_TIMER(bp->tx_coal_ticks);
4438 /* buf timer set to 1/4 of interrupt timer */
4439 buf_tmr = max_t(u16, buf_tmr / 4, 1);
4440 buf_tmr_irq = BNXT_USEC_TO_COAL_TIMER(bp->tx_coal_ticks_irq);
4441 buf_tmr_irq = max_t(u16, buf_tmr_irq, 1);
4442
4443 flags = RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_TIMER_RESET;
4444 bnxt_hwrm_set_coal_params(bp, max_buf_irq << 16 | max_buf,
4445 buf_tmr_irq << 16 | buf_tmr, flags, &req_tx);
Michael Chanc0c050c2015-10-22 16:01:17 -04004446
4447 mutex_lock(&bp->hwrm_cmd_lock);
4448 for (i = 0; i < bp->cp_nr_rings; i++) {
Michael Chandfc9c942016-02-26 04:00:03 -05004449 struct bnxt_napi *bnapi = bp->bnapi[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04004450
Michael Chandfc9c942016-02-26 04:00:03 -05004451 req = &req_rx;
4452 if (!bnapi->rx_ring)
4453 req = &req_tx;
4454 req->ring_id = cpu_to_le16(bp->grp_info[i].cp_fw_ring_id);
4455
4456 rc = _hwrm_send_message(bp, req, sizeof(*req),
Michael Chanc0c050c2015-10-22 16:01:17 -04004457 HWRM_CMD_TIMEOUT);
4458 if (rc)
4459 break;
4460 }
4461 mutex_unlock(&bp->hwrm_cmd_lock);
4462 return rc;
4463}
4464
4465static int bnxt_hwrm_stat_ctx_free(struct bnxt *bp)
4466{
4467 int rc = 0, i;
4468 struct hwrm_stat_ctx_free_input req = {0};
4469
4470 if (!bp->bnapi)
4471 return 0;
4472
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04004473 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
4474 return 0;
4475
Michael Chanc0c050c2015-10-22 16:01:17 -04004476 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_STAT_CTX_FREE, -1, -1);
4477
4478 mutex_lock(&bp->hwrm_cmd_lock);
4479 for (i = 0; i < bp->cp_nr_rings; i++) {
4480 struct bnxt_napi *bnapi = bp->bnapi[i];
4481 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
4482
4483 if (cpr->hw_stats_ctx_id != INVALID_STATS_CTX_ID) {
4484 req.stat_ctx_id = cpu_to_le32(cpr->hw_stats_ctx_id);
4485
4486 rc = _hwrm_send_message(bp, &req, sizeof(req),
4487 HWRM_CMD_TIMEOUT);
4488 if (rc)
4489 break;
4490
4491 cpr->hw_stats_ctx_id = INVALID_STATS_CTX_ID;
4492 }
4493 }
4494 mutex_unlock(&bp->hwrm_cmd_lock);
4495 return rc;
4496}
4497
4498static int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp)
4499{
4500 int rc = 0, i;
4501 struct hwrm_stat_ctx_alloc_input req = {0};
4502 struct hwrm_stat_ctx_alloc_output *resp = bp->hwrm_cmd_resp_addr;
4503
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04004504 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
4505 return 0;
4506
Michael Chanc0c050c2015-10-22 16:01:17 -04004507 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_STAT_CTX_ALLOC, -1, -1);
4508
Michael Chan51f30782016-07-01 18:46:29 -04004509 req.update_period_ms = cpu_to_le32(bp->stats_coal_ticks / 1000);
Michael Chanc0c050c2015-10-22 16:01:17 -04004510
4511 mutex_lock(&bp->hwrm_cmd_lock);
4512 for (i = 0; i < bp->cp_nr_rings; i++) {
4513 struct bnxt_napi *bnapi = bp->bnapi[i];
4514 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
4515
4516 req.stats_dma_addr = cpu_to_le64(cpr->hw_stats_map);
4517
4518 rc = _hwrm_send_message(bp, &req, sizeof(req),
4519 HWRM_CMD_TIMEOUT);
4520 if (rc)
4521 break;
4522
4523 cpr->hw_stats_ctx_id = le32_to_cpu(resp->stat_ctx_id);
4524
4525 bp->grp_info[i].fw_stats_ctx = cpr->hw_stats_ctx_id;
4526 }
4527 mutex_unlock(&bp->hwrm_cmd_lock);
Pan Bian89aa8442016-12-03 17:56:17 +08004528 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04004529}
4530
Michael Chancf6645f2016-06-13 02:25:28 -04004531static int bnxt_hwrm_func_qcfg(struct bnxt *bp)
4532{
4533 struct hwrm_func_qcfg_input req = {0};
Satish Baddipadige567b2ab2016-06-13 02:25:31 -04004534 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
Michael Chancf6645f2016-06-13 02:25:28 -04004535 int rc;
4536
4537 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCFG, -1, -1);
4538 req.fid = cpu_to_le16(0xffff);
4539 mutex_lock(&bp->hwrm_cmd_lock);
4540 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4541 if (rc)
4542 goto func_qcfg_exit;
4543
4544#ifdef CONFIG_BNXT_SRIOV
4545 if (BNXT_VF(bp)) {
Michael Chancf6645f2016-06-13 02:25:28 -04004546 struct bnxt_vf_info *vf = &bp->vf;
4547
4548 vf->vlan = le16_to_cpu(resp->vlan) & VLAN_VID_MASK;
4549 }
4550#endif
Deepak Khungar9e54e322017-04-21 20:11:26 -04004551 if (BNXT_PF(bp)) {
4552 u16 flags = le16_to_cpu(resp->flags);
4553
4554 if (flags & (FUNC_QCFG_RESP_FLAGS_FW_DCBX_AGENT_ENABLED |
4555 FUNC_QCFG_RESP_FLAGS_FW_LLDP_AGENT_ENABLED))
4556 bp->flags |= BNXT_FLAG_FW_LLDP_AGENT;
4557 if (flags & FUNC_QCFG_RESP_FLAGS_MULTI_HOST)
4558 bp->flags |= BNXT_FLAG_MULTI_HOST;
4559 }
Michael Chanbc39f882017-03-08 18:44:34 -05004560
Satish Baddipadige567b2ab2016-06-13 02:25:31 -04004561 switch (resp->port_partition_type) {
4562 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_0:
4563 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_5:
4564 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR2_0:
4565 bp->port_partition_type = resp->port_partition_type;
4566 break;
4567 }
Michael Chancf6645f2016-06-13 02:25:28 -04004568
4569func_qcfg_exit:
4570 mutex_unlock(&bp->hwrm_cmd_lock);
4571 return rc;
4572}
4573
Michael Chan7b08f662016-12-07 00:26:18 -05004574static int bnxt_hwrm_func_qcaps(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04004575{
4576 int rc = 0;
4577 struct hwrm_func_qcaps_input req = {0};
4578 struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
4579
4580 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCAPS, -1, -1);
4581 req.fid = cpu_to_le16(0xffff);
4582
4583 mutex_lock(&bp->hwrm_cmd_lock);
4584 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4585 if (rc)
4586 goto hwrm_func_qcaps_exit;
4587
Michael Chane4060d32016-12-07 00:26:19 -05004588 if (resp->flags & cpu_to_le32(FUNC_QCAPS_RESP_FLAGS_ROCE_V1_SUPPORTED))
4589 bp->flags |= BNXT_FLAG_ROCEV1_CAP;
4590 if (resp->flags & cpu_to_le32(FUNC_QCAPS_RESP_FLAGS_ROCE_V2_SUPPORTED))
4591 bp->flags |= BNXT_FLAG_ROCEV2_CAP;
4592
Michael Chan7cc5a202016-09-19 03:58:05 -04004593 bp->tx_push_thresh = 0;
4594 if (resp->flags &
4595 cpu_to_le32(FUNC_QCAPS_RESP_FLAGS_PUSH_MODE_SUPPORTED))
4596 bp->tx_push_thresh = BNXT_TX_PUSH_THRESH;
4597
Michael Chanc0c050c2015-10-22 16:01:17 -04004598 if (BNXT_PF(bp)) {
4599 struct bnxt_pf_info *pf = &bp->pf;
4600
4601 pf->fw_fid = le16_to_cpu(resp->fid);
4602 pf->port_id = le16_to_cpu(resp->port_id);
Michael Chan87027db2016-07-01 18:46:28 -04004603 bp->dev->dev_port = pf->port_id;
Michael Chan11f15ed2016-04-05 14:08:55 -04004604 memcpy(pf->mac_addr, resp->mac_address, ETH_ALEN);
Jeffrey Huangbdd43472015-12-02 01:54:07 -05004605 memcpy(bp->dev->dev_addr, pf->mac_addr, ETH_ALEN);
Michael Chanc0c050c2015-10-22 16:01:17 -04004606 pf->max_rsscos_ctxs = le16_to_cpu(resp->max_rsscos_ctx);
4607 pf->max_cp_rings = le16_to_cpu(resp->max_cmpl_rings);
4608 pf->max_tx_rings = le16_to_cpu(resp->max_tx_rings);
Michael Chanc0c050c2015-10-22 16:01:17 -04004609 pf->max_rx_rings = le16_to_cpu(resp->max_rx_rings);
Michael Chanb72d4a62015-12-27 18:19:27 -05004610 pf->max_hw_ring_grps = le32_to_cpu(resp->max_hw_ring_grps);
4611 if (!pf->max_hw_ring_grps)
4612 pf->max_hw_ring_grps = pf->max_tx_rings;
Michael Chanc0c050c2015-10-22 16:01:17 -04004613 pf->max_l2_ctxs = le16_to_cpu(resp->max_l2_ctxs);
4614 pf->max_vnics = le16_to_cpu(resp->max_vnics);
4615 pf->max_stat_ctxs = le16_to_cpu(resp->max_stat_ctx);
4616 pf->first_vf_id = le16_to_cpu(resp->first_vf_id);
4617 pf->max_vfs = le16_to_cpu(resp->max_vfs);
4618 pf->max_encap_records = le32_to_cpu(resp->max_encap_records);
4619 pf->max_decap_records = le32_to_cpu(resp->max_decap_records);
4620 pf->max_tx_em_flows = le32_to_cpu(resp->max_tx_em_flows);
4621 pf->max_tx_wm_flows = le32_to_cpu(resp->max_tx_wm_flows);
4622 pf->max_rx_em_flows = le32_to_cpu(resp->max_rx_em_flows);
4623 pf->max_rx_wm_flows = le32_to_cpu(resp->max_rx_wm_flows);
Michael Chanc1ef1462017-04-04 18:14:07 -04004624 if (resp->flags &
4625 cpu_to_le32(FUNC_QCAPS_RESP_FLAGS_WOL_MAGICPKT_SUPPORTED))
4626 bp->flags |= BNXT_FLAG_WOL_CAP;
Michael Chanc0c050c2015-10-22 16:01:17 -04004627 } else {
Michael Chan379a80a2015-10-23 15:06:19 -04004628#ifdef CONFIG_BNXT_SRIOV
Michael Chanc0c050c2015-10-22 16:01:17 -04004629 struct bnxt_vf_info *vf = &bp->vf;
4630
4631 vf->fw_fid = le16_to_cpu(resp->fid);
Michael Chanc0c050c2015-10-22 16:01:17 -04004632
4633 vf->max_rsscos_ctxs = le16_to_cpu(resp->max_rsscos_ctx);
4634 vf->max_cp_rings = le16_to_cpu(resp->max_cmpl_rings);
4635 vf->max_tx_rings = le16_to_cpu(resp->max_tx_rings);
4636 vf->max_rx_rings = le16_to_cpu(resp->max_rx_rings);
Michael Chanb72d4a62015-12-27 18:19:27 -05004637 vf->max_hw_ring_grps = le32_to_cpu(resp->max_hw_ring_grps);
4638 if (!vf->max_hw_ring_grps)
4639 vf->max_hw_ring_grps = vf->max_tx_rings;
Michael Chanc0c050c2015-10-22 16:01:17 -04004640 vf->max_l2_ctxs = le16_to_cpu(resp->max_l2_ctxs);
4641 vf->max_vnics = le16_to_cpu(resp->max_vnics);
4642 vf->max_stat_ctxs = le16_to_cpu(resp->max_stat_ctx);
Michael Chan7cc5a202016-09-19 03:58:05 -04004643
4644 memcpy(vf->mac_addr, resp->mac_address, ETH_ALEN);
Michael Chan001154e2016-09-19 03:58:06 -04004645 mutex_unlock(&bp->hwrm_cmd_lock);
4646
4647 if (is_valid_ether_addr(vf->mac_addr)) {
Michael Chan7cc5a202016-09-19 03:58:05 -04004648 /* overwrite netdev dev_adr with admin VF MAC */
4649 memcpy(bp->dev->dev_addr, vf->mac_addr, ETH_ALEN);
Michael Chan001154e2016-09-19 03:58:06 -04004650 } else {
Tobias Klauser1faaa782017-02-21 15:27:28 +01004651 eth_hw_addr_random(bp->dev);
Michael Chan001154e2016-09-19 03:58:06 -04004652 rc = bnxt_approve_mac(bp, bp->dev->dev_addr);
4653 }
4654 return rc;
Michael Chan379a80a2015-10-23 15:06:19 -04004655#endif
Michael Chanc0c050c2015-10-22 16:01:17 -04004656 }
4657
Michael Chanc0c050c2015-10-22 16:01:17 -04004658hwrm_func_qcaps_exit:
4659 mutex_unlock(&bp->hwrm_cmd_lock);
4660 return rc;
4661}
4662
4663static int bnxt_hwrm_func_reset(struct bnxt *bp)
4664{
4665 struct hwrm_func_reset_input req = {0};
4666
4667 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_RESET, -1, -1);
4668 req.enables = 0;
4669
4670 return hwrm_send_message(bp, &req, sizeof(req), HWRM_RESET_TIMEOUT);
4671}
4672
4673static int bnxt_hwrm_queue_qportcfg(struct bnxt *bp)
4674{
4675 int rc = 0;
4676 struct hwrm_queue_qportcfg_input req = {0};
4677 struct hwrm_queue_qportcfg_output *resp = bp->hwrm_cmd_resp_addr;
4678 u8 i, *qptr;
4679
4680 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_QUEUE_QPORTCFG, -1, -1);
4681
4682 mutex_lock(&bp->hwrm_cmd_lock);
4683 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4684 if (rc)
4685 goto qportcfg_exit;
4686
4687 if (!resp->max_configurable_queues) {
4688 rc = -EINVAL;
4689 goto qportcfg_exit;
4690 }
4691 bp->max_tc = resp->max_configurable_queues;
Michael Chan87c374d2016-12-02 21:17:16 -05004692 bp->max_lltc = resp->max_configurable_lossless_queues;
Michael Chanc0c050c2015-10-22 16:01:17 -04004693 if (bp->max_tc > BNXT_MAX_QUEUE)
4694 bp->max_tc = BNXT_MAX_QUEUE;
4695
Michael Chan441cabb2016-09-19 03:58:02 -04004696 if (resp->queue_cfg_info & QUEUE_QPORTCFG_RESP_QUEUE_CFG_INFO_ASYM_CFG)
4697 bp->max_tc = 1;
4698
Michael Chan87c374d2016-12-02 21:17:16 -05004699 if (bp->max_lltc > bp->max_tc)
4700 bp->max_lltc = bp->max_tc;
4701
Michael Chanc0c050c2015-10-22 16:01:17 -04004702 qptr = &resp->queue_id0;
4703 for (i = 0; i < bp->max_tc; i++) {
4704 bp->q_info[i].queue_id = *qptr++;
4705 bp->q_info[i].queue_profile = *qptr++;
4706 }
4707
4708qportcfg_exit:
4709 mutex_unlock(&bp->hwrm_cmd_lock);
4710 return rc;
4711}
4712
4713static int bnxt_hwrm_ver_get(struct bnxt *bp)
4714{
4715 int rc;
4716 struct hwrm_ver_get_input req = {0};
4717 struct hwrm_ver_get_output *resp = bp->hwrm_cmd_resp_addr;
Deepak Khungare605db82017-05-29 19:06:04 -04004718 u32 dev_caps_cfg;
Michael Chanc0c050c2015-10-22 16:01:17 -04004719
Michael Chane6ef2692016-03-28 19:46:05 -04004720 bp->hwrm_max_req_len = HWRM_MAX_REQ_LEN;
Michael Chanc0c050c2015-10-22 16:01:17 -04004721 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VER_GET, -1, -1);
4722 req.hwrm_intf_maj = HWRM_VERSION_MAJOR;
4723 req.hwrm_intf_min = HWRM_VERSION_MINOR;
4724 req.hwrm_intf_upd = HWRM_VERSION_UPDATE;
4725 mutex_lock(&bp->hwrm_cmd_lock);
4726 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4727 if (rc)
4728 goto hwrm_ver_get_exit;
4729
4730 memcpy(&bp->ver_resp, resp, sizeof(struct hwrm_ver_get_output));
4731
Michael Chan11f15ed2016-04-05 14:08:55 -04004732 bp->hwrm_spec_code = resp->hwrm_intf_maj << 16 |
4733 resp->hwrm_intf_min << 8 | resp->hwrm_intf_upd;
Michael Chanc1935542015-12-27 18:19:28 -05004734 if (resp->hwrm_intf_maj < 1) {
4735 netdev_warn(bp->dev, "HWRM interface %d.%d.%d is older than 1.0.0.\n",
Michael Chanc0c050c2015-10-22 16:01:17 -04004736 resp->hwrm_intf_maj, resp->hwrm_intf_min,
Michael Chanc1935542015-12-27 18:19:28 -05004737 resp->hwrm_intf_upd);
4738 netdev_warn(bp->dev, "Please update firmware with HWRM interface 1.0.0 or newer.\n");
Michael Chanc0c050c2015-10-22 16:01:17 -04004739 }
Rob Swindell3ebf6f02016-02-26 04:00:06 -05004740 snprintf(bp->fw_ver_str, BC_HWRM_STR_LEN, "%d.%d.%d/%d.%d.%d",
Michael Chanc0c050c2015-10-22 16:01:17 -04004741 resp->hwrm_fw_maj, resp->hwrm_fw_min, resp->hwrm_fw_bld,
4742 resp->hwrm_intf_maj, resp->hwrm_intf_min, resp->hwrm_intf_upd);
4743
Michael Chanff4fe812016-02-26 04:00:04 -05004744 bp->hwrm_cmd_timeout = le16_to_cpu(resp->def_req_timeout);
4745 if (!bp->hwrm_cmd_timeout)
4746 bp->hwrm_cmd_timeout = DFLT_HWRM_CMD_TIMEOUT;
4747
Michael Chane6ef2692016-03-28 19:46:05 -04004748 if (resp->hwrm_intf_maj >= 1)
4749 bp->hwrm_max_req_len = le16_to_cpu(resp->max_req_win_len);
4750
Michael Chan659c8052016-06-13 02:25:33 -04004751 bp->chip_num = le16_to_cpu(resp->chip_num);
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04004752 if (bp->chip_num == CHIP_NUM_58700 && !resp->chip_rev &&
4753 !resp->chip_metal)
4754 bp->flags |= BNXT_FLAG_CHIP_NITRO_A0;
Michael Chan659c8052016-06-13 02:25:33 -04004755
Deepak Khungare605db82017-05-29 19:06:04 -04004756 dev_caps_cfg = le32_to_cpu(resp->dev_caps_cfg);
4757 if ((dev_caps_cfg & VER_GET_RESP_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED) &&
4758 (dev_caps_cfg & VER_GET_RESP_DEV_CAPS_CFG_SHORT_CMD_REQUIRED))
4759 bp->flags |= BNXT_FLAG_SHORT_CMD;
4760
Michael Chanc0c050c2015-10-22 16:01:17 -04004761hwrm_ver_get_exit:
4762 mutex_unlock(&bp->hwrm_cmd_lock);
4763 return rc;
4764}
4765
Rob Swindell5ac67d82016-09-19 03:58:03 -04004766int bnxt_hwrm_fw_set_time(struct bnxt *bp)
4767{
Rob Swindell878786d2016-09-20 03:36:33 -04004768#if IS_ENABLED(CONFIG_RTC_LIB)
Rob Swindell5ac67d82016-09-19 03:58:03 -04004769 struct hwrm_fw_set_time_input req = {0};
4770 struct rtc_time tm;
4771 struct timeval tv;
4772
4773 if (bp->hwrm_spec_code < 0x10400)
4774 return -EOPNOTSUPP;
4775
4776 do_gettimeofday(&tv);
4777 rtc_time_to_tm(tv.tv_sec, &tm);
4778 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_SET_TIME, -1, -1);
4779 req.year = cpu_to_le16(1900 + tm.tm_year);
4780 req.month = 1 + tm.tm_mon;
4781 req.day = tm.tm_mday;
4782 req.hour = tm.tm_hour;
4783 req.minute = tm.tm_min;
4784 req.second = tm.tm_sec;
4785 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
Rob Swindell878786d2016-09-20 03:36:33 -04004786#else
4787 return -EOPNOTSUPP;
4788#endif
Rob Swindell5ac67d82016-09-19 03:58:03 -04004789}
4790
Michael Chan3bdf56c2016-03-07 15:38:45 -05004791static int bnxt_hwrm_port_qstats(struct bnxt *bp)
4792{
4793 int rc;
4794 struct bnxt_pf_info *pf = &bp->pf;
4795 struct hwrm_port_qstats_input req = {0};
4796
4797 if (!(bp->flags & BNXT_FLAG_PORT_STATS))
4798 return 0;
4799
4800 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_QSTATS, -1, -1);
4801 req.port_id = cpu_to_le16(pf->port_id);
4802 req.tx_stat_host_addr = cpu_to_le64(bp->hw_tx_port_stats_map);
4803 req.rx_stat_host_addr = cpu_to_le64(bp->hw_rx_port_stats_map);
4804 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4805 return rc;
4806}
4807
Michael Chanc0c050c2015-10-22 16:01:17 -04004808static void bnxt_hwrm_free_tunnel_ports(struct bnxt *bp)
4809{
4810 if (bp->vxlan_port_cnt) {
4811 bnxt_hwrm_tunnel_dst_port_free(
4812 bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN);
4813 }
4814 bp->vxlan_port_cnt = 0;
4815 if (bp->nge_port_cnt) {
4816 bnxt_hwrm_tunnel_dst_port_free(
4817 bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE);
4818 }
4819 bp->nge_port_cnt = 0;
4820}
4821
4822static int bnxt_set_tpa(struct bnxt *bp, bool set_tpa)
4823{
4824 int rc, i;
4825 u32 tpa_flags = 0;
4826
4827 if (set_tpa)
4828 tpa_flags = bp->flags & BNXT_FLAG_TPA;
4829 for (i = 0; i < bp->nr_vnics; i++) {
4830 rc = bnxt_hwrm_vnic_set_tpa(bp, i, tpa_flags);
4831 if (rc) {
4832 netdev_err(bp->dev, "hwrm vnic set tpa failure rc for vnic %d: %x\n",
Sankar Patchineelam23e12c82017-03-28 19:47:30 -04004833 i, rc);
Michael Chanc0c050c2015-10-22 16:01:17 -04004834 return rc;
4835 }
4836 }
4837 return 0;
4838}
4839
4840static void bnxt_hwrm_clear_vnic_rss(struct bnxt *bp)
4841{
4842 int i;
4843
4844 for (i = 0; i < bp->nr_vnics; i++)
4845 bnxt_hwrm_vnic_set_rss(bp, i, false);
4846}
4847
4848static void bnxt_hwrm_resource_free(struct bnxt *bp, bool close_path,
4849 bool irq_re_init)
4850{
4851 if (bp->vnic_info) {
4852 bnxt_hwrm_clear_vnic_filter(bp);
4853 /* clear all RSS setting before free vnic ctx */
4854 bnxt_hwrm_clear_vnic_rss(bp);
4855 bnxt_hwrm_vnic_ctx_free(bp);
4856 /* before free the vnic, undo the vnic tpa settings */
4857 if (bp->flags & BNXT_FLAG_TPA)
4858 bnxt_set_tpa(bp, false);
4859 bnxt_hwrm_vnic_free(bp);
4860 }
4861 bnxt_hwrm_ring_free(bp, close_path);
4862 bnxt_hwrm_ring_grp_free(bp);
4863 if (irq_re_init) {
4864 bnxt_hwrm_stat_ctx_free(bp);
4865 bnxt_hwrm_free_tunnel_ports(bp);
4866 }
4867}
4868
4869static int bnxt_setup_vnic(struct bnxt *bp, u16 vnic_id)
4870{
Michael Chanae10ae72016-12-29 12:13:38 -05004871 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
Michael Chanc0c050c2015-10-22 16:01:17 -04004872 int rc;
4873
Michael Chanae10ae72016-12-29 12:13:38 -05004874 if (vnic->flags & BNXT_VNIC_RFS_NEW_RSS_FLAG)
4875 goto skip_rss_ctx;
4876
Michael Chanc0c050c2015-10-22 16:01:17 -04004877 /* allocate context for vnic */
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004878 rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic_id, 0);
Michael Chanc0c050c2015-10-22 16:01:17 -04004879 if (rc) {
4880 netdev_err(bp->dev, "hwrm vnic %d alloc failure rc: %x\n",
4881 vnic_id, rc);
4882 goto vnic_setup_err;
4883 }
4884 bp->rsscos_nr_ctxs++;
4885
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004886 if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
4887 rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic_id, 1);
4888 if (rc) {
4889 netdev_err(bp->dev, "hwrm vnic %d cos ctx alloc failure rc: %x\n",
4890 vnic_id, rc);
4891 goto vnic_setup_err;
4892 }
4893 bp->rsscos_nr_ctxs++;
4894 }
4895
Michael Chanae10ae72016-12-29 12:13:38 -05004896skip_rss_ctx:
Michael Chanc0c050c2015-10-22 16:01:17 -04004897 /* configure default vnic, ring grp */
4898 rc = bnxt_hwrm_vnic_cfg(bp, vnic_id);
4899 if (rc) {
4900 netdev_err(bp->dev, "hwrm vnic %d cfg failure rc: %x\n",
4901 vnic_id, rc);
4902 goto vnic_setup_err;
4903 }
4904
4905 /* Enable RSS hashing on vnic */
4906 rc = bnxt_hwrm_vnic_set_rss(bp, vnic_id, true);
4907 if (rc) {
4908 netdev_err(bp->dev, "hwrm vnic %d set rss failure rc: %x\n",
4909 vnic_id, rc);
4910 goto vnic_setup_err;
4911 }
4912
4913 if (bp->flags & BNXT_FLAG_AGG_RINGS) {
4914 rc = bnxt_hwrm_vnic_set_hds(bp, vnic_id);
4915 if (rc) {
4916 netdev_err(bp->dev, "hwrm vnic %d set hds failure rc: %x\n",
4917 vnic_id, rc);
4918 }
4919 }
4920
4921vnic_setup_err:
4922 return rc;
4923}
4924
4925static int bnxt_alloc_rfs_vnics(struct bnxt *bp)
4926{
4927#ifdef CONFIG_RFS_ACCEL
4928 int i, rc = 0;
4929
4930 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanae10ae72016-12-29 12:13:38 -05004931 struct bnxt_vnic_info *vnic;
Michael Chanc0c050c2015-10-22 16:01:17 -04004932 u16 vnic_id = i + 1;
4933 u16 ring_id = i;
4934
4935 if (vnic_id >= bp->nr_vnics)
4936 break;
4937
Michael Chanae10ae72016-12-29 12:13:38 -05004938 vnic = &bp->vnic_info[vnic_id];
4939 vnic->flags |= BNXT_VNIC_RFS_FLAG;
4940 if (bp->flags & BNXT_FLAG_NEW_RSS_CAP)
4941 vnic->flags |= BNXT_VNIC_RFS_NEW_RSS_FLAG;
Michael Chanb81a90d2016-01-02 23:45:01 -05004942 rc = bnxt_hwrm_vnic_alloc(bp, vnic_id, ring_id, 1);
Michael Chanc0c050c2015-10-22 16:01:17 -04004943 if (rc) {
4944 netdev_err(bp->dev, "hwrm vnic %d alloc failure rc: %x\n",
4945 vnic_id, rc);
4946 break;
4947 }
4948 rc = bnxt_setup_vnic(bp, vnic_id);
4949 if (rc)
4950 break;
4951 }
4952 return rc;
4953#else
4954 return 0;
4955#endif
4956}
4957
Michael Chan17c71ac2016-07-01 18:46:27 -04004958/* Allow PF and VF with default VLAN to be in promiscuous mode */
4959static bool bnxt_promisc_ok(struct bnxt *bp)
4960{
4961#ifdef CONFIG_BNXT_SRIOV
4962 if (BNXT_VF(bp) && !bp->vf.vlan)
4963 return false;
4964#endif
4965 return true;
4966}
4967
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04004968static int bnxt_setup_nitroa0_vnic(struct bnxt *bp)
4969{
4970 unsigned int rc = 0;
4971
4972 rc = bnxt_hwrm_vnic_alloc(bp, 1, bp->rx_nr_rings - 1, 1);
4973 if (rc) {
4974 netdev_err(bp->dev, "Cannot allocate special vnic for NS2 A0: %x\n",
4975 rc);
4976 return rc;
4977 }
4978
4979 rc = bnxt_hwrm_vnic_cfg(bp, 1);
4980 if (rc) {
4981 netdev_err(bp->dev, "Cannot allocate special vnic for NS2 A0: %x\n",
4982 rc);
4983 return rc;
4984 }
4985 return rc;
4986}
4987
Michael Chanb664f002015-12-02 01:54:08 -05004988static int bnxt_cfg_rx_mode(struct bnxt *);
Michael Chan7d2837d2016-05-04 16:56:44 -04004989static bool bnxt_mc_list_updated(struct bnxt *, u32 *);
Michael Chanb664f002015-12-02 01:54:08 -05004990
Michael Chanc0c050c2015-10-22 16:01:17 -04004991static int bnxt_init_chip(struct bnxt *bp, bool irq_re_init)
4992{
Michael Chan7d2837d2016-05-04 16:56:44 -04004993 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
Michael Chanc0c050c2015-10-22 16:01:17 -04004994 int rc = 0;
Prashant Sreedharan76595192016-07-18 07:15:22 -04004995 unsigned int rx_nr_rings = bp->rx_nr_rings;
Michael Chanc0c050c2015-10-22 16:01:17 -04004996
4997 if (irq_re_init) {
4998 rc = bnxt_hwrm_stat_ctx_alloc(bp);
4999 if (rc) {
5000 netdev_err(bp->dev, "hwrm stat ctx alloc failure rc: %x\n",
5001 rc);
5002 goto err_out;
5003 }
5004 }
5005
5006 rc = bnxt_hwrm_ring_alloc(bp);
5007 if (rc) {
5008 netdev_err(bp->dev, "hwrm ring alloc failure rc: %x\n", rc);
5009 goto err_out;
5010 }
5011
5012 rc = bnxt_hwrm_ring_grp_alloc(bp);
5013 if (rc) {
5014 netdev_err(bp->dev, "hwrm_ring_grp alloc failure: %x\n", rc);
5015 goto err_out;
5016 }
5017
Prashant Sreedharan76595192016-07-18 07:15:22 -04005018 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
5019 rx_nr_rings--;
5020
Michael Chanc0c050c2015-10-22 16:01:17 -04005021 /* default vnic 0 */
Prashant Sreedharan76595192016-07-18 07:15:22 -04005022 rc = bnxt_hwrm_vnic_alloc(bp, 0, 0, rx_nr_rings);
Michael Chanc0c050c2015-10-22 16:01:17 -04005023 if (rc) {
5024 netdev_err(bp->dev, "hwrm vnic alloc failure rc: %x\n", rc);
5025 goto err_out;
5026 }
5027
5028 rc = bnxt_setup_vnic(bp, 0);
5029 if (rc)
5030 goto err_out;
5031
5032 if (bp->flags & BNXT_FLAG_RFS) {
5033 rc = bnxt_alloc_rfs_vnics(bp);
5034 if (rc)
5035 goto err_out;
5036 }
5037
5038 if (bp->flags & BNXT_FLAG_TPA) {
5039 rc = bnxt_set_tpa(bp, true);
5040 if (rc)
5041 goto err_out;
5042 }
5043
5044 if (BNXT_VF(bp))
5045 bnxt_update_vf_mac(bp);
5046
5047 /* Filter for default vnic 0 */
5048 rc = bnxt_hwrm_set_vnic_filter(bp, 0, 0, bp->dev->dev_addr);
5049 if (rc) {
5050 netdev_err(bp->dev, "HWRM vnic filter failure rc: %x\n", rc);
5051 goto err_out;
5052 }
Michael Chan7d2837d2016-05-04 16:56:44 -04005053 vnic->uc_filter_count = 1;
Michael Chanc0c050c2015-10-22 16:01:17 -04005054
Michael Chan7d2837d2016-05-04 16:56:44 -04005055 vnic->rx_mask = CFA_L2_SET_RX_MASK_REQ_MASK_BCAST;
Michael Chanc0c050c2015-10-22 16:01:17 -04005056
Michael Chan17c71ac2016-07-01 18:46:27 -04005057 if ((bp->dev->flags & IFF_PROMISC) && bnxt_promisc_ok(bp))
Michael Chan7d2837d2016-05-04 16:56:44 -04005058 vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS;
5059
5060 if (bp->dev->flags & IFF_ALLMULTI) {
5061 vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST;
5062 vnic->mc_list_count = 0;
5063 } else {
5064 u32 mask = 0;
5065
5066 bnxt_mc_list_updated(bp, &mask);
5067 vnic->rx_mask |= mask;
5068 }
Michael Chanc0c050c2015-10-22 16:01:17 -04005069
Michael Chanb664f002015-12-02 01:54:08 -05005070 rc = bnxt_cfg_rx_mode(bp);
5071 if (rc)
Michael Chanc0c050c2015-10-22 16:01:17 -04005072 goto err_out;
Michael Chanc0c050c2015-10-22 16:01:17 -04005073
5074 rc = bnxt_hwrm_set_coal(bp);
5075 if (rc)
5076 netdev_warn(bp->dev, "HWRM set coalescing failure rc: %x\n",
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04005077 rc);
5078
5079 if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
5080 rc = bnxt_setup_nitroa0_vnic(bp);
5081 if (rc)
5082 netdev_err(bp->dev, "Special vnic setup failure for NS2 A0 rc: %x\n",
5083 rc);
5084 }
Michael Chanc0c050c2015-10-22 16:01:17 -04005085
Michael Chancf6645f2016-06-13 02:25:28 -04005086 if (BNXT_VF(bp)) {
5087 bnxt_hwrm_func_qcfg(bp);
5088 netdev_update_features(bp->dev);
5089 }
5090
Michael Chanc0c050c2015-10-22 16:01:17 -04005091 return 0;
5092
5093err_out:
5094 bnxt_hwrm_resource_free(bp, 0, true);
5095
5096 return rc;
5097}
5098
5099static int bnxt_shutdown_nic(struct bnxt *bp, bool irq_re_init)
5100{
5101 bnxt_hwrm_resource_free(bp, 1, irq_re_init);
5102 return 0;
5103}
5104
5105static int bnxt_init_nic(struct bnxt *bp, bool irq_re_init)
5106{
Sankar Patchineelam22479252017-03-28 19:47:29 -04005107 bnxt_init_cp_rings(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04005108 bnxt_init_rx_rings(bp);
5109 bnxt_init_tx_rings(bp);
5110 bnxt_init_ring_grps(bp, irq_re_init);
5111 bnxt_init_vnics(bp);
5112
5113 return bnxt_init_chip(bp, irq_re_init);
5114}
5115
Michael Chanc0c050c2015-10-22 16:01:17 -04005116static int bnxt_set_real_num_queues(struct bnxt *bp)
5117{
5118 int rc;
5119 struct net_device *dev = bp->dev;
5120
Michael Chan5f449242017-02-06 16:55:40 -05005121 rc = netif_set_real_num_tx_queues(dev, bp->tx_nr_rings -
5122 bp->tx_nr_rings_xdp);
Michael Chanc0c050c2015-10-22 16:01:17 -04005123 if (rc)
5124 return rc;
5125
5126 rc = netif_set_real_num_rx_queues(dev, bp->rx_nr_rings);
5127 if (rc)
5128 return rc;
5129
5130#ifdef CONFIG_RFS_ACCEL
Michael Chan45019a12015-12-27 18:19:22 -05005131 if (bp->flags & BNXT_FLAG_RFS)
Michael Chanc0c050c2015-10-22 16:01:17 -04005132 dev->rx_cpu_rmap = alloc_irq_cpu_rmap(bp->rx_nr_rings);
Michael Chanc0c050c2015-10-22 16:01:17 -04005133#endif
5134
5135 return rc;
5136}
5137
Michael Chan6e6c5a52016-01-02 23:45:02 -05005138static int bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max,
5139 bool shared)
5140{
5141 int _rx = *rx, _tx = *tx;
5142
5143 if (shared) {
5144 *rx = min_t(int, _rx, max);
5145 *tx = min_t(int, _tx, max);
5146 } else {
5147 if (max < 2)
5148 return -ENOMEM;
5149
5150 while (_rx + _tx > max) {
5151 if (_rx > _tx && _rx > 1)
5152 _rx--;
5153 else if (_tx > 1)
5154 _tx--;
5155 }
5156 *rx = _rx;
5157 *tx = _tx;
5158 }
5159 return 0;
5160}
5161
Michael Chan78095922016-12-07 00:26:16 -05005162static void bnxt_setup_msix(struct bnxt *bp)
5163{
5164 const int len = sizeof(bp->irq_tbl[0].name);
5165 struct net_device *dev = bp->dev;
5166 int tcs, i;
5167
5168 tcs = netdev_get_num_tc(dev);
5169 if (tcs > 1) {
Michael Chand1e79252017-02-06 16:55:38 -05005170 int i, off, count;
Michael Chan78095922016-12-07 00:26:16 -05005171
Michael Chand1e79252017-02-06 16:55:38 -05005172 for (i = 0; i < tcs; i++) {
5173 count = bp->tx_nr_rings_per_tc;
5174 off = i * count;
5175 netdev_set_tc_queue(dev, i, count, off);
Michael Chan78095922016-12-07 00:26:16 -05005176 }
5177 }
5178
5179 for (i = 0; i < bp->cp_nr_rings; i++) {
5180 char *attr;
5181
5182 if (bp->flags & BNXT_FLAG_SHARED_RINGS)
5183 attr = "TxRx";
5184 else if (i < bp->rx_nr_rings)
5185 attr = "rx";
5186 else
5187 attr = "tx";
5188
5189 snprintf(bp->irq_tbl[i].name, len, "%s-%s-%d", dev->name, attr,
5190 i);
5191 bp->irq_tbl[i].handler = bnxt_msix;
5192 }
5193}
5194
5195static void bnxt_setup_inta(struct bnxt *bp)
5196{
5197 const int len = sizeof(bp->irq_tbl[0].name);
5198
5199 if (netdev_get_num_tc(bp->dev))
5200 netdev_reset_tc(bp->dev);
5201
5202 snprintf(bp->irq_tbl[0].name, len, "%s-%s-%d", bp->dev->name, "TxRx",
5203 0);
5204 bp->irq_tbl[0].handler = bnxt_inta;
5205}
5206
5207static int bnxt_setup_int_mode(struct bnxt *bp)
5208{
5209 int rc;
5210
5211 if (bp->flags & BNXT_FLAG_USING_MSIX)
5212 bnxt_setup_msix(bp);
5213 else
5214 bnxt_setup_inta(bp);
5215
5216 rc = bnxt_set_real_num_queues(bp);
5217 return rc;
5218}
5219
Michael Chanb7429952017-01-13 01:32:00 -05005220#ifdef CONFIG_RFS_ACCEL
Michael Chan8079e8f2016-12-29 12:13:37 -05005221static unsigned int bnxt_get_max_func_rss_ctxs(struct bnxt *bp)
5222{
5223#if defined(CONFIG_BNXT_SRIOV)
5224 if (BNXT_VF(bp))
5225 return bp->vf.max_rsscos_ctxs;
5226#endif
5227 return bp->pf.max_rsscos_ctxs;
5228}
5229
5230static unsigned int bnxt_get_max_func_vnics(struct bnxt *bp)
5231{
5232#if defined(CONFIG_BNXT_SRIOV)
5233 if (BNXT_VF(bp))
5234 return bp->vf.max_vnics;
5235#endif
5236 return bp->pf.max_vnics;
5237}
Michael Chanb7429952017-01-13 01:32:00 -05005238#endif
Michael Chan8079e8f2016-12-29 12:13:37 -05005239
Michael Chane4060d32016-12-07 00:26:19 -05005240unsigned int bnxt_get_max_func_stat_ctxs(struct bnxt *bp)
5241{
5242#if defined(CONFIG_BNXT_SRIOV)
5243 if (BNXT_VF(bp))
5244 return bp->vf.max_stat_ctxs;
5245#endif
5246 return bp->pf.max_stat_ctxs;
5247}
5248
Michael Chana588e452016-12-07 00:26:21 -05005249void bnxt_set_max_func_stat_ctxs(struct bnxt *bp, unsigned int max)
5250{
5251#if defined(CONFIG_BNXT_SRIOV)
5252 if (BNXT_VF(bp))
5253 bp->vf.max_stat_ctxs = max;
5254 else
5255#endif
5256 bp->pf.max_stat_ctxs = max;
5257}
5258
Michael Chane4060d32016-12-07 00:26:19 -05005259unsigned int bnxt_get_max_func_cp_rings(struct bnxt *bp)
5260{
5261#if defined(CONFIG_BNXT_SRIOV)
5262 if (BNXT_VF(bp))
5263 return bp->vf.max_cp_rings;
5264#endif
5265 return bp->pf.max_cp_rings;
5266}
5267
Michael Chana588e452016-12-07 00:26:21 -05005268void bnxt_set_max_func_cp_rings(struct bnxt *bp, unsigned int max)
5269{
5270#if defined(CONFIG_BNXT_SRIOV)
5271 if (BNXT_VF(bp))
5272 bp->vf.max_cp_rings = max;
5273 else
5274#endif
5275 bp->pf.max_cp_rings = max;
5276}
5277
Michael Chan78095922016-12-07 00:26:16 -05005278static unsigned int bnxt_get_max_func_irqs(struct bnxt *bp)
5279{
5280#if defined(CONFIG_BNXT_SRIOV)
5281 if (BNXT_VF(bp))
Michael Chan68a946b2017-04-04 18:14:17 -04005282 return min_t(unsigned int, bp->vf.max_irqs,
5283 bp->vf.max_cp_rings);
Michael Chan78095922016-12-07 00:26:16 -05005284#endif
Michael Chan68a946b2017-04-04 18:14:17 -04005285 return min_t(unsigned int, bp->pf.max_irqs, bp->pf.max_cp_rings);
Michael Chan78095922016-12-07 00:26:16 -05005286}
5287
Michael Chan33c26572016-12-07 00:26:15 -05005288void bnxt_set_max_func_irqs(struct bnxt *bp, unsigned int max_irqs)
5289{
5290#if defined(CONFIG_BNXT_SRIOV)
5291 if (BNXT_VF(bp))
5292 bp->vf.max_irqs = max_irqs;
5293 else
5294#endif
5295 bp->pf.max_irqs = max_irqs;
5296}
5297
Michael Chan78095922016-12-07 00:26:16 -05005298static int bnxt_init_msix(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04005299{
Michael Chan01657bc2016-01-02 23:45:03 -05005300 int i, total_vecs, rc = 0, min = 1;
Michael Chan78095922016-12-07 00:26:16 -05005301 struct msix_entry *msix_ent;
Michael Chanc0c050c2015-10-22 16:01:17 -04005302
Michael Chan78095922016-12-07 00:26:16 -05005303 total_vecs = bnxt_get_max_func_irqs(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04005304 msix_ent = kcalloc(total_vecs, sizeof(struct msix_entry), GFP_KERNEL);
5305 if (!msix_ent)
5306 return -ENOMEM;
5307
5308 for (i = 0; i < total_vecs; i++) {
5309 msix_ent[i].entry = i;
5310 msix_ent[i].vector = 0;
5311 }
5312
Michael Chan01657bc2016-01-02 23:45:03 -05005313 if (!(bp->flags & BNXT_FLAG_SHARED_RINGS))
5314 min = 2;
5315
5316 total_vecs = pci_enable_msix_range(bp->pdev, msix_ent, min, total_vecs);
Michael Chanc0c050c2015-10-22 16:01:17 -04005317 if (total_vecs < 0) {
5318 rc = -ENODEV;
5319 goto msix_setup_exit;
5320 }
5321
5322 bp->irq_tbl = kcalloc(total_vecs, sizeof(struct bnxt_irq), GFP_KERNEL);
5323 if (bp->irq_tbl) {
Michael Chan78095922016-12-07 00:26:16 -05005324 for (i = 0; i < total_vecs; i++)
5325 bp->irq_tbl[i].vector = msix_ent[i].vector;
Michael Chanc0c050c2015-10-22 16:01:17 -04005326
Michael Chan78095922016-12-07 00:26:16 -05005327 bp->total_irqs = total_vecs;
Michael Chanc0c050c2015-10-22 16:01:17 -04005328 /* Trim rings based upon num of vectors allocated */
Michael Chan6e6c5a52016-01-02 23:45:02 -05005329 rc = bnxt_trim_rings(bp, &bp->rx_nr_rings, &bp->tx_nr_rings,
Michael Chan01657bc2016-01-02 23:45:03 -05005330 total_vecs, min == 1);
Michael Chan6e6c5a52016-01-02 23:45:02 -05005331 if (rc)
5332 goto msix_setup_exit;
5333
Michael Chanc0c050c2015-10-22 16:01:17 -04005334 bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
Michael Chan78095922016-12-07 00:26:16 -05005335 bp->cp_nr_rings = (min == 1) ?
5336 max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
5337 bp->tx_nr_rings + bp->rx_nr_rings;
Michael Chanc0c050c2015-10-22 16:01:17 -04005338
Michael Chanc0c050c2015-10-22 16:01:17 -04005339 } else {
5340 rc = -ENOMEM;
5341 goto msix_setup_exit;
5342 }
5343 bp->flags |= BNXT_FLAG_USING_MSIX;
5344 kfree(msix_ent);
5345 return 0;
5346
5347msix_setup_exit:
Michael Chan78095922016-12-07 00:26:16 -05005348 netdev_err(bp->dev, "bnxt_init_msix err: %x\n", rc);
5349 kfree(bp->irq_tbl);
5350 bp->irq_tbl = NULL;
Michael Chanc0c050c2015-10-22 16:01:17 -04005351 pci_disable_msix(bp->pdev);
5352 kfree(msix_ent);
5353 return rc;
5354}
5355
Michael Chan78095922016-12-07 00:26:16 -05005356static int bnxt_init_inta(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04005357{
Michael Chanc0c050c2015-10-22 16:01:17 -04005358 bp->irq_tbl = kcalloc(1, sizeof(struct bnxt_irq), GFP_KERNEL);
Michael Chan78095922016-12-07 00:26:16 -05005359 if (!bp->irq_tbl)
5360 return -ENOMEM;
5361
5362 bp->total_irqs = 1;
Michael Chanc0c050c2015-10-22 16:01:17 -04005363 bp->rx_nr_rings = 1;
5364 bp->tx_nr_rings = 1;
5365 bp->cp_nr_rings = 1;
5366 bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
Michael Chan01657bc2016-01-02 23:45:03 -05005367 bp->flags |= BNXT_FLAG_SHARED_RINGS;
Michael Chanc0c050c2015-10-22 16:01:17 -04005368 bp->irq_tbl[0].vector = bp->pdev->irq;
Michael Chan78095922016-12-07 00:26:16 -05005369 return 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04005370}
5371
Michael Chan78095922016-12-07 00:26:16 -05005372static int bnxt_init_int_mode(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04005373{
5374 int rc = 0;
5375
5376 if (bp->flags & BNXT_FLAG_MSIX_CAP)
Michael Chan78095922016-12-07 00:26:16 -05005377 rc = bnxt_init_msix(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04005378
Michael Chan1fa72e22016-04-25 02:30:49 -04005379 if (!(bp->flags & BNXT_FLAG_USING_MSIX) && BNXT_PF(bp)) {
Michael Chanc0c050c2015-10-22 16:01:17 -04005380 /* fallback to INTA */
Michael Chan78095922016-12-07 00:26:16 -05005381 rc = bnxt_init_inta(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04005382 }
5383 return rc;
5384}
5385
Michael Chan78095922016-12-07 00:26:16 -05005386static void bnxt_clear_int_mode(struct bnxt *bp)
5387{
5388 if (bp->flags & BNXT_FLAG_USING_MSIX)
5389 pci_disable_msix(bp->pdev);
5390
5391 kfree(bp->irq_tbl);
5392 bp->irq_tbl = NULL;
5393 bp->flags &= ~BNXT_FLAG_USING_MSIX;
5394}
5395
Michael Chanc0c050c2015-10-22 16:01:17 -04005396static void bnxt_free_irq(struct bnxt *bp)
5397{
5398 struct bnxt_irq *irq;
5399 int i;
5400
5401#ifdef CONFIG_RFS_ACCEL
5402 free_irq_cpu_rmap(bp->dev->rx_cpu_rmap);
5403 bp->dev->rx_cpu_rmap = NULL;
5404#endif
5405 if (!bp->irq_tbl)
5406 return;
5407
5408 for (i = 0; i < bp->cp_nr_rings; i++) {
5409 irq = &bp->irq_tbl[i];
5410 if (irq->requested)
5411 free_irq(irq->vector, bp->bnapi[i]);
5412 irq->requested = 0;
5413 }
Michael Chanc0c050c2015-10-22 16:01:17 -04005414}
5415
5416static int bnxt_request_irq(struct bnxt *bp)
5417{
Michael Chanb81a90d2016-01-02 23:45:01 -05005418 int i, j, rc = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04005419 unsigned long flags = 0;
5420#ifdef CONFIG_RFS_ACCEL
5421 struct cpu_rmap *rmap = bp->dev->rx_cpu_rmap;
5422#endif
5423
5424 if (!(bp->flags & BNXT_FLAG_USING_MSIX))
5425 flags = IRQF_SHARED;
5426
Michael Chanb81a90d2016-01-02 23:45:01 -05005427 for (i = 0, j = 0; i < bp->cp_nr_rings; i++) {
Michael Chanc0c050c2015-10-22 16:01:17 -04005428 struct bnxt_irq *irq = &bp->irq_tbl[i];
5429#ifdef CONFIG_RFS_ACCEL
Michael Chanb81a90d2016-01-02 23:45:01 -05005430 if (rmap && bp->bnapi[i]->rx_ring) {
Michael Chanc0c050c2015-10-22 16:01:17 -04005431 rc = irq_cpu_rmap_add(rmap, irq->vector);
5432 if (rc)
5433 netdev_warn(bp->dev, "failed adding irq rmap for ring %d\n",
Michael Chanb81a90d2016-01-02 23:45:01 -05005434 j);
5435 j++;
Michael Chanc0c050c2015-10-22 16:01:17 -04005436 }
5437#endif
5438 rc = request_irq(irq->vector, irq->handler, flags, irq->name,
5439 bp->bnapi[i]);
5440 if (rc)
5441 break;
5442
5443 irq->requested = 1;
5444 }
5445 return rc;
5446}
5447
5448static void bnxt_del_napi(struct bnxt *bp)
5449{
5450 int i;
5451
5452 if (!bp->bnapi)
5453 return;
5454
5455 for (i = 0; i < bp->cp_nr_rings; i++) {
5456 struct bnxt_napi *bnapi = bp->bnapi[i];
5457
5458 napi_hash_del(&bnapi->napi);
5459 netif_napi_del(&bnapi->napi);
5460 }
Eric Dumazete5f6f562016-11-16 06:31:52 -08005461 /* We called napi_hash_del() before netif_napi_del(), we need
5462 * to respect an RCU grace period before freeing napi structures.
5463 */
5464 synchronize_net();
Michael Chanc0c050c2015-10-22 16:01:17 -04005465}
5466
5467static void bnxt_init_napi(struct bnxt *bp)
5468{
5469 int i;
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04005470 unsigned int cp_nr_rings = bp->cp_nr_rings;
Michael Chanc0c050c2015-10-22 16:01:17 -04005471 struct bnxt_napi *bnapi;
5472
5473 if (bp->flags & BNXT_FLAG_USING_MSIX) {
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04005474 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
5475 cp_nr_rings--;
5476 for (i = 0; i < cp_nr_rings; i++) {
Michael Chanc0c050c2015-10-22 16:01:17 -04005477 bnapi = bp->bnapi[i];
5478 netif_napi_add(bp->dev, &bnapi->napi,
5479 bnxt_poll, 64);
Michael Chanc0c050c2015-10-22 16:01:17 -04005480 }
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04005481 if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
5482 bnapi = bp->bnapi[cp_nr_rings];
5483 netif_napi_add(bp->dev, &bnapi->napi,
5484 bnxt_poll_nitroa0, 64);
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04005485 }
Michael Chanc0c050c2015-10-22 16:01:17 -04005486 } else {
5487 bnapi = bp->bnapi[0];
5488 netif_napi_add(bp->dev, &bnapi->napi, bnxt_poll, 64);
Michael Chanc0c050c2015-10-22 16:01:17 -04005489 }
5490}
5491
5492static void bnxt_disable_napi(struct bnxt *bp)
5493{
5494 int i;
5495
5496 if (!bp->bnapi)
5497 return;
5498
Michael Chanb356a2e2016-12-29 12:13:31 -05005499 for (i = 0; i < bp->cp_nr_rings; i++)
Michael Chanc0c050c2015-10-22 16:01:17 -04005500 napi_disable(&bp->bnapi[i]->napi);
Michael Chanc0c050c2015-10-22 16:01:17 -04005501}
5502
5503static void bnxt_enable_napi(struct bnxt *bp)
5504{
5505 int i;
5506
5507 for (i = 0; i < bp->cp_nr_rings; i++) {
Michael Chanfa7e2812016-05-10 19:18:00 -04005508 bp->bnapi[i]->in_reset = false;
Michael Chanc0c050c2015-10-22 16:01:17 -04005509 napi_enable(&bp->bnapi[i]->napi);
5510 }
5511}
5512
Michael Chan7df4ae92016-12-02 21:17:17 -05005513void bnxt_tx_disable(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04005514{
5515 int i;
Michael Chanc0c050c2015-10-22 16:01:17 -04005516 struct bnxt_tx_ring_info *txr;
5517 struct netdev_queue *txq;
5518
Michael Chanb6ab4b02016-01-02 23:44:59 -05005519 if (bp->tx_ring) {
Michael Chanc0c050c2015-10-22 16:01:17 -04005520 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05005521 txr = &bp->tx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04005522 txq = netdev_get_tx_queue(bp->dev, i);
Michael Chanc0c050c2015-10-22 16:01:17 -04005523 txr->dev_state = BNXT_DEV_STATE_CLOSING;
Michael Chanc0c050c2015-10-22 16:01:17 -04005524 }
5525 }
5526 /* Stop all TX queues */
5527 netif_tx_disable(bp->dev);
5528 netif_carrier_off(bp->dev);
5529}
5530
Michael Chan7df4ae92016-12-02 21:17:17 -05005531void bnxt_tx_enable(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04005532{
5533 int i;
Michael Chanc0c050c2015-10-22 16:01:17 -04005534 struct bnxt_tx_ring_info *txr;
5535 struct netdev_queue *txq;
5536
5537 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05005538 txr = &bp->tx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04005539 txq = netdev_get_tx_queue(bp->dev, i);
5540 txr->dev_state = 0;
5541 }
5542 netif_tx_wake_all_queues(bp->dev);
5543 if (bp->link_info.link_up)
5544 netif_carrier_on(bp->dev);
5545}
5546
5547static void bnxt_report_link(struct bnxt *bp)
5548{
5549 if (bp->link_info.link_up) {
5550 const char *duplex;
5551 const char *flow_ctrl;
Deepak Khungar38a21b32017-04-21 20:11:24 -04005552 u32 speed;
5553 u16 fec;
Michael Chanc0c050c2015-10-22 16:01:17 -04005554
5555 netif_carrier_on(bp->dev);
5556 if (bp->link_info.duplex == BNXT_LINK_DUPLEX_FULL)
5557 duplex = "full";
5558 else
5559 duplex = "half";
5560 if (bp->link_info.pause == BNXT_LINK_PAUSE_BOTH)
5561 flow_ctrl = "ON - receive & transmit";
5562 else if (bp->link_info.pause == BNXT_LINK_PAUSE_TX)
5563 flow_ctrl = "ON - transmit";
5564 else if (bp->link_info.pause == BNXT_LINK_PAUSE_RX)
5565 flow_ctrl = "ON - receive";
5566 else
5567 flow_ctrl = "none";
5568 speed = bnxt_fw_to_ethtool_speed(bp->link_info.link_speed);
Deepak Khungar38a21b32017-04-21 20:11:24 -04005569 netdev_info(bp->dev, "NIC Link is Up, %u Mbps %s duplex, Flow control: %s\n",
Michael Chanc0c050c2015-10-22 16:01:17 -04005570 speed, duplex, flow_ctrl);
Michael Chan170ce012016-04-05 14:08:57 -04005571 if (bp->flags & BNXT_FLAG_EEE_CAP)
5572 netdev_info(bp->dev, "EEE is %s\n",
5573 bp->eee.eee_active ? "active" :
5574 "not active");
Michael Chane70c7522017-02-12 19:18:16 -05005575 fec = bp->link_info.fec_cfg;
5576 if (!(fec & PORT_PHY_QCFG_RESP_FEC_CFG_FEC_NONE_SUPPORTED))
5577 netdev_info(bp->dev, "FEC autoneg %s encodings: %s\n",
5578 (fec & BNXT_FEC_AUTONEG) ? "on" : "off",
5579 (fec & BNXT_FEC_ENC_BASE_R) ? "BaseR" :
5580 (fec & BNXT_FEC_ENC_RS) ? "RS" : "None");
Michael Chanc0c050c2015-10-22 16:01:17 -04005581 } else {
5582 netif_carrier_off(bp->dev);
5583 netdev_err(bp->dev, "NIC Link is Down\n");
5584 }
5585}
5586
Michael Chan170ce012016-04-05 14:08:57 -04005587static int bnxt_hwrm_phy_qcaps(struct bnxt *bp)
5588{
5589 int rc = 0;
5590 struct hwrm_port_phy_qcaps_input req = {0};
5591 struct hwrm_port_phy_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
Michael Chan93ed8112016-06-13 02:25:37 -04005592 struct bnxt_link_info *link_info = &bp->link_info;
Michael Chan170ce012016-04-05 14:08:57 -04005593
5594 if (bp->hwrm_spec_code < 0x10201)
5595 return 0;
5596
5597 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCAPS, -1, -1);
5598
5599 mutex_lock(&bp->hwrm_cmd_lock);
5600 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5601 if (rc)
5602 goto hwrm_phy_qcaps_exit;
5603
5604 if (resp->eee_supported & PORT_PHY_QCAPS_RESP_EEE_SUPPORTED) {
5605 struct ethtool_eee *eee = &bp->eee;
5606 u16 fw_speeds = le16_to_cpu(resp->supported_speeds_eee_mode);
5607
5608 bp->flags |= BNXT_FLAG_EEE_CAP;
5609 eee->supported = _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0);
5610 bp->lpi_tmr_lo = le32_to_cpu(resp->tx_lpi_timer_low) &
5611 PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_LOW_MASK;
5612 bp->lpi_tmr_hi = le32_to_cpu(resp->valid_tx_lpi_timer_high) &
5613 PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_HIGH_MASK;
5614 }
Michael Chan520ad892017-03-08 18:44:35 -05005615 if (resp->supported_speeds_auto_mode)
5616 link_info->support_auto_speeds =
5617 le16_to_cpu(resp->supported_speeds_auto_mode);
Michael Chan170ce012016-04-05 14:08:57 -04005618
5619hwrm_phy_qcaps_exit:
5620 mutex_unlock(&bp->hwrm_cmd_lock);
5621 return rc;
5622}
5623
Michael Chanc0c050c2015-10-22 16:01:17 -04005624static int bnxt_update_link(struct bnxt *bp, bool chng_link_state)
5625{
5626 int rc = 0;
5627 struct bnxt_link_info *link_info = &bp->link_info;
5628 struct hwrm_port_phy_qcfg_input req = {0};
5629 struct hwrm_port_phy_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
5630 u8 link_up = link_info->link_up;
Michael Chan286ef9d2016-11-16 21:13:08 -05005631 u16 diff;
Michael Chanc0c050c2015-10-22 16:01:17 -04005632
5633 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCFG, -1, -1);
5634
5635 mutex_lock(&bp->hwrm_cmd_lock);
5636 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5637 if (rc) {
5638 mutex_unlock(&bp->hwrm_cmd_lock);
5639 return rc;
5640 }
5641
5642 memcpy(&link_info->phy_qcfg_resp, resp, sizeof(*resp));
5643 link_info->phy_link_status = resp->link;
5644 link_info->duplex = resp->duplex;
5645 link_info->pause = resp->pause;
5646 link_info->auto_mode = resp->auto_mode;
5647 link_info->auto_pause_setting = resp->auto_pause;
Michael Chan32773602016-03-07 15:38:42 -05005648 link_info->lp_pause = resp->link_partner_adv_pause;
Michael Chanc0c050c2015-10-22 16:01:17 -04005649 link_info->force_pause_setting = resp->force_pause;
Michael Chanc1935542015-12-27 18:19:28 -05005650 link_info->duplex_setting = resp->duplex;
Michael Chanc0c050c2015-10-22 16:01:17 -04005651 if (link_info->phy_link_status == BNXT_LINK_LINK)
5652 link_info->link_speed = le16_to_cpu(resp->link_speed);
5653 else
5654 link_info->link_speed = 0;
5655 link_info->force_link_speed = le16_to_cpu(resp->force_link_speed);
Michael Chanc0c050c2015-10-22 16:01:17 -04005656 link_info->support_speeds = le16_to_cpu(resp->support_speeds);
5657 link_info->auto_link_speeds = le16_to_cpu(resp->auto_link_speed_mask);
Michael Chan32773602016-03-07 15:38:42 -05005658 link_info->lp_auto_link_speeds =
5659 le16_to_cpu(resp->link_partner_adv_speeds);
Michael Chanc0c050c2015-10-22 16:01:17 -04005660 link_info->preemphasis = le32_to_cpu(resp->preemphasis);
5661 link_info->phy_ver[0] = resp->phy_maj;
5662 link_info->phy_ver[1] = resp->phy_min;
5663 link_info->phy_ver[2] = resp->phy_bld;
5664 link_info->media_type = resp->media_type;
Michael Chan03efbec2016-04-11 04:11:11 -04005665 link_info->phy_type = resp->phy_type;
Michael Chan11f15ed2016-04-05 14:08:55 -04005666 link_info->transceiver = resp->xcvr_pkg_type;
Michael Chan170ce012016-04-05 14:08:57 -04005667 link_info->phy_addr = resp->eee_config_phy_addr &
5668 PORT_PHY_QCFG_RESP_PHY_ADDR_MASK;
Ajit Khaparde42ee18f2016-05-15 03:04:44 -04005669 link_info->module_status = resp->module_status;
Michael Chanc0c050c2015-10-22 16:01:17 -04005670
Michael Chan170ce012016-04-05 14:08:57 -04005671 if (bp->flags & BNXT_FLAG_EEE_CAP) {
5672 struct ethtool_eee *eee = &bp->eee;
5673 u16 fw_speeds;
5674
5675 eee->eee_active = 0;
5676 if (resp->eee_config_phy_addr &
5677 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ACTIVE) {
5678 eee->eee_active = 1;
5679 fw_speeds = le16_to_cpu(
5680 resp->link_partner_adv_eee_link_speed_mask);
5681 eee->lp_advertised =
5682 _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0);
5683 }
5684
5685 /* Pull initial EEE config */
5686 if (!chng_link_state) {
5687 if (resp->eee_config_phy_addr &
5688 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ENABLED)
5689 eee->eee_enabled = 1;
5690
5691 fw_speeds = le16_to_cpu(resp->adv_eee_link_speed_mask);
5692 eee->advertised =
5693 _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0);
5694
5695 if (resp->eee_config_phy_addr &
5696 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_TX_LPI) {
5697 __le32 tmr;
5698
5699 eee->tx_lpi_enabled = 1;
5700 tmr = resp->xcvr_identifier_type_tx_lpi_timer;
5701 eee->tx_lpi_timer = le32_to_cpu(tmr) &
5702 PORT_PHY_QCFG_RESP_TX_LPI_TIMER_MASK;
5703 }
5704 }
5705 }
Michael Chane70c7522017-02-12 19:18:16 -05005706
5707 link_info->fec_cfg = PORT_PHY_QCFG_RESP_FEC_CFG_FEC_NONE_SUPPORTED;
5708 if (bp->hwrm_spec_code >= 0x10504)
5709 link_info->fec_cfg = le16_to_cpu(resp->fec_cfg);
5710
Michael Chanc0c050c2015-10-22 16:01:17 -04005711 /* TODO: need to add more logic to report VF link */
5712 if (chng_link_state) {
5713 if (link_info->phy_link_status == BNXT_LINK_LINK)
5714 link_info->link_up = 1;
5715 else
5716 link_info->link_up = 0;
5717 if (link_up != link_info->link_up)
5718 bnxt_report_link(bp);
5719 } else {
5720 /* alwasy link down if not require to update link state */
5721 link_info->link_up = 0;
5722 }
5723 mutex_unlock(&bp->hwrm_cmd_lock);
Michael Chan286ef9d2016-11-16 21:13:08 -05005724
5725 diff = link_info->support_auto_speeds ^ link_info->advertising;
5726 if ((link_info->support_auto_speeds | diff) !=
5727 link_info->support_auto_speeds) {
5728 /* An advertised speed is no longer supported, so we need to
Michael Chan0eaa24b2017-01-25 02:55:08 -05005729 * update the advertisement settings. Caller holds RTNL
5730 * so we can modify link settings.
Michael Chan286ef9d2016-11-16 21:13:08 -05005731 */
Michael Chan286ef9d2016-11-16 21:13:08 -05005732 link_info->advertising = link_info->support_auto_speeds;
Michael Chan0eaa24b2017-01-25 02:55:08 -05005733 if (link_info->autoneg & BNXT_AUTONEG_SPEED)
Michael Chan286ef9d2016-11-16 21:13:08 -05005734 bnxt_hwrm_set_link_setting(bp, true, false);
Michael Chan286ef9d2016-11-16 21:13:08 -05005735 }
Michael Chanc0c050c2015-10-22 16:01:17 -04005736 return 0;
5737}
5738
Michael Chan10289be2016-05-15 03:04:49 -04005739static void bnxt_get_port_module_status(struct bnxt *bp)
5740{
5741 struct bnxt_link_info *link_info = &bp->link_info;
5742 struct hwrm_port_phy_qcfg_output *resp = &link_info->phy_qcfg_resp;
5743 u8 module_status;
5744
5745 if (bnxt_update_link(bp, true))
5746 return;
5747
5748 module_status = link_info->module_status;
5749 switch (module_status) {
5750 case PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX:
5751 case PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN:
5752 case PORT_PHY_QCFG_RESP_MODULE_STATUS_WARNINGMSG:
5753 netdev_warn(bp->dev, "Unqualified SFP+ module detected on port %d\n",
5754 bp->pf.port_id);
5755 if (bp->hwrm_spec_code >= 0x10201) {
5756 netdev_warn(bp->dev, "Module part number %s\n",
5757 resp->phy_vendor_partnumber);
5758 }
5759 if (module_status == PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX)
5760 netdev_warn(bp->dev, "TX is disabled\n");
5761 if (module_status == PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN)
5762 netdev_warn(bp->dev, "SFP+ module is shutdown\n");
5763 }
5764}
5765
Michael Chanc0c050c2015-10-22 16:01:17 -04005766static void
5767bnxt_hwrm_set_pause_common(struct bnxt *bp, struct hwrm_port_phy_cfg_input *req)
5768{
5769 if (bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL) {
Michael Chanc9ee9512016-04-05 14:08:56 -04005770 if (bp->hwrm_spec_code >= 0x10201)
5771 req->auto_pause =
5772 PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE;
Michael Chanc0c050c2015-10-22 16:01:17 -04005773 if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_RX)
5774 req->auto_pause |= PORT_PHY_CFG_REQ_AUTO_PAUSE_RX;
5775 if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_TX)
Michael Chan49b5c7a2016-03-28 19:46:06 -04005776 req->auto_pause |= PORT_PHY_CFG_REQ_AUTO_PAUSE_TX;
Michael Chanc0c050c2015-10-22 16:01:17 -04005777 req->enables |=
5778 cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE);
5779 } else {
5780 if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_RX)
5781 req->force_pause |= PORT_PHY_CFG_REQ_FORCE_PAUSE_RX;
5782 if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_TX)
5783 req->force_pause |= PORT_PHY_CFG_REQ_FORCE_PAUSE_TX;
5784 req->enables |=
5785 cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_FORCE_PAUSE);
Michael Chanc9ee9512016-04-05 14:08:56 -04005786 if (bp->hwrm_spec_code >= 0x10201) {
5787 req->auto_pause = req->force_pause;
5788 req->enables |= cpu_to_le32(
5789 PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE);
5790 }
Michael Chanc0c050c2015-10-22 16:01:17 -04005791 }
5792}
5793
5794static void bnxt_hwrm_set_link_common(struct bnxt *bp,
5795 struct hwrm_port_phy_cfg_input *req)
5796{
5797 u8 autoneg = bp->link_info.autoneg;
5798 u16 fw_link_speed = bp->link_info.req_link_speed;
Michael Chan68515a12016-12-29 12:13:34 -05005799 u16 advertising = bp->link_info.advertising;
Michael Chanc0c050c2015-10-22 16:01:17 -04005800
5801 if (autoneg & BNXT_AUTONEG_SPEED) {
5802 req->auto_mode |=
Michael Chan11f15ed2016-04-05 14:08:55 -04005803 PORT_PHY_CFG_REQ_AUTO_MODE_SPEED_MASK;
Michael Chanc0c050c2015-10-22 16:01:17 -04005804
5805 req->enables |= cpu_to_le32(
5806 PORT_PHY_CFG_REQ_ENABLES_AUTO_LINK_SPEED_MASK);
5807 req->auto_link_speed_mask = cpu_to_le16(advertising);
5808
5809 req->enables |= cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_MODE);
5810 req->flags |=
5811 cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESTART_AUTONEG);
5812 } else {
5813 req->force_link_speed = cpu_to_le16(fw_link_speed);
5814 req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE);
5815 }
5816
Michael Chanc0c050c2015-10-22 16:01:17 -04005817 /* tell chimp that the setting takes effect immediately */
5818 req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESET_PHY);
5819}
5820
5821int bnxt_hwrm_set_pause(struct bnxt *bp)
5822{
5823 struct hwrm_port_phy_cfg_input req = {0};
5824 int rc;
5825
5826 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1);
5827 bnxt_hwrm_set_pause_common(bp, &req);
5828
5829 if ((bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL) ||
5830 bp->link_info.force_link_chng)
5831 bnxt_hwrm_set_link_common(bp, &req);
5832
5833 mutex_lock(&bp->hwrm_cmd_lock);
5834 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5835 if (!rc && !(bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL)) {
5836 /* since changing of pause setting doesn't trigger any link
5837 * change event, the driver needs to update the current pause
5838 * result upon successfully return of the phy_cfg command
5839 */
5840 bp->link_info.pause =
5841 bp->link_info.force_pause_setting = bp->link_info.req_flow_ctrl;
5842 bp->link_info.auto_pause_setting = 0;
5843 if (!bp->link_info.force_link_chng)
5844 bnxt_report_link(bp);
5845 }
5846 bp->link_info.force_link_chng = false;
5847 mutex_unlock(&bp->hwrm_cmd_lock);
5848 return rc;
5849}
5850
Michael Chan939f7f02016-04-05 14:08:58 -04005851static void bnxt_hwrm_set_eee(struct bnxt *bp,
5852 struct hwrm_port_phy_cfg_input *req)
5853{
5854 struct ethtool_eee *eee = &bp->eee;
5855
5856 if (eee->eee_enabled) {
5857 u16 eee_speeds;
5858 u32 flags = PORT_PHY_CFG_REQ_FLAGS_EEE_ENABLE;
5859
5860 if (eee->tx_lpi_enabled)
5861 flags |= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_ENABLE;
5862 else
5863 flags |= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_DISABLE;
5864
5865 req->flags |= cpu_to_le32(flags);
5866 eee_speeds = bnxt_get_fw_auto_link_speeds(eee->advertised);
5867 req->eee_link_speed_mask = cpu_to_le16(eee_speeds);
5868 req->tx_lpi_timer = cpu_to_le32(eee->tx_lpi_timer);
5869 } else {
5870 req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_EEE_DISABLE);
5871 }
5872}
5873
5874int bnxt_hwrm_set_link_setting(struct bnxt *bp, bool set_pause, bool set_eee)
Michael Chanc0c050c2015-10-22 16:01:17 -04005875{
5876 struct hwrm_port_phy_cfg_input req = {0};
5877
5878 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1);
5879 if (set_pause)
5880 bnxt_hwrm_set_pause_common(bp, &req);
5881
5882 bnxt_hwrm_set_link_common(bp, &req);
Michael Chan939f7f02016-04-05 14:08:58 -04005883
5884 if (set_eee)
5885 bnxt_hwrm_set_eee(bp, &req);
Michael Chanc0c050c2015-10-22 16:01:17 -04005886 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5887}
5888
Michael Chan33f7d552016-04-11 04:11:12 -04005889static int bnxt_hwrm_shutdown_link(struct bnxt *bp)
5890{
5891 struct hwrm_port_phy_cfg_input req = {0};
5892
Satish Baddipadige567b2ab2016-06-13 02:25:31 -04005893 if (!BNXT_SINGLE_PF(bp))
Michael Chan33f7d552016-04-11 04:11:12 -04005894 return 0;
5895
5896 if (pci_num_vf(bp->pdev))
5897 return 0;
5898
5899 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1);
Michael Chan16d663a2016-11-16 21:13:07 -05005900 req.flags = cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE_LINK_DWN);
Michael Chan33f7d552016-04-11 04:11:12 -04005901 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5902}
5903
Michael Chan5ad2cbe2017-01-13 01:32:03 -05005904static int bnxt_hwrm_port_led_qcaps(struct bnxt *bp)
5905{
5906 struct hwrm_port_led_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
5907 struct hwrm_port_led_qcaps_input req = {0};
5908 struct bnxt_pf_info *pf = &bp->pf;
5909 int rc;
5910
5911 if (BNXT_VF(bp) || bp->hwrm_spec_code < 0x10601)
5912 return 0;
5913
5914 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_LED_QCAPS, -1, -1);
5915 req.port_id = cpu_to_le16(pf->port_id);
5916 mutex_lock(&bp->hwrm_cmd_lock);
5917 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5918 if (rc) {
5919 mutex_unlock(&bp->hwrm_cmd_lock);
5920 return rc;
5921 }
5922 if (resp->num_leds > 0 && resp->num_leds < BNXT_MAX_LED) {
5923 int i;
5924
5925 bp->num_leds = resp->num_leds;
5926 memcpy(bp->leds, &resp->led0_id, sizeof(bp->leds[0]) *
5927 bp->num_leds);
5928 for (i = 0; i < bp->num_leds; i++) {
5929 struct bnxt_led_info *led = &bp->leds[i];
5930 __le16 caps = led->led_state_caps;
5931
5932 if (!led->led_group_id ||
5933 !BNXT_LED_ALT_BLINK_CAP(caps)) {
5934 bp->num_leds = 0;
5935 break;
5936 }
5937 }
5938 }
5939 mutex_unlock(&bp->hwrm_cmd_lock);
5940 return 0;
5941}
5942
Michael Chan5282db62017-04-04 18:14:10 -04005943int bnxt_hwrm_alloc_wol_fltr(struct bnxt *bp)
5944{
5945 struct hwrm_wol_filter_alloc_input req = {0};
5946 struct hwrm_wol_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr;
5947 int rc;
5948
5949 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_WOL_FILTER_ALLOC, -1, -1);
5950 req.port_id = cpu_to_le16(bp->pf.port_id);
5951 req.wol_type = WOL_FILTER_ALLOC_REQ_WOL_TYPE_MAGICPKT;
5952 req.enables = cpu_to_le32(WOL_FILTER_ALLOC_REQ_ENABLES_MAC_ADDRESS);
5953 memcpy(req.mac_address, bp->dev->dev_addr, ETH_ALEN);
5954 mutex_lock(&bp->hwrm_cmd_lock);
5955 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5956 if (!rc)
5957 bp->wol_filter_id = resp->wol_filter_id;
5958 mutex_unlock(&bp->hwrm_cmd_lock);
5959 return rc;
5960}
5961
5962int bnxt_hwrm_free_wol_fltr(struct bnxt *bp)
5963{
5964 struct hwrm_wol_filter_free_input req = {0};
5965 int rc;
5966
5967 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_WOL_FILTER_FREE, -1, -1);
5968 req.port_id = cpu_to_le16(bp->pf.port_id);
5969 req.enables = cpu_to_le32(WOL_FILTER_FREE_REQ_ENABLES_WOL_FILTER_ID);
5970 req.wol_filter_id = bp->wol_filter_id;
5971 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5972 return rc;
5973}
5974
Michael Chanc1ef1462017-04-04 18:14:07 -04005975static u16 bnxt_hwrm_get_wol_fltrs(struct bnxt *bp, u16 handle)
5976{
5977 struct hwrm_wol_filter_qcfg_input req = {0};
5978 struct hwrm_wol_filter_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
5979 u16 next_handle = 0;
5980 int rc;
5981
5982 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_WOL_FILTER_QCFG, -1, -1);
5983 req.port_id = cpu_to_le16(bp->pf.port_id);
5984 req.handle = cpu_to_le16(handle);
5985 mutex_lock(&bp->hwrm_cmd_lock);
5986 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5987 if (!rc) {
5988 next_handle = le16_to_cpu(resp->next_handle);
5989 if (next_handle != 0) {
5990 if (resp->wol_type ==
5991 WOL_FILTER_ALLOC_REQ_WOL_TYPE_MAGICPKT) {
5992 bp->wol = 1;
5993 bp->wol_filter_id = resp->wol_filter_id;
5994 }
5995 }
5996 }
5997 mutex_unlock(&bp->hwrm_cmd_lock);
5998 return next_handle;
5999}
6000
6001static void bnxt_get_wol_settings(struct bnxt *bp)
6002{
6003 u16 handle = 0;
6004
6005 if (!BNXT_PF(bp) || !(bp->flags & BNXT_FLAG_WOL_CAP))
6006 return;
6007
6008 do {
6009 handle = bnxt_hwrm_get_wol_fltrs(bp, handle);
6010 } while (handle && handle != 0xffff);
6011}
6012
Michael Chan939f7f02016-04-05 14:08:58 -04006013static bool bnxt_eee_config_ok(struct bnxt *bp)
6014{
6015 struct ethtool_eee *eee = &bp->eee;
6016 struct bnxt_link_info *link_info = &bp->link_info;
6017
6018 if (!(bp->flags & BNXT_FLAG_EEE_CAP))
6019 return true;
6020
6021 if (eee->eee_enabled) {
6022 u32 advertising =
6023 _bnxt_fw_to_ethtool_adv_spds(link_info->advertising, 0);
6024
6025 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) {
6026 eee->eee_enabled = 0;
6027 return false;
6028 }
6029 if (eee->advertised & ~advertising) {
6030 eee->advertised = advertising & eee->supported;
6031 return false;
6032 }
6033 }
6034 return true;
6035}
6036
Michael Chanc0c050c2015-10-22 16:01:17 -04006037static int bnxt_update_phy_setting(struct bnxt *bp)
6038{
6039 int rc;
6040 bool update_link = false;
6041 bool update_pause = false;
Michael Chan939f7f02016-04-05 14:08:58 -04006042 bool update_eee = false;
Michael Chanc0c050c2015-10-22 16:01:17 -04006043 struct bnxt_link_info *link_info = &bp->link_info;
6044
6045 rc = bnxt_update_link(bp, true);
6046 if (rc) {
6047 netdev_err(bp->dev, "failed to update link (rc: %x)\n",
6048 rc);
6049 return rc;
6050 }
Michael Chan33dac242017-02-12 19:18:15 -05006051 if (!BNXT_SINGLE_PF(bp))
6052 return 0;
6053
Michael Chanc0c050c2015-10-22 16:01:17 -04006054 if ((link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) &&
Michael Chanc9ee9512016-04-05 14:08:56 -04006055 (link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH) !=
6056 link_info->req_flow_ctrl)
Michael Chanc0c050c2015-10-22 16:01:17 -04006057 update_pause = true;
6058 if (!(link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) &&
6059 link_info->force_pause_setting != link_info->req_flow_ctrl)
6060 update_pause = true;
Michael Chanc0c050c2015-10-22 16:01:17 -04006061 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) {
6062 if (BNXT_AUTO_MODE(link_info->auto_mode))
6063 update_link = true;
6064 if (link_info->req_link_speed != link_info->force_link_speed)
6065 update_link = true;
Michael Chande730182016-02-19 19:43:20 -05006066 if (link_info->req_duplex != link_info->duplex_setting)
6067 update_link = true;
Michael Chanc0c050c2015-10-22 16:01:17 -04006068 } else {
6069 if (link_info->auto_mode == BNXT_LINK_AUTO_NONE)
6070 update_link = true;
6071 if (link_info->advertising != link_info->auto_link_speeds)
6072 update_link = true;
Michael Chanc0c050c2015-10-22 16:01:17 -04006073 }
6074
Michael Chan16d663a2016-11-16 21:13:07 -05006075 /* The last close may have shutdown the link, so need to call
6076 * PHY_CFG to bring it back up.
6077 */
6078 if (!netif_carrier_ok(bp->dev))
6079 update_link = true;
6080
Michael Chan939f7f02016-04-05 14:08:58 -04006081 if (!bnxt_eee_config_ok(bp))
6082 update_eee = true;
6083
Michael Chanc0c050c2015-10-22 16:01:17 -04006084 if (update_link)
Michael Chan939f7f02016-04-05 14:08:58 -04006085 rc = bnxt_hwrm_set_link_setting(bp, update_pause, update_eee);
Michael Chanc0c050c2015-10-22 16:01:17 -04006086 else if (update_pause)
6087 rc = bnxt_hwrm_set_pause(bp);
6088 if (rc) {
6089 netdev_err(bp->dev, "failed to update phy setting (rc: %x)\n",
6090 rc);
6091 return rc;
6092 }
6093
6094 return rc;
6095}
6096
Jeffrey Huang11809492015-11-05 16:25:49 -05006097/* Common routine to pre-map certain register block to different GRC window.
6098 * A PF has 16 4K windows and a VF has 4 4K windows. However, only 15 windows
6099 * in PF and 3 windows in VF that can be customized to map in different
6100 * register blocks.
6101 */
6102static void bnxt_preset_reg_win(struct bnxt *bp)
6103{
6104 if (BNXT_PF(bp)) {
6105 /* CAG registers map to GRC window #4 */
6106 writel(BNXT_CAG_REG_BASE,
6107 bp->bar0 + BNXT_GRCPF_REG_WINDOW_BASE_OUT + 12);
6108 }
6109}
6110
Michael Chanc0c050c2015-10-22 16:01:17 -04006111static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
6112{
6113 int rc = 0;
6114
Jeffrey Huang11809492015-11-05 16:25:49 -05006115 bnxt_preset_reg_win(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04006116 netif_carrier_off(bp->dev);
6117 if (irq_re_init) {
6118 rc = bnxt_setup_int_mode(bp);
6119 if (rc) {
6120 netdev_err(bp->dev, "bnxt_setup_int_mode err: %x\n",
6121 rc);
6122 return rc;
6123 }
6124 }
6125 if ((bp->flags & BNXT_FLAG_RFS) &&
6126 !(bp->flags & BNXT_FLAG_USING_MSIX)) {
6127 /* disable RFS if falling back to INTA */
6128 bp->dev->hw_features &= ~NETIF_F_NTUPLE;
6129 bp->flags &= ~BNXT_FLAG_RFS;
6130 }
6131
6132 rc = bnxt_alloc_mem(bp, irq_re_init);
6133 if (rc) {
6134 netdev_err(bp->dev, "bnxt_alloc_mem err: %x\n", rc);
6135 goto open_err_free_mem;
6136 }
6137
6138 if (irq_re_init) {
6139 bnxt_init_napi(bp);
6140 rc = bnxt_request_irq(bp);
6141 if (rc) {
6142 netdev_err(bp->dev, "bnxt_request_irq err: %x\n", rc);
6143 goto open_err;
6144 }
6145 }
6146
6147 bnxt_enable_napi(bp);
6148
6149 rc = bnxt_init_nic(bp, irq_re_init);
6150 if (rc) {
6151 netdev_err(bp->dev, "bnxt_init_nic err: %x\n", rc);
6152 goto open_err;
6153 }
6154
6155 if (link_re_init) {
6156 rc = bnxt_update_phy_setting(bp);
6157 if (rc)
Michael Chanba41d462016-02-19 19:43:21 -05006158 netdev_warn(bp->dev, "failed to update phy settings\n");
Michael Chanc0c050c2015-10-22 16:01:17 -04006159 }
6160
Alexander Duyck7cdd5fc2016-06-16 12:21:36 -07006161 if (irq_re_init)
Alexander Duyckad51b8e2016-06-16 12:21:19 -07006162 udp_tunnel_get_rx_info(bp->dev);
Michael Chanc0c050c2015-10-22 16:01:17 -04006163
Michael Chancaefe522015-12-09 19:35:42 -05006164 set_bit(BNXT_STATE_OPEN, &bp->state);
Michael Chanc0c050c2015-10-22 16:01:17 -04006165 bnxt_enable_int(bp);
6166 /* Enable TX queues */
6167 bnxt_tx_enable(bp);
6168 mod_timer(&bp->timer, jiffies + bp->current_interval);
Michael Chan10289be2016-05-15 03:04:49 -04006169 /* Poll link status and check for SFP+ module status */
6170 bnxt_get_port_module_status(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04006171
6172 return 0;
6173
6174open_err:
6175 bnxt_disable_napi(bp);
6176 bnxt_del_napi(bp);
6177
6178open_err_free_mem:
6179 bnxt_free_skbs(bp);
6180 bnxt_free_irq(bp);
6181 bnxt_free_mem(bp, true);
6182 return rc;
6183}
6184
6185/* rtnl_lock held */
6186int bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
6187{
6188 int rc = 0;
6189
6190 rc = __bnxt_open_nic(bp, irq_re_init, link_re_init);
6191 if (rc) {
6192 netdev_err(bp->dev, "nic open fail (rc: %x)\n", rc);
6193 dev_close(bp->dev);
6194 }
6195 return rc;
6196}
6197
Michael Chanf7dc1ea2017-04-04 18:14:13 -04006198/* rtnl_lock held, open the NIC half way by allocating all resources, but
6199 * NAPI, IRQ, and TX are not enabled. This is mainly used for offline
6200 * self tests.
6201 */
6202int bnxt_half_open_nic(struct bnxt *bp)
6203{
6204 int rc = 0;
6205
6206 rc = bnxt_alloc_mem(bp, false);
6207 if (rc) {
6208 netdev_err(bp->dev, "bnxt_alloc_mem err: %x\n", rc);
6209 goto half_open_err;
6210 }
6211 rc = bnxt_init_nic(bp, false);
6212 if (rc) {
6213 netdev_err(bp->dev, "bnxt_init_nic err: %x\n", rc);
6214 goto half_open_err;
6215 }
6216 return 0;
6217
6218half_open_err:
6219 bnxt_free_skbs(bp);
6220 bnxt_free_mem(bp, false);
6221 dev_close(bp->dev);
6222 return rc;
6223}
6224
6225/* rtnl_lock held, this call can only be made after a previous successful
6226 * call to bnxt_half_open_nic().
6227 */
6228void bnxt_half_close_nic(struct bnxt *bp)
6229{
6230 bnxt_hwrm_resource_free(bp, false, false);
6231 bnxt_free_skbs(bp);
6232 bnxt_free_mem(bp, false);
6233}
6234
Michael Chanc0c050c2015-10-22 16:01:17 -04006235static int bnxt_open(struct net_device *dev)
6236{
6237 struct bnxt *bp = netdev_priv(dev);
Michael Chanc0c050c2015-10-22 16:01:17 -04006238
Michael Chanc0c050c2015-10-22 16:01:17 -04006239 return __bnxt_open_nic(bp, true, true);
6240}
6241
Michael Chanc0c050c2015-10-22 16:01:17 -04006242int bnxt_close_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
6243{
6244 int rc = 0;
6245
6246#ifdef CONFIG_BNXT_SRIOV
6247 if (bp->sriov_cfg) {
6248 rc = wait_event_interruptible_timeout(bp->sriov_cfg_wait,
6249 !bp->sriov_cfg,
6250 BNXT_SRIOV_CFG_WAIT_TMO);
6251 if (rc)
6252 netdev_warn(bp->dev, "timeout waiting for SRIOV config operation to complete!\n");
6253 }
6254#endif
6255 /* Change device state to avoid TX queue wake up's */
6256 bnxt_tx_disable(bp);
6257
Michael Chancaefe522015-12-09 19:35:42 -05006258 clear_bit(BNXT_STATE_OPEN, &bp->state);
Michael Chan4cebdce2015-12-09 19:35:43 -05006259 smp_mb__after_atomic();
6260 while (test_bit(BNXT_STATE_IN_SP_TASK, &bp->state))
6261 msleep(20);
Michael Chanc0c050c2015-10-22 16:01:17 -04006262
Michael Chan9d8bc092016-12-29 12:13:33 -05006263 /* Flush rings and and disable interrupts */
Michael Chanc0c050c2015-10-22 16:01:17 -04006264 bnxt_shutdown_nic(bp, irq_re_init);
6265
6266 /* TODO CHIMP_FW: Link/PHY related cleanup if (link_re_init) */
6267
6268 bnxt_disable_napi(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04006269 del_timer_sync(&bp->timer);
6270 bnxt_free_skbs(bp);
6271
6272 if (irq_re_init) {
6273 bnxt_free_irq(bp);
6274 bnxt_del_napi(bp);
6275 }
6276 bnxt_free_mem(bp, irq_re_init);
6277 return rc;
6278}
6279
6280static int bnxt_close(struct net_device *dev)
6281{
6282 struct bnxt *bp = netdev_priv(dev);
6283
6284 bnxt_close_nic(bp, true, true);
Michael Chan33f7d552016-04-11 04:11:12 -04006285 bnxt_hwrm_shutdown_link(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04006286 return 0;
6287}
6288
6289/* rtnl_lock held */
6290static int bnxt_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
6291{
6292 switch (cmd) {
6293 case SIOCGMIIPHY:
6294 /* fallthru */
6295 case SIOCGMIIREG: {
6296 if (!netif_running(dev))
6297 return -EAGAIN;
6298
6299 return 0;
6300 }
6301
6302 case SIOCSMIIREG:
6303 if (!netif_running(dev))
6304 return -EAGAIN;
6305
6306 return 0;
6307
6308 default:
6309 /* do nothing */
6310 break;
6311 }
6312 return -EOPNOTSUPP;
6313}
6314
stephen hemmingerbc1f4472017-01-06 19:12:52 -08006315static void
Michael Chanc0c050c2015-10-22 16:01:17 -04006316bnxt_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
6317{
6318 u32 i;
6319 struct bnxt *bp = netdev_priv(dev);
6320
Michael Chanc0c050c2015-10-22 16:01:17 -04006321 if (!bp->bnapi)
stephen hemmingerbc1f4472017-01-06 19:12:52 -08006322 return;
Michael Chanc0c050c2015-10-22 16:01:17 -04006323
6324 /* TODO check if we need to synchronize with bnxt_close path */
6325 for (i = 0; i < bp->cp_nr_rings; i++) {
6326 struct bnxt_napi *bnapi = bp->bnapi[i];
6327 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
6328 struct ctx_hw_stats *hw_stats = cpr->hw_stats;
6329
6330 stats->rx_packets += le64_to_cpu(hw_stats->rx_ucast_pkts);
6331 stats->rx_packets += le64_to_cpu(hw_stats->rx_mcast_pkts);
6332 stats->rx_packets += le64_to_cpu(hw_stats->rx_bcast_pkts);
6333
6334 stats->tx_packets += le64_to_cpu(hw_stats->tx_ucast_pkts);
6335 stats->tx_packets += le64_to_cpu(hw_stats->tx_mcast_pkts);
6336 stats->tx_packets += le64_to_cpu(hw_stats->tx_bcast_pkts);
6337
6338 stats->rx_bytes += le64_to_cpu(hw_stats->rx_ucast_bytes);
6339 stats->rx_bytes += le64_to_cpu(hw_stats->rx_mcast_bytes);
6340 stats->rx_bytes += le64_to_cpu(hw_stats->rx_bcast_bytes);
6341
6342 stats->tx_bytes += le64_to_cpu(hw_stats->tx_ucast_bytes);
6343 stats->tx_bytes += le64_to_cpu(hw_stats->tx_mcast_bytes);
6344 stats->tx_bytes += le64_to_cpu(hw_stats->tx_bcast_bytes);
6345
6346 stats->rx_missed_errors +=
6347 le64_to_cpu(hw_stats->rx_discard_pkts);
6348
6349 stats->multicast += le64_to_cpu(hw_stats->rx_mcast_pkts);
6350
Michael Chanc0c050c2015-10-22 16:01:17 -04006351 stats->tx_dropped += le64_to_cpu(hw_stats->tx_drop_pkts);
6352 }
6353
Michael Chan9947f832016-03-07 15:38:46 -05006354 if (bp->flags & BNXT_FLAG_PORT_STATS) {
6355 struct rx_port_stats *rx = bp->hw_rx_port_stats;
6356 struct tx_port_stats *tx = bp->hw_tx_port_stats;
6357
6358 stats->rx_crc_errors = le64_to_cpu(rx->rx_fcs_err_frames);
6359 stats->rx_frame_errors = le64_to_cpu(rx->rx_align_err_frames);
6360 stats->rx_length_errors = le64_to_cpu(rx->rx_undrsz_frames) +
6361 le64_to_cpu(rx->rx_ovrsz_frames) +
6362 le64_to_cpu(rx->rx_runt_frames);
6363 stats->rx_errors = le64_to_cpu(rx->rx_false_carrier_frames) +
6364 le64_to_cpu(rx->rx_jbr_frames);
6365 stats->collisions = le64_to_cpu(tx->tx_total_collisions);
6366 stats->tx_fifo_errors = le64_to_cpu(tx->tx_fifo_underruns);
6367 stats->tx_errors = le64_to_cpu(tx->tx_err);
6368 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006369}
6370
6371static bool bnxt_mc_list_updated(struct bnxt *bp, u32 *rx_mask)
6372{
6373 struct net_device *dev = bp->dev;
6374 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
6375 struct netdev_hw_addr *ha;
6376 u8 *haddr;
6377 int mc_count = 0;
6378 bool update = false;
6379 int off = 0;
6380
6381 netdev_for_each_mc_addr(ha, dev) {
6382 if (mc_count >= BNXT_MAX_MC_ADDRS) {
6383 *rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST;
6384 vnic->mc_list_count = 0;
6385 return false;
6386 }
6387 haddr = ha->addr;
6388 if (!ether_addr_equal(haddr, vnic->mc_list + off)) {
6389 memcpy(vnic->mc_list + off, haddr, ETH_ALEN);
6390 update = true;
6391 }
6392 off += ETH_ALEN;
6393 mc_count++;
6394 }
6395 if (mc_count)
6396 *rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_MCAST;
6397
6398 if (mc_count != vnic->mc_list_count) {
6399 vnic->mc_list_count = mc_count;
6400 update = true;
6401 }
6402 return update;
6403}
6404
6405static bool bnxt_uc_list_updated(struct bnxt *bp)
6406{
6407 struct net_device *dev = bp->dev;
6408 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
6409 struct netdev_hw_addr *ha;
6410 int off = 0;
6411
6412 if (netdev_uc_count(dev) != (vnic->uc_filter_count - 1))
6413 return true;
6414
6415 netdev_for_each_uc_addr(ha, dev) {
6416 if (!ether_addr_equal(ha->addr, vnic->uc_list + off))
6417 return true;
6418
6419 off += ETH_ALEN;
6420 }
6421 return false;
6422}
6423
6424static void bnxt_set_rx_mode(struct net_device *dev)
6425{
6426 struct bnxt *bp = netdev_priv(dev);
6427 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
6428 u32 mask = vnic->rx_mask;
6429 bool mc_update = false;
6430 bool uc_update;
6431
6432 if (!netif_running(dev))
6433 return;
6434
6435 mask &= ~(CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS |
6436 CFA_L2_SET_RX_MASK_REQ_MASK_MCAST |
6437 CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST);
6438
Michael Chan17c71ac2016-07-01 18:46:27 -04006439 if ((dev->flags & IFF_PROMISC) && bnxt_promisc_ok(bp))
Michael Chanc0c050c2015-10-22 16:01:17 -04006440 mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS;
6441
6442 uc_update = bnxt_uc_list_updated(bp);
6443
6444 if (dev->flags & IFF_ALLMULTI) {
6445 mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST;
6446 vnic->mc_list_count = 0;
6447 } else {
6448 mc_update = bnxt_mc_list_updated(bp, &mask);
6449 }
6450
6451 if (mask != vnic->rx_mask || uc_update || mc_update) {
6452 vnic->rx_mask = mask;
6453
6454 set_bit(BNXT_RX_MASK_SP_EVENT, &bp->sp_event);
6455 schedule_work(&bp->sp_task);
6456 }
6457}
6458
Michael Chanb664f002015-12-02 01:54:08 -05006459static int bnxt_cfg_rx_mode(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04006460{
6461 struct net_device *dev = bp->dev;
6462 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
6463 struct netdev_hw_addr *ha;
6464 int i, off = 0, rc;
6465 bool uc_update;
6466
6467 netif_addr_lock_bh(dev);
6468 uc_update = bnxt_uc_list_updated(bp);
6469 netif_addr_unlock_bh(dev);
6470
6471 if (!uc_update)
6472 goto skip_uc;
6473
6474 mutex_lock(&bp->hwrm_cmd_lock);
6475 for (i = 1; i < vnic->uc_filter_count; i++) {
6476 struct hwrm_cfa_l2_filter_free_input req = {0};
6477
6478 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_L2_FILTER_FREE, -1,
6479 -1);
6480
6481 req.l2_filter_id = vnic->fw_l2_filter_id[i];
6482
6483 rc = _hwrm_send_message(bp, &req, sizeof(req),
6484 HWRM_CMD_TIMEOUT);
6485 }
6486 mutex_unlock(&bp->hwrm_cmd_lock);
6487
6488 vnic->uc_filter_count = 1;
6489
6490 netif_addr_lock_bh(dev);
6491 if (netdev_uc_count(dev) > (BNXT_MAX_UC_ADDRS - 1)) {
6492 vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS;
6493 } else {
6494 netdev_for_each_uc_addr(ha, dev) {
6495 memcpy(vnic->uc_list + off, ha->addr, ETH_ALEN);
6496 off += ETH_ALEN;
6497 vnic->uc_filter_count++;
6498 }
6499 }
6500 netif_addr_unlock_bh(dev);
6501
6502 for (i = 1, off = 0; i < vnic->uc_filter_count; i++, off += ETH_ALEN) {
6503 rc = bnxt_hwrm_set_vnic_filter(bp, 0, i, vnic->uc_list + off);
6504 if (rc) {
6505 netdev_err(bp->dev, "HWRM vnic filter failure rc: %x\n",
6506 rc);
6507 vnic->uc_filter_count = i;
Michael Chanb664f002015-12-02 01:54:08 -05006508 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04006509 }
6510 }
6511
6512skip_uc:
6513 rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, 0);
6514 if (rc)
6515 netdev_err(bp->dev, "HWRM cfa l2 rx mask failure rc: %x\n",
6516 rc);
Michael Chanb664f002015-12-02 01:54:08 -05006517
6518 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04006519}
6520
Michael Chan8079e8f2016-12-29 12:13:37 -05006521/* If the chip and firmware supports RFS */
6522static bool bnxt_rfs_supported(struct bnxt *bp)
6523{
6524 if (BNXT_PF(bp) && !BNXT_CHIP_TYPE_NITRO_A0(bp))
6525 return true;
Michael Chanae10ae72016-12-29 12:13:38 -05006526 if (bp->flags & BNXT_FLAG_NEW_RSS_CAP)
6527 return true;
Michael Chan8079e8f2016-12-29 12:13:37 -05006528 return false;
6529}
6530
6531/* If runtime conditions support RFS */
Michael Chan2bcfa6f2015-12-27 18:19:24 -05006532static bool bnxt_rfs_capable(struct bnxt *bp)
6533{
6534#ifdef CONFIG_RFS_ACCEL
Michael Chan8079e8f2016-12-29 12:13:37 -05006535 int vnics, max_vnics, max_rss_ctxs;
Michael Chan2bcfa6f2015-12-27 18:19:24 -05006536
Michael Chan964fd482017-02-12 19:18:13 -05006537 if (!(bp->flags & BNXT_FLAG_MSIX_CAP))
Michael Chan2bcfa6f2015-12-27 18:19:24 -05006538 return false;
6539
6540 vnics = 1 + bp->rx_nr_rings;
Michael Chan8079e8f2016-12-29 12:13:37 -05006541 max_vnics = bnxt_get_max_func_vnics(bp);
6542 max_rss_ctxs = bnxt_get_max_func_rss_ctxs(bp);
Michael Chanae10ae72016-12-29 12:13:38 -05006543
6544 /* RSS contexts not a limiting factor */
6545 if (bp->flags & BNXT_FLAG_NEW_RSS_CAP)
6546 max_rss_ctxs = max_vnics;
Michael Chan8079e8f2016-12-29 12:13:37 -05006547 if (vnics > max_vnics || vnics > max_rss_ctxs) {
Vasundhara Volama2304902016-07-25 12:33:36 -04006548 netdev_warn(bp->dev,
6549 "Not enough resources to support NTUPLE filters, enough resources for up to %d rx rings\n",
Michael Chan8079e8f2016-12-29 12:13:37 -05006550 min(max_rss_ctxs - 1, max_vnics - 1));
Michael Chan2bcfa6f2015-12-27 18:19:24 -05006551 return false;
Vasundhara Volama2304902016-07-25 12:33:36 -04006552 }
Michael Chan2bcfa6f2015-12-27 18:19:24 -05006553
6554 return true;
6555#else
6556 return false;
6557#endif
6558}
6559
Michael Chanc0c050c2015-10-22 16:01:17 -04006560static netdev_features_t bnxt_fix_features(struct net_device *dev,
6561 netdev_features_t features)
6562{
Michael Chan2bcfa6f2015-12-27 18:19:24 -05006563 struct bnxt *bp = netdev_priv(dev);
6564
Vasundhara Volama2304902016-07-25 12:33:36 -04006565 if ((features & NETIF_F_NTUPLE) && !bnxt_rfs_capable(bp))
Michael Chan2bcfa6f2015-12-27 18:19:24 -05006566 features &= ~NETIF_F_NTUPLE;
Michael Chan5a9f6b22016-06-06 02:37:15 -04006567
6568 /* Both CTAG and STAG VLAN accelaration on the RX side have to be
6569 * turned on or off together.
6570 */
6571 if ((features & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX)) !=
6572 (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX)) {
6573 if (dev->features & NETIF_F_HW_VLAN_CTAG_RX)
6574 features &= ~(NETIF_F_HW_VLAN_CTAG_RX |
6575 NETIF_F_HW_VLAN_STAG_RX);
6576 else
6577 features |= NETIF_F_HW_VLAN_CTAG_RX |
6578 NETIF_F_HW_VLAN_STAG_RX;
6579 }
Michael Chancf6645f2016-06-13 02:25:28 -04006580#ifdef CONFIG_BNXT_SRIOV
6581 if (BNXT_VF(bp)) {
6582 if (bp->vf.vlan) {
6583 features &= ~(NETIF_F_HW_VLAN_CTAG_RX |
6584 NETIF_F_HW_VLAN_STAG_RX);
6585 }
6586 }
6587#endif
Michael Chanc0c050c2015-10-22 16:01:17 -04006588 return features;
6589}
6590
6591static int bnxt_set_features(struct net_device *dev, netdev_features_t features)
6592{
6593 struct bnxt *bp = netdev_priv(dev);
6594 u32 flags = bp->flags;
6595 u32 changes;
6596 int rc = 0;
6597 bool re_init = false;
6598 bool update_tpa = false;
6599
6600 flags &= ~BNXT_FLAG_ALL_CONFIG_FEATS;
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04006601 if ((features & NETIF_F_GRO) && !BNXT_CHIP_TYPE_NITRO_A0(bp))
Michael Chanc0c050c2015-10-22 16:01:17 -04006602 flags |= BNXT_FLAG_GRO;
6603 if (features & NETIF_F_LRO)
6604 flags |= BNXT_FLAG_LRO;
6605
Michael Chanbdbd1eb2016-12-29 12:13:43 -05006606 if (bp->flags & BNXT_FLAG_NO_AGG_RINGS)
6607 flags &= ~BNXT_FLAG_TPA;
6608
Michael Chanc0c050c2015-10-22 16:01:17 -04006609 if (features & NETIF_F_HW_VLAN_CTAG_RX)
6610 flags |= BNXT_FLAG_STRIP_VLAN;
6611
6612 if (features & NETIF_F_NTUPLE)
6613 flags |= BNXT_FLAG_RFS;
6614
6615 changes = flags ^ bp->flags;
6616 if (changes & BNXT_FLAG_TPA) {
6617 update_tpa = true;
6618 if ((bp->flags & BNXT_FLAG_TPA) == 0 ||
6619 (flags & BNXT_FLAG_TPA) == 0)
6620 re_init = true;
6621 }
6622
6623 if (changes & ~BNXT_FLAG_TPA)
6624 re_init = true;
6625
6626 if (flags != bp->flags) {
6627 u32 old_flags = bp->flags;
6628
6629 bp->flags = flags;
6630
Michael Chan2bcfa6f2015-12-27 18:19:24 -05006631 if (!test_bit(BNXT_STATE_OPEN, &bp->state)) {
Michael Chanc0c050c2015-10-22 16:01:17 -04006632 if (update_tpa)
6633 bnxt_set_ring_params(bp);
6634 return rc;
6635 }
6636
6637 if (re_init) {
6638 bnxt_close_nic(bp, false, false);
6639 if (update_tpa)
6640 bnxt_set_ring_params(bp);
6641
6642 return bnxt_open_nic(bp, false, false);
6643 }
6644 if (update_tpa) {
6645 rc = bnxt_set_tpa(bp,
6646 (flags & BNXT_FLAG_TPA) ?
6647 true : false);
6648 if (rc)
6649 bp->flags = old_flags;
6650 }
6651 }
6652 return rc;
6653}
6654
Michael Chan9f554592016-01-02 23:44:58 -05006655static void bnxt_dump_tx_sw_state(struct bnxt_napi *bnapi)
6656{
Michael Chanb6ab4b02016-01-02 23:44:59 -05006657 struct bnxt_tx_ring_info *txr = bnapi->tx_ring;
Michael Chan9f554592016-01-02 23:44:58 -05006658 int i = bnapi->index;
6659
Michael Chan3b2b7d92016-01-02 23:45:00 -05006660 if (!txr)
6661 return;
6662
Michael Chan9f554592016-01-02 23:44:58 -05006663 netdev_info(bnapi->bp->dev, "[%d]: tx{fw_ring: %d prod: %x cons: %x}\n",
6664 i, txr->tx_ring_struct.fw_ring_id, txr->tx_prod,
6665 txr->tx_cons);
6666}
6667
6668static void bnxt_dump_rx_sw_state(struct bnxt_napi *bnapi)
6669{
Michael Chanb6ab4b02016-01-02 23:44:59 -05006670 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
Michael Chan9f554592016-01-02 23:44:58 -05006671 int i = bnapi->index;
6672
Michael Chan3b2b7d92016-01-02 23:45:00 -05006673 if (!rxr)
6674 return;
6675
Michael Chan9f554592016-01-02 23:44:58 -05006676 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",
6677 i, rxr->rx_ring_struct.fw_ring_id, rxr->rx_prod,
6678 rxr->rx_agg_ring_struct.fw_ring_id, rxr->rx_agg_prod,
6679 rxr->rx_sw_agg_prod);
6680}
6681
6682static void bnxt_dump_cp_sw_state(struct bnxt_napi *bnapi)
6683{
6684 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
6685 int i = bnapi->index;
6686
6687 netdev_info(bnapi->bp->dev, "[%d]: cp{fw_ring: %d raw_cons: %x}\n",
6688 i, cpr->cp_ring_struct.fw_ring_id, cpr->cp_raw_cons);
6689}
6690
Michael Chanc0c050c2015-10-22 16:01:17 -04006691static void bnxt_dbg_dump_states(struct bnxt *bp)
6692{
6693 int i;
6694 struct bnxt_napi *bnapi;
Michael Chanc0c050c2015-10-22 16:01:17 -04006695
6696 for (i = 0; i < bp->cp_nr_rings; i++) {
6697 bnapi = bp->bnapi[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04006698 if (netif_msg_drv(bp)) {
Michael Chan9f554592016-01-02 23:44:58 -05006699 bnxt_dump_tx_sw_state(bnapi);
6700 bnxt_dump_rx_sw_state(bnapi);
6701 bnxt_dump_cp_sw_state(bnapi);
Michael Chanc0c050c2015-10-22 16:01:17 -04006702 }
6703 }
6704}
6705
Michael Chan6988bd92016-06-13 02:25:29 -04006706static void bnxt_reset_task(struct bnxt *bp, bool silent)
Michael Chanc0c050c2015-10-22 16:01:17 -04006707{
Michael Chan6988bd92016-06-13 02:25:29 -04006708 if (!silent)
6709 bnxt_dbg_dump_states(bp);
Michael Chan028de142015-12-09 19:35:44 -05006710 if (netif_running(bp->dev)) {
Michael Chanb386cd32017-03-08 18:44:33 -05006711 int rc;
6712
6713 if (!silent)
6714 bnxt_ulp_stop(bp);
Michael Chan028de142015-12-09 19:35:44 -05006715 bnxt_close_nic(bp, false, false);
Michael Chanb386cd32017-03-08 18:44:33 -05006716 rc = bnxt_open_nic(bp, false, false);
6717 if (!silent && !rc)
6718 bnxt_ulp_start(bp);
Michael Chan028de142015-12-09 19:35:44 -05006719 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006720}
6721
6722static void bnxt_tx_timeout(struct net_device *dev)
6723{
6724 struct bnxt *bp = netdev_priv(dev);
6725
6726 netdev_err(bp->dev, "TX timeout detected, starting reset task!\n");
6727 set_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event);
6728 schedule_work(&bp->sp_task);
6729}
6730
6731#ifdef CONFIG_NET_POLL_CONTROLLER
6732static void bnxt_poll_controller(struct net_device *dev)
6733{
6734 struct bnxt *bp = netdev_priv(dev);
6735 int i;
6736
6737 for (i = 0; i < bp->cp_nr_rings; i++) {
6738 struct bnxt_irq *irq = &bp->irq_tbl[i];
6739
6740 disable_irq(irq->vector);
6741 irq->handler(irq->vector, bp->bnapi[i]);
6742 enable_irq(irq->vector);
6743 }
6744}
6745#endif
6746
6747static void bnxt_timer(unsigned long data)
6748{
6749 struct bnxt *bp = (struct bnxt *)data;
6750 struct net_device *dev = bp->dev;
6751
6752 if (!netif_running(dev))
6753 return;
6754
6755 if (atomic_read(&bp->intr_sem) != 0)
6756 goto bnxt_restart_timer;
6757
Michael Chan3bdf56c2016-03-07 15:38:45 -05006758 if (bp->link_info.link_up && (bp->flags & BNXT_FLAG_PORT_STATS)) {
6759 set_bit(BNXT_PERIODIC_STATS_SP_EVENT, &bp->sp_event);
6760 schedule_work(&bp->sp_task);
6761 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006762bnxt_restart_timer:
6763 mod_timer(&bp->timer, jiffies + bp->current_interval);
6764}
6765
Michael Chana551ee92017-01-25 02:55:07 -05006766static void bnxt_rtnl_lock_sp(struct bnxt *bp)
Michael Chan6988bd92016-06-13 02:25:29 -04006767{
Michael Chana551ee92017-01-25 02:55:07 -05006768 /* We are called from bnxt_sp_task which has BNXT_STATE_IN_SP_TASK
6769 * set. If the device is being closed, bnxt_close() may be holding
Michael Chan6988bd92016-06-13 02:25:29 -04006770 * rtnl() and waiting for BNXT_STATE_IN_SP_TASK to clear. So we
6771 * must clear BNXT_STATE_IN_SP_TASK before holding rtnl().
6772 */
6773 clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
6774 rtnl_lock();
Michael Chana551ee92017-01-25 02:55:07 -05006775}
6776
6777static void bnxt_rtnl_unlock_sp(struct bnxt *bp)
6778{
Michael Chan6988bd92016-06-13 02:25:29 -04006779 set_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
6780 rtnl_unlock();
6781}
6782
Michael Chana551ee92017-01-25 02:55:07 -05006783/* Only called from bnxt_sp_task() */
6784static void bnxt_reset(struct bnxt *bp, bool silent)
6785{
6786 bnxt_rtnl_lock_sp(bp);
6787 if (test_bit(BNXT_STATE_OPEN, &bp->state))
6788 bnxt_reset_task(bp, silent);
6789 bnxt_rtnl_unlock_sp(bp);
6790}
6791
Michael Chanc0c050c2015-10-22 16:01:17 -04006792static void bnxt_cfg_ntp_filters(struct bnxt *);
6793
6794static void bnxt_sp_task(struct work_struct *work)
6795{
6796 struct bnxt *bp = container_of(work, struct bnxt, sp_task);
Michael Chanc0c050c2015-10-22 16:01:17 -04006797
Michael Chan4cebdce2015-12-09 19:35:43 -05006798 set_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
6799 smp_mb__after_atomic();
6800 if (!test_bit(BNXT_STATE_OPEN, &bp->state)) {
6801 clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
Michael Chanc0c050c2015-10-22 16:01:17 -04006802 return;
Michael Chan4cebdce2015-12-09 19:35:43 -05006803 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006804
6805 if (test_and_clear_bit(BNXT_RX_MASK_SP_EVENT, &bp->sp_event))
6806 bnxt_cfg_rx_mode(bp);
6807
6808 if (test_and_clear_bit(BNXT_RX_NTP_FLTR_SP_EVENT, &bp->sp_event))
6809 bnxt_cfg_ntp_filters(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04006810 if (test_and_clear_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT, &bp->sp_event))
6811 bnxt_hwrm_exec_fwd_req(bp);
6812 if (test_and_clear_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT, &bp->sp_event)) {
6813 bnxt_hwrm_tunnel_dst_port_alloc(
6814 bp, bp->vxlan_port,
6815 TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN);
6816 }
6817 if (test_and_clear_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT, &bp->sp_event)) {
6818 bnxt_hwrm_tunnel_dst_port_free(
6819 bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN);
6820 }
Alexander Duyck7cdd5fc2016-06-16 12:21:36 -07006821 if (test_and_clear_bit(BNXT_GENEVE_ADD_PORT_SP_EVENT, &bp->sp_event)) {
6822 bnxt_hwrm_tunnel_dst_port_alloc(
6823 bp, bp->nge_port,
6824 TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE);
6825 }
6826 if (test_and_clear_bit(BNXT_GENEVE_DEL_PORT_SP_EVENT, &bp->sp_event)) {
6827 bnxt_hwrm_tunnel_dst_port_free(
6828 bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE);
6829 }
Michael Chan3bdf56c2016-03-07 15:38:45 -05006830 if (test_and_clear_bit(BNXT_PERIODIC_STATS_SP_EVENT, &bp->sp_event))
6831 bnxt_hwrm_port_qstats(bp);
6832
Michael Chana551ee92017-01-25 02:55:07 -05006833 /* These functions below will clear BNXT_STATE_IN_SP_TASK. They
6834 * must be the last functions to be called before exiting.
6835 */
Michael Chan0eaa24b2017-01-25 02:55:08 -05006836 if (test_and_clear_bit(BNXT_LINK_CHNG_SP_EVENT, &bp->sp_event)) {
6837 int rc = 0;
6838
6839 if (test_and_clear_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT,
6840 &bp->sp_event))
6841 bnxt_hwrm_phy_qcaps(bp);
6842
6843 bnxt_rtnl_lock_sp(bp);
6844 if (test_bit(BNXT_STATE_OPEN, &bp->state))
6845 rc = bnxt_update_link(bp, true);
6846 bnxt_rtnl_unlock_sp(bp);
6847 if (rc)
6848 netdev_err(bp->dev, "SP task can't update link (rc: %x)\n",
6849 rc);
6850 }
Michael Chan90c694b2017-01-25 02:55:09 -05006851 if (test_and_clear_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT, &bp->sp_event)) {
6852 bnxt_rtnl_lock_sp(bp);
6853 if (test_bit(BNXT_STATE_OPEN, &bp->state))
6854 bnxt_get_port_module_status(bp);
6855 bnxt_rtnl_unlock_sp(bp);
6856 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006857 if (test_and_clear_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event))
6858 bnxt_reset(bp, false);
6859
6860 if (test_and_clear_bit(BNXT_RESET_TASK_SILENT_SP_EVENT, &bp->sp_event))
6861 bnxt_reset(bp, true);
6862
Michael Chanc0c050c2015-10-22 16:01:17 -04006863 smp_mb__before_atomic();
6864 clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
6865}
6866
Michael Chand1e79252017-02-06 16:55:38 -05006867/* Under rtnl_lock */
Michael Chan5f449242017-02-06 16:55:40 -05006868int bnxt_reserve_rings(struct bnxt *bp, int tx, int rx, int tcs, int tx_xdp)
Michael Chand1e79252017-02-06 16:55:38 -05006869{
6870 int max_rx, max_tx, tx_sets = 1;
6871 int tx_rings_needed;
6872 bool sh = true;
6873 int rc;
6874
6875 if (!(bp->flags & BNXT_FLAG_SHARED_RINGS))
6876 sh = false;
6877
6878 if (tcs)
6879 tx_sets = tcs;
6880
6881 rc = bnxt_get_max_rings(bp, &max_rx, &max_tx, sh);
6882 if (rc)
6883 return rc;
6884
6885 if (max_rx < rx)
6886 return -ENOMEM;
6887
Michael Chan5f449242017-02-06 16:55:40 -05006888 tx_rings_needed = tx * tx_sets + tx_xdp;
Michael Chand1e79252017-02-06 16:55:38 -05006889 if (max_tx < tx_rings_needed)
6890 return -ENOMEM;
6891
6892 if (bnxt_hwrm_reserve_tx_rings(bp, &tx_rings_needed) ||
Michael Chan5f449242017-02-06 16:55:40 -05006893 tx_rings_needed < (tx * tx_sets + tx_xdp))
Michael Chand1e79252017-02-06 16:55:38 -05006894 return -ENOMEM;
6895 return 0;
6896}
6897
Sathya Perla17086392017-02-20 19:25:18 -05006898static void bnxt_unmap_bars(struct bnxt *bp, struct pci_dev *pdev)
6899{
6900 if (bp->bar2) {
6901 pci_iounmap(pdev, bp->bar2);
6902 bp->bar2 = NULL;
6903 }
6904
6905 if (bp->bar1) {
6906 pci_iounmap(pdev, bp->bar1);
6907 bp->bar1 = NULL;
6908 }
6909
6910 if (bp->bar0) {
6911 pci_iounmap(pdev, bp->bar0);
6912 bp->bar0 = NULL;
6913 }
6914}
6915
6916static void bnxt_cleanup_pci(struct bnxt *bp)
6917{
6918 bnxt_unmap_bars(bp, bp->pdev);
6919 pci_release_regions(bp->pdev);
6920 pci_disable_device(bp->pdev);
6921}
6922
Michael Chanc0c050c2015-10-22 16:01:17 -04006923static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev)
6924{
6925 int rc;
6926 struct bnxt *bp = netdev_priv(dev);
6927
6928 SET_NETDEV_DEV(dev, &pdev->dev);
6929
6930 /* enable device (incl. PCI PM wakeup), and bus-mastering */
6931 rc = pci_enable_device(pdev);
6932 if (rc) {
6933 dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n");
6934 goto init_err;
6935 }
6936
6937 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
6938 dev_err(&pdev->dev,
6939 "Cannot find PCI device base address, aborting\n");
6940 rc = -ENODEV;
6941 goto init_err_disable;
6942 }
6943
6944 rc = pci_request_regions(pdev, DRV_MODULE_NAME);
6945 if (rc) {
6946 dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting\n");
6947 goto init_err_disable;
6948 }
6949
6950 if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)) != 0 &&
6951 dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)) != 0) {
6952 dev_err(&pdev->dev, "System does not support DMA, aborting\n");
6953 goto init_err_disable;
6954 }
6955
6956 pci_set_master(pdev);
6957
6958 bp->dev = dev;
6959 bp->pdev = pdev;
6960
6961 bp->bar0 = pci_ioremap_bar(pdev, 0);
6962 if (!bp->bar0) {
6963 dev_err(&pdev->dev, "Cannot map device registers, aborting\n");
6964 rc = -ENOMEM;
6965 goto init_err_release;
6966 }
6967
6968 bp->bar1 = pci_ioremap_bar(pdev, 2);
6969 if (!bp->bar1) {
6970 dev_err(&pdev->dev, "Cannot map doorbell registers, aborting\n");
6971 rc = -ENOMEM;
6972 goto init_err_release;
6973 }
6974
6975 bp->bar2 = pci_ioremap_bar(pdev, 4);
6976 if (!bp->bar2) {
6977 dev_err(&pdev->dev, "Cannot map bar4 registers, aborting\n");
6978 rc = -ENOMEM;
6979 goto init_err_release;
6980 }
6981
Satish Baddipadige6316ea62016-03-07 15:38:48 -05006982 pci_enable_pcie_error_reporting(pdev);
6983
Michael Chanc0c050c2015-10-22 16:01:17 -04006984 INIT_WORK(&bp->sp_task, bnxt_sp_task);
6985
6986 spin_lock_init(&bp->ntp_fltr_lock);
6987
6988 bp->rx_ring_size = BNXT_DEFAULT_RX_RING_SIZE;
6989 bp->tx_ring_size = BNXT_DEFAULT_TX_RING_SIZE;
6990
Michael Chandfb5b892016-02-26 04:00:01 -05006991 /* tick values in micro seconds */
Michael Chandfc9c942016-02-26 04:00:03 -05006992 bp->rx_coal_ticks = 12;
6993 bp->rx_coal_bufs = 30;
Michael Chandfb5b892016-02-26 04:00:01 -05006994 bp->rx_coal_ticks_irq = 1;
6995 bp->rx_coal_bufs_irq = 2;
Michael Chanc0c050c2015-10-22 16:01:17 -04006996
Michael Chandfc9c942016-02-26 04:00:03 -05006997 bp->tx_coal_ticks = 25;
6998 bp->tx_coal_bufs = 30;
6999 bp->tx_coal_ticks_irq = 2;
7000 bp->tx_coal_bufs_irq = 2;
7001
Michael Chan51f30782016-07-01 18:46:29 -04007002 bp->stats_coal_ticks = BNXT_DEF_STATS_COAL_TICKS;
7003
Michael Chanc0c050c2015-10-22 16:01:17 -04007004 init_timer(&bp->timer);
7005 bp->timer.data = (unsigned long)bp;
7006 bp->timer.function = bnxt_timer;
7007 bp->current_interval = BNXT_TIMER_INTERVAL;
7008
Michael Chancaefe522015-12-09 19:35:42 -05007009 clear_bit(BNXT_STATE_OPEN, &bp->state);
Michael Chanc0c050c2015-10-22 16:01:17 -04007010 return 0;
7011
7012init_err_release:
Sathya Perla17086392017-02-20 19:25:18 -05007013 bnxt_unmap_bars(bp, pdev);
Michael Chanc0c050c2015-10-22 16:01:17 -04007014 pci_release_regions(pdev);
7015
7016init_err_disable:
7017 pci_disable_device(pdev);
7018
7019init_err:
7020 return rc;
7021}
7022
7023/* rtnl_lock held */
7024static int bnxt_change_mac_addr(struct net_device *dev, void *p)
7025{
7026 struct sockaddr *addr = p;
Jeffrey Huang1fc2cfd2015-12-02 01:54:06 -05007027 struct bnxt *bp = netdev_priv(dev);
7028 int rc = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04007029
7030 if (!is_valid_ether_addr(addr->sa_data))
7031 return -EADDRNOTAVAIL;
7032
Michael Chan84c33dd2016-04-11 04:11:13 -04007033 rc = bnxt_approve_mac(bp, addr->sa_data);
7034 if (rc)
7035 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04007036
Jeffrey Huang1fc2cfd2015-12-02 01:54:06 -05007037 if (ether_addr_equal(addr->sa_data, dev->dev_addr))
7038 return 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04007039
Jeffrey Huang1fc2cfd2015-12-02 01:54:06 -05007040 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
7041 if (netif_running(dev)) {
7042 bnxt_close_nic(bp, false, false);
7043 rc = bnxt_open_nic(bp, false, false);
7044 }
7045
7046 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04007047}
7048
7049/* rtnl_lock held */
7050static int bnxt_change_mtu(struct net_device *dev, int new_mtu)
7051{
7052 struct bnxt *bp = netdev_priv(dev);
7053
Michael Chanc0c050c2015-10-22 16:01:17 -04007054 if (netif_running(dev))
7055 bnxt_close_nic(bp, false, false);
7056
7057 dev->mtu = new_mtu;
7058 bnxt_set_ring_params(bp);
7059
7060 if (netif_running(dev))
7061 return bnxt_open_nic(bp, false, false);
7062
7063 return 0;
7064}
7065
Michael Chanc5e3deb2016-12-02 21:17:15 -05007066int bnxt_setup_mq_tc(struct net_device *dev, u8 tc)
Michael Chanc0c050c2015-10-22 16:01:17 -04007067{
7068 struct bnxt *bp = netdev_priv(dev);
Michael Chan3ffb6a32016-11-11 00:11:42 -05007069 bool sh = false;
Michael Chand1e79252017-02-06 16:55:38 -05007070 int rc;
John Fastabend16e5cc62016-02-16 21:16:43 -08007071
Michael Chanc0c050c2015-10-22 16:01:17 -04007072 if (tc > bp->max_tc) {
Michael Chanb451c8b2017-02-12 19:18:17 -05007073 netdev_err(dev, "Too many traffic classes requested: %d. Max supported is %d.\n",
Michael Chanc0c050c2015-10-22 16:01:17 -04007074 tc, bp->max_tc);
7075 return -EINVAL;
7076 }
7077
7078 if (netdev_get_num_tc(dev) == tc)
7079 return 0;
7080
Michael Chan3ffb6a32016-11-11 00:11:42 -05007081 if (bp->flags & BNXT_FLAG_SHARED_RINGS)
7082 sh = true;
7083
Michael Chan5f449242017-02-06 16:55:40 -05007084 rc = bnxt_reserve_rings(bp, bp->tx_nr_rings_per_tc, bp->rx_nr_rings,
7085 tc, bp->tx_nr_rings_xdp);
Michael Chand1e79252017-02-06 16:55:38 -05007086 if (rc)
7087 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04007088
7089 /* Needs to close the device and do hw resource re-allocations */
7090 if (netif_running(bp->dev))
7091 bnxt_close_nic(bp, true, false);
7092
7093 if (tc) {
7094 bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tc;
7095 netdev_set_num_tc(dev, tc);
7096 } else {
7097 bp->tx_nr_rings = bp->tx_nr_rings_per_tc;
7098 netdev_reset_tc(dev);
7099 }
Michael Chan3ffb6a32016-11-11 00:11:42 -05007100 bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
7101 bp->tx_nr_rings + bp->rx_nr_rings;
Michael Chanc0c050c2015-10-22 16:01:17 -04007102 bp->num_stat_ctxs = bp->cp_nr_rings;
7103
7104 if (netif_running(bp->dev))
7105 return bnxt_open_nic(bp, true, false);
7106
7107 return 0;
7108}
7109
Michael Chanc5e3deb2016-12-02 21:17:15 -05007110static int bnxt_setup_tc(struct net_device *dev, u32 handle, __be16 proto,
7111 struct tc_to_netdev *ntc)
7112{
7113 if (ntc->type != TC_SETUP_MQPRIO)
7114 return -EINVAL;
7115
Amritha Nambiar56f36ac2017-03-15 10:39:25 -07007116 ntc->mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
7117
7118 return bnxt_setup_mq_tc(dev, ntc->mqprio->num_tc);
Michael Chanc5e3deb2016-12-02 21:17:15 -05007119}
7120
Michael Chanc0c050c2015-10-22 16:01:17 -04007121#ifdef CONFIG_RFS_ACCEL
7122static bool bnxt_fltr_match(struct bnxt_ntuple_filter *f1,
7123 struct bnxt_ntuple_filter *f2)
7124{
7125 struct flow_keys *keys1 = &f1->fkeys;
7126 struct flow_keys *keys2 = &f2->fkeys;
7127
7128 if (keys1->addrs.v4addrs.src == keys2->addrs.v4addrs.src &&
7129 keys1->addrs.v4addrs.dst == keys2->addrs.v4addrs.dst &&
7130 keys1->ports.ports == keys2->ports.ports &&
7131 keys1->basic.ip_proto == keys2->basic.ip_proto &&
7132 keys1->basic.n_proto == keys2->basic.n_proto &&
Michael Chan61aad722017-02-12 19:18:14 -05007133 keys1->control.flags == keys2->control.flags &&
Michael Chana54c4d72016-07-25 12:33:35 -04007134 ether_addr_equal(f1->src_mac_addr, f2->src_mac_addr) &&
7135 ether_addr_equal(f1->dst_mac_addr, f2->dst_mac_addr))
Michael Chanc0c050c2015-10-22 16:01:17 -04007136 return true;
7137
7138 return false;
7139}
7140
7141static int bnxt_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
7142 u16 rxq_index, u32 flow_id)
7143{
7144 struct bnxt *bp = netdev_priv(dev);
7145 struct bnxt_ntuple_filter *fltr, *new_fltr;
7146 struct flow_keys *fkeys;
7147 struct ethhdr *eth = (struct ethhdr *)skb_mac_header(skb);
Michael Chana54c4d72016-07-25 12:33:35 -04007148 int rc = 0, idx, bit_id, l2_idx = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04007149 struct hlist_head *head;
7150
Michael Chana54c4d72016-07-25 12:33:35 -04007151 if (!ether_addr_equal(dev->dev_addr, eth->h_dest)) {
7152 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
7153 int off = 0, j;
7154
7155 netif_addr_lock_bh(dev);
7156 for (j = 0; j < vnic->uc_filter_count; j++, off += ETH_ALEN) {
7157 if (ether_addr_equal(eth->h_dest,
7158 vnic->uc_list + off)) {
7159 l2_idx = j + 1;
7160 break;
7161 }
7162 }
7163 netif_addr_unlock_bh(dev);
7164 if (!l2_idx)
7165 return -EINVAL;
7166 }
Michael Chanc0c050c2015-10-22 16:01:17 -04007167 new_fltr = kzalloc(sizeof(*new_fltr), GFP_ATOMIC);
7168 if (!new_fltr)
7169 return -ENOMEM;
7170
7171 fkeys = &new_fltr->fkeys;
7172 if (!skb_flow_dissect_flow_keys(skb, fkeys, 0)) {
7173 rc = -EPROTONOSUPPORT;
7174 goto err_free;
7175 }
7176
Michael Chandda0e742016-12-29 12:13:40 -05007177 if ((fkeys->basic.n_proto != htons(ETH_P_IP) &&
7178 fkeys->basic.n_proto != htons(ETH_P_IPV6)) ||
Michael Chanc0c050c2015-10-22 16:01:17 -04007179 ((fkeys->basic.ip_proto != IPPROTO_TCP) &&
7180 (fkeys->basic.ip_proto != IPPROTO_UDP))) {
7181 rc = -EPROTONOSUPPORT;
7182 goto err_free;
7183 }
Michael Chandda0e742016-12-29 12:13:40 -05007184 if (fkeys->basic.n_proto == htons(ETH_P_IPV6) &&
7185 bp->hwrm_spec_code < 0x10601) {
7186 rc = -EPROTONOSUPPORT;
7187 goto err_free;
7188 }
Michael Chan61aad722017-02-12 19:18:14 -05007189 if ((fkeys->control.flags & FLOW_DIS_ENCAPSULATION) &&
7190 bp->hwrm_spec_code < 0x10601) {
7191 rc = -EPROTONOSUPPORT;
7192 goto err_free;
7193 }
Michael Chanc0c050c2015-10-22 16:01:17 -04007194
Michael Chana54c4d72016-07-25 12:33:35 -04007195 memcpy(new_fltr->dst_mac_addr, eth->h_dest, ETH_ALEN);
Michael Chanc0c050c2015-10-22 16:01:17 -04007196 memcpy(new_fltr->src_mac_addr, eth->h_source, ETH_ALEN);
7197
7198 idx = skb_get_hash_raw(skb) & BNXT_NTP_FLTR_HASH_MASK;
7199 head = &bp->ntp_fltr_hash_tbl[idx];
7200 rcu_read_lock();
7201 hlist_for_each_entry_rcu(fltr, head, hash) {
7202 if (bnxt_fltr_match(fltr, new_fltr)) {
7203 rcu_read_unlock();
7204 rc = 0;
7205 goto err_free;
7206 }
7207 }
7208 rcu_read_unlock();
7209
7210 spin_lock_bh(&bp->ntp_fltr_lock);
Michael Chan84e86b92015-11-05 16:25:50 -05007211 bit_id = bitmap_find_free_region(bp->ntp_fltr_bmap,
7212 BNXT_NTP_FLTR_MAX_FLTR, 0);
7213 if (bit_id < 0) {
Michael Chanc0c050c2015-10-22 16:01:17 -04007214 spin_unlock_bh(&bp->ntp_fltr_lock);
7215 rc = -ENOMEM;
7216 goto err_free;
7217 }
7218
Michael Chan84e86b92015-11-05 16:25:50 -05007219 new_fltr->sw_id = (u16)bit_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04007220 new_fltr->flow_id = flow_id;
Michael Chana54c4d72016-07-25 12:33:35 -04007221 new_fltr->l2_fltr_idx = l2_idx;
Michael Chanc0c050c2015-10-22 16:01:17 -04007222 new_fltr->rxq = rxq_index;
7223 hlist_add_head_rcu(&new_fltr->hash, head);
7224 bp->ntp_fltr_count++;
7225 spin_unlock_bh(&bp->ntp_fltr_lock);
7226
7227 set_bit(BNXT_RX_NTP_FLTR_SP_EVENT, &bp->sp_event);
7228 schedule_work(&bp->sp_task);
7229
7230 return new_fltr->sw_id;
7231
7232err_free:
7233 kfree(new_fltr);
7234 return rc;
7235}
7236
7237static void bnxt_cfg_ntp_filters(struct bnxt *bp)
7238{
7239 int i;
7240
7241 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
7242 struct hlist_head *head;
7243 struct hlist_node *tmp;
7244 struct bnxt_ntuple_filter *fltr;
7245 int rc;
7246
7247 head = &bp->ntp_fltr_hash_tbl[i];
7248 hlist_for_each_entry_safe(fltr, tmp, head, hash) {
7249 bool del = false;
7250
7251 if (test_bit(BNXT_FLTR_VALID, &fltr->state)) {
7252 if (rps_may_expire_flow(bp->dev, fltr->rxq,
7253 fltr->flow_id,
7254 fltr->sw_id)) {
7255 bnxt_hwrm_cfa_ntuple_filter_free(bp,
7256 fltr);
7257 del = true;
7258 }
7259 } else {
7260 rc = bnxt_hwrm_cfa_ntuple_filter_alloc(bp,
7261 fltr);
7262 if (rc)
7263 del = true;
7264 else
7265 set_bit(BNXT_FLTR_VALID, &fltr->state);
7266 }
7267
7268 if (del) {
7269 spin_lock_bh(&bp->ntp_fltr_lock);
7270 hlist_del_rcu(&fltr->hash);
7271 bp->ntp_fltr_count--;
7272 spin_unlock_bh(&bp->ntp_fltr_lock);
7273 synchronize_rcu();
7274 clear_bit(fltr->sw_id, bp->ntp_fltr_bmap);
7275 kfree(fltr);
7276 }
7277 }
7278 }
Jeffrey Huang19241362016-02-26 04:00:00 -05007279 if (test_and_clear_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT, &bp->sp_event))
7280 netdev_info(bp->dev, "Receive PF driver unload event!");
Michael Chanc0c050c2015-10-22 16:01:17 -04007281}
7282
7283#else
7284
7285static void bnxt_cfg_ntp_filters(struct bnxt *bp)
7286{
7287}
7288
7289#endif /* CONFIG_RFS_ACCEL */
7290
Alexander Duyckad51b8e2016-06-16 12:21:19 -07007291static void bnxt_udp_tunnel_add(struct net_device *dev,
7292 struct udp_tunnel_info *ti)
Michael Chanc0c050c2015-10-22 16:01:17 -04007293{
7294 struct bnxt *bp = netdev_priv(dev);
7295
Alexander Duyckad51b8e2016-06-16 12:21:19 -07007296 if (ti->sa_family != AF_INET6 && ti->sa_family != AF_INET)
7297 return;
7298
Michael Chanc0c050c2015-10-22 16:01:17 -04007299 if (!netif_running(dev))
7300 return;
7301
Alexander Duyckad51b8e2016-06-16 12:21:19 -07007302 switch (ti->type) {
7303 case UDP_TUNNEL_TYPE_VXLAN:
7304 if (bp->vxlan_port_cnt && bp->vxlan_port != ti->port)
7305 return;
Michael Chanc0c050c2015-10-22 16:01:17 -04007306
Alexander Duyckad51b8e2016-06-16 12:21:19 -07007307 bp->vxlan_port_cnt++;
7308 if (bp->vxlan_port_cnt == 1) {
7309 bp->vxlan_port = ti->port;
7310 set_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT, &bp->sp_event);
Michael Chanc0c050c2015-10-22 16:01:17 -04007311 schedule_work(&bp->sp_task);
7312 }
Alexander Duyckad51b8e2016-06-16 12:21:19 -07007313 break;
Alexander Duyck7cdd5fc2016-06-16 12:21:36 -07007314 case UDP_TUNNEL_TYPE_GENEVE:
7315 if (bp->nge_port_cnt && bp->nge_port != ti->port)
7316 return;
7317
7318 bp->nge_port_cnt++;
7319 if (bp->nge_port_cnt == 1) {
7320 bp->nge_port = ti->port;
7321 set_bit(BNXT_GENEVE_ADD_PORT_SP_EVENT, &bp->sp_event);
7322 }
7323 break;
Alexander Duyckad51b8e2016-06-16 12:21:19 -07007324 default:
7325 return;
Michael Chanc0c050c2015-10-22 16:01:17 -04007326 }
Alexander Duyckad51b8e2016-06-16 12:21:19 -07007327
7328 schedule_work(&bp->sp_task);
7329}
7330
7331static void bnxt_udp_tunnel_del(struct net_device *dev,
7332 struct udp_tunnel_info *ti)
7333{
7334 struct bnxt *bp = netdev_priv(dev);
7335
7336 if (ti->sa_family != AF_INET6 && ti->sa_family != AF_INET)
7337 return;
7338
7339 if (!netif_running(dev))
7340 return;
7341
7342 switch (ti->type) {
7343 case UDP_TUNNEL_TYPE_VXLAN:
7344 if (!bp->vxlan_port_cnt || bp->vxlan_port != ti->port)
7345 return;
7346 bp->vxlan_port_cnt--;
7347
7348 if (bp->vxlan_port_cnt != 0)
7349 return;
7350
7351 set_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT, &bp->sp_event);
7352 break;
Alexander Duyck7cdd5fc2016-06-16 12:21:36 -07007353 case UDP_TUNNEL_TYPE_GENEVE:
7354 if (!bp->nge_port_cnt || bp->nge_port != ti->port)
7355 return;
7356 bp->nge_port_cnt--;
7357
7358 if (bp->nge_port_cnt != 0)
7359 return;
7360
7361 set_bit(BNXT_GENEVE_DEL_PORT_SP_EVENT, &bp->sp_event);
7362 break;
Alexander Duyckad51b8e2016-06-16 12:21:19 -07007363 default:
7364 return;
7365 }
7366
7367 schedule_work(&bp->sp_task);
Michael Chanc0c050c2015-10-22 16:01:17 -04007368}
7369
7370static const struct net_device_ops bnxt_netdev_ops = {
7371 .ndo_open = bnxt_open,
7372 .ndo_start_xmit = bnxt_start_xmit,
7373 .ndo_stop = bnxt_close,
7374 .ndo_get_stats64 = bnxt_get_stats64,
7375 .ndo_set_rx_mode = bnxt_set_rx_mode,
7376 .ndo_do_ioctl = bnxt_ioctl,
7377 .ndo_validate_addr = eth_validate_addr,
7378 .ndo_set_mac_address = bnxt_change_mac_addr,
7379 .ndo_change_mtu = bnxt_change_mtu,
7380 .ndo_fix_features = bnxt_fix_features,
7381 .ndo_set_features = bnxt_set_features,
7382 .ndo_tx_timeout = bnxt_tx_timeout,
7383#ifdef CONFIG_BNXT_SRIOV
7384 .ndo_get_vf_config = bnxt_get_vf_config,
7385 .ndo_set_vf_mac = bnxt_set_vf_mac,
7386 .ndo_set_vf_vlan = bnxt_set_vf_vlan,
7387 .ndo_set_vf_rate = bnxt_set_vf_bw,
7388 .ndo_set_vf_link_state = bnxt_set_vf_link_state,
7389 .ndo_set_vf_spoofchk = bnxt_set_vf_spoofchk,
7390#endif
7391#ifdef CONFIG_NET_POLL_CONTROLLER
7392 .ndo_poll_controller = bnxt_poll_controller,
7393#endif
7394 .ndo_setup_tc = bnxt_setup_tc,
7395#ifdef CONFIG_RFS_ACCEL
7396 .ndo_rx_flow_steer = bnxt_rx_flow_steer,
7397#endif
Alexander Duyckad51b8e2016-06-16 12:21:19 -07007398 .ndo_udp_tunnel_add = bnxt_udp_tunnel_add,
7399 .ndo_udp_tunnel_del = bnxt_udp_tunnel_del,
Michael Chanc6d30e82017-02-06 16:55:42 -05007400 .ndo_xdp = bnxt_xdp,
Michael Chanc0c050c2015-10-22 16:01:17 -04007401};
7402
7403static void bnxt_remove_one(struct pci_dev *pdev)
7404{
7405 struct net_device *dev = pci_get_drvdata(pdev);
7406 struct bnxt *bp = netdev_priv(dev);
7407
7408 if (BNXT_PF(bp))
7409 bnxt_sriov_disable(bp);
7410
Satish Baddipadige6316ea62016-03-07 15:38:48 -05007411 pci_disable_pcie_error_reporting(pdev);
Michael Chanc0c050c2015-10-22 16:01:17 -04007412 unregister_netdev(dev);
7413 cancel_work_sync(&bp->sp_task);
7414 bp->sp_event = 0;
7415
Michael Chan78095922016-12-07 00:26:16 -05007416 bnxt_clear_int_mode(bp);
Jeffrey Huangbe58a0d2015-12-27 18:19:18 -05007417 bnxt_hwrm_func_drv_unrgtr(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04007418 bnxt_free_hwrm_resources(bp);
Deepak Khungare605db82017-05-29 19:06:04 -04007419 bnxt_free_hwrm_short_cmd_req(bp);
Michael Chaneb513652017-04-04 18:14:12 -04007420 bnxt_ethtool_free(bp);
Michael Chan7df4ae92016-12-02 21:17:17 -05007421 bnxt_dcb_free(bp);
Michael Chana588e452016-12-07 00:26:21 -05007422 kfree(bp->edev);
7423 bp->edev = NULL;
Michael Chanc6d30e82017-02-06 16:55:42 -05007424 if (bp->xdp_prog)
7425 bpf_prog_put(bp->xdp_prog);
Sathya Perla17086392017-02-20 19:25:18 -05007426 bnxt_cleanup_pci(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04007427 free_netdev(dev);
Michael Chanc0c050c2015-10-22 16:01:17 -04007428}
7429
7430static int bnxt_probe_phy(struct bnxt *bp)
7431{
7432 int rc = 0;
7433 struct bnxt_link_info *link_info = &bp->link_info;
Michael Chanc0c050c2015-10-22 16:01:17 -04007434
Michael Chan170ce012016-04-05 14:08:57 -04007435 rc = bnxt_hwrm_phy_qcaps(bp);
7436 if (rc) {
7437 netdev_err(bp->dev, "Probe phy can't get phy capabilities (rc: %x)\n",
7438 rc);
7439 return rc;
7440 }
7441
Michael Chanc0c050c2015-10-22 16:01:17 -04007442 rc = bnxt_update_link(bp, false);
7443 if (rc) {
7444 netdev_err(bp->dev, "Probe phy can't update link (rc: %x)\n",
7445 rc);
7446 return rc;
7447 }
7448
Michael Chan93ed8112016-06-13 02:25:37 -04007449 /* Older firmware does not have supported_auto_speeds, so assume
7450 * that all supported speeds can be autonegotiated.
7451 */
7452 if (link_info->auto_link_speeds && !link_info->support_auto_speeds)
7453 link_info->support_auto_speeds = link_info->support_speeds;
7454
Michael Chanc0c050c2015-10-22 16:01:17 -04007455 /*initialize the ethool setting copy with NVM settings */
Michael Chan0d8abf02016-02-10 17:33:47 -05007456 if (BNXT_AUTO_MODE(link_info->auto_mode)) {
Michael Chanc9ee9512016-04-05 14:08:56 -04007457 link_info->autoneg = BNXT_AUTONEG_SPEED;
7458 if (bp->hwrm_spec_code >= 0x10201) {
7459 if (link_info->auto_pause_setting &
7460 PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE)
7461 link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
7462 } else {
7463 link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
7464 }
Michael Chan0d8abf02016-02-10 17:33:47 -05007465 link_info->advertising = link_info->auto_link_speeds;
Michael Chan0d8abf02016-02-10 17:33:47 -05007466 } else {
7467 link_info->req_link_speed = link_info->force_link_speed;
7468 link_info->req_duplex = link_info->duplex_setting;
Michael Chanc0c050c2015-10-22 16:01:17 -04007469 }
Michael Chanc9ee9512016-04-05 14:08:56 -04007470 if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL)
7471 link_info->req_flow_ctrl =
7472 link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH;
7473 else
7474 link_info->req_flow_ctrl = link_info->force_pause_setting;
Michael Chanc0c050c2015-10-22 16:01:17 -04007475 return rc;
7476}
7477
7478static int bnxt_get_max_irq(struct pci_dev *pdev)
7479{
7480 u16 ctrl;
7481
7482 if (!pdev->msix_cap)
7483 return 1;
7484
7485 pci_read_config_word(pdev, pdev->msix_cap + PCI_MSIX_FLAGS, &ctrl);
7486 return (ctrl & PCI_MSIX_FLAGS_QSIZE) + 1;
7487}
7488
Michael Chan6e6c5a52016-01-02 23:45:02 -05007489static void _bnxt_get_max_rings(struct bnxt *bp, int *max_rx, int *max_tx,
7490 int *max_cp)
Michael Chanc0c050c2015-10-22 16:01:17 -04007491{
Michael Chan6e6c5a52016-01-02 23:45:02 -05007492 int max_ring_grps = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04007493
Michael Chan379a80a2015-10-23 15:06:19 -04007494#ifdef CONFIG_BNXT_SRIOV
Arnd Bergmann415b6f12016-01-12 16:05:08 +01007495 if (!BNXT_PF(bp)) {
Michael Chanc0c050c2015-10-22 16:01:17 -04007496 *max_tx = bp->vf.max_tx_rings;
7497 *max_rx = bp->vf.max_rx_rings;
Michael Chan6e6c5a52016-01-02 23:45:02 -05007498 *max_cp = min_t(int, bp->vf.max_irqs, bp->vf.max_cp_rings);
7499 *max_cp = min_t(int, *max_cp, bp->vf.max_stat_ctxs);
Michael Chanb72d4a62015-12-27 18:19:27 -05007500 max_ring_grps = bp->vf.max_hw_ring_grps;
Arnd Bergmann415b6f12016-01-12 16:05:08 +01007501 } else
Michael Chan379a80a2015-10-23 15:06:19 -04007502#endif
Arnd Bergmann415b6f12016-01-12 16:05:08 +01007503 {
7504 *max_tx = bp->pf.max_tx_rings;
7505 *max_rx = bp->pf.max_rx_rings;
7506 *max_cp = min_t(int, bp->pf.max_irqs, bp->pf.max_cp_rings);
7507 *max_cp = min_t(int, *max_cp, bp->pf.max_stat_ctxs);
7508 max_ring_grps = bp->pf.max_hw_ring_grps;
Michael Chanc0c050c2015-10-22 16:01:17 -04007509 }
Prashant Sreedharan76595192016-07-18 07:15:22 -04007510 if (BNXT_CHIP_TYPE_NITRO_A0(bp) && BNXT_PF(bp)) {
7511 *max_cp -= 1;
7512 *max_rx -= 2;
7513 }
Michael Chanc0c050c2015-10-22 16:01:17 -04007514 if (bp->flags & BNXT_FLAG_AGG_RINGS)
7515 *max_rx >>= 1;
Michael Chanb72d4a62015-12-27 18:19:27 -05007516 *max_rx = min_t(int, *max_rx, max_ring_grps);
Michael Chan6e6c5a52016-01-02 23:45:02 -05007517}
7518
7519int bnxt_get_max_rings(struct bnxt *bp, int *max_rx, int *max_tx, bool shared)
7520{
7521 int rx, tx, cp;
7522
7523 _bnxt_get_max_rings(bp, &rx, &tx, &cp);
7524 if (!rx || !tx || !cp)
7525 return -ENOMEM;
7526
7527 *max_rx = rx;
7528 *max_tx = tx;
7529 return bnxt_trim_rings(bp, max_rx, max_tx, cp, shared);
7530}
7531
Michael Chane4060d32016-12-07 00:26:19 -05007532static int bnxt_get_dflt_rings(struct bnxt *bp, int *max_rx, int *max_tx,
7533 bool shared)
7534{
7535 int rc;
7536
7537 rc = bnxt_get_max_rings(bp, max_rx, max_tx, shared);
Michael Chanbdbd1eb2016-12-29 12:13:43 -05007538 if (rc && (bp->flags & BNXT_FLAG_AGG_RINGS)) {
7539 /* Not enough rings, try disabling agg rings. */
7540 bp->flags &= ~BNXT_FLAG_AGG_RINGS;
7541 rc = bnxt_get_max_rings(bp, max_rx, max_tx, shared);
7542 if (rc)
7543 return rc;
7544 bp->flags |= BNXT_FLAG_NO_AGG_RINGS;
7545 bp->dev->hw_features &= ~NETIF_F_LRO;
7546 bp->dev->features &= ~NETIF_F_LRO;
7547 bnxt_set_ring_params(bp);
7548 }
Michael Chane4060d32016-12-07 00:26:19 -05007549
7550 if (bp->flags & BNXT_FLAG_ROCE_CAP) {
7551 int max_cp, max_stat, max_irq;
7552
7553 /* Reserve minimum resources for RoCE */
7554 max_cp = bnxt_get_max_func_cp_rings(bp);
7555 max_stat = bnxt_get_max_func_stat_ctxs(bp);
7556 max_irq = bnxt_get_max_func_irqs(bp);
7557 if (max_cp <= BNXT_MIN_ROCE_CP_RINGS ||
7558 max_irq <= BNXT_MIN_ROCE_CP_RINGS ||
7559 max_stat <= BNXT_MIN_ROCE_STAT_CTXS)
7560 return 0;
7561
7562 max_cp -= BNXT_MIN_ROCE_CP_RINGS;
7563 max_irq -= BNXT_MIN_ROCE_CP_RINGS;
7564 max_stat -= BNXT_MIN_ROCE_STAT_CTXS;
7565 max_cp = min_t(int, max_cp, max_irq);
7566 max_cp = min_t(int, max_cp, max_stat);
7567 rc = bnxt_trim_rings(bp, max_rx, max_tx, max_cp, shared);
7568 if (rc)
7569 rc = 0;
7570 }
7571 return rc;
7572}
7573
Michael Chan6e6c5a52016-01-02 23:45:02 -05007574static int bnxt_set_dflt_rings(struct bnxt *bp)
7575{
7576 int dflt_rings, max_rx_rings, max_tx_rings, rc;
7577 bool sh = true;
7578
7579 if (sh)
7580 bp->flags |= BNXT_FLAG_SHARED_RINGS;
7581 dflt_rings = netif_get_num_default_rss_queues();
Michael Chane4060d32016-12-07 00:26:19 -05007582 rc = bnxt_get_dflt_rings(bp, &max_rx_rings, &max_tx_rings, sh);
Michael Chan6e6c5a52016-01-02 23:45:02 -05007583 if (rc)
7584 return rc;
7585 bp->rx_nr_rings = min_t(int, dflt_rings, max_rx_rings);
7586 bp->tx_nr_rings_per_tc = min_t(int, dflt_rings, max_tx_rings);
Michael Chan391be5c2016-12-29 12:13:41 -05007587
7588 rc = bnxt_hwrm_reserve_tx_rings(bp, &bp->tx_nr_rings_per_tc);
7589 if (rc)
7590 netdev_warn(bp->dev, "Unable to reserve tx rings\n");
7591
Michael Chan6e6c5a52016-01-02 23:45:02 -05007592 bp->tx_nr_rings = bp->tx_nr_rings_per_tc;
7593 bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
7594 bp->tx_nr_rings + bp->rx_nr_rings;
7595 bp->num_stat_ctxs = bp->cp_nr_rings;
Prashant Sreedharan76595192016-07-18 07:15:22 -04007596 if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
7597 bp->rx_nr_rings++;
7598 bp->cp_nr_rings++;
7599 }
Michael Chan6e6c5a52016-01-02 23:45:02 -05007600 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04007601}
7602
Michael Chan7b08f662016-12-07 00:26:18 -05007603void bnxt_restore_pf_fw_resources(struct bnxt *bp)
7604{
7605 ASSERT_RTNL();
7606 bnxt_hwrm_func_qcaps(bp);
Michael Chana588e452016-12-07 00:26:21 -05007607 bnxt_subtract_ulp_resources(bp, BNXT_ROCE_ULP);
Michael Chan7b08f662016-12-07 00:26:18 -05007608}
7609
Ajit Khaparde90c4f782016-05-15 03:04:45 -04007610static void bnxt_parse_log_pcie_link(struct bnxt *bp)
7611{
7612 enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN;
7613 enum pci_bus_speed speed = PCI_SPEED_UNKNOWN;
7614
7615 if (pcie_get_minimum_link(bp->pdev, &speed, &width) ||
7616 speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN)
7617 netdev_info(bp->dev, "Failed to determine PCIe Link Info\n");
7618 else
7619 netdev_info(bp->dev, "PCIe: Speed %s Width x%d\n",
7620 speed == PCIE_SPEED_2_5GT ? "2.5GT/s" :
7621 speed == PCIE_SPEED_5_0GT ? "5.0GT/s" :
7622 speed == PCIE_SPEED_8_0GT ? "8.0GT/s" :
7623 "Unknown", width);
7624}
7625
Michael Chanc0c050c2015-10-22 16:01:17 -04007626static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
7627{
7628 static int version_printed;
7629 struct net_device *dev;
7630 struct bnxt *bp;
Michael Chan6e6c5a52016-01-02 23:45:02 -05007631 int rc, max_irqs;
Michael Chanc0c050c2015-10-22 16:01:17 -04007632
Ray Jui4e003382017-02-20 19:25:16 -05007633 if (pci_is_bridge(pdev))
Prashant Sreedharanfa853dd2016-07-18 07:15:25 -04007634 return -ENODEV;
7635
Michael Chanc0c050c2015-10-22 16:01:17 -04007636 if (version_printed++ == 0)
7637 pr_info("%s", version);
7638
7639 max_irqs = bnxt_get_max_irq(pdev);
7640 dev = alloc_etherdev_mq(sizeof(*bp), max_irqs);
7641 if (!dev)
7642 return -ENOMEM;
7643
7644 bp = netdev_priv(dev);
7645
7646 if (bnxt_vf_pciid(ent->driver_data))
7647 bp->flags |= BNXT_FLAG_VF;
7648
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007649 if (pdev->msix_cap)
Michael Chanc0c050c2015-10-22 16:01:17 -04007650 bp->flags |= BNXT_FLAG_MSIX_CAP;
Michael Chanc0c050c2015-10-22 16:01:17 -04007651
7652 rc = bnxt_init_board(pdev, dev);
7653 if (rc < 0)
7654 goto init_err_free;
7655
7656 dev->netdev_ops = &bnxt_netdev_ops;
7657 dev->watchdog_timeo = BNXT_TX_TIMEOUT;
7658 dev->ethtool_ops = &bnxt_ethtool_ops;
Michael Chanc0c050c2015-10-22 16:01:17 -04007659 pci_set_drvdata(pdev, dev);
7660
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04007661 rc = bnxt_alloc_hwrm_resources(bp);
7662 if (rc)
Sathya Perla17086392017-02-20 19:25:18 -05007663 goto init_err_pci_clean;
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04007664
7665 mutex_init(&bp->hwrm_cmd_lock);
7666 rc = bnxt_hwrm_ver_get(bp);
7667 if (rc)
Sathya Perla17086392017-02-20 19:25:18 -05007668 goto init_err_pci_clean;
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04007669
Deepak Khungare605db82017-05-29 19:06:04 -04007670 if (bp->flags & BNXT_FLAG_SHORT_CMD) {
7671 rc = bnxt_alloc_hwrm_short_cmd_req(bp);
7672 if (rc)
7673 goto init_err_pci_clean;
7674 }
7675
Michael Chan3c2217a2017-03-08 18:44:32 -05007676 rc = bnxt_hwrm_func_reset(bp);
7677 if (rc)
7678 goto init_err_pci_clean;
7679
Rob Swindell5ac67d82016-09-19 03:58:03 -04007680 bnxt_hwrm_fw_set_time(bp);
7681
Michael Chanc0c050c2015-10-22 16:01:17 -04007682 dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
7683 NETIF_F_TSO | NETIF_F_TSO6 |
7684 NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_GRE |
Tom Herbert7e133182016-05-18 09:06:10 -07007685 NETIF_F_GSO_IPXIP4 |
Alexander Duyck152971e2016-05-02 09:38:55 -07007686 NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_GSO_GRE_CSUM |
7687 NETIF_F_GSO_PARTIAL | NETIF_F_RXHASH |
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04007688 NETIF_F_RXCSUM | NETIF_F_GRO;
7689
7690 if (!BNXT_CHIP_TYPE_NITRO_A0(bp))
7691 dev->hw_features |= NETIF_F_LRO;
Michael Chanc0c050c2015-10-22 16:01:17 -04007692
Michael Chanc0c050c2015-10-22 16:01:17 -04007693 dev->hw_enc_features =
7694 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
7695 NETIF_F_TSO | NETIF_F_TSO6 |
7696 NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_GRE |
Alexander Duyck152971e2016-05-02 09:38:55 -07007697 NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_GSO_GRE_CSUM |
Tom Herbert7e133182016-05-18 09:06:10 -07007698 NETIF_F_GSO_IPXIP4 | NETIF_F_GSO_PARTIAL;
Alexander Duyck152971e2016-05-02 09:38:55 -07007699 dev->gso_partial_features = NETIF_F_GSO_UDP_TUNNEL_CSUM |
7700 NETIF_F_GSO_GRE_CSUM;
Michael Chanc0c050c2015-10-22 16:01:17 -04007701 dev->vlan_features = dev->hw_features | NETIF_F_HIGHDMA;
7702 dev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX |
7703 NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_STAG_TX;
7704 dev->features |= dev->hw_features | NETIF_F_HIGHDMA;
7705 dev->priv_flags |= IFF_UNICAST_FLT;
7706
Jarod Wilsone1c6dcc2016-10-17 15:54:04 -04007707 /* MTU range: 60 - 9500 */
7708 dev->min_mtu = ETH_ZLEN;
Michael Chanc61fb992017-02-06 16:55:36 -05007709 dev->max_mtu = BNXT_MAX_MTU;
Jarod Wilsone1c6dcc2016-10-17 15:54:04 -04007710
Michael Chanc0c050c2015-10-22 16:01:17 -04007711#ifdef CONFIG_BNXT_SRIOV
7712 init_waitqueue_head(&bp->sriov_cfg_wait);
7713#endif
Michael Chan309369c2016-06-13 02:25:34 -04007714 bp->gro_func = bnxt_gro_func_5730x;
Michael Chan94758f82016-06-13 02:25:35 -04007715 if (BNXT_CHIP_NUM_57X1X(bp->chip_num))
7716 bp->gro_func = bnxt_gro_func_5731x;
Michael Chan309369c2016-06-13 02:25:34 -04007717
Michael Chanc0c050c2015-10-22 16:01:17 -04007718 rc = bnxt_hwrm_func_drv_rgtr(bp);
7719 if (rc)
Sathya Perla17086392017-02-20 19:25:18 -05007720 goto init_err_pci_clean;
Michael Chanc0c050c2015-10-22 16:01:17 -04007721
Michael Chana1653b12016-12-07 00:26:20 -05007722 rc = bnxt_hwrm_func_rgtr_async_events(bp, NULL, 0);
7723 if (rc)
Sathya Perla17086392017-02-20 19:25:18 -05007724 goto init_err_pci_clean;
Michael Chana1653b12016-12-07 00:26:20 -05007725
Michael Chana588e452016-12-07 00:26:21 -05007726 bp->ulp_probe = bnxt_ulp_probe;
7727
Michael Chanc0c050c2015-10-22 16:01:17 -04007728 /* Get the MAX capabilities for this function */
7729 rc = bnxt_hwrm_func_qcaps(bp);
7730 if (rc) {
7731 netdev_err(bp->dev, "hwrm query capability failure rc: %x\n",
7732 rc);
7733 rc = -1;
Sathya Perla17086392017-02-20 19:25:18 -05007734 goto init_err_pci_clean;
Michael Chanc0c050c2015-10-22 16:01:17 -04007735 }
7736
7737 rc = bnxt_hwrm_queue_qportcfg(bp);
7738 if (rc) {
7739 netdev_err(bp->dev, "hwrm query qportcfg failure rc: %x\n",
7740 rc);
7741 rc = -1;
Sathya Perla17086392017-02-20 19:25:18 -05007742 goto init_err_pci_clean;
Michael Chanc0c050c2015-10-22 16:01:17 -04007743 }
7744
Satish Baddipadige567b2ab2016-06-13 02:25:31 -04007745 bnxt_hwrm_func_qcfg(bp);
Michael Chan5ad2cbe2017-01-13 01:32:03 -05007746 bnxt_hwrm_port_led_qcaps(bp);
Michael Chaneb513652017-04-04 18:14:12 -04007747 bnxt_ethtool_init(bp);
Michael Chan87fe6032017-05-16 16:39:43 -04007748 bnxt_dcb_init(bp);
Satish Baddipadige567b2ab2016-06-13 02:25:31 -04007749
Michael Chanc61fb992017-02-06 16:55:36 -05007750 bnxt_set_rx_skb_mode(bp, false);
Michael Chanc0c050c2015-10-22 16:01:17 -04007751 bnxt_set_tpa_flags(bp);
7752 bnxt_set_ring_params(bp);
Michael Chan33c26572016-12-07 00:26:15 -05007753 bnxt_set_max_func_irqs(bp, max_irqs);
Michael Chanbdbd1eb2016-12-29 12:13:43 -05007754 rc = bnxt_set_dflt_rings(bp);
7755 if (rc) {
7756 netdev_err(bp->dev, "Not enough rings available.\n");
7757 rc = -ENOMEM;
Sathya Perla17086392017-02-20 19:25:18 -05007758 goto init_err_pci_clean;
Michael Chanbdbd1eb2016-12-29 12:13:43 -05007759 }
Michael Chanc0c050c2015-10-22 16:01:17 -04007760
Michael Chan87da7f72016-11-16 21:13:09 -05007761 /* Default RSS hash cfg. */
7762 bp->rss_hash_cfg = VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4 |
7763 VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4 |
7764 VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6 |
7765 VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6;
7766 if (!BNXT_CHIP_NUM_57X0X(bp->chip_num) &&
7767 !BNXT_CHIP_TYPE_NITRO_A0(bp) &&
7768 bp->hwrm_spec_code >= 0x10501) {
7769 bp->flags |= BNXT_FLAG_UDP_RSS_CAP;
7770 bp->rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4 |
7771 VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6;
7772 }
7773
Michael Chan8fdefd62016-12-29 12:13:36 -05007774 bnxt_hwrm_vnic_qcaps(bp);
Michael Chan8079e8f2016-12-29 12:13:37 -05007775 if (bnxt_rfs_supported(bp)) {
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007776 dev->hw_features |= NETIF_F_NTUPLE;
7777 if (bnxt_rfs_capable(bp)) {
7778 bp->flags |= BNXT_FLAG_RFS;
7779 dev->features |= NETIF_F_NTUPLE;
7780 }
7781 }
7782
Michael Chanc0c050c2015-10-22 16:01:17 -04007783 if (dev->hw_features & NETIF_F_HW_VLAN_CTAG_RX)
7784 bp->flags |= BNXT_FLAG_STRIP_VLAN;
7785
7786 rc = bnxt_probe_phy(bp);
7787 if (rc)
Sathya Perla17086392017-02-20 19:25:18 -05007788 goto init_err_pci_clean;
Michael Chanc0c050c2015-10-22 16:01:17 -04007789
Michael Chan78095922016-12-07 00:26:16 -05007790 rc = bnxt_init_int_mode(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04007791 if (rc)
Sathya Perla17086392017-02-20 19:25:18 -05007792 goto init_err_pci_clean;
Michael Chanc0c050c2015-10-22 16:01:17 -04007793
Michael Chanc1ef1462017-04-04 18:14:07 -04007794 bnxt_get_wol_settings(bp);
Michael Chand196ece2017-04-04 18:14:08 -04007795 if (bp->flags & BNXT_FLAG_WOL_CAP)
7796 device_set_wakeup_enable(&pdev->dev, bp->wol);
7797 else
7798 device_set_wakeup_capable(&pdev->dev, false);
Michael Chanc1ef1462017-04-04 18:14:07 -04007799
Michael Chan78095922016-12-07 00:26:16 -05007800 rc = register_netdev(dev);
7801 if (rc)
7802 goto init_err_clr_int;
7803
Michael Chanc0c050c2015-10-22 16:01:17 -04007804 netdev_info(dev, "%s found at mem %lx, node addr %pM\n",
7805 board_info[ent->driver_data].name,
7806 (long)pci_resource_start(pdev, 0), dev->dev_addr);
7807
Ajit Khaparde90c4f782016-05-15 03:04:45 -04007808 bnxt_parse_log_pcie_link(bp);
7809
Michael Chanc0c050c2015-10-22 16:01:17 -04007810 return 0;
7811
Michael Chan78095922016-12-07 00:26:16 -05007812init_err_clr_int:
7813 bnxt_clear_int_mode(bp);
7814
Sathya Perla17086392017-02-20 19:25:18 -05007815init_err_pci_clean:
7816 bnxt_cleanup_pci(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04007817
7818init_err_free:
7819 free_netdev(dev);
7820 return rc;
7821}
7822
Michael Chand196ece2017-04-04 18:14:08 -04007823static void bnxt_shutdown(struct pci_dev *pdev)
7824{
7825 struct net_device *dev = pci_get_drvdata(pdev);
7826 struct bnxt *bp;
7827
7828 if (!dev)
7829 return;
7830
7831 rtnl_lock();
7832 bp = netdev_priv(dev);
7833 if (!bp)
7834 goto shutdown_exit;
7835
7836 if (netif_running(dev))
7837 dev_close(dev);
7838
7839 if (system_state == SYSTEM_POWER_OFF) {
7840 bnxt_clear_int_mode(bp);
7841 pci_wake_from_d3(pdev, bp->wol);
7842 pci_set_power_state(pdev, PCI_D3hot);
7843 }
7844
7845shutdown_exit:
7846 rtnl_unlock();
7847}
7848
Michael Chanf65a2042017-04-04 18:14:11 -04007849#ifdef CONFIG_PM_SLEEP
7850static int bnxt_suspend(struct device *device)
7851{
7852 struct pci_dev *pdev = to_pci_dev(device);
7853 struct net_device *dev = pci_get_drvdata(pdev);
7854 struct bnxt *bp = netdev_priv(dev);
7855 int rc = 0;
7856
7857 rtnl_lock();
7858 if (netif_running(dev)) {
7859 netif_device_detach(dev);
7860 rc = bnxt_close(dev);
7861 }
7862 bnxt_hwrm_func_drv_unrgtr(bp);
7863 rtnl_unlock();
7864 return rc;
7865}
7866
7867static int bnxt_resume(struct device *device)
7868{
7869 struct pci_dev *pdev = to_pci_dev(device);
7870 struct net_device *dev = pci_get_drvdata(pdev);
7871 struct bnxt *bp = netdev_priv(dev);
7872 int rc = 0;
7873
7874 rtnl_lock();
7875 if (bnxt_hwrm_ver_get(bp) || bnxt_hwrm_func_drv_rgtr(bp)) {
7876 rc = -ENODEV;
7877 goto resume_exit;
7878 }
7879 rc = bnxt_hwrm_func_reset(bp);
7880 if (rc) {
7881 rc = -EBUSY;
7882 goto resume_exit;
7883 }
7884 bnxt_get_wol_settings(bp);
7885 if (netif_running(dev)) {
7886 rc = bnxt_open(dev);
7887 if (!rc)
7888 netif_device_attach(dev);
7889 }
7890
7891resume_exit:
7892 rtnl_unlock();
7893 return rc;
7894}
7895
7896static SIMPLE_DEV_PM_OPS(bnxt_pm_ops, bnxt_suspend, bnxt_resume);
7897#define BNXT_PM_OPS (&bnxt_pm_ops)
7898
7899#else
7900
7901#define BNXT_PM_OPS NULL
7902
7903#endif /* CONFIG_PM_SLEEP */
7904
Satish Baddipadige6316ea62016-03-07 15:38:48 -05007905/**
7906 * bnxt_io_error_detected - called when PCI error is detected
7907 * @pdev: Pointer to PCI device
7908 * @state: The current pci connection state
7909 *
7910 * This function is called after a PCI bus error affecting
7911 * this device has been detected.
7912 */
7913static pci_ers_result_t bnxt_io_error_detected(struct pci_dev *pdev,
7914 pci_channel_state_t state)
7915{
7916 struct net_device *netdev = pci_get_drvdata(pdev);
Michael Chana588e452016-12-07 00:26:21 -05007917 struct bnxt *bp = netdev_priv(netdev);
Satish Baddipadige6316ea62016-03-07 15:38:48 -05007918
7919 netdev_info(netdev, "PCI I/O error detected\n");
7920
7921 rtnl_lock();
7922 netif_device_detach(netdev);
7923
Michael Chana588e452016-12-07 00:26:21 -05007924 bnxt_ulp_stop(bp);
7925
Satish Baddipadige6316ea62016-03-07 15:38:48 -05007926 if (state == pci_channel_io_perm_failure) {
7927 rtnl_unlock();
7928 return PCI_ERS_RESULT_DISCONNECT;
7929 }
7930
7931 if (netif_running(netdev))
7932 bnxt_close(netdev);
7933
7934 pci_disable_device(pdev);
7935 rtnl_unlock();
7936
7937 /* Request a slot slot reset. */
7938 return PCI_ERS_RESULT_NEED_RESET;
7939}
7940
7941/**
7942 * bnxt_io_slot_reset - called after the pci bus has been reset.
7943 * @pdev: Pointer to PCI device
7944 *
7945 * Restart the card from scratch, as if from a cold-boot.
7946 * At this point, the card has exprienced a hard reset,
7947 * followed by fixups by BIOS, and has its config space
7948 * set up identically to what it was at cold boot.
7949 */
7950static pci_ers_result_t bnxt_io_slot_reset(struct pci_dev *pdev)
7951{
7952 struct net_device *netdev = pci_get_drvdata(pdev);
7953 struct bnxt *bp = netdev_priv(netdev);
7954 int err = 0;
7955 pci_ers_result_t result = PCI_ERS_RESULT_DISCONNECT;
7956
7957 netdev_info(bp->dev, "PCI Slot Reset\n");
7958
7959 rtnl_lock();
7960
7961 if (pci_enable_device(pdev)) {
7962 dev_err(&pdev->dev,
7963 "Cannot re-enable PCI device after reset.\n");
7964 } else {
7965 pci_set_master(pdev);
7966
Michael Chanaa8ed022016-12-07 00:26:17 -05007967 err = bnxt_hwrm_func_reset(bp);
7968 if (!err && netif_running(netdev))
Satish Baddipadige6316ea62016-03-07 15:38:48 -05007969 err = bnxt_open(netdev);
7970
Michael Chana588e452016-12-07 00:26:21 -05007971 if (!err) {
Satish Baddipadige6316ea62016-03-07 15:38:48 -05007972 result = PCI_ERS_RESULT_RECOVERED;
Michael Chana588e452016-12-07 00:26:21 -05007973 bnxt_ulp_start(bp);
7974 }
Satish Baddipadige6316ea62016-03-07 15:38:48 -05007975 }
7976
7977 if (result != PCI_ERS_RESULT_RECOVERED && netif_running(netdev))
7978 dev_close(netdev);
7979
7980 rtnl_unlock();
7981
7982 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7983 if (err) {
7984 dev_err(&pdev->dev,
7985 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
7986 err); /* non-fatal, continue */
7987 }
7988
7989 return PCI_ERS_RESULT_RECOVERED;
7990}
7991
7992/**
7993 * bnxt_io_resume - called when traffic can start flowing again.
7994 * @pdev: Pointer to PCI device
7995 *
7996 * This callback is called when the error recovery driver tells
7997 * us that its OK to resume normal operation.
7998 */
7999static void bnxt_io_resume(struct pci_dev *pdev)
8000{
8001 struct net_device *netdev = pci_get_drvdata(pdev);
8002
8003 rtnl_lock();
8004
8005 netif_device_attach(netdev);
8006
8007 rtnl_unlock();
8008}
8009
8010static const struct pci_error_handlers bnxt_err_handler = {
8011 .error_detected = bnxt_io_error_detected,
8012 .slot_reset = bnxt_io_slot_reset,
8013 .resume = bnxt_io_resume
8014};
8015
Michael Chanc0c050c2015-10-22 16:01:17 -04008016static struct pci_driver bnxt_pci_driver = {
8017 .name = DRV_MODULE_NAME,
8018 .id_table = bnxt_pci_tbl,
8019 .probe = bnxt_init_one,
8020 .remove = bnxt_remove_one,
Michael Chand196ece2017-04-04 18:14:08 -04008021 .shutdown = bnxt_shutdown,
Michael Chanf65a2042017-04-04 18:14:11 -04008022 .driver.pm = BNXT_PM_OPS,
Satish Baddipadige6316ea62016-03-07 15:38:48 -05008023 .err_handler = &bnxt_err_handler,
Michael Chanc0c050c2015-10-22 16:01:17 -04008024#if defined(CONFIG_BNXT_SRIOV)
8025 .sriov_configure = bnxt_sriov_configure,
8026#endif
8027};
8028
8029module_pci_driver(bnxt_pci_driver);