blob: bda618d06118c3c92cd1655d9b64c603b03f0852 [file] [log] [blame]
Michael Chanc0c050c2015-10-22 16:01:17 -04001/* Broadcom NetXtreme-C/E network driver.
2 *
Michael Chan11f15ed2016-04-05 14:08:55 -04003 * Copyright (c) 2014-2016 Broadcom Corporation
Michael Chan894aa692018-01-17 03:21:03 -05004 * Copyright (c) 2016-2018 Broadcom Limited
Michael Chanc0c050c2015-10-22 16:01:17 -04005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation.
9 */
10
11#include <linux/module.h>
12
13#include <linux/stringify.h>
14#include <linux/kernel.h>
15#include <linux/timer.h>
16#include <linux/errno.h>
17#include <linux/ioport.h>
18#include <linux/slab.h>
19#include <linux/vmalloc.h>
20#include <linux/interrupt.h>
21#include <linux/pci.h>
22#include <linux/netdevice.h>
23#include <linux/etherdevice.h>
24#include <linux/skbuff.h>
25#include <linux/dma-mapping.h>
26#include <linux/bitops.h>
27#include <linux/io.h>
28#include <linux/irq.h>
29#include <linux/delay.h>
30#include <asm/byteorder.h>
31#include <asm/page.h>
32#include <linux/time.h>
33#include <linux/mii.h>
34#include <linux/if.h>
35#include <linux/if_vlan.h>
Michael Chan32e8239c2017-07-24 12:34:21 -040036#include <linux/if_bridge.h>
Rob Swindell5ac67d82016-09-19 03:58:03 -040037#include <linux/rtc.h>
Michael Chanc6d30e82017-02-06 16:55:42 -050038#include <linux/bpf.h>
Michael Chanc0c050c2015-10-22 16:01:17 -040039#include <net/ip.h>
40#include <net/tcp.h>
41#include <net/udp.h>
42#include <net/checksum.h>
43#include <net/ip6_checksum.h>
Alexander Duyckad51b8e2016-06-16 12:21:19 -070044#include <net/udp_tunnel.h>
Michael Chanc0c050c2015-10-22 16:01:17 -040045#include <linux/workqueue.h>
46#include <linux/prefetch.h>
47#include <linux/cache.h>
48#include <linux/log2.h>
49#include <linux/aer.h>
50#include <linux/bitmap.h>
51#include <linux/cpu_rmap.h>
Vasundhara Volam56f0fd82017-08-28 13:40:27 -040052#include <linux/cpumask.h>
Sathya Perla2ae74082017-08-28 13:40:33 -040053#include <net/pkt_cls.h>
Michael Chanc0c050c2015-10-22 16:01:17 -040054
55#include "bnxt_hsi.h"
56#include "bnxt.h"
Michael Chana588e452016-12-07 00:26:21 -050057#include "bnxt_ulp.h"
Michael Chanc0c050c2015-10-22 16:01:17 -040058#include "bnxt_sriov.h"
59#include "bnxt_ethtool.h"
Michael Chan7df4ae92016-12-02 21:17:17 -050060#include "bnxt_dcb.h"
Michael Chanc6d30e82017-02-06 16:55:42 -050061#include "bnxt_xdp.h"
Sathya Perla4ab0c6a2017-07-24 12:34:27 -040062#include "bnxt_vfr.h"
Sathya Perla2ae74082017-08-28 13:40:33 -040063#include "bnxt_tc.h"
Steve Lin3c467bf2017-10-19 10:45:56 -040064#include "bnxt_devlink.h"
Michael Chanc0c050c2015-10-22 16:01:17 -040065
66#define BNXT_TX_TIMEOUT (5 * HZ)
67
68static const char version[] =
69 "Broadcom NetXtreme-C/E driver " DRV_MODULE_NAME " v" DRV_MODULE_VERSION "\n";
70
71MODULE_LICENSE("GPL");
72MODULE_DESCRIPTION("Broadcom BCM573xx network driver");
73MODULE_VERSION(DRV_MODULE_VERSION);
74
75#define BNXT_RX_OFFSET (NET_SKB_PAD + NET_IP_ALIGN)
76#define BNXT_RX_DMA_OFFSET NET_SKB_PAD
77#define BNXT_RX_COPY_THRESH 256
78
Michael Chan4419dbe2016-02-10 17:33:49 -050079#define BNXT_TX_PUSH_THRESH 164
Michael Chanc0c050c2015-10-22 16:01:17 -040080
81enum board_idx {
David Christensenfbc9a522015-12-27 18:19:29 -050082 BCM57301,
Michael Chanc0c050c2015-10-22 16:01:17 -040083 BCM57302,
84 BCM57304,
Michael Chan1f681682016-07-25 12:33:37 -040085 BCM57417_NPAR,
Prashant Sreedharanfa853dd2016-07-18 07:15:25 -040086 BCM58700,
Michael Chanb24eb6a2016-06-13 02:25:36 -040087 BCM57311,
88 BCM57312,
David Christensenfbc9a522015-12-27 18:19:29 -050089 BCM57402,
Michael Chanc0c050c2015-10-22 16:01:17 -040090 BCM57404,
91 BCM57406,
Michael Chan1f681682016-07-25 12:33:37 -040092 BCM57402_NPAR,
93 BCM57407,
Michael Chanb24eb6a2016-06-13 02:25:36 -040094 BCM57412,
95 BCM57414,
96 BCM57416,
97 BCM57417,
Michael Chan1f681682016-07-25 12:33:37 -040098 BCM57412_NPAR,
Michael Chan5049e332016-05-15 03:04:50 -040099 BCM57314,
Michael Chan1f681682016-07-25 12:33:37 -0400100 BCM57417_SFP,
101 BCM57416_SFP,
102 BCM57404_NPAR,
103 BCM57406_NPAR,
104 BCM57407_SFP,
Michael Chanadbc8302016-09-19 03:58:01 -0400105 BCM57407_NPAR,
Michael Chan1f681682016-07-25 12:33:37 -0400106 BCM57414_NPAR,
107 BCM57416_NPAR,
Deepak Khungar32b40792017-02-12 19:18:18 -0500108 BCM57452,
109 BCM57454,
Vasundhara Volam92abef32018-01-17 03:21:13 -0500110 BCM5745x_NPAR,
Ray Jui4a581392017-08-28 13:40:28 -0400111 BCM58802,
Ray Jui8ed693b2017-10-26 11:51:20 -0400112 BCM58804,
Ray Jui4a581392017-08-28 13:40:28 -0400113 BCM58808,
Michael Chanadbc8302016-09-19 03:58:01 -0400114 NETXTREME_E_VF,
115 NETXTREME_C_VF,
Rob Miller618784e2017-10-26 11:51:21 -0400116 NETXTREME_S_VF,
Michael Chanc0c050c2015-10-22 16:01:17 -0400117};
118
119/* indexed by enum above */
120static const struct {
121 char *name;
122} board_info[] = {
Scott Branden27573a72017-08-28 13:40:29 -0400123 [BCM57301] = { "Broadcom BCM57301 NetXtreme-C 10Gb Ethernet" },
124 [BCM57302] = { "Broadcom BCM57302 NetXtreme-C 10Gb/25Gb Ethernet" },
125 [BCM57304] = { "Broadcom BCM57304 NetXtreme-C 10Gb/25Gb/40Gb/50Gb Ethernet" },
126 [BCM57417_NPAR] = { "Broadcom BCM57417 NetXtreme-E Ethernet Partition" },
127 [BCM58700] = { "Broadcom BCM58700 Nitro 1Gb/2.5Gb/10Gb Ethernet" },
128 [BCM57311] = { "Broadcom BCM57311 NetXtreme-C 10Gb Ethernet" },
129 [BCM57312] = { "Broadcom BCM57312 NetXtreme-C 10Gb/25Gb Ethernet" },
130 [BCM57402] = { "Broadcom BCM57402 NetXtreme-E 10Gb Ethernet" },
131 [BCM57404] = { "Broadcom BCM57404 NetXtreme-E 10Gb/25Gb Ethernet" },
132 [BCM57406] = { "Broadcom BCM57406 NetXtreme-E 10GBase-T Ethernet" },
133 [BCM57402_NPAR] = { "Broadcom BCM57402 NetXtreme-E Ethernet Partition" },
134 [BCM57407] = { "Broadcom BCM57407 NetXtreme-E 10GBase-T Ethernet" },
135 [BCM57412] = { "Broadcom BCM57412 NetXtreme-E 10Gb Ethernet" },
136 [BCM57414] = { "Broadcom BCM57414 NetXtreme-E 10Gb/25Gb Ethernet" },
137 [BCM57416] = { "Broadcom BCM57416 NetXtreme-E 10GBase-T Ethernet" },
138 [BCM57417] = { "Broadcom BCM57417 NetXtreme-E 10GBase-T Ethernet" },
139 [BCM57412_NPAR] = { "Broadcom BCM57412 NetXtreme-E Ethernet Partition" },
140 [BCM57314] = { "Broadcom BCM57314 NetXtreme-C 10Gb/25Gb/40Gb/50Gb Ethernet" },
141 [BCM57417_SFP] = { "Broadcom BCM57417 NetXtreme-E 10Gb/25Gb Ethernet" },
142 [BCM57416_SFP] = { "Broadcom BCM57416 NetXtreme-E 10Gb Ethernet" },
143 [BCM57404_NPAR] = { "Broadcom BCM57404 NetXtreme-E Ethernet Partition" },
144 [BCM57406_NPAR] = { "Broadcom BCM57406 NetXtreme-E Ethernet Partition" },
145 [BCM57407_SFP] = { "Broadcom BCM57407 NetXtreme-E 25Gb Ethernet" },
146 [BCM57407_NPAR] = { "Broadcom BCM57407 NetXtreme-E Ethernet Partition" },
147 [BCM57414_NPAR] = { "Broadcom BCM57414 NetXtreme-E Ethernet Partition" },
148 [BCM57416_NPAR] = { "Broadcom BCM57416 NetXtreme-E Ethernet Partition" },
149 [BCM57452] = { "Broadcom BCM57452 NetXtreme-E 10Gb/25Gb/40Gb/50Gb Ethernet" },
150 [BCM57454] = { "Broadcom BCM57454 NetXtreme-E 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" },
Vasundhara Volam92abef32018-01-17 03:21:13 -0500151 [BCM5745x_NPAR] = { "Broadcom BCM5745x NetXtreme-E Ethernet Partition" },
Scott Branden27573a72017-08-28 13:40:29 -0400152 [BCM58802] = { "Broadcom BCM58802 NetXtreme-S 10Gb/25Gb/40Gb/50Gb Ethernet" },
Ray Jui8ed693b2017-10-26 11:51:20 -0400153 [BCM58804] = { "Broadcom BCM58804 NetXtreme-S 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" },
Scott Branden27573a72017-08-28 13:40:29 -0400154 [BCM58808] = { "Broadcom BCM58808 NetXtreme-S 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" },
155 [NETXTREME_E_VF] = { "Broadcom NetXtreme-E Ethernet Virtual Function" },
156 [NETXTREME_C_VF] = { "Broadcom NetXtreme-C Ethernet Virtual Function" },
Rob Miller618784e2017-10-26 11:51:21 -0400157 [NETXTREME_S_VF] = { "Broadcom NetXtreme-S Ethernet Virtual Function" },
Michael Chanc0c050c2015-10-22 16:01:17 -0400158};
159
160static const struct pci_device_id bnxt_pci_tbl[] = {
Vasundhara Volam92abef32018-01-17 03:21:13 -0500161 { PCI_VDEVICE(BROADCOM, 0x1604), .driver_data = BCM5745x_NPAR },
162 { PCI_VDEVICE(BROADCOM, 0x1605), .driver_data = BCM5745x_NPAR },
Ray Jui4a581392017-08-28 13:40:28 -0400163 { PCI_VDEVICE(BROADCOM, 0x1614), .driver_data = BCM57454 },
Michael Chanadbc8302016-09-19 03:58:01 -0400164 { PCI_VDEVICE(BROADCOM, 0x16c0), .driver_data = BCM57417_NPAR },
David Christensenfbc9a522015-12-27 18:19:29 -0500165 { PCI_VDEVICE(BROADCOM, 0x16c8), .driver_data = BCM57301 },
Michael Chanc0c050c2015-10-22 16:01:17 -0400166 { PCI_VDEVICE(BROADCOM, 0x16c9), .driver_data = BCM57302 },
167 { PCI_VDEVICE(BROADCOM, 0x16ca), .driver_data = BCM57304 },
Michael Chan1f681682016-07-25 12:33:37 -0400168 { PCI_VDEVICE(BROADCOM, 0x16cc), .driver_data = BCM57417_NPAR },
Prashant Sreedharanfa853dd2016-07-18 07:15:25 -0400169 { PCI_VDEVICE(BROADCOM, 0x16cd), .driver_data = BCM58700 },
Michael Chanb24eb6a2016-06-13 02:25:36 -0400170 { PCI_VDEVICE(BROADCOM, 0x16ce), .driver_data = BCM57311 },
171 { PCI_VDEVICE(BROADCOM, 0x16cf), .driver_data = BCM57312 },
David Christensenfbc9a522015-12-27 18:19:29 -0500172 { PCI_VDEVICE(BROADCOM, 0x16d0), .driver_data = BCM57402 },
Michael Chanc0c050c2015-10-22 16:01:17 -0400173 { PCI_VDEVICE(BROADCOM, 0x16d1), .driver_data = BCM57404 },
174 { PCI_VDEVICE(BROADCOM, 0x16d2), .driver_data = BCM57406 },
Michael Chan1f681682016-07-25 12:33:37 -0400175 { PCI_VDEVICE(BROADCOM, 0x16d4), .driver_data = BCM57402_NPAR },
176 { PCI_VDEVICE(BROADCOM, 0x16d5), .driver_data = BCM57407 },
Michael Chanb24eb6a2016-06-13 02:25:36 -0400177 { PCI_VDEVICE(BROADCOM, 0x16d6), .driver_data = BCM57412 },
178 { PCI_VDEVICE(BROADCOM, 0x16d7), .driver_data = BCM57414 },
179 { PCI_VDEVICE(BROADCOM, 0x16d8), .driver_data = BCM57416 },
180 { PCI_VDEVICE(BROADCOM, 0x16d9), .driver_data = BCM57417 },
Michael Chan1f681682016-07-25 12:33:37 -0400181 { PCI_VDEVICE(BROADCOM, 0x16de), .driver_data = BCM57412_NPAR },
Michael Chan5049e332016-05-15 03:04:50 -0400182 { PCI_VDEVICE(BROADCOM, 0x16df), .driver_data = BCM57314 },
Michael Chan1f681682016-07-25 12:33:37 -0400183 { PCI_VDEVICE(BROADCOM, 0x16e2), .driver_data = BCM57417_SFP },
184 { PCI_VDEVICE(BROADCOM, 0x16e3), .driver_data = BCM57416_SFP },
185 { PCI_VDEVICE(BROADCOM, 0x16e7), .driver_data = BCM57404_NPAR },
186 { PCI_VDEVICE(BROADCOM, 0x16e8), .driver_data = BCM57406_NPAR },
187 { PCI_VDEVICE(BROADCOM, 0x16e9), .driver_data = BCM57407_SFP },
Michael Chanadbc8302016-09-19 03:58:01 -0400188 { PCI_VDEVICE(BROADCOM, 0x16ea), .driver_data = BCM57407_NPAR },
189 { PCI_VDEVICE(BROADCOM, 0x16eb), .driver_data = BCM57412_NPAR },
Michael Chan1f681682016-07-25 12:33:37 -0400190 { PCI_VDEVICE(BROADCOM, 0x16ec), .driver_data = BCM57414_NPAR },
Michael Chanadbc8302016-09-19 03:58:01 -0400191 { PCI_VDEVICE(BROADCOM, 0x16ed), .driver_data = BCM57414_NPAR },
Michael Chan1f681682016-07-25 12:33:37 -0400192 { PCI_VDEVICE(BROADCOM, 0x16ee), .driver_data = BCM57416_NPAR },
Michael Chanadbc8302016-09-19 03:58:01 -0400193 { PCI_VDEVICE(BROADCOM, 0x16ef), .driver_data = BCM57416_NPAR },
Ray Jui4a581392017-08-28 13:40:28 -0400194 { PCI_VDEVICE(BROADCOM, 0x16f0), .driver_data = BCM58808 },
Deepak Khungar32b40792017-02-12 19:18:18 -0500195 { PCI_VDEVICE(BROADCOM, 0x16f1), .driver_data = BCM57452 },
Ray Jui4a581392017-08-28 13:40:28 -0400196 { PCI_VDEVICE(BROADCOM, 0xd802), .driver_data = BCM58802 },
Ray Jui8ed693b2017-10-26 11:51:20 -0400197 { PCI_VDEVICE(BROADCOM, 0xd804), .driver_data = BCM58804 },
Michael Chanc0c050c2015-10-22 16:01:17 -0400198#ifdef CONFIG_BNXT_SRIOV
Deepak Khungarc7ef35e2017-05-29 19:06:05 -0400199 { PCI_VDEVICE(BROADCOM, 0x1606), .driver_data = NETXTREME_E_VF },
200 { PCI_VDEVICE(BROADCOM, 0x1609), .driver_data = NETXTREME_E_VF },
Michael Chanadbc8302016-09-19 03:58:01 -0400201 { PCI_VDEVICE(BROADCOM, 0x16c1), .driver_data = NETXTREME_E_VF },
202 { PCI_VDEVICE(BROADCOM, 0x16cb), .driver_data = NETXTREME_C_VF },
203 { PCI_VDEVICE(BROADCOM, 0x16d3), .driver_data = NETXTREME_E_VF },
204 { PCI_VDEVICE(BROADCOM, 0x16dc), .driver_data = NETXTREME_E_VF },
205 { PCI_VDEVICE(BROADCOM, 0x16e1), .driver_data = NETXTREME_C_VF },
206 { PCI_VDEVICE(BROADCOM, 0x16e5), .driver_data = NETXTREME_C_VF },
Rob Miller618784e2017-10-26 11:51:21 -0400207 { PCI_VDEVICE(BROADCOM, 0xd800), .driver_data = NETXTREME_S_VF },
Michael Chanc0c050c2015-10-22 16:01:17 -0400208#endif
209 { 0 }
210};
211
212MODULE_DEVICE_TABLE(pci, bnxt_pci_tbl);
213
214static const u16 bnxt_vf_req_snif[] = {
215 HWRM_FUNC_CFG,
Vasundhara Volam91cdda42018-01-17 03:21:14 -0500216 HWRM_FUNC_VF_CFG,
Michael Chanc0c050c2015-10-22 16:01:17 -0400217 HWRM_PORT_PHY_QCFG,
218 HWRM_CFA_L2_FILTER_ALLOC,
219};
220
Michael Chan25be8622016-04-05 14:09:00 -0400221static const u16 bnxt_async_events_arr[] = {
Michael Chan87c374d2016-12-02 21:17:16 -0500222 ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE,
223 ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD,
224 ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED,
225 ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE,
226 ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE,
Michael Chan25be8622016-04-05 14:09:00 -0400227};
228
Michael Chanc213eae2017-10-13 21:09:29 -0400229static struct workqueue_struct *bnxt_pf_wq;
230
Michael Chanc0c050c2015-10-22 16:01:17 -0400231static bool bnxt_vf_pciid(enum board_idx idx)
232{
Rob Miller618784e2017-10-26 11:51:21 -0400233 return (idx == NETXTREME_C_VF || idx == NETXTREME_E_VF ||
234 idx == NETXTREME_S_VF);
Michael Chanc0c050c2015-10-22 16:01:17 -0400235}
236
237#define DB_CP_REARM_FLAGS (DB_KEY_CP | DB_IDX_VALID)
238#define DB_CP_FLAGS (DB_KEY_CP | DB_IDX_VALID | DB_IRQ_DIS)
239#define DB_CP_IRQ_DIS_FLAGS (DB_KEY_CP | DB_IRQ_DIS)
240
241#define BNXT_CP_DB_REARM(db, raw_cons) \
242 writel(DB_CP_REARM_FLAGS | RING_CMP(raw_cons), db)
243
244#define BNXT_CP_DB(db, raw_cons) \
245 writel(DB_CP_FLAGS | RING_CMP(raw_cons), db)
246
247#define BNXT_CP_DB_IRQ_DIS(db) \
248 writel(DB_CP_IRQ_DIS_FLAGS, db)
249
Michael Chan38413402017-02-06 16:55:43 -0500250const u16 bnxt_lhint_arr[] = {
Michael Chanc0c050c2015-10-22 16:01:17 -0400251 TX_BD_FLAGS_LHINT_512_AND_SMALLER,
252 TX_BD_FLAGS_LHINT_512_TO_1023,
253 TX_BD_FLAGS_LHINT_1024_TO_2047,
254 TX_BD_FLAGS_LHINT_1024_TO_2047,
255 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
256 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
257 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
258 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
259 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
260 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
261 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
262 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
263 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
264 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
265 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
266 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
267 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
268 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
269 TX_BD_FLAGS_LHINT_2048_AND_LARGER,
270};
271
Sathya Perlaee5c7fb2017-07-24 12:34:28 -0400272static u16 bnxt_xmit_get_cfa_action(struct sk_buff *skb)
273{
274 struct metadata_dst *md_dst = skb_metadata_dst(skb);
275
276 if (!md_dst || md_dst->type != METADATA_HW_PORT_MUX)
277 return 0;
278
279 return md_dst->u.port_info.port_id;
280}
281
Michael Chanc0c050c2015-10-22 16:01:17 -0400282static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
283{
284 struct bnxt *bp = netdev_priv(dev);
285 struct tx_bd *txbd;
286 struct tx_bd_ext *txbd1;
287 struct netdev_queue *txq;
288 int i;
289 dma_addr_t mapping;
290 unsigned int length, pad = 0;
291 u32 len, free_size, vlan_tag_flags, cfa_action, flags;
292 u16 prod, last_frag;
293 struct pci_dev *pdev = bp->pdev;
Michael Chanc0c050c2015-10-22 16:01:17 -0400294 struct bnxt_tx_ring_info *txr;
295 struct bnxt_sw_tx_bd *tx_buf;
296
297 i = skb_get_queue_mapping(skb);
298 if (unlikely(i >= bp->tx_nr_rings)) {
299 dev_kfree_skb_any(skb);
300 return NETDEV_TX_OK;
301 }
302
Michael Chanc0c050c2015-10-22 16:01:17 -0400303 txq = netdev_get_tx_queue(dev, i);
Michael Chana960dec2017-02-06 16:55:39 -0500304 txr = &bp->tx_ring[bp->tx_ring_map[i]];
Michael Chanc0c050c2015-10-22 16:01:17 -0400305 prod = txr->tx_prod;
306
307 free_size = bnxt_tx_avail(bp, txr);
308 if (unlikely(free_size < skb_shinfo(skb)->nr_frags + 2)) {
309 netif_tx_stop_queue(txq);
310 return NETDEV_TX_BUSY;
311 }
312
313 length = skb->len;
314 len = skb_headlen(skb);
315 last_frag = skb_shinfo(skb)->nr_frags;
316
317 txbd = &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)];
318
319 txbd->tx_bd_opaque = prod;
320
321 tx_buf = &txr->tx_buf_ring[prod];
322 tx_buf->skb = skb;
323 tx_buf->nr_frags = last_frag;
324
325 vlan_tag_flags = 0;
Sathya Perlaee5c7fb2017-07-24 12:34:28 -0400326 cfa_action = bnxt_xmit_get_cfa_action(skb);
Michael Chanc0c050c2015-10-22 16:01:17 -0400327 if (skb_vlan_tag_present(skb)) {
328 vlan_tag_flags = TX_BD_CFA_META_KEY_VLAN |
329 skb_vlan_tag_get(skb);
330 /* Currently supports 8021Q, 8021AD vlan offloads
331 * QINQ1, QINQ2, QINQ3 vlan headers are deprecated
332 */
333 if (skb->vlan_proto == htons(ETH_P_8021Q))
334 vlan_tag_flags |= 1 << TX_BD_CFA_META_TPID_SHIFT;
335 }
336
337 if (free_size == bp->tx_ring_size && length <= bp->tx_push_thresh) {
Michael Chan4419dbe2016-02-10 17:33:49 -0500338 struct tx_push_buffer *tx_push_buf = txr->tx_push;
339 struct tx_push_bd *tx_push = &tx_push_buf->push_bd;
340 struct tx_bd_ext *tx_push1 = &tx_push->txbd2;
341 void *pdata = tx_push_buf->data;
342 u64 *end;
343 int j, push_len;
Michael Chanc0c050c2015-10-22 16:01:17 -0400344
345 /* Set COAL_NOW to be ready quickly for the next push */
346 tx_push->tx_bd_len_flags_type =
347 cpu_to_le32((length << TX_BD_LEN_SHIFT) |
348 TX_BD_TYPE_LONG_TX_BD |
349 TX_BD_FLAGS_LHINT_512_AND_SMALLER |
350 TX_BD_FLAGS_COAL_NOW |
351 TX_BD_FLAGS_PACKET_END |
352 (2 << TX_BD_FLAGS_BD_CNT_SHIFT));
353
354 if (skb->ip_summed == CHECKSUM_PARTIAL)
355 tx_push1->tx_bd_hsize_lflags =
356 cpu_to_le32(TX_BD_FLAGS_TCP_UDP_CHKSUM);
357 else
358 tx_push1->tx_bd_hsize_lflags = 0;
359
360 tx_push1->tx_bd_cfa_meta = cpu_to_le32(vlan_tag_flags);
Sathya Perlaee5c7fb2017-07-24 12:34:28 -0400361 tx_push1->tx_bd_cfa_action =
362 cpu_to_le32(cfa_action << TX_BD_CFA_ACTION_SHIFT);
Michael Chanc0c050c2015-10-22 16:01:17 -0400363
Michael Chanfbb0fa82016-02-22 02:10:26 -0500364 end = pdata + length;
365 end = PTR_ALIGN(end, 8) - 1;
Michael Chan4419dbe2016-02-10 17:33:49 -0500366 *end = 0;
367
Michael Chanc0c050c2015-10-22 16:01:17 -0400368 skb_copy_from_linear_data(skb, pdata, len);
369 pdata += len;
370 for (j = 0; j < last_frag; j++) {
371 skb_frag_t *frag = &skb_shinfo(skb)->frags[j];
372 void *fptr;
373
374 fptr = skb_frag_address_safe(frag);
375 if (!fptr)
376 goto normal_tx;
377
378 memcpy(pdata, fptr, skb_frag_size(frag));
379 pdata += skb_frag_size(frag);
380 }
381
Michael Chan4419dbe2016-02-10 17:33:49 -0500382 txbd->tx_bd_len_flags_type = tx_push->tx_bd_len_flags_type;
383 txbd->tx_bd_haddr = txr->data_mapping;
Michael Chanc0c050c2015-10-22 16:01:17 -0400384 prod = NEXT_TX(prod);
385 txbd = &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)];
386 memcpy(txbd, tx_push1, sizeof(*txbd));
387 prod = NEXT_TX(prod);
Michael Chan4419dbe2016-02-10 17:33:49 -0500388 tx_push->doorbell =
Michael Chanc0c050c2015-10-22 16:01:17 -0400389 cpu_to_le32(DB_KEY_TX_PUSH | DB_LONG_TX_PUSH | prod);
390 txr->tx_prod = prod;
391
Michael Chanb9a84602016-06-06 02:37:14 -0400392 tx_buf->is_push = 1;
Michael Chanc0c050c2015-10-22 16:01:17 -0400393 netdev_tx_sent_queue(txq, skb->len);
Michael Chanb9a84602016-06-06 02:37:14 -0400394 wmb(); /* Sync is_push and byte queue before pushing data */
Michael Chanc0c050c2015-10-22 16:01:17 -0400395
Michael Chan4419dbe2016-02-10 17:33:49 -0500396 push_len = (length + sizeof(*tx_push) + 7) / 8;
397 if (push_len > 16) {
398 __iowrite64_copy(txr->tx_doorbell, tx_push_buf, 16);
Michael Chan9d137442016-09-05 01:57:35 -0400399 __iowrite32_copy(txr->tx_doorbell + 4, tx_push_buf + 1,
400 (push_len - 16) << 1);
Michael Chan4419dbe2016-02-10 17:33:49 -0500401 } else {
402 __iowrite64_copy(txr->tx_doorbell, tx_push_buf,
403 push_len);
404 }
Michael Chanc0c050c2015-10-22 16:01:17 -0400405
Michael Chanc0c050c2015-10-22 16:01:17 -0400406 goto tx_done;
407 }
408
409normal_tx:
410 if (length < BNXT_MIN_PKT_SIZE) {
411 pad = BNXT_MIN_PKT_SIZE - length;
412 if (skb_pad(skb, pad)) {
413 /* SKB already freed. */
414 tx_buf->skb = NULL;
415 return NETDEV_TX_OK;
416 }
417 length = BNXT_MIN_PKT_SIZE;
418 }
419
420 mapping = dma_map_single(&pdev->dev, skb->data, len, DMA_TO_DEVICE);
421
422 if (unlikely(dma_mapping_error(&pdev->dev, mapping))) {
423 dev_kfree_skb_any(skb);
424 tx_buf->skb = NULL;
425 return NETDEV_TX_OK;
426 }
427
428 dma_unmap_addr_set(tx_buf, mapping, mapping);
429 flags = (len << TX_BD_LEN_SHIFT) | TX_BD_TYPE_LONG_TX_BD |
430 ((last_frag + 2) << TX_BD_FLAGS_BD_CNT_SHIFT);
431
432 txbd->tx_bd_haddr = cpu_to_le64(mapping);
433
434 prod = NEXT_TX(prod);
435 txbd1 = (struct tx_bd_ext *)
436 &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)];
437
438 txbd1->tx_bd_hsize_lflags = 0;
439 if (skb_is_gso(skb)) {
440 u32 hdr_len;
441
442 if (skb->encapsulation)
443 hdr_len = skb_inner_network_offset(skb) +
444 skb_inner_network_header_len(skb) +
445 inner_tcp_hdrlen(skb);
446 else
447 hdr_len = skb_transport_offset(skb) +
448 tcp_hdrlen(skb);
449
450 txbd1->tx_bd_hsize_lflags = cpu_to_le32(TX_BD_FLAGS_LSO |
451 TX_BD_FLAGS_T_IPID |
452 (hdr_len << (TX_BD_HSIZE_SHIFT - 1)));
453 length = skb_shinfo(skb)->gso_size;
454 txbd1->tx_bd_mss = cpu_to_le32(length);
455 length += hdr_len;
456 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
457 txbd1->tx_bd_hsize_lflags =
458 cpu_to_le32(TX_BD_FLAGS_TCP_UDP_CHKSUM);
459 txbd1->tx_bd_mss = 0;
460 }
461
462 length >>= 9;
463 flags |= bnxt_lhint_arr[length];
464 txbd->tx_bd_len_flags_type = cpu_to_le32(flags);
465
466 txbd1->tx_bd_cfa_meta = cpu_to_le32(vlan_tag_flags);
Sathya Perlaee5c7fb2017-07-24 12:34:28 -0400467 txbd1->tx_bd_cfa_action =
468 cpu_to_le32(cfa_action << TX_BD_CFA_ACTION_SHIFT);
Michael Chanc0c050c2015-10-22 16:01:17 -0400469 for (i = 0; i < last_frag; i++) {
470 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
471
472 prod = NEXT_TX(prod);
473 txbd = &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)];
474
475 len = skb_frag_size(frag);
476 mapping = skb_frag_dma_map(&pdev->dev, frag, 0, len,
477 DMA_TO_DEVICE);
478
479 if (unlikely(dma_mapping_error(&pdev->dev, mapping)))
480 goto tx_dma_error;
481
482 tx_buf = &txr->tx_buf_ring[prod];
483 dma_unmap_addr_set(tx_buf, mapping, mapping);
484
485 txbd->tx_bd_haddr = cpu_to_le64(mapping);
486
487 flags = len << TX_BD_LEN_SHIFT;
488 txbd->tx_bd_len_flags_type = cpu_to_le32(flags);
489 }
490
491 flags &= ~TX_BD_LEN;
492 txbd->tx_bd_len_flags_type =
493 cpu_to_le32(((len + pad) << TX_BD_LEN_SHIFT) | flags |
494 TX_BD_FLAGS_PACKET_END);
495
496 netdev_tx_sent_queue(txq, skb->len);
497
498 /* Sync BD data before updating doorbell */
499 wmb();
500
501 prod = NEXT_TX(prod);
502 txr->tx_prod = prod;
503
Michael Chanffe40642017-05-30 20:03:00 -0400504 if (!skb->xmit_more || netif_xmit_stopped(txq))
Michael Chan4d172f22017-05-29 19:06:09 -0400505 bnxt_db_write(bp, txr->tx_doorbell, DB_KEY_TX | prod);
Michael Chanc0c050c2015-10-22 16:01:17 -0400506
507tx_done:
508
509 mmiowb();
510
511 if (unlikely(bnxt_tx_avail(bp, txr) <= MAX_SKB_FRAGS + 1)) {
Michael Chan4d172f22017-05-29 19:06:09 -0400512 if (skb->xmit_more && !tx_buf->is_push)
513 bnxt_db_write(bp, txr->tx_doorbell, DB_KEY_TX | prod);
514
Michael Chanc0c050c2015-10-22 16:01:17 -0400515 netif_tx_stop_queue(txq);
516
517 /* netif_tx_stop_queue() must be done before checking
518 * tx index in bnxt_tx_avail() below, because in
519 * bnxt_tx_int(), we update tx index before checking for
520 * netif_tx_queue_stopped().
521 */
522 smp_mb();
523 if (bnxt_tx_avail(bp, txr) > bp->tx_wake_thresh)
524 netif_tx_wake_queue(txq);
525 }
526 return NETDEV_TX_OK;
527
528tx_dma_error:
529 last_frag = i;
530
531 /* start back at beginning and unmap skb */
532 prod = txr->tx_prod;
533 tx_buf = &txr->tx_buf_ring[prod];
534 tx_buf->skb = NULL;
535 dma_unmap_single(&pdev->dev, dma_unmap_addr(tx_buf, mapping),
536 skb_headlen(skb), PCI_DMA_TODEVICE);
537 prod = NEXT_TX(prod);
538
539 /* unmap remaining mapped pages */
540 for (i = 0; i < last_frag; i++) {
541 prod = NEXT_TX(prod);
542 tx_buf = &txr->tx_buf_ring[prod];
543 dma_unmap_page(&pdev->dev, dma_unmap_addr(tx_buf, mapping),
544 skb_frag_size(&skb_shinfo(skb)->frags[i]),
545 PCI_DMA_TODEVICE);
546 }
547
548 dev_kfree_skb_any(skb);
549 return NETDEV_TX_OK;
550}
551
552static void bnxt_tx_int(struct bnxt *bp, struct bnxt_napi *bnapi, int nr_pkts)
553{
Michael Chanb6ab4b02016-01-02 23:44:59 -0500554 struct bnxt_tx_ring_info *txr = bnapi->tx_ring;
Michael Chana960dec2017-02-06 16:55:39 -0500555 struct netdev_queue *txq = netdev_get_tx_queue(bp->dev, txr->txq_index);
Michael Chanc0c050c2015-10-22 16:01:17 -0400556 u16 cons = txr->tx_cons;
557 struct pci_dev *pdev = bp->pdev;
558 int i;
559 unsigned int tx_bytes = 0;
560
561 for (i = 0; i < nr_pkts; i++) {
562 struct bnxt_sw_tx_bd *tx_buf;
563 struct sk_buff *skb;
564 int j, last;
565
566 tx_buf = &txr->tx_buf_ring[cons];
567 cons = NEXT_TX(cons);
568 skb = tx_buf->skb;
569 tx_buf->skb = NULL;
570
571 if (tx_buf->is_push) {
572 tx_buf->is_push = 0;
573 goto next_tx_int;
574 }
575
576 dma_unmap_single(&pdev->dev, dma_unmap_addr(tx_buf, mapping),
577 skb_headlen(skb), PCI_DMA_TODEVICE);
578 last = tx_buf->nr_frags;
579
580 for (j = 0; j < last; j++) {
581 cons = NEXT_TX(cons);
582 tx_buf = &txr->tx_buf_ring[cons];
583 dma_unmap_page(
584 &pdev->dev,
585 dma_unmap_addr(tx_buf, mapping),
586 skb_frag_size(&skb_shinfo(skb)->frags[j]),
587 PCI_DMA_TODEVICE);
588 }
589
590next_tx_int:
591 cons = NEXT_TX(cons);
592
593 tx_bytes += skb->len;
594 dev_kfree_skb_any(skb);
595 }
596
597 netdev_tx_completed_queue(txq, nr_pkts, tx_bytes);
598 txr->tx_cons = cons;
599
600 /* Need to make the tx_cons update visible to bnxt_start_xmit()
601 * before checking for netif_tx_queue_stopped(). Without the
602 * memory barrier, there is a small possibility that bnxt_start_xmit()
603 * will miss it and cause the queue to be stopped forever.
604 */
605 smp_mb();
606
607 if (unlikely(netif_tx_queue_stopped(txq)) &&
608 (bnxt_tx_avail(bp, txr) > bp->tx_wake_thresh)) {
609 __netif_tx_lock(txq, smp_processor_id());
610 if (netif_tx_queue_stopped(txq) &&
611 bnxt_tx_avail(bp, txr) > bp->tx_wake_thresh &&
612 txr->dev_state != BNXT_DEV_STATE_CLOSING)
613 netif_tx_wake_queue(txq);
614 __netif_tx_unlock(txq);
615 }
616}
617
Michael Chanc61fb992017-02-06 16:55:36 -0500618static struct page *__bnxt_alloc_rx_page(struct bnxt *bp, dma_addr_t *mapping,
619 gfp_t gfp)
620{
621 struct device *dev = &bp->pdev->dev;
622 struct page *page;
623
624 page = alloc_page(gfp);
625 if (!page)
626 return NULL;
627
Shannon Nelsonc519fe92017-05-09 18:30:12 -0700628 *mapping = dma_map_page_attrs(dev, page, 0, PAGE_SIZE, bp->rx_dir,
629 DMA_ATTR_WEAK_ORDERING);
Michael Chanc61fb992017-02-06 16:55:36 -0500630 if (dma_mapping_error(dev, *mapping)) {
631 __free_page(page);
632 return NULL;
633 }
634 *mapping += bp->rx_dma_offset;
635 return page;
636}
637
Michael Chanc0c050c2015-10-22 16:01:17 -0400638static inline u8 *__bnxt_alloc_rx_data(struct bnxt *bp, dma_addr_t *mapping,
639 gfp_t gfp)
640{
641 u8 *data;
642 struct pci_dev *pdev = bp->pdev;
643
644 data = kmalloc(bp->rx_buf_size, gfp);
645 if (!data)
646 return NULL;
647
Shannon Nelsonc519fe92017-05-09 18:30:12 -0700648 *mapping = dma_map_single_attrs(&pdev->dev, data + bp->rx_dma_offset,
649 bp->rx_buf_use_size, bp->rx_dir,
650 DMA_ATTR_WEAK_ORDERING);
Michael Chanc0c050c2015-10-22 16:01:17 -0400651
652 if (dma_mapping_error(&pdev->dev, *mapping)) {
653 kfree(data);
654 data = NULL;
655 }
656 return data;
657}
658
Michael Chan38413402017-02-06 16:55:43 -0500659int bnxt_alloc_rx_data(struct bnxt *bp, struct bnxt_rx_ring_info *rxr,
660 u16 prod, gfp_t gfp)
Michael Chanc0c050c2015-10-22 16:01:17 -0400661{
662 struct rx_bd *rxbd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)];
663 struct bnxt_sw_rx_bd *rx_buf = &rxr->rx_buf_ring[prod];
Michael Chanc0c050c2015-10-22 16:01:17 -0400664 dma_addr_t mapping;
665
Michael Chanc61fb992017-02-06 16:55:36 -0500666 if (BNXT_RX_PAGE_MODE(bp)) {
667 struct page *page = __bnxt_alloc_rx_page(bp, &mapping, gfp);
Michael Chanc0c050c2015-10-22 16:01:17 -0400668
Michael Chanc61fb992017-02-06 16:55:36 -0500669 if (!page)
670 return -ENOMEM;
671
672 rx_buf->data = page;
673 rx_buf->data_ptr = page_address(page) + bp->rx_offset;
674 } else {
675 u8 *data = __bnxt_alloc_rx_data(bp, &mapping, gfp);
676
677 if (!data)
678 return -ENOMEM;
679
680 rx_buf->data = data;
681 rx_buf->data_ptr = data + bp->rx_offset;
682 }
Michael Chan11cd1192017-02-06 16:55:33 -0500683 rx_buf->mapping = mapping;
Michael Chanc0c050c2015-10-22 16:01:17 -0400684
685 rxbd->rx_bd_haddr = cpu_to_le64(mapping);
Michael Chanc0c050c2015-10-22 16:01:17 -0400686 return 0;
687}
688
Michael Chanc6d30e82017-02-06 16:55:42 -0500689void bnxt_reuse_rx_data(struct bnxt_rx_ring_info *rxr, u16 cons, void *data)
Michael Chanc0c050c2015-10-22 16:01:17 -0400690{
691 u16 prod = rxr->rx_prod;
692 struct bnxt_sw_rx_bd *cons_rx_buf, *prod_rx_buf;
693 struct rx_bd *cons_bd, *prod_bd;
694
695 prod_rx_buf = &rxr->rx_buf_ring[prod];
696 cons_rx_buf = &rxr->rx_buf_ring[cons];
697
698 prod_rx_buf->data = data;
Michael Chan6bb19472017-02-06 16:55:32 -0500699 prod_rx_buf->data_ptr = cons_rx_buf->data_ptr;
Michael Chanc0c050c2015-10-22 16:01:17 -0400700
Michael Chan11cd1192017-02-06 16:55:33 -0500701 prod_rx_buf->mapping = cons_rx_buf->mapping;
Michael Chanc0c050c2015-10-22 16:01:17 -0400702
703 prod_bd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)];
704 cons_bd = &rxr->rx_desc_ring[RX_RING(cons)][RX_IDX(cons)];
705
706 prod_bd->rx_bd_haddr = cons_bd->rx_bd_haddr;
707}
708
709static inline u16 bnxt_find_next_agg_idx(struct bnxt_rx_ring_info *rxr, u16 idx)
710{
711 u16 next, max = rxr->rx_agg_bmap_size;
712
713 next = find_next_zero_bit(rxr->rx_agg_bmap, max, idx);
714 if (next >= max)
715 next = find_first_zero_bit(rxr->rx_agg_bmap, max);
716 return next;
717}
718
719static inline int bnxt_alloc_rx_page(struct bnxt *bp,
720 struct bnxt_rx_ring_info *rxr,
721 u16 prod, gfp_t gfp)
722{
723 struct rx_bd *rxbd =
724 &rxr->rx_agg_desc_ring[RX_RING(prod)][RX_IDX(prod)];
725 struct bnxt_sw_rx_agg_bd *rx_agg_buf;
726 struct pci_dev *pdev = bp->pdev;
727 struct page *page;
728 dma_addr_t mapping;
729 u16 sw_prod = rxr->rx_sw_agg_prod;
Michael Chan89d0a062016-04-25 02:30:51 -0400730 unsigned int offset = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -0400731
Michael Chan89d0a062016-04-25 02:30:51 -0400732 if (PAGE_SIZE > BNXT_RX_PAGE_SIZE) {
733 page = rxr->rx_page;
734 if (!page) {
735 page = alloc_page(gfp);
736 if (!page)
737 return -ENOMEM;
738 rxr->rx_page = page;
739 rxr->rx_page_offset = 0;
740 }
741 offset = rxr->rx_page_offset;
742 rxr->rx_page_offset += BNXT_RX_PAGE_SIZE;
743 if (rxr->rx_page_offset == PAGE_SIZE)
744 rxr->rx_page = NULL;
745 else
746 get_page(page);
747 } else {
748 page = alloc_page(gfp);
749 if (!page)
750 return -ENOMEM;
751 }
Michael Chanc0c050c2015-10-22 16:01:17 -0400752
Shannon Nelsonc519fe92017-05-09 18:30:12 -0700753 mapping = dma_map_page_attrs(&pdev->dev, page, offset,
754 BNXT_RX_PAGE_SIZE, PCI_DMA_FROMDEVICE,
755 DMA_ATTR_WEAK_ORDERING);
Michael Chanc0c050c2015-10-22 16:01:17 -0400756 if (dma_mapping_error(&pdev->dev, mapping)) {
757 __free_page(page);
758 return -EIO;
759 }
760
761 if (unlikely(test_bit(sw_prod, rxr->rx_agg_bmap)))
762 sw_prod = bnxt_find_next_agg_idx(rxr, sw_prod);
763
764 __set_bit(sw_prod, rxr->rx_agg_bmap);
765 rx_agg_buf = &rxr->rx_agg_ring[sw_prod];
766 rxr->rx_sw_agg_prod = NEXT_RX_AGG(sw_prod);
767
768 rx_agg_buf->page = page;
Michael Chan89d0a062016-04-25 02:30:51 -0400769 rx_agg_buf->offset = offset;
Michael Chanc0c050c2015-10-22 16:01:17 -0400770 rx_agg_buf->mapping = mapping;
771 rxbd->rx_bd_haddr = cpu_to_le64(mapping);
772 rxbd->rx_bd_opaque = sw_prod;
773 return 0;
774}
775
776static void bnxt_reuse_rx_agg_bufs(struct bnxt_napi *bnapi, u16 cp_cons,
777 u32 agg_bufs)
778{
779 struct bnxt *bp = bnapi->bp;
780 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
Michael Chanb6ab4b02016-01-02 23:44:59 -0500781 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
Michael Chanc0c050c2015-10-22 16:01:17 -0400782 u16 prod = rxr->rx_agg_prod;
783 u16 sw_prod = rxr->rx_sw_agg_prod;
784 u32 i;
785
786 for (i = 0; i < agg_bufs; i++) {
787 u16 cons;
788 struct rx_agg_cmp *agg;
789 struct bnxt_sw_rx_agg_bd *cons_rx_buf, *prod_rx_buf;
790 struct rx_bd *prod_bd;
791 struct page *page;
792
793 agg = (struct rx_agg_cmp *)
794 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
795 cons = agg->rx_agg_cmp_opaque;
796 __clear_bit(cons, rxr->rx_agg_bmap);
797
798 if (unlikely(test_bit(sw_prod, rxr->rx_agg_bmap)))
799 sw_prod = bnxt_find_next_agg_idx(rxr, sw_prod);
800
801 __set_bit(sw_prod, rxr->rx_agg_bmap);
802 prod_rx_buf = &rxr->rx_agg_ring[sw_prod];
803 cons_rx_buf = &rxr->rx_agg_ring[cons];
804
805 /* It is possible for sw_prod to be equal to cons, so
806 * set cons_rx_buf->page to NULL first.
807 */
808 page = cons_rx_buf->page;
809 cons_rx_buf->page = NULL;
810 prod_rx_buf->page = page;
Michael Chan89d0a062016-04-25 02:30:51 -0400811 prod_rx_buf->offset = cons_rx_buf->offset;
Michael Chanc0c050c2015-10-22 16:01:17 -0400812
813 prod_rx_buf->mapping = cons_rx_buf->mapping;
814
815 prod_bd = &rxr->rx_agg_desc_ring[RX_RING(prod)][RX_IDX(prod)];
816
817 prod_bd->rx_bd_haddr = cpu_to_le64(cons_rx_buf->mapping);
818 prod_bd->rx_bd_opaque = sw_prod;
819
820 prod = NEXT_RX_AGG(prod);
821 sw_prod = NEXT_RX_AGG(sw_prod);
822 cp_cons = NEXT_CMP(cp_cons);
823 }
824 rxr->rx_agg_prod = prod;
825 rxr->rx_sw_agg_prod = sw_prod;
826}
827
Michael Chanc61fb992017-02-06 16:55:36 -0500828static struct sk_buff *bnxt_rx_page_skb(struct bnxt *bp,
829 struct bnxt_rx_ring_info *rxr,
830 u16 cons, void *data, u8 *data_ptr,
831 dma_addr_t dma_addr,
832 unsigned int offset_and_len)
833{
834 unsigned int payload = offset_and_len >> 16;
835 unsigned int len = offset_and_len & 0xffff;
836 struct skb_frag_struct *frag;
837 struct page *page = data;
838 u16 prod = rxr->rx_prod;
839 struct sk_buff *skb;
840 int off, err;
841
842 err = bnxt_alloc_rx_data(bp, rxr, prod, GFP_ATOMIC);
843 if (unlikely(err)) {
844 bnxt_reuse_rx_data(rxr, cons, data);
845 return NULL;
846 }
847 dma_addr -= bp->rx_dma_offset;
Shannon Nelsonc519fe92017-05-09 18:30:12 -0700848 dma_unmap_page_attrs(&bp->pdev->dev, dma_addr, PAGE_SIZE, bp->rx_dir,
849 DMA_ATTR_WEAK_ORDERING);
Michael Chanc61fb992017-02-06 16:55:36 -0500850
851 if (unlikely(!payload))
852 payload = eth_get_headlen(data_ptr, len);
853
854 skb = napi_alloc_skb(&rxr->bnapi->napi, payload);
855 if (!skb) {
856 __free_page(page);
857 return NULL;
858 }
859
860 off = (void *)data_ptr - page_address(page);
861 skb_add_rx_frag(skb, 0, page, off, len, PAGE_SIZE);
862 memcpy(skb->data - NET_IP_ALIGN, data_ptr - NET_IP_ALIGN,
863 payload + NET_IP_ALIGN);
864
865 frag = &skb_shinfo(skb)->frags[0];
866 skb_frag_size_sub(frag, payload);
867 frag->page_offset += payload;
868 skb->data_len -= payload;
869 skb->tail += payload;
870
871 return skb;
872}
873
Michael Chanc0c050c2015-10-22 16:01:17 -0400874static struct sk_buff *bnxt_rx_skb(struct bnxt *bp,
875 struct bnxt_rx_ring_info *rxr, u16 cons,
Michael Chan6bb19472017-02-06 16:55:32 -0500876 void *data, u8 *data_ptr,
877 dma_addr_t dma_addr,
878 unsigned int offset_and_len)
Michael Chanc0c050c2015-10-22 16:01:17 -0400879{
Michael Chan6bb19472017-02-06 16:55:32 -0500880 u16 prod = rxr->rx_prod;
Michael Chanc0c050c2015-10-22 16:01:17 -0400881 struct sk_buff *skb;
Michael Chan6bb19472017-02-06 16:55:32 -0500882 int err;
Michael Chanc0c050c2015-10-22 16:01:17 -0400883
884 err = bnxt_alloc_rx_data(bp, rxr, prod, GFP_ATOMIC);
885 if (unlikely(err)) {
886 bnxt_reuse_rx_data(rxr, cons, data);
887 return NULL;
888 }
889
890 skb = build_skb(data, 0);
Shannon Nelsonc519fe92017-05-09 18:30:12 -0700891 dma_unmap_single_attrs(&bp->pdev->dev, dma_addr, bp->rx_buf_use_size,
892 bp->rx_dir, DMA_ATTR_WEAK_ORDERING);
Michael Chanc0c050c2015-10-22 16:01:17 -0400893 if (!skb) {
894 kfree(data);
895 return NULL;
896 }
897
Michael Chanb3dba772017-02-06 16:55:35 -0500898 skb_reserve(skb, bp->rx_offset);
Michael Chan6bb19472017-02-06 16:55:32 -0500899 skb_put(skb, offset_and_len & 0xffff);
Michael Chanc0c050c2015-10-22 16:01:17 -0400900 return skb;
901}
902
903static struct sk_buff *bnxt_rx_pages(struct bnxt *bp, struct bnxt_napi *bnapi,
904 struct sk_buff *skb, u16 cp_cons,
905 u32 agg_bufs)
906{
907 struct pci_dev *pdev = bp->pdev;
908 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
Michael Chanb6ab4b02016-01-02 23:44:59 -0500909 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
Michael Chanc0c050c2015-10-22 16:01:17 -0400910 u16 prod = rxr->rx_agg_prod;
911 u32 i;
912
913 for (i = 0; i < agg_bufs; i++) {
914 u16 cons, frag_len;
915 struct rx_agg_cmp *agg;
916 struct bnxt_sw_rx_agg_bd *cons_rx_buf;
917 struct page *page;
918 dma_addr_t mapping;
919
920 agg = (struct rx_agg_cmp *)
921 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
922 cons = agg->rx_agg_cmp_opaque;
923 frag_len = (le32_to_cpu(agg->rx_agg_cmp_len_flags_type) &
924 RX_AGG_CMP_LEN) >> RX_AGG_CMP_LEN_SHIFT;
925
926 cons_rx_buf = &rxr->rx_agg_ring[cons];
Michael Chan89d0a062016-04-25 02:30:51 -0400927 skb_fill_page_desc(skb, i, cons_rx_buf->page,
928 cons_rx_buf->offset, frag_len);
Michael Chanc0c050c2015-10-22 16:01:17 -0400929 __clear_bit(cons, rxr->rx_agg_bmap);
930
931 /* It is possible for bnxt_alloc_rx_page() to allocate
932 * a sw_prod index that equals the cons index, so we
933 * need to clear the cons entry now.
934 */
Michael Chan11cd1192017-02-06 16:55:33 -0500935 mapping = cons_rx_buf->mapping;
Michael Chanc0c050c2015-10-22 16:01:17 -0400936 page = cons_rx_buf->page;
937 cons_rx_buf->page = NULL;
938
939 if (bnxt_alloc_rx_page(bp, rxr, prod, GFP_ATOMIC) != 0) {
940 struct skb_shared_info *shinfo;
941 unsigned int nr_frags;
942
943 shinfo = skb_shinfo(skb);
944 nr_frags = --shinfo->nr_frags;
945 __skb_frag_set_page(&shinfo->frags[nr_frags], NULL);
946
947 dev_kfree_skb(skb);
948
949 cons_rx_buf->page = page;
950
951 /* Update prod since possibly some pages have been
952 * allocated already.
953 */
954 rxr->rx_agg_prod = prod;
955 bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs - i);
956 return NULL;
957 }
958
Shannon Nelsonc519fe92017-05-09 18:30:12 -0700959 dma_unmap_page_attrs(&pdev->dev, mapping, BNXT_RX_PAGE_SIZE,
960 PCI_DMA_FROMDEVICE,
961 DMA_ATTR_WEAK_ORDERING);
Michael Chanc0c050c2015-10-22 16:01:17 -0400962
963 skb->data_len += frag_len;
964 skb->len += frag_len;
965 skb->truesize += PAGE_SIZE;
966
967 prod = NEXT_RX_AGG(prod);
968 cp_cons = NEXT_CMP(cp_cons);
969 }
970 rxr->rx_agg_prod = prod;
971 return skb;
972}
973
974static int bnxt_agg_bufs_valid(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
975 u8 agg_bufs, u32 *raw_cons)
976{
977 u16 last;
978 struct rx_agg_cmp *agg;
979
980 *raw_cons = ADV_RAW_CMP(*raw_cons, agg_bufs);
981 last = RING_CMP(*raw_cons);
982 agg = (struct rx_agg_cmp *)
983 &cpr->cp_desc_ring[CP_RING(last)][CP_IDX(last)];
984 return RX_AGG_CMP_VALID(agg, *raw_cons);
985}
986
987static inline struct sk_buff *bnxt_copy_skb(struct bnxt_napi *bnapi, u8 *data,
988 unsigned int len,
989 dma_addr_t mapping)
990{
991 struct bnxt *bp = bnapi->bp;
992 struct pci_dev *pdev = bp->pdev;
993 struct sk_buff *skb;
994
995 skb = napi_alloc_skb(&bnapi->napi, len);
996 if (!skb)
997 return NULL;
998
Michael Chan745fc052017-02-06 16:55:34 -0500999 dma_sync_single_for_cpu(&pdev->dev, mapping, bp->rx_copy_thresh,
1000 bp->rx_dir);
Michael Chanc0c050c2015-10-22 16:01:17 -04001001
Michael Chan6bb19472017-02-06 16:55:32 -05001002 memcpy(skb->data - NET_IP_ALIGN, data - NET_IP_ALIGN,
1003 len + NET_IP_ALIGN);
Michael Chanc0c050c2015-10-22 16:01:17 -04001004
Michael Chan745fc052017-02-06 16:55:34 -05001005 dma_sync_single_for_device(&pdev->dev, mapping, bp->rx_copy_thresh,
1006 bp->rx_dir);
Michael Chanc0c050c2015-10-22 16:01:17 -04001007
1008 skb_put(skb, len);
1009 return skb;
1010}
1011
Michael Chanfa7e2812016-05-10 19:18:00 -04001012static int bnxt_discard_rx(struct bnxt *bp, struct bnxt_napi *bnapi,
1013 u32 *raw_cons, void *cmp)
1014{
1015 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1016 struct rx_cmp *rxcmp = cmp;
1017 u32 tmp_raw_cons = *raw_cons;
1018 u8 cmp_type, agg_bufs = 0;
1019
1020 cmp_type = RX_CMP_TYPE(rxcmp);
1021
1022 if (cmp_type == CMP_TYPE_RX_L2_CMP) {
1023 agg_bufs = (le32_to_cpu(rxcmp->rx_cmp_misc_v1) &
1024 RX_CMP_AGG_BUFS) >>
1025 RX_CMP_AGG_BUFS_SHIFT;
1026 } else if (cmp_type == CMP_TYPE_RX_L2_TPA_END_CMP) {
1027 struct rx_tpa_end_cmp *tpa_end = cmp;
1028
1029 agg_bufs = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) &
1030 RX_TPA_END_CMP_AGG_BUFS) >>
1031 RX_TPA_END_CMP_AGG_BUFS_SHIFT;
1032 }
1033
1034 if (agg_bufs) {
1035 if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, &tmp_raw_cons))
1036 return -EBUSY;
1037 }
1038 *raw_cons = tmp_raw_cons;
1039 return 0;
1040}
1041
Michael Chanc213eae2017-10-13 21:09:29 -04001042static void bnxt_queue_sp_work(struct bnxt *bp)
1043{
1044 if (BNXT_PF(bp))
1045 queue_work(bnxt_pf_wq, &bp->sp_task);
1046 else
1047 schedule_work(&bp->sp_task);
1048}
1049
1050static void bnxt_cancel_sp_work(struct bnxt *bp)
1051{
1052 if (BNXT_PF(bp))
1053 flush_workqueue(bnxt_pf_wq);
1054 else
1055 cancel_work_sync(&bp->sp_task);
1056}
1057
Michael Chanfa7e2812016-05-10 19:18:00 -04001058static void bnxt_sched_reset(struct bnxt *bp, struct bnxt_rx_ring_info *rxr)
1059{
1060 if (!rxr->bnapi->in_reset) {
1061 rxr->bnapi->in_reset = true;
1062 set_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event);
Michael Chanc213eae2017-10-13 21:09:29 -04001063 bnxt_queue_sp_work(bp);
Michael Chanfa7e2812016-05-10 19:18:00 -04001064 }
1065 rxr->rx_next_cons = 0xffff;
1066}
1067
Michael Chanc0c050c2015-10-22 16:01:17 -04001068static void bnxt_tpa_start(struct bnxt *bp, struct bnxt_rx_ring_info *rxr,
1069 struct rx_tpa_start_cmp *tpa_start,
1070 struct rx_tpa_start_cmp_ext *tpa_start1)
1071{
1072 u8 agg_id = TPA_START_AGG_ID(tpa_start);
1073 u16 cons, prod;
1074 struct bnxt_tpa_info *tpa_info;
1075 struct bnxt_sw_rx_bd *cons_rx_buf, *prod_rx_buf;
1076 struct rx_bd *prod_bd;
1077 dma_addr_t mapping;
1078
1079 cons = tpa_start->rx_tpa_start_cmp_opaque;
1080 prod = rxr->rx_prod;
1081 cons_rx_buf = &rxr->rx_buf_ring[cons];
1082 prod_rx_buf = &rxr->rx_buf_ring[prod];
1083 tpa_info = &rxr->rx_tpa[agg_id];
1084
Michael Chanfa7e2812016-05-10 19:18:00 -04001085 if (unlikely(cons != rxr->rx_next_cons)) {
1086 bnxt_sched_reset(bp, rxr);
1087 return;
1088 }
Sathya Perlaee5c7fb2017-07-24 12:34:28 -04001089 /* Store cfa_code in tpa_info to use in tpa_end
1090 * completion processing.
1091 */
1092 tpa_info->cfa_code = TPA_START_CFA_CODE(tpa_start1);
Michael Chanc0c050c2015-10-22 16:01:17 -04001093 prod_rx_buf->data = tpa_info->data;
Michael Chan6bb19472017-02-06 16:55:32 -05001094 prod_rx_buf->data_ptr = tpa_info->data_ptr;
Michael Chanc0c050c2015-10-22 16:01:17 -04001095
1096 mapping = tpa_info->mapping;
Michael Chan11cd1192017-02-06 16:55:33 -05001097 prod_rx_buf->mapping = mapping;
Michael Chanc0c050c2015-10-22 16:01:17 -04001098
1099 prod_bd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)];
1100
1101 prod_bd->rx_bd_haddr = cpu_to_le64(mapping);
1102
1103 tpa_info->data = cons_rx_buf->data;
Michael Chan6bb19472017-02-06 16:55:32 -05001104 tpa_info->data_ptr = cons_rx_buf->data_ptr;
Michael Chanc0c050c2015-10-22 16:01:17 -04001105 cons_rx_buf->data = NULL;
Michael Chan11cd1192017-02-06 16:55:33 -05001106 tpa_info->mapping = cons_rx_buf->mapping;
Michael Chanc0c050c2015-10-22 16:01:17 -04001107
1108 tpa_info->len =
1109 le32_to_cpu(tpa_start->rx_tpa_start_cmp_len_flags_type) >>
1110 RX_TPA_START_CMP_LEN_SHIFT;
1111 if (likely(TPA_START_HASH_VALID(tpa_start))) {
1112 u32 hash_type = TPA_START_HASH_TYPE(tpa_start);
1113
1114 tpa_info->hash_type = PKT_HASH_TYPE_L4;
1115 tpa_info->gso_type = SKB_GSO_TCPV4;
1116 /* RSS profiles 1 and 3 with extract code 0 for inner 4-tuple */
1117 if (hash_type == 3)
1118 tpa_info->gso_type = SKB_GSO_TCPV6;
1119 tpa_info->rss_hash =
1120 le32_to_cpu(tpa_start->rx_tpa_start_cmp_rss_hash);
1121 } else {
1122 tpa_info->hash_type = PKT_HASH_TYPE_NONE;
1123 tpa_info->gso_type = 0;
1124 if (netif_msg_rx_err(bp))
1125 netdev_warn(bp->dev, "TPA packet without valid hash\n");
1126 }
1127 tpa_info->flags2 = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_flags2);
1128 tpa_info->metadata = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_metadata);
Michael Chan94758f82016-06-13 02:25:35 -04001129 tpa_info->hdr_info = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_hdr_info);
Michael Chanc0c050c2015-10-22 16:01:17 -04001130
1131 rxr->rx_prod = NEXT_RX(prod);
1132 cons = NEXT_RX(cons);
Michael Chan376a5b82016-05-10 19:17:59 -04001133 rxr->rx_next_cons = NEXT_RX(cons);
Michael Chanc0c050c2015-10-22 16:01:17 -04001134 cons_rx_buf = &rxr->rx_buf_ring[cons];
1135
1136 bnxt_reuse_rx_data(rxr, cons, cons_rx_buf->data);
1137 rxr->rx_prod = NEXT_RX(rxr->rx_prod);
1138 cons_rx_buf->data = NULL;
1139}
1140
1141static void bnxt_abort_tpa(struct bnxt *bp, struct bnxt_napi *bnapi,
1142 u16 cp_cons, u32 agg_bufs)
1143{
1144 if (agg_bufs)
1145 bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs);
1146}
1147
Michael Chan94758f82016-06-13 02:25:35 -04001148static struct sk_buff *bnxt_gro_func_5731x(struct bnxt_tpa_info *tpa_info,
1149 int payload_off, int tcp_ts,
1150 struct sk_buff *skb)
1151{
1152#ifdef CONFIG_INET
1153 struct tcphdr *th;
1154 int len, nw_off;
1155 u16 outer_ip_off, inner_ip_off, inner_mac_off;
1156 u32 hdr_info = tpa_info->hdr_info;
1157 bool loopback = false;
1158
1159 inner_ip_off = BNXT_TPA_INNER_L3_OFF(hdr_info);
1160 inner_mac_off = BNXT_TPA_INNER_L2_OFF(hdr_info);
1161 outer_ip_off = BNXT_TPA_OUTER_L3_OFF(hdr_info);
1162
1163 /* If the packet is an internal loopback packet, the offsets will
1164 * have an extra 4 bytes.
1165 */
1166 if (inner_mac_off == 4) {
1167 loopback = true;
1168 } else if (inner_mac_off > 4) {
1169 __be16 proto = *((__be16 *)(skb->data + inner_ip_off -
1170 ETH_HLEN - 2));
1171
1172 /* We only support inner iPv4/ipv6. If we don't see the
1173 * correct protocol ID, it must be a loopback packet where
1174 * the offsets are off by 4.
1175 */
Dan Carpenter09a76362016-07-07 11:23:09 +03001176 if (proto != htons(ETH_P_IP) && proto != htons(ETH_P_IPV6))
Michael Chan94758f82016-06-13 02:25:35 -04001177 loopback = true;
1178 }
1179 if (loopback) {
1180 /* internal loopback packet, subtract all offsets by 4 */
1181 inner_ip_off -= 4;
1182 inner_mac_off -= 4;
1183 outer_ip_off -= 4;
1184 }
1185
1186 nw_off = inner_ip_off - ETH_HLEN;
1187 skb_set_network_header(skb, nw_off);
1188 if (tpa_info->flags2 & RX_TPA_START_CMP_FLAGS2_IP_TYPE) {
1189 struct ipv6hdr *iph = ipv6_hdr(skb);
1190
1191 skb_set_transport_header(skb, nw_off + sizeof(struct ipv6hdr));
1192 len = skb->len - skb_transport_offset(skb);
1193 th = tcp_hdr(skb);
1194 th->check = ~tcp_v6_check(len, &iph->saddr, &iph->daddr, 0);
1195 } else {
1196 struct iphdr *iph = ip_hdr(skb);
1197
1198 skb_set_transport_header(skb, nw_off + sizeof(struct iphdr));
1199 len = skb->len - skb_transport_offset(skb);
1200 th = tcp_hdr(skb);
1201 th->check = ~tcp_v4_check(len, iph->saddr, iph->daddr, 0);
1202 }
1203
1204 if (inner_mac_off) { /* tunnel */
1205 struct udphdr *uh = NULL;
1206 __be16 proto = *((__be16 *)(skb->data + outer_ip_off -
1207 ETH_HLEN - 2));
1208
1209 if (proto == htons(ETH_P_IP)) {
1210 struct iphdr *iph = (struct iphdr *)skb->data;
1211
1212 if (iph->protocol == IPPROTO_UDP)
1213 uh = (struct udphdr *)(iph + 1);
1214 } else {
1215 struct ipv6hdr *iph = (struct ipv6hdr *)skb->data;
1216
1217 if (iph->nexthdr == IPPROTO_UDP)
1218 uh = (struct udphdr *)(iph + 1);
1219 }
1220 if (uh) {
1221 if (uh->check)
1222 skb_shinfo(skb)->gso_type |=
1223 SKB_GSO_UDP_TUNNEL_CSUM;
1224 else
1225 skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL;
1226 }
1227 }
1228#endif
1229 return skb;
1230}
1231
Michael Chanc0c050c2015-10-22 16:01:17 -04001232#define BNXT_IPV4_HDR_SIZE (sizeof(struct iphdr) + sizeof(struct tcphdr))
1233#define BNXT_IPV6_HDR_SIZE (sizeof(struct ipv6hdr) + sizeof(struct tcphdr))
1234
Michael Chan309369c2016-06-13 02:25:34 -04001235static struct sk_buff *bnxt_gro_func_5730x(struct bnxt_tpa_info *tpa_info,
1236 int payload_off, int tcp_ts,
Michael Chanc0c050c2015-10-22 16:01:17 -04001237 struct sk_buff *skb)
1238{
Michael Chand1611c32015-10-25 22:27:57 -04001239#ifdef CONFIG_INET
Michael Chanc0c050c2015-10-22 16:01:17 -04001240 struct tcphdr *th;
Michael Chan719ca812017-01-17 22:07:19 -05001241 int len, nw_off, tcp_opt_len = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04001242
Michael Chan309369c2016-06-13 02:25:34 -04001243 if (tcp_ts)
Michael Chanc0c050c2015-10-22 16:01:17 -04001244 tcp_opt_len = 12;
1245
Michael Chanc0c050c2015-10-22 16:01:17 -04001246 if (tpa_info->gso_type == SKB_GSO_TCPV4) {
1247 struct iphdr *iph;
1248
1249 nw_off = payload_off - BNXT_IPV4_HDR_SIZE - tcp_opt_len -
1250 ETH_HLEN;
1251 skb_set_network_header(skb, nw_off);
1252 iph = ip_hdr(skb);
1253 skb_set_transport_header(skb, nw_off + sizeof(struct iphdr));
1254 len = skb->len - skb_transport_offset(skb);
1255 th = tcp_hdr(skb);
1256 th->check = ~tcp_v4_check(len, iph->saddr, iph->daddr, 0);
1257 } else if (tpa_info->gso_type == SKB_GSO_TCPV6) {
1258 struct ipv6hdr *iph;
1259
1260 nw_off = payload_off - BNXT_IPV6_HDR_SIZE - tcp_opt_len -
1261 ETH_HLEN;
1262 skb_set_network_header(skb, nw_off);
1263 iph = ipv6_hdr(skb);
1264 skb_set_transport_header(skb, nw_off + sizeof(struct ipv6hdr));
1265 len = skb->len - skb_transport_offset(skb);
1266 th = tcp_hdr(skb);
1267 th->check = ~tcp_v6_check(len, &iph->saddr, &iph->daddr, 0);
1268 } else {
1269 dev_kfree_skb_any(skb);
1270 return NULL;
1271 }
Michael Chanc0c050c2015-10-22 16:01:17 -04001272
1273 if (nw_off) { /* tunnel */
1274 struct udphdr *uh = NULL;
1275
1276 if (skb->protocol == htons(ETH_P_IP)) {
1277 struct iphdr *iph = (struct iphdr *)skb->data;
1278
1279 if (iph->protocol == IPPROTO_UDP)
1280 uh = (struct udphdr *)(iph + 1);
1281 } else {
1282 struct ipv6hdr *iph = (struct ipv6hdr *)skb->data;
1283
1284 if (iph->nexthdr == IPPROTO_UDP)
1285 uh = (struct udphdr *)(iph + 1);
1286 }
1287 if (uh) {
1288 if (uh->check)
1289 skb_shinfo(skb)->gso_type |=
1290 SKB_GSO_UDP_TUNNEL_CSUM;
1291 else
1292 skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL;
1293 }
1294 }
1295#endif
1296 return skb;
1297}
1298
Michael Chan309369c2016-06-13 02:25:34 -04001299static inline struct sk_buff *bnxt_gro_skb(struct bnxt *bp,
1300 struct bnxt_tpa_info *tpa_info,
1301 struct rx_tpa_end_cmp *tpa_end,
1302 struct rx_tpa_end_cmp_ext *tpa_end1,
1303 struct sk_buff *skb)
1304{
1305#ifdef CONFIG_INET
1306 int payload_off;
1307 u16 segs;
1308
1309 segs = TPA_END_TPA_SEGS(tpa_end);
1310 if (segs == 1)
1311 return skb;
1312
1313 NAPI_GRO_CB(skb)->count = segs;
1314 skb_shinfo(skb)->gso_size =
1315 le32_to_cpu(tpa_end1->rx_tpa_end_cmp_seg_len);
1316 skb_shinfo(skb)->gso_type = tpa_info->gso_type;
1317 payload_off = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) &
1318 RX_TPA_END_CMP_PAYLOAD_OFFSET) >>
1319 RX_TPA_END_CMP_PAYLOAD_OFFSET_SHIFT;
1320 skb = bp->gro_func(tpa_info, payload_off, TPA_END_GRO_TS(tpa_end), skb);
Michael Chan59109062016-12-29 12:13:35 -05001321 if (likely(skb))
1322 tcp_gro_complete(skb);
Michael Chan309369c2016-06-13 02:25:34 -04001323#endif
1324 return skb;
1325}
1326
Sathya Perlaee5c7fb2017-07-24 12:34:28 -04001327/* Given the cfa_code of a received packet determine which
1328 * netdev (vf-rep or PF) the packet is destined to.
1329 */
1330static struct net_device *bnxt_get_pkt_dev(struct bnxt *bp, u16 cfa_code)
1331{
1332 struct net_device *dev = bnxt_get_vf_rep(bp, cfa_code);
1333
1334 /* if vf-rep dev is NULL, the must belongs to the PF */
1335 return dev ? dev : bp->dev;
1336}
1337
Michael Chanc0c050c2015-10-22 16:01:17 -04001338static inline struct sk_buff *bnxt_tpa_end(struct bnxt *bp,
1339 struct bnxt_napi *bnapi,
1340 u32 *raw_cons,
1341 struct rx_tpa_end_cmp *tpa_end,
1342 struct rx_tpa_end_cmp_ext *tpa_end1,
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001343 u8 *event)
Michael Chanc0c050c2015-10-22 16:01:17 -04001344{
1345 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
Michael Chanb6ab4b02016-01-02 23:44:59 -05001346 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
Michael Chanc0c050c2015-10-22 16:01:17 -04001347 u8 agg_id = TPA_END_AGG_ID(tpa_end);
Michael Chan6bb19472017-02-06 16:55:32 -05001348 u8 *data_ptr, agg_bufs;
Michael Chanc0c050c2015-10-22 16:01:17 -04001349 u16 cp_cons = RING_CMP(*raw_cons);
1350 unsigned int len;
1351 struct bnxt_tpa_info *tpa_info;
1352 dma_addr_t mapping;
1353 struct sk_buff *skb;
Michael Chan6bb19472017-02-06 16:55:32 -05001354 void *data;
Michael Chanc0c050c2015-10-22 16:01:17 -04001355
Michael Chanfa7e2812016-05-10 19:18:00 -04001356 if (unlikely(bnapi->in_reset)) {
1357 int rc = bnxt_discard_rx(bp, bnapi, raw_cons, tpa_end);
1358
1359 if (rc < 0)
1360 return ERR_PTR(-EBUSY);
1361 return NULL;
1362 }
1363
Michael Chanc0c050c2015-10-22 16:01:17 -04001364 tpa_info = &rxr->rx_tpa[agg_id];
1365 data = tpa_info->data;
Michael Chan6bb19472017-02-06 16:55:32 -05001366 data_ptr = tpa_info->data_ptr;
1367 prefetch(data_ptr);
Michael Chanc0c050c2015-10-22 16:01:17 -04001368 len = tpa_info->len;
1369 mapping = tpa_info->mapping;
1370
1371 agg_bufs = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) &
1372 RX_TPA_END_CMP_AGG_BUFS) >> RX_TPA_END_CMP_AGG_BUFS_SHIFT;
1373
1374 if (agg_bufs) {
1375 if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, raw_cons))
1376 return ERR_PTR(-EBUSY);
1377
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001378 *event |= BNXT_AGG_EVENT;
Michael Chanc0c050c2015-10-22 16:01:17 -04001379 cp_cons = NEXT_CMP(cp_cons);
1380 }
1381
Michael Chan69c149e2017-06-23 14:01:00 -04001382 if (unlikely(agg_bufs > MAX_SKB_FRAGS || TPA_END_ERRORS(tpa_end1))) {
Michael Chanc0c050c2015-10-22 16:01:17 -04001383 bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs);
Michael Chan69c149e2017-06-23 14:01:00 -04001384 if (agg_bufs > MAX_SKB_FRAGS)
1385 netdev_warn(bp->dev, "TPA frags %d exceeded MAX_SKB_FRAGS %d\n",
1386 agg_bufs, (int)MAX_SKB_FRAGS);
Michael Chanc0c050c2015-10-22 16:01:17 -04001387 return NULL;
1388 }
1389
1390 if (len <= bp->rx_copy_thresh) {
Michael Chan6bb19472017-02-06 16:55:32 -05001391 skb = bnxt_copy_skb(bnapi, data_ptr, len, mapping);
Michael Chanc0c050c2015-10-22 16:01:17 -04001392 if (!skb) {
1393 bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs);
1394 return NULL;
1395 }
1396 } else {
1397 u8 *new_data;
1398 dma_addr_t new_mapping;
1399
1400 new_data = __bnxt_alloc_rx_data(bp, &new_mapping, GFP_ATOMIC);
1401 if (!new_data) {
1402 bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs);
1403 return NULL;
1404 }
1405
1406 tpa_info->data = new_data;
Michael Chanb3dba772017-02-06 16:55:35 -05001407 tpa_info->data_ptr = new_data + bp->rx_offset;
Michael Chanc0c050c2015-10-22 16:01:17 -04001408 tpa_info->mapping = new_mapping;
1409
1410 skb = build_skb(data, 0);
Shannon Nelsonc519fe92017-05-09 18:30:12 -07001411 dma_unmap_single_attrs(&bp->pdev->dev, mapping,
1412 bp->rx_buf_use_size, bp->rx_dir,
1413 DMA_ATTR_WEAK_ORDERING);
Michael Chanc0c050c2015-10-22 16:01:17 -04001414
1415 if (!skb) {
1416 kfree(data);
1417 bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs);
1418 return NULL;
1419 }
Michael Chanb3dba772017-02-06 16:55:35 -05001420 skb_reserve(skb, bp->rx_offset);
Michael Chanc0c050c2015-10-22 16:01:17 -04001421 skb_put(skb, len);
1422 }
1423
1424 if (agg_bufs) {
1425 skb = bnxt_rx_pages(bp, bnapi, skb, cp_cons, agg_bufs);
1426 if (!skb) {
1427 /* Page reuse already handled by bnxt_rx_pages(). */
1428 return NULL;
1429 }
1430 }
Sathya Perlaee5c7fb2017-07-24 12:34:28 -04001431
1432 skb->protocol =
1433 eth_type_trans(skb, bnxt_get_pkt_dev(bp, tpa_info->cfa_code));
Michael Chanc0c050c2015-10-22 16:01:17 -04001434
1435 if (tpa_info->hash_type != PKT_HASH_TYPE_NONE)
1436 skb_set_hash(skb, tpa_info->rss_hash, tpa_info->hash_type);
1437
Michael Chan8852ddb2016-06-06 02:37:16 -04001438 if ((tpa_info->flags2 & RX_CMP_FLAGS2_META_FORMAT_VLAN) &&
1439 (skb->dev->features & NETIF_F_HW_VLAN_CTAG_RX)) {
Michael Chanc0c050c2015-10-22 16:01:17 -04001440 u16 vlan_proto = tpa_info->metadata >>
1441 RX_CMP_FLAGS2_METADATA_TPID_SFT;
Michael Chaned7bc6022018-03-09 23:46:06 -05001442 u16 vtag = tpa_info->metadata & RX_CMP_FLAGS2_METADATA_TCI_MASK;
Michael Chanc0c050c2015-10-22 16:01:17 -04001443
Michael Chan8852ddb2016-06-06 02:37:16 -04001444 __vlan_hwaccel_put_tag(skb, htons(vlan_proto), vtag);
Michael Chanc0c050c2015-10-22 16:01:17 -04001445 }
1446
1447 skb_checksum_none_assert(skb);
1448 if (likely(tpa_info->flags2 & RX_TPA_START_CMP_FLAGS2_L4_CS_CALC)) {
1449 skb->ip_summed = CHECKSUM_UNNECESSARY;
1450 skb->csum_level =
1451 (tpa_info->flags2 & RX_CMP_FLAGS2_T_L4_CS_CALC) >> 3;
1452 }
1453
1454 if (TPA_END_GRO(tpa_end))
Michael Chan309369c2016-06-13 02:25:34 -04001455 skb = bnxt_gro_skb(bp, tpa_info, tpa_end, tpa_end1, skb);
Michael Chanc0c050c2015-10-22 16:01:17 -04001456
1457 return skb;
1458}
1459
Sathya Perlaee5c7fb2017-07-24 12:34:28 -04001460static void bnxt_deliver_skb(struct bnxt *bp, struct bnxt_napi *bnapi,
1461 struct sk_buff *skb)
1462{
1463 if (skb->dev != bp->dev) {
1464 /* this packet belongs to a vf-rep */
1465 bnxt_vf_rep_rx(bp, skb);
1466 return;
1467 }
1468 skb_record_rx_queue(skb, bnapi->index);
1469 napi_gro_receive(&bnapi->napi, skb);
1470}
1471
Michael Chanc0c050c2015-10-22 16:01:17 -04001472/* returns the following:
1473 * 1 - 1 packet successfully received
1474 * 0 - successful TPA_START, packet not completed yet
1475 * -EBUSY - completion ring does not have all the agg buffers yet
1476 * -ENOMEM - packet aborted due to out of memory
1477 * -EIO - packet aborted due to hw error indicated in BD
1478 */
1479static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_napi *bnapi, u32 *raw_cons,
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001480 u8 *event)
Michael Chanc0c050c2015-10-22 16:01:17 -04001481{
1482 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
Michael Chanb6ab4b02016-01-02 23:44:59 -05001483 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
Michael Chanc0c050c2015-10-22 16:01:17 -04001484 struct net_device *dev = bp->dev;
1485 struct rx_cmp *rxcmp;
1486 struct rx_cmp_ext *rxcmp1;
1487 u32 tmp_raw_cons = *raw_cons;
Sathya Perlaee5c7fb2017-07-24 12:34:28 -04001488 u16 cfa_code, cons, prod, cp_cons = RING_CMP(tmp_raw_cons);
Michael Chanc0c050c2015-10-22 16:01:17 -04001489 struct bnxt_sw_rx_bd *rx_buf;
1490 unsigned int len;
Michael Chan6bb19472017-02-06 16:55:32 -05001491 u8 *data_ptr, agg_bufs, cmp_type;
Michael Chanc0c050c2015-10-22 16:01:17 -04001492 dma_addr_t dma_addr;
1493 struct sk_buff *skb;
Michael Chan6bb19472017-02-06 16:55:32 -05001494 void *data;
Michael Chanc0c050c2015-10-22 16:01:17 -04001495 int rc = 0;
Michael Chanc61fb992017-02-06 16:55:36 -05001496 u32 misc;
Michael Chanc0c050c2015-10-22 16:01:17 -04001497
1498 rxcmp = (struct rx_cmp *)
1499 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
1500
1501 tmp_raw_cons = NEXT_RAW_CMP(tmp_raw_cons);
1502 cp_cons = RING_CMP(tmp_raw_cons);
1503 rxcmp1 = (struct rx_cmp_ext *)
1504 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
1505
1506 if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons))
1507 return -EBUSY;
1508
1509 cmp_type = RX_CMP_TYPE(rxcmp);
1510
1511 prod = rxr->rx_prod;
1512
1513 if (cmp_type == CMP_TYPE_RX_L2_TPA_START_CMP) {
1514 bnxt_tpa_start(bp, rxr, (struct rx_tpa_start_cmp *)rxcmp,
1515 (struct rx_tpa_start_cmp_ext *)rxcmp1);
1516
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001517 *event |= BNXT_RX_EVENT;
Colin Ian Kinge7e70fa2018-01-16 10:22:50 +00001518 goto next_rx_no_prod_no_len;
Michael Chanc0c050c2015-10-22 16:01:17 -04001519
1520 } else if (cmp_type == CMP_TYPE_RX_L2_TPA_END_CMP) {
1521 skb = bnxt_tpa_end(bp, bnapi, &tmp_raw_cons,
1522 (struct rx_tpa_end_cmp *)rxcmp,
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001523 (struct rx_tpa_end_cmp_ext *)rxcmp1, event);
Michael Chanc0c050c2015-10-22 16:01:17 -04001524
Tobias Klauser1fac4b22017-09-26 15:12:26 +02001525 if (IS_ERR(skb))
Michael Chanc0c050c2015-10-22 16:01:17 -04001526 return -EBUSY;
1527
1528 rc = -ENOMEM;
1529 if (likely(skb)) {
Sathya Perlaee5c7fb2017-07-24 12:34:28 -04001530 bnxt_deliver_skb(bp, bnapi, skb);
Michael Chanc0c050c2015-10-22 16:01:17 -04001531 rc = 1;
1532 }
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001533 *event |= BNXT_RX_EVENT;
Colin Ian Kinge7e70fa2018-01-16 10:22:50 +00001534 goto next_rx_no_prod_no_len;
Michael Chanc0c050c2015-10-22 16:01:17 -04001535 }
1536
1537 cons = rxcmp->rx_cmp_opaque;
1538 rx_buf = &rxr->rx_buf_ring[cons];
1539 data = rx_buf->data;
Michael Chan6bb19472017-02-06 16:55:32 -05001540 data_ptr = rx_buf->data_ptr;
Michael Chanfa7e2812016-05-10 19:18:00 -04001541 if (unlikely(cons != rxr->rx_next_cons)) {
1542 int rc1 = bnxt_discard_rx(bp, bnapi, raw_cons, rxcmp);
1543
1544 bnxt_sched_reset(bp, rxr);
1545 return rc1;
1546 }
Michael Chan6bb19472017-02-06 16:55:32 -05001547 prefetch(data_ptr);
Michael Chanc0c050c2015-10-22 16:01:17 -04001548
Michael Chanc61fb992017-02-06 16:55:36 -05001549 misc = le32_to_cpu(rxcmp->rx_cmp_misc_v1);
1550 agg_bufs = (misc & RX_CMP_AGG_BUFS) >> RX_CMP_AGG_BUFS_SHIFT;
Michael Chanc0c050c2015-10-22 16:01:17 -04001551
1552 if (agg_bufs) {
1553 if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, &tmp_raw_cons))
1554 return -EBUSY;
1555
1556 cp_cons = NEXT_CMP(cp_cons);
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001557 *event |= BNXT_AGG_EVENT;
Michael Chanc0c050c2015-10-22 16:01:17 -04001558 }
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001559 *event |= BNXT_RX_EVENT;
Michael Chanc0c050c2015-10-22 16:01:17 -04001560
1561 rx_buf->data = NULL;
1562 if (rxcmp1->rx_cmp_cfa_code_errors_v2 & RX_CMP_L2_ERRORS) {
1563 bnxt_reuse_rx_data(rxr, cons, data);
1564 if (agg_bufs)
1565 bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs);
1566
1567 rc = -EIO;
1568 goto next_rx;
1569 }
1570
1571 len = le32_to_cpu(rxcmp->rx_cmp_len_flags_type) >> RX_CMP_LEN_SHIFT;
Michael Chan11cd1192017-02-06 16:55:33 -05001572 dma_addr = rx_buf->mapping;
Michael Chanc0c050c2015-10-22 16:01:17 -04001573
Michael Chanc6d30e82017-02-06 16:55:42 -05001574 if (bnxt_rx_xdp(bp, rxr, cons, data, &data_ptr, &len, event)) {
1575 rc = 1;
1576 goto next_rx;
1577 }
1578
Michael Chanc0c050c2015-10-22 16:01:17 -04001579 if (len <= bp->rx_copy_thresh) {
Michael Chan6bb19472017-02-06 16:55:32 -05001580 skb = bnxt_copy_skb(bnapi, data_ptr, len, dma_addr);
Michael Chanc0c050c2015-10-22 16:01:17 -04001581 bnxt_reuse_rx_data(rxr, cons, data);
1582 if (!skb) {
1583 rc = -ENOMEM;
1584 goto next_rx;
1585 }
1586 } else {
Michael Chanc61fb992017-02-06 16:55:36 -05001587 u32 payload;
1588
Michael Chanc6d30e82017-02-06 16:55:42 -05001589 if (rx_buf->data_ptr == data_ptr)
1590 payload = misc & RX_CMP_PAYLOAD_OFFSET;
1591 else
1592 payload = 0;
Michael Chan6bb19472017-02-06 16:55:32 -05001593 skb = bp->rx_skb_func(bp, rxr, cons, data, data_ptr, dma_addr,
Michael Chanc61fb992017-02-06 16:55:36 -05001594 payload | len);
Michael Chanc0c050c2015-10-22 16:01:17 -04001595 if (!skb) {
1596 rc = -ENOMEM;
1597 goto next_rx;
1598 }
1599 }
1600
1601 if (agg_bufs) {
1602 skb = bnxt_rx_pages(bp, bnapi, skb, cp_cons, agg_bufs);
1603 if (!skb) {
1604 rc = -ENOMEM;
1605 goto next_rx;
1606 }
1607 }
1608
1609 if (RX_CMP_HASH_VALID(rxcmp)) {
1610 u32 hash_type = RX_CMP_HASH_TYPE(rxcmp);
1611 enum pkt_hash_types type = PKT_HASH_TYPE_L4;
1612
1613 /* RSS profiles 1 and 3 with extract code 0 for inner 4-tuple */
1614 if (hash_type != 1 && hash_type != 3)
1615 type = PKT_HASH_TYPE_L3;
1616 skb_set_hash(skb, le32_to_cpu(rxcmp->rx_cmp_rss_hash), type);
1617 }
1618
Sathya Perlaee5c7fb2017-07-24 12:34:28 -04001619 cfa_code = RX_CMP_CFA_CODE(rxcmp1);
1620 skb->protocol = eth_type_trans(skb, bnxt_get_pkt_dev(bp, cfa_code));
Michael Chanc0c050c2015-10-22 16:01:17 -04001621
Michael Chan8852ddb2016-06-06 02:37:16 -04001622 if ((rxcmp1->rx_cmp_flags2 &
1623 cpu_to_le32(RX_CMP_FLAGS2_META_FORMAT_VLAN)) &&
1624 (skb->dev->features & NETIF_F_HW_VLAN_CTAG_RX)) {
Michael Chanc0c050c2015-10-22 16:01:17 -04001625 u32 meta_data = le32_to_cpu(rxcmp1->rx_cmp_meta_data);
Michael Chaned7bc6022018-03-09 23:46:06 -05001626 u16 vtag = meta_data & RX_CMP_FLAGS2_METADATA_TCI_MASK;
Michael Chanc0c050c2015-10-22 16:01:17 -04001627 u16 vlan_proto = meta_data >> RX_CMP_FLAGS2_METADATA_TPID_SFT;
1628
Michael Chan8852ddb2016-06-06 02:37:16 -04001629 __vlan_hwaccel_put_tag(skb, htons(vlan_proto), vtag);
Michael Chanc0c050c2015-10-22 16:01:17 -04001630 }
1631
1632 skb_checksum_none_assert(skb);
1633 if (RX_CMP_L4_CS_OK(rxcmp1)) {
1634 if (dev->features & NETIF_F_RXCSUM) {
1635 skb->ip_summed = CHECKSUM_UNNECESSARY;
1636 skb->csum_level = RX_CMP_ENCAP(rxcmp1);
1637 }
1638 } else {
Satish Baddipadige665e3502015-12-27 18:19:21 -05001639 if (rxcmp1->rx_cmp_cfa_code_errors_v2 & RX_CMP_L4_CS_ERR_BITS) {
1640 if (dev->features & NETIF_F_RXCSUM)
1641 cpr->rx_l4_csum_errors++;
1642 }
Michael Chanc0c050c2015-10-22 16:01:17 -04001643 }
1644
Sathya Perlaee5c7fb2017-07-24 12:34:28 -04001645 bnxt_deliver_skb(bp, bnapi, skb);
Michael Chanc0c050c2015-10-22 16:01:17 -04001646 rc = 1;
1647
1648next_rx:
1649 rxr->rx_prod = NEXT_RX(prod);
Michael Chan376a5b82016-05-10 19:17:59 -04001650 rxr->rx_next_cons = NEXT_RX(cons);
Michael Chanc0c050c2015-10-22 16:01:17 -04001651
Andy Gospodarek6a8788f2018-01-09 16:06:20 -05001652 cpr->rx_packets += 1;
1653 cpr->rx_bytes += len;
Colin Ian Kinge7e70fa2018-01-16 10:22:50 +00001654
1655next_rx_no_prod_no_len:
Michael Chanc0c050c2015-10-22 16:01:17 -04001656 *raw_cons = tmp_raw_cons;
1657
1658 return rc;
1659}
1660
Michael Chan2270bc52017-06-23 14:01:01 -04001661/* In netpoll mode, if we are using a combined completion ring, we need to
1662 * discard the rx packets and recycle the buffers.
1663 */
1664static int bnxt_force_rx_discard(struct bnxt *bp, struct bnxt_napi *bnapi,
1665 u32 *raw_cons, u8 *event)
1666{
1667 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1668 u32 tmp_raw_cons = *raw_cons;
1669 struct rx_cmp_ext *rxcmp1;
1670 struct rx_cmp *rxcmp;
1671 u16 cp_cons;
1672 u8 cmp_type;
1673
1674 cp_cons = RING_CMP(tmp_raw_cons);
1675 rxcmp = (struct rx_cmp *)
1676 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
1677
1678 tmp_raw_cons = NEXT_RAW_CMP(tmp_raw_cons);
1679 cp_cons = RING_CMP(tmp_raw_cons);
1680 rxcmp1 = (struct rx_cmp_ext *)
1681 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
1682
1683 if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons))
1684 return -EBUSY;
1685
1686 cmp_type = RX_CMP_TYPE(rxcmp);
1687 if (cmp_type == CMP_TYPE_RX_L2_CMP) {
1688 rxcmp1->rx_cmp_cfa_code_errors_v2 |=
1689 cpu_to_le32(RX_CMPL_ERRORS_CRC_ERROR);
1690 } else if (cmp_type == CMP_TYPE_RX_L2_TPA_END_CMP) {
1691 struct rx_tpa_end_cmp_ext *tpa_end1;
1692
1693 tpa_end1 = (struct rx_tpa_end_cmp_ext *)rxcmp1;
1694 tpa_end1->rx_tpa_end_cmp_errors_v2 |=
1695 cpu_to_le32(RX_TPA_END_CMP_ERRORS);
1696 }
1697 return bnxt_rx_pkt(bp, bnapi, raw_cons, event);
1698}
1699
Michael Chan4bb13ab2016-04-05 14:09:01 -04001700#define BNXT_GET_EVENT_PORT(data) \
Michael Chan87c374d2016-12-02 21:17:16 -05001701 ((data) & \
1702 ASYNC_EVENT_CMPL_PORT_CONN_NOT_ALLOWED_EVENT_DATA1_PORT_ID_MASK)
Michael Chan4bb13ab2016-04-05 14:09:01 -04001703
Michael Chanc0c050c2015-10-22 16:01:17 -04001704static int bnxt_async_event_process(struct bnxt *bp,
1705 struct hwrm_async_event_cmpl *cmpl)
1706{
1707 u16 event_id = le16_to_cpu(cmpl->event_id);
1708
1709 /* TODO CHIMP_FW: Define event id's for link change, error etc */
1710 switch (event_id) {
Michael Chan87c374d2016-12-02 21:17:16 -05001711 case ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE: {
Michael Chan8cbde112016-04-11 04:11:14 -04001712 u32 data1 = le32_to_cpu(cmpl->event_data1);
1713 struct bnxt_link_info *link_info = &bp->link_info;
1714
1715 if (BNXT_VF(bp))
1716 goto async_event_process_exit;
Michael Chana8168b62017-12-06 17:31:22 -05001717
1718 /* print unsupported speed warning in forced speed mode only */
1719 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED) &&
1720 (data1 & 0x20000)) {
Michael Chan8cbde112016-04-11 04:11:14 -04001721 u16 fw_speed = link_info->force_link_speed;
1722 u32 speed = bnxt_fw_to_ethtool_speed(fw_speed);
1723
Michael Chana8168b62017-12-06 17:31:22 -05001724 if (speed != SPEED_UNKNOWN)
1725 netdev_warn(bp->dev, "Link speed %d no longer supported\n",
1726 speed);
Michael Chan8cbde112016-04-11 04:11:14 -04001727 }
Michael Chan286ef9d2016-11-16 21:13:08 -05001728 set_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT, &bp->sp_event);
Michael Chan8cbde112016-04-11 04:11:14 -04001729 /* fall thru */
1730 }
Michael Chan87c374d2016-12-02 21:17:16 -05001731 case ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE:
Michael Chanc0c050c2015-10-22 16:01:17 -04001732 set_bit(BNXT_LINK_CHNG_SP_EVENT, &bp->sp_event);
Jeffrey Huang19241362016-02-26 04:00:00 -05001733 break;
Michael Chan87c374d2016-12-02 21:17:16 -05001734 case ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD:
Jeffrey Huang19241362016-02-26 04:00:00 -05001735 set_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT, &bp->sp_event);
Michael Chanc0c050c2015-10-22 16:01:17 -04001736 break;
Michael Chan87c374d2016-12-02 21:17:16 -05001737 case ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED: {
Michael Chan4bb13ab2016-04-05 14:09:01 -04001738 u32 data1 = le32_to_cpu(cmpl->event_data1);
1739 u16 port_id = BNXT_GET_EVENT_PORT(data1);
1740
1741 if (BNXT_VF(bp))
1742 break;
1743
1744 if (bp->pf.port_id != port_id)
1745 break;
1746
Michael Chan4bb13ab2016-04-05 14:09:01 -04001747 set_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT, &bp->sp_event);
1748 break;
1749 }
Michael Chan87c374d2016-12-02 21:17:16 -05001750 case ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE:
Michael Chanfc0f1922016-06-13 02:25:30 -04001751 if (BNXT_PF(bp))
1752 goto async_event_process_exit;
1753 set_bit(BNXT_RESET_TASK_SILENT_SP_EVENT, &bp->sp_event);
1754 break;
Michael Chanc0c050c2015-10-22 16:01:17 -04001755 default:
Jeffrey Huang19241362016-02-26 04:00:00 -05001756 goto async_event_process_exit;
Michael Chanc0c050c2015-10-22 16:01:17 -04001757 }
Michael Chanc213eae2017-10-13 21:09:29 -04001758 bnxt_queue_sp_work(bp);
Jeffrey Huang19241362016-02-26 04:00:00 -05001759async_event_process_exit:
Michael Chana588e452016-12-07 00:26:21 -05001760 bnxt_ulp_async_events(bp, cmpl);
Michael Chanc0c050c2015-10-22 16:01:17 -04001761 return 0;
1762}
1763
1764static int bnxt_hwrm_handler(struct bnxt *bp, struct tx_cmp *txcmp)
1765{
1766 u16 cmpl_type = TX_CMP_TYPE(txcmp), vf_id, seq_id;
1767 struct hwrm_cmpl *h_cmpl = (struct hwrm_cmpl *)txcmp;
1768 struct hwrm_fwd_req_cmpl *fwd_req_cmpl =
1769 (struct hwrm_fwd_req_cmpl *)txcmp;
1770
1771 switch (cmpl_type) {
1772 case CMPL_BASE_TYPE_HWRM_DONE:
1773 seq_id = le16_to_cpu(h_cmpl->sequence_id);
1774 if (seq_id == bp->hwrm_intr_seq_id)
1775 bp->hwrm_intr_seq_id = HWRM_SEQ_ID_INVALID;
1776 else
1777 netdev_err(bp->dev, "Invalid hwrm seq id %d\n", seq_id);
1778 break;
1779
1780 case CMPL_BASE_TYPE_HWRM_FWD_REQ:
1781 vf_id = le16_to_cpu(fwd_req_cmpl->source_id);
1782
1783 if ((vf_id < bp->pf.first_vf_id) ||
1784 (vf_id >= bp->pf.first_vf_id + bp->pf.active_vfs)) {
1785 netdev_err(bp->dev, "Msg contains invalid VF id %x\n",
1786 vf_id);
1787 return -EINVAL;
1788 }
1789
1790 set_bit(vf_id - bp->pf.first_vf_id, bp->pf.vf_event_bmap);
1791 set_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT, &bp->sp_event);
Michael Chanc213eae2017-10-13 21:09:29 -04001792 bnxt_queue_sp_work(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04001793 break;
1794
1795 case CMPL_BASE_TYPE_HWRM_ASYNC_EVENT:
1796 bnxt_async_event_process(bp,
1797 (struct hwrm_async_event_cmpl *)txcmp);
1798
1799 default:
1800 break;
1801 }
1802
1803 return 0;
1804}
1805
1806static irqreturn_t bnxt_msix(int irq, void *dev_instance)
1807{
1808 struct bnxt_napi *bnapi = dev_instance;
1809 struct bnxt *bp = bnapi->bp;
1810 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1811 u32 cons = RING_CMP(cpr->cp_raw_cons);
1812
Andy Gospodarek6a8788f2018-01-09 16:06:20 -05001813 cpr->event_ctr++;
Michael Chanc0c050c2015-10-22 16:01:17 -04001814 prefetch(&cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]);
1815 napi_schedule(&bnapi->napi);
1816 return IRQ_HANDLED;
1817}
1818
1819static inline int bnxt_has_work(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
1820{
1821 u32 raw_cons = cpr->cp_raw_cons;
1822 u16 cons = RING_CMP(raw_cons);
1823 struct tx_cmp *txcmp;
1824
1825 txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)];
1826
1827 return TX_CMP_VALID(txcmp, raw_cons);
1828}
1829
Michael Chanc0c050c2015-10-22 16:01:17 -04001830static irqreturn_t bnxt_inta(int irq, void *dev_instance)
1831{
1832 struct bnxt_napi *bnapi = dev_instance;
1833 struct bnxt *bp = bnapi->bp;
1834 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1835 u32 cons = RING_CMP(cpr->cp_raw_cons);
1836 u32 int_status;
1837
1838 prefetch(&cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]);
1839
1840 if (!bnxt_has_work(bp, cpr)) {
Jeffrey Huang11809492015-11-05 16:25:49 -05001841 int_status = readl(bp->bar0 + BNXT_CAG_REG_LEGACY_INT_STATUS);
Michael Chanc0c050c2015-10-22 16:01:17 -04001842 /* return if erroneous interrupt */
1843 if (!(int_status & (0x10000 << cpr->cp_ring_struct.fw_ring_id)))
1844 return IRQ_NONE;
1845 }
1846
1847 /* disable ring IRQ */
1848 BNXT_CP_DB_IRQ_DIS(cpr->cp_doorbell);
1849
1850 /* Return here if interrupt is shared and is disabled. */
1851 if (unlikely(atomic_read(&bp->intr_sem) != 0))
1852 return IRQ_HANDLED;
1853
1854 napi_schedule(&bnapi->napi);
1855 return IRQ_HANDLED;
1856}
1857
1858static int bnxt_poll_work(struct bnxt *bp, struct bnxt_napi *bnapi, int budget)
1859{
1860 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1861 u32 raw_cons = cpr->cp_raw_cons;
1862 u32 cons;
1863 int tx_pkts = 0;
1864 int rx_pkts = 0;
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001865 u8 event = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04001866 struct tx_cmp *txcmp;
1867
1868 while (1) {
1869 int rc;
1870
1871 cons = RING_CMP(raw_cons);
1872 txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)];
1873
1874 if (!TX_CMP_VALID(txcmp, raw_cons))
1875 break;
1876
Michael Chan67a95e22016-05-04 16:56:43 -04001877 /* The valid test of the entry must be done first before
1878 * reading any further.
1879 */
Michael Chanb67daab2016-05-15 03:04:51 -04001880 dma_rmb();
Michael Chanc0c050c2015-10-22 16:01:17 -04001881 if (TX_CMP_TYPE(txcmp) == CMP_TYPE_TX_L2_CMP) {
1882 tx_pkts++;
1883 /* return full budget so NAPI will complete. */
1884 if (unlikely(tx_pkts > bp->tx_wake_thresh))
1885 rx_pkts = budget;
1886 } else if ((TX_CMP_TYPE(txcmp) & 0x30) == 0x10) {
Michael Chan2270bc52017-06-23 14:01:01 -04001887 if (likely(budget))
1888 rc = bnxt_rx_pkt(bp, bnapi, &raw_cons, &event);
1889 else
1890 rc = bnxt_force_rx_discard(bp, bnapi, &raw_cons,
1891 &event);
Michael Chanc0c050c2015-10-22 16:01:17 -04001892 if (likely(rc >= 0))
1893 rx_pkts += rc;
Michael Chan903649e2017-08-28 13:40:30 -04001894 /* Increment rx_pkts when rc is -ENOMEM to count towards
1895 * the NAPI budget. Otherwise, we may potentially loop
1896 * here forever if we consistently cannot allocate
1897 * buffers.
1898 */
Calvin Owens2edbdb32017-12-08 09:05:26 -08001899 else if (rc == -ENOMEM && budget)
Michael Chan903649e2017-08-28 13:40:30 -04001900 rx_pkts++;
Michael Chanc0c050c2015-10-22 16:01:17 -04001901 else if (rc == -EBUSY) /* partial completion */
1902 break;
Michael Chanc0c050c2015-10-22 16:01:17 -04001903 } else if (unlikely((TX_CMP_TYPE(txcmp) ==
1904 CMPL_BASE_TYPE_HWRM_DONE) ||
1905 (TX_CMP_TYPE(txcmp) ==
1906 CMPL_BASE_TYPE_HWRM_FWD_REQ) ||
1907 (TX_CMP_TYPE(txcmp) ==
1908 CMPL_BASE_TYPE_HWRM_ASYNC_EVENT))) {
1909 bnxt_hwrm_handler(bp, txcmp);
1910 }
1911 raw_cons = NEXT_RAW_CMP(raw_cons);
1912
1913 if (rx_pkts == budget)
1914 break;
1915 }
1916
Michael Chan38413402017-02-06 16:55:43 -05001917 if (event & BNXT_TX_EVENT) {
1918 struct bnxt_tx_ring_info *txr = bnapi->tx_ring;
1919 void __iomem *db = txr->tx_doorbell;
1920 u16 prod = txr->tx_prod;
1921
1922 /* Sync BD data before updating doorbell */
1923 wmb();
1924
Sinan Kayafd141fa2018-03-25 10:39:20 -04001925 bnxt_db_write_relaxed(bp, db, DB_KEY_TX | prod);
Michael Chan38413402017-02-06 16:55:43 -05001926 }
1927
Michael Chanc0c050c2015-10-22 16:01:17 -04001928 cpr->cp_raw_cons = raw_cons;
1929 /* ACK completion ring before freeing tx ring and producing new
1930 * buffers in rx/agg rings to prevent overflowing the completion
1931 * ring.
1932 */
1933 BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
1934
1935 if (tx_pkts)
Michael Chanfa3e93e2017-02-06 16:55:41 -05001936 bnapi->tx_int(bp, bnapi, tx_pkts);
Michael Chanc0c050c2015-10-22 16:01:17 -04001937
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001938 if (event & BNXT_RX_EVENT) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05001939 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
Michael Chanc0c050c2015-10-22 16:01:17 -04001940
Michael Chan434c9752017-05-29 19:06:08 -04001941 bnxt_db_write(bp, rxr->rx_doorbell, DB_KEY_RX | rxr->rx_prod);
1942 if (event & BNXT_AGG_EVENT)
1943 bnxt_db_write(bp, rxr->rx_agg_doorbell,
1944 DB_KEY_RX | rxr->rx_agg_prod);
Michael Chanc0c050c2015-10-22 16:01:17 -04001945 }
1946 return rx_pkts;
1947}
1948
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04001949static int bnxt_poll_nitroa0(struct napi_struct *napi, int budget)
1950{
1951 struct bnxt_napi *bnapi = container_of(napi, struct bnxt_napi, napi);
1952 struct bnxt *bp = bnapi->bp;
1953 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
1954 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
1955 struct tx_cmp *txcmp;
1956 struct rx_cmp_ext *rxcmp1;
1957 u32 cp_cons, tmp_raw_cons;
1958 u32 raw_cons = cpr->cp_raw_cons;
1959 u32 rx_pkts = 0;
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001960 u8 event = 0;
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04001961
1962 while (1) {
1963 int rc;
1964
1965 cp_cons = RING_CMP(raw_cons);
1966 txcmp = &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
1967
1968 if (!TX_CMP_VALID(txcmp, raw_cons))
1969 break;
1970
1971 if ((TX_CMP_TYPE(txcmp) & 0x30) == 0x10) {
1972 tmp_raw_cons = NEXT_RAW_CMP(raw_cons);
1973 cp_cons = RING_CMP(tmp_raw_cons);
1974 rxcmp1 = (struct rx_cmp_ext *)
1975 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
1976
1977 if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons))
1978 break;
1979
1980 /* force an error to recycle the buffer */
1981 rxcmp1->rx_cmp_cfa_code_errors_v2 |=
1982 cpu_to_le32(RX_CMPL_ERRORS_CRC_ERROR);
1983
Michael Chan4e5dbbda2017-02-06 16:55:37 -05001984 rc = bnxt_rx_pkt(bp, bnapi, &raw_cons, &event);
Calvin Owens2edbdb32017-12-08 09:05:26 -08001985 if (likely(rc == -EIO) && budget)
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04001986 rx_pkts++;
1987 else if (rc == -EBUSY) /* partial completion */
1988 break;
1989 } else if (unlikely(TX_CMP_TYPE(txcmp) ==
1990 CMPL_BASE_TYPE_HWRM_DONE)) {
1991 bnxt_hwrm_handler(bp, txcmp);
1992 } else {
1993 netdev_err(bp->dev,
1994 "Invalid completion received on special ring\n");
1995 }
1996 raw_cons = NEXT_RAW_CMP(raw_cons);
1997
1998 if (rx_pkts == budget)
1999 break;
2000 }
2001
2002 cpr->cp_raw_cons = raw_cons;
2003 BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
Michael Chan434c9752017-05-29 19:06:08 -04002004 bnxt_db_write(bp, rxr->rx_doorbell, DB_KEY_RX | rxr->rx_prod);
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04002005
Michael Chan434c9752017-05-29 19:06:08 -04002006 if (event & BNXT_AGG_EVENT)
2007 bnxt_db_write(bp, rxr->rx_agg_doorbell,
2008 DB_KEY_RX | rxr->rx_agg_prod);
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04002009
2010 if (!bnxt_has_work(bp, cpr) && rx_pkts < budget) {
Eric Dumazet6ad20162017-01-30 08:22:01 -08002011 napi_complete_done(napi, rx_pkts);
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04002012 BNXT_CP_DB_REARM(cpr->cp_doorbell, cpr->cp_raw_cons);
2013 }
2014 return rx_pkts;
2015}
2016
Michael Chanc0c050c2015-10-22 16:01:17 -04002017static int bnxt_poll(struct napi_struct *napi, int budget)
2018{
2019 struct bnxt_napi *bnapi = container_of(napi, struct bnxt_napi, napi);
2020 struct bnxt *bp = bnapi->bp;
2021 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
2022 int work_done = 0;
2023
Michael Chanc0c050c2015-10-22 16:01:17 -04002024 while (1) {
2025 work_done += bnxt_poll_work(bp, bnapi, budget - work_done);
2026
2027 if (work_done >= budget)
2028 break;
2029
2030 if (!bnxt_has_work(bp, cpr)) {
Michael Chane7b95692016-12-29 12:13:32 -05002031 if (napi_complete_done(napi, work_done))
2032 BNXT_CP_DB_REARM(cpr->cp_doorbell,
2033 cpr->cp_raw_cons);
Michael Chanc0c050c2015-10-22 16:01:17 -04002034 break;
2035 }
2036 }
Andy Gospodarek6a8788f2018-01-09 16:06:20 -05002037 if (bp->flags & BNXT_FLAG_DIM) {
2038 struct net_dim_sample dim_sample;
2039
2040 net_dim_sample(cpr->event_ctr,
2041 cpr->rx_packets,
2042 cpr->rx_bytes,
2043 &dim_sample);
2044 net_dim(&cpr->dim, dim_sample);
2045 }
Michael Chanc0c050c2015-10-22 16:01:17 -04002046 mmiowb();
Michael Chanc0c050c2015-10-22 16:01:17 -04002047 return work_done;
2048}
2049
Michael Chanc0c050c2015-10-22 16:01:17 -04002050static void bnxt_free_tx_skbs(struct bnxt *bp)
2051{
2052 int i, max_idx;
2053 struct pci_dev *pdev = bp->pdev;
2054
Michael Chanb6ab4b02016-01-02 23:44:59 -05002055 if (!bp->tx_ring)
Michael Chanc0c050c2015-10-22 16:01:17 -04002056 return;
2057
2058 max_idx = bp->tx_nr_pages * TX_DESC_CNT;
2059 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05002060 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04002061 int j;
2062
Michael Chanc0c050c2015-10-22 16:01:17 -04002063 for (j = 0; j < max_idx;) {
2064 struct bnxt_sw_tx_bd *tx_buf = &txr->tx_buf_ring[j];
2065 struct sk_buff *skb = tx_buf->skb;
2066 int k, last;
2067
2068 if (!skb) {
2069 j++;
2070 continue;
2071 }
2072
2073 tx_buf->skb = NULL;
2074
2075 if (tx_buf->is_push) {
2076 dev_kfree_skb(skb);
2077 j += 2;
2078 continue;
2079 }
2080
2081 dma_unmap_single(&pdev->dev,
2082 dma_unmap_addr(tx_buf, mapping),
2083 skb_headlen(skb),
2084 PCI_DMA_TODEVICE);
2085
2086 last = tx_buf->nr_frags;
2087 j += 2;
Michael Chand612a572016-01-28 03:11:22 -05002088 for (k = 0; k < last; k++, j++) {
2089 int ring_idx = j & bp->tx_ring_mask;
Michael Chanc0c050c2015-10-22 16:01:17 -04002090 skb_frag_t *frag = &skb_shinfo(skb)->frags[k];
2091
Michael Chand612a572016-01-28 03:11:22 -05002092 tx_buf = &txr->tx_buf_ring[ring_idx];
Michael Chanc0c050c2015-10-22 16:01:17 -04002093 dma_unmap_page(
2094 &pdev->dev,
2095 dma_unmap_addr(tx_buf, mapping),
2096 skb_frag_size(frag), PCI_DMA_TODEVICE);
2097 }
2098 dev_kfree_skb(skb);
2099 }
2100 netdev_tx_reset_queue(netdev_get_tx_queue(bp->dev, i));
2101 }
2102}
2103
2104static void bnxt_free_rx_skbs(struct bnxt *bp)
2105{
2106 int i, max_idx, max_agg_idx;
2107 struct pci_dev *pdev = bp->pdev;
2108
Michael Chanb6ab4b02016-01-02 23:44:59 -05002109 if (!bp->rx_ring)
Michael Chanc0c050c2015-10-22 16:01:17 -04002110 return;
2111
2112 max_idx = bp->rx_nr_pages * RX_DESC_CNT;
2113 max_agg_idx = bp->rx_agg_nr_pages * RX_DESC_CNT;
2114 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05002115 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04002116 int j;
2117
Michael Chanc0c050c2015-10-22 16:01:17 -04002118 if (rxr->rx_tpa) {
2119 for (j = 0; j < MAX_TPA; j++) {
2120 struct bnxt_tpa_info *tpa_info =
2121 &rxr->rx_tpa[j];
2122 u8 *data = tpa_info->data;
2123
2124 if (!data)
2125 continue;
2126
Shannon Nelsonc519fe92017-05-09 18:30:12 -07002127 dma_unmap_single_attrs(&pdev->dev,
2128 tpa_info->mapping,
2129 bp->rx_buf_use_size,
2130 bp->rx_dir,
2131 DMA_ATTR_WEAK_ORDERING);
Michael Chanc0c050c2015-10-22 16:01:17 -04002132
2133 tpa_info->data = NULL;
2134
2135 kfree(data);
2136 }
2137 }
2138
2139 for (j = 0; j < max_idx; j++) {
2140 struct bnxt_sw_rx_bd *rx_buf = &rxr->rx_buf_ring[j];
Michael Chan3ed3a832017-03-28 19:47:31 -04002141 dma_addr_t mapping = rx_buf->mapping;
Michael Chan6bb19472017-02-06 16:55:32 -05002142 void *data = rx_buf->data;
Michael Chanc0c050c2015-10-22 16:01:17 -04002143
2144 if (!data)
2145 continue;
2146
Michael Chanc0c050c2015-10-22 16:01:17 -04002147 rx_buf->data = NULL;
2148
Michael Chan3ed3a832017-03-28 19:47:31 -04002149 if (BNXT_RX_PAGE_MODE(bp)) {
2150 mapping -= bp->rx_dma_offset;
Shannon Nelsonc519fe92017-05-09 18:30:12 -07002151 dma_unmap_page_attrs(&pdev->dev, mapping,
2152 PAGE_SIZE, bp->rx_dir,
2153 DMA_ATTR_WEAK_ORDERING);
Michael Chanc61fb992017-02-06 16:55:36 -05002154 __free_page(data);
Michael Chan3ed3a832017-03-28 19:47:31 -04002155 } else {
Shannon Nelsonc519fe92017-05-09 18:30:12 -07002156 dma_unmap_single_attrs(&pdev->dev, mapping,
2157 bp->rx_buf_use_size,
2158 bp->rx_dir,
2159 DMA_ATTR_WEAK_ORDERING);
Michael Chanc61fb992017-02-06 16:55:36 -05002160 kfree(data);
Michael Chan3ed3a832017-03-28 19:47:31 -04002161 }
Michael Chanc0c050c2015-10-22 16:01:17 -04002162 }
2163
2164 for (j = 0; j < max_agg_idx; j++) {
2165 struct bnxt_sw_rx_agg_bd *rx_agg_buf =
2166 &rxr->rx_agg_ring[j];
2167 struct page *page = rx_agg_buf->page;
2168
2169 if (!page)
2170 continue;
2171
Shannon Nelsonc519fe92017-05-09 18:30:12 -07002172 dma_unmap_page_attrs(&pdev->dev, rx_agg_buf->mapping,
2173 BNXT_RX_PAGE_SIZE,
2174 PCI_DMA_FROMDEVICE,
2175 DMA_ATTR_WEAK_ORDERING);
Michael Chanc0c050c2015-10-22 16:01:17 -04002176
2177 rx_agg_buf->page = NULL;
2178 __clear_bit(j, rxr->rx_agg_bmap);
2179
2180 __free_page(page);
2181 }
Michael Chan89d0a062016-04-25 02:30:51 -04002182 if (rxr->rx_page) {
2183 __free_page(rxr->rx_page);
2184 rxr->rx_page = NULL;
2185 }
Michael Chanc0c050c2015-10-22 16:01:17 -04002186 }
2187}
2188
2189static void bnxt_free_skbs(struct bnxt *bp)
2190{
2191 bnxt_free_tx_skbs(bp);
2192 bnxt_free_rx_skbs(bp);
2193}
2194
2195static void bnxt_free_ring(struct bnxt *bp, struct bnxt_ring_struct *ring)
2196{
2197 struct pci_dev *pdev = bp->pdev;
2198 int i;
2199
2200 for (i = 0; i < ring->nr_pages; i++) {
2201 if (!ring->pg_arr[i])
2202 continue;
2203
2204 dma_free_coherent(&pdev->dev, ring->page_size,
2205 ring->pg_arr[i], ring->dma_arr[i]);
2206
2207 ring->pg_arr[i] = NULL;
2208 }
2209 if (ring->pg_tbl) {
2210 dma_free_coherent(&pdev->dev, ring->nr_pages * 8,
2211 ring->pg_tbl, ring->pg_tbl_map);
2212 ring->pg_tbl = NULL;
2213 }
2214 if (ring->vmem_size && *ring->vmem) {
2215 vfree(*ring->vmem);
2216 *ring->vmem = NULL;
2217 }
2218}
2219
2220static int bnxt_alloc_ring(struct bnxt *bp, struct bnxt_ring_struct *ring)
2221{
2222 int i;
2223 struct pci_dev *pdev = bp->pdev;
2224
2225 if (ring->nr_pages > 1) {
2226 ring->pg_tbl = dma_alloc_coherent(&pdev->dev,
2227 ring->nr_pages * 8,
2228 &ring->pg_tbl_map,
2229 GFP_KERNEL);
2230 if (!ring->pg_tbl)
2231 return -ENOMEM;
2232 }
2233
2234 for (i = 0; i < ring->nr_pages; i++) {
2235 ring->pg_arr[i] = dma_alloc_coherent(&pdev->dev,
2236 ring->page_size,
2237 &ring->dma_arr[i],
2238 GFP_KERNEL);
2239 if (!ring->pg_arr[i])
2240 return -ENOMEM;
2241
2242 if (ring->nr_pages > 1)
2243 ring->pg_tbl[i] = cpu_to_le64(ring->dma_arr[i]);
2244 }
2245
2246 if (ring->vmem_size) {
2247 *ring->vmem = vzalloc(ring->vmem_size);
2248 if (!(*ring->vmem))
2249 return -ENOMEM;
2250 }
2251 return 0;
2252}
2253
2254static void bnxt_free_rx_rings(struct bnxt *bp)
2255{
2256 int i;
2257
Michael Chanb6ab4b02016-01-02 23:44:59 -05002258 if (!bp->rx_ring)
Michael Chanc0c050c2015-10-22 16:01:17 -04002259 return;
2260
2261 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05002262 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04002263 struct bnxt_ring_struct *ring;
2264
Michael Chanc6d30e82017-02-06 16:55:42 -05002265 if (rxr->xdp_prog)
2266 bpf_prog_put(rxr->xdp_prog);
2267
Jesper Dangaard Brouer96a86042018-01-03 11:25:44 +01002268 if (xdp_rxq_info_is_reg(&rxr->xdp_rxq))
2269 xdp_rxq_info_unreg(&rxr->xdp_rxq);
2270
Michael Chanc0c050c2015-10-22 16:01:17 -04002271 kfree(rxr->rx_tpa);
2272 rxr->rx_tpa = NULL;
2273
2274 kfree(rxr->rx_agg_bmap);
2275 rxr->rx_agg_bmap = NULL;
2276
2277 ring = &rxr->rx_ring_struct;
2278 bnxt_free_ring(bp, ring);
2279
2280 ring = &rxr->rx_agg_ring_struct;
2281 bnxt_free_ring(bp, ring);
2282 }
2283}
2284
2285static int bnxt_alloc_rx_rings(struct bnxt *bp)
2286{
2287 int i, rc, agg_rings = 0, tpa_rings = 0;
2288
Michael Chanb6ab4b02016-01-02 23:44:59 -05002289 if (!bp->rx_ring)
2290 return -ENOMEM;
2291
Michael Chanc0c050c2015-10-22 16:01:17 -04002292 if (bp->flags & BNXT_FLAG_AGG_RINGS)
2293 agg_rings = 1;
2294
2295 if (bp->flags & BNXT_FLAG_TPA)
2296 tpa_rings = 1;
2297
2298 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05002299 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04002300 struct bnxt_ring_struct *ring;
2301
Michael Chanc0c050c2015-10-22 16:01:17 -04002302 ring = &rxr->rx_ring_struct;
2303
Jesper Dangaard Brouer96a86042018-01-03 11:25:44 +01002304 rc = xdp_rxq_info_reg(&rxr->xdp_rxq, bp->dev, i);
2305 if (rc < 0)
2306 return rc;
2307
Michael Chanc0c050c2015-10-22 16:01:17 -04002308 rc = bnxt_alloc_ring(bp, ring);
2309 if (rc)
2310 return rc;
2311
2312 if (agg_rings) {
2313 u16 mem_size;
2314
2315 ring = &rxr->rx_agg_ring_struct;
2316 rc = bnxt_alloc_ring(bp, ring);
2317 if (rc)
2318 return rc;
2319
Michael Chan9899bb52018-03-31 13:54:16 -04002320 ring->grp_idx = i;
Michael Chanc0c050c2015-10-22 16:01:17 -04002321 rxr->rx_agg_bmap_size = bp->rx_agg_ring_mask + 1;
2322 mem_size = rxr->rx_agg_bmap_size / 8;
2323 rxr->rx_agg_bmap = kzalloc(mem_size, GFP_KERNEL);
2324 if (!rxr->rx_agg_bmap)
2325 return -ENOMEM;
2326
2327 if (tpa_rings) {
2328 rxr->rx_tpa = kcalloc(MAX_TPA,
2329 sizeof(struct bnxt_tpa_info),
2330 GFP_KERNEL);
2331 if (!rxr->rx_tpa)
2332 return -ENOMEM;
2333 }
2334 }
2335 }
2336 return 0;
2337}
2338
2339static void bnxt_free_tx_rings(struct bnxt *bp)
2340{
2341 int i;
2342 struct pci_dev *pdev = bp->pdev;
2343
Michael Chanb6ab4b02016-01-02 23:44:59 -05002344 if (!bp->tx_ring)
Michael Chanc0c050c2015-10-22 16:01:17 -04002345 return;
2346
2347 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05002348 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04002349 struct bnxt_ring_struct *ring;
2350
Michael Chanc0c050c2015-10-22 16:01:17 -04002351 if (txr->tx_push) {
2352 dma_free_coherent(&pdev->dev, bp->tx_push_size,
2353 txr->tx_push, txr->tx_push_mapping);
2354 txr->tx_push = NULL;
2355 }
2356
2357 ring = &txr->tx_ring_struct;
2358
2359 bnxt_free_ring(bp, ring);
2360 }
2361}
2362
2363static int bnxt_alloc_tx_rings(struct bnxt *bp)
2364{
2365 int i, j, rc;
2366 struct pci_dev *pdev = bp->pdev;
2367
2368 bp->tx_push_size = 0;
2369 if (bp->tx_push_thresh) {
2370 int push_size;
2371
2372 push_size = L1_CACHE_ALIGN(sizeof(struct tx_push_bd) +
2373 bp->tx_push_thresh);
2374
Michael Chan4419dbe2016-02-10 17:33:49 -05002375 if (push_size > 256) {
Michael Chanc0c050c2015-10-22 16:01:17 -04002376 push_size = 0;
2377 bp->tx_push_thresh = 0;
2378 }
2379
2380 bp->tx_push_size = push_size;
2381 }
2382
2383 for (i = 0, j = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05002384 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04002385 struct bnxt_ring_struct *ring;
Michael Chan2e8ef772018-04-26 17:44:31 -04002386 u8 qidx;
Michael Chanc0c050c2015-10-22 16:01:17 -04002387
Michael Chanc0c050c2015-10-22 16:01:17 -04002388 ring = &txr->tx_ring_struct;
2389
2390 rc = bnxt_alloc_ring(bp, ring);
2391 if (rc)
2392 return rc;
2393
Michael Chan9899bb52018-03-31 13:54:16 -04002394 ring->grp_idx = txr->bnapi->index;
Michael Chanc0c050c2015-10-22 16:01:17 -04002395 if (bp->tx_push_size) {
Michael Chanc0c050c2015-10-22 16:01:17 -04002396 dma_addr_t mapping;
2397
2398 /* One pre-allocated DMA buffer to backup
2399 * TX push operation
2400 */
2401 txr->tx_push = dma_alloc_coherent(&pdev->dev,
2402 bp->tx_push_size,
2403 &txr->tx_push_mapping,
2404 GFP_KERNEL);
2405
2406 if (!txr->tx_push)
2407 return -ENOMEM;
2408
Michael Chanc0c050c2015-10-22 16:01:17 -04002409 mapping = txr->tx_push_mapping +
2410 sizeof(struct tx_push_bd);
Michael Chan4419dbe2016-02-10 17:33:49 -05002411 txr->data_mapping = cpu_to_le64(mapping);
Michael Chanc0c050c2015-10-22 16:01:17 -04002412
Michael Chan4419dbe2016-02-10 17:33:49 -05002413 memset(txr->tx_push, 0, sizeof(struct tx_push_bd));
Michael Chanc0c050c2015-10-22 16:01:17 -04002414 }
Michael Chan2e8ef772018-04-26 17:44:31 -04002415 qidx = bp->tc_to_qidx[j];
2416 ring->queue_id = bp->q_info[qidx].queue_id;
Michael Chan5f449242017-02-06 16:55:40 -05002417 if (i < bp->tx_nr_rings_xdp)
2418 continue;
Michael Chanc0c050c2015-10-22 16:01:17 -04002419 if (i % bp->tx_nr_rings_per_tc == (bp->tx_nr_rings_per_tc - 1))
2420 j++;
2421 }
2422 return 0;
2423}
2424
2425static void bnxt_free_cp_rings(struct bnxt *bp)
2426{
2427 int i;
2428
2429 if (!bp->bnapi)
2430 return;
2431
2432 for (i = 0; i < bp->cp_nr_rings; i++) {
2433 struct bnxt_napi *bnapi = bp->bnapi[i];
2434 struct bnxt_cp_ring_info *cpr;
2435 struct bnxt_ring_struct *ring;
2436
2437 if (!bnapi)
2438 continue;
2439
2440 cpr = &bnapi->cp_ring;
2441 ring = &cpr->cp_ring_struct;
2442
2443 bnxt_free_ring(bp, ring);
2444 }
2445}
2446
2447static int bnxt_alloc_cp_rings(struct bnxt *bp)
2448{
Michael Chane5811b82018-03-31 13:54:18 -04002449 int i, rc, ulp_base_vec, ulp_msix;
Michael Chanc0c050c2015-10-22 16:01:17 -04002450
Michael Chane5811b82018-03-31 13:54:18 -04002451 ulp_msix = bnxt_get_ulp_msix_num(bp);
2452 ulp_base_vec = bnxt_get_ulp_msix_base(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04002453 for (i = 0; i < bp->cp_nr_rings; i++) {
2454 struct bnxt_napi *bnapi = bp->bnapi[i];
2455 struct bnxt_cp_ring_info *cpr;
2456 struct bnxt_ring_struct *ring;
2457
2458 if (!bnapi)
2459 continue;
2460
2461 cpr = &bnapi->cp_ring;
2462 ring = &cpr->cp_ring_struct;
2463
2464 rc = bnxt_alloc_ring(bp, ring);
2465 if (rc)
2466 return rc;
Michael Chane5811b82018-03-31 13:54:18 -04002467
2468 if (ulp_msix && i >= ulp_base_vec)
2469 ring->map_idx = i + ulp_msix;
2470 else
2471 ring->map_idx = i;
Michael Chanc0c050c2015-10-22 16:01:17 -04002472 }
2473 return 0;
2474}
2475
2476static void bnxt_init_ring_struct(struct bnxt *bp)
2477{
2478 int i;
2479
2480 for (i = 0; i < bp->cp_nr_rings; i++) {
2481 struct bnxt_napi *bnapi = bp->bnapi[i];
2482 struct bnxt_cp_ring_info *cpr;
2483 struct bnxt_rx_ring_info *rxr;
2484 struct bnxt_tx_ring_info *txr;
2485 struct bnxt_ring_struct *ring;
2486
2487 if (!bnapi)
2488 continue;
2489
2490 cpr = &bnapi->cp_ring;
2491 ring = &cpr->cp_ring_struct;
2492 ring->nr_pages = bp->cp_nr_pages;
2493 ring->page_size = HW_CMPD_RING_SIZE;
2494 ring->pg_arr = (void **)cpr->cp_desc_ring;
2495 ring->dma_arr = cpr->cp_desc_mapping;
2496 ring->vmem_size = 0;
2497
Michael Chanb6ab4b02016-01-02 23:44:59 -05002498 rxr = bnapi->rx_ring;
Michael Chan3b2b7d92016-01-02 23:45:00 -05002499 if (!rxr)
2500 goto skip_rx;
2501
Michael Chanc0c050c2015-10-22 16:01:17 -04002502 ring = &rxr->rx_ring_struct;
2503 ring->nr_pages = bp->rx_nr_pages;
2504 ring->page_size = HW_RXBD_RING_SIZE;
2505 ring->pg_arr = (void **)rxr->rx_desc_ring;
2506 ring->dma_arr = rxr->rx_desc_mapping;
2507 ring->vmem_size = SW_RXBD_RING_SIZE * bp->rx_nr_pages;
2508 ring->vmem = (void **)&rxr->rx_buf_ring;
2509
2510 ring = &rxr->rx_agg_ring_struct;
2511 ring->nr_pages = bp->rx_agg_nr_pages;
2512 ring->page_size = HW_RXBD_RING_SIZE;
2513 ring->pg_arr = (void **)rxr->rx_agg_desc_ring;
2514 ring->dma_arr = rxr->rx_agg_desc_mapping;
2515 ring->vmem_size = SW_RXBD_AGG_RING_SIZE * bp->rx_agg_nr_pages;
2516 ring->vmem = (void **)&rxr->rx_agg_ring;
2517
Michael Chan3b2b7d92016-01-02 23:45:00 -05002518skip_rx:
Michael Chanb6ab4b02016-01-02 23:44:59 -05002519 txr = bnapi->tx_ring;
Michael Chan3b2b7d92016-01-02 23:45:00 -05002520 if (!txr)
2521 continue;
2522
Michael Chanc0c050c2015-10-22 16:01:17 -04002523 ring = &txr->tx_ring_struct;
2524 ring->nr_pages = bp->tx_nr_pages;
2525 ring->page_size = HW_RXBD_RING_SIZE;
2526 ring->pg_arr = (void **)txr->tx_desc_ring;
2527 ring->dma_arr = txr->tx_desc_mapping;
2528 ring->vmem_size = SW_TXBD_RING_SIZE * bp->tx_nr_pages;
2529 ring->vmem = (void **)&txr->tx_buf_ring;
2530 }
2531}
2532
2533static void bnxt_init_rxbd_pages(struct bnxt_ring_struct *ring, u32 type)
2534{
2535 int i;
2536 u32 prod;
2537 struct rx_bd **rx_buf_ring;
2538
2539 rx_buf_ring = (struct rx_bd **)ring->pg_arr;
2540 for (i = 0, prod = 0; i < ring->nr_pages; i++) {
2541 int j;
2542 struct rx_bd *rxbd;
2543
2544 rxbd = rx_buf_ring[i];
2545 if (!rxbd)
2546 continue;
2547
2548 for (j = 0; j < RX_DESC_CNT; j++, rxbd++, prod++) {
2549 rxbd->rx_bd_len_flags_type = cpu_to_le32(type);
2550 rxbd->rx_bd_opaque = prod;
2551 }
2552 }
2553}
2554
2555static int bnxt_init_one_rx_ring(struct bnxt *bp, int ring_nr)
2556{
2557 struct net_device *dev = bp->dev;
Michael Chanc0c050c2015-10-22 16:01:17 -04002558 struct bnxt_rx_ring_info *rxr;
2559 struct bnxt_ring_struct *ring;
2560 u32 prod, type;
2561 int i;
2562
Michael Chanc0c050c2015-10-22 16:01:17 -04002563 type = (bp->rx_buf_use_size << RX_BD_LEN_SHIFT) |
2564 RX_BD_TYPE_RX_PACKET_BD | RX_BD_FLAGS_EOP;
2565
2566 if (NET_IP_ALIGN == 2)
2567 type |= RX_BD_FLAGS_SOP;
2568
Michael Chanb6ab4b02016-01-02 23:44:59 -05002569 rxr = &bp->rx_ring[ring_nr];
Michael Chanc0c050c2015-10-22 16:01:17 -04002570 ring = &rxr->rx_ring_struct;
2571 bnxt_init_rxbd_pages(ring, type);
2572
Michael Chanc6d30e82017-02-06 16:55:42 -05002573 if (BNXT_RX_PAGE_MODE(bp) && bp->xdp_prog) {
2574 rxr->xdp_prog = bpf_prog_add(bp->xdp_prog, 1);
2575 if (IS_ERR(rxr->xdp_prog)) {
2576 int rc = PTR_ERR(rxr->xdp_prog);
2577
2578 rxr->xdp_prog = NULL;
2579 return rc;
2580 }
2581 }
Michael Chanc0c050c2015-10-22 16:01:17 -04002582 prod = rxr->rx_prod;
2583 for (i = 0; i < bp->rx_ring_size; i++) {
2584 if (bnxt_alloc_rx_data(bp, rxr, prod, GFP_KERNEL) != 0) {
2585 netdev_warn(dev, "init'ed rx ring %d with %d/%d skbs only\n",
2586 ring_nr, i, bp->rx_ring_size);
2587 break;
2588 }
2589 prod = NEXT_RX(prod);
2590 }
2591 rxr->rx_prod = prod;
2592 ring->fw_ring_id = INVALID_HW_RING_ID;
2593
Michael Chanedd0c2c2015-12-27 18:19:19 -05002594 ring = &rxr->rx_agg_ring_struct;
2595 ring->fw_ring_id = INVALID_HW_RING_ID;
2596
Michael Chanc0c050c2015-10-22 16:01:17 -04002597 if (!(bp->flags & BNXT_FLAG_AGG_RINGS))
2598 return 0;
2599
Michael Chan2839f282016-04-25 02:30:50 -04002600 type = ((u32)BNXT_RX_PAGE_SIZE << RX_BD_LEN_SHIFT) |
Michael Chanc0c050c2015-10-22 16:01:17 -04002601 RX_BD_TYPE_RX_AGG_BD | RX_BD_FLAGS_SOP;
2602
2603 bnxt_init_rxbd_pages(ring, type);
2604
2605 prod = rxr->rx_agg_prod;
2606 for (i = 0; i < bp->rx_agg_ring_size; i++) {
2607 if (bnxt_alloc_rx_page(bp, rxr, prod, GFP_KERNEL) != 0) {
2608 netdev_warn(dev, "init'ed rx ring %d with %d/%d pages only\n",
2609 ring_nr, i, bp->rx_ring_size);
2610 break;
2611 }
2612 prod = NEXT_RX_AGG(prod);
2613 }
2614 rxr->rx_agg_prod = prod;
Michael Chanc0c050c2015-10-22 16:01:17 -04002615
2616 if (bp->flags & BNXT_FLAG_TPA) {
2617 if (rxr->rx_tpa) {
2618 u8 *data;
2619 dma_addr_t mapping;
2620
2621 for (i = 0; i < MAX_TPA; i++) {
2622 data = __bnxt_alloc_rx_data(bp, &mapping,
2623 GFP_KERNEL);
2624 if (!data)
2625 return -ENOMEM;
2626
2627 rxr->rx_tpa[i].data = data;
Michael Chanb3dba772017-02-06 16:55:35 -05002628 rxr->rx_tpa[i].data_ptr = data + bp->rx_offset;
Michael Chanc0c050c2015-10-22 16:01:17 -04002629 rxr->rx_tpa[i].mapping = mapping;
2630 }
2631 } else {
2632 netdev_err(bp->dev, "No resource allocated for LRO/GRO\n");
2633 return -ENOMEM;
2634 }
2635 }
2636
2637 return 0;
2638}
2639
Sankar Patchineelam22479252017-03-28 19:47:29 -04002640static void bnxt_init_cp_rings(struct bnxt *bp)
2641{
2642 int i;
2643
2644 for (i = 0; i < bp->cp_nr_rings; i++) {
2645 struct bnxt_cp_ring_info *cpr = &bp->bnapi[i]->cp_ring;
2646 struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
2647
2648 ring->fw_ring_id = INVALID_HW_RING_ID;
Andy Gospodarek6a8788f2018-01-09 16:06:20 -05002649 cpr->rx_ring_coal.coal_ticks = bp->rx_coal.coal_ticks;
2650 cpr->rx_ring_coal.coal_bufs = bp->rx_coal.coal_bufs;
Sankar Patchineelam22479252017-03-28 19:47:29 -04002651 }
2652}
2653
Michael Chanc0c050c2015-10-22 16:01:17 -04002654static int bnxt_init_rx_rings(struct bnxt *bp)
2655{
2656 int i, rc = 0;
2657
Michael Chanc61fb992017-02-06 16:55:36 -05002658 if (BNXT_RX_PAGE_MODE(bp)) {
Michael Chanc6d30e82017-02-06 16:55:42 -05002659 bp->rx_offset = NET_IP_ALIGN + XDP_PACKET_HEADROOM;
2660 bp->rx_dma_offset = XDP_PACKET_HEADROOM;
Michael Chanc61fb992017-02-06 16:55:36 -05002661 } else {
2662 bp->rx_offset = BNXT_RX_OFFSET;
2663 bp->rx_dma_offset = BNXT_RX_DMA_OFFSET;
2664 }
Michael Chanb3dba772017-02-06 16:55:35 -05002665
Michael Chanc0c050c2015-10-22 16:01:17 -04002666 for (i = 0; i < bp->rx_nr_rings; i++) {
2667 rc = bnxt_init_one_rx_ring(bp, i);
2668 if (rc)
2669 break;
2670 }
2671
2672 return rc;
2673}
2674
2675static int bnxt_init_tx_rings(struct bnxt *bp)
2676{
2677 u16 i;
2678
2679 bp->tx_wake_thresh = max_t(int, bp->tx_ring_size / 2,
2680 MAX_SKB_FRAGS + 1);
2681
2682 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05002683 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04002684 struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
2685
2686 ring->fw_ring_id = INVALID_HW_RING_ID;
2687 }
2688
2689 return 0;
2690}
2691
2692static void bnxt_free_ring_grps(struct bnxt *bp)
2693{
2694 kfree(bp->grp_info);
2695 bp->grp_info = NULL;
2696}
2697
2698static int bnxt_init_ring_grps(struct bnxt *bp, bool irq_re_init)
2699{
2700 int i;
2701
2702 if (irq_re_init) {
2703 bp->grp_info = kcalloc(bp->cp_nr_rings,
2704 sizeof(struct bnxt_ring_grp_info),
2705 GFP_KERNEL);
2706 if (!bp->grp_info)
2707 return -ENOMEM;
2708 }
2709 for (i = 0; i < bp->cp_nr_rings; i++) {
2710 if (irq_re_init)
2711 bp->grp_info[i].fw_stats_ctx = INVALID_HW_RING_ID;
2712 bp->grp_info[i].fw_grp_id = INVALID_HW_RING_ID;
2713 bp->grp_info[i].rx_fw_ring_id = INVALID_HW_RING_ID;
2714 bp->grp_info[i].agg_fw_ring_id = INVALID_HW_RING_ID;
2715 bp->grp_info[i].cp_fw_ring_id = INVALID_HW_RING_ID;
2716 }
2717 return 0;
2718}
2719
2720static void bnxt_free_vnics(struct bnxt *bp)
2721{
2722 kfree(bp->vnic_info);
2723 bp->vnic_info = NULL;
2724 bp->nr_vnics = 0;
2725}
2726
2727static int bnxt_alloc_vnics(struct bnxt *bp)
2728{
2729 int num_vnics = 1;
2730
2731#ifdef CONFIG_RFS_ACCEL
2732 if (bp->flags & BNXT_FLAG_RFS)
2733 num_vnics += bp->rx_nr_rings;
2734#endif
2735
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04002736 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
2737 num_vnics++;
2738
Michael Chanc0c050c2015-10-22 16:01:17 -04002739 bp->vnic_info = kcalloc(num_vnics, sizeof(struct bnxt_vnic_info),
2740 GFP_KERNEL);
2741 if (!bp->vnic_info)
2742 return -ENOMEM;
2743
2744 bp->nr_vnics = num_vnics;
2745 return 0;
2746}
2747
2748static void bnxt_init_vnics(struct bnxt *bp)
2749{
2750 int i;
2751
2752 for (i = 0; i < bp->nr_vnics; i++) {
2753 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
2754
2755 vnic->fw_vnic_id = INVALID_HW_RING_ID;
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04002756 vnic->fw_rss_cos_lb_ctx[0] = INVALID_HW_RING_ID;
2757 vnic->fw_rss_cos_lb_ctx[1] = INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04002758 vnic->fw_l2_ctx_id = INVALID_HW_RING_ID;
2759
2760 if (bp->vnic_info[i].rss_hash_key) {
2761 if (i == 0)
2762 prandom_bytes(vnic->rss_hash_key,
2763 HW_HASH_KEY_SIZE);
2764 else
2765 memcpy(vnic->rss_hash_key,
2766 bp->vnic_info[0].rss_hash_key,
2767 HW_HASH_KEY_SIZE);
2768 }
2769 }
2770}
2771
2772static int bnxt_calc_nr_ring_pages(u32 ring_size, int desc_per_pg)
2773{
2774 int pages;
2775
2776 pages = ring_size / desc_per_pg;
2777
2778 if (!pages)
2779 return 1;
2780
2781 pages++;
2782
2783 while (pages & (pages - 1))
2784 pages++;
2785
2786 return pages;
2787}
2788
Michael Chanc6d30e82017-02-06 16:55:42 -05002789void bnxt_set_tpa_flags(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04002790{
2791 bp->flags &= ~BNXT_FLAG_TPA;
Michael Chan341138c2017-01-13 01:32:01 -05002792 if (bp->flags & BNXT_FLAG_NO_AGG_RINGS)
2793 return;
Michael Chanc0c050c2015-10-22 16:01:17 -04002794 if (bp->dev->features & NETIF_F_LRO)
2795 bp->flags |= BNXT_FLAG_LRO;
Michael Chan1054aee2017-12-16 03:09:42 -05002796 else if (bp->dev->features & NETIF_F_GRO_HW)
Michael Chanc0c050c2015-10-22 16:01:17 -04002797 bp->flags |= BNXT_FLAG_GRO;
2798}
2799
2800/* bp->rx_ring_size, bp->tx_ring_size, dev->mtu, BNXT_FLAG_{G|L}RO flags must
2801 * be set on entry.
2802 */
2803void bnxt_set_ring_params(struct bnxt *bp)
2804{
2805 u32 ring_size, rx_size, rx_space;
2806 u32 agg_factor = 0, agg_ring_size = 0;
2807
2808 /* 8 for CRC and VLAN */
2809 rx_size = SKB_DATA_ALIGN(bp->dev->mtu + ETH_HLEN + NET_IP_ALIGN + 8);
2810
2811 rx_space = rx_size + NET_SKB_PAD +
2812 SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
2813
2814 bp->rx_copy_thresh = BNXT_RX_COPY_THRESH;
2815 ring_size = bp->rx_ring_size;
2816 bp->rx_agg_ring_size = 0;
2817 bp->rx_agg_nr_pages = 0;
2818
2819 if (bp->flags & BNXT_FLAG_TPA)
Michael Chan2839f282016-04-25 02:30:50 -04002820 agg_factor = min_t(u32, 4, 65536 / BNXT_RX_PAGE_SIZE);
Michael Chanc0c050c2015-10-22 16:01:17 -04002821
2822 bp->flags &= ~BNXT_FLAG_JUMBO;
Michael Chanbdbd1eb2016-12-29 12:13:43 -05002823 if (rx_space > PAGE_SIZE && !(bp->flags & BNXT_FLAG_NO_AGG_RINGS)) {
Michael Chanc0c050c2015-10-22 16:01:17 -04002824 u32 jumbo_factor;
2825
2826 bp->flags |= BNXT_FLAG_JUMBO;
2827 jumbo_factor = PAGE_ALIGN(bp->dev->mtu - 40) >> PAGE_SHIFT;
2828 if (jumbo_factor > agg_factor)
2829 agg_factor = jumbo_factor;
2830 }
2831 agg_ring_size = ring_size * agg_factor;
2832
2833 if (agg_ring_size) {
2834 bp->rx_agg_nr_pages = bnxt_calc_nr_ring_pages(agg_ring_size,
2835 RX_DESC_CNT);
2836 if (bp->rx_agg_nr_pages > MAX_RX_AGG_PAGES) {
2837 u32 tmp = agg_ring_size;
2838
2839 bp->rx_agg_nr_pages = MAX_RX_AGG_PAGES;
2840 agg_ring_size = MAX_RX_AGG_PAGES * RX_DESC_CNT - 1;
2841 netdev_warn(bp->dev, "rx agg ring size %d reduced to %d.\n",
2842 tmp, agg_ring_size);
2843 }
2844 bp->rx_agg_ring_size = agg_ring_size;
2845 bp->rx_agg_ring_mask = (bp->rx_agg_nr_pages * RX_DESC_CNT) - 1;
2846 rx_size = SKB_DATA_ALIGN(BNXT_RX_COPY_THRESH + NET_IP_ALIGN);
2847 rx_space = rx_size + NET_SKB_PAD +
2848 SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
2849 }
2850
2851 bp->rx_buf_use_size = rx_size;
2852 bp->rx_buf_size = rx_space;
2853
2854 bp->rx_nr_pages = bnxt_calc_nr_ring_pages(ring_size, RX_DESC_CNT);
2855 bp->rx_ring_mask = (bp->rx_nr_pages * RX_DESC_CNT) - 1;
2856
2857 ring_size = bp->tx_ring_size;
2858 bp->tx_nr_pages = bnxt_calc_nr_ring_pages(ring_size, TX_DESC_CNT);
2859 bp->tx_ring_mask = (bp->tx_nr_pages * TX_DESC_CNT) - 1;
2860
2861 ring_size = bp->rx_ring_size * (2 + agg_factor) + bp->tx_ring_size;
2862 bp->cp_ring_size = ring_size;
2863
2864 bp->cp_nr_pages = bnxt_calc_nr_ring_pages(ring_size, CP_DESC_CNT);
2865 if (bp->cp_nr_pages > MAX_CP_PAGES) {
2866 bp->cp_nr_pages = MAX_CP_PAGES;
2867 bp->cp_ring_size = MAX_CP_PAGES * CP_DESC_CNT - 1;
2868 netdev_warn(bp->dev, "completion ring size %d reduced to %d.\n",
2869 ring_size, bp->cp_ring_size);
2870 }
2871 bp->cp_bit = bp->cp_nr_pages * CP_DESC_CNT;
2872 bp->cp_ring_mask = bp->cp_bit - 1;
2873}
2874
Jesper Dangaard Brouer96a86042018-01-03 11:25:44 +01002875/* Changing allocation mode of RX rings.
2876 * TODO: Update when extending xdp_rxq_info to support allocation modes.
2877 */
Michael Chanc61fb992017-02-06 16:55:36 -05002878int bnxt_set_rx_skb_mode(struct bnxt *bp, bool page_mode)
Michael Chan6bb19472017-02-06 16:55:32 -05002879{
Michael Chanc61fb992017-02-06 16:55:36 -05002880 if (page_mode) {
2881 if (bp->dev->mtu > BNXT_MAX_PAGE_MODE_MTU)
2882 return -EOPNOTSUPP;
Michael Chan7eb9bb32017-10-26 11:51:25 -04002883 bp->dev->max_mtu =
2884 min_t(u16, bp->max_mtu, BNXT_MAX_PAGE_MODE_MTU);
Michael Chanc61fb992017-02-06 16:55:36 -05002885 bp->flags &= ~BNXT_FLAG_AGG_RINGS;
2886 bp->flags |= BNXT_FLAG_NO_AGG_RINGS | BNXT_FLAG_RX_PAGE_MODE;
Michael Chanc61fb992017-02-06 16:55:36 -05002887 bp->rx_dir = DMA_BIDIRECTIONAL;
2888 bp->rx_skb_func = bnxt_rx_page_skb;
Michael Chan1054aee2017-12-16 03:09:42 -05002889 /* Disable LRO or GRO_HW */
2890 netdev_update_features(bp->dev);
Michael Chanc61fb992017-02-06 16:55:36 -05002891 } else {
Michael Chan7eb9bb32017-10-26 11:51:25 -04002892 bp->dev->max_mtu = bp->max_mtu;
Michael Chanc61fb992017-02-06 16:55:36 -05002893 bp->flags &= ~BNXT_FLAG_RX_PAGE_MODE;
2894 bp->rx_dir = DMA_FROM_DEVICE;
2895 bp->rx_skb_func = bnxt_rx_skb;
2896 }
Michael Chan6bb19472017-02-06 16:55:32 -05002897 return 0;
2898}
2899
Michael Chanc0c050c2015-10-22 16:01:17 -04002900static void bnxt_free_vnic_attributes(struct bnxt *bp)
2901{
2902 int i;
2903 struct bnxt_vnic_info *vnic;
2904 struct pci_dev *pdev = bp->pdev;
2905
2906 if (!bp->vnic_info)
2907 return;
2908
2909 for (i = 0; i < bp->nr_vnics; i++) {
2910 vnic = &bp->vnic_info[i];
2911
2912 kfree(vnic->fw_grp_ids);
2913 vnic->fw_grp_ids = NULL;
2914
2915 kfree(vnic->uc_list);
2916 vnic->uc_list = NULL;
2917
2918 if (vnic->mc_list) {
2919 dma_free_coherent(&pdev->dev, vnic->mc_list_size,
2920 vnic->mc_list, vnic->mc_list_mapping);
2921 vnic->mc_list = NULL;
2922 }
2923
2924 if (vnic->rss_table) {
2925 dma_free_coherent(&pdev->dev, PAGE_SIZE,
2926 vnic->rss_table,
2927 vnic->rss_table_dma_addr);
2928 vnic->rss_table = NULL;
2929 }
2930
2931 vnic->rss_hash_key = NULL;
2932 vnic->flags = 0;
2933 }
2934}
2935
2936static int bnxt_alloc_vnic_attributes(struct bnxt *bp)
2937{
2938 int i, rc = 0, size;
2939 struct bnxt_vnic_info *vnic;
2940 struct pci_dev *pdev = bp->pdev;
2941 int max_rings;
2942
2943 for (i = 0; i < bp->nr_vnics; i++) {
2944 vnic = &bp->vnic_info[i];
2945
2946 if (vnic->flags & BNXT_VNIC_UCAST_FLAG) {
2947 int mem_size = (BNXT_MAX_UC_ADDRS - 1) * ETH_ALEN;
2948
2949 if (mem_size > 0) {
2950 vnic->uc_list = kmalloc(mem_size, GFP_KERNEL);
2951 if (!vnic->uc_list) {
2952 rc = -ENOMEM;
2953 goto out;
2954 }
2955 }
2956 }
2957
2958 if (vnic->flags & BNXT_VNIC_MCAST_FLAG) {
2959 vnic->mc_list_size = BNXT_MAX_MC_ADDRS * ETH_ALEN;
2960 vnic->mc_list =
2961 dma_alloc_coherent(&pdev->dev,
2962 vnic->mc_list_size,
2963 &vnic->mc_list_mapping,
2964 GFP_KERNEL);
2965 if (!vnic->mc_list) {
2966 rc = -ENOMEM;
2967 goto out;
2968 }
2969 }
2970
2971 if (vnic->flags & BNXT_VNIC_RSS_FLAG)
2972 max_rings = bp->rx_nr_rings;
2973 else
2974 max_rings = 1;
2975
2976 vnic->fw_grp_ids = kcalloc(max_rings, sizeof(u16), GFP_KERNEL);
2977 if (!vnic->fw_grp_ids) {
2978 rc = -ENOMEM;
2979 goto out;
2980 }
2981
Michael Chanae10ae72016-12-29 12:13:38 -05002982 if ((bp->flags & BNXT_FLAG_NEW_RSS_CAP) &&
2983 !(vnic->flags & BNXT_VNIC_RSS_FLAG))
2984 continue;
2985
Michael Chanc0c050c2015-10-22 16:01:17 -04002986 /* Allocate rss table and hash key */
2987 vnic->rss_table = dma_alloc_coherent(&pdev->dev, PAGE_SIZE,
2988 &vnic->rss_table_dma_addr,
2989 GFP_KERNEL);
2990 if (!vnic->rss_table) {
2991 rc = -ENOMEM;
2992 goto out;
2993 }
2994
2995 size = L1_CACHE_ALIGN(HW_HASH_INDEX_SIZE * sizeof(u16));
2996
2997 vnic->rss_hash_key = ((void *)vnic->rss_table) + size;
2998 vnic->rss_hash_key_dma_addr = vnic->rss_table_dma_addr + size;
2999 }
3000 return 0;
3001
3002out:
3003 return rc;
3004}
3005
3006static void bnxt_free_hwrm_resources(struct bnxt *bp)
3007{
3008 struct pci_dev *pdev = bp->pdev;
3009
3010 dma_free_coherent(&pdev->dev, PAGE_SIZE, bp->hwrm_cmd_resp_addr,
3011 bp->hwrm_cmd_resp_dma_addr);
3012
3013 bp->hwrm_cmd_resp_addr = NULL;
3014 if (bp->hwrm_dbg_resp_addr) {
3015 dma_free_coherent(&pdev->dev, HWRM_DBG_REG_BUF_SIZE,
3016 bp->hwrm_dbg_resp_addr,
3017 bp->hwrm_dbg_resp_dma_addr);
3018
3019 bp->hwrm_dbg_resp_addr = NULL;
3020 }
3021}
3022
3023static int bnxt_alloc_hwrm_resources(struct bnxt *bp)
3024{
3025 struct pci_dev *pdev = bp->pdev;
3026
3027 bp->hwrm_cmd_resp_addr = dma_alloc_coherent(&pdev->dev, PAGE_SIZE,
3028 &bp->hwrm_cmd_resp_dma_addr,
3029 GFP_KERNEL);
3030 if (!bp->hwrm_cmd_resp_addr)
3031 return -ENOMEM;
3032 bp->hwrm_dbg_resp_addr = dma_alloc_coherent(&pdev->dev,
3033 HWRM_DBG_REG_BUF_SIZE,
3034 &bp->hwrm_dbg_resp_dma_addr,
3035 GFP_KERNEL);
3036 if (!bp->hwrm_dbg_resp_addr)
3037 netdev_warn(bp->dev, "fail to alloc debug register dma mem\n");
3038
3039 return 0;
3040}
3041
Deepak Khungare605db82017-05-29 19:06:04 -04003042static void bnxt_free_hwrm_short_cmd_req(struct bnxt *bp)
3043{
3044 if (bp->hwrm_short_cmd_req_addr) {
3045 struct pci_dev *pdev = bp->pdev;
3046
3047 dma_free_coherent(&pdev->dev, BNXT_HWRM_MAX_REQ_LEN,
3048 bp->hwrm_short_cmd_req_addr,
3049 bp->hwrm_short_cmd_req_dma_addr);
3050 bp->hwrm_short_cmd_req_addr = NULL;
3051 }
3052}
3053
3054static int bnxt_alloc_hwrm_short_cmd_req(struct bnxt *bp)
3055{
3056 struct pci_dev *pdev = bp->pdev;
3057
3058 bp->hwrm_short_cmd_req_addr =
3059 dma_alloc_coherent(&pdev->dev, BNXT_HWRM_MAX_REQ_LEN,
3060 &bp->hwrm_short_cmd_req_dma_addr,
3061 GFP_KERNEL);
3062 if (!bp->hwrm_short_cmd_req_addr)
3063 return -ENOMEM;
3064
3065 return 0;
3066}
3067
Michael Chanc0c050c2015-10-22 16:01:17 -04003068static void bnxt_free_stats(struct bnxt *bp)
3069{
3070 u32 size, i;
3071 struct pci_dev *pdev = bp->pdev;
3072
Vasundhara Volam00db3cb2018-03-31 13:54:12 -04003073 bp->flags &= ~BNXT_FLAG_PORT_STATS;
3074 bp->flags &= ~BNXT_FLAG_PORT_STATS_EXT;
3075
Michael Chan3bdf56c2016-03-07 15:38:45 -05003076 if (bp->hw_rx_port_stats) {
3077 dma_free_coherent(&pdev->dev, bp->hw_port_stats_size,
3078 bp->hw_rx_port_stats,
3079 bp->hw_rx_port_stats_map);
3080 bp->hw_rx_port_stats = NULL;
Vasundhara Volam00db3cb2018-03-31 13:54:12 -04003081 }
3082
3083 if (bp->hw_rx_port_stats_ext) {
3084 dma_free_coherent(&pdev->dev, sizeof(struct rx_port_stats_ext),
3085 bp->hw_rx_port_stats_ext,
3086 bp->hw_rx_port_stats_ext_map);
3087 bp->hw_rx_port_stats_ext = NULL;
Michael Chan3bdf56c2016-03-07 15:38:45 -05003088 }
3089
Michael Chanc0c050c2015-10-22 16:01:17 -04003090 if (!bp->bnapi)
3091 return;
3092
3093 size = sizeof(struct ctx_hw_stats);
3094
3095 for (i = 0; i < bp->cp_nr_rings; i++) {
3096 struct bnxt_napi *bnapi = bp->bnapi[i];
3097 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
3098
3099 if (cpr->hw_stats) {
3100 dma_free_coherent(&pdev->dev, size, cpr->hw_stats,
3101 cpr->hw_stats_map);
3102 cpr->hw_stats = NULL;
3103 }
3104 }
3105}
3106
3107static int bnxt_alloc_stats(struct bnxt *bp)
3108{
3109 u32 size, i;
3110 struct pci_dev *pdev = bp->pdev;
3111
3112 size = sizeof(struct ctx_hw_stats);
3113
3114 for (i = 0; i < bp->cp_nr_rings; i++) {
3115 struct bnxt_napi *bnapi = bp->bnapi[i];
3116 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
3117
3118 cpr->hw_stats = dma_alloc_coherent(&pdev->dev, size,
3119 &cpr->hw_stats_map,
3120 GFP_KERNEL);
3121 if (!cpr->hw_stats)
3122 return -ENOMEM;
3123
3124 cpr->hw_stats_ctx_id = INVALID_STATS_CTX_ID;
3125 }
Michael Chan3bdf56c2016-03-07 15:38:45 -05003126
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04003127 if (BNXT_PF(bp) && bp->chip_num != CHIP_NUM_58700) {
Michael Chan3bdf56c2016-03-07 15:38:45 -05003128 bp->hw_port_stats_size = sizeof(struct rx_port_stats) +
3129 sizeof(struct tx_port_stats) + 1024;
3130
3131 bp->hw_rx_port_stats =
3132 dma_alloc_coherent(&pdev->dev, bp->hw_port_stats_size,
3133 &bp->hw_rx_port_stats_map,
3134 GFP_KERNEL);
3135 if (!bp->hw_rx_port_stats)
3136 return -ENOMEM;
3137
3138 bp->hw_tx_port_stats = (void *)(bp->hw_rx_port_stats + 1) +
3139 512;
3140 bp->hw_tx_port_stats_map = bp->hw_rx_port_stats_map +
3141 sizeof(struct rx_port_stats) + 512;
3142 bp->flags |= BNXT_FLAG_PORT_STATS;
Vasundhara Volam00db3cb2018-03-31 13:54:12 -04003143
3144 /* Display extended statistics only if FW supports it */
3145 if (bp->hwrm_spec_code < 0x10804 ||
3146 bp->hwrm_spec_code == 0x10900)
3147 return 0;
3148
3149 bp->hw_rx_port_stats_ext =
3150 dma_zalloc_coherent(&pdev->dev,
3151 sizeof(struct rx_port_stats_ext),
3152 &bp->hw_rx_port_stats_ext_map,
3153 GFP_KERNEL);
3154 if (!bp->hw_rx_port_stats_ext)
3155 return 0;
3156
3157 bp->flags |= BNXT_FLAG_PORT_STATS_EXT;
Michael Chan3bdf56c2016-03-07 15:38:45 -05003158 }
Michael Chanc0c050c2015-10-22 16:01:17 -04003159 return 0;
3160}
3161
3162static void bnxt_clear_ring_indices(struct bnxt *bp)
3163{
3164 int i;
3165
3166 if (!bp->bnapi)
3167 return;
3168
3169 for (i = 0; i < bp->cp_nr_rings; i++) {
3170 struct bnxt_napi *bnapi = bp->bnapi[i];
3171 struct bnxt_cp_ring_info *cpr;
3172 struct bnxt_rx_ring_info *rxr;
3173 struct bnxt_tx_ring_info *txr;
3174
3175 if (!bnapi)
3176 continue;
3177
3178 cpr = &bnapi->cp_ring;
3179 cpr->cp_raw_cons = 0;
3180
Michael Chanb6ab4b02016-01-02 23:44:59 -05003181 txr = bnapi->tx_ring;
Michael Chan3b2b7d92016-01-02 23:45:00 -05003182 if (txr) {
3183 txr->tx_prod = 0;
3184 txr->tx_cons = 0;
3185 }
Michael Chanc0c050c2015-10-22 16:01:17 -04003186
Michael Chanb6ab4b02016-01-02 23:44:59 -05003187 rxr = bnapi->rx_ring;
Michael Chan3b2b7d92016-01-02 23:45:00 -05003188 if (rxr) {
3189 rxr->rx_prod = 0;
3190 rxr->rx_agg_prod = 0;
3191 rxr->rx_sw_agg_prod = 0;
Michael Chan376a5b82016-05-10 19:17:59 -04003192 rxr->rx_next_cons = 0;
Michael Chan3b2b7d92016-01-02 23:45:00 -05003193 }
Michael Chanc0c050c2015-10-22 16:01:17 -04003194 }
3195}
3196
3197static void bnxt_free_ntp_fltrs(struct bnxt *bp, bool irq_reinit)
3198{
3199#ifdef CONFIG_RFS_ACCEL
3200 int i;
3201
3202 /* Under rtnl_lock and all our NAPIs have been disabled. It's
3203 * safe to delete the hash table.
3204 */
3205 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
3206 struct hlist_head *head;
3207 struct hlist_node *tmp;
3208 struct bnxt_ntuple_filter *fltr;
3209
3210 head = &bp->ntp_fltr_hash_tbl[i];
3211 hlist_for_each_entry_safe(fltr, tmp, head, hash) {
3212 hlist_del(&fltr->hash);
3213 kfree(fltr);
3214 }
3215 }
3216 if (irq_reinit) {
3217 kfree(bp->ntp_fltr_bmap);
3218 bp->ntp_fltr_bmap = NULL;
3219 }
3220 bp->ntp_fltr_count = 0;
3221#endif
3222}
3223
3224static int bnxt_alloc_ntp_fltrs(struct bnxt *bp)
3225{
3226#ifdef CONFIG_RFS_ACCEL
3227 int i, rc = 0;
3228
3229 if (!(bp->flags & BNXT_FLAG_RFS))
3230 return 0;
3231
3232 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++)
3233 INIT_HLIST_HEAD(&bp->ntp_fltr_hash_tbl[i]);
3234
3235 bp->ntp_fltr_count = 0;
Dan Carpenterac45bd92017-05-06 03:49:01 +03003236 bp->ntp_fltr_bmap = kcalloc(BITS_TO_LONGS(BNXT_NTP_FLTR_MAX_FLTR),
3237 sizeof(long),
Michael Chanc0c050c2015-10-22 16:01:17 -04003238 GFP_KERNEL);
3239
3240 if (!bp->ntp_fltr_bmap)
3241 rc = -ENOMEM;
3242
3243 return rc;
3244#else
3245 return 0;
3246#endif
3247}
3248
3249static void bnxt_free_mem(struct bnxt *bp, bool irq_re_init)
3250{
3251 bnxt_free_vnic_attributes(bp);
3252 bnxt_free_tx_rings(bp);
3253 bnxt_free_rx_rings(bp);
3254 bnxt_free_cp_rings(bp);
3255 bnxt_free_ntp_fltrs(bp, irq_re_init);
3256 if (irq_re_init) {
3257 bnxt_free_stats(bp);
3258 bnxt_free_ring_grps(bp);
3259 bnxt_free_vnics(bp);
Michael Chana960dec2017-02-06 16:55:39 -05003260 kfree(bp->tx_ring_map);
3261 bp->tx_ring_map = NULL;
Michael Chanb6ab4b02016-01-02 23:44:59 -05003262 kfree(bp->tx_ring);
3263 bp->tx_ring = NULL;
3264 kfree(bp->rx_ring);
3265 bp->rx_ring = NULL;
Michael Chanc0c050c2015-10-22 16:01:17 -04003266 kfree(bp->bnapi);
3267 bp->bnapi = NULL;
3268 } else {
3269 bnxt_clear_ring_indices(bp);
3270 }
3271}
3272
3273static int bnxt_alloc_mem(struct bnxt *bp, bool irq_re_init)
3274{
Michael Chan01657bc2016-01-02 23:45:03 -05003275 int i, j, rc, size, arr_size;
Michael Chanc0c050c2015-10-22 16:01:17 -04003276 void *bnapi;
3277
3278 if (irq_re_init) {
3279 /* Allocate bnapi mem pointer array and mem block for
3280 * all queues
3281 */
3282 arr_size = L1_CACHE_ALIGN(sizeof(struct bnxt_napi *) *
3283 bp->cp_nr_rings);
3284 size = L1_CACHE_ALIGN(sizeof(struct bnxt_napi));
3285 bnapi = kzalloc(arr_size + size * bp->cp_nr_rings, GFP_KERNEL);
3286 if (!bnapi)
3287 return -ENOMEM;
3288
3289 bp->bnapi = bnapi;
3290 bnapi += arr_size;
3291 for (i = 0; i < bp->cp_nr_rings; i++, bnapi += size) {
3292 bp->bnapi[i] = bnapi;
3293 bp->bnapi[i]->index = i;
3294 bp->bnapi[i]->bp = bp;
3295 }
3296
Michael Chanb6ab4b02016-01-02 23:44:59 -05003297 bp->rx_ring = kcalloc(bp->rx_nr_rings,
3298 sizeof(struct bnxt_rx_ring_info),
3299 GFP_KERNEL);
3300 if (!bp->rx_ring)
3301 return -ENOMEM;
3302
3303 for (i = 0; i < bp->rx_nr_rings; i++) {
3304 bp->rx_ring[i].bnapi = bp->bnapi[i];
3305 bp->bnapi[i]->rx_ring = &bp->rx_ring[i];
3306 }
3307
3308 bp->tx_ring = kcalloc(bp->tx_nr_rings,
3309 sizeof(struct bnxt_tx_ring_info),
3310 GFP_KERNEL);
3311 if (!bp->tx_ring)
3312 return -ENOMEM;
3313
Michael Chana960dec2017-02-06 16:55:39 -05003314 bp->tx_ring_map = kcalloc(bp->tx_nr_rings, sizeof(u16),
3315 GFP_KERNEL);
3316
3317 if (!bp->tx_ring_map)
3318 return -ENOMEM;
3319
Michael Chan01657bc2016-01-02 23:45:03 -05003320 if (bp->flags & BNXT_FLAG_SHARED_RINGS)
3321 j = 0;
3322 else
3323 j = bp->rx_nr_rings;
3324
3325 for (i = 0; i < bp->tx_nr_rings; i++, j++) {
3326 bp->tx_ring[i].bnapi = bp->bnapi[j];
3327 bp->bnapi[j]->tx_ring = &bp->tx_ring[i];
Michael Chan5f449242017-02-06 16:55:40 -05003328 bp->tx_ring_map[i] = bp->tx_nr_rings_xdp + i;
Michael Chan38413402017-02-06 16:55:43 -05003329 if (i >= bp->tx_nr_rings_xdp) {
Michael Chan5f449242017-02-06 16:55:40 -05003330 bp->tx_ring[i].txq_index = i -
3331 bp->tx_nr_rings_xdp;
Michael Chan38413402017-02-06 16:55:43 -05003332 bp->bnapi[j]->tx_int = bnxt_tx_int;
3333 } else {
Michael Chanfa3e93e2017-02-06 16:55:41 -05003334 bp->bnapi[j]->flags |= BNXT_NAPI_FLAG_XDP;
Michael Chan38413402017-02-06 16:55:43 -05003335 bp->bnapi[j]->tx_int = bnxt_tx_int_xdp;
3336 }
Michael Chanb6ab4b02016-01-02 23:44:59 -05003337 }
3338
Michael Chanc0c050c2015-10-22 16:01:17 -04003339 rc = bnxt_alloc_stats(bp);
3340 if (rc)
3341 goto alloc_mem_err;
3342
3343 rc = bnxt_alloc_ntp_fltrs(bp);
3344 if (rc)
3345 goto alloc_mem_err;
3346
3347 rc = bnxt_alloc_vnics(bp);
3348 if (rc)
3349 goto alloc_mem_err;
3350 }
3351
3352 bnxt_init_ring_struct(bp);
3353
3354 rc = bnxt_alloc_rx_rings(bp);
3355 if (rc)
3356 goto alloc_mem_err;
3357
3358 rc = bnxt_alloc_tx_rings(bp);
3359 if (rc)
3360 goto alloc_mem_err;
3361
3362 rc = bnxt_alloc_cp_rings(bp);
3363 if (rc)
3364 goto alloc_mem_err;
3365
3366 bp->vnic_info[0].flags |= BNXT_VNIC_RSS_FLAG | BNXT_VNIC_MCAST_FLAG |
3367 BNXT_VNIC_UCAST_FLAG;
3368 rc = bnxt_alloc_vnic_attributes(bp);
3369 if (rc)
3370 goto alloc_mem_err;
3371 return 0;
3372
3373alloc_mem_err:
3374 bnxt_free_mem(bp, true);
3375 return rc;
3376}
3377
Michael Chan9d8bc092016-12-29 12:13:33 -05003378static void bnxt_disable_int(struct bnxt *bp)
3379{
3380 int i;
3381
3382 if (!bp->bnapi)
3383 return;
3384
3385 for (i = 0; i < bp->cp_nr_rings; i++) {
3386 struct bnxt_napi *bnapi = bp->bnapi[i];
3387 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
Michael Chandaf1f1e2017-02-20 19:25:17 -05003388 struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
Michael Chan9d8bc092016-12-29 12:13:33 -05003389
Michael Chandaf1f1e2017-02-20 19:25:17 -05003390 if (ring->fw_ring_id != INVALID_HW_RING_ID)
3391 BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
Michael Chan9d8bc092016-12-29 12:13:33 -05003392 }
3393}
3394
Michael Chane5811b82018-03-31 13:54:18 -04003395static int bnxt_cp_num_to_irq_num(struct bnxt *bp, int n)
3396{
3397 struct bnxt_napi *bnapi = bp->bnapi[n];
3398 struct bnxt_cp_ring_info *cpr;
3399
3400 cpr = &bnapi->cp_ring;
3401 return cpr->cp_ring_struct.map_idx;
3402}
3403
Michael Chan9d8bc092016-12-29 12:13:33 -05003404static void bnxt_disable_int_sync(struct bnxt *bp)
3405{
3406 int i;
3407
3408 atomic_inc(&bp->intr_sem);
3409
3410 bnxt_disable_int(bp);
Michael Chane5811b82018-03-31 13:54:18 -04003411 for (i = 0; i < bp->cp_nr_rings; i++) {
3412 int map_idx = bnxt_cp_num_to_irq_num(bp, i);
3413
3414 synchronize_irq(bp->irq_tbl[map_idx].vector);
3415 }
Michael Chan9d8bc092016-12-29 12:13:33 -05003416}
3417
3418static void bnxt_enable_int(struct bnxt *bp)
3419{
3420 int i;
3421
3422 atomic_set(&bp->intr_sem, 0);
3423 for (i = 0; i < bp->cp_nr_rings; i++) {
3424 struct bnxt_napi *bnapi = bp->bnapi[i];
3425 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
3426
3427 BNXT_CP_DB_REARM(cpr->cp_doorbell, cpr->cp_raw_cons);
3428 }
3429}
3430
Michael Chanc0c050c2015-10-22 16:01:17 -04003431void bnxt_hwrm_cmd_hdr_init(struct bnxt *bp, void *request, u16 req_type,
3432 u16 cmpl_ring, u16 target_id)
3433{
Michael Chana8643e12016-02-26 04:00:05 -05003434 struct input *req = request;
Michael Chanc0c050c2015-10-22 16:01:17 -04003435
Michael Chana8643e12016-02-26 04:00:05 -05003436 req->req_type = cpu_to_le16(req_type);
3437 req->cmpl_ring = cpu_to_le16(cmpl_ring);
3438 req->target_id = cpu_to_le16(target_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04003439 req->resp_addr = cpu_to_le64(bp->hwrm_cmd_resp_dma_addr);
3440}
3441
Michael Chanfbfbc482016-02-26 04:00:07 -05003442static int bnxt_hwrm_do_send_msg(struct bnxt *bp, void *msg, u32 msg_len,
3443 int timeout, bool silent)
Michael Chanc0c050c2015-10-22 16:01:17 -04003444{
Michael Chana11fa2b2016-05-15 03:04:47 -04003445 int i, intr_process, rc, tmo_count;
Michael Chana8643e12016-02-26 04:00:05 -05003446 struct input *req = msg;
Michael Chanc0c050c2015-10-22 16:01:17 -04003447 u32 *data = msg;
Michael Chan845adfe2018-03-31 13:54:15 -04003448 __le32 *resp_len;
3449 u8 *valid;
Michael Chanc0c050c2015-10-22 16:01:17 -04003450 u16 cp_ring_id, len = 0;
3451 struct hwrm_err_output *resp = bp->hwrm_cmd_resp_addr;
Deepak Khungare605db82017-05-29 19:06:04 -04003452 u16 max_req_len = BNXT_HWRM_MAX_REQ_LEN;
Vasundhara Volamebd58182017-12-01 03:13:05 -05003453 struct hwrm_short_input short_input = {0};
Michael Chanc0c050c2015-10-22 16:01:17 -04003454
Michael Chana8643e12016-02-26 04:00:05 -05003455 req->seq_id = cpu_to_le16(bp->hwrm_cmd_seq++);
Michael Chanc0c050c2015-10-22 16:01:17 -04003456 memset(resp, 0, PAGE_SIZE);
Michael Chana8643e12016-02-26 04:00:05 -05003457 cp_ring_id = le16_to_cpu(req->cmpl_ring);
Michael Chanc0c050c2015-10-22 16:01:17 -04003458 intr_process = (cp_ring_id == INVALID_HW_RING_ID) ? 0 : 1;
3459
Deepak Khungare605db82017-05-29 19:06:04 -04003460 if (bp->flags & BNXT_FLAG_SHORT_CMD) {
3461 void *short_cmd_req = bp->hwrm_short_cmd_req_addr;
Deepak Khungare605db82017-05-29 19:06:04 -04003462
3463 memcpy(short_cmd_req, req, msg_len);
3464 memset(short_cmd_req + msg_len, 0, BNXT_HWRM_MAX_REQ_LEN -
3465 msg_len);
3466
3467 short_input.req_type = req->req_type;
3468 short_input.signature =
3469 cpu_to_le16(SHORT_REQ_SIGNATURE_SHORT_CMD);
3470 short_input.size = cpu_to_le16(msg_len);
3471 short_input.req_addr =
3472 cpu_to_le64(bp->hwrm_short_cmd_req_dma_addr);
3473
3474 data = (u32 *)&short_input;
3475 msg_len = sizeof(short_input);
3476
3477 /* Sync memory write before updating doorbell */
3478 wmb();
3479
3480 max_req_len = BNXT_HWRM_SHORT_REQ_LEN;
3481 }
3482
Michael Chanc0c050c2015-10-22 16:01:17 -04003483 /* Write request msg to hwrm channel */
3484 __iowrite32_copy(bp->bar0, data, msg_len / 4);
3485
Deepak Khungare605db82017-05-29 19:06:04 -04003486 for (i = msg_len; i < max_req_len; i += 4)
Michael Chand79979a2016-01-07 19:56:57 -05003487 writel(0, bp->bar0 + i);
3488
Michael Chanc0c050c2015-10-22 16:01:17 -04003489 /* currently supports only one outstanding message */
3490 if (intr_process)
Michael Chana8643e12016-02-26 04:00:05 -05003491 bp->hwrm_intr_seq_id = le16_to_cpu(req->seq_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04003492
3493 /* Ring channel doorbell */
3494 writel(1, bp->bar0 + 0x100);
3495
Michael Chanff4fe812016-02-26 04:00:04 -05003496 if (!timeout)
3497 timeout = DFLT_HWRM_CMD_TIMEOUT;
3498
Michael Chanc0c050c2015-10-22 16:01:17 -04003499 i = 0;
Michael Chana11fa2b2016-05-15 03:04:47 -04003500 tmo_count = timeout * 40;
Michael Chan845adfe2018-03-31 13:54:15 -04003501 resp_len = bp->hwrm_cmd_resp_addr + HWRM_RESP_LEN_OFFSET;
Michael Chanc0c050c2015-10-22 16:01:17 -04003502 if (intr_process) {
3503 /* Wait until hwrm response cmpl interrupt is processed */
3504 while (bp->hwrm_intr_seq_id != HWRM_SEQ_ID_INVALID &&
Michael Chana11fa2b2016-05-15 03:04:47 -04003505 i++ < tmo_count) {
3506 usleep_range(25, 40);
Michael Chanc0c050c2015-10-22 16:01:17 -04003507 }
3508
3509 if (bp->hwrm_intr_seq_id != HWRM_SEQ_ID_INVALID) {
3510 netdev_err(bp->dev, "Resp cmpl intr err msg: 0x%x\n",
Michael Chana8643e12016-02-26 04:00:05 -05003511 le16_to_cpu(req->req_type));
Michael Chanc0c050c2015-10-22 16:01:17 -04003512 return -1;
3513 }
Michael Chan845adfe2018-03-31 13:54:15 -04003514 len = (le32_to_cpu(*resp_len) & HWRM_RESP_LEN_MASK) >>
3515 HWRM_RESP_LEN_SFT;
3516 valid = bp->hwrm_cmd_resp_addr + len - 1;
Michael Chanc0c050c2015-10-22 16:01:17 -04003517 } else {
3518 /* Check if response len is updated */
Michael Chana11fa2b2016-05-15 03:04:47 -04003519 for (i = 0; i < tmo_count; i++) {
Michael Chanc0c050c2015-10-22 16:01:17 -04003520 len = (le32_to_cpu(*resp_len) & HWRM_RESP_LEN_MASK) >>
3521 HWRM_RESP_LEN_SFT;
3522 if (len)
3523 break;
Michael Chana11fa2b2016-05-15 03:04:47 -04003524 usleep_range(25, 40);
Michael Chanc0c050c2015-10-22 16:01:17 -04003525 }
3526
Michael Chana11fa2b2016-05-15 03:04:47 -04003527 if (i >= tmo_count) {
Michael Chanc0c050c2015-10-22 16:01:17 -04003528 netdev_err(bp->dev, "Error (timeout: %d) msg {0x%x 0x%x} len:%d\n",
Michael Chana8643e12016-02-26 04:00:05 -05003529 timeout, le16_to_cpu(req->req_type),
Michael Chan8578d6c2016-05-15 03:04:48 -04003530 le16_to_cpu(req->seq_id), len);
Michael Chanc0c050c2015-10-22 16:01:17 -04003531 return -1;
3532 }
3533
Michael Chan845adfe2018-03-31 13:54:15 -04003534 /* Last byte of resp contains valid bit */
3535 valid = bp->hwrm_cmd_resp_addr + len - 1;
Michael Chana11fa2b2016-05-15 03:04:47 -04003536 for (i = 0; i < 5; i++) {
Michael Chan845adfe2018-03-31 13:54:15 -04003537 /* make sure we read from updated DMA memory */
3538 dma_rmb();
3539 if (*valid)
Michael Chanc0c050c2015-10-22 16:01:17 -04003540 break;
Michael Chana11fa2b2016-05-15 03:04:47 -04003541 udelay(1);
Michael Chanc0c050c2015-10-22 16:01:17 -04003542 }
3543
Michael Chana11fa2b2016-05-15 03:04:47 -04003544 if (i >= 5) {
Michael Chanc0c050c2015-10-22 16:01:17 -04003545 netdev_err(bp->dev, "Error (timeout: %d) msg {0x%x 0x%x} len:%d v:%d\n",
Michael Chana8643e12016-02-26 04:00:05 -05003546 timeout, le16_to_cpu(req->req_type),
3547 le16_to_cpu(req->seq_id), len, *valid);
Michael Chanc0c050c2015-10-22 16:01:17 -04003548 return -1;
3549 }
3550 }
3551
Michael Chan845adfe2018-03-31 13:54:15 -04003552 /* Zero valid bit for compatibility. Valid bit in an older spec
3553 * may become a new field in a newer spec. We must make sure that
3554 * a new field not implemented by old spec will read zero.
3555 */
3556 *valid = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04003557 rc = le16_to_cpu(resp->error_code);
Michael Chanfbfbc482016-02-26 04:00:07 -05003558 if (rc && !silent)
Michael Chanc0c050c2015-10-22 16:01:17 -04003559 netdev_err(bp->dev, "hwrm req_type 0x%x seq id 0x%x error 0x%x\n",
3560 le16_to_cpu(resp->req_type),
3561 le16_to_cpu(resp->seq_id), rc);
Michael Chanfbfbc482016-02-26 04:00:07 -05003562 return rc;
3563}
3564
3565int _hwrm_send_message(struct bnxt *bp, void *msg, u32 msg_len, int timeout)
3566{
3567 return bnxt_hwrm_do_send_msg(bp, msg, msg_len, timeout, false);
Michael Chanc0c050c2015-10-22 16:01:17 -04003568}
3569
Michael Chancc72f3b2017-10-13 21:09:33 -04003570int _hwrm_send_message_silent(struct bnxt *bp, void *msg, u32 msg_len,
3571 int timeout)
3572{
3573 return bnxt_hwrm_do_send_msg(bp, msg, msg_len, timeout, true);
3574}
3575
Michael Chanc0c050c2015-10-22 16:01:17 -04003576int hwrm_send_message(struct bnxt *bp, void *msg, u32 msg_len, int timeout)
3577{
3578 int rc;
3579
3580 mutex_lock(&bp->hwrm_cmd_lock);
3581 rc = _hwrm_send_message(bp, msg, msg_len, timeout);
3582 mutex_unlock(&bp->hwrm_cmd_lock);
3583 return rc;
3584}
3585
Michael Chan90e209212016-02-26 04:00:08 -05003586int hwrm_send_message_silent(struct bnxt *bp, void *msg, u32 msg_len,
3587 int timeout)
3588{
3589 int rc;
3590
3591 mutex_lock(&bp->hwrm_cmd_lock);
3592 rc = bnxt_hwrm_do_send_msg(bp, msg, msg_len, timeout, true);
3593 mutex_unlock(&bp->hwrm_cmd_lock);
3594 return rc;
3595}
3596
Michael Chana1653b12016-12-07 00:26:20 -05003597int bnxt_hwrm_func_rgtr_async_events(struct bnxt *bp, unsigned long *bmap,
3598 int bmap_size)
Michael Chanc0c050c2015-10-22 16:01:17 -04003599{
3600 struct hwrm_func_drv_rgtr_input req = {0};
Michael Chan25be8622016-04-05 14:09:00 -04003601 DECLARE_BITMAP(async_events_bmap, 256);
3602 u32 *events = (u32 *)async_events_bmap;
Michael Chana1653b12016-12-07 00:26:20 -05003603 int i;
Michael Chanc0c050c2015-10-22 16:01:17 -04003604
3605 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_RGTR, -1, -1);
3606
3607 req.enables =
Michael Chana1653b12016-12-07 00:26:20 -05003608 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_ASYNC_EVENT_FWD);
Michael Chanc0c050c2015-10-22 16:01:17 -04003609
Michael Chan25be8622016-04-05 14:09:00 -04003610 memset(async_events_bmap, 0, sizeof(async_events_bmap));
3611 for (i = 0; i < ARRAY_SIZE(bnxt_async_events_arr); i++)
3612 __set_bit(bnxt_async_events_arr[i], async_events_bmap);
3613
Michael Chana1653b12016-12-07 00:26:20 -05003614 if (bmap && bmap_size) {
3615 for (i = 0; i < bmap_size; i++) {
3616 if (test_bit(i, bmap))
3617 __set_bit(i, async_events_bmap);
3618 }
3619 }
3620
Michael Chan25be8622016-04-05 14:09:00 -04003621 for (i = 0; i < 8; i++)
3622 req.async_event_fwd[i] |= cpu_to_le32(events[i]);
3623
Michael Chana1653b12016-12-07 00:26:20 -05003624 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3625}
3626
3627static int bnxt_hwrm_func_drv_rgtr(struct bnxt *bp)
3628{
3629 struct hwrm_func_drv_rgtr_input req = {0};
3630
3631 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_RGTR, -1, -1);
3632
3633 req.enables =
3634 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_OS_TYPE |
3635 FUNC_DRV_RGTR_REQ_ENABLES_VER);
3636
Michael Chan11f15ed2016-04-05 14:08:55 -04003637 req.os_type = cpu_to_le16(FUNC_DRV_RGTR_REQ_OS_TYPE_LINUX);
Michael Chand4f52de02018-03-31 13:54:06 -04003638 req.flags = cpu_to_le32(FUNC_DRV_RGTR_REQ_FLAGS_16BIT_VER_MODE);
3639 req.ver_maj_8b = DRV_VER_MAJ;
3640 req.ver_min_8b = DRV_VER_MIN;
3641 req.ver_upd_8b = DRV_VER_UPD;
3642 req.ver_maj = cpu_to_le16(DRV_VER_MAJ);
3643 req.ver_min = cpu_to_le16(DRV_VER_MIN);
3644 req.ver_upd = cpu_to_le16(DRV_VER_UPD);
Michael Chanc0c050c2015-10-22 16:01:17 -04003645
3646 if (BNXT_PF(bp)) {
Michael Chan9b0436c2017-07-11 13:05:36 -04003647 u32 data[8];
Michael Chana1653b12016-12-07 00:26:20 -05003648 int i;
Michael Chanc0c050c2015-10-22 16:01:17 -04003649
Michael Chan9b0436c2017-07-11 13:05:36 -04003650 memset(data, 0, sizeof(data));
3651 for (i = 0; i < ARRAY_SIZE(bnxt_vf_req_snif); i++) {
3652 u16 cmd = bnxt_vf_req_snif[i];
3653 unsigned int bit, idx;
3654
3655 idx = cmd / 32;
3656 bit = cmd % 32;
3657 data[idx] |= 1 << bit;
3658 }
Michael Chanc0c050c2015-10-22 16:01:17 -04003659
Michael Chande68f5de2015-12-09 19:35:41 -05003660 for (i = 0; i < 8; i++)
3661 req.vf_req_fwd[i] = cpu_to_le32(data[i]);
3662
Michael Chanc0c050c2015-10-22 16:01:17 -04003663 req.enables |=
3664 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_VF_REQ_FWD);
3665 }
3666
3667 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3668}
3669
Jeffrey Huangbe58a0d2015-12-27 18:19:18 -05003670static int bnxt_hwrm_func_drv_unrgtr(struct bnxt *bp)
3671{
3672 struct hwrm_func_drv_unrgtr_input req = {0};
3673
3674 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_UNRGTR, -1, -1);
3675 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3676}
3677
Michael Chanc0c050c2015-10-22 16:01:17 -04003678static int bnxt_hwrm_tunnel_dst_port_free(struct bnxt *bp, u8 tunnel_type)
3679{
3680 u32 rc = 0;
3681 struct hwrm_tunnel_dst_port_free_input req = {0};
3682
3683 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_TUNNEL_DST_PORT_FREE, -1, -1);
3684 req.tunnel_type = tunnel_type;
3685
3686 switch (tunnel_type) {
3687 case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN:
3688 req.tunnel_dst_port_id = bp->vxlan_fw_dst_port_id;
3689 break;
3690 case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE:
3691 req.tunnel_dst_port_id = bp->nge_fw_dst_port_id;
3692 break;
3693 default:
3694 break;
3695 }
3696
3697 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3698 if (rc)
3699 netdev_err(bp->dev, "hwrm_tunnel_dst_port_free failed. rc:%d\n",
3700 rc);
3701 return rc;
3702}
3703
3704static int bnxt_hwrm_tunnel_dst_port_alloc(struct bnxt *bp, __be16 port,
3705 u8 tunnel_type)
3706{
3707 u32 rc = 0;
3708 struct hwrm_tunnel_dst_port_alloc_input req = {0};
3709 struct hwrm_tunnel_dst_port_alloc_output *resp = bp->hwrm_cmd_resp_addr;
3710
3711 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_TUNNEL_DST_PORT_ALLOC, -1, -1);
3712
3713 req.tunnel_type = tunnel_type;
3714 req.tunnel_dst_port_val = port;
3715
3716 mutex_lock(&bp->hwrm_cmd_lock);
3717 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3718 if (rc) {
3719 netdev_err(bp->dev, "hwrm_tunnel_dst_port_alloc failed. rc:%d\n",
3720 rc);
3721 goto err_out;
3722 }
3723
Christophe Jaillet57aac712016-11-22 06:14:40 +01003724 switch (tunnel_type) {
3725 case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_VXLAN:
Michael Chanc0c050c2015-10-22 16:01:17 -04003726 bp->vxlan_fw_dst_port_id = resp->tunnel_dst_port_id;
Christophe Jaillet57aac712016-11-22 06:14:40 +01003727 break;
3728 case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_GENEVE:
Michael Chanc0c050c2015-10-22 16:01:17 -04003729 bp->nge_fw_dst_port_id = resp->tunnel_dst_port_id;
Christophe Jaillet57aac712016-11-22 06:14:40 +01003730 break;
3731 default:
3732 break;
3733 }
3734
Michael Chanc0c050c2015-10-22 16:01:17 -04003735err_out:
3736 mutex_unlock(&bp->hwrm_cmd_lock);
3737 return rc;
3738}
3739
3740static int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt *bp, u16 vnic_id)
3741{
3742 struct hwrm_cfa_l2_set_rx_mask_input req = {0};
3743 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
3744
3745 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_L2_SET_RX_MASK, -1, -1);
Michael Chanc1935542015-12-27 18:19:28 -05003746 req.vnic_id = cpu_to_le32(vnic->fw_vnic_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04003747
3748 req.num_mc_entries = cpu_to_le32(vnic->mc_list_count);
3749 req.mc_tbl_addr = cpu_to_le64(vnic->mc_list_mapping);
3750 req.mask = cpu_to_le32(vnic->rx_mask);
3751 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3752}
3753
3754#ifdef CONFIG_RFS_ACCEL
3755static int bnxt_hwrm_cfa_ntuple_filter_free(struct bnxt *bp,
3756 struct bnxt_ntuple_filter *fltr)
3757{
3758 struct hwrm_cfa_ntuple_filter_free_input req = {0};
3759
3760 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_NTUPLE_FILTER_FREE, -1, -1);
3761 req.ntuple_filter_id = fltr->filter_id;
3762 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3763}
3764
3765#define BNXT_NTP_FLTR_FLAGS \
3766 (CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_L2_FILTER_ID | \
3767 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_ETHERTYPE | \
3768 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_MACADDR | \
3769 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IPADDR_TYPE | \
3770 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR | \
3771 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR_MASK | \
3772 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR | \
3773 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR_MASK | \
3774 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IP_PROTOCOL | \
3775 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT | \
3776 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT_MASK | \
3777 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT | \
3778 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT_MASK | \
Michael Chanc1935542015-12-27 18:19:28 -05003779 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_ID)
Michael Chanc0c050c2015-10-22 16:01:17 -04003780
Michael Chan61aad722017-02-12 19:18:14 -05003781#define BNXT_NTP_TUNNEL_FLTR_FLAG \
3782 CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_TUNNEL_TYPE
3783
Michael Chanc0c050c2015-10-22 16:01:17 -04003784static int bnxt_hwrm_cfa_ntuple_filter_alloc(struct bnxt *bp,
3785 struct bnxt_ntuple_filter *fltr)
3786{
3787 int rc = 0;
3788 struct hwrm_cfa_ntuple_filter_alloc_input req = {0};
3789 struct hwrm_cfa_ntuple_filter_alloc_output *resp =
3790 bp->hwrm_cmd_resp_addr;
3791 struct flow_keys *keys = &fltr->fkeys;
3792 struct bnxt_vnic_info *vnic = &bp->vnic_info[fltr->rxq + 1];
3793
3794 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_NTUPLE_FILTER_ALLOC, -1, -1);
Michael Chana54c4d72016-07-25 12:33:35 -04003795 req.l2_filter_id = bp->vnic_info[0].fw_l2_filter_id[fltr->l2_fltr_idx];
Michael Chanc0c050c2015-10-22 16:01:17 -04003796
3797 req.enables = cpu_to_le32(BNXT_NTP_FLTR_FLAGS);
3798
3799 req.ethertype = htons(ETH_P_IP);
3800 memcpy(req.src_macaddr, fltr->src_mac_addr, ETH_ALEN);
Michael Chanc1935542015-12-27 18:19:28 -05003801 req.ip_addr_type = CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV4;
Michael Chanc0c050c2015-10-22 16:01:17 -04003802 req.ip_protocol = keys->basic.ip_proto;
3803
Michael Chandda0e742016-12-29 12:13:40 -05003804 if (keys->basic.n_proto == htons(ETH_P_IPV6)) {
3805 int i;
3806
3807 req.ethertype = htons(ETH_P_IPV6);
3808 req.ip_addr_type =
3809 CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV6;
3810 *(struct in6_addr *)&req.src_ipaddr[0] =
3811 keys->addrs.v6addrs.src;
3812 *(struct in6_addr *)&req.dst_ipaddr[0] =
3813 keys->addrs.v6addrs.dst;
3814 for (i = 0; i < 4; i++) {
3815 req.src_ipaddr_mask[i] = cpu_to_be32(0xffffffff);
3816 req.dst_ipaddr_mask[i] = cpu_to_be32(0xffffffff);
3817 }
3818 } else {
3819 req.src_ipaddr[0] = keys->addrs.v4addrs.src;
3820 req.src_ipaddr_mask[0] = cpu_to_be32(0xffffffff);
3821 req.dst_ipaddr[0] = keys->addrs.v4addrs.dst;
3822 req.dst_ipaddr_mask[0] = cpu_to_be32(0xffffffff);
3823 }
Michael Chan61aad722017-02-12 19:18:14 -05003824 if (keys->control.flags & FLOW_DIS_ENCAPSULATION) {
3825 req.enables |= cpu_to_le32(BNXT_NTP_TUNNEL_FLTR_FLAG);
3826 req.tunnel_type =
3827 CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_ANYTUNNEL;
3828 }
Michael Chanc0c050c2015-10-22 16:01:17 -04003829
3830 req.src_port = keys->ports.src;
3831 req.src_port_mask = cpu_to_be16(0xffff);
3832 req.dst_port = keys->ports.dst;
3833 req.dst_port_mask = cpu_to_be16(0xffff);
3834
Michael Chanc1935542015-12-27 18:19:28 -05003835 req.dst_id = cpu_to_le16(vnic->fw_vnic_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04003836 mutex_lock(&bp->hwrm_cmd_lock);
3837 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3838 if (!rc)
3839 fltr->filter_id = resp->ntuple_filter_id;
3840 mutex_unlock(&bp->hwrm_cmd_lock);
3841 return rc;
3842}
3843#endif
3844
3845static int bnxt_hwrm_set_vnic_filter(struct bnxt *bp, u16 vnic_id, u16 idx,
3846 u8 *mac_addr)
3847{
3848 u32 rc = 0;
3849 struct hwrm_cfa_l2_filter_alloc_input req = {0};
3850 struct hwrm_cfa_l2_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr;
3851
3852 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_L2_FILTER_ALLOC, -1, -1);
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04003853 req.flags = cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_PATH_RX);
3854 if (!BNXT_CHIP_TYPE_NITRO_A0(bp))
3855 req.flags |=
3856 cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_OUTERMOST);
Michael Chanc1935542015-12-27 18:19:28 -05003857 req.dst_id = cpu_to_le16(bp->vnic_info[vnic_id].fw_vnic_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04003858 req.enables =
3859 cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR |
Michael Chanc1935542015-12-27 18:19:28 -05003860 CFA_L2_FILTER_ALLOC_REQ_ENABLES_DST_ID |
Michael Chanc0c050c2015-10-22 16:01:17 -04003861 CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR_MASK);
3862 memcpy(req.l2_addr, mac_addr, ETH_ALEN);
3863 req.l2_addr_mask[0] = 0xff;
3864 req.l2_addr_mask[1] = 0xff;
3865 req.l2_addr_mask[2] = 0xff;
3866 req.l2_addr_mask[3] = 0xff;
3867 req.l2_addr_mask[4] = 0xff;
3868 req.l2_addr_mask[5] = 0xff;
3869
3870 mutex_lock(&bp->hwrm_cmd_lock);
3871 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3872 if (!rc)
3873 bp->vnic_info[vnic_id].fw_l2_filter_id[idx] =
3874 resp->l2_filter_id;
3875 mutex_unlock(&bp->hwrm_cmd_lock);
3876 return rc;
3877}
3878
3879static int bnxt_hwrm_clear_vnic_filter(struct bnxt *bp)
3880{
3881 u16 i, j, num_of_vnics = 1; /* only vnic 0 supported */
3882 int rc = 0;
3883
3884 /* Any associated ntuple filters will also be cleared by firmware. */
3885 mutex_lock(&bp->hwrm_cmd_lock);
3886 for (i = 0; i < num_of_vnics; i++) {
3887 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
3888
3889 for (j = 0; j < vnic->uc_filter_count; j++) {
3890 struct hwrm_cfa_l2_filter_free_input req = {0};
3891
3892 bnxt_hwrm_cmd_hdr_init(bp, &req,
3893 HWRM_CFA_L2_FILTER_FREE, -1, -1);
3894
3895 req.l2_filter_id = vnic->fw_l2_filter_id[j];
3896
3897 rc = _hwrm_send_message(bp, &req, sizeof(req),
3898 HWRM_CMD_TIMEOUT);
3899 }
3900 vnic->uc_filter_count = 0;
3901 }
3902 mutex_unlock(&bp->hwrm_cmd_lock);
3903
3904 return rc;
3905}
3906
3907static int bnxt_hwrm_vnic_set_tpa(struct bnxt *bp, u16 vnic_id, u32 tpa_flags)
3908{
3909 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
3910 struct hwrm_vnic_tpa_cfg_input req = {0};
3911
Michael Chan3c4fe802018-03-09 23:46:10 -05003912 if (vnic->fw_vnic_id == INVALID_HW_RING_ID)
3913 return 0;
3914
Michael Chanc0c050c2015-10-22 16:01:17 -04003915 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_TPA_CFG, -1, -1);
3916
3917 if (tpa_flags) {
3918 u16 mss = bp->dev->mtu - 40;
3919 u32 nsegs, n, segs = 0, flags;
3920
3921 flags = VNIC_TPA_CFG_REQ_FLAGS_TPA |
3922 VNIC_TPA_CFG_REQ_FLAGS_ENCAP_TPA |
3923 VNIC_TPA_CFG_REQ_FLAGS_RSC_WND_UPDATE |
3924 VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_ECN |
3925 VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_SAME_GRE_SEQ;
3926 if (tpa_flags & BNXT_FLAG_GRO)
3927 flags |= VNIC_TPA_CFG_REQ_FLAGS_GRO;
3928
3929 req.flags = cpu_to_le32(flags);
3930
3931 req.enables =
3932 cpu_to_le32(VNIC_TPA_CFG_REQ_ENABLES_MAX_AGG_SEGS |
Michael Chanc1935542015-12-27 18:19:28 -05003933 VNIC_TPA_CFG_REQ_ENABLES_MAX_AGGS |
3934 VNIC_TPA_CFG_REQ_ENABLES_MIN_AGG_LEN);
Michael Chanc0c050c2015-10-22 16:01:17 -04003935
3936 /* Number of segs are log2 units, and first packet is not
3937 * included as part of this units.
3938 */
Michael Chan2839f282016-04-25 02:30:50 -04003939 if (mss <= BNXT_RX_PAGE_SIZE) {
3940 n = BNXT_RX_PAGE_SIZE / mss;
Michael Chanc0c050c2015-10-22 16:01:17 -04003941 nsegs = (MAX_SKB_FRAGS - 1) * n;
3942 } else {
Michael Chan2839f282016-04-25 02:30:50 -04003943 n = mss / BNXT_RX_PAGE_SIZE;
3944 if (mss & (BNXT_RX_PAGE_SIZE - 1))
Michael Chanc0c050c2015-10-22 16:01:17 -04003945 n++;
3946 nsegs = (MAX_SKB_FRAGS - n) / n;
3947 }
3948
3949 segs = ilog2(nsegs);
3950 req.max_agg_segs = cpu_to_le16(segs);
3951 req.max_aggs = cpu_to_le16(VNIC_TPA_CFG_REQ_MAX_AGGS_MAX);
Michael Chanc1935542015-12-27 18:19:28 -05003952
3953 req.min_agg_len = cpu_to_le32(512);
Michael Chanc0c050c2015-10-22 16:01:17 -04003954 }
3955 req.vnic_id = cpu_to_le16(vnic->fw_vnic_id);
3956
3957 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3958}
3959
3960static int bnxt_hwrm_vnic_set_rss(struct bnxt *bp, u16 vnic_id, bool set_rss)
3961{
3962 u32 i, j, max_rings;
3963 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
3964 struct hwrm_vnic_rss_cfg_input req = {0};
3965
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04003966 if (vnic->fw_rss_cos_lb_ctx[0] == INVALID_HW_RING_ID)
Michael Chanc0c050c2015-10-22 16:01:17 -04003967 return 0;
3968
3969 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_CFG, -1, -1);
3970 if (set_rss) {
Michael Chan87da7f72016-11-16 21:13:09 -05003971 req.hash_type = cpu_to_le32(bp->rss_hash_cfg);
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04003972 if (vnic->flags & BNXT_VNIC_RSS_FLAG) {
3973 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
3974 max_rings = bp->rx_nr_rings - 1;
3975 else
3976 max_rings = bp->rx_nr_rings;
3977 } else {
Michael Chanc0c050c2015-10-22 16:01:17 -04003978 max_rings = 1;
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04003979 }
Michael Chanc0c050c2015-10-22 16:01:17 -04003980
3981 /* Fill the RSS indirection table with ring group ids */
3982 for (i = 0, j = 0; i < HW_HASH_INDEX_SIZE; i++, j++) {
3983 if (j == max_rings)
3984 j = 0;
3985 vnic->rss_table[i] = cpu_to_le16(vnic->fw_grp_ids[j]);
3986 }
3987
3988 req.ring_grp_tbl_addr = cpu_to_le64(vnic->rss_table_dma_addr);
3989 req.hash_key_tbl_addr =
3990 cpu_to_le64(vnic->rss_hash_key_dma_addr);
3991 }
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04003992 req.rss_ctx_idx = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[0]);
Michael Chanc0c050c2015-10-22 16:01:17 -04003993 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3994}
3995
3996static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, u16 vnic_id)
3997{
3998 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
3999 struct hwrm_vnic_plcmodes_cfg_input req = {0};
4000
4001 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_PLCMODES_CFG, -1, -1);
4002 req.flags = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT |
4003 VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV4 |
4004 VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6);
4005 req.enables =
4006 cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID |
4007 VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID);
4008 /* thresholds not implemented in firmware yet */
4009 req.jumbo_thresh = cpu_to_le16(bp->rx_copy_thresh);
4010 req.hds_threshold = cpu_to_le16(bp->rx_copy_thresh);
4011 req.vnic_id = cpu_to_le32(vnic->fw_vnic_id);
4012 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4013}
4014
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004015static void bnxt_hwrm_vnic_ctx_free_one(struct bnxt *bp, u16 vnic_id,
4016 u16 ctx_idx)
Michael Chanc0c050c2015-10-22 16:01:17 -04004017{
4018 struct hwrm_vnic_rss_cos_lb_ctx_free_input req = {0};
4019
4020 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_COS_LB_CTX_FREE, -1, -1);
4021 req.rss_cos_lb_ctx_id =
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004022 cpu_to_le16(bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx]);
Michael Chanc0c050c2015-10-22 16:01:17 -04004023
4024 hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004025 bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx] = INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04004026}
4027
4028static void bnxt_hwrm_vnic_ctx_free(struct bnxt *bp)
4029{
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004030 int i, j;
Michael Chanc0c050c2015-10-22 16:01:17 -04004031
4032 for (i = 0; i < bp->nr_vnics; i++) {
4033 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
4034
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004035 for (j = 0; j < BNXT_MAX_CTX_PER_VNIC; j++) {
4036 if (vnic->fw_rss_cos_lb_ctx[j] != INVALID_HW_RING_ID)
4037 bnxt_hwrm_vnic_ctx_free_one(bp, i, j);
4038 }
Michael Chanc0c050c2015-10-22 16:01:17 -04004039 }
4040 bp->rsscos_nr_ctxs = 0;
4041}
4042
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004043static int bnxt_hwrm_vnic_ctx_alloc(struct bnxt *bp, u16 vnic_id, u16 ctx_idx)
Michael Chanc0c050c2015-10-22 16:01:17 -04004044{
4045 int rc;
4046 struct hwrm_vnic_rss_cos_lb_ctx_alloc_input req = {0};
4047 struct hwrm_vnic_rss_cos_lb_ctx_alloc_output *resp =
4048 bp->hwrm_cmd_resp_addr;
4049
4050 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_COS_LB_CTX_ALLOC, -1,
4051 -1);
4052
4053 mutex_lock(&bp->hwrm_cmd_lock);
4054 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4055 if (!rc)
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004056 bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx] =
Michael Chanc0c050c2015-10-22 16:01:17 -04004057 le16_to_cpu(resp->rss_cos_lb_ctx_id);
4058 mutex_unlock(&bp->hwrm_cmd_lock);
4059
4060 return rc;
4061}
4062
Michael Chanabe93ad2018-03-31 13:54:08 -04004063static u32 bnxt_get_roce_vnic_mode(struct bnxt *bp)
4064{
4065 if (bp->flags & BNXT_FLAG_ROCE_MIRROR_CAP)
4066 return VNIC_CFG_REQ_FLAGS_ROCE_MIRRORING_CAPABLE_VNIC_MODE;
4067 return VNIC_CFG_REQ_FLAGS_ROCE_DUAL_VNIC_MODE;
4068}
4069
Michael Chana588e452016-12-07 00:26:21 -05004070int bnxt_hwrm_vnic_cfg(struct bnxt *bp, u16 vnic_id)
Michael Chanc0c050c2015-10-22 16:01:17 -04004071{
Michael Chanb81a90d2016-01-02 23:45:01 -05004072 unsigned int ring = 0, grp_idx;
Michael Chanc0c050c2015-10-22 16:01:17 -04004073 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
4074 struct hwrm_vnic_cfg_input req = {0};
Michael Chancf6645f2016-06-13 02:25:28 -04004075 u16 def_vlan = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04004076
4077 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_CFG, -1, -1);
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004078
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04004079 req.enables = cpu_to_le32(VNIC_CFG_REQ_ENABLES_DFLT_RING_GRP);
4080 /* Only RSS support for now TBD: COS & LB */
4081 if (vnic->fw_rss_cos_lb_ctx[0] != INVALID_HW_RING_ID) {
4082 req.rss_rule = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[0]);
4083 req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE |
4084 VNIC_CFG_REQ_ENABLES_MRU);
Michael Chanae10ae72016-12-29 12:13:38 -05004085 } else if (vnic->flags & BNXT_VNIC_RFS_NEW_RSS_FLAG) {
4086 req.rss_rule =
4087 cpu_to_le16(bp->vnic_info[0].fw_rss_cos_lb_ctx[0]);
4088 req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE |
4089 VNIC_CFG_REQ_ENABLES_MRU);
4090 req.flags |= cpu_to_le32(VNIC_CFG_REQ_FLAGS_RSS_DFLT_CR_MODE);
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04004091 } else {
4092 req.rss_rule = cpu_to_le16(0xffff);
4093 }
4094
4095 if (BNXT_CHIP_TYPE_NITRO_A0(bp) &&
4096 (vnic->fw_rss_cos_lb_ctx[0] != INVALID_HW_RING_ID)) {
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004097 req.cos_rule = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[1]);
4098 req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_COS_RULE);
4099 } else {
4100 req.cos_rule = cpu_to_le16(0xffff);
4101 }
4102
Michael Chanc0c050c2015-10-22 16:01:17 -04004103 if (vnic->flags & BNXT_VNIC_RSS_FLAG)
Michael Chanb81a90d2016-01-02 23:45:01 -05004104 ring = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04004105 else if (vnic->flags & BNXT_VNIC_RFS_FLAG)
Michael Chanb81a90d2016-01-02 23:45:01 -05004106 ring = vnic_id - 1;
Prashant Sreedharan76595192016-07-18 07:15:22 -04004107 else if ((vnic_id == 1) && BNXT_CHIP_TYPE_NITRO_A0(bp))
4108 ring = bp->rx_nr_rings - 1;
Michael Chanc0c050c2015-10-22 16:01:17 -04004109
Michael Chanb81a90d2016-01-02 23:45:01 -05004110 grp_idx = bp->rx_ring[ring].bnapi->index;
Michael Chanc0c050c2015-10-22 16:01:17 -04004111 req.vnic_id = cpu_to_le16(vnic->fw_vnic_id);
4112 req.dflt_ring_grp = cpu_to_le16(bp->grp_info[grp_idx].fw_grp_id);
4113
4114 req.lb_rule = cpu_to_le16(0xffff);
4115 req.mru = cpu_to_le16(bp->dev->mtu + ETH_HLEN + ETH_FCS_LEN +
4116 VLAN_HLEN);
4117
Michael Chancf6645f2016-06-13 02:25:28 -04004118#ifdef CONFIG_BNXT_SRIOV
4119 if (BNXT_VF(bp))
4120 def_vlan = bp->vf.vlan;
4121#endif
4122 if ((bp->flags & BNXT_FLAG_STRIP_VLAN) || def_vlan)
Michael Chanc0c050c2015-10-22 16:01:17 -04004123 req.flags |= cpu_to_le32(VNIC_CFG_REQ_FLAGS_VLAN_STRIP_MODE);
Michael Chana588e452016-12-07 00:26:21 -05004124 if (!vnic_id && bnxt_ulp_registered(bp->edev, BNXT_ROCE_ULP))
Michael Chanabe93ad2018-03-31 13:54:08 -04004125 req.flags |= cpu_to_le32(bnxt_get_roce_vnic_mode(bp));
Michael Chanc0c050c2015-10-22 16:01:17 -04004126
4127 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4128}
4129
4130static int bnxt_hwrm_vnic_free_one(struct bnxt *bp, u16 vnic_id)
4131{
4132 u32 rc = 0;
4133
4134 if (bp->vnic_info[vnic_id].fw_vnic_id != INVALID_HW_RING_ID) {
4135 struct hwrm_vnic_free_input req = {0};
4136
4137 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_FREE, -1, -1);
4138 req.vnic_id =
4139 cpu_to_le32(bp->vnic_info[vnic_id].fw_vnic_id);
4140
4141 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4142 if (rc)
4143 return rc;
4144 bp->vnic_info[vnic_id].fw_vnic_id = INVALID_HW_RING_ID;
4145 }
4146 return rc;
4147}
4148
4149static void bnxt_hwrm_vnic_free(struct bnxt *bp)
4150{
4151 u16 i;
4152
4153 for (i = 0; i < bp->nr_vnics; i++)
4154 bnxt_hwrm_vnic_free_one(bp, i);
4155}
4156
Michael Chanb81a90d2016-01-02 23:45:01 -05004157static int bnxt_hwrm_vnic_alloc(struct bnxt *bp, u16 vnic_id,
4158 unsigned int start_rx_ring_idx,
4159 unsigned int nr_rings)
Michael Chanc0c050c2015-10-22 16:01:17 -04004160{
Michael Chanb81a90d2016-01-02 23:45:01 -05004161 int rc = 0;
4162 unsigned int i, j, grp_idx, end_idx = start_rx_ring_idx + nr_rings;
Michael Chanc0c050c2015-10-22 16:01:17 -04004163 struct hwrm_vnic_alloc_input req = {0};
4164 struct hwrm_vnic_alloc_output *resp = bp->hwrm_cmd_resp_addr;
4165
4166 /* map ring groups to this vnic */
Michael Chanb81a90d2016-01-02 23:45:01 -05004167 for (i = start_rx_ring_idx, j = 0; i < end_idx; i++, j++) {
4168 grp_idx = bp->rx_ring[i].bnapi->index;
4169 if (bp->grp_info[grp_idx].fw_grp_id == INVALID_HW_RING_ID) {
Michael Chanc0c050c2015-10-22 16:01:17 -04004170 netdev_err(bp->dev, "Not enough ring groups avail:%x req:%x\n",
Michael Chanb81a90d2016-01-02 23:45:01 -05004171 j, nr_rings);
Michael Chanc0c050c2015-10-22 16:01:17 -04004172 break;
4173 }
4174 bp->vnic_info[vnic_id].fw_grp_ids[j] =
Michael Chanb81a90d2016-01-02 23:45:01 -05004175 bp->grp_info[grp_idx].fw_grp_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04004176 }
4177
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04004178 bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[0] = INVALID_HW_RING_ID;
4179 bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[1] = INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04004180 if (vnic_id == 0)
4181 req.flags = cpu_to_le32(VNIC_ALLOC_REQ_FLAGS_DEFAULT);
4182
4183 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_ALLOC, -1, -1);
4184
4185 mutex_lock(&bp->hwrm_cmd_lock);
4186 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4187 if (!rc)
4188 bp->vnic_info[vnic_id].fw_vnic_id = le32_to_cpu(resp->vnic_id);
4189 mutex_unlock(&bp->hwrm_cmd_lock);
4190 return rc;
4191}
4192
Michael Chan8fdefd62016-12-29 12:13:36 -05004193static int bnxt_hwrm_vnic_qcaps(struct bnxt *bp)
4194{
4195 struct hwrm_vnic_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
4196 struct hwrm_vnic_qcaps_input req = {0};
4197 int rc;
4198
4199 if (bp->hwrm_spec_code < 0x10600)
4200 return 0;
4201
4202 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_QCAPS, -1, -1);
4203 mutex_lock(&bp->hwrm_cmd_lock);
4204 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4205 if (!rc) {
Michael Chanabe93ad2018-03-31 13:54:08 -04004206 u32 flags = le32_to_cpu(resp->flags);
4207
4208 if (flags & VNIC_QCAPS_RESP_FLAGS_RSS_DFLT_CR_CAP)
Michael Chan8fdefd62016-12-29 12:13:36 -05004209 bp->flags |= BNXT_FLAG_NEW_RSS_CAP;
Michael Chanabe93ad2018-03-31 13:54:08 -04004210 if (flags &
4211 VNIC_QCAPS_RESP_FLAGS_ROCE_MIRRORING_CAPABLE_VNIC_CAP)
4212 bp->flags |= BNXT_FLAG_ROCE_MIRROR_CAP;
Michael Chan8fdefd62016-12-29 12:13:36 -05004213 }
4214 mutex_unlock(&bp->hwrm_cmd_lock);
4215 return rc;
4216}
4217
Michael Chanc0c050c2015-10-22 16:01:17 -04004218static int bnxt_hwrm_ring_grp_alloc(struct bnxt *bp)
4219{
4220 u16 i;
4221 u32 rc = 0;
4222
4223 mutex_lock(&bp->hwrm_cmd_lock);
4224 for (i = 0; i < bp->rx_nr_rings; i++) {
4225 struct hwrm_ring_grp_alloc_input req = {0};
4226 struct hwrm_ring_grp_alloc_output *resp =
4227 bp->hwrm_cmd_resp_addr;
Michael Chanb81a90d2016-01-02 23:45:01 -05004228 unsigned int grp_idx = bp->rx_ring[i].bnapi->index;
Michael Chanc0c050c2015-10-22 16:01:17 -04004229
4230 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_GRP_ALLOC, -1, -1);
4231
Michael Chanb81a90d2016-01-02 23:45:01 -05004232 req.cr = cpu_to_le16(bp->grp_info[grp_idx].cp_fw_ring_id);
4233 req.rr = cpu_to_le16(bp->grp_info[grp_idx].rx_fw_ring_id);
4234 req.ar = cpu_to_le16(bp->grp_info[grp_idx].agg_fw_ring_id);
4235 req.sc = cpu_to_le16(bp->grp_info[grp_idx].fw_stats_ctx);
Michael Chanc0c050c2015-10-22 16:01:17 -04004236
4237 rc = _hwrm_send_message(bp, &req, sizeof(req),
4238 HWRM_CMD_TIMEOUT);
4239 if (rc)
4240 break;
4241
Michael Chanb81a90d2016-01-02 23:45:01 -05004242 bp->grp_info[grp_idx].fw_grp_id =
4243 le32_to_cpu(resp->ring_group_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04004244 }
4245 mutex_unlock(&bp->hwrm_cmd_lock);
4246 return rc;
4247}
4248
4249static int bnxt_hwrm_ring_grp_free(struct bnxt *bp)
4250{
4251 u16 i;
4252 u32 rc = 0;
4253 struct hwrm_ring_grp_free_input req = {0};
4254
4255 if (!bp->grp_info)
4256 return 0;
4257
4258 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_GRP_FREE, -1, -1);
4259
4260 mutex_lock(&bp->hwrm_cmd_lock);
4261 for (i = 0; i < bp->cp_nr_rings; i++) {
4262 if (bp->grp_info[i].fw_grp_id == INVALID_HW_RING_ID)
4263 continue;
4264 req.ring_group_id =
4265 cpu_to_le32(bp->grp_info[i].fw_grp_id);
4266
4267 rc = _hwrm_send_message(bp, &req, sizeof(req),
4268 HWRM_CMD_TIMEOUT);
4269 if (rc)
4270 break;
4271 bp->grp_info[i].fw_grp_id = INVALID_HW_RING_ID;
4272 }
4273 mutex_unlock(&bp->hwrm_cmd_lock);
4274 return rc;
4275}
4276
4277static int hwrm_ring_alloc_send_msg(struct bnxt *bp,
4278 struct bnxt_ring_struct *ring,
Michael Chan9899bb52018-03-31 13:54:16 -04004279 u32 ring_type, u32 map_index)
Michael Chanc0c050c2015-10-22 16:01:17 -04004280{
4281 int rc = 0, err = 0;
4282 struct hwrm_ring_alloc_input req = {0};
4283 struct hwrm_ring_alloc_output *resp = bp->hwrm_cmd_resp_addr;
Michael Chan9899bb52018-03-31 13:54:16 -04004284 struct bnxt_ring_grp_info *grp_info;
Michael Chanc0c050c2015-10-22 16:01:17 -04004285 u16 ring_id;
4286
4287 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_ALLOC, -1, -1);
4288
4289 req.enables = 0;
4290 if (ring->nr_pages > 1) {
4291 req.page_tbl_addr = cpu_to_le64(ring->pg_tbl_map);
4292 /* Page size is in log2 units */
4293 req.page_size = BNXT_PAGE_SHIFT;
4294 req.page_tbl_depth = 1;
4295 } else {
4296 req.page_tbl_addr = cpu_to_le64(ring->dma_arr[0]);
4297 }
4298 req.fbo = 0;
4299 /* Association of ring index with doorbell index and MSIX number */
4300 req.logical_id = cpu_to_le16(map_index);
4301
4302 switch (ring_type) {
4303 case HWRM_RING_ALLOC_TX:
4304 req.ring_type = RING_ALLOC_REQ_RING_TYPE_TX;
4305 /* Association of transmit ring with completion ring */
Michael Chan9899bb52018-03-31 13:54:16 -04004306 grp_info = &bp->grp_info[ring->grp_idx];
4307 req.cmpl_ring_id = cpu_to_le16(grp_info->cp_fw_ring_id);
Michael Chanc0c050c2015-10-22 16:01:17 -04004308 req.length = cpu_to_le32(bp->tx_ring_mask + 1);
Michael Chan9899bb52018-03-31 13:54:16 -04004309 req.stat_ctx_id = cpu_to_le32(grp_info->fw_stats_ctx);
Michael Chanc0c050c2015-10-22 16:01:17 -04004310 req.queue_id = cpu_to_le16(ring->queue_id);
4311 break;
4312 case HWRM_RING_ALLOC_RX:
4313 req.ring_type = RING_ALLOC_REQ_RING_TYPE_RX;
4314 req.length = cpu_to_le32(bp->rx_ring_mask + 1);
4315 break;
4316 case HWRM_RING_ALLOC_AGG:
4317 req.ring_type = RING_ALLOC_REQ_RING_TYPE_RX;
4318 req.length = cpu_to_le32(bp->rx_agg_ring_mask + 1);
4319 break;
4320 case HWRM_RING_ALLOC_CMPL:
Michael Chanbac9a7e2017-02-12 19:18:10 -05004321 req.ring_type = RING_ALLOC_REQ_RING_TYPE_L2_CMPL;
Michael Chanc0c050c2015-10-22 16:01:17 -04004322 req.length = cpu_to_le32(bp->cp_ring_mask + 1);
4323 if (bp->flags & BNXT_FLAG_USING_MSIX)
4324 req.int_mode = RING_ALLOC_REQ_INT_MODE_MSIX;
4325 break;
4326 default:
4327 netdev_err(bp->dev, "hwrm alloc invalid ring type %d\n",
4328 ring_type);
4329 return -1;
4330 }
4331
4332 mutex_lock(&bp->hwrm_cmd_lock);
4333 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4334 err = le16_to_cpu(resp->error_code);
4335 ring_id = le16_to_cpu(resp->ring_id);
4336 mutex_unlock(&bp->hwrm_cmd_lock);
4337
4338 if (rc || err) {
4339 switch (ring_type) {
Michael Chanbac9a7e2017-02-12 19:18:10 -05004340 case RING_FREE_REQ_RING_TYPE_L2_CMPL:
Michael Chanc0c050c2015-10-22 16:01:17 -04004341 netdev_err(bp->dev, "hwrm_ring_alloc cp failed. rc:%x err:%x\n",
4342 rc, err);
4343 return -1;
4344
4345 case RING_FREE_REQ_RING_TYPE_RX:
4346 netdev_err(bp->dev, "hwrm_ring_alloc rx failed. rc:%x err:%x\n",
4347 rc, err);
4348 return -1;
4349
4350 case RING_FREE_REQ_RING_TYPE_TX:
4351 netdev_err(bp->dev, "hwrm_ring_alloc tx failed. rc:%x err:%x\n",
4352 rc, err);
4353 return -1;
4354
4355 default:
4356 netdev_err(bp->dev, "Invalid ring\n");
4357 return -1;
4358 }
4359 }
4360 ring->fw_ring_id = ring_id;
4361 return rc;
4362}
4363
Michael Chan486b5c22016-12-29 12:13:42 -05004364static int bnxt_hwrm_set_async_event_cr(struct bnxt *bp, int idx)
4365{
4366 int rc;
4367
4368 if (BNXT_PF(bp)) {
4369 struct hwrm_func_cfg_input req = {0};
4370
4371 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1);
4372 req.fid = cpu_to_le16(0xffff);
4373 req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_ASYNC_EVENT_CR);
4374 req.async_event_cr = cpu_to_le16(idx);
4375 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4376 } else {
4377 struct hwrm_func_vf_cfg_input req = {0};
4378
4379 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_VF_CFG, -1, -1);
4380 req.enables =
4381 cpu_to_le32(FUNC_VF_CFG_REQ_ENABLES_ASYNC_EVENT_CR);
4382 req.async_event_cr = cpu_to_le16(idx);
4383 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4384 }
4385 return rc;
4386}
4387
Michael Chanc0c050c2015-10-22 16:01:17 -04004388static int bnxt_hwrm_ring_alloc(struct bnxt *bp)
4389{
4390 int i, rc = 0;
4391
Michael Chanedd0c2c2015-12-27 18:19:19 -05004392 for (i = 0; i < bp->cp_nr_rings; i++) {
4393 struct bnxt_napi *bnapi = bp->bnapi[i];
4394 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
4395 struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
Michael Chan9899bb52018-03-31 13:54:16 -04004396 u32 map_idx = ring->map_idx;
Michael Chanc0c050c2015-10-22 16:01:17 -04004397
Michael Chan9899bb52018-03-31 13:54:16 -04004398 cpr->cp_doorbell = bp->bar1 + map_idx * 0x80;
4399 rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_CMPL,
4400 map_idx);
Michael Chanedd0c2c2015-12-27 18:19:19 -05004401 if (rc)
4402 goto err_out;
Michael Chanedd0c2c2015-12-27 18:19:19 -05004403 BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
4404 bp->grp_info[i].cp_fw_ring_id = ring->fw_ring_id;
Michael Chan486b5c22016-12-29 12:13:42 -05004405
4406 if (!i) {
4407 rc = bnxt_hwrm_set_async_event_cr(bp, ring->fw_ring_id);
4408 if (rc)
4409 netdev_warn(bp->dev, "Failed to set async event completion ring.\n");
4410 }
Michael Chanc0c050c2015-10-22 16:01:17 -04004411 }
4412
Michael Chanedd0c2c2015-12-27 18:19:19 -05004413 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05004414 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
Michael Chanedd0c2c2015-12-27 18:19:19 -05004415 struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
Michael Chan9899bb52018-03-31 13:54:16 -04004416 u32 map_idx = i;
Michael Chanc0c050c2015-10-22 16:01:17 -04004417
Michael Chanb81a90d2016-01-02 23:45:01 -05004418 rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_TX,
Michael Chan9899bb52018-03-31 13:54:16 -04004419 map_idx);
Michael Chanedd0c2c2015-12-27 18:19:19 -05004420 if (rc)
4421 goto err_out;
Michael Chanb81a90d2016-01-02 23:45:01 -05004422 txr->tx_doorbell = bp->bar1 + map_idx * 0x80;
Michael Chanc0c050c2015-10-22 16:01:17 -04004423 }
4424
Michael Chanedd0c2c2015-12-27 18:19:19 -05004425 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05004426 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
Michael Chanedd0c2c2015-12-27 18:19:19 -05004427 struct bnxt_ring_struct *ring = &rxr->rx_ring_struct;
Michael Chanb81a90d2016-01-02 23:45:01 -05004428 u32 map_idx = rxr->bnapi->index;
Michael Chanc0c050c2015-10-22 16:01:17 -04004429
Michael Chanb81a90d2016-01-02 23:45:01 -05004430 rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_RX,
Michael Chan9899bb52018-03-31 13:54:16 -04004431 map_idx);
Michael Chanedd0c2c2015-12-27 18:19:19 -05004432 if (rc)
4433 goto err_out;
Michael Chanb81a90d2016-01-02 23:45:01 -05004434 rxr->rx_doorbell = bp->bar1 + map_idx * 0x80;
Michael Chanedd0c2c2015-12-27 18:19:19 -05004435 writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell);
Michael Chanb81a90d2016-01-02 23:45:01 -05004436 bp->grp_info[map_idx].rx_fw_ring_id = ring->fw_ring_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04004437 }
4438
4439 if (bp->flags & BNXT_FLAG_AGG_RINGS) {
4440 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05004441 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04004442 struct bnxt_ring_struct *ring =
4443 &rxr->rx_agg_ring_struct;
Michael Chan9899bb52018-03-31 13:54:16 -04004444 u32 grp_idx = ring->grp_idx;
Michael Chanb81a90d2016-01-02 23:45:01 -05004445 u32 map_idx = grp_idx + bp->rx_nr_rings;
Michael Chanc0c050c2015-10-22 16:01:17 -04004446
4447 rc = hwrm_ring_alloc_send_msg(bp, ring,
4448 HWRM_RING_ALLOC_AGG,
Michael Chan9899bb52018-03-31 13:54:16 -04004449 map_idx);
Michael Chanc0c050c2015-10-22 16:01:17 -04004450 if (rc)
4451 goto err_out;
4452
Michael Chanb81a90d2016-01-02 23:45:01 -05004453 rxr->rx_agg_doorbell = bp->bar1 + map_idx * 0x80;
Michael Chanc0c050c2015-10-22 16:01:17 -04004454 writel(DB_KEY_RX | rxr->rx_agg_prod,
4455 rxr->rx_agg_doorbell);
Michael Chanb81a90d2016-01-02 23:45:01 -05004456 bp->grp_info[grp_idx].agg_fw_ring_id = ring->fw_ring_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04004457 }
4458 }
4459err_out:
4460 return rc;
4461}
4462
4463static int hwrm_ring_free_send_msg(struct bnxt *bp,
4464 struct bnxt_ring_struct *ring,
4465 u32 ring_type, int cmpl_ring_id)
4466{
4467 int rc;
4468 struct hwrm_ring_free_input req = {0};
4469 struct hwrm_ring_free_output *resp = bp->hwrm_cmd_resp_addr;
4470 u16 error_code;
4471
Prashant Sreedharan74608fc2016-01-28 03:11:20 -05004472 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_FREE, cmpl_ring_id, -1);
Michael Chanc0c050c2015-10-22 16:01:17 -04004473 req.ring_type = ring_type;
4474 req.ring_id = cpu_to_le16(ring->fw_ring_id);
4475
4476 mutex_lock(&bp->hwrm_cmd_lock);
4477 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4478 error_code = le16_to_cpu(resp->error_code);
4479 mutex_unlock(&bp->hwrm_cmd_lock);
4480
4481 if (rc || error_code) {
4482 switch (ring_type) {
Michael Chanbac9a7e2017-02-12 19:18:10 -05004483 case RING_FREE_REQ_RING_TYPE_L2_CMPL:
Michael Chanc0c050c2015-10-22 16:01:17 -04004484 netdev_err(bp->dev, "hwrm_ring_free cp failed. rc:%d\n",
4485 rc);
4486 return rc;
4487 case RING_FREE_REQ_RING_TYPE_RX:
4488 netdev_err(bp->dev, "hwrm_ring_free rx failed. rc:%d\n",
4489 rc);
4490 return rc;
4491 case RING_FREE_REQ_RING_TYPE_TX:
4492 netdev_err(bp->dev, "hwrm_ring_free tx failed. rc:%d\n",
4493 rc);
4494 return rc;
4495 default:
4496 netdev_err(bp->dev, "Invalid ring\n");
4497 return -1;
4498 }
4499 }
4500 return 0;
4501}
4502
Michael Chanedd0c2c2015-12-27 18:19:19 -05004503static void bnxt_hwrm_ring_free(struct bnxt *bp, bool close_path)
Michael Chanc0c050c2015-10-22 16:01:17 -04004504{
Michael Chanedd0c2c2015-12-27 18:19:19 -05004505 int i;
Michael Chanc0c050c2015-10-22 16:01:17 -04004506
4507 if (!bp->bnapi)
Michael Chanedd0c2c2015-12-27 18:19:19 -05004508 return;
Michael Chanc0c050c2015-10-22 16:01:17 -04004509
Michael Chanedd0c2c2015-12-27 18:19:19 -05004510 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05004511 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
Michael Chanedd0c2c2015-12-27 18:19:19 -05004512 struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
Michael Chanb81a90d2016-01-02 23:45:01 -05004513 u32 grp_idx = txr->bnapi->index;
4514 u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04004515
Michael Chanedd0c2c2015-12-27 18:19:19 -05004516 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
4517 hwrm_ring_free_send_msg(bp, ring,
4518 RING_FREE_REQ_RING_TYPE_TX,
4519 close_path ? cmpl_ring_id :
4520 INVALID_HW_RING_ID);
4521 ring->fw_ring_id = INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04004522 }
4523 }
4524
Michael Chanedd0c2c2015-12-27 18:19:19 -05004525 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05004526 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
Michael Chanedd0c2c2015-12-27 18:19:19 -05004527 struct bnxt_ring_struct *ring = &rxr->rx_ring_struct;
Michael Chanb81a90d2016-01-02 23:45:01 -05004528 u32 grp_idx = rxr->bnapi->index;
4529 u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04004530
Michael Chanedd0c2c2015-12-27 18:19:19 -05004531 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
4532 hwrm_ring_free_send_msg(bp, ring,
4533 RING_FREE_REQ_RING_TYPE_RX,
4534 close_path ? cmpl_ring_id :
4535 INVALID_HW_RING_ID);
4536 ring->fw_ring_id = INVALID_HW_RING_ID;
Michael Chanb81a90d2016-01-02 23:45:01 -05004537 bp->grp_info[grp_idx].rx_fw_ring_id =
4538 INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04004539 }
4540 }
4541
Michael Chanedd0c2c2015-12-27 18:19:19 -05004542 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05004543 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
Michael Chanedd0c2c2015-12-27 18:19:19 -05004544 struct bnxt_ring_struct *ring = &rxr->rx_agg_ring_struct;
Michael Chanb81a90d2016-01-02 23:45:01 -05004545 u32 grp_idx = rxr->bnapi->index;
4546 u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04004547
Michael Chanedd0c2c2015-12-27 18:19:19 -05004548 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
4549 hwrm_ring_free_send_msg(bp, ring,
4550 RING_FREE_REQ_RING_TYPE_RX,
4551 close_path ? cmpl_ring_id :
4552 INVALID_HW_RING_ID);
4553 ring->fw_ring_id = INVALID_HW_RING_ID;
Michael Chanb81a90d2016-01-02 23:45:01 -05004554 bp->grp_info[grp_idx].agg_fw_ring_id =
4555 INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04004556 }
4557 }
4558
Michael Chan9d8bc092016-12-29 12:13:33 -05004559 /* The completion rings are about to be freed. After that the
4560 * IRQ doorbell will not work anymore. So we need to disable
4561 * IRQ here.
4562 */
4563 bnxt_disable_int_sync(bp);
4564
Michael Chanedd0c2c2015-12-27 18:19:19 -05004565 for (i = 0; i < bp->cp_nr_rings; i++) {
4566 struct bnxt_napi *bnapi = bp->bnapi[i];
4567 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
4568 struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
Michael Chanc0c050c2015-10-22 16:01:17 -04004569
Michael Chanedd0c2c2015-12-27 18:19:19 -05004570 if (ring->fw_ring_id != INVALID_HW_RING_ID) {
4571 hwrm_ring_free_send_msg(bp, ring,
Michael Chanbac9a7e2017-02-12 19:18:10 -05004572 RING_FREE_REQ_RING_TYPE_L2_CMPL,
Michael Chanedd0c2c2015-12-27 18:19:19 -05004573 INVALID_HW_RING_ID);
4574 ring->fw_ring_id = INVALID_HW_RING_ID;
4575 bp->grp_info[i].cp_fw_ring_id = INVALID_HW_RING_ID;
Michael Chanc0c050c2015-10-22 16:01:17 -04004576 }
4577 }
Michael Chanc0c050c2015-10-22 16:01:17 -04004578}
4579
Michael Chan674f50a2018-01-17 03:21:09 -05004580static int bnxt_hwrm_get_rings(struct bnxt *bp)
4581{
4582 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
4583 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
4584 struct hwrm_func_qcfg_input req = {0};
4585 int rc;
4586
4587 if (bp->hwrm_spec_code < 0x10601)
4588 return 0;
4589
4590 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCFG, -1, -1);
4591 req.fid = cpu_to_le16(0xffff);
4592 mutex_lock(&bp->hwrm_cmd_lock);
4593 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4594 if (rc) {
4595 mutex_unlock(&bp->hwrm_cmd_lock);
4596 return -EIO;
4597 }
4598
4599 hw_resc->resv_tx_rings = le16_to_cpu(resp->alloc_tx_rings);
4600 if (bp->flags & BNXT_FLAG_NEW_RM) {
4601 u16 cp, stats;
4602
4603 hw_resc->resv_rx_rings = le16_to_cpu(resp->alloc_rx_rings);
4604 hw_resc->resv_hw_ring_grps =
4605 le32_to_cpu(resp->alloc_hw_ring_grps);
4606 hw_resc->resv_vnics = le16_to_cpu(resp->alloc_vnics);
4607 cp = le16_to_cpu(resp->alloc_cmpl_rings);
4608 stats = le16_to_cpu(resp->alloc_stat_ctx);
4609 cp = min_t(u16, cp, stats);
4610 hw_resc->resv_cp_rings = cp;
4611 }
4612 mutex_unlock(&bp->hwrm_cmd_lock);
4613 return 0;
4614}
4615
Michael Chan391be5c2016-12-29 12:13:41 -05004616/* Caller must hold bp->hwrm_cmd_lock */
4617int __bnxt_hwrm_get_tx_rings(struct bnxt *bp, u16 fid, int *tx_rings)
4618{
4619 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
4620 struct hwrm_func_qcfg_input req = {0};
4621 int rc;
4622
4623 if (bp->hwrm_spec_code < 0x10601)
4624 return 0;
4625
4626 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCFG, -1, -1);
4627 req.fid = cpu_to_le16(fid);
4628 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4629 if (!rc)
4630 *tx_rings = le16_to_cpu(resp->alloc_tx_rings);
4631
4632 return rc;
4633}
4634
Michael Chan4ed50ef2018-03-09 23:46:03 -05004635static void
4636__bnxt_hwrm_reserve_pf_rings(struct bnxt *bp, struct hwrm_func_cfg_input *req,
4637 int tx_rings, int rx_rings, int ring_grps,
4638 int cp_rings, int vnics)
Michael Chan391be5c2016-12-29 12:13:41 -05004639{
Michael Chan674f50a2018-01-17 03:21:09 -05004640 u32 enables = 0;
Michael Chan391be5c2016-12-29 12:13:41 -05004641
Michael Chan4ed50ef2018-03-09 23:46:03 -05004642 bnxt_hwrm_cmd_hdr_init(bp, req, HWRM_FUNC_CFG, -1, -1);
4643 req->fid = cpu_to_le16(0xffff);
Michael Chan674f50a2018-01-17 03:21:09 -05004644 enables |= tx_rings ? FUNC_CFG_REQ_ENABLES_NUM_TX_RINGS : 0;
Michael Chan4ed50ef2018-03-09 23:46:03 -05004645 req->num_tx_rings = cpu_to_le16(tx_rings);
Michael Chan674f50a2018-01-17 03:21:09 -05004646 if (bp->flags & BNXT_FLAG_NEW_RM) {
4647 enables |= rx_rings ? FUNC_CFG_REQ_ENABLES_NUM_RX_RINGS : 0;
4648 enables |= cp_rings ? FUNC_CFG_REQ_ENABLES_NUM_CMPL_RINGS |
4649 FUNC_CFG_REQ_ENABLES_NUM_STAT_CTXS : 0;
4650 enables |= ring_grps ?
4651 FUNC_CFG_REQ_ENABLES_NUM_HW_RING_GRPS : 0;
4652 enables |= vnics ? FUNC_VF_CFG_REQ_ENABLES_NUM_VNICS : 0;
4653
Michael Chan4ed50ef2018-03-09 23:46:03 -05004654 req->num_rx_rings = cpu_to_le16(rx_rings);
4655 req->num_hw_ring_grps = cpu_to_le16(ring_grps);
4656 req->num_cmpl_rings = cpu_to_le16(cp_rings);
4657 req->num_stat_ctxs = req->num_cmpl_rings;
4658 req->num_vnics = cpu_to_le16(vnics);
Michael Chan674f50a2018-01-17 03:21:09 -05004659 }
Michael Chan4ed50ef2018-03-09 23:46:03 -05004660 req->enables = cpu_to_le32(enables);
4661}
4662
4663static void
4664__bnxt_hwrm_reserve_vf_rings(struct bnxt *bp,
4665 struct hwrm_func_vf_cfg_input *req, int tx_rings,
4666 int rx_rings, int ring_grps, int cp_rings,
4667 int vnics)
4668{
4669 u32 enables = 0;
4670
4671 bnxt_hwrm_cmd_hdr_init(bp, req, HWRM_FUNC_VF_CFG, -1, -1);
4672 enables |= tx_rings ? FUNC_VF_CFG_REQ_ENABLES_NUM_TX_RINGS : 0;
4673 enables |= rx_rings ? FUNC_VF_CFG_REQ_ENABLES_NUM_RX_RINGS : 0;
4674 enables |= cp_rings ? FUNC_VF_CFG_REQ_ENABLES_NUM_CMPL_RINGS |
4675 FUNC_VF_CFG_REQ_ENABLES_NUM_STAT_CTXS : 0;
4676 enables |= ring_grps ? FUNC_VF_CFG_REQ_ENABLES_NUM_HW_RING_GRPS : 0;
4677 enables |= vnics ? FUNC_VF_CFG_REQ_ENABLES_NUM_VNICS : 0;
4678
4679 req->num_tx_rings = cpu_to_le16(tx_rings);
4680 req->num_rx_rings = cpu_to_le16(rx_rings);
4681 req->num_hw_ring_grps = cpu_to_le16(ring_grps);
4682 req->num_cmpl_rings = cpu_to_le16(cp_rings);
4683 req->num_stat_ctxs = req->num_cmpl_rings;
4684 req->num_vnics = cpu_to_le16(vnics);
4685
4686 req->enables = cpu_to_le32(enables);
4687}
4688
4689static int
4690bnxt_hwrm_reserve_pf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
4691 int ring_grps, int cp_rings, int vnics)
4692{
4693 struct hwrm_func_cfg_input req = {0};
4694 int rc;
4695
4696 __bnxt_hwrm_reserve_pf_rings(bp, &req, tx_rings, rx_rings, ring_grps,
4697 cp_rings, vnics);
4698 if (!req.enables)
Michael Chan674f50a2018-01-17 03:21:09 -05004699 return 0;
4700
Michael Chan674f50a2018-01-17 03:21:09 -05004701 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4702 if (rc)
4703 return -ENOMEM;
4704
4705 if (bp->hwrm_spec_code < 0x10601)
4706 bp->hw_resc.resv_tx_rings = tx_rings;
4707
4708 rc = bnxt_hwrm_get_rings(bp);
4709 return rc;
4710}
4711
4712static int
4713bnxt_hwrm_reserve_vf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
4714 int ring_grps, int cp_rings, int vnics)
4715{
4716 struct hwrm_func_vf_cfg_input req = {0};
Michael Chan674f50a2018-01-17 03:21:09 -05004717 int rc;
4718
4719 if (!(bp->flags & BNXT_FLAG_NEW_RM)) {
4720 bp->hw_resc.resv_tx_rings = tx_rings;
4721 return 0;
4722 }
4723
Michael Chan4ed50ef2018-03-09 23:46:03 -05004724 __bnxt_hwrm_reserve_vf_rings(bp, &req, tx_rings, rx_rings, ring_grps,
4725 cp_rings, vnics);
Michael Chan674f50a2018-01-17 03:21:09 -05004726 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4727 if (rc)
4728 return -ENOMEM;
4729
4730 rc = bnxt_hwrm_get_rings(bp);
4731 return rc;
4732}
4733
4734static int bnxt_hwrm_reserve_rings(struct bnxt *bp, int tx, int rx, int grp,
4735 int cp, int vnic)
4736{
4737 if (BNXT_PF(bp))
4738 return bnxt_hwrm_reserve_pf_rings(bp, tx, rx, grp, cp, vnic);
4739 else
4740 return bnxt_hwrm_reserve_vf_rings(bp, tx, rx, grp, cp, vnic);
4741}
4742
Michael Chan08654eb2018-03-31 13:54:17 -04004743static int bnxt_cp_rings_in_use(struct bnxt *bp)
4744{
4745 int cp = bp->cp_nr_rings;
4746 int ulp_msix, ulp_base;
4747
4748 ulp_msix = bnxt_get_ulp_msix_num(bp);
4749 if (ulp_msix) {
4750 ulp_base = bnxt_get_ulp_msix_base(bp);
4751 cp += ulp_msix;
4752 if ((ulp_base + ulp_msix) > cp)
4753 cp = ulp_base + ulp_msix;
4754 }
4755 return cp;
4756}
4757
Michael Chan4e41dc52018-03-31 13:54:19 -04004758static bool bnxt_need_reserve_rings(struct bnxt *bp)
4759{
4760 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
Michael Chanfbcfc8e2018-03-31 13:54:20 -04004761 int cp = bnxt_cp_rings_in_use(bp);
Michael Chan4e41dc52018-03-31 13:54:19 -04004762 int rx = bp->rx_nr_rings;
4763 int vnic = 1, grp = rx;
4764
4765 if (bp->hwrm_spec_code < 0x10601)
4766 return false;
4767
4768 if (hw_resc->resv_tx_rings != bp->tx_nr_rings)
4769 return true;
4770
4771 if (bp->flags & BNXT_FLAG_RFS)
4772 vnic = rx + 1;
4773 if (bp->flags & BNXT_FLAG_AGG_RINGS)
4774 rx <<= 1;
4775 if ((bp->flags & BNXT_FLAG_NEW_RM) &&
4776 (hw_resc->resv_rx_rings != rx || hw_resc->resv_cp_rings != cp ||
4777 hw_resc->resv_hw_ring_grps != grp || hw_resc->resv_vnics != vnic))
4778 return true;
4779 return false;
4780}
4781
Michael Chan674f50a2018-01-17 03:21:09 -05004782static int bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max,
4783 bool shared);
4784
4785static int __bnxt_reserve_rings(struct bnxt *bp)
4786{
4787 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
Michael Chanfbcfc8e2018-03-31 13:54:20 -04004788 int cp = bnxt_cp_rings_in_use(bp);
Michael Chan674f50a2018-01-17 03:21:09 -05004789 int tx = bp->tx_nr_rings;
4790 int rx = bp->rx_nr_rings;
Michael Chan674f50a2018-01-17 03:21:09 -05004791 int grp, rx_rings, rc;
4792 bool sh = false;
4793 int vnic = 1;
4794
Michael Chan4e41dc52018-03-31 13:54:19 -04004795 if (!bnxt_need_reserve_rings(bp))
Michael Chan391be5c2016-12-29 12:13:41 -05004796 return 0;
4797
Michael Chan674f50a2018-01-17 03:21:09 -05004798 if (bp->flags & BNXT_FLAG_SHARED_RINGS)
4799 sh = true;
4800 if (bp->flags & BNXT_FLAG_RFS)
4801 vnic = rx + 1;
4802 if (bp->flags & BNXT_FLAG_AGG_RINGS)
4803 rx <<= 1;
Michael Chan674f50a2018-01-17 03:21:09 -05004804 grp = bp->rx_nr_rings;
Michael Chan391be5c2016-12-29 12:13:41 -05004805
Michael Chan674f50a2018-01-17 03:21:09 -05004806 rc = bnxt_hwrm_reserve_rings(bp, tx, rx, grp, cp, vnic);
Michael Chan391be5c2016-12-29 12:13:41 -05004807 if (rc)
4808 return rc;
4809
Michael Chan674f50a2018-01-17 03:21:09 -05004810 tx = hw_resc->resv_tx_rings;
4811 if (bp->flags & BNXT_FLAG_NEW_RM) {
4812 rx = hw_resc->resv_rx_rings;
4813 cp = hw_resc->resv_cp_rings;
4814 grp = hw_resc->resv_hw_ring_grps;
4815 vnic = hw_resc->resv_vnics;
4816 }
4817
4818 rx_rings = rx;
4819 if (bp->flags & BNXT_FLAG_AGG_RINGS) {
4820 if (rx >= 2) {
4821 rx_rings = rx >> 1;
4822 } else {
4823 if (netif_running(bp->dev))
4824 return -ENOMEM;
4825
4826 bp->flags &= ~BNXT_FLAG_AGG_RINGS;
4827 bp->flags |= BNXT_FLAG_NO_AGG_RINGS;
4828 bp->dev->hw_features &= ~NETIF_F_LRO;
4829 bp->dev->features &= ~NETIF_F_LRO;
4830 bnxt_set_ring_params(bp);
4831 }
4832 }
4833 rx_rings = min_t(int, rx_rings, grp);
4834 rc = bnxt_trim_rings(bp, &rx_rings, &tx, cp, sh);
4835 if (bp->flags & BNXT_FLAG_AGG_RINGS)
4836 rx = rx_rings << 1;
4837 cp = sh ? max_t(int, tx, rx_rings) : tx + rx_rings;
4838 bp->tx_nr_rings = tx;
4839 bp->rx_nr_rings = rx_rings;
4840 bp->cp_nr_rings = cp;
4841
4842 if (!tx || !rx || !cp || !grp || !vnic)
4843 return -ENOMEM;
4844
Michael Chan391be5c2016-12-29 12:13:41 -05004845 return rc;
4846}
4847
Michael Chan8f23d632018-01-17 03:21:12 -05004848static int bnxt_hwrm_check_vf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004849 int ring_grps, int cp_rings, int vnics)
Michael Chan98fdbe72017-08-28 13:40:26 -04004850{
Michael Chan8f23d632018-01-17 03:21:12 -05004851 struct hwrm_func_vf_cfg_input req = {0};
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004852 u32 flags;
Michael Chan98fdbe72017-08-28 13:40:26 -04004853 int rc;
4854
Michael Chan8f23d632018-01-17 03:21:12 -05004855 if (!(bp->flags & BNXT_FLAG_NEW_RM))
Michael Chan98fdbe72017-08-28 13:40:26 -04004856 return 0;
4857
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004858 __bnxt_hwrm_reserve_vf_rings(bp, &req, tx_rings, rx_rings, ring_grps,
4859 cp_rings, vnics);
Michael Chan8f23d632018-01-17 03:21:12 -05004860 flags = FUNC_VF_CFG_REQ_FLAGS_TX_ASSETS_TEST |
4861 FUNC_VF_CFG_REQ_FLAGS_RX_ASSETS_TEST |
4862 FUNC_VF_CFG_REQ_FLAGS_CMPL_ASSETS_TEST |
4863 FUNC_VF_CFG_REQ_FLAGS_RING_GRP_ASSETS_TEST |
4864 FUNC_VF_CFG_REQ_FLAGS_STAT_CTX_ASSETS_TEST |
4865 FUNC_VF_CFG_REQ_FLAGS_VNIC_ASSETS_TEST;
Michael Chan98fdbe72017-08-28 13:40:26 -04004866
Michael Chan8f23d632018-01-17 03:21:12 -05004867 req.flags = cpu_to_le32(flags);
Michael Chan98fdbe72017-08-28 13:40:26 -04004868 rc = hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4869 if (rc)
4870 return -ENOMEM;
4871 return 0;
4872}
4873
Michael Chan8f23d632018-01-17 03:21:12 -05004874static int bnxt_hwrm_check_pf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004875 int ring_grps, int cp_rings, int vnics)
Michael Chan8f23d632018-01-17 03:21:12 -05004876{
4877 struct hwrm_func_cfg_input req = {0};
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004878 u32 flags;
Michael Chan8f23d632018-01-17 03:21:12 -05004879 int rc;
4880
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004881 __bnxt_hwrm_reserve_pf_rings(bp, &req, tx_rings, rx_rings, ring_grps,
4882 cp_rings, vnics);
Michael Chan8f23d632018-01-17 03:21:12 -05004883 flags = FUNC_CFG_REQ_FLAGS_TX_ASSETS_TEST;
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004884 if (bp->flags & BNXT_FLAG_NEW_RM)
Michael Chan8f23d632018-01-17 03:21:12 -05004885 flags |= FUNC_CFG_REQ_FLAGS_RX_ASSETS_TEST |
4886 FUNC_CFG_REQ_FLAGS_CMPL_ASSETS_TEST |
4887 FUNC_CFG_REQ_FLAGS_RING_GRP_ASSETS_TEST |
4888 FUNC_CFG_REQ_FLAGS_STAT_CTX_ASSETS_TEST |
4889 FUNC_CFG_REQ_FLAGS_VNIC_ASSETS_TEST;
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004890
Michael Chan8f23d632018-01-17 03:21:12 -05004891 req.flags = cpu_to_le32(flags);
Michael Chan8f23d632018-01-17 03:21:12 -05004892 rc = hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
4893 if (rc)
4894 return -ENOMEM;
4895 return 0;
4896}
4897
4898static int bnxt_hwrm_check_rings(struct bnxt *bp, int tx_rings, int rx_rings,
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004899 int ring_grps, int cp_rings, int vnics)
Michael Chan8f23d632018-01-17 03:21:12 -05004900{
4901 if (bp->hwrm_spec_code < 0x10801)
4902 return 0;
4903
4904 if (BNXT_PF(bp))
4905 return bnxt_hwrm_check_pf_rings(bp, tx_rings, rx_rings,
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004906 ring_grps, cp_rings, vnics);
Michael Chan8f23d632018-01-17 03:21:12 -05004907
4908 return bnxt_hwrm_check_vf_rings(bp, tx_rings, rx_rings, ring_grps,
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05004909 cp_rings, vnics);
Michael Chan8f23d632018-01-17 03:21:12 -05004910}
4911
Michael Chanf8503962017-10-26 11:51:28 -04004912static void bnxt_hwrm_set_coal_params(struct bnxt_coal *hw_coal,
Michael Chanbb053f52016-02-26 04:00:02 -05004913 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *req)
4914{
Michael Chanf8503962017-10-26 11:51:28 -04004915 u16 val, tmr, max, flags;
4916
4917 max = hw_coal->bufs_per_record * 128;
4918 if (hw_coal->budget)
4919 max = hw_coal->bufs_per_record * hw_coal->budget;
4920
4921 val = clamp_t(u16, hw_coal->coal_bufs, 1, max);
4922 req->num_cmpl_aggr_int = cpu_to_le16(val);
Michael Chanb153cbc2017-11-03 03:32:39 -04004923
4924 /* This is a 6-bit value and must not be 0, or we'll get non stop IRQ */
4925 val = min_t(u16, val, 63);
Michael Chanf8503962017-10-26 11:51:28 -04004926 req->num_cmpl_dma_aggr = cpu_to_le16(val);
4927
Michael Chanb153cbc2017-11-03 03:32:39 -04004928 /* This is a 6-bit value and must not be 0, or we'll get non stop IRQ */
4929 val = clamp_t(u16, hw_coal->coal_bufs_irq, 1, 63);
Michael Chanf8503962017-10-26 11:51:28 -04004930 req->num_cmpl_dma_aggr_during_int = cpu_to_le16(val);
4931
4932 tmr = BNXT_USEC_TO_COAL_TIMER(hw_coal->coal_ticks);
4933 tmr = max_t(u16, tmr, 1);
4934 req->int_lat_tmr_max = cpu_to_le16(tmr);
4935
4936 /* min timer set to 1/2 of interrupt timer */
4937 val = tmr / 2;
4938 req->int_lat_tmr_min = cpu_to_le16(val);
4939
4940 /* buf timer set to 1/4 of interrupt timer */
4941 val = max_t(u16, tmr / 4, 1);
4942 req->cmpl_aggr_dma_tmr = cpu_to_le16(val);
4943
4944 tmr = BNXT_USEC_TO_COAL_TIMER(hw_coal->coal_ticks_irq);
4945 tmr = max_t(u16, tmr, 1);
4946 req->cmpl_aggr_dma_tmr_during_int = cpu_to_le16(tmr);
4947
4948 flags = RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_TIMER_RESET;
4949 if (hw_coal->idle_thresh && hw_coal->coal_ticks < hw_coal->idle_thresh)
4950 flags |= RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_RING_IDLE;
Michael Chanbb053f52016-02-26 04:00:02 -05004951 req->flags = cpu_to_le16(flags);
Michael Chanbb053f52016-02-26 04:00:02 -05004952}
4953
Andy Gospodarek6a8788f2018-01-09 16:06:20 -05004954int bnxt_hwrm_set_ring_coal(struct bnxt *bp, struct bnxt_napi *bnapi)
4955{
4956 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req_rx = {0};
4957 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
4958 struct bnxt_coal coal;
4959 unsigned int grp_idx;
4960
4961 /* Tick values in micro seconds.
4962 * 1 coal_buf x bufs_per_record = 1 completion record.
4963 */
4964 memcpy(&coal, &bp->rx_coal, sizeof(struct bnxt_coal));
4965
4966 coal.coal_ticks = cpr->rx_ring_coal.coal_ticks;
4967 coal.coal_bufs = cpr->rx_ring_coal.coal_bufs;
4968
4969 if (!bnapi->rx_ring)
4970 return -ENODEV;
4971
4972 bnxt_hwrm_cmd_hdr_init(bp, &req_rx,
4973 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1);
4974
4975 bnxt_hwrm_set_coal_params(&coal, &req_rx);
4976
4977 grp_idx = bnapi->index;
4978 req_rx.ring_id = cpu_to_le16(bp->grp_info[grp_idx].cp_fw_ring_id);
4979
4980 return hwrm_send_message(bp, &req_rx, sizeof(req_rx),
4981 HWRM_CMD_TIMEOUT);
4982}
4983
Michael Chanc0c050c2015-10-22 16:01:17 -04004984int bnxt_hwrm_set_coal(struct bnxt *bp)
4985{
4986 int i, rc = 0;
Michael Chandfc9c942016-02-26 04:00:03 -05004987 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req_rx = {0},
4988 req_tx = {0}, *req;
Michael Chanc0c050c2015-10-22 16:01:17 -04004989
Michael Chandfc9c942016-02-26 04:00:03 -05004990 bnxt_hwrm_cmd_hdr_init(bp, &req_rx,
4991 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1);
4992 bnxt_hwrm_cmd_hdr_init(bp, &req_tx,
4993 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1);
Michael Chanc0c050c2015-10-22 16:01:17 -04004994
Michael Chanf8503962017-10-26 11:51:28 -04004995 bnxt_hwrm_set_coal_params(&bp->rx_coal, &req_rx);
4996 bnxt_hwrm_set_coal_params(&bp->tx_coal, &req_tx);
Michael Chanc0c050c2015-10-22 16:01:17 -04004997
4998 mutex_lock(&bp->hwrm_cmd_lock);
4999 for (i = 0; i < bp->cp_nr_rings; i++) {
Michael Chandfc9c942016-02-26 04:00:03 -05005000 struct bnxt_napi *bnapi = bp->bnapi[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04005001
Michael Chandfc9c942016-02-26 04:00:03 -05005002 req = &req_rx;
5003 if (!bnapi->rx_ring)
5004 req = &req_tx;
5005 req->ring_id = cpu_to_le16(bp->grp_info[i].cp_fw_ring_id);
5006
5007 rc = _hwrm_send_message(bp, req, sizeof(*req),
Michael Chanc0c050c2015-10-22 16:01:17 -04005008 HWRM_CMD_TIMEOUT);
5009 if (rc)
5010 break;
5011 }
5012 mutex_unlock(&bp->hwrm_cmd_lock);
5013 return rc;
5014}
5015
5016static int bnxt_hwrm_stat_ctx_free(struct bnxt *bp)
5017{
5018 int rc = 0, i;
5019 struct hwrm_stat_ctx_free_input req = {0};
5020
5021 if (!bp->bnapi)
5022 return 0;
5023
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04005024 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
5025 return 0;
5026
Michael Chanc0c050c2015-10-22 16:01:17 -04005027 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_STAT_CTX_FREE, -1, -1);
5028
5029 mutex_lock(&bp->hwrm_cmd_lock);
5030 for (i = 0; i < bp->cp_nr_rings; i++) {
5031 struct bnxt_napi *bnapi = bp->bnapi[i];
5032 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
5033
5034 if (cpr->hw_stats_ctx_id != INVALID_STATS_CTX_ID) {
5035 req.stat_ctx_id = cpu_to_le32(cpr->hw_stats_ctx_id);
5036
5037 rc = _hwrm_send_message(bp, &req, sizeof(req),
5038 HWRM_CMD_TIMEOUT);
5039 if (rc)
5040 break;
5041
5042 cpr->hw_stats_ctx_id = INVALID_STATS_CTX_ID;
5043 }
5044 }
5045 mutex_unlock(&bp->hwrm_cmd_lock);
5046 return rc;
5047}
5048
5049static int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp)
5050{
5051 int rc = 0, i;
5052 struct hwrm_stat_ctx_alloc_input req = {0};
5053 struct hwrm_stat_ctx_alloc_output *resp = bp->hwrm_cmd_resp_addr;
5054
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04005055 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
5056 return 0;
5057
Michael Chanc0c050c2015-10-22 16:01:17 -04005058 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_STAT_CTX_ALLOC, -1, -1);
5059
Michael Chan51f30782016-07-01 18:46:29 -04005060 req.update_period_ms = cpu_to_le32(bp->stats_coal_ticks / 1000);
Michael Chanc0c050c2015-10-22 16:01:17 -04005061
5062 mutex_lock(&bp->hwrm_cmd_lock);
5063 for (i = 0; i < bp->cp_nr_rings; i++) {
5064 struct bnxt_napi *bnapi = bp->bnapi[i];
5065 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
5066
5067 req.stats_dma_addr = cpu_to_le64(cpr->hw_stats_map);
5068
5069 rc = _hwrm_send_message(bp, &req, sizeof(req),
5070 HWRM_CMD_TIMEOUT);
5071 if (rc)
5072 break;
5073
5074 cpr->hw_stats_ctx_id = le32_to_cpu(resp->stat_ctx_id);
5075
5076 bp->grp_info[i].fw_stats_ctx = cpr->hw_stats_ctx_id;
5077 }
5078 mutex_unlock(&bp->hwrm_cmd_lock);
Pan Bian89aa8442016-12-03 17:56:17 +08005079 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04005080}
5081
Michael Chancf6645f2016-06-13 02:25:28 -04005082static int bnxt_hwrm_func_qcfg(struct bnxt *bp)
5083{
5084 struct hwrm_func_qcfg_input req = {0};
Satish Baddipadige567b2ab2016-06-13 02:25:31 -04005085 struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
Michael Chan9315edc2017-07-24 12:34:25 -04005086 u16 flags;
Michael Chancf6645f2016-06-13 02:25:28 -04005087 int rc;
5088
5089 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCFG, -1, -1);
5090 req.fid = cpu_to_le16(0xffff);
5091 mutex_lock(&bp->hwrm_cmd_lock);
5092 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5093 if (rc)
5094 goto func_qcfg_exit;
5095
5096#ifdef CONFIG_BNXT_SRIOV
5097 if (BNXT_VF(bp)) {
Michael Chancf6645f2016-06-13 02:25:28 -04005098 struct bnxt_vf_info *vf = &bp->vf;
5099
5100 vf->vlan = le16_to_cpu(resp->vlan) & VLAN_VID_MASK;
5101 }
5102#endif
Michael Chan9315edc2017-07-24 12:34:25 -04005103 flags = le16_to_cpu(resp->flags);
5104 if (flags & (FUNC_QCFG_RESP_FLAGS_FW_DCBX_AGENT_ENABLED |
5105 FUNC_QCFG_RESP_FLAGS_FW_LLDP_AGENT_ENABLED)) {
5106 bp->flags |= BNXT_FLAG_FW_LLDP_AGENT;
5107 if (flags & FUNC_QCFG_RESP_FLAGS_FW_DCBX_AGENT_ENABLED)
5108 bp->flags |= BNXT_FLAG_FW_DCBX_AGENT;
Deepak Khungar9e54e322017-04-21 20:11:26 -04005109 }
Michael Chan9315edc2017-07-24 12:34:25 -04005110 if (BNXT_PF(bp) && (flags & FUNC_QCFG_RESP_FLAGS_MULTI_HOST))
5111 bp->flags |= BNXT_FLAG_MULTI_HOST;
Michael Chanbc39f882017-03-08 18:44:34 -05005112
Satish Baddipadige567b2ab2016-06-13 02:25:31 -04005113 switch (resp->port_partition_type) {
5114 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_0:
5115 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_5:
5116 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR2_0:
5117 bp->port_partition_type = resp->port_partition_type;
5118 break;
5119 }
Michael Chan32e8239c2017-07-24 12:34:21 -04005120 if (bp->hwrm_spec_code < 0x10707 ||
5121 resp->evb_mode == FUNC_QCFG_RESP_EVB_MODE_VEB)
5122 bp->br_mode = BRIDGE_MODE_VEB;
5123 else if (resp->evb_mode == FUNC_QCFG_RESP_EVB_MODE_VEPA)
5124 bp->br_mode = BRIDGE_MODE_VEPA;
5125 else
5126 bp->br_mode = BRIDGE_MODE_UNDEF;
Michael Chancf6645f2016-06-13 02:25:28 -04005127
Michael Chan7eb9bb32017-10-26 11:51:25 -04005128 bp->max_mtu = le16_to_cpu(resp->max_mtu_configured);
5129 if (!bp->max_mtu)
5130 bp->max_mtu = BNXT_MAX_MTU;
5131
Michael Chancf6645f2016-06-13 02:25:28 -04005132func_qcfg_exit:
5133 mutex_unlock(&bp->hwrm_cmd_lock);
5134 return rc;
5135}
5136
Michael Chandb4723b2018-03-31 13:54:13 -04005137int bnxt_hwrm_func_resc_qcaps(struct bnxt *bp, bool all)
Michael Chanbe0dd9c2018-01-17 03:21:07 -05005138{
5139 struct hwrm_func_resource_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
5140 struct hwrm_func_resource_qcaps_input req = {0};
5141 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
5142 int rc;
5143
5144 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_RESOURCE_QCAPS, -1, -1);
5145 req.fid = cpu_to_le16(0xffff);
5146
5147 mutex_lock(&bp->hwrm_cmd_lock);
5148 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5149 if (rc) {
5150 rc = -EIO;
5151 goto hwrm_func_resc_qcaps_exit;
5152 }
5153
Michael Chandb4723b2018-03-31 13:54:13 -04005154 hw_resc->max_tx_sch_inputs = le16_to_cpu(resp->max_tx_scheduler_inputs);
5155 if (!all)
5156 goto hwrm_func_resc_qcaps_exit;
5157
Michael Chanbe0dd9c2018-01-17 03:21:07 -05005158 hw_resc->min_rsscos_ctxs = le16_to_cpu(resp->min_rsscos_ctx);
5159 hw_resc->max_rsscos_ctxs = le16_to_cpu(resp->max_rsscos_ctx);
5160 hw_resc->min_cp_rings = le16_to_cpu(resp->min_cmpl_rings);
5161 hw_resc->max_cp_rings = le16_to_cpu(resp->max_cmpl_rings);
5162 hw_resc->min_tx_rings = le16_to_cpu(resp->min_tx_rings);
5163 hw_resc->max_tx_rings = le16_to_cpu(resp->max_tx_rings);
5164 hw_resc->min_rx_rings = le16_to_cpu(resp->min_rx_rings);
5165 hw_resc->max_rx_rings = le16_to_cpu(resp->max_rx_rings);
5166 hw_resc->min_hw_ring_grps = le16_to_cpu(resp->min_hw_ring_grps);
5167 hw_resc->max_hw_ring_grps = le16_to_cpu(resp->max_hw_ring_grps);
5168 hw_resc->min_l2_ctxs = le16_to_cpu(resp->min_l2_ctxs);
5169 hw_resc->max_l2_ctxs = le16_to_cpu(resp->max_l2_ctxs);
5170 hw_resc->min_vnics = le16_to_cpu(resp->min_vnics);
5171 hw_resc->max_vnics = le16_to_cpu(resp->max_vnics);
5172 hw_resc->min_stat_ctxs = le16_to_cpu(resp->min_stat_ctx);
5173 hw_resc->max_stat_ctxs = le16_to_cpu(resp->max_stat_ctx);
5174
Michael Chan4673d662018-01-17 03:21:11 -05005175 if (BNXT_PF(bp)) {
5176 struct bnxt_pf_info *pf = &bp->pf;
5177
5178 pf->vf_resv_strategy =
5179 le16_to_cpu(resp->vf_reservation_strategy);
5180 if (pf->vf_resv_strategy > BNXT_VF_RESV_STRATEGY_MINIMAL)
5181 pf->vf_resv_strategy = BNXT_VF_RESV_STRATEGY_MAXIMAL;
5182 }
Michael Chanbe0dd9c2018-01-17 03:21:07 -05005183hwrm_func_resc_qcaps_exit:
5184 mutex_unlock(&bp->hwrm_cmd_lock);
5185 return rc;
5186}
5187
5188static int __bnxt_hwrm_func_qcaps(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04005189{
5190 int rc = 0;
5191 struct hwrm_func_qcaps_input req = {0};
5192 struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
Michael Chan6a4f2942018-01-17 03:21:06 -05005193 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
5194 u32 flags;
Michael Chanc0c050c2015-10-22 16:01:17 -04005195
5196 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCAPS, -1, -1);
5197 req.fid = cpu_to_le16(0xffff);
5198
5199 mutex_lock(&bp->hwrm_cmd_lock);
5200 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5201 if (rc)
5202 goto hwrm_func_qcaps_exit;
5203
Michael Chan6a4f2942018-01-17 03:21:06 -05005204 flags = le32_to_cpu(resp->flags);
5205 if (flags & FUNC_QCAPS_RESP_FLAGS_ROCE_V1_SUPPORTED)
Michael Chane4060d32016-12-07 00:26:19 -05005206 bp->flags |= BNXT_FLAG_ROCEV1_CAP;
Michael Chan6a4f2942018-01-17 03:21:06 -05005207 if (flags & FUNC_QCAPS_RESP_FLAGS_ROCE_V2_SUPPORTED)
Michael Chane4060d32016-12-07 00:26:19 -05005208 bp->flags |= BNXT_FLAG_ROCEV2_CAP;
5209
Michael Chan7cc5a202016-09-19 03:58:05 -04005210 bp->tx_push_thresh = 0;
Michael Chan6a4f2942018-01-17 03:21:06 -05005211 if (flags & FUNC_QCAPS_RESP_FLAGS_PUSH_MODE_SUPPORTED)
Michael Chan7cc5a202016-09-19 03:58:05 -04005212 bp->tx_push_thresh = BNXT_TX_PUSH_THRESH;
5213
Michael Chan6a4f2942018-01-17 03:21:06 -05005214 hw_resc->max_rsscos_ctxs = le16_to_cpu(resp->max_rsscos_ctx);
5215 hw_resc->max_cp_rings = le16_to_cpu(resp->max_cmpl_rings);
5216 hw_resc->max_tx_rings = le16_to_cpu(resp->max_tx_rings);
5217 hw_resc->max_rx_rings = le16_to_cpu(resp->max_rx_rings);
5218 hw_resc->max_hw_ring_grps = le32_to_cpu(resp->max_hw_ring_grps);
5219 if (!hw_resc->max_hw_ring_grps)
5220 hw_resc->max_hw_ring_grps = hw_resc->max_tx_rings;
5221 hw_resc->max_l2_ctxs = le16_to_cpu(resp->max_l2_ctxs);
5222 hw_resc->max_vnics = le16_to_cpu(resp->max_vnics);
5223 hw_resc->max_stat_ctxs = le16_to_cpu(resp->max_stat_ctx);
5224
Michael Chanc0c050c2015-10-22 16:01:17 -04005225 if (BNXT_PF(bp)) {
5226 struct bnxt_pf_info *pf = &bp->pf;
5227
5228 pf->fw_fid = le16_to_cpu(resp->fid);
5229 pf->port_id = le16_to_cpu(resp->port_id);
Michael Chan87027db2016-07-01 18:46:28 -04005230 bp->dev->dev_port = pf->port_id;
Michael Chan11f15ed2016-04-05 14:08:55 -04005231 memcpy(pf->mac_addr, resp->mac_address, ETH_ALEN);
Michael Chanc0c050c2015-10-22 16:01:17 -04005232 pf->first_vf_id = le16_to_cpu(resp->first_vf_id);
5233 pf->max_vfs = le16_to_cpu(resp->max_vfs);
5234 pf->max_encap_records = le32_to_cpu(resp->max_encap_records);
5235 pf->max_decap_records = le32_to_cpu(resp->max_decap_records);
5236 pf->max_tx_em_flows = le32_to_cpu(resp->max_tx_em_flows);
5237 pf->max_tx_wm_flows = le32_to_cpu(resp->max_tx_wm_flows);
5238 pf->max_rx_em_flows = le32_to_cpu(resp->max_rx_em_flows);
5239 pf->max_rx_wm_flows = le32_to_cpu(resp->max_rx_wm_flows);
Michael Chan6a4f2942018-01-17 03:21:06 -05005240 if (flags & FUNC_QCAPS_RESP_FLAGS_WOL_MAGICPKT_SUPPORTED)
Michael Chanc1ef1462017-04-04 18:14:07 -04005241 bp->flags |= BNXT_FLAG_WOL_CAP;
Michael Chanc0c050c2015-10-22 16:01:17 -04005242 } else {
Michael Chan379a80a2015-10-23 15:06:19 -04005243#ifdef CONFIG_BNXT_SRIOV
Michael Chanc0c050c2015-10-22 16:01:17 -04005244 struct bnxt_vf_info *vf = &bp->vf;
5245
5246 vf->fw_fid = le16_to_cpu(resp->fid);
Michael Chan7cc5a202016-09-19 03:58:05 -04005247 memcpy(vf->mac_addr, resp->mac_address, ETH_ALEN);
Michael Chan379a80a2015-10-23 15:06:19 -04005248#endif
Michael Chanc0c050c2015-10-22 16:01:17 -04005249 }
5250
Michael Chanc0c050c2015-10-22 16:01:17 -04005251hwrm_func_qcaps_exit:
5252 mutex_unlock(&bp->hwrm_cmd_lock);
5253 return rc;
5254}
5255
Michael Chanbe0dd9c2018-01-17 03:21:07 -05005256static int bnxt_hwrm_func_qcaps(struct bnxt *bp)
5257{
5258 int rc;
5259
5260 rc = __bnxt_hwrm_func_qcaps(bp);
5261 if (rc)
5262 return rc;
5263 if (bp->hwrm_spec_code >= 0x10803) {
Michael Chandb4723b2018-03-31 13:54:13 -04005264 rc = bnxt_hwrm_func_resc_qcaps(bp, true);
Michael Chanbe0dd9c2018-01-17 03:21:07 -05005265 if (!rc)
5266 bp->flags |= BNXT_FLAG_NEW_RM;
5267 }
5268 return 0;
5269}
5270
Michael Chanc0c050c2015-10-22 16:01:17 -04005271static int bnxt_hwrm_func_reset(struct bnxt *bp)
5272{
5273 struct hwrm_func_reset_input req = {0};
5274
5275 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_RESET, -1, -1);
5276 req.enables = 0;
5277
5278 return hwrm_send_message(bp, &req, sizeof(req), HWRM_RESET_TIMEOUT);
5279}
5280
5281static int bnxt_hwrm_queue_qportcfg(struct bnxt *bp)
5282{
5283 int rc = 0;
5284 struct hwrm_queue_qportcfg_input req = {0};
5285 struct hwrm_queue_qportcfg_output *resp = bp->hwrm_cmd_resp_addr;
5286 u8 i, *qptr;
5287
5288 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_QUEUE_QPORTCFG, -1, -1);
5289
5290 mutex_lock(&bp->hwrm_cmd_lock);
5291 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5292 if (rc)
5293 goto qportcfg_exit;
5294
5295 if (!resp->max_configurable_queues) {
5296 rc = -EINVAL;
5297 goto qportcfg_exit;
5298 }
5299 bp->max_tc = resp->max_configurable_queues;
Michael Chan87c374d2016-12-02 21:17:16 -05005300 bp->max_lltc = resp->max_configurable_lossless_queues;
Michael Chanc0c050c2015-10-22 16:01:17 -04005301 if (bp->max_tc > BNXT_MAX_QUEUE)
5302 bp->max_tc = BNXT_MAX_QUEUE;
5303
Michael Chan441cabb2016-09-19 03:58:02 -04005304 if (resp->queue_cfg_info & QUEUE_QPORTCFG_RESP_QUEUE_CFG_INFO_ASYM_CFG)
5305 bp->max_tc = 1;
5306
Michael Chan87c374d2016-12-02 21:17:16 -05005307 if (bp->max_lltc > bp->max_tc)
5308 bp->max_lltc = bp->max_tc;
5309
Michael Chanc0c050c2015-10-22 16:01:17 -04005310 qptr = &resp->queue_id0;
5311 for (i = 0; i < bp->max_tc; i++) {
5312 bp->q_info[i].queue_id = *qptr++;
5313 bp->q_info[i].queue_profile = *qptr++;
Michael Chan2e8ef772018-04-26 17:44:31 -04005314 bp->tc_to_qidx[i] = i;
Michael Chanc0c050c2015-10-22 16:01:17 -04005315 }
5316
5317qportcfg_exit:
5318 mutex_unlock(&bp->hwrm_cmd_lock);
5319 return rc;
5320}
5321
5322static int bnxt_hwrm_ver_get(struct bnxt *bp)
5323{
5324 int rc;
5325 struct hwrm_ver_get_input req = {0};
5326 struct hwrm_ver_get_output *resp = bp->hwrm_cmd_resp_addr;
Deepak Khungare605db82017-05-29 19:06:04 -04005327 u32 dev_caps_cfg;
Michael Chanc0c050c2015-10-22 16:01:17 -04005328
Michael Chane6ef2692016-03-28 19:46:05 -04005329 bp->hwrm_max_req_len = HWRM_MAX_REQ_LEN;
Michael Chanc0c050c2015-10-22 16:01:17 -04005330 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VER_GET, -1, -1);
5331 req.hwrm_intf_maj = HWRM_VERSION_MAJOR;
5332 req.hwrm_intf_min = HWRM_VERSION_MINOR;
5333 req.hwrm_intf_upd = HWRM_VERSION_UPDATE;
5334 mutex_lock(&bp->hwrm_cmd_lock);
5335 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5336 if (rc)
5337 goto hwrm_ver_get_exit;
5338
5339 memcpy(&bp->ver_resp, resp, sizeof(struct hwrm_ver_get_output));
5340
Michael Chan894aa692018-01-17 03:21:03 -05005341 bp->hwrm_spec_code = resp->hwrm_intf_maj_8b << 16 |
5342 resp->hwrm_intf_min_8b << 8 |
5343 resp->hwrm_intf_upd_8b;
5344 if (resp->hwrm_intf_maj_8b < 1) {
Michael Chanc1935542015-12-27 18:19:28 -05005345 netdev_warn(bp->dev, "HWRM interface %d.%d.%d is older than 1.0.0.\n",
Michael Chan894aa692018-01-17 03:21:03 -05005346 resp->hwrm_intf_maj_8b, resp->hwrm_intf_min_8b,
5347 resp->hwrm_intf_upd_8b);
Michael Chanc1935542015-12-27 18:19:28 -05005348 netdev_warn(bp->dev, "Please update firmware with HWRM interface 1.0.0 or newer.\n");
Michael Chanc0c050c2015-10-22 16:01:17 -04005349 }
Michael Chan431aa1e2017-10-26 11:51:23 -04005350 snprintf(bp->fw_ver_str, BC_HWRM_STR_LEN, "%d.%d.%d.%d",
Michael Chan894aa692018-01-17 03:21:03 -05005351 resp->hwrm_fw_maj_8b, resp->hwrm_fw_min_8b,
5352 resp->hwrm_fw_bld_8b, resp->hwrm_fw_rsvd_8b);
Michael Chanc0c050c2015-10-22 16:01:17 -04005353
Michael Chanff4fe812016-02-26 04:00:04 -05005354 bp->hwrm_cmd_timeout = le16_to_cpu(resp->def_req_timeout);
5355 if (!bp->hwrm_cmd_timeout)
5356 bp->hwrm_cmd_timeout = DFLT_HWRM_CMD_TIMEOUT;
5357
Michael Chan894aa692018-01-17 03:21:03 -05005358 if (resp->hwrm_intf_maj_8b >= 1)
Michael Chane6ef2692016-03-28 19:46:05 -04005359 bp->hwrm_max_req_len = le16_to_cpu(resp->max_req_win_len);
5360
Michael Chan659c8052016-06-13 02:25:33 -04005361 bp->chip_num = le16_to_cpu(resp->chip_num);
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04005362 if (bp->chip_num == CHIP_NUM_58700 && !resp->chip_rev &&
5363 !resp->chip_metal)
5364 bp->flags |= BNXT_FLAG_CHIP_NITRO_A0;
Michael Chan659c8052016-06-13 02:25:33 -04005365
Deepak Khungare605db82017-05-29 19:06:04 -04005366 dev_caps_cfg = le32_to_cpu(resp->dev_caps_cfg);
5367 if ((dev_caps_cfg & VER_GET_RESP_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED) &&
5368 (dev_caps_cfg & VER_GET_RESP_DEV_CAPS_CFG_SHORT_CMD_REQUIRED))
5369 bp->flags |= BNXT_FLAG_SHORT_CMD;
5370
Michael Chanc0c050c2015-10-22 16:01:17 -04005371hwrm_ver_get_exit:
5372 mutex_unlock(&bp->hwrm_cmd_lock);
5373 return rc;
5374}
5375
Rob Swindell5ac67d82016-09-19 03:58:03 -04005376int bnxt_hwrm_fw_set_time(struct bnxt *bp)
5377{
5378 struct hwrm_fw_set_time_input req = {0};
Arnd Bergmann7dfaa7b2017-11-06 15:04:39 +01005379 struct tm tm;
5380 time64_t now = ktime_get_real_seconds();
Rob Swindell5ac67d82016-09-19 03:58:03 -04005381
5382 if (bp->hwrm_spec_code < 0x10400)
5383 return -EOPNOTSUPP;
5384
Arnd Bergmann7dfaa7b2017-11-06 15:04:39 +01005385 time64_to_tm(now, 0, &tm);
Rob Swindell5ac67d82016-09-19 03:58:03 -04005386 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_SET_TIME, -1, -1);
5387 req.year = cpu_to_le16(1900 + tm.tm_year);
5388 req.month = 1 + tm.tm_mon;
5389 req.day = tm.tm_mday;
5390 req.hour = tm.tm_hour;
5391 req.minute = tm.tm_min;
5392 req.second = tm.tm_sec;
5393 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5394}
5395
Michael Chan3bdf56c2016-03-07 15:38:45 -05005396static int bnxt_hwrm_port_qstats(struct bnxt *bp)
5397{
5398 int rc;
5399 struct bnxt_pf_info *pf = &bp->pf;
5400 struct hwrm_port_qstats_input req = {0};
5401
5402 if (!(bp->flags & BNXT_FLAG_PORT_STATS))
5403 return 0;
5404
5405 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_QSTATS, -1, -1);
5406 req.port_id = cpu_to_le16(pf->port_id);
5407 req.tx_stat_host_addr = cpu_to_le64(bp->hw_tx_port_stats_map);
5408 req.rx_stat_host_addr = cpu_to_le64(bp->hw_rx_port_stats_map);
5409 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5410 return rc;
5411}
5412
Vasundhara Volam00db3cb2018-03-31 13:54:12 -04005413static int bnxt_hwrm_port_qstats_ext(struct bnxt *bp)
5414{
5415 struct hwrm_port_qstats_ext_input req = {0};
5416 struct bnxt_pf_info *pf = &bp->pf;
5417
5418 if (!(bp->flags & BNXT_FLAG_PORT_STATS_EXT))
5419 return 0;
5420
5421 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_QSTATS_EXT, -1, -1);
5422 req.port_id = cpu_to_le16(pf->port_id);
5423 req.rx_stat_size = cpu_to_le16(sizeof(struct rx_port_stats_ext));
5424 req.rx_stat_host_addr = cpu_to_le64(bp->hw_rx_port_stats_ext_map);
5425 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5426}
5427
Michael Chanc0c050c2015-10-22 16:01:17 -04005428static void bnxt_hwrm_free_tunnel_ports(struct bnxt *bp)
5429{
5430 if (bp->vxlan_port_cnt) {
5431 bnxt_hwrm_tunnel_dst_port_free(
5432 bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN);
5433 }
5434 bp->vxlan_port_cnt = 0;
5435 if (bp->nge_port_cnt) {
5436 bnxt_hwrm_tunnel_dst_port_free(
5437 bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE);
5438 }
5439 bp->nge_port_cnt = 0;
5440}
5441
5442static int bnxt_set_tpa(struct bnxt *bp, bool set_tpa)
5443{
5444 int rc, i;
5445 u32 tpa_flags = 0;
5446
5447 if (set_tpa)
5448 tpa_flags = bp->flags & BNXT_FLAG_TPA;
5449 for (i = 0; i < bp->nr_vnics; i++) {
5450 rc = bnxt_hwrm_vnic_set_tpa(bp, i, tpa_flags);
5451 if (rc) {
5452 netdev_err(bp->dev, "hwrm vnic set tpa failure rc for vnic %d: %x\n",
Sankar Patchineelam23e12c82017-03-28 19:47:30 -04005453 i, rc);
Michael Chanc0c050c2015-10-22 16:01:17 -04005454 return rc;
5455 }
5456 }
5457 return 0;
5458}
5459
5460static void bnxt_hwrm_clear_vnic_rss(struct bnxt *bp)
5461{
5462 int i;
5463
5464 for (i = 0; i < bp->nr_vnics; i++)
5465 bnxt_hwrm_vnic_set_rss(bp, i, false);
5466}
5467
5468static void bnxt_hwrm_resource_free(struct bnxt *bp, bool close_path,
5469 bool irq_re_init)
5470{
5471 if (bp->vnic_info) {
5472 bnxt_hwrm_clear_vnic_filter(bp);
5473 /* clear all RSS setting before free vnic ctx */
5474 bnxt_hwrm_clear_vnic_rss(bp);
5475 bnxt_hwrm_vnic_ctx_free(bp);
5476 /* before free the vnic, undo the vnic tpa settings */
5477 if (bp->flags & BNXT_FLAG_TPA)
5478 bnxt_set_tpa(bp, false);
5479 bnxt_hwrm_vnic_free(bp);
5480 }
5481 bnxt_hwrm_ring_free(bp, close_path);
5482 bnxt_hwrm_ring_grp_free(bp);
5483 if (irq_re_init) {
5484 bnxt_hwrm_stat_ctx_free(bp);
5485 bnxt_hwrm_free_tunnel_ports(bp);
5486 }
5487}
5488
Michael Chan39d8ba22017-07-24 12:34:22 -04005489static int bnxt_hwrm_set_br_mode(struct bnxt *bp, u16 br_mode)
5490{
5491 struct hwrm_func_cfg_input req = {0};
5492 int rc;
5493
5494 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1);
5495 req.fid = cpu_to_le16(0xffff);
5496 req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_EVB_MODE);
5497 if (br_mode == BRIDGE_MODE_VEB)
5498 req.evb_mode = FUNC_CFG_REQ_EVB_MODE_VEB;
5499 else if (br_mode == BRIDGE_MODE_VEPA)
5500 req.evb_mode = FUNC_CFG_REQ_EVB_MODE_VEPA;
5501 else
5502 return -EINVAL;
5503 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5504 if (rc)
5505 rc = -EIO;
5506 return rc;
5507}
5508
Michael Chanc3480a62018-01-17 03:21:15 -05005509static int bnxt_hwrm_set_cache_line_size(struct bnxt *bp, int size)
5510{
5511 struct hwrm_func_cfg_input req = {0};
5512 int rc;
5513
5514 if (BNXT_VF(bp) || bp->hwrm_spec_code < 0x10803)
5515 return 0;
5516
5517 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1);
5518 req.fid = cpu_to_le16(0xffff);
5519 req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_CACHE_LINESIZE);
Michael Chand4f52de02018-03-31 13:54:06 -04005520 req.options = FUNC_CFG_REQ_OPTIONS_CACHE_LINESIZE_SIZE_64;
Michael Chanc3480a62018-01-17 03:21:15 -05005521 if (size == 128)
Michael Chand4f52de02018-03-31 13:54:06 -04005522 req.options = FUNC_CFG_REQ_OPTIONS_CACHE_LINESIZE_SIZE_128;
Michael Chanc3480a62018-01-17 03:21:15 -05005523
5524 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
5525 if (rc)
5526 rc = -EIO;
5527 return rc;
5528}
5529
Michael Chanc0c050c2015-10-22 16:01:17 -04005530static int bnxt_setup_vnic(struct bnxt *bp, u16 vnic_id)
5531{
Michael Chanae10ae72016-12-29 12:13:38 -05005532 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
Michael Chanc0c050c2015-10-22 16:01:17 -04005533 int rc;
5534
Michael Chanae10ae72016-12-29 12:13:38 -05005535 if (vnic->flags & BNXT_VNIC_RFS_NEW_RSS_FLAG)
5536 goto skip_rss_ctx;
5537
Michael Chanc0c050c2015-10-22 16:01:17 -04005538 /* allocate context for vnic */
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04005539 rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic_id, 0);
Michael Chanc0c050c2015-10-22 16:01:17 -04005540 if (rc) {
5541 netdev_err(bp->dev, "hwrm vnic %d alloc failure rc: %x\n",
5542 vnic_id, rc);
5543 goto vnic_setup_err;
5544 }
5545 bp->rsscos_nr_ctxs++;
5546
Prashant Sreedharan94ce9ca2016-07-18 07:15:21 -04005547 if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
5548 rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic_id, 1);
5549 if (rc) {
5550 netdev_err(bp->dev, "hwrm vnic %d cos ctx alloc failure rc: %x\n",
5551 vnic_id, rc);
5552 goto vnic_setup_err;
5553 }
5554 bp->rsscos_nr_ctxs++;
5555 }
5556
Michael Chanae10ae72016-12-29 12:13:38 -05005557skip_rss_ctx:
Michael Chanc0c050c2015-10-22 16:01:17 -04005558 /* configure default vnic, ring grp */
5559 rc = bnxt_hwrm_vnic_cfg(bp, vnic_id);
5560 if (rc) {
5561 netdev_err(bp->dev, "hwrm vnic %d cfg failure rc: %x\n",
5562 vnic_id, rc);
5563 goto vnic_setup_err;
5564 }
5565
5566 /* Enable RSS hashing on vnic */
5567 rc = bnxt_hwrm_vnic_set_rss(bp, vnic_id, true);
5568 if (rc) {
5569 netdev_err(bp->dev, "hwrm vnic %d set rss failure rc: %x\n",
5570 vnic_id, rc);
5571 goto vnic_setup_err;
5572 }
5573
5574 if (bp->flags & BNXT_FLAG_AGG_RINGS) {
5575 rc = bnxt_hwrm_vnic_set_hds(bp, vnic_id);
5576 if (rc) {
5577 netdev_err(bp->dev, "hwrm vnic %d set hds failure rc: %x\n",
5578 vnic_id, rc);
5579 }
5580 }
5581
5582vnic_setup_err:
5583 return rc;
5584}
5585
5586static int bnxt_alloc_rfs_vnics(struct bnxt *bp)
5587{
5588#ifdef CONFIG_RFS_ACCEL
5589 int i, rc = 0;
5590
5591 for (i = 0; i < bp->rx_nr_rings; i++) {
Michael Chanae10ae72016-12-29 12:13:38 -05005592 struct bnxt_vnic_info *vnic;
Michael Chanc0c050c2015-10-22 16:01:17 -04005593 u16 vnic_id = i + 1;
5594 u16 ring_id = i;
5595
5596 if (vnic_id >= bp->nr_vnics)
5597 break;
5598
Michael Chanae10ae72016-12-29 12:13:38 -05005599 vnic = &bp->vnic_info[vnic_id];
5600 vnic->flags |= BNXT_VNIC_RFS_FLAG;
5601 if (bp->flags & BNXT_FLAG_NEW_RSS_CAP)
5602 vnic->flags |= BNXT_VNIC_RFS_NEW_RSS_FLAG;
Michael Chanb81a90d2016-01-02 23:45:01 -05005603 rc = bnxt_hwrm_vnic_alloc(bp, vnic_id, ring_id, 1);
Michael Chanc0c050c2015-10-22 16:01:17 -04005604 if (rc) {
5605 netdev_err(bp->dev, "hwrm vnic %d alloc failure rc: %x\n",
5606 vnic_id, rc);
5607 break;
5608 }
5609 rc = bnxt_setup_vnic(bp, vnic_id);
5610 if (rc)
5611 break;
5612 }
5613 return rc;
5614#else
5615 return 0;
5616#endif
5617}
5618
Michael Chan17c71ac2016-07-01 18:46:27 -04005619/* Allow PF and VF with default VLAN to be in promiscuous mode */
5620static bool bnxt_promisc_ok(struct bnxt *bp)
5621{
5622#ifdef CONFIG_BNXT_SRIOV
5623 if (BNXT_VF(bp) && !bp->vf.vlan)
5624 return false;
5625#endif
5626 return true;
5627}
5628
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04005629static int bnxt_setup_nitroa0_vnic(struct bnxt *bp)
5630{
5631 unsigned int rc = 0;
5632
5633 rc = bnxt_hwrm_vnic_alloc(bp, 1, bp->rx_nr_rings - 1, 1);
5634 if (rc) {
5635 netdev_err(bp->dev, "Cannot allocate special vnic for NS2 A0: %x\n",
5636 rc);
5637 return rc;
5638 }
5639
5640 rc = bnxt_hwrm_vnic_cfg(bp, 1);
5641 if (rc) {
5642 netdev_err(bp->dev, "Cannot allocate special vnic for NS2 A0: %x\n",
5643 rc);
5644 return rc;
5645 }
5646 return rc;
5647}
5648
Michael Chanb664f002015-12-02 01:54:08 -05005649static int bnxt_cfg_rx_mode(struct bnxt *);
Michael Chan7d2837d2016-05-04 16:56:44 -04005650static bool bnxt_mc_list_updated(struct bnxt *, u32 *);
Michael Chanb664f002015-12-02 01:54:08 -05005651
Michael Chanc0c050c2015-10-22 16:01:17 -04005652static int bnxt_init_chip(struct bnxt *bp, bool irq_re_init)
5653{
Michael Chan7d2837d2016-05-04 16:56:44 -04005654 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
Michael Chanc0c050c2015-10-22 16:01:17 -04005655 int rc = 0;
Prashant Sreedharan76595192016-07-18 07:15:22 -04005656 unsigned int rx_nr_rings = bp->rx_nr_rings;
Michael Chanc0c050c2015-10-22 16:01:17 -04005657
5658 if (irq_re_init) {
5659 rc = bnxt_hwrm_stat_ctx_alloc(bp);
5660 if (rc) {
5661 netdev_err(bp->dev, "hwrm stat ctx alloc failure rc: %x\n",
5662 rc);
5663 goto err_out;
5664 }
5665 }
5666
5667 rc = bnxt_hwrm_ring_alloc(bp);
5668 if (rc) {
5669 netdev_err(bp->dev, "hwrm ring alloc failure rc: %x\n", rc);
5670 goto err_out;
5671 }
5672
5673 rc = bnxt_hwrm_ring_grp_alloc(bp);
5674 if (rc) {
5675 netdev_err(bp->dev, "hwrm_ring_grp alloc failure: %x\n", rc);
5676 goto err_out;
5677 }
5678
Prashant Sreedharan76595192016-07-18 07:15:22 -04005679 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
5680 rx_nr_rings--;
5681
Michael Chanc0c050c2015-10-22 16:01:17 -04005682 /* default vnic 0 */
Prashant Sreedharan76595192016-07-18 07:15:22 -04005683 rc = bnxt_hwrm_vnic_alloc(bp, 0, 0, rx_nr_rings);
Michael Chanc0c050c2015-10-22 16:01:17 -04005684 if (rc) {
5685 netdev_err(bp->dev, "hwrm vnic alloc failure rc: %x\n", rc);
5686 goto err_out;
5687 }
5688
5689 rc = bnxt_setup_vnic(bp, 0);
5690 if (rc)
5691 goto err_out;
5692
5693 if (bp->flags & BNXT_FLAG_RFS) {
5694 rc = bnxt_alloc_rfs_vnics(bp);
5695 if (rc)
5696 goto err_out;
5697 }
5698
5699 if (bp->flags & BNXT_FLAG_TPA) {
5700 rc = bnxt_set_tpa(bp, true);
5701 if (rc)
5702 goto err_out;
5703 }
5704
5705 if (BNXT_VF(bp))
5706 bnxt_update_vf_mac(bp);
5707
5708 /* Filter for default vnic 0 */
5709 rc = bnxt_hwrm_set_vnic_filter(bp, 0, 0, bp->dev->dev_addr);
5710 if (rc) {
5711 netdev_err(bp->dev, "HWRM vnic filter failure rc: %x\n", rc);
5712 goto err_out;
5713 }
Michael Chan7d2837d2016-05-04 16:56:44 -04005714 vnic->uc_filter_count = 1;
Michael Chanc0c050c2015-10-22 16:01:17 -04005715
Michael Chan7d2837d2016-05-04 16:56:44 -04005716 vnic->rx_mask = CFA_L2_SET_RX_MASK_REQ_MASK_BCAST;
Michael Chanc0c050c2015-10-22 16:01:17 -04005717
Michael Chan17c71ac2016-07-01 18:46:27 -04005718 if ((bp->dev->flags & IFF_PROMISC) && bnxt_promisc_ok(bp))
Michael Chan7d2837d2016-05-04 16:56:44 -04005719 vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS;
5720
5721 if (bp->dev->flags & IFF_ALLMULTI) {
5722 vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST;
5723 vnic->mc_list_count = 0;
5724 } else {
5725 u32 mask = 0;
5726
5727 bnxt_mc_list_updated(bp, &mask);
5728 vnic->rx_mask |= mask;
5729 }
Michael Chanc0c050c2015-10-22 16:01:17 -04005730
Michael Chanb664f002015-12-02 01:54:08 -05005731 rc = bnxt_cfg_rx_mode(bp);
5732 if (rc)
Michael Chanc0c050c2015-10-22 16:01:17 -04005733 goto err_out;
Michael Chanc0c050c2015-10-22 16:01:17 -04005734
5735 rc = bnxt_hwrm_set_coal(bp);
5736 if (rc)
5737 netdev_warn(bp->dev, "HWRM set coalescing failure rc: %x\n",
Prashant Sreedharandc52c6c2016-07-18 07:15:24 -04005738 rc);
5739
5740 if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
5741 rc = bnxt_setup_nitroa0_vnic(bp);
5742 if (rc)
5743 netdev_err(bp->dev, "Special vnic setup failure for NS2 A0 rc: %x\n",
5744 rc);
5745 }
Michael Chanc0c050c2015-10-22 16:01:17 -04005746
Michael Chancf6645f2016-06-13 02:25:28 -04005747 if (BNXT_VF(bp)) {
5748 bnxt_hwrm_func_qcfg(bp);
5749 netdev_update_features(bp->dev);
5750 }
5751
Michael Chanc0c050c2015-10-22 16:01:17 -04005752 return 0;
5753
5754err_out:
5755 bnxt_hwrm_resource_free(bp, 0, true);
5756
5757 return rc;
5758}
5759
5760static int bnxt_shutdown_nic(struct bnxt *bp, bool irq_re_init)
5761{
5762 bnxt_hwrm_resource_free(bp, 1, irq_re_init);
5763 return 0;
5764}
5765
5766static int bnxt_init_nic(struct bnxt *bp, bool irq_re_init)
5767{
Sankar Patchineelam22479252017-03-28 19:47:29 -04005768 bnxt_init_cp_rings(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04005769 bnxt_init_rx_rings(bp);
5770 bnxt_init_tx_rings(bp);
5771 bnxt_init_ring_grps(bp, irq_re_init);
5772 bnxt_init_vnics(bp);
5773
5774 return bnxt_init_chip(bp, irq_re_init);
5775}
5776
Michael Chanc0c050c2015-10-22 16:01:17 -04005777static int bnxt_set_real_num_queues(struct bnxt *bp)
5778{
5779 int rc;
5780 struct net_device *dev = bp->dev;
5781
Michael Chan5f449242017-02-06 16:55:40 -05005782 rc = netif_set_real_num_tx_queues(dev, bp->tx_nr_rings -
5783 bp->tx_nr_rings_xdp);
Michael Chanc0c050c2015-10-22 16:01:17 -04005784 if (rc)
5785 return rc;
5786
5787 rc = netif_set_real_num_rx_queues(dev, bp->rx_nr_rings);
5788 if (rc)
5789 return rc;
5790
5791#ifdef CONFIG_RFS_ACCEL
Michael Chan45019a12015-12-27 18:19:22 -05005792 if (bp->flags & BNXT_FLAG_RFS)
Michael Chanc0c050c2015-10-22 16:01:17 -04005793 dev->rx_cpu_rmap = alloc_irq_cpu_rmap(bp->rx_nr_rings);
Michael Chanc0c050c2015-10-22 16:01:17 -04005794#endif
5795
5796 return rc;
5797}
5798
Michael Chan6e6c5a52016-01-02 23:45:02 -05005799static int bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max,
5800 bool shared)
5801{
5802 int _rx = *rx, _tx = *tx;
5803
5804 if (shared) {
5805 *rx = min_t(int, _rx, max);
5806 *tx = min_t(int, _tx, max);
5807 } else {
5808 if (max < 2)
5809 return -ENOMEM;
5810
5811 while (_rx + _tx > max) {
5812 if (_rx > _tx && _rx > 1)
5813 _rx--;
5814 else if (_tx > 1)
5815 _tx--;
5816 }
5817 *rx = _rx;
5818 *tx = _tx;
5819 }
5820 return 0;
5821}
5822
Michael Chan78095922016-12-07 00:26:16 -05005823static void bnxt_setup_msix(struct bnxt *bp)
5824{
5825 const int len = sizeof(bp->irq_tbl[0].name);
5826 struct net_device *dev = bp->dev;
5827 int tcs, i;
5828
5829 tcs = netdev_get_num_tc(dev);
5830 if (tcs > 1) {
Michael Chand1e79252017-02-06 16:55:38 -05005831 int i, off, count;
Michael Chan78095922016-12-07 00:26:16 -05005832
Michael Chand1e79252017-02-06 16:55:38 -05005833 for (i = 0; i < tcs; i++) {
5834 count = bp->tx_nr_rings_per_tc;
5835 off = i * count;
5836 netdev_set_tc_queue(dev, i, count, off);
Michael Chan78095922016-12-07 00:26:16 -05005837 }
5838 }
5839
5840 for (i = 0; i < bp->cp_nr_rings; i++) {
Michael Chane5811b82018-03-31 13:54:18 -04005841 int map_idx = bnxt_cp_num_to_irq_num(bp, i);
Michael Chan78095922016-12-07 00:26:16 -05005842 char *attr;
5843
5844 if (bp->flags & BNXT_FLAG_SHARED_RINGS)
5845 attr = "TxRx";
5846 else if (i < bp->rx_nr_rings)
5847 attr = "rx";
5848 else
5849 attr = "tx";
5850
Michael Chane5811b82018-03-31 13:54:18 -04005851 snprintf(bp->irq_tbl[map_idx].name, len, "%s-%s-%d", dev->name,
5852 attr, i);
5853 bp->irq_tbl[map_idx].handler = bnxt_msix;
Michael Chan78095922016-12-07 00:26:16 -05005854 }
5855}
5856
5857static void bnxt_setup_inta(struct bnxt *bp)
5858{
5859 const int len = sizeof(bp->irq_tbl[0].name);
5860
5861 if (netdev_get_num_tc(bp->dev))
5862 netdev_reset_tc(bp->dev);
5863
5864 snprintf(bp->irq_tbl[0].name, len, "%s-%s-%d", bp->dev->name, "TxRx",
5865 0);
5866 bp->irq_tbl[0].handler = bnxt_inta;
5867}
5868
5869static int bnxt_setup_int_mode(struct bnxt *bp)
5870{
5871 int rc;
5872
5873 if (bp->flags & BNXT_FLAG_USING_MSIX)
5874 bnxt_setup_msix(bp);
5875 else
5876 bnxt_setup_inta(bp);
5877
5878 rc = bnxt_set_real_num_queues(bp);
5879 return rc;
5880}
5881
Michael Chanb7429952017-01-13 01:32:00 -05005882#ifdef CONFIG_RFS_ACCEL
Michael Chan8079e8f2016-12-29 12:13:37 -05005883static unsigned int bnxt_get_max_func_rss_ctxs(struct bnxt *bp)
5884{
Michael Chan6a4f2942018-01-17 03:21:06 -05005885 return bp->hw_resc.max_rsscos_ctxs;
Michael Chan8079e8f2016-12-29 12:13:37 -05005886}
5887
5888static unsigned int bnxt_get_max_func_vnics(struct bnxt *bp)
5889{
Michael Chan6a4f2942018-01-17 03:21:06 -05005890 return bp->hw_resc.max_vnics;
Michael Chan8079e8f2016-12-29 12:13:37 -05005891}
Michael Chanb7429952017-01-13 01:32:00 -05005892#endif
Michael Chan8079e8f2016-12-29 12:13:37 -05005893
Michael Chane4060d32016-12-07 00:26:19 -05005894unsigned int bnxt_get_max_func_stat_ctxs(struct bnxt *bp)
5895{
Michael Chan6a4f2942018-01-17 03:21:06 -05005896 return bp->hw_resc.max_stat_ctxs;
Michael Chane4060d32016-12-07 00:26:19 -05005897}
5898
Michael Chana588e452016-12-07 00:26:21 -05005899void bnxt_set_max_func_stat_ctxs(struct bnxt *bp, unsigned int max)
5900{
Michael Chan6a4f2942018-01-17 03:21:06 -05005901 bp->hw_resc.max_stat_ctxs = max;
Michael Chana588e452016-12-07 00:26:21 -05005902}
5903
Michael Chane4060d32016-12-07 00:26:19 -05005904unsigned int bnxt_get_max_func_cp_rings(struct bnxt *bp)
5905{
Michael Chan6a4f2942018-01-17 03:21:06 -05005906 return bp->hw_resc.max_cp_rings;
Michael Chane4060d32016-12-07 00:26:19 -05005907}
5908
Michael Chana588e452016-12-07 00:26:21 -05005909void bnxt_set_max_func_cp_rings(struct bnxt *bp, unsigned int max)
5910{
Michael Chan6a4f2942018-01-17 03:21:06 -05005911 bp->hw_resc.max_cp_rings = max;
Michael Chana588e452016-12-07 00:26:21 -05005912}
5913
Michael Chanfbcfc8e2018-03-31 13:54:20 -04005914unsigned int bnxt_get_max_func_irqs(struct bnxt *bp)
Michael Chan78095922016-12-07 00:26:16 -05005915{
Michael Chan6a4f2942018-01-17 03:21:06 -05005916 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
5917
5918 return min_t(unsigned int, hw_resc->max_irqs, hw_resc->max_cp_rings);
Michael Chan78095922016-12-07 00:26:16 -05005919}
5920
Michael Chan33c26572016-12-07 00:26:15 -05005921void bnxt_set_max_func_irqs(struct bnxt *bp, unsigned int max_irqs)
5922{
Michael Chan6a4f2942018-01-17 03:21:06 -05005923 bp->hw_resc.max_irqs = max_irqs;
Michael Chan33c26572016-12-07 00:26:15 -05005924}
5925
Michael Chanfbcfc8e2018-03-31 13:54:20 -04005926int bnxt_get_avail_msix(struct bnxt *bp, int num)
5927{
5928 int max_cp = bnxt_get_max_func_cp_rings(bp);
5929 int max_irq = bnxt_get_max_func_irqs(bp);
5930 int total_req = bp->cp_nr_rings + num;
5931 int max_idx, avail_msix;
5932
5933 max_idx = min_t(int, bp->total_irqs, max_cp);
5934 avail_msix = max_idx - bp->cp_nr_rings;
5935 if (!(bp->flags & BNXT_FLAG_NEW_RM) || avail_msix >= num)
5936 return avail_msix;
5937
5938 if (max_irq < total_req) {
5939 num = max_irq - bp->cp_nr_rings;
5940 if (num <= 0)
5941 return 0;
5942 }
5943 return num;
5944}
5945
Michael Chan08654eb2018-03-31 13:54:17 -04005946static int bnxt_get_num_msix(struct bnxt *bp)
5947{
5948 if (!(bp->flags & BNXT_FLAG_NEW_RM))
5949 return bnxt_get_max_func_irqs(bp);
5950
5951 return bnxt_cp_rings_in_use(bp);
5952}
5953
Michael Chan78095922016-12-07 00:26:16 -05005954static int bnxt_init_msix(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04005955{
Michael Chanfbcfc8e2018-03-31 13:54:20 -04005956 int i, total_vecs, max, rc = 0, min = 1, ulp_msix;
Michael Chan78095922016-12-07 00:26:16 -05005957 struct msix_entry *msix_ent;
Michael Chanc0c050c2015-10-22 16:01:17 -04005958
Michael Chan08654eb2018-03-31 13:54:17 -04005959 total_vecs = bnxt_get_num_msix(bp);
5960 max = bnxt_get_max_func_irqs(bp);
5961 if (total_vecs > max)
5962 total_vecs = max;
5963
Michael Chanc0c050c2015-10-22 16:01:17 -04005964 msix_ent = kcalloc(total_vecs, sizeof(struct msix_entry), GFP_KERNEL);
5965 if (!msix_ent)
5966 return -ENOMEM;
5967
5968 for (i = 0; i < total_vecs; i++) {
5969 msix_ent[i].entry = i;
5970 msix_ent[i].vector = 0;
5971 }
5972
Michael Chan01657bc2016-01-02 23:45:03 -05005973 if (!(bp->flags & BNXT_FLAG_SHARED_RINGS))
5974 min = 2;
5975
5976 total_vecs = pci_enable_msix_range(bp->pdev, msix_ent, min, total_vecs);
Michael Chanfbcfc8e2018-03-31 13:54:20 -04005977 ulp_msix = bnxt_get_ulp_msix_num(bp);
5978 if (total_vecs < 0 || total_vecs < ulp_msix) {
Michael Chanc0c050c2015-10-22 16:01:17 -04005979 rc = -ENODEV;
5980 goto msix_setup_exit;
5981 }
5982
5983 bp->irq_tbl = kcalloc(total_vecs, sizeof(struct bnxt_irq), GFP_KERNEL);
5984 if (bp->irq_tbl) {
Michael Chan78095922016-12-07 00:26:16 -05005985 for (i = 0; i < total_vecs; i++)
5986 bp->irq_tbl[i].vector = msix_ent[i].vector;
Michael Chanc0c050c2015-10-22 16:01:17 -04005987
Michael Chan78095922016-12-07 00:26:16 -05005988 bp->total_irqs = total_vecs;
Michael Chanc0c050c2015-10-22 16:01:17 -04005989 /* Trim rings based upon num of vectors allocated */
Michael Chan6e6c5a52016-01-02 23:45:02 -05005990 rc = bnxt_trim_rings(bp, &bp->rx_nr_rings, &bp->tx_nr_rings,
Michael Chanfbcfc8e2018-03-31 13:54:20 -04005991 total_vecs - ulp_msix, min == 1);
Michael Chan6e6c5a52016-01-02 23:45:02 -05005992 if (rc)
5993 goto msix_setup_exit;
5994
Michael Chan78095922016-12-07 00:26:16 -05005995 bp->cp_nr_rings = (min == 1) ?
5996 max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
5997 bp->tx_nr_rings + bp->rx_nr_rings;
Michael Chanc0c050c2015-10-22 16:01:17 -04005998
Michael Chanc0c050c2015-10-22 16:01:17 -04005999 } else {
6000 rc = -ENOMEM;
6001 goto msix_setup_exit;
6002 }
6003 bp->flags |= BNXT_FLAG_USING_MSIX;
6004 kfree(msix_ent);
6005 return 0;
6006
6007msix_setup_exit:
Michael Chan78095922016-12-07 00:26:16 -05006008 netdev_err(bp->dev, "bnxt_init_msix err: %x\n", rc);
6009 kfree(bp->irq_tbl);
6010 bp->irq_tbl = NULL;
Michael Chanc0c050c2015-10-22 16:01:17 -04006011 pci_disable_msix(bp->pdev);
6012 kfree(msix_ent);
6013 return rc;
6014}
6015
Michael Chan78095922016-12-07 00:26:16 -05006016static int bnxt_init_inta(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04006017{
Michael Chanc0c050c2015-10-22 16:01:17 -04006018 bp->irq_tbl = kcalloc(1, sizeof(struct bnxt_irq), GFP_KERNEL);
Michael Chan78095922016-12-07 00:26:16 -05006019 if (!bp->irq_tbl)
6020 return -ENOMEM;
6021
6022 bp->total_irqs = 1;
Michael Chanc0c050c2015-10-22 16:01:17 -04006023 bp->rx_nr_rings = 1;
6024 bp->tx_nr_rings = 1;
6025 bp->cp_nr_rings = 1;
Michael Chan01657bc2016-01-02 23:45:03 -05006026 bp->flags |= BNXT_FLAG_SHARED_RINGS;
Michael Chanc0c050c2015-10-22 16:01:17 -04006027 bp->irq_tbl[0].vector = bp->pdev->irq;
Michael Chan78095922016-12-07 00:26:16 -05006028 return 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04006029}
6030
Michael Chan78095922016-12-07 00:26:16 -05006031static int bnxt_init_int_mode(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04006032{
6033 int rc = 0;
6034
6035 if (bp->flags & BNXT_FLAG_MSIX_CAP)
Michael Chan78095922016-12-07 00:26:16 -05006036 rc = bnxt_init_msix(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04006037
Michael Chan1fa72e22016-04-25 02:30:49 -04006038 if (!(bp->flags & BNXT_FLAG_USING_MSIX) && BNXT_PF(bp)) {
Michael Chanc0c050c2015-10-22 16:01:17 -04006039 /* fallback to INTA */
Michael Chan78095922016-12-07 00:26:16 -05006040 rc = bnxt_init_inta(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04006041 }
6042 return rc;
6043}
6044
Michael Chan78095922016-12-07 00:26:16 -05006045static void bnxt_clear_int_mode(struct bnxt *bp)
6046{
6047 if (bp->flags & BNXT_FLAG_USING_MSIX)
6048 pci_disable_msix(bp->pdev);
6049
6050 kfree(bp->irq_tbl);
6051 bp->irq_tbl = NULL;
6052 bp->flags &= ~BNXT_FLAG_USING_MSIX;
6053}
6054
Michael Chanfbcfc8e2018-03-31 13:54:20 -04006055int bnxt_reserve_rings(struct bnxt *bp)
Michael Chan674f50a2018-01-17 03:21:09 -05006056{
Michael Chan674f50a2018-01-17 03:21:09 -05006057 int tcs = netdev_get_num_tc(bp->dev);
6058 int rc;
6059
6060 if (!bnxt_need_reserve_rings(bp))
6061 return 0;
6062
6063 rc = __bnxt_reserve_rings(bp);
6064 if (rc) {
6065 netdev_err(bp->dev, "ring reservation failure rc: %d\n", rc);
6066 return rc;
6067 }
Michael Chanfbcfc8e2018-03-31 13:54:20 -04006068 if ((bp->flags & BNXT_FLAG_NEW_RM) &&
6069 (bnxt_get_num_msix(bp) != bp->total_irqs)) {
Michael Chanec86f142018-03-31 13:54:21 -04006070 bnxt_ulp_irq_stop(bp);
Michael Chan674f50a2018-01-17 03:21:09 -05006071 bnxt_clear_int_mode(bp);
6072 rc = bnxt_init_int_mode(bp);
Michael Chanec86f142018-03-31 13:54:21 -04006073 bnxt_ulp_irq_restart(bp, rc);
Michael Chan674f50a2018-01-17 03:21:09 -05006074 if (rc)
6075 return rc;
6076 }
6077 if (tcs && (bp->tx_nr_rings_per_tc * tcs != bp->tx_nr_rings)) {
6078 netdev_err(bp->dev, "tx ring reservation failure\n");
6079 netdev_reset_tc(bp->dev);
6080 bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
6081 return -ENOMEM;
6082 }
6083 bp->num_stat_ctxs = bp->cp_nr_rings;
6084 return 0;
6085}
6086
Michael Chanc0c050c2015-10-22 16:01:17 -04006087static void bnxt_free_irq(struct bnxt *bp)
6088{
6089 struct bnxt_irq *irq;
6090 int i;
6091
6092#ifdef CONFIG_RFS_ACCEL
6093 free_irq_cpu_rmap(bp->dev->rx_cpu_rmap);
6094 bp->dev->rx_cpu_rmap = NULL;
6095#endif
Michael Chancb985262018-04-11 11:50:18 -04006096 if (!bp->irq_tbl || !bp->bnapi)
Michael Chanc0c050c2015-10-22 16:01:17 -04006097 return;
6098
6099 for (i = 0; i < bp->cp_nr_rings; i++) {
Michael Chane5811b82018-03-31 13:54:18 -04006100 int map_idx = bnxt_cp_num_to_irq_num(bp, i);
6101
6102 irq = &bp->irq_tbl[map_idx];
Vasundhara Volam56f0fd82017-08-28 13:40:27 -04006103 if (irq->requested) {
6104 if (irq->have_cpumask) {
6105 irq_set_affinity_hint(irq->vector, NULL);
6106 free_cpumask_var(irq->cpu_mask);
6107 irq->have_cpumask = 0;
6108 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006109 free_irq(irq->vector, bp->bnapi[i]);
Vasundhara Volam56f0fd82017-08-28 13:40:27 -04006110 }
6111
Michael Chanc0c050c2015-10-22 16:01:17 -04006112 irq->requested = 0;
6113 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006114}
6115
6116static int bnxt_request_irq(struct bnxt *bp)
6117{
Michael Chanb81a90d2016-01-02 23:45:01 -05006118 int i, j, rc = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04006119 unsigned long flags = 0;
6120#ifdef CONFIG_RFS_ACCEL
Michael Chane5811b82018-03-31 13:54:18 -04006121 struct cpu_rmap *rmap;
Michael Chanc0c050c2015-10-22 16:01:17 -04006122#endif
6123
Michael Chane5811b82018-03-31 13:54:18 -04006124 rc = bnxt_setup_int_mode(bp);
6125 if (rc) {
6126 netdev_err(bp->dev, "bnxt_setup_int_mode err: %x\n",
6127 rc);
6128 return rc;
6129 }
6130#ifdef CONFIG_RFS_ACCEL
6131 rmap = bp->dev->rx_cpu_rmap;
6132#endif
Michael Chanc0c050c2015-10-22 16:01:17 -04006133 if (!(bp->flags & BNXT_FLAG_USING_MSIX))
6134 flags = IRQF_SHARED;
6135
Michael Chanb81a90d2016-01-02 23:45:01 -05006136 for (i = 0, j = 0; i < bp->cp_nr_rings; i++) {
Michael Chane5811b82018-03-31 13:54:18 -04006137 int map_idx = bnxt_cp_num_to_irq_num(bp, i);
6138 struct bnxt_irq *irq = &bp->irq_tbl[map_idx];
6139
Michael Chanc0c050c2015-10-22 16:01:17 -04006140#ifdef CONFIG_RFS_ACCEL
Michael Chanb81a90d2016-01-02 23:45:01 -05006141 if (rmap && bp->bnapi[i]->rx_ring) {
Michael Chanc0c050c2015-10-22 16:01:17 -04006142 rc = irq_cpu_rmap_add(rmap, irq->vector);
6143 if (rc)
6144 netdev_warn(bp->dev, "failed adding irq rmap for ring %d\n",
Michael Chanb81a90d2016-01-02 23:45:01 -05006145 j);
6146 j++;
Michael Chanc0c050c2015-10-22 16:01:17 -04006147 }
6148#endif
6149 rc = request_irq(irq->vector, irq->handler, flags, irq->name,
6150 bp->bnapi[i]);
6151 if (rc)
6152 break;
6153
6154 irq->requested = 1;
Vasundhara Volam56f0fd82017-08-28 13:40:27 -04006155
6156 if (zalloc_cpumask_var(&irq->cpu_mask, GFP_KERNEL)) {
6157 int numa_node = dev_to_node(&bp->pdev->dev);
6158
6159 irq->have_cpumask = 1;
6160 cpumask_set_cpu(cpumask_local_spread(i, numa_node),
6161 irq->cpu_mask);
6162 rc = irq_set_affinity_hint(irq->vector, irq->cpu_mask);
6163 if (rc) {
6164 netdev_warn(bp->dev,
6165 "Set affinity failed, IRQ = %d\n",
6166 irq->vector);
6167 break;
6168 }
6169 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006170 }
6171 return rc;
6172}
6173
6174static void bnxt_del_napi(struct bnxt *bp)
6175{
6176 int i;
6177
6178 if (!bp->bnapi)
6179 return;
6180
6181 for (i = 0; i < bp->cp_nr_rings; i++) {
6182 struct bnxt_napi *bnapi = bp->bnapi[i];
6183
6184 napi_hash_del(&bnapi->napi);
6185 netif_napi_del(&bnapi->napi);
6186 }
Eric Dumazete5f6f562016-11-16 06:31:52 -08006187 /* We called napi_hash_del() before netif_napi_del(), we need
6188 * to respect an RCU grace period before freeing napi structures.
6189 */
6190 synchronize_net();
Michael Chanc0c050c2015-10-22 16:01:17 -04006191}
6192
6193static void bnxt_init_napi(struct bnxt *bp)
6194{
6195 int i;
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04006196 unsigned int cp_nr_rings = bp->cp_nr_rings;
Michael Chanc0c050c2015-10-22 16:01:17 -04006197 struct bnxt_napi *bnapi;
6198
6199 if (bp->flags & BNXT_FLAG_USING_MSIX) {
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04006200 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
6201 cp_nr_rings--;
6202 for (i = 0; i < cp_nr_rings; i++) {
Michael Chanc0c050c2015-10-22 16:01:17 -04006203 bnapi = bp->bnapi[i];
6204 netif_napi_add(bp->dev, &bnapi->napi,
6205 bnxt_poll, 64);
Michael Chanc0c050c2015-10-22 16:01:17 -04006206 }
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04006207 if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
6208 bnapi = bp->bnapi[cp_nr_rings];
6209 netif_napi_add(bp->dev, &bnapi->napi,
6210 bnxt_poll_nitroa0, 64);
Prashant Sreedharan10bbdaf2016-07-18 07:15:23 -04006211 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006212 } else {
6213 bnapi = bp->bnapi[0];
6214 netif_napi_add(bp->dev, &bnapi->napi, bnxt_poll, 64);
Michael Chanc0c050c2015-10-22 16:01:17 -04006215 }
6216}
6217
6218static void bnxt_disable_napi(struct bnxt *bp)
6219{
6220 int i;
6221
6222 if (!bp->bnapi)
6223 return;
6224
Andy Gospodarek0bc0b972018-01-26 10:27:47 -05006225 for (i = 0; i < bp->cp_nr_rings; i++) {
6226 struct bnxt_cp_ring_info *cpr = &bp->bnapi[i]->cp_ring;
6227
6228 if (bp->bnapi[i]->rx_ring)
6229 cancel_work_sync(&cpr->dim.work);
6230
Michael Chanc0c050c2015-10-22 16:01:17 -04006231 napi_disable(&bp->bnapi[i]->napi);
Andy Gospodarek0bc0b972018-01-26 10:27:47 -05006232 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006233}
6234
6235static void bnxt_enable_napi(struct bnxt *bp)
6236{
6237 int i;
6238
6239 for (i = 0; i < bp->cp_nr_rings; i++) {
Andy Gospodarek6a8788f2018-01-09 16:06:20 -05006240 struct bnxt_cp_ring_info *cpr = &bp->bnapi[i]->cp_ring;
Michael Chanfa7e2812016-05-10 19:18:00 -04006241 bp->bnapi[i]->in_reset = false;
Andy Gospodarek6a8788f2018-01-09 16:06:20 -05006242
6243 if (bp->bnapi[i]->rx_ring) {
6244 INIT_WORK(&cpr->dim.work, bnxt_dim_work);
6245 cpr->dim.mode = NET_DIM_CQ_PERIOD_MODE_START_FROM_EQE;
6246 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006247 napi_enable(&bp->bnapi[i]->napi);
6248 }
6249}
6250
Michael Chan7df4ae92016-12-02 21:17:17 -05006251void bnxt_tx_disable(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04006252{
6253 int i;
Michael Chanc0c050c2015-10-22 16:01:17 -04006254 struct bnxt_tx_ring_info *txr;
Michael Chanc0c050c2015-10-22 16:01:17 -04006255
Michael Chanb6ab4b02016-01-02 23:44:59 -05006256 if (bp->tx_ring) {
Michael Chanc0c050c2015-10-22 16:01:17 -04006257 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05006258 txr = &bp->tx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04006259 txr->dev_state = BNXT_DEV_STATE_CLOSING;
Michael Chanc0c050c2015-10-22 16:01:17 -04006260 }
6261 }
6262 /* Stop all TX queues */
6263 netif_tx_disable(bp->dev);
6264 netif_carrier_off(bp->dev);
6265}
6266
Michael Chan7df4ae92016-12-02 21:17:17 -05006267void bnxt_tx_enable(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04006268{
6269 int i;
Michael Chanc0c050c2015-10-22 16:01:17 -04006270 struct bnxt_tx_ring_info *txr;
Michael Chanc0c050c2015-10-22 16:01:17 -04006271
6272 for (i = 0; i < bp->tx_nr_rings; i++) {
Michael Chanb6ab4b02016-01-02 23:44:59 -05006273 txr = &bp->tx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04006274 txr->dev_state = 0;
6275 }
6276 netif_tx_wake_all_queues(bp->dev);
6277 if (bp->link_info.link_up)
6278 netif_carrier_on(bp->dev);
6279}
6280
6281static void bnxt_report_link(struct bnxt *bp)
6282{
6283 if (bp->link_info.link_up) {
6284 const char *duplex;
6285 const char *flow_ctrl;
Deepak Khungar38a21b32017-04-21 20:11:24 -04006286 u32 speed;
6287 u16 fec;
Michael Chanc0c050c2015-10-22 16:01:17 -04006288
6289 netif_carrier_on(bp->dev);
6290 if (bp->link_info.duplex == BNXT_LINK_DUPLEX_FULL)
6291 duplex = "full";
6292 else
6293 duplex = "half";
6294 if (bp->link_info.pause == BNXT_LINK_PAUSE_BOTH)
6295 flow_ctrl = "ON - receive & transmit";
6296 else if (bp->link_info.pause == BNXT_LINK_PAUSE_TX)
6297 flow_ctrl = "ON - transmit";
6298 else if (bp->link_info.pause == BNXT_LINK_PAUSE_RX)
6299 flow_ctrl = "ON - receive";
6300 else
6301 flow_ctrl = "none";
6302 speed = bnxt_fw_to_ethtool_speed(bp->link_info.link_speed);
Deepak Khungar38a21b32017-04-21 20:11:24 -04006303 netdev_info(bp->dev, "NIC Link is Up, %u Mbps %s duplex, Flow control: %s\n",
Michael Chanc0c050c2015-10-22 16:01:17 -04006304 speed, duplex, flow_ctrl);
Michael Chan170ce012016-04-05 14:08:57 -04006305 if (bp->flags & BNXT_FLAG_EEE_CAP)
6306 netdev_info(bp->dev, "EEE is %s\n",
6307 bp->eee.eee_active ? "active" :
6308 "not active");
Michael Chane70c7522017-02-12 19:18:16 -05006309 fec = bp->link_info.fec_cfg;
6310 if (!(fec & PORT_PHY_QCFG_RESP_FEC_CFG_FEC_NONE_SUPPORTED))
6311 netdev_info(bp->dev, "FEC autoneg %s encodings: %s\n",
6312 (fec & BNXT_FEC_AUTONEG) ? "on" : "off",
6313 (fec & BNXT_FEC_ENC_BASE_R) ? "BaseR" :
6314 (fec & BNXT_FEC_ENC_RS) ? "RS" : "None");
Michael Chanc0c050c2015-10-22 16:01:17 -04006315 } else {
6316 netif_carrier_off(bp->dev);
6317 netdev_err(bp->dev, "NIC Link is Down\n");
6318 }
6319}
6320
Michael Chan170ce012016-04-05 14:08:57 -04006321static int bnxt_hwrm_phy_qcaps(struct bnxt *bp)
6322{
6323 int rc = 0;
6324 struct hwrm_port_phy_qcaps_input req = {0};
6325 struct hwrm_port_phy_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
Michael Chan93ed8112016-06-13 02:25:37 -04006326 struct bnxt_link_info *link_info = &bp->link_info;
Michael Chan170ce012016-04-05 14:08:57 -04006327
6328 if (bp->hwrm_spec_code < 0x10201)
6329 return 0;
6330
6331 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCAPS, -1, -1);
6332
6333 mutex_lock(&bp->hwrm_cmd_lock);
6334 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6335 if (rc)
6336 goto hwrm_phy_qcaps_exit;
6337
Michael Chanacb20052017-07-24 12:34:20 -04006338 if (resp->flags & PORT_PHY_QCAPS_RESP_FLAGS_EEE_SUPPORTED) {
Michael Chan170ce012016-04-05 14:08:57 -04006339 struct ethtool_eee *eee = &bp->eee;
6340 u16 fw_speeds = le16_to_cpu(resp->supported_speeds_eee_mode);
6341
6342 bp->flags |= BNXT_FLAG_EEE_CAP;
6343 eee->supported = _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0);
6344 bp->lpi_tmr_lo = le32_to_cpu(resp->tx_lpi_timer_low) &
6345 PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_LOW_MASK;
6346 bp->lpi_tmr_hi = le32_to_cpu(resp->valid_tx_lpi_timer_high) &
6347 PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_HIGH_MASK;
6348 }
Michael Chan520ad892017-03-08 18:44:35 -05006349 if (resp->supported_speeds_auto_mode)
6350 link_info->support_auto_speeds =
6351 le16_to_cpu(resp->supported_speeds_auto_mode);
Michael Chan170ce012016-04-05 14:08:57 -04006352
Michael Chand5430d32017-08-28 13:40:31 -04006353 bp->port_count = resp->port_cnt;
6354
Michael Chan170ce012016-04-05 14:08:57 -04006355hwrm_phy_qcaps_exit:
6356 mutex_unlock(&bp->hwrm_cmd_lock);
6357 return rc;
6358}
6359
Michael Chanc0c050c2015-10-22 16:01:17 -04006360static int bnxt_update_link(struct bnxt *bp, bool chng_link_state)
6361{
6362 int rc = 0;
6363 struct bnxt_link_info *link_info = &bp->link_info;
6364 struct hwrm_port_phy_qcfg_input req = {0};
6365 struct hwrm_port_phy_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
6366 u8 link_up = link_info->link_up;
Michael Chan286ef9d2016-11-16 21:13:08 -05006367 u16 diff;
Michael Chanc0c050c2015-10-22 16:01:17 -04006368
6369 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCFG, -1, -1);
6370
6371 mutex_lock(&bp->hwrm_cmd_lock);
6372 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6373 if (rc) {
6374 mutex_unlock(&bp->hwrm_cmd_lock);
6375 return rc;
6376 }
6377
6378 memcpy(&link_info->phy_qcfg_resp, resp, sizeof(*resp));
6379 link_info->phy_link_status = resp->link;
Michael Chanacb20052017-07-24 12:34:20 -04006380 link_info->duplex = resp->duplex_cfg;
6381 if (bp->hwrm_spec_code >= 0x10800)
6382 link_info->duplex = resp->duplex_state;
Michael Chanc0c050c2015-10-22 16:01:17 -04006383 link_info->pause = resp->pause;
6384 link_info->auto_mode = resp->auto_mode;
6385 link_info->auto_pause_setting = resp->auto_pause;
Michael Chan32773602016-03-07 15:38:42 -05006386 link_info->lp_pause = resp->link_partner_adv_pause;
Michael Chanc0c050c2015-10-22 16:01:17 -04006387 link_info->force_pause_setting = resp->force_pause;
Michael Chanacb20052017-07-24 12:34:20 -04006388 link_info->duplex_setting = resp->duplex_cfg;
Michael Chanc0c050c2015-10-22 16:01:17 -04006389 if (link_info->phy_link_status == BNXT_LINK_LINK)
6390 link_info->link_speed = le16_to_cpu(resp->link_speed);
6391 else
6392 link_info->link_speed = 0;
6393 link_info->force_link_speed = le16_to_cpu(resp->force_link_speed);
Michael Chanc0c050c2015-10-22 16:01:17 -04006394 link_info->support_speeds = le16_to_cpu(resp->support_speeds);
6395 link_info->auto_link_speeds = le16_to_cpu(resp->auto_link_speed_mask);
Michael Chan32773602016-03-07 15:38:42 -05006396 link_info->lp_auto_link_speeds =
6397 le16_to_cpu(resp->link_partner_adv_speeds);
Michael Chanc0c050c2015-10-22 16:01:17 -04006398 link_info->preemphasis = le32_to_cpu(resp->preemphasis);
6399 link_info->phy_ver[0] = resp->phy_maj;
6400 link_info->phy_ver[1] = resp->phy_min;
6401 link_info->phy_ver[2] = resp->phy_bld;
6402 link_info->media_type = resp->media_type;
Michael Chan03efbec2016-04-11 04:11:11 -04006403 link_info->phy_type = resp->phy_type;
Michael Chan11f15ed2016-04-05 14:08:55 -04006404 link_info->transceiver = resp->xcvr_pkg_type;
Michael Chan170ce012016-04-05 14:08:57 -04006405 link_info->phy_addr = resp->eee_config_phy_addr &
6406 PORT_PHY_QCFG_RESP_PHY_ADDR_MASK;
Ajit Khaparde42ee18f2016-05-15 03:04:44 -04006407 link_info->module_status = resp->module_status;
Michael Chanc0c050c2015-10-22 16:01:17 -04006408
Michael Chan170ce012016-04-05 14:08:57 -04006409 if (bp->flags & BNXT_FLAG_EEE_CAP) {
6410 struct ethtool_eee *eee = &bp->eee;
6411 u16 fw_speeds;
6412
6413 eee->eee_active = 0;
6414 if (resp->eee_config_phy_addr &
6415 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ACTIVE) {
6416 eee->eee_active = 1;
6417 fw_speeds = le16_to_cpu(
6418 resp->link_partner_adv_eee_link_speed_mask);
6419 eee->lp_advertised =
6420 _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0);
6421 }
6422
6423 /* Pull initial EEE config */
6424 if (!chng_link_state) {
6425 if (resp->eee_config_phy_addr &
6426 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ENABLED)
6427 eee->eee_enabled = 1;
6428
6429 fw_speeds = le16_to_cpu(resp->adv_eee_link_speed_mask);
6430 eee->advertised =
6431 _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0);
6432
6433 if (resp->eee_config_phy_addr &
6434 PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_TX_LPI) {
6435 __le32 tmr;
6436
6437 eee->tx_lpi_enabled = 1;
6438 tmr = resp->xcvr_identifier_type_tx_lpi_timer;
6439 eee->tx_lpi_timer = le32_to_cpu(tmr) &
6440 PORT_PHY_QCFG_RESP_TX_LPI_TIMER_MASK;
6441 }
6442 }
6443 }
Michael Chane70c7522017-02-12 19:18:16 -05006444
6445 link_info->fec_cfg = PORT_PHY_QCFG_RESP_FEC_CFG_FEC_NONE_SUPPORTED;
6446 if (bp->hwrm_spec_code >= 0x10504)
6447 link_info->fec_cfg = le16_to_cpu(resp->fec_cfg);
6448
Michael Chanc0c050c2015-10-22 16:01:17 -04006449 /* TODO: need to add more logic to report VF link */
6450 if (chng_link_state) {
6451 if (link_info->phy_link_status == BNXT_LINK_LINK)
6452 link_info->link_up = 1;
6453 else
6454 link_info->link_up = 0;
6455 if (link_up != link_info->link_up)
6456 bnxt_report_link(bp);
6457 } else {
6458 /* alwasy link down if not require to update link state */
6459 link_info->link_up = 0;
6460 }
6461 mutex_unlock(&bp->hwrm_cmd_lock);
Michael Chan286ef9d2016-11-16 21:13:08 -05006462
6463 diff = link_info->support_auto_speeds ^ link_info->advertising;
6464 if ((link_info->support_auto_speeds | diff) !=
6465 link_info->support_auto_speeds) {
6466 /* An advertised speed is no longer supported, so we need to
Michael Chan0eaa24b2017-01-25 02:55:08 -05006467 * update the advertisement settings. Caller holds RTNL
6468 * so we can modify link settings.
Michael Chan286ef9d2016-11-16 21:13:08 -05006469 */
Michael Chan286ef9d2016-11-16 21:13:08 -05006470 link_info->advertising = link_info->support_auto_speeds;
Michael Chan0eaa24b2017-01-25 02:55:08 -05006471 if (link_info->autoneg & BNXT_AUTONEG_SPEED)
Michael Chan286ef9d2016-11-16 21:13:08 -05006472 bnxt_hwrm_set_link_setting(bp, true, false);
Michael Chan286ef9d2016-11-16 21:13:08 -05006473 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006474 return 0;
6475}
6476
Michael Chan10289be2016-05-15 03:04:49 -04006477static void bnxt_get_port_module_status(struct bnxt *bp)
6478{
6479 struct bnxt_link_info *link_info = &bp->link_info;
6480 struct hwrm_port_phy_qcfg_output *resp = &link_info->phy_qcfg_resp;
6481 u8 module_status;
6482
6483 if (bnxt_update_link(bp, true))
6484 return;
6485
6486 module_status = link_info->module_status;
6487 switch (module_status) {
6488 case PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX:
6489 case PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN:
6490 case PORT_PHY_QCFG_RESP_MODULE_STATUS_WARNINGMSG:
6491 netdev_warn(bp->dev, "Unqualified SFP+ module detected on port %d\n",
6492 bp->pf.port_id);
6493 if (bp->hwrm_spec_code >= 0x10201) {
6494 netdev_warn(bp->dev, "Module part number %s\n",
6495 resp->phy_vendor_partnumber);
6496 }
6497 if (module_status == PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX)
6498 netdev_warn(bp->dev, "TX is disabled\n");
6499 if (module_status == PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN)
6500 netdev_warn(bp->dev, "SFP+ module is shutdown\n");
6501 }
6502}
6503
Michael Chanc0c050c2015-10-22 16:01:17 -04006504static void
6505bnxt_hwrm_set_pause_common(struct bnxt *bp, struct hwrm_port_phy_cfg_input *req)
6506{
6507 if (bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL) {
Michael Chanc9ee9512016-04-05 14:08:56 -04006508 if (bp->hwrm_spec_code >= 0x10201)
6509 req->auto_pause =
6510 PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE;
Michael Chanc0c050c2015-10-22 16:01:17 -04006511 if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_RX)
6512 req->auto_pause |= PORT_PHY_CFG_REQ_AUTO_PAUSE_RX;
6513 if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_TX)
Michael Chan49b5c7a2016-03-28 19:46:06 -04006514 req->auto_pause |= PORT_PHY_CFG_REQ_AUTO_PAUSE_TX;
Michael Chanc0c050c2015-10-22 16:01:17 -04006515 req->enables |=
6516 cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE);
6517 } else {
6518 if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_RX)
6519 req->force_pause |= PORT_PHY_CFG_REQ_FORCE_PAUSE_RX;
6520 if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_TX)
6521 req->force_pause |= PORT_PHY_CFG_REQ_FORCE_PAUSE_TX;
6522 req->enables |=
6523 cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_FORCE_PAUSE);
Michael Chanc9ee9512016-04-05 14:08:56 -04006524 if (bp->hwrm_spec_code >= 0x10201) {
6525 req->auto_pause = req->force_pause;
6526 req->enables |= cpu_to_le32(
6527 PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE);
6528 }
Michael Chanc0c050c2015-10-22 16:01:17 -04006529 }
6530}
6531
6532static void bnxt_hwrm_set_link_common(struct bnxt *bp,
6533 struct hwrm_port_phy_cfg_input *req)
6534{
6535 u8 autoneg = bp->link_info.autoneg;
6536 u16 fw_link_speed = bp->link_info.req_link_speed;
Michael Chan68515a12016-12-29 12:13:34 -05006537 u16 advertising = bp->link_info.advertising;
Michael Chanc0c050c2015-10-22 16:01:17 -04006538
6539 if (autoneg & BNXT_AUTONEG_SPEED) {
6540 req->auto_mode |=
Michael Chan11f15ed2016-04-05 14:08:55 -04006541 PORT_PHY_CFG_REQ_AUTO_MODE_SPEED_MASK;
Michael Chanc0c050c2015-10-22 16:01:17 -04006542
6543 req->enables |= cpu_to_le32(
6544 PORT_PHY_CFG_REQ_ENABLES_AUTO_LINK_SPEED_MASK);
6545 req->auto_link_speed_mask = cpu_to_le16(advertising);
6546
6547 req->enables |= cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_MODE);
6548 req->flags |=
6549 cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESTART_AUTONEG);
6550 } else {
6551 req->force_link_speed = cpu_to_le16(fw_link_speed);
6552 req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE);
6553 }
6554
Michael Chanc0c050c2015-10-22 16:01:17 -04006555 /* tell chimp that the setting takes effect immediately */
6556 req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESET_PHY);
6557}
6558
6559int bnxt_hwrm_set_pause(struct bnxt *bp)
6560{
6561 struct hwrm_port_phy_cfg_input req = {0};
6562 int rc;
6563
6564 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1);
6565 bnxt_hwrm_set_pause_common(bp, &req);
6566
6567 if ((bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL) ||
6568 bp->link_info.force_link_chng)
6569 bnxt_hwrm_set_link_common(bp, &req);
6570
6571 mutex_lock(&bp->hwrm_cmd_lock);
6572 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6573 if (!rc && !(bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL)) {
6574 /* since changing of pause setting doesn't trigger any link
6575 * change event, the driver needs to update the current pause
6576 * result upon successfully return of the phy_cfg command
6577 */
6578 bp->link_info.pause =
6579 bp->link_info.force_pause_setting = bp->link_info.req_flow_ctrl;
6580 bp->link_info.auto_pause_setting = 0;
6581 if (!bp->link_info.force_link_chng)
6582 bnxt_report_link(bp);
6583 }
6584 bp->link_info.force_link_chng = false;
6585 mutex_unlock(&bp->hwrm_cmd_lock);
6586 return rc;
6587}
6588
Michael Chan939f7f02016-04-05 14:08:58 -04006589static void bnxt_hwrm_set_eee(struct bnxt *bp,
6590 struct hwrm_port_phy_cfg_input *req)
6591{
6592 struct ethtool_eee *eee = &bp->eee;
6593
6594 if (eee->eee_enabled) {
6595 u16 eee_speeds;
6596 u32 flags = PORT_PHY_CFG_REQ_FLAGS_EEE_ENABLE;
6597
6598 if (eee->tx_lpi_enabled)
6599 flags |= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_ENABLE;
6600 else
6601 flags |= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_DISABLE;
6602
6603 req->flags |= cpu_to_le32(flags);
6604 eee_speeds = bnxt_get_fw_auto_link_speeds(eee->advertised);
6605 req->eee_link_speed_mask = cpu_to_le16(eee_speeds);
6606 req->tx_lpi_timer = cpu_to_le32(eee->tx_lpi_timer);
6607 } else {
6608 req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_EEE_DISABLE);
6609 }
6610}
6611
6612int bnxt_hwrm_set_link_setting(struct bnxt *bp, bool set_pause, bool set_eee)
Michael Chanc0c050c2015-10-22 16:01:17 -04006613{
6614 struct hwrm_port_phy_cfg_input req = {0};
6615
6616 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1);
6617 if (set_pause)
6618 bnxt_hwrm_set_pause_common(bp, &req);
6619
6620 bnxt_hwrm_set_link_common(bp, &req);
Michael Chan939f7f02016-04-05 14:08:58 -04006621
6622 if (set_eee)
6623 bnxt_hwrm_set_eee(bp, &req);
Michael Chanc0c050c2015-10-22 16:01:17 -04006624 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6625}
6626
Michael Chan33f7d552016-04-11 04:11:12 -04006627static int bnxt_hwrm_shutdown_link(struct bnxt *bp)
6628{
6629 struct hwrm_port_phy_cfg_input req = {0};
6630
Satish Baddipadige567b2ab2016-06-13 02:25:31 -04006631 if (!BNXT_SINGLE_PF(bp))
Michael Chan33f7d552016-04-11 04:11:12 -04006632 return 0;
6633
6634 if (pci_num_vf(bp->pdev))
6635 return 0;
6636
6637 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1);
Michael Chan16d663a2016-11-16 21:13:07 -05006638 req.flags = cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE_LINK_DWN);
Michael Chan33f7d552016-04-11 04:11:12 -04006639 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6640}
6641
Michael Chan5ad2cbe2017-01-13 01:32:03 -05006642static int bnxt_hwrm_port_led_qcaps(struct bnxt *bp)
6643{
6644 struct hwrm_port_led_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
6645 struct hwrm_port_led_qcaps_input req = {0};
6646 struct bnxt_pf_info *pf = &bp->pf;
6647 int rc;
6648
6649 if (BNXT_VF(bp) || bp->hwrm_spec_code < 0x10601)
6650 return 0;
6651
6652 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_LED_QCAPS, -1, -1);
6653 req.port_id = cpu_to_le16(pf->port_id);
6654 mutex_lock(&bp->hwrm_cmd_lock);
6655 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6656 if (rc) {
6657 mutex_unlock(&bp->hwrm_cmd_lock);
6658 return rc;
6659 }
6660 if (resp->num_leds > 0 && resp->num_leds < BNXT_MAX_LED) {
6661 int i;
6662
6663 bp->num_leds = resp->num_leds;
6664 memcpy(bp->leds, &resp->led0_id, sizeof(bp->leds[0]) *
6665 bp->num_leds);
6666 for (i = 0; i < bp->num_leds; i++) {
6667 struct bnxt_led_info *led = &bp->leds[i];
6668 __le16 caps = led->led_state_caps;
6669
6670 if (!led->led_group_id ||
6671 !BNXT_LED_ALT_BLINK_CAP(caps)) {
6672 bp->num_leds = 0;
6673 break;
6674 }
6675 }
6676 }
6677 mutex_unlock(&bp->hwrm_cmd_lock);
6678 return 0;
6679}
6680
Michael Chan5282db62017-04-04 18:14:10 -04006681int bnxt_hwrm_alloc_wol_fltr(struct bnxt *bp)
6682{
6683 struct hwrm_wol_filter_alloc_input req = {0};
6684 struct hwrm_wol_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr;
6685 int rc;
6686
6687 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_WOL_FILTER_ALLOC, -1, -1);
6688 req.port_id = cpu_to_le16(bp->pf.port_id);
6689 req.wol_type = WOL_FILTER_ALLOC_REQ_WOL_TYPE_MAGICPKT;
6690 req.enables = cpu_to_le32(WOL_FILTER_ALLOC_REQ_ENABLES_MAC_ADDRESS);
6691 memcpy(req.mac_address, bp->dev->dev_addr, ETH_ALEN);
6692 mutex_lock(&bp->hwrm_cmd_lock);
6693 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6694 if (!rc)
6695 bp->wol_filter_id = resp->wol_filter_id;
6696 mutex_unlock(&bp->hwrm_cmd_lock);
6697 return rc;
6698}
6699
6700int bnxt_hwrm_free_wol_fltr(struct bnxt *bp)
6701{
6702 struct hwrm_wol_filter_free_input req = {0};
6703 int rc;
6704
6705 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_WOL_FILTER_FREE, -1, -1);
6706 req.port_id = cpu_to_le16(bp->pf.port_id);
6707 req.enables = cpu_to_le32(WOL_FILTER_FREE_REQ_ENABLES_WOL_FILTER_ID);
6708 req.wol_filter_id = bp->wol_filter_id;
6709 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6710 return rc;
6711}
6712
Michael Chanc1ef1462017-04-04 18:14:07 -04006713static u16 bnxt_hwrm_get_wol_fltrs(struct bnxt *bp, u16 handle)
6714{
6715 struct hwrm_wol_filter_qcfg_input req = {0};
6716 struct hwrm_wol_filter_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
6717 u16 next_handle = 0;
6718 int rc;
6719
6720 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_WOL_FILTER_QCFG, -1, -1);
6721 req.port_id = cpu_to_le16(bp->pf.port_id);
6722 req.handle = cpu_to_le16(handle);
6723 mutex_lock(&bp->hwrm_cmd_lock);
6724 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
6725 if (!rc) {
6726 next_handle = le16_to_cpu(resp->next_handle);
6727 if (next_handle != 0) {
6728 if (resp->wol_type ==
6729 WOL_FILTER_ALLOC_REQ_WOL_TYPE_MAGICPKT) {
6730 bp->wol = 1;
6731 bp->wol_filter_id = resp->wol_filter_id;
6732 }
6733 }
6734 }
6735 mutex_unlock(&bp->hwrm_cmd_lock);
6736 return next_handle;
6737}
6738
6739static void bnxt_get_wol_settings(struct bnxt *bp)
6740{
6741 u16 handle = 0;
6742
6743 if (!BNXT_PF(bp) || !(bp->flags & BNXT_FLAG_WOL_CAP))
6744 return;
6745
6746 do {
6747 handle = bnxt_hwrm_get_wol_fltrs(bp, handle);
6748 } while (handle && handle != 0xffff);
6749}
6750
Michael Chan939f7f02016-04-05 14:08:58 -04006751static bool bnxt_eee_config_ok(struct bnxt *bp)
6752{
6753 struct ethtool_eee *eee = &bp->eee;
6754 struct bnxt_link_info *link_info = &bp->link_info;
6755
6756 if (!(bp->flags & BNXT_FLAG_EEE_CAP))
6757 return true;
6758
6759 if (eee->eee_enabled) {
6760 u32 advertising =
6761 _bnxt_fw_to_ethtool_adv_spds(link_info->advertising, 0);
6762
6763 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) {
6764 eee->eee_enabled = 0;
6765 return false;
6766 }
6767 if (eee->advertised & ~advertising) {
6768 eee->advertised = advertising & eee->supported;
6769 return false;
6770 }
6771 }
6772 return true;
6773}
6774
Michael Chanc0c050c2015-10-22 16:01:17 -04006775static int bnxt_update_phy_setting(struct bnxt *bp)
6776{
6777 int rc;
6778 bool update_link = false;
6779 bool update_pause = false;
Michael Chan939f7f02016-04-05 14:08:58 -04006780 bool update_eee = false;
Michael Chanc0c050c2015-10-22 16:01:17 -04006781 struct bnxt_link_info *link_info = &bp->link_info;
6782
6783 rc = bnxt_update_link(bp, true);
6784 if (rc) {
6785 netdev_err(bp->dev, "failed to update link (rc: %x)\n",
6786 rc);
6787 return rc;
6788 }
Michael Chan33dac242017-02-12 19:18:15 -05006789 if (!BNXT_SINGLE_PF(bp))
6790 return 0;
6791
Michael Chanc0c050c2015-10-22 16:01:17 -04006792 if ((link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) &&
Michael Chanc9ee9512016-04-05 14:08:56 -04006793 (link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH) !=
6794 link_info->req_flow_ctrl)
Michael Chanc0c050c2015-10-22 16:01:17 -04006795 update_pause = true;
6796 if (!(link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) &&
6797 link_info->force_pause_setting != link_info->req_flow_ctrl)
6798 update_pause = true;
Michael Chanc0c050c2015-10-22 16:01:17 -04006799 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) {
6800 if (BNXT_AUTO_MODE(link_info->auto_mode))
6801 update_link = true;
6802 if (link_info->req_link_speed != link_info->force_link_speed)
6803 update_link = true;
Michael Chande730182016-02-19 19:43:20 -05006804 if (link_info->req_duplex != link_info->duplex_setting)
6805 update_link = true;
Michael Chanc0c050c2015-10-22 16:01:17 -04006806 } else {
6807 if (link_info->auto_mode == BNXT_LINK_AUTO_NONE)
6808 update_link = true;
6809 if (link_info->advertising != link_info->auto_link_speeds)
6810 update_link = true;
Michael Chanc0c050c2015-10-22 16:01:17 -04006811 }
6812
Michael Chan16d663a2016-11-16 21:13:07 -05006813 /* The last close may have shutdown the link, so need to call
6814 * PHY_CFG to bring it back up.
6815 */
6816 if (!netif_carrier_ok(bp->dev))
6817 update_link = true;
6818
Michael Chan939f7f02016-04-05 14:08:58 -04006819 if (!bnxt_eee_config_ok(bp))
6820 update_eee = true;
6821
Michael Chanc0c050c2015-10-22 16:01:17 -04006822 if (update_link)
Michael Chan939f7f02016-04-05 14:08:58 -04006823 rc = bnxt_hwrm_set_link_setting(bp, update_pause, update_eee);
Michael Chanc0c050c2015-10-22 16:01:17 -04006824 else if (update_pause)
6825 rc = bnxt_hwrm_set_pause(bp);
6826 if (rc) {
6827 netdev_err(bp->dev, "failed to update phy setting (rc: %x)\n",
6828 rc);
6829 return rc;
6830 }
6831
6832 return rc;
6833}
6834
Jeffrey Huang11809492015-11-05 16:25:49 -05006835/* Common routine to pre-map certain register block to different GRC window.
6836 * A PF has 16 4K windows and a VF has 4 4K windows. However, only 15 windows
6837 * in PF and 3 windows in VF that can be customized to map in different
6838 * register blocks.
6839 */
6840static void bnxt_preset_reg_win(struct bnxt *bp)
6841{
6842 if (BNXT_PF(bp)) {
6843 /* CAG registers map to GRC window #4 */
6844 writel(BNXT_CAG_REG_BASE,
6845 bp->bar0 + BNXT_GRCPF_REG_WINDOW_BASE_OUT + 12);
6846 }
6847}
6848
Michael Chanc0c050c2015-10-22 16:01:17 -04006849static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
6850{
6851 int rc = 0;
6852
Jeffrey Huang11809492015-11-05 16:25:49 -05006853 bnxt_preset_reg_win(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04006854 netif_carrier_off(bp->dev);
6855 if (irq_re_init) {
Michael Chan674f50a2018-01-17 03:21:09 -05006856 rc = bnxt_reserve_rings(bp);
6857 if (rc)
6858 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04006859 }
6860 if ((bp->flags & BNXT_FLAG_RFS) &&
6861 !(bp->flags & BNXT_FLAG_USING_MSIX)) {
6862 /* disable RFS if falling back to INTA */
6863 bp->dev->hw_features &= ~NETIF_F_NTUPLE;
6864 bp->flags &= ~BNXT_FLAG_RFS;
6865 }
6866
6867 rc = bnxt_alloc_mem(bp, irq_re_init);
6868 if (rc) {
6869 netdev_err(bp->dev, "bnxt_alloc_mem err: %x\n", rc);
6870 goto open_err_free_mem;
6871 }
6872
6873 if (irq_re_init) {
6874 bnxt_init_napi(bp);
6875 rc = bnxt_request_irq(bp);
6876 if (rc) {
6877 netdev_err(bp->dev, "bnxt_request_irq err: %x\n", rc);
6878 goto open_err;
6879 }
6880 }
6881
6882 bnxt_enable_napi(bp);
6883
6884 rc = bnxt_init_nic(bp, irq_re_init);
6885 if (rc) {
6886 netdev_err(bp->dev, "bnxt_init_nic err: %x\n", rc);
6887 goto open_err;
6888 }
6889
6890 if (link_re_init) {
Michael Chane2dc9b62017-10-13 21:09:30 -04006891 mutex_lock(&bp->link_lock);
Michael Chanc0c050c2015-10-22 16:01:17 -04006892 rc = bnxt_update_phy_setting(bp);
Michael Chane2dc9b62017-10-13 21:09:30 -04006893 mutex_unlock(&bp->link_lock);
Michael Chanc0c050c2015-10-22 16:01:17 -04006894 if (rc)
Michael Chanba41d462016-02-19 19:43:21 -05006895 netdev_warn(bp->dev, "failed to update phy settings\n");
Michael Chanc0c050c2015-10-22 16:01:17 -04006896 }
6897
Alexander Duyck7cdd5fc2016-06-16 12:21:36 -07006898 if (irq_re_init)
Alexander Duyckad51b8e2016-06-16 12:21:19 -07006899 udp_tunnel_get_rx_info(bp->dev);
Michael Chanc0c050c2015-10-22 16:01:17 -04006900
Michael Chancaefe522015-12-09 19:35:42 -05006901 set_bit(BNXT_STATE_OPEN, &bp->state);
Michael Chanc0c050c2015-10-22 16:01:17 -04006902 bnxt_enable_int(bp);
6903 /* Enable TX queues */
6904 bnxt_tx_enable(bp);
6905 mod_timer(&bp->timer, jiffies + bp->current_interval);
Michael Chan10289be2016-05-15 03:04:49 -04006906 /* Poll link status and check for SFP+ module status */
6907 bnxt_get_port_module_status(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04006908
Sathya Perlaee5c7fb2017-07-24 12:34:28 -04006909 /* VF-reps may need to be re-opened after the PF is re-opened */
6910 if (BNXT_PF(bp))
6911 bnxt_vf_reps_open(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04006912 return 0;
6913
6914open_err:
6915 bnxt_disable_napi(bp);
6916 bnxt_del_napi(bp);
6917
6918open_err_free_mem:
6919 bnxt_free_skbs(bp);
6920 bnxt_free_irq(bp);
6921 bnxt_free_mem(bp, true);
6922 return rc;
6923}
6924
6925/* rtnl_lock held */
6926int bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
6927{
6928 int rc = 0;
6929
6930 rc = __bnxt_open_nic(bp, irq_re_init, link_re_init);
6931 if (rc) {
6932 netdev_err(bp->dev, "nic open fail (rc: %x)\n", rc);
6933 dev_close(bp->dev);
6934 }
6935 return rc;
6936}
6937
Michael Chanf7dc1ea2017-04-04 18:14:13 -04006938/* rtnl_lock held, open the NIC half way by allocating all resources, but
6939 * NAPI, IRQ, and TX are not enabled. This is mainly used for offline
6940 * self tests.
6941 */
6942int bnxt_half_open_nic(struct bnxt *bp)
6943{
6944 int rc = 0;
6945
6946 rc = bnxt_alloc_mem(bp, false);
6947 if (rc) {
6948 netdev_err(bp->dev, "bnxt_alloc_mem err: %x\n", rc);
6949 goto half_open_err;
6950 }
6951 rc = bnxt_init_nic(bp, false);
6952 if (rc) {
6953 netdev_err(bp->dev, "bnxt_init_nic err: %x\n", rc);
6954 goto half_open_err;
6955 }
6956 return 0;
6957
6958half_open_err:
6959 bnxt_free_skbs(bp);
6960 bnxt_free_mem(bp, false);
6961 dev_close(bp->dev);
6962 return rc;
6963}
6964
6965/* rtnl_lock held, this call can only be made after a previous successful
6966 * call to bnxt_half_open_nic().
6967 */
6968void bnxt_half_close_nic(struct bnxt *bp)
6969{
6970 bnxt_hwrm_resource_free(bp, false, false);
6971 bnxt_free_skbs(bp);
6972 bnxt_free_mem(bp, false);
6973}
6974
Michael Chanc0c050c2015-10-22 16:01:17 -04006975static int bnxt_open(struct net_device *dev)
6976{
6977 struct bnxt *bp = netdev_priv(dev);
Michael Chanc0c050c2015-10-22 16:01:17 -04006978
Michael Chanc0c050c2015-10-22 16:01:17 -04006979 return __bnxt_open_nic(bp, true, true);
6980}
6981
Michael Chanf9b76eb2017-07-11 13:05:34 -04006982static bool bnxt_drv_busy(struct bnxt *bp)
6983{
6984 return (test_bit(BNXT_STATE_IN_SP_TASK, &bp->state) ||
6985 test_bit(BNXT_STATE_READ_STATS, &bp->state));
6986}
6987
Michael Chan86e953d2018-01-17 03:21:04 -05006988static void __bnxt_close_nic(struct bnxt *bp, bool irq_re_init,
6989 bool link_re_init)
Michael Chanc0c050c2015-10-22 16:01:17 -04006990{
Sathya Perlaee5c7fb2017-07-24 12:34:28 -04006991 /* Close the VF-reps before closing PF */
6992 if (BNXT_PF(bp))
6993 bnxt_vf_reps_close(bp);
Michael Chan86e953d2018-01-17 03:21:04 -05006994
Michael Chanc0c050c2015-10-22 16:01:17 -04006995 /* Change device state to avoid TX queue wake up's */
6996 bnxt_tx_disable(bp);
6997
Michael Chancaefe522015-12-09 19:35:42 -05006998 clear_bit(BNXT_STATE_OPEN, &bp->state);
Michael Chan4cebdce2015-12-09 19:35:43 -05006999 smp_mb__after_atomic();
Michael Chanf9b76eb2017-07-11 13:05:34 -04007000 while (bnxt_drv_busy(bp))
Michael Chan4cebdce2015-12-09 19:35:43 -05007001 msleep(20);
Michael Chanc0c050c2015-10-22 16:01:17 -04007002
Michael Chan9d8bc092016-12-29 12:13:33 -05007003 /* Flush rings and and disable interrupts */
Michael Chanc0c050c2015-10-22 16:01:17 -04007004 bnxt_shutdown_nic(bp, irq_re_init);
7005
7006 /* TODO CHIMP_FW: Link/PHY related cleanup if (link_re_init) */
7007
7008 bnxt_disable_napi(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04007009 del_timer_sync(&bp->timer);
7010 bnxt_free_skbs(bp);
7011
7012 if (irq_re_init) {
7013 bnxt_free_irq(bp);
7014 bnxt_del_napi(bp);
7015 }
7016 bnxt_free_mem(bp, irq_re_init);
Michael Chan86e953d2018-01-17 03:21:04 -05007017}
7018
7019int bnxt_close_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
7020{
7021 int rc = 0;
7022
7023#ifdef CONFIG_BNXT_SRIOV
7024 if (bp->sriov_cfg) {
7025 rc = wait_event_interruptible_timeout(bp->sriov_cfg_wait,
7026 !bp->sriov_cfg,
7027 BNXT_SRIOV_CFG_WAIT_TMO);
7028 if (rc)
7029 netdev_warn(bp->dev, "timeout waiting for SRIOV config operation to complete!\n");
7030 }
7031#endif
7032 __bnxt_close_nic(bp, irq_re_init, link_re_init);
Michael Chanc0c050c2015-10-22 16:01:17 -04007033 return rc;
7034}
7035
7036static int bnxt_close(struct net_device *dev)
7037{
7038 struct bnxt *bp = netdev_priv(dev);
7039
7040 bnxt_close_nic(bp, true, true);
Michael Chan33f7d552016-04-11 04:11:12 -04007041 bnxt_hwrm_shutdown_link(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04007042 return 0;
7043}
7044
7045/* rtnl_lock held */
7046static int bnxt_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
7047{
7048 switch (cmd) {
7049 case SIOCGMIIPHY:
7050 /* fallthru */
7051 case SIOCGMIIREG: {
7052 if (!netif_running(dev))
7053 return -EAGAIN;
7054
7055 return 0;
7056 }
7057
7058 case SIOCSMIIREG:
7059 if (!netif_running(dev))
7060 return -EAGAIN;
7061
7062 return 0;
7063
7064 default:
7065 /* do nothing */
7066 break;
7067 }
7068 return -EOPNOTSUPP;
7069}
7070
stephen hemmingerbc1f4472017-01-06 19:12:52 -08007071static void
Michael Chanc0c050c2015-10-22 16:01:17 -04007072bnxt_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
7073{
7074 u32 i;
7075 struct bnxt *bp = netdev_priv(dev);
7076
Michael Chanf9b76eb2017-07-11 13:05:34 -04007077 set_bit(BNXT_STATE_READ_STATS, &bp->state);
7078 /* Make sure bnxt_close_nic() sees that we are reading stats before
7079 * we check the BNXT_STATE_OPEN flag.
7080 */
7081 smp_mb__after_atomic();
7082 if (!test_bit(BNXT_STATE_OPEN, &bp->state)) {
7083 clear_bit(BNXT_STATE_READ_STATS, &bp->state);
stephen hemmingerbc1f4472017-01-06 19:12:52 -08007084 return;
Michael Chanf9b76eb2017-07-11 13:05:34 -04007085 }
Michael Chanc0c050c2015-10-22 16:01:17 -04007086
7087 /* TODO check if we need to synchronize with bnxt_close path */
7088 for (i = 0; i < bp->cp_nr_rings; i++) {
7089 struct bnxt_napi *bnapi = bp->bnapi[i];
7090 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
7091 struct ctx_hw_stats *hw_stats = cpr->hw_stats;
7092
7093 stats->rx_packets += le64_to_cpu(hw_stats->rx_ucast_pkts);
7094 stats->rx_packets += le64_to_cpu(hw_stats->rx_mcast_pkts);
7095 stats->rx_packets += le64_to_cpu(hw_stats->rx_bcast_pkts);
7096
7097 stats->tx_packets += le64_to_cpu(hw_stats->tx_ucast_pkts);
7098 stats->tx_packets += le64_to_cpu(hw_stats->tx_mcast_pkts);
7099 stats->tx_packets += le64_to_cpu(hw_stats->tx_bcast_pkts);
7100
7101 stats->rx_bytes += le64_to_cpu(hw_stats->rx_ucast_bytes);
7102 stats->rx_bytes += le64_to_cpu(hw_stats->rx_mcast_bytes);
7103 stats->rx_bytes += le64_to_cpu(hw_stats->rx_bcast_bytes);
7104
7105 stats->tx_bytes += le64_to_cpu(hw_stats->tx_ucast_bytes);
7106 stats->tx_bytes += le64_to_cpu(hw_stats->tx_mcast_bytes);
7107 stats->tx_bytes += le64_to_cpu(hw_stats->tx_bcast_bytes);
7108
7109 stats->rx_missed_errors +=
7110 le64_to_cpu(hw_stats->rx_discard_pkts);
7111
7112 stats->multicast += le64_to_cpu(hw_stats->rx_mcast_pkts);
7113
Michael Chanc0c050c2015-10-22 16:01:17 -04007114 stats->tx_dropped += le64_to_cpu(hw_stats->tx_drop_pkts);
7115 }
7116
Michael Chan9947f832016-03-07 15:38:46 -05007117 if (bp->flags & BNXT_FLAG_PORT_STATS) {
7118 struct rx_port_stats *rx = bp->hw_rx_port_stats;
7119 struct tx_port_stats *tx = bp->hw_tx_port_stats;
7120
7121 stats->rx_crc_errors = le64_to_cpu(rx->rx_fcs_err_frames);
7122 stats->rx_frame_errors = le64_to_cpu(rx->rx_align_err_frames);
7123 stats->rx_length_errors = le64_to_cpu(rx->rx_undrsz_frames) +
7124 le64_to_cpu(rx->rx_ovrsz_frames) +
7125 le64_to_cpu(rx->rx_runt_frames);
7126 stats->rx_errors = le64_to_cpu(rx->rx_false_carrier_frames) +
7127 le64_to_cpu(rx->rx_jbr_frames);
7128 stats->collisions = le64_to_cpu(tx->tx_total_collisions);
7129 stats->tx_fifo_errors = le64_to_cpu(tx->tx_fifo_underruns);
7130 stats->tx_errors = le64_to_cpu(tx->tx_err);
7131 }
Michael Chanf9b76eb2017-07-11 13:05:34 -04007132 clear_bit(BNXT_STATE_READ_STATS, &bp->state);
Michael Chanc0c050c2015-10-22 16:01:17 -04007133}
7134
7135static bool bnxt_mc_list_updated(struct bnxt *bp, u32 *rx_mask)
7136{
7137 struct net_device *dev = bp->dev;
7138 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
7139 struct netdev_hw_addr *ha;
7140 u8 *haddr;
7141 int mc_count = 0;
7142 bool update = false;
7143 int off = 0;
7144
7145 netdev_for_each_mc_addr(ha, dev) {
7146 if (mc_count >= BNXT_MAX_MC_ADDRS) {
7147 *rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST;
7148 vnic->mc_list_count = 0;
7149 return false;
7150 }
7151 haddr = ha->addr;
7152 if (!ether_addr_equal(haddr, vnic->mc_list + off)) {
7153 memcpy(vnic->mc_list + off, haddr, ETH_ALEN);
7154 update = true;
7155 }
7156 off += ETH_ALEN;
7157 mc_count++;
7158 }
7159 if (mc_count)
7160 *rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_MCAST;
7161
7162 if (mc_count != vnic->mc_list_count) {
7163 vnic->mc_list_count = mc_count;
7164 update = true;
7165 }
7166 return update;
7167}
7168
7169static bool bnxt_uc_list_updated(struct bnxt *bp)
7170{
7171 struct net_device *dev = bp->dev;
7172 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
7173 struct netdev_hw_addr *ha;
7174 int off = 0;
7175
7176 if (netdev_uc_count(dev) != (vnic->uc_filter_count - 1))
7177 return true;
7178
7179 netdev_for_each_uc_addr(ha, dev) {
7180 if (!ether_addr_equal(ha->addr, vnic->uc_list + off))
7181 return true;
7182
7183 off += ETH_ALEN;
7184 }
7185 return false;
7186}
7187
7188static void bnxt_set_rx_mode(struct net_device *dev)
7189{
7190 struct bnxt *bp = netdev_priv(dev);
7191 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
7192 u32 mask = vnic->rx_mask;
7193 bool mc_update = false;
7194 bool uc_update;
7195
7196 if (!netif_running(dev))
7197 return;
7198
7199 mask &= ~(CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS |
7200 CFA_L2_SET_RX_MASK_REQ_MASK_MCAST |
7201 CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST);
7202
Michael Chan17c71ac2016-07-01 18:46:27 -04007203 if ((dev->flags & IFF_PROMISC) && bnxt_promisc_ok(bp))
Michael Chanc0c050c2015-10-22 16:01:17 -04007204 mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS;
7205
7206 uc_update = bnxt_uc_list_updated(bp);
7207
7208 if (dev->flags & IFF_ALLMULTI) {
7209 mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST;
7210 vnic->mc_list_count = 0;
7211 } else {
7212 mc_update = bnxt_mc_list_updated(bp, &mask);
7213 }
7214
7215 if (mask != vnic->rx_mask || uc_update || mc_update) {
7216 vnic->rx_mask = mask;
7217
7218 set_bit(BNXT_RX_MASK_SP_EVENT, &bp->sp_event);
Michael Chanc213eae2017-10-13 21:09:29 -04007219 bnxt_queue_sp_work(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04007220 }
7221}
7222
Michael Chanb664f002015-12-02 01:54:08 -05007223static int bnxt_cfg_rx_mode(struct bnxt *bp)
Michael Chanc0c050c2015-10-22 16:01:17 -04007224{
7225 struct net_device *dev = bp->dev;
7226 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
7227 struct netdev_hw_addr *ha;
7228 int i, off = 0, rc;
7229 bool uc_update;
7230
7231 netif_addr_lock_bh(dev);
7232 uc_update = bnxt_uc_list_updated(bp);
7233 netif_addr_unlock_bh(dev);
7234
7235 if (!uc_update)
7236 goto skip_uc;
7237
7238 mutex_lock(&bp->hwrm_cmd_lock);
7239 for (i = 1; i < vnic->uc_filter_count; i++) {
7240 struct hwrm_cfa_l2_filter_free_input req = {0};
7241
7242 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_L2_FILTER_FREE, -1,
7243 -1);
7244
7245 req.l2_filter_id = vnic->fw_l2_filter_id[i];
7246
7247 rc = _hwrm_send_message(bp, &req, sizeof(req),
7248 HWRM_CMD_TIMEOUT);
7249 }
7250 mutex_unlock(&bp->hwrm_cmd_lock);
7251
7252 vnic->uc_filter_count = 1;
7253
7254 netif_addr_lock_bh(dev);
7255 if (netdev_uc_count(dev) > (BNXT_MAX_UC_ADDRS - 1)) {
7256 vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS;
7257 } else {
7258 netdev_for_each_uc_addr(ha, dev) {
7259 memcpy(vnic->uc_list + off, ha->addr, ETH_ALEN);
7260 off += ETH_ALEN;
7261 vnic->uc_filter_count++;
7262 }
7263 }
7264 netif_addr_unlock_bh(dev);
7265
7266 for (i = 1, off = 0; i < vnic->uc_filter_count; i++, off += ETH_ALEN) {
7267 rc = bnxt_hwrm_set_vnic_filter(bp, 0, i, vnic->uc_list + off);
7268 if (rc) {
7269 netdev_err(bp->dev, "HWRM vnic filter failure rc: %x\n",
7270 rc);
7271 vnic->uc_filter_count = i;
Michael Chanb664f002015-12-02 01:54:08 -05007272 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04007273 }
7274 }
7275
7276skip_uc:
7277 rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, 0);
7278 if (rc)
7279 netdev_err(bp->dev, "HWRM cfa l2 rx mask failure rc: %x\n",
7280 rc);
Michael Chanb664f002015-12-02 01:54:08 -05007281
7282 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04007283}
7284
Michael Chan8079e8f2016-12-29 12:13:37 -05007285/* If the chip and firmware supports RFS */
7286static bool bnxt_rfs_supported(struct bnxt *bp)
7287{
7288 if (BNXT_PF(bp) && !BNXT_CHIP_TYPE_NITRO_A0(bp))
7289 return true;
Michael Chanae10ae72016-12-29 12:13:38 -05007290 if (bp->flags & BNXT_FLAG_NEW_RSS_CAP)
7291 return true;
Michael Chan8079e8f2016-12-29 12:13:37 -05007292 return false;
7293}
7294
7295/* If runtime conditions support RFS */
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007296static bool bnxt_rfs_capable(struct bnxt *bp)
7297{
7298#ifdef CONFIG_RFS_ACCEL
Michael Chan8079e8f2016-12-29 12:13:37 -05007299 int vnics, max_vnics, max_rss_ctxs;
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007300
Michael Chan964fd482017-02-12 19:18:13 -05007301 if (!(bp->flags & BNXT_FLAG_MSIX_CAP))
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007302 return false;
7303
7304 vnics = 1 + bp->rx_nr_rings;
Michael Chan8079e8f2016-12-29 12:13:37 -05007305 max_vnics = bnxt_get_max_func_vnics(bp);
7306 max_rss_ctxs = bnxt_get_max_func_rss_ctxs(bp);
Michael Chanae10ae72016-12-29 12:13:38 -05007307
7308 /* RSS contexts not a limiting factor */
7309 if (bp->flags & BNXT_FLAG_NEW_RSS_CAP)
7310 max_rss_ctxs = max_vnics;
Michael Chan8079e8f2016-12-29 12:13:37 -05007311 if (vnics > max_vnics || vnics > max_rss_ctxs) {
Michael Chan6a1eef52018-01-17 03:21:10 -05007312 if (bp->rx_nr_rings > 1)
7313 netdev_warn(bp->dev,
7314 "Not enough resources to support NTUPLE filters, enough resources for up to %d rx rings\n",
7315 min(max_rss_ctxs - 1, max_vnics - 1));
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007316 return false;
Vasundhara Volama2304902016-07-25 12:33:36 -04007317 }
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007318
Michael Chan6a1eef52018-01-17 03:21:10 -05007319 if (!(bp->flags & BNXT_FLAG_NEW_RM))
7320 return true;
7321
7322 if (vnics == bp->hw_resc.resv_vnics)
7323 return true;
7324
7325 bnxt_hwrm_reserve_rings(bp, 0, 0, 0, 0, vnics);
7326 if (vnics <= bp->hw_resc.resv_vnics)
7327 return true;
7328
7329 netdev_warn(bp->dev, "Unable to reserve resources to support NTUPLE filters.\n");
7330 bnxt_hwrm_reserve_rings(bp, 0, 0, 0, 0, 1);
7331 return false;
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007332#else
7333 return false;
7334#endif
7335}
7336
Michael Chanc0c050c2015-10-22 16:01:17 -04007337static netdev_features_t bnxt_fix_features(struct net_device *dev,
7338 netdev_features_t features)
7339{
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007340 struct bnxt *bp = netdev_priv(dev);
7341
Vasundhara Volama2304902016-07-25 12:33:36 -04007342 if ((features & NETIF_F_NTUPLE) && !bnxt_rfs_capable(bp))
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007343 features &= ~NETIF_F_NTUPLE;
Michael Chan5a9f6b22016-06-06 02:37:15 -04007344
Michael Chan1054aee2017-12-16 03:09:42 -05007345 if (bp->flags & BNXT_FLAG_NO_AGG_RINGS)
7346 features &= ~(NETIF_F_LRO | NETIF_F_GRO_HW);
7347
7348 if (!(features & NETIF_F_GRO))
7349 features &= ~NETIF_F_GRO_HW;
7350
7351 if (features & NETIF_F_GRO_HW)
7352 features &= ~NETIF_F_LRO;
7353
Michael Chan5a9f6b22016-06-06 02:37:15 -04007354 /* Both CTAG and STAG VLAN accelaration on the RX side have to be
7355 * turned on or off together.
7356 */
7357 if ((features & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX)) !=
7358 (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX)) {
7359 if (dev->features & NETIF_F_HW_VLAN_CTAG_RX)
7360 features &= ~(NETIF_F_HW_VLAN_CTAG_RX |
7361 NETIF_F_HW_VLAN_STAG_RX);
7362 else
7363 features |= NETIF_F_HW_VLAN_CTAG_RX |
7364 NETIF_F_HW_VLAN_STAG_RX;
7365 }
Michael Chancf6645f2016-06-13 02:25:28 -04007366#ifdef CONFIG_BNXT_SRIOV
7367 if (BNXT_VF(bp)) {
7368 if (bp->vf.vlan) {
7369 features &= ~(NETIF_F_HW_VLAN_CTAG_RX |
7370 NETIF_F_HW_VLAN_STAG_RX);
7371 }
7372 }
7373#endif
Michael Chanc0c050c2015-10-22 16:01:17 -04007374 return features;
7375}
7376
7377static int bnxt_set_features(struct net_device *dev, netdev_features_t features)
7378{
7379 struct bnxt *bp = netdev_priv(dev);
7380 u32 flags = bp->flags;
7381 u32 changes;
7382 int rc = 0;
7383 bool re_init = false;
7384 bool update_tpa = false;
7385
7386 flags &= ~BNXT_FLAG_ALL_CONFIG_FEATS;
Michael Chan1054aee2017-12-16 03:09:42 -05007387 if (features & NETIF_F_GRO_HW)
Michael Chanc0c050c2015-10-22 16:01:17 -04007388 flags |= BNXT_FLAG_GRO;
Michael Chan1054aee2017-12-16 03:09:42 -05007389 else if (features & NETIF_F_LRO)
Michael Chanc0c050c2015-10-22 16:01:17 -04007390 flags |= BNXT_FLAG_LRO;
7391
Michael Chanbdbd1eb2016-12-29 12:13:43 -05007392 if (bp->flags & BNXT_FLAG_NO_AGG_RINGS)
7393 flags &= ~BNXT_FLAG_TPA;
7394
Michael Chanc0c050c2015-10-22 16:01:17 -04007395 if (features & NETIF_F_HW_VLAN_CTAG_RX)
7396 flags |= BNXT_FLAG_STRIP_VLAN;
7397
7398 if (features & NETIF_F_NTUPLE)
7399 flags |= BNXT_FLAG_RFS;
7400
7401 changes = flags ^ bp->flags;
7402 if (changes & BNXT_FLAG_TPA) {
7403 update_tpa = true;
7404 if ((bp->flags & BNXT_FLAG_TPA) == 0 ||
7405 (flags & BNXT_FLAG_TPA) == 0)
7406 re_init = true;
7407 }
7408
7409 if (changes & ~BNXT_FLAG_TPA)
7410 re_init = true;
7411
7412 if (flags != bp->flags) {
7413 u32 old_flags = bp->flags;
7414
7415 bp->flags = flags;
7416
Michael Chan2bcfa6f2015-12-27 18:19:24 -05007417 if (!test_bit(BNXT_STATE_OPEN, &bp->state)) {
Michael Chanc0c050c2015-10-22 16:01:17 -04007418 if (update_tpa)
7419 bnxt_set_ring_params(bp);
7420 return rc;
7421 }
7422
7423 if (re_init) {
7424 bnxt_close_nic(bp, false, false);
7425 if (update_tpa)
7426 bnxt_set_ring_params(bp);
7427
7428 return bnxt_open_nic(bp, false, false);
7429 }
7430 if (update_tpa) {
7431 rc = bnxt_set_tpa(bp,
7432 (flags & BNXT_FLAG_TPA) ?
7433 true : false);
7434 if (rc)
7435 bp->flags = old_flags;
7436 }
7437 }
7438 return rc;
7439}
7440
Michael Chan9f554592016-01-02 23:44:58 -05007441static void bnxt_dump_tx_sw_state(struct bnxt_napi *bnapi)
7442{
Michael Chanb6ab4b02016-01-02 23:44:59 -05007443 struct bnxt_tx_ring_info *txr = bnapi->tx_ring;
Michael Chan9f554592016-01-02 23:44:58 -05007444 int i = bnapi->index;
7445
Michael Chan3b2b7d92016-01-02 23:45:00 -05007446 if (!txr)
7447 return;
7448
Michael Chan9f554592016-01-02 23:44:58 -05007449 netdev_info(bnapi->bp->dev, "[%d]: tx{fw_ring: %d prod: %x cons: %x}\n",
7450 i, txr->tx_ring_struct.fw_ring_id, txr->tx_prod,
7451 txr->tx_cons);
7452}
7453
7454static void bnxt_dump_rx_sw_state(struct bnxt_napi *bnapi)
7455{
Michael Chanb6ab4b02016-01-02 23:44:59 -05007456 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
Michael Chan9f554592016-01-02 23:44:58 -05007457 int i = bnapi->index;
7458
Michael Chan3b2b7d92016-01-02 23:45:00 -05007459 if (!rxr)
7460 return;
7461
Michael Chan9f554592016-01-02 23:44:58 -05007462 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",
7463 i, rxr->rx_ring_struct.fw_ring_id, rxr->rx_prod,
7464 rxr->rx_agg_ring_struct.fw_ring_id, rxr->rx_agg_prod,
7465 rxr->rx_sw_agg_prod);
7466}
7467
7468static void bnxt_dump_cp_sw_state(struct bnxt_napi *bnapi)
7469{
7470 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
7471 int i = bnapi->index;
7472
7473 netdev_info(bnapi->bp->dev, "[%d]: cp{fw_ring: %d raw_cons: %x}\n",
7474 i, cpr->cp_ring_struct.fw_ring_id, cpr->cp_raw_cons);
7475}
7476
Michael Chanc0c050c2015-10-22 16:01:17 -04007477static void bnxt_dbg_dump_states(struct bnxt *bp)
7478{
7479 int i;
7480 struct bnxt_napi *bnapi;
Michael Chanc0c050c2015-10-22 16:01:17 -04007481
7482 for (i = 0; i < bp->cp_nr_rings; i++) {
7483 bnapi = bp->bnapi[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04007484 if (netif_msg_drv(bp)) {
Michael Chan9f554592016-01-02 23:44:58 -05007485 bnxt_dump_tx_sw_state(bnapi);
7486 bnxt_dump_rx_sw_state(bnapi);
7487 bnxt_dump_cp_sw_state(bnapi);
Michael Chanc0c050c2015-10-22 16:01:17 -04007488 }
7489 }
7490}
7491
Michael Chan6988bd92016-06-13 02:25:29 -04007492static void bnxt_reset_task(struct bnxt *bp, bool silent)
Michael Chanc0c050c2015-10-22 16:01:17 -04007493{
Michael Chan6988bd92016-06-13 02:25:29 -04007494 if (!silent)
7495 bnxt_dbg_dump_states(bp);
Michael Chan028de142015-12-09 19:35:44 -05007496 if (netif_running(bp->dev)) {
Michael Chanb386cd32017-03-08 18:44:33 -05007497 int rc;
7498
7499 if (!silent)
7500 bnxt_ulp_stop(bp);
Michael Chan028de142015-12-09 19:35:44 -05007501 bnxt_close_nic(bp, false, false);
Michael Chanb386cd32017-03-08 18:44:33 -05007502 rc = bnxt_open_nic(bp, false, false);
7503 if (!silent && !rc)
7504 bnxt_ulp_start(bp);
Michael Chan028de142015-12-09 19:35:44 -05007505 }
Michael Chanc0c050c2015-10-22 16:01:17 -04007506}
7507
7508static void bnxt_tx_timeout(struct net_device *dev)
7509{
7510 struct bnxt *bp = netdev_priv(dev);
7511
7512 netdev_err(bp->dev, "TX timeout detected, starting reset task!\n");
7513 set_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event);
Michael Chanc213eae2017-10-13 21:09:29 -04007514 bnxt_queue_sp_work(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04007515}
7516
7517#ifdef CONFIG_NET_POLL_CONTROLLER
7518static void bnxt_poll_controller(struct net_device *dev)
7519{
7520 struct bnxt *bp = netdev_priv(dev);
7521 int i;
7522
Michael Chan2270bc52017-06-23 14:01:01 -04007523 /* Only process tx rings/combined rings in netpoll mode. */
7524 for (i = 0; i < bp->tx_nr_rings; i++) {
7525 struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
Michael Chanc0c050c2015-10-22 16:01:17 -04007526
Michael Chan2270bc52017-06-23 14:01:01 -04007527 napi_schedule(&txr->bnapi->napi);
Michael Chanc0c050c2015-10-22 16:01:17 -04007528 }
7529}
7530#endif
7531
Kees Cooke99e88a2017-10-16 14:43:17 -07007532static void bnxt_timer(struct timer_list *t)
Michael Chanc0c050c2015-10-22 16:01:17 -04007533{
Kees Cooke99e88a2017-10-16 14:43:17 -07007534 struct bnxt *bp = from_timer(bp, t, timer);
Michael Chanc0c050c2015-10-22 16:01:17 -04007535 struct net_device *dev = bp->dev;
7536
7537 if (!netif_running(dev))
7538 return;
7539
7540 if (atomic_read(&bp->intr_sem) != 0)
7541 goto bnxt_restart_timer;
7542
Michael Chanadcc3312017-07-24 12:34:24 -04007543 if (bp->link_info.link_up && (bp->flags & BNXT_FLAG_PORT_STATS) &&
7544 bp->stats_coal_ticks) {
Michael Chan3bdf56c2016-03-07 15:38:45 -05007545 set_bit(BNXT_PERIODIC_STATS_SP_EVENT, &bp->sp_event);
Michael Chanc213eae2017-10-13 21:09:29 -04007546 bnxt_queue_sp_work(bp);
Michael Chan3bdf56c2016-03-07 15:38:45 -05007547 }
Sathya Perla5a84acb2017-10-26 11:51:31 -04007548
7549 if (bnxt_tc_flower_enabled(bp)) {
7550 set_bit(BNXT_FLOW_STATS_SP_EVENT, &bp->sp_event);
7551 bnxt_queue_sp_work(bp);
7552 }
Michael Chanc0c050c2015-10-22 16:01:17 -04007553bnxt_restart_timer:
7554 mod_timer(&bp->timer, jiffies + bp->current_interval);
7555}
7556
Michael Chana551ee92017-01-25 02:55:07 -05007557static void bnxt_rtnl_lock_sp(struct bnxt *bp)
Michael Chan6988bd92016-06-13 02:25:29 -04007558{
Michael Chana551ee92017-01-25 02:55:07 -05007559 /* We are called from bnxt_sp_task which has BNXT_STATE_IN_SP_TASK
7560 * set. If the device is being closed, bnxt_close() may be holding
Michael Chan6988bd92016-06-13 02:25:29 -04007561 * rtnl() and waiting for BNXT_STATE_IN_SP_TASK to clear. So we
7562 * must clear BNXT_STATE_IN_SP_TASK before holding rtnl().
7563 */
7564 clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
7565 rtnl_lock();
Michael Chana551ee92017-01-25 02:55:07 -05007566}
7567
7568static void bnxt_rtnl_unlock_sp(struct bnxt *bp)
7569{
Michael Chan6988bd92016-06-13 02:25:29 -04007570 set_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
7571 rtnl_unlock();
7572}
7573
Michael Chana551ee92017-01-25 02:55:07 -05007574/* Only called from bnxt_sp_task() */
7575static void bnxt_reset(struct bnxt *bp, bool silent)
7576{
7577 bnxt_rtnl_lock_sp(bp);
7578 if (test_bit(BNXT_STATE_OPEN, &bp->state))
7579 bnxt_reset_task(bp, silent);
7580 bnxt_rtnl_unlock_sp(bp);
7581}
7582
Michael Chanc0c050c2015-10-22 16:01:17 -04007583static void bnxt_cfg_ntp_filters(struct bnxt *);
7584
7585static void bnxt_sp_task(struct work_struct *work)
7586{
7587 struct bnxt *bp = container_of(work, struct bnxt, sp_task);
Michael Chanc0c050c2015-10-22 16:01:17 -04007588
Michael Chan4cebdce2015-12-09 19:35:43 -05007589 set_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
7590 smp_mb__after_atomic();
7591 if (!test_bit(BNXT_STATE_OPEN, &bp->state)) {
7592 clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
Michael Chanc0c050c2015-10-22 16:01:17 -04007593 return;
Michael Chan4cebdce2015-12-09 19:35:43 -05007594 }
Michael Chanc0c050c2015-10-22 16:01:17 -04007595
7596 if (test_and_clear_bit(BNXT_RX_MASK_SP_EVENT, &bp->sp_event))
7597 bnxt_cfg_rx_mode(bp);
7598
7599 if (test_and_clear_bit(BNXT_RX_NTP_FLTR_SP_EVENT, &bp->sp_event))
7600 bnxt_cfg_ntp_filters(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04007601 if (test_and_clear_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT, &bp->sp_event))
7602 bnxt_hwrm_exec_fwd_req(bp);
7603 if (test_and_clear_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT, &bp->sp_event)) {
7604 bnxt_hwrm_tunnel_dst_port_alloc(
7605 bp, bp->vxlan_port,
7606 TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN);
7607 }
7608 if (test_and_clear_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT, &bp->sp_event)) {
7609 bnxt_hwrm_tunnel_dst_port_free(
7610 bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN);
7611 }
Alexander Duyck7cdd5fc2016-06-16 12:21:36 -07007612 if (test_and_clear_bit(BNXT_GENEVE_ADD_PORT_SP_EVENT, &bp->sp_event)) {
7613 bnxt_hwrm_tunnel_dst_port_alloc(
7614 bp, bp->nge_port,
7615 TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE);
7616 }
7617 if (test_and_clear_bit(BNXT_GENEVE_DEL_PORT_SP_EVENT, &bp->sp_event)) {
7618 bnxt_hwrm_tunnel_dst_port_free(
7619 bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE);
7620 }
Vasundhara Volam00db3cb2018-03-31 13:54:12 -04007621 if (test_and_clear_bit(BNXT_PERIODIC_STATS_SP_EVENT, &bp->sp_event)) {
Michael Chan3bdf56c2016-03-07 15:38:45 -05007622 bnxt_hwrm_port_qstats(bp);
Vasundhara Volam00db3cb2018-03-31 13:54:12 -04007623 bnxt_hwrm_port_qstats_ext(bp);
7624 }
Michael Chan3bdf56c2016-03-07 15:38:45 -05007625
Michael Chan0eaa24b2017-01-25 02:55:08 -05007626 if (test_and_clear_bit(BNXT_LINK_CHNG_SP_EVENT, &bp->sp_event)) {
Michael Chane2dc9b62017-10-13 21:09:30 -04007627 int rc;
Michael Chan0eaa24b2017-01-25 02:55:08 -05007628
Michael Chane2dc9b62017-10-13 21:09:30 -04007629 mutex_lock(&bp->link_lock);
Michael Chan0eaa24b2017-01-25 02:55:08 -05007630 if (test_and_clear_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT,
7631 &bp->sp_event))
7632 bnxt_hwrm_phy_qcaps(bp);
7633
Michael Chane2dc9b62017-10-13 21:09:30 -04007634 rc = bnxt_update_link(bp, true);
7635 mutex_unlock(&bp->link_lock);
Michael Chan0eaa24b2017-01-25 02:55:08 -05007636 if (rc)
7637 netdev_err(bp->dev, "SP task can't update link (rc: %x)\n",
7638 rc);
7639 }
Michael Chan90c694b2017-01-25 02:55:09 -05007640 if (test_and_clear_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT, &bp->sp_event)) {
Michael Chane2dc9b62017-10-13 21:09:30 -04007641 mutex_lock(&bp->link_lock);
7642 bnxt_get_port_module_status(bp);
7643 mutex_unlock(&bp->link_lock);
Michael Chan90c694b2017-01-25 02:55:09 -05007644 }
Sathya Perla5a84acb2017-10-26 11:51:31 -04007645
7646 if (test_and_clear_bit(BNXT_FLOW_STATS_SP_EVENT, &bp->sp_event))
7647 bnxt_tc_flow_stats_work(bp);
7648
Michael Chane2dc9b62017-10-13 21:09:30 -04007649 /* These functions below will clear BNXT_STATE_IN_SP_TASK. They
7650 * must be the last functions to be called before exiting.
7651 */
Michael Chanc0c050c2015-10-22 16:01:17 -04007652 if (test_and_clear_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event))
7653 bnxt_reset(bp, false);
7654
7655 if (test_and_clear_bit(BNXT_RESET_TASK_SILENT_SP_EVENT, &bp->sp_event))
7656 bnxt_reset(bp, true);
7657
Michael Chanc0c050c2015-10-22 16:01:17 -04007658 smp_mb__before_atomic();
7659 clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
7660}
7661
Michael Chand1e79252017-02-06 16:55:38 -05007662/* Under rtnl_lock */
Michael Chan98fdbe72017-08-28 13:40:26 -04007663int bnxt_check_rings(struct bnxt *bp, int tx, int rx, bool sh, int tcs,
7664 int tx_xdp)
Michael Chand1e79252017-02-06 16:55:38 -05007665{
7666 int max_rx, max_tx, tx_sets = 1;
7667 int tx_rings_needed;
Michael Chan8f23d632018-01-17 03:21:12 -05007668 int rx_rings = rx;
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05007669 int cp, vnics, rc;
Michael Chand1e79252017-02-06 16:55:38 -05007670
Michael Chand1e79252017-02-06 16:55:38 -05007671 if (tcs)
7672 tx_sets = tcs;
7673
7674 rc = bnxt_get_max_rings(bp, &max_rx, &max_tx, sh);
7675 if (rc)
7676 return rc;
7677
7678 if (max_rx < rx)
7679 return -ENOMEM;
7680
Michael Chan5f449242017-02-06 16:55:40 -05007681 tx_rings_needed = tx * tx_sets + tx_xdp;
Michael Chand1e79252017-02-06 16:55:38 -05007682 if (max_tx < tx_rings_needed)
7683 return -ENOMEM;
7684
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05007685 vnics = 1;
7686 if (bp->flags & BNXT_FLAG_RFS)
7687 vnics += rx_rings;
7688
Michael Chan8f23d632018-01-17 03:21:12 -05007689 if (bp->flags & BNXT_FLAG_AGG_RINGS)
7690 rx_rings <<= 1;
7691 cp = sh ? max_t(int, tx_rings_needed, rx) : tx_rings_needed + rx;
Michael Chan11c3ec72018-04-11 11:50:17 -04007692 if (bp->flags & BNXT_FLAG_NEW_RM)
7693 cp += bnxt_get_ulp_msix_num(bp);
Eddie Wai6fc2ffd2018-03-09 23:46:04 -05007694 return bnxt_hwrm_check_rings(bp, tx_rings_needed, rx_rings, rx, cp,
7695 vnics);
Michael Chand1e79252017-02-06 16:55:38 -05007696}
7697
Sathya Perla17086392017-02-20 19:25:18 -05007698static void bnxt_unmap_bars(struct bnxt *bp, struct pci_dev *pdev)
7699{
7700 if (bp->bar2) {
7701 pci_iounmap(pdev, bp->bar2);
7702 bp->bar2 = NULL;
7703 }
7704
7705 if (bp->bar1) {
7706 pci_iounmap(pdev, bp->bar1);
7707 bp->bar1 = NULL;
7708 }
7709
7710 if (bp->bar0) {
7711 pci_iounmap(pdev, bp->bar0);
7712 bp->bar0 = NULL;
7713 }
7714}
7715
7716static void bnxt_cleanup_pci(struct bnxt *bp)
7717{
7718 bnxt_unmap_bars(bp, bp->pdev);
7719 pci_release_regions(bp->pdev);
7720 pci_disable_device(bp->pdev);
7721}
7722
Michael Chan18775aa2017-10-26 11:51:27 -04007723static void bnxt_init_dflt_coal(struct bnxt *bp)
7724{
7725 struct bnxt_coal *coal;
7726
7727 /* Tick values in micro seconds.
7728 * 1 coal_buf x bufs_per_record = 1 completion record.
7729 */
7730 coal = &bp->rx_coal;
7731 coal->coal_ticks = 14;
7732 coal->coal_bufs = 30;
7733 coal->coal_ticks_irq = 1;
7734 coal->coal_bufs_irq = 2;
7735 coal->idle_thresh = 25;
7736 coal->bufs_per_record = 2;
7737 coal->budget = 64; /* NAPI budget */
7738
7739 coal = &bp->tx_coal;
7740 coal->coal_ticks = 28;
7741 coal->coal_bufs = 30;
7742 coal->coal_ticks_irq = 2;
7743 coal->coal_bufs_irq = 2;
7744 coal->bufs_per_record = 1;
7745
7746 bp->stats_coal_ticks = BNXT_DEF_STATS_COAL_TICKS;
7747}
7748
Michael Chanc0c050c2015-10-22 16:01:17 -04007749static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev)
7750{
7751 int rc;
7752 struct bnxt *bp = netdev_priv(dev);
7753
7754 SET_NETDEV_DEV(dev, &pdev->dev);
7755
7756 /* enable device (incl. PCI PM wakeup), and bus-mastering */
7757 rc = pci_enable_device(pdev);
7758 if (rc) {
7759 dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n");
7760 goto init_err;
7761 }
7762
7763 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
7764 dev_err(&pdev->dev,
7765 "Cannot find PCI device base address, aborting\n");
7766 rc = -ENODEV;
7767 goto init_err_disable;
7768 }
7769
7770 rc = pci_request_regions(pdev, DRV_MODULE_NAME);
7771 if (rc) {
7772 dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting\n");
7773 goto init_err_disable;
7774 }
7775
7776 if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)) != 0 &&
7777 dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)) != 0) {
7778 dev_err(&pdev->dev, "System does not support DMA, aborting\n");
7779 goto init_err_disable;
7780 }
7781
7782 pci_set_master(pdev);
7783
7784 bp->dev = dev;
7785 bp->pdev = pdev;
7786
7787 bp->bar0 = pci_ioremap_bar(pdev, 0);
7788 if (!bp->bar0) {
7789 dev_err(&pdev->dev, "Cannot map device registers, aborting\n");
7790 rc = -ENOMEM;
7791 goto init_err_release;
7792 }
7793
7794 bp->bar1 = pci_ioremap_bar(pdev, 2);
7795 if (!bp->bar1) {
7796 dev_err(&pdev->dev, "Cannot map doorbell registers, aborting\n");
7797 rc = -ENOMEM;
7798 goto init_err_release;
7799 }
7800
7801 bp->bar2 = pci_ioremap_bar(pdev, 4);
7802 if (!bp->bar2) {
7803 dev_err(&pdev->dev, "Cannot map bar4 registers, aborting\n");
7804 rc = -ENOMEM;
7805 goto init_err_release;
7806 }
7807
Satish Baddipadige6316ea62016-03-07 15:38:48 -05007808 pci_enable_pcie_error_reporting(pdev);
7809
Michael Chanc0c050c2015-10-22 16:01:17 -04007810 INIT_WORK(&bp->sp_task, bnxt_sp_task);
7811
7812 spin_lock_init(&bp->ntp_fltr_lock);
7813
7814 bp->rx_ring_size = BNXT_DEFAULT_RX_RING_SIZE;
7815 bp->tx_ring_size = BNXT_DEFAULT_TX_RING_SIZE;
7816
Michael Chan18775aa2017-10-26 11:51:27 -04007817 bnxt_init_dflt_coal(bp);
Michael Chan51f30782016-07-01 18:46:29 -04007818
Kees Cooke99e88a2017-10-16 14:43:17 -07007819 timer_setup(&bp->timer, bnxt_timer, 0);
Michael Chanc0c050c2015-10-22 16:01:17 -04007820 bp->current_interval = BNXT_TIMER_INTERVAL;
7821
Michael Chancaefe522015-12-09 19:35:42 -05007822 clear_bit(BNXT_STATE_OPEN, &bp->state);
Michael Chanc0c050c2015-10-22 16:01:17 -04007823 return 0;
7824
7825init_err_release:
Sathya Perla17086392017-02-20 19:25:18 -05007826 bnxt_unmap_bars(bp, pdev);
Michael Chanc0c050c2015-10-22 16:01:17 -04007827 pci_release_regions(pdev);
7828
7829init_err_disable:
7830 pci_disable_device(pdev);
7831
7832init_err:
7833 return rc;
7834}
7835
7836/* rtnl_lock held */
7837static int bnxt_change_mac_addr(struct net_device *dev, void *p)
7838{
7839 struct sockaddr *addr = p;
Jeffrey Huang1fc2cfd2015-12-02 01:54:06 -05007840 struct bnxt *bp = netdev_priv(dev);
7841 int rc = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04007842
7843 if (!is_valid_ether_addr(addr->sa_data))
7844 return -EADDRNOTAVAIL;
7845
Michael Chanc1a7bdf2017-10-26 11:51:24 -04007846 if (ether_addr_equal(addr->sa_data, dev->dev_addr))
7847 return 0;
7848
Michael Chan84c33dd2016-04-11 04:11:13 -04007849 rc = bnxt_approve_mac(bp, addr->sa_data);
7850 if (rc)
7851 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04007852
Jeffrey Huang1fc2cfd2015-12-02 01:54:06 -05007853 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
7854 if (netif_running(dev)) {
7855 bnxt_close_nic(bp, false, false);
7856 rc = bnxt_open_nic(bp, false, false);
7857 }
7858
7859 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04007860}
7861
7862/* rtnl_lock held */
7863static int bnxt_change_mtu(struct net_device *dev, int new_mtu)
7864{
7865 struct bnxt *bp = netdev_priv(dev);
7866
Michael Chanc0c050c2015-10-22 16:01:17 -04007867 if (netif_running(dev))
7868 bnxt_close_nic(bp, false, false);
7869
7870 dev->mtu = new_mtu;
7871 bnxt_set_ring_params(bp);
7872
7873 if (netif_running(dev))
7874 return bnxt_open_nic(bp, false, false);
7875
7876 return 0;
7877}
7878
Michael Chanc5e3deb2016-12-02 21:17:15 -05007879int bnxt_setup_mq_tc(struct net_device *dev, u8 tc)
Michael Chanc0c050c2015-10-22 16:01:17 -04007880{
7881 struct bnxt *bp = netdev_priv(dev);
Michael Chan3ffb6a32016-11-11 00:11:42 -05007882 bool sh = false;
Michael Chand1e79252017-02-06 16:55:38 -05007883 int rc;
John Fastabend16e5cc62016-02-16 21:16:43 -08007884
Michael Chanc0c050c2015-10-22 16:01:17 -04007885 if (tc > bp->max_tc) {
Michael Chanb451c8b2017-02-12 19:18:17 -05007886 netdev_err(dev, "Too many traffic classes requested: %d. Max supported is %d.\n",
Michael Chanc0c050c2015-10-22 16:01:17 -04007887 tc, bp->max_tc);
7888 return -EINVAL;
7889 }
7890
7891 if (netdev_get_num_tc(dev) == tc)
7892 return 0;
7893
Michael Chan3ffb6a32016-11-11 00:11:42 -05007894 if (bp->flags & BNXT_FLAG_SHARED_RINGS)
7895 sh = true;
7896
Michael Chan98fdbe72017-08-28 13:40:26 -04007897 rc = bnxt_check_rings(bp, bp->tx_nr_rings_per_tc, bp->rx_nr_rings,
7898 sh, tc, bp->tx_nr_rings_xdp);
Michael Chand1e79252017-02-06 16:55:38 -05007899 if (rc)
7900 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04007901
7902 /* Needs to close the device and do hw resource re-allocations */
7903 if (netif_running(bp->dev))
7904 bnxt_close_nic(bp, true, false);
7905
7906 if (tc) {
7907 bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tc;
7908 netdev_set_num_tc(dev, tc);
7909 } else {
7910 bp->tx_nr_rings = bp->tx_nr_rings_per_tc;
7911 netdev_reset_tc(dev);
7912 }
Michael Chan87e9b372017-08-23 19:34:03 -04007913 bp->tx_nr_rings += bp->tx_nr_rings_xdp;
Michael Chan3ffb6a32016-11-11 00:11:42 -05007914 bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
7915 bp->tx_nr_rings + bp->rx_nr_rings;
Michael Chanc0c050c2015-10-22 16:01:17 -04007916 bp->num_stat_ctxs = bp->cp_nr_rings;
7917
7918 if (netif_running(bp->dev))
7919 return bnxt_open_nic(bp, true, false);
7920
7921 return 0;
7922}
7923
Jiri Pirko9e0fd152017-10-19 15:50:39 +02007924static int bnxt_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
7925 void *cb_priv)
Sathya Perla2ae74082017-08-28 13:40:33 -04007926{
Jiri Pirko9e0fd152017-10-19 15:50:39 +02007927 struct bnxt *bp = cb_priv;
Sathya Perla2ae74082017-08-28 13:40:33 -04007928
Jakub Kicinski312324f2018-01-25 14:00:48 -08007929 if (!bnxt_tc_flower_enabled(bp) ||
7930 !tc_cls_can_offload_and_chain0(bp->dev, type_data))
Sathya Perla2ae74082017-08-28 13:40:33 -04007931 return -EOPNOTSUPP;
7932
Jiri Pirko9e0fd152017-10-19 15:50:39 +02007933 switch (type) {
7934 case TC_SETUP_CLSFLOWER:
7935 return bnxt_tc_setup_flower(bp, bp->pf.fw_fid, type_data);
7936 default:
7937 return -EOPNOTSUPP;
7938 }
7939}
7940
7941static int bnxt_setup_tc_block(struct net_device *dev,
7942 struct tc_block_offload *f)
7943{
7944 struct bnxt *bp = netdev_priv(dev);
7945
7946 if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
7947 return -EOPNOTSUPP;
7948
7949 switch (f->command) {
7950 case TC_BLOCK_BIND:
7951 return tcf_block_cb_register(f->block, bnxt_setup_tc_block_cb,
7952 bp, bp);
7953 case TC_BLOCK_UNBIND:
7954 tcf_block_cb_unregister(f->block, bnxt_setup_tc_block_cb, bp);
7955 return 0;
7956 default:
7957 return -EOPNOTSUPP;
7958 }
Sathya Perla2ae74082017-08-28 13:40:33 -04007959}
7960
Jiri Pirko2572ac52017-08-07 10:15:17 +02007961static int bnxt_setup_tc(struct net_device *dev, enum tc_setup_type type,
Jiri Pirkode4784c2017-08-07 10:15:32 +02007962 void *type_data)
Michael Chanc5e3deb2016-12-02 21:17:15 -05007963{
Sathya Perla2ae74082017-08-28 13:40:33 -04007964 switch (type) {
Jiri Pirko9e0fd152017-10-19 15:50:39 +02007965 case TC_SETUP_BLOCK:
7966 return bnxt_setup_tc_block(dev, type_data);
Nogah Frankel575ed7d2017-11-06 07:23:42 +01007967 case TC_SETUP_QDISC_MQPRIO: {
Sathya Perla2ae74082017-08-28 13:40:33 -04007968 struct tc_mqprio_qopt *mqprio = type_data;
Jiri Pirkode4784c2017-08-07 10:15:32 +02007969
Sathya Perla2ae74082017-08-28 13:40:33 -04007970 mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
7971
7972 return bnxt_setup_mq_tc(dev, mqprio->num_tc);
7973 }
7974 default:
Jiri Pirko38cf0422017-08-07 10:15:31 +02007975 return -EOPNOTSUPP;
Sathya Perla2ae74082017-08-28 13:40:33 -04007976 }
Michael Chanc5e3deb2016-12-02 21:17:15 -05007977}
7978
Michael Chanc0c050c2015-10-22 16:01:17 -04007979#ifdef CONFIG_RFS_ACCEL
7980static bool bnxt_fltr_match(struct bnxt_ntuple_filter *f1,
7981 struct bnxt_ntuple_filter *f2)
7982{
7983 struct flow_keys *keys1 = &f1->fkeys;
7984 struct flow_keys *keys2 = &f2->fkeys;
7985
7986 if (keys1->addrs.v4addrs.src == keys2->addrs.v4addrs.src &&
7987 keys1->addrs.v4addrs.dst == keys2->addrs.v4addrs.dst &&
7988 keys1->ports.ports == keys2->ports.ports &&
7989 keys1->basic.ip_proto == keys2->basic.ip_proto &&
7990 keys1->basic.n_proto == keys2->basic.n_proto &&
Michael Chan61aad722017-02-12 19:18:14 -05007991 keys1->control.flags == keys2->control.flags &&
Michael Chana54c4d72016-07-25 12:33:35 -04007992 ether_addr_equal(f1->src_mac_addr, f2->src_mac_addr) &&
7993 ether_addr_equal(f1->dst_mac_addr, f2->dst_mac_addr))
Michael Chanc0c050c2015-10-22 16:01:17 -04007994 return true;
7995
7996 return false;
7997}
7998
7999static int bnxt_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
8000 u16 rxq_index, u32 flow_id)
8001{
8002 struct bnxt *bp = netdev_priv(dev);
8003 struct bnxt_ntuple_filter *fltr, *new_fltr;
8004 struct flow_keys *fkeys;
8005 struct ethhdr *eth = (struct ethhdr *)skb_mac_header(skb);
Michael Chana54c4d72016-07-25 12:33:35 -04008006 int rc = 0, idx, bit_id, l2_idx = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04008007 struct hlist_head *head;
8008
Michael Chana54c4d72016-07-25 12:33:35 -04008009 if (!ether_addr_equal(dev->dev_addr, eth->h_dest)) {
8010 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
8011 int off = 0, j;
8012
8013 netif_addr_lock_bh(dev);
8014 for (j = 0; j < vnic->uc_filter_count; j++, off += ETH_ALEN) {
8015 if (ether_addr_equal(eth->h_dest,
8016 vnic->uc_list + off)) {
8017 l2_idx = j + 1;
8018 break;
8019 }
8020 }
8021 netif_addr_unlock_bh(dev);
8022 if (!l2_idx)
8023 return -EINVAL;
8024 }
Michael Chanc0c050c2015-10-22 16:01:17 -04008025 new_fltr = kzalloc(sizeof(*new_fltr), GFP_ATOMIC);
8026 if (!new_fltr)
8027 return -ENOMEM;
8028
8029 fkeys = &new_fltr->fkeys;
8030 if (!skb_flow_dissect_flow_keys(skb, fkeys, 0)) {
8031 rc = -EPROTONOSUPPORT;
8032 goto err_free;
8033 }
8034
Michael Chandda0e742016-12-29 12:13:40 -05008035 if ((fkeys->basic.n_proto != htons(ETH_P_IP) &&
8036 fkeys->basic.n_proto != htons(ETH_P_IPV6)) ||
Michael Chanc0c050c2015-10-22 16:01:17 -04008037 ((fkeys->basic.ip_proto != IPPROTO_TCP) &&
8038 (fkeys->basic.ip_proto != IPPROTO_UDP))) {
8039 rc = -EPROTONOSUPPORT;
8040 goto err_free;
8041 }
Michael Chandda0e742016-12-29 12:13:40 -05008042 if (fkeys->basic.n_proto == htons(ETH_P_IPV6) &&
8043 bp->hwrm_spec_code < 0x10601) {
8044 rc = -EPROTONOSUPPORT;
8045 goto err_free;
8046 }
Michael Chan61aad722017-02-12 19:18:14 -05008047 if ((fkeys->control.flags & FLOW_DIS_ENCAPSULATION) &&
8048 bp->hwrm_spec_code < 0x10601) {
8049 rc = -EPROTONOSUPPORT;
8050 goto err_free;
8051 }
Michael Chanc0c050c2015-10-22 16:01:17 -04008052
Michael Chana54c4d72016-07-25 12:33:35 -04008053 memcpy(new_fltr->dst_mac_addr, eth->h_dest, ETH_ALEN);
Michael Chanc0c050c2015-10-22 16:01:17 -04008054 memcpy(new_fltr->src_mac_addr, eth->h_source, ETH_ALEN);
8055
8056 idx = skb_get_hash_raw(skb) & BNXT_NTP_FLTR_HASH_MASK;
8057 head = &bp->ntp_fltr_hash_tbl[idx];
8058 rcu_read_lock();
8059 hlist_for_each_entry_rcu(fltr, head, hash) {
8060 if (bnxt_fltr_match(fltr, new_fltr)) {
8061 rcu_read_unlock();
8062 rc = 0;
8063 goto err_free;
8064 }
8065 }
8066 rcu_read_unlock();
8067
8068 spin_lock_bh(&bp->ntp_fltr_lock);
Michael Chan84e86b92015-11-05 16:25:50 -05008069 bit_id = bitmap_find_free_region(bp->ntp_fltr_bmap,
8070 BNXT_NTP_FLTR_MAX_FLTR, 0);
8071 if (bit_id < 0) {
Michael Chanc0c050c2015-10-22 16:01:17 -04008072 spin_unlock_bh(&bp->ntp_fltr_lock);
8073 rc = -ENOMEM;
8074 goto err_free;
8075 }
8076
Michael Chan84e86b92015-11-05 16:25:50 -05008077 new_fltr->sw_id = (u16)bit_id;
Michael Chanc0c050c2015-10-22 16:01:17 -04008078 new_fltr->flow_id = flow_id;
Michael Chana54c4d72016-07-25 12:33:35 -04008079 new_fltr->l2_fltr_idx = l2_idx;
Michael Chanc0c050c2015-10-22 16:01:17 -04008080 new_fltr->rxq = rxq_index;
8081 hlist_add_head_rcu(&new_fltr->hash, head);
8082 bp->ntp_fltr_count++;
8083 spin_unlock_bh(&bp->ntp_fltr_lock);
8084
8085 set_bit(BNXT_RX_NTP_FLTR_SP_EVENT, &bp->sp_event);
Michael Chanc213eae2017-10-13 21:09:29 -04008086 bnxt_queue_sp_work(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04008087
8088 return new_fltr->sw_id;
8089
8090err_free:
8091 kfree(new_fltr);
8092 return rc;
8093}
8094
8095static void bnxt_cfg_ntp_filters(struct bnxt *bp)
8096{
8097 int i;
8098
8099 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
8100 struct hlist_head *head;
8101 struct hlist_node *tmp;
8102 struct bnxt_ntuple_filter *fltr;
8103 int rc;
8104
8105 head = &bp->ntp_fltr_hash_tbl[i];
8106 hlist_for_each_entry_safe(fltr, tmp, head, hash) {
8107 bool del = false;
8108
8109 if (test_bit(BNXT_FLTR_VALID, &fltr->state)) {
8110 if (rps_may_expire_flow(bp->dev, fltr->rxq,
8111 fltr->flow_id,
8112 fltr->sw_id)) {
8113 bnxt_hwrm_cfa_ntuple_filter_free(bp,
8114 fltr);
8115 del = true;
8116 }
8117 } else {
8118 rc = bnxt_hwrm_cfa_ntuple_filter_alloc(bp,
8119 fltr);
8120 if (rc)
8121 del = true;
8122 else
8123 set_bit(BNXT_FLTR_VALID, &fltr->state);
8124 }
8125
8126 if (del) {
8127 spin_lock_bh(&bp->ntp_fltr_lock);
8128 hlist_del_rcu(&fltr->hash);
8129 bp->ntp_fltr_count--;
8130 spin_unlock_bh(&bp->ntp_fltr_lock);
8131 synchronize_rcu();
8132 clear_bit(fltr->sw_id, bp->ntp_fltr_bmap);
8133 kfree(fltr);
8134 }
8135 }
8136 }
Jeffrey Huang19241362016-02-26 04:00:00 -05008137 if (test_and_clear_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT, &bp->sp_event))
8138 netdev_info(bp->dev, "Receive PF driver unload event!");
Michael Chanc0c050c2015-10-22 16:01:17 -04008139}
8140
8141#else
8142
8143static void bnxt_cfg_ntp_filters(struct bnxt *bp)
8144{
8145}
8146
8147#endif /* CONFIG_RFS_ACCEL */
8148
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008149static void bnxt_udp_tunnel_add(struct net_device *dev,
8150 struct udp_tunnel_info *ti)
Michael Chanc0c050c2015-10-22 16:01:17 -04008151{
8152 struct bnxt *bp = netdev_priv(dev);
8153
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008154 if (ti->sa_family != AF_INET6 && ti->sa_family != AF_INET)
8155 return;
8156
Michael Chanc0c050c2015-10-22 16:01:17 -04008157 if (!netif_running(dev))
8158 return;
8159
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008160 switch (ti->type) {
8161 case UDP_TUNNEL_TYPE_VXLAN:
8162 if (bp->vxlan_port_cnt && bp->vxlan_port != ti->port)
8163 return;
Michael Chanc0c050c2015-10-22 16:01:17 -04008164
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008165 bp->vxlan_port_cnt++;
8166 if (bp->vxlan_port_cnt == 1) {
8167 bp->vxlan_port = ti->port;
8168 set_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT, &bp->sp_event);
Michael Chanc213eae2017-10-13 21:09:29 -04008169 bnxt_queue_sp_work(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04008170 }
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008171 break;
Alexander Duyck7cdd5fc2016-06-16 12:21:36 -07008172 case UDP_TUNNEL_TYPE_GENEVE:
8173 if (bp->nge_port_cnt && bp->nge_port != ti->port)
8174 return;
8175
8176 bp->nge_port_cnt++;
8177 if (bp->nge_port_cnt == 1) {
8178 bp->nge_port = ti->port;
8179 set_bit(BNXT_GENEVE_ADD_PORT_SP_EVENT, &bp->sp_event);
8180 }
8181 break;
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008182 default:
8183 return;
Michael Chanc0c050c2015-10-22 16:01:17 -04008184 }
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008185
Michael Chanc213eae2017-10-13 21:09:29 -04008186 bnxt_queue_sp_work(bp);
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008187}
8188
8189static void bnxt_udp_tunnel_del(struct net_device *dev,
8190 struct udp_tunnel_info *ti)
8191{
8192 struct bnxt *bp = netdev_priv(dev);
8193
8194 if (ti->sa_family != AF_INET6 && ti->sa_family != AF_INET)
8195 return;
8196
8197 if (!netif_running(dev))
8198 return;
8199
8200 switch (ti->type) {
8201 case UDP_TUNNEL_TYPE_VXLAN:
8202 if (!bp->vxlan_port_cnt || bp->vxlan_port != ti->port)
8203 return;
8204 bp->vxlan_port_cnt--;
8205
8206 if (bp->vxlan_port_cnt != 0)
8207 return;
8208
8209 set_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT, &bp->sp_event);
8210 break;
Alexander Duyck7cdd5fc2016-06-16 12:21:36 -07008211 case UDP_TUNNEL_TYPE_GENEVE:
8212 if (!bp->nge_port_cnt || bp->nge_port != ti->port)
8213 return;
8214 bp->nge_port_cnt--;
8215
8216 if (bp->nge_port_cnt != 0)
8217 return;
8218
8219 set_bit(BNXT_GENEVE_DEL_PORT_SP_EVENT, &bp->sp_event);
8220 break;
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008221 default:
8222 return;
8223 }
8224
Michael Chanc213eae2017-10-13 21:09:29 -04008225 bnxt_queue_sp_work(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04008226}
8227
Michael Chan39d8ba22017-07-24 12:34:22 -04008228static int bnxt_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
8229 struct net_device *dev, u32 filter_mask,
8230 int nlflags)
8231{
8232 struct bnxt *bp = netdev_priv(dev);
8233
8234 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, bp->br_mode, 0, 0,
8235 nlflags, filter_mask, NULL);
8236}
8237
8238static int bnxt_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh,
8239 u16 flags)
8240{
8241 struct bnxt *bp = netdev_priv(dev);
8242 struct nlattr *attr, *br_spec;
8243 int rem, rc = 0;
8244
8245 if (bp->hwrm_spec_code < 0x10708 || !BNXT_SINGLE_PF(bp))
8246 return -EOPNOTSUPP;
8247
8248 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
8249 if (!br_spec)
8250 return -EINVAL;
8251
8252 nla_for_each_nested(attr, br_spec, rem) {
8253 u16 mode;
8254
8255 if (nla_type(attr) != IFLA_BRIDGE_MODE)
8256 continue;
8257
8258 if (nla_len(attr) < sizeof(mode))
8259 return -EINVAL;
8260
8261 mode = nla_get_u16(attr);
8262 if (mode == bp->br_mode)
8263 break;
8264
8265 rc = bnxt_hwrm_set_br_mode(bp, mode);
8266 if (!rc)
8267 bp->br_mode = mode;
8268 break;
8269 }
8270 return rc;
8271}
8272
Sathya Perlac124a622017-07-24 12:34:29 -04008273static int bnxt_get_phys_port_name(struct net_device *dev, char *buf,
8274 size_t len)
8275{
8276 struct bnxt *bp = netdev_priv(dev);
8277 int rc;
8278
8279 /* The PF and it's VF-reps only support the switchdev framework */
8280 if (!BNXT_PF(bp))
8281 return -EOPNOTSUPP;
8282
Sathya Perla53f70b82017-07-25 13:28:41 -04008283 rc = snprintf(buf, len, "p%d", bp->pf.port_id);
Sathya Perlac124a622017-07-24 12:34:29 -04008284
8285 if (rc >= len)
8286 return -EOPNOTSUPP;
8287 return 0;
8288}
8289
8290int bnxt_port_attr_get(struct bnxt *bp, struct switchdev_attr *attr)
8291{
8292 if (bp->eswitch_mode != DEVLINK_ESWITCH_MODE_SWITCHDEV)
8293 return -EOPNOTSUPP;
8294
8295 /* The PF and it's VF-reps only support the switchdev framework */
8296 if (!BNXT_PF(bp))
8297 return -EOPNOTSUPP;
8298
8299 switch (attr->id) {
8300 case SWITCHDEV_ATTR_ID_PORT_PARENT_ID:
Sathya Perladd4ea1d2018-01-17 03:21:16 -05008301 attr->u.ppid.id_len = sizeof(bp->switch_id);
8302 memcpy(attr->u.ppid.id, bp->switch_id, attr->u.ppid.id_len);
Sathya Perlac124a622017-07-24 12:34:29 -04008303 break;
8304 default:
8305 return -EOPNOTSUPP;
8306 }
8307 return 0;
8308}
8309
8310static int bnxt_swdev_port_attr_get(struct net_device *dev,
8311 struct switchdev_attr *attr)
8312{
8313 return bnxt_port_attr_get(netdev_priv(dev), attr);
8314}
8315
8316static const struct switchdev_ops bnxt_switchdev_ops = {
8317 .switchdev_port_attr_get = bnxt_swdev_port_attr_get
8318};
8319
Michael Chanc0c050c2015-10-22 16:01:17 -04008320static const struct net_device_ops bnxt_netdev_ops = {
8321 .ndo_open = bnxt_open,
8322 .ndo_start_xmit = bnxt_start_xmit,
8323 .ndo_stop = bnxt_close,
8324 .ndo_get_stats64 = bnxt_get_stats64,
8325 .ndo_set_rx_mode = bnxt_set_rx_mode,
8326 .ndo_do_ioctl = bnxt_ioctl,
8327 .ndo_validate_addr = eth_validate_addr,
8328 .ndo_set_mac_address = bnxt_change_mac_addr,
8329 .ndo_change_mtu = bnxt_change_mtu,
8330 .ndo_fix_features = bnxt_fix_features,
8331 .ndo_set_features = bnxt_set_features,
8332 .ndo_tx_timeout = bnxt_tx_timeout,
8333#ifdef CONFIG_BNXT_SRIOV
8334 .ndo_get_vf_config = bnxt_get_vf_config,
8335 .ndo_set_vf_mac = bnxt_set_vf_mac,
8336 .ndo_set_vf_vlan = bnxt_set_vf_vlan,
8337 .ndo_set_vf_rate = bnxt_set_vf_bw,
8338 .ndo_set_vf_link_state = bnxt_set_vf_link_state,
8339 .ndo_set_vf_spoofchk = bnxt_set_vf_spoofchk,
Vasundhara Volam746df132018-03-31 13:54:10 -04008340 .ndo_set_vf_trust = bnxt_set_vf_trust,
Michael Chanc0c050c2015-10-22 16:01:17 -04008341#endif
8342#ifdef CONFIG_NET_POLL_CONTROLLER
8343 .ndo_poll_controller = bnxt_poll_controller,
8344#endif
8345 .ndo_setup_tc = bnxt_setup_tc,
8346#ifdef CONFIG_RFS_ACCEL
8347 .ndo_rx_flow_steer = bnxt_rx_flow_steer,
8348#endif
Alexander Duyckad51b8e2016-06-16 12:21:19 -07008349 .ndo_udp_tunnel_add = bnxt_udp_tunnel_add,
8350 .ndo_udp_tunnel_del = bnxt_udp_tunnel_del,
Jakub Kicinskif4e63522017-11-03 13:56:16 -07008351 .ndo_bpf = bnxt_xdp,
Michael Chan39d8ba22017-07-24 12:34:22 -04008352 .ndo_bridge_getlink = bnxt_bridge_getlink,
8353 .ndo_bridge_setlink = bnxt_bridge_setlink,
Sathya Perlac124a622017-07-24 12:34:29 -04008354 .ndo_get_phys_port_name = bnxt_get_phys_port_name
Michael Chanc0c050c2015-10-22 16:01:17 -04008355};
8356
8357static void bnxt_remove_one(struct pci_dev *pdev)
8358{
8359 struct net_device *dev = pci_get_drvdata(pdev);
8360 struct bnxt *bp = netdev_priv(dev);
8361
Sathya Perla4ab0c6a2017-07-24 12:34:27 -04008362 if (BNXT_PF(bp)) {
Michael Chanc0c050c2015-10-22 16:01:17 -04008363 bnxt_sriov_disable(bp);
Sathya Perla4ab0c6a2017-07-24 12:34:27 -04008364 bnxt_dl_unregister(bp);
8365 }
Michael Chanc0c050c2015-10-22 16:01:17 -04008366
Satish Baddipadige6316ea62016-03-07 15:38:48 -05008367 pci_disable_pcie_error_reporting(pdev);
Michael Chanc0c050c2015-10-22 16:01:17 -04008368 unregister_netdev(dev);
Sathya Perla2ae74082017-08-28 13:40:33 -04008369 bnxt_shutdown_tc(bp);
Michael Chanc213eae2017-10-13 21:09:29 -04008370 bnxt_cancel_sp_work(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04008371 bp->sp_event = 0;
8372
Michael Chan78095922016-12-07 00:26:16 -05008373 bnxt_clear_int_mode(bp);
Jeffrey Huangbe58a0d2015-12-27 18:19:18 -05008374 bnxt_hwrm_func_drv_unrgtr(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04008375 bnxt_free_hwrm_resources(bp);
Deepak Khungare605db82017-05-29 19:06:04 -04008376 bnxt_free_hwrm_short_cmd_req(bp);
Michael Chaneb513652017-04-04 18:14:12 -04008377 bnxt_ethtool_free(bp);
Michael Chan7df4ae92016-12-02 21:17:17 -05008378 bnxt_dcb_free(bp);
Michael Chana588e452016-12-07 00:26:21 -05008379 kfree(bp->edev);
8380 bp->edev = NULL;
Sathya Perla17086392017-02-20 19:25:18 -05008381 bnxt_cleanup_pci(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04008382 free_netdev(dev);
Michael Chanc0c050c2015-10-22 16:01:17 -04008383}
8384
8385static int bnxt_probe_phy(struct bnxt *bp)
8386{
8387 int rc = 0;
8388 struct bnxt_link_info *link_info = &bp->link_info;
Michael Chanc0c050c2015-10-22 16:01:17 -04008389
Michael Chan170ce012016-04-05 14:08:57 -04008390 rc = bnxt_hwrm_phy_qcaps(bp);
8391 if (rc) {
8392 netdev_err(bp->dev, "Probe phy can't get phy capabilities (rc: %x)\n",
8393 rc);
8394 return rc;
8395 }
Michael Chane2dc9b62017-10-13 21:09:30 -04008396 mutex_init(&bp->link_lock);
Michael Chan170ce012016-04-05 14:08:57 -04008397
Michael Chanc0c050c2015-10-22 16:01:17 -04008398 rc = bnxt_update_link(bp, false);
8399 if (rc) {
8400 netdev_err(bp->dev, "Probe phy can't update link (rc: %x)\n",
8401 rc);
8402 return rc;
8403 }
8404
Michael Chan93ed8112016-06-13 02:25:37 -04008405 /* Older firmware does not have supported_auto_speeds, so assume
8406 * that all supported speeds can be autonegotiated.
8407 */
8408 if (link_info->auto_link_speeds && !link_info->support_auto_speeds)
8409 link_info->support_auto_speeds = link_info->support_speeds;
8410
Michael Chanc0c050c2015-10-22 16:01:17 -04008411 /*initialize the ethool setting copy with NVM settings */
Michael Chan0d8abf02016-02-10 17:33:47 -05008412 if (BNXT_AUTO_MODE(link_info->auto_mode)) {
Michael Chanc9ee9512016-04-05 14:08:56 -04008413 link_info->autoneg = BNXT_AUTONEG_SPEED;
8414 if (bp->hwrm_spec_code >= 0x10201) {
8415 if (link_info->auto_pause_setting &
8416 PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE)
8417 link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
8418 } else {
8419 link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
8420 }
Michael Chan0d8abf02016-02-10 17:33:47 -05008421 link_info->advertising = link_info->auto_link_speeds;
Michael Chan0d8abf02016-02-10 17:33:47 -05008422 } else {
8423 link_info->req_link_speed = link_info->force_link_speed;
8424 link_info->req_duplex = link_info->duplex_setting;
Michael Chanc0c050c2015-10-22 16:01:17 -04008425 }
Michael Chanc9ee9512016-04-05 14:08:56 -04008426 if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL)
8427 link_info->req_flow_ctrl =
8428 link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH;
8429 else
8430 link_info->req_flow_ctrl = link_info->force_pause_setting;
Michael Chanc0c050c2015-10-22 16:01:17 -04008431 return rc;
8432}
8433
8434static int bnxt_get_max_irq(struct pci_dev *pdev)
8435{
8436 u16 ctrl;
8437
8438 if (!pdev->msix_cap)
8439 return 1;
8440
8441 pci_read_config_word(pdev, pdev->msix_cap + PCI_MSIX_FLAGS, &ctrl);
8442 return (ctrl & PCI_MSIX_FLAGS_QSIZE) + 1;
8443}
8444
Michael Chan6e6c5a52016-01-02 23:45:02 -05008445static void _bnxt_get_max_rings(struct bnxt *bp, int *max_rx, int *max_tx,
8446 int *max_cp)
Michael Chanc0c050c2015-10-22 16:01:17 -04008447{
Michael Chan6a4f2942018-01-17 03:21:06 -05008448 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
Michael Chan6e6c5a52016-01-02 23:45:02 -05008449 int max_ring_grps = 0;
Michael Chanc0c050c2015-10-22 16:01:17 -04008450
Michael Chan6a4f2942018-01-17 03:21:06 -05008451 *max_tx = hw_resc->max_tx_rings;
8452 *max_rx = hw_resc->max_rx_rings;
8453 *max_cp = min_t(int, hw_resc->max_irqs, hw_resc->max_cp_rings);
8454 *max_cp = min_t(int, *max_cp, hw_resc->max_stat_ctxs);
8455 max_ring_grps = hw_resc->max_hw_ring_grps;
Prashant Sreedharan76595192016-07-18 07:15:22 -04008456 if (BNXT_CHIP_TYPE_NITRO_A0(bp) && BNXT_PF(bp)) {
8457 *max_cp -= 1;
8458 *max_rx -= 2;
8459 }
Michael Chanc0c050c2015-10-22 16:01:17 -04008460 if (bp->flags & BNXT_FLAG_AGG_RINGS)
8461 *max_rx >>= 1;
Michael Chanb72d4a62015-12-27 18:19:27 -05008462 *max_rx = min_t(int, *max_rx, max_ring_grps);
Michael Chan6e6c5a52016-01-02 23:45:02 -05008463}
8464
8465int bnxt_get_max_rings(struct bnxt *bp, int *max_rx, int *max_tx, bool shared)
8466{
8467 int rx, tx, cp;
8468
8469 _bnxt_get_max_rings(bp, &rx, &tx, &cp);
8470 if (!rx || !tx || !cp)
8471 return -ENOMEM;
8472
8473 *max_rx = rx;
8474 *max_tx = tx;
8475 return bnxt_trim_rings(bp, max_rx, max_tx, cp, shared);
8476}
8477
Michael Chane4060d32016-12-07 00:26:19 -05008478static int bnxt_get_dflt_rings(struct bnxt *bp, int *max_rx, int *max_tx,
8479 bool shared)
8480{
8481 int rc;
8482
8483 rc = bnxt_get_max_rings(bp, max_rx, max_tx, shared);
Michael Chanbdbd1eb2016-12-29 12:13:43 -05008484 if (rc && (bp->flags & BNXT_FLAG_AGG_RINGS)) {
8485 /* Not enough rings, try disabling agg rings. */
8486 bp->flags &= ~BNXT_FLAG_AGG_RINGS;
8487 rc = bnxt_get_max_rings(bp, max_rx, max_tx, shared);
8488 if (rc)
8489 return rc;
8490 bp->flags |= BNXT_FLAG_NO_AGG_RINGS;
Michael Chan1054aee2017-12-16 03:09:42 -05008491 bp->dev->hw_features &= ~(NETIF_F_LRO | NETIF_F_GRO_HW);
8492 bp->dev->features &= ~(NETIF_F_LRO | NETIF_F_GRO_HW);
Michael Chanbdbd1eb2016-12-29 12:13:43 -05008493 bnxt_set_ring_params(bp);
8494 }
Michael Chane4060d32016-12-07 00:26:19 -05008495
8496 if (bp->flags & BNXT_FLAG_ROCE_CAP) {
8497 int max_cp, max_stat, max_irq;
8498
8499 /* Reserve minimum resources for RoCE */
8500 max_cp = bnxt_get_max_func_cp_rings(bp);
8501 max_stat = bnxt_get_max_func_stat_ctxs(bp);
8502 max_irq = bnxt_get_max_func_irqs(bp);
8503 if (max_cp <= BNXT_MIN_ROCE_CP_RINGS ||
8504 max_irq <= BNXT_MIN_ROCE_CP_RINGS ||
8505 max_stat <= BNXT_MIN_ROCE_STAT_CTXS)
8506 return 0;
8507
8508 max_cp -= BNXT_MIN_ROCE_CP_RINGS;
8509 max_irq -= BNXT_MIN_ROCE_CP_RINGS;
8510 max_stat -= BNXT_MIN_ROCE_STAT_CTXS;
8511 max_cp = min_t(int, max_cp, max_irq);
8512 max_cp = min_t(int, max_cp, max_stat);
8513 rc = bnxt_trim_rings(bp, max_rx, max_tx, max_cp, shared);
8514 if (rc)
8515 rc = 0;
8516 }
8517 return rc;
8518}
8519
Michael Chan58ea8012018-01-17 03:21:08 -05008520/* In initial default shared ring setting, each shared ring must have a
8521 * RX/TX ring pair.
8522 */
8523static void bnxt_trim_dflt_sh_rings(struct bnxt *bp)
8524{
8525 bp->cp_nr_rings = min_t(int, bp->tx_nr_rings_per_tc, bp->rx_nr_rings);
8526 bp->rx_nr_rings = bp->cp_nr_rings;
8527 bp->tx_nr_rings_per_tc = bp->cp_nr_rings;
8528 bp->tx_nr_rings = bp->tx_nr_rings_per_tc;
8529}
8530
Michael Chan702c2212017-05-29 19:06:10 -04008531static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh)
Michael Chan6e6c5a52016-01-02 23:45:02 -05008532{
8533 int dflt_rings, max_rx_rings, max_tx_rings, rc;
Michael Chan6e6c5a52016-01-02 23:45:02 -05008534
8535 if (sh)
8536 bp->flags |= BNXT_FLAG_SHARED_RINGS;
8537 dflt_rings = netif_get_num_default_rss_queues();
Michael Chan1d3ef132018-03-31 13:54:07 -04008538 /* Reduce default rings on multi-port cards so that total default
8539 * rings do not exceed CPU count.
8540 */
8541 if (bp->port_count > 1) {
8542 int max_rings =
8543 max_t(int, num_online_cpus() / bp->port_count, 1);
8544
8545 dflt_rings = min_t(int, dflt_rings, max_rings);
8546 }
Michael Chane4060d32016-12-07 00:26:19 -05008547 rc = bnxt_get_dflt_rings(bp, &max_rx_rings, &max_tx_rings, sh);
Michael Chan6e6c5a52016-01-02 23:45:02 -05008548 if (rc)
8549 return rc;
8550 bp->rx_nr_rings = min_t(int, dflt_rings, max_rx_rings);
8551 bp->tx_nr_rings_per_tc = min_t(int, dflt_rings, max_tx_rings);
Michael Chan58ea8012018-01-17 03:21:08 -05008552 if (sh)
8553 bnxt_trim_dflt_sh_rings(bp);
8554 else
8555 bp->cp_nr_rings = bp->tx_nr_rings_per_tc + bp->rx_nr_rings;
8556 bp->tx_nr_rings = bp->tx_nr_rings_per_tc;
Michael Chan391be5c2016-12-29 12:13:41 -05008557
Michael Chan674f50a2018-01-17 03:21:09 -05008558 rc = __bnxt_reserve_rings(bp);
Michael Chan391be5c2016-12-29 12:13:41 -05008559 if (rc)
8560 netdev_warn(bp->dev, "Unable to reserve tx rings\n");
Michael Chan58ea8012018-01-17 03:21:08 -05008561 bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
8562 if (sh)
8563 bnxt_trim_dflt_sh_rings(bp);
Michael Chan391be5c2016-12-29 12:13:41 -05008564
Michael Chan674f50a2018-01-17 03:21:09 -05008565 /* Rings may have been trimmed, re-reserve the trimmed rings. */
8566 if (bnxt_need_reserve_rings(bp)) {
8567 rc = __bnxt_reserve_rings(bp);
8568 if (rc)
8569 netdev_warn(bp->dev, "2nd rings reservation failed.\n");
8570 bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
8571 }
Michael Chan6e6c5a52016-01-02 23:45:02 -05008572 bp->num_stat_ctxs = bp->cp_nr_rings;
Prashant Sreedharan76595192016-07-18 07:15:22 -04008573 if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
8574 bp->rx_nr_rings++;
8575 bp->cp_nr_rings++;
8576 }
Michael Chan6e6c5a52016-01-02 23:45:02 -05008577 return rc;
Michael Chanc0c050c2015-10-22 16:01:17 -04008578}
8579
Michael Chan80fcaf42018-01-17 03:21:05 -05008580int bnxt_restore_pf_fw_resources(struct bnxt *bp)
Michael Chan7b08f662016-12-07 00:26:18 -05008581{
Michael Chan80fcaf42018-01-17 03:21:05 -05008582 int rc;
8583
Michael Chan7b08f662016-12-07 00:26:18 -05008584 ASSERT_RTNL();
8585 bnxt_hwrm_func_qcaps(bp);
Venkat Duvvuru1a037782018-03-09 23:46:09 -05008586
8587 if (netif_running(bp->dev))
8588 __bnxt_close_nic(bp, true, false);
8589
Michael Chanec86f142018-03-31 13:54:21 -04008590 bnxt_ulp_irq_stop(bp);
Michael Chan80fcaf42018-01-17 03:21:05 -05008591 bnxt_clear_int_mode(bp);
8592 rc = bnxt_init_int_mode(bp);
Michael Chanec86f142018-03-31 13:54:21 -04008593 bnxt_ulp_irq_restart(bp, rc);
Venkat Duvvuru1a037782018-03-09 23:46:09 -05008594
8595 if (netif_running(bp->dev)) {
8596 if (rc)
8597 dev_close(bp->dev);
8598 else
8599 rc = bnxt_open_nic(bp, true, false);
8600 }
8601
Michael Chan80fcaf42018-01-17 03:21:05 -05008602 return rc;
Michael Chan7b08f662016-12-07 00:26:18 -05008603}
8604
Michael Chana22a6ac2017-08-23 19:34:05 -04008605static int bnxt_init_mac_addr(struct bnxt *bp)
8606{
8607 int rc = 0;
8608
8609 if (BNXT_PF(bp)) {
8610 memcpy(bp->dev->dev_addr, bp->pf.mac_addr, ETH_ALEN);
8611 } else {
8612#ifdef CONFIG_BNXT_SRIOV
8613 struct bnxt_vf_info *vf = &bp->vf;
8614
8615 if (is_valid_ether_addr(vf->mac_addr)) {
Vasundhara Volam91cdda42018-01-17 03:21:14 -05008616 /* overwrite netdev dev_addr with admin VF MAC */
Michael Chana22a6ac2017-08-23 19:34:05 -04008617 memcpy(bp->dev->dev_addr, vf->mac_addr, ETH_ALEN);
8618 } else {
8619 eth_hw_addr_random(bp->dev);
8620 rc = bnxt_approve_mac(bp, bp->dev->dev_addr);
8621 }
8622#endif
8623 }
8624 return rc;
8625}
8626
Ajit Khaparde90c4f782016-05-15 03:04:45 -04008627static void bnxt_parse_log_pcie_link(struct bnxt *bp)
8628{
8629 enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN;
8630 enum pci_bus_speed speed = PCI_SPEED_UNKNOWN;
8631
Vasundhara Volam7ab07602017-10-13 21:09:31 -04008632 if (pcie_get_minimum_link(pci_physfn(bp->pdev), &speed, &width) ||
Ajit Khaparde90c4f782016-05-15 03:04:45 -04008633 speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN)
8634 netdev_info(bp->dev, "Failed to determine PCIe Link Info\n");
8635 else
8636 netdev_info(bp->dev, "PCIe: Speed %s Width x%d\n",
8637 speed == PCIE_SPEED_2_5GT ? "2.5GT/s" :
8638 speed == PCIE_SPEED_5_0GT ? "5.0GT/s" :
8639 speed == PCIE_SPEED_8_0GT ? "8.0GT/s" :
8640 "Unknown", width);
8641}
8642
Michael Chanc0c050c2015-10-22 16:01:17 -04008643static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
8644{
8645 static int version_printed;
8646 struct net_device *dev;
8647 struct bnxt *bp;
Michael Chan6e6c5a52016-01-02 23:45:02 -05008648 int rc, max_irqs;
Michael Chanc0c050c2015-10-22 16:01:17 -04008649
Ray Jui4e003382017-02-20 19:25:16 -05008650 if (pci_is_bridge(pdev))
Prashant Sreedharanfa853dd2016-07-18 07:15:25 -04008651 return -ENODEV;
8652
Michael Chanc0c050c2015-10-22 16:01:17 -04008653 if (version_printed++ == 0)
8654 pr_info("%s", version);
8655
8656 max_irqs = bnxt_get_max_irq(pdev);
8657 dev = alloc_etherdev_mq(sizeof(*bp), max_irqs);
8658 if (!dev)
8659 return -ENOMEM;
8660
8661 bp = netdev_priv(dev);
8662
8663 if (bnxt_vf_pciid(ent->driver_data))
8664 bp->flags |= BNXT_FLAG_VF;
8665
Michael Chan2bcfa6f2015-12-27 18:19:24 -05008666 if (pdev->msix_cap)
Michael Chanc0c050c2015-10-22 16:01:17 -04008667 bp->flags |= BNXT_FLAG_MSIX_CAP;
Michael Chanc0c050c2015-10-22 16:01:17 -04008668
8669 rc = bnxt_init_board(pdev, dev);
8670 if (rc < 0)
8671 goto init_err_free;
8672
8673 dev->netdev_ops = &bnxt_netdev_ops;
8674 dev->watchdog_timeo = BNXT_TX_TIMEOUT;
8675 dev->ethtool_ops = &bnxt_ethtool_ops;
David S. Millerbc880552017-07-24 21:20:16 -07008676 SWITCHDEV_SET_OPS(dev, &bnxt_switchdev_ops);
Michael Chanc0c050c2015-10-22 16:01:17 -04008677 pci_set_drvdata(pdev, dev);
8678
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04008679 rc = bnxt_alloc_hwrm_resources(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
8683 mutex_init(&bp->hwrm_cmd_lock);
8684 rc = bnxt_hwrm_ver_get(bp);
8685 if (rc)
Sathya Perla17086392017-02-20 19:25:18 -05008686 goto init_err_pci_clean;
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04008687
Deepak Khungare605db82017-05-29 19:06:04 -04008688 if (bp->flags & BNXT_FLAG_SHORT_CMD) {
8689 rc = bnxt_alloc_hwrm_short_cmd_req(bp);
8690 if (rc)
8691 goto init_err_pci_clean;
8692 }
8693
Michael Chan3c2217a2017-03-08 18:44:32 -05008694 rc = bnxt_hwrm_func_reset(bp);
8695 if (rc)
8696 goto init_err_pci_clean;
8697
Rob Swindell5ac67d82016-09-19 03:58:03 -04008698 bnxt_hwrm_fw_set_time(bp);
8699
Michael Chanc0c050c2015-10-22 16:01:17 -04008700 dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
8701 NETIF_F_TSO | NETIF_F_TSO6 |
8702 NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_GRE |
Tom Herbert7e133182016-05-18 09:06:10 -07008703 NETIF_F_GSO_IPXIP4 |
Alexander Duyck152971e2016-05-02 09:38:55 -07008704 NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_GSO_GRE_CSUM |
8705 NETIF_F_GSO_PARTIAL | NETIF_F_RXHASH |
Prashant Sreedharan3e8060f2016-07-18 07:15:20 -04008706 NETIF_F_RXCSUM | NETIF_F_GRO;
8707
8708 if (!BNXT_CHIP_TYPE_NITRO_A0(bp))
8709 dev->hw_features |= NETIF_F_LRO;
Michael Chanc0c050c2015-10-22 16:01:17 -04008710
Michael Chanc0c050c2015-10-22 16:01:17 -04008711 dev->hw_enc_features =
8712 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
8713 NETIF_F_TSO | NETIF_F_TSO6 |
8714 NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_GRE |
Alexander Duyck152971e2016-05-02 09:38:55 -07008715 NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_GSO_GRE_CSUM |
Tom Herbert7e133182016-05-18 09:06:10 -07008716 NETIF_F_GSO_IPXIP4 | NETIF_F_GSO_PARTIAL;
Alexander Duyck152971e2016-05-02 09:38:55 -07008717 dev->gso_partial_features = NETIF_F_GSO_UDP_TUNNEL_CSUM |
8718 NETIF_F_GSO_GRE_CSUM;
Michael Chanc0c050c2015-10-22 16:01:17 -04008719 dev->vlan_features = dev->hw_features | NETIF_F_HIGHDMA;
8720 dev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX |
8721 NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_STAG_TX;
Michael Chan1054aee2017-12-16 03:09:42 -05008722 if (!BNXT_CHIP_TYPE_NITRO_A0(bp))
8723 dev->hw_features |= NETIF_F_GRO_HW;
Michael Chanc0c050c2015-10-22 16:01:17 -04008724 dev->features |= dev->hw_features | NETIF_F_HIGHDMA;
Michael Chan1054aee2017-12-16 03:09:42 -05008725 if (dev->features & NETIF_F_GRO_HW)
8726 dev->features &= ~NETIF_F_LRO;
Michael Chanc0c050c2015-10-22 16:01:17 -04008727 dev->priv_flags |= IFF_UNICAST_FLT;
8728
8729#ifdef CONFIG_BNXT_SRIOV
8730 init_waitqueue_head(&bp->sriov_cfg_wait);
Sathya Perla4ab0c6a2017-07-24 12:34:27 -04008731 mutex_init(&bp->sriov_lock);
Michael Chanc0c050c2015-10-22 16:01:17 -04008732#endif
Michael Chan309369c2016-06-13 02:25:34 -04008733 bp->gro_func = bnxt_gro_func_5730x;
Michael Chan3284f9e2017-05-29 19:06:07 -04008734 if (BNXT_CHIP_P4_PLUS(bp))
Michael Chan94758f82016-06-13 02:25:35 -04008735 bp->gro_func = bnxt_gro_func_5731x;
Michael Chan434c9752017-05-29 19:06:08 -04008736 else
8737 bp->flags |= BNXT_FLAG_DOUBLE_DB;
Michael Chan309369c2016-06-13 02:25:34 -04008738
Michael Chanc0c050c2015-10-22 16:01:17 -04008739 rc = bnxt_hwrm_func_drv_rgtr(bp);
8740 if (rc)
Sathya Perla17086392017-02-20 19:25:18 -05008741 goto init_err_pci_clean;
Michael Chanc0c050c2015-10-22 16:01:17 -04008742
Michael Chana1653b12016-12-07 00:26:20 -05008743 rc = bnxt_hwrm_func_rgtr_async_events(bp, NULL, 0);
8744 if (rc)
Sathya Perla17086392017-02-20 19:25:18 -05008745 goto init_err_pci_clean;
Michael Chana1653b12016-12-07 00:26:20 -05008746
Michael Chana588e452016-12-07 00:26:21 -05008747 bp->ulp_probe = bnxt_ulp_probe;
8748
Michael Chanc0c050c2015-10-22 16:01:17 -04008749 /* Get the MAX capabilities for this function */
8750 rc = bnxt_hwrm_func_qcaps(bp);
8751 if (rc) {
8752 netdev_err(bp->dev, "hwrm query capability failure rc: %x\n",
8753 rc);
8754 rc = -1;
Sathya Perla17086392017-02-20 19:25:18 -05008755 goto init_err_pci_clean;
Michael Chanc0c050c2015-10-22 16:01:17 -04008756 }
Michael Chana22a6ac2017-08-23 19:34:05 -04008757 rc = bnxt_init_mac_addr(bp);
8758 if (rc) {
8759 dev_err(&pdev->dev, "Unable to initialize mac address.\n");
8760 rc = -EADDRNOTAVAIL;
8761 goto init_err_pci_clean;
8762 }
Michael Chanc0c050c2015-10-22 16:01:17 -04008763 rc = bnxt_hwrm_queue_qportcfg(bp);
8764 if (rc) {
8765 netdev_err(bp->dev, "hwrm query qportcfg failure rc: %x\n",
8766 rc);
8767 rc = -1;
Sathya Perla17086392017-02-20 19:25:18 -05008768 goto init_err_pci_clean;
Michael Chanc0c050c2015-10-22 16:01:17 -04008769 }
8770
Satish Baddipadige567b2ab2016-06-13 02:25:31 -04008771 bnxt_hwrm_func_qcfg(bp);
Michael Chan5ad2cbe2017-01-13 01:32:03 -05008772 bnxt_hwrm_port_led_qcaps(bp);
Michael Chaneb513652017-04-04 18:14:12 -04008773 bnxt_ethtool_init(bp);
Michael Chan87fe6032017-05-16 16:39:43 -04008774 bnxt_dcb_init(bp);
Satish Baddipadige567b2ab2016-06-13 02:25:31 -04008775
Michael Chan7eb9bb32017-10-26 11:51:25 -04008776 /* MTU range: 60 - FW defined max */
8777 dev->min_mtu = ETH_ZLEN;
8778 dev->max_mtu = bp->max_mtu;
8779
Michael Chand5430d32017-08-28 13:40:31 -04008780 rc = bnxt_probe_phy(bp);
8781 if (rc)
8782 goto init_err_pci_clean;
8783
Michael Chanc61fb992017-02-06 16:55:36 -05008784 bnxt_set_rx_skb_mode(bp, false);
Michael Chanc0c050c2015-10-22 16:01:17 -04008785 bnxt_set_tpa_flags(bp);
8786 bnxt_set_ring_params(bp);
Michael Chan33c26572016-12-07 00:26:15 -05008787 bnxt_set_max_func_irqs(bp, max_irqs);
Michael Chan702c2212017-05-29 19:06:10 -04008788 rc = bnxt_set_dflt_rings(bp, true);
Michael Chanbdbd1eb2016-12-29 12:13:43 -05008789 if (rc) {
8790 netdev_err(bp->dev, "Not enough rings available.\n");
8791 rc = -ENOMEM;
Sathya Perla17086392017-02-20 19:25:18 -05008792 goto init_err_pci_clean;
Michael Chanbdbd1eb2016-12-29 12:13:43 -05008793 }
Michael Chanc0c050c2015-10-22 16:01:17 -04008794
Michael Chan87da7f72016-11-16 21:13:09 -05008795 /* Default RSS hash cfg. */
8796 bp->rss_hash_cfg = VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4 |
8797 VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4 |
8798 VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6 |
8799 VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6;
Michael Chan3284f9e2017-05-29 19:06:07 -04008800 if (BNXT_CHIP_P4_PLUS(bp) && bp->hwrm_spec_code >= 0x10501) {
Michael Chan87da7f72016-11-16 21:13:09 -05008801 bp->flags |= BNXT_FLAG_UDP_RSS_CAP;
8802 bp->rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4 |
8803 VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6;
8804 }
8805
Michael Chan8fdefd62016-12-29 12:13:36 -05008806 bnxt_hwrm_vnic_qcaps(bp);
Michael Chan8079e8f2016-12-29 12:13:37 -05008807 if (bnxt_rfs_supported(bp)) {
Michael Chan2bcfa6f2015-12-27 18:19:24 -05008808 dev->hw_features |= NETIF_F_NTUPLE;
8809 if (bnxt_rfs_capable(bp)) {
8810 bp->flags |= BNXT_FLAG_RFS;
8811 dev->features |= NETIF_F_NTUPLE;
8812 }
8813 }
8814
Michael Chanc0c050c2015-10-22 16:01:17 -04008815 if (dev->hw_features & NETIF_F_HW_VLAN_CTAG_RX)
8816 bp->flags |= BNXT_FLAG_STRIP_VLAN;
8817
Michael Chan78095922016-12-07 00:26:16 -05008818 rc = bnxt_init_int_mode(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04008819 if (rc)
Sathya Perla17086392017-02-20 19:25:18 -05008820 goto init_err_pci_clean;
Michael Chanc0c050c2015-10-22 16:01:17 -04008821
Michael Chan832aed12018-03-09 23:46:07 -05008822 /* No TC has been set yet and rings may have been trimmed due to
8823 * limited MSIX, so we re-initialize the TX rings per TC.
8824 */
8825 bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
8826
Michael Chanc1ef1462017-04-04 18:14:07 -04008827 bnxt_get_wol_settings(bp);
Michael Chand196ece2017-04-04 18:14:08 -04008828 if (bp->flags & BNXT_FLAG_WOL_CAP)
8829 device_set_wakeup_enable(&pdev->dev, bp->wol);
8830 else
8831 device_set_wakeup_capable(&pdev->dev, false);
Michael Chanc1ef1462017-04-04 18:14:07 -04008832
Michael Chanc3480a62018-01-17 03:21:15 -05008833 bnxt_hwrm_set_cache_line_size(bp, cache_line_size());
8834
Michael Chanc213eae2017-10-13 21:09:29 -04008835 if (BNXT_PF(bp)) {
8836 if (!bnxt_pf_wq) {
8837 bnxt_pf_wq =
8838 create_singlethread_workqueue("bnxt_pf_wq");
8839 if (!bnxt_pf_wq) {
8840 dev_err(&pdev->dev, "Unable to create workqueue.\n");
8841 goto init_err_pci_clean;
8842 }
8843 }
Sathya Perla2ae74082017-08-28 13:40:33 -04008844 bnxt_init_tc(bp);
Michael Chanc213eae2017-10-13 21:09:29 -04008845 }
Sathya Perla2ae74082017-08-28 13:40:33 -04008846
Michael Chan78095922016-12-07 00:26:16 -05008847 rc = register_netdev(dev);
8848 if (rc)
Sathya Perla2ae74082017-08-28 13:40:33 -04008849 goto init_err_cleanup_tc;
Michael Chan78095922016-12-07 00:26:16 -05008850
Sathya Perla4ab0c6a2017-07-24 12:34:27 -04008851 if (BNXT_PF(bp))
8852 bnxt_dl_register(bp);
8853
Michael Chanc0c050c2015-10-22 16:01:17 -04008854 netdev_info(dev, "%s found at mem %lx, node addr %pM\n",
8855 board_info[ent->driver_data].name,
8856 (long)pci_resource_start(pdev, 0), dev->dev_addr);
8857
Ajit Khaparde90c4f782016-05-15 03:04:45 -04008858 bnxt_parse_log_pcie_link(bp);
8859
Michael Chanc0c050c2015-10-22 16:01:17 -04008860 return 0;
8861
Sathya Perla2ae74082017-08-28 13:40:33 -04008862init_err_cleanup_tc:
8863 bnxt_shutdown_tc(bp);
Michael Chan78095922016-12-07 00:26:16 -05008864 bnxt_clear_int_mode(bp);
8865
Sathya Perla17086392017-02-20 19:25:18 -05008866init_err_pci_clean:
8867 bnxt_cleanup_pci(bp);
Michael Chanc0c050c2015-10-22 16:01:17 -04008868
8869init_err_free:
8870 free_netdev(dev);
8871 return rc;
8872}
8873
Michael Chand196ece2017-04-04 18:14:08 -04008874static void bnxt_shutdown(struct pci_dev *pdev)
8875{
8876 struct net_device *dev = pci_get_drvdata(pdev);
8877 struct bnxt *bp;
8878
8879 if (!dev)
8880 return;
8881
8882 rtnl_lock();
8883 bp = netdev_priv(dev);
8884 if (!bp)
8885 goto shutdown_exit;
8886
8887 if (netif_running(dev))
8888 dev_close(dev);
8889
Ray Juia7f3f932017-12-01 03:13:02 -05008890 bnxt_ulp_shutdown(bp);
8891
Michael Chand196ece2017-04-04 18:14:08 -04008892 if (system_state == SYSTEM_POWER_OFF) {
8893 bnxt_clear_int_mode(bp);
8894 pci_wake_from_d3(pdev, bp->wol);
8895 pci_set_power_state(pdev, PCI_D3hot);
8896 }
8897
8898shutdown_exit:
8899 rtnl_unlock();
8900}
8901
Michael Chanf65a2042017-04-04 18:14:11 -04008902#ifdef CONFIG_PM_SLEEP
8903static int bnxt_suspend(struct device *device)
8904{
8905 struct pci_dev *pdev = to_pci_dev(device);
8906 struct net_device *dev = pci_get_drvdata(pdev);
8907 struct bnxt *bp = netdev_priv(dev);
8908 int rc = 0;
8909
8910 rtnl_lock();
8911 if (netif_running(dev)) {
8912 netif_device_detach(dev);
8913 rc = bnxt_close(dev);
8914 }
8915 bnxt_hwrm_func_drv_unrgtr(bp);
8916 rtnl_unlock();
8917 return rc;
8918}
8919
8920static int bnxt_resume(struct device *device)
8921{
8922 struct pci_dev *pdev = to_pci_dev(device);
8923 struct net_device *dev = pci_get_drvdata(pdev);
8924 struct bnxt *bp = netdev_priv(dev);
8925 int rc = 0;
8926
8927 rtnl_lock();
8928 if (bnxt_hwrm_ver_get(bp) || bnxt_hwrm_func_drv_rgtr(bp)) {
8929 rc = -ENODEV;
8930 goto resume_exit;
8931 }
8932 rc = bnxt_hwrm_func_reset(bp);
8933 if (rc) {
8934 rc = -EBUSY;
8935 goto resume_exit;
8936 }
8937 bnxt_get_wol_settings(bp);
8938 if (netif_running(dev)) {
8939 rc = bnxt_open(dev);
8940 if (!rc)
8941 netif_device_attach(dev);
8942 }
8943
8944resume_exit:
8945 rtnl_unlock();
8946 return rc;
8947}
8948
8949static SIMPLE_DEV_PM_OPS(bnxt_pm_ops, bnxt_suspend, bnxt_resume);
8950#define BNXT_PM_OPS (&bnxt_pm_ops)
8951
8952#else
8953
8954#define BNXT_PM_OPS NULL
8955
8956#endif /* CONFIG_PM_SLEEP */
8957
Satish Baddipadige6316ea62016-03-07 15:38:48 -05008958/**
8959 * bnxt_io_error_detected - called when PCI error is detected
8960 * @pdev: Pointer to PCI device
8961 * @state: The current pci connection state
8962 *
8963 * This function is called after a PCI bus error affecting
8964 * this device has been detected.
8965 */
8966static pci_ers_result_t bnxt_io_error_detected(struct pci_dev *pdev,
8967 pci_channel_state_t state)
8968{
8969 struct net_device *netdev = pci_get_drvdata(pdev);
Michael Chana588e452016-12-07 00:26:21 -05008970 struct bnxt *bp = netdev_priv(netdev);
Satish Baddipadige6316ea62016-03-07 15:38:48 -05008971
8972 netdev_info(netdev, "PCI I/O error detected\n");
8973
8974 rtnl_lock();
8975 netif_device_detach(netdev);
8976
Michael Chana588e452016-12-07 00:26:21 -05008977 bnxt_ulp_stop(bp);
8978
Satish Baddipadige6316ea62016-03-07 15:38:48 -05008979 if (state == pci_channel_io_perm_failure) {
8980 rtnl_unlock();
8981 return PCI_ERS_RESULT_DISCONNECT;
8982 }
8983
8984 if (netif_running(netdev))
8985 bnxt_close(netdev);
8986
8987 pci_disable_device(pdev);
8988 rtnl_unlock();
8989
8990 /* Request a slot slot reset. */
8991 return PCI_ERS_RESULT_NEED_RESET;
8992}
8993
8994/**
8995 * bnxt_io_slot_reset - called after the pci bus has been reset.
8996 * @pdev: Pointer to PCI device
8997 *
8998 * Restart the card from scratch, as if from a cold-boot.
8999 * At this point, the card has exprienced a hard reset,
9000 * followed by fixups by BIOS, and has its config space
9001 * set up identically to what it was at cold boot.
9002 */
9003static pci_ers_result_t bnxt_io_slot_reset(struct pci_dev *pdev)
9004{
9005 struct net_device *netdev = pci_get_drvdata(pdev);
9006 struct bnxt *bp = netdev_priv(netdev);
9007 int err = 0;
9008 pci_ers_result_t result = PCI_ERS_RESULT_DISCONNECT;
9009
9010 netdev_info(bp->dev, "PCI Slot Reset\n");
9011
9012 rtnl_lock();
9013
9014 if (pci_enable_device(pdev)) {
9015 dev_err(&pdev->dev,
9016 "Cannot re-enable PCI device after reset.\n");
9017 } else {
9018 pci_set_master(pdev);
9019
Michael Chanaa8ed022016-12-07 00:26:17 -05009020 err = bnxt_hwrm_func_reset(bp);
9021 if (!err && netif_running(netdev))
Satish Baddipadige6316ea62016-03-07 15:38:48 -05009022 err = bnxt_open(netdev);
9023
Michael Chana588e452016-12-07 00:26:21 -05009024 if (!err) {
Satish Baddipadige6316ea62016-03-07 15:38:48 -05009025 result = PCI_ERS_RESULT_RECOVERED;
Michael Chana588e452016-12-07 00:26:21 -05009026 bnxt_ulp_start(bp);
9027 }
Satish Baddipadige6316ea62016-03-07 15:38:48 -05009028 }
9029
9030 if (result != PCI_ERS_RESULT_RECOVERED && netif_running(netdev))
9031 dev_close(netdev);
9032
9033 rtnl_unlock();
9034
9035 err = pci_cleanup_aer_uncorrect_error_status(pdev);
9036 if (err) {
9037 dev_err(&pdev->dev,
9038 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
9039 err); /* non-fatal, continue */
9040 }
9041
9042 return PCI_ERS_RESULT_RECOVERED;
9043}
9044
9045/**
9046 * bnxt_io_resume - called when traffic can start flowing again.
9047 * @pdev: Pointer to PCI device
9048 *
9049 * This callback is called when the error recovery driver tells
9050 * us that its OK to resume normal operation.
9051 */
9052static void bnxt_io_resume(struct pci_dev *pdev)
9053{
9054 struct net_device *netdev = pci_get_drvdata(pdev);
9055
9056 rtnl_lock();
9057
9058 netif_device_attach(netdev);
9059
9060 rtnl_unlock();
9061}
9062
9063static const struct pci_error_handlers bnxt_err_handler = {
9064 .error_detected = bnxt_io_error_detected,
9065 .slot_reset = bnxt_io_slot_reset,
9066 .resume = bnxt_io_resume
9067};
9068
Michael Chanc0c050c2015-10-22 16:01:17 -04009069static struct pci_driver bnxt_pci_driver = {
9070 .name = DRV_MODULE_NAME,
9071 .id_table = bnxt_pci_tbl,
9072 .probe = bnxt_init_one,
9073 .remove = bnxt_remove_one,
Michael Chand196ece2017-04-04 18:14:08 -04009074 .shutdown = bnxt_shutdown,
Michael Chanf65a2042017-04-04 18:14:11 -04009075 .driver.pm = BNXT_PM_OPS,
Satish Baddipadige6316ea62016-03-07 15:38:48 -05009076 .err_handler = &bnxt_err_handler,
Michael Chanc0c050c2015-10-22 16:01:17 -04009077#if defined(CONFIG_BNXT_SRIOV)
9078 .sriov_configure = bnxt_sriov_configure,
9079#endif
9080};
9081
Michael Chanc213eae2017-10-13 21:09:29 -04009082static int __init bnxt_init(void)
9083{
9084 return pci_register_driver(&bnxt_pci_driver);
9085}
9086
9087static void __exit bnxt_exit(void)
9088{
9089 pci_unregister_driver(&bnxt_pci_driver);
9090 if (bnxt_pf_wq)
9091 destroy_workqueue(bnxt_pf_wq);
9092}
9093
9094module_init(bnxt_init);
9095module_exit(bnxt_exit);