blob: 1991f0c7bc0eedb13015c9fd94391bea72520fd0 [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 Chaned7bc602018-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 Chaned7bc602018-03-09 23:46:06 -05001626 u16 vtag = meta_data & RX_CMP_FLAGS2_METADATA_TCI_MASK;
Michael Chanc0c050c2015-10-22 16:01:17 -04001627 u16 vlan_proto = meta_data >> RX_CMP_FLAGS2_METADATA_TPID_SFT;
1628
Michael Chan8852ddb2016-06-06 02:37:16 -04001629 __vlan_hwaccel_put_tag(skb, htons(vlan_proto), vtag);
Michael Chanc0c050c2015-10-22 16:01:17 -04001630 }
1631
1632 skb_checksum_none_assert(skb);
1633 if (RX_CMP_L4_CS_OK(rxcmp1)) {
1634 if (dev->features & NETIF_F_RXCSUM) {
1635 skb->ip_summed = CHECKSUM_UNNECESSARY;
1636 skb->csum_level = RX_CMP_ENCAP(rxcmp1);
1637 }
1638 } else {
Satish Baddipadige665e3502015-12-27 18:19:21 -05001639 if (rxcmp1->rx_cmp_cfa_code_errors_v2 & RX_CMP_L4_CS_ERR_BITS) {
1640 if (dev->features & NETIF_F_RXCSUM)
1641 cpr->rx_l4_csum_errors++;
1642 }
Michael Chanc0c050c2015-10-22 16:01:17 -04001643 }
1644
Sathya Perlaee5c7fb2017-07-24 12:34:28 -04001645 bnxt_deliver_skb(bp, bnapi, skb);
Michael Chanc0c050c2015-10-22 16:01:17 -04001646 rc = 1;
1647
1648next_rx:
1649 rxr->rx_prod = NEXT_RX(prod);
Michael Chan376a5b82016-05-10 19:17:59 -04001650 rxr->rx_next_cons = NEXT_RX(cons);
Michael Chanc0c050c2015-10-22 16:01:17 -04001651
Andy Gospodarek6a8788f2018-01-09 16:06:20 -05001652 cpr->rx_packets += 1;
1653 cpr->rx_bytes += len;
Colin Ian Kinge7e70fa2018-01-16 10:22:50 +00001654
1655next_rx_no_prod_no_len:
Michael Chanc0c050c2015-10-22 16:01:17 -04001656 *raw_cons = tmp_raw_cons;
1657
1658 return rc;
1659}
1660
Michael Chan2270bc52017-06-23 14:01:01 -04001661/* In netpoll mode, if we are using a combined completion ring, we need to
1662 * discard the rx packets and recycle the buffers.
1663 */
1664static int bnxt_force_rx_discard(struct bnxt *bp, struct bnxt_napi *bnapi,
1665 u32 *raw_cons, u8 *event)
1666{
1667 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1668 u32 tmp_raw_cons = *raw_cons;
1669 struct rx_cmp_ext *rxcmp1;
1670 struct rx_cmp *rxcmp;
1671 u16 cp_cons;
1672 u8 cmp_type;
1673
1674 cp_cons = RING_CMP(tmp_raw_cons);
1675 rxcmp = (struct rx_cmp *)
1676 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
1677
1678 tmp_raw_cons = NEXT_RAW_CMP(tmp_raw_cons);
1679 cp_cons = RING_CMP(tmp_raw_cons);
1680 rxcmp1 = (struct rx_cmp_ext *)
1681 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
1682
1683 if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons))
1684 return -EBUSY;
1685
1686 cmp_type = RX_CMP_TYPE(rxcmp);
1687 if (cmp_type == CMP_TYPE_RX_L2_CMP) {
1688 rxcmp1->rx_cmp_cfa_code_errors_v2 |=
1689 cpu_to_le32(RX_CMPL_ERRORS_CRC_ERROR);
1690 } else if (cmp_type == CMP_TYPE_RX_L2_TPA_END_CMP) {
1691 struct rx_tpa_end_cmp_ext *tpa_end1;
1692
1693 tpa_end1 = (struct rx_tpa_end_cmp_ext *)rxcmp1;
1694 tpa_end1->rx_tpa_end_cmp_errors_v2 |=
1695 cpu_to_le32(RX_TPA_END_CMP_ERRORS);
1696 }
1697 return bnxt_rx_pkt(bp, bnapi, raw_cons, event);
1698}
1699
Michael Chan4bb13ab2016-04-05 14:09:01 -04001700#define BNXT_GET_EVENT_PORT(data) \
Michael Chan87c374d2016-12-02 21:17:16 -05001701 ((data) & \
1702 ASYNC_EVENT_CMPL_PORT_CONN_NOT_ALLOWED_EVENT_DATA1_PORT_ID_MASK)
Michael Chan4bb13ab2016-04-05 14:09:01 -04001703
Michael Chanc0c050c2015-10-22 16:01:17 -04001704static int bnxt_async_event_process(struct bnxt *bp,
1705 struct hwrm_async_event_cmpl *cmpl)
1706{
1707 u16 event_id = le16_to_cpu(cmpl->event_id);
1708
1709 /* TODO CHIMP_FW: Define event id's for link change, error etc */
1710 switch (event_id) {
Michael Chan87c374d2016-12-02 21:17:16 -05001711 case ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE: {
Michael Chan8cbde112016-04-11 04:11:14 -04001712 u32 data1 = le32_to_cpu(cmpl->event_data1);
1713 struct bnxt_link_info *link_info = &bp->link_info;
1714
1715 if (BNXT_VF(bp))
1716 goto async_event_process_exit;
Michael Chana8168b62017-12-06 17:31:22 -05001717
1718 /* print unsupported speed warning in forced speed mode only */
1719 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED) &&
1720 (data1 & 0x20000)) {
Michael Chan8cbde112016-04-11 04:11:14 -04001721 u16 fw_speed = link_info->force_link_speed;
1722 u32 speed = bnxt_fw_to_ethtool_speed(fw_speed);
1723
Michael Chana8168b62017-12-06 17:31:22 -05001724 if (speed != SPEED_UNKNOWN)
1725 netdev_warn(bp->dev, "Link speed %d no longer supported\n",
1726 speed);
Michael Chan8cbde112016-04-11 04:11:14 -04001727 }
Michael Chan286ef9d2016-11-16 21:13:08 -05001728 set_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT, &bp->sp_event);
Michael Chan8cbde112016-04-11 04:11:14 -04001729 /* fall thru */
1730 }
Michael Chan87c374d2016-12-02 21:17:16 -05001731 case ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE:
Michael Chanc0c050c2015-10-22 16:01:17 -04001732 set_bit(BNXT_LINK_CHNG_SP_EVENT, &bp->sp_event);
Jeffrey Huang19241362016-02-26 04:00:00 -05001733 break;
Michael Chan87c374d2016-12-02 21:17:16 -05001734 case ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD:
Jeffrey Huang19241362016-02-26 04:00:00 -05001735 set_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT, &bp->sp_event);
Michael Chanc0c050c2015-10-22 16:01:17 -04001736 break;
Michael Chan87c374d2016-12-02 21:17:16 -05001737 case ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED: {
Michael Chan4bb13ab2016-04-05 14:09:01 -04001738 u32 data1 = le32_to_cpu(cmpl->event_data1);
1739 u16 port_id = BNXT_GET_EVENT_PORT(data1);
1740
1741 if (BNXT_VF(bp))
1742 break;
1743
1744 if (bp->pf.port_id != port_id)
1745 break;
1746
Michael Chan4bb13ab2016-04-05 14:09:01 -04001747 set_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT, &bp->sp_event);
1748 break;
1749 }
Michael Chan87c374d2016-12-02 21:17:16 -05001750 case ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE:
Michael Chanfc0f1922016-06-13 02:25:30 -04001751 if (BNXT_PF(bp))
1752 goto async_event_process_exit;
1753 set_bit(BNXT_RESET_TASK_SILENT_SP_EVENT, &bp->sp_event);
1754 break;
Michael Chanc0c050c2015-10-22 16:01:17 -04001755 default:
Jeffrey Huang19241362016-02-26 04:00:00 -05001756 goto async_event_process_exit;
Michael Chanc0c050c2015-10-22 16:01:17 -04001757 }
Michael Chanc213eae2017-10-13 21:09:29 -04001758 bnxt_queue_sp_work(bp);
Jeffrey Huang19241362016-02-26 04:00:00 -05001759async_event_process_exit:
Michael Chana588e452016-12-07 00:26:21 -05001760 bnxt_ulp_async_events(bp, cmpl);
Michael Chanc0c050c2015-10-22 16:01:17 -04001761 return 0;
1762}
1763
1764static int bnxt_hwrm_handler(struct bnxt *bp, struct tx_cmp *txcmp)
1765{
1766 u16 cmpl_type = TX_CMP_TYPE(txcmp), vf_id, seq_id;
1767 struct hwrm_cmpl *h_cmpl = (struct hwrm_cmpl *)txcmp;
1768 struct hwrm_fwd_req_cmpl *fwd_req_cmpl =
1769 (struct hwrm_fwd_req_cmpl *)txcmp;
1770
1771 switch (cmpl_type) {
1772 case CMPL_BASE_TYPE_HWRM_DONE:
1773 seq_id = le16_to_cpu(h_cmpl->sequence_id);
1774 if (seq_id == bp->hwrm_intr_seq_id)
1775 bp->hwrm_intr_seq_id = HWRM_SEQ_ID_INVALID;
1776 else
1777 netdev_err(bp->dev, "Invalid hwrm seq id %d\n", seq_id);
1778 break;
1779
1780 case CMPL_BASE_TYPE_HWRM_FWD_REQ:
1781 vf_id = le16_to_cpu(fwd_req_cmpl->source_id);
1782
1783 if ((vf_id < bp->pf.first_vf_id) ||
1784 (vf_id >= bp->pf.first_vf_id + bp->pf.active_vfs)) {
1785 netdev_err(bp->dev, "Msg contains invalid VF id %x\n",
1786 vf_id);
1787 return -EINVAL;
1788 }
1789
1790 set_bit(vf_id - bp->pf.first_vf_id, bp->pf.vf_event_bmap);
1791 set_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT, &bp->sp_event);
Michael Chanc213eae2017-10-13 21:09:29 -04001792 bnxt_queue_sp_work(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04001793 break;
1794
1795 case CMPL_BASE_TYPE_HWRM_ASYNC_EVENT:
1796 bnxt_async_event_process(bp,
1797 (struct hwrm_async_event_cmpl *)txcmp);
1798
1799 default:
1800 break;
1801 }
1802
1803 return 0;
1804}
1805
1806static irqreturn_t bnxt_msix(int irq, void *dev_instance)
1807{
1808 struct bnxt_napi *bnapi = dev_instance;
1809 struct bnxt *bp = bnapi->bp;
1810 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1811 u32 cons = RING_CMP(cpr->cp_raw_cons);
1812
Andy Gospodarek6a8788f2018-01-09 16:06:20 -05001813 cpr->event_ctr++;
Michael Chanc0c050c2015-10-22 16:01:17 -04001814 prefetch(&cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]);
1815 napi_schedule(&bnapi->napi);
1816 return IRQ_HANDLED;
1817}
1818
1819static inline int bnxt_has_work(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
1820{
1821 u32 raw_cons = cpr->cp_raw_cons;
1822 u16 cons = RING_CMP(raw_cons);
1823 struct tx_cmp *txcmp;
1824
1825 txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)];
1826
1827 return TX_CMP_VALID(txcmp, raw_cons);
1828}
1829
Michael Chanc0c050c2015-10-22 16:01:17 -04001830static irqreturn_t bnxt_inta(int irq, void *dev_instance)
1831{
1832 struct bnxt_napi *bnapi = dev_instance;
1833 struct bnxt *bp = bnapi->bp;
1834 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1835 u32 cons = RING_CMP(cpr->cp_raw_cons);
1836 u32 int_status;
1837
1838 prefetch(&cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]);
1839
1840 if (!bnxt_has_work(bp, cpr)) {
Jeffrey Huang11809492015-11-05 16:25:49 -05001841 int_status = readl(bp->bar0 + BNXT_CAG_REG_LEGACY_INT_STATUS);
Michael Chanc0c050c2015-10-22 16:01:17 -04001842 /* return if erroneous interrupt */
1843 if (!(int_status & (0x10000 << cpr->cp_ring_struct.fw_ring_id)))
1844 return IRQ_NONE;
1845 }
1846
1847 /* disable ring IRQ */
1848 BNXT_CP_DB_IRQ_DIS(cpr->cp_doorbell);
1849
1850 /* Return here if interrupt is shared and is disabled. */
1851 if (unlikely(atomic_read(&bp->intr_sem) != 0))
1852 return IRQ_HANDLED;
1853
1854 napi_schedule(&bnapi->napi);
1855 return IRQ_HANDLED;
1856}
1857
1858static int bnxt_poll_work(struct bnxt *bp, struct bnxt_napi *bnapi, int budget)
1859{
1860 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1861 u32 raw_cons = cpr->cp_raw_cons;
1862 u32 cons;
1863 int tx_pkts = 0;
1864 int rx_pkts = 0;
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001865 u8 event = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04001866 struct tx_cmp *txcmp;
1867
1868 while (1) {
1869 int rc;
1870
1871 cons = RING_CMP(raw_cons);
1872 txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)];
1873
1874 if (!TX_CMP_VALID(txcmp, raw_cons))
1875 break;
1876
Michael Chan67a95e22016-05-04 16:56:43 -04001877 /* The valid test of the entry must be done first before
1878 * reading any further.
1879 */
Michael Chanb67daab2016-05-15 03:04:51 -04001880 dma_rmb();
Michael Chanc0c050c2015-10-22 16:01:17 -04001881 if (TX_CMP_TYPE(txcmp) == CMP_TYPE_TX_L2_CMP) {
1882 tx_pkts++;
1883 /* return full budget so NAPI will complete. */
1884 if (unlikely(tx_pkts > bp->tx_wake_thresh))
1885 rx_pkts = budget;
1886 } else if ((TX_CMP_TYPE(txcmp) & 0x30) == 0x10) {
Michael Chan2270bc52017-06-23 14:01:01 -04001887 if (likely(budget))
1888 rc = bnxt_rx_pkt(bp, bnapi, &raw_cons, &event);
1889 else
1890 rc = bnxt_force_rx_discard(bp, bnapi, &raw_cons,
1891 &event);
Michael Chanc0c050c2015-10-22 16:01:17 -04001892 if (likely(rc >= 0))
1893 rx_pkts += rc;
Michael Chan903649e2017-08-28 13:40:30 -04001894 /* Increment rx_pkts when rc is -ENOMEM to count towards
1895 * the NAPI budget. Otherwise, we may potentially loop
1896 * here forever if we consistently cannot allocate
1897 * buffers.
1898 */
Calvin Owens2edbdb32017-12-08 09:05:26 -08001899 else if (rc == -ENOMEM && budget)
Michael Chan903649e2017-08-28 13:40:30 -04001900 rx_pkts++;
Michael Chanc0c050c2015-10-22 16:01:17 -04001901 else if (rc == -EBUSY) /* partial completion */
1902 break;
Michael Chanc0c050c2015-10-22 16:01:17 -04001903 } else if (unlikely((TX_CMP_TYPE(txcmp) ==
1904 CMPL_BASE_TYPE_HWRM_DONE) ||
1905 (TX_CMP_TYPE(txcmp) ==
1906 CMPL_BASE_TYPE_HWRM_FWD_REQ) ||
1907 (TX_CMP_TYPE(txcmp) ==
1908 CMPL_BASE_TYPE_HWRM_ASYNC_EVENT))) {
1909 bnxt_hwrm_handler(bp, txcmp);
1910 }
1911 raw_cons = NEXT_RAW_CMP(raw_cons);
1912
1913 if (rx_pkts == budget)
1914 break;
1915 }
1916
Michael Chan38413402017-02-06 16:55:43 -05001917 if (event & BNXT_TX_EVENT) {
1918 struct bnxt_tx_ring_info *txr = bnapi->tx_ring;
1919 void __iomem *db = txr->tx_doorbell;
1920 u16 prod = txr->tx_prod;
1921
1922 /* Sync BD data before updating doorbell */
1923 wmb();
1924
Sinan Kayafd141fa2018-03-25 10:39:20 -04001925 bnxt_db_write_relaxed(bp, db, DB_KEY_TX | prod);
Michael Chan38413402017-02-06 16:55:43 -05001926 }
1927
Michael Chanc0c050c2015-10-22 16:01:17 -04001928 cpr->cp_raw_cons = raw_cons;
1929 /* ACK completion ring before freeing tx ring and producing new
1930 * buffers in rx/agg rings to prevent overflowing the completion
1931 * ring.
1932 */
1933 BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
1934
1935 if (tx_pkts)
Michael Chanfa3e93e2017-02-06 16:55:41 -05001936 bnapi->tx_int(bp, bnapi, tx_pkts);
Michael Chanc0c050c2015-10-22 16:01:17 -04001937
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001938 if (event & BNXT_RX_EVENT) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05001939 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
Michael Chanc0c050c2015-10-22 16:01:17 -04001940
Michael Chan434c9752017-05-29 19:06:08 -04001941 bnxt_db_write(bp, rxr->rx_doorbell, DB_KEY_RX | rxr->rx_prod);
1942 if (event & BNXT_AGG_EVENT)
1943 bnxt_db_write(bp, rxr->rx_agg_doorbell,
1944 DB_KEY_RX | rxr->rx_agg_prod);
Michael Chanc0c050c2015-10-22 16:01:17 -04001945 }
1946 return rx_pkts;
1947}
1948
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04001949static int bnxt_poll_nitroa0(struct napi_struct *napi, int budget)
1950{
1951 struct bnxt_napi *bnapi = container_of(napi, struct bnxt_napi, napi);
1952 struct bnxt *bp = bnapi->bp;
1953 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1954 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
1955 struct tx_cmp *txcmp;
1956 struct rx_cmp_ext *rxcmp1;
1957 u32 cp_cons, tmp_raw_cons;
1958 u32 raw_cons = cpr->cp_raw_cons;
1959 u32 rx_pkts = 0;
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001960 u8 event = 0;
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04001961
1962 while (1) {
1963 int rc;
1964
1965 cp_cons = RING_CMP(raw_cons);
1966 txcmp = &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
1967
1968 if (!TX_CMP_VALID(txcmp, raw_cons))
1969 break;
1970
1971 if ((TX_CMP_TYPE(txcmp) & 0x30) == 0x10) {
1972 tmp_raw_cons = NEXT_RAW_CMP(raw_cons);
1973 cp_cons = RING_CMP(tmp_raw_cons);
1974 rxcmp1 = (struct rx_cmp_ext *)
1975 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
1976
1977 if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons))
1978 break;
1979
1980 /* force an error to recycle the buffer */
1981 rxcmp1->rx_cmp_cfa_code_errors_v2 |=
1982 cpu_to_le32(RX_CMPL_ERRORS_CRC_ERROR);
1983
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001984 rc = bnxt_rx_pkt(bp, bnapi, &raw_cons, &event);
Calvin Owens2edbdb32017-12-08 09:05:26 -08001985 if (likely(rc == -EIO) && budget)
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04001986 rx_pkts++;
1987 else if (rc == -EBUSY) /* partial completion */
1988 break;
1989 } else if (unlikely(TX_CMP_TYPE(txcmp) ==
1990 CMPL_BASE_TYPE_HWRM_DONE)) {
1991 bnxt_hwrm_handler(bp, txcmp);
1992 } else {
1993 netdev_err(bp->dev,
1994 "Invalid completion received on special ring\n");
1995 }
1996 raw_cons = NEXT_RAW_CMP(raw_cons);
1997
1998 if (rx_pkts == budget)
1999 break;
2000 }
2001
2002 cpr->cp_raw_cons = raw_cons;
2003 BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
Michael Chan434c9752017-05-29 19:06:08 -04002004 bnxt_db_write(bp, rxr->rx_doorbell, DB_KEY_RX | rxr->rx_prod);
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04002005
Michael Chan434c9752017-05-29 19:06:08 -04002006 if (event & BNXT_AGG_EVENT)
2007 bnxt_db_write(bp, rxr->rx_agg_doorbell,
2008 DB_KEY_RX | rxr->rx_agg_prod);
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04002009
2010 if (!bnxt_has_work(bp, cpr) && rx_pkts < budget) {
Eric Dumazet6ad20162017-01-30 08:22:01 -08002011 napi_complete_done(napi, rx_pkts);
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04002012 BNXT_CP_DB_REARM(cpr->cp_doorbell, cpr->cp_raw_cons);
2013 }
2014 return rx_pkts;
2015}
2016
Michael Chanc0c050c2015-10-22 16:01:17 -04002017static int bnxt_poll(struct napi_struct *napi, int budget)
2018{
2019 struct bnxt_napi *bnapi = container_of(napi, struct bnxt_napi, napi);
2020 struct bnxt *bp = bnapi->bp;
2021 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
2022 int work_done = 0;
2023
Michael Chanc0c050c2015-10-22 16:01:17 -04002024 while (1) {
2025 work_done += bnxt_poll_work(bp, bnapi, budget - work_done);
2026
2027 if (work_done >= budget)
2028 break;
2029
2030 if (!bnxt_has_work(bp, cpr)) {
Michael Chane7b95692016-12-29 12:13:32 -05002031 if (napi_complete_done(napi, work_done))
2032 BNXT_CP_DB_REARM(cpr->cp_doorbell,
2033 cpr->cp_raw_cons);
Michael Chanc0c050c2015-10-22 16:01:17 -04002034 break;
2035 }
2036 }
Andy Gospodarek6a8788f2018-01-09 16:06:20 -05002037 if (bp->flags & BNXT_FLAG_DIM) {
2038 struct net_dim_sample dim_sample;
2039
2040 net_dim_sample(cpr->event_ctr,
2041 cpr->rx_packets,
2042 cpr->rx_bytes,
2043 &dim_sample);
2044 net_dim(&cpr->dim, dim_sample);
2045 }
Michael Chanc0c050c2015-10-22 16:01:17 -04002046 mmiowb();
Michael Chanc0c050c2015-10-22 16:01:17 -04002047 return work_done;
2048}
2049
Michael Chanc0c050c2015-10-22 16:01:17 -04002050static void bnxt_free_tx_skbs(struct bnxt *bp)
2051{
2052 int i, max_idx;
2053 struct pci_dev *pdev = bp->pdev;
2054
Michael Chanb6ab4b02016-01-02 23:44:59 -05002055 if (!bp->tx_ring)
Michael Chanc0c050c2015-10-22 16:01:17 -04002056 return;
2057
2058 max_idx = bp->tx_nr_pages * TX_DESC_CNT;
2059 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05002060 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04002061 int j;
2062
Michael Chanc0c050c2015-10-22 16:01:17 -04002063 for (j = 0; j < max_idx;) {
2064 struct bnxt_sw_tx_bd *tx_buf = &txr->tx_buf_ring[j];
2065 struct sk_buff *skb = tx_buf->skb;
2066 int k, last;
2067
2068 if (!skb) {
2069 j++;
2070 continue;
2071 }
2072
2073 tx_buf->skb = NULL;
2074
2075 if (tx_buf->is_push) {
2076 dev_kfree_skb(skb);
2077 j += 2;
2078 continue;
2079 }
2080
2081 dma_unmap_single(&pdev->dev,
2082 dma_unmap_addr(tx_buf, mapping),
2083 skb_headlen(skb),
2084 PCI_DMA_TODEVICE);
2085
2086 last = tx_buf->nr_frags;
2087 j += 2;
Michael Chand612a572016-01-28 03:11:22 -05002088 for (k = 0; k < last; k++, j++) {
2089 int ring_idx = j & bp->tx_ring_mask;
Michael Chanc0c050c2015-10-22 16:01:17 -04002090 skb_frag_t *frag = &skb_shinfo(skb)->frags[k];
2091
Michael Chand612a572016-01-28 03:11:22 -05002092 tx_buf = &txr->tx_buf_ring[ring_idx];
Michael Chanc0c050c2015-10-22 16:01:17 -04002093 dma_unmap_page(
2094 &pdev->dev,
2095 dma_unmap_addr(tx_buf, mapping),
2096 skb_frag_size(frag), PCI_DMA_TODEVICE);
2097 }
2098 dev_kfree_skb(skb);
2099 }
2100 netdev_tx_reset_queue(netdev_get_tx_queue(bp->dev, i));
2101 }
2102}
2103
2104static void bnxt_free_rx_skbs(struct bnxt *bp)
2105{
2106 int i, max_idx, max_agg_idx;
2107 struct pci_dev *pdev = bp->pdev;
2108
Michael Chanb6ab4b02016-01-02 23:44:59 -05002109 if (!bp->rx_ring)
Michael Chanc0c050c2015-10-22 16:01:17 -04002110 return;
2111
2112 max_idx = bp->rx_nr_pages * RX_DESC_CNT;
2113 max_agg_idx = bp->rx_agg_nr_pages * RX_DESC_CNT;
2114 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05002115 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04002116 int j;
2117
Michael Chanc0c050c2015-10-22 16:01:17 -04002118 if (rxr->rx_tpa) {
2119 for (j = 0; j < MAX_TPA; j++) {
2120 struct bnxt_tpa_info *tpa_info =
2121 &rxr->rx_tpa[j];
2122 u8 *data = tpa_info->data;
2123
2124 if (!data)
2125 continue;
2126
Shannon Nelsonc519fe92017-05-09 18:30:12 -07002127 dma_unmap_single_attrs(&pdev->dev,
2128 tpa_info->mapping,
2129 bp->rx_buf_use_size,
2130 bp->rx_dir,
2131 DMA_ATTR_WEAK_ORDERING);
Michael Chanc0c050c2015-10-22 16:01:17 -04002132
2133 tpa_info->data = NULL;
2134
2135 kfree(data);
2136 }
2137 }
2138
2139 for (j = 0; j < max_idx; j++) {
2140 struct bnxt_sw_rx_bd *rx_buf = &rxr->rx_buf_ring[j];
Michael Chan3ed3a832017-03-28 19:47:31 -04002141 dma_addr_t mapping = rx_buf->mapping;
Michael Chan6bb19472017-02-06 16:55:32 -05002142 void *data = rx_buf->data;
Michael Chanc0c050c2015-10-22 16:01:17 -04002143
2144 if (!data)
2145 continue;
2146
Michael Chanc0c050c2015-10-22 16:01:17 -04002147 rx_buf->data = NULL;
2148
Michael Chan3ed3a832017-03-28 19:47:31 -04002149 if (BNXT_RX_PAGE_MODE(bp)) {
2150 mapping -= bp->rx_dma_offset;
Shannon Nelsonc519fe92017-05-09 18:30:12 -07002151 dma_unmap_page_attrs(&pdev->dev, mapping,
2152 PAGE_SIZE, bp->rx_dir,
2153 DMA_ATTR_WEAK_ORDERING);
Michael Chanc61fb992017-02-06 16:55:36 -05002154 __free_page(data);
Michael Chan3ed3a832017-03-28 19:47:31 -04002155 } else {
Shannon Nelsonc519fe92017-05-09 18:30:12 -07002156 dma_unmap_single_attrs(&pdev->dev, mapping,
2157 bp->rx_buf_use_size,
2158 bp->rx_dir,
2159 DMA_ATTR_WEAK_ORDERING);
Michael Chanc61fb992017-02-06 16:55:36 -05002160 kfree(data);
Michael Chan3ed3a832017-03-28 19:47:31 -04002161 }
Michael Chanc0c050c2015-10-22 16:01:17 -04002162 }
2163
2164 for (j = 0; j < max_agg_idx; j++) {
2165 struct bnxt_sw_rx_agg_bd *rx_agg_buf =
2166 &rxr->rx_agg_ring[j];
2167 struct page *page = rx_agg_buf->page;
2168
2169 if (!page)
2170 continue;
2171
Shannon Nelsonc519fe92017-05-09 18:30:12 -07002172 dma_unmap_page_attrs(&pdev->dev, rx_agg_buf->mapping,
2173 BNXT_RX_PAGE_SIZE,
2174 PCI_DMA_FROMDEVICE,
2175 DMA_ATTR_WEAK_ORDERING);
Michael Chanc0c050c2015-10-22 16:01:17 -04002176
2177 rx_agg_buf->page = NULL;
2178 __clear_bit(j, rxr->rx_agg_bmap);
2179
2180 __free_page(page);
2181 }
Michael Chan89d0a062016-04-25 02:30:51 -04002182 if (rxr->rx_page) {
2183 __free_page(rxr->rx_page);
2184 rxr->rx_page = NULL;
2185 }
Michael Chanc0c050c2015-10-22 16:01:17 -04002186 }
2187}
2188
2189static void bnxt_free_skbs(struct bnxt *bp)
2190{
2191 bnxt_free_tx_skbs(bp);
2192 bnxt_free_rx_skbs(bp);
2193}
2194
2195static void bnxt_free_ring(struct bnxt *bp, struct bnxt_ring_struct *ring)
2196{
2197 struct pci_dev *pdev = bp->pdev;
2198 int i;
2199
2200 for (i = 0; i < ring->nr_pages; i++) {
2201 if (!ring->pg_arr[i])
2202 continue;
2203
2204 dma_free_coherent(&pdev->dev, ring->page_size,
2205 ring->pg_arr[i], ring->dma_arr[i]);
2206
2207 ring->pg_arr[i] = NULL;
2208 }
2209 if (ring->pg_tbl) {
2210 dma_free_coherent(&pdev->dev, ring->nr_pages * 8,
2211 ring->pg_tbl, ring->pg_tbl_map);
2212 ring->pg_tbl = NULL;
2213 }
2214 if (ring->vmem_size && *ring->vmem) {
2215 vfree(*ring->vmem);
2216 *ring->vmem = NULL;
2217 }
2218}
2219
2220static int bnxt_alloc_ring(struct bnxt *bp, struct bnxt_ring_struct *ring)
2221{
2222 int i;
2223 struct pci_dev *pdev = bp->pdev;
2224
2225 if (ring->nr_pages > 1) {
2226 ring->pg_tbl = dma_alloc_coherent(&pdev->dev,
2227 ring->nr_pages * 8,
2228 &ring->pg_tbl_map,
2229 GFP_KERNEL);
2230 if (!ring->pg_tbl)
2231 return -ENOMEM;
2232 }
2233
2234 for (i = 0; i < ring->nr_pages; i++) {
2235 ring->pg_arr[i] = dma_alloc_coherent(&pdev->dev,
2236 ring->page_size,
2237 &ring->dma_arr[i],
2238 GFP_KERNEL);
2239 if (!ring->pg_arr[i])
2240 return -ENOMEM;
2241
2242 if (ring->nr_pages > 1)
2243 ring->pg_tbl[i] = cpu_to_le64(ring->dma_arr[i]);
2244 }
2245
2246 if (ring->vmem_size) {
2247 *ring->vmem = vzalloc(ring->vmem_size);
2248 if (!(*ring->vmem))
2249 return -ENOMEM;
2250 }
2251 return 0;
2252}
2253
2254static void bnxt_free_rx_rings(struct bnxt *bp)
2255{
2256 int i;
2257
Michael Chanb6ab4b02016-01-02 23:44:59 -05002258 if (!bp->rx_ring)
Michael Chanc0c050c2015-10-22 16:01:17 -04002259 return;
2260
2261 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05002262 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04002263 struct bnxt_ring_struct *ring;
2264
Michael Chanc6d30e82017-02-06 16:55:42 -05002265 if (rxr->xdp_prog)
2266 bpf_prog_put(rxr->xdp_prog);
2267
Jesper Dangaard Brouer96a86042018-01-03 11:25:44 +01002268 if (xdp_rxq_info_is_reg(&rxr->xdp_rxq))
2269 xdp_rxq_info_unreg(&rxr->xdp_rxq);
2270
Michael Chanc0c050c2015-10-22 16:01:17 -04002271 kfree(rxr->rx_tpa);
2272 rxr->rx_tpa = NULL;
2273
2274 kfree(rxr->rx_agg_bmap);
2275 rxr->rx_agg_bmap = NULL;
2276
2277 ring = &rxr->rx_ring_struct;
2278 bnxt_free_ring(bp, ring);
2279
2280 ring = &rxr->rx_agg_ring_struct;
2281 bnxt_free_ring(bp, ring);
2282 }
2283}
2284
2285static int bnxt_alloc_rx_rings(struct bnxt *bp)
2286{
2287 int i, rc, agg_rings = 0, tpa_rings = 0;
2288
Michael Chanb6ab4b02016-01-02 23:44:59 -05002289 if (!bp->rx_ring)
2290 return -ENOMEM;
2291
Michael Chanc0c050c2015-10-22 16:01:17 -04002292 if (bp->flags & BNXT_FLAG_AGG_RINGS)
2293 agg_rings = 1;
2294
2295 if (bp->flags & BNXT_FLAG_TPA)
2296 tpa_rings = 1;
2297
2298 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05002299 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04002300 struct bnxt_ring_struct *ring;
2301
Michael Chanc0c050c2015-10-22 16:01:17 -04002302 ring = &rxr->rx_ring_struct;
2303
Jesper Dangaard Brouer96a86042018-01-03 11:25:44 +01002304 rc = xdp_rxq_info_reg(&rxr->xdp_rxq, bp->dev, i);
2305 if (rc < 0)
2306 return rc;
2307
Michael Chanc0c050c2015-10-22 16:01:17 -04002308 rc = bnxt_alloc_ring(bp, ring);
2309 if (rc)
2310 return rc;
2311
2312 if (agg_rings) {
2313 u16 mem_size;
2314
2315 ring = &rxr->rx_agg_ring_struct;
2316 rc = bnxt_alloc_ring(bp, ring);
2317 if (rc)
2318 return rc;
2319
Michael Chan9899bb52018-03-31 13:54:16 -04002320 ring->grp_idx = i;
Michael Chanc0c050c2015-10-22 16:01:17 -04002321 rxr->rx_agg_bmap_size = bp->rx_agg_ring_mask + 1;
2322 mem_size = rxr->rx_agg_bmap_size / 8;
2323 rxr->rx_agg_bmap = kzalloc(mem_size, GFP_KERNEL);
2324 if (!rxr->rx_agg_bmap)
2325 return -ENOMEM;
2326
2327 if (tpa_rings) {
2328 rxr->rx_tpa = kcalloc(MAX_TPA,
2329 sizeof(struct bnxt_tpa_info),
2330 GFP_KERNEL);
2331 if (!rxr->rx_tpa)
2332 return -ENOMEM;
2333 }
2334 }
2335 }
2336 return 0;
2337}
2338
2339static void bnxt_free_tx_rings(struct bnxt *bp)
2340{
2341 int i;
2342 struct pci_dev *pdev = bp->pdev;
2343
Michael Chanb6ab4b02016-01-02 23:44:59 -05002344 if (!bp->tx_ring)
Michael Chanc0c050c2015-10-22 16:01:17 -04002345 return;
2346
2347 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05002348 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04002349 struct bnxt_ring_struct *ring;
2350
Michael Chanc0c050c2015-10-22 16:01:17 -04002351 if (txr->tx_push) {
2352 dma_free_coherent(&pdev->dev, bp->tx_push_size,
2353 txr->tx_push, txr->tx_push_mapping);
2354 txr->tx_push = NULL;
2355 }
2356
2357 ring = &txr->tx_ring_struct;
2358
2359 bnxt_free_ring(bp, ring);
2360 }
2361}
2362
2363static int bnxt_alloc_tx_rings(struct bnxt *bp)
2364{
2365 int i, j, rc;
2366 struct pci_dev *pdev = bp->pdev;
2367
2368 bp->tx_push_size = 0;
2369 if (bp->tx_push_thresh) {
2370 int push_size;
2371
2372 push_size = L1_CACHE_ALIGN(sizeof(struct tx_push_bd) +
2373 bp->tx_push_thresh);
2374
Michael Chan4419dbe2016-02-10 17:33:49 -05002375 if (push_size > 256) {
Michael Chanc0c050c2015-10-22 16:01:17 -04002376 push_size = 0;
2377 bp->tx_push_thresh = 0;
2378 }
2379
2380 bp->tx_push_size = push_size;
2381 }
2382
2383 for (i = 0, j = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05002384 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04002385 struct bnxt_ring_struct *ring;
2386
Michael Chanc0c050c2015-10-22 16:01:17 -04002387 ring = &txr->tx_ring_struct;
2388
2389 rc = bnxt_alloc_ring(bp, ring);
2390 if (rc)
2391 return rc;
2392
Michael Chan9899bb52018-03-31 13:54:16 -04002393 ring->grp_idx = txr->bnapi->index;
Michael Chanc0c050c2015-10-22 16:01:17 -04002394 if (bp->tx_push_size) {
Michael Chanc0c050c2015-10-22 16:01:17 -04002395 dma_addr_t mapping;
2396
2397 /* One pre-allocated DMA buffer to backup
2398 * TX push operation
2399 */
2400 txr->tx_push = dma_alloc_coherent(&pdev->dev,
2401 bp->tx_push_size,
2402 &txr->tx_push_mapping,
2403 GFP_KERNEL);
2404
2405 if (!txr->tx_push)
2406 return -ENOMEM;
2407
Michael Chanc0c050c2015-10-22 16:01:17 -04002408 mapping = txr->tx_push_mapping +
2409 sizeof(struct tx_push_bd);
Michael Chan4419dbe2016-02-10 17:33:49 -05002410 txr->data_mapping = cpu_to_le64(mapping);
Michael Chanc0c050c2015-10-22 16:01:17 -04002411
Michael Chan4419dbe2016-02-10 17:33:49 -05002412 memset(txr->tx_push, 0, sizeof(struct tx_push_bd));
Michael Chanc0c050c2015-10-22 16:01:17 -04002413 }
2414 ring->queue_id = bp->q_info[j].queue_id;
Michael Chan5f449242017-02-06 16:55:40 -05002415 if (i < bp->tx_nr_rings_xdp)
2416 continue;
Michael Chanc0c050c2015-10-22 16:01:17 -04002417 if (i % bp->tx_nr_rings_per_tc == (bp->tx_nr_rings_per_tc - 1))
2418 j++;
2419 }
2420 return 0;
2421}
2422
2423static void bnxt_free_cp_rings(struct bnxt *bp)
2424{
2425 int i;
2426
2427 if (!bp->bnapi)
2428 return;
2429
2430 for (i = 0; i < bp->cp_nr_rings; i++) {
2431 struct bnxt_napi *bnapi = bp->bnapi[i];
2432 struct bnxt_cp_ring_info *cpr;
2433 struct bnxt_ring_struct *ring;
2434
2435 if (!bnapi)
2436 continue;
2437
2438 cpr = &bnapi->cp_ring;
2439 ring = &cpr->cp_ring_struct;
2440
2441 bnxt_free_ring(bp, ring);
2442 }
2443}
2444
2445static int bnxt_alloc_cp_rings(struct bnxt *bp)
2446{
Michael Chane5811b82018-03-31 13:54:18 -04002447 int i, rc, ulp_base_vec, ulp_msix;
Michael Chanc0c050c2015-10-22 16:01:17 -04002448
Michael Chane5811b82018-03-31 13:54:18 -04002449 ulp_msix = bnxt_get_ulp_msix_num(bp);
2450 ulp_base_vec = bnxt_get_ulp_msix_base(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04002451 for (i = 0; i < bp->cp_nr_rings; i++) {
2452 struct bnxt_napi *bnapi = bp->bnapi[i];
2453 struct bnxt_cp_ring_info *cpr;
2454 struct bnxt_ring_struct *ring;
2455
2456 if (!bnapi)
2457 continue;
2458
2459 cpr = &bnapi->cp_ring;
2460 ring = &cpr->cp_ring_struct;
2461
2462 rc = bnxt_alloc_ring(bp, ring);
2463 if (rc)
2464 return rc;
Michael Chane5811b82018-03-31 13:54:18 -04002465
2466 if (ulp_msix && i >= ulp_base_vec)
2467 ring->map_idx = i + ulp_msix;
2468 else
2469 ring->map_idx = i;
Michael Chanc0c050c2015-10-22 16:01:17 -04002470 }
2471 return 0;
2472}
2473
2474static void bnxt_init_ring_struct(struct bnxt *bp)
2475{
2476 int i;
2477
2478 for (i = 0; i < bp->cp_nr_rings; i++) {
2479 struct bnxt_napi *bnapi = bp->bnapi[i];
2480 struct bnxt_cp_ring_info *cpr;
2481 struct bnxt_rx_ring_info *rxr;
2482 struct bnxt_tx_ring_info *txr;
2483 struct bnxt_ring_struct *ring;
2484
2485 if (!bnapi)
2486 continue;
2487
2488 cpr = &bnapi->cp_ring;
2489 ring = &cpr->cp_ring_struct;
2490 ring->nr_pages = bp->cp_nr_pages;
2491 ring->page_size = HW_CMPD_RING_SIZE;
2492 ring->pg_arr = (void **)cpr->cp_desc_ring;
2493 ring->dma_arr = cpr->cp_desc_mapping;
2494 ring->vmem_size = 0;
2495
Michael Chanb6ab4b02016-01-02 23:44:59 -05002496 rxr = bnapi->rx_ring;
Michael Chan3b2b7d92016-01-02 23:45:00 -05002497 if (!rxr)
2498 goto skip_rx;
2499
Michael Chanc0c050c2015-10-22 16:01:17 -04002500 ring = &rxr->rx_ring_struct;
2501 ring->nr_pages = bp->rx_nr_pages;
2502 ring->page_size = HW_RXBD_RING_SIZE;
2503 ring->pg_arr = (void **)rxr->rx_desc_ring;
2504 ring->dma_arr = rxr->rx_desc_mapping;
2505 ring->vmem_size = SW_RXBD_RING_SIZE * bp->rx_nr_pages;
2506 ring->vmem = (void **)&rxr->rx_buf_ring;
2507
2508 ring = &rxr->rx_agg_ring_struct;
2509 ring->nr_pages = bp->rx_agg_nr_pages;
2510 ring->page_size = HW_RXBD_RING_SIZE;
2511 ring->pg_arr = (void **)rxr->rx_agg_desc_ring;
2512 ring->dma_arr = rxr->rx_agg_desc_mapping;
2513 ring->vmem_size = SW_RXBD_AGG_RING_SIZE * bp->rx_agg_nr_pages;
2514 ring->vmem = (void **)&rxr->rx_agg_ring;
2515
Michael Chan3b2b7d92016-01-02 23:45:00 -05002516skip_rx:
Michael Chanb6ab4b02016-01-02 23:44:59 -05002517 txr = bnapi->tx_ring;
Michael Chan3b2b7d92016-01-02 23:45:00 -05002518 if (!txr)
2519 continue;
2520
Michael Chanc0c050c2015-10-22 16:01:17 -04002521 ring = &txr->tx_ring_struct;
2522 ring->nr_pages = bp->tx_nr_pages;
2523 ring->page_size = HW_RXBD_RING_SIZE;
2524 ring->pg_arr = (void **)txr->tx_desc_ring;
2525 ring->dma_arr = txr->tx_desc_mapping;
2526 ring->vmem_size = SW_TXBD_RING_SIZE * bp->tx_nr_pages;
2527 ring->vmem = (void **)&txr->tx_buf_ring;
2528 }
2529}
2530
2531static void bnxt_init_rxbd_pages(struct bnxt_ring_struct *ring, u32 type)
2532{
2533 int i;
2534 u32 prod;
2535 struct rx_bd **rx_buf_ring;
2536
2537 rx_buf_ring = (struct rx_bd **)ring->pg_arr;
2538 for (i = 0, prod = 0; i < ring->nr_pages; i++) {
2539 int j;
2540 struct rx_bd *rxbd;
2541
2542 rxbd = rx_buf_ring[i];
2543 if (!rxbd)
2544 continue;
2545
2546 for (j = 0; j < RX_DESC_CNT; j++, rxbd++, prod++) {
2547 rxbd->rx_bd_len_flags_type = cpu_to_le32(type);
2548 rxbd->rx_bd_opaque = prod;
2549 }
2550 }
2551}
2552
2553static int bnxt_init_one_rx_ring(struct bnxt *bp, int ring_nr)
2554{
2555 struct net_device *dev = bp->dev;
Michael Chanc0c050c2015-10-22 16:01:17 -04002556 struct bnxt_rx_ring_info *rxr;
2557 struct bnxt_ring_struct *ring;
2558 u32 prod, type;
2559 int i;
2560
Michael Chanc0c050c2015-10-22 16:01:17 -04002561 type = (bp->rx_buf_use_size << RX_BD_LEN_SHIFT) |
2562 RX_BD_TYPE_RX_PACKET_BD | RX_BD_FLAGS_EOP;
2563
2564 if (NET_IP_ALIGN == 2)
2565 type |= RX_BD_FLAGS_SOP;
2566
Michael Chanb6ab4b02016-01-02 23:44:59 -05002567 rxr = &bp->rx_ring[ring_nr];
Michael Chanc0c050c2015-10-22 16:01:17 -04002568 ring = &rxr->rx_ring_struct;
2569 bnxt_init_rxbd_pages(ring, type);
2570
Michael Chanc6d30e82017-02-06 16:55:42 -05002571 if (BNXT_RX_PAGE_MODE(bp) && bp->xdp_prog) {
2572 rxr->xdp_prog = bpf_prog_add(bp->xdp_prog, 1);
2573 if (IS_ERR(rxr->xdp_prog)) {
2574 int rc = PTR_ERR(rxr->xdp_prog);
2575
2576 rxr->xdp_prog = NULL;
2577 return rc;
2578 }
2579 }
Michael Chanc0c050c2015-10-22 16:01:17 -04002580 prod = rxr->rx_prod;
2581 for (i = 0; i < bp->rx_ring_size; i++) {
2582 if (bnxt_alloc_rx_data(bp, rxr, prod, GFP_KERNEL) != 0) {
2583 netdev_warn(dev, "init'ed rx ring %d with %d/%d skbs only\n",
2584 ring_nr, i, bp->rx_ring_size);
2585 break;
2586 }
2587 prod = NEXT_RX(prod);
2588 }
2589 rxr->rx_prod = prod;
2590 ring->fw_ring_id = INVALID_HW_RING_ID;
2591
Michael Chanedd0c2c2015-12-27 18:19:19 -05002592 ring = &rxr->rx_agg_ring_struct;
2593 ring->fw_ring_id = INVALID_HW_RING_ID;
2594
Michael Chanc0c050c2015-10-22 16:01:17 -04002595 if (!(bp->flags & BNXT_FLAG_AGG_RINGS))
2596 return 0;
2597
Michael Chan2839f282016-04-25 02:30:50 -04002598 type = ((u32)BNXT_RX_PAGE_SIZE << RX_BD_LEN_SHIFT) |
Michael Chanc0c050c2015-10-22 16:01:17 -04002599 RX_BD_TYPE_RX_AGG_BD | RX_BD_FLAGS_SOP;
2600
2601 bnxt_init_rxbd_pages(ring, type);
2602
2603 prod = rxr->rx_agg_prod;
2604 for (i = 0; i < bp->rx_agg_ring_size; i++) {
2605 if (bnxt_alloc_rx_page(bp, rxr, prod, GFP_KERNEL) != 0) {
2606 netdev_warn(dev, "init'ed rx ring %d with %d/%d pages only\n",
2607 ring_nr, i, bp->rx_ring_size);
2608 break;
2609 }
2610 prod = NEXT_RX_AGG(prod);
2611 }
2612 rxr->rx_agg_prod = prod;
Michael Chanc0c050c2015-10-22 16:01:17 -04002613
2614 if (bp->flags & BNXT_FLAG_TPA) {
2615 if (rxr->rx_tpa) {
2616 u8 *data;
2617 dma_addr_t mapping;
2618
2619 for (i = 0; i < MAX_TPA; i++) {
2620 data = __bnxt_alloc_rx_data(bp, &mapping,
2621 GFP_KERNEL);
2622 if (!data)
2623 return -ENOMEM;
2624
2625 rxr->rx_tpa[i].data = data;
Michael Chanb3dba772017-02-06 16:55:35 -05002626 rxr->rx_tpa[i].data_ptr = data + bp->rx_offset;
Michael Chanc0c050c2015-10-22 16:01:17 -04002627 rxr->rx_tpa[i].mapping = mapping;
2628 }
2629 } else {
2630 netdev_err(bp->dev, "No resource allocated for LRO/GRO\n");
2631 return -ENOMEM;
2632 }
2633 }
2634
2635 return 0;
2636}
2637
Sankar Patchineelam22479252017-03-28 19:47:29 -04002638static void bnxt_init_cp_rings(struct bnxt *bp)
2639{
2640 int i;
2641
2642 for (i = 0; i < bp->cp_nr_rings; i++) {
2643 struct bnxt_cp_ring_info *cpr = &bp->bnapi[i]->cp_ring;
2644 struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
2645
2646 ring->fw_ring_id = INVALID_HW_RING_ID;
Andy Gospodarek6a8788f2018-01-09 16:06:20 -05002647 cpr->rx_ring_coal.coal_ticks = bp->rx_coal.coal_ticks;
2648 cpr->rx_ring_coal.coal_bufs = bp->rx_coal.coal_bufs;
Sankar Patchineelam22479252017-03-28 19:47:29 -04002649 }
2650}
2651
Michael Chanc0c050c2015-10-22 16:01:17 -04002652static int bnxt_init_rx_rings(struct bnxt *bp)
2653{
2654 int i, rc = 0;
2655
Michael Chanc61fb992017-02-06 16:55:36 -05002656 if (BNXT_RX_PAGE_MODE(bp)) {
Michael Chanc6d30e82017-02-06 16:55:42 -05002657 bp->rx_offset = NET_IP_ALIGN + XDP_PACKET_HEADROOM;
2658 bp->rx_dma_offset = XDP_PACKET_HEADROOM;
Michael Chanc61fb992017-02-06 16:55:36 -05002659 } else {
2660 bp->rx_offset = BNXT_RX_OFFSET;
2661 bp->rx_dma_offset = BNXT_RX_DMA_OFFSET;
2662 }
Michael Chanb3dba772017-02-06 16:55:35 -05002663
Michael Chanc0c050c2015-10-22 16:01:17 -04002664 for (i = 0; i < bp->rx_nr_rings; i++) {
2665 rc = bnxt_init_one_rx_ring(bp, i);
2666 if (rc)
2667 break;
2668 }
2669
2670 return rc;
2671}
2672
2673static int bnxt_init_tx_rings(struct bnxt *bp)
2674{
2675 u16 i;
2676
2677 bp->tx_wake_thresh = max_t(int, bp->tx_ring_size / 2,
2678 MAX_SKB_FRAGS + 1);
2679
2680 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05002681 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04002682 struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
2683
2684 ring->fw_ring_id = INVALID_HW_RING_ID;
2685 }
2686
2687 return 0;
2688}
2689
2690static void bnxt_free_ring_grps(struct bnxt *bp)
2691{
2692 kfree(bp->grp_info);
2693 bp->grp_info = NULL;
2694}
2695
2696static int bnxt_init_ring_grps(struct bnxt *bp, bool irq_re_init)
2697{
2698 int i;
2699
2700 if (irq_re_init) {
2701 bp->grp_info = kcalloc(bp->cp_nr_rings,
2702 sizeof(struct bnxt_ring_grp_info),
2703 GFP_KERNEL);
2704 if (!bp->grp_info)
2705 return -ENOMEM;
2706 }
2707 for (i = 0; i < bp->cp_nr_rings; i++) {
2708 if (irq_re_init)
2709 bp->grp_info[i].fw_stats_ctx = INVALID_HW_RING_ID;
2710 bp->grp_info[i].fw_grp_id = INVALID_HW_RING_ID;
2711 bp->grp_info[i].rx_fw_ring_id = INVALID_HW_RING_ID;
2712 bp->grp_info[i].agg_fw_ring_id = INVALID_HW_RING_ID;
2713 bp->grp_info[i].cp_fw_ring_id = INVALID_HW_RING_ID;
2714 }
2715 return 0;
2716}
2717
2718static void bnxt_free_vnics(struct bnxt *bp)
2719{
2720 kfree(bp->vnic_info);
2721 bp->vnic_info = NULL;
2722 bp->nr_vnics = 0;
2723}
2724
2725static int bnxt_alloc_vnics(struct bnxt *bp)
2726{
2727 int num_vnics = 1;
2728
2729#ifdef CONFIG_RFS_ACCEL
2730 if (bp->flags & BNXT_FLAG_RFS)
2731 num_vnics += bp->rx_nr_rings;
2732#endif
2733
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04002734 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
2735 num_vnics++;
2736
Michael Chanc0c050c2015-10-22 16:01:17 -04002737 bp->vnic_info = kcalloc(num_vnics, sizeof(struct bnxt_vnic_info),
2738 GFP_KERNEL);
2739 if (!bp->vnic_info)
2740 return -ENOMEM;
2741
2742 bp->nr_vnics = num_vnics;
2743 return 0;
2744}
2745
2746static void bnxt_init_vnics(struct bnxt *bp)
2747{
2748 int i;
2749
2750 for (i = 0; i < bp->nr_vnics; i++) {
2751 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
2752
2753 vnic->fw_vnic_id = INVALID_HW_RING_ID;
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04002754 vnic->fw_rss_cos_lb_ctx[0] = INVALID_HW_RING_ID;
2755 vnic->fw_rss_cos_lb_ctx[1] = INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04002756 vnic->fw_l2_ctx_id = INVALID_HW_RING_ID;
2757
2758 if (bp->vnic_info[i].rss_hash_key) {
2759 if (i == 0)
2760 prandom_bytes(vnic->rss_hash_key,
2761 HW_HASH_KEY_SIZE);
2762 else
2763 memcpy(vnic->rss_hash_key,
2764 bp->vnic_info[0].rss_hash_key,
2765 HW_HASH_KEY_SIZE);
2766 }
2767 }
2768}
2769
2770static int bnxt_calc_nr_ring_pages(u32 ring_size, int desc_per_pg)
2771{
2772 int pages;
2773
2774 pages = ring_size / desc_per_pg;
2775
2776 if (!pages)
2777 return 1;
2778
2779 pages++;
2780
2781 while (pages & (pages - 1))
2782 pages++;
2783
2784 return pages;
2785}
2786
Michael Chanc6d30e82017-02-06 16:55:42 -05002787void bnxt_set_tpa_flags(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04002788{
2789 bp->flags &= ~BNXT_FLAG_TPA;
Michael Chan341138c2017-01-13 01:32:01 -05002790 if (bp->flags & BNXT_FLAG_NO_AGG_RINGS)
2791 return;
Michael Chanc0c050c2015-10-22 16:01:17 -04002792 if (bp->dev->features & NETIF_F_LRO)
2793 bp->flags |= BNXT_FLAG_LRO;
Michael Chan1054aee2017-12-16 03:09:42 -05002794 else if (bp->dev->features & NETIF_F_GRO_HW)
Michael Chanc0c050c2015-10-22 16:01:17 -04002795 bp->flags |= BNXT_FLAG_GRO;
2796}
2797
2798/* bp->rx_ring_size, bp->tx_ring_size, dev->mtu, BNXT_FLAG_{G|L}RO flags must
2799 * be set on entry.
2800 */
2801void bnxt_set_ring_params(struct bnxt *bp)
2802{
2803 u32 ring_size, rx_size, rx_space;
2804 u32 agg_factor = 0, agg_ring_size = 0;
2805
2806 /* 8 for CRC and VLAN */
2807 rx_size = SKB_DATA_ALIGN(bp->dev->mtu + ETH_HLEN + NET_IP_ALIGN + 8);
2808
2809 rx_space = rx_size + NET_SKB_PAD +
2810 SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
2811
2812 bp->rx_copy_thresh = BNXT_RX_COPY_THRESH;
2813 ring_size = bp->rx_ring_size;
2814 bp->rx_agg_ring_size = 0;
2815 bp->rx_agg_nr_pages = 0;
2816
2817 if (bp->flags & BNXT_FLAG_TPA)
Michael Chan2839f282016-04-25 02:30:50 -04002818 agg_factor = min_t(u32, 4, 65536 / BNXT_RX_PAGE_SIZE);
Michael Chanc0c050c2015-10-22 16:01:17 -04002819
2820 bp->flags &= ~BNXT_FLAG_JUMBO;
Michael Chanbdbd1eb2016-12-29 12:13:43 -05002821 if (rx_space > PAGE_SIZE && !(bp->flags & BNXT_FLAG_NO_AGG_RINGS)) {
Michael Chanc0c050c2015-10-22 16:01:17 -04002822 u32 jumbo_factor;
2823
2824 bp->flags |= BNXT_FLAG_JUMBO;
2825 jumbo_factor = PAGE_ALIGN(bp->dev->mtu - 40) >> PAGE_SHIFT;
2826 if (jumbo_factor > agg_factor)
2827 agg_factor = jumbo_factor;
2828 }
2829 agg_ring_size = ring_size * agg_factor;
2830
2831 if (agg_ring_size) {
2832 bp->rx_agg_nr_pages = bnxt_calc_nr_ring_pages(agg_ring_size,
2833 RX_DESC_CNT);
2834 if (bp->rx_agg_nr_pages > MAX_RX_AGG_PAGES) {
2835 u32 tmp = agg_ring_size;
2836
2837 bp->rx_agg_nr_pages = MAX_RX_AGG_PAGES;
2838 agg_ring_size = MAX_RX_AGG_PAGES * RX_DESC_CNT - 1;
2839 netdev_warn(bp->dev, "rx agg ring size %d reduced to %d.\n",
2840 tmp, agg_ring_size);
2841 }
2842 bp->rx_agg_ring_size = agg_ring_size;
2843 bp->rx_agg_ring_mask = (bp->rx_agg_nr_pages * RX_DESC_CNT) - 1;
2844 rx_size = SKB_DATA_ALIGN(BNXT_RX_COPY_THRESH + NET_IP_ALIGN);
2845 rx_space = rx_size + NET_SKB_PAD +
2846 SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
2847 }
2848
2849 bp->rx_buf_use_size = rx_size;
2850 bp->rx_buf_size = rx_space;
2851
2852 bp->rx_nr_pages = bnxt_calc_nr_ring_pages(ring_size, RX_DESC_CNT);
2853 bp->rx_ring_mask = (bp->rx_nr_pages * RX_DESC_CNT) - 1;
2854
2855 ring_size = bp->tx_ring_size;
2856 bp->tx_nr_pages = bnxt_calc_nr_ring_pages(ring_size, TX_DESC_CNT);
2857 bp->tx_ring_mask = (bp->tx_nr_pages * TX_DESC_CNT) - 1;
2858
2859 ring_size = bp->rx_ring_size * (2 + agg_factor) + bp->tx_ring_size;
2860 bp->cp_ring_size = ring_size;
2861
2862 bp->cp_nr_pages = bnxt_calc_nr_ring_pages(ring_size, CP_DESC_CNT);
2863 if (bp->cp_nr_pages > MAX_CP_PAGES) {
2864 bp->cp_nr_pages = MAX_CP_PAGES;
2865 bp->cp_ring_size = MAX_CP_PAGES * CP_DESC_CNT - 1;
2866 netdev_warn(bp->dev, "completion ring size %d reduced to %d.\n",
2867 ring_size, bp->cp_ring_size);
2868 }
2869 bp->cp_bit = bp->cp_nr_pages * CP_DESC_CNT;
2870 bp->cp_ring_mask = bp->cp_bit - 1;
2871}
2872
Jesper Dangaard Brouer96a86042018-01-03 11:25:44 +01002873/* Changing allocation mode of RX rings.
2874 * TODO: Update when extending xdp_rxq_info to support allocation modes.
2875 */
Michael Chanc61fb992017-02-06 16:55:36 -05002876int bnxt_set_rx_skb_mode(struct bnxt *bp, bool page_mode)
Michael Chan6bb19472017-02-06 16:55:32 -05002877{
Michael Chanc61fb992017-02-06 16:55:36 -05002878 if (page_mode) {
2879 if (bp->dev->mtu > BNXT_MAX_PAGE_MODE_MTU)
2880 return -EOPNOTSUPP;
Michael Chan7eb9bb32017-10-26 11:51:25 -04002881 bp->dev->max_mtu =
2882 min_t(u16, bp->max_mtu, BNXT_MAX_PAGE_MODE_MTU);
Michael Chanc61fb992017-02-06 16:55:36 -05002883 bp->flags &= ~BNXT_FLAG_AGG_RINGS;
2884 bp->flags |= BNXT_FLAG_NO_AGG_RINGS | BNXT_FLAG_RX_PAGE_MODE;
Michael Chanc61fb992017-02-06 16:55:36 -05002885 bp->rx_dir = DMA_BIDIRECTIONAL;
2886 bp->rx_skb_func = bnxt_rx_page_skb;
Michael Chan1054aee2017-12-16 03:09:42 -05002887 /* Disable LRO or GRO_HW */
2888 netdev_update_features(bp->dev);
Michael Chanc61fb992017-02-06 16:55:36 -05002889 } else {
Michael Chan7eb9bb32017-10-26 11:51:25 -04002890 bp->dev->max_mtu = bp->max_mtu;
Michael Chanc61fb992017-02-06 16:55:36 -05002891 bp->flags &= ~BNXT_FLAG_RX_PAGE_MODE;
2892 bp->rx_dir = DMA_FROM_DEVICE;
2893 bp->rx_skb_func = bnxt_rx_skb;
2894 }
Michael Chan6bb19472017-02-06 16:55:32 -05002895 return 0;
2896}
2897
Michael Chanc0c050c2015-10-22 16:01:17 -04002898static void bnxt_free_vnic_attributes(struct bnxt *bp)
2899{
2900 int i;
2901 struct bnxt_vnic_info *vnic;
2902 struct pci_dev *pdev = bp->pdev;
2903
2904 if (!bp->vnic_info)
2905 return;
2906
2907 for (i = 0; i < bp->nr_vnics; i++) {
2908 vnic = &bp->vnic_info[i];
2909
2910 kfree(vnic->fw_grp_ids);
2911 vnic->fw_grp_ids = NULL;
2912
2913 kfree(vnic->uc_list);
2914 vnic->uc_list = NULL;
2915
2916 if (vnic->mc_list) {
2917 dma_free_coherent(&pdev->dev, vnic->mc_list_size,
2918 vnic->mc_list, vnic->mc_list_mapping);
2919 vnic->mc_list = NULL;
2920 }
2921
2922 if (vnic->rss_table) {
2923 dma_free_coherent(&pdev->dev, PAGE_SIZE,
2924 vnic->rss_table,
2925 vnic->rss_table_dma_addr);
2926 vnic->rss_table = NULL;
2927 }
2928
2929 vnic->rss_hash_key = NULL;
2930 vnic->flags = 0;
2931 }
2932}
2933
2934static int bnxt_alloc_vnic_attributes(struct bnxt *bp)
2935{
2936 int i, rc = 0, size;
2937 struct bnxt_vnic_info *vnic;
2938 struct pci_dev *pdev = bp->pdev;
2939 int max_rings;
2940
2941 for (i = 0; i < bp->nr_vnics; i++) {
2942 vnic = &bp->vnic_info[i];
2943
2944 if (vnic->flags & BNXT_VNIC_UCAST_FLAG) {
2945 int mem_size = (BNXT_MAX_UC_ADDRS - 1) * ETH_ALEN;
2946
2947 if (mem_size > 0) {
2948 vnic->uc_list = kmalloc(mem_size, GFP_KERNEL);
2949 if (!vnic->uc_list) {
2950 rc = -ENOMEM;
2951 goto out;
2952 }
2953 }
2954 }
2955
2956 if (vnic->flags & BNXT_VNIC_MCAST_FLAG) {
2957 vnic->mc_list_size = BNXT_MAX_MC_ADDRS * ETH_ALEN;
2958 vnic->mc_list =
2959 dma_alloc_coherent(&pdev->dev,
2960 vnic->mc_list_size,
2961 &vnic->mc_list_mapping,
2962 GFP_KERNEL);
2963 if (!vnic->mc_list) {
2964 rc = -ENOMEM;
2965 goto out;
2966 }
2967 }
2968
2969 if (vnic->flags & BNXT_VNIC_RSS_FLAG)
2970 max_rings = bp->rx_nr_rings;
2971 else
2972 max_rings = 1;
2973
2974 vnic->fw_grp_ids = kcalloc(max_rings, sizeof(u16), GFP_KERNEL);
2975 if (!vnic->fw_grp_ids) {
2976 rc = -ENOMEM;
2977 goto out;
2978 }
2979
Michael Chanae10ae72016-12-29 12:13:38 -05002980 if ((bp->flags & BNXT_FLAG_NEW_RSS_CAP) &&
2981 !(vnic->flags & BNXT_VNIC_RSS_FLAG))
2982 continue;
2983
Michael Chanc0c050c2015-10-22 16:01:17 -04002984 /* Allocate rss table and hash key */
2985 vnic->rss_table = dma_alloc_coherent(&pdev->dev, PAGE_SIZE,
2986 &vnic->rss_table_dma_addr,
2987 GFP_KERNEL);
2988 if (!vnic->rss_table) {
2989 rc = -ENOMEM;
2990 goto out;
2991 }
2992
2993 size = L1_CACHE_ALIGN(HW_HASH_INDEX_SIZE * sizeof(u16));
2994
2995 vnic->rss_hash_key = ((void *)vnic->rss_table) + size;
2996 vnic->rss_hash_key_dma_addr = vnic->rss_table_dma_addr + size;
2997 }
2998 return 0;
2999
3000out:
3001 return rc;
3002}
3003
3004static void bnxt_free_hwrm_resources(struct bnxt *bp)
3005{
3006 struct pci_dev *pdev = bp->pdev;
3007
3008 dma_free_coherent(&pdev->dev, PAGE_SIZE, bp->hwrm_cmd_resp_addr,
3009 bp->hwrm_cmd_resp_dma_addr);
3010
3011 bp->hwrm_cmd_resp_addr = NULL;
3012 if (bp->hwrm_dbg_resp_addr) {
3013 dma_free_coherent(&pdev->dev, HWRM_DBG_REG_BUF_SIZE,
3014 bp->hwrm_dbg_resp_addr,
3015 bp->hwrm_dbg_resp_dma_addr);
3016
3017 bp->hwrm_dbg_resp_addr = NULL;
3018 }
3019}
3020
3021static int bnxt_alloc_hwrm_resources(struct bnxt *bp)
3022{
3023 struct pci_dev *pdev = bp->pdev;
3024
3025 bp->hwrm_cmd_resp_addr = dma_alloc_coherent(&pdev->dev, PAGE_SIZE,
3026 &bp->hwrm_cmd_resp_dma_addr,
3027 GFP_KERNEL);
3028 if (!bp->hwrm_cmd_resp_addr)
3029 return -ENOMEM;
3030 bp->hwrm_dbg_resp_addr = dma_alloc_coherent(&pdev->dev,
3031 HWRM_DBG_REG_BUF_SIZE,
3032 &bp->hwrm_dbg_resp_dma_addr,
3033 GFP_KERNEL);
3034 if (!bp->hwrm_dbg_resp_addr)
3035 netdev_warn(bp->dev, "fail to alloc debug register dma mem\n");
3036
3037 return 0;
3038}
3039
Deepak Khungare605db82017-05-29 19:06:04 -04003040static void bnxt_free_hwrm_short_cmd_req(struct bnxt *bp)
3041{
3042 if (bp->hwrm_short_cmd_req_addr) {
3043 struct pci_dev *pdev = bp->pdev;
3044
3045 dma_free_coherent(&pdev->dev, BNXT_HWRM_MAX_REQ_LEN,
3046 bp->hwrm_short_cmd_req_addr,
3047 bp->hwrm_short_cmd_req_dma_addr);
3048 bp->hwrm_short_cmd_req_addr = NULL;
3049 }
3050}
3051
3052static int bnxt_alloc_hwrm_short_cmd_req(struct bnxt *bp)
3053{
3054 struct pci_dev *pdev = bp->pdev;
3055
3056 bp->hwrm_short_cmd_req_addr =
3057 dma_alloc_coherent(&pdev->dev, BNXT_HWRM_MAX_REQ_LEN,
3058 &bp->hwrm_short_cmd_req_dma_addr,
3059 GFP_KERNEL);
3060 if (!bp->hwrm_short_cmd_req_addr)
3061 return -ENOMEM;
3062
3063 return 0;
3064}
3065
Michael Chanc0c050c2015-10-22 16:01:17 -04003066static void bnxt_free_stats(struct bnxt *bp)
3067{
3068 u32 size, i;
3069 struct pci_dev *pdev = bp->pdev;
3070
Vasundhara Volam00db3cb2018-03-31 13:54:12 -04003071 bp->flags &= ~BNXT_FLAG_PORT_STATS;
3072 bp->flags &= ~BNXT_FLAG_PORT_STATS_EXT;
3073
Michael Chan3bdf56c2016-03-07 15:38:45 -05003074 if (bp->hw_rx_port_stats) {
3075 dma_free_coherent(&pdev->dev, bp->hw_port_stats_size,
3076 bp->hw_rx_port_stats,
3077 bp->hw_rx_port_stats_map);
3078 bp->hw_rx_port_stats = NULL;
Vasundhara Volam00db3cb2018-03-31 13:54:12 -04003079 }
3080
3081 if (bp->hw_rx_port_stats_ext) {
3082 dma_free_coherent(&pdev->dev, sizeof(struct rx_port_stats_ext),
3083 bp->hw_rx_port_stats_ext,
3084 bp->hw_rx_port_stats_ext_map);
3085 bp->hw_rx_port_stats_ext = NULL;
Michael Chan3bdf56c2016-03-07 15:38:45 -05003086 }
3087
Michael Chanc0c050c2015-10-22 16:01:17 -04003088 if (!bp->bnapi)
3089 return;
3090
3091 size = sizeof(struct ctx_hw_stats);
3092
3093 for (i = 0; i < bp->cp_nr_rings; i++) {
3094 struct bnxt_napi *bnapi = bp->bnapi[i];
3095 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
3096
3097 if (cpr->hw_stats) {
3098 dma_free_coherent(&pdev->dev, size, cpr->hw_stats,
3099 cpr->hw_stats_map);
3100 cpr->hw_stats = NULL;
3101 }
3102 }
3103}
3104
3105static int bnxt_alloc_stats(struct bnxt *bp)
3106{
3107 u32 size, i;
3108 struct pci_dev *pdev = bp->pdev;
3109
3110 size = sizeof(struct ctx_hw_stats);
3111
3112 for (i = 0; i < bp->cp_nr_rings; i++) {
3113 struct bnxt_napi *bnapi = bp->bnapi[i];
3114 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
3115
3116 cpr->hw_stats = dma_alloc_coherent(&pdev->dev, size,
3117 &cpr->hw_stats_map,
3118 GFP_KERNEL);
3119 if (!cpr->hw_stats)
3120 return -ENOMEM;
3121
3122 cpr->hw_stats_ctx_id = INVALID_STATS_CTX_ID;
3123 }
Michael Chan3bdf56c2016-03-07 15:38:45 -05003124
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04003125 if (BNXT_PF(bp) && bp->chip_num != CHIP_NUM_58700) {
Michael Chan3bdf56c2016-03-07 15:38:45 -05003126 bp->hw_port_stats_size = sizeof(struct rx_port_stats) +
3127 sizeof(struct tx_port_stats) + 1024;
3128
3129 bp->hw_rx_port_stats =
3130 dma_alloc_coherent(&pdev->dev, bp->hw_port_stats_size,
3131 &bp->hw_rx_port_stats_map,
3132 GFP_KERNEL);
3133 if (!bp->hw_rx_port_stats)
3134 return -ENOMEM;
3135
3136 bp->hw_tx_port_stats = (void *)(bp->hw_rx_port_stats + 1) +
3137 512;
3138 bp->hw_tx_port_stats_map = bp->hw_rx_port_stats_map +
3139 sizeof(struct rx_port_stats) + 512;
3140 bp->flags |= BNXT_FLAG_PORT_STATS;
Vasundhara Volam00db3cb2018-03-31 13:54:12 -04003141
3142 /* Display extended statistics only if FW supports it */
3143 if (bp->hwrm_spec_code < 0x10804 ||
3144 bp->hwrm_spec_code == 0x10900)
3145 return 0;
3146
3147 bp->hw_rx_port_stats_ext =
3148 dma_zalloc_coherent(&pdev->dev,
3149 sizeof(struct rx_port_stats_ext),
3150 &bp->hw_rx_port_stats_ext_map,
3151 GFP_KERNEL);
3152 if (!bp->hw_rx_port_stats_ext)
3153 return 0;
3154
3155 bp->flags |= BNXT_FLAG_PORT_STATS_EXT;
Michael Chan3bdf56c2016-03-07 15:38:45 -05003156 }
Michael Chanc0c050c2015-10-22 16:01:17 -04003157 return 0;
3158}
3159
3160static void bnxt_clear_ring_indices(struct bnxt *bp)
3161{
3162 int i;
3163
3164 if (!bp->bnapi)
3165 return;
3166
3167 for (i = 0; i < bp->cp_nr_rings; i++) {
3168 struct bnxt_napi *bnapi = bp->bnapi[i];
3169 struct bnxt_cp_ring_info *cpr;
3170 struct bnxt_rx_ring_info *rxr;
3171 struct bnxt_tx_ring_info *txr;
3172
3173 if (!bnapi)
3174 continue;
3175
3176 cpr = &bnapi->cp_ring;
3177 cpr->cp_raw_cons = 0;
3178
Michael Chanb6ab4b02016-01-02 23:44:59 -05003179 txr = bnapi->tx_ring;
Michael Chan3b2b7d92016-01-02 23:45:00 -05003180 if (txr) {
3181 txr->tx_prod = 0;
3182 txr->tx_cons = 0;
3183 }
Michael Chanc0c050c2015-10-22 16:01:17 -04003184
Michael Chanb6ab4b02016-01-02 23:44:59 -05003185 rxr = bnapi->rx_ring;
Michael Chan3b2b7d92016-01-02 23:45:00 -05003186 if (rxr) {
3187 rxr->rx_prod = 0;
3188 rxr->rx_agg_prod = 0;
3189 rxr->rx_sw_agg_prod = 0;
Michael Chan376a5b82016-05-10 19:17:59 -04003190 rxr->rx_next_cons = 0;
Michael Chan3b2b7d92016-01-02 23:45:00 -05003191 }
Michael Chanc0c050c2015-10-22 16:01:17 -04003192 }
3193}
3194
3195static void bnxt_free_ntp_fltrs(struct bnxt *bp, bool irq_reinit)
3196{
3197#ifdef CONFIG_RFS_ACCEL
3198 int i;
3199
3200 /* Under rtnl_lock and all our NAPIs have been disabled. It's
3201 * safe to delete the hash table.
3202 */
3203 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
3204 struct hlist_head *head;
3205 struct hlist_node *tmp;
3206 struct bnxt_ntuple_filter *fltr;
3207
3208 head = &bp->ntp_fltr_hash_tbl[i];
3209 hlist_for_each_entry_safe(fltr, tmp, head, hash) {
3210 hlist_del(&fltr->hash);
3211 kfree(fltr);
3212 }
3213 }
3214 if (irq_reinit) {
3215 kfree(bp->ntp_fltr_bmap);
3216 bp->ntp_fltr_bmap = NULL;
3217 }
3218 bp->ntp_fltr_count = 0;
3219#endif
3220}
3221
3222static int bnxt_alloc_ntp_fltrs(struct bnxt *bp)
3223{
3224#ifdef CONFIG_RFS_ACCEL
3225 int i, rc = 0;
3226
3227 if (!(bp->flags & BNXT_FLAG_RFS))
3228 return 0;
3229
3230 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++)
3231 INIT_HLIST_HEAD(&bp->ntp_fltr_hash_tbl[i]);
3232
3233 bp->ntp_fltr_count = 0;
Dan Carpenterac45bd92017-05-06 03:49:01 +03003234 bp->ntp_fltr_bmap = kcalloc(BITS_TO_LONGS(BNXT_NTP_FLTR_MAX_FLTR),
3235 sizeof(long),
Michael Chanc0c050c2015-10-22 16:01:17 -04003236 GFP_KERNEL);
3237
3238 if (!bp->ntp_fltr_bmap)
3239 rc = -ENOMEM;
3240
3241 return rc;
3242#else
3243 return 0;
3244#endif
3245}
3246
3247static void bnxt_free_mem(struct bnxt *bp, bool irq_re_init)
3248{
3249 bnxt_free_vnic_attributes(bp);
3250 bnxt_free_tx_rings(bp);
3251 bnxt_free_rx_rings(bp);
3252 bnxt_free_cp_rings(bp);
3253 bnxt_free_ntp_fltrs(bp, irq_re_init);
3254 if (irq_re_init) {
3255 bnxt_free_stats(bp);
3256 bnxt_free_ring_grps(bp);
3257 bnxt_free_vnics(bp);
Michael Chana960dec2017-02-06 16:55:39 -05003258 kfree(bp->tx_ring_map);
3259 bp->tx_ring_map = NULL;
Michael Chanb6ab4b02016-01-02 23:44:59 -05003260 kfree(bp->tx_ring);
3261 bp->tx_ring = NULL;
3262 kfree(bp->rx_ring);
3263 bp->rx_ring = NULL;
Michael Chanc0c050c2015-10-22 16:01:17 -04003264 kfree(bp->bnapi);
3265 bp->bnapi = NULL;
3266 } else {
3267 bnxt_clear_ring_indices(bp);
3268 }
3269}
3270
3271static int bnxt_alloc_mem(struct bnxt *bp, bool irq_re_init)
3272{
Michael Chan01657bc2016-01-02 23:45:03 -05003273 int i, j, rc, size, arr_size;
Michael Chanc0c050c2015-10-22 16:01:17 -04003274 void *bnapi;
3275
3276 if (irq_re_init) {
3277 /* Allocate bnapi mem pointer array and mem block for
3278 * all queues
3279 */
3280 arr_size = L1_CACHE_ALIGN(sizeof(struct bnxt_napi *) *
3281 bp->cp_nr_rings);
3282 size = L1_CACHE_ALIGN(sizeof(struct bnxt_napi));
3283 bnapi = kzalloc(arr_size + size * bp->cp_nr_rings, GFP_KERNEL);
3284 if (!bnapi)
3285 return -ENOMEM;
3286
3287 bp->bnapi = bnapi;
3288 bnapi += arr_size;
3289 for (i = 0; i < bp->cp_nr_rings; i++, bnapi += size) {
3290 bp->bnapi[i] = bnapi;
3291 bp->bnapi[i]->index = i;
3292 bp->bnapi[i]->bp = bp;
3293 }
3294
Michael Chanb6ab4b02016-01-02 23:44:59 -05003295 bp->rx_ring = kcalloc(bp->rx_nr_rings,
3296 sizeof(struct bnxt_rx_ring_info),
3297 GFP_KERNEL);
3298 if (!bp->rx_ring)
3299 return -ENOMEM;
3300
3301 for (i = 0; i < bp->rx_nr_rings; i++) {
3302 bp->rx_ring[i].bnapi = bp->bnapi[i];
3303 bp->bnapi[i]->rx_ring = &bp->rx_ring[i];
3304 }
3305
3306 bp->tx_ring = kcalloc(bp->tx_nr_rings,
3307 sizeof(struct bnxt_tx_ring_info),
3308 GFP_KERNEL);
3309 if (!bp->tx_ring)
3310 return -ENOMEM;
3311
Michael Chana960dec2017-02-06 16:55:39 -05003312 bp->tx_ring_map = kcalloc(bp->tx_nr_rings, sizeof(u16),
3313 GFP_KERNEL);
3314
3315 if (!bp->tx_ring_map)
3316 return -ENOMEM;
3317
Michael Chan01657bc2016-01-02 23:45:03 -05003318 if (bp->flags & BNXT_FLAG_SHARED_RINGS)
3319 j = 0;
3320 else
3321 j = bp->rx_nr_rings;
3322
3323 for (i = 0; i < bp->tx_nr_rings; i++, j++) {
3324 bp->tx_ring[i].bnapi = bp->bnapi[j];
3325 bp->bnapi[j]->tx_ring = &bp->tx_ring[i];
Michael Chan5f449242017-02-06 16:55:40 -05003326 bp->tx_ring_map[i] = bp->tx_nr_rings_xdp + i;
Michael Chan38413402017-02-06 16:55:43 -05003327 if (i >= bp->tx_nr_rings_xdp) {
Michael Chan5f449242017-02-06 16:55:40 -05003328 bp->tx_ring[i].txq_index = i -
3329 bp->tx_nr_rings_xdp;
Michael Chan38413402017-02-06 16:55:43 -05003330 bp->bnapi[j]->tx_int = bnxt_tx_int;
3331 } else {
Michael Chanfa3e93e2017-02-06 16:55:41 -05003332 bp->bnapi[j]->flags |= BNXT_NAPI_FLAG_XDP;
Michael Chan38413402017-02-06 16:55:43 -05003333 bp->bnapi[j]->tx_int = bnxt_tx_int_xdp;
3334 }
Michael Chanb6ab4b02016-01-02 23:44:59 -05003335 }
3336
Michael Chanc0c050c2015-10-22 16:01:17 -04003337 rc = bnxt_alloc_stats(bp);
3338 if (rc)
3339 goto alloc_mem_err;
3340
3341 rc = bnxt_alloc_ntp_fltrs(bp);
3342 if (rc)
3343 goto alloc_mem_err;
3344
3345 rc = bnxt_alloc_vnics(bp);
3346 if (rc)
3347 goto alloc_mem_err;
3348 }
3349
3350 bnxt_init_ring_struct(bp);
3351
3352 rc = bnxt_alloc_rx_rings(bp);
3353 if (rc)
3354 goto alloc_mem_err;
3355
3356 rc = bnxt_alloc_tx_rings(bp);
3357 if (rc)
3358 goto alloc_mem_err;
3359
3360 rc = bnxt_alloc_cp_rings(bp);
3361 if (rc)
3362 goto alloc_mem_err;
3363
3364 bp->vnic_info[0].flags |= BNXT_VNIC_RSS_FLAG | BNXT_VNIC_MCAST_FLAG |
3365 BNXT_VNIC_UCAST_FLAG;
3366 rc = bnxt_alloc_vnic_attributes(bp);
3367 if (rc)
3368 goto alloc_mem_err;
3369 return 0;
3370
3371alloc_mem_err:
3372 bnxt_free_mem(bp, true);
3373 return rc;
3374}
3375
Michael Chan9d8bc092016-12-29 12:13:33 -05003376static void bnxt_disable_int(struct bnxt *bp)
3377{
3378 int i;
3379
3380 if (!bp->bnapi)
3381 return;
3382
3383 for (i = 0; i < bp->cp_nr_rings; i++) {
3384 struct bnxt_napi *bnapi = bp->bnapi[i];
3385 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
Michael Chandaf1f1e2017-02-20 19:25:17 -05003386 struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
Michael Chan9d8bc092016-12-29 12:13:33 -05003387
Michael Chandaf1f1e2017-02-20 19:25:17 -05003388 if (ring->fw_ring_id != INVALID_HW_RING_ID)
3389 BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
Michael Chan9d8bc092016-12-29 12:13:33 -05003390 }
3391}
3392
Michael Chane5811b82018-03-31 13:54:18 -04003393static int bnxt_cp_num_to_irq_num(struct bnxt *bp, int n)
3394{
3395 struct bnxt_napi *bnapi = bp->bnapi[n];
3396 struct bnxt_cp_ring_info *cpr;
3397
3398 cpr = &bnapi->cp_ring;
3399 return cpr->cp_ring_struct.map_idx;
3400}
3401
Michael Chan9d8bc092016-12-29 12:13:33 -05003402static void bnxt_disable_int_sync(struct bnxt *bp)
3403{
3404 int i;
3405
3406 atomic_inc(&bp->intr_sem);
3407
3408 bnxt_disable_int(bp);
Michael Chane5811b82018-03-31 13:54:18 -04003409 for (i = 0; i < bp->cp_nr_rings; i++) {
3410 int map_idx = bnxt_cp_num_to_irq_num(bp, i);
3411
3412 synchronize_irq(bp->irq_tbl[map_idx].vector);
3413 }
Michael Chan9d8bc092016-12-29 12:13:33 -05003414}
3415
3416static void bnxt_enable_int(struct bnxt *bp)
3417{
3418 int i;
3419
3420 atomic_set(&bp->intr_sem, 0);
3421 for (i = 0; i < bp->cp_nr_rings; i++) {
3422 struct bnxt_napi *bnapi = bp->bnapi[i];
3423 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
3424
3425 BNXT_CP_DB_REARM(cpr->cp_doorbell, cpr->cp_raw_cons);
3426 }
3427}
3428
Michael Chanc0c050c2015-10-22 16:01:17 -04003429void bnxt_hwrm_cmd_hdr_init(struct bnxt *bp, void *request, u16 req_type,
3430 u16 cmpl_ring, u16 target_id)
3431{
Michael Chana8643e12016-02-26 04:00:05 -05003432 struct input *req = request;
Michael Chanc0c050c2015-10-22 16:01:17 -04003433
Michael Chana8643e12016-02-26 04:00:05 -05003434 req->req_type = cpu_to_le16(req_type);
3435 req->cmpl_ring = cpu_to_le16(cmpl_ring);
3436 req->target_id = cpu_to_le16(target_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04003437 req->resp_addr = cpu_to_le64(bp->hwrm_cmd_resp_dma_addr);
3438}
3439
Michael Chanfbfbc482016-02-26 04:00:07 -05003440static int bnxt_hwrm_do_send_msg(struct bnxt *bp, void *msg, u32 msg_len,
3441 int timeout, bool silent)
Michael Chanc0c050c2015-10-22 16:01:17 -04003442{
Michael Chana11fa2b2016-05-15 03:04:47 -04003443 int i, intr_process, rc, tmo_count;
Michael Chana8643e12016-02-26 04:00:05 -05003444 struct input *req = msg;
Michael Chanc0c050c2015-10-22 16:01:17 -04003445 u32 *data = msg;
Michael Chan845adfe2018-03-31 13:54:15 -04003446 __le32 *resp_len;
3447 u8 *valid;
Michael Chanc0c050c2015-10-22 16:01:17 -04003448 u16 cp_ring_id, len = 0;
3449 struct hwrm_err_output *resp = bp->hwrm_cmd_resp_addr;
Deepak Khungare605db82017-05-29 19:06:04 -04003450 u16 max_req_len = BNXT_HWRM_MAX_REQ_LEN;
Vasundhara Volamebd58182017-12-01 03:13:05 -05003451 struct hwrm_short_input short_input = {0};
Michael Chanc0c050c2015-10-22 16:01:17 -04003452
Michael Chana8643e12016-02-26 04:00:05 -05003453 req->seq_id = cpu_to_le16(bp->hwrm_cmd_seq++);
Michael Chanc0c050c2015-10-22 16:01:17 -04003454 memset(resp, 0, PAGE_SIZE);
Michael Chana8643e12016-02-26 04:00:05 -05003455 cp_ring_id = le16_to_cpu(req->cmpl_ring);
Michael Chanc0c050c2015-10-22 16:01:17 -04003456 intr_process = (cp_ring_id == INVALID_HW_RING_ID) ? 0 : 1;
3457
Deepak Khungare605db82017-05-29 19:06:04 -04003458 if (bp->flags & BNXT_FLAG_SHORT_CMD) {
3459 void *short_cmd_req = bp->hwrm_short_cmd_req_addr;
Deepak Khungare605db82017-05-29 19:06:04 -04003460
3461 memcpy(short_cmd_req, req, msg_len);
3462 memset(short_cmd_req + msg_len, 0, BNXT_HWRM_MAX_REQ_LEN -
3463 msg_len);
3464
3465 short_input.req_type = req->req_type;
3466 short_input.signature =
3467 cpu_to_le16(SHORT_REQ_SIGNATURE_SHORT_CMD);
3468 short_input.size = cpu_to_le16(msg_len);
3469 short_input.req_addr =
3470 cpu_to_le64(bp->hwrm_short_cmd_req_dma_addr);
3471
3472 data = (u32 *)&short_input;
3473 msg_len = sizeof(short_input);
3474
3475 /* Sync memory write before updating doorbell */
3476 wmb();
3477
3478 max_req_len = BNXT_HWRM_SHORT_REQ_LEN;
3479 }
3480
Michael Chanc0c050c2015-10-22 16:01:17 -04003481 /* Write request msg to hwrm channel */
3482 __iowrite32_copy(bp->bar0, data, msg_len / 4);
3483
Deepak Khungare605db82017-05-29 19:06:04 -04003484 for (i = msg_len; i < max_req_len; i += 4)
Michael Chand79979a2016-01-07 19:56:57 -05003485 writel(0, bp->bar0 + i);
3486
Michael Chanc0c050c2015-10-22 16:01:17 -04003487 /* currently supports only one outstanding message */
3488 if (intr_process)
Michael Chana8643e12016-02-26 04:00:05 -05003489 bp->hwrm_intr_seq_id = le16_to_cpu(req->seq_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04003490
3491 /* Ring channel doorbell */
3492 writel(1, bp->bar0 + 0x100);
3493
Michael Chanff4fe812016-02-26 04:00:04 -05003494 if (!timeout)
3495 timeout = DFLT_HWRM_CMD_TIMEOUT;
3496
Michael Chanc0c050c2015-10-22 16:01:17 -04003497 i = 0;
Michael Chana11fa2b2016-05-15 03:04:47 -04003498 tmo_count = timeout * 40;
Michael Chan845adfe2018-03-31 13:54:15 -04003499 resp_len = bp->hwrm_cmd_resp_addr + HWRM_RESP_LEN_OFFSET;
Michael Chanc0c050c2015-10-22 16:01:17 -04003500 if (intr_process) {
3501 /* Wait until hwrm response cmpl interrupt is processed */
3502 while (bp->hwrm_intr_seq_id != HWRM_SEQ_ID_INVALID &&
Michael Chana11fa2b2016-05-15 03:04:47 -04003503 i++ < tmo_count) {
3504 usleep_range(25, 40);
Michael Chanc0c050c2015-10-22 16:01:17 -04003505 }
3506
3507 if (bp->hwrm_intr_seq_id != HWRM_SEQ_ID_INVALID) {
3508 netdev_err(bp->dev, "Resp cmpl intr err msg: 0x%x\n",
Michael Chana8643e12016-02-26 04:00:05 -05003509 le16_to_cpu(req->req_type));
Michael Chanc0c050c2015-10-22 16:01:17 -04003510 return -1;
3511 }
Michael Chan845adfe2018-03-31 13:54:15 -04003512 len = (le32_to_cpu(*resp_len) & HWRM_RESP_LEN_MASK) >>
3513 HWRM_RESP_LEN_SFT;
3514 valid = bp->hwrm_cmd_resp_addr + len - 1;
Michael Chanc0c050c2015-10-22 16:01:17 -04003515 } else {
3516 /* Check if response len is updated */
Michael Chana11fa2b2016-05-15 03:04:47 -04003517 for (i = 0; i < tmo_count; i++) {
Michael Chanc0c050c2015-10-22 16:01:17 -04003518 len = (le32_to_cpu(*resp_len) & HWRM_RESP_LEN_MASK) >>
3519 HWRM_RESP_LEN_SFT;
3520 if (len)
3521 break;
Michael Chana11fa2b2016-05-15 03:04:47 -04003522 usleep_range(25, 40);
Michael Chanc0c050c2015-10-22 16:01:17 -04003523 }
3524
Michael Chana11fa2b2016-05-15 03:04:47 -04003525 if (i >= tmo_count) {
Michael Chanc0c050c2015-10-22 16:01:17 -04003526 netdev_err(bp->dev, "Error (timeout: %d) msg {0x%x 0x%x} len:%d\n",
Michael Chana8643e12016-02-26 04:00:05 -05003527 timeout, le16_to_cpu(req->req_type),
Michael Chan8578d6c2016-05-15 03:04:48 -04003528 le16_to_cpu(req->seq_id), len);
Michael Chanc0c050c2015-10-22 16:01:17 -04003529 return -1;
3530 }
3531
Michael Chan845adfe2018-03-31 13:54:15 -04003532 /* Last byte of resp contains valid bit */
3533 valid = bp->hwrm_cmd_resp_addr + len - 1;
Michael Chana11fa2b2016-05-15 03:04:47 -04003534 for (i = 0; i < 5; i++) {
Michael Chan845adfe2018-03-31 13:54:15 -04003535 /* make sure we read from updated DMA memory */
3536 dma_rmb();
3537 if (*valid)
Michael Chanc0c050c2015-10-22 16:01:17 -04003538 break;
Michael Chana11fa2b2016-05-15 03:04:47 -04003539 udelay(1);
Michael Chanc0c050c2015-10-22 16:01:17 -04003540 }
3541
Michael Chana11fa2b2016-05-15 03:04:47 -04003542 if (i >= 5) {
Michael Chanc0c050c2015-10-22 16:01:17 -04003543 netdev_err(bp->dev, "Error (timeout: %d) msg {0x%x 0x%x} len:%d v:%d\n",
Michael Chana8643e12016-02-26 04:00:05 -05003544 timeout, le16_to_cpu(req->req_type),
3545 le16_to_cpu(req->seq_id), len, *valid);
Michael Chanc0c050c2015-10-22 16:01:17 -04003546 return -1;
3547 }
3548 }
3549
Michael Chan845adfe2018-03-31 13:54:15 -04003550 /* Zero valid bit for compatibility. Valid bit in an older spec
3551 * may become a new field in a newer spec. We must make sure that
3552 * a new field not implemented by old spec will read zero.
3553 */
3554 *valid = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04003555 rc = le16_to_cpu(resp->error_code);
Michael Chanfbfbc482016-02-26 04:00:07 -05003556 if (rc && !silent)
Michael Chanc0c050c2015-10-22 16:01:17 -04003557 netdev_err(bp->dev, "hwrm req_type 0x%x seq id 0x%x error 0x%x\n",
3558 le16_to_cpu(resp->req_type),
3559 le16_to_cpu(resp->seq_id), rc);
Michael Chanfbfbc482016-02-26 04:00:07 -05003560 return rc;
3561}
3562
3563int _hwrm_send_message(struct bnxt *bp, void *msg, u32 msg_len, int timeout)
3564{
3565 return bnxt_hwrm_do_send_msg(bp, msg, msg_len, timeout, false);
Michael Chanc0c050c2015-10-22 16:01:17 -04003566}
3567
Michael Chancc72f3b2017-10-13 21:09:33 -04003568int _hwrm_send_message_silent(struct bnxt *bp, void *msg, u32 msg_len,
3569 int timeout)
3570{
3571 return bnxt_hwrm_do_send_msg(bp, msg, msg_len, timeout, true);
3572}
3573
Michael Chanc0c050c2015-10-22 16:01:17 -04003574int hwrm_send_message(struct bnxt *bp, void *msg, u32 msg_len, int timeout)
3575{
3576 int rc;
3577
3578 mutex_lock(&bp->hwrm_cmd_lock);
3579 rc = _hwrm_send_message(bp, msg, msg_len, timeout);
3580 mutex_unlock(&bp->hwrm_cmd_lock);
3581 return rc;
3582}
3583
Michael Chan90e209212016-02-26 04:00:08 -05003584int hwrm_send_message_silent(struct bnxt *bp, void *msg, u32 msg_len,
3585 int timeout)
3586{
3587 int rc;
3588
3589 mutex_lock(&bp->hwrm_cmd_lock);
3590 rc = bnxt_hwrm_do_send_msg(bp, msg, msg_len, timeout, true);
3591 mutex_unlock(&bp->hwrm_cmd_lock);
3592 return rc;
3593}
3594
Michael Chana1653b12016-12-07 00:26:20 -05003595int bnxt_hwrm_func_rgtr_async_events(struct bnxt *bp, unsigned long *bmap,
3596 int bmap_size)
Michael Chanc0c050c2015-10-22 16:01:17 -04003597{
3598 struct hwrm_func_drv_rgtr_input req = {0};
Michael Chan25be8622016-04-05 14:09:00 -04003599 DECLARE_BITMAP(async_events_bmap, 256);
3600 u32 *events = (u32 *)async_events_bmap;
Michael Chana1653b12016-12-07 00:26:20 -05003601 int i;
Michael Chanc0c050c2015-10-22 16:01:17 -04003602
3603 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_RGTR, -1, -1);
3604
3605 req.enables =
Michael Chana1653b12016-12-07 00:26:20 -05003606 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_ASYNC_EVENT_FWD);
Michael Chanc0c050c2015-10-22 16:01:17 -04003607
Michael Chan25be8622016-04-05 14:09:00 -04003608 memset(async_events_bmap, 0, sizeof(async_events_bmap));
3609 for (i = 0; i < ARRAY_SIZE(bnxt_async_events_arr); i++)
3610 __set_bit(bnxt_async_events_arr[i], async_events_bmap);
3611
Michael Chana1653b12016-12-07 00:26:20 -05003612 if (bmap && bmap_size) {
3613 for (i = 0; i < bmap_size; i++) {
3614 if (test_bit(i, bmap))
3615 __set_bit(i, async_events_bmap);
3616 }
3617 }
3618
Michael Chan25be8622016-04-05 14:09:00 -04003619 for (i = 0; i < 8; i++)
3620 req.async_event_fwd[i] |= cpu_to_le32(events[i]);
3621
Michael Chana1653b12016-12-07 00:26:20 -05003622 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3623}
3624
3625static int bnxt_hwrm_func_drv_rgtr(struct bnxt *bp)
3626{
3627 struct hwrm_func_drv_rgtr_input req = {0};
3628
3629 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_RGTR, -1, -1);
3630
3631 req.enables =
3632 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_OS_TYPE |
3633 FUNC_DRV_RGTR_REQ_ENABLES_VER);
3634
Michael Chan11f15ed2016-04-05 14:08:55 -04003635 req.os_type = cpu_to_le16(FUNC_DRV_RGTR_REQ_OS_TYPE_LINUX);
Michael Chand4f52de2018-03-31 13:54:06 -04003636 req.flags = cpu_to_le32(FUNC_DRV_RGTR_REQ_FLAGS_16BIT_VER_MODE);
3637 req.ver_maj_8b = DRV_VER_MAJ;
3638 req.ver_min_8b = DRV_VER_MIN;
3639 req.ver_upd_8b = DRV_VER_UPD;
3640 req.ver_maj = cpu_to_le16(DRV_VER_MAJ);
3641 req.ver_min = cpu_to_le16(DRV_VER_MIN);
3642 req.ver_upd = cpu_to_le16(DRV_VER_UPD);
Michael Chanc0c050c2015-10-22 16:01:17 -04003643
3644 if (BNXT_PF(bp)) {
Michael Chan9b0436c2017-07-11 13:05:36 -04003645 u32 data[8];
Michael Chana1653b12016-12-07 00:26:20 -05003646 int i;
Michael Chanc0c050c2015-10-22 16:01:17 -04003647
Michael Chan9b0436c2017-07-11 13:05:36 -04003648 memset(data, 0, sizeof(data));
3649 for (i = 0; i < ARRAY_SIZE(bnxt_vf_req_snif); i++) {
3650 u16 cmd = bnxt_vf_req_snif[i];
3651 unsigned int bit, idx;
3652
3653 idx = cmd / 32;
3654 bit = cmd % 32;
3655 data[idx] |= 1 << bit;
3656 }
Michael Chanc0c050c2015-10-22 16:01:17 -04003657
Michael Chande68f5de2015-12-09 19:35:41 -05003658 for (i = 0; i < 8; i++)
3659 req.vf_req_fwd[i] = cpu_to_le32(data[i]);
3660
Michael Chanc0c050c2015-10-22 16:01:17 -04003661 req.enables |=
3662 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_VF_REQ_FWD);
3663 }
3664
3665 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3666}
3667
Jeffrey Huangbe58a0d2015-12-27 18:19:18 -05003668static int bnxt_hwrm_func_drv_unrgtr(struct bnxt *bp)
3669{
3670 struct hwrm_func_drv_unrgtr_input req = {0};
3671
3672 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_UNRGTR, -1, -1);
3673 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3674}
3675
Michael Chanc0c050c2015-10-22 16:01:17 -04003676static int bnxt_hwrm_tunnel_dst_port_free(struct bnxt *bp, u8 tunnel_type)
3677{
3678 u32 rc = 0;
3679 struct hwrm_tunnel_dst_port_free_input req = {0};
3680
3681 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_TUNNEL_DST_PORT_FREE, -1, -1);
3682 req.tunnel_type = tunnel_type;
3683
3684 switch (tunnel_type) {
3685 case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN:
3686 req.tunnel_dst_port_id = bp->vxlan_fw_dst_port_id;
3687 break;
3688 case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE:
3689 req.tunnel_dst_port_id = bp->nge_fw_dst_port_id;
3690 break;
3691 default:
3692 break;
3693 }
3694
3695 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3696 if (rc)
3697 netdev_err(bp->dev, "hwrm_tunnel_dst_port_free failed. rc:%d\n",
3698 rc);
3699 return rc;
3700}
3701
3702static int bnxt_hwrm_tunnel_dst_port_alloc(struct bnxt *bp, __be16 port,
3703 u8 tunnel_type)
3704{
3705 u32 rc = 0;
3706 struct hwrm_tunnel_dst_port_alloc_input req = {0};
3707 struct hwrm_tunnel_dst_port_alloc_output *resp = bp->hwrm_cmd_resp_addr;
3708
3709 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_TUNNEL_DST_PORT_ALLOC, -1, -1);
3710
3711 req.tunnel_type = tunnel_type;
3712 req.tunnel_dst_port_val = port;
3713
3714 mutex_lock(&bp->hwrm_cmd_lock);
3715 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3716 if (rc) {
3717 netdev_err(bp->dev, "hwrm_tunnel_dst_port_alloc failed. rc:%d\n",
3718 rc);
3719 goto err_out;
3720 }
3721
Christophe Jaillet57aac712016-11-22 06:14:40 +01003722 switch (tunnel_type) {
3723 case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_VXLAN:
Michael Chanc0c050c2015-10-22 16:01:17 -04003724 bp->vxlan_fw_dst_port_id = resp->tunnel_dst_port_id;
Christophe Jaillet57aac712016-11-22 06:14:40 +01003725 break;
3726 case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_GENEVE:
Michael Chanc0c050c2015-10-22 16:01:17 -04003727 bp->nge_fw_dst_port_id = resp->tunnel_dst_port_id;
Christophe Jaillet57aac712016-11-22 06:14:40 +01003728 break;
3729 default:
3730 break;
3731 }
3732
Michael Chanc0c050c2015-10-22 16:01:17 -04003733err_out:
3734 mutex_unlock(&bp->hwrm_cmd_lock);
3735 return rc;
3736}
3737
3738static int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt *bp, u16 vnic_id)
3739{
3740 struct hwrm_cfa_l2_set_rx_mask_input req = {0};
3741 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
3742
3743 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_L2_SET_RX_MASK, -1, -1);
Michael Chanc1935542015-12-27 18:19:28 -05003744 req.vnic_id = cpu_to_le32(vnic->fw_vnic_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04003745
3746 req.num_mc_entries = cpu_to_le32(vnic->mc_list_count);
3747 req.mc_tbl_addr = cpu_to_le64(vnic->mc_list_mapping);
3748 req.mask = cpu_to_le32(vnic->rx_mask);
3749 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3750}
3751
3752#ifdef CONFIG_RFS_ACCEL
3753static int bnxt_hwrm_cfa_ntuple_filter_free(struct bnxt *bp,
3754 struct bnxt_ntuple_filter *fltr)
3755{
3756 struct hwrm_cfa_ntuple_filter_free_input req = {0};
3757
3758 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_NTUPLE_FILTER_FREE, -1, -1);
3759 req.ntuple_filter_id = fltr->filter_id;
3760 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3761}
3762
3763#define BNXT_NTP_FLTR_FLAGS \
3764 (CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_L2_FILTER_ID | \
3765 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_ETHERTYPE | \
3766 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_MACADDR | \
3767 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IPADDR_TYPE | \
3768 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR | \
3769 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR_MASK | \
3770 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR | \
3771 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR_MASK | \
3772 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IP_PROTOCOL | \
3773 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT | \
3774 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT_MASK | \
3775 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT | \
3776 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT_MASK | \
Michael Chanc1935542015-12-27 18:19:28 -05003777 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_ID)
Michael Chanc0c050c2015-10-22 16:01:17 -04003778
Michael Chan61aad722017-02-12 19:18:14 -05003779#define BNXT_NTP_TUNNEL_FLTR_FLAG \
3780 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_TUNNEL_TYPE
3781
Michael Chanc0c050c2015-10-22 16:01:17 -04003782static int bnxt_hwrm_cfa_ntuple_filter_alloc(struct bnxt *bp,
3783 struct bnxt_ntuple_filter *fltr)
3784{
3785 int rc = 0;
3786 struct hwrm_cfa_ntuple_filter_alloc_input req = {0};
3787 struct hwrm_cfa_ntuple_filter_alloc_output *resp =
3788 bp->hwrm_cmd_resp_addr;
3789 struct flow_keys *keys = &fltr->fkeys;
3790 struct bnxt_vnic_info *vnic = &bp->vnic_info[fltr->rxq + 1];
3791
3792 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_NTUPLE_FILTER_ALLOC, -1, -1);
Michael Chana54c4d72016-07-25 12:33:35 -04003793 req.l2_filter_id = bp->vnic_info[0].fw_l2_filter_id[fltr->l2_fltr_idx];
Michael Chanc0c050c2015-10-22 16:01:17 -04003794
3795 req.enables = cpu_to_le32(BNXT_NTP_FLTR_FLAGS);
3796
3797 req.ethertype = htons(ETH_P_IP);
3798 memcpy(req.src_macaddr, fltr->src_mac_addr, ETH_ALEN);
Michael Chanc1935542015-12-27 18:19:28 -05003799 req.ip_addr_type = CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV4;
Michael Chanc0c050c2015-10-22 16:01:17 -04003800 req.ip_protocol = keys->basic.ip_proto;
3801
Michael Chandda0e742016-12-29 12:13:40 -05003802 if (keys->basic.n_proto == htons(ETH_P_IPV6)) {
3803 int i;
3804
3805 req.ethertype = htons(ETH_P_IPV6);
3806 req.ip_addr_type =
3807 CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV6;
3808 *(struct in6_addr *)&req.src_ipaddr[0] =
3809 keys->addrs.v6addrs.src;
3810 *(struct in6_addr *)&req.dst_ipaddr[0] =
3811 keys->addrs.v6addrs.dst;
3812 for (i = 0; i < 4; i++) {
3813 req.src_ipaddr_mask[i] = cpu_to_be32(0xffffffff);
3814 req.dst_ipaddr_mask[i] = cpu_to_be32(0xffffffff);
3815 }
3816 } else {
3817 req.src_ipaddr[0] = keys->addrs.v4addrs.src;
3818 req.src_ipaddr_mask[0] = cpu_to_be32(0xffffffff);
3819 req.dst_ipaddr[0] = keys->addrs.v4addrs.dst;
3820 req.dst_ipaddr_mask[0] = cpu_to_be32(0xffffffff);
3821 }
Michael Chan61aad722017-02-12 19:18:14 -05003822 if (keys->control.flags & FLOW_DIS_ENCAPSULATION) {
3823 req.enables |= cpu_to_le32(BNXT_NTP_TUNNEL_FLTR_FLAG);
3824 req.tunnel_type =
3825 CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_ANYTUNNEL;
3826 }
Michael Chanc0c050c2015-10-22 16:01:17 -04003827
3828 req.src_port = keys->ports.src;
3829 req.src_port_mask = cpu_to_be16(0xffff);
3830 req.dst_port = keys->ports.dst;
3831 req.dst_port_mask = cpu_to_be16(0xffff);
3832
Michael Chanc1935542015-12-27 18:19:28 -05003833 req.dst_id = cpu_to_le16(vnic->fw_vnic_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04003834 mutex_lock(&bp->hwrm_cmd_lock);
3835 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3836 if (!rc)
3837 fltr->filter_id = resp->ntuple_filter_id;
3838 mutex_unlock(&bp->hwrm_cmd_lock);
3839 return rc;
3840}
3841#endif
3842
3843static int bnxt_hwrm_set_vnic_filter(struct bnxt *bp, u16 vnic_id, u16 idx,
3844 u8 *mac_addr)
3845{
3846 u32 rc = 0;
3847 struct hwrm_cfa_l2_filter_alloc_input req = {0};
3848 struct hwrm_cfa_l2_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr;
3849
3850 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_L2_FILTER_ALLOC, -1, -1);
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04003851 req.flags = cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_PATH_RX);
3852 if (!BNXT_CHIP_TYPE_NITRO_A0(bp))
3853 req.flags |=
3854 cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_OUTERMOST);
Michael Chanc1935542015-12-27 18:19:28 -05003855 req.dst_id = cpu_to_le16(bp->vnic_info[vnic_id].fw_vnic_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04003856 req.enables =
3857 cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR |
Michael Chanc1935542015-12-27 18:19:28 -05003858 CFA_L2_FILTER_ALLOC_REQ_ENABLES_DST_ID |
Michael Chanc0c050c2015-10-22 16:01:17 -04003859 CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR_MASK);
3860 memcpy(req.l2_addr, mac_addr, ETH_ALEN);
3861 req.l2_addr_mask[0] = 0xff;
3862 req.l2_addr_mask[1] = 0xff;
3863 req.l2_addr_mask[2] = 0xff;
3864 req.l2_addr_mask[3] = 0xff;
3865 req.l2_addr_mask[4] = 0xff;
3866 req.l2_addr_mask[5] = 0xff;
3867
3868 mutex_lock(&bp->hwrm_cmd_lock);
3869 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3870 if (!rc)
3871 bp->vnic_info[vnic_id].fw_l2_filter_id[idx] =
3872 resp->l2_filter_id;
3873 mutex_unlock(&bp->hwrm_cmd_lock);
3874 return rc;
3875}
3876
3877static int bnxt_hwrm_clear_vnic_filter(struct bnxt *bp)
3878{
3879 u16 i, j, num_of_vnics = 1; /* only vnic 0 supported */
3880 int rc = 0;
3881
3882 /* Any associated ntuple filters will also be cleared by firmware. */
3883 mutex_lock(&bp->hwrm_cmd_lock);
3884 for (i = 0; i < num_of_vnics; i++) {
3885 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
3886
3887 for (j = 0; j < vnic->uc_filter_count; j++) {
3888 struct hwrm_cfa_l2_filter_free_input req = {0};
3889
3890 bnxt_hwrm_cmd_hdr_init(bp, &req,
3891 HWRM_CFA_L2_FILTER_FREE, -1, -1);
3892
3893 req.l2_filter_id = vnic->fw_l2_filter_id[j];
3894
3895 rc = _hwrm_send_message(bp, &req, sizeof(req),
3896 HWRM_CMD_TIMEOUT);
3897 }
3898 vnic->uc_filter_count = 0;
3899 }
3900 mutex_unlock(&bp->hwrm_cmd_lock);
3901
3902 return rc;
3903}
3904
3905static int bnxt_hwrm_vnic_set_tpa(struct bnxt *bp, u16 vnic_id, u32 tpa_flags)
3906{
3907 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
3908 struct hwrm_vnic_tpa_cfg_input req = {0};
3909
Michael Chan3c4fe802018-03-09 23:46:10 -05003910 if (vnic->fw_vnic_id == INVALID_HW_RING_ID)
3911 return 0;
3912
Michael Chanc0c050c2015-10-22 16:01:17 -04003913 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_TPA_CFG, -1, -1);
3914
3915 if (tpa_flags) {
3916 u16 mss = bp->dev->mtu - 40;
3917 u32 nsegs, n, segs = 0, flags;
3918
3919 flags = VNIC_TPA_CFG_REQ_FLAGS_TPA |
3920 VNIC_TPA_CFG_REQ_FLAGS_ENCAP_TPA |
3921 VNIC_TPA_CFG_REQ_FLAGS_RSC_WND_UPDATE |
3922 VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_ECN |
3923 VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_SAME_GRE_SEQ;
3924 if (tpa_flags & BNXT_FLAG_GRO)
3925 flags |= VNIC_TPA_CFG_REQ_FLAGS_GRO;
3926
3927 req.flags = cpu_to_le32(flags);
3928
3929 req.enables =
3930 cpu_to_le32(VNIC_TPA_CFG_REQ_ENABLES_MAX_AGG_SEGS |
Michael Chanc1935542015-12-27 18:19:28 -05003931 VNIC_TPA_CFG_REQ_ENABLES_MAX_AGGS |
3932 VNIC_TPA_CFG_REQ_ENABLES_MIN_AGG_LEN);
Michael Chanc0c050c2015-10-22 16:01:17 -04003933
3934 /* Number of segs are log2 units, and first packet is not
3935 * included as part of this units.
3936 */
Michael Chan2839f282016-04-25 02:30:50 -04003937 if (mss <= BNXT_RX_PAGE_SIZE) {
3938 n = BNXT_RX_PAGE_SIZE / mss;
Michael Chanc0c050c2015-10-22 16:01:17 -04003939 nsegs = (MAX_SKB_FRAGS - 1) * n;
3940 } else {
Michael Chan2839f282016-04-25 02:30:50 -04003941 n = mss / BNXT_RX_PAGE_SIZE;
3942 if (mss & (BNXT_RX_PAGE_SIZE - 1))
Michael Chanc0c050c2015-10-22 16:01:17 -04003943 n++;
3944 nsegs = (MAX_SKB_FRAGS - n) / n;
3945 }
3946
3947 segs = ilog2(nsegs);
3948 req.max_agg_segs = cpu_to_le16(segs);
3949 req.max_aggs = cpu_to_le16(VNIC_TPA_CFG_REQ_MAX_AGGS_MAX);
Michael Chanc1935542015-12-27 18:19:28 -05003950
3951 req.min_agg_len = cpu_to_le32(512);
Michael Chanc0c050c2015-10-22 16:01:17 -04003952 }
3953 req.vnic_id = cpu_to_le16(vnic->fw_vnic_id);
3954
3955 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3956}
3957
3958static int bnxt_hwrm_vnic_set_rss(struct bnxt *bp, u16 vnic_id, bool set_rss)
3959{
3960 u32 i, j, max_rings;
3961 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
3962 struct hwrm_vnic_rss_cfg_input req = {0};
3963
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04003964 if (vnic->fw_rss_cos_lb_ctx[0] == INVALID_HW_RING_ID)
Michael Chanc0c050c2015-10-22 16:01:17 -04003965 return 0;
3966
3967 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_CFG, -1, -1);
3968 if (set_rss) {
Michael Chan87da7f72016-11-16 21:13:09 -05003969 req.hash_type = cpu_to_le32(bp->rss_hash_cfg);
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04003970 if (vnic->flags & BNXT_VNIC_RSS_FLAG) {
3971 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
3972 max_rings = bp->rx_nr_rings - 1;
3973 else
3974 max_rings = bp->rx_nr_rings;
3975 } else {
Michael Chanc0c050c2015-10-22 16:01:17 -04003976 max_rings = 1;
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04003977 }
Michael Chanc0c050c2015-10-22 16:01:17 -04003978
3979 /* Fill the RSS indirection table with ring group ids */
3980 for (i = 0, j = 0; i < HW_HASH_INDEX_SIZE; i++, j++) {
3981 if (j == max_rings)
3982 j = 0;
3983 vnic->rss_table[i] = cpu_to_le16(vnic->fw_grp_ids[j]);
3984 }
3985
3986 req.ring_grp_tbl_addr = cpu_to_le64(vnic->rss_table_dma_addr);
3987 req.hash_key_tbl_addr =
3988 cpu_to_le64(vnic->rss_hash_key_dma_addr);
3989 }
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04003990 req.rss_ctx_idx = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[0]);
Michael Chanc0c050c2015-10-22 16:01:17 -04003991 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3992}
3993
3994static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, u16 vnic_id)
3995{
3996 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
3997 struct hwrm_vnic_plcmodes_cfg_input req = {0};
3998
3999 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_PLCMODES_CFG, -1, -1);
4000 req.flags = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT |
4001 VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV4 |
4002 VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6);
4003 req.enables =
4004 cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID |
4005 VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID);
4006 /* thresholds not implemented in firmware yet */
4007 req.jumbo_thresh = cpu_to_le16(bp->rx_copy_thresh);
4008 req.hds_threshold = cpu_to_le16(bp->rx_copy_thresh);
4009 req.vnic_id = cpu_to_le32(vnic->fw_vnic_id);
4010 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4011}
4012
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004013static void bnxt_hwrm_vnic_ctx_free_one(struct bnxt *bp, u16 vnic_id,
4014 u16 ctx_idx)
Michael Chanc0c050c2015-10-22 16:01:17 -04004015{
4016 struct hwrm_vnic_rss_cos_lb_ctx_free_input req = {0};
4017
4018 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_COS_LB_CTX_FREE, -1, -1);
4019 req.rss_cos_lb_ctx_id =
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004020 cpu_to_le16(bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx]);
Michael Chanc0c050c2015-10-22 16:01:17 -04004021
4022 hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004023 bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx] = INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04004024}
4025
4026static void bnxt_hwrm_vnic_ctx_free(struct bnxt *bp)
4027{
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004028 int i, j;
Michael Chanc0c050c2015-10-22 16:01:17 -04004029
4030 for (i = 0; i < bp->nr_vnics; i++) {
4031 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
4032
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004033 for (j = 0; j < BNXT_MAX_CTX_PER_VNIC; j++) {
4034 if (vnic->fw_rss_cos_lb_ctx[j] != INVALID_HW_RING_ID)
4035 bnxt_hwrm_vnic_ctx_free_one(bp, i, j);
4036 }
Michael Chanc0c050c2015-10-22 16:01:17 -04004037 }
4038 bp->rsscos_nr_ctxs = 0;
4039}
4040
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004041static int bnxt_hwrm_vnic_ctx_alloc(struct bnxt *bp, u16 vnic_id, u16 ctx_idx)
Michael Chanc0c050c2015-10-22 16:01:17 -04004042{
4043 int rc;
4044 struct hwrm_vnic_rss_cos_lb_ctx_alloc_input req = {0};
4045 struct hwrm_vnic_rss_cos_lb_ctx_alloc_output *resp =
4046 bp->hwrm_cmd_resp_addr;
4047
4048 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_COS_LB_CTX_ALLOC, -1,
4049 -1);
4050
4051 mutex_lock(&bp->hwrm_cmd_lock);
4052 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4053 if (!rc)
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004054 bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx] =
Michael Chanc0c050c2015-10-22 16:01:17 -04004055 le16_to_cpu(resp->rss_cos_lb_ctx_id);
4056 mutex_unlock(&bp->hwrm_cmd_lock);
4057
4058 return rc;
4059}
4060
Michael Chanabe93ad2018-03-31 13:54:08 -04004061static u32 bnxt_get_roce_vnic_mode(struct bnxt *bp)
4062{
4063 if (bp->flags & BNXT_FLAG_ROCE_MIRROR_CAP)
4064 return VNIC_CFG_REQ_FLAGS_ROCE_MIRRORING_CAPABLE_VNIC_MODE;
4065 return VNIC_CFG_REQ_FLAGS_ROCE_DUAL_VNIC_MODE;
4066}
4067
Michael Chana588e452016-12-07 00:26:21 -05004068int bnxt_hwrm_vnic_cfg(struct bnxt *bp, u16 vnic_id)
Michael Chanc0c050c2015-10-22 16:01:17 -04004069{
Michael Chanb81a90d2016-01-02 23:45:01 -05004070 unsigned int ring = 0, grp_idx;
Michael Chanc0c050c2015-10-22 16:01:17 -04004071 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
4072 struct hwrm_vnic_cfg_input req = {0};
Michael Chancf6645f2016-06-13 02:25:28 -04004073 u16 def_vlan = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04004074
4075 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_CFG, -1, -1);
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004076
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04004077 req.enables = cpu_to_le32(VNIC_CFG_REQ_ENABLES_DFLT_RING_GRP);
4078 /* Only RSS support for now TBD: COS & LB */
4079 if (vnic->fw_rss_cos_lb_ctx[0] != INVALID_HW_RING_ID) {
4080 req.rss_rule = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[0]);
4081 req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE |
4082 VNIC_CFG_REQ_ENABLES_MRU);
Michael Chanae10ae72016-12-29 12:13:38 -05004083 } else if (vnic->flags & BNXT_VNIC_RFS_NEW_RSS_FLAG) {
4084 req.rss_rule =
4085 cpu_to_le16(bp->vnic_info[0].fw_rss_cos_lb_ctx[0]);
4086 req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE |
4087 VNIC_CFG_REQ_ENABLES_MRU);
4088 req.flags |= cpu_to_le32(VNIC_CFG_REQ_FLAGS_RSS_DFLT_CR_MODE);
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04004089 } else {
4090 req.rss_rule = cpu_to_le16(0xffff);
4091 }
4092
4093 if (BNXT_CHIP_TYPE_NITRO_A0(bp) &&
4094 (vnic->fw_rss_cos_lb_ctx[0] != INVALID_HW_RING_ID)) {
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004095 req.cos_rule = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[1]);
4096 req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_COS_RULE);
4097 } else {
4098 req.cos_rule = cpu_to_le16(0xffff);
4099 }
4100
Michael Chanc0c050c2015-10-22 16:01:17 -04004101 if (vnic->flags & BNXT_VNIC_RSS_FLAG)
Michael Chanb81a90d2016-01-02 23:45:01 -05004102 ring = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04004103 else if (vnic->flags & BNXT_VNIC_RFS_FLAG)
Michael Chanb81a90d2016-01-02 23:45:01 -05004104 ring = vnic_id - 1;
Prashant Sreedharan76595192016-07-18 07:15:22 -04004105 else if ((vnic_id == 1) && BNXT_CHIP_TYPE_NITRO_A0(bp))
4106 ring = bp->rx_nr_rings - 1;
Michael Chanc0c050c2015-10-22 16:01:17 -04004107
Michael Chanb81a90d2016-01-02 23:45:01 -05004108 grp_idx = bp->rx_ring[ring].bnapi->index;
Michael Chanc0c050c2015-10-22 16:01:17 -04004109 req.vnic_id = cpu_to_le16(vnic->fw_vnic_id);
4110 req.dflt_ring_grp = cpu_to_le16(bp->grp_info[grp_idx].fw_grp_id);
4111
4112 req.lb_rule = cpu_to_le16(0xffff);
4113 req.mru = cpu_to_le16(bp->dev->mtu + ETH_HLEN + ETH_FCS_LEN +
4114 VLAN_HLEN);
4115
Michael Chancf6645f2016-06-13 02:25:28 -04004116#ifdef CONFIG_BNXT_SRIOV
4117 if (BNXT_VF(bp))
4118 def_vlan = bp->vf.vlan;
4119#endif
4120 if ((bp->flags & BNXT_FLAG_STRIP_VLAN) || def_vlan)
Michael Chanc0c050c2015-10-22 16:01:17 -04004121 req.flags |= cpu_to_le32(VNIC_CFG_REQ_FLAGS_VLAN_STRIP_MODE);
Michael Chana588e452016-12-07 00:26:21 -05004122 if (!vnic_id && bnxt_ulp_registered(bp->edev, BNXT_ROCE_ULP))
Michael Chanabe93ad2018-03-31 13:54:08 -04004123 req.flags |= cpu_to_le32(bnxt_get_roce_vnic_mode(bp));
Michael Chanc0c050c2015-10-22 16:01:17 -04004124
4125 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4126}
4127
4128static int bnxt_hwrm_vnic_free_one(struct bnxt *bp, u16 vnic_id)
4129{
4130 u32 rc = 0;
4131
4132 if (bp->vnic_info[vnic_id].fw_vnic_id != INVALID_HW_RING_ID) {
4133 struct hwrm_vnic_free_input req = {0};
4134
4135 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_FREE, -1, -1);
4136 req.vnic_id =
4137 cpu_to_le32(bp->vnic_info[vnic_id].fw_vnic_id);
4138
4139 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4140 if (rc)
4141 return rc;
4142 bp->vnic_info[vnic_id].fw_vnic_id = INVALID_HW_RING_ID;
4143 }
4144 return rc;
4145}
4146
4147static void bnxt_hwrm_vnic_free(struct bnxt *bp)
4148{
4149 u16 i;
4150
4151 for (i = 0; i < bp->nr_vnics; i++)
4152 bnxt_hwrm_vnic_free_one(bp, i);
4153}
4154
Michael Chanb81a90d2016-01-02 23:45:01 -05004155static int bnxt_hwrm_vnic_alloc(struct bnxt *bp, u16 vnic_id,
4156 unsigned int start_rx_ring_idx,
4157 unsigned int nr_rings)
Michael Chanc0c050c2015-10-22 16:01:17 -04004158{
Michael Chanb81a90d2016-01-02 23:45:01 -05004159 int rc = 0;
4160 unsigned int i, j, grp_idx, end_idx = start_rx_ring_idx + nr_rings;
Michael Chanc0c050c2015-10-22 16:01:17 -04004161 struct hwrm_vnic_alloc_input req = {0};
4162 struct hwrm_vnic_alloc_output *resp = bp->hwrm_cmd_resp_addr;
4163
4164 /* map ring groups to this vnic */
Michael Chanb81a90d2016-01-02 23:45:01 -05004165 for (i = start_rx_ring_idx, j = 0; i < end_idx; i++, j++) {
4166 grp_idx = bp->rx_ring[i].bnapi->index;
4167 if (bp->grp_info[grp_idx].fw_grp_id == INVALID_HW_RING_ID) {
Michael Chanc0c050c2015-10-22 16:01:17 -04004168 netdev_err(bp->dev, "Not enough ring groups avail:%x req:%x\n",
Michael Chanb81a90d2016-01-02 23:45:01 -05004169 j, nr_rings);
Michael Chanc0c050c2015-10-22 16:01:17 -04004170 break;
4171 }
4172 bp->vnic_info[vnic_id].fw_grp_ids[j] =
Michael Chanb81a90d2016-01-02 23:45:01 -05004173 bp->grp_info[grp_idx].fw_grp_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04004174 }
4175
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004176 bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[0] = INVALID_HW_RING_ID;
4177 bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[1] = INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04004178 if (vnic_id == 0)
4179 req.flags = cpu_to_le32(VNIC_ALLOC_REQ_FLAGS_DEFAULT);
4180
4181 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_ALLOC, -1, -1);
4182
4183 mutex_lock(&bp->hwrm_cmd_lock);
4184 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4185 if (!rc)
4186 bp->vnic_info[vnic_id].fw_vnic_id = le32_to_cpu(resp->vnic_id);
4187 mutex_unlock(&bp->hwrm_cmd_lock);
4188 return rc;
4189}
4190
Michael Chan8fdefd62016-12-29 12:13:36 -05004191static int bnxt_hwrm_vnic_qcaps(struct bnxt *bp)
4192{
4193 struct hwrm_vnic_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
4194 struct hwrm_vnic_qcaps_input req = {0};
4195 int rc;
4196
4197 if (bp->hwrm_spec_code < 0x10600)
4198 return 0;
4199
4200 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_QCAPS, -1, -1);
4201 mutex_lock(&bp->hwrm_cmd_lock);
4202 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4203 if (!rc) {
Michael Chanabe93ad2018-03-31 13:54:08 -04004204 u32 flags = le32_to_cpu(resp->flags);
4205
4206 if (flags & VNIC_QCAPS_RESP_FLAGS_RSS_DFLT_CR_CAP)
Michael Chan8fdefd62016-12-29 12:13:36 -05004207 bp->flags |= BNXT_FLAG_NEW_RSS_CAP;
Michael Chanabe93ad2018-03-31 13:54:08 -04004208 if (flags &
4209 VNIC_QCAPS_RESP_FLAGS_ROCE_MIRRORING_CAPABLE_VNIC_CAP)
4210 bp->flags |= BNXT_FLAG_ROCE_MIRROR_CAP;
Michael Chan8fdefd62016-12-29 12:13:36 -05004211 }
4212 mutex_unlock(&bp->hwrm_cmd_lock);
4213 return rc;
4214}
4215
Michael Chanc0c050c2015-10-22 16:01:17 -04004216static int bnxt_hwrm_ring_grp_alloc(struct bnxt *bp)
4217{
4218 u16 i;
4219 u32 rc = 0;
4220
4221 mutex_lock(&bp->hwrm_cmd_lock);
4222 for (i = 0; i < bp->rx_nr_rings; i++) {
4223 struct hwrm_ring_grp_alloc_input req = {0};
4224 struct hwrm_ring_grp_alloc_output *resp =
4225 bp->hwrm_cmd_resp_addr;
Michael Chanb81a90d2016-01-02 23:45:01 -05004226 unsigned int grp_idx = bp->rx_ring[i].bnapi->index;
Michael Chanc0c050c2015-10-22 16:01:17 -04004227
4228 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_GRP_ALLOC, -1, -1);
4229
Michael Chanb81a90d2016-01-02 23:45:01 -05004230 req.cr = cpu_to_le16(bp->grp_info[grp_idx].cp_fw_ring_id);
4231 req.rr = cpu_to_le16(bp->grp_info[grp_idx].rx_fw_ring_id);
4232 req.ar = cpu_to_le16(bp->grp_info[grp_idx].agg_fw_ring_id);
4233 req.sc = cpu_to_le16(bp->grp_info[grp_idx].fw_stats_ctx);
Michael Chanc0c050c2015-10-22 16:01:17 -04004234
4235 rc = _hwrm_send_message(bp, &req, sizeof(req),
4236 HWRM_CMD_TIMEOUT);
4237 if (rc)
4238 break;
4239
Michael Chanb81a90d2016-01-02 23:45:01 -05004240 bp->grp_info[grp_idx].fw_grp_id =
4241 le32_to_cpu(resp->ring_group_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04004242 }
4243 mutex_unlock(&bp->hwrm_cmd_lock);
4244 return rc;
4245}
4246
4247static int bnxt_hwrm_ring_grp_free(struct bnxt *bp)
4248{
4249 u16 i;
4250 u32 rc = 0;
4251 struct hwrm_ring_grp_free_input req = {0};
4252
4253 if (!bp->grp_info)
4254 return 0;
4255
4256 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_GRP_FREE, -1, -1);
4257
4258 mutex_lock(&bp->hwrm_cmd_lock);
4259 for (i = 0; i < bp->cp_nr_rings; i++) {
4260 if (bp->grp_info[i].fw_grp_id == INVALID_HW_RING_ID)
4261 continue;
4262 req.ring_group_id =
4263 cpu_to_le32(bp->grp_info[i].fw_grp_id);
4264
4265 rc = _hwrm_send_message(bp, &req, sizeof(req),
4266 HWRM_CMD_TIMEOUT);
4267 if (rc)
4268 break;
4269 bp->grp_info[i].fw_grp_id = INVALID_HW_RING_ID;
4270 }
4271 mutex_unlock(&bp->hwrm_cmd_lock);
4272 return rc;
4273}
4274
4275static int hwrm_ring_alloc_send_msg(struct bnxt *bp,
4276 struct bnxt_ring_struct *ring,
Michael Chan9899bb52018-03-31 13:54:16 -04004277 u32 ring_type, u32 map_index)
Michael Chanc0c050c2015-10-22 16:01:17 -04004278{
4279 int rc = 0, err = 0;
4280 struct hwrm_ring_alloc_input req = {0};
4281 struct hwrm_ring_alloc_output *resp = bp->hwrm_cmd_resp_addr;
Michael Chan9899bb52018-03-31 13:54:16 -04004282 struct bnxt_ring_grp_info *grp_info;
Michael Chanc0c050c2015-10-22 16:01:17 -04004283 u16 ring_id;
4284
4285 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_ALLOC, -1, -1);
4286
4287 req.enables = 0;
4288 if (ring->nr_pages > 1) {
4289 req.page_tbl_addr = cpu_to_le64(ring->pg_tbl_map);
4290 /* Page size is in log2 units */
4291 req.page_size = BNXT_PAGE_SHIFT;
4292 req.page_tbl_depth = 1;
4293 } else {
4294 req.page_tbl_addr = cpu_to_le64(ring->dma_arr[0]);
4295 }
4296 req.fbo = 0;
4297 /* Association of ring index with doorbell index and MSIX number */
4298 req.logical_id = cpu_to_le16(map_index);
4299
4300 switch (ring_type) {
4301 case HWRM_RING_ALLOC_TX:
4302 req.ring_type = RING_ALLOC_REQ_RING_TYPE_TX;
4303 /* Association of transmit ring with completion ring */
Michael Chan9899bb52018-03-31 13:54:16 -04004304 grp_info = &bp->grp_info[ring->grp_idx];
4305 req.cmpl_ring_id = cpu_to_le16(grp_info->cp_fw_ring_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04004306 req.length = cpu_to_le32(bp->tx_ring_mask + 1);
Michael Chan9899bb52018-03-31 13:54:16 -04004307 req.stat_ctx_id = cpu_to_le32(grp_info->fw_stats_ctx);
Michael Chanc0c050c2015-10-22 16:01:17 -04004308 req.queue_id = cpu_to_le16(ring->queue_id);
4309 break;
4310 case HWRM_RING_ALLOC_RX:
4311 req.ring_type = RING_ALLOC_REQ_RING_TYPE_RX;
4312 req.length = cpu_to_le32(bp->rx_ring_mask + 1);
4313 break;
4314 case HWRM_RING_ALLOC_AGG:
4315 req.ring_type = RING_ALLOC_REQ_RING_TYPE_RX;
4316 req.length = cpu_to_le32(bp->rx_agg_ring_mask + 1);
4317 break;
4318 case HWRM_RING_ALLOC_CMPL:
Michael Chanbac9a7e2017-02-12 19:18:10 -05004319 req.ring_type = RING_ALLOC_REQ_RING_TYPE_L2_CMPL;
Michael Chanc0c050c2015-10-22 16:01:17 -04004320 req.length = cpu_to_le32(bp->cp_ring_mask + 1);
4321 if (bp->flags & BNXT_FLAG_USING_MSIX)
4322 req.int_mode = RING_ALLOC_REQ_INT_MODE_MSIX;
4323 break;
4324 default:
4325 netdev_err(bp->dev, "hwrm alloc invalid ring type %d\n",
4326 ring_type);
4327 return -1;
4328 }
4329
4330 mutex_lock(&bp->hwrm_cmd_lock);
4331 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4332 err = le16_to_cpu(resp->error_code);
4333 ring_id = le16_to_cpu(resp->ring_id);
4334 mutex_unlock(&bp->hwrm_cmd_lock);
4335
4336 if (rc || err) {
4337 switch (ring_type) {
Michael Chanbac9a7e2017-02-12 19:18:10 -05004338 case RING_FREE_REQ_RING_TYPE_L2_CMPL:
Michael Chanc0c050c2015-10-22 16:01:17 -04004339 netdev_err(bp->dev, "hwrm_ring_alloc cp failed. rc:%x err:%x\n",
4340 rc, err);
4341 return -1;
4342
4343 case RING_FREE_REQ_RING_TYPE_RX:
4344 netdev_err(bp->dev, "hwrm_ring_alloc rx failed. rc:%x err:%x\n",
4345 rc, err);
4346 return -1;
4347
4348 case RING_FREE_REQ_RING_TYPE_TX:
4349 netdev_err(bp->dev, "hwrm_ring_alloc tx failed. rc:%x err:%x\n",
4350 rc, err);
4351 return -1;
4352
4353 default:
4354 netdev_err(bp->dev, "Invalid ring\n");
4355 return -1;
4356 }
4357 }
4358 ring->fw_ring_id = ring_id;
4359 return rc;
4360}
4361
Michael Chan486b5c22016-12-29 12:13:42 -05004362static int bnxt_hwrm_set_async_event_cr(struct bnxt *bp, int idx)
4363{
4364 int rc;
4365
4366 if (BNXT_PF(bp)) {
4367 struct hwrm_func_cfg_input req = {0};
4368
4369 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1);
4370 req.fid = cpu_to_le16(0xffff);
4371 req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_ASYNC_EVENT_CR);
4372 req.async_event_cr = cpu_to_le16(idx);
4373 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4374 } else {
4375 struct hwrm_func_vf_cfg_input req = {0};
4376
4377 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_VF_CFG, -1, -1);
4378 req.enables =
4379 cpu_to_le32(FUNC_VF_CFG_REQ_ENABLES_ASYNC_EVENT_CR);
4380 req.async_event_cr = cpu_to_le16(idx);
4381 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4382 }
4383 return rc;
4384}
4385
Michael Chanc0c050c2015-10-22 16:01:17 -04004386static int bnxt_hwrm_ring_alloc(struct bnxt *bp)
4387{
4388 int i, rc = 0;
4389
Michael Chanedd0c2c2015-12-27 18:19:19 -05004390 for (i = 0; i < bp->cp_nr_rings; i++) {
4391 struct bnxt_napi *bnapi = bp->bnapi[i];
4392 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
4393 struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
Michael Chan9899bb52018-03-31 13:54:16 -04004394 u32 map_idx = ring->map_idx;
Michael Chanc0c050c2015-10-22 16:01:17 -04004395
Michael Chan9899bb52018-03-31 13:54:16 -04004396 cpr->cp_doorbell = bp->bar1 + map_idx * 0x80;
4397 rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_CMPL,
4398 map_idx);
Michael Chanedd0c2c2015-12-27 18:19:19 -05004399 if (rc)
4400 goto err_out;
Michael Chanedd0c2c2015-12-27 18:19:19 -05004401 BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
4402 bp->grp_info[i].cp_fw_ring_id = ring->fw_ring_id;
Michael Chan486b5c22016-12-29 12:13:42 -05004403
4404 if (!i) {
4405 rc = bnxt_hwrm_set_async_event_cr(bp, ring->fw_ring_id);
4406 if (rc)
4407 netdev_warn(bp->dev, "Failed to set async event completion ring.\n");
4408 }
Michael Chanc0c050c2015-10-22 16:01:17 -04004409 }
4410
Michael Chanedd0c2c2015-12-27 18:19:19 -05004411 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05004412 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
Michael Chanedd0c2c2015-12-27 18:19:19 -05004413 struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
Michael Chan9899bb52018-03-31 13:54:16 -04004414 u32 map_idx = i;
Michael Chanc0c050c2015-10-22 16:01:17 -04004415
Michael Chanb81a90d2016-01-02 23:45:01 -05004416 rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_TX,
Michael Chan9899bb52018-03-31 13:54:16 -04004417 map_idx);
Michael Chanedd0c2c2015-12-27 18:19:19 -05004418 if (rc)
4419 goto err_out;
Michael Chanb81a90d2016-01-02 23:45:01 -05004420 txr->tx_doorbell = bp->bar1 + map_idx * 0x80;
Michael Chanc0c050c2015-10-22 16:01:17 -04004421 }
4422
Michael Chanedd0c2c2015-12-27 18:19:19 -05004423 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05004424 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
Michael Chanedd0c2c2015-12-27 18:19:19 -05004425 struct bnxt_ring_struct *ring = &rxr->rx_ring_struct;
Michael Chanb81a90d2016-01-02 23:45:01 -05004426 u32 map_idx = rxr->bnapi->index;
Michael Chanc0c050c2015-10-22 16:01:17 -04004427
Michael Chanb81a90d2016-01-02 23:45:01 -05004428 rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_RX,
Michael Chan9899bb52018-03-31 13:54:16 -04004429 map_idx);
Michael Chanedd0c2c2015-12-27 18:19:19 -05004430 if (rc)
4431 goto err_out;
Michael Chanb81a90d2016-01-02 23:45:01 -05004432 rxr->rx_doorbell = bp->bar1 + map_idx * 0x80;
Michael Chanedd0c2c2015-12-27 18:19:19 -05004433 writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell);
Michael Chanb81a90d2016-01-02 23:45:01 -05004434 bp->grp_info[map_idx].rx_fw_ring_id = ring->fw_ring_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04004435 }
4436
4437 if (bp->flags & BNXT_FLAG_AGG_RINGS) {
4438 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05004439 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04004440 struct bnxt_ring_struct *ring =
4441 &rxr->rx_agg_ring_struct;
Michael Chan9899bb52018-03-31 13:54:16 -04004442 u32 grp_idx = ring->grp_idx;
Michael Chanb81a90d2016-01-02 23:45:01 -05004443 u32 map_idx = grp_idx + bp->rx_nr_rings;
Michael Chanc0c050c2015-10-22 16:01:17 -04004444
4445 rc = hwrm_ring_alloc_send_msg(bp, ring,
4446 HWRM_RING_ALLOC_AGG,
Michael Chan9899bb52018-03-31 13:54:16 -04004447 map_idx);
Michael Chanc0c050c2015-10-22 16:01:17 -04004448 if (rc)
4449 goto err_out;
4450
Michael Chanb81a90d2016-01-02 23:45:01 -05004451 rxr->rx_agg_doorbell = bp->bar1 + map_idx * 0x80;
Michael Chanc0c050c2015-10-22 16:01:17 -04004452 writel(DB_KEY_RX | rxr->rx_agg_prod,
4453 rxr->rx_agg_doorbell);
Michael Chanb81a90d2016-01-02 23:45:01 -05004454 bp->grp_info[grp_idx].agg_fw_ring_id = ring->fw_ring_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04004455 }
4456 }
4457err_out:
4458 return rc;
4459}
4460
4461static int hwrm_ring_free_send_msg(struct bnxt *bp,
4462 struct bnxt_ring_struct *ring,
4463 u32 ring_type, int cmpl_ring_id)
4464{
4465 int rc;
4466 struct hwrm_ring_free_input req = {0};
4467 struct hwrm_ring_free_output *resp = bp->hwrm_cmd_resp_addr;
4468 u16 error_code;
4469
Prashant Sreedharan74608fc2016-01-28 03:11:20 -05004470 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_FREE, cmpl_ring_id, -1);
Michael Chanc0c050c2015-10-22 16:01:17 -04004471 req.ring_type = ring_type;
4472 req.ring_id = cpu_to_le16(ring->fw_ring_id);
4473
4474 mutex_lock(&bp->hwrm_cmd_lock);
4475 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4476 error_code = le16_to_cpu(resp->error_code);
4477 mutex_unlock(&bp->hwrm_cmd_lock);
4478
4479 if (rc || error_code) {
4480 switch (ring_type) {
Michael Chanbac9a7e2017-02-12 19:18:10 -05004481 case RING_FREE_REQ_RING_TYPE_L2_CMPL:
Michael Chanc0c050c2015-10-22 16:01:17 -04004482 netdev_err(bp->dev, "hwrm_ring_free cp failed. rc:%d\n",
4483 rc);
4484 return rc;
4485 case RING_FREE_REQ_RING_TYPE_RX:
4486 netdev_err(bp->dev, "hwrm_ring_free rx failed. rc:%d\n",
4487 rc);
4488 return rc;
4489 case RING_FREE_REQ_RING_TYPE_TX:
4490 netdev_err(bp->dev, "hwrm_ring_free tx failed. rc:%d\n",
4491 rc);
4492 return rc;
4493 default:
4494 netdev_err(bp->dev, "Invalid ring\n");
4495 return -1;
4496 }
4497 }
4498 return 0;
4499}
4500
Michael Chanedd0c2c2015-12-27 18:19:19 -05004501static void bnxt_hwrm_ring_free(struct bnxt *bp, bool close_path)
Michael Chanc0c050c2015-10-22 16:01:17 -04004502{
Michael Chanedd0c2c2015-12-27 18:19:19 -05004503 int i;
Michael Chanc0c050c2015-10-22 16:01:17 -04004504
4505 if (!bp->bnapi)
Michael Chanedd0c2c2015-12-27 18:19:19 -05004506 return;
Michael Chanc0c050c2015-10-22 16:01:17 -04004507
Michael Chanedd0c2c2015-12-27 18:19:19 -05004508 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05004509 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
Michael Chanedd0c2c2015-12-27 18:19:19 -05004510 struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
Michael Chanb81a90d2016-01-02 23:45:01 -05004511 u32 grp_idx = txr->bnapi->index;
4512 u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04004513
Michael Chanedd0c2c2015-12-27 18:19:19 -05004514 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
4515 hwrm_ring_free_send_msg(bp, ring,
4516 RING_FREE_REQ_RING_TYPE_TX,
4517 close_path ? cmpl_ring_id :
4518 INVALID_HW_RING_ID);
4519 ring->fw_ring_id = INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04004520 }
4521 }
4522
Michael Chanedd0c2c2015-12-27 18:19:19 -05004523 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05004524 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
Michael Chanedd0c2c2015-12-27 18:19:19 -05004525 struct bnxt_ring_struct *ring = &rxr->rx_ring_struct;
Michael Chanb81a90d2016-01-02 23:45:01 -05004526 u32 grp_idx = rxr->bnapi->index;
4527 u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04004528
Michael Chanedd0c2c2015-12-27 18:19:19 -05004529 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
4530 hwrm_ring_free_send_msg(bp, ring,
4531 RING_FREE_REQ_RING_TYPE_RX,
4532 close_path ? cmpl_ring_id :
4533 INVALID_HW_RING_ID);
4534 ring->fw_ring_id = INVALID_HW_RING_ID;
Michael Chanb81a90d2016-01-02 23:45:01 -05004535 bp->grp_info[grp_idx].rx_fw_ring_id =
4536 INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04004537 }
4538 }
4539
Michael Chanedd0c2c2015-12-27 18:19:19 -05004540 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05004541 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
Michael Chanedd0c2c2015-12-27 18:19:19 -05004542 struct bnxt_ring_struct *ring = &rxr->rx_agg_ring_struct;
Michael Chanb81a90d2016-01-02 23:45:01 -05004543 u32 grp_idx = rxr->bnapi->index;
4544 u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04004545
Michael Chanedd0c2c2015-12-27 18:19:19 -05004546 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
4547 hwrm_ring_free_send_msg(bp, ring,
4548 RING_FREE_REQ_RING_TYPE_RX,
4549 close_path ? cmpl_ring_id :
4550 INVALID_HW_RING_ID);
4551 ring->fw_ring_id = INVALID_HW_RING_ID;
Michael Chanb81a90d2016-01-02 23:45:01 -05004552 bp->grp_info[grp_idx].agg_fw_ring_id =
4553 INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04004554 }
4555 }
4556
Michael Chan9d8bc092016-12-29 12:13:33 -05004557 /* The completion rings are about to be freed. After that the
4558 * IRQ doorbell will not work anymore. So we need to disable
4559 * IRQ here.
4560 */
4561 bnxt_disable_int_sync(bp);
4562
Michael Chanedd0c2c2015-12-27 18:19:19 -05004563 for (i = 0; i < bp->cp_nr_rings; i++) {
4564 struct bnxt_napi *bnapi = bp->bnapi[i];
4565 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
4566 struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
Michael Chanc0c050c2015-10-22 16:01:17 -04004567
Michael Chanedd0c2c2015-12-27 18:19:19 -05004568 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
4569 hwrm_ring_free_send_msg(bp, ring,
Michael Chanbac9a7e2017-02-12 19:18:10 -05004570 RING_FREE_REQ_RING_TYPE_L2_CMPL,
Michael Chanedd0c2c2015-12-27 18:19:19 -05004571 INVALID_HW_RING_ID);
4572 ring->fw_ring_id = INVALID_HW_RING_ID;
4573 bp->grp_info[i].cp_fw_ring_id = INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04004574 }
4575 }
Michael Chanc0c050c2015-10-22 16:01:17 -04004576}
4577
Michael Chan674f50a2018-01-17 03:21:09 -05004578static int bnxt_hwrm_get_rings(struct bnxt *bp)
4579{
4580 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
4581 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
4582 struct hwrm_func_qcfg_input req = {0};
4583 int rc;
4584
4585 if (bp->hwrm_spec_code < 0x10601)
4586 return 0;
4587
4588 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCFG, -1, -1);
4589 req.fid = cpu_to_le16(0xffff);
4590 mutex_lock(&bp->hwrm_cmd_lock);
4591 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4592 if (rc) {
4593 mutex_unlock(&bp->hwrm_cmd_lock);
4594 return -EIO;
4595 }
4596
4597 hw_resc->resv_tx_rings = le16_to_cpu(resp->alloc_tx_rings);
4598 if (bp->flags & BNXT_FLAG_NEW_RM) {
4599 u16 cp, stats;
4600
4601 hw_resc->resv_rx_rings = le16_to_cpu(resp->alloc_rx_rings);
4602 hw_resc->resv_hw_ring_grps =
4603 le32_to_cpu(resp->alloc_hw_ring_grps);
4604 hw_resc->resv_vnics = le16_to_cpu(resp->alloc_vnics);
4605 cp = le16_to_cpu(resp->alloc_cmpl_rings);
4606 stats = le16_to_cpu(resp->alloc_stat_ctx);
4607 cp = min_t(u16, cp, stats);
4608 hw_resc->resv_cp_rings = cp;
4609 }
4610 mutex_unlock(&bp->hwrm_cmd_lock);
4611 return 0;
4612}
4613
Michael Chan391be5c2016-12-29 12:13:41 -05004614/* Caller must hold bp->hwrm_cmd_lock */
4615int __bnxt_hwrm_get_tx_rings(struct bnxt *bp, u16 fid, int *tx_rings)
4616{
4617 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
4618 struct hwrm_func_qcfg_input req = {0};
4619 int rc;
4620
4621 if (bp->hwrm_spec_code < 0x10601)
4622 return 0;
4623
4624 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCFG, -1, -1);
4625 req.fid = cpu_to_le16(fid);
4626 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4627 if (!rc)
4628 *tx_rings = le16_to_cpu(resp->alloc_tx_rings);
4629
4630 return rc;
4631}
4632
Michael Chan4ed50ef2018-03-09 23:46:03 -05004633static void
4634__bnxt_hwrm_reserve_pf_rings(struct bnxt *bp, struct hwrm_func_cfg_input *req,
4635 int tx_rings, int rx_rings, int ring_grps,
4636 int cp_rings, int vnics)
Michael Chan391be5c2016-12-29 12:13:41 -05004637{
Michael Chan674f50a2018-01-17 03:21:09 -05004638 u32 enables = 0;
Michael Chan391be5c2016-12-29 12:13:41 -05004639
Michael Chan4ed50ef2018-03-09 23:46:03 -05004640 bnxt_hwrm_cmd_hdr_init(bp, req, HWRM_FUNC_CFG, -1, -1);
4641 req->fid = cpu_to_le16(0xffff);
Michael Chan674f50a2018-01-17 03:21:09 -05004642 enables |= tx_rings ? FUNC_CFG_REQ_ENABLES_NUM_TX_RINGS : 0;
Michael Chan4ed50ef2018-03-09 23:46:03 -05004643 req->num_tx_rings = cpu_to_le16(tx_rings);
Michael Chan674f50a2018-01-17 03:21:09 -05004644 if (bp->flags & BNXT_FLAG_NEW_RM) {
4645 enables |= rx_rings ? FUNC_CFG_REQ_ENABLES_NUM_RX_RINGS : 0;
4646 enables |= cp_rings ? FUNC_CFG_REQ_ENABLES_NUM_CMPL_RINGS |
4647 FUNC_CFG_REQ_ENABLES_NUM_STAT_CTXS : 0;
4648 enables |= ring_grps ?
4649 FUNC_CFG_REQ_ENABLES_NUM_HW_RING_GRPS : 0;
4650 enables |= vnics ? FUNC_VF_CFG_REQ_ENABLES_NUM_VNICS : 0;
4651
Michael Chan4ed50ef2018-03-09 23:46:03 -05004652 req->num_rx_rings = cpu_to_le16(rx_rings);
4653 req->num_hw_ring_grps = cpu_to_le16(ring_grps);
4654 req->num_cmpl_rings = cpu_to_le16(cp_rings);
4655 req->num_stat_ctxs = req->num_cmpl_rings;
4656 req->num_vnics = cpu_to_le16(vnics);
Michael Chan674f50a2018-01-17 03:21:09 -05004657 }
Michael Chan4ed50ef2018-03-09 23:46:03 -05004658 req->enables = cpu_to_le32(enables);
4659}
4660
4661static void
4662__bnxt_hwrm_reserve_vf_rings(struct bnxt *bp,
4663 struct hwrm_func_vf_cfg_input *req, int tx_rings,
4664 int rx_rings, int ring_grps, int cp_rings,
4665 int vnics)
4666{
4667 u32 enables = 0;
4668
4669 bnxt_hwrm_cmd_hdr_init(bp, req, HWRM_FUNC_VF_CFG, -1, -1);
4670 enables |= tx_rings ? FUNC_VF_CFG_REQ_ENABLES_NUM_TX_RINGS : 0;
4671 enables |= rx_rings ? FUNC_VF_CFG_REQ_ENABLES_NUM_RX_RINGS : 0;
4672 enables |= cp_rings ? FUNC_VF_CFG_REQ_ENABLES_NUM_CMPL_RINGS |
4673 FUNC_VF_CFG_REQ_ENABLES_NUM_STAT_CTXS : 0;
4674 enables |= ring_grps ? FUNC_VF_CFG_REQ_ENABLES_NUM_HW_RING_GRPS : 0;
4675 enables |= vnics ? FUNC_VF_CFG_REQ_ENABLES_NUM_VNICS : 0;
4676
4677 req->num_tx_rings = cpu_to_le16(tx_rings);
4678 req->num_rx_rings = cpu_to_le16(rx_rings);
4679 req->num_hw_ring_grps = cpu_to_le16(ring_grps);
4680 req->num_cmpl_rings = cpu_to_le16(cp_rings);
4681 req->num_stat_ctxs = req->num_cmpl_rings;
4682 req->num_vnics = cpu_to_le16(vnics);
4683
4684 req->enables = cpu_to_le32(enables);
4685}
4686
4687static int
4688bnxt_hwrm_reserve_pf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
4689 int ring_grps, int cp_rings, int vnics)
4690{
4691 struct hwrm_func_cfg_input req = {0};
4692 int rc;
4693
4694 __bnxt_hwrm_reserve_pf_rings(bp, &req, tx_rings, rx_rings, ring_grps,
4695 cp_rings, vnics);
4696 if (!req.enables)
Michael Chan674f50a2018-01-17 03:21:09 -05004697 return 0;
4698
Michael Chan674f50a2018-01-17 03:21:09 -05004699 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4700 if (rc)
4701 return -ENOMEM;
4702
4703 if (bp->hwrm_spec_code < 0x10601)
4704 bp->hw_resc.resv_tx_rings = tx_rings;
4705
4706 rc = bnxt_hwrm_get_rings(bp);
4707 return rc;
4708}
4709
4710static int
4711bnxt_hwrm_reserve_vf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
4712 int ring_grps, int cp_rings, int vnics)
4713{
4714 struct hwrm_func_vf_cfg_input req = {0};
Michael Chan674f50a2018-01-17 03:21:09 -05004715 int rc;
4716
4717 if (!(bp->flags & BNXT_FLAG_NEW_RM)) {
4718 bp->hw_resc.resv_tx_rings = tx_rings;
4719 return 0;
4720 }
4721
Michael Chan4ed50ef2018-03-09 23:46:03 -05004722 __bnxt_hwrm_reserve_vf_rings(bp, &req, tx_rings, rx_rings, ring_grps,
4723 cp_rings, vnics);
Michael Chan674f50a2018-01-17 03:21:09 -05004724 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4725 if (rc)
4726 return -ENOMEM;
4727
4728 rc = bnxt_hwrm_get_rings(bp);
4729 return rc;
4730}
4731
4732static int bnxt_hwrm_reserve_rings(struct bnxt *bp, int tx, int rx, int grp,
4733 int cp, int vnic)
4734{
4735 if (BNXT_PF(bp))
4736 return bnxt_hwrm_reserve_pf_rings(bp, tx, rx, grp, cp, vnic);
4737 else
4738 return bnxt_hwrm_reserve_vf_rings(bp, tx, rx, grp, cp, vnic);
4739}
4740
Michael Chan08654eb2018-03-31 13:54:17 -04004741static int bnxt_cp_rings_in_use(struct bnxt *bp)
4742{
4743 int cp = bp->cp_nr_rings;
4744 int ulp_msix, ulp_base;
4745
4746 ulp_msix = bnxt_get_ulp_msix_num(bp);
4747 if (ulp_msix) {
4748 ulp_base = bnxt_get_ulp_msix_base(bp);
4749 cp += ulp_msix;
4750 if ((ulp_base + ulp_msix) > cp)
4751 cp = ulp_base + ulp_msix;
4752 }
4753 return cp;
4754}
4755
Michael Chan4e41dc52018-03-31 13:54:19 -04004756static bool bnxt_need_reserve_rings(struct bnxt *bp)
4757{
4758 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
Michael Chanfbcfc8e2018-03-31 13:54:20 -04004759 int cp = bnxt_cp_rings_in_use(bp);
Michael Chan4e41dc52018-03-31 13:54:19 -04004760 int rx = bp->rx_nr_rings;
4761 int vnic = 1, grp = rx;
4762
4763 if (bp->hwrm_spec_code < 0x10601)
4764 return false;
4765
4766 if (hw_resc->resv_tx_rings != bp->tx_nr_rings)
4767 return true;
4768
4769 if (bp->flags & BNXT_FLAG_RFS)
4770 vnic = rx + 1;
4771 if (bp->flags & BNXT_FLAG_AGG_RINGS)
4772 rx <<= 1;
4773 if ((bp->flags & BNXT_FLAG_NEW_RM) &&
4774 (hw_resc->resv_rx_rings != rx || hw_resc->resv_cp_rings != cp ||
4775 hw_resc->resv_hw_ring_grps != grp || hw_resc->resv_vnics != vnic))
4776 return true;
4777 return false;
4778}
4779
Michael Chan674f50a2018-01-17 03:21:09 -05004780static int bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max,
4781 bool shared);
4782
4783static int __bnxt_reserve_rings(struct bnxt *bp)
4784{
4785 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
Michael Chanfbcfc8e2018-03-31 13:54:20 -04004786 int cp = bnxt_cp_rings_in_use(bp);
Michael Chan674f50a2018-01-17 03:21:09 -05004787 int tx = bp->tx_nr_rings;
4788 int rx = bp->rx_nr_rings;
Michael Chan674f50a2018-01-17 03:21:09 -05004789 int grp, rx_rings, rc;
4790 bool sh = false;
4791 int vnic = 1;
4792
Michael Chan4e41dc52018-03-31 13:54:19 -04004793 if (!bnxt_need_reserve_rings(bp))
Michael Chan391be5c2016-12-29 12:13:41 -05004794 return 0;
4795
Michael Chan674f50a2018-01-17 03:21:09 -05004796 if (bp->flags & BNXT_FLAG_SHARED_RINGS)
4797 sh = true;
4798 if (bp->flags & BNXT_FLAG_RFS)
4799 vnic = rx + 1;
4800 if (bp->flags & BNXT_FLAG_AGG_RINGS)
4801 rx <<= 1;
Michael Chan674f50a2018-01-17 03:21:09 -05004802 grp = bp->rx_nr_rings;
Michael Chan391be5c2016-12-29 12:13:41 -05004803
Michael Chan674f50a2018-01-17 03:21:09 -05004804 rc = bnxt_hwrm_reserve_rings(bp, tx, rx, grp, cp, vnic);
Michael Chan391be5c2016-12-29 12:13:41 -05004805 if (rc)
4806 return rc;
4807
Michael Chan674f50a2018-01-17 03:21:09 -05004808 tx = hw_resc->resv_tx_rings;
4809 if (bp->flags & BNXT_FLAG_NEW_RM) {
4810 rx = hw_resc->resv_rx_rings;
4811 cp = hw_resc->resv_cp_rings;
4812 grp = hw_resc->resv_hw_ring_grps;
4813 vnic = hw_resc->resv_vnics;
4814 }
4815
4816 rx_rings = rx;
4817 if (bp->flags & BNXT_FLAG_AGG_RINGS) {
4818 if (rx >= 2) {
4819 rx_rings = rx >> 1;
4820 } else {
4821 if (netif_running(bp->dev))
4822 return -ENOMEM;
4823
4824 bp->flags &= ~BNXT_FLAG_AGG_RINGS;
4825 bp->flags |= BNXT_FLAG_NO_AGG_RINGS;
4826 bp->dev->hw_features &= ~NETIF_F_LRO;
4827 bp->dev->features &= ~NETIF_F_LRO;
4828 bnxt_set_ring_params(bp);
4829 }
4830 }
4831 rx_rings = min_t(int, rx_rings, grp);
4832 rc = bnxt_trim_rings(bp, &rx_rings, &tx, cp, sh);
4833 if (bp->flags & BNXT_FLAG_AGG_RINGS)
4834 rx = rx_rings << 1;
4835 cp = sh ? max_t(int, tx, rx_rings) : tx + rx_rings;
4836 bp->tx_nr_rings = tx;
4837 bp->rx_nr_rings = rx_rings;
4838 bp->cp_nr_rings = cp;
4839
4840 if (!tx || !rx || !cp || !grp || !vnic)
4841 return -ENOMEM;
4842
Michael Chan391be5c2016-12-29 12:13:41 -05004843 return rc;
4844}
4845
Michael Chan8f23d632018-01-17 03:21:12 -05004846static int bnxt_hwrm_check_vf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004847 int ring_grps, int cp_rings, int vnics)
Michael Chan98fdbe72017-08-28 13:40:26 -04004848{
Michael Chan8f23d632018-01-17 03:21:12 -05004849 struct hwrm_func_vf_cfg_input req = {0};
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004850 u32 flags;
Michael Chan98fdbe72017-08-28 13:40:26 -04004851 int rc;
4852
Michael Chan8f23d632018-01-17 03:21:12 -05004853 if (!(bp->flags & BNXT_FLAG_NEW_RM))
Michael Chan98fdbe72017-08-28 13:40:26 -04004854 return 0;
4855
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004856 __bnxt_hwrm_reserve_vf_rings(bp, &req, tx_rings, rx_rings, ring_grps,
4857 cp_rings, vnics);
Michael Chan8f23d632018-01-17 03:21:12 -05004858 flags = FUNC_VF_CFG_REQ_FLAGS_TX_ASSETS_TEST |
4859 FUNC_VF_CFG_REQ_FLAGS_RX_ASSETS_TEST |
4860 FUNC_VF_CFG_REQ_FLAGS_CMPL_ASSETS_TEST |
4861 FUNC_VF_CFG_REQ_FLAGS_RING_GRP_ASSETS_TEST |
4862 FUNC_VF_CFG_REQ_FLAGS_STAT_CTX_ASSETS_TEST |
4863 FUNC_VF_CFG_REQ_FLAGS_VNIC_ASSETS_TEST;
Michael Chan98fdbe72017-08-28 13:40:26 -04004864
Michael Chan8f23d632018-01-17 03:21:12 -05004865 req.flags = cpu_to_le32(flags);
Michael Chan98fdbe72017-08-28 13:40:26 -04004866 rc = hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4867 if (rc)
4868 return -ENOMEM;
4869 return 0;
4870}
4871
Michael Chan8f23d632018-01-17 03:21:12 -05004872static int bnxt_hwrm_check_pf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004873 int ring_grps, int cp_rings, int vnics)
Michael Chan8f23d632018-01-17 03:21:12 -05004874{
4875 struct hwrm_func_cfg_input req = {0};
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004876 u32 flags;
Michael Chan8f23d632018-01-17 03:21:12 -05004877 int rc;
4878
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004879 __bnxt_hwrm_reserve_pf_rings(bp, &req, tx_rings, rx_rings, ring_grps,
4880 cp_rings, vnics);
Michael Chan8f23d632018-01-17 03:21:12 -05004881 flags = FUNC_CFG_REQ_FLAGS_TX_ASSETS_TEST;
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004882 if (bp->flags & BNXT_FLAG_NEW_RM)
Michael Chan8f23d632018-01-17 03:21:12 -05004883 flags |= FUNC_CFG_REQ_FLAGS_RX_ASSETS_TEST |
4884 FUNC_CFG_REQ_FLAGS_CMPL_ASSETS_TEST |
4885 FUNC_CFG_REQ_FLAGS_RING_GRP_ASSETS_TEST |
4886 FUNC_CFG_REQ_FLAGS_STAT_CTX_ASSETS_TEST |
4887 FUNC_CFG_REQ_FLAGS_VNIC_ASSETS_TEST;
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004888
Michael Chan8f23d632018-01-17 03:21:12 -05004889 req.flags = cpu_to_le32(flags);
Michael Chan8f23d632018-01-17 03:21:12 -05004890 rc = hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4891 if (rc)
4892 return -ENOMEM;
4893 return 0;
4894}
4895
4896static int bnxt_hwrm_check_rings(struct bnxt *bp, int tx_rings, int rx_rings,
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004897 int ring_grps, int cp_rings, int vnics)
Michael Chan8f23d632018-01-17 03:21:12 -05004898{
4899 if (bp->hwrm_spec_code < 0x10801)
4900 return 0;
4901
4902 if (BNXT_PF(bp))
4903 return bnxt_hwrm_check_pf_rings(bp, tx_rings, rx_rings,
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004904 ring_grps, cp_rings, vnics);
Michael Chan8f23d632018-01-17 03:21:12 -05004905
4906 return bnxt_hwrm_check_vf_rings(bp, tx_rings, rx_rings, ring_grps,
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004907 cp_rings, vnics);
Michael Chan8f23d632018-01-17 03:21:12 -05004908}
4909
Michael Chanf8503962017-10-26 11:51:28 -04004910static void bnxt_hwrm_set_coal_params(struct bnxt_coal *hw_coal,
Michael Chanbb053f52016-02-26 04:00:02 -05004911 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *req)
4912{
Michael Chanf8503962017-10-26 11:51:28 -04004913 u16 val, tmr, max, flags;
4914
4915 max = hw_coal->bufs_per_record * 128;
4916 if (hw_coal->budget)
4917 max = hw_coal->bufs_per_record * hw_coal->budget;
4918
4919 val = clamp_t(u16, hw_coal->coal_bufs, 1, max);
4920 req->num_cmpl_aggr_int = cpu_to_le16(val);
Michael Chanb153cbc2017-11-03 03:32:39 -04004921
4922 /* This is a 6-bit value and must not be 0, or we'll get non stop IRQ */
4923 val = min_t(u16, val, 63);
Michael Chanf8503962017-10-26 11:51:28 -04004924 req->num_cmpl_dma_aggr = cpu_to_le16(val);
4925
Michael Chanb153cbc2017-11-03 03:32:39 -04004926 /* This is a 6-bit value and must not be 0, or we'll get non stop IRQ */
4927 val = clamp_t(u16, hw_coal->coal_bufs_irq, 1, 63);
Michael Chanf8503962017-10-26 11:51:28 -04004928 req->num_cmpl_dma_aggr_during_int = cpu_to_le16(val);
4929
4930 tmr = BNXT_USEC_TO_COAL_TIMER(hw_coal->coal_ticks);
4931 tmr = max_t(u16, tmr, 1);
4932 req->int_lat_tmr_max = cpu_to_le16(tmr);
4933
4934 /* min timer set to 1/2 of interrupt timer */
4935 val = tmr / 2;
4936 req->int_lat_tmr_min = cpu_to_le16(val);
4937
4938 /* buf timer set to 1/4 of interrupt timer */
4939 val = max_t(u16, tmr / 4, 1);
4940 req->cmpl_aggr_dma_tmr = cpu_to_le16(val);
4941
4942 tmr = BNXT_USEC_TO_COAL_TIMER(hw_coal->coal_ticks_irq);
4943 tmr = max_t(u16, tmr, 1);
4944 req->cmpl_aggr_dma_tmr_during_int = cpu_to_le16(tmr);
4945
4946 flags = RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_TIMER_RESET;
4947 if (hw_coal->idle_thresh && hw_coal->coal_ticks < hw_coal->idle_thresh)
4948 flags |= RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_RING_IDLE;
Michael Chanbb053f52016-02-26 04:00:02 -05004949 req->flags = cpu_to_le16(flags);
Michael Chanbb053f52016-02-26 04:00:02 -05004950}
4951
Andy Gospodarek6a8788f2018-01-09 16:06:20 -05004952int bnxt_hwrm_set_ring_coal(struct bnxt *bp, struct bnxt_napi *bnapi)
4953{
4954 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req_rx = {0};
4955 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
4956 struct bnxt_coal coal;
4957 unsigned int grp_idx;
4958
4959 /* Tick values in micro seconds.
4960 * 1 coal_buf x bufs_per_record = 1 completion record.
4961 */
4962 memcpy(&coal, &bp->rx_coal, sizeof(struct bnxt_coal));
4963
4964 coal.coal_ticks = cpr->rx_ring_coal.coal_ticks;
4965 coal.coal_bufs = cpr->rx_ring_coal.coal_bufs;
4966
4967 if (!bnapi->rx_ring)
4968 return -ENODEV;
4969
4970 bnxt_hwrm_cmd_hdr_init(bp, &req_rx,
4971 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1);
4972
4973 bnxt_hwrm_set_coal_params(&coal, &req_rx);
4974
4975 grp_idx = bnapi->index;
4976 req_rx.ring_id = cpu_to_le16(bp->grp_info[grp_idx].cp_fw_ring_id);
4977
4978 return hwrm_send_message(bp, &req_rx, sizeof(req_rx),
4979 HWRM_CMD_TIMEOUT);
4980}
4981
Michael Chanc0c050c2015-10-22 16:01:17 -04004982int bnxt_hwrm_set_coal(struct bnxt *bp)
4983{
4984 int i, rc = 0;
Michael Chandfc9c942016-02-26 04:00:03 -05004985 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req_rx = {0},
4986 req_tx = {0}, *req;
Michael Chanc0c050c2015-10-22 16:01:17 -04004987
Michael Chandfc9c942016-02-26 04:00:03 -05004988 bnxt_hwrm_cmd_hdr_init(bp, &req_rx,
4989 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1);
4990 bnxt_hwrm_cmd_hdr_init(bp, &req_tx,
4991 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1);
Michael Chanc0c050c2015-10-22 16:01:17 -04004992
Michael Chanf8503962017-10-26 11:51:28 -04004993 bnxt_hwrm_set_coal_params(&bp->rx_coal, &req_rx);
4994 bnxt_hwrm_set_coal_params(&bp->tx_coal, &req_tx);
Michael Chanc0c050c2015-10-22 16:01:17 -04004995
4996 mutex_lock(&bp->hwrm_cmd_lock);
4997 for (i = 0; i < bp->cp_nr_rings; i++) {
Michael Chandfc9c942016-02-26 04:00:03 -05004998 struct bnxt_napi *bnapi = bp->bnapi[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04004999
Michael Chandfc9c942016-02-26 04:00:03 -05005000 req = &req_rx;
5001 if (!bnapi->rx_ring)
5002 req = &req_tx;
5003 req->ring_id = cpu_to_le16(bp->grp_info[i].cp_fw_ring_id);
5004
5005 rc = _hwrm_send_message(bp, req, sizeof(*req),
Michael Chanc0c050c2015-10-22 16:01:17 -04005006 HWRM_CMD_TIMEOUT);
5007 if (rc)
5008 break;
5009 }
5010 mutex_unlock(&bp->hwrm_cmd_lock);
5011 return rc;
5012}
5013
5014static int bnxt_hwrm_stat_ctx_free(struct bnxt *bp)
5015{
5016 int rc = 0, i;
5017 struct hwrm_stat_ctx_free_input req = {0};
5018
5019 if (!bp->bnapi)
5020 return 0;
5021
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04005022 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
5023 return 0;
5024
Michael Chanc0c050c2015-10-22 16:01:17 -04005025 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_STAT_CTX_FREE, -1, -1);
5026
5027 mutex_lock(&bp->hwrm_cmd_lock);
5028 for (i = 0; i < bp->cp_nr_rings; i++) {
5029 struct bnxt_napi *bnapi = bp->bnapi[i];
5030 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
5031
5032 if (cpr->hw_stats_ctx_id != INVALID_STATS_CTX_ID) {
5033 req.stat_ctx_id = cpu_to_le32(cpr->hw_stats_ctx_id);
5034
5035 rc = _hwrm_send_message(bp, &req, sizeof(req),
5036 HWRM_CMD_TIMEOUT);
5037 if (rc)
5038 break;
5039
5040 cpr->hw_stats_ctx_id = INVALID_STATS_CTX_ID;
5041 }
5042 }
5043 mutex_unlock(&bp->hwrm_cmd_lock);
5044 return rc;
5045}
5046
5047static int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp)
5048{
5049 int rc = 0, i;
5050 struct hwrm_stat_ctx_alloc_input req = {0};
5051 struct hwrm_stat_ctx_alloc_output *resp = bp->hwrm_cmd_resp_addr;
5052
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04005053 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
5054 return 0;
5055
Michael Chanc0c050c2015-10-22 16:01:17 -04005056 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_STAT_CTX_ALLOC, -1, -1);
5057
Michael Chan51f30782016-07-01 18:46:29 -04005058 req.update_period_ms = cpu_to_le32(bp->stats_coal_ticks / 1000);
Michael Chanc0c050c2015-10-22 16:01:17 -04005059
5060 mutex_lock(&bp->hwrm_cmd_lock);
5061 for (i = 0; i < bp->cp_nr_rings; i++) {
5062 struct bnxt_napi *bnapi = bp->bnapi[i];
5063 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
5064
5065 req.stats_dma_addr = cpu_to_le64(cpr->hw_stats_map);
5066
5067 rc = _hwrm_send_message(bp, &req, sizeof(req),
5068 HWRM_CMD_TIMEOUT);
5069 if (rc)
5070 break;
5071
5072 cpr->hw_stats_ctx_id = le32_to_cpu(resp->stat_ctx_id);
5073
5074 bp->grp_info[i].fw_stats_ctx = cpr->hw_stats_ctx_id;
5075 }
5076 mutex_unlock(&bp->hwrm_cmd_lock);
Pan Bian89aa8442016-12-03 17:56:17 +08005077 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04005078}
5079
Michael Chancf6645f2016-06-13 02:25:28 -04005080static int bnxt_hwrm_func_qcfg(struct bnxt *bp)
5081{
5082 struct hwrm_func_qcfg_input req = {0};
Satish Baddipadige567b2ab2016-06-13 02:25:31 -04005083 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
Michael Chan9315edc2017-07-24 12:34:25 -04005084 u16 flags;
Michael Chancf6645f2016-06-13 02:25:28 -04005085 int rc;
5086
5087 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCFG, -1, -1);
5088 req.fid = cpu_to_le16(0xffff);
5089 mutex_lock(&bp->hwrm_cmd_lock);
5090 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5091 if (rc)
5092 goto func_qcfg_exit;
5093
5094#ifdef CONFIG_BNXT_SRIOV
5095 if (BNXT_VF(bp)) {
Michael Chancf6645f2016-06-13 02:25:28 -04005096 struct bnxt_vf_info *vf = &bp->vf;
5097
5098 vf->vlan = le16_to_cpu(resp->vlan) & VLAN_VID_MASK;
5099 }
5100#endif
Michael Chan9315edc2017-07-24 12:34:25 -04005101 flags = le16_to_cpu(resp->flags);
5102 if (flags & (FUNC_QCFG_RESP_FLAGS_FW_DCBX_AGENT_ENABLED |
5103 FUNC_QCFG_RESP_FLAGS_FW_LLDP_AGENT_ENABLED)) {
5104 bp->flags |= BNXT_FLAG_FW_LLDP_AGENT;
5105 if (flags & FUNC_QCFG_RESP_FLAGS_FW_DCBX_AGENT_ENABLED)
5106 bp->flags |= BNXT_FLAG_FW_DCBX_AGENT;
Deepak Khungar9e54e322017-04-21 20:11:26 -04005107 }
Michael Chan9315edc2017-07-24 12:34:25 -04005108 if (BNXT_PF(bp) && (flags & FUNC_QCFG_RESP_FLAGS_MULTI_HOST))
5109 bp->flags |= BNXT_FLAG_MULTI_HOST;
Michael Chanbc39f882017-03-08 18:44:34 -05005110
Satish Baddipadige567b2ab2016-06-13 02:25:31 -04005111 switch (resp->port_partition_type) {
5112 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_0:
5113 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_5:
5114 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR2_0:
5115 bp->port_partition_type = resp->port_partition_type;
5116 break;
5117 }
Michael Chan32e8239c2017-07-24 12:34:21 -04005118 if (bp->hwrm_spec_code < 0x10707 ||
5119 resp->evb_mode == FUNC_QCFG_RESP_EVB_MODE_VEB)
5120 bp->br_mode = BRIDGE_MODE_VEB;
5121 else if (resp->evb_mode == FUNC_QCFG_RESP_EVB_MODE_VEPA)
5122 bp->br_mode = BRIDGE_MODE_VEPA;
5123 else
5124 bp->br_mode = BRIDGE_MODE_UNDEF;
Michael Chancf6645f2016-06-13 02:25:28 -04005125
Michael Chan7eb9bb32017-10-26 11:51:25 -04005126 bp->max_mtu = le16_to_cpu(resp->max_mtu_configured);
5127 if (!bp->max_mtu)
5128 bp->max_mtu = BNXT_MAX_MTU;
5129
Michael Chancf6645f2016-06-13 02:25:28 -04005130func_qcfg_exit:
5131 mutex_unlock(&bp->hwrm_cmd_lock);
5132 return rc;
5133}
5134
Michael Chandb4723b2018-03-31 13:54:13 -04005135int bnxt_hwrm_func_resc_qcaps(struct bnxt *bp, bool all)
Michael Chanbe0dd9c2018-01-17 03:21:07 -05005136{
5137 struct hwrm_func_resource_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
5138 struct hwrm_func_resource_qcaps_input req = {0};
5139 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
5140 int rc;
5141
5142 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_RESOURCE_QCAPS, -1, -1);
5143 req.fid = cpu_to_le16(0xffff);
5144
5145 mutex_lock(&bp->hwrm_cmd_lock);
5146 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5147 if (rc) {
5148 rc = -EIO;
5149 goto hwrm_func_resc_qcaps_exit;
5150 }
5151
Michael Chandb4723b2018-03-31 13:54:13 -04005152 hw_resc->max_tx_sch_inputs = le16_to_cpu(resp->max_tx_scheduler_inputs);
5153 if (!all)
5154 goto hwrm_func_resc_qcaps_exit;
5155
Michael Chanbe0dd9c2018-01-17 03:21:07 -05005156 hw_resc->min_rsscos_ctxs = le16_to_cpu(resp->min_rsscos_ctx);
5157 hw_resc->max_rsscos_ctxs = le16_to_cpu(resp->max_rsscos_ctx);
5158 hw_resc->min_cp_rings = le16_to_cpu(resp->min_cmpl_rings);
5159 hw_resc->max_cp_rings = le16_to_cpu(resp->max_cmpl_rings);
5160 hw_resc->min_tx_rings = le16_to_cpu(resp->min_tx_rings);
5161 hw_resc->max_tx_rings = le16_to_cpu(resp->max_tx_rings);
5162 hw_resc->min_rx_rings = le16_to_cpu(resp->min_rx_rings);
5163 hw_resc->max_rx_rings = le16_to_cpu(resp->max_rx_rings);
5164 hw_resc->min_hw_ring_grps = le16_to_cpu(resp->min_hw_ring_grps);
5165 hw_resc->max_hw_ring_grps = le16_to_cpu(resp->max_hw_ring_grps);
5166 hw_resc->min_l2_ctxs = le16_to_cpu(resp->min_l2_ctxs);
5167 hw_resc->max_l2_ctxs = le16_to_cpu(resp->max_l2_ctxs);
5168 hw_resc->min_vnics = le16_to_cpu(resp->min_vnics);
5169 hw_resc->max_vnics = le16_to_cpu(resp->max_vnics);
5170 hw_resc->min_stat_ctxs = le16_to_cpu(resp->min_stat_ctx);
5171 hw_resc->max_stat_ctxs = le16_to_cpu(resp->max_stat_ctx);
5172
Michael Chan4673d662018-01-17 03:21:11 -05005173 if (BNXT_PF(bp)) {
5174 struct bnxt_pf_info *pf = &bp->pf;
5175
5176 pf->vf_resv_strategy =
5177 le16_to_cpu(resp->vf_reservation_strategy);
5178 if (pf->vf_resv_strategy > BNXT_VF_RESV_STRATEGY_MINIMAL)
5179 pf->vf_resv_strategy = BNXT_VF_RESV_STRATEGY_MAXIMAL;
5180 }
Michael Chanbe0dd9c2018-01-17 03:21:07 -05005181hwrm_func_resc_qcaps_exit:
5182 mutex_unlock(&bp->hwrm_cmd_lock);
5183 return rc;
5184}
5185
5186static int __bnxt_hwrm_func_qcaps(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04005187{
5188 int rc = 0;
5189 struct hwrm_func_qcaps_input req = {0};
5190 struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
Michael Chan6a4f2942018-01-17 03:21:06 -05005191 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
5192 u32 flags;
Michael Chanc0c050c2015-10-22 16:01:17 -04005193
5194 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCAPS, -1, -1);
5195 req.fid = cpu_to_le16(0xffff);
5196
5197 mutex_lock(&bp->hwrm_cmd_lock);
5198 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5199 if (rc)
5200 goto hwrm_func_qcaps_exit;
5201
Michael Chan6a4f2942018-01-17 03:21:06 -05005202 flags = le32_to_cpu(resp->flags);
5203 if (flags & FUNC_QCAPS_RESP_FLAGS_ROCE_V1_SUPPORTED)
Michael Chane4060d32016-12-07 00:26:19 -05005204 bp->flags |= BNXT_FLAG_ROCEV1_CAP;
Michael Chan6a4f2942018-01-17 03:21:06 -05005205 if (flags & FUNC_QCAPS_RESP_FLAGS_ROCE_V2_SUPPORTED)
Michael Chane4060d32016-12-07 00:26:19 -05005206 bp->flags |= BNXT_FLAG_ROCEV2_CAP;
5207
Michael Chan7cc5a202016-09-19 03:58:05 -04005208 bp->tx_push_thresh = 0;
Michael Chan6a4f2942018-01-17 03:21:06 -05005209 if (flags & FUNC_QCAPS_RESP_FLAGS_PUSH_MODE_SUPPORTED)
Michael Chan7cc5a202016-09-19 03:58:05 -04005210 bp->tx_push_thresh = BNXT_TX_PUSH_THRESH;
5211
Michael Chan6a4f2942018-01-17 03:21:06 -05005212 hw_resc->max_rsscos_ctxs = le16_to_cpu(resp->max_rsscos_ctx);
5213 hw_resc->max_cp_rings = le16_to_cpu(resp->max_cmpl_rings);
5214 hw_resc->max_tx_rings = le16_to_cpu(resp->max_tx_rings);
5215 hw_resc->max_rx_rings = le16_to_cpu(resp->max_rx_rings);
5216 hw_resc->max_hw_ring_grps = le32_to_cpu(resp->max_hw_ring_grps);
5217 if (!hw_resc->max_hw_ring_grps)
5218 hw_resc->max_hw_ring_grps = hw_resc->max_tx_rings;
5219 hw_resc->max_l2_ctxs = le16_to_cpu(resp->max_l2_ctxs);
5220 hw_resc->max_vnics = le16_to_cpu(resp->max_vnics);
5221 hw_resc->max_stat_ctxs = le16_to_cpu(resp->max_stat_ctx);
5222
Michael Chanc0c050c2015-10-22 16:01:17 -04005223 if (BNXT_PF(bp)) {
5224 struct bnxt_pf_info *pf = &bp->pf;
5225
5226 pf->fw_fid = le16_to_cpu(resp->fid);
5227 pf->port_id = le16_to_cpu(resp->port_id);
Michael Chan87027db2016-07-01 18:46:28 -04005228 bp->dev->dev_port = pf->port_id;
Michael Chan11f15ed2016-04-05 14:08:55 -04005229 memcpy(pf->mac_addr, resp->mac_address, ETH_ALEN);
Michael Chanc0c050c2015-10-22 16:01:17 -04005230 pf->first_vf_id = le16_to_cpu(resp->first_vf_id);
5231 pf->max_vfs = le16_to_cpu(resp->max_vfs);
5232 pf->max_encap_records = le32_to_cpu(resp->max_encap_records);
5233 pf->max_decap_records = le32_to_cpu(resp->max_decap_records);
5234 pf->max_tx_em_flows = le32_to_cpu(resp->max_tx_em_flows);
5235 pf->max_tx_wm_flows = le32_to_cpu(resp->max_tx_wm_flows);
5236 pf->max_rx_em_flows = le32_to_cpu(resp->max_rx_em_flows);
5237 pf->max_rx_wm_flows = le32_to_cpu(resp->max_rx_wm_flows);
Michael Chan6a4f2942018-01-17 03:21:06 -05005238 if (flags & FUNC_QCAPS_RESP_FLAGS_WOL_MAGICPKT_SUPPORTED)
Michael Chanc1ef1462017-04-04 18:14:07 -04005239 bp->flags |= BNXT_FLAG_WOL_CAP;
Michael Chanc0c050c2015-10-22 16:01:17 -04005240 } else {
Michael Chan379a80a2015-10-23 15:06:19 -04005241#ifdef CONFIG_BNXT_SRIOV
Michael Chanc0c050c2015-10-22 16:01:17 -04005242 struct bnxt_vf_info *vf = &bp->vf;
5243
5244 vf->fw_fid = le16_to_cpu(resp->fid);
Michael Chan7cc5a202016-09-19 03:58:05 -04005245 memcpy(vf->mac_addr, resp->mac_address, ETH_ALEN);
Michael Chan379a80a2015-10-23 15:06:19 -04005246#endif
Michael Chanc0c050c2015-10-22 16:01:17 -04005247 }
5248
Michael Chanc0c050c2015-10-22 16:01:17 -04005249hwrm_func_qcaps_exit:
5250 mutex_unlock(&bp->hwrm_cmd_lock);
5251 return rc;
5252}
5253
Michael Chanbe0dd9c2018-01-17 03:21:07 -05005254static int bnxt_hwrm_func_qcaps(struct bnxt *bp)
5255{
5256 int rc;
5257
5258 rc = __bnxt_hwrm_func_qcaps(bp);
5259 if (rc)
5260 return rc;
5261 if (bp->hwrm_spec_code >= 0x10803) {
Michael Chandb4723b2018-03-31 13:54:13 -04005262 rc = bnxt_hwrm_func_resc_qcaps(bp, true);
Michael Chanbe0dd9c2018-01-17 03:21:07 -05005263 if (!rc)
5264 bp->flags |= BNXT_FLAG_NEW_RM;
5265 }
5266 return 0;
5267}
5268
Michael Chanc0c050c2015-10-22 16:01:17 -04005269static int bnxt_hwrm_func_reset(struct bnxt *bp)
5270{
5271 struct hwrm_func_reset_input req = {0};
5272
5273 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_RESET, -1, -1);
5274 req.enables = 0;
5275
5276 return hwrm_send_message(bp, &req, sizeof(req), HWRM_RESET_TIMEOUT);
5277}
5278
5279static int bnxt_hwrm_queue_qportcfg(struct bnxt *bp)
5280{
5281 int rc = 0;
5282 struct hwrm_queue_qportcfg_input req = {0};
5283 struct hwrm_queue_qportcfg_output *resp = bp->hwrm_cmd_resp_addr;
5284 u8 i, *qptr;
5285
5286 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_QUEUE_QPORTCFG, -1, -1);
5287
5288 mutex_lock(&bp->hwrm_cmd_lock);
5289 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5290 if (rc)
5291 goto qportcfg_exit;
5292
5293 if (!resp->max_configurable_queues) {
5294 rc = -EINVAL;
5295 goto qportcfg_exit;
5296 }
5297 bp->max_tc = resp->max_configurable_queues;
Michael Chan87c374d2016-12-02 21:17:16 -05005298 bp->max_lltc = resp->max_configurable_lossless_queues;
Michael Chanc0c050c2015-10-22 16:01:17 -04005299 if (bp->max_tc > BNXT_MAX_QUEUE)
5300 bp->max_tc = BNXT_MAX_QUEUE;
5301
Michael Chan441cabb2016-09-19 03:58:02 -04005302 if (resp->queue_cfg_info & QUEUE_QPORTCFG_RESP_QUEUE_CFG_INFO_ASYM_CFG)
5303 bp->max_tc = 1;
5304
Michael Chan87c374d2016-12-02 21:17:16 -05005305 if (bp->max_lltc > bp->max_tc)
5306 bp->max_lltc = bp->max_tc;
5307
Michael Chanc0c050c2015-10-22 16:01:17 -04005308 qptr = &resp->queue_id0;
5309 for (i = 0; i < bp->max_tc; i++) {
5310 bp->q_info[i].queue_id = *qptr++;
5311 bp->q_info[i].queue_profile = *qptr++;
5312 }
5313
5314qportcfg_exit:
5315 mutex_unlock(&bp->hwrm_cmd_lock);
5316 return rc;
5317}
5318
5319static int bnxt_hwrm_ver_get(struct bnxt *bp)
5320{
5321 int rc;
5322 struct hwrm_ver_get_input req = {0};
5323 struct hwrm_ver_get_output *resp = bp->hwrm_cmd_resp_addr;
Deepak Khungare605db82017-05-29 19:06:04 -04005324 u32 dev_caps_cfg;
Michael Chanc0c050c2015-10-22 16:01:17 -04005325
Michael Chane6ef2692016-03-28 19:46:05 -04005326 bp->hwrm_max_req_len = HWRM_MAX_REQ_LEN;
Michael Chanc0c050c2015-10-22 16:01:17 -04005327 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VER_GET, -1, -1);
5328 req.hwrm_intf_maj = HWRM_VERSION_MAJOR;
5329 req.hwrm_intf_min = HWRM_VERSION_MINOR;
5330 req.hwrm_intf_upd = HWRM_VERSION_UPDATE;
5331 mutex_lock(&bp->hwrm_cmd_lock);
5332 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5333 if (rc)
5334 goto hwrm_ver_get_exit;
5335
5336 memcpy(&bp->ver_resp, resp, sizeof(struct hwrm_ver_get_output));
5337
Michael Chan894aa692018-01-17 03:21:03 -05005338 bp->hwrm_spec_code = resp->hwrm_intf_maj_8b << 16 |
5339 resp->hwrm_intf_min_8b << 8 |
5340 resp->hwrm_intf_upd_8b;
5341 if (resp->hwrm_intf_maj_8b < 1) {
Michael Chanc1935542015-12-27 18:19:28 -05005342 netdev_warn(bp->dev, "HWRM interface %d.%d.%d is older than 1.0.0.\n",
Michael Chan894aa692018-01-17 03:21:03 -05005343 resp->hwrm_intf_maj_8b, resp->hwrm_intf_min_8b,
5344 resp->hwrm_intf_upd_8b);
Michael Chanc1935542015-12-27 18:19:28 -05005345 netdev_warn(bp->dev, "Please update firmware with HWRM interface 1.0.0 or newer.\n");
Michael Chanc0c050c2015-10-22 16:01:17 -04005346 }
Michael Chan431aa1e2017-10-26 11:51:23 -04005347 snprintf(bp->fw_ver_str, BC_HWRM_STR_LEN, "%d.%d.%d.%d",
Michael Chan894aa692018-01-17 03:21:03 -05005348 resp->hwrm_fw_maj_8b, resp->hwrm_fw_min_8b,
5349 resp->hwrm_fw_bld_8b, resp->hwrm_fw_rsvd_8b);
Michael Chanc0c050c2015-10-22 16:01:17 -04005350
Michael Chanff4fe812016-02-26 04:00:04 -05005351 bp->hwrm_cmd_timeout = le16_to_cpu(resp->def_req_timeout);
5352 if (!bp->hwrm_cmd_timeout)
5353 bp->hwrm_cmd_timeout = DFLT_HWRM_CMD_TIMEOUT;
5354
Michael Chan894aa692018-01-17 03:21:03 -05005355 if (resp->hwrm_intf_maj_8b >= 1)
Michael Chane6ef2692016-03-28 19:46:05 -04005356 bp->hwrm_max_req_len = le16_to_cpu(resp->max_req_win_len);
5357
Michael Chan659c8052016-06-13 02:25:33 -04005358 bp->chip_num = le16_to_cpu(resp->chip_num);
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04005359 if (bp->chip_num == CHIP_NUM_58700 && !resp->chip_rev &&
5360 !resp->chip_metal)
5361 bp->flags |= BNXT_FLAG_CHIP_NITRO_A0;
Michael Chan659c8052016-06-13 02:25:33 -04005362
Deepak Khungare605db82017-05-29 19:06:04 -04005363 dev_caps_cfg = le32_to_cpu(resp->dev_caps_cfg);
5364 if ((dev_caps_cfg & VER_GET_RESP_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED) &&
5365 (dev_caps_cfg & VER_GET_RESP_DEV_CAPS_CFG_SHORT_CMD_REQUIRED))
5366 bp->flags |= BNXT_FLAG_SHORT_CMD;
5367
Michael Chanc0c050c2015-10-22 16:01:17 -04005368hwrm_ver_get_exit:
5369 mutex_unlock(&bp->hwrm_cmd_lock);
5370 return rc;
5371}
5372
Rob Swindell5ac67d82016-09-19 03:58:03 -04005373int bnxt_hwrm_fw_set_time(struct bnxt *bp)
5374{
5375 struct hwrm_fw_set_time_input req = {0};
Arnd Bergmann7dfaa7b2017-11-06 15:04:39 +01005376 struct tm tm;
5377 time64_t now = ktime_get_real_seconds();
Rob Swindell5ac67d82016-09-19 03:58:03 -04005378
5379 if (bp->hwrm_spec_code < 0x10400)
5380 return -EOPNOTSUPP;
5381
Arnd Bergmann7dfaa7b2017-11-06 15:04:39 +01005382 time64_to_tm(now, 0, &tm);
Rob Swindell5ac67d82016-09-19 03:58:03 -04005383 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_SET_TIME, -1, -1);
5384 req.year = cpu_to_le16(1900 + tm.tm_year);
5385 req.month = 1 + tm.tm_mon;
5386 req.day = tm.tm_mday;
5387 req.hour = tm.tm_hour;
5388 req.minute = tm.tm_min;
5389 req.second = tm.tm_sec;
5390 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5391}
5392
Michael Chan3bdf56c2016-03-07 15:38:45 -05005393static int bnxt_hwrm_port_qstats(struct bnxt *bp)
5394{
5395 int rc;
5396 struct bnxt_pf_info *pf = &bp->pf;
5397 struct hwrm_port_qstats_input req = {0};
5398
5399 if (!(bp->flags & BNXT_FLAG_PORT_STATS))
5400 return 0;
5401
5402 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_QSTATS, -1, -1);
5403 req.port_id = cpu_to_le16(pf->port_id);
5404 req.tx_stat_host_addr = cpu_to_le64(bp->hw_tx_port_stats_map);
5405 req.rx_stat_host_addr = cpu_to_le64(bp->hw_rx_port_stats_map);
5406 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5407 return rc;
5408}
5409
Vasundhara Volam00db3cb2018-03-31 13:54:12 -04005410static int bnxt_hwrm_port_qstats_ext(struct bnxt *bp)
5411{
5412 struct hwrm_port_qstats_ext_input req = {0};
5413 struct bnxt_pf_info *pf = &bp->pf;
5414
5415 if (!(bp->flags & BNXT_FLAG_PORT_STATS_EXT))
5416 return 0;
5417
5418 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_QSTATS_EXT, -1, -1);
5419 req.port_id = cpu_to_le16(pf->port_id);
5420 req.rx_stat_size = cpu_to_le16(sizeof(struct rx_port_stats_ext));
5421 req.rx_stat_host_addr = cpu_to_le64(bp->hw_rx_port_stats_ext_map);
5422 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5423}
5424
Michael Chanc0c050c2015-10-22 16:01:17 -04005425static void bnxt_hwrm_free_tunnel_ports(struct bnxt *bp)
5426{
5427 if (bp->vxlan_port_cnt) {
5428 bnxt_hwrm_tunnel_dst_port_free(
5429 bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN);
5430 }
5431 bp->vxlan_port_cnt = 0;
5432 if (bp->nge_port_cnt) {
5433 bnxt_hwrm_tunnel_dst_port_free(
5434 bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE);
5435 }
5436 bp->nge_port_cnt = 0;
5437}
5438
5439static int bnxt_set_tpa(struct bnxt *bp, bool set_tpa)
5440{
5441 int rc, i;
5442 u32 tpa_flags = 0;
5443
5444 if (set_tpa)
5445 tpa_flags = bp->flags & BNXT_FLAG_TPA;
5446 for (i = 0; i < bp->nr_vnics; i++) {
5447 rc = bnxt_hwrm_vnic_set_tpa(bp, i, tpa_flags);
5448 if (rc) {
5449 netdev_err(bp->dev, "hwrm vnic set tpa failure rc for vnic %d: %x\n",
Sankar Patchineelam23e12c82017-03-28 19:47:30 -04005450 i, rc);
Michael Chanc0c050c2015-10-22 16:01:17 -04005451 return rc;
5452 }
5453 }
5454 return 0;
5455}
5456
5457static void bnxt_hwrm_clear_vnic_rss(struct bnxt *bp)
5458{
5459 int i;
5460
5461 for (i = 0; i < bp->nr_vnics; i++)
5462 bnxt_hwrm_vnic_set_rss(bp, i, false);
5463}
5464
5465static void bnxt_hwrm_resource_free(struct bnxt *bp, bool close_path,
5466 bool irq_re_init)
5467{
5468 if (bp->vnic_info) {
5469 bnxt_hwrm_clear_vnic_filter(bp);
5470 /* clear all RSS setting before free vnic ctx */
5471 bnxt_hwrm_clear_vnic_rss(bp);
5472 bnxt_hwrm_vnic_ctx_free(bp);
5473 /* before free the vnic, undo the vnic tpa settings */
5474 if (bp->flags & BNXT_FLAG_TPA)
5475 bnxt_set_tpa(bp, false);
5476 bnxt_hwrm_vnic_free(bp);
5477 }
5478 bnxt_hwrm_ring_free(bp, close_path);
5479 bnxt_hwrm_ring_grp_free(bp);
5480 if (irq_re_init) {
5481 bnxt_hwrm_stat_ctx_free(bp);
5482 bnxt_hwrm_free_tunnel_ports(bp);
5483 }
5484}
5485
Michael Chan39d8ba22017-07-24 12:34:22 -04005486static int bnxt_hwrm_set_br_mode(struct bnxt *bp, u16 br_mode)
5487{
5488 struct hwrm_func_cfg_input req = {0};
5489 int rc;
5490
5491 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1);
5492 req.fid = cpu_to_le16(0xffff);
5493 req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_EVB_MODE);
5494 if (br_mode == BRIDGE_MODE_VEB)
5495 req.evb_mode = FUNC_CFG_REQ_EVB_MODE_VEB;
5496 else if (br_mode == BRIDGE_MODE_VEPA)
5497 req.evb_mode = FUNC_CFG_REQ_EVB_MODE_VEPA;
5498 else
5499 return -EINVAL;
5500 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5501 if (rc)
5502 rc = -EIO;
5503 return rc;
5504}
5505
Michael Chanc3480a62018-01-17 03:21:15 -05005506static int bnxt_hwrm_set_cache_line_size(struct bnxt *bp, int size)
5507{
5508 struct hwrm_func_cfg_input req = {0};
5509 int rc;
5510
5511 if (BNXT_VF(bp) || bp->hwrm_spec_code < 0x10803)
5512 return 0;
5513
5514 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1);
5515 req.fid = cpu_to_le16(0xffff);
5516 req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_CACHE_LINESIZE);
Michael Chand4f52de2018-03-31 13:54:06 -04005517 req.options = FUNC_CFG_REQ_OPTIONS_CACHE_LINESIZE_SIZE_64;
Michael Chanc3480a62018-01-17 03:21:15 -05005518 if (size == 128)
Michael Chand4f52de2018-03-31 13:54:06 -04005519 req.options = FUNC_CFG_REQ_OPTIONS_CACHE_LINESIZE_SIZE_128;
Michael Chanc3480a62018-01-17 03:21:15 -05005520
5521 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5522 if (rc)
5523 rc = -EIO;
5524 return rc;
5525}
5526
Michael Chanc0c050c2015-10-22 16:01:17 -04005527static int bnxt_setup_vnic(struct bnxt *bp, u16 vnic_id)
5528{
Michael Chanae10ae72016-12-29 12:13:38 -05005529 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
Michael Chanc0c050c2015-10-22 16:01:17 -04005530 int rc;
5531
Michael Chanae10ae72016-12-29 12:13:38 -05005532 if (vnic->flags & BNXT_VNIC_RFS_NEW_RSS_FLAG)
5533 goto skip_rss_ctx;
5534
Michael Chanc0c050c2015-10-22 16:01:17 -04005535 /* allocate context for vnic */
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04005536 rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic_id, 0);
Michael Chanc0c050c2015-10-22 16:01:17 -04005537 if (rc) {
5538 netdev_err(bp->dev, "hwrm vnic %d alloc failure rc: %x\n",
5539 vnic_id, rc);
5540 goto vnic_setup_err;
5541 }
5542 bp->rsscos_nr_ctxs++;
5543
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04005544 if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
5545 rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic_id, 1);
5546 if (rc) {
5547 netdev_err(bp->dev, "hwrm vnic %d cos ctx alloc failure rc: %x\n",
5548 vnic_id, rc);
5549 goto vnic_setup_err;
5550 }
5551 bp->rsscos_nr_ctxs++;
5552 }
5553
Michael Chanae10ae72016-12-29 12:13:38 -05005554skip_rss_ctx:
Michael Chanc0c050c2015-10-22 16:01:17 -04005555 /* configure default vnic, ring grp */
5556 rc = bnxt_hwrm_vnic_cfg(bp, vnic_id);
5557 if (rc) {
5558 netdev_err(bp->dev, "hwrm vnic %d cfg failure rc: %x\n",
5559 vnic_id, rc);
5560 goto vnic_setup_err;
5561 }
5562
5563 /* Enable RSS hashing on vnic */
5564 rc = bnxt_hwrm_vnic_set_rss(bp, vnic_id, true);
5565 if (rc) {
5566 netdev_err(bp->dev, "hwrm vnic %d set rss failure rc: %x\n",
5567 vnic_id, rc);
5568 goto vnic_setup_err;
5569 }
5570
5571 if (bp->flags & BNXT_FLAG_AGG_RINGS) {
5572 rc = bnxt_hwrm_vnic_set_hds(bp, vnic_id);
5573 if (rc) {
5574 netdev_err(bp->dev, "hwrm vnic %d set hds failure rc: %x\n",
5575 vnic_id, rc);
5576 }
5577 }
5578
5579vnic_setup_err:
5580 return rc;
5581}
5582
5583static int bnxt_alloc_rfs_vnics(struct bnxt *bp)
5584{
5585#ifdef CONFIG_RFS_ACCEL
5586 int i, rc = 0;
5587
5588 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanae10ae72016-12-29 12:13:38 -05005589 struct bnxt_vnic_info *vnic;
Michael Chanc0c050c2015-10-22 16:01:17 -04005590 u16 vnic_id = i + 1;
5591 u16 ring_id = i;
5592
5593 if (vnic_id >= bp->nr_vnics)
5594 break;
5595
Michael Chanae10ae72016-12-29 12:13:38 -05005596 vnic = &bp->vnic_info[vnic_id];
5597 vnic->flags |= BNXT_VNIC_RFS_FLAG;
5598 if (bp->flags & BNXT_FLAG_NEW_RSS_CAP)
5599 vnic->flags |= BNXT_VNIC_RFS_NEW_RSS_FLAG;
Michael Chanb81a90d2016-01-02 23:45:01 -05005600 rc = bnxt_hwrm_vnic_alloc(bp, vnic_id, ring_id, 1);
Michael Chanc0c050c2015-10-22 16:01:17 -04005601 if (rc) {
5602 netdev_err(bp->dev, "hwrm vnic %d alloc failure rc: %x\n",
5603 vnic_id, rc);
5604 break;
5605 }
5606 rc = bnxt_setup_vnic(bp, vnic_id);
5607 if (rc)
5608 break;
5609 }
5610 return rc;
5611#else
5612 return 0;
5613#endif
5614}
5615
Michael Chan17c71ac2016-07-01 18:46:27 -04005616/* Allow PF and VF with default VLAN to be in promiscuous mode */
5617static bool bnxt_promisc_ok(struct bnxt *bp)
5618{
5619#ifdef CONFIG_BNXT_SRIOV
5620 if (BNXT_VF(bp) && !bp->vf.vlan)
5621 return false;
5622#endif
5623 return true;
5624}
5625
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04005626static int bnxt_setup_nitroa0_vnic(struct bnxt *bp)
5627{
5628 unsigned int rc = 0;
5629
5630 rc = bnxt_hwrm_vnic_alloc(bp, 1, bp->rx_nr_rings - 1, 1);
5631 if (rc) {
5632 netdev_err(bp->dev, "Cannot allocate special vnic for NS2 A0: %x\n",
5633 rc);
5634 return rc;
5635 }
5636
5637 rc = bnxt_hwrm_vnic_cfg(bp, 1);
5638 if (rc) {
5639 netdev_err(bp->dev, "Cannot allocate special vnic for NS2 A0: %x\n",
5640 rc);
5641 return rc;
5642 }
5643 return rc;
5644}
5645
Michael Chanb664f002015-12-02 01:54:08 -05005646static int bnxt_cfg_rx_mode(struct bnxt *);
Michael Chan7d2837d2016-05-04 16:56:44 -04005647static bool bnxt_mc_list_updated(struct bnxt *, u32 *);
Michael Chanb664f002015-12-02 01:54:08 -05005648
Michael Chanc0c050c2015-10-22 16:01:17 -04005649static int bnxt_init_chip(struct bnxt *bp, bool irq_re_init)
5650{
Michael Chan7d2837d2016-05-04 16:56:44 -04005651 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
Michael Chanc0c050c2015-10-22 16:01:17 -04005652 int rc = 0;
Prashant Sreedharan76595192016-07-18 07:15:22 -04005653 unsigned int rx_nr_rings = bp->rx_nr_rings;
Michael Chanc0c050c2015-10-22 16:01:17 -04005654
5655 if (irq_re_init) {
5656 rc = bnxt_hwrm_stat_ctx_alloc(bp);
5657 if (rc) {
5658 netdev_err(bp->dev, "hwrm stat ctx alloc failure rc: %x\n",
5659 rc);
5660 goto err_out;
5661 }
5662 }
5663
5664 rc = bnxt_hwrm_ring_alloc(bp);
5665 if (rc) {
5666 netdev_err(bp->dev, "hwrm ring alloc failure rc: %x\n", rc);
5667 goto err_out;
5668 }
5669
5670 rc = bnxt_hwrm_ring_grp_alloc(bp);
5671 if (rc) {
5672 netdev_err(bp->dev, "hwrm_ring_grp alloc failure: %x\n", rc);
5673 goto err_out;
5674 }
5675
Prashant Sreedharan76595192016-07-18 07:15:22 -04005676 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
5677 rx_nr_rings--;
5678
Michael Chanc0c050c2015-10-22 16:01:17 -04005679 /* default vnic 0 */
Prashant Sreedharan76595192016-07-18 07:15:22 -04005680 rc = bnxt_hwrm_vnic_alloc(bp, 0, 0, rx_nr_rings);
Michael Chanc0c050c2015-10-22 16:01:17 -04005681 if (rc) {
5682 netdev_err(bp->dev, "hwrm vnic alloc failure rc: %x\n", rc);
5683 goto err_out;
5684 }
5685
5686 rc = bnxt_setup_vnic(bp, 0);
5687 if (rc)
5688 goto err_out;
5689
5690 if (bp->flags & BNXT_FLAG_RFS) {
5691 rc = bnxt_alloc_rfs_vnics(bp);
5692 if (rc)
5693 goto err_out;
5694 }
5695
5696 if (bp->flags & BNXT_FLAG_TPA) {
5697 rc = bnxt_set_tpa(bp, true);
5698 if (rc)
5699 goto err_out;
5700 }
5701
5702 if (BNXT_VF(bp))
5703 bnxt_update_vf_mac(bp);
5704
5705 /* Filter for default vnic 0 */
5706 rc = bnxt_hwrm_set_vnic_filter(bp, 0, 0, bp->dev->dev_addr);
5707 if (rc) {
5708 netdev_err(bp->dev, "HWRM vnic filter failure rc: %x\n", rc);
5709 goto err_out;
5710 }
Michael Chan7d2837d2016-05-04 16:56:44 -04005711 vnic->uc_filter_count = 1;
Michael Chanc0c050c2015-10-22 16:01:17 -04005712
Michael Chan7d2837d2016-05-04 16:56:44 -04005713 vnic->rx_mask = CFA_L2_SET_RX_MASK_REQ_MASK_BCAST;
Michael Chanc0c050c2015-10-22 16:01:17 -04005714
Michael Chan17c71ac2016-07-01 18:46:27 -04005715 if ((bp->dev->flags & IFF_PROMISC) && bnxt_promisc_ok(bp))
Michael Chan7d2837d2016-05-04 16:56:44 -04005716 vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS;
5717
5718 if (bp->dev->flags & IFF_ALLMULTI) {
5719 vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST;
5720 vnic->mc_list_count = 0;
5721 } else {
5722 u32 mask = 0;
5723
5724 bnxt_mc_list_updated(bp, &mask);
5725 vnic->rx_mask |= mask;
5726 }
Michael Chanc0c050c2015-10-22 16:01:17 -04005727
Michael Chanb664f002015-12-02 01:54:08 -05005728 rc = bnxt_cfg_rx_mode(bp);
5729 if (rc)
Michael Chanc0c050c2015-10-22 16:01:17 -04005730 goto err_out;
Michael Chanc0c050c2015-10-22 16:01:17 -04005731
5732 rc = bnxt_hwrm_set_coal(bp);
5733 if (rc)
5734 netdev_warn(bp->dev, "HWRM set coalescing failure rc: %x\n",
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04005735 rc);
5736
5737 if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
5738 rc = bnxt_setup_nitroa0_vnic(bp);
5739 if (rc)
5740 netdev_err(bp->dev, "Special vnic setup failure for NS2 A0 rc: %x\n",
5741 rc);
5742 }
Michael Chanc0c050c2015-10-22 16:01:17 -04005743
Michael Chancf6645f2016-06-13 02:25:28 -04005744 if (BNXT_VF(bp)) {
5745 bnxt_hwrm_func_qcfg(bp);
5746 netdev_update_features(bp->dev);
5747 }
5748
Michael Chanc0c050c2015-10-22 16:01:17 -04005749 return 0;
5750
5751err_out:
5752 bnxt_hwrm_resource_free(bp, 0, true);
5753
5754 return rc;
5755}
5756
5757static int bnxt_shutdown_nic(struct bnxt *bp, bool irq_re_init)
5758{
5759 bnxt_hwrm_resource_free(bp, 1, irq_re_init);
5760 return 0;
5761}
5762
5763static int bnxt_init_nic(struct bnxt *bp, bool irq_re_init)
5764{
Sankar Patchineelam22479252017-03-28 19:47:29 -04005765 bnxt_init_cp_rings(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04005766 bnxt_init_rx_rings(bp);
5767 bnxt_init_tx_rings(bp);
5768 bnxt_init_ring_grps(bp, irq_re_init);
5769 bnxt_init_vnics(bp);
5770
5771 return bnxt_init_chip(bp, irq_re_init);
5772}
5773
Michael Chanc0c050c2015-10-22 16:01:17 -04005774static int bnxt_set_real_num_queues(struct bnxt *bp)
5775{
5776 int rc;
5777 struct net_device *dev = bp->dev;
5778
Michael Chan5f449242017-02-06 16:55:40 -05005779 rc = netif_set_real_num_tx_queues(dev, bp->tx_nr_rings -
5780 bp->tx_nr_rings_xdp);
Michael Chanc0c050c2015-10-22 16:01:17 -04005781 if (rc)
5782 return rc;
5783
5784 rc = netif_set_real_num_rx_queues(dev, bp->rx_nr_rings);
5785 if (rc)
5786 return rc;
5787
5788#ifdef CONFIG_RFS_ACCEL
Michael Chan45019a12015-12-27 18:19:22 -05005789 if (bp->flags & BNXT_FLAG_RFS)
Michael Chanc0c050c2015-10-22 16:01:17 -04005790 dev->rx_cpu_rmap = alloc_irq_cpu_rmap(bp->rx_nr_rings);
Michael Chanc0c050c2015-10-22 16:01:17 -04005791#endif
5792
5793 return rc;
5794}
5795
Michael Chan6e6c5a52016-01-02 23:45:02 -05005796static int bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max,
5797 bool shared)
5798{
5799 int _rx = *rx, _tx = *tx;
5800
5801 if (shared) {
5802 *rx = min_t(int, _rx, max);
5803 *tx = min_t(int, _tx, max);
5804 } else {
5805 if (max < 2)
5806 return -ENOMEM;
5807
5808 while (_rx + _tx > max) {
5809 if (_rx > _tx && _rx > 1)
5810 _rx--;
5811 else if (_tx > 1)
5812 _tx--;
5813 }
5814 *rx = _rx;
5815 *tx = _tx;
5816 }
5817 return 0;
5818}
5819
Michael Chan78095922016-12-07 00:26:16 -05005820static void bnxt_setup_msix(struct bnxt *bp)
5821{
5822 const int len = sizeof(bp->irq_tbl[0].name);
5823 struct net_device *dev = bp->dev;
5824 int tcs, i;
5825
5826 tcs = netdev_get_num_tc(dev);
5827 if (tcs > 1) {
Michael Chand1e79252017-02-06 16:55:38 -05005828 int i, off, count;
Michael Chan78095922016-12-07 00:26:16 -05005829
Michael Chand1e79252017-02-06 16:55:38 -05005830 for (i = 0; i < tcs; i++) {
5831 count = bp->tx_nr_rings_per_tc;
5832 off = i * count;
5833 netdev_set_tc_queue(dev, i, count, off);
Michael Chan78095922016-12-07 00:26:16 -05005834 }
5835 }
5836
5837 for (i = 0; i < bp->cp_nr_rings; i++) {
Michael Chane5811b82018-03-31 13:54:18 -04005838 int map_idx = bnxt_cp_num_to_irq_num(bp, i);
Michael Chan78095922016-12-07 00:26:16 -05005839 char *attr;
5840
5841 if (bp->flags & BNXT_FLAG_SHARED_RINGS)
5842 attr = "TxRx";
5843 else if (i < bp->rx_nr_rings)
5844 attr = "rx";
5845 else
5846 attr = "tx";
5847
Michael Chane5811b82018-03-31 13:54:18 -04005848 snprintf(bp->irq_tbl[map_idx].name, len, "%s-%s-%d", dev->name,
5849 attr, i);
5850 bp->irq_tbl[map_idx].handler = bnxt_msix;
Michael Chan78095922016-12-07 00:26:16 -05005851 }
5852}
5853
5854static void bnxt_setup_inta(struct bnxt *bp)
5855{
5856 const int len = sizeof(bp->irq_tbl[0].name);
5857
5858 if (netdev_get_num_tc(bp->dev))
5859 netdev_reset_tc(bp->dev);
5860
5861 snprintf(bp->irq_tbl[0].name, len, "%s-%s-%d", bp->dev->name, "TxRx",
5862 0);
5863 bp->irq_tbl[0].handler = bnxt_inta;
5864}
5865
5866static int bnxt_setup_int_mode(struct bnxt *bp)
5867{
5868 int rc;
5869
5870 if (bp->flags & BNXT_FLAG_USING_MSIX)
5871 bnxt_setup_msix(bp);
5872 else
5873 bnxt_setup_inta(bp);
5874
5875 rc = bnxt_set_real_num_queues(bp);
5876 return rc;
5877}
5878
Michael Chanb7429952017-01-13 01:32:00 -05005879#ifdef CONFIG_RFS_ACCEL
Michael Chan8079e8f2016-12-29 12:13:37 -05005880static unsigned int bnxt_get_max_func_rss_ctxs(struct bnxt *bp)
5881{
Michael Chan6a4f2942018-01-17 03:21:06 -05005882 return bp->hw_resc.max_rsscos_ctxs;
Michael Chan8079e8f2016-12-29 12:13:37 -05005883}
5884
5885static unsigned int bnxt_get_max_func_vnics(struct bnxt *bp)
5886{
Michael Chan6a4f2942018-01-17 03:21:06 -05005887 return bp->hw_resc.max_vnics;
Michael Chan8079e8f2016-12-29 12:13:37 -05005888}
Michael Chanb7429952017-01-13 01:32:00 -05005889#endif
Michael Chan8079e8f2016-12-29 12:13:37 -05005890
Michael Chane4060d32016-12-07 00:26:19 -05005891unsigned int bnxt_get_max_func_stat_ctxs(struct bnxt *bp)
5892{
Michael Chan6a4f2942018-01-17 03:21:06 -05005893 return bp->hw_resc.max_stat_ctxs;
Michael Chane4060d32016-12-07 00:26:19 -05005894}
5895
Michael Chana588e452016-12-07 00:26:21 -05005896void bnxt_set_max_func_stat_ctxs(struct bnxt *bp, unsigned int max)
5897{
Michael Chan6a4f2942018-01-17 03:21:06 -05005898 bp->hw_resc.max_stat_ctxs = max;
Michael Chana588e452016-12-07 00:26:21 -05005899}
5900
Michael Chane4060d32016-12-07 00:26:19 -05005901unsigned int bnxt_get_max_func_cp_rings(struct bnxt *bp)
5902{
Michael Chan6a4f2942018-01-17 03:21:06 -05005903 return bp->hw_resc.max_cp_rings;
Michael Chane4060d32016-12-07 00:26:19 -05005904}
5905
Michael Chana588e452016-12-07 00:26:21 -05005906void bnxt_set_max_func_cp_rings(struct bnxt *bp, unsigned int max)
5907{
Michael Chan6a4f2942018-01-17 03:21:06 -05005908 bp->hw_resc.max_cp_rings = max;
Michael Chana588e452016-12-07 00:26:21 -05005909}
5910
Michael Chanfbcfc8e2018-03-31 13:54:20 -04005911unsigned int bnxt_get_max_func_irqs(struct bnxt *bp)
Michael Chan78095922016-12-07 00:26:16 -05005912{
Michael Chan6a4f2942018-01-17 03:21:06 -05005913 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
5914
5915 return min_t(unsigned int, hw_resc->max_irqs, hw_resc->max_cp_rings);
Michael Chan78095922016-12-07 00:26:16 -05005916}
5917
Michael Chan33c26572016-12-07 00:26:15 -05005918void bnxt_set_max_func_irqs(struct bnxt *bp, unsigned int max_irqs)
5919{
Michael Chan6a4f2942018-01-17 03:21:06 -05005920 bp->hw_resc.max_irqs = max_irqs;
Michael Chan33c26572016-12-07 00:26:15 -05005921}
5922
Michael Chanfbcfc8e2018-03-31 13:54:20 -04005923int bnxt_get_avail_msix(struct bnxt *bp, int num)
5924{
5925 int max_cp = bnxt_get_max_func_cp_rings(bp);
5926 int max_irq = bnxt_get_max_func_irqs(bp);
5927 int total_req = bp->cp_nr_rings + num;
5928 int max_idx, avail_msix;
5929
5930 max_idx = min_t(int, bp->total_irqs, max_cp);
5931 avail_msix = max_idx - bp->cp_nr_rings;
5932 if (!(bp->flags & BNXT_FLAG_NEW_RM) || avail_msix >= num)
5933 return avail_msix;
5934
5935 if (max_irq < total_req) {
5936 num = max_irq - bp->cp_nr_rings;
5937 if (num <= 0)
5938 return 0;
5939 }
5940 return num;
5941}
5942
Michael Chan08654eb2018-03-31 13:54:17 -04005943static int bnxt_get_num_msix(struct bnxt *bp)
5944{
5945 if (!(bp->flags & BNXT_FLAG_NEW_RM))
5946 return bnxt_get_max_func_irqs(bp);
5947
5948 return bnxt_cp_rings_in_use(bp);
5949}
5950
Michael Chan78095922016-12-07 00:26:16 -05005951static int bnxt_init_msix(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04005952{
Michael Chanfbcfc8e2018-03-31 13:54:20 -04005953 int i, total_vecs, max, rc = 0, min = 1, ulp_msix;
Michael Chan78095922016-12-07 00:26:16 -05005954 struct msix_entry *msix_ent;
Michael Chanc0c050c2015-10-22 16:01:17 -04005955
Michael Chan08654eb2018-03-31 13:54:17 -04005956 total_vecs = bnxt_get_num_msix(bp);
5957 max = bnxt_get_max_func_irqs(bp);
5958 if (total_vecs > max)
5959 total_vecs = max;
5960
Michael Chanc0c050c2015-10-22 16:01:17 -04005961 msix_ent = kcalloc(total_vecs, sizeof(struct msix_entry), GFP_KERNEL);
5962 if (!msix_ent)
5963 return -ENOMEM;
5964
5965 for (i = 0; i < total_vecs; i++) {
5966 msix_ent[i].entry = i;
5967 msix_ent[i].vector = 0;
5968 }
5969
Michael Chan01657bc2016-01-02 23:45:03 -05005970 if (!(bp->flags & BNXT_FLAG_SHARED_RINGS))
5971 min = 2;
5972
5973 total_vecs = pci_enable_msix_range(bp->pdev, msix_ent, min, total_vecs);
Michael Chanfbcfc8e2018-03-31 13:54:20 -04005974 ulp_msix = bnxt_get_ulp_msix_num(bp);
5975 if (total_vecs < 0 || total_vecs < ulp_msix) {
Michael Chanc0c050c2015-10-22 16:01:17 -04005976 rc = -ENODEV;
5977 goto msix_setup_exit;
5978 }
5979
5980 bp->irq_tbl = kcalloc(total_vecs, sizeof(struct bnxt_irq), GFP_KERNEL);
5981 if (bp->irq_tbl) {
Michael Chan78095922016-12-07 00:26:16 -05005982 for (i = 0; i < total_vecs; i++)
5983 bp->irq_tbl[i].vector = msix_ent[i].vector;
Michael Chanc0c050c2015-10-22 16:01:17 -04005984
Michael Chan78095922016-12-07 00:26:16 -05005985 bp->total_irqs = total_vecs;
Michael Chanc0c050c2015-10-22 16:01:17 -04005986 /* Trim rings based upon num of vectors allocated */
Michael Chan6e6c5a52016-01-02 23:45:02 -05005987 rc = bnxt_trim_rings(bp, &bp->rx_nr_rings, &bp->tx_nr_rings,
Michael Chanfbcfc8e2018-03-31 13:54:20 -04005988 total_vecs - ulp_msix, min == 1);
Michael Chan6e6c5a52016-01-02 23:45:02 -05005989 if (rc)
5990 goto msix_setup_exit;
5991
Michael Chan78095922016-12-07 00:26:16 -05005992 bp->cp_nr_rings = (min == 1) ?
5993 max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
5994 bp->tx_nr_rings + bp->rx_nr_rings;
Michael Chanc0c050c2015-10-22 16:01:17 -04005995
Michael Chanc0c050c2015-10-22 16:01:17 -04005996 } else {
5997 rc = -ENOMEM;
5998 goto msix_setup_exit;
5999 }
6000 bp->flags |= BNXT_FLAG_USING_MSIX;
6001 kfree(msix_ent);
6002 return 0;
6003
6004msix_setup_exit:
Michael Chan78095922016-12-07 00:26:16 -05006005 netdev_err(bp->dev, "bnxt_init_msix err: %x\n", rc);
6006 kfree(bp->irq_tbl);
6007 bp->irq_tbl = NULL;
Michael Chanc0c050c2015-10-22 16:01:17 -04006008 pci_disable_msix(bp->pdev);
6009 kfree(msix_ent);
6010 return rc;
6011}
6012
Michael Chan78095922016-12-07 00:26:16 -05006013static int bnxt_init_inta(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04006014{
Michael Chanc0c050c2015-10-22 16:01:17 -04006015 bp->irq_tbl = kcalloc(1, sizeof(struct bnxt_irq), GFP_KERNEL);
Michael Chan78095922016-12-07 00:26:16 -05006016 if (!bp->irq_tbl)
6017 return -ENOMEM;
6018
6019 bp->total_irqs = 1;
Michael Chanc0c050c2015-10-22 16:01:17 -04006020 bp->rx_nr_rings = 1;
6021 bp->tx_nr_rings = 1;
6022 bp->cp_nr_rings = 1;
Michael Chan01657bc2016-01-02 23:45:03 -05006023 bp->flags |= BNXT_FLAG_SHARED_RINGS;
Michael Chanc0c050c2015-10-22 16:01:17 -04006024 bp->irq_tbl[0].vector = bp->pdev->irq;
Michael Chan78095922016-12-07 00:26:16 -05006025 return 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04006026}
6027
Michael Chan78095922016-12-07 00:26:16 -05006028static int bnxt_init_int_mode(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04006029{
6030 int rc = 0;
6031
6032 if (bp->flags & BNXT_FLAG_MSIX_CAP)
Michael Chan78095922016-12-07 00:26:16 -05006033 rc = bnxt_init_msix(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04006034
Michael Chan1fa72e22016-04-25 02:30:49 -04006035 if (!(bp->flags & BNXT_FLAG_USING_MSIX) && BNXT_PF(bp)) {
Michael Chanc0c050c2015-10-22 16:01:17 -04006036 /* fallback to INTA */
Michael Chan78095922016-12-07 00:26:16 -05006037 rc = bnxt_init_inta(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04006038 }
6039 return rc;
6040}
6041
Michael Chan78095922016-12-07 00:26:16 -05006042static void bnxt_clear_int_mode(struct bnxt *bp)
6043{
6044 if (bp->flags & BNXT_FLAG_USING_MSIX)
6045 pci_disable_msix(bp->pdev);
6046
6047 kfree(bp->irq_tbl);
6048 bp->irq_tbl = NULL;
6049 bp->flags &= ~BNXT_FLAG_USING_MSIX;
6050}
6051
Michael Chanfbcfc8e2018-03-31 13:54:20 -04006052int bnxt_reserve_rings(struct bnxt *bp)
Michael Chan674f50a2018-01-17 03:21:09 -05006053{
Michael Chan674f50a2018-01-17 03:21:09 -05006054 int tcs = netdev_get_num_tc(bp->dev);
6055 int rc;
6056
6057 if (!bnxt_need_reserve_rings(bp))
6058 return 0;
6059
6060 rc = __bnxt_reserve_rings(bp);
6061 if (rc) {
6062 netdev_err(bp->dev, "ring reservation failure rc: %d\n", rc);
6063 return rc;
6064 }
Michael Chanfbcfc8e2018-03-31 13:54:20 -04006065 if ((bp->flags & BNXT_FLAG_NEW_RM) &&
6066 (bnxt_get_num_msix(bp) != bp->total_irqs)) {
Michael Chanec86f142018-03-31 13:54:21 -04006067 bnxt_ulp_irq_stop(bp);
Michael Chan674f50a2018-01-17 03:21:09 -05006068 bnxt_clear_int_mode(bp);
6069 rc = bnxt_init_int_mode(bp);
Michael Chanec86f142018-03-31 13:54:21 -04006070 bnxt_ulp_irq_restart(bp, rc);
Michael Chan674f50a2018-01-17 03:21:09 -05006071 if (rc)
6072 return rc;
6073 }
6074 if (tcs && (bp->tx_nr_rings_per_tc * tcs != bp->tx_nr_rings)) {
6075 netdev_err(bp->dev, "tx ring reservation failure\n");
6076 netdev_reset_tc(bp->dev);
6077 bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
6078 return -ENOMEM;
6079 }
6080 bp->num_stat_ctxs = bp->cp_nr_rings;
6081 return 0;
6082}
6083
Michael Chanc0c050c2015-10-22 16:01:17 -04006084static void bnxt_free_irq(struct bnxt *bp)
6085{
6086 struct bnxt_irq *irq;
6087 int i;
6088
6089#ifdef CONFIG_RFS_ACCEL
6090 free_irq_cpu_rmap(bp->dev->rx_cpu_rmap);
6091 bp->dev->rx_cpu_rmap = NULL;
6092#endif
6093 if (!bp->irq_tbl)
6094 return;
6095
6096 for (i = 0; i < bp->cp_nr_rings; i++) {
Michael Chane5811b82018-03-31 13:54:18 -04006097 int map_idx = bnxt_cp_num_to_irq_num(bp, i);
6098
6099 irq = &bp->irq_tbl[map_idx];
Vasundhara Volam56f0fd82017-08-28 13:40:27 -04006100 if (irq->requested) {
6101 if (irq->have_cpumask) {
6102 irq_set_affinity_hint(irq->vector, NULL);
6103 free_cpumask_var(irq->cpu_mask);
6104 irq->have_cpumask = 0;
6105 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006106 free_irq(irq->vector, bp->bnapi[i]);
Vasundhara Volam56f0fd82017-08-28 13:40:27 -04006107 }
6108
Michael Chanc0c050c2015-10-22 16:01:17 -04006109 irq->requested = 0;
6110 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006111}
6112
6113static int bnxt_request_irq(struct bnxt *bp)
6114{
Michael Chanb81a90d2016-01-02 23:45:01 -05006115 int i, j, rc = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04006116 unsigned long flags = 0;
6117#ifdef CONFIG_RFS_ACCEL
Michael Chane5811b82018-03-31 13:54:18 -04006118 struct cpu_rmap *rmap;
Michael Chanc0c050c2015-10-22 16:01:17 -04006119#endif
6120
Michael Chane5811b82018-03-31 13:54:18 -04006121 rc = bnxt_setup_int_mode(bp);
6122 if (rc) {
6123 netdev_err(bp->dev, "bnxt_setup_int_mode err: %x\n",
6124 rc);
6125 return rc;
6126 }
6127#ifdef CONFIG_RFS_ACCEL
6128 rmap = bp->dev->rx_cpu_rmap;
6129#endif
Michael Chanc0c050c2015-10-22 16:01:17 -04006130 if (!(bp->flags & BNXT_FLAG_USING_MSIX))
6131 flags = IRQF_SHARED;
6132
Michael Chanb81a90d2016-01-02 23:45:01 -05006133 for (i = 0, j = 0; i < bp->cp_nr_rings; i++) {
Michael Chane5811b82018-03-31 13:54:18 -04006134 int map_idx = bnxt_cp_num_to_irq_num(bp, i);
6135 struct bnxt_irq *irq = &bp->irq_tbl[map_idx];
6136
Michael Chanc0c050c2015-10-22 16:01:17 -04006137#ifdef CONFIG_RFS_ACCEL
Michael Chanb81a90d2016-01-02 23:45:01 -05006138 if (rmap && bp->bnapi[i]->rx_ring) {
Michael Chanc0c050c2015-10-22 16:01:17 -04006139 rc = irq_cpu_rmap_add(rmap, irq->vector);
6140 if (rc)
6141 netdev_warn(bp->dev, "failed adding irq rmap for ring %d\n",
Michael Chanb81a90d2016-01-02 23:45:01 -05006142 j);
6143 j++;
Michael Chanc0c050c2015-10-22 16:01:17 -04006144 }
6145#endif
6146 rc = request_irq(irq->vector, irq->handler, flags, irq->name,
6147 bp->bnapi[i]);
6148 if (rc)
6149 break;
6150
6151 irq->requested = 1;
Vasundhara Volam56f0fd82017-08-28 13:40:27 -04006152
6153 if (zalloc_cpumask_var(&irq->cpu_mask, GFP_KERNEL)) {
6154 int numa_node = dev_to_node(&bp->pdev->dev);
6155
6156 irq->have_cpumask = 1;
6157 cpumask_set_cpu(cpumask_local_spread(i, numa_node),
6158 irq->cpu_mask);
6159 rc = irq_set_affinity_hint(irq->vector, irq->cpu_mask);
6160 if (rc) {
6161 netdev_warn(bp->dev,
6162 "Set affinity failed, IRQ = %d\n",
6163 irq->vector);
6164 break;
6165 }
6166 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006167 }
6168 return rc;
6169}
6170
6171static void bnxt_del_napi(struct bnxt *bp)
6172{
6173 int i;
6174
6175 if (!bp->bnapi)
6176 return;
6177
6178 for (i = 0; i < bp->cp_nr_rings; i++) {
6179 struct bnxt_napi *bnapi = bp->bnapi[i];
6180
6181 napi_hash_del(&bnapi->napi);
6182 netif_napi_del(&bnapi->napi);
6183 }
Eric Dumazete5f6f562016-11-16 06:31:52 -08006184 /* We called napi_hash_del() before netif_napi_del(), we need
6185 * to respect an RCU grace period before freeing napi structures.
6186 */
6187 synchronize_net();
Michael Chanc0c050c2015-10-22 16:01:17 -04006188}
6189
6190static void bnxt_init_napi(struct bnxt *bp)
6191{
6192 int i;
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04006193 unsigned int cp_nr_rings = bp->cp_nr_rings;
Michael Chanc0c050c2015-10-22 16:01:17 -04006194 struct bnxt_napi *bnapi;
6195
6196 if (bp->flags & BNXT_FLAG_USING_MSIX) {
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04006197 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
6198 cp_nr_rings--;
6199 for (i = 0; i < cp_nr_rings; i++) {
Michael Chanc0c050c2015-10-22 16:01:17 -04006200 bnapi = bp->bnapi[i];
6201 netif_napi_add(bp->dev, &bnapi->napi,
6202 bnxt_poll, 64);
Michael Chanc0c050c2015-10-22 16:01:17 -04006203 }
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04006204 if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
6205 bnapi = bp->bnapi[cp_nr_rings];
6206 netif_napi_add(bp->dev, &bnapi->napi,
6207 bnxt_poll_nitroa0, 64);
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04006208 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006209 } else {
6210 bnapi = bp->bnapi[0];
6211 netif_napi_add(bp->dev, &bnapi->napi, bnxt_poll, 64);
Michael Chanc0c050c2015-10-22 16:01:17 -04006212 }
6213}
6214
6215static void bnxt_disable_napi(struct bnxt *bp)
6216{
6217 int i;
6218
6219 if (!bp->bnapi)
6220 return;
6221
Andy Gospodarek0bc0b972018-01-26 10:27:47 -05006222 for (i = 0; i < bp->cp_nr_rings; i++) {
6223 struct bnxt_cp_ring_info *cpr = &bp->bnapi[i]->cp_ring;
6224
6225 if (bp->bnapi[i]->rx_ring)
6226 cancel_work_sync(&cpr->dim.work);
6227
Michael Chanc0c050c2015-10-22 16:01:17 -04006228 napi_disable(&bp->bnapi[i]->napi);
Andy Gospodarek0bc0b972018-01-26 10:27:47 -05006229 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006230}
6231
6232static void bnxt_enable_napi(struct bnxt *bp)
6233{
6234 int i;
6235
6236 for (i = 0; i < bp->cp_nr_rings; i++) {
Andy Gospodarek6a8788f2018-01-09 16:06:20 -05006237 struct bnxt_cp_ring_info *cpr = &bp->bnapi[i]->cp_ring;
Michael Chanfa7e2812016-05-10 19:18:00 -04006238 bp->bnapi[i]->in_reset = false;
Andy Gospodarek6a8788f2018-01-09 16:06:20 -05006239
6240 if (bp->bnapi[i]->rx_ring) {
6241 INIT_WORK(&cpr->dim.work, bnxt_dim_work);
6242 cpr->dim.mode = NET_DIM_CQ_PERIOD_MODE_START_FROM_EQE;
6243 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006244 napi_enable(&bp->bnapi[i]->napi);
6245 }
6246}
6247
Michael Chan7df4ae92016-12-02 21:17:17 -05006248void bnxt_tx_disable(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04006249{
6250 int i;
Michael Chanc0c050c2015-10-22 16:01:17 -04006251 struct bnxt_tx_ring_info *txr;
Michael Chanc0c050c2015-10-22 16:01:17 -04006252
Michael Chanb6ab4b02016-01-02 23:44:59 -05006253 if (bp->tx_ring) {
Michael Chanc0c050c2015-10-22 16:01:17 -04006254 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05006255 txr = &bp->tx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04006256 txr->dev_state = BNXT_DEV_STATE_CLOSING;
Michael Chanc0c050c2015-10-22 16:01:17 -04006257 }
6258 }
6259 /* Stop all TX queues */
6260 netif_tx_disable(bp->dev);
6261 netif_carrier_off(bp->dev);
6262}
6263
Michael Chan7df4ae92016-12-02 21:17:17 -05006264void bnxt_tx_enable(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04006265{
6266 int i;
Michael Chanc0c050c2015-10-22 16:01:17 -04006267 struct bnxt_tx_ring_info *txr;
Michael Chanc0c050c2015-10-22 16:01:17 -04006268
6269 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05006270 txr = &bp->tx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04006271 txr->dev_state = 0;
6272 }
6273 netif_tx_wake_all_queues(bp->dev);
6274 if (bp->link_info.link_up)
6275 netif_carrier_on(bp->dev);
6276}
6277
6278static void bnxt_report_link(struct bnxt *bp)
6279{
6280 if (bp->link_info.link_up) {
6281 const char *duplex;
6282 const char *flow_ctrl;
Deepak Khungar38a21b32017-04-21 20:11:24 -04006283 u32 speed;
6284 u16 fec;
Michael Chanc0c050c2015-10-22 16:01:17 -04006285
6286 netif_carrier_on(bp->dev);
6287 if (bp->link_info.duplex == BNXT_LINK_DUPLEX_FULL)
6288 duplex = "full";
6289 else
6290 duplex = "half";
6291 if (bp->link_info.pause == BNXT_LINK_PAUSE_BOTH)
6292 flow_ctrl = "ON - receive & transmit";
6293 else if (bp->link_info.pause == BNXT_LINK_PAUSE_TX)
6294 flow_ctrl = "ON - transmit";
6295 else if (bp->link_info.pause == BNXT_LINK_PAUSE_RX)
6296 flow_ctrl = "ON - receive";
6297 else
6298 flow_ctrl = "none";
6299 speed = bnxt_fw_to_ethtool_speed(bp->link_info.link_speed);
Deepak Khungar38a21b32017-04-21 20:11:24 -04006300 netdev_info(bp->dev, "NIC Link is Up, %u Mbps %s duplex, Flow control: %s\n",
Michael Chanc0c050c2015-10-22 16:01:17 -04006301 speed, duplex, flow_ctrl);
Michael Chan170ce012016-04-05 14:08:57 -04006302 if (bp->flags & BNXT_FLAG_EEE_CAP)
6303 netdev_info(bp->dev, "EEE is %s\n",
6304 bp->eee.eee_active ? "active" :
6305 "not active");
Michael Chane70c7522017-02-12 19:18:16 -05006306 fec = bp->link_info.fec_cfg;
6307 if (!(fec & PORT_PHY_QCFG_RESP_FEC_CFG_FEC_NONE_SUPPORTED))
6308 netdev_info(bp->dev, "FEC autoneg %s encodings: %s\n",
6309 (fec & BNXT_FEC_AUTONEG) ? "on" : "off",
6310 (fec & BNXT_FEC_ENC_BASE_R) ? "BaseR" :
6311 (fec & BNXT_FEC_ENC_RS) ? "RS" : "None");
Michael Chanc0c050c2015-10-22 16:01:17 -04006312 } else {
6313 netif_carrier_off(bp->dev);
6314 netdev_err(bp->dev, "NIC Link is Down\n");
6315 }
6316}
6317
Michael Chan170ce012016-04-05 14:08:57 -04006318static int bnxt_hwrm_phy_qcaps(struct bnxt *bp)
6319{
6320 int rc = 0;
6321 struct hwrm_port_phy_qcaps_input req = {0};
6322 struct hwrm_port_phy_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
Michael Chan93ed8112016-06-13 02:25:37 -04006323 struct bnxt_link_info *link_info = &bp->link_info;
Michael Chan170ce012016-04-05 14:08:57 -04006324
6325 if (bp->hwrm_spec_code < 0x10201)
6326 return 0;
6327
6328 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCAPS, -1, -1);
6329
6330 mutex_lock(&bp->hwrm_cmd_lock);
6331 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6332 if (rc)
6333 goto hwrm_phy_qcaps_exit;
6334
Michael Chanacb20052017-07-24 12:34:20 -04006335 if (resp->flags & PORT_PHY_QCAPS_RESP_FLAGS_EEE_SUPPORTED) {
Michael Chan170ce012016-04-05 14:08:57 -04006336 struct ethtool_eee *eee = &bp->eee;
6337 u16 fw_speeds = le16_to_cpu(resp->supported_speeds_eee_mode);
6338
6339 bp->flags |= BNXT_FLAG_EEE_CAP;
6340 eee->supported = _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0);
6341 bp->lpi_tmr_lo = le32_to_cpu(resp->tx_lpi_timer_low) &
6342 PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_LOW_MASK;
6343 bp->lpi_tmr_hi = le32_to_cpu(resp->valid_tx_lpi_timer_high) &
6344 PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_HIGH_MASK;
6345 }
Michael Chan520ad892017-03-08 18:44:35 -05006346 if (resp->supported_speeds_auto_mode)
6347 link_info->support_auto_speeds =
6348 le16_to_cpu(resp->supported_speeds_auto_mode);
Michael Chan170ce012016-04-05 14:08:57 -04006349
Michael Chand5430d32017-08-28 13:40:31 -04006350 bp->port_count = resp->port_cnt;
6351
Michael Chan170ce012016-04-05 14:08:57 -04006352hwrm_phy_qcaps_exit:
6353 mutex_unlock(&bp->hwrm_cmd_lock);
6354 return rc;
6355}
6356
Michael Chanc0c050c2015-10-22 16:01:17 -04006357static int bnxt_update_link(struct bnxt *bp, bool chng_link_state)
6358{
6359 int rc = 0;
6360 struct bnxt_link_info *link_info = &bp->link_info;
6361 struct hwrm_port_phy_qcfg_input req = {0};
6362 struct hwrm_port_phy_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
6363 u8 link_up = link_info->link_up;
Michael Chan286ef9d2016-11-16 21:13:08 -05006364 u16 diff;
Michael Chanc0c050c2015-10-22 16:01:17 -04006365
6366 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCFG, -1, -1);
6367
6368 mutex_lock(&bp->hwrm_cmd_lock);
6369 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6370 if (rc) {
6371 mutex_unlock(&bp->hwrm_cmd_lock);
6372 return rc;
6373 }
6374
6375 memcpy(&link_info->phy_qcfg_resp, resp, sizeof(*resp));
6376 link_info->phy_link_status = resp->link;
Michael Chanacb20052017-07-24 12:34:20 -04006377 link_info->duplex = resp->duplex_cfg;
6378 if (bp->hwrm_spec_code >= 0x10800)
6379 link_info->duplex = resp->duplex_state;
Michael Chanc0c050c2015-10-22 16:01:17 -04006380 link_info->pause = resp->pause;
6381 link_info->auto_mode = resp->auto_mode;
6382 link_info->auto_pause_setting = resp->auto_pause;
Michael Chan32773602016-03-07 15:38:42 -05006383 link_info->lp_pause = resp->link_partner_adv_pause;
Michael Chanc0c050c2015-10-22 16:01:17 -04006384 link_info->force_pause_setting = resp->force_pause;
Michael Chanacb20052017-07-24 12:34:20 -04006385 link_info->duplex_setting = resp->duplex_cfg;
Michael Chanc0c050c2015-10-22 16:01:17 -04006386 if (link_info->phy_link_status == BNXT_LINK_LINK)
6387 link_info->link_speed = le16_to_cpu(resp->link_speed);
6388 else
6389 link_info->link_speed = 0;
6390 link_info->force_link_speed = le16_to_cpu(resp->force_link_speed);
Michael Chanc0c050c2015-10-22 16:01:17 -04006391 link_info->support_speeds = le16_to_cpu(resp->support_speeds);
6392 link_info->auto_link_speeds = le16_to_cpu(resp->auto_link_speed_mask);
Michael Chan32773602016-03-07 15:38:42 -05006393 link_info->lp_auto_link_speeds =
6394 le16_to_cpu(resp->link_partner_adv_speeds);
Michael Chanc0c050c2015-10-22 16:01:17 -04006395 link_info->preemphasis = le32_to_cpu(resp->preemphasis);
6396 link_info->phy_ver[0] = resp->phy_maj;
6397 link_info->phy_ver[1] = resp->phy_min;
6398 link_info->phy_ver[2] = resp->phy_bld;
6399 link_info->media_type = resp->media_type;
Michael Chan03efbec2016-04-11 04:11:11 -04006400 link_info->phy_type = resp->phy_type;
Michael Chan11f15ed2016-04-05 14:08:55 -04006401 link_info->transceiver = resp->xcvr_pkg_type;
Michael Chan170ce012016-04-05 14:08:57 -04006402 link_info->phy_addr = resp->eee_config_phy_addr &
6403 PORT_PHY_QCFG_RESP_PHY_ADDR_MASK;
Ajit Khaparde42ee18f2016-05-15 03:04:44 -04006404 link_info->module_status = resp->module_status;
Michael Chanc0c050c2015-10-22 16:01:17 -04006405
Michael Chan170ce012016-04-05 14:08:57 -04006406 if (bp->flags & BNXT_FLAG_EEE_CAP) {
6407 struct ethtool_eee *eee = &bp->eee;
6408 u16 fw_speeds;
6409
6410 eee->eee_active = 0;
6411 if (resp->eee_config_phy_addr &
6412 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ACTIVE) {
6413 eee->eee_active = 1;
6414 fw_speeds = le16_to_cpu(
6415 resp->link_partner_adv_eee_link_speed_mask);
6416 eee->lp_advertised =
6417 _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0);
6418 }
6419
6420 /* Pull initial EEE config */
6421 if (!chng_link_state) {
6422 if (resp->eee_config_phy_addr &
6423 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ENABLED)
6424 eee->eee_enabled = 1;
6425
6426 fw_speeds = le16_to_cpu(resp->adv_eee_link_speed_mask);
6427 eee->advertised =
6428 _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0);
6429
6430 if (resp->eee_config_phy_addr &
6431 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_TX_LPI) {
6432 __le32 tmr;
6433
6434 eee->tx_lpi_enabled = 1;
6435 tmr = resp->xcvr_identifier_type_tx_lpi_timer;
6436 eee->tx_lpi_timer = le32_to_cpu(tmr) &
6437 PORT_PHY_QCFG_RESP_TX_LPI_TIMER_MASK;
6438 }
6439 }
6440 }
Michael Chane70c7522017-02-12 19:18:16 -05006441
6442 link_info->fec_cfg = PORT_PHY_QCFG_RESP_FEC_CFG_FEC_NONE_SUPPORTED;
6443 if (bp->hwrm_spec_code >= 0x10504)
6444 link_info->fec_cfg = le16_to_cpu(resp->fec_cfg);
6445
Michael Chanc0c050c2015-10-22 16:01:17 -04006446 /* TODO: need to add more logic to report VF link */
6447 if (chng_link_state) {
6448 if (link_info->phy_link_status == BNXT_LINK_LINK)
6449 link_info->link_up = 1;
6450 else
6451 link_info->link_up = 0;
6452 if (link_up != link_info->link_up)
6453 bnxt_report_link(bp);
6454 } else {
6455 /* alwasy link down if not require to update link state */
6456 link_info->link_up = 0;
6457 }
6458 mutex_unlock(&bp->hwrm_cmd_lock);
Michael Chan286ef9d2016-11-16 21:13:08 -05006459
6460 diff = link_info->support_auto_speeds ^ link_info->advertising;
6461 if ((link_info->support_auto_speeds | diff) !=
6462 link_info->support_auto_speeds) {
6463 /* An advertised speed is no longer supported, so we need to
Michael Chan0eaa24b2017-01-25 02:55:08 -05006464 * update the advertisement settings. Caller holds RTNL
6465 * so we can modify link settings.
Michael Chan286ef9d2016-11-16 21:13:08 -05006466 */
Michael Chan286ef9d2016-11-16 21:13:08 -05006467 link_info->advertising = link_info->support_auto_speeds;
Michael Chan0eaa24b2017-01-25 02:55:08 -05006468 if (link_info->autoneg & BNXT_AUTONEG_SPEED)
Michael Chan286ef9d2016-11-16 21:13:08 -05006469 bnxt_hwrm_set_link_setting(bp, true, false);
Michael Chan286ef9d2016-11-16 21:13:08 -05006470 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006471 return 0;
6472}
6473
Michael Chan10289be2016-05-15 03:04:49 -04006474static void bnxt_get_port_module_status(struct bnxt *bp)
6475{
6476 struct bnxt_link_info *link_info = &bp->link_info;
6477 struct hwrm_port_phy_qcfg_output *resp = &link_info->phy_qcfg_resp;
6478 u8 module_status;
6479
6480 if (bnxt_update_link(bp, true))
6481 return;
6482
6483 module_status = link_info->module_status;
6484 switch (module_status) {
6485 case PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX:
6486 case PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN:
6487 case PORT_PHY_QCFG_RESP_MODULE_STATUS_WARNINGMSG:
6488 netdev_warn(bp->dev, "Unqualified SFP+ module detected on port %d\n",
6489 bp->pf.port_id);
6490 if (bp->hwrm_spec_code >= 0x10201) {
6491 netdev_warn(bp->dev, "Module part number %s\n",
6492 resp->phy_vendor_partnumber);
6493 }
6494 if (module_status == PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX)
6495 netdev_warn(bp->dev, "TX is disabled\n");
6496 if (module_status == PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN)
6497 netdev_warn(bp->dev, "SFP+ module is shutdown\n");
6498 }
6499}
6500
Michael Chanc0c050c2015-10-22 16:01:17 -04006501static void
6502bnxt_hwrm_set_pause_common(struct bnxt *bp, struct hwrm_port_phy_cfg_input *req)
6503{
6504 if (bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL) {
Michael Chanc9ee9512016-04-05 14:08:56 -04006505 if (bp->hwrm_spec_code >= 0x10201)
6506 req->auto_pause =
6507 PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE;
Michael Chanc0c050c2015-10-22 16:01:17 -04006508 if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_RX)
6509 req->auto_pause |= PORT_PHY_CFG_REQ_AUTO_PAUSE_RX;
6510 if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_TX)
Michael Chan49b5c7a2016-03-28 19:46:06 -04006511 req->auto_pause |= PORT_PHY_CFG_REQ_AUTO_PAUSE_TX;
Michael Chanc0c050c2015-10-22 16:01:17 -04006512 req->enables |=
6513 cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE);
6514 } else {
6515 if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_RX)
6516 req->force_pause |= PORT_PHY_CFG_REQ_FORCE_PAUSE_RX;
6517 if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_TX)
6518 req->force_pause |= PORT_PHY_CFG_REQ_FORCE_PAUSE_TX;
6519 req->enables |=
6520 cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_FORCE_PAUSE);
Michael Chanc9ee9512016-04-05 14:08:56 -04006521 if (bp->hwrm_spec_code >= 0x10201) {
6522 req->auto_pause = req->force_pause;
6523 req->enables |= cpu_to_le32(
6524 PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE);
6525 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006526 }
6527}
6528
6529static void bnxt_hwrm_set_link_common(struct bnxt *bp,
6530 struct hwrm_port_phy_cfg_input *req)
6531{
6532 u8 autoneg = bp->link_info.autoneg;
6533 u16 fw_link_speed = bp->link_info.req_link_speed;
Michael Chan68515a12016-12-29 12:13:34 -05006534 u16 advertising = bp->link_info.advertising;
Michael Chanc0c050c2015-10-22 16:01:17 -04006535
6536 if (autoneg & BNXT_AUTONEG_SPEED) {
6537 req->auto_mode |=
Michael Chan11f15ed2016-04-05 14:08:55 -04006538 PORT_PHY_CFG_REQ_AUTO_MODE_SPEED_MASK;
Michael Chanc0c050c2015-10-22 16:01:17 -04006539
6540 req->enables |= cpu_to_le32(
6541 PORT_PHY_CFG_REQ_ENABLES_AUTO_LINK_SPEED_MASK);
6542 req->auto_link_speed_mask = cpu_to_le16(advertising);
6543
6544 req->enables |= cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_MODE);
6545 req->flags |=
6546 cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESTART_AUTONEG);
6547 } else {
6548 req->force_link_speed = cpu_to_le16(fw_link_speed);
6549 req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE);
6550 }
6551
Michael Chanc0c050c2015-10-22 16:01:17 -04006552 /* tell chimp that the setting takes effect immediately */
6553 req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESET_PHY);
6554}
6555
6556int bnxt_hwrm_set_pause(struct bnxt *bp)
6557{
6558 struct hwrm_port_phy_cfg_input req = {0};
6559 int rc;
6560
6561 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1);
6562 bnxt_hwrm_set_pause_common(bp, &req);
6563
6564 if ((bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL) ||
6565 bp->link_info.force_link_chng)
6566 bnxt_hwrm_set_link_common(bp, &req);
6567
6568 mutex_lock(&bp->hwrm_cmd_lock);
6569 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6570 if (!rc && !(bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL)) {
6571 /* since changing of pause setting doesn't trigger any link
6572 * change event, the driver needs to update the current pause
6573 * result upon successfully return of the phy_cfg command
6574 */
6575 bp->link_info.pause =
6576 bp->link_info.force_pause_setting = bp->link_info.req_flow_ctrl;
6577 bp->link_info.auto_pause_setting = 0;
6578 if (!bp->link_info.force_link_chng)
6579 bnxt_report_link(bp);
6580 }
6581 bp->link_info.force_link_chng = false;
6582 mutex_unlock(&bp->hwrm_cmd_lock);
6583 return rc;
6584}
6585
Michael Chan939f7f02016-04-05 14:08:58 -04006586static void bnxt_hwrm_set_eee(struct bnxt *bp,
6587 struct hwrm_port_phy_cfg_input *req)
6588{
6589 struct ethtool_eee *eee = &bp->eee;
6590
6591 if (eee->eee_enabled) {
6592 u16 eee_speeds;
6593 u32 flags = PORT_PHY_CFG_REQ_FLAGS_EEE_ENABLE;
6594
6595 if (eee->tx_lpi_enabled)
6596 flags |= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_ENABLE;
6597 else
6598 flags |= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_DISABLE;
6599
6600 req->flags |= cpu_to_le32(flags);
6601 eee_speeds = bnxt_get_fw_auto_link_speeds(eee->advertised);
6602 req->eee_link_speed_mask = cpu_to_le16(eee_speeds);
6603 req->tx_lpi_timer = cpu_to_le32(eee->tx_lpi_timer);
6604 } else {
6605 req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_EEE_DISABLE);
6606 }
6607}
6608
6609int bnxt_hwrm_set_link_setting(struct bnxt *bp, bool set_pause, bool set_eee)
Michael Chanc0c050c2015-10-22 16:01:17 -04006610{
6611 struct hwrm_port_phy_cfg_input req = {0};
6612
6613 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1);
6614 if (set_pause)
6615 bnxt_hwrm_set_pause_common(bp, &req);
6616
6617 bnxt_hwrm_set_link_common(bp, &req);
Michael Chan939f7f02016-04-05 14:08:58 -04006618
6619 if (set_eee)
6620 bnxt_hwrm_set_eee(bp, &req);
Michael Chanc0c050c2015-10-22 16:01:17 -04006621 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6622}
6623
Michael Chan33f7d552016-04-11 04:11:12 -04006624static int bnxt_hwrm_shutdown_link(struct bnxt *bp)
6625{
6626 struct hwrm_port_phy_cfg_input req = {0};
6627
Satish Baddipadige567b2ab2016-06-13 02:25:31 -04006628 if (!BNXT_SINGLE_PF(bp))
Michael Chan33f7d552016-04-11 04:11:12 -04006629 return 0;
6630
6631 if (pci_num_vf(bp->pdev))
6632 return 0;
6633
6634 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1);
Michael Chan16d663a2016-11-16 21:13:07 -05006635 req.flags = cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE_LINK_DWN);
Michael Chan33f7d552016-04-11 04:11:12 -04006636 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6637}
6638
Michael Chan5ad2cbe2017-01-13 01:32:03 -05006639static int bnxt_hwrm_port_led_qcaps(struct bnxt *bp)
6640{
6641 struct hwrm_port_led_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
6642 struct hwrm_port_led_qcaps_input req = {0};
6643 struct bnxt_pf_info *pf = &bp->pf;
6644 int rc;
6645
6646 if (BNXT_VF(bp) || bp->hwrm_spec_code < 0x10601)
6647 return 0;
6648
6649 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_LED_QCAPS, -1, -1);
6650 req.port_id = cpu_to_le16(pf->port_id);
6651 mutex_lock(&bp->hwrm_cmd_lock);
6652 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6653 if (rc) {
6654 mutex_unlock(&bp->hwrm_cmd_lock);
6655 return rc;
6656 }
6657 if (resp->num_leds > 0 && resp->num_leds < BNXT_MAX_LED) {
6658 int i;
6659
6660 bp->num_leds = resp->num_leds;
6661 memcpy(bp->leds, &resp->led0_id, sizeof(bp->leds[0]) *
6662 bp->num_leds);
6663 for (i = 0; i < bp->num_leds; i++) {
6664 struct bnxt_led_info *led = &bp->leds[i];
6665 __le16 caps = led->led_state_caps;
6666
6667 if (!led->led_group_id ||
6668 !BNXT_LED_ALT_BLINK_CAP(caps)) {
6669 bp->num_leds = 0;
6670 break;
6671 }
6672 }
6673 }
6674 mutex_unlock(&bp->hwrm_cmd_lock);
6675 return 0;
6676}
6677
Michael Chan5282db62017-04-04 18:14:10 -04006678int bnxt_hwrm_alloc_wol_fltr(struct bnxt *bp)
6679{
6680 struct hwrm_wol_filter_alloc_input req = {0};
6681 struct hwrm_wol_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr;
6682 int rc;
6683
6684 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_WOL_FILTER_ALLOC, -1, -1);
6685 req.port_id = cpu_to_le16(bp->pf.port_id);
6686 req.wol_type = WOL_FILTER_ALLOC_REQ_WOL_TYPE_MAGICPKT;
6687 req.enables = cpu_to_le32(WOL_FILTER_ALLOC_REQ_ENABLES_MAC_ADDRESS);
6688 memcpy(req.mac_address, bp->dev->dev_addr, ETH_ALEN);
6689 mutex_lock(&bp->hwrm_cmd_lock);
6690 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6691 if (!rc)
6692 bp->wol_filter_id = resp->wol_filter_id;
6693 mutex_unlock(&bp->hwrm_cmd_lock);
6694 return rc;
6695}
6696
6697int bnxt_hwrm_free_wol_fltr(struct bnxt *bp)
6698{
6699 struct hwrm_wol_filter_free_input req = {0};
6700 int rc;
6701
6702 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_WOL_FILTER_FREE, -1, -1);
6703 req.port_id = cpu_to_le16(bp->pf.port_id);
6704 req.enables = cpu_to_le32(WOL_FILTER_FREE_REQ_ENABLES_WOL_FILTER_ID);
6705 req.wol_filter_id = bp->wol_filter_id;
6706 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6707 return rc;
6708}
6709
Michael Chanc1ef1462017-04-04 18:14:07 -04006710static u16 bnxt_hwrm_get_wol_fltrs(struct bnxt *bp, u16 handle)
6711{
6712 struct hwrm_wol_filter_qcfg_input req = {0};
6713 struct hwrm_wol_filter_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
6714 u16 next_handle = 0;
6715 int rc;
6716
6717 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_WOL_FILTER_QCFG, -1, -1);
6718 req.port_id = cpu_to_le16(bp->pf.port_id);
6719 req.handle = cpu_to_le16(handle);
6720 mutex_lock(&bp->hwrm_cmd_lock);
6721 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6722 if (!rc) {
6723 next_handle = le16_to_cpu(resp->next_handle);
6724 if (next_handle != 0) {
6725 if (resp->wol_type ==
6726 WOL_FILTER_ALLOC_REQ_WOL_TYPE_MAGICPKT) {
6727 bp->wol = 1;
6728 bp->wol_filter_id = resp->wol_filter_id;
6729 }
6730 }
6731 }
6732 mutex_unlock(&bp->hwrm_cmd_lock);
6733 return next_handle;
6734}
6735
6736static void bnxt_get_wol_settings(struct bnxt *bp)
6737{
6738 u16 handle = 0;
6739
6740 if (!BNXT_PF(bp) || !(bp->flags & BNXT_FLAG_WOL_CAP))
6741 return;
6742
6743 do {
6744 handle = bnxt_hwrm_get_wol_fltrs(bp, handle);
6745 } while (handle && handle != 0xffff);
6746}
6747
Michael Chan939f7f02016-04-05 14:08:58 -04006748static bool bnxt_eee_config_ok(struct bnxt *bp)
6749{
6750 struct ethtool_eee *eee = &bp->eee;
6751 struct bnxt_link_info *link_info = &bp->link_info;
6752
6753 if (!(bp->flags & BNXT_FLAG_EEE_CAP))
6754 return true;
6755
6756 if (eee->eee_enabled) {
6757 u32 advertising =
6758 _bnxt_fw_to_ethtool_adv_spds(link_info->advertising, 0);
6759
6760 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) {
6761 eee->eee_enabled = 0;
6762 return false;
6763 }
6764 if (eee->advertised & ~advertising) {
6765 eee->advertised = advertising & eee->supported;
6766 return false;
6767 }
6768 }
6769 return true;
6770}
6771
Michael Chanc0c050c2015-10-22 16:01:17 -04006772static int bnxt_update_phy_setting(struct bnxt *bp)
6773{
6774 int rc;
6775 bool update_link = false;
6776 bool update_pause = false;
Michael Chan939f7f02016-04-05 14:08:58 -04006777 bool update_eee = false;
Michael Chanc0c050c2015-10-22 16:01:17 -04006778 struct bnxt_link_info *link_info = &bp->link_info;
6779
6780 rc = bnxt_update_link(bp, true);
6781 if (rc) {
6782 netdev_err(bp->dev, "failed to update link (rc: %x)\n",
6783 rc);
6784 return rc;
6785 }
Michael Chan33dac242017-02-12 19:18:15 -05006786 if (!BNXT_SINGLE_PF(bp))
6787 return 0;
6788
Michael Chanc0c050c2015-10-22 16:01:17 -04006789 if ((link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) &&
Michael Chanc9ee9512016-04-05 14:08:56 -04006790 (link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH) !=
6791 link_info->req_flow_ctrl)
Michael Chanc0c050c2015-10-22 16:01:17 -04006792 update_pause = true;
6793 if (!(link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) &&
6794 link_info->force_pause_setting != link_info->req_flow_ctrl)
6795 update_pause = true;
Michael Chanc0c050c2015-10-22 16:01:17 -04006796 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) {
6797 if (BNXT_AUTO_MODE(link_info->auto_mode))
6798 update_link = true;
6799 if (link_info->req_link_speed != link_info->force_link_speed)
6800 update_link = true;
Michael Chande730182016-02-19 19:43:20 -05006801 if (link_info->req_duplex != link_info->duplex_setting)
6802 update_link = true;
Michael Chanc0c050c2015-10-22 16:01:17 -04006803 } else {
6804 if (link_info->auto_mode == BNXT_LINK_AUTO_NONE)
6805 update_link = true;
6806 if (link_info->advertising != link_info->auto_link_speeds)
6807 update_link = true;
Michael Chanc0c050c2015-10-22 16:01:17 -04006808 }
6809
Michael Chan16d663a2016-11-16 21:13:07 -05006810 /* The last close may have shutdown the link, so need to call
6811 * PHY_CFG to bring it back up.
6812 */
6813 if (!netif_carrier_ok(bp->dev))
6814 update_link = true;
6815
Michael Chan939f7f02016-04-05 14:08:58 -04006816 if (!bnxt_eee_config_ok(bp))
6817 update_eee = true;
6818
Michael Chanc0c050c2015-10-22 16:01:17 -04006819 if (update_link)
Michael Chan939f7f02016-04-05 14:08:58 -04006820 rc = bnxt_hwrm_set_link_setting(bp, update_pause, update_eee);
Michael Chanc0c050c2015-10-22 16:01:17 -04006821 else if (update_pause)
6822 rc = bnxt_hwrm_set_pause(bp);
6823 if (rc) {
6824 netdev_err(bp->dev, "failed to update phy setting (rc: %x)\n",
6825 rc);
6826 return rc;
6827 }
6828
6829 return rc;
6830}
6831
Jeffrey Huang11809492015-11-05 16:25:49 -05006832/* Common routine to pre-map certain register block to different GRC window.
6833 * A PF has 16 4K windows and a VF has 4 4K windows. However, only 15 windows
6834 * in PF and 3 windows in VF that can be customized to map in different
6835 * register blocks.
6836 */
6837static void bnxt_preset_reg_win(struct bnxt *bp)
6838{
6839 if (BNXT_PF(bp)) {
6840 /* CAG registers map to GRC window #4 */
6841 writel(BNXT_CAG_REG_BASE,
6842 bp->bar0 + BNXT_GRCPF_REG_WINDOW_BASE_OUT + 12);
6843 }
6844}
6845
Michael Chanc0c050c2015-10-22 16:01:17 -04006846static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
6847{
6848 int rc = 0;
6849
Jeffrey Huang11809492015-11-05 16:25:49 -05006850 bnxt_preset_reg_win(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04006851 netif_carrier_off(bp->dev);
6852 if (irq_re_init) {
Michael Chan674f50a2018-01-17 03:21:09 -05006853 rc = bnxt_reserve_rings(bp);
6854 if (rc)
6855 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04006856 }
6857 if ((bp->flags & BNXT_FLAG_RFS) &&
6858 !(bp->flags & BNXT_FLAG_USING_MSIX)) {
6859 /* disable RFS if falling back to INTA */
6860 bp->dev->hw_features &= ~NETIF_F_NTUPLE;
6861 bp->flags &= ~BNXT_FLAG_RFS;
6862 }
6863
6864 rc = bnxt_alloc_mem(bp, irq_re_init);
6865 if (rc) {
6866 netdev_err(bp->dev, "bnxt_alloc_mem err: %x\n", rc);
6867 goto open_err_free_mem;
6868 }
6869
6870 if (irq_re_init) {
6871 bnxt_init_napi(bp);
6872 rc = bnxt_request_irq(bp);
6873 if (rc) {
6874 netdev_err(bp->dev, "bnxt_request_irq err: %x\n", rc);
6875 goto open_err;
6876 }
6877 }
6878
6879 bnxt_enable_napi(bp);
6880
6881 rc = bnxt_init_nic(bp, irq_re_init);
6882 if (rc) {
6883 netdev_err(bp->dev, "bnxt_init_nic err: %x\n", rc);
6884 goto open_err;
6885 }
6886
6887 if (link_re_init) {
Michael Chane2dc9b62017-10-13 21:09:30 -04006888 mutex_lock(&bp->link_lock);
Michael Chanc0c050c2015-10-22 16:01:17 -04006889 rc = bnxt_update_phy_setting(bp);
Michael Chane2dc9b62017-10-13 21:09:30 -04006890 mutex_unlock(&bp->link_lock);
Michael Chanc0c050c2015-10-22 16:01:17 -04006891 if (rc)
Michael Chanba41d462016-02-19 19:43:21 -05006892 netdev_warn(bp->dev, "failed to update phy settings\n");
Michael Chanc0c050c2015-10-22 16:01:17 -04006893 }
6894
Alexander Duyck7cdd5fc2016-06-16 12:21:36 -07006895 if (irq_re_init)
Alexander Duyckad51b8e2016-06-16 12:21:19 -07006896 udp_tunnel_get_rx_info(bp->dev);
Michael Chanc0c050c2015-10-22 16:01:17 -04006897
Michael Chancaefe522015-12-09 19:35:42 -05006898 set_bit(BNXT_STATE_OPEN, &bp->state);
Michael Chanc0c050c2015-10-22 16:01:17 -04006899 bnxt_enable_int(bp);
6900 /* Enable TX queues */
6901 bnxt_tx_enable(bp);
6902 mod_timer(&bp->timer, jiffies + bp->current_interval);
Michael Chan10289be2016-05-15 03:04:49 -04006903 /* Poll link status and check for SFP+ module status */
6904 bnxt_get_port_module_status(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04006905
Sathya Perlaee5c7fb2017-07-24 12:34:28 -04006906 /* VF-reps may need to be re-opened after the PF is re-opened */
6907 if (BNXT_PF(bp))
6908 bnxt_vf_reps_open(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04006909 return 0;
6910
6911open_err:
6912 bnxt_disable_napi(bp);
6913 bnxt_del_napi(bp);
6914
6915open_err_free_mem:
6916 bnxt_free_skbs(bp);
6917 bnxt_free_irq(bp);
6918 bnxt_free_mem(bp, true);
6919 return rc;
6920}
6921
6922/* rtnl_lock held */
6923int bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
6924{
6925 int rc = 0;
6926
6927 rc = __bnxt_open_nic(bp, irq_re_init, link_re_init);
6928 if (rc) {
6929 netdev_err(bp->dev, "nic open fail (rc: %x)\n", rc);
6930 dev_close(bp->dev);
6931 }
6932 return rc;
6933}
6934
Michael Chanf7dc1ea2017-04-04 18:14:13 -04006935/* rtnl_lock held, open the NIC half way by allocating all resources, but
6936 * NAPI, IRQ, and TX are not enabled. This is mainly used for offline
6937 * self tests.
6938 */
6939int bnxt_half_open_nic(struct bnxt *bp)
6940{
6941 int rc = 0;
6942
6943 rc = bnxt_alloc_mem(bp, false);
6944 if (rc) {
6945 netdev_err(bp->dev, "bnxt_alloc_mem err: %x\n", rc);
6946 goto half_open_err;
6947 }
6948 rc = bnxt_init_nic(bp, false);
6949 if (rc) {
6950 netdev_err(bp->dev, "bnxt_init_nic err: %x\n", rc);
6951 goto half_open_err;
6952 }
6953 return 0;
6954
6955half_open_err:
6956 bnxt_free_skbs(bp);
6957 bnxt_free_mem(bp, false);
6958 dev_close(bp->dev);
6959 return rc;
6960}
6961
6962/* rtnl_lock held, this call can only be made after a previous successful
6963 * call to bnxt_half_open_nic().
6964 */
6965void bnxt_half_close_nic(struct bnxt *bp)
6966{
6967 bnxt_hwrm_resource_free(bp, false, false);
6968 bnxt_free_skbs(bp);
6969 bnxt_free_mem(bp, false);
6970}
6971
Michael Chanc0c050c2015-10-22 16:01:17 -04006972static int bnxt_open(struct net_device *dev)
6973{
6974 struct bnxt *bp = netdev_priv(dev);
Michael Chanc0c050c2015-10-22 16:01:17 -04006975
Michael Chanc0c050c2015-10-22 16:01:17 -04006976 return __bnxt_open_nic(bp, true, true);
6977}
6978
Michael Chanf9b76eb2017-07-11 13:05:34 -04006979static bool bnxt_drv_busy(struct bnxt *bp)
6980{
6981 return (test_bit(BNXT_STATE_IN_SP_TASK, &bp->state) ||
6982 test_bit(BNXT_STATE_READ_STATS, &bp->state));
6983}
6984
Michael Chan86e953d2018-01-17 03:21:04 -05006985static void __bnxt_close_nic(struct bnxt *bp, bool irq_re_init,
6986 bool link_re_init)
Michael Chanc0c050c2015-10-22 16:01:17 -04006987{
Sathya Perlaee5c7fb2017-07-24 12:34:28 -04006988 /* Close the VF-reps before closing PF */
6989 if (BNXT_PF(bp))
6990 bnxt_vf_reps_close(bp);
Michael Chan86e953d2018-01-17 03:21:04 -05006991
Michael Chanc0c050c2015-10-22 16:01:17 -04006992 /* Change device state to avoid TX queue wake up's */
6993 bnxt_tx_disable(bp);
6994
Michael Chancaefe522015-12-09 19:35:42 -05006995 clear_bit(BNXT_STATE_OPEN, &bp->state);
Michael Chan4cebdce2015-12-09 19:35:43 -05006996 smp_mb__after_atomic();
Michael Chanf9b76eb2017-07-11 13:05:34 -04006997 while (bnxt_drv_busy(bp))
Michael Chan4cebdce2015-12-09 19:35:43 -05006998 msleep(20);
Michael Chanc0c050c2015-10-22 16:01:17 -04006999
Michael Chan9d8bc092016-12-29 12:13:33 -05007000 /* Flush rings and and disable interrupts */
Michael Chanc0c050c2015-10-22 16:01:17 -04007001 bnxt_shutdown_nic(bp, irq_re_init);
7002
7003 /* TODO CHIMP_FW: Link/PHY related cleanup if (link_re_init) */
7004
7005 bnxt_disable_napi(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04007006 del_timer_sync(&bp->timer);
7007 bnxt_free_skbs(bp);
7008
7009 if (irq_re_init) {
7010 bnxt_free_irq(bp);
7011 bnxt_del_napi(bp);
7012 }
7013 bnxt_free_mem(bp, irq_re_init);
Michael Chan86e953d2018-01-17 03:21:04 -05007014}
7015
7016int bnxt_close_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
7017{
7018 int rc = 0;
7019
7020#ifdef CONFIG_BNXT_SRIOV
7021 if (bp->sriov_cfg) {
7022 rc = wait_event_interruptible_timeout(bp->sriov_cfg_wait,
7023 !bp->sriov_cfg,
7024 BNXT_SRIOV_CFG_WAIT_TMO);
7025 if (rc)
7026 netdev_warn(bp->dev, "timeout waiting for SRIOV config operation to complete!\n");
7027 }
7028#endif
7029 __bnxt_close_nic(bp, irq_re_init, link_re_init);
Michael Chanc0c050c2015-10-22 16:01:17 -04007030 return rc;
7031}
7032
7033static int bnxt_close(struct net_device *dev)
7034{
7035 struct bnxt *bp = netdev_priv(dev);
7036
7037 bnxt_close_nic(bp, true, true);
Michael Chan33f7d552016-04-11 04:11:12 -04007038 bnxt_hwrm_shutdown_link(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04007039 return 0;
7040}
7041
7042/* rtnl_lock held */
7043static int bnxt_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
7044{
7045 switch (cmd) {
7046 case SIOCGMIIPHY:
7047 /* fallthru */
7048 case SIOCGMIIREG: {
7049 if (!netif_running(dev))
7050 return -EAGAIN;
7051
7052 return 0;
7053 }
7054
7055 case SIOCSMIIREG:
7056 if (!netif_running(dev))
7057 return -EAGAIN;
7058
7059 return 0;
7060
7061 default:
7062 /* do nothing */
7063 break;
7064 }
7065 return -EOPNOTSUPP;
7066}
7067
stephen hemmingerbc1f4472017-01-06 19:12:52 -08007068static void
Michael Chanc0c050c2015-10-22 16:01:17 -04007069bnxt_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
7070{
7071 u32 i;
7072 struct bnxt *bp = netdev_priv(dev);
7073
Michael Chanf9b76eb2017-07-11 13:05:34 -04007074 set_bit(BNXT_STATE_READ_STATS, &bp->state);
7075 /* Make sure bnxt_close_nic() sees that we are reading stats before
7076 * we check the BNXT_STATE_OPEN flag.
7077 */
7078 smp_mb__after_atomic();
7079 if (!test_bit(BNXT_STATE_OPEN, &bp->state)) {
7080 clear_bit(BNXT_STATE_READ_STATS, &bp->state);
stephen hemmingerbc1f4472017-01-06 19:12:52 -08007081 return;
Michael Chanf9b76eb2017-07-11 13:05:34 -04007082 }
Michael Chanc0c050c2015-10-22 16:01:17 -04007083
7084 /* TODO check if we need to synchronize with bnxt_close path */
7085 for (i = 0; i < bp->cp_nr_rings; i++) {
7086 struct bnxt_napi *bnapi = bp->bnapi[i];
7087 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
7088 struct ctx_hw_stats *hw_stats = cpr->hw_stats;
7089
7090 stats->rx_packets += le64_to_cpu(hw_stats->rx_ucast_pkts);
7091 stats->rx_packets += le64_to_cpu(hw_stats->rx_mcast_pkts);
7092 stats->rx_packets += le64_to_cpu(hw_stats->rx_bcast_pkts);
7093
7094 stats->tx_packets += le64_to_cpu(hw_stats->tx_ucast_pkts);
7095 stats->tx_packets += le64_to_cpu(hw_stats->tx_mcast_pkts);
7096 stats->tx_packets += le64_to_cpu(hw_stats->tx_bcast_pkts);
7097
7098 stats->rx_bytes += le64_to_cpu(hw_stats->rx_ucast_bytes);
7099 stats->rx_bytes += le64_to_cpu(hw_stats->rx_mcast_bytes);
7100 stats->rx_bytes += le64_to_cpu(hw_stats->rx_bcast_bytes);
7101
7102 stats->tx_bytes += le64_to_cpu(hw_stats->tx_ucast_bytes);
7103 stats->tx_bytes += le64_to_cpu(hw_stats->tx_mcast_bytes);
7104 stats->tx_bytes += le64_to_cpu(hw_stats->tx_bcast_bytes);
7105
7106 stats->rx_missed_errors +=
7107 le64_to_cpu(hw_stats->rx_discard_pkts);
7108
7109 stats->multicast += le64_to_cpu(hw_stats->rx_mcast_pkts);
7110
Michael Chanc0c050c2015-10-22 16:01:17 -04007111 stats->tx_dropped += le64_to_cpu(hw_stats->tx_drop_pkts);
7112 }
7113
Michael Chan9947f832016-03-07 15:38:46 -05007114 if (bp->flags & BNXT_FLAG_PORT_STATS) {
7115 struct rx_port_stats *rx = bp->hw_rx_port_stats;
7116 struct tx_port_stats *tx = bp->hw_tx_port_stats;
7117
7118 stats->rx_crc_errors = le64_to_cpu(rx->rx_fcs_err_frames);
7119 stats->rx_frame_errors = le64_to_cpu(rx->rx_align_err_frames);
7120 stats->rx_length_errors = le64_to_cpu(rx->rx_undrsz_frames) +
7121 le64_to_cpu(rx->rx_ovrsz_frames) +
7122 le64_to_cpu(rx->rx_runt_frames);
7123 stats->rx_errors = le64_to_cpu(rx->rx_false_carrier_frames) +
7124 le64_to_cpu(rx->rx_jbr_frames);
7125 stats->collisions = le64_to_cpu(tx->tx_total_collisions);
7126 stats->tx_fifo_errors = le64_to_cpu(tx->tx_fifo_underruns);
7127 stats->tx_errors = le64_to_cpu(tx->tx_err);
7128 }
Michael Chanf9b76eb2017-07-11 13:05:34 -04007129 clear_bit(BNXT_STATE_READ_STATS, &bp->state);
Michael Chanc0c050c2015-10-22 16:01:17 -04007130}
7131
7132static bool bnxt_mc_list_updated(struct bnxt *bp, u32 *rx_mask)
7133{
7134 struct net_device *dev = bp->dev;
7135 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
7136 struct netdev_hw_addr *ha;
7137 u8 *haddr;
7138 int mc_count = 0;
7139 bool update = false;
7140 int off = 0;
7141
7142 netdev_for_each_mc_addr(ha, dev) {
7143 if (mc_count >= BNXT_MAX_MC_ADDRS) {
7144 *rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST;
7145 vnic->mc_list_count = 0;
7146 return false;
7147 }
7148 haddr = ha->addr;
7149 if (!ether_addr_equal(haddr, vnic->mc_list + off)) {
7150 memcpy(vnic->mc_list + off, haddr, ETH_ALEN);
7151 update = true;
7152 }
7153 off += ETH_ALEN;
7154 mc_count++;
7155 }
7156 if (mc_count)
7157 *rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_MCAST;
7158
7159 if (mc_count != vnic->mc_list_count) {
7160 vnic->mc_list_count = mc_count;
7161 update = true;
7162 }
7163 return update;
7164}
7165
7166static bool bnxt_uc_list_updated(struct bnxt *bp)
7167{
7168 struct net_device *dev = bp->dev;
7169 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
7170 struct netdev_hw_addr *ha;
7171 int off = 0;
7172
7173 if (netdev_uc_count(dev) != (vnic->uc_filter_count - 1))
7174 return true;
7175
7176 netdev_for_each_uc_addr(ha, dev) {
7177 if (!ether_addr_equal(ha->addr, vnic->uc_list + off))
7178 return true;
7179
7180 off += ETH_ALEN;
7181 }
7182 return false;
7183}
7184
7185static void bnxt_set_rx_mode(struct net_device *dev)
7186{
7187 struct bnxt *bp = netdev_priv(dev);
7188 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
7189 u32 mask = vnic->rx_mask;
7190 bool mc_update = false;
7191 bool uc_update;
7192
7193 if (!netif_running(dev))
7194 return;
7195
7196 mask &= ~(CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS |
7197 CFA_L2_SET_RX_MASK_REQ_MASK_MCAST |
7198 CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST);
7199
Michael Chan17c71ac2016-07-01 18:46:27 -04007200 if ((dev->flags & IFF_PROMISC) && bnxt_promisc_ok(bp))
Michael Chanc0c050c2015-10-22 16:01:17 -04007201 mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS;
7202
7203 uc_update = bnxt_uc_list_updated(bp);
7204
7205 if (dev->flags & IFF_ALLMULTI) {
7206 mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST;
7207 vnic->mc_list_count = 0;
7208 } else {
7209 mc_update = bnxt_mc_list_updated(bp, &mask);
7210 }
7211
7212 if (mask != vnic->rx_mask || uc_update || mc_update) {
7213 vnic->rx_mask = mask;
7214
7215 set_bit(BNXT_RX_MASK_SP_EVENT, &bp->sp_event);
Michael Chanc213eae2017-10-13 21:09:29 -04007216 bnxt_queue_sp_work(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04007217 }
7218}
7219
Michael Chanb664f002015-12-02 01:54:08 -05007220static int bnxt_cfg_rx_mode(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04007221{
7222 struct net_device *dev = bp->dev;
7223 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
7224 struct netdev_hw_addr *ha;
7225 int i, off = 0, rc;
7226 bool uc_update;
7227
7228 netif_addr_lock_bh(dev);
7229 uc_update = bnxt_uc_list_updated(bp);
7230 netif_addr_unlock_bh(dev);
7231
7232 if (!uc_update)
7233 goto skip_uc;
7234
7235 mutex_lock(&bp->hwrm_cmd_lock);
7236 for (i = 1; i < vnic->uc_filter_count; i++) {
7237 struct hwrm_cfa_l2_filter_free_input req = {0};
7238
7239 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_L2_FILTER_FREE, -1,
7240 -1);
7241
7242 req.l2_filter_id = vnic->fw_l2_filter_id[i];
7243
7244 rc = _hwrm_send_message(bp, &req, sizeof(req),
7245 HWRM_CMD_TIMEOUT);
7246 }
7247 mutex_unlock(&bp->hwrm_cmd_lock);
7248
7249 vnic->uc_filter_count = 1;
7250
7251 netif_addr_lock_bh(dev);
7252 if (netdev_uc_count(dev) > (BNXT_MAX_UC_ADDRS - 1)) {
7253 vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS;
7254 } else {
7255 netdev_for_each_uc_addr(ha, dev) {
7256 memcpy(vnic->uc_list + off, ha->addr, ETH_ALEN);
7257 off += ETH_ALEN;
7258 vnic->uc_filter_count++;
7259 }
7260 }
7261 netif_addr_unlock_bh(dev);
7262
7263 for (i = 1, off = 0; i < vnic->uc_filter_count; i++, off += ETH_ALEN) {
7264 rc = bnxt_hwrm_set_vnic_filter(bp, 0, i, vnic->uc_list + off);
7265 if (rc) {
7266 netdev_err(bp->dev, "HWRM vnic filter failure rc: %x\n",
7267 rc);
7268 vnic->uc_filter_count = i;
Michael Chanb664f002015-12-02 01:54:08 -05007269 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04007270 }
7271 }
7272
7273skip_uc:
7274 rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, 0);
7275 if (rc)
7276 netdev_err(bp->dev, "HWRM cfa l2 rx mask failure rc: %x\n",
7277 rc);
Michael Chanb664f002015-12-02 01:54:08 -05007278
7279 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04007280}
7281
Michael Chan8079e8f2016-12-29 12:13:37 -05007282/* If the chip and firmware supports RFS */
7283static bool bnxt_rfs_supported(struct bnxt *bp)
7284{
7285 if (BNXT_PF(bp) && !BNXT_CHIP_TYPE_NITRO_A0(bp))
7286 return true;
Michael Chanae10ae72016-12-29 12:13:38 -05007287 if (bp->flags & BNXT_FLAG_NEW_RSS_CAP)
7288 return true;
Michael Chan8079e8f2016-12-29 12:13:37 -05007289 return false;
7290}
7291
7292/* If runtime conditions support RFS */
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007293static bool bnxt_rfs_capable(struct bnxt *bp)
7294{
7295#ifdef CONFIG_RFS_ACCEL
Michael Chan8079e8f2016-12-29 12:13:37 -05007296 int vnics, max_vnics, max_rss_ctxs;
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007297
Michael Chan964fd482017-02-12 19:18:13 -05007298 if (!(bp->flags & BNXT_FLAG_MSIX_CAP))
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007299 return false;
7300
7301 vnics = 1 + bp->rx_nr_rings;
Michael Chan8079e8f2016-12-29 12:13:37 -05007302 max_vnics = bnxt_get_max_func_vnics(bp);
7303 max_rss_ctxs = bnxt_get_max_func_rss_ctxs(bp);
Michael Chanae10ae72016-12-29 12:13:38 -05007304
7305 /* RSS contexts not a limiting factor */
7306 if (bp->flags & BNXT_FLAG_NEW_RSS_CAP)
7307 max_rss_ctxs = max_vnics;
Michael Chan8079e8f2016-12-29 12:13:37 -05007308 if (vnics > max_vnics || vnics > max_rss_ctxs) {
Michael Chan6a1eef52018-01-17 03:21:10 -05007309 if (bp->rx_nr_rings > 1)
7310 netdev_warn(bp->dev,
7311 "Not enough resources to support NTUPLE filters, enough resources for up to %d rx rings\n",
7312 min(max_rss_ctxs - 1, max_vnics - 1));
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007313 return false;
Vasundhara Volama2304902016-07-25 12:33:36 -04007314 }
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007315
Michael Chan6a1eef52018-01-17 03:21:10 -05007316 if (!(bp->flags & BNXT_FLAG_NEW_RM))
7317 return true;
7318
7319 if (vnics == bp->hw_resc.resv_vnics)
7320 return true;
7321
7322 bnxt_hwrm_reserve_rings(bp, 0, 0, 0, 0, vnics);
7323 if (vnics <= bp->hw_resc.resv_vnics)
7324 return true;
7325
7326 netdev_warn(bp->dev, "Unable to reserve resources to support NTUPLE filters.\n");
7327 bnxt_hwrm_reserve_rings(bp, 0, 0, 0, 0, 1);
7328 return false;
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007329#else
7330 return false;
7331#endif
7332}
7333
Michael Chanc0c050c2015-10-22 16:01:17 -04007334static netdev_features_t bnxt_fix_features(struct net_device *dev,
7335 netdev_features_t features)
7336{
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007337 struct bnxt *bp = netdev_priv(dev);
7338
Vasundhara Volama2304902016-07-25 12:33:36 -04007339 if ((features & NETIF_F_NTUPLE) && !bnxt_rfs_capable(bp))
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007340 features &= ~NETIF_F_NTUPLE;
Michael Chan5a9f6b22016-06-06 02:37:15 -04007341
Michael Chan1054aee2017-12-16 03:09:42 -05007342 if (bp->flags & BNXT_FLAG_NO_AGG_RINGS)
7343 features &= ~(NETIF_F_LRO | NETIF_F_GRO_HW);
7344
7345 if (!(features & NETIF_F_GRO))
7346 features &= ~NETIF_F_GRO_HW;
7347
7348 if (features & NETIF_F_GRO_HW)
7349 features &= ~NETIF_F_LRO;
7350
Michael Chan5a9f6b22016-06-06 02:37:15 -04007351 /* Both CTAG and STAG VLAN accelaration on the RX side have to be
7352 * turned on or off together.
7353 */
7354 if ((features & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX)) !=
7355 (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX)) {
7356 if (dev->features & NETIF_F_HW_VLAN_CTAG_RX)
7357 features &= ~(NETIF_F_HW_VLAN_CTAG_RX |
7358 NETIF_F_HW_VLAN_STAG_RX);
7359 else
7360 features |= NETIF_F_HW_VLAN_CTAG_RX |
7361 NETIF_F_HW_VLAN_STAG_RX;
7362 }
Michael Chancf6645f2016-06-13 02:25:28 -04007363#ifdef CONFIG_BNXT_SRIOV
7364 if (BNXT_VF(bp)) {
7365 if (bp->vf.vlan) {
7366 features &= ~(NETIF_F_HW_VLAN_CTAG_RX |
7367 NETIF_F_HW_VLAN_STAG_RX);
7368 }
7369 }
7370#endif
Michael Chanc0c050c2015-10-22 16:01:17 -04007371 return features;
7372}
7373
7374static int bnxt_set_features(struct net_device *dev, netdev_features_t features)
7375{
7376 struct bnxt *bp = netdev_priv(dev);
7377 u32 flags = bp->flags;
7378 u32 changes;
7379 int rc = 0;
7380 bool re_init = false;
7381 bool update_tpa = false;
7382
7383 flags &= ~BNXT_FLAG_ALL_CONFIG_FEATS;
Michael Chan1054aee2017-12-16 03:09:42 -05007384 if (features & NETIF_F_GRO_HW)
Michael Chanc0c050c2015-10-22 16:01:17 -04007385 flags |= BNXT_FLAG_GRO;
Michael Chan1054aee2017-12-16 03:09:42 -05007386 else if (features & NETIF_F_LRO)
Michael Chanc0c050c2015-10-22 16:01:17 -04007387 flags |= BNXT_FLAG_LRO;
7388
Michael Chanbdbd1eb2016-12-29 12:13:43 -05007389 if (bp->flags & BNXT_FLAG_NO_AGG_RINGS)
7390 flags &= ~BNXT_FLAG_TPA;
7391
Michael Chanc0c050c2015-10-22 16:01:17 -04007392 if (features & NETIF_F_HW_VLAN_CTAG_RX)
7393 flags |= BNXT_FLAG_STRIP_VLAN;
7394
7395 if (features & NETIF_F_NTUPLE)
7396 flags |= BNXT_FLAG_RFS;
7397
7398 changes = flags ^ bp->flags;
7399 if (changes & BNXT_FLAG_TPA) {
7400 update_tpa = true;
7401 if ((bp->flags & BNXT_FLAG_TPA) == 0 ||
7402 (flags & BNXT_FLAG_TPA) == 0)
7403 re_init = true;
7404 }
7405
7406 if (changes & ~BNXT_FLAG_TPA)
7407 re_init = true;
7408
7409 if (flags != bp->flags) {
7410 u32 old_flags = bp->flags;
7411
7412 bp->flags = flags;
7413
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007414 if (!test_bit(BNXT_STATE_OPEN, &bp->state)) {
Michael Chanc0c050c2015-10-22 16:01:17 -04007415 if (update_tpa)
7416 bnxt_set_ring_params(bp);
7417 return rc;
7418 }
7419
7420 if (re_init) {
7421 bnxt_close_nic(bp, false, false);
7422 if (update_tpa)
7423 bnxt_set_ring_params(bp);
7424
7425 return bnxt_open_nic(bp, false, false);
7426 }
7427 if (update_tpa) {
7428 rc = bnxt_set_tpa(bp,
7429 (flags & BNXT_FLAG_TPA) ?
7430 true : false);
7431 if (rc)
7432 bp->flags = old_flags;
7433 }
7434 }
7435 return rc;
7436}
7437
Michael Chan9f554592016-01-02 23:44:58 -05007438static void bnxt_dump_tx_sw_state(struct bnxt_napi *bnapi)
7439{
Michael Chanb6ab4b02016-01-02 23:44:59 -05007440 struct bnxt_tx_ring_info *txr = bnapi->tx_ring;
Michael Chan9f554592016-01-02 23:44:58 -05007441 int i = bnapi->index;
7442
Michael Chan3b2b7d92016-01-02 23:45:00 -05007443 if (!txr)
7444 return;
7445
Michael Chan9f554592016-01-02 23:44:58 -05007446 netdev_info(bnapi->bp->dev, "[%d]: tx{fw_ring: %d prod: %x cons: %x}\n",
7447 i, txr->tx_ring_struct.fw_ring_id, txr->tx_prod,
7448 txr->tx_cons);
7449}
7450
7451static void bnxt_dump_rx_sw_state(struct bnxt_napi *bnapi)
7452{
Michael Chanb6ab4b02016-01-02 23:44:59 -05007453 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
Michael Chan9f554592016-01-02 23:44:58 -05007454 int i = bnapi->index;
7455
Michael Chan3b2b7d92016-01-02 23:45:00 -05007456 if (!rxr)
7457 return;
7458
Michael Chan9f554592016-01-02 23:44:58 -05007459 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",
7460 i, rxr->rx_ring_struct.fw_ring_id, rxr->rx_prod,
7461 rxr->rx_agg_ring_struct.fw_ring_id, rxr->rx_agg_prod,
7462 rxr->rx_sw_agg_prod);
7463}
7464
7465static void bnxt_dump_cp_sw_state(struct bnxt_napi *bnapi)
7466{
7467 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
7468 int i = bnapi->index;
7469
7470 netdev_info(bnapi->bp->dev, "[%d]: cp{fw_ring: %d raw_cons: %x}\n",
7471 i, cpr->cp_ring_struct.fw_ring_id, cpr->cp_raw_cons);
7472}
7473
Michael Chanc0c050c2015-10-22 16:01:17 -04007474static void bnxt_dbg_dump_states(struct bnxt *bp)
7475{
7476 int i;
7477 struct bnxt_napi *bnapi;
Michael Chanc0c050c2015-10-22 16:01:17 -04007478
7479 for (i = 0; i < bp->cp_nr_rings; i++) {
7480 bnapi = bp->bnapi[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04007481 if (netif_msg_drv(bp)) {
Michael Chan9f554592016-01-02 23:44:58 -05007482 bnxt_dump_tx_sw_state(bnapi);
7483 bnxt_dump_rx_sw_state(bnapi);
7484 bnxt_dump_cp_sw_state(bnapi);
Michael Chanc0c050c2015-10-22 16:01:17 -04007485 }
7486 }
7487}
7488
Michael Chan6988bd92016-06-13 02:25:29 -04007489static void bnxt_reset_task(struct bnxt *bp, bool silent)
Michael Chanc0c050c2015-10-22 16:01:17 -04007490{
Michael Chan6988bd92016-06-13 02:25:29 -04007491 if (!silent)
7492 bnxt_dbg_dump_states(bp);
Michael Chan028de142015-12-09 19:35:44 -05007493 if (netif_running(bp->dev)) {
Michael Chanb386cd32017-03-08 18:44:33 -05007494 int rc;
7495
7496 if (!silent)
7497 bnxt_ulp_stop(bp);
Michael Chan028de142015-12-09 19:35:44 -05007498 bnxt_close_nic(bp, false, false);
Michael Chanb386cd32017-03-08 18:44:33 -05007499 rc = bnxt_open_nic(bp, false, false);
7500 if (!silent && !rc)
7501 bnxt_ulp_start(bp);
Michael Chan028de142015-12-09 19:35:44 -05007502 }
Michael Chanc0c050c2015-10-22 16:01:17 -04007503}
7504
7505static void bnxt_tx_timeout(struct net_device *dev)
7506{
7507 struct bnxt *bp = netdev_priv(dev);
7508
7509 netdev_err(bp->dev, "TX timeout detected, starting reset task!\n");
7510 set_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event);
Michael Chanc213eae2017-10-13 21:09:29 -04007511 bnxt_queue_sp_work(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04007512}
7513
7514#ifdef CONFIG_NET_POLL_CONTROLLER
7515static void bnxt_poll_controller(struct net_device *dev)
7516{
7517 struct bnxt *bp = netdev_priv(dev);
7518 int i;
7519
Michael Chan2270bc52017-06-23 14:01:01 -04007520 /* Only process tx rings/combined rings in netpoll mode. */
7521 for (i = 0; i < bp->tx_nr_rings; i++) {
7522 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04007523
Michael Chan2270bc52017-06-23 14:01:01 -04007524 napi_schedule(&txr->bnapi->napi);
Michael Chanc0c050c2015-10-22 16:01:17 -04007525 }
7526}
7527#endif
7528
Kees Cooke99e88a2017-10-16 14:43:17 -07007529static void bnxt_timer(struct timer_list *t)
Michael Chanc0c050c2015-10-22 16:01:17 -04007530{
Kees Cooke99e88a2017-10-16 14:43:17 -07007531 struct bnxt *bp = from_timer(bp, t, timer);
Michael Chanc0c050c2015-10-22 16:01:17 -04007532 struct net_device *dev = bp->dev;
7533
7534 if (!netif_running(dev))
7535 return;
7536
7537 if (atomic_read(&bp->intr_sem) != 0)
7538 goto bnxt_restart_timer;
7539
Michael Chanadcc3312017-07-24 12:34:24 -04007540 if (bp->link_info.link_up && (bp->flags & BNXT_FLAG_PORT_STATS) &&
7541 bp->stats_coal_ticks) {
Michael Chan3bdf56c2016-03-07 15:38:45 -05007542 set_bit(BNXT_PERIODIC_STATS_SP_EVENT, &bp->sp_event);
Michael Chanc213eae2017-10-13 21:09:29 -04007543 bnxt_queue_sp_work(bp);
Michael Chan3bdf56c2016-03-07 15:38:45 -05007544 }
Sathya Perla5a84acb2017-10-26 11:51:31 -04007545
7546 if (bnxt_tc_flower_enabled(bp)) {
7547 set_bit(BNXT_FLOW_STATS_SP_EVENT, &bp->sp_event);
7548 bnxt_queue_sp_work(bp);
7549 }
Michael Chanc0c050c2015-10-22 16:01:17 -04007550bnxt_restart_timer:
7551 mod_timer(&bp->timer, jiffies + bp->current_interval);
7552}
7553
Michael Chana551ee92017-01-25 02:55:07 -05007554static void bnxt_rtnl_lock_sp(struct bnxt *bp)
Michael Chan6988bd92016-06-13 02:25:29 -04007555{
Michael Chana551ee92017-01-25 02:55:07 -05007556 /* We are called from bnxt_sp_task which has BNXT_STATE_IN_SP_TASK
7557 * set. If the device is being closed, bnxt_close() may be holding
Michael Chan6988bd92016-06-13 02:25:29 -04007558 * rtnl() and waiting for BNXT_STATE_IN_SP_TASK to clear. So we
7559 * must clear BNXT_STATE_IN_SP_TASK before holding rtnl().
7560 */
7561 clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
7562 rtnl_lock();
Michael Chana551ee92017-01-25 02:55:07 -05007563}
7564
7565static void bnxt_rtnl_unlock_sp(struct bnxt *bp)
7566{
Michael Chan6988bd92016-06-13 02:25:29 -04007567 set_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
7568 rtnl_unlock();
7569}
7570
Michael Chana551ee92017-01-25 02:55:07 -05007571/* Only called from bnxt_sp_task() */
7572static void bnxt_reset(struct bnxt *bp, bool silent)
7573{
7574 bnxt_rtnl_lock_sp(bp);
7575 if (test_bit(BNXT_STATE_OPEN, &bp->state))
7576 bnxt_reset_task(bp, silent);
7577 bnxt_rtnl_unlock_sp(bp);
7578}
7579
Michael Chanc0c050c2015-10-22 16:01:17 -04007580static void bnxt_cfg_ntp_filters(struct bnxt *);
7581
7582static void bnxt_sp_task(struct work_struct *work)
7583{
7584 struct bnxt *bp = container_of(work, struct bnxt, sp_task);
Michael Chanc0c050c2015-10-22 16:01:17 -04007585
Michael Chan4cebdce2015-12-09 19:35:43 -05007586 set_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
7587 smp_mb__after_atomic();
7588 if (!test_bit(BNXT_STATE_OPEN, &bp->state)) {
7589 clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
Michael Chanc0c050c2015-10-22 16:01:17 -04007590 return;
Michael Chan4cebdce2015-12-09 19:35:43 -05007591 }
Michael Chanc0c050c2015-10-22 16:01:17 -04007592
7593 if (test_and_clear_bit(BNXT_RX_MASK_SP_EVENT, &bp->sp_event))
7594 bnxt_cfg_rx_mode(bp);
7595
7596 if (test_and_clear_bit(BNXT_RX_NTP_FLTR_SP_EVENT, &bp->sp_event))
7597 bnxt_cfg_ntp_filters(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04007598 if (test_and_clear_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT, &bp->sp_event))
7599 bnxt_hwrm_exec_fwd_req(bp);
7600 if (test_and_clear_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT, &bp->sp_event)) {
7601 bnxt_hwrm_tunnel_dst_port_alloc(
7602 bp, bp->vxlan_port,
7603 TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN);
7604 }
7605 if (test_and_clear_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT, &bp->sp_event)) {
7606 bnxt_hwrm_tunnel_dst_port_free(
7607 bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN);
7608 }
Alexander Duyck7cdd5fc2016-06-16 12:21:36 -07007609 if (test_and_clear_bit(BNXT_GENEVE_ADD_PORT_SP_EVENT, &bp->sp_event)) {
7610 bnxt_hwrm_tunnel_dst_port_alloc(
7611 bp, bp->nge_port,
7612 TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE);
7613 }
7614 if (test_and_clear_bit(BNXT_GENEVE_DEL_PORT_SP_EVENT, &bp->sp_event)) {
7615 bnxt_hwrm_tunnel_dst_port_free(
7616 bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE);
7617 }
Vasundhara Volam00db3cb2018-03-31 13:54:12 -04007618 if (test_and_clear_bit(BNXT_PERIODIC_STATS_SP_EVENT, &bp->sp_event)) {
Michael Chan3bdf56c2016-03-07 15:38:45 -05007619 bnxt_hwrm_port_qstats(bp);
Vasundhara Volam00db3cb2018-03-31 13:54:12 -04007620 bnxt_hwrm_port_qstats_ext(bp);
7621 }
Michael Chan3bdf56c2016-03-07 15:38:45 -05007622
Michael Chan0eaa24b2017-01-25 02:55:08 -05007623 if (test_and_clear_bit(BNXT_LINK_CHNG_SP_EVENT, &bp->sp_event)) {
Michael Chane2dc9b62017-10-13 21:09:30 -04007624 int rc;
Michael Chan0eaa24b2017-01-25 02:55:08 -05007625
Michael Chane2dc9b62017-10-13 21:09:30 -04007626 mutex_lock(&bp->link_lock);
Michael Chan0eaa24b2017-01-25 02:55:08 -05007627 if (test_and_clear_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT,
7628 &bp->sp_event))
7629 bnxt_hwrm_phy_qcaps(bp);
7630
Michael Chane2dc9b62017-10-13 21:09:30 -04007631 rc = bnxt_update_link(bp, true);
7632 mutex_unlock(&bp->link_lock);
Michael Chan0eaa24b2017-01-25 02:55:08 -05007633 if (rc)
7634 netdev_err(bp->dev, "SP task can't update link (rc: %x)\n",
7635 rc);
7636 }
Michael Chan90c694b2017-01-25 02:55:09 -05007637 if (test_and_clear_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT, &bp->sp_event)) {
Michael Chane2dc9b62017-10-13 21:09:30 -04007638 mutex_lock(&bp->link_lock);
7639 bnxt_get_port_module_status(bp);
7640 mutex_unlock(&bp->link_lock);
Michael Chan90c694b2017-01-25 02:55:09 -05007641 }
Sathya Perla5a84acb2017-10-26 11:51:31 -04007642
7643 if (test_and_clear_bit(BNXT_FLOW_STATS_SP_EVENT, &bp->sp_event))
7644 bnxt_tc_flow_stats_work(bp);
7645
Michael Chane2dc9b62017-10-13 21:09:30 -04007646 /* These functions below will clear BNXT_STATE_IN_SP_TASK. They
7647 * must be the last functions to be called before exiting.
7648 */
Michael Chanc0c050c2015-10-22 16:01:17 -04007649 if (test_and_clear_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event))
7650 bnxt_reset(bp, false);
7651
7652 if (test_and_clear_bit(BNXT_RESET_TASK_SILENT_SP_EVENT, &bp->sp_event))
7653 bnxt_reset(bp, true);
7654
Michael Chanc0c050c2015-10-22 16:01:17 -04007655 smp_mb__before_atomic();
7656 clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
7657}
7658
Michael Chand1e79252017-02-06 16:55:38 -05007659/* Under rtnl_lock */
Michael Chan98fdbe72017-08-28 13:40:26 -04007660int bnxt_check_rings(struct bnxt *bp, int tx, int rx, bool sh, int tcs,
7661 int tx_xdp)
Michael Chand1e79252017-02-06 16:55:38 -05007662{
7663 int max_rx, max_tx, tx_sets = 1;
7664 int tx_rings_needed;
Michael Chan8f23d632018-01-17 03:21:12 -05007665 int rx_rings = rx;
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05007666 int cp, vnics, rc;
Michael Chand1e79252017-02-06 16:55:38 -05007667
Michael Chand1e79252017-02-06 16:55:38 -05007668 if (tcs)
7669 tx_sets = tcs;
7670
7671 rc = bnxt_get_max_rings(bp, &max_rx, &max_tx, sh);
7672 if (rc)
7673 return rc;
7674
7675 if (max_rx < rx)
7676 return -ENOMEM;
7677
Michael Chan5f449242017-02-06 16:55:40 -05007678 tx_rings_needed = tx * tx_sets + tx_xdp;
Michael Chand1e79252017-02-06 16:55:38 -05007679 if (max_tx < tx_rings_needed)
7680 return -ENOMEM;
7681
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05007682 vnics = 1;
7683 if (bp->flags & BNXT_FLAG_RFS)
7684 vnics += rx_rings;
7685
Michael Chan8f23d632018-01-17 03:21:12 -05007686 if (bp->flags & BNXT_FLAG_AGG_RINGS)
7687 rx_rings <<= 1;
7688 cp = sh ? max_t(int, tx_rings_needed, rx) : tx_rings_needed + rx;
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05007689 return bnxt_hwrm_check_rings(bp, tx_rings_needed, rx_rings, rx, cp,
7690 vnics);
Michael Chand1e79252017-02-06 16:55:38 -05007691}
7692
Sathya Perla17086392017-02-20 19:25:18 -05007693static void bnxt_unmap_bars(struct bnxt *bp, struct pci_dev *pdev)
7694{
7695 if (bp->bar2) {
7696 pci_iounmap(pdev, bp->bar2);
7697 bp->bar2 = NULL;
7698 }
7699
7700 if (bp->bar1) {
7701 pci_iounmap(pdev, bp->bar1);
7702 bp->bar1 = NULL;
7703 }
7704
7705 if (bp->bar0) {
7706 pci_iounmap(pdev, bp->bar0);
7707 bp->bar0 = NULL;
7708 }
7709}
7710
7711static void bnxt_cleanup_pci(struct bnxt *bp)
7712{
7713 bnxt_unmap_bars(bp, bp->pdev);
7714 pci_release_regions(bp->pdev);
7715 pci_disable_device(bp->pdev);
7716}
7717
Michael Chan18775aa2017-10-26 11:51:27 -04007718static void bnxt_init_dflt_coal(struct bnxt *bp)
7719{
7720 struct bnxt_coal *coal;
7721
7722 /* Tick values in micro seconds.
7723 * 1 coal_buf x bufs_per_record = 1 completion record.
7724 */
7725 coal = &bp->rx_coal;
7726 coal->coal_ticks = 14;
7727 coal->coal_bufs = 30;
7728 coal->coal_ticks_irq = 1;
7729 coal->coal_bufs_irq = 2;
7730 coal->idle_thresh = 25;
7731 coal->bufs_per_record = 2;
7732 coal->budget = 64; /* NAPI budget */
7733
7734 coal = &bp->tx_coal;
7735 coal->coal_ticks = 28;
7736 coal->coal_bufs = 30;
7737 coal->coal_ticks_irq = 2;
7738 coal->coal_bufs_irq = 2;
7739 coal->bufs_per_record = 1;
7740
7741 bp->stats_coal_ticks = BNXT_DEF_STATS_COAL_TICKS;
7742}
7743
Michael Chanc0c050c2015-10-22 16:01:17 -04007744static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev)
7745{
7746 int rc;
7747 struct bnxt *bp = netdev_priv(dev);
7748
7749 SET_NETDEV_DEV(dev, &pdev->dev);
7750
7751 /* enable device (incl. PCI PM wakeup), and bus-mastering */
7752 rc = pci_enable_device(pdev);
7753 if (rc) {
7754 dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n");
7755 goto init_err;
7756 }
7757
7758 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
7759 dev_err(&pdev->dev,
7760 "Cannot find PCI device base address, aborting\n");
7761 rc = -ENODEV;
7762 goto init_err_disable;
7763 }
7764
7765 rc = pci_request_regions(pdev, DRV_MODULE_NAME);
7766 if (rc) {
7767 dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting\n");
7768 goto init_err_disable;
7769 }
7770
7771 if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)) != 0 &&
7772 dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)) != 0) {
7773 dev_err(&pdev->dev, "System does not support DMA, aborting\n");
7774 goto init_err_disable;
7775 }
7776
7777 pci_set_master(pdev);
7778
7779 bp->dev = dev;
7780 bp->pdev = pdev;
7781
7782 bp->bar0 = pci_ioremap_bar(pdev, 0);
7783 if (!bp->bar0) {
7784 dev_err(&pdev->dev, "Cannot map device registers, aborting\n");
7785 rc = -ENOMEM;
7786 goto init_err_release;
7787 }
7788
7789 bp->bar1 = pci_ioremap_bar(pdev, 2);
7790 if (!bp->bar1) {
7791 dev_err(&pdev->dev, "Cannot map doorbell registers, aborting\n");
7792 rc = -ENOMEM;
7793 goto init_err_release;
7794 }
7795
7796 bp->bar2 = pci_ioremap_bar(pdev, 4);
7797 if (!bp->bar2) {
7798 dev_err(&pdev->dev, "Cannot map bar4 registers, aborting\n");
7799 rc = -ENOMEM;
7800 goto init_err_release;
7801 }
7802
Satish Baddipadige6316ea62016-03-07 15:38:48 -05007803 pci_enable_pcie_error_reporting(pdev);
7804
Michael Chanc0c050c2015-10-22 16:01:17 -04007805 INIT_WORK(&bp->sp_task, bnxt_sp_task);
7806
7807 spin_lock_init(&bp->ntp_fltr_lock);
7808
7809 bp->rx_ring_size = BNXT_DEFAULT_RX_RING_SIZE;
7810 bp->tx_ring_size = BNXT_DEFAULT_TX_RING_SIZE;
7811
Michael Chan18775aa2017-10-26 11:51:27 -04007812 bnxt_init_dflt_coal(bp);
Michael Chan51f30782016-07-01 18:46:29 -04007813
Kees Cooke99e88a2017-10-16 14:43:17 -07007814 timer_setup(&bp->timer, bnxt_timer, 0);
Michael Chanc0c050c2015-10-22 16:01:17 -04007815 bp->current_interval = BNXT_TIMER_INTERVAL;
7816
Michael Chancaefe522015-12-09 19:35:42 -05007817 clear_bit(BNXT_STATE_OPEN, &bp->state);
Michael Chanc0c050c2015-10-22 16:01:17 -04007818 return 0;
7819
7820init_err_release:
Sathya Perla17086392017-02-20 19:25:18 -05007821 bnxt_unmap_bars(bp, pdev);
Michael Chanc0c050c2015-10-22 16:01:17 -04007822 pci_release_regions(pdev);
7823
7824init_err_disable:
7825 pci_disable_device(pdev);
7826
7827init_err:
7828 return rc;
7829}
7830
7831/* rtnl_lock held */
7832static int bnxt_change_mac_addr(struct net_device *dev, void *p)
7833{
7834 struct sockaddr *addr = p;
Jeffrey Huang1fc2cfd2015-12-02 01:54:06 -05007835 struct bnxt *bp = netdev_priv(dev);
7836 int rc = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04007837
7838 if (!is_valid_ether_addr(addr->sa_data))
7839 return -EADDRNOTAVAIL;
7840
Michael Chanc1a7bdf2017-10-26 11:51:24 -04007841 if (ether_addr_equal(addr->sa_data, dev->dev_addr))
7842 return 0;
7843
Michael Chan84c33dd2016-04-11 04:11:13 -04007844 rc = bnxt_approve_mac(bp, addr->sa_data);
7845 if (rc)
7846 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04007847
Jeffrey Huang1fc2cfd2015-12-02 01:54:06 -05007848 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
7849 if (netif_running(dev)) {
7850 bnxt_close_nic(bp, false, false);
7851 rc = bnxt_open_nic(bp, false, false);
7852 }
7853
7854 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04007855}
7856
7857/* rtnl_lock held */
7858static int bnxt_change_mtu(struct net_device *dev, int new_mtu)
7859{
7860 struct bnxt *bp = netdev_priv(dev);
7861
Michael Chanc0c050c2015-10-22 16:01:17 -04007862 if (netif_running(dev))
7863 bnxt_close_nic(bp, false, false);
7864
7865 dev->mtu = new_mtu;
7866 bnxt_set_ring_params(bp);
7867
7868 if (netif_running(dev))
7869 return bnxt_open_nic(bp, false, false);
7870
7871 return 0;
7872}
7873
Michael Chanc5e3deb2016-12-02 21:17:15 -05007874int bnxt_setup_mq_tc(struct net_device *dev, u8 tc)
Michael Chanc0c050c2015-10-22 16:01:17 -04007875{
7876 struct bnxt *bp = netdev_priv(dev);
Michael Chan3ffb6a32016-11-11 00:11:42 -05007877 bool sh = false;
Michael Chand1e79252017-02-06 16:55:38 -05007878 int rc;
John Fastabend16e5cc62016-02-16 21:16:43 -08007879
Michael Chanc0c050c2015-10-22 16:01:17 -04007880 if (tc > bp->max_tc) {
Michael Chanb451c8b2017-02-12 19:18:17 -05007881 netdev_err(dev, "Too many traffic classes requested: %d. Max supported is %d.\n",
Michael Chanc0c050c2015-10-22 16:01:17 -04007882 tc, bp->max_tc);
7883 return -EINVAL;
7884 }
7885
7886 if (netdev_get_num_tc(dev) == tc)
7887 return 0;
7888
Michael Chan3ffb6a32016-11-11 00:11:42 -05007889 if (bp->flags & BNXT_FLAG_SHARED_RINGS)
7890 sh = true;
7891
Michael Chan98fdbe72017-08-28 13:40:26 -04007892 rc = bnxt_check_rings(bp, bp->tx_nr_rings_per_tc, bp->rx_nr_rings,
7893 sh, tc, bp->tx_nr_rings_xdp);
Michael Chand1e79252017-02-06 16:55:38 -05007894 if (rc)
7895 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04007896
7897 /* Needs to close the device and do hw resource re-allocations */
7898 if (netif_running(bp->dev))
7899 bnxt_close_nic(bp, true, false);
7900
7901 if (tc) {
7902 bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tc;
7903 netdev_set_num_tc(dev, tc);
7904 } else {
7905 bp->tx_nr_rings = bp->tx_nr_rings_per_tc;
7906 netdev_reset_tc(dev);
7907 }
Michael Chan87e9b372017-08-23 19:34:03 -04007908 bp->tx_nr_rings += bp->tx_nr_rings_xdp;
Michael Chan3ffb6a32016-11-11 00:11:42 -05007909 bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
7910 bp->tx_nr_rings + bp->rx_nr_rings;
Michael Chanc0c050c2015-10-22 16:01:17 -04007911 bp->num_stat_ctxs = bp->cp_nr_rings;
7912
7913 if (netif_running(bp->dev))
7914 return bnxt_open_nic(bp, true, false);
7915
7916 return 0;
7917}
7918
Jiri Pirko9e0fd152017-10-19 15:50:39 +02007919static int bnxt_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
7920 void *cb_priv)
Sathya Perla2ae74082017-08-28 13:40:33 -04007921{
Jiri Pirko9e0fd152017-10-19 15:50:39 +02007922 struct bnxt *bp = cb_priv;
Sathya Perla2ae74082017-08-28 13:40:33 -04007923
Jakub Kicinski312324f2018-01-25 14:00:48 -08007924 if (!bnxt_tc_flower_enabled(bp) ||
7925 !tc_cls_can_offload_and_chain0(bp->dev, type_data))
Sathya Perla2ae74082017-08-28 13:40:33 -04007926 return -EOPNOTSUPP;
7927
Jiri Pirko9e0fd152017-10-19 15:50:39 +02007928 switch (type) {
7929 case TC_SETUP_CLSFLOWER:
7930 return bnxt_tc_setup_flower(bp, bp->pf.fw_fid, type_data);
7931 default:
7932 return -EOPNOTSUPP;
7933 }
7934}
7935
7936static int bnxt_setup_tc_block(struct net_device *dev,
7937 struct tc_block_offload *f)
7938{
7939 struct bnxt *bp = netdev_priv(dev);
7940
7941 if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
7942 return -EOPNOTSUPP;
7943
7944 switch (f->command) {
7945 case TC_BLOCK_BIND:
7946 return tcf_block_cb_register(f->block, bnxt_setup_tc_block_cb,
7947 bp, bp);
7948 case TC_BLOCK_UNBIND:
7949 tcf_block_cb_unregister(f->block, bnxt_setup_tc_block_cb, bp);
7950 return 0;
7951 default:
7952 return -EOPNOTSUPP;
7953 }
Sathya Perla2ae74082017-08-28 13:40:33 -04007954}
7955
Jiri Pirko2572ac52017-08-07 10:15:17 +02007956static int bnxt_setup_tc(struct net_device *dev, enum tc_setup_type type,
Jiri Pirkode4784c2017-08-07 10:15:32 +02007957 void *type_data)
Michael Chanc5e3deb2016-12-02 21:17:15 -05007958{
Sathya Perla2ae74082017-08-28 13:40:33 -04007959 switch (type) {
Jiri Pirko9e0fd152017-10-19 15:50:39 +02007960 case TC_SETUP_BLOCK:
7961 return bnxt_setup_tc_block(dev, type_data);
Nogah Frankel575ed7d2017-11-06 07:23:42 +01007962 case TC_SETUP_QDISC_MQPRIO: {
Sathya Perla2ae74082017-08-28 13:40:33 -04007963 struct tc_mqprio_qopt *mqprio = type_data;
Jiri Pirkode4784c2017-08-07 10:15:32 +02007964
Sathya Perla2ae74082017-08-28 13:40:33 -04007965 mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
7966
7967 return bnxt_setup_mq_tc(dev, mqprio->num_tc);
7968 }
7969 default:
Jiri Pirko38cf0422017-08-07 10:15:31 +02007970 return -EOPNOTSUPP;
Sathya Perla2ae74082017-08-28 13:40:33 -04007971 }
Michael Chanc5e3deb2016-12-02 21:17:15 -05007972}
7973
Michael Chanc0c050c2015-10-22 16:01:17 -04007974#ifdef CONFIG_RFS_ACCEL
7975static bool bnxt_fltr_match(struct bnxt_ntuple_filter *f1,
7976 struct bnxt_ntuple_filter *f2)
7977{
7978 struct flow_keys *keys1 = &f1->fkeys;
7979 struct flow_keys *keys2 = &f2->fkeys;
7980
7981 if (keys1->addrs.v4addrs.src == keys2->addrs.v4addrs.src &&
7982 keys1->addrs.v4addrs.dst == keys2->addrs.v4addrs.dst &&
7983 keys1->ports.ports == keys2->ports.ports &&
7984 keys1->basic.ip_proto == keys2->basic.ip_proto &&
7985 keys1->basic.n_proto == keys2->basic.n_proto &&
Michael Chan61aad722017-02-12 19:18:14 -05007986 keys1->control.flags == keys2->control.flags &&
Michael Chana54c4d72016-07-25 12:33:35 -04007987 ether_addr_equal(f1->src_mac_addr, f2->src_mac_addr) &&
7988 ether_addr_equal(f1->dst_mac_addr, f2->dst_mac_addr))
Michael Chanc0c050c2015-10-22 16:01:17 -04007989 return true;
7990
7991 return false;
7992}
7993
7994static int bnxt_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
7995 u16 rxq_index, u32 flow_id)
7996{
7997 struct bnxt *bp = netdev_priv(dev);
7998 struct bnxt_ntuple_filter *fltr, *new_fltr;
7999 struct flow_keys *fkeys;
8000 struct ethhdr *eth = (struct ethhdr *)skb_mac_header(skb);
Michael Chana54c4d72016-07-25 12:33:35 -04008001 int rc = 0, idx, bit_id, l2_idx = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04008002 struct hlist_head *head;
8003
Michael Chana54c4d72016-07-25 12:33:35 -04008004 if (!ether_addr_equal(dev->dev_addr, eth->h_dest)) {
8005 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
8006 int off = 0, j;
8007
8008 netif_addr_lock_bh(dev);
8009 for (j = 0; j < vnic->uc_filter_count; j++, off += ETH_ALEN) {
8010 if (ether_addr_equal(eth->h_dest,
8011 vnic->uc_list + off)) {
8012 l2_idx = j + 1;
8013 break;
8014 }
8015 }
8016 netif_addr_unlock_bh(dev);
8017 if (!l2_idx)
8018 return -EINVAL;
8019 }
Michael Chanc0c050c2015-10-22 16:01:17 -04008020 new_fltr = kzalloc(sizeof(*new_fltr), GFP_ATOMIC);
8021 if (!new_fltr)
8022 return -ENOMEM;
8023
8024 fkeys = &new_fltr->fkeys;
8025 if (!skb_flow_dissect_flow_keys(skb, fkeys, 0)) {
8026 rc = -EPROTONOSUPPORT;
8027 goto err_free;
8028 }
8029
Michael Chandda0e742016-12-29 12:13:40 -05008030 if ((fkeys->basic.n_proto != htons(ETH_P_IP) &&
8031 fkeys->basic.n_proto != htons(ETH_P_IPV6)) ||
Michael Chanc0c050c2015-10-22 16:01:17 -04008032 ((fkeys->basic.ip_proto != IPPROTO_TCP) &&
8033 (fkeys->basic.ip_proto != IPPROTO_UDP))) {
8034 rc = -EPROTONOSUPPORT;
8035 goto err_free;
8036 }
Michael Chandda0e742016-12-29 12:13:40 -05008037 if (fkeys->basic.n_proto == htons(ETH_P_IPV6) &&
8038 bp->hwrm_spec_code < 0x10601) {
8039 rc = -EPROTONOSUPPORT;
8040 goto err_free;
8041 }
Michael Chan61aad722017-02-12 19:18:14 -05008042 if ((fkeys->control.flags & FLOW_DIS_ENCAPSULATION) &&
8043 bp->hwrm_spec_code < 0x10601) {
8044 rc = -EPROTONOSUPPORT;
8045 goto err_free;
8046 }
Michael Chanc0c050c2015-10-22 16:01:17 -04008047
Michael Chana54c4d72016-07-25 12:33:35 -04008048 memcpy(new_fltr->dst_mac_addr, eth->h_dest, ETH_ALEN);
Michael Chanc0c050c2015-10-22 16:01:17 -04008049 memcpy(new_fltr->src_mac_addr, eth->h_source, ETH_ALEN);
8050
8051 idx = skb_get_hash_raw(skb) & BNXT_NTP_FLTR_HASH_MASK;
8052 head = &bp->ntp_fltr_hash_tbl[idx];
8053 rcu_read_lock();
8054 hlist_for_each_entry_rcu(fltr, head, hash) {
8055 if (bnxt_fltr_match(fltr, new_fltr)) {
8056 rcu_read_unlock();
8057 rc = 0;
8058 goto err_free;
8059 }
8060 }
8061 rcu_read_unlock();
8062
8063 spin_lock_bh(&bp->ntp_fltr_lock);
Michael Chan84e86b92015-11-05 16:25:50 -05008064 bit_id = bitmap_find_free_region(bp->ntp_fltr_bmap,
8065 BNXT_NTP_FLTR_MAX_FLTR, 0);
8066 if (bit_id < 0) {
Michael Chanc0c050c2015-10-22 16:01:17 -04008067 spin_unlock_bh(&bp->ntp_fltr_lock);
8068 rc = -ENOMEM;
8069 goto err_free;
8070 }
8071
Michael Chan84e86b92015-11-05 16:25:50 -05008072 new_fltr->sw_id = (u16)bit_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04008073 new_fltr->flow_id = flow_id;
Michael Chana54c4d72016-07-25 12:33:35 -04008074 new_fltr->l2_fltr_idx = l2_idx;
Michael Chanc0c050c2015-10-22 16:01:17 -04008075 new_fltr->rxq = rxq_index;
8076 hlist_add_head_rcu(&new_fltr->hash, head);
8077 bp->ntp_fltr_count++;
8078 spin_unlock_bh(&bp->ntp_fltr_lock);
8079
8080 set_bit(BNXT_RX_NTP_FLTR_SP_EVENT, &bp->sp_event);
Michael Chanc213eae2017-10-13 21:09:29 -04008081 bnxt_queue_sp_work(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04008082
8083 return new_fltr->sw_id;
8084
8085err_free:
8086 kfree(new_fltr);
8087 return rc;
8088}
8089
8090static void bnxt_cfg_ntp_filters(struct bnxt *bp)
8091{
8092 int i;
8093
8094 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
8095 struct hlist_head *head;
8096 struct hlist_node *tmp;
8097 struct bnxt_ntuple_filter *fltr;
8098 int rc;
8099
8100 head = &bp->ntp_fltr_hash_tbl[i];
8101 hlist_for_each_entry_safe(fltr, tmp, head, hash) {
8102 bool del = false;
8103
8104 if (test_bit(BNXT_FLTR_VALID, &fltr->state)) {
8105 if (rps_may_expire_flow(bp->dev, fltr->rxq,
8106 fltr->flow_id,
8107 fltr->sw_id)) {
8108 bnxt_hwrm_cfa_ntuple_filter_free(bp,
8109 fltr);
8110 del = true;
8111 }
8112 } else {
8113 rc = bnxt_hwrm_cfa_ntuple_filter_alloc(bp,
8114 fltr);
8115 if (rc)
8116 del = true;
8117 else
8118 set_bit(BNXT_FLTR_VALID, &fltr->state);
8119 }
8120
8121 if (del) {
8122 spin_lock_bh(&bp->ntp_fltr_lock);
8123 hlist_del_rcu(&fltr->hash);
8124 bp->ntp_fltr_count--;
8125 spin_unlock_bh(&bp->ntp_fltr_lock);
8126 synchronize_rcu();
8127 clear_bit(fltr->sw_id, bp->ntp_fltr_bmap);
8128 kfree(fltr);
8129 }
8130 }
8131 }
Jeffrey Huang19241362016-02-26 04:00:00 -05008132 if (test_and_clear_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT, &bp->sp_event))
8133 netdev_info(bp->dev, "Receive PF driver unload event!");
Michael Chanc0c050c2015-10-22 16:01:17 -04008134}
8135
8136#else
8137
8138static void bnxt_cfg_ntp_filters(struct bnxt *bp)
8139{
8140}
8141
8142#endif /* CONFIG_RFS_ACCEL */
8143
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008144static void bnxt_udp_tunnel_add(struct net_device *dev,
8145 struct udp_tunnel_info *ti)
Michael Chanc0c050c2015-10-22 16:01:17 -04008146{
8147 struct bnxt *bp = netdev_priv(dev);
8148
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008149 if (ti->sa_family != AF_INET6 && ti->sa_family != AF_INET)
8150 return;
8151
Michael Chanc0c050c2015-10-22 16:01:17 -04008152 if (!netif_running(dev))
8153 return;
8154
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008155 switch (ti->type) {
8156 case UDP_TUNNEL_TYPE_VXLAN:
8157 if (bp->vxlan_port_cnt && bp->vxlan_port != ti->port)
8158 return;
Michael Chanc0c050c2015-10-22 16:01:17 -04008159
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008160 bp->vxlan_port_cnt++;
8161 if (bp->vxlan_port_cnt == 1) {
8162 bp->vxlan_port = ti->port;
8163 set_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT, &bp->sp_event);
Michael Chanc213eae2017-10-13 21:09:29 -04008164 bnxt_queue_sp_work(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04008165 }
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008166 break;
Alexander Duyck7cdd5fc2016-06-16 12:21:36 -07008167 case UDP_TUNNEL_TYPE_GENEVE:
8168 if (bp->nge_port_cnt && bp->nge_port != ti->port)
8169 return;
8170
8171 bp->nge_port_cnt++;
8172 if (bp->nge_port_cnt == 1) {
8173 bp->nge_port = ti->port;
8174 set_bit(BNXT_GENEVE_ADD_PORT_SP_EVENT, &bp->sp_event);
8175 }
8176 break;
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008177 default:
8178 return;
Michael Chanc0c050c2015-10-22 16:01:17 -04008179 }
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008180
Michael Chanc213eae2017-10-13 21:09:29 -04008181 bnxt_queue_sp_work(bp);
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008182}
8183
8184static void bnxt_udp_tunnel_del(struct net_device *dev,
8185 struct udp_tunnel_info *ti)
8186{
8187 struct bnxt *bp = netdev_priv(dev);
8188
8189 if (ti->sa_family != AF_INET6 && ti->sa_family != AF_INET)
8190 return;
8191
8192 if (!netif_running(dev))
8193 return;
8194
8195 switch (ti->type) {
8196 case UDP_TUNNEL_TYPE_VXLAN:
8197 if (!bp->vxlan_port_cnt || bp->vxlan_port != ti->port)
8198 return;
8199 bp->vxlan_port_cnt--;
8200
8201 if (bp->vxlan_port_cnt != 0)
8202 return;
8203
8204 set_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT, &bp->sp_event);
8205 break;
Alexander Duyck7cdd5fc2016-06-16 12:21:36 -07008206 case UDP_TUNNEL_TYPE_GENEVE:
8207 if (!bp->nge_port_cnt || bp->nge_port != ti->port)
8208 return;
8209 bp->nge_port_cnt--;
8210
8211 if (bp->nge_port_cnt != 0)
8212 return;
8213
8214 set_bit(BNXT_GENEVE_DEL_PORT_SP_EVENT, &bp->sp_event);
8215 break;
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008216 default:
8217 return;
8218 }
8219
Michael Chanc213eae2017-10-13 21:09:29 -04008220 bnxt_queue_sp_work(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04008221}
8222
Michael Chan39d8ba22017-07-24 12:34:22 -04008223static int bnxt_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
8224 struct net_device *dev, u32 filter_mask,
8225 int nlflags)
8226{
8227 struct bnxt *bp = netdev_priv(dev);
8228
8229 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, bp->br_mode, 0, 0,
8230 nlflags, filter_mask, NULL);
8231}
8232
8233static int bnxt_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh,
8234 u16 flags)
8235{
8236 struct bnxt *bp = netdev_priv(dev);
8237 struct nlattr *attr, *br_spec;
8238 int rem, rc = 0;
8239
8240 if (bp->hwrm_spec_code < 0x10708 || !BNXT_SINGLE_PF(bp))
8241 return -EOPNOTSUPP;
8242
8243 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
8244 if (!br_spec)
8245 return -EINVAL;
8246
8247 nla_for_each_nested(attr, br_spec, rem) {
8248 u16 mode;
8249
8250 if (nla_type(attr) != IFLA_BRIDGE_MODE)
8251 continue;
8252
8253 if (nla_len(attr) < sizeof(mode))
8254 return -EINVAL;
8255
8256 mode = nla_get_u16(attr);
8257 if (mode == bp->br_mode)
8258 break;
8259
8260 rc = bnxt_hwrm_set_br_mode(bp, mode);
8261 if (!rc)
8262 bp->br_mode = mode;
8263 break;
8264 }
8265 return rc;
8266}
8267
Sathya Perlac124a622017-07-24 12:34:29 -04008268static int bnxt_get_phys_port_name(struct net_device *dev, char *buf,
8269 size_t len)
8270{
8271 struct bnxt *bp = netdev_priv(dev);
8272 int rc;
8273
8274 /* The PF and it's VF-reps only support the switchdev framework */
8275 if (!BNXT_PF(bp))
8276 return -EOPNOTSUPP;
8277
Sathya Perla53f70b82017-07-25 13:28:41 -04008278 rc = snprintf(buf, len, "p%d", bp->pf.port_id);
Sathya Perlac124a622017-07-24 12:34:29 -04008279
8280 if (rc >= len)
8281 return -EOPNOTSUPP;
8282 return 0;
8283}
8284
8285int bnxt_port_attr_get(struct bnxt *bp, struct switchdev_attr *attr)
8286{
8287 if (bp->eswitch_mode != DEVLINK_ESWITCH_MODE_SWITCHDEV)
8288 return -EOPNOTSUPP;
8289
8290 /* The PF and it's VF-reps only support the switchdev framework */
8291 if (!BNXT_PF(bp))
8292 return -EOPNOTSUPP;
8293
8294 switch (attr->id) {
8295 case SWITCHDEV_ATTR_ID_PORT_PARENT_ID:
Sathya Perladd4ea1d2018-01-17 03:21:16 -05008296 attr->u.ppid.id_len = sizeof(bp->switch_id);
8297 memcpy(attr->u.ppid.id, bp->switch_id, attr->u.ppid.id_len);
Sathya Perlac124a622017-07-24 12:34:29 -04008298 break;
8299 default:
8300 return -EOPNOTSUPP;
8301 }
8302 return 0;
8303}
8304
8305static int bnxt_swdev_port_attr_get(struct net_device *dev,
8306 struct switchdev_attr *attr)
8307{
8308 return bnxt_port_attr_get(netdev_priv(dev), attr);
8309}
8310
8311static const struct switchdev_ops bnxt_switchdev_ops = {
8312 .switchdev_port_attr_get = bnxt_swdev_port_attr_get
8313};
8314
Michael Chanc0c050c2015-10-22 16:01:17 -04008315static const struct net_device_ops bnxt_netdev_ops = {
8316 .ndo_open = bnxt_open,
8317 .ndo_start_xmit = bnxt_start_xmit,
8318 .ndo_stop = bnxt_close,
8319 .ndo_get_stats64 = bnxt_get_stats64,
8320 .ndo_set_rx_mode = bnxt_set_rx_mode,
8321 .ndo_do_ioctl = bnxt_ioctl,
8322 .ndo_validate_addr = eth_validate_addr,
8323 .ndo_set_mac_address = bnxt_change_mac_addr,
8324 .ndo_change_mtu = bnxt_change_mtu,
8325 .ndo_fix_features = bnxt_fix_features,
8326 .ndo_set_features = bnxt_set_features,
8327 .ndo_tx_timeout = bnxt_tx_timeout,
8328#ifdef CONFIG_BNXT_SRIOV
8329 .ndo_get_vf_config = bnxt_get_vf_config,
8330 .ndo_set_vf_mac = bnxt_set_vf_mac,
8331 .ndo_set_vf_vlan = bnxt_set_vf_vlan,
8332 .ndo_set_vf_rate = bnxt_set_vf_bw,
8333 .ndo_set_vf_link_state = bnxt_set_vf_link_state,
8334 .ndo_set_vf_spoofchk = bnxt_set_vf_spoofchk,
Vasundhara Volam746df132018-03-31 13:54:10 -04008335 .ndo_set_vf_trust = bnxt_set_vf_trust,
Michael Chanc0c050c2015-10-22 16:01:17 -04008336#endif
8337#ifdef CONFIG_NET_POLL_CONTROLLER
8338 .ndo_poll_controller = bnxt_poll_controller,
8339#endif
8340 .ndo_setup_tc = bnxt_setup_tc,
8341#ifdef CONFIG_RFS_ACCEL
8342 .ndo_rx_flow_steer = bnxt_rx_flow_steer,
8343#endif
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008344 .ndo_udp_tunnel_add = bnxt_udp_tunnel_add,
8345 .ndo_udp_tunnel_del = bnxt_udp_tunnel_del,
Jakub Kicinskif4e63522017-11-03 13:56:16 -07008346 .ndo_bpf = bnxt_xdp,
Michael Chan39d8ba22017-07-24 12:34:22 -04008347 .ndo_bridge_getlink = bnxt_bridge_getlink,
8348 .ndo_bridge_setlink = bnxt_bridge_setlink,
Sathya Perlac124a622017-07-24 12:34:29 -04008349 .ndo_get_phys_port_name = bnxt_get_phys_port_name
Michael Chanc0c050c2015-10-22 16:01:17 -04008350};
8351
8352static void bnxt_remove_one(struct pci_dev *pdev)
8353{
8354 struct net_device *dev = pci_get_drvdata(pdev);
8355 struct bnxt *bp = netdev_priv(dev);
8356
Sathya Perla4ab0c6a2017-07-24 12:34:27 -04008357 if (BNXT_PF(bp)) {
Michael Chanc0c050c2015-10-22 16:01:17 -04008358 bnxt_sriov_disable(bp);
Sathya Perla4ab0c6a2017-07-24 12:34:27 -04008359 bnxt_dl_unregister(bp);
8360 }
Michael Chanc0c050c2015-10-22 16:01:17 -04008361
Satish Baddipadige6316ea62016-03-07 15:38:48 -05008362 pci_disable_pcie_error_reporting(pdev);
Michael Chanc0c050c2015-10-22 16:01:17 -04008363 unregister_netdev(dev);
Sathya Perla2ae74082017-08-28 13:40:33 -04008364 bnxt_shutdown_tc(bp);
Michael Chanc213eae2017-10-13 21:09:29 -04008365 bnxt_cancel_sp_work(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04008366 bp->sp_event = 0;
8367
Michael Chan78095922016-12-07 00:26:16 -05008368 bnxt_clear_int_mode(bp);
Jeffrey Huangbe58a0d2015-12-27 18:19:18 -05008369 bnxt_hwrm_func_drv_unrgtr(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04008370 bnxt_free_hwrm_resources(bp);
Deepak Khungare605db82017-05-29 19:06:04 -04008371 bnxt_free_hwrm_short_cmd_req(bp);
Michael Chaneb513652017-04-04 18:14:12 -04008372 bnxt_ethtool_free(bp);
Michael Chan7df4ae92016-12-02 21:17:17 -05008373 bnxt_dcb_free(bp);
Michael Chana588e452016-12-07 00:26:21 -05008374 kfree(bp->edev);
8375 bp->edev = NULL;
Sathya Perla17086392017-02-20 19:25:18 -05008376 bnxt_cleanup_pci(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04008377 free_netdev(dev);
Michael Chanc0c050c2015-10-22 16:01:17 -04008378}
8379
8380static int bnxt_probe_phy(struct bnxt *bp)
8381{
8382 int rc = 0;
8383 struct bnxt_link_info *link_info = &bp->link_info;
Michael Chanc0c050c2015-10-22 16:01:17 -04008384
Michael Chan170ce012016-04-05 14:08:57 -04008385 rc = bnxt_hwrm_phy_qcaps(bp);
8386 if (rc) {
8387 netdev_err(bp->dev, "Probe phy can't get phy capabilities (rc: %x)\n",
8388 rc);
8389 return rc;
8390 }
Michael Chane2dc9b62017-10-13 21:09:30 -04008391 mutex_init(&bp->link_lock);
Michael Chan170ce012016-04-05 14:08:57 -04008392
Michael Chanc0c050c2015-10-22 16:01:17 -04008393 rc = bnxt_update_link(bp, false);
8394 if (rc) {
8395 netdev_err(bp->dev, "Probe phy can't update link (rc: %x)\n",
8396 rc);
8397 return rc;
8398 }
8399
Michael Chan93ed8112016-06-13 02:25:37 -04008400 /* Older firmware does not have supported_auto_speeds, so assume
8401 * that all supported speeds can be autonegotiated.
8402 */
8403 if (link_info->auto_link_speeds && !link_info->support_auto_speeds)
8404 link_info->support_auto_speeds = link_info->support_speeds;
8405
Michael Chanc0c050c2015-10-22 16:01:17 -04008406 /*initialize the ethool setting copy with NVM settings */
Michael Chan0d8abf02016-02-10 17:33:47 -05008407 if (BNXT_AUTO_MODE(link_info->auto_mode)) {
Michael Chanc9ee9512016-04-05 14:08:56 -04008408 link_info->autoneg = BNXT_AUTONEG_SPEED;
8409 if (bp->hwrm_spec_code >= 0x10201) {
8410 if (link_info->auto_pause_setting &
8411 PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE)
8412 link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
8413 } else {
8414 link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
8415 }
Michael Chan0d8abf02016-02-10 17:33:47 -05008416 link_info->advertising = link_info->auto_link_speeds;
Michael Chan0d8abf02016-02-10 17:33:47 -05008417 } else {
8418 link_info->req_link_speed = link_info->force_link_speed;
8419 link_info->req_duplex = link_info->duplex_setting;
Michael Chanc0c050c2015-10-22 16:01:17 -04008420 }
Michael Chanc9ee9512016-04-05 14:08:56 -04008421 if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL)
8422 link_info->req_flow_ctrl =
8423 link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH;
8424 else
8425 link_info->req_flow_ctrl = link_info->force_pause_setting;
Michael Chanc0c050c2015-10-22 16:01:17 -04008426 return rc;
8427}
8428
8429static int bnxt_get_max_irq(struct pci_dev *pdev)
8430{
8431 u16 ctrl;
8432
8433 if (!pdev->msix_cap)
8434 return 1;
8435
8436 pci_read_config_word(pdev, pdev->msix_cap + PCI_MSIX_FLAGS, &ctrl);
8437 return (ctrl & PCI_MSIX_FLAGS_QSIZE) + 1;
8438}
8439
Michael Chan6e6c5a52016-01-02 23:45:02 -05008440static void _bnxt_get_max_rings(struct bnxt *bp, int *max_rx, int *max_tx,
8441 int *max_cp)
Michael Chanc0c050c2015-10-22 16:01:17 -04008442{
Michael Chan6a4f2942018-01-17 03:21:06 -05008443 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
Michael Chan6e6c5a52016-01-02 23:45:02 -05008444 int max_ring_grps = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04008445
Michael Chan6a4f2942018-01-17 03:21:06 -05008446 *max_tx = hw_resc->max_tx_rings;
8447 *max_rx = hw_resc->max_rx_rings;
8448 *max_cp = min_t(int, hw_resc->max_irqs, hw_resc->max_cp_rings);
8449 *max_cp = min_t(int, *max_cp, hw_resc->max_stat_ctxs);
8450 max_ring_grps = hw_resc->max_hw_ring_grps;
Prashant Sreedharan76595192016-07-18 07:15:22 -04008451 if (BNXT_CHIP_TYPE_NITRO_A0(bp) && BNXT_PF(bp)) {
8452 *max_cp -= 1;
8453 *max_rx -= 2;
8454 }
Michael Chanc0c050c2015-10-22 16:01:17 -04008455 if (bp->flags & BNXT_FLAG_AGG_RINGS)
8456 *max_rx >>= 1;
Michael Chanb72d4a62015-12-27 18:19:27 -05008457 *max_rx = min_t(int, *max_rx, max_ring_grps);
Michael Chan6e6c5a52016-01-02 23:45:02 -05008458}
8459
8460int bnxt_get_max_rings(struct bnxt *bp, int *max_rx, int *max_tx, bool shared)
8461{
8462 int rx, tx, cp;
8463
8464 _bnxt_get_max_rings(bp, &rx, &tx, &cp);
8465 if (!rx || !tx || !cp)
8466 return -ENOMEM;
8467
8468 *max_rx = rx;
8469 *max_tx = tx;
8470 return bnxt_trim_rings(bp, max_rx, max_tx, cp, shared);
8471}
8472
Michael Chane4060d32016-12-07 00:26:19 -05008473static int bnxt_get_dflt_rings(struct bnxt *bp, int *max_rx, int *max_tx,
8474 bool shared)
8475{
8476 int rc;
8477
8478 rc = bnxt_get_max_rings(bp, max_rx, max_tx, shared);
Michael Chanbdbd1eb2016-12-29 12:13:43 -05008479 if (rc && (bp->flags & BNXT_FLAG_AGG_RINGS)) {
8480 /* Not enough rings, try disabling agg rings. */
8481 bp->flags &= ~BNXT_FLAG_AGG_RINGS;
8482 rc = bnxt_get_max_rings(bp, max_rx, max_tx, shared);
8483 if (rc)
8484 return rc;
8485 bp->flags |= BNXT_FLAG_NO_AGG_RINGS;
Michael Chan1054aee2017-12-16 03:09:42 -05008486 bp->dev->hw_features &= ~(NETIF_F_LRO | NETIF_F_GRO_HW);
8487 bp->dev->features &= ~(NETIF_F_LRO | NETIF_F_GRO_HW);
Michael Chanbdbd1eb2016-12-29 12:13:43 -05008488 bnxt_set_ring_params(bp);
8489 }
Michael Chane4060d32016-12-07 00:26:19 -05008490
8491 if (bp->flags & BNXT_FLAG_ROCE_CAP) {
8492 int max_cp, max_stat, max_irq;
8493
8494 /* Reserve minimum resources for RoCE */
8495 max_cp = bnxt_get_max_func_cp_rings(bp);
8496 max_stat = bnxt_get_max_func_stat_ctxs(bp);
8497 max_irq = bnxt_get_max_func_irqs(bp);
8498 if (max_cp <= BNXT_MIN_ROCE_CP_RINGS ||
8499 max_irq <= BNXT_MIN_ROCE_CP_RINGS ||
8500 max_stat <= BNXT_MIN_ROCE_STAT_CTXS)
8501 return 0;
8502
8503 max_cp -= BNXT_MIN_ROCE_CP_RINGS;
8504 max_irq -= BNXT_MIN_ROCE_CP_RINGS;
8505 max_stat -= BNXT_MIN_ROCE_STAT_CTXS;
8506 max_cp = min_t(int, max_cp, max_irq);
8507 max_cp = min_t(int, max_cp, max_stat);
8508 rc = bnxt_trim_rings(bp, max_rx, max_tx, max_cp, shared);
8509 if (rc)
8510 rc = 0;
8511 }
8512 return rc;
8513}
8514
Michael Chan58ea8012018-01-17 03:21:08 -05008515/* In initial default shared ring setting, each shared ring must have a
8516 * RX/TX ring pair.
8517 */
8518static void bnxt_trim_dflt_sh_rings(struct bnxt *bp)
8519{
8520 bp->cp_nr_rings = min_t(int, bp->tx_nr_rings_per_tc, bp->rx_nr_rings);
8521 bp->rx_nr_rings = bp->cp_nr_rings;
8522 bp->tx_nr_rings_per_tc = bp->cp_nr_rings;
8523 bp->tx_nr_rings = bp->tx_nr_rings_per_tc;
8524}
8525
Michael Chan702c2212017-05-29 19:06:10 -04008526static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh)
Michael Chan6e6c5a52016-01-02 23:45:02 -05008527{
8528 int dflt_rings, max_rx_rings, max_tx_rings, rc;
Michael Chan6e6c5a52016-01-02 23:45:02 -05008529
8530 if (sh)
8531 bp->flags |= BNXT_FLAG_SHARED_RINGS;
8532 dflt_rings = netif_get_num_default_rss_queues();
Michael Chan1d3ef132018-03-31 13:54:07 -04008533 /* Reduce default rings on multi-port cards so that total default
8534 * rings do not exceed CPU count.
8535 */
8536 if (bp->port_count > 1) {
8537 int max_rings =
8538 max_t(int, num_online_cpus() / bp->port_count, 1);
8539
8540 dflt_rings = min_t(int, dflt_rings, max_rings);
8541 }
Michael Chane4060d32016-12-07 00:26:19 -05008542 rc = bnxt_get_dflt_rings(bp, &max_rx_rings, &max_tx_rings, sh);
Michael Chan6e6c5a52016-01-02 23:45:02 -05008543 if (rc)
8544 return rc;
8545 bp->rx_nr_rings = min_t(int, dflt_rings, max_rx_rings);
8546 bp->tx_nr_rings_per_tc = min_t(int, dflt_rings, max_tx_rings);
Michael Chan58ea8012018-01-17 03:21:08 -05008547 if (sh)
8548 bnxt_trim_dflt_sh_rings(bp);
8549 else
8550 bp->cp_nr_rings = bp->tx_nr_rings_per_tc + bp->rx_nr_rings;
8551 bp->tx_nr_rings = bp->tx_nr_rings_per_tc;
Michael Chan391be5c2016-12-29 12:13:41 -05008552
Michael Chan674f50a2018-01-17 03:21:09 -05008553 rc = __bnxt_reserve_rings(bp);
Michael Chan391be5c2016-12-29 12:13:41 -05008554 if (rc)
8555 netdev_warn(bp->dev, "Unable to reserve tx rings\n");
Michael Chan58ea8012018-01-17 03:21:08 -05008556 bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
8557 if (sh)
8558 bnxt_trim_dflt_sh_rings(bp);
Michael Chan391be5c2016-12-29 12:13:41 -05008559
Michael Chan674f50a2018-01-17 03:21:09 -05008560 /* Rings may have been trimmed, re-reserve the trimmed rings. */
8561 if (bnxt_need_reserve_rings(bp)) {
8562 rc = __bnxt_reserve_rings(bp);
8563 if (rc)
8564 netdev_warn(bp->dev, "2nd rings reservation failed.\n");
8565 bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
8566 }
Michael Chan6e6c5a52016-01-02 23:45:02 -05008567 bp->num_stat_ctxs = bp->cp_nr_rings;
Prashant Sreedharan76595192016-07-18 07:15:22 -04008568 if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
8569 bp->rx_nr_rings++;
8570 bp->cp_nr_rings++;
8571 }
Michael Chan6e6c5a52016-01-02 23:45:02 -05008572 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04008573}
8574
Michael Chan80fcaf42018-01-17 03:21:05 -05008575int bnxt_restore_pf_fw_resources(struct bnxt *bp)
Michael Chan7b08f662016-12-07 00:26:18 -05008576{
Michael Chan80fcaf42018-01-17 03:21:05 -05008577 int rc;
8578
Michael Chan7b08f662016-12-07 00:26:18 -05008579 ASSERT_RTNL();
8580 bnxt_hwrm_func_qcaps(bp);
Venkat Duvvuru1a037782018-03-09 23:46:09 -05008581
8582 if (netif_running(bp->dev))
8583 __bnxt_close_nic(bp, true, false);
8584
Michael Chanec86f142018-03-31 13:54:21 -04008585 bnxt_ulp_irq_stop(bp);
Michael Chan80fcaf42018-01-17 03:21:05 -05008586 bnxt_clear_int_mode(bp);
8587 rc = bnxt_init_int_mode(bp);
Michael Chanec86f142018-03-31 13:54:21 -04008588 bnxt_ulp_irq_restart(bp, rc);
Venkat Duvvuru1a037782018-03-09 23:46:09 -05008589
8590 if (netif_running(bp->dev)) {
8591 if (rc)
8592 dev_close(bp->dev);
8593 else
8594 rc = bnxt_open_nic(bp, true, false);
8595 }
8596
Michael Chan80fcaf42018-01-17 03:21:05 -05008597 return rc;
Michael Chan7b08f662016-12-07 00:26:18 -05008598}
8599
Michael Chana22a6ac2017-08-23 19:34:05 -04008600static int bnxt_init_mac_addr(struct bnxt *bp)
8601{
8602 int rc = 0;
8603
8604 if (BNXT_PF(bp)) {
8605 memcpy(bp->dev->dev_addr, bp->pf.mac_addr, ETH_ALEN);
8606 } else {
8607#ifdef CONFIG_BNXT_SRIOV
8608 struct bnxt_vf_info *vf = &bp->vf;
8609
8610 if (is_valid_ether_addr(vf->mac_addr)) {
Vasundhara Volam91cdda42018-01-17 03:21:14 -05008611 /* overwrite netdev dev_addr with admin VF MAC */
Michael Chana22a6ac2017-08-23 19:34:05 -04008612 memcpy(bp->dev->dev_addr, vf->mac_addr, ETH_ALEN);
8613 } else {
8614 eth_hw_addr_random(bp->dev);
8615 rc = bnxt_approve_mac(bp, bp->dev->dev_addr);
8616 }
8617#endif
8618 }
8619 return rc;
8620}
8621
Ajit Khaparde90c4f782016-05-15 03:04:45 -04008622static void bnxt_parse_log_pcie_link(struct bnxt *bp)
8623{
8624 enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN;
8625 enum pci_bus_speed speed = PCI_SPEED_UNKNOWN;
8626
Vasundhara Volam7ab07602017-10-13 21:09:31 -04008627 if (pcie_get_minimum_link(pci_physfn(bp->pdev), &speed, &width) ||
Ajit Khaparde90c4f782016-05-15 03:04:45 -04008628 speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN)
8629 netdev_info(bp->dev, "Failed to determine PCIe Link Info\n");
8630 else
8631 netdev_info(bp->dev, "PCIe: Speed %s Width x%d\n",
8632 speed == PCIE_SPEED_2_5GT ? "2.5GT/s" :
8633 speed == PCIE_SPEED_5_0GT ? "5.0GT/s" :
8634 speed == PCIE_SPEED_8_0GT ? "8.0GT/s" :
8635 "Unknown", width);
8636}
8637
Michael Chanc0c050c2015-10-22 16:01:17 -04008638static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
8639{
8640 static int version_printed;
8641 struct net_device *dev;
8642 struct bnxt *bp;
Michael Chan6e6c5a52016-01-02 23:45:02 -05008643 int rc, max_irqs;
Michael Chanc0c050c2015-10-22 16:01:17 -04008644
Ray Jui4e003382017-02-20 19:25:16 -05008645 if (pci_is_bridge(pdev))
Prashant Sreedharanfa853dd2016-07-18 07:15:25 -04008646 return -ENODEV;
8647
Michael Chanc0c050c2015-10-22 16:01:17 -04008648 if (version_printed++ == 0)
8649 pr_info("%s", version);
8650
8651 max_irqs = bnxt_get_max_irq(pdev);
8652 dev = alloc_etherdev_mq(sizeof(*bp), max_irqs);
8653 if (!dev)
8654 return -ENOMEM;
8655
8656 bp = netdev_priv(dev);
8657
8658 if (bnxt_vf_pciid(ent->driver_data))
8659 bp->flags |= BNXT_FLAG_VF;
8660
Michael Chan2bcfa6f2015-12-27 18:19:24 -05008661 if (pdev->msix_cap)
Michael Chanc0c050c2015-10-22 16:01:17 -04008662 bp->flags |= BNXT_FLAG_MSIX_CAP;
Michael Chanc0c050c2015-10-22 16:01:17 -04008663
8664 rc = bnxt_init_board(pdev, dev);
8665 if (rc < 0)
8666 goto init_err_free;
8667
8668 dev->netdev_ops = &bnxt_netdev_ops;
8669 dev->watchdog_timeo = BNXT_TX_TIMEOUT;
8670 dev->ethtool_ops = &bnxt_ethtool_ops;
David S. Millerbc880552017-07-24 21:20:16 -07008671 SWITCHDEV_SET_OPS(dev, &bnxt_switchdev_ops);
Michael Chanc0c050c2015-10-22 16:01:17 -04008672 pci_set_drvdata(pdev, dev);
8673
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04008674 rc = bnxt_alloc_hwrm_resources(bp);
8675 if (rc)
Sathya Perla17086392017-02-20 19:25:18 -05008676 goto init_err_pci_clean;
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04008677
8678 mutex_init(&bp->hwrm_cmd_lock);
8679 rc = bnxt_hwrm_ver_get(bp);
8680 if (rc)
Sathya Perla17086392017-02-20 19:25:18 -05008681 goto init_err_pci_clean;
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04008682
Deepak Khungare605db82017-05-29 19:06:04 -04008683 if (bp->flags & BNXT_FLAG_SHORT_CMD) {
8684 rc = bnxt_alloc_hwrm_short_cmd_req(bp);
8685 if (rc)
8686 goto init_err_pci_clean;
8687 }
8688
Michael Chan3c2217a2017-03-08 18:44:32 -05008689 rc = bnxt_hwrm_func_reset(bp);
8690 if (rc)
8691 goto init_err_pci_clean;
8692
Rob Swindell5ac67d82016-09-19 03:58:03 -04008693 bnxt_hwrm_fw_set_time(bp);
8694
Michael Chanc0c050c2015-10-22 16:01:17 -04008695 dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
8696 NETIF_F_TSO | NETIF_F_TSO6 |
8697 NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_GRE |
Tom Herbert7e133182016-05-18 09:06:10 -07008698 NETIF_F_GSO_IPXIP4 |
Alexander Duyck152971e2016-05-02 09:38:55 -07008699 NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_GSO_GRE_CSUM |
8700 NETIF_F_GSO_PARTIAL | NETIF_F_RXHASH |
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04008701 NETIF_F_RXCSUM | NETIF_F_GRO;
8702
8703 if (!BNXT_CHIP_TYPE_NITRO_A0(bp))
8704 dev->hw_features |= NETIF_F_LRO;
Michael Chanc0c050c2015-10-22 16:01:17 -04008705
Michael Chanc0c050c2015-10-22 16:01:17 -04008706 dev->hw_enc_features =
8707 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
8708 NETIF_F_TSO | NETIF_F_TSO6 |
8709 NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_GRE |
Alexander Duyck152971e2016-05-02 09:38:55 -07008710 NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_GSO_GRE_CSUM |
Tom Herbert7e133182016-05-18 09:06:10 -07008711 NETIF_F_GSO_IPXIP4 | NETIF_F_GSO_PARTIAL;
Alexander Duyck152971e2016-05-02 09:38:55 -07008712 dev->gso_partial_features = NETIF_F_GSO_UDP_TUNNEL_CSUM |
8713 NETIF_F_GSO_GRE_CSUM;
Michael Chanc0c050c2015-10-22 16:01:17 -04008714 dev->vlan_features = dev->hw_features | NETIF_F_HIGHDMA;
8715 dev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX |
8716 NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_STAG_TX;
Michael Chan1054aee2017-12-16 03:09:42 -05008717 if (!BNXT_CHIP_TYPE_NITRO_A0(bp))
8718 dev->hw_features |= NETIF_F_GRO_HW;
Michael Chanc0c050c2015-10-22 16:01:17 -04008719 dev->features |= dev->hw_features | NETIF_F_HIGHDMA;
Michael Chan1054aee2017-12-16 03:09:42 -05008720 if (dev->features & NETIF_F_GRO_HW)
8721 dev->features &= ~NETIF_F_LRO;
Michael Chanc0c050c2015-10-22 16:01:17 -04008722 dev->priv_flags |= IFF_UNICAST_FLT;
8723
8724#ifdef CONFIG_BNXT_SRIOV
8725 init_waitqueue_head(&bp->sriov_cfg_wait);
Sathya Perla4ab0c6a2017-07-24 12:34:27 -04008726 mutex_init(&bp->sriov_lock);
Michael Chanc0c050c2015-10-22 16:01:17 -04008727#endif
Michael Chan309369c2016-06-13 02:25:34 -04008728 bp->gro_func = bnxt_gro_func_5730x;
Michael Chan3284f9e2017-05-29 19:06:07 -04008729 if (BNXT_CHIP_P4_PLUS(bp))
Michael Chan94758f82016-06-13 02:25:35 -04008730 bp->gro_func = bnxt_gro_func_5731x;
Michael Chan434c9752017-05-29 19:06:08 -04008731 else
8732 bp->flags |= BNXT_FLAG_DOUBLE_DB;
Michael Chan309369c2016-06-13 02:25:34 -04008733
Michael Chanc0c050c2015-10-22 16:01:17 -04008734 rc = bnxt_hwrm_func_drv_rgtr(bp);
8735 if (rc)
Sathya Perla17086392017-02-20 19:25:18 -05008736 goto init_err_pci_clean;
Michael Chanc0c050c2015-10-22 16:01:17 -04008737
Michael Chana1653b12016-12-07 00:26:20 -05008738 rc = bnxt_hwrm_func_rgtr_async_events(bp, NULL, 0);
8739 if (rc)
Sathya Perla17086392017-02-20 19:25:18 -05008740 goto init_err_pci_clean;
Michael Chana1653b12016-12-07 00:26:20 -05008741
Michael Chana588e452016-12-07 00:26:21 -05008742 bp->ulp_probe = bnxt_ulp_probe;
8743
Michael Chanc0c050c2015-10-22 16:01:17 -04008744 /* Get the MAX capabilities for this function */
8745 rc = bnxt_hwrm_func_qcaps(bp);
8746 if (rc) {
8747 netdev_err(bp->dev, "hwrm query capability failure rc: %x\n",
8748 rc);
8749 rc = -1;
Sathya Perla17086392017-02-20 19:25:18 -05008750 goto init_err_pci_clean;
Michael Chanc0c050c2015-10-22 16:01:17 -04008751 }
Michael Chana22a6ac2017-08-23 19:34:05 -04008752 rc = bnxt_init_mac_addr(bp);
8753 if (rc) {
8754 dev_err(&pdev->dev, "Unable to initialize mac address.\n");
8755 rc = -EADDRNOTAVAIL;
8756 goto init_err_pci_clean;
8757 }
Michael Chanc0c050c2015-10-22 16:01:17 -04008758 rc = bnxt_hwrm_queue_qportcfg(bp);
8759 if (rc) {
8760 netdev_err(bp->dev, "hwrm query qportcfg failure rc: %x\n",
8761 rc);
8762 rc = -1;
Sathya Perla17086392017-02-20 19:25:18 -05008763 goto init_err_pci_clean;
Michael Chanc0c050c2015-10-22 16:01:17 -04008764 }
8765
Satish Baddipadige567b2ab2016-06-13 02:25:31 -04008766 bnxt_hwrm_func_qcfg(bp);
Michael Chan5ad2cbe2017-01-13 01:32:03 -05008767 bnxt_hwrm_port_led_qcaps(bp);
Michael Chaneb513652017-04-04 18:14:12 -04008768 bnxt_ethtool_init(bp);
Michael Chan87fe6032017-05-16 16:39:43 -04008769 bnxt_dcb_init(bp);
Satish Baddipadige567b2ab2016-06-13 02:25:31 -04008770
Michael Chan7eb9bb32017-10-26 11:51:25 -04008771 /* MTU range: 60 - FW defined max */
8772 dev->min_mtu = ETH_ZLEN;
8773 dev->max_mtu = bp->max_mtu;
8774
Michael Chand5430d32017-08-28 13:40:31 -04008775 rc = bnxt_probe_phy(bp);
8776 if (rc)
8777 goto init_err_pci_clean;
8778
Michael Chanc61fb992017-02-06 16:55:36 -05008779 bnxt_set_rx_skb_mode(bp, false);
Michael Chanc0c050c2015-10-22 16:01:17 -04008780 bnxt_set_tpa_flags(bp);
8781 bnxt_set_ring_params(bp);
Michael Chan33c26572016-12-07 00:26:15 -05008782 bnxt_set_max_func_irqs(bp, max_irqs);
Michael Chan702c2212017-05-29 19:06:10 -04008783 rc = bnxt_set_dflt_rings(bp, true);
Michael Chanbdbd1eb2016-12-29 12:13:43 -05008784 if (rc) {
8785 netdev_err(bp->dev, "Not enough rings available.\n");
8786 rc = -ENOMEM;
Sathya Perla17086392017-02-20 19:25:18 -05008787 goto init_err_pci_clean;
Michael Chanbdbd1eb2016-12-29 12:13:43 -05008788 }
Michael Chanc0c050c2015-10-22 16:01:17 -04008789
Michael Chan87da7f72016-11-16 21:13:09 -05008790 /* Default RSS hash cfg. */
8791 bp->rss_hash_cfg = VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4 |
8792 VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4 |
8793 VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6 |
8794 VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6;
Michael Chan3284f9e2017-05-29 19:06:07 -04008795 if (BNXT_CHIP_P4_PLUS(bp) && bp->hwrm_spec_code >= 0x10501) {
Michael Chan87da7f72016-11-16 21:13:09 -05008796 bp->flags |= BNXT_FLAG_UDP_RSS_CAP;
8797 bp->rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4 |
8798 VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6;
8799 }
8800
Michael Chan8fdefd62016-12-29 12:13:36 -05008801 bnxt_hwrm_vnic_qcaps(bp);
Michael Chan8079e8f2016-12-29 12:13:37 -05008802 if (bnxt_rfs_supported(bp)) {
Michael Chan2bcfa6f2015-12-27 18:19:24 -05008803 dev->hw_features |= NETIF_F_NTUPLE;
8804 if (bnxt_rfs_capable(bp)) {
8805 bp->flags |= BNXT_FLAG_RFS;
8806 dev->features |= NETIF_F_NTUPLE;
8807 }
8808 }
8809
Michael Chanc0c050c2015-10-22 16:01:17 -04008810 if (dev->hw_features & NETIF_F_HW_VLAN_CTAG_RX)
8811 bp->flags |= BNXT_FLAG_STRIP_VLAN;
8812
Michael Chan78095922016-12-07 00:26:16 -05008813 rc = bnxt_init_int_mode(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04008814 if (rc)
Sathya Perla17086392017-02-20 19:25:18 -05008815 goto init_err_pci_clean;
Michael Chanc0c050c2015-10-22 16:01:17 -04008816
Michael Chan832aed12018-03-09 23:46:07 -05008817 /* No TC has been set yet and rings may have been trimmed due to
8818 * limited MSIX, so we re-initialize the TX rings per TC.
8819 */
8820 bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
8821
Michael Chanc1ef1462017-04-04 18:14:07 -04008822 bnxt_get_wol_settings(bp);
Michael Chand196ece2017-04-04 18:14:08 -04008823 if (bp->flags & BNXT_FLAG_WOL_CAP)
8824 device_set_wakeup_enable(&pdev->dev, bp->wol);
8825 else
8826 device_set_wakeup_capable(&pdev->dev, false);
Michael Chanc1ef1462017-04-04 18:14:07 -04008827
Michael Chanc3480a62018-01-17 03:21:15 -05008828 bnxt_hwrm_set_cache_line_size(bp, cache_line_size());
8829
Michael Chanc213eae2017-10-13 21:09:29 -04008830 if (BNXT_PF(bp)) {
8831 if (!bnxt_pf_wq) {
8832 bnxt_pf_wq =
8833 create_singlethread_workqueue("bnxt_pf_wq");
8834 if (!bnxt_pf_wq) {
8835 dev_err(&pdev->dev, "Unable to create workqueue.\n");
8836 goto init_err_pci_clean;
8837 }
8838 }
Sathya Perla2ae74082017-08-28 13:40:33 -04008839 bnxt_init_tc(bp);
Michael Chanc213eae2017-10-13 21:09:29 -04008840 }
Sathya Perla2ae74082017-08-28 13:40:33 -04008841
Michael Chan78095922016-12-07 00:26:16 -05008842 rc = register_netdev(dev);
8843 if (rc)
Sathya Perla2ae74082017-08-28 13:40:33 -04008844 goto init_err_cleanup_tc;
Michael Chan78095922016-12-07 00:26:16 -05008845
Sathya Perla4ab0c6a2017-07-24 12:34:27 -04008846 if (BNXT_PF(bp))
8847 bnxt_dl_register(bp);
8848
Michael Chanc0c050c2015-10-22 16:01:17 -04008849 netdev_info(dev, "%s found at mem %lx, node addr %pM\n",
8850 board_info[ent->driver_data].name,
8851 (long)pci_resource_start(pdev, 0), dev->dev_addr);
8852
Ajit Khaparde90c4f782016-05-15 03:04:45 -04008853 bnxt_parse_log_pcie_link(bp);
8854
Michael Chanc0c050c2015-10-22 16:01:17 -04008855 return 0;
8856
Sathya Perla2ae74082017-08-28 13:40:33 -04008857init_err_cleanup_tc:
8858 bnxt_shutdown_tc(bp);
Michael Chan78095922016-12-07 00:26:16 -05008859 bnxt_clear_int_mode(bp);
8860
Sathya Perla17086392017-02-20 19:25:18 -05008861init_err_pci_clean:
8862 bnxt_cleanup_pci(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04008863
8864init_err_free:
8865 free_netdev(dev);
8866 return rc;
8867}
8868
Michael Chand196ece2017-04-04 18:14:08 -04008869static void bnxt_shutdown(struct pci_dev *pdev)
8870{
8871 struct net_device *dev = pci_get_drvdata(pdev);
8872 struct bnxt *bp;
8873
8874 if (!dev)
8875 return;
8876
8877 rtnl_lock();
8878 bp = netdev_priv(dev);
8879 if (!bp)
8880 goto shutdown_exit;
8881
8882 if (netif_running(dev))
8883 dev_close(dev);
8884
Ray Juia7f3f932017-12-01 03:13:02 -05008885 bnxt_ulp_shutdown(bp);
8886
Michael Chand196ece2017-04-04 18:14:08 -04008887 if (system_state == SYSTEM_POWER_OFF) {
8888 bnxt_clear_int_mode(bp);
8889 pci_wake_from_d3(pdev, bp->wol);
8890 pci_set_power_state(pdev, PCI_D3hot);
8891 }
8892
8893shutdown_exit:
8894 rtnl_unlock();
8895}
8896
Michael Chanf65a2042017-04-04 18:14:11 -04008897#ifdef CONFIG_PM_SLEEP
8898static int bnxt_suspend(struct device *device)
8899{
8900 struct pci_dev *pdev = to_pci_dev(device);
8901 struct net_device *dev = pci_get_drvdata(pdev);
8902 struct bnxt *bp = netdev_priv(dev);
8903 int rc = 0;
8904
8905 rtnl_lock();
8906 if (netif_running(dev)) {
8907 netif_device_detach(dev);
8908 rc = bnxt_close(dev);
8909 }
8910 bnxt_hwrm_func_drv_unrgtr(bp);
8911 rtnl_unlock();
8912 return rc;
8913}
8914
8915static int bnxt_resume(struct device *device)
8916{
8917 struct pci_dev *pdev = to_pci_dev(device);
8918 struct net_device *dev = pci_get_drvdata(pdev);
8919 struct bnxt *bp = netdev_priv(dev);
8920 int rc = 0;
8921
8922 rtnl_lock();
8923 if (bnxt_hwrm_ver_get(bp) || bnxt_hwrm_func_drv_rgtr(bp)) {
8924 rc = -ENODEV;
8925 goto resume_exit;
8926 }
8927 rc = bnxt_hwrm_func_reset(bp);
8928 if (rc) {
8929 rc = -EBUSY;
8930 goto resume_exit;
8931 }
8932 bnxt_get_wol_settings(bp);
8933 if (netif_running(dev)) {
8934 rc = bnxt_open(dev);
8935 if (!rc)
8936 netif_device_attach(dev);
8937 }
8938
8939resume_exit:
8940 rtnl_unlock();
8941 return rc;
8942}
8943
8944static SIMPLE_DEV_PM_OPS(bnxt_pm_ops, bnxt_suspend, bnxt_resume);
8945#define BNXT_PM_OPS (&bnxt_pm_ops)
8946
8947#else
8948
8949#define BNXT_PM_OPS NULL
8950
8951#endif /* CONFIG_PM_SLEEP */
8952
Satish Baddipadige6316ea62016-03-07 15:38:48 -05008953/**
8954 * bnxt_io_error_detected - called when PCI error is detected
8955 * @pdev: Pointer to PCI device
8956 * @state: The current pci connection state
8957 *
8958 * This function is called after a PCI bus error affecting
8959 * this device has been detected.
8960 */
8961static pci_ers_result_t bnxt_io_error_detected(struct pci_dev *pdev,
8962 pci_channel_state_t state)
8963{
8964 struct net_device *netdev = pci_get_drvdata(pdev);
Michael Chana588e452016-12-07 00:26:21 -05008965 struct bnxt *bp = netdev_priv(netdev);
Satish Baddipadige6316ea62016-03-07 15:38:48 -05008966
8967 netdev_info(netdev, "PCI I/O error detected\n");
8968
8969 rtnl_lock();
8970 netif_device_detach(netdev);
8971
Michael Chana588e452016-12-07 00:26:21 -05008972 bnxt_ulp_stop(bp);
8973
Satish Baddipadige6316ea62016-03-07 15:38:48 -05008974 if (state == pci_channel_io_perm_failure) {
8975 rtnl_unlock();
8976 return PCI_ERS_RESULT_DISCONNECT;
8977 }
8978
8979 if (netif_running(netdev))
8980 bnxt_close(netdev);
8981
8982 pci_disable_device(pdev);
8983 rtnl_unlock();
8984
8985 /* Request a slot slot reset. */
8986 return PCI_ERS_RESULT_NEED_RESET;
8987}
8988
8989/**
8990 * bnxt_io_slot_reset - called after the pci bus has been reset.
8991 * @pdev: Pointer to PCI device
8992 *
8993 * Restart the card from scratch, as if from a cold-boot.
8994 * At this point, the card has exprienced a hard reset,
8995 * followed by fixups by BIOS, and has its config space
8996 * set up identically to what it was at cold boot.
8997 */
8998static pci_ers_result_t bnxt_io_slot_reset(struct pci_dev *pdev)
8999{
9000 struct net_device *netdev = pci_get_drvdata(pdev);
9001 struct bnxt *bp = netdev_priv(netdev);
9002 int err = 0;
9003 pci_ers_result_t result = PCI_ERS_RESULT_DISCONNECT;
9004
9005 netdev_info(bp->dev, "PCI Slot Reset\n");
9006
9007 rtnl_lock();
9008
9009 if (pci_enable_device(pdev)) {
9010 dev_err(&pdev->dev,
9011 "Cannot re-enable PCI device after reset.\n");
9012 } else {
9013 pci_set_master(pdev);
9014
Michael Chanaa8ed022016-12-07 00:26:17 -05009015 err = bnxt_hwrm_func_reset(bp);
9016 if (!err && netif_running(netdev))
Satish Baddipadige6316ea62016-03-07 15:38:48 -05009017 err = bnxt_open(netdev);
9018
Michael Chana588e452016-12-07 00:26:21 -05009019 if (!err) {
Satish Baddipadige6316ea62016-03-07 15:38:48 -05009020 result = PCI_ERS_RESULT_RECOVERED;
Michael Chana588e452016-12-07 00:26:21 -05009021 bnxt_ulp_start(bp);
9022 }
Satish Baddipadige6316ea62016-03-07 15:38:48 -05009023 }
9024
9025 if (result != PCI_ERS_RESULT_RECOVERED && netif_running(netdev))
9026 dev_close(netdev);
9027
9028 rtnl_unlock();
9029
9030 err = pci_cleanup_aer_uncorrect_error_status(pdev);
9031 if (err) {
9032 dev_err(&pdev->dev,
9033 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
9034 err); /* non-fatal, continue */
9035 }
9036
9037 return PCI_ERS_RESULT_RECOVERED;
9038}
9039
9040/**
9041 * bnxt_io_resume - called when traffic can start flowing again.
9042 * @pdev: Pointer to PCI device
9043 *
9044 * This callback is called when the error recovery driver tells
9045 * us that its OK to resume normal operation.
9046 */
9047static void bnxt_io_resume(struct pci_dev *pdev)
9048{
9049 struct net_device *netdev = pci_get_drvdata(pdev);
9050
9051 rtnl_lock();
9052
9053 netif_device_attach(netdev);
9054
9055 rtnl_unlock();
9056}
9057
9058static const struct pci_error_handlers bnxt_err_handler = {
9059 .error_detected = bnxt_io_error_detected,
9060 .slot_reset = bnxt_io_slot_reset,
9061 .resume = bnxt_io_resume
9062};
9063
Michael Chanc0c050c2015-10-22 16:01:17 -04009064static struct pci_driver bnxt_pci_driver = {
9065 .name = DRV_MODULE_NAME,
9066 .id_table = bnxt_pci_tbl,
9067 .probe = bnxt_init_one,
9068 .remove = bnxt_remove_one,
Michael Chand196ece2017-04-04 18:14:08 -04009069 .shutdown = bnxt_shutdown,
Michael Chanf65a2042017-04-04 18:14:11 -04009070 .driver.pm = BNXT_PM_OPS,
Satish Baddipadige6316ea62016-03-07 15:38:48 -05009071 .err_handler = &bnxt_err_handler,
Michael Chanc0c050c2015-10-22 16:01:17 -04009072#if defined(CONFIG_BNXT_SRIOV)
9073 .sriov_configure = bnxt_sriov_configure,
9074#endif
9075};
9076
Michael Chanc213eae2017-10-13 21:09:29 -04009077static int __init bnxt_init(void)
9078{
9079 return pci_register_driver(&bnxt_pci_driver);
9080}
9081
9082static void __exit bnxt_exit(void)
9083{
9084 pci_unregister_driver(&bnxt_pci_driver);
9085 if (bnxt_pf_wq)
9086 destroy_workqueue(bnxt_pf_wq);
9087}
9088
9089module_init(bnxt_init);
9090module_exit(bnxt_exit);