blob: 13199317c8e00336f0eb2962ffb852f16d0009a8 [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>
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +000068
69#include "cxgb4.h"
Rahul Lakkireddyd57fd6c2016-09-20 17:13:06 +053070#include "cxgb4_filter.h"
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +000071#include "t4_regs.h"
Hariprasad Shenaif612b812015-01-05 16:30:43 +053072#include "t4_values.h"
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +000073#include "t4_msg.h"
74#include "t4fw_api.h"
Hariprasad Shenaicd6c2f12015-01-27 20:12:52 +053075#include "t4fw_version.h"
Anish Bhatt688848b2014-06-19 21:37:13 -070076#include "cxgb4_dcb.h"
Hariprasad Shenaifd88b312014-11-07 09:35:23 +053077#include "cxgb4_debugfs.h"
Anish Bhattb5a02f52015-01-14 15:17:34 -080078#include "clip_tbl.h"
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +000079#include "l2t.h"
Rahul Lakkireddyb72a32d2016-08-22 16:29:06 +053080#include "sched.h"
Rahul Lakkireddyd8931842016-09-20 17:13:09 +053081#include "cxgb4_tc_u32.h"
Atul Guptaa45695042017-07-04 16:46:20 +053082#include "cxgb4_ptp.h"
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +000083
Hariprasad Shenai812034f2015-04-06 20:23:23 +053084char cxgb4_driver_name[] = KBUILD_MODNAME;
85
Vipul Pandya01bcca62013-07-04 16:10:46 +053086#ifdef DRV_VERSION
87#undef DRV_VERSION
88#endif
Santosh Rastapur3a7f8552013-03-14 05:08:55 +000089#define DRV_VERSION "2.0.0-ko"
Hariprasad Shenai812034f2015-04-06 20:23:23 +053090const char cxgb4_driver_version[] = DRV_VERSION;
Hariprasad Shenai52a5f842015-10-21 14:39:54 +053091#define DRV_DESC "Chelsio T4/T5/T6 Network Driver"
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +000092
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +000093#define DFLT_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK | \
94 NETIF_MSG_TIMER | NETIF_MSG_IFDOWN | NETIF_MSG_IFUP |\
95 NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR)
96
Hariprasad Shenai3fedeab2014-11-25 08:33:58 +053097/* Macros needed to support the PCI Device ID Table ...
98 */
99#define CH_PCI_DEVICE_ID_TABLE_DEFINE_BEGIN \
Hariprasad Shenai768ffc62015-03-19 22:27:36 +0530100 static const struct pci_device_id cxgb4_pci_tbl[] = {
Hariprasad Shenai3fedeab2014-11-25 08:33:58 +0530101#define CH_PCI_DEVICE_ID_FUNCTION 0x4
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000102
Hariprasad Shenai3fedeab2014-11-25 08:33:58 +0530103/* Include PCI Device IDs for both PF4 and PF0-3 so our PCI probe() routine is
104 * called for both.
105 */
106#define CH_PCI_DEVICE_ID_FUNCTION2 0x0
107
108#define CH_PCI_ID_TABLE_ENTRY(devid) \
109 {PCI_VDEVICE(CHELSIO, (devid)), 4}
110
111#define CH_PCI_DEVICE_ID_TABLE_DEFINE_END \
112 { 0, } \
113 }
114
115#include "t4_pci_id_tbl.h"
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000116
Hariprasad Shenai16e47622013-12-03 17:05:58 +0530117#define FW4_FNAME "cxgb4/t4fw.bin"
Santosh Rastapur0a57a532013-03-14 05:08:49 +0000118#define FW5_FNAME "cxgb4/t5fw.bin"
Hariprasad Shenai3ccc6cf2015-06-02 13:59:39 +0530119#define FW6_FNAME "cxgb4/t6fw.bin"
Hariprasad Shenai16e47622013-12-03 17:05:58 +0530120#define FW4_CFNAME "cxgb4/t4-config.txt"
Santosh Rastapur0a57a532013-03-14 05:08:49 +0000121#define FW5_CFNAME "cxgb4/t5-config.txt"
Hariprasad Shenai3ccc6cf2015-06-02 13:59:39 +0530122#define FW6_CFNAME "cxgb4/t6-config.txt"
Hariprasad Shenai01b69612015-05-22 21:58:21 +0530123#define PHY_AQ1202_FIRMWARE "cxgb4/aq1202_fw.cld"
124#define PHY_BCM84834_FIRMWARE "cxgb4/bcm8483.bin"
125#define PHY_AQ1202_DEVICEID 0x4409
126#define PHY_BCM84834_DEVICEID 0x4486
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000127
128MODULE_DESCRIPTION(DRV_DESC);
129MODULE_AUTHOR("Chelsio Communications");
130MODULE_LICENSE("Dual BSD/GPL");
131MODULE_VERSION(DRV_VERSION);
132MODULE_DEVICE_TABLE(pci, cxgb4_pci_tbl);
Hariprasad Shenai16e47622013-12-03 17:05:58 +0530133MODULE_FIRMWARE(FW4_FNAME);
Santosh Rastapur0a57a532013-03-14 05:08:49 +0000134MODULE_FIRMWARE(FW5_FNAME);
Hariprasad Shenai52a5f842015-10-21 14:39:54 +0530135MODULE_FIRMWARE(FW6_FNAME);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000136
Vipul Pandya636f9d32012-09-26 02:39:39 +0000137/*
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000138 * The driver uses the best interrupt scheme available on a platform in the
139 * order MSI-X, MSI, legacy INTx interrupts. This parameter determines which
140 * of these schemes the driver may consider as follows:
141 *
142 * msi = 2: choose from among all three options
143 * msi = 1: only consider MSI and INTx interrupts
144 * msi = 0: force INTx interrupts
145 */
146static int msi = 2;
147
148module_param(msi, int, 0644);
149MODULE_PARM_DESC(msi, "whether to use INTx (0), MSI (1) or MSI-X (2)");
150
151/*
Vipul Pandya636f9d32012-09-26 02:39:39 +0000152 * Normally we tell the chip to deliver Ingress Packets into our DMA buffers
153 * offset by 2 bytes in order to have the IP headers line up on 4-byte
154 * boundaries. This is a requirement for many architectures which will throw
155 * a machine check fault if an attempt is made to access one of the 4-byte IP
156 * header fields on a non-4-byte boundary. And it's a major performance issue
157 * even on some architectures which allow it like some implementations of the
158 * x86 ISA. However, some architectures don't mind this and for some very
159 * edge-case performance sensitive applications (like forwarding large volumes
160 * of small packets), setting this DMA offset to 0 will decrease the number of
161 * PCI-E Bus transfers enough to measurably affect performance.
162 */
163static int rx_dma_offset = 2;
164
Anish Bhatt688848b2014-06-19 21:37:13 -0700165/* TX Queue select used to determine what algorithm to use for selecting TX
166 * queue. Select between the kernel provided function (select_queue=0) or user
167 * cxgb_select_queue function (select_queue=1)
168 *
169 * Default: select_queue=0
170 */
171static int select_queue;
172module_param(select_queue, int, 0644);
173MODULE_PARM_DESC(select_queue,
174 "Select between kernel provided method of selecting or driver method of selecting TX queue. Default is kernel method.");
175
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000176static struct dentry *cxgb4_debugfs_root;
177
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +0530178LIST_HEAD(adapter_list);
179DEFINE_MUTEX(uld_mutex);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000180
181static void link_report(struct net_device *dev)
182{
183 if (!netif_carrier_ok(dev))
184 netdev_info(dev, "link down\n");
185 else {
186 static const char *fc[] = { "no", "Rx", "Tx", "Tx/Rx" };
187
Hariprasad Shenai85412252015-10-01 13:48:48 +0530188 const char *s;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000189 const struct port_info *p = netdev_priv(dev);
190
191 switch (p->link_cfg.speed) {
Ben Hutchingse8b39012014-02-23 00:03:24 +0000192 case 100:
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000193 s = "100Mbps";
194 break;
Ganesh Goudar5e78f7f2017-01-06 16:51:46 +0530195 case 1000:
196 s = "1Gbps";
197 break;
198 case 10000:
199 s = "10Gbps";
200 break;
201 case 25000:
202 s = "25Gbps";
203 break;
Ben Hutchingse8b39012014-02-23 00:03:24 +0000204 case 40000:
Kumar Sanghvi72aca4b2014-02-18 17:56:08 +0530205 s = "40Gbps";
206 break;
Ganesh Goudar5e78f7f2017-01-06 16:51:46 +0530207 case 100000:
208 s = "100Gbps";
209 break;
Hariprasad Shenai85412252015-10-01 13:48:48 +0530210 default:
211 pr_info("%s: unsupported speed: %d\n",
212 dev->name, p->link_cfg.speed);
213 return;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000214 }
215
216 netdev_info(dev, "link up, %s, full-duplex, %s PAUSE\n", s,
217 fc[p->link_cfg.fc]);
218 }
219}
220
Anish Bhatt688848b2014-06-19 21:37:13 -0700221#ifdef CONFIG_CHELSIO_T4_DCB
222/* Set up/tear down Data Center Bridging Priority mapping for a net device. */
223static void dcb_tx_queue_prio_enable(struct net_device *dev, int enable)
224{
225 struct port_info *pi = netdev_priv(dev);
226 struct adapter *adap = pi->adapter;
227 struct sge_eth_txq *txq = &adap->sge.ethtxq[pi->first_qset];
228 int i;
229
230 /* We use a simple mapping of Port TX Queue Index to DCB
231 * Priority when we're enabling DCB.
232 */
233 for (i = 0; i < pi->nqsets; i++, txq++) {
234 u32 name, value;
235 int err;
236
Hariprasad Shenai51678652014-11-21 12:52:02 +0530237 name = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DMAQ) |
238 FW_PARAMS_PARAM_X_V(
239 FW_PARAMS_PARAM_DMAQ_EQ_DCBPRIO_ETH) |
240 FW_PARAMS_PARAM_YZ_V(txq->q.cntxt_id));
Anish Bhatt688848b2014-06-19 21:37:13 -0700241 value = enable ? i : 0xffffffff;
242
243 /* Since we can be called while atomic (from "interrupt
244 * level") we need to issue the Set Parameters Commannd
245 * without sleeping (timeout < 0).
246 */
Hariprasad Shenaib2612722015-05-27 22:30:24 +0530247 err = t4_set_params_timeout(adap, adap->mbox, adap->pf, 0, 1,
Hariprasad Shenai01b69612015-05-22 21:58:21 +0530248 &name, &value,
249 -FW_CMD_MAX_TIMEOUT);
Anish Bhatt688848b2014-06-19 21:37:13 -0700250
251 if (err)
252 dev_err(adap->pdev_dev,
253 "Can't %s DCB Priority on port %d, TX Queue %d: err=%d\n",
254 enable ? "set" : "unset", pi->port_id, i, -err);
Anish Bhatt10b00462014-08-07 16:14:03 -0700255 else
256 txq->dcb_prio = value;
Anish Bhatt688848b2014-06-19 21:37:13 -0700257 }
258}
Anish Bhatt688848b2014-06-19 21:37:13 -0700259
Baoyou Xie50935852016-09-25 14:10:09 +0800260static int cxgb4_dcb_enabled(const struct net_device *dev)
Hariprasad Shenai218d48e2016-05-05 11:05:39 +0530261{
Hariprasad Shenai218d48e2016-05-05 11:05:39 +0530262 struct port_info *pi = netdev_priv(dev);
263
264 if (!pi->dcb.enabled)
265 return 0;
266
267 return ((pi->dcb.state == CXGB4_DCB_STATE_FW_ALLSYNCED) ||
268 (pi->dcb.state == CXGB4_DCB_STATE_HOST));
Hariprasad Shenai218d48e2016-05-05 11:05:39 +0530269}
Arnd Bergmann7c70c4f2016-09-30 18:15:33 +0200270#endif /* CONFIG_CHELSIO_T4_DCB */
Hariprasad Shenai218d48e2016-05-05 11:05:39 +0530271
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000272void t4_os_link_changed(struct adapter *adapter, int port_id, int link_stat)
273{
274 struct net_device *dev = adapter->port[port_id];
275
276 /* Skip changes from disabled ports. */
277 if (netif_running(dev) && link_stat != netif_carrier_ok(dev)) {
278 if (link_stat)
279 netif_carrier_on(dev);
Anish Bhatt688848b2014-06-19 21:37:13 -0700280 else {
281#ifdef CONFIG_CHELSIO_T4_DCB
Hariprasad Shenai218d48e2016-05-05 11:05:39 +0530282 if (cxgb4_dcb_enabled(dev)) {
283 cxgb4_dcb_state_init(dev);
284 dcb_tx_queue_prio_enable(dev, false);
285 }
Anish Bhatt688848b2014-06-19 21:37:13 -0700286#endif /* CONFIG_CHELSIO_T4_DCB */
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000287 netif_carrier_off(dev);
Anish Bhatt688848b2014-06-19 21:37:13 -0700288 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000289
290 link_report(dev);
291 }
292}
293
294void t4_os_portmod_changed(const struct adapter *adap, int port_id)
295{
296 static const char *mod_str[] = {
Dimitris Michailidisa0881ca2010-06-18 10:05:34 +0000297 NULL, "LR", "SR", "ER", "passive DA", "active DA", "LRM"
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000298 };
299
300 const struct net_device *dev = adap->port[port_id];
301 const struct port_info *pi = netdev_priv(dev);
302
303 if (pi->mod_type == FW_PORT_MOD_TYPE_NONE)
304 netdev_info(dev, "port module unplugged\n");
Dimitris Michailidisa0881ca2010-06-18 10:05:34 +0000305 else if (pi->mod_type < ARRAY_SIZE(mod_str))
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000306 netdev_info(dev, "%s module inserted\n", mod_str[pi->mod_type]);
Hariprasad Shenaibe81a2d2016-04-26 20:10:25 +0530307 else if (pi->mod_type == FW_PORT_MOD_TYPE_NOTSUPPORTED)
308 netdev_info(dev, "%s: unsupported port module inserted\n",
309 dev->name);
310 else if (pi->mod_type == FW_PORT_MOD_TYPE_UNKNOWN)
311 netdev_info(dev, "%s: unknown port module inserted\n",
312 dev->name);
313 else if (pi->mod_type == FW_PORT_MOD_TYPE_ERROR)
314 netdev_info(dev, "%s: transceiver module error\n", dev->name);
315 else
316 netdev_info(dev, "%s: unknown module type %d inserted\n",
317 dev->name, pi->mod_type);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000318}
319
Vipul Pandya3069ee9b2012-05-18 15:29:26 +0530320int dbfifo_int_thresh = 10; /* 10 == 640 entry threshold */
321module_param(dbfifo_int_thresh, int, 0644);
322MODULE_PARM_DESC(dbfifo_int_thresh, "doorbell fifo interrupt threshold");
323
Vipul Pandya404d9e32012-10-08 02:59:43 +0000324/*
325 * usecs to sleep while draining the dbfifo
326 */
327static int dbfifo_drain_delay = 1000;
Vipul Pandya3069ee9b2012-05-18 15:29:26 +0530328module_param(dbfifo_drain_delay, int, 0644);
329MODULE_PARM_DESC(dbfifo_drain_delay,
330 "usecs to sleep while draining the dbfifo");
331
Hariprasad Shenaifc08a012016-02-16 10:07:09 +0530332static inline int cxgb4_set_addr_hash(struct port_info *pi)
333{
334 struct adapter *adap = pi->adapter;
335 u64 vec = 0;
336 bool ucast = false;
337 struct hash_mac_addr *entry;
338
339 /* Calculate the hash vector for the updated list and program it */
340 list_for_each_entry(entry, &adap->mac_hlist, list) {
341 ucast |= is_unicast_ether_addr(entry->addr);
342 vec |= (1ULL << hash_mac_addr(entry->addr));
343 }
344 return t4_set_addr_hash(adap, adap->mbox, pi->viid, ucast,
345 vec, false);
346}
347
348static int cxgb4_mac_sync(struct net_device *netdev, const u8 *mac_addr)
349{
350 struct port_info *pi = netdev_priv(netdev);
351 struct adapter *adap = pi->adapter;
352 int ret;
353 u64 mhash = 0;
354 u64 uhash = 0;
355 bool free = false;
356 bool ucast = is_unicast_ether_addr(mac_addr);
357 const u8 *maclist[1] = {mac_addr};
358 struct hash_mac_addr *new_entry;
359
360 ret = t4_alloc_mac_filt(adap, adap->mbox, pi->viid, free, 1, maclist,
361 NULL, ucast ? &uhash : &mhash, false);
362 if (ret < 0)
363 goto out;
364 /* if hash != 0, then add the addr to hash addr list
365 * so on the end we will calculate the hash for the
366 * list and program it
367 */
368 if (uhash || mhash) {
369 new_entry = kzalloc(sizeof(*new_entry), GFP_ATOMIC);
370 if (!new_entry)
371 return -ENOMEM;
372 ether_addr_copy(new_entry->addr, mac_addr);
373 list_add_tail(&new_entry->list, &adap->mac_hlist);
374 ret = cxgb4_set_addr_hash(pi);
375 }
376out:
377 return ret < 0 ? ret : 0;
378}
379
380static int cxgb4_mac_unsync(struct net_device *netdev, const u8 *mac_addr)
381{
382 struct port_info *pi = netdev_priv(netdev);
383 struct adapter *adap = pi->adapter;
384 int ret;
385 const u8 *maclist[1] = {mac_addr};
386 struct hash_mac_addr *entry, *tmp;
387
388 /* If the MAC address to be removed is in the hash addr
389 * list, delete it from the list and update hash vector
390 */
391 list_for_each_entry_safe(entry, tmp, &adap->mac_hlist, list) {
392 if (ether_addr_equal(entry->addr, mac_addr)) {
393 list_del(&entry->list);
394 kfree(entry);
395 return cxgb4_set_addr_hash(pi);
396 }
397 }
398
399 ret = t4_free_mac_filt(adap, adap->mbox, pi->viid, 1, maclist, false);
400 return ret < 0 ? -EINVAL : 0;
401}
402
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000403/*
404 * Set Rx properties of a port, such as promiscruity, address filters, and MTU.
405 * If @mtu is -1 it is left unchanged.
406 */
407static int set_rxmode(struct net_device *dev, int mtu, bool sleep_ok)
408{
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000409 struct port_info *pi = netdev_priv(dev);
Hariprasad Shenaifc08a012016-02-16 10:07:09 +0530410 struct adapter *adapter = pi->adapter;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000411
Hariprasad Shenaid01f7ab2016-06-14 14:39:32 +0530412 __dev_uc_sync(dev, cxgb4_mac_sync, cxgb4_mac_unsync);
413 __dev_mc_sync(dev, cxgb4_mac_sync, cxgb4_mac_unsync);
Hariprasad Shenaifc08a012016-02-16 10:07:09 +0530414
415 return t4_set_rxmode(adapter, adapter->mbox, pi->viid, mtu,
416 (dev->flags & IFF_PROMISC) ? 1 : 0,
417 (dev->flags & IFF_ALLMULTI) ? 1 : 0, 1, -1,
418 sleep_ok);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000419}
420
421/**
422 * link_start - enable a port
423 * @dev: the port to enable
424 *
425 * Performs the MAC and PHY actions needed to enable a port.
426 */
427static int link_start(struct net_device *dev)
428{
429 int ret;
430 struct port_info *pi = netdev_priv(dev);
Hariprasad Shenaib2612722015-05-27 22:30:24 +0530431 unsigned int mb = pi->adapter->pf;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000432
433 /*
434 * We do not set address filters and promiscuity here, the stack does
435 * that step explicitly.
436 */
Dimitris Michailidis060e0c72010-08-02 13:19:21 +0000437 ret = t4_set_rxmode(pi->adapter, mb, pi->viid, dev->mtu, -1, -1, -1,
Patrick McHardyf6469682013-04-19 02:04:27 +0000438 !!(dev->features & NETIF_F_HW_VLAN_CTAG_RX), true);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000439 if (ret == 0) {
Dimitris Michailidis060e0c72010-08-02 13:19:21 +0000440 ret = t4_change_mac(pi->adapter, mb, pi->viid,
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000441 pi->xact_addr_filt, dev->dev_addr, true,
Dimitris Michailidisb6bd29e2010-05-18 10:07:11 +0000442 true);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000443 if (ret >= 0) {
444 pi->xact_addr_filt = ret;
445 ret = 0;
446 }
447 }
448 if (ret == 0)
Hariprasad Shenai4036da92015-06-05 14:24:49 +0530449 ret = t4_link_l1cfg(pi->adapter, mb, pi->tx_chan,
Dimitris Michailidis060e0c72010-08-02 13:19:21 +0000450 &pi->link_cfg);
Anish Bhatt30f00842014-08-05 16:05:23 -0700451 if (ret == 0) {
452 local_bh_disable();
Anish Bhatt688848b2014-06-19 21:37:13 -0700453 ret = t4_enable_vi_params(pi->adapter, mb, pi->viid, true,
454 true, CXGB4_DCB_ENABLED);
Anish Bhatt30f00842014-08-05 16:05:23 -0700455 local_bh_enable();
456 }
Anish Bhatt688848b2014-06-19 21:37:13 -0700457
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000458 return ret;
459}
460
Anish Bhatt688848b2014-06-19 21:37:13 -0700461#ifdef CONFIG_CHELSIO_T4_DCB
462/* Handle a Data Center Bridging update message from the firmware. */
463static void dcb_rpl(struct adapter *adap, const struct fw_port_cmd *pcmd)
464{
Hariprasad Shenai2b5fb1f2014-11-21 12:52:04 +0530465 int port = FW_PORT_CMD_PORTID_G(ntohl(pcmd->op_to_portid));
Hariprasad Shenai134491f2016-04-26 20:10:27 +0530466 struct net_device *dev = adap->port[adap->chan_map[port]];
Anish Bhatt688848b2014-06-19 21:37:13 -0700467 int old_dcb_enabled = cxgb4_dcb_enabled(dev);
468 int new_dcb_enabled;
469
470 cxgb4_dcb_handle_fw_update(adap, pcmd);
471 new_dcb_enabled = cxgb4_dcb_enabled(dev);
472
473 /* If the DCB has become enabled or disabled on the port then we're
474 * going to need to set up/tear down DCB Priority parameters for the
475 * TX Queues associated with the port.
476 */
477 if (new_dcb_enabled != old_dcb_enabled)
478 dcb_tx_queue_prio_enable(dev, new_dcb_enabled);
479}
480#endif /* CONFIG_CHELSIO_T4_DCB */
481
Vipul Pandyaf2b7e782012-12-10 09:30:52 +0000482/* Response queue handler for the FW event queue.
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000483 */
484static int fwevtq_handler(struct sge_rspq *q, const __be64 *rsp,
485 const struct pkt_gl *gl)
486{
487 u8 opcode = ((const struct rss_header *)rsp)->opcode;
488
489 rsp++; /* skip RSS header */
Vipul Pandyab407a4a2013-04-29 04:04:40 +0000490
491 /* FW can send EGR_UPDATEs encapsulated in a CPL_FW4_MSG.
492 */
493 if (unlikely(opcode == CPL_FW4_MSG &&
494 ((const struct cpl_fw4_msg *)rsp)->type == FW_TYPE_RSSCPL)) {
495 rsp++;
496 opcode = ((const struct rss_header *)rsp)->opcode;
497 rsp++;
498 if (opcode != CPL_SGE_EGR_UPDATE) {
499 dev_err(q->adap->pdev_dev, "unexpected FW4/CPL %#x on FW event queue\n"
500 , opcode);
501 goto out;
502 }
503 }
504
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000505 if (likely(opcode == CPL_SGE_EGR_UPDATE)) {
506 const struct cpl_sge_egr_update *p = (void *)rsp;
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -0800507 unsigned int qid = EGR_QID_G(ntohl(p->opcode_qid));
Dimitris Michailidise46dab42010-08-23 17:20:58 +0000508 struct sge_txq *txq;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000509
Dimitris Michailidise46dab42010-08-23 17:20:58 +0000510 txq = q->adap->sge.egr_map[qid - q->adap->sge.egr_start];
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000511 txq->restarts++;
Hariprasad Shenaiab677ff2016-11-18 16:37:40 +0530512 if (txq->q_type == CXGB4_TXQ_ETH) {
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000513 struct sge_eth_txq *eq;
514
515 eq = container_of(txq, struct sge_eth_txq, q);
516 netif_tx_wake_queue(eq->txq);
517 } else {
Hariprasad Shenaiab677ff2016-11-18 16:37:40 +0530518 struct sge_uld_txq *oq;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000519
Hariprasad Shenaiab677ff2016-11-18 16:37:40 +0530520 oq = container_of(txq, struct sge_uld_txq, q);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000521 tasklet_schedule(&oq->qresume_tsk);
522 }
523 } else if (opcode == CPL_FW6_MSG || opcode == CPL_FW4_MSG) {
524 const struct cpl_fw6_msg *p = (void *)rsp;
525
Anish Bhatt688848b2014-06-19 21:37:13 -0700526#ifdef CONFIG_CHELSIO_T4_DCB
527 const struct fw_port_cmd *pcmd = (const void *)p->data;
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530528 unsigned int cmd = FW_CMD_OP_G(ntohl(pcmd->op_to_portid));
Anish Bhatt688848b2014-06-19 21:37:13 -0700529 unsigned int action =
Hariprasad Shenai2b5fb1f2014-11-21 12:52:04 +0530530 FW_PORT_CMD_ACTION_G(ntohl(pcmd->action_to_len16));
Anish Bhatt688848b2014-06-19 21:37:13 -0700531
532 if (cmd == FW_PORT_CMD &&
533 action == FW_PORT_ACTION_GET_PORT_INFO) {
Hariprasad Shenai2b5fb1f2014-11-21 12:52:04 +0530534 int port = FW_PORT_CMD_PORTID_G(
Anish Bhatt688848b2014-06-19 21:37:13 -0700535 be32_to_cpu(pcmd->op_to_portid));
Hariprasad Shenai134491f2016-04-26 20:10:27 +0530536 struct net_device *dev =
537 q->adap->port[q->adap->chan_map[port]];
Anish Bhatt688848b2014-06-19 21:37:13 -0700538 int state_input = ((pcmd->u.info.dcbxdis_pkd &
Hariprasad Shenai2b5fb1f2014-11-21 12:52:04 +0530539 FW_PORT_CMD_DCBXDIS_F)
Anish Bhatt688848b2014-06-19 21:37:13 -0700540 ? CXGB4_DCB_INPUT_FW_DISABLED
541 : CXGB4_DCB_INPUT_FW_ENABLED);
542
543 cxgb4_dcb_state_fsm(dev, state_input);
544 }
545
546 if (cmd == FW_PORT_CMD &&
547 action == FW_PORT_ACTION_L2_DCB_CFG)
548 dcb_rpl(q->adap, pcmd);
549 else
550#endif
551 if (p->type == 0)
552 t4_handle_fw_rpl(q->adap, p->data);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000553 } else if (opcode == CPL_L2T_WRITE_RPL) {
554 const struct cpl_l2t_write_rpl *p = (void *)rsp;
555
556 do_l2t_write_rpl(q->adap, p);
Vipul Pandyaf2b7e782012-12-10 09:30:52 +0000557 } else if (opcode == CPL_SET_TCB_RPL) {
558 const struct cpl_set_tcb_rpl *p = (void *)rsp;
559
560 filter_rpl(q->adap, p);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000561 } else
562 dev_err(q->adap->pdev_dev,
563 "unexpected CPL %#x on FW event queue\n", opcode);
Vipul Pandyab407a4a2013-04-29 04:04:40 +0000564out:
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000565 return 0;
566}
567
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000568static void disable_msi(struct adapter *adapter)
569{
570 if (adapter->flags & USING_MSIX) {
571 pci_disable_msix(adapter->pdev);
572 adapter->flags &= ~USING_MSIX;
573 } else if (adapter->flags & USING_MSI) {
574 pci_disable_msi(adapter->pdev);
575 adapter->flags &= ~USING_MSI;
576 }
577}
578
579/*
580 * Interrupt handler for non-data events used with MSI-X.
581 */
582static irqreturn_t t4_nondata_intr(int irq, void *cookie)
583{
584 struct adapter *adap = cookie;
Hariprasad Shenai0d804332015-01-05 16:30:47 +0530585 u32 v = t4_read_reg(adap, MYPF_REG(PL_PF_INT_CAUSE_A));
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000586
Hariprasad Shenai0d804332015-01-05 16:30:47 +0530587 if (v & PFSW_F) {
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000588 adap->swintr = 1;
Hariprasad Shenai0d804332015-01-05 16:30:47 +0530589 t4_write_reg(adap, MYPF_REG(PL_PF_INT_CAUSE_A), v);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000590 }
Hariprasad Shenaic3c7b122015-04-15 02:02:34 +0530591 if (adap->flags & MASTER_PF)
592 t4_slow_intr_handler(adap);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000593 return IRQ_HANDLED;
594}
595
596/*
597 * Name the MSI-X interrupts.
598 */
599static void name_msix_vecs(struct adapter *adap)
600{
Dimitris Michailidisba278162010-12-14 21:36:50 +0000601 int i, j, msi_idx = 2, n = sizeof(adap->msix_info[0].desc);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000602
603 /* non-data interrupts */
Dimitris Michailidisb1a3c2b2010-12-14 21:36:51 +0000604 snprintf(adap->msix_info[0].desc, n, "%s", adap->port[0]->name);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000605
606 /* FW events */
Dimitris Michailidisb1a3c2b2010-12-14 21:36:51 +0000607 snprintf(adap->msix_info[1].desc, n, "%s-FWeventq",
608 adap->port[0]->name);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000609
610 /* Ethernet queues */
611 for_each_port(adap, j) {
612 struct net_device *d = adap->port[j];
613 const struct port_info *pi = netdev_priv(d);
614
Dimitris Michailidisba278162010-12-14 21:36:50 +0000615 for (i = 0; i < pi->nqsets; i++, msi_idx++)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000616 snprintf(adap->msix_info[msi_idx].desc, n, "%s-Rx%d",
617 d->name, i);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000618 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000619}
620
621static int request_msix_queue_irqs(struct adapter *adap)
622{
623 struct sge *s = &adap->sge;
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +0530624 int err, ethqidx;
Hariprasad Shenaicf38be62014-06-06 21:40:42 +0530625 int msi_index = 2;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000626
627 err = request_irq(adap->msix_info[1].vec, t4_sge_intr_msix, 0,
628 adap->msix_info[1].desc, &s->fw_evtq);
629 if (err)
630 return err;
631
632 for_each_ethrxq(s, ethqidx) {
Vipul Pandya404d9e32012-10-08 02:59:43 +0000633 err = request_irq(adap->msix_info[msi_index].vec,
634 t4_sge_intr_msix, 0,
635 adap->msix_info[msi_index].desc,
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000636 &s->ethrxq[ethqidx].rspq);
637 if (err)
638 goto unwind;
Vipul Pandya404d9e32012-10-08 02:59:43 +0000639 msi_index++;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000640 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000641 return 0;
642
643unwind:
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000644 while (--ethqidx >= 0)
Vipul Pandya404d9e32012-10-08 02:59:43 +0000645 free_irq(adap->msix_info[--msi_index].vec,
646 &s->ethrxq[ethqidx].rspq);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000647 free_irq(adap->msix_info[1].vec, &s->fw_evtq);
648 return err;
649}
650
651static void free_msix_queue_irqs(struct adapter *adap)
652{
Vipul Pandya404d9e32012-10-08 02:59:43 +0000653 int i, msi_index = 2;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000654 struct sge *s = &adap->sge;
655
656 free_irq(adap->msix_info[1].vec, &s->fw_evtq);
657 for_each_ethrxq(s, i)
Vipul Pandya404d9e32012-10-08 02:59:43 +0000658 free_irq(adap->msix_info[msi_index++].vec, &s->ethrxq[i].rspq);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000659}
660
661/**
Hariprasad Shenai812034f2015-04-06 20:23:23 +0530662 * cxgb4_write_rss - write the RSS table for a given port
Dimitris Michailidis671b0062010-07-11 12:01:17 +0000663 * @pi: the port
664 * @queues: array of queue indices for RSS
665 *
666 * Sets up the portion of the HW RSS table for the port's VI to distribute
667 * packets to the Rx queues in @queues.
Hariprasad Shenaic035e182015-05-06 19:48:37 +0530668 * Should never be called before setting up sge eth rx queues
Dimitris Michailidis671b0062010-07-11 12:01:17 +0000669 */
Hariprasad Shenai812034f2015-04-06 20:23:23 +0530670int cxgb4_write_rss(const struct port_info *pi, const u16 *queues)
Dimitris Michailidis671b0062010-07-11 12:01:17 +0000671{
672 u16 *rss;
673 int i, err;
Hariprasad Shenaic035e182015-05-06 19:48:37 +0530674 struct adapter *adapter = pi->adapter;
675 const struct sge_eth_rxq *rxq;
Dimitris Michailidis671b0062010-07-11 12:01:17 +0000676
Hariprasad Shenaic035e182015-05-06 19:48:37 +0530677 rxq = &adapter->sge.ethrxq[pi->first_qset];
Dimitris Michailidis671b0062010-07-11 12:01:17 +0000678 rss = kmalloc(pi->rss_size * sizeof(u16), GFP_KERNEL);
679 if (!rss)
680 return -ENOMEM;
681
682 /* map the queue indices to queue ids */
683 for (i = 0; i < pi->rss_size; i++, queues++)
Hariprasad Shenaic035e182015-05-06 19:48:37 +0530684 rss[i] = rxq[*queues].rspq.abs_id;
Dimitris Michailidis671b0062010-07-11 12:01:17 +0000685
Hariprasad Shenaib2612722015-05-27 22:30:24 +0530686 err = t4_config_rss_range(adapter, adapter->pf, pi->viid, 0,
Dimitris Michailidis060e0c72010-08-02 13:19:21 +0000687 pi->rss_size, rss, pi->rss_size);
Hariprasad Shenaic035e182015-05-06 19:48:37 +0530688 /* If Tunnel All Lookup isn't specified in the global RSS
689 * Configuration, then we need to specify a default Ingress
690 * Queue for any ingress packets which aren't hashed. We'll
691 * use our first ingress queue ...
692 */
693 if (!err)
694 err = t4_config_vi_rss(adapter, adapter->mbox, pi->viid,
695 FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN_F |
696 FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN_F |
697 FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN_F |
698 FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN_F |
699 FW_RSS_VI_CONFIG_CMD_UDPEN_F,
700 rss[0]);
Dimitris Michailidis671b0062010-07-11 12:01:17 +0000701 kfree(rss);
702 return err;
703}
704
705/**
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000706 * setup_rss - configure RSS
707 * @adap: the adapter
708 *
Dimitris Michailidis671b0062010-07-11 12:01:17 +0000709 * Sets up RSS for each port.
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000710 */
711static int setup_rss(struct adapter *adap)
712{
Hariprasad Shenaic035e182015-05-06 19:48:37 +0530713 int i, j, err;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000714
715 for_each_port(adap, i) {
716 const struct port_info *pi = adap2pinfo(adap, i);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000717
Hariprasad Shenaic035e182015-05-06 19:48:37 +0530718 /* Fill default values with equal distribution */
719 for (j = 0; j < pi->rss_size; j++)
720 pi->rss[j] = j % pi->nqsets;
721
Hariprasad Shenai812034f2015-04-06 20:23:23 +0530722 err = cxgb4_write_rss(pi, pi->rss);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000723 if (err)
724 return err;
725 }
726 return 0;
727}
728
729/*
Dimitris Michailidise46dab42010-08-23 17:20:58 +0000730 * Return the channel of the ingress queue with the given qid.
731 */
732static unsigned int rxq_to_chan(const struct sge *p, unsigned int qid)
733{
734 qid -= p->ingr_start;
735 return netdev2pinfo(p->ingr_map[qid]->netdev)->tx_chan;
736}
737
738/*
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000739 * Wait until all NAPI handlers are descheduled.
740 */
741static void quiesce_rx(struct adapter *adap)
742{
743 int i;
744
Hariprasad Shenai4b8e27a2015-03-26 10:04:25 +0530745 for (i = 0; i < adap->sge.ingr_sz; i++) {
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000746 struct sge_rspq *q = adap->sge.ingr_map[i];
747
Eric Dumazet5226b7912017-02-02 11:44:27 -0800748 if (q && q->handler)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000749 napi_disable(&q->napi);
750 }
751}
752
Hariprasad Shenaib37987e2015-03-26 10:04:26 +0530753/* Disable interrupt and napi handler */
754static void disable_interrupts(struct adapter *adap)
755{
756 if (adap->flags & FULL_INIT_DONE) {
757 t4_intr_disable(adap);
758 if (adap->flags & USING_MSIX) {
759 free_msix_queue_irqs(adap);
760 free_irq(adap->msix_info[0].vec, adap);
761 } else {
762 free_irq(adap->pdev->irq, adap);
763 }
764 quiesce_rx(adap);
765 }
766}
767
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000768/*
769 * Enable NAPI scheduling and interrupt generation for all Rx queues.
770 */
771static void enable_rx(struct adapter *adap)
772{
773 int i;
774
Hariprasad Shenai4b8e27a2015-03-26 10:04:25 +0530775 for (i = 0; i < adap->sge.ingr_sz; i++) {
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000776 struct sge_rspq *q = adap->sge.ingr_map[i];
777
778 if (!q)
779 continue;
Eric Dumazet5226b7912017-02-02 11:44:27 -0800780 if (q->handler)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000781 napi_enable(&q->napi);
Eric Dumazet5226b7912017-02-02 11:44:27 -0800782
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000783 /* 0-increment GTS to start the timer and enable interrupts */
Hariprasad Shenaif612b812015-01-05 16:30:43 +0530784 t4_write_reg(adap, MYPF_REG(SGE_PF_GTS_A),
785 SEINTARM_V(q->intr_params) |
786 INGRESSQID_V(q->cntxt_id));
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000787 }
788}
789
Hariprasad Shenai1c6a5b02015-03-04 18:16:27 +0530790
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +0530791static int setup_fw_sge_queues(struct adapter *adap)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000792{
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000793 struct sge *s = &adap->sge;
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +0530794 int err = 0;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000795
Hariprasad Shenai4b8e27a2015-03-26 10:04:25 +0530796 bitmap_zero(s->starving_fl, s->egr_sz);
797 bitmap_zero(s->txq_maperr, s->egr_sz);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000798
799 if (adap->flags & USING_MSIX)
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +0530800 adap->msi_idx = 1; /* vector 0 is for non-queue interrupts */
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000801 else {
802 err = t4_sge_alloc_rxq(adap, &s->intrq, false, adap->port[0], 0,
Varun Prakash2337ba42016-02-14 23:02:41 +0530803 NULL, NULL, NULL, -1);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000804 if (err)
805 return err;
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +0530806 adap->msi_idx = -((int)s->intrq.abs_id + 1);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000807 }
808
809 err = t4_sge_alloc_rxq(adap, &s->fw_evtq, true, adap->port[0],
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +0530810 adap->msi_idx, NULL, fwevtq_handler, NULL, -1);
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +0530811 if (err)
812 t4_free_sge_resources(adap);
813 return err;
814}
815
816/**
817 * setup_sge_queues - configure SGE Tx/Rx/response queues
818 * @adap: the adapter
819 *
820 * Determines how many sets of SGE queues to use and initializes them.
821 * We support multiple queue sets per port if we have MSI-X, otherwise
822 * just one queue set per port.
823 */
824static int setup_sge_queues(struct adapter *adap)
825{
826 int err, i, j;
827 struct sge *s = &adap->sge;
Ganesh Goudard427cae2017-06-16 15:36:09 +0530828 struct sge_uld_rxq_info *rxq_info = NULL;
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +0530829 unsigned int cmplqid = 0;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000830
Ganesh Goudard427cae2017-06-16 15:36:09 +0530831 if (is_uld(adap))
832 rxq_info = s->uld_rxq_info[CXGB4_ULD_RDMA];
833
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000834 for_each_port(adap, i) {
835 struct net_device *dev = adap->port[i];
836 struct port_info *pi = netdev_priv(dev);
837 struct sge_eth_rxq *q = &s->ethrxq[pi->first_qset];
838 struct sge_eth_txq *t = &s->ethtxq[pi->first_qset];
839
840 for (j = 0; j < pi->nqsets; j++, q++) {
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +0530841 if (adap->msi_idx > 0)
842 adap->msi_idx++;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000843 err = t4_sge_alloc_rxq(adap, &q->rspq, false, dev,
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +0530844 adap->msi_idx, &q->fl,
Hariprasad Shenai145ef8a2015-05-05 14:59:52 +0530845 t4_ethrx_handler,
Varun Prakash2337ba42016-02-14 23:02:41 +0530846 NULL,
Arjun Vynipadath193c4c22017-06-23 19:14:36 +0530847 t4_get_tp_ch_map(adap,
848 pi->tx_chan));
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000849 if (err)
850 goto freeout;
851 q->rspq.idx = j;
852 memset(&q->stats, 0, sizeof(q->stats));
853 }
854 for (j = 0; j < pi->nqsets; j++, t++) {
855 err = t4_sge_alloc_eth_txq(adap, t, dev,
856 netdev_get_tx_queue(dev, j),
857 s->fw_evtq.cntxt_id);
858 if (err)
859 goto freeout;
860 }
861 }
862
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000863 for_each_port(adap, i) {
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +0530864 /* Note that cmplqid below is 0 if we don't
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000865 * have RDMA queues, and that's the right value.
866 */
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +0530867 if (rxq_info)
868 cmplqid = rxq_info->uldrxq[i].rspq.cntxt_id;
869
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000870 err = t4_sge_alloc_ctrl_txq(adap, &s->ctrlq[i], adap->port[i],
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +0530871 s->fw_evtq.cntxt_id, cmplqid);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000872 if (err)
873 goto freeout;
874 }
875
Atul Guptaa45695042017-07-04 16:46:20 +0530876 if (!is_t4(adap->params.chip)) {
877 err = t4_sge_alloc_eth_txq(adap, &s->ptptxq, adap->port[0],
878 netdev_get_tx_queue(adap->port[0], 0)
879 , s->fw_evtq.cntxt_id);
880 if (err)
881 goto freeout;
882 }
883
Hariprasad Shenai9bb59b92014-09-01 19:54:57 +0530884 t4_write_reg(adap, is_t4(adap->params.chip) ?
Hariprasad Shenai837e4a42015-01-05 16:30:46 +0530885 MPS_TRC_RSS_CONTROL_A :
886 MPS_T5_TRC_RSS_CONTROL_A,
887 RSSCONTROL_V(netdev2pinfo(adap->port[0])->tx_chan) |
888 QUEUENUMBER_V(s->ethrxq[0].rspq.abs_id));
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000889 return 0;
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +0530890freeout:
891 t4_free_sge_resources(adap);
892 return err;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000893}
894
Anish Bhatt688848b2014-06-19 21:37:13 -0700895static u16 cxgb_select_queue(struct net_device *dev, struct sk_buff *skb,
896 void *accel_priv, select_queue_fallback_t fallback)
897{
898 int txq;
899
900#ifdef CONFIG_CHELSIO_T4_DCB
901 /* If a Data Center Bridging has been successfully negotiated on this
902 * link then we'll use the skb's priority to map it to a TX Queue.
903 * The skb's priority is determined via the VLAN Tag Priority Code
904 * Point field.
905 */
Ganesh Goudar85eacf32017-05-16 21:17:42 +0530906 if (cxgb4_dcb_enabled(dev) && !is_kdump_kernel()) {
Anish Bhatt688848b2014-06-19 21:37:13 -0700907 u16 vlan_tci;
908 int err;
909
910 err = vlan_get_tag(skb, &vlan_tci);
911 if (unlikely(err)) {
912 if (net_ratelimit())
913 netdev_warn(dev,
914 "TX Packet without VLAN Tag on DCB Link\n");
915 txq = 0;
916 } else {
917 txq = (vlan_tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
Varun Prakash84a200b2015-03-24 19:14:46 +0530918#ifdef CONFIG_CHELSIO_T4_FCOE
919 if (skb->protocol == htons(ETH_P_FCOE))
920 txq = skb->priority & 0x7;
921#endif /* CONFIG_CHELSIO_T4_FCOE */
Anish Bhatt688848b2014-06-19 21:37:13 -0700922 }
923 return txq;
924 }
925#endif /* CONFIG_CHELSIO_T4_DCB */
926
927 if (select_queue) {
928 txq = (skb_rx_queue_recorded(skb)
929 ? skb_get_rx_queue(skb)
930 : smp_processor_id());
931
932 while (unlikely(txq >= dev->real_num_tx_queues))
933 txq -= dev->real_num_tx_queues;
934
935 return txq;
936 }
937
938 return fallback(dev, skb) % dev->real_num_tx_queues;
939}
940
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000941static int closest_timer(const struct sge *s, int time)
942{
943 int i, delta, match = 0, min_delta = INT_MAX;
944
945 for (i = 0; i < ARRAY_SIZE(s->timer_val); i++) {
946 delta = time - s->timer_val[i];
947 if (delta < 0)
948 delta = -delta;
949 if (delta < min_delta) {
950 min_delta = delta;
951 match = i;
952 }
953 }
954 return match;
955}
956
957static int closest_thres(const struct sge *s, int thres)
958{
959 int i, delta, match = 0, min_delta = INT_MAX;
960
961 for (i = 0; i < ARRAY_SIZE(s->counter_val); i++) {
962 delta = thres - s->counter_val[i];
963 if (delta < 0)
964 delta = -delta;
965 if (delta < min_delta) {
966 min_delta = delta;
967 match = i;
968 }
969 }
970 return match;
971}
972
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000973/**
Hariprasad Shenai812034f2015-04-06 20:23:23 +0530974 * cxgb4_set_rspq_intr_params - set a queue's interrupt holdoff parameters
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000975 * @q: the Rx queue
976 * @us: the hold-off time in us, or 0 to disable timer
977 * @cnt: the hold-off packet count, or 0 to disable counter
978 *
979 * Sets an Rx queue's interrupt hold-off time and packet count. At least
980 * one of the two needs to be enabled for the queue to generate interrupts.
981 */
Hariprasad Shenai812034f2015-04-06 20:23:23 +0530982int cxgb4_set_rspq_intr_params(struct sge_rspq *q,
983 unsigned int us, unsigned int cnt)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000984{
Hariprasad Shenaic887ad02014-06-06 21:40:45 +0530985 struct adapter *adap = q->adap;
986
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +0000987 if ((us | cnt) == 0)
988 cnt = 1;
989
990 if (cnt) {
991 int err;
992 u32 v, new_idx;
993
994 new_idx = closest_thres(&adap->sge, cnt);
995 if (q->desc && q->pktcnt_idx != new_idx) {
996 /* the queue has already been created, update it */
Hariprasad Shenai51678652014-11-21 12:52:02 +0530997 v = FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DMAQ) |
998 FW_PARAMS_PARAM_X_V(
999 FW_PARAMS_PARAM_DMAQ_IQ_INTCNTTHRESH) |
1000 FW_PARAMS_PARAM_YZ_V(q->cntxt_id);
Hariprasad Shenaib2612722015-05-27 22:30:24 +05301001 err = t4_set_params(adap, adap->mbox, adap->pf, 0, 1,
1002 &v, &new_idx);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001003 if (err)
1004 return err;
1005 }
1006 q->pktcnt_idx = new_idx;
1007 }
1008
1009 us = us == 0 ? 6 : closest_timer(&adap->sge, us);
Hariprasad Shenai1ecc7b72015-05-12 04:43:43 +05301010 q->intr_params = QINTR_TIMER_IDX_V(us) | QINTR_CNT_EN_V(cnt > 0);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001011 return 0;
1012}
1013
Michał Mirosławc8f44af2011-11-15 15:29:55 +00001014static int cxgb_set_features(struct net_device *dev, netdev_features_t features)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001015{
Michał Mirosław2ed28ba2011-04-16 13:05:08 +00001016 const struct port_info *pi = netdev_priv(dev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00001017 netdev_features_t changed = dev->features ^ features;
Dimitris Michailidis19ecae22010-10-21 11:29:56 +00001018 int err;
Dimitris Michailidis19ecae22010-10-21 11:29:56 +00001019
Patrick McHardyf6469682013-04-19 02:04:27 +00001020 if (!(changed & NETIF_F_HW_VLAN_CTAG_RX))
Michał Mirosław2ed28ba2011-04-16 13:05:08 +00001021 return 0;
Dimitris Michailidis19ecae22010-10-21 11:29:56 +00001022
Hariprasad Shenaib2612722015-05-27 22:30:24 +05301023 err = t4_set_rxmode(pi->adapter, pi->adapter->pf, pi->viid, -1,
Michał Mirosław2ed28ba2011-04-16 13:05:08 +00001024 -1, -1, -1,
Patrick McHardyf6469682013-04-19 02:04:27 +00001025 !!(features & NETIF_F_HW_VLAN_CTAG_RX), true);
Michał Mirosław2ed28ba2011-04-16 13:05:08 +00001026 if (unlikely(err))
Patrick McHardyf6469682013-04-19 02:04:27 +00001027 dev->features = features ^ NETIF_F_HW_VLAN_CTAG_RX;
Dimitris Michailidis19ecae22010-10-21 11:29:56 +00001028 return err;
Dimitris Michailidis87b6cf52010-04-27 16:22:42 -07001029}
1030
Bill Pemberton91744942012-12-03 09:23:02 -05001031static int setup_debugfs(struct adapter *adap)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001032{
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001033 if (IS_ERR_OR_NULL(adap->debugfs_root))
1034 return -1;
1035
Hariprasad Shenaifd88b312014-11-07 09:35:23 +05301036#ifdef CONFIG_DEBUG_FS
1037 t4_setup_debugfs(adap);
1038#endif
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001039 return 0;
1040}
1041
1042/*
1043 * upper-layer driver support
1044 */
1045
1046/*
1047 * Allocate an active-open TID and set it to the supplied value.
1048 */
1049int cxgb4_alloc_atid(struct tid_info *t, void *data)
1050{
1051 int atid = -1;
1052
1053 spin_lock_bh(&t->atid_lock);
1054 if (t->afree) {
1055 union aopen_entry *p = t->afree;
1056
Vipul Pandyaf2b7e782012-12-10 09:30:52 +00001057 atid = (p - t->atid_tab) + t->atid_base;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001058 t->afree = p->next;
1059 p->data = data;
1060 t->atids_in_use++;
1061 }
1062 spin_unlock_bh(&t->atid_lock);
1063 return atid;
1064}
1065EXPORT_SYMBOL(cxgb4_alloc_atid);
1066
1067/*
1068 * Release an active-open TID.
1069 */
1070void cxgb4_free_atid(struct tid_info *t, unsigned int atid)
1071{
Vipul Pandyaf2b7e782012-12-10 09:30:52 +00001072 union aopen_entry *p = &t->atid_tab[atid - t->atid_base];
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001073
1074 spin_lock_bh(&t->atid_lock);
1075 p->next = t->afree;
1076 t->afree = p;
1077 t->atids_in_use--;
1078 spin_unlock_bh(&t->atid_lock);
1079}
1080EXPORT_SYMBOL(cxgb4_free_atid);
1081
1082/*
1083 * Allocate a server TID and set it to the supplied value.
1084 */
1085int cxgb4_alloc_stid(struct tid_info *t, int family, void *data)
1086{
1087 int stid;
1088
1089 spin_lock_bh(&t->stid_lock);
1090 if (family == PF_INET) {
1091 stid = find_first_zero_bit(t->stid_bmap, t->nstids);
1092 if (stid < t->nstids)
1093 __set_bit(stid, t->stid_bmap);
1094 else
1095 stid = -1;
1096 } else {
Hariprasad Shenaia99c6832015-12-24 16:15:17 +05301097 stid = bitmap_find_free_region(t->stid_bmap, t->nstids, 1);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001098 if (stid < 0)
1099 stid = -1;
1100 }
1101 if (stid >= 0) {
1102 t->stid_tab[stid].data = data;
1103 stid += t->stid_base;
Kumar Sanghvi15f63b72013-12-18 16:38:22 +05301104 /* IPv6 requires max of 520 bits or 16 cells in TCAM
1105 * This is equivalent to 4 TIDs. With CLIP enabled it
1106 * needs 2 TIDs.
1107 */
Ganesh Goudar1dec4ce2017-06-07 15:04:51 +05301108 if (family == PF_INET6) {
Hariprasad Shenaia99c6832015-12-24 16:15:17 +05301109 t->stids_in_use += 2;
Ganesh Goudar1dec4ce2017-06-07 15:04:51 +05301110 t->v6_stids_in_use += 2;
1111 } else {
1112 t->stids_in_use++;
1113 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001114 }
1115 spin_unlock_bh(&t->stid_lock);
1116 return stid;
1117}
1118EXPORT_SYMBOL(cxgb4_alloc_stid);
1119
Vipul Pandyadca4fae2012-12-10 09:30:53 +00001120/* Allocate a server filter TID and set it to the supplied value.
1121 */
1122int cxgb4_alloc_sftid(struct tid_info *t, int family, void *data)
1123{
1124 int stid;
1125
1126 spin_lock_bh(&t->stid_lock);
1127 if (family == PF_INET) {
1128 stid = find_next_zero_bit(t->stid_bmap,
1129 t->nstids + t->nsftids, t->nstids);
1130 if (stid < (t->nstids + t->nsftids))
1131 __set_bit(stid, t->stid_bmap);
1132 else
1133 stid = -1;
1134 } else {
1135 stid = -1;
1136 }
1137 if (stid >= 0) {
1138 t->stid_tab[stid].data = data;
Kumar Sanghvi470c60c2013-12-18 16:38:21 +05301139 stid -= t->nstids;
1140 stid += t->sftid_base;
Hariprasad Shenai2248b292015-08-12 16:55:06 +05301141 t->sftids_in_use++;
Vipul Pandyadca4fae2012-12-10 09:30:53 +00001142 }
1143 spin_unlock_bh(&t->stid_lock);
1144 return stid;
1145}
1146EXPORT_SYMBOL(cxgb4_alloc_sftid);
1147
1148/* Release a server TID.
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001149 */
1150void cxgb4_free_stid(struct tid_info *t, unsigned int stid, int family)
1151{
Kumar Sanghvi470c60c2013-12-18 16:38:21 +05301152 /* Is it a server filter TID? */
1153 if (t->nsftids && (stid >= t->sftid_base)) {
1154 stid -= t->sftid_base;
1155 stid += t->nstids;
1156 } else {
1157 stid -= t->stid_base;
1158 }
1159
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001160 spin_lock_bh(&t->stid_lock);
1161 if (family == PF_INET)
1162 __clear_bit(stid, t->stid_bmap);
1163 else
Hariprasad Shenaia99c6832015-12-24 16:15:17 +05301164 bitmap_release_region(t->stid_bmap, stid, 1);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001165 t->stid_tab[stid].data = NULL;
Hariprasad Shenai2248b292015-08-12 16:55:06 +05301166 if (stid < t->nstids) {
Ganesh Goudar1dec4ce2017-06-07 15:04:51 +05301167 if (family == PF_INET6) {
Hariprasad Shenaia99c6832015-12-24 16:15:17 +05301168 t->stids_in_use -= 2;
Ganesh Goudar1dec4ce2017-06-07 15:04:51 +05301169 t->v6_stids_in_use -= 2;
1170 } else {
1171 t->stids_in_use--;
1172 }
Hariprasad Shenai2248b292015-08-12 16:55:06 +05301173 } else {
1174 t->sftids_in_use--;
1175 }
Ganesh Goudar1dec4ce2017-06-07 15:04:51 +05301176
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001177 spin_unlock_bh(&t->stid_lock);
1178}
1179EXPORT_SYMBOL(cxgb4_free_stid);
1180
1181/*
1182 * Populate a TID_RELEASE WR. Caller must properly size the skb.
1183 */
1184static void mk_tid_release(struct sk_buff *skb, unsigned int chan,
1185 unsigned int tid)
1186{
1187 struct cpl_tid_release *req;
1188
1189 set_wr_txq(skb, CPL_PRIORITY_SETUP, chan);
Johannes Berg4df864c2017-06-16 14:29:21 +02001190 req = __skb_put(skb, sizeof(*req));
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001191 INIT_TP_WR(req, tid);
1192 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_TID_RELEASE, tid));
1193}
1194
1195/*
1196 * Queue a TID release request and if necessary schedule a work queue to
1197 * process it.
1198 */
stephen hemminger31b9c192010-10-18 05:39:18 +00001199static void cxgb4_queue_tid_release(struct tid_info *t, unsigned int chan,
1200 unsigned int tid)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001201{
1202 void **p = &t->tid_tab[tid];
1203 struct adapter *adap = container_of(t, struct adapter, tids);
1204
1205 spin_lock_bh(&adap->tid_release_lock);
1206 *p = adap->tid_release_head;
1207 /* Low 2 bits encode the Tx channel number */
1208 adap->tid_release_head = (void **)((uintptr_t)p | chan);
1209 if (!adap->tid_release_task_busy) {
1210 adap->tid_release_task_busy = true;
Anish Bhatt29aaee62014-08-20 13:44:06 -07001211 queue_work(adap->workq, &adap->tid_release_task);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001212 }
1213 spin_unlock_bh(&adap->tid_release_lock);
1214}
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001215
1216/*
1217 * Process the list of pending TID release requests.
1218 */
1219static void process_tid_release_list(struct work_struct *work)
1220{
1221 struct sk_buff *skb;
1222 struct adapter *adap;
1223
1224 adap = container_of(work, struct adapter, tid_release_task);
1225
1226 spin_lock_bh(&adap->tid_release_lock);
1227 while (adap->tid_release_head) {
1228 void **p = adap->tid_release_head;
1229 unsigned int chan = (uintptr_t)p & 3;
1230 p = (void *)p - chan;
1231
1232 adap->tid_release_head = *p;
1233 *p = NULL;
1234 spin_unlock_bh(&adap->tid_release_lock);
1235
1236 while (!(skb = alloc_skb(sizeof(struct cpl_tid_release),
1237 GFP_KERNEL)))
1238 schedule_timeout_uninterruptible(1);
1239
1240 mk_tid_release(skb, chan, p - adap->tids.tid_tab);
1241 t4_ofld_send(adap, skb);
1242 spin_lock_bh(&adap->tid_release_lock);
1243 }
1244 adap->tid_release_task_busy = false;
1245 spin_unlock_bh(&adap->tid_release_lock);
1246}
1247
1248/*
1249 * Release a TID and inform HW. If we are unable to allocate the release
1250 * message we defer to a work queue.
1251 */
Ganesh Goudar1dec4ce2017-06-07 15:04:51 +05301252void cxgb4_remove_tid(struct tid_info *t, unsigned int chan, unsigned int tid,
1253 unsigned short family)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001254{
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001255 struct sk_buff *skb;
1256 struct adapter *adap = container_of(t, struct adapter, tids);
1257
Hariprasad Shenai9a1bb9f2015-08-12 16:55:05 +05301258 WARN_ON(tid >= t->ntids);
1259
1260 if (t->tid_tab[tid]) {
1261 t->tid_tab[tid] = NULL;
Ganesh Goudar1dec4ce2017-06-07 15:04:51 +05301262 atomic_dec(&t->conns_in_use);
1263 if (t->hash_base && (tid >= t->hash_base)) {
1264 if (family == AF_INET6)
1265 atomic_sub(2, &t->hash_tids_in_use);
1266 else
1267 atomic_dec(&t->hash_tids_in_use);
1268 } else {
1269 if (family == AF_INET6)
1270 atomic_sub(2, &t->tids_in_use);
1271 else
1272 atomic_dec(&t->tids_in_use);
1273 }
Hariprasad Shenai9a1bb9f2015-08-12 16:55:05 +05301274 }
1275
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001276 skb = alloc_skb(sizeof(struct cpl_tid_release), GFP_ATOMIC);
1277 if (likely(skb)) {
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001278 mk_tid_release(skb, chan, tid);
1279 t4_ofld_send(adap, skb);
1280 } else
1281 cxgb4_queue_tid_release(t, chan, tid);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001282}
1283EXPORT_SYMBOL(cxgb4_remove_tid);
1284
1285/*
1286 * Allocate and initialize the TID tables. Returns 0 on success.
1287 */
1288static int tid_init(struct tid_info *t)
1289{
Kumar Sanghvib6f8eae2013-12-18 16:38:19 +05301290 struct adapter *adap = container_of(t, struct adapter, tids);
Rahul Lakkireddy578b46b2016-09-20 17:13:07 +05301291 unsigned int max_ftids = t->nftids + t->nsftids;
1292 unsigned int natids = t->natids;
1293 unsigned int stid_bmap_size;
1294 unsigned int ftid_bmap_size;
1295 size_t size;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001296
Vipul Pandyadca4fae2012-12-10 09:30:53 +00001297 stid_bmap_size = BITS_TO_LONGS(t->nstids + t->nsftids);
Rahul Lakkireddy578b46b2016-09-20 17:13:07 +05301298 ftid_bmap_size = BITS_TO_LONGS(t->nftids);
Vipul Pandyaf2b7e782012-12-10 09:30:52 +00001299 size = t->ntids * sizeof(*t->tid_tab) +
1300 natids * sizeof(*t->atid_tab) +
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001301 t->nstids * sizeof(*t->stid_tab) +
Vipul Pandyadca4fae2012-12-10 09:30:53 +00001302 t->nsftids * sizeof(*t->stid_tab) +
Vipul Pandyaf2b7e782012-12-10 09:30:52 +00001303 stid_bmap_size * sizeof(long) +
Rahul Lakkireddy578b46b2016-09-20 17:13:07 +05301304 max_ftids * sizeof(*t->ftid_tab) +
1305 ftid_bmap_size * sizeof(long);
Vipul Pandyaf2b7e782012-12-10 09:30:52 +00001306
Michal Hocko752ade62017-05-08 15:57:27 -07001307 t->tid_tab = kvzalloc(size, GFP_KERNEL);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001308 if (!t->tid_tab)
1309 return -ENOMEM;
1310
1311 t->atid_tab = (union aopen_entry *)&t->tid_tab[t->ntids];
1312 t->stid_tab = (struct serv_entry *)&t->atid_tab[natids];
Vipul Pandyadca4fae2012-12-10 09:30:53 +00001313 t->stid_bmap = (unsigned long *)&t->stid_tab[t->nstids + t->nsftids];
Vipul Pandyaf2b7e782012-12-10 09:30:52 +00001314 t->ftid_tab = (struct filter_entry *)&t->stid_bmap[stid_bmap_size];
Rahul Lakkireddy578b46b2016-09-20 17:13:07 +05301315 t->ftid_bmap = (unsigned long *)&t->ftid_tab[max_ftids];
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001316 spin_lock_init(&t->stid_lock);
1317 spin_lock_init(&t->atid_lock);
Rahul Lakkireddy578b46b2016-09-20 17:13:07 +05301318 spin_lock_init(&t->ftid_lock);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001319
1320 t->stids_in_use = 0;
Ganesh Goudar1dec4ce2017-06-07 15:04:51 +05301321 t->v6_stids_in_use = 0;
Hariprasad Shenai2248b292015-08-12 16:55:06 +05301322 t->sftids_in_use = 0;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001323 t->afree = NULL;
1324 t->atids_in_use = 0;
1325 atomic_set(&t->tids_in_use, 0);
Ganesh Goudar1dec4ce2017-06-07 15:04:51 +05301326 atomic_set(&t->conns_in_use, 0);
Hariprasad Shenai9a1bb9f2015-08-12 16:55:05 +05301327 atomic_set(&t->hash_tids_in_use, 0);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001328
1329 /* Setup the free list for atid_tab and clear the stid bitmap. */
1330 if (natids) {
1331 while (--natids)
1332 t->atid_tab[natids - 1].next = &t->atid_tab[natids];
1333 t->afree = t->atid_tab;
1334 }
Kumar Sanghvib6f8eae2013-12-18 16:38:19 +05301335
Rahul Lakkireddy578b46b2016-09-20 17:13:07 +05301336 if (is_offload(adap)) {
1337 bitmap_zero(t->stid_bmap, t->nstids + t->nsftids);
1338 /* Reserve stid 0 for T4/T5 adapters */
1339 if (!t->stid_base &&
1340 CHELSIO_CHIP_VERSION(adap->params.chip) <= CHELSIO_T5)
1341 __set_bit(0, t->stid_bmap);
1342 }
1343
1344 bitmap_zero(t->ftid_bmap, t->nftids);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001345 return 0;
1346}
1347
1348/**
1349 * cxgb4_create_server - create an IP server
1350 * @dev: the device
1351 * @stid: the server TID
1352 * @sip: local IP address to bind server to
1353 * @sport: the server's TCP port
1354 * @queue: queue to direct messages from this server to
1355 *
1356 * Create an IP server for the given port and address.
1357 * Returns <0 on error and one of the %NET_XMIT_* values on success.
1358 */
1359int cxgb4_create_server(const struct net_device *dev, unsigned int stid,
Vipul Pandya793dad92012-12-10 09:30:56 +00001360 __be32 sip, __be16 sport, __be16 vlan,
1361 unsigned int queue)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001362{
1363 unsigned int chan;
1364 struct sk_buff *skb;
1365 struct adapter *adap;
1366 struct cpl_pass_open_req *req;
Vipul Pandya80f40c12013-07-04 16:10:45 +05301367 int ret;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001368
1369 skb = alloc_skb(sizeof(*req), GFP_KERNEL);
1370 if (!skb)
1371 return -ENOMEM;
1372
1373 adap = netdev2adap(dev);
Johannes Berg4df864c2017-06-16 14:29:21 +02001374 req = __skb_put(skb, sizeof(*req));
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001375 INIT_TP_WR(req, 0);
1376 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_OPEN_REQ, stid));
1377 req->local_port = sport;
1378 req->peer_port = htons(0);
1379 req->local_ip = sip;
1380 req->peer_ip = htonl(0);
Dimitris Michailidise46dab42010-08-23 17:20:58 +00001381 chan = rxq_to_chan(&adap->sge, queue);
Anish Bhattd7990b02014-11-12 17:15:57 -08001382 req->opt0 = cpu_to_be64(TX_CHAN_V(chan));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001383 req->opt1 = cpu_to_be64(CONN_POLICY_V(CPL_CONN_POLICY_ASK) |
1384 SYN_RSS_ENABLE_F | SYN_RSS_QUEUE_V(queue));
Vipul Pandya80f40c12013-07-04 16:10:45 +05301385 ret = t4_mgmt_tx(adap, skb);
1386 return net_xmit_eval(ret);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001387}
1388EXPORT_SYMBOL(cxgb4_create_server);
1389
Vipul Pandya80f40c12013-07-04 16:10:45 +05301390/* cxgb4_create_server6 - create an IPv6 server
1391 * @dev: the device
1392 * @stid: the server TID
1393 * @sip: local IPv6 address to bind server to
1394 * @sport: the server's TCP port
1395 * @queue: queue to direct messages from this server to
1396 *
1397 * Create an IPv6 server for the given port and address.
1398 * Returns <0 on error and one of the %NET_XMIT_* values on success.
1399 */
1400int cxgb4_create_server6(const struct net_device *dev, unsigned int stid,
1401 const struct in6_addr *sip, __be16 sport,
1402 unsigned int queue)
1403{
1404 unsigned int chan;
1405 struct sk_buff *skb;
1406 struct adapter *adap;
1407 struct cpl_pass_open_req6 *req;
1408 int ret;
1409
1410 skb = alloc_skb(sizeof(*req), GFP_KERNEL);
1411 if (!skb)
1412 return -ENOMEM;
1413
1414 adap = netdev2adap(dev);
Johannes Berg4df864c2017-06-16 14:29:21 +02001415 req = __skb_put(skb, sizeof(*req));
Vipul Pandya80f40c12013-07-04 16:10:45 +05301416 INIT_TP_WR(req, 0);
1417 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_OPEN_REQ6, stid));
1418 req->local_port = sport;
1419 req->peer_port = htons(0);
1420 req->local_ip_hi = *(__be64 *)(sip->s6_addr);
1421 req->local_ip_lo = *(__be64 *)(sip->s6_addr + 8);
1422 req->peer_ip_hi = cpu_to_be64(0);
1423 req->peer_ip_lo = cpu_to_be64(0);
1424 chan = rxq_to_chan(&adap->sge, queue);
Anish Bhattd7990b02014-11-12 17:15:57 -08001425 req->opt0 = cpu_to_be64(TX_CHAN_V(chan));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001426 req->opt1 = cpu_to_be64(CONN_POLICY_V(CPL_CONN_POLICY_ASK) |
1427 SYN_RSS_ENABLE_F | SYN_RSS_QUEUE_V(queue));
Vipul Pandya80f40c12013-07-04 16:10:45 +05301428 ret = t4_mgmt_tx(adap, skb);
1429 return net_xmit_eval(ret);
1430}
1431EXPORT_SYMBOL(cxgb4_create_server6);
1432
1433int cxgb4_remove_server(const struct net_device *dev, unsigned int stid,
1434 unsigned int queue, bool ipv6)
1435{
1436 struct sk_buff *skb;
1437 struct adapter *adap;
1438 struct cpl_close_listsvr_req *req;
1439 int ret;
1440
1441 adap = netdev2adap(dev);
1442
1443 skb = alloc_skb(sizeof(*req), GFP_KERNEL);
1444 if (!skb)
1445 return -ENOMEM;
1446
Johannes Berg4df864c2017-06-16 14:29:21 +02001447 req = __skb_put(skb, sizeof(*req));
Vipul Pandya80f40c12013-07-04 16:10:45 +05301448 INIT_TP_WR(req, 0);
1449 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_CLOSE_LISTSRV_REQ, stid));
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08001450 req->reply_ctrl = htons(NO_REPLY_V(0) | (ipv6 ? LISTSVR_IPV6_V(1) :
1451 LISTSVR_IPV6_V(0)) | QUEUENO_V(queue));
Vipul Pandya80f40c12013-07-04 16:10:45 +05301452 ret = t4_mgmt_tx(adap, skb);
1453 return net_xmit_eval(ret);
1454}
1455EXPORT_SYMBOL(cxgb4_remove_server);
1456
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001457/**
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001458 * cxgb4_best_mtu - find the entry in the MTU table closest to an MTU
1459 * @mtus: the HW MTU table
1460 * @mtu: the target MTU
1461 * @idx: index of selected entry in the MTU table
1462 *
1463 * Returns the index and the value in the HW MTU table that is closest to
1464 * but does not exceed @mtu, unless @mtu is smaller than any value in the
1465 * table, in which case that smallest available value is selected.
1466 */
1467unsigned int cxgb4_best_mtu(const unsigned short *mtus, unsigned short mtu,
1468 unsigned int *idx)
1469{
1470 unsigned int i = 0;
1471
1472 while (i < NMTUS - 1 && mtus[i + 1] <= mtu)
1473 ++i;
1474 if (idx)
1475 *idx = i;
1476 return mtus[i];
1477}
1478EXPORT_SYMBOL(cxgb4_best_mtu);
1479
1480/**
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05301481 * cxgb4_best_aligned_mtu - find best MTU, [hopefully] data size aligned
1482 * @mtus: the HW MTU table
1483 * @header_size: Header Size
1484 * @data_size_max: maximum Data Segment Size
1485 * @data_size_align: desired Data Segment Size Alignment (2^N)
1486 * @mtu_idxp: HW MTU Table Index return value pointer (possibly NULL)
1487 *
1488 * Similar to cxgb4_best_mtu() but instead of searching the Hardware
1489 * MTU Table based solely on a Maximum MTU parameter, we break that
1490 * parameter up into a Header Size and Maximum Data Segment Size, and
1491 * provide a desired Data Segment Size Alignment. If we find an MTU in
1492 * the Hardware MTU Table which will result in a Data Segment Size with
1493 * the requested alignment _and_ that MTU isn't "too far" from the
1494 * closest MTU, then we'll return that rather than the closest MTU.
1495 */
1496unsigned int cxgb4_best_aligned_mtu(const unsigned short *mtus,
1497 unsigned short header_size,
1498 unsigned short data_size_max,
1499 unsigned short data_size_align,
1500 unsigned int *mtu_idxp)
1501{
1502 unsigned short max_mtu = header_size + data_size_max;
1503 unsigned short data_size_align_mask = data_size_align - 1;
1504 int mtu_idx, aligned_mtu_idx;
1505
1506 /* Scan the MTU Table till we find an MTU which is larger than our
1507 * Maximum MTU or we reach the end of the table. Along the way,
1508 * record the last MTU found, if any, which will result in a Data
1509 * Segment Length matching the requested alignment.
1510 */
1511 for (mtu_idx = 0, aligned_mtu_idx = -1; mtu_idx < NMTUS; mtu_idx++) {
1512 unsigned short data_size = mtus[mtu_idx] - header_size;
1513
1514 /* If this MTU minus the Header Size would result in a
1515 * Data Segment Size of the desired alignment, remember it.
1516 */
1517 if ((data_size & data_size_align_mask) == 0)
1518 aligned_mtu_idx = mtu_idx;
1519
1520 /* If we're not at the end of the Hardware MTU Table and the
1521 * next element is larger than our Maximum MTU, drop out of
1522 * the loop.
1523 */
1524 if (mtu_idx+1 < NMTUS && mtus[mtu_idx+1] > max_mtu)
1525 break;
1526 }
1527
1528 /* If we fell out of the loop because we ran to the end of the table,
1529 * then we just have to use the last [largest] entry.
1530 */
1531 if (mtu_idx == NMTUS)
1532 mtu_idx--;
1533
1534 /* If we found an MTU which resulted in the requested Data Segment
1535 * Length alignment and that's "not far" from the largest MTU which is
1536 * less than or equal to the maximum MTU, then use that.
1537 */
1538 if (aligned_mtu_idx >= 0 &&
1539 mtu_idx - aligned_mtu_idx <= 1)
1540 mtu_idx = aligned_mtu_idx;
1541
1542 /* If the caller has passed in an MTU Index pointer, pass the
1543 * MTU Index back. Return the MTU value.
1544 */
1545 if (mtu_idxp)
1546 *mtu_idxp = mtu_idx;
1547 return mtus[mtu_idx];
1548}
1549EXPORT_SYMBOL(cxgb4_best_aligned_mtu);
1550
1551/**
Hariprasad S27999802015-09-23 17:19:26 +05301552 * cxgb4_tp_smt_idx - Get the Source Mac Table index for this VI
1553 * @chip: chip type
1554 * @viid: VI id of the given port
1555 *
1556 * Return the SMT index for this VI.
1557 */
1558unsigned int cxgb4_tp_smt_idx(enum chip_type chip, unsigned int viid)
1559{
1560 /* In T4/T5, SMT contains 256 SMAC entries organized in
1561 * 128 rows of 2 entries each.
1562 * In T6, SMT contains 256 SMAC entries in 256 rows.
1563 * TODO: The below code needs to be updated when we add support
1564 * for 256 VFs.
1565 */
1566 if (CHELSIO_CHIP_VERSION(chip) <= CHELSIO_T5)
1567 return ((viid & 0x7f) << 1);
1568 else
1569 return (viid & 0x7f);
1570}
1571EXPORT_SYMBOL(cxgb4_tp_smt_idx);
1572
1573/**
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001574 * cxgb4_port_chan - get the HW channel of a port
1575 * @dev: the net device for the port
1576 *
1577 * Return the HW Tx channel of the given port.
1578 */
1579unsigned int cxgb4_port_chan(const struct net_device *dev)
1580{
1581 return netdev2pinfo(dev)->tx_chan;
1582}
1583EXPORT_SYMBOL(cxgb4_port_chan);
1584
Vipul Pandya881806b2012-05-18 15:29:24 +05301585unsigned int cxgb4_dbfifo_count(const struct net_device *dev, int lpfifo)
1586{
1587 struct adapter *adap = netdev2adap(dev);
Santosh Rastapur2cc301d2013-03-14 05:08:52 +00001588 u32 v1, v2, lp_count, hp_count;
Vipul Pandya881806b2012-05-18 15:29:24 +05301589
Hariprasad Shenaif061de422015-01-05 16:30:44 +05301590 v1 = t4_read_reg(adap, SGE_DBFIFO_STATUS_A);
1591 v2 = t4_read_reg(adap, SGE_DBFIFO_STATUS2_A);
Hariprasad Shenaid14807d2013-12-03 17:05:56 +05301592 if (is_t4(adap->params.chip)) {
Hariprasad Shenaif061de422015-01-05 16:30:44 +05301593 lp_count = LP_COUNT_G(v1);
1594 hp_count = HP_COUNT_G(v1);
Santosh Rastapur2cc301d2013-03-14 05:08:52 +00001595 } else {
Hariprasad Shenaif061de422015-01-05 16:30:44 +05301596 lp_count = LP_COUNT_T5_G(v1);
1597 hp_count = HP_COUNT_T5_G(v2);
Santosh Rastapur2cc301d2013-03-14 05:08:52 +00001598 }
1599 return lpfifo ? lp_count : hp_count;
Vipul Pandya881806b2012-05-18 15:29:24 +05301600}
1601EXPORT_SYMBOL(cxgb4_dbfifo_count);
1602
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001603/**
1604 * cxgb4_port_viid - get the VI id of a port
1605 * @dev: the net device for the port
1606 *
1607 * Return the VI id of the given port.
1608 */
1609unsigned int cxgb4_port_viid(const struct net_device *dev)
1610{
1611 return netdev2pinfo(dev)->viid;
1612}
1613EXPORT_SYMBOL(cxgb4_port_viid);
1614
1615/**
1616 * cxgb4_port_idx - get the index of a port
1617 * @dev: the net device for the port
1618 *
1619 * Return the index of the given port.
1620 */
1621unsigned int cxgb4_port_idx(const struct net_device *dev)
1622{
1623 return netdev2pinfo(dev)->port_id;
1624}
1625EXPORT_SYMBOL(cxgb4_port_idx);
1626
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001627void cxgb4_get_tcp_stats(struct pci_dev *pdev, struct tp_tcp_stats *v4,
1628 struct tp_tcp_stats *v6)
1629{
1630 struct adapter *adap = pci_get_drvdata(pdev);
1631
1632 spin_lock(&adap->stats_lock);
1633 t4_tp_get_tcp_stats(adap, v4, v6);
1634 spin_unlock(&adap->stats_lock);
1635}
1636EXPORT_SYMBOL(cxgb4_get_tcp_stats);
1637
1638void cxgb4_iscsi_init(struct net_device *dev, unsigned int tag_mask,
1639 const unsigned int *pgsz_order)
1640{
1641 struct adapter *adap = netdev2adap(dev);
1642
Hariprasad Shenai0d804332015-01-05 16:30:47 +05301643 t4_write_reg(adap, ULP_RX_ISCSI_TAGMASK_A, tag_mask);
1644 t4_write_reg(adap, ULP_RX_ISCSI_PSZ_A, HPZ0_V(pgsz_order[0]) |
1645 HPZ1_V(pgsz_order[1]) | HPZ2_V(pgsz_order[2]) |
1646 HPZ3_V(pgsz_order[3]));
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001647}
1648EXPORT_SYMBOL(cxgb4_iscsi_init);
1649
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301650int cxgb4_flush_eq_cache(struct net_device *dev)
1651{
1652 struct adapter *adap = netdev2adap(dev);
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301653
Hariprasad Shenai5d700ec2015-06-05 14:24:48 +05301654 return t4_sge_ctxt_flush(adap, adap->mbox);
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301655}
1656EXPORT_SYMBOL(cxgb4_flush_eq_cache);
1657
1658static int read_eq_indices(struct adapter *adap, u16 qid, u16 *pidx, u16 *cidx)
1659{
Hariprasad Shenaif061de422015-01-05 16:30:44 +05301660 u32 addr = t4_read_reg(adap, SGE_DBQ_CTXT_BADDR_A) + 24 * qid + 8;
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301661 __be64 indices;
1662 int ret;
1663
Hariprasad Shenaifc5ab022014-06-27 19:23:49 +05301664 spin_lock(&adap->win0_lock);
1665 ret = t4_memory_rw(adap, 0, MEM_EDC0, addr,
1666 sizeof(indices), (__be32 *)&indices,
1667 T4_MEMORY_READ);
1668 spin_unlock(&adap->win0_lock);
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301669 if (!ret) {
Vipul Pandya404d9e32012-10-08 02:59:43 +00001670 *cidx = (be64_to_cpu(indices) >> 25) & 0xffff;
1671 *pidx = (be64_to_cpu(indices) >> 9) & 0xffff;
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301672 }
1673 return ret;
1674}
1675
1676int cxgb4_sync_txq_pidx(struct net_device *dev, u16 qid, u16 pidx,
1677 u16 size)
1678{
1679 struct adapter *adap = netdev2adap(dev);
1680 u16 hw_pidx, hw_cidx;
1681 int ret;
1682
1683 ret = read_eq_indices(adap, qid, &hw_pidx, &hw_cidx);
1684 if (ret)
1685 goto out;
1686
1687 if (pidx != hw_pidx) {
1688 u16 delta;
Hariprasad Shenaif612b812015-01-05 16:30:43 +05301689 u32 val;
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301690
1691 if (pidx >= hw_pidx)
1692 delta = pidx - hw_pidx;
1693 else
1694 delta = size - hw_pidx + pidx;
Hariprasad Shenaif612b812015-01-05 16:30:43 +05301695
1696 if (is_t4(adap->params.chip))
1697 val = PIDX_V(delta);
1698 else
1699 val = PIDX_T5_V(delta);
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301700 wmb();
Hariprasad Shenaif612b812015-01-05 16:30:43 +05301701 t4_write_reg(adap, MYPF_REG(SGE_PF_KDOORBELL_A),
1702 QID_V(qid) | val);
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301703 }
1704out:
1705 return ret;
1706}
1707EXPORT_SYMBOL(cxgb4_sync_txq_pidx);
1708
Hariprasad Shenai031cf472014-07-14 21:34:53 +05301709int cxgb4_read_tpte(struct net_device *dev, u32 stag, __be32 *tpte)
1710{
1711 struct adapter *adap;
1712 u32 offset, memtype, memaddr;
Hariprasad Shenai6559a7e2014-11-07 09:35:24 +05301713 u32 edc0_size, edc1_size, mc0_size, mc1_size, size;
Hariprasad Shenai031cf472014-07-14 21:34:53 +05301714 u32 edc0_end, edc1_end, mc0_end, mc1_end;
1715 int ret;
1716
1717 adap = netdev2adap(dev);
1718
1719 offset = ((stag >> 8) * 32) + adap->vres.stag.start;
1720
1721 /* Figure out where the offset lands in the Memory Type/Address scheme.
1722 * This code assumes that the memory is laid out starting at offset 0
1723 * with no breaks as: EDC0, EDC1, MC0, MC1. All cards have both EDC0
1724 * and EDC1. Some cards will have neither MC0 nor MC1, most cards have
1725 * MC0, and some have both MC0 and MC1.
1726 */
Hariprasad Shenai6559a7e2014-11-07 09:35:24 +05301727 size = t4_read_reg(adap, MA_EDRAM0_BAR_A);
1728 edc0_size = EDRAM0_SIZE_G(size) << 20;
1729 size = t4_read_reg(adap, MA_EDRAM1_BAR_A);
1730 edc1_size = EDRAM1_SIZE_G(size) << 20;
1731 size = t4_read_reg(adap, MA_EXT_MEMORY0_BAR_A);
1732 mc0_size = EXT_MEM0_SIZE_G(size) << 20;
Hariprasad Shenai031cf472014-07-14 21:34:53 +05301733
1734 edc0_end = edc0_size;
1735 edc1_end = edc0_end + edc1_size;
1736 mc0_end = edc1_end + mc0_size;
1737
1738 if (offset < edc0_end) {
1739 memtype = MEM_EDC0;
1740 memaddr = offset;
1741 } else if (offset < edc1_end) {
1742 memtype = MEM_EDC1;
1743 memaddr = offset - edc0_end;
1744 } else {
1745 if (offset < mc0_end) {
1746 memtype = MEM_MC0;
1747 memaddr = offset - edc1_end;
Hariprasad Shenai3ccc6cf2015-06-02 13:59:39 +05301748 } else if (is_t5(adap->params.chip)) {
Hariprasad Shenai6559a7e2014-11-07 09:35:24 +05301749 size = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A);
1750 mc1_size = EXT_MEM1_SIZE_G(size) << 20;
Hariprasad Shenai031cf472014-07-14 21:34:53 +05301751 mc1_end = mc0_end + mc1_size;
1752 if (offset < mc1_end) {
1753 memtype = MEM_MC1;
1754 memaddr = offset - mc0_end;
1755 } else {
1756 /* offset beyond the end of any memory */
1757 goto err;
1758 }
Hariprasad Shenai3ccc6cf2015-06-02 13:59:39 +05301759 } else {
1760 /* T4/T6 only has a single memory channel */
1761 goto err;
Hariprasad Shenai031cf472014-07-14 21:34:53 +05301762 }
1763 }
1764
1765 spin_lock(&adap->win0_lock);
1766 ret = t4_memory_rw(adap, 0, memtype, memaddr, 32, tpte, T4_MEMORY_READ);
1767 spin_unlock(&adap->win0_lock);
1768 return ret;
1769
1770err:
1771 dev_err(adap->pdev_dev, "stag %#x, offset %#x out of range\n",
1772 stag, offset);
1773 return -EINVAL;
1774}
1775EXPORT_SYMBOL(cxgb4_read_tpte);
1776
Hariprasad Shenai7730b4c2014-07-14 21:34:54 +05301777u64 cxgb4_read_sge_timestamp(struct net_device *dev)
1778{
1779 u32 hi, lo;
1780 struct adapter *adap;
1781
1782 adap = netdev2adap(dev);
Hariprasad Shenaif612b812015-01-05 16:30:43 +05301783 lo = t4_read_reg(adap, SGE_TIMESTAMP_LO_A);
1784 hi = TSVAL_G(t4_read_reg(adap, SGE_TIMESTAMP_HI_A));
Hariprasad Shenai7730b4c2014-07-14 21:34:54 +05301785
1786 return ((u64)hi << 32) | (u64)lo;
1787}
1788EXPORT_SYMBOL(cxgb4_read_sge_timestamp);
1789
Hariprasad Shenaidf64e4d2014-12-03 19:32:53 +05301790int cxgb4_bar2_sge_qregs(struct net_device *dev,
1791 unsigned int qid,
1792 enum cxgb4_bar2_qtype qtype,
Hariprasad S66cf1882015-06-09 18:23:11 +05301793 int user,
Hariprasad Shenaidf64e4d2014-12-03 19:32:53 +05301794 u64 *pbar2_qoffset,
1795 unsigned int *pbar2_qid)
1796{
Hariprasad Shenaib2612722015-05-27 22:30:24 +05301797 return t4_bar2_sge_qregs(netdev2adap(dev),
Hariprasad Shenaidf64e4d2014-12-03 19:32:53 +05301798 qid,
1799 (qtype == CXGB4_BAR2_QTYPE_EGRESS
1800 ? T4_BAR2_QTYPE_EGRESS
1801 : T4_BAR2_QTYPE_INGRESS),
Hariprasad S66cf1882015-06-09 18:23:11 +05301802 user,
Hariprasad Shenaidf64e4d2014-12-03 19:32:53 +05301803 pbar2_qoffset,
1804 pbar2_qid);
1805}
1806EXPORT_SYMBOL(cxgb4_bar2_sge_qregs);
1807
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001808static struct pci_driver cxgb4_driver;
1809
1810static void check_neigh_update(struct neighbour *neigh)
1811{
1812 const struct device *parent;
1813 const struct net_device *netdev = neigh->dev;
1814
Parav Panditd0d7b102017-02-04 11:00:49 -06001815 if (is_vlan_dev(netdev))
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001816 netdev = vlan_dev_real_dev(netdev);
1817 parent = netdev->dev.parent;
1818 if (parent && parent->driver == &cxgb4_driver.driver)
1819 t4_l2t_update(dev_get_drvdata(parent), neigh);
1820}
1821
1822static int netevent_cb(struct notifier_block *nb, unsigned long event,
1823 void *data)
1824{
1825 switch (event) {
1826 case NETEVENT_NEIGH_UPDATE:
1827 check_neigh_update(data);
1828 break;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00001829 case NETEVENT_REDIRECT:
1830 default:
1831 break;
1832 }
1833 return 0;
1834}
1835
1836static bool netevent_registered;
1837static struct notifier_block cxgb4_netevent_nb = {
1838 .notifier_call = netevent_cb
1839};
1840
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301841static void drain_db_fifo(struct adapter *adap, int usecs)
1842{
Santosh Rastapur2cc301d2013-03-14 05:08:52 +00001843 u32 v1, v2, lp_count, hp_count;
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301844
1845 do {
Hariprasad Shenaif061de422015-01-05 16:30:44 +05301846 v1 = t4_read_reg(adap, SGE_DBFIFO_STATUS_A);
1847 v2 = t4_read_reg(adap, SGE_DBFIFO_STATUS2_A);
Hariprasad Shenaid14807d2013-12-03 17:05:56 +05301848 if (is_t4(adap->params.chip)) {
Hariprasad Shenaif061de422015-01-05 16:30:44 +05301849 lp_count = LP_COUNT_G(v1);
1850 hp_count = HP_COUNT_G(v1);
Santosh Rastapur2cc301d2013-03-14 05:08:52 +00001851 } else {
Hariprasad Shenaif061de422015-01-05 16:30:44 +05301852 lp_count = LP_COUNT_T5_G(v1);
1853 hp_count = HP_COUNT_T5_G(v2);
Santosh Rastapur2cc301d2013-03-14 05:08:52 +00001854 }
1855
1856 if (lp_count == 0 && hp_count == 0)
1857 break;
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301858 set_current_state(TASK_UNINTERRUPTIBLE);
1859 schedule_timeout(usecs_to_jiffies(usecs));
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301860 } while (1);
1861}
1862
1863static void disable_txq_db(struct sge_txq *q)
1864{
Steve Wise05eb2382014-03-14 21:52:08 +05301865 unsigned long flags;
1866
1867 spin_lock_irqsave(&q->db_lock, flags);
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301868 q->db_disabled = 1;
Steve Wise05eb2382014-03-14 21:52:08 +05301869 spin_unlock_irqrestore(&q->db_lock, flags);
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301870}
1871
Steve Wise05eb2382014-03-14 21:52:08 +05301872static void enable_txq_db(struct adapter *adap, struct sge_txq *q)
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301873{
1874 spin_lock_irq(&q->db_lock);
Steve Wise05eb2382014-03-14 21:52:08 +05301875 if (q->db_pidx_inc) {
1876 /* Make sure that all writes to the TX descriptors
1877 * are committed before we tell HW about them.
1878 */
1879 wmb();
Hariprasad Shenaif612b812015-01-05 16:30:43 +05301880 t4_write_reg(adap, MYPF_REG(SGE_PF_KDOORBELL_A),
1881 QID_V(q->cntxt_id) | PIDX_V(q->db_pidx_inc));
Steve Wise05eb2382014-03-14 21:52:08 +05301882 q->db_pidx_inc = 0;
1883 }
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301884 q->db_disabled = 0;
1885 spin_unlock_irq(&q->db_lock);
1886}
1887
1888static void disable_dbs(struct adapter *adap)
1889{
1890 int i;
1891
1892 for_each_ethrxq(&adap->sge, i)
1893 disable_txq_db(&adap->sge.ethtxq[i].q);
Hariprasad Shenaiab677ff2016-11-18 16:37:40 +05301894 if (is_offload(adap)) {
1895 struct sge_uld_txq_info *txq_info =
1896 adap->sge.uld_txq_info[CXGB4_TX_OFLD];
1897
1898 if (txq_info) {
1899 for_each_ofldtxq(&adap->sge, i) {
1900 struct sge_uld_txq *txq = &txq_info->uldtxq[i];
1901
1902 disable_txq_db(&txq->q);
1903 }
1904 }
1905 }
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301906 for_each_port(adap, i)
1907 disable_txq_db(&adap->sge.ctrlq[i].q);
1908}
1909
1910static void enable_dbs(struct adapter *adap)
1911{
1912 int i;
1913
1914 for_each_ethrxq(&adap->sge, i)
Steve Wise05eb2382014-03-14 21:52:08 +05301915 enable_txq_db(adap, &adap->sge.ethtxq[i].q);
Hariprasad Shenaiab677ff2016-11-18 16:37:40 +05301916 if (is_offload(adap)) {
1917 struct sge_uld_txq_info *txq_info =
1918 adap->sge.uld_txq_info[CXGB4_TX_OFLD];
1919
1920 if (txq_info) {
1921 for_each_ofldtxq(&adap->sge, i) {
1922 struct sge_uld_txq *txq = &txq_info->uldtxq[i];
1923
1924 enable_txq_db(adap, &txq->q);
1925 }
1926 }
1927 }
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301928 for_each_port(adap, i)
Steve Wise05eb2382014-03-14 21:52:08 +05301929 enable_txq_db(adap, &adap->sge.ctrlq[i].q);
1930}
1931
1932static void notify_rdma_uld(struct adapter *adap, enum cxgb4_control cmd)
1933{
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05301934 enum cxgb4_uld type = CXGB4_ULD_RDMA;
1935
1936 if (adap->uld && adap->uld[type].handle)
1937 adap->uld[type].control(adap->uld[type].handle, cmd);
Steve Wise05eb2382014-03-14 21:52:08 +05301938}
1939
1940static void process_db_full(struct work_struct *work)
1941{
1942 struct adapter *adap;
1943
1944 adap = container_of(work, struct adapter, db_full_task);
1945
1946 drain_db_fifo(adap, dbfifo_drain_delay);
1947 enable_dbs(adap);
1948 notify_rdma_uld(adap, CXGB4_CONTROL_DB_EMPTY);
Hariprasad Shenai3ccc6cf2015-06-02 13:59:39 +05301949 if (CHELSIO_CHIP_VERSION(adap->params.chip) <= CHELSIO_T5)
1950 t4_set_reg_field(adap, SGE_INT_ENABLE3_A,
1951 DBFIFO_HP_INT_F | DBFIFO_LP_INT_F,
1952 DBFIFO_HP_INT_F | DBFIFO_LP_INT_F);
1953 else
1954 t4_set_reg_field(adap, SGE_INT_ENABLE3_A,
1955 DBFIFO_LP_INT_F, DBFIFO_LP_INT_F);
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301956}
1957
1958static void sync_txq_pidx(struct adapter *adap, struct sge_txq *q)
1959{
1960 u16 hw_pidx, hw_cidx;
1961 int ret;
1962
Steve Wise05eb2382014-03-14 21:52:08 +05301963 spin_lock_irq(&q->db_lock);
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301964 ret = read_eq_indices(adap, (u16)q->cntxt_id, &hw_pidx, &hw_cidx);
1965 if (ret)
1966 goto out;
1967 if (q->db_pidx != hw_pidx) {
1968 u16 delta;
Hariprasad Shenaif612b812015-01-05 16:30:43 +05301969 u32 val;
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301970
1971 if (q->db_pidx >= hw_pidx)
1972 delta = q->db_pidx - hw_pidx;
1973 else
1974 delta = q->size - hw_pidx + q->db_pidx;
Hariprasad Shenaif612b812015-01-05 16:30:43 +05301975
1976 if (is_t4(adap->params.chip))
1977 val = PIDX_V(delta);
1978 else
1979 val = PIDX_T5_V(delta);
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301980 wmb();
Hariprasad Shenaif612b812015-01-05 16:30:43 +05301981 t4_write_reg(adap, MYPF_REG(SGE_PF_KDOORBELL_A),
1982 QID_V(q->cntxt_id) | val);
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301983 }
1984out:
1985 q->db_disabled = 0;
Steve Wise05eb2382014-03-14 21:52:08 +05301986 q->db_pidx_inc = 0;
1987 spin_unlock_irq(&q->db_lock);
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301988 if (ret)
1989 CH_WARN(adap, "DB drop recovery failed.\n");
1990}
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05301991
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05301992static void recover_all_queues(struct adapter *adap)
1993{
1994 int i;
1995
1996 for_each_ethrxq(&adap->sge, i)
1997 sync_txq_pidx(adap, &adap->sge.ethtxq[i].q);
Hariprasad Shenaiab677ff2016-11-18 16:37:40 +05301998 if (is_offload(adap)) {
1999 struct sge_uld_txq_info *txq_info =
2000 adap->sge.uld_txq_info[CXGB4_TX_OFLD];
2001 if (txq_info) {
2002 for_each_ofldtxq(&adap->sge, i) {
2003 struct sge_uld_txq *txq = &txq_info->uldtxq[i];
2004
2005 sync_txq_pidx(adap, &txq->q);
2006 }
2007 }
2008 }
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05302009 for_each_port(adap, i)
2010 sync_txq_pidx(adap, &adap->sge.ctrlq[i].q);
2011}
2012
Vipul Pandya881806b2012-05-18 15:29:24 +05302013static void process_db_drop(struct work_struct *work)
2014{
2015 struct adapter *adap;
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05302016
Vipul Pandya881806b2012-05-18 15:29:24 +05302017 adap = container_of(work, struct adapter, db_drop_task);
2018
Hariprasad Shenaid14807d2013-12-03 17:05:56 +05302019 if (is_t4(adap->params.chip)) {
Steve Wise05eb2382014-03-14 21:52:08 +05302020 drain_db_fifo(adap, dbfifo_drain_delay);
Santosh Rastapur2cc301d2013-03-14 05:08:52 +00002021 notify_rdma_uld(adap, CXGB4_CONTROL_DB_DROP);
Steve Wise05eb2382014-03-14 21:52:08 +05302022 drain_db_fifo(adap, dbfifo_drain_delay);
Santosh Rastapur2cc301d2013-03-14 05:08:52 +00002023 recover_all_queues(adap);
Steve Wise05eb2382014-03-14 21:52:08 +05302024 drain_db_fifo(adap, dbfifo_drain_delay);
Santosh Rastapur2cc301d2013-03-14 05:08:52 +00002025 enable_dbs(adap);
Steve Wise05eb2382014-03-14 21:52:08 +05302026 notify_rdma_uld(adap, CXGB4_CONTROL_DB_EMPTY);
Hariprasad Shenai3ccc6cf2015-06-02 13:59:39 +05302027 } else if (is_t5(adap->params.chip)) {
Santosh Rastapur2cc301d2013-03-14 05:08:52 +00002028 u32 dropped_db = t4_read_reg(adap, 0x010ac);
2029 u16 qid = (dropped_db >> 15) & 0x1ffff;
2030 u16 pidx_inc = dropped_db & 0x1fff;
Hariprasad Shenaidf64e4d2014-12-03 19:32:53 +05302031 u64 bar2_qoffset;
2032 unsigned int bar2_qid;
2033 int ret;
Santosh Rastapur2cc301d2013-03-14 05:08:52 +00002034
Hariprasad Shenaib2612722015-05-27 22:30:24 +05302035 ret = t4_bar2_sge_qregs(adap, qid, T4_BAR2_QTYPE_EGRESS,
Linus Torvaldse0456712015-06-24 16:49:49 -07002036 0, &bar2_qoffset, &bar2_qid);
Hariprasad Shenaidf64e4d2014-12-03 19:32:53 +05302037 if (ret)
2038 dev_err(adap->pdev_dev, "doorbell drop recovery: "
2039 "qid=%d, pidx_inc=%d\n", qid, pidx_inc);
2040 else
Hariprasad Shenaif612b812015-01-05 16:30:43 +05302041 writel(PIDX_T5_V(pidx_inc) | QID_V(bar2_qid),
Hariprasad Shenaidf64e4d2014-12-03 19:32:53 +05302042 adap->bar2 + bar2_qoffset + SGE_UDB_KDOORBELL);
Santosh Rastapur2cc301d2013-03-14 05:08:52 +00002043
2044 /* Re-enable BAR2 WC */
2045 t4_set_reg_field(adap, 0x10b0, 1<<15, 1<<15);
2046 }
2047
Hariprasad Shenai3ccc6cf2015-06-02 13:59:39 +05302048 if (CHELSIO_CHIP_VERSION(adap->params.chip) <= CHELSIO_T5)
2049 t4_set_reg_field(adap, SGE_DOORBELL_CONTROL_A, DROPPED_DB_F, 0);
Vipul Pandya881806b2012-05-18 15:29:24 +05302050}
2051
2052void t4_db_full(struct adapter *adap)
2053{
Hariprasad Shenaid14807d2013-12-03 17:05:56 +05302054 if (is_t4(adap->params.chip)) {
Steve Wise05eb2382014-03-14 21:52:08 +05302055 disable_dbs(adap);
2056 notify_rdma_uld(adap, CXGB4_CONTROL_DB_FULL);
Hariprasad Shenaif612b812015-01-05 16:30:43 +05302057 t4_set_reg_field(adap, SGE_INT_ENABLE3_A,
2058 DBFIFO_HP_INT_F | DBFIFO_LP_INT_F, 0);
Anish Bhatt29aaee62014-08-20 13:44:06 -07002059 queue_work(adap->workq, &adap->db_full_task);
Santosh Rastapur2cc301d2013-03-14 05:08:52 +00002060 }
Vipul Pandya881806b2012-05-18 15:29:24 +05302061}
2062
2063void t4_db_dropped(struct adapter *adap)
2064{
Steve Wise05eb2382014-03-14 21:52:08 +05302065 if (is_t4(adap->params.chip)) {
2066 disable_dbs(adap);
2067 notify_rdma_uld(adap, CXGB4_CONTROL_DB_FULL);
2068 }
Anish Bhatt29aaee62014-08-20 13:44:06 -07002069 queue_work(adap->workq, &adap->db_drop_task);
Vipul Pandya881806b2012-05-18 15:29:24 +05302070}
2071
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05302072void t4_register_netevent_notifier(void)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002073{
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002074 if (!netevent_registered) {
2075 register_netevent_notifier(&cxgb4_netevent_nb);
2076 netevent_registered = true;
2077 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002078}
2079
2080static void detach_ulds(struct adapter *adap)
2081{
2082 unsigned int i;
2083
2084 mutex_lock(&uld_mutex);
2085 list_del(&adap->list_node);
Guilherme G. Piccoli6a146f32017-07-10 10:55:46 -03002086
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002087 for (i = 0; i < CXGB4_ULD_MAX; i++)
Guilherme G. Piccoli6a146f32017-07-10 10:55:46 -03002088 if (adap->uld && adap->uld[i].handle)
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05302089 adap->uld[i].state_change(adap->uld[i].handle,
2090 CXGB4_STATE_DETACH);
Guilherme G. Piccoli6a146f32017-07-10 10:55:46 -03002091
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002092 if (netevent_registered && list_empty(&adapter_list)) {
2093 unregister_netevent_notifier(&cxgb4_netevent_nb);
2094 netevent_registered = false;
2095 }
2096 mutex_unlock(&uld_mutex);
2097}
2098
2099static void notify_ulds(struct adapter *adap, enum cxgb4_state new_state)
2100{
2101 unsigned int i;
2102
2103 mutex_lock(&uld_mutex);
2104 for (i = 0; i < CXGB4_ULD_MAX; i++)
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05302105 if (adap->uld && adap->uld[i].handle)
2106 adap->uld[i].state_change(adap->uld[i].handle,
2107 new_state);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002108 mutex_unlock(&uld_mutex);
2109}
2110
Anish Bhatt1bb60372014-10-14 20:07:22 -07002111#if IS_ENABLED(CONFIG_IPV6)
Anish Bhattb5a02f52015-01-14 15:17:34 -08002112static int cxgb4_inet6addr_handler(struct notifier_block *this,
2113 unsigned long event, void *data)
Vipul Pandya01bcca62013-07-04 16:10:46 +05302114{
Anish Bhattb5a02f52015-01-14 15:17:34 -08002115 struct inet6_ifaddr *ifa = data;
2116 struct net_device *event_dev = ifa->idev->dev;
2117 const struct device *parent = NULL;
2118#if IS_ENABLED(CONFIG_BONDING)
Vipul Pandya01bcca62013-07-04 16:10:46 +05302119 struct adapter *adap;
Anish Bhattb5a02f52015-01-14 15:17:34 -08002120#endif
Parav Panditd0d7b102017-02-04 11:00:49 -06002121 if (is_vlan_dev(event_dev))
Anish Bhattb5a02f52015-01-14 15:17:34 -08002122 event_dev = vlan_dev_real_dev(event_dev);
2123#if IS_ENABLED(CONFIG_BONDING)
2124 if (event_dev->flags & IFF_MASTER) {
2125 list_for_each_entry(adap, &adapter_list, list_node) {
2126 switch (event) {
2127 case NETDEV_UP:
2128 cxgb4_clip_get(adap->port[0],
2129 (const u32 *)ifa, 1);
2130 break;
2131 case NETDEV_DOWN:
2132 cxgb4_clip_release(adap->port[0],
2133 (const u32 *)ifa, 1);
2134 break;
2135 default:
2136 break;
2137 }
2138 }
2139 return NOTIFY_OK;
2140 }
2141#endif
Vipul Pandya01bcca62013-07-04 16:10:46 +05302142
Anish Bhattb5a02f52015-01-14 15:17:34 -08002143 if (event_dev)
2144 parent = event_dev->dev.parent;
Vipul Pandya01bcca62013-07-04 16:10:46 +05302145
Anish Bhattb5a02f52015-01-14 15:17:34 -08002146 if (parent && parent->driver == &cxgb4_driver.driver) {
Vipul Pandya01bcca62013-07-04 16:10:46 +05302147 switch (event) {
2148 case NETDEV_UP:
Anish Bhattb5a02f52015-01-14 15:17:34 -08002149 cxgb4_clip_get(event_dev, (const u32 *)ifa, 1);
Vipul Pandya01bcca62013-07-04 16:10:46 +05302150 break;
2151 case NETDEV_DOWN:
Anish Bhattb5a02f52015-01-14 15:17:34 -08002152 cxgb4_clip_release(event_dev, (const u32 *)ifa, 1);
Vipul Pandya01bcca62013-07-04 16:10:46 +05302153 break;
2154 default:
2155 break;
2156 }
2157 }
Anish Bhattb5a02f52015-01-14 15:17:34 -08002158 return NOTIFY_OK;
Vipul Pandya01bcca62013-07-04 16:10:46 +05302159}
2160
Anish Bhattb5a02f52015-01-14 15:17:34 -08002161static bool inet6addr_registered;
Vipul Pandya01bcca62013-07-04 16:10:46 +05302162static struct notifier_block cxgb4_inet6addr_notifier = {
2163 .notifier_call = cxgb4_inet6addr_handler
2164};
2165
Vipul Pandya01bcca62013-07-04 16:10:46 +05302166static void update_clip(const struct adapter *adap)
2167{
2168 int i;
2169 struct net_device *dev;
2170 int ret;
2171
2172 rcu_read_lock();
2173
2174 for (i = 0; i < MAX_NPORTS; i++) {
2175 dev = adap->port[i];
2176 ret = 0;
2177
2178 if (dev)
Anish Bhattb5a02f52015-01-14 15:17:34 -08002179 ret = cxgb4_update_root_dev_clip(dev);
Vipul Pandya01bcca62013-07-04 16:10:46 +05302180
2181 if (ret < 0)
2182 break;
2183 }
2184 rcu_read_unlock();
2185}
Anish Bhatt1bb60372014-10-14 20:07:22 -07002186#endif /* IS_ENABLED(CONFIG_IPV6) */
Vipul Pandya01bcca62013-07-04 16:10:46 +05302187
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002188/**
2189 * cxgb_up - enable the adapter
2190 * @adap: adapter being enabled
2191 *
2192 * Called when the first port is enabled, this function performs the
2193 * actions necessary to make an adapter operational, such as completing
2194 * the initialization of HW modules, and enabling interrupts.
2195 *
2196 * Must be called with the rtnl lock held.
2197 */
2198static int cxgb_up(struct adapter *adap)
2199{
Dimitris Michailidisaaefae92010-05-18 10:07:12 +00002200 int err;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002201
Raju Rangoju91060382017-06-19 17:40:48 +05302202 mutex_lock(&uld_mutex);
Dimitris Michailidisaaefae92010-05-18 10:07:12 +00002203 err = setup_sge_queues(adap);
2204 if (err)
Raju Rangoju91060382017-06-19 17:40:48 +05302205 goto rel_lock;
Dimitris Michailidisaaefae92010-05-18 10:07:12 +00002206 err = setup_rss(adap);
2207 if (err)
2208 goto freeq;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002209
2210 if (adap->flags & USING_MSIX) {
Dimitris Michailidisaaefae92010-05-18 10:07:12 +00002211 name_msix_vecs(adap);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002212 err = request_irq(adap->msix_info[0].vec, t4_nondata_intr, 0,
2213 adap->msix_info[0].desc, adap);
2214 if (err)
2215 goto irq_err;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002216 err = request_msix_queue_irqs(adap);
2217 if (err) {
2218 free_irq(adap->msix_info[0].vec, adap);
2219 goto irq_err;
2220 }
2221 } else {
2222 err = request_irq(adap->pdev->irq, t4_intr_handler(adap),
2223 (adap->flags & USING_MSI) ? 0 : IRQF_SHARED,
Dimitris Michailidisb1a3c2b2010-12-14 21:36:51 +00002224 adap->port[0]->name, adap);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002225 if (err)
2226 goto irq_err;
2227 }
Ganesh Goudare7519f92017-05-31 18:26:28 +05302228
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002229 enable_rx(adap);
2230 t4_sge_start(adap);
2231 t4_intr_enable(adap);
Dimitris Michailidisaaefae92010-05-18 10:07:12 +00002232 adap->flags |= FULL_INIT_DONE;
Ganesh Goudare7519f92017-05-31 18:26:28 +05302233 mutex_unlock(&uld_mutex);
2234
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002235 notify_ulds(adap, CXGB4_STATE_UP);
Anish Bhatt1bb60372014-10-14 20:07:22 -07002236#if IS_ENABLED(CONFIG_IPV6)
Vipul Pandya01bcca62013-07-04 16:10:46 +05302237 update_clip(adap);
Anish Bhatt1bb60372014-10-14 20:07:22 -07002238#endif
Hariprasad Shenaifc08a012016-02-16 10:07:09 +05302239 /* Initialize hash mac addr list*/
2240 INIT_LIST_HEAD(&adap->mac_hlist);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002241 return err;
Raju Rangoju91060382017-06-19 17:40:48 +05302242
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002243 irq_err:
2244 dev_err(adap->pdev_dev, "request_irq failed, err %d\n", err);
Dimitris Michailidisaaefae92010-05-18 10:07:12 +00002245 freeq:
2246 t4_free_sge_resources(adap);
Raju Rangoju91060382017-06-19 17:40:48 +05302247 rel_lock:
2248 mutex_unlock(&uld_mutex);
2249 return err;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002250}
2251
2252static void cxgb_down(struct adapter *adapter)
2253{
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002254 cancel_work_sync(&adapter->tid_release_task);
Vipul Pandya881806b2012-05-18 15:29:24 +05302255 cancel_work_sync(&adapter->db_full_task);
2256 cancel_work_sync(&adapter->db_drop_task);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002257 adapter->tid_release_task_busy = false;
Dimitris Michailidis204dc3c2010-06-18 10:05:29 +00002258 adapter->tid_release_head = NULL;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002259
Dimitris Michailidisaaefae92010-05-18 10:07:12 +00002260 t4_sge_stop(adapter);
2261 t4_free_sge_resources(adapter);
2262 adapter->flags &= ~FULL_INIT_DONE;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002263}
2264
2265/*
2266 * net_device operations
2267 */
2268static int cxgb_open(struct net_device *dev)
2269{
2270 int err;
2271 struct port_info *pi = netdev_priv(dev);
2272 struct adapter *adapter = pi->adapter;
2273
Dimitris Michailidis6a3c8692011-01-19 15:29:05 +00002274 netif_carrier_off(dev);
2275
Dimitris Michailidisaaefae92010-05-18 10:07:12 +00002276 if (!(adapter->flags & FULL_INIT_DONE)) {
2277 err = cxgb_up(adapter);
2278 if (err < 0)
2279 return err;
2280 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002281
Ganesh Goudar2061ec32017-05-19 17:50:15 +05302282 /* It's possible that the basic port information could have
2283 * changed since we first read it.
2284 */
2285 err = t4_update_port_info(pi);
2286 if (err < 0)
2287 return err;
2288
Dimitris Michailidisf68707b2010-06-18 10:05:32 +00002289 err = link_start(dev);
2290 if (!err)
2291 netif_tx_start_all_queues(dev);
2292 return err;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002293}
2294
2295static int cxgb_close(struct net_device *dev)
2296{
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002297 struct port_info *pi = netdev_priv(dev);
2298 struct adapter *adapter = pi->adapter;
2299
2300 netif_tx_stop_all_queues(dev);
2301 netif_carrier_off(dev);
Hariprasad Shenaib2612722015-05-27 22:30:24 +05302302 return t4_enable_vi(adapter, adapter->pf, pi->viid, false, false);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002303}
2304
Vipul Pandyadca4fae2012-12-10 09:30:53 +00002305int cxgb4_create_server_filter(const struct net_device *dev, unsigned int stid,
Vipul Pandya793dad92012-12-10 09:30:56 +00002306 __be32 sip, __be16 sport, __be16 vlan,
2307 unsigned int queue, unsigned char port, unsigned char mask)
Vipul Pandyadca4fae2012-12-10 09:30:53 +00002308{
2309 int ret;
2310 struct filter_entry *f;
2311 struct adapter *adap;
2312 int i;
2313 u8 *val;
2314
2315 adap = netdev2adap(dev);
2316
Vipul Pandya1cab7752012-12-10 09:30:55 +00002317 /* Adjust stid to correct filter index */
Kumar Sanghvi470c60c2013-12-18 16:38:21 +05302318 stid -= adap->tids.sftid_base;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002319 stid += adap->tids.nftids;
2320
Vipul Pandyadca4fae2012-12-10 09:30:53 +00002321 /* Check to make sure the filter requested is writable ...
2322 */
2323 f = &adap->tids.ftid_tab[stid];
2324 ret = writable_filter(f);
2325 if (ret)
2326 return ret;
2327
2328 /* Clear out any old resources being used by the filter before
2329 * we start constructing the new filter.
2330 */
2331 if (f->valid)
2332 clear_filter(adap, f);
2333
2334 /* Clear out filter specifications */
2335 memset(&f->fs, 0, sizeof(struct ch_filter_specification));
2336 f->fs.val.lport = cpu_to_be16(sport);
2337 f->fs.mask.lport = ~0;
2338 val = (u8 *)&sip;
Vipul Pandya793dad92012-12-10 09:30:56 +00002339 if ((val[0] | val[1] | val[2] | val[3]) != 0) {
Vipul Pandyadca4fae2012-12-10 09:30:53 +00002340 for (i = 0; i < 4; i++) {
2341 f->fs.val.lip[i] = val[i];
2342 f->fs.mask.lip[i] = ~0;
2343 }
Hariprasad Shenai0d804332015-01-05 16:30:47 +05302344 if (adap->params.tp.vlan_pri_map & PORT_F) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002345 f->fs.val.iport = port;
2346 f->fs.mask.iport = mask;
2347 }
2348 }
Vipul Pandyadca4fae2012-12-10 09:30:53 +00002349
Hariprasad Shenai0d804332015-01-05 16:30:47 +05302350 if (adap->params.tp.vlan_pri_map & PROTOCOL_F) {
Kumar Sanghvi7c89e552013-12-18 16:38:20 +05302351 f->fs.val.proto = IPPROTO_TCP;
2352 f->fs.mask.proto = ~0;
2353 }
2354
Vipul Pandyadca4fae2012-12-10 09:30:53 +00002355 f->fs.dirsteer = 1;
2356 f->fs.iq = queue;
2357 /* Mark filter as locked */
2358 f->locked = 1;
2359 f->fs.rpttid = 1;
2360
Ganesh Goudar6b254af2017-04-10 21:26:18 +05302361 /* Save the actual tid. We need this to get the corresponding
2362 * filter entry structure in filter_rpl.
2363 */
2364 f->tid = stid + adap->tids.ftid_base;
Vipul Pandyadca4fae2012-12-10 09:30:53 +00002365 ret = set_filter_wr(adap, stid);
2366 if (ret) {
2367 clear_filter(adap, f);
2368 return ret;
2369 }
2370
2371 return 0;
2372}
2373EXPORT_SYMBOL(cxgb4_create_server_filter);
2374
2375int cxgb4_remove_server_filter(const struct net_device *dev, unsigned int stid,
2376 unsigned int queue, bool ipv6)
2377{
Vipul Pandyadca4fae2012-12-10 09:30:53 +00002378 struct filter_entry *f;
2379 struct adapter *adap;
2380
2381 adap = netdev2adap(dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002382
2383 /* Adjust stid to correct filter index */
Kumar Sanghvi470c60c2013-12-18 16:38:21 +05302384 stid -= adap->tids.sftid_base;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002385 stid += adap->tids.nftids;
2386
Vipul Pandyadca4fae2012-12-10 09:30:53 +00002387 f = &adap->tids.ftid_tab[stid];
2388 /* Unlock the filter */
2389 f->locked = 0;
2390
Wei Yongjun8c148462016-08-20 15:32:41 +00002391 return delete_filter(adap, stid);
Vipul Pandyadca4fae2012-12-10 09:30:53 +00002392}
2393EXPORT_SYMBOL(cxgb4_remove_server_filter);
2394
stephen hemmingerbc1f4472017-01-06 19:12:52 -08002395static void cxgb_get_stats(struct net_device *dev,
2396 struct rtnl_link_stats64 *ns)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002397{
2398 struct port_stats stats;
2399 struct port_info *p = netdev_priv(dev);
2400 struct adapter *adapter = p->adapter;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002401
Gavin Shan9fe6cb52014-01-23 12:27:35 +08002402 /* Block retrieving statistics during EEH error
2403 * recovery. Otherwise, the recovery might fail
2404 * and the PCI device will be removed permanently
2405 */
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002406 spin_lock(&adapter->stats_lock);
Gavin Shan9fe6cb52014-01-23 12:27:35 +08002407 if (!netif_device_present(dev)) {
2408 spin_unlock(&adapter->stats_lock);
stephen hemmingerbc1f4472017-01-06 19:12:52 -08002409 return;
Gavin Shan9fe6cb52014-01-23 12:27:35 +08002410 }
Hariprasad Shenaia4cfd922015-06-03 21:04:39 +05302411 t4_get_port_stats_offset(adapter, p->tx_chan, &stats,
2412 &p->stats_base);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002413 spin_unlock(&adapter->stats_lock);
2414
2415 ns->tx_bytes = stats.tx_octets;
2416 ns->tx_packets = stats.tx_frames;
2417 ns->rx_bytes = stats.rx_octets;
2418 ns->rx_packets = stats.rx_frames;
2419 ns->multicast = stats.rx_mcast_frames;
2420
2421 /* detailed rx_errors */
2422 ns->rx_length_errors = stats.rx_jabber + stats.rx_too_long +
2423 stats.rx_runt;
2424 ns->rx_over_errors = 0;
2425 ns->rx_crc_errors = stats.rx_fcs_err;
2426 ns->rx_frame_errors = stats.rx_symbol_err;
Ganesh Goudarb93f79b2017-02-15 11:45:25 +05302427 ns->rx_dropped = stats.rx_ovflow0 + stats.rx_ovflow1 +
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002428 stats.rx_ovflow2 + stats.rx_ovflow3 +
2429 stats.rx_trunc0 + stats.rx_trunc1 +
2430 stats.rx_trunc2 + stats.rx_trunc3;
2431 ns->rx_missed_errors = 0;
2432
2433 /* detailed tx_errors */
2434 ns->tx_aborted_errors = 0;
2435 ns->tx_carrier_errors = 0;
2436 ns->tx_fifo_errors = 0;
2437 ns->tx_heartbeat_errors = 0;
2438 ns->tx_window_errors = 0;
2439
2440 ns->tx_errors = stats.tx_error_frames;
2441 ns->rx_errors = stats.rx_symbol_err + stats.rx_fcs_err +
2442 ns->rx_length_errors + stats.rx_len_err + ns->rx_fifo_errors;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002443}
2444
2445static int cxgb_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
2446{
Dimitris Michailidis060e0c72010-08-02 13:19:21 +00002447 unsigned int mbox;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002448 int ret = 0, prtad, devad;
2449 struct port_info *pi = netdev_priv(dev);
Atul Guptaa45695042017-07-04 16:46:20 +05302450 struct adapter *adapter = pi->adapter;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002451 struct mii_ioctl_data *data = (struct mii_ioctl_data *)&req->ifr_data;
2452
2453 switch (cmd) {
2454 case SIOCGMIIPHY:
2455 if (pi->mdio_addr < 0)
2456 return -EOPNOTSUPP;
2457 data->phy_id = pi->mdio_addr;
2458 break;
2459 case SIOCGMIIREG:
2460 case SIOCSMIIREG:
2461 if (mdio_phy_id_is_c45(data->phy_id)) {
2462 prtad = mdio_phy_id_prtad(data->phy_id);
2463 devad = mdio_phy_id_devad(data->phy_id);
2464 } else if (data->phy_id < 32) {
2465 prtad = data->phy_id;
2466 devad = 0;
2467 data->reg_num &= 0x1f;
2468 } else
2469 return -EINVAL;
2470
Hariprasad Shenaib2612722015-05-27 22:30:24 +05302471 mbox = pi->adapter->pf;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002472 if (cmd == SIOCGMIIREG)
Dimitris Michailidis060e0c72010-08-02 13:19:21 +00002473 ret = t4_mdio_rd(pi->adapter, mbox, prtad, devad,
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002474 data->reg_num, &data->val_out);
2475 else
Dimitris Michailidis060e0c72010-08-02 13:19:21 +00002476 ret = t4_mdio_wr(pi->adapter, mbox, prtad, devad,
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002477 data->reg_num, data->val_in);
2478 break;
Hariprasad Shenai5e2a5eb2015-09-28 10:26:53 +05302479 case SIOCGHWTSTAMP:
2480 return copy_to_user(req->ifr_data, &pi->tstamp_config,
2481 sizeof(pi->tstamp_config)) ?
2482 -EFAULT : 0;
2483 case SIOCSHWTSTAMP:
2484 if (copy_from_user(&pi->tstamp_config, req->ifr_data,
2485 sizeof(pi->tstamp_config)))
2486 return -EFAULT;
2487
Atul Guptaa45695042017-07-04 16:46:20 +05302488 if (!is_t4(adapter->params.chip)) {
2489 switch (pi->tstamp_config.tx_type) {
2490 case HWTSTAMP_TX_OFF:
2491 case HWTSTAMP_TX_ON:
2492 break;
2493 default:
2494 return -ERANGE;
2495 }
2496
2497 switch (pi->tstamp_config.rx_filter) {
2498 case HWTSTAMP_FILTER_NONE:
2499 pi->rxtstamp = false;
2500 break;
2501 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
2502 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
2503 cxgb4_ptprx_timestamping(pi, pi->port_id,
2504 PTP_TS_L4);
2505 break;
2506 case HWTSTAMP_FILTER_PTP_V2_EVENT:
2507 cxgb4_ptprx_timestamping(pi, pi->port_id,
2508 PTP_TS_L2_L4);
2509 break;
2510 case HWTSTAMP_FILTER_ALL:
2511 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
2512 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
2513 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
2514 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
2515 pi->rxtstamp = true;
2516 break;
2517 default:
2518 pi->tstamp_config.rx_filter =
2519 HWTSTAMP_FILTER_NONE;
2520 return -ERANGE;
2521 }
2522
2523 if ((pi->tstamp_config.tx_type == HWTSTAMP_TX_OFF) &&
2524 (pi->tstamp_config.rx_filter ==
2525 HWTSTAMP_FILTER_NONE)) {
2526 if (cxgb4_ptp_txtype(adapter, pi->port_id) >= 0)
2527 pi->ptp_enable = false;
2528 }
2529
2530 if (pi->tstamp_config.rx_filter !=
2531 HWTSTAMP_FILTER_NONE) {
2532 if (cxgb4_ptp_redirect_rx_packet(adapter,
2533 pi) >= 0)
2534 pi->ptp_enable = true;
2535 }
2536 } else {
2537 /* For T4 Adapters */
2538 switch (pi->tstamp_config.rx_filter) {
2539 case HWTSTAMP_FILTER_NONE:
Hariprasad Shenai5e2a5eb2015-09-28 10:26:53 +05302540 pi->rxtstamp = false;
2541 break;
Atul Guptaa45695042017-07-04 16:46:20 +05302542 case HWTSTAMP_FILTER_ALL:
Hariprasad Shenai5e2a5eb2015-09-28 10:26:53 +05302543 pi->rxtstamp = true;
2544 break;
Atul Guptaa45695042017-07-04 16:46:20 +05302545 default:
2546 pi->tstamp_config.rx_filter =
2547 HWTSTAMP_FILTER_NONE;
Hariprasad Shenai5e2a5eb2015-09-28 10:26:53 +05302548 return -ERANGE;
Atul Guptaa45695042017-07-04 16:46:20 +05302549 }
Hariprasad Shenai5e2a5eb2015-09-28 10:26:53 +05302550 }
Hariprasad Shenai5e2a5eb2015-09-28 10:26:53 +05302551 return copy_to_user(req->ifr_data, &pi->tstamp_config,
2552 sizeof(pi->tstamp_config)) ?
2553 -EFAULT : 0;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002554 default:
2555 return -EOPNOTSUPP;
2556 }
2557 return ret;
2558}
2559
2560static void cxgb_set_rxmode(struct net_device *dev)
2561{
2562 /* unfortunately we can't return errors to the stack */
2563 set_rxmode(dev, -1, false);
2564}
2565
2566static int cxgb_change_mtu(struct net_device *dev, int new_mtu)
2567{
2568 int ret;
2569 struct port_info *pi = netdev_priv(dev);
2570
Hariprasad Shenaib2612722015-05-27 22:30:24 +05302571 ret = t4_set_rxmode(pi->adapter, pi->adapter->pf, pi->viid, new_mtu, -1,
Dimitris Michailidis060e0c72010-08-02 13:19:21 +00002572 -1, -1, -1, true);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002573 if (!ret)
2574 dev->mtu = new_mtu;
2575 return ret;
2576}
2577
Hariprasad Shenai858aa652016-08-11 21:06:24 +05302578#ifdef CONFIG_PCI_IOV
Hariprasad Shenaie7b48a32016-08-23 11:35:32 +05302579static int dummy_open(struct net_device *dev)
2580{
2581 /* Turn carrier off since we don't have to transmit anything on this
2582 * interface.
2583 */
2584 netif_carrier_off(dev);
2585 return 0;
2586}
2587
Hariprasad Shenai661dbeb2016-09-02 19:13:53 +05302588/* Fill MAC address that will be assigned by the FW */
2589static void fill_vf_station_mac_addr(struct adapter *adap)
2590{
2591 unsigned int i;
2592 u8 hw_addr[ETH_ALEN], macaddr[ETH_ALEN];
2593 int err;
2594 u8 *na;
2595 u16 a, b;
2596
2597 err = t4_get_raw_vpd_params(adap, &adap->params.vpd);
2598 if (!err) {
2599 na = adap->params.vpd.na;
2600 for (i = 0; i < ETH_ALEN; i++)
2601 hw_addr[i] = (hex2val(na[2 * i + 0]) * 16 +
2602 hex2val(na[2 * i + 1]));
2603 a = (hw_addr[0] << 8) | hw_addr[1];
2604 b = (hw_addr[1] << 8) | hw_addr[2];
2605 a ^= b;
2606 a |= 0x0200; /* locally assigned Ethernet MAC address */
2607 a &= ~0x0100; /* not a multicast Ethernet MAC address */
2608 macaddr[0] = a >> 8;
2609 macaddr[1] = a & 0xff;
2610
2611 for (i = 2; i < 5; i++)
2612 macaddr[i] = hw_addr[i + 1];
2613
2614 for (i = 0; i < adap->num_vfs; i++) {
2615 macaddr[5] = adap->pf * 16 + i;
2616 ether_addr_copy(adap->vfinfo[i].vf_mac_addr, macaddr);
2617 }
2618 }
2619}
2620
Hariprasad Shenai858aa652016-08-11 21:06:24 +05302621static int cxgb_set_vf_mac(struct net_device *dev, int vf, u8 *mac)
2622{
2623 struct port_info *pi = netdev_priv(dev);
2624 struct adapter *adap = pi->adapter;
Hariprasad Shenai661dbeb2016-09-02 19:13:53 +05302625 int ret;
Hariprasad Shenai858aa652016-08-11 21:06:24 +05302626
2627 /* verify MAC addr is valid */
2628 if (!is_valid_ether_addr(mac)) {
2629 dev_err(pi->adapter->pdev_dev,
2630 "Invalid Ethernet address %pM for VF %d\n",
2631 mac, vf);
2632 return -EINVAL;
2633 }
2634
2635 dev_info(pi->adapter->pdev_dev,
2636 "Setting MAC %pM on VF %d\n", mac, vf);
Hariprasad Shenai661dbeb2016-09-02 19:13:53 +05302637 ret = t4_set_vf_mac_acl(adap, vf + 1, 1, mac);
2638 if (!ret)
2639 ether_addr_copy(adap->vfinfo[vf].vf_mac_addr, mac);
2640 return ret;
2641}
2642
2643static int cxgb_get_vf_config(struct net_device *dev,
2644 int vf, struct ifla_vf_info *ivi)
2645{
2646 struct port_info *pi = netdev_priv(dev);
2647 struct adapter *adap = pi->adapter;
2648
2649 if (vf >= adap->num_vfs)
2650 return -EINVAL;
2651 ivi->vf = vf;
Ganesh Goudar8ea4fae2017-06-05 18:34:20 +05302652 ivi->max_tx_rate = adap->vfinfo[vf].tx_rate;
2653 ivi->min_tx_rate = 0;
Hariprasad Shenai661dbeb2016-09-02 19:13:53 +05302654 ether_addr_copy(ivi->mac, adap->vfinfo[vf].vf_mac_addr);
2655 return 0;
Hariprasad Shenai858aa652016-08-11 21:06:24 +05302656}
Ganesh Goudar96fe11f2017-01-17 14:09:38 +05302657
2658static int cxgb_get_phys_port_id(struct net_device *dev,
2659 struct netdev_phys_item_id *ppid)
2660{
2661 struct port_info *pi = netdev_priv(dev);
2662 unsigned int phy_port_id;
2663
2664 phy_port_id = pi->adapter->adap_idx * 10 + pi->port_id;
2665 ppid->id_len = sizeof(phy_port_id);
2666 memcpy(ppid->id, &phy_port_id, ppid->id_len);
2667 return 0;
2668}
2669
Ganesh Goudar8ea4fae2017-06-05 18:34:20 +05302670static int cxgb_set_vf_rate(struct net_device *dev, int vf, int min_tx_rate,
2671 int max_tx_rate)
2672{
2673 struct port_info *pi = netdev_priv(dev);
2674 struct adapter *adap = pi->adapter;
2675 struct fw_port_cmd port_cmd, port_rpl;
2676 u32 link_status, speed = 0;
2677 u32 fw_pfvf, fw_class;
2678 int class_id = vf;
2679 int link_ok, ret;
2680 u16 pktsize;
2681
2682 if (vf >= adap->num_vfs)
2683 return -EINVAL;
2684
2685 if (min_tx_rate) {
2686 dev_err(adap->pdev_dev,
2687 "Min tx rate (%d) (> 0) for VF %d is Invalid.\n",
2688 min_tx_rate, vf);
2689 return -EINVAL;
2690 }
2691 /* Retrieve link details for VF port */
2692 memset(&port_cmd, 0, sizeof(port_cmd));
2693 port_cmd.op_to_portid = cpu_to_be32(FW_CMD_OP_V(FW_PORT_CMD) |
2694 FW_CMD_REQUEST_F |
2695 FW_CMD_READ_F |
2696 FW_PORT_CMD_PORTID_V(pi->port_id));
2697 port_cmd.action_to_len16 =
2698 cpu_to_be32(FW_PORT_CMD_ACTION_V(FW_PORT_ACTION_GET_PORT_INFO) |
2699 FW_LEN16(port_cmd));
2700 ret = t4_wr_mbox(adap, adap->mbox, &port_cmd, sizeof(port_cmd),
2701 &port_rpl);
2702 if (ret != FW_SUCCESS) {
2703 dev_err(adap->pdev_dev,
2704 "Failed to get link status for VF %d\n", vf);
2705 return -EINVAL;
2706 }
2707 link_status = be32_to_cpu(port_rpl.u.info.lstatus_to_modtype);
2708 link_ok = (link_status & FW_PORT_CMD_LSTATUS_F) != 0;
2709 if (!link_ok) {
2710 dev_err(adap->pdev_dev, "Link down for VF %d\n", vf);
2711 return -EINVAL;
2712 }
2713 /* Determine link speed */
2714 if (link_status & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_100M))
2715 speed = 100;
2716 else if (link_status & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_1G))
2717 speed = 1000;
2718 else if (link_status & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_10G))
2719 speed = 10000;
2720 else if (link_status & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_25G))
2721 speed = 25000;
2722 else if (link_status & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_40G))
2723 speed = 40000;
2724 else if (link_status & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_100G))
2725 speed = 100000;
2726
2727 if (max_tx_rate > speed) {
2728 dev_err(adap->pdev_dev,
2729 "Max tx rate %d for VF %d can't be > link-speed %u",
2730 max_tx_rate, vf, speed);
2731 return -EINVAL;
2732 }
2733 pktsize = be16_to_cpu(port_rpl.u.info.mtu);
2734 /* subtract ethhdr size and 4 bytes crc since, f/w appends it */
2735 pktsize = pktsize - sizeof(struct ethhdr) - 4;
2736 /* subtract ipv4 hdr size, tcp hdr size to get typical IPv4 MSS size */
2737 pktsize = pktsize - sizeof(struct iphdr) - sizeof(struct tcphdr);
2738 /* configure Traffic Class for rate-limiting */
2739 ret = t4_sched_params(adap, SCHED_CLASS_TYPE_PACKET,
2740 SCHED_CLASS_LEVEL_CL_RL,
2741 SCHED_CLASS_MODE_CLASS,
2742 SCHED_CLASS_RATEUNIT_BITS,
2743 SCHED_CLASS_RATEMODE_ABS,
2744 pi->port_id, class_id, 0,
2745 max_tx_rate * 1000, 0, pktsize);
2746 if (ret) {
2747 dev_err(adap->pdev_dev, "Err %d for Traffic Class config\n",
2748 ret);
2749 return -EINVAL;
2750 }
2751 dev_info(adap->pdev_dev,
2752 "Class %d with MSS %u configured with rate %u\n",
2753 class_id, pktsize, max_tx_rate);
2754
2755 /* bind VF to configured Traffic Class */
2756 fw_pfvf = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_PFVF) |
2757 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_PFVF_SCHEDCLASS_ETH));
2758 fw_class = class_id;
2759 ret = t4_set_params(adap, adap->mbox, adap->pf, vf + 1, 1, &fw_pfvf,
2760 &fw_class);
2761 if (ret) {
2762 dev_err(adap->pdev_dev,
2763 "Err %d in binding VF %d to Traffic Class %d\n",
2764 ret, vf, class_id);
2765 return -EINVAL;
2766 }
2767 dev_info(adap->pdev_dev, "PF %d VF %d is bound to Class %d\n",
2768 adap->pf, vf, class_id);
2769 adap->vfinfo[vf].tx_rate = max_tx_rate;
2770 return 0;
2771}
2772
Hariprasad Shenai858aa652016-08-11 21:06:24 +05302773#endif
2774
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002775static int cxgb_set_mac_addr(struct net_device *dev, void *p)
2776{
2777 int ret;
2778 struct sockaddr *addr = p;
2779 struct port_info *pi = netdev_priv(dev);
2780
2781 if (!is_valid_ether_addr(addr->sa_data))
Danny Kukawka504f9b52012-02-21 02:07:49 +00002782 return -EADDRNOTAVAIL;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002783
Hariprasad Shenaib2612722015-05-27 22:30:24 +05302784 ret = t4_change_mac(pi->adapter, pi->adapter->pf, pi->viid,
Dimitris Michailidis060e0c72010-08-02 13:19:21 +00002785 pi->xact_addr_filt, addr->sa_data, true, true);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002786 if (ret < 0)
2787 return ret;
2788
2789 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
2790 pi->xact_addr_filt = ret;
2791 return 0;
2792}
2793
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002794#ifdef CONFIG_NET_POLL_CONTROLLER
2795static void cxgb_netpoll(struct net_device *dev)
2796{
2797 struct port_info *pi = netdev_priv(dev);
2798 struct adapter *adap = pi->adapter;
2799
2800 if (adap->flags & USING_MSIX) {
2801 int i;
2802 struct sge_eth_rxq *rx = &adap->sge.ethrxq[pi->first_qset];
2803
2804 for (i = pi->nqsets; i; i--, rx++)
2805 t4_sge_intr_msix(0, &rx->rspq);
2806 } else
2807 t4_intr_handler(adap)(0, adap);
2808}
2809#endif
2810
Rahul Lakkireddy10a26042016-08-22 16:29:08 +05302811static int cxgb_set_tx_maxrate(struct net_device *dev, int index, u32 rate)
2812{
2813 struct port_info *pi = netdev_priv(dev);
2814 struct adapter *adap = pi->adapter;
2815 struct sched_class *e;
2816 struct ch_sched_params p;
2817 struct ch_sched_queue qe;
2818 u32 req_rate;
2819 int err = 0;
2820
2821 if (!can_sched(dev))
2822 return -ENOTSUPP;
2823
2824 if (index < 0 || index > pi->nqsets - 1)
2825 return -EINVAL;
2826
2827 if (!(adap->flags & FULL_INIT_DONE)) {
2828 dev_err(adap->pdev_dev,
2829 "Failed to rate limit on queue %d. Link Down?\n",
2830 index);
2831 return -EINVAL;
2832 }
2833
2834 /* Convert from Mbps to Kbps */
2835 req_rate = rate << 10;
2836
2837 /* Max rate is 10 Gbps */
2838 if (req_rate >= SCHED_MAX_RATE_KBPS) {
2839 dev_err(adap->pdev_dev,
2840 "Invalid rate %u Mbps, Max rate is %u Gbps\n",
2841 rate, SCHED_MAX_RATE_KBPS);
2842 return -ERANGE;
2843 }
2844
2845 /* First unbind the queue from any existing class */
2846 memset(&qe, 0, sizeof(qe));
2847 qe.queue = index;
2848 qe.class = SCHED_CLS_NONE;
2849
2850 err = cxgb4_sched_class_unbind(dev, (void *)(&qe), SCHED_QUEUE);
2851 if (err) {
2852 dev_err(adap->pdev_dev,
2853 "Unbinding Queue %d on port %d fail. Err: %d\n",
2854 index, pi->port_id, err);
2855 return err;
2856 }
2857
2858 /* Queue already unbound */
2859 if (!req_rate)
2860 return 0;
2861
2862 /* Fetch any available unused or matching scheduling class */
2863 memset(&p, 0, sizeof(p));
2864 p.type = SCHED_CLASS_TYPE_PACKET;
2865 p.u.params.level = SCHED_CLASS_LEVEL_CL_RL;
2866 p.u.params.mode = SCHED_CLASS_MODE_CLASS;
2867 p.u.params.rateunit = SCHED_CLASS_RATEUNIT_BITS;
2868 p.u.params.ratemode = SCHED_CLASS_RATEMODE_ABS;
2869 p.u.params.channel = pi->tx_chan;
2870 p.u.params.class = SCHED_CLS_NONE;
2871 p.u.params.minrate = 0;
2872 p.u.params.maxrate = req_rate;
2873 p.u.params.weight = 0;
2874 p.u.params.pktsize = dev->mtu;
2875
2876 e = cxgb4_sched_class_alloc(dev, &p);
2877 if (!e)
2878 return -ENOMEM;
2879
2880 /* Bind the queue to a scheduling class */
2881 memset(&qe, 0, sizeof(qe));
2882 qe.queue = index;
2883 qe.class = e->idx;
2884
2885 err = cxgb4_sched_class_bind(dev, (void *)(&qe), SCHED_QUEUE);
2886 if (err)
2887 dev_err(adap->pdev_dev,
2888 "Queue rate limiting failed. Err: %d\n", err);
2889 return err;
2890}
2891
Jiri Pirkof7323042017-08-07 10:15:20 +02002892static int cxgb_setup_tc_cls_u32(struct net_device *dev,
Jiri Pirkof7323042017-08-07 10:15:20 +02002893 struct tc_cls_u32_offload *cls_u32)
2894{
Jiri Pirko5fd9fc42017-08-07 10:15:29 +02002895 if (TC_H_MAJ(cls_u32->common.handle) != TC_H_MAJ(TC_H_INGRESS) ||
2896 cls_u32->common.chain_index)
Jiri Pirkof7323042017-08-07 10:15:20 +02002897 return -EOPNOTSUPP;
2898
2899 switch (cls_u32->command) {
2900 case TC_CLSU32_NEW_KNODE:
2901 case TC_CLSU32_REPLACE_KNODE:
Jiri Pirko5fd9fc42017-08-07 10:15:29 +02002902 return cxgb4_config_knode(dev, cls_u32);
Jiri Pirkof7323042017-08-07 10:15:20 +02002903 case TC_CLSU32_DELETE_KNODE:
Jiri Pirko5fd9fc42017-08-07 10:15:29 +02002904 return cxgb4_delete_knode(dev, cls_u32);
Jiri Pirkof7323042017-08-07 10:15:20 +02002905 default:
2906 return -EOPNOTSUPP;
2907 }
2908}
2909
Jiri Pirko2572ac52017-08-07 10:15:17 +02002910static int cxgb_setup_tc(struct net_device *dev, enum tc_setup_type type,
Jiri Pirko2572ac52017-08-07 10:15:17 +02002911 struct tc_to_netdev *tc)
Rahul Lakkireddyd8931842016-09-20 17:13:09 +05302912{
2913 struct port_info *pi = netdev2pinfo(dev);
2914 struct adapter *adap = netdev2adap(dev);
2915
2916 if (!(adap->flags & FULL_INIT_DONE)) {
2917 dev_err(adap->pdev_dev,
2918 "Failed to setup tc on port %d. Link Down?\n",
2919 pi->port_id);
2920 return -EINVAL;
2921 }
2922
Jiri Pirkof7323042017-08-07 10:15:20 +02002923 switch (type) {
2924 case TC_SETUP_CLSU32:
Jiri Pirko5fd9fc42017-08-07 10:15:29 +02002925 return cxgb_setup_tc_cls_u32(dev, tc->cls_u32);
Jiri Pirkof7323042017-08-07 10:15:20 +02002926 default:
2927 return -EOPNOTSUPP;
Rahul Lakkireddyd8931842016-09-20 17:13:09 +05302928 }
Rahul Lakkireddyd8931842016-09-20 17:13:09 +05302929}
2930
Arjun Vynipadath90592b92017-05-30 13:30:24 +05302931static netdev_features_t cxgb_fix_features(struct net_device *dev,
2932 netdev_features_t features)
2933{
2934 /* Disable GRO, if RX_CSUM is disabled */
2935 if (!(features & NETIF_F_RXCSUM))
2936 features &= ~NETIF_F_GRO;
2937
2938 return features;
2939}
2940
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002941static const struct net_device_ops cxgb4_netdev_ops = {
2942 .ndo_open = cxgb_open,
2943 .ndo_stop = cxgb_close,
2944 .ndo_start_xmit = t4_eth_xmit,
Anish Bhatt688848b2014-06-19 21:37:13 -07002945 .ndo_select_queue = cxgb_select_queue,
Dimitris Michailidis9be793b2010-06-18 10:05:31 +00002946 .ndo_get_stats64 = cxgb_get_stats,
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002947 .ndo_set_rx_mode = cxgb_set_rxmode,
2948 .ndo_set_mac_address = cxgb_set_mac_addr,
Michał Mirosław2ed28ba2011-04-16 13:05:08 +00002949 .ndo_set_features = cxgb_set_features,
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002950 .ndo_validate_addr = eth_validate_addr,
2951 .ndo_do_ioctl = cxgb_ioctl,
2952 .ndo_change_mtu = cxgb_change_mtu,
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002953#ifdef CONFIG_NET_POLL_CONTROLLER
2954 .ndo_poll_controller = cxgb_netpoll,
2955#endif
Varun Prakash84a200b2015-03-24 19:14:46 +05302956#ifdef CONFIG_CHELSIO_T4_FCOE
2957 .ndo_fcoe_enable = cxgb_fcoe_enable,
2958 .ndo_fcoe_disable = cxgb_fcoe_disable,
2959#endif /* CONFIG_CHELSIO_T4_FCOE */
Rahul Lakkireddy10a26042016-08-22 16:29:08 +05302960 .ndo_set_tx_maxrate = cxgb_set_tx_maxrate,
Rahul Lakkireddyd8931842016-09-20 17:13:09 +05302961 .ndo_setup_tc = cxgb_setup_tc,
Arjun Vynipadath90592b92017-05-30 13:30:24 +05302962 .ndo_fix_features = cxgb_fix_features,
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002963};
2964
Hariprasad Shenai858aa652016-08-11 21:06:24 +05302965#ifdef CONFIG_PCI_IOV
Hariprasad Shenaie7b48a32016-08-23 11:35:32 +05302966static const struct net_device_ops cxgb4_mgmt_netdev_ops = {
2967 .ndo_open = dummy_open,
Hariprasad Shenai858aa652016-08-11 21:06:24 +05302968 .ndo_set_vf_mac = cxgb_set_vf_mac,
Hariprasad Shenai661dbeb2016-09-02 19:13:53 +05302969 .ndo_get_vf_config = cxgb_get_vf_config,
Ganesh Goudar8ea4fae2017-06-05 18:34:20 +05302970 .ndo_set_vf_rate = cxgb_set_vf_rate,
Ganesh Goudar96fe11f2017-01-17 14:09:38 +05302971 .ndo_get_phys_port_id = cxgb_get_phys_port_id,
Hariprasad Shenai78294512016-08-11 21:06:23 +05302972};
Hariprasad Shenaie7b48a32016-08-23 11:35:32 +05302973#endif
Hariprasad Shenai78294512016-08-11 21:06:23 +05302974
2975static void get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
2976{
2977 struct adapter *adapter = netdev2adap(dev);
2978
2979 strlcpy(info->driver, cxgb4_driver_name, sizeof(info->driver));
2980 strlcpy(info->version, cxgb4_driver_version,
2981 sizeof(info->version));
2982 strlcpy(info->bus_info, pci_name(adapter->pdev),
2983 sizeof(info->bus_info));
2984}
2985
2986static const struct ethtool_ops cxgb4_mgmt_ethtool_ops = {
2987 .get_drvinfo = get_drvinfo,
2988};
2989
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00002990void t4_fatal_err(struct adapter *adap)
2991{
Hariprasad Shenai3be06792017-01-13 21:55:26 +05302992 int port;
2993
Guilherme G. Piccoli025d0972017-05-28 23:07:01 -03002994 if (pci_channel_offline(adap->pdev))
2995 return;
2996
Hariprasad Shenai3be06792017-01-13 21:55:26 +05302997 /* Disable the SGE since ULDs are going to free resources that
2998 * could be exposed to the adapter. RDMA MWs for example...
2999 */
3000 t4_shutdown_adapter(adap);
3001 for_each_port(adap, port) {
3002 struct net_device *dev = adap->port[port];
3003
3004 /* If we get here in very early initialization the network
3005 * devices may not have been set up yet.
3006 */
3007 if (!dev)
3008 continue;
3009
3010 netif_tx_stop_all_queues(dev);
3011 netif_carrier_off(dev);
3012 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003013 dev_alert(adap->pdev_dev, "encountered fatal error, adapter stopped\n");
3014}
3015
3016static void setup_memwin(struct adapter *adap)
3017{
Hariprasad Shenaib562fc32015-05-20 17:53:45 +05303018 u32 nic_win_base = t4_get_util_window(adap);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003019
Hariprasad Shenaib562fc32015-05-20 17:53:45 +05303020 t4_setup_memwin(adap, nic_win_base, MEMWIN_NIC);
Vipul Pandya636f9d32012-09-26 02:39:39 +00003021}
3022
3023static void setup_memwin_rdma(struct adapter *adap)
3024{
Dimitris Michailidis1ae970e2010-08-02 13:19:19 +00003025 if (adap->vres.ocq.size) {
Hariprasad Shenai0abfd152014-06-27 19:23:48 +05303026 u32 start;
3027 unsigned int sz_kb;
Dimitris Michailidis1ae970e2010-08-02 13:19:19 +00003028
Hariprasad Shenai0abfd152014-06-27 19:23:48 +05303029 start = t4_read_pcie_cfg4(adap, PCI_BASE_ADDRESS_2);
3030 start &= PCI_BASE_ADDRESS_MEM_MASK;
3031 start += OCQ_WIN_OFFSET(adap->pdev, &adap->vres);
Dimitris Michailidis1ae970e2010-08-02 13:19:19 +00003032 sz_kb = roundup_pow_of_two(adap->vres.ocq.size) >> 10;
3033 t4_write_reg(adap,
Hariprasad Shenaif061de422015-01-05 16:30:44 +05303034 PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_BASE_WIN_A, 3),
3035 start | BIR_V(1) | WINDOW_V(ilog2(sz_kb)));
Dimitris Michailidis1ae970e2010-08-02 13:19:19 +00003036 t4_write_reg(adap,
Hariprasad Shenaif061de422015-01-05 16:30:44 +05303037 PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A, 3),
Dimitris Michailidis1ae970e2010-08-02 13:19:19 +00003038 adap->vres.ocq.start);
3039 t4_read_reg(adap,
Hariprasad Shenaif061de422015-01-05 16:30:44 +05303040 PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A, 3));
Dimitris Michailidis1ae970e2010-08-02 13:19:19 +00003041 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003042}
3043
Dimitris Michailidis02b5fb82010-06-18 10:05:28 +00003044static int adap_init1(struct adapter *adap, struct fw_caps_config_cmd *c)
3045{
3046 u32 v;
3047 int ret;
3048
3049 /* get device capabilities */
3050 memset(c, 0, sizeof(*c));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303051 c->op_to_write = htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
3052 FW_CMD_REQUEST_F | FW_CMD_READ_F);
Naresh Kumar Innace91a922012-11-15 22:41:17 +05303053 c->cfvalid_to_len16 = htonl(FW_LEN16(*c));
Hariprasad Shenaib2612722015-05-27 22:30:24 +05303054 ret = t4_wr_mbox(adap, adap->mbox, c, sizeof(*c), c);
Dimitris Michailidis02b5fb82010-06-18 10:05:28 +00003055 if (ret < 0)
3056 return ret;
3057
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303058 c->op_to_write = htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
3059 FW_CMD_REQUEST_F | FW_CMD_WRITE_F);
Hariprasad Shenaib2612722015-05-27 22:30:24 +05303060 ret = t4_wr_mbox(adap, adap->mbox, c, sizeof(*c), NULL);
Dimitris Michailidis02b5fb82010-06-18 10:05:28 +00003061 if (ret < 0)
3062 return ret;
3063
Hariprasad Shenaib2612722015-05-27 22:30:24 +05303064 ret = t4_config_glbl_rss(adap, adap->pf,
Dimitris Michailidis02b5fb82010-06-18 10:05:28 +00003065 FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL,
Hariprasad Shenaib2e1a3f2014-11-21 12:52:05 +05303066 FW_RSS_GLB_CONFIG_CMD_TNLMAPEN_F |
3067 FW_RSS_GLB_CONFIG_CMD_TNLALLLKP_F);
Dimitris Michailidis02b5fb82010-06-18 10:05:28 +00003068 if (ret < 0)
3069 return ret;
3070
Hariprasad Shenaib2612722015-05-27 22:30:24 +05303071 ret = t4_cfg_pfvf(adap, adap->mbox, adap->pf, 0, adap->sge.egr_sz, 64,
Hariprasad Shenai4b8e27a2015-03-26 10:04:25 +05303072 MAX_INGQ, 0, 0, 4, 0xf, 0xf, 16, FW_CMD_CAP_PF,
3073 FW_CMD_CAP_PF);
Dimitris Michailidis02b5fb82010-06-18 10:05:28 +00003074 if (ret < 0)
3075 return ret;
3076
3077 t4_sge_init(adap);
3078
Dimitris Michailidis02b5fb82010-06-18 10:05:28 +00003079 /* tweak some settings */
Hariprasad Shenai837e4a42015-01-05 16:30:46 +05303080 t4_write_reg(adap, TP_SHIFT_CNT_A, 0x64f8849);
Hariprasad Shenai0d804332015-01-05 16:30:47 +05303081 t4_write_reg(adap, ULP_RX_TDDP_PSZ_A, HPZ0_V(PAGE_SHIFT - 12));
Hariprasad Shenai837e4a42015-01-05 16:30:46 +05303082 t4_write_reg(adap, TP_PIO_ADDR_A, TP_INGRESS_CONFIG_A);
3083 v = t4_read_reg(adap, TP_PIO_DATA_A);
3084 t4_write_reg(adap, TP_PIO_DATA_A, v & ~CSUM_HAS_PSEUDO_HDR_F);
Dimitris Michailidis060e0c72010-08-02 13:19:21 +00003085
Vipul Pandyadca4fae2012-12-10 09:30:53 +00003086 /* first 4 Tx modulation queues point to consecutive Tx channels */
3087 adap->params.tp.tx_modq_map = 0xE4;
Hariprasad Shenai0d804332015-01-05 16:30:47 +05303088 t4_write_reg(adap, TP_TX_MOD_QUEUE_REQ_MAP_A,
3089 TX_MOD_QUEUE_REQ_MAP_V(adap->params.tp.tx_modq_map));
Vipul Pandyadca4fae2012-12-10 09:30:53 +00003090
3091 /* associate each Tx modulation queue with consecutive Tx channels */
3092 v = 0x84218421;
Hariprasad Shenai837e4a42015-01-05 16:30:46 +05303093 t4_write_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A,
Hariprasad Shenai0d804332015-01-05 16:30:47 +05303094 &v, 1, TP_TX_SCHED_HDR_A);
Hariprasad Shenai837e4a42015-01-05 16:30:46 +05303095 t4_write_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A,
Hariprasad Shenai0d804332015-01-05 16:30:47 +05303096 &v, 1, TP_TX_SCHED_FIFO_A);
Hariprasad Shenai837e4a42015-01-05 16:30:46 +05303097 t4_write_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A,
Hariprasad Shenai0d804332015-01-05 16:30:47 +05303098 &v, 1, TP_TX_SCHED_PCMD_A);
Vipul Pandyadca4fae2012-12-10 09:30:53 +00003099
3100#define T4_TX_MODQ_10G_WEIGHT_DEFAULT 16 /* in KB units */
3101 if (is_offload(adap)) {
Hariprasad Shenai0d804332015-01-05 16:30:47 +05303102 t4_write_reg(adap, TP_TX_MOD_QUEUE_WEIGHT0_A,
3103 TX_MODQ_WEIGHT0_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
3104 TX_MODQ_WEIGHT1_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
3105 TX_MODQ_WEIGHT2_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
3106 TX_MODQ_WEIGHT3_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT));
3107 t4_write_reg(adap, TP_TX_MOD_CHANNEL_WEIGHT_A,
3108 TX_MODQ_WEIGHT0_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
3109 TX_MODQ_WEIGHT1_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
3110 TX_MODQ_WEIGHT2_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
3111 TX_MODQ_WEIGHT3_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT));
Vipul Pandyadca4fae2012-12-10 09:30:53 +00003112 }
3113
Dimitris Michailidis060e0c72010-08-02 13:19:21 +00003114 /* get basic stuff going */
Hariprasad Shenaib2612722015-05-27 22:30:24 +05303115 return t4_early_init(adap, adap->pf);
Dimitris Michailidis02b5fb82010-06-18 10:05:28 +00003116}
3117
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003118/*
3119 * Max # of ATIDs. The absolute HW max is 16K but we keep it lower.
3120 */
3121#define MAX_ATIDS 8192U
3122
3123/*
3124 * Phase 0 of initialization: contact FW, obtain config, perform basic init.
Vipul Pandya636f9d32012-09-26 02:39:39 +00003125 *
3126 * If the firmware we're dealing with has Configuration File support, then
3127 * we use that to perform all configuration
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003128 */
Vipul Pandya636f9d32012-09-26 02:39:39 +00003129
3130/*
3131 * Tweak configuration based on module parameters, etc. Most of these have
3132 * defaults assigned to them by Firmware Configuration Files (if we're using
3133 * them) but need to be explicitly set if we're using hard-coded
3134 * initialization. But even in the case of using Firmware Configuration
3135 * Files, we'd like to expose the ability to change these via module
3136 * parameters so these are essentially common tweaks/settings for
3137 * Configuration Files and hard-coded initialization ...
3138 */
3139static int adap_init0_tweaks(struct adapter *adapter)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003140{
Vipul Pandya636f9d32012-09-26 02:39:39 +00003141 /*
3142 * Fix up various Host-Dependent Parameters like Page Size, Cache
3143 * Line Size, etc. The firmware default is for a 4KB Page Size and
3144 * 64B Cache Line Size ...
3145 */
3146 t4_fixup_host_params(adapter, PAGE_SIZE, L1_CACHE_BYTES);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003147
Vipul Pandya636f9d32012-09-26 02:39:39 +00003148 /*
3149 * Process module parameters which affect early initialization.
3150 */
3151 if (rx_dma_offset != 2 && rx_dma_offset != 0) {
3152 dev_err(&adapter->pdev->dev,
3153 "Ignoring illegal rx_dma_offset=%d, using 2\n",
3154 rx_dma_offset);
3155 rx_dma_offset = 2;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003156 }
Hariprasad Shenaif612b812015-01-05 16:30:43 +05303157 t4_set_reg_field(adapter, SGE_CONTROL_A,
3158 PKTSHIFT_V(PKTSHIFT_M),
3159 PKTSHIFT_V(rx_dma_offset));
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003160
Vipul Pandya636f9d32012-09-26 02:39:39 +00003161 /*
3162 * Don't include the "IP Pseudo Header" in CPL_RX_PKT checksums: Linux
3163 * adds the pseudo header itself.
3164 */
Hariprasad Shenai837e4a42015-01-05 16:30:46 +05303165 t4_tp_wr_bits_indirect(adapter, TP_INGRESS_CONFIG_A,
3166 CSUM_HAS_PSEUDO_HDR_F, 0);
Vipul Pandya636f9d32012-09-26 02:39:39 +00003167
3168 return 0;
3169}
3170
Hariprasad Shenai01b69612015-05-22 21:58:21 +05303171/* 10Gb/s-BT PHY Support. chip-external 10Gb/s-BT PHYs are complex chips
3172 * unto themselves and they contain their own firmware to perform their
3173 * tasks ...
3174 */
3175static int phy_aq1202_version(const u8 *phy_fw_data,
3176 size_t phy_fw_size)
3177{
3178 int offset;
3179
3180 /* At offset 0x8 you're looking for the primary image's
3181 * starting offset which is 3 Bytes wide
3182 *
3183 * At offset 0xa of the primary image, you look for the offset
3184 * of the DRAM segment which is 3 Bytes wide.
3185 *
3186 * The FW version is at offset 0x27e of the DRAM and is 2 Bytes
3187 * wide
3188 */
3189 #define be16(__p) (((__p)[0] << 8) | (__p)[1])
3190 #define le16(__p) ((__p)[0] | ((__p)[1] << 8))
3191 #define le24(__p) (le16(__p) | ((__p)[2] << 16))
3192
3193 offset = le24(phy_fw_data + 0x8) << 12;
3194 offset = le24(phy_fw_data + offset + 0xa);
3195 return be16(phy_fw_data + offset + 0x27e);
3196
3197 #undef be16
3198 #undef le16
3199 #undef le24
3200}
3201
3202static struct info_10gbt_phy_fw {
3203 unsigned int phy_fw_id; /* PCI Device ID */
3204 char *phy_fw_file; /* /lib/firmware/ PHY Firmware file */
3205 int (*phy_fw_version)(const u8 *phy_fw_data, size_t phy_fw_size);
3206 int phy_flash; /* Has FLASH for PHY Firmware */
3207} phy_info_array[] = {
3208 {
3209 PHY_AQ1202_DEVICEID,
3210 PHY_AQ1202_FIRMWARE,
3211 phy_aq1202_version,
3212 1,
3213 },
3214 {
3215 PHY_BCM84834_DEVICEID,
3216 PHY_BCM84834_FIRMWARE,
3217 NULL,
3218 0,
3219 },
3220 { 0, NULL, NULL },
3221};
3222
3223static struct info_10gbt_phy_fw *find_phy_info(int devid)
3224{
3225 int i;
3226
3227 for (i = 0; i < ARRAY_SIZE(phy_info_array); i++) {
3228 if (phy_info_array[i].phy_fw_id == devid)
3229 return &phy_info_array[i];
3230 }
3231 return NULL;
3232}
3233
3234/* Handle updating of chip-external 10Gb/s-BT PHY firmware. This needs to
3235 * happen after the FW_RESET_CMD but before the FW_INITIALIZE_CMD. On error
3236 * we return a negative error number. If we transfer new firmware we return 1
3237 * (from t4_load_phy_fw()). If we don't do anything we return 0.
3238 */
3239static int adap_init0_phy(struct adapter *adap)
3240{
3241 const struct firmware *phyf;
3242 int ret;
3243 struct info_10gbt_phy_fw *phy_info;
3244
3245 /* Use the device ID to determine which PHY file to flash.
3246 */
3247 phy_info = find_phy_info(adap->pdev->device);
3248 if (!phy_info) {
3249 dev_warn(adap->pdev_dev,
3250 "No PHY Firmware file found for this PHY\n");
3251 return -EOPNOTSUPP;
3252 }
3253
3254 /* If we have a T4 PHY firmware file under /lib/firmware/cxgb4/, then
3255 * use that. The adapter firmware provides us with a memory buffer
3256 * where we can load a PHY firmware file from the host if we want to
3257 * override the PHY firmware File in flash.
3258 */
3259 ret = request_firmware_direct(&phyf, phy_info->phy_fw_file,
3260 adap->pdev_dev);
3261 if (ret < 0) {
3262 /* For adapters without FLASH attached to PHY for their
3263 * firmware, it's obviously a fatal error if we can't get the
3264 * firmware to the adapter. For adapters with PHY firmware
3265 * FLASH storage, it's worth a warning if we can't find the
3266 * PHY Firmware but we'll neuter the error ...
3267 */
3268 dev_err(adap->pdev_dev, "unable to find PHY Firmware image "
3269 "/lib/firmware/%s, error %d\n",
3270 phy_info->phy_fw_file, -ret);
3271 if (phy_info->phy_flash) {
3272 int cur_phy_fw_ver = 0;
3273
3274 t4_phy_fw_ver(adap, &cur_phy_fw_ver);
3275 dev_warn(adap->pdev_dev, "continuing with, on-adapter "
3276 "FLASH copy, version %#x\n", cur_phy_fw_ver);
3277 ret = 0;
3278 }
3279
3280 return ret;
3281 }
3282
3283 /* Load PHY Firmware onto adapter.
3284 */
3285 ret = t4_load_phy_fw(adap, MEMWIN_NIC, &adap->win0_lock,
3286 phy_info->phy_fw_version,
3287 (u8 *)phyf->data, phyf->size);
3288 if (ret < 0)
3289 dev_err(adap->pdev_dev, "PHY Firmware transfer error %d\n",
3290 -ret);
3291 else if (ret > 0) {
3292 int new_phy_fw_ver = 0;
3293
3294 if (phy_info->phy_fw_version)
3295 new_phy_fw_ver = phy_info->phy_fw_version(phyf->data,
3296 phyf->size);
3297 dev_info(adap->pdev_dev, "Successfully transferred PHY "
3298 "Firmware /lib/firmware/%s, version %#x\n",
3299 phy_info->phy_fw_file, new_phy_fw_ver);
3300 }
3301
3302 release_firmware(phyf);
3303
3304 return ret;
3305}
3306
Vipul Pandya636f9d32012-09-26 02:39:39 +00003307/*
3308 * Attempt to initialize the adapter via a Firmware Configuration File.
3309 */
3310static int adap_init0_config(struct adapter *adapter, int reset)
3311{
3312 struct fw_caps_config_cmd caps_cmd;
3313 const struct firmware *cf;
3314 unsigned long mtype = 0, maddr = 0;
3315 u32 finiver, finicsum, cfcsum;
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303316 int ret;
3317 int config_issued = 0;
Santosh Rastapur0a57a532013-03-14 05:08:49 +00003318 char *fw_config_file, fw_config_file_path[256];
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303319 char *config_name = NULL;
Vipul Pandya636f9d32012-09-26 02:39:39 +00003320
3321 /*
3322 * Reset device if necessary.
3323 */
3324 if (reset) {
3325 ret = t4_fw_reset(adapter, adapter->mbox,
Hariprasad Shenai0d804332015-01-05 16:30:47 +05303326 PIORSTMODE_F | PIORST_F);
Vipul Pandya636f9d32012-09-26 02:39:39 +00003327 if (ret < 0)
3328 goto bye;
3329 }
3330
Hariprasad Shenai01b69612015-05-22 21:58:21 +05303331 /* If this is a 10Gb/s-BT adapter make sure the chip-external
3332 * 10Gb/s-BT PHYs have up-to-date firmware. Note that this step needs
3333 * to be performed after any global adapter RESET above since some
3334 * PHYs only have local RAM copies of the PHY firmware.
3335 */
3336 if (is_10gbt_device(adapter->pdev->device)) {
3337 ret = adap_init0_phy(adapter);
3338 if (ret < 0)
3339 goto bye;
3340 }
Vipul Pandya636f9d32012-09-26 02:39:39 +00003341 /*
3342 * If we have a T4 configuration file under /lib/firmware/cxgb4/,
3343 * then use that. Otherwise, use the configuration file stored
3344 * in the adapter flash ...
3345 */
Hariprasad Shenaid14807d2013-12-03 17:05:56 +05303346 switch (CHELSIO_CHIP_VERSION(adapter->params.chip)) {
Santosh Rastapur0a57a532013-03-14 05:08:49 +00003347 case CHELSIO_T4:
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303348 fw_config_file = FW4_CFNAME;
Santosh Rastapur0a57a532013-03-14 05:08:49 +00003349 break;
3350 case CHELSIO_T5:
3351 fw_config_file = FW5_CFNAME;
3352 break;
Hariprasad Shenai3ccc6cf2015-06-02 13:59:39 +05303353 case CHELSIO_T6:
3354 fw_config_file = FW6_CFNAME;
3355 break;
Santosh Rastapur0a57a532013-03-14 05:08:49 +00003356 default:
3357 dev_err(adapter->pdev_dev, "Device %d is not supported\n",
3358 adapter->pdev->device);
3359 ret = -EINVAL;
3360 goto bye;
3361 }
3362
3363 ret = request_firmware(&cf, fw_config_file, adapter->pdev_dev);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003364 if (ret < 0) {
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303365 config_name = "On FLASH";
Vipul Pandya636f9d32012-09-26 02:39:39 +00003366 mtype = FW_MEMTYPE_CF_FLASH;
3367 maddr = t4_flash_cfg_addr(adapter);
3368 } else {
3369 u32 params[7], val[7];
3370
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303371 sprintf(fw_config_file_path,
3372 "/lib/firmware/%s", fw_config_file);
3373 config_name = fw_config_file_path;
3374
Vipul Pandya636f9d32012-09-26 02:39:39 +00003375 if (cf->size >= FLASH_CFG_MAX_SIZE)
3376 ret = -ENOMEM;
3377 else {
Hariprasad Shenai51678652014-11-21 12:52:02 +05303378 params[0] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
3379 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_CF));
Vipul Pandya636f9d32012-09-26 02:39:39 +00003380 ret = t4_query_params(adapter, adapter->mbox,
Hariprasad Shenaib2612722015-05-27 22:30:24 +05303381 adapter->pf, 0, 1, params, val);
Vipul Pandya636f9d32012-09-26 02:39:39 +00003382 if (ret == 0) {
3383 /*
Hariprasad Shenaifc5ab022014-06-27 19:23:49 +05303384 * For t4_memory_rw() below addresses and
Vipul Pandya636f9d32012-09-26 02:39:39 +00003385 * sizes have to be in terms of multiples of 4
3386 * bytes. So, if the Configuration File isn't
3387 * a multiple of 4 bytes in length we'll have
3388 * to write that out separately since we can't
3389 * guarantee that the bytes following the
3390 * residual byte in the buffer returned by
3391 * request_firmware() are zeroed out ...
3392 */
3393 size_t resid = cf->size & 0x3;
3394 size_t size = cf->size & ~0x3;
3395 __be32 *data = (__be32 *)cf->data;
3396
Hariprasad Shenai51678652014-11-21 12:52:02 +05303397 mtype = FW_PARAMS_PARAM_Y_G(val[0]);
3398 maddr = FW_PARAMS_PARAM_Z_G(val[0]) << 16;
Vipul Pandya636f9d32012-09-26 02:39:39 +00003399
Hariprasad Shenaifc5ab022014-06-27 19:23:49 +05303400 spin_lock(&adapter->win0_lock);
3401 ret = t4_memory_rw(adapter, 0, mtype, maddr,
3402 size, data, T4_MEMORY_WRITE);
Vipul Pandya636f9d32012-09-26 02:39:39 +00003403 if (ret == 0 && resid != 0) {
3404 union {
3405 __be32 word;
3406 char buf[4];
3407 } last;
3408 int i;
3409
3410 last.word = data[size >> 2];
3411 for (i = resid; i < 4; i++)
3412 last.buf[i] = 0;
Hariprasad Shenaifc5ab022014-06-27 19:23:49 +05303413 ret = t4_memory_rw(adapter, 0, mtype,
3414 maddr + size,
3415 4, &last.word,
3416 T4_MEMORY_WRITE);
Vipul Pandya636f9d32012-09-26 02:39:39 +00003417 }
Hariprasad Shenaifc5ab022014-06-27 19:23:49 +05303418 spin_unlock(&adapter->win0_lock);
Vipul Pandya636f9d32012-09-26 02:39:39 +00003419 }
3420 }
3421
3422 release_firmware(cf);
3423 if (ret)
3424 goto bye;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003425 }
3426
Vipul Pandya636f9d32012-09-26 02:39:39 +00003427 /*
3428 * Issue a Capability Configuration command to the firmware to get it
3429 * to parse the Configuration File. We don't use t4_fw_config_file()
3430 * because we want the ability to modify various features after we've
3431 * processed the configuration file ...
3432 */
3433 memset(&caps_cmd, 0, sizeof(caps_cmd));
3434 caps_cmd.op_to_write =
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303435 htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
3436 FW_CMD_REQUEST_F |
3437 FW_CMD_READ_F);
Naresh Kumar Innace91a922012-11-15 22:41:17 +05303438 caps_cmd.cfvalid_to_len16 =
Hariprasad Shenai51678652014-11-21 12:52:02 +05303439 htonl(FW_CAPS_CONFIG_CMD_CFVALID_F |
3440 FW_CAPS_CONFIG_CMD_MEMTYPE_CF_V(mtype) |
3441 FW_CAPS_CONFIG_CMD_MEMADDR64K_CF_V(maddr >> 16) |
Vipul Pandya636f9d32012-09-26 02:39:39 +00003442 FW_LEN16(caps_cmd));
3443 ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd, sizeof(caps_cmd),
3444 &caps_cmd);
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303445
3446 /* If the CAPS_CONFIG failed with an ENOENT (for a Firmware
3447 * Configuration File in FLASH), our last gasp effort is to use the
3448 * Firmware Configuration File which is embedded in the firmware. A
3449 * very few early versions of the firmware didn't have one embedded
3450 * but we can ignore those.
3451 */
3452 if (ret == -ENOENT) {
3453 memset(&caps_cmd, 0, sizeof(caps_cmd));
3454 caps_cmd.op_to_write =
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303455 htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
3456 FW_CMD_REQUEST_F |
3457 FW_CMD_READ_F);
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303458 caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd));
3459 ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd,
3460 sizeof(caps_cmd), &caps_cmd);
3461 config_name = "Firmware Default";
3462 }
3463
3464 config_issued = 1;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003465 if (ret < 0)
3466 goto bye;
3467
Vipul Pandya636f9d32012-09-26 02:39:39 +00003468 finiver = ntohl(caps_cmd.finiver);
3469 finicsum = ntohl(caps_cmd.finicsum);
3470 cfcsum = ntohl(caps_cmd.cfcsum);
3471 if (finicsum != cfcsum)
3472 dev_warn(adapter->pdev_dev, "Configuration File checksum "\
3473 "mismatch: [fini] csum=%#x, computed csum=%#x\n",
3474 finicsum, cfcsum);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003475
Vipul Pandya636f9d32012-09-26 02:39:39 +00003476 /*
Vipul Pandya636f9d32012-09-26 02:39:39 +00003477 * And now tell the firmware to use the configuration we just loaded.
3478 */
3479 caps_cmd.op_to_write =
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303480 htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
3481 FW_CMD_REQUEST_F |
3482 FW_CMD_WRITE_F);
Naresh Kumar Innace91a922012-11-15 22:41:17 +05303483 caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd));
Vipul Pandya636f9d32012-09-26 02:39:39 +00003484 ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd, sizeof(caps_cmd),
3485 NULL);
Dimitris Michailidisa0881ca2010-06-18 10:05:34 +00003486 if (ret < 0)
3487 goto bye;
3488
Vipul Pandya636f9d32012-09-26 02:39:39 +00003489 /*
3490 * Tweak configuration based on system architecture, module
3491 * parameters, etc.
3492 */
3493 ret = adap_init0_tweaks(adapter);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003494 if (ret < 0)
3495 goto bye;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003496
Vipul Pandya636f9d32012-09-26 02:39:39 +00003497 /*
3498 * And finally tell the firmware to initialize itself using the
3499 * parameters from the Configuration File.
3500 */
3501 ret = t4_fw_initialize(adapter, adapter->mbox);
3502 if (ret < 0)
3503 goto bye;
3504
Hariprasad Shenai06640312015-01-13 15:19:25 +05303505 /* Emit Firmware Configuration File information and return
3506 * successfully.
Vipul Pandya636f9d32012-09-26 02:39:39 +00003507 */
Vipul Pandya636f9d32012-09-26 02:39:39 +00003508 dev_info(adapter->pdev_dev, "Successfully configured using Firmware "\
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303509 "Configuration File \"%s\", version %#x, computed checksum %#x\n",
3510 config_name, finiver, cfcsum);
Vipul Pandya636f9d32012-09-26 02:39:39 +00003511 return 0;
3512
3513 /*
3514 * Something bad happened. Return the error ... (If the "error"
3515 * is that there's no Configuration File on the adapter we don't
3516 * want to issue a warning since this is fairly common.)
3517 */
3518bye:
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303519 if (config_issued && ret != -ENOENT)
3520 dev_warn(adapter->pdev_dev, "\"%s\" configuration file error %d\n",
3521 config_name, -ret);
Vipul Pandya636f9d32012-09-26 02:39:39 +00003522 return ret;
3523}
3524
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303525static struct fw_info fw_info_array[] = {
3526 {
3527 .chip = CHELSIO_T4,
3528 .fs_name = FW4_CFNAME,
3529 .fw_mod_name = FW4_FNAME,
3530 .fw_hdr = {
3531 .chip = FW_HDR_CHIP_T4,
3532 .fw_ver = __cpu_to_be32(FW_VERSION(T4)),
3533 .intfver_nic = FW_INTFVER(T4, NIC),
3534 .intfver_vnic = FW_INTFVER(T4, VNIC),
3535 .intfver_ri = FW_INTFVER(T4, RI),
3536 .intfver_iscsi = FW_INTFVER(T4, ISCSI),
3537 .intfver_fcoe = FW_INTFVER(T4, FCOE),
3538 },
3539 }, {
3540 .chip = CHELSIO_T5,
3541 .fs_name = FW5_CFNAME,
3542 .fw_mod_name = FW5_FNAME,
3543 .fw_hdr = {
3544 .chip = FW_HDR_CHIP_T5,
3545 .fw_ver = __cpu_to_be32(FW_VERSION(T5)),
3546 .intfver_nic = FW_INTFVER(T5, NIC),
3547 .intfver_vnic = FW_INTFVER(T5, VNIC),
3548 .intfver_ri = FW_INTFVER(T5, RI),
3549 .intfver_iscsi = FW_INTFVER(T5, ISCSI),
3550 .intfver_fcoe = FW_INTFVER(T5, FCOE),
3551 },
Hariprasad Shenai3ccc6cf2015-06-02 13:59:39 +05303552 }, {
3553 .chip = CHELSIO_T6,
3554 .fs_name = FW6_CFNAME,
3555 .fw_mod_name = FW6_FNAME,
3556 .fw_hdr = {
3557 .chip = FW_HDR_CHIP_T6,
3558 .fw_ver = __cpu_to_be32(FW_VERSION(T6)),
3559 .intfver_nic = FW_INTFVER(T6, NIC),
3560 .intfver_vnic = FW_INTFVER(T6, VNIC),
3561 .intfver_ofld = FW_INTFVER(T6, OFLD),
3562 .intfver_ri = FW_INTFVER(T6, RI),
3563 .intfver_iscsipdu = FW_INTFVER(T6, ISCSIPDU),
3564 .intfver_iscsi = FW_INTFVER(T6, ISCSI),
3565 .intfver_fcoepdu = FW_INTFVER(T6, FCOEPDU),
3566 .intfver_fcoe = FW_INTFVER(T6, FCOE),
3567 },
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303568 }
Hariprasad Shenai3ccc6cf2015-06-02 13:59:39 +05303569
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303570};
3571
3572static struct fw_info *find_fw_info(int chip)
3573{
3574 int i;
3575
3576 for (i = 0; i < ARRAY_SIZE(fw_info_array); i++) {
3577 if (fw_info_array[i].chip == chip)
3578 return &fw_info_array[i];
3579 }
3580 return NULL;
3581}
3582
Vipul Pandya13ee15d2012-09-26 02:39:40 +00003583/*
Vipul Pandya636f9d32012-09-26 02:39:39 +00003584 * Phase 0 of initialization: contact FW, obtain config, perform basic init.
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003585 */
3586static int adap_init0(struct adapter *adap)
3587{
3588 int ret;
3589 u32 v, port_vec;
3590 enum dev_state state;
3591 u32 params[7], val[7];
Vipul Pandya9a4da2c2012-10-19 02:09:53 +00003592 struct fw_caps_config_cmd caps_cmd;
Kumar Sanghvidcf7b6f2013-12-18 16:38:23 +05303593 int reset = 1;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003594
Hariprasad Shenaiae469b62015-04-01 21:41:16 +05303595 /* Grab Firmware Device Log parameters as early as possible so we have
3596 * access to it for debugging, etc.
3597 */
3598 ret = t4_init_devlog_params(adap);
3599 if (ret < 0)
3600 return ret;
3601
Hariprasad Shenai666224d2014-12-11 11:11:43 +05303602 /* Contact FW, advertising Master capability */
Hariprasad Shenaic5a8c0f2016-06-14 14:39:30 +05303603 ret = t4_fw_hello(adap, adap->mbox, adap->mbox,
3604 is_kdump_kernel() ? MASTER_MUST : MASTER_MAY, &state);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003605 if (ret < 0) {
3606 dev_err(adap->pdev_dev, "could not connect to FW, error %d\n",
3607 ret);
3608 return ret;
3609 }
Vipul Pandya636f9d32012-09-26 02:39:39 +00003610 if (ret == adap->mbox)
3611 adap->flags |= MASTER_PF;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003612
Vipul Pandya636f9d32012-09-26 02:39:39 +00003613 /*
3614 * If we're the Master PF Driver and the device is uninitialized,
3615 * then let's consider upgrading the firmware ... (We always want
3616 * to check the firmware version number in order to A. get it for
3617 * later reporting and B. to warn if the currently loaded firmware
3618 * is excessively mismatched relative to the driver.)
3619 */
Hariprasad Shenai0de72732016-04-26 20:10:22 +05303620
Ganesh Goudar760446f2017-07-20 18:28:48 +05303621 t4_get_version_info(adap);
Hariprasad Shenaia69265e2015-08-28 11:17:12 +05303622 ret = t4_check_fw_version(adap);
3623 /* If firmware is too old (not supported by driver) force an update. */
Hariprasad Shenai21d11bd2015-10-08 10:08:23 +05303624 if (ret)
Hariprasad Shenaia69265e2015-08-28 11:17:12 +05303625 state = DEV_STATE_UNINIT;
Vipul Pandya636f9d32012-09-26 02:39:39 +00003626 if ((adap->flags & MASTER_PF) && state != DEV_STATE_INIT) {
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303627 struct fw_info *fw_info;
3628 struct fw_hdr *card_fw;
3629 const struct firmware *fw;
3630 const u8 *fw_data = NULL;
3631 unsigned int fw_size = 0;
3632
3633 /* This is the firmware whose headers the driver was compiled
3634 * against
3635 */
3636 fw_info = find_fw_info(CHELSIO_CHIP_VERSION(adap->params.chip));
3637 if (fw_info == NULL) {
3638 dev_err(adap->pdev_dev,
3639 "unable to get firmware info for chip %d.\n",
3640 CHELSIO_CHIP_VERSION(adap->params.chip));
3641 return -EINVAL;
Vipul Pandya636f9d32012-09-26 02:39:39 +00003642 }
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303643
3644 /* allocate memory to read the header of the firmware on the
3645 * card
3646 */
Michal Hocko752ade62017-05-08 15:57:27 -07003647 card_fw = kvzalloc(sizeof(*card_fw), GFP_KERNEL);
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303648
3649 /* Get FW from from /lib/firmware/ */
3650 ret = request_firmware(&fw, fw_info->fw_mod_name,
3651 adap->pdev_dev);
3652 if (ret < 0) {
3653 dev_err(adap->pdev_dev,
3654 "unable to load firmware image %s, error %d\n",
3655 fw_info->fw_mod_name, ret);
3656 } else {
3657 fw_data = fw->data;
3658 fw_size = fw->size;
3659 }
3660
3661 /* upgrade FW logic */
3662 ret = t4_prep_fw(adap, fw_info, fw_data, fw_size, card_fw,
3663 state, &reset);
3664
3665 /* Cleaning up */
Markus Elfring0b5b6be2015-02-04 11:28:43 +01003666 release_firmware(fw);
Michal Hocko752ade62017-05-08 15:57:27 -07003667 kvfree(card_fw);
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303668
Vipul Pandya636f9d32012-09-26 02:39:39 +00003669 if (ret < 0)
Hariprasad Shenai16e47622013-12-03 17:05:58 +05303670 goto bye;
Vipul Pandya636f9d32012-09-26 02:39:39 +00003671 }
3672
3673 /*
3674 * Grab VPD parameters. This should be done after we establish a
3675 * connection to the firmware since some of the VPD parameters
3676 * (notably the Core Clock frequency) are retrieved via requests to
3677 * the firmware. On the other hand, we need these fairly early on
3678 * so we do this right after getting ahold of the firmware.
3679 */
Hariprasad Shenai098ef6c2015-06-05 14:24:50 +05303680 ret = t4_get_vpd_params(adap, &adap->params.vpd);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003681 if (ret < 0)
3682 goto bye;
3683
Vipul Pandya636f9d32012-09-26 02:39:39 +00003684 /*
Vipul Pandya13ee15d2012-09-26 02:39:40 +00003685 * Find out what ports are available to us. Note that we need to do
3686 * this before calling adap_init0_no_config() since it needs nports
3687 * and portvec ...
Vipul Pandya636f9d32012-09-26 02:39:39 +00003688 */
3689 v =
Hariprasad Shenai51678652014-11-21 12:52:02 +05303690 FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
3691 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_PORTVEC);
Hariprasad Shenaib2612722015-05-27 22:30:24 +05303692 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1, &v, &port_vec);
Vipul Pandya636f9d32012-09-26 02:39:39 +00003693 if (ret < 0)
3694 goto bye;
3695
3696 adap->params.nports = hweight32(port_vec);
3697 adap->params.portvec = port_vec;
3698
Hariprasad Shenai06640312015-01-13 15:19:25 +05303699 /* If the firmware is initialized already, emit a simply note to that
3700 * effect. Otherwise, it's time to try initializing the adapter.
Vipul Pandya636f9d32012-09-26 02:39:39 +00003701 */
3702 if (state == DEV_STATE_INIT) {
3703 dev_info(adap->pdev_dev, "Coming up as %s: "\
3704 "Adapter already initialized\n",
3705 adap->flags & MASTER_PF ? "MASTER" : "SLAVE");
Vipul Pandya636f9d32012-09-26 02:39:39 +00003706 } else {
3707 dev_info(adap->pdev_dev, "Coming up as MASTER: "\
3708 "Initializing adapter\n");
Hariprasad Shenai06640312015-01-13 15:19:25 +05303709
3710 /* Find out whether we're dealing with a version of the
3711 * firmware which has configuration file support.
Vipul Pandya636f9d32012-09-26 02:39:39 +00003712 */
Hariprasad Shenai06640312015-01-13 15:19:25 +05303713 params[0] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
3714 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_CF));
Hariprasad Shenaib2612722015-05-27 22:30:24 +05303715 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1,
Hariprasad Shenai06640312015-01-13 15:19:25 +05303716 params, val);
Vipul Pandya636f9d32012-09-26 02:39:39 +00003717
Hariprasad Shenai06640312015-01-13 15:19:25 +05303718 /* If the firmware doesn't support Configuration Files,
3719 * return an error.
3720 */
3721 if (ret < 0) {
3722 dev_err(adap->pdev_dev, "firmware doesn't support "
3723 "Firmware Configuration Files\n");
3724 goto bye;
3725 }
Vipul Pandya13ee15d2012-09-26 02:39:40 +00003726
Hariprasad Shenai06640312015-01-13 15:19:25 +05303727 /* The firmware provides us with a memory buffer where we can
3728 * load a Configuration File from the host if we want to
3729 * override the Configuration File in flash.
3730 */
3731 ret = adap_init0_config(adap, reset);
3732 if (ret == -ENOENT) {
3733 dev_err(adap->pdev_dev, "no Configuration File "
3734 "present on adapter.\n");
3735 goto bye;
Vipul Pandya636f9d32012-09-26 02:39:39 +00003736 }
3737 if (ret < 0) {
Hariprasad Shenai06640312015-01-13 15:19:25 +05303738 dev_err(adap->pdev_dev, "could not initialize "
3739 "adapter, error %d\n", -ret);
Vipul Pandya636f9d32012-09-26 02:39:39 +00003740 goto bye;
3741 }
3742 }
3743
Hariprasad Shenai06640312015-01-13 15:19:25 +05303744 /* Give the SGE code a chance to pull in anything that it needs ...
3745 * Note that this must be called after we retrieve our VPD parameters
3746 * in order to know how to convert core ticks to seconds, etc.
Vipul Pandya636f9d32012-09-26 02:39:39 +00003747 */
Hariprasad Shenai06640312015-01-13 15:19:25 +05303748 ret = t4_sge_init(adap);
3749 if (ret < 0)
3750 goto bye;
Vipul Pandya636f9d32012-09-26 02:39:39 +00003751
Vipul Pandya9a4da2c2012-10-19 02:09:53 +00003752 if (is_bypass_device(adap->pdev->device))
3753 adap->params.bypass = 1;
3754
Vipul Pandya636f9d32012-09-26 02:39:39 +00003755 /*
3756 * Grab some of our basic fundamental operating parameters.
3757 */
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003758#define FW_PARAM_DEV(param) \
Hariprasad Shenai51678652014-11-21 12:52:02 +05303759 (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) | \
3760 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_##param))
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003761
3762#define FW_PARAM_PFVF(param) \
Hariprasad Shenai51678652014-11-21 12:52:02 +05303763 FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_PFVF) | \
3764 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_PFVF_##param)| \
3765 FW_PARAMS_PARAM_Y_V(0) | \
3766 FW_PARAMS_PARAM_Z_V(0)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003767
Vipul Pandya636f9d32012-09-26 02:39:39 +00003768 params[0] = FW_PARAM_PFVF(EQ_START);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003769 params[1] = FW_PARAM_PFVF(L2T_START);
3770 params[2] = FW_PARAM_PFVF(L2T_END);
3771 params[3] = FW_PARAM_PFVF(FILTER_START);
3772 params[4] = FW_PARAM_PFVF(FILTER_END);
3773 params[5] = FW_PARAM_PFVF(IQFLINT_START);
Hariprasad Shenaib2612722015-05-27 22:30:24 +05303774 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 6, params, val);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003775 if (ret < 0)
3776 goto bye;
Vipul Pandya636f9d32012-09-26 02:39:39 +00003777 adap->sge.egr_start = val[0];
3778 adap->l2t_start = val[1];
3779 adap->l2t_end = val[2];
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003780 adap->tids.ftid_base = val[3];
3781 adap->tids.nftids = val[4] - val[3] + 1;
3782 adap->sge.ingr_start = val[5];
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003783
Hariprasad Shenai4b8e27a2015-03-26 10:04:25 +05303784 /* qids (ingress/egress) returned from firmware can be anywhere
3785 * in the range from EQ(IQFLINT)_START to EQ(IQFLINT)_END.
3786 * Hence driver needs to allocate memory for this range to
3787 * store the queue info. Get the highest IQFLINT/EQ index returned
3788 * in FW_EQ_*_CMD.alloc command.
3789 */
3790 params[0] = FW_PARAM_PFVF(EQ_END);
3791 params[1] = FW_PARAM_PFVF(IQFLINT_END);
Hariprasad Shenaib2612722015-05-27 22:30:24 +05303792 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params, val);
Hariprasad Shenai4b8e27a2015-03-26 10:04:25 +05303793 if (ret < 0)
3794 goto bye;
3795 adap->sge.egr_sz = val[0] - adap->sge.egr_start + 1;
3796 adap->sge.ingr_sz = val[1] - adap->sge.ingr_start + 1;
3797
3798 adap->sge.egr_map = kcalloc(adap->sge.egr_sz,
3799 sizeof(*adap->sge.egr_map), GFP_KERNEL);
3800 if (!adap->sge.egr_map) {
3801 ret = -ENOMEM;
3802 goto bye;
3803 }
3804
3805 adap->sge.ingr_map = kcalloc(adap->sge.ingr_sz,
3806 sizeof(*adap->sge.ingr_map), GFP_KERNEL);
3807 if (!adap->sge.ingr_map) {
3808 ret = -ENOMEM;
3809 goto bye;
3810 }
3811
3812 /* Allocate the memory for the vaious egress queue bitmaps
Hariprasad Shenai5b377d12015-05-27 22:30:23 +05303813 * ie starving_fl, txq_maperr and blocked_fl.
Hariprasad Shenai4b8e27a2015-03-26 10:04:25 +05303814 */
3815 adap->sge.starving_fl = kcalloc(BITS_TO_LONGS(adap->sge.egr_sz),
3816 sizeof(long), GFP_KERNEL);
3817 if (!adap->sge.starving_fl) {
3818 ret = -ENOMEM;
3819 goto bye;
3820 }
3821
3822 adap->sge.txq_maperr = kcalloc(BITS_TO_LONGS(adap->sge.egr_sz),
3823 sizeof(long), GFP_KERNEL);
3824 if (!adap->sge.txq_maperr) {
3825 ret = -ENOMEM;
3826 goto bye;
3827 }
3828
Hariprasad Shenai5b377d12015-05-27 22:30:23 +05303829#ifdef CONFIG_DEBUG_FS
3830 adap->sge.blocked_fl = kcalloc(BITS_TO_LONGS(adap->sge.egr_sz),
3831 sizeof(long), GFP_KERNEL);
3832 if (!adap->sge.blocked_fl) {
3833 ret = -ENOMEM;
3834 goto bye;
3835 }
3836#endif
3837
Anish Bhattb5a02f52015-01-14 15:17:34 -08003838 params[0] = FW_PARAM_PFVF(CLIP_START);
3839 params[1] = FW_PARAM_PFVF(CLIP_END);
Hariprasad Shenaib2612722015-05-27 22:30:24 +05303840 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params, val);
Anish Bhattb5a02f52015-01-14 15:17:34 -08003841 if (ret < 0)
3842 goto bye;
3843 adap->clipt_start = val[0];
3844 adap->clipt_end = val[1];
3845
Rahul Lakkireddyb72a32d2016-08-22 16:29:06 +05303846 /* We don't yet have a PARAMs calls to retrieve the number of Traffic
3847 * Classes supported by the hardware/firmware so we hard code it here
3848 * for now.
3849 */
3850 adap->params.nsched_cls = is_t4(adap->params.chip) ? 15 : 16;
3851
Vipul Pandya636f9d32012-09-26 02:39:39 +00003852 /* query params related to active filter region */
3853 params[0] = FW_PARAM_PFVF(ACTIVE_FILTER_START);
3854 params[1] = FW_PARAM_PFVF(ACTIVE_FILTER_END);
Hariprasad Shenaib2612722015-05-27 22:30:24 +05303855 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params, val);
Vipul Pandya636f9d32012-09-26 02:39:39 +00003856 /* If Active filter size is set we enable establishing
3857 * offload connection through firmware work request
3858 */
3859 if ((val[0] != val[1]) && (ret >= 0)) {
3860 adap->flags |= FW_OFLD_CONN;
3861 adap->tids.aftid_base = val[0];
3862 adap->tids.aftid_end = val[1];
3863 }
3864
Vipul Pandyab407a4a2013-04-29 04:04:40 +00003865 /* If we're running on newer firmware, let it know that we're
3866 * prepared to deal with encapsulated CPL messages. Older
3867 * firmware won't understand this and we'll just get
3868 * unencapsulated messages ...
3869 */
3870 params[0] = FW_PARAM_PFVF(CPLFW4MSG_ENCAP);
3871 val[0] = 1;
Hariprasad Shenaib2612722015-05-27 22:30:24 +05303872 (void)t4_set_params(adap, adap->mbox, adap->pf, 0, 1, params, val);
Vipul Pandyab407a4a2013-04-29 04:04:40 +00003873
Vipul Pandya636f9d32012-09-26 02:39:39 +00003874 /*
Kumar Sanghvi1ac0f092014-02-18 17:56:12 +05303875 * Find out whether we're allowed to use the T5+ ULPTX MEMWRITE DSGL
3876 * capability. Earlier versions of the firmware didn't have the
3877 * ULPTX_MEMWRITE_DSGL so we'll interpret a query failure as no
3878 * permission to use ULPTX MEMWRITE DSGL.
3879 */
3880 if (is_t4(adap->params.chip)) {
3881 adap->params.ulptx_memwrite_dsgl = false;
3882 } else {
3883 params[0] = FW_PARAM_DEV(ULPTX_MEMWRITE_DSGL);
Hariprasad Shenaib2612722015-05-27 22:30:24 +05303884 ret = t4_query_params(adap, adap->mbox, adap->pf, 0,
Kumar Sanghvi1ac0f092014-02-18 17:56:12 +05303885 1, params, val);
3886 adap->params.ulptx_memwrite_dsgl = (ret == 0 && val[0] != 0);
3887 }
3888
Steve Wise086de572016-09-16 07:54:49 -07003889 /* See if FW supports FW_RI_FR_NSMR_TPTE_WR work request */
3890 params[0] = FW_PARAM_DEV(RI_FR_NSMR_TPTE_WR);
3891 ret = t4_query_params(adap, adap->mbox, adap->pf, 0,
3892 1, params, val);
3893 adap->params.fr_nsmr_tpte_wr_support = (ret == 0 && val[0] != 0);
3894
Kumar Sanghvi1ac0f092014-02-18 17:56:12 +05303895 /*
Vipul Pandya636f9d32012-09-26 02:39:39 +00003896 * Get device capabilities so we can determine what resources we need
3897 * to manage.
3898 */
3899 memset(&caps_cmd, 0, sizeof(caps_cmd));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303900 caps_cmd.op_to_write = htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
3901 FW_CMD_REQUEST_F | FW_CMD_READ_F);
Naresh Kumar Innace91a922012-11-15 22:41:17 +05303902 caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd));
Vipul Pandya636f9d32012-09-26 02:39:39 +00003903 ret = t4_wr_mbox(adap, adap->mbox, &caps_cmd, sizeof(caps_cmd),
3904 &caps_cmd);
3905 if (ret < 0)
3906 goto bye;
3907
Vipul Pandya13ee15d2012-09-26 02:39:40 +00003908 if (caps_cmd.ofldcaps) {
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003909 /* query offload-related parameters */
3910 params[0] = FW_PARAM_DEV(NTID);
3911 params[1] = FW_PARAM_PFVF(SERVER_START);
3912 params[2] = FW_PARAM_PFVF(SERVER_END);
3913 params[3] = FW_PARAM_PFVF(TDDP_START);
3914 params[4] = FW_PARAM_PFVF(TDDP_END);
3915 params[5] = FW_PARAM_DEV(FLOWC_BUFFIFO_SZ);
Hariprasad Shenaib2612722015-05-27 22:30:24 +05303916 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 6,
Vipul Pandya636f9d32012-09-26 02:39:39 +00003917 params, val);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003918 if (ret < 0)
3919 goto bye;
3920 adap->tids.ntids = val[0];
3921 adap->tids.natids = min(adap->tids.ntids / 2, MAX_ATIDS);
3922 adap->tids.stid_base = val[1];
3923 adap->tids.nstids = val[2] - val[1] + 1;
Vipul Pandya636f9d32012-09-26 02:39:39 +00003924 /*
Joe Perchesdbedd442015-03-06 20:49:12 -08003925 * Setup server filter region. Divide the available filter
Vipul Pandya636f9d32012-09-26 02:39:39 +00003926 * region into two parts. Regular filters get 1/3rd and server
3927 * filters get 2/3rd part. This is only enabled if workarond
3928 * path is enabled.
3929 * 1. For regular filters.
3930 * 2. Server filter: This are special filters which are used
3931 * to redirect SYN packets to offload queue.
3932 */
3933 if (adap->flags & FW_OFLD_CONN && !is_bypass(adap)) {
3934 adap->tids.sftid_base = adap->tids.ftid_base +
3935 DIV_ROUND_UP(adap->tids.nftids, 3);
3936 adap->tids.nsftids = adap->tids.nftids -
3937 DIV_ROUND_UP(adap->tids.nftids, 3);
3938 adap->tids.nftids = adap->tids.sftid_base -
3939 adap->tids.ftid_base;
3940 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003941 adap->vres.ddp.start = val[3];
3942 adap->vres.ddp.size = val[4] - val[3] + 1;
3943 adap->params.ofldq_wr_cred = val[5];
Vipul Pandya636f9d32012-09-26 02:39:39 +00003944
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003945 adap->params.offload = 1;
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05303946 adap->num_ofld_uld += 1;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003947 }
Vipul Pandya636f9d32012-09-26 02:39:39 +00003948 if (caps_cmd.rdmacaps) {
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003949 params[0] = FW_PARAM_PFVF(STAG_START);
3950 params[1] = FW_PARAM_PFVF(STAG_END);
3951 params[2] = FW_PARAM_PFVF(RQ_START);
3952 params[3] = FW_PARAM_PFVF(RQ_END);
3953 params[4] = FW_PARAM_PFVF(PBL_START);
3954 params[5] = FW_PARAM_PFVF(PBL_END);
Hariprasad Shenaib2612722015-05-27 22:30:24 +05303955 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 6,
Vipul Pandya636f9d32012-09-26 02:39:39 +00003956 params, val);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00003957 if (ret < 0)
3958 goto bye;
3959 adap->vres.stag.start = val[0];
3960 adap->vres.stag.size = val[1] - val[0] + 1;
3961 adap->vres.rq.start = val[2];
3962 adap->vres.rq.size = val[3] - val[2] + 1;
3963 adap->vres.pbl.start = val[4];
3964 adap->vres.pbl.size = val[5] - val[4] + 1;
Dimitris Michailidisa0881ca2010-06-18 10:05:34 +00003965
3966 params[0] = FW_PARAM_PFVF(SQRQ_START);
3967 params[1] = FW_PARAM_PFVF(SQRQ_END);
3968 params[2] = FW_PARAM_PFVF(CQ_START);
3969 params[3] = FW_PARAM_PFVF(CQ_END);
Dimitris Michailidis1ae970e2010-08-02 13:19:19 +00003970 params[4] = FW_PARAM_PFVF(OCQ_START);
3971 params[5] = FW_PARAM_PFVF(OCQ_END);
Hariprasad Shenaib2612722015-05-27 22:30:24 +05303972 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 6, params,
Hariprasad Shenai5c937dd2014-09-01 19:55:00 +05303973 val);
Dimitris Michailidisa0881ca2010-06-18 10:05:34 +00003974 if (ret < 0)
3975 goto bye;
3976 adap->vres.qp.start = val[0];
3977 adap->vres.qp.size = val[1] - val[0] + 1;
3978 adap->vres.cq.start = val[2];
3979 adap->vres.cq.size = val[3] - val[2] + 1;
Dimitris Michailidis1ae970e2010-08-02 13:19:19 +00003980 adap->vres.ocq.start = val[4];
3981 adap->vres.ocq.size = val[5] - val[4] + 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303982
3983 params[0] = FW_PARAM_DEV(MAXORDIRD_QP);
3984 params[1] = FW_PARAM_DEV(MAXIRD_ADAPTER);
Hariprasad Shenaib2612722015-05-27 22:30:24 +05303985 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params,
Hariprasad Shenai5c937dd2014-09-01 19:55:00 +05303986 val);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303987 if (ret < 0) {
3988 adap->params.max_ordird_qp = 8;
3989 adap->params.max_ird_adapter = 32 * adap->tids.ntids;
3990 ret = 0;
3991 } else {
3992 adap->params.max_ordird_qp = val[0];
3993 adap->params.max_ird_adapter = val[1];
3994 }
3995 dev_info(adap->pdev_dev,
3996 "max_ordird_qp %d max_ird_adapter %d\n",
3997 adap->params.max_ordird_qp,
3998 adap->params.max_ird_adapter);
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05303999 adap->num_ofld_uld += 2;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004000 }
Vipul Pandya636f9d32012-09-26 02:39:39 +00004001 if (caps_cmd.iscsicaps) {
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004002 params[0] = FW_PARAM_PFVF(ISCSI_START);
4003 params[1] = FW_PARAM_PFVF(ISCSI_END);
Hariprasad Shenaib2612722015-05-27 22:30:24 +05304004 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2,
Vipul Pandya636f9d32012-09-26 02:39:39 +00004005 params, val);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004006 if (ret < 0)
4007 goto bye;
4008 adap->vres.iscsi.start = val[0];
4009 adap->vres.iscsi.size = val[1] - val[0] + 1;
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304010 /* LIO target and cxgb4i initiaitor */
4011 adap->num_ofld_uld += 2;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004012 }
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304013 if (caps_cmd.cryptocaps) {
4014 /* Should query params here...TODO */
Harsh Jain72a56ca2017-04-10 18:24:00 +05304015 params[0] = FW_PARAM_PFVF(NCRYPTO_LOOKASIDE);
4016 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2,
4017 params, val);
4018 if (ret < 0) {
4019 if (ret != -EINVAL)
4020 goto bye;
4021 } else {
4022 adap->vres.ncrypto_fc = val[0];
4023 }
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304024 adap->params.crypto |= ULP_CRYPTO_LOOKASIDE;
4025 adap->num_uld += 1;
4026 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004027#undef FW_PARAM_PFVF
4028#undef FW_PARAM_DEV
4029
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05304030 /* The MTU/MSS Table is initialized by now, so load their values. If
4031 * we're initializing the adapter, then we'll make any modifications
4032 * we want to the MTU/MSS Table and also initialize the congestion
4033 * parameters.
Vipul Pandya636f9d32012-09-26 02:39:39 +00004034 */
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004035 t4_read_mtu_tbl(adap, adap->params.mtus, NULL);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05304036 if (state != DEV_STATE_INIT) {
4037 int i;
Casey Leedom7ee9ff92010-06-25 12:11:46 +00004038
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05304039 /* The default MTU Table contains values 1492 and 1500.
4040 * However, for TCP, it's better to have two values which are
4041 * a multiple of 8 +/- 4 bytes apart near this popular MTU.
4042 * This allows us to have a TCP Data Payload which is a
4043 * multiple of 8 regardless of what combination of TCP Options
4044 * are in use (always a multiple of 4 bytes) which is
4045 * important for performance reasons. For instance, if no
4046 * options are in use, then we have a 20-byte IP header and a
4047 * 20-byte TCP header. In this case, a 1500-byte MSS would
4048 * result in a TCP Data Payload of 1500 - 40 == 1460 bytes
4049 * which is not a multiple of 8. So using an MSS of 1488 in
4050 * this case results in a TCP Data Payload of 1448 bytes which
4051 * is a multiple of 8. On the other hand, if 12-byte TCP Time
4052 * Stamps have been negotiated, then an MTU of 1500 bytes
4053 * results in a TCP Data Payload of 1448 bytes which, as
4054 * above, is a multiple of 8 bytes ...
4055 */
4056 for (i = 0; i < NMTUS; i++)
4057 if (adap->params.mtus[i] == 1492) {
4058 adap->params.mtus[i] = 1488;
4059 break;
4060 }
4061
4062 t4_load_mtus(adap, adap->params.mtus, adap->params.a_wnd,
4063 adap->params.b_wnd);
4064 }
Hariprasad Shenaidf64e4d2014-12-03 19:32:53 +05304065 t4_init_sge_params(adap);
Vipul Pandya636f9d32012-09-26 02:39:39 +00004066 adap->flags |= FW_OK;
Hariprasad Shenaic1e9af02015-06-05 14:24:52 +05304067 t4_init_tp_params(adap);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004068 return 0;
4069
4070 /*
Vipul Pandya636f9d32012-09-26 02:39:39 +00004071 * Something bad happened. If a command timed out or failed with EIO
4072 * FW does not operate within its spec or something catastrophic
4073 * happened to HW/FW, stop issuing commands.
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004074 */
Vipul Pandya636f9d32012-09-26 02:39:39 +00004075bye:
Hariprasad Shenai4b8e27a2015-03-26 10:04:25 +05304076 kfree(adap->sge.egr_map);
4077 kfree(adap->sge.ingr_map);
4078 kfree(adap->sge.starving_fl);
4079 kfree(adap->sge.txq_maperr);
Hariprasad Shenai5b377d12015-05-27 22:30:23 +05304080#ifdef CONFIG_DEBUG_FS
4081 kfree(adap->sge.blocked_fl);
4082#endif
Vipul Pandya636f9d32012-09-26 02:39:39 +00004083 if (ret != -ETIMEDOUT && ret != -EIO)
4084 t4_fw_bye(adap, adap->mbox);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004085 return ret;
4086}
4087
Dimitris Michailidis204dc3c2010-06-18 10:05:29 +00004088/* EEH callbacks */
4089
4090static pci_ers_result_t eeh_err_detected(struct pci_dev *pdev,
4091 pci_channel_state_t state)
4092{
4093 int i;
4094 struct adapter *adap = pci_get_drvdata(pdev);
4095
4096 if (!adap)
4097 goto out;
4098
4099 rtnl_lock();
4100 adap->flags &= ~FW_OK;
4101 notify_ulds(adap, CXGB4_STATE_START_RECOVERY);
Gavin Shan9fe6cb52014-01-23 12:27:35 +08004102 spin_lock(&adap->stats_lock);
Dimitris Michailidis204dc3c2010-06-18 10:05:29 +00004103 for_each_port(adap, i) {
4104 struct net_device *dev = adap->port[i];
Guilherme G. Piccoli025d0972017-05-28 23:07:01 -03004105 if (dev) {
4106 netif_device_detach(dev);
4107 netif_carrier_off(dev);
4108 }
Dimitris Michailidis204dc3c2010-06-18 10:05:29 +00004109 }
Gavin Shan9fe6cb52014-01-23 12:27:35 +08004110 spin_unlock(&adap->stats_lock);
Hariprasad Shenaib37987e2015-03-26 10:04:26 +05304111 disable_interrupts(adap);
Dimitris Michailidis204dc3c2010-06-18 10:05:29 +00004112 if (adap->flags & FULL_INIT_DONE)
4113 cxgb_down(adap);
4114 rtnl_unlock();
Gavin Shan144be3d2014-01-23 12:27:34 +08004115 if ((adap->flags & DEV_ENABLED)) {
4116 pci_disable_device(pdev);
4117 adap->flags &= ~DEV_ENABLED;
4118 }
Dimitris Michailidis204dc3c2010-06-18 10:05:29 +00004119out: return state == pci_channel_io_perm_failure ?
4120 PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_NEED_RESET;
4121}
4122
4123static pci_ers_result_t eeh_slot_reset(struct pci_dev *pdev)
4124{
4125 int i, ret;
4126 struct fw_caps_config_cmd c;
4127 struct adapter *adap = pci_get_drvdata(pdev);
4128
4129 if (!adap) {
4130 pci_restore_state(pdev);
4131 pci_save_state(pdev);
4132 return PCI_ERS_RESULT_RECOVERED;
4133 }
4134
Gavin Shan144be3d2014-01-23 12:27:34 +08004135 if (!(adap->flags & DEV_ENABLED)) {
4136 if (pci_enable_device(pdev)) {
4137 dev_err(&pdev->dev, "Cannot reenable PCI "
4138 "device after reset\n");
4139 return PCI_ERS_RESULT_DISCONNECT;
4140 }
4141 adap->flags |= DEV_ENABLED;
Dimitris Michailidis204dc3c2010-06-18 10:05:29 +00004142 }
4143
4144 pci_set_master(pdev);
4145 pci_restore_state(pdev);
4146 pci_save_state(pdev);
4147 pci_cleanup_aer_uncorrect_error_status(pdev);
4148
Hariprasad Shenai8203b502014-10-09 05:48:47 +05304149 if (t4_wait_dev_ready(adap->regs) < 0)
Dimitris Michailidis204dc3c2010-06-18 10:05:29 +00004150 return PCI_ERS_RESULT_DISCONNECT;
Hariprasad Shenaib2612722015-05-27 22:30:24 +05304151 if (t4_fw_hello(adap, adap->mbox, adap->pf, MASTER_MUST, NULL) < 0)
Dimitris Michailidis204dc3c2010-06-18 10:05:29 +00004152 return PCI_ERS_RESULT_DISCONNECT;
4153 adap->flags |= FW_OK;
4154 if (adap_init1(adap, &c))
4155 return PCI_ERS_RESULT_DISCONNECT;
4156
4157 for_each_port(adap, i) {
4158 struct port_info *p = adap2pinfo(adap, i);
4159
Hariprasad Shenaib2612722015-05-27 22:30:24 +05304160 ret = t4_alloc_vi(adap, adap->mbox, p->tx_chan, adap->pf, 0, 1,
Dimitris Michailidis060e0c72010-08-02 13:19:21 +00004161 NULL, NULL);
Dimitris Michailidis204dc3c2010-06-18 10:05:29 +00004162 if (ret < 0)
4163 return PCI_ERS_RESULT_DISCONNECT;
4164 p->viid = ret;
4165 p->xact_addr_filt = -1;
4166 }
4167
4168 t4_load_mtus(adap, adap->params.mtus, adap->params.a_wnd,
4169 adap->params.b_wnd);
Dimitris Michailidis1ae970e2010-08-02 13:19:19 +00004170 setup_memwin(adap);
Dimitris Michailidis204dc3c2010-06-18 10:05:29 +00004171 if (cxgb_up(adap))
4172 return PCI_ERS_RESULT_DISCONNECT;
4173 return PCI_ERS_RESULT_RECOVERED;
4174}
4175
4176static void eeh_resume(struct pci_dev *pdev)
4177{
4178 int i;
4179 struct adapter *adap = pci_get_drvdata(pdev);
4180
4181 if (!adap)
4182 return;
4183
4184 rtnl_lock();
4185 for_each_port(adap, i) {
4186 struct net_device *dev = adap->port[i];
Guilherme G. Piccoli025d0972017-05-28 23:07:01 -03004187 if (dev) {
4188 if (netif_running(dev)) {
4189 link_start(dev);
4190 cxgb_set_rxmode(dev);
4191 }
4192 netif_device_attach(dev);
Dimitris Michailidis204dc3c2010-06-18 10:05:29 +00004193 }
Dimitris Michailidis204dc3c2010-06-18 10:05:29 +00004194 }
4195 rtnl_unlock();
4196}
4197
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07004198static const struct pci_error_handlers cxgb4_eeh = {
Dimitris Michailidis204dc3c2010-06-18 10:05:29 +00004199 .error_detected = eeh_err_detected,
4200 .slot_reset = eeh_slot_reset,
4201 .resume = eeh_resume,
4202};
4203
Hariprasad Shenai9b86a8d2016-09-20 12:00:52 +05304204/* Return true if the Link Configuration supports "High Speeds" (those greater
4205 * than 1Gb/s).
4206 */
Kumar Sanghvi57d8b762014-02-18 17:56:10 +05304207static inline bool is_x_10g_port(const struct link_config *lc)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004208{
Hariprasad Shenai9b86a8d2016-09-20 12:00:52 +05304209 unsigned int speeds, high_speeds;
4210
4211 speeds = FW_PORT_CAP_SPEED_V(FW_PORT_CAP_SPEED_G(lc->supported));
4212 high_speeds = speeds & ~(FW_PORT_CAP_SPEED_100M | FW_PORT_CAP_SPEED_1G);
4213
4214 return high_speeds != 0;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004215}
4216
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004217/*
4218 * Perform default configuration of DMA queues depending on the number and type
4219 * of ports we found and the number of available CPUs. Most settings can be
4220 * modified by the admin prior to actual use.
4221 */
Bill Pemberton91744942012-12-03 09:23:02 -05004222static void cfg_queues(struct adapter *adap)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004223{
4224 struct sge *s = &adap->sge;
Hariprasad Shenaiab677ff2016-11-18 16:37:40 +05304225 int i = 0, n10g = 0, qidx = 0;
Anish Bhatt688848b2014-06-19 21:37:13 -07004226#ifndef CONFIG_CHELSIO_T4_DCB
4227 int q10g = 0;
4228#endif
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004229
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304230 /* Reduce memory usage in kdump environment, disable all offload.
4231 */
Ganesh Goudar85eacf32017-05-16 21:17:42 +05304232 if (is_kdump_kernel() || (is_uld(adap) && t4_uld_mem_alloc(adap))) {
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304233 adap->params.offload = 0;
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304234 adap->params.crypto = 0;
4235 }
4236
Hariprasad Shenaiab677ff2016-11-18 16:37:40 +05304237 n10g += is_x_10g_port(&adap2pinfo(adap, i)->link_cfg);
Anish Bhatt688848b2014-06-19 21:37:13 -07004238#ifdef CONFIG_CHELSIO_T4_DCB
4239 /* For Data Center Bridging support we need to be able to support up
4240 * to 8 Traffic Priorities; each of which will be assigned to its
4241 * own TX Queue in order to prevent Head-Of-Line Blocking.
4242 */
4243 if (adap->params.nports * 8 > MAX_ETH_QSETS) {
4244 dev_err(adap->pdev_dev, "MAX_ETH_QSETS=%d < %d!\n",
4245 MAX_ETH_QSETS, adap->params.nports * 8);
4246 BUG_ON(1);
4247 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004248
Anish Bhatt688848b2014-06-19 21:37:13 -07004249 for_each_port(adap, i) {
4250 struct port_info *pi = adap2pinfo(adap, i);
4251
4252 pi->first_qset = qidx;
Ganesh Goudar85eacf32017-05-16 21:17:42 +05304253 pi->nqsets = is_kdump_kernel() ? 1 : 8;
Anish Bhatt688848b2014-06-19 21:37:13 -07004254 qidx += pi->nqsets;
4255 }
4256#else /* !CONFIG_CHELSIO_T4_DCB */
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004257 /*
4258 * We default to 1 queue per non-10G port and up to # of cores queues
4259 * per 10G port.
4260 */
4261 if (n10g)
4262 q10g = (MAX_ETH_QSETS - (adap->params.nports - n10g)) / n10g;
Yuval Mintz5952dde2012-07-01 03:18:55 +00004263 if (q10g > netif_get_num_default_rss_queues())
4264 q10g = netif_get_num_default_rss_queues();
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004265
Ganesh Goudar85eacf32017-05-16 21:17:42 +05304266 if (is_kdump_kernel())
4267 q10g = 1;
4268
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004269 for_each_port(adap, i) {
4270 struct port_info *pi = adap2pinfo(adap, i);
4271
4272 pi->first_qset = qidx;
Kumar Sanghvi57d8b762014-02-18 17:56:10 +05304273 pi->nqsets = is_x_10g_port(&pi->link_cfg) ? q10g : 1;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004274 qidx += pi->nqsets;
4275 }
Anish Bhatt688848b2014-06-19 21:37:13 -07004276#endif /* !CONFIG_CHELSIO_T4_DCB */
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004277
4278 s->ethqsets = qidx;
4279 s->max_ethqsets = qidx; /* MSI-X may lower it later */
4280
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304281 if (is_uld(adap)) {
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004282 /*
4283 * For offload we use 1 queue/channel if all ports are up to 1G,
4284 * otherwise we divide all available queues amongst the channels
4285 * capped by the number of available cores.
4286 */
4287 if (n10g) {
Ganesh Goudara56177e2016-10-18 14:21:25 +05304288 i = min_t(int, MAX_OFLD_QSETS, num_online_cpus());
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304289 s->ofldqsets = roundup(i, adap->params.nports);
4290 } else {
4291 s->ofldqsets = adap->params.nports;
4292 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004293 }
4294
4295 for (i = 0; i < ARRAY_SIZE(s->ethrxq); i++) {
4296 struct sge_eth_rxq *r = &s->ethrxq[i];
4297
Hariprasad Shenaic887ad02014-06-06 21:40:45 +05304298 init_rspq(adap, &r->rspq, 5, 10, 1024, 64);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004299 r->fl.size = 72;
4300 }
4301
4302 for (i = 0; i < ARRAY_SIZE(s->ethtxq); i++)
4303 s->ethtxq[i].q.size = 1024;
4304
4305 for (i = 0; i < ARRAY_SIZE(s->ctrlq); i++)
4306 s->ctrlq[i].q.size = 512;
4307
Atul Guptaa45695042017-07-04 16:46:20 +05304308 if (!is_t4(adap->params.chip))
4309 s->ptptxq.q.size = 8;
4310
Hariprasad Shenaic887ad02014-06-06 21:40:45 +05304311 init_rspq(adap, &s->fw_evtq, 0, 1, 1024, 64);
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304312 init_rspq(adap, &s->intrq, 0, 1, 512, 64);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004313}
4314
4315/*
4316 * Reduce the number of Ethernet queues across all ports to at most n.
4317 * n provides at least one queue per port.
4318 */
Bill Pemberton91744942012-12-03 09:23:02 -05004319static void reduce_ethqs(struct adapter *adap, int n)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004320{
4321 int i;
4322 struct port_info *pi;
4323
4324 while (n < adap->sge.ethqsets)
4325 for_each_port(adap, i) {
4326 pi = adap2pinfo(adap, i);
4327 if (pi->nqsets > 1) {
4328 pi->nqsets--;
4329 adap->sge.ethqsets--;
4330 if (adap->sge.ethqsets <= n)
4331 break;
4332 }
4333 }
4334
4335 n = 0;
4336 for_each_port(adap, i) {
4337 pi = adap2pinfo(adap, i);
4338 pi->first_qset = n;
4339 n += pi->nqsets;
4340 }
4341}
4342
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304343static int get_msix_info(struct adapter *adap)
4344{
4345 struct uld_msix_info *msix_info;
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304346 unsigned int max_ingq = 0;
4347
4348 if (is_offload(adap))
4349 max_ingq += MAX_OFLD_QSETS * adap->num_ofld_uld;
4350 if (is_pci_uld(adap))
4351 max_ingq += MAX_OFLD_QSETS * adap->num_uld;
4352
4353 if (!max_ingq)
4354 goto out;
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304355
4356 msix_info = kcalloc(max_ingq, sizeof(*msix_info), GFP_KERNEL);
4357 if (!msix_info)
4358 return -ENOMEM;
4359
4360 adap->msix_bmap_ulds.msix_bmap = kcalloc(BITS_TO_LONGS(max_ingq),
4361 sizeof(long), GFP_KERNEL);
4362 if (!adap->msix_bmap_ulds.msix_bmap) {
4363 kfree(msix_info);
4364 return -ENOMEM;
4365 }
4366 spin_lock_init(&adap->msix_bmap_ulds.lock);
4367 adap->msix_info_ulds = msix_info;
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304368out:
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304369 return 0;
4370}
4371
4372static void free_msix_info(struct adapter *adap)
4373{
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304374 if (!(adap->num_uld && adap->num_ofld_uld))
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304375 return;
4376
4377 kfree(adap->msix_info_ulds);
4378 kfree(adap->msix_bmap_ulds.msix_bmap);
4379}
4380
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004381/* 2 MSI-X vectors needed for the FW queue and non-data interrupts */
4382#define EXTRA_VECS 2
4383
Bill Pemberton91744942012-12-03 09:23:02 -05004384static int enable_msix(struct adapter *adap)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004385{
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304386 int ofld_need = 0, uld_need = 0;
4387 int i, j, want, need, allocated;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004388 struct sge *s = &adap->sge;
4389 unsigned int nchan = adap->params.nports;
Hariprasad Shenaif36e58e2015-03-04 18:16:28 +05304390 struct msix_entry *entries;
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304391 int max_ingq = MAX_INGQ;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004392
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304393 if (is_pci_uld(adap))
4394 max_ingq += (MAX_OFLD_QSETS * adap->num_uld);
4395 if (is_offload(adap))
4396 max_ingq += (MAX_OFLD_QSETS * adap->num_ofld_uld);
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304397 entries = kmalloc(sizeof(*entries) * (max_ingq + 1),
Hariprasad Shenaif36e58e2015-03-04 18:16:28 +05304398 GFP_KERNEL);
4399 if (!entries)
4400 return -ENOMEM;
4401
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304402 /* map for msix */
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304403 if (get_msix_info(adap)) {
4404 adap->params.offload = 0;
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304405 adap->params.crypto = 0;
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304406 }
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304407
4408 for (i = 0; i < max_ingq + 1; ++i)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004409 entries[i].entry = i;
4410
4411 want = s->max_ethqsets + EXTRA_VECS;
4412 if (is_offload(adap)) {
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304413 want += adap->num_ofld_uld * s->ofldqsets;
4414 ofld_need = adap->num_ofld_uld * nchan;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004415 }
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304416 if (is_pci_uld(adap)) {
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304417 want += adap->num_uld * s->ofldqsets;
4418 uld_need = adap->num_uld * nchan;
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304419 }
Anish Bhatt688848b2014-06-19 21:37:13 -07004420#ifdef CONFIG_CHELSIO_T4_DCB
4421 /* For Data Center Bridging we need 8 Ethernet TX Priority Queues for
4422 * each port.
4423 */
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304424 need = 8 * adap->params.nports + EXTRA_VECS + ofld_need + uld_need;
Anish Bhatt688848b2014-06-19 21:37:13 -07004425#else
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304426 need = adap->params.nports + EXTRA_VECS + ofld_need + uld_need;
Anish Bhatt688848b2014-06-19 21:37:13 -07004427#endif
Hariprasad Shenaif36e58e2015-03-04 18:16:28 +05304428 allocated = pci_enable_msix_range(adap->pdev, entries, need, want);
4429 if (allocated < 0) {
4430 dev_info(adap->pdev_dev, "not enough MSI-X vectors left,"
4431 " not using MSI-X\n");
4432 kfree(entries);
4433 return allocated;
4434 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004435
Hariprasad Shenaif36e58e2015-03-04 18:16:28 +05304436 /* Distribute available vectors to the various queue groups.
Alexander Gordeevc32ad222014-02-18 11:07:59 +01004437 * Every group gets its minimum requirement and NIC gets top
4438 * priority for leftovers.
4439 */
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304440 i = allocated - EXTRA_VECS - ofld_need - uld_need;
Alexander Gordeevc32ad222014-02-18 11:07:59 +01004441 if (i < s->max_ethqsets) {
4442 s->max_ethqsets = i;
4443 if (i < s->ethqsets)
4444 reduce_ethqs(adap, i);
4445 }
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304446 if (is_uld(adap)) {
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304447 if (allocated < want)
4448 s->nqs_per_uld = nchan;
4449 else
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304450 s->nqs_per_uld = s->ofldqsets;
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304451 }
4452
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304453 for (i = 0; i < (s->max_ethqsets + EXTRA_VECS); ++i)
Alexander Gordeevc32ad222014-02-18 11:07:59 +01004454 adap->msix_info[i].vec = entries[i].vector;
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304455 if (is_uld(adap)) {
4456 for (j = 0 ; i < allocated; ++i, j++) {
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304457 adap->msix_info_ulds[j].vec = entries[i].vector;
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304458 adap->msix_info_ulds[j].idx = i;
4459 }
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05304460 adap->msix_bmap_ulds.mapsize = j;
4461 }
Hariprasad Shenai43eb4e82015-10-21 14:39:53 +05304462 dev_info(adap->pdev_dev, "%d MSI-X vectors allocated, "
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05304463 "nic %d per uld %d\n",
4464 allocated, s->max_ethqsets, s->nqs_per_uld);
Alexander Gordeevc32ad222014-02-18 11:07:59 +01004465
Hariprasad Shenaif36e58e2015-03-04 18:16:28 +05304466 kfree(entries);
Alexander Gordeevc32ad222014-02-18 11:07:59 +01004467 return 0;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004468}
4469
4470#undef EXTRA_VECS
4471
Bill Pemberton91744942012-12-03 09:23:02 -05004472static int init_rss(struct adapter *adap)
Dimitris Michailidis671b0062010-07-11 12:01:17 +00004473{
Hariprasad Shenaic035e182015-05-06 19:48:37 +05304474 unsigned int i;
4475 int err;
4476
4477 err = t4_init_rss_mode(adap, adap->mbox);
4478 if (err)
4479 return err;
Dimitris Michailidis671b0062010-07-11 12:01:17 +00004480
4481 for_each_port(adap, i) {
4482 struct port_info *pi = adap2pinfo(adap, i);
4483
4484 pi->rss = kcalloc(pi->rss_size, sizeof(u16), GFP_KERNEL);
4485 if (!pi->rss)
4486 return -ENOMEM;
Dimitris Michailidis671b0062010-07-11 12:01:17 +00004487 }
4488 return 0;
4489}
4490
Hariprasad Shenai547fd272015-12-23 11:29:53 +05304491static int cxgb4_get_pcie_dev_link_caps(struct adapter *adap,
4492 enum pci_bus_speed *speed,
4493 enum pcie_link_width *width)
4494{
4495 u32 lnkcap1, lnkcap2;
4496 int err1, err2;
4497
4498#define PCIE_MLW_CAP_SHIFT 4 /* start of MLW mask in link capabilities */
4499
4500 *speed = PCI_SPEED_UNKNOWN;
4501 *width = PCIE_LNK_WIDTH_UNKNOWN;
4502
4503 err1 = pcie_capability_read_dword(adap->pdev, PCI_EXP_LNKCAP,
4504 &lnkcap1);
4505 err2 = pcie_capability_read_dword(adap->pdev, PCI_EXP_LNKCAP2,
4506 &lnkcap2);
4507 if (!err2 && lnkcap2) { /* PCIe r3.0-compliant */
4508 if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_8_0GB)
4509 *speed = PCIE_SPEED_8_0GT;
4510 else if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_5_0GB)
4511 *speed = PCIE_SPEED_5_0GT;
4512 else if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_2_5GB)
4513 *speed = PCIE_SPEED_2_5GT;
4514 }
4515 if (!err1) {
4516 *width = (lnkcap1 & PCI_EXP_LNKCAP_MLW) >> PCIE_MLW_CAP_SHIFT;
4517 if (!lnkcap2) { /* pre-r3.0 */
4518 if (lnkcap1 & PCI_EXP_LNKCAP_SLS_5_0GB)
4519 *speed = PCIE_SPEED_5_0GT;
4520 else if (lnkcap1 & PCI_EXP_LNKCAP_SLS_2_5GB)
4521 *speed = PCIE_SPEED_2_5GT;
4522 }
4523 }
4524
4525 if (*speed == PCI_SPEED_UNKNOWN || *width == PCIE_LNK_WIDTH_UNKNOWN)
4526 return err1 ? err1 : err2 ? err2 : -EINVAL;
4527 return 0;
4528}
4529
4530static void cxgb4_check_pcie_caps(struct adapter *adap)
4531{
4532 enum pcie_link_width width, width_cap;
4533 enum pci_bus_speed speed, speed_cap;
4534
4535#define PCIE_SPEED_STR(speed) \
4536 (speed == PCIE_SPEED_8_0GT ? "8.0GT/s" : \
4537 speed == PCIE_SPEED_5_0GT ? "5.0GT/s" : \
4538 speed == PCIE_SPEED_2_5GT ? "2.5GT/s" : \
4539 "Unknown")
4540
4541 if (cxgb4_get_pcie_dev_link_caps(adap, &speed_cap, &width_cap)) {
4542 dev_warn(adap->pdev_dev,
4543 "Unable to determine PCIe device BW capabilities\n");
4544 return;
4545 }
4546
4547 if (pcie_get_minimum_link(adap->pdev, &speed, &width) ||
4548 speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) {
4549 dev_warn(adap->pdev_dev,
4550 "Unable to determine PCI Express bandwidth.\n");
4551 return;
4552 }
4553
4554 dev_info(adap->pdev_dev, "PCIe link speed is %s, device supports %s\n",
4555 PCIE_SPEED_STR(speed), PCIE_SPEED_STR(speed_cap));
4556 dev_info(adap->pdev_dev, "PCIe link width is x%d, device supports x%d\n",
4557 width, width_cap);
4558 if (speed < speed_cap || width < width_cap)
4559 dev_info(adap->pdev_dev,
4560 "A slot with more lanes and/or higher speed is "
4561 "suggested for optimal performance.\n");
4562}
4563
Hariprasad Shenai0de72732016-04-26 20:10:22 +05304564/* Dump basic information about the adapter */
4565static void print_adapter_info(struct adapter *adapter)
4566{
Ganesh Goudar760446f2017-07-20 18:28:48 +05304567 /* Hardware/Firmware/etc. Version/Revision IDs */
4568 t4_dump_version_info(adapter);
Hariprasad Shenai0de72732016-04-26 20:10:22 +05304569
4570 /* Software/Hardware configuration */
4571 dev_info(adapter->pdev_dev, "Configuration: %sNIC %s, %s capable\n",
4572 is_offload(adapter) ? "R" : "",
4573 ((adapter->flags & USING_MSIX) ? "MSI-X" :
4574 (adapter->flags & USING_MSI) ? "MSI" : ""),
4575 is_offload(adapter) ? "Offload" : "non-Offload");
4576}
4577
Bill Pemberton91744942012-12-03 09:23:02 -05004578static void print_port_info(const struct net_device *dev)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004579{
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004580 char buf[80];
Dimitris Michailidis118969e2010-12-14 21:36:48 +00004581 char *bufp = buf;
Dimitris Michailidisf1a051b2010-05-10 15:58:08 +00004582 const char *spd = "";
Dimitris Michailidis118969e2010-12-14 21:36:48 +00004583 const struct port_info *pi = netdev_priv(dev);
4584 const struct adapter *adap = pi->adapter;
Dimitris Michailidisf1a051b2010-05-10 15:58:08 +00004585
4586 if (adap->params.pci.speed == PCI_EXP_LNKSTA_CLS_2_5GB)
4587 spd = " 2.5 GT/s";
4588 else if (adap->params.pci.speed == PCI_EXP_LNKSTA_CLS_5_0GB)
4589 spd = " 5 GT/s";
Roland Dreierd2e752d2014-04-28 17:36:20 -07004590 else if (adap->params.pci.speed == PCI_EXP_LNKSTA_CLS_8_0GB)
4591 spd = " 8 GT/s";
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004592
Dimitris Michailidis118969e2010-12-14 21:36:48 +00004593 if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_100M)
Ganesh Goudar5e78f7f2017-01-06 16:51:46 +05304594 bufp += sprintf(bufp, "100M/");
Dimitris Michailidis118969e2010-12-14 21:36:48 +00004595 if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_1G)
Ganesh Goudar5e78f7f2017-01-06 16:51:46 +05304596 bufp += sprintf(bufp, "1G/");
Dimitris Michailidis118969e2010-12-14 21:36:48 +00004597 if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_10G)
4598 bufp += sprintf(bufp, "10G/");
Hariprasad Shenai9b86a8d2016-09-20 12:00:52 +05304599 if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_25G)
4600 bufp += sprintf(bufp, "25G/");
Kumar Sanghvi72aca4b2014-02-18 17:56:08 +05304601 if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_40G)
4602 bufp += sprintf(bufp, "40G/");
Hariprasad Shenai9b86a8d2016-09-20 12:00:52 +05304603 if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_100G)
4604 bufp += sprintf(bufp, "100G/");
Dimitris Michailidis118969e2010-12-14 21:36:48 +00004605 if (bufp != buf)
4606 --bufp;
Kumar Sanghvi72aca4b2014-02-18 17:56:08 +05304607 sprintf(bufp, "BASE-%s", t4_get_port_type_description(pi->port_type));
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004608
Hariprasad Shenai0de72732016-04-26 20:10:22 +05304609 netdev_info(dev, "%s: Chelsio %s (%s) %s\n",
4610 dev->name, adap->params.vpd.id, adap->name, buf);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004611}
4612
Bill Pemberton91744942012-12-03 09:23:02 -05004613static void enable_pcie_relaxed_ordering(struct pci_dev *dev)
Dimitris Michailidisef306b52010-12-14 21:36:44 +00004614{
Jiang Liue5c8ae52012-08-20 13:53:19 -06004615 pcie_capability_set_word(dev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_RELAX_EN);
Dimitris Michailidisef306b52010-12-14 21:36:44 +00004616}
4617
Dimitris Michailidis06546392010-07-11 12:01:16 +00004618/*
4619 * Free the following resources:
4620 * - memory used for tables
4621 * - MSI/MSI-X
4622 * - net devices
4623 * - resources FW is holding for us
4624 */
4625static void free_some_resources(struct adapter *adapter)
4626{
4627 unsigned int i;
4628
Michal Hocko752ade62017-05-08 15:57:27 -07004629 kvfree(adapter->l2t);
Rahul Lakkireddyb72a32d2016-08-22 16:29:06 +05304630 t4_cleanup_sched(adapter);
Michal Hocko752ade62017-05-08 15:57:27 -07004631 kvfree(adapter->tids.tid_tab);
Rahul Lakkireddyd8931842016-09-20 17:13:09 +05304632 cxgb4_cleanup_tc_u32(adapter);
Hariprasad Shenai4b8e27a2015-03-26 10:04:25 +05304633 kfree(adapter->sge.egr_map);
4634 kfree(adapter->sge.ingr_map);
4635 kfree(adapter->sge.starving_fl);
4636 kfree(adapter->sge.txq_maperr);
Hariprasad Shenai5b377d12015-05-27 22:30:23 +05304637#ifdef CONFIG_DEBUG_FS
4638 kfree(adapter->sge.blocked_fl);
4639#endif
Dimitris Michailidis06546392010-07-11 12:01:16 +00004640 disable_msi(adapter);
4641
4642 for_each_port(adapter, i)
Dimitris Michailidis671b0062010-07-11 12:01:17 +00004643 if (adapter->port[i]) {
Hariprasad Shenai4f3a0fc2015-06-05 14:24:47 +05304644 struct port_info *pi = adap2pinfo(adapter, i);
4645
4646 if (pi->viid != 0)
4647 t4_free_vi(adapter, adapter->mbox, adapter->pf,
4648 0, pi->viid);
Dimitris Michailidis671b0062010-07-11 12:01:17 +00004649 kfree(adap2pinfo(adapter, i)->rss);
Dimitris Michailidis06546392010-07-11 12:01:16 +00004650 free_netdev(adapter->port[i]);
Dimitris Michailidis671b0062010-07-11 12:01:17 +00004651 }
Dimitris Michailidis06546392010-07-11 12:01:16 +00004652 if (adapter->flags & FW_OK)
Hariprasad Shenaib2612722015-05-27 22:30:24 +05304653 t4_fw_bye(adapter, adapter->pf);
Dimitris Michailidis06546392010-07-11 12:01:16 +00004654}
4655
Michał Mirosław2ed28ba2011-04-16 13:05:08 +00004656#define TSO_FLAGS (NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_TSO_ECN)
Dimitris Michailidis35d35682010-08-02 13:19:20 +00004657#define VLAN_FEAT (NETIF_F_SG | NETIF_F_IP_CSUM | TSO_FLAGS | \
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004658 NETIF_F_IPV6_CSUM | NETIF_F_HIGHDMA)
Santosh Rastapur22adfe02013-03-14 05:08:51 +00004659#define SEGMENT_SIZE 128
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004660
Hariprasad Shenaid86bd292015-08-04 14:36:19 +05304661static int get_chip_type(struct pci_dev *pdev, u32 pl_rev)
4662{
Hariprasad Shenaid86bd292015-08-04 14:36:19 +05304663 u16 device_id;
4664
4665 /* Retrieve adapter's device ID */
4666 pci_read_config_word(pdev, PCI_DEVICE_ID, &device_id);
françois romieu46cdc9b2015-09-04 23:05:42 +02004667
4668 switch (device_id >> 12) {
Hariprasad Shenaid86bd292015-08-04 14:36:19 +05304669 case CHELSIO_T4:
françois romieu46cdc9b2015-09-04 23:05:42 +02004670 return CHELSIO_CHIP_CODE(CHELSIO_T4, pl_rev);
Hariprasad Shenaid86bd292015-08-04 14:36:19 +05304671 case CHELSIO_T5:
françois romieu46cdc9b2015-09-04 23:05:42 +02004672 return CHELSIO_CHIP_CODE(CHELSIO_T5, pl_rev);
Hariprasad Shenaid86bd292015-08-04 14:36:19 +05304673 case CHELSIO_T6:
françois romieu46cdc9b2015-09-04 23:05:42 +02004674 return CHELSIO_CHIP_CODE(CHELSIO_T6, pl_rev);
Hariprasad Shenaid86bd292015-08-04 14:36:19 +05304675 default:
4676 dev_err(&pdev->dev, "Device %d is not supported\n",
4677 device_id);
Hariprasad Shenaid86bd292015-08-04 14:36:19 +05304678 }
françois romieu46cdc9b2015-09-04 23:05:42 +02004679 return -EINVAL;
Hariprasad Shenaid86bd292015-08-04 14:36:19 +05304680}
4681
Hariprasad Shenaib6244202016-06-14 14:39:31 +05304682#ifdef CONFIG_PCI_IOV
Hariprasad Shenaie7b48a32016-08-23 11:35:32 +05304683static void dummy_setup(struct net_device *dev)
4684{
4685 dev->type = ARPHRD_NONE;
4686 dev->mtu = 0;
4687 dev->hard_header_len = 0;
4688 dev->addr_len = 0;
4689 dev->tx_queue_len = 0;
4690 dev->flags |= IFF_NOARP;
4691 dev->priv_flags |= IFF_NO_QUEUE;
4692
4693 /* Initialize the device structure. */
4694 dev->netdev_ops = &cxgb4_mgmt_netdev_ops;
4695 dev->ethtool_ops = &cxgb4_mgmt_ethtool_ops;
David S. Millercf124db2017-05-08 12:52:56 -04004696 dev->needs_free_netdev = true;
Hariprasad Shenaie7b48a32016-08-23 11:35:32 +05304697}
4698
4699static int config_mgmt_dev(struct pci_dev *pdev)
4700{
4701 struct adapter *adap = pci_get_drvdata(pdev);
4702 struct net_device *netdev;
4703 struct port_info *pi;
4704 char name[IFNAMSIZ];
4705 int err;
4706
4707 snprintf(name, IFNAMSIZ, "mgmtpf%d%d", adap->adap_idx, adap->pf);
Ganesh Goudar038c35a2017-01-12 12:23:21 +05304708 netdev = alloc_netdev(sizeof(struct port_info), name, NET_NAME_UNKNOWN,
4709 dummy_setup);
Hariprasad Shenaie7b48a32016-08-23 11:35:32 +05304710 if (!netdev)
4711 return -ENOMEM;
4712
4713 pi = netdev_priv(netdev);
4714 pi->adapter = adap;
Ganesh Goudar96fe11f2017-01-17 14:09:38 +05304715 pi->port_id = adap->pf % adap->params.nports;
Hariprasad Shenaie7b48a32016-08-23 11:35:32 +05304716 SET_NETDEV_DEV(netdev, &pdev->dev);
4717
4718 adap->port[0] = netdev;
4719
4720 err = register_netdev(adap->port[0]);
4721 if (err) {
4722 pr_info("Unable to register VF mgmt netdev %s\n", name);
4723 free_netdev(adap->port[0]);
4724 adap->port[0] = NULL;
4725 return err;
4726 }
4727 return 0;
4728}
4729
Hariprasad Shenaib6244202016-06-14 14:39:31 +05304730static int cxgb4_iov_configure(struct pci_dev *pdev, int num_vfs)
4731{
Hariprasad Shenai78294512016-08-11 21:06:23 +05304732 struct adapter *adap = pci_get_drvdata(pdev);
Hariprasad Shenaib6244202016-06-14 14:39:31 +05304733 int err = 0;
4734 int current_vfs = pci_num_vf(pdev);
4735 u32 pcie_fw;
Hariprasad Shenaib6244202016-06-14 14:39:31 +05304736
Hariprasad Shenai78294512016-08-11 21:06:23 +05304737 pcie_fw = readl(adap->regs + PCIE_FW_A);
Hariprasad Shenaib6244202016-06-14 14:39:31 +05304738 /* Check if cxgb4 is the MASTER and fw is initialized */
4739 if (!(pcie_fw & PCIE_FW_INIT_F) ||
4740 !(pcie_fw & PCIE_FW_MASTER_VLD_F) ||
4741 PCIE_FW_MASTER_G(pcie_fw) != 4) {
4742 dev_warn(&pdev->dev,
4743 "cxgb4 driver needs to be MASTER to support SRIOV\n");
4744 return -EOPNOTSUPP;
4745 }
4746
4747 /* If any of the VF's is already assigned to Guest OS, then
4748 * SRIOV for the same cannot be modified
4749 */
4750 if (current_vfs && pci_vfs_assigned(pdev)) {
4751 dev_err(&pdev->dev,
4752 "Cannot modify SR-IOV while VFs are assigned\n");
4753 num_vfs = current_vfs;
4754 return num_vfs;
4755 }
4756
4757 /* Disable SRIOV when zero is passed.
4758 * One needs to disable SRIOV before modifying it, else
4759 * stack throws the below warning:
4760 * " 'n' VFs already enabled. Disable before enabling 'm' VFs."
4761 */
4762 if (!num_vfs) {
4763 pci_disable_sriov(pdev);
Hariprasad Shenaie7b48a32016-08-23 11:35:32 +05304764 if (adap->port[0]) {
Hariprasad Shenai78294512016-08-11 21:06:23 +05304765 unregister_netdev(adap->port[0]);
Hariprasad Shenaie7b48a32016-08-23 11:35:32 +05304766 adap->port[0] = NULL;
4767 }
Hariprasad Shenai661dbeb2016-09-02 19:13:53 +05304768 /* free VF resources */
4769 kfree(adap->vfinfo);
4770 adap->vfinfo = NULL;
4771 adap->num_vfs = 0;
Hariprasad Shenaib6244202016-06-14 14:39:31 +05304772 return num_vfs;
4773 }
4774
4775 if (num_vfs != current_vfs) {
4776 err = pci_enable_sriov(pdev, num_vfs);
4777 if (err)
4778 return err;
Hariprasad Shenai78294512016-08-11 21:06:23 +05304779
Hariprasad Shenai661dbeb2016-09-02 19:13:53 +05304780 adap->num_vfs = num_vfs;
Hariprasad Shenaie7b48a32016-08-23 11:35:32 +05304781 err = config_mgmt_dev(pdev);
4782 if (err)
4783 return err;
Hariprasad Shenaib6244202016-06-14 14:39:31 +05304784 }
Hariprasad Shenai661dbeb2016-09-02 19:13:53 +05304785
4786 adap->vfinfo = kcalloc(adap->num_vfs,
4787 sizeof(struct vf_info), GFP_KERNEL);
4788 if (adap->vfinfo)
4789 fill_vf_station_mac_addr(adap);
Hariprasad Shenaib6244202016-06-14 14:39:31 +05304790 return num_vfs;
4791}
4792#endif
4793
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00004794static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004795{
Santosh Rastapur22adfe02013-03-14 05:08:51 +00004796 int func, i, err, s_qpp, qpp, num_seg;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004797 struct port_info *pi;
Michał Mirosławc8f44af2011-11-15 15:29:55 +00004798 bool highdma = false;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004799 struct adapter *adapter = NULL;
Hariprasad Shenai78294512016-08-11 21:06:23 +05304800 struct net_device *netdev;
Hariprasad Shenaid6ce2622014-09-16 02:58:46 +05304801 void __iomem *regs;
Hariprasad Shenaid86bd292015-08-04 14:36:19 +05304802 u32 whoami, pl_rev;
4803 enum chip_type chip;
Hariprasad Shenai78294512016-08-11 21:06:23 +05304804 static int adap_idx = 1;
Arnd Bergmann0a327882017-01-18 15:52:51 +01004805#ifdef CONFIG_PCI_IOV
Ganesh Goudar96fe11f2017-01-17 14:09:38 +05304806 u32 v, port_vec;
Arnd Bergmann0a327882017-01-18 15:52:51 +01004807#endif
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004808
4809 printk_once(KERN_INFO "%s - version %s\n", DRV_DESC, DRV_VERSION);
4810
4811 err = pci_request_regions(pdev, KBUILD_MODNAME);
4812 if (err) {
4813 /* Just info, some other driver may have claimed the device. */
4814 dev_info(&pdev->dev, "cannot obtain PCI resources\n");
4815 return err;
4816 }
4817
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004818 err = pci_enable_device(pdev);
4819 if (err) {
4820 dev_err(&pdev->dev, "cannot enable PCI device\n");
4821 goto out_release_regions;
4822 }
4823
Hariprasad Shenaid6ce2622014-09-16 02:58:46 +05304824 regs = pci_ioremap_bar(pdev, 0);
4825 if (!regs) {
4826 dev_err(&pdev->dev, "cannot map device registers\n");
4827 err = -ENOMEM;
4828 goto out_disable_device;
4829 }
4830
Hariprasad Shenai8203b502014-10-09 05:48:47 +05304831 err = t4_wait_dev_ready(regs);
4832 if (err < 0)
4833 goto out_unmap_bar0;
4834
Hariprasad Shenaid6ce2622014-09-16 02:58:46 +05304835 /* We control everything through one PF */
Hariprasad Shenaid86bd292015-08-04 14:36:19 +05304836 whoami = readl(regs + PL_WHOAMI_A);
4837 pl_rev = REV_G(readl(regs + PL_REV_A));
4838 chip = get_chip_type(pdev, pl_rev);
4839 func = CHELSIO_CHIP_VERSION(chip) <= CHELSIO_T5 ?
4840 SOURCEPF_G(whoami) : T6_SOURCEPF_G(whoami);
Hariprasad Shenaid6ce2622014-09-16 02:58:46 +05304841 if (func != ent->driver_data) {
Hariprasad Shenai78294512016-08-11 21:06:23 +05304842#ifndef CONFIG_PCI_IOV
Hariprasad Shenaid6ce2622014-09-16 02:58:46 +05304843 iounmap(regs);
Hariprasad Shenai78294512016-08-11 21:06:23 +05304844#endif
Hariprasad Shenaid6ce2622014-09-16 02:58:46 +05304845 pci_disable_device(pdev);
4846 pci_save_state(pdev); /* to restore SR-IOV later */
4847 goto sriov;
4848 }
4849
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004850 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
Michał Mirosławc8f44af2011-11-15 15:29:55 +00004851 highdma = true;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004852 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
4853 if (err) {
4854 dev_err(&pdev->dev, "unable to obtain 64-bit DMA for "
4855 "coherent allocations\n");
Hariprasad Shenaid6ce2622014-09-16 02:58:46 +05304856 goto out_unmap_bar0;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004857 }
4858 } else {
4859 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
4860 if (err) {
4861 dev_err(&pdev->dev, "no usable DMA configuration\n");
Hariprasad Shenaid6ce2622014-09-16 02:58:46 +05304862 goto out_unmap_bar0;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004863 }
4864 }
4865
4866 pci_enable_pcie_error_reporting(pdev);
Dimitris Michailidisef306b52010-12-14 21:36:44 +00004867 enable_pcie_relaxed_ordering(pdev);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004868 pci_set_master(pdev);
4869 pci_save_state(pdev);
4870
4871 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
4872 if (!adapter) {
4873 err = -ENOMEM;
Hariprasad Shenaid6ce2622014-09-16 02:58:46 +05304874 goto out_unmap_bar0;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004875 }
Hariprasad Shenai78294512016-08-11 21:06:23 +05304876 adap_idx++;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004877
Anish Bhatt29aaee62014-08-20 13:44:06 -07004878 adapter->workq = create_singlethread_workqueue("cxgb4");
4879 if (!adapter->workq) {
4880 err = -ENOMEM;
4881 goto out_free_adapter;
4882 }
4883
Hariprasad Shenai7f080c32016-04-28 13:23:18 +05304884 adapter->mbox_log = kzalloc(sizeof(*adapter->mbox_log) +
4885 (sizeof(struct mbox_cmd) *
4886 T4_OS_LOG_MBOX_CMDS),
4887 GFP_KERNEL);
4888 if (!adapter->mbox_log) {
4889 err = -ENOMEM;
4890 goto out_free_adapter;
4891 }
4892 adapter->mbox_log->size = T4_OS_LOG_MBOX_CMDS;
4893
Gavin Shan144be3d2014-01-23 12:27:34 +08004894 /* PCI device has been enabled */
4895 adapter->flags |= DEV_ENABLED;
4896
Hariprasad Shenaid6ce2622014-09-16 02:58:46 +05304897 adapter->regs = regs;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004898 adapter->pdev = pdev;
4899 adapter->pdev_dev = &pdev->dev;
Hariprasad Shenai0de72732016-04-26 20:10:22 +05304900 adapter->name = pci_name(pdev);
Vipul Pandya3069ee9b2012-05-18 15:29:26 +05304901 adapter->mbox = func;
Hariprasad Shenaib2612722015-05-27 22:30:24 +05304902 adapter->pf = func;
Ganesh Goudarea1e76f2016-12-08 13:16:25 +05304903 adapter->msg_enable = DFLT_MSG_ENABLE;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004904 memset(adapter->chan_map, 0xff, sizeof(adapter->chan_map));
4905
4906 spin_lock_init(&adapter->stats_lock);
4907 spin_lock_init(&adapter->tid_release_lock);
Anish Bhatte327c222014-10-29 17:54:03 -07004908 spin_lock_init(&adapter->win0_lock);
Hariprasad Shenai4055ae52017-01-06 08:47:20 +05304909 spin_lock_init(&adapter->mbox_lock);
4910
4911 INIT_LIST_HEAD(&adapter->mlist.list);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004912
4913 INIT_WORK(&adapter->tid_release_task, process_tid_release_list);
Vipul Pandya881806b2012-05-18 15:29:24 +05304914 INIT_WORK(&adapter->db_full_task, process_db_full);
4915 INIT_WORK(&adapter->db_drop_task, process_db_drop);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004916
4917 err = t4_prep_adapter(adapter);
4918 if (err)
Hariprasad Shenaid6ce2622014-09-16 02:58:46 +05304919 goto out_free_adapter;
4920
Santosh Rastapur22adfe02013-03-14 05:08:51 +00004921
Hariprasad Shenaid14807d2013-12-03 17:05:56 +05304922 if (!is_t4(adapter->params.chip)) {
Hariprasad Shenaif612b812015-01-05 16:30:43 +05304923 s_qpp = (QUEUESPERPAGEPF0_S +
4924 (QUEUESPERPAGEPF1_S - QUEUESPERPAGEPF0_S) *
Hariprasad Shenaib2612722015-05-27 22:30:24 +05304925 adapter->pf);
Hariprasad Shenaif612b812015-01-05 16:30:43 +05304926 qpp = 1 << QUEUESPERPAGEPF0_G(t4_read_reg(adapter,
4927 SGE_EGRESS_QUEUES_PER_PAGE_PF_A) >> s_qpp);
Santosh Rastapur22adfe02013-03-14 05:08:51 +00004928 num_seg = PAGE_SIZE / SEGMENT_SIZE;
4929
4930 /* Each segment size is 128B. Write coalescing is enabled only
4931 * when SGE_EGRESS_QUEUES_PER_PAGE_PF reg value for the
4932 * queue is less no of segments that can be accommodated in
4933 * a page size.
4934 */
4935 if (qpp > num_seg) {
4936 dev_err(&pdev->dev,
4937 "Incorrect number of egress queues per page\n");
4938 err = -EINVAL;
Hariprasad Shenaid6ce2622014-09-16 02:58:46 +05304939 goto out_free_adapter;
Santosh Rastapur22adfe02013-03-14 05:08:51 +00004940 }
4941 adapter->bar2 = ioremap_wc(pci_resource_start(pdev, 2),
4942 pci_resource_len(pdev, 2));
4943 if (!adapter->bar2) {
4944 dev_err(&pdev->dev, "cannot map device bar2 region\n");
4945 err = -ENOMEM;
Hariprasad Shenaid6ce2622014-09-16 02:58:46 +05304946 goto out_free_adapter;
Santosh Rastapur22adfe02013-03-14 05:08:51 +00004947 }
4948 }
4949
Vipul Pandya636f9d32012-09-26 02:39:39 +00004950 setup_memwin(adapter);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004951 err = adap_init0(adapter);
Hariprasad Shenai5b377d12015-05-27 22:30:23 +05304952#ifdef CONFIG_DEBUG_FS
4953 bitmap_zero(adapter->sge.blocked_fl, adapter->sge.egr_sz);
4954#endif
Vipul Pandya636f9d32012-09-26 02:39:39 +00004955 setup_memwin_rdma(adapter);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004956 if (err)
4957 goto out_unmap_bar;
4958
Hariprasad Shenai2a485cf2015-09-08 16:25:40 +05304959 /* configure SGE_STAT_CFG_A to read WC stats */
4960 if (!is_t4(adapter->params.chip))
Hariprasad Shenai676d6a72015-12-23 22:47:14 +05304961 t4_write_reg(adapter, SGE_STAT_CFG_A, STATSOURCE_T5_V(7) |
4962 (is_t5(adapter->params.chip) ? STATMODE_V(0) :
4963 T6_STATMODE_V(0)));
Hariprasad Shenai2a485cf2015-09-08 16:25:40 +05304964
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004965 for_each_port(adapter, i) {
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004966 netdev = alloc_etherdev_mq(sizeof(struct port_info),
4967 MAX_ETH_QSETS);
4968 if (!netdev) {
4969 err = -ENOMEM;
4970 goto out_free_dev;
4971 }
4972
4973 SET_NETDEV_DEV(netdev, &pdev->dev);
4974
4975 adapter->port[i] = netdev;
4976 pi = netdev_priv(netdev);
4977 pi->adapter = adapter;
4978 pi->xact_addr_filt = -1;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004979 pi->port_id = i;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004980 netdev->irq = pdev->irq;
4981
Michał Mirosław2ed28ba2011-04-16 13:05:08 +00004982 netdev->hw_features = NETIF_F_SG | TSO_FLAGS |
4983 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
4984 NETIF_F_RXCSUM | NETIF_F_RXHASH |
Rahul Lakkireddyd8931842016-09-20 17:13:09 +05304985 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX |
4986 NETIF_F_HW_TC;
Michał Mirosławc8f44af2011-11-15 15:29:55 +00004987 if (highdma)
4988 netdev->hw_features |= NETIF_F_HIGHDMA;
4989 netdev->features |= netdev->hw_features;
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004990 netdev->vlan_features = netdev->features & VLAN_FEAT;
4991
Jiri Pirko01789342011-08-16 06:29:00 +00004992 netdev->priv_flags |= IFF_UNICAST_FLT;
4993
Jarod Wilsond894be52016-10-20 13:55:16 -04004994 /* MTU range: 81 - 9600 */
4995 netdev->min_mtu = 81;
4996 netdev->max_mtu = MAX_MTU;
4997
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00004998 netdev->netdev_ops = &cxgb4_netdev_ops;
Anish Bhatt688848b2014-06-19 21:37:13 -07004999#ifdef CONFIG_CHELSIO_T4_DCB
5000 netdev->dcbnl_ops = &cxgb4_dcb_ops;
5001 cxgb4_dcb_state_init(netdev);
5002#endif
Hariprasad Shenai812034f2015-04-06 20:23:23 +05305003 cxgb4_set_ethtool_ops(netdev);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005004 }
5005
5006 pci_set_drvdata(pdev, adapter);
5007
5008 if (adapter->flags & FW_OK) {
Dimitris Michailidis060e0c72010-08-02 13:19:21 +00005009 err = t4_port_init(adapter, func, func, 0);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005010 if (err)
5011 goto out_free_dev;
Hariprasad Shenai098ef6c2015-06-05 14:24:50 +05305012 } else if (adapter->params.nports == 1) {
5013 /* If we don't have a connection to the firmware -- possibly
5014 * because of an error -- grab the raw VPD parameters so we
5015 * can set the proper MAC Address on the debug network
5016 * interface that we've created.
5017 */
5018 u8 hw_addr[ETH_ALEN];
5019 u8 *na = adapter->params.vpd.na;
5020
5021 err = t4_get_raw_vpd_params(adapter, &adapter->params.vpd);
5022 if (!err) {
5023 for (i = 0; i < ETH_ALEN; i++)
5024 hw_addr[i] = (hex2val(na[2 * i + 0]) * 16 +
5025 hex2val(na[2 * i + 1]));
5026 t4_set_hw_addr(adapter, 0, hw_addr);
5027 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005028 }
5029
Hariprasad Shenai098ef6c2015-06-05 14:24:50 +05305030 /* Configure queues and allocate tables now, they can be needed as
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005031 * soon as the first register_netdev completes.
5032 */
5033 cfg_queues(adapter);
5034
Hariprasad Shenai5be9ed82015-07-07 21:49:18 +05305035 adapter->l2t = t4_init_l2t(adapter->l2t_start, adapter->l2t_end);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005036 if (!adapter->l2t) {
5037 /* We tolerate a lack of L2T, giving up some functionality */
5038 dev_warn(&pdev->dev, "could not allocate L2T, continuing\n");
5039 adapter->params.offload = 0;
5040 }
5041
Anish Bhattb5a02f52015-01-14 15:17:34 -08005042#if IS_ENABLED(CONFIG_IPV6)
Hariprasad Shenaieb72f742015-12-09 17:16:35 +05305043 if ((CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5) &&
5044 (!(t4_read_reg(adapter, LE_DB_CONFIG_A) & ASLIPCOMPEN_F))) {
5045 /* CLIP functionality is not present in hardware,
5046 * hence disable all offload features
Anish Bhattb5a02f52015-01-14 15:17:34 -08005047 */
5048 dev_warn(&pdev->dev,
Hariprasad Shenaieb72f742015-12-09 17:16:35 +05305049 "CLIP not enabled in hardware, continuing\n");
Anish Bhattb5a02f52015-01-14 15:17:34 -08005050 adapter->params.offload = 0;
Hariprasad Shenaieb72f742015-12-09 17:16:35 +05305051 } else {
5052 adapter->clipt = t4_init_clip_tbl(adapter->clipt_start,
5053 adapter->clipt_end);
5054 if (!adapter->clipt) {
5055 /* We tolerate a lack of clip_table, giving up
5056 * some functionality
5057 */
5058 dev_warn(&pdev->dev,
5059 "could not allocate Clip table, continuing\n");
5060 adapter->params.offload = 0;
5061 }
Anish Bhattb5a02f52015-01-14 15:17:34 -08005062 }
5063#endif
Rahul Lakkireddyb72a32d2016-08-22 16:29:06 +05305064
5065 for_each_port(adapter, i) {
5066 pi = adap2pinfo(adapter, i);
5067 pi->sched_tbl = t4_init_sched(adapter->params.nsched_cls);
5068 if (!pi->sched_tbl)
5069 dev_warn(&pdev->dev,
5070 "could not activate scheduling on port %d\n",
5071 i);
5072 }
5073
Rahul Lakkireddy578b46b2016-09-20 17:13:07 +05305074 if (tid_init(&adapter->tids) < 0) {
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005075 dev_warn(&pdev->dev, "could not allocate TID table, "
5076 "continuing\n");
5077 adapter->params.offload = 0;
Rahul Lakkireddyd8931842016-09-20 17:13:09 +05305078 } else {
Arjun V45da1ca2017-02-16 12:22:45 +05305079 adapter->tc_u32 = cxgb4_init_tc_u32(adapter);
Rahul Lakkireddyd8931842016-09-20 17:13:09 +05305080 if (!adapter->tc_u32)
5081 dev_warn(&pdev->dev,
5082 "could not offload tc u32, continuing\n");
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005083 }
5084
Hariprasad Shenai9a1bb9f2015-08-12 16:55:05 +05305085 if (is_offload(adapter)) {
5086 if (t4_read_reg(adapter, LE_DB_CONFIG_A) & HASHEN_F) {
5087 u32 hash_base, hash_reg;
5088
5089 if (chip <= CHELSIO_T5) {
5090 hash_reg = LE_DB_TID_HASHBASE_A;
5091 hash_base = t4_read_reg(adapter, hash_reg);
5092 adapter->tids.hash_base = hash_base / 4;
5093 } else {
5094 hash_reg = T6_LE_DB_HASH_TID_BASE_A;
5095 hash_base = t4_read_reg(adapter, hash_reg);
5096 adapter->tids.hash_base = hash_base;
5097 }
5098 }
5099 }
5100
Dimitris Michailidisf7cabcd2010-07-11 12:01:15 +00005101 /* See what interrupts we'll be using */
5102 if (msi > 1 && enable_msix(adapter) == 0)
5103 adapter->flags |= USING_MSIX;
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05305104 else if (msi > 0 && pci_enable_msi(pdev) == 0) {
Dimitris Michailidisf7cabcd2010-07-11 12:01:15 +00005105 adapter->flags |= USING_MSI;
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05305106 if (msi > 1)
5107 free_msix_info(adapter);
5108 }
Dimitris Michailidisf7cabcd2010-07-11 12:01:15 +00005109
Hariprasad Shenai547fd272015-12-23 11:29:53 +05305110 /* check for PCI Express bandwidth capabiltites */
5111 cxgb4_check_pcie_caps(adapter);
5112
Dimitris Michailidis671b0062010-07-11 12:01:17 +00005113 err = init_rss(adapter);
5114 if (err)
5115 goto out_free_dev;
5116
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005117 /*
5118 * The card is now ready to go. If any errors occur during device
5119 * registration we do not fail the whole card but rather proceed only
5120 * with the ports we manage to register successfully. However we must
5121 * register at least one net device.
5122 */
5123 for_each_port(adapter, i) {
Dimitris Michailidisa57cabe2010-12-14 21:36:46 +00005124 pi = adap2pinfo(adapter, i);
Arjun Vd2a007ab2016-12-08 18:09:23 +05305125 adapter->port[i]->dev_port = pi->lport;
Dimitris Michailidisa57cabe2010-12-14 21:36:46 +00005126 netif_set_real_num_tx_queues(adapter->port[i], pi->nqsets);
5127 netif_set_real_num_rx_queues(adapter->port[i], pi->nqsets);
5128
Surendra Mobiyab1a73af2017-05-30 11:32:06 +05305129 netif_carrier_off(adapter->port[i]);
5130
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005131 err = register_netdev(adapter->port[i]);
5132 if (err)
Dimitris Michailidisb1a3c2b2010-12-14 21:36:51 +00005133 break;
Dimitris Michailidisb1a3c2b2010-12-14 21:36:51 +00005134 adapter->chan_map[pi->tx_chan] = i;
5135 print_port_info(adapter->port[i]);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005136 }
Dimitris Michailidisb1a3c2b2010-12-14 21:36:51 +00005137 if (i == 0) {
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005138 dev_err(&pdev->dev, "could not register any net devices\n");
5139 goto out_free_dev;
5140 }
Dimitris Michailidisb1a3c2b2010-12-14 21:36:51 +00005141 if (err) {
5142 dev_warn(&pdev->dev, "only %d net devices registered\n", i);
5143 err = 0;
Joe Perches6403eab2011-06-03 11:51:20 +00005144 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005145
5146 if (cxgb4_debugfs_root) {
5147 adapter->debugfs_root = debugfs_create_dir(pci_name(pdev),
5148 cxgb4_debugfs_root);
5149 setup_debugfs(adapter);
5150 }
5151
David S. Miller88c51002011-10-07 13:38:43 -04005152 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
5153 pdev->needs_freset = 1;
5154
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05305155 if (is_uld(adapter)) {
5156 mutex_lock(&uld_mutex);
5157 list_add_tail(&adapter->list_node, &adapter_list);
5158 mutex_unlock(&uld_mutex);
5159 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005160
Atul Gupta9c33e422017-07-04 16:46:21 +05305161 if (!is_t4(adapter->params.chip))
5162 cxgb4_ptp_init(adapter);
5163
Hariprasad Shenai0de72732016-04-26 20:10:22 +05305164 print_adapter_info(adapter);
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05305165 setup_fw_sge_queues(adapter);
Hariprasad Shenai78294512016-08-11 21:06:23 +05305166 return 0;
Hariprasad Shenai0de72732016-04-26 20:10:22 +05305167
Hariprasad Shenai8e1e6052014-08-06 17:10:59 +05305168sriov:
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005169#ifdef CONFIG_PCI_IOV
Hariprasad Shenai78294512016-08-11 21:06:23 +05305170 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
5171 if (!adapter) {
5172 err = -ENOMEM;
5173 goto free_pci_region;
5174 }
5175
Hariprasad Shenai78294512016-08-11 21:06:23 +05305176 adapter->pdev = pdev;
5177 adapter->pdev_dev = &pdev->dev;
5178 adapter->name = pci_name(pdev);
5179 adapter->mbox = func;
5180 adapter->pf = func;
5181 adapter->regs = regs;
Hariprasad Shenaie7b48a32016-08-23 11:35:32 +05305182 adapter->adap_idx = adap_idx;
Hariprasad Shenai78294512016-08-11 21:06:23 +05305183 adapter->mbox_log = kzalloc(sizeof(*adapter->mbox_log) +
5184 (sizeof(struct mbox_cmd) *
5185 T4_OS_LOG_MBOX_CMDS),
5186 GFP_KERNEL);
5187 if (!adapter->mbox_log) {
5188 err = -ENOMEM;
Hariprasad Shenaie7b48a32016-08-23 11:35:32 +05305189 goto free_adapter;
Hariprasad Shenai78294512016-08-11 21:06:23 +05305190 }
Ganesh Goudar038c35a2017-01-12 12:23:21 +05305191 spin_lock_init(&adapter->mbox_lock);
5192 INIT_LIST_HEAD(&adapter->mlist.list);
Ganesh Goudar96fe11f2017-01-17 14:09:38 +05305193
5194 v = FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
5195 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_PORTVEC);
5196 err = t4_query_params(adapter, adapter->mbox, adapter->pf, 0, 1,
5197 &v, &port_vec);
5198 if (err < 0) {
5199 dev_err(adapter->pdev_dev, "Could not fetch port params\n");
Ganesh Goudard0417842017-06-09 19:26:24 +05305200 goto free_mbox_log;
Ganesh Goudar96fe11f2017-01-17 14:09:38 +05305201 }
5202
5203 adapter->params.nports = hweight32(port_vec);
Hariprasad Shenai78294512016-08-11 21:06:23 +05305204 pci_set_drvdata(pdev, adapter);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005205 return 0;
5206
Ganesh Goudard0417842017-06-09 19:26:24 +05305207free_mbox_log:
5208 kfree(adapter->mbox_log);
Hariprasad Shenai78294512016-08-11 21:06:23 +05305209 free_adapter:
5210 kfree(adapter);
5211 free_pci_region:
5212 iounmap(regs);
5213 pci_disable_sriov(pdev);
5214 pci_release_regions(pdev);
5215 return err;
5216#else
5217 return 0;
5218#endif
5219
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005220 out_free_dev:
Dimitris Michailidis06546392010-07-11 12:01:16 +00005221 free_some_resources(adapter);
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05305222 if (adapter->flags & USING_MSIX)
5223 free_msix_info(adapter);
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05305224 if (adapter->num_uld || adapter->num_ofld_uld)
5225 t4_uld_mem_free(adapter);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005226 out_unmap_bar:
Hariprasad Shenaid14807d2013-12-03 17:05:56 +05305227 if (!is_t4(adapter->params.chip))
Santosh Rastapur22adfe02013-03-14 05:08:51 +00005228 iounmap(adapter->bar2);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005229 out_free_adapter:
Anish Bhatt29aaee62014-08-20 13:44:06 -07005230 if (adapter->workq)
5231 destroy_workqueue(adapter->workq);
5232
Hariprasad Shenai7f080c32016-04-28 13:23:18 +05305233 kfree(adapter->mbox_log);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005234 kfree(adapter);
Hariprasad Shenaid6ce2622014-09-16 02:58:46 +05305235 out_unmap_bar0:
5236 iounmap(regs);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005237 out_disable_device:
5238 pci_disable_pcie_error_reporting(pdev);
5239 pci_disable_device(pdev);
5240 out_release_regions:
5241 pci_release_regions(pdev);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005242 return err;
5243}
5244
Bill Pemberton91744942012-12-03 09:23:02 -05005245static void remove_one(struct pci_dev *pdev)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005246{
5247 struct adapter *adapter = pci_get_drvdata(pdev);
5248
Hariprasad Shenai78294512016-08-11 21:06:23 +05305249 if (!adapter) {
5250 pci_release_regions(pdev);
5251 return;
5252 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005253
Hariprasad Shenai78294512016-08-11 21:06:23 +05305254 if (adapter->pf == 4) {
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005255 int i;
5256
Anish Bhatt29aaee62014-08-20 13:44:06 -07005257 /* Tear down per-adapter Work Queue first since it can contain
5258 * references to our adapter data structure.
5259 */
5260 destroy_workqueue(adapter->workq);
5261
Guilherme G. Piccoli6a146f32017-07-10 10:55:46 -03005262 if (is_uld(adapter)) {
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005263 detach_ulds(adapter);
Guilherme G. Piccoli6a146f32017-07-10 10:55:46 -03005264 t4_uld_clean_up(adapter);
5265 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005266
Hariprasad Shenaib37987e2015-03-26 10:04:26 +05305267 disable_interrupts(adapter);
5268
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005269 for_each_port(adapter, i)
Dimitris Michailidis8f3a7672010-12-14 21:36:52 +00005270 if (adapter->port[i]->reg_state == NETREG_REGISTERED)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005271 unregister_netdev(adapter->port[i]);
5272
Fabian Frederick9f16dc22014-06-27 22:51:52 +02005273 debugfs_remove_recursive(adapter->debugfs_root);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005274
Atul Gupta9c33e422017-07-04 16:46:21 +05305275 if (!is_t4(adapter->params.chip))
5276 cxgb4_ptp_stop(adapter);
5277
Vipul Pandyaf2b7e782012-12-10 09:30:52 +00005278 /* If we allocated filters, free up state associated with any
5279 * valid filters ...
5280 */
Rahul Lakkireddy578b46b2016-09-20 17:13:07 +05305281 clear_all_filters(adapter);
Vipul Pandyaf2b7e782012-12-10 09:30:52 +00005282
Dimitris Michailidisaaefae92010-05-18 10:07:12 +00005283 if (adapter->flags & FULL_INIT_DONE)
5284 cxgb_down(adapter);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005285
Hariprasad Shenai94cdb8b2016-08-17 12:33:03 +05305286 if (adapter->flags & USING_MSIX)
5287 free_msix_info(adapter);
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05305288 if (adapter->num_uld || adapter->num_ofld_uld)
5289 t4_uld_mem_free(adapter);
Dimitris Michailidis06546392010-07-11 12:01:16 +00005290 free_some_resources(adapter);
Anish Bhattb5a02f52015-01-14 15:17:34 -08005291#if IS_ENABLED(CONFIG_IPV6)
5292 t4_cleanup_clip_tbl(adapter);
5293#endif
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005294 iounmap(adapter->regs);
Hariprasad Shenaid14807d2013-12-03 17:05:56 +05305295 if (!is_t4(adapter->params.chip))
Santosh Rastapur22adfe02013-03-14 05:08:51 +00005296 iounmap(adapter->bar2);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005297 pci_disable_pcie_error_reporting(pdev);
Gavin Shan144be3d2014-01-23 12:27:34 +08005298 if ((adapter->flags & DEV_ENABLED)) {
5299 pci_disable_device(pdev);
5300 adapter->flags &= ~DEV_ENABLED;
5301 }
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005302 pci_release_regions(pdev);
Hariprasad Shenai7f080c32016-04-28 13:23:18 +05305303 kfree(adapter->mbox_log);
Li RongQingee9a33b2014-06-20 17:32:36 +08005304 synchronize_rcu();
Gavin Shan8b662fe2014-01-24 17:12:03 +08005305 kfree(adapter);
Hariprasad Shenai78294512016-08-11 21:06:23 +05305306 }
5307#ifdef CONFIG_PCI_IOV
5308 else {
Hariprasad Shenaie7b48a32016-08-23 11:35:32 +05305309 if (adapter->port[0])
Hariprasad Shenai78294512016-08-11 21:06:23 +05305310 unregister_netdev(adapter->port[0]);
Hariprasad Shenai78294512016-08-11 21:06:23 +05305311 iounmap(adapter->regs);
Hariprasad Shenai661dbeb2016-09-02 19:13:53 +05305312 kfree(adapter->vfinfo);
Ganesh Goudard0417842017-06-09 19:26:24 +05305313 kfree(adapter->mbox_log);
Hariprasad Shenai78294512016-08-11 21:06:23 +05305314 kfree(adapter);
5315 pci_disable_sriov(pdev);
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005316 pci_release_regions(pdev);
Hariprasad Shenai78294512016-08-11 21:06:23 +05305317 }
5318#endif
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005319}
5320
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05305321/* "Shutdown" quiesces the device, stopping Ingress Packet and Interrupt
5322 * delivery. This is essentially a stripped down version of the PCI remove()
5323 * function where we do the minimal amount of work necessary to shutdown any
5324 * further activity.
5325 */
5326static void shutdown_one(struct pci_dev *pdev)
5327{
5328 struct adapter *adapter = pci_get_drvdata(pdev);
5329
5330 /* As with remove_one() above (see extended comment), we only want do
5331 * do cleanup on PCI Devices which went all the way through init_one()
5332 * ...
5333 */
5334 if (!adapter) {
5335 pci_release_regions(pdev);
5336 return;
5337 }
5338
5339 if (adapter->pf == 4) {
5340 int i;
5341
5342 for_each_port(adapter, i)
5343 if (adapter->port[i]->reg_state == NETREG_REGISTERED)
5344 cxgb_close(adapter->port[i]);
5345
Guilherme G. Piccoli6a146f32017-07-10 10:55:46 -03005346 if (is_uld(adapter)) {
5347 detach_ulds(adapter);
5348 t4_uld_clean_up(adapter);
5349 }
5350
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05305351 disable_interrupts(adapter);
5352 disable_msi(adapter);
5353
5354 t4_sge_stop(adapter);
5355 if (adapter->flags & FW_OK)
5356 t4_fw_bye(adapter, adapter->mbox);
5357 }
5358#ifdef CONFIG_PCI_IOV
5359 else {
5360 if (adapter->port[0])
5361 unregister_netdev(adapter->port[0]);
5362 iounmap(adapter->regs);
5363 kfree(adapter->vfinfo);
Ganesh Goudard0417842017-06-09 19:26:24 +05305364 kfree(adapter->mbox_log);
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05305365 kfree(adapter);
5366 pci_disable_sriov(pdev);
5367 pci_release_regions(pdev);
5368 }
5369#endif
5370}
5371
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005372static struct pci_driver cxgb4_driver = {
5373 .name = KBUILD_MODNAME,
5374 .id_table = cxgb4_pci_tbl,
5375 .probe = init_one,
Bill Pemberton91744942012-12-03 09:23:02 -05005376 .remove = remove_one,
Hariprasad Shenai0fbc81b2016-09-17 08:12:39 +05305377 .shutdown = shutdown_one,
Hariprasad Shenaib6244202016-06-14 14:39:31 +05305378#ifdef CONFIG_PCI_IOV
5379 .sriov_configure = cxgb4_iov_configure,
5380#endif
Dimitris Michailidis204dc3c2010-06-18 10:05:29 +00005381 .err_handler = &cxgb4_eeh,
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005382};
5383
5384static int __init cxgb4_init_module(void)
5385{
5386 int ret;
5387
5388 /* Debugfs support is optional, just warn if this fails */
5389 cxgb4_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
5390 if (!cxgb4_debugfs_root)
Joe Perches428ac432013-01-06 13:34:49 +00005391 pr_warn("could not create debugfs entry, continuing\n");
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005392
5393 ret = pci_register_driver(&cxgb4_driver);
Anish Bhatt29aaee62014-08-20 13:44:06 -07005394 if (ret < 0)
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005395 debugfs_remove(cxgb4_debugfs_root);
Vipul Pandya01bcca62013-07-04 16:10:46 +05305396
Anish Bhatt1bb60372014-10-14 20:07:22 -07005397#if IS_ENABLED(CONFIG_IPV6)
Anish Bhattb5a02f52015-01-14 15:17:34 -08005398 if (!inet6addr_registered) {
5399 register_inet6addr_notifier(&cxgb4_inet6addr_notifier);
5400 inet6addr_registered = true;
5401 }
Anish Bhatt1bb60372014-10-14 20:07:22 -07005402#endif
Vipul Pandya01bcca62013-07-04 16:10:46 +05305403
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005404 return ret;
5405}
5406
5407static void __exit cxgb4_cleanup_module(void)
5408{
Anish Bhatt1bb60372014-10-14 20:07:22 -07005409#if IS_ENABLED(CONFIG_IPV6)
Hariprasad Shenai1793c792015-01-21 20:57:52 +05305410 if (inet6addr_registered) {
Anish Bhattb5a02f52015-01-14 15:17:34 -08005411 unregister_inet6addr_notifier(&cxgb4_inet6addr_notifier);
5412 inet6addr_registered = false;
5413 }
Anish Bhatt1bb60372014-10-14 20:07:22 -07005414#endif
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005415 pci_unregister_driver(&cxgb4_driver);
5416 debugfs_remove(cxgb4_debugfs_root); /* NULL ok */
Dimitris Michailidisb8ff05a2010-04-01 15:28:26 +00005417}
5418
5419module_init(cxgb4_init_module);
5420module_exit(cxgb4_cleanup_module);