blob: a221a10c4c29502c1df7336896866c429cc40206 [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;
Michael Chan2e8ef772018-04-26 17:44:31 -04002386 u8 qidx;
Michael Chanc0c050c2015-10-22 16:01:17 -04002387
Michael Chanc0c050c2015-10-22 16:01:17 -04002388 ring = &txr->tx_ring_struct;
2389
2390 rc = bnxt_alloc_ring(bp, ring);
2391 if (rc)
2392 return rc;
2393
Michael Chan9899bb52018-03-31 13:54:16 -04002394 ring->grp_idx = txr->bnapi->index;
Michael Chanc0c050c2015-10-22 16:01:17 -04002395 if (bp->tx_push_size) {
Michael Chanc0c050c2015-10-22 16:01:17 -04002396 dma_addr_t mapping;
2397
2398 /* One pre-allocated DMA buffer to backup
2399 * TX push operation
2400 */
2401 txr->tx_push = dma_alloc_coherent(&pdev->dev,
2402 bp->tx_push_size,
2403 &txr->tx_push_mapping,
2404 GFP_KERNEL);
2405
2406 if (!txr->tx_push)
2407 return -ENOMEM;
2408
Michael Chanc0c050c2015-10-22 16:01:17 -04002409 mapping = txr->tx_push_mapping +
2410 sizeof(struct tx_push_bd);
Michael Chan4419dbe2016-02-10 17:33:49 -05002411 txr->data_mapping = cpu_to_le64(mapping);
Michael Chanc0c050c2015-10-22 16:01:17 -04002412
Michael Chan4419dbe2016-02-10 17:33:49 -05002413 memset(txr->tx_push, 0, sizeof(struct tx_push_bd));
Michael Chanc0c050c2015-10-22 16:01:17 -04002414 }
Michael Chan2e8ef772018-04-26 17:44:31 -04002415 qidx = bp->tc_to_qidx[j];
2416 ring->queue_id = bp->q_info[qidx].queue_id;
Michael Chan5f449242017-02-06 16:55:40 -05002417 if (i < bp->tx_nr_rings_xdp)
2418 continue;
Michael Chanc0c050c2015-10-22 16:01:17 -04002419 if (i % bp->tx_nr_rings_per_tc == (bp->tx_nr_rings_per_tc - 1))
2420 j++;
2421 }
2422 return 0;
2423}
2424
2425static void bnxt_free_cp_rings(struct bnxt *bp)
2426{
2427 int i;
2428
2429 if (!bp->bnapi)
2430 return;
2431
2432 for (i = 0; i < bp->cp_nr_rings; i++) {
2433 struct bnxt_napi *bnapi = bp->bnapi[i];
2434 struct bnxt_cp_ring_info *cpr;
2435 struct bnxt_ring_struct *ring;
2436
2437 if (!bnapi)
2438 continue;
2439
2440 cpr = &bnapi->cp_ring;
2441 ring = &cpr->cp_ring_struct;
2442
2443 bnxt_free_ring(bp, ring);
2444 }
2445}
2446
2447static int bnxt_alloc_cp_rings(struct bnxt *bp)
2448{
Michael Chane5811b82018-03-31 13:54:18 -04002449 int i, rc, ulp_base_vec, ulp_msix;
Michael Chanc0c050c2015-10-22 16:01:17 -04002450
Michael Chane5811b82018-03-31 13:54:18 -04002451 ulp_msix = bnxt_get_ulp_msix_num(bp);
2452 ulp_base_vec = bnxt_get_ulp_msix_base(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04002453 for (i = 0; i < bp->cp_nr_rings; i++) {
2454 struct bnxt_napi *bnapi = bp->bnapi[i];
2455 struct bnxt_cp_ring_info *cpr;
2456 struct bnxt_ring_struct *ring;
2457
2458 if (!bnapi)
2459 continue;
2460
2461 cpr = &bnapi->cp_ring;
2462 ring = &cpr->cp_ring_struct;
2463
2464 rc = bnxt_alloc_ring(bp, ring);
2465 if (rc)
2466 return rc;
Michael Chane5811b82018-03-31 13:54:18 -04002467
2468 if (ulp_msix && i >= ulp_base_vec)
2469 ring->map_idx = i + ulp_msix;
2470 else
2471 ring->map_idx = i;
Michael Chanc0c050c2015-10-22 16:01:17 -04002472 }
2473 return 0;
2474}
2475
2476static void bnxt_init_ring_struct(struct bnxt *bp)
2477{
2478 int i;
2479
2480 for (i = 0; i < bp->cp_nr_rings; i++) {
2481 struct bnxt_napi *bnapi = bp->bnapi[i];
2482 struct bnxt_cp_ring_info *cpr;
2483 struct bnxt_rx_ring_info *rxr;
2484 struct bnxt_tx_ring_info *txr;
2485 struct bnxt_ring_struct *ring;
2486
2487 if (!bnapi)
2488 continue;
2489
2490 cpr = &bnapi->cp_ring;
2491 ring = &cpr->cp_ring_struct;
2492 ring->nr_pages = bp->cp_nr_pages;
2493 ring->page_size = HW_CMPD_RING_SIZE;
2494 ring->pg_arr = (void **)cpr->cp_desc_ring;
2495 ring->dma_arr = cpr->cp_desc_mapping;
2496 ring->vmem_size = 0;
2497
Michael Chanb6ab4b02016-01-02 23:44:59 -05002498 rxr = bnapi->rx_ring;
Michael Chan3b2b7d92016-01-02 23:45:00 -05002499 if (!rxr)
2500 goto skip_rx;
2501
Michael Chanc0c050c2015-10-22 16:01:17 -04002502 ring = &rxr->rx_ring_struct;
2503 ring->nr_pages = bp->rx_nr_pages;
2504 ring->page_size = HW_RXBD_RING_SIZE;
2505 ring->pg_arr = (void **)rxr->rx_desc_ring;
2506 ring->dma_arr = rxr->rx_desc_mapping;
2507 ring->vmem_size = SW_RXBD_RING_SIZE * bp->rx_nr_pages;
2508 ring->vmem = (void **)&rxr->rx_buf_ring;
2509
2510 ring = &rxr->rx_agg_ring_struct;
2511 ring->nr_pages = bp->rx_agg_nr_pages;
2512 ring->page_size = HW_RXBD_RING_SIZE;
2513 ring->pg_arr = (void **)rxr->rx_agg_desc_ring;
2514 ring->dma_arr = rxr->rx_agg_desc_mapping;
2515 ring->vmem_size = SW_RXBD_AGG_RING_SIZE * bp->rx_agg_nr_pages;
2516 ring->vmem = (void **)&rxr->rx_agg_ring;
2517
Michael Chan3b2b7d92016-01-02 23:45:00 -05002518skip_rx:
Michael Chanb6ab4b02016-01-02 23:44:59 -05002519 txr = bnapi->tx_ring;
Michael Chan3b2b7d92016-01-02 23:45:00 -05002520 if (!txr)
2521 continue;
2522
Michael Chanc0c050c2015-10-22 16:01:17 -04002523 ring = &txr->tx_ring_struct;
2524 ring->nr_pages = bp->tx_nr_pages;
2525 ring->page_size = HW_RXBD_RING_SIZE;
2526 ring->pg_arr = (void **)txr->tx_desc_ring;
2527 ring->dma_arr = txr->tx_desc_mapping;
2528 ring->vmem_size = SW_TXBD_RING_SIZE * bp->tx_nr_pages;
2529 ring->vmem = (void **)&txr->tx_buf_ring;
2530 }
2531}
2532
2533static void bnxt_init_rxbd_pages(struct bnxt_ring_struct *ring, u32 type)
2534{
2535 int i;
2536 u32 prod;
2537 struct rx_bd **rx_buf_ring;
2538
2539 rx_buf_ring = (struct rx_bd **)ring->pg_arr;
2540 for (i = 0, prod = 0; i < ring->nr_pages; i++) {
2541 int j;
2542 struct rx_bd *rxbd;
2543
2544 rxbd = rx_buf_ring[i];
2545 if (!rxbd)
2546 continue;
2547
2548 for (j = 0; j < RX_DESC_CNT; j++, rxbd++, prod++) {
2549 rxbd->rx_bd_len_flags_type = cpu_to_le32(type);
2550 rxbd->rx_bd_opaque = prod;
2551 }
2552 }
2553}
2554
2555static int bnxt_init_one_rx_ring(struct bnxt *bp, int ring_nr)
2556{
2557 struct net_device *dev = bp->dev;
Michael Chanc0c050c2015-10-22 16:01:17 -04002558 struct bnxt_rx_ring_info *rxr;
2559 struct bnxt_ring_struct *ring;
2560 u32 prod, type;
2561 int i;
2562
Michael Chanc0c050c2015-10-22 16:01:17 -04002563 type = (bp->rx_buf_use_size << RX_BD_LEN_SHIFT) |
2564 RX_BD_TYPE_RX_PACKET_BD | RX_BD_FLAGS_EOP;
2565
2566 if (NET_IP_ALIGN == 2)
2567 type |= RX_BD_FLAGS_SOP;
2568
Michael Chanb6ab4b02016-01-02 23:44:59 -05002569 rxr = &bp->rx_ring[ring_nr];
Michael Chanc0c050c2015-10-22 16:01:17 -04002570 ring = &rxr->rx_ring_struct;
2571 bnxt_init_rxbd_pages(ring, type);
2572
Michael Chanc6d30e82017-02-06 16:55:42 -05002573 if (BNXT_RX_PAGE_MODE(bp) && bp->xdp_prog) {
2574 rxr->xdp_prog = bpf_prog_add(bp->xdp_prog, 1);
2575 if (IS_ERR(rxr->xdp_prog)) {
2576 int rc = PTR_ERR(rxr->xdp_prog);
2577
2578 rxr->xdp_prog = NULL;
2579 return rc;
2580 }
2581 }
Michael Chanc0c050c2015-10-22 16:01:17 -04002582 prod = rxr->rx_prod;
2583 for (i = 0; i < bp->rx_ring_size; i++) {
2584 if (bnxt_alloc_rx_data(bp, rxr, prod, GFP_KERNEL) != 0) {
2585 netdev_warn(dev, "init'ed rx ring %d with %d/%d skbs only\n",
2586 ring_nr, i, bp->rx_ring_size);
2587 break;
2588 }
2589 prod = NEXT_RX(prod);
2590 }
2591 rxr->rx_prod = prod;
2592 ring->fw_ring_id = INVALID_HW_RING_ID;
2593
Michael Chanedd0c2c2015-12-27 18:19:19 -05002594 ring = &rxr->rx_agg_ring_struct;
2595 ring->fw_ring_id = INVALID_HW_RING_ID;
2596
Michael Chanc0c050c2015-10-22 16:01:17 -04002597 if (!(bp->flags & BNXT_FLAG_AGG_RINGS))
2598 return 0;
2599
Michael Chan2839f282016-04-25 02:30:50 -04002600 type = ((u32)BNXT_RX_PAGE_SIZE << RX_BD_LEN_SHIFT) |
Michael Chanc0c050c2015-10-22 16:01:17 -04002601 RX_BD_TYPE_RX_AGG_BD | RX_BD_FLAGS_SOP;
2602
2603 bnxt_init_rxbd_pages(ring, type);
2604
2605 prod = rxr->rx_agg_prod;
2606 for (i = 0; i < bp->rx_agg_ring_size; i++) {
2607 if (bnxt_alloc_rx_page(bp, rxr, prod, GFP_KERNEL) != 0) {
2608 netdev_warn(dev, "init'ed rx ring %d with %d/%d pages only\n",
2609 ring_nr, i, bp->rx_ring_size);
2610 break;
2611 }
2612 prod = NEXT_RX_AGG(prod);
2613 }
2614 rxr->rx_agg_prod = prod;
Michael Chanc0c050c2015-10-22 16:01:17 -04002615
2616 if (bp->flags & BNXT_FLAG_TPA) {
2617 if (rxr->rx_tpa) {
2618 u8 *data;
2619 dma_addr_t mapping;
2620
2621 for (i = 0; i < MAX_TPA; i++) {
2622 data = __bnxt_alloc_rx_data(bp, &mapping,
2623 GFP_KERNEL);
2624 if (!data)
2625 return -ENOMEM;
2626
2627 rxr->rx_tpa[i].data = data;
Michael Chanb3dba772017-02-06 16:55:35 -05002628 rxr->rx_tpa[i].data_ptr = data + bp->rx_offset;
Michael Chanc0c050c2015-10-22 16:01:17 -04002629 rxr->rx_tpa[i].mapping = mapping;
2630 }
2631 } else {
2632 netdev_err(bp->dev, "No resource allocated for LRO/GRO\n");
2633 return -ENOMEM;
2634 }
2635 }
2636
2637 return 0;
2638}
2639
Sankar Patchineelam22479252017-03-28 19:47:29 -04002640static void bnxt_init_cp_rings(struct bnxt *bp)
2641{
2642 int i;
2643
2644 for (i = 0; i < bp->cp_nr_rings; i++) {
2645 struct bnxt_cp_ring_info *cpr = &bp->bnapi[i]->cp_ring;
2646 struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
2647
2648 ring->fw_ring_id = INVALID_HW_RING_ID;
Andy Gospodarek6a8788f2018-01-09 16:06:20 -05002649 cpr->rx_ring_coal.coal_ticks = bp->rx_coal.coal_ticks;
2650 cpr->rx_ring_coal.coal_bufs = bp->rx_coal.coal_bufs;
Sankar Patchineelam22479252017-03-28 19:47:29 -04002651 }
2652}
2653
Michael Chanc0c050c2015-10-22 16:01:17 -04002654static int bnxt_init_rx_rings(struct bnxt *bp)
2655{
2656 int i, rc = 0;
2657
Michael Chanc61fb992017-02-06 16:55:36 -05002658 if (BNXT_RX_PAGE_MODE(bp)) {
Michael Chanc6d30e82017-02-06 16:55:42 -05002659 bp->rx_offset = NET_IP_ALIGN + XDP_PACKET_HEADROOM;
2660 bp->rx_dma_offset = XDP_PACKET_HEADROOM;
Michael Chanc61fb992017-02-06 16:55:36 -05002661 } else {
2662 bp->rx_offset = BNXT_RX_OFFSET;
2663 bp->rx_dma_offset = BNXT_RX_DMA_OFFSET;
2664 }
Michael Chanb3dba772017-02-06 16:55:35 -05002665
Michael Chanc0c050c2015-10-22 16:01:17 -04002666 for (i = 0; i < bp->rx_nr_rings; i++) {
2667 rc = bnxt_init_one_rx_ring(bp, i);
2668 if (rc)
2669 break;
2670 }
2671
2672 return rc;
2673}
2674
2675static int bnxt_init_tx_rings(struct bnxt *bp)
2676{
2677 u16 i;
2678
2679 bp->tx_wake_thresh = max_t(int, bp->tx_ring_size / 2,
2680 MAX_SKB_FRAGS + 1);
2681
2682 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05002683 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04002684 struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
2685
2686 ring->fw_ring_id = INVALID_HW_RING_ID;
2687 }
2688
2689 return 0;
2690}
2691
2692static void bnxt_free_ring_grps(struct bnxt *bp)
2693{
2694 kfree(bp->grp_info);
2695 bp->grp_info = NULL;
2696}
2697
2698static int bnxt_init_ring_grps(struct bnxt *bp, bool irq_re_init)
2699{
2700 int i;
2701
2702 if (irq_re_init) {
2703 bp->grp_info = kcalloc(bp->cp_nr_rings,
2704 sizeof(struct bnxt_ring_grp_info),
2705 GFP_KERNEL);
2706 if (!bp->grp_info)
2707 return -ENOMEM;
2708 }
2709 for (i = 0; i < bp->cp_nr_rings; i++) {
2710 if (irq_re_init)
2711 bp->grp_info[i].fw_stats_ctx = INVALID_HW_RING_ID;
2712 bp->grp_info[i].fw_grp_id = INVALID_HW_RING_ID;
2713 bp->grp_info[i].rx_fw_ring_id = INVALID_HW_RING_ID;
2714 bp->grp_info[i].agg_fw_ring_id = INVALID_HW_RING_ID;
2715 bp->grp_info[i].cp_fw_ring_id = INVALID_HW_RING_ID;
2716 }
2717 return 0;
2718}
2719
2720static void bnxt_free_vnics(struct bnxt *bp)
2721{
2722 kfree(bp->vnic_info);
2723 bp->vnic_info = NULL;
2724 bp->nr_vnics = 0;
2725}
2726
2727static int bnxt_alloc_vnics(struct bnxt *bp)
2728{
2729 int num_vnics = 1;
2730
2731#ifdef CONFIG_RFS_ACCEL
2732 if (bp->flags & BNXT_FLAG_RFS)
2733 num_vnics += bp->rx_nr_rings;
2734#endif
2735
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04002736 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
2737 num_vnics++;
2738
Michael Chanc0c050c2015-10-22 16:01:17 -04002739 bp->vnic_info = kcalloc(num_vnics, sizeof(struct bnxt_vnic_info),
2740 GFP_KERNEL);
2741 if (!bp->vnic_info)
2742 return -ENOMEM;
2743
2744 bp->nr_vnics = num_vnics;
2745 return 0;
2746}
2747
2748static void bnxt_init_vnics(struct bnxt *bp)
2749{
2750 int i;
2751
2752 for (i = 0; i < bp->nr_vnics; i++) {
2753 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
2754
2755 vnic->fw_vnic_id = INVALID_HW_RING_ID;
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04002756 vnic->fw_rss_cos_lb_ctx[0] = INVALID_HW_RING_ID;
2757 vnic->fw_rss_cos_lb_ctx[1] = INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04002758 vnic->fw_l2_ctx_id = INVALID_HW_RING_ID;
2759
2760 if (bp->vnic_info[i].rss_hash_key) {
2761 if (i == 0)
2762 prandom_bytes(vnic->rss_hash_key,
2763 HW_HASH_KEY_SIZE);
2764 else
2765 memcpy(vnic->rss_hash_key,
2766 bp->vnic_info[0].rss_hash_key,
2767 HW_HASH_KEY_SIZE);
2768 }
2769 }
2770}
2771
2772static int bnxt_calc_nr_ring_pages(u32 ring_size, int desc_per_pg)
2773{
2774 int pages;
2775
2776 pages = ring_size / desc_per_pg;
2777
2778 if (!pages)
2779 return 1;
2780
2781 pages++;
2782
2783 while (pages & (pages - 1))
2784 pages++;
2785
2786 return pages;
2787}
2788
Michael Chanc6d30e82017-02-06 16:55:42 -05002789void bnxt_set_tpa_flags(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04002790{
2791 bp->flags &= ~BNXT_FLAG_TPA;
Michael Chan341138c2017-01-13 01:32:01 -05002792 if (bp->flags & BNXT_FLAG_NO_AGG_RINGS)
2793 return;
Michael Chanc0c050c2015-10-22 16:01:17 -04002794 if (bp->dev->features & NETIF_F_LRO)
2795 bp->flags |= BNXT_FLAG_LRO;
Michael Chan1054aee2017-12-16 03:09:42 -05002796 else if (bp->dev->features & NETIF_F_GRO_HW)
Michael Chanc0c050c2015-10-22 16:01:17 -04002797 bp->flags |= BNXT_FLAG_GRO;
2798}
2799
2800/* bp->rx_ring_size, bp->tx_ring_size, dev->mtu, BNXT_FLAG_{G|L}RO flags must
2801 * be set on entry.
2802 */
2803void bnxt_set_ring_params(struct bnxt *bp)
2804{
2805 u32 ring_size, rx_size, rx_space;
2806 u32 agg_factor = 0, agg_ring_size = 0;
2807
2808 /* 8 for CRC and VLAN */
2809 rx_size = SKB_DATA_ALIGN(bp->dev->mtu + ETH_HLEN + NET_IP_ALIGN + 8);
2810
2811 rx_space = rx_size + NET_SKB_PAD +
2812 SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
2813
2814 bp->rx_copy_thresh = BNXT_RX_COPY_THRESH;
2815 ring_size = bp->rx_ring_size;
2816 bp->rx_agg_ring_size = 0;
2817 bp->rx_agg_nr_pages = 0;
2818
2819 if (bp->flags & BNXT_FLAG_TPA)
Michael Chan2839f282016-04-25 02:30:50 -04002820 agg_factor = min_t(u32, 4, 65536 / BNXT_RX_PAGE_SIZE);
Michael Chanc0c050c2015-10-22 16:01:17 -04002821
2822 bp->flags &= ~BNXT_FLAG_JUMBO;
Michael Chanbdbd1eb2016-12-29 12:13:43 -05002823 if (rx_space > PAGE_SIZE && !(bp->flags & BNXT_FLAG_NO_AGG_RINGS)) {
Michael Chanc0c050c2015-10-22 16:01:17 -04002824 u32 jumbo_factor;
2825
2826 bp->flags |= BNXT_FLAG_JUMBO;
2827 jumbo_factor = PAGE_ALIGN(bp->dev->mtu - 40) >> PAGE_SHIFT;
2828 if (jumbo_factor > agg_factor)
2829 agg_factor = jumbo_factor;
2830 }
2831 agg_ring_size = ring_size * agg_factor;
2832
2833 if (agg_ring_size) {
2834 bp->rx_agg_nr_pages = bnxt_calc_nr_ring_pages(agg_ring_size,
2835 RX_DESC_CNT);
2836 if (bp->rx_agg_nr_pages > MAX_RX_AGG_PAGES) {
2837 u32 tmp = agg_ring_size;
2838
2839 bp->rx_agg_nr_pages = MAX_RX_AGG_PAGES;
2840 agg_ring_size = MAX_RX_AGG_PAGES * RX_DESC_CNT - 1;
2841 netdev_warn(bp->dev, "rx agg ring size %d reduced to %d.\n",
2842 tmp, agg_ring_size);
2843 }
2844 bp->rx_agg_ring_size = agg_ring_size;
2845 bp->rx_agg_ring_mask = (bp->rx_agg_nr_pages * RX_DESC_CNT) - 1;
2846 rx_size = SKB_DATA_ALIGN(BNXT_RX_COPY_THRESH + NET_IP_ALIGN);
2847 rx_space = rx_size + NET_SKB_PAD +
2848 SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
2849 }
2850
2851 bp->rx_buf_use_size = rx_size;
2852 bp->rx_buf_size = rx_space;
2853
2854 bp->rx_nr_pages = bnxt_calc_nr_ring_pages(ring_size, RX_DESC_CNT);
2855 bp->rx_ring_mask = (bp->rx_nr_pages * RX_DESC_CNT) - 1;
2856
2857 ring_size = bp->tx_ring_size;
2858 bp->tx_nr_pages = bnxt_calc_nr_ring_pages(ring_size, TX_DESC_CNT);
2859 bp->tx_ring_mask = (bp->tx_nr_pages * TX_DESC_CNT) - 1;
2860
2861 ring_size = bp->rx_ring_size * (2 + agg_factor) + bp->tx_ring_size;
2862 bp->cp_ring_size = ring_size;
2863
2864 bp->cp_nr_pages = bnxt_calc_nr_ring_pages(ring_size, CP_DESC_CNT);
2865 if (bp->cp_nr_pages > MAX_CP_PAGES) {
2866 bp->cp_nr_pages = MAX_CP_PAGES;
2867 bp->cp_ring_size = MAX_CP_PAGES * CP_DESC_CNT - 1;
2868 netdev_warn(bp->dev, "completion ring size %d reduced to %d.\n",
2869 ring_size, bp->cp_ring_size);
2870 }
2871 bp->cp_bit = bp->cp_nr_pages * CP_DESC_CNT;
2872 bp->cp_ring_mask = bp->cp_bit - 1;
2873}
2874
Jesper Dangaard Brouer96a86042018-01-03 11:25:44 +01002875/* Changing allocation mode of RX rings.
2876 * TODO: Update when extending xdp_rxq_info to support allocation modes.
2877 */
Michael Chanc61fb992017-02-06 16:55:36 -05002878int bnxt_set_rx_skb_mode(struct bnxt *bp, bool page_mode)
Michael Chan6bb19472017-02-06 16:55:32 -05002879{
Michael Chanc61fb992017-02-06 16:55:36 -05002880 if (page_mode) {
2881 if (bp->dev->mtu > BNXT_MAX_PAGE_MODE_MTU)
2882 return -EOPNOTSUPP;
Michael Chan7eb9bb32017-10-26 11:51:25 -04002883 bp->dev->max_mtu =
2884 min_t(u16, bp->max_mtu, BNXT_MAX_PAGE_MODE_MTU);
Michael Chanc61fb992017-02-06 16:55:36 -05002885 bp->flags &= ~BNXT_FLAG_AGG_RINGS;
2886 bp->flags |= BNXT_FLAG_NO_AGG_RINGS | BNXT_FLAG_RX_PAGE_MODE;
Michael Chanc61fb992017-02-06 16:55:36 -05002887 bp->rx_dir = DMA_BIDIRECTIONAL;
2888 bp->rx_skb_func = bnxt_rx_page_skb;
Michael Chan1054aee2017-12-16 03:09:42 -05002889 /* Disable LRO or GRO_HW */
2890 netdev_update_features(bp->dev);
Michael Chanc61fb992017-02-06 16:55:36 -05002891 } else {
Michael Chan7eb9bb32017-10-26 11:51:25 -04002892 bp->dev->max_mtu = bp->max_mtu;
Michael Chanc61fb992017-02-06 16:55:36 -05002893 bp->flags &= ~BNXT_FLAG_RX_PAGE_MODE;
2894 bp->rx_dir = DMA_FROM_DEVICE;
2895 bp->rx_skb_func = bnxt_rx_skb;
2896 }
Michael Chan6bb19472017-02-06 16:55:32 -05002897 return 0;
2898}
2899
Michael Chanc0c050c2015-10-22 16:01:17 -04002900static void bnxt_free_vnic_attributes(struct bnxt *bp)
2901{
2902 int i;
2903 struct bnxt_vnic_info *vnic;
2904 struct pci_dev *pdev = bp->pdev;
2905
2906 if (!bp->vnic_info)
2907 return;
2908
2909 for (i = 0; i < bp->nr_vnics; i++) {
2910 vnic = &bp->vnic_info[i];
2911
2912 kfree(vnic->fw_grp_ids);
2913 vnic->fw_grp_ids = NULL;
2914
2915 kfree(vnic->uc_list);
2916 vnic->uc_list = NULL;
2917
2918 if (vnic->mc_list) {
2919 dma_free_coherent(&pdev->dev, vnic->mc_list_size,
2920 vnic->mc_list, vnic->mc_list_mapping);
2921 vnic->mc_list = NULL;
2922 }
2923
2924 if (vnic->rss_table) {
2925 dma_free_coherent(&pdev->dev, PAGE_SIZE,
2926 vnic->rss_table,
2927 vnic->rss_table_dma_addr);
2928 vnic->rss_table = NULL;
2929 }
2930
2931 vnic->rss_hash_key = NULL;
2932 vnic->flags = 0;
2933 }
2934}
2935
2936static int bnxt_alloc_vnic_attributes(struct bnxt *bp)
2937{
2938 int i, rc = 0, size;
2939 struct bnxt_vnic_info *vnic;
2940 struct pci_dev *pdev = bp->pdev;
2941 int max_rings;
2942
2943 for (i = 0; i < bp->nr_vnics; i++) {
2944 vnic = &bp->vnic_info[i];
2945
2946 if (vnic->flags & BNXT_VNIC_UCAST_FLAG) {
2947 int mem_size = (BNXT_MAX_UC_ADDRS - 1) * ETH_ALEN;
2948
2949 if (mem_size > 0) {
2950 vnic->uc_list = kmalloc(mem_size, GFP_KERNEL);
2951 if (!vnic->uc_list) {
2952 rc = -ENOMEM;
2953 goto out;
2954 }
2955 }
2956 }
2957
2958 if (vnic->flags & BNXT_VNIC_MCAST_FLAG) {
2959 vnic->mc_list_size = BNXT_MAX_MC_ADDRS * ETH_ALEN;
2960 vnic->mc_list =
2961 dma_alloc_coherent(&pdev->dev,
2962 vnic->mc_list_size,
2963 &vnic->mc_list_mapping,
2964 GFP_KERNEL);
2965 if (!vnic->mc_list) {
2966 rc = -ENOMEM;
2967 goto out;
2968 }
2969 }
2970
2971 if (vnic->flags & BNXT_VNIC_RSS_FLAG)
2972 max_rings = bp->rx_nr_rings;
2973 else
2974 max_rings = 1;
2975
2976 vnic->fw_grp_ids = kcalloc(max_rings, sizeof(u16), GFP_KERNEL);
2977 if (!vnic->fw_grp_ids) {
2978 rc = -ENOMEM;
2979 goto out;
2980 }
2981
Michael Chanae10ae72016-12-29 12:13:38 -05002982 if ((bp->flags & BNXT_FLAG_NEW_RSS_CAP) &&
2983 !(vnic->flags & BNXT_VNIC_RSS_FLAG))
2984 continue;
2985
Michael Chanc0c050c2015-10-22 16:01:17 -04002986 /* Allocate rss table and hash key */
2987 vnic->rss_table = dma_alloc_coherent(&pdev->dev, PAGE_SIZE,
2988 &vnic->rss_table_dma_addr,
2989 GFP_KERNEL);
2990 if (!vnic->rss_table) {
2991 rc = -ENOMEM;
2992 goto out;
2993 }
2994
2995 size = L1_CACHE_ALIGN(HW_HASH_INDEX_SIZE * sizeof(u16));
2996
2997 vnic->rss_hash_key = ((void *)vnic->rss_table) + size;
2998 vnic->rss_hash_key_dma_addr = vnic->rss_table_dma_addr + size;
2999 }
3000 return 0;
3001
3002out:
3003 return rc;
3004}
3005
3006static void bnxt_free_hwrm_resources(struct bnxt *bp)
3007{
3008 struct pci_dev *pdev = bp->pdev;
3009
3010 dma_free_coherent(&pdev->dev, PAGE_SIZE, bp->hwrm_cmd_resp_addr,
3011 bp->hwrm_cmd_resp_dma_addr);
3012
3013 bp->hwrm_cmd_resp_addr = NULL;
3014 if (bp->hwrm_dbg_resp_addr) {
3015 dma_free_coherent(&pdev->dev, HWRM_DBG_REG_BUF_SIZE,
3016 bp->hwrm_dbg_resp_addr,
3017 bp->hwrm_dbg_resp_dma_addr);
3018
3019 bp->hwrm_dbg_resp_addr = NULL;
3020 }
3021}
3022
3023static int bnxt_alloc_hwrm_resources(struct bnxt *bp)
3024{
3025 struct pci_dev *pdev = bp->pdev;
3026
3027 bp->hwrm_cmd_resp_addr = dma_alloc_coherent(&pdev->dev, PAGE_SIZE,
3028 &bp->hwrm_cmd_resp_dma_addr,
3029 GFP_KERNEL);
3030 if (!bp->hwrm_cmd_resp_addr)
3031 return -ENOMEM;
3032 bp->hwrm_dbg_resp_addr = dma_alloc_coherent(&pdev->dev,
3033 HWRM_DBG_REG_BUF_SIZE,
3034 &bp->hwrm_dbg_resp_dma_addr,
3035 GFP_KERNEL);
3036 if (!bp->hwrm_dbg_resp_addr)
3037 netdev_warn(bp->dev, "fail to alloc debug register dma mem\n");
3038
3039 return 0;
3040}
3041
Deepak Khungare605db82017-05-29 19:06:04 -04003042static void bnxt_free_hwrm_short_cmd_req(struct bnxt *bp)
3043{
3044 if (bp->hwrm_short_cmd_req_addr) {
3045 struct pci_dev *pdev = bp->pdev;
3046
3047 dma_free_coherent(&pdev->dev, BNXT_HWRM_MAX_REQ_LEN,
3048 bp->hwrm_short_cmd_req_addr,
3049 bp->hwrm_short_cmd_req_dma_addr);
3050 bp->hwrm_short_cmd_req_addr = NULL;
3051 }
3052}
3053
3054static int bnxt_alloc_hwrm_short_cmd_req(struct bnxt *bp)
3055{
3056 struct pci_dev *pdev = bp->pdev;
3057
3058 bp->hwrm_short_cmd_req_addr =
3059 dma_alloc_coherent(&pdev->dev, BNXT_HWRM_MAX_REQ_LEN,
3060 &bp->hwrm_short_cmd_req_dma_addr,
3061 GFP_KERNEL);
3062 if (!bp->hwrm_short_cmd_req_addr)
3063 return -ENOMEM;
3064
3065 return 0;
3066}
3067
Michael Chanc0c050c2015-10-22 16:01:17 -04003068static void bnxt_free_stats(struct bnxt *bp)
3069{
3070 u32 size, i;
3071 struct pci_dev *pdev = bp->pdev;
3072
Vasundhara Volam00db3cb2018-03-31 13:54:12 -04003073 bp->flags &= ~BNXT_FLAG_PORT_STATS;
3074 bp->flags &= ~BNXT_FLAG_PORT_STATS_EXT;
3075
Michael Chan3bdf56c2016-03-07 15:38:45 -05003076 if (bp->hw_rx_port_stats) {
3077 dma_free_coherent(&pdev->dev, bp->hw_port_stats_size,
3078 bp->hw_rx_port_stats,
3079 bp->hw_rx_port_stats_map);
3080 bp->hw_rx_port_stats = NULL;
Vasundhara Volam00db3cb2018-03-31 13:54:12 -04003081 }
3082
3083 if (bp->hw_rx_port_stats_ext) {
3084 dma_free_coherent(&pdev->dev, sizeof(struct rx_port_stats_ext),
3085 bp->hw_rx_port_stats_ext,
3086 bp->hw_rx_port_stats_ext_map);
3087 bp->hw_rx_port_stats_ext = NULL;
Michael Chan3bdf56c2016-03-07 15:38:45 -05003088 }
3089
Michael Chanc0c050c2015-10-22 16:01:17 -04003090 if (!bp->bnapi)
3091 return;
3092
3093 size = sizeof(struct ctx_hw_stats);
3094
3095 for (i = 0; i < bp->cp_nr_rings; i++) {
3096 struct bnxt_napi *bnapi = bp->bnapi[i];
3097 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
3098
3099 if (cpr->hw_stats) {
3100 dma_free_coherent(&pdev->dev, size, cpr->hw_stats,
3101 cpr->hw_stats_map);
3102 cpr->hw_stats = NULL;
3103 }
3104 }
3105}
3106
3107static int bnxt_alloc_stats(struct bnxt *bp)
3108{
3109 u32 size, i;
3110 struct pci_dev *pdev = bp->pdev;
3111
3112 size = sizeof(struct ctx_hw_stats);
3113
3114 for (i = 0; i < bp->cp_nr_rings; i++) {
3115 struct bnxt_napi *bnapi = bp->bnapi[i];
3116 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
3117
3118 cpr->hw_stats = dma_alloc_coherent(&pdev->dev, size,
3119 &cpr->hw_stats_map,
3120 GFP_KERNEL);
3121 if (!cpr->hw_stats)
3122 return -ENOMEM;
3123
3124 cpr->hw_stats_ctx_id = INVALID_STATS_CTX_ID;
3125 }
Michael Chan3bdf56c2016-03-07 15:38:45 -05003126
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04003127 if (BNXT_PF(bp) && bp->chip_num != CHIP_NUM_58700) {
Michael Chan3bdf56c2016-03-07 15:38:45 -05003128 bp->hw_port_stats_size = sizeof(struct rx_port_stats) +
3129 sizeof(struct tx_port_stats) + 1024;
3130
3131 bp->hw_rx_port_stats =
3132 dma_alloc_coherent(&pdev->dev, bp->hw_port_stats_size,
3133 &bp->hw_rx_port_stats_map,
3134 GFP_KERNEL);
3135 if (!bp->hw_rx_port_stats)
3136 return -ENOMEM;
3137
3138 bp->hw_tx_port_stats = (void *)(bp->hw_rx_port_stats + 1) +
3139 512;
3140 bp->hw_tx_port_stats_map = bp->hw_rx_port_stats_map +
3141 sizeof(struct rx_port_stats) + 512;
3142 bp->flags |= BNXT_FLAG_PORT_STATS;
Vasundhara Volam00db3cb2018-03-31 13:54:12 -04003143
3144 /* Display extended statistics only if FW supports it */
3145 if (bp->hwrm_spec_code < 0x10804 ||
3146 bp->hwrm_spec_code == 0x10900)
3147 return 0;
3148
3149 bp->hw_rx_port_stats_ext =
3150 dma_zalloc_coherent(&pdev->dev,
3151 sizeof(struct rx_port_stats_ext),
3152 &bp->hw_rx_port_stats_ext_map,
3153 GFP_KERNEL);
3154 if (!bp->hw_rx_port_stats_ext)
3155 return 0;
3156
3157 bp->flags |= BNXT_FLAG_PORT_STATS_EXT;
Michael Chan3bdf56c2016-03-07 15:38:45 -05003158 }
Michael Chanc0c050c2015-10-22 16:01:17 -04003159 return 0;
3160}
3161
3162static void bnxt_clear_ring_indices(struct bnxt *bp)
3163{
3164 int i;
3165
3166 if (!bp->bnapi)
3167 return;
3168
3169 for (i = 0; i < bp->cp_nr_rings; i++) {
3170 struct bnxt_napi *bnapi = bp->bnapi[i];
3171 struct bnxt_cp_ring_info *cpr;
3172 struct bnxt_rx_ring_info *rxr;
3173 struct bnxt_tx_ring_info *txr;
3174
3175 if (!bnapi)
3176 continue;
3177
3178 cpr = &bnapi->cp_ring;
3179 cpr->cp_raw_cons = 0;
3180
Michael Chanb6ab4b02016-01-02 23:44:59 -05003181 txr = bnapi->tx_ring;
Michael Chan3b2b7d92016-01-02 23:45:00 -05003182 if (txr) {
3183 txr->tx_prod = 0;
3184 txr->tx_cons = 0;
3185 }
Michael Chanc0c050c2015-10-22 16:01:17 -04003186
Michael Chanb6ab4b02016-01-02 23:44:59 -05003187 rxr = bnapi->rx_ring;
Michael Chan3b2b7d92016-01-02 23:45:00 -05003188 if (rxr) {
3189 rxr->rx_prod = 0;
3190 rxr->rx_agg_prod = 0;
3191 rxr->rx_sw_agg_prod = 0;
Michael Chan376a5b82016-05-10 19:17:59 -04003192 rxr->rx_next_cons = 0;
Michael Chan3b2b7d92016-01-02 23:45:00 -05003193 }
Michael Chanc0c050c2015-10-22 16:01:17 -04003194 }
3195}
3196
3197static void bnxt_free_ntp_fltrs(struct bnxt *bp, bool irq_reinit)
3198{
3199#ifdef CONFIG_RFS_ACCEL
3200 int i;
3201
3202 /* Under rtnl_lock and all our NAPIs have been disabled. It's
3203 * safe to delete the hash table.
3204 */
3205 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
3206 struct hlist_head *head;
3207 struct hlist_node *tmp;
3208 struct bnxt_ntuple_filter *fltr;
3209
3210 head = &bp->ntp_fltr_hash_tbl[i];
3211 hlist_for_each_entry_safe(fltr, tmp, head, hash) {
3212 hlist_del(&fltr->hash);
3213 kfree(fltr);
3214 }
3215 }
3216 if (irq_reinit) {
3217 kfree(bp->ntp_fltr_bmap);
3218 bp->ntp_fltr_bmap = NULL;
3219 }
3220 bp->ntp_fltr_count = 0;
3221#endif
3222}
3223
3224static int bnxt_alloc_ntp_fltrs(struct bnxt *bp)
3225{
3226#ifdef CONFIG_RFS_ACCEL
3227 int i, rc = 0;
3228
3229 if (!(bp->flags & BNXT_FLAG_RFS))
3230 return 0;
3231
3232 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++)
3233 INIT_HLIST_HEAD(&bp->ntp_fltr_hash_tbl[i]);
3234
3235 bp->ntp_fltr_count = 0;
Dan Carpenterac45bd92017-05-06 03:49:01 +03003236 bp->ntp_fltr_bmap = kcalloc(BITS_TO_LONGS(BNXT_NTP_FLTR_MAX_FLTR),
3237 sizeof(long),
Michael Chanc0c050c2015-10-22 16:01:17 -04003238 GFP_KERNEL);
3239
3240 if (!bp->ntp_fltr_bmap)
3241 rc = -ENOMEM;
3242
3243 return rc;
3244#else
3245 return 0;
3246#endif
3247}
3248
3249static void bnxt_free_mem(struct bnxt *bp, bool irq_re_init)
3250{
3251 bnxt_free_vnic_attributes(bp);
3252 bnxt_free_tx_rings(bp);
3253 bnxt_free_rx_rings(bp);
3254 bnxt_free_cp_rings(bp);
3255 bnxt_free_ntp_fltrs(bp, irq_re_init);
3256 if (irq_re_init) {
3257 bnxt_free_stats(bp);
3258 bnxt_free_ring_grps(bp);
3259 bnxt_free_vnics(bp);
Michael Chana960dec2017-02-06 16:55:39 -05003260 kfree(bp->tx_ring_map);
3261 bp->tx_ring_map = NULL;
Michael Chanb6ab4b02016-01-02 23:44:59 -05003262 kfree(bp->tx_ring);
3263 bp->tx_ring = NULL;
3264 kfree(bp->rx_ring);
3265 bp->rx_ring = NULL;
Michael Chanc0c050c2015-10-22 16:01:17 -04003266 kfree(bp->bnapi);
3267 bp->bnapi = NULL;
3268 } else {
3269 bnxt_clear_ring_indices(bp);
3270 }
3271}
3272
3273static int bnxt_alloc_mem(struct bnxt *bp, bool irq_re_init)
3274{
Michael Chan01657bc2016-01-02 23:45:03 -05003275 int i, j, rc, size, arr_size;
Michael Chanc0c050c2015-10-22 16:01:17 -04003276 void *bnapi;
3277
3278 if (irq_re_init) {
3279 /* Allocate bnapi mem pointer array and mem block for
3280 * all queues
3281 */
3282 arr_size = L1_CACHE_ALIGN(sizeof(struct bnxt_napi *) *
3283 bp->cp_nr_rings);
3284 size = L1_CACHE_ALIGN(sizeof(struct bnxt_napi));
3285 bnapi = kzalloc(arr_size + size * bp->cp_nr_rings, GFP_KERNEL);
3286 if (!bnapi)
3287 return -ENOMEM;
3288
3289 bp->bnapi = bnapi;
3290 bnapi += arr_size;
3291 for (i = 0; i < bp->cp_nr_rings; i++, bnapi += size) {
3292 bp->bnapi[i] = bnapi;
3293 bp->bnapi[i]->index = i;
3294 bp->bnapi[i]->bp = bp;
3295 }
3296
Michael Chanb6ab4b02016-01-02 23:44:59 -05003297 bp->rx_ring = kcalloc(bp->rx_nr_rings,
3298 sizeof(struct bnxt_rx_ring_info),
3299 GFP_KERNEL);
3300 if (!bp->rx_ring)
3301 return -ENOMEM;
3302
3303 for (i = 0; i < bp->rx_nr_rings; i++) {
3304 bp->rx_ring[i].bnapi = bp->bnapi[i];
3305 bp->bnapi[i]->rx_ring = &bp->rx_ring[i];
3306 }
3307
3308 bp->tx_ring = kcalloc(bp->tx_nr_rings,
3309 sizeof(struct bnxt_tx_ring_info),
3310 GFP_KERNEL);
3311 if (!bp->tx_ring)
3312 return -ENOMEM;
3313
Michael Chana960dec2017-02-06 16:55:39 -05003314 bp->tx_ring_map = kcalloc(bp->tx_nr_rings, sizeof(u16),
3315 GFP_KERNEL);
3316
3317 if (!bp->tx_ring_map)
3318 return -ENOMEM;
3319
Michael Chan01657bc2016-01-02 23:45:03 -05003320 if (bp->flags & BNXT_FLAG_SHARED_RINGS)
3321 j = 0;
3322 else
3323 j = bp->rx_nr_rings;
3324
3325 for (i = 0; i < bp->tx_nr_rings; i++, j++) {
3326 bp->tx_ring[i].bnapi = bp->bnapi[j];
3327 bp->bnapi[j]->tx_ring = &bp->tx_ring[i];
Michael Chan5f449242017-02-06 16:55:40 -05003328 bp->tx_ring_map[i] = bp->tx_nr_rings_xdp + i;
Michael Chan38413402017-02-06 16:55:43 -05003329 if (i >= bp->tx_nr_rings_xdp) {
Michael Chan5f449242017-02-06 16:55:40 -05003330 bp->tx_ring[i].txq_index = i -
3331 bp->tx_nr_rings_xdp;
Michael Chan38413402017-02-06 16:55:43 -05003332 bp->bnapi[j]->tx_int = bnxt_tx_int;
3333 } else {
Michael Chanfa3e93e2017-02-06 16:55:41 -05003334 bp->bnapi[j]->flags |= BNXT_NAPI_FLAG_XDP;
Michael Chan38413402017-02-06 16:55:43 -05003335 bp->bnapi[j]->tx_int = bnxt_tx_int_xdp;
3336 }
Michael Chanb6ab4b02016-01-02 23:44:59 -05003337 }
3338
Michael Chanc0c050c2015-10-22 16:01:17 -04003339 rc = bnxt_alloc_stats(bp);
3340 if (rc)
3341 goto alloc_mem_err;
3342
3343 rc = bnxt_alloc_ntp_fltrs(bp);
3344 if (rc)
3345 goto alloc_mem_err;
3346
3347 rc = bnxt_alloc_vnics(bp);
3348 if (rc)
3349 goto alloc_mem_err;
3350 }
3351
3352 bnxt_init_ring_struct(bp);
3353
3354 rc = bnxt_alloc_rx_rings(bp);
3355 if (rc)
3356 goto alloc_mem_err;
3357
3358 rc = bnxt_alloc_tx_rings(bp);
3359 if (rc)
3360 goto alloc_mem_err;
3361
3362 rc = bnxt_alloc_cp_rings(bp);
3363 if (rc)
3364 goto alloc_mem_err;
3365
3366 bp->vnic_info[0].flags |= BNXT_VNIC_RSS_FLAG | BNXT_VNIC_MCAST_FLAG |
3367 BNXT_VNIC_UCAST_FLAG;
3368 rc = bnxt_alloc_vnic_attributes(bp);
3369 if (rc)
3370 goto alloc_mem_err;
3371 return 0;
3372
3373alloc_mem_err:
3374 bnxt_free_mem(bp, true);
3375 return rc;
3376}
3377
Michael Chan9d8bc092016-12-29 12:13:33 -05003378static void bnxt_disable_int(struct bnxt *bp)
3379{
3380 int i;
3381
3382 if (!bp->bnapi)
3383 return;
3384
3385 for (i = 0; i < bp->cp_nr_rings; i++) {
3386 struct bnxt_napi *bnapi = bp->bnapi[i];
3387 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
Michael Chandaf1f1e2017-02-20 19:25:17 -05003388 struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
Michael Chan9d8bc092016-12-29 12:13:33 -05003389
Michael Chandaf1f1e2017-02-20 19:25:17 -05003390 if (ring->fw_ring_id != INVALID_HW_RING_ID)
3391 BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
Michael Chan9d8bc092016-12-29 12:13:33 -05003392 }
3393}
3394
Michael Chane5811b82018-03-31 13:54:18 -04003395static int bnxt_cp_num_to_irq_num(struct bnxt *bp, int n)
3396{
3397 struct bnxt_napi *bnapi = bp->bnapi[n];
3398 struct bnxt_cp_ring_info *cpr;
3399
3400 cpr = &bnapi->cp_ring;
3401 return cpr->cp_ring_struct.map_idx;
3402}
3403
Michael Chan9d8bc092016-12-29 12:13:33 -05003404static void bnxt_disable_int_sync(struct bnxt *bp)
3405{
3406 int i;
3407
3408 atomic_inc(&bp->intr_sem);
3409
3410 bnxt_disable_int(bp);
Michael Chane5811b82018-03-31 13:54:18 -04003411 for (i = 0; i < bp->cp_nr_rings; i++) {
3412 int map_idx = bnxt_cp_num_to_irq_num(bp, i);
3413
3414 synchronize_irq(bp->irq_tbl[map_idx].vector);
3415 }
Michael Chan9d8bc092016-12-29 12:13:33 -05003416}
3417
3418static void bnxt_enable_int(struct bnxt *bp)
3419{
3420 int i;
3421
3422 atomic_set(&bp->intr_sem, 0);
3423 for (i = 0; i < bp->cp_nr_rings; i++) {
3424 struct bnxt_napi *bnapi = bp->bnapi[i];
3425 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
3426
3427 BNXT_CP_DB_REARM(cpr->cp_doorbell, cpr->cp_raw_cons);
3428 }
3429}
3430
Michael Chanc0c050c2015-10-22 16:01:17 -04003431void bnxt_hwrm_cmd_hdr_init(struct bnxt *bp, void *request, u16 req_type,
3432 u16 cmpl_ring, u16 target_id)
3433{
Michael Chana8643e12016-02-26 04:00:05 -05003434 struct input *req = request;
Michael Chanc0c050c2015-10-22 16:01:17 -04003435
Michael Chana8643e12016-02-26 04:00:05 -05003436 req->req_type = cpu_to_le16(req_type);
3437 req->cmpl_ring = cpu_to_le16(cmpl_ring);
3438 req->target_id = cpu_to_le16(target_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04003439 req->resp_addr = cpu_to_le64(bp->hwrm_cmd_resp_dma_addr);
3440}
3441
Michael Chanfbfbc482016-02-26 04:00:07 -05003442static int bnxt_hwrm_do_send_msg(struct bnxt *bp, void *msg, u32 msg_len,
3443 int timeout, bool silent)
Michael Chanc0c050c2015-10-22 16:01:17 -04003444{
Michael Chana11fa2b2016-05-15 03:04:47 -04003445 int i, intr_process, rc, tmo_count;
Michael Chana8643e12016-02-26 04:00:05 -05003446 struct input *req = msg;
Michael Chanc0c050c2015-10-22 16:01:17 -04003447 u32 *data = msg;
Michael Chan845adfe2018-03-31 13:54:15 -04003448 __le32 *resp_len;
3449 u8 *valid;
Michael Chanc0c050c2015-10-22 16:01:17 -04003450 u16 cp_ring_id, len = 0;
3451 struct hwrm_err_output *resp = bp->hwrm_cmd_resp_addr;
Deepak Khungare605db82017-05-29 19:06:04 -04003452 u16 max_req_len = BNXT_HWRM_MAX_REQ_LEN;
Vasundhara Volamebd58182017-12-01 03:13:05 -05003453 struct hwrm_short_input short_input = {0};
Michael Chanc0c050c2015-10-22 16:01:17 -04003454
Michael Chana8643e12016-02-26 04:00:05 -05003455 req->seq_id = cpu_to_le16(bp->hwrm_cmd_seq++);
Michael Chanc0c050c2015-10-22 16:01:17 -04003456 memset(resp, 0, PAGE_SIZE);
Michael Chana8643e12016-02-26 04:00:05 -05003457 cp_ring_id = le16_to_cpu(req->cmpl_ring);
Michael Chanc0c050c2015-10-22 16:01:17 -04003458 intr_process = (cp_ring_id == INVALID_HW_RING_ID) ? 0 : 1;
3459
Deepak Khungare605db82017-05-29 19:06:04 -04003460 if (bp->flags & BNXT_FLAG_SHORT_CMD) {
3461 void *short_cmd_req = bp->hwrm_short_cmd_req_addr;
Deepak Khungare605db82017-05-29 19:06:04 -04003462
3463 memcpy(short_cmd_req, req, msg_len);
3464 memset(short_cmd_req + msg_len, 0, BNXT_HWRM_MAX_REQ_LEN -
3465 msg_len);
3466
3467 short_input.req_type = req->req_type;
3468 short_input.signature =
3469 cpu_to_le16(SHORT_REQ_SIGNATURE_SHORT_CMD);
3470 short_input.size = cpu_to_le16(msg_len);
3471 short_input.req_addr =
3472 cpu_to_le64(bp->hwrm_short_cmd_req_dma_addr);
3473
3474 data = (u32 *)&short_input;
3475 msg_len = sizeof(short_input);
3476
3477 /* Sync memory write before updating doorbell */
3478 wmb();
3479
3480 max_req_len = BNXT_HWRM_SHORT_REQ_LEN;
3481 }
3482
Michael Chanc0c050c2015-10-22 16:01:17 -04003483 /* Write request msg to hwrm channel */
3484 __iowrite32_copy(bp->bar0, data, msg_len / 4);
3485
Deepak Khungare605db82017-05-29 19:06:04 -04003486 for (i = msg_len; i < max_req_len; i += 4)
Michael Chand79979a2016-01-07 19:56:57 -05003487 writel(0, bp->bar0 + i);
3488
Michael Chanc0c050c2015-10-22 16:01:17 -04003489 /* currently supports only one outstanding message */
3490 if (intr_process)
Michael Chana8643e12016-02-26 04:00:05 -05003491 bp->hwrm_intr_seq_id = le16_to_cpu(req->seq_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04003492
3493 /* Ring channel doorbell */
3494 writel(1, bp->bar0 + 0x100);
3495
Michael Chanff4fe812016-02-26 04:00:04 -05003496 if (!timeout)
3497 timeout = DFLT_HWRM_CMD_TIMEOUT;
3498
Michael Chanc0c050c2015-10-22 16:01:17 -04003499 i = 0;
Michael Chana11fa2b2016-05-15 03:04:47 -04003500 tmo_count = timeout * 40;
Michael Chan845adfe2018-03-31 13:54:15 -04003501 resp_len = bp->hwrm_cmd_resp_addr + HWRM_RESP_LEN_OFFSET;
Michael Chanc0c050c2015-10-22 16:01:17 -04003502 if (intr_process) {
3503 /* Wait until hwrm response cmpl interrupt is processed */
3504 while (bp->hwrm_intr_seq_id != HWRM_SEQ_ID_INVALID &&
Michael Chana11fa2b2016-05-15 03:04:47 -04003505 i++ < tmo_count) {
3506 usleep_range(25, 40);
Michael Chanc0c050c2015-10-22 16:01:17 -04003507 }
3508
3509 if (bp->hwrm_intr_seq_id != HWRM_SEQ_ID_INVALID) {
3510 netdev_err(bp->dev, "Resp cmpl intr err msg: 0x%x\n",
Michael Chana8643e12016-02-26 04:00:05 -05003511 le16_to_cpu(req->req_type));
Michael Chanc0c050c2015-10-22 16:01:17 -04003512 return -1;
3513 }
Michael Chan845adfe2018-03-31 13:54:15 -04003514 len = (le32_to_cpu(*resp_len) & HWRM_RESP_LEN_MASK) >>
3515 HWRM_RESP_LEN_SFT;
3516 valid = bp->hwrm_cmd_resp_addr + len - 1;
Michael Chanc0c050c2015-10-22 16:01:17 -04003517 } else {
3518 /* Check if response len is updated */
Michael Chana11fa2b2016-05-15 03:04:47 -04003519 for (i = 0; i < tmo_count; i++) {
Michael Chanc0c050c2015-10-22 16:01:17 -04003520 len = (le32_to_cpu(*resp_len) & HWRM_RESP_LEN_MASK) >>
3521 HWRM_RESP_LEN_SFT;
3522 if (len)
3523 break;
Michael Chana11fa2b2016-05-15 03:04:47 -04003524 usleep_range(25, 40);
Michael Chanc0c050c2015-10-22 16:01:17 -04003525 }
3526
Michael Chana11fa2b2016-05-15 03:04:47 -04003527 if (i >= tmo_count) {
Michael Chanc0c050c2015-10-22 16:01:17 -04003528 netdev_err(bp->dev, "Error (timeout: %d) msg {0x%x 0x%x} len:%d\n",
Michael Chana8643e12016-02-26 04:00:05 -05003529 timeout, le16_to_cpu(req->req_type),
Michael Chan8578d6c2016-05-15 03:04:48 -04003530 le16_to_cpu(req->seq_id), len);
Michael Chanc0c050c2015-10-22 16:01:17 -04003531 return -1;
3532 }
3533
Michael Chan845adfe2018-03-31 13:54:15 -04003534 /* Last byte of resp contains valid bit */
3535 valid = bp->hwrm_cmd_resp_addr + len - 1;
Michael Chana11fa2b2016-05-15 03:04:47 -04003536 for (i = 0; i < 5; i++) {
Michael Chan845adfe2018-03-31 13:54:15 -04003537 /* make sure we read from updated DMA memory */
3538 dma_rmb();
3539 if (*valid)
Michael Chanc0c050c2015-10-22 16:01:17 -04003540 break;
Michael Chana11fa2b2016-05-15 03:04:47 -04003541 udelay(1);
Michael Chanc0c050c2015-10-22 16:01:17 -04003542 }
3543
Michael Chana11fa2b2016-05-15 03:04:47 -04003544 if (i >= 5) {
Michael Chanc0c050c2015-10-22 16:01:17 -04003545 netdev_err(bp->dev, "Error (timeout: %d) msg {0x%x 0x%x} len:%d v:%d\n",
Michael Chana8643e12016-02-26 04:00:05 -05003546 timeout, le16_to_cpu(req->req_type),
3547 le16_to_cpu(req->seq_id), len, *valid);
Michael Chanc0c050c2015-10-22 16:01:17 -04003548 return -1;
3549 }
3550 }
3551
Michael Chan845adfe2018-03-31 13:54:15 -04003552 /* Zero valid bit for compatibility. Valid bit in an older spec
3553 * may become a new field in a newer spec. We must make sure that
3554 * a new field not implemented by old spec will read zero.
3555 */
3556 *valid = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04003557 rc = le16_to_cpu(resp->error_code);
Michael Chanfbfbc482016-02-26 04:00:07 -05003558 if (rc && !silent)
Michael Chanc0c050c2015-10-22 16:01:17 -04003559 netdev_err(bp->dev, "hwrm req_type 0x%x seq id 0x%x error 0x%x\n",
3560 le16_to_cpu(resp->req_type),
3561 le16_to_cpu(resp->seq_id), rc);
Michael Chanfbfbc482016-02-26 04:00:07 -05003562 return rc;
3563}
3564
3565int _hwrm_send_message(struct bnxt *bp, void *msg, u32 msg_len, int timeout)
3566{
3567 return bnxt_hwrm_do_send_msg(bp, msg, msg_len, timeout, false);
Michael Chanc0c050c2015-10-22 16:01:17 -04003568}
3569
Michael Chancc72f3b2017-10-13 21:09:33 -04003570int _hwrm_send_message_silent(struct bnxt *bp, void *msg, u32 msg_len,
3571 int timeout)
3572{
3573 return bnxt_hwrm_do_send_msg(bp, msg, msg_len, timeout, true);
3574}
3575
Michael Chanc0c050c2015-10-22 16:01:17 -04003576int hwrm_send_message(struct bnxt *bp, void *msg, u32 msg_len, int timeout)
3577{
3578 int rc;
3579
3580 mutex_lock(&bp->hwrm_cmd_lock);
3581 rc = _hwrm_send_message(bp, msg, msg_len, timeout);
3582 mutex_unlock(&bp->hwrm_cmd_lock);
3583 return rc;
3584}
3585
Michael Chan90e209212016-02-26 04:00:08 -05003586int hwrm_send_message_silent(struct bnxt *bp, void *msg, u32 msg_len,
3587 int timeout)
3588{
3589 int rc;
3590
3591 mutex_lock(&bp->hwrm_cmd_lock);
3592 rc = bnxt_hwrm_do_send_msg(bp, msg, msg_len, timeout, true);
3593 mutex_unlock(&bp->hwrm_cmd_lock);
3594 return rc;
3595}
3596
Michael Chana1653b12016-12-07 00:26:20 -05003597int bnxt_hwrm_func_rgtr_async_events(struct bnxt *bp, unsigned long *bmap,
3598 int bmap_size)
Michael Chanc0c050c2015-10-22 16:01:17 -04003599{
3600 struct hwrm_func_drv_rgtr_input req = {0};
Michael Chan25be8622016-04-05 14:09:00 -04003601 DECLARE_BITMAP(async_events_bmap, 256);
3602 u32 *events = (u32 *)async_events_bmap;
Michael Chana1653b12016-12-07 00:26:20 -05003603 int i;
Michael Chanc0c050c2015-10-22 16:01:17 -04003604
3605 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_RGTR, -1, -1);
3606
3607 req.enables =
Michael Chana1653b12016-12-07 00:26:20 -05003608 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_ASYNC_EVENT_FWD);
Michael Chanc0c050c2015-10-22 16:01:17 -04003609
Michael Chan25be8622016-04-05 14:09:00 -04003610 memset(async_events_bmap, 0, sizeof(async_events_bmap));
3611 for (i = 0; i < ARRAY_SIZE(bnxt_async_events_arr); i++)
3612 __set_bit(bnxt_async_events_arr[i], async_events_bmap);
3613
Michael Chana1653b12016-12-07 00:26:20 -05003614 if (bmap && bmap_size) {
3615 for (i = 0; i < bmap_size; i++) {
3616 if (test_bit(i, bmap))
3617 __set_bit(i, async_events_bmap);
3618 }
3619 }
3620
Michael Chan25be8622016-04-05 14:09:00 -04003621 for (i = 0; i < 8; i++)
3622 req.async_event_fwd[i] |= cpu_to_le32(events[i]);
3623
Michael Chana1653b12016-12-07 00:26:20 -05003624 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3625}
3626
3627static int bnxt_hwrm_func_drv_rgtr(struct bnxt *bp)
3628{
3629 struct hwrm_func_drv_rgtr_input req = {0};
3630
3631 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_RGTR, -1, -1);
3632
3633 req.enables =
3634 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_OS_TYPE |
3635 FUNC_DRV_RGTR_REQ_ENABLES_VER);
3636
Michael Chan11f15ed2016-04-05 14:08:55 -04003637 req.os_type = cpu_to_le16(FUNC_DRV_RGTR_REQ_OS_TYPE_LINUX);
Michael Chand4f52de02018-03-31 13:54:06 -04003638 req.flags = cpu_to_le32(FUNC_DRV_RGTR_REQ_FLAGS_16BIT_VER_MODE);
3639 req.ver_maj_8b = DRV_VER_MAJ;
3640 req.ver_min_8b = DRV_VER_MIN;
3641 req.ver_upd_8b = DRV_VER_UPD;
3642 req.ver_maj = cpu_to_le16(DRV_VER_MAJ);
3643 req.ver_min = cpu_to_le16(DRV_VER_MIN);
3644 req.ver_upd = cpu_to_le16(DRV_VER_UPD);
Michael Chanc0c050c2015-10-22 16:01:17 -04003645
3646 if (BNXT_PF(bp)) {
Michael Chan9b0436c2017-07-11 13:05:36 -04003647 u32 data[8];
Michael Chana1653b12016-12-07 00:26:20 -05003648 int i;
Michael Chanc0c050c2015-10-22 16:01:17 -04003649
Michael Chan9b0436c2017-07-11 13:05:36 -04003650 memset(data, 0, sizeof(data));
3651 for (i = 0; i < ARRAY_SIZE(bnxt_vf_req_snif); i++) {
3652 u16 cmd = bnxt_vf_req_snif[i];
3653 unsigned int bit, idx;
3654
3655 idx = cmd / 32;
3656 bit = cmd % 32;
3657 data[idx] |= 1 << bit;
3658 }
Michael Chanc0c050c2015-10-22 16:01:17 -04003659
Michael Chande68f5de2015-12-09 19:35:41 -05003660 for (i = 0; i < 8; i++)
3661 req.vf_req_fwd[i] = cpu_to_le32(data[i]);
3662
Michael Chanc0c050c2015-10-22 16:01:17 -04003663 req.enables |=
3664 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_VF_REQ_FWD);
3665 }
3666
3667 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3668}
3669
Jeffrey Huangbe58a0d2015-12-27 18:19:18 -05003670static int bnxt_hwrm_func_drv_unrgtr(struct bnxt *bp)
3671{
3672 struct hwrm_func_drv_unrgtr_input req = {0};
3673
3674 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_UNRGTR, -1, -1);
3675 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3676}
3677
Michael Chanc0c050c2015-10-22 16:01:17 -04003678static int bnxt_hwrm_tunnel_dst_port_free(struct bnxt *bp, u8 tunnel_type)
3679{
3680 u32 rc = 0;
3681 struct hwrm_tunnel_dst_port_free_input req = {0};
3682
3683 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_TUNNEL_DST_PORT_FREE, -1, -1);
3684 req.tunnel_type = tunnel_type;
3685
3686 switch (tunnel_type) {
3687 case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN:
3688 req.tunnel_dst_port_id = bp->vxlan_fw_dst_port_id;
3689 break;
3690 case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE:
3691 req.tunnel_dst_port_id = bp->nge_fw_dst_port_id;
3692 break;
3693 default:
3694 break;
3695 }
3696
3697 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3698 if (rc)
3699 netdev_err(bp->dev, "hwrm_tunnel_dst_port_free failed. rc:%d\n",
3700 rc);
3701 return rc;
3702}
3703
3704static int bnxt_hwrm_tunnel_dst_port_alloc(struct bnxt *bp, __be16 port,
3705 u8 tunnel_type)
3706{
3707 u32 rc = 0;
3708 struct hwrm_tunnel_dst_port_alloc_input req = {0};
3709 struct hwrm_tunnel_dst_port_alloc_output *resp = bp->hwrm_cmd_resp_addr;
3710
3711 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_TUNNEL_DST_PORT_ALLOC, -1, -1);
3712
3713 req.tunnel_type = tunnel_type;
3714 req.tunnel_dst_port_val = port;
3715
3716 mutex_lock(&bp->hwrm_cmd_lock);
3717 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3718 if (rc) {
3719 netdev_err(bp->dev, "hwrm_tunnel_dst_port_alloc failed. rc:%d\n",
3720 rc);
3721 goto err_out;
3722 }
3723
Christophe Jaillet57aac712016-11-22 06:14:40 +01003724 switch (tunnel_type) {
3725 case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_VXLAN:
Michael Chanc0c050c2015-10-22 16:01:17 -04003726 bp->vxlan_fw_dst_port_id = resp->tunnel_dst_port_id;
Christophe Jaillet57aac712016-11-22 06:14:40 +01003727 break;
3728 case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_GENEVE:
Michael Chanc0c050c2015-10-22 16:01:17 -04003729 bp->nge_fw_dst_port_id = resp->tunnel_dst_port_id;
Christophe Jaillet57aac712016-11-22 06:14:40 +01003730 break;
3731 default:
3732 break;
3733 }
3734
Michael Chanc0c050c2015-10-22 16:01:17 -04003735err_out:
3736 mutex_unlock(&bp->hwrm_cmd_lock);
3737 return rc;
3738}
3739
3740static int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt *bp, u16 vnic_id)
3741{
3742 struct hwrm_cfa_l2_set_rx_mask_input req = {0};
3743 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
3744
3745 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_L2_SET_RX_MASK, -1, -1);
Michael Chanc1935542015-12-27 18:19:28 -05003746 req.vnic_id = cpu_to_le32(vnic->fw_vnic_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04003747
3748 req.num_mc_entries = cpu_to_le32(vnic->mc_list_count);
3749 req.mc_tbl_addr = cpu_to_le64(vnic->mc_list_mapping);
3750 req.mask = cpu_to_le32(vnic->rx_mask);
3751 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3752}
3753
3754#ifdef CONFIG_RFS_ACCEL
3755static int bnxt_hwrm_cfa_ntuple_filter_free(struct bnxt *bp,
3756 struct bnxt_ntuple_filter *fltr)
3757{
3758 struct hwrm_cfa_ntuple_filter_free_input req = {0};
3759
3760 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_NTUPLE_FILTER_FREE, -1, -1);
3761 req.ntuple_filter_id = fltr->filter_id;
3762 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3763}
3764
3765#define BNXT_NTP_FLTR_FLAGS \
3766 (CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_L2_FILTER_ID | \
3767 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_ETHERTYPE | \
3768 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_MACADDR | \
3769 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IPADDR_TYPE | \
3770 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR | \
3771 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR_MASK | \
3772 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR | \
3773 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR_MASK | \
3774 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IP_PROTOCOL | \
3775 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT | \
3776 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT_MASK | \
3777 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT | \
3778 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT_MASK | \
Michael Chanc1935542015-12-27 18:19:28 -05003779 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_ID)
Michael Chanc0c050c2015-10-22 16:01:17 -04003780
Michael Chan61aad722017-02-12 19:18:14 -05003781#define BNXT_NTP_TUNNEL_FLTR_FLAG \
3782 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_TUNNEL_TYPE
3783
Michael Chanc0c050c2015-10-22 16:01:17 -04003784static int bnxt_hwrm_cfa_ntuple_filter_alloc(struct bnxt *bp,
3785 struct bnxt_ntuple_filter *fltr)
3786{
3787 int rc = 0;
3788 struct hwrm_cfa_ntuple_filter_alloc_input req = {0};
3789 struct hwrm_cfa_ntuple_filter_alloc_output *resp =
3790 bp->hwrm_cmd_resp_addr;
3791 struct flow_keys *keys = &fltr->fkeys;
3792 struct bnxt_vnic_info *vnic = &bp->vnic_info[fltr->rxq + 1];
3793
3794 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_NTUPLE_FILTER_ALLOC, -1, -1);
Michael Chana54c4d72016-07-25 12:33:35 -04003795 req.l2_filter_id = bp->vnic_info[0].fw_l2_filter_id[fltr->l2_fltr_idx];
Michael Chanc0c050c2015-10-22 16:01:17 -04003796
3797 req.enables = cpu_to_le32(BNXT_NTP_FLTR_FLAGS);
3798
3799 req.ethertype = htons(ETH_P_IP);
3800 memcpy(req.src_macaddr, fltr->src_mac_addr, ETH_ALEN);
Michael Chanc1935542015-12-27 18:19:28 -05003801 req.ip_addr_type = CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV4;
Michael Chanc0c050c2015-10-22 16:01:17 -04003802 req.ip_protocol = keys->basic.ip_proto;
3803
Michael Chandda0e742016-12-29 12:13:40 -05003804 if (keys->basic.n_proto == htons(ETH_P_IPV6)) {
3805 int i;
3806
3807 req.ethertype = htons(ETH_P_IPV6);
3808 req.ip_addr_type =
3809 CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV6;
3810 *(struct in6_addr *)&req.src_ipaddr[0] =
3811 keys->addrs.v6addrs.src;
3812 *(struct in6_addr *)&req.dst_ipaddr[0] =
3813 keys->addrs.v6addrs.dst;
3814 for (i = 0; i < 4; i++) {
3815 req.src_ipaddr_mask[i] = cpu_to_be32(0xffffffff);
3816 req.dst_ipaddr_mask[i] = cpu_to_be32(0xffffffff);
3817 }
3818 } else {
3819 req.src_ipaddr[0] = keys->addrs.v4addrs.src;
3820 req.src_ipaddr_mask[0] = cpu_to_be32(0xffffffff);
3821 req.dst_ipaddr[0] = keys->addrs.v4addrs.dst;
3822 req.dst_ipaddr_mask[0] = cpu_to_be32(0xffffffff);
3823 }
Michael Chan61aad722017-02-12 19:18:14 -05003824 if (keys->control.flags & FLOW_DIS_ENCAPSULATION) {
3825 req.enables |= cpu_to_le32(BNXT_NTP_TUNNEL_FLTR_FLAG);
3826 req.tunnel_type =
3827 CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_ANYTUNNEL;
3828 }
Michael Chanc0c050c2015-10-22 16:01:17 -04003829
3830 req.src_port = keys->ports.src;
3831 req.src_port_mask = cpu_to_be16(0xffff);
3832 req.dst_port = keys->ports.dst;
3833 req.dst_port_mask = cpu_to_be16(0xffff);
3834
Michael Chanc1935542015-12-27 18:19:28 -05003835 req.dst_id = cpu_to_le16(vnic->fw_vnic_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04003836 mutex_lock(&bp->hwrm_cmd_lock);
3837 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3838 if (!rc)
3839 fltr->filter_id = resp->ntuple_filter_id;
3840 mutex_unlock(&bp->hwrm_cmd_lock);
3841 return rc;
3842}
3843#endif
3844
3845static int bnxt_hwrm_set_vnic_filter(struct bnxt *bp, u16 vnic_id, u16 idx,
3846 u8 *mac_addr)
3847{
3848 u32 rc = 0;
3849 struct hwrm_cfa_l2_filter_alloc_input req = {0};
3850 struct hwrm_cfa_l2_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr;
3851
3852 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_L2_FILTER_ALLOC, -1, -1);
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04003853 req.flags = cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_PATH_RX);
3854 if (!BNXT_CHIP_TYPE_NITRO_A0(bp))
3855 req.flags |=
3856 cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_OUTERMOST);
Michael Chanc1935542015-12-27 18:19:28 -05003857 req.dst_id = cpu_to_le16(bp->vnic_info[vnic_id].fw_vnic_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04003858 req.enables =
3859 cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR |
Michael Chanc1935542015-12-27 18:19:28 -05003860 CFA_L2_FILTER_ALLOC_REQ_ENABLES_DST_ID |
Michael Chanc0c050c2015-10-22 16:01:17 -04003861 CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR_MASK);
3862 memcpy(req.l2_addr, mac_addr, ETH_ALEN);
3863 req.l2_addr_mask[0] = 0xff;
3864 req.l2_addr_mask[1] = 0xff;
3865 req.l2_addr_mask[2] = 0xff;
3866 req.l2_addr_mask[3] = 0xff;
3867 req.l2_addr_mask[4] = 0xff;
3868 req.l2_addr_mask[5] = 0xff;
3869
3870 mutex_lock(&bp->hwrm_cmd_lock);
3871 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3872 if (!rc)
3873 bp->vnic_info[vnic_id].fw_l2_filter_id[idx] =
3874 resp->l2_filter_id;
3875 mutex_unlock(&bp->hwrm_cmd_lock);
3876 return rc;
3877}
3878
3879static int bnxt_hwrm_clear_vnic_filter(struct bnxt *bp)
3880{
3881 u16 i, j, num_of_vnics = 1; /* only vnic 0 supported */
3882 int rc = 0;
3883
3884 /* Any associated ntuple filters will also be cleared by firmware. */
3885 mutex_lock(&bp->hwrm_cmd_lock);
3886 for (i = 0; i < num_of_vnics; i++) {
3887 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
3888
3889 for (j = 0; j < vnic->uc_filter_count; j++) {
3890 struct hwrm_cfa_l2_filter_free_input req = {0};
3891
3892 bnxt_hwrm_cmd_hdr_init(bp, &req,
3893 HWRM_CFA_L2_FILTER_FREE, -1, -1);
3894
3895 req.l2_filter_id = vnic->fw_l2_filter_id[j];
3896
3897 rc = _hwrm_send_message(bp, &req, sizeof(req),
3898 HWRM_CMD_TIMEOUT);
3899 }
3900 vnic->uc_filter_count = 0;
3901 }
3902 mutex_unlock(&bp->hwrm_cmd_lock);
3903
3904 return rc;
3905}
3906
3907static int bnxt_hwrm_vnic_set_tpa(struct bnxt *bp, u16 vnic_id, u32 tpa_flags)
3908{
3909 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
3910 struct hwrm_vnic_tpa_cfg_input req = {0};
3911
Michael Chan3c4fe802018-03-09 23:46:10 -05003912 if (vnic->fw_vnic_id == INVALID_HW_RING_ID)
3913 return 0;
3914
Michael Chanc0c050c2015-10-22 16:01:17 -04003915 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_TPA_CFG, -1, -1);
3916
3917 if (tpa_flags) {
3918 u16 mss = bp->dev->mtu - 40;
3919 u32 nsegs, n, segs = 0, flags;
3920
3921 flags = VNIC_TPA_CFG_REQ_FLAGS_TPA |
3922 VNIC_TPA_CFG_REQ_FLAGS_ENCAP_TPA |
3923 VNIC_TPA_CFG_REQ_FLAGS_RSC_WND_UPDATE |
3924 VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_ECN |
3925 VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_SAME_GRE_SEQ;
3926 if (tpa_flags & BNXT_FLAG_GRO)
3927 flags |= VNIC_TPA_CFG_REQ_FLAGS_GRO;
3928
3929 req.flags = cpu_to_le32(flags);
3930
3931 req.enables =
3932 cpu_to_le32(VNIC_TPA_CFG_REQ_ENABLES_MAX_AGG_SEGS |
Michael Chanc1935542015-12-27 18:19:28 -05003933 VNIC_TPA_CFG_REQ_ENABLES_MAX_AGGS |
3934 VNIC_TPA_CFG_REQ_ENABLES_MIN_AGG_LEN);
Michael Chanc0c050c2015-10-22 16:01:17 -04003935
3936 /* Number of segs are log2 units, and first packet is not
3937 * included as part of this units.
3938 */
Michael Chan2839f282016-04-25 02:30:50 -04003939 if (mss <= BNXT_RX_PAGE_SIZE) {
3940 n = BNXT_RX_PAGE_SIZE / mss;
Michael Chanc0c050c2015-10-22 16:01:17 -04003941 nsegs = (MAX_SKB_FRAGS - 1) * n;
3942 } else {
Michael Chan2839f282016-04-25 02:30:50 -04003943 n = mss / BNXT_RX_PAGE_SIZE;
3944 if (mss & (BNXT_RX_PAGE_SIZE - 1))
Michael Chanc0c050c2015-10-22 16:01:17 -04003945 n++;
3946 nsegs = (MAX_SKB_FRAGS - n) / n;
3947 }
3948
3949 segs = ilog2(nsegs);
3950 req.max_agg_segs = cpu_to_le16(segs);
3951 req.max_aggs = cpu_to_le16(VNIC_TPA_CFG_REQ_MAX_AGGS_MAX);
Michael Chanc1935542015-12-27 18:19:28 -05003952
3953 req.min_agg_len = cpu_to_le32(512);
Michael Chanc0c050c2015-10-22 16:01:17 -04003954 }
3955 req.vnic_id = cpu_to_le16(vnic->fw_vnic_id);
3956
3957 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3958}
3959
3960static int bnxt_hwrm_vnic_set_rss(struct bnxt *bp, u16 vnic_id, bool set_rss)
3961{
3962 u32 i, j, max_rings;
3963 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
3964 struct hwrm_vnic_rss_cfg_input req = {0};
3965
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04003966 if (vnic->fw_rss_cos_lb_ctx[0] == INVALID_HW_RING_ID)
Michael Chanc0c050c2015-10-22 16:01:17 -04003967 return 0;
3968
3969 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_CFG, -1, -1);
3970 if (set_rss) {
Michael Chan87da7f72016-11-16 21:13:09 -05003971 req.hash_type = cpu_to_le32(bp->rss_hash_cfg);
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04003972 if (vnic->flags & BNXT_VNIC_RSS_FLAG) {
3973 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
3974 max_rings = bp->rx_nr_rings - 1;
3975 else
3976 max_rings = bp->rx_nr_rings;
3977 } else {
Michael Chanc0c050c2015-10-22 16:01:17 -04003978 max_rings = 1;
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04003979 }
Michael Chanc0c050c2015-10-22 16:01:17 -04003980
3981 /* Fill the RSS indirection table with ring group ids */
3982 for (i = 0, j = 0; i < HW_HASH_INDEX_SIZE; i++, j++) {
3983 if (j == max_rings)
3984 j = 0;
3985 vnic->rss_table[i] = cpu_to_le16(vnic->fw_grp_ids[j]);
3986 }
3987
3988 req.ring_grp_tbl_addr = cpu_to_le64(vnic->rss_table_dma_addr);
3989 req.hash_key_tbl_addr =
3990 cpu_to_le64(vnic->rss_hash_key_dma_addr);
3991 }
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04003992 req.rss_ctx_idx = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[0]);
Michael Chanc0c050c2015-10-22 16:01:17 -04003993 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3994}
3995
3996static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, u16 vnic_id)
3997{
3998 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
3999 struct hwrm_vnic_plcmodes_cfg_input req = {0};
4000
4001 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_PLCMODES_CFG, -1, -1);
4002 req.flags = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT |
4003 VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV4 |
4004 VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6);
4005 req.enables =
4006 cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID |
4007 VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID);
4008 /* thresholds not implemented in firmware yet */
4009 req.jumbo_thresh = cpu_to_le16(bp->rx_copy_thresh);
4010 req.hds_threshold = cpu_to_le16(bp->rx_copy_thresh);
4011 req.vnic_id = cpu_to_le32(vnic->fw_vnic_id);
4012 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4013}
4014
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004015static void bnxt_hwrm_vnic_ctx_free_one(struct bnxt *bp, u16 vnic_id,
4016 u16 ctx_idx)
Michael Chanc0c050c2015-10-22 16:01:17 -04004017{
4018 struct hwrm_vnic_rss_cos_lb_ctx_free_input req = {0};
4019
4020 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_COS_LB_CTX_FREE, -1, -1);
4021 req.rss_cos_lb_ctx_id =
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004022 cpu_to_le16(bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx]);
Michael Chanc0c050c2015-10-22 16:01:17 -04004023
4024 hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004025 bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx] = INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04004026}
4027
4028static void bnxt_hwrm_vnic_ctx_free(struct bnxt *bp)
4029{
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004030 int i, j;
Michael Chanc0c050c2015-10-22 16:01:17 -04004031
4032 for (i = 0; i < bp->nr_vnics; i++) {
4033 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
4034
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004035 for (j = 0; j < BNXT_MAX_CTX_PER_VNIC; j++) {
4036 if (vnic->fw_rss_cos_lb_ctx[j] != INVALID_HW_RING_ID)
4037 bnxt_hwrm_vnic_ctx_free_one(bp, i, j);
4038 }
Michael Chanc0c050c2015-10-22 16:01:17 -04004039 }
4040 bp->rsscos_nr_ctxs = 0;
4041}
4042
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004043static int bnxt_hwrm_vnic_ctx_alloc(struct bnxt *bp, u16 vnic_id, u16 ctx_idx)
Michael Chanc0c050c2015-10-22 16:01:17 -04004044{
4045 int rc;
4046 struct hwrm_vnic_rss_cos_lb_ctx_alloc_input req = {0};
4047 struct hwrm_vnic_rss_cos_lb_ctx_alloc_output *resp =
4048 bp->hwrm_cmd_resp_addr;
4049
4050 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_COS_LB_CTX_ALLOC, -1,
4051 -1);
4052
4053 mutex_lock(&bp->hwrm_cmd_lock);
4054 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4055 if (!rc)
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004056 bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx] =
Michael Chanc0c050c2015-10-22 16:01:17 -04004057 le16_to_cpu(resp->rss_cos_lb_ctx_id);
4058 mutex_unlock(&bp->hwrm_cmd_lock);
4059
4060 return rc;
4061}
4062
Michael Chanabe93ad2018-03-31 13:54:08 -04004063static u32 bnxt_get_roce_vnic_mode(struct bnxt *bp)
4064{
4065 if (bp->flags & BNXT_FLAG_ROCE_MIRROR_CAP)
4066 return VNIC_CFG_REQ_FLAGS_ROCE_MIRRORING_CAPABLE_VNIC_MODE;
4067 return VNIC_CFG_REQ_FLAGS_ROCE_DUAL_VNIC_MODE;
4068}
4069
Michael Chana588e452016-12-07 00:26:21 -05004070int bnxt_hwrm_vnic_cfg(struct bnxt *bp, u16 vnic_id)
Michael Chanc0c050c2015-10-22 16:01:17 -04004071{
Michael Chanb81a90d2016-01-02 23:45:01 -05004072 unsigned int ring = 0, grp_idx;
Michael Chanc0c050c2015-10-22 16:01:17 -04004073 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
4074 struct hwrm_vnic_cfg_input req = {0};
Michael Chancf6645f2016-06-13 02:25:28 -04004075 u16 def_vlan = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04004076
4077 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_CFG, -1, -1);
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004078
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04004079 req.enables = cpu_to_le32(VNIC_CFG_REQ_ENABLES_DFLT_RING_GRP);
4080 /* Only RSS support for now TBD: COS & LB */
4081 if (vnic->fw_rss_cos_lb_ctx[0] != INVALID_HW_RING_ID) {
4082 req.rss_rule = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[0]);
4083 req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE |
4084 VNIC_CFG_REQ_ENABLES_MRU);
Michael Chanae10ae72016-12-29 12:13:38 -05004085 } else if (vnic->flags & BNXT_VNIC_RFS_NEW_RSS_FLAG) {
4086 req.rss_rule =
4087 cpu_to_le16(bp->vnic_info[0].fw_rss_cos_lb_ctx[0]);
4088 req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE |
4089 VNIC_CFG_REQ_ENABLES_MRU);
4090 req.flags |= cpu_to_le32(VNIC_CFG_REQ_FLAGS_RSS_DFLT_CR_MODE);
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04004091 } else {
4092 req.rss_rule = cpu_to_le16(0xffff);
4093 }
4094
4095 if (BNXT_CHIP_TYPE_NITRO_A0(bp) &&
4096 (vnic->fw_rss_cos_lb_ctx[0] != INVALID_HW_RING_ID)) {
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004097 req.cos_rule = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[1]);
4098 req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_COS_RULE);
4099 } else {
4100 req.cos_rule = cpu_to_le16(0xffff);
4101 }
4102
Michael Chanc0c050c2015-10-22 16:01:17 -04004103 if (vnic->flags & BNXT_VNIC_RSS_FLAG)
Michael Chanb81a90d2016-01-02 23:45:01 -05004104 ring = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04004105 else if (vnic->flags & BNXT_VNIC_RFS_FLAG)
Michael Chanb81a90d2016-01-02 23:45:01 -05004106 ring = vnic_id - 1;
Prashant Sreedharan76595192016-07-18 07:15:22 -04004107 else if ((vnic_id == 1) && BNXT_CHIP_TYPE_NITRO_A0(bp))
4108 ring = bp->rx_nr_rings - 1;
Michael Chanc0c050c2015-10-22 16:01:17 -04004109
Michael Chanb81a90d2016-01-02 23:45:01 -05004110 grp_idx = bp->rx_ring[ring].bnapi->index;
Michael Chanc0c050c2015-10-22 16:01:17 -04004111 req.vnic_id = cpu_to_le16(vnic->fw_vnic_id);
4112 req.dflt_ring_grp = cpu_to_le16(bp->grp_info[grp_idx].fw_grp_id);
4113
4114 req.lb_rule = cpu_to_le16(0xffff);
4115 req.mru = cpu_to_le16(bp->dev->mtu + ETH_HLEN + ETH_FCS_LEN +
4116 VLAN_HLEN);
4117
Michael Chancf6645f2016-06-13 02:25:28 -04004118#ifdef CONFIG_BNXT_SRIOV
4119 if (BNXT_VF(bp))
4120 def_vlan = bp->vf.vlan;
4121#endif
4122 if ((bp->flags & BNXT_FLAG_STRIP_VLAN) || def_vlan)
Michael Chanc0c050c2015-10-22 16:01:17 -04004123 req.flags |= cpu_to_le32(VNIC_CFG_REQ_FLAGS_VLAN_STRIP_MODE);
Michael Chana588e452016-12-07 00:26:21 -05004124 if (!vnic_id && bnxt_ulp_registered(bp->edev, BNXT_ROCE_ULP))
Michael Chanabe93ad2018-03-31 13:54:08 -04004125 req.flags |= cpu_to_le32(bnxt_get_roce_vnic_mode(bp));
Michael Chanc0c050c2015-10-22 16:01:17 -04004126
4127 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4128}
4129
4130static int bnxt_hwrm_vnic_free_one(struct bnxt *bp, u16 vnic_id)
4131{
4132 u32 rc = 0;
4133
4134 if (bp->vnic_info[vnic_id].fw_vnic_id != INVALID_HW_RING_ID) {
4135 struct hwrm_vnic_free_input req = {0};
4136
4137 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_FREE, -1, -1);
4138 req.vnic_id =
4139 cpu_to_le32(bp->vnic_info[vnic_id].fw_vnic_id);
4140
4141 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4142 if (rc)
4143 return rc;
4144 bp->vnic_info[vnic_id].fw_vnic_id = INVALID_HW_RING_ID;
4145 }
4146 return rc;
4147}
4148
4149static void bnxt_hwrm_vnic_free(struct bnxt *bp)
4150{
4151 u16 i;
4152
4153 for (i = 0; i < bp->nr_vnics; i++)
4154 bnxt_hwrm_vnic_free_one(bp, i);
4155}
4156
Michael Chanb81a90d2016-01-02 23:45:01 -05004157static int bnxt_hwrm_vnic_alloc(struct bnxt *bp, u16 vnic_id,
4158 unsigned int start_rx_ring_idx,
4159 unsigned int nr_rings)
Michael Chanc0c050c2015-10-22 16:01:17 -04004160{
Michael Chanb81a90d2016-01-02 23:45:01 -05004161 int rc = 0;
4162 unsigned int i, j, grp_idx, end_idx = start_rx_ring_idx + nr_rings;
Michael Chanc0c050c2015-10-22 16:01:17 -04004163 struct hwrm_vnic_alloc_input req = {0};
4164 struct hwrm_vnic_alloc_output *resp = bp->hwrm_cmd_resp_addr;
4165
4166 /* map ring groups to this vnic */
Michael Chanb81a90d2016-01-02 23:45:01 -05004167 for (i = start_rx_ring_idx, j = 0; i < end_idx; i++, j++) {
4168 grp_idx = bp->rx_ring[i].bnapi->index;
4169 if (bp->grp_info[grp_idx].fw_grp_id == INVALID_HW_RING_ID) {
Michael Chanc0c050c2015-10-22 16:01:17 -04004170 netdev_err(bp->dev, "Not enough ring groups avail:%x req:%x\n",
Michael Chanb81a90d2016-01-02 23:45:01 -05004171 j, nr_rings);
Michael Chanc0c050c2015-10-22 16:01:17 -04004172 break;
4173 }
4174 bp->vnic_info[vnic_id].fw_grp_ids[j] =
Michael Chanb81a90d2016-01-02 23:45:01 -05004175 bp->grp_info[grp_idx].fw_grp_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04004176 }
4177
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004178 bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[0] = INVALID_HW_RING_ID;
4179 bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[1] = INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04004180 if (vnic_id == 0)
4181 req.flags = cpu_to_le32(VNIC_ALLOC_REQ_FLAGS_DEFAULT);
4182
4183 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_ALLOC, -1, -1);
4184
4185 mutex_lock(&bp->hwrm_cmd_lock);
4186 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4187 if (!rc)
4188 bp->vnic_info[vnic_id].fw_vnic_id = le32_to_cpu(resp->vnic_id);
4189 mutex_unlock(&bp->hwrm_cmd_lock);
4190 return rc;
4191}
4192
Michael Chan8fdefd62016-12-29 12:13:36 -05004193static int bnxt_hwrm_vnic_qcaps(struct bnxt *bp)
4194{
4195 struct hwrm_vnic_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
4196 struct hwrm_vnic_qcaps_input req = {0};
4197 int rc;
4198
4199 if (bp->hwrm_spec_code < 0x10600)
4200 return 0;
4201
4202 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_QCAPS, -1, -1);
4203 mutex_lock(&bp->hwrm_cmd_lock);
4204 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4205 if (!rc) {
Michael Chanabe93ad2018-03-31 13:54:08 -04004206 u32 flags = le32_to_cpu(resp->flags);
4207
4208 if (flags & VNIC_QCAPS_RESP_FLAGS_RSS_DFLT_CR_CAP)
Michael Chan8fdefd62016-12-29 12:13:36 -05004209 bp->flags |= BNXT_FLAG_NEW_RSS_CAP;
Michael Chanabe93ad2018-03-31 13:54:08 -04004210 if (flags &
4211 VNIC_QCAPS_RESP_FLAGS_ROCE_MIRRORING_CAPABLE_VNIC_CAP)
4212 bp->flags |= BNXT_FLAG_ROCE_MIRROR_CAP;
Michael Chan8fdefd62016-12-29 12:13:36 -05004213 }
4214 mutex_unlock(&bp->hwrm_cmd_lock);
4215 return rc;
4216}
4217
Michael Chanc0c050c2015-10-22 16:01:17 -04004218static int bnxt_hwrm_ring_grp_alloc(struct bnxt *bp)
4219{
4220 u16 i;
4221 u32 rc = 0;
4222
4223 mutex_lock(&bp->hwrm_cmd_lock);
4224 for (i = 0; i < bp->rx_nr_rings; i++) {
4225 struct hwrm_ring_grp_alloc_input req = {0};
4226 struct hwrm_ring_grp_alloc_output *resp =
4227 bp->hwrm_cmd_resp_addr;
Michael Chanb81a90d2016-01-02 23:45:01 -05004228 unsigned int grp_idx = bp->rx_ring[i].bnapi->index;
Michael Chanc0c050c2015-10-22 16:01:17 -04004229
4230 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_GRP_ALLOC, -1, -1);
4231
Michael Chanb81a90d2016-01-02 23:45:01 -05004232 req.cr = cpu_to_le16(bp->grp_info[grp_idx].cp_fw_ring_id);
4233 req.rr = cpu_to_le16(bp->grp_info[grp_idx].rx_fw_ring_id);
4234 req.ar = cpu_to_le16(bp->grp_info[grp_idx].agg_fw_ring_id);
4235 req.sc = cpu_to_le16(bp->grp_info[grp_idx].fw_stats_ctx);
Michael Chanc0c050c2015-10-22 16:01:17 -04004236
4237 rc = _hwrm_send_message(bp, &req, sizeof(req),
4238 HWRM_CMD_TIMEOUT);
4239 if (rc)
4240 break;
4241
Michael Chanb81a90d2016-01-02 23:45:01 -05004242 bp->grp_info[grp_idx].fw_grp_id =
4243 le32_to_cpu(resp->ring_group_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04004244 }
4245 mutex_unlock(&bp->hwrm_cmd_lock);
4246 return rc;
4247}
4248
4249static int bnxt_hwrm_ring_grp_free(struct bnxt *bp)
4250{
4251 u16 i;
4252 u32 rc = 0;
4253 struct hwrm_ring_grp_free_input req = {0};
4254
4255 if (!bp->grp_info)
4256 return 0;
4257
4258 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_GRP_FREE, -1, -1);
4259
4260 mutex_lock(&bp->hwrm_cmd_lock);
4261 for (i = 0; i < bp->cp_nr_rings; i++) {
4262 if (bp->grp_info[i].fw_grp_id == INVALID_HW_RING_ID)
4263 continue;
4264 req.ring_group_id =
4265 cpu_to_le32(bp->grp_info[i].fw_grp_id);
4266
4267 rc = _hwrm_send_message(bp, &req, sizeof(req),
4268 HWRM_CMD_TIMEOUT);
4269 if (rc)
4270 break;
4271 bp->grp_info[i].fw_grp_id = INVALID_HW_RING_ID;
4272 }
4273 mutex_unlock(&bp->hwrm_cmd_lock);
4274 return rc;
4275}
4276
4277static int hwrm_ring_alloc_send_msg(struct bnxt *bp,
4278 struct bnxt_ring_struct *ring,
Michael Chan9899bb52018-03-31 13:54:16 -04004279 u32 ring_type, u32 map_index)
Michael Chanc0c050c2015-10-22 16:01:17 -04004280{
4281 int rc = 0, err = 0;
4282 struct hwrm_ring_alloc_input req = {0};
4283 struct hwrm_ring_alloc_output *resp = bp->hwrm_cmd_resp_addr;
Michael Chan9899bb52018-03-31 13:54:16 -04004284 struct bnxt_ring_grp_info *grp_info;
Michael Chanc0c050c2015-10-22 16:01:17 -04004285 u16 ring_id;
4286
4287 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_ALLOC, -1, -1);
4288
4289 req.enables = 0;
4290 if (ring->nr_pages > 1) {
4291 req.page_tbl_addr = cpu_to_le64(ring->pg_tbl_map);
4292 /* Page size is in log2 units */
4293 req.page_size = BNXT_PAGE_SHIFT;
4294 req.page_tbl_depth = 1;
4295 } else {
4296 req.page_tbl_addr = cpu_to_le64(ring->dma_arr[0]);
4297 }
4298 req.fbo = 0;
4299 /* Association of ring index with doorbell index and MSIX number */
4300 req.logical_id = cpu_to_le16(map_index);
4301
4302 switch (ring_type) {
4303 case HWRM_RING_ALLOC_TX:
4304 req.ring_type = RING_ALLOC_REQ_RING_TYPE_TX;
4305 /* Association of transmit ring with completion ring */
Michael Chan9899bb52018-03-31 13:54:16 -04004306 grp_info = &bp->grp_info[ring->grp_idx];
4307 req.cmpl_ring_id = cpu_to_le16(grp_info->cp_fw_ring_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04004308 req.length = cpu_to_le32(bp->tx_ring_mask + 1);
Michael Chan9899bb52018-03-31 13:54:16 -04004309 req.stat_ctx_id = cpu_to_le32(grp_info->fw_stats_ctx);
Michael Chanc0c050c2015-10-22 16:01:17 -04004310 req.queue_id = cpu_to_le16(ring->queue_id);
4311 break;
4312 case HWRM_RING_ALLOC_RX:
4313 req.ring_type = RING_ALLOC_REQ_RING_TYPE_RX;
4314 req.length = cpu_to_le32(bp->rx_ring_mask + 1);
4315 break;
4316 case HWRM_RING_ALLOC_AGG:
4317 req.ring_type = RING_ALLOC_REQ_RING_TYPE_RX;
4318 req.length = cpu_to_le32(bp->rx_agg_ring_mask + 1);
4319 break;
4320 case HWRM_RING_ALLOC_CMPL:
Michael Chanbac9a7e2017-02-12 19:18:10 -05004321 req.ring_type = RING_ALLOC_REQ_RING_TYPE_L2_CMPL;
Michael Chanc0c050c2015-10-22 16:01:17 -04004322 req.length = cpu_to_le32(bp->cp_ring_mask + 1);
4323 if (bp->flags & BNXT_FLAG_USING_MSIX)
4324 req.int_mode = RING_ALLOC_REQ_INT_MODE_MSIX;
4325 break;
4326 default:
4327 netdev_err(bp->dev, "hwrm alloc invalid ring type %d\n",
4328 ring_type);
4329 return -1;
4330 }
4331
4332 mutex_lock(&bp->hwrm_cmd_lock);
4333 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4334 err = le16_to_cpu(resp->error_code);
4335 ring_id = le16_to_cpu(resp->ring_id);
4336 mutex_unlock(&bp->hwrm_cmd_lock);
4337
4338 if (rc || err) {
Michael Chan2727c882018-04-26 17:44:35 -04004339 netdev_err(bp->dev, "hwrm_ring_alloc type %d failed. rc:%x err:%x\n",
4340 ring_type, rc, err);
4341 return -EIO;
Michael Chanc0c050c2015-10-22 16:01:17 -04004342 }
4343 ring->fw_ring_id = ring_id;
4344 return rc;
4345}
4346
Michael Chan486b5c22016-12-29 12:13:42 -05004347static int bnxt_hwrm_set_async_event_cr(struct bnxt *bp, int idx)
4348{
4349 int rc;
4350
4351 if (BNXT_PF(bp)) {
4352 struct hwrm_func_cfg_input req = {0};
4353
4354 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1);
4355 req.fid = cpu_to_le16(0xffff);
4356 req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_ASYNC_EVENT_CR);
4357 req.async_event_cr = cpu_to_le16(idx);
4358 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4359 } else {
4360 struct hwrm_func_vf_cfg_input req = {0};
4361
4362 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_VF_CFG, -1, -1);
4363 req.enables =
4364 cpu_to_le32(FUNC_VF_CFG_REQ_ENABLES_ASYNC_EVENT_CR);
4365 req.async_event_cr = cpu_to_le16(idx);
4366 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4367 }
4368 return rc;
4369}
4370
Michael Chanc0c050c2015-10-22 16:01:17 -04004371static int bnxt_hwrm_ring_alloc(struct bnxt *bp)
4372{
4373 int i, rc = 0;
4374
Michael Chanedd0c2c2015-12-27 18:19:19 -05004375 for (i = 0; i < bp->cp_nr_rings; i++) {
4376 struct bnxt_napi *bnapi = bp->bnapi[i];
4377 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
4378 struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
Michael Chan9899bb52018-03-31 13:54:16 -04004379 u32 map_idx = ring->map_idx;
Michael Chanc0c050c2015-10-22 16:01:17 -04004380
Michael Chan9899bb52018-03-31 13:54:16 -04004381 cpr->cp_doorbell = bp->bar1 + map_idx * 0x80;
4382 rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_CMPL,
4383 map_idx);
Michael Chanedd0c2c2015-12-27 18:19:19 -05004384 if (rc)
4385 goto err_out;
Michael Chanedd0c2c2015-12-27 18:19:19 -05004386 BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
4387 bp->grp_info[i].cp_fw_ring_id = ring->fw_ring_id;
Michael Chan486b5c22016-12-29 12:13:42 -05004388
4389 if (!i) {
4390 rc = bnxt_hwrm_set_async_event_cr(bp, ring->fw_ring_id);
4391 if (rc)
4392 netdev_warn(bp->dev, "Failed to set async event completion ring.\n");
4393 }
Michael Chanc0c050c2015-10-22 16:01:17 -04004394 }
4395
Michael Chanedd0c2c2015-12-27 18:19:19 -05004396 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05004397 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
Michael Chanedd0c2c2015-12-27 18:19:19 -05004398 struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
Michael Chan9899bb52018-03-31 13:54:16 -04004399 u32 map_idx = i;
Michael Chanc0c050c2015-10-22 16:01:17 -04004400
Michael Chanb81a90d2016-01-02 23:45:01 -05004401 rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_TX,
Michael Chan9899bb52018-03-31 13:54:16 -04004402 map_idx);
Michael Chanedd0c2c2015-12-27 18:19:19 -05004403 if (rc)
4404 goto err_out;
Michael Chanb81a90d2016-01-02 23:45:01 -05004405 txr->tx_doorbell = bp->bar1 + map_idx * 0x80;
Michael Chanc0c050c2015-10-22 16:01:17 -04004406 }
4407
Michael Chanedd0c2c2015-12-27 18:19:19 -05004408 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05004409 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
Michael Chanedd0c2c2015-12-27 18:19:19 -05004410 struct bnxt_ring_struct *ring = &rxr->rx_ring_struct;
Michael Chanb81a90d2016-01-02 23:45:01 -05004411 u32 map_idx = rxr->bnapi->index;
Michael Chanc0c050c2015-10-22 16:01:17 -04004412
Michael Chanb81a90d2016-01-02 23:45:01 -05004413 rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_RX,
Michael Chan9899bb52018-03-31 13:54:16 -04004414 map_idx);
Michael Chanedd0c2c2015-12-27 18:19:19 -05004415 if (rc)
4416 goto err_out;
Michael Chanb81a90d2016-01-02 23:45:01 -05004417 rxr->rx_doorbell = bp->bar1 + map_idx * 0x80;
Michael Chanedd0c2c2015-12-27 18:19:19 -05004418 writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell);
Michael Chanb81a90d2016-01-02 23:45:01 -05004419 bp->grp_info[map_idx].rx_fw_ring_id = ring->fw_ring_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04004420 }
4421
4422 if (bp->flags & BNXT_FLAG_AGG_RINGS) {
4423 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 Chanc0c050c2015-10-22 16:01:17 -04004425 struct bnxt_ring_struct *ring =
4426 &rxr->rx_agg_ring_struct;
Michael Chan9899bb52018-03-31 13:54:16 -04004427 u32 grp_idx = ring->grp_idx;
Michael Chanb81a90d2016-01-02 23:45:01 -05004428 u32 map_idx = grp_idx + bp->rx_nr_rings;
Michael Chanc0c050c2015-10-22 16:01:17 -04004429
4430 rc = hwrm_ring_alloc_send_msg(bp, ring,
4431 HWRM_RING_ALLOC_AGG,
Michael Chan9899bb52018-03-31 13:54:16 -04004432 map_idx);
Michael Chanc0c050c2015-10-22 16:01:17 -04004433 if (rc)
4434 goto err_out;
4435
Michael Chanb81a90d2016-01-02 23:45:01 -05004436 rxr->rx_agg_doorbell = bp->bar1 + map_idx * 0x80;
Michael Chanc0c050c2015-10-22 16:01:17 -04004437 writel(DB_KEY_RX | rxr->rx_agg_prod,
4438 rxr->rx_agg_doorbell);
Michael Chanb81a90d2016-01-02 23:45:01 -05004439 bp->grp_info[grp_idx].agg_fw_ring_id = ring->fw_ring_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04004440 }
4441 }
4442err_out:
4443 return rc;
4444}
4445
4446static int hwrm_ring_free_send_msg(struct bnxt *bp,
4447 struct bnxt_ring_struct *ring,
4448 u32 ring_type, int cmpl_ring_id)
4449{
4450 int rc;
4451 struct hwrm_ring_free_input req = {0};
4452 struct hwrm_ring_free_output *resp = bp->hwrm_cmd_resp_addr;
4453 u16 error_code;
4454
Prashant Sreedharan74608fc2016-01-28 03:11:20 -05004455 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_FREE, cmpl_ring_id, -1);
Michael Chanc0c050c2015-10-22 16:01:17 -04004456 req.ring_type = ring_type;
4457 req.ring_id = cpu_to_le16(ring->fw_ring_id);
4458
4459 mutex_lock(&bp->hwrm_cmd_lock);
4460 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4461 error_code = le16_to_cpu(resp->error_code);
4462 mutex_unlock(&bp->hwrm_cmd_lock);
4463
4464 if (rc || error_code) {
Michael Chan2727c882018-04-26 17:44:35 -04004465 netdev_err(bp->dev, "hwrm_ring_free type %d failed. rc:%x err:%x\n",
4466 ring_type, rc, error_code);
4467 return -EIO;
Michael Chanc0c050c2015-10-22 16:01:17 -04004468 }
4469 return 0;
4470}
4471
Michael Chanedd0c2c2015-12-27 18:19:19 -05004472static void bnxt_hwrm_ring_free(struct bnxt *bp, bool close_path)
Michael Chanc0c050c2015-10-22 16:01:17 -04004473{
Michael Chanedd0c2c2015-12-27 18:19:19 -05004474 int i;
Michael Chanc0c050c2015-10-22 16:01:17 -04004475
4476 if (!bp->bnapi)
Michael Chanedd0c2c2015-12-27 18:19:19 -05004477 return;
Michael Chanc0c050c2015-10-22 16:01:17 -04004478
Michael Chanedd0c2c2015-12-27 18:19:19 -05004479 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05004480 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
Michael Chanedd0c2c2015-12-27 18:19:19 -05004481 struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
Michael Chanb81a90d2016-01-02 23:45:01 -05004482 u32 grp_idx = txr->bnapi->index;
4483 u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04004484
Michael Chanedd0c2c2015-12-27 18:19:19 -05004485 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
4486 hwrm_ring_free_send_msg(bp, ring,
4487 RING_FREE_REQ_RING_TYPE_TX,
4488 close_path ? cmpl_ring_id :
4489 INVALID_HW_RING_ID);
4490 ring->fw_ring_id = INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04004491 }
4492 }
4493
Michael Chanedd0c2c2015-12-27 18:19:19 -05004494 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05004495 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
Michael Chanedd0c2c2015-12-27 18:19:19 -05004496 struct bnxt_ring_struct *ring = &rxr->rx_ring_struct;
Michael Chanb81a90d2016-01-02 23:45:01 -05004497 u32 grp_idx = rxr->bnapi->index;
4498 u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04004499
Michael Chanedd0c2c2015-12-27 18:19:19 -05004500 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
4501 hwrm_ring_free_send_msg(bp, ring,
4502 RING_FREE_REQ_RING_TYPE_RX,
4503 close_path ? cmpl_ring_id :
4504 INVALID_HW_RING_ID);
4505 ring->fw_ring_id = INVALID_HW_RING_ID;
Michael Chanb81a90d2016-01-02 23:45:01 -05004506 bp->grp_info[grp_idx].rx_fw_ring_id =
4507 INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04004508 }
4509 }
4510
Michael Chanedd0c2c2015-12-27 18:19:19 -05004511 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05004512 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
Michael Chanedd0c2c2015-12-27 18:19:19 -05004513 struct bnxt_ring_struct *ring = &rxr->rx_agg_ring_struct;
Michael Chanb81a90d2016-01-02 23:45:01 -05004514 u32 grp_idx = rxr->bnapi->index;
4515 u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04004516
Michael Chanedd0c2c2015-12-27 18:19:19 -05004517 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
4518 hwrm_ring_free_send_msg(bp, ring,
4519 RING_FREE_REQ_RING_TYPE_RX,
4520 close_path ? cmpl_ring_id :
4521 INVALID_HW_RING_ID);
4522 ring->fw_ring_id = INVALID_HW_RING_ID;
Michael Chanb81a90d2016-01-02 23:45:01 -05004523 bp->grp_info[grp_idx].agg_fw_ring_id =
4524 INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04004525 }
4526 }
4527
Michael Chan9d8bc092016-12-29 12:13:33 -05004528 /* The completion rings are about to be freed. After that the
4529 * IRQ doorbell will not work anymore. So we need to disable
4530 * IRQ here.
4531 */
4532 bnxt_disable_int_sync(bp);
4533
Michael Chanedd0c2c2015-12-27 18:19:19 -05004534 for (i = 0; i < bp->cp_nr_rings; i++) {
4535 struct bnxt_napi *bnapi = bp->bnapi[i];
4536 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
4537 struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
Michael Chanc0c050c2015-10-22 16:01:17 -04004538
Michael Chanedd0c2c2015-12-27 18:19:19 -05004539 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
4540 hwrm_ring_free_send_msg(bp, ring,
Michael Chanbac9a7e2017-02-12 19:18:10 -05004541 RING_FREE_REQ_RING_TYPE_L2_CMPL,
Michael Chanedd0c2c2015-12-27 18:19:19 -05004542 INVALID_HW_RING_ID);
4543 ring->fw_ring_id = INVALID_HW_RING_ID;
4544 bp->grp_info[i].cp_fw_ring_id = INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04004545 }
4546 }
Michael Chanc0c050c2015-10-22 16:01:17 -04004547}
4548
Michael Chan674f50a2018-01-17 03:21:09 -05004549static int bnxt_hwrm_get_rings(struct bnxt *bp)
4550{
4551 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
4552 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
4553 struct hwrm_func_qcfg_input req = {0};
4554 int rc;
4555
4556 if (bp->hwrm_spec_code < 0x10601)
4557 return 0;
4558
4559 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCFG, -1, -1);
4560 req.fid = cpu_to_le16(0xffff);
4561 mutex_lock(&bp->hwrm_cmd_lock);
4562 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4563 if (rc) {
4564 mutex_unlock(&bp->hwrm_cmd_lock);
4565 return -EIO;
4566 }
4567
4568 hw_resc->resv_tx_rings = le16_to_cpu(resp->alloc_tx_rings);
4569 if (bp->flags & BNXT_FLAG_NEW_RM) {
4570 u16 cp, stats;
4571
4572 hw_resc->resv_rx_rings = le16_to_cpu(resp->alloc_rx_rings);
4573 hw_resc->resv_hw_ring_grps =
4574 le32_to_cpu(resp->alloc_hw_ring_grps);
4575 hw_resc->resv_vnics = le16_to_cpu(resp->alloc_vnics);
4576 cp = le16_to_cpu(resp->alloc_cmpl_rings);
4577 stats = le16_to_cpu(resp->alloc_stat_ctx);
4578 cp = min_t(u16, cp, stats);
4579 hw_resc->resv_cp_rings = cp;
4580 }
4581 mutex_unlock(&bp->hwrm_cmd_lock);
4582 return 0;
4583}
4584
Michael Chan391be5c2016-12-29 12:13:41 -05004585/* Caller must hold bp->hwrm_cmd_lock */
4586int __bnxt_hwrm_get_tx_rings(struct bnxt *bp, u16 fid, int *tx_rings)
4587{
4588 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
4589 struct hwrm_func_qcfg_input req = {0};
4590 int rc;
4591
4592 if (bp->hwrm_spec_code < 0x10601)
4593 return 0;
4594
4595 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCFG, -1, -1);
4596 req.fid = cpu_to_le16(fid);
4597 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4598 if (!rc)
4599 *tx_rings = le16_to_cpu(resp->alloc_tx_rings);
4600
4601 return rc;
4602}
4603
Michael Chan4ed50ef2018-03-09 23:46:03 -05004604static void
4605__bnxt_hwrm_reserve_pf_rings(struct bnxt *bp, struct hwrm_func_cfg_input *req,
4606 int tx_rings, int rx_rings, int ring_grps,
4607 int cp_rings, int vnics)
Michael Chan391be5c2016-12-29 12:13:41 -05004608{
Michael Chan674f50a2018-01-17 03:21:09 -05004609 u32 enables = 0;
Michael Chan391be5c2016-12-29 12:13:41 -05004610
Michael Chan4ed50ef2018-03-09 23:46:03 -05004611 bnxt_hwrm_cmd_hdr_init(bp, req, HWRM_FUNC_CFG, -1, -1);
4612 req->fid = cpu_to_le16(0xffff);
Michael Chan674f50a2018-01-17 03:21:09 -05004613 enables |= tx_rings ? FUNC_CFG_REQ_ENABLES_NUM_TX_RINGS : 0;
Michael Chan4ed50ef2018-03-09 23:46:03 -05004614 req->num_tx_rings = cpu_to_le16(tx_rings);
Michael Chan674f50a2018-01-17 03:21:09 -05004615 if (bp->flags & BNXT_FLAG_NEW_RM) {
4616 enables |= rx_rings ? FUNC_CFG_REQ_ENABLES_NUM_RX_RINGS : 0;
4617 enables |= cp_rings ? FUNC_CFG_REQ_ENABLES_NUM_CMPL_RINGS |
4618 FUNC_CFG_REQ_ENABLES_NUM_STAT_CTXS : 0;
4619 enables |= ring_grps ?
4620 FUNC_CFG_REQ_ENABLES_NUM_HW_RING_GRPS : 0;
4621 enables |= vnics ? FUNC_VF_CFG_REQ_ENABLES_NUM_VNICS : 0;
4622
Michael Chan4ed50ef2018-03-09 23:46:03 -05004623 req->num_rx_rings = cpu_to_le16(rx_rings);
4624 req->num_hw_ring_grps = cpu_to_le16(ring_grps);
4625 req->num_cmpl_rings = cpu_to_le16(cp_rings);
4626 req->num_stat_ctxs = req->num_cmpl_rings;
4627 req->num_vnics = cpu_to_le16(vnics);
Michael Chan674f50a2018-01-17 03:21:09 -05004628 }
Michael Chan4ed50ef2018-03-09 23:46:03 -05004629 req->enables = cpu_to_le32(enables);
4630}
4631
4632static void
4633__bnxt_hwrm_reserve_vf_rings(struct bnxt *bp,
4634 struct hwrm_func_vf_cfg_input *req, int tx_rings,
4635 int rx_rings, int ring_grps, int cp_rings,
4636 int vnics)
4637{
4638 u32 enables = 0;
4639
4640 bnxt_hwrm_cmd_hdr_init(bp, req, HWRM_FUNC_VF_CFG, -1, -1);
4641 enables |= tx_rings ? FUNC_VF_CFG_REQ_ENABLES_NUM_TX_RINGS : 0;
4642 enables |= rx_rings ? FUNC_VF_CFG_REQ_ENABLES_NUM_RX_RINGS : 0;
4643 enables |= cp_rings ? FUNC_VF_CFG_REQ_ENABLES_NUM_CMPL_RINGS |
4644 FUNC_VF_CFG_REQ_ENABLES_NUM_STAT_CTXS : 0;
4645 enables |= ring_grps ? FUNC_VF_CFG_REQ_ENABLES_NUM_HW_RING_GRPS : 0;
4646 enables |= vnics ? FUNC_VF_CFG_REQ_ENABLES_NUM_VNICS : 0;
4647
4648 req->num_tx_rings = cpu_to_le16(tx_rings);
4649 req->num_rx_rings = cpu_to_le16(rx_rings);
4650 req->num_hw_ring_grps = cpu_to_le16(ring_grps);
4651 req->num_cmpl_rings = cpu_to_le16(cp_rings);
4652 req->num_stat_ctxs = req->num_cmpl_rings;
4653 req->num_vnics = cpu_to_le16(vnics);
4654
4655 req->enables = cpu_to_le32(enables);
4656}
4657
4658static int
4659bnxt_hwrm_reserve_pf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
4660 int ring_grps, int cp_rings, int vnics)
4661{
4662 struct hwrm_func_cfg_input req = {0};
4663 int rc;
4664
4665 __bnxt_hwrm_reserve_pf_rings(bp, &req, tx_rings, rx_rings, ring_grps,
4666 cp_rings, vnics);
4667 if (!req.enables)
Michael Chan674f50a2018-01-17 03:21:09 -05004668 return 0;
4669
Michael Chan674f50a2018-01-17 03:21:09 -05004670 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4671 if (rc)
4672 return -ENOMEM;
4673
4674 if (bp->hwrm_spec_code < 0x10601)
4675 bp->hw_resc.resv_tx_rings = tx_rings;
4676
4677 rc = bnxt_hwrm_get_rings(bp);
4678 return rc;
4679}
4680
4681static int
4682bnxt_hwrm_reserve_vf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
4683 int ring_grps, int cp_rings, int vnics)
4684{
4685 struct hwrm_func_vf_cfg_input req = {0};
Michael Chan674f50a2018-01-17 03:21:09 -05004686 int rc;
4687
4688 if (!(bp->flags & BNXT_FLAG_NEW_RM)) {
4689 bp->hw_resc.resv_tx_rings = tx_rings;
4690 return 0;
4691 }
4692
Michael Chan4ed50ef2018-03-09 23:46:03 -05004693 __bnxt_hwrm_reserve_vf_rings(bp, &req, tx_rings, rx_rings, ring_grps,
4694 cp_rings, vnics);
Michael Chan674f50a2018-01-17 03:21:09 -05004695 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4696 if (rc)
4697 return -ENOMEM;
4698
4699 rc = bnxt_hwrm_get_rings(bp);
4700 return rc;
4701}
4702
4703static int bnxt_hwrm_reserve_rings(struct bnxt *bp, int tx, int rx, int grp,
4704 int cp, int vnic)
4705{
4706 if (BNXT_PF(bp))
4707 return bnxt_hwrm_reserve_pf_rings(bp, tx, rx, grp, cp, vnic);
4708 else
4709 return bnxt_hwrm_reserve_vf_rings(bp, tx, rx, grp, cp, vnic);
4710}
4711
Michael Chan08654eb2018-03-31 13:54:17 -04004712static int bnxt_cp_rings_in_use(struct bnxt *bp)
4713{
4714 int cp = bp->cp_nr_rings;
4715 int ulp_msix, ulp_base;
4716
4717 ulp_msix = bnxt_get_ulp_msix_num(bp);
4718 if (ulp_msix) {
4719 ulp_base = bnxt_get_ulp_msix_base(bp);
4720 cp += ulp_msix;
4721 if ((ulp_base + ulp_msix) > cp)
4722 cp = ulp_base + ulp_msix;
4723 }
4724 return cp;
4725}
4726
Michael Chan4e41dc52018-03-31 13:54:19 -04004727static bool bnxt_need_reserve_rings(struct bnxt *bp)
4728{
4729 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
Michael Chanfbcfc8e2018-03-31 13:54:20 -04004730 int cp = bnxt_cp_rings_in_use(bp);
Michael Chan4e41dc52018-03-31 13:54:19 -04004731 int rx = bp->rx_nr_rings;
4732 int vnic = 1, grp = rx;
4733
4734 if (bp->hwrm_spec_code < 0x10601)
4735 return false;
4736
4737 if (hw_resc->resv_tx_rings != bp->tx_nr_rings)
4738 return true;
4739
4740 if (bp->flags & BNXT_FLAG_RFS)
4741 vnic = rx + 1;
4742 if (bp->flags & BNXT_FLAG_AGG_RINGS)
4743 rx <<= 1;
4744 if ((bp->flags & BNXT_FLAG_NEW_RM) &&
4745 (hw_resc->resv_rx_rings != rx || hw_resc->resv_cp_rings != cp ||
4746 hw_resc->resv_hw_ring_grps != grp || hw_resc->resv_vnics != vnic))
4747 return true;
4748 return false;
4749}
4750
Michael Chan674f50a2018-01-17 03:21:09 -05004751static int bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max,
4752 bool shared);
4753
4754static int __bnxt_reserve_rings(struct bnxt *bp)
4755{
4756 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
Michael Chanfbcfc8e2018-03-31 13:54:20 -04004757 int cp = bnxt_cp_rings_in_use(bp);
Michael Chan674f50a2018-01-17 03:21:09 -05004758 int tx = bp->tx_nr_rings;
4759 int rx = bp->rx_nr_rings;
Michael Chan674f50a2018-01-17 03:21:09 -05004760 int grp, rx_rings, rc;
4761 bool sh = false;
4762 int vnic = 1;
4763
Michael Chan4e41dc52018-03-31 13:54:19 -04004764 if (!bnxt_need_reserve_rings(bp))
Michael Chan391be5c2016-12-29 12:13:41 -05004765 return 0;
4766
Michael Chan674f50a2018-01-17 03:21:09 -05004767 if (bp->flags & BNXT_FLAG_SHARED_RINGS)
4768 sh = true;
4769 if (bp->flags & BNXT_FLAG_RFS)
4770 vnic = rx + 1;
4771 if (bp->flags & BNXT_FLAG_AGG_RINGS)
4772 rx <<= 1;
Michael Chan674f50a2018-01-17 03:21:09 -05004773 grp = bp->rx_nr_rings;
Michael Chan391be5c2016-12-29 12:13:41 -05004774
Michael Chan674f50a2018-01-17 03:21:09 -05004775 rc = bnxt_hwrm_reserve_rings(bp, tx, rx, grp, cp, vnic);
Michael Chan391be5c2016-12-29 12:13:41 -05004776 if (rc)
4777 return rc;
4778
Michael Chan674f50a2018-01-17 03:21:09 -05004779 tx = hw_resc->resv_tx_rings;
4780 if (bp->flags & BNXT_FLAG_NEW_RM) {
4781 rx = hw_resc->resv_rx_rings;
4782 cp = hw_resc->resv_cp_rings;
4783 grp = hw_resc->resv_hw_ring_grps;
4784 vnic = hw_resc->resv_vnics;
4785 }
4786
4787 rx_rings = rx;
4788 if (bp->flags & BNXT_FLAG_AGG_RINGS) {
4789 if (rx >= 2) {
4790 rx_rings = rx >> 1;
4791 } else {
4792 if (netif_running(bp->dev))
4793 return -ENOMEM;
4794
4795 bp->flags &= ~BNXT_FLAG_AGG_RINGS;
4796 bp->flags |= BNXT_FLAG_NO_AGG_RINGS;
4797 bp->dev->hw_features &= ~NETIF_F_LRO;
4798 bp->dev->features &= ~NETIF_F_LRO;
4799 bnxt_set_ring_params(bp);
4800 }
4801 }
4802 rx_rings = min_t(int, rx_rings, grp);
4803 rc = bnxt_trim_rings(bp, &rx_rings, &tx, cp, sh);
4804 if (bp->flags & BNXT_FLAG_AGG_RINGS)
4805 rx = rx_rings << 1;
4806 cp = sh ? max_t(int, tx, rx_rings) : tx + rx_rings;
4807 bp->tx_nr_rings = tx;
4808 bp->rx_nr_rings = rx_rings;
4809 bp->cp_nr_rings = cp;
4810
4811 if (!tx || !rx || !cp || !grp || !vnic)
4812 return -ENOMEM;
4813
Michael Chan391be5c2016-12-29 12:13:41 -05004814 return rc;
4815}
4816
Michael Chan8f23d632018-01-17 03:21:12 -05004817static int bnxt_hwrm_check_vf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004818 int ring_grps, int cp_rings, int vnics)
Michael Chan98fdbe72017-08-28 13:40:26 -04004819{
Michael Chan8f23d632018-01-17 03:21:12 -05004820 struct hwrm_func_vf_cfg_input req = {0};
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004821 u32 flags;
Michael Chan98fdbe72017-08-28 13:40:26 -04004822 int rc;
4823
Michael Chan8f23d632018-01-17 03:21:12 -05004824 if (!(bp->flags & BNXT_FLAG_NEW_RM))
Michael Chan98fdbe72017-08-28 13:40:26 -04004825 return 0;
4826
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004827 __bnxt_hwrm_reserve_vf_rings(bp, &req, tx_rings, rx_rings, ring_grps,
4828 cp_rings, vnics);
Michael Chan8f23d632018-01-17 03:21:12 -05004829 flags = FUNC_VF_CFG_REQ_FLAGS_TX_ASSETS_TEST |
4830 FUNC_VF_CFG_REQ_FLAGS_RX_ASSETS_TEST |
4831 FUNC_VF_CFG_REQ_FLAGS_CMPL_ASSETS_TEST |
4832 FUNC_VF_CFG_REQ_FLAGS_RING_GRP_ASSETS_TEST |
4833 FUNC_VF_CFG_REQ_FLAGS_STAT_CTX_ASSETS_TEST |
4834 FUNC_VF_CFG_REQ_FLAGS_VNIC_ASSETS_TEST;
Michael Chan98fdbe72017-08-28 13:40:26 -04004835
Michael Chan8f23d632018-01-17 03:21:12 -05004836 req.flags = cpu_to_le32(flags);
Michael Chan98fdbe72017-08-28 13:40:26 -04004837 rc = hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4838 if (rc)
4839 return -ENOMEM;
4840 return 0;
4841}
4842
Michael Chan8f23d632018-01-17 03:21:12 -05004843static int bnxt_hwrm_check_pf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004844 int ring_grps, int cp_rings, int vnics)
Michael Chan8f23d632018-01-17 03:21:12 -05004845{
4846 struct hwrm_func_cfg_input req = {0};
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004847 u32 flags;
Michael Chan8f23d632018-01-17 03:21:12 -05004848 int rc;
4849
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004850 __bnxt_hwrm_reserve_pf_rings(bp, &req, tx_rings, rx_rings, ring_grps,
4851 cp_rings, vnics);
Michael Chan8f23d632018-01-17 03:21:12 -05004852 flags = FUNC_CFG_REQ_FLAGS_TX_ASSETS_TEST;
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004853 if (bp->flags & BNXT_FLAG_NEW_RM)
Michael Chan8f23d632018-01-17 03:21:12 -05004854 flags |= FUNC_CFG_REQ_FLAGS_RX_ASSETS_TEST |
4855 FUNC_CFG_REQ_FLAGS_CMPL_ASSETS_TEST |
4856 FUNC_CFG_REQ_FLAGS_RING_GRP_ASSETS_TEST |
4857 FUNC_CFG_REQ_FLAGS_STAT_CTX_ASSETS_TEST |
4858 FUNC_CFG_REQ_FLAGS_VNIC_ASSETS_TEST;
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004859
Michael Chan8f23d632018-01-17 03:21:12 -05004860 req.flags = cpu_to_le32(flags);
Michael Chan8f23d632018-01-17 03:21:12 -05004861 rc = hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4862 if (rc)
4863 return -ENOMEM;
4864 return 0;
4865}
4866
4867static int bnxt_hwrm_check_rings(struct bnxt *bp, int tx_rings, int rx_rings,
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004868 int ring_grps, int cp_rings, int vnics)
Michael Chan8f23d632018-01-17 03:21:12 -05004869{
4870 if (bp->hwrm_spec_code < 0x10801)
4871 return 0;
4872
4873 if (BNXT_PF(bp))
4874 return bnxt_hwrm_check_pf_rings(bp, tx_rings, rx_rings,
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004875 ring_grps, cp_rings, vnics);
Michael Chan8f23d632018-01-17 03:21:12 -05004876
4877 return bnxt_hwrm_check_vf_rings(bp, tx_rings, rx_rings, ring_grps,
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004878 cp_rings, vnics);
Michael Chan8f23d632018-01-17 03:21:12 -05004879}
4880
Michael Chanf8503962017-10-26 11:51:28 -04004881static void bnxt_hwrm_set_coal_params(struct bnxt_coal *hw_coal,
Michael Chanbb053f52016-02-26 04:00:02 -05004882 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *req)
4883{
Michael Chanf8503962017-10-26 11:51:28 -04004884 u16 val, tmr, max, flags;
4885
4886 max = hw_coal->bufs_per_record * 128;
4887 if (hw_coal->budget)
4888 max = hw_coal->bufs_per_record * hw_coal->budget;
4889
4890 val = clamp_t(u16, hw_coal->coal_bufs, 1, max);
4891 req->num_cmpl_aggr_int = cpu_to_le16(val);
Michael Chanb153cbc2017-11-03 03:32:39 -04004892
4893 /* This is a 6-bit value and must not be 0, or we'll get non stop IRQ */
4894 val = min_t(u16, val, 63);
Michael Chanf8503962017-10-26 11:51:28 -04004895 req->num_cmpl_dma_aggr = cpu_to_le16(val);
4896
Michael Chanb153cbc2017-11-03 03:32:39 -04004897 /* This is a 6-bit value and must not be 0, or we'll get non stop IRQ */
4898 val = clamp_t(u16, hw_coal->coal_bufs_irq, 1, 63);
Michael Chanf8503962017-10-26 11:51:28 -04004899 req->num_cmpl_dma_aggr_during_int = cpu_to_le16(val);
4900
4901 tmr = BNXT_USEC_TO_COAL_TIMER(hw_coal->coal_ticks);
4902 tmr = max_t(u16, tmr, 1);
4903 req->int_lat_tmr_max = cpu_to_le16(tmr);
4904
4905 /* min timer set to 1/2 of interrupt timer */
4906 val = tmr / 2;
4907 req->int_lat_tmr_min = cpu_to_le16(val);
4908
4909 /* buf timer set to 1/4 of interrupt timer */
4910 val = max_t(u16, tmr / 4, 1);
4911 req->cmpl_aggr_dma_tmr = cpu_to_le16(val);
4912
4913 tmr = BNXT_USEC_TO_COAL_TIMER(hw_coal->coal_ticks_irq);
4914 tmr = max_t(u16, tmr, 1);
4915 req->cmpl_aggr_dma_tmr_during_int = cpu_to_le16(tmr);
4916
4917 flags = RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_TIMER_RESET;
4918 if (hw_coal->idle_thresh && hw_coal->coal_ticks < hw_coal->idle_thresh)
4919 flags |= RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_RING_IDLE;
Michael Chanbb053f52016-02-26 04:00:02 -05004920 req->flags = cpu_to_le16(flags);
Michael Chanbb053f52016-02-26 04:00:02 -05004921}
4922
Andy Gospodarek6a8788f2018-01-09 16:06:20 -05004923int bnxt_hwrm_set_ring_coal(struct bnxt *bp, struct bnxt_napi *bnapi)
4924{
4925 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req_rx = {0};
4926 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
4927 struct bnxt_coal coal;
4928 unsigned int grp_idx;
4929
4930 /* Tick values in micro seconds.
4931 * 1 coal_buf x bufs_per_record = 1 completion record.
4932 */
4933 memcpy(&coal, &bp->rx_coal, sizeof(struct bnxt_coal));
4934
4935 coal.coal_ticks = cpr->rx_ring_coal.coal_ticks;
4936 coal.coal_bufs = cpr->rx_ring_coal.coal_bufs;
4937
4938 if (!bnapi->rx_ring)
4939 return -ENODEV;
4940
4941 bnxt_hwrm_cmd_hdr_init(bp, &req_rx,
4942 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1);
4943
4944 bnxt_hwrm_set_coal_params(&coal, &req_rx);
4945
4946 grp_idx = bnapi->index;
4947 req_rx.ring_id = cpu_to_le16(bp->grp_info[grp_idx].cp_fw_ring_id);
4948
4949 return hwrm_send_message(bp, &req_rx, sizeof(req_rx),
4950 HWRM_CMD_TIMEOUT);
4951}
4952
Michael Chanc0c050c2015-10-22 16:01:17 -04004953int bnxt_hwrm_set_coal(struct bnxt *bp)
4954{
4955 int i, rc = 0;
Michael Chandfc9c942016-02-26 04:00:03 -05004956 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req_rx = {0},
4957 req_tx = {0}, *req;
Michael Chanc0c050c2015-10-22 16:01:17 -04004958
Michael Chandfc9c942016-02-26 04:00:03 -05004959 bnxt_hwrm_cmd_hdr_init(bp, &req_rx,
4960 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1);
4961 bnxt_hwrm_cmd_hdr_init(bp, &req_tx,
4962 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1);
Michael Chanc0c050c2015-10-22 16:01:17 -04004963
Michael Chanf8503962017-10-26 11:51:28 -04004964 bnxt_hwrm_set_coal_params(&bp->rx_coal, &req_rx);
4965 bnxt_hwrm_set_coal_params(&bp->tx_coal, &req_tx);
Michael Chanc0c050c2015-10-22 16:01:17 -04004966
4967 mutex_lock(&bp->hwrm_cmd_lock);
4968 for (i = 0; i < bp->cp_nr_rings; i++) {
Michael Chandfc9c942016-02-26 04:00:03 -05004969 struct bnxt_napi *bnapi = bp->bnapi[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04004970
Michael Chandfc9c942016-02-26 04:00:03 -05004971 req = &req_rx;
4972 if (!bnapi->rx_ring)
4973 req = &req_tx;
4974 req->ring_id = cpu_to_le16(bp->grp_info[i].cp_fw_ring_id);
4975
4976 rc = _hwrm_send_message(bp, req, sizeof(*req),
Michael Chanc0c050c2015-10-22 16:01:17 -04004977 HWRM_CMD_TIMEOUT);
4978 if (rc)
4979 break;
4980 }
4981 mutex_unlock(&bp->hwrm_cmd_lock);
4982 return rc;
4983}
4984
4985static int bnxt_hwrm_stat_ctx_free(struct bnxt *bp)
4986{
4987 int rc = 0, i;
4988 struct hwrm_stat_ctx_free_input req = {0};
4989
4990 if (!bp->bnapi)
4991 return 0;
4992
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04004993 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
4994 return 0;
4995
Michael Chanc0c050c2015-10-22 16:01:17 -04004996 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_STAT_CTX_FREE, -1, -1);
4997
4998 mutex_lock(&bp->hwrm_cmd_lock);
4999 for (i = 0; i < bp->cp_nr_rings; i++) {
5000 struct bnxt_napi *bnapi = bp->bnapi[i];
5001 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
5002
5003 if (cpr->hw_stats_ctx_id != INVALID_STATS_CTX_ID) {
5004 req.stat_ctx_id = cpu_to_le32(cpr->hw_stats_ctx_id);
5005
5006 rc = _hwrm_send_message(bp, &req, sizeof(req),
5007 HWRM_CMD_TIMEOUT);
5008 if (rc)
5009 break;
5010
5011 cpr->hw_stats_ctx_id = INVALID_STATS_CTX_ID;
5012 }
5013 }
5014 mutex_unlock(&bp->hwrm_cmd_lock);
5015 return rc;
5016}
5017
5018static int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp)
5019{
5020 int rc = 0, i;
5021 struct hwrm_stat_ctx_alloc_input req = {0};
5022 struct hwrm_stat_ctx_alloc_output *resp = bp->hwrm_cmd_resp_addr;
5023
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04005024 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
5025 return 0;
5026
Michael Chanc0c050c2015-10-22 16:01:17 -04005027 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_STAT_CTX_ALLOC, -1, -1);
5028
Michael Chan51f30782016-07-01 18:46:29 -04005029 req.update_period_ms = cpu_to_le32(bp->stats_coal_ticks / 1000);
Michael Chanc0c050c2015-10-22 16:01:17 -04005030
5031 mutex_lock(&bp->hwrm_cmd_lock);
5032 for (i = 0; i < bp->cp_nr_rings; i++) {
5033 struct bnxt_napi *bnapi = bp->bnapi[i];
5034 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
5035
5036 req.stats_dma_addr = cpu_to_le64(cpr->hw_stats_map);
5037
5038 rc = _hwrm_send_message(bp, &req, sizeof(req),
5039 HWRM_CMD_TIMEOUT);
5040 if (rc)
5041 break;
5042
5043 cpr->hw_stats_ctx_id = le32_to_cpu(resp->stat_ctx_id);
5044
5045 bp->grp_info[i].fw_stats_ctx = cpr->hw_stats_ctx_id;
5046 }
5047 mutex_unlock(&bp->hwrm_cmd_lock);
Pan Bian89aa8442016-12-03 17:56:17 +08005048 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04005049}
5050
Michael Chancf6645f2016-06-13 02:25:28 -04005051static int bnxt_hwrm_func_qcfg(struct bnxt *bp)
5052{
5053 struct hwrm_func_qcfg_input req = {0};
Satish Baddipadige567b2ab2016-06-13 02:25:31 -04005054 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
Michael Chan9315edc2017-07-24 12:34:25 -04005055 u16 flags;
Michael Chancf6645f2016-06-13 02:25:28 -04005056 int rc;
5057
5058 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCFG, -1, -1);
5059 req.fid = cpu_to_le16(0xffff);
5060 mutex_lock(&bp->hwrm_cmd_lock);
5061 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5062 if (rc)
5063 goto func_qcfg_exit;
5064
5065#ifdef CONFIG_BNXT_SRIOV
5066 if (BNXT_VF(bp)) {
Michael Chancf6645f2016-06-13 02:25:28 -04005067 struct bnxt_vf_info *vf = &bp->vf;
5068
5069 vf->vlan = le16_to_cpu(resp->vlan) & VLAN_VID_MASK;
5070 }
5071#endif
Michael Chan9315edc2017-07-24 12:34:25 -04005072 flags = le16_to_cpu(resp->flags);
5073 if (flags & (FUNC_QCFG_RESP_FLAGS_FW_DCBX_AGENT_ENABLED |
5074 FUNC_QCFG_RESP_FLAGS_FW_LLDP_AGENT_ENABLED)) {
5075 bp->flags |= BNXT_FLAG_FW_LLDP_AGENT;
5076 if (flags & FUNC_QCFG_RESP_FLAGS_FW_DCBX_AGENT_ENABLED)
5077 bp->flags |= BNXT_FLAG_FW_DCBX_AGENT;
Deepak Khungar9e54e322017-04-21 20:11:26 -04005078 }
Michael Chan9315edc2017-07-24 12:34:25 -04005079 if (BNXT_PF(bp) && (flags & FUNC_QCFG_RESP_FLAGS_MULTI_HOST))
5080 bp->flags |= BNXT_FLAG_MULTI_HOST;
Michael Chanbc39f882017-03-08 18:44:34 -05005081
Satish Baddipadige567b2ab2016-06-13 02:25:31 -04005082 switch (resp->port_partition_type) {
5083 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_0:
5084 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_5:
5085 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR2_0:
5086 bp->port_partition_type = resp->port_partition_type;
5087 break;
5088 }
Michael Chan32e8239c2017-07-24 12:34:21 -04005089 if (bp->hwrm_spec_code < 0x10707 ||
5090 resp->evb_mode == FUNC_QCFG_RESP_EVB_MODE_VEB)
5091 bp->br_mode = BRIDGE_MODE_VEB;
5092 else if (resp->evb_mode == FUNC_QCFG_RESP_EVB_MODE_VEPA)
5093 bp->br_mode = BRIDGE_MODE_VEPA;
5094 else
5095 bp->br_mode = BRIDGE_MODE_UNDEF;
Michael Chancf6645f2016-06-13 02:25:28 -04005096
Michael Chan7eb9bb32017-10-26 11:51:25 -04005097 bp->max_mtu = le16_to_cpu(resp->max_mtu_configured);
5098 if (!bp->max_mtu)
5099 bp->max_mtu = BNXT_MAX_MTU;
5100
Michael Chancf6645f2016-06-13 02:25:28 -04005101func_qcfg_exit:
5102 mutex_unlock(&bp->hwrm_cmd_lock);
5103 return rc;
5104}
5105
Michael Chandb4723b2018-03-31 13:54:13 -04005106int bnxt_hwrm_func_resc_qcaps(struct bnxt *bp, bool all)
Michael Chanbe0dd9c2018-01-17 03:21:07 -05005107{
5108 struct hwrm_func_resource_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
5109 struct hwrm_func_resource_qcaps_input req = {0};
5110 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
5111 int rc;
5112
5113 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_RESOURCE_QCAPS, -1, -1);
5114 req.fid = cpu_to_le16(0xffff);
5115
5116 mutex_lock(&bp->hwrm_cmd_lock);
5117 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5118 if (rc) {
5119 rc = -EIO;
5120 goto hwrm_func_resc_qcaps_exit;
5121 }
5122
Michael Chandb4723b2018-03-31 13:54:13 -04005123 hw_resc->max_tx_sch_inputs = le16_to_cpu(resp->max_tx_scheduler_inputs);
5124 if (!all)
5125 goto hwrm_func_resc_qcaps_exit;
5126
Michael Chanbe0dd9c2018-01-17 03:21:07 -05005127 hw_resc->min_rsscos_ctxs = le16_to_cpu(resp->min_rsscos_ctx);
5128 hw_resc->max_rsscos_ctxs = le16_to_cpu(resp->max_rsscos_ctx);
5129 hw_resc->min_cp_rings = le16_to_cpu(resp->min_cmpl_rings);
5130 hw_resc->max_cp_rings = le16_to_cpu(resp->max_cmpl_rings);
5131 hw_resc->min_tx_rings = le16_to_cpu(resp->min_tx_rings);
5132 hw_resc->max_tx_rings = le16_to_cpu(resp->max_tx_rings);
5133 hw_resc->min_rx_rings = le16_to_cpu(resp->min_rx_rings);
5134 hw_resc->max_rx_rings = le16_to_cpu(resp->max_rx_rings);
5135 hw_resc->min_hw_ring_grps = le16_to_cpu(resp->min_hw_ring_grps);
5136 hw_resc->max_hw_ring_grps = le16_to_cpu(resp->max_hw_ring_grps);
5137 hw_resc->min_l2_ctxs = le16_to_cpu(resp->min_l2_ctxs);
5138 hw_resc->max_l2_ctxs = le16_to_cpu(resp->max_l2_ctxs);
5139 hw_resc->min_vnics = le16_to_cpu(resp->min_vnics);
5140 hw_resc->max_vnics = le16_to_cpu(resp->max_vnics);
5141 hw_resc->min_stat_ctxs = le16_to_cpu(resp->min_stat_ctx);
5142 hw_resc->max_stat_ctxs = le16_to_cpu(resp->max_stat_ctx);
5143
Michael Chan4673d662018-01-17 03:21:11 -05005144 if (BNXT_PF(bp)) {
5145 struct bnxt_pf_info *pf = &bp->pf;
5146
5147 pf->vf_resv_strategy =
5148 le16_to_cpu(resp->vf_reservation_strategy);
5149 if (pf->vf_resv_strategy > BNXT_VF_RESV_STRATEGY_MINIMAL)
5150 pf->vf_resv_strategy = BNXT_VF_RESV_STRATEGY_MAXIMAL;
5151 }
Michael Chanbe0dd9c2018-01-17 03:21:07 -05005152hwrm_func_resc_qcaps_exit:
5153 mutex_unlock(&bp->hwrm_cmd_lock);
5154 return rc;
5155}
5156
5157static int __bnxt_hwrm_func_qcaps(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04005158{
5159 int rc = 0;
5160 struct hwrm_func_qcaps_input req = {0};
5161 struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
Michael Chan6a4f2942018-01-17 03:21:06 -05005162 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
5163 u32 flags;
Michael Chanc0c050c2015-10-22 16:01:17 -04005164
5165 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCAPS, -1, -1);
5166 req.fid = cpu_to_le16(0xffff);
5167
5168 mutex_lock(&bp->hwrm_cmd_lock);
5169 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5170 if (rc)
5171 goto hwrm_func_qcaps_exit;
5172
Michael Chan6a4f2942018-01-17 03:21:06 -05005173 flags = le32_to_cpu(resp->flags);
5174 if (flags & FUNC_QCAPS_RESP_FLAGS_ROCE_V1_SUPPORTED)
Michael Chane4060d32016-12-07 00:26:19 -05005175 bp->flags |= BNXT_FLAG_ROCEV1_CAP;
Michael Chan6a4f2942018-01-17 03:21:06 -05005176 if (flags & FUNC_QCAPS_RESP_FLAGS_ROCE_V2_SUPPORTED)
Michael Chane4060d32016-12-07 00:26:19 -05005177 bp->flags |= BNXT_FLAG_ROCEV2_CAP;
5178
Michael Chan7cc5a202016-09-19 03:58:05 -04005179 bp->tx_push_thresh = 0;
Michael Chan6a4f2942018-01-17 03:21:06 -05005180 if (flags & FUNC_QCAPS_RESP_FLAGS_PUSH_MODE_SUPPORTED)
Michael Chan7cc5a202016-09-19 03:58:05 -04005181 bp->tx_push_thresh = BNXT_TX_PUSH_THRESH;
5182
Michael Chan6a4f2942018-01-17 03:21:06 -05005183 hw_resc->max_rsscos_ctxs = le16_to_cpu(resp->max_rsscos_ctx);
5184 hw_resc->max_cp_rings = le16_to_cpu(resp->max_cmpl_rings);
5185 hw_resc->max_tx_rings = le16_to_cpu(resp->max_tx_rings);
5186 hw_resc->max_rx_rings = le16_to_cpu(resp->max_rx_rings);
5187 hw_resc->max_hw_ring_grps = le32_to_cpu(resp->max_hw_ring_grps);
5188 if (!hw_resc->max_hw_ring_grps)
5189 hw_resc->max_hw_ring_grps = hw_resc->max_tx_rings;
5190 hw_resc->max_l2_ctxs = le16_to_cpu(resp->max_l2_ctxs);
5191 hw_resc->max_vnics = le16_to_cpu(resp->max_vnics);
5192 hw_resc->max_stat_ctxs = le16_to_cpu(resp->max_stat_ctx);
5193
Michael Chanc0c050c2015-10-22 16:01:17 -04005194 if (BNXT_PF(bp)) {
5195 struct bnxt_pf_info *pf = &bp->pf;
5196
5197 pf->fw_fid = le16_to_cpu(resp->fid);
5198 pf->port_id = le16_to_cpu(resp->port_id);
Michael Chan87027db2016-07-01 18:46:28 -04005199 bp->dev->dev_port = pf->port_id;
Michael Chan11f15ed2016-04-05 14:08:55 -04005200 memcpy(pf->mac_addr, resp->mac_address, ETH_ALEN);
Michael Chanc0c050c2015-10-22 16:01:17 -04005201 pf->first_vf_id = le16_to_cpu(resp->first_vf_id);
5202 pf->max_vfs = le16_to_cpu(resp->max_vfs);
5203 pf->max_encap_records = le32_to_cpu(resp->max_encap_records);
5204 pf->max_decap_records = le32_to_cpu(resp->max_decap_records);
5205 pf->max_tx_em_flows = le32_to_cpu(resp->max_tx_em_flows);
5206 pf->max_tx_wm_flows = le32_to_cpu(resp->max_tx_wm_flows);
5207 pf->max_rx_em_flows = le32_to_cpu(resp->max_rx_em_flows);
5208 pf->max_rx_wm_flows = le32_to_cpu(resp->max_rx_wm_flows);
Michael Chan6a4f2942018-01-17 03:21:06 -05005209 if (flags & FUNC_QCAPS_RESP_FLAGS_WOL_MAGICPKT_SUPPORTED)
Michael Chanc1ef1462017-04-04 18:14:07 -04005210 bp->flags |= BNXT_FLAG_WOL_CAP;
Michael Chanc0c050c2015-10-22 16:01:17 -04005211 } else {
Michael Chan379a80a2015-10-23 15:06:19 -04005212#ifdef CONFIG_BNXT_SRIOV
Michael Chanc0c050c2015-10-22 16:01:17 -04005213 struct bnxt_vf_info *vf = &bp->vf;
5214
5215 vf->fw_fid = le16_to_cpu(resp->fid);
Michael Chan7cc5a202016-09-19 03:58:05 -04005216 memcpy(vf->mac_addr, resp->mac_address, ETH_ALEN);
Michael Chan379a80a2015-10-23 15:06:19 -04005217#endif
Michael Chanc0c050c2015-10-22 16:01:17 -04005218 }
5219
Michael Chanc0c050c2015-10-22 16:01:17 -04005220hwrm_func_qcaps_exit:
5221 mutex_unlock(&bp->hwrm_cmd_lock);
5222 return rc;
5223}
5224
Michael Chanbe0dd9c2018-01-17 03:21:07 -05005225static int bnxt_hwrm_func_qcaps(struct bnxt *bp)
5226{
5227 int rc;
5228
5229 rc = __bnxt_hwrm_func_qcaps(bp);
5230 if (rc)
5231 return rc;
5232 if (bp->hwrm_spec_code >= 0x10803) {
Michael Chandb4723b2018-03-31 13:54:13 -04005233 rc = bnxt_hwrm_func_resc_qcaps(bp, true);
Michael Chanbe0dd9c2018-01-17 03:21:07 -05005234 if (!rc)
5235 bp->flags |= BNXT_FLAG_NEW_RM;
5236 }
5237 return 0;
5238}
5239
Michael Chanc0c050c2015-10-22 16:01:17 -04005240static int bnxt_hwrm_func_reset(struct bnxt *bp)
5241{
5242 struct hwrm_func_reset_input req = {0};
5243
5244 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_RESET, -1, -1);
5245 req.enables = 0;
5246
5247 return hwrm_send_message(bp, &req, sizeof(req), HWRM_RESET_TIMEOUT);
5248}
5249
5250static int bnxt_hwrm_queue_qportcfg(struct bnxt *bp)
5251{
5252 int rc = 0;
5253 struct hwrm_queue_qportcfg_input req = {0};
5254 struct hwrm_queue_qportcfg_output *resp = bp->hwrm_cmd_resp_addr;
5255 u8 i, *qptr;
5256
5257 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_QUEUE_QPORTCFG, -1, -1);
5258
5259 mutex_lock(&bp->hwrm_cmd_lock);
5260 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5261 if (rc)
5262 goto qportcfg_exit;
5263
5264 if (!resp->max_configurable_queues) {
5265 rc = -EINVAL;
5266 goto qportcfg_exit;
5267 }
5268 bp->max_tc = resp->max_configurable_queues;
Michael Chan87c374d2016-12-02 21:17:16 -05005269 bp->max_lltc = resp->max_configurable_lossless_queues;
Michael Chanc0c050c2015-10-22 16:01:17 -04005270 if (bp->max_tc > BNXT_MAX_QUEUE)
5271 bp->max_tc = BNXT_MAX_QUEUE;
5272
Michael Chan441cabb2016-09-19 03:58:02 -04005273 if (resp->queue_cfg_info & QUEUE_QPORTCFG_RESP_QUEUE_CFG_INFO_ASYM_CFG)
5274 bp->max_tc = 1;
5275
Michael Chan87c374d2016-12-02 21:17:16 -05005276 if (bp->max_lltc > bp->max_tc)
5277 bp->max_lltc = bp->max_tc;
5278
Michael Chanc0c050c2015-10-22 16:01:17 -04005279 qptr = &resp->queue_id0;
5280 for (i = 0; i < bp->max_tc; i++) {
5281 bp->q_info[i].queue_id = *qptr++;
5282 bp->q_info[i].queue_profile = *qptr++;
Michael Chan2e8ef772018-04-26 17:44:31 -04005283 bp->tc_to_qidx[i] = i;
Michael Chanc0c050c2015-10-22 16:01:17 -04005284 }
5285
5286qportcfg_exit:
5287 mutex_unlock(&bp->hwrm_cmd_lock);
5288 return rc;
5289}
5290
5291static int bnxt_hwrm_ver_get(struct bnxt *bp)
5292{
5293 int rc;
5294 struct hwrm_ver_get_input req = {0};
5295 struct hwrm_ver_get_output *resp = bp->hwrm_cmd_resp_addr;
Deepak Khungare605db82017-05-29 19:06:04 -04005296 u32 dev_caps_cfg;
Michael Chanc0c050c2015-10-22 16:01:17 -04005297
Michael Chane6ef2692016-03-28 19:46:05 -04005298 bp->hwrm_max_req_len = HWRM_MAX_REQ_LEN;
Michael Chanc0c050c2015-10-22 16:01:17 -04005299 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VER_GET, -1, -1);
5300 req.hwrm_intf_maj = HWRM_VERSION_MAJOR;
5301 req.hwrm_intf_min = HWRM_VERSION_MINOR;
5302 req.hwrm_intf_upd = HWRM_VERSION_UPDATE;
5303 mutex_lock(&bp->hwrm_cmd_lock);
5304 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5305 if (rc)
5306 goto hwrm_ver_get_exit;
5307
5308 memcpy(&bp->ver_resp, resp, sizeof(struct hwrm_ver_get_output));
5309
Michael Chan894aa692018-01-17 03:21:03 -05005310 bp->hwrm_spec_code = resp->hwrm_intf_maj_8b << 16 |
5311 resp->hwrm_intf_min_8b << 8 |
5312 resp->hwrm_intf_upd_8b;
5313 if (resp->hwrm_intf_maj_8b < 1) {
Michael Chanc1935542015-12-27 18:19:28 -05005314 netdev_warn(bp->dev, "HWRM interface %d.%d.%d is older than 1.0.0.\n",
Michael Chan894aa692018-01-17 03:21:03 -05005315 resp->hwrm_intf_maj_8b, resp->hwrm_intf_min_8b,
5316 resp->hwrm_intf_upd_8b);
Michael Chanc1935542015-12-27 18:19:28 -05005317 netdev_warn(bp->dev, "Please update firmware with HWRM interface 1.0.0 or newer.\n");
Michael Chanc0c050c2015-10-22 16:01:17 -04005318 }
Michael Chan431aa1e2017-10-26 11:51:23 -04005319 snprintf(bp->fw_ver_str, BC_HWRM_STR_LEN, "%d.%d.%d.%d",
Michael Chan894aa692018-01-17 03:21:03 -05005320 resp->hwrm_fw_maj_8b, resp->hwrm_fw_min_8b,
5321 resp->hwrm_fw_bld_8b, resp->hwrm_fw_rsvd_8b);
Michael Chanc0c050c2015-10-22 16:01:17 -04005322
Michael Chanff4fe812016-02-26 04:00:04 -05005323 bp->hwrm_cmd_timeout = le16_to_cpu(resp->def_req_timeout);
5324 if (!bp->hwrm_cmd_timeout)
5325 bp->hwrm_cmd_timeout = DFLT_HWRM_CMD_TIMEOUT;
5326
Michael Chan894aa692018-01-17 03:21:03 -05005327 if (resp->hwrm_intf_maj_8b >= 1)
Michael Chane6ef2692016-03-28 19:46:05 -04005328 bp->hwrm_max_req_len = le16_to_cpu(resp->max_req_win_len);
5329
Michael Chan659c8052016-06-13 02:25:33 -04005330 bp->chip_num = le16_to_cpu(resp->chip_num);
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04005331 if (bp->chip_num == CHIP_NUM_58700 && !resp->chip_rev &&
5332 !resp->chip_metal)
5333 bp->flags |= BNXT_FLAG_CHIP_NITRO_A0;
Michael Chan659c8052016-06-13 02:25:33 -04005334
Deepak Khungare605db82017-05-29 19:06:04 -04005335 dev_caps_cfg = le32_to_cpu(resp->dev_caps_cfg);
5336 if ((dev_caps_cfg & VER_GET_RESP_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED) &&
5337 (dev_caps_cfg & VER_GET_RESP_DEV_CAPS_CFG_SHORT_CMD_REQUIRED))
5338 bp->flags |= BNXT_FLAG_SHORT_CMD;
5339
Michael Chanc0c050c2015-10-22 16:01:17 -04005340hwrm_ver_get_exit:
5341 mutex_unlock(&bp->hwrm_cmd_lock);
5342 return rc;
5343}
5344
Rob Swindell5ac67d82016-09-19 03:58:03 -04005345int bnxt_hwrm_fw_set_time(struct bnxt *bp)
5346{
5347 struct hwrm_fw_set_time_input req = {0};
Arnd Bergmann7dfaa7b2017-11-06 15:04:39 +01005348 struct tm tm;
5349 time64_t now = ktime_get_real_seconds();
Rob Swindell5ac67d82016-09-19 03:58:03 -04005350
Michael Chanca2c39e2018-04-26 17:44:34 -04005351 if ((BNXT_VF(bp) && bp->hwrm_spec_code < 0x10901) ||
5352 bp->hwrm_spec_code < 0x10400)
Rob Swindell5ac67d82016-09-19 03:58:03 -04005353 return -EOPNOTSUPP;
5354
Arnd Bergmann7dfaa7b2017-11-06 15:04:39 +01005355 time64_to_tm(now, 0, &tm);
Rob Swindell5ac67d82016-09-19 03:58:03 -04005356 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_SET_TIME, -1, -1);
5357 req.year = cpu_to_le16(1900 + tm.tm_year);
5358 req.month = 1 + tm.tm_mon;
5359 req.day = tm.tm_mday;
5360 req.hour = tm.tm_hour;
5361 req.minute = tm.tm_min;
5362 req.second = tm.tm_sec;
5363 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5364}
5365
Michael Chan3bdf56c2016-03-07 15:38:45 -05005366static int bnxt_hwrm_port_qstats(struct bnxt *bp)
5367{
5368 int rc;
5369 struct bnxt_pf_info *pf = &bp->pf;
5370 struct hwrm_port_qstats_input req = {0};
5371
5372 if (!(bp->flags & BNXT_FLAG_PORT_STATS))
5373 return 0;
5374
5375 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_QSTATS, -1, -1);
5376 req.port_id = cpu_to_le16(pf->port_id);
5377 req.tx_stat_host_addr = cpu_to_le64(bp->hw_tx_port_stats_map);
5378 req.rx_stat_host_addr = cpu_to_le64(bp->hw_rx_port_stats_map);
5379 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5380 return rc;
5381}
5382
Vasundhara Volam00db3cb2018-03-31 13:54:12 -04005383static int bnxt_hwrm_port_qstats_ext(struct bnxt *bp)
5384{
5385 struct hwrm_port_qstats_ext_input req = {0};
5386 struct bnxt_pf_info *pf = &bp->pf;
5387
5388 if (!(bp->flags & BNXT_FLAG_PORT_STATS_EXT))
5389 return 0;
5390
5391 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_QSTATS_EXT, -1, -1);
5392 req.port_id = cpu_to_le16(pf->port_id);
5393 req.rx_stat_size = cpu_to_le16(sizeof(struct rx_port_stats_ext));
5394 req.rx_stat_host_addr = cpu_to_le64(bp->hw_rx_port_stats_ext_map);
5395 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5396}
5397
Michael Chanc0c050c2015-10-22 16:01:17 -04005398static void bnxt_hwrm_free_tunnel_ports(struct bnxt *bp)
5399{
5400 if (bp->vxlan_port_cnt) {
5401 bnxt_hwrm_tunnel_dst_port_free(
5402 bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN);
5403 }
5404 bp->vxlan_port_cnt = 0;
5405 if (bp->nge_port_cnt) {
5406 bnxt_hwrm_tunnel_dst_port_free(
5407 bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE);
5408 }
5409 bp->nge_port_cnt = 0;
5410}
5411
5412static int bnxt_set_tpa(struct bnxt *bp, bool set_tpa)
5413{
5414 int rc, i;
5415 u32 tpa_flags = 0;
5416
5417 if (set_tpa)
5418 tpa_flags = bp->flags & BNXT_FLAG_TPA;
5419 for (i = 0; i < bp->nr_vnics; i++) {
5420 rc = bnxt_hwrm_vnic_set_tpa(bp, i, tpa_flags);
5421 if (rc) {
5422 netdev_err(bp->dev, "hwrm vnic set tpa failure rc for vnic %d: %x\n",
Sankar Patchineelam23e12c82017-03-28 19:47:30 -04005423 i, rc);
Michael Chanc0c050c2015-10-22 16:01:17 -04005424 return rc;
5425 }
5426 }
5427 return 0;
5428}
5429
5430static void bnxt_hwrm_clear_vnic_rss(struct bnxt *bp)
5431{
5432 int i;
5433
5434 for (i = 0; i < bp->nr_vnics; i++)
5435 bnxt_hwrm_vnic_set_rss(bp, i, false);
5436}
5437
5438static void bnxt_hwrm_resource_free(struct bnxt *bp, bool close_path,
5439 bool irq_re_init)
5440{
5441 if (bp->vnic_info) {
5442 bnxt_hwrm_clear_vnic_filter(bp);
5443 /* clear all RSS setting before free vnic ctx */
5444 bnxt_hwrm_clear_vnic_rss(bp);
5445 bnxt_hwrm_vnic_ctx_free(bp);
5446 /* before free the vnic, undo the vnic tpa settings */
5447 if (bp->flags & BNXT_FLAG_TPA)
5448 bnxt_set_tpa(bp, false);
5449 bnxt_hwrm_vnic_free(bp);
5450 }
5451 bnxt_hwrm_ring_free(bp, close_path);
5452 bnxt_hwrm_ring_grp_free(bp);
5453 if (irq_re_init) {
5454 bnxt_hwrm_stat_ctx_free(bp);
5455 bnxt_hwrm_free_tunnel_ports(bp);
5456 }
5457}
5458
Michael Chan39d8ba22017-07-24 12:34:22 -04005459static int bnxt_hwrm_set_br_mode(struct bnxt *bp, u16 br_mode)
5460{
5461 struct hwrm_func_cfg_input req = {0};
5462 int rc;
5463
5464 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1);
5465 req.fid = cpu_to_le16(0xffff);
5466 req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_EVB_MODE);
5467 if (br_mode == BRIDGE_MODE_VEB)
5468 req.evb_mode = FUNC_CFG_REQ_EVB_MODE_VEB;
5469 else if (br_mode == BRIDGE_MODE_VEPA)
5470 req.evb_mode = FUNC_CFG_REQ_EVB_MODE_VEPA;
5471 else
5472 return -EINVAL;
5473 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5474 if (rc)
5475 rc = -EIO;
5476 return rc;
5477}
5478
Michael Chanc3480a62018-01-17 03:21:15 -05005479static int bnxt_hwrm_set_cache_line_size(struct bnxt *bp, int size)
5480{
5481 struct hwrm_func_cfg_input req = {0};
5482 int rc;
5483
5484 if (BNXT_VF(bp) || bp->hwrm_spec_code < 0x10803)
5485 return 0;
5486
5487 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1);
5488 req.fid = cpu_to_le16(0xffff);
5489 req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_CACHE_LINESIZE);
Michael Chand4f52de02018-03-31 13:54:06 -04005490 req.options = FUNC_CFG_REQ_OPTIONS_CACHE_LINESIZE_SIZE_64;
Michael Chanc3480a62018-01-17 03:21:15 -05005491 if (size == 128)
Michael Chand4f52de02018-03-31 13:54:06 -04005492 req.options = FUNC_CFG_REQ_OPTIONS_CACHE_LINESIZE_SIZE_128;
Michael Chanc3480a62018-01-17 03:21:15 -05005493
5494 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5495 if (rc)
5496 rc = -EIO;
5497 return rc;
5498}
5499
Michael Chanc0c050c2015-10-22 16:01:17 -04005500static int bnxt_setup_vnic(struct bnxt *bp, u16 vnic_id)
5501{
Michael Chanae10ae72016-12-29 12:13:38 -05005502 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
Michael Chanc0c050c2015-10-22 16:01:17 -04005503 int rc;
5504
Michael Chanae10ae72016-12-29 12:13:38 -05005505 if (vnic->flags & BNXT_VNIC_RFS_NEW_RSS_FLAG)
5506 goto skip_rss_ctx;
5507
Michael Chanc0c050c2015-10-22 16:01:17 -04005508 /* allocate context for vnic */
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04005509 rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic_id, 0);
Michael Chanc0c050c2015-10-22 16:01:17 -04005510 if (rc) {
5511 netdev_err(bp->dev, "hwrm vnic %d alloc failure rc: %x\n",
5512 vnic_id, rc);
5513 goto vnic_setup_err;
5514 }
5515 bp->rsscos_nr_ctxs++;
5516
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04005517 if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
5518 rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic_id, 1);
5519 if (rc) {
5520 netdev_err(bp->dev, "hwrm vnic %d cos ctx alloc failure rc: %x\n",
5521 vnic_id, rc);
5522 goto vnic_setup_err;
5523 }
5524 bp->rsscos_nr_ctxs++;
5525 }
5526
Michael Chanae10ae72016-12-29 12:13:38 -05005527skip_rss_ctx:
Michael Chanc0c050c2015-10-22 16:01:17 -04005528 /* configure default vnic, ring grp */
5529 rc = bnxt_hwrm_vnic_cfg(bp, vnic_id);
5530 if (rc) {
5531 netdev_err(bp->dev, "hwrm vnic %d cfg failure rc: %x\n",
5532 vnic_id, rc);
5533 goto vnic_setup_err;
5534 }
5535
5536 /* Enable RSS hashing on vnic */
5537 rc = bnxt_hwrm_vnic_set_rss(bp, vnic_id, true);
5538 if (rc) {
5539 netdev_err(bp->dev, "hwrm vnic %d set rss failure rc: %x\n",
5540 vnic_id, rc);
5541 goto vnic_setup_err;
5542 }
5543
5544 if (bp->flags & BNXT_FLAG_AGG_RINGS) {
5545 rc = bnxt_hwrm_vnic_set_hds(bp, vnic_id);
5546 if (rc) {
5547 netdev_err(bp->dev, "hwrm vnic %d set hds failure rc: %x\n",
5548 vnic_id, rc);
5549 }
5550 }
5551
5552vnic_setup_err:
5553 return rc;
5554}
5555
5556static int bnxt_alloc_rfs_vnics(struct bnxt *bp)
5557{
5558#ifdef CONFIG_RFS_ACCEL
5559 int i, rc = 0;
5560
5561 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanae10ae72016-12-29 12:13:38 -05005562 struct bnxt_vnic_info *vnic;
Michael Chanc0c050c2015-10-22 16:01:17 -04005563 u16 vnic_id = i + 1;
5564 u16 ring_id = i;
5565
5566 if (vnic_id >= bp->nr_vnics)
5567 break;
5568
Michael Chanae10ae72016-12-29 12:13:38 -05005569 vnic = &bp->vnic_info[vnic_id];
5570 vnic->flags |= BNXT_VNIC_RFS_FLAG;
5571 if (bp->flags & BNXT_FLAG_NEW_RSS_CAP)
5572 vnic->flags |= BNXT_VNIC_RFS_NEW_RSS_FLAG;
Michael Chanb81a90d2016-01-02 23:45:01 -05005573 rc = bnxt_hwrm_vnic_alloc(bp, vnic_id, ring_id, 1);
Michael Chanc0c050c2015-10-22 16:01:17 -04005574 if (rc) {
5575 netdev_err(bp->dev, "hwrm vnic %d alloc failure rc: %x\n",
5576 vnic_id, rc);
5577 break;
5578 }
5579 rc = bnxt_setup_vnic(bp, vnic_id);
5580 if (rc)
5581 break;
5582 }
5583 return rc;
5584#else
5585 return 0;
5586#endif
5587}
5588
Michael Chan17c71ac2016-07-01 18:46:27 -04005589/* Allow PF and VF with default VLAN to be in promiscuous mode */
5590static bool bnxt_promisc_ok(struct bnxt *bp)
5591{
5592#ifdef CONFIG_BNXT_SRIOV
5593 if (BNXT_VF(bp) && !bp->vf.vlan)
5594 return false;
5595#endif
5596 return true;
5597}
5598
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04005599static int bnxt_setup_nitroa0_vnic(struct bnxt *bp)
5600{
5601 unsigned int rc = 0;
5602
5603 rc = bnxt_hwrm_vnic_alloc(bp, 1, bp->rx_nr_rings - 1, 1);
5604 if (rc) {
5605 netdev_err(bp->dev, "Cannot allocate special vnic for NS2 A0: %x\n",
5606 rc);
5607 return rc;
5608 }
5609
5610 rc = bnxt_hwrm_vnic_cfg(bp, 1);
5611 if (rc) {
5612 netdev_err(bp->dev, "Cannot allocate special vnic for NS2 A0: %x\n",
5613 rc);
5614 return rc;
5615 }
5616 return rc;
5617}
5618
Michael Chanb664f002015-12-02 01:54:08 -05005619static int bnxt_cfg_rx_mode(struct bnxt *);
Michael Chan7d2837d2016-05-04 16:56:44 -04005620static bool bnxt_mc_list_updated(struct bnxt *, u32 *);
Michael Chanb664f002015-12-02 01:54:08 -05005621
Michael Chanc0c050c2015-10-22 16:01:17 -04005622static int bnxt_init_chip(struct bnxt *bp, bool irq_re_init)
5623{
Michael Chan7d2837d2016-05-04 16:56:44 -04005624 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
Michael Chanc0c050c2015-10-22 16:01:17 -04005625 int rc = 0;
Prashant Sreedharan76595192016-07-18 07:15:22 -04005626 unsigned int rx_nr_rings = bp->rx_nr_rings;
Michael Chanc0c050c2015-10-22 16:01:17 -04005627
5628 if (irq_re_init) {
5629 rc = bnxt_hwrm_stat_ctx_alloc(bp);
5630 if (rc) {
5631 netdev_err(bp->dev, "hwrm stat ctx alloc failure rc: %x\n",
5632 rc);
5633 goto err_out;
5634 }
5635 }
5636
5637 rc = bnxt_hwrm_ring_alloc(bp);
5638 if (rc) {
5639 netdev_err(bp->dev, "hwrm ring alloc failure rc: %x\n", rc);
5640 goto err_out;
5641 }
5642
5643 rc = bnxt_hwrm_ring_grp_alloc(bp);
5644 if (rc) {
5645 netdev_err(bp->dev, "hwrm_ring_grp alloc failure: %x\n", rc);
5646 goto err_out;
5647 }
5648
Prashant Sreedharan76595192016-07-18 07:15:22 -04005649 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
5650 rx_nr_rings--;
5651
Michael Chanc0c050c2015-10-22 16:01:17 -04005652 /* default vnic 0 */
Prashant Sreedharan76595192016-07-18 07:15:22 -04005653 rc = bnxt_hwrm_vnic_alloc(bp, 0, 0, rx_nr_rings);
Michael Chanc0c050c2015-10-22 16:01:17 -04005654 if (rc) {
5655 netdev_err(bp->dev, "hwrm vnic alloc failure rc: %x\n", rc);
5656 goto err_out;
5657 }
5658
5659 rc = bnxt_setup_vnic(bp, 0);
5660 if (rc)
5661 goto err_out;
5662
5663 if (bp->flags & BNXT_FLAG_RFS) {
5664 rc = bnxt_alloc_rfs_vnics(bp);
5665 if (rc)
5666 goto err_out;
5667 }
5668
5669 if (bp->flags & BNXT_FLAG_TPA) {
5670 rc = bnxt_set_tpa(bp, true);
5671 if (rc)
5672 goto err_out;
5673 }
5674
5675 if (BNXT_VF(bp))
5676 bnxt_update_vf_mac(bp);
5677
5678 /* Filter for default vnic 0 */
5679 rc = bnxt_hwrm_set_vnic_filter(bp, 0, 0, bp->dev->dev_addr);
5680 if (rc) {
5681 netdev_err(bp->dev, "HWRM vnic filter failure rc: %x\n", rc);
5682 goto err_out;
5683 }
Michael Chan7d2837d2016-05-04 16:56:44 -04005684 vnic->uc_filter_count = 1;
Michael Chanc0c050c2015-10-22 16:01:17 -04005685
Michael Chan7d2837d2016-05-04 16:56:44 -04005686 vnic->rx_mask = CFA_L2_SET_RX_MASK_REQ_MASK_BCAST;
Michael Chanc0c050c2015-10-22 16:01:17 -04005687
Michael Chan17c71ac2016-07-01 18:46:27 -04005688 if ((bp->dev->flags & IFF_PROMISC) && bnxt_promisc_ok(bp))
Michael Chan7d2837d2016-05-04 16:56:44 -04005689 vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS;
5690
5691 if (bp->dev->flags & IFF_ALLMULTI) {
5692 vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST;
5693 vnic->mc_list_count = 0;
5694 } else {
5695 u32 mask = 0;
5696
5697 bnxt_mc_list_updated(bp, &mask);
5698 vnic->rx_mask |= mask;
5699 }
Michael Chanc0c050c2015-10-22 16:01:17 -04005700
Michael Chanb664f002015-12-02 01:54:08 -05005701 rc = bnxt_cfg_rx_mode(bp);
5702 if (rc)
Michael Chanc0c050c2015-10-22 16:01:17 -04005703 goto err_out;
Michael Chanc0c050c2015-10-22 16:01:17 -04005704
5705 rc = bnxt_hwrm_set_coal(bp);
5706 if (rc)
5707 netdev_warn(bp->dev, "HWRM set coalescing failure rc: %x\n",
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04005708 rc);
5709
5710 if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
5711 rc = bnxt_setup_nitroa0_vnic(bp);
5712 if (rc)
5713 netdev_err(bp->dev, "Special vnic setup failure for NS2 A0 rc: %x\n",
5714 rc);
5715 }
Michael Chanc0c050c2015-10-22 16:01:17 -04005716
Michael Chancf6645f2016-06-13 02:25:28 -04005717 if (BNXT_VF(bp)) {
5718 bnxt_hwrm_func_qcfg(bp);
5719 netdev_update_features(bp->dev);
5720 }
5721
Michael Chanc0c050c2015-10-22 16:01:17 -04005722 return 0;
5723
5724err_out:
5725 bnxt_hwrm_resource_free(bp, 0, true);
5726
5727 return rc;
5728}
5729
5730static int bnxt_shutdown_nic(struct bnxt *bp, bool irq_re_init)
5731{
5732 bnxt_hwrm_resource_free(bp, 1, irq_re_init);
5733 return 0;
5734}
5735
5736static int bnxt_init_nic(struct bnxt *bp, bool irq_re_init)
5737{
Sankar Patchineelam22479252017-03-28 19:47:29 -04005738 bnxt_init_cp_rings(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04005739 bnxt_init_rx_rings(bp);
5740 bnxt_init_tx_rings(bp);
5741 bnxt_init_ring_grps(bp, irq_re_init);
5742 bnxt_init_vnics(bp);
5743
5744 return bnxt_init_chip(bp, irq_re_init);
5745}
5746
Michael Chanc0c050c2015-10-22 16:01:17 -04005747static int bnxt_set_real_num_queues(struct bnxt *bp)
5748{
5749 int rc;
5750 struct net_device *dev = bp->dev;
5751
Michael Chan5f449242017-02-06 16:55:40 -05005752 rc = netif_set_real_num_tx_queues(dev, bp->tx_nr_rings -
5753 bp->tx_nr_rings_xdp);
Michael Chanc0c050c2015-10-22 16:01:17 -04005754 if (rc)
5755 return rc;
5756
5757 rc = netif_set_real_num_rx_queues(dev, bp->rx_nr_rings);
5758 if (rc)
5759 return rc;
5760
5761#ifdef CONFIG_RFS_ACCEL
Michael Chan45019a12015-12-27 18:19:22 -05005762 if (bp->flags & BNXT_FLAG_RFS)
Michael Chanc0c050c2015-10-22 16:01:17 -04005763 dev->rx_cpu_rmap = alloc_irq_cpu_rmap(bp->rx_nr_rings);
Michael Chanc0c050c2015-10-22 16:01:17 -04005764#endif
5765
5766 return rc;
5767}
5768
Michael Chan6e6c5a52016-01-02 23:45:02 -05005769static int bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max,
5770 bool shared)
5771{
5772 int _rx = *rx, _tx = *tx;
5773
5774 if (shared) {
5775 *rx = min_t(int, _rx, max);
5776 *tx = min_t(int, _tx, max);
5777 } else {
5778 if (max < 2)
5779 return -ENOMEM;
5780
5781 while (_rx + _tx > max) {
5782 if (_rx > _tx && _rx > 1)
5783 _rx--;
5784 else if (_tx > 1)
5785 _tx--;
5786 }
5787 *rx = _rx;
5788 *tx = _tx;
5789 }
5790 return 0;
5791}
5792
Michael Chan78095922016-12-07 00:26:16 -05005793static void bnxt_setup_msix(struct bnxt *bp)
5794{
5795 const int len = sizeof(bp->irq_tbl[0].name);
5796 struct net_device *dev = bp->dev;
5797 int tcs, i;
5798
5799 tcs = netdev_get_num_tc(dev);
5800 if (tcs > 1) {
Michael Chand1e79252017-02-06 16:55:38 -05005801 int i, off, count;
Michael Chan78095922016-12-07 00:26:16 -05005802
Michael Chand1e79252017-02-06 16:55:38 -05005803 for (i = 0; i < tcs; i++) {
5804 count = bp->tx_nr_rings_per_tc;
5805 off = i * count;
5806 netdev_set_tc_queue(dev, i, count, off);
Michael Chan78095922016-12-07 00:26:16 -05005807 }
5808 }
5809
5810 for (i = 0; i < bp->cp_nr_rings; i++) {
Michael Chane5811b82018-03-31 13:54:18 -04005811 int map_idx = bnxt_cp_num_to_irq_num(bp, i);
Michael Chan78095922016-12-07 00:26:16 -05005812 char *attr;
5813
5814 if (bp->flags & BNXT_FLAG_SHARED_RINGS)
5815 attr = "TxRx";
5816 else if (i < bp->rx_nr_rings)
5817 attr = "rx";
5818 else
5819 attr = "tx";
5820
Michael Chane5811b82018-03-31 13:54:18 -04005821 snprintf(bp->irq_tbl[map_idx].name, len, "%s-%s-%d", dev->name,
5822 attr, i);
5823 bp->irq_tbl[map_idx].handler = bnxt_msix;
Michael Chan78095922016-12-07 00:26:16 -05005824 }
5825}
5826
5827static void bnxt_setup_inta(struct bnxt *bp)
5828{
5829 const int len = sizeof(bp->irq_tbl[0].name);
5830
5831 if (netdev_get_num_tc(bp->dev))
5832 netdev_reset_tc(bp->dev);
5833
5834 snprintf(bp->irq_tbl[0].name, len, "%s-%s-%d", bp->dev->name, "TxRx",
5835 0);
5836 bp->irq_tbl[0].handler = bnxt_inta;
5837}
5838
5839static int bnxt_setup_int_mode(struct bnxt *bp)
5840{
5841 int rc;
5842
5843 if (bp->flags & BNXT_FLAG_USING_MSIX)
5844 bnxt_setup_msix(bp);
5845 else
5846 bnxt_setup_inta(bp);
5847
5848 rc = bnxt_set_real_num_queues(bp);
5849 return rc;
5850}
5851
Michael Chanb7429952017-01-13 01:32:00 -05005852#ifdef CONFIG_RFS_ACCEL
Michael Chan8079e8f2016-12-29 12:13:37 -05005853static unsigned int bnxt_get_max_func_rss_ctxs(struct bnxt *bp)
5854{
Michael Chan6a4f2942018-01-17 03:21:06 -05005855 return bp->hw_resc.max_rsscos_ctxs;
Michael Chan8079e8f2016-12-29 12:13:37 -05005856}
5857
5858static unsigned int bnxt_get_max_func_vnics(struct bnxt *bp)
5859{
Michael Chan6a4f2942018-01-17 03:21:06 -05005860 return bp->hw_resc.max_vnics;
Michael Chan8079e8f2016-12-29 12:13:37 -05005861}
Michael Chanb7429952017-01-13 01:32:00 -05005862#endif
Michael Chan8079e8f2016-12-29 12:13:37 -05005863
Michael Chane4060d32016-12-07 00:26:19 -05005864unsigned int bnxt_get_max_func_stat_ctxs(struct bnxt *bp)
5865{
Michael Chan6a4f2942018-01-17 03:21:06 -05005866 return bp->hw_resc.max_stat_ctxs;
Michael Chane4060d32016-12-07 00:26:19 -05005867}
5868
Michael Chana588e452016-12-07 00:26:21 -05005869void bnxt_set_max_func_stat_ctxs(struct bnxt *bp, unsigned int max)
5870{
Michael Chan6a4f2942018-01-17 03:21:06 -05005871 bp->hw_resc.max_stat_ctxs = max;
Michael Chana588e452016-12-07 00:26:21 -05005872}
5873
Michael Chane4060d32016-12-07 00:26:19 -05005874unsigned int bnxt_get_max_func_cp_rings(struct bnxt *bp)
5875{
Michael Chan6a4f2942018-01-17 03:21:06 -05005876 return bp->hw_resc.max_cp_rings;
Michael Chane4060d32016-12-07 00:26:19 -05005877}
5878
Michael Chana588e452016-12-07 00:26:21 -05005879void bnxt_set_max_func_cp_rings(struct bnxt *bp, unsigned int max)
5880{
Michael Chan6a4f2942018-01-17 03:21:06 -05005881 bp->hw_resc.max_cp_rings = max;
Michael Chana588e452016-12-07 00:26:21 -05005882}
5883
Michael Chanfbcfc8e2018-03-31 13:54:20 -04005884unsigned int bnxt_get_max_func_irqs(struct bnxt *bp)
Michael Chan78095922016-12-07 00:26:16 -05005885{
Michael Chan6a4f2942018-01-17 03:21:06 -05005886 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
5887
5888 return min_t(unsigned int, hw_resc->max_irqs, hw_resc->max_cp_rings);
Michael Chan78095922016-12-07 00:26:16 -05005889}
5890
Michael Chan33c26572016-12-07 00:26:15 -05005891void bnxt_set_max_func_irqs(struct bnxt *bp, unsigned int max_irqs)
5892{
Michael Chan6a4f2942018-01-17 03:21:06 -05005893 bp->hw_resc.max_irqs = max_irqs;
Michael Chan33c26572016-12-07 00:26:15 -05005894}
5895
Michael Chanfbcfc8e2018-03-31 13:54:20 -04005896int bnxt_get_avail_msix(struct bnxt *bp, int num)
5897{
5898 int max_cp = bnxt_get_max_func_cp_rings(bp);
5899 int max_irq = bnxt_get_max_func_irqs(bp);
5900 int total_req = bp->cp_nr_rings + num;
5901 int max_idx, avail_msix;
5902
5903 max_idx = min_t(int, bp->total_irqs, max_cp);
5904 avail_msix = max_idx - bp->cp_nr_rings;
5905 if (!(bp->flags & BNXT_FLAG_NEW_RM) || avail_msix >= num)
5906 return avail_msix;
5907
5908 if (max_irq < total_req) {
5909 num = max_irq - bp->cp_nr_rings;
5910 if (num <= 0)
5911 return 0;
5912 }
5913 return num;
5914}
5915
Michael Chan08654eb2018-03-31 13:54:17 -04005916static int bnxt_get_num_msix(struct bnxt *bp)
5917{
5918 if (!(bp->flags & BNXT_FLAG_NEW_RM))
5919 return bnxt_get_max_func_irqs(bp);
5920
5921 return bnxt_cp_rings_in_use(bp);
5922}
5923
Michael Chan78095922016-12-07 00:26:16 -05005924static int bnxt_init_msix(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04005925{
Michael Chanfbcfc8e2018-03-31 13:54:20 -04005926 int i, total_vecs, max, rc = 0, min = 1, ulp_msix;
Michael Chan78095922016-12-07 00:26:16 -05005927 struct msix_entry *msix_ent;
Michael Chanc0c050c2015-10-22 16:01:17 -04005928
Michael Chan08654eb2018-03-31 13:54:17 -04005929 total_vecs = bnxt_get_num_msix(bp);
5930 max = bnxt_get_max_func_irqs(bp);
5931 if (total_vecs > max)
5932 total_vecs = max;
5933
Michael Chanc0c050c2015-10-22 16:01:17 -04005934 msix_ent = kcalloc(total_vecs, sizeof(struct msix_entry), GFP_KERNEL);
5935 if (!msix_ent)
5936 return -ENOMEM;
5937
5938 for (i = 0; i < total_vecs; i++) {
5939 msix_ent[i].entry = i;
5940 msix_ent[i].vector = 0;
5941 }
5942
Michael Chan01657bc2016-01-02 23:45:03 -05005943 if (!(bp->flags & BNXT_FLAG_SHARED_RINGS))
5944 min = 2;
5945
5946 total_vecs = pci_enable_msix_range(bp->pdev, msix_ent, min, total_vecs);
Michael Chanfbcfc8e2018-03-31 13:54:20 -04005947 ulp_msix = bnxt_get_ulp_msix_num(bp);
5948 if (total_vecs < 0 || total_vecs < ulp_msix) {
Michael Chanc0c050c2015-10-22 16:01:17 -04005949 rc = -ENODEV;
5950 goto msix_setup_exit;
5951 }
5952
5953 bp->irq_tbl = kcalloc(total_vecs, sizeof(struct bnxt_irq), GFP_KERNEL);
5954 if (bp->irq_tbl) {
Michael Chan78095922016-12-07 00:26:16 -05005955 for (i = 0; i < total_vecs; i++)
5956 bp->irq_tbl[i].vector = msix_ent[i].vector;
Michael Chanc0c050c2015-10-22 16:01:17 -04005957
Michael Chan78095922016-12-07 00:26:16 -05005958 bp->total_irqs = total_vecs;
Michael Chanc0c050c2015-10-22 16:01:17 -04005959 /* Trim rings based upon num of vectors allocated */
Michael Chan6e6c5a52016-01-02 23:45:02 -05005960 rc = bnxt_trim_rings(bp, &bp->rx_nr_rings, &bp->tx_nr_rings,
Michael Chanfbcfc8e2018-03-31 13:54:20 -04005961 total_vecs - ulp_msix, min == 1);
Michael Chan6e6c5a52016-01-02 23:45:02 -05005962 if (rc)
5963 goto msix_setup_exit;
5964
Michael Chan78095922016-12-07 00:26:16 -05005965 bp->cp_nr_rings = (min == 1) ?
5966 max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
5967 bp->tx_nr_rings + bp->rx_nr_rings;
Michael Chanc0c050c2015-10-22 16:01:17 -04005968
Michael Chanc0c050c2015-10-22 16:01:17 -04005969 } else {
5970 rc = -ENOMEM;
5971 goto msix_setup_exit;
5972 }
5973 bp->flags |= BNXT_FLAG_USING_MSIX;
5974 kfree(msix_ent);
5975 return 0;
5976
5977msix_setup_exit:
Michael Chan78095922016-12-07 00:26:16 -05005978 netdev_err(bp->dev, "bnxt_init_msix err: %x\n", rc);
5979 kfree(bp->irq_tbl);
5980 bp->irq_tbl = NULL;
Michael Chanc0c050c2015-10-22 16:01:17 -04005981 pci_disable_msix(bp->pdev);
5982 kfree(msix_ent);
5983 return rc;
5984}
5985
Michael Chan78095922016-12-07 00:26:16 -05005986static int bnxt_init_inta(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04005987{
Michael Chanc0c050c2015-10-22 16:01:17 -04005988 bp->irq_tbl = kcalloc(1, sizeof(struct bnxt_irq), GFP_KERNEL);
Michael Chan78095922016-12-07 00:26:16 -05005989 if (!bp->irq_tbl)
5990 return -ENOMEM;
5991
5992 bp->total_irqs = 1;
Michael Chanc0c050c2015-10-22 16:01:17 -04005993 bp->rx_nr_rings = 1;
5994 bp->tx_nr_rings = 1;
5995 bp->cp_nr_rings = 1;
Michael Chan01657bc2016-01-02 23:45:03 -05005996 bp->flags |= BNXT_FLAG_SHARED_RINGS;
Michael Chanc0c050c2015-10-22 16:01:17 -04005997 bp->irq_tbl[0].vector = bp->pdev->irq;
Michael Chan78095922016-12-07 00:26:16 -05005998 return 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04005999}
6000
Michael Chan78095922016-12-07 00:26:16 -05006001static int bnxt_init_int_mode(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04006002{
6003 int rc = 0;
6004
6005 if (bp->flags & BNXT_FLAG_MSIX_CAP)
Michael Chan78095922016-12-07 00:26:16 -05006006 rc = bnxt_init_msix(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04006007
Michael Chan1fa72e22016-04-25 02:30:49 -04006008 if (!(bp->flags & BNXT_FLAG_USING_MSIX) && BNXT_PF(bp)) {
Michael Chanc0c050c2015-10-22 16:01:17 -04006009 /* fallback to INTA */
Michael Chan78095922016-12-07 00:26:16 -05006010 rc = bnxt_init_inta(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04006011 }
6012 return rc;
6013}
6014
Michael Chan78095922016-12-07 00:26:16 -05006015static void bnxt_clear_int_mode(struct bnxt *bp)
6016{
6017 if (bp->flags & BNXT_FLAG_USING_MSIX)
6018 pci_disable_msix(bp->pdev);
6019
6020 kfree(bp->irq_tbl);
6021 bp->irq_tbl = NULL;
6022 bp->flags &= ~BNXT_FLAG_USING_MSIX;
6023}
6024
Michael Chanfbcfc8e2018-03-31 13:54:20 -04006025int bnxt_reserve_rings(struct bnxt *bp)
Michael Chan674f50a2018-01-17 03:21:09 -05006026{
Michael Chan674f50a2018-01-17 03:21:09 -05006027 int tcs = netdev_get_num_tc(bp->dev);
6028 int rc;
6029
6030 if (!bnxt_need_reserve_rings(bp))
6031 return 0;
6032
6033 rc = __bnxt_reserve_rings(bp);
6034 if (rc) {
6035 netdev_err(bp->dev, "ring reservation failure rc: %d\n", rc);
6036 return rc;
6037 }
Michael Chanfbcfc8e2018-03-31 13:54:20 -04006038 if ((bp->flags & BNXT_FLAG_NEW_RM) &&
6039 (bnxt_get_num_msix(bp) != bp->total_irqs)) {
Michael Chanec86f142018-03-31 13:54:21 -04006040 bnxt_ulp_irq_stop(bp);
Michael Chan674f50a2018-01-17 03:21:09 -05006041 bnxt_clear_int_mode(bp);
6042 rc = bnxt_init_int_mode(bp);
Michael Chanec86f142018-03-31 13:54:21 -04006043 bnxt_ulp_irq_restart(bp, rc);
Michael Chan674f50a2018-01-17 03:21:09 -05006044 if (rc)
6045 return rc;
6046 }
6047 if (tcs && (bp->tx_nr_rings_per_tc * tcs != bp->tx_nr_rings)) {
6048 netdev_err(bp->dev, "tx ring reservation failure\n");
6049 netdev_reset_tc(bp->dev);
6050 bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
6051 return -ENOMEM;
6052 }
6053 bp->num_stat_ctxs = bp->cp_nr_rings;
6054 return 0;
6055}
6056
Michael Chanc0c050c2015-10-22 16:01:17 -04006057static void bnxt_free_irq(struct bnxt *bp)
6058{
6059 struct bnxt_irq *irq;
6060 int i;
6061
6062#ifdef CONFIG_RFS_ACCEL
6063 free_irq_cpu_rmap(bp->dev->rx_cpu_rmap);
6064 bp->dev->rx_cpu_rmap = NULL;
6065#endif
Michael Chancb985262018-04-11 11:50:18 -04006066 if (!bp->irq_tbl || !bp->bnapi)
Michael Chanc0c050c2015-10-22 16:01:17 -04006067 return;
6068
6069 for (i = 0; i < bp->cp_nr_rings; i++) {
Michael Chane5811b82018-03-31 13:54:18 -04006070 int map_idx = bnxt_cp_num_to_irq_num(bp, i);
6071
6072 irq = &bp->irq_tbl[map_idx];
Vasundhara Volam56f0fd82017-08-28 13:40:27 -04006073 if (irq->requested) {
6074 if (irq->have_cpumask) {
6075 irq_set_affinity_hint(irq->vector, NULL);
6076 free_cpumask_var(irq->cpu_mask);
6077 irq->have_cpumask = 0;
6078 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006079 free_irq(irq->vector, bp->bnapi[i]);
Vasundhara Volam56f0fd82017-08-28 13:40:27 -04006080 }
6081
Michael Chanc0c050c2015-10-22 16:01:17 -04006082 irq->requested = 0;
6083 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006084}
6085
6086static int bnxt_request_irq(struct bnxt *bp)
6087{
Michael Chanb81a90d2016-01-02 23:45:01 -05006088 int i, j, rc = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04006089 unsigned long flags = 0;
6090#ifdef CONFIG_RFS_ACCEL
Michael Chane5811b82018-03-31 13:54:18 -04006091 struct cpu_rmap *rmap;
Michael Chanc0c050c2015-10-22 16:01:17 -04006092#endif
6093
Michael Chane5811b82018-03-31 13:54:18 -04006094 rc = bnxt_setup_int_mode(bp);
6095 if (rc) {
6096 netdev_err(bp->dev, "bnxt_setup_int_mode err: %x\n",
6097 rc);
6098 return rc;
6099 }
6100#ifdef CONFIG_RFS_ACCEL
6101 rmap = bp->dev->rx_cpu_rmap;
6102#endif
Michael Chanc0c050c2015-10-22 16:01:17 -04006103 if (!(bp->flags & BNXT_FLAG_USING_MSIX))
6104 flags = IRQF_SHARED;
6105
Michael Chanb81a90d2016-01-02 23:45:01 -05006106 for (i = 0, j = 0; i < bp->cp_nr_rings; i++) {
Michael Chane5811b82018-03-31 13:54:18 -04006107 int map_idx = bnxt_cp_num_to_irq_num(bp, i);
6108 struct bnxt_irq *irq = &bp->irq_tbl[map_idx];
6109
Michael Chanc0c050c2015-10-22 16:01:17 -04006110#ifdef CONFIG_RFS_ACCEL
Michael Chanb81a90d2016-01-02 23:45:01 -05006111 if (rmap && bp->bnapi[i]->rx_ring) {
Michael Chanc0c050c2015-10-22 16:01:17 -04006112 rc = irq_cpu_rmap_add(rmap, irq->vector);
6113 if (rc)
6114 netdev_warn(bp->dev, "failed adding irq rmap for ring %d\n",
Michael Chanb81a90d2016-01-02 23:45:01 -05006115 j);
6116 j++;
Michael Chanc0c050c2015-10-22 16:01:17 -04006117 }
6118#endif
6119 rc = request_irq(irq->vector, irq->handler, flags, irq->name,
6120 bp->bnapi[i]);
6121 if (rc)
6122 break;
6123
6124 irq->requested = 1;
Vasundhara Volam56f0fd82017-08-28 13:40:27 -04006125
6126 if (zalloc_cpumask_var(&irq->cpu_mask, GFP_KERNEL)) {
6127 int numa_node = dev_to_node(&bp->pdev->dev);
6128
6129 irq->have_cpumask = 1;
6130 cpumask_set_cpu(cpumask_local_spread(i, numa_node),
6131 irq->cpu_mask);
6132 rc = irq_set_affinity_hint(irq->vector, irq->cpu_mask);
6133 if (rc) {
6134 netdev_warn(bp->dev,
6135 "Set affinity failed, IRQ = %d\n",
6136 irq->vector);
6137 break;
6138 }
6139 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006140 }
6141 return rc;
6142}
6143
6144static void bnxt_del_napi(struct bnxt *bp)
6145{
6146 int i;
6147
6148 if (!bp->bnapi)
6149 return;
6150
6151 for (i = 0; i < bp->cp_nr_rings; i++) {
6152 struct bnxt_napi *bnapi = bp->bnapi[i];
6153
6154 napi_hash_del(&bnapi->napi);
6155 netif_napi_del(&bnapi->napi);
6156 }
Eric Dumazete5f6f562016-11-16 06:31:52 -08006157 /* We called napi_hash_del() before netif_napi_del(), we need
6158 * to respect an RCU grace period before freeing napi structures.
6159 */
6160 synchronize_net();
Michael Chanc0c050c2015-10-22 16:01:17 -04006161}
6162
6163static void bnxt_init_napi(struct bnxt *bp)
6164{
6165 int i;
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04006166 unsigned int cp_nr_rings = bp->cp_nr_rings;
Michael Chanc0c050c2015-10-22 16:01:17 -04006167 struct bnxt_napi *bnapi;
6168
6169 if (bp->flags & BNXT_FLAG_USING_MSIX) {
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04006170 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
6171 cp_nr_rings--;
6172 for (i = 0; i < cp_nr_rings; i++) {
Michael Chanc0c050c2015-10-22 16:01:17 -04006173 bnapi = bp->bnapi[i];
6174 netif_napi_add(bp->dev, &bnapi->napi,
6175 bnxt_poll, 64);
Michael Chanc0c050c2015-10-22 16:01:17 -04006176 }
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04006177 if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
6178 bnapi = bp->bnapi[cp_nr_rings];
6179 netif_napi_add(bp->dev, &bnapi->napi,
6180 bnxt_poll_nitroa0, 64);
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04006181 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006182 } else {
6183 bnapi = bp->bnapi[0];
6184 netif_napi_add(bp->dev, &bnapi->napi, bnxt_poll, 64);
Michael Chanc0c050c2015-10-22 16:01:17 -04006185 }
6186}
6187
6188static void bnxt_disable_napi(struct bnxt *bp)
6189{
6190 int i;
6191
6192 if (!bp->bnapi)
6193 return;
6194
Andy Gospodarek0bc0b972018-01-26 10:27:47 -05006195 for (i = 0; i < bp->cp_nr_rings; i++) {
6196 struct bnxt_cp_ring_info *cpr = &bp->bnapi[i]->cp_ring;
6197
6198 if (bp->bnapi[i]->rx_ring)
6199 cancel_work_sync(&cpr->dim.work);
6200
Michael Chanc0c050c2015-10-22 16:01:17 -04006201 napi_disable(&bp->bnapi[i]->napi);
Andy Gospodarek0bc0b972018-01-26 10:27:47 -05006202 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006203}
6204
6205static void bnxt_enable_napi(struct bnxt *bp)
6206{
6207 int i;
6208
6209 for (i = 0; i < bp->cp_nr_rings; i++) {
Andy Gospodarek6a8788f2018-01-09 16:06:20 -05006210 struct bnxt_cp_ring_info *cpr = &bp->bnapi[i]->cp_ring;
Michael Chanfa7e2812016-05-10 19:18:00 -04006211 bp->bnapi[i]->in_reset = false;
Andy Gospodarek6a8788f2018-01-09 16:06:20 -05006212
6213 if (bp->bnapi[i]->rx_ring) {
6214 INIT_WORK(&cpr->dim.work, bnxt_dim_work);
6215 cpr->dim.mode = NET_DIM_CQ_PERIOD_MODE_START_FROM_EQE;
6216 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006217 napi_enable(&bp->bnapi[i]->napi);
6218 }
6219}
6220
Michael Chan7df4ae92016-12-02 21:17:17 -05006221void bnxt_tx_disable(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04006222{
6223 int i;
Michael Chanc0c050c2015-10-22 16:01:17 -04006224 struct bnxt_tx_ring_info *txr;
Michael Chanc0c050c2015-10-22 16:01:17 -04006225
Michael Chanb6ab4b02016-01-02 23:44:59 -05006226 if (bp->tx_ring) {
Michael Chanc0c050c2015-10-22 16:01:17 -04006227 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05006228 txr = &bp->tx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04006229 txr->dev_state = BNXT_DEV_STATE_CLOSING;
Michael Chanc0c050c2015-10-22 16:01:17 -04006230 }
6231 }
6232 /* Stop all TX queues */
6233 netif_tx_disable(bp->dev);
6234 netif_carrier_off(bp->dev);
6235}
6236
Michael Chan7df4ae92016-12-02 21:17:17 -05006237void bnxt_tx_enable(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04006238{
6239 int i;
Michael Chanc0c050c2015-10-22 16:01:17 -04006240 struct bnxt_tx_ring_info *txr;
Michael Chanc0c050c2015-10-22 16:01:17 -04006241
6242 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05006243 txr = &bp->tx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04006244 txr->dev_state = 0;
6245 }
6246 netif_tx_wake_all_queues(bp->dev);
6247 if (bp->link_info.link_up)
6248 netif_carrier_on(bp->dev);
6249}
6250
6251static void bnxt_report_link(struct bnxt *bp)
6252{
6253 if (bp->link_info.link_up) {
6254 const char *duplex;
6255 const char *flow_ctrl;
Deepak Khungar38a21b32017-04-21 20:11:24 -04006256 u32 speed;
6257 u16 fec;
Michael Chanc0c050c2015-10-22 16:01:17 -04006258
6259 netif_carrier_on(bp->dev);
6260 if (bp->link_info.duplex == BNXT_LINK_DUPLEX_FULL)
6261 duplex = "full";
6262 else
6263 duplex = "half";
6264 if (bp->link_info.pause == BNXT_LINK_PAUSE_BOTH)
6265 flow_ctrl = "ON - receive & transmit";
6266 else if (bp->link_info.pause == BNXT_LINK_PAUSE_TX)
6267 flow_ctrl = "ON - transmit";
6268 else if (bp->link_info.pause == BNXT_LINK_PAUSE_RX)
6269 flow_ctrl = "ON - receive";
6270 else
6271 flow_ctrl = "none";
6272 speed = bnxt_fw_to_ethtool_speed(bp->link_info.link_speed);
Deepak Khungar38a21b32017-04-21 20:11:24 -04006273 netdev_info(bp->dev, "NIC Link is Up, %u Mbps %s duplex, Flow control: %s\n",
Michael Chanc0c050c2015-10-22 16:01:17 -04006274 speed, duplex, flow_ctrl);
Michael Chan170ce012016-04-05 14:08:57 -04006275 if (bp->flags & BNXT_FLAG_EEE_CAP)
6276 netdev_info(bp->dev, "EEE is %s\n",
6277 bp->eee.eee_active ? "active" :
6278 "not active");
Michael Chane70c7522017-02-12 19:18:16 -05006279 fec = bp->link_info.fec_cfg;
6280 if (!(fec & PORT_PHY_QCFG_RESP_FEC_CFG_FEC_NONE_SUPPORTED))
6281 netdev_info(bp->dev, "FEC autoneg %s encodings: %s\n",
6282 (fec & BNXT_FEC_AUTONEG) ? "on" : "off",
6283 (fec & BNXT_FEC_ENC_BASE_R) ? "BaseR" :
6284 (fec & BNXT_FEC_ENC_RS) ? "RS" : "None");
Michael Chanc0c050c2015-10-22 16:01:17 -04006285 } else {
6286 netif_carrier_off(bp->dev);
6287 netdev_err(bp->dev, "NIC Link is Down\n");
6288 }
6289}
6290
Michael Chan170ce012016-04-05 14:08:57 -04006291static int bnxt_hwrm_phy_qcaps(struct bnxt *bp)
6292{
6293 int rc = 0;
6294 struct hwrm_port_phy_qcaps_input req = {0};
6295 struct hwrm_port_phy_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
Michael Chan93ed8112016-06-13 02:25:37 -04006296 struct bnxt_link_info *link_info = &bp->link_info;
Michael Chan170ce012016-04-05 14:08:57 -04006297
6298 if (bp->hwrm_spec_code < 0x10201)
6299 return 0;
6300
6301 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCAPS, -1, -1);
6302
6303 mutex_lock(&bp->hwrm_cmd_lock);
6304 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6305 if (rc)
6306 goto hwrm_phy_qcaps_exit;
6307
Michael Chanacb20052017-07-24 12:34:20 -04006308 if (resp->flags & PORT_PHY_QCAPS_RESP_FLAGS_EEE_SUPPORTED) {
Michael Chan170ce012016-04-05 14:08:57 -04006309 struct ethtool_eee *eee = &bp->eee;
6310 u16 fw_speeds = le16_to_cpu(resp->supported_speeds_eee_mode);
6311
6312 bp->flags |= BNXT_FLAG_EEE_CAP;
6313 eee->supported = _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0);
6314 bp->lpi_tmr_lo = le32_to_cpu(resp->tx_lpi_timer_low) &
6315 PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_LOW_MASK;
6316 bp->lpi_tmr_hi = le32_to_cpu(resp->valid_tx_lpi_timer_high) &
6317 PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_HIGH_MASK;
6318 }
Michael Chan520ad892017-03-08 18:44:35 -05006319 if (resp->supported_speeds_auto_mode)
6320 link_info->support_auto_speeds =
6321 le16_to_cpu(resp->supported_speeds_auto_mode);
Michael Chan170ce012016-04-05 14:08:57 -04006322
Michael Chand5430d32017-08-28 13:40:31 -04006323 bp->port_count = resp->port_cnt;
6324
Michael Chan170ce012016-04-05 14:08:57 -04006325hwrm_phy_qcaps_exit:
6326 mutex_unlock(&bp->hwrm_cmd_lock);
6327 return rc;
6328}
6329
Michael Chanc0c050c2015-10-22 16:01:17 -04006330static int bnxt_update_link(struct bnxt *bp, bool chng_link_state)
6331{
6332 int rc = 0;
6333 struct bnxt_link_info *link_info = &bp->link_info;
6334 struct hwrm_port_phy_qcfg_input req = {0};
6335 struct hwrm_port_phy_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
6336 u8 link_up = link_info->link_up;
Michael Chan286ef9d2016-11-16 21:13:08 -05006337 u16 diff;
Michael Chanc0c050c2015-10-22 16:01:17 -04006338
6339 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCFG, -1, -1);
6340
6341 mutex_lock(&bp->hwrm_cmd_lock);
6342 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6343 if (rc) {
6344 mutex_unlock(&bp->hwrm_cmd_lock);
6345 return rc;
6346 }
6347
6348 memcpy(&link_info->phy_qcfg_resp, resp, sizeof(*resp));
6349 link_info->phy_link_status = resp->link;
Michael Chanacb20052017-07-24 12:34:20 -04006350 link_info->duplex = resp->duplex_cfg;
6351 if (bp->hwrm_spec_code >= 0x10800)
6352 link_info->duplex = resp->duplex_state;
Michael Chanc0c050c2015-10-22 16:01:17 -04006353 link_info->pause = resp->pause;
6354 link_info->auto_mode = resp->auto_mode;
6355 link_info->auto_pause_setting = resp->auto_pause;
Michael Chan32773602016-03-07 15:38:42 -05006356 link_info->lp_pause = resp->link_partner_adv_pause;
Michael Chanc0c050c2015-10-22 16:01:17 -04006357 link_info->force_pause_setting = resp->force_pause;
Michael Chanacb20052017-07-24 12:34:20 -04006358 link_info->duplex_setting = resp->duplex_cfg;
Michael Chanc0c050c2015-10-22 16:01:17 -04006359 if (link_info->phy_link_status == BNXT_LINK_LINK)
6360 link_info->link_speed = le16_to_cpu(resp->link_speed);
6361 else
6362 link_info->link_speed = 0;
6363 link_info->force_link_speed = le16_to_cpu(resp->force_link_speed);
Michael Chanc0c050c2015-10-22 16:01:17 -04006364 link_info->support_speeds = le16_to_cpu(resp->support_speeds);
6365 link_info->auto_link_speeds = le16_to_cpu(resp->auto_link_speed_mask);
Michael Chan32773602016-03-07 15:38:42 -05006366 link_info->lp_auto_link_speeds =
6367 le16_to_cpu(resp->link_partner_adv_speeds);
Michael Chanc0c050c2015-10-22 16:01:17 -04006368 link_info->preemphasis = le32_to_cpu(resp->preemphasis);
6369 link_info->phy_ver[0] = resp->phy_maj;
6370 link_info->phy_ver[1] = resp->phy_min;
6371 link_info->phy_ver[2] = resp->phy_bld;
6372 link_info->media_type = resp->media_type;
Michael Chan03efbec2016-04-11 04:11:11 -04006373 link_info->phy_type = resp->phy_type;
Michael Chan11f15ed2016-04-05 14:08:55 -04006374 link_info->transceiver = resp->xcvr_pkg_type;
Michael Chan170ce012016-04-05 14:08:57 -04006375 link_info->phy_addr = resp->eee_config_phy_addr &
6376 PORT_PHY_QCFG_RESP_PHY_ADDR_MASK;
Ajit Khaparde42ee18f2016-05-15 03:04:44 -04006377 link_info->module_status = resp->module_status;
Michael Chanc0c050c2015-10-22 16:01:17 -04006378
Michael Chan170ce012016-04-05 14:08:57 -04006379 if (bp->flags & BNXT_FLAG_EEE_CAP) {
6380 struct ethtool_eee *eee = &bp->eee;
6381 u16 fw_speeds;
6382
6383 eee->eee_active = 0;
6384 if (resp->eee_config_phy_addr &
6385 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ACTIVE) {
6386 eee->eee_active = 1;
6387 fw_speeds = le16_to_cpu(
6388 resp->link_partner_adv_eee_link_speed_mask);
6389 eee->lp_advertised =
6390 _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0);
6391 }
6392
6393 /* Pull initial EEE config */
6394 if (!chng_link_state) {
6395 if (resp->eee_config_phy_addr &
6396 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ENABLED)
6397 eee->eee_enabled = 1;
6398
6399 fw_speeds = le16_to_cpu(resp->adv_eee_link_speed_mask);
6400 eee->advertised =
6401 _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0);
6402
6403 if (resp->eee_config_phy_addr &
6404 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_TX_LPI) {
6405 __le32 tmr;
6406
6407 eee->tx_lpi_enabled = 1;
6408 tmr = resp->xcvr_identifier_type_tx_lpi_timer;
6409 eee->tx_lpi_timer = le32_to_cpu(tmr) &
6410 PORT_PHY_QCFG_RESP_TX_LPI_TIMER_MASK;
6411 }
6412 }
6413 }
Michael Chane70c7522017-02-12 19:18:16 -05006414
6415 link_info->fec_cfg = PORT_PHY_QCFG_RESP_FEC_CFG_FEC_NONE_SUPPORTED;
6416 if (bp->hwrm_spec_code >= 0x10504)
6417 link_info->fec_cfg = le16_to_cpu(resp->fec_cfg);
6418
Michael Chanc0c050c2015-10-22 16:01:17 -04006419 /* TODO: need to add more logic to report VF link */
6420 if (chng_link_state) {
6421 if (link_info->phy_link_status == BNXT_LINK_LINK)
6422 link_info->link_up = 1;
6423 else
6424 link_info->link_up = 0;
6425 if (link_up != link_info->link_up)
6426 bnxt_report_link(bp);
6427 } else {
6428 /* alwasy link down if not require to update link state */
6429 link_info->link_up = 0;
6430 }
6431 mutex_unlock(&bp->hwrm_cmd_lock);
Michael Chan286ef9d2016-11-16 21:13:08 -05006432
6433 diff = link_info->support_auto_speeds ^ link_info->advertising;
6434 if ((link_info->support_auto_speeds | diff) !=
6435 link_info->support_auto_speeds) {
6436 /* An advertised speed is no longer supported, so we need to
Michael Chan0eaa24b2017-01-25 02:55:08 -05006437 * update the advertisement settings. Caller holds RTNL
6438 * so we can modify link settings.
Michael Chan286ef9d2016-11-16 21:13:08 -05006439 */
Michael Chan286ef9d2016-11-16 21:13:08 -05006440 link_info->advertising = link_info->support_auto_speeds;
Michael Chan0eaa24b2017-01-25 02:55:08 -05006441 if (link_info->autoneg & BNXT_AUTONEG_SPEED)
Michael Chan286ef9d2016-11-16 21:13:08 -05006442 bnxt_hwrm_set_link_setting(bp, true, false);
Michael Chan286ef9d2016-11-16 21:13:08 -05006443 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006444 return 0;
6445}
6446
Michael Chan10289be2016-05-15 03:04:49 -04006447static void bnxt_get_port_module_status(struct bnxt *bp)
6448{
6449 struct bnxt_link_info *link_info = &bp->link_info;
6450 struct hwrm_port_phy_qcfg_output *resp = &link_info->phy_qcfg_resp;
6451 u8 module_status;
6452
6453 if (bnxt_update_link(bp, true))
6454 return;
6455
6456 module_status = link_info->module_status;
6457 switch (module_status) {
6458 case PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX:
6459 case PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN:
6460 case PORT_PHY_QCFG_RESP_MODULE_STATUS_WARNINGMSG:
6461 netdev_warn(bp->dev, "Unqualified SFP+ module detected on port %d\n",
6462 bp->pf.port_id);
6463 if (bp->hwrm_spec_code >= 0x10201) {
6464 netdev_warn(bp->dev, "Module part number %s\n",
6465 resp->phy_vendor_partnumber);
6466 }
6467 if (module_status == PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX)
6468 netdev_warn(bp->dev, "TX is disabled\n");
6469 if (module_status == PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN)
6470 netdev_warn(bp->dev, "SFP+ module is shutdown\n");
6471 }
6472}
6473
Michael Chanc0c050c2015-10-22 16:01:17 -04006474static void
6475bnxt_hwrm_set_pause_common(struct bnxt *bp, struct hwrm_port_phy_cfg_input *req)
6476{
6477 if (bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL) {
Michael Chanc9ee9512016-04-05 14:08:56 -04006478 if (bp->hwrm_spec_code >= 0x10201)
6479 req->auto_pause =
6480 PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE;
Michael Chanc0c050c2015-10-22 16:01:17 -04006481 if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_RX)
6482 req->auto_pause |= PORT_PHY_CFG_REQ_AUTO_PAUSE_RX;
6483 if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_TX)
Michael Chan49b5c7a2016-03-28 19:46:06 -04006484 req->auto_pause |= PORT_PHY_CFG_REQ_AUTO_PAUSE_TX;
Michael Chanc0c050c2015-10-22 16:01:17 -04006485 req->enables |=
6486 cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE);
6487 } else {
6488 if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_RX)
6489 req->force_pause |= PORT_PHY_CFG_REQ_FORCE_PAUSE_RX;
6490 if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_TX)
6491 req->force_pause |= PORT_PHY_CFG_REQ_FORCE_PAUSE_TX;
6492 req->enables |=
6493 cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_FORCE_PAUSE);
Michael Chanc9ee9512016-04-05 14:08:56 -04006494 if (bp->hwrm_spec_code >= 0x10201) {
6495 req->auto_pause = req->force_pause;
6496 req->enables |= cpu_to_le32(
6497 PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE);
6498 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006499 }
6500}
6501
6502static void bnxt_hwrm_set_link_common(struct bnxt *bp,
6503 struct hwrm_port_phy_cfg_input *req)
6504{
6505 u8 autoneg = bp->link_info.autoneg;
6506 u16 fw_link_speed = bp->link_info.req_link_speed;
Michael Chan68515a12016-12-29 12:13:34 -05006507 u16 advertising = bp->link_info.advertising;
Michael Chanc0c050c2015-10-22 16:01:17 -04006508
6509 if (autoneg & BNXT_AUTONEG_SPEED) {
6510 req->auto_mode |=
Michael Chan11f15ed2016-04-05 14:08:55 -04006511 PORT_PHY_CFG_REQ_AUTO_MODE_SPEED_MASK;
Michael Chanc0c050c2015-10-22 16:01:17 -04006512
6513 req->enables |= cpu_to_le32(
6514 PORT_PHY_CFG_REQ_ENABLES_AUTO_LINK_SPEED_MASK);
6515 req->auto_link_speed_mask = cpu_to_le16(advertising);
6516
6517 req->enables |= cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_MODE);
6518 req->flags |=
6519 cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESTART_AUTONEG);
6520 } else {
6521 req->force_link_speed = cpu_to_le16(fw_link_speed);
6522 req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE);
6523 }
6524
Michael Chanc0c050c2015-10-22 16:01:17 -04006525 /* tell chimp that the setting takes effect immediately */
6526 req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESET_PHY);
6527}
6528
6529int bnxt_hwrm_set_pause(struct bnxt *bp)
6530{
6531 struct hwrm_port_phy_cfg_input req = {0};
6532 int rc;
6533
6534 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1);
6535 bnxt_hwrm_set_pause_common(bp, &req);
6536
6537 if ((bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL) ||
6538 bp->link_info.force_link_chng)
6539 bnxt_hwrm_set_link_common(bp, &req);
6540
6541 mutex_lock(&bp->hwrm_cmd_lock);
6542 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6543 if (!rc && !(bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL)) {
6544 /* since changing of pause setting doesn't trigger any link
6545 * change event, the driver needs to update the current pause
6546 * result upon successfully return of the phy_cfg command
6547 */
6548 bp->link_info.pause =
6549 bp->link_info.force_pause_setting = bp->link_info.req_flow_ctrl;
6550 bp->link_info.auto_pause_setting = 0;
6551 if (!bp->link_info.force_link_chng)
6552 bnxt_report_link(bp);
6553 }
6554 bp->link_info.force_link_chng = false;
6555 mutex_unlock(&bp->hwrm_cmd_lock);
6556 return rc;
6557}
6558
Michael Chan939f7f02016-04-05 14:08:58 -04006559static void bnxt_hwrm_set_eee(struct bnxt *bp,
6560 struct hwrm_port_phy_cfg_input *req)
6561{
6562 struct ethtool_eee *eee = &bp->eee;
6563
6564 if (eee->eee_enabled) {
6565 u16 eee_speeds;
6566 u32 flags = PORT_PHY_CFG_REQ_FLAGS_EEE_ENABLE;
6567
6568 if (eee->tx_lpi_enabled)
6569 flags |= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_ENABLE;
6570 else
6571 flags |= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_DISABLE;
6572
6573 req->flags |= cpu_to_le32(flags);
6574 eee_speeds = bnxt_get_fw_auto_link_speeds(eee->advertised);
6575 req->eee_link_speed_mask = cpu_to_le16(eee_speeds);
6576 req->tx_lpi_timer = cpu_to_le32(eee->tx_lpi_timer);
6577 } else {
6578 req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_EEE_DISABLE);
6579 }
6580}
6581
6582int bnxt_hwrm_set_link_setting(struct bnxt *bp, bool set_pause, bool set_eee)
Michael Chanc0c050c2015-10-22 16:01:17 -04006583{
6584 struct hwrm_port_phy_cfg_input req = {0};
6585
6586 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1);
6587 if (set_pause)
6588 bnxt_hwrm_set_pause_common(bp, &req);
6589
6590 bnxt_hwrm_set_link_common(bp, &req);
Michael Chan939f7f02016-04-05 14:08:58 -04006591
6592 if (set_eee)
6593 bnxt_hwrm_set_eee(bp, &req);
Michael Chanc0c050c2015-10-22 16:01:17 -04006594 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6595}
6596
Michael Chan33f7d552016-04-11 04:11:12 -04006597static int bnxt_hwrm_shutdown_link(struct bnxt *bp)
6598{
6599 struct hwrm_port_phy_cfg_input req = {0};
6600
Satish Baddipadige567b2ab2016-06-13 02:25:31 -04006601 if (!BNXT_SINGLE_PF(bp))
Michael Chan33f7d552016-04-11 04:11:12 -04006602 return 0;
6603
6604 if (pci_num_vf(bp->pdev))
6605 return 0;
6606
6607 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1);
Michael Chan16d663a2016-11-16 21:13:07 -05006608 req.flags = cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE_LINK_DWN);
Michael Chan33f7d552016-04-11 04:11:12 -04006609 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6610}
6611
Michael Chan5ad2cbe2017-01-13 01:32:03 -05006612static int bnxt_hwrm_port_led_qcaps(struct bnxt *bp)
6613{
6614 struct hwrm_port_led_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
6615 struct hwrm_port_led_qcaps_input req = {0};
6616 struct bnxt_pf_info *pf = &bp->pf;
6617 int rc;
6618
6619 if (BNXT_VF(bp) || bp->hwrm_spec_code < 0x10601)
6620 return 0;
6621
6622 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_LED_QCAPS, -1, -1);
6623 req.port_id = cpu_to_le16(pf->port_id);
6624 mutex_lock(&bp->hwrm_cmd_lock);
6625 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6626 if (rc) {
6627 mutex_unlock(&bp->hwrm_cmd_lock);
6628 return rc;
6629 }
6630 if (resp->num_leds > 0 && resp->num_leds < BNXT_MAX_LED) {
6631 int i;
6632
6633 bp->num_leds = resp->num_leds;
6634 memcpy(bp->leds, &resp->led0_id, sizeof(bp->leds[0]) *
6635 bp->num_leds);
6636 for (i = 0; i < bp->num_leds; i++) {
6637 struct bnxt_led_info *led = &bp->leds[i];
6638 __le16 caps = led->led_state_caps;
6639
6640 if (!led->led_group_id ||
6641 !BNXT_LED_ALT_BLINK_CAP(caps)) {
6642 bp->num_leds = 0;
6643 break;
6644 }
6645 }
6646 }
6647 mutex_unlock(&bp->hwrm_cmd_lock);
6648 return 0;
6649}
6650
Michael Chan5282db62017-04-04 18:14:10 -04006651int bnxt_hwrm_alloc_wol_fltr(struct bnxt *bp)
6652{
6653 struct hwrm_wol_filter_alloc_input req = {0};
6654 struct hwrm_wol_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr;
6655 int rc;
6656
6657 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_WOL_FILTER_ALLOC, -1, -1);
6658 req.port_id = cpu_to_le16(bp->pf.port_id);
6659 req.wol_type = WOL_FILTER_ALLOC_REQ_WOL_TYPE_MAGICPKT;
6660 req.enables = cpu_to_le32(WOL_FILTER_ALLOC_REQ_ENABLES_MAC_ADDRESS);
6661 memcpy(req.mac_address, bp->dev->dev_addr, ETH_ALEN);
6662 mutex_lock(&bp->hwrm_cmd_lock);
6663 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6664 if (!rc)
6665 bp->wol_filter_id = resp->wol_filter_id;
6666 mutex_unlock(&bp->hwrm_cmd_lock);
6667 return rc;
6668}
6669
6670int bnxt_hwrm_free_wol_fltr(struct bnxt *bp)
6671{
6672 struct hwrm_wol_filter_free_input req = {0};
6673 int rc;
6674
6675 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_WOL_FILTER_FREE, -1, -1);
6676 req.port_id = cpu_to_le16(bp->pf.port_id);
6677 req.enables = cpu_to_le32(WOL_FILTER_FREE_REQ_ENABLES_WOL_FILTER_ID);
6678 req.wol_filter_id = bp->wol_filter_id;
6679 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6680 return rc;
6681}
6682
Michael Chanc1ef1462017-04-04 18:14:07 -04006683static u16 bnxt_hwrm_get_wol_fltrs(struct bnxt *bp, u16 handle)
6684{
6685 struct hwrm_wol_filter_qcfg_input req = {0};
6686 struct hwrm_wol_filter_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
6687 u16 next_handle = 0;
6688 int rc;
6689
6690 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_WOL_FILTER_QCFG, -1, -1);
6691 req.port_id = cpu_to_le16(bp->pf.port_id);
6692 req.handle = cpu_to_le16(handle);
6693 mutex_lock(&bp->hwrm_cmd_lock);
6694 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6695 if (!rc) {
6696 next_handle = le16_to_cpu(resp->next_handle);
6697 if (next_handle != 0) {
6698 if (resp->wol_type ==
6699 WOL_FILTER_ALLOC_REQ_WOL_TYPE_MAGICPKT) {
6700 bp->wol = 1;
6701 bp->wol_filter_id = resp->wol_filter_id;
6702 }
6703 }
6704 }
6705 mutex_unlock(&bp->hwrm_cmd_lock);
6706 return next_handle;
6707}
6708
6709static void bnxt_get_wol_settings(struct bnxt *bp)
6710{
6711 u16 handle = 0;
6712
6713 if (!BNXT_PF(bp) || !(bp->flags & BNXT_FLAG_WOL_CAP))
6714 return;
6715
6716 do {
6717 handle = bnxt_hwrm_get_wol_fltrs(bp, handle);
6718 } while (handle && handle != 0xffff);
6719}
6720
Michael Chan939f7f02016-04-05 14:08:58 -04006721static bool bnxt_eee_config_ok(struct bnxt *bp)
6722{
6723 struct ethtool_eee *eee = &bp->eee;
6724 struct bnxt_link_info *link_info = &bp->link_info;
6725
6726 if (!(bp->flags & BNXT_FLAG_EEE_CAP))
6727 return true;
6728
6729 if (eee->eee_enabled) {
6730 u32 advertising =
6731 _bnxt_fw_to_ethtool_adv_spds(link_info->advertising, 0);
6732
6733 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) {
6734 eee->eee_enabled = 0;
6735 return false;
6736 }
6737 if (eee->advertised & ~advertising) {
6738 eee->advertised = advertising & eee->supported;
6739 return false;
6740 }
6741 }
6742 return true;
6743}
6744
Michael Chanc0c050c2015-10-22 16:01:17 -04006745static int bnxt_update_phy_setting(struct bnxt *bp)
6746{
6747 int rc;
6748 bool update_link = false;
6749 bool update_pause = false;
Michael Chan939f7f02016-04-05 14:08:58 -04006750 bool update_eee = false;
Michael Chanc0c050c2015-10-22 16:01:17 -04006751 struct bnxt_link_info *link_info = &bp->link_info;
6752
6753 rc = bnxt_update_link(bp, true);
6754 if (rc) {
6755 netdev_err(bp->dev, "failed to update link (rc: %x)\n",
6756 rc);
6757 return rc;
6758 }
Michael Chan33dac242017-02-12 19:18:15 -05006759 if (!BNXT_SINGLE_PF(bp))
6760 return 0;
6761
Michael Chanc0c050c2015-10-22 16:01:17 -04006762 if ((link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) &&
Michael Chanc9ee9512016-04-05 14:08:56 -04006763 (link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH) !=
6764 link_info->req_flow_ctrl)
Michael Chanc0c050c2015-10-22 16:01:17 -04006765 update_pause = true;
6766 if (!(link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) &&
6767 link_info->force_pause_setting != link_info->req_flow_ctrl)
6768 update_pause = true;
Michael Chanc0c050c2015-10-22 16:01:17 -04006769 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) {
6770 if (BNXT_AUTO_MODE(link_info->auto_mode))
6771 update_link = true;
6772 if (link_info->req_link_speed != link_info->force_link_speed)
6773 update_link = true;
Michael Chande730182016-02-19 19:43:20 -05006774 if (link_info->req_duplex != link_info->duplex_setting)
6775 update_link = true;
Michael Chanc0c050c2015-10-22 16:01:17 -04006776 } else {
6777 if (link_info->auto_mode == BNXT_LINK_AUTO_NONE)
6778 update_link = true;
6779 if (link_info->advertising != link_info->auto_link_speeds)
6780 update_link = true;
Michael Chanc0c050c2015-10-22 16:01:17 -04006781 }
6782
Michael Chan16d663a2016-11-16 21:13:07 -05006783 /* The last close may have shutdown the link, so need to call
6784 * PHY_CFG to bring it back up.
6785 */
6786 if (!netif_carrier_ok(bp->dev))
6787 update_link = true;
6788
Michael Chan939f7f02016-04-05 14:08:58 -04006789 if (!bnxt_eee_config_ok(bp))
6790 update_eee = true;
6791
Michael Chanc0c050c2015-10-22 16:01:17 -04006792 if (update_link)
Michael Chan939f7f02016-04-05 14:08:58 -04006793 rc = bnxt_hwrm_set_link_setting(bp, update_pause, update_eee);
Michael Chanc0c050c2015-10-22 16:01:17 -04006794 else if (update_pause)
6795 rc = bnxt_hwrm_set_pause(bp);
6796 if (rc) {
6797 netdev_err(bp->dev, "failed to update phy setting (rc: %x)\n",
6798 rc);
6799 return rc;
6800 }
6801
6802 return rc;
6803}
6804
Jeffrey Huang11809492015-11-05 16:25:49 -05006805/* Common routine to pre-map certain register block to different GRC window.
6806 * A PF has 16 4K windows and a VF has 4 4K windows. However, only 15 windows
6807 * in PF and 3 windows in VF that can be customized to map in different
6808 * register blocks.
6809 */
6810static void bnxt_preset_reg_win(struct bnxt *bp)
6811{
6812 if (BNXT_PF(bp)) {
6813 /* CAG registers map to GRC window #4 */
6814 writel(BNXT_CAG_REG_BASE,
6815 bp->bar0 + BNXT_GRCPF_REG_WINDOW_BASE_OUT + 12);
6816 }
6817}
6818
Michael Chanc0c050c2015-10-22 16:01:17 -04006819static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
6820{
6821 int rc = 0;
6822
Jeffrey Huang11809492015-11-05 16:25:49 -05006823 bnxt_preset_reg_win(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04006824 netif_carrier_off(bp->dev);
6825 if (irq_re_init) {
Michael Chan674f50a2018-01-17 03:21:09 -05006826 rc = bnxt_reserve_rings(bp);
6827 if (rc)
6828 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04006829 }
6830 if ((bp->flags & BNXT_FLAG_RFS) &&
6831 !(bp->flags & BNXT_FLAG_USING_MSIX)) {
6832 /* disable RFS if falling back to INTA */
6833 bp->dev->hw_features &= ~NETIF_F_NTUPLE;
6834 bp->flags &= ~BNXT_FLAG_RFS;
6835 }
6836
6837 rc = bnxt_alloc_mem(bp, irq_re_init);
6838 if (rc) {
6839 netdev_err(bp->dev, "bnxt_alloc_mem err: %x\n", rc);
6840 goto open_err_free_mem;
6841 }
6842
6843 if (irq_re_init) {
6844 bnxt_init_napi(bp);
6845 rc = bnxt_request_irq(bp);
6846 if (rc) {
6847 netdev_err(bp->dev, "bnxt_request_irq err: %x\n", rc);
6848 goto open_err;
6849 }
6850 }
6851
6852 bnxt_enable_napi(bp);
6853
6854 rc = bnxt_init_nic(bp, irq_re_init);
6855 if (rc) {
6856 netdev_err(bp->dev, "bnxt_init_nic err: %x\n", rc);
6857 goto open_err;
6858 }
6859
6860 if (link_re_init) {
Michael Chane2dc9b62017-10-13 21:09:30 -04006861 mutex_lock(&bp->link_lock);
Michael Chanc0c050c2015-10-22 16:01:17 -04006862 rc = bnxt_update_phy_setting(bp);
Michael Chane2dc9b62017-10-13 21:09:30 -04006863 mutex_unlock(&bp->link_lock);
Michael Chanc0c050c2015-10-22 16:01:17 -04006864 if (rc)
Michael Chanba41d462016-02-19 19:43:21 -05006865 netdev_warn(bp->dev, "failed to update phy settings\n");
Michael Chanc0c050c2015-10-22 16:01:17 -04006866 }
6867
Alexander Duyck7cdd5fc2016-06-16 12:21:36 -07006868 if (irq_re_init)
Alexander Duyckad51b8e2016-06-16 12:21:19 -07006869 udp_tunnel_get_rx_info(bp->dev);
Michael Chanc0c050c2015-10-22 16:01:17 -04006870
Michael Chancaefe522015-12-09 19:35:42 -05006871 set_bit(BNXT_STATE_OPEN, &bp->state);
Michael Chanc0c050c2015-10-22 16:01:17 -04006872 bnxt_enable_int(bp);
6873 /* Enable TX queues */
6874 bnxt_tx_enable(bp);
6875 mod_timer(&bp->timer, jiffies + bp->current_interval);
Michael Chan10289be2016-05-15 03:04:49 -04006876 /* Poll link status and check for SFP+ module status */
6877 bnxt_get_port_module_status(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04006878
Sathya Perlaee5c7fb2017-07-24 12:34:28 -04006879 /* VF-reps may need to be re-opened after the PF is re-opened */
6880 if (BNXT_PF(bp))
6881 bnxt_vf_reps_open(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04006882 return 0;
6883
6884open_err:
6885 bnxt_disable_napi(bp);
6886 bnxt_del_napi(bp);
6887
6888open_err_free_mem:
6889 bnxt_free_skbs(bp);
6890 bnxt_free_irq(bp);
6891 bnxt_free_mem(bp, true);
6892 return rc;
6893}
6894
6895/* rtnl_lock held */
6896int bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
6897{
6898 int rc = 0;
6899
6900 rc = __bnxt_open_nic(bp, irq_re_init, link_re_init);
6901 if (rc) {
6902 netdev_err(bp->dev, "nic open fail (rc: %x)\n", rc);
6903 dev_close(bp->dev);
6904 }
6905 return rc;
6906}
6907
Michael Chanf7dc1ea2017-04-04 18:14:13 -04006908/* rtnl_lock held, open the NIC half way by allocating all resources, but
6909 * NAPI, IRQ, and TX are not enabled. This is mainly used for offline
6910 * self tests.
6911 */
6912int bnxt_half_open_nic(struct bnxt *bp)
6913{
6914 int rc = 0;
6915
6916 rc = bnxt_alloc_mem(bp, false);
6917 if (rc) {
6918 netdev_err(bp->dev, "bnxt_alloc_mem err: %x\n", rc);
6919 goto half_open_err;
6920 }
6921 rc = bnxt_init_nic(bp, false);
6922 if (rc) {
6923 netdev_err(bp->dev, "bnxt_init_nic err: %x\n", rc);
6924 goto half_open_err;
6925 }
6926 return 0;
6927
6928half_open_err:
6929 bnxt_free_skbs(bp);
6930 bnxt_free_mem(bp, false);
6931 dev_close(bp->dev);
6932 return rc;
6933}
6934
6935/* rtnl_lock held, this call can only be made after a previous successful
6936 * call to bnxt_half_open_nic().
6937 */
6938void bnxt_half_close_nic(struct bnxt *bp)
6939{
6940 bnxt_hwrm_resource_free(bp, false, false);
6941 bnxt_free_skbs(bp);
6942 bnxt_free_mem(bp, false);
6943}
6944
Michael Chanc0c050c2015-10-22 16:01:17 -04006945static int bnxt_open(struct net_device *dev)
6946{
6947 struct bnxt *bp = netdev_priv(dev);
Michael Chanc0c050c2015-10-22 16:01:17 -04006948
Michael Chanc0c050c2015-10-22 16:01:17 -04006949 return __bnxt_open_nic(bp, true, true);
6950}
6951
Michael Chanf9b76eb2017-07-11 13:05:34 -04006952static bool bnxt_drv_busy(struct bnxt *bp)
6953{
6954 return (test_bit(BNXT_STATE_IN_SP_TASK, &bp->state) ||
6955 test_bit(BNXT_STATE_READ_STATS, &bp->state));
6956}
6957
Michael Chan86e953d2018-01-17 03:21:04 -05006958static void __bnxt_close_nic(struct bnxt *bp, bool irq_re_init,
6959 bool link_re_init)
Michael Chanc0c050c2015-10-22 16:01:17 -04006960{
Sathya Perlaee5c7fb2017-07-24 12:34:28 -04006961 /* Close the VF-reps before closing PF */
6962 if (BNXT_PF(bp))
6963 bnxt_vf_reps_close(bp);
Michael Chan86e953d2018-01-17 03:21:04 -05006964
Michael Chanc0c050c2015-10-22 16:01:17 -04006965 /* Change device state to avoid TX queue wake up's */
6966 bnxt_tx_disable(bp);
6967
Michael Chancaefe522015-12-09 19:35:42 -05006968 clear_bit(BNXT_STATE_OPEN, &bp->state);
Michael Chan4cebdce2015-12-09 19:35:43 -05006969 smp_mb__after_atomic();
Michael Chanf9b76eb2017-07-11 13:05:34 -04006970 while (bnxt_drv_busy(bp))
Michael Chan4cebdce2015-12-09 19:35:43 -05006971 msleep(20);
Michael Chanc0c050c2015-10-22 16:01:17 -04006972
Michael Chan9d8bc092016-12-29 12:13:33 -05006973 /* Flush rings and and disable interrupts */
Michael Chanc0c050c2015-10-22 16:01:17 -04006974 bnxt_shutdown_nic(bp, irq_re_init);
6975
6976 /* TODO CHIMP_FW: Link/PHY related cleanup if (link_re_init) */
6977
6978 bnxt_disable_napi(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04006979 del_timer_sync(&bp->timer);
6980 bnxt_free_skbs(bp);
6981
6982 if (irq_re_init) {
6983 bnxt_free_irq(bp);
6984 bnxt_del_napi(bp);
6985 }
6986 bnxt_free_mem(bp, irq_re_init);
Michael Chan86e953d2018-01-17 03:21:04 -05006987}
6988
6989int bnxt_close_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
6990{
6991 int rc = 0;
6992
6993#ifdef CONFIG_BNXT_SRIOV
6994 if (bp->sriov_cfg) {
6995 rc = wait_event_interruptible_timeout(bp->sriov_cfg_wait,
6996 !bp->sriov_cfg,
6997 BNXT_SRIOV_CFG_WAIT_TMO);
6998 if (rc)
6999 netdev_warn(bp->dev, "timeout waiting for SRIOV config operation to complete!\n");
7000 }
7001#endif
7002 __bnxt_close_nic(bp, irq_re_init, link_re_init);
Michael Chanc0c050c2015-10-22 16:01:17 -04007003 return rc;
7004}
7005
7006static int bnxt_close(struct net_device *dev)
7007{
7008 struct bnxt *bp = netdev_priv(dev);
7009
7010 bnxt_close_nic(bp, true, true);
Michael Chan33f7d552016-04-11 04:11:12 -04007011 bnxt_hwrm_shutdown_link(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04007012 return 0;
7013}
7014
7015/* rtnl_lock held */
7016static int bnxt_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
7017{
7018 switch (cmd) {
7019 case SIOCGMIIPHY:
7020 /* fallthru */
7021 case SIOCGMIIREG: {
7022 if (!netif_running(dev))
7023 return -EAGAIN;
7024
7025 return 0;
7026 }
7027
7028 case SIOCSMIIREG:
7029 if (!netif_running(dev))
7030 return -EAGAIN;
7031
7032 return 0;
7033
7034 default:
7035 /* do nothing */
7036 break;
7037 }
7038 return -EOPNOTSUPP;
7039}
7040
stephen hemmingerbc1f4472017-01-06 19:12:52 -08007041static void
Michael Chanc0c050c2015-10-22 16:01:17 -04007042bnxt_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
7043{
7044 u32 i;
7045 struct bnxt *bp = netdev_priv(dev);
7046
Michael Chanf9b76eb2017-07-11 13:05:34 -04007047 set_bit(BNXT_STATE_READ_STATS, &bp->state);
7048 /* Make sure bnxt_close_nic() sees that we are reading stats before
7049 * we check the BNXT_STATE_OPEN flag.
7050 */
7051 smp_mb__after_atomic();
7052 if (!test_bit(BNXT_STATE_OPEN, &bp->state)) {
7053 clear_bit(BNXT_STATE_READ_STATS, &bp->state);
stephen hemmingerbc1f4472017-01-06 19:12:52 -08007054 return;
Michael Chanf9b76eb2017-07-11 13:05:34 -04007055 }
Michael Chanc0c050c2015-10-22 16:01:17 -04007056
7057 /* TODO check if we need to synchronize with bnxt_close path */
7058 for (i = 0; i < bp->cp_nr_rings; i++) {
7059 struct bnxt_napi *bnapi = bp->bnapi[i];
7060 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
7061 struct ctx_hw_stats *hw_stats = cpr->hw_stats;
7062
7063 stats->rx_packets += le64_to_cpu(hw_stats->rx_ucast_pkts);
7064 stats->rx_packets += le64_to_cpu(hw_stats->rx_mcast_pkts);
7065 stats->rx_packets += le64_to_cpu(hw_stats->rx_bcast_pkts);
7066
7067 stats->tx_packets += le64_to_cpu(hw_stats->tx_ucast_pkts);
7068 stats->tx_packets += le64_to_cpu(hw_stats->tx_mcast_pkts);
7069 stats->tx_packets += le64_to_cpu(hw_stats->tx_bcast_pkts);
7070
7071 stats->rx_bytes += le64_to_cpu(hw_stats->rx_ucast_bytes);
7072 stats->rx_bytes += le64_to_cpu(hw_stats->rx_mcast_bytes);
7073 stats->rx_bytes += le64_to_cpu(hw_stats->rx_bcast_bytes);
7074
7075 stats->tx_bytes += le64_to_cpu(hw_stats->tx_ucast_bytes);
7076 stats->tx_bytes += le64_to_cpu(hw_stats->tx_mcast_bytes);
7077 stats->tx_bytes += le64_to_cpu(hw_stats->tx_bcast_bytes);
7078
7079 stats->rx_missed_errors +=
7080 le64_to_cpu(hw_stats->rx_discard_pkts);
7081
7082 stats->multicast += le64_to_cpu(hw_stats->rx_mcast_pkts);
7083
Michael Chanc0c050c2015-10-22 16:01:17 -04007084 stats->tx_dropped += le64_to_cpu(hw_stats->tx_drop_pkts);
7085 }
7086
Michael Chan9947f832016-03-07 15:38:46 -05007087 if (bp->flags & BNXT_FLAG_PORT_STATS) {
7088 struct rx_port_stats *rx = bp->hw_rx_port_stats;
7089 struct tx_port_stats *tx = bp->hw_tx_port_stats;
7090
7091 stats->rx_crc_errors = le64_to_cpu(rx->rx_fcs_err_frames);
7092 stats->rx_frame_errors = le64_to_cpu(rx->rx_align_err_frames);
7093 stats->rx_length_errors = le64_to_cpu(rx->rx_undrsz_frames) +
7094 le64_to_cpu(rx->rx_ovrsz_frames) +
7095 le64_to_cpu(rx->rx_runt_frames);
7096 stats->rx_errors = le64_to_cpu(rx->rx_false_carrier_frames) +
7097 le64_to_cpu(rx->rx_jbr_frames);
7098 stats->collisions = le64_to_cpu(tx->tx_total_collisions);
7099 stats->tx_fifo_errors = le64_to_cpu(tx->tx_fifo_underruns);
7100 stats->tx_errors = le64_to_cpu(tx->tx_err);
7101 }
Michael Chanf9b76eb2017-07-11 13:05:34 -04007102 clear_bit(BNXT_STATE_READ_STATS, &bp->state);
Michael Chanc0c050c2015-10-22 16:01:17 -04007103}
7104
7105static bool bnxt_mc_list_updated(struct bnxt *bp, u32 *rx_mask)
7106{
7107 struct net_device *dev = bp->dev;
7108 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
7109 struct netdev_hw_addr *ha;
7110 u8 *haddr;
7111 int mc_count = 0;
7112 bool update = false;
7113 int off = 0;
7114
7115 netdev_for_each_mc_addr(ha, dev) {
7116 if (mc_count >= BNXT_MAX_MC_ADDRS) {
7117 *rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST;
7118 vnic->mc_list_count = 0;
7119 return false;
7120 }
7121 haddr = ha->addr;
7122 if (!ether_addr_equal(haddr, vnic->mc_list + off)) {
7123 memcpy(vnic->mc_list + off, haddr, ETH_ALEN);
7124 update = true;
7125 }
7126 off += ETH_ALEN;
7127 mc_count++;
7128 }
7129 if (mc_count)
7130 *rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_MCAST;
7131
7132 if (mc_count != vnic->mc_list_count) {
7133 vnic->mc_list_count = mc_count;
7134 update = true;
7135 }
7136 return update;
7137}
7138
7139static bool bnxt_uc_list_updated(struct bnxt *bp)
7140{
7141 struct net_device *dev = bp->dev;
7142 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
7143 struct netdev_hw_addr *ha;
7144 int off = 0;
7145
7146 if (netdev_uc_count(dev) != (vnic->uc_filter_count - 1))
7147 return true;
7148
7149 netdev_for_each_uc_addr(ha, dev) {
7150 if (!ether_addr_equal(ha->addr, vnic->uc_list + off))
7151 return true;
7152
7153 off += ETH_ALEN;
7154 }
7155 return false;
7156}
7157
7158static void bnxt_set_rx_mode(struct net_device *dev)
7159{
7160 struct bnxt *bp = netdev_priv(dev);
7161 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
7162 u32 mask = vnic->rx_mask;
7163 bool mc_update = false;
7164 bool uc_update;
7165
7166 if (!netif_running(dev))
7167 return;
7168
7169 mask &= ~(CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS |
7170 CFA_L2_SET_RX_MASK_REQ_MASK_MCAST |
7171 CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST);
7172
Michael Chan17c71ac2016-07-01 18:46:27 -04007173 if ((dev->flags & IFF_PROMISC) && bnxt_promisc_ok(bp))
Michael Chanc0c050c2015-10-22 16:01:17 -04007174 mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS;
7175
7176 uc_update = bnxt_uc_list_updated(bp);
7177
7178 if (dev->flags & IFF_ALLMULTI) {
7179 mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST;
7180 vnic->mc_list_count = 0;
7181 } else {
7182 mc_update = bnxt_mc_list_updated(bp, &mask);
7183 }
7184
7185 if (mask != vnic->rx_mask || uc_update || mc_update) {
7186 vnic->rx_mask = mask;
7187
7188 set_bit(BNXT_RX_MASK_SP_EVENT, &bp->sp_event);
Michael Chanc213eae2017-10-13 21:09:29 -04007189 bnxt_queue_sp_work(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04007190 }
7191}
7192
Michael Chanb664f002015-12-02 01:54:08 -05007193static int bnxt_cfg_rx_mode(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04007194{
7195 struct net_device *dev = bp->dev;
7196 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
7197 struct netdev_hw_addr *ha;
7198 int i, off = 0, rc;
7199 bool uc_update;
7200
7201 netif_addr_lock_bh(dev);
7202 uc_update = bnxt_uc_list_updated(bp);
7203 netif_addr_unlock_bh(dev);
7204
7205 if (!uc_update)
7206 goto skip_uc;
7207
7208 mutex_lock(&bp->hwrm_cmd_lock);
7209 for (i = 1; i < vnic->uc_filter_count; i++) {
7210 struct hwrm_cfa_l2_filter_free_input req = {0};
7211
7212 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_L2_FILTER_FREE, -1,
7213 -1);
7214
7215 req.l2_filter_id = vnic->fw_l2_filter_id[i];
7216
7217 rc = _hwrm_send_message(bp, &req, sizeof(req),
7218 HWRM_CMD_TIMEOUT);
7219 }
7220 mutex_unlock(&bp->hwrm_cmd_lock);
7221
7222 vnic->uc_filter_count = 1;
7223
7224 netif_addr_lock_bh(dev);
7225 if (netdev_uc_count(dev) > (BNXT_MAX_UC_ADDRS - 1)) {
7226 vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS;
7227 } else {
7228 netdev_for_each_uc_addr(ha, dev) {
7229 memcpy(vnic->uc_list + off, ha->addr, ETH_ALEN);
7230 off += ETH_ALEN;
7231 vnic->uc_filter_count++;
7232 }
7233 }
7234 netif_addr_unlock_bh(dev);
7235
7236 for (i = 1, off = 0; i < vnic->uc_filter_count; i++, off += ETH_ALEN) {
7237 rc = bnxt_hwrm_set_vnic_filter(bp, 0, i, vnic->uc_list + off);
7238 if (rc) {
7239 netdev_err(bp->dev, "HWRM vnic filter failure rc: %x\n",
7240 rc);
7241 vnic->uc_filter_count = i;
Michael Chanb664f002015-12-02 01:54:08 -05007242 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04007243 }
7244 }
7245
7246skip_uc:
7247 rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, 0);
7248 if (rc)
7249 netdev_err(bp->dev, "HWRM cfa l2 rx mask failure rc: %x\n",
7250 rc);
Michael Chanb664f002015-12-02 01:54:08 -05007251
7252 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04007253}
7254
Michael Chan8079e8f2016-12-29 12:13:37 -05007255/* If the chip and firmware supports RFS */
7256static bool bnxt_rfs_supported(struct bnxt *bp)
7257{
7258 if (BNXT_PF(bp) && !BNXT_CHIP_TYPE_NITRO_A0(bp))
7259 return true;
Michael Chanae10ae72016-12-29 12:13:38 -05007260 if (bp->flags & BNXT_FLAG_NEW_RSS_CAP)
7261 return true;
Michael Chan8079e8f2016-12-29 12:13:37 -05007262 return false;
7263}
7264
7265/* If runtime conditions support RFS */
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007266static bool bnxt_rfs_capable(struct bnxt *bp)
7267{
7268#ifdef CONFIG_RFS_ACCEL
Michael Chan8079e8f2016-12-29 12:13:37 -05007269 int vnics, max_vnics, max_rss_ctxs;
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007270
Michael Chan964fd482017-02-12 19:18:13 -05007271 if (!(bp->flags & BNXT_FLAG_MSIX_CAP))
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007272 return false;
7273
7274 vnics = 1 + bp->rx_nr_rings;
Michael Chan8079e8f2016-12-29 12:13:37 -05007275 max_vnics = bnxt_get_max_func_vnics(bp);
7276 max_rss_ctxs = bnxt_get_max_func_rss_ctxs(bp);
Michael Chanae10ae72016-12-29 12:13:38 -05007277
7278 /* RSS contexts not a limiting factor */
7279 if (bp->flags & BNXT_FLAG_NEW_RSS_CAP)
7280 max_rss_ctxs = max_vnics;
Michael Chan8079e8f2016-12-29 12:13:37 -05007281 if (vnics > max_vnics || vnics > max_rss_ctxs) {
Michael Chan6a1eef52018-01-17 03:21:10 -05007282 if (bp->rx_nr_rings > 1)
7283 netdev_warn(bp->dev,
7284 "Not enough resources to support NTUPLE filters, enough resources for up to %d rx rings\n",
7285 min(max_rss_ctxs - 1, max_vnics - 1));
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007286 return false;
Vasundhara Volama2304902016-07-25 12:33:36 -04007287 }
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007288
Michael Chan6a1eef52018-01-17 03:21:10 -05007289 if (!(bp->flags & BNXT_FLAG_NEW_RM))
7290 return true;
7291
7292 if (vnics == bp->hw_resc.resv_vnics)
7293 return true;
7294
7295 bnxt_hwrm_reserve_rings(bp, 0, 0, 0, 0, vnics);
7296 if (vnics <= bp->hw_resc.resv_vnics)
7297 return true;
7298
7299 netdev_warn(bp->dev, "Unable to reserve resources to support NTUPLE filters.\n");
7300 bnxt_hwrm_reserve_rings(bp, 0, 0, 0, 0, 1);
7301 return false;
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007302#else
7303 return false;
7304#endif
7305}
7306
Michael Chanc0c050c2015-10-22 16:01:17 -04007307static netdev_features_t bnxt_fix_features(struct net_device *dev,
7308 netdev_features_t features)
7309{
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007310 struct bnxt *bp = netdev_priv(dev);
7311
Vasundhara Volama2304902016-07-25 12:33:36 -04007312 if ((features & NETIF_F_NTUPLE) && !bnxt_rfs_capable(bp))
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007313 features &= ~NETIF_F_NTUPLE;
Michael Chan5a9f6b22016-06-06 02:37:15 -04007314
Michael Chan1054aee2017-12-16 03:09:42 -05007315 if (bp->flags & BNXT_FLAG_NO_AGG_RINGS)
7316 features &= ~(NETIF_F_LRO | NETIF_F_GRO_HW);
7317
7318 if (!(features & NETIF_F_GRO))
7319 features &= ~NETIF_F_GRO_HW;
7320
7321 if (features & NETIF_F_GRO_HW)
7322 features &= ~NETIF_F_LRO;
7323
Michael Chan5a9f6b22016-06-06 02:37:15 -04007324 /* Both CTAG and STAG VLAN accelaration on the RX side have to be
7325 * turned on or off together.
7326 */
7327 if ((features & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX)) !=
7328 (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX)) {
7329 if (dev->features & NETIF_F_HW_VLAN_CTAG_RX)
7330 features &= ~(NETIF_F_HW_VLAN_CTAG_RX |
7331 NETIF_F_HW_VLAN_STAG_RX);
7332 else
7333 features |= NETIF_F_HW_VLAN_CTAG_RX |
7334 NETIF_F_HW_VLAN_STAG_RX;
7335 }
Michael Chancf6645f2016-06-13 02:25:28 -04007336#ifdef CONFIG_BNXT_SRIOV
7337 if (BNXT_VF(bp)) {
7338 if (bp->vf.vlan) {
7339 features &= ~(NETIF_F_HW_VLAN_CTAG_RX |
7340 NETIF_F_HW_VLAN_STAG_RX);
7341 }
7342 }
7343#endif
Michael Chanc0c050c2015-10-22 16:01:17 -04007344 return features;
7345}
7346
7347static int bnxt_set_features(struct net_device *dev, netdev_features_t features)
7348{
7349 struct bnxt *bp = netdev_priv(dev);
7350 u32 flags = bp->flags;
7351 u32 changes;
7352 int rc = 0;
7353 bool re_init = false;
7354 bool update_tpa = false;
7355
7356 flags &= ~BNXT_FLAG_ALL_CONFIG_FEATS;
Michael Chan1054aee2017-12-16 03:09:42 -05007357 if (features & NETIF_F_GRO_HW)
Michael Chanc0c050c2015-10-22 16:01:17 -04007358 flags |= BNXT_FLAG_GRO;
Michael Chan1054aee2017-12-16 03:09:42 -05007359 else if (features & NETIF_F_LRO)
Michael Chanc0c050c2015-10-22 16:01:17 -04007360 flags |= BNXT_FLAG_LRO;
7361
Michael Chanbdbd1eb2016-12-29 12:13:43 -05007362 if (bp->flags & BNXT_FLAG_NO_AGG_RINGS)
7363 flags &= ~BNXT_FLAG_TPA;
7364
Michael Chanc0c050c2015-10-22 16:01:17 -04007365 if (features & NETIF_F_HW_VLAN_CTAG_RX)
7366 flags |= BNXT_FLAG_STRIP_VLAN;
7367
7368 if (features & NETIF_F_NTUPLE)
7369 flags |= BNXT_FLAG_RFS;
7370
7371 changes = flags ^ bp->flags;
7372 if (changes & BNXT_FLAG_TPA) {
7373 update_tpa = true;
7374 if ((bp->flags & BNXT_FLAG_TPA) == 0 ||
7375 (flags & BNXT_FLAG_TPA) == 0)
7376 re_init = true;
7377 }
7378
7379 if (changes & ~BNXT_FLAG_TPA)
7380 re_init = true;
7381
7382 if (flags != bp->flags) {
7383 u32 old_flags = bp->flags;
7384
7385 bp->flags = flags;
7386
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007387 if (!test_bit(BNXT_STATE_OPEN, &bp->state)) {
Michael Chanc0c050c2015-10-22 16:01:17 -04007388 if (update_tpa)
7389 bnxt_set_ring_params(bp);
7390 return rc;
7391 }
7392
7393 if (re_init) {
7394 bnxt_close_nic(bp, false, false);
7395 if (update_tpa)
7396 bnxt_set_ring_params(bp);
7397
7398 return bnxt_open_nic(bp, false, false);
7399 }
7400 if (update_tpa) {
7401 rc = bnxt_set_tpa(bp,
7402 (flags & BNXT_FLAG_TPA) ?
7403 true : false);
7404 if (rc)
7405 bp->flags = old_flags;
7406 }
7407 }
7408 return rc;
7409}
7410
Michael Chan9f554592016-01-02 23:44:58 -05007411static void bnxt_dump_tx_sw_state(struct bnxt_napi *bnapi)
7412{
Michael Chanb6ab4b02016-01-02 23:44:59 -05007413 struct bnxt_tx_ring_info *txr = bnapi->tx_ring;
Michael Chan9f554592016-01-02 23:44:58 -05007414 int i = bnapi->index;
7415
Michael Chan3b2b7d92016-01-02 23:45:00 -05007416 if (!txr)
7417 return;
7418
Michael Chan9f554592016-01-02 23:44:58 -05007419 netdev_info(bnapi->bp->dev, "[%d]: tx{fw_ring: %d prod: %x cons: %x}\n",
7420 i, txr->tx_ring_struct.fw_ring_id, txr->tx_prod,
7421 txr->tx_cons);
7422}
7423
7424static void bnxt_dump_rx_sw_state(struct bnxt_napi *bnapi)
7425{
Michael Chanb6ab4b02016-01-02 23:44:59 -05007426 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
Michael Chan9f554592016-01-02 23:44:58 -05007427 int i = bnapi->index;
7428
Michael Chan3b2b7d92016-01-02 23:45:00 -05007429 if (!rxr)
7430 return;
7431
Michael Chan9f554592016-01-02 23:44:58 -05007432 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",
7433 i, rxr->rx_ring_struct.fw_ring_id, rxr->rx_prod,
7434 rxr->rx_agg_ring_struct.fw_ring_id, rxr->rx_agg_prod,
7435 rxr->rx_sw_agg_prod);
7436}
7437
7438static void bnxt_dump_cp_sw_state(struct bnxt_napi *bnapi)
7439{
7440 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
7441 int i = bnapi->index;
7442
7443 netdev_info(bnapi->bp->dev, "[%d]: cp{fw_ring: %d raw_cons: %x}\n",
7444 i, cpr->cp_ring_struct.fw_ring_id, cpr->cp_raw_cons);
7445}
7446
Michael Chanc0c050c2015-10-22 16:01:17 -04007447static void bnxt_dbg_dump_states(struct bnxt *bp)
7448{
7449 int i;
7450 struct bnxt_napi *bnapi;
Michael Chanc0c050c2015-10-22 16:01:17 -04007451
7452 for (i = 0; i < bp->cp_nr_rings; i++) {
7453 bnapi = bp->bnapi[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04007454 if (netif_msg_drv(bp)) {
Michael Chan9f554592016-01-02 23:44:58 -05007455 bnxt_dump_tx_sw_state(bnapi);
7456 bnxt_dump_rx_sw_state(bnapi);
7457 bnxt_dump_cp_sw_state(bnapi);
Michael Chanc0c050c2015-10-22 16:01:17 -04007458 }
7459 }
7460}
7461
Michael Chan6988bd92016-06-13 02:25:29 -04007462static void bnxt_reset_task(struct bnxt *bp, bool silent)
Michael Chanc0c050c2015-10-22 16:01:17 -04007463{
Michael Chan6988bd92016-06-13 02:25:29 -04007464 if (!silent)
7465 bnxt_dbg_dump_states(bp);
Michael Chan028de142015-12-09 19:35:44 -05007466 if (netif_running(bp->dev)) {
Michael Chanb386cd32017-03-08 18:44:33 -05007467 int rc;
7468
7469 if (!silent)
7470 bnxt_ulp_stop(bp);
Michael Chan028de142015-12-09 19:35:44 -05007471 bnxt_close_nic(bp, false, false);
Michael Chanb386cd32017-03-08 18:44:33 -05007472 rc = bnxt_open_nic(bp, false, false);
7473 if (!silent && !rc)
7474 bnxt_ulp_start(bp);
Michael Chan028de142015-12-09 19:35:44 -05007475 }
Michael Chanc0c050c2015-10-22 16:01:17 -04007476}
7477
7478static void bnxt_tx_timeout(struct net_device *dev)
7479{
7480 struct bnxt *bp = netdev_priv(dev);
7481
7482 netdev_err(bp->dev, "TX timeout detected, starting reset task!\n");
7483 set_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event);
Michael Chanc213eae2017-10-13 21:09:29 -04007484 bnxt_queue_sp_work(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04007485}
7486
7487#ifdef CONFIG_NET_POLL_CONTROLLER
7488static void bnxt_poll_controller(struct net_device *dev)
7489{
7490 struct bnxt *bp = netdev_priv(dev);
7491 int i;
7492
Michael Chan2270bc52017-06-23 14:01:01 -04007493 /* Only process tx rings/combined rings in netpoll mode. */
7494 for (i = 0; i < bp->tx_nr_rings; i++) {
7495 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04007496
Michael Chan2270bc52017-06-23 14:01:01 -04007497 napi_schedule(&txr->bnapi->napi);
Michael Chanc0c050c2015-10-22 16:01:17 -04007498 }
7499}
7500#endif
7501
Kees Cooke99e88a2017-10-16 14:43:17 -07007502static void bnxt_timer(struct timer_list *t)
Michael Chanc0c050c2015-10-22 16:01:17 -04007503{
Kees Cooke99e88a2017-10-16 14:43:17 -07007504 struct bnxt *bp = from_timer(bp, t, timer);
Michael Chanc0c050c2015-10-22 16:01:17 -04007505 struct net_device *dev = bp->dev;
7506
7507 if (!netif_running(dev))
7508 return;
7509
7510 if (atomic_read(&bp->intr_sem) != 0)
7511 goto bnxt_restart_timer;
7512
Michael Chanadcc3312017-07-24 12:34:24 -04007513 if (bp->link_info.link_up && (bp->flags & BNXT_FLAG_PORT_STATS) &&
7514 bp->stats_coal_ticks) {
Michael Chan3bdf56c2016-03-07 15:38:45 -05007515 set_bit(BNXT_PERIODIC_STATS_SP_EVENT, &bp->sp_event);
Michael Chanc213eae2017-10-13 21:09:29 -04007516 bnxt_queue_sp_work(bp);
Michael Chan3bdf56c2016-03-07 15:38:45 -05007517 }
Sathya Perla5a84acb2017-10-26 11:51:31 -04007518
7519 if (bnxt_tc_flower_enabled(bp)) {
7520 set_bit(BNXT_FLOW_STATS_SP_EVENT, &bp->sp_event);
7521 bnxt_queue_sp_work(bp);
7522 }
Michael Chanc0c050c2015-10-22 16:01:17 -04007523bnxt_restart_timer:
7524 mod_timer(&bp->timer, jiffies + bp->current_interval);
7525}
7526
Michael Chana551ee92017-01-25 02:55:07 -05007527static void bnxt_rtnl_lock_sp(struct bnxt *bp)
Michael Chan6988bd92016-06-13 02:25:29 -04007528{
Michael Chana551ee92017-01-25 02:55:07 -05007529 /* We are called from bnxt_sp_task which has BNXT_STATE_IN_SP_TASK
7530 * set. If the device is being closed, bnxt_close() may be holding
Michael Chan6988bd92016-06-13 02:25:29 -04007531 * rtnl() and waiting for BNXT_STATE_IN_SP_TASK to clear. So we
7532 * must clear BNXT_STATE_IN_SP_TASK before holding rtnl().
7533 */
7534 clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
7535 rtnl_lock();
Michael Chana551ee92017-01-25 02:55:07 -05007536}
7537
7538static void bnxt_rtnl_unlock_sp(struct bnxt *bp)
7539{
Michael Chan6988bd92016-06-13 02:25:29 -04007540 set_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
7541 rtnl_unlock();
7542}
7543
Michael Chana551ee92017-01-25 02:55:07 -05007544/* Only called from bnxt_sp_task() */
7545static void bnxt_reset(struct bnxt *bp, bool silent)
7546{
7547 bnxt_rtnl_lock_sp(bp);
7548 if (test_bit(BNXT_STATE_OPEN, &bp->state))
7549 bnxt_reset_task(bp, silent);
7550 bnxt_rtnl_unlock_sp(bp);
7551}
7552
Michael Chanc0c050c2015-10-22 16:01:17 -04007553static void bnxt_cfg_ntp_filters(struct bnxt *);
7554
7555static void bnxt_sp_task(struct work_struct *work)
7556{
7557 struct bnxt *bp = container_of(work, struct bnxt, sp_task);
Michael Chanc0c050c2015-10-22 16:01:17 -04007558
Michael Chan4cebdce2015-12-09 19:35:43 -05007559 set_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
7560 smp_mb__after_atomic();
7561 if (!test_bit(BNXT_STATE_OPEN, &bp->state)) {
7562 clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
Michael Chanc0c050c2015-10-22 16:01:17 -04007563 return;
Michael Chan4cebdce2015-12-09 19:35:43 -05007564 }
Michael Chanc0c050c2015-10-22 16:01:17 -04007565
7566 if (test_and_clear_bit(BNXT_RX_MASK_SP_EVENT, &bp->sp_event))
7567 bnxt_cfg_rx_mode(bp);
7568
7569 if (test_and_clear_bit(BNXT_RX_NTP_FLTR_SP_EVENT, &bp->sp_event))
7570 bnxt_cfg_ntp_filters(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04007571 if (test_and_clear_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT, &bp->sp_event))
7572 bnxt_hwrm_exec_fwd_req(bp);
7573 if (test_and_clear_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT, &bp->sp_event)) {
7574 bnxt_hwrm_tunnel_dst_port_alloc(
7575 bp, bp->vxlan_port,
7576 TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN);
7577 }
7578 if (test_and_clear_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT, &bp->sp_event)) {
7579 bnxt_hwrm_tunnel_dst_port_free(
7580 bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN);
7581 }
Alexander Duyck7cdd5fc2016-06-16 12:21:36 -07007582 if (test_and_clear_bit(BNXT_GENEVE_ADD_PORT_SP_EVENT, &bp->sp_event)) {
7583 bnxt_hwrm_tunnel_dst_port_alloc(
7584 bp, bp->nge_port,
7585 TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE);
7586 }
7587 if (test_and_clear_bit(BNXT_GENEVE_DEL_PORT_SP_EVENT, &bp->sp_event)) {
7588 bnxt_hwrm_tunnel_dst_port_free(
7589 bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE);
7590 }
Vasundhara Volam00db3cb2018-03-31 13:54:12 -04007591 if (test_and_clear_bit(BNXT_PERIODIC_STATS_SP_EVENT, &bp->sp_event)) {
Michael Chan3bdf56c2016-03-07 15:38:45 -05007592 bnxt_hwrm_port_qstats(bp);
Vasundhara Volam00db3cb2018-03-31 13:54:12 -04007593 bnxt_hwrm_port_qstats_ext(bp);
7594 }
Michael Chan3bdf56c2016-03-07 15:38:45 -05007595
Michael Chan0eaa24b2017-01-25 02:55:08 -05007596 if (test_and_clear_bit(BNXT_LINK_CHNG_SP_EVENT, &bp->sp_event)) {
Michael Chane2dc9b62017-10-13 21:09:30 -04007597 int rc;
Michael Chan0eaa24b2017-01-25 02:55:08 -05007598
Michael Chane2dc9b62017-10-13 21:09:30 -04007599 mutex_lock(&bp->link_lock);
Michael Chan0eaa24b2017-01-25 02:55:08 -05007600 if (test_and_clear_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT,
7601 &bp->sp_event))
7602 bnxt_hwrm_phy_qcaps(bp);
7603
Michael Chane2dc9b62017-10-13 21:09:30 -04007604 rc = bnxt_update_link(bp, true);
7605 mutex_unlock(&bp->link_lock);
Michael Chan0eaa24b2017-01-25 02:55:08 -05007606 if (rc)
7607 netdev_err(bp->dev, "SP task can't update link (rc: %x)\n",
7608 rc);
7609 }
Michael Chan90c694b2017-01-25 02:55:09 -05007610 if (test_and_clear_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT, &bp->sp_event)) {
Michael Chane2dc9b62017-10-13 21:09:30 -04007611 mutex_lock(&bp->link_lock);
7612 bnxt_get_port_module_status(bp);
7613 mutex_unlock(&bp->link_lock);
Michael Chan90c694b2017-01-25 02:55:09 -05007614 }
Sathya Perla5a84acb2017-10-26 11:51:31 -04007615
7616 if (test_and_clear_bit(BNXT_FLOW_STATS_SP_EVENT, &bp->sp_event))
7617 bnxt_tc_flow_stats_work(bp);
7618
Michael Chane2dc9b62017-10-13 21:09:30 -04007619 /* These functions below will clear BNXT_STATE_IN_SP_TASK. They
7620 * must be the last functions to be called before exiting.
7621 */
Michael Chanc0c050c2015-10-22 16:01:17 -04007622 if (test_and_clear_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event))
7623 bnxt_reset(bp, false);
7624
7625 if (test_and_clear_bit(BNXT_RESET_TASK_SILENT_SP_EVENT, &bp->sp_event))
7626 bnxt_reset(bp, true);
7627
Michael Chanc0c050c2015-10-22 16:01:17 -04007628 smp_mb__before_atomic();
7629 clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
7630}
7631
Michael Chand1e79252017-02-06 16:55:38 -05007632/* Under rtnl_lock */
Michael Chan98fdbe72017-08-28 13:40:26 -04007633int bnxt_check_rings(struct bnxt *bp, int tx, int rx, bool sh, int tcs,
7634 int tx_xdp)
Michael Chand1e79252017-02-06 16:55:38 -05007635{
7636 int max_rx, max_tx, tx_sets = 1;
7637 int tx_rings_needed;
Michael Chan8f23d632018-01-17 03:21:12 -05007638 int rx_rings = rx;
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05007639 int cp, vnics, rc;
Michael Chand1e79252017-02-06 16:55:38 -05007640
Michael Chand1e79252017-02-06 16:55:38 -05007641 if (tcs)
7642 tx_sets = tcs;
7643
7644 rc = bnxt_get_max_rings(bp, &max_rx, &max_tx, sh);
7645 if (rc)
7646 return rc;
7647
7648 if (max_rx < rx)
7649 return -ENOMEM;
7650
Michael Chan5f449242017-02-06 16:55:40 -05007651 tx_rings_needed = tx * tx_sets + tx_xdp;
Michael Chand1e79252017-02-06 16:55:38 -05007652 if (max_tx < tx_rings_needed)
7653 return -ENOMEM;
7654
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05007655 vnics = 1;
7656 if (bp->flags & BNXT_FLAG_RFS)
7657 vnics += rx_rings;
7658
Michael Chan8f23d632018-01-17 03:21:12 -05007659 if (bp->flags & BNXT_FLAG_AGG_RINGS)
7660 rx_rings <<= 1;
7661 cp = sh ? max_t(int, tx_rings_needed, rx) : tx_rings_needed + rx;
Michael Chan11c3ec72018-04-11 11:50:17 -04007662 if (bp->flags & BNXT_FLAG_NEW_RM)
7663 cp += bnxt_get_ulp_msix_num(bp);
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05007664 return bnxt_hwrm_check_rings(bp, tx_rings_needed, rx_rings, rx, cp,
7665 vnics);
Michael Chand1e79252017-02-06 16:55:38 -05007666}
7667
Sathya Perla17086392017-02-20 19:25:18 -05007668static void bnxt_unmap_bars(struct bnxt *bp, struct pci_dev *pdev)
7669{
7670 if (bp->bar2) {
7671 pci_iounmap(pdev, bp->bar2);
7672 bp->bar2 = NULL;
7673 }
7674
7675 if (bp->bar1) {
7676 pci_iounmap(pdev, bp->bar1);
7677 bp->bar1 = NULL;
7678 }
7679
7680 if (bp->bar0) {
7681 pci_iounmap(pdev, bp->bar0);
7682 bp->bar0 = NULL;
7683 }
7684}
7685
7686static void bnxt_cleanup_pci(struct bnxt *bp)
7687{
7688 bnxt_unmap_bars(bp, bp->pdev);
7689 pci_release_regions(bp->pdev);
7690 pci_disable_device(bp->pdev);
7691}
7692
Michael Chan18775aa2017-10-26 11:51:27 -04007693static void bnxt_init_dflt_coal(struct bnxt *bp)
7694{
7695 struct bnxt_coal *coal;
7696
7697 /* Tick values in micro seconds.
7698 * 1 coal_buf x bufs_per_record = 1 completion record.
7699 */
7700 coal = &bp->rx_coal;
7701 coal->coal_ticks = 14;
7702 coal->coal_bufs = 30;
7703 coal->coal_ticks_irq = 1;
7704 coal->coal_bufs_irq = 2;
Andy Gospodarek05abe4dd2018-04-26 17:44:38 -04007705 coal->idle_thresh = 50;
Michael Chan18775aa2017-10-26 11:51:27 -04007706 coal->bufs_per_record = 2;
7707 coal->budget = 64; /* NAPI budget */
7708
7709 coal = &bp->tx_coal;
7710 coal->coal_ticks = 28;
7711 coal->coal_bufs = 30;
7712 coal->coal_ticks_irq = 2;
7713 coal->coal_bufs_irq = 2;
7714 coal->bufs_per_record = 1;
7715
7716 bp->stats_coal_ticks = BNXT_DEF_STATS_COAL_TICKS;
7717}
7718
Michael Chanc0c050c2015-10-22 16:01:17 -04007719static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev)
7720{
7721 int rc;
7722 struct bnxt *bp = netdev_priv(dev);
7723
7724 SET_NETDEV_DEV(dev, &pdev->dev);
7725
7726 /* enable device (incl. PCI PM wakeup), and bus-mastering */
7727 rc = pci_enable_device(pdev);
7728 if (rc) {
7729 dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n");
7730 goto init_err;
7731 }
7732
7733 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
7734 dev_err(&pdev->dev,
7735 "Cannot find PCI device base address, aborting\n");
7736 rc = -ENODEV;
7737 goto init_err_disable;
7738 }
7739
7740 rc = pci_request_regions(pdev, DRV_MODULE_NAME);
7741 if (rc) {
7742 dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting\n");
7743 goto init_err_disable;
7744 }
7745
7746 if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)) != 0 &&
7747 dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)) != 0) {
7748 dev_err(&pdev->dev, "System does not support DMA, aborting\n");
7749 goto init_err_disable;
7750 }
7751
7752 pci_set_master(pdev);
7753
7754 bp->dev = dev;
7755 bp->pdev = pdev;
7756
7757 bp->bar0 = pci_ioremap_bar(pdev, 0);
7758 if (!bp->bar0) {
7759 dev_err(&pdev->dev, "Cannot map device registers, aborting\n");
7760 rc = -ENOMEM;
7761 goto init_err_release;
7762 }
7763
7764 bp->bar1 = pci_ioremap_bar(pdev, 2);
7765 if (!bp->bar1) {
7766 dev_err(&pdev->dev, "Cannot map doorbell registers, aborting\n");
7767 rc = -ENOMEM;
7768 goto init_err_release;
7769 }
7770
7771 bp->bar2 = pci_ioremap_bar(pdev, 4);
7772 if (!bp->bar2) {
7773 dev_err(&pdev->dev, "Cannot map bar4 registers, aborting\n");
7774 rc = -ENOMEM;
7775 goto init_err_release;
7776 }
7777
Satish Baddipadige6316ea62016-03-07 15:38:48 -05007778 pci_enable_pcie_error_reporting(pdev);
7779
Michael Chanc0c050c2015-10-22 16:01:17 -04007780 INIT_WORK(&bp->sp_task, bnxt_sp_task);
7781
7782 spin_lock_init(&bp->ntp_fltr_lock);
7783
7784 bp->rx_ring_size = BNXT_DEFAULT_RX_RING_SIZE;
7785 bp->tx_ring_size = BNXT_DEFAULT_TX_RING_SIZE;
7786
Michael Chan18775aa2017-10-26 11:51:27 -04007787 bnxt_init_dflt_coal(bp);
Michael Chan51f30782016-07-01 18:46:29 -04007788
Kees Cooke99e88a2017-10-16 14:43:17 -07007789 timer_setup(&bp->timer, bnxt_timer, 0);
Michael Chanc0c050c2015-10-22 16:01:17 -04007790 bp->current_interval = BNXT_TIMER_INTERVAL;
7791
Michael Chancaefe522015-12-09 19:35:42 -05007792 clear_bit(BNXT_STATE_OPEN, &bp->state);
Michael Chanc0c050c2015-10-22 16:01:17 -04007793 return 0;
7794
7795init_err_release:
Sathya Perla17086392017-02-20 19:25:18 -05007796 bnxt_unmap_bars(bp, pdev);
Michael Chanc0c050c2015-10-22 16:01:17 -04007797 pci_release_regions(pdev);
7798
7799init_err_disable:
7800 pci_disable_device(pdev);
7801
7802init_err:
7803 return rc;
7804}
7805
7806/* rtnl_lock held */
7807static int bnxt_change_mac_addr(struct net_device *dev, void *p)
7808{
7809 struct sockaddr *addr = p;
Jeffrey Huang1fc2cfd2015-12-02 01:54:06 -05007810 struct bnxt *bp = netdev_priv(dev);
7811 int rc = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04007812
7813 if (!is_valid_ether_addr(addr->sa_data))
7814 return -EADDRNOTAVAIL;
7815
Michael Chanc1a7bdf2017-10-26 11:51:24 -04007816 if (ether_addr_equal(addr->sa_data, dev->dev_addr))
7817 return 0;
7818
Michael Chan84c33dd2016-04-11 04:11:13 -04007819 rc = bnxt_approve_mac(bp, addr->sa_data);
7820 if (rc)
7821 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04007822
Jeffrey Huang1fc2cfd2015-12-02 01:54:06 -05007823 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
7824 if (netif_running(dev)) {
7825 bnxt_close_nic(bp, false, false);
7826 rc = bnxt_open_nic(bp, false, false);
7827 }
7828
7829 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04007830}
7831
7832/* rtnl_lock held */
7833static int bnxt_change_mtu(struct net_device *dev, int new_mtu)
7834{
7835 struct bnxt *bp = netdev_priv(dev);
7836
Michael Chanc0c050c2015-10-22 16:01:17 -04007837 if (netif_running(dev))
7838 bnxt_close_nic(bp, false, false);
7839
7840 dev->mtu = new_mtu;
7841 bnxt_set_ring_params(bp);
7842
7843 if (netif_running(dev))
7844 return bnxt_open_nic(bp, false, false);
7845
7846 return 0;
7847}
7848
Michael Chanc5e3deb2016-12-02 21:17:15 -05007849int bnxt_setup_mq_tc(struct net_device *dev, u8 tc)
Michael Chanc0c050c2015-10-22 16:01:17 -04007850{
7851 struct bnxt *bp = netdev_priv(dev);
Michael Chan3ffb6a32016-11-11 00:11:42 -05007852 bool sh = false;
Michael Chand1e79252017-02-06 16:55:38 -05007853 int rc;
John Fastabend16e5cc62016-02-16 21:16:43 -08007854
Michael Chanc0c050c2015-10-22 16:01:17 -04007855 if (tc > bp->max_tc) {
Michael Chanb451c8b2017-02-12 19:18:17 -05007856 netdev_err(dev, "Too many traffic classes requested: %d. Max supported is %d.\n",
Michael Chanc0c050c2015-10-22 16:01:17 -04007857 tc, bp->max_tc);
7858 return -EINVAL;
7859 }
7860
7861 if (netdev_get_num_tc(dev) == tc)
7862 return 0;
7863
Michael Chan3ffb6a32016-11-11 00:11:42 -05007864 if (bp->flags & BNXT_FLAG_SHARED_RINGS)
7865 sh = true;
7866
Michael Chan98fdbe72017-08-28 13:40:26 -04007867 rc = bnxt_check_rings(bp, bp->tx_nr_rings_per_tc, bp->rx_nr_rings,
7868 sh, tc, bp->tx_nr_rings_xdp);
Michael Chand1e79252017-02-06 16:55:38 -05007869 if (rc)
7870 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04007871
7872 /* Needs to close the device and do hw resource re-allocations */
7873 if (netif_running(bp->dev))
7874 bnxt_close_nic(bp, true, false);
7875
7876 if (tc) {
7877 bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tc;
7878 netdev_set_num_tc(dev, tc);
7879 } else {
7880 bp->tx_nr_rings = bp->tx_nr_rings_per_tc;
7881 netdev_reset_tc(dev);
7882 }
Michael Chan87e9b372017-08-23 19:34:03 -04007883 bp->tx_nr_rings += bp->tx_nr_rings_xdp;
Michael Chan3ffb6a32016-11-11 00:11:42 -05007884 bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
7885 bp->tx_nr_rings + bp->rx_nr_rings;
Michael Chanc0c050c2015-10-22 16:01:17 -04007886 bp->num_stat_ctxs = bp->cp_nr_rings;
7887
7888 if (netif_running(bp->dev))
7889 return bnxt_open_nic(bp, true, false);
7890
7891 return 0;
7892}
7893
Jiri Pirko9e0fd152017-10-19 15:50:39 +02007894static int bnxt_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
7895 void *cb_priv)
Sathya Perla2ae74082017-08-28 13:40:33 -04007896{
Jiri Pirko9e0fd152017-10-19 15:50:39 +02007897 struct bnxt *bp = cb_priv;
Sathya Perla2ae74082017-08-28 13:40:33 -04007898
Jakub Kicinski312324f2018-01-25 14:00:48 -08007899 if (!bnxt_tc_flower_enabled(bp) ||
7900 !tc_cls_can_offload_and_chain0(bp->dev, type_data))
Sathya Perla2ae74082017-08-28 13:40:33 -04007901 return -EOPNOTSUPP;
7902
Jiri Pirko9e0fd152017-10-19 15:50:39 +02007903 switch (type) {
7904 case TC_SETUP_CLSFLOWER:
7905 return bnxt_tc_setup_flower(bp, bp->pf.fw_fid, type_data);
7906 default:
7907 return -EOPNOTSUPP;
7908 }
7909}
7910
7911static int bnxt_setup_tc_block(struct net_device *dev,
7912 struct tc_block_offload *f)
7913{
7914 struct bnxt *bp = netdev_priv(dev);
7915
7916 if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
7917 return -EOPNOTSUPP;
7918
7919 switch (f->command) {
7920 case TC_BLOCK_BIND:
7921 return tcf_block_cb_register(f->block, bnxt_setup_tc_block_cb,
7922 bp, bp);
7923 case TC_BLOCK_UNBIND:
7924 tcf_block_cb_unregister(f->block, bnxt_setup_tc_block_cb, bp);
7925 return 0;
7926 default:
7927 return -EOPNOTSUPP;
7928 }
Sathya Perla2ae74082017-08-28 13:40:33 -04007929}
7930
Jiri Pirko2572ac52017-08-07 10:15:17 +02007931static int bnxt_setup_tc(struct net_device *dev, enum tc_setup_type type,
Jiri Pirkode4784c2017-08-07 10:15:32 +02007932 void *type_data)
Michael Chanc5e3deb2016-12-02 21:17:15 -05007933{
Sathya Perla2ae74082017-08-28 13:40:33 -04007934 switch (type) {
Jiri Pirko9e0fd152017-10-19 15:50:39 +02007935 case TC_SETUP_BLOCK:
7936 return bnxt_setup_tc_block(dev, type_data);
Nogah Frankel575ed7d2017-11-06 07:23:42 +01007937 case TC_SETUP_QDISC_MQPRIO: {
Sathya Perla2ae74082017-08-28 13:40:33 -04007938 struct tc_mqprio_qopt *mqprio = type_data;
Jiri Pirkode4784c2017-08-07 10:15:32 +02007939
Sathya Perla2ae74082017-08-28 13:40:33 -04007940 mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
7941
7942 return bnxt_setup_mq_tc(dev, mqprio->num_tc);
7943 }
7944 default:
Jiri Pirko38cf0422017-08-07 10:15:31 +02007945 return -EOPNOTSUPP;
Sathya Perla2ae74082017-08-28 13:40:33 -04007946 }
Michael Chanc5e3deb2016-12-02 21:17:15 -05007947}
7948
Michael Chanc0c050c2015-10-22 16:01:17 -04007949#ifdef CONFIG_RFS_ACCEL
7950static bool bnxt_fltr_match(struct bnxt_ntuple_filter *f1,
7951 struct bnxt_ntuple_filter *f2)
7952{
7953 struct flow_keys *keys1 = &f1->fkeys;
7954 struct flow_keys *keys2 = &f2->fkeys;
7955
7956 if (keys1->addrs.v4addrs.src == keys2->addrs.v4addrs.src &&
7957 keys1->addrs.v4addrs.dst == keys2->addrs.v4addrs.dst &&
7958 keys1->ports.ports == keys2->ports.ports &&
7959 keys1->basic.ip_proto == keys2->basic.ip_proto &&
7960 keys1->basic.n_proto == keys2->basic.n_proto &&
Michael Chan61aad722017-02-12 19:18:14 -05007961 keys1->control.flags == keys2->control.flags &&
Michael Chana54c4d72016-07-25 12:33:35 -04007962 ether_addr_equal(f1->src_mac_addr, f2->src_mac_addr) &&
7963 ether_addr_equal(f1->dst_mac_addr, f2->dst_mac_addr))
Michael Chanc0c050c2015-10-22 16:01:17 -04007964 return true;
7965
7966 return false;
7967}
7968
7969static int bnxt_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
7970 u16 rxq_index, u32 flow_id)
7971{
7972 struct bnxt *bp = netdev_priv(dev);
7973 struct bnxt_ntuple_filter *fltr, *new_fltr;
7974 struct flow_keys *fkeys;
7975 struct ethhdr *eth = (struct ethhdr *)skb_mac_header(skb);
Michael Chana54c4d72016-07-25 12:33:35 -04007976 int rc = 0, idx, bit_id, l2_idx = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04007977 struct hlist_head *head;
7978
Michael Chana54c4d72016-07-25 12:33:35 -04007979 if (!ether_addr_equal(dev->dev_addr, eth->h_dest)) {
7980 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
7981 int off = 0, j;
7982
7983 netif_addr_lock_bh(dev);
7984 for (j = 0; j < vnic->uc_filter_count; j++, off += ETH_ALEN) {
7985 if (ether_addr_equal(eth->h_dest,
7986 vnic->uc_list + off)) {
7987 l2_idx = j + 1;
7988 break;
7989 }
7990 }
7991 netif_addr_unlock_bh(dev);
7992 if (!l2_idx)
7993 return -EINVAL;
7994 }
Michael Chanc0c050c2015-10-22 16:01:17 -04007995 new_fltr = kzalloc(sizeof(*new_fltr), GFP_ATOMIC);
7996 if (!new_fltr)
7997 return -ENOMEM;
7998
7999 fkeys = &new_fltr->fkeys;
8000 if (!skb_flow_dissect_flow_keys(skb, fkeys, 0)) {
8001 rc = -EPROTONOSUPPORT;
8002 goto err_free;
8003 }
8004
Michael Chandda0e742016-12-29 12:13:40 -05008005 if ((fkeys->basic.n_proto != htons(ETH_P_IP) &&
8006 fkeys->basic.n_proto != htons(ETH_P_IPV6)) ||
Michael Chanc0c050c2015-10-22 16:01:17 -04008007 ((fkeys->basic.ip_proto != IPPROTO_TCP) &&
8008 (fkeys->basic.ip_proto != IPPROTO_UDP))) {
8009 rc = -EPROTONOSUPPORT;
8010 goto err_free;
8011 }
Michael Chandda0e742016-12-29 12:13:40 -05008012 if (fkeys->basic.n_proto == htons(ETH_P_IPV6) &&
8013 bp->hwrm_spec_code < 0x10601) {
8014 rc = -EPROTONOSUPPORT;
8015 goto err_free;
8016 }
Michael Chan61aad722017-02-12 19:18:14 -05008017 if ((fkeys->control.flags & FLOW_DIS_ENCAPSULATION) &&
8018 bp->hwrm_spec_code < 0x10601) {
8019 rc = -EPROTONOSUPPORT;
8020 goto err_free;
8021 }
Michael Chanc0c050c2015-10-22 16:01:17 -04008022
Michael Chana54c4d72016-07-25 12:33:35 -04008023 memcpy(new_fltr->dst_mac_addr, eth->h_dest, ETH_ALEN);
Michael Chanc0c050c2015-10-22 16:01:17 -04008024 memcpy(new_fltr->src_mac_addr, eth->h_source, ETH_ALEN);
8025
8026 idx = skb_get_hash_raw(skb) & BNXT_NTP_FLTR_HASH_MASK;
8027 head = &bp->ntp_fltr_hash_tbl[idx];
8028 rcu_read_lock();
8029 hlist_for_each_entry_rcu(fltr, head, hash) {
8030 if (bnxt_fltr_match(fltr, new_fltr)) {
8031 rcu_read_unlock();
8032 rc = 0;
8033 goto err_free;
8034 }
8035 }
8036 rcu_read_unlock();
8037
8038 spin_lock_bh(&bp->ntp_fltr_lock);
Michael Chan84e86b92015-11-05 16:25:50 -05008039 bit_id = bitmap_find_free_region(bp->ntp_fltr_bmap,
8040 BNXT_NTP_FLTR_MAX_FLTR, 0);
8041 if (bit_id < 0) {
Michael Chanc0c050c2015-10-22 16:01:17 -04008042 spin_unlock_bh(&bp->ntp_fltr_lock);
8043 rc = -ENOMEM;
8044 goto err_free;
8045 }
8046
Michael Chan84e86b92015-11-05 16:25:50 -05008047 new_fltr->sw_id = (u16)bit_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04008048 new_fltr->flow_id = flow_id;
Michael Chana54c4d72016-07-25 12:33:35 -04008049 new_fltr->l2_fltr_idx = l2_idx;
Michael Chanc0c050c2015-10-22 16:01:17 -04008050 new_fltr->rxq = rxq_index;
8051 hlist_add_head_rcu(&new_fltr->hash, head);
8052 bp->ntp_fltr_count++;
8053 spin_unlock_bh(&bp->ntp_fltr_lock);
8054
8055 set_bit(BNXT_RX_NTP_FLTR_SP_EVENT, &bp->sp_event);
Michael Chanc213eae2017-10-13 21:09:29 -04008056 bnxt_queue_sp_work(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04008057
8058 return new_fltr->sw_id;
8059
8060err_free:
8061 kfree(new_fltr);
8062 return rc;
8063}
8064
8065static void bnxt_cfg_ntp_filters(struct bnxt *bp)
8066{
8067 int i;
8068
8069 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
8070 struct hlist_head *head;
8071 struct hlist_node *tmp;
8072 struct bnxt_ntuple_filter *fltr;
8073 int rc;
8074
8075 head = &bp->ntp_fltr_hash_tbl[i];
8076 hlist_for_each_entry_safe(fltr, tmp, head, hash) {
8077 bool del = false;
8078
8079 if (test_bit(BNXT_FLTR_VALID, &fltr->state)) {
8080 if (rps_may_expire_flow(bp->dev, fltr->rxq,
8081 fltr->flow_id,
8082 fltr->sw_id)) {
8083 bnxt_hwrm_cfa_ntuple_filter_free(bp,
8084 fltr);
8085 del = true;
8086 }
8087 } else {
8088 rc = bnxt_hwrm_cfa_ntuple_filter_alloc(bp,
8089 fltr);
8090 if (rc)
8091 del = true;
8092 else
8093 set_bit(BNXT_FLTR_VALID, &fltr->state);
8094 }
8095
8096 if (del) {
8097 spin_lock_bh(&bp->ntp_fltr_lock);
8098 hlist_del_rcu(&fltr->hash);
8099 bp->ntp_fltr_count--;
8100 spin_unlock_bh(&bp->ntp_fltr_lock);
8101 synchronize_rcu();
8102 clear_bit(fltr->sw_id, bp->ntp_fltr_bmap);
8103 kfree(fltr);
8104 }
8105 }
8106 }
Jeffrey Huang19241362016-02-26 04:00:00 -05008107 if (test_and_clear_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT, &bp->sp_event))
8108 netdev_info(bp->dev, "Receive PF driver unload event!");
Michael Chanc0c050c2015-10-22 16:01:17 -04008109}
8110
8111#else
8112
8113static void bnxt_cfg_ntp_filters(struct bnxt *bp)
8114{
8115}
8116
8117#endif /* CONFIG_RFS_ACCEL */
8118
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008119static void bnxt_udp_tunnel_add(struct net_device *dev,
8120 struct udp_tunnel_info *ti)
Michael Chanc0c050c2015-10-22 16:01:17 -04008121{
8122 struct bnxt *bp = netdev_priv(dev);
8123
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008124 if (ti->sa_family != AF_INET6 && ti->sa_family != AF_INET)
8125 return;
8126
Michael Chanc0c050c2015-10-22 16:01:17 -04008127 if (!netif_running(dev))
8128 return;
8129
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008130 switch (ti->type) {
8131 case UDP_TUNNEL_TYPE_VXLAN:
8132 if (bp->vxlan_port_cnt && bp->vxlan_port != ti->port)
8133 return;
Michael Chanc0c050c2015-10-22 16:01:17 -04008134
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008135 bp->vxlan_port_cnt++;
8136 if (bp->vxlan_port_cnt == 1) {
8137 bp->vxlan_port = ti->port;
8138 set_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT, &bp->sp_event);
Michael Chanc213eae2017-10-13 21:09:29 -04008139 bnxt_queue_sp_work(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04008140 }
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008141 break;
Alexander Duyck7cdd5fc2016-06-16 12:21:36 -07008142 case UDP_TUNNEL_TYPE_GENEVE:
8143 if (bp->nge_port_cnt && bp->nge_port != ti->port)
8144 return;
8145
8146 bp->nge_port_cnt++;
8147 if (bp->nge_port_cnt == 1) {
8148 bp->nge_port = ti->port;
8149 set_bit(BNXT_GENEVE_ADD_PORT_SP_EVENT, &bp->sp_event);
8150 }
8151 break;
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008152 default:
8153 return;
Michael Chanc0c050c2015-10-22 16:01:17 -04008154 }
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008155
Michael Chanc213eae2017-10-13 21:09:29 -04008156 bnxt_queue_sp_work(bp);
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008157}
8158
8159static void bnxt_udp_tunnel_del(struct net_device *dev,
8160 struct udp_tunnel_info *ti)
8161{
8162 struct bnxt *bp = netdev_priv(dev);
8163
8164 if (ti->sa_family != AF_INET6 && ti->sa_family != AF_INET)
8165 return;
8166
8167 if (!netif_running(dev))
8168 return;
8169
8170 switch (ti->type) {
8171 case UDP_TUNNEL_TYPE_VXLAN:
8172 if (!bp->vxlan_port_cnt || bp->vxlan_port != ti->port)
8173 return;
8174 bp->vxlan_port_cnt--;
8175
8176 if (bp->vxlan_port_cnt != 0)
8177 return;
8178
8179 set_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT, &bp->sp_event);
8180 break;
Alexander Duyck7cdd5fc2016-06-16 12:21:36 -07008181 case UDP_TUNNEL_TYPE_GENEVE:
8182 if (!bp->nge_port_cnt || bp->nge_port != ti->port)
8183 return;
8184 bp->nge_port_cnt--;
8185
8186 if (bp->nge_port_cnt != 0)
8187 return;
8188
8189 set_bit(BNXT_GENEVE_DEL_PORT_SP_EVENT, &bp->sp_event);
8190 break;
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008191 default:
8192 return;
8193 }
8194
Michael Chanc213eae2017-10-13 21:09:29 -04008195 bnxt_queue_sp_work(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04008196}
8197
Michael Chan39d8ba22017-07-24 12:34:22 -04008198static int bnxt_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
8199 struct net_device *dev, u32 filter_mask,
8200 int nlflags)
8201{
8202 struct bnxt *bp = netdev_priv(dev);
8203
8204 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, bp->br_mode, 0, 0,
8205 nlflags, filter_mask, NULL);
8206}
8207
8208static int bnxt_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh,
8209 u16 flags)
8210{
8211 struct bnxt *bp = netdev_priv(dev);
8212 struct nlattr *attr, *br_spec;
8213 int rem, rc = 0;
8214
8215 if (bp->hwrm_spec_code < 0x10708 || !BNXT_SINGLE_PF(bp))
8216 return -EOPNOTSUPP;
8217
8218 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
8219 if (!br_spec)
8220 return -EINVAL;
8221
8222 nla_for_each_nested(attr, br_spec, rem) {
8223 u16 mode;
8224
8225 if (nla_type(attr) != IFLA_BRIDGE_MODE)
8226 continue;
8227
8228 if (nla_len(attr) < sizeof(mode))
8229 return -EINVAL;
8230
8231 mode = nla_get_u16(attr);
8232 if (mode == bp->br_mode)
8233 break;
8234
8235 rc = bnxt_hwrm_set_br_mode(bp, mode);
8236 if (!rc)
8237 bp->br_mode = mode;
8238 break;
8239 }
8240 return rc;
8241}
8242
Sathya Perlac124a622017-07-24 12:34:29 -04008243static int bnxt_get_phys_port_name(struct net_device *dev, char *buf,
8244 size_t len)
8245{
8246 struct bnxt *bp = netdev_priv(dev);
8247 int rc;
8248
8249 /* The PF and it's VF-reps only support the switchdev framework */
8250 if (!BNXT_PF(bp))
8251 return -EOPNOTSUPP;
8252
Sathya Perla53f70b82017-07-25 13:28:41 -04008253 rc = snprintf(buf, len, "p%d", bp->pf.port_id);
Sathya Perlac124a622017-07-24 12:34:29 -04008254
8255 if (rc >= len)
8256 return -EOPNOTSUPP;
8257 return 0;
8258}
8259
8260int bnxt_port_attr_get(struct bnxt *bp, struct switchdev_attr *attr)
8261{
8262 if (bp->eswitch_mode != DEVLINK_ESWITCH_MODE_SWITCHDEV)
8263 return -EOPNOTSUPP;
8264
8265 /* The PF and it's VF-reps only support the switchdev framework */
8266 if (!BNXT_PF(bp))
8267 return -EOPNOTSUPP;
8268
8269 switch (attr->id) {
8270 case SWITCHDEV_ATTR_ID_PORT_PARENT_ID:
Sathya Perladd4ea1d2018-01-17 03:21:16 -05008271 attr->u.ppid.id_len = sizeof(bp->switch_id);
8272 memcpy(attr->u.ppid.id, bp->switch_id, attr->u.ppid.id_len);
Sathya Perlac124a622017-07-24 12:34:29 -04008273 break;
8274 default:
8275 return -EOPNOTSUPP;
8276 }
8277 return 0;
8278}
8279
8280static int bnxt_swdev_port_attr_get(struct net_device *dev,
8281 struct switchdev_attr *attr)
8282{
8283 return bnxt_port_attr_get(netdev_priv(dev), attr);
8284}
8285
8286static const struct switchdev_ops bnxt_switchdev_ops = {
8287 .switchdev_port_attr_get = bnxt_swdev_port_attr_get
8288};
8289
Michael Chanc0c050c2015-10-22 16:01:17 -04008290static const struct net_device_ops bnxt_netdev_ops = {
8291 .ndo_open = bnxt_open,
8292 .ndo_start_xmit = bnxt_start_xmit,
8293 .ndo_stop = bnxt_close,
8294 .ndo_get_stats64 = bnxt_get_stats64,
8295 .ndo_set_rx_mode = bnxt_set_rx_mode,
8296 .ndo_do_ioctl = bnxt_ioctl,
8297 .ndo_validate_addr = eth_validate_addr,
8298 .ndo_set_mac_address = bnxt_change_mac_addr,
8299 .ndo_change_mtu = bnxt_change_mtu,
8300 .ndo_fix_features = bnxt_fix_features,
8301 .ndo_set_features = bnxt_set_features,
8302 .ndo_tx_timeout = bnxt_tx_timeout,
8303#ifdef CONFIG_BNXT_SRIOV
8304 .ndo_get_vf_config = bnxt_get_vf_config,
8305 .ndo_set_vf_mac = bnxt_set_vf_mac,
8306 .ndo_set_vf_vlan = bnxt_set_vf_vlan,
8307 .ndo_set_vf_rate = bnxt_set_vf_bw,
8308 .ndo_set_vf_link_state = bnxt_set_vf_link_state,
8309 .ndo_set_vf_spoofchk = bnxt_set_vf_spoofchk,
Vasundhara Volam746df132018-03-31 13:54:10 -04008310 .ndo_set_vf_trust = bnxt_set_vf_trust,
Michael Chanc0c050c2015-10-22 16:01:17 -04008311#endif
8312#ifdef CONFIG_NET_POLL_CONTROLLER
8313 .ndo_poll_controller = bnxt_poll_controller,
8314#endif
8315 .ndo_setup_tc = bnxt_setup_tc,
8316#ifdef CONFIG_RFS_ACCEL
8317 .ndo_rx_flow_steer = bnxt_rx_flow_steer,
8318#endif
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008319 .ndo_udp_tunnel_add = bnxt_udp_tunnel_add,
8320 .ndo_udp_tunnel_del = bnxt_udp_tunnel_del,
Jakub Kicinskif4e63522017-11-03 13:56:16 -07008321 .ndo_bpf = bnxt_xdp,
Michael Chan39d8ba22017-07-24 12:34:22 -04008322 .ndo_bridge_getlink = bnxt_bridge_getlink,
8323 .ndo_bridge_setlink = bnxt_bridge_setlink,
Sathya Perlac124a622017-07-24 12:34:29 -04008324 .ndo_get_phys_port_name = bnxt_get_phys_port_name
Michael Chanc0c050c2015-10-22 16:01:17 -04008325};
8326
8327static void bnxt_remove_one(struct pci_dev *pdev)
8328{
8329 struct net_device *dev = pci_get_drvdata(pdev);
8330 struct bnxt *bp = netdev_priv(dev);
8331
Sathya Perla4ab0c6a2017-07-24 12:34:27 -04008332 if (BNXT_PF(bp)) {
Michael Chanc0c050c2015-10-22 16:01:17 -04008333 bnxt_sriov_disable(bp);
Sathya Perla4ab0c6a2017-07-24 12:34:27 -04008334 bnxt_dl_unregister(bp);
8335 }
Michael Chanc0c050c2015-10-22 16:01:17 -04008336
Satish Baddipadige6316ea62016-03-07 15:38:48 -05008337 pci_disable_pcie_error_reporting(pdev);
Michael Chanc0c050c2015-10-22 16:01:17 -04008338 unregister_netdev(dev);
Sathya Perla2ae74082017-08-28 13:40:33 -04008339 bnxt_shutdown_tc(bp);
Michael Chanc213eae2017-10-13 21:09:29 -04008340 bnxt_cancel_sp_work(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04008341 bp->sp_event = 0;
8342
Michael Chan78095922016-12-07 00:26:16 -05008343 bnxt_clear_int_mode(bp);
Jeffrey Huangbe58a0d2015-12-27 18:19:18 -05008344 bnxt_hwrm_func_drv_unrgtr(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04008345 bnxt_free_hwrm_resources(bp);
Deepak Khungare605db82017-05-29 19:06:04 -04008346 bnxt_free_hwrm_short_cmd_req(bp);
Michael Chaneb513652017-04-04 18:14:12 -04008347 bnxt_ethtool_free(bp);
Michael Chan7df4ae92016-12-02 21:17:17 -05008348 bnxt_dcb_free(bp);
Michael Chana588e452016-12-07 00:26:21 -05008349 kfree(bp->edev);
8350 bp->edev = NULL;
Sathya Perla17086392017-02-20 19:25:18 -05008351 bnxt_cleanup_pci(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04008352 free_netdev(dev);
Michael Chanc0c050c2015-10-22 16:01:17 -04008353}
8354
8355static int bnxt_probe_phy(struct bnxt *bp)
8356{
8357 int rc = 0;
8358 struct bnxt_link_info *link_info = &bp->link_info;
Michael Chanc0c050c2015-10-22 16:01:17 -04008359
Michael Chan170ce012016-04-05 14:08:57 -04008360 rc = bnxt_hwrm_phy_qcaps(bp);
8361 if (rc) {
8362 netdev_err(bp->dev, "Probe phy can't get phy capabilities (rc: %x)\n",
8363 rc);
8364 return rc;
8365 }
Michael Chane2dc9b62017-10-13 21:09:30 -04008366 mutex_init(&bp->link_lock);
Michael Chan170ce012016-04-05 14:08:57 -04008367
Michael Chanc0c050c2015-10-22 16:01:17 -04008368 rc = bnxt_update_link(bp, false);
8369 if (rc) {
8370 netdev_err(bp->dev, "Probe phy can't update link (rc: %x)\n",
8371 rc);
8372 return rc;
8373 }
8374
Michael Chan93ed8112016-06-13 02:25:37 -04008375 /* Older firmware does not have supported_auto_speeds, so assume
8376 * that all supported speeds can be autonegotiated.
8377 */
8378 if (link_info->auto_link_speeds && !link_info->support_auto_speeds)
8379 link_info->support_auto_speeds = link_info->support_speeds;
8380
Michael Chanc0c050c2015-10-22 16:01:17 -04008381 /*initialize the ethool setting copy with NVM settings */
Michael Chan0d8abf02016-02-10 17:33:47 -05008382 if (BNXT_AUTO_MODE(link_info->auto_mode)) {
Michael Chanc9ee9512016-04-05 14:08:56 -04008383 link_info->autoneg = BNXT_AUTONEG_SPEED;
8384 if (bp->hwrm_spec_code >= 0x10201) {
8385 if (link_info->auto_pause_setting &
8386 PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE)
8387 link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
8388 } else {
8389 link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
8390 }
Michael Chan0d8abf02016-02-10 17:33:47 -05008391 link_info->advertising = link_info->auto_link_speeds;
Michael Chan0d8abf02016-02-10 17:33:47 -05008392 } else {
8393 link_info->req_link_speed = link_info->force_link_speed;
8394 link_info->req_duplex = link_info->duplex_setting;
Michael Chanc0c050c2015-10-22 16:01:17 -04008395 }
Michael Chanc9ee9512016-04-05 14:08:56 -04008396 if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL)
8397 link_info->req_flow_ctrl =
8398 link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH;
8399 else
8400 link_info->req_flow_ctrl = link_info->force_pause_setting;
Michael Chanc0c050c2015-10-22 16:01:17 -04008401 return rc;
8402}
8403
8404static int bnxt_get_max_irq(struct pci_dev *pdev)
8405{
8406 u16 ctrl;
8407
8408 if (!pdev->msix_cap)
8409 return 1;
8410
8411 pci_read_config_word(pdev, pdev->msix_cap + PCI_MSIX_FLAGS, &ctrl);
8412 return (ctrl & PCI_MSIX_FLAGS_QSIZE) + 1;
8413}
8414
Michael Chan6e6c5a52016-01-02 23:45:02 -05008415static void _bnxt_get_max_rings(struct bnxt *bp, int *max_rx, int *max_tx,
8416 int *max_cp)
Michael Chanc0c050c2015-10-22 16:01:17 -04008417{
Michael Chan6a4f2942018-01-17 03:21:06 -05008418 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
Michael Chan6e6c5a52016-01-02 23:45:02 -05008419 int max_ring_grps = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04008420
Michael Chan6a4f2942018-01-17 03:21:06 -05008421 *max_tx = hw_resc->max_tx_rings;
8422 *max_rx = hw_resc->max_rx_rings;
8423 *max_cp = min_t(int, hw_resc->max_irqs, hw_resc->max_cp_rings);
8424 *max_cp = min_t(int, *max_cp, hw_resc->max_stat_ctxs);
8425 max_ring_grps = hw_resc->max_hw_ring_grps;
Prashant Sreedharan76595192016-07-18 07:15:22 -04008426 if (BNXT_CHIP_TYPE_NITRO_A0(bp) && BNXT_PF(bp)) {
8427 *max_cp -= 1;
8428 *max_rx -= 2;
8429 }
Michael Chanc0c050c2015-10-22 16:01:17 -04008430 if (bp->flags & BNXT_FLAG_AGG_RINGS)
8431 *max_rx >>= 1;
Michael Chanb72d4a62015-12-27 18:19:27 -05008432 *max_rx = min_t(int, *max_rx, max_ring_grps);
Michael Chan6e6c5a52016-01-02 23:45:02 -05008433}
8434
8435int bnxt_get_max_rings(struct bnxt *bp, int *max_rx, int *max_tx, bool shared)
8436{
8437 int rx, tx, cp;
8438
8439 _bnxt_get_max_rings(bp, &rx, &tx, &cp);
8440 if (!rx || !tx || !cp)
8441 return -ENOMEM;
8442
8443 *max_rx = rx;
8444 *max_tx = tx;
8445 return bnxt_trim_rings(bp, max_rx, max_tx, cp, shared);
8446}
8447
Michael Chane4060d32016-12-07 00:26:19 -05008448static int bnxt_get_dflt_rings(struct bnxt *bp, int *max_rx, int *max_tx,
8449 bool shared)
8450{
8451 int rc;
8452
8453 rc = bnxt_get_max_rings(bp, max_rx, max_tx, shared);
Michael Chanbdbd1eb2016-12-29 12:13:43 -05008454 if (rc && (bp->flags & BNXT_FLAG_AGG_RINGS)) {
8455 /* Not enough rings, try disabling agg rings. */
8456 bp->flags &= ~BNXT_FLAG_AGG_RINGS;
8457 rc = bnxt_get_max_rings(bp, max_rx, max_tx, shared);
8458 if (rc)
8459 return rc;
8460 bp->flags |= BNXT_FLAG_NO_AGG_RINGS;
Michael Chan1054aee2017-12-16 03:09:42 -05008461 bp->dev->hw_features &= ~(NETIF_F_LRO | NETIF_F_GRO_HW);
8462 bp->dev->features &= ~(NETIF_F_LRO | NETIF_F_GRO_HW);
Michael Chanbdbd1eb2016-12-29 12:13:43 -05008463 bnxt_set_ring_params(bp);
8464 }
Michael Chane4060d32016-12-07 00:26:19 -05008465
8466 if (bp->flags & BNXT_FLAG_ROCE_CAP) {
8467 int max_cp, max_stat, max_irq;
8468
8469 /* Reserve minimum resources for RoCE */
8470 max_cp = bnxt_get_max_func_cp_rings(bp);
8471 max_stat = bnxt_get_max_func_stat_ctxs(bp);
8472 max_irq = bnxt_get_max_func_irqs(bp);
8473 if (max_cp <= BNXT_MIN_ROCE_CP_RINGS ||
8474 max_irq <= BNXT_MIN_ROCE_CP_RINGS ||
8475 max_stat <= BNXT_MIN_ROCE_STAT_CTXS)
8476 return 0;
8477
8478 max_cp -= BNXT_MIN_ROCE_CP_RINGS;
8479 max_irq -= BNXT_MIN_ROCE_CP_RINGS;
8480 max_stat -= BNXT_MIN_ROCE_STAT_CTXS;
8481 max_cp = min_t(int, max_cp, max_irq);
8482 max_cp = min_t(int, max_cp, max_stat);
8483 rc = bnxt_trim_rings(bp, max_rx, max_tx, max_cp, shared);
8484 if (rc)
8485 rc = 0;
8486 }
8487 return rc;
8488}
8489
Michael Chan58ea8012018-01-17 03:21:08 -05008490/* In initial default shared ring setting, each shared ring must have a
8491 * RX/TX ring pair.
8492 */
8493static void bnxt_trim_dflt_sh_rings(struct bnxt *bp)
8494{
8495 bp->cp_nr_rings = min_t(int, bp->tx_nr_rings_per_tc, bp->rx_nr_rings);
8496 bp->rx_nr_rings = bp->cp_nr_rings;
8497 bp->tx_nr_rings_per_tc = bp->cp_nr_rings;
8498 bp->tx_nr_rings = bp->tx_nr_rings_per_tc;
8499}
8500
Michael Chan702c2212017-05-29 19:06:10 -04008501static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh)
Michael Chan6e6c5a52016-01-02 23:45:02 -05008502{
8503 int dflt_rings, max_rx_rings, max_tx_rings, rc;
Michael Chan6e6c5a52016-01-02 23:45:02 -05008504
8505 if (sh)
8506 bp->flags |= BNXT_FLAG_SHARED_RINGS;
8507 dflt_rings = netif_get_num_default_rss_queues();
Michael Chan1d3ef132018-03-31 13:54:07 -04008508 /* Reduce default rings on multi-port cards so that total default
8509 * rings do not exceed CPU count.
8510 */
8511 if (bp->port_count > 1) {
8512 int max_rings =
8513 max_t(int, num_online_cpus() / bp->port_count, 1);
8514
8515 dflt_rings = min_t(int, dflt_rings, max_rings);
8516 }
Michael Chane4060d32016-12-07 00:26:19 -05008517 rc = bnxt_get_dflt_rings(bp, &max_rx_rings, &max_tx_rings, sh);
Michael Chan6e6c5a52016-01-02 23:45:02 -05008518 if (rc)
8519 return rc;
8520 bp->rx_nr_rings = min_t(int, dflt_rings, max_rx_rings);
8521 bp->tx_nr_rings_per_tc = min_t(int, dflt_rings, max_tx_rings);
Michael Chan58ea8012018-01-17 03:21:08 -05008522 if (sh)
8523 bnxt_trim_dflt_sh_rings(bp);
8524 else
8525 bp->cp_nr_rings = bp->tx_nr_rings_per_tc + bp->rx_nr_rings;
8526 bp->tx_nr_rings = bp->tx_nr_rings_per_tc;
Michael Chan391be5c2016-12-29 12:13:41 -05008527
Michael Chan674f50a2018-01-17 03:21:09 -05008528 rc = __bnxt_reserve_rings(bp);
Michael Chan391be5c2016-12-29 12:13:41 -05008529 if (rc)
8530 netdev_warn(bp->dev, "Unable to reserve tx rings\n");
Michael Chan58ea8012018-01-17 03:21:08 -05008531 bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
8532 if (sh)
8533 bnxt_trim_dflt_sh_rings(bp);
Michael Chan391be5c2016-12-29 12:13:41 -05008534
Michael Chan674f50a2018-01-17 03:21:09 -05008535 /* Rings may have been trimmed, re-reserve the trimmed rings. */
8536 if (bnxt_need_reserve_rings(bp)) {
8537 rc = __bnxt_reserve_rings(bp);
8538 if (rc)
8539 netdev_warn(bp->dev, "2nd rings reservation failed.\n");
8540 bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
8541 }
Michael Chan6e6c5a52016-01-02 23:45:02 -05008542 bp->num_stat_ctxs = bp->cp_nr_rings;
Prashant Sreedharan76595192016-07-18 07:15:22 -04008543 if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
8544 bp->rx_nr_rings++;
8545 bp->cp_nr_rings++;
8546 }
Michael Chan6e6c5a52016-01-02 23:45:02 -05008547 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04008548}
8549
Michael Chan80fcaf42018-01-17 03:21:05 -05008550int bnxt_restore_pf_fw_resources(struct bnxt *bp)
Michael Chan7b08f662016-12-07 00:26:18 -05008551{
Michael Chan80fcaf42018-01-17 03:21:05 -05008552 int rc;
8553
Michael Chan7b08f662016-12-07 00:26:18 -05008554 ASSERT_RTNL();
8555 bnxt_hwrm_func_qcaps(bp);
Venkat Duvvuru1a037782018-03-09 23:46:09 -05008556
8557 if (netif_running(bp->dev))
8558 __bnxt_close_nic(bp, true, false);
8559
Michael Chanec86f142018-03-31 13:54:21 -04008560 bnxt_ulp_irq_stop(bp);
Michael Chan80fcaf42018-01-17 03:21:05 -05008561 bnxt_clear_int_mode(bp);
8562 rc = bnxt_init_int_mode(bp);
Michael Chanec86f142018-03-31 13:54:21 -04008563 bnxt_ulp_irq_restart(bp, rc);
Venkat Duvvuru1a037782018-03-09 23:46:09 -05008564
8565 if (netif_running(bp->dev)) {
8566 if (rc)
8567 dev_close(bp->dev);
8568 else
8569 rc = bnxt_open_nic(bp, true, false);
8570 }
8571
Michael Chan80fcaf42018-01-17 03:21:05 -05008572 return rc;
Michael Chan7b08f662016-12-07 00:26:18 -05008573}
8574
Michael Chana22a6ac2017-08-23 19:34:05 -04008575static int bnxt_init_mac_addr(struct bnxt *bp)
8576{
8577 int rc = 0;
8578
8579 if (BNXT_PF(bp)) {
8580 memcpy(bp->dev->dev_addr, bp->pf.mac_addr, ETH_ALEN);
8581 } else {
8582#ifdef CONFIG_BNXT_SRIOV
8583 struct bnxt_vf_info *vf = &bp->vf;
8584
8585 if (is_valid_ether_addr(vf->mac_addr)) {
Vasundhara Volam91cdda42018-01-17 03:21:14 -05008586 /* overwrite netdev dev_addr with admin VF MAC */
Michael Chana22a6ac2017-08-23 19:34:05 -04008587 memcpy(bp->dev->dev_addr, vf->mac_addr, ETH_ALEN);
8588 } else {
8589 eth_hw_addr_random(bp->dev);
8590 rc = bnxt_approve_mac(bp, bp->dev->dev_addr);
8591 }
8592#endif
8593 }
8594 return rc;
8595}
8596
Ajit Khaparde90c4f782016-05-15 03:04:45 -04008597static void bnxt_parse_log_pcie_link(struct bnxt *bp)
8598{
8599 enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN;
8600 enum pci_bus_speed speed = PCI_SPEED_UNKNOWN;
8601
Vasundhara Volam7ab07602017-10-13 21:09:31 -04008602 if (pcie_get_minimum_link(pci_physfn(bp->pdev), &speed, &width) ||
Ajit Khaparde90c4f782016-05-15 03:04:45 -04008603 speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN)
8604 netdev_info(bp->dev, "Failed to determine PCIe Link Info\n");
8605 else
8606 netdev_info(bp->dev, "PCIe: Speed %s Width x%d\n",
8607 speed == PCIE_SPEED_2_5GT ? "2.5GT/s" :
8608 speed == PCIE_SPEED_5_0GT ? "5.0GT/s" :
8609 speed == PCIE_SPEED_8_0GT ? "8.0GT/s" :
8610 "Unknown", width);
8611}
8612
Michael Chanc0c050c2015-10-22 16:01:17 -04008613static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
8614{
8615 static int version_printed;
8616 struct net_device *dev;
8617 struct bnxt *bp;
Michael Chan6e6c5a52016-01-02 23:45:02 -05008618 int rc, max_irqs;
Michael Chanc0c050c2015-10-22 16:01:17 -04008619
Ray Jui4e003382017-02-20 19:25:16 -05008620 if (pci_is_bridge(pdev))
Prashant Sreedharanfa853dd2016-07-18 07:15:25 -04008621 return -ENODEV;
8622
Michael Chanc0c050c2015-10-22 16:01:17 -04008623 if (version_printed++ == 0)
8624 pr_info("%s", version);
8625
8626 max_irqs = bnxt_get_max_irq(pdev);
8627 dev = alloc_etherdev_mq(sizeof(*bp), max_irqs);
8628 if (!dev)
8629 return -ENOMEM;
8630
8631 bp = netdev_priv(dev);
8632
8633 if (bnxt_vf_pciid(ent->driver_data))
8634 bp->flags |= BNXT_FLAG_VF;
8635
Michael Chan2bcfa6f2015-12-27 18:19:24 -05008636 if (pdev->msix_cap)
Michael Chanc0c050c2015-10-22 16:01:17 -04008637 bp->flags |= BNXT_FLAG_MSIX_CAP;
Michael Chanc0c050c2015-10-22 16:01:17 -04008638
8639 rc = bnxt_init_board(pdev, dev);
8640 if (rc < 0)
8641 goto init_err_free;
8642
8643 dev->netdev_ops = &bnxt_netdev_ops;
8644 dev->watchdog_timeo = BNXT_TX_TIMEOUT;
8645 dev->ethtool_ops = &bnxt_ethtool_ops;
David S. Millerbc880552017-07-24 21:20:16 -07008646 SWITCHDEV_SET_OPS(dev, &bnxt_switchdev_ops);
Michael Chanc0c050c2015-10-22 16:01:17 -04008647 pci_set_drvdata(pdev, dev);
8648
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04008649 rc = bnxt_alloc_hwrm_resources(bp);
8650 if (rc)
Sathya Perla17086392017-02-20 19:25:18 -05008651 goto init_err_pci_clean;
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04008652
8653 mutex_init(&bp->hwrm_cmd_lock);
8654 rc = bnxt_hwrm_ver_get(bp);
8655 if (rc)
Sathya Perla17086392017-02-20 19:25:18 -05008656 goto init_err_pci_clean;
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04008657
Deepak Khungare605db82017-05-29 19:06:04 -04008658 if (bp->flags & BNXT_FLAG_SHORT_CMD) {
8659 rc = bnxt_alloc_hwrm_short_cmd_req(bp);
8660 if (rc)
8661 goto init_err_pci_clean;
8662 }
8663
Michael Chan3c2217a2017-03-08 18:44:32 -05008664 rc = bnxt_hwrm_func_reset(bp);
8665 if (rc)
8666 goto init_err_pci_clean;
8667
Rob Swindell5ac67d82016-09-19 03:58:03 -04008668 bnxt_hwrm_fw_set_time(bp);
8669
Michael Chanc0c050c2015-10-22 16:01:17 -04008670 dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
8671 NETIF_F_TSO | NETIF_F_TSO6 |
8672 NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_GRE |
Tom Herbert7e133182016-05-18 09:06:10 -07008673 NETIF_F_GSO_IPXIP4 |
Alexander Duyck152971e2016-05-02 09:38:55 -07008674 NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_GSO_GRE_CSUM |
8675 NETIF_F_GSO_PARTIAL | NETIF_F_RXHASH |
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04008676 NETIF_F_RXCSUM | NETIF_F_GRO;
8677
8678 if (!BNXT_CHIP_TYPE_NITRO_A0(bp))
8679 dev->hw_features |= NETIF_F_LRO;
Michael Chanc0c050c2015-10-22 16:01:17 -04008680
Michael Chanc0c050c2015-10-22 16:01:17 -04008681 dev->hw_enc_features =
8682 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
8683 NETIF_F_TSO | NETIF_F_TSO6 |
8684 NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_GRE |
Alexander Duyck152971e2016-05-02 09:38:55 -07008685 NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_GSO_GRE_CSUM |
Tom Herbert7e133182016-05-18 09:06:10 -07008686 NETIF_F_GSO_IPXIP4 | NETIF_F_GSO_PARTIAL;
Alexander Duyck152971e2016-05-02 09:38:55 -07008687 dev->gso_partial_features = NETIF_F_GSO_UDP_TUNNEL_CSUM |
8688 NETIF_F_GSO_GRE_CSUM;
Michael Chanc0c050c2015-10-22 16:01:17 -04008689 dev->vlan_features = dev->hw_features | NETIF_F_HIGHDMA;
8690 dev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX |
8691 NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_STAG_TX;
Michael Chan1054aee2017-12-16 03:09:42 -05008692 if (!BNXT_CHIP_TYPE_NITRO_A0(bp))
8693 dev->hw_features |= NETIF_F_GRO_HW;
Michael Chanc0c050c2015-10-22 16:01:17 -04008694 dev->features |= dev->hw_features | NETIF_F_HIGHDMA;
Michael Chan1054aee2017-12-16 03:09:42 -05008695 if (dev->features & NETIF_F_GRO_HW)
8696 dev->features &= ~NETIF_F_LRO;
Michael Chanc0c050c2015-10-22 16:01:17 -04008697 dev->priv_flags |= IFF_UNICAST_FLT;
8698
8699#ifdef CONFIG_BNXT_SRIOV
8700 init_waitqueue_head(&bp->sriov_cfg_wait);
Sathya Perla4ab0c6a2017-07-24 12:34:27 -04008701 mutex_init(&bp->sriov_lock);
Michael Chanc0c050c2015-10-22 16:01:17 -04008702#endif
Michael Chan309369c2016-06-13 02:25:34 -04008703 bp->gro_func = bnxt_gro_func_5730x;
Michael Chan3284f9e2017-05-29 19:06:07 -04008704 if (BNXT_CHIP_P4_PLUS(bp))
Michael Chan94758f82016-06-13 02:25:35 -04008705 bp->gro_func = bnxt_gro_func_5731x;
Michael Chan434c9752017-05-29 19:06:08 -04008706 else
8707 bp->flags |= BNXT_FLAG_DOUBLE_DB;
Michael Chan309369c2016-06-13 02:25:34 -04008708
Michael Chanc0c050c2015-10-22 16:01:17 -04008709 rc = bnxt_hwrm_func_drv_rgtr(bp);
8710 if (rc)
Sathya Perla17086392017-02-20 19:25:18 -05008711 goto init_err_pci_clean;
Michael Chanc0c050c2015-10-22 16:01:17 -04008712
Michael Chana1653b12016-12-07 00:26:20 -05008713 rc = bnxt_hwrm_func_rgtr_async_events(bp, NULL, 0);
8714 if (rc)
Sathya Perla17086392017-02-20 19:25:18 -05008715 goto init_err_pci_clean;
Michael Chana1653b12016-12-07 00:26:20 -05008716
Michael Chana588e452016-12-07 00:26:21 -05008717 bp->ulp_probe = bnxt_ulp_probe;
8718
Michael Chanc0c050c2015-10-22 16:01:17 -04008719 /* Get the MAX capabilities for this function */
8720 rc = bnxt_hwrm_func_qcaps(bp);
8721 if (rc) {
8722 netdev_err(bp->dev, "hwrm query capability failure rc: %x\n",
8723 rc);
8724 rc = -1;
Sathya Perla17086392017-02-20 19:25:18 -05008725 goto init_err_pci_clean;
Michael Chanc0c050c2015-10-22 16:01:17 -04008726 }
Michael Chana22a6ac2017-08-23 19:34:05 -04008727 rc = bnxt_init_mac_addr(bp);
8728 if (rc) {
8729 dev_err(&pdev->dev, "Unable to initialize mac address.\n");
8730 rc = -EADDRNOTAVAIL;
8731 goto init_err_pci_clean;
8732 }
Michael Chanc0c050c2015-10-22 16:01:17 -04008733 rc = bnxt_hwrm_queue_qportcfg(bp);
8734 if (rc) {
8735 netdev_err(bp->dev, "hwrm query qportcfg failure rc: %x\n",
8736 rc);
8737 rc = -1;
Sathya Perla17086392017-02-20 19:25:18 -05008738 goto init_err_pci_clean;
Michael Chanc0c050c2015-10-22 16:01:17 -04008739 }
8740
Satish Baddipadige567b2ab2016-06-13 02:25:31 -04008741 bnxt_hwrm_func_qcfg(bp);
Michael Chan5ad2cbe2017-01-13 01:32:03 -05008742 bnxt_hwrm_port_led_qcaps(bp);
Michael Chaneb513652017-04-04 18:14:12 -04008743 bnxt_ethtool_init(bp);
Michael Chan87fe6032017-05-16 16:39:43 -04008744 bnxt_dcb_init(bp);
Satish Baddipadige567b2ab2016-06-13 02:25:31 -04008745
Michael Chan7eb9bb32017-10-26 11:51:25 -04008746 /* MTU range: 60 - FW defined max */
8747 dev->min_mtu = ETH_ZLEN;
8748 dev->max_mtu = bp->max_mtu;
8749
Michael Chand5430d32017-08-28 13:40:31 -04008750 rc = bnxt_probe_phy(bp);
8751 if (rc)
8752 goto init_err_pci_clean;
8753
Michael Chanc61fb992017-02-06 16:55:36 -05008754 bnxt_set_rx_skb_mode(bp, false);
Michael Chanc0c050c2015-10-22 16:01:17 -04008755 bnxt_set_tpa_flags(bp);
8756 bnxt_set_ring_params(bp);
Michael Chan33c26572016-12-07 00:26:15 -05008757 bnxt_set_max_func_irqs(bp, max_irqs);
Michael Chan702c2212017-05-29 19:06:10 -04008758 rc = bnxt_set_dflt_rings(bp, true);
Michael Chanbdbd1eb2016-12-29 12:13:43 -05008759 if (rc) {
8760 netdev_err(bp->dev, "Not enough rings available.\n");
8761 rc = -ENOMEM;
Sathya Perla17086392017-02-20 19:25:18 -05008762 goto init_err_pci_clean;
Michael Chanbdbd1eb2016-12-29 12:13:43 -05008763 }
Michael Chanc0c050c2015-10-22 16:01:17 -04008764
Michael Chan87da7f72016-11-16 21:13:09 -05008765 /* Default RSS hash cfg. */
8766 bp->rss_hash_cfg = VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4 |
8767 VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4 |
8768 VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6 |
8769 VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6;
Michael Chan3284f9e2017-05-29 19:06:07 -04008770 if (BNXT_CHIP_P4_PLUS(bp) && bp->hwrm_spec_code >= 0x10501) {
Michael Chan87da7f72016-11-16 21:13:09 -05008771 bp->flags |= BNXT_FLAG_UDP_RSS_CAP;
8772 bp->rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4 |
8773 VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6;
8774 }
8775
Michael Chan8fdefd62016-12-29 12:13:36 -05008776 bnxt_hwrm_vnic_qcaps(bp);
Michael Chan8079e8f2016-12-29 12:13:37 -05008777 if (bnxt_rfs_supported(bp)) {
Michael Chan2bcfa6f2015-12-27 18:19:24 -05008778 dev->hw_features |= NETIF_F_NTUPLE;
8779 if (bnxt_rfs_capable(bp)) {
8780 bp->flags |= BNXT_FLAG_RFS;
8781 dev->features |= NETIF_F_NTUPLE;
8782 }
8783 }
8784
Michael Chanc0c050c2015-10-22 16:01:17 -04008785 if (dev->hw_features & NETIF_F_HW_VLAN_CTAG_RX)
8786 bp->flags |= BNXT_FLAG_STRIP_VLAN;
8787
Michael Chan78095922016-12-07 00:26:16 -05008788 rc = bnxt_init_int_mode(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04008789 if (rc)
Sathya Perla17086392017-02-20 19:25:18 -05008790 goto init_err_pci_clean;
Michael Chanc0c050c2015-10-22 16:01:17 -04008791
Michael Chan832aed12018-03-09 23:46:07 -05008792 /* No TC has been set yet and rings may have been trimmed due to
8793 * limited MSIX, so we re-initialize the TX rings per TC.
8794 */
8795 bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
8796
Michael Chanc1ef1462017-04-04 18:14:07 -04008797 bnxt_get_wol_settings(bp);
Michael Chand196ece2017-04-04 18:14:08 -04008798 if (bp->flags & BNXT_FLAG_WOL_CAP)
8799 device_set_wakeup_enable(&pdev->dev, bp->wol);
8800 else
8801 device_set_wakeup_capable(&pdev->dev, false);
Michael Chanc1ef1462017-04-04 18:14:07 -04008802
Michael Chanc3480a62018-01-17 03:21:15 -05008803 bnxt_hwrm_set_cache_line_size(bp, cache_line_size());
8804
Michael Chanc213eae2017-10-13 21:09:29 -04008805 if (BNXT_PF(bp)) {
8806 if (!bnxt_pf_wq) {
8807 bnxt_pf_wq =
8808 create_singlethread_workqueue("bnxt_pf_wq");
8809 if (!bnxt_pf_wq) {
8810 dev_err(&pdev->dev, "Unable to create workqueue.\n");
8811 goto init_err_pci_clean;
8812 }
8813 }
Sathya Perla2ae74082017-08-28 13:40:33 -04008814 bnxt_init_tc(bp);
Michael Chanc213eae2017-10-13 21:09:29 -04008815 }
Sathya Perla2ae74082017-08-28 13:40:33 -04008816
Michael Chan78095922016-12-07 00:26:16 -05008817 rc = register_netdev(dev);
8818 if (rc)
Sathya Perla2ae74082017-08-28 13:40:33 -04008819 goto init_err_cleanup_tc;
Michael Chan78095922016-12-07 00:26:16 -05008820
Sathya Perla4ab0c6a2017-07-24 12:34:27 -04008821 if (BNXT_PF(bp))
8822 bnxt_dl_register(bp);
8823
Michael Chanc0c050c2015-10-22 16:01:17 -04008824 netdev_info(dev, "%s found at mem %lx, node addr %pM\n",
8825 board_info[ent->driver_data].name,
8826 (long)pci_resource_start(pdev, 0), dev->dev_addr);
8827
Ajit Khaparde90c4f782016-05-15 03:04:45 -04008828 bnxt_parse_log_pcie_link(bp);
8829
Michael Chanc0c050c2015-10-22 16:01:17 -04008830 return 0;
8831
Sathya Perla2ae74082017-08-28 13:40:33 -04008832init_err_cleanup_tc:
8833 bnxt_shutdown_tc(bp);
Michael Chan78095922016-12-07 00:26:16 -05008834 bnxt_clear_int_mode(bp);
8835
Sathya Perla17086392017-02-20 19:25:18 -05008836init_err_pci_clean:
8837 bnxt_cleanup_pci(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04008838
8839init_err_free:
8840 free_netdev(dev);
8841 return rc;
8842}
8843
Michael Chand196ece2017-04-04 18:14:08 -04008844static void bnxt_shutdown(struct pci_dev *pdev)
8845{
8846 struct net_device *dev = pci_get_drvdata(pdev);
8847 struct bnxt *bp;
8848
8849 if (!dev)
8850 return;
8851
8852 rtnl_lock();
8853 bp = netdev_priv(dev);
8854 if (!bp)
8855 goto shutdown_exit;
8856
8857 if (netif_running(dev))
8858 dev_close(dev);
8859
Ray Juia7f3f932017-12-01 03:13:02 -05008860 bnxt_ulp_shutdown(bp);
8861
Michael Chand196ece2017-04-04 18:14:08 -04008862 if (system_state == SYSTEM_POWER_OFF) {
8863 bnxt_clear_int_mode(bp);
8864 pci_wake_from_d3(pdev, bp->wol);
8865 pci_set_power_state(pdev, PCI_D3hot);
8866 }
8867
8868shutdown_exit:
8869 rtnl_unlock();
8870}
8871
Michael Chanf65a2042017-04-04 18:14:11 -04008872#ifdef CONFIG_PM_SLEEP
8873static int bnxt_suspend(struct device *device)
8874{
8875 struct pci_dev *pdev = to_pci_dev(device);
8876 struct net_device *dev = pci_get_drvdata(pdev);
8877 struct bnxt *bp = netdev_priv(dev);
8878 int rc = 0;
8879
8880 rtnl_lock();
8881 if (netif_running(dev)) {
8882 netif_device_detach(dev);
8883 rc = bnxt_close(dev);
8884 }
8885 bnxt_hwrm_func_drv_unrgtr(bp);
8886 rtnl_unlock();
8887 return rc;
8888}
8889
8890static int bnxt_resume(struct device *device)
8891{
8892 struct pci_dev *pdev = to_pci_dev(device);
8893 struct net_device *dev = pci_get_drvdata(pdev);
8894 struct bnxt *bp = netdev_priv(dev);
8895 int rc = 0;
8896
8897 rtnl_lock();
8898 if (bnxt_hwrm_ver_get(bp) || bnxt_hwrm_func_drv_rgtr(bp)) {
8899 rc = -ENODEV;
8900 goto resume_exit;
8901 }
8902 rc = bnxt_hwrm_func_reset(bp);
8903 if (rc) {
8904 rc = -EBUSY;
8905 goto resume_exit;
8906 }
8907 bnxt_get_wol_settings(bp);
8908 if (netif_running(dev)) {
8909 rc = bnxt_open(dev);
8910 if (!rc)
8911 netif_device_attach(dev);
8912 }
8913
8914resume_exit:
8915 rtnl_unlock();
8916 return rc;
8917}
8918
8919static SIMPLE_DEV_PM_OPS(bnxt_pm_ops, bnxt_suspend, bnxt_resume);
8920#define BNXT_PM_OPS (&bnxt_pm_ops)
8921
8922#else
8923
8924#define BNXT_PM_OPS NULL
8925
8926#endif /* CONFIG_PM_SLEEP */
8927
Satish Baddipadige6316ea62016-03-07 15:38:48 -05008928/**
8929 * bnxt_io_error_detected - called when PCI error is detected
8930 * @pdev: Pointer to PCI device
8931 * @state: The current pci connection state
8932 *
8933 * This function is called after a PCI bus error affecting
8934 * this device has been detected.
8935 */
8936static pci_ers_result_t bnxt_io_error_detected(struct pci_dev *pdev,
8937 pci_channel_state_t state)
8938{
8939 struct net_device *netdev = pci_get_drvdata(pdev);
Michael Chana588e452016-12-07 00:26:21 -05008940 struct bnxt *bp = netdev_priv(netdev);
Satish Baddipadige6316ea62016-03-07 15:38:48 -05008941
8942 netdev_info(netdev, "PCI I/O error detected\n");
8943
8944 rtnl_lock();
8945 netif_device_detach(netdev);
8946
Michael Chana588e452016-12-07 00:26:21 -05008947 bnxt_ulp_stop(bp);
8948
Satish Baddipadige6316ea62016-03-07 15:38:48 -05008949 if (state == pci_channel_io_perm_failure) {
8950 rtnl_unlock();
8951 return PCI_ERS_RESULT_DISCONNECT;
8952 }
8953
8954 if (netif_running(netdev))
8955 bnxt_close(netdev);
8956
8957 pci_disable_device(pdev);
8958 rtnl_unlock();
8959
8960 /* Request a slot slot reset. */
8961 return PCI_ERS_RESULT_NEED_RESET;
8962}
8963
8964/**
8965 * bnxt_io_slot_reset - called after the pci bus has been reset.
8966 * @pdev: Pointer to PCI device
8967 *
8968 * Restart the card from scratch, as if from a cold-boot.
8969 * At this point, the card has exprienced a hard reset,
8970 * followed by fixups by BIOS, and has its config space
8971 * set up identically to what it was at cold boot.
8972 */
8973static pci_ers_result_t bnxt_io_slot_reset(struct pci_dev *pdev)
8974{
8975 struct net_device *netdev = pci_get_drvdata(pdev);
8976 struct bnxt *bp = netdev_priv(netdev);
8977 int err = 0;
8978 pci_ers_result_t result = PCI_ERS_RESULT_DISCONNECT;
8979
8980 netdev_info(bp->dev, "PCI Slot Reset\n");
8981
8982 rtnl_lock();
8983
8984 if (pci_enable_device(pdev)) {
8985 dev_err(&pdev->dev,
8986 "Cannot re-enable PCI device after reset.\n");
8987 } else {
8988 pci_set_master(pdev);
8989
Michael Chanaa8ed022016-12-07 00:26:17 -05008990 err = bnxt_hwrm_func_reset(bp);
8991 if (!err && netif_running(netdev))
Satish Baddipadige6316ea62016-03-07 15:38:48 -05008992 err = bnxt_open(netdev);
8993
Michael Chana588e452016-12-07 00:26:21 -05008994 if (!err) {
Satish Baddipadige6316ea62016-03-07 15:38:48 -05008995 result = PCI_ERS_RESULT_RECOVERED;
Michael Chana588e452016-12-07 00:26:21 -05008996 bnxt_ulp_start(bp);
8997 }
Satish Baddipadige6316ea62016-03-07 15:38:48 -05008998 }
8999
9000 if (result != PCI_ERS_RESULT_RECOVERED && netif_running(netdev))
9001 dev_close(netdev);
9002
9003 rtnl_unlock();
9004
9005 err = pci_cleanup_aer_uncorrect_error_status(pdev);
9006 if (err) {
9007 dev_err(&pdev->dev,
9008 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
9009 err); /* non-fatal, continue */
9010 }
9011
9012 return PCI_ERS_RESULT_RECOVERED;
9013}
9014
9015/**
9016 * bnxt_io_resume - called when traffic can start flowing again.
9017 * @pdev: Pointer to PCI device
9018 *
9019 * This callback is called when the error recovery driver tells
9020 * us that its OK to resume normal operation.
9021 */
9022static void bnxt_io_resume(struct pci_dev *pdev)
9023{
9024 struct net_device *netdev = pci_get_drvdata(pdev);
9025
9026 rtnl_lock();
9027
9028 netif_device_attach(netdev);
9029
9030 rtnl_unlock();
9031}
9032
9033static const struct pci_error_handlers bnxt_err_handler = {
9034 .error_detected = bnxt_io_error_detected,
9035 .slot_reset = bnxt_io_slot_reset,
9036 .resume = bnxt_io_resume
9037};
9038
Michael Chanc0c050c2015-10-22 16:01:17 -04009039static struct pci_driver bnxt_pci_driver = {
9040 .name = DRV_MODULE_NAME,
9041 .id_table = bnxt_pci_tbl,
9042 .probe = bnxt_init_one,
9043 .remove = bnxt_remove_one,
Michael Chand196ece2017-04-04 18:14:08 -04009044 .shutdown = bnxt_shutdown,
Michael Chanf65a2042017-04-04 18:14:11 -04009045 .driver.pm = BNXT_PM_OPS,
Satish Baddipadige6316ea62016-03-07 15:38:48 -05009046 .err_handler = &bnxt_err_handler,
Michael Chanc0c050c2015-10-22 16:01:17 -04009047#if defined(CONFIG_BNXT_SRIOV)
9048 .sriov_configure = bnxt_sriov_configure,
9049#endif
9050};
9051
Michael Chanc213eae2017-10-13 21:09:29 -04009052static int __init bnxt_init(void)
9053{
9054 return pci_register_driver(&bnxt_pci_driver);
9055}
9056
9057static void __exit bnxt_exit(void)
9058{
9059 pci_unregister_driver(&bnxt_pci_driver);
9060 if (bnxt_pf_wq)
9061 destroy_workqueue(bnxt_pf_wq);
9062}
9063
9064module_init(bnxt_init);
9065module_exit(bnxt_exit);