blob: 11fe5961040a925ce330f4dce8c05c7f555dcc59 [file] [log] [blame]
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001/*
2 * This file is part of the Chelsio T4 Ethernet driver for Linux.
3 *
Rahul Lakkireddyb72a32d2016-08-22 16:29:06 +05304 * Copyright (c) 2003-2016 Chelsio Communications, Inc. All rights reserved.
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005 *
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
11 *
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
14 * conditions are met:
15 *
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer.
19 *
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 * SOFTWARE.
33 */
34
35#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
36
37#include <linux/bitmap.h>
38#include <linux/crc32.h>
39#include <linux/ctype.h>
40#include <linux/debugfs.h>
41#include <linux/err.h>
42#include <linux/etherdevice.h>
43#include <linux/firmware.h>
Jiri Pirko01789342011-08-16 06:29:00 +000044#include <linux/if.h>
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +000045#include <linux/if_vlan.h>
46#include <linux/init.h>
47#include <linux/log2.h>
48#include <linux/mdio.h>
49#include <linux/module.h>
50#include <linux/moduleparam.h>
51#include <linux/mutex.h>
52#include <linux/netdevice.h>
53#include <linux/pci.h>
54#include <linux/aer.h>
55#include <linux/rtnetlink.h>
56#include <linux/sched.h>
57#include <linux/seq_file.h>
58#include <linux/sockios.h>
59#include <linux/vmalloc.h>
60#include <linux/workqueue.h>
61#include <net/neighbour.h>
62#include <net/netevent.h>
Vipul Pandya01bcca62013-07-04 16:10:46 +053063#include <net/addrconf.h>
David S. Miller1ef80192014-11-10 13:27:49 -050064#include <net/bonding.h>
Anish Bhattb5a02f52015-01-14 15:17:34 -080065#include <net/addrconf.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080066#include <linux/uaccess.h>
Hariprasad Shenaic5a8c0f2016-06-14 14:39:30 +053067#include <linux/crash_dump.h>
Ganesh Goudar846eac32018-01-10 18:15:08 +053068#include <net/udp_tunnel.h>
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +000069
70#include "cxgb4.h"
Rahul Lakkireddyd57fd6c2016-09-20 17:13:06 +053071#include "cxgb4_filter.h"
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +000072#include "t4_regs.h"
Hariprasad Shenaif612b812015-01-05 16:30:43 +053073#include "t4_values.h"
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +000074#include "t4_msg.h"
75#include "t4fw_api.h"
Hariprasad Shenaicd6c2f12015-01-27 20:12:52 +053076#include "t4fw_version.h"
Anish Bhatt688848b2014-06-19 21:37:13 -070077#include "cxgb4_dcb.h"
Hariprasad Shenaifd88b312014-11-07 09:35:23 +053078#include "cxgb4_debugfs.h"
Anish Bhattb5a02f52015-01-14 15:17:34 -080079#include "clip_tbl.h"
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +000080#include "l2t.h"
Kumar Sanghvi3bdb3762017-10-18 20:49:11 +053081#include "smt.h"
Rahul Lakkireddyb72a32d2016-08-22 16:29:06 +053082#include "sched.h"
Rahul Lakkireddyd8931842016-09-20 17:13:09 +053083#include "cxgb4_tc_u32.h"
Kumar Sanghvi6a345b32017-09-21 23:41:13 +053084#include "cxgb4_tc_flower.h"
Atul Guptaa45695042017-07-04 16:46:20 +053085#include "cxgb4_ptp.h"
Rahul Lakkireddyad75b7d2017-10-13 18:48:13 +053086#include "cxgb4_cudbg.h"
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +000087
Hariprasad Shenai812034f2015-04-06 20:23:23 +053088char cxgb4_driver_name[] = KBUILD_MODNAME;
89
Vipul Pandya01bcca62013-07-04 16:10:46 +053090#ifdef DRV_VERSION
91#undef DRV_VERSION
92#endif
Santosh Rastapur3a7f8552013-03-14 05:08:55 +000093#define DRV_VERSION "2.0.0-ko"
Hariprasad Shenai812034f2015-04-06 20:23:23 +053094const char cxgb4_driver_version[] = DRV_VERSION;
Hariprasad Shenai52a5f842015-10-21 14:39:54 +053095#define DRV_DESC "Chelsio T4/T5/T6 Network Driver"
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +000096
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +000097#define DFLT_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK | \
98 NETIF_MSG_TIMER | NETIF_MSG_IFDOWN | NETIF_MSG_IFUP |\
99 NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR)
100
Hariprasad Shenai3fedeab2014-11-25 08:33:58 +0530101/* Macros needed to support the PCI Device ID Table ...
102 */
103#define CH_PCI_DEVICE_ID_TABLE_DEFINE_BEGIN \
Hariprasad Shenai768ffc62015-03-19 22:27:36 +0530104 static const struct pci_device_id cxgb4_pci_tbl[] = {
Ganesh Goudarbaf50862018-01-16 16:17:40 +0530105#define CXGB4_UNIFIED_PF 0x4
106
107#define CH_PCI_DEVICE_ID_FUNCTION CXGB4_UNIFIED_PF
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000108
Hariprasad Shenai3fedeab2014-11-25 08:33:58 +0530109/* Include PCI Device IDs for both PF4 and PF0-3 so our PCI probe() routine is
110 * called for both.
111 */
112#define CH_PCI_DEVICE_ID_FUNCTION2 0x0
113
114#define CH_PCI_ID_TABLE_ENTRY(devid) \
Ganesh Goudarbaf50862018-01-16 16:17:40 +0530115 {PCI_VDEVICE(CHELSIO, (devid)), CXGB4_UNIFIED_PF}
Hariprasad Shenai3fedeab2014-11-25 08:33:58 +0530116
117#define CH_PCI_DEVICE_ID_TABLE_DEFINE_END \
118 { 0, } \
119 }
120
121#include "t4_pci_id_tbl.h"
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000122
Hariprasad Shenai16e47622013-12-03 17:05:58 +0530123#define FW4_FNAME "cxgb4/t4fw.bin"
Santosh Rastapur0a57a532013-03-14 05:08:49 +0000124#define FW5_FNAME "cxgb4/t5fw.bin"
Hariprasad Shenai3ccc6cf2015-06-02 13:59:39 +0530125#define FW6_FNAME "cxgb4/t6fw.bin"
Hariprasad Shenai16e47622013-12-03 17:05:58 +0530126#define FW4_CFNAME "cxgb4/t4-config.txt"
Santosh Rastapur0a57a532013-03-14 05:08:49 +0000127#define FW5_CFNAME "cxgb4/t5-config.txt"
Hariprasad Shenai3ccc6cf2015-06-02 13:59:39 +0530128#define FW6_CFNAME "cxgb4/t6-config.txt"
Hariprasad Shenai01b69612015-05-22 21:58:21 +0530129#define PHY_AQ1202_FIRMWARE "cxgb4/aq1202_fw.cld"
130#define PHY_BCM84834_FIRMWARE "cxgb4/bcm8483.bin"
131#define PHY_AQ1202_DEVICEID 0x4409
132#define PHY_BCM84834_DEVICEID 0x4486
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000133
134MODULE_DESCRIPTION(DRV_DESC);
135MODULE_AUTHOR("Chelsio Communications");
136MODULE_LICENSE("Dual BSD/GPL");
137MODULE_VERSION(DRV_VERSION);
138MODULE_DEVICE_TABLE(pci, cxgb4_pci_tbl);
Hariprasad Shenai16e47622013-12-03 17:05:58 +0530139MODULE_FIRMWARE(FW4_FNAME);
Santosh Rastapur0a57a532013-03-14 05:08:49 +0000140MODULE_FIRMWARE(FW5_FNAME);
Hariprasad Shenai52a5f842015-10-21 14:39:54 +0530141MODULE_FIRMWARE(FW6_FNAME);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000142
Vipul Pandya636f9d32012-09-26 02:39:39 +0000143/*
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000144 * The driver uses the best interrupt scheme available on a platform in the
145 * order MSI-X, MSI, legacy INTx interrupts. This parameter determines which
146 * of these schemes the driver may consider as follows:
147 *
148 * msi = 2: choose from among all three options
149 * msi = 1: only consider MSI and INTx interrupts
150 * msi = 0: force INTx interrupts
151 */
152static int msi = 2;
153
154module_param(msi, int, 0644);
155MODULE_PARM_DESC(msi, "whether to use INTx (0), MSI (1) or MSI-X (2)");
156
157/*
Vipul Pandya636f9d32012-09-26 02:39:39 +0000158 * Normally we tell the chip to deliver Ingress Packets into our DMA buffers
159 * offset by 2 bytes in order to have the IP headers line up on 4-byte
160 * boundaries. This is a requirement for many architectures which will throw
161 * a machine check fault if an attempt is made to access one of the 4-byte IP
162 * header fields on a non-4-byte boundary. And it's a major performance issue
163 * even on some architectures which allow it like some implementations of the
164 * x86 ISA. However, some architectures don't mind this and for some very
165 * edge-case performance sensitive applications (like forwarding large volumes
166 * of small packets), setting this DMA offset to 0 will decrease the number of
167 * PCI-E Bus transfers enough to measurably affect performance.
168 */
169static int rx_dma_offset = 2;
170
Anish Bhatt688848b2014-06-19 21:37:13 -0700171/* TX Queue select used to determine what algorithm to use for selecting TX
172 * queue. Select between the kernel provided function (select_queue=0) or user
173 * cxgb_select_queue function (select_queue=1)
174 *
175 * Default: select_queue=0
176 */
177static int select_queue;
178module_param(select_queue, int, 0644);
179MODULE_PARM_DESC(select_queue,
180 "Select between kernel provided method of selecting or driver method of selecting TX queue. Default is kernel method.");
181
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000182static struct dentry *cxgb4_debugfs_root;
183
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +0530184LIST_HEAD(adapter_list);
185DEFINE_MUTEX(uld_mutex);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000186
187static void link_report(struct net_device *dev)
188{
189 if (!netif_carrier_ok(dev))
190 netdev_info(dev, "link down\n");
191 else {
192 static const char *fc[] = { "no", "Rx", "Tx", "Tx/Rx" };
193
Hariprasad Shenai85412252015-10-01 13:48:48 +0530194 const char *s;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000195 const struct port_info *p = netdev_priv(dev);
196
197 switch (p->link_cfg.speed) {
Ben Hutchingse8b39012014-02-23 00:03:24 +0000198 case 100:
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000199 s = "100Mbps";
200 break;
Ganesh Goudar5e78f7f2017-01-06 16:51:46 +0530201 case 1000:
202 s = "1Gbps";
203 break;
204 case 10000:
205 s = "10Gbps";
206 break;
207 case 25000:
208 s = "25Gbps";
209 break;
Ben Hutchingse8b39012014-02-23 00:03:24 +0000210 case 40000:
Kumar Sanghvi72aca4b2014-02-18 17:56:08 +0530211 s = "40Gbps";
212 break;
Ganesh Goudar5e78f7f2017-01-06 16:51:46 +0530213 case 100000:
214 s = "100Gbps";
215 break;
Hariprasad Shenai85412252015-10-01 13:48:48 +0530216 default:
217 pr_info("%s: unsupported speed: %d\n",
218 dev->name, p->link_cfg.speed);
219 return;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000220 }
221
222 netdev_info(dev, "link up, %s, full-duplex, %s PAUSE\n", s,
223 fc[p->link_cfg.fc]);
224 }
225}
226
Anish Bhatt688848b2014-06-19 21:37:13 -0700227#ifdef CONFIG_CHELSIO_T4_DCB
228/* Set up/tear down Data Center Bridging Priority mapping for a net device. */
229static void dcb_tx_queue_prio_enable(struct net_device *dev, int enable)
230{
231 struct port_info *pi = netdev_priv(dev);
232 struct adapter *adap = pi->adapter;
233 struct sge_eth_txq *txq = &adap->sge.ethtxq[pi->first_qset];
234 int i;
235
236 /* We use a simple mapping of Port TX Queue Index to DCB
237 * Priority when we're enabling DCB.
238 */
239 for (i = 0; i < pi->nqsets; i++, txq++) {
240 u32 name, value;
241 int err;
242
Hariprasad Shenai51678652014-11-21 12:52:02 +0530243 name = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DMAQ) |
244 FW_PARAMS_PARAM_X_V(
245 FW_PARAMS_PARAM_DMAQ_EQ_DCBPRIO_ETH) |
246 FW_PARAMS_PARAM_YZ_V(txq->q.cntxt_id));
Anish Bhatt688848b2014-06-19 21:37:13 -0700247 value = enable ? i : 0xffffffff;
248
249 /* Since we can be called while atomic (from "interrupt
250 * level") we need to issue the Set Parameters Commannd
251 * without sleeping (timeout < 0).
252 */
Hariprasad Shenaib2612722015-05-27 22:30:24 +0530253 err = t4_set_params_timeout(adap, adap->mbox, adap->pf, 0, 1,
Hariprasad Shenai01b69612015-05-22 21:58:21 +0530254 &name, &value,
255 -FW_CMD_MAX_TIMEOUT);
Anish Bhatt688848b2014-06-19 21:37:13 -0700256
257 if (err)
258 dev_err(adap->pdev_dev,
259 "Can't %s DCB Priority on port %d, TX Queue %d: err=%d\n",
260 enable ? "set" : "unset", pi->port_id, i, -err);
Anish Bhatt10b00462014-08-07 16:14:03 -0700261 else
262 txq->dcb_prio = value;
Anish Bhatt688848b2014-06-19 21:37:13 -0700263 }
264}
Anish Bhatt688848b2014-06-19 21:37:13 -0700265
Baoyou Xie50935852016-09-25 14:10:09 +0800266static int cxgb4_dcb_enabled(const struct net_device *dev)
Hariprasad Shenai218d48e2016-05-05 11:05:39 +0530267{
Hariprasad Shenai218d48e2016-05-05 11:05:39 +0530268 struct port_info *pi = netdev_priv(dev);
269
270 if (!pi->dcb.enabled)
271 return 0;
272
273 return ((pi->dcb.state == CXGB4_DCB_STATE_FW_ALLSYNCED) ||
274 (pi->dcb.state == CXGB4_DCB_STATE_HOST));
Hariprasad Shenai218d48e2016-05-05 11:05:39 +0530275}
Arnd Bergmann7c70c4f2016-09-30 18:15:33 +0200276#endif /* CONFIG_CHELSIO_T4_DCB */
Hariprasad Shenai218d48e2016-05-05 11:05:39 +0530277
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000278void t4_os_link_changed(struct adapter *adapter, int port_id, int link_stat)
279{
280 struct net_device *dev = adapter->port[port_id];
281
282 /* Skip changes from disabled ports. */
283 if (netif_running(dev) && link_stat != netif_carrier_ok(dev)) {
284 if (link_stat)
285 netif_carrier_on(dev);
Anish Bhatt688848b2014-06-19 21:37:13 -0700286 else {
287#ifdef CONFIG_CHELSIO_T4_DCB
Hariprasad Shenai218d48e2016-05-05 11:05:39 +0530288 if (cxgb4_dcb_enabled(dev)) {
Ganesh Goudarba581f72017-09-23 16:07:28 +0530289 cxgb4_dcb_reset(dev);
Hariprasad Shenai218d48e2016-05-05 11:05:39 +0530290 dcb_tx_queue_prio_enable(dev, false);
291 }
Anish Bhatt688848b2014-06-19 21:37:13 -0700292#endif /* CONFIG_CHELSIO_T4_DCB */
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000293 netif_carrier_off(dev);
Anish Bhatt688848b2014-06-19 21:37:13 -0700294 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000295
296 link_report(dev);
297 }
298}
299
300void t4_os_portmod_changed(const struct adapter *adap, int port_id)
301{
302 static const char *mod_str[] = {
Dimitris Michailidisa0881ca2010-06-18 10:05:34 +0000303 NULL, "LR", "SR", "ER", "passive DA", "active DA", "LRM"
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000304 };
305
306 const struct net_device *dev = adap->port[port_id];
307 const struct port_info *pi = netdev_priv(dev);
308
309 if (pi->mod_type == FW_PORT_MOD_TYPE_NONE)
310 netdev_info(dev, "port module unplugged\n");
Dimitris Michailidisa0881ca2010-06-18 10:05:34 +0000311 else if (pi->mod_type < ARRAY_SIZE(mod_str))
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000312 netdev_info(dev, "%s module inserted\n", mod_str[pi->mod_type]);
Hariprasad Shenaibe81a2d2016-04-26 20:10:25 +0530313 else if (pi->mod_type == FW_PORT_MOD_TYPE_NOTSUPPORTED)
314 netdev_info(dev, "%s: unsupported port module inserted\n",
315 dev->name);
316 else if (pi->mod_type == FW_PORT_MOD_TYPE_UNKNOWN)
317 netdev_info(dev, "%s: unknown port module inserted\n",
318 dev->name);
319 else if (pi->mod_type == FW_PORT_MOD_TYPE_ERROR)
320 netdev_info(dev, "%s: transceiver module error\n", dev->name);
321 else
322 netdev_info(dev, "%s: unknown module type %d inserted\n",
323 dev->name, pi->mod_type);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000324}
325
Vipul Pandya3069ee9b2012-05-18 15:29:26 +0530326int dbfifo_int_thresh = 10; /* 10 == 640 entry threshold */
327module_param(dbfifo_int_thresh, int, 0644);
328MODULE_PARM_DESC(dbfifo_int_thresh, "doorbell fifo interrupt threshold");
329
Vipul Pandya404d9e32012-10-08 02:59:43 +0000330/*
331 * usecs to sleep while draining the dbfifo
332 */
333static int dbfifo_drain_delay = 1000;
Vipul Pandya3069ee9b2012-05-18 15:29:26 +0530334module_param(dbfifo_drain_delay, int, 0644);
335MODULE_PARM_DESC(dbfifo_drain_delay,
336 "usecs to sleep while draining the dbfifo");
337
Hariprasad Shenaifc08a012016-02-16 10:07:09 +0530338static inline int cxgb4_set_addr_hash(struct port_info *pi)
339{
340 struct adapter *adap = pi->adapter;
341 u64 vec = 0;
342 bool ucast = false;
343 struct hash_mac_addr *entry;
344
345 /* Calculate the hash vector for the updated list and program it */
346 list_for_each_entry(entry, &adap->mac_hlist, list) {
347 ucast |= is_unicast_ether_addr(entry->addr);
348 vec |= (1ULL << hash_mac_addr(entry->addr));
349 }
350 return t4_set_addr_hash(adap, adap->mbox, pi->viid, ucast,
351 vec, false);
352}
353
354static int cxgb4_mac_sync(struct net_device *netdev, const u8 *mac_addr)
355{
356 struct port_info *pi = netdev_priv(netdev);
357 struct adapter *adap = pi->adapter;
358 int ret;
359 u64 mhash = 0;
360 u64 uhash = 0;
361 bool free = false;
362 bool ucast = is_unicast_ether_addr(mac_addr);
363 const u8 *maclist[1] = {mac_addr};
364 struct hash_mac_addr *new_entry;
365
366 ret = t4_alloc_mac_filt(adap, adap->mbox, pi->viid, free, 1, maclist,
367 NULL, ucast ? &uhash : &mhash, false);
368 if (ret < 0)
369 goto out;
370 /* if hash != 0, then add the addr to hash addr list
371 * so on the end we will calculate the hash for the
372 * list and program it
373 */
374 if (uhash || mhash) {
375 new_entry = kzalloc(sizeof(*new_entry), GFP_ATOMIC);
376 if (!new_entry)
377 return -ENOMEM;
378 ether_addr_copy(new_entry->addr, mac_addr);
379 list_add_tail(&new_entry->list, &adap->mac_hlist);
380 ret = cxgb4_set_addr_hash(pi);
381 }
382out:
383 return ret < 0 ? ret : 0;
384}
385
386static int cxgb4_mac_unsync(struct net_device *netdev, const u8 *mac_addr)
387{
388 struct port_info *pi = netdev_priv(netdev);
389 struct adapter *adap = pi->adapter;
390 int ret;
391 const u8 *maclist[1] = {mac_addr};
392 struct hash_mac_addr *entry, *tmp;
393
394 /* If the MAC address to be removed is in the hash addr
395 * list, delete it from the list and update hash vector
396 */
397 list_for_each_entry_safe(entry, tmp, &adap->mac_hlist, list) {
398 if (ether_addr_equal(entry->addr, mac_addr)) {
399 list_del(&entry->list);
400 kfree(entry);
401 return cxgb4_set_addr_hash(pi);
402 }
403 }
404
405 ret = t4_free_mac_filt(adap, adap->mbox, pi->viid, 1, maclist, false);
406 return ret < 0 ? -EINVAL : 0;
407}
408
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000409/*
410 * Set Rx properties of a port, such as promiscruity, address filters, and MTU.
411 * If @mtu is -1 it is left unchanged.
412 */
413static int set_rxmode(struct net_device *dev, int mtu, bool sleep_ok)
414{
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000415 struct port_info *pi = netdev_priv(dev);
Hariprasad Shenaifc08a012016-02-16 10:07:09 +0530416 struct adapter *adapter = pi->adapter;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000417
Hariprasad Shenaid01f7ab2016-06-14 14:39:32 +0530418 __dev_uc_sync(dev, cxgb4_mac_sync, cxgb4_mac_unsync);
419 __dev_mc_sync(dev, cxgb4_mac_sync, cxgb4_mac_unsync);
Hariprasad Shenaifc08a012016-02-16 10:07:09 +0530420
421 return t4_set_rxmode(adapter, adapter->mbox, pi->viid, mtu,
422 (dev->flags & IFF_PROMISC) ? 1 : 0,
423 (dev->flags & IFF_ALLMULTI) ? 1 : 0, 1, -1,
424 sleep_ok);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000425}
426
427/**
428 * link_start - enable a port
429 * @dev: the port to enable
430 *
431 * Performs the MAC and PHY actions needed to enable a port.
432 */
433static int link_start(struct net_device *dev)
434{
435 int ret;
436 struct port_info *pi = netdev_priv(dev);
Hariprasad Shenaib2612722015-05-27 22:30:24 +0530437 unsigned int mb = pi->adapter->pf;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000438
439 /*
440 * We do not set address filters and promiscuity here, the stack does
441 * that step explicitly.
442 */
Dimitris Michailidis060e0c72010-08-02 13:19:21 +0000443 ret = t4_set_rxmode(pi->adapter, mb, pi->viid, dev->mtu, -1, -1, -1,
Patrick McHardyf6469682013-04-19 02:04:27 +0000444 !!(dev->features & NETIF_F_HW_VLAN_CTAG_RX), true);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000445 if (ret == 0) {
Dimitris Michailidis060e0c72010-08-02 13:19:21 +0000446 ret = t4_change_mac(pi->adapter, mb, pi->viid,
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000447 pi->xact_addr_filt, dev->dev_addr, true,
Dimitris Michailidisb6bd29e2010-05-18 10:07:11 +0000448 true);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000449 if (ret >= 0) {
450 pi->xact_addr_filt = ret;
451 ret = 0;
452 }
453 }
454 if (ret == 0)
Hariprasad Shenai4036da92015-06-05 14:24:49 +0530455 ret = t4_link_l1cfg(pi->adapter, mb, pi->tx_chan,
Dimitris Michailidis060e0c72010-08-02 13:19:21 +0000456 &pi->link_cfg);
Anish Bhatt30f00842014-08-05 16:05:23 -0700457 if (ret == 0) {
458 local_bh_disable();
Anish Bhatt688848b2014-06-19 21:37:13 -0700459 ret = t4_enable_vi_params(pi->adapter, mb, pi->viid, true,
460 true, CXGB4_DCB_ENABLED);
Anish Bhatt30f00842014-08-05 16:05:23 -0700461 local_bh_enable();
462 }
Anish Bhatt688848b2014-06-19 21:37:13 -0700463
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000464 return ret;
465}
466
Anish Bhatt688848b2014-06-19 21:37:13 -0700467#ifdef CONFIG_CHELSIO_T4_DCB
468/* Handle a Data Center Bridging update message from the firmware. */
469static void dcb_rpl(struct adapter *adap, const struct fw_port_cmd *pcmd)
470{
Hariprasad Shenai2b5fb1f2014-11-21 12:52:04 +0530471 int port = FW_PORT_CMD_PORTID_G(ntohl(pcmd->op_to_portid));
Hariprasad Shenai134491f2016-04-26 20:10:27 +0530472 struct net_device *dev = adap->port[adap->chan_map[port]];
Anish Bhatt688848b2014-06-19 21:37:13 -0700473 int old_dcb_enabled = cxgb4_dcb_enabled(dev);
474 int new_dcb_enabled;
475
476 cxgb4_dcb_handle_fw_update(adap, pcmd);
477 new_dcb_enabled = cxgb4_dcb_enabled(dev);
478
479 /* If the DCB has become enabled or disabled on the port then we're
480 * going to need to set up/tear down DCB Priority parameters for the
481 * TX Queues associated with the port.
482 */
483 if (new_dcb_enabled != old_dcb_enabled)
484 dcb_tx_queue_prio_enable(dev, new_dcb_enabled);
485}
486#endif /* CONFIG_CHELSIO_T4_DCB */
487
Vipul Pandyaf2b7e782012-12-10 09:30:52 +0000488/* Response queue handler for the FW event queue.
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000489 */
490static int fwevtq_handler(struct sge_rspq *q, const __be64 *rsp,
491 const struct pkt_gl *gl)
492{
493 u8 opcode = ((const struct rss_header *)rsp)->opcode;
494
495 rsp++; /* skip RSS header */
Vipul Pandyab407a4a2013-04-29 04:04:40 +0000496
497 /* FW can send EGR_UPDATEs encapsulated in a CPL_FW4_MSG.
498 */
499 if (unlikely(opcode == CPL_FW4_MSG &&
500 ((const struct cpl_fw4_msg *)rsp)->type == FW_TYPE_RSSCPL)) {
501 rsp++;
502 opcode = ((const struct rss_header *)rsp)->opcode;
503 rsp++;
504 if (opcode != CPL_SGE_EGR_UPDATE) {
505 dev_err(q->adap->pdev_dev, "unexpected FW4/CPL %#x on FW event queue\n"
506 , opcode);
507 goto out;
508 }
509 }
510
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000511 if (likely(opcode == CPL_SGE_EGR_UPDATE)) {
512 const struct cpl_sge_egr_update *p = (void *)rsp;
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -0800513 unsigned int qid = EGR_QID_G(ntohl(p->opcode_qid));
Dimitris Michailidise46dab42010-08-23 17:20:58 +0000514 struct sge_txq *txq;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000515
Dimitris Michailidise46dab42010-08-23 17:20:58 +0000516 txq = q->adap->sge.egr_map[qid - q->adap->sge.egr_start];
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000517 txq->restarts++;
Hariprasad Shenaiab677ff2016-11-18 16:37:40 +0530518 if (txq->q_type == CXGB4_TXQ_ETH) {
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000519 struct sge_eth_txq *eq;
520
521 eq = container_of(txq, struct sge_eth_txq, q);
522 netif_tx_wake_queue(eq->txq);
523 } else {
Hariprasad Shenaiab677ff2016-11-18 16:37:40 +0530524 struct sge_uld_txq *oq;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000525
Hariprasad Shenaiab677ff2016-11-18 16:37:40 +0530526 oq = container_of(txq, struct sge_uld_txq, q);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000527 tasklet_schedule(&oq->qresume_tsk);
528 }
529 } else if (opcode == CPL_FW6_MSG || opcode == CPL_FW4_MSG) {
530 const struct cpl_fw6_msg *p = (void *)rsp;
531
Anish Bhatt688848b2014-06-19 21:37:13 -0700532#ifdef CONFIG_CHELSIO_T4_DCB
533 const struct fw_port_cmd *pcmd = (const void *)p->data;
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530534 unsigned int cmd = FW_CMD_OP_G(ntohl(pcmd->op_to_portid));
Anish Bhatt688848b2014-06-19 21:37:13 -0700535 unsigned int action =
Hariprasad Shenai2b5fb1f2014-11-21 12:52:04 +0530536 FW_PORT_CMD_ACTION_G(ntohl(pcmd->action_to_len16));
Anish Bhatt688848b2014-06-19 21:37:13 -0700537
538 if (cmd == FW_PORT_CMD &&
Ganesh Goudarc3168ca2017-08-20 14:15:51 +0530539 (action == FW_PORT_ACTION_GET_PORT_INFO ||
540 action == FW_PORT_ACTION_GET_PORT_INFO32)) {
Hariprasad Shenai2b5fb1f2014-11-21 12:52:04 +0530541 int port = FW_PORT_CMD_PORTID_G(
Anish Bhatt688848b2014-06-19 21:37:13 -0700542 be32_to_cpu(pcmd->op_to_portid));
Ganesh Goudarc3168ca2017-08-20 14:15:51 +0530543 struct net_device *dev;
544 int dcbxdis, state_input;
545
546 dev = q->adap->port[q->adap->chan_map[port]];
547 dcbxdis = (action == FW_PORT_ACTION_GET_PORT_INFO
548 ? !!(pcmd->u.info.dcbxdis_pkd &
549 FW_PORT_CMD_DCBXDIS_F)
550 : !!(pcmd->u.info32.lstatus32_to_cbllen32 &
551 FW_PORT_CMD_DCBXDIS32_F));
552 state_input = (dcbxdis
553 ? CXGB4_DCB_INPUT_FW_DISABLED
554 : CXGB4_DCB_INPUT_FW_ENABLED);
Anish Bhatt688848b2014-06-19 21:37:13 -0700555
556 cxgb4_dcb_state_fsm(dev, state_input);
557 }
558
559 if (cmd == FW_PORT_CMD &&
560 action == FW_PORT_ACTION_L2_DCB_CFG)
561 dcb_rpl(q->adap, pcmd);
562 else
563#endif
564 if (p->type == 0)
565 t4_handle_fw_rpl(q->adap, p->data);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000566 } else if (opcode == CPL_L2T_WRITE_RPL) {
567 const struct cpl_l2t_write_rpl *p = (void *)rsp;
568
569 do_l2t_write_rpl(q->adap, p);
Kumar Sanghvi3bdb3762017-10-18 20:49:11 +0530570 } else if (opcode == CPL_SMT_WRITE_RPL) {
571 const struct cpl_smt_write_rpl *p = (void *)rsp;
572
573 do_smt_write_rpl(q->adap, p);
Vipul Pandyaf2b7e782012-12-10 09:30:52 +0000574 } else if (opcode == CPL_SET_TCB_RPL) {
575 const struct cpl_set_tcb_rpl *p = (void *)rsp;
576
577 filter_rpl(q->adap, p);
Kumar Sanghvi12b276f2017-11-01 08:53:01 +0530578 } else if (opcode == CPL_ACT_OPEN_RPL) {
579 const struct cpl_act_open_rpl *p = (void *)rsp;
580
581 hash_filter_rpl(q->adap, p);
Kumar Sanghvi3b0b3be2017-11-01 08:53:02 +0530582 } else if (opcode == CPL_ABORT_RPL_RSS) {
583 const struct cpl_abort_rpl_rss *p = (void *)rsp;
584
585 hash_del_filter_rpl(q->adap, p);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000586 } else
587 dev_err(q->adap->pdev_dev,
588 "unexpected CPL %#x on FW event queue\n", opcode);
Vipul Pandyab407a4a2013-04-29 04:04:40 +0000589out:
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000590 return 0;
591}
592
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000593static void disable_msi(struct adapter *adapter)
594{
595 if (adapter->flags & USING_MSIX) {
596 pci_disable_msix(adapter->pdev);
597 adapter->flags &= ~USING_MSIX;
598 } else if (adapter->flags & USING_MSI) {
599 pci_disable_msi(adapter->pdev);
600 adapter->flags &= ~USING_MSI;
601 }
602}
603
604/*
605 * Interrupt handler for non-data events used with MSI-X.
606 */
607static irqreturn_t t4_nondata_intr(int irq, void *cookie)
608{
609 struct adapter *adap = cookie;
Hariprasad Shenai0d804332015-01-05 16:30:47 +0530610 u32 v = t4_read_reg(adap, MYPF_REG(PL_PF_INT_CAUSE_A));
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000611
Hariprasad Shenai0d804332015-01-05 16:30:47 +0530612 if (v & PFSW_F) {
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000613 adap->swintr = 1;
Hariprasad Shenai0d804332015-01-05 16:30:47 +0530614 t4_write_reg(adap, MYPF_REG(PL_PF_INT_CAUSE_A), v);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000615 }
Hariprasad Shenaic3c7b122015-04-15 02:02:34 +0530616 if (adap->flags & MASTER_PF)
617 t4_slow_intr_handler(adap);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000618 return IRQ_HANDLED;
619}
620
621/*
622 * Name the MSI-X interrupts.
623 */
624static void name_msix_vecs(struct adapter *adap)
625{
Dimitris Michailidisba278162010-12-14 21:36:50 +0000626 int i, j, msi_idx = 2, n = sizeof(adap->msix_info[0].desc);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000627
628 /* non-data interrupts */
Dimitris Michailidisb1a3c2b2010-12-14 21:36:51 +0000629 snprintf(adap->msix_info[0].desc, n, "%s", adap->port[0]->name);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000630
631 /* FW events */
Dimitris Michailidisb1a3c2b2010-12-14 21:36:51 +0000632 snprintf(adap->msix_info[1].desc, n, "%s-FWeventq",
633 adap->port[0]->name);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000634
635 /* Ethernet queues */
636 for_each_port(adap, j) {
637 struct net_device *d = adap->port[j];
638 const struct port_info *pi = netdev_priv(d);
639
Dimitris Michailidisba278162010-12-14 21:36:50 +0000640 for (i = 0; i < pi->nqsets; i++, msi_idx++)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000641 snprintf(adap->msix_info[msi_idx].desc, n, "%s-Rx%d",
642 d->name, i);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000643 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000644}
645
646static int request_msix_queue_irqs(struct adapter *adap)
647{
648 struct sge *s = &adap->sge;
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +0530649 int err, ethqidx;
Hariprasad Shenaicf38be62014-06-06 21:40:42 +0530650 int msi_index = 2;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000651
652 err = request_irq(adap->msix_info[1].vec, t4_sge_intr_msix, 0,
653 adap->msix_info[1].desc, &s->fw_evtq);
654 if (err)
655 return err;
656
657 for_each_ethrxq(s, ethqidx) {
Vipul Pandya404d9e32012-10-08 02:59:43 +0000658 err = request_irq(adap->msix_info[msi_index].vec,
659 t4_sge_intr_msix, 0,
660 adap->msix_info[msi_index].desc,
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000661 &s->ethrxq[ethqidx].rspq);
662 if (err)
663 goto unwind;
Vipul Pandya404d9e32012-10-08 02:59:43 +0000664 msi_index++;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000665 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000666 return 0;
667
668unwind:
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000669 while (--ethqidx >= 0)
Vipul Pandya404d9e32012-10-08 02:59:43 +0000670 free_irq(adap->msix_info[--msi_index].vec,
671 &s->ethrxq[ethqidx].rspq);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000672 free_irq(adap->msix_info[1].vec, &s->fw_evtq);
673 return err;
674}
675
676static void free_msix_queue_irqs(struct adapter *adap)
677{
Vipul Pandya404d9e32012-10-08 02:59:43 +0000678 int i, msi_index = 2;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000679 struct sge *s = &adap->sge;
680
681 free_irq(adap->msix_info[1].vec, &s->fw_evtq);
682 for_each_ethrxq(s, i)
Vipul Pandya404d9e32012-10-08 02:59:43 +0000683 free_irq(adap->msix_info[msi_index++].vec, &s->ethrxq[i].rspq);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000684}
685
686/**
Hariprasad Shenai812034f2015-04-06 20:23:23 +0530687 * cxgb4_write_rss - write the RSS table for a given port
Dimitris Michailidis671b0062010-07-11 12:01:17 +0000688 * @pi: the port
689 * @queues: array of queue indices for RSS
690 *
691 * Sets up the portion of the HW RSS table for the port's VI to distribute
692 * packets to the Rx queues in @queues.
Hariprasad Shenaic035e182015-05-06 19:48:37 +0530693 * Should never be called before setting up sge eth rx queues
Dimitris Michailidis671b0062010-07-11 12:01:17 +0000694 */
Hariprasad Shenai812034f2015-04-06 20:23:23 +0530695int cxgb4_write_rss(const struct port_info *pi, const u16 *queues)
Dimitris Michailidis671b0062010-07-11 12:01:17 +0000696{
697 u16 *rss;
698 int i, err;
Hariprasad Shenaic035e182015-05-06 19:48:37 +0530699 struct adapter *adapter = pi->adapter;
700 const struct sge_eth_rxq *rxq;
Dimitris Michailidis671b0062010-07-11 12:01:17 +0000701
Hariprasad Shenaic035e182015-05-06 19:48:37 +0530702 rxq = &adapter->sge.ethrxq[pi->first_qset];
Dimitris Michailidis671b0062010-07-11 12:01:17 +0000703 rss = kmalloc(pi->rss_size * sizeof(u16), GFP_KERNEL);
704 if (!rss)
705 return -ENOMEM;
706
707 /* map the queue indices to queue ids */
708 for (i = 0; i < pi->rss_size; i++, queues++)
Hariprasad Shenaic035e182015-05-06 19:48:37 +0530709 rss[i] = rxq[*queues].rspq.abs_id;
Dimitris Michailidis671b0062010-07-11 12:01:17 +0000710
Hariprasad Shenaib2612722015-05-27 22:30:24 +0530711 err = t4_config_rss_range(adapter, adapter->pf, pi->viid, 0,
Dimitris Michailidis060e0c72010-08-02 13:19:21 +0000712 pi->rss_size, rss, pi->rss_size);
Hariprasad Shenaic035e182015-05-06 19:48:37 +0530713 /* If Tunnel All Lookup isn't specified in the global RSS
714 * Configuration, then we need to specify a default Ingress
715 * Queue for any ingress packets which aren't hashed. We'll
716 * use our first ingress queue ...
717 */
718 if (!err)
719 err = t4_config_vi_rss(adapter, adapter->mbox, pi->viid,
720 FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN_F |
721 FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN_F |
722 FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN_F |
723 FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN_F |
724 FW_RSS_VI_CONFIG_CMD_UDPEN_F,
725 rss[0]);
Dimitris Michailidis671b0062010-07-11 12:01:17 +0000726 kfree(rss);
727 return err;
728}
729
730/**
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000731 * setup_rss - configure RSS
732 * @adap: the adapter
733 *
Dimitris Michailidis671b0062010-07-11 12:01:17 +0000734 * Sets up RSS for each port.
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000735 */
736static int setup_rss(struct adapter *adap)
737{
Hariprasad Shenaic035e182015-05-06 19:48:37 +0530738 int i, j, err;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000739
740 for_each_port(adap, i) {
741 const struct port_info *pi = adap2pinfo(adap, i);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000742
Hariprasad Shenaic035e182015-05-06 19:48:37 +0530743 /* Fill default values with equal distribution */
744 for (j = 0; j < pi->rss_size; j++)
745 pi->rss[j] = j % pi->nqsets;
746
Hariprasad Shenai812034f2015-04-06 20:23:23 +0530747 err = cxgb4_write_rss(pi, pi->rss);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000748 if (err)
749 return err;
750 }
751 return 0;
752}
753
754/*
Dimitris Michailidise46dab42010-08-23 17:20:58 +0000755 * Return the channel of the ingress queue with the given qid.
756 */
757static unsigned int rxq_to_chan(const struct sge *p, unsigned int qid)
758{
759 qid -= p->ingr_start;
760 return netdev2pinfo(p->ingr_map[qid]->netdev)->tx_chan;
761}
762
763/*
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000764 * Wait until all NAPI handlers are descheduled.
765 */
766static void quiesce_rx(struct adapter *adap)
767{
768 int i;
769
Hariprasad Shenai4b8e27a2015-03-26 10:04:25 +0530770 for (i = 0; i < adap->sge.ingr_sz; i++) {
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000771 struct sge_rspq *q = adap->sge.ingr_map[i];
772
Eric Dumazet5226b7912017-02-02 11:44:27 -0800773 if (q && q->handler)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000774 napi_disable(&q->napi);
775 }
776}
777
Hariprasad Shenaib37987e2015-03-26 10:04:26 +0530778/* Disable interrupt and napi handler */
779static void disable_interrupts(struct adapter *adap)
780{
781 if (adap->flags & FULL_INIT_DONE) {
782 t4_intr_disable(adap);
783 if (adap->flags & USING_MSIX) {
784 free_msix_queue_irqs(adap);
785 free_irq(adap->msix_info[0].vec, adap);
786 } else {
787 free_irq(adap->pdev->irq, adap);
788 }
789 quiesce_rx(adap);
790 }
791}
792
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000793/*
794 * Enable NAPI scheduling and interrupt generation for all Rx queues.
795 */
796static void enable_rx(struct adapter *adap)
797{
798 int i;
799
Hariprasad Shenai4b8e27a2015-03-26 10:04:25 +0530800 for (i = 0; i < adap->sge.ingr_sz; i++) {
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000801 struct sge_rspq *q = adap->sge.ingr_map[i];
802
803 if (!q)
804 continue;
Eric Dumazet5226b7912017-02-02 11:44:27 -0800805 if (q->handler)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000806 napi_enable(&q->napi);
Eric Dumazet5226b7912017-02-02 11:44:27 -0800807
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000808 /* 0-increment GTS to start the timer and enable interrupts */
Hariprasad Shenaif612b812015-01-05 16:30:43 +0530809 t4_write_reg(adap, MYPF_REG(SGE_PF_GTS_A),
810 SEINTARM_V(q->intr_params) |
811 INGRESSQID_V(q->cntxt_id));
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000812 }
813}
814
Hariprasad Shenai1c6a5b02015-03-04 18:16:27 +0530815
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +0530816static int setup_fw_sge_queues(struct adapter *adap)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000817{
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000818 struct sge *s = &adap->sge;
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +0530819 int err = 0;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000820
Hariprasad Shenai4b8e27a2015-03-26 10:04:25 +0530821 bitmap_zero(s->starving_fl, s->egr_sz);
822 bitmap_zero(s->txq_maperr, s->egr_sz);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000823
824 if (adap->flags & USING_MSIX)
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +0530825 adap->msi_idx = 1; /* vector 0 is for non-queue interrupts */
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000826 else {
827 err = t4_sge_alloc_rxq(adap, &s->intrq, false, adap->port[0], 0,
Varun Prakash2337ba42016-02-14 23:02:41 +0530828 NULL, NULL, NULL, -1);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000829 if (err)
830 return err;
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +0530831 adap->msi_idx = -((int)s->intrq.abs_id + 1);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000832 }
833
834 err = t4_sge_alloc_rxq(adap, &s->fw_evtq, true, adap->port[0],
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +0530835 adap->msi_idx, NULL, fwevtq_handler, NULL, -1);
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +0530836 if (err)
837 t4_free_sge_resources(adap);
838 return err;
839}
840
841/**
842 * setup_sge_queues - configure SGE Tx/Rx/response queues
843 * @adap: the adapter
844 *
845 * Determines how many sets of SGE queues to use and initializes them.
846 * We support multiple queue sets per port if we have MSI-X, otherwise
847 * just one queue set per port.
848 */
849static int setup_sge_queues(struct adapter *adap)
850{
851 int err, i, j;
852 struct sge *s = &adap->sge;
Ganesh Goudard427cae2017-06-16 15:36:09 +0530853 struct sge_uld_rxq_info *rxq_info = NULL;
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +0530854 unsigned int cmplqid = 0;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000855
Ganesh Goudard427cae2017-06-16 15:36:09 +0530856 if (is_uld(adap))
857 rxq_info = s->uld_rxq_info[CXGB4_ULD_RDMA];
858
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000859 for_each_port(adap, i) {
860 struct net_device *dev = adap->port[i];
861 struct port_info *pi = netdev_priv(dev);
862 struct sge_eth_rxq *q = &s->ethrxq[pi->first_qset];
863 struct sge_eth_txq *t = &s->ethtxq[pi->first_qset];
864
865 for (j = 0; j < pi->nqsets; j++, q++) {
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +0530866 if (adap->msi_idx > 0)
867 adap->msi_idx++;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000868 err = t4_sge_alloc_rxq(adap, &q->rspq, false, dev,
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +0530869 adap->msi_idx, &q->fl,
Hariprasad Shenai145ef8a2015-05-05 14:59:52 +0530870 t4_ethrx_handler,
Varun Prakash2337ba42016-02-14 23:02:41 +0530871 NULL,
Arjun Vynipadath193c4c22017-06-23 19:14:36 +0530872 t4_get_tp_ch_map(adap,
873 pi->tx_chan));
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000874 if (err)
875 goto freeout;
876 q->rspq.idx = j;
877 memset(&q->stats, 0, sizeof(q->stats));
878 }
879 for (j = 0; j < pi->nqsets; j++, t++) {
880 err = t4_sge_alloc_eth_txq(adap, t, dev,
881 netdev_get_tx_queue(dev, j),
882 s->fw_evtq.cntxt_id);
883 if (err)
884 goto freeout;
885 }
886 }
887
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000888 for_each_port(adap, i) {
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +0530889 /* Note that cmplqid below is 0 if we don't
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000890 * have RDMA queues, and that's the right value.
891 */
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +0530892 if (rxq_info)
893 cmplqid = rxq_info->uldrxq[i].rspq.cntxt_id;
894
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000895 err = t4_sge_alloc_ctrl_txq(adap, &s->ctrlq[i], adap->port[i],
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +0530896 s->fw_evtq.cntxt_id, cmplqid);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000897 if (err)
898 goto freeout;
899 }
900
Atul Guptaa45695042017-07-04 16:46:20 +0530901 if (!is_t4(adap->params.chip)) {
902 err = t4_sge_alloc_eth_txq(adap, &s->ptptxq, adap->port[0],
903 netdev_get_tx_queue(adap->port[0], 0)
904 , s->fw_evtq.cntxt_id);
905 if (err)
906 goto freeout;
907 }
908
Hariprasad Shenai9bb59b92014-09-01 19:54:57 +0530909 t4_write_reg(adap, is_t4(adap->params.chip) ?
Hariprasad Shenai837e4a42015-01-05 16:30:46 +0530910 MPS_TRC_RSS_CONTROL_A :
911 MPS_T5_TRC_RSS_CONTROL_A,
912 RSSCONTROL_V(netdev2pinfo(adap->port[0])->tx_chan) |
913 QUEUENUMBER_V(s->ethrxq[0].rspq.abs_id));
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000914 return 0;
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +0530915freeout:
916 t4_free_sge_resources(adap);
917 return err;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000918}
919
Anish Bhatt688848b2014-06-19 21:37:13 -0700920static u16 cxgb_select_queue(struct net_device *dev, struct sk_buff *skb,
921 void *accel_priv, select_queue_fallback_t fallback)
922{
923 int txq;
924
925#ifdef CONFIG_CHELSIO_T4_DCB
926 /* If a Data Center Bridging has been successfully negotiated on this
927 * link then we'll use the skb's priority to map it to a TX Queue.
928 * The skb's priority is determined via the VLAN Tag Priority Code
929 * Point field.
930 */
Ganesh Goudar85eacf32017-05-16 21:17:42 +0530931 if (cxgb4_dcb_enabled(dev) && !is_kdump_kernel()) {
Anish Bhatt688848b2014-06-19 21:37:13 -0700932 u16 vlan_tci;
933 int err;
934
935 err = vlan_get_tag(skb, &vlan_tci);
936 if (unlikely(err)) {
937 if (net_ratelimit())
938 netdev_warn(dev,
939 "TX Packet without VLAN Tag on DCB Link\n");
940 txq = 0;
941 } else {
942 txq = (vlan_tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
Varun Prakash84a200b2015-03-24 19:14:46 +0530943#ifdef CONFIG_CHELSIO_T4_FCOE
944 if (skb->protocol == htons(ETH_P_FCOE))
945 txq = skb->priority & 0x7;
946#endif /* CONFIG_CHELSIO_T4_FCOE */
Anish Bhatt688848b2014-06-19 21:37:13 -0700947 }
948 return txq;
949 }
950#endif /* CONFIG_CHELSIO_T4_DCB */
951
952 if (select_queue) {
953 txq = (skb_rx_queue_recorded(skb)
954 ? skb_get_rx_queue(skb)
955 : smp_processor_id());
956
957 while (unlikely(txq >= dev->real_num_tx_queues))
958 txq -= dev->real_num_tx_queues;
959
960 return txq;
961 }
962
963 return fallback(dev, skb) % dev->real_num_tx_queues;
964}
965
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000966static int closest_timer(const struct sge *s, int time)
967{
968 int i, delta, match = 0, min_delta = INT_MAX;
969
970 for (i = 0; i < ARRAY_SIZE(s->timer_val); i++) {
971 delta = time - s->timer_val[i];
972 if (delta < 0)
973 delta = -delta;
974 if (delta < min_delta) {
975 min_delta = delta;
976 match = i;
977 }
978 }
979 return match;
980}
981
982static int closest_thres(const struct sge *s, int thres)
983{
984 int i, delta, match = 0, min_delta = INT_MAX;
985
986 for (i = 0; i < ARRAY_SIZE(s->counter_val); i++) {
987 delta = thres - s->counter_val[i];
988 if (delta < 0)
989 delta = -delta;
990 if (delta < min_delta) {
991 min_delta = delta;
992 match = i;
993 }
994 }
995 return match;
996}
997
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000998/**
Hariprasad Shenai812034f2015-04-06 20:23:23 +0530999 * cxgb4_set_rspq_intr_params - set a queue's interrupt holdoff parameters
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001000 * @q: the Rx queue
1001 * @us: the hold-off time in us, or 0 to disable timer
1002 * @cnt: the hold-off packet count, or 0 to disable counter
1003 *
1004 * Sets an Rx queue's interrupt hold-off time and packet count. At least
1005 * one of the two needs to be enabled for the queue to generate interrupts.
1006 */
Hariprasad Shenai812034f2015-04-06 20:23:23 +05301007int cxgb4_set_rspq_intr_params(struct sge_rspq *q,
1008 unsigned int us, unsigned int cnt)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001009{
Hariprasad Shenaic887ad02014-06-06 21:40:45 +05301010 struct adapter *adap = q->adap;
1011
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001012 if ((us | cnt) == 0)
1013 cnt = 1;
1014
1015 if (cnt) {
1016 int err;
1017 u32 v, new_idx;
1018
1019 new_idx = closest_thres(&adap->sge, cnt);
1020 if (q->desc && q->pktcnt_idx != new_idx) {
1021 /* the queue has already been created, update it */
Hariprasad Shenai51678652014-11-21 12:52:02 +05301022 v = FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DMAQ) |
1023 FW_PARAMS_PARAM_X_V(
1024 FW_PARAMS_PARAM_DMAQ_IQ_INTCNTTHRESH) |
1025 FW_PARAMS_PARAM_YZ_V(q->cntxt_id);
Hariprasad Shenaib2612722015-05-27 22:30:24 +05301026 err = t4_set_params(adap, adap->mbox, adap->pf, 0, 1,
1027 &v, &new_idx);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001028 if (err)
1029 return err;
1030 }
1031 q->pktcnt_idx = new_idx;
1032 }
1033
1034 us = us == 0 ? 6 : closest_timer(&adap->sge, us);
Hariprasad Shenai1ecc7b72015-05-12 04:43:43 +05301035 q->intr_params = QINTR_TIMER_IDX_V(us) | QINTR_CNT_EN_V(cnt > 0);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001036 return 0;
1037}
1038
Michał Mirosławc8f44af2011-11-15 15:29:55 +00001039static int cxgb_set_features(struct net_device *dev, netdev_features_t features)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001040{
Michał Mirosław2ed28ba2011-04-16 13:05:08 +00001041 const struct port_info *pi = netdev_priv(dev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00001042 netdev_features_t changed = dev->features ^ features;
Dimitris Michailidis19ecae22010-10-21 11:29:56 +00001043 int err;
Dimitris Michailidis19ecae22010-10-21 11:29:56 +00001044
Patrick McHardyf6469682013-04-19 02:04:27 +00001045 if (!(changed & NETIF_F_HW_VLAN_CTAG_RX))
Michał Mirosław2ed28ba2011-04-16 13:05:08 +00001046 return 0;
Dimitris Michailidis19ecae22010-10-21 11:29:56 +00001047
Hariprasad Shenaib2612722015-05-27 22:30:24 +05301048 err = t4_set_rxmode(pi->adapter, pi->adapter->pf, pi->viid, -1,
Michał Mirosław2ed28ba2011-04-16 13:05:08 +00001049 -1, -1, -1,
Patrick McHardyf6469682013-04-19 02:04:27 +00001050 !!(features & NETIF_F_HW_VLAN_CTAG_RX), true);
Michał Mirosław2ed28ba2011-04-16 13:05:08 +00001051 if (unlikely(err))
Patrick McHardyf6469682013-04-19 02:04:27 +00001052 dev->features = features ^ NETIF_F_HW_VLAN_CTAG_RX;
Dimitris Michailidis19ecae22010-10-21 11:29:56 +00001053 return err;
Dimitris Michailidis87b6cf52010-04-27 16:22:42 -07001054}
1055
Bill Pemberton91744942012-12-03 09:23:02 -05001056static int setup_debugfs(struct adapter *adap)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001057{
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001058 if (IS_ERR_OR_NULL(adap->debugfs_root))
1059 return -1;
1060
Hariprasad Shenaifd88b312014-11-07 09:35:23 +05301061#ifdef CONFIG_DEBUG_FS
1062 t4_setup_debugfs(adap);
1063#endif
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001064 return 0;
1065}
1066
1067/*
1068 * upper-layer driver support
1069 */
1070
1071/*
1072 * Allocate an active-open TID and set it to the supplied value.
1073 */
1074int cxgb4_alloc_atid(struct tid_info *t, void *data)
1075{
1076 int atid = -1;
1077
1078 spin_lock_bh(&t->atid_lock);
1079 if (t->afree) {
1080 union aopen_entry *p = t->afree;
1081
Vipul Pandyaf2b7e782012-12-10 09:30:52 +00001082 atid = (p - t->atid_tab) + t->atid_base;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001083 t->afree = p->next;
1084 p->data = data;
1085 t->atids_in_use++;
1086 }
1087 spin_unlock_bh(&t->atid_lock);
1088 return atid;
1089}
1090EXPORT_SYMBOL(cxgb4_alloc_atid);
1091
1092/*
1093 * Release an active-open TID.
1094 */
1095void cxgb4_free_atid(struct tid_info *t, unsigned int atid)
1096{
Vipul Pandyaf2b7e782012-12-10 09:30:52 +00001097 union aopen_entry *p = &t->atid_tab[atid - t->atid_base];
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001098
1099 spin_lock_bh(&t->atid_lock);
1100 p->next = t->afree;
1101 t->afree = p;
1102 t->atids_in_use--;
1103 spin_unlock_bh(&t->atid_lock);
1104}
1105EXPORT_SYMBOL(cxgb4_free_atid);
1106
1107/*
1108 * Allocate a server TID and set it to the supplied value.
1109 */
1110int cxgb4_alloc_stid(struct tid_info *t, int family, void *data)
1111{
1112 int stid;
1113
1114 spin_lock_bh(&t->stid_lock);
1115 if (family == PF_INET) {
1116 stid = find_first_zero_bit(t->stid_bmap, t->nstids);
1117 if (stid < t->nstids)
1118 __set_bit(stid, t->stid_bmap);
1119 else
1120 stid = -1;
1121 } else {
Hariprasad Shenaia99c6832015-12-24 16:15:17 +05301122 stid = bitmap_find_free_region(t->stid_bmap, t->nstids, 1);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001123 if (stid < 0)
1124 stid = -1;
1125 }
1126 if (stid >= 0) {
1127 t->stid_tab[stid].data = data;
1128 stid += t->stid_base;
Kumar Sanghvi15f63b72013-12-18 16:38:22 +05301129 /* IPv6 requires max of 520 bits or 16 cells in TCAM
1130 * This is equivalent to 4 TIDs. With CLIP enabled it
1131 * needs 2 TIDs.
1132 */
Ganesh Goudar1dec4ce2017-06-07 15:04:51 +05301133 if (family == PF_INET6) {
Hariprasad Shenaia99c6832015-12-24 16:15:17 +05301134 t->stids_in_use += 2;
Ganesh Goudar1dec4ce2017-06-07 15:04:51 +05301135 t->v6_stids_in_use += 2;
1136 } else {
1137 t->stids_in_use++;
1138 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001139 }
1140 spin_unlock_bh(&t->stid_lock);
1141 return stid;
1142}
1143EXPORT_SYMBOL(cxgb4_alloc_stid);
1144
Vipul Pandyadca4fae2012-12-10 09:30:53 +00001145/* Allocate a server filter TID and set it to the supplied value.
1146 */
1147int cxgb4_alloc_sftid(struct tid_info *t, int family, void *data)
1148{
1149 int stid;
1150
1151 spin_lock_bh(&t->stid_lock);
1152 if (family == PF_INET) {
1153 stid = find_next_zero_bit(t->stid_bmap,
1154 t->nstids + t->nsftids, t->nstids);
1155 if (stid < (t->nstids + t->nsftids))
1156 __set_bit(stid, t->stid_bmap);
1157 else
1158 stid = -1;
1159 } else {
1160 stid = -1;
1161 }
1162 if (stid >= 0) {
1163 t->stid_tab[stid].data = data;
Kumar Sanghvi470c60c2013-12-18 16:38:21 +05301164 stid -= t->nstids;
1165 stid += t->sftid_base;
Hariprasad Shenai2248b292015-08-12 16:55:06 +05301166 t->sftids_in_use++;
Vipul Pandyadca4fae2012-12-10 09:30:53 +00001167 }
1168 spin_unlock_bh(&t->stid_lock);
1169 return stid;
1170}
1171EXPORT_SYMBOL(cxgb4_alloc_sftid);
1172
1173/* Release a server TID.
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001174 */
1175void cxgb4_free_stid(struct tid_info *t, unsigned int stid, int family)
1176{
Kumar Sanghvi470c60c2013-12-18 16:38:21 +05301177 /* Is it a server filter TID? */
1178 if (t->nsftids && (stid >= t->sftid_base)) {
1179 stid -= t->sftid_base;
1180 stid += t->nstids;
1181 } else {
1182 stid -= t->stid_base;
1183 }
1184
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001185 spin_lock_bh(&t->stid_lock);
1186 if (family == PF_INET)
1187 __clear_bit(stid, t->stid_bmap);
1188 else
Hariprasad Shenaia99c6832015-12-24 16:15:17 +05301189 bitmap_release_region(t->stid_bmap, stid, 1);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001190 t->stid_tab[stid].data = NULL;
Hariprasad Shenai2248b292015-08-12 16:55:06 +05301191 if (stid < t->nstids) {
Ganesh Goudar1dec4ce2017-06-07 15:04:51 +05301192 if (family == PF_INET6) {
Hariprasad Shenaia99c6832015-12-24 16:15:17 +05301193 t->stids_in_use -= 2;
Ganesh Goudar1dec4ce2017-06-07 15:04:51 +05301194 t->v6_stids_in_use -= 2;
1195 } else {
1196 t->stids_in_use--;
1197 }
Hariprasad Shenai2248b292015-08-12 16:55:06 +05301198 } else {
1199 t->sftids_in_use--;
1200 }
Ganesh Goudar1dec4ce2017-06-07 15:04:51 +05301201
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001202 spin_unlock_bh(&t->stid_lock);
1203}
1204EXPORT_SYMBOL(cxgb4_free_stid);
1205
1206/*
1207 * Populate a TID_RELEASE WR. Caller must properly size the skb.
1208 */
1209static void mk_tid_release(struct sk_buff *skb, unsigned int chan,
1210 unsigned int tid)
1211{
1212 struct cpl_tid_release *req;
1213
1214 set_wr_txq(skb, CPL_PRIORITY_SETUP, chan);
Johannes Berg4df864c2017-06-16 14:29:21 +02001215 req = __skb_put(skb, sizeof(*req));
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001216 INIT_TP_WR(req, tid);
1217 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_TID_RELEASE, tid));
1218}
1219
1220/*
1221 * Queue a TID release request and if necessary schedule a work queue to
1222 * process it.
1223 */
stephen hemminger31b9c192010-10-18 05:39:18 +00001224static void cxgb4_queue_tid_release(struct tid_info *t, unsigned int chan,
1225 unsigned int tid)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001226{
1227 void **p = &t->tid_tab[tid];
1228 struct adapter *adap = container_of(t, struct adapter, tids);
1229
1230 spin_lock_bh(&adap->tid_release_lock);
1231 *p = adap->tid_release_head;
1232 /* Low 2 bits encode the Tx channel number */
1233 adap->tid_release_head = (void **)((uintptr_t)p | chan);
1234 if (!adap->tid_release_task_busy) {
1235 adap->tid_release_task_busy = true;
Anish Bhatt29aaee62014-08-20 13:44:06 -07001236 queue_work(adap->workq, &adap->tid_release_task);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001237 }
1238 spin_unlock_bh(&adap->tid_release_lock);
1239}
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001240
1241/*
1242 * Process the list of pending TID release requests.
1243 */
1244static void process_tid_release_list(struct work_struct *work)
1245{
1246 struct sk_buff *skb;
1247 struct adapter *adap;
1248
1249 adap = container_of(work, struct adapter, tid_release_task);
1250
1251 spin_lock_bh(&adap->tid_release_lock);
1252 while (adap->tid_release_head) {
1253 void **p = adap->tid_release_head;
1254 unsigned int chan = (uintptr_t)p & 3;
1255 p = (void *)p - chan;
1256
1257 adap->tid_release_head = *p;
1258 *p = NULL;
1259 spin_unlock_bh(&adap->tid_release_lock);
1260
1261 while (!(skb = alloc_skb(sizeof(struct cpl_tid_release),
1262 GFP_KERNEL)))
1263 schedule_timeout_uninterruptible(1);
1264
1265 mk_tid_release(skb, chan, p - adap->tids.tid_tab);
1266 t4_ofld_send(adap, skb);
1267 spin_lock_bh(&adap->tid_release_lock);
1268 }
1269 adap->tid_release_task_busy = false;
1270 spin_unlock_bh(&adap->tid_release_lock);
1271}
1272
1273/*
1274 * Release a TID and inform HW. If we are unable to allocate the release
1275 * message we defer to a work queue.
1276 */
Ganesh Goudar1dec4ce2017-06-07 15:04:51 +05301277void cxgb4_remove_tid(struct tid_info *t, unsigned int chan, unsigned int tid,
1278 unsigned short family)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001279{
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001280 struct sk_buff *skb;
1281 struct adapter *adap = container_of(t, struct adapter, tids);
1282
Hariprasad Shenai9a1bb9f2015-08-12 16:55:05 +05301283 WARN_ON(tid >= t->ntids);
1284
1285 if (t->tid_tab[tid]) {
1286 t->tid_tab[tid] = NULL;
Ganesh Goudar1dec4ce2017-06-07 15:04:51 +05301287 atomic_dec(&t->conns_in_use);
1288 if (t->hash_base && (tid >= t->hash_base)) {
1289 if (family == AF_INET6)
1290 atomic_sub(2, &t->hash_tids_in_use);
1291 else
1292 atomic_dec(&t->hash_tids_in_use);
1293 } else {
1294 if (family == AF_INET6)
1295 atomic_sub(2, &t->tids_in_use);
1296 else
1297 atomic_dec(&t->tids_in_use);
1298 }
Hariprasad Shenai9a1bb9f2015-08-12 16:55:05 +05301299 }
1300
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001301 skb = alloc_skb(sizeof(struct cpl_tid_release), GFP_ATOMIC);
1302 if (likely(skb)) {
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001303 mk_tid_release(skb, chan, tid);
1304 t4_ofld_send(adap, skb);
1305 } else
1306 cxgb4_queue_tid_release(t, chan, tid);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001307}
1308EXPORT_SYMBOL(cxgb4_remove_tid);
1309
1310/*
1311 * Allocate and initialize the TID tables. Returns 0 on success.
1312 */
1313static int tid_init(struct tid_info *t)
1314{
Kumar Sanghvib6f8eae2013-12-18 16:38:19 +05301315 struct adapter *adap = container_of(t, struct adapter, tids);
Rahul Lakkireddy578b46b2016-09-20 17:13:07 +05301316 unsigned int max_ftids = t->nftids + t->nsftids;
1317 unsigned int natids = t->natids;
1318 unsigned int stid_bmap_size;
1319 unsigned int ftid_bmap_size;
1320 size_t size;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001321
Vipul Pandyadca4fae2012-12-10 09:30:53 +00001322 stid_bmap_size = BITS_TO_LONGS(t->nstids + t->nsftids);
Rahul Lakkireddy578b46b2016-09-20 17:13:07 +05301323 ftid_bmap_size = BITS_TO_LONGS(t->nftids);
Vipul Pandyaf2b7e782012-12-10 09:30:52 +00001324 size = t->ntids * sizeof(*t->tid_tab) +
1325 natids * sizeof(*t->atid_tab) +
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001326 t->nstids * sizeof(*t->stid_tab) +
Vipul Pandyadca4fae2012-12-10 09:30:53 +00001327 t->nsftids * sizeof(*t->stid_tab) +
Vipul Pandyaf2b7e782012-12-10 09:30:52 +00001328 stid_bmap_size * sizeof(long) +
Rahul Lakkireddy578b46b2016-09-20 17:13:07 +05301329 max_ftids * sizeof(*t->ftid_tab) +
1330 ftid_bmap_size * sizeof(long);
Vipul Pandyaf2b7e782012-12-10 09:30:52 +00001331
Michal Hocko752ade62017-05-08 15:57:27 -07001332 t->tid_tab = kvzalloc(size, GFP_KERNEL);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001333 if (!t->tid_tab)
1334 return -ENOMEM;
1335
1336 t->atid_tab = (union aopen_entry *)&t->tid_tab[t->ntids];
1337 t->stid_tab = (struct serv_entry *)&t->atid_tab[natids];
Vipul Pandyadca4fae2012-12-10 09:30:53 +00001338 t->stid_bmap = (unsigned long *)&t->stid_tab[t->nstids + t->nsftids];
Vipul Pandyaf2b7e782012-12-10 09:30:52 +00001339 t->ftid_tab = (struct filter_entry *)&t->stid_bmap[stid_bmap_size];
Rahul Lakkireddy578b46b2016-09-20 17:13:07 +05301340 t->ftid_bmap = (unsigned long *)&t->ftid_tab[max_ftids];
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001341 spin_lock_init(&t->stid_lock);
1342 spin_lock_init(&t->atid_lock);
Rahul Lakkireddy578b46b2016-09-20 17:13:07 +05301343 spin_lock_init(&t->ftid_lock);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001344
1345 t->stids_in_use = 0;
Ganesh Goudar1dec4ce2017-06-07 15:04:51 +05301346 t->v6_stids_in_use = 0;
Hariprasad Shenai2248b292015-08-12 16:55:06 +05301347 t->sftids_in_use = 0;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001348 t->afree = NULL;
1349 t->atids_in_use = 0;
1350 atomic_set(&t->tids_in_use, 0);
Ganesh Goudar1dec4ce2017-06-07 15:04:51 +05301351 atomic_set(&t->conns_in_use, 0);
Hariprasad Shenai9a1bb9f2015-08-12 16:55:05 +05301352 atomic_set(&t->hash_tids_in_use, 0);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001353
1354 /* Setup the free list for atid_tab and clear the stid bitmap. */
1355 if (natids) {
1356 while (--natids)
1357 t->atid_tab[natids - 1].next = &t->atid_tab[natids];
1358 t->afree = t->atid_tab;
1359 }
Kumar Sanghvib6f8eae2013-12-18 16:38:19 +05301360
Rahul Lakkireddy578b46b2016-09-20 17:13:07 +05301361 if (is_offload(adap)) {
1362 bitmap_zero(t->stid_bmap, t->nstids + t->nsftids);
1363 /* Reserve stid 0 for T4/T5 adapters */
1364 if (!t->stid_base &&
1365 CHELSIO_CHIP_VERSION(adap->params.chip) <= CHELSIO_T5)
1366 __set_bit(0, t->stid_bmap);
1367 }
1368
1369 bitmap_zero(t->ftid_bmap, t->nftids);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001370 return 0;
1371}
1372
1373/**
1374 * cxgb4_create_server - create an IP server
1375 * @dev: the device
1376 * @stid: the server TID
1377 * @sip: local IP address to bind server to
1378 * @sport: the server's TCP port
1379 * @queue: queue to direct messages from this server to
1380 *
1381 * Create an IP server for the given port and address.
1382 * Returns <0 on error and one of the %NET_XMIT_* values on success.
1383 */
1384int cxgb4_create_server(const struct net_device *dev, unsigned int stid,
Vipul Pandya793dad92012-12-10 09:30:56 +00001385 __be32 sip, __be16 sport, __be16 vlan,
1386 unsigned int queue)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001387{
1388 unsigned int chan;
1389 struct sk_buff *skb;
1390 struct adapter *adap;
1391 struct cpl_pass_open_req *req;
Vipul Pandya80f40c12013-07-04 16:10:45 +05301392 int ret;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001393
1394 skb = alloc_skb(sizeof(*req), GFP_KERNEL);
1395 if (!skb)
1396 return -ENOMEM;
1397
1398 adap = netdev2adap(dev);
Johannes Berg4df864c2017-06-16 14:29:21 +02001399 req = __skb_put(skb, sizeof(*req));
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001400 INIT_TP_WR(req, 0);
1401 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_OPEN_REQ, stid));
1402 req->local_port = sport;
1403 req->peer_port = htons(0);
1404 req->local_ip = sip;
1405 req->peer_ip = htonl(0);
Dimitris Michailidise46dab42010-08-23 17:20:58 +00001406 chan = rxq_to_chan(&adap->sge, queue);
Anish Bhattd7990b02014-11-12 17:15:57 -08001407 req->opt0 = cpu_to_be64(TX_CHAN_V(chan));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001408 req->opt1 = cpu_to_be64(CONN_POLICY_V(CPL_CONN_POLICY_ASK) |
1409 SYN_RSS_ENABLE_F | SYN_RSS_QUEUE_V(queue));
Vipul Pandya80f40c12013-07-04 16:10:45 +05301410 ret = t4_mgmt_tx(adap, skb);
1411 return net_xmit_eval(ret);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001412}
1413EXPORT_SYMBOL(cxgb4_create_server);
1414
Vipul Pandya80f40c12013-07-04 16:10:45 +05301415/* cxgb4_create_server6 - create an IPv6 server
1416 * @dev: the device
1417 * @stid: the server TID
1418 * @sip: local IPv6 address to bind server to
1419 * @sport: the server's TCP port
1420 * @queue: queue to direct messages from this server to
1421 *
1422 * Create an IPv6 server for the given port and address.
1423 * Returns <0 on error and one of the %NET_XMIT_* values on success.
1424 */
1425int cxgb4_create_server6(const struct net_device *dev, unsigned int stid,
1426 const struct in6_addr *sip, __be16 sport,
1427 unsigned int queue)
1428{
1429 unsigned int chan;
1430 struct sk_buff *skb;
1431 struct adapter *adap;
1432 struct cpl_pass_open_req6 *req;
1433 int ret;
1434
1435 skb = alloc_skb(sizeof(*req), GFP_KERNEL);
1436 if (!skb)
1437 return -ENOMEM;
1438
1439 adap = netdev2adap(dev);
Johannes Berg4df864c2017-06-16 14:29:21 +02001440 req = __skb_put(skb, sizeof(*req));
Vipul Pandya80f40c12013-07-04 16:10:45 +05301441 INIT_TP_WR(req, 0);
1442 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_OPEN_REQ6, stid));
1443 req->local_port = sport;
1444 req->peer_port = htons(0);
1445 req->local_ip_hi = *(__be64 *)(sip->s6_addr);
1446 req->local_ip_lo = *(__be64 *)(sip->s6_addr + 8);
1447 req->peer_ip_hi = cpu_to_be64(0);
1448 req->peer_ip_lo = cpu_to_be64(0);
1449 chan = rxq_to_chan(&adap->sge, queue);
Anish Bhattd7990b02014-11-12 17:15:57 -08001450 req->opt0 = cpu_to_be64(TX_CHAN_V(chan));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001451 req->opt1 = cpu_to_be64(CONN_POLICY_V(CPL_CONN_POLICY_ASK) |
1452 SYN_RSS_ENABLE_F | SYN_RSS_QUEUE_V(queue));
Vipul Pandya80f40c12013-07-04 16:10:45 +05301453 ret = t4_mgmt_tx(adap, skb);
1454 return net_xmit_eval(ret);
1455}
1456EXPORT_SYMBOL(cxgb4_create_server6);
1457
1458int cxgb4_remove_server(const struct net_device *dev, unsigned int stid,
1459 unsigned int queue, bool ipv6)
1460{
1461 struct sk_buff *skb;
1462 struct adapter *adap;
1463 struct cpl_close_listsvr_req *req;
1464 int ret;
1465
1466 adap = netdev2adap(dev);
1467
1468 skb = alloc_skb(sizeof(*req), GFP_KERNEL);
1469 if (!skb)
1470 return -ENOMEM;
1471
Johannes Berg4df864c2017-06-16 14:29:21 +02001472 req = __skb_put(skb, sizeof(*req));
Vipul Pandya80f40c12013-07-04 16:10:45 +05301473 INIT_TP_WR(req, 0);
1474 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_CLOSE_LISTSRV_REQ, stid));
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08001475 req->reply_ctrl = htons(NO_REPLY_V(0) | (ipv6 ? LISTSVR_IPV6_V(1) :
1476 LISTSVR_IPV6_V(0)) | QUEUENO_V(queue));
Vipul Pandya80f40c12013-07-04 16:10:45 +05301477 ret = t4_mgmt_tx(adap, skb);
1478 return net_xmit_eval(ret);
1479}
1480EXPORT_SYMBOL(cxgb4_remove_server);
1481
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001482/**
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001483 * cxgb4_best_mtu - find the entry in the MTU table closest to an MTU
1484 * @mtus: the HW MTU table
1485 * @mtu: the target MTU
1486 * @idx: index of selected entry in the MTU table
1487 *
1488 * Returns the index and the value in the HW MTU table that is closest to
1489 * but does not exceed @mtu, unless @mtu is smaller than any value in the
1490 * table, in which case that smallest available value is selected.
1491 */
1492unsigned int cxgb4_best_mtu(const unsigned short *mtus, unsigned short mtu,
1493 unsigned int *idx)
1494{
1495 unsigned int i = 0;
1496
1497 while (i < NMTUS - 1 && mtus[i + 1] <= mtu)
1498 ++i;
1499 if (idx)
1500 *idx = i;
1501 return mtus[i];
1502}
1503EXPORT_SYMBOL(cxgb4_best_mtu);
1504
1505/**
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05301506 * cxgb4_best_aligned_mtu - find best MTU, [hopefully] data size aligned
1507 * @mtus: the HW MTU table
1508 * @header_size: Header Size
1509 * @data_size_max: maximum Data Segment Size
1510 * @data_size_align: desired Data Segment Size Alignment (2^N)
1511 * @mtu_idxp: HW MTU Table Index return value pointer (possibly NULL)
1512 *
1513 * Similar to cxgb4_best_mtu() but instead of searching the Hardware
1514 * MTU Table based solely on a Maximum MTU parameter, we break that
1515 * parameter up into a Header Size and Maximum Data Segment Size, and
1516 * provide a desired Data Segment Size Alignment. If we find an MTU in
1517 * the Hardware MTU Table which will result in a Data Segment Size with
1518 * the requested alignment _and_ that MTU isn't "too far" from the
1519 * closest MTU, then we'll return that rather than the closest MTU.
1520 */
1521unsigned int cxgb4_best_aligned_mtu(const unsigned short *mtus,
1522 unsigned short header_size,
1523 unsigned short data_size_max,
1524 unsigned short data_size_align,
1525 unsigned int *mtu_idxp)
1526{
1527 unsigned short max_mtu = header_size + data_size_max;
1528 unsigned short data_size_align_mask = data_size_align - 1;
1529 int mtu_idx, aligned_mtu_idx;
1530
1531 /* Scan the MTU Table till we find an MTU which is larger than our
1532 * Maximum MTU or we reach the end of the table. Along the way,
1533 * record the last MTU found, if any, which will result in a Data
1534 * Segment Length matching the requested alignment.
1535 */
1536 for (mtu_idx = 0, aligned_mtu_idx = -1; mtu_idx < NMTUS; mtu_idx++) {
1537 unsigned short data_size = mtus[mtu_idx] - header_size;
1538
1539 /* If this MTU minus the Header Size would result in a
1540 * Data Segment Size of the desired alignment, remember it.
1541 */
1542 if ((data_size & data_size_align_mask) == 0)
1543 aligned_mtu_idx = mtu_idx;
1544
1545 /* If we're not at the end of the Hardware MTU Table and the
1546 * next element is larger than our Maximum MTU, drop out of
1547 * the loop.
1548 */
1549 if (mtu_idx+1 < NMTUS && mtus[mtu_idx+1] > max_mtu)
1550 break;
1551 }
1552
1553 /* If we fell out of the loop because we ran to the end of the table,
1554 * then we just have to use the last [largest] entry.
1555 */
1556 if (mtu_idx == NMTUS)
1557 mtu_idx--;
1558
1559 /* If we found an MTU which resulted in the requested Data Segment
1560 * Length alignment and that's "not far" from the largest MTU which is
1561 * less than or equal to the maximum MTU, then use that.
1562 */
1563 if (aligned_mtu_idx >= 0 &&
1564 mtu_idx - aligned_mtu_idx <= 1)
1565 mtu_idx = aligned_mtu_idx;
1566
1567 /* If the caller has passed in an MTU Index pointer, pass the
1568 * MTU Index back. Return the MTU value.
1569 */
1570 if (mtu_idxp)
1571 *mtu_idxp = mtu_idx;
1572 return mtus[mtu_idx];
1573}
1574EXPORT_SYMBOL(cxgb4_best_aligned_mtu);
1575
1576/**
Hariprasad S27999802015-09-23 17:19:26 +05301577 * cxgb4_tp_smt_idx - Get the Source Mac Table index for this VI
1578 * @chip: chip type
1579 * @viid: VI id of the given port
1580 *
1581 * Return the SMT index for this VI.
1582 */
1583unsigned int cxgb4_tp_smt_idx(enum chip_type chip, unsigned int viid)
1584{
1585 /* In T4/T5, SMT contains 256 SMAC entries organized in
1586 * 128 rows of 2 entries each.
1587 * In T6, SMT contains 256 SMAC entries in 256 rows.
1588 * TODO: The below code needs to be updated when we add support
1589 * for 256 VFs.
1590 */
1591 if (CHELSIO_CHIP_VERSION(chip) <= CHELSIO_T5)
1592 return ((viid & 0x7f) << 1);
1593 else
1594 return (viid & 0x7f);
1595}
1596EXPORT_SYMBOL(cxgb4_tp_smt_idx);
1597
1598/**
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001599 * cxgb4_port_chan - get the HW channel of a port
1600 * @dev: the net device for the port
1601 *
1602 * Return the HW Tx channel of the given port.
1603 */
1604unsigned int cxgb4_port_chan(const struct net_device *dev)
1605{
1606 return netdev2pinfo(dev)->tx_chan;
1607}
1608EXPORT_SYMBOL(cxgb4_port_chan);
1609
Vipul Pandya881806b2012-05-18 15:29:24 +05301610unsigned int cxgb4_dbfifo_count(const struct net_device *dev, int lpfifo)
1611{
1612 struct adapter *adap = netdev2adap(dev);
Santosh Rastapur2cc301d2013-03-14 05:08:52 +00001613 u32 v1, v2, lp_count, hp_count;
Vipul Pandya881806b2012-05-18 15:29:24 +05301614
Hariprasad Shenaif061de422015-01-05 16:30:44 +05301615 v1 = t4_read_reg(adap, SGE_DBFIFO_STATUS_A);
1616 v2 = t4_read_reg(adap, SGE_DBFIFO_STATUS2_A);
Hariprasad Shenaid14807d2013-12-03 17:05:56 +05301617 if (is_t4(adap->params.chip)) {
Hariprasad Shenaif061de422015-01-05 16:30:44 +05301618 lp_count = LP_COUNT_G(v1);
1619 hp_count = HP_COUNT_G(v1);
Santosh Rastapur2cc301d2013-03-14 05:08:52 +00001620 } else {
Hariprasad Shenaif061de422015-01-05 16:30:44 +05301621 lp_count = LP_COUNT_T5_G(v1);
1622 hp_count = HP_COUNT_T5_G(v2);
Santosh Rastapur2cc301d2013-03-14 05:08:52 +00001623 }
1624 return lpfifo ? lp_count : hp_count;
Vipul Pandya881806b2012-05-18 15:29:24 +05301625}
1626EXPORT_SYMBOL(cxgb4_dbfifo_count);
1627
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001628/**
1629 * cxgb4_port_viid - get the VI id of a port
1630 * @dev: the net device for the port
1631 *
1632 * Return the VI id of the given port.
1633 */
1634unsigned int cxgb4_port_viid(const struct net_device *dev)
1635{
1636 return netdev2pinfo(dev)->viid;
1637}
1638EXPORT_SYMBOL(cxgb4_port_viid);
1639
1640/**
1641 * cxgb4_port_idx - get the index of a port
1642 * @dev: the net device for the port
1643 *
1644 * Return the index of the given port.
1645 */
1646unsigned int cxgb4_port_idx(const struct net_device *dev)
1647{
1648 return netdev2pinfo(dev)->port_id;
1649}
1650EXPORT_SYMBOL(cxgb4_port_idx);
1651
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001652void cxgb4_get_tcp_stats(struct pci_dev *pdev, struct tp_tcp_stats *v4,
1653 struct tp_tcp_stats *v6)
1654{
1655 struct adapter *adap = pci_get_drvdata(pdev);
1656
1657 spin_lock(&adap->stats_lock);
Rahul Lakkireddy5ccf9d02017-10-13 18:48:17 +05301658 t4_tp_get_tcp_stats(adap, v4, v6, false);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001659 spin_unlock(&adap->stats_lock);
1660}
1661EXPORT_SYMBOL(cxgb4_get_tcp_stats);
1662
1663void cxgb4_iscsi_init(struct net_device *dev, unsigned int tag_mask,
1664 const unsigned int *pgsz_order)
1665{
1666 struct adapter *adap = netdev2adap(dev);
1667
Hariprasad Shenai0d804332015-01-05 16:30:47 +05301668 t4_write_reg(adap, ULP_RX_ISCSI_TAGMASK_A, tag_mask);
1669 t4_write_reg(adap, ULP_RX_ISCSI_PSZ_A, HPZ0_V(pgsz_order[0]) |
1670 HPZ1_V(pgsz_order[1]) | HPZ2_V(pgsz_order[2]) |
1671 HPZ3_V(pgsz_order[3]));
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001672}
1673EXPORT_SYMBOL(cxgb4_iscsi_init);
1674
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301675int cxgb4_flush_eq_cache(struct net_device *dev)
1676{
1677 struct adapter *adap = netdev2adap(dev);
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301678
Rahul Lakkireddy736c3b92017-12-08 09:48:40 +05301679 return t4_sge_ctxt_flush(adap, adap->mbox, CTXT_EGRESS);
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301680}
1681EXPORT_SYMBOL(cxgb4_flush_eq_cache);
1682
1683static int read_eq_indices(struct adapter *adap, u16 qid, u16 *pidx, u16 *cidx)
1684{
Hariprasad Shenaif061de422015-01-05 16:30:44 +05301685 u32 addr = t4_read_reg(adap, SGE_DBQ_CTXT_BADDR_A) + 24 * qid + 8;
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301686 __be64 indices;
1687 int ret;
1688
Hariprasad Shenaifc5ab022014-06-27 19:23:49 +05301689 spin_lock(&adap->win0_lock);
1690 ret = t4_memory_rw(adap, 0, MEM_EDC0, addr,
1691 sizeof(indices), (__be32 *)&indices,
1692 T4_MEMORY_READ);
1693 spin_unlock(&adap->win0_lock);
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301694 if (!ret) {
Vipul Pandya404d9e32012-10-08 02:59:43 +00001695 *cidx = (be64_to_cpu(indices) >> 25) & 0xffff;
1696 *pidx = (be64_to_cpu(indices) >> 9) & 0xffff;
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301697 }
1698 return ret;
1699}
1700
1701int cxgb4_sync_txq_pidx(struct net_device *dev, u16 qid, u16 pidx,
1702 u16 size)
1703{
1704 struct adapter *adap = netdev2adap(dev);
1705 u16 hw_pidx, hw_cidx;
1706 int ret;
1707
1708 ret = read_eq_indices(adap, qid, &hw_pidx, &hw_cidx);
1709 if (ret)
1710 goto out;
1711
1712 if (pidx != hw_pidx) {
1713 u16 delta;
Hariprasad Shenaif612b812015-01-05 16:30:43 +05301714 u32 val;
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301715
1716 if (pidx >= hw_pidx)
1717 delta = pidx - hw_pidx;
1718 else
1719 delta = size - hw_pidx + pidx;
Hariprasad Shenaif612b812015-01-05 16:30:43 +05301720
1721 if (is_t4(adap->params.chip))
1722 val = PIDX_V(delta);
1723 else
1724 val = PIDX_T5_V(delta);
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301725 wmb();
Hariprasad Shenaif612b812015-01-05 16:30:43 +05301726 t4_write_reg(adap, MYPF_REG(SGE_PF_KDOORBELL_A),
1727 QID_V(qid) | val);
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301728 }
1729out:
1730 return ret;
1731}
1732EXPORT_SYMBOL(cxgb4_sync_txq_pidx);
1733
Hariprasad Shenai031cf472014-07-14 21:34:53 +05301734int cxgb4_read_tpte(struct net_device *dev, u32 stag, __be32 *tpte)
1735{
1736 struct adapter *adap;
1737 u32 offset, memtype, memaddr;
Hariprasad Shenai6559a7e2014-11-07 09:35:24 +05301738 u32 edc0_size, edc1_size, mc0_size, mc1_size, size;
Hariprasad Shenai031cf472014-07-14 21:34:53 +05301739 u32 edc0_end, edc1_end, mc0_end, mc1_end;
1740 int ret;
1741
1742 adap = netdev2adap(dev);
1743
1744 offset = ((stag >> 8) * 32) + adap->vres.stag.start;
1745
1746 /* Figure out where the offset lands in the Memory Type/Address scheme.
1747 * This code assumes that the memory is laid out starting at offset 0
1748 * with no breaks as: EDC0, EDC1, MC0, MC1. All cards have both EDC0
1749 * and EDC1. Some cards will have neither MC0 nor MC1, most cards have
1750 * MC0, and some have both MC0 and MC1.
1751 */
Hariprasad Shenai6559a7e2014-11-07 09:35:24 +05301752 size = t4_read_reg(adap, MA_EDRAM0_BAR_A);
1753 edc0_size = EDRAM0_SIZE_G(size) << 20;
1754 size = t4_read_reg(adap, MA_EDRAM1_BAR_A);
1755 edc1_size = EDRAM1_SIZE_G(size) << 20;
1756 size = t4_read_reg(adap, MA_EXT_MEMORY0_BAR_A);
1757 mc0_size = EXT_MEM0_SIZE_G(size) << 20;
Hariprasad Shenai031cf472014-07-14 21:34:53 +05301758
1759 edc0_end = edc0_size;
1760 edc1_end = edc0_end + edc1_size;
1761 mc0_end = edc1_end + mc0_size;
1762
1763 if (offset < edc0_end) {
1764 memtype = MEM_EDC0;
1765 memaddr = offset;
1766 } else if (offset < edc1_end) {
1767 memtype = MEM_EDC1;
1768 memaddr = offset - edc0_end;
1769 } else {
1770 if (offset < mc0_end) {
1771 memtype = MEM_MC0;
1772 memaddr = offset - edc1_end;
Hariprasad Shenai3ccc6cf2015-06-02 13:59:39 +05301773 } else if (is_t5(adap->params.chip)) {
Hariprasad Shenai6559a7e2014-11-07 09:35:24 +05301774 size = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A);
1775 mc1_size = EXT_MEM1_SIZE_G(size) << 20;
Hariprasad Shenai031cf472014-07-14 21:34:53 +05301776 mc1_end = mc0_end + mc1_size;
1777 if (offset < mc1_end) {
1778 memtype = MEM_MC1;
1779 memaddr = offset - mc0_end;
1780 } else {
1781 /* offset beyond the end of any memory */
1782 goto err;
1783 }
Hariprasad Shenai3ccc6cf2015-06-02 13:59:39 +05301784 } else {
1785 /* T4/T6 only has a single memory channel */
1786 goto err;
Hariprasad Shenai031cf472014-07-14 21:34:53 +05301787 }
1788 }
1789
1790 spin_lock(&adap->win0_lock);
1791 ret = t4_memory_rw(adap, 0, memtype, memaddr, 32, tpte, T4_MEMORY_READ);
1792 spin_unlock(&adap->win0_lock);
1793 return ret;
1794
1795err:
1796 dev_err(adap->pdev_dev, "stag %#x, offset %#x out of range\n",
1797 stag, offset);
1798 return -EINVAL;
1799}
1800EXPORT_SYMBOL(cxgb4_read_tpte);
1801
Hariprasad Shenai7730b4c2014-07-14 21:34:54 +05301802u64 cxgb4_read_sge_timestamp(struct net_device *dev)
1803{
1804 u32 hi, lo;
1805 struct adapter *adap;
1806
1807 adap = netdev2adap(dev);
Hariprasad Shenaif612b812015-01-05 16:30:43 +05301808 lo = t4_read_reg(adap, SGE_TIMESTAMP_LO_A);
1809 hi = TSVAL_G(t4_read_reg(adap, SGE_TIMESTAMP_HI_A));
Hariprasad Shenai7730b4c2014-07-14 21:34:54 +05301810
1811 return ((u64)hi << 32) | (u64)lo;
1812}
1813EXPORT_SYMBOL(cxgb4_read_sge_timestamp);
1814
Hariprasad Shenaidf64e4d2014-12-03 19:32:53 +05301815int cxgb4_bar2_sge_qregs(struct net_device *dev,
1816 unsigned int qid,
1817 enum cxgb4_bar2_qtype qtype,
Hariprasad S66cf1882015-06-09 18:23:11 +05301818 int user,
Hariprasad Shenaidf64e4d2014-12-03 19:32:53 +05301819 u64 *pbar2_qoffset,
1820 unsigned int *pbar2_qid)
1821{
Hariprasad Shenaib2612722015-05-27 22:30:24 +05301822 return t4_bar2_sge_qregs(netdev2adap(dev),
Hariprasad Shenaidf64e4d2014-12-03 19:32:53 +05301823 qid,
1824 (qtype == CXGB4_BAR2_QTYPE_EGRESS
1825 ? T4_BAR2_QTYPE_EGRESS
1826 : T4_BAR2_QTYPE_INGRESS),
Hariprasad S66cf1882015-06-09 18:23:11 +05301827 user,
Hariprasad Shenaidf64e4d2014-12-03 19:32:53 +05301828 pbar2_qoffset,
1829 pbar2_qid);
1830}
1831EXPORT_SYMBOL(cxgb4_bar2_sge_qregs);
1832
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001833static struct pci_driver cxgb4_driver;
1834
1835static void check_neigh_update(struct neighbour *neigh)
1836{
1837 const struct device *parent;
1838 const struct net_device *netdev = neigh->dev;
1839
Parav Panditd0d7b102017-02-04 11:00:49 -06001840 if (is_vlan_dev(netdev))
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001841 netdev = vlan_dev_real_dev(netdev);
1842 parent = netdev->dev.parent;
1843 if (parent && parent->driver == &cxgb4_driver.driver)
1844 t4_l2t_update(dev_get_drvdata(parent), neigh);
1845}
1846
1847static int netevent_cb(struct notifier_block *nb, unsigned long event,
1848 void *data)
1849{
1850 switch (event) {
1851 case NETEVENT_NEIGH_UPDATE:
1852 check_neigh_update(data);
1853 break;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001854 case NETEVENT_REDIRECT:
1855 default:
1856 break;
1857 }
1858 return 0;
1859}
1860
1861static bool netevent_registered;
1862static struct notifier_block cxgb4_netevent_nb = {
1863 .notifier_call = netevent_cb
1864};
1865
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301866static void drain_db_fifo(struct adapter *adap, int usecs)
1867{
Santosh Rastapur2cc301d2013-03-14 05:08:52 +00001868 u32 v1, v2, lp_count, hp_count;
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301869
1870 do {
Hariprasad Shenaif061de422015-01-05 16:30:44 +05301871 v1 = t4_read_reg(adap, SGE_DBFIFO_STATUS_A);
1872 v2 = t4_read_reg(adap, SGE_DBFIFO_STATUS2_A);
Hariprasad Shenaid14807d2013-12-03 17:05:56 +05301873 if (is_t4(adap->params.chip)) {
Hariprasad Shenaif061de422015-01-05 16:30:44 +05301874 lp_count = LP_COUNT_G(v1);
1875 hp_count = HP_COUNT_G(v1);
Santosh Rastapur2cc301d2013-03-14 05:08:52 +00001876 } else {
Hariprasad Shenaif061de422015-01-05 16:30:44 +05301877 lp_count = LP_COUNT_T5_G(v1);
1878 hp_count = HP_COUNT_T5_G(v2);
Santosh Rastapur2cc301d2013-03-14 05:08:52 +00001879 }
1880
1881 if (lp_count == 0 && hp_count == 0)
1882 break;
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301883 set_current_state(TASK_UNINTERRUPTIBLE);
1884 schedule_timeout(usecs_to_jiffies(usecs));
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301885 } while (1);
1886}
1887
1888static void disable_txq_db(struct sge_txq *q)
1889{
Steve Wise05eb2382014-03-14 21:52:08 +05301890 unsigned long flags;
1891
1892 spin_lock_irqsave(&q->db_lock, flags);
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301893 q->db_disabled = 1;
Steve Wise05eb2382014-03-14 21:52:08 +05301894 spin_unlock_irqrestore(&q->db_lock, flags);
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301895}
1896
Steve Wise05eb2382014-03-14 21:52:08 +05301897static void enable_txq_db(struct adapter *adap, struct sge_txq *q)
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301898{
1899 spin_lock_irq(&q->db_lock);
Steve Wise05eb2382014-03-14 21:52:08 +05301900 if (q->db_pidx_inc) {
1901 /* Make sure that all writes to the TX descriptors
1902 * are committed before we tell HW about them.
1903 */
1904 wmb();
Hariprasad Shenaif612b812015-01-05 16:30:43 +05301905 t4_write_reg(adap, MYPF_REG(SGE_PF_KDOORBELL_A),
1906 QID_V(q->cntxt_id) | PIDX_V(q->db_pidx_inc));
Steve Wise05eb2382014-03-14 21:52:08 +05301907 q->db_pidx_inc = 0;
1908 }
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301909 q->db_disabled = 0;
1910 spin_unlock_irq(&q->db_lock);
1911}
1912
1913static void disable_dbs(struct adapter *adap)
1914{
1915 int i;
1916
1917 for_each_ethrxq(&adap->sge, i)
1918 disable_txq_db(&adap->sge.ethtxq[i].q);
Hariprasad Shenaiab677ff2016-11-18 16:37:40 +05301919 if (is_offload(adap)) {
1920 struct sge_uld_txq_info *txq_info =
1921 adap->sge.uld_txq_info[CXGB4_TX_OFLD];
1922
1923 if (txq_info) {
1924 for_each_ofldtxq(&adap->sge, i) {
1925 struct sge_uld_txq *txq = &txq_info->uldtxq[i];
1926
1927 disable_txq_db(&txq->q);
1928 }
1929 }
1930 }
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301931 for_each_port(adap, i)
1932 disable_txq_db(&adap->sge.ctrlq[i].q);
1933}
1934
1935static void enable_dbs(struct adapter *adap)
1936{
1937 int i;
1938
1939 for_each_ethrxq(&adap->sge, i)
Steve Wise05eb2382014-03-14 21:52:08 +05301940 enable_txq_db(adap, &adap->sge.ethtxq[i].q);
Hariprasad Shenaiab677ff2016-11-18 16:37:40 +05301941 if (is_offload(adap)) {
1942 struct sge_uld_txq_info *txq_info =
1943 adap->sge.uld_txq_info[CXGB4_TX_OFLD];
1944
1945 if (txq_info) {
1946 for_each_ofldtxq(&adap->sge, i) {
1947 struct sge_uld_txq *txq = &txq_info->uldtxq[i];
1948
1949 enable_txq_db(adap, &txq->q);
1950 }
1951 }
1952 }
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301953 for_each_port(adap, i)
Steve Wise05eb2382014-03-14 21:52:08 +05301954 enable_txq_db(adap, &adap->sge.ctrlq[i].q);
1955}
1956
1957static void notify_rdma_uld(struct adapter *adap, enum cxgb4_control cmd)
1958{
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05301959 enum cxgb4_uld type = CXGB4_ULD_RDMA;
1960
1961 if (adap->uld && adap->uld[type].handle)
1962 adap->uld[type].control(adap->uld[type].handle, cmd);
Steve Wise05eb2382014-03-14 21:52:08 +05301963}
1964
1965static void process_db_full(struct work_struct *work)
1966{
1967 struct adapter *adap;
1968
1969 adap = container_of(work, struct adapter, db_full_task);
1970
1971 drain_db_fifo(adap, dbfifo_drain_delay);
1972 enable_dbs(adap);
1973 notify_rdma_uld(adap, CXGB4_CONTROL_DB_EMPTY);
Hariprasad Shenai3ccc6cf2015-06-02 13:59:39 +05301974 if (CHELSIO_CHIP_VERSION(adap->params.chip) <= CHELSIO_T5)
1975 t4_set_reg_field(adap, SGE_INT_ENABLE3_A,
1976 DBFIFO_HP_INT_F | DBFIFO_LP_INT_F,
1977 DBFIFO_HP_INT_F | DBFIFO_LP_INT_F);
1978 else
1979 t4_set_reg_field(adap, SGE_INT_ENABLE3_A,
1980 DBFIFO_LP_INT_F, DBFIFO_LP_INT_F);
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301981}
1982
1983static void sync_txq_pidx(struct adapter *adap, struct sge_txq *q)
1984{
1985 u16 hw_pidx, hw_cidx;
1986 int ret;
1987
Steve Wise05eb2382014-03-14 21:52:08 +05301988 spin_lock_irq(&q->db_lock);
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301989 ret = read_eq_indices(adap, (u16)q->cntxt_id, &hw_pidx, &hw_cidx);
1990 if (ret)
1991 goto out;
1992 if (q->db_pidx != hw_pidx) {
1993 u16 delta;
Hariprasad Shenaif612b812015-01-05 16:30:43 +05301994 u32 val;
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301995
1996 if (q->db_pidx >= hw_pidx)
1997 delta = q->db_pidx - hw_pidx;
1998 else
1999 delta = q->size - hw_pidx + q->db_pidx;
Hariprasad Shenaif612b812015-01-05 16:30:43 +05302000
2001 if (is_t4(adap->params.chip))
2002 val = PIDX_V(delta);
2003 else
2004 val = PIDX_T5_V(delta);
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05302005 wmb();
Hariprasad Shenaif612b812015-01-05 16:30:43 +05302006 t4_write_reg(adap, MYPF_REG(SGE_PF_KDOORBELL_A),
2007 QID_V(q->cntxt_id) | val);
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05302008 }
2009out:
2010 q->db_disabled = 0;
Steve Wise05eb2382014-03-14 21:52:08 +05302011 q->db_pidx_inc = 0;
2012 spin_unlock_irq(&q->db_lock);
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05302013 if (ret)
2014 CH_WARN(adap, "DB drop recovery failed.\n");
2015}
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05302016
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05302017static void recover_all_queues(struct adapter *adap)
2018{
2019 int i;
2020
2021 for_each_ethrxq(&adap->sge, i)
2022 sync_txq_pidx(adap, &adap->sge.ethtxq[i].q);
Hariprasad Shenaiab677ff2016-11-18 16:37:40 +05302023 if (is_offload(adap)) {
2024 struct sge_uld_txq_info *txq_info =
2025 adap->sge.uld_txq_info[CXGB4_TX_OFLD];
2026 if (txq_info) {
2027 for_each_ofldtxq(&adap->sge, i) {
2028 struct sge_uld_txq *txq = &txq_info->uldtxq[i];
2029
2030 sync_txq_pidx(adap, &txq->q);
2031 }
2032 }
2033 }
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05302034 for_each_port(adap, i)
2035 sync_txq_pidx(adap, &adap->sge.ctrlq[i].q);
2036}
2037
Vipul Pandya881806b2012-05-18 15:29:24 +05302038static void process_db_drop(struct work_struct *work)
2039{
2040 struct adapter *adap;
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05302041
Vipul Pandya881806b2012-05-18 15:29:24 +05302042 adap = container_of(work, struct adapter, db_drop_task);
2043
Hariprasad Shenaid14807d2013-12-03 17:05:56 +05302044 if (is_t4(adap->params.chip)) {
Steve Wise05eb2382014-03-14 21:52:08 +05302045 drain_db_fifo(adap, dbfifo_drain_delay);
Santosh Rastapur2cc301d2013-03-14 05:08:52 +00002046 notify_rdma_uld(adap, CXGB4_CONTROL_DB_DROP);
Steve Wise05eb2382014-03-14 21:52:08 +05302047 drain_db_fifo(adap, dbfifo_drain_delay);
Santosh Rastapur2cc301d2013-03-14 05:08:52 +00002048 recover_all_queues(adap);
Steve Wise05eb2382014-03-14 21:52:08 +05302049 drain_db_fifo(adap, dbfifo_drain_delay);
Santosh Rastapur2cc301d2013-03-14 05:08:52 +00002050 enable_dbs(adap);
Steve Wise05eb2382014-03-14 21:52:08 +05302051 notify_rdma_uld(adap, CXGB4_CONTROL_DB_EMPTY);
Hariprasad Shenai3ccc6cf2015-06-02 13:59:39 +05302052 } else if (is_t5(adap->params.chip)) {
Santosh Rastapur2cc301d2013-03-14 05:08:52 +00002053 u32 dropped_db = t4_read_reg(adap, 0x010ac);
2054 u16 qid = (dropped_db >> 15) & 0x1ffff;
2055 u16 pidx_inc = dropped_db & 0x1fff;
Hariprasad Shenaidf64e4d2014-12-03 19:32:53 +05302056 u64 bar2_qoffset;
2057 unsigned int bar2_qid;
2058 int ret;
Santosh Rastapur2cc301d2013-03-14 05:08:52 +00002059
Hariprasad Shenaib2612722015-05-27 22:30:24 +05302060 ret = t4_bar2_sge_qregs(adap, qid, T4_BAR2_QTYPE_EGRESS,
Linus Torvaldse0456712015-06-24 16:49:49 -07002061 0, &bar2_qoffset, &bar2_qid);
Hariprasad Shenaidf64e4d2014-12-03 19:32:53 +05302062 if (ret)
2063 dev_err(adap->pdev_dev, "doorbell drop recovery: "
2064 "qid=%d, pidx_inc=%d\n", qid, pidx_inc);
2065 else
Hariprasad Shenaif612b812015-01-05 16:30:43 +05302066 writel(PIDX_T5_V(pidx_inc) | QID_V(bar2_qid),
Hariprasad Shenaidf64e4d2014-12-03 19:32:53 +05302067 adap->bar2 + bar2_qoffset + SGE_UDB_KDOORBELL);
Santosh Rastapur2cc301d2013-03-14 05:08:52 +00002068
2069 /* Re-enable BAR2 WC */
2070 t4_set_reg_field(adap, 0x10b0, 1<<15, 1<<15);
2071 }
2072
Hariprasad Shenai3ccc6cf2015-06-02 13:59:39 +05302073 if (CHELSIO_CHIP_VERSION(adap->params.chip) <= CHELSIO_T5)
2074 t4_set_reg_field(adap, SGE_DOORBELL_CONTROL_A, DROPPED_DB_F, 0);
Vipul Pandya881806b2012-05-18 15:29:24 +05302075}
2076
2077void t4_db_full(struct adapter *adap)
2078{
Hariprasad Shenaid14807d2013-12-03 17:05:56 +05302079 if (is_t4(adap->params.chip)) {
Steve Wise05eb2382014-03-14 21:52:08 +05302080 disable_dbs(adap);
2081 notify_rdma_uld(adap, CXGB4_CONTROL_DB_FULL);
Hariprasad Shenaif612b812015-01-05 16:30:43 +05302082 t4_set_reg_field(adap, SGE_INT_ENABLE3_A,
2083 DBFIFO_HP_INT_F | DBFIFO_LP_INT_F, 0);
Anish Bhatt29aaee62014-08-20 13:44:06 -07002084 queue_work(adap->workq, &adap->db_full_task);
Santosh Rastapur2cc301d2013-03-14 05:08:52 +00002085 }
Vipul Pandya881806b2012-05-18 15:29:24 +05302086}
2087
2088void t4_db_dropped(struct adapter *adap)
2089{
Steve Wise05eb2382014-03-14 21:52:08 +05302090 if (is_t4(adap->params.chip)) {
2091 disable_dbs(adap);
2092 notify_rdma_uld(adap, CXGB4_CONTROL_DB_FULL);
2093 }
Anish Bhatt29aaee62014-08-20 13:44:06 -07002094 queue_work(adap->workq, &adap->db_drop_task);
Vipul Pandya881806b2012-05-18 15:29:24 +05302095}
2096
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05302097void t4_register_netevent_notifier(void)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002098{
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002099 if (!netevent_registered) {
2100 register_netevent_notifier(&cxgb4_netevent_nb);
2101 netevent_registered = true;
2102 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002103}
2104
2105static void detach_ulds(struct adapter *adap)
2106{
2107 unsigned int i;
2108
2109 mutex_lock(&uld_mutex);
2110 list_del(&adap->list_node);
Guilherme G. Piccoli6a146f32017-07-10 10:55:46 -03002111
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002112 for (i = 0; i < CXGB4_ULD_MAX; i++)
Guilherme G. Piccoli6a146f32017-07-10 10:55:46 -03002113 if (adap->uld && adap->uld[i].handle)
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05302114 adap->uld[i].state_change(adap->uld[i].handle,
2115 CXGB4_STATE_DETACH);
Guilherme G. Piccoli6a146f32017-07-10 10:55:46 -03002116
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002117 if (netevent_registered && list_empty(&adapter_list)) {
2118 unregister_netevent_notifier(&cxgb4_netevent_nb);
2119 netevent_registered = false;
2120 }
2121 mutex_unlock(&uld_mutex);
2122}
2123
2124static void notify_ulds(struct adapter *adap, enum cxgb4_state new_state)
2125{
2126 unsigned int i;
2127
2128 mutex_lock(&uld_mutex);
2129 for (i = 0; i < CXGB4_ULD_MAX; i++)
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05302130 if (adap->uld && adap->uld[i].handle)
2131 adap->uld[i].state_change(adap->uld[i].handle,
2132 new_state);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002133 mutex_unlock(&uld_mutex);
2134}
2135
Anish Bhatt1bb60372014-10-14 20:07:22 -07002136#if IS_ENABLED(CONFIG_IPV6)
Anish Bhattb5a02f52015-01-14 15:17:34 -08002137static int cxgb4_inet6addr_handler(struct notifier_block *this,
2138 unsigned long event, void *data)
Vipul Pandya01bcca62013-07-04 16:10:46 +05302139{
Anish Bhattb5a02f52015-01-14 15:17:34 -08002140 struct inet6_ifaddr *ifa = data;
2141 struct net_device *event_dev = ifa->idev->dev;
2142 const struct device *parent = NULL;
2143#if IS_ENABLED(CONFIG_BONDING)
Vipul Pandya01bcca62013-07-04 16:10:46 +05302144 struct adapter *adap;
Anish Bhattb5a02f52015-01-14 15:17:34 -08002145#endif
Parav Panditd0d7b102017-02-04 11:00:49 -06002146 if (is_vlan_dev(event_dev))
Anish Bhattb5a02f52015-01-14 15:17:34 -08002147 event_dev = vlan_dev_real_dev(event_dev);
2148#if IS_ENABLED(CONFIG_BONDING)
2149 if (event_dev->flags & IFF_MASTER) {
2150 list_for_each_entry(adap, &adapter_list, list_node) {
2151 switch (event) {
2152 case NETDEV_UP:
2153 cxgb4_clip_get(adap->port[0],
2154 (const u32 *)ifa, 1);
2155 break;
2156 case NETDEV_DOWN:
2157 cxgb4_clip_release(adap->port[0],
2158 (const u32 *)ifa, 1);
2159 break;
2160 default:
2161 break;
2162 }
2163 }
2164 return NOTIFY_OK;
2165 }
2166#endif
Vipul Pandya01bcca62013-07-04 16:10:46 +05302167
Anish Bhattb5a02f52015-01-14 15:17:34 -08002168 if (event_dev)
2169 parent = event_dev->dev.parent;
Vipul Pandya01bcca62013-07-04 16:10:46 +05302170
Anish Bhattb5a02f52015-01-14 15:17:34 -08002171 if (parent && parent->driver == &cxgb4_driver.driver) {
Vipul Pandya01bcca62013-07-04 16:10:46 +05302172 switch (event) {
2173 case NETDEV_UP:
Anish Bhattb5a02f52015-01-14 15:17:34 -08002174 cxgb4_clip_get(event_dev, (const u32 *)ifa, 1);
Vipul Pandya01bcca62013-07-04 16:10:46 +05302175 break;
2176 case NETDEV_DOWN:
Anish Bhattb5a02f52015-01-14 15:17:34 -08002177 cxgb4_clip_release(event_dev, (const u32 *)ifa, 1);
Vipul Pandya01bcca62013-07-04 16:10:46 +05302178 break;
2179 default:
2180 break;
2181 }
2182 }
Anish Bhattb5a02f52015-01-14 15:17:34 -08002183 return NOTIFY_OK;
Vipul Pandya01bcca62013-07-04 16:10:46 +05302184}
2185
Anish Bhattb5a02f52015-01-14 15:17:34 -08002186static bool inet6addr_registered;
Vipul Pandya01bcca62013-07-04 16:10:46 +05302187static struct notifier_block cxgb4_inet6addr_notifier = {
2188 .notifier_call = cxgb4_inet6addr_handler
2189};
2190
Vipul Pandya01bcca62013-07-04 16:10:46 +05302191static void update_clip(const struct adapter *adap)
2192{
2193 int i;
2194 struct net_device *dev;
2195 int ret;
2196
2197 rcu_read_lock();
2198
2199 for (i = 0; i < MAX_NPORTS; i++) {
2200 dev = adap->port[i];
2201 ret = 0;
2202
2203 if (dev)
Anish Bhattb5a02f52015-01-14 15:17:34 -08002204 ret = cxgb4_update_root_dev_clip(dev);
Vipul Pandya01bcca62013-07-04 16:10:46 +05302205
2206 if (ret < 0)
2207 break;
2208 }
2209 rcu_read_unlock();
2210}
Anish Bhatt1bb60372014-10-14 20:07:22 -07002211#endif /* IS_ENABLED(CONFIG_IPV6) */
Vipul Pandya01bcca62013-07-04 16:10:46 +05302212
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002213/**
2214 * cxgb_up - enable the adapter
2215 * @adap: adapter being enabled
2216 *
2217 * Called when the first port is enabled, this function performs the
2218 * actions necessary to make an adapter operational, such as completing
2219 * the initialization of HW modules, and enabling interrupts.
2220 *
2221 * Must be called with the rtnl lock held.
2222 */
2223static int cxgb_up(struct adapter *adap)
2224{
Dimitris Michailidisaaefae92010-05-18 10:07:12 +00002225 int err;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002226
Raju Rangoju91060382017-06-19 17:40:48 +05302227 mutex_lock(&uld_mutex);
Dimitris Michailidisaaefae92010-05-18 10:07:12 +00002228 err = setup_sge_queues(adap);
2229 if (err)
Raju Rangoju91060382017-06-19 17:40:48 +05302230 goto rel_lock;
Dimitris Michailidisaaefae92010-05-18 10:07:12 +00002231 err = setup_rss(adap);
2232 if (err)
2233 goto freeq;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002234
2235 if (adap->flags & USING_MSIX) {
Dimitris Michailidisaaefae92010-05-18 10:07:12 +00002236 name_msix_vecs(adap);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002237 err = request_irq(adap->msix_info[0].vec, t4_nondata_intr, 0,
2238 adap->msix_info[0].desc, adap);
2239 if (err)
2240 goto irq_err;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002241 err = request_msix_queue_irqs(adap);
2242 if (err) {
2243 free_irq(adap->msix_info[0].vec, adap);
2244 goto irq_err;
2245 }
2246 } else {
2247 err = request_irq(adap->pdev->irq, t4_intr_handler(adap),
2248 (adap->flags & USING_MSI) ? 0 : IRQF_SHARED,
Dimitris Michailidisb1a3c2b2010-12-14 21:36:51 +00002249 adap->port[0]->name, adap);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002250 if (err)
2251 goto irq_err;
2252 }
Ganesh Goudare7519f92017-05-31 18:26:28 +05302253
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002254 enable_rx(adap);
2255 t4_sge_start(adap);
2256 t4_intr_enable(adap);
Dimitris Michailidisaaefae92010-05-18 10:07:12 +00002257 adap->flags |= FULL_INIT_DONE;
Ganesh Goudare7519f92017-05-31 18:26:28 +05302258 mutex_unlock(&uld_mutex);
2259
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002260 notify_ulds(adap, CXGB4_STATE_UP);
Anish Bhatt1bb60372014-10-14 20:07:22 -07002261#if IS_ENABLED(CONFIG_IPV6)
Vipul Pandya01bcca62013-07-04 16:10:46 +05302262 update_clip(adap);
Anish Bhatt1bb60372014-10-14 20:07:22 -07002263#endif
Hariprasad Shenaifc08a012016-02-16 10:07:09 +05302264 /* Initialize hash mac addr list*/
2265 INIT_LIST_HEAD(&adap->mac_hlist);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002266 return err;
Raju Rangoju91060382017-06-19 17:40:48 +05302267
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002268 irq_err:
2269 dev_err(adap->pdev_dev, "request_irq failed, err %d\n", err);
Dimitris Michailidisaaefae92010-05-18 10:07:12 +00002270 freeq:
2271 t4_free_sge_resources(adap);
Raju Rangoju91060382017-06-19 17:40:48 +05302272 rel_lock:
2273 mutex_unlock(&uld_mutex);
2274 return err;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002275}
2276
2277static void cxgb_down(struct adapter *adapter)
2278{
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002279 cancel_work_sync(&adapter->tid_release_task);
Vipul Pandya881806b2012-05-18 15:29:24 +05302280 cancel_work_sync(&adapter->db_full_task);
2281 cancel_work_sync(&adapter->db_drop_task);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002282 adapter->tid_release_task_busy = false;
Dimitris Michailidis204dc3c2010-06-18 10:05:29 +00002283 adapter->tid_release_head = NULL;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002284
Dimitris Michailidisaaefae92010-05-18 10:07:12 +00002285 t4_sge_stop(adapter);
2286 t4_free_sge_resources(adapter);
2287 adapter->flags &= ~FULL_INIT_DONE;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002288}
2289
2290/*
2291 * net_device operations
2292 */
2293static int cxgb_open(struct net_device *dev)
2294{
2295 int err;
2296 struct port_info *pi = netdev_priv(dev);
2297 struct adapter *adapter = pi->adapter;
2298
Dimitris Michailidis6a3c8692011-01-19 15:29:05 +00002299 netif_carrier_off(dev);
2300
Dimitris Michailidisaaefae92010-05-18 10:07:12 +00002301 if (!(adapter->flags & FULL_INIT_DONE)) {
2302 err = cxgb_up(adapter);
2303 if (err < 0)
2304 return err;
2305 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002306
Ganesh Goudar2061ec32017-05-19 17:50:15 +05302307 /* It's possible that the basic port information could have
2308 * changed since we first read it.
2309 */
2310 err = t4_update_port_info(pi);
2311 if (err < 0)
2312 return err;
2313
Dimitris Michailidisf68707b2010-06-18 10:05:32 +00002314 err = link_start(dev);
2315 if (!err)
2316 netif_tx_start_all_queues(dev);
2317 return err;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002318}
2319
2320static int cxgb_close(struct net_device *dev)
2321{
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002322 struct port_info *pi = netdev_priv(dev);
2323 struct adapter *adapter = pi->adapter;
Ganesh Goudarba581f72017-09-23 16:07:28 +05302324 int ret;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002325
2326 netif_tx_stop_all_queues(dev);
2327 netif_carrier_off(dev);
Ganesh Goudarba581f72017-09-23 16:07:28 +05302328 ret = t4_enable_vi(adapter, adapter->pf, pi->viid, false, false);
2329#ifdef CONFIG_CHELSIO_T4_DCB
2330 cxgb4_dcb_reset(dev);
2331 dcb_tx_queue_prio_enable(dev, false);
2332#endif
2333 return ret;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002334}
2335
Vipul Pandyadca4fae2012-12-10 09:30:53 +00002336int cxgb4_create_server_filter(const struct net_device *dev, unsigned int stid,
Vipul Pandya793dad92012-12-10 09:30:56 +00002337 __be32 sip, __be16 sport, __be16 vlan,
2338 unsigned int queue, unsigned char port, unsigned char mask)
Vipul Pandyadca4fae2012-12-10 09:30:53 +00002339{
2340 int ret;
2341 struct filter_entry *f;
2342 struct adapter *adap;
2343 int i;
2344 u8 *val;
2345
2346 adap = netdev2adap(dev);
2347
Vipul Pandya1cab7752012-12-10 09:30:55 +00002348 /* Adjust stid to correct filter index */
Kumar Sanghvi470c60c2013-12-18 16:38:21 +05302349 stid -= adap->tids.sftid_base;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002350 stid += adap->tids.nftids;
2351
Vipul Pandyadca4fae2012-12-10 09:30:53 +00002352 /* Check to make sure the filter requested is writable ...
2353 */
2354 f = &adap->tids.ftid_tab[stid];
2355 ret = writable_filter(f);
2356 if (ret)
2357 return ret;
2358
2359 /* Clear out any old resources being used by the filter before
2360 * we start constructing the new filter.
2361 */
2362 if (f->valid)
2363 clear_filter(adap, f);
2364
2365 /* Clear out filter specifications */
2366 memset(&f->fs, 0, sizeof(struct ch_filter_specification));
2367 f->fs.val.lport = cpu_to_be16(sport);
2368 f->fs.mask.lport = ~0;
2369 val = (u8 *)&sip;
Vipul Pandya793dad92012-12-10 09:30:56 +00002370 if ((val[0] | val[1] | val[2] | val[3]) != 0) {
Vipul Pandyadca4fae2012-12-10 09:30:53 +00002371 for (i = 0; i < 4; i++) {
2372 f->fs.val.lip[i] = val[i];
2373 f->fs.mask.lip[i] = ~0;
2374 }
Hariprasad Shenai0d804332015-01-05 16:30:47 +05302375 if (adap->params.tp.vlan_pri_map & PORT_F) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002376 f->fs.val.iport = port;
2377 f->fs.mask.iport = mask;
2378 }
2379 }
Vipul Pandyadca4fae2012-12-10 09:30:53 +00002380
Hariprasad Shenai0d804332015-01-05 16:30:47 +05302381 if (adap->params.tp.vlan_pri_map & PROTOCOL_F) {
Kumar Sanghvi7c89e552013-12-18 16:38:20 +05302382 f->fs.val.proto = IPPROTO_TCP;
2383 f->fs.mask.proto = ~0;
2384 }
2385
Vipul Pandyadca4fae2012-12-10 09:30:53 +00002386 f->fs.dirsteer = 1;
2387 f->fs.iq = queue;
2388 /* Mark filter as locked */
2389 f->locked = 1;
2390 f->fs.rpttid = 1;
2391
Ganesh Goudar6b254af2017-04-10 21:26:18 +05302392 /* Save the actual tid. We need this to get the corresponding
2393 * filter entry structure in filter_rpl.
2394 */
2395 f->tid = stid + adap->tids.ftid_base;
Vipul Pandyadca4fae2012-12-10 09:30:53 +00002396 ret = set_filter_wr(adap, stid);
2397 if (ret) {
2398 clear_filter(adap, f);
2399 return ret;
2400 }
2401
2402 return 0;
2403}
2404EXPORT_SYMBOL(cxgb4_create_server_filter);
2405
2406int cxgb4_remove_server_filter(const struct net_device *dev, unsigned int stid,
2407 unsigned int queue, bool ipv6)
2408{
Vipul Pandyadca4fae2012-12-10 09:30:53 +00002409 struct filter_entry *f;
2410 struct adapter *adap;
2411
2412 adap = netdev2adap(dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002413
2414 /* Adjust stid to correct filter index */
Kumar Sanghvi470c60c2013-12-18 16:38:21 +05302415 stid -= adap->tids.sftid_base;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002416 stid += adap->tids.nftids;
2417
Vipul Pandyadca4fae2012-12-10 09:30:53 +00002418 f = &adap->tids.ftid_tab[stid];
2419 /* Unlock the filter */
2420 f->locked = 0;
2421
Wei Yongjun8c148462016-08-20 15:32:41 +00002422 return delete_filter(adap, stid);
Vipul Pandyadca4fae2012-12-10 09:30:53 +00002423}
2424EXPORT_SYMBOL(cxgb4_remove_server_filter);
2425
stephen hemmingerbc1f4472017-01-06 19:12:52 -08002426static void cxgb_get_stats(struct net_device *dev,
2427 struct rtnl_link_stats64 *ns)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002428{
2429 struct port_stats stats;
2430 struct port_info *p = netdev_priv(dev);
2431 struct adapter *adapter = p->adapter;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002432
Gavin Shan9fe6cb52014-01-23 12:27:35 +08002433 /* Block retrieving statistics during EEH error
2434 * recovery. Otherwise, the recovery might fail
2435 * and the PCI device will be removed permanently
2436 */
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002437 spin_lock(&adapter->stats_lock);
Gavin Shan9fe6cb52014-01-23 12:27:35 +08002438 if (!netif_device_present(dev)) {
2439 spin_unlock(&adapter->stats_lock);
stephen hemmingerbc1f4472017-01-06 19:12:52 -08002440 return;
Gavin Shan9fe6cb52014-01-23 12:27:35 +08002441 }
Hariprasad Shenaia4cfd922015-06-03 21:04:39 +05302442 t4_get_port_stats_offset(adapter, p->tx_chan, &stats,
2443 &p->stats_base);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002444 spin_unlock(&adapter->stats_lock);
2445
2446 ns->tx_bytes = stats.tx_octets;
2447 ns->tx_packets = stats.tx_frames;
2448 ns->rx_bytes = stats.rx_octets;
2449 ns->rx_packets = stats.rx_frames;
2450 ns->multicast = stats.rx_mcast_frames;
2451
2452 /* detailed rx_errors */
2453 ns->rx_length_errors = stats.rx_jabber + stats.rx_too_long +
2454 stats.rx_runt;
2455 ns->rx_over_errors = 0;
2456 ns->rx_crc_errors = stats.rx_fcs_err;
2457 ns->rx_frame_errors = stats.rx_symbol_err;
Ganesh Goudarb93f79b2017-02-15 11:45:25 +05302458 ns->rx_dropped = stats.rx_ovflow0 + stats.rx_ovflow1 +
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002459 stats.rx_ovflow2 + stats.rx_ovflow3 +
2460 stats.rx_trunc0 + stats.rx_trunc1 +
2461 stats.rx_trunc2 + stats.rx_trunc3;
2462 ns->rx_missed_errors = 0;
2463
2464 /* detailed tx_errors */
2465 ns->tx_aborted_errors = 0;
2466 ns->tx_carrier_errors = 0;
2467 ns->tx_fifo_errors = 0;
2468 ns->tx_heartbeat_errors = 0;
2469 ns->tx_window_errors = 0;
2470
2471 ns->tx_errors = stats.tx_error_frames;
2472 ns->rx_errors = stats.rx_symbol_err + stats.rx_fcs_err +
2473 ns->rx_length_errors + stats.rx_len_err + ns->rx_fifo_errors;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002474}
2475
2476static int cxgb_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
2477{
Dimitris Michailidis060e0c72010-08-02 13:19:21 +00002478 unsigned int mbox;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002479 int ret = 0, prtad, devad;
2480 struct port_info *pi = netdev_priv(dev);
Atul Guptaa45695042017-07-04 16:46:20 +05302481 struct adapter *adapter = pi->adapter;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002482 struct mii_ioctl_data *data = (struct mii_ioctl_data *)&req->ifr_data;
2483
2484 switch (cmd) {
2485 case SIOCGMIIPHY:
2486 if (pi->mdio_addr < 0)
2487 return -EOPNOTSUPP;
2488 data->phy_id = pi->mdio_addr;
2489 break;
2490 case SIOCGMIIREG:
2491 case SIOCSMIIREG:
2492 if (mdio_phy_id_is_c45(data->phy_id)) {
2493 prtad = mdio_phy_id_prtad(data->phy_id);
2494 devad = mdio_phy_id_devad(data->phy_id);
2495 } else if (data->phy_id < 32) {
2496 prtad = data->phy_id;
2497 devad = 0;
2498 data->reg_num &= 0x1f;
2499 } else
2500 return -EINVAL;
2501
Hariprasad Shenaib2612722015-05-27 22:30:24 +05302502 mbox = pi->adapter->pf;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002503 if (cmd == SIOCGMIIREG)
Dimitris Michailidis060e0c72010-08-02 13:19:21 +00002504 ret = t4_mdio_rd(pi->adapter, mbox, prtad, devad,
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002505 data->reg_num, &data->val_out);
2506 else
Dimitris Michailidis060e0c72010-08-02 13:19:21 +00002507 ret = t4_mdio_wr(pi->adapter, mbox, prtad, devad,
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002508 data->reg_num, data->val_in);
2509 break;
Hariprasad Shenai5e2a5eb2015-09-28 10:26:53 +05302510 case SIOCGHWTSTAMP:
2511 return copy_to_user(req->ifr_data, &pi->tstamp_config,
2512 sizeof(pi->tstamp_config)) ?
2513 -EFAULT : 0;
2514 case SIOCSHWTSTAMP:
2515 if (copy_from_user(&pi->tstamp_config, req->ifr_data,
2516 sizeof(pi->tstamp_config)))
2517 return -EFAULT;
2518
Atul Guptaa45695042017-07-04 16:46:20 +05302519 if (!is_t4(adapter->params.chip)) {
2520 switch (pi->tstamp_config.tx_type) {
2521 case HWTSTAMP_TX_OFF:
2522 case HWTSTAMP_TX_ON:
2523 break;
2524 default:
2525 return -ERANGE;
2526 }
2527
2528 switch (pi->tstamp_config.rx_filter) {
2529 case HWTSTAMP_FILTER_NONE:
2530 pi->rxtstamp = false;
2531 break;
2532 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
2533 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
2534 cxgb4_ptprx_timestamping(pi, pi->port_id,
2535 PTP_TS_L4);
2536 break;
2537 case HWTSTAMP_FILTER_PTP_V2_EVENT:
2538 cxgb4_ptprx_timestamping(pi, pi->port_id,
2539 PTP_TS_L2_L4);
2540 break;
2541 case HWTSTAMP_FILTER_ALL:
2542 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
2543 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
2544 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
2545 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
2546 pi->rxtstamp = true;
2547 break;
2548 default:
2549 pi->tstamp_config.rx_filter =
2550 HWTSTAMP_FILTER_NONE;
2551 return -ERANGE;
2552 }
2553
2554 if ((pi->tstamp_config.tx_type == HWTSTAMP_TX_OFF) &&
2555 (pi->tstamp_config.rx_filter ==
2556 HWTSTAMP_FILTER_NONE)) {
2557 if (cxgb4_ptp_txtype(adapter, pi->port_id) >= 0)
2558 pi->ptp_enable = false;
2559 }
2560
2561 if (pi->tstamp_config.rx_filter !=
2562 HWTSTAMP_FILTER_NONE) {
2563 if (cxgb4_ptp_redirect_rx_packet(adapter,
2564 pi) >= 0)
2565 pi->ptp_enable = true;
2566 }
2567 } else {
2568 /* For T4 Adapters */
2569 switch (pi->tstamp_config.rx_filter) {
2570 case HWTSTAMP_FILTER_NONE:
Hariprasad Shenai5e2a5eb2015-09-28 10:26:53 +05302571 pi->rxtstamp = false;
2572 break;
Atul Guptaa45695042017-07-04 16:46:20 +05302573 case HWTSTAMP_FILTER_ALL:
Hariprasad Shenai5e2a5eb2015-09-28 10:26:53 +05302574 pi->rxtstamp = true;
2575 break;
Atul Guptaa45695042017-07-04 16:46:20 +05302576 default:
2577 pi->tstamp_config.rx_filter =
2578 HWTSTAMP_FILTER_NONE;
Hariprasad Shenai5e2a5eb2015-09-28 10:26:53 +05302579 return -ERANGE;
Atul Guptaa45695042017-07-04 16:46:20 +05302580 }
Hariprasad Shenai5e2a5eb2015-09-28 10:26:53 +05302581 }
Hariprasad Shenai5e2a5eb2015-09-28 10:26:53 +05302582 return copy_to_user(req->ifr_data, &pi->tstamp_config,
2583 sizeof(pi->tstamp_config)) ?
2584 -EFAULT : 0;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002585 default:
2586 return -EOPNOTSUPP;
2587 }
2588 return ret;
2589}
2590
2591static void cxgb_set_rxmode(struct net_device *dev)
2592{
2593 /* unfortunately we can't return errors to the stack */
2594 set_rxmode(dev, -1, false);
2595}
2596
2597static int cxgb_change_mtu(struct net_device *dev, int new_mtu)
2598{
2599 int ret;
2600 struct port_info *pi = netdev_priv(dev);
2601
Hariprasad Shenaib2612722015-05-27 22:30:24 +05302602 ret = t4_set_rxmode(pi->adapter, pi->adapter->pf, pi->viid, new_mtu, -1,
Dimitris Michailidis060e0c72010-08-02 13:19:21 +00002603 -1, -1, -1, true);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002604 if (!ret)
2605 dev->mtu = new_mtu;
2606 return ret;
2607}
2608
Hariprasad Shenai858aa652016-08-11 21:06:24 +05302609#ifdef CONFIG_PCI_IOV
Ganesh Goudarbaf50862018-01-16 16:17:40 +05302610static int cxgb4_mgmt_open(struct net_device *dev)
Hariprasad Shenaie7b48a32016-08-23 11:35:32 +05302611{
2612 /* Turn carrier off since we don't have to transmit anything on this
2613 * interface.
2614 */
2615 netif_carrier_off(dev);
2616 return 0;
2617}
2618
Hariprasad Shenai661dbeb2016-09-02 19:13:53 +05302619/* Fill MAC address that will be assigned by the FW */
Ganesh Goudarbaf50862018-01-16 16:17:40 +05302620static void cxgb4_mgmt_fill_vf_station_mac_addr(struct adapter *adap)
Hariprasad Shenai661dbeb2016-09-02 19:13:53 +05302621{
Hariprasad Shenai661dbeb2016-09-02 19:13:53 +05302622 u8 hw_addr[ETH_ALEN], macaddr[ETH_ALEN];
Ganesh Goudarbaf50862018-01-16 16:17:40 +05302623 unsigned int i, vf, nvfs;
2624 u16 a, b;
Hariprasad Shenai661dbeb2016-09-02 19:13:53 +05302625 int err;
2626 u8 *na;
Hariprasad Shenai661dbeb2016-09-02 19:13:53 +05302627
Ganesh Goudarbaf50862018-01-16 16:17:40 +05302628 adap->params.pci.vpd_cap_addr = pci_find_capability(adap->pdev,
2629 PCI_CAP_ID_VPD);
Hariprasad Shenai661dbeb2016-09-02 19:13:53 +05302630 err = t4_get_raw_vpd_params(adap, &adap->params.vpd);
Ganesh Goudarbaf50862018-01-16 16:17:40 +05302631 if (err)
2632 return;
Hariprasad Shenai661dbeb2016-09-02 19:13:53 +05302633
Ganesh Goudarbaf50862018-01-16 16:17:40 +05302634 na = adap->params.vpd.na;
2635 for (i = 0; i < ETH_ALEN; i++)
2636 hw_addr[i] = (hex2val(na[2 * i + 0]) * 16 +
2637 hex2val(na[2 * i + 1]));
Hariprasad Shenai661dbeb2016-09-02 19:13:53 +05302638
Ganesh Goudarbaf50862018-01-16 16:17:40 +05302639 a = (hw_addr[0] << 8) | hw_addr[1];
2640 b = (hw_addr[1] << 8) | hw_addr[2];
2641 a ^= b;
2642 a |= 0x0200; /* locally assigned Ethernet MAC address */
2643 a &= ~0x0100; /* not a multicast Ethernet MAC address */
2644 macaddr[0] = a >> 8;
2645 macaddr[1] = a & 0xff;
2646
2647 for (i = 2; i < 5; i++)
2648 macaddr[i] = hw_addr[i + 1];
2649
2650 for (vf = 0, nvfs = pci_sriov_get_totalvfs(adap->pdev);
2651 vf < nvfs; vf++) {
2652 macaddr[5] = adap->pf * 16 + vf;
2653 ether_addr_copy(adap->vfinfo[vf].vf_mac_addr, macaddr);
Hariprasad Shenai661dbeb2016-09-02 19:13:53 +05302654 }
2655}
2656
Ganesh Goudarbaf50862018-01-16 16:17:40 +05302657static int cxgb4_mgmt_set_vf_mac(struct net_device *dev, int vf, u8 *mac)
Hariprasad Shenai858aa652016-08-11 21:06:24 +05302658{
2659 struct port_info *pi = netdev_priv(dev);
2660 struct adapter *adap = pi->adapter;
Hariprasad Shenai661dbeb2016-09-02 19:13:53 +05302661 int ret;
Hariprasad Shenai858aa652016-08-11 21:06:24 +05302662
2663 /* verify MAC addr is valid */
2664 if (!is_valid_ether_addr(mac)) {
2665 dev_err(pi->adapter->pdev_dev,
2666 "Invalid Ethernet address %pM for VF %d\n",
2667 mac, vf);
2668 return -EINVAL;
2669 }
2670
2671 dev_info(pi->adapter->pdev_dev,
2672 "Setting MAC %pM on VF %d\n", mac, vf);
Hariprasad Shenai661dbeb2016-09-02 19:13:53 +05302673 ret = t4_set_vf_mac_acl(adap, vf + 1, 1, mac);
2674 if (!ret)
2675 ether_addr_copy(adap->vfinfo[vf].vf_mac_addr, mac);
2676 return ret;
2677}
2678
Ganesh Goudarbaf50862018-01-16 16:17:40 +05302679static int cxgb4_mgmt_get_vf_config(struct net_device *dev,
2680 int vf, struct ifla_vf_info *ivi)
Hariprasad Shenai661dbeb2016-09-02 19:13:53 +05302681{
2682 struct port_info *pi = netdev_priv(dev);
2683 struct adapter *adap = pi->adapter;
2684
2685 if (vf >= adap->num_vfs)
2686 return -EINVAL;
2687 ivi->vf = vf;
Ganesh Goudar8ea4fae2017-06-05 18:34:20 +05302688 ivi->max_tx_rate = adap->vfinfo[vf].tx_rate;
2689 ivi->min_tx_rate = 0;
Hariprasad Shenai661dbeb2016-09-02 19:13:53 +05302690 ether_addr_copy(ivi->mac, adap->vfinfo[vf].vf_mac_addr);
2691 return 0;
Hariprasad Shenai858aa652016-08-11 21:06:24 +05302692}
Ganesh Goudar96fe11f2017-01-17 14:09:38 +05302693
Ganesh Goudarbaf50862018-01-16 16:17:40 +05302694static int cxgb4_mgmt_get_phys_port_id(struct net_device *dev,
2695 struct netdev_phys_item_id *ppid)
Ganesh Goudar96fe11f2017-01-17 14:09:38 +05302696{
2697 struct port_info *pi = netdev_priv(dev);
2698 unsigned int phy_port_id;
2699
2700 phy_port_id = pi->adapter->adap_idx * 10 + pi->port_id;
2701 ppid->id_len = sizeof(phy_port_id);
2702 memcpy(ppid->id, &phy_port_id, ppid->id_len);
2703 return 0;
2704}
2705
Ganesh Goudarbaf50862018-01-16 16:17:40 +05302706static int cxgb4_mgmt_set_vf_rate(struct net_device *dev, int vf,
2707 int min_tx_rate, int max_tx_rate)
Ganesh Goudar8ea4fae2017-06-05 18:34:20 +05302708{
2709 struct port_info *pi = netdev_priv(dev);
2710 struct adapter *adap = pi->adapter;
Ganesh Goudarc3168ca2017-08-20 14:15:51 +05302711 unsigned int link_ok, speed, mtu;
Ganesh Goudar8ea4fae2017-06-05 18:34:20 +05302712 u32 fw_pfvf, fw_class;
2713 int class_id = vf;
Ganesh Goudarc3168ca2017-08-20 14:15:51 +05302714 int ret;
Ganesh Goudar8ea4fae2017-06-05 18:34:20 +05302715 u16 pktsize;
2716
2717 if (vf >= adap->num_vfs)
2718 return -EINVAL;
2719
2720 if (min_tx_rate) {
2721 dev_err(adap->pdev_dev,
2722 "Min tx rate (%d) (> 0) for VF %d is Invalid.\n",
2723 min_tx_rate, vf);
2724 return -EINVAL;
2725 }
Ganesh Goudarc3168ca2017-08-20 14:15:51 +05302726
2727 ret = t4_get_link_params(pi, &link_ok, &speed, &mtu);
Ganesh Goudar8ea4fae2017-06-05 18:34:20 +05302728 if (ret != FW_SUCCESS) {
2729 dev_err(adap->pdev_dev,
Ganesh Goudarc3168ca2017-08-20 14:15:51 +05302730 "Failed to get link information for VF %d\n", vf);
Ganesh Goudar8ea4fae2017-06-05 18:34:20 +05302731 return -EINVAL;
2732 }
Ganesh Goudarc3168ca2017-08-20 14:15:51 +05302733
Ganesh Goudar8ea4fae2017-06-05 18:34:20 +05302734 if (!link_ok) {
2735 dev_err(adap->pdev_dev, "Link down for VF %d\n", vf);
2736 return -EINVAL;
2737 }
Ganesh Goudar8ea4fae2017-06-05 18:34:20 +05302738
2739 if (max_tx_rate > speed) {
2740 dev_err(adap->pdev_dev,
2741 "Max tx rate %d for VF %d can't be > link-speed %u",
2742 max_tx_rate, vf, speed);
2743 return -EINVAL;
2744 }
Ganesh Goudarc3168ca2017-08-20 14:15:51 +05302745
2746 pktsize = mtu;
Ganesh Goudar8ea4fae2017-06-05 18:34:20 +05302747 /* subtract ethhdr size and 4 bytes crc since, f/w appends it */
2748 pktsize = pktsize - sizeof(struct ethhdr) - 4;
2749 /* subtract ipv4 hdr size, tcp hdr size to get typical IPv4 MSS size */
2750 pktsize = pktsize - sizeof(struct iphdr) - sizeof(struct tcphdr);
2751 /* configure Traffic Class for rate-limiting */
2752 ret = t4_sched_params(adap, SCHED_CLASS_TYPE_PACKET,
2753 SCHED_CLASS_LEVEL_CL_RL,
2754 SCHED_CLASS_MODE_CLASS,
2755 SCHED_CLASS_RATEUNIT_BITS,
2756 SCHED_CLASS_RATEMODE_ABS,
Ganesh Goudarc3168ca2017-08-20 14:15:51 +05302757 pi->tx_chan, class_id, 0,
Ganesh Goudar8ea4fae2017-06-05 18:34:20 +05302758 max_tx_rate * 1000, 0, pktsize);
2759 if (ret) {
2760 dev_err(adap->pdev_dev, "Err %d for Traffic Class config\n",
2761 ret);
2762 return -EINVAL;
2763 }
2764 dev_info(adap->pdev_dev,
2765 "Class %d with MSS %u configured with rate %u\n",
2766 class_id, pktsize, max_tx_rate);
2767
2768 /* bind VF to configured Traffic Class */
2769 fw_pfvf = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_PFVF) |
2770 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_PFVF_SCHEDCLASS_ETH));
2771 fw_class = class_id;
2772 ret = t4_set_params(adap, adap->mbox, adap->pf, vf + 1, 1, &fw_pfvf,
2773 &fw_class);
2774 if (ret) {
2775 dev_err(adap->pdev_dev,
2776 "Err %d in binding VF %d to Traffic Class %d\n",
2777 ret, vf, class_id);
2778 return -EINVAL;
2779 }
2780 dev_info(adap->pdev_dev, "PF %d VF %d is bound to Class %d\n",
2781 adap->pf, vf, class_id);
2782 adap->vfinfo[vf].tx_rate = max_tx_rate;
2783 return 0;
2784}
2785
Hariprasad Shenai858aa652016-08-11 21:06:24 +05302786#endif
2787
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002788static int cxgb_set_mac_addr(struct net_device *dev, void *p)
2789{
2790 int ret;
2791 struct sockaddr *addr = p;
2792 struct port_info *pi = netdev_priv(dev);
2793
2794 if (!is_valid_ether_addr(addr->sa_data))
Danny Kukawka504f9b52012-02-21 02:07:49 +00002795 return -EADDRNOTAVAIL;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002796
Hariprasad Shenaib2612722015-05-27 22:30:24 +05302797 ret = t4_change_mac(pi->adapter, pi->adapter->pf, pi->viid,
Dimitris Michailidis060e0c72010-08-02 13:19:21 +00002798 pi->xact_addr_filt, addr->sa_data, true, true);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002799 if (ret < 0)
2800 return ret;
2801
2802 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
2803 pi->xact_addr_filt = ret;
2804 return 0;
2805}
2806
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002807#ifdef CONFIG_NET_POLL_CONTROLLER
2808static void cxgb_netpoll(struct net_device *dev)
2809{
2810 struct port_info *pi = netdev_priv(dev);
2811 struct adapter *adap = pi->adapter;
2812
2813 if (adap->flags & USING_MSIX) {
2814 int i;
2815 struct sge_eth_rxq *rx = &adap->sge.ethrxq[pi->first_qset];
2816
2817 for (i = pi->nqsets; i; i--, rx++)
2818 t4_sge_intr_msix(0, &rx->rspq);
2819 } else
2820 t4_intr_handler(adap)(0, adap);
2821}
2822#endif
2823
Rahul Lakkireddy10a26042016-08-22 16:29:08 +05302824static int cxgb_set_tx_maxrate(struct net_device *dev, int index, u32 rate)
2825{
2826 struct port_info *pi = netdev_priv(dev);
2827 struct adapter *adap = pi->adapter;
2828 struct sched_class *e;
2829 struct ch_sched_params p;
2830 struct ch_sched_queue qe;
2831 u32 req_rate;
2832 int err = 0;
2833
2834 if (!can_sched(dev))
2835 return -ENOTSUPP;
2836
2837 if (index < 0 || index > pi->nqsets - 1)
2838 return -EINVAL;
2839
2840 if (!(adap->flags & FULL_INIT_DONE)) {
2841 dev_err(adap->pdev_dev,
2842 "Failed to rate limit on queue %d. Link Down?\n",
2843 index);
2844 return -EINVAL;
2845 }
2846
2847 /* Convert from Mbps to Kbps */
2848 req_rate = rate << 10;
2849
2850 /* Max rate is 10 Gbps */
2851 if (req_rate >= SCHED_MAX_RATE_KBPS) {
2852 dev_err(adap->pdev_dev,
2853 "Invalid rate %u Mbps, Max rate is %u Gbps\n",
2854 rate, SCHED_MAX_RATE_KBPS);
2855 return -ERANGE;
2856 }
2857
2858 /* First unbind the queue from any existing class */
2859 memset(&qe, 0, sizeof(qe));
2860 qe.queue = index;
2861 qe.class = SCHED_CLS_NONE;
2862
2863 err = cxgb4_sched_class_unbind(dev, (void *)(&qe), SCHED_QUEUE);
2864 if (err) {
2865 dev_err(adap->pdev_dev,
2866 "Unbinding Queue %d on port %d fail. Err: %d\n",
2867 index, pi->port_id, err);
2868 return err;
2869 }
2870
2871 /* Queue already unbound */
2872 if (!req_rate)
2873 return 0;
2874
2875 /* Fetch any available unused or matching scheduling class */
2876 memset(&p, 0, sizeof(p));
2877 p.type = SCHED_CLASS_TYPE_PACKET;
2878 p.u.params.level = SCHED_CLASS_LEVEL_CL_RL;
2879 p.u.params.mode = SCHED_CLASS_MODE_CLASS;
2880 p.u.params.rateunit = SCHED_CLASS_RATEUNIT_BITS;
2881 p.u.params.ratemode = SCHED_CLASS_RATEMODE_ABS;
2882 p.u.params.channel = pi->tx_chan;
2883 p.u.params.class = SCHED_CLS_NONE;
2884 p.u.params.minrate = 0;
2885 p.u.params.maxrate = req_rate;
2886 p.u.params.weight = 0;
2887 p.u.params.pktsize = dev->mtu;
2888
2889 e = cxgb4_sched_class_alloc(dev, &p);
2890 if (!e)
2891 return -ENOMEM;
2892
2893 /* Bind the queue to a scheduling class */
2894 memset(&qe, 0, sizeof(qe));
2895 qe.queue = index;
2896 qe.class = e->idx;
2897
2898 err = cxgb4_sched_class_bind(dev, (void *)(&qe), SCHED_QUEUE);
2899 if (err)
2900 dev_err(adap->pdev_dev,
2901 "Queue rate limiting failed. Err: %d\n", err);
2902 return err;
2903}
2904
Kumar Sanghvi6a345b32017-09-21 23:41:13 +05302905static int cxgb_setup_tc_flower(struct net_device *dev,
2906 struct tc_cls_flower_offload *cls_flower)
2907{
Jiri Pirkocd019e92017-10-19 15:50:40 +02002908 if (cls_flower->common.chain_index)
Kumar Sanghvi6a345b32017-09-21 23:41:13 +05302909 return -EOPNOTSUPP;
2910
2911 switch (cls_flower->command) {
2912 case TC_CLSFLOWER_REPLACE:
2913 return cxgb4_tc_flower_replace(dev, cls_flower);
2914 case TC_CLSFLOWER_DESTROY:
2915 return cxgb4_tc_flower_destroy(dev, cls_flower);
2916 case TC_CLSFLOWER_STATS:
2917 return cxgb4_tc_flower_stats(dev, cls_flower);
2918 default:
2919 return -EOPNOTSUPP;
2920 }
2921}
2922
Jiri Pirkof7323042017-08-07 10:15:20 +02002923static int cxgb_setup_tc_cls_u32(struct net_device *dev,
Jiri Pirkof7323042017-08-07 10:15:20 +02002924 struct tc_cls_u32_offload *cls_u32)
2925{
Jiri Pirkocd019e92017-10-19 15:50:40 +02002926 if (cls_u32->common.chain_index)
Jiri Pirkof7323042017-08-07 10:15:20 +02002927 return -EOPNOTSUPP;
2928
2929 switch (cls_u32->command) {
2930 case TC_CLSU32_NEW_KNODE:
2931 case TC_CLSU32_REPLACE_KNODE:
Jiri Pirko5fd9fc42017-08-07 10:15:29 +02002932 return cxgb4_config_knode(dev, cls_u32);
Jiri Pirkof7323042017-08-07 10:15:20 +02002933 case TC_CLSU32_DELETE_KNODE:
Jiri Pirko5fd9fc42017-08-07 10:15:29 +02002934 return cxgb4_delete_knode(dev, cls_u32);
Jiri Pirkof7323042017-08-07 10:15:20 +02002935 default:
2936 return -EOPNOTSUPP;
2937 }
2938}
2939
Jiri Pirkocd019e92017-10-19 15:50:40 +02002940static int cxgb_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
2941 void *cb_priv)
Rahul Lakkireddyd8931842016-09-20 17:13:09 +05302942{
Jiri Pirkocd019e92017-10-19 15:50:40 +02002943 struct net_device *dev = cb_priv;
Rahul Lakkireddyd8931842016-09-20 17:13:09 +05302944 struct port_info *pi = netdev2pinfo(dev);
2945 struct adapter *adap = netdev2adap(dev);
2946
2947 if (!(adap->flags & FULL_INIT_DONE)) {
2948 dev_err(adap->pdev_dev,
2949 "Failed to setup tc on port %d. Link Down?\n",
2950 pi->port_id);
2951 return -EINVAL;
2952 }
2953
Jiri Pirko44ae12a2017-11-01 11:47:39 +01002954 if (!tc_can_offload(dev))
2955 return -EOPNOTSUPP;
2956
Jiri Pirkof7323042017-08-07 10:15:20 +02002957 switch (type) {
2958 case TC_SETUP_CLSU32:
Jiri Pirkode4784c2017-08-07 10:15:32 +02002959 return cxgb_setup_tc_cls_u32(dev, type_data);
Kumar Sanghvi6a345b32017-09-21 23:41:13 +05302960 case TC_SETUP_CLSFLOWER:
2961 return cxgb_setup_tc_flower(dev, type_data);
Jiri Pirkof7323042017-08-07 10:15:20 +02002962 default:
2963 return -EOPNOTSUPP;
Rahul Lakkireddyd8931842016-09-20 17:13:09 +05302964 }
Rahul Lakkireddyd8931842016-09-20 17:13:09 +05302965}
2966
Jiri Pirkocd019e92017-10-19 15:50:40 +02002967static int cxgb_setup_tc_block(struct net_device *dev,
2968 struct tc_block_offload *f)
2969{
2970 struct port_info *pi = netdev2pinfo(dev);
2971
2972 if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
2973 return -EOPNOTSUPP;
2974
2975 switch (f->command) {
2976 case TC_BLOCK_BIND:
2977 return tcf_block_cb_register(f->block, cxgb_setup_tc_block_cb,
2978 pi, dev);
2979 case TC_BLOCK_UNBIND:
2980 tcf_block_cb_unregister(f->block, cxgb_setup_tc_block_cb, pi);
2981 return 0;
2982 default:
2983 return -EOPNOTSUPP;
2984 }
2985}
2986
2987static int cxgb_setup_tc(struct net_device *dev, enum tc_setup_type type,
2988 void *type_data)
2989{
2990 switch (type) {
Jiri Pirkocd019e92017-10-19 15:50:40 +02002991 case TC_SETUP_BLOCK:
2992 return cxgb_setup_tc_block(dev, type_data);
2993 default:
2994 return -EOPNOTSUPP;
2995 }
2996}
2997
Ganesh Goudar846eac32018-01-10 18:15:08 +05302998static void cxgb_del_udp_tunnel(struct net_device *netdev,
2999 struct udp_tunnel_info *ti)
3000{
3001 struct port_info *pi = netdev_priv(netdev);
3002 struct adapter *adapter = pi->adapter;
3003 unsigned int chip_ver = CHELSIO_CHIP_VERSION(adapter->params.chip);
3004 u8 match_all_mac[] = { 0, 0, 0, 0, 0, 0 };
3005 int ret = 0, i;
3006
3007 if (chip_ver < CHELSIO_T6)
3008 return;
3009
3010 switch (ti->type) {
3011 case UDP_TUNNEL_TYPE_VXLAN:
3012 if (!adapter->vxlan_port_cnt ||
3013 adapter->vxlan_port != ti->port)
3014 return; /* Invalid VxLAN destination port */
3015
3016 adapter->vxlan_port_cnt--;
3017 if (adapter->vxlan_port_cnt)
3018 return;
3019
3020 adapter->vxlan_port = 0;
3021 t4_write_reg(adapter, MPS_RX_VXLAN_TYPE_A, 0);
3022 break;
3023 default:
3024 return;
3025 }
3026
3027 /* Matchall mac entries can be deleted only after all tunnel ports
3028 * are brought down or removed.
3029 */
3030 if (!adapter->rawf_cnt)
3031 return;
3032 for_each_port(adapter, i) {
3033 pi = adap2pinfo(adapter, i);
3034 ret = t4_free_raw_mac_filt(adapter, pi->viid,
3035 match_all_mac, match_all_mac,
3036 adapter->rawf_start +
3037 pi->port_id,
3038 1, pi->port_id, true);
3039 if (ret < 0) {
3040 netdev_info(netdev, "Failed to free mac filter entry, for port %d\n",
3041 i);
3042 return;
3043 }
3044 atomic_dec(&adapter->mps_encap[adapter->rawf_start +
3045 pi->port_id].refcnt);
3046 }
3047}
3048
3049static void cxgb_add_udp_tunnel(struct net_device *netdev,
3050 struct udp_tunnel_info *ti)
3051{
3052 struct port_info *pi = netdev_priv(netdev);
3053 struct adapter *adapter = pi->adapter;
3054 unsigned int chip_ver = CHELSIO_CHIP_VERSION(adapter->params.chip);
3055 u8 match_all_mac[] = { 0, 0, 0, 0, 0, 0 };
3056 int i, ret;
3057
3058 if (chip_ver < CHELSIO_T6)
3059 return;
3060
3061 switch (ti->type) {
3062 case UDP_TUNNEL_TYPE_VXLAN:
3063 /* For T6 fw reserves last 2 entries for
3064 * storing match all mac filter (config file entry).
3065 */
3066 if (!adapter->rawf_cnt)
3067 return;
3068
3069 /* Callback for adding vxlan port can be called with the same
3070 * port for both IPv4 and IPv6. We should not disable the
3071 * offloading when the same port for both protocols is added
3072 * and later one of them is removed.
3073 */
3074 if (adapter->vxlan_port_cnt &&
3075 adapter->vxlan_port == ti->port) {
3076 adapter->vxlan_port_cnt++;
3077 return;
3078 }
3079
3080 /* We will support only one VxLAN port */
3081 if (adapter->vxlan_port_cnt) {
3082 netdev_info(netdev, "UDP port %d already offloaded, not adding port %d\n",
3083 be16_to_cpu(adapter->vxlan_port),
3084 be16_to_cpu(ti->port));
3085 return;
3086 }
3087
3088 adapter->vxlan_port = ti->port;
3089 adapter->vxlan_port_cnt = 1;
3090
3091 t4_write_reg(adapter, MPS_RX_VXLAN_TYPE_A,
3092 VXLAN_V(be16_to_cpu(ti->port)) | VXLAN_EN_F);
3093 break;
3094 default:
3095 return;
3096 }
3097
3098 /* Create a 'match all' mac filter entry for inner mac,
3099 * if raw mac interface is supported. Once the linux kernel provides
3100 * driver entry points for adding/deleting the inner mac addresses,
3101 * we will remove this 'match all' entry and fallback to adding
3102 * exact match filters.
3103 */
3104 if (adapter->rawf_cnt) {
3105 for_each_port(adapter, i) {
3106 pi = adap2pinfo(adapter, i);
3107
3108 ret = t4_alloc_raw_mac_filt(adapter, pi->viid,
3109 match_all_mac,
3110 match_all_mac,
3111 adapter->rawf_start +
3112 pi->port_id,
3113 1, pi->port_id, true);
3114 if (ret < 0) {
3115 netdev_info(netdev, "Failed to allocate a mac filter entry, not adding port %d\n",
3116 be16_to_cpu(ti->port));
3117 cxgb_del_udp_tunnel(netdev, ti);
3118 return;
3119 }
3120 atomic_inc(&adapter->mps_encap[ret].refcnt);
3121 }
3122 }
3123}
3124
Ganesh Goudar4621ffd2018-01-10 18:15:47 +05303125static netdev_features_t cxgb_features_check(struct sk_buff *skb,
3126 struct net_device *dev,
3127 netdev_features_t features)
3128{
3129 struct port_info *pi = netdev_priv(dev);
3130 struct adapter *adapter = pi->adapter;
3131
3132 if (CHELSIO_CHIP_VERSION(adapter->params.chip) < CHELSIO_T6)
3133 return features;
3134
3135 /* Check if hw supports offload for this packet */
3136 if (!skb->encapsulation || cxgb_encap_offload_supported(skb))
3137 return features;
3138
3139 /* Offload is not supported for this encapsulated packet */
3140 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
3141}
3142
Arjun Vynipadath90592b92017-05-30 13:30:24 +05303143static netdev_features_t cxgb_fix_features(struct net_device *dev,
3144 netdev_features_t features)
3145{
3146 /* Disable GRO, if RX_CSUM is disabled */
3147 if (!(features & NETIF_F_RXCSUM))
3148 features &= ~NETIF_F_GRO;
3149
3150 return features;
3151}
3152
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003153static const struct net_device_ops cxgb4_netdev_ops = {
3154 .ndo_open = cxgb_open,
3155 .ndo_stop = cxgb_close,
3156 .ndo_start_xmit = t4_eth_xmit,
Anish Bhatt688848b2014-06-19 21:37:13 -07003157 .ndo_select_queue = cxgb_select_queue,
Dimitris Michailidis9be793b2010-06-18 10:05:31 +00003158 .ndo_get_stats64 = cxgb_get_stats,
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003159 .ndo_set_rx_mode = cxgb_set_rxmode,
3160 .ndo_set_mac_address = cxgb_set_mac_addr,
Michał Mirosław2ed28ba2011-04-16 13:05:08 +00003161 .ndo_set_features = cxgb_set_features,
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003162 .ndo_validate_addr = eth_validate_addr,
3163 .ndo_do_ioctl = cxgb_ioctl,
3164 .ndo_change_mtu = cxgb_change_mtu,
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003165#ifdef CONFIG_NET_POLL_CONTROLLER
3166 .ndo_poll_controller = cxgb_netpoll,
3167#endif
Varun Prakash84a200b2015-03-24 19:14:46 +05303168#ifdef CONFIG_CHELSIO_T4_FCOE
3169 .ndo_fcoe_enable = cxgb_fcoe_enable,
3170 .ndo_fcoe_disable = cxgb_fcoe_disable,
3171#endif /* CONFIG_CHELSIO_T4_FCOE */
Rahul Lakkireddy10a26042016-08-22 16:29:08 +05303172 .ndo_set_tx_maxrate = cxgb_set_tx_maxrate,
Rahul Lakkireddyd8931842016-09-20 17:13:09 +05303173 .ndo_setup_tc = cxgb_setup_tc,
Ganesh Goudar846eac32018-01-10 18:15:08 +05303174 .ndo_udp_tunnel_add = cxgb_add_udp_tunnel,
3175 .ndo_udp_tunnel_del = cxgb_del_udp_tunnel,
Ganesh Goudar4621ffd2018-01-10 18:15:47 +05303176 .ndo_features_check = cxgb_features_check,
Arjun Vynipadath90592b92017-05-30 13:30:24 +05303177 .ndo_fix_features = cxgb_fix_features,
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003178};
3179
Hariprasad Shenai858aa652016-08-11 21:06:24 +05303180#ifdef CONFIG_PCI_IOV
Hariprasad Shenaie7b48a32016-08-23 11:35:32 +05303181static const struct net_device_ops cxgb4_mgmt_netdev_ops = {
Ganesh Goudarbaf50862018-01-16 16:17:40 +05303182 .ndo_open = cxgb4_mgmt_open,
3183 .ndo_set_vf_mac = cxgb4_mgmt_set_vf_mac,
3184 .ndo_get_vf_config = cxgb4_mgmt_get_vf_config,
3185 .ndo_set_vf_rate = cxgb4_mgmt_set_vf_rate,
3186 .ndo_get_phys_port_id = cxgb4_mgmt_get_phys_port_id,
Hariprasad Shenai78294512016-08-11 21:06:23 +05303187};
Hariprasad Shenaie7b48a32016-08-23 11:35:32 +05303188#endif
Hariprasad Shenai78294512016-08-11 21:06:23 +05303189
Ganesh Goudarbaf50862018-01-16 16:17:40 +05303190static void cxgb4_mgmt_get_drvinfo(struct net_device *dev,
3191 struct ethtool_drvinfo *info)
Hariprasad Shenai78294512016-08-11 21:06:23 +05303192{
3193 struct adapter *adapter = netdev2adap(dev);
3194
3195 strlcpy(info->driver, cxgb4_driver_name, sizeof(info->driver));
3196 strlcpy(info->version, cxgb4_driver_version,
3197 sizeof(info->version));
3198 strlcpy(info->bus_info, pci_name(adapter->pdev),
3199 sizeof(info->bus_info));
3200}
3201
3202static const struct ethtool_ops cxgb4_mgmt_ethtool_ops = {
Ganesh Goudarbaf50862018-01-16 16:17:40 +05303203 .get_drvinfo = cxgb4_mgmt_get_drvinfo,
Hariprasad Shenai78294512016-08-11 21:06:23 +05303204};
3205
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003206void t4_fatal_err(struct adapter *adap)
3207{
Hariprasad Shenai3be06792017-01-13 21:55:26 +05303208 int port;
3209
Guilherme G. Piccoli025d0972017-05-28 23:07:01 -03003210 if (pci_channel_offline(adap->pdev))
3211 return;
3212
Hariprasad Shenai3be06792017-01-13 21:55:26 +05303213 /* Disable the SGE since ULDs are going to free resources that
3214 * could be exposed to the adapter. RDMA MWs for example...
3215 */
3216 t4_shutdown_adapter(adap);
3217 for_each_port(adap, port) {
3218 struct net_device *dev = adap->port[port];
3219
3220 /* If we get here in very early initialization the network
3221 * devices may not have been set up yet.
3222 */
3223 if (!dev)
3224 continue;
3225
3226 netif_tx_stop_all_queues(dev);
3227 netif_carrier_off(dev);
3228 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003229 dev_alert(adap->pdev_dev, "encountered fatal error, adapter stopped\n");
3230}
3231
3232static void setup_memwin(struct adapter *adap)
3233{
Hariprasad Shenaib562fc32015-05-20 17:53:45 +05303234 u32 nic_win_base = t4_get_util_window(adap);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003235
Hariprasad Shenaib562fc32015-05-20 17:53:45 +05303236 t4_setup_memwin(adap, nic_win_base, MEMWIN_NIC);
Vipul Pandya636f9d32012-09-26 02:39:39 +00003237}
3238
3239static void setup_memwin_rdma(struct adapter *adap)
3240{
Dimitris Michailidis1ae970e2010-08-02 13:19:19 +00003241 if (adap->vres.ocq.size) {
Hariprasad Shenai0abfd152014-06-27 19:23:48 +05303242 u32 start;
3243 unsigned int sz_kb;
Dimitris Michailidis1ae970e2010-08-02 13:19:19 +00003244
Hariprasad Shenai0abfd152014-06-27 19:23:48 +05303245 start = t4_read_pcie_cfg4(adap, PCI_BASE_ADDRESS_2);
3246 start &= PCI_BASE_ADDRESS_MEM_MASK;
3247 start += OCQ_WIN_OFFSET(adap->pdev, &adap->vres);
Dimitris Michailidis1ae970e2010-08-02 13:19:19 +00003248 sz_kb = roundup_pow_of_two(adap->vres.ocq.size) >> 10;
3249 t4_write_reg(adap,
Hariprasad Shenaif061de422015-01-05 16:30:44 +05303250 PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_BASE_WIN_A, 3),
3251 start | BIR_V(1) | WINDOW_V(ilog2(sz_kb)));
Dimitris Michailidis1ae970e2010-08-02 13:19:19 +00003252 t4_write_reg(adap,
Hariprasad Shenaif061de422015-01-05 16:30:44 +05303253 PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A, 3),
Dimitris Michailidis1ae970e2010-08-02 13:19:19 +00003254 adap->vres.ocq.start);
3255 t4_read_reg(adap,
Hariprasad Shenaif061de422015-01-05 16:30:44 +05303256 PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A, 3));
Dimitris Michailidis1ae970e2010-08-02 13:19:19 +00003257 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003258}
3259
Dimitris Michailidis02b5fb82010-06-18 10:05:28 +00003260static int adap_init1(struct adapter *adap, struct fw_caps_config_cmd *c)
3261{
3262 u32 v;
3263 int ret;
3264
3265 /* get device capabilities */
3266 memset(c, 0, sizeof(*c));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303267 c->op_to_write = htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
3268 FW_CMD_REQUEST_F | FW_CMD_READ_F);
Naresh Kumar Innace91a922012-11-15 22:41:17 +05303269 c->cfvalid_to_len16 = htonl(FW_LEN16(*c));
Hariprasad Shenaib2612722015-05-27 22:30:24 +05303270 ret = t4_wr_mbox(adap, adap->mbox, c, sizeof(*c), c);
Dimitris Michailidis02b5fb82010-06-18 10:05:28 +00003271 if (ret < 0)
3272 return ret;
3273
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303274 c->op_to_write = htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
3275 FW_CMD_REQUEST_F | FW_CMD_WRITE_F);
Hariprasad Shenaib2612722015-05-27 22:30:24 +05303276 ret = t4_wr_mbox(adap, adap->mbox, c, sizeof(*c), NULL);
Dimitris Michailidis02b5fb82010-06-18 10:05:28 +00003277 if (ret < 0)
3278 return ret;
3279
Hariprasad Shenaib2612722015-05-27 22:30:24 +05303280 ret = t4_config_glbl_rss(adap, adap->pf,
Dimitris Michailidis02b5fb82010-06-18 10:05:28 +00003281 FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL,
Hariprasad Shenaib2e1a3f2014-11-21 12:52:05 +05303282 FW_RSS_GLB_CONFIG_CMD_TNLMAPEN_F |
3283 FW_RSS_GLB_CONFIG_CMD_TNLALLLKP_F);
Dimitris Michailidis02b5fb82010-06-18 10:05:28 +00003284 if (ret < 0)
3285 return ret;
3286
Hariprasad Shenaib2612722015-05-27 22:30:24 +05303287 ret = t4_cfg_pfvf(adap, adap->mbox, adap->pf, 0, adap->sge.egr_sz, 64,
Hariprasad Shenai4b8e27a2015-03-26 10:04:25 +05303288 MAX_INGQ, 0, 0, 4, 0xf, 0xf, 16, FW_CMD_CAP_PF,
3289 FW_CMD_CAP_PF);
Dimitris Michailidis02b5fb82010-06-18 10:05:28 +00003290 if (ret < 0)
3291 return ret;
3292
3293 t4_sge_init(adap);
3294
Dimitris Michailidis02b5fb82010-06-18 10:05:28 +00003295 /* tweak some settings */
Hariprasad Shenai837e4a42015-01-05 16:30:46 +05303296 t4_write_reg(adap, TP_SHIFT_CNT_A, 0x64f8849);
Hariprasad Shenai0d804332015-01-05 16:30:47 +05303297 t4_write_reg(adap, ULP_RX_TDDP_PSZ_A, HPZ0_V(PAGE_SHIFT - 12));
Hariprasad Shenai837e4a42015-01-05 16:30:46 +05303298 t4_write_reg(adap, TP_PIO_ADDR_A, TP_INGRESS_CONFIG_A);
3299 v = t4_read_reg(adap, TP_PIO_DATA_A);
3300 t4_write_reg(adap, TP_PIO_DATA_A, v & ~CSUM_HAS_PSEUDO_HDR_F);
Dimitris Michailidis060e0c72010-08-02 13:19:21 +00003301
Vipul Pandyadca4fae2012-12-10 09:30:53 +00003302 /* first 4 Tx modulation queues point to consecutive Tx channels */
3303 adap->params.tp.tx_modq_map = 0xE4;
Hariprasad Shenai0d804332015-01-05 16:30:47 +05303304 t4_write_reg(adap, TP_TX_MOD_QUEUE_REQ_MAP_A,
3305 TX_MOD_QUEUE_REQ_MAP_V(adap->params.tp.tx_modq_map));
Vipul Pandyadca4fae2012-12-10 09:30:53 +00003306
3307 /* associate each Tx modulation queue with consecutive Tx channels */
3308 v = 0x84218421;
Hariprasad Shenai837e4a42015-01-05 16:30:46 +05303309 t4_write_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A,
Hariprasad Shenai0d804332015-01-05 16:30:47 +05303310 &v, 1, TP_TX_SCHED_HDR_A);
Hariprasad Shenai837e4a42015-01-05 16:30:46 +05303311 t4_write_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A,
Hariprasad Shenai0d804332015-01-05 16:30:47 +05303312 &v, 1, TP_TX_SCHED_FIFO_A);
Hariprasad Shenai837e4a42015-01-05 16:30:46 +05303313 t4_write_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A,
Hariprasad Shenai0d804332015-01-05 16:30:47 +05303314 &v, 1, TP_TX_SCHED_PCMD_A);
Vipul Pandyadca4fae2012-12-10 09:30:53 +00003315
3316#define T4_TX_MODQ_10G_WEIGHT_DEFAULT 16 /* in KB units */
3317 if (is_offload(adap)) {
Hariprasad Shenai0d804332015-01-05 16:30:47 +05303318 t4_write_reg(adap, TP_TX_MOD_QUEUE_WEIGHT0_A,
3319 TX_MODQ_WEIGHT0_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
3320 TX_MODQ_WEIGHT1_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
3321 TX_MODQ_WEIGHT2_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
3322 TX_MODQ_WEIGHT3_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT));
3323 t4_write_reg(adap, TP_TX_MOD_CHANNEL_WEIGHT_A,
3324 TX_MODQ_WEIGHT0_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
3325 TX_MODQ_WEIGHT1_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
3326 TX_MODQ_WEIGHT2_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
3327 TX_MODQ_WEIGHT3_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT));
Vipul Pandyadca4fae2012-12-10 09:30:53 +00003328 }
3329
Dimitris Michailidis060e0c72010-08-02 13:19:21 +00003330 /* get basic stuff going */
Hariprasad Shenaib2612722015-05-27 22:30:24 +05303331 return t4_early_init(adap, adap->pf);
Dimitris Michailidis02b5fb82010-06-18 10:05:28 +00003332}
3333
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003334/*
3335 * Max # of ATIDs. The absolute HW max is 16K but we keep it lower.
3336 */
3337#define MAX_ATIDS 8192U
3338
3339/*
3340 * Phase 0 of initialization: contact FW, obtain config, perform basic init.
Vipul Pandya636f9d32012-09-26 02:39:39 +00003341 *
3342 * If the firmware we're dealing with has Configuration File support, then
3343 * we use that to perform all configuration
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003344 */
Vipul Pandya636f9d32012-09-26 02:39:39 +00003345
3346/*
3347 * Tweak configuration based on module parameters, etc. Most of these have
3348 * defaults assigned to them by Firmware Configuration Files (if we're using
3349 * them) but need to be explicitly set if we're using hard-coded
3350 * initialization. But even in the case of using Firmware Configuration
3351 * Files, we'd like to expose the ability to change these via module
3352 * parameters so these are essentially common tweaks/settings for
3353 * Configuration Files and hard-coded initialization ...
3354 */
3355static int adap_init0_tweaks(struct adapter *adapter)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003356{
Vipul Pandya636f9d32012-09-26 02:39:39 +00003357 /*
3358 * Fix up various Host-Dependent Parameters like Page Size, Cache
3359 * Line Size, etc. The firmware default is for a 4KB Page Size and
3360 * 64B Cache Line Size ...
3361 */
3362 t4_fixup_host_params(adapter, PAGE_SIZE, L1_CACHE_BYTES);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003363
Vipul Pandya636f9d32012-09-26 02:39:39 +00003364 /*
3365 * Process module parameters which affect early initialization.
3366 */
3367 if (rx_dma_offset != 2 && rx_dma_offset != 0) {
3368 dev_err(&adapter->pdev->dev,
3369 "Ignoring illegal rx_dma_offset=%d, using 2\n",
3370 rx_dma_offset);
3371 rx_dma_offset = 2;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003372 }
Hariprasad Shenaif612b812015-01-05 16:30:43 +05303373 t4_set_reg_field(adapter, SGE_CONTROL_A,
3374 PKTSHIFT_V(PKTSHIFT_M),
3375 PKTSHIFT_V(rx_dma_offset));
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003376
Vipul Pandya636f9d32012-09-26 02:39:39 +00003377 /*
3378 * Don't include the "IP Pseudo Header" in CPL_RX_PKT checksums: Linux
3379 * adds the pseudo header itself.
3380 */
Hariprasad Shenai837e4a42015-01-05 16:30:46 +05303381 t4_tp_wr_bits_indirect(adapter, TP_INGRESS_CONFIG_A,
3382 CSUM_HAS_PSEUDO_HDR_F, 0);
Vipul Pandya636f9d32012-09-26 02:39:39 +00003383
3384 return 0;
3385}
3386
Hariprasad Shenai01b69612015-05-22 21:58:21 +05303387/* 10Gb/s-BT PHY Support. chip-external 10Gb/s-BT PHYs are complex chips
3388 * unto themselves and they contain their own firmware to perform their
3389 * tasks ...
3390 */
3391static int phy_aq1202_version(const u8 *phy_fw_data,
3392 size_t phy_fw_size)
3393{
3394 int offset;
3395
3396 /* At offset 0x8 you're looking for the primary image's
3397 * starting offset which is 3 Bytes wide
3398 *
3399 * At offset 0xa of the primary image, you look for the offset
3400 * of the DRAM segment which is 3 Bytes wide.
3401 *
3402 * The FW version is at offset 0x27e of the DRAM and is 2 Bytes
3403 * wide
3404 */
3405 #define be16(__p) (((__p)[0] << 8) | (__p)[1])
3406 #define le16(__p) ((__p)[0] | ((__p)[1] << 8))
3407 #define le24(__p) (le16(__p) | ((__p)[2] << 16))
3408
3409 offset = le24(phy_fw_data + 0x8) << 12;
3410 offset = le24(phy_fw_data + offset + 0xa);
3411 return be16(phy_fw_data + offset + 0x27e);
3412
3413 #undef be16
3414 #undef le16
3415 #undef le24
3416}
3417
3418static struct info_10gbt_phy_fw {
3419 unsigned int phy_fw_id; /* PCI Device ID */
3420 char *phy_fw_file; /* /lib/firmware/ PHY Firmware file */
3421 int (*phy_fw_version)(const u8 *phy_fw_data, size_t phy_fw_size);
3422 int phy_flash; /* Has FLASH for PHY Firmware */
3423} phy_info_array[] = {
3424 {
3425 PHY_AQ1202_DEVICEID,
3426 PHY_AQ1202_FIRMWARE,
3427 phy_aq1202_version,
3428 1,
3429 },
3430 {
3431 PHY_BCM84834_DEVICEID,
3432 PHY_BCM84834_FIRMWARE,
3433 NULL,
3434 0,
3435 },
3436 { 0, NULL, NULL },
3437};
3438
3439static struct info_10gbt_phy_fw *find_phy_info(int devid)
3440{
3441 int i;
3442
3443 for (i = 0; i < ARRAY_SIZE(phy_info_array); i++) {
3444 if (phy_info_array[i].phy_fw_id == devid)
3445 return &phy_info_array[i];
3446 }
3447 return NULL;
3448}
3449
3450/* Handle updating of chip-external 10Gb/s-BT PHY firmware. This needs to
3451 * happen after the FW_RESET_CMD but before the FW_INITIALIZE_CMD. On error
3452 * we return a negative error number. If we transfer new firmware we return 1
3453 * (from t4_load_phy_fw()). If we don't do anything we return 0.
3454 */
3455static int adap_init0_phy(struct adapter *adap)
3456{
3457 const struct firmware *phyf;
3458 int ret;
3459 struct info_10gbt_phy_fw *phy_info;
3460
3461 /* Use the device ID to determine which PHY file to flash.
3462 */
3463 phy_info = find_phy_info(adap->pdev->device);
3464 if (!phy_info) {
3465 dev_warn(adap->pdev_dev,
3466 "No PHY Firmware file found for this PHY\n");
3467 return -EOPNOTSUPP;
3468 }
3469
3470 /* If we have a T4 PHY firmware file under /lib/firmware/cxgb4/, then
3471 * use that. The adapter firmware provides us with a memory buffer
3472 * where we can load a PHY firmware file from the host if we want to
3473 * override the PHY firmware File in flash.
3474 */
3475 ret = request_firmware_direct(&phyf, phy_info->phy_fw_file,
3476 adap->pdev_dev);
3477 if (ret < 0) {
3478 /* For adapters without FLASH attached to PHY for their
3479 * firmware, it's obviously a fatal error if we can't get the
3480 * firmware to the adapter. For adapters with PHY firmware
3481 * FLASH storage, it's worth a warning if we can't find the
3482 * PHY Firmware but we'll neuter the error ...
3483 */
3484 dev_err(adap->pdev_dev, "unable to find PHY Firmware image "
3485 "/lib/firmware/%s, error %d\n",
3486 phy_info->phy_fw_file, -ret);
3487 if (phy_info->phy_flash) {
3488 int cur_phy_fw_ver = 0;
3489
3490 t4_phy_fw_ver(adap, &cur_phy_fw_ver);
3491 dev_warn(adap->pdev_dev, "continuing with, on-adapter "
3492 "FLASH copy, version %#x\n", cur_phy_fw_ver);
3493 ret = 0;
3494 }
3495
3496 return ret;
3497 }
3498
3499 /* Load PHY Firmware onto adapter.
3500 */
3501 ret = t4_load_phy_fw(adap, MEMWIN_NIC, &adap->win0_lock,
3502 phy_info->phy_fw_version,
3503 (u8 *)phyf->data, phyf->size);
3504 if (ret < 0)
3505 dev_err(adap->pdev_dev, "PHY Firmware transfer error %d\n",
3506 -ret);
3507 else if (ret > 0) {
3508 int new_phy_fw_ver = 0;
3509
3510 if (phy_info->phy_fw_version)
3511 new_phy_fw_ver = phy_info->phy_fw_version(phyf->data,
3512 phyf->size);
3513 dev_info(adap->pdev_dev, "Successfully transferred PHY "
3514 "Firmware /lib/firmware/%s, version %#x\n",
3515 phy_info->phy_fw_file, new_phy_fw_ver);
3516 }
3517
3518 release_firmware(phyf);
3519
3520 return ret;
3521}
3522
Vipul Pandya636f9d32012-09-26 02:39:39 +00003523/*
3524 * Attempt to initialize the adapter via a Firmware Configuration File.
3525 */
3526static int adap_init0_config(struct adapter *adapter, int reset)
3527{
3528 struct fw_caps_config_cmd caps_cmd;
3529 const struct firmware *cf;
3530 unsigned long mtype = 0, maddr = 0;
3531 u32 finiver, finicsum, cfcsum;
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303532 int ret;
3533 int config_issued = 0;
Santosh Rastapur0a57a532013-03-14 05:08:49 +00003534 char *fw_config_file, fw_config_file_path[256];
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303535 char *config_name = NULL;
Vipul Pandya636f9d32012-09-26 02:39:39 +00003536
3537 /*
3538 * Reset device if necessary.
3539 */
3540 if (reset) {
3541 ret = t4_fw_reset(adapter, adapter->mbox,
Hariprasad Shenai0d804332015-01-05 16:30:47 +05303542 PIORSTMODE_F | PIORST_F);
Vipul Pandya636f9d32012-09-26 02:39:39 +00003543 if (ret < 0)
3544 goto bye;
3545 }
3546
Hariprasad Shenai01b69612015-05-22 21:58:21 +05303547 /* If this is a 10Gb/s-BT adapter make sure the chip-external
3548 * 10Gb/s-BT PHYs have up-to-date firmware. Note that this step needs
3549 * to be performed after any global adapter RESET above since some
3550 * PHYs only have local RAM copies of the PHY firmware.
3551 */
3552 if (is_10gbt_device(adapter->pdev->device)) {
3553 ret = adap_init0_phy(adapter);
3554 if (ret < 0)
3555 goto bye;
3556 }
Vipul Pandya636f9d32012-09-26 02:39:39 +00003557 /*
3558 * If we have a T4 configuration file under /lib/firmware/cxgb4/,
3559 * then use that. Otherwise, use the configuration file stored
3560 * in the adapter flash ...
3561 */
Hariprasad Shenaid14807d2013-12-03 17:05:56 +05303562 switch (CHELSIO_CHIP_VERSION(adapter->params.chip)) {
Santosh Rastapur0a57a532013-03-14 05:08:49 +00003563 case CHELSIO_T4:
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303564 fw_config_file = FW4_CFNAME;
Santosh Rastapur0a57a532013-03-14 05:08:49 +00003565 break;
3566 case CHELSIO_T5:
3567 fw_config_file = FW5_CFNAME;
3568 break;
Hariprasad Shenai3ccc6cf2015-06-02 13:59:39 +05303569 case CHELSIO_T6:
3570 fw_config_file = FW6_CFNAME;
3571 break;
Santosh Rastapur0a57a532013-03-14 05:08:49 +00003572 default:
3573 dev_err(adapter->pdev_dev, "Device %d is not supported\n",
3574 adapter->pdev->device);
3575 ret = -EINVAL;
3576 goto bye;
3577 }
3578
3579 ret = request_firmware(&cf, fw_config_file, adapter->pdev_dev);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003580 if (ret < 0) {
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303581 config_name = "On FLASH";
Vipul Pandya636f9d32012-09-26 02:39:39 +00003582 mtype = FW_MEMTYPE_CF_FLASH;
3583 maddr = t4_flash_cfg_addr(adapter);
3584 } else {
3585 u32 params[7], val[7];
3586
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303587 sprintf(fw_config_file_path,
3588 "/lib/firmware/%s", fw_config_file);
3589 config_name = fw_config_file_path;
3590
Vipul Pandya636f9d32012-09-26 02:39:39 +00003591 if (cf->size >= FLASH_CFG_MAX_SIZE)
3592 ret = -ENOMEM;
3593 else {
Hariprasad Shenai51678652014-11-21 12:52:02 +05303594 params[0] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
3595 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_CF));
Vipul Pandya636f9d32012-09-26 02:39:39 +00003596 ret = t4_query_params(adapter, adapter->mbox,
Hariprasad Shenaib2612722015-05-27 22:30:24 +05303597 adapter->pf, 0, 1, params, val);
Vipul Pandya636f9d32012-09-26 02:39:39 +00003598 if (ret == 0) {
3599 /*
Hariprasad Shenaifc5ab022014-06-27 19:23:49 +05303600 * For t4_memory_rw() below addresses and
Vipul Pandya636f9d32012-09-26 02:39:39 +00003601 * sizes have to be in terms of multiples of 4
3602 * bytes. So, if the Configuration File isn't
3603 * a multiple of 4 bytes in length we'll have
3604 * to write that out separately since we can't
3605 * guarantee that the bytes following the
3606 * residual byte in the buffer returned by
3607 * request_firmware() are zeroed out ...
3608 */
3609 size_t resid = cf->size & 0x3;
3610 size_t size = cf->size & ~0x3;
3611 __be32 *data = (__be32 *)cf->data;
3612
Hariprasad Shenai51678652014-11-21 12:52:02 +05303613 mtype = FW_PARAMS_PARAM_Y_G(val[0]);
3614 maddr = FW_PARAMS_PARAM_Z_G(val[0]) << 16;
Vipul Pandya636f9d32012-09-26 02:39:39 +00003615
Hariprasad Shenaifc5ab022014-06-27 19:23:49 +05303616 spin_lock(&adapter->win0_lock);
3617 ret = t4_memory_rw(adapter, 0, mtype, maddr,
3618 size, data, T4_MEMORY_WRITE);
Vipul Pandya636f9d32012-09-26 02:39:39 +00003619 if (ret == 0 && resid != 0) {
3620 union {
3621 __be32 word;
3622 char buf[4];
3623 } last;
3624 int i;
3625
3626 last.word = data[size >> 2];
3627 for (i = resid; i < 4; i++)
3628 last.buf[i] = 0;
Hariprasad Shenaifc5ab022014-06-27 19:23:49 +05303629 ret = t4_memory_rw(adapter, 0, mtype,
3630 maddr + size,
3631 4, &last.word,
3632 T4_MEMORY_WRITE);
Vipul Pandya636f9d32012-09-26 02:39:39 +00003633 }
Hariprasad Shenaifc5ab022014-06-27 19:23:49 +05303634 spin_unlock(&adapter->win0_lock);
Vipul Pandya636f9d32012-09-26 02:39:39 +00003635 }
3636 }
3637
3638 release_firmware(cf);
3639 if (ret)
3640 goto bye;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003641 }
3642
Vipul Pandya636f9d32012-09-26 02:39:39 +00003643 /*
3644 * Issue a Capability Configuration command to the firmware to get it
3645 * to parse the Configuration File. We don't use t4_fw_config_file()
3646 * because we want the ability to modify various features after we've
3647 * processed the configuration file ...
3648 */
3649 memset(&caps_cmd, 0, sizeof(caps_cmd));
3650 caps_cmd.op_to_write =
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303651 htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
3652 FW_CMD_REQUEST_F |
3653 FW_CMD_READ_F);
Naresh Kumar Innace91a922012-11-15 22:41:17 +05303654 caps_cmd.cfvalid_to_len16 =
Hariprasad Shenai51678652014-11-21 12:52:02 +05303655 htonl(FW_CAPS_CONFIG_CMD_CFVALID_F |
3656 FW_CAPS_CONFIG_CMD_MEMTYPE_CF_V(mtype) |
3657 FW_CAPS_CONFIG_CMD_MEMADDR64K_CF_V(maddr >> 16) |
Vipul Pandya636f9d32012-09-26 02:39:39 +00003658 FW_LEN16(caps_cmd));
3659 ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd, sizeof(caps_cmd),
3660 &caps_cmd);
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303661
3662 /* If the CAPS_CONFIG failed with an ENOENT (for a Firmware
3663 * Configuration File in FLASH), our last gasp effort is to use the
3664 * Firmware Configuration File which is embedded in the firmware. A
3665 * very few early versions of the firmware didn't have one embedded
3666 * but we can ignore those.
3667 */
3668 if (ret == -ENOENT) {
3669 memset(&caps_cmd, 0, sizeof(caps_cmd));
3670 caps_cmd.op_to_write =
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303671 htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
3672 FW_CMD_REQUEST_F |
3673 FW_CMD_READ_F);
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303674 caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd));
3675 ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd,
3676 sizeof(caps_cmd), &caps_cmd);
3677 config_name = "Firmware Default";
3678 }
3679
3680 config_issued = 1;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003681 if (ret < 0)
3682 goto bye;
3683
Vipul Pandya636f9d32012-09-26 02:39:39 +00003684 finiver = ntohl(caps_cmd.finiver);
3685 finicsum = ntohl(caps_cmd.finicsum);
3686 cfcsum = ntohl(caps_cmd.cfcsum);
3687 if (finicsum != cfcsum)
3688 dev_warn(adapter->pdev_dev, "Configuration File checksum "\
3689 "mismatch: [fini] csum=%#x, computed csum=%#x\n",
3690 finicsum, cfcsum);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003691
Vipul Pandya636f9d32012-09-26 02:39:39 +00003692 /*
Vipul Pandya636f9d32012-09-26 02:39:39 +00003693 * And now tell the firmware to use the configuration we just loaded.
3694 */
3695 caps_cmd.op_to_write =
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303696 htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
3697 FW_CMD_REQUEST_F |
3698 FW_CMD_WRITE_F);
Naresh Kumar Innace91a922012-11-15 22:41:17 +05303699 caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd));
Vipul Pandya636f9d32012-09-26 02:39:39 +00003700 ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd, sizeof(caps_cmd),
3701 NULL);
Dimitris Michailidisa0881ca2010-06-18 10:05:34 +00003702 if (ret < 0)
3703 goto bye;
3704
Vipul Pandya636f9d32012-09-26 02:39:39 +00003705 /*
3706 * Tweak configuration based on system architecture, module
3707 * parameters, etc.
3708 */
3709 ret = adap_init0_tweaks(adapter);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003710 if (ret < 0)
3711 goto bye;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003712
Vipul Pandya636f9d32012-09-26 02:39:39 +00003713 /*
3714 * And finally tell the firmware to initialize itself using the
3715 * parameters from the Configuration File.
3716 */
3717 ret = t4_fw_initialize(adapter, adapter->mbox);
3718 if (ret < 0)
3719 goto bye;
3720
Hariprasad Shenai06640312015-01-13 15:19:25 +05303721 /* Emit Firmware Configuration File information and return
3722 * successfully.
Vipul Pandya636f9d32012-09-26 02:39:39 +00003723 */
Vipul Pandya636f9d32012-09-26 02:39:39 +00003724 dev_info(adapter->pdev_dev, "Successfully configured using Firmware "\
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303725 "Configuration File \"%s\", version %#x, computed checksum %#x\n",
3726 config_name, finiver, cfcsum);
Vipul Pandya636f9d32012-09-26 02:39:39 +00003727 return 0;
3728
3729 /*
3730 * Something bad happened. Return the error ... (If the "error"
3731 * is that there's no Configuration File on the adapter we don't
3732 * want to issue a warning since this is fairly common.)
3733 */
3734bye:
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303735 if (config_issued && ret != -ENOENT)
3736 dev_warn(adapter->pdev_dev, "\"%s\" configuration file error %d\n",
3737 config_name, -ret);
Vipul Pandya636f9d32012-09-26 02:39:39 +00003738 return ret;
3739}
3740
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303741static struct fw_info fw_info_array[] = {
3742 {
3743 .chip = CHELSIO_T4,
3744 .fs_name = FW4_CFNAME,
3745 .fw_mod_name = FW4_FNAME,
3746 .fw_hdr = {
3747 .chip = FW_HDR_CHIP_T4,
3748 .fw_ver = __cpu_to_be32(FW_VERSION(T4)),
3749 .intfver_nic = FW_INTFVER(T4, NIC),
3750 .intfver_vnic = FW_INTFVER(T4, VNIC),
3751 .intfver_ri = FW_INTFVER(T4, RI),
3752 .intfver_iscsi = FW_INTFVER(T4, ISCSI),
3753 .intfver_fcoe = FW_INTFVER(T4, FCOE),
3754 },
3755 }, {
3756 .chip = CHELSIO_T5,
3757 .fs_name = FW5_CFNAME,
3758 .fw_mod_name = FW5_FNAME,
3759 .fw_hdr = {
3760 .chip = FW_HDR_CHIP_T5,
3761 .fw_ver = __cpu_to_be32(FW_VERSION(T5)),
3762 .intfver_nic = FW_INTFVER(T5, NIC),
3763 .intfver_vnic = FW_INTFVER(T5, VNIC),
3764 .intfver_ri = FW_INTFVER(T5, RI),
3765 .intfver_iscsi = FW_INTFVER(T5, ISCSI),
3766 .intfver_fcoe = FW_INTFVER(T5, FCOE),
3767 },
Hariprasad Shenai3ccc6cf2015-06-02 13:59:39 +05303768 }, {
3769 .chip = CHELSIO_T6,
3770 .fs_name = FW6_CFNAME,
3771 .fw_mod_name = FW6_FNAME,
3772 .fw_hdr = {
3773 .chip = FW_HDR_CHIP_T6,
3774 .fw_ver = __cpu_to_be32(FW_VERSION(T6)),
3775 .intfver_nic = FW_INTFVER(T6, NIC),
3776 .intfver_vnic = FW_INTFVER(T6, VNIC),
3777 .intfver_ofld = FW_INTFVER(T6, OFLD),
3778 .intfver_ri = FW_INTFVER(T6, RI),
3779 .intfver_iscsipdu = FW_INTFVER(T6, ISCSIPDU),
3780 .intfver_iscsi = FW_INTFVER(T6, ISCSI),
3781 .intfver_fcoepdu = FW_INTFVER(T6, FCOEPDU),
3782 .intfver_fcoe = FW_INTFVER(T6, FCOE),
3783 },
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303784 }
Hariprasad Shenai3ccc6cf2015-06-02 13:59:39 +05303785
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303786};
3787
3788static struct fw_info *find_fw_info(int chip)
3789{
3790 int i;
3791
3792 for (i = 0; i < ARRAY_SIZE(fw_info_array); i++) {
3793 if (fw_info_array[i].chip == chip)
3794 return &fw_info_array[i];
3795 }
3796 return NULL;
3797}
3798
Vipul Pandya13ee15d2012-09-26 02:39:40 +00003799/*
Vipul Pandya636f9d32012-09-26 02:39:39 +00003800 * Phase 0 of initialization: contact FW, obtain config, perform basic init.
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003801 */
3802static int adap_init0(struct adapter *adap)
3803{
3804 int ret;
3805 u32 v, port_vec;
3806 enum dev_state state;
3807 u32 params[7], val[7];
Vipul Pandya9a4da2c2012-10-19 02:09:53 +00003808 struct fw_caps_config_cmd caps_cmd;
Kumar Sanghvidcf7b6f2013-12-18 16:38:23 +05303809 int reset = 1;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003810
Hariprasad Shenaiae469b62015-04-01 21:41:16 +05303811 /* Grab Firmware Device Log parameters as early as possible so we have
3812 * access to it for debugging, etc.
3813 */
3814 ret = t4_init_devlog_params(adap);
3815 if (ret < 0)
3816 return ret;
3817
Hariprasad Shenai666224d2014-12-11 11:11:43 +05303818 /* Contact FW, advertising Master capability */
Hariprasad Shenaic5a8c0f2016-06-14 14:39:30 +05303819 ret = t4_fw_hello(adap, adap->mbox, adap->mbox,
3820 is_kdump_kernel() ? MASTER_MUST : MASTER_MAY, &state);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003821 if (ret < 0) {
3822 dev_err(adap->pdev_dev, "could not connect to FW, error %d\n",
3823 ret);
3824 return ret;
3825 }
Vipul Pandya636f9d32012-09-26 02:39:39 +00003826 if (ret == adap->mbox)
3827 adap->flags |= MASTER_PF;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003828
Vipul Pandya636f9d32012-09-26 02:39:39 +00003829 /*
3830 * If we're the Master PF Driver and the device is uninitialized,
3831 * then let's consider upgrading the firmware ... (We always want
3832 * to check the firmware version number in order to A. get it for
3833 * later reporting and B. to warn if the currently loaded firmware
3834 * is excessively mismatched relative to the driver.)
3835 */
Hariprasad Shenai0de72732016-04-26 20:10:22 +05303836
Ganesh Goudar760446f2017-07-20 18:28:48 +05303837 t4_get_version_info(adap);
Hariprasad Shenaia69265e2015-08-28 11:17:12 +05303838 ret = t4_check_fw_version(adap);
3839 /* If firmware is too old (not supported by driver) force an update. */
Hariprasad Shenai21d11bd2015-10-08 10:08:23 +05303840 if (ret)
Hariprasad Shenaia69265e2015-08-28 11:17:12 +05303841 state = DEV_STATE_UNINIT;
Vipul Pandya636f9d32012-09-26 02:39:39 +00003842 if ((adap->flags & MASTER_PF) && state != DEV_STATE_INIT) {
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303843 struct fw_info *fw_info;
3844 struct fw_hdr *card_fw;
3845 const struct firmware *fw;
3846 const u8 *fw_data = NULL;
3847 unsigned int fw_size = 0;
3848
3849 /* This is the firmware whose headers the driver was compiled
3850 * against
3851 */
3852 fw_info = find_fw_info(CHELSIO_CHIP_VERSION(adap->params.chip));
3853 if (fw_info == NULL) {
3854 dev_err(adap->pdev_dev,
3855 "unable to get firmware info for chip %d.\n",
3856 CHELSIO_CHIP_VERSION(adap->params.chip));
3857 return -EINVAL;
Vipul Pandya636f9d32012-09-26 02:39:39 +00003858 }
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303859
3860 /* allocate memory to read the header of the firmware on the
3861 * card
3862 */
Michal Hocko752ade62017-05-08 15:57:27 -07003863 card_fw = kvzalloc(sizeof(*card_fw), GFP_KERNEL);
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303864
3865 /* Get FW from from /lib/firmware/ */
3866 ret = request_firmware(&fw, fw_info->fw_mod_name,
3867 adap->pdev_dev);
3868 if (ret < 0) {
3869 dev_err(adap->pdev_dev,
3870 "unable to load firmware image %s, error %d\n",
3871 fw_info->fw_mod_name, ret);
3872 } else {
3873 fw_data = fw->data;
3874 fw_size = fw->size;
3875 }
3876
3877 /* upgrade FW logic */
3878 ret = t4_prep_fw(adap, fw_info, fw_data, fw_size, card_fw,
3879 state, &reset);
3880
3881 /* Cleaning up */
Markus Elfring0b5b6be2015-02-04 11:28:43 +01003882 release_firmware(fw);
Michal Hocko752ade62017-05-08 15:57:27 -07003883 kvfree(card_fw);
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303884
Vipul Pandya636f9d32012-09-26 02:39:39 +00003885 if (ret < 0)
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303886 goto bye;
Vipul Pandya636f9d32012-09-26 02:39:39 +00003887 }
3888
3889 /*
3890 * Grab VPD parameters. This should be done after we establish a
3891 * connection to the firmware since some of the VPD parameters
3892 * (notably the Core Clock frequency) are retrieved via requests to
3893 * the firmware. On the other hand, we need these fairly early on
3894 * so we do this right after getting ahold of the firmware.
3895 */
Hariprasad Shenai098ef6c2015-06-05 14:24:50 +05303896 ret = t4_get_vpd_params(adap, &adap->params.vpd);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003897 if (ret < 0)
3898 goto bye;
3899
Vipul Pandya636f9d32012-09-26 02:39:39 +00003900 /*
Vipul Pandya13ee15d2012-09-26 02:39:40 +00003901 * Find out what ports are available to us. Note that we need to do
3902 * this before calling adap_init0_no_config() since it needs nports
3903 * and portvec ...
Vipul Pandya636f9d32012-09-26 02:39:39 +00003904 */
3905 v =
Hariprasad Shenai51678652014-11-21 12:52:02 +05303906 FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
3907 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_PORTVEC);
Hariprasad Shenaib2612722015-05-27 22:30:24 +05303908 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1, &v, &port_vec);
Vipul Pandya636f9d32012-09-26 02:39:39 +00003909 if (ret < 0)
3910 goto bye;
3911
3912 adap->params.nports = hweight32(port_vec);
3913 adap->params.portvec = port_vec;
3914
Hariprasad Shenai06640312015-01-13 15:19:25 +05303915 /* If the firmware is initialized already, emit a simply note to that
3916 * effect. Otherwise, it's time to try initializing the adapter.
Vipul Pandya636f9d32012-09-26 02:39:39 +00003917 */
3918 if (state == DEV_STATE_INIT) {
3919 dev_info(adap->pdev_dev, "Coming up as %s: "\
3920 "Adapter already initialized\n",
3921 adap->flags & MASTER_PF ? "MASTER" : "SLAVE");
Vipul Pandya636f9d32012-09-26 02:39:39 +00003922 } else {
3923 dev_info(adap->pdev_dev, "Coming up as MASTER: "\
3924 "Initializing adapter\n");
Hariprasad Shenai06640312015-01-13 15:19:25 +05303925
3926 /* Find out whether we're dealing with a version of the
3927 * firmware which has configuration file support.
Vipul Pandya636f9d32012-09-26 02:39:39 +00003928 */
Hariprasad Shenai06640312015-01-13 15:19:25 +05303929 params[0] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
3930 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_CF));
Hariprasad Shenaib2612722015-05-27 22:30:24 +05303931 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1,
Hariprasad Shenai06640312015-01-13 15:19:25 +05303932 params, val);
Vipul Pandya636f9d32012-09-26 02:39:39 +00003933
Hariprasad Shenai06640312015-01-13 15:19:25 +05303934 /* If the firmware doesn't support Configuration Files,
3935 * return an error.
3936 */
3937 if (ret < 0) {
3938 dev_err(adap->pdev_dev, "firmware doesn't support "
3939 "Firmware Configuration Files\n");
3940 goto bye;
3941 }
Vipul Pandya13ee15d2012-09-26 02:39:40 +00003942
Hariprasad Shenai06640312015-01-13 15:19:25 +05303943 /* The firmware provides us with a memory buffer where we can
3944 * load a Configuration File from the host if we want to
3945 * override the Configuration File in flash.
3946 */
3947 ret = adap_init0_config(adap, reset);
3948 if (ret == -ENOENT) {
3949 dev_err(adap->pdev_dev, "no Configuration File "
3950 "present on adapter.\n");
3951 goto bye;
Vipul Pandya636f9d32012-09-26 02:39:39 +00003952 }
3953 if (ret < 0) {
Hariprasad Shenai06640312015-01-13 15:19:25 +05303954 dev_err(adap->pdev_dev, "could not initialize "
3955 "adapter, error %d\n", -ret);
Vipul Pandya636f9d32012-09-26 02:39:39 +00003956 goto bye;
3957 }
3958 }
3959
Hariprasad Shenai06640312015-01-13 15:19:25 +05303960 /* Give the SGE code a chance to pull in anything that it needs ...
3961 * Note that this must be called after we retrieve our VPD parameters
3962 * in order to know how to convert core ticks to seconds, etc.
Vipul Pandya636f9d32012-09-26 02:39:39 +00003963 */
Hariprasad Shenai06640312015-01-13 15:19:25 +05303964 ret = t4_sge_init(adap);
3965 if (ret < 0)
3966 goto bye;
Vipul Pandya636f9d32012-09-26 02:39:39 +00003967
Vipul Pandya9a4da2c2012-10-19 02:09:53 +00003968 if (is_bypass_device(adap->pdev->device))
3969 adap->params.bypass = 1;
3970
Vipul Pandya636f9d32012-09-26 02:39:39 +00003971 /*
3972 * Grab some of our basic fundamental operating parameters.
3973 */
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003974#define FW_PARAM_DEV(param) \
Hariprasad Shenai51678652014-11-21 12:52:02 +05303975 (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) | \
3976 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_##param))
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003977
3978#define FW_PARAM_PFVF(param) \
Hariprasad Shenai51678652014-11-21 12:52:02 +05303979 FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_PFVF) | \
3980 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_PFVF_##param)| \
3981 FW_PARAMS_PARAM_Y_V(0) | \
3982 FW_PARAMS_PARAM_Z_V(0)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003983
Vipul Pandya636f9d32012-09-26 02:39:39 +00003984 params[0] = FW_PARAM_PFVF(EQ_START);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003985 params[1] = FW_PARAM_PFVF(L2T_START);
3986 params[2] = FW_PARAM_PFVF(L2T_END);
3987 params[3] = FW_PARAM_PFVF(FILTER_START);
3988 params[4] = FW_PARAM_PFVF(FILTER_END);
3989 params[5] = FW_PARAM_PFVF(IQFLINT_START);
Hariprasad Shenaib2612722015-05-27 22:30:24 +05303990 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 6, params, val);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003991 if (ret < 0)
3992 goto bye;
Vipul Pandya636f9d32012-09-26 02:39:39 +00003993 adap->sge.egr_start = val[0];
3994 adap->l2t_start = val[1];
3995 adap->l2t_end = val[2];
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003996 adap->tids.ftid_base = val[3];
3997 adap->tids.nftids = val[4] - val[3] + 1;
3998 adap->sge.ingr_start = val[5];
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003999
Hariprasad Shenai4b8e27a2015-03-26 10:04:25 +05304000 /* qids (ingress/egress) returned from firmware can be anywhere
4001 * in the range from EQ(IQFLINT)_START to EQ(IQFLINT)_END.
4002 * Hence driver needs to allocate memory for this range to
4003 * store the queue info. Get the highest IQFLINT/EQ index returned
4004 * in FW_EQ_*_CMD.alloc command.
4005 */
4006 params[0] = FW_PARAM_PFVF(EQ_END);
4007 params[1] = FW_PARAM_PFVF(IQFLINT_END);
Hariprasad Shenaib2612722015-05-27 22:30:24 +05304008 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params, val);
Hariprasad Shenai4b8e27a2015-03-26 10:04:25 +05304009 if (ret < 0)
4010 goto bye;
4011 adap->sge.egr_sz = val[0] - adap->sge.egr_start + 1;
4012 adap->sge.ingr_sz = val[1] - adap->sge.ingr_start + 1;
4013
4014 adap->sge.egr_map = kcalloc(adap->sge.egr_sz,
4015 sizeof(*adap->sge.egr_map), GFP_KERNEL);
4016 if (!adap->sge.egr_map) {
4017 ret = -ENOMEM;
4018 goto bye;
4019 }
4020
4021 adap->sge.ingr_map = kcalloc(adap->sge.ingr_sz,
4022 sizeof(*adap->sge.ingr_map), GFP_KERNEL);
4023 if (!adap->sge.ingr_map) {
4024 ret = -ENOMEM;
4025 goto bye;
4026 }
4027
4028 /* Allocate the memory for the vaious egress queue bitmaps
Hariprasad Shenai5b377d12015-05-27 22:30:23 +05304029 * ie starving_fl, txq_maperr and blocked_fl.
Hariprasad Shenai4b8e27a2015-03-26 10:04:25 +05304030 */
4031 adap->sge.starving_fl = kcalloc(BITS_TO_LONGS(adap->sge.egr_sz),
4032 sizeof(long), GFP_KERNEL);
4033 if (!adap->sge.starving_fl) {
4034 ret = -ENOMEM;
4035 goto bye;
4036 }
4037
4038 adap->sge.txq_maperr = kcalloc(BITS_TO_LONGS(adap->sge.egr_sz),
4039 sizeof(long), GFP_KERNEL);
4040 if (!adap->sge.txq_maperr) {
4041 ret = -ENOMEM;
4042 goto bye;
4043 }
4044
Hariprasad Shenai5b377d12015-05-27 22:30:23 +05304045#ifdef CONFIG_DEBUG_FS
4046 adap->sge.blocked_fl = kcalloc(BITS_TO_LONGS(adap->sge.egr_sz),
4047 sizeof(long), GFP_KERNEL);
4048 if (!adap->sge.blocked_fl) {
4049 ret = -ENOMEM;
4050 goto bye;
4051 }
4052#endif
4053
Anish Bhattb5a02f52015-01-14 15:17:34 -08004054 params[0] = FW_PARAM_PFVF(CLIP_START);
4055 params[1] = FW_PARAM_PFVF(CLIP_END);
Hariprasad Shenaib2612722015-05-27 22:30:24 +05304056 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params, val);
Anish Bhattb5a02f52015-01-14 15:17:34 -08004057 if (ret < 0)
4058 goto bye;
4059 adap->clipt_start = val[0];
4060 adap->clipt_end = val[1];
4061
Rahul Lakkireddyb72a32d2016-08-22 16:29:06 +05304062 /* We don't yet have a PARAMs calls to retrieve the number of Traffic
4063 * Classes supported by the hardware/firmware so we hard code it here
4064 * for now.
4065 */
4066 adap->params.nsched_cls = is_t4(adap->params.chip) ? 15 : 16;
4067
Vipul Pandya636f9d32012-09-26 02:39:39 +00004068 /* query params related to active filter region */
4069 params[0] = FW_PARAM_PFVF(ACTIVE_FILTER_START);
4070 params[1] = FW_PARAM_PFVF(ACTIVE_FILTER_END);
Hariprasad Shenaib2612722015-05-27 22:30:24 +05304071 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params, val);
Vipul Pandya636f9d32012-09-26 02:39:39 +00004072 /* If Active filter size is set we enable establishing
4073 * offload connection through firmware work request
4074 */
4075 if ((val[0] != val[1]) && (ret >= 0)) {
4076 adap->flags |= FW_OFLD_CONN;
4077 adap->tids.aftid_base = val[0];
4078 adap->tids.aftid_end = val[1];
4079 }
4080
Vipul Pandyab407a4a2013-04-29 04:04:40 +00004081 /* If we're running on newer firmware, let it know that we're
4082 * prepared to deal with encapsulated CPL messages. Older
4083 * firmware won't understand this and we'll just get
4084 * unencapsulated messages ...
4085 */
4086 params[0] = FW_PARAM_PFVF(CPLFW4MSG_ENCAP);
4087 val[0] = 1;
Hariprasad Shenaib2612722015-05-27 22:30:24 +05304088 (void)t4_set_params(adap, adap->mbox, adap->pf, 0, 1, params, val);
Vipul Pandyab407a4a2013-04-29 04:04:40 +00004089
Vipul Pandya636f9d32012-09-26 02:39:39 +00004090 /*
Kumar Sanghvi1ac0f092014-02-18 17:56:12 +05304091 * Find out whether we're allowed to use the T5+ ULPTX MEMWRITE DSGL
4092 * capability. Earlier versions of the firmware didn't have the
4093 * ULPTX_MEMWRITE_DSGL so we'll interpret a query failure as no
4094 * permission to use ULPTX MEMWRITE DSGL.
4095 */
4096 if (is_t4(adap->params.chip)) {
4097 adap->params.ulptx_memwrite_dsgl = false;
4098 } else {
4099 params[0] = FW_PARAM_DEV(ULPTX_MEMWRITE_DSGL);
Hariprasad Shenaib2612722015-05-27 22:30:24 +05304100 ret = t4_query_params(adap, adap->mbox, adap->pf, 0,
Kumar Sanghvi1ac0f092014-02-18 17:56:12 +05304101 1, params, val);
4102 adap->params.ulptx_memwrite_dsgl = (ret == 0 && val[0] != 0);
4103 }
4104
Steve Wise086de572016-09-16 07:54:49 -07004105 /* See if FW supports FW_RI_FR_NSMR_TPTE_WR work request */
4106 params[0] = FW_PARAM_DEV(RI_FR_NSMR_TPTE_WR);
4107 ret = t4_query_params(adap, adap->mbox, adap->pf, 0,
4108 1, params, val);
4109 adap->params.fr_nsmr_tpte_wr_support = (ret == 0 && val[0] != 0);
4110
Kumar Sanghvi0ff90992017-10-18 20:49:13 +05304111 /* See if FW supports FW_FILTER2 work request */
4112 if (is_t4(adap->params.chip)) {
4113 adap->params.filter2_wr_support = 0;
4114 } else {
4115 params[0] = FW_PARAM_DEV(FILTER2_WR);
4116 ret = t4_query_params(adap, adap->mbox, adap->pf, 0,
4117 1, params, val);
4118 adap->params.filter2_wr_support = (ret == 0 && val[0] != 0);
4119 }
4120
Kumar Sanghvi1ac0f092014-02-18 17:56:12 +05304121 /*
Vipul Pandya636f9d32012-09-26 02:39:39 +00004122 * Get device capabilities so we can determine what resources we need
4123 * to manage.
4124 */
4125 memset(&caps_cmd, 0, sizeof(caps_cmd));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05304126 caps_cmd.op_to_write = htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
4127 FW_CMD_REQUEST_F | FW_CMD_READ_F);
Naresh Kumar Innace91a922012-11-15 22:41:17 +05304128 caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd));
Vipul Pandya636f9d32012-09-26 02:39:39 +00004129 ret = t4_wr_mbox(adap, adap->mbox, &caps_cmd, sizeof(caps_cmd),
4130 &caps_cmd);
4131 if (ret < 0)
4132 goto bye;
4133
Kumar Sanghvi5c312542017-11-01 08:53:00 +05304134 if (caps_cmd.ofldcaps ||
4135 (caps_cmd.niccaps & htons(FW_CAPS_CONFIG_NIC_HASHFILTER))) {
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004136 /* query offload-related parameters */
4137 params[0] = FW_PARAM_DEV(NTID);
4138 params[1] = FW_PARAM_PFVF(SERVER_START);
4139 params[2] = FW_PARAM_PFVF(SERVER_END);
4140 params[3] = FW_PARAM_PFVF(TDDP_START);
4141 params[4] = FW_PARAM_PFVF(TDDP_END);
4142 params[5] = FW_PARAM_DEV(FLOWC_BUFFIFO_SZ);
Hariprasad Shenaib2612722015-05-27 22:30:24 +05304143 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 6,
Vipul Pandya636f9d32012-09-26 02:39:39 +00004144 params, val);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004145 if (ret < 0)
4146 goto bye;
4147 adap->tids.ntids = val[0];
4148 adap->tids.natids = min(adap->tids.ntids / 2, MAX_ATIDS);
4149 adap->tids.stid_base = val[1];
4150 adap->tids.nstids = val[2] - val[1] + 1;
Vipul Pandya636f9d32012-09-26 02:39:39 +00004151 /*
Joe Perchesdbedd442015-03-06 20:49:12 -08004152 * Setup server filter region. Divide the available filter
Vipul Pandya636f9d32012-09-26 02:39:39 +00004153 * region into two parts. Regular filters get 1/3rd and server
4154 * filters get 2/3rd part. This is only enabled if workarond
4155 * path is enabled.
4156 * 1. For regular filters.
4157 * 2. Server filter: This are special filters which are used
4158 * to redirect SYN packets to offload queue.
4159 */
4160 if (adap->flags & FW_OFLD_CONN && !is_bypass(adap)) {
4161 adap->tids.sftid_base = adap->tids.ftid_base +
4162 DIV_ROUND_UP(adap->tids.nftids, 3);
4163 adap->tids.nsftids = adap->tids.nftids -
4164 DIV_ROUND_UP(adap->tids.nftids, 3);
4165 adap->tids.nftids = adap->tids.sftid_base -
4166 adap->tids.ftid_base;
4167 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004168 adap->vres.ddp.start = val[3];
4169 adap->vres.ddp.size = val[4] - val[3] + 1;
4170 adap->params.ofldq_wr_cred = val[5];
Vipul Pandya636f9d32012-09-26 02:39:39 +00004171
Kumar Sanghvi5c312542017-11-01 08:53:00 +05304172 if (caps_cmd.niccaps & htons(FW_CAPS_CONFIG_NIC_HASHFILTER)) {
4173 if (init_hash_filter(adap) < 0)
4174 goto bye;
4175 } else {
4176 adap->params.offload = 1;
4177 adap->num_ofld_uld += 1;
4178 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004179 }
Vipul Pandya636f9d32012-09-26 02:39:39 +00004180 if (caps_cmd.rdmacaps) {
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004181 params[0] = FW_PARAM_PFVF(STAG_START);
4182 params[1] = FW_PARAM_PFVF(STAG_END);
4183 params[2] = FW_PARAM_PFVF(RQ_START);
4184 params[3] = FW_PARAM_PFVF(RQ_END);
4185 params[4] = FW_PARAM_PFVF(PBL_START);
4186 params[5] = FW_PARAM_PFVF(PBL_END);
Hariprasad Shenaib2612722015-05-27 22:30:24 +05304187 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 6,
Vipul Pandya636f9d32012-09-26 02:39:39 +00004188 params, val);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004189 if (ret < 0)
4190 goto bye;
4191 adap->vres.stag.start = val[0];
4192 adap->vres.stag.size = val[1] - val[0] + 1;
4193 adap->vres.rq.start = val[2];
4194 adap->vres.rq.size = val[3] - val[2] + 1;
4195 adap->vres.pbl.start = val[4];
4196 adap->vres.pbl.size = val[5] - val[4] + 1;
Dimitris Michailidisa0881ca2010-06-18 10:05:34 +00004197
4198 params[0] = FW_PARAM_PFVF(SQRQ_START);
4199 params[1] = FW_PARAM_PFVF(SQRQ_END);
4200 params[2] = FW_PARAM_PFVF(CQ_START);
4201 params[3] = FW_PARAM_PFVF(CQ_END);
Dimitris Michailidis1ae970e2010-08-02 13:19:19 +00004202 params[4] = FW_PARAM_PFVF(OCQ_START);
4203 params[5] = FW_PARAM_PFVF(OCQ_END);
Hariprasad Shenaib2612722015-05-27 22:30:24 +05304204 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 6, params,
Hariprasad Shenai5c937dd2014-09-01 19:55:00 +05304205 val);
Dimitris Michailidisa0881ca2010-06-18 10:05:34 +00004206 if (ret < 0)
4207 goto bye;
4208 adap->vres.qp.start = val[0];
4209 adap->vres.qp.size = val[1] - val[0] + 1;
4210 adap->vres.cq.start = val[2];
4211 adap->vres.cq.size = val[3] - val[2] + 1;
Dimitris Michailidis1ae970e2010-08-02 13:19:19 +00004212 adap->vres.ocq.start = val[4];
4213 adap->vres.ocq.size = val[5] - val[4] + 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05304214
4215 params[0] = FW_PARAM_DEV(MAXORDIRD_QP);
4216 params[1] = FW_PARAM_DEV(MAXIRD_ADAPTER);
Hariprasad Shenaib2612722015-05-27 22:30:24 +05304217 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params,
Hariprasad Shenai5c937dd2014-09-01 19:55:00 +05304218 val);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05304219 if (ret < 0) {
4220 adap->params.max_ordird_qp = 8;
4221 adap->params.max_ird_adapter = 32 * adap->tids.ntids;
4222 ret = 0;
4223 } else {
4224 adap->params.max_ordird_qp = val[0];
4225 adap->params.max_ird_adapter = val[1];
4226 }
4227 dev_info(adap->pdev_dev,
4228 "max_ordird_qp %d max_ird_adapter %d\n",
4229 adap->params.max_ordird_qp,
4230 adap->params.max_ird_adapter);
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304231 adap->num_ofld_uld += 2;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004232 }
Vipul Pandya636f9d32012-09-26 02:39:39 +00004233 if (caps_cmd.iscsicaps) {
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004234 params[0] = FW_PARAM_PFVF(ISCSI_START);
4235 params[1] = FW_PARAM_PFVF(ISCSI_END);
Hariprasad Shenaib2612722015-05-27 22:30:24 +05304236 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2,
Vipul Pandya636f9d32012-09-26 02:39:39 +00004237 params, val);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004238 if (ret < 0)
4239 goto bye;
4240 adap->vres.iscsi.start = val[0];
4241 adap->vres.iscsi.size = val[1] - val[0] + 1;
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304242 /* LIO target and cxgb4i initiaitor */
4243 adap->num_ofld_uld += 2;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004244 }
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304245 if (caps_cmd.cryptocaps) {
4246 /* Should query params here...TODO */
Harsh Jain72a56ca2017-04-10 18:24:00 +05304247 params[0] = FW_PARAM_PFVF(NCRYPTO_LOOKASIDE);
4248 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2,
4249 params, val);
4250 if (ret < 0) {
4251 if (ret != -EINVAL)
4252 goto bye;
4253 } else {
4254 adap->vres.ncrypto_fc = val[0];
4255 }
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304256 adap->params.crypto |= ULP_CRYPTO_LOOKASIDE;
4257 adap->num_uld += 1;
4258 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004259#undef FW_PARAM_PFVF
4260#undef FW_PARAM_DEV
4261
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05304262 /* The MTU/MSS Table is initialized by now, so load their values. If
4263 * we're initializing the adapter, then we'll make any modifications
4264 * we want to the MTU/MSS Table and also initialize the congestion
4265 * parameters.
Vipul Pandya636f9d32012-09-26 02:39:39 +00004266 */
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004267 t4_read_mtu_tbl(adap, adap->params.mtus, NULL);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05304268 if (state != DEV_STATE_INIT) {
4269 int i;
Casey Leedom7ee9ff92010-06-25 12:11:46 +00004270
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05304271 /* The default MTU Table contains values 1492 and 1500.
4272 * However, for TCP, it's better to have two values which are
4273 * a multiple of 8 +/- 4 bytes apart near this popular MTU.
4274 * This allows us to have a TCP Data Payload which is a
4275 * multiple of 8 regardless of what combination of TCP Options
4276 * are in use (always a multiple of 4 bytes) which is
4277 * important for performance reasons. For instance, if no
4278 * options are in use, then we have a 20-byte IP header and a
4279 * 20-byte TCP header. In this case, a 1500-byte MSS would
4280 * result in a TCP Data Payload of 1500 - 40 == 1460 bytes
4281 * which is not a multiple of 8. So using an MSS of 1488 in
4282 * this case results in a TCP Data Payload of 1448 bytes which
4283 * is a multiple of 8. On the other hand, if 12-byte TCP Time
4284 * Stamps have been negotiated, then an MTU of 1500 bytes
4285 * results in a TCP Data Payload of 1448 bytes which, as
4286 * above, is a multiple of 8 bytes ...
4287 */
4288 for (i = 0; i < NMTUS; i++)
4289 if (adap->params.mtus[i] == 1492) {
4290 adap->params.mtus[i] = 1488;
4291 break;
4292 }
4293
4294 t4_load_mtus(adap, adap->params.mtus, adap->params.a_wnd,
4295 adap->params.b_wnd);
4296 }
Hariprasad Shenaidf64e4d2014-12-03 19:32:53 +05304297 t4_init_sge_params(adap);
Vipul Pandya636f9d32012-09-26 02:39:39 +00004298 adap->flags |= FW_OK;
Rahul Lakkireddy5ccf9d02017-10-13 18:48:17 +05304299 t4_init_tp_params(adap, true);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004300 return 0;
4301
4302 /*
Vipul Pandya636f9d32012-09-26 02:39:39 +00004303 * Something bad happened. If a command timed out or failed with EIO
4304 * FW does not operate within its spec or something catastrophic
4305 * happened to HW/FW, stop issuing commands.
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004306 */
Vipul Pandya636f9d32012-09-26 02:39:39 +00004307bye:
Hariprasad Shenai4b8e27a2015-03-26 10:04:25 +05304308 kfree(adap->sge.egr_map);
4309 kfree(adap->sge.ingr_map);
4310 kfree(adap->sge.starving_fl);
4311 kfree(adap->sge.txq_maperr);
Hariprasad Shenai5b377d12015-05-27 22:30:23 +05304312#ifdef CONFIG_DEBUG_FS
4313 kfree(adap->sge.blocked_fl);
4314#endif
Vipul Pandya636f9d32012-09-26 02:39:39 +00004315 if (ret != -ETIMEDOUT && ret != -EIO)
4316 t4_fw_bye(adap, adap->mbox);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004317 return ret;
4318}
4319
Dimitris Michailidis204dc3c2010-06-18 10:05:29 +00004320/* EEH callbacks */
4321
4322static pci_ers_result_t eeh_err_detected(struct pci_dev *pdev,
4323 pci_channel_state_t state)
4324{
4325 int i;
4326 struct adapter *adap = pci_get_drvdata(pdev);
4327
4328 if (!adap)
4329 goto out;
4330
4331 rtnl_lock();
4332 adap->flags &= ~FW_OK;
4333 notify_ulds(adap, CXGB4_STATE_START_RECOVERY);
Gavin Shan9fe6cb52014-01-23 12:27:35 +08004334 spin_lock(&adap->stats_lock);
Dimitris Michailidis204dc3c2010-06-18 10:05:29 +00004335 for_each_port(adap, i) {
4336 struct net_device *dev = adap->port[i];
Guilherme G. Piccoli025d0972017-05-28 23:07:01 -03004337 if (dev) {
4338 netif_device_detach(dev);
4339 netif_carrier_off(dev);
4340 }
Dimitris Michailidis204dc3c2010-06-18 10:05:29 +00004341 }
Gavin Shan9fe6cb52014-01-23 12:27:35 +08004342 spin_unlock(&adap->stats_lock);
Hariprasad Shenaib37987e2015-03-26 10:04:26 +05304343 disable_interrupts(adap);
Dimitris Michailidis204dc3c2010-06-18 10:05:29 +00004344 if (adap->flags & FULL_INIT_DONE)
4345 cxgb_down(adap);
4346 rtnl_unlock();
Gavin Shan144be3d2014-01-23 12:27:34 +08004347 if ((adap->flags & DEV_ENABLED)) {
4348 pci_disable_device(pdev);
4349 adap->flags &= ~DEV_ENABLED;
4350 }
Dimitris Michailidis204dc3c2010-06-18 10:05:29 +00004351out: return state == pci_channel_io_perm_failure ?
4352 PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_NEED_RESET;
4353}
4354
4355static pci_ers_result_t eeh_slot_reset(struct pci_dev *pdev)
4356{
4357 int i, ret;
4358 struct fw_caps_config_cmd c;
4359 struct adapter *adap = pci_get_drvdata(pdev);
4360
4361 if (!adap) {
4362 pci_restore_state(pdev);
4363 pci_save_state(pdev);
4364 return PCI_ERS_RESULT_RECOVERED;
4365 }
4366
Gavin Shan144be3d2014-01-23 12:27:34 +08004367 if (!(adap->flags & DEV_ENABLED)) {
4368 if (pci_enable_device(pdev)) {
4369 dev_err(&pdev->dev, "Cannot reenable PCI "
4370 "device after reset\n");
4371 return PCI_ERS_RESULT_DISCONNECT;
4372 }
4373 adap->flags |= DEV_ENABLED;
Dimitris Michailidis204dc3c2010-06-18 10:05:29 +00004374 }
4375
4376 pci_set_master(pdev);
4377 pci_restore_state(pdev);
4378 pci_save_state(pdev);
4379 pci_cleanup_aer_uncorrect_error_status(pdev);
4380
Hariprasad Shenai8203b502014-10-09 05:48:47 +05304381 if (t4_wait_dev_ready(adap->regs) < 0)
Dimitris Michailidis204dc3c2010-06-18 10:05:29 +00004382 return PCI_ERS_RESULT_DISCONNECT;
Hariprasad Shenaib2612722015-05-27 22:30:24 +05304383 if (t4_fw_hello(adap, adap->mbox, adap->pf, MASTER_MUST, NULL) < 0)
Dimitris Michailidis204dc3c2010-06-18 10:05:29 +00004384 return PCI_ERS_RESULT_DISCONNECT;
4385 adap->flags |= FW_OK;
4386 if (adap_init1(adap, &c))
4387 return PCI_ERS_RESULT_DISCONNECT;
4388
4389 for_each_port(adap, i) {
4390 struct port_info *p = adap2pinfo(adap, i);
4391
Hariprasad Shenaib2612722015-05-27 22:30:24 +05304392 ret = t4_alloc_vi(adap, adap->mbox, p->tx_chan, adap->pf, 0, 1,
Dimitris Michailidis060e0c72010-08-02 13:19:21 +00004393 NULL, NULL);
Dimitris Michailidis204dc3c2010-06-18 10:05:29 +00004394 if (ret < 0)
4395 return PCI_ERS_RESULT_DISCONNECT;
4396 p->viid = ret;
4397 p->xact_addr_filt = -1;
4398 }
4399
4400 t4_load_mtus(adap, adap->params.mtus, adap->params.a_wnd,
4401 adap->params.b_wnd);
Dimitris Michailidis1ae970e2010-08-02 13:19:19 +00004402 setup_memwin(adap);
Dimitris Michailidis204dc3c2010-06-18 10:05:29 +00004403 if (cxgb_up(adap))
4404 return PCI_ERS_RESULT_DISCONNECT;
4405 return PCI_ERS_RESULT_RECOVERED;
4406}
4407
4408static void eeh_resume(struct pci_dev *pdev)
4409{
4410 int i;
4411 struct adapter *adap = pci_get_drvdata(pdev);
4412
4413 if (!adap)
4414 return;
4415
4416 rtnl_lock();
4417 for_each_port(adap, i) {
4418 struct net_device *dev = adap->port[i];
Guilherme G. Piccoli025d0972017-05-28 23:07:01 -03004419 if (dev) {
4420 if (netif_running(dev)) {
4421 link_start(dev);
4422 cxgb_set_rxmode(dev);
4423 }
4424 netif_device_attach(dev);
Dimitris Michailidis204dc3c2010-06-18 10:05:29 +00004425 }
Dimitris Michailidis204dc3c2010-06-18 10:05:29 +00004426 }
4427 rtnl_unlock();
4428}
4429
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07004430static const struct pci_error_handlers cxgb4_eeh = {
Dimitris Michailidis204dc3c2010-06-18 10:05:29 +00004431 .error_detected = eeh_err_detected,
4432 .slot_reset = eeh_slot_reset,
4433 .resume = eeh_resume,
4434};
4435
Hariprasad Shenai9b86a8d2016-09-20 12:00:52 +05304436/* Return true if the Link Configuration supports "High Speeds" (those greater
4437 * than 1Gb/s).
4438 */
Kumar Sanghvi57d8b762014-02-18 17:56:10 +05304439static inline bool is_x_10g_port(const struct link_config *lc)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004440{
Hariprasad Shenai9b86a8d2016-09-20 12:00:52 +05304441 unsigned int speeds, high_speeds;
4442
Ganesh Goudarc3168ca2017-08-20 14:15:51 +05304443 speeds = FW_PORT_CAP32_SPEED_V(FW_PORT_CAP32_SPEED_G(lc->pcaps));
4444 high_speeds = speeds &
4445 ~(FW_PORT_CAP32_SPEED_100M | FW_PORT_CAP32_SPEED_1G);
Hariprasad Shenai9b86a8d2016-09-20 12:00:52 +05304446
4447 return high_speeds != 0;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004448}
4449
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004450/*
4451 * Perform default configuration of DMA queues depending on the number and type
4452 * of ports we found and the number of available CPUs. Most settings can be
4453 * modified by the admin prior to actual use.
4454 */
Bill Pemberton91744942012-12-03 09:23:02 -05004455static void cfg_queues(struct adapter *adap)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004456{
4457 struct sge *s = &adap->sge;
Hariprasad Shenaiab677ff2016-11-18 16:37:40 +05304458 int i = 0, n10g = 0, qidx = 0;
Anish Bhatt688848b2014-06-19 21:37:13 -07004459#ifndef CONFIG_CHELSIO_T4_DCB
4460 int q10g = 0;
4461#endif
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004462
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304463 /* Reduce memory usage in kdump environment, disable all offload.
4464 */
Ganesh Goudar85eacf32017-05-16 21:17:42 +05304465 if (is_kdump_kernel() || (is_uld(adap) && t4_uld_mem_alloc(adap))) {
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304466 adap->params.offload = 0;
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304467 adap->params.crypto = 0;
4468 }
4469
Hariprasad Shenaiab677ff2016-11-18 16:37:40 +05304470 n10g += is_x_10g_port(&adap2pinfo(adap, i)->link_cfg);
Anish Bhatt688848b2014-06-19 21:37:13 -07004471#ifdef CONFIG_CHELSIO_T4_DCB
4472 /* For Data Center Bridging support we need to be able to support up
4473 * to 8 Traffic Priorities; each of which will be assigned to its
4474 * own TX Queue in order to prevent Head-Of-Line Blocking.
4475 */
4476 if (adap->params.nports * 8 > MAX_ETH_QSETS) {
4477 dev_err(adap->pdev_dev, "MAX_ETH_QSETS=%d < %d!\n",
4478 MAX_ETH_QSETS, adap->params.nports * 8);
4479 BUG_ON(1);
4480 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004481
Anish Bhatt688848b2014-06-19 21:37:13 -07004482 for_each_port(adap, i) {
4483 struct port_info *pi = adap2pinfo(adap, i);
4484
4485 pi->first_qset = qidx;
Ganesh Goudar85eacf32017-05-16 21:17:42 +05304486 pi->nqsets = is_kdump_kernel() ? 1 : 8;
Anish Bhatt688848b2014-06-19 21:37:13 -07004487 qidx += pi->nqsets;
4488 }
4489#else /* !CONFIG_CHELSIO_T4_DCB */
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004490 /*
4491 * We default to 1 queue per non-10G port and up to # of cores queues
4492 * per 10G port.
4493 */
4494 if (n10g)
4495 q10g = (MAX_ETH_QSETS - (adap->params.nports - n10g)) / n10g;
Yuval Mintz5952dde2012-07-01 03:18:55 +00004496 if (q10g > netif_get_num_default_rss_queues())
4497 q10g = netif_get_num_default_rss_queues();
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004498
Ganesh Goudar85eacf32017-05-16 21:17:42 +05304499 if (is_kdump_kernel())
4500 q10g = 1;
4501
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004502 for_each_port(adap, i) {
4503 struct port_info *pi = adap2pinfo(adap, i);
4504
4505 pi->first_qset = qidx;
Kumar Sanghvi57d8b762014-02-18 17:56:10 +05304506 pi->nqsets = is_x_10g_port(&pi->link_cfg) ? q10g : 1;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004507 qidx += pi->nqsets;
4508 }
Anish Bhatt688848b2014-06-19 21:37:13 -07004509#endif /* !CONFIG_CHELSIO_T4_DCB */
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004510
4511 s->ethqsets = qidx;
4512 s->max_ethqsets = qidx; /* MSI-X may lower it later */
4513
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304514 if (is_uld(adap)) {
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004515 /*
4516 * For offload we use 1 queue/channel if all ports are up to 1G,
4517 * otherwise we divide all available queues amongst the channels
4518 * capped by the number of available cores.
4519 */
4520 if (n10g) {
Ganesh Goudara56177e2016-10-18 14:21:25 +05304521 i = min_t(int, MAX_OFLD_QSETS, num_online_cpus());
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304522 s->ofldqsets = roundup(i, adap->params.nports);
4523 } else {
4524 s->ofldqsets = adap->params.nports;
4525 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004526 }
4527
4528 for (i = 0; i < ARRAY_SIZE(s->ethrxq); i++) {
4529 struct sge_eth_rxq *r = &s->ethrxq[i];
4530
Hariprasad Shenaic887ad02014-06-06 21:40:45 +05304531 init_rspq(adap, &r->rspq, 5, 10, 1024, 64);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004532 r->fl.size = 72;
4533 }
4534
4535 for (i = 0; i < ARRAY_SIZE(s->ethtxq); i++)
4536 s->ethtxq[i].q.size = 1024;
4537
4538 for (i = 0; i < ARRAY_SIZE(s->ctrlq); i++)
4539 s->ctrlq[i].q.size = 512;
4540
Atul Guptaa45695042017-07-04 16:46:20 +05304541 if (!is_t4(adap->params.chip))
4542 s->ptptxq.q.size = 8;
4543
Hariprasad Shenaic887ad02014-06-06 21:40:45 +05304544 init_rspq(adap, &s->fw_evtq, 0, 1, 1024, 64);
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304545 init_rspq(adap, &s->intrq, 0, 1, 512, 64);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004546}
4547
4548/*
4549 * Reduce the number of Ethernet queues across all ports to at most n.
4550 * n provides at least one queue per port.
4551 */
Bill Pemberton91744942012-12-03 09:23:02 -05004552static void reduce_ethqs(struct adapter *adap, int n)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004553{
4554 int i;
4555 struct port_info *pi;
4556
4557 while (n < adap->sge.ethqsets)
4558 for_each_port(adap, i) {
4559 pi = adap2pinfo(adap, i);
4560 if (pi->nqsets > 1) {
4561 pi->nqsets--;
4562 adap->sge.ethqsets--;
4563 if (adap->sge.ethqsets <= n)
4564 break;
4565 }
4566 }
4567
4568 n = 0;
4569 for_each_port(adap, i) {
4570 pi = adap2pinfo(adap, i);
4571 pi->first_qset = n;
4572 n += pi->nqsets;
4573 }
4574}
4575
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304576static int get_msix_info(struct adapter *adap)
4577{
4578 struct uld_msix_info *msix_info;
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304579 unsigned int max_ingq = 0;
4580
4581 if (is_offload(adap))
4582 max_ingq += MAX_OFLD_QSETS * adap->num_ofld_uld;
4583 if (is_pci_uld(adap))
4584 max_ingq += MAX_OFLD_QSETS * adap->num_uld;
4585
4586 if (!max_ingq)
4587 goto out;
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304588
4589 msix_info = kcalloc(max_ingq, sizeof(*msix_info), GFP_KERNEL);
4590 if (!msix_info)
4591 return -ENOMEM;
4592
4593 adap->msix_bmap_ulds.msix_bmap = kcalloc(BITS_TO_LONGS(max_ingq),
4594 sizeof(long), GFP_KERNEL);
4595 if (!adap->msix_bmap_ulds.msix_bmap) {
4596 kfree(msix_info);
4597 return -ENOMEM;
4598 }
4599 spin_lock_init(&adap->msix_bmap_ulds.lock);
4600 adap->msix_info_ulds = msix_info;
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304601out:
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304602 return 0;
4603}
4604
4605static void free_msix_info(struct adapter *adap)
4606{
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304607 if (!(adap->num_uld && adap->num_ofld_uld))
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304608 return;
4609
4610 kfree(adap->msix_info_ulds);
4611 kfree(adap->msix_bmap_ulds.msix_bmap);
4612}
4613
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004614/* 2 MSI-X vectors needed for the FW queue and non-data interrupts */
4615#define EXTRA_VECS 2
4616
Bill Pemberton91744942012-12-03 09:23:02 -05004617static int enable_msix(struct adapter *adap)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004618{
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304619 int ofld_need = 0, uld_need = 0;
4620 int i, j, want, need, allocated;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004621 struct sge *s = &adap->sge;
4622 unsigned int nchan = adap->params.nports;
Hariprasad Shenaif36e58e2015-03-04 18:16:28 +05304623 struct msix_entry *entries;
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304624 int max_ingq = MAX_INGQ;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004625
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304626 if (is_pci_uld(adap))
4627 max_ingq += (MAX_OFLD_QSETS * adap->num_uld);
4628 if (is_offload(adap))
4629 max_ingq += (MAX_OFLD_QSETS * adap->num_ofld_uld);
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304630 entries = kmalloc(sizeof(*entries) * (max_ingq + 1),
Hariprasad Shenaif36e58e2015-03-04 18:16:28 +05304631 GFP_KERNEL);
4632 if (!entries)
4633 return -ENOMEM;
4634
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304635 /* map for msix */
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304636 if (get_msix_info(adap)) {
4637 adap->params.offload = 0;
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304638 adap->params.crypto = 0;
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304639 }
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304640
4641 for (i = 0; i < max_ingq + 1; ++i)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004642 entries[i].entry = i;
4643
4644 want = s->max_ethqsets + EXTRA_VECS;
4645 if (is_offload(adap)) {
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304646 want += adap->num_ofld_uld * s->ofldqsets;
4647 ofld_need = adap->num_ofld_uld * nchan;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004648 }
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304649 if (is_pci_uld(adap)) {
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304650 want += adap->num_uld * s->ofldqsets;
4651 uld_need = adap->num_uld * nchan;
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304652 }
Anish Bhatt688848b2014-06-19 21:37:13 -07004653#ifdef CONFIG_CHELSIO_T4_DCB
4654 /* For Data Center Bridging we need 8 Ethernet TX Priority Queues for
4655 * each port.
4656 */
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304657 need = 8 * adap->params.nports + EXTRA_VECS + ofld_need + uld_need;
Anish Bhatt688848b2014-06-19 21:37:13 -07004658#else
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304659 need = adap->params.nports + EXTRA_VECS + ofld_need + uld_need;
Anish Bhatt688848b2014-06-19 21:37:13 -07004660#endif
Hariprasad Shenaif36e58e2015-03-04 18:16:28 +05304661 allocated = pci_enable_msix_range(adap->pdev, entries, need, want);
4662 if (allocated < 0) {
4663 dev_info(adap->pdev_dev, "not enough MSI-X vectors left,"
4664 " not using MSI-X\n");
4665 kfree(entries);
4666 return allocated;
4667 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004668
Hariprasad Shenaif36e58e2015-03-04 18:16:28 +05304669 /* Distribute available vectors to the various queue groups.
Alexander Gordeevc32ad222014-02-18 11:07:59 +01004670 * Every group gets its minimum requirement and NIC gets top
4671 * priority for leftovers.
4672 */
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304673 i = allocated - EXTRA_VECS - ofld_need - uld_need;
Alexander Gordeevc32ad222014-02-18 11:07:59 +01004674 if (i < s->max_ethqsets) {
4675 s->max_ethqsets = i;
4676 if (i < s->ethqsets)
4677 reduce_ethqs(adap, i);
4678 }
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304679 if (is_uld(adap)) {
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304680 if (allocated < want)
4681 s->nqs_per_uld = nchan;
4682 else
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304683 s->nqs_per_uld = s->ofldqsets;
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304684 }
4685
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304686 for (i = 0; i < (s->max_ethqsets + EXTRA_VECS); ++i)
Alexander Gordeevc32ad222014-02-18 11:07:59 +01004687 adap->msix_info[i].vec = entries[i].vector;
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304688 if (is_uld(adap)) {
4689 for (j = 0 ; i < allocated; ++i, j++) {
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304690 adap->msix_info_ulds[j].vec = entries[i].vector;
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304691 adap->msix_info_ulds[j].idx = i;
4692 }
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304693 adap->msix_bmap_ulds.mapsize = j;
4694 }
Hariprasad Shenai43eb4e82015-10-21 14:39:53 +05304695 dev_info(adap->pdev_dev, "%d MSI-X vectors allocated, "
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304696 "nic %d per uld %d\n",
4697 allocated, s->max_ethqsets, s->nqs_per_uld);
Alexander Gordeevc32ad222014-02-18 11:07:59 +01004698
Hariprasad Shenaif36e58e2015-03-04 18:16:28 +05304699 kfree(entries);
Alexander Gordeevc32ad222014-02-18 11:07:59 +01004700 return 0;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004701}
4702
4703#undef EXTRA_VECS
4704
Bill Pemberton91744942012-12-03 09:23:02 -05004705static int init_rss(struct adapter *adap)
Dimitris Michailidis671b0062010-07-11 12:01:17 +00004706{
Hariprasad Shenaic035e182015-05-06 19:48:37 +05304707 unsigned int i;
4708 int err;
4709
4710 err = t4_init_rss_mode(adap, adap->mbox);
4711 if (err)
4712 return err;
Dimitris Michailidis671b0062010-07-11 12:01:17 +00004713
4714 for_each_port(adap, i) {
4715 struct port_info *pi = adap2pinfo(adap, i);
4716
4717 pi->rss = kcalloc(pi->rss_size, sizeof(u16), GFP_KERNEL);
4718 if (!pi->rss)
4719 return -ENOMEM;
Dimitris Michailidis671b0062010-07-11 12:01:17 +00004720 }
4721 return 0;
4722}
4723
Hariprasad Shenai547fd272015-12-23 11:29:53 +05304724static int cxgb4_get_pcie_dev_link_caps(struct adapter *adap,
4725 enum pci_bus_speed *speed,
4726 enum pcie_link_width *width)
4727{
4728 u32 lnkcap1, lnkcap2;
4729 int err1, err2;
4730
4731#define PCIE_MLW_CAP_SHIFT 4 /* start of MLW mask in link capabilities */
4732
4733 *speed = PCI_SPEED_UNKNOWN;
4734 *width = PCIE_LNK_WIDTH_UNKNOWN;
4735
4736 err1 = pcie_capability_read_dword(adap->pdev, PCI_EXP_LNKCAP,
4737 &lnkcap1);
4738 err2 = pcie_capability_read_dword(adap->pdev, PCI_EXP_LNKCAP2,
4739 &lnkcap2);
4740 if (!err2 && lnkcap2) { /* PCIe r3.0-compliant */
4741 if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_8_0GB)
4742 *speed = PCIE_SPEED_8_0GT;
4743 else if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_5_0GB)
4744 *speed = PCIE_SPEED_5_0GT;
4745 else if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_2_5GB)
4746 *speed = PCIE_SPEED_2_5GT;
4747 }
4748 if (!err1) {
4749 *width = (lnkcap1 & PCI_EXP_LNKCAP_MLW) >> PCIE_MLW_CAP_SHIFT;
4750 if (!lnkcap2) { /* pre-r3.0 */
4751 if (lnkcap1 & PCI_EXP_LNKCAP_SLS_5_0GB)
4752 *speed = PCIE_SPEED_5_0GT;
4753 else if (lnkcap1 & PCI_EXP_LNKCAP_SLS_2_5GB)
4754 *speed = PCIE_SPEED_2_5GT;
4755 }
4756 }
4757
4758 if (*speed == PCI_SPEED_UNKNOWN || *width == PCIE_LNK_WIDTH_UNKNOWN)
4759 return err1 ? err1 : err2 ? err2 : -EINVAL;
4760 return 0;
4761}
4762
4763static void cxgb4_check_pcie_caps(struct adapter *adap)
4764{
4765 enum pcie_link_width width, width_cap;
4766 enum pci_bus_speed speed, speed_cap;
4767
4768#define PCIE_SPEED_STR(speed) \
4769 (speed == PCIE_SPEED_8_0GT ? "8.0GT/s" : \
4770 speed == PCIE_SPEED_5_0GT ? "5.0GT/s" : \
4771 speed == PCIE_SPEED_2_5GT ? "2.5GT/s" : \
4772 "Unknown")
4773
4774 if (cxgb4_get_pcie_dev_link_caps(adap, &speed_cap, &width_cap)) {
4775 dev_warn(adap->pdev_dev,
4776 "Unable to determine PCIe device BW capabilities\n");
4777 return;
4778 }
4779
4780 if (pcie_get_minimum_link(adap->pdev, &speed, &width) ||
4781 speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) {
4782 dev_warn(adap->pdev_dev,
4783 "Unable to determine PCI Express bandwidth.\n");
4784 return;
4785 }
4786
4787 dev_info(adap->pdev_dev, "PCIe link speed is %s, device supports %s\n",
4788 PCIE_SPEED_STR(speed), PCIE_SPEED_STR(speed_cap));
4789 dev_info(adap->pdev_dev, "PCIe link width is x%d, device supports x%d\n",
4790 width, width_cap);
4791 if (speed < speed_cap || width < width_cap)
4792 dev_info(adap->pdev_dev,
4793 "A slot with more lanes and/or higher speed is "
4794 "suggested for optimal performance.\n");
4795}
4796
Hariprasad Shenai0de72732016-04-26 20:10:22 +05304797/* Dump basic information about the adapter */
4798static void print_adapter_info(struct adapter *adapter)
4799{
Ganesh Goudar760446f2017-07-20 18:28:48 +05304800 /* Hardware/Firmware/etc. Version/Revision IDs */
4801 t4_dump_version_info(adapter);
Hariprasad Shenai0de72732016-04-26 20:10:22 +05304802
4803 /* Software/Hardware configuration */
4804 dev_info(adapter->pdev_dev, "Configuration: %sNIC %s, %s capable\n",
4805 is_offload(adapter) ? "R" : "",
4806 ((adapter->flags & USING_MSIX) ? "MSI-X" :
4807 (adapter->flags & USING_MSI) ? "MSI" : ""),
4808 is_offload(adapter) ? "Offload" : "non-Offload");
4809}
4810
Bill Pemberton91744942012-12-03 09:23:02 -05004811static void print_port_info(const struct net_device *dev)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004812{
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004813 char buf[80];
Dimitris Michailidis118969e2010-12-14 21:36:48 +00004814 char *bufp = buf;
Dimitris Michailidisf1a051b2010-05-10 15:58:08 +00004815 const char *spd = "";
Dimitris Michailidis118969e2010-12-14 21:36:48 +00004816 const struct port_info *pi = netdev_priv(dev);
4817 const struct adapter *adap = pi->adapter;
Dimitris Michailidisf1a051b2010-05-10 15:58:08 +00004818
4819 if (adap->params.pci.speed == PCI_EXP_LNKSTA_CLS_2_5GB)
4820 spd = " 2.5 GT/s";
4821 else if (adap->params.pci.speed == PCI_EXP_LNKSTA_CLS_5_0GB)
4822 spd = " 5 GT/s";
Roland Dreierd2e752d2014-04-28 17:36:20 -07004823 else if (adap->params.pci.speed == PCI_EXP_LNKSTA_CLS_8_0GB)
4824 spd = " 8 GT/s";
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004825
Ganesh Goudarc3168ca2017-08-20 14:15:51 +05304826 if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_100M)
Ganesh Goudar5e78f7f2017-01-06 16:51:46 +05304827 bufp += sprintf(bufp, "100M/");
Ganesh Goudarc3168ca2017-08-20 14:15:51 +05304828 if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_1G)
Ganesh Goudar5e78f7f2017-01-06 16:51:46 +05304829 bufp += sprintf(bufp, "1G/");
Ganesh Goudarc3168ca2017-08-20 14:15:51 +05304830 if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_10G)
Dimitris Michailidis118969e2010-12-14 21:36:48 +00004831 bufp += sprintf(bufp, "10G/");
Ganesh Goudarc3168ca2017-08-20 14:15:51 +05304832 if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_25G)
Hariprasad Shenai9b86a8d2016-09-20 12:00:52 +05304833 bufp += sprintf(bufp, "25G/");
Ganesh Goudarc3168ca2017-08-20 14:15:51 +05304834 if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_40G)
Kumar Sanghvi72aca4b2014-02-18 17:56:08 +05304835 bufp += sprintf(bufp, "40G/");
Ganesh Goudarc3168ca2017-08-20 14:15:51 +05304836 if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_50G)
4837 bufp += sprintf(bufp, "50G/");
4838 if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_100G)
Hariprasad Shenai9b86a8d2016-09-20 12:00:52 +05304839 bufp += sprintf(bufp, "100G/");
Ganesh Goudarc3168ca2017-08-20 14:15:51 +05304840 if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_200G)
4841 bufp += sprintf(bufp, "200G/");
4842 if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_400G)
4843 bufp += sprintf(bufp, "400G/");
Dimitris Michailidis118969e2010-12-14 21:36:48 +00004844 if (bufp != buf)
4845 --bufp;
Kumar Sanghvi72aca4b2014-02-18 17:56:08 +05304846 sprintf(bufp, "BASE-%s", t4_get_port_type_description(pi->port_type));
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004847
Hariprasad Shenai0de72732016-04-26 20:10:22 +05304848 netdev_info(dev, "%s: Chelsio %s (%s) %s\n",
4849 dev->name, adap->params.vpd.id, adap->name, buf);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004850}
4851
Dimitris Michailidis06546392010-07-11 12:01:16 +00004852/*
4853 * Free the following resources:
4854 * - memory used for tables
4855 * - MSI/MSI-X
4856 * - net devices
4857 * - resources FW is holding for us
4858 */
4859static void free_some_resources(struct adapter *adapter)
4860{
4861 unsigned int i;
4862
Kumar Sanghvi3bdb3762017-10-18 20:49:11 +05304863 kvfree(adapter->smt);
Michal Hocko752ade62017-05-08 15:57:27 -07004864 kvfree(adapter->l2t);
Rahul Lakkireddyb72a32d2016-08-22 16:29:06 +05304865 t4_cleanup_sched(adapter);
Michal Hocko752ade62017-05-08 15:57:27 -07004866 kvfree(adapter->tids.tid_tab);
Kumar Sanghvie0f911c2017-09-21 23:41:16 +05304867 cxgb4_cleanup_tc_flower(adapter);
Rahul Lakkireddyd8931842016-09-20 17:13:09 +05304868 cxgb4_cleanup_tc_u32(adapter);
Hariprasad Shenai4b8e27a2015-03-26 10:04:25 +05304869 kfree(adapter->sge.egr_map);
4870 kfree(adapter->sge.ingr_map);
4871 kfree(adapter->sge.starving_fl);
4872 kfree(adapter->sge.txq_maperr);
Hariprasad Shenai5b377d12015-05-27 22:30:23 +05304873#ifdef CONFIG_DEBUG_FS
4874 kfree(adapter->sge.blocked_fl);
4875#endif
Dimitris Michailidis06546392010-07-11 12:01:16 +00004876 disable_msi(adapter);
4877
4878 for_each_port(adapter, i)
Dimitris Michailidis671b0062010-07-11 12:01:17 +00004879 if (adapter->port[i]) {
Hariprasad Shenai4f3a0fc2015-06-05 14:24:47 +05304880 struct port_info *pi = adap2pinfo(adapter, i);
4881
4882 if (pi->viid != 0)
4883 t4_free_vi(adapter, adapter->mbox, adapter->pf,
4884 0, pi->viid);
Dimitris Michailidis671b0062010-07-11 12:01:17 +00004885 kfree(adap2pinfo(adapter, i)->rss);
Dimitris Michailidis06546392010-07-11 12:01:16 +00004886 free_netdev(adapter->port[i]);
Dimitris Michailidis671b0062010-07-11 12:01:17 +00004887 }
Dimitris Michailidis06546392010-07-11 12:01:16 +00004888 if (adapter->flags & FW_OK)
Hariprasad Shenaib2612722015-05-27 22:30:24 +05304889 t4_fw_bye(adapter, adapter->pf);
Dimitris Michailidis06546392010-07-11 12:01:16 +00004890}
4891
Michał Mirosław2ed28ba2011-04-16 13:05:08 +00004892#define TSO_FLAGS (NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_TSO_ECN)
Dimitris Michailidis35d35682010-08-02 13:19:20 +00004893#define VLAN_FEAT (NETIF_F_SG | NETIF_F_IP_CSUM | TSO_FLAGS | \
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004894 NETIF_F_IPV6_CSUM | NETIF_F_HIGHDMA)
Santosh Rastapur22adfe02013-03-14 05:08:51 +00004895#define SEGMENT_SIZE 128
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004896
Hariprasad Shenaid86bd292015-08-04 14:36:19 +05304897static int get_chip_type(struct pci_dev *pdev, u32 pl_rev)
4898{
Hariprasad Shenaid86bd292015-08-04 14:36:19 +05304899 u16 device_id;
4900
4901 /* Retrieve adapter's device ID */
4902 pci_read_config_word(pdev, PCI_DEVICE_ID, &device_id);
françois romieu46cdc9b2015-09-04 23:05:42 +02004903
4904 switch (device_id >> 12) {
Hariprasad Shenaid86bd292015-08-04 14:36:19 +05304905 case CHELSIO_T4:
françois romieu46cdc9b2015-09-04 23:05:42 +02004906 return CHELSIO_CHIP_CODE(CHELSIO_T4, pl_rev);
Hariprasad Shenaid86bd292015-08-04 14:36:19 +05304907 case CHELSIO_T5:
françois romieu46cdc9b2015-09-04 23:05:42 +02004908 return CHELSIO_CHIP_CODE(CHELSIO_T5, pl_rev);
Hariprasad Shenaid86bd292015-08-04 14:36:19 +05304909 case CHELSIO_T6:
françois romieu46cdc9b2015-09-04 23:05:42 +02004910 return CHELSIO_CHIP_CODE(CHELSIO_T6, pl_rev);
Hariprasad Shenaid86bd292015-08-04 14:36:19 +05304911 default:
4912 dev_err(&pdev->dev, "Device %d is not supported\n",
4913 device_id);
Hariprasad Shenaid86bd292015-08-04 14:36:19 +05304914 }
françois romieu46cdc9b2015-09-04 23:05:42 +02004915 return -EINVAL;
Hariprasad Shenaid86bd292015-08-04 14:36:19 +05304916}
4917
Hariprasad Shenaib6244202016-06-14 14:39:31 +05304918#ifdef CONFIG_PCI_IOV
Ganesh Goudarbaf50862018-01-16 16:17:40 +05304919static void cxgb4_mgmt_setup(struct net_device *dev)
Hariprasad Shenaie7b48a32016-08-23 11:35:32 +05304920{
4921 dev->type = ARPHRD_NONE;
4922 dev->mtu = 0;
4923 dev->hard_header_len = 0;
4924 dev->addr_len = 0;
4925 dev->tx_queue_len = 0;
4926 dev->flags |= IFF_NOARP;
4927 dev->priv_flags |= IFF_NO_QUEUE;
4928
4929 /* Initialize the device structure. */
4930 dev->netdev_ops = &cxgb4_mgmt_netdev_ops;
4931 dev->ethtool_ops = &cxgb4_mgmt_ethtool_ops;
David S. Millercf124db2017-05-08 12:52:56 -04004932 dev->needs_free_netdev = true;
Hariprasad Shenaie7b48a32016-08-23 11:35:32 +05304933}
4934
Hariprasad Shenaib6244202016-06-14 14:39:31 +05304935static int cxgb4_iov_configure(struct pci_dev *pdev, int num_vfs)
4936{
Hariprasad Shenai78294512016-08-11 21:06:23 +05304937 struct adapter *adap = pci_get_drvdata(pdev);
Hariprasad Shenaib6244202016-06-14 14:39:31 +05304938 int err = 0;
4939 int current_vfs = pci_num_vf(pdev);
4940 u32 pcie_fw;
Hariprasad Shenaib6244202016-06-14 14:39:31 +05304941
Hariprasad Shenai78294512016-08-11 21:06:23 +05304942 pcie_fw = readl(adap->regs + PCIE_FW_A);
Hariprasad Shenaib6244202016-06-14 14:39:31 +05304943 /* Check if cxgb4 is the MASTER and fw is initialized */
4944 if (!(pcie_fw & PCIE_FW_INIT_F) ||
4945 !(pcie_fw & PCIE_FW_MASTER_VLD_F) ||
Ganesh Goudarbaf50862018-01-16 16:17:40 +05304946 PCIE_FW_MASTER_G(pcie_fw) != CXGB4_UNIFIED_PF) {
Hariprasad Shenaib6244202016-06-14 14:39:31 +05304947 dev_warn(&pdev->dev,
4948 "cxgb4 driver needs to be MASTER to support SRIOV\n");
4949 return -EOPNOTSUPP;
4950 }
4951
4952 /* If any of the VF's is already assigned to Guest OS, then
4953 * SRIOV for the same cannot be modified
4954 */
4955 if (current_vfs && pci_vfs_assigned(pdev)) {
4956 dev_err(&pdev->dev,
4957 "Cannot modify SR-IOV while VFs are assigned\n");
Ganesh Goudarbaf50862018-01-16 16:17:40 +05304958 return current_vfs;
Hariprasad Shenaib6244202016-06-14 14:39:31 +05304959 }
Ganesh Goudarbaf50862018-01-16 16:17:40 +05304960 /* Note that the upper-level code ensures that we're never called with
4961 * a non-zero "num_vfs" when we already have VFs instantiated. But
4962 * it never hurts to code defensively.
Hariprasad Shenaib6244202016-06-14 14:39:31 +05304963 */
Ganesh Goudarbaf50862018-01-16 16:17:40 +05304964 if (num_vfs != 0 && current_vfs != 0)
4965 return -EBUSY;
4966
4967 /* Nothing to do for no change. */
4968 if (num_vfs == current_vfs)
4969 return num_vfs;
4970
4971 /* Disable SRIOV when zero is passed. */
Hariprasad Shenaib6244202016-06-14 14:39:31 +05304972 if (!num_vfs) {
4973 pci_disable_sriov(pdev);
Ganesh Goudarbaf50862018-01-16 16:17:40 +05304974 /* free VF Management Interface */
4975 unregister_netdev(adap->port[0]);
4976 free_netdev(adap->port[0]);
4977 adap->port[0] = NULL;
4978
Hariprasad Shenai661dbeb2016-09-02 19:13:53 +05304979 /* free VF resources */
Ganesh Goudarbaf50862018-01-16 16:17:40 +05304980 adap->num_vfs = 0;
Hariprasad Shenai661dbeb2016-09-02 19:13:53 +05304981 kfree(adap->vfinfo);
4982 adap->vfinfo = NULL;
Ganesh Goudarbaf50862018-01-16 16:17:40 +05304983 return 0;
Hariprasad Shenaib6244202016-06-14 14:39:31 +05304984 }
4985
Ganesh Goudarbaf50862018-01-16 16:17:40 +05304986 if (!current_vfs) {
4987 struct fw_pfvf_cmd port_cmd, port_rpl;
4988 struct net_device *netdev;
4989 unsigned int pmask, port;
4990 struct pci_dev *pbridge;
4991 struct port_info *pi;
4992 char name[IFNAMSIZ];
4993 u32 devcap2;
4994 u16 flags;
4995 int pos;
Hariprasad Shenai78294512016-08-11 21:06:23 +05304996
Ganesh Goudarbaf50862018-01-16 16:17:40 +05304997 /* If we want to instantiate Virtual Functions, then our
4998 * parent bridge's PCI-E needs to support Alternative Routing
4999 * ID (ARI) because our VFs will show up at function offset 8
5000 * and above.
5001 */
5002 pbridge = pdev->bus->self;
5003 pos = pci_find_capability(pbridge, PCI_CAP_ID_EXP);
5004 pci_read_config_word(pbridge, pos + PCI_EXP_FLAGS, &flags);
5005 pci_read_config_dword(pbridge, pos + PCI_EXP_DEVCAP2, &devcap2);
5006
5007 if ((flags & PCI_EXP_FLAGS_VERS) < 2 ||
5008 !(devcap2 & PCI_EXP_DEVCAP2_ARI)) {
5009 /* Our parent bridge does not support ARI so issue a
5010 * warning and skip instantiating the VFs. They
5011 * won't be reachable.
5012 */
5013 dev_warn(&pdev->dev, "Parent bridge %02x:%02x.%x doesn't support ARI; can't instantiate Virtual Functions\n",
5014 pbridge->bus->number, PCI_SLOT(pbridge->devfn),
5015 PCI_FUNC(pbridge->devfn));
5016 return -ENOTSUPP;
5017 }
5018 memset(&port_cmd, 0, sizeof(port_cmd));
5019 port_cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_PFVF_CMD) |
5020 FW_CMD_REQUEST_F |
5021 FW_CMD_READ_F |
5022 FW_PFVF_CMD_PFN_V(adap->pf) |
5023 FW_PFVF_CMD_VFN_V(0));
5024 port_cmd.retval_len16 = cpu_to_be32(FW_LEN16(port_cmd));
5025 err = t4_wr_mbox(adap, adap->mbox, &port_cmd, sizeof(port_cmd),
5026 &port_rpl);
Hariprasad Shenaie7b48a32016-08-23 11:35:32 +05305027 if (err)
5028 return err;
Ganesh Goudarbaf50862018-01-16 16:17:40 +05305029 pmask = FW_PFVF_CMD_PMASK_G(be32_to_cpu(port_rpl.type_to_neq));
5030 port = ffs(pmask) - 1;
5031 /* Allocate VF Management Interface. */
5032 snprintf(name, IFNAMSIZ, "mgmtpf%d,%d", adap->adap_idx,
5033 adap->pf);
5034 netdev = alloc_netdev(sizeof(struct port_info),
5035 name, NET_NAME_UNKNOWN, cxgb4_mgmt_setup);
5036 if (!netdev)
5037 return -ENOMEM;
5038
5039 pi = netdev_priv(netdev);
5040 pi->adapter = adap;
5041 pi->lport = port;
5042 pi->tx_chan = port;
5043 SET_NETDEV_DEV(netdev, &pdev->dev);
5044
5045 adap->port[0] = netdev;
5046 pi->port_id = 0;
5047
5048 err = register_netdev(adap->port[0]);
5049 if (err) {
5050 pr_info("Unable to register VF mgmt netdev %s\n", name);
5051 free_netdev(adap->port[0]);
5052 adap->port[0] = NULL;
5053 return err;
5054 }
5055 /* Allocate and set up VF Information. */
5056 adap->vfinfo = kcalloc(pci_sriov_get_totalvfs(pdev),
5057 sizeof(struct vf_info), GFP_KERNEL);
5058 if (!adap->vfinfo) {
5059 unregister_netdev(adap->port[0]);
5060 free_netdev(adap->port[0]);
5061 adap->port[0] = NULL;
5062 return -ENOMEM;
5063 }
5064 cxgb4_mgmt_fill_vf_station_mac_addr(adap);
5065 }
5066 /* Instantiate the requested number of VFs. */
5067 err = pci_enable_sriov(pdev, num_vfs);
5068 if (err) {
5069 pr_info("Unable to instantiate %d VFs\n", num_vfs);
5070 if (!current_vfs) {
5071 unregister_netdev(adap->port[0]);
5072 free_netdev(adap->port[0]);
5073 adap->port[0] = NULL;
5074 kfree(adap->vfinfo);
5075 adap->vfinfo = NULL;
5076 }
5077 return err;
Hariprasad Shenaib6244202016-06-14 14:39:31 +05305078 }
Hariprasad Shenai661dbeb2016-09-02 19:13:53 +05305079
Ganesh Goudarbaf50862018-01-16 16:17:40 +05305080 adap->num_vfs = num_vfs;
Hariprasad Shenaib6244202016-06-14 14:39:31 +05305081 return num_vfs;
5082}
Ganesh Goudarbaf50862018-01-16 16:17:40 +05305083#endif /* CONFIG_PCI_IOV */
Hariprasad Shenaib6244202016-06-14 14:39:31 +05305084
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00005085static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005086{
Santosh Rastapur22adfe02013-03-14 05:08:51 +00005087 int func, i, err, s_qpp, qpp, num_seg;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005088 struct port_info *pi;
Michał Mirosławc8f44af2011-11-15 15:29:55 +00005089 bool highdma = false;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005090 struct adapter *adapter = NULL;
Hariprasad Shenai78294512016-08-11 21:06:23 +05305091 struct net_device *netdev;
Hariprasad Shenaid6ce2622014-09-16 02:58:46 +05305092 void __iomem *regs;
Hariprasad Shenaid86bd292015-08-04 14:36:19 +05305093 u32 whoami, pl_rev;
5094 enum chip_type chip;
Hariprasad Shenai78294512016-08-11 21:06:23 +05305095 static int adap_idx = 1;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005096
5097 printk_once(KERN_INFO "%s - version %s\n", DRV_DESC, DRV_VERSION);
5098
5099 err = pci_request_regions(pdev, KBUILD_MODNAME);
5100 if (err) {
5101 /* Just info, some other driver may have claimed the device. */
5102 dev_info(&pdev->dev, "cannot obtain PCI resources\n");
5103 return err;
5104 }
5105
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005106 err = pci_enable_device(pdev);
5107 if (err) {
5108 dev_err(&pdev->dev, "cannot enable PCI device\n");
5109 goto out_release_regions;
5110 }
5111
Hariprasad Shenaid6ce2622014-09-16 02:58:46 +05305112 regs = pci_ioremap_bar(pdev, 0);
5113 if (!regs) {
5114 dev_err(&pdev->dev, "cannot map device registers\n");
5115 err = -ENOMEM;
5116 goto out_disable_device;
5117 }
5118
Ganesh Goudarbaf50862018-01-16 16:17:40 +05305119 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
5120 if (!adapter) {
5121 err = -ENOMEM;
5122 goto out_unmap_bar0;
5123 }
5124
5125 adapter->regs = regs;
Hariprasad Shenai8203b502014-10-09 05:48:47 +05305126 err = t4_wait_dev_ready(regs);
5127 if (err < 0)
5128 goto out_unmap_bar0;
5129
Hariprasad Shenaid6ce2622014-09-16 02:58:46 +05305130 /* We control everything through one PF */
Hariprasad Shenaid86bd292015-08-04 14:36:19 +05305131 whoami = readl(regs + PL_WHOAMI_A);
5132 pl_rev = REV_G(readl(regs + PL_REV_A));
5133 chip = get_chip_type(pdev, pl_rev);
5134 func = CHELSIO_CHIP_VERSION(chip) <= CHELSIO_T5 ?
5135 SOURCEPF_G(whoami) : T6_SOURCEPF_G(whoami);
Hariprasad Shenaid6ce2622014-09-16 02:58:46 +05305136
Ganesh Goudarbaf50862018-01-16 16:17:40 +05305137 adapter->pdev = pdev;
5138 adapter->pdev_dev = &pdev->dev;
5139 adapter->name = pci_name(pdev);
5140 adapter->mbox = func;
5141 adapter->pf = func;
5142 adapter->msg_enable = DFLT_MSG_ENABLE;
Hariprasad Shenai7f080c32016-04-28 13:23:18 +05305143 adapter->mbox_log = kzalloc(sizeof(*adapter->mbox_log) +
5144 (sizeof(struct mbox_cmd) *
5145 T4_OS_LOG_MBOX_CMDS),
5146 GFP_KERNEL);
5147 if (!adapter->mbox_log) {
5148 err = -ENOMEM;
5149 goto out_free_adapter;
5150 }
Ganesh Goudarbaf50862018-01-16 16:17:40 +05305151 spin_lock_init(&adapter->mbox_lock);
5152 INIT_LIST_HEAD(&adapter->mlist.list);
5153 pci_set_drvdata(pdev, adapter);
5154
5155 if (func != ent->driver_data) {
5156 pci_disable_device(pdev);
5157 pci_save_state(pdev); /* to restore SR-IOV later */
5158 return 0;
5159 }
5160
5161 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
5162 highdma = true;
5163 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
5164 if (err) {
5165 dev_err(&pdev->dev, "unable to obtain 64-bit DMA for "
5166 "coherent allocations\n");
5167 goto out_free_adapter;
5168 }
5169 } else {
5170 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
5171 if (err) {
5172 dev_err(&pdev->dev, "no usable DMA configuration\n");
5173 goto out_free_adapter;
5174 }
5175 }
5176
5177 pci_enable_pcie_error_reporting(pdev);
5178 pci_set_master(pdev);
5179 pci_save_state(pdev);
5180 adap_idx++;
5181 adapter->workq = create_singlethread_workqueue("cxgb4");
5182 if (!adapter->workq) {
5183 err = -ENOMEM;
5184 goto out_free_adapter;
5185 }
5186
Hariprasad Shenai7f080c32016-04-28 13:23:18 +05305187 adapter->mbox_log->size = T4_OS_LOG_MBOX_CMDS;
5188
Gavin Shan144be3d2014-01-23 12:27:34 +08005189 /* PCI device has been enabled */
5190 adapter->flags |= DEV_ENABLED;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005191 memset(adapter->chan_map, 0xff, sizeof(adapter->chan_map));
5192
Casey Leedomb0ba9d52017-08-15 11:23:26 +08005193 /* If possible, we use PCIe Relaxed Ordering Attribute to deliver
5194 * Ingress Packet Data to Free List Buffers in order to allow for
5195 * chipset performance optimizations between the Root Complex and
5196 * Memory Controllers. (Messages to the associated Ingress Queue
5197 * notifying new Packet Placement in the Free Lists Buffers will be
5198 * send without the Relaxed Ordering Attribute thus guaranteeing that
5199 * all preceding PCIe Transaction Layer Packets will be processed
5200 * first.) But some Root Complexes have various issues with Upstream
5201 * Transaction Layer Packets with the Relaxed Ordering Attribute set.
5202 * The PCIe devices which under the Root Complexes will be cleared the
5203 * Relaxed Ordering bit in the configuration space, So we check our
5204 * PCIe configuration space to see if it's flagged with advice against
5205 * using Relaxed Ordering.
5206 */
5207 if (!pcie_relaxed_ordering_enabled(pdev))
5208 adapter->flags |= ROOT_NO_RELAXED_ORDERING;
5209
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005210 spin_lock_init(&adapter->stats_lock);
5211 spin_lock_init(&adapter->tid_release_lock);
Anish Bhatte327c222014-10-29 17:54:03 -07005212 spin_lock_init(&adapter->win0_lock);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005213
5214 INIT_WORK(&adapter->tid_release_task, process_tid_release_list);
Vipul Pandya881806b2012-05-18 15:29:24 +05305215 INIT_WORK(&adapter->db_full_task, process_db_full);
5216 INIT_WORK(&adapter->db_drop_task, process_db_drop);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005217
5218 err = t4_prep_adapter(adapter);
5219 if (err)
Hariprasad Shenaid6ce2622014-09-16 02:58:46 +05305220 goto out_free_adapter;
5221
Santosh Rastapur22adfe02013-03-14 05:08:51 +00005222
Hariprasad Shenaid14807d2013-12-03 17:05:56 +05305223 if (!is_t4(adapter->params.chip)) {
Hariprasad Shenaif612b812015-01-05 16:30:43 +05305224 s_qpp = (QUEUESPERPAGEPF0_S +
5225 (QUEUESPERPAGEPF1_S - QUEUESPERPAGEPF0_S) *
Hariprasad Shenaib2612722015-05-27 22:30:24 +05305226 adapter->pf);
Hariprasad Shenaif612b812015-01-05 16:30:43 +05305227 qpp = 1 << QUEUESPERPAGEPF0_G(t4_read_reg(adapter,
5228 SGE_EGRESS_QUEUES_PER_PAGE_PF_A) >> s_qpp);
Santosh Rastapur22adfe02013-03-14 05:08:51 +00005229 num_seg = PAGE_SIZE / SEGMENT_SIZE;
5230
5231 /* Each segment size is 128B. Write coalescing is enabled only
5232 * when SGE_EGRESS_QUEUES_PER_PAGE_PF reg value for the
5233 * queue is less no of segments that can be accommodated in
5234 * a page size.
5235 */
5236 if (qpp > num_seg) {
5237 dev_err(&pdev->dev,
5238 "Incorrect number of egress queues per page\n");
5239 err = -EINVAL;
Hariprasad Shenaid6ce2622014-09-16 02:58:46 +05305240 goto out_free_adapter;
Santosh Rastapur22adfe02013-03-14 05:08:51 +00005241 }
5242 adapter->bar2 = ioremap_wc(pci_resource_start(pdev, 2),
5243 pci_resource_len(pdev, 2));
5244 if (!adapter->bar2) {
5245 dev_err(&pdev->dev, "cannot map device bar2 region\n");
5246 err = -ENOMEM;
Hariprasad Shenaid6ce2622014-09-16 02:58:46 +05305247 goto out_free_adapter;
Santosh Rastapur22adfe02013-03-14 05:08:51 +00005248 }
5249 }
5250
Vipul Pandya636f9d32012-09-26 02:39:39 +00005251 setup_memwin(adapter);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005252 err = adap_init0(adapter);
Hariprasad Shenai5b377d12015-05-27 22:30:23 +05305253#ifdef CONFIG_DEBUG_FS
5254 bitmap_zero(adapter->sge.blocked_fl, adapter->sge.egr_sz);
5255#endif
Vipul Pandya636f9d32012-09-26 02:39:39 +00005256 setup_memwin_rdma(adapter);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005257 if (err)
5258 goto out_unmap_bar;
5259
Hariprasad Shenai2a485cf2015-09-08 16:25:40 +05305260 /* configure SGE_STAT_CFG_A to read WC stats */
5261 if (!is_t4(adapter->params.chip))
Hariprasad Shenai676d6a72015-12-23 22:47:14 +05305262 t4_write_reg(adapter, SGE_STAT_CFG_A, STATSOURCE_T5_V(7) |
5263 (is_t5(adapter->params.chip) ? STATMODE_V(0) :
5264 T6_STATMODE_V(0)));
Hariprasad Shenai2a485cf2015-09-08 16:25:40 +05305265
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005266 for_each_port(adapter, i) {
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005267 netdev = alloc_etherdev_mq(sizeof(struct port_info),
5268 MAX_ETH_QSETS);
5269 if (!netdev) {
5270 err = -ENOMEM;
5271 goto out_free_dev;
5272 }
5273
5274 SET_NETDEV_DEV(netdev, &pdev->dev);
5275
5276 adapter->port[i] = netdev;
5277 pi = netdev_priv(netdev);
5278 pi->adapter = adapter;
5279 pi->xact_addr_filt = -1;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005280 pi->port_id = i;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005281 netdev->irq = pdev->irq;
5282
Michał Mirosław2ed28ba2011-04-16 13:05:08 +00005283 netdev->hw_features = NETIF_F_SG | TSO_FLAGS |
5284 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
5285 NETIF_F_RXCSUM | NETIF_F_RXHASH |
Rahul Lakkireddyd8931842016-09-20 17:13:09 +05305286 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX |
5287 NETIF_F_HW_TC;
Ganesh Goudard0a12992018-01-10 18:15:26 +05305288
5289 if (CHELSIO_CHIP_VERSION(chip) > CHELSIO_T5)
5290 netdev->hw_features |= NETIF_F_GSO_UDP_TUNNEL;
5291
Michał Mirosławc8f44af2011-11-15 15:29:55 +00005292 if (highdma)
5293 netdev->hw_features |= NETIF_F_HIGHDMA;
5294 netdev->features |= netdev->hw_features;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005295 netdev->vlan_features = netdev->features & VLAN_FEAT;
5296
Jiri Pirko01789342011-08-16 06:29:00 +00005297 netdev->priv_flags |= IFF_UNICAST_FLT;
5298
Jarod Wilsond894be52016-10-20 13:55:16 -04005299 /* MTU range: 81 - 9600 */
Arjun Vynipadatha047fba2017-10-03 11:43:05 +05305300 netdev->min_mtu = 81; /* accommodate SACK */
Jarod Wilsond894be52016-10-20 13:55:16 -04005301 netdev->max_mtu = MAX_MTU;
5302
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005303 netdev->netdev_ops = &cxgb4_netdev_ops;
Anish Bhatt688848b2014-06-19 21:37:13 -07005304#ifdef CONFIG_CHELSIO_T4_DCB
5305 netdev->dcbnl_ops = &cxgb4_dcb_ops;
5306 cxgb4_dcb_state_init(netdev);
5307#endif
Hariprasad Shenai812034f2015-04-06 20:23:23 +05305308 cxgb4_set_ethtool_ops(netdev);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005309 }
5310
Rahul Lakkireddyad75b7d2017-10-13 18:48:13 +05305311 cxgb4_init_ethtool_dump(adapter);
5312
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005313 pci_set_drvdata(pdev, adapter);
5314
5315 if (adapter->flags & FW_OK) {
Dimitris Michailidis060e0c72010-08-02 13:19:21 +00005316 err = t4_port_init(adapter, func, func, 0);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005317 if (err)
5318 goto out_free_dev;
Hariprasad Shenai098ef6c2015-06-05 14:24:50 +05305319 } else if (adapter->params.nports == 1) {
5320 /* If we don't have a connection to the firmware -- possibly
5321 * because of an error -- grab the raw VPD parameters so we
5322 * can set the proper MAC Address on the debug network
5323 * interface that we've created.
5324 */
5325 u8 hw_addr[ETH_ALEN];
5326 u8 *na = adapter->params.vpd.na;
5327
5328 err = t4_get_raw_vpd_params(adapter, &adapter->params.vpd);
5329 if (!err) {
5330 for (i = 0; i < ETH_ALEN; i++)
5331 hw_addr[i] = (hex2val(na[2 * i + 0]) * 16 +
5332 hex2val(na[2 * i + 1]));
5333 t4_set_hw_addr(adapter, 0, hw_addr);
5334 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005335 }
5336
Hariprasad Shenai098ef6c2015-06-05 14:24:50 +05305337 /* Configure queues and allocate tables now, they can be needed as
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005338 * soon as the first register_netdev completes.
5339 */
5340 cfg_queues(adapter);
5341
Kumar Sanghvi3bdb3762017-10-18 20:49:11 +05305342 adapter->smt = t4_init_smt();
5343 if (!adapter->smt) {
5344 /* We tolerate a lack of SMT, giving up some functionality */
5345 dev_warn(&pdev->dev, "could not allocate SMT, continuing\n");
5346 }
5347
Hariprasad Shenai5be9ed82015-07-07 21:49:18 +05305348 adapter->l2t = t4_init_l2t(adapter->l2t_start, adapter->l2t_end);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005349 if (!adapter->l2t) {
5350 /* We tolerate a lack of L2T, giving up some functionality */
5351 dev_warn(&pdev->dev, "could not allocate L2T, continuing\n");
5352 adapter->params.offload = 0;
5353 }
5354
Anish Bhattb5a02f52015-01-14 15:17:34 -08005355#if IS_ENABLED(CONFIG_IPV6)
Hariprasad Shenaieb72f742015-12-09 17:16:35 +05305356 if ((CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5) &&
5357 (!(t4_read_reg(adapter, LE_DB_CONFIG_A) & ASLIPCOMPEN_F))) {
5358 /* CLIP functionality is not present in hardware,
5359 * hence disable all offload features
Anish Bhattb5a02f52015-01-14 15:17:34 -08005360 */
5361 dev_warn(&pdev->dev,
Hariprasad Shenaieb72f742015-12-09 17:16:35 +05305362 "CLIP not enabled in hardware, continuing\n");
Anish Bhattb5a02f52015-01-14 15:17:34 -08005363 adapter->params.offload = 0;
Hariprasad Shenaieb72f742015-12-09 17:16:35 +05305364 } else {
5365 adapter->clipt = t4_init_clip_tbl(adapter->clipt_start,
5366 adapter->clipt_end);
5367 if (!adapter->clipt) {
5368 /* We tolerate a lack of clip_table, giving up
5369 * some functionality
5370 */
5371 dev_warn(&pdev->dev,
5372 "could not allocate Clip table, continuing\n");
5373 adapter->params.offload = 0;
5374 }
Anish Bhattb5a02f52015-01-14 15:17:34 -08005375 }
5376#endif
Rahul Lakkireddyb72a32d2016-08-22 16:29:06 +05305377
5378 for_each_port(adapter, i) {
5379 pi = adap2pinfo(adapter, i);
5380 pi->sched_tbl = t4_init_sched(adapter->params.nsched_cls);
5381 if (!pi->sched_tbl)
5382 dev_warn(&pdev->dev,
5383 "could not activate scheduling on port %d\n",
5384 i);
5385 }
5386
Rahul Lakkireddy578b46b2016-09-20 17:13:07 +05305387 if (tid_init(&adapter->tids) < 0) {
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005388 dev_warn(&pdev->dev, "could not allocate TID table, "
5389 "continuing\n");
5390 adapter->params.offload = 0;
Rahul Lakkireddyd8931842016-09-20 17:13:09 +05305391 } else {
Arjun V45da1ca2017-02-16 12:22:45 +05305392 adapter->tc_u32 = cxgb4_init_tc_u32(adapter);
Rahul Lakkireddyd8931842016-09-20 17:13:09 +05305393 if (!adapter->tc_u32)
5394 dev_warn(&pdev->dev,
5395 "could not offload tc u32, continuing\n");
Kumar Sanghvi62488e42017-09-21 23:41:14 +05305396
Kumar Sanghvi79e6d462017-11-01 08:53:04 +05305397 if (cxgb4_init_tc_flower(adapter))
5398 dev_warn(&pdev->dev,
5399 "could not offload tc flower, continuing\n");
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005400 }
5401
Kumar Sanghvi5c312542017-11-01 08:53:00 +05305402 if (is_offload(adapter) || is_hashfilter(adapter)) {
Hariprasad Shenai9a1bb9f2015-08-12 16:55:05 +05305403 if (t4_read_reg(adapter, LE_DB_CONFIG_A) & HASHEN_F) {
5404 u32 hash_base, hash_reg;
5405
5406 if (chip <= CHELSIO_T5) {
5407 hash_reg = LE_DB_TID_HASHBASE_A;
5408 hash_base = t4_read_reg(adapter, hash_reg);
5409 adapter->tids.hash_base = hash_base / 4;
5410 } else {
5411 hash_reg = T6_LE_DB_HASH_TID_BASE_A;
5412 hash_base = t4_read_reg(adapter, hash_reg);
5413 adapter->tids.hash_base = hash_base;
5414 }
5415 }
5416 }
5417
Dimitris Michailidisf7cabcd2010-07-11 12:01:15 +00005418 /* See what interrupts we'll be using */
5419 if (msi > 1 && enable_msix(adapter) == 0)
5420 adapter->flags |= USING_MSIX;
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05305421 else if (msi > 0 && pci_enable_msi(pdev) == 0) {
Dimitris Michailidisf7cabcd2010-07-11 12:01:15 +00005422 adapter->flags |= USING_MSI;
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05305423 if (msi > 1)
5424 free_msix_info(adapter);
5425 }
Dimitris Michailidisf7cabcd2010-07-11 12:01:15 +00005426
Hariprasad Shenai547fd272015-12-23 11:29:53 +05305427 /* check for PCI Express bandwidth capabiltites */
5428 cxgb4_check_pcie_caps(adapter);
5429
Dimitris Michailidis671b0062010-07-11 12:01:17 +00005430 err = init_rss(adapter);
5431 if (err)
5432 goto out_free_dev;
5433
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005434 /*
5435 * The card is now ready to go. If any errors occur during device
5436 * registration we do not fail the whole card but rather proceed only
5437 * with the ports we manage to register successfully. However we must
5438 * register at least one net device.
5439 */
5440 for_each_port(adapter, i) {
Dimitris Michailidisa57cabe2010-12-14 21:36:46 +00005441 pi = adap2pinfo(adapter, i);
Arjun Vd2a007ab2016-12-08 18:09:23 +05305442 adapter->port[i]->dev_port = pi->lport;
Dimitris Michailidisa57cabe2010-12-14 21:36:46 +00005443 netif_set_real_num_tx_queues(adapter->port[i], pi->nqsets);
5444 netif_set_real_num_rx_queues(adapter->port[i], pi->nqsets);
5445
Surendra Mobiyab1a73af2017-05-30 11:32:06 +05305446 netif_carrier_off(adapter->port[i]);
5447
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005448 err = register_netdev(adapter->port[i]);
5449 if (err)
Dimitris Michailidisb1a3c2b2010-12-14 21:36:51 +00005450 break;
Dimitris Michailidisb1a3c2b2010-12-14 21:36:51 +00005451 adapter->chan_map[pi->tx_chan] = i;
5452 print_port_info(adapter->port[i]);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005453 }
Dimitris Michailidisb1a3c2b2010-12-14 21:36:51 +00005454 if (i == 0) {
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005455 dev_err(&pdev->dev, "could not register any net devices\n");
5456 goto out_free_dev;
5457 }
Dimitris Michailidisb1a3c2b2010-12-14 21:36:51 +00005458 if (err) {
5459 dev_warn(&pdev->dev, "only %d net devices registered\n", i);
5460 err = 0;
Joe Perches6403eab2011-06-03 11:51:20 +00005461 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005462
5463 if (cxgb4_debugfs_root) {
5464 adapter->debugfs_root = debugfs_create_dir(pci_name(pdev),
5465 cxgb4_debugfs_root);
5466 setup_debugfs(adapter);
5467 }
5468
David S. Miller88c51002011-10-07 13:38:43 -04005469 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
5470 pdev->needs_freset = 1;
5471
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05305472 if (is_uld(adapter)) {
5473 mutex_lock(&uld_mutex);
5474 list_add_tail(&adapter->list_node, &adapter_list);
5475 mutex_unlock(&uld_mutex);
5476 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005477
Atul Gupta9c33e422017-07-04 16:46:21 +05305478 if (!is_t4(adapter->params.chip))
5479 cxgb4_ptp_init(adapter);
5480
Hariprasad Shenai0de72732016-04-26 20:10:22 +05305481 print_adapter_info(adapter);
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05305482 setup_fw_sge_queues(adapter);
Hariprasad Shenai78294512016-08-11 21:06:23 +05305483 return 0;
Hariprasad Shenai0de72732016-04-26 20:10:22 +05305484
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005485 out_free_dev:
Dimitris Michailidis06546392010-07-11 12:01:16 +00005486 free_some_resources(adapter);
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05305487 if (adapter->flags & USING_MSIX)
5488 free_msix_info(adapter);
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05305489 if (adapter->num_uld || adapter->num_ofld_uld)
5490 t4_uld_mem_free(adapter);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005491 out_unmap_bar:
Hariprasad Shenaid14807d2013-12-03 17:05:56 +05305492 if (!is_t4(adapter->params.chip))
Santosh Rastapur22adfe02013-03-14 05:08:51 +00005493 iounmap(adapter->bar2);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005494 out_free_adapter:
Anish Bhatt29aaee62014-08-20 13:44:06 -07005495 if (adapter->workq)
5496 destroy_workqueue(adapter->workq);
5497
Hariprasad Shenai7f080c32016-04-28 13:23:18 +05305498 kfree(adapter->mbox_log);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005499 kfree(adapter);
Hariprasad Shenaid6ce2622014-09-16 02:58:46 +05305500 out_unmap_bar0:
5501 iounmap(regs);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005502 out_disable_device:
5503 pci_disable_pcie_error_reporting(pdev);
5504 pci_disable_device(pdev);
5505 out_release_regions:
5506 pci_release_regions(pdev);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005507 return err;
5508}
5509
Bill Pemberton91744942012-12-03 09:23:02 -05005510static void remove_one(struct pci_dev *pdev)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005511{
5512 struct adapter *adapter = pci_get_drvdata(pdev);
5513
Hariprasad Shenai78294512016-08-11 21:06:23 +05305514 if (!adapter) {
5515 pci_release_regions(pdev);
5516 return;
5517 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005518
Ganesh Goudare1f61982017-09-21 12:50:47 +05305519 adapter->flags |= SHUTTING_DOWN;
5520
Hariprasad Shenai78294512016-08-11 21:06:23 +05305521 if (adapter->pf == 4) {
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005522 int i;
5523
Anish Bhatt29aaee62014-08-20 13:44:06 -07005524 /* Tear down per-adapter Work Queue first since it can contain
5525 * references to our adapter data structure.
5526 */
5527 destroy_workqueue(adapter->workq);
5528
Guilherme G. Piccoli6a146f32017-07-10 10:55:46 -03005529 if (is_uld(adapter)) {
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005530 detach_ulds(adapter);
Guilherme G. Piccoli6a146f32017-07-10 10:55:46 -03005531 t4_uld_clean_up(adapter);
5532 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005533
Hariprasad Shenaib37987e2015-03-26 10:04:26 +05305534 disable_interrupts(adapter);
5535
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005536 for_each_port(adapter, i)
Dimitris Michailidis8f3a7672010-12-14 21:36:52 +00005537 if (adapter->port[i]->reg_state == NETREG_REGISTERED)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005538 unregister_netdev(adapter->port[i]);
5539
Fabian Frederick9f16dc22014-06-27 22:51:52 +02005540 debugfs_remove_recursive(adapter->debugfs_root);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005541
Atul Gupta9c33e422017-07-04 16:46:21 +05305542 if (!is_t4(adapter->params.chip))
5543 cxgb4_ptp_stop(adapter);
5544
Vipul Pandyaf2b7e782012-12-10 09:30:52 +00005545 /* If we allocated filters, free up state associated with any
5546 * valid filters ...
5547 */
Rahul Lakkireddy578b46b2016-09-20 17:13:07 +05305548 clear_all_filters(adapter);
Vipul Pandyaf2b7e782012-12-10 09:30:52 +00005549
Dimitris Michailidisaaefae92010-05-18 10:07:12 +00005550 if (adapter->flags & FULL_INIT_DONE)
5551 cxgb_down(adapter);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005552
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05305553 if (adapter->flags & USING_MSIX)
5554 free_msix_info(adapter);
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05305555 if (adapter->num_uld || adapter->num_ofld_uld)
5556 t4_uld_mem_free(adapter);
Dimitris Michailidis06546392010-07-11 12:01:16 +00005557 free_some_resources(adapter);
Anish Bhattb5a02f52015-01-14 15:17:34 -08005558#if IS_ENABLED(CONFIG_IPV6)
5559 t4_cleanup_clip_tbl(adapter);
5560#endif
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005561 iounmap(adapter->regs);
Hariprasad Shenaid14807d2013-12-03 17:05:56 +05305562 if (!is_t4(adapter->params.chip))
Santosh Rastapur22adfe02013-03-14 05:08:51 +00005563 iounmap(adapter->bar2);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005564 pci_disable_pcie_error_reporting(pdev);
Gavin Shan144be3d2014-01-23 12:27:34 +08005565 if ((adapter->flags & DEV_ENABLED)) {
5566 pci_disable_device(pdev);
5567 adapter->flags &= ~DEV_ENABLED;
5568 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005569 pci_release_regions(pdev);
Hariprasad Shenai7f080c32016-04-28 13:23:18 +05305570 kfree(adapter->mbox_log);
Li RongQingee9a33b2014-06-20 17:32:36 +08005571 synchronize_rcu();
Gavin Shan8b662fe2014-01-24 17:12:03 +08005572 kfree(adapter);
Hariprasad Shenai78294512016-08-11 21:06:23 +05305573 }
5574#ifdef CONFIG_PCI_IOV
5575 else {
Ganesh Goudarbaf50862018-01-16 16:17:40 +05305576 cxgb4_iov_configure(adapter->pdev, 0);
Hariprasad Shenai78294512016-08-11 21:06:23 +05305577 }
5578#endif
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005579}
5580
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05305581/* "Shutdown" quiesces the device, stopping Ingress Packet and Interrupt
5582 * delivery. This is essentially a stripped down version of the PCI remove()
5583 * function where we do the minimal amount of work necessary to shutdown any
5584 * further activity.
5585 */
5586static void shutdown_one(struct pci_dev *pdev)
5587{
5588 struct adapter *adapter = pci_get_drvdata(pdev);
5589
5590 /* As with remove_one() above (see extended comment), we only want do
5591 * do cleanup on PCI Devices which went all the way through init_one()
5592 * ...
5593 */
5594 if (!adapter) {
5595 pci_release_regions(pdev);
5596 return;
5597 }
5598
Ganesh Goudare1f61982017-09-21 12:50:47 +05305599 adapter->flags |= SHUTTING_DOWN;
5600
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05305601 if (adapter->pf == 4) {
5602 int i;
5603
5604 for_each_port(adapter, i)
5605 if (adapter->port[i]->reg_state == NETREG_REGISTERED)
5606 cxgb_close(adapter->port[i]);
5607
Guilherme G. Piccoli6a146f32017-07-10 10:55:46 -03005608 if (is_uld(adapter)) {
5609 detach_ulds(adapter);
5610 t4_uld_clean_up(adapter);
5611 }
5612
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05305613 disable_interrupts(adapter);
5614 disable_msi(adapter);
5615
5616 t4_sge_stop(adapter);
5617 if (adapter->flags & FW_OK)
5618 t4_fw_bye(adapter, adapter->mbox);
5619 }
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05305620}
5621
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005622static struct pci_driver cxgb4_driver = {
5623 .name = KBUILD_MODNAME,
5624 .id_table = cxgb4_pci_tbl,
5625 .probe = init_one,
Bill Pemberton91744942012-12-03 09:23:02 -05005626 .remove = remove_one,
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05305627 .shutdown = shutdown_one,
Hariprasad Shenaib6244202016-06-14 14:39:31 +05305628#ifdef CONFIG_PCI_IOV
5629 .sriov_configure = cxgb4_iov_configure,
5630#endif
Dimitris Michailidis204dc3c2010-06-18 10:05:29 +00005631 .err_handler = &cxgb4_eeh,
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005632};
5633
5634static int __init cxgb4_init_module(void)
5635{
5636 int ret;
5637
5638 /* Debugfs support is optional, just warn if this fails */
5639 cxgb4_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
5640 if (!cxgb4_debugfs_root)
Joe Perches428ac432013-01-06 13:34:49 +00005641 pr_warn("could not create debugfs entry, continuing\n");
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005642
5643 ret = pci_register_driver(&cxgb4_driver);
Anish Bhatt29aaee62014-08-20 13:44:06 -07005644 if (ret < 0)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005645 debugfs_remove(cxgb4_debugfs_root);
Vipul Pandya01bcca62013-07-04 16:10:46 +05305646
Anish Bhatt1bb60372014-10-14 20:07:22 -07005647#if IS_ENABLED(CONFIG_IPV6)
Anish Bhattb5a02f52015-01-14 15:17:34 -08005648 if (!inet6addr_registered) {
5649 register_inet6addr_notifier(&cxgb4_inet6addr_notifier);
5650 inet6addr_registered = true;
5651 }
Anish Bhatt1bb60372014-10-14 20:07:22 -07005652#endif
Vipul Pandya01bcca62013-07-04 16:10:46 +05305653
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005654 return ret;
5655}
5656
5657static void __exit cxgb4_cleanup_module(void)
5658{
Anish Bhatt1bb60372014-10-14 20:07:22 -07005659#if IS_ENABLED(CONFIG_IPV6)
Hariprasad Shenai1793c792015-01-21 20:57:52 +05305660 if (inet6addr_registered) {
Anish Bhattb5a02f52015-01-14 15:17:34 -08005661 unregister_inet6addr_notifier(&cxgb4_inet6addr_notifier);
5662 inet6addr_registered = false;
5663 }
Anish Bhatt1bb60372014-10-14 20:07:22 -07005664#endif
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005665 pci_unregister_driver(&cxgb4_driver);
5666 debugfs_remove(cxgb4_debugfs_root); /* NULL ok */
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005667}
5668
5669module_init(cxgb4_init_module);
5670module_exit(cxgb4_cleanup_module);