blob: 6a1d18fc140faf0fdd10b6208d892085699591ea [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 Chan894aa692018-01-17 03:21:03 -05004 * Copyright (c) 2016-2018 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>
Michael Chan32e8239c2017-07-24 12:34:21 -040036#include <linux/if_bridge.h>
Rob Swindell5ac67d82016-09-19 03:58:03 -040037#include <linux/rtc.h>
Michael Chanc6d30e82017-02-06 16:55:42 -050038#include <linux/bpf.h>
Michael Chanc0c050c2015-10-22 16:01:17 -040039#include <net/ip.h>
40#include <net/tcp.h>
41#include <net/udp.h>
42#include <net/checksum.h>
43#include <net/ip6_checksum.h>
Alexander Duyckad51b8e2016-06-16 12:21:19 -070044#include <net/udp_tunnel.h>
Michael Chanc0c050c2015-10-22 16:01:17 -040045#include <linux/workqueue.h>
46#include <linux/prefetch.h>
47#include <linux/cache.h>
48#include <linux/log2.h>
49#include <linux/aer.h>
50#include <linux/bitmap.h>
51#include <linux/cpu_rmap.h>
Vasundhara Volam56f0fd82017-08-28 13:40:27 -040052#include <linux/cpumask.h>
Sathya Perla2ae74082017-08-28 13:40:33 -040053#include <net/pkt_cls.h>
Michael Chanc0c050c2015-10-22 16:01:17 -040054
55#include "bnxt_hsi.h"
56#include "bnxt.h"
Michael Chana588e452016-12-07 00:26:21 -050057#include "bnxt_ulp.h"
Michael Chanc0c050c2015-10-22 16:01:17 -040058#include "bnxt_sriov.h"
59#include "bnxt_ethtool.h"
Michael Chan7df4ae92016-12-02 21:17:17 -050060#include "bnxt_dcb.h"
Michael Chanc6d30e82017-02-06 16:55:42 -050061#include "bnxt_xdp.h"
Sathya Perla4ab0c6a2017-07-24 12:34:27 -040062#include "bnxt_vfr.h"
Sathya Perla2ae74082017-08-28 13:40:33 -040063#include "bnxt_tc.h"
Steve Lin3c467bf2017-10-19 10:45:56 -040064#include "bnxt_devlink.h"
Michael Chanc0c050c2015-10-22 16:01:17 -040065
66#define BNXT_TX_TIMEOUT (5 * HZ)
67
68static const char version[] =
69 "Broadcom NetXtreme-C/E driver " DRV_MODULE_NAME " v" DRV_MODULE_VERSION "\n";
70
71MODULE_LICENSE("GPL");
72MODULE_DESCRIPTION("Broadcom BCM573xx network driver");
73MODULE_VERSION(DRV_MODULE_VERSION);
74
75#define BNXT_RX_OFFSET (NET_SKB_PAD + NET_IP_ALIGN)
76#define BNXT_RX_DMA_OFFSET NET_SKB_PAD
77#define BNXT_RX_COPY_THRESH 256
78
Michael Chan4419dbe2016-02-10 17:33:49 -050079#define BNXT_TX_PUSH_THRESH 164
Michael Chanc0c050c2015-10-22 16:01:17 -040080
81enum board_idx {
David Christensenfbc9a522015-12-27 18:19:29 -050082 BCM57301,
Michael Chanc0c050c2015-10-22 16:01:17 -040083 BCM57302,
84 BCM57304,
Michael Chan1f681682016-07-25 12:33:37 -040085 BCM57417_NPAR,
Prashant Sreedharanfa853dd2016-07-18 07:15:25 -040086 BCM58700,
Michael Chanb24eb6a2016-06-13 02:25:36 -040087 BCM57311,
88 BCM57312,
David Christensenfbc9a522015-12-27 18:19:29 -050089 BCM57402,
Michael Chanc0c050c2015-10-22 16:01:17 -040090 BCM57404,
91 BCM57406,
Michael Chan1f681682016-07-25 12:33:37 -040092 BCM57402_NPAR,
93 BCM57407,
Michael Chanb24eb6a2016-06-13 02:25:36 -040094 BCM57412,
95 BCM57414,
96 BCM57416,
97 BCM57417,
Michael Chan1f681682016-07-25 12:33:37 -040098 BCM57412_NPAR,
Michael Chan5049e332016-05-15 03:04:50 -040099 BCM57314,
Michael Chan1f681682016-07-25 12:33:37 -0400100 BCM57417_SFP,
101 BCM57416_SFP,
102 BCM57404_NPAR,
103 BCM57406_NPAR,
104 BCM57407_SFP,
Michael Chanadbc8302016-09-19 03:58:01 -0400105 BCM57407_NPAR,
Michael Chan1f681682016-07-25 12:33:37 -0400106 BCM57414_NPAR,
107 BCM57416_NPAR,
Deepak Khungar32b40792017-02-12 19:18:18 -0500108 BCM57452,
109 BCM57454,
Vasundhara Volam92abef32018-01-17 03:21:13 -0500110 BCM5745x_NPAR,
Ray Jui4a581392017-08-28 13:40:28 -0400111 BCM58802,
Ray Jui8ed693b2017-10-26 11:51:20 -0400112 BCM58804,
Ray Jui4a581392017-08-28 13:40:28 -0400113 BCM58808,
Michael Chanadbc8302016-09-19 03:58:01 -0400114 NETXTREME_E_VF,
115 NETXTREME_C_VF,
Rob Miller618784e2017-10-26 11:51:21 -0400116 NETXTREME_S_VF,
Michael Chanc0c050c2015-10-22 16:01:17 -0400117};
118
119/* indexed by enum above */
120static const struct {
121 char *name;
122} board_info[] = {
Scott Branden27573a72017-08-28 13:40:29 -0400123 [BCM57301] = { "Broadcom BCM57301 NetXtreme-C 10Gb Ethernet" },
124 [BCM57302] = { "Broadcom BCM57302 NetXtreme-C 10Gb/25Gb Ethernet" },
125 [BCM57304] = { "Broadcom BCM57304 NetXtreme-C 10Gb/25Gb/40Gb/50Gb Ethernet" },
126 [BCM57417_NPAR] = { "Broadcom BCM57417 NetXtreme-E Ethernet Partition" },
127 [BCM58700] = { "Broadcom BCM58700 Nitro 1Gb/2.5Gb/10Gb Ethernet" },
128 [BCM57311] = { "Broadcom BCM57311 NetXtreme-C 10Gb Ethernet" },
129 [BCM57312] = { "Broadcom BCM57312 NetXtreme-C 10Gb/25Gb Ethernet" },
130 [BCM57402] = { "Broadcom BCM57402 NetXtreme-E 10Gb Ethernet" },
131 [BCM57404] = { "Broadcom BCM57404 NetXtreme-E 10Gb/25Gb Ethernet" },
132 [BCM57406] = { "Broadcom BCM57406 NetXtreme-E 10GBase-T Ethernet" },
133 [BCM57402_NPAR] = { "Broadcom BCM57402 NetXtreme-E Ethernet Partition" },
134 [BCM57407] = { "Broadcom BCM57407 NetXtreme-E 10GBase-T Ethernet" },
135 [BCM57412] = { "Broadcom BCM57412 NetXtreme-E 10Gb Ethernet" },
136 [BCM57414] = { "Broadcom BCM57414 NetXtreme-E 10Gb/25Gb Ethernet" },
137 [BCM57416] = { "Broadcom BCM57416 NetXtreme-E 10GBase-T Ethernet" },
138 [BCM57417] = { "Broadcom BCM57417 NetXtreme-E 10GBase-T Ethernet" },
139 [BCM57412_NPAR] = { "Broadcom BCM57412 NetXtreme-E Ethernet Partition" },
140 [BCM57314] = { "Broadcom BCM57314 NetXtreme-C 10Gb/25Gb/40Gb/50Gb Ethernet" },
141 [BCM57417_SFP] = { "Broadcom BCM57417 NetXtreme-E 10Gb/25Gb Ethernet" },
142 [BCM57416_SFP] = { "Broadcom BCM57416 NetXtreme-E 10Gb Ethernet" },
143 [BCM57404_NPAR] = { "Broadcom BCM57404 NetXtreme-E Ethernet Partition" },
144 [BCM57406_NPAR] = { "Broadcom BCM57406 NetXtreme-E Ethernet Partition" },
145 [BCM57407_SFP] = { "Broadcom BCM57407 NetXtreme-E 25Gb Ethernet" },
146 [BCM57407_NPAR] = { "Broadcom BCM57407 NetXtreme-E Ethernet Partition" },
147 [BCM57414_NPAR] = { "Broadcom BCM57414 NetXtreme-E Ethernet Partition" },
148 [BCM57416_NPAR] = { "Broadcom BCM57416 NetXtreme-E Ethernet Partition" },
149 [BCM57452] = { "Broadcom BCM57452 NetXtreme-E 10Gb/25Gb/40Gb/50Gb Ethernet" },
150 [BCM57454] = { "Broadcom BCM57454 NetXtreme-E 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" },
Vasundhara Volam92abef32018-01-17 03:21:13 -0500151 [BCM5745x_NPAR] = { "Broadcom BCM5745x NetXtreme-E Ethernet Partition" },
Scott Branden27573a72017-08-28 13:40:29 -0400152 [BCM58802] = { "Broadcom BCM58802 NetXtreme-S 10Gb/25Gb/40Gb/50Gb Ethernet" },
Ray Jui8ed693b2017-10-26 11:51:20 -0400153 [BCM58804] = { "Broadcom BCM58804 NetXtreme-S 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" },
Scott Branden27573a72017-08-28 13:40:29 -0400154 [BCM58808] = { "Broadcom BCM58808 NetXtreme-S 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" },
155 [NETXTREME_E_VF] = { "Broadcom NetXtreme-E Ethernet Virtual Function" },
156 [NETXTREME_C_VF] = { "Broadcom NetXtreme-C Ethernet Virtual Function" },
Rob Miller618784e2017-10-26 11:51:21 -0400157 [NETXTREME_S_VF] = { "Broadcom NetXtreme-S Ethernet Virtual Function" },
Michael Chanc0c050c2015-10-22 16:01:17 -0400158};
159
160static const struct pci_device_id bnxt_pci_tbl[] = {
Vasundhara Volam92abef32018-01-17 03:21:13 -0500161 { PCI_VDEVICE(BROADCOM, 0x1604), .driver_data = BCM5745x_NPAR },
162 { PCI_VDEVICE(BROADCOM, 0x1605), .driver_data = BCM5745x_NPAR },
Ray Jui4a581392017-08-28 13:40:28 -0400163 { PCI_VDEVICE(BROADCOM, 0x1614), .driver_data = BCM57454 },
Michael Chanadbc8302016-09-19 03:58:01 -0400164 { PCI_VDEVICE(BROADCOM, 0x16c0), .driver_data = BCM57417_NPAR },
David Christensenfbc9a522015-12-27 18:19:29 -0500165 { PCI_VDEVICE(BROADCOM, 0x16c8), .driver_data = BCM57301 },
Michael Chanc0c050c2015-10-22 16:01:17 -0400166 { PCI_VDEVICE(BROADCOM, 0x16c9), .driver_data = BCM57302 },
167 { PCI_VDEVICE(BROADCOM, 0x16ca), .driver_data = BCM57304 },
Michael Chan1f681682016-07-25 12:33:37 -0400168 { PCI_VDEVICE(BROADCOM, 0x16cc), .driver_data = BCM57417_NPAR },
Prashant Sreedharanfa853dd2016-07-18 07:15:25 -0400169 { PCI_VDEVICE(BROADCOM, 0x16cd), .driver_data = BCM58700 },
Michael Chanb24eb6a2016-06-13 02:25:36 -0400170 { PCI_VDEVICE(BROADCOM, 0x16ce), .driver_data = BCM57311 },
171 { PCI_VDEVICE(BROADCOM, 0x16cf), .driver_data = BCM57312 },
David Christensenfbc9a522015-12-27 18:19:29 -0500172 { PCI_VDEVICE(BROADCOM, 0x16d0), .driver_data = BCM57402 },
Michael Chanc0c050c2015-10-22 16:01:17 -0400173 { PCI_VDEVICE(BROADCOM, 0x16d1), .driver_data = BCM57404 },
174 { PCI_VDEVICE(BROADCOM, 0x16d2), .driver_data = BCM57406 },
Michael Chan1f681682016-07-25 12:33:37 -0400175 { PCI_VDEVICE(BROADCOM, 0x16d4), .driver_data = BCM57402_NPAR },
176 { PCI_VDEVICE(BROADCOM, 0x16d5), .driver_data = BCM57407 },
Michael Chanb24eb6a2016-06-13 02:25:36 -0400177 { PCI_VDEVICE(BROADCOM, 0x16d6), .driver_data = BCM57412 },
178 { PCI_VDEVICE(BROADCOM, 0x16d7), .driver_data = BCM57414 },
179 { PCI_VDEVICE(BROADCOM, 0x16d8), .driver_data = BCM57416 },
180 { PCI_VDEVICE(BROADCOM, 0x16d9), .driver_data = BCM57417 },
Michael Chan1f681682016-07-25 12:33:37 -0400181 { PCI_VDEVICE(BROADCOM, 0x16de), .driver_data = BCM57412_NPAR },
Michael Chan5049e332016-05-15 03:04:50 -0400182 { PCI_VDEVICE(BROADCOM, 0x16df), .driver_data = BCM57314 },
Michael Chan1f681682016-07-25 12:33:37 -0400183 { PCI_VDEVICE(BROADCOM, 0x16e2), .driver_data = BCM57417_SFP },
184 { PCI_VDEVICE(BROADCOM, 0x16e3), .driver_data = BCM57416_SFP },
185 { PCI_VDEVICE(BROADCOM, 0x16e7), .driver_data = BCM57404_NPAR },
186 { PCI_VDEVICE(BROADCOM, 0x16e8), .driver_data = BCM57406_NPAR },
187 { PCI_VDEVICE(BROADCOM, 0x16e9), .driver_data = BCM57407_SFP },
Michael Chanadbc8302016-09-19 03:58:01 -0400188 { PCI_VDEVICE(BROADCOM, 0x16ea), .driver_data = BCM57407_NPAR },
189 { PCI_VDEVICE(BROADCOM, 0x16eb), .driver_data = BCM57412_NPAR },
Michael Chan1f681682016-07-25 12:33:37 -0400190 { PCI_VDEVICE(BROADCOM, 0x16ec), .driver_data = BCM57414_NPAR },
Michael Chanadbc8302016-09-19 03:58:01 -0400191 { PCI_VDEVICE(BROADCOM, 0x16ed), .driver_data = BCM57414_NPAR },
Michael Chan1f681682016-07-25 12:33:37 -0400192 { PCI_VDEVICE(BROADCOM, 0x16ee), .driver_data = BCM57416_NPAR },
Michael Chanadbc8302016-09-19 03:58:01 -0400193 { PCI_VDEVICE(BROADCOM, 0x16ef), .driver_data = BCM57416_NPAR },
Ray Jui4a581392017-08-28 13:40:28 -0400194 { PCI_VDEVICE(BROADCOM, 0x16f0), .driver_data = BCM58808 },
Deepak Khungar32b40792017-02-12 19:18:18 -0500195 { PCI_VDEVICE(BROADCOM, 0x16f1), .driver_data = BCM57452 },
Ray Jui4a581392017-08-28 13:40:28 -0400196 { PCI_VDEVICE(BROADCOM, 0xd802), .driver_data = BCM58802 },
Ray Jui8ed693b2017-10-26 11:51:20 -0400197 { PCI_VDEVICE(BROADCOM, 0xd804), .driver_data = BCM58804 },
Michael Chanc0c050c2015-10-22 16:01:17 -0400198#ifdef CONFIG_BNXT_SRIOV
Deepak Khungarc7ef35e2017-05-29 19:06:05 -0400199 { PCI_VDEVICE(BROADCOM, 0x1606), .driver_data = NETXTREME_E_VF },
200 { PCI_VDEVICE(BROADCOM, 0x1609), .driver_data = NETXTREME_E_VF },
Michael Chanadbc8302016-09-19 03:58:01 -0400201 { PCI_VDEVICE(BROADCOM, 0x16c1), .driver_data = NETXTREME_E_VF },
202 { PCI_VDEVICE(BROADCOM, 0x16cb), .driver_data = NETXTREME_C_VF },
203 { PCI_VDEVICE(BROADCOM, 0x16d3), .driver_data = NETXTREME_E_VF },
204 { PCI_VDEVICE(BROADCOM, 0x16dc), .driver_data = NETXTREME_E_VF },
205 { PCI_VDEVICE(BROADCOM, 0x16e1), .driver_data = NETXTREME_C_VF },
206 { PCI_VDEVICE(BROADCOM, 0x16e5), .driver_data = NETXTREME_C_VF },
Rob Miller618784e2017-10-26 11:51:21 -0400207 { PCI_VDEVICE(BROADCOM, 0xd800), .driver_data = NETXTREME_S_VF },
Michael Chanc0c050c2015-10-22 16:01:17 -0400208#endif
209 { 0 }
210};
211
212MODULE_DEVICE_TABLE(pci, bnxt_pci_tbl);
213
214static const u16 bnxt_vf_req_snif[] = {
215 HWRM_FUNC_CFG,
Vasundhara Volam91cdda42018-01-17 03:21:14 -0500216 HWRM_FUNC_VF_CFG,
Michael Chanc0c050c2015-10-22 16:01:17 -0400217 HWRM_PORT_PHY_QCFG,
218 HWRM_CFA_L2_FILTER_ALLOC,
219};
220
Michael Chan25be8622016-04-05 14:09:00 -0400221static const u16 bnxt_async_events_arr[] = {
Michael Chan87c374d2016-12-02 21:17:16 -0500222 ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE,
223 ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD,
224 ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED,
225 ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE,
226 ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE,
Michael Chan25be8622016-04-05 14:09:00 -0400227};
228
Michael Chanc213eae2017-10-13 21:09:29 -0400229static struct workqueue_struct *bnxt_pf_wq;
230
Michael Chanc0c050c2015-10-22 16:01:17 -0400231static bool bnxt_vf_pciid(enum board_idx idx)
232{
Rob Miller618784e2017-10-26 11:51:21 -0400233 return (idx == NETXTREME_C_VF || idx == NETXTREME_E_VF ||
234 idx == NETXTREME_S_VF);
Michael Chanc0c050c2015-10-22 16:01:17 -0400235}
236
237#define DB_CP_REARM_FLAGS (DB_KEY_CP | DB_IDX_VALID)
238#define DB_CP_FLAGS (DB_KEY_CP | DB_IDX_VALID | DB_IRQ_DIS)
239#define DB_CP_IRQ_DIS_FLAGS (DB_KEY_CP | DB_IRQ_DIS)
240
241#define BNXT_CP_DB_REARM(db, raw_cons) \
242 writel(DB_CP_REARM_FLAGS | RING_CMP(raw_cons), db)
243
244#define BNXT_CP_DB(db, raw_cons) \
245 writel(DB_CP_FLAGS | RING_CMP(raw_cons), db)
246
247#define BNXT_CP_DB_IRQ_DIS(db) \
248 writel(DB_CP_IRQ_DIS_FLAGS, db)
249
Michael Chan38413402017-02-06 16:55:43 -0500250const u16 bnxt_lhint_arr[] = {
Michael Chanc0c050c2015-10-22 16:01:17 -0400251 TX_BD_FLAGS_LHINT_512_AND_SMALLER,
252 TX_BD_FLAGS_LHINT_512_TO_1023,
253 TX_BD_FLAGS_LHINT_1024_TO_2047,
254 TX_BD_FLAGS_LHINT_1024_TO_2047,
255 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
256 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
257 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
258 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
259 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
260 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
261 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
262 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
263 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
264 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
265 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
266 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
267 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
268 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
269 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
270};
271
Sathya Perlaee5c7fb2017-07-24 12:34:28 -0400272static u16 bnxt_xmit_get_cfa_action(struct sk_buff *skb)
273{
274 struct metadata_dst *md_dst = skb_metadata_dst(skb);
275
276 if (!md_dst || md_dst->type != METADATA_HW_PORT_MUX)
277 return 0;
278
279 return md_dst->u.port_info.port_id;
280}
281
Michael Chanc0c050c2015-10-22 16:01:17 -0400282static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
283{
284 struct bnxt *bp = netdev_priv(dev);
285 struct tx_bd *txbd;
286 struct tx_bd_ext *txbd1;
287 struct netdev_queue *txq;
288 int i;
289 dma_addr_t mapping;
290 unsigned int length, pad = 0;
291 u32 len, free_size, vlan_tag_flags, cfa_action, flags;
292 u16 prod, last_frag;
293 struct pci_dev *pdev = bp->pdev;
Michael Chanc0c050c2015-10-22 16:01:17 -0400294 struct bnxt_tx_ring_info *txr;
295 struct bnxt_sw_tx_bd *tx_buf;
296
297 i = skb_get_queue_mapping(skb);
298 if (unlikely(i >= bp->tx_nr_rings)) {
299 dev_kfree_skb_any(skb);
300 return NETDEV_TX_OK;
301 }
302
Michael Chanc0c050c2015-10-22 16:01:17 -0400303 txq = netdev_get_tx_queue(dev, i);
Michael Chana960dec2017-02-06 16:55:39 -0500304 txr = &bp->tx_ring[bp->tx_ring_map[i]];
Michael Chanc0c050c2015-10-22 16:01:17 -0400305 prod = txr->tx_prod;
306
307 free_size = bnxt_tx_avail(bp, txr);
308 if (unlikely(free_size < skb_shinfo(skb)->nr_frags + 2)) {
309 netif_tx_stop_queue(txq);
310 return NETDEV_TX_BUSY;
311 }
312
313 length = skb->len;
314 len = skb_headlen(skb);
315 last_frag = skb_shinfo(skb)->nr_frags;
316
317 txbd = &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)];
318
319 txbd->tx_bd_opaque = prod;
320
321 tx_buf = &txr->tx_buf_ring[prod];
322 tx_buf->skb = skb;
323 tx_buf->nr_frags = last_frag;
324
325 vlan_tag_flags = 0;
Sathya Perlaee5c7fb2017-07-24 12:34:28 -0400326 cfa_action = bnxt_xmit_get_cfa_action(skb);
Michael Chanc0c050c2015-10-22 16:01:17 -0400327 if (skb_vlan_tag_present(skb)) {
328 vlan_tag_flags = TX_BD_CFA_META_KEY_VLAN |
329 skb_vlan_tag_get(skb);
330 /* Currently supports 8021Q, 8021AD vlan offloads
331 * QINQ1, QINQ2, QINQ3 vlan headers are deprecated
332 */
333 if (skb->vlan_proto == htons(ETH_P_8021Q))
334 vlan_tag_flags |= 1 << TX_BD_CFA_META_TPID_SHIFT;
335 }
336
337 if (free_size == bp->tx_ring_size && length <= bp->tx_push_thresh) {
Michael Chan4419dbe2016-02-10 17:33:49 -0500338 struct tx_push_buffer *tx_push_buf = txr->tx_push;
339 struct tx_push_bd *tx_push = &tx_push_buf->push_bd;
340 struct tx_bd_ext *tx_push1 = &tx_push->txbd2;
341 void *pdata = tx_push_buf->data;
342 u64 *end;
343 int j, push_len;
Michael Chanc0c050c2015-10-22 16:01:17 -0400344
345 /* Set COAL_NOW to be ready quickly for the next push */
346 tx_push->tx_bd_len_flags_type =
347 cpu_to_le32((length << TX_BD_LEN_SHIFT) |
348 TX_BD_TYPE_LONG_TX_BD |
349 TX_BD_FLAGS_LHINT_512_AND_SMALLER |
350 TX_BD_FLAGS_COAL_NOW |
351 TX_BD_FLAGS_PACKET_END |
352 (2 << TX_BD_FLAGS_BD_CNT_SHIFT));
353
354 if (skb->ip_summed == CHECKSUM_PARTIAL)
355 tx_push1->tx_bd_hsize_lflags =
356 cpu_to_le32(TX_BD_FLAGS_TCP_UDP_CHKSUM);
357 else
358 tx_push1->tx_bd_hsize_lflags = 0;
359
360 tx_push1->tx_bd_cfa_meta = cpu_to_le32(vlan_tag_flags);
Sathya Perlaee5c7fb2017-07-24 12:34:28 -0400361 tx_push1->tx_bd_cfa_action =
362 cpu_to_le32(cfa_action << TX_BD_CFA_ACTION_SHIFT);
Michael Chanc0c050c2015-10-22 16:01:17 -0400363
Michael Chanfbb0fa82016-02-22 02:10:26 -0500364 end = pdata + length;
365 end = PTR_ALIGN(end, 8) - 1;
Michael Chan4419dbe2016-02-10 17:33:49 -0500366 *end = 0;
367
Michael Chanc0c050c2015-10-22 16:01:17 -0400368 skb_copy_from_linear_data(skb, pdata, len);
369 pdata += len;
370 for (j = 0; j < last_frag; j++) {
371 skb_frag_t *frag = &skb_shinfo(skb)->frags[j];
372 void *fptr;
373
374 fptr = skb_frag_address_safe(frag);
375 if (!fptr)
376 goto normal_tx;
377
378 memcpy(pdata, fptr, skb_frag_size(frag));
379 pdata += skb_frag_size(frag);
380 }
381
Michael Chan4419dbe2016-02-10 17:33:49 -0500382 txbd->tx_bd_len_flags_type = tx_push->tx_bd_len_flags_type;
383 txbd->tx_bd_haddr = txr->data_mapping;
Michael Chanc0c050c2015-10-22 16:01:17 -0400384 prod = NEXT_TX(prod);
385 txbd = &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)];
386 memcpy(txbd, tx_push1, sizeof(*txbd));
387 prod = NEXT_TX(prod);
Michael Chan4419dbe2016-02-10 17:33:49 -0500388 tx_push->doorbell =
Michael Chanc0c050c2015-10-22 16:01:17 -0400389 cpu_to_le32(DB_KEY_TX_PUSH | DB_LONG_TX_PUSH | prod);
390 txr->tx_prod = prod;
391
Michael Chanb9a84602016-06-06 02:37:14 -0400392 tx_buf->is_push = 1;
Michael Chanc0c050c2015-10-22 16:01:17 -0400393 netdev_tx_sent_queue(txq, skb->len);
Michael Chanb9a84602016-06-06 02:37:14 -0400394 wmb(); /* Sync is_push and byte queue before pushing data */
Michael Chanc0c050c2015-10-22 16:01:17 -0400395
Michael Chan4419dbe2016-02-10 17:33:49 -0500396 push_len = (length + sizeof(*tx_push) + 7) / 8;
397 if (push_len > 16) {
398 __iowrite64_copy(txr->tx_doorbell, tx_push_buf, 16);
Michael Chan9d137442016-09-05 01:57:35 -0400399 __iowrite32_copy(txr->tx_doorbell + 4, tx_push_buf + 1,
400 (push_len - 16) << 1);
Michael Chan4419dbe2016-02-10 17:33:49 -0500401 } else {
402 __iowrite64_copy(txr->tx_doorbell, tx_push_buf,
403 push_len);
404 }
Michael Chanc0c050c2015-10-22 16:01:17 -0400405
Michael Chanc0c050c2015-10-22 16:01:17 -0400406 goto tx_done;
407 }
408
409normal_tx:
410 if (length < BNXT_MIN_PKT_SIZE) {
411 pad = BNXT_MIN_PKT_SIZE - length;
412 if (skb_pad(skb, pad)) {
413 /* SKB already freed. */
414 tx_buf->skb = NULL;
415 return NETDEV_TX_OK;
416 }
417 length = BNXT_MIN_PKT_SIZE;
418 }
419
420 mapping = dma_map_single(&pdev->dev, skb->data, len, DMA_TO_DEVICE);
421
422 if (unlikely(dma_mapping_error(&pdev->dev, mapping))) {
423 dev_kfree_skb_any(skb);
424 tx_buf->skb = NULL;
425 return NETDEV_TX_OK;
426 }
427
428 dma_unmap_addr_set(tx_buf, mapping, mapping);
429 flags = (len << TX_BD_LEN_SHIFT) | TX_BD_TYPE_LONG_TX_BD |
430 ((last_frag + 2) << TX_BD_FLAGS_BD_CNT_SHIFT);
431
432 txbd->tx_bd_haddr = cpu_to_le64(mapping);
433
434 prod = NEXT_TX(prod);
435 txbd1 = (struct tx_bd_ext *)
436 &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)];
437
438 txbd1->tx_bd_hsize_lflags = 0;
439 if (skb_is_gso(skb)) {
440 u32 hdr_len;
441
442 if (skb->encapsulation)
443 hdr_len = skb_inner_network_offset(skb) +
444 skb_inner_network_header_len(skb) +
445 inner_tcp_hdrlen(skb);
446 else
447 hdr_len = skb_transport_offset(skb) +
448 tcp_hdrlen(skb);
449
450 txbd1->tx_bd_hsize_lflags = cpu_to_le32(TX_BD_FLAGS_LSO |
451 TX_BD_FLAGS_T_IPID |
452 (hdr_len << (TX_BD_HSIZE_SHIFT - 1)));
453 length = skb_shinfo(skb)->gso_size;
454 txbd1->tx_bd_mss = cpu_to_le32(length);
455 length += hdr_len;
456 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
457 txbd1->tx_bd_hsize_lflags =
458 cpu_to_le32(TX_BD_FLAGS_TCP_UDP_CHKSUM);
459 txbd1->tx_bd_mss = 0;
460 }
461
462 length >>= 9;
463 flags |= bnxt_lhint_arr[length];
464 txbd->tx_bd_len_flags_type = cpu_to_le32(flags);
465
466 txbd1->tx_bd_cfa_meta = cpu_to_le32(vlan_tag_flags);
Sathya Perlaee5c7fb2017-07-24 12:34:28 -0400467 txbd1->tx_bd_cfa_action =
468 cpu_to_le32(cfa_action << TX_BD_CFA_ACTION_SHIFT);
Michael Chanc0c050c2015-10-22 16:01:17 -0400469 for (i = 0; i < last_frag; i++) {
470 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
471
472 prod = NEXT_TX(prod);
473 txbd = &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)];
474
475 len = skb_frag_size(frag);
476 mapping = skb_frag_dma_map(&pdev->dev, frag, 0, len,
477 DMA_TO_DEVICE);
478
479 if (unlikely(dma_mapping_error(&pdev->dev, mapping)))
480 goto tx_dma_error;
481
482 tx_buf = &txr->tx_buf_ring[prod];
483 dma_unmap_addr_set(tx_buf, mapping, mapping);
484
485 txbd->tx_bd_haddr = cpu_to_le64(mapping);
486
487 flags = len << TX_BD_LEN_SHIFT;
488 txbd->tx_bd_len_flags_type = cpu_to_le32(flags);
489 }
490
491 flags &= ~TX_BD_LEN;
492 txbd->tx_bd_len_flags_type =
493 cpu_to_le32(((len + pad) << TX_BD_LEN_SHIFT) | flags |
494 TX_BD_FLAGS_PACKET_END);
495
496 netdev_tx_sent_queue(txq, skb->len);
497
498 /* Sync BD data before updating doorbell */
499 wmb();
500
501 prod = NEXT_TX(prod);
502 txr->tx_prod = prod;
503
Michael Chanffe40642017-05-30 20:03:00 -0400504 if (!skb->xmit_more || netif_xmit_stopped(txq))
Michael Chan4d172f22017-05-29 19:06:09 -0400505 bnxt_db_write(bp, txr->tx_doorbell, DB_KEY_TX | prod);
Michael Chanc0c050c2015-10-22 16:01:17 -0400506
507tx_done:
508
509 mmiowb();
510
511 if (unlikely(bnxt_tx_avail(bp, txr) <= MAX_SKB_FRAGS + 1)) {
Michael Chan4d172f22017-05-29 19:06:09 -0400512 if (skb->xmit_more && !tx_buf->is_push)
513 bnxt_db_write(bp, txr->tx_doorbell, DB_KEY_TX | prod);
514
Michael Chanc0c050c2015-10-22 16:01:17 -0400515 netif_tx_stop_queue(txq);
516
517 /* netif_tx_stop_queue() must be done before checking
518 * tx index in bnxt_tx_avail() below, because in
519 * bnxt_tx_int(), we update tx index before checking for
520 * netif_tx_queue_stopped().
521 */
522 smp_mb();
523 if (bnxt_tx_avail(bp, txr) > bp->tx_wake_thresh)
524 netif_tx_wake_queue(txq);
525 }
526 return NETDEV_TX_OK;
527
528tx_dma_error:
529 last_frag = i;
530
531 /* start back at beginning and unmap skb */
532 prod = txr->tx_prod;
533 tx_buf = &txr->tx_buf_ring[prod];
534 tx_buf->skb = NULL;
535 dma_unmap_single(&pdev->dev, dma_unmap_addr(tx_buf, mapping),
536 skb_headlen(skb), PCI_DMA_TODEVICE);
537 prod = NEXT_TX(prod);
538
539 /* unmap remaining mapped pages */
540 for (i = 0; i < last_frag; i++) {
541 prod = NEXT_TX(prod);
542 tx_buf = &txr->tx_buf_ring[prod];
543 dma_unmap_page(&pdev->dev, dma_unmap_addr(tx_buf, mapping),
544 skb_frag_size(&skb_shinfo(skb)->frags[i]),
545 PCI_DMA_TODEVICE);
546 }
547
548 dev_kfree_skb_any(skb);
549 return NETDEV_TX_OK;
550}
551
552static void bnxt_tx_int(struct bnxt *bp, struct bnxt_napi *bnapi, int nr_pkts)
553{
Michael Chanb6ab4b02016-01-02 23:44:59 -0500554 struct bnxt_tx_ring_info *txr = bnapi->tx_ring;
Michael Chana960dec2017-02-06 16:55:39 -0500555 struct netdev_queue *txq = netdev_get_tx_queue(bp->dev, txr->txq_index);
Michael Chanc0c050c2015-10-22 16:01:17 -0400556 u16 cons = txr->tx_cons;
557 struct pci_dev *pdev = bp->pdev;
558 int i;
559 unsigned int tx_bytes = 0;
560
561 for (i = 0; i < nr_pkts; i++) {
562 struct bnxt_sw_tx_bd *tx_buf;
563 struct sk_buff *skb;
564 int j, last;
565
566 tx_buf = &txr->tx_buf_ring[cons];
567 cons = NEXT_TX(cons);
568 skb = tx_buf->skb;
569 tx_buf->skb = NULL;
570
571 if (tx_buf->is_push) {
572 tx_buf->is_push = 0;
573 goto next_tx_int;
574 }
575
576 dma_unmap_single(&pdev->dev, dma_unmap_addr(tx_buf, mapping),
577 skb_headlen(skb), PCI_DMA_TODEVICE);
578 last = tx_buf->nr_frags;
579
580 for (j = 0; j < last; j++) {
581 cons = NEXT_TX(cons);
582 tx_buf = &txr->tx_buf_ring[cons];
583 dma_unmap_page(
584 &pdev->dev,
585 dma_unmap_addr(tx_buf, mapping),
586 skb_frag_size(&skb_shinfo(skb)->frags[j]),
587 PCI_DMA_TODEVICE);
588 }
589
590next_tx_int:
591 cons = NEXT_TX(cons);
592
593 tx_bytes += skb->len;
594 dev_kfree_skb_any(skb);
595 }
596
597 netdev_tx_completed_queue(txq, nr_pkts, tx_bytes);
598 txr->tx_cons = cons;
599
600 /* Need to make the tx_cons update visible to bnxt_start_xmit()
601 * before checking for netif_tx_queue_stopped(). Without the
602 * memory barrier, there is a small possibility that bnxt_start_xmit()
603 * will miss it and cause the queue to be stopped forever.
604 */
605 smp_mb();
606
607 if (unlikely(netif_tx_queue_stopped(txq)) &&
608 (bnxt_tx_avail(bp, txr) > bp->tx_wake_thresh)) {
609 __netif_tx_lock(txq, smp_processor_id());
610 if (netif_tx_queue_stopped(txq) &&
611 bnxt_tx_avail(bp, txr) > bp->tx_wake_thresh &&
612 txr->dev_state != BNXT_DEV_STATE_CLOSING)
613 netif_tx_wake_queue(txq);
614 __netif_tx_unlock(txq);
615 }
616}
617
Michael Chanc61fb992017-02-06 16:55:36 -0500618static struct page *__bnxt_alloc_rx_page(struct bnxt *bp, dma_addr_t *mapping,
619 gfp_t gfp)
620{
621 struct device *dev = &bp->pdev->dev;
622 struct page *page;
623
624 page = alloc_page(gfp);
625 if (!page)
626 return NULL;
627
Shannon Nelsonc519fe92017-05-09 18:30:12 -0700628 *mapping = dma_map_page_attrs(dev, page, 0, PAGE_SIZE, bp->rx_dir,
629 DMA_ATTR_WEAK_ORDERING);
Michael Chanc61fb992017-02-06 16:55:36 -0500630 if (dma_mapping_error(dev, *mapping)) {
631 __free_page(page);
632 return NULL;
633 }
634 *mapping += bp->rx_dma_offset;
635 return page;
636}
637
Michael Chanc0c050c2015-10-22 16:01:17 -0400638static inline u8 *__bnxt_alloc_rx_data(struct bnxt *bp, dma_addr_t *mapping,
639 gfp_t gfp)
640{
641 u8 *data;
642 struct pci_dev *pdev = bp->pdev;
643
644 data = kmalloc(bp->rx_buf_size, gfp);
645 if (!data)
646 return NULL;
647
Shannon Nelsonc519fe92017-05-09 18:30:12 -0700648 *mapping = dma_map_single_attrs(&pdev->dev, data + bp->rx_dma_offset,
649 bp->rx_buf_use_size, bp->rx_dir,
650 DMA_ATTR_WEAK_ORDERING);
Michael Chanc0c050c2015-10-22 16:01:17 -0400651
652 if (dma_mapping_error(&pdev->dev, *mapping)) {
653 kfree(data);
654 data = NULL;
655 }
656 return data;
657}
658
Michael Chan38413402017-02-06 16:55:43 -0500659int bnxt_alloc_rx_data(struct bnxt *bp, struct bnxt_rx_ring_info *rxr,
660 u16 prod, gfp_t gfp)
Michael Chanc0c050c2015-10-22 16:01:17 -0400661{
662 struct rx_bd *rxbd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)];
663 struct bnxt_sw_rx_bd *rx_buf = &rxr->rx_buf_ring[prod];
Michael Chanc0c050c2015-10-22 16:01:17 -0400664 dma_addr_t mapping;
665
Michael Chanc61fb992017-02-06 16:55:36 -0500666 if (BNXT_RX_PAGE_MODE(bp)) {
667 struct page *page = __bnxt_alloc_rx_page(bp, &mapping, gfp);
Michael Chanc0c050c2015-10-22 16:01:17 -0400668
Michael Chanc61fb992017-02-06 16:55:36 -0500669 if (!page)
670 return -ENOMEM;
671
672 rx_buf->data = page;
673 rx_buf->data_ptr = page_address(page) + bp->rx_offset;
674 } else {
675 u8 *data = __bnxt_alloc_rx_data(bp, &mapping, gfp);
676
677 if (!data)
678 return -ENOMEM;
679
680 rx_buf->data = data;
681 rx_buf->data_ptr = data + bp->rx_offset;
682 }
Michael Chan11cd1192017-02-06 16:55:33 -0500683 rx_buf->mapping = mapping;
Michael Chanc0c050c2015-10-22 16:01:17 -0400684
685 rxbd->rx_bd_haddr = cpu_to_le64(mapping);
Michael Chanc0c050c2015-10-22 16:01:17 -0400686 return 0;
687}
688
Michael Chanc6d30e82017-02-06 16:55:42 -0500689void bnxt_reuse_rx_data(struct bnxt_rx_ring_info *rxr, u16 cons, void *data)
Michael Chanc0c050c2015-10-22 16:01:17 -0400690{
691 u16 prod = rxr->rx_prod;
692 struct bnxt_sw_rx_bd *cons_rx_buf, *prod_rx_buf;
693 struct rx_bd *cons_bd, *prod_bd;
694
695 prod_rx_buf = &rxr->rx_buf_ring[prod];
696 cons_rx_buf = &rxr->rx_buf_ring[cons];
697
698 prod_rx_buf->data = data;
Michael Chan6bb19472017-02-06 16:55:32 -0500699 prod_rx_buf->data_ptr = cons_rx_buf->data_ptr;
Michael Chanc0c050c2015-10-22 16:01:17 -0400700
Michael Chan11cd1192017-02-06 16:55:33 -0500701 prod_rx_buf->mapping = cons_rx_buf->mapping;
Michael Chanc0c050c2015-10-22 16:01:17 -0400702
703 prod_bd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)];
704 cons_bd = &rxr->rx_desc_ring[RX_RING(cons)][RX_IDX(cons)];
705
706 prod_bd->rx_bd_haddr = cons_bd->rx_bd_haddr;
707}
708
709static inline u16 bnxt_find_next_agg_idx(struct bnxt_rx_ring_info *rxr, u16 idx)
710{
711 u16 next, max = rxr->rx_agg_bmap_size;
712
713 next = find_next_zero_bit(rxr->rx_agg_bmap, max, idx);
714 if (next >= max)
715 next = find_first_zero_bit(rxr->rx_agg_bmap, max);
716 return next;
717}
718
719static inline int bnxt_alloc_rx_page(struct bnxt *bp,
720 struct bnxt_rx_ring_info *rxr,
721 u16 prod, gfp_t gfp)
722{
723 struct rx_bd *rxbd =
724 &rxr->rx_agg_desc_ring[RX_RING(prod)][RX_IDX(prod)];
725 struct bnxt_sw_rx_agg_bd *rx_agg_buf;
726 struct pci_dev *pdev = bp->pdev;
727 struct page *page;
728 dma_addr_t mapping;
729 u16 sw_prod = rxr->rx_sw_agg_prod;
Michael Chan89d0a062016-04-25 02:30:51 -0400730 unsigned int offset = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -0400731
Michael Chan89d0a062016-04-25 02:30:51 -0400732 if (PAGE_SIZE > BNXT_RX_PAGE_SIZE) {
733 page = rxr->rx_page;
734 if (!page) {
735 page = alloc_page(gfp);
736 if (!page)
737 return -ENOMEM;
738 rxr->rx_page = page;
739 rxr->rx_page_offset = 0;
740 }
741 offset = rxr->rx_page_offset;
742 rxr->rx_page_offset += BNXT_RX_PAGE_SIZE;
743 if (rxr->rx_page_offset == PAGE_SIZE)
744 rxr->rx_page = NULL;
745 else
746 get_page(page);
747 } else {
748 page = alloc_page(gfp);
749 if (!page)
750 return -ENOMEM;
751 }
Michael Chanc0c050c2015-10-22 16:01:17 -0400752
Shannon Nelsonc519fe92017-05-09 18:30:12 -0700753 mapping = dma_map_page_attrs(&pdev->dev, page, offset,
754 BNXT_RX_PAGE_SIZE, PCI_DMA_FROMDEVICE,
755 DMA_ATTR_WEAK_ORDERING);
Michael Chanc0c050c2015-10-22 16:01:17 -0400756 if (dma_mapping_error(&pdev->dev, mapping)) {
757 __free_page(page);
758 return -EIO;
759 }
760
761 if (unlikely(test_bit(sw_prod, rxr->rx_agg_bmap)))
762 sw_prod = bnxt_find_next_agg_idx(rxr, sw_prod);
763
764 __set_bit(sw_prod, rxr->rx_agg_bmap);
765 rx_agg_buf = &rxr->rx_agg_ring[sw_prod];
766 rxr->rx_sw_agg_prod = NEXT_RX_AGG(sw_prod);
767
768 rx_agg_buf->page = page;
Michael Chan89d0a062016-04-25 02:30:51 -0400769 rx_agg_buf->offset = offset;
Michael Chanc0c050c2015-10-22 16:01:17 -0400770 rx_agg_buf->mapping = mapping;
771 rxbd->rx_bd_haddr = cpu_to_le64(mapping);
772 rxbd->rx_bd_opaque = sw_prod;
773 return 0;
774}
775
776static void bnxt_reuse_rx_agg_bufs(struct bnxt_napi *bnapi, u16 cp_cons,
777 u32 agg_bufs)
778{
779 struct bnxt *bp = bnapi->bp;
780 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
Michael Chanb6ab4b02016-01-02 23:44:59 -0500781 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
Michael Chanc0c050c2015-10-22 16:01:17 -0400782 u16 prod = rxr->rx_agg_prod;
783 u16 sw_prod = rxr->rx_sw_agg_prod;
784 u32 i;
785
786 for (i = 0; i < agg_bufs; i++) {
787 u16 cons;
788 struct rx_agg_cmp *agg;
789 struct bnxt_sw_rx_agg_bd *cons_rx_buf, *prod_rx_buf;
790 struct rx_bd *prod_bd;
791 struct page *page;
792
793 agg = (struct rx_agg_cmp *)
794 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
795 cons = agg->rx_agg_cmp_opaque;
796 __clear_bit(cons, rxr->rx_agg_bmap);
797
798 if (unlikely(test_bit(sw_prod, rxr->rx_agg_bmap)))
799 sw_prod = bnxt_find_next_agg_idx(rxr, sw_prod);
800
801 __set_bit(sw_prod, rxr->rx_agg_bmap);
802 prod_rx_buf = &rxr->rx_agg_ring[sw_prod];
803 cons_rx_buf = &rxr->rx_agg_ring[cons];
804
805 /* It is possible for sw_prod to be equal to cons, so
806 * set cons_rx_buf->page to NULL first.
807 */
808 page = cons_rx_buf->page;
809 cons_rx_buf->page = NULL;
810 prod_rx_buf->page = page;
Michael Chan89d0a062016-04-25 02:30:51 -0400811 prod_rx_buf->offset = cons_rx_buf->offset;
Michael Chanc0c050c2015-10-22 16:01:17 -0400812
813 prod_rx_buf->mapping = cons_rx_buf->mapping;
814
815 prod_bd = &rxr->rx_agg_desc_ring[RX_RING(prod)][RX_IDX(prod)];
816
817 prod_bd->rx_bd_haddr = cpu_to_le64(cons_rx_buf->mapping);
818 prod_bd->rx_bd_opaque = sw_prod;
819
820 prod = NEXT_RX_AGG(prod);
821 sw_prod = NEXT_RX_AGG(sw_prod);
822 cp_cons = NEXT_CMP(cp_cons);
823 }
824 rxr->rx_agg_prod = prod;
825 rxr->rx_sw_agg_prod = sw_prod;
826}
827
Michael Chanc61fb992017-02-06 16:55:36 -0500828static struct sk_buff *bnxt_rx_page_skb(struct bnxt *bp,
829 struct bnxt_rx_ring_info *rxr,
830 u16 cons, void *data, u8 *data_ptr,
831 dma_addr_t dma_addr,
832 unsigned int offset_and_len)
833{
834 unsigned int payload = offset_and_len >> 16;
835 unsigned int len = offset_and_len & 0xffff;
836 struct skb_frag_struct *frag;
837 struct page *page = data;
838 u16 prod = rxr->rx_prod;
839 struct sk_buff *skb;
840 int off, err;
841
842 err = bnxt_alloc_rx_data(bp, rxr, prod, GFP_ATOMIC);
843 if (unlikely(err)) {
844 bnxt_reuse_rx_data(rxr, cons, data);
845 return NULL;
846 }
847 dma_addr -= bp->rx_dma_offset;
Shannon Nelsonc519fe92017-05-09 18:30:12 -0700848 dma_unmap_page_attrs(&bp->pdev->dev, dma_addr, PAGE_SIZE, bp->rx_dir,
849 DMA_ATTR_WEAK_ORDERING);
Michael Chanc61fb992017-02-06 16:55:36 -0500850
851 if (unlikely(!payload))
852 payload = eth_get_headlen(data_ptr, len);
853
854 skb = napi_alloc_skb(&rxr->bnapi->napi, payload);
855 if (!skb) {
856 __free_page(page);
857 return NULL;
858 }
859
860 off = (void *)data_ptr - page_address(page);
861 skb_add_rx_frag(skb, 0, page, off, len, PAGE_SIZE);
862 memcpy(skb->data - NET_IP_ALIGN, data_ptr - NET_IP_ALIGN,
863 payload + NET_IP_ALIGN);
864
865 frag = &skb_shinfo(skb)->frags[0];
866 skb_frag_size_sub(frag, payload);
867 frag->page_offset += payload;
868 skb->data_len -= payload;
869 skb->tail += payload;
870
871 return skb;
872}
873
Michael Chanc0c050c2015-10-22 16:01:17 -0400874static struct sk_buff *bnxt_rx_skb(struct bnxt *bp,
875 struct bnxt_rx_ring_info *rxr, u16 cons,
Michael Chan6bb19472017-02-06 16:55:32 -0500876 void *data, u8 *data_ptr,
877 dma_addr_t dma_addr,
878 unsigned int offset_and_len)
Michael Chanc0c050c2015-10-22 16:01:17 -0400879{
Michael Chan6bb19472017-02-06 16:55:32 -0500880 u16 prod = rxr->rx_prod;
Michael Chanc0c050c2015-10-22 16:01:17 -0400881 struct sk_buff *skb;
Michael Chan6bb19472017-02-06 16:55:32 -0500882 int err;
Michael Chanc0c050c2015-10-22 16:01:17 -0400883
884 err = bnxt_alloc_rx_data(bp, rxr, prod, GFP_ATOMIC);
885 if (unlikely(err)) {
886 bnxt_reuse_rx_data(rxr, cons, data);
887 return NULL;
888 }
889
890 skb = build_skb(data, 0);
Shannon Nelsonc519fe92017-05-09 18:30:12 -0700891 dma_unmap_single_attrs(&bp->pdev->dev, dma_addr, bp->rx_buf_use_size,
892 bp->rx_dir, DMA_ATTR_WEAK_ORDERING);
Michael Chanc0c050c2015-10-22 16:01:17 -0400893 if (!skb) {
894 kfree(data);
895 return NULL;
896 }
897
Michael Chanb3dba772017-02-06 16:55:35 -0500898 skb_reserve(skb, bp->rx_offset);
Michael Chan6bb19472017-02-06 16:55:32 -0500899 skb_put(skb, offset_and_len & 0xffff);
Michael Chanc0c050c2015-10-22 16:01:17 -0400900 return skb;
901}
902
903static struct sk_buff *bnxt_rx_pages(struct bnxt *bp, struct bnxt_napi *bnapi,
904 struct sk_buff *skb, u16 cp_cons,
905 u32 agg_bufs)
906{
907 struct pci_dev *pdev = bp->pdev;
908 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
Michael Chanb6ab4b02016-01-02 23:44:59 -0500909 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
Michael Chanc0c050c2015-10-22 16:01:17 -0400910 u16 prod = rxr->rx_agg_prod;
911 u32 i;
912
913 for (i = 0; i < agg_bufs; i++) {
914 u16 cons, frag_len;
915 struct rx_agg_cmp *agg;
916 struct bnxt_sw_rx_agg_bd *cons_rx_buf;
917 struct page *page;
918 dma_addr_t mapping;
919
920 agg = (struct rx_agg_cmp *)
921 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
922 cons = agg->rx_agg_cmp_opaque;
923 frag_len = (le32_to_cpu(agg->rx_agg_cmp_len_flags_type) &
924 RX_AGG_CMP_LEN) >> RX_AGG_CMP_LEN_SHIFT;
925
926 cons_rx_buf = &rxr->rx_agg_ring[cons];
Michael Chan89d0a062016-04-25 02:30:51 -0400927 skb_fill_page_desc(skb, i, cons_rx_buf->page,
928 cons_rx_buf->offset, frag_len);
Michael Chanc0c050c2015-10-22 16:01:17 -0400929 __clear_bit(cons, rxr->rx_agg_bmap);
930
931 /* It is possible for bnxt_alloc_rx_page() to allocate
932 * a sw_prod index that equals the cons index, so we
933 * need to clear the cons entry now.
934 */
Michael Chan11cd1192017-02-06 16:55:33 -0500935 mapping = cons_rx_buf->mapping;
Michael Chanc0c050c2015-10-22 16:01:17 -0400936 page = cons_rx_buf->page;
937 cons_rx_buf->page = NULL;
938
939 if (bnxt_alloc_rx_page(bp, rxr, prod, GFP_ATOMIC) != 0) {
940 struct skb_shared_info *shinfo;
941 unsigned int nr_frags;
942
943 shinfo = skb_shinfo(skb);
944 nr_frags = --shinfo->nr_frags;
945 __skb_frag_set_page(&shinfo->frags[nr_frags], NULL);
946
947 dev_kfree_skb(skb);
948
949 cons_rx_buf->page = page;
950
951 /* Update prod since possibly some pages have been
952 * allocated already.
953 */
954 rxr->rx_agg_prod = prod;
955 bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs - i);
956 return NULL;
957 }
958
Shannon Nelsonc519fe92017-05-09 18:30:12 -0700959 dma_unmap_page_attrs(&pdev->dev, mapping, BNXT_RX_PAGE_SIZE,
960 PCI_DMA_FROMDEVICE,
961 DMA_ATTR_WEAK_ORDERING);
Michael Chanc0c050c2015-10-22 16:01:17 -0400962
963 skb->data_len += frag_len;
964 skb->len += frag_len;
965 skb->truesize += PAGE_SIZE;
966
967 prod = NEXT_RX_AGG(prod);
968 cp_cons = NEXT_CMP(cp_cons);
969 }
970 rxr->rx_agg_prod = prod;
971 return skb;
972}
973
974static int bnxt_agg_bufs_valid(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
975 u8 agg_bufs, u32 *raw_cons)
976{
977 u16 last;
978 struct rx_agg_cmp *agg;
979
980 *raw_cons = ADV_RAW_CMP(*raw_cons, agg_bufs);
981 last = RING_CMP(*raw_cons);
982 agg = (struct rx_agg_cmp *)
983 &cpr->cp_desc_ring[CP_RING(last)][CP_IDX(last)];
984 return RX_AGG_CMP_VALID(agg, *raw_cons);
985}
986
987static inline struct sk_buff *bnxt_copy_skb(struct bnxt_napi *bnapi, u8 *data,
988 unsigned int len,
989 dma_addr_t mapping)
990{
991 struct bnxt *bp = bnapi->bp;
992 struct pci_dev *pdev = bp->pdev;
993 struct sk_buff *skb;
994
995 skb = napi_alloc_skb(&bnapi->napi, len);
996 if (!skb)
997 return NULL;
998
Michael Chan745fc052017-02-06 16:55:34 -0500999 dma_sync_single_for_cpu(&pdev->dev, mapping, bp->rx_copy_thresh,
1000 bp->rx_dir);
Michael Chanc0c050c2015-10-22 16:01:17 -04001001
Michael Chan6bb19472017-02-06 16:55:32 -05001002 memcpy(skb->data - NET_IP_ALIGN, data - NET_IP_ALIGN,
1003 len + NET_IP_ALIGN);
Michael Chanc0c050c2015-10-22 16:01:17 -04001004
Michael Chan745fc052017-02-06 16:55:34 -05001005 dma_sync_single_for_device(&pdev->dev, mapping, bp->rx_copy_thresh,
1006 bp->rx_dir);
Michael Chanc0c050c2015-10-22 16:01:17 -04001007
1008 skb_put(skb, len);
1009 return skb;
1010}
1011
Michael Chanfa7e2812016-05-10 19:18:00 -04001012static int bnxt_discard_rx(struct bnxt *bp, struct bnxt_napi *bnapi,
1013 u32 *raw_cons, void *cmp)
1014{
1015 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1016 struct rx_cmp *rxcmp = cmp;
1017 u32 tmp_raw_cons = *raw_cons;
1018 u8 cmp_type, agg_bufs = 0;
1019
1020 cmp_type = RX_CMP_TYPE(rxcmp);
1021
1022 if (cmp_type == CMP_TYPE_RX_L2_CMP) {
1023 agg_bufs = (le32_to_cpu(rxcmp->rx_cmp_misc_v1) &
1024 RX_CMP_AGG_BUFS) >>
1025 RX_CMP_AGG_BUFS_SHIFT;
1026 } else if (cmp_type == CMP_TYPE_RX_L2_TPA_END_CMP) {
1027 struct rx_tpa_end_cmp *tpa_end = cmp;
1028
1029 agg_bufs = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) &
1030 RX_TPA_END_CMP_AGG_BUFS) >>
1031 RX_TPA_END_CMP_AGG_BUFS_SHIFT;
1032 }
1033
1034 if (agg_bufs) {
1035 if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, &tmp_raw_cons))
1036 return -EBUSY;
1037 }
1038 *raw_cons = tmp_raw_cons;
1039 return 0;
1040}
1041
Michael Chanc213eae2017-10-13 21:09:29 -04001042static void bnxt_queue_sp_work(struct bnxt *bp)
1043{
1044 if (BNXT_PF(bp))
1045 queue_work(bnxt_pf_wq, &bp->sp_task);
1046 else
1047 schedule_work(&bp->sp_task);
1048}
1049
1050static void bnxt_cancel_sp_work(struct bnxt *bp)
1051{
1052 if (BNXT_PF(bp))
1053 flush_workqueue(bnxt_pf_wq);
1054 else
1055 cancel_work_sync(&bp->sp_task);
1056}
1057
Michael Chanfa7e2812016-05-10 19:18:00 -04001058static void bnxt_sched_reset(struct bnxt *bp, struct bnxt_rx_ring_info *rxr)
1059{
1060 if (!rxr->bnapi->in_reset) {
1061 rxr->bnapi->in_reset = true;
1062 set_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event);
Michael Chanc213eae2017-10-13 21:09:29 -04001063 bnxt_queue_sp_work(bp);
Michael Chanfa7e2812016-05-10 19:18:00 -04001064 }
1065 rxr->rx_next_cons = 0xffff;
1066}
1067
Michael Chanc0c050c2015-10-22 16:01:17 -04001068static void bnxt_tpa_start(struct bnxt *bp, struct bnxt_rx_ring_info *rxr,
1069 struct rx_tpa_start_cmp *tpa_start,
1070 struct rx_tpa_start_cmp_ext *tpa_start1)
1071{
1072 u8 agg_id = TPA_START_AGG_ID(tpa_start);
1073 u16 cons, prod;
1074 struct bnxt_tpa_info *tpa_info;
1075 struct bnxt_sw_rx_bd *cons_rx_buf, *prod_rx_buf;
1076 struct rx_bd *prod_bd;
1077 dma_addr_t mapping;
1078
1079 cons = tpa_start->rx_tpa_start_cmp_opaque;
1080 prod = rxr->rx_prod;
1081 cons_rx_buf = &rxr->rx_buf_ring[cons];
1082 prod_rx_buf = &rxr->rx_buf_ring[prod];
1083 tpa_info = &rxr->rx_tpa[agg_id];
1084
Michael Chanfa7e2812016-05-10 19:18:00 -04001085 if (unlikely(cons != rxr->rx_next_cons)) {
1086 bnxt_sched_reset(bp, rxr);
1087 return;
1088 }
Sathya Perlaee5c7fb2017-07-24 12:34:28 -04001089 /* Store cfa_code in tpa_info to use in tpa_end
1090 * completion processing.
1091 */
1092 tpa_info->cfa_code = TPA_START_CFA_CODE(tpa_start1);
Michael Chanc0c050c2015-10-22 16:01:17 -04001093 prod_rx_buf->data = tpa_info->data;
Michael Chan6bb19472017-02-06 16:55:32 -05001094 prod_rx_buf->data_ptr = tpa_info->data_ptr;
Michael Chanc0c050c2015-10-22 16:01:17 -04001095
1096 mapping = tpa_info->mapping;
Michael Chan11cd1192017-02-06 16:55:33 -05001097 prod_rx_buf->mapping = mapping;
Michael Chanc0c050c2015-10-22 16:01:17 -04001098
1099 prod_bd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)];
1100
1101 prod_bd->rx_bd_haddr = cpu_to_le64(mapping);
1102
1103 tpa_info->data = cons_rx_buf->data;
Michael Chan6bb19472017-02-06 16:55:32 -05001104 tpa_info->data_ptr = cons_rx_buf->data_ptr;
Michael Chanc0c050c2015-10-22 16:01:17 -04001105 cons_rx_buf->data = NULL;
Michael Chan11cd1192017-02-06 16:55:33 -05001106 tpa_info->mapping = cons_rx_buf->mapping;
Michael Chanc0c050c2015-10-22 16:01:17 -04001107
1108 tpa_info->len =
1109 le32_to_cpu(tpa_start->rx_tpa_start_cmp_len_flags_type) >>
1110 RX_TPA_START_CMP_LEN_SHIFT;
1111 if (likely(TPA_START_HASH_VALID(tpa_start))) {
1112 u32 hash_type = TPA_START_HASH_TYPE(tpa_start);
1113
1114 tpa_info->hash_type = PKT_HASH_TYPE_L4;
1115 tpa_info->gso_type = SKB_GSO_TCPV4;
1116 /* RSS profiles 1 and 3 with extract code 0 for inner 4-tuple */
1117 if (hash_type == 3)
1118 tpa_info->gso_type = SKB_GSO_TCPV6;
1119 tpa_info->rss_hash =
1120 le32_to_cpu(tpa_start->rx_tpa_start_cmp_rss_hash);
1121 } else {
1122 tpa_info->hash_type = PKT_HASH_TYPE_NONE;
1123 tpa_info->gso_type = 0;
1124 if (netif_msg_rx_err(bp))
1125 netdev_warn(bp->dev, "TPA packet without valid hash\n");
1126 }
1127 tpa_info->flags2 = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_flags2);
1128 tpa_info->metadata = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_metadata);
Michael Chan94758f82016-06-13 02:25:35 -04001129 tpa_info->hdr_info = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_hdr_info);
Michael Chanc0c050c2015-10-22 16:01:17 -04001130
1131 rxr->rx_prod = NEXT_RX(prod);
1132 cons = NEXT_RX(cons);
Michael Chan376a5b82016-05-10 19:17:59 -04001133 rxr->rx_next_cons = NEXT_RX(cons);
Michael Chanc0c050c2015-10-22 16:01:17 -04001134 cons_rx_buf = &rxr->rx_buf_ring[cons];
1135
1136 bnxt_reuse_rx_data(rxr, cons, cons_rx_buf->data);
1137 rxr->rx_prod = NEXT_RX(rxr->rx_prod);
1138 cons_rx_buf->data = NULL;
1139}
1140
1141static void bnxt_abort_tpa(struct bnxt *bp, struct bnxt_napi *bnapi,
1142 u16 cp_cons, u32 agg_bufs)
1143{
1144 if (agg_bufs)
1145 bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs);
1146}
1147
Michael Chan94758f82016-06-13 02:25:35 -04001148static struct sk_buff *bnxt_gro_func_5731x(struct bnxt_tpa_info *tpa_info,
1149 int payload_off, int tcp_ts,
1150 struct sk_buff *skb)
1151{
1152#ifdef CONFIG_INET
1153 struct tcphdr *th;
1154 int len, nw_off;
1155 u16 outer_ip_off, inner_ip_off, inner_mac_off;
1156 u32 hdr_info = tpa_info->hdr_info;
1157 bool loopback = false;
1158
1159 inner_ip_off = BNXT_TPA_INNER_L3_OFF(hdr_info);
1160 inner_mac_off = BNXT_TPA_INNER_L2_OFF(hdr_info);
1161 outer_ip_off = BNXT_TPA_OUTER_L3_OFF(hdr_info);
1162
1163 /* If the packet is an internal loopback packet, the offsets will
1164 * have an extra 4 bytes.
1165 */
1166 if (inner_mac_off == 4) {
1167 loopback = true;
1168 } else if (inner_mac_off > 4) {
1169 __be16 proto = *((__be16 *)(skb->data + inner_ip_off -
1170 ETH_HLEN - 2));
1171
1172 /* We only support inner iPv4/ipv6. If we don't see the
1173 * correct protocol ID, it must be a loopback packet where
1174 * the offsets are off by 4.
1175 */
Dan Carpenter09a76362016-07-07 11:23:09 +03001176 if (proto != htons(ETH_P_IP) && proto != htons(ETH_P_IPV6))
Michael Chan94758f82016-06-13 02:25:35 -04001177 loopback = true;
1178 }
1179 if (loopback) {
1180 /* internal loopback packet, subtract all offsets by 4 */
1181 inner_ip_off -= 4;
1182 inner_mac_off -= 4;
1183 outer_ip_off -= 4;
1184 }
1185
1186 nw_off = inner_ip_off - ETH_HLEN;
1187 skb_set_network_header(skb, nw_off);
1188 if (tpa_info->flags2 & RX_TPA_START_CMP_FLAGS2_IP_TYPE) {
1189 struct ipv6hdr *iph = ipv6_hdr(skb);
1190
1191 skb_set_transport_header(skb, nw_off + sizeof(struct ipv6hdr));
1192 len = skb->len - skb_transport_offset(skb);
1193 th = tcp_hdr(skb);
1194 th->check = ~tcp_v6_check(len, &iph->saddr, &iph->daddr, 0);
1195 } else {
1196 struct iphdr *iph = ip_hdr(skb);
1197
1198 skb_set_transport_header(skb, nw_off + sizeof(struct iphdr));
1199 len = skb->len - skb_transport_offset(skb);
1200 th = tcp_hdr(skb);
1201 th->check = ~tcp_v4_check(len, iph->saddr, iph->daddr, 0);
1202 }
1203
1204 if (inner_mac_off) { /* tunnel */
1205 struct udphdr *uh = NULL;
1206 __be16 proto = *((__be16 *)(skb->data + outer_ip_off -
1207 ETH_HLEN - 2));
1208
1209 if (proto == htons(ETH_P_IP)) {
1210 struct iphdr *iph = (struct iphdr *)skb->data;
1211
1212 if (iph->protocol == IPPROTO_UDP)
1213 uh = (struct udphdr *)(iph + 1);
1214 } else {
1215 struct ipv6hdr *iph = (struct ipv6hdr *)skb->data;
1216
1217 if (iph->nexthdr == IPPROTO_UDP)
1218 uh = (struct udphdr *)(iph + 1);
1219 }
1220 if (uh) {
1221 if (uh->check)
1222 skb_shinfo(skb)->gso_type |=
1223 SKB_GSO_UDP_TUNNEL_CSUM;
1224 else
1225 skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL;
1226 }
1227 }
1228#endif
1229 return skb;
1230}
1231
Michael Chanc0c050c2015-10-22 16:01:17 -04001232#define BNXT_IPV4_HDR_SIZE (sizeof(struct iphdr) + sizeof(struct tcphdr))
1233#define BNXT_IPV6_HDR_SIZE (sizeof(struct ipv6hdr) + sizeof(struct tcphdr))
1234
Michael Chan309369c2016-06-13 02:25:34 -04001235static struct sk_buff *bnxt_gro_func_5730x(struct bnxt_tpa_info *tpa_info,
1236 int payload_off, int tcp_ts,
Michael Chanc0c050c2015-10-22 16:01:17 -04001237 struct sk_buff *skb)
1238{
Michael Chand1611c32015-10-25 22:27:57 -04001239#ifdef CONFIG_INET
Michael Chanc0c050c2015-10-22 16:01:17 -04001240 struct tcphdr *th;
Michael Chan719ca812017-01-17 22:07:19 -05001241 int len, nw_off, tcp_opt_len = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04001242
Michael Chan309369c2016-06-13 02:25:34 -04001243 if (tcp_ts)
Michael Chanc0c050c2015-10-22 16:01:17 -04001244 tcp_opt_len = 12;
1245
Michael Chanc0c050c2015-10-22 16:01:17 -04001246 if (tpa_info->gso_type == SKB_GSO_TCPV4) {
1247 struct iphdr *iph;
1248
1249 nw_off = payload_off - BNXT_IPV4_HDR_SIZE - tcp_opt_len -
1250 ETH_HLEN;
1251 skb_set_network_header(skb, nw_off);
1252 iph = ip_hdr(skb);
1253 skb_set_transport_header(skb, nw_off + sizeof(struct iphdr));
1254 len = skb->len - skb_transport_offset(skb);
1255 th = tcp_hdr(skb);
1256 th->check = ~tcp_v4_check(len, iph->saddr, iph->daddr, 0);
1257 } else if (tpa_info->gso_type == SKB_GSO_TCPV6) {
1258 struct ipv6hdr *iph;
1259
1260 nw_off = payload_off - BNXT_IPV6_HDR_SIZE - tcp_opt_len -
1261 ETH_HLEN;
1262 skb_set_network_header(skb, nw_off);
1263 iph = ipv6_hdr(skb);
1264 skb_set_transport_header(skb, nw_off + sizeof(struct ipv6hdr));
1265 len = skb->len - skb_transport_offset(skb);
1266 th = tcp_hdr(skb);
1267 th->check = ~tcp_v6_check(len, &iph->saddr, &iph->daddr, 0);
1268 } else {
1269 dev_kfree_skb_any(skb);
1270 return NULL;
1271 }
Michael Chanc0c050c2015-10-22 16:01:17 -04001272
1273 if (nw_off) { /* tunnel */
1274 struct udphdr *uh = NULL;
1275
1276 if (skb->protocol == htons(ETH_P_IP)) {
1277 struct iphdr *iph = (struct iphdr *)skb->data;
1278
1279 if (iph->protocol == IPPROTO_UDP)
1280 uh = (struct udphdr *)(iph + 1);
1281 } else {
1282 struct ipv6hdr *iph = (struct ipv6hdr *)skb->data;
1283
1284 if (iph->nexthdr == IPPROTO_UDP)
1285 uh = (struct udphdr *)(iph + 1);
1286 }
1287 if (uh) {
1288 if (uh->check)
1289 skb_shinfo(skb)->gso_type |=
1290 SKB_GSO_UDP_TUNNEL_CSUM;
1291 else
1292 skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL;
1293 }
1294 }
1295#endif
1296 return skb;
1297}
1298
Michael Chan309369c2016-06-13 02:25:34 -04001299static inline struct sk_buff *bnxt_gro_skb(struct bnxt *bp,
1300 struct bnxt_tpa_info *tpa_info,
1301 struct rx_tpa_end_cmp *tpa_end,
1302 struct rx_tpa_end_cmp_ext *tpa_end1,
1303 struct sk_buff *skb)
1304{
1305#ifdef CONFIG_INET
1306 int payload_off;
1307 u16 segs;
1308
1309 segs = TPA_END_TPA_SEGS(tpa_end);
1310 if (segs == 1)
1311 return skb;
1312
1313 NAPI_GRO_CB(skb)->count = segs;
1314 skb_shinfo(skb)->gso_size =
1315 le32_to_cpu(tpa_end1->rx_tpa_end_cmp_seg_len);
1316 skb_shinfo(skb)->gso_type = tpa_info->gso_type;
1317 payload_off = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) &
1318 RX_TPA_END_CMP_PAYLOAD_OFFSET) >>
1319 RX_TPA_END_CMP_PAYLOAD_OFFSET_SHIFT;
1320 skb = bp->gro_func(tpa_info, payload_off, TPA_END_GRO_TS(tpa_end), skb);
Michael Chan59109062016-12-29 12:13:35 -05001321 if (likely(skb))
1322 tcp_gro_complete(skb);
Michael Chan309369c2016-06-13 02:25:34 -04001323#endif
1324 return skb;
1325}
1326
Sathya Perlaee5c7fb2017-07-24 12:34:28 -04001327/* Given the cfa_code of a received packet determine which
1328 * netdev (vf-rep or PF) the packet is destined to.
1329 */
1330static struct net_device *bnxt_get_pkt_dev(struct bnxt *bp, u16 cfa_code)
1331{
1332 struct net_device *dev = bnxt_get_vf_rep(bp, cfa_code);
1333
1334 /* if vf-rep dev is NULL, the must belongs to the PF */
1335 return dev ? dev : bp->dev;
1336}
1337
Michael Chanc0c050c2015-10-22 16:01:17 -04001338static inline struct sk_buff *bnxt_tpa_end(struct bnxt *bp,
1339 struct bnxt_napi *bnapi,
1340 u32 *raw_cons,
1341 struct rx_tpa_end_cmp *tpa_end,
1342 struct rx_tpa_end_cmp_ext *tpa_end1,
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001343 u8 *event)
Michael Chanc0c050c2015-10-22 16:01:17 -04001344{
1345 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
Michael Chanb6ab4b02016-01-02 23:44:59 -05001346 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
Michael Chanc0c050c2015-10-22 16:01:17 -04001347 u8 agg_id = TPA_END_AGG_ID(tpa_end);
Michael Chan6bb19472017-02-06 16:55:32 -05001348 u8 *data_ptr, agg_bufs;
Michael Chanc0c050c2015-10-22 16:01:17 -04001349 u16 cp_cons = RING_CMP(*raw_cons);
1350 unsigned int len;
1351 struct bnxt_tpa_info *tpa_info;
1352 dma_addr_t mapping;
1353 struct sk_buff *skb;
Michael Chan6bb19472017-02-06 16:55:32 -05001354 void *data;
Michael Chanc0c050c2015-10-22 16:01:17 -04001355
Michael Chanfa7e2812016-05-10 19:18:00 -04001356 if (unlikely(bnapi->in_reset)) {
1357 int rc = bnxt_discard_rx(bp, bnapi, raw_cons, tpa_end);
1358
1359 if (rc < 0)
1360 return ERR_PTR(-EBUSY);
1361 return NULL;
1362 }
1363
Michael Chanc0c050c2015-10-22 16:01:17 -04001364 tpa_info = &rxr->rx_tpa[agg_id];
1365 data = tpa_info->data;
Michael Chan6bb19472017-02-06 16:55:32 -05001366 data_ptr = tpa_info->data_ptr;
1367 prefetch(data_ptr);
Michael Chanc0c050c2015-10-22 16:01:17 -04001368 len = tpa_info->len;
1369 mapping = tpa_info->mapping;
1370
1371 agg_bufs = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) &
1372 RX_TPA_END_CMP_AGG_BUFS) >> RX_TPA_END_CMP_AGG_BUFS_SHIFT;
1373
1374 if (agg_bufs) {
1375 if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, raw_cons))
1376 return ERR_PTR(-EBUSY);
1377
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001378 *event |= BNXT_AGG_EVENT;
Michael Chanc0c050c2015-10-22 16:01:17 -04001379 cp_cons = NEXT_CMP(cp_cons);
1380 }
1381
Michael Chan69c149e2017-06-23 14:01:00 -04001382 if (unlikely(agg_bufs > MAX_SKB_FRAGS || TPA_END_ERRORS(tpa_end1))) {
Michael Chanc0c050c2015-10-22 16:01:17 -04001383 bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs);
Michael Chan69c149e2017-06-23 14:01:00 -04001384 if (agg_bufs > MAX_SKB_FRAGS)
1385 netdev_warn(bp->dev, "TPA frags %d exceeded MAX_SKB_FRAGS %d\n",
1386 agg_bufs, (int)MAX_SKB_FRAGS);
Michael Chanc0c050c2015-10-22 16:01:17 -04001387 return NULL;
1388 }
1389
1390 if (len <= bp->rx_copy_thresh) {
Michael Chan6bb19472017-02-06 16:55:32 -05001391 skb = bnxt_copy_skb(bnapi, data_ptr, len, mapping);
Michael Chanc0c050c2015-10-22 16:01:17 -04001392 if (!skb) {
1393 bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs);
1394 return NULL;
1395 }
1396 } else {
1397 u8 *new_data;
1398 dma_addr_t new_mapping;
1399
1400 new_data = __bnxt_alloc_rx_data(bp, &new_mapping, GFP_ATOMIC);
1401 if (!new_data) {
1402 bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs);
1403 return NULL;
1404 }
1405
1406 tpa_info->data = new_data;
Michael Chanb3dba772017-02-06 16:55:35 -05001407 tpa_info->data_ptr = new_data + bp->rx_offset;
Michael Chanc0c050c2015-10-22 16:01:17 -04001408 tpa_info->mapping = new_mapping;
1409
1410 skb = build_skb(data, 0);
Shannon Nelsonc519fe92017-05-09 18:30:12 -07001411 dma_unmap_single_attrs(&bp->pdev->dev, mapping,
1412 bp->rx_buf_use_size, bp->rx_dir,
1413 DMA_ATTR_WEAK_ORDERING);
Michael Chanc0c050c2015-10-22 16:01:17 -04001414
1415 if (!skb) {
1416 kfree(data);
1417 bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs);
1418 return NULL;
1419 }
Michael Chanb3dba772017-02-06 16:55:35 -05001420 skb_reserve(skb, bp->rx_offset);
Michael Chanc0c050c2015-10-22 16:01:17 -04001421 skb_put(skb, len);
1422 }
1423
1424 if (agg_bufs) {
1425 skb = bnxt_rx_pages(bp, bnapi, skb, cp_cons, agg_bufs);
1426 if (!skb) {
1427 /* Page reuse already handled by bnxt_rx_pages(). */
1428 return NULL;
1429 }
1430 }
Sathya Perlaee5c7fb2017-07-24 12:34:28 -04001431
1432 skb->protocol =
1433 eth_type_trans(skb, bnxt_get_pkt_dev(bp, tpa_info->cfa_code));
Michael Chanc0c050c2015-10-22 16:01:17 -04001434
1435 if (tpa_info->hash_type != PKT_HASH_TYPE_NONE)
1436 skb_set_hash(skb, tpa_info->rss_hash, tpa_info->hash_type);
1437
Michael Chan8852ddb2016-06-06 02:37:16 -04001438 if ((tpa_info->flags2 & RX_CMP_FLAGS2_META_FORMAT_VLAN) &&
1439 (skb->dev->features & NETIF_F_HW_VLAN_CTAG_RX)) {
Michael Chanc0c050c2015-10-22 16:01:17 -04001440 u16 vlan_proto = tpa_info->metadata >>
1441 RX_CMP_FLAGS2_METADATA_TPID_SFT;
Michael Chaned7bc6022018-03-09 23:46:06 -05001442 u16 vtag = tpa_info->metadata & RX_CMP_FLAGS2_METADATA_TCI_MASK;
Michael Chanc0c050c2015-10-22 16:01:17 -04001443
Michael Chan8852ddb2016-06-06 02:37:16 -04001444 __vlan_hwaccel_put_tag(skb, htons(vlan_proto), vtag);
Michael Chanc0c050c2015-10-22 16:01:17 -04001445 }
1446
1447 skb_checksum_none_assert(skb);
1448 if (likely(tpa_info->flags2 & RX_TPA_START_CMP_FLAGS2_L4_CS_CALC)) {
1449 skb->ip_summed = CHECKSUM_UNNECESSARY;
1450 skb->csum_level =
1451 (tpa_info->flags2 & RX_CMP_FLAGS2_T_L4_CS_CALC) >> 3;
1452 }
1453
1454 if (TPA_END_GRO(tpa_end))
Michael Chan309369c2016-06-13 02:25:34 -04001455 skb = bnxt_gro_skb(bp, tpa_info, tpa_end, tpa_end1, skb);
Michael Chanc0c050c2015-10-22 16:01:17 -04001456
1457 return skb;
1458}
1459
Sathya Perlaee5c7fb2017-07-24 12:34:28 -04001460static void bnxt_deliver_skb(struct bnxt *bp, struct bnxt_napi *bnapi,
1461 struct sk_buff *skb)
1462{
1463 if (skb->dev != bp->dev) {
1464 /* this packet belongs to a vf-rep */
1465 bnxt_vf_rep_rx(bp, skb);
1466 return;
1467 }
1468 skb_record_rx_queue(skb, bnapi->index);
1469 napi_gro_receive(&bnapi->napi, skb);
1470}
1471
Michael Chanc0c050c2015-10-22 16:01:17 -04001472/* returns the following:
1473 * 1 - 1 packet successfully received
1474 * 0 - successful TPA_START, packet not completed yet
1475 * -EBUSY - completion ring does not have all the agg buffers yet
1476 * -ENOMEM - packet aborted due to out of memory
1477 * -EIO - packet aborted due to hw error indicated in BD
1478 */
1479static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_napi *bnapi, u32 *raw_cons,
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001480 u8 *event)
Michael Chanc0c050c2015-10-22 16:01:17 -04001481{
1482 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
Michael Chanb6ab4b02016-01-02 23:44:59 -05001483 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
Michael Chanc0c050c2015-10-22 16:01:17 -04001484 struct net_device *dev = bp->dev;
1485 struct rx_cmp *rxcmp;
1486 struct rx_cmp_ext *rxcmp1;
1487 u32 tmp_raw_cons = *raw_cons;
Sathya Perlaee5c7fb2017-07-24 12:34:28 -04001488 u16 cfa_code, cons, prod, cp_cons = RING_CMP(tmp_raw_cons);
Michael Chanc0c050c2015-10-22 16:01:17 -04001489 struct bnxt_sw_rx_bd *rx_buf;
1490 unsigned int len;
Michael Chan6bb19472017-02-06 16:55:32 -05001491 u8 *data_ptr, agg_bufs, cmp_type;
Michael Chanc0c050c2015-10-22 16:01:17 -04001492 dma_addr_t dma_addr;
1493 struct sk_buff *skb;
Michael Chan6bb19472017-02-06 16:55:32 -05001494 void *data;
Michael Chanc0c050c2015-10-22 16:01:17 -04001495 int rc = 0;
Michael Chanc61fb992017-02-06 16:55:36 -05001496 u32 misc;
Michael Chanc0c050c2015-10-22 16:01:17 -04001497
1498 rxcmp = (struct rx_cmp *)
1499 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
1500
1501 tmp_raw_cons = NEXT_RAW_CMP(tmp_raw_cons);
1502 cp_cons = RING_CMP(tmp_raw_cons);
1503 rxcmp1 = (struct rx_cmp_ext *)
1504 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
1505
1506 if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons))
1507 return -EBUSY;
1508
1509 cmp_type = RX_CMP_TYPE(rxcmp);
1510
1511 prod = rxr->rx_prod;
1512
1513 if (cmp_type == CMP_TYPE_RX_L2_TPA_START_CMP) {
1514 bnxt_tpa_start(bp, rxr, (struct rx_tpa_start_cmp *)rxcmp,
1515 (struct rx_tpa_start_cmp_ext *)rxcmp1);
1516
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001517 *event |= BNXT_RX_EVENT;
Colin Ian Kinge7e70fa2018-01-16 10:22:50 +00001518 goto next_rx_no_prod_no_len;
Michael Chanc0c050c2015-10-22 16:01:17 -04001519
1520 } else if (cmp_type == CMP_TYPE_RX_L2_TPA_END_CMP) {
1521 skb = bnxt_tpa_end(bp, bnapi, &tmp_raw_cons,
1522 (struct rx_tpa_end_cmp *)rxcmp,
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001523 (struct rx_tpa_end_cmp_ext *)rxcmp1, event);
Michael Chanc0c050c2015-10-22 16:01:17 -04001524
Tobias Klauser1fac4b22017-09-26 15:12:26 +02001525 if (IS_ERR(skb))
Michael Chanc0c050c2015-10-22 16:01:17 -04001526 return -EBUSY;
1527
1528 rc = -ENOMEM;
1529 if (likely(skb)) {
Sathya Perlaee5c7fb2017-07-24 12:34:28 -04001530 bnxt_deliver_skb(bp, bnapi, skb);
Michael Chanc0c050c2015-10-22 16:01:17 -04001531 rc = 1;
1532 }
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001533 *event |= BNXT_RX_EVENT;
Colin Ian Kinge7e70fa2018-01-16 10:22:50 +00001534 goto next_rx_no_prod_no_len;
Michael Chanc0c050c2015-10-22 16:01:17 -04001535 }
1536
1537 cons = rxcmp->rx_cmp_opaque;
1538 rx_buf = &rxr->rx_buf_ring[cons];
1539 data = rx_buf->data;
Michael Chan6bb19472017-02-06 16:55:32 -05001540 data_ptr = rx_buf->data_ptr;
Michael Chanfa7e2812016-05-10 19:18:00 -04001541 if (unlikely(cons != rxr->rx_next_cons)) {
1542 int rc1 = bnxt_discard_rx(bp, bnapi, raw_cons, rxcmp);
1543
1544 bnxt_sched_reset(bp, rxr);
1545 return rc1;
1546 }
Michael Chan6bb19472017-02-06 16:55:32 -05001547 prefetch(data_ptr);
Michael Chanc0c050c2015-10-22 16:01:17 -04001548
Michael Chanc61fb992017-02-06 16:55:36 -05001549 misc = le32_to_cpu(rxcmp->rx_cmp_misc_v1);
1550 agg_bufs = (misc & RX_CMP_AGG_BUFS) >> RX_CMP_AGG_BUFS_SHIFT;
Michael Chanc0c050c2015-10-22 16:01:17 -04001551
1552 if (agg_bufs) {
1553 if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, &tmp_raw_cons))
1554 return -EBUSY;
1555
1556 cp_cons = NEXT_CMP(cp_cons);
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001557 *event |= BNXT_AGG_EVENT;
Michael Chanc0c050c2015-10-22 16:01:17 -04001558 }
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001559 *event |= BNXT_RX_EVENT;
Michael Chanc0c050c2015-10-22 16:01:17 -04001560
1561 rx_buf->data = NULL;
1562 if (rxcmp1->rx_cmp_cfa_code_errors_v2 & RX_CMP_L2_ERRORS) {
1563 bnxt_reuse_rx_data(rxr, cons, data);
1564 if (agg_bufs)
1565 bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs);
1566
1567 rc = -EIO;
1568 goto next_rx;
1569 }
1570
1571 len = le32_to_cpu(rxcmp->rx_cmp_len_flags_type) >> RX_CMP_LEN_SHIFT;
Michael Chan11cd1192017-02-06 16:55:33 -05001572 dma_addr = rx_buf->mapping;
Michael Chanc0c050c2015-10-22 16:01:17 -04001573
Michael Chanc6d30e82017-02-06 16:55:42 -05001574 if (bnxt_rx_xdp(bp, rxr, cons, data, &data_ptr, &len, event)) {
1575 rc = 1;
1576 goto next_rx;
1577 }
1578
Michael Chanc0c050c2015-10-22 16:01:17 -04001579 if (len <= bp->rx_copy_thresh) {
Michael Chan6bb19472017-02-06 16:55:32 -05001580 skb = bnxt_copy_skb(bnapi, data_ptr, len, dma_addr);
Michael Chanc0c050c2015-10-22 16:01:17 -04001581 bnxt_reuse_rx_data(rxr, cons, data);
1582 if (!skb) {
1583 rc = -ENOMEM;
1584 goto next_rx;
1585 }
1586 } else {
Michael Chanc61fb992017-02-06 16:55:36 -05001587 u32 payload;
1588
Michael Chanc6d30e82017-02-06 16:55:42 -05001589 if (rx_buf->data_ptr == data_ptr)
1590 payload = misc & RX_CMP_PAYLOAD_OFFSET;
1591 else
1592 payload = 0;
Michael Chan6bb19472017-02-06 16:55:32 -05001593 skb = bp->rx_skb_func(bp, rxr, cons, data, data_ptr, dma_addr,
Michael Chanc61fb992017-02-06 16:55:36 -05001594 payload | len);
Michael Chanc0c050c2015-10-22 16:01:17 -04001595 if (!skb) {
1596 rc = -ENOMEM;
1597 goto next_rx;
1598 }
1599 }
1600
1601 if (agg_bufs) {
1602 skb = bnxt_rx_pages(bp, bnapi, skb, cp_cons, agg_bufs);
1603 if (!skb) {
1604 rc = -ENOMEM;
1605 goto next_rx;
1606 }
1607 }
1608
1609 if (RX_CMP_HASH_VALID(rxcmp)) {
1610 u32 hash_type = RX_CMP_HASH_TYPE(rxcmp);
1611 enum pkt_hash_types type = PKT_HASH_TYPE_L4;
1612
1613 /* RSS profiles 1 and 3 with extract code 0 for inner 4-tuple */
1614 if (hash_type != 1 && hash_type != 3)
1615 type = PKT_HASH_TYPE_L3;
1616 skb_set_hash(skb, le32_to_cpu(rxcmp->rx_cmp_rss_hash), type);
1617 }
1618
Sathya Perlaee5c7fb2017-07-24 12:34:28 -04001619 cfa_code = RX_CMP_CFA_CODE(rxcmp1);
1620 skb->protocol = eth_type_trans(skb, bnxt_get_pkt_dev(bp, cfa_code));
Michael Chanc0c050c2015-10-22 16:01:17 -04001621
Michael Chan8852ddb2016-06-06 02:37:16 -04001622 if ((rxcmp1->rx_cmp_flags2 &
1623 cpu_to_le32(RX_CMP_FLAGS2_META_FORMAT_VLAN)) &&
1624 (skb->dev->features & NETIF_F_HW_VLAN_CTAG_RX)) {
Michael Chanc0c050c2015-10-22 16:01:17 -04001625 u32 meta_data = le32_to_cpu(rxcmp1->rx_cmp_meta_data);
Michael Chaned7bc6022018-03-09 23:46:06 -05001626 u16 vtag = meta_data & RX_CMP_FLAGS2_METADATA_TCI_MASK;
Michael Chanc0c050c2015-10-22 16:01:17 -04001627 u16 vlan_proto = meta_data >> RX_CMP_FLAGS2_METADATA_TPID_SFT;
1628
Michael Chan8852ddb2016-06-06 02:37:16 -04001629 __vlan_hwaccel_put_tag(skb, htons(vlan_proto), vtag);
Michael Chanc0c050c2015-10-22 16:01:17 -04001630 }
1631
1632 skb_checksum_none_assert(skb);
1633 if (RX_CMP_L4_CS_OK(rxcmp1)) {
1634 if (dev->features & NETIF_F_RXCSUM) {
1635 skb->ip_summed = CHECKSUM_UNNECESSARY;
1636 skb->csum_level = RX_CMP_ENCAP(rxcmp1);
1637 }
1638 } else {
Satish Baddipadige665e3502015-12-27 18:19:21 -05001639 if (rxcmp1->rx_cmp_cfa_code_errors_v2 & RX_CMP_L4_CS_ERR_BITS) {
1640 if (dev->features & NETIF_F_RXCSUM)
1641 cpr->rx_l4_csum_errors++;
1642 }
Michael Chanc0c050c2015-10-22 16:01:17 -04001643 }
1644
Sathya Perlaee5c7fb2017-07-24 12:34:28 -04001645 bnxt_deliver_skb(bp, bnapi, skb);
Michael Chanc0c050c2015-10-22 16:01:17 -04001646 rc = 1;
1647
1648next_rx:
1649 rxr->rx_prod = NEXT_RX(prod);
Michael Chan376a5b82016-05-10 19:17:59 -04001650 rxr->rx_next_cons = NEXT_RX(cons);
Michael Chanc0c050c2015-10-22 16:01:17 -04001651
Andy Gospodarek6a8788f2018-01-09 16:06:20 -05001652 cpr->rx_packets += 1;
1653 cpr->rx_bytes += len;
Colin Ian Kinge7e70fa2018-01-16 10:22:50 +00001654
1655next_rx_no_prod_no_len:
Michael Chanc0c050c2015-10-22 16:01:17 -04001656 *raw_cons = tmp_raw_cons;
1657
1658 return rc;
1659}
1660
Michael Chan2270bc52017-06-23 14:01:01 -04001661/* In netpoll mode, if we are using a combined completion ring, we need to
1662 * discard the rx packets and recycle the buffers.
1663 */
1664static int bnxt_force_rx_discard(struct bnxt *bp, struct bnxt_napi *bnapi,
1665 u32 *raw_cons, u8 *event)
1666{
1667 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1668 u32 tmp_raw_cons = *raw_cons;
1669 struct rx_cmp_ext *rxcmp1;
1670 struct rx_cmp *rxcmp;
1671 u16 cp_cons;
1672 u8 cmp_type;
1673
1674 cp_cons = RING_CMP(tmp_raw_cons);
1675 rxcmp = (struct rx_cmp *)
1676 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
1677
1678 tmp_raw_cons = NEXT_RAW_CMP(tmp_raw_cons);
1679 cp_cons = RING_CMP(tmp_raw_cons);
1680 rxcmp1 = (struct rx_cmp_ext *)
1681 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
1682
1683 if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons))
1684 return -EBUSY;
1685
1686 cmp_type = RX_CMP_TYPE(rxcmp);
1687 if (cmp_type == CMP_TYPE_RX_L2_CMP) {
1688 rxcmp1->rx_cmp_cfa_code_errors_v2 |=
1689 cpu_to_le32(RX_CMPL_ERRORS_CRC_ERROR);
1690 } else if (cmp_type == CMP_TYPE_RX_L2_TPA_END_CMP) {
1691 struct rx_tpa_end_cmp_ext *tpa_end1;
1692
1693 tpa_end1 = (struct rx_tpa_end_cmp_ext *)rxcmp1;
1694 tpa_end1->rx_tpa_end_cmp_errors_v2 |=
1695 cpu_to_le32(RX_TPA_END_CMP_ERRORS);
1696 }
1697 return bnxt_rx_pkt(bp, bnapi, raw_cons, event);
1698}
1699
Michael Chan4bb13ab2016-04-05 14:09:01 -04001700#define BNXT_GET_EVENT_PORT(data) \
Michael Chan87c374d2016-12-02 21:17:16 -05001701 ((data) & \
1702 ASYNC_EVENT_CMPL_PORT_CONN_NOT_ALLOWED_EVENT_DATA1_PORT_ID_MASK)
Michael Chan4bb13ab2016-04-05 14:09:01 -04001703
Michael Chanc0c050c2015-10-22 16:01:17 -04001704static int bnxt_async_event_process(struct bnxt *bp,
1705 struct hwrm_async_event_cmpl *cmpl)
1706{
1707 u16 event_id = le16_to_cpu(cmpl->event_id);
1708
1709 /* TODO CHIMP_FW: Define event id's for link change, error etc */
1710 switch (event_id) {
Michael Chan87c374d2016-12-02 21:17:16 -05001711 case ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE: {
Michael Chan8cbde112016-04-11 04:11:14 -04001712 u32 data1 = le32_to_cpu(cmpl->event_data1);
1713 struct bnxt_link_info *link_info = &bp->link_info;
1714
1715 if (BNXT_VF(bp))
1716 goto async_event_process_exit;
Michael Chana8168b62017-12-06 17:31:22 -05001717
1718 /* print unsupported speed warning in forced speed mode only */
1719 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED) &&
1720 (data1 & 0x20000)) {
Michael Chan8cbde112016-04-11 04:11:14 -04001721 u16 fw_speed = link_info->force_link_speed;
1722 u32 speed = bnxt_fw_to_ethtool_speed(fw_speed);
1723
Michael Chana8168b62017-12-06 17:31:22 -05001724 if (speed != SPEED_UNKNOWN)
1725 netdev_warn(bp->dev, "Link speed %d no longer supported\n",
1726 speed);
Michael Chan8cbde112016-04-11 04:11:14 -04001727 }
Michael Chan286ef9d2016-11-16 21:13:08 -05001728 set_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT, &bp->sp_event);
Michael Chan8cbde112016-04-11 04:11:14 -04001729 /* fall thru */
1730 }
Michael Chan87c374d2016-12-02 21:17:16 -05001731 case ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE:
Michael Chanc0c050c2015-10-22 16:01:17 -04001732 set_bit(BNXT_LINK_CHNG_SP_EVENT, &bp->sp_event);
Jeffrey Huang19241362016-02-26 04:00:00 -05001733 break;
Michael Chan87c374d2016-12-02 21:17:16 -05001734 case ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD:
Jeffrey Huang19241362016-02-26 04:00:00 -05001735 set_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT, &bp->sp_event);
Michael Chanc0c050c2015-10-22 16:01:17 -04001736 break;
Michael Chan87c374d2016-12-02 21:17:16 -05001737 case ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED: {
Michael Chan4bb13ab2016-04-05 14:09:01 -04001738 u32 data1 = le32_to_cpu(cmpl->event_data1);
1739 u16 port_id = BNXT_GET_EVENT_PORT(data1);
1740
1741 if (BNXT_VF(bp))
1742 break;
1743
1744 if (bp->pf.port_id != port_id)
1745 break;
1746
Michael Chan4bb13ab2016-04-05 14:09:01 -04001747 set_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT, &bp->sp_event);
1748 break;
1749 }
Michael Chan87c374d2016-12-02 21:17:16 -05001750 case ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE:
Michael Chanfc0f1922016-06-13 02:25:30 -04001751 if (BNXT_PF(bp))
1752 goto async_event_process_exit;
1753 set_bit(BNXT_RESET_TASK_SILENT_SP_EVENT, &bp->sp_event);
1754 break;
Michael Chanc0c050c2015-10-22 16:01:17 -04001755 default:
Jeffrey Huang19241362016-02-26 04:00:00 -05001756 goto async_event_process_exit;
Michael Chanc0c050c2015-10-22 16:01:17 -04001757 }
Michael Chanc213eae2017-10-13 21:09:29 -04001758 bnxt_queue_sp_work(bp);
Jeffrey Huang19241362016-02-26 04:00:00 -05001759async_event_process_exit:
Michael Chana588e452016-12-07 00:26:21 -05001760 bnxt_ulp_async_events(bp, cmpl);
Michael Chanc0c050c2015-10-22 16:01:17 -04001761 return 0;
1762}
1763
1764static int bnxt_hwrm_handler(struct bnxt *bp, struct tx_cmp *txcmp)
1765{
1766 u16 cmpl_type = TX_CMP_TYPE(txcmp), vf_id, seq_id;
1767 struct hwrm_cmpl *h_cmpl = (struct hwrm_cmpl *)txcmp;
1768 struct hwrm_fwd_req_cmpl *fwd_req_cmpl =
1769 (struct hwrm_fwd_req_cmpl *)txcmp;
1770
1771 switch (cmpl_type) {
1772 case CMPL_BASE_TYPE_HWRM_DONE:
1773 seq_id = le16_to_cpu(h_cmpl->sequence_id);
1774 if (seq_id == bp->hwrm_intr_seq_id)
1775 bp->hwrm_intr_seq_id = HWRM_SEQ_ID_INVALID;
1776 else
1777 netdev_err(bp->dev, "Invalid hwrm seq id %d\n", seq_id);
1778 break;
1779
1780 case CMPL_BASE_TYPE_HWRM_FWD_REQ:
1781 vf_id = le16_to_cpu(fwd_req_cmpl->source_id);
1782
1783 if ((vf_id < bp->pf.first_vf_id) ||
1784 (vf_id >= bp->pf.first_vf_id + bp->pf.active_vfs)) {
1785 netdev_err(bp->dev, "Msg contains invalid VF id %x\n",
1786 vf_id);
1787 return -EINVAL;
1788 }
1789
1790 set_bit(vf_id - bp->pf.first_vf_id, bp->pf.vf_event_bmap);
1791 set_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT, &bp->sp_event);
Michael Chanc213eae2017-10-13 21:09:29 -04001792 bnxt_queue_sp_work(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04001793 break;
1794
1795 case CMPL_BASE_TYPE_HWRM_ASYNC_EVENT:
1796 bnxt_async_event_process(bp,
1797 (struct hwrm_async_event_cmpl *)txcmp);
1798
1799 default:
1800 break;
1801 }
1802
1803 return 0;
1804}
1805
1806static irqreturn_t bnxt_msix(int irq, void *dev_instance)
1807{
1808 struct bnxt_napi *bnapi = dev_instance;
1809 struct bnxt *bp = bnapi->bp;
1810 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1811 u32 cons = RING_CMP(cpr->cp_raw_cons);
1812
Andy Gospodarek6a8788f2018-01-09 16:06:20 -05001813 cpr->event_ctr++;
Michael Chanc0c050c2015-10-22 16:01:17 -04001814 prefetch(&cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]);
1815 napi_schedule(&bnapi->napi);
1816 return IRQ_HANDLED;
1817}
1818
1819static inline int bnxt_has_work(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
1820{
1821 u32 raw_cons = cpr->cp_raw_cons;
1822 u16 cons = RING_CMP(raw_cons);
1823 struct tx_cmp *txcmp;
1824
1825 txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)];
1826
1827 return TX_CMP_VALID(txcmp, raw_cons);
1828}
1829
Michael Chanc0c050c2015-10-22 16:01:17 -04001830static irqreturn_t bnxt_inta(int irq, void *dev_instance)
1831{
1832 struct bnxt_napi *bnapi = dev_instance;
1833 struct bnxt *bp = bnapi->bp;
1834 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1835 u32 cons = RING_CMP(cpr->cp_raw_cons);
1836 u32 int_status;
1837
1838 prefetch(&cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]);
1839
1840 if (!bnxt_has_work(bp, cpr)) {
Jeffrey Huang11809492015-11-05 16:25:49 -05001841 int_status = readl(bp->bar0 + BNXT_CAG_REG_LEGACY_INT_STATUS);
Michael Chanc0c050c2015-10-22 16:01:17 -04001842 /* return if erroneous interrupt */
1843 if (!(int_status & (0x10000 << cpr->cp_ring_struct.fw_ring_id)))
1844 return IRQ_NONE;
1845 }
1846
1847 /* disable ring IRQ */
1848 BNXT_CP_DB_IRQ_DIS(cpr->cp_doorbell);
1849
1850 /* Return here if interrupt is shared and is disabled. */
1851 if (unlikely(atomic_read(&bp->intr_sem) != 0))
1852 return IRQ_HANDLED;
1853
1854 napi_schedule(&bnapi->napi);
1855 return IRQ_HANDLED;
1856}
1857
1858static int bnxt_poll_work(struct bnxt *bp, struct bnxt_napi *bnapi, int budget)
1859{
1860 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1861 u32 raw_cons = cpr->cp_raw_cons;
1862 u32 cons;
1863 int tx_pkts = 0;
1864 int rx_pkts = 0;
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001865 u8 event = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04001866 struct tx_cmp *txcmp;
1867
1868 while (1) {
1869 int rc;
1870
1871 cons = RING_CMP(raw_cons);
1872 txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)];
1873
1874 if (!TX_CMP_VALID(txcmp, raw_cons))
1875 break;
1876
Michael Chan67a95e22016-05-04 16:56:43 -04001877 /* The valid test of the entry must be done first before
1878 * reading any further.
1879 */
Michael Chanb67daab2016-05-15 03:04:51 -04001880 dma_rmb();
Michael Chanc0c050c2015-10-22 16:01:17 -04001881 if (TX_CMP_TYPE(txcmp) == CMP_TYPE_TX_L2_CMP) {
1882 tx_pkts++;
1883 /* return full budget so NAPI will complete. */
1884 if (unlikely(tx_pkts > bp->tx_wake_thresh))
1885 rx_pkts = budget;
1886 } else if ((TX_CMP_TYPE(txcmp) & 0x30) == 0x10) {
Michael Chan2270bc52017-06-23 14:01:01 -04001887 if (likely(budget))
1888 rc = bnxt_rx_pkt(bp, bnapi, &raw_cons, &event);
1889 else
1890 rc = bnxt_force_rx_discard(bp, bnapi, &raw_cons,
1891 &event);
Michael Chanc0c050c2015-10-22 16:01:17 -04001892 if (likely(rc >= 0))
1893 rx_pkts += rc;
Michael Chan903649e2017-08-28 13:40:30 -04001894 /* Increment rx_pkts when rc is -ENOMEM to count towards
1895 * the NAPI budget. Otherwise, we may potentially loop
1896 * here forever if we consistently cannot allocate
1897 * buffers.
1898 */
Calvin Owens2edbdb32017-12-08 09:05:26 -08001899 else if (rc == -ENOMEM && budget)
Michael Chan903649e2017-08-28 13:40:30 -04001900 rx_pkts++;
Michael Chanc0c050c2015-10-22 16:01:17 -04001901 else if (rc == -EBUSY) /* partial completion */
1902 break;
Michael Chanc0c050c2015-10-22 16:01:17 -04001903 } else if (unlikely((TX_CMP_TYPE(txcmp) ==
1904 CMPL_BASE_TYPE_HWRM_DONE) ||
1905 (TX_CMP_TYPE(txcmp) ==
1906 CMPL_BASE_TYPE_HWRM_FWD_REQ) ||
1907 (TX_CMP_TYPE(txcmp) ==
1908 CMPL_BASE_TYPE_HWRM_ASYNC_EVENT))) {
1909 bnxt_hwrm_handler(bp, txcmp);
1910 }
1911 raw_cons = NEXT_RAW_CMP(raw_cons);
1912
1913 if (rx_pkts == budget)
1914 break;
1915 }
1916
Michael Chan38413402017-02-06 16:55:43 -05001917 if (event & BNXT_TX_EVENT) {
1918 struct bnxt_tx_ring_info *txr = bnapi->tx_ring;
1919 void __iomem *db = txr->tx_doorbell;
1920 u16 prod = txr->tx_prod;
1921
1922 /* Sync BD data before updating doorbell */
1923 wmb();
1924
Sinan Kayafd141fa2018-03-25 10:39:20 -04001925 bnxt_db_write_relaxed(bp, db, DB_KEY_TX | prod);
Michael Chan38413402017-02-06 16:55:43 -05001926 }
1927
Michael Chanc0c050c2015-10-22 16:01:17 -04001928 cpr->cp_raw_cons = raw_cons;
1929 /* ACK completion ring before freeing tx ring and producing new
1930 * buffers in rx/agg rings to prevent overflowing the completion
1931 * ring.
1932 */
1933 BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
1934
1935 if (tx_pkts)
Michael Chanfa3e93e2017-02-06 16:55:41 -05001936 bnapi->tx_int(bp, bnapi, tx_pkts);
Michael Chanc0c050c2015-10-22 16:01:17 -04001937
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001938 if (event & BNXT_RX_EVENT) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05001939 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
Michael Chanc0c050c2015-10-22 16:01:17 -04001940
Michael Chan434c9752017-05-29 19:06:08 -04001941 bnxt_db_write(bp, rxr->rx_doorbell, DB_KEY_RX | rxr->rx_prod);
1942 if (event & BNXT_AGG_EVENT)
1943 bnxt_db_write(bp, rxr->rx_agg_doorbell,
1944 DB_KEY_RX | rxr->rx_agg_prod);
Michael Chanc0c050c2015-10-22 16:01:17 -04001945 }
1946 return rx_pkts;
1947}
1948
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04001949static int bnxt_poll_nitroa0(struct napi_struct *napi, int budget)
1950{
1951 struct bnxt_napi *bnapi = container_of(napi, struct bnxt_napi, napi);
1952 struct bnxt *bp = bnapi->bp;
1953 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1954 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
1955 struct tx_cmp *txcmp;
1956 struct rx_cmp_ext *rxcmp1;
1957 u32 cp_cons, tmp_raw_cons;
1958 u32 raw_cons = cpr->cp_raw_cons;
1959 u32 rx_pkts = 0;
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001960 u8 event = 0;
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04001961
1962 while (1) {
1963 int rc;
1964
1965 cp_cons = RING_CMP(raw_cons);
1966 txcmp = &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
1967
1968 if (!TX_CMP_VALID(txcmp, raw_cons))
1969 break;
1970
1971 if ((TX_CMP_TYPE(txcmp) & 0x30) == 0x10) {
1972 tmp_raw_cons = NEXT_RAW_CMP(raw_cons);
1973 cp_cons = RING_CMP(tmp_raw_cons);
1974 rxcmp1 = (struct rx_cmp_ext *)
1975 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
1976
1977 if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons))
1978 break;
1979
1980 /* force an error to recycle the buffer */
1981 rxcmp1->rx_cmp_cfa_code_errors_v2 |=
1982 cpu_to_le32(RX_CMPL_ERRORS_CRC_ERROR);
1983
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001984 rc = bnxt_rx_pkt(bp, bnapi, &raw_cons, &event);
Calvin Owens2edbdb32017-12-08 09:05:26 -08001985 if (likely(rc == -EIO) && budget)
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04001986 rx_pkts++;
1987 else if (rc == -EBUSY) /* partial completion */
1988 break;
1989 } else if (unlikely(TX_CMP_TYPE(txcmp) ==
1990 CMPL_BASE_TYPE_HWRM_DONE)) {
1991 bnxt_hwrm_handler(bp, txcmp);
1992 } else {
1993 netdev_err(bp->dev,
1994 "Invalid completion received on special ring\n");
1995 }
1996 raw_cons = NEXT_RAW_CMP(raw_cons);
1997
1998 if (rx_pkts == budget)
1999 break;
2000 }
2001
2002 cpr->cp_raw_cons = raw_cons;
2003 BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
Michael Chan434c9752017-05-29 19:06:08 -04002004 bnxt_db_write(bp, rxr->rx_doorbell, DB_KEY_RX | rxr->rx_prod);
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04002005
Michael Chan434c9752017-05-29 19:06:08 -04002006 if (event & BNXT_AGG_EVENT)
2007 bnxt_db_write(bp, rxr->rx_agg_doorbell,
2008 DB_KEY_RX | rxr->rx_agg_prod);
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04002009
2010 if (!bnxt_has_work(bp, cpr) && rx_pkts < budget) {
Eric Dumazet6ad20162017-01-30 08:22:01 -08002011 napi_complete_done(napi, rx_pkts);
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04002012 BNXT_CP_DB_REARM(cpr->cp_doorbell, cpr->cp_raw_cons);
2013 }
2014 return rx_pkts;
2015}
2016
Michael Chanc0c050c2015-10-22 16:01:17 -04002017static int bnxt_poll(struct napi_struct *napi, int budget)
2018{
2019 struct bnxt_napi *bnapi = container_of(napi, struct bnxt_napi, napi);
2020 struct bnxt *bp = bnapi->bp;
2021 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
2022 int work_done = 0;
2023
Michael Chanc0c050c2015-10-22 16:01:17 -04002024 while (1) {
2025 work_done += bnxt_poll_work(bp, bnapi, budget - work_done);
2026
2027 if (work_done >= budget)
2028 break;
2029
2030 if (!bnxt_has_work(bp, cpr)) {
Michael Chane7b95692016-12-29 12:13:32 -05002031 if (napi_complete_done(napi, work_done))
2032 BNXT_CP_DB_REARM(cpr->cp_doorbell,
2033 cpr->cp_raw_cons);
Michael Chanc0c050c2015-10-22 16:01:17 -04002034 break;
2035 }
2036 }
Andy Gospodarek6a8788f2018-01-09 16:06:20 -05002037 if (bp->flags & BNXT_FLAG_DIM) {
2038 struct net_dim_sample dim_sample;
2039
2040 net_dim_sample(cpr->event_ctr,
2041 cpr->rx_packets,
2042 cpr->rx_bytes,
2043 &dim_sample);
2044 net_dim(&cpr->dim, dim_sample);
2045 }
Michael Chanc0c050c2015-10-22 16:01:17 -04002046 mmiowb();
Michael Chanc0c050c2015-10-22 16:01:17 -04002047 return work_done;
2048}
2049
Michael Chanc0c050c2015-10-22 16:01:17 -04002050static void bnxt_free_tx_skbs(struct bnxt *bp)
2051{
2052 int i, max_idx;
2053 struct pci_dev *pdev = bp->pdev;
2054
Michael Chanb6ab4b02016-01-02 23:44:59 -05002055 if (!bp->tx_ring)
Michael Chanc0c050c2015-10-22 16:01:17 -04002056 return;
2057
2058 max_idx = bp->tx_nr_pages * TX_DESC_CNT;
2059 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05002060 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04002061 int j;
2062
Michael Chanc0c050c2015-10-22 16:01:17 -04002063 for (j = 0; j < max_idx;) {
2064 struct bnxt_sw_tx_bd *tx_buf = &txr->tx_buf_ring[j];
2065 struct sk_buff *skb = tx_buf->skb;
2066 int k, last;
2067
2068 if (!skb) {
2069 j++;
2070 continue;
2071 }
2072
2073 tx_buf->skb = NULL;
2074
2075 if (tx_buf->is_push) {
2076 dev_kfree_skb(skb);
2077 j += 2;
2078 continue;
2079 }
2080
2081 dma_unmap_single(&pdev->dev,
2082 dma_unmap_addr(tx_buf, mapping),
2083 skb_headlen(skb),
2084 PCI_DMA_TODEVICE);
2085
2086 last = tx_buf->nr_frags;
2087 j += 2;
Michael Chand612a572016-01-28 03:11:22 -05002088 for (k = 0; k < last; k++, j++) {
2089 int ring_idx = j & bp->tx_ring_mask;
Michael Chanc0c050c2015-10-22 16:01:17 -04002090 skb_frag_t *frag = &skb_shinfo(skb)->frags[k];
2091
Michael Chand612a572016-01-28 03:11:22 -05002092 tx_buf = &txr->tx_buf_ring[ring_idx];
Michael Chanc0c050c2015-10-22 16:01:17 -04002093 dma_unmap_page(
2094 &pdev->dev,
2095 dma_unmap_addr(tx_buf, mapping),
2096 skb_frag_size(frag), PCI_DMA_TODEVICE);
2097 }
2098 dev_kfree_skb(skb);
2099 }
2100 netdev_tx_reset_queue(netdev_get_tx_queue(bp->dev, i));
2101 }
2102}
2103
2104static void bnxt_free_rx_skbs(struct bnxt *bp)
2105{
2106 int i, max_idx, max_agg_idx;
2107 struct pci_dev *pdev = bp->pdev;
2108
Michael Chanb6ab4b02016-01-02 23:44:59 -05002109 if (!bp->rx_ring)
Michael Chanc0c050c2015-10-22 16:01:17 -04002110 return;
2111
2112 max_idx = bp->rx_nr_pages * RX_DESC_CNT;
2113 max_agg_idx = bp->rx_agg_nr_pages * RX_DESC_CNT;
2114 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05002115 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04002116 int j;
2117
Michael Chanc0c050c2015-10-22 16:01:17 -04002118 if (rxr->rx_tpa) {
2119 for (j = 0; j < MAX_TPA; j++) {
2120 struct bnxt_tpa_info *tpa_info =
2121 &rxr->rx_tpa[j];
2122 u8 *data = tpa_info->data;
2123
2124 if (!data)
2125 continue;
2126
Shannon Nelsonc519fe92017-05-09 18:30:12 -07002127 dma_unmap_single_attrs(&pdev->dev,
2128 tpa_info->mapping,
2129 bp->rx_buf_use_size,
2130 bp->rx_dir,
2131 DMA_ATTR_WEAK_ORDERING);
Michael Chanc0c050c2015-10-22 16:01:17 -04002132
2133 tpa_info->data = NULL;
2134
2135 kfree(data);
2136 }
2137 }
2138
2139 for (j = 0; j < max_idx; j++) {
2140 struct bnxt_sw_rx_bd *rx_buf = &rxr->rx_buf_ring[j];
Michael Chan3ed3a832017-03-28 19:47:31 -04002141 dma_addr_t mapping = rx_buf->mapping;
Michael Chan6bb19472017-02-06 16:55:32 -05002142 void *data = rx_buf->data;
Michael Chanc0c050c2015-10-22 16:01:17 -04002143
2144 if (!data)
2145 continue;
2146
Michael Chanc0c050c2015-10-22 16:01:17 -04002147 rx_buf->data = NULL;
2148
Michael Chan3ed3a832017-03-28 19:47:31 -04002149 if (BNXT_RX_PAGE_MODE(bp)) {
2150 mapping -= bp->rx_dma_offset;
Shannon Nelsonc519fe92017-05-09 18:30:12 -07002151 dma_unmap_page_attrs(&pdev->dev, mapping,
2152 PAGE_SIZE, bp->rx_dir,
2153 DMA_ATTR_WEAK_ORDERING);
Michael Chanc61fb992017-02-06 16:55:36 -05002154 __free_page(data);
Michael Chan3ed3a832017-03-28 19:47:31 -04002155 } else {
Shannon Nelsonc519fe92017-05-09 18:30:12 -07002156 dma_unmap_single_attrs(&pdev->dev, mapping,
2157 bp->rx_buf_use_size,
2158 bp->rx_dir,
2159 DMA_ATTR_WEAK_ORDERING);
Michael Chanc61fb992017-02-06 16:55:36 -05002160 kfree(data);
Michael Chan3ed3a832017-03-28 19:47:31 -04002161 }
Michael Chanc0c050c2015-10-22 16:01:17 -04002162 }
2163
2164 for (j = 0; j < max_agg_idx; j++) {
2165 struct bnxt_sw_rx_agg_bd *rx_agg_buf =
2166 &rxr->rx_agg_ring[j];
2167 struct page *page = rx_agg_buf->page;
2168
2169 if (!page)
2170 continue;
2171
Shannon Nelsonc519fe92017-05-09 18:30:12 -07002172 dma_unmap_page_attrs(&pdev->dev, rx_agg_buf->mapping,
2173 BNXT_RX_PAGE_SIZE,
2174 PCI_DMA_FROMDEVICE,
2175 DMA_ATTR_WEAK_ORDERING);
Michael Chanc0c050c2015-10-22 16:01:17 -04002176
2177 rx_agg_buf->page = NULL;
2178 __clear_bit(j, rxr->rx_agg_bmap);
2179
2180 __free_page(page);
2181 }
Michael Chan89d0a062016-04-25 02:30:51 -04002182 if (rxr->rx_page) {
2183 __free_page(rxr->rx_page);
2184 rxr->rx_page = NULL;
2185 }
Michael Chanc0c050c2015-10-22 16:01:17 -04002186 }
2187}
2188
2189static void bnxt_free_skbs(struct bnxt *bp)
2190{
2191 bnxt_free_tx_skbs(bp);
2192 bnxt_free_rx_skbs(bp);
2193}
2194
2195static void bnxt_free_ring(struct bnxt *bp, struct bnxt_ring_struct *ring)
2196{
2197 struct pci_dev *pdev = bp->pdev;
2198 int i;
2199
2200 for (i = 0; i < ring->nr_pages; i++) {
2201 if (!ring->pg_arr[i])
2202 continue;
2203
2204 dma_free_coherent(&pdev->dev, ring->page_size,
2205 ring->pg_arr[i], ring->dma_arr[i]);
2206
2207 ring->pg_arr[i] = NULL;
2208 }
2209 if (ring->pg_tbl) {
2210 dma_free_coherent(&pdev->dev, ring->nr_pages * 8,
2211 ring->pg_tbl, ring->pg_tbl_map);
2212 ring->pg_tbl = NULL;
2213 }
2214 if (ring->vmem_size && *ring->vmem) {
2215 vfree(*ring->vmem);
2216 *ring->vmem = NULL;
2217 }
2218}
2219
2220static int bnxt_alloc_ring(struct bnxt *bp, struct bnxt_ring_struct *ring)
2221{
2222 int i;
2223 struct pci_dev *pdev = bp->pdev;
2224
2225 if (ring->nr_pages > 1) {
2226 ring->pg_tbl = dma_alloc_coherent(&pdev->dev,
2227 ring->nr_pages * 8,
2228 &ring->pg_tbl_map,
2229 GFP_KERNEL);
2230 if (!ring->pg_tbl)
2231 return -ENOMEM;
2232 }
2233
2234 for (i = 0; i < ring->nr_pages; i++) {
2235 ring->pg_arr[i] = dma_alloc_coherent(&pdev->dev,
2236 ring->page_size,
2237 &ring->dma_arr[i],
2238 GFP_KERNEL);
2239 if (!ring->pg_arr[i])
2240 return -ENOMEM;
2241
2242 if (ring->nr_pages > 1)
2243 ring->pg_tbl[i] = cpu_to_le64(ring->dma_arr[i]);
2244 }
2245
2246 if (ring->vmem_size) {
2247 *ring->vmem = vzalloc(ring->vmem_size);
2248 if (!(*ring->vmem))
2249 return -ENOMEM;
2250 }
2251 return 0;
2252}
2253
2254static void bnxt_free_rx_rings(struct bnxt *bp)
2255{
2256 int i;
2257
Michael Chanb6ab4b02016-01-02 23:44:59 -05002258 if (!bp->rx_ring)
Michael Chanc0c050c2015-10-22 16:01:17 -04002259 return;
2260
2261 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05002262 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04002263 struct bnxt_ring_struct *ring;
2264
Michael Chanc6d30e82017-02-06 16:55:42 -05002265 if (rxr->xdp_prog)
2266 bpf_prog_put(rxr->xdp_prog);
2267
Jesper Dangaard Brouer96a86042018-01-03 11:25:44 +01002268 if (xdp_rxq_info_is_reg(&rxr->xdp_rxq))
2269 xdp_rxq_info_unreg(&rxr->xdp_rxq);
2270
Michael Chanc0c050c2015-10-22 16:01:17 -04002271 kfree(rxr->rx_tpa);
2272 rxr->rx_tpa = NULL;
2273
2274 kfree(rxr->rx_agg_bmap);
2275 rxr->rx_agg_bmap = NULL;
2276
2277 ring = &rxr->rx_ring_struct;
2278 bnxt_free_ring(bp, ring);
2279
2280 ring = &rxr->rx_agg_ring_struct;
2281 bnxt_free_ring(bp, ring);
2282 }
2283}
2284
2285static int bnxt_alloc_rx_rings(struct bnxt *bp)
2286{
2287 int i, rc, agg_rings = 0, tpa_rings = 0;
2288
Michael Chanb6ab4b02016-01-02 23:44:59 -05002289 if (!bp->rx_ring)
2290 return -ENOMEM;
2291
Michael Chanc0c050c2015-10-22 16:01:17 -04002292 if (bp->flags & BNXT_FLAG_AGG_RINGS)
2293 agg_rings = 1;
2294
2295 if (bp->flags & BNXT_FLAG_TPA)
2296 tpa_rings = 1;
2297
2298 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05002299 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04002300 struct bnxt_ring_struct *ring;
2301
Michael Chanc0c050c2015-10-22 16:01:17 -04002302 ring = &rxr->rx_ring_struct;
2303
Jesper Dangaard Brouer96a86042018-01-03 11:25:44 +01002304 rc = xdp_rxq_info_reg(&rxr->xdp_rxq, bp->dev, i);
2305 if (rc < 0)
2306 return rc;
2307
Michael Chanc0c050c2015-10-22 16:01:17 -04002308 rc = bnxt_alloc_ring(bp, ring);
2309 if (rc)
2310 return rc;
2311
2312 if (agg_rings) {
2313 u16 mem_size;
2314
2315 ring = &rxr->rx_agg_ring_struct;
2316 rc = bnxt_alloc_ring(bp, ring);
2317 if (rc)
2318 return rc;
2319
Michael Chan9899bb52018-03-31 13:54:16 -04002320 ring->grp_idx = i;
Michael Chanc0c050c2015-10-22 16:01:17 -04002321 rxr->rx_agg_bmap_size = bp->rx_agg_ring_mask + 1;
2322 mem_size = rxr->rx_agg_bmap_size / 8;
2323 rxr->rx_agg_bmap = kzalloc(mem_size, GFP_KERNEL);
2324 if (!rxr->rx_agg_bmap)
2325 return -ENOMEM;
2326
2327 if (tpa_rings) {
2328 rxr->rx_tpa = kcalloc(MAX_TPA,
2329 sizeof(struct bnxt_tpa_info),
2330 GFP_KERNEL);
2331 if (!rxr->rx_tpa)
2332 return -ENOMEM;
2333 }
2334 }
2335 }
2336 return 0;
2337}
2338
2339static void bnxt_free_tx_rings(struct bnxt *bp)
2340{
2341 int i;
2342 struct pci_dev *pdev = bp->pdev;
2343
Michael Chanb6ab4b02016-01-02 23:44:59 -05002344 if (!bp->tx_ring)
Michael Chanc0c050c2015-10-22 16:01:17 -04002345 return;
2346
2347 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05002348 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04002349 struct bnxt_ring_struct *ring;
2350
Michael Chanc0c050c2015-10-22 16:01:17 -04002351 if (txr->tx_push) {
2352 dma_free_coherent(&pdev->dev, bp->tx_push_size,
2353 txr->tx_push, txr->tx_push_mapping);
2354 txr->tx_push = NULL;
2355 }
2356
2357 ring = &txr->tx_ring_struct;
2358
2359 bnxt_free_ring(bp, ring);
2360 }
2361}
2362
2363static int bnxt_alloc_tx_rings(struct bnxt *bp)
2364{
2365 int i, j, rc;
2366 struct pci_dev *pdev = bp->pdev;
2367
2368 bp->tx_push_size = 0;
2369 if (bp->tx_push_thresh) {
2370 int push_size;
2371
2372 push_size = L1_CACHE_ALIGN(sizeof(struct tx_push_bd) +
2373 bp->tx_push_thresh);
2374
Michael Chan4419dbe2016-02-10 17:33:49 -05002375 if (push_size > 256) {
Michael Chanc0c050c2015-10-22 16:01:17 -04002376 push_size = 0;
2377 bp->tx_push_thresh = 0;
2378 }
2379
2380 bp->tx_push_size = push_size;
2381 }
2382
2383 for (i = 0, j = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05002384 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04002385 struct bnxt_ring_struct *ring;
2386
Michael Chanc0c050c2015-10-22 16:01:17 -04002387 ring = &txr->tx_ring_struct;
2388
2389 rc = bnxt_alloc_ring(bp, ring);
2390 if (rc)
2391 return rc;
2392
Michael Chan9899bb52018-03-31 13:54:16 -04002393 ring->grp_idx = txr->bnapi->index;
Michael Chanc0c050c2015-10-22 16:01:17 -04002394 if (bp->tx_push_size) {
Michael Chanc0c050c2015-10-22 16:01:17 -04002395 dma_addr_t mapping;
2396
2397 /* One pre-allocated DMA buffer to backup
2398 * TX push operation
2399 */
2400 txr->tx_push = dma_alloc_coherent(&pdev->dev,
2401 bp->tx_push_size,
2402 &txr->tx_push_mapping,
2403 GFP_KERNEL);
2404
2405 if (!txr->tx_push)
2406 return -ENOMEM;
2407
Michael Chanc0c050c2015-10-22 16:01:17 -04002408 mapping = txr->tx_push_mapping +
2409 sizeof(struct tx_push_bd);
Michael Chan4419dbe2016-02-10 17:33:49 -05002410 txr->data_mapping = cpu_to_le64(mapping);
Michael Chanc0c050c2015-10-22 16:01:17 -04002411
Michael Chan4419dbe2016-02-10 17:33:49 -05002412 memset(txr->tx_push, 0, sizeof(struct tx_push_bd));
Michael Chanc0c050c2015-10-22 16:01:17 -04002413 }
2414 ring->queue_id = bp->q_info[j].queue_id;
Michael Chan5f449242017-02-06 16:55:40 -05002415 if (i < bp->tx_nr_rings_xdp)
2416 continue;
Michael Chanc0c050c2015-10-22 16:01:17 -04002417 if (i % bp->tx_nr_rings_per_tc == (bp->tx_nr_rings_per_tc - 1))
2418 j++;
2419 }
2420 return 0;
2421}
2422
2423static void bnxt_free_cp_rings(struct bnxt *bp)
2424{
2425 int i;
2426
2427 if (!bp->bnapi)
2428 return;
2429
2430 for (i = 0; i < bp->cp_nr_rings; i++) {
2431 struct bnxt_napi *bnapi = bp->bnapi[i];
2432 struct bnxt_cp_ring_info *cpr;
2433 struct bnxt_ring_struct *ring;
2434
2435 if (!bnapi)
2436 continue;
2437
2438 cpr = &bnapi->cp_ring;
2439 ring = &cpr->cp_ring_struct;
2440
2441 bnxt_free_ring(bp, ring);
2442 }
2443}
2444
2445static int bnxt_alloc_cp_rings(struct bnxt *bp)
2446{
Michael Chane5811b82018-03-31 13:54:18 -04002447 int i, rc, ulp_base_vec, ulp_msix;
Michael Chanc0c050c2015-10-22 16:01:17 -04002448
Michael Chane5811b82018-03-31 13:54:18 -04002449 ulp_msix = bnxt_get_ulp_msix_num(bp);
2450 ulp_base_vec = bnxt_get_ulp_msix_base(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04002451 for (i = 0; i < bp->cp_nr_rings; i++) {
2452 struct bnxt_napi *bnapi = bp->bnapi[i];
2453 struct bnxt_cp_ring_info *cpr;
2454 struct bnxt_ring_struct *ring;
2455
2456 if (!bnapi)
2457 continue;
2458
2459 cpr = &bnapi->cp_ring;
2460 ring = &cpr->cp_ring_struct;
2461
2462 rc = bnxt_alloc_ring(bp, ring);
2463 if (rc)
2464 return rc;
Michael Chane5811b82018-03-31 13:54:18 -04002465
2466 if (ulp_msix && i >= ulp_base_vec)
2467 ring->map_idx = i + ulp_msix;
2468 else
2469 ring->map_idx = i;
Michael Chanc0c050c2015-10-22 16:01:17 -04002470 }
2471 return 0;
2472}
2473
2474static void bnxt_init_ring_struct(struct bnxt *bp)
2475{
2476 int i;
2477
2478 for (i = 0; i < bp->cp_nr_rings; i++) {
2479 struct bnxt_napi *bnapi = bp->bnapi[i];
2480 struct bnxt_cp_ring_info *cpr;
2481 struct bnxt_rx_ring_info *rxr;
2482 struct bnxt_tx_ring_info *txr;
2483 struct bnxt_ring_struct *ring;
2484
2485 if (!bnapi)
2486 continue;
2487
2488 cpr = &bnapi->cp_ring;
2489 ring = &cpr->cp_ring_struct;
2490 ring->nr_pages = bp->cp_nr_pages;
2491 ring->page_size = HW_CMPD_RING_SIZE;
2492 ring->pg_arr = (void **)cpr->cp_desc_ring;
2493 ring->dma_arr = cpr->cp_desc_mapping;
2494 ring->vmem_size = 0;
2495
Michael Chanb6ab4b02016-01-02 23:44:59 -05002496 rxr = bnapi->rx_ring;
Michael Chan3b2b7d92016-01-02 23:45:00 -05002497 if (!rxr)
2498 goto skip_rx;
2499
Michael Chanc0c050c2015-10-22 16:01:17 -04002500 ring = &rxr->rx_ring_struct;
2501 ring->nr_pages = bp->rx_nr_pages;
2502 ring->page_size = HW_RXBD_RING_SIZE;
2503 ring->pg_arr = (void **)rxr->rx_desc_ring;
2504 ring->dma_arr = rxr->rx_desc_mapping;
2505 ring->vmem_size = SW_RXBD_RING_SIZE * bp->rx_nr_pages;
2506 ring->vmem = (void **)&rxr->rx_buf_ring;
2507
2508 ring = &rxr->rx_agg_ring_struct;
2509 ring->nr_pages = bp->rx_agg_nr_pages;
2510 ring->page_size = HW_RXBD_RING_SIZE;
2511 ring->pg_arr = (void **)rxr->rx_agg_desc_ring;
2512 ring->dma_arr = rxr->rx_agg_desc_mapping;
2513 ring->vmem_size = SW_RXBD_AGG_RING_SIZE * bp->rx_agg_nr_pages;
2514 ring->vmem = (void **)&rxr->rx_agg_ring;
2515
Michael Chan3b2b7d92016-01-02 23:45:00 -05002516skip_rx:
Michael Chanb6ab4b02016-01-02 23:44:59 -05002517 txr = bnapi->tx_ring;
Michael Chan3b2b7d92016-01-02 23:45:00 -05002518 if (!txr)
2519 continue;
2520
Michael Chanc0c050c2015-10-22 16:01:17 -04002521 ring = &txr->tx_ring_struct;
2522 ring->nr_pages = bp->tx_nr_pages;
2523 ring->page_size = HW_RXBD_RING_SIZE;
2524 ring->pg_arr = (void **)txr->tx_desc_ring;
2525 ring->dma_arr = txr->tx_desc_mapping;
2526 ring->vmem_size = SW_TXBD_RING_SIZE * bp->tx_nr_pages;
2527 ring->vmem = (void **)&txr->tx_buf_ring;
2528 }
2529}
2530
2531static void bnxt_init_rxbd_pages(struct bnxt_ring_struct *ring, u32 type)
2532{
2533 int i;
2534 u32 prod;
2535 struct rx_bd **rx_buf_ring;
2536
2537 rx_buf_ring = (struct rx_bd **)ring->pg_arr;
2538 for (i = 0, prod = 0; i < ring->nr_pages; i++) {
2539 int j;
2540 struct rx_bd *rxbd;
2541
2542 rxbd = rx_buf_ring[i];
2543 if (!rxbd)
2544 continue;
2545
2546 for (j = 0; j < RX_DESC_CNT; j++, rxbd++, prod++) {
2547 rxbd->rx_bd_len_flags_type = cpu_to_le32(type);
2548 rxbd->rx_bd_opaque = prod;
2549 }
2550 }
2551}
2552
2553static int bnxt_init_one_rx_ring(struct bnxt *bp, int ring_nr)
2554{
2555 struct net_device *dev = bp->dev;
Michael Chanc0c050c2015-10-22 16:01:17 -04002556 struct bnxt_rx_ring_info *rxr;
2557 struct bnxt_ring_struct *ring;
2558 u32 prod, type;
2559 int i;
2560
Michael Chanc0c050c2015-10-22 16:01:17 -04002561 type = (bp->rx_buf_use_size << RX_BD_LEN_SHIFT) |
2562 RX_BD_TYPE_RX_PACKET_BD | RX_BD_FLAGS_EOP;
2563
2564 if (NET_IP_ALIGN == 2)
2565 type |= RX_BD_FLAGS_SOP;
2566
Michael Chanb6ab4b02016-01-02 23:44:59 -05002567 rxr = &bp->rx_ring[ring_nr];
Michael Chanc0c050c2015-10-22 16:01:17 -04002568 ring = &rxr->rx_ring_struct;
2569 bnxt_init_rxbd_pages(ring, type);
2570
Michael Chanc6d30e82017-02-06 16:55:42 -05002571 if (BNXT_RX_PAGE_MODE(bp) && bp->xdp_prog) {
2572 rxr->xdp_prog = bpf_prog_add(bp->xdp_prog, 1);
2573 if (IS_ERR(rxr->xdp_prog)) {
2574 int rc = PTR_ERR(rxr->xdp_prog);
2575
2576 rxr->xdp_prog = NULL;
2577 return rc;
2578 }
2579 }
Michael Chanc0c050c2015-10-22 16:01:17 -04002580 prod = rxr->rx_prod;
2581 for (i = 0; i < bp->rx_ring_size; i++) {
2582 if (bnxt_alloc_rx_data(bp, rxr, prod, GFP_KERNEL) != 0) {
2583 netdev_warn(dev, "init'ed rx ring %d with %d/%d skbs only\n",
2584 ring_nr, i, bp->rx_ring_size);
2585 break;
2586 }
2587 prod = NEXT_RX(prod);
2588 }
2589 rxr->rx_prod = prod;
2590 ring->fw_ring_id = INVALID_HW_RING_ID;
2591
Michael Chanedd0c2c2015-12-27 18:19:19 -05002592 ring = &rxr->rx_agg_ring_struct;
2593 ring->fw_ring_id = INVALID_HW_RING_ID;
2594
Michael Chanc0c050c2015-10-22 16:01:17 -04002595 if (!(bp->flags & BNXT_FLAG_AGG_RINGS))
2596 return 0;
2597
Michael Chan2839f282016-04-25 02:30:50 -04002598 type = ((u32)BNXT_RX_PAGE_SIZE << RX_BD_LEN_SHIFT) |
Michael Chanc0c050c2015-10-22 16:01:17 -04002599 RX_BD_TYPE_RX_AGG_BD | RX_BD_FLAGS_SOP;
2600
2601 bnxt_init_rxbd_pages(ring, type);
2602
2603 prod = rxr->rx_agg_prod;
2604 for (i = 0; i < bp->rx_agg_ring_size; i++) {
2605 if (bnxt_alloc_rx_page(bp, rxr, prod, GFP_KERNEL) != 0) {
2606 netdev_warn(dev, "init'ed rx ring %d with %d/%d pages only\n",
2607 ring_nr, i, bp->rx_ring_size);
2608 break;
2609 }
2610 prod = NEXT_RX_AGG(prod);
2611 }
2612 rxr->rx_agg_prod = prod;
Michael Chanc0c050c2015-10-22 16:01:17 -04002613
2614 if (bp->flags & BNXT_FLAG_TPA) {
2615 if (rxr->rx_tpa) {
2616 u8 *data;
2617 dma_addr_t mapping;
2618
2619 for (i = 0; i < MAX_TPA; i++) {
2620 data = __bnxt_alloc_rx_data(bp, &mapping,
2621 GFP_KERNEL);
2622 if (!data)
2623 return -ENOMEM;
2624
2625 rxr->rx_tpa[i].data = data;
Michael Chanb3dba772017-02-06 16:55:35 -05002626 rxr->rx_tpa[i].data_ptr = data + bp->rx_offset;
Michael Chanc0c050c2015-10-22 16:01:17 -04002627 rxr->rx_tpa[i].mapping = mapping;
2628 }
2629 } else {
2630 netdev_err(bp->dev, "No resource allocated for LRO/GRO\n");
2631 return -ENOMEM;
2632 }
2633 }
2634
2635 return 0;
2636}
2637
Sankar Patchineelam22479252017-03-28 19:47:29 -04002638static void bnxt_init_cp_rings(struct bnxt *bp)
2639{
2640 int i;
2641
2642 for (i = 0; i < bp->cp_nr_rings; i++) {
2643 struct bnxt_cp_ring_info *cpr = &bp->bnapi[i]->cp_ring;
2644 struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
2645
2646 ring->fw_ring_id = INVALID_HW_RING_ID;
Andy Gospodarek6a8788f2018-01-09 16:06:20 -05002647 cpr->rx_ring_coal.coal_ticks = bp->rx_coal.coal_ticks;
2648 cpr->rx_ring_coal.coal_bufs = bp->rx_coal.coal_bufs;
Sankar Patchineelam22479252017-03-28 19:47:29 -04002649 }
2650}
2651
Michael Chanc0c050c2015-10-22 16:01:17 -04002652static int bnxt_init_rx_rings(struct bnxt *bp)
2653{
2654 int i, rc = 0;
2655
Michael Chanc61fb992017-02-06 16:55:36 -05002656 if (BNXT_RX_PAGE_MODE(bp)) {
Michael Chanc6d30e82017-02-06 16:55:42 -05002657 bp->rx_offset = NET_IP_ALIGN + XDP_PACKET_HEADROOM;
2658 bp->rx_dma_offset = XDP_PACKET_HEADROOM;
Michael Chanc61fb992017-02-06 16:55:36 -05002659 } else {
2660 bp->rx_offset = BNXT_RX_OFFSET;
2661 bp->rx_dma_offset = BNXT_RX_DMA_OFFSET;
2662 }
Michael Chanb3dba772017-02-06 16:55:35 -05002663
Michael Chanc0c050c2015-10-22 16:01:17 -04002664 for (i = 0; i < bp->rx_nr_rings; i++) {
2665 rc = bnxt_init_one_rx_ring(bp, i);
2666 if (rc)
2667 break;
2668 }
2669
2670 return rc;
2671}
2672
2673static int bnxt_init_tx_rings(struct bnxt *bp)
2674{
2675 u16 i;
2676
2677 bp->tx_wake_thresh = max_t(int, bp->tx_ring_size / 2,
2678 MAX_SKB_FRAGS + 1);
2679
2680 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05002681 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04002682 struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
2683
2684 ring->fw_ring_id = INVALID_HW_RING_ID;
2685 }
2686
2687 return 0;
2688}
2689
2690static void bnxt_free_ring_grps(struct bnxt *bp)
2691{
2692 kfree(bp->grp_info);
2693 bp->grp_info = NULL;
2694}
2695
2696static int bnxt_init_ring_grps(struct bnxt *bp, bool irq_re_init)
2697{
2698 int i;
2699
2700 if (irq_re_init) {
2701 bp->grp_info = kcalloc(bp->cp_nr_rings,
2702 sizeof(struct bnxt_ring_grp_info),
2703 GFP_KERNEL);
2704 if (!bp->grp_info)
2705 return -ENOMEM;
2706 }
2707 for (i = 0; i < bp->cp_nr_rings; i++) {
2708 if (irq_re_init)
2709 bp->grp_info[i].fw_stats_ctx = INVALID_HW_RING_ID;
2710 bp->grp_info[i].fw_grp_id = INVALID_HW_RING_ID;
2711 bp->grp_info[i].rx_fw_ring_id = INVALID_HW_RING_ID;
2712 bp->grp_info[i].agg_fw_ring_id = INVALID_HW_RING_ID;
2713 bp->grp_info[i].cp_fw_ring_id = INVALID_HW_RING_ID;
2714 }
2715 return 0;
2716}
2717
2718static void bnxt_free_vnics(struct bnxt *bp)
2719{
2720 kfree(bp->vnic_info);
2721 bp->vnic_info = NULL;
2722 bp->nr_vnics = 0;
2723}
2724
2725static int bnxt_alloc_vnics(struct bnxt *bp)
2726{
2727 int num_vnics = 1;
2728
2729#ifdef CONFIG_RFS_ACCEL
2730 if (bp->flags & BNXT_FLAG_RFS)
2731 num_vnics += bp->rx_nr_rings;
2732#endif
2733
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04002734 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
2735 num_vnics++;
2736
Michael Chanc0c050c2015-10-22 16:01:17 -04002737 bp->vnic_info = kcalloc(num_vnics, sizeof(struct bnxt_vnic_info),
2738 GFP_KERNEL);
2739 if (!bp->vnic_info)
2740 return -ENOMEM;
2741
2742 bp->nr_vnics = num_vnics;
2743 return 0;
2744}
2745
2746static void bnxt_init_vnics(struct bnxt *bp)
2747{
2748 int i;
2749
2750 for (i = 0; i < bp->nr_vnics; i++) {
2751 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
2752
2753 vnic->fw_vnic_id = INVALID_HW_RING_ID;
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04002754 vnic->fw_rss_cos_lb_ctx[0] = INVALID_HW_RING_ID;
2755 vnic->fw_rss_cos_lb_ctx[1] = INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04002756 vnic->fw_l2_ctx_id = INVALID_HW_RING_ID;
2757
2758 if (bp->vnic_info[i].rss_hash_key) {
2759 if (i == 0)
2760 prandom_bytes(vnic->rss_hash_key,
2761 HW_HASH_KEY_SIZE);
2762 else
2763 memcpy(vnic->rss_hash_key,
2764 bp->vnic_info[0].rss_hash_key,
2765 HW_HASH_KEY_SIZE);
2766 }
2767 }
2768}
2769
2770static int bnxt_calc_nr_ring_pages(u32 ring_size, int desc_per_pg)
2771{
2772 int pages;
2773
2774 pages = ring_size / desc_per_pg;
2775
2776 if (!pages)
2777 return 1;
2778
2779 pages++;
2780
2781 while (pages & (pages - 1))
2782 pages++;
2783
2784 return pages;
2785}
2786
Michael Chanc6d30e82017-02-06 16:55:42 -05002787void bnxt_set_tpa_flags(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04002788{
2789 bp->flags &= ~BNXT_FLAG_TPA;
Michael Chan341138c2017-01-13 01:32:01 -05002790 if (bp->flags & BNXT_FLAG_NO_AGG_RINGS)
2791 return;
Michael Chanc0c050c2015-10-22 16:01:17 -04002792 if (bp->dev->features & NETIF_F_LRO)
2793 bp->flags |= BNXT_FLAG_LRO;
Michael Chan1054aee2017-12-16 03:09:42 -05002794 else if (bp->dev->features & NETIF_F_GRO_HW)
Michael Chanc0c050c2015-10-22 16:01:17 -04002795 bp->flags |= BNXT_FLAG_GRO;
2796}
2797
2798/* bp->rx_ring_size, bp->tx_ring_size, dev->mtu, BNXT_FLAG_{G|L}RO flags must
2799 * be set on entry.
2800 */
2801void bnxt_set_ring_params(struct bnxt *bp)
2802{
2803 u32 ring_size, rx_size, rx_space;
2804 u32 agg_factor = 0, agg_ring_size = 0;
2805
2806 /* 8 for CRC and VLAN */
2807 rx_size = SKB_DATA_ALIGN(bp->dev->mtu + ETH_HLEN + NET_IP_ALIGN + 8);
2808
2809 rx_space = rx_size + NET_SKB_PAD +
2810 SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
2811
2812 bp->rx_copy_thresh = BNXT_RX_COPY_THRESH;
2813 ring_size = bp->rx_ring_size;
2814 bp->rx_agg_ring_size = 0;
2815 bp->rx_agg_nr_pages = 0;
2816
2817 if (bp->flags & BNXT_FLAG_TPA)
Michael Chan2839f282016-04-25 02:30:50 -04002818 agg_factor = min_t(u32, 4, 65536 / BNXT_RX_PAGE_SIZE);
Michael Chanc0c050c2015-10-22 16:01:17 -04002819
2820 bp->flags &= ~BNXT_FLAG_JUMBO;
Michael Chanbdbd1eb2016-12-29 12:13:43 -05002821 if (rx_space > PAGE_SIZE && !(bp->flags & BNXT_FLAG_NO_AGG_RINGS)) {
Michael Chanc0c050c2015-10-22 16:01:17 -04002822 u32 jumbo_factor;
2823
2824 bp->flags |= BNXT_FLAG_JUMBO;
2825 jumbo_factor = PAGE_ALIGN(bp->dev->mtu - 40) >> PAGE_SHIFT;
2826 if (jumbo_factor > agg_factor)
2827 agg_factor = jumbo_factor;
2828 }
2829 agg_ring_size = ring_size * agg_factor;
2830
2831 if (agg_ring_size) {
2832 bp->rx_agg_nr_pages = bnxt_calc_nr_ring_pages(agg_ring_size,
2833 RX_DESC_CNT);
2834 if (bp->rx_agg_nr_pages > MAX_RX_AGG_PAGES) {
2835 u32 tmp = agg_ring_size;
2836
2837 bp->rx_agg_nr_pages = MAX_RX_AGG_PAGES;
2838 agg_ring_size = MAX_RX_AGG_PAGES * RX_DESC_CNT - 1;
2839 netdev_warn(bp->dev, "rx agg ring size %d reduced to %d.\n",
2840 tmp, agg_ring_size);
2841 }
2842 bp->rx_agg_ring_size = agg_ring_size;
2843 bp->rx_agg_ring_mask = (bp->rx_agg_nr_pages * RX_DESC_CNT) - 1;
2844 rx_size = SKB_DATA_ALIGN(BNXT_RX_COPY_THRESH + NET_IP_ALIGN);
2845 rx_space = rx_size + NET_SKB_PAD +
2846 SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
2847 }
2848
2849 bp->rx_buf_use_size = rx_size;
2850 bp->rx_buf_size = rx_space;
2851
2852 bp->rx_nr_pages = bnxt_calc_nr_ring_pages(ring_size, RX_DESC_CNT);
2853 bp->rx_ring_mask = (bp->rx_nr_pages * RX_DESC_CNT) - 1;
2854
2855 ring_size = bp->tx_ring_size;
2856 bp->tx_nr_pages = bnxt_calc_nr_ring_pages(ring_size, TX_DESC_CNT);
2857 bp->tx_ring_mask = (bp->tx_nr_pages * TX_DESC_CNT) - 1;
2858
2859 ring_size = bp->rx_ring_size * (2 + agg_factor) + bp->tx_ring_size;
2860 bp->cp_ring_size = ring_size;
2861
2862 bp->cp_nr_pages = bnxt_calc_nr_ring_pages(ring_size, CP_DESC_CNT);
2863 if (bp->cp_nr_pages > MAX_CP_PAGES) {
2864 bp->cp_nr_pages = MAX_CP_PAGES;
2865 bp->cp_ring_size = MAX_CP_PAGES * CP_DESC_CNT - 1;
2866 netdev_warn(bp->dev, "completion ring size %d reduced to %d.\n",
2867 ring_size, bp->cp_ring_size);
2868 }
2869 bp->cp_bit = bp->cp_nr_pages * CP_DESC_CNT;
2870 bp->cp_ring_mask = bp->cp_bit - 1;
2871}
2872
Jesper Dangaard Brouer96a86042018-01-03 11:25:44 +01002873/* Changing allocation mode of RX rings.
2874 * TODO: Update when extending xdp_rxq_info to support allocation modes.
2875 */
Michael Chanc61fb992017-02-06 16:55:36 -05002876int bnxt_set_rx_skb_mode(struct bnxt *bp, bool page_mode)
Michael Chan6bb19472017-02-06 16:55:32 -05002877{
Michael Chanc61fb992017-02-06 16:55:36 -05002878 if (page_mode) {
2879 if (bp->dev->mtu > BNXT_MAX_PAGE_MODE_MTU)
2880 return -EOPNOTSUPP;
Michael Chan7eb9bb32017-10-26 11:51:25 -04002881 bp->dev->max_mtu =
2882 min_t(u16, bp->max_mtu, BNXT_MAX_PAGE_MODE_MTU);
Michael Chanc61fb992017-02-06 16:55:36 -05002883 bp->flags &= ~BNXT_FLAG_AGG_RINGS;
2884 bp->flags |= BNXT_FLAG_NO_AGG_RINGS | BNXT_FLAG_RX_PAGE_MODE;
Michael Chanc61fb992017-02-06 16:55:36 -05002885 bp->rx_dir = DMA_BIDIRECTIONAL;
2886 bp->rx_skb_func = bnxt_rx_page_skb;
Michael Chan1054aee2017-12-16 03:09:42 -05002887 /* Disable LRO or GRO_HW */
2888 netdev_update_features(bp->dev);
Michael Chanc61fb992017-02-06 16:55:36 -05002889 } else {
Michael Chan7eb9bb32017-10-26 11:51:25 -04002890 bp->dev->max_mtu = bp->max_mtu;
Michael Chanc61fb992017-02-06 16:55:36 -05002891 bp->flags &= ~BNXT_FLAG_RX_PAGE_MODE;
2892 bp->rx_dir = DMA_FROM_DEVICE;
2893 bp->rx_skb_func = bnxt_rx_skb;
2894 }
Michael Chan6bb19472017-02-06 16:55:32 -05002895 return 0;
2896}
2897
Michael Chanc0c050c2015-10-22 16:01:17 -04002898static void bnxt_free_vnic_attributes(struct bnxt *bp)
2899{
2900 int i;
2901 struct bnxt_vnic_info *vnic;
2902 struct pci_dev *pdev = bp->pdev;
2903
2904 if (!bp->vnic_info)
2905 return;
2906
2907 for (i = 0; i < bp->nr_vnics; i++) {
2908 vnic = &bp->vnic_info[i];
2909
2910 kfree(vnic->fw_grp_ids);
2911 vnic->fw_grp_ids = NULL;
2912
2913 kfree(vnic->uc_list);
2914 vnic->uc_list = NULL;
2915
2916 if (vnic->mc_list) {
2917 dma_free_coherent(&pdev->dev, vnic->mc_list_size,
2918 vnic->mc_list, vnic->mc_list_mapping);
2919 vnic->mc_list = NULL;
2920 }
2921
2922 if (vnic->rss_table) {
2923 dma_free_coherent(&pdev->dev, PAGE_SIZE,
2924 vnic->rss_table,
2925 vnic->rss_table_dma_addr);
2926 vnic->rss_table = NULL;
2927 }
2928
2929 vnic->rss_hash_key = NULL;
2930 vnic->flags = 0;
2931 }
2932}
2933
2934static int bnxt_alloc_vnic_attributes(struct bnxt *bp)
2935{
2936 int i, rc = 0, size;
2937 struct bnxt_vnic_info *vnic;
2938 struct pci_dev *pdev = bp->pdev;
2939 int max_rings;
2940
2941 for (i = 0; i < bp->nr_vnics; i++) {
2942 vnic = &bp->vnic_info[i];
2943
2944 if (vnic->flags & BNXT_VNIC_UCAST_FLAG) {
2945 int mem_size = (BNXT_MAX_UC_ADDRS - 1) * ETH_ALEN;
2946
2947 if (mem_size > 0) {
2948 vnic->uc_list = kmalloc(mem_size, GFP_KERNEL);
2949 if (!vnic->uc_list) {
2950 rc = -ENOMEM;
2951 goto out;
2952 }
2953 }
2954 }
2955
2956 if (vnic->flags & BNXT_VNIC_MCAST_FLAG) {
2957 vnic->mc_list_size = BNXT_MAX_MC_ADDRS * ETH_ALEN;
2958 vnic->mc_list =
2959 dma_alloc_coherent(&pdev->dev,
2960 vnic->mc_list_size,
2961 &vnic->mc_list_mapping,
2962 GFP_KERNEL);
2963 if (!vnic->mc_list) {
2964 rc = -ENOMEM;
2965 goto out;
2966 }
2967 }
2968
2969 if (vnic->flags & BNXT_VNIC_RSS_FLAG)
2970 max_rings = bp->rx_nr_rings;
2971 else
2972 max_rings = 1;
2973
2974 vnic->fw_grp_ids = kcalloc(max_rings, sizeof(u16), GFP_KERNEL);
2975 if (!vnic->fw_grp_ids) {
2976 rc = -ENOMEM;
2977 goto out;
2978 }
2979
Michael Chanae10ae72016-12-29 12:13:38 -05002980 if ((bp->flags & BNXT_FLAG_NEW_RSS_CAP) &&
2981 !(vnic->flags & BNXT_VNIC_RSS_FLAG))
2982 continue;
2983
Michael Chanc0c050c2015-10-22 16:01:17 -04002984 /* Allocate rss table and hash key */
2985 vnic->rss_table = dma_alloc_coherent(&pdev->dev, PAGE_SIZE,
2986 &vnic->rss_table_dma_addr,
2987 GFP_KERNEL);
2988 if (!vnic->rss_table) {
2989 rc = -ENOMEM;
2990 goto out;
2991 }
2992
2993 size = L1_CACHE_ALIGN(HW_HASH_INDEX_SIZE * sizeof(u16));
2994
2995 vnic->rss_hash_key = ((void *)vnic->rss_table) + size;
2996 vnic->rss_hash_key_dma_addr = vnic->rss_table_dma_addr + size;
2997 }
2998 return 0;
2999
3000out:
3001 return rc;
3002}
3003
3004static void bnxt_free_hwrm_resources(struct bnxt *bp)
3005{
3006 struct pci_dev *pdev = bp->pdev;
3007
3008 dma_free_coherent(&pdev->dev, PAGE_SIZE, bp->hwrm_cmd_resp_addr,
3009 bp->hwrm_cmd_resp_dma_addr);
3010
3011 bp->hwrm_cmd_resp_addr = NULL;
3012 if (bp->hwrm_dbg_resp_addr) {
3013 dma_free_coherent(&pdev->dev, HWRM_DBG_REG_BUF_SIZE,
3014 bp->hwrm_dbg_resp_addr,
3015 bp->hwrm_dbg_resp_dma_addr);
3016
3017 bp->hwrm_dbg_resp_addr = NULL;
3018 }
3019}
3020
3021static int bnxt_alloc_hwrm_resources(struct bnxt *bp)
3022{
3023 struct pci_dev *pdev = bp->pdev;
3024
3025 bp->hwrm_cmd_resp_addr = dma_alloc_coherent(&pdev->dev, PAGE_SIZE,
3026 &bp->hwrm_cmd_resp_dma_addr,
3027 GFP_KERNEL);
3028 if (!bp->hwrm_cmd_resp_addr)
3029 return -ENOMEM;
3030 bp->hwrm_dbg_resp_addr = dma_alloc_coherent(&pdev->dev,
3031 HWRM_DBG_REG_BUF_SIZE,
3032 &bp->hwrm_dbg_resp_dma_addr,
3033 GFP_KERNEL);
3034 if (!bp->hwrm_dbg_resp_addr)
3035 netdev_warn(bp->dev, "fail to alloc debug register dma mem\n");
3036
3037 return 0;
3038}
3039
Deepak Khungare605db82017-05-29 19:06:04 -04003040static void bnxt_free_hwrm_short_cmd_req(struct bnxt *bp)
3041{
3042 if (bp->hwrm_short_cmd_req_addr) {
3043 struct pci_dev *pdev = bp->pdev;
3044
3045 dma_free_coherent(&pdev->dev, BNXT_HWRM_MAX_REQ_LEN,
3046 bp->hwrm_short_cmd_req_addr,
3047 bp->hwrm_short_cmd_req_dma_addr);
3048 bp->hwrm_short_cmd_req_addr = NULL;
3049 }
3050}
3051
3052static int bnxt_alloc_hwrm_short_cmd_req(struct bnxt *bp)
3053{
3054 struct pci_dev *pdev = bp->pdev;
3055
3056 bp->hwrm_short_cmd_req_addr =
3057 dma_alloc_coherent(&pdev->dev, BNXT_HWRM_MAX_REQ_LEN,
3058 &bp->hwrm_short_cmd_req_dma_addr,
3059 GFP_KERNEL);
3060 if (!bp->hwrm_short_cmd_req_addr)
3061 return -ENOMEM;
3062
3063 return 0;
3064}
3065
Michael Chanc0c050c2015-10-22 16:01:17 -04003066static void bnxt_free_stats(struct bnxt *bp)
3067{
3068 u32 size, i;
3069 struct pci_dev *pdev = bp->pdev;
3070
Vasundhara Volam00db3cb2018-03-31 13:54:12 -04003071 bp->flags &= ~BNXT_FLAG_PORT_STATS;
3072 bp->flags &= ~BNXT_FLAG_PORT_STATS_EXT;
3073
Michael Chan3bdf56c2016-03-07 15:38:45 -05003074 if (bp->hw_rx_port_stats) {
3075 dma_free_coherent(&pdev->dev, bp->hw_port_stats_size,
3076 bp->hw_rx_port_stats,
3077 bp->hw_rx_port_stats_map);
3078 bp->hw_rx_port_stats = NULL;
Vasundhara Volam00db3cb2018-03-31 13:54:12 -04003079 }
3080
3081 if (bp->hw_rx_port_stats_ext) {
3082 dma_free_coherent(&pdev->dev, sizeof(struct rx_port_stats_ext),
3083 bp->hw_rx_port_stats_ext,
3084 bp->hw_rx_port_stats_ext_map);
3085 bp->hw_rx_port_stats_ext = NULL;
Michael Chan3bdf56c2016-03-07 15:38:45 -05003086 }
3087
Michael Chanc0c050c2015-10-22 16:01:17 -04003088 if (!bp->bnapi)
3089 return;
3090
3091 size = sizeof(struct ctx_hw_stats);
3092
3093 for (i = 0; i < bp->cp_nr_rings; i++) {
3094 struct bnxt_napi *bnapi = bp->bnapi[i];
3095 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
3096
3097 if (cpr->hw_stats) {
3098 dma_free_coherent(&pdev->dev, size, cpr->hw_stats,
3099 cpr->hw_stats_map);
3100 cpr->hw_stats = NULL;
3101 }
3102 }
3103}
3104
3105static int bnxt_alloc_stats(struct bnxt *bp)
3106{
3107 u32 size, i;
3108 struct pci_dev *pdev = bp->pdev;
3109
3110 size = sizeof(struct ctx_hw_stats);
3111
3112 for (i = 0; i < bp->cp_nr_rings; i++) {
3113 struct bnxt_napi *bnapi = bp->bnapi[i];
3114 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
3115
3116 cpr->hw_stats = dma_alloc_coherent(&pdev->dev, size,
3117 &cpr->hw_stats_map,
3118 GFP_KERNEL);
3119 if (!cpr->hw_stats)
3120 return -ENOMEM;
3121
3122 cpr->hw_stats_ctx_id = INVALID_STATS_CTX_ID;
3123 }
Michael Chan3bdf56c2016-03-07 15:38:45 -05003124
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04003125 if (BNXT_PF(bp) && bp->chip_num != CHIP_NUM_58700) {
Michael Chan3bdf56c2016-03-07 15:38:45 -05003126 bp->hw_port_stats_size = sizeof(struct rx_port_stats) +
3127 sizeof(struct tx_port_stats) + 1024;
3128
3129 bp->hw_rx_port_stats =
3130 dma_alloc_coherent(&pdev->dev, bp->hw_port_stats_size,
3131 &bp->hw_rx_port_stats_map,
3132 GFP_KERNEL);
3133 if (!bp->hw_rx_port_stats)
3134 return -ENOMEM;
3135
3136 bp->hw_tx_port_stats = (void *)(bp->hw_rx_port_stats + 1) +
3137 512;
3138 bp->hw_tx_port_stats_map = bp->hw_rx_port_stats_map +
3139 sizeof(struct rx_port_stats) + 512;
3140 bp->flags |= BNXT_FLAG_PORT_STATS;
Vasundhara Volam00db3cb2018-03-31 13:54:12 -04003141
3142 /* Display extended statistics only if FW supports it */
3143 if (bp->hwrm_spec_code < 0x10804 ||
3144 bp->hwrm_spec_code == 0x10900)
3145 return 0;
3146
3147 bp->hw_rx_port_stats_ext =
3148 dma_zalloc_coherent(&pdev->dev,
3149 sizeof(struct rx_port_stats_ext),
3150 &bp->hw_rx_port_stats_ext_map,
3151 GFP_KERNEL);
3152 if (!bp->hw_rx_port_stats_ext)
3153 return 0;
3154
3155 bp->flags |= BNXT_FLAG_PORT_STATS_EXT;
Michael Chan3bdf56c2016-03-07 15:38:45 -05003156 }
Michael Chanc0c050c2015-10-22 16:01:17 -04003157 return 0;
3158}
3159
3160static void bnxt_clear_ring_indices(struct bnxt *bp)
3161{
3162 int i;
3163
3164 if (!bp->bnapi)
3165 return;
3166
3167 for (i = 0; i < bp->cp_nr_rings; i++) {
3168 struct bnxt_napi *bnapi = bp->bnapi[i];
3169 struct bnxt_cp_ring_info *cpr;
3170 struct bnxt_rx_ring_info *rxr;
3171 struct bnxt_tx_ring_info *txr;
3172
3173 if (!bnapi)
3174 continue;
3175
3176 cpr = &bnapi->cp_ring;
3177 cpr->cp_raw_cons = 0;
3178
Michael Chanb6ab4b02016-01-02 23:44:59 -05003179 txr = bnapi->tx_ring;
Michael Chan3b2b7d92016-01-02 23:45:00 -05003180 if (txr) {
3181 txr->tx_prod = 0;
3182 txr->tx_cons = 0;
3183 }
Michael Chanc0c050c2015-10-22 16:01:17 -04003184
Michael Chanb6ab4b02016-01-02 23:44:59 -05003185 rxr = bnapi->rx_ring;
Michael Chan3b2b7d92016-01-02 23:45:00 -05003186 if (rxr) {
3187 rxr->rx_prod = 0;
3188 rxr->rx_agg_prod = 0;
3189 rxr->rx_sw_agg_prod = 0;
Michael Chan376a5b82016-05-10 19:17:59 -04003190 rxr->rx_next_cons = 0;
Michael Chan3b2b7d92016-01-02 23:45:00 -05003191 }
Michael Chanc0c050c2015-10-22 16:01:17 -04003192 }
3193}
3194
3195static void bnxt_free_ntp_fltrs(struct bnxt *bp, bool irq_reinit)
3196{
3197#ifdef CONFIG_RFS_ACCEL
3198 int i;
3199
3200 /* Under rtnl_lock and all our NAPIs have been disabled. It's
3201 * safe to delete the hash table.
3202 */
3203 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
3204 struct hlist_head *head;
3205 struct hlist_node *tmp;
3206 struct bnxt_ntuple_filter *fltr;
3207
3208 head = &bp->ntp_fltr_hash_tbl[i];
3209 hlist_for_each_entry_safe(fltr, tmp, head, hash) {
3210 hlist_del(&fltr->hash);
3211 kfree(fltr);
3212 }
3213 }
3214 if (irq_reinit) {
3215 kfree(bp->ntp_fltr_bmap);
3216 bp->ntp_fltr_bmap = NULL;
3217 }
3218 bp->ntp_fltr_count = 0;
3219#endif
3220}
3221
3222static int bnxt_alloc_ntp_fltrs(struct bnxt *bp)
3223{
3224#ifdef CONFIG_RFS_ACCEL
3225 int i, rc = 0;
3226
3227 if (!(bp->flags & BNXT_FLAG_RFS))
3228 return 0;
3229
3230 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++)
3231 INIT_HLIST_HEAD(&bp->ntp_fltr_hash_tbl[i]);
3232
3233 bp->ntp_fltr_count = 0;
Dan Carpenterac45bd92017-05-06 03:49:01 +03003234 bp->ntp_fltr_bmap = kcalloc(BITS_TO_LONGS(BNXT_NTP_FLTR_MAX_FLTR),
3235 sizeof(long),
Michael Chanc0c050c2015-10-22 16:01:17 -04003236 GFP_KERNEL);
3237
3238 if (!bp->ntp_fltr_bmap)
3239 rc = -ENOMEM;
3240
3241 return rc;
3242#else
3243 return 0;
3244#endif
3245}
3246
3247static void bnxt_free_mem(struct bnxt *bp, bool irq_re_init)
3248{
3249 bnxt_free_vnic_attributes(bp);
3250 bnxt_free_tx_rings(bp);
3251 bnxt_free_rx_rings(bp);
3252 bnxt_free_cp_rings(bp);
3253 bnxt_free_ntp_fltrs(bp, irq_re_init);
3254 if (irq_re_init) {
3255 bnxt_free_stats(bp);
3256 bnxt_free_ring_grps(bp);
3257 bnxt_free_vnics(bp);
Michael Chana960dec2017-02-06 16:55:39 -05003258 kfree(bp->tx_ring_map);
3259 bp->tx_ring_map = NULL;
Michael Chanb6ab4b02016-01-02 23:44:59 -05003260 kfree(bp->tx_ring);
3261 bp->tx_ring = NULL;
3262 kfree(bp->rx_ring);
3263 bp->rx_ring = NULL;
Michael Chanc0c050c2015-10-22 16:01:17 -04003264 kfree(bp->bnapi);
3265 bp->bnapi = NULL;
3266 } else {
3267 bnxt_clear_ring_indices(bp);
3268 }
3269}
3270
3271static int bnxt_alloc_mem(struct bnxt *bp, bool irq_re_init)
3272{
Michael Chan01657bc2016-01-02 23:45:03 -05003273 int i, j, rc, size, arr_size;
Michael Chanc0c050c2015-10-22 16:01:17 -04003274 void *bnapi;
3275
3276 if (irq_re_init) {
3277 /* Allocate bnapi mem pointer array and mem block for
3278 * all queues
3279 */
3280 arr_size = L1_CACHE_ALIGN(sizeof(struct bnxt_napi *) *
3281 bp->cp_nr_rings);
3282 size = L1_CACHE_ALIGN(sizeof(struct bnxt_napi));
3283 bnapi = kzalloc(arr_size + size * bp->cp_nr_rings, GFP_KERNEL);
3284 if (!bnapi)
3285 return -ENOMEM;
3286
3287 bp->bnapi = bnapi;
3288 bnapi += arr_size;
3289 for (i = 0; i < bp->cp_nr_rings; i++, bnapi += size) {
3290 bp->bnapi[i] = bnapi;
3291 bp->bnapi[i]->index = i;
3292 bp->bnapi[i]->bp = bp;
3293 }
3294
Michael Chanb6ab4b02016-01-02 23:44:59 -05003295 bp->rx_ring = kcalloc(bp->rx_nr_rings,
3296 sizeof(struct bnxt_rx_ring_info),
3297 GFP_KERNEL);
3298 if (!bp->rx_ring)
3299 return -ENOMEM;
3300
3301 for (i = 0; i < bp->rx_nr_rings; i++) {
3302 bp->rx_ring[i].bnapi = bp->bnapi[i];
3303 bp->bnapi[i]->rx_ring = &bp->rx_ring[i];
3304 }
3305
3306 bp->tx_ring = kcalloc(bp->tx_nr_rings,
3307 sizeof(struct bnxt_tx_ring_info),
3308 GFP_KERNEL);
3309 if (!bp->tx_ring)
3310 return -ENOMEM;
3311
Michael Chana960dec2017-02-06 16:55:39 -05003312 bp->tx_ring_map = kcalloc(bp->tx_nr_rings, sizeof(u16),
3313 GFP_KERNEL);
3314
3315 if (!bp->tx_ring_map)
3316 return -ENOMEM;
3317
Michael Chan01657bc2016-01-02 23:45:03 -05003318 if (bp->flags & BNXT_FLAG_SHARED_RINGS)
3319 j = 0;
3320 else
3321 j = bp->rx_nr_rings;
3322
3323 for (i = 0; i < bp->tx_nr_rings; i++, j++) {
3324 bp->tx_ring[i].bnapi = bp->bnapi[j];
3325 bp->bnapi[j]->tx_ring = &bp->tx_ring[i];
Michael Chan5f449242017-02-06 16:55:40 -05003326 bp->tx_ring_map[i] = bp->tx_nr_rings_xdp + i;
Michael Chan38413402017-02-06 16:55:43 -05003327 if (i >= bp->tx_nr_rings_xdp) {
Michael Chan5f449242017-02-06 16:55:40 -05003328 bp->tx_ring[i].txq_index = i -
3329 bp->tx_nr_rings_xdp;
Michael Chan38413402017-02-06 16:55:43 -05003330 bp->bnapi[j]->tx_int = bnxt_tx_int;
3331 } else {
Michael Chanfa3e93e2017-02-06 16:55:41 -05003332 bp->bnapi[j]->flags |= BNXT_NAPI_FLAG_XDP;
Michael Chan38413402017-02-06 16:55:43 -05003333 bp->bnapi[j]->tx_int = bnxt_tx_int_xdp;
3334 }
Michael Chanb6ab4b02016-01-02 23:44:59 -05003335 }
3336
Michael Chanc0c050c2015-10-22 16:01:17 -04003337 rc = bnxt_alloc_stats(bp);
3338 if (rc)
3339 goto alloc_mem_err;
3340
3341 rc = bnxt_alloc_ntp_fltrs(bp);
3342 if (rc)
3343 goto alloc_mem_err;
3344
3345 rc = bnxt_alloc_vnics(bp);
3346 if (rc)
3347 goto alloc_mem_err;
3348 }
3349
3350 bnxt_init_ring_struct(bp);
3351
3352 rc = bnxt_alloc_rx_rings(bp);
3353 if (rc)
3354 goto alloc_mem_err;
3355
3356 rc = bnxt_alloc_tx_rings(bp);
3357 if (rc)
3358 goto alloc_mem_err;
3359
3360 rc = bnxt_alloc_cp_rings(bp);
3361 if (rc)
3362 goto alloc_mem_err;
3363
3364 bp->vnic_info[0].flags |= BNXT_VNIC_RSS_FLAG | BNXT_VNIC_MCAST_FLAG |
3365 BNXT_VNIC_UCAST_FLAG;
3366 rc = bnxt_alloc_vnic_attributes(bp);
3367 if (rc)
3368 goto alloc_mem_err;
3369 return 0;
3370
3371alloc_mem_err:
3372 bnxt_free_mem(bp, true);
3373 return rc;
3374}
3375
Michael Chan9d8bc092016-12-29 12:13:33 -05003376static void bnxt_disable_int(struct bnxt *bp)
3377{
3378 int i;
3379
3380 if (!bp->bnapi)
3381 return;
3382
3383 for (i = 0; i < bp->cp_nr_rings; i++) {
3384 struct bnxt_napi *bnapi = bp->bnapi[i];
3385 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
Michael Chandaf1f1e2017-02-20 19:25:17 -05003386 struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
Michael Chan9d8bc092016-12-29 12:13:33 -05003387
Michael Chandaf1f1e2017-02-20 19:25:17 -05003388 if (ring->fw_ring_id != INVALID_HW_RING_ID)
3389 BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
Michael Chan9d8bc092016-12-29 12:13:33 -05003390 }
3391}
3392
Michael Chane5811b82018-03-31 13:54:18 -04003393static int bnxt_cp_num_to_irq_num(struct bnxt *bp, int n)
3394{
3395 struct bnxt_napi *bnapi = bp->bnapi[n];
3396 struct bnxt_cp_ring_info *cpr;
3397
3398 cpr = &bnapi->cp_ring;
3399 return cpr->cp_ring_struct.map_idx;
3400}
3401
Michael Chan9d8bc092016-12-29 12:13:33 -05003402static void bnxt_disable_int_sync(struct bnxt *bp)
3403{
3404 int i;
3405
3406 atomic_inc(&bp->intr_sem);
3407
3408 bnxt_disable_int(bp);
Michael Chane5811b82018-03-31 13:54:18 -04003409 for (i = 0; i < bp->cp_nr_rings; i++) {
3410 int map_idx = bnxt_cp_num_to_irq_num(bp, i);
3411
3412 synchronize_irq(bp->irq_tbl[map_idx].vector);
3413 }
Michael Chan9d8bc092016-12-29 12:13:33 -05003414}
3415
3416static void bnxt_enable_int(struct bnxt *bp)
3417{
3418 int i;
3419
3420 atomic_set(&bp->intr_sem, 0);
3421 for (i = 0; i < bp->cp_nr_rings; i++) {
3422 struct bnxt_napi *bnapi = bp->bnapi[i];
3423 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
3424
3425 BNXT_CP_DB_REARM(cpr->cp_doorbell, cpr->cp_raw_cons);
3426 }
3427}
3428
Michael Chanc0c050c2015-10-22 16:01:17 -04003429void bnxt_hwrm_cmd_hdr_init(struct bnxt *bp, void *request, u16 req_type,
3430 u16 cmpl_ring, u16 target_id)
3431{
Michael Chana8643e12016-02-26 04:00:05 -05003432 struct input *req = request;
Michael Chanc0c050c2015-10-22 16:01:17 -04003433
Michael Chana8643e12016-02-26 04:00:05 -05003434 req->req_type = cpu_to_le16(req_type);
3435 req->cmpl_ring = cpu_to_le16(cmpl_ring);
3436 req->target_id = cpu_to_le16(target_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04003437 req->resp_addr = cpu_to_le64(bp->hwrm_cmd_resp_dma_addr);
3438}
3439
Michael Chanfbfbc482016-02-26 04:00:07 -05003440static int bnxt_hwrm_do_send_msg(struct bnxt *bp, void *msg, u32 msg_len,
3441 int timeout, bool silent)
Michael Chanc0c050c2015-10-22 16:01:17 -04003442{
Michael Chana11fa2b2016-05-15 03:04:47 -04003443 int i, intr_process, rc, tmo_count;
Michael Chana8643e12016-02-26 04:00:05 -05003444 struct input *req = msg;
Michael Chanc0c050c2015-10-22 16:01:17 -04003445 u32 *data = msg;
Michael Chan845adfe2018-03-31 13:54:15 -04003446 __le32 *resp_len;
3447 u8 *valid;
Michael Chanc0c050c2015-10-22 16:01:17 -04003448 u16 cp_ring_id, len = 0;
3449 struct hwrm_err_output *resp = bp->hwrm_cmd_resp_addr;
Deepak Khungare605db82017-05-29 19:06:04 -04003450 u16 max_req_len = BNXT_HWRM_MAX_REQ_LEN;
Vasundhara Volamebd58182017-12-01 03:13:05 -05003451 struct hwrm_short_input short_input = {0};
Michael Chanc0c050c2015-10-22 16:01:17 -04003452
Michael Chana8643e12016-02-26 04:00:05 -05003453 req->seq_id = cpu_to_le16(bp->hwrm_cmd_seq++);
Michael Chanc0c050c2015-10-22 16:01:17 -04003454 memset(resp, 0, PAGE_SIZE);
Michael Chana8643e12016-02-26 04:00:05 -05003455 cp_ring_id = le16_to_cpu(req->cmpl_ring);
Michael Chanc0c050c2015-10-22 16:01:17 -04003456 intr_process = (cp_ring_id == INVALID_HW_RING_ID) ? 0 : 1;
3457
Deepak Khungare605db82017-05-29 19:06:04 -04003458 if (bp->flags & BNXT_FLAG_SHORT_CMD) {
3459 void *short_cmd_req = bp->hwrm_short_cmd_req_addr;
Deepak Khungare605db82017-05-29 19:06:04 -04003460
3461 memcpy(short_cmd_req, req, msg_len);
3462 memset(short_cmd_req + msg_len, 0, BNXT_HWRM_MAX_REQ_LEN -
3463 msg_len);
3464
3465 short_input.req_type = req->req_type;
3466 short_input.signature =
3467 cpu_to_le16(SHORT_REQ_SIGNATURE_SHORT_CMD);
3468 short_input.size = cpu_to_le16(msg_len);
3469 short_input.req_addr =
3470 cpu_to_le64(bp->hwrm_short_cmd_req_dma_addr);
3471
3472 data = (u32 *)&short_input;
3473 msg_len = sizeof(short_input);
3474
3475 /* Sync memory write before updating doorbell */
3476 wmb();
3477
3478 max_req_len = BNXT_HWRM_SHORT_REQ_LEN;
3479 }
3480
Michael Chanc0c050c2015-10-22 16:01:17 -04003481 /* Write request msg to hwrm channel */
3482 __iowrite32_copy(bp->bar0, data, msg_len / 4);
3483
Deepak Khungare605db82017-05-29 19:06:04 -04003484 for (i = msg_len; i < max_req_len; i += 4)
Michael Chand79979a2016-01-07 19:56:57 -05003485 writel(0, bp->bar0 + i);
3486
Michael Chanc0c050c2015-10-22 16:01:17 -04003487 /* currently supports only one outstanding message */
3488 if (intr_process)
Michael Chana8643e12016-02-26 04:00:05 -05003489 bp->hwrm_intr_seq_id = le16_to_cpu(req->seq_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04003490
3491 /* Ring channel doorbell */
3492 writel(1, bp->bar0 + 0x100);
3493
Michael Chanff4fe812016-02-26 04:00:04 -05003494 if (!timeout)
3495 timeout = DFLT_HWRM_CMD_TIMEOUT;
3496
Michael Chanc0c050c2015-10-22 16:01:17 -04003497 i = 0;
Michael Chana11fa2b2016-05-15 03:04:47 -04003498 tmo_count = timeout * 40;
Michael Chan845adfe2018-03-31 13:54:15 -04003499 resp_len = bp->hwrm_cmd_resp_addr + HWRM_RESP_LEN_OFFSET;
Michael Chanc0c050c2015-10-22 16:01:17 -04003500 if (intr_process) {
3501 /* Wait until hwrm response cmpl interrupt is processed */
3502 while (bp->hwrm_intr_seq_id != HWRM_SEQ_ID_INVALID &&
Michael Chana11fa2b2016-05-15 03:04:47 -04003503 i++ < tmo_count) {
3504 usleep_range(25, 40);
Michael Chanc0c050c2015-10-22 16:01:17 -04003505 }
3506
3507 if (bp->hwrm_intr_seq_id != HWRM_SEQ_ID_INVALID) {
3508 netdev_err(bp->dev, "Resp cmpl intr err msg: 0x%x\n",
Michael Chana8643e12016-02-26 04:00:05 -05003509 le16_to_cpu(req->req_type));
Michael Chanc0c050c2015-10-22 16:01:17 -04003510 return -1;
3511 }
Michael Chan845adfe2018-03-31 13:54:15 -04003512 len = (le32_to_cpu(*resp_len) & HWRM_RESP_LEN_MASK) >>
3513 HWRM_RESP_LEN_SFT;
3514 valid = bp->hwrm_cmd_resp_addr + len - 1;
Michael Chanc0c050c2015-10-22 16:01:17 -04003515 } else {
3516 /* Check if response len is updated */
Michael Chana11fa2b2016-05-15 03:04:47 -04003517 for (i = 0; i < tmo_count; i++) {
Michael Chanc0c050c2015-10-22 16:01:17 -04003518 len = (le32_to_cpu(*resp_len) & HWRM_RESP_LEN_MASK) >>
3519 HWRM_RESP_LEN_SFT;
3520 if (len)
3521 break;
Michael Chana11fa2b2016-05-15 03:04:47 -04003522 usleep_range(25, 40);
Michael Chanc0c050c2015-10-22 16:01:17 -04003523 }
3524
Michael Chana11fa2b2016-05-15 03:04:47 -04003525 if (i >= tmo_count) {
Michael Chanc0c050c2015-10-22 16:01:17 -04003526 netdev_err(bp->dev, "Error (timeout: %d) msg {0x%x 0x%x} len:%d\n",
Michael Chana8643e12016-02-26 04:00:05 -05003527 timeout, le16_to_cpu(req->req_type),
Michael Chan8578d6c2016-05-15 03:04:48 -04003528 le16_to_cpu(req->seq_id), len);
Michael Chanc0c050c2015-10-22 16:01:17 -04003529 return -1;
3530 }
3531
Michael Chan845adfe2018-03-31 13:54:15 -04003532 /* Last byte of resp contains valid bit */
3533 valid = bp->hwrm_cmd_resp_addr + len - 1;
Michael Chana11fa2b2016-05-15 03:04:47 -04003534 for (i = 0; i < 5; i++) {
Michael Chan845adfe2018-03-31 13:54:15 -04003535 /* make sure we read from updated DMA memory */
3536 dma_rmb();
3537 if (*valid)
Michael Chanc0c050c2015-10-22 16:01:17 -04003538 break;
Michael Chana11fa2b2016-05-15 03:04:47 -04003539 udelay(1);
Michael Chanc0c050c2015-10-22 16:01:17 -04003540 }
3541
Michael Chana11fa2b2016-05-15 03:04:47 -04003542 if (i >= 5) {
Michael Chanc0c050c2015-10-22 16:01:17 -04003543 netdev_err(bp->dev, "Error (timeout: %d) msg {0x%x 0x%x} len:%d v:%d\n",
Michael Chana8643e12016-02-26 04:00:05 -05003544 timeout, le16_to_cpu(req->req_type),
3545 le16_to_cpu(req->seq_id), len, *valid);
Michael Chanc0c050c2015-10-22 16:01:17 -04003546 return -1;
3547 }
3548 }
3549
Michael Chan845adfe2018-03-31 13:54:15 -04003550 /* Zero valid bit for compatibility. Valid bit in an older spec
3551 * may become a new field in a newer spec. We must make sure that
3552 * a new field not implemented by old spec will read zero.
3553 */
3554 *valid = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04003555 rc = le16_to_cpu(resp->error_code);
Michael Chanfbfbc482016-02-26 04:00:07 -05003556 if (rc && !silent)
Michael Chanc0c050c2015-10-22 16:01:17 -04003557 netdev_err(bp->dev, "hwrm req_type 0x%x seq id 0x%x error 0x%x\n",
3558 le16_to_cpu(resp->req_type),
3559 le16_to_cpu(resp->seq_id), rc);
Michael Chanfbfbc482016-02-26 04:00:07 -05003560 return rc;
3561}
3562
3563int _hwrm_send_message(struct bnxt *bp, void *msg, u32 msg_len, int timeout)
3564{
3565 return bnxt_hwrm_do_send_msg(bp, msg, msg_len, timeout, false);
Michael Chanc0c050c2015-10-22 16:01:17 -04003566}
3567
Michael Chancc72f3b2017-10-13 21:09:33 -04003568int _hwrm_send_message_silent(struct bnxt *bp, void *msg, u32 msg_len,
3569 int timeout)
3570{
3571 return bnxt_hwrm_do_send_msg(bp, msg, msg_len, timeout, true);
3572}
3573
Michael Chanc0c050c2015-10-22 16:01:17 -04003574int hwrm_send_message(struct bnxt *bp, void *msg, u32 msg_len, int timeout)
3575{
3576 int rc;
3577
3578 mutex_lock(&bp->hwrm_cmd_lock);
3579 rc = _hwrm_send_message(bp, msg, msg_len, timeout);
3580 mutex_unlock(&bp->hwrm_cmd_lock);
3581 return rc;
3582}
3583
Michael Chan90e209212016-02-26 04:00:08 -05003584int hwrm_send_message_silent(struct bnxt *bp, void *msg, u32 msg_len,
3585 int timeout)
3586{
3587 int rc;
3588
3589 mutex_lock(&bp->hwrm_cmd_lock);
3590 rc = bnxt_hwrm_do_send_msg(bp, msg, msg_len, timeout, true);
3591 mutex_unlock(&bp->hwrm_cmd_lock);
3592 return rc;
3593}
3594
Michael Chana1653b12016-12-07 00:26:20 -05003595int bnxt_hwrm_func_rgtr_async_events(struct bnxt *bp, unsigned long *bmap,
3596 int bmap_size)
Michael Chanc0c050c2015-10-22 16:01:17 -04003597{
3598 struct hwrm_func_drv_rgtr_input req = {0};
Michael Chan25be8622016-04-05 14:09:00 -04003599 DECLARE_BITMAP(async_events_bmap, 256);
3600 u32 *events = (u32 *)async_events_bmap;
Michael Chana1653b12016-12-07 00:26:20 -05003601 int i;
Michael Chanc0c050c2015-10-22 16:01:17 -04003602
3603 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_RGTR, -1, -1);
3604
3605 req.enables =
Michael Chana1653b12016-12-07 00:26:20 -05003606 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_ASYNC_EVENT_FWD);
Michael Chanc0c050c2015-10-22 16:01:17 -04003607
Michael Chan25be8622016-04-05 14:09:00 -04003608 memset(async_events_bmap, 0, sizeof(async_events_bmap));
3609 for (i = 0; i < ARRAY_SIZE(bnxt_async_events_arr); i++)
3610 __set_bit(bnxt_async_events_arr[i], async_events_bmap);
3611
Michael Chana1653b12016-12-07 00:26:20 -05003612 if (bmap && bmap_size) {
3613 for (i = 0; i < bmap_size; i++) {
3614 if (test_bit(i, bmap))
3615 __set_bit(i, async_events_bmap);
3616 }
3617 }
3618
Michael Chan25be8622016-04-05 14:09:00 -04003619 for (i = 0; i < 8; i++)
3620 req.async_event_fwd[i] |= cpu_to_le32(events[i]);
3621
Michael Chana1653b12016-12-07 00:26:20 -05003622 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3623}
3624
3625static int bnxt_hwrm_func_drv_rgtr(struct bnxt *bp)
3626{
3627 struct hwrm_func_drv_rgtr_input req = {0};
3628
3629 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_RGTR, -1, -1);
3630
3631 req.enables =
3632 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_OS_TYPE |
3633 FUNC_DRV_RGTR_REQ_ENABLES_VER);
3634
Michael Chan11f15ed2016-04-05 14:08:55 -04003635 req.os_type = cpu_to_le16(FUNC_DRV_RGTR_REQ_OS_TYPE_LINUX);
Michael Chand4f52de02018-03-31 13:54:06 -04003636 req.flags = cpu_to_le32(FUNC_DRV_RGTR_REQ_FLAGS_16BIT_VER_MODE);
3637 req.ver_maj_8b = DRV_VER_MAJ;
3638 req.ver_min_8b = DRV_VER_MIN;
3639 req.ver_upd_8b = DRV_VER_UPD;
3640 req.ver_maj = cpu_to_le16(DRV_VER_MAJ);
3641 req.ver_min = cpu_to_le16(DRV_VER_MIN);
3642 req.ver_upd = cpu_to_le16(DRV_VER_UPD);
Michael Chanc0c050c2015-10-22 16:01:17 -04003643
3644 if (BNXT_PF(bp)) {
Michael Chan9b0436c2017-07-11 13:05:36 -04003645 u32 data[8];
Michael Chana1653b12016-12-07 00:26:20 -05003646 int i;
Michael Chanc0c050c2015-10-22 16:01:17 -04003647
Michael Chan9b0436c2017-07-11 13:05:36 -04003648 memset(data, 0, sizeof(data));
3649 for (i = 0; i < ARRAY_SIZE(bnxt_vf_req_snif); i++) {
3650 u16 cmd = bnxt_vf_req_snif[i];
3651 unsigned int bit, idx;
3652
3653 idx = cmd / 32;
3654 bit = cmd % 32;
3655 data[idx] |= 1 << bit;
3656 }
Michael Chanc0c050c2015-10-22 16:01:17 -04003657
Michael Chande68f5de2015-12-09 19:35:41 -05003658 for (i = 0; i < 8; i++)
3659 req.vf_req_fwd[i] = cpu_to_le32(data[i]);
3660
Michael Chanc0c050c2015-10-22 16:01:17 -04003661 req.enables |=
3662 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_VF_REQ_FWD);
3663 }
3664
3665 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3666}
3667
Jeffrey Huangbe58a0d2015-12-27 18:19:18 -05003668static int bnxt_hwrm_func_drv_unrgtr(struct bnxt *bp)
3669{
3670 struct hwrm_func_drv_unrgtr_input req = {0};
3671
3672 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_UNRGTR, -1, -1);
3673 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3674}
3675
Michael Chanc0c050c2015-10-22 16:01:17 -04003676static int bnxt_hwrm_tunnel_dst_port_free(struct bnxt *bp, u8 tunnel_type)
3677{
3678 u32 rc = 0;
3679 struct hwrm_tunnel_dst_port_free_input req = {0};
3680
3681 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_TUNNEL_DST_PORT_FREE, -1, -1);
3682 req.tunnel_type = tunnel_type;
3683
3684 switch (tunnel_type) {
3685 case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN:
3686 req.tunnel_dst_port_id = bp->vxlan_fw_dst_port_id;
3687 break;
3688 case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE:
3689 req.tunnel_dst_port_id = bp->nge_fw_dst_port_id;
3690 break;
3691 default:
3692 break;
3693 }
3694
3695 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3696 if (rc)
3697 netdev_err(bp->dev, "hwrm_tunnel_dst_port_free failed. rc:%d\n",
3698 rc);
3699 return rc;
3700}
3701
3702static int bnxt_hwrm_tunnel_dst_port_alloc(struct bnxt *bp, __be16 port,
3703 u8 tunnel_type)
3704{
3705 u32 rc = 0;
3706 struct hwrm_tunnel_dst_port_alloc_input req = {0};
3707 struct hwrm_tunnel_dst_port_alloc_output *resp = bp->hwrm_cmd_resp_addr;
3708
3709 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_TUNNEL_DST_PORT_ALLOC, -1, -1);
3710
3711 req.tunnel_type = tunnel_type;
3712 req.tunnel_dst_port_val = port;
3713
3714 mutex_lock(&bp->hwrm_cmd_lock);
3715 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3716 if (rc) {
3717 netdev_err(bp->dev, "hwrm_tunnel_dst_port_alloc failed. rc:%d\n",
3718 rc);
3719 goto err_out;
3720 }
3721
Christophe Jaillet57aac712016-11-22 06:14:40 +01003722 switch (tunnel_type) {
3723 case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_VXLAN:
Michael Chanc0c050c2015-10-22 16:01:17 -04003724 bp->vxlan_fw_dst_port_id = resp->tunnel_dst_port_id;
Christophe Jaillet57aac712016-11-22 06:14:40 +01003725 break;
3726 case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_GENEVE:
Michael Chanc0c050c2015-10-22 16:01:17 -04003727 bp->nge_fw_dst_port_id = resp->tunnel_dst_port_id;
Christophe Jaillet57aac712016-11-22 06:14:40 +01003728 break;
3729 default:
3730 break;
3731 }
3732
Michael Chanc0c050c2015-10-22 16:01:17 -04003733err_out:
3734 mutex_unlock(&bp->hwrm_cmd_lock);
3735 return rc;
3736}
3737
3738static int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt *bp, u16 vnic_id)
3739{
3740 struct hwrm_cfa_l2_set_rx_mask_input req = {0};
3741 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
3742
3743 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_L2_SET_RX_MASK, -1, -1);
Michael Chanc1935542015-12-27 18:19:28 -05003744 req.vnic_id = cpu_to_le32(vnic->fw_vnic_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04003745
3746 req.num_mc_entries = cpu_to_le32(vnic->mc_list_count);
3747 req.mc_tbl_addr = cpu_to_le64(vnic->mc_list_mapping);
3748 req.mask = cpu_to_le32(vnic->rx_mask);
3749 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3750}
3751
3752#ifdef CONFIG_RFS_ACCEL
3753static int bnxt_hwrm_cfa_ntuple_filter_free(struct bnxt *bp,
3754 struct bnxt_ntuple_filter *fltr)
3755{
3756 struct hwrm_cfa_ntuple_filter_free_input req = {0};
3757
3758 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_NTUPLE_FILTER_FREE, -1, -1);
3759 req.ntuple_filter_id = fltr->filter_id;
3760 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3761}
3762
3763#define BNXT_NTP_FLTR_FLAGS \
3764 (CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_L2_FILTER_ID | \
3765 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_ETHERTYPE | \
3766 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_MACADDR | \
3767 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IPADDR_TYPE | \
3768 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR | \
3769 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR_MASK | \
3770 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR | \
3771 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR_MASK | \
3772 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IP_PROTOCOL | \
3773 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT | \
3774 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT_MASK | \
3775 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT | \
3776 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT_MASK | \
Michael Chanc1935542015-12-27 18:19:28 -05003777 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_ID)
Michael Chanc0c050c2015-10-22 16:01:17 -04003778
Michael Chan61aad722017-02-12 19:18:14 -05003779#define BNXT_NTP_TUNNEL_FLTR_FLAG \
3780 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_TUNNEL_TYPE
3781
Michael Chanc0c050c2015-10-22 16:01:17 -04003782static int bnxt_hwrm_cfa_ntuple_filter_alloc(struct bnxt *bp,
3783 struct bnxt_ntuple_filter *fltr)
3784{
3785 int rc = 0;
3786 struct hwrm_cfa_ntuple_filter_alloc_input req = {0};
3787 struct hwrm_cfa_ntuple_filter_alloc_output *resp =
3788 bp->hwrm_cmd_resp_addr;
3789 struct flow_keys *keys = &fltr->fkeys;
3790 struct bnxt_vnic_info *vnic = &bp->vnic_info[fltr->rxq + 1];
3791
3792 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_NTUPLE_FILTER_ALLOC, -1, -1);
Michael Chana54c4d72016-07-25 12:33:35 -04003793 req.l2_filter_id = bp->vnic_info[0].fw_l2_filter_id[fltr->l2_fltr_idx];
Michael Chanc0c050c2015-10-22 16:01:17 -04003794
3795 req.enables = cpu_to_le32(BNXT_NTP_FLTR_FLAGS);
3796
3797 req.ethertype = htons(ETH_P_IP);
3798 memcpy(req.src_macaddr, fltr->src_mac_addr, ETH_ALEN);
Michael Chanc1935542015-12-27 18:19:28 -05003799 req.ip_addr_type = CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV4;
Michael Chanc0c050c2015-10-22 16:01:17 -04003800 req.ip_protocol = keys->basic.ip_proto;
3801
Michael Chandda0e742016-12-29 12:13:40 -05003802 if (keys->basic.n_proto == htons(ETH_P_IPV6)) {
3803 int i;
3804
3805 req.ethertype = htons(ETH_P_IPV6);
3806 req.ip_addr_type =
3807 CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV6;
3808 *(struct in6_addr *)&req.src_ipaddr[0] =
3809 keys->addrs.v6addrs.src;
3810 *(struct in6_addr *)&req.dst_ipaddr[0] =
3811 keys->addrs.v6addrs.dst;
3812 for (i = 0; i < 4; i++) {
3813 req.src_ipaddr_mask[i] = cpu_to_be32(0xffffffff);
3814 req.dst_ipaddr_mask[i] = cpu_to_be32(0xffffffff);
3815 }
3816 } else {
3817 req.src_ipaddr[0] = keys->addrs.v4addrs.src;
3818 req.src_ipaddr_mask[0] = cpu_to_be32(0xffffffff);
3819 req.dst_ipaddr[0] = keys->addrs.v4addrs.dst;
3820 req.dst_ipaddr_mask[0] = cpu_to_be32(0xffffffff);
3821 }
Michael Chan61aad722017-02-12 19:18:14 -05003822 if (keys->control.flags & FLOW_DIS_ENCAPSULATION) {
3823 req.enables |= cpu_to_le32(BNXT_NTP_TUNNEL_FLTR_FLAG);
3824 req.tunnel_type =
3825 CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_ANYTUNNEL;
3826 }
Michael Chanc0c050c2015-10-22 16:01:17 -04003827
3828 req.src_port = keys->ports.src;
3829 req.src_port_mask = cpu_to_be16(0xffff);
3830 req.dst_port = keys->ports.dst;
3831 req.dst_port_mask = cpu_to_be16(0xffff);
3832
Michael Chanc1935542015-12-27 18:19:28 -05003833 req.dst_id = cpu_to_le16(vnic->fw_vnic_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04003834 mutex_lock(&bp->hwrm_cmd_lock);
3835 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3836 if (!rc)
3837 fltr->filter_id = resp->ntuple_filter_id;
3838 mutex_unlock(&bp->hwrm_cmd_lock);
3839 return rc;
3840}
3841#endif
3842
3843static int bnxt_hwrm_set_vnic_filter(struct bnxt *bp, u16 vnic_id, u16 idx,
3844 u8 *mac_addr)
3845{
3846 u32 rc = 0;
3847 struct hwrm_cfa_l2_filter_alloc_input req = {0};
3848 struct hwrm_cfa_l2_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr;
3849
3850 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_L2_FILTER_ALLOC, -1, -1);
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04003851 req.flags = cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_PATH_RX);
3852 if (!BNXT_CHIP_TYPE_NITRO_A0(bp))
3853 req.flags |=
3854 cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_OUTERMOST);
Michael Chanc1935542015-12-27 18:19:28 -05003855 req.dst_id = cpu_to_le16(bp->vnic_info[vnic_id].fw_vnic_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04003856 req.enables =
3857 cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR |
Michael Chanc1935542015-12-27 18:19:28 -05003858 CFA_L2_FILTER_ALLOC_REQ_ENABLES_DST_ID |
Michael Chanc0c050c2015-10-22 16:01:17 -04003859 CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR_MASK);
3860 memcpy(req.l2_addr, mac_addr, ETH_ALEN);
3861 req.l2_addr_mask[0] = 0xff;
3862 req.l2_addr_mask[1] = 0xff;
3863 req.l2_addr_mask[2] = 0xff;
3864 req.l2_addr_mask[3] = 0xff;
3865 req.l2_addr_mask[4] = 0xff;
3866 req.l2_addr_mask[5] = 0xff;
3867
3868 mutex_lock(&bp->hwrm_cmd_lock);
3869 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3870 if (!rc)
3871 bp->vnic_info[vnic_id].fw_l2_filter_id[idx] =
3872 resp->l2_filter_id;
3873 mutex_unlock(&bp->hwrm_cmd_lock);
3874 return rc;
3875}
3876
3877static int bnxt_hwrm_clear_vnic_filter(struct bnxt *bp)
3878{
3879 u16 i, j, num_of_vnics = 1; /* only vnic 0 supported */
3880 int rc = 0;
3881
3882 /* Any associated ntuple filters will also be cleared by firmware. */
3883 mutex_lock(&bp->hwrm_cmd_lock);
3884 for (i = 0; i < num_of_vnics; i++) {
3885 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
3886
3887 for (j = 0; j < vnic->uc_filter_count; j++) {
3888 struct hwrm_cfa_l2_filter_free_input req = {0};
3889
3890 bnxt_hwrm_cmd_hdr_init(bp, &req,
3891 HWRM_CFA_L2_FILTER_FREE, -1, -1);
3892
3893 req.l2_filter_id = vnic->fw_l2_filter_id[j];
3894
3895 rc = _hwrm_send_message(bp, &req, sizeof(req),
3896 HWRM_CMD_TIMEOUT);
3897 }
3898 vnic->uc_filter_count = 0;
3899 }
3900 mutex_unlock(&bp->hwrm_cmd_lock);
3901
3902 return rc;
3903}
3904
3905static int bnxt_hwrm_vnic_set_tpa(struct bnxt *bp, u16 vnic_id, u32 tpa_flags)
3906{
3907 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
3908 struct hwrm_vnic_tpa_cfg_input req = {0};
3909
Michael Chan3c4fe802018-03-09 23:46:10 -05003910 if (vnic->fw_vnic_id == INVALID_HW_RING_ID)
3911 return 0;
3912
Michael Chanc0c050c2015-10-22 16:01:17 -04003913 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_TPA_CFG, -1, -1);
3914
3915 if (tpa_flags) {
3916 u16 mss = bp->dev->mtu - 40;
3917 u32 nsegs, n, segs = 0, flags;
3918
3919 flags = VNIC_TPA_CFG_REQ_FLAGS_TPA |
3920 VNIC_TPA_CFG_REQ_FLAGS_ENCAP_TPA |
3921 VNIC_TPA_CFG_REQ_FLAGS_RSC_WND_UPDATE |
3922 VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_ECN |
3923 VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_SAME_GRE_SEQ;
3924 if (tpa_flags & BNXT_FLAG_GRO)
3925 flags |= VNIC_TPA_CFG_REQ_FLAGS_GRO;
3926
3927 req.flags = cpu_to_le32(flags);
3928
3929 req.enables =
3930 cpu_to_le32(VNIC_TPA_CFG_REQ_ENABLES_MAX_AGG_SEGS |
Michael Chanc1935542015-12-27 18:19:28 -05003931 VNIC_TPA_CFG_REQ_ENABLES_MAX_AGGS |
3932 VNIC_TPA_CFG_REQ_ENABLES_MIN_AGG_LEN);
Michael Chanc0c050c2015-10-22 16:01:17 -04003933
3934 /* Number of segs are log2 units, and first packet is not
3935 * included as part of this units.
3936 */
Michael Chan2839f282016-04-25 02:30:50 -04003937 if (mss <= BNXT_RX_PAGE_SIZE) {
3938 n = BNXT_RX_PAGE_SIZE / mss;
Michael Chanc0c050c2015-10-22 16:01:17 -04003939 nsegs = (MAX_SKB_FRAGS - 1) * n;
3940 } else {
Michael Chan2839f282016-04-25 02:30:50 -04003941 n = mss / BNXT_RX_PAGE_SIZE;
3942 if (mss & (BNXT_RX_PAGE_SIZE - 1))
Michael Chanc0c050c2015-10-22 16:01:17 -04003943 n++;
3944 nsegs = (MAX_SKB_FRAGS - n) / n;
3945 }
3946
3947 segs = ilog2(nsegs);
3948 req.max_agg_segs = cpu_to_le16(segs);
3949 req.max_aggs = cpu_to_le16(VNIC_TPA_CFG_REQ_MAX_AGGS_MAX);
Michael Chanc1935542015-12-27 18:19:28 -05003950
3951 req.min_agg_len = cpu_to_le32(512);
Michael Chanc0c050c2015-10-22 16:01:17 -04003952 }
3953 req.vnic_id = cpu_to_le16(vnic->fw_vnic_id);
3954
3955 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3956}
3957
3958static int bnxt_hwrm_vnic_set_rss(struct bnxt *bp, u16 vnic_id, bool set_rss)
3959{
3960 u32 i, j, max_rings;
3961 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
3962 struct hwrm_vnic_rss_cfg_input req = {0};
3963
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04003964 if (vnic->fw_rss_cos_lb_ctx[0] == INVALID_HW_RING_ID)
Michael Chanc0c050c2015-10-22 16:01:17 -04003965 return 0;
3966
3967 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_CFG, -1, -1);
3968 if (set_rss) {
Michael Chan87da7f72016-11-16 21:13:09 -05003969 req.hash_type = cpu_to_le32(bp->rss_hash_cfg);
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04003970 if (vnic->flags & BNXT_VNIC_RSS_FLAG) {
3971 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
3972 max_rings = bp->rx_nr_rings - 1;
3973 else
3974 max_rings = bp->rx_nr_rings;
3975 } else {
Michael Chanc0c050c2015-10-22 16:01:17 -04003976 max_rings = 1;
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04003977 }
Michael Chanc0c050c2015-10-22 16:01:17 -04003978
3979 /* Fill the RSS indirection table with ring group ids */
3980 for (i = 0, j = 0; i < HW_HASH_INDEX_SIZE; i++, j++) {
3981 if (j == max_rings)
3982 j = 0;
3983 vnic->rss_table[i] = cpu_to_le16(vnic->fw_grp_ids[j]);
3984 }
3985
3986 req.ring_grp_tbl_addr = cpu_to_le64(vnic->rss_table_dma_addr);
3987 req.hash_key_tbl_addr =
3988 cpu_to_le64(vnic->rss_hash_key_dma_addr);
3989 }
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04003990 req.rss_ctx_idx = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[0]);
Michael Chanc0c050c2015-10-22 16:01:17 -04003991 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3992}
3993
3994static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, u16 vnic_id)
3995{
3996 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
3997 struct hwrm_vnic_plcmodes_cfg_input req = {0};
3998
3999 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_PLCMODES_CFG, -1, -1);
4000 req.flags = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT |
4001 VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV4 |
4002 VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6);
4003 req.enables =
4004 cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID |
4005 VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID);
4006 /* thresholds not implemented in firmware yet */
4007 req.jumbo_thresh = cpu_to_le16(bp->rx_copy_thresh);
4008 req.hds_threshold = cpu_to_le16(bp->rx_copy_thresh);
4009 req.vnic_id = cpu_to_le32(vnic->fw_vnic_id);
4010 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4011}
4012
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004013static void bnxt_hwrm_vnic_ctx_free_one(struct bnxt *bp, u16 vnic_id,
4014 u16 ctx_idx)
Michael Chanc0c050c2015-10-22 16:01:17 -04004015{
4016 struct hwrm_vnic_rss_cos_lb_ctx_free_input req = {0};
4017
4018 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_COS_LB_CTX_FREE, -1, -1);
4019 req.rss_cos_lb_ctx_id =
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004020 cpu_to_le16(bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx]);
Michael Chanc0c050c2015-10-22 16:01:17 -04004021
4022 hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004023 bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx] = INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04004024}
4025
4026static void bnxt_hwrm_vnic_ctx_free(struct bnxt *bp)
4027{
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004028 int i, j;
Michael Chanc0c050c2015-10-22 16:01:17 -04004029
4030 for (i = 0; i < bp->nr_vnics; i++) {
4031 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
4032
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004033 for (j = 0; j < BNXT_MAX_CTX_PER_VNIC; j++) {
4034 if (vnic->fw_rss_cos_lb_ctx[j] != INVALID_HW_RING_ID)
4035 bnxt_hwrm_vnic_ctx_free_one(bp, i, j);
4036 }
Michael Chanc0c050c2015-10-22 16:01:17 -04004037 }
4038 bp->rsscos_nr_ctxs = 0;
4039}
4040
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004041static int bnxt_hwrm_vnic_ctx_alloc(struct bnxt *bp, u16 vnic_id, u16 ctx_idx)
Michael Chanc0c050c2015-10-22 16:01:17 -04004042{
4043 int rc;
4044 struct hwrm_vnic_rss_cos_lb_ctx_alloc_input req = {0};
4045 struct hwrm_vnic_rss_cos_lb_ctx_alloc_output *resp =
4046 bp->hwrm_cmd_resp_addr;
4047
4048 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_COS_LB_CTX_ALLOC, -1,
4049 -1);
4050
4051 mutex_lock(&bp->hwrm_cmd_lock);
4052 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4053 if (!rc)
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004054 bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx] =
Michael Chanc0c050c2015-10-22 16:01:17 -04004055 le16_to_cpu(resp->rss_cos_lb_ctx_id);
4056 mutex_unlock(&bp->hwrm_cmd_lock);
4057
4058 return rc;
4059}
4060
Michael Chanabe93ad2018-03-31 13:54:08 -04004061static u32 bnxt_get_roce_vnic_mode(struct bnxt *bp)
4062{
4063 if (bp->flags & BNXT_FLAG_ROCE_MIRROR_CAP)
4064 return VNIC_CFG_REQ_FLAGS_ROCE_MIRRORING_CAPABLE_VNIC_MODE;
4065 return VNIC_CFG_REQ_FLAGS_ROCE_DUAL_VNIC_MODE;
4066}
4067
Michael Chana588e452016-12-07 00:26:21 -05004068int bnxt_hwrm_vnic_cfg(struct bnxt *bp, u16 vnic_id)
Michael Chanc0c050c2015-10-22 16:01:17 -04004069{
Michael Chanb81a90d2016-01-02 23:45:01 -05004070 unsigned int ring = 0, grp_idx;
Michael Chanc0c050c2015-10-22 16:01:17 -04004071 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
4072 struct hwrm_vnic_cfg_input req = {0};
Michael Chancf6645f2016-06-13 02:25:28 -04004073 u16 def_vlan = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04004074
4075 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_CFG, -1, -1);
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004076
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04004077 req.enables = cpu_to_le32(VNIC_CFG_REQ_ENABLES_DFLT_RING_GRP);
4078 /* Only RSS support for now TBD: COS & LB */
4079 if (vnic->fw_rss_cos_lb_ctx[0] != INVALID_HW_RING_ID) {
4080 req.rss_rule = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[0]);
4081 req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE |
4082 VNIC_CFG_REQ_ENABLES_MRU);
Michael Chanae10ae72016-12-29 12:13:38 -05004083 } else if (vnic->flags & BNXT_VNIC_RFS_NEW_RSS_FLAG) {
4084 req.rss_rule =
4085 cpu_to_le16(bp->vnic_info[0].fw_rss_cos_lb_ctx[0]);
4086 req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE |
4087 VNIC_CFG_REQ_ENABLES_MRU);
4088 req.flags |= cpu_to_le32(VNIC_CFG_REQ_FLAGS_RSS_DFLT_CR_MODE);
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04004089 } else {
4090 req.rss_rule = cpu_to_le16(0xffff);
4091 }
4092
4093 if (BNXT_CHIP_TYPE_NITRO_A0(bp) &&
4094 (vnic->fw_rss_cos_lb_ctx[0] != INVALID_HW_RING_ID)) {
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004095 req.cos_rule = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[1]);
4096 req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_COS_RULE);
4097 } else {
4098 req.cos_rule = cpu_to_le16(0xffff);
4099 }
4100
Michael Chanc0c050c2015-10-22 16:01:17 -04004101 if (vnic->flags & BNXT_VNIC_RSS_FLAG)
Michael Chanb81a90d2016-01-02 23:45:01 -05004102 ring = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04004103 else if (vnic->flags & BNXT_VNIC_RFS_FLAG)
Michael Chanb81a90d2016-01-02 23:45:01 -05004104 ring = vnic_id - 1;
Prashant Sreedharan76595192016-07-18 07:15:22 -04004105 else if ((vnic_id == 1) && BNXT_CHIP_TYPE_NITRO_A0(bp))
4106 ring = bp->rx_nr_rings - 1;
Michael Chanc0c050c2015-10-22 16:01:17 -04004107
Michael Chanb81a90d2016-01-02 23:45:01 -05004108 grp_idx = bp->rx_ring[ring].bnapi->index;
Michael Chanc0c050c2015-10-22 16:01:17 -04004109 req.vnic_id = cpu_to_le16(vnic->fw_vnic_id);
4110 req.dflt_ring_grp = cpu_to_le16(bp->grp_info[grp_idx].fw_grp_id);
4111
4112 req.lb_rule = cpu_to_le16(0xffff);
4113 req.mru = cpu_to_le16(bp->dev->mtu + ETH_HLEN + ETH_FCS_LEN +
4114 VLAN_HLEN);
4115
Michael Chancf6645f2016-06-13 02:25:28 -04004116#ifdef CONFIG_BNXT_SRIOV
4117 if (BNXT_VF(bp))
4118 def_vlan = bp->vf.vlan;
4119#endif
4120 if ((bp->flags & BNXT_FLAG_STRIP_VLAN) || def_vlan)
Michael Chanc0c050c2015-10-22 16:01:17 -04004121 req.flags |= cpu_to_le32(VNIC_CFG_REQ_FLAGS_VLAN_STRIP_MODE);
Michael Chana588e452016-12-07 00:26:21 -05004122 if (!vnic_id && bnxt_ulp_registered(bp->edev, BNXT_ROCE_ULP))
Michael Chanabe93ad2018-03-31 13:54:08 -04004123 req.flags |= cpu_to_le32(bnxt_get_roce_vnic_mode(bp));
Michael Chanc0c050c2015-10-22 16:01:17 -04004124
4125 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4126}
4127
4128static int bnxt_hwrm_vnic_free_one(struct bnxt *bp, u16 vnic_id)
4129{
4130 u32 rc = 0;
4131
4132 if (bp->vnic_info[vnic_id].fw_vnic_id != INVALID_HW_RING_ID) {
4133 struct hwrm_vnic_free_input req = {0};
4134
4135 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_FREE, -1, -1);
4136 req.vnic_id =
4137 cpu_to_le32(bp->vnic_info[vnic_id].fw_vnic_id);
4138
4139 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4140 if (rc)
4141 return rc;
4142 bp->vnic_info[vnic_id].fw_vnic_id = INVALID_HW_RING_ID;
4143 }
4144 return rc;
4145}
4146
4147static void bnxt_hwrm_vnic_free(struct bnxt *bp)
4148{
4149 u16 i;
4150
4151 for (i = 0; i < bp->nr_vnics; i++)
4152 bnxt_hwrm_vnic_free_one(bp, i);
4153}
4154
Michael Chanb81a90d2016-01-02 23:45:01 -05004155static int bnxt_hwrm_vnic_alloc(struct bnxt *bp, u16 vnic_id,
4156 unsigned int start_rx_ring_idx,
4157 unsigned int nr_rings)
Michael Chanc0c050c2015-10-22 16:01:17 -04004158{
Michael Chanb81a90d2016-01-02 23:45:01 -05004159 int rc = 0;
4160 unsigned int i, j, grp_idx, end_idx = start_rx_ring_idx + nr_rings;
Michael Chanc0c050c2015-10-22 16:01:17 -04004161 struct hwrm_vnic_alloc_input req = {0};
4162 struct hwrm_vnic_alloc_output *resp = bp->hwrm_cmd_resp_addr;
4163
4164 /* map ring groups to this vnic */
Michael Chanb81a90d2016-01-02 23:45:01 -05004165 for (i = start_rx_ring_idx, j = 0; i < end_idx; i++, j++) {
4166 grp_idx = bp->rx_ring[i].bnapi->index;
4167 if (bp->grp_info[grp_idx].fw_grp_id == INVALID_HW_RING_ID) {
Michael Chanc0c050c2015-10-22 16:01:17 -04004168 netdev_err(bp->dev, "Not enough ring groups avail:%x req:%x\n",
Michael Chanb81a90d2016-01-02 23:45:01 -05004169 j, nr_rings);
Michael Chanc0c050c2015-10-22 16:01:17 -04004170 break;
4171 }
4172 bp->vnic_info[vnic_id].fw_grp_ids[j] =
Michael Chanb81a90d2016-01-02 23:45:01 -05004173 bp->grp_info[grp_idx].fw_grp_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04004174 }
4175
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004176 bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[0] = INVALID_HW_RING_ID;
4177 bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[1] = INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04004178 if (vnic_id == 0)
4179 req.flags = cpu_to_le32(VNIC_ALLOC_REQ_FLAGS_DEFAULT);
4180
4181 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_ALLOC, -1, -1);
4182
4183 mutex_lock(&bp->hwrm_cmd_lock);
4184 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4185 if (!rc)
4186 bp->vnic_info[vnic_id].fw_vnic_id = le32_to_cpu(resp->vnic_id);
4187 mutex_unlock(&bp->hwrm_cmd_lock);
4188 return rc;
4189}
4190
Michael Chan8fdefd62016-12-29 12:13:36 -05004191static int bnxt_hwrm_vnic_qcaps(struct bnxt *bp)
4192{
4193 struct hwrm_vnic_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
4194 struct hwrm_vnic_qcaps_input req = {0};
4195 int rc;
4196
4197 if (bp->hwrm_spec_code < 0x10600)
4198 return 0;
4199
4200 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_QCAPS, -1, -1);
4201 mutex_lock(&bp->hwrm_cmd_lock);
4202 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4203 if (!rc) {
Michael Chanabe93ad2018-03-31 13:54:08 -04004204 u32 flags = le32_to_cpu(resp->flags);
4205
4206 if (flags & VNIC_QCAPS_RESP_FLAGS_RSS_DFLT_CR_CAP)
Michael Chan8fdefd62016-12-29 12:13:36 -05004207 bp->flags |= BNXT_FLAG_NEW_RSS_CAP;
Michael Chanabe93ad2018-03-31 13:54:08 -04004208 if (flags &
4209 VNIC_QCAPS_RESP_FLAGS_ROCE_MIRRORING_CAPABLE_VNIC_CAP)
4210 bp->flags |= BNXT_FLAG_ROCE_MIRROR_CAP;
Michael Chan8fdefd62016-12-29 12:13:36 -05004211 }
4212 mutex_unlock(&bp->hwrm_cmd_lock);
4213 return rc;
4214}
4215
Michael Chanc0c050c2015-10-22 16:01:17 -04004216static int bnxt_hwrm_ring_grp_alloc(struct bnxt *bp)
4217{
4218 u16 i;
4219 u32 rc = 0;
4220
4221 mutex_lock(&bp->hwrm_cmd_lock);
4222 for (i = 0; i < bp->rx_nr_rings; i++) {
4223 struct hwrm_ring_grp_alloc_input req = {0};
4224 struct hwrm_ring_grp_alloc_output *resp =
4225 bp->hwrm_cmd_resp_addr;
Michael Chanb81a90d2016-01-02 23:45:01 -05004226 unsigned int grp_idx = bp->rx_ring[i].bnapi->index;
Michael Chanc0c050c2015-10-22 16:01:17 -04004227
4228 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_GRP_ALLOC, -1, -1);
4229
Michael Chanb81a90d2016-01-02 23:45:01 -05004230 req.cr = cpu_to_le16(bp->grp_info[grp_idx].cp_fw_ring_id);
4231 req.rr = cpu_to_le16(bp->grp_info[grp_idx].rx_fw_ring_id);
4232 req.ar = cpu_to_le16(bp->grp_info[grp_idx].agg_fw_ring_id);
4233 req.sc = cpu_to_le16(bp->grp_info[grp_idx].fw_stats_ctx);
Michael Chanc0c050c2015-10-22 16:01:17 -04004234
4235 rc = _hwrm_send_message(bp, &req, sizeof(req),
4236 HWRM_CMD_TIMEOUT);
4237 if (rc)
4238 break;
4239
Michael Chanb81a90d2016-01-02 23:45:01 -05004240 bp->grp_info[grp_idx].fw_grp_id =
4241 le32_to_cpu(resp->ring_group_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04004242 }
4243 mutex_unlock(&bp->hwrm_cmd_lock);
4244 return rc;
4245}
4246
4247static int bnxt_hwrm_ring_grp_free(struct bnxt *bp)
4248{
4249 u16 i;
4250 u32 rc = 0;
4251 struct hwrm_ring_grp_free_input req = {0};
4252
4253 if (!bp->grp_info)
4254 return 0;
4255
4256 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_GRP_FREE, -1, -1);
4257
4258 mutex_lock(&bp->hwrm_cmd_lock);
4259 for (i = 0; i < bp->cp_nr_rings; i++) {
4260 if (bp->grp_info[i].fw_grp_id == INVALID_HW_RING_ID)
4261 continue;
4262 req.ring_group_id =
4263 cpu_to_le32(bp->grp_info[i].fw_grp_id);
4264
4265 rc = _hwrm_send_message(bp, &req, sizeof(req),
4266 HWRM_CMD_TIMEOUT);
4267 if (rc)
4268 break;
4269 bp->grp_info[i].fw_grp_id = INVALID_HW_RING_ID;
4270 }
4271 mutex_unlock(&bp->hwrm_cmd_lock);
4272 return rc;
4273}
4274
4275static int hwrm_ring_alloc_send_msg(struct bnxt *bp,
4276 struct bnxt_ring_struct *ring,
Michael Chan9899bb52018-03-31 13:54:16 -04004277 u32 ring_type, u32 map_index)
Michael Chanc0c050c2015-10-22 16:01:17 -04004278{
4279 int rc = 0, err = 0;
4280 struct hwrm_ring_alloc_input req = {0};
4281 struct hwrm_ring_alloc_output *resp = bp->hwrm_cmd_resp_addr;
Michael Chan9899bb52018-03-31 13:54:16 -04004282 struct bnxt_ring_grp_info *grp_info;
Michael Chanc0c050c2015-10-22 16:01:17 -04004283 u16 ring_id;
4284
4285 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_ALLOC, -1, -1);
4286
4287 req.enables = 0;
4288 if (ring->nr_pages > 1) {
4289 req.page_tbl_addr = cpu_to_le64(ring->pg_tbl_map);
4290 /* Page size is in log2 units */
4291 req.page_size = BNXT_PAGE_SHIFT;
4292 req.page_tbl_depth = 1;
4293 } else {
4294 req.page_tbl_addr = cpu_to_le64(ring->dma_arr[0]);
4295 }
4296 req.fbo = 0;
4297 /* Association of ring index with doorbell index and MSIX number */
4298 req.logical_id = cpu_to_le16(map_index);
4299
4300 switch (ring_type) {
4301 case HWRM_RING_ALLOC_TX:
4302 req.ring_type = RING_ALLOC_REQ_RING_TYPE_TX;
4303 /* Association of transmit ring with completion ring */
Michael Chan9899bb52018-03-31 13:54:16 -04004304 grp_info = &bp->grp_info[ring->grp_idx];
4305 req.cmpl_ring_id = cpu_to_le16(grp_info->cp_fw_ring_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04004306 req.length = cpu_to_le32(bp->tx_ring_mask + 1);
Michael Chan9899bb52018-03-31 13:54:16 -04004307 req.stat_ctx_id = cpu_to_le32(grp_info->fw_stats_ctx);
Michael Chanc0c050c2015-10-22 16:01:17 -04004308 req.queue_id = cpu_to_le16(ring->queue_id);
4309 break;
4310 case HWRM_RING_ALLOC_RX:
4311 req.ring_type = RING_ALLOC_REQ_RING_TYPE_RX;
4312 req.length = cpu_to_le32(bp->rx_ring_mask + 1);
4313 break;
4314 case HWRM_RING_ALLOC_AGG:
4315 req.ring_type = RING_ALLOC_REQ_RING_TYPE_RX;
4316 req.length = cpu_to_le32(bp->rx_agg_ring_mask + 1);
4317 break;
4318 case HWRM_RING_ALLOC_CMPL:
Michael Chanbac9a7e2017-02-12 19:18:10 -05004319 req.ring_type = RING_ALLOC_REQ_RING_TYPE_L2_CMPL;
Michael Chanc0c050c2015-10-22 16:01:17 -04004320 req.length = cpu_to_le32(bp->cp_ring_mask + 1);
4321 if (bp->flags & BNXT_FLAG_USING_MSIX)
4322 req.int_mode = RING_ALLOC_REQ_INT_MODE_MSIX;
4323 break;
4324 default:
4325 netdev_err(bp->dev, "hwrm alloc invalid ring type %d\n",
4326 ring_type);
4327 return -1;
4328 }
4329
4330 mutex_lock(&bp->hwrm_cmd_lock);
4331 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4332 err = le16_to_cpu(resp->error_code);
4333 ring_id = le16_to_cpu(resp->ring_id);
4334 mutex_unlock(&bp->hwrm_cmd_lock);
4335
4336 if (rc || err) {
4337 switch (ring_type) {
Michael Chanbac9a7e2017-02-12 19:18:10 -05004338 case RING_FREE_REQ_RING_TYPE_L2_CMPL:
Michael Chanc0c050c2015-10-22 16:01:17 -04004339 netdev_err(bp->dev, "hwrm_ring_alloc cp failed. rc:%x err:%x\n",
4340 rc, err);
4341 return -1;
4342
4343 case RING_FREE_REQ_RING_TYPE_RX:
4344 netdev_err(bp->dev, "hwrm_ring_alloc rx failed. rc:%x err:%x\n",
4345 rc, err);
4346 return -1;
4347
4348 case RING_FREE_REQ_RING_TYPE_TX:
4349 netdev_err(bp->dev, "hwrm_ring_alloc tx failed. rc:%x err:%x\n",
4350 rc, err);
4351 return -1;
4352
4353 default:
4354 netdev_err(bp->dev, "Invalid ring\n");
4355 return -1;
4356 }
4357 }
4358 ring->fw_ring_id = ring_id;
4359 return rc;
4360}
4361
Michael Chan486b5c22016-12-29 12:13:42 -05004362static int bnxt_hwrm_set_async_event_cr(struct bnxt *bp, int idx)
4363{
4364 int rc;
4365
4366 if (BNXT_PF(bp)) {
4367 struct hwrm_func_cfg_input req = {0};
4368
4369 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1);
4370 req.fid = cpu_to_le16(0xffff);
4371 req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_ASYNC_EVENT_CR);
4372 req.async_event_cr = cpu_to_le16(idx);
4373 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4374 } else {
4375 struct hwrm_func_vf_cfg_input req = {0};
4376
4377 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_VF_CFG, -1, -1);
4378 req.enables =
4379 cpu_to_le32(FUNC_VF_CFG_REQ_ENABLES_ASYNC_EVENT_CR);
4380 req.async_event_cr = cpu_to_le16(idx);
4381 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4382 }
4383 return rc;
4384}
4385
Michael Chanc0c050c2015-10-22 16:01:17 -04004386static int bnxt_hwrm_ring_alloc(struct bnxt *bp)
4387{
4388 int i, rc = 0;
4389
Michael Chanedd0c2c2015-12-27 18:19:19 -05004390 for (i = 0; i < bp->cp_nr_rings; i++) {
4391 struct bnxt_napi *bnapi = bp->bnapi[i];
4392 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
4393 struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
Michael Chan9899bb52018-03-31 13:54:16 -04004394 u32 map_idx = ring->map_idx;
Michael Chanc0c050c2015-10-22 16:01:17 -04004395
Michael Chan9899bb52018-03-31 13:54:16 -04004396 cpr->cp_doorbell = bp->bar1 + map_idx * 0x80;
4397 rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_CMPL,
4398 map_idx);
Michael Chanedd0c2c2015-12-27 18:19:19 -05004399 if (rc)
4400 goto err_out;
Michael Chanedd0c2c2015-12-27 18:19:19 -05004401 BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
4402 bp->grp_info[i].cp_fw_ring_id = ring->fw_ring_id;
Michael Chan486b5c22016-12-29 12:13:42 -05004403
4404 if (!i) {
4405 rc = bnxt_hwrm_set_async_event_cr(bp, ring->fw_ring_id);
4406 if (rc)
4407 netdev_warn(bp->dev, "Failed to set async event completion ring.\n");
4408 }
Michael Chanc0c050c2015-10-22 16:01:17 -04004409 }
4410
Michael Chanedd0c2c2015-12-27 18:19:19 -05004411 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05004412 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
Michael Chanedd0c2c2015-12-27 18:19:19 -05004413 struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
Michael Chan9899bb52018-03-31 13:54:16 -04004414 u32 map_idx = i;
Michael Chanc0c050c2015-10-22 16:01:17 -04004415
Michael Chanb81a90d2016-01-02 23:45:01 -05004416 rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_TX,
Michael Chan9899bb52018-03-31 13:54:16 -04004417 map_idx);
Michael Chanedd0c2c2015-12-27 18:19:19 -05004418 if (rc)
4419 goto err_out;
Michael Chanb81a90d2016-01-02 23:45:01 -05004420 txr->tx_doorbell = bp->bar1 + map_idx * 0x80;
Michael Chanc0c050c2015-10-22 16:01:17 -04004421 }
4422
Michael Chanedd0c2c2015-12-27 18:19:19 -05004423 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05004424 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
Michael Chanedd0c2c2015-12-27 18:19:19 -05004425 struct bnxt_ring_struct *ring = &rxr->rx_ring_struct;
Michael Chanb81a90d2016-01-02 23:45:01 -05004426 u32 map_idx = rxr->bnapi->index;
Michael Chanc0c050c2015-10-22 16:01:17 -04004427
Michael Chanb81a90d2016-01-02 23:45:01 -05004428 rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_RX,
Michael Chan9899bb52018-03-31 13:54:16 -04004429 map_idx);
Michael Chanedd0c2c2015-12-27 18:19:19 -05004430 if (rc)
4431 goto err_out;
Michael Chanb81a90d2016-01-02 23:45:01 -05004432 rxr->rx_doorbell = bp->bar1 + map_idx * 0x80;
Michael Chanedd0c2c2015-12-27 18:19:19 -05004433 writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell);
Michael Chanb81a90d2016-01-02 23:45:01 -05004434 bp->grp_info[map_idx].rx_fw_ring_id = ring->fw_ring_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04004435 }
4436
4437 if (bp->flags & BNXT_FLAG_AGG_RINGS) {
4438 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05004439 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04004440 struct bnxt_ring_struct *ring =
4441 &rxr->rx_agg_ring_struct;
Michael Chan9899bb52018-03-31 13:54:16 -04004442 u32 grp_idx = ring->grp_idx;
Michael Chanb81a90d2016-01-02 23:45:01 -05004443 u32 map_idx = grp_idx + bp->rx_nr_rings;
Michael Chanc0c050c2015-10-22 16:01:17 -04004444
4445 rc = hwrm_ring_alloc_send_msg(bp, ring,
4446 HWRM_RING_ALLOC_AGG,
Michael Chan9899bb52018-03-31 13:54:16 -04004447 map_idx);
Michael Chanc0c050c2015-10-22 16:01:17 -04004448 if (rc)
4449 goto err_out;
4450
Michael Chanb81a90d2016-01-02 23:45:01 -05004451 rxr->rx_agg_doorbell = bp->bar1 + map_idx * 0x80;
Michael Chanc0c050c2015-10-22 16:01:17 -04004452 writel(DB_KEY_RX | rxr->rx_agg_prod,
4453 rxr->rx_agg_doorbell);
Michael Chanb81a90d2016-01-02 23:45:01 -05004454 bp->grp_info[grp_idx].agg_fw_ring_id = ring->fw_ring_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04004455 }
4456 }
4457err_out:
4458 return rc;
4459}
4460
4461static int hwrm_ring_free_send_msg(struct bnxt *bp,
4462 struct bnxt_ring_struct *ring,
4463 u32 ring_type, int cmpl_ring_id)
4464{
4465 int rc;
4466 struct hwrm_ring_free_input req = {0};
4467 struct hwrm_ring_free_output *resp = bp->hwrm_cmd_resp_addr;
4468 u16 error_code;
4469
Prashant Sreedharan74608fc2016-01-28 03:11:20 -05004470 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_FREE, cmpl_ring_id, -1);
Michael Chanc0c050c2015-10-22 16:01:17 -04004471 req.ring_type = ring_type;
4472 req.ring_id = cpu_to_le16(ring->fw_ring_id);
4473
4474 mutex_lock(&bp->hwrm_cmd_lock);
4475 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4476 error_code = le16_to_cpu(resp->error_code);
4477 mutex_unlock(&bp->hwrm_cmd_lock);
4478
4479 if (rc || error_code) {
4480 switch (ring_type) {
Michael Chanbac9a7e2017-02-12 19:18:10 -05004481 case RING_FREE_REQ_RING_TYPE_L2_CMPL:
Michael Chanc0c050c2015-10-22 16:01:17 -04004482 netdev_err(bp->dev, "hwrm_ring_free cp failed. rc:%d\n",
4483 rc);
4484 return rc;
4485 case RING_FREE_REQ_RING_TYPE_RX:
4486 netdev_err(bp->dev, "hwrm_ring_free rx failed. rc:%d\n",
4487 rc);
4488 return rc;
4489 case RING_FREE_REQ_RING_TYPE_TX:
4490 netdev_err(bp->dev, "hwrm_ring_free tx failed. rc:%d\n",
4491 rc);
4492 return rc;
4493 default:
4494 netdev_err(bp->dev, "Invalid ring\n");
4495 return -1;
4496 }
4497 }
4498 return 0;
4499}
4500
Michael Chanedd0c2c2015-12-27 18:19:19 -05004501static void bnxt_hwrm_ring_free(struct bnxt *bp, bool close_path)
Michael Chanc0c050c2015-10-22 16:01:17 -04004502{
Michael Chanedd0c2c2015-12-27 18:19:19 -05004503 int i;
Michael Chanc0c050c2015-10-22 16:01:17 -04004504
4505 if (!bp->bnapi)
Michael Chanedd0c2c2015-12-27 18:19:19 -05004506 return;
Michael Chanc0c050c2015-10-22 16:01:17 -04004507
Michael Chanedd0c2c2015-12-27 18:19:19 -05004508 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05004509 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
Michael Chanedd0c2c2015-12-27 18:19:19 -05004510 struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
Michael Chanb81a90d2016-01-02 23:45:01 -05004511 u32 grp_idx = txr->bnapi->index;
4512 u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04004513
Michael Chanedd0c2c2015-12-27 18:19:19 -05004514 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
4515 hwrm_ring_free_send_msg(bp, ring,
4516 RING_FREE_REQ_RING_TYPE_TX,
4517 close_path ? cmpl_ring_id :
4518 INVALID_HW_RING_ID);
4519 ring->fw_ring_id = INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04004520 }
4521 }
4522
Michael Chanedd0c2c2015-12-27 18:19:19 -05004523 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05004524 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
Michael Chanedd0c2c2015-12-27 18:19:19 -05004525 struct bnxt_ring_struct *ring = &rxr->rx_ring_struct;
Michael Chanb81a90d2016-01-02 23:45:01 -05004526 u32 grp_idx = rxr->bnapi->index;
4527 u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04004528
Michael Chanedd0c2c2015-12-27 18:19:19 -05004529 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
4530 hwrm_ring_free_send_msg(bp, ring,
4531 RING_FREE_REQ_RING_TYPE_RX,
4532 close_path ? cmpl_ring_id :
4533 INVALID_HW_RING_ID);
4534 ring->fw_ring_id = INVALID_HW_RING_ID;
Michael Chanb81a90d2016-01-02 23:45:01 -05004535 bp->grp_info[grp_idx].rx_fw_ring_id =
4536 INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04004537 }
4538 }
4539
Michael Chanedd0c2c2015-12-27 18:19:19 -05004540 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05004541 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
Michael Chanedd0c2c2015-12-27 18:19:19 -05004542 struct bnxt_ring_struct *ring = &rxr->rx_agg_ring_struct;
Michael Chanb81a90d2016-01-02 23:45:01 -05004543 u32 grp_idx = rxr->bnapi->index;
4544 u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04004545
Michael Chanedd0c2c2015-12-27 18:19:19 -05004546 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
4547 hwrm_ring_free_send_msg(bp, ring,
4548 RING_FREE_REQ_RING_TYPE_RX,
4549 close_path ? cmpl_ring_id :
4550 INVALID_HW_RING_ID);
4551 ring->fw_ring_id = INVALID_HW_RING_ID;
Michael Chanb81a90d2016-01-02 23:45:01 -05004552 bp->grp_info[grp_idx].agg_fw_ring_id =
4553 INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04004554 }
4555 }
4556
Michael Chan9d8bc092016-12-29 12:13:33 -05004557 /* The completion rings are about to be freed. After that the
4558 * IRQ doorbell will not work anymore. So we need to disable
4559 * IRQ here.
4560 */
4561 bnxt_disable_int_sync(bp);
4562
Michael Chanedd0c2c2015-12-27 18:19:19 -05004563 for (i = 0; i < bp->cp_nr_rings; i++) {
4564 struct bnxt_napi *bnapi = bp->bnapi[i];
4565 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
4566 struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
Michael Chanc0c050c2015-10-22 16:01:17 -04004567
Michael Chanedd0c2c2015-12-27 18:19:19 -05004568 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
4569 hwrm_ring_free_send_msg(bp, ring,
Michael Chanbac9a7e2017-02-12 19:18:10 -05004570 RING_FREE_REQ_RING_TYPE_L2_CMPL,
Michael Chanedd0c2c2015-12-27 18:19:19 -05004571 INVALID_HW_RING_ID);
4572 ring->fw_ring_id = INVALID_HW_RING_ID;
4573 bp->grp_info[i].cp_fw_ring_id = INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04004574 }
4575 }
Michael Chanc0c050c2015-10-22 16:01:17 -04004576}
4577
Michael Chan674f50a2018-01-17 03:21:09 -05004578static int bnxt_hwrm_get_rings(struct bnxt *bp)
4579{
4580 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
4581 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
4582 struct hwrm_func_qcfg_input req = {0};
4583 int rc;
4584
4585 if (bp->hwrm_spec_code < 0x10601)
4586 return 0;
4587
4588 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCFG, -1, -1);
4589 req.fid = cpu_to_le16(0xffff);
4590 mutex_lock(&bp->hwrm_cmd_lock);
4591 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4592 if (rc) {
4593 mutex_unlock(&bp->hwrm_cmd_lock);
4594 return -EIO;
4595 }
4596
4597 hw_resc->resv_tx_rings = le16_to_cpu(resp->alloc_tx_rings);
4598 if (bp->flags & BNXT_FLAG_NEW_RM) {
4599 u16 cp, stats;
4600
4601 hw_resc->resv_rx_rings = le16_to_cpu(resp->alloc_rx_rings);
4602 hw_resc->resv_hw_ring_grps =
4603 le32_to_cpu(resp->alloc_hw_ring_grps);
4604 hw_resc->resv_vnics = le16_to_cpu(resp->alloc_vnics);
4605 cp = le16_to_cpu(resp->alloc_cmpl_rings);
4606 stats = le16_to_cpu(resp->alloc_stat_ctx);
4607 cp = min_t(u16, cp, stats);
4608 hw_resc->resv_cp_rings = cp;
4609 }
4610 mutex_unlock(&bp->hwrm_cmd_lock);
4611 return 0;
4612}
4613
Michael Chan391be5c2016-12-29 12:13:41 -05004614/* Caller must hold bp->hwrm_cmd_lock */
4615int __bnxt_hwrm_get_tx_rings(struct bnxt *bp, u16 fid, int *tx_rings)
4616{
4617 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
4618 struct hwrm_func_qcfg_input req = {0};
4619 int rc;
4620
4621 if (bp->hwrm_spec_code < 0x10601)
4622 return 0;
4623
4624 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCFG, -1, -1);
4625 req.fid = cpu_to_le16(fid);
4626 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4627 if (!rc)
4628 *tx_rings = le16_to_cpu(resp->alloc_tx_rings);
4629
4630 return rc;
4631}
4632
Michael Chan4ed50ef2018-03-09 23:46:03 -05004633static void
4634__bnxt_hwrm_reserve_pf_rings(struct bnxt *bp, struct hwrm_func_cfg_input *req,
4635 int tx_rings, int rx_rings, int ring_grps,
4636 int cp_rings, int vnics)
Michael Chan391be5c2016-12-29 12:13:41 -05004637{
Michael Chan674f50a2018-01-17 03:21:09 -05004638 u32 enables = 0;
Michael Chan391be5c2016-12-29 12:13:41 -05004639
Michael Chan4ed50ef2018-03-09 23:46:03 -05004640 bnxt_hwrm_cmd_hdr_init(bp, req, HWRM_FUNC_CFG, -1, -1);
4641 req->fid = cpu_to_le16(0xffff);
Michael Chan674f50a2018-01-17 03:21:09 -05004642 enables |= tx_rings ? FUNC_CFG_REQ_ENABLES_NUM_TX_RINGS : 0;
Michael Chan4ed50ef2018-03-09 23:46:03 -05004643 req->num_tx_rings = cpu_to_le16(tx_rings);
Michael Chan674f50a2018-01-17 03:21:09 -05004644 if (bp->flags & BNXT_FLAG_NEW_RM) {
4645 enables |= rx_rings ? FUNC_CFG_REQ_ENABLES_NUM_RX_RINGS : 0;
4646 enables |= cp_rings ? FUNC_CFG_REQ_ENABLES_NUM_CMPL_RINGS |
4647 FUNC_CFG_REQ_ENABLES_NUM_STAT_CTXS : 0;
4648 enables |= ring_grps ?
4649 FUNC_CFG_REQ_ENABLES_NUM_HW_RING_GRPS : 0;
4650 enables |= vnics ? FUNC_VF_CFG_REQ_ENABLES_NUM_VNICS : 0;
4651
Michael Chan4ed50ef2018-03-09 23:46:03 -05004652 req->num_rx_rings = cpu_to_le16(rx_rings);
4653 req->num_hw_ring_grps = cpu_to_le16(ring_grps);
4654 req->num_cmpl_rings = cpu_to_le16(cp_rings);
4655 req->num_stat_ctxs = req->num_cmpl_rings;
4656 req->num_vnics = cpu_to_le16(vnics);
Michael Chan674f50a2018-01-17 03:21:09 -05004657 }
Michael Chan4ed50ef2018-03-09 23:46:03 -05004658 req->enables = cpu_to_le32(enables);
4659}
4660
4661static void
4662__bnxt_hwrm_reserve_vf_rings(struct bnxt *bp,
4663 struct hwrm_func_vf_cfg_input *req, int tx_rings,
4664 int rx_rings, int ring_grps, int cp_rings,
4665 int vnics)
4666{
4667 u32 enables = 0;
4668
4669 bnxt_hwrm_cmd_hdr_init(bp, req, HWRM_FUNC_VF_CFG, -1, -1);
4670 enables |= tx_rings ? FUNC_VF_CFG_REQ_ENABLES_NUM_TX_RINGS : 0;
4671 enables |= rx_rings ? FUNC_VF_CFG_REQ_ENABLES_NUM_RX_RINGS : 0;
4672 enables |= cp_rings ? FUNC_VF_CFG_REQ_ENABLES_NUM_CMPL_RINGS |
4673 FUNC_VF_CFG_REQ_ENABLES_NUM_STAT_CTXS : 0;
4674 enables |= ring_grps ? FUNC_VF_CFG_REQ_ENABLES_NUM_HW_RING_GRPS : 0;
4675 enables |= vnics ? FUNC_VF_CFG_REQ_ENABLES_NUM_VNICS : 0;
4676
4677 req->num_tx_rings = cpu_to_le16(tx_rings);
4678 req->num_rx_rings = cpu_to_le16(rx_rings);
4679 req->num_hw_ring_grps = cpu_to_le16(ring_grps);
4680 req->num_cmpl_rings = cpu_to_le16(cp_rings);
4681 req->num_stat_ctxs = req->num_cmpl_rings;
4682 req->num_vnics = cpu_to_le16(vnics);
4683
4684 req->enables = cpu_to_le32(enables);
4685}
4686
4687static int
4688bnxt_hwrm_reserve_pf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
4689 int ring_grps, int cp_rings, int vnics)
4690{
4691 struct hwrm_func_cfg_input req = {0};
4692 int rc;
4693
4694 __bnxt_hwrm_reserve_pf_rings(bp, &req, tx_rings, rx_rings, ring_grps,
4695 cp_rings, vnics);
4696 if (!req.enables)
Michael Chan674f50a2018-01-17 03:21:09 -05004697 return 0;
4698
Michael Chan674f50a2018-01-17 03:21:09 -05004699 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4700 if (rc)
4701 return -ENOMEM;
4702
4703 if (bp->hwrm_spec_code < 0x10601)
4704 bp->hw_resc.resv_tx_rings = tx_rings;
4705
4706 rc = bnxt_hwrm_get_rings(bp);
4707 return rc;
4708}
4709
4710static int
4711bnxt_hwrm_reserve_vf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
4712 int ring_grps, int cp_rings, int vnics)
4713{
4714 struct hwrm_func_vf_cfg_input req = {0};
Michael Chan674f50a2018-01-17 03:21:09 -05004715 int rc;
4716
4717 if (!(bp->flags & BNXT_FLAG_NEW_RM)) {
4718 bp->hw_resc.resv_tx_rings = tx_rings;
4719 return 0;
4720 }
4721
Michael Chan4ed50ef2018-03-09 23:46:03 -05004722 __bnxt_hwrm_reserve_vf_rings(bp, &req, tx_rings, rx_rings, ring_grps,
4723 cp_rings, vnics);
Michael Chan674f50a2018-01-17 03:21:09 -05004724 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4725 if (rc)
4726 return -ENOMEM;
4727
4728 rc = bnxt_hwrm_get_rings(bp);
4729 return rc;
4730}
4731
4732static int bnxt_hwrm_reserve_rings(struct bnxt *bp, int tx, int rx, int grp,
4733 int cp, int vnic)
4734{
4735 if (BNXT_PF(bp))
4736 return bnxt_hwrm_reserve_pf_rings(bp, tx, rx, grp, cp, vnic);
4737 else
4738 return bnxt_hwrm_reserve_vf_rings(bp, tx, rx, grp, cp, vnic);
4739}
4740
Michael Chan08654eb2018-03-31 13:54:17 -04004741static int bnxt_cp_rings_in_use(struct bnxt *bp)
4742{
4743 int cp = bp->cp_nr_rings;
4744 int ulp_msix, ulp_base;
4745
4746 ulp_msix = bnxt_get_ulp_msix_num(bp);
4747 if (ulp_msix) {
4748 ulp_base = bnxt_get_ulp_msix_base(bp);
4749 cp += ulp_msix;
4750 if ((ulp_base + ulp_msix) > cp)
4751 cp = ulp_base + ulp_msix;
4752 }
4753 return cp;
4754}
4755
Michael Chan4e41dc52018-03-31 13:54:19 -04004756static bool bnxt_need_reserve_rings(struct bnxt *bp)
4757{
4758 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
Michael Chanfbcfc8e2018-03-31 13:54:20 -04004759 int cp = bnxt_cp_rings_in_use(bp);
Michael Chan4e41dc52018-03-31 13:54:19 -04004760 int rx = bp->rx_nr_rings;
4761 int vnic = 1, grp = rx;
4762
4763 if (bp->hwrm_spec_code < 0x10601)
4764 return false;
4765
4766 if (hw_resc->resv_tx_rings != bp->tx_nr_rings)
4767 return true;
4768
4769 if (bp->flags & BNXT_FLAG_RFS)
4770 vnic = rx + 1;
4771 if (bp->flags & BNXT_FLAG_AGG_RINGS)
4772 rx <<= 1;
4773 if ((bp->flags & BNXT_FLAG_NEW_RM) &&
4774 (hw_resc->resv_rx_rings != rx || hw_resc->resv_cp_rings != cp ||
4775 hw_resc->resv_hw_ring_grps != grp || hw_resc->resv_vnics != vnic))
4776 return true;
4777 return false;
4778}
4779
Michael Chan674f50a2018-01-17 03:21:09 -05004780static int bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max,
4781 bool shared);
4782
4783static int __bnxt_reserve_rings(struct bnxt *bp)
4784{
4785 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
Michael Chanfbcfc8e2018-03-31 13:54:20 -04004786 int cp = bnxt_cp_rings_in_use(bp);
Michael Chan674f50a2018-01-17 03:21:09 -05004787 int tx = bp->tx_nr_rings;
4788 int rx = bp->rx_nr_rings;
Michael Chan674f50a2018-01-17 03:21:09 -05004789 int grp, rx_rings, rc;
4790 bool sh = false;
4791 int vnic = 1;
4792
Michael Chan4e41dc52018-03-31 13:54:19 -04004793 if (!bnxt_need_reserve_rings(bp))
Michael Chan391be5c2016-12-29 12:13:41 -05004794 return 0;
4795
Michael Chan674f50a2018-01-17 03:21:09 -05004796 if (bp->flags & BNXT_FLAG_SHARED_RINGS)
4797 sh = true;
4798 if (bp->flags & BNXT_FLAG_RFS)
4799 vnic = rx + 1;
4800 if (bp->flags & BNXT_FLAG_AGG_RINGS)
4801 rx <<= 1;
Michael Chan674f50a2018-01-17 03:21:09 -05004802 grp = bp->rx_nr_rings;
Michael Chan391be5c2016-12-29 12:13:41 -05004803
Michael Chan674f50a2018-01-17 03:21:09 -05004804 rc = bnxt_hwrm_reserve_rings(bp, tx, rx, grp, cp, vnic);
Michael Chan391be5c2016-12-29 12:13:41 -05004805 if (rc)
4806 return rc;
4807
Michael Chan674f50a2018-01-17 03:21:09 -05004808 tx = hw_resc->resv_tx_rings;
4809 if (bp->flags & BNXT_FLAG_NEW_RM) {
4810 rx = hw_resc->resv_rx_rings;
4811 cp = hw_resc->resv_cp_rings;
4812 grp = hw_resc->resv_hw_ring_grps;
4813 vnic = hw_resc->resv_vnics;
4814 }
4815
4816 rx_rings = rx;
4817 if (bp->flags & BNXT_FLAG_AGG_RINGS) {
4818 if (rx >= 2) {
4819 rx_rings = rx >> 1;
4820 } else {
4821 if (netif_running(bp->dev))
4822 return -ENOMEM;
4823
4824 bp->flags &= ~BNXT_FLAG_AGG_RINGS;
4825 bp->flags |= BNXT_FLAG_NO_AGG_RINGS;
4826 bp->dev->hw_features &= ~NETIF_F_LRO;
4827 bp->dev->features &= ~NETIF_F_LRO;
4828 bnxt_set_ring_params(bp);
4829 }
4830 }
4831 rx_rings = min_t(int, rx_rings, grp);
4832 rc = bnxt_trim_rings(bp, &rx_rings, &tx, cp, sh);
4833 if (bp->flags & BNXT_FLAG_AGG_RINGS)
4834 rx = rx_rings << 1;
4835 cp = sh ? max_t(int, tx, rx_rings) : tx + rx_rings;
4836 bp->tx_nr_rings = tx;
4837 bp->rx_nr_rings = rx_rings;
4838 bp->cp_nr_rings = cp;
4839
4840 if (!tx || !rx || !cp || !grp || !vnic)
4841 return -ENOMEM;
4842
Michael Chan391be5c2016-12-29 12:13:41 -05004843 return rc;
4844}
4845
Michael Chan8f23d632018-01-17 03:21:12 -05004846static int bnxt_hwrm_check_vf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004847 int ring_grps, int cp_rings, int vnics)
Michael Chan98fdbe72017-08-28 13:40:26 -04004848{
Michael Chan8f23d632018-01-17 03:21:12 -05004849 struct hwrm_func_vf_cfg_input req = {0};
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004850 u32 flags;
Michael Chan98fdbe72017-08-28 13:40:26 -04004851 int rc;
4852
Michael Chan8f23d632018-01-17 03:21:12 -05004853 if (!(bp->flags & BNXT_FLAG_NEW_RM))
Michael Chan98fdbe72017-08-28 13:40:26 -04004854 return 0;
4855
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004856 __bnxt_hwrm_reserve_vf_rings(bp, &req, tx_rings, rx_rings, ring_grps,
4857 cp_rings, vnics);
Michael Chan8f23d632018-01-17 03:21:12 -05004858 flags = FUNC_VF_CFG_REQ_FLAGS_TX_ASSETS_TEST |
4859 FUNC_VF_CFG_REQ_FLAGS_RX_ASSETS_TEST |
4860 FUNC_VF_CFG_REQ_FLAGS_CMPL_ASSETS_TEST |
4861 FUNC_VF_CFG_REQ_FLAGS_RING_GRP_ASSETS_TEST |
4862 FUNC_VF_CFG_REQ_FLAGS_STAT_CTX_ASSETS_TEST |
4863 FUNC_VF_CFG_REQ_FLAGS_VNIC_ASSETS_TEST;
Michael Chan98fdbe72017-08-28 13:40:26 -04004864
Michael Chan8f23d632018-01-17 03:21:12 -05004865 req.flags = cpu_to_le32(flags);
Michael Chan98fdbe72017-08-28 13:40:26 -04004866 rc = hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4867 if (rc)
4868 return -ENOMEM;
4869 return 0;
4870}
4871
Michael Chan8f23d632018-01-17 03:21:12 -05004872static int bnxt_hwrm_check_pf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004873 int ring_grps, int cp_rings, int vnics)
Michael Chan8f23d632018-01-17 03:21:12 -05004874{
4875 struct hwrm_func_cfg_input req = {0};
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004876 u32 flags;
Michael Chan8f23d632018-01-17 03:21:12 -05004877 int rc;
4878
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004879 __bnxt_hwrm_reserve_pf_rings(bp, &req, tx_rings, rx_rings, ring_grps,
4880 cp_rings, vnics);
Michael Chan8f23d632018-01-17 03:21:12 -05004881 flags = FUNC_CFG_REQ_FLAGS_TX_ASSETS_TEST;
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004882 if (bp->flags & BNXT_FLAG_NEW_RM)
Michael Chan8f23d632018-01-17 03:21:12 -05004883 flags |= FUNC_CFG_REQ_FLAGS_RX_ASSETS_TEST |
4884 FUNC_CFG_REQ_FLAGS_CMPL_ASSETS_TEST |
4885 FUNC_CFG_REQ_FLAGS_RING_GRP_ASSETS_TEST |
4886 FUNC_CFG_REQ_FLAGS_STAT_CTX_ASSETS_TEST |
4887 FUNC_CFG_REQ_FLAGS_VNIC_ASSETS_TEST;
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004888
Michael Chan8f23d632018-01-17 03:21:12 -05004889 req.flags = cpu_to_le32(flags);
Michael Chan8f23d632018-01-17 03:21:12 -05004890 rc = hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4891 if (rc)
4892 return -ENOMEM;
4893 return 0;
4894}
4895
4896static int bnxt_hwrm_check_rings(struct bnxt *bp, int tx_rings, int rx_rings,
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004897 int ring_grps, int cp_rings, int vnics)
Michael Chan8f23d632018-01-17 03:21:12 -05004898{
4899 if (bp->hwrm_spec_code < 0x10801)
4900 return 0;
4901
4902 if (BNXT_PF(bp))
4903 return bnxt_hwrm_check_pf_rings(bp, tx_rings, rx_rings,
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004904 ring_grps, cp_rings, vnics);
Michael Chan8f23d632018-01-17 03:21:12 -05004905
4906 return bnxt_hwrm_check_vf_rings(bp, tx_rings, rx_rings, ring_grps,
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004907 cp_rings, vnics);
Michael Chan8f23d632018-01-17 03:21:12 -05004908}
4909
Michael Chanf8503962017-10-26 11:51:28 -04004910static void bnxt_hwrm_set_coal_params(struct bnxt_coal *hw_coal,
Michael Chanbb053f52016-02-26 04:00:02 -05004911 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *req)
4912{
Michael Chanf8503962017-10-26 11:51:28 -04004913 u16 val, tmr, max, flags;
4914
4915 max = hw_coal->bufs_per_record * 128;
4916 if (hw_coal->budget)
4917 max = hw_coal->bufs_per_record * hw_coal->budget;
4918
4919 val = clamp_t(u16, hw_coal->coal_bufs, 1, max);
4920 req->num_cmpl_aggr_int = cpu_to_le16(val);
Michael Chanb153cbc2017-11-03 03:32:39 -04004921
4922 /* This is a 6-bit value and must not be 0, or we'll get non stop IRQ */
4923 val = min_t(u16, val, 63);
Michael Chanf8503962017-10-26 11:51:28 -04004924 req->num_cmpl_dma_aggr = cpu_to_le16(val);
4925
Michael Chanb153cbc2017-11-03 03:32:39 -04004926 /* This is a 6-bit value and must not be 0, or we'll get non stop IRQ */
4927 val = clamp_t(u16, hw_coal->coal_bufs_irq, 1, 63);
Michael Chanf8503962017-10-26 11:51:28 -04004928 req->num_cmpl_dma_aggr_during_int = cpu_to_le16(val);
4929
4930 tmr = BNXT_USEC_TO_COAL_TIMER(hw_coal->coal_ticks);
4931 tmr = max_t(u16, tmr, 1);
4932 req->int_lat_tmr_max = cpu_to_le16(tmr);
4933
4934 /* min timer set to 1/2 of interrupt timer */
4935 val = tmr / 2;
4936 req->int_lat_tmr_min = cpu_to_le16(val);
4937
4938 /* buf timer set to 1/4 of interrupt timer */
4939 val = max_t(u16, tmr / 4, 1);
4940 req->cmpl_aggr_dma_tmr = cpu_to_le16(val);
4941
4942 tmr = BNXT_USEC_TO_COAL_TIMER(hw_coal->coal_ticks_irq);
4943 tmr = max_t(u16, tmr, 1);
4944 req->cmpl_aggr_dma_tmr_during_int = cpu_to_le16(tmr);
4945
4946 flags = RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_TIMER_RESET;
4947 if (hw_coal->idle_thresh && hw_coal->coal_ticks < hw_coal->idle_thresh)
4948 flags |= RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_RING_IDLE;
Michael Chanbb053f52016-02-26 04:00:02 -05004949 req->flags = cpu_to_le16(flags);
Michael Chanbb053f52016-02-26 04:00:02 -05004950}
4951
Andy Gospodarek6a8788f2018-01-09 16:06:20 -05004952int bnxt_hwrm_set_ring_coal(struct bnxt *bp, struct bnxt_napi *bnapi)
4953{
4954 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req_rx = {0};
4955 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
4956 struct bnxt_coal coal;
4957 unsigned int grp_idx;
4958
4959 /* Tick values in micro seconds.
4960 * 1 coal_buf x bufs_per_record = 1 completion record.
4961 */
4962 memcpy(&coal, &bp->rx_coal, sizeof(struct bnxt_coal));
4963
4964 coal.coal_ticks = cpr->rx_ring_coal.coal_ticks;
4965 coal.coal_bufs = cpr->rx_ring_coal.coal_bufs;
4966
4967 if (!bnapi->rx_ring)
4968 return -ENODEV;
4969
4970 bnxt_hwrm_cmd_hdr_init(bp, &req_rx,
4971 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1);
4972
4973 bnxt_hwrm_set_coal_params(&coal, &req_rx);
4974
4975 grp_idx = bnapi->index;
4976 req_rx.ring_id = cpu_to_le16(bp->grp_info[grp_idx].cp_fw_ring_id);
4977
4978 return hwrm_send_message(bp, &req_rx, sizeof(req_rx),
4979 HWRM_CMD_TIMEOUT);
4980}
4981
Michael Chanc0c050c2015-10-22 16:01:17 -04004982int bnxt_hwrm_set_coal(struct bnxt *bp)
4983{
4984 int i, rc = 0;
Michael Chandfc9c942016-02-26 04:00:03 -05004985 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req_rx = {0},
4986 req_tx = {0}, *req;
Michael Chanc0c050c2015-10-22 16:01:17 -04004987
Michael Chandfc9c942016-02-26 04:00:03 -05004988 bnxt_hwrm_cmd_hdr_init(bp, &req_rx,
4989 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1);
4990 bnxt_hwrm_cmd_hdr_init(bp, &req_tx,
4991 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1);
Michael Chanc0c050c2015-10-22 16:01:17 -04004992
Michael Chanf8503962017-10-26 11:51:28 -04004993 bnxt_hwrm_set_coal_params(&bp->rx_coal, &req_rx);
4994 bnxt_hwrm_set_coal_params(&bp->tx_coal, &req_tx);
Michael Chanc0c050c2015-10-22 16:01:17 -04004995
4996 mutex_lock(&bp->hwrm_cmd_lock);
4997 for (i = 0; i < bp->cp_nr_rings; i++) {
Michael Chandfc9c942016-02-26 04:00:03 -05004998 struct bnxt_napi *bnapi = bp->bnapi[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04004999
Michael Chandfc9c942016-02-26 04:00:03 -05005000 req = &req_rx;
5001 if (!bnapi->rx_ring)
5002 req = &req_tx;
5003 req->ring_id = cpu_to_le16(bp->grp_info[i].cp_fw_ring_id);
5004
5005 rc = _hwrm_send_message(bp, req, sizeof(*req),
Michael Chanc0c050c2015-10-22 16:01:17 -04005006 HWRM_CMD_TIMEOUT);
5007 if (rc)
5008 break;
5009 }
5010 mutex_unlock(&bp->hwrm_cmd_lock);
5011 return rc;
5012}
5013
5014static int bnxt_hwrm_stat_ctx_free(struct bnxt *bp)
5015{
5016 int rc = 0, i;
5017 struct hwrm_stat_ctx_free_input req = {0};
5018
5019 if (!bp->bnapi)
5020 return 0;
5021
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04005022 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
5023 return 0;
5024
Michael Chanc0c050c2015-10-22 16:01:17 -04005025 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_STAT_CTX_FREE, -1, -1);
5026
5027 mutex_lock(&bp->hwrm_cmd_lock);
5028 for (i = 0; i < bp->cp_nr_rings; i++) {
5029 struct bnxt_napi *bnapi = bp->bnapi[i];
5030 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
5031
5032 if (cpr->hw_stats_ctx_id != INVALID_STATS_CTX_ID) {
5033 req.stat_ctx_id = cpu_to_le32(cpr->hw_stats_ctx_id);
5034
5035 rc = _hwrm_send_message(bp, &req, sizeof(req),
5036 HWRM_CMD_TIMEOUT);
5037 if (rc)
5038 break;
5039
5040 cpr->hw_stats_ctx_id = INVALID_STATS_CTX_ID;
5041 }
5042 }
5043 mutex_unlock(&bp->hwrm_cmd_lock);
5044 return rc;
5045}
5046
5047static int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp)
5048{
5049 int rc = 0, i;
5050 struct hwrm_stat_ctx_alloc_input req = {0};
5051 struct hwrm_stat_ctx_alloc_output *resp = bp->hwrm_cmd_resp_addr;
5052
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04005053 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
5054 return 0;
5055
Michael Chanc0c050c2015-10-22 16:01:17 -04005056 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_STAT_CTX_ALLOC, -1, -1);
5057
Michael Chan51f30782016-07-01 18:46:29 -04005058 req.update_period_ms = cpu_to_le32(bp->stats_coal_ticks / 1000);
Michael Chanc0c050c2015-10-22 16:01:17 -04005059
5060 mutex_lock(&bp->hwrm_cmd_lock);
5061 for (i = 0; i < bp->cp_nr_rings; i++) {
5062 struct bnxt_napi *bnapi = bp->bnapi[i];
5063 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
5064
5065 req.stats_dma_addr = cpu_to_le64(cpr->hw_stats_map);
5066
5067 rc = _hwrm_send_message(bp, &req, sizeof(req),
5068 HWRM_CMD_TIMEOUT);
5069 if (rc)
5070 break;
5071
5072 cpr->hw_stats_ctx_id = le32_to_cpu(resp->stat_ctx_id);
5073
5074 bp->grp_info[i].fw_stats_ctx = cpr->hw_stats_ctx_id;
5075 }
5076 mutex_unlock(&bp->hwrm_cmd_lock);
Pan Bian89aa8442016-12-03 17:56:17 +08005077 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04005078}
5079
Michael Chancf6645f2016-06-13 02:25:28 -04005080static int bnxt_hwrm_func_qcfg(struct bnxt *bp)
5081{
5082 struct hwrm_func_qcfg_input req = {0};
Satish Baddipadige567b2ab2016-06-13 02:25:31 -04005083 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
Michael Chan9315edc2017-07-24 12:34:25 -04005084 u16 flags;
Michael Chancf6645f2016-06-13 02:25:28 -04005085 int rc;
5086
5087 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCFG, -1, -1);
5088 req.fid = cpu_to_le16(0xffff);
5089 mutex_lock(&bp->hwrm_cmd_lock);
5090 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5091 if (rc)
5092 goto func_qcfg_exit;
5093
5094#ifdef CONFIG_BNXT_SRIOV
5095 if (BNXT_VF(bp)) {
Michael Chancf6645f2016-06-13 02:25:28 -04005096 struct bnxt_vf_info *vf = &bp->vf;
5097
5098 vf->vlan = le16_to_cpu(resp->vlan) & VLAN_VID_MASK;
5099 }
5100#endif
Michael Chan9315edc2017-07-24 12:34:25 -04005101 flags = le16_to_cpu(resp->flags);
5102 if (flags & (FUNC_QCFG_RESP_FLAGS_FW_DCBX_AGENT_ENABLED |
5103 FUNC_QCFG_RESP_FLAGS_FW_LLDP_AGENT_ENABLED)) {
5104 bp->flags |= BNXT_FLAG_FW_LLDP_AGENT;
5105 if (flags & FUNC_QCFG_RESP_FLAGS_FW_DCBX_AGENT_ENABLED)
5106 bp->flags |= BNXT_FLAG_FW_DCBX_AGENT;
Deepak Khungar9e54e322017-04-21 20:11:26 -04005107 }
Michael Chan9315edc2017-07-24 12:34:25 -04005108 if (BNXT_PF(bp) && (flags & FUNC_QCFG_RESP_FLAGS_MULTI_HOST))
5109 bp->flags |= BNXT_FLAG_MULTI_HOST;
Michael Chanbc39f882017-03-08 18:44:34 -05005110
Satish Baddipadige567b2ab2016-06-13 02:25:31 -04005111 switch (resp->port_partition_type) {
5112 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_0:
5113 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_5:
5114 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR2_0:
5115 bp->port_partition_type = resp->port_partition_type;
5116 break;
5117 }
Michael Chan32e8239c2017-07-24 12:34:21 -04005118 if (bp->hwrm_spec_code < 0x10707 ||
5119 resp->evb_mode == FUNC_QCFG_RESP_EVB_MODE_VEB)
5120 bp->br_mode = BRIDGE_MODE_VEB;
5121 else if (resp->evb_mode == FUNC_QCFG_RESP_EVB_MODE_VEPA)
5122 bp->br_mode = BRIDGE_MODE_VEPA;
5123 else
5124 bp->br_mode = BRIDGE_MODE_UNDEF;
Michael Chancf6645f2016-06-13 02:25:28 -04005125
Michael Chan7eb9bb32017-10-26 11:51:25 -04005126 bp->max_mtu = le16_to_cpu(resp->max_mtu_configured);
5127 if (!bp->max_mtu)
5128 bp->max_mtu = BNXT_MAX_MTU;
5129
Michael Chancf6645f2016-06-13 02:25:28 -04005130func_qcfg_exit:
5131 mutex_unlock(&bp->hwrm_cmd_lock);
5132 return rc;
5133}
5134
Michael Chandb4723b2018-03-31 13:54:13 -04005135int bnxt_hwrm_func_resc_qcaps(struct bnxt *bp, bool all)
Michael Chanbe0dd9c2018-01-17 03:21:07 -05005136{
5137 struct hwrm_func_resource_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
5138 struct hwrm_func_resource_qcaps_input req = {0};
5139 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
5140 int rc;
5141
5142 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_RESOURCE_QCAPS, -1, -1);
5143 req.fid = cpu_to_le16(0xffff);
5144
5145 mutex_lock(&bp->hwrm_cmd_lock);
5146 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5147 if (rc) {
5148 rc = -EIO;
5149 goto hwrm_func_resc_qcaps_exit;
5150 }
5151
Michael Chandb4723b2018-03-31 13:54:13 -04005152 hw_resc->max_tx_sch_inputs = le16_to_cpu(resp->max_tx_scheduler_inputs);
5153 if (!all)
5154 goto hwrm_func_resc_qcaps_exit;
5155
Michael Chanbe0dd9c2018-01-17 03:21:07 -05005156 hw_resc->min_rsscos_ctxs = le16_to_cpu(resp->min_rsscos_ctx);
5157 hw_resc->max_rsscos_ctxs = le16_to_cpu(resp->max_rsscos_ctx);
5158 hw_resc->min_cp_rings = le16_to_cpu(resp->min_cmpl_rings);
5159 hw_resc->max_cp_rings = le16_to_cpu(resp->max_cmpl_rings);
5160 hw_resc->min_tx_rings = le16_to_cpu(resp->min_tx_rings);
5161 hw_resc->max_tx_rings = le16_to_cpu(resp->max_tx_rings);
5162 hw_resc->min_rx_rings = le16_to_cpu(resp->min_rx_rings);
5163 hw_resc->max_rx_rings = le16_to_cpu(resp->max_rx_rings);
5164 hw_resc->min_hw_ring_grps = le16_to_cpu(resp->min_hw_ring_grps);
5165 hw_resc->max_hw_ring_grps = le16_to_cpu(resp->max_hw_ring_grps);
5166 hw_resc->min_l2_ctxs = le16_to_cpu(resp->min_l2_ctxs);
5167 hw_resc->max_l2_ctxs = le16_to_cpu(resp->max_l2_ctxs);
5168 hw_resc->min_vnics = le16_to_cpu(resp->min_vnics);
5169 hw_resc->max_vnics = le16_to_cpu(resp->max_vnics);
5170 hw_resc->min_stat_ctxs = le16_to_cpu(resp->min_stat_ctx);
5171 hw_resc->max_stat_ctxs = le16_to_cpu(resp->max_stat_ctx);
5172
Michael Chan4673d662018-01-17 03:21:11 -05005173 if (BNXT_PF(bp)) {
5174 struct bnxt_pf_info *pf = &bp->pf;
5175
5176 pf->vf_resv_strategy =
5177 le16_to_cpu(resp->vf_reservation_strategy);
5178 if (pf->vf_resv_strategy > BNXT_VF_RESV_STRATEGY_MINIMAL)
5179 pf->vf_resv_strategy = BNXT_VF_RESV_STRATEGY_MAXIMAL;
5180 }
Michael Chanbe0dd9c2018-01-17 03:21:07 -05005181hwrm_func_resc_qcaps_exit:
5182 mutex_unlock(&bp->hwrm_cmd_lock);
5183 return rc;
5184}
5185
5186static int __bnxt_hwrm_func_qcaps(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04005187{
5188 int rc = 0;
5189 struct hwrm_func_qcaps_input req = {0};
5190 struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
Michael Chan6a4f2942018-01-17 03:21:06 -05005191 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
5192 u32 flags;
Michael Chanc0c050c2015-10-22 16:01:17 -04005193
5194 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCAPS, -1, -1);
5195 req.fid = cpu_to_le16(0xffff);
5196
5197 mutex_lock(&bp->hwrm_cmd_lock);
5198 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5199 if (rc)
5200 goto hwrm_func_qcaps_exit;
5201
Michael Chan6a4f2942018-01-17 03:21:06 -05005202 flags = le32_to_cpu(resp->flags);
5203 if (flags & FUNC_QCAPS_RESP_FLAGS_ROCE_V1_SUPPORTED)
Michael Chane4060d32016-12-07 00:26:19 -05005204 bp->flags |= BNXT_FLAG_ROCEV1_CAP;
Michael Chan6a4f2942018-01-17 03:21:06 -05005205 if (flags & FUNC_QCAPS_RESP_FLAGS_ROCE_V2_SUPPORTED)
Michael Chane4060d32016-12-07 00:26:19 -05005206 bp->flags |= BNXT_FLAG_ROCEV2_CAP;
5207
Michael Chan7cc5a202016-09-19 03:58:05 -04005208 bp->tx_push_thresh = 0;
Michael Chan6a4f2942018-01-17 03:21:06 -05005209 if (flags & FUNC_QCAPS_RESP_FLAGS_PUSH_MODE_SUPPORTED)
Michael Chan7cc5a202016-09-19 03:58:05 -04005210 bp->tx_push_thresh = BNXT_TX_PUSH_THRESH;
5211
Michael Chan6a4f2942018-01-17 03:21:06 -05005212 hw_resc->max_rsscos_ctxs = le16_to_cpu(resp->max_rsscos_ctx);
5213 hw_resc->max_cp_rings = le16_to_cpu(resp->max_cmpl_rings);
5214 hw_resc->max_tx_rings = le16_to_cpu(resp->max_tx_rings);
5215 hw_resc->max_rx_rings = le16_to_cpu(resp->max_rx_rings);
5216 hw_resc->max_hw_ring_grps = le32_to_cpu(resp->max_hw_ring_grps);
5217 if (!hw_resc->max_hw_ring_grps)
5218 hw_resc->max_hw_ring_grps = hw_resc->max_tx_rings;
5219 hw_resc->max_l2_ctxs = le16_to_cpu(resp->max_l2_ctxs);
5220 hw_resc->max_vnics = le16_to_cpu(resp->max_vnics);
5221 hw_resc->max_stat_ctxs = le16_to_cpu(resp->max_stat_ctx);
5222
Michael Chanc0c050c2015-10-22 16:01:17 -04005223 if (BNXT_PF(bp)) {
5224 struct bnxt_pf_info *pf = &bp->pf;
5225
5226 pf->fw_fid = le16_to_cpu(resp->fid);
5227 pf->port_id = le16_to_cpu(resp->port_id);
Michael Chan87027db2016-07-01 18:46:28 -04005228 bp->dev->dev_port = pf->port_id;
Michael Chan11f15ed2016-04-05 14:08:55 -04005229 memcpy(pf->mac_addr, resp->mac_address, ETH_ALEN);
Michael Chanc0c050c2015-10-22 16:01:17 -04005230 pf->first_vf_id = le16_to_cpu(resp->first_vf_id);
5231 pf->max_vfs = le16_to_cpu(resp->max_vfs);
5232 pf->max_encap_records = le32_to_cpu(resp->max_encap_records);
5233 pf->max_decap_records = le32_to_cpu(resp->max_decap_records);
5234 pf->max_tx_em_flows = le32_to_cpu(resp->max_tx_em_flows);
5235 pf->max_tx_wm_flows = le32_to_cpu(resp->max_tx_wm_flows);
5236 pf->max_rx_em_flows = le32_to_cpu(resp->max_rx_em_flows);
5237 pf->max_rx_wm_flows = le32_to_cpu(resp->max_rx_wm_flows);
Michael Chan6a4f2942018-01-17 03:21:06 -05005238 if (flags & FUNC_QCAPS_RESP_FLAGS_WOL_MAGICPKT_SUPPORTED)
Michael Chanc1ef1462017-04-04 18:14:07 -04005239 bp->flags |= BNXT_FLAG_WOL_CAP;
Michael Chanc0c050c2015-10-22 16:01:17 -04005240 } else {
Michael Chan379a80a2015-10-23 15:06:19 -04005241#ifdef CONFIG_BNXT_SRIOV
Michael Chanc0c050c2015-10-22 16:01:17 -04005242 struct bnxt_vf_info *vf = &bp->vf;
5243
5244 vf->fw_fid = le16_to_cpu(resp->fid);
Michael Chan7cc5a202016-09-19 03:58:05 -04005245 memcpy(vf->mac_addr, resp->mac_address, ETH_ALEN);
Michael Chan379a80a2015-10-23 15:06:19 -04005246#endif
Michael Chanc0c050c2015-10-22 16:01:17 -04005247 }
5248
Michael Chanc0c050c2015-10-22 16:01:17 -04005249hwrm_func_qcaps_exit:
5250 mutex_unlock(&bp->hwrm_cmd_lock);
5251 return rc;
5252}
5253
Michael Chanbe0dd9c2018-01-17 03:21:07 -05005254static int bnxt_hwrm_func_qcaps(struct bnxt *bp)
5255{
5256 int rc;
5257
5258 rc = __bnxt_hwrm_func_qcaps(bp);
5259 if (rc)
5260 return rc;
5261 if (bp->hwrm_spec_code >= 0x10803) {
Michael Chandb4723b2018-03-31 13:54:13 -04005262 rc = bnxt_hwrm_func_resc_qcaps(bp, true);
Michael Chanbe0dd9c2018-01-17 03:21:07 -05005263 if (!rc)
5264 bp->flags |= BNXT_FLAG_NEW_RM;
5265 }
5266 return 0;
5267}
5268
Michael Chanc0c050c2015-10-22 16:01:17 -04005269static int bnxt_hwrm_func_reset(struct bnxt *bp)
5270{
5271 struct hwrm_func_reset_input req = {0};
5272
5273 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_RESET, -1, -1);
5274 req.enables = 0;
5275
5276 return hwrm_send_message(bp, &req, sizeof(req), HWRM_RESET_TIMEOUT);
5277}
5278
5279static int bnxt_hwrm_queue_qportcfg(struct bnxt *bp)
5280{
5281 int rc = 0;
5282 struct hwrm_queue_qportcfg_input req = {0};
5283 struct hwrm_queue_qportcfg_output *resp = bp->hwrm_cmd_resp_addr;
5284 u8 i, *qptr;
5285
5286 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_QUEUE_QPORTCFG, -1, -1);
5287
5288 mutex_lock(&bp->hwrm_cmd_lock);
5289 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5290 if (rc)
5291 goto qportcfg_exit;
5292
5293 if (!resp->max_configurable_queues) {
5294 rc = -EINVAL;
5295 goto qportcfg_exit;
5296 }
5297 bp->max_tc = resp->max_configurable_queues;
Michael Chan87c374d2016-12-02 21:17:16 -05005298 bp->max_lltc = resp->max_configurable_lossless_queues;
Michael Chanc0c050c2015-10-22 16:01:17 -04005299 if (bp->max_tc > BNXT_MAX_QUEUE)
5300 bp->max_tc = BNXT_MAX_QUEUE;
5301
Michael Chan441cabb2016-09-19 03:58:02 -04005302 if (resp->queue_cfg_info & QUEUE_QPORTCFG_RESP_QUEUE_CFG_INFO_ASYM_CFG)
5303 bp->max_tc = 1;
5304
Michael Chan87c374d2016-12-02 21:17:16 -05005305 if (bp->max_lltc > bp->max_tc)
5306 bp->max_lltc = bp->max_tc;
5307
Michael Chanc0c050c2015-10-22 16:01:17 -04005308 qptr = &resp->queue_id0;
5309 for (i = 0; i < bp->max_tc; i++) {
5310 bp->q_info[i].queue_id = *qptr++;
5311 bp->q_info[i].queue_profile = *qptr++;
5312 }
5313
5314qportcfg_exit:
5315 mutex_unlock(&bp->hwrm_cmd_lock);
5316 return rc;
5317}
5318
5319static int bnxt_hwrm_ver_get(struct bnxt *bp)
5320{
5321 int rc;
5322 struct hwrm_ver_get_input req = {0};
5323 struct hwrm_ver_get_output *resp = bp->hwrm_cmd_resp_addr;
Deepak Khungare605db82017-05-29 19:06:04 -04005324 u32 dev_caps_cfg;
Michael Chanc0c050c2015-10-22 16:01:17 -04005325
Michael Chane6ef2692016-03-28 19:46:05 -04005326 bp->hwrm_max_req_len = HWRM_MAX_REQ_LEN;
Michael Chanc0c050c2015-10-22 16:01:17 -04005327 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VER_GET, -1, -1);
5328 req.hwrm_intf_maj = HWRM_VERSION_MAJOR;
5329 req.hwrm_intf_min = HWRM_VERSION_MINOR;
5330 req.hwrm_intf_upd = HWRM_VERSION_UPDATE;
5331 mutex_lock(&bp->hwrm_cmd_lock);
5332 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5333 if (rc)
5334 goto hwrm_ver_get_exit;
5335
5336 memcpy(&bp->ver_resp, resp, sizeof(struct hwrm_ver_get_output));
5337
Michael Chan894aa692018-01-17 03:21:03 -05005338 bp->hwrm_spec_code = resp->hwrm_intf_maj_8b << 16 |
5339 resp->hwrm_intf_min_8b << 8 |
5340 resp->hwrm_intf_upd_8b;
5341 if (resp->hwrm_intf_maj_8b < 1) {
Michael Chanc1935542015-12-27 18:19:28 -05005342 netdev_warn(bp->dev, "HWRM interface %d.%d.%d is older than 1.0.0.\n",
Michael Chan894aa692018-01-17 03:21:03 -05005343 resp->hwrm_intf_maj_8b, resp->hwrm_intf_min_8b,
5344 resp->hwrm_intf_upd_8b);
Michael Chanc1935542015-12-27 18:19:28 -05005345 netdev_warn(bp->dev, "Please update firmware with HWRM interface 1.0.0 or newer.\n");
Michael Chanc0c050c2015-10-22 16:01:17 -04005346 }
Michael Chan431aa1e2017-10-26 11:51:23 -04005347 snprintf(bp->fw_ver_str, BC_HWRM_STR_LEN, "%d.%d.%d.%d",
Michael Chan894aa692018-01-17 03:21:03 -05005348 resp->hwrm_fw_maj_8b, resp->hwrm_fw_min_8b,
5349 resp->hwrm_fw_bld_8b, resp->hwrm_fw_rsvd_8b);
Michael Chanc0c050c2015-10-22 16:01:17 -04005350
Michael Chanff4fe812016-02-26 04:00:04 -05005351 bp->hwrm_cmd_timeout = le16_to_cpu(resp->def_req_timeout);
5352 if (!bp->hwrm_cmd_timeout)
5353 bp->hwrm_cmd_timeout = DFLT_HWRM_CMD_TIMEOUT;
5354
Michael Chan894aa692018-01-17 03:21:03 -05005355 if (resp->hwrm_intf_maj_8b >= 1)
Michael Chane6ef2692016-03-28 19:46:05 -04005356 bp->hwrm_max_req_len = le16_to_cpu(resp->max_req_win_len);
5357
Michael Chan659c8052016-06-13 02:25:33 -04005358 bp->chip_num = le16_to_cpu(resp->chip_num);
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04005359 if (bp->chip_num == CHIP_NUM_58700 && !resp->chip_rev &&
5360 !resp->chip_metal)
5361 bp->flags |= BNXT_FLAG_CHIP_NITRO_A0;
Michael Chan659c8052016-06-13 02:25:33 -04005362
Deepak Khungare605db82017-05-29 19:06:04 -04005363 dev_caps_cfg = le32_to_cpu(resp->dev_caps_cfg);
5364 if ((dev_caps_cfg & VER_GET_RESP_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED) &&
5365 (dev_caps_cfg & VER_GET_RESP_DEV_CAPS_CFG_SHORT_CMD_REQUIRED))
5366 bp->flags |= BNXT_FLAG_SHORT_CMD;
5367
Michael Chanc0c050c2015-10-22 16:01:17 -04005368hwrm_ver_get_exit:
5369 mutex_unlock(&bp->hwrm_cmd_lock);
5370 return rc;
5371}
5372
Rob Swindell5ac67d82016-09-19 03:58:03 -04005373int bnxt_hwrm_fw_set_time(struct bnxt *bp)
5374{
5375 struct hwrm_fw_set_time_input req = {0};
Arnd Bergmann7dfaa7b2017-11-06 15:04:39 +01005376 struct tm tm;
5377 time64_t now = ktime_get_real_seconds();
Rob Swindell5ac67d82016-09-19 03:58:03 -04005378
5379 if (bp->hwrm_spec_code < 0x10400)
5380 return -EOPNOTSUPP;
5381
Arnd Bergmann7dfaa7b2017-11-06 15:04:39 +01005382 time64_to_tm(now, 0, &tm);
Rob Swindell5ac67d82016-09-19 03:58:03 -04005383 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_SET_TIME, -1, -1);
5384 req.year = cpu_to_le16(1900 + tm.tm_year);
5385 req.month = 1 + tm.tm_mon;
5386 req.day = tm.tm_mday;
5387 req.hour = tm.tm_hour;
5388 req.minute = tm.tm_min;
5389 req.second = tm.tm_sec;
5390 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5391}
5392
Michael Chan3bdf56c2016-03-07 15:38:45 -05005393static int bnxt_hwrm_port_qstats(struct bnxt *bp)
5394{
5395 int rc;
5396 struct bnxt_pf_info *pf = &bp->pf;
5397 struct hwrm_port_qstats_input req = {0};
5398
5399 if (!(bp->flags & BNXT_FLAG_PORT_STATS))
5400 return 0;
5401
5402 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_QSTATS, -1, -1);
5403 req.port_id = cpu_to_le16(pf->port_id);
5404 req.tx_stat_host_addr = cpu_to_le64(bp->hw_tx_port_stats_map);
5405 req.rx_stat_host_addr = cpu_to_le64(bp->hw_rx_port_stats_map);
5406 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5407 return rc;
5408}
5409
Vasundhara Volam00db3cb2018-03-31 13:54:12 -04005410static int bnxt_hwrm_port_qstats_ext(struct bnxt *bp)
5411{
5412 struct hwrm_port_qstats_ext_input req = {0};
5413 struct bnxt_pf_info *pf = &bp->pf;
5414
5415 if (!(bp->flags & BNXT_FLAG_PORT_STATS_EXT))
5416 return 0;
5417
5418 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_QSTATS_EXT, -1, -1);
5419 req.port_id = cpu_to_le16(pf->port_id);
5420 req.rx_stat_size = cpu_to_le16(sizeof(struct rx_port_stats_ext));
5421 req.rx_stat_host_addr = cpu_to_le64(bp->hw_rx_port_stats_ext_map);
5422 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5423}
5424
Michael Chanc0c050c2015-10-22 16:01:17 -04005425static void bnxt_hwrm_free_tunnel_ports(struct bnxt *bp)
5426{
5427 if (bp->vxlan_port_cnt) {
5428 bnxt_hwrm_tunnel_dst_port_free(
5429 bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN);
5430 }
5431 bp->vxlan_port_cnt = 0;
5432 if (bp->nge_port_cnt) {
5433 bnxt_hwrm_tunnel_dst_port_free(
5434 bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE);
5435 }
5436 bp->nge_port_cnt = 0;
5437}
5438
5439static int bnxt_set_tpa(struct bnxt *bp, bool set_tpa)
5440{
5441 int rc, i;
5442 u32 tpa_flags = 0;
5443
5444 if (set_tpa)
5445 tpa_flags = bp->flags & BNXT_FLAG_TPA;
5446 for (i = 0; i < bp->nr_vnics; i++) {
5447 rc = bnxt_hwrm_vnic_set_tpa(bp, i, tpa_flags);
5448 if (rc) {
5449 netdev_err(bp->dev, "hwrm vnic set tpa failure rc for vnic %d: %x\n",
Sankar Patchineelam23e12c82017-03-28 19:47:30 -04005450 i, rc);
Michael Chanc0c050c2015-10-22 16:01:17 -04005451 return rc;
5452 }
5453 }
5454 return 0;
5455}
5456
5457static void bnxt_hwrm_clear_vnic_rss(struct bnxt *bp)
5458{
5459 int i;
5460
5461 for (i = 0; i < bp->nr_vnics; i++)
5462 bnxt_hwrm_vnic_set_rss(bp, i, false);
5463}
5464
5465static void bnxt_hwrm_resource_free(struct bnxt *bp, bool close_path,
5466 bool irq_re_init)
5467{
5468 if (bp->vnic_info) {
5469 bnxt_hwrm_clear_vnic_filter(bp);
5470 /* clear all RSS setting before free vnic ctx */
5471 bnxt_hwrm_clear_vnic_rss(bp);
5472 bnxt_hwrm_vnic_ctx_free(bp);
5473 /* before free the vnic, undo the vnic tpa settings */
5474 if (bp->flags & BNXT_FLAG_TPA)
5475 bnxt_set_tpa(bp, false);
5476 bnxt_hwrm_vnic_free(bp);
5477 }
5478 bnxt_hwrm_ring_free(bp, close_path);
5479 bnxt_hwrm_ring_grp_free(bp);
5480 if (irq_re_init) {
5481 bnxt_hwrm_stat_ctx_free(bp);
5482 bnxt_hwrm_free_tunnel_ports(bp);
5483 }
5484}
5485
Michael Chan39d8ba22017-07-24 12:34:22 -04005486static int bnxt_hwrm_set_br_mode(struct bnxt *bp, u16 br_mode)
5487{
5488 struct hwrm_func_cfg_input req = {0};
5489 int rc;
5490
5491 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1);
5492 req.fid = cpu_to_le16(0xffff);
5493 req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_EVB_MODE);
5494 if (br_mode == BRIDGE_MODE_VEB)
5495 req.evb_mode = FUNC_CFG_REQ_EVB_MODE_VEB;
5496 else if (br_mode == BRIDGE_MODE_VEPA)
5497 req.evb_mode = FUNC_CFG_REQ_EVB_MODE_VEPA;
5498 else
5499 return -EINVAL;
5500 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5501 if (rc)
5502 rc = -EIO;
5503 return rc;
5504}
5505
Michael Chanc3480a62018-01-17 03:21:15 -05005506static int bnxt_hwrm_set_cache_line_size(struct bnxt *bp, int size)
5507{
5508 struct hwrm_func_cfg_input req = {0};
5509 int rc;
5510
5511 if (BNXT_VF(bp) || bp->hwrm_spec_code < 0x10803)
5512 return 0;
5513
5514 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1);
5515 req.fid = cpu_to_le16(0xffff);
5516 req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_CACHE_LINESIZE);
Michael Chand4f52de02018-03-31 13:54:06 -04005517 req.options = FUNC_CFG_REQ_OPTIONS_CACHE_LINESIZE_SIZE_64;
Michael Chanc3480a62018-01-17 03:21:15 -05005518 if (size == 128)
Michael Chand4f52de02018-03-31 13:54:06 -04005519 req.options = FUNC_CFG_REQ_OPTIONS_CACHE_LINESIZE_SIZE_128;
Michael Chanc3480a62018-01-17 03:21:15 -05005520
5521 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5522 if (rc)
5523 rc = -EIO;
5524 return rc;
5525}
5526
Michael Chanc0c050c2015-10-22 16:01:17 -04005527static int bnxt_setup_vnic(struct bnxt *bp, u16 vnic_id)
5528{
Michael Chanae10ae72016-12-29 12:13:38 -05005529 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
Michael Chanc0c050c2015-10-22 16:01:17 -04005530 int rc;
5531
Michael Chanae10ae72016-12-29 12:13:38 -05005532 if (vnic->flags & BNXT_VNIC_RFS_NEW_RSS_FLAG)
5533 goto skip_rss_ctx;
5534
Michael Chanc0c050c2015-10-22 16:01:17 -04005535 /* allocate context for vnic */
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04005536 rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic_id, 0);
Michael Chanc0c050c2015-10-22 16:01:17 -04005537 if (rc) {
5538 netdev_err(bp->dev, "hwrm vnic %d alloc failure rc: %x\n",
5539 vnic_id, rc);
5540 goto vnic_setup_err;
5541 }
5542 bp->rsscos_nr_ctxs++;
5543
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04005544 if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
5545 rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic_id, 1);
5546 if (rc) {
5547 netdev_err(bp->dev, "hwrm vnic %d cos ctx alloc failure rc: %x\n",
5548 vnic_id, rc);
5549 goto vnic_setup_err;
5550 }
5551 bp->rsscos_nr_ctxs++;
5552 }
5553
Michael Chanae10ae72016-12-29 12:13:38 -05005554skip_rss_ctx:
Michael Chanc0c050c2015-10-22 16:01:17 -04005555 /* configure default vnic, ring grp */
5556 rc = bnxt_hwrm_vnic_cfg(bp, vnic_id);
5557 if (rc) {
5558 netdev_err(bp->dev, "hwrm vnic %d cfg failure rc: %x\n",
5559 vnic_id, rc);
5560 goto vnic_setup_err;
5561 }
5562
5563 /* Enable RSS hashing on vnic */
5564 rc = bnxt_hwrm_vnic_set_rss(bp, vnic_id, true);
5565 if (rc) {
5566 netdev_err(bp->dev, "hwrm vnic %d set rss failure rc: %x\n",
5567 vnic_id, rc);
5568 goto vnic_setup_err;
5569 }
5570
5571 if (bp->flags & BNXT_FLAG_AGG_RINGS) {
5572 rc = bnxt_hwrm_vnic_set_hds(bp, vnic_id);
5573 if (rc) {
5574 netdev_err(bp->dev, "hwrm vnic %d set hds failure rc: %x\n",
5575 vnic_id, rc);
5576 }
5577 }
5578
5579vnic_setup_err:
5580 return rc;
5581}
5582
5583static int bnxt_alloc_rfs_vnics(struct bnxt *bp)
5584{
5585#ifdef CONFIG_RFS_ACCEL
5586 int i, rc = 0;
5587
5588 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanae10ae72016-12-29 12:13:38 -05005589 struct bnxt_vnic_info *vnic;
Michael Chanc0c050c2015-10-22 16:01:17 -04005590 u16 vnic_id = i + 1;
5591 u16 ring_id = i;
5592
5593 if (vnic_id >= bp->nr_vnics)
5594 break;
5595
Michael Chanae10ae72016-12-29 12:13:38 -05005596 vnic = &bp->vnic_info[vnic_id];
5597 vnic->flags |= BNXT_VNIC_RFS_FLAG;
5598 if (bp->flags & BNXT_FLAG_NEW_RSS_CAP)
5599 vnic->flags |= BNXT_VNIC_RFS_NEW_RSS_FLAG;
Michael Chanb81a90d2016-01-02 23:45:01 -05005600 rc = bnxt_hwrm_vnic_alloc(bp, vnic_id, ring_id, 1);
Michael Chanc0c050c2015-10-22 16:01:17 -04005601 if (rc) {
5602 netdev_err(bp->dev, "hwrm vnic %d alloc failure rc: %x\n",
5603 vnic_id, rc);
5604 break;
5605 }
5606 rc = bnxt_setup_vnic(bp, vnic_id);
5607 if (rc)
5608 break;
5609 }
5610 return rc;
5611#else
5612 return 0;
5613#endif
5614}
5615
Michael Chan17c71ac2016-07-01 18:46:27 -04005616/* Allow PF and VF with default VLAN to be in promiscuous mode */
5617static bool bnxt_promisc_ok(struct bnxt *bp)
5618{
5619#ifdef CONFIG_BNXT_SRIOV
5620 if (BNXT_VF(bp) && !bp->vf.vlan)
5621 return false;
5622#endif
5623 return true;
5624}
5625
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04005626static int bnxt_setup_nitroa0_vnic(struct bnxt *bp)
5627{
5628 unsigned int rc = 0;
5629
5630 rc = bnxt_hwrm_vnic_alloc(bp, 1, bp->rx_nr_rings - 1, 1);
5631 if (rc) {
5632 netdev_err(bp->dev, "Cannot allocate special vnic for NS2 A0: %x\n",
5633 rc);
5634 return rc;
5635 }
5636
5637 rc = bnxt_hwrm_vnic_cfg(bp, 1);
5638 if (rc) {
5639 netdev_err(bp->dev, "Cannot allocate special vnic for NS2 A0: %x\n",
5640 rc);
5641 return rc;
5642 }
5643 return rc;
5644}
5645
Michael Chanb664f002015-12-02 01:54:08 -05005646static int bnxt_cfg_rx_mode(struct bnxt *);
Michael Chan7d2837d2016-05-04 16:56:44 -04005647static bool bnxt_mc_list_updated(struct bnxt *, u32 *);
Michael Chanb664f002015-12-02 01:54:08 -05005648
Michael Chanc0c050c2015-10-22 16:01:17 -04005649static int bnxt_init_chip(struct bnxt *bp, bool irq_re_init)
5650{
Michael Chan7d2837d2016-05-04 16:56:44 -04005651 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
Michael Chanc0c050c2015-10-22 16:01:17 -04005652 int rc = 0;
Prashant Sreedharan76595192016-07-18 07:15:22 -04005653 unsigned int rx_nr_rings = bp->rx_nr_rings;
Michael Chanc0c050c2015-10-22 16:01:17 -04005654
5655 if (irq_re_init) {
5656 rc = bnxt_hwrm_stat_ctx_alloc(bp);
5657 if (rc) {
5658 netdev_err(bp->dev, "hwrm stat ctx alloc failure rc: %x\n",
5659 rc);
5660 goto err_out;
5661 }
5662 }
5663
5664 rc = bnxt_hwrm_ring_alloc(bp);
5665 if (rc) {
5666 netdev_err(bp->dev, "hwrm ring alloc failure rc: %x\n", rc);
5667 goto err_out;
5668 }
5669
5670 rc = bnxt_hwrm_ring_grp_alloc(bp);
5671 if (rc) {
5672 netdev_err(bp->dev, "hwrm_ring_grp alloc failure: %x\n", rc);
5673 goto err_out;
5674 }
5675
Prashant Sreedharan76595192016-07-18 07:15:22 -04005676 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
5677 rx_nr_rings--;
5678
Michael Chanc0c050c2015-10-22 16:01:17 -04005679 /* default vnic 0 */
Prashant Sreedharan76595192016-07-18 07:15:22 -04005680 rc = bnxt_hwrm_vnic_alloc(bp, 0, 0, rx_nr_rings);
Michael Chanc0c050c2015-10-22 16:01:17 -04005681 if (rc) {
5682 netdev_err(bp->dev, "hwrm vnic alloc failure rc: %x\n", rc);
5683 goto err_out;
5684 }
5685
5686 rc = bnxt_setup_vnic(bp, 0);
5687 if (rc)
5688 goto err_out;
5689
5690 if (bp->flags & BNXT_FLAG_RFS) {
5691 rc = bnxt_alloc_rfs_vnics(bp);
5692 if (rc)
5693 goto err_out;
5694 }
5695
5696 if (bp->flags & BNXT_FLAG_TPA) {
5697 rc = bnxt_set_tpa(bp, true);
5698 if (rc)
5699 goto err_out;
5700 }
5701
5702 if (BNXT_VF(bp))
5703 bnxt_update_vf_mac(bp);
5704
5705 /* Filter for default vnic 0 */
5706 rc = bnxt_hwrm_set_vnic_filter(bp, 0, 0, bp->dev->dev_addr);
5707 if (rc) {
5708 netdev_err(bp->dev, "HWRM vnic filter failure rc: %x\n", rc);
5709 goto err_out;
5710 }
Michael Chan7d2837d2016-05-04 16:56:44 -04005711 vnic->uc_filter_count = 1;
Michael Chanc0c050c2015-10-22 16:01:17 -04005712
Michael Chan7d2837d2016-05-04 16:56:44 -04005713 vnic->rx_mask = CFA_L2_SET_RX_MASK_REQ_MASK_BCAST;
Michael Chanc0c050c2015-10-22 16:01:17 -04005714
Michael Chan17c71ac2016-07-01 18:46:27 -04005715 if ((bp->dev->flags & IFF_PROMISC) && bnxt_promisc_ok(bp))
Michael Chan7d2837d2016-05-04 16:56:44 -04005716 vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS;
5717
5718 if (bp->dev->flags & IFF_ALLMULTI) {
5719 vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST;
5720 vnic->mc_list_count = 0;
5721 } else {
5722 u32 mask = 0;
5723
5724 bnxt_mc_list_updated(bp, &mask);
5725 vnic->rx_mask |= mask;
5726 }
Michael Chanc0c050c2015-10-22 16:01:17 -04005727
Michael Chanb664f002015-12-02 01:54:08 -05005728 rc = bnxt_cfg_rx_mode(bp);
5729 if (rc)
Michael Chanc0c050c2015-10-22 16:01:17 -04005730 goto err_out;
Michael Chanc0c050c2015-10-22 16:01:17 -04005731
5732 rc = bnxt_hwrm_set_coal(bp);
5733 if (rc)
5734 netdev_warn(bp->dev, "HWRM set coalescing failure rc: %x\n",
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04005735 rc);
5736
5737 if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
5738 rc = bnxt_setup_nitroa0_vnic(bp);
5739 if (rc)
5740 netdev_err(bp->dev, "Special vnic setup failure for NS2 A0 rc: %x\n",
5741 rc);
5742 }
Michael Chanc0c050c2015-10-22 16:01:17 -04005743
Michael Chancf6645f2016-06-13 02:25:28 -04005744 if (BNXT_VF(bp)) {
5745 bnxt_hwrm_func_qcfg(bp);
5746 netdev_update_features(bp->dev);
5747 }
5748
Michael Chanc0c050c2015-10-22 16:01:17 -04005749 return 0;
5750
5751err_out:
5752 bnxt_hwrm_resource_free(bp, 0, true);
5753
5754 return rc;
5755}
5756
5757static int bnxt_shutdown_nic(struct bnxt *bp, bool irq_re_init)
5758{
5759 bnxt_hwrm_resource_free(bp, 1, irq_re_init);
5760 return 0;
5761}
5762
5763static int bnxt_init_nic(struct bnxt *bp, bool irq_re_init)
5764{
Sankar Patchineelam22479252017-03-28 19:47:29 -04005765 bnxt_init_cp_rings(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04005766 bnxt_init_rx_rings(bp);
5767 bnxt_init_tx_rings(bp);
5768 bnxt_init_ring_grps(bp, irq_re_init);
5769 bnxt_init_vnics(bp);
5770
5771 return bnxt_init_chip(bp, irq_re_init);
5772}
5773
Michael Chanc0c050c2015-10-22 16:01:17 -04005774static int bnxt_set_real_num_queues(struct bnxt *bp)
5775{
5776 int rc;
5777 struct net_device *dev = bp->dev;
5778
Michael Chan5f449242017-02-06 16:55:40 -05005779 rc = netif_set_real_num_tx_queues(dev, bp->tx_nr_rings -
5780 bp->tx_nr_rings_xdp);
Michael Chanc0c050c2015-10-22 16:01:17 -04005781 if (rc)
5782 return rc;
5783
5784 rc = netif_set_real_num_rx_queues(dev, bp->rx_nr_rings);
5785 if (rc)
5786 return rc;
5787
5788#ifdef CONFIG_RFS_ACCEL
Michael Chan45019a12015-12-27 18:19:22 -05005789 if (bp->flags & BNXT_FLAG_RFS)
Michael Chanc0c050c2015-10-22 16:01:17 -04005790 dev->rx_cpu_rmap = alloc_irq_cpu_rmap(bp->rx_nr_rings);
Michael Chanc0c050c2015-10-22 16:01:17 -04005791#endif
5792
5793 return rc;
5794}
5795
Michael Chan6e6c5a52016-01-02 23:45:02 -05005796static int bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max,
5797 bool shared)
5798{
5799 int _rx = *rx, _tx = *tx;
5800
5801 if (shared) {
5802 *rx = min_t(int, _rx, max);
5803 *tx = min_t(int, _tx, max);
5804 } else {
5805 if (max < 2)
5806 return -ENOMEM;
5807
5808 while (_rx + _tx > max) {
5809 if (_rx > _tx && _rx > 1)
5810 _rx--;
5811 else if (_tx > 1)
5812 _tx--;
5813 }
5814 *rx = _rx;
5815 *tx = _tx;
5816 }
5817 return 0;
5818}
5819
Michael Chan78095922016-12-07 00:26:16 -05005820static void bnxt_setup_msix(struct bnxt *bp)
5821{
5822 const int len = sizeof(bp->irq_tbl[0].name);
5823 struct net_device *dev = bp->dev;
5824 int tcs, i;
5825
5826 tcs = netdev_get_num_tc(dev);
5827 if (tcs > 1) {
Michael Chand1e79252017-02-06 16:55:38 -05005828 int i, off, count;
Michael Chan78095922016-12-07 00:26:16 -05005829
Michael Chand1e79252017-02-06 16:55:38 -05005830 for (i = 0; i < tcs; i++) {
5831 count = bp->tx_nr_rings_per_tc;
5832 off = i * count;
5833 netdev_set_tc_queue(dev, i, count, off);
Michael Chan78095922016-12-07 00:26:16 -05005834 }
5835 }
5836
5837 for (i = 0; i < bp->cp_nr_rings; i++) {
Michael Chane5811b82018-03-31 13:54:18 -04005838 int map_idx = bnxt_cp_num_to_irq_num(bp, i);
Michael Chan78095922016-12-07 00:26:16 -05005839 char *attr;
5840
5841 if (bp->flags & BNXT_FLAG_SHARED_RINGS)
5842 attr = "TxRx";
5843 else if (i < bp->rx_nr_rings)
5844 attr = "rx";
5845 else
5846 attr = "tx";
5847
Michael Chane5811b82018-03-31 13:54:18 -04005848 snprintf(bp->irq_tbl[map_idx].name, len, "%s-%s-%d", dev->name,
5849 attr, i);
5850 bp->irq_tbl[map_idx].handler = bnxt_msix;
Michael Chan78095922016-12-07 00:26:16 -05005851 }
5852}
5853
5854static void bnxt_setup_inta(struct bnxt *bp)
5855{
5856 const int len = sizeof(bp->irq_tbl[0].name);
5857
5858 if (netdev_get_num_tc(bp->dev))
5859 netdev_reset_tc(bp->dev);
5860
5861 snprintf(bp->irq_tbl[0].name, len, "%s-%s-%d", bp->dev->name, "TxRx",
5862 0);
5863 bp->irq_tbl[0].handler = bnxt_inta;
5864}
5865
5866static int bnxt_setup_int_mode(struct bnxt *bp)
5867{
5868 int rc;
5869
5870 if (bp->flags & BNXT_FLAG_USING_MSIX)
5871 bnxt_setup_msix(bp);
5872 else
5873 bnxt_setup_inta(bp);
5874
5875 rc = bnxt_set_real_num_queues(bp);
5876 return rc;
5877}
5878
Michael Chanb7429952017-01-13 01:32:00 -05005879#ifdef CONFIG_RFS_ACCEL
Michael Chan8079e8f2016-12-29 12:13:37 -05005880static unsigned int bnxt_get_max_func_rss_ctxs(struct bnxt *bp)
5881{
Michael Chan6a4f2942018-01-17 03:21:06 -05005882 return bp->hw_resc.max_rsscos_ctxs;
Michael Chan8079e8f2016-12-29 12:13:37 -05005883}
5884
5885static unsigned int bnxt_get_max_func_vnics(struct bnxt *bp)
5886{
Michael Chan6a4f2942018-01-17 03:21:06 -05005887 return bp->hw_resc.max_vnics;
Michael Chan8079e8f2016-12-29 12:13:37 -05005888}
Michael Chanb7429952017-01-13 01:32:00 -05005889#endif
Michael Chan8079e8f2016-12-29 12:13:37 -05005890
Michael Chane4060d32016-12-07 00:26:19 -05005891unsigned int bnxt_get_max_func_stat_ctxs(struct bnxt *bp)
5892{
Michael Chan6a4f2942018-01-17 03:21:06 -05005893 return bp->hw_resc.max_stat_ctxs;
Michael Chane4060d32016-12-07 00:26:19 -05005894}
5895
Michael Chana588e452016-12-07 00:26:21 -05005896void bnxt_set_max_func_stat_ctxs(struct bnxt *bp, unsigned int max)
5897{
Michael Chan6a4f2942018-01-17 03:21:06 -05005898 bp->hw_resc.max_stat_ctxs = max;
Michael Chana588e452016-12-07 00:26:21 -05005899}
5900
Michael Chane4060d32016-12-07 00:26:19 -05005901unsigned int bnxt_get_max_func_cp_rings(struct bnxt *bp)
5902{
Michael Chan6a4f2942018-01-17 03:21:06 -05005903 return bp->hw_resc.max_cp_rings;
Michael Chane4060d32016-12-07 00:26:19 -05005904}
5905
Michael Chana588e452016-12-07 00:26:21 -05005906void bnxt_set_max_func_cp_rings(struct bnxt *bp, unsigned int max)
5907{
Michael Chan6a4f2942018-01-17 03:21:06 -05005908 bp->hw_resc.max_cp_rings = max;
Michael Chana588e452016-12-07 00:26:21 -05005909}
5910
Michael Chanfbcfc8e2018-03-31 13:54:20 -04005911unsigned int bnxt_get_max_func_irqs(struct bnxt *bp)
Michael Chan78095922016-12-07 00:26:16 -05005912{
Michael Chan6a4f2942018-01-17 03:21:06 -05005913 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
5914
5915 return min_t(unsigned int, hw_resc->max_irqs, hw_resc->max_cp_rings);
Michael Chan78095922016-12-07 00:26:16 -05005916}
5917
Michael Chan33c26572016-12-07 00:26:15 -05005918void bnxt_set_max_func_irqs(struct bnxt *bp, unsigned int max_irqs)
5919{
Michael Chan6a4f2942018-01-17 03:21:06 -05005920 bp->hw_resc.max_irqs = max_irqs;
Michael Chan33c26572016-12-07 00:26:15 -05005921}
5922
Michael Chanfbcfc8e2018-03-31 13:54:20 -04005923int bnxt_get_avail_msix(struct bnxt *bp, int num)
5924{
5925 int max_cp = bnxt_get_max_func_cp_rings(bp);
5926 int max_irq = bnxt_get_max_func_irqs(bp);
5927 int total_req = bp->cp_nr_rings + num;
5928 int max_idx, avail_msix;
5929
5930 max_idx = min_t(int, bp->total_irqs, max_cp);
5931 avail_msix = max_idx - bp->cp_nr_rings;
5932 if (!(bp->flags & BNXT_FLAG_NEW_RM) || avail_msix >= num)
5933 return avail_msix;
5934
5935 if (max_irq < total_req) {
5936 num = max_irq - bp->cp_nr_rings;
5937 if (num <= 0)
5938 return 0;
5939 }
5940 return num;
5941}
5942
Michael Chan08654eb2018-03-31 13:54:17 -04005943static int bnxt_get_num_msix(struct bnxt *bp)
5944{
5945 if (!(bp->flags & BNXT_FLAG_NEW_RM))
5946 return bnxt_get_max_func_irqs(bp);
5947
5948 return bnxt_cp_rings_in_use(bp);
5949}
5950
Michael Chan78095922016-12-07 00:26:16 -05005951static int bnxt_init_msix(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04005952{
Michael Chanfbcfc8e2018-03-31 13:54:20 -04005953 int i, total_vecs, max, rc = 0, min = 1, ulp_msix;
Michael Chan78095922016-12-07 00:26:16 -05005954 struct msix_entry *msix_ent;
Michael Chanc0c050c2015-10-22 16:01:17 -04005955
Michael Chan08654eb2018-03-31 13:54:17 -04005956 total_vecs = bnxt_get_num_msix(bp);
5957 max = bnxt_get_max_func_irqs(bp);
5958 if (total_vecs > max)
5959 total_vecs = max;
5960
Michael Chanc0c050c2015-10-22 16:01:17 -04005961 msix_ent = kcalloc(total_vecs, sizeof(struct msix_entry), GFP_KERNEL);
5962 if (!msix_ent)
5963 return -ENOMEM;
5964
5965 for (i = 0; i < total_vecs; i++) {
5966 msix_ent[i].entry = i;
5967 msix_ent[i].vector = 0;
5968 }
5969
Michael Chan01657bc2016-01-02 23:45:03 -05005970 if (!(bp->flags & BNXT_FLAG_SHARED_RINGS))
5971 min = 2;
5972
5973 total_vecs = pci_enable_msix_range(bp->pdev, msix_ent, min, total_vecs);
Michael Chanfbcfc8e2018-03-31 13:54:20 -04005974 ulp_msix = bnxt_get_ulp_msix_num(bp);
5975 if (total_vecs < 0 || total_vecs < ulp_msix) {
Michael Chanc0c050c2015-10-22 16:01:17 -04005976 rc = -ENODEV;
5977 goto msix_setup_exit;
5978 }
5979
5980 bp->irq_tbl = kcalloc(total_vecs, sizeof(struct bnxt_irq), GFP_KERNEL);
5981 if (bp->irq_tbl) {
Michael Chan78095922016-12-07 00:26:16 -05005982 for (i = 0; i < total_vecs; i++)
5983 bp->irq_tbl[i].vector = msix_ent[i].vector;
Michael Chanc0c050c2015-10-22 16:01:17 -04005984
Michael Chan78095922016-12-07 00:26:16 -05005985 bp->total_irqs = total_vecs;
Michael Chanc0c050c2015-10-22 16:01:17 -04005986 /* Trim rings based upon num of vectors allocated */
Michael Chan6e6c5a52016-01-02 23:45:02 -05005987 rc = bnxt_trim_rings(bp, &bp->rx_nr_rings, &bp->tx_nr_rings,
Michael Chanfbcfc8e2018-03-31 13:54:20 -04005988 total_vecs - ulp_msix, min == 1);
Michael Chan6e6c5a52016-01-02 23:45:02 -05005989 if (rc)
5990 goto msix_setup_exit;
5991
Michael Chan78095922016-12-07 00:26:16 -05005992 bp->cp_nr_rings = (min == 1) ?
5993 max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
5994 bp->tx_nr_rings + bp->rx_nr_rings;
Michael Chanc0c050c2015-10-22 16:01:17 -04005995
Michael Chanc0c050c2015-10-22 16:01:17 -04005996 } else {
5997 rc = -ENOMEM;
5998 goto msix_setup_exit;
5999 }
6000 bp->flags |= BNXT_FLAG_USING_MSIX;
6001 kfree(msix_ent);
6002 return 0;
6003
6004msix_setup_exit:
Michael Chan78095922016-12-07 00:26:16 -05006005 netdev_err(bp->dev, "bnxt_init_msix err: %x\n", rc);
6006 kfree(bp->irq_tbl);
6007 bp->irq_tbl = NULL;
Michael Chanc0c050c2015-10-22 16:01:17 -04006008 pci_disable_msix(bp->pdev);
6009 kfree(msix_ent);
6010 return rc;
6011}
6012
Michael Chan78095922016-12-07 00:26:16 -05006013static int bnxt_init_inta(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04006014{
Michael Chanc0c050c2015-10-22 16:01:17 -04006015 bp->irq_tbl = kcalloc(1, sizeof(struct bnxt_irq), GFP_KERNEL);
Michael Chan78095922016-12-07 00:26:16 -05006016 if (!bp->irq_tbl)
6017 return -ENOMEM;
6018
6019 bp->total_irqs = 1;
Michael Chanc0c050c2015-10-22 16:01:17 -04006020 bp->rx_nr_rings = 1;
6021 bp->tx_nr_rings = 1;
6022 bp->cp_nr_rings = 1;
Michael Chan01657bc2016-01-02 23:45:03 -05006023 bp->flags |= BNXT_FLAG_SHARED_RINGS;
Michael Chanc0c050c2015-10-22 16:01:17 -04006024 bp->irq_tbl[0].vector = bp->pdev->irq;
Michael Chan78095922016-12-07 00:26:16 -05006025 return 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04006026}
6027
Michael Chan78095922016-12-07 00:26:16 -05006028static int bnxt_init_int_mode(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04006029{
6030 int rc = 0;
6031
6032 if (bp->flags & BNXT_FLAG_MSIX_CAP)
Michael Chan78095922016-12-07 00:26:16 -05006033 rc = bnxt_init_msix(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04006034
Michael Chan1fa72e22016-04-25 02:30:49 -04006035 if (!(bp->flags & BNXT_FLAG_USING_MSIX) && BNXT_PF(bp)) {
Michael Chanc0c050c2015-10-22 16:01:17 -04006036 /* fallback to INTA */
Michael Chan78095922016-12-07 00:26:16 -05006037 rc = bnxt_init_inta(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04006038 }
6039 return rc;
6040}
6041
Michael Chan78095922016-12-07 00:26:16 -05006042static void bnxt_clear_int_mode(struct bnxt *bp)
6043{
6044 if (bp->flags & BNXT_FLAG_USING_MSIX)
6045 pci_disable_msix(bp->pdev);
6046
6047 kfree(bp->irq_tbl);
6048 bp->irq_tbl = NULL;
6049 bp->flags &= ~BNXT_FLAG_USING_MSIX;
6050}
6051
Michael Chanfbcfc8e2018-03-31 13:54:20 -04006052int bnxt_reserve_rings(struct bnxt *bp)
Michael Chan674f50a2018-01-17 03:21:09 -05006053{
Michael Chan674f50a2018-01-17 03:21:09 -05006054 int tcs = netdev_get_num_tc(bp->dev);
6055 int rc;
6056
6057 if (!bnxt_need_reserve_rings(bp))
6058 return 0;
6059
6060 rc = __bnxt_reserve_rings(bp);
6061 if (rc) {
6062 netdev_err(bp->dev, "ring reservation failure rc: %d\n", rc);
6063 return rc;
6064 }
Michael Chanfbcfc8e2018-03-31 13:54:20 -04006065 if ((bp->flags & BNXT_FLAG_NEW_RM) &&
6066 (bnxt_get_num_msix(bp) != bp->total_irqs)) {
Michael Chan674f50a2018-01-17 03:21:09 -05006067 bnxt_clear_int_mode(bp);
6068 rc = bnxt_init_int_mode(bp);
6069 if (rc)
6070 return rc;
6071 }
6072 if (tcs && (bp->tx_nr_rings_per_tc * tcs != bp->tx_nr_rings)) {
6073 netdev_err(bp->dev, "tx ring reservation failure\n");
6074 netdev_reset_tc(bp->dev);
6075 bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
6076 return -ENOMEM;
6077 }
6078 bp->num_stat_ctxs = bp->cp_nr_rings;
6079 return 0;
6080}
6081
Michael Chanc0c050c2015-10-22 16:01:17 -04006082static void bnxt_free_irq(struct bnxt *bp)
6083{
6084 struct bnxt_irq *irq;
6085 int i;
6086
6087#ifdef CONFIG_RFS_ACCEL
6088 free_irq_cpu_rmap(bp->dev->rx_cpu_rmap);
6089 bp->dev->rx_cpu_rmap = NULL;
6090#endif
6091 if (!bp->irq_tbl)
6092 return;
6093
6094 for (i = 0; i < bp->cp_nr_rings; i++) {
Michael Chane5811b82018-03-31 13:54:18 -04006095 int map_idx = bnxt_cp_num_to_irq_num(bp, i);
6096
6097 irq = &bp->irq_tbl[map_idx];
Vasundhara Volam56f0fd82017-08-28 13:40:27 -04006098 if (irq->requested) {
6099 if (irq->have_cpumask) {
6100 irq_set_affinity_hint(irq->vector, NULL);
6101 free_cpumask_var(irq->cpu_mask);
6102 irq->have_cpumask = 0;
6103 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006104 free_irq(irq->vector, bp->bnapi[i]);
Vasundhara Volam56f0fd82017-08-28 13:40:27 -04006105 }
6106
Michael Chanc0c050c2015-10-22 16:01:17 -04006107 irq->requested = 0;
6108 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006109}
6110
6111static int bnxt_request_irq(struct bnxt *bp)
6112{
Michael Chanb81a90d2016-01-02 23:45:01 -05006113 int i, j, rc = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04006114 unsigned long flags = 0;
6115#ifdef CONFIG_RFS_ACCEL
Michael Chane5811b82018-03-31 13:54:18 -04006116 struct cpu_rmap *rmap;
Michael Chanc0c050c2015-10-22 16:01:17 -04006117#endif
6118
Michael Chane5811b82018-03-31 13:54:18 -04006119 rc = bnxt_setup_int_mode(bp);
6120 if (rc) {
6121 netdev_err(bp->dev, "bnxt_setup_int_mode err: %x\n",
6122 rc);
6123 return rc;
6124 }
6125#ifdef CONFIG_RFS_ACCEL
6126 rmap = bp->dev->rx_cpu_rmap;
6127#endif
Michael Chanc0c050c2015-10-22 16:01:17 -04006128 if (!(bp->flags & BNXT_FLAG_USING_MSIX))
6129 flags = IRQF_SHARED;
6130
Michael Chanb81a90d2016-01-02 23:45:01 -05006131 for (i = 0, j = 0; i < bp->cp_nr_rings; i++) {
Michael Chane5811b82018-03-31 13:54:18 -04006132 int map_idx = bnxt_cp_num_to_irq_num(bp, i);
6133 struct bnxt_irq *irq = &bp->irq_tbl[map_idx];
6134
Michael Chanc0c050c2015-10-22 16:01:17 -04006135#ifdef CONFIG_RFS_ACCEL
Michael Chanb81a90d2016-01-02 23:45:01 -05006136 if (rmap && bp->bnapi[i]->rx_ring) {
Michael Chanc0c050c2015-10-22 16:01:17 -04006137 rc = irq_cpu_rmap_add(rmap, irq->vector);
6138 if (rc)
6139 netdev_warn(bp->dev, "failed adding irq rmap for ring %d\n",
Michael Chanb81a90d2016-01-02 23:45:01 -05006140 j);
6141 j++;
Michael Chanc0c050c2015-10-22 16:01:17 -04006142 }
6143#endif
6144 rc = request_irq(irq->vector, irq->handler, flags, irq->name,
6145 bp->bnapi[i]);
6146 if (rc)
6147 break;
6148
6149 irq->requested = 1;
Vasundhara Volam56f0fd82017-08-28 13:40:27 -04006150
6151 if (zalloc_cpumask_var(&irq->cpu_mask, GFP_KERNEL)) {
6152 int numa_node = dev_to_node(&bp->pdev->dev);
6153
6154 irq->have_cpumask = 1;
6155 cpumask_set_cpu(cpumask_local_spread(i, numa_node),
6156 irq->cpu_mask);
6157 rc = irq_set_affinity_hint(irq->vector, irq->cpu_mask);
6158 if (rc) {
6159 netdev_warn(bp->dev,
6160 "Set affinity failed, IRQ = %d\n",
6161 irq->vector);
6162 break;
6163 }
6164 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006165 }
6166 return rc;
6167}
6168
6169static void bnxt_del_napi(struct bnxt *bp)
6170{
6171 int i;
6172
6173 if (!bp->bnapi)
6174 return;
6175
6176 for (i = 0; i < bp->cp_nr_rings; i++) {
6177 struct bnxt_napi *bnapi = bp->bnapi[i];
6178
6179 napi_hash_del(&bnapi->napi);
6180 netif_napi_del(&bnapi->napi);
6181 }
Eric Dumazete5f6f562016-11-16 06:31:52 -08006182 /* We called napi_hash_del() before netif_napi_del(), we need
6183 * to respect an RCU grace period before freeing napi structures.
6184 */
6185 synchronize_net();
Michael Chanc0c050c2015-10-22 16:01:17 -04006186}
6187
6188static void bnxt_init_napi(struct bnxt *bp)
6189{
6190 int i;
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04006191 unsigned int cp_nr_rings = bp->cp_nr_rings;
Michael Chanc0c050c2015-10-22 16:01:17 -04006192 struct bnxt_napi *bnapi;
6193
6194 if (bp->flags & BNXT_FLAG_USING_MSIX) {
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04006195 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
6196 cp_nr_rings--;
6197 for (i = 0; i < cp_nr_rings; i++) {
Michael Chanc0c050c2015-10-22 16:01:17 -04006198 bnapi = bp->bnapi[i];
6199 netif_napi_add(bp->dev, &bnapi->napi,
6200 bnxt_poll, 64);
Michael Chanc0c050c2015-10-22 16:01:17 -04006201 }
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04006202 if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
6203 bnapi = bp->bnapi[cp_nr_rings];
6204 netif_napi_add(bp->dev, &bnapi->napi,
6205 bnxt_poll_nitroa0, 64);
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04006206 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006207 } else {
6208 bnapi = bp->bnapi[0];
6209 netif_napi_add(bp->dev, &bnapi->napi, bnxt_poll, 64);
Michael Chanc0c050c2015-10-22 16:01:17 -04006210 }
6211}
6212
6213static void bnxt_disable_napi(struct bnxt *bp)
6214{
6215 int i;
6216
6217 if (!bp->bnapi)
6218 return;
6219
Andy Gospodarek0bc0b972018-01-26 10:27:47 -05006220 for (i = 0; i < bp->cp_nr_rings; i++) {
6221 struct bnxt_cp_ring_info *cpr = &bp->bnapi[i]->cp_ring;
6222
6223 if (bp->bnapi[i]->rx_ring)
6224 cancel_work_sync(&cpr->dim.work);
6225
Michael Chanc0c050c2015-10-22 16:01:17 -04006226 napi_disable(&bp->bnapi[i]->napi);
Andy Gospodarek0bc0b972018-01-26 10:27:47 -05006227 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006228}
6229
6230static void bnxt_enable_napi(struct bnxt *bp)
6231{
6232 int i;
6233
6234 for (i = 0; i < bp->cp_nr_rings; i++) {
Andy Gospodarek6a8788f2018-01-09 16:06:20 -05006235 struct bnxt_cp_ring_info *cpr = &bp->bnapi[i]->cp_ring;
Michael Chanfa7e2812016-05-10 19:18:00 -04006236 bp->bnapi[i]->in_reset = false;
Andy Gospodarek6a8788f2018-01-09 16:06:20 -05006237
6238 if (bp->bnapi[i]->rx_ring) {
6239 INIT_WORK(&cpr->dim.work, bnxt_dim_work);
6240 cpr->dim.mode = NET_DIM_CQ_PERIOD_MODE_START_FROM_EQE;
6241 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006242 napi_enable(&bp->bnapi[i]->napi);
6243 }
6244}
6245
Michael Chan7df4ae92016-12-02 21:17:17 -05006246void bnxt_tx_disable(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04006247{
6248 int i;
Michael Chanc0c050c2015-10-22 16:01:17 -04006249 struct bnxt_tx_ring_info *txr;
Michael Chanc0c050c2015-10-22 16:01:17 -04006250
Michael Chanb6ab4b02016-01-02 23:44:59 -05006251 if (bp->tx_ring) {
Michael Chanc0c050c2015-10-22 16:01:17 -04006252 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05006253 txr = &bp->tx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04006254 txr->dev_state = BNXT_DEV_STATE_CLOSING;
Michael Chanc0c050c2015-10-22 16:01:17 -04006255 }
6256 }
6257 /* Stop all TX queues */
6258 netif_tx_disable(bp->dev);
6259 netif_carrier_off(bp->dev);
6260}
6261
Michael Chan7df4ae92016-12-02 21:17:17 -05006262void bnxt_tx_enable(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04006263{
6264 int i;
Michael Chanc0c050c2015-10-22 16:01:17 -04006265 struct bnxt_tx_ring_info *txr;
Michael Chanc0c050c2015-10-22 16:01:17 -04006266
6267 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05006268 txr = &bp->tx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04006269 txr->dev_state = 0;
6270 }
6271 netif_tx_wake_all_queues(bp->dev);
6272 if (bp->link_info.link_up)
6273 netif_carrier_on(bp->dev);
6274}
6275
6276static void bnxt_report_link(struct bnxt *bp)
6277{
6278 if (bp->link_info.link_up) {
6279 const char *duplex;
6280 const char *flow_ctrl;
Deepak Khungar38a21b32017-04-21 20:11:24 -04006281 u32 speed;
6282 u16 fec;
Michael Chanc0c050c2015-10-22 16:01:17 -04006283
6284 netif_carrier_on(bp->dev);
6285 if (bp->link_info.duplex == BNXT_LINK_DUPLEX_FULL)
6286 duplex = "full";
6287 else
6288 duplex = "half";
6289 if (bp->link_info.pause == BNXT_LINK_PAUSE_BOTH)
6290 flow_ctrl = "ON - receive & transmit";
6291 else if (bp->link_info.pause == BNXT_LINK_PAUSE_TX)
6292 flow_ctrl = "ON - transmit";
6293 else if (bp->link_info.pause == BNXT_LINK_PAUSE_RX)
6294 flow_ctrl = "ON - receive";
6295 else
6296 flow_ctrl = "none";
6297 speed = bnxt_fw_to_ethtool_speed(bp->link_info.link_speed);
Deepak Khungar38a21b32017-04-21 20:11:24 -04006298 netdev_info(bp->dev, "NIC Link is Up, %u Mbps %s duplex, Flow control: %s\n",
Michael Chanc0c050c2015-10-22 16:01:17 -04006299 speed, duplex, flow_ctrl);
Michael Chan170ce012016-04-05 14:08:57 -04006300 if (bp->flags & BNXT_FLAG_EEE_CAP)
6301 netdev_info(bp->dev, "EEE is %s\n",
6302 bp->eee.eee_active ? "active" :
6303 "not active");
Michael Chane70c7522017-02-12 19:18:16 -05006304 fec = bp->link_info.fec_cfg;
6305 if (!(fec & PORT_PHY_QCFG_RESP_FEC_CFG_FEC_NONE_SUPPORTED))
6306 netdev_info(bp->dev, "FEC autoneg %s encodings: %s\n",
6307 (fec & BNXT_FEC_AUTONEG) ? "on" : "off",
6308 (fec & BNXT_FEC_ENC_BASE_R) ? "BaseR" :
6309 (fec & BNXT_FEC_ENC_RS) ? "RS" : "None");
Michael Chanc0c050c2015-10-22 16:01:17 -04006310 } else {
6311 netif_carrier_off(bp->dev);
6312 netdev_err(bp->dev, "NIC Link is Down\n");
6313 }
6314}
6315
Michael Chan170ce012016-04-05 14:08:57 -04006316static int bnxt_hwrm_phy_qcaps(struct bnxt *bp)
6317{
6318 int rc = 0;
6319 struct hwrm_port_phy_qcaps_input req = {0};
6320 struct hwrm_port_phy_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
Michael Chan93ed8112016-06-13 02:25:37 -04006321 struct bnxt_link_info *link_info = &bp->link_info;
Michael Chan170ce012016-04-05 14:08:57 -04006322
6323 if (bp->hwrm_spec_code < 0x10201)
6324 return 0;
6325
6326 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCAPS, -1, -1);
6327
6328 mutex_lock(&bp->hwrm_cmd_lock);
6329 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6330 if (rc)
6331 goto hwrm_phy_qcaps_exit;
6332
Michael Chanacb20052017-07-24 12:34:20 -04006333 if (resp->flags & PORT_PHY_QCAPS_RESP_FLAGS_EEE_SUPPORTED) {
Michael Chan170ce012016-04-05 14:08:57 -04006334 struct ethtool_eee *eee = &bp->eee;
6335 u16 fw_speeds = le16_to_cpu(resp->supported_speeds_eee_mode);
6336
6337 bp->flags |= BNXT_FLAG_EEE_CAP;
6338 eee->supported = _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0);
6339 bp->lpi_tmr_lo = le32_to_cpu(resp->tx_lpi_timer_low) &
6340 PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_LOW_MASK;
6341 bp->lpi_tmr_hi = le32_to_cpu(resp->valid_tx_lpi_timer_high) &
6342 PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_HIGH_MASK;
6343 }
Michael Chan520ad892017-03-08 18:44:35 -05006344 if (resp->supported_speeds_auto_mode)
6345 link_info->support_auto_speeds =
6346 le16_to_cpu(resp->supported_speeds_auto_mode);
Michael Chan170ce012016-04-05 14:08:57 -04006347
Michael Chand5430d32017-08-28 13:40:31 -04006348 bp->port_count = resp->port_cnt;
6349
Michael Chan170ce012016-04-05 14:08:57 -04006350hwrm_phy_qcaps_exit:
6351 mutex_unlock(&bp->hwrm_cmd_lock);
6352 return rc;
6353}
6354
Michael Chanc0c050c2015-10-22 16:01:17 -04006355static int bnxt_update_link(struct bnxt *bp, bool chng_link_state)
6356{
6357 int rc = 0;
6358 struct bnxt_link_info *link_info = &bp->link_info;
6359 struct hwrm_port_phy_qcfg_input req = {0};
6360 struct hwrm_port_phy_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
6361 u8 link_up = link_info->link_up;
Michael Chan286ef9d2016-11-16 21:13:08 -05006362 u16 diff;
Michael Chanc0c050c2015-10-22 16:01:17 -04006363
6364 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCFG, -1, -1);
6365
6366 mutex_lock(&bp->hwrm_cmd_lock);
6367 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6368 if (rc) {
6369 mutex_unlock(&bp->hwrm_cmd_lock);
6370 return rc;
6371 }
6372
6373 memcpy(&link_info->phy_qcfg_resp, resp, sizeof(*resp));
6374 link_info->phy_link_status = resp->link;
Michael Chanacb20052017-07-24 12:34:20 -04006375 link_info->duplex = resp->duplex_cfg;
6376 if (bp->hwrm_spec_code >= 0x10800)
6377 link_info->duplex = resp->duplex_state;
Michael Chanc0c050c2015-10-22 16:01:17 -04006378 link_info->pause = resp->pause;
6379 link_info->auto_mode = resp->auto_mode;
6380 link_info->auto_pause_setting = resp->auto_pause;
Michael Chan32773602016-03-07 15:38:42 -05006381 link_info->lp_pause = resp->link_partner_adv_pause;
Michael Chanc0c050c2015-10-22 16:01:17 -04006382 link_info->force_pause_setting = resp->force_pause;
Michael Chanacb20052017-07-24 12:34:20 -04006383 link_info->duplex_setting = resp->duplex_cfg;
Michael Chanc0c050c2015-10-22 16:01:17 -04006384 if (link_info->phy_link_status == BNXT_LINK_LINK)
6385 link_info->link_speed = le16_to_cpu(resp->link_speed);
6386 else
6387 link_info->link_speed = 0;
6388 link_info->force_link_speed = le16_to_cpu(resp->force_link_speed);
Michael Chanc0c050c2015-10-22 16:01:17 -04006389 link_info->support_speeds = le16_to_cpu(resp->support_speeds);
6390 link_info->auto_link_speeds = le16_to_cpu(resp->auto_link_speed_mask);
Michael Chan32773602016-03-07 15:38:42 -05006391 link_info->lp_auto_link_speeds =
6392 le16_to_cpu(resp->link_partner_adv_speeds);
Michael Chanc0c050c2015-10-22 16:01:17 -04006393 link_info->preemphasis = le32_to_cpu(resp->preemphasis);
6394 link_info->phy_ver[0] = resp->phy_maj;
6395 link_info->phy_ver[1] = resp->phy_min;
6396 link_info->phy_ver[2] = resp->phy_bld;
6397 link_info->media_type = resp->media_type;
Michael Chan03efbec2016-04-11 04:11:11 -04006398 link_info->phy_type = resp->phy_type;
Michael Chan11f15ed2016-04-05 14:08:55 -04006399 link_info->transceiver = resp->xcvr_pkg_type;
Michael Chan170ce012016-04-05 14:08:57 -04006400 link_info->phy_addr = resp->eee_config_phy_addr &
6401 PORT_PHY_QCFG_RESP_PHY_ADDR_MASK;
Ajit Khaparde42ee18f2016-05-15 03:04:44 -04006402 link_info->module_status = resp->module_status;
Michael Chanc0c050c2015-10-22 16:01:17 -04006403
Michael Chan170ce012016-04-05 14:08:57 -04006404 if (bp->flags & BNXT_FLAG_EEE_CAP) {
6405 struct ethtool_eee *eee = &bp->eee;
6406 u16 fw_speeds;
6407
6408 eee->eee_active = 0;
6409 if (resp->eee_config_phy_addr &
6410 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ACTIVE) {
6411 eee->eee_active = 1;
6412 fw_speeds = le16_to_cpu(
6413 resp->link_partner_adv_eee_link_speed_mask);
6414 eee->lp_advertised =
6415 _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0);
6416 }
6417
6418 /* Pull initial EEE config */
6419 if (!chng_link_state) {
6420 if (resp->eee_config_phy_addr &
6421 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ENABLED)
6422 eee->eee_enabled = 1;
6423
6424 fw_speeds = le16_to_cpu(resp->adv_eee_link_speed_mask);
6425 eee->advertised =
6426 _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0);
6427
6428 if (resp->eee_config_phy_addr &
6429 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_TX_LPI) {
6430 __le32 tmr;
6431
6432 eee->tx_lpi_enabled = 1;
6433 tmr = resp->xcvr_identifier_type_tx_lpi_timer;
6434 eee->tx_lpi_timer = le32_to_cpu(tmr) &
6435 PORT_PHY_QCFG_RESP_TX_LPI_TIMER_MASK;
6436 }
6437 }
6438 }
Michael Chane70c7522017-02-12 19:18:16 -05006439
6440 link_info->fec_cfg = PORT_PHY_QCFG_RESP_FEC_CFG_FEC_NONE_SUPPORTED;
6441 if (bp->hwrm_spec_code >= 0x10504)
6442 link_info->fec_cfg = le16_to_cpu(resp->fec_cfg);
6443
Michael Chanc0c050c2015-10-22 16:01:17 -04006444 /* TODO: need to add more logic to report VF link */
6445 if (chng_link_state) {
6446 if (link_info->phy_link_status == BNXT_LINK_LINK)
6447 link_info->link_up = 1;
6448 else
6449 link_info->link_up = 0;
6450 if (link_up != link_info->link_up)
6451 bnxt_report_link(bp);
6452 } else {
6453 /* alwasy link down if not require to update link state */
6454 link_info->link_up = 0;
6455 }
6456 mutex_unlock(&bp->hwrm_cmd_lock);
Michael Chan286ef9d2016-11-16 21:13:08 -05006457
6458 diff = link_info->support_auto_speeds ^ link_info->advertising;
6459 if ((link_info->support_auto_speeds | diff) !=
6460 link_info->support_auto_speeds) {
6461 /* An advertised speed is no longer supported, so we need to
Michael Chan0eaa24b2017-01-25 02:55:08 -05006462 * update the advertisement settings. Caller holds RTNL
6463 * so we can modify link settings.
Michael Chan286ef9d2016-11-16 21:13:08 -05006464 */
Michael Chan286ef9d2016-11-16 21:13:08 -05006465 link_info->advertising = link_info->support_auto_speeds;
Michael Chan0eaa24b2017-01-25 02:55:08 -05006466 if (link_info->autoneg & BNXT_AUTONEG_SPEED)
Michael Chan286ef9d2016-11-16 21:13:08 -05006467 bnxt_hwrm_set_link_setting(bp, true, false);
Michael Chan286ef9d2016-11-16 21:13:08 -05006468 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006469 return 0;
6470}
6471
Michael Chan10289be2016-05-15 03:04:49 -04006472static void bnxt_get_port_module_status(struct bnxt *bp)
6473{
6474 struct bnxt_link_info *link_info = &bp->link_info;
6475 struct hwrm_port_phy_qcfg_output *resp = &link_info->phy_qcfg_resp;
6476 u8 module_status;
6477
6478 if (bnxt_update_link(bp, true))
6479 return;
6480
6481 module_status = link_info->module_status;
6482 switch (module_status) {
6483 case PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX:
6484 case PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN:
6485 case PORT_PHY_QCFG_RESP_MODULE_STATUS_WARNINGMSG:
6486 netdev_warn(bp->dev, "Unqualified SFP+ module detected on port %d\n",
6487 bp->pf.port_id);
6488 if (bp->hwrm_spec_code >= 0x10201) {
6489 netdev_warn(bp->dev, "Module part number %s\n",
6490 resp->phy_vendor_partnumber);
6491 }
6492 if (module_status == PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX)
6493 netdev_warn(bp->dev, "TX is disabled\n");
6494 if (module_status == PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN)
6495 netdev_warn(bp->dev, "SFP+ module is shutdown\n");
6496 }
6497}
6498
Michael Chanc0c050c2015-10-22 16:01:17 -04006499static void
6500bnxt_hwrm_set_pause_common(struct bnxt *bp, struct hwrm_port_phy_cfg_input *req)
6501{
6502 if (bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL) {
Michael Chanc9ee9512016-04-05 14:08:56 -04006503 if (bp->hwrm_spec_code >= 0x10201)
6504 req->auto_pause =
6505 PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE;
Michael Chanc0c050c2015-10-22 16:01:17 -04006506 if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_RX)
6507 req->auto_pause |= PORT_PHY_CFG_REQ_AUTO_PAUSE_RX;
6508 if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_TX)
Michael Chan49b5c7a2016-03-28 19:46:06 -04006509 req->auto_pause |= PORT_PHY_CFG_REQ_AUTO_PAUSE_TX;
Michael Chanc0c050c2015-10-22 16:01:17 -04006510 req->enables |=
6511 cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE);
6512 } else {
6513 if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_RX)
6514 req->force_pause |= PORT_PHY_CFG_REQ_FORCE_PAUSE_RX;
6515 if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_TX)
6516 req->force_pause |= PORT_PHY_CFG_REQ_FORCE_PAUSE_TX;
6517 req->enables |=
6518 cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_FORCE_PAUSE);
Michael Chanc9ee9512016-04-05 14:08:56 -04006519 if (bp->hwrm_spec_code >= 0x10201) {
6520 req->auto_pause = req->force_pause;
6521 req->enables |= cpu_to_le32(
6522 PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE);
6523 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006524 }
6525}
6526
6527static void bnxt_hwrm_set_link_common(struct bnxt *bp,
6528 struct hwrm_port_phy_cfg_input *req)
6529{
6530 u8 autoneg = bp->link_info.autoneg;
6531 u16 fw_link_speed = bp->link_info.req_link_speed;
Michael Chan68515a12016-12-29 12:13:34 -05006532 u16 advertising = bp->link_info.advertising;
Michael Chanc0c050c2015-10-22 16:01:17 -04006533
6534 if (autoneg & BNXT_AUTONEG_SPEED) {
6535 req->auto_mode |=
Michael Chan11f15ed2016-04-05 14:08:55 -04006536 PORT_PHY_CFG_REQ_AUTO_MODE_SPEED_MASK;
Michael Chanc0c050c2015-10-22 16:01:17 -04006537
6538 req->enables |= cpu_to_le32(
6539 PORT_PHY_CFG_REQ_ENABLES_AUTO_LINK_SPEED_MASK);
6540 req->auto_link_speed_mask = cpu_to_le16(advertising);
6541
6542 req->enables |= cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_MODE);
6543 req->flags |=
6544 cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESTART_AUTONEG);
6545 } else {
6546 req->force_link_speed = cpu_to_le16(fw_link_speed);
6547 req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE);
6548 }
6549
Michael Chanc0c050c2015-10-22 16:01:17 -04006550 /* tell chimp that the setting takes effect immediately */
6551 req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESET_PHY);
6552}
6553
6554int bnxt_hwrm_set_pause(struct bnxt *bp)
6555{
6556 struct hwrm_port_phy_cfg_input req = {0};
6557 int rc;
6558
6559 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1);
6560 bnxt_hwrm_set_pause_common(bp, &req);
6561
6562 if ((bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL) ||
6563 bp->link_info.force_link_chng)
6564 bnxt_hwrm_set_link_common(bp, &req);
6565
6566 mutex_lock(&bp->hwrm_cmd_lock);
6567 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6568 if (!rc && !(bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL)) {
6569 /* since changing of pause setting doesn't trigger any link
6570 * change event, the driver needs to update the current pause
6571 * result upon successfully return of the phy_cfg command
6572 */
6573 bp->link_info.pause =
6574 bp->link_info.force_pause_setting = bp->link_info.req_flow_ctrl;
6575 bp->link_info.auto_pause_setting = 0;
6576 if (!bp->link_info.force_link_chng)
6577 bnxt_report_link(bp);
6578 }
6579 bp->link_info.force_link_chng = false;
6580 mutex_unlock(&bp->hwrm_cmd_lock);
6581 return rc;
6582}
6583
Michael Chan939f7f02016-04-05 14:08:58 -04006584static void bnxt_hwrm_set_eee(struct bnxt *bp,
6585 struct hwrm_port_phy_cfg_input *req)
6586{
6587 struct ethtool_eee *eee = &bp->eee;
6588
6589 if (eee->eee_enabled) {
6590 u16 eee_speeds;
6591 u32 flags = PORT_PHY_CFG_REQ_FLAGS_EEE_ENABLE;
6592
6593 if (eee->tx_lpi_enabled)
6594 flags |= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_ENABLE;
6595 else
6596 flags |= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_DISABLE;
6597
6598 req->flags |= cpu_to_le32(flags);
6599 eee_speeds = bnxt_get_fw_auto_link_speeds(eee->advertised);
6600 req->eee_link_speed_mask = cpu_to_le16(eee_speeds);
6601 req->tx_lpi_timer = cpu_to_le32(eee->tx_lpi_timer);
6602 } else {
6603 req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_EEE_DISABLE);
6604 }
6605}
6606
6607int bnxt_hwrm_set_link_setting(struct bnxt *bp, bool set_pause, bool set_eee)
Michael Chanc0c050c2015-10-22 16:01:17 -04006608{
6609 struct hwrm_port_phy_cfg_input req = {0};
6610
6611 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1);
6612 if (set_pause)
6613 bnxt_hwrm_set_pause_common(bp, &req);
6614
6615 bnxt_hwrm_set_link_common(bp, &req);
Michael Chan939f7f02016-04-05 14:08:58 -04006616
6617 if (set_eee)
6618 bnxt_hwrm_set_eee(bp, &req);
Michael Chanc0c050c2015-10-22 16:01:17 -04006619 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6620}
6621
Michael Chan33f7d552016-04-11 04:11:12 -04006622static int bnxt_hwrm_shutdown_link(struct bnxt *bp)
6623{
6624 struct hwrm_port_phy_cfg_input req = {0};
6625
Satish Baddipadige567b2ab2016-06-13 02:25:31 -04006626 if (!BNXT_SINGLE_PF(bp))
Michael Chan33f7d552016-04-11 04:11:12 -04006627 return 0;
6628
6629 if (pci_num_vf(bp->pdev))
6630 return 0;
6631
6632 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1);
Michael Chan16d663a2016-11-16 21:13:07 -05006633 req.flags = cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE_LINK_DWN);
Michael Chan33f7d552016-04-11 04:11:12 -04006634 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6635}
6636
Michael Chan5ad2cbe2017-01-13 01:32:03 -05006637static int bnxt_hwrm_port_led_qcaps(struct bnxt *bp)
6638{
6639 struct hwrm_port_led_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
6640 struct hwrm_port_led_qcaps_input req = {0};
6641 struct bnxt_pf_info *pf = &bp->pf;
6642 int rc;
6643
6644 if (BNXT_VF(bp) || bp->hwrm_spec_code < 0x10601)
6645 return 0;
6646
6647 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_LED_QCAPS, -1, -1);
6648 req.port_id = cpu_to_le16(pf->port_id);
6649 mutex_lock(&bp->hwrm_cmd_lock);
6650 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6651 if (rc) {
6652 mutex_unlock(&bp->hwrm_cmd_lock);
6653 return rc;
6654 }
6655 if (resp->num_leds > 0 && resp->num_leds < BNXT_MAX_LED) {
6656 int i;
6657
6658 bp->num_leds = resp->num_leds;
6659 memcpy(bp->leds, &resp->led0_id, sizeof(bp->leds[0]) *
6660 bp->num_leds);
6661 for (i = 0; i < bp->num_leds; i++) {
6662 struct bnxt_led_info *led = &bp->leds[i];
6663 __le16 caps = led->led_state_caps;
6664
6665 if (!led->led_group_id ||
6666 !BNXT_LED_ALT_BLINK_CAP(caps)) {
6667 bp->num_leds = 0;
6668 break;
6669 }
6670 }
6671 }
6672 mutex_unlock(&bp->hwrm_cmd_lock);
6673 return 0;
6674}
6675
Michael Chan5282db62017-04-04 18:14:10 -04006676int bnxt_hwrm_alloc_wol_fltr(struct bnxt *bp)
6677{
6678 struct hwrm_wol_filter_alloc_input req = {0};
6679 struct hwrm_wol_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr;
6680 int rc;
6681
6682 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_WOL_FILTER_ALLOC, -1, -1);
6683 req.port_id = cpu_to_le16(bp->pf.port_id);
6684 req.wol_type = WOL_FILTER_ALLOC_REQ_WOL_TYPE_MAGICPKT;
6685 req.enables = cpu_to_le32(WOL_FILTER_ALLOC_REQ_ENABLES_MAC_ADDRESS);
6686 memcpy(req.mac_address, bp->dev->dev_addr, ETH_ALEN);
6687 mutex_lock(&bp->hwrm_cmd_lock);
6688 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6689 if (!rc)
6690 bp->wol_filter_id = resp->wol_filter_id;
6691 mutex_unlock(&bp->hwrm_cmd_lock);
6692 return rc;
6693}
6694
6695int bnxt_hwrm_free_wol_fltr(struct bnxt *bp)
6696{
6697 struct hwrm_wol_filter_free_input req = {0};
6698 int rc;
6699
6700 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_WOL_FILTER_FREE, -1, -1);
6701 req.port_id = cpu_to_le16(bp->pf.port_id);
6702 req.enables = cpu_to_le32(WOL_FILTER_FREE_REQ_ENABLES_WOL_FILTER_ID);
6703 req.wol_filter_id = bp->wol_filter_id;
6704 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6705 return rc;
6706}
6707
Michael Chanc1ef1462017-04-04 18:14:07 -04006708static u16 bnxt_hwrm_get_wol_fltrs(struct bnxt *bp, u16 handle)
6709{
6710 struct hwrm_wol_filter_qcfg_input req = {0};
6711 struct hwrm_wol_filter_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
6712 u16 next_handle = 0;
6713 int rc;
6714
6715 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_WOL_FILTER_QCFG, -1, -1);
6716 req.port_id = cpu_to_le16(bp->pf.port_id);
6717 req.handle = cpu_to_le16(handle);
6718 mutex_lock(&bp->hwrm_cmd_lock);
6719 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6720 if (!rc) {
6721 next_handle = le16_to_cpu(resp->next_handle);
6722 if (next_handle != 0) {
6723 if (resp->wol_type ==
6724 WOL_FILTER_ALLOC_REQ_WOL_TYPE_MAGICPKT) {
6725 bp->wol = 1;
6726 bp->wol_filter_id = resp->wol_filter_id;
6727 }
6728 }
6729 }
6730 mutex_unlock(&bp->hwrm_cmd_lock);
6731 return next_handle;
6732}
6733
6734static void bnxt_get_wol_settings(struct bnxt *bp)
6735{
6736 u16 handle = 0;
6737
6738 if (!BNXT_PF(bp) || !(bp->flags & BNXT_FLAG_WOL_CAP))
6739 return;
6740
6741 do {
6742 handle = bnxt_hwrm_get_wol_fltrs(bp, handle);
6743 } while (handle && handle != 0xffff);
6744}
6745
Michael Chan939f7f02016-04-05 14:08:58 -04006746static bool bnxt_eee_config_ok(struct bnxt *bp)
6747{
6748 struct ethtool_eee *eee = &bp->eee;
6749 struct bnxt_link_info *link_info = &bp->link_info;
6750
6751 if (!(bp->flags & BNXT_FLAG_EEE_CAP))
6752 return true;
6753
6754 if (eee->eee_enabled) {
6755 u32 advertising =
6756 _bnxt_fw_to_ethtool_adv_spds(link_info->advertising, 0);
6757
6758 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) {
6759 eee->eee_enabled = 0;
6760 return false;
6761 }
6762 if (eee->advertised & ~advertising) {
6763 eee->advertised = advertising & eee->supported;
6764 return false;
6765 }
6766 }
6767 return true;
6768}
6769
Michael Chanc0c050c2015-10-22 16:01:17 -04006770static int bnxt_update_phy_setting(struct bnxt *bp)
6771{
6772 int rc;
6773 bool update_link = false;
6774 bool update_pause = false;
Michael Chan939f7f02016-04-05 14:08:58 -04006775 bool update_eee = false;
Michael Chanc0c050c2015-10-22 16:01:17 -04006776 struct bnxt_link_info *link_info = &bp->link_info;
6777
6778 rc = bnxt_update_link(bp, true);
6779 if (rc) {
6780 netdev_err(bp->dev, "failed to update link (rc: %x)\n",
6781 rc);
6782 return rc;
6783 }
Michael Chan33dac242017-02-12 19:18:15 -05006784 if (!BNXT_SINGLE_PF(bp))
6785 return 0;
6786
Michael Chanc0c050c2015-10-22 16:01:17 -04006787 if ((link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) &&
Michael Chanc9ee9512016-04-05 14:08:56 -04006788 (link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH) !=
6789 link_info->req_flow_ctrl)
Michael Chanc0c050c2015-10-22 16:01:17 -04006790 update_pause = true;
6791 if (!(link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) &&
6792 link_info->force_pause_setting != link_info->req_flow_ctrl)
6793 update_pause = true;
Michael Chanc0c050c2015-10-22 16:01:17 -04006794 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) {
6795 if (BNXT_AUTO_MODE(link_info->auto_mode))
6796 update_link = true;
6797 if (link_info->req_link_speed != link_info->force_link_speed)
6798 update_link = true;
Michael Chande730182016-02-19 19:43:20 -05006799 if (link_info->req_duplex != link_info->duplex_setting)
6800 update_link = true;
Michael Chanc0c050c2015-10-22 16:01:17 -04006801 } else {
6802 if (link_info->auto_mode == BNXT_LINK_AUTO_NONE)
6803 update_link = true;
6804 if (link_info->advertising != link_info->auto_link_speeds)
6805 update_link = true;
Michael Chanc0c050c2015-10-22 16:01:17 -04006806 }
6807
Michael Chan16d663a2016-11-16 21:13:07 -05006808 /* The last close may have shutdown the link, so need to call
6809 * PHY_CFG to bring it back up.
6810 */
6811 if (!netif_carrier_ok(bp->dev))
6812 update_link = true;
6813
Michael Chan939f7f02016-04-05 14:08:58 -04006814 if (!bnxt_eee_config_ok(bp))
6815 update_eee = true;
6816
Michael Chanc0c050c2015-10-22 16:01:17 -04006817 if (update_link)
Michael Chan939f7f02016-04-05 14:08:58 -04006818 rc = bnxt_hwrm_set_link_setting(bp, update_pause, update_eee);
Michael Chanc0c050c2015-10-22 16:01:17 -04006819 else if (update_pause)
6820 rc = bnxt_hwrm_set_pause(bp);
6821 if (rc) {
6822 netdev_err(bp->dev, "failed to update phy setting (rc: %x)\n",
6823 rc);
6824 return rc;
6825 }
6826
6827 return rc;
6828}
6829
Jeffrey Huang11809492015-11-05 16:25:49 -05006830/* Common routine to pre-map certain register block to different GRC window.
6831 * A PF has 16 4K windows and a VF has 4 4K windows. However, only 15 windows
6832 * in PF and 3 windows in VF that can be customized to map in different
6833 * register blocks.
6834 */
6835static void bnxt_preset_reg_win(struct bnxt *bp)
6836{
6837 if (BNXT_PF(bp)) {
6838 /* CAG registers map to GRC window #4 */
6839 writel(BNXT_CAG_REG_BASE,
6840 bp->bar0 + BNXT_GRCPF_REG_WINDOW_BASE_OUT + 12);
6841 }
6842}
6843
Michael Chanc0c050c2015-10-22 16:01:17 -04006844static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
6845{
6846 int rc = 0;
6847
Jeffrey Huang11809492015-11-05 16:25:49 -05006848 bnxt_preset_reg_win(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04006849 netif_carrier_off(bp->dev);
6850 if (irq_re_init) {
Michael Chan674f50a2018-01-17 03:21:09 -05006851 rc = bnxt_reserve_rings(bp);
6852 if (rc)
6853 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04006854 }
6855 if ((bp->flags & BNXT_FLAG_RFS) &&
6856 !(bp->flags & BNXT_FLAG_USING_MSIX)) {
6857 /* disable RFS if falling back to INTA */
6858 bp->dev->hw_features &= ~NETIF_F_NTUPLE;
6859 bp->flags &= ~BNXT_FLAG_RFS;
6860 }
6861
6862 rc = bnxt_alloc_mem(bp, irq_re_init);
6863 if (rc) {
6864 netdev_err(bp->dev, "bnxt_alloc_mem err: %x\n", rc);
6865 goto open_err_free_mem;
6866 }
6867
6868 if (irq_re_init) {
6869 bnxt_init_napi(bp);
6870 rc = bnxt_request_irq(bp);
6871 if (rc) {
6872 netdev_err(bp->dev, "bnxt_request_irq err: %x\n", rc);
6873 goto open_err;
6874 }
6875 }
6876
6877 bnxt_enable_napi(bp);
6878
6879 rc = bnxt_init_nic(bp, irq_re_init);
6880 if (rc) {
6881 netdev_err(bp->dev, "bnxt_init_nic err: %x\n", rc);
6882 goto open_err;
6883 }
6884
6885 if (link_re_init) {
Michael Chane2dc9b62017-10-13 21:09:30 -04006886 mutex_lock(&bp->link_lock);
Michael Chanc0c050c2015-10-22 16:01:17 -04006887 rc = bnxt_update_phy_setting(bp);
Michael Chane2dc9b62017-10-13 21:09:30 -04006888 mutex_unlock(&bp->link_lock);
Michael Chanc0c050c2015-10-22 16:01:17 -04006889 if (rc)
Michael Chanba41d462016-02-19 19:43:21 -05006890 netdev_warn(bp->dev, "failed to update phy settings\n");
Michael Chanc0c050c2015-10-22 16:01:17 -04006891 }
6892
Alexander Duyck7cdd5fc2016-06-16 12:21:36 -07006893 if (irq_re_init)
Alexander Duyckad51b8e2016-06-16 12:21:19 -07006894 udp_tunnel_get_rx_info(bp->dev);
Michael Chanc0c050c2015-10-22 16:01:17 -04006895
Michael Chancaefe522015-12-09 19:35:42 -05006896 set_bit(BNXT_STATE_OPEN, &bp->state);
Michael Chanc0c050c2015-10-22 16:01:17 -04006897 bnxt_enable_int(bp);
6898 /* Enable TX queues */
6899 bnxt_tx_enable(bp);
6900 mod_timer(&bp->timer, jiffies + bp->current_interval);
Michael Chan10289be2016-05-15 03:04:49 -04006901 /* Poll link status and check for SFP+ module status */
6902 bnxt_get_port_module_status(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04006903
Sathya Perlaee5c7fb2017-07-24 12:34:28 -04006904 /* VF-reps may need to be re-opened after the PF is re-opened */
6905 if (BNXT_PF(bp))
6906 bnxt_vf_reps_open(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04006907 return 0;
6908
6909open_err:
6910 bnxt_disable_napi(bp);
6911 bnxt_del_napi(bp);
6912
6913open_err_free_mem:
6914 bnxt_free_skbs(bp);
6915 bnxt_free_irq(bp);
6916 bnxt_free_mem(bp, true);
6917 return rc;
6918}
6919
6920/* rtnl_lock held */
6921int bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
6922{
6923 int rc = 0;
6924
6925 rc = __bnxt_open_nic(bp, irq_re_init, link_re_init);
6926 if (rc) {
6927 netdev_err(bp->dev, "nic open fail (rc: %x)\n", rc);
6928 dev_close(bp->dev);
6929 }
6930 return rc;
6931}
6932
Michael Chanf7dc1ea2017-04-04 18:14:13 -04006933/* rtnl_lock held, open the NIC half way by allocating all resources, but
6934 * NAPI, IRQ, and TX are not enabled. This is mainly used for offline
6935 * self tests.
6936 */
6937int bnxt_half_open_nic(struct bnxt *bp)
6938{
6939 int rc = 0;
6940
6941 rc = bnxt_alloc_mem(bp, false);
6942 if (rc) {
6943 netdev_err(bp->dev, "bnxt_alloc_mem err: %x\n", rc);
6944 goto half_open_err;
6945 }
6946 rc = bnxt_init_nic(bp, false);
6947 if (rc) {
6948 netdev_err(bp->dev, "bnxt_init_nic err: %x\n", rc);
6949 goto half_open_err;
6950 }
6951 return 0;
6952
6953half_open_err:
6954 bnxt_free_skbs(bp);
6955 bnxt_free_mem(bp, false);
6956 dev_close(bp->dev);
6957 return rc;
6958}
6959
6960/* rtnl_lock held, this call can only be made after a previous successful
6961 * call to bnxt_half_open_nic().
6962 */
6963void bnxt_half_close_nic(struct bnxt *bp)
6964{
6965 bnxt_hwrm_resource_free(bp, false, false);
6966 bnxt_free_skbs(bp);
6967 bnxt_free_mem(bp, false);
6968}
6969
Michael Chanc0c050c2015-10-22 16:01:17 -04006970static int bnxt_open(struct net_device *dev)
6971{
6972 struct bnxt *bp = netdev_priv(dev);
Michael Chanc0c050c2015-10-22 16:01:17 -04006973
Michael Chanc0c050c2015-10-22 16:01:17 -04006974 return __bnxt_open_nic(bp, true, true);
6975}
6976
Michael Chanf9b76eb2017-07-11 13:05:34 -04006977static bool bnxt_drv_busy(struct bnxt *bp)
6978{
6979 return (test_bit(BNXT_STATE_IN_SP_TASK, &bp->state) ||
6980 test_bit(BNXT_STATE_READ_STATS, &bp->state));
6981}
6982
Michael Chan86e953d2018-01-17 03:21:04 -05006983static void __bnxt_close_nic(struct bnxt *bp, bool irq_re_init,
6984 bool link_re_init)
Michael Chanc0c050c2015-10-22 16:01:17 -04006985{
Sathya Perlaee5c7fb2017-07-24 12:34:28 -04006986 /* Close the VF-reps before closing PF */
6987 if (BNXT_PF(bp))
6988 bnxt_vf_reps_close(bp);
Michael Chan86e953d2018-01-17 03:21:04 -05006989
Michael Chanc0c050c2015-10-22 16:01:17 -04006990 /* Change device state to avoid TX queue wake up's */
6991 bnxt_tx_disable(bp);
6992
Michael Chancaefe522015-12-09 19:35:42 -05006993 clear_bit(BNXT_STATE_OPEN, &bp->state);
Michael Chan4cebdce2015-12-09 19:35:43 -05006994 smp_mb__after_atomic();
Michael Chanf9b76eb2017-07-11 13:05:34 -04006995 while (bnxt_drv_busy(bp))
Michael Chan4cebdce2015-12-09 19:35:43 -05006996 msleep(20);
Michael Chanc0c050c2015-10-22 16:01:17 -04006997
Michael Chan9d8bc092016-12-29 12:13:33 -05006998 /* Flush rings and and disable interrupts */
Michael Chanc0c050c2015-10-22 16:01:17 -04006999 bnxt_shutdown_nic(bp, irq_re_init);
7000
7001 /* TODO CHIMP_FW: Link/PHY related cleanup if (link_re_init) */
7002
7003 bnxt_disable_napi(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04007004 del_timer_sync(&bp->timer);
7005 bnxt_free_skbs(bp);
7006
7007 if (irq_re_init) {
7008 bnxt_free_irq(bp);
7009 bnxt_del_napi(bp);
7010 }
7011 bnxt_free_mem(bp, irq_re_init);
Michael Chan86e953d2018-01-17 03:21:04 -05007012}
7013
7014int bnxt_close_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
7015{
7016 int rc = 0;
7017
7018#ifdef CONFIG_BNXT_SRIOV
7019 if (bp->sriov_cfg) {
7020 rc = wait_event_interruptible_timeout(bp->sriov_cfg_wait,
7021 !bp->sriov_cfg,
7022 BNXT_SRIOV_CFG_WAIT_TMO);
7023 if (rc)
7024 netdev_warn(bp->dev, "timeout waiting for SRIOV config operation to complete!\n");
7025 }
7026#endif
7027 __bnxt_close_nic(bp, irq_re_init, link_re_init);
Michael Chanc0c050c2015-10-22 16:01:17 -04007028 return rc;
7029}
7030
7031static int bnxt_close(struct net_device *dev)
7032{
7033 struct bnxt *bp = netdev_priv(dev);
7034
7035 bnxt_close_nic(bp, true, true);
Michael Chan33f7d552016-04-11 04:11:12 -04007036 bnxt_hwrm_shutdown_link(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04007037 return 0;
7038}
7039
7040/* rtnl_lock held */
7041static int bnxt_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
7042{
7043 switch (cmd) {
7044 case SIOCGMIIPHY:
7045 /* fallthru */
7046 case SIOCGMIIREG: {
7047 if (!netif_running(dev))
7048 return -EAGAIN;
7049
7050 return 0;
7051 }
7052
7053 case SIOCSMIIREG:
7054 if (!netif_running(dev))
7055 return -EAGAIN;
7056
7057 return 0;
7058
7059 default:
7060 /* do nothing */
7061 break;
7062 }
7063 return -EOPNOTSUPP;
7064}
7065
stephen hemmingerbc1f4472017-01-06 19:12:52 -08007066static void
Michael Chanc0c050c2015-10-22 16:01:17 -04007067bnxt_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
7068{
7069 u32 i;
7070 struct bnxt *bp = netdev_priv(dev);
7071
Michael Chanf9b76eb2017-07-11 13:05:34 -04007072 set_bit(BNXT_STATE_READ_STATS, &bp->state);
7073 /* Make sure bnxt_close_nic() sees that we are reading stats before
7074 * we check the BNXT_STATE_OPEN flag.
7075 */
7076 smp_mb__after_atomic();
7077 if (!test_bit(BNXT_STATE_OPEN, &bp->state)) {
7078 clear_bit(BNXT_STATE_READ_STATS, &bp->state);
stephen hemmingerbc1f4472017-01-06 19:12:52 -08007079 return;
Michael Chanf9b76eb2017-07-11 13:05:34 -04007080 }
Michael Chanc0c050c2015-10-22 16:01:17 -04007081
7082 /* TODO check if we need to synchronize with bnxt_close path */
7083 for (i = 0; i < bp->cp_nr_rings; i++) {
7084 struct bnxt_napi *bnapi = bp->bnapi[i];
7085 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
7086 struct ctx_hw_stats *hw_stats = cpr->hw_stats;
7087
7088 stats->rx_packets += le64_to_cpu(hw_stats->rx_ucast_pkts);
7089 stats->rx_packets += le64_to_cpu(hw_stats->rx_mcast_pkts);
7090 stats->rx_packets += le64_to_cpu(hw_stats->rx_bcast_pkts);
7091
7092 stats->tx_packets += le64_to_cpu(hw_stats->tx_ucast_pkts);
7093 stats->tx_packets += le64_to_cpu(hw_stats->tx_mcast_pkts);
7094 stats->tx_packets += le64_to_cpu(hw_stats->tx_bcast_pkts);
7095
7096 stats->rx_bytes += le64_to_cpu(hw_stats->rx_ucast_bytes);
7097 stats->rx_bytes += le64_to_cpu(hw_stats->rx_mcast_bytes);
7098 stats->rx_bytes += le64_to_cpu(hw_stats->rx_bcast_bytes);
7099
7100 stats->tx_bytes += le64_to_cpu(hw_stats->tx_ucast_bytes);
7101 stats->tx_bytes += le64_to_cpu(hw_stats->tx_mcast_bytes);
7102 stats->tx_bytes += le64_to_cpu(hw_stats->tx_bcast_bytes);
7103
7104 stats->rx_missed_errors +=
7105 le64_to_cpu(hw_stats->rx_discard_pkts);
7106
7107 stats->multicast += le64_to_cpu(hw_stats->rx_mcast_pkts);
7108
Michael Chanc0c050c2015-10-22 16:01:17 -04007109 stats->tx_dropped += le64_to_cpu(hw_stats->tx_drop_pkts);
7110 }
7111
Michael Chan9947f832016-03-07 15:38:46 -05007112 if (bp->flags & BNXT_FLAG_PORT_STATS) {
7113 struct rx_port_stats *rx = bp->hw_rx_port_stats;
7114 struct tx_port_stats *tx = bp->hw_tx_port_stats;
7115
7116 stats->rx_crc_errors = le64_to_cpu(rx->rx_fcs_err_frames);
7117 stats->rx_frame_errors = le64_to_cpu(rx->rx_align_err_frames);
7118 stats->rx_length_errors = le64_to_cpu(rx->rx_undrsz_frames) +
7119 le64_to_cpu(rx->rx_ovrsz_frames) +
7120 le64_to_cpu(rx->rx_runt_frames);
7121 stats->rx_errors = le64_to_cpu(rx->rx_false_carrier_frames) +
7122 le64_to_cpu(rx->rx_jbr_frames);
7123 stats->collisions = le64_to_cpu(tx->tx_total_collisions);
7124 stats->tx_fifo_errors = le64_to_cpu(tx->tx_fifo_underruns);
7125 stats->tx_errors = le64_to_cpu(tx->tx_err);
7126 }
Michael Chanf9b76eb2017-07-11 13:05:34 -04007127 clear_bit(BNXT_STATE_READ_STATS, &bp->state);
Michael Chanc0c050c2015-10-22 16:01:17 -04007128}
7129
7130static bool bnxt_mc_list_updated(struct bnxt *bp, u32 *rx_mask)
7131{
7132 struct net_device *dev = bp->dev;
7133 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
7134 struct netdev_hw_addr *ha;
7135 u8 *haddr;
7136 int mc_count = 0;
7137 bool update = false;
7138 int off = 0;
7139
7140 netdev_for_each_mc_addr(ha, dev) {
7141 if (mc_count >= BNXT_MAX_MC_ADDRS) {
7142 *rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST;
7143 vnic->mc_list_count = 0;
7144 return false;
7145 }
7146 haddr = ha->addr;
7147 if (!ether_addr_equal(haddr, vnic->mc_list + off)) {
7148 memcpy(vnic->mc_list + off, haddr, ETH_ALEN);
7149 update = true;
7150 }
7151 off += ETH_ALEN;
7152 mc_count++;
7153 }
7154 if (mc_count)
7155 *rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_MCAST;
7156
7157 if (mc_count != vnic->mc_list_count) {
7158 vnic->mc_list_count = mc_count;
7159 update = true;
7160 }
7161 return update;
7162}
7163
7164static bool bnxt_uc_list_updated(struct bnxt *bp)
7165{
7166 struct net_device *dev = bp->dev;
7167 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
7168 struct netdev_hw_addr *ha;
7169 int off = 0;
7170
7171 if (netdev_uc_count(dev) != (vnic->uc_filter_count - 1))
7172 return true;
7173
7174 netdev_for_each_uc_addr(ha, dev) {
7175 if (!ether_addr_equal(ha->addr, vnic->uc_list + off))
7176 return true;
7177
7178 off += ETH_ALEN;
7179 }
7180 return false;
7181}
7182
7183static void bnxt_set_rx_mode(struct net_device *dev)
7184{
7185 struct bnxt *bp = netdev_priv(dev);
7186 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
7187 u32 mask = vnic->rx_mask;
7188 bool mc_update = false;
7189 bool uc_update;
7190
7191 if (!netif_running(dev))
7192 return;
7193
7194 mask &= ~(CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS |
7195 CFA_L2_SET_RX_MASK_REQ_MASK_MCAST |
7196 CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST);
7197
Michael Chan17c71ac2016-07-01 18:46:27 -04007198 if ((dev->flags & IFF_PROMISC) && bnxt_promisc_ok(bp))
Michael Chanc0c050c2015-10-22 16:01:17 -04007199 mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS;
7200
7201 uc_update = bnxt_uc_list_updated(bp);
7202
7203 if (dev->flags & IFF_ALLMULTI) {
7204 mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST;
7205 vnic->mc_list_count = 0;
7206 } else {
7207 mc_update = bnxt_mc_list_updated(bp, &mask);
7208 }
7209
7210 if (mask != vnic->rx_mask || uc_update || mc_update) {
7211 vnic->rx_mask = mask;
7212
7213 set_bit(BNXT_RX_MASK_SP_EVENT, &bp->sp_event);
Michael Chanc213eae2017-10-13 21:09:29 -04007214 bnxt_queue_sp_work(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04007215 }
7216}
7217
Michael Chanb664f002015-12-02 01:54:08 -05007218static int bnxt_cfg_rx_mode(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04007219{
7220 struct net_device *dev = bp->dev;
7221 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
7222 struct netdev_hw_addr *ha;
7223 int i, off = 0, rc;
7224 bool uc_update;
7225
7226 netif_addr_lock_bh(dev);
7227 uc_update = bnxt_uc_list_updated(bp);
7228 netif_addr_unlock_bh(dev);
7229
7230 if (!uc_update)
7231 goto skip_uc;
7232
7233 mutex_lock(&bp->hwrm_cmd_lock);
7234 for (i = 1; i < vnic->uc_filter_count; i++) {
7235 struct hwrm_cfa_l2_filter_free_input req = {0};
7236
7237 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_L2_FILTER_FREE, -1,
7238 -1);
7239
7240 req.l2_filter_id = vnic->fw_l2_filter_id[i];
7241
7242 rc = _hwrm_send_message(bp, &req, sizeof(req),
7243 HWRM_CMD_TIMEOUT);
7244 }
7245 mutex_unlock(&bp->hwrm_cmd_lock);
7246
7247 vnic->uc_filter_count = 1;
7248
7249 netif_addr_lock_bh(dev);
7250 if (netdev_uc_count(dev) > (BNXT_MAX_UC_ADDRS - 1)) {
7251 vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS;
7252 } else {
7253 netdev_for_each_uc_addr(ha, dev) {
7254 memcpy(vnic->uc_list + off, ha->addr, ETH_ALEN);
7255 off += ETH_ALEN;
7256 vnic->uc_filter_count++;
7257 }
7258 }
7259 netif_addr_unlock_bh(dev);
7260
7261 for (i = 1, off = 0; i < vnic->uc_filter_count; i++, off += ETH_ALEN) {
7262 rc = bnxt_hwrm_set_vnic_filter(bp, 0, i, vnic->uc_list + off);
7263 if (rc) {
7264 netdev_err(bp->dev, "HWRM vnic filter failure rc: %x\n",
7265 rc);
7266 vnic->uc_filter_count = i;
Michael Chanb664f002015-12-02 01:54:08 -05007267 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04007268 }
7269 }
7270
7271skip_uc:
7272 rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, 0);
7273 if (rc)
7274 netdev_err(bp->dev, "HWRM cfa l2 rx mask failure rc: %x\n",
7275 rc);
Michael Chanb664f002015-12-02 01:54:08 -05007276
7277 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04007278}
7279
Michael Chan8079e8f2016-12-29 12:13:37 -05007280/* If the chip and firmware supports RFS */
7281static bool bnxt_rfs_supported(struct bnxt *bp)
7282{
7283 if (BNXT_PF(bp) && !BNXT_CHIP_TYPE_NITRO_A0(bp))
7284 return true;
Michael Chanae10ae72016-12-29 12:13:38 -05007285 if (bp->flags & BNXT_FLAG_NEW_RSS_CAP)
7286 return true;
Michael Chan8079e8f2016-12-29 12:13:37 -05007287 return false;
7288}
7289
7290/* If runtime conditions support RFS */
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007291static bool bnxt_rfs_capable(struct bnxt *bp)
7292{
7293#ifdef CONFIG_RFS_ACCEL
Michael Chan8079e8f2016-12-29 12:13:37 -05007294 int vnics, max_vnics, max_rss_ctxs;
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007295
Michael Chan964fd482017-02-12 19:18:13 -05007296 if (!(bp->flags & BNXT_FLAG_MSIX_CAP))
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007297 return false;
7298
7299 vnics = 1 + bp->rx_nr_rings;
Michael Chan8079e8f2016-12-29 12:13:37 -05007300 max_vnics = bnxt_get_max_func_vnics(bp);
7301 max_rss_ctxs = bnxt_get_max_func_rss_ctxs(bp);
Michael Chanae10ae72016-12-29 12:13:38 -05007302
7303 /* RSS contexts not a limiting factor */
7304 if (bp->flags & BNXT_FLAG_NEW_RSS_CAP)
7305 max_rss_ctxs = max_vnics;
Michael Chan8079e8f2016-12-29 12:13:37 -05007306 if (vnics > max_vnics || vnics > max_rss_ctxs) {
Michael Chan6a1eef52018-01-17 03:21:10 -05007307 if (bp->rx_nr_rings > 1)
7308 netdev_warn(bp->dev,
7309 "Not enough resources to support NTUPLE filters, enough resources for up to %d rx rings\n",
7310 min(max_rss_ctxs - 1, max_vnics - 1));
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007311 return false;
Vasundhara Volama2304902016-07-25 12:33:36 -04007312 }
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007313
Michael Chan6a1eef52018-01-17 03:21:10 -05007314 if (!(bp->flags & BNXT_FLAG_NEW_RM))
7315 return true;
7316
7317 if (vnics == bp->hw_resc.resv_vnics)
7318 return true;
7319
7320 bnxt_hwrm_reserve_rings(bp, 0, 0, 0, 0, vnics);
7321 if (vnics <= bp->hw_resc.resv_vnics)
7322 return true;
7323
7324 netdev_warn(bp->dev, "Unable to reserve resources to support NTUPLE filters.\n");
7325 bnxt_hwrm_reserve_rings(bp, 0, 0, 0, 0, 1);
7326 return false;
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007327#else
7328 return false;
7329#endif
7330}
7331
Michael Chanc0c050c2015-10-22 16:01:17 -04007332static netdev_features_t bnxt_fix_features(struct net_device *dev,
7333 netdev_features_t features)
7334{
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007335 struct bnxt *bp = netdev_priv(dev);
7336
Vasundhara Volama2304902016-07-25 12:33:36 -04007337 if ((features & NETIF_F_NTUPLE) && !bnxt_rfs_capable(bp))
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007338 features &= ~NETIF_F_NTUPLE;
Michael Chan5a9f6b22016-06-06 02:37:15 -04007339
Michael Chan1054aee2017-12-16 03:09:42 -05007340 if (bp->flags & BNXT_FLAG_NO_AGG_RINGS)
7341 features &= ~(NETIF_F_LRO | NETIF_F_GRO_HW);
7342
7343 if (!(features & NETIF_F_GRO))
7344 features &= ~NETIF_F_GRO_HW;
7345
7346 if (features & NETIF_F_GRO_HW)
7347 features &= ~NETIF_F_LRO;
7348
Michael Chan5a9f6b22016-06-06 02:37:15 -04007349 /* Both CTAG and STAG VLAN accelaration on the RX side have to be
7350 * turned on or off together.
7351 */
7352 if ((features & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX)) !=
7353 (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX)) {
7354 if (dev->features & NETIF_F_HW_VLAN_CTAG_RX)
7355 features &= ~(NETIF_F_HW_VLAN_CTAG_RX |
7356 NETIF_F_HW_VLAN_STAG_RX);
7357 else
7358 features |= NETIF_F_HW_VLAN_CTAG_RX |
7359 NETIF_F_HW_VLAN_STAG_RX;
7360 }
Michael Chancf6645f2016-06-13 02:25:28 -04007361#ifdef CONFIG_BNXT_SRIOV
7362 if (BNXT_VF(bp)) {
7363 if (bp->vf.vlan) {
7364 features &= ~(NETIF_F_HW_VLAN_CTAG_RX |
7365 NETIF_F_HW_VLAN_STAG_RX);
7366 }
7367 }
7368#endif
Michael Chanc0c050c2015-10-22 16:01:17 -04007369 return features;
7370}
7371
7372static int bnxt_set_features(struct net_device *dev, netdev_features_t features)
7373{
7374 struct bnxt *bp = netdev_priv(dev);
7375 u32 flags = bp->flags;
7376 u32 changes;
7377 int rc = 0;
7378 bool re_init = false;
7379 bool update_tpa = false;
7380
7381 flags &= ~BNXT_FLAG_ALL_CONFIG_FEATS;
Michael Chan1054aee2017-12-16 03:09:42 -05007382 if (features & NETIF_F_GRO_HW)
Michael Chanc0c050c2015-10-22 16:01:17 -04007383 flags |= BNXT_FLAG_GRO;
Michael Chan1054aee2017-12-16 03:09:42 -05007384 else if (features & NETIF_F_LRO)
Michael Chanc0c050c2015-10-22 16:01:17 -04007385 flags |= BNXT_FLAG_LRO;
7386
Michael Chanbdbd1eb2016-12-29 12:13:43 -05007387 if (bp->flags & BNXT_FLAG_NO_AGG_RINGS)
7388 flags &= ~BNXT_FLAG_TPA;
7389
Michael Chanc0c050c2015-10-22 16:01:17 -04007390 if (features & NETIF_F_HW_VLAN_CTAG_RX)
7391 flags |= BNXT_FLAG_STRIP_VLAN;
7392
7393 if (features & NETIF_F_NTUPLE)
7394 flags |= BNXT_FLAG_RFS;
7395
7396 changes = flags ^ bp->flags;
7397 if (changes & BNXT_FLAG_TPA) {
7398 update_tpa = true;
7399 if ((bp->flags & BNXT_FLAG_TPA) == 0 ||
7400 (flags & BNXT_FLAG_TPA) == 0)
7401 re_init = true;
7402 }
7403
7404 if (changes & ~BNXT_FLAG_TPA)
7405 re_init = true;
7406
7407 if (flags != bp->flags) {
7408 u32 old_flags = bp->flags;
7409
7410 bp->flags = flags;
7411
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007412 if (!test_bit(BNXT_STATE_OPEN, &bp->state)) {
Michael Chanc0c050c2015-10-22 16:01:17 -04007413 if (update_tpa)
7414 bnxt_set_ring_params(bp);
7415 return rc;
7416 }
7417
7418 if (re_init) {
7419 bnxt_close_nic(bp, false, false);
7420 if (update_tpa)
7421 bnxt_set_ring_params(bp);
7422
7423 return bnxt_open_nic(bp, false, false);
7424 }
7425 if (update_tpa) {
7426 rc = bnxt_set_tpa(bp,
7427 (flags & BNXT_FLAG_TPA) ?
7428 true : false);
7429 if (rc)
7430 bp->flags = old_flags;
7431 }
7432 }
7433 return rc;
7434}
7435
Michael Chan9f554592016-01-02 23:44:58 -05007436static void bnxt_dump_tx_sw_state(struct bnxt_napi *bnapi)
7437{
Michael Chanb6ab4b02016-01-02 23:44:59 -05007438 struct bnxt_tx_ring_info *txr = bnapi->tx_ring;
Michael Chan9f554592016-01-02 23:44:58 -05007439 int i = bnapi->index;
7440
Michael Chan3b2b7d92016-01-02 23:45:00 -05007441 if (!txr)
7442 return;
7443
Michael Chan9f554592016-01-02 23:44:58 -05007444 netdev_info(bnapi->bp->dev, "[%d]: tx{fw_ring: %d prod: %x cons: %x}\n",
7445 i, txr->tx_ring_struct.fw_ring_id, txr->tx_prod,
7446 txr->tx_cons);
7447}
7448
7449static void bnxt_dump_rx_sw_state(struct bnxt_napi *bnapi)
7450{
Michael Chanb6ab4b02016-01-02 23:44:59 -05007451 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
Michael Chan9f554592016-01-02 23:44:58 -05007452 int i = bnapi->index;
7453
Michael Chan3b2b7d92016-01-02 23:45:00 -05007454 if (!rxr)
7455 return;
7456
Michael Chan9f554592016-01-02 23:44:58 -05007457 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",
7458 i, rxr->rx_ring_struct.fw_ring_id, rxr->rx_prod,
7459 rxr->rx_agg_ring_struct.fw_ring_id, rxr->rx_agg_prod,
7460 rxr->rx_sw_agg_prod);
7461}
7462
7463static void bnxt_dump_cp_sw_state(struct bnxt_napi *bnapi)
7464{
7465 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
7466 int i = bnapi->index;
7467
7468 netdev_info(bnapi->bp->dev, "[%d]: cp{fw_ring: %d raw_cons: %x}\n",
7469 i, cpr->cp_ring_struct.fw_ring_id, cpr->cp_raw_cons);
7470}
7471
Michael Chanc0c050c2015-10-22 16:01:17 -04007472static void bnxt_dbg_dump_states(struct bnxt *bp)
7473{
7474 int i;
7475 struct bnxt_napi *bnapi;
Michael Chanc0c050c2015-10-22 16:01:17 -04007476
7477 for (i = 0; i < bp->cp_nr_rings; i++) {
7478 bnapi = bp->bnapi[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04007479 if (netif_msg_drv(bp)) {
Michael Chan9f554592016-01-02 23:44:58 -05007480 bnxt_dump_tx_sw_state(bnapi);
7481 bnxt_dump_rx_sw_state(bnapi);
7482 bnxt_dump_cp_sw_state(bnapi);
Michael Chanc0c050c2015-10-22 16:01:17 -04007483 }
7484 }
7485}
7486
Michael Chan6988bd92016-06-13 02:25:29 -04007487static void bnxt_reset_task(struct bnxt *bp, bool silent)
Michael Chanc0c050c2015-10-22 16:01:17 -04007488{
Michael Chan6988bd92016-06-13 02:25:29 -04007489 if (!silent)
7490 bnxt_dbg_dump_states(bp);
Michael Chan028de142015-12-09 19:35:44 -05007491 if (netif_running(bp->dev)) {
Michael Chanb386cd32017-03-08 18:44:33 -05007492 int rc;
7493
7494 if (!silent)
7495 bnxt_ulp_stop(bp);
Michael Chan028de142015-12-09 19:35:44 -05007496 bnxt_close_nic(bp, false, false);
Michael Chanb386cd32017-03-08 18:44:33 -05007497 rc = bnxt_open_nic(bp, false, false);
7498 if (!silent && !rc)
7499 bnxt_ulp_start(bp);
Michael Chan028de142015-12-09 19:35:44 -05007500 }
Michael Chanc0c050c2015-10-22 16:01:17 -04007501}
7502
7503static void bnxt_tx_timeout(struct net_device *dev)
7504{
7505 struct bnxt *bp = netdev_priv(dev);
7506
7507 netdev_err(bp->dev, "TX timeout detected, starting reset task!\n");
7508 set_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event);
Michael Chanc213eae2017-10-13 21:09:29 -04007509 bnxt_queue_sp_work(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04007510}
7511
7512#ifdef CONFIG_NET_POLL_CONTROLLER
7513static void bnxt_poll_controller(struct net_device *dev)
7514{
7515 struct bnxt *bp = netdev_priv(dev);
7516 int i;
7517
Michael Chan2270bc52017-06-23 14:01:01 -04007518 /* Only process tx rings/combined rings in netpoll mode. */
7519 for (i = 0; i < bp->tx_nr_rings; i++) {
7520 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04007521
Michael Chan2270bc52017-06-23 14:01:01 -04007522 napi_schedule(&txr->bnapi->napi);
Michael Chanc0c050c2015-10-22 16:01:17 -04007523 }
7524}
7525#endif
7526
Kees Cooke99e88a2017-10-16 14:43:17 -07007527static void bnxt_timer(struct timer_list *t)
Michael Chanc0c050c2015-10-22 16:01:17 -04007528{
Kees Cooke99e88a2017-10-16 14:43:17 -07007529 struct bnxt *bp = from_timer(bp, t, timer);
Michael Chanc0c050c2015-10-22 16:01:17 -04007530 struct net_device *dev = bp->dev;
7531
7532 if (!netif_running(dev))
7533 return;
7534
7535 if (atomic_read(&bp->intr_sem) != 0)
7536 goto bnxt_restart_timer;
7537
Michael Chanadcc3312017-07-24 12:34:24 -04007538 if (bp->link_info.link_up && (bp->flags & BNXT_FLAG_PORT_STATS) &&
7539 bp->stats_coal_ticks) {
Michael Chan3bdf56c2016-03-07 15:38:45 -05007540 set_bit(BNXT_PERIODIC_STATS_SP_EVENT, &bp->sp_event);
Michael Chanc213eae2017-10-13 21:09:29 -04007541 bnxt_queue_sp_work(bp);
Michael Chan3bdf56c2016-03-07 15:38:45 -05007542 }
Sathya Perla5a84acb2017-10-26 11:51:31 -04007543
7544 if (bnxt_tc_flower_enabled(bp)) {
7545 set_bit(BNXT_FLOW_STATS_SP_EVENT, &bp->sp_event);
7546 bnxt_queue_sp_work(bp);
7547 }
Michael Chanc0c050c2015-10-22 16:01:17 -04007548bnxt_restart_timer:
7549 mod_timer(&bp->timer, jiffies + bp->current_interval);
7550}
7551
Michael Chana551ee92017-01-25 02:55:07 -05007552static void bnxt_rtnl_lock_sp(struct bnxt *bp)
Michael Chan6988bd92016-06-13 02:25:29 -04007553{
Michael Chana551ee92017-01-25 02:55:07 -05007554 /* We are called from bnxt_sp_task which has BNXT_STATE_IN_SP_TASK
7555 * set. If the device is being closed, bnxt_close() may be holding
Michael Chan6988bd92016-06-13 02:25:29 -04007556 * rtnl() and waiting for BNXT_STATE_IN_SP_TASK to clear. So we
7557 * must clear BNXT_STATE_IN_SP_TASK before holding rtnl().
7558 */
7559 clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
7560 rtnl_lock();
Michael Chana551ee92017-01-25 02:55:07 -05007561}
7562
7563static void bnxt_rtnl_unlock_sp(struct bnxt *bp)
7564{
Michael Chan6988bd92016-06-13 02:25:29 -04007565 set_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
7566 rtnl_unlock();
7567}
7568
Michael Chana551ee92017-01-25 02:55:07 -05007569/* Only called from bnxt_sp_task() */
7570static void bnxt_reset(struct bnxt *bp, bool silent)
7571{
7572 bnxt_rtnl_lock_sp(bp);
7573 if (test_bit(BNXT_STATE_OPEN, &bp->state))
7574 bnxt_reset_task(bp, silent);
7575 bnxt_rtnl_unlock_sp(bp);
7576}
7577
Michael Chanc0c050c2015-10-22 16:01:17 -04007578static void bnxt_cfg_ntp_filters(struct bnxt *);
7579
7580static void bnxt_sp_task(struct work_struct *work)
7581{
7582 struct bnxt *bp = container_of(work, struct bnxt, sp_task);
Michael Chanc0c050c2015-10-22 16:01:17 -04007583
Michael Chan4cebdce2015-12-09 19:35:43 -05007584 set_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
7585 smp_mb__after_atomic();
7586 if (!test_bit(BNXT_STATE_OPEN, &bp->state)) {
7587 clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
Michael Chanc0c050c2015-10-22 16:01:17 -04007588 return;
Michael Chan4cebdce2015-12-09 19:35:43 -05007589 }
Michael Chanc0c050c2015-10-22 16:01:17 -04007590
7591 if (test_and_clear_bit(BNXT_RX_MASK_SP_EVENT, &bp->sp_event))
7592 bnxt_cfg_rx_mode(bp);
7593
7594 if (test_and_clear_bit(BNXT_RX_NTP_FLTR_SP_EVENT, &bp->sp_event))
7595 bnxt_cfg_ntp_filters(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04007596 if (test_and_clear_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT, &bp->sp_event))
7597 bnxt_hwrm_exec_fwd_req(bp);
7598 if (test_and_clear_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT, &bp->sp_event)) {
7599 bnxt_hwrm_tunnel_dst_port_alloc(
7600 bp, bp->vxlan_port,
7601 TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN);
7602 }
7603 if (test_and_clear_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT, &bp->sp_event)) {
7604 bnxt_hwrm_tunnel_dst_port_free(
7605 bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN);
7606 }
Alexander Duyck7cdd5fc2016-06-16 12:21:36 -07007607 if (test_and_clear_bit(BNXT_GENEVE_ADD_PORT_SP_EVENT, &bp->sp_event)) {
7608 bnxt_hwrm_tunnel_dst_port_alloc(
7609 bp, bp->nge_port,
7610 TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE);
7611 }
7612 if (test_and_clear_bit(BNXT_GENEVE_DEL_PORT_SP_EVENT, &bp->sp_event)) {
7613 bnxt_hwrm_tunnel_dst_port_free(
7614 bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE);
7615 }
Vasundhara Volam00db3cb2018-03-31 13:54:12 -04007616 if (test_and_clear_bit(BNXT_PERIODIC_STATS_SP_EVENT, &bp->sp_event)) {
Michael Chan3bdf56c2016-03-07 15:38:45 -05007617 bnxt_hwrm_port_qstats(bp);
Vasundhara Volam00db3cb2018-03-31 13:54:12 -04007618 bnxt_hwrm_port_qstats_ext(bp);
7619 }
Michael Chan3bdf56c2016-03-07 15:38:45 -05007620
Michael Chan0eaa24b2017-01-25 02:55:08 -05007621 if (test_and_clear_bit(BNXT_LINK_CHNG_SP_EVENT, &bp->sp_event)) {
Michael Chane2dc9b62017-10-13 21:09:30 -04007622 int rc;
Michael Chan0eaa24b2017-01-25 02:55:08 -05007623
Michael Chane2dc9b62017-10-13 21:09:30 -04007624 mutex_lock(&bp->link_lock);
Michael Chan0eaa24b2017-01-25 02:55:08 -05007625 if (test_and_clear_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT,
7626 &bp->sp_event))
7627 bnxt_hwrm_phy_qcaps(bp);
7628
Michael Chane2dc9b62017-10-13 21:09:30 -04007629 rc = bnxt_update_link(bp, true);
7630 mutex_unlock(&bp->link_lock);
Michael Chan0eaa24b2017-01-25 02:55:08 -05007631 if (rc)
7632 netdev_err(bp->dev, "SP task can't update link (rc: %x)\n",
7633 rc);
7634 }
Michael Chan90c694b2017-01-25 02:55:09 -05007635 if (test_and_clear_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT, &bp->sp_event)) {
Michael Chane2dc9b62017-10-13 21:09:30 -04007636 mutex_lock(&bp->link_lock);
7637 bnxt_get_port_module_status(bp);
7638 mutex_unlock(&bp->link_lock);
Michael Chan90c694b2017-01-25 02:55:09 -05007639 }
Sathya Perla5a84acb2017-10-26 11:51:31 -04007640
7641 if (test_and_clear_bit(BNXT_FLOW_STATS_SP_EVENT, &bp->sp_event))
7642 bnxt_tc_flow_stats_work(bp);
7643
Michael Chane2dc9b62017-10-13 21:09:30 -04007644 /* These functions below will clear BNXT_STATE_IN_SP_TASK. They
7645 * must be the last functions to be called before exiting.
7646 */
Michael Chanc0c050c2015-10-22 16:01:17 -04007647 if (test_and_clear_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event))
7648 bnxt_reset(bp, false);
7649
7650 if (test_and_clear_bit(BNXT_RESET_TASK_SILENT_SP_EVENT, &bp->sp_event))
7651 bnxt_reset(bp, true);
7652
Michael Chanc0c050c2015-10-22 16:01:17 -04007653 smp_mb__before_atomic();
7654 clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
7655}
7656
Michael Chand1e79252017-02-06 16:55:38 -05007657/* Under rtnl_lock */
Michael Chan98fdbe72017-08-28 13:40:26 -04007658int bnxt_check_rings(struct bnxt *bp, int tx, int rx, bool sh, int tcs,
7659 int tx_xdp)
Michael Chand1e79252017-02-06 16:55:38 -05007660{
7661 int max_rx, max_tx, tx_sets = 1;
7662 int tx_rings_needed;
Michael Chan8f23d632018-01-17 03:21:12 -05007663 int rx_rings = rx;
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05007664 int cp, vnics, rc;
Michael Chand1e79252017-02-06 16:55:38 -05007665
Michael Chand1e79252017-02-06 16:55:38 -05007666 if (tcs)
7667 tx_sets = tcs;
7668
7669 rc = bnxt_get_max_rings(bp, &max_rx, &max_tx, sh);
7670 if (rc)
7671 return rc;
7672
7673 if (max_rx < rx)
7674 return -ENOMEM;
7675
Michael Chan5f449242017-02-06 16:55:40 -05007676 tx_rings_needed = tx * tx_sets + tx_xdp;
Michael Chand1e79252017-02-06 16:55:38 -05007677 if (max_tx < tx_rings_needed)
7678 return -ENOMEM;
7679
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05007680 vnics = 1;
7681 if (bp->flags & BNXT_FLAG_RFS)
7682 vnics += rx_rings;
7683
Michael Chan8f23d632018-01-17 03:21:12 -05007684 if (bp->flags & BNXT_FLAG_AGG_RINGS)
7685 rx_rings <<= 1;
7686 cp = sh ? max_t(int, tx_rings_needed, rx) : tx_rings_needed + rx;
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05007687 return bnxt_hwrm_check_rings(bp, tx_rings_needed, rx_rings, rx, cp,
7688 vnics);
Michael Chand1e79252017-02-06 16:55:38 -05007689}
7690
Sathya Perla17086392017-02-20 19:25:18 -05007691static void bnxt_unmap_bars(struct bnxt *bp, struct pci_dev *pdev)
7692{
7693 if (bp->bar2) {
7694 pci_iounmap(pdev, bp->bar2);
7695 bp->bar2 = NULL;
7696 }
7697
7698 if (bp->bar1) {
7699 pci_iounmap(pdev, bp->bar1);
7700 bp->bar1 = NULL;
7701 }
7702
7703 if (bp->bar0) {
7704 pci_iounmap(pdev, bp->bar0);
7705 bp->bar0 = NULL;
7706 }
7707}
7708
7709static void bnxt_cleanup_pci(struct bnxt *bp)
7710{
7711 bnxt_unmap_bars(bp, bp->pdev);
7712 pci_release_regions(bp->pdev);
7713 pci_disable_device(bp->pdev);
7714}
7715
Michael Chan18775aa2017-10-26 11:51:27 -04007716static void bnxt_init_dflt_coal(struct bnxt *bp)
7717{
7718 struct bnxt_coal *coal;
7719
7720 /* Tick values in micro seconds.
7721 * 1 coal_buf x bufs_per_record = 1 completion record.
7722 */
7723 coal = &bp->rx_coal;
7724 coal->coal_ticks = 14;
7725 coal->coal_bufs = 30;
7726 coal->coal_ticks_irq = 1;
7727 coal->coal_bufs_irq = 2;
7728 coal->idle_thresh = 25;
7729 coal->bufs_per_record = 2;
7730 coal->budget = 64; /* NAPI budget */
7731
7732 coal = &bp->tx_coal;
7733 coal->coal_ticks = 28;
7734 coal->coal_bufs = 30;
7735 coal->coal_ticks_irq = 2;
7736 coal->coal_bufs_irq = 2;
7737 coal->bufs_per_record = 1;
7738
7739 bp->stats_coal_ticks = BNXT_DEF_STATS_COAL_TICKS;
7740}
7741
Michael Chanc0c050c2015-10-22 16:01:17 -04007742static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev)
7743{
7744 int rc;
7745 struct bnxt *bp = netdev_priv(dev);
7746
7747 SET_NETDEV_DEV(dev, &pdev->dev);
7748
7749 /* enable device (incl. PCI PM wakeup), and bus-mastering */
7750 rc = pci_enable_device(pdev);
7751 if (rc) {
7752 dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n");
7753 goto init_err;
7754 }
7755
7756 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
7757 dev_err(&pdev->dev,
7758 "Cannot find PCI device base address, aborting\n");
7759 rc = -ENODEV;
7760 goto init_err_disable;
7761 }
7762
7763 rc = pci_request_regions(pdev, DRV_MODULE_NAME);
7764 if (rc) {
7765 dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting\n");
7766 goto init_err_disable;
7767 }
7768
7769 if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)) != 0 &&
7770 dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)) != 0) {
7771 dev_err(&pdev->dev, "System does not support DMA, aborting\n");
7772 goto init_err_disable;
7773 }
7774
7775 pci_set_master(pdev);
7776
7777 bp->dev = dev;
7778 bp->pdev = pdev;
7779
7780 bp->bar0 = pci_ioremap_bar(pdev, 0);
7781 if (!bp->bar0) {
7782 dev_err(&pdev->dev, "Cannot map device registers, aborting\n");
7783 rc = -ENOMEM;
7784 goto init_err_release;
7785 }
7786
7787 bp->bar1 = pci_ioremap_bar(pdev, 2);
7788 if (!bp->bar1) {
7789 dev_err(&pdev->dev, "Cannot map doorbell registers, aborting\n");
7790 rc = -ENOMEM;
7791 goto init_err_release;
7792 }
7793
7794 bp->bar2 = pci_ioremap_bar(pdev, 4);
7795 if (!bp->bar2) {
7796 dev_err(&pdev->dev, "Cannot map bar4 registers, aborting\n");
7797 rc = -ENOMEM;
7798 goto init_err_release;
7799 }
7800
Satish Baddipadige6316ea62016-03-07 15:38:48 -05007801 pci_enable_pcie_error_reporting(pdev);
7802
Michael Chanc0c050c2015-10-22 16:01:17 -04007803 INIT_WORK(&bp->sp_task, bnxt_sp_task);
7804
7805 spin_lock_init(&bp->ntp_fltr_lock);
7806
7807 bp->rx_ring_size = BNXT_DEFAULT_RX_RING_SIZE;
7808 bp->tx_ring_size = BNXT_DEFAULT_TX_RING_SIZE;
7809
Michael Chan18775aa2017-10-26 11:51:27 -04007810 bnxt_init_dflt_coal(bp);
Michael Chan51f30782016-07-01 18:46:29 -04007811
Kees Cooke99e88a2017-10-16 14:43:17 -07007812 timer_setup(&bp->timer, bnxt_timer, 0);
Michael Chanc0c050c2015-10-22 16:01:17 -04007813 bp->current_interval = BNXT_TIMER_INTERVAL;
7814
Michael Chancaefe522015-12-09 19:35:42 -05007815 clear_bit(BNXT_STATE_OPEN, &bp->state);
Michael Chanc0c050c2015-10-22 16:01:17 -04007816 return 0;
7817
7818init_err_release:
Sathya Perla17086392017-02-20 19:25:18 -05007819 bnxt_unmap_bars(bp, pdev);
Michael Chanc0c050c2015-10-22 16:01:17 -04007820 pci_release_regions(pdev);
7821
7822init_err_disable:
7823 pci_disable_device(pdev);
7824
7825init_err:
7826 return rc;
7827}
7828
7829/* rtnl_lock held */
7830static int bnxt_change_mac_addr(struct net_device *dev, void *p)
7831{
7832 struct sockaddr *addr = p;
Jeffrey Huang1fc2cfd2015-12-02 01:54:06 -05007833 struct bnxt *bp = netdev_priv(dev);
7834 int rc = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04007835
7836 if (!is_valid_ether_addr(addr->sa_data))
7837 return -EADDRNOTAVAIL;
7838
Michael Chanc1a7bdf2017-10-26 11:51:24 -04007839 if (ether_addr_equal(addr->sa_data, dev->dev_addr))
7840 return 0;
7841
Michael Chan84c33dd2016-04-11 04:11:13 -04007842 rc = bnxt_approve_mac(bp, addr->sa_data);
7843 if (rc)
7844 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04007845
Jeffrey Huang1fc2cfd2015-12-02 01:54:06 -05007846 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
7847 if (netif_running(dev)) {
7848 bnxt_close_nic(bp, false, false);
7849 rc = bnxt_open_nic(bp, false, false);
7850 }
7851
7852 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04007853}
7854
7855/* rtnl_lock held */
7856static int bnxt_change_mtu(struct net_device *dev, int new_mtu)
7857{
7858 struct bnxt *bp = netdev_priv(dev);
7859
Michael Chanc0c050c2015-10-22 16:01:17 -04007860 if (netif_running(dev))
7861 bnxt_close_nic(bp, false, false);
7862
7863 dev->mtu = new_mtu;
7864 bnxt_set_ring_params(bp);
7865
7866 if (netif_running(dev))
7867 return bnxt_open_nic(bp, false, false);
7868
7869 return 0;
7870}
7871
Michael Chanc5e3deb2016-12-02 21:17:15 -05007872int bnxt_setup_mq_tc(struct net_device *dev, u8 tc)
Michael Chanc0c050c2015-10-22 16:01:17 -04007873{
7874 struct bnxt *bp = netdev_priv(dev);
Michael Chan3ffb6a32016-11-11 00:11:42 -05007875 bool sh = false;
Michael Chand1e79252017-02-06 16:55:38 -05007876 int rc;
John Fastabend16e5cc62016-02-16 21:16:43 -08007877
Michael Chanc0c050c2015-10-22 16:01:17 -04007878 if (tc > bp->max_tc) {
Michael Chanb451c8b2017-02-12 19:18:17 -05007879 netdev_err(dev, "Too many traffic classes requested: %d. Max supported is %d.\n",
Michael Chanc0c050c2015-10-22 16:01:17 -04007880 tc, bp->max_tc);
7881 return -EINVAL;
7882 }
7883
7884 if (netdev_get_num_tc(dev) == tc)
7885 return 0;
7886
Michael Chan3ffb6a32016-11-11 00:11:42 -05007887 if (bp->flags & BNXT_FLAG_SHARED_RINGS)
7888 sh = true;
7889
Michael Chan98fdbe72017-08-28 13:40:26 -04007890 rc = bnxt_check_rings(bp, bp->tx_nr_rings_per_tc, bp->rx_nr_rings,
7891 sh, tc, bp->tx_nr_rings_xdp);
Michael Chand1e79252017-02-06 16:55:38 -05007892 if (rc)
7893 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04007894
7895 /* Needs to close the device and do hw resource re-allocations */
7896 if (netif_running(bp->dev))
7897 bnxt_close_nic(bp, true, false);
7898
7899 if (tc) {
7900 bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tc;
7901 netdev_set_num_tc(dev, tc);
7902 } else {
7903 bp->tx_nr_rings = bp->tx_nr_rings_per_tc;
7904 netdev_reset_tc(dev);
7905 }
Michael Chan87e9b372017-08-23 19:34:03 -04007906 bp->tx_nr_rings += bp->tx_nr_rings_xdp;
Michael Chan3ffb6a32016-11-11 00:11:42 -05007907 bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
7908 bp->tx_nr_rings + bp->rx_nr_rings;
Michael Chanc0c050c2015-10-22 16:01:17 -04007909 bp->num_stat_ctxs = bp->cp_nr_rings;
7910
7911 if (netif_running(bp->dev))
7912 return bnxt_open_nic(bp, true, false);
7913
7914 return 0;
7915}
7916
Jiri Pirko9e0fd152017-10-19 15:50:39 +02007917static int bnxt_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
7918 void *cb_priv)
Sathya Perla2ae74082017-08-28 13:40:33 -04007919{
Jiri Pirko9e0fd152017-10-19 15:50:39 +02007920 struct bnxt *bp = cb_priv;
Sathya Perla2ae74082017-08-28 13:40:33 -04007921
Jakub Kicinski312324f2018-01-25 14:00:48 -08007922 if (!bnxt_tc_flower_enabled(bp) ||
7923 !tc_cls_can_offload_and_chain0(bp->dev, type_data))
Sathya Perla2ae74082017-08-28 13:40:33 -04007924 return -EOPNOTSUPP;
7925
Jiri Pirko9e0fd152017-10-19 15:50:39 +02007926 switch (type) {
7927 case TC_SETUP_CLSFLOWER:
7928 return bnxt_tc_setup_flower(bp, bp->pf.fw_fid, type_data);
7929 default:
7930 return -EOPNOTSUPP;
7931 }
7932}
7933
7934static int bnxt_setup_tc_block(struct net_device *dev,
7935 struct tc_block_offload *f)
7936{
7937 struct bnxt *bp = netdev_priv(dev);
7938
7939 if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
7940 return -EOPNOTSUPP;
7941
7942 switch (f->command) {
7943 case TC_BLOCK_BIND:
7944 return tcf_block_cb_register(f->block, bnxt_setup_tc_block_cb,
7945 bp, bp);
7946 case TC_BLOCK_UNBIND:
7947 tcf_block_cb_unregister(f->block, bnxt_setup_tc_block_cb, bp);
7948 return 0;
7949 default:
7950 return -EOPNOTSUPP;
7951 }
Sathya Perla2ae74082017-08-28 13:40:33 -04007952}
7953
Jiri Pirko2572ac52017-08-07 10:15:17 +02007954static int bnxt_setup_tc(struct net_device *dev, enum tc_setup_type type,
Jiri Pirkode4784c2017-08-07 10:15:32 +02007955 void *type_data)
Michael Chanc5e3deb2016-12-02 21:17:15 -05007956{
Sathya Perla2ae74082017-08-28 13:40:33 -04007957 switch (type) {
Jiri Pirko9e0fd152017-10-19 15:50:39 +02007958 case TC_SETUP_BLOCK:
7959 return bnxt_setup_tc_block(dev, type_data);
Nogah Frankel575ed7d2017-11-06 07:23:42 +01007960 case TC_SETUP_QDISC_MQPRIO: {
Sathya Perla2ae74082017-08-28 13:40:33 -04007961 struct tc_mqprio_qopt *mqprio = type_data;
Jiri Pirkode4784c2017-08-07 10:15:32 +02007962
Sathya Perla2ae74082017-08-28 13:40:33 -04007963 mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
7964
7965 return bnxt_setup_mq_tc(dev, mqprio->num_tc);
7966 }
7967 default:
Jiri Pirko38cf0422017-08-07 10:15:31 +02007968 return -EOPNOTSUPP;
Sathya Perla2ae74082017-08-28 13:40:33 -04007969 }
Michael Chanc5e3deb2016-12-02 21:17:15 -05007970}
7971
Michael Chanc0c050c2015-10-22 16:01:17 -04007972#ifdef CONFIG_RFS_ACCEL
7973static bool bnxt_fltr_match(struct bnxt_ntuple_filter *f1,
7974 struct bnxt_ntuple_filter *f2)
7975{
7976 struct flow_keys *keys1 = &f1->fkeys;
7977 struct flow_keys *keys2 = &f2->fkeys;
7978
7979 if (keys1->addrs.v4addrs.src == keys2->addrs.v4addrs.src &&
7980 keys1->addrs.v4addrs.dst == keys2->addrs.v4addrs.dst &&
7981 keys1->ports.ports == keys2->ports.ports &&
7982 keys1->basic.ip_proto == keys2->basic.ip_proto &&
7983 keys1->basic.n_proto == keys2->basic.n_proto &&
Michael Chan61aad722017-02-12 19:18:14 -05007984 keys1->control.flags == keys2->control.flags &&
Michael Chana54c4d72016-07-25 12:33:35 -04007985 ether_addr_equal(f1->src_mac_addr, f2->src_mac_addr) &&
7986 ether_addr_equal(f1->dst_mac_addr, f2->dst_mac_addr))
Michael Chanc0c050c2015-10-22 16:01:17 -04007987 return true;
7988
7989 return false;
7990}
7991
7992static int bnxt_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
7993 u16 rxq_index, u32 flow_id)
7994{
7995 struct bnxt *bp = netdev_priv(dev);
7996 struct bnxt_ntuple_filter *fltr, *new_fltr;
7997 struct flow_keys *fkeys;
7998 struct ethhdr *eth = (struct ethhdr *)skb_mac_header(skb);
Michael Chana54c4d72016-07-25 12:33:35 -04007999 int rc = 0, idx, bit_id, l2_idx = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04008000 struct hlist_head *head;
8001
Michael Chana54c4d72016-07-25 12:33:35 -04008002 if (!ether_addr_equal(dev->dev_addr, eth->h_dest)) {
8003 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
8004 int off = 0, j;
8005
8006 netif_addr_lock_bh(dev);
8007 for (j = 0; j < vnic->uc_filter_count; j++, off += ETH_ALEN) {
8008 if (ether_addr_equal(eth->h_dest,
8009 vnic->uc_list + off)) {
8010 l2_idx = j + 1;
8011 break;
8012 }
8013 }
8014 netif_addr_unlock_bh(dev);
8015 if (!l2_idx)
8016 return -EINVAL;
8017 }
Michael Chanc0c050c2015-10-22 16:01:17 -04008018 new_fltr = kzalloc(sizeof(*new_fltr), GFP_ATOMIC);
8019 if (!new_fltr)
8020 return -ENOMEM;
8021
8022 fkeys = &new_fltr->fkeys;
8023 if (!skb_flow_dissect_flow_keys(skb, fkeys, 0)) {
8024 rc = -EPROTONOSUPPORT;
8025 goto err_free;
8026 }
8027
Michael Chandda0e742016-12-29 12:13:40 -05008028 if ((fkeys->basic.n_proto != htons(ETH_P_IP) &&
8029 fkeys->basic.n_proto != htons(ETH_P_IPV6)) ||
Michael Chanc0c050c2015-10-22 16:01:17 -04008030 ((fkeys->basic.ip_proto != IPPROTO_TCP) &&
8031 (fkeys->basic.ip_proto != IPPROTO_UDP))) {
8032 rc = -EPROTONOSUPPORT;
8033 goto err_free;
8034 }
Michael Chandda0e742016-12-29 12:13:40 -05008035 if (fkeys->basic.n_proto == htons(ETH_P_IPV6) &&
8036 bp->hwrm_spec_code < 0x10601) {
8037 rc = -EPROTONOSUPPORT;
8038 goto err_free;
8039 }
Michael Chan61aad722017-02-12 19:18:14 -05008040 if ((fkeys->control.flags & FLOW_DIS_ENCAPSULATION) &&
8041 bp->hwrm_spec_code < 0x10601) {
8042 rc = -EPROTONOSUPPORT;
8043 goto err_free;
8044 }
Michael Chanc0c050c2015-10-22 16:01:17 -04008045
Michael Chana54c4d72016-07-25 12:33:35 -04008046 memcpy(new_fltr->dst_mac_addr, eth->h_dest, ETH_ALEN);
Michael Chanc0c050c2015-10-22 16:01:17 -04008047 memcpy(new_fltr->src_mac_addr, eth->h_source, ETH_ALEN);
8048
8049 idx = skb_get_hash_raw(skb) & BNXT_NTP_FLTR_HASH_MASK;
8050 head = &bp->ntp_fltr_hash_tbl[idx];
8051 rcu_read_lock();
8052 hlist_for_each_entry_rcu(fltr, head, hash) {
8053 if (bnxt_fltr_match(fltr, new_fltr)) {
8054 rcu_read_unlock();
8055 rc = 0;
8056 goto err_free;
8057 }
8058 }
8059 rcu_read_unlock();
8060
8061 spin_lock_bh(&bp->ntp_fltr_lock);
Michael Chan84e86b92015-11-05 16:25:50 -05008062 bit_id = bitmap_find_free_region(bp->ntp_fltr_bmap,
8063 BNXT_NTP_FLTR_MAX_FLTR, 0);
8064 if (bit_id < 0) {
Michael Chanc0c050c2015-10-22 16:01:17 -04008065 spin_unlock_bh(&bp->ntp_fltr_lock);
8066 rc = -ENOMEM;
8067 goto err_free;
8068 }
8069
Michael Chan84e86b92015-11-05 16:25:50 -05008070 new_fltr->sw_id = (u16)bit_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04008071 new_fltr->flow_id = flow_id;
Michael Chana54c4d72016-07-25 12:33:35 -04008072 new_fltr->l2_fltr_idx = l2_idx;
Michael Chanc0c050c2015-10-22 16:01:17 -04008073 new_fltr->rxq = rxq_index;
8074 hlist_add_head_rcu(&new_fltr->hash, head);
8075 bp->ntp_fltr_count++;
8076 spin_unlock_bh(&bp->ntp_fltr_lock);
8077
8078 set_bit(BNXT_RX_NTP_FLTR_SP_EVENT, &bp->sp_event);
Michael Chanc213eae2017-10-13 21:09:29 -04008079 bnxt_queue_sp_work(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04008080
8081 return new_fltr->sw_id;
8082
8083err_free:
8084 kfree(new_fltr);
8085 return rc;
8086}
8087
8088static void bnxt_cfg_ntp_filters(struct bnxt *bp)
8089{
8090 int i;
8091
8092 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
8093 struct hlist_head *head;
8094 struct hlist_node *tmp;
8095 struct bnxt_ntuple_filter *fltr;
8096 int rc;
8097
8098 head = &bp->ntp_fltr_hash_tbl[i];
8099 hlist_for_each_entry_safe(fltr, tmp, head, hash) {
8100 bool del = false;
8101
8102 if (test_bit(BNXT_FLTR_VALID, &fltr->state)) {
8103 if (rps_may_expire_flow(bp->dev, fltr->rxq,
8104 fltr->flow_id,
8105 fltr->sw_id)) {
8106 bnxt_hwrm_cfa_ntuple_filter_free(bp,
8107 fltr);
8108 del = true;
8109 }
8110 } else {
8111 rc = bnxt_hwrm_cfa_ntuple_filter_alloc(bp,
8112 fltr);
8113 if (rc)
8114 del = true;
8115 else
8116 set_bit(BNXT_FLTR_VALID, &fltr->state);
8117 }
8118
8119 if (del) {
8120 spin_lock_bh(&bp->ntp_fltr_lock);
8121 hlist_del_rcu(&fltr->hash);
8122 bp->ntp_fltr_count--;
8123 spin_unlock_bh(&bp->ntp_fltr_lock);
8124 synchronize_rcu();
8125 clear_bit(fltr->sw_id, bp->ntp_fltr_bmap);
8126 kfree(fltr);
8127 }
8128 }
8129 }
Jeffrey Huang19241362016-02-26 04:00:00 -05008130 if (test_and_clear_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT, &bp->sp_event))
8131 netdev_info(bp->dev, "Receive PF driver unload event!");
Michael Chanc0c050c2015-10-22 16:01:17 -04008132}
8133
8134#else
8135
8136static void bnxt_cfg_ntp_filters(struct bnxt *bp)
8137{
8138}
8139
8140#endif /* CONFIG_RFS_ACCEL */
8141
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008142static void bnxt_udp_tunnel_add(struct net_device *dev,
8143 struct udp_tunnel_info *ti)
Michael Chanc0c050c2015-10-22 16:01:17 -04008144{
8145 struct bnxt *bp = netdev_priv(dev);
8146
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008147 if (ti->sa_family != AF_INET6 && ti->sa_family != AF_INET)
8148 return;
8149
Michael Chanc0c050c2015-10-22 16:01:17 -04008150 if (!netif_running(dev))
8151 return;
8152
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008153 switch (ti->type) {
8154 case UDP_TUNNEL_TYPE_VXLAN:
8155 if (bp->vxlan_port_cnt && bp->vxlan_port != ti->port)
8156 return;
Michael Chanc0c050c2015-10-22 16:01:17 -04008157
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008158 bp->vxlan_port_cnt++;
8159 if (bp->vxlan_port_cnt == 1) {
8160 bp->vxlan_port = ti->port;
8161 set_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT, &bp->sp_event);
Michael Chanc213eae2017-10-13 21:09:29 -04008162 bnxt_queue_sp_work(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04008163 }
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008164 break;
Alexander Duyck7cdd5fc2016-06-16 12:21:36 -07008165 case UDP_TUNNEL_TYPE_GENEVE:
8166 if (bp->nge_port_cnt && bp->nge_port != ti->port)
8167 return;
8168
8169 bp->nge_port_cnt++;
8170 if (bp->nge_port_cnt == 1) {
8171 bp->nge_port = ti->port;
8172 set_bit(BNXT_GENEVE_ADD_PORT_SP_EVENT, &bp->sp_event);
8173 }
8174 break;
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008175 default:
8176 return;
Michael Chanc0c050c2015-10-22 16:01:17 -04008177 }
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008178
Michael Chanc213eae2017-10-13 21:09:29 -04008179 bnxt_queue_sp_work(bp);
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008180}
8181
8182static void bnxt_udp_tunnel_del(struct net_device *dev,
8183 struct udp_tunnel_info *ti)
8184{
8185 struct bnxt *bp = netdev_priv(dev);
8186
8187 if (ti->sa_family != AF_INET6 && ti->sa_family != AF_INET)
8188 return;
8189
8190 if (!netif_running(dev))
8191 return;
8192
8193 switch (ti->type) {
8194 case UDP_TUNNEL_TYPE_VXLAN:
8195 if (!bp->vxlan_port_cnt || bp->vxlan_port != ti->port)
8196 return;
8197 bp->vxlan_port_cnt--;
8198
8199 if (bp->vxlan_port_cnt != 0)
8200 return;
8201
8202 set_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT, &bp->sp_event);
8203 break;
Alexander Duyck7cdd5fc2016-06-16 12:21:36 -07008204 case UDP_TUNNEL_TYPE_GENEVE:
8205 if (!bp->nge_port_cnt || bp->nge_port != ti->port)
8206 return;
8207 bp->nge_port_cnt--;
8208
8209 if (bp->nge_port_cnt != 0)
8210 return;
8211
8212 set_bit(BNXT_GENEVE_DEL_PORT_SP_EVENT, &bp->sp_event);
8213 break;
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008214 default:
8215 return;
8216 }
8217
Michael Chanc213eae2017-10-13 21:09:29 -04008218 bnxt_queue_sp_work(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04008219}
8220
Michael Chan39d8ba22017-07-24 12:34:22 -04008221static int bnxt_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
8222 struct net_device *dev, u32 filter_mask,
8223 int nlflags)
8224{
8225 struct bnxt *bp = netdev_priv(dev);
8226
8227 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, bp->br_mode, 0, 0,
8228 nlflags, filter_mask, NULL);
8229}
8230
8231static int bnxt_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh,
8232 u16 flags)
8233{
8234 struct bnxt *bp = netdev_priv(dev);
8235 struct nlattr *attr, *br_spec;
8236 int rem, rc = 0;
8237
8238 if (bp->hwrm_spec_code < 0x10708 || !BNXT_SINGLE_PF(bp))
8239 return -EOPNOTSUPP;
8240
8241 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
8242 if (!br_spec)
8243 return -EINVAL;
8244
8245 nla_for_each_nested(attr, br_spec, rem) {
8246 u16 mode;
8247
8248 if (nla_type(attr) != IFLA_BRIDGE_MODE)
8249 continue;
8250
8251 if (nla_len(attr) < sizeof(mode))
8252 return -EINVAL;
8253
8254 mode = nla_get_u16(attr);
8255 if (mode == bp->br_mode)
8256 break;
8257
8258 rc = bnxt_hwrm_set_br_mode(bp, mode);
8259 if (!rc)
8260 bp->br_mode = mode;
8261 break;
8262 }
8263 return rc;
8264}
8265
Sathya Perlac124a622017-07-24 12:34:29 -04008266static int bnxt_get_phys_port_name(struct net_device *dev, char *buf,
8267 size_t len)
8268{
8269 struct bnxt *bp = netdev_priv(dev);
8270 int rc;
8271
8272 /* The PF and it's VF-reps only support the switchdev framework */
8273 if (!BNXT_PF(bp))
8274 return -EOPNOTSUPP;
8275
Sathya Perla53f70b82017-07-25 13:28:41 -04008276 rc = snprintf(buf, len, "p%d", bp->pf.port_id);
Sathya Perlac124a622017-07-24 12:34:29 -04008277
8278 if (rc >= len)
8279 return -EOPNOTSUPP;
8280 return 0;
8281}
8282
8283int bnxt_port_attr_get(struct bnxt *bp, struct switchdev_attr *attr)
8284{
8285 if (bp->eswitch_mode != DEVLINK_ESWITCH_MODE_SWITCHDEV)
8286 return -EOPNOTSUPP;
8287
8288 /* The PF and it's VF-reps only support the switchdev framework */
8289 if (!BNXT_PF(bp))
8290 return -EOPNOTSUPP;
8291
8292 switch (attr->id) {
8293 case SWITCHDEV_ATTR_ID_PORT_PARENT_ID:
Sathya Perladd4ea1d2018-01-17 03:21:16 -05008294 attr->u.ppid.id_len = sizeof(bp->switch_id);
8295 memcpy(attr->u.ppid.id, bp->switch_id, attr->u.ppid.id_len);
Sathya Perlac124a622017-07-24 12:34:29 -04008296 break;
8297 default:
8298 return -EOPNOTSUPP;
8299 }
8300 return 0;
8301}
8302
8303static int bnxt_swdev_port_attr_get(struct net_device *dev,
8304 struct switchdev_attr *attr)
8305{
8306 return bnxt_port_attr_get(netdev_priv(dev), attr);
8307}
8308
8309static const struct switchdev_ops bnxt_switchdev_ops = {
8310 .switchdev_port_attr_get = bnxt_swdev_port_attr_get
8311};
8312
Michael Chanc0c050c2015-10-22 16:01:17 -04008313static const struct net_device_ops bnxt_netdev_ops = {
8314 .ndo_open = bnxt_open,
8315 .ndo_start_xmit = bnxt_start_xmit,
8316 .ndo_stop = bnxt_close,
8317 .ndo_get_stats64 = bnxt_get_stats64,
8318 .ndo_set_rx_mode = bnxt_set_rx_mode,
8319 .ndo_do_ioctl = bnxt_ioctl,
8320 .ndo_validate_addr = eth_validate_addr,
8321 .ndo_set_mac_address = bnxt_change_mac_addr,
8322 .ndo_change_mtu = bnxt_change_mtu,
8323 .ndo_fix_features = bnxt_fix_features,
8324 .ndo_set_features = bnxt_set_features,
8325 .ndo_tx_timeout = bnxt_tx_timeout,
8326#ifdef CONFIG_BNXT_SRIOV
8327 .ndo_get_vf_config = bnxt_get_vf_config,
8328 .ndo_set_vf_mac = bnxt_set_vf_mac,
8329 .ndo_set_vf_vlan = bnxt_set_vf_vlan,
8330 .ndo_set_vf_rate = bnxt_set_vf_bw,
8331 .ndo_set_vf_link_state = bnxt_set_vf_link_state,
8332 .ndo_set_vf_spoofchk = bnxt_set_vf_spoofchk,
Vasundhara Volam746df132018-03-31 13:54:10 -04008333 .ndo_set_vf_trust = bnxt_set_vf_trust,
Michael Chanc0c050c2015-10-22 16:01:17 -04008334#endif
8335#ifdef CONFIG_NET_POLL_CONTROLLER
8336 .ndo_poll_controller = bnxt_poll_controller,
8337#endif
8338 .ndo_setup_tc = bnxt_setup_tc,
8339#ifdef CONFIG_RFS_ACCEL
8340 .ndo_rx_flow_steer = bnxt_rx_flow_steer,
8341#endif
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008342 .ndo_udp_tunnel_add = bnxt_udp_tunnel_add,
8343 .ndo_udp_tunnel_del = bnxt_udp_tunnel_del,
Jakub Kicinskif4e63522017-11-03 13:56:16 -07008344 .ndo_bpf = bnxt_xdp,
Michael Chan39d8ba22017-07-24 12:34:22 -04008345 .ndo_bridge_getlink = bnxt_bridge_getlink,
8346 .ndo_bridge_setlink = bnxt_bridge_setlink,
Sathya Perlac124a622017-07-24 12:34:29 -04008347 .ndo_get_phys_port_name = bnxt_get_phys_port_name
Michael Chanc0c050c2015-10-22 16:01:17 -04008348};
8349
8350static void bnxt_remove_one(struct pci_dev *pdev)
8351{
8352 struct net_device *dev = pci_get_drvdata(pdev);
8353 struct bnxt *bp = netdev_priv(dev);
8354
Sathya Perla4ab0c6a2017-07-24 12:34:27 -04008355 if (BNXT_PF(bp)) {
Michael Chanc0c050c2015-10-22 16:01:17 -04008356 bnxt_sriov_disable(bp);
Sathya Perla4ab0c6a2017-07-24 12:34:27 -04008357 bnxt_dl_unregister(bp);
8358 }
Michael Chanc0c050c2015-10-22 16:01:17 -04008359
Satish Baddipadige6316ea62016-03-07 15:38:48 -05008360 pci_disable_pcie_error_reporting(pdev);
Michael Chanc0c050c2015-10-22 16:01:17 -04008361 unregister_netdev(dev);
Sathya Perla2ae74082017-08-28 13:40:33 -04008362 bnxt_shutdown_tc(bp);
Michael Chanc213eae2017-10-13 21:09:29 -04008363 bnxt_cancel_sp_work(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04008364 bp->sp_event = 0;
8365
Michael Chan78095922016-12-07 00:26:16 -05008366 bnxt_clear_int_mode(bp);
Jeffrey Huangbe58a0d2015-12-27 18:19:18 -05008367 bnxt_hwrm_func_drv_unrgtr(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04008368 bnxt_free_hwrm_resources(bp);
Deepak Khungare605db82017-05-29 19:06:04 -04008369 bnxt_free_hwrm_short_cmd_req(bp);
Michael Chaneb513652017-04-04 18:14:12 -04008370 bnxt_ethtool_free(bp);
Michael Chan7df4ae92016-12-02 21:17:17 -05008371 bnxt_dcb_free(bp);
Michael Chana588e452016-12-07 00:26:21 -05008372 kfree(bp->edev);
8373 bp->edev = NULL;
Sathya Perla17086392017-02-20 19:25:18 -05008374 bnxt_cleanup_pci(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04008375 free_netdev(dev);
Michael Chanc0c050c2015-10-22 16:01:17 -04008376}
8377
8378static int bnxt_probe_phy(struct bnxt *bp)
8379{
8380 int rc = 0;
8381 struct bnxt_link_info *link_info = &bp->link_info;
Michael Chanc0c050c2015-10-22 16:01:17 -04008382
Michael Chan170ce012016-04-05 14:08:57 -04008383 rc = bnxt_hwrm_phy_qcaps(bp);
8384 if (rc) {
8385 netdev_err(bp->dev, "Probe phy can't get phy capabilities (rc: %x)\n",
8386 rc);
8387 return rc;
8388 }
Michael Chane2dc9b62017-10-13 21:09:30 -04008389 mutex_init(&bp->link_lock);
Michael Chan170ce012016-04-05 14:08:57 -04008390
Michael Chanc0c050c2015-10-22 16:01:17 -04008391 rc = bnxt_update_link(bp, false);
8392 if (rc) {
8393 netdev_err(bp->dev, "Probe phy can't update link (rc: %x)\n",
8394 rc);
8395 return rc;
8396 }
8397
Michael Chan93ed8112016-06-13 02:25:37 -04008398 /* Older firmware does not have supported_auto_speeds, so assume
8399 * that all supported speeds can be autonegotiated.
8400 */
8401 if (link_info->auto_link_speeds && !link_info->support_auto_speeds)
8402 link_info->support_auto_speeds = link_info->support_speeds;
8403
Michael Chanc0c050c2015-10-22 16:01:17 -04008404 /*initialize the ethool setting copy with NVM settings */
Michael Chan0d8abf02016-02-10 17:33:47 -05008405 if (BNXT_AUTO_MODE(link_info->auto_mode)) {
Michael Chanc9ee9512016-04-05 14:08:56 -04008406 link_info->autoneg = BNXT_AUTONEG_SPEED;
8407 if (bp->hwrm_spec_code >= 0x10201) {
8408 if (link_info->auto_pause_setting &
8409 PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE)
8410 link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
8411 } else {
8412 link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
8413 }
Michael Chan0d8abf02016-02-10 17:33:47 -05008414 link_info->advertising = link_info->auto_link_speeds;
Michael Chan0d8abf02016-02-10 17:33:47 -05008415 } else {
8416 link_info->req_link_speed = link_info->force_link_speed;
8417 link_info->req_duplex = link_info->duplex_setting;
Michael Chanc0c050c2015-10-22 16:01:17 -04008418 }
Michael Chanc9ee9512016-04-05 14:08:56 -04008419 if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL)
8420 link_info->req_flow_ctrl =
8421 link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH;
8422 else
8423 link_info->req_flow_ctrl = link_info->force_pause_setting;
Michael Chanc0c050c2015-10-22 16:01:17 -04008424 return rc;
8425}
8426
8427static int bnxt_get_max_irq(struct pci_dev *pdev)
8428{
8429 u16 ctrl;
8430
8431 if (!pdev->msix_cap)
8432 return 1;
8433
8434 pci_read_config_word(pdev, pdev->msix_cap + PCI_MSIX_FLAGS, &ctrl);
8435 return (ctrl & PCI_MSIX_FLAGS_QSIZE) + 1;
8436}
8437
Michael Chan6e6c5a52016-01-02 23:45:02 -05008438static void _bnxt_get_max_rings(struct bnxt *bp, int *max_rx, int *max_tx,
8439 int *max_cp)
Michael Chanc0c050c2015-10-22 16:01:17 -04008440{
Michael Chan6a4f2942018-01-17 03:21:06 -05008441 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
Michael Chan6e6c5a52016-01-02 23:45:02 -05008442 int max_ring_grps = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04008443
Michael Chan6a4f2942018-01-17 03:21:06 -05008444 *max_tx = hw_resc->max_tx_rings;
8445 *max_rx = hw_resc->max_rx_rings;
8446 *max_cp = min_t(int, hw_resc->max_irqs, hw_resc->max_cp_rings);
8447 *max_cp = min_t(int, *max_cp, hw_resc->max_stat_ctxs);
8448 max_ring_grps = hw_resc->max_hw_ring_grps;
Prashant Sreedharan76595192016-07-18 07:15:22 -04008449 if (BNXT_CHIP_TYPE_NITRO_A0(bp) && BNXT_PF(bp)) {
8450 *max_cp -= 1;
8451 *max_rx -= 2;
8452 }
Michael Chanc0c050c2015-10-22 16:01:17 -04008453 if (bp->flags & BNXT_FLAG_AGG_RINGS)
8454 *max_rx >>= 1;
Michael Chanb72d4a62015-12-27 18:19:27 -05008455 *max_rx = min_t(int, *max_rx, max_ring_grps);
Michael Chan6e6c5a52016-01-02 23:45:02 -05008456}
8457
8458int bnxt_get_max_rings(struct bnxt *bp, int *max_rx, int *max_tx, bool shared)
8459{
8460 int rx, tx, cp;
8461
8462 _bnxt_get_max_rings(bp, &rx, &tx, &cp);
8463 if (!rx || !tx || !cp)
8464 return -ENOMEM;
8465
8466 *max_rx = rx;
8467 *max_tx = tx;
8468 return bnxt_trim_rings(bp, max_rx, max_tx, cp, shared);
8469}
8470
Michael Chane4060d32016-12-07 00:26:19 -05008471static int bnxt_get_dflt_rings(struct bnxt *bp, int *max_rx, int *max_tx,
8472 bool shared)
8473{
8474 int rc;
8475
8476 rc = bnxt_get_max_rings(bp, max_rx, max_tx, shared);
Michael Chanbdbd1eb2016-12-29 12:13:43 -05008477 if (rc && (bp->flags & BNXT_FLAG_AGG_RINGS)) {
8478 /* Not enough rings, try disabling agg rings. */
8479 bp->flags &= ~BNXT_FLAG_AGG_RINGS;
8480 rc = bnxt_get_max_rings(bp, max_rx, max_tx, shared);
8481 if (rc)
8482 return rc;
8483 bp->flags |= BNXT_FLAG_NO_AGG_RINGS;
Michael Chan1054aee2017-12-16 03:09:42 -05008484 bp->dev->hw_features &= ~(NETIF_F_LRO | NETIF_F_GRO_HW);
8485 bp->dev->features &= ~(NETIF_F_LRO | NETIF_F_GRO_HW);
Michael Chanbdbd1eb2016-12-29 12:13:43 -05008486 bnxt_set_ring_params(bp);
8487 }
Michael Chane4060d32016-12-07 00:26:19 -05008488
8489 if (bp->flags & BNXT_FLAG_ROCE_CAP) {
8490 int max_cp, max_stat, max_irq;
8491
8492 /* Reserve minimum resources for RoCE */
8493 max_cp = bnxt_get_max_func_cp_rings(bp);
8494 max_stat = bnxt_get_max_func_stat_ctxs(bp);
8495 max_irq = bnxt_get_max_func_irqs(bp);
8496 if (max_cp <= BNXT_MIN_ROCE_CP_RINGS ||
8497 max_irq <= BNXT_MIN_ROCE_CP_RINGS ||
8498 max_stat <= BNXT_MIN_ROCE_STAT_CTXS)
8499 return 0;
8500
8501 max_cp -= BNXT_MIN_ROCE_CP_RINGS;
8502 max_irq -= BNXT_MIN_ROCE_CP_RINGS;
8503 max_stat -= BNXT_MIN_ROCE_STAT_CTXS;
8504 max_cp = min_t(int, max_cp, max_irq);
8505 max_cp = min_t(int, max_cp, max_stat);
8506 rc = bnxt_trim_rings(bp, max_rx, max_tx, max_cp, shared);
8507 if (rc)
8508 rc = 0;
8509 }
8510 return rc;
8511}
8512
Michael Chan58ea8012018-01-17 03:21:08 -05008513/* In initial default shared ring setting, each shared ring must have a
8514 * RX/TX ring pair.
8515 */
8516static void bnxt_trim_dflt_sh_rings(struct bnxt *bp)
8517{
8518 bp->cp_nr_rings = min_t(int, bp->tx_nr_rings_per_tc, bp->rx_nr_rings);
8519 bp->rx_nr_rings = bp->cp_nr_rings;
8520 bp->tx_nr_rings_per_tc = bp->cp_nr_rings;
8521 bp->tx_nr_rings = bp->tx_nr_rings_per_tc;
8522}
8523
Michael Chan702c2212017-05-29 19:06:10 -04008524static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh)
Michael Chan6e6c5a52016-01-02 23:45:02 -05008525{
8526 int dflt_rings, max_rx_rings, max_tx_rings, rc;
Michael Chan6e6c5a52016-01-02 23:45:02 -05008527
8528 if (sh)
8529 bp->flags |= BNXT_FLAG_SHARED_RINGS;
8530 dflt_rings = netif_get_num_default_rss_queues();
Michael Chan1d3ef132018-03-31 13:54:07 -04008531 /* Reduce default rings on multi-port cards so that total default
8532 * rings do not exceed CPU count.
8533 */
8534 if (bp->port_count > 1) {
8535 int max_rings =
8536 max_t(int, num_online_cpus() / bp->port_count, 1);
8537
8538 dflt_rings = min_t(int, dflt_rings, max_rings);
8539 }
Michael Chane4060d32016-12-07 00:26:19 -05008540 rc = bnxt_get_dflt_rings(bp, &max_rx_rings, &max_tx_rings, sh);
Michael Chan6e6c5a52016-01-02 23:45:02 -05008541 if (rc)
8542 return rc;
8543 bp->rx_nr_rings = min_t(int, dflt_rings, max_rx_rings);
8544 bp->tx_nr_rings_per_tc = min_t(int, dflt_rings, max_tx_rings);
Michael Chan58ea8012018-01-17 03:21:08 -05008545 if (sh)
8546 bnxt_trim_dflt_sh_rings(bp);
8547 else
8548 bp->cp_nr_rings = bp->tx_nr_rings_per_tc + bp->rx_nr_rings;
8549 bp->tx_nr_rings = bp->tx_nr_rings_per_tc;
Michael Chan391be5c2016-12-29 12:13:41 -05008550
Michael Chan674f50a2018-01-17 03:21:09 -05008551 rc = __bnxt_reserve_rings(bp);
Michael Chan391be5c2016-12-29 12:13:41 -05008552 if (rc)
8553 netdev_warn(bp->dev, "Unable to reserve tx rings\n");
Michael Chan58ea8012018-01-17 03:21:08 -05008554 bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
8555 if (sh)
8556 bnxt_trim_dflt_sh_rings(bp);
Michael Chan391be5c2016-12-29 12:13:41 -05008557
Michael Chan674f50a2018-01-17 03:21:09 -05008558 /* Rings may have been trimmed, re-reserve the trimmed rings. */
8559 if (bnxt_need_reserve_rings(bp)) {
8560 rc = __bnxt_reserve_rings(bp);
8561 if (rc)
8562 netdev_warn(bp->dev, "2nd rings reservation failed.\n");
8563 bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
8564 }
Michael Chan6e6c5a52016-01-02 23:45:02 -05008565 bp->num_stat_ctxs = bp->cp_nr_rings;
Prashant Sreedharan76595192016-07-18 07:15:22 -04008566 if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
8567 bp->rx_nr_rings++;
8568 bp->cp_nr_rings++;
8569 }
Michael Chan6e6c5a52016-01-02 23:45:02 -05008570 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04008571}
8572
Michael Chan80fcaf42018-01-17 03:21:05 -05008573int bnxt_restore_pf_fw_resources(struct bnxt *bp)
Michael Chan7b08f662016-12-07 00:26:18 -05008574{
Michael Chan80fcaf42018-01-17 03:21:05 -05008575 int rc;
8576
Michael Chan7b08f662016-12-07 00:26:18 -05008577 ASSERT_RTNL();
Michael Chan80fcaf42018-01-17 03:21:05 -05008578 if (bnxt_ulp_registered(bp->edev, BNXT_ROCE_ULP))
8579 return 0;
8580
Michael Chan7b08f662016-12-07 00:26:18 -05008581 bnxt_hwrm_func_qcaps(bp);
Venkat Duvvuru1a037782018-03-09 23:46:09 -05008582
8583 if (netif_running(bp->dev))
8584 __bnxt_close_nic(bp, true, false);
8585
Michael Chan80fcaf42018-01-17 03:21:05 -05008586 bnxt_clear_int_mode(bp);
8587 rc = bnxt_init_int_mode(bp);
Venkat Duvvuru1a037782018-03-09 23:46:09 -05008588
8589 if (netif_running(bp->dev)) {
8590 if (rc)
8591 dev_close(bp->dev);
8592 else
8593 rc = bnxt_open_nic(bp, true, false);
8594 }
8595
Michael Chan80fcaf42018-01-17 03:21:05 -05008596 return rc;
Michael Chan7b08f662016-12-07 00:26:18 -05008597}
8598
Michael Chana22a6ac2017-08-23 19:34:05 -04008599static int bnxt_init_mac_addr(struct bnxt *bp)
8600{
8601 int rc = 0;
8602
8603 if (BNXT_PF(bp)) {
8604 memcpy(bp->dev->dev_addr, bp->pf.mac_addr, ETH_ALEN);
8605 } else {
8606#ifdef CONFIG_BNXT_SRIOV
8607 struct bnxt_vf_info *vf = &bp->vf;
8608
8609 if (is_valid_ether_addr(vf->mac_addr)) {
Vasundhara Volam91cdda42018-01-17 03:21:14 -05008610 /* overwrite netdev dev_addr with admin VF MAC */
Michael Chana22a6ac2017-08-23 19:34:05 -04008611 memcpy(bp->dev->dev_addr, vf->mac_addr, ETH_ALEN);
8612 } else {
8613 eth_hw_addr_random(bp->dev);
8614 rc = bnxt_approve_mac(bp, bp->dev->dev_addr);
8615 }
8616#endif
8617 }
8618 return rc;
8619}
8620
Ajit Khaparde90c4f782016-05-15 03:04:45 -04008621static void bnxt_parse_log_pcie_link(struct bnxt *bp)
8622{
8623 enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN;
8624 enum pci_bus_speed speed = PCI_SPEED_UNKNOWN;
8625
Vasundhara Volam7ab07602017-10-13 21:09:31 -04008626 if (pcie_get_minimum_link(pci_physfn(bp->pdev), &speed, &width) ||
Ajit Khaparde90c4f782016-05-15 03:04:45 -04008627 speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN)
8628 netdev_info(bp->dev, "Failed to determine PCIe Link Info\n");
8629 else
8630 netdev_info(bp->dev, "PCIe: Speed %s Width x%d\n",
8631 speed == PCIE_SPEED_2_5GT ? "2.5GT/s" :
8632 speed == PCIE_SPEED_5_0GT ? "5.0GT/s" :
8633 speed == PCIE_SPEED_8_0GT ? "8.0GT/s" :
8634 "Unknown", width);
8635}
8636
Michael Chanc0c050c2015-10-22 16:01:17 -04008637static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
8638{
8639 static int version_printed;
8640 struct net_device *dev;
8641 struct bnxt *bp;
Michael Chan6e6c5a52016-01-02 23:45:02 -05008642 int rc, max_irqs;
Michael Chanc0c050c2015-10-22 16:01:17 -04008643
Ray Jui4e003382017-02-20 19:25:16 -05008644 if (pci_is_bridge(pdev))
Prashant Sreedharanfa853dd2016-07-18 07:15:25 -04008645 return -ENODEV;
8646
Michael Chanc0c050c2015-10-22 16:01:17 -04008647 if (version_printed++ == 0)
8648 pr_info("%s", version);
8649
8650 max_irqs = bnxt_get_max_irq(pdev);
8651 dev = alloc_etherdev_mq(sizeof(*bp), max_irqs);
8652 if (!dev)
8653 return -ENOMEM;
8654
8655 bp = netdev_priv(dev);
8656
8657 if (bnxt_vf_pciid(ent->driver_data))
8658 bp->flags |= BNXT_FLAG_VF;
8659
Michael Chan2bcfa6f2015-12-27 18:19:24 -05008660 if (pdev->msix_cap)
Michael Chanc0c050c2015-10-22 16:01:17 -04008661 bp->flags |= BNXT_FLAG_MSIX_CAP;
Michael Chanc0c050c2015-10-22 16:01:17 -04008662
8663 rc = bnxt_init_board(pdev, dev);
8664 if (rc < 0)
8665 goto init_err_free;
8666
8667 dev->netdev_ops = &bnxt_netdev_ops;
8668 dev->watchdog_timeo = BNXT_TX_TIMEOUT;
8669 dev->ethtool_ops = &bnxt_ethtool_ops;
David S. Millerbc880552017-07-24 21:20:16 -07008670 SWITCHDEV_SET_OPS(dev, &bnxt_switchdev_ops);
Michael Chanc0c050c2015-10-22 16:01:17 -04008671 pci_set_drvdata(pdev, dev);
8672
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04008673 rc = bnxt_alloc_hwrm_resources(bp);
8674 if (rc)
Sathya Perla17086392017-02-20 19:25:18 -05008675 goto init_err_pci_clean;
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04008676
8677 mutex_init(&bp->hwrm_cmd_lock);
8678 rc = bnxt_hwrm_ver_get(bp);
8679 if (rc)
Sathya Perla17086392017-02-20 19:25:18 -05008680 goto init_err_pci_clean;
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04008681
Deepak Khungare605db82017-05-29 19:06:04 -04008682 if (bp->flags & BNXT_FLAG_SHORT_CMD) {
8683 rc = bnxt_alloc_hwrm_short_cmd_req(bp);
8684 if (rc)
8685 goto init_err_pci_clean;
8686 }
8687
Michael Chan3c2217a2017-03-08 18:44:32 -05008688 rc = bnxt_hwrm_func_reset(bp);
8689 if (rc)
8690 goto init_err_pci_clean;
8691
Rob Swindell5ac67d82016-09-19 03:58:03 -04008692 bnxt_hwrm_fw_set_time(bp);
8693
Michael Chanc0c050c2015-10-22 16:01:17 -04008694 dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
8695 NETIF_F_TSO | NETIF_F_TSO6 |
8696 NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_GRE |
Tom Herbert7e133182016-05-18 09:06:10 -07008697 NETIF_F_GSO_IPXIP4 |
Alexander Duyck152971e2016-05-02 09:38:55 -07008698 NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_GSO_GRE_CSUM |
8699 NETIF_F_GSO_PARTIAL | NETIF_F_RXHASH |
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04008700 NETIF_F_RXCSUM | NETIF_F_GRO;
8701
8702 if (!BNXT_CHIP_TYPE_NITRO_A0(bp))
8703 dev->hw_features |= NETIF_F_LRO;
Michael Chanc0c050c2015-10-22 16:01:17 -04008704
Michael Chanc0c050c2015-10-22 16:01:17 -04008705 dev->hw_enc_features =
8706 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
8707 NETIF_F_TSO | NETIF_F_TSO6 |
8708 NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_GRE |
Alexander Duyck152971e2016-05-02 09:38:55 -07008709 NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_GSO_GRE_CSUM |
Tom Herbert7e133182016-05-18 09:06:10 -07008710 NETIF_F_GSO_IPXIP4 | NETIF_F_GSO_PARTIAL;
Alexander Duyck152971e2016-05-02 09:38:55 -07008711 dev->gso_partial_features = NETIF_F_GSO_UDP_TUNNEL_CSUM |
8712 NETIF_F_GSO_GRE_CSUM;
Michael Chanc0c050c2015-10-22 16:01:17 -04008713 dev->vlan_features = dev->hw_features | NETIF_F_HIGHDMA;
8714 dev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX |
8715 NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_STAG_TX;
Michael Chan1054aee2017-12-16 03:09:42 -05008716 if (!BNXT_CHIP_TYPE_NITRO_A0(bp))
8717 dev->hw_features |= NETIF_F_GRO_HW;
Michael Chanc0c050c2015-10-22 16:01:17 -04008718 dev->features |= dev->hw_features | NETIF_F_HIGHDMA;
Michael Chan1054aee2017-12-16 03:09:42 -05008719 if (dev->features & NETIF_F_GRO_HW)
8720 dev->features &= ~NETIF_F_LRO;
Michael Chanc0c050c2015-10-22 16:01:17 -04008721 dev->priv_flags |= IFF_UNICAST_FLT;
8722
8723#ifdef CONFIG_BNXT_SRIOV
8724 init_waitqueue_head(&bp->sriov_cfg_wait);
Sathya Perla4ab0c6a2017-07-24 12:34:27 -04008725 mutex_init(&bp->sriov_lock);
Michael Chanc0c050c2015-10-22 16:01:17 -04008726#endif
Michael Chan309369c2016-06-13 02:25:34 -04008727 bp->gro_func = bnxt_gro_func_5730x;
Michael Chan3284f9e2017-05-29 19:06:07 -04008728 if (BNXT_CHIP_P4_PLUS(bp))
Michael Chan94758f82016-06-13 02:25:35 -04008729 bp->gro_func = bnxt_gro_func_5731x;
Michael Chan434c9752017-05-29 19:06:08 -04008730 else
8731 bp->flags |= BNXT_FLAG_DOUBLE_DB;
Michael Chan309369c2016-06-13 02:25:34 -04008732
Michael Chanc0c050c2015-10-22 16:01:17 -04008733 rc = bnxt_hwrm_func_drv_rgtr(bp);
8734 if (rc)
Sathya Perla17086392017-02-20 19:25:18 -05008735 goto init_err_pci_clean;
Michael Chanc0c050c2015-10-22 16:01:17 -04008736
Michael Chana1653b12016-12-07 00:26:20 -05008737 rc = bnxt_hwrm_func_rgtr_async_events(bp, NULL, 0);
8738 if (rc)
Sathya Perla17086392017-02-20 19:25:18 -05008739 goto init_err_pci_clean;
Michael Chana1653b12016-12-07 00:26:20 -05008740
Michael Chana588e452016-12-07 00:26:21 -05008741 bp->ulp_probe = bnxt_ulp_probe;
8742
Michael Chanc0c050c2015-10-22 16:01:17 -04008743 /* Get the MAX capabilities for this function */
8744 rc = bnxt_hwrm_func_qcaps(bp);
8745 if (rc) {
8746 netdev_err(bp->dev, "hwrm query capability failure rc: %x\n",
8747 rc);
8748 rc = -1;
Sathya Perla17086392017-02-20 19:25:18 -05008749 goto init_err_pci_clean;
Michael Chanc0c050c2015-10-22 16:01:17 -04008750 }
Michael Chana22a6ac2017-08-23 19:34:05 -04008751 rc = bnxt_init_mac_addr(bp);
8752 if (rc) {
8753 dev_err(&pdev->dev, "Unable to initialize mac address.\n");
8754 rc = -EADDRNOTAVAIL;
8755 goto init_err_pci_clean;
8756 }
Michael Chanc0c050c2015-10-22 16:01:17 -04008757 rc = bnxt_hwrm_queue_qportcfg(bp);
8758 if (rc) {
8759 netdev_err(bp->dev, "hwrm query qportcfg failure rc: %x\n",
8760 rc);
8761 rc = -1;
Sathya Perla17086392017-02-20 19:25:18 -05008762 goto init_err_pci_clean;
Michael Chanc0c050c2015-10-22 16:01:17 -04008763 }
8764
Satish Baddipadige567b2ab2016-06-13 02:25:31 -04008765 bnxt_hwrm_func_qcfg(bp);
Michael Chan5ad2cbe2017-01-13 01:32:03 -05008766 bnxt_hwrm_port_led_qcaps(bp);
Michael Chaneb513652017-04-04 18:14:12 -04008767 bnxt_ethtool_init(bp);
Michael Chan87fe6032017-05-16 16:39:43 -04008768 bnxt_dcb_init(bp);
Satish Baddipadige567b2ab2016-06-13 02:25:31 -04008769
Michael Chan7eb9bb32017-10-26 11:51:25 -04008770 /* MTU range: 60 - FW defined max */
8771 dev->min_mtu = ETH_ZLEN;
8772 dev->max_mtu = bp->max_mtu;
8773
Michael Chand5430d32017-08-28 13:40:31 -04008774 rc = bnxt_probe_phy(bp);
8775 if (rc)
8776 goto init_err_pci_clean;
8777
Michael Chanc61fb992017-02-06 16:55:36 -05008778 bnxt_set_rx_skb_mode(bp, false);
Michael Chanc0c050c2015-10-22 16:01:17 -04008779 bnxt_set_tpa_flags(bp);
8780 bnxt_set_ring_params(bp);
Michael Chan33c26572016-12-07 00:26:15 -05008781 bnxt_set_max_func_irqs(bp, max_irqs);
Michael Chan702c2212017-05-29 19:06:10 -04008782 rc = bnxt_set_dflt_rings(bp, true);
Michael Chanbdbd1eb2016-12-29 12:13:43 -05008783 if (rc) {
8784 netdev_err(bp->dev, "Not enough rings available.\n");
8785 rc = -ENOMEM;
Sathya Perla17086392017-02-20 19:25:18 -05008786 goto init_err_pci_clean;
Michael Chanbdbd1eb2016-12-29 12:13:43 -05008787 }
Michael Chanc0c050c2015-10-22 16:01:17 -04008788
Michael Chan87da7f72016-11-16 21:13:09 -05008789 /* Default RSS hash cfg. */
8790 bp->rss_hash_cfg = VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4 |
8791 VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4 |
8792 VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6 |
8793 VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6;
Michael Chan3284f9e2017-05-29 19:06:07 -04008794 if (BNXT_CHIP_P4_PLUS(bp) && bp->hwrm_spec_code >= 0x10501) {
Michael Chan87da7f72016-11-16 21:13:09 -05008795 bp->flags |= BNXT_FLAG_UDP_RSS_CAP;
8796 bp->rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4 |
8797 VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6;
8798 }
8799
Michael Chan8fdefd62016-12-29 12:13:36 -05008800 bnxt_hwrm_vnic_qcaps(bp);
Michael Chan8079e8f2016-12-29 12:13:37 -05008801 if (bnxt_rfs_supported(bp)) {
Michael Chan2bcfa6f2015-12-27 18:19:24 -05008802 dev->hw_features |= NETIF_F_NTUPLE;
8803 if (bnxt_rfs_capable(bp)) {
8804 bp->flags |= BNXT_FLAG_RFS;
8805 dev->features |= NETIF_F_NTUPLE;
8806 }
8807 }
8808
Michael Chanc0c050c2015-10-22 16:01:17 -04008809 if (dev->hw_features & NETIF_F_HW_VLAN_CTAG_RX)
8810 bp->flags |= BNXT_FLAG_STRIP_VLAN;
8811
Michael Chan78095922016-12-07 00:26:16 -05008812 rc = bnxt_init_int_mode(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04008813 if (rc)
Sathya Perla17086392017-02-20 19:25:18 -05008814 goto init_err_pci_clean;
Michael Chanc0c050c2015-10-22 16:01:17 -04008815
Michael Chan832aed12018-03-09 23:46:07 -05008816 /* No TC has been set yet and rings may have been trimmed due to
8817 * limited MSIX, so we re-initialize the TX rings per TC.
8818 */
8819 bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
8820
Michael Chanc1ef1462017-04-04 18:14:07 -04008821 bnxt_get_wol_settings(bp);
Michael Chand196ece2017-04-04 18:14:08 -04008822 if (bp->flags & BNXT_FLAG_WOL_CAP)
8823 device_set_wakeup_enable(&pdev->dev, bp->wol);
8824 else
8825 device_set_wakeup_capable(&pdev->dev, false);
Michael Chanc1ef1462017-04-04 18:14:07 -04008826
Michael Chanc3480a62018-01-17 03:21:15 -05008827 bnxt_hwrm_set_cache_line_size(bp, cache_line_size());
8828
Michael Chanc213eae2017-10-13 21:09:29 -04008829 if (BNXT_PF(bp)) {
8830 if (!bnxt_pf_wq) {
8831 bnxt_pf_wq =
8832 create_singlethread_workqueue("bnxt_pf_wq");
8833 if (!bnxt_pf_wq) {
8834 dev_err(&pdev->dev, "Unable to create workqueue.\n");
8835 goto init_err_pci_clean;
8836 }
8837 }
Sathya Perla2ae74082017-08-28 13:40:33 -04008838 bnxt_init_tc(bp);
Michael Chanc213eae2017-10-13 21:09:29 -04008839 }
Sathya Perla2ae74082017-08-28 13:40:33 -04008840
Michael Chan78095922016-12-07 00:26:16 -05008841 rc = register_netdev(dev);
8842 if (rc)
Sathya Perla2ae74082017-08-28 13:40:33 -04008843 goto init_err_cleanup_tc;
Michael Chan78095922016-12-07 00:26:16 -05008844
Sathya Perla4ab0c6a2017-07-24 12:34:27 -04008845 if (BNXT_PF(bp))
8846 bnxt_dl_register(bp);
8847
Michael Chanc0c050c2015-10-22 16:01:17 -04008848 netdev_info(dev, "%s found at mem %lx, node addr %pM\n",
8849 board_info[ent->driver_data].name,
8850 (long)pci_resource_start(pdev, 0), dev->dev_addr);
8851
Ajit Khaparde90c4f782016-05-15 03:04:45 -04008852 bnxt_parse_log_pcie_link(bp);
8853
Michael Chanc0c050c2015-10-22 16:01:17 -04008854 return 0;
8855
Sathya Perla2ae74082017-08-28 13:40:33 -04008856init_err_cleanup_tc:
8857 bnxt_shutdown_tc(bp);
Michael Chan78095922016-12-07 00:26:16 -05008858 bnxt_clear_int_mode(bp);
8859
Sathya Perla17086392017-02-20 19:25:18 -05008860init_err_pci_clean:
8861 bnxt_cleanup_pci(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04008862
8863init_err_free:
8864 free_netdev(dev);
8865 return rc;
8866}
8867
Michael Chand196ece2017-04-04 18:14:08 -04008868static void bnxt_shutdown(struct pci_dev *pdev)
8869{
8870 struct net_device *dev = pci_get_drvdata(pdev);
8871 struct bnxt *bp;
8872
8873 if (!dev)
8874 return;
8875
8876 rtnl_lock();
8877 bp = netdev_priv(dev);
8878 if (!bp)
8879 goto shutdown_exit;
8880
8881 if (netif_running(dev))
8882 dev_close(dev);
8883
Ray Juia7f3f932017-12-01 03:13:02 -05008884 bnxt_ulp_shutdown(bp);
8885
Michael Chand196ece2017-04-04 18:14:08 -04008886 if (system_state == SYSTEM_POWER_OFF) {
8887 bnxt_clear_int_mode(bp);
8888 pci_wake_from_d3(pdev, bp->wol);
8889 pci_set_power_state(pdev, PCI_D3hot);
8890 }
8891
8892shutdown_exit:
8893 rtnl_unlock();
8894}
8895
Michael Chanf65a2042017-04-04 18:14:11 -04008896#ifdef CONFIG_PM_SLEEP
8897static int bnxt_suspend(struct device *device)
8898{
8899 struct pci_dev *pdev = to_pci_dev(device);
8900 struct net_device *dev = pci_get_drvdata(pdev);
8901 struct bnxt *bp = netdev_priv(dev);
8902 int rc = 0;
8903
8904 rtnl_lock();
8905 if (netif_running(dev)) {
8906 netif_device_detach(dev);
8907 rc = bnxt_close(dev);
8908 }
8909 bnxt_hwrm_func_drv_unrgtr(bp);
8910 rtnl_unlock();
8911 return rc;
8912}
8913
8914static int bnxt_resume(struct device *device)
8915{
8916 struct pci_dev *pdev = to_pci_dev(device);
8917 struct net_device *dev = pci_get_drvdata(pdev);
8918 struct bnxt *bp = netdev_priv(dev);
8919 int rc = 0;
8920
8921 rtnl_lock();
8922 if (bnxt_hwrm_ver_get(bp) || bnxt_hwrm_func_drv_rgtr(bp)) {
8923 rc = -ENODEV;
8924 goto resume_exit;
8925 }
8926 rc = bnxt_hwrm_func_reset(bp);
8927 if (rc) {
8928 rc = -EBUSY;
8929 goto resume_exit;
8930 }
8931 bnxt_get_wol_settings(bp);
8932 if (netif_running(dev)) {
8933 rc = bnxt_open(dev);
8934 if (!rc)
8935 netif_device_attach(dev);
8936 }
8937
8938resume_exit:
8939 rtnl_unlock();
8940 return rc;
8941}
8942
8943static SIMPLE_DEV_PM_OPS(bnxt_pm_ops, bnxt_suspend, bnxt_resume);
8944#define BNXT_PM_OPS (&bnxt_pm_ops)
8945
8946#else
8947
8948#define BNXT_PM_OPS NULL
8949
8950#endif /* CONFIG_PM_SLEEP */
8951
Satish Baddipadige6316ea62016-03-07 15:38:48 -05008952/**
8953 * bnxt_io_error_detected - called when PCI error is detected
8954 * @pdev: Pointer to PCI device
8955 * @state: The current pci connection state
8956 *
8957 * This function is called after a PCI bus error affecting
8958 * this device has been detected.
8959 */
8960static pci_ers_result_t bnxt_io_error_detected(struct pci_dev *pdev,
8961 pci_channel_state_t state)
8962{
8963 struct net_device *netdev = pci_get_drvdata(pdev);
Michael Chana588e452016-12-07 00:26:21 -05008964 struct bnxt *bp = netdev_priv(netdev);
Satish Baddipadige6316ea62016-03-07 15:38:48 -05008965
8966 netdev_info(netdev, "PCI I/O error detected\n");
8967
8968 rtnl_lock();
8969 netif_device_detach(netdev);
8970
Michael Chana588e452016-12-07 00:26:21 -05008971 bnxt_ulp_stop(bp);
8972
Satish Baddipadige6316ea62016-03-07 15:38:48 -05008973 if (state == pci_channel_io_perm_failure) {
8974 rtnl_unlock();
8975 return PCI_ERS_RESULT_DISCONNECT;
8976 }
8977
8978 if (netif_running(netdev))
8979 bnxt_close(netdev);
8980
8981 pci_disable_device(pdev);
8982 rtnl_unlock();
8983
8984 /* Request a slot slot reset. */
8985 return PCI_ERS_RESULT_NEED_RESET;
8986}
8987
8988/**
8989 * bnxt_io_slot_reset - called after the pci bus has been reset.
8990 * @pdev: Pointer to PCI device
8991 *
8992 * Restart the card from scratch, as if from a cold-boot.
8993 * At this point, the card has exprienced a hard reset,
8994 * followed by fixups by BIOS, and has its config space
8995 * set up identically to what it was at cold boot.
8996 */
8997static pci_ers_result_t bnxt_io_slot_reset(struct pci_dev *pdev)
8998{
8999 struct net_device *netdev = pci_get_drvdata(pdev);
9000 struct bnxt *bp = netdev_priv(netdev);
9001 int err = 0;
9002 pci_ers_result_t result = PCI_ERS_RESULT_DISCONNECT;
9003
9004 netdev_info(bp->dev, "PCI Slot Reset\n");
9005
9006 rtnl_lock();
9007
9008 if (pci_enable_device(pdev)) {
9009 dev_err(&pdev->dev,
9010 "Cannot re-enable PCI device after reset.\n");
9011 } else {
9012 pci_set_master(pdev);
9013
Michael Chanaa8ed022016-12-07 00:26:17 -05009014 err = bnxt_hwrm_func_reset(bp);
9015 if (!err && netif_running(netdev))
Satish Baddipadige6316ea62016-03-07 15:38:48 -05009016 err = bnxt_open(netdev);
9017
Michael Chana588e452016-12-07 00:26:21 -05009018 if (!err) {
Satish Baddipadige6316ea62016-03-07 15:38:48 -05009019 result = PCI_ERS_RESULT_RECOVERED;
Michael Chana588e452016-12-07 00:26:21 -05009020 bnxt_ulp_start(bp);
9021 }
Satish Baddipadige6316ea62016-03-07 15:38:48 -05009022 }
9023
9024 if (result != PCI_ERS_RESULT_RECOVERED && netif_running(netdev))
9025 dev_close(netdev);
9026
9027 rtnl_unlock();
9028
9029 err = pci_cleanup_aer_uncorrect_error_status(pdev);
9030 if (err) {
9031 dev_err(&pdev->dev,
9032 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
9033 err); /* non-fatal, continue */
9034 }
9035
9036 return PCI_ERS_RESULT_RECOVERED;
9037}
9038
9039/**
9040 * bnxt_io_resume - called when traffic can start flowing again.
9041 * @pdev: Pointer to PCI device
9042 *
9043 * This callback is called when the error recovery driver tells
9044 * us that its OK to resume normal operation.
9045 */
9046static void bnxt_io_resume(struct pci_dev *pdev)
9047{
9048 struct net_device *netdev = pci_get_drvdata(pdev);
9049
9050 rtnl_lock();
9051
9052 netif_device_attach(netdev);
9053
9054 rtnl_unlock();
9055}
9056
9057static const struct pci_error_handlers bnxt_err_handler = {
9058 .error_detected = bnxt_io_error_detected,
9059 .slot_reset = bnxt_io_slot_reset,
9060 .resume = bnxt_io_resume
9061};
9062
Michael Chanc0c050c2015-10-22 16:01:17 -04009063static struct pci_driver bnxt_pci_driver = {
9064 .name = DRV_MODULE_NAME,
9065 .id_table = bnxt_pci_tbl,
9066 .probe = bnxt_init_one,
9067 .remove = bnxt_remove_one,
Michael Chand196ece2017-04-04 18:14:08 -04009068 .shutdown = bnxt_shutdown,
Michael Chanf65a2042017-04-04 18:14:11 -04009069 .driver.pm = BNXT_PM_OPS,
Satish Baddipadige6316ea62016-03-07 15:38:48 -05009070 .err_handler = &bnxt_err_handler,
Michael Chanc0c050c2015-10-22 16:01:17 -04009071#if defined(CONFIG_BNXT_SRIOV)
9072 .sriov_configure = bnxt_sriov_configure,
9073#endif
9074};
9075
Michael Chanc213eae2017-10-13 21:09:29 -04009076static int __init bnxt_init(void)
9077{
9078 return pci_register_driver(&bnxt_pci_driver);
9079}
9080
9081static void __exit bnxt_exit(void)
9082{
9083 pci_unregister_driver(&bnxt_pci_driver);
9084 if (bnxt_pf_wq)
9085 destroy_workqueue(bnxt_pf_wq);
9086}
9087
9088module_init(bnxt_init);
9089module_exit(bnxt_exit);