xref: /dpdk/drivers/net/cxgbe/cxgbe_main.c (revision 64a46f14f616ff83da9ebfa8ab1c93e62dc99dd5)
12aa5c722SRahul Lakkireddy /* SPDX-License-Identifier: BSD-3-Clause
22aa5c722SRahul Lakkireddy  * Copyright(c) 2014-2018 Chelsio Communications.
383189849SRahul Lakkireddy  * All rights reserved.
483189849SRahul Lakkireddy  */
583189849SRahul Lakkireddy 
683189849SRahul Lakkireddy #include <sys/queue.h>
783189849SRahul Lakkireddy #include <stdio.h>
883189849SRahul Lakkireddy #include <errno.h>
983189849SRahul Lakkireddy #include <stdint.h>
1083189849SRahul Lakkireddy #include <string.h>
1183189849SRahul Lakkireddy #include <unistd.h>
1283189849SRahul Lakkireddy #include <stdarg.h>
1383189849SRahul Lakkireddy #include <inttypes.h>
1483189849SRahul Lakkireddy #include <netinet/in.h>
1583189849SRahul Lakkireddy 
1683189849SRahul Lakkireddy #include <rte_byteorder.h>
1783189849SRahul Lakkireddy #include <rte_common.h>
1883189849SRahul Lakkireddy #include <rte_cycles.h>
1983189849SRahul Lakkireddy #include <rte_interrupts.h>
2083189849SRahul Lakkireddy #include <rte_log.h>
2183189849SRahul Lakkireddy #include <rte_debug.h>
2283189849SRahul Lakkireddy #include <rte_pci.h>
2383189849SRahul Lakkireddy #include <rte_atomic.h>
2483189849SRahul Lakkireddy #include <rte_branch_prediction.h>
2583189849SRahul Lakkireddy #include <rte_memory.h>
2683189849SRahul Lakkireddy #include <rte_tailq.h>
2783189849SRahul Lakkireddy #include <rte_eal.h>
2883189849SRahul Lakkireddy #include <rte_alarm.h>
2983189849SRahul Lakkireddy #include <rte_ether.h>
30ffc905f3SFerruh Yigit #include <rte_ethdev_driver.h>
317d012402SJan Blunck #include <rte_ethdev_pci.h>
3283189849SRahul Lakkireddy #include <rte_random.h>
3383189849SRahul Lakkireddy #include <rte_dev.h>
34cda260a4SShagun Agrawal #include <rte_kvargs.h>
3583189849SRahul Lakkireddy 
3689c8bd95SRahul Lakkireddy #include "base/common.h"
3789c8bd95SRahul Lakkireddy #include "base/t4_regs.h"
3889c8bd95SRahul Lakkireddy #include "base/t4_msg.h"
3983189849SRahul Lakkireddy #include "cxgbe.h"
403f2c1e20SShagun Agrawal #include "clip_tbl.h"
4123af667fSShagun Agrawal #include "l2t.h"
426fda3f0dSShagun Agrawal #include "mps_tcam.h"
4383189849SRahul Lakkireddy 
446f2a064bSShagun Agrawal /**
456f2a064bSShagun Agrawal  * Allocate a chunk of memory. The allocated memory is cleared.
466f2a064bSShagun Agrawal  */
476f2a064bSShagun Agrawal void *t4_alloc_mem(size_t size)
486f2a064bSShagun Agrawal {
496f2a064bSShagun Agrawal 	return rte_zmalloc(NULL, size, 0);
506f2a064bSShagun Agrawal }
516f2a064bSShagun Agrawal 
526f2a064bSShagun Agrawal /**
536f2a064bSShagun Agrawal  * Free memory allocated through t4_alloc_mem().
546f2a064bSShagun Agrawal  */
556f2a064bSShagun Agrawal void t4_free_mem(void *addr)
566f2a064bSShagun Agrawal {
576f2a064bSShagun Agrawal 	rte_free(addr);
586f2a064bSShagun Agrawal }
596f2a064bSShagun Agrawal 
6092c8a632SRahul Lakkireddy /*
6192c8a632SRahul Lakkireddy  * Response queue handler for the FW event queue.
6292c8a632SRahul Lakkireddy  */
6392c8a632SRahul Lakkireddy static int fwevtq_handler(struct sge_rspq *q, const __be64 *rsp,
6492c8a632SRahul Lakkireddy 			  __rte_unused const struct pkt_gl *gl)
6592c8a632SRahul Lakkireddy {
6692c8a632SRahul Lakkireddy 	u8 opcode = ((const struct rss_header *)rsp)->opcode;
6792c8a632SRahul Lakkireddy 
6892c8a632SRahul Lakkireddy 	rsp++;                                          /* skip RSS header */
6992c8a632SRahul Lakkireddy 
7092c8a632SRahul Lakkireddy 	/*
7192c8a632SRahul Lakkireddy 	 * FW can send EGR_UPDATEs encapsulated in a CPL_FW4_MSG.
7292c8a632SRahul Lakkireddy 	 */
7392c8a632SRahul Lakkireddy 	if (unlikely(opcode == CPL_FW4_MSG &&
7492c8a632SRahul Lakkireddy 		     ((const struct cpl_fw4_msg *)rsp)->type ==
7592c8a632SRahul Lakkireddy 		      FW_TYPE_RSSCPL)) {
7692c8a632SRahul Lakkireddy 		rsp++;
7792c8a632SRahul Lakkireddy 		opcode = ((const struct rss_header *)rsp)->opcode;
7892c8a632SRahul Lakkireddy 		rsp++;
7992c8a632SRahul Lakkireddy 		if (opcode != CPL_SGE_EGR_UPDATE) {
8092c8a632SRahul Lakkireddy 			dev_err(q->adapter, "unexpected FW4/CPL %#x on FW event queue\n",
8192c8a632SRahul Lakkireddy 				opcode);
8292c8a632SRahul Lakkireddy 			goto out;
8392c8a632SRahul Lakkireddy 		}
8492c8a632SRahul Lakkireddy 	}
8592c8a632SRahul Lakkireddy 
8692c8a632SRahul Lakkireddy 	if (likely(opcode == CPL_SGE_EGR_UPDATE)) {
8792c8a632SRahul Lakkireddy 		/* do nothing */
8892c8a632SRahul Lakkireddy 	} else if (opcode == CPL_FW6_MSG || opcode == CPL_FW4_MSG) {
8992c8a632SRahul Lakkireddy 		const struct cpl_fw6_msg *msg = (const void *)rsp;
9092c8a632SRahul Lakkireddy 
9192c8a632SRahul Lakkireddy 		t4_handle_fw_rpl(q->adapter, msg->data);
9241dc98b0SShagun Agrawal 	} else if (opcode == CPL_ABORT_RPL_RSS) {
9341dc98b0SShagun Agrawal 		const struct cpl_abort_rpl_rss *p = (const void *)rsp;
9441dc98b0SShagun Agrawal 
9541dc98b0SShagun Agrawal 		hash_del_filter_rpl(q->adapter, p);
969eb2c9a4SShagun Agrawal 	} else if (opcode == CPL_SET_TCB_RPL) {
979eb2c9a4SShagun Agrawal 		const struct cpl_set_tcb_rpl *p = (const void *)rsp;
989eb2c9a4SShagun Agrawal 
999eb2c9a4SShagun Agrawal 		filter_rpl(q->adapter, p);
100af44a577SShagun Agrawal 	} else if (opcode == CPL_ACT_OPEN_RPL) {
101af44a577SShagun Agrawal 		const struct cpl_act_open_rpl *p = (const void *)rsp;
102af44a577SShagun Agrawal 
103af44a577SShagun Agrawal 		hash_filter_rpl(q->adapter, p);
10423af667fSShagun Agrawal 	} else if (opcode == CPL_L2T_WRITE_RPL) {
10523af667fSShagun Agrawal 		const struct cpl_l2t_write_rpl *p = (const void *)rsp;
10623af667fSShagun Agrawal 
10723af667fSShagun Agrawal 		do_l2t_write_rpl(q->adapter, p);
10892c8a632SRahul Lakkireddy 	} else {
10992c8a632SRahul Lakkireddy 		dev_err(adapter, "unexpected CPL %#x on FW event queue\n",
11092c8a632SRahul Lakkireddy 			opcode);
11192c8a632SRahul Lakkireddy 	}
11292c8a632SRahul Lakkireddy out:
11392c8a632SRahul Lakkireddy 	return 0;
11492c8a632SRahul Lakkireddy }
11592c8a632SRahul Lakkireddy 
1163a3aaabcSShagun Agrawal /**
1173a3aaabcSShagun Agrawal  * Setup sge control queues to pass control information.
1183a3aaabcSShagun Agrawal  */
119b7fd9ea8SStephen Hemminger int cxgbe_setup_sge_ctrl_txq(struct adapter *adapter)
1203a3aaabcSShagun Agrawal {
1213a3aaabcSShagun Agrawal 	struct sge *s = &adapter->sge;
1223a3aaabcSShagun Agrawal 	int err = 0, i = 0;
1233a3aaabcSShagun Agrawal 
1243a3aaabcSShagun Agrawal 	for_each_port(adapter, i) {
12546df488bSRahul Lakkireddy 		struct port_info *pi = adap2pinfo(adapter, i);
1263a3aaabcSShagun Agrawal 		char name[RTE_ETH_NAME_MAX_LEN];
1273a3aaabcSShagun Agrawal 		struct sge_ctrl_txq *q = &s->ctrlq[i];
1283a3aaabcSShagun Agrawal 
1293a3aaabcSShagun Agrawal 		q->q.size = 1024;
1303a3aaabcSShagun Agrawal 		err = t4_sge_alloc_ctrl_txq(adapter, q,
1313a3aaabcSShagun Agrawal 					    adapter->eth_dev,  i,
1323a3aaabcSShagun Agrawal 					    s->fw_evtq.cntxt_id,
1333a3aaabcSShagun Agrawal 					    rte_socket_id());
1343a3aaabcSShagun Agrawal 		if (err) {
1353a3aaabcSShagun Agrawal 			dev_err(adapter, "Failed to alloc ctrl txq. Err: %d",
1363a3aaabcSShagun Agrawal 				err);
1373a3aaabcSShagun Agrawal 			goto out;
1383a3aaabcSShagun Agrawal 		}
13946df488bSRahul Lakkireddy 		snprintf(name, sizeof(name), "%s_ctrl_pool_%d",
14046df488bSRahul Lakkireddy 			 pi->eth_dev->device->driver->name,
14146df488bSRahul Lakkireddy 			 pi->eth_dev->data->port_id);
1423a3aaabcSShagun Agrawal 		q->mb_pool = rte_pktmbuf_pool_create(name, s->ctrlq[i].q.size,
1433a3aaabcSShagun Agrawal 						     RTE_CACHE_LINE_SIZE,
1443a3aaabcSShagun Agrawal 						     RTE_MBUF_PRIV_ALIGN,
1453a3aaabcSShagun Agrawal 						     RTE_MBUF_DEFAULT_BUF_SIZE,
1463a3aaabcSShagun Agrawal 						     SOCKET_ID_ANY);
1473a3aaabcSShagun Agrawal 		if (!q->mb_pool) {
14846df488bSRahul Lakkireddy 			err = -rte_errno;
14946df488bSRahul Lakkireddy 			dev_err(adapter,
15046df488bSRahul Lakkireddy 				"Can't create ctrl pool for port %d. Err: %d\n",
15146df488bSRahul Lakkireddy 				pi->eth_dev->data->port_id, err);
1523a3aaabcSShagun Agrawal 			goto out;
1533a3aaabcSShagun Agrawal 		}
1543a3aaabcSShagun Agrawal 	}
1553a3aaabcSShagun Agrawal 	return 0;
1563a3aaabcSShagun Agrawal out:
1573a3aaabcSShagun Agrawal 	t4_free_sge_resources(adapter);
1583a3aaabcSShagun Agrawal 	return err;
1593a3aaabcSShagun Agrawal }
1603a3aaabcSShagun Agrawal 
1619eb2c9a4SShagun Agrawal /**
1629eb2c9a4SShagun Agrawal  * cxgbe_poll_for_completion: Poll rxq for completion
1639eb2c9a4SShagun Agrawal  * @q: rxq to poll
164f1e9d2afSRahul Lakkireddy  * @ms: milliseconds to delay
1659eb2c9a4SShagun Agrawal  * @cnt: number of times to poll
1669eb2c9a4SShagun Agrawal  * @c: completion to check for 'done' status
1679eb2c9a4SShagun Agrawal  *
1689eb2c9a4SShagun Agrawal  * Polls the rxq for reples until completion is done or the count
1699eb2c9a4SShagun Agrawal  * expires.
1709eb2c9a4SShagun Agrawal  */
171f1e9d2afSRahul Lakkireddy int cxgbe_poll_for_completion(struct sge_rspq *q, unsigned int ms,
1729eb2c9a4SShagun Agrawal 			      unsigned int cnt, struct t4_completion *c)
1739eb2c9a4SShagun Agrawal {
1749eb2c9a4SShagun Agrawal 	unsigned int i;
175f1e9d2afSRahul Lakkireddy 	unsigned int work_done, budget = 32;
1769eb2c9a4SShagun Agrawal 
1779eb2c9a4SShagun Agrawal 	if (!c)
1789eb2c9a4SShagun Agrawal 		return -EINVAL;
1799eb2c9a4SShagun Agrawal 
1809eb2c9a4SShagun Agrawal 	for (i = 0; i < cnt; i++) {
1819eb2c9a4SShagun Agrawal 		cxgbe_poll(q, NULL, budget, &work_done);
1829eb2c9a4SShagun Agrawal 		t4_os_lock(&c->lock);
1839eb2c9a4SShagun Agrawal 		if (c->done) {
1849eb2c9a4SShagun Agrawal 			t4_os_unlock(&c->lock);
1859eb2c9a4SShagun Agrawal 			return 0;
1869eb2c9a4SShagun Agrawal 		}
1879eb2c9a4SShagun Agrawal 		t4_os_unlock(&c->lock);
188f1e9d2afSRahul Lakkireddy 		rte_delay_ms(ms);
1899eb2c9a4SShagun Agrawal 	}
1909eb2c9a4SShagun Agrawal 	return -ETIMEDOUT;
1919eb2c9a4SShagun Agrawal }
1929eb2c9a4SShagun Agrawal 
193b7fd9ea8SStephen Hemminger int cxgbe_setup_sge_fwevtq(struct adapter *adapter)
19492c8a632SRahul Lakkireddy {
19592c8a632SRahul Lakkireddy 	struct sge *s = &adapter->sge;
19692c8a632SRahul Lakkireddy 	int err = 0;
19792c8a632SRahul Lakkireddy 	int msi_idx = 0;
19892c8a632SRahul Lakkireddy 
19992c8a632SRahul Lakkireddy 	err = t4_sge_alloc_rxq(adapter, &s->fw_evtq, true, adapter->eth_dev,
20092c8a632SRahul Lakkireddy 			       msi_idx, NULL, fwevtq_handler, -1, NULL, 0,
20192c8a632SRahul Lakkireddy 			       rte_socket_id());
20292c8a632SRahul Lakkireddy 	return err;
20392c8a632SRahul Lakkireddy }
20492c8a632SRahul Lakkireddy 
20592c8a632SRahul Lakkireddy static int closest_timer(const struct sge *s, int time)
20692c8a632SRahul Lakkireddy {
20792c8a632SRahul Lakkireddy 	unsigned int i, match = 0;
20892c8a632SRahul Lakkireddy 	int delta, min_delta = INT_MAX;
20992c8a632SRahul Lakkireddy 
21092c8a632SRahul Lakkireddy 	for (i = 0; i < ARRAY_SIZE(s->timer_val); i++) {
21192c8a632SRahul Lakkireddy 		delta = time - s->timer_val[i];
21292c8a632SRahul Lakkireddy 		if (delta < 0)
21392c8a632SRahul Lakkireddy 			delta = -delta;
21492c8a632SRahul Lakkireddy 		if (delta < min_delta) {
21592c8a632SRahul Lakkireddy 			min_delta = delta;
21692c8a632SRahul Lakkireddy 			match = i;
21792c8a632SRahul Lakkireddy 		}
21892c8a632SRahul Lakkireddy 	}
21992c8a632SRahul Lakkireddy 	return match;
22092c8a632SRahul Lakkireddy }
22192c8a632SRahul Lakkireddy 
22292c8a632SRahul Lakkireddy static int closest_thres(const struct sge *s, int thres)
22392c8a632SRahul Lakkireddy {
22492c8a632SRahul Lakkireddy 	unsigned int i, match = 0;
22592c8a632SRahul Lakkireddy 	int delta, min_delta = INT_MAX;
22692c8a632SRahul Lakkireddy 
22792c8a632SRahul Lakkireddy 	for (i = 0; i < ARRAY_SIZE(s->counter_val); i++) {
22892c8a632SRahul Lakkireddy 		delta = thres - s->counter_val[i];
22992c8a632SRahul Lakkireddy 		if (delta < 0)
23092c8a632SRahul Lakkireddy 			delta = -delta;
23192c8a632SRahul Lakkireddy 		if (delta < min_delta) {
23292c8a632SRahul Lakkireddy 			min_delta = delta;
23392c8a632SRahul Lakkireddy 			match = i;
23492c8a632SRahul Lakkireddy 		}
23592c8a632SRahul Lakkireddy 	}
23692c8a632SRahul Lakkireddy 	return match;
23792c8a632SRahul Lakkireddy }
23892c8a632SRahul Lakkireddy 
23992c8a632SRahul Lakkireddy /**
24092c8a632SRahul Lakkireddy  * cxgb4_set_rspq_intr_params - set a queue's interrupt holdoff parameters
24192c8a632SRahul Lakkireddy  * @q: the Rx queue
24292c8a632SRahul Lakkireddy  * @us: the hold-off time in us, or 0 to disable timer
24392c8a632SRahul Lakkireddy  * @cnt: the hold-off packet count, or 0 to disable counter
24492c8a632SRahul Lakkireddy  *
24592c8a632SRahul Lakkireddy  * Sets an Rx queue's interrupt hold-off time and packet count.  At least
24692c8a632SRahul Lakkireddy  * one of the two needs to be enabled for the queue to generate interrupts.
24792c8a632SRahul Lakkireddy  */
24892c8a632SRahul Lakkireddy int cxgb4_set_rspq_intr_params(struct sge_rspq *q, unsigned int us,
24992c8a632SRahul Lakkireddy 			       unsigned int cnt)
25092c8a632SRahul Lakkireddy {
25192c8a632SRahul Lakkireddy 	struct adapter *adap = q->adapter;
25292c8a632SRahul Lakkireddy 	unsigned int timer_val;
25392c8a632SRahul Lakkireddy 
25492c8a632SRahul Lakkireddy 	if (cnt) {
25592c8a632SRahul Lakkireddy 		int err;
25692c8a632SRahul Lakkireddy 		u32 v, new_idx;
25792c8a632SRahul Lakkireddy 
25892c8a632SRahul Lakkireddy 		new_idx = closest_thres(&adap->sge, cnt);
25992c8a632SRahul Lakkireddy 		if (q->desc && q->pktcnt_idx != new_idx) {
26092c8a632SRahul Lakkireddy 			/* the queue has already been created, update it */
26192c8a632SRahul Lakkireddy 			v = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DMAQ) |
26292c8a632SRahul Lakkireddy 			    V_FW_PARAMS_PARAM_X(
26392c8a632SRahul Lakkireddy 			    FW_PARAMS_PARAM_DMAQ_IQ_INTCNTTHRESH) |
26492c8a632SRahul Lakkireddy 			    V_FW_PARAMS_PARAM_YZ(q->cntxt_id);
26592c8a632SRahul Lakkireddy 			err = t4_set_params(adap, adap->mbox, adap->pf, 0, 1,
26692c8a632SRahul Lakkireddy 					    &v, &new_idx);
26792c8a632SRahul Lakkireddy 			if (err)
26892c8a632SRahul Lakkireddy 				return err;
26992c8a632SRahul Lakkireddy 		}
27092c8a632SRahul Lakkireddy 		q->pktcnt_idx = new_idx;
27192c8a632SRahul Lakkireddy 	}
27292c8a632SRahul Lakkireddy 
27392c8a632SRahul Lakkireddy 	timer_val = (us == 0) ? X_TIMERREG_RESTART_COUNTER :
27492c8a632SRahul Lakkireddy 				closest_timer(&adap->sge, us);
27592c8a632SRahul Lakkireddy 
27692c8a632SRahul Lakkireddy 	if ((us | cnt) == 0)
27792c8a632SRahul Lakkireddy 		q->intr_params = V_QINTR_TIMER_IDX(X_TIMERREG_UPDATE_CIDX);
27892c8a632SRahul Lakkireddy 	else
27992c8a632SRahul Lakkireddy 		q->intr_params = V_QINTR_TIMER_IDX(timer_val) |
28092c8a632SRahul Lakkireddy 				 V_QINTR_CNT_EN(cnt > 0);
28192c8a632SRahul Lakkireddy 	return 0;
28292c8a632SRahul Lakkireddy }
28392c8a632SRahul Lakkireddy 
2846f2a064bSShagun Agrawal /**
285af44a577SShagun Agrawal  * Allocate an active-open TID and set it to the supplied value.
286af44a577SShagun Agrawal  */
287af44a577SShagun Agrawal int cxgbe_alloc_atid(struct tid_info *t, void *data)
288af44a577SShagun Agrawal {
289af44a577SShagun Agrawal 	int atid = -1;
290af44a577SShagun Agrawal 
291af44a577SShagun Agrawal 	t4_os_lock(&t->atid_lock);
292af44a577SShagun Agrawal 	if (t->afree) {
293af44a577SShagun Agrawal 		union aopen_entry *p = t->afree;
294af44a577SShagun Agrawal 
295af44a577SShagun Agrawal 		atid = p - t->atid_tab;
296af44a577SShagun Agrawal 		t->afree = p->next;
297af44a577SShagun Agrawal 		p->data = data;
298af44a577SShagun Agrawal 		t->atids_in_use++;
299af44a577SShagun Agrawal 	}
300af44a577SShagun Agrawal 	t4_os_unlock(&t->atid_lock);
301af44a577SShagun Agrawal 	return atid;
302af44a577SShagun Agrawal }
303af44a577SShagun Agrawal 
304af44a577SShagun Agrawal /**
305af44a577SShagun Agrawal  * Release an active-open TID.
306af44a577SShagun Agrawal  */
307af44a577SShagun Agrawal void cxgbe_free_atid(struct tid_info *t, unsigned int atid)
308af44a577SShagun Agrawal {
309af44a577SShagun Agrawal 	union aopen_entry *p = &t->atid_tab[atid];
310af44a577SShagun Agrawal 
311af44a577SShagun Agrawal 	t4_os_lock(&t->atid_lock);
312af44a577SShagun Agrawal 	p->next = t->afree;
313af44a577SShagun Agrawal 	t->afree = p;
314af44a577SShagun Agrawal 	t->atids_in_use--;
315af44a577SShagun Agrawal 	t4_os_unlock(&t->atid_lock);
316af44a577SShagun Agrawal }
317af44a577SShagun Agrawal 
318af44a577SShagun Agrawal /**
31941dc98b0SShagun Agrawal  * Populate a TID_RELEASE WR.  Caller must properly size the skb.
32041dc98b0SShagun Agrawal  */
32141dc98b0SShagun Agrawal static void mk_tid_release(struct rte_mbuf *mbuf, unsigned int tid)
32241dc98b0SShagun Agrawal {
32341dc98b0SShagun Agrawal 	struct cpl_tid_release *req;
32441dc98b0SShagun Agrawal 
32541dc98b0SShagun Agrawal 	req = rte_pktmbuf_mtod(mbuf, struct cpl_tid_release *);
32641dc98b0SShagun Agrawal 	INIT_TP_WR_MIT_CPL(req, CPL_TID_RELEASE, tid);
32741dc98b0SShagun Agrawal }
32841dc98b0SShagun Agrawal 
32941dc98b0SShagun Agrawal /**
33041dc98b0SShagun Agrawal  * Release a TID and inform HW.  If we are unable to allocate the release
33141dc98b0SShagun Agrawal  * message we defer to a work queue.
33241dc98b0SShagun Agrawal  */
33341dc98b0SShagun Agrawal void cxgbe_remove_tid(struct tid_info *t, unsigned int chan, unsigned int tid,
33441dc98b0SShagun Agrawal 		      unsigned short family)
33541dc98b0SShagun Agrawal {
33641dc98b0SShagun Agrawal 	struct rte_mbuf *mbuf;
33741dc98b0SShagun Agrawal 	struct adapter *adap = container_of(t, struct adapter, tids);
33841dc98b0SShagun Agrawal 
33941dc98b0SShagun Agrawal 	WARN_ON(tid >= t->ntids);
34041dc98b0SShagun Agrawal 
34141dc98b0SShagun Agrawal 	if (t->tid_tab[tid]) {
34241dc98b0SShagun Agrawal 		t->tid_tab[tid] = NULL;
34341dc98b0SShagun Agrawal 		rte_atomic32_dec(&t->conns_in_use);
34441dc98b0SShagun Agrawal 		if (t->hash_base && tid >= t->hash_base) {
34541dc98b0SShagun Agrawal 			if (family == FILTER_TYPE_IPV4)
34641dc98b0SShagun Agrawal 				rte_atomic32_dec(&t->hash_tids_in_use);
34741dc98b0SShagun Agrawal 		} else {
34841dc98b0SShagun Agrawal 			if (family == FILTER_TYPE_IPV4)
34941dc98b0SShagun Agrawal 				rte_atomic32_dec(&t->tids_in_use);
35041dc98b0SShagun Agrawal 		}
35141dc98b0SShagun Agrawal 	}
35241dc98b0SShagun Agrawal 
35341dc98b0SShagun Agrawal 	mbuf = rte_pktmbuf_alloc((&adap->sge.ctrlq[chan])->mb_pool);
35441dc98b0SShagun Agrawal 	if (mbuf) {
35541dc98b0SShagun Agrawal 		mbuf->data_len = sizeof(struct cpl_tid_release);
35641dc98b0SShagun Agrawal 		mbuf->pkt_len = mbuf->data_len;
35741dc98b0SShagun Agrawal 		mk_tid_release(mbuf, tid);
35841dc98b0SShagun Agrawal 		t4_mgmt_tx(&adap->sge.ctrlq[chan], mbuf);
35941dc98b0SShagun Agrawal 	}
36041dc98b0SShagun Agrawal }
36141dc98b0SShagun Agrawal 
36241dc98b0SShagun Agrawal /**
363af44a577SShagun Agrawal  * Insert a TID.
364af44a577SShagun Agrawal  */
365af44a577SShagun Agrawal void cxgbe_insert_tid(struct tid_info *t, void *data, unsigned int tid,
366af44a577SShagun Agrawal 		      unsigned short family)
367af44a577SShagun Agrawal {
368af44a577SShagun Agrawal 	t->tid_tab[tid] = data;
369af44a577SShagun Agrawal 	if (t->hash_base && tid >= t->hash_base) {
370af44a577SShagun Agrawal 		if (family == FILTER_TYPE_IPV4)
371af44a577SShagun Agrawal 			rte_atomic32_inc(&t->hash_tids_in_use);
372af44a577SShagun Agrawal 	} else {
373af44a577SShagun Agrawal 		if (family == FILTER_TYPE_IPV4)
374af44a577SShagun Agrawal 			rte_atomic32_inc(&t->tids_in_use);
375af44a577SShagun Agrawal 	}
376af44a577SShagun Agrawal 
377af44a577SShagun Agrawal 	rte_atomic32_inc(&t->conns_in_use);
378af44a577SShagun Agrawal }
379af44a577SShagun Agrawal 
380af44a577SShagun Agrawal /**
3816f2a064bSShagun Agrawal  * Free TID tables.
3826f2a064bSShagun Agrawal  */
3836f2a064bSShagun Agrawal static void tid_free(struct tid_info *t)
3846f2a064bSShagun Agrawal {
3856f2a064bSShagun Agrawal 	if (t->tid_tab) {
3866f2a064bSShagun Agrawal 		if (t->ftid_bmap)
3876f2a064bSShagun Agrawal 			rte_bitmap_free(t->ftid_bmap);
3886f2a064bSShagun Agrawal 
3896f2a064bSShagun Agrawal 		if (t->ftid_bmap_array)
3906f2a064bSShagun Agrawal 			t4_os_free(t->ftid_bmap_array);
3916f2a064bSShagun Agrawal 
3926f2a064bSShagun Agrawal 		t4_os_free(t->tid_tab);
3936f2a064bSShagun Agrawal 	}
3946f2a064bSShagun Agrawal 
3956f2a064bSShagun Agrawal 	memset(t, 0, sizeof(struct tid_info));
3966f2a064bSShagun Agrawal }
3976f2a064bSShagun Agrawal 
3986f2a064bSShagun Agrawal /**
3996f2a064bSShagun Agrawal  * Allocate and initialize the TID tables.  Returns 0 on success.
4006f2a064bSShagun Agrawal  */
4016f2a064bSShagun Agrawal static int tid_init(struct tid_info *t)
4026f2a064bSShagun Agrawal {
4036f2a064bSShagun Agrawal 	size_t size;
4046f2a064bSShagun Agrawal 	unsigned int ftid_bmap_size;
4053a381a41SShagun Agrawal 	unsigned int natids = t->natids;
4066f2a064bSShagun Agrawal 	unsigned int max_ftids = t->nftids;
4076f2a064bSShagun Agrawal 
4086f2a064bSShagun Agrawal 	ftid_bmap_size = rte_bitmap_get_memory_footprint(t->nftids);
4096f2a064bSShagun Agrawal 	size = t->ntids * sizeof(*t->tid_tab) +
4103a381a41SShagun Agrawal 		max_ftids * sizeof(*t->ftid_tab) +
4113a381a41SShagun Agrawal 		natids * sizeof(*t->atid_tab);
4126f2a064bSShagun Agrawal 
4136f2a064bSShagun Agrawal 	t->tid_tab = t4_os_alloc(size);
4146f2a064bSShagun Agrawal 	if (!t->tid_tab)
4156f2a064bSShagun Agrawal 		return -ENOMEM;
4166f2a064bSShagun Agrawal 
4173a381a41SShagun Agrawal 	t->atid_tab = (union aopen_entry *)&t->tid_tab[t->ntids];
41827288219SRahul Lakkireddy 	t->ftid_tab = (struct filter_entry *)&t->atid_tab[t->natids];
4196f2a064bSShagun Agrawal 	t->ftid_bmap_array = t4_os_alloc(ftid_bmap_size);
4206f2a064bSShagun Agrawal 	if (!t->ftid_bmap_array) {
4216f2a064bSShagun Agrawal 		tid_free(t);
4226f2a064bSShagun Agrawal 		return -ENOMEM;
4236f2a064bSShagun Agrawal 	}
4246f2a064bSShagun Agrawal 
4253a381a41SShagun Agrawal 	t4_os_lock_init(&t->atid_lock);
4266f2a064bSShagun Agrawal 	t4_os_lock_init(&t->ftid_lock);
4273a381a41SShagun Agrawal 
4283a381a41SShagun Agrawal 	t->afree = NULL;
4293a381a41SShagun Agrawal 	t->atids_in_use = 0;
4303a381a41SShagun Agrawal 	rte_atomic32_init(&t->tids_in_use);
4313a381a41SShagun Agrawal 	rte_atomic32_set(&t->tids_in_use, 0);
4323a381a41SShagun Agrawal 	rte_atomic32_init(&t->conns_in_use);
4333a381a41SShagun Agrawal 	rte_atomic32_set(&t->conns_in_use, 0);
4343a381a41SShagun Agrawal 
4353a381a41SShagun Agrawal 	/* Setup the free list for atid_tab and clear the stid bitmap. */
4363a381a41SShagun Agrawal 	if (natids) {
4373a381a41SShagun Agrawal 		while (--natids)
4383a381a41SShagun Agrawal 			t->atid_tab[natids - 1].next = &t->atid_tab[natids];
4393a381a41SShagun Agrawal 		t->afree = t->atid_tab;
4403a381a41SShagun Agrawal 	}
4413a381a41SShagun Agrawal 
4426f2a064bSShagun Agrawal 	t->ftid_bmap = rte_bitmap_init(t->nftids, t->ftid_bmap_array,
4436f2a064bSShagun Agrawal 				       ftid_bmap_size);
4446f2a064bSShagun Agrawal 	if (!t->ftid_bmap) {
4456f2a064bSShagun Agrawal 		tid_free(t);
4466f2a064bSShagun Agrawal 		return -ENOMEM;
4476f2a064bSShagun Agrawal 	}
4486f2a064bSShagun Agrawal 
4496f2a064bSShagun Agrawal 	return 0;
4506f2a064bSShagun Agrawal }
4516f2a064bSShagun Agrawal 
45292c8a632SRahul Lakkireddy static inline bool is_x_1g_port(const struct link_config *lc)
45392c8a632SRahul Lakkireddy {
45476488837SRahul Lakkireddy 	return (lc->pcaps & FW_PORT_CAP32_SPEED_1G) != 0;
45592c8a632SRahul Lakkireddy }
45692c8a632SRahul Lakkireddy 
45792c8a632SRahul Lakkireddy static inline bool is_x_10g_port(const struct link_config *lc)
45892c8a632SRahul Lakkireddy {
4599da2a694SRahul Lakkireddy 	unsigned int speeds, high_speeds;
4609da2a694SRahul Lakkireddy 
46176488837SRahul Lakkireddy 	speeds = V_FW_PORT_CAP32_SPEED(G_FW_PORT_CAP32_SPEED(lc->pcaps));
46276488837SRahul Lakkireddy 	high_speeds = speeds &
46376488837SRahul Lakkireddy 		      ~(FW_PORT_CAP32_SPEED_100M | FW_PORT_CAP32_SPEED_1G);
4649da2a694SRahul Lakkireddy 
4659da2a694SRahul Lakkireddy 	return high_speeds != 0;
46692c8a632SRahul Lakkireddy }
46792c8a632SRahul Lakkireddy 
468b7fd9ea8SStephen Hemminger static inline void init_rspq(struct adapter *adap, struct sge_rspq *q,
46992c8a632SRahul Lakkireddy 		      unsigned int us, unsigned int cnt,
47092c8a632SRahul Lakkireddy 		      unsigned int size, unsigned int iqe_size)
47192c8a632SRahul Lakkireddy {
47292c8a632SRahul Lakkireddy 	q->adapter = adap;
47392c8a632SRahul Lakkireddy 	cxgb4_set_rspq_intr_params(q, us, cnt);
47492c8a632SRahul Lakkireddy 	q->iqe_len = iqe_size;
47592c8a632SRahul Lakkireddy 	q->size = size;
47692c8a632SRahul Lakkireddy }
47792c8a632SRahul Lakkireddy 
478b7fd9ea8SStephen Hemminger int cxgbe_cfg_queue_count(struct rte_eth_dev *eth_dev)
47992c8a632SRahul Lakkireddy {
48092c8a632SRahul Lakkireddy 	struct port_info *pi = (struct port_info *)(eth_dev->data->dev_private);
48192c8a632SRahul Lakkireddy 	struct adapter *adap = pi->adapter;
48292c8a632SRahul Lakkireddy 	struct sge *s = &adap->sge;
48392c8a632SRahul Lakkireddy 	unsigned int max_queues = s->max_ethqsets / adap->params.nports;
48492c8a632SRahul Lakkireddy 
48592c8a632SRahul Lakkireddy 	if ((eth_dev->data->nb_rx_queues < 1) ||
48692c8a632SRahul Lakkireddy 	    (eth_dev->data->nb_tx_queues < 1))
48792c8a632SRahul Lakkireddy 		return -EINVAL;
48892c8a632SRahul Lakkireddy 
48992c8a632SRahul Lakkireddy 	if ((eth_dev->data->nb_rx_queues > max_queues) ||
49092c8a632SRahul Lakkireddy 	    (eth_dev->data->nb_tx_queues > max_queues))
49192c8a632SRahul Lakkireddy 		return -EINVAL;
49292c8a632SRahul Lakkireddy 
49392c8a632SRahul Lakkireddy 	if (eth_dev->data->nb_rx_queues > pi->rss_size)
49492c8a632SRahul Lakkireddy 		return -EINVAL;
49592c8a632SRahul Lakkireddy 
49692c8a632SRahul Lakkireddy 	/* We must configure RSS, since config has changed*/
49792c8a632SRahul Lakkireddy 	pi->flags &= ~PORT_RSS_DONE;
49892c8a632SRahul Lakkireddy 
49992c8a632SRahul Lakkireddy 	pi->n_rx_qsets = eth_dev->data->nb_rx_queues;
50092c8a632SRahul Lakkireddy 	pi->n_tx_qsets = eth_dev->data->nb_tx_queues;
50192c8a632SRahul Lakkireddy 
50292c8a632SRahul Lakkireddy 	return 0;
50392c8a632SRahul Lakkireddy }
50492c8a632SRahul Lakkireddy 
505b7fd9ea8SStephen Hemminger void cxgbe_cfg_queues(struct rte_eth_dev *eth_dev)
50692c8a632SRahul Lakkireddy {
50792c8a632SRahul Lakkireddy 	struct port_info *pi = (struct port_info *)(eth_dev->data->dev_private);
50892c8a632SRahul Lakkireddy 	struct adapter *adap = pi->adapter;
50992c8a632SRahul Lakkireddy 	struct sge *s = &adap->sge;
51092c8a632SRahul Lakkireddy 	unsigned int i, nb_ports = 0, qidx = 0;
51192c8a632SRahul Lakkireddy 	unsigned int q_per_port = 0;
51292c8a632SRahul Lakkireddy 
51392c8a632SRahul Lakkireddy 	if (!(adap->flags & CFG_QUEUES)) {
51492c8a632SRahul Lakkireddy 		for_each_port(adap, i) {
51592c8a632SRahul Lakkireddy 			struct port_info *tpi = adap2pinfo(adap, i);
51692c8a632SRahul Lakkireddy 
51792c8a632SRahul Lakkireddy 			nb_ports += (is_x_10g_port(&tpi->link_cfg)) ||
51892c8a632SRahul Lakkireddy 				     is_x_1g_port(&tpi->link_cfg) ? 1 : 0;
51992c8a632SRahul Lakkireddy 		}
52092c8a632SRahul Lakkireddy 
52192c8a632SRahul Lakkireddy 		/*
52292c8a632SRahul Lakkireddy 		 * We default up to # of cores queues per 1G/10G port.
52392c8a632SRahul Lakkireddy 		 */
52492c8a632SRahul Lakkireddy 		if (nb_ports)
52587a3ae3eSRahul Lakkireddy 			q_per_port = (s->max_ethqsets -
52692c8a632SRahul Lakkireddy 				     (adap->params.nports - nb_ports)) /
52792c8a632SRahul Lakkireddy 				     nb_ports;
52892c8a632SRahul Lakkireddy 
529*64a46f14SDavid Marchand 		if (q_per_port > rte_lcore_count())
530*64a46f14SDavid Marchand 			q_per_port = rte_lcore_count();
53192c8a632SRahul Lakkireddy 
53292c8a632SRahul Lakkireddy 		for_each_port(adap, i) {
53392c8a632SRahul Lakkireddy 			struct port_info *pi = adap2pinfo(adap, i);
53492c8a632SRahul Lakkireddy 
53592c8a632SRahul Lakkireddy 			pi->first_qset = qidx;
53692c8a632SRahul Lakkireddy 
53792c8a632SRahul Lakkireddy 			/* Initially n_rx_qsets == n_tx_qsets */
53892c8a632SRahul Lakkireddy 			pi->n_rx_qsets = (is_x_10g_port(&pi->link_cfg) ||
53992c8a632SRahul Lakkireddy 					  is_x_1g_port(&pi->link_cfg)) ?
54092c8a632SRahul Lakkireddy 					  q_per_port : 1;
54192c8a632SRahul Lakkireddy 			pi->n_tx_qsets = pi->n_rx_qsets;
54292c8a632SRahul Lakkireddy 
54392c8a632SRahul Lakkireddy 			if (pi->n_rx_qsets > pi->rss_size)
54492c8a632SRahul Lakkireddy 				pi->n_rx_qsets = pi->rss_size;
54592c8a632SRahul Lakkireddy 
54692c8a632SRahul Lakkireddy 			qidx += pi->n_rx_qsets;
54792c8a632SRahul Lakkireddy 		}
54892c8a632SRahul Lakkireddy 
54992c8a632SRahul Lakkireddy 		for (i = 0; i < ARRAY_SIZE(s->ethrxq); i++) {
55092c8a632SRahul Lakkireddy 			struct sge_eth_rxq *r = &s->ethrxq[i];
55192c8a632SRahul Lakkireddy 
5526c280962SRahul Lakkireddy 			init_rspq(adap, &r->rspq, 5, 32, 1024, 64);
55392c8a632SRahul Lakkireddy 			r->usembufs = 1;
55492c8a632SRahul Lakkireddy 			r->fl.size = (r->usembufs ? 1024 : 72);
55592c8a632SRahul Lakkireddy 		}
55692c8a632SRahul Lakkireddy 
55792c8a632SRahul Lakkireddy 		for (i = 0; i < ARRAY_SIZE(s->ethtxq); i++)
55892c8a632SRahul Lakkireddy 			s->ethtxq[i].q.size = 1024;
55992c8a632SRahul Lakkireddy 
56092c8a632SRahul Lakkireddy 		init_rspq(adap, &adap->sge.fw_evtq, 0, 0, 1024, 64);
56192c8a632SRahul Lakkireddy 		adap->flags |= CFG_QUEUES;
56292c8a632SRahul Lakkireddy 	}
56392c8a632SRahul Lakkireddy }
56492c8a632SRahul Lakkireddy 
565856505d3SRahul Lakkireddy void cxgbe_stats_get(struct port_info *pi, struct port_stats *stats)
566856505d3SRahul Lakkireddy {
567856505d3SRahul Lakkireddy 	t4_get_port_stats_offset(pi->adapter, pi->tx_chan, stats,
568856505d3SRahul Lakkireddy 				 &pi->stats_base);
569856505d3SRahul Lakkireddy }
570856505d3SRahul Lakkireddy 
571856505d3SRahul Lakkireddy void cxgbe_stats_reset(struct port_info *pi)
572856505d3SRahul Lakkireddy {
573856505d3SRahul Lakkireddy 	t4_clr_port_stats(pi->adapter, pi->tx_chan);
574856505d3SRahul Lakkireddy }
575856505d3SRahul Lakkireddy 
57683189849SRahul Lakkireddy static void setup_memwin(struct adapter *adap)
57783189849SRahul Lakkireddy {
57883189849SRahul Lakkireddy 	u32 mem_win0_base;
57983189849SRahul Lakkireddy 
58083189849SRahul Lakkireddy 	/* For T5, only relative offset inside the PCIe BAR is passed */
58183189849SRahul Lakkireddy 	mem_win0_base = MEMWIN0_BASE;
58283189849SRahul Lakkireddy 
58383189849SRahul Lakkireddy 	/*
58483189849SRahul Lakkireddy 	 * Set up memory window for accessing adapter memory ranges.  (Read
58583189849SRahul Lakkireddy 	 * back MA register to ensure that changes propagate before we attempt
58683189849SRahul Lakkireddy 	 * to use the new values.)
58783189849SRahul Lakkireddy 	 */
58883189849SRahul Lakkireddy 	t4_write_reg(adap,
58983189849SRahul Lakkireddy 		     PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_BASE_WIN,
59083189849SRahul Lakkireddy 					 MEMWIN_NIC),
59183189849SRahul Lakkireddy 		     mem_win0_base | V_BIR(0) |
59283189849SRahul Lakkireddy 		     V_WINDOW(ilog2(MEMWIN0_APERTURE) - X_WINDOW_SHIFT));
59383189849SRahul Lakkireddy 	t4_read_reg(adap,
59483189849SRahul Lakkireddy 		    PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_BASE_WIN,
59583189849SRahul Lakkireddy 					MEMWIN_NIC));
59683189849SRahul Lakkireddy }
59783189849SRahul Lakkireddy 
598b7fd9ea8SStephen Hemminger int cxgbe_init_rss(struct adapter *adap)
59992c8a632SRahul Lakkireddy {
60092c8a632SRahul Lakkireddy 	unsigned int i;
601bfcb257dSKumar Sanghvi 
602bfcb257dSKumar Sanghvi 	if (is_pf4(adap)) {
60392c8a632SRahul Lakkireddy 		int err;
60492c8a632SRahul Lakkireddy 
60592c8a632SRahul Lakkireddy 		err = t4_init_rss_mode(adap, adap->mbox);
60692c8a632SRahul Lakkireddy 		if (err)
60792c8a632SRahul Lakkireddy 			return err;
608bfcb257dSKumar Sanghvi 	}
60992c8a632SRahul Lakkireddy 
61092c8a632SRahul Lakkireddy 	for_each_port(adap, i) {
61192c8a632SRahul Lakkireddy 		struct port_info *pi = adap2pinfo(adap, i);
61292c8a632SRahul Lakkireddy 
6138dca8cc5SRahul Lakkireddy 		pi->rss = rte_zmalloc(NULL, pi->rss_size * sizeof(u16), 0);
61492c8a632SRahul Lakkireddy 		if (!pi->rss)
61592c8a632SRahul Lakkireddy 			return -ENOMEM;
61608e21af9SKumar Sanghvi 
61708e21af9SKumar Sanghvi 		pi->rss_hf = CXGBE_RSS_HF_ALL;
61892c8a632SRahul Lakkireddy 	}
61992c8a632SRahul Lakkireddy 	return 0;
62092c8a632SRahul Lakkireddy }
62192c8a632SRahul Lakkireddy 
622c962618cSRahul Lakkireddy /**
623c962618cSRahul Lakkireddy  * Dump basic information about the adapter.
624c962618cSRahul Lakkireddy  */
625b7fd9ea8SStephen Hemminger void cxgbe_print_adapter_info(struct adapter *adap)
626c962618cSRahul Lakkireddy {
627c962618cSRahul Lakkireddy 	/**
628c962618cSRahul Lakkireddy 	 * Hardware/Firmware/etc. Version/Revision IDs.
629c962618cSRahul Lakkireddy 	 */
630c962618cSRahul Lakkireddy 	t4_dump_version_info(adap);
631c962618cSRahul Lakkireddy }
632c962618cSRahul Lakkireddy 
633b7fd9ea8SStephen Hemminger void cxgbe_print_port_info(struct adapter *adap)
63483189849SRahul Lakkireddy {
63583189849SRahul Lakkireddy 	int i;
63683189849SRahul Lakkireddy 	char buf[80];
63783189849SRahul Lakkireddy 	struct rte_pci_addr *loc = &adap->pdev->addr;
63883189849SRahul Lakkireddy 
63983189849SRahul Lakkireddy 	for_each_port(adap, i) {
6402195df6dSRahul Lakkireddy 		const struct port_info *pi = adap2pinfo(adap, i);
64183189849SRahul Lakkireddy 		char *bufp = buf;
64283189849SRahul Lakkireddy 
64376488837SRahul Lakkireddy 		if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_100M)
6449da2a694SRahul Lakkireddy 			bufp += sprintf(bufp, "100M/");
64576488837SRahul Lakkireddy 		if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_1G)
6469da2a694SRahul Lakkireddy 			bufp += sprintf(bufp, "1G/");
64776488837SRahul Lakkireddy 		if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_10G)
64883189849SRahul Lakkireddy 			bufp += sprintf(bufp, "10G/");
64976488837SRahul Lakkireddy 		if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_25G)
6509da2a694SRahul Lakkireddy 			bufp += sprintf(bufp, "25G/");
65176488837SRahul Lakkireddy 		if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_40G)
65283189849SRahul Lakkireddy 			bufp += sprintf(bufp, "40G/");
65376488837SRahul Lakkireddy 		if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_50G)
65476488837SRahul Lakkireddy 			bufp += sprintf(bufp, "50G/");
65576488837SRahul Lakkireddy 		if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_100G)
6569da2a694SRahul Lakkireddy 			bufp += sprintf(bufp, "100G/");
65783189849SRahul Lakkireddy 		if (bufp != buf)
65883189849SRahul Lakkireddy 			--bufp;
65983189849SRahul Lakkireddy 		sprintf(bufp, "BASE-%s",
660efa8a43eSBruce Richardson 			t4_get_port_type_description(
661efa8a43eSBruce Richardson 					(enum fw_port_type)pi->port_type));
66283189849SRahul Lakkireddy 
66383189849SRahul Lakkireddy 		dev_info(adap,
66483189849SRahul Lakkireddy 			 " " PCI_PRI_FMT " Chelsio rev %d %s %s\n",
66583189849SRahul Lakkireddy 			 loc->domain, loc->bus, loc->devid, loc->function,
66683189849SRahul Lakkireddy 			 CHELSIO_CHIP_RELEASE(adap->params.chip), buf,
66783189849SRahul Lakkireddy 			 (adap->flags & USING_MSIX) ? " MSI-X" :
66883189849SRahul Lakkireddy 			 (adap->flags & USING_MSI) ? " MSI" : "");
66983189849SRahul Lakkireddy 	}
67083189849SRahul Lakkireddy }
67183189849SRahul Lakkireddy 
672cda260a4SShagun Agrawal static int
673cda260a4SShagun Agrawal check_devargs_handler(__rte_unused const char *key, const char *value,
674cda260a4SShagun Agrawal 		      __rte_unused void *opaque)
675cda260a4SShagun Agrawal {
676cda260a4SShagun Agrawal 	if (strcmp(value, "1"))
677cda260a4SShagun Agrawal 		return -1;
678cda260a4SShagun Agrawal 
679cda260a4SShagun Agrawal 	return 0;
680cda260a4SShagun Agrawal }
681cda260a4SShagun Agrawal 
682f5b3c7b2SShagun Agrawal int cxgbe_get_devargs(struct rte_devargs *devargs, const char *key)
683cda260a4SShagun Agrawal {
684cda260a4SShagun Agrawal 	struct rte_kvargs *kvlist;
685cda260a4SShagun Agrawal 
686cda260a4SShagun Agrawal 	if (!devargs)
687cda260a4SShagun Agrawal 		return 0;
688cda260a4SShagun Agrawal 
689cda260a4SShagun Agrawal 	kvlist = rte_kvargs_parse(devargs->args, NULL);
690cda260a4SShagun Agrawal 	if (!kvlist)
691cda260a4SShagun Agrawal 		return 0;
692cda260a4SShagun Agrawal 
693cda260a4SShagun Agrawal 	if (!rte_kvargs_count(kvlist, key)) {
694cda260a4SShagun Agrawal 		rte_kvargs_free(kvlist);
695cda260a4SShagun Agrawal 		return 0;
696cda260a4SShagun Agrawal 	}
697cda260a4SShagun Agrawal 
698cda260a4SShagun Agrawal 	if (rte_kvargs_process(kvlist, key,
699cda260a4SShagun Agrawal 			       check_devargs_handler, NULL) < 0) {
700cda260a4SShagun Agrawal 		rte_kvargs_free(kvlist);
701cda260a4SShagun Agrawal 		return 0;
702cda260a4SShagun Agrawal 	}
703cda260a4SShagun Agrawal 	rte_kvargs_free(kvlist);
704cda260a4SShagun Agrawal 
705cda260a4SShagun Agrawal 	return 1;
706cda260a4SShagun Agrawal }
707cda260a4SShagun Agrawal 
708cda260a4SShagun Agrawal static void configure_vlan_types(struct adapter *adapter)
709cda260a4SShagun Agrawal {
710cda260a4SShagun Agrawal 	struct rte_pci_device *pdev = adapter->pdev;
711cda260a4SShagun Agrawal 	int i;
712cda260a4SShagun Agrawal 
713cda260a4SShagun Agrawal 	for_each_port(adapter, i) {
714cda260a4SShagun Agrawal 		/* OVLAN Type 0x88a8 */
715cda260a4SShagun Agrawal 		t4_set_reg_field(adapter, MPS_PORT_RX_OVLAN_REG(i, A_RX_OVLAN0),
716cda260a4SShagun Agrawal 				 V_OVLAN_MASK(M_OVLAN_MASK) |
717cda260a4SShagun Agrawal 				 V_OVLAN_ETYPE(M_OVLAN_ETYPE),
718cda260a4SShagun Agrawal 				 V_OVLAN_MASK(M_OVLAN_MASK) |
719cda260a4SShagun Agrawal 				 V_OVLAN_ETYPE(0x88a8));
720cda260a4SShagun Agrawal 		/* OVLAN Type 0x9100 */
721cda260a4SShagun Agrawal 		t4_set_reg_field(adapter, MPS_PORT_RX_OVLAN_REG(i, A_RX_OVLAN1),
722cda260a4SShagun Agrawal 				 V_OVLAN_MASK(M_OVLAN_MASK) |
723cda260a4SShagun Agrawal 				 V_OVLAN_ETYPE(M_OVLAN_ETYPE),
724cda260a4SShagun Agrawal 				 V_OVLAN_MASK(M_OVLAN_MASK) |
725cda260a4SShagun Agrawal 				 V_OVLAN_ETYPE(0x9100));
726cda260a4SShagun Agrawal 		/* OVLAN Type 0x8100 */
727cda260a4SShagun Agrawal 		t4_set_reg_field(adapter, MPS_PORT_RX_OVLAN_REG(i, A_RX_OVLAN2),
728cda260a4SShagun Agrawal 				 V_OVLAN_MASK(M_OVLAN_MASK) |
729cda260a4SShagun Agrawal 				 V_OVLAN_ETYPE(M_OVLAN_ETYPE),
730cda260a4SShagun Agrawal 				 V_OVLAN_MASK(M_OVLAN_MASK) |
731cda260a4SShagun Agrawal 				 V_OVLAN_ETYPE(0x8100));
732cda260a4SShagun Agrawal 
733cda260a4SShagun Agrawal 		/* IVLAN 0X8100 */
734cda260a4SShagun Agrawal 		t4_set_reg_field(adapter, MPS_PORT_RX_IVLAN(i),
735cda260a4SShagun Agrawal 				 V_IVLAN_ETYPE(M_IVLAN_ETYPE),
736cda260a4SShagun Agrawal 				 V_IVLAN_ETYPE(0x8100));
737cda260a4SShagun Agrawal 
738cda260a4SShagun Agrawal 		t4_set_reg_field(adapter, MPS_PORT_RX_CTL(i),
739cda260a4SShagun Agrawal 				 F_OVLAN_EN0 | F_OVLAN_EN1 |
740cda260a4SShagun Agrawal 				 F_OVLAN_EN2 | F_IVLAN_EN,
741cda260a4SShagun Agrawal 				 F_OVLAN_EN0 | F_OVLAN_EN1 |
742cda260a4SShagun Agrawal 				 F_OVLAN_EN2 | F_IVLAN_EN);
743cda260a4SShagun Agrawal 	}
744cda260a4SShagun Agrawal 
745cda260a4SShagun Agrawal 	if (cxgbe_get_devargs(pdev->device.devargs, CXGBE_DEVARG_KEEP_OVLAN))
746cda260a4SShagun Agrawal 		t4_tp_wr_bits_indirect(adapter, A_TP_INGRESS_CONFIG,
747cda260a4SShagun Agrawal 				       V_RM_OVLAN(1), V_RM_OVLAN(0));
748cda260a4SShagun Agrawal }
749cda260a4SShagun Agrawal 
750ee606d92SRahul Lakkireddy static void configure_pcie_ext_tag(struct adapter *adapter)
751ee606d92SRahul Lakkireddy {
752ee606d92SRahul Lakkireddy 	u16 v;
753ee606d92SRahul Lakkireddy 	int pos = t4_os_find_pci_capability(adapter, PCI_CAP_ID_EXP);
754ee606d92SRahul Lakkireddy 
755ee606d92SRahul Lakkireddy 	if (!pos)
756ee606d92SRahul Lakkireddy 		return;
757ee606d92SRahul Lakkireddy 
758ee606d92SRahul Lakkireddy 	if (pos > 0) {
759ee606d92SRahul Lakkireddy 		t4_os_pci_read_cfg2(adapter, pos + PCI_EXP_DEVCTL, &v);
760ee606d92SRahul Lakkireddy 		v |= PCI_EXP_DEVCTL_EXT_TAG;
761ee606d92SRahul Lakkireddy 		t4_os_pci_write_cfg2(adapter, pos + PCI_EXP_DEVCTL, v);
762ee606d92SRahul Lakkireddy 		if (is_t6(adapter->params.chip)) {
763ee606d92SRahul Lakkireddy 			t4_set_reg_field(adapter, A_PCIE_CFG2,
764ee606d92SRahul Lakkireddy 					 V_T6_TOTMAXTAG(M_T6_TOTMAXTAG),
765ee606d92SRahul Lakkireddy 					 V_T6_TOTMAXTAG(7));
766ee606d92SRahul Lakkireddy 			t4_set_reg_field(adapter, A_PCIE_CMD_CFG,
767ee606d92SRahul Lakkireddy 					 V_T6_MINTAG(M_T6_MINTAG),
768ee606d92SRahul Lakkireddy 					 V_T6_MINTAG(8));
769ee606d92SRahul Lakkireddy 		} else {
770ee606d92SRahul Lakkireddy 			t4_set_reg_field(adapter, A_PCIE_CFG2,
771ee606d92SRahul Lakkireddy 					 V_TOTMAXTAG(M_TOTMAXTAG),
772ee606d92SRahul Lakkireddy 					 V_TOTMAXTAG(3));
773ee606d92SRahul Lakkireddy 			t4_set_reg_field(adapter, A_PCIE_CMD_CFG,
774ee606d92SRahul Lakkireddy 					 V_MINTAG(M_MINTAG),
775ee606d92SRahul Lakkireddy 					 V_MINTAG(8));
776ee606d92SRahul Lakkireddy 		}
777ee606d92SRahul Lakkireddy 	}
778ee606d92SRahul Lakkireddy }
779ee606d92SRahul Lakkireddy 
78087a3ae3eSRahul Lakkireddy /* Figure out how many Queue Sets we can support */
781b7fd9ea8SStephen Hemminger void cxgbe_configure_max_ethqsets(struct adapter *adapter)
78287a3ae3eSRahul Lakkireddy {
78387a3ae3eSRahul Lakkireddy 	unsigned int ethqsets;
78487a3ae3eSRahul Lakkireddy 
78587a3ae3eSRahul Lakkireddy 	/*
78687a3ae3eSRahul Lakkireddy 	 * We need to reserve an Ingress Queue for the Asynchronous Firmware
78787a3ae3eSRahul Lakkireddy 	 * Event Queue.
78887a3ae3eSRahul Lakkireddy 	 *
78987a3ae3eSRahul Lakkireddy 	 * For each Queue Set, we'll need the ability to allocate two Egress
79087a3ae3eSRahul Lakkireddy 	 * Contexts -- one for the Ingress Queue Free List and one for the TX
79187a3ae3eSRahul Lakkireddy 	 * Ethernet Queue.
79287a3ae3eSRahul Lakkireddy 	 */
79387a3ae3eSRahul Lakkireddy 	if (is_pf4(adapter)) {
79487a3ae3eSRahul Lakkireddy 		struct pf_resources *pfres = &adapter->params.pfres;
79587a3ae3eSRahul Lakkireddy 
79687a3ae3eSRahul Lakkireddy 		ethqsets = pfres->niqflint - 1;
79787a3ae3eSRahul Lakkireddy 		if (pfres->neq < ethqsets * 2)
79887a3ae3eSRahul Lakkireddy 			ethqsets = pfres->neq / 2;
79987a3ae3eSRahul Lakkireddy 	} else {
80087a3ae3eSRahul Lakkireddy 		struct vf_resources *vfres = &adapter->params.vfres;
80187a3ae3eSRahul Lakkireddy 
80287a3ae3eSRahul Lakkireddy 		ethqsets = vfres->niqflint - 1;
80387a3ae3eSRahul Lakkireddy 		if (vfres->nethctrl != ethqsets)
80487a3ae3eSRahul Lakkireddy 			ethqsets = min(vfres->nethctrl, ethqsets);
80587a3ae3eSRahul Lakkireddy 		if (vfres->neq < ethqsets * 2)
80687a3ae3eSRahul Lakkireddy 			ethqsets = vfres->neq / 2;
80787a3ae3eSRahul Lakkireddy 	}
80887a3ae3eSRahul Lakkireddy 
80987a3ae3eSRahul Lakkireddy 	if (ethqsets > MAX_ETH_QSETS)
81087a3ae3eSRahul Lakkireddy 		ethqsets = MAX_ETH_QSETS;
81187a3ae3eSRahul Lakkireddy 	adapter->sge.max_ethqsets = ethqsets;
81287a3ae3eSRahul Lakkireddy }
81387a3ae3eSRahul Lakkireddy 
81483189849SRahul Lakkireddy /*
81583189849SRahul Lakkireddy  * Tweak configuration based on system architecture, etc.  Most of these have
81683189849SRahul Lakkireddy  * defaults assigned to them by Firmware Configuration Files (if we're using
81783189849SRahul Lakkireddy  * them) but need to be explicitly set if we're using hard-coded
81883189849SRahul Lakkireddy  * initialization. So these are essentially common tweaks/settings for
81983189849SRahul Lakkireddy  * Configuration Files and hard-coded initialization ...
82083189849SRahul Lakkireddy  */
82183189849SRahul Lakkireddy static int adap_init0_tweaks(struct adapter *adapter)
82283189849SRahul Lakkireddy {
82383189849SRahul Lakkireddy 	u8 rx_dma_offset;
82483189849SRahul Lakkireddy 
82583189849SRahul Lakkireddy 	/*
82683189849SRahul Lakkireddy 	 * Fix up various Host-Dependent Parameters like Page Size, Cache
82783189849SRahul Lakkireddy 	 * Line Size, etc.  The firmware default is for a 4KB Page Size and
82883189849SRahul Lakkireddy 	 * 64B Cache Line Size ...
82983189849SRahul Lakkireddy 	 */
8301f8613f1SRahul Lakkireddy 	t4_fixup_host_params_compat(adapter, CXGBE_PAGE_SIZE, L1_CACHE_BYTES,
83183189849SRahul Lakkireddy 				    T5_LAST_REV);
83283189849SRahul Lakkireddy 
83383189849SRahul Lakkireddy 	/*
83483189849SRahul Lakkireddy 	 * Keep the chip default offset to deliver Ingress packets into our
83583189849SRahul Lakkireddy 	 * DMA buffers to zero
83683189849SRahul Lakkireddy 	 */
83783189849SRahul Lakkireddy 	rx_dma_offset = 0;
83883189849SRahul Lakkireddy 	t4_set_reg_field(adapter, A_SGE_CONTROL, V_PKTSHIFT(M_PKTSHIFT),
83983189849SRahul Lakkireddy 			 V_PKTSHIFT(rx_dma_offset));
84083189849SRahul Lakkireddy 
841bf89cbedSRahul Lakkireddy 	t4_set_reg_field(adapter, A_SGE_FLM_CFG,
842bf89cbedSRahul Lakkireddy 			 V_CREDITCNT(M_CREDITCNT) | M_CREDITCNTPACKING,
843bf89cbedSRahul Lakkireddy 			 V_CREDITCNT(3) | V_CREDITCNTPACKING(1));
844bf89cbedSRahul Lakkireddy 
8456c280962SRahul Lakkireddy 	t4_set_reg_field(adapter, A_SGE_INGRESS_RX_THRESHOLD,
8466c280962SRahul Lakkireddy 			 V_THRESHOLD_3(M_THRESHOLD_3), V_THRESHOLD_3(32U));
8476c280962SRahul Lakkireddy 
848bf89cbedSRahul Lakkireddy 	t4_set_reg_field(adapter, A_SGE_CONTROL2, V_IDMAARBROUNDROBIN(1U),
849bf89cbedSRahul Lakkireddy 			 V_IDMAARBROUNDROBIN(1U));
850bf89cbedSRahul Lakkireddy 
85183189849SRahul Lakkireddy 	/*
85283189849SRahul Lakkireddy 	 * Don't include the "IP Pseudo Header" in CPL_RX_PKT checksums: Linux
85383189849SRahul Lakkireddy 	 * adds the pseudo header itself.
85483189849SRahul Lakkireddy 	 */
85583189849SRahul Lakkireddy 	t4_tp_wr_bits_indirect(adapter, A_TP_INGRESS_CONFIG,
85683189849SRahul Lakkireddy 			       F_CSUM_HAS_PSEUDO_HDR, 0);
85783189849SRahul Lakkireddy 
85883189849SRahul Lakkireddy 	return 0;
85983189849SRahul Lakkireddy }
86083189849SRahul Lakkireddy 
86183189849SRahul Lakkireddy /*
86283189849SRahul Lakkireddy  * Attempt to initialize the adapter via a Firmware Configuration File.
86383189849SRahul Lakkireddy  */
86483189849SRahul Lakkireddy static int adap_init0_config(struct adapter *adapter, int reset)
86583189849SRahul Lakkireddy {
86683189849SRahul Lakkireddy 	struct fw_caps_config_cmd caps_cmd;
86783189849SRahul Lakkireddy 	unsigned long mtype = 0, maddr = 0;
86883189849SRahul Lakkireddy 	u32 finiver, finicsum, cfcsum;
86983189849SRahul Lakkireddy 	int ret;
87083189849SRahul Lakkireddy 	int config_issued = 0;
87183189849SRahul Lakkireddy 	int cfg_addr;
87283189849SRahul Lakkireddy 	char config_name[20];
87383189849SRahul Lakkireddy 
87483189849SRahul Lakkireddy 	/*
87583189849SRahul Lakkireddy 	 * Reset device if necessary.
87683189849SRahul Lakkireddy 	 */
87783189849SRahul Lakkireddy 	if (reset) {
87883189849SRahul Lakkireddy 		ret = t4_fw_reset(adapter, adapter->mbox,
87983189849SRahul Lakkireddy 				  F_PIORSTMODE | F_PIORST);
88083189849SRahul Lakkireddy 		if (ret < 0) {
88183189849SRahul Lakkireddy 			dev_warn(adapter, "Firmware reset failed, error %d\n",
88283189849SRahul Lakkireddy 				 -ret);
88383189849SRahul Lakkireddy 			goto bye;
88483189849SRahul Lakkireddy 		}
88583189849SRahul Lakkireddy 	}
88683189849SRahul Lakkireddy 
88783189849SRahul Lakkireddy 	cfg_addr = t4_flash_cfg_addr(adapter);
88883189849SRahul Lakkireddy 	if (cfg_addr < 0) {
88983189849SRahul Lakkireddy 		ret = cfg_addr;
89083189849SRahul Lakkireddy 		dev_warn(adapter, "Finding address for firmware config file in flash failed, error %d\n",
89183189849SRahul Lakkireddy 			 -ret);
89283189849SRahul Lakkireddy 		goto bye;
89383189849SRahul Lakkireddy 	}
89483189849SRahul Lakkireddy 
89583189849SRahul Lakkireddy 	strcpy(config_name, "On Flash");
89683189849SRahul Lakkireddy 	mtype = FW_MEMTYPE_CF_FLASH;
89783189849SRahul Lakkireddy 	maddr = cfg_addr;
89883189849SRahul Lakkireddy 
89983189849SRahul Lakkireddy 	/*
90083189849SRahul Lakkireddy 	 * Issue a Capability Configuration command to the firmware to get it
90183189849SRahul Lakkireddy 	 * to parse the Configuration File.  We don't use t4_fw_config_file()
90283189849SRahul Lakkireddy 	 * because we want the ability to modify various features after we've
90383189849SRahul Lakkireddy 	 * processed the configuration file ...
90483189849SRahul Lakkireddy 	 */
90583189849SRahul Lakkireddy 	memset(&caps_cmd, 0, sizeof(caps_cmd));
90683189849SRahul Lakkireddy 	caps_cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
90783189849SRahul Lakkireddy 					   F_FW_CMD_REQUEST | F_FW_CMD_READ);
90883189849SRahul Lakkireddy 	caps_cmd.cfvalid_to_len16 =
90983189849SRahul Lakkireddy 		cpu_to_be32(F_FW_CAPS_CONFIG_CMD_CFVALID |
91083189849SRahul Lakkireddy 			    V_FW_CAPS_CONFIG_CMD_MEMTYPE_CF(mtype) |
91183189849SRahul Lakkireddy 			    V_FW_CAPS_CONFIG_CMD_MEMADDR64K_CF(maddr >> 16) |
91283189849SRahul Lakkireddy 			    FW_LEN16(caps_cmd));
91383189849SRahul Lakkireddy 	ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd, sizeof(caps_cmd),
91483189849SRahul Lakkireddy 			 &caps_cmd);
91583189849SRahul Lakkireddy 	/*
91683189849SRahul Lakkireddy 	 * If the CAPS_CONFIG failed with an ENOENT (for a Firmware
91783189849SRahul Lakkireddy 	 * Configuration File in FLASH), our last gasp effort is to use the
91883189849SRahul Lakkireddy 	 * Firmware Configuration File which is embedded in the firmware.  A
91983189849SRahul Lakkireddy 	 * very few early versions of the firmware didn't have one embedded
92083189849SRahul Lakkireddy 	 * but we can ignore those.
92183189849SRahul Lakkireddy 	 */
92283189849SRahul Lakkireddy 	if (ret == -ENOENT) {
92383189849SRahul Lakkireddy 		dev_info(adapter, "%s: Going for embedded config in firmware..\n",
92483189849SRahul Lakkireddy 			 __func__);
92583189849SRahul Lakkireddy 
92683189849SRahul Lakkireddy 		memset(&caps_cmd, 0, sizeof(caps_cmd));
92783189849SRahul Lakkireddy 		caps_cmd.op_to_write =
92883189849SRahul Lakkireddy 			cpu_to_be32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
92983189849SRahul Lakkireddy 				    F_FW_CMD_REQUEST | F_FW_CMD_READ);
93083189849SRahul Lakkireddy 		caps_cmd.cfvalid_to_len16 = cpu_to_be32(FW_LEN16(caps_cmd));
93183189849SRahul Lakkireddy 		ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd,
93283189849SRahul Lakkireddy 				 sizeof(caps_cmd), &caps_cmd);
93383189849SRahul Lakkireddy 		strcpy(config_name, "Firmware Default");
93483189849SRahul Lakkireddy 	}
93583189849SRahul Lakkireddy 
93683189849SRahul Lakkireddy 	config_issued = 1;
93783189849SRahul Lakkireddy 	if (ret < 0)
93883189849SRahul Lakkireddy 		goto bye;
93983189849SRahul Lakkireddy 
94083189849SRahul Lakkireddy 	finiver = be32_to_cpu(caps_cmd.finiver);
94183189849SRahul Lakkireddy 	finicsum = be32_to_cpu(caps_cmd.finicsum);
94283189849SRahul Lakkireddy 	cfcsum = be32_to_cpu(caps_cmd.cfcsum);
94383189849SRahul Lakkireddy 	if (finicsum != cfcsum)
94483189849SRahul Lakkireddy 		dev_warn(adapter, "Configuration File checksum mismatch: [fini] csum=%#x, computed csum=%#x\n",
94583189849SRahul Lakkireddy 			 finicsum, cfcsum);
94683189849SRahul Lakkireddy 
94783189849SRahul Lakkireddy 	/*
94883189849SRahul Lakkireddy 	 * If we're a pure NIC driver then disable all offloading facilities.
94983189849SRahul Lakkireddy 	 * This will allow the firmware to optimize aspects of the hardware
95083189849SRahul Lakkireddy 	 * configuration which will result in improved performance.
95183189849SRahul Lakkireddy 	 */
9523a381a41SShagun Agrawal 	caps_cmd.niccaps &= cpu_to_be16(~FW_CAPS_CONFIG_NIC_ETHOFLD);
95383189849SRahul Lakkireddy 	caps_cmd.toecaps = 0;
95483189849SRahul Lakkireddy 	caps_cmd.iscsicaps = 0;
95583189849SRahul Lakkireddy 	caps_cmd.rdmacaps = 0;
95683189849SRahul Lakkireddy 	caps_cmd.fcoecaps = 0;
95783189849SRahul Lakkireddy 
95883189849SRahul Lakkireddy 	/*
95983189849SRahul Lakkireddy 	 * And now tell the firmware to use the configuration we just loaded.
96083189849SRahul Lakkireddy 	 */
96183189849SRahul Lakkireddy 	caps_cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
96283189849SRahul Lakkireddy 					   F_FW_CMD_REQUEST | F_FW_CMD_WRITE);
96383189849SRahul Lakkireddy 	caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd));
96483189849SRahul Lakkireddy 	ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd, sizeof(caps_cmd),
96583189849SRahul Lakkireddy 			 NULL);
96683189849SRahul Lakkireddy 	if (ret < 0) {
96783189849SRahul Lakkireddy 		dev_warn(adapter, "Unable to finalize Firmware Capabilities %d\n",
96883189849SRahul Lakkireddy 			 -ret);
96983189849SRahul Lakkireddy 		goto bye;
97083189849SRahul Lakkireddy 	}
97183189849SRahul Lakkireddy 
97283189849SRahul Lakkireddy 	/*
97383189849SRahul Lakkireddy 	 * Tweak configuration based on system architecture, etc.
97483189849SRahul Lakkireddy 	 */
97583189849SRahul Lakkireddy 	ret = adap_init0_tweaks(adapter);
97683189849SRahul Lakkireddy 	if (ret < 0) {
97783189849SRahul Lakkireddy 		dev_warn(adapter, "Unable to do init0-tweaks %d\n", -ret);
97883189849SRahul Lakkireddy 		goto bye;
97983189849SRahul Lakkireddy 	}
98083189849SRahul Lakkireddy 
98183189849SRahul Lakkireddy 	/*
98283189849SRahul Lakkireddy 	 * And finally tell the firmware to initialize itself using the
98383189849SRahul Lakkireddy 	 * parameters from the Configuration File.
98483189849SRahul Lakkireddy 	 */
98583189849SRahul Lakkireddy 	ret = t4_fw_initialize(adapter, adapter->mbox);
98683189849SRahul Lakkireddy 	if (ret < 0) {
98783189849SRahul Lakkireddy 		dev_warn(adapter, "Initializing Firmware failed, error %d\n",
98883189849SRahul Lakkireddy 			 -ret);
98983189849SRahul Lakkireddy 		goto bye;
99083189849SRahul Lakkireddy 	}
99183189849SRahul Lakkireddy 
99283189849SRahul Lakkireddy 	/*
99383189849SRahul Lakkireddy 	 * Return successfully and note that we're operating with parameters
99483189849SRahul Lakkireddy 	 * not supplied by the driver, rather than from hard-wired
99598a7ea33SJerin Jacob 	 * initialization constants buried in the driver.
99683189849SRahul Lakkireddy 	 */
99783189849SRahul Lakkireddy 	dev_info(adapter,
99883189849SRahul Lakkireddy 		 "Successfully configured using Firmware Configuration File \"%s\", version %#x, computed checksum %#x\n",
99983189849SRahul Lakkireddy 		 config_name, finiver, cfcsum);
100083189849SRahul Lakkireddy 
100183189849SRahul Lakkireddy 	return 0;
100283189849SRahul Lakkireddy 
100383189849SRahul Lakkireddy 	/*
100483189849SRahul Lakkireddy 	 * Something bad happened.  Return the error ...  (If the "error"
100583189849SRahul Lakkireddy 	 * is that there's no Configuration File on the adapter we don't
100683189849SRahul Lakkireddy 	 * want to issue a warning since this is fairly common.)
100783189849SRahul Lakkireddy 	 */
100883189849SRahul Lakkireddy bye:
100983189849SRahul Lakkireddy 	if (config_issued && ret != -ENOENT)
101083189849SRahul Lakkireddy 		dev_warn(adapter, "\"%s\" configuration file error %d\n",
101183189849SRahul Lakkireddy 			 config_name, -ret);
101283189849SRahul Lakkireddy 
101383189849SRahul Lakkireddy 	dev_debug(adapter, "%s: returning ret = %d ..\n", __func__, ret);
101483189849SRahul Lakkireddy 	return ret;
101583189849SRahul Lakkireddy }
101683189849SRahul Lakkireddy 
101783189849SRahul Lakkireddy static int adap_init0(struct adapter *adap)
101883189849SRahul Lakkireddy {
10196f2a064bSShagun Agrawal 	struct fw_caps_config_cmd caps_cmd;
102083189849SRahul Lakkireddy 	int ret = 0;
102183189849SRahul Lakkireddy 	u32 v, port_vec;
102283189849SRahul Lakkireddy 	enum dev_state state;
102383189849SRahul Lakkireddy 	u32 params[7], val[7];
102483189849SRahul Lakkireddy 	int reset = 1;
102583189849SRahul Lakkireddy 	int mbox = adap->mbox;
102683189849SRahul Lakkireddy 
102783189849SRahul Lakkireddy 	/*
102883189849SRahul Lakkireddy 	 * Contact FW, advertising Master capability.
102983189849SRahul Lakkireddy 	 */
103083189849SRahul Lakkireddy 	ret = t4_fw_hello(adap, adap->mbox, adap->mbox, MASTER_MAY, &state);
103183189849SRahul Lakkireddy 	if (ret < 0) {
103283189849SRahul Lakkireddy 		dev_err(adap, "%s: could not connect to FW, error %d\n",
103383189849SRahul Lakkireddy 			__func__, -ret);
103483189849SRahul Lakkireddy 		goto bye;
103583189849SRahul Lakkireddy 	}
103683189849SRahul Lakkireddy 
103783189849SRahul Lakkireddy 	CXGBE_DEBUG_MBOX(adap, "%s: adap->mbox = %d; ret = %d\n", __func__,
103883189849SRahul Lakkireddy 			 adap->mbox, ret);
103983189849SRahul Lakkireddy 
104083189849SRahul Lakkireddy 	if (ret == mbox)
104183189849SRahul Lakkireddy 		adap->flags |= MASTER_PF;
104283189849SRahul Lakkireddy 
104383189849SRahul Lakkireddy 	if (state == DEV_STATE_INIT) {
104483189849SRahul Lakkireddy 		/*
104583189849SRahul Lakkireddy 		 * Force halt and reset FW because a previous instance may have
104683189849SRahul Lakkireddy 		 * exited abnormally without properly shutting down
104783189849SRahul Lakkireddy 		 */
104883189849SRahul Lakkireddy 		ret = t4_fw_halt(adap, adap->mbox, reset);
104983189849SRahul Lakkireddy 		if (ret < 0) {
105083189849SRahul Lakkireddy 			dev_err(adap, "Failed to halt. Exit.\n");
105183189849SRahul Lakkireddy 			goto bye;
105283189849SRahul Lakkireddy 		}
105383189849SRahul Lakkireddy 
105483189849SRahul Lakkireddy 		ret = t4_fw_restart(adap, adap->mbox, reset);
105583189849SRahul Lakkireddy 		if (ret < 0) {
105683189849SRahul Lakkireddy 			dev_err(adap, "Failed to restart. Exit.\n");
105783189849SRahul Lakkireddy 			goto bye;
105883189849SRahul Lakkireddy 		}
1059efa8a43eSBruce Richardson 		state = (enum dev_state)((unsigned)state & ~DEV_STATE_INIT);
106083189849SRahul Lakkireddy 	}
106183189849SRahul Lakkireddy 
1062c962618cSRahul Lakkireddy 	t4_get_version_info(adap);
106383189849SRahul Lakkireddy 
106483189849SRahul Lakkireddy 	ret = t4_get_core_clock(adap, &adap->params.vpd);
106583189849SRahul Lakkireddy 	if (ret < 0) {
106683189849SRahul Lakkireddy 		dev_err(adap, "%s: could not get core clock, error %d\n",
106783189849SRahul Lakkireddy 			__func__, -ret);
106883189849SRahul Lakkireddy 		goto bye;
106983189849SRahul Lakkireddy 	}
107083189849SRahul Lakkireddy 
107183189849SRahul Lakkireddy 	/*
107283189849SRahul Lakkireddy 	 * If the firmware is initialized already (and we're not forcing a
107383189849SRahul Lakkireddy 	 * master initialization), note that we're living with existing
107483189849SRahul Lakkireddy 	 * adapter parameters.  Otherwise, it's time to try initializing the
107583189849SRahul Lakkireddy 	 * adapter ...
107683189849SRahul Lakkireddy 	 */
107783189849SRahul Lakkireddy 	if (state == DEV_STATE_INIT) {
107883189849SRahul Lakkireddy 		dev_info(adap, "Coming up as %s: Adapter already initialized\n",
107983189849SRahul Lakkireddy 			 adap->flags & MASTER_PF ? "MASTER" : "SLAVE");
108083189849SRahul Lakkireddy 	} else {
108183189849SRahul Lakkireddy 		dev_info(adap, "Coming up as MASTER: Initializing adapter\n");
108283189849SRahul Lakkireddy 
108383189849SRahul Lakkireddy 		ret = adap_init0_config(adap, reset);
108483189849SRahul Lakkireddy 		if (ret == -ENOENT) {
108583189849SRahul Lakkireddy 			dev_err(adap,
108683189849SRahul Lakkireddy 				"No Configuration File present on adapter. Using hard-wired configuration parameters.\n");
108783189849SRahul Lakkireddy 			goto bye;
108883189849SRahul Lakkireddy 		}
108983189849SRahul Lakkireddy 	}
109083189849SRahul Lakkireddy 	if (ret < 0) {
109183189849SRahul Lakkireddy 		dev_err(adap, "could not initialize adapter, error %d\n", -ret);
109283189849SRahul Lakkireddy 		goto bye;
109383189849SRahul Lakkireddy 	}
109483189849SRahul Lakkireddy 
109587a3ae3eSRahul Lakkireddy 	/* Now that we've successfully configured and initialized the adapter
109687a3ae3eSRahul Lakkireddy 	 * (or found it already initialized), we can ask the Firmware what
109787a3ae3eSRahul Lakkireddy 	 * resources it has provisioned for us.
109887a3ae3eSRahul Lakkireddy 	 */
109987a3ae3eSRahul Lakkireddy 	ret = t4_get_pfres(adap);
110087a3ae3eSRahul Lakkireddy 	if (ret) {
110187a3ae3eSRahul Lakkireddy 		dev_err(adap->pdev_dev,
110287a3ae3eSRahul Lakkireddy 			"Unable to retrieve resource provisioning info\n");
110387a3ae3eSRahul Lakkireddy 		goto bye;
110487a3ae3eSRahul Lakkireddy 	}
110587a3ae3eSRahul Lakkireddy 
11065eb55bf8SRahul Lakkireddy 	/* Find out what ports are available to us. */
11075eb55bf8SRahul Lakkireddy 	v = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
11085eb55bf8SRahul Lakkireddy 	    V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_PORTVEC);
11095eb55bf8SRahul Lakkireddy 	ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1, &v, &port_vec);
11105eb55bf8SRahul Lakkireddy 	if (ret < 0) {
11115eb55bf8SRahul Lakkireddy 		dev_err(adap, "%s: failure in t4_query_params; error = %d\n",
11125eb55bf8SRahul Lakkireddy 			__func__, ret);
11135eb55bf8SRahul Lakkireddy 		goto bye;
11145eb55bf8SRahul Lakkireddy 	}
11155eb55bf8SRahul Lakkireddy 
11165eb55bf8SRahul Lakkireddy 	adap->params.nports = hweight32(port_vec);
11175eb55bf8SRahul Lakkireddy 	adap->params.portvec = port_vec;
11185eb55bf8SRahul Lakkireddy 
11195eb55bf8SRahul Lakkireddy 	dev_debug(adap, "%s: adap->params.nports = %u\n", __func__,
11205eb55bf8SRahul Lakkireddy 		  adap->params.nports);
11215eb55bf8SRahul Lakkireddy 
112283189849SRahul Lakkireddy 	/*
112383189849SRahul Lakkireddy 	 * Give the SGE code a chance to pull in anything that it needs ...
112483189849SRahul Lakkireddy 	 * Note that this must be called after we retrieve our VPD parameters
112583189849SRahul Lakkireddy 	 * in order to know how to convert core ticks to seconds, etc.
112683189849SRahul Lakkireddy 	 */
112783189849SRahul Lakkireddy 	ret = t4_sge_init(adap);
112883189849SRahul Lakkireddy 	if (ret < 0) {
112983189849SRahul Lakkireddy 		dev_err(adap, "t4_sge_init failed with error %d\n",
113083189849SRahul Lakkireddy 			-ret);
113183189849SRahul Lakkireddy 		goto bye;
113283189849SRahul Lakkireddy 	}
113383189849SRahul Lakkireddy 
113483189849SRahul Lakkireddy 	/*
113583189849SRahul Lakkireddy 	 * Grab some of our basic fundamental operating parameters.
113683189849SRahul Lakkireddy 	 */
113783189849SRahul Lakkireddy #define FW_PARAM_DEV(param) \
113883189849SRahul Lakkireddy 	(V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) | \
113983189849SRahul Lakkireddy 	 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_##param))
114083189849SRahul Lakkireddy 
114183189849SRahul Lakkireddy #define FW_PARAM_PFVF(param) \
114283189849SRahul Lakkireddy 	(V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_PFVF) | \
114383189849SRahul Lakkireddy 	 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_PFVF_##param) |  \
114483189849SRahul Lakkireddy 	 V_FW_PARAMS_PARAM_Y(0) | \
114583189849SRahul Lakkireddy 	 V_FW_PARAMS_PARAM_Z(0))
114683189849SRahul Lakkireddy 
114723af667fSShagun Agrawal 	params[0] = FW_PARAM_PFVF(L2T_START);
114823af667fSShagun Agrawal 	params[1] = FW_PARAM_PFVF(L2T_END);
114923af667fSShagun Agrawal 	params[2] = FW_PARAM_PFVF(FILTER_START);
115023af667fSShagun Agrawal 	params[3] = FW_PARAM_PFVF(FILTER_END);
115123af667fSShagun Agrawal 	ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 4, params, val);
11526f2a064bSShagun Agrawal 	if (ret < 0)
11536f2a064bSShagun Agrawal 		goto bye;
115423af667fSShagun Agrawal 	adap->l2t_start = val[0];
115523af667fSShagun Agrawal 	adap->l2t_end = val[1];
115623af667fSShagun Agrawal 	adap->tids.ftid_base = val[2];
115723af667fSShagun Agrawal 	adap->tids.nftids = val[3] - val[2] + 1;
11586f2a064bSShagun Agrawal 
11593f2c1e20SShagun Agrawal 	params[0] = FW_PARAM_PFVF(CLIP_START);
11603f2c1e20SShagun Agrawal 	params[1] = FW_PARAM_PFVF(CLIP_END);
11613f2c1e20SShagun Agrawal 	ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params, val);
11623f2c1e20SShagun Agrawal 	if (ret < 0)
11633f2c1e20SShagun Agrawal 		goto bye;
11643f2c1e20SShagun Agrawal 	adap->clipt_start = val[0];
11653f2c1e20SShagun Agrawal 	adap->clipt_end = val[1];
11663f2c1e20SShagun Agrawal 
11676f2a064bSShagun Agrawal 	/*
11686f2a064bSShagun Agrawal 	 * Get device capabilities so we can determine what resources we need
11696f2a064bSShagun Agrawal 	 * to manage.
11706f2a064bSShagun Agrawal 	 */
11716f2a064bSShagun Agrawal 	memset(&caps_cmd, 0, sizeof(caps_cmd));
11726f2a064bSShagun Agrawal 	caps_cmd.op_to_write = htonl(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
11736f2a064bSShagun Agrawal 				     F_FW_CMD_REQUEST | F_FW_CMD_READ);
11746f2a064bSShagun Agrawal 	caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd));
11756f2a064bSShagun Agrawal 	ret = t4_wr_mbox(adap, adap->mbox, &caps_cmd, sizeof(caps_cmd),
11766f2a064bSShagun Agrawal 			 &caps_cmd);
11776f2a064bSShagun Agrawal 	if (ret < 0)
11786f2a064bSShagun Agrawal 		goto bye;
11796f2a064bSShagun Agrawal 
11803a381a41SShagun Agrawal 	if ((caps_cmd.niccaps & cpu_to_be16(FW_CAPS_CONFIG_NIC_HASHFILTER)) &&
11813a381a41SShagun Agrawal 	    is_t6(adap->params.chip)) {
11823a381a41SShagun Agrawal 		if (init_hash_filter(adap) < 0)
11833a381a41SShagun Agrawal 			goto bye;
11843a381a41SShagun Agrawal 	}
11853a381a41SShagun Agrawal 
118648f523f6SRahul Lakkireddy 	/* See if FW supports FW_FILTER2 work request */
118748f523f6SRahul Lakkireddy 	if (is_t4(adap->params.chip)) {
118848f523f6SRahul Lakkireddy 		adap->params.filter2_wr_support = 0;
118948f523f6SRahul Lakkireddy 	} else {
119048f523f6SRahul Lakkireddy 		params[0] = FW_PARAM_DEV(FILTER2_WR);
119148f523f6SRahul Lakkireddy 		ret = t4_query_params(adap, adap->mbox, adap->pf, 0,
119248f523f6SRahul Lakkireddy 				      1, params, val);
119348f523f6SRahul Lakkireddy 		adap->params.filter2_wr_support = (ret == 0 && val[0] != 0);
119448f523f6SRahul Lakkireddy 	}
119548f523f6SRahul Lakkireddy 
11966f2a064bSShagun Agrawal 	/* query tid-related parameters */
11976f2a064bSShagun Agrawal 	params[0] = FW_PARAM_DEV(NTID);
11986f2a064bSShagun Agrawal 	ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1,
11996f2a064bSShagun Agrawal 			      params, val);
12006f2a064bSShagun Agrawal 	if (ret < 0)
12016f2a064bSShagun Agrawal 		goto bye;
12026f2a064bSShagun Agrawal 	adap->tids.ntids = val[0];
12033a381a41SShagun Agrawal 	adap->tids.natids = min(adap->tids.ntids / 2, MAX_ATIDS);
12046f2a064bSShagun Agrawal 
120583189849SRahul Lakkireddy 	/* If we're running on newer firmware, let it know that we're
120683189849SRahul Lakkireddy 	 * prepared to deal with encapsulated CPL messages.  Older
120783189849SRahul Lakkireddy 	 * firmware won't understand this and we'll just get
120883189849SRahul Lakkireddy 	 * unencapsulated messages ...
120983189849SRahul Lakkireddy 	 */
121083189849SRahul Lakkireddy 	params[0] = FW_PARAM_PFVF(CPLFW4MSG_ENCAP);
121183189849SRahul Lakkireddy 	val[0] = 1;
121283189849SRahul Lakkireddy 	(void)t4_set_params(adap, adap->mbox, adap->pf, 0, 1, params, val);
121383189849SRahul Lakkireddy 
121483189849SRahul Lakkireddy 	/*
121583189849SRahul Lakkireddy 	 * Find out whether we're allowed to use the T5+ ULPTX MEMWRITE DSGL
121683189849SRahul Lakkireddy 	 * capability.  Earlier versions of the firmware didn't have the
121783189849SRahul Lakkireddy 	 * ULPTX_MEMWRITE_DSGL so we'll interpret a query failure as no
121883189849SRahul Lakkireddy 	 * permission to use ULPTX MEMWRITE DSGL.
121983189849SRahul Lakkireddy 	 */
122083189849SRahul Lakkireddy 	if (is_t4(adap->params.chip)) {
122183189849SRahul Lakkireddy 		adap->params.ulptx_memwrite_dsgl = false;
122283189849SRahul Lakkireddy 	} else {
122383189849SRahul Lakkireddy 		params[0] = FW_PARAM_DEV(ULPTX_MEMWRITE_DSGL);
122483189849SRahul Lakkireddy 		ret = t4_query_params(adap, adap->mbox, adap->pf, 0,
122583189849SRahul Lakkireddy 				      1, params, val);
122683189849SRahul Lakkireddy 		adap->params.ulptx_memwrite_dsgl = (ret == 0 && val[0] != 0);
122783189849SRahul Lakkireddy 	}
122883189849SRahul Lakkireddy 
122983189849SRahul Lakkireddy 	/*
123083189849SRahul Lakkireddy 	 * The MTU/MSS Table is initialized by now, so load their values.  If
123183189849SRahul Lakkireddy 	 * we're initializing the adapter, then we'll make any modifications
123283189849SRahul Lakkireddy 	 * we want to the MTU/MSS Table and also initialize the congestion
123383189849SRahul Lakkireddy 	 * parameters.
123483189849SRahul Lakkireddy 	 */
123583189849SRahul Lakkireddy 	t4_read_mtu_tbl(adap, adap->params.mtus, NULL);
123683189849SRahul Lakkireddy 	if (state != DEV_STATE_INIT) {
123783189849SRahul Lakkireddy 		int i;
123883189849SRahul Lakkireddy 
123983189849SRahul Lakkireddy 		/*
124083189849SRahul Lakkireddy 		 * The default MTU Table contains values 1492 and 1500.
124183189849SRahul Lakkireddy 		 * However, for TCP, it's better to have two values which are
124283189849SRahul Lakkireddy 		 * a multiple of 8 +/- 4 bytes apart near this popular MTU.
124383189849SRahul Lakkireddy 		 * This allows us to have a TCP Data Payload which is a
124483189849SRahul Lakkireddy 		 * multiple of 8 regardless of what combination of TCP Options
124583189849SRahul Lakkireddy 		 * are in use (always a multiple of 4 bytes) which is
124683189849SRahul Lakkireddy 		 * important for performance reasons.  For instance, if no
124783189849SRahul Lakkireddy 		 * options are in use, then we have a 20-byte IP header and a
124883189849SRahul Lakkireddy 		 * 20-byte TCP header.  In this case, a 1500-byte MSS would
124983189849SRahul Lakkireddy 		 * result in a TCP Data Payload of 1500 - 40 == 1460 bytes
125083189849SRahul Lakkireddy 		 * which is not a multiple of 8.  So using an MSS of 1488 in
125183189849SRahul Lakkireddy 		 * this case results in a TCP Data Payload of 1448 bytes which
125283189849SRahul Lakkireddy 		 * is a multiple of 8.  On the other hand, if 12-byte TCP Time
125383189849SRahul Lakkireddy 		 * Stamps have been negotiated, then an MTU of 1500 bytes
125483189849SRahul Lakkireddy 		 * results in a TCP Data Payload of 1448 bytes which, as
125583189849SRahul Lakkireddy 		 * above, is a multiple of 8 bytes ...
125683189849SRahul Lakkireddy 		 */
125783189849SRahul Lakkireddy 		for (i = 0; i < NMTUS; i++)
125883189849SRahul Lakkireddy 			if (adap->params.mtus[i] == 1492) {
125983189849SRahul Lakkireddy 				adap->params.mtus[i] = 1488;
126083189849SRahul Lakkireddy 				break;
126183189849SRahul Lakkireddy 			}
126283189849SRahul Lakkireddy 
126383189849SRahul Lakkireddy 		t4_load_mtus(adap, adap->params.mtus, adap->params.a_wnd,
126483189849SRahul Lakkireddy 			     adap->params.b_wnd);
126583189849SRahul Lakkireddy 	}
126683189849SRahul Lakkireddy 	t4_init_sge_params(adap);
126783189849SRahul Lakkireddy 	t4_init_tp_params(adap);
1268ee606d92SRahul Lakkireddy 	configure_pcie_ext_tag(adap);
1269cda260a4SShagun Agrawal 	configure_vlan_types(adap);
1270b7fd9ea8SStephen Hemminger 	cxgbe_configure_max_ethqsets(adap);
127183189849SRahul Lakkireddy 
127283189849SRahul Lakkireddy 	adap->params.drv_memwin = MEMWIN_NIC;
127383189849SRahul Lakkireddy 	adap->flags |= FW_OK;
127483189849SRahul Lakkireddy 	dev_debug(adap, "%s: returning zero..\n", __func__);
127583189849SRahul Lakkireddy 	return 0;
127683189849SRahul Lakkireddy 
127783189849SRahul Lakkireddy 	/*
127883189849SRahul Lakkireddy 	 * Something bad happened.  If a command timed out or failed with EIO
127983189849SRahul Lakkireddy 	 * FW does not operate within its spec or something catastrophic
128083189849SRahul Lakkireddy 	 * happened to HW/FW, stop issuing commands.
128183189849SRahul Lakkireddy 	 */
128283189849SRahul Lakkireddy bye:
128383189849SRahul Lakkireddy 	if (ret != -ETIMEDOUT && ret != -EIO)
128483189849SRahul Lakkireddy 		t4_fw_bye(adap, adap->mbox);
128583189849SRahul Lakkireddy 	return ret;
128683189849SRahul Lakkireddy }
128783189849SRahul Lakkireddy 
128883189849SRahul Lakkireddy /**
128983189849SRahul Lakkireddy  * t4_os_portmod_changed - handle port module changes
129083189849SRahul Lakkireddy  * @adap: the adapter associated with the module change
129183189849SRahul Lakkireddy  * @port_id: the port index whose module status has changed
129283189849SRahul Lakkireddy  *
129383189849SRahul Lakkireddy  * This is the OS-dependent handler for port module changes.  It is
129483189849SRahul Lakkireddy  * invoked when a port module is removed or inserted for any OS-specific
129583189849SRahul Lakkireddy  * processing.
129683189849SRahul Lakkireddy  */
129783189849SRahul Lakkireddy void t4_os_portmod_changed(const struct adapter *adap, int port_id)
129883189849SRahul Lakkireddy {
129983189849SRahul Lakkireddy 	static const char * const mod_str[] = {
130083189849SRahul Lakkireddy 		NULL, "LR", "SR", "ER", "passive DA", "active DA", "LRM"
130183189849SRahul Lakkireddy 	};
130283189849SRahul Lakkireddy 
13032195df6dSRahul Lakkireddy 	const struct port_info *pi = adap2pinfo(adap, port_id);
130483189849SRahul Lakkireddy 
130583189849SRahul Lakkireddy 	if (pi->mod_type == FW_PORT_MOD_TYPE_NONE)
130683189849SRahul Lakkireddy 		dev_info(adap, "Port%d: port module unplugged\n", pi->port_id);
130783189849SRahul Lakkireddy 	else if (pi->mod_type < ARRAY_SIZE(mod_str))
130883189849SRahul Lakkireddy 		dev_info(adap, "Port%d: %s port module inserted\n", pi->port_id,
130983189849SRahul Lakkireddy 			 mod_str[pi->mod_type]);
131083189849SRahul Lakkireddy 	else if (pi->mod_type == FW_PORT_MOD_TYPE_NOTSUPPORTED)
13119da2a694SRahul Lakkireddy 		dev_info(adap, "Port%d: unsupported port module inserted\n",
131283189849SRahul Lakkireddy 			 pi->port_id);
131383189849SRahul Lakkireddy 	else if (pi->mod_type == FW_PORT_MOD_TYPE_UNKNOWN)
13149da2a694SRahul Lakkireddy 		dev_info(adap, "Port%d: unknown port module inserted\n",
131583189849SRahul Lakkireddy 			 pi->port_id);
131683189849SRahul Lakkireddy 	else if (pi->mod_type == FW_PORT_MOD_TYPE_ERROR)
131783189849SRahul Lakkireddy 		dev_info(adap, "Port%d: transceiver module error\n",
131883189849SRahul Lakkireddy 			 pi->port_id);
131983189849SRahul Lakkireddy 	else
132083189849SRahul Lakkireddy 		dev_info(adap, "Port%d: unknown module type %d inserted\n",
132183189849SRahul Lakkireddy 			 pi->port_id, pi->mod_type);
132283189849SRahul Lakkireddy }
132383189849SRahul Lakkireddy 
1324b7fd9ea8SStephen Hemminger bool cxgbe_force_linkup(struct adapter *adap)
1325f5b3c7b2SShagun Agrawal {
1326f5b3c7b2SShagun Agrawal 	struct rte_pci_device *pdev = adap->pdev;
1327f5b3c7b2SShagun Agrawal 
1328f5b3c7b2SShagun Agrawal 	if (is_pf4(adap))
1329f5b3c7b2SShagun Agrawal 		return false;	/* force_linkup not required for pf driver*/
1330f5b3c7b2SShagun Agrawal 	if (!cxgbe_get_devargs(pdev->device.devargs,
1331f5b3c7b2SShagun Agrawal 			       CXGBE_DEVARG_FORCE_LINK_UP))
1332f5b3c7b2SShagun Agrawal 		return false;
1333f5b3c7b2SShagun Agrawal 	return true;
1334f5b3c7b2SShagun Agrawal }
1335f5b3c7b2SShagun Agrawal 
133692c8a632SRahul Lakkireddy /**
13370462d115SRahul Lakkireddy  * link_start - enable a port
13380462d115SRahul Lakkireddy  * @dev: the port to enable
13390462d115SRahul Lakkireddy  *
13400462d115SRahul Lakkireddy  * Performs the MAC and PHY actions needed to enable a port.
13410462d115SRahul Lakkireddy  */
1342b7fd9ea8SStephen Hemminger int cxgbe_link_start(struct port_info *pi)
13430462d115SRahul Lakkireddy {
13440462d115SRahul Lakkireddy 	struct adapter *adapter = pi->adapter;
13456507fb6fSRahul Lakkireddy 	u64 conf_offloads;
13465a9e303aSRahul Lakkireddy 	unsigned int mtu;
13476507fb6fSRahul Lakkireddy 	int ret;
13485a9e303aSRahul Lakkireddy 
13495a9e303aSRahul Lakkireddy 	mtu = pi->eth_dev->data->dev_conf.rxmode.max_rx_pkt_len -
135035b2d13fSOlivier Matz 	      (RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN);
13510462d115SRahul Lakkireddy 
13526507fb6fSRahul Lakkireddy 	conf_offloads = pi->eth_dev->data->dev_conf.rxmode.offloads;
13536507fb6fSRahul Lakkireddy 
13540462d115SRahul Lakkireddy 	/*
13550462d115SRahul Lakkireddy 	 * We do not set address filters and promiscuity here, the stack does
13560462d115SRahul Lakkireddy 	 * that step explicitly.
13570462d115SRahul Lakkireddy 	 */
13586507fb6fSRahul Lakkireddy 	ret = t4_set_rxmode(adapter, adapter->mbox, pi->viid, mtu, -1, -1, -1,
13596507fb6fSRahul Lakkireddy 			    !!(conf_offloads & DEV_RX_OFFLOAD_VLAN_STRIP),
13606507fb6fSRahul Lakkireddy 			    true);
13610462d115SRahul Lakkireddy 	if (ret == 0) {
1362fefee7a6SShagun Agrawal 		ret = cxgbe_mpstcam_modify(pi, (int)pi->xact_addr_filt,
1363fefee7a6SShagun Agrawal 				(u8 *)&pi->eth_dev->data->mac_addrs[0]);
13640462d115SRahul Lakkireddy 		if (ret >= 0) {
13650462d115SRahul Lakkireddy 			pi->xact_addr_filt = ret;
13660462d115SRahul Lakkireddy 			ret = 0;
13670462d115SRahul Lakkireddy 		}
13680462d115SRahul Lakkireddy 	}
13695e80364aSKumar Sanghvi 	if (ret == 0 && is_pf4(adapter))
13700462d115SRahul Lakkireddy 		ret = t4_link_l1cfg(adapter, adapter->mbox, pi->tx_chan,
13710462d115SRahul Lakkireddy 				    &pi->link_cfg);
13720462d115SRahul Lakkireddy 	if (ret == 0) {
13730462d115SRahul Lakkireddy 		/*
13740462d115SRahul Lakkireddy 		 * Enabling a Virtual Interface can result in an interrupt
13750462d115SRahul Lakkireddy 		 * during the processing of the VI Enable command and, in some
13760462d115SRahul Lakkireddy 		 * paths, result in an attempt to issue another command in the
13770462d115SRahul Lakkireddy 		 * interrupt context.  Thus, we disable interrupts during the
13780462d115SRahul Lakkireddy 		 * course of the VI Enable command ...
13790462d115SRahul Lakkireddy 		 */
13800462d115SRahul Lakkireddy 		ret = t4_enable_vi_params(adapter, adapter->mbox, pi->viid,
13810462d115SRahul Lakkireddy 					  true, true, false);
13820462d115SRahul Lakkireddy 	}
1383f5b3c7b2SShagun Agrawal 
1384b7fd9ea8SStephen Hemminger 	if (ret == 0 && cxgbe_force_linkup(adapter))
1385f5b3c7b2SShagun Agrawal 		pi->eth_dev->data->dev_link.link_status = ETH_LINK_UP;
13860462d115SRahul Lakkireddy 	return ret;
13870462d115SRahul Lakkireddy }
13880462d115SRahul Lakkireddy 
13890462d115SRahul Lakkireddy /**
139008e21af9SKumar Sanghvi  * cxgbe_write_rss_conf - flash the RSS configuration for a given port
139108e21af9SKumar Sanghvi  * @pi: the port
139208e21af9SKumar Sanghvi  * @rss_hf: Hash configuration to apply
139308e21af9SKumar Sanghvi  */
139408e21af9SKumar Sanghvi int cxgbe_write_rss_conf(const struct port_info *pi, uint64_t rss_hf)
139508e21af9SKumar Sanghvi {
139608e21af9SKumar Sanghvi 	struct adapter *adapter = pi->adapter;
139708e21af9SKumar Sanghvi 	const struct sge_eth_rxq *rxq;
139808e21af9SKumar Sanghvi 	u64 flags = 0;
139908e21af9SKumar Sanghvi 	u16 rss;
140008e21af9SKumar Sanghvi 	int err;
140108e21af9SKumar Sanghvi 
140208e21af9SKumar Sanghvi 	/*  Should never be called before setting up sge eth rx queues */
140308e21af9SKumar Sanghvi 	if (!(adapter->flags & FULL_INIT_DONE)) {
140408e21af9SKumar Sanghvi 		dev_err(adap, "%s No RXQs available on port %d\n",
140508e21af9SKumar Sanghvi 			__func__, pi->port_id);
140608e21af9SKumar Sanghvi 		return -EINVAL;
140708e21af9SKumar Sanghvi 	}
140808e21af9SKumar Sanghvi 
140908e21af9SKumar Sanghvi 	/* Don't allow unsupported hash functions */
141008e21af9SKumar Sanghvi 	if (rss_hf & ~CXGBE_RSS_HF_ALL)
141108e21af9SKumar Sanghvi 		return -EINVAL;
141208e21af9SKumar Sanghvi 
1413d97aa415SRahul Lakkireddy 	if (rss_hf & CXGBE_RSS_HF_IPV4_MASK)
141408e21af9SKumar Sanghvi 		flags |= F_FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN;
141508e21af9SKumar Sanghvi 
141608e21af9SKumar Sanghvi 	if (rss_hf & ETH_RSS_NONFRAG_IPV4_TCP)
141708e21af9SKumar Sanghvi 		flags |= F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN;
141808e21af9SKumar Sanghvi 
141908e21af9SKumar Sanghvi 	if (rss_hf & ETH_RSS_NONFRAG_IPV4_UDP)
142008e21af9SKumar Sanghvi 		flags |= F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN |
142108e21af9SKumar Sanghvi 			 F_FW_RSS_VI_CONFIG_CMD_UDPEN;
142208e21af9SKumar Sanghvi 
1423d97aa415SRahul Lakkireddy 	if (rss_hf & CXGBE_RSS_HF_IPV6_MASK)
142408e21af9SKumar Sanghvi 		flags |= F_FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN;
142508e21af9SKumar Sanghvi 
1426d97aa415SRahul Lakkireddy 	if (rss_hf & CXGBE_RSS_HF_TCP_IPV6_MASK)
1427d97aa415SRahul Lakkireddy 		flags |= F_FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN |
1428d97aa415SRahul Lakkireddy 			 F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN;
142908e21af9SKumar Sanghvi 
1430d97aa415SRahul Lakkireddy 	if (rss_hf & CXGBE_RSS_HF_UDP_IPV6_MASK)
1431d97aa415SRahul Lakkireddy 		flags |= F_FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN |
1432d97aa415SRahul Lakkireddy 			 F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN |
143308e21af9SKumar Sanghvi 			 F_FW_RSS_VI_CONFIG_CMD_UDPEN;
143408e21af9SKumar Sanghvi 
143508e21af9SKumar Sanghvi 	rxq = &adapter->sge.ethrxq[pi->first_qset];
143608e21af9SKumar Sanghvi 	rss = rxq[0].rspq.abs_id;
143708e21af9SKumar Sanghvi 
143808e21af9SKumar Sanghvi 	/* If Tunnel All Lookup isn't specified in the global RSS
143908e21af9SKumar Sanghvi 	 * Configuration, then we need to specify a default Ingress
144008e21af9SKumar Sanghvi 	 * Queue for any ingress packets which aren't hashed.  We'll
144108e21af9SKumar Sanghvi 	 * use our first ingress queue ...
144208e21af9SKumar Sanghvi 	 */
144308e21af9SKumar Sanghvi 	err = t4_config_vi_rss(adapter, adapter->mbox, pi->viid,
144408e21af9SKumar Sanghvi 			       flags, rss);
144508e21af9SKumar Sanghvi 	return err;
144608e21af9SKumar Sanghvi }
144708e21af9SKumar Sanghvi 
144808e21af9SKumar Sanghvi /**
144908e21af9SKumar Sanghvi  * cxgbe_write_rss - write the RSS table for a given port
145092c8a632SRahul Lakkireddy  * @pi: the port
145192c8a632SRahul Lakkireddy  * @queues: array of queue indices for RSS
145292c8a632SRahul Lakkireddy  *
145392c8a632SRahul Lakkireddy  * Sets up the portion of the HW RSS table for the port's VI to distribute
145492c8a632SRahul Lakkireddy  * packets to the Rx queues in @queues.
145592c8a632SRahul Lakkireddy  */
145608e21af9SKumar Sanghvi int cxgbe_write_rss(const struct port_info *pi, const u16 *queues)
145792c8a632SRahul Lakkireddy {
145892c8a632SRahul Lakkireddy 	u16 *rss;
145992c8a632SRahul Lakkireddy 	int i, err;
146092c8a632SRahul Lakkireddy 	struct adapter *adapter = pi->adapter;
146192c8a632SRahul Lakkireddy 	const struct sge_eth_rxq *rxq;
146292c8a632SRahul Lakkireddy 
146392c8a632SRahul Lakkireddy 	/*  Should never be called before setting up sge eth rx queues */
146492c8a632SRahul Lakkireddy 	BUG_ON(!(adapter->flags & FULL_INIT_DONE));
146592c8a632SRahul Lakkireddy 
146692c8a632SRahul Lakkireddy 	rxq = &adapter->sge.ethrxq[pi->first_qset];
146792c8a632SRahul Lakkireddy 	rss = rte_zmalloc(NULL, pi->rss_size * sizeof(u16), 0);
146892c8a632SRahul Lakkireddy 	if (!rss)
146992c8a632SRahul Lakkireddy 		return -ENOMEM;
147092c8a632SRahul Lakkireddy 
147192c8a632SRahul Lakkireddy 	/* map the queue indices to queue ids */
147292c8a632SRahul Lakkireddy 	for (i = 0; i < pi->rss_size; i++, queues++)
147392c8a632SRahul Lakkireddy 		rss[i] = rxq[*queues].rspq.abs_id;
147492c8a632SRahul Lakkireddy 
147592c8a632SRahul Lakkireddy 	err = t4_config_rss_range(adapter, adapter->pf, pi->viid, 0,
147692c8a632SRahul Lakkireddy 				  pi->rss_size, rss, pi->rss_size);
147792c8a632SRahul Lakkireddy 	rte_free(rss);
147892c8a632SRahul Lakkireddy 	return err;
147992c8a632SRahul Lakkireddy }
148092c8a632SRahul Lakkireddy 
148192c8a632SRahul Lakkireddy /**
148292c8a632SRahul Lakkireddy  * setup_rss - configure RSS
148392c8a632SRahul Lakkireddy  * @adapter: the adapter
148492c8a632SRahul Lakkireddy  *
148592c8a632SRahul Lakkireddy  * Sets up RSS to distribute packets to multiple receive queues.  We
148692c8a632SRahul Lakkireddy  * configure the RSS CPU lookup table to distribute to the number of HW
148792c8a632SRahul Lakkireddy  * receive queues, and the response queue lookup table to narrow that
148892c8a632SRahul Lakkireddy  * down to the response queues actually configured for each port.
148992c8a632SRahul Lakkireddy  * We always configure the RSS mapping for all ports since the mapping
149092c8a632SRahul Lakkireddy  * table has plenty of entries.
149192c8a632SRahul Lakkireddy  */
1492b7fd9ea8SStephen Hemminger int cxgbe_setup_rss(struct port_info *pi)
149392c8a632SRahul Lakkireddy {
149492c8a632SRahul Lakkireddy 	int j, err;
149592c8a632SRahul Lakkireddy 	struct adapter *adapter = pi->adapter;
149692c8a632SRahul Lakkireddy 
149792c8a632SRahul Lakkireddy 	dev_debug(adapter, "%s:  pi->rss_size = %u; pi->n_rx_qsets = %u\n",
149892c8a632SRahul Lakkireddy 		  __func__, pi->rss_size, pi->n_rx_qsets);
149992c8a632SRahul Lakkireddy 
15001039ee1cSEmmanuel Roullit 	if (!(pi->flags & PORT_RSS_DONE)) {
150192c8a632SRahul Lakkireddy 		if (adapter->flags & FULL_INIT_DONE) {
150292c8a632SRahul Lakkireddy 			/* Fill default values with equal distribution */
150392c8a632SRahul Lakkireddy 			for (j = 0; j < pi->rss_size; j++)
150492c8a632SRahul Lakkireddy 				pi->rss[j] = j % pi->n_rx_qsets;
150592c8a632SRahul Lakkireddy 
150608e21af9SKumar Sanghvi 			err = cxgbe_write_rss(pi, pi->rss);
150708e21af9SKumar Sanghvi 			if (err)
150808e21af9SKumar Sanghvi 				return err;
150908e21af9SKumar Sanghvi 
151008e21af9SKumar Sanghvi 			err = cxgbe_write_rss_conf(pi, pi->rss_hf);
151192c8a632SRahul Lakkireddy 			if (err)
151292c8a632SRahul Lakkireddy 				return err;
151392c8a632SRahul Lakkireddy 			pi->flags |= PORT_RSS_DONE;
151492c8a632SRahul Lakkireddy 		}
151592c8a632SRahul Lakkireddy 	}
151692c8a632SRahul Lakkireddy 	return 0;
151792c8a632SRahul Lakkireddy }
151892c8a632SRahul Lakkireddy 
15190462d115SRahul Lakkireddy /*
15200462d115SRahul Lakkireddy  * Enable NAPI scheduling and interrupt generation for all Rx queues.
15210462d115SRahul Lakkireddy  */
1522d87ba24dSRahul Lakkireddy static void enable_rx(struct adapter *adap, struct sge_rspq *q)
15230462d115SRahul Lakkireddy {
15240462d115SRahul Lakkireddy 	/* 0-increment GTS to start the timer and enable interrupts */
15255e59e39aSKumar Sanghvi 	t4_write_reg(adap, is_pf4(adap) ? MYPF_REG(A_SGE_PF_GTS) :
15265e59e39aSKumar Sanghvi 					  T4VF_SGE_BASE_ADDR + A_SGE_VF_GTS,
15270462d115SRahul Lakkireddy 		     V_SEINTARM(q->intr_params) |
15280462d115SRahul Lakkireddy 		     V_INGRESSQID(q->cntxt_id));
15290462d115SRahul Lakkireddy }
1530d87ba24dSRahul Lakkireddy 
1531d87ba24dSRahul Lakkireddy void cxgbe_enable_rx_queues(struct port_info *pi)
1532d87ba24dSRahul Lakkireddy {
1533d87ba24dSRahul Lakkireddy 	struct adapter *adap = pi->adapter;
1534d87ba24dSRahul Lakkireddy 	struct sge *s = &adap->sge;
1535d87ba24dSRahul Lakkireddy 	unsigned int i;
1536d87ba24dSRahul Lakkireddy 
1537d87ba24dSRahul Lakkireddy 	for (i = 0; i < pi->n_rx_qsets; i++)
1538d87ba24dSRahul Lakkireddy 		enable_rx(adap, &s->ethrxq[pi->first_qset + i].rspq);
15390462d115SRahul Lakkireddy }
15400462d115SRahul Lakkireddy 
15410462d115SRahul Lakkireddy /**
1542e307e65bSRahul Lakkireddy  * fw_caps_to_speed_caps - translate Firmware Port Caps to Speed Caps.
1543e307e65bSRahul Lakkireddy  * @port_type: Firmware Port Type
1544e307e65bSRahul Lakkireddy  * @fw_caps: Firmware Port Capabilities
1545e307e65bSRahul Lakkireddy  * @speed_caps: Device Info Speed Capabilities
1546e307e65bSRahul Lakkireddy  *
1547e307e65bSRahul Lakkireddy  * Translate a Firmware Port Capabilities specification to Device Info
1548e307e65bSRahul Lakkireddy  * Speed Capabilities.
1549e307e65bSRahul Lakkireddy  */
1550e307e65bSRahul Lakkireddy static void fw_caps_to_speed_caps(enum fw_port_type port_type,
1551e307e65bSRahul Lakkireddy 				  unsigned int fw_caps,
1552e307e65bSRahul Lakkireddy 				  u32 *speed_caps)
1553e307e65bSRahul Lakkireddy {
1554e307e65bSRahul Lakkireddy #define SET_SPEED(__speed_name) \
1555e307e65bSRahul Lakkireddy 	do { \
1556e307e65bSRahul Lakkireddy 		*speed_caps |= ETH_LINK_ ## __speed_name; \
1557e307e65bSRahul Lakkireddy 	} while (0)
1558e307e65bSRahul Lakkireddy 
1559e307e65bSRahul Lakkireddy #define FW_CAPS_TO_SPEED(__fw_name) \
1560e307e65bSRahul Lakkireddy 	do { \
156176488837SRahul Lakkireddy 		if (fw_caps & FW_PORT_CAP32_ ## __fw_name) \
1562e307e65bSRahul Lakkireddy 			SET_SPEED(__fw_name); \
1563e307e65bSRahul Lakkireddy 	} while (0)
1564e307e65bSRahul Lakkireddy 
1565e307e65bSRahul Lakkireddy 	switch (port_type) {
1566e307e65bSRahul Lakkireddy 	case FW_PORT_TYPE_BT_SGMII:
1567e307e65bSRahul Lakkireddy 	case FW_PORT_TYPE_BT_XFI:
1568e307e65bSRahul Lakkireddy 	case FW_PORT_TYPE_BT_XAUI:
1569e307e65bSRahul Lakkireddy 		FW_CAPS_TO_SPEED(SPEED_100M);
1570e307e65bSRahul Lakkireddy 		FW_CAPS_TO_SPEED(SPEED_1G);
1571e307e65bSRahul Lakkireddy 		FW_CAPS_TO_SPEED(SPEED_10G);
1572e307e65bSRahul Lakkireddy 		break;
1573e307e65bSRahul Lakkireddy 
1574e307e65bSRahul Lakkireddy 	case FW_PORT_TYPE_KX4:
1575e307e65bSRahul Lakkireddy 	case FW_PORT_TYPE_KX:
1576e307e65bSRahul Lakkireddy 	case FW_PORT_TYPE_FIBER_XFI:
1577e307e65bSRahul Lakkireddy 	case FW_PORT_TYPE_FIBER_XAUI:
1578e307e65bSRahul Lakkireddy 	case FW_PORT_TYPE_SFP:
1579e307e65bSRahul Lakkireddy 	case FW_PORT_TYPE_QSFP_10G:
1580e307e65bSRahul Lakkireddy 	case FW_PORT_TYPE_QSA:
1581e307e65bSRahul Lakkireddy 		FW_CAPS_TO_SPEED(SPEED_1G);
1582e307e65bSRahul Lakkireddy 		FW_CAPS_TO_SPEED(SPEED_10G);
1583e307e65bSRahul Lakkireddy 		break;
1584e307e65bSRahul Lakkireddy 
1585e307e65bSRahul Lakkireddy 	case FW_PORT_TYPE_KR:
1586e307e65bSRahul Lakkireddy 		SET_SPEED(SPEED_10G);
1587e307e65bSRahul Lakkireddy 		break;
1588e307e65bSRahul Lakkireddy 
1589e307e65bSRahul Lakkireddy 	case FW_PORT_TYPE_BP_AP:
1590e307e65bSRahul Lakkireddy 	case FW_PORT_TYPE_BP4_AP:
1591e307e65bSRahul Lakkireddy 		SET_SPEED(SPEED_1G);
1592e307e65bSRahul Lakkireddy 		SET_SPEED(SPEED_10G);
1593e307e65bSRahul Lakkireddy 		break;
1594e307e65bSRahul Lakkireddy 
1595e307e65bSRahul Lakkireddy 	case FW_PORT_TYPE_BP40_BA:
1596e307e65bSRahul Lakkireddy 	case FW_PORT_TYPE_QSFP:
1597e307e65bSRahul Lakkireddy 		SET_SPEED(SPEED_40G);
1598e307e65bSRahul Lakkireddy 		break;
1599e307e65bSRahul Lakkireddy 
1600e307e65bSRahul Lakkireddy 	case FW_PORT_TYPE_CR_QSFP:
1601e307e65bSRahul Lakkireddy 	case FW_PORT_TYPE_SFP28:
1602e307e65bSRahul Lakkireddy 	case FW_PORT_TYPE_KR_SFP28:
1603e307e65bSRahul Lakkireddy 		FW_CAPS_TO_SPEED(SPEED_1G);
1604e307e65bSRahul Lakkireddy 		FW_CAPS_TO_SPEED(SPEED_10G);
1605e307e65bSRahul Lakkireddy 		FW_CAPS_TO_SPEED(SPEED_25G);
1606e307e65bSRahul Lakkireddy 		break;
1607e307e65bSRahul Lakkireddy 
1608e307e65bSRahul Lakkireddy 	case FW_PORT_TYPE_CR2_QSFP:
1609e307e65bSRahul Lakkireddy 		SET_SPEED(SPEED_50G);
1610e307e65bSRahul Lakkireddy 		break;
1611e307e65bSRahul Lakkireddy 
1612e307e65bSRahul Lakkireddy 	case FW_PORT_TYPE_KR4_100G:
1613e307e65bSRahul Lakkireddy 	case FW_PORT_TYPE_CR4_QSFP:
1614e307e65bSRahul Lakkireddy 		FW_CAPS_TO_SPEED(SPEED_25G);
1615e307e65bSRahul Lakkireddy 		FW_CAPS_TO_SPEED(SPEED_40G);
161676488837SRahul Lakkireddy 		FW_CAPS_TO_SPEED(SPEED_50G);
1617e307e65bSRahul Lakkireddy 		FW_CAPS_TO_SPEED(SPEED_100G);
1618e307e65bSRahul Lakkireddy 		break;
1619e307e65bSRahul Lakkireddy 
1620e307e65bSRahul Lakkireddy 	default:
1621e307e65bSRahul Lakkireddy 		break;
1622e307e65bSRahul Lakkireddy 	}
1623e307e65bSRahul Lakkireddy 
1624e307e65bSRahul Lakkireddy #undef FW_CAPS_TO_SPEED
1625e307e65bSRahul Lakkireddy #undef SET_SPEED
1626e307e65bSRahul Lakkireddy }
1627e307e65bSRahul Lakkireddy 
1628e307e65bSRahul Lakkireddy /**
1629e307e65bSRahul Lakkireddy  * cxgbe_get_speed_caps - Fetch supported speed capabilities
1630e307e65bSRahul Lakkireddy  * @pi: Underlying port's info
1631e307e65bSRahul Lakkireddy  * @speed_caps: Device Info speed capabilities
1632e307e65bSRahul Lakkireddy  *
1633e307e65bSRahul Lakkireddy  * Fetch supported speed capabilities of the underlying port.
1634e307e65bSRahul Lakkireddy  */
1635e307e65bSRahul Lakkireddy void cxgbe_get_speed_caps(struct port_info *pi, u32 *speed_caps)
1636e307e65bSRahul Lakkireddy {
1637e307e65bSRahul Lakkireddy 	*speed_caps = 0;
1638e307e65bSRahul Lakkireddy 
163976488837SRahul Lakkireddy 	fw_caps_to_speed_caps(pi->port_type, pi->link_cfg.pcaps,
1640e307e65bSRahul Lakkireddy 			      speed_caps);
1641e307e65bSRahul Lakkireddy 
164276488837SRahul Lakkireddy 	if (!(pi->link_cfg.pcaps & FW_PORT_CAP32_ANEG))
1643e307e65bSRahul Lakkireddy 		*speed_caps |= ETH_LINK_SPEED_FIXED;
1644e307e65bSRahul Lakkireddy }
1645e307e65bSRahul Lakkireddy 
1646e307e65bSRahul Lakkireddy /**
1647265af08eSRahul Lakkireddy  * cxgbe_set_link_status - Set device link up or down.
1648265af08eSRahul Lakkireddy  * @pi: Underlying port's info
1649265af08eSRahul Lakkireddy  * @status: 0 - down, 1 - up
1650265af08eSRahul Lakkireddy  *
1651265af08eSRahul Lakkireddy  * Set the device link up or down.
1652265af08eSRahul Lakkireddy  */
1653265af08eSRahul Lakkireddy int cxgbe_set_link_status(struct port_info *pi, bool status)
1654265af08eSRahul Lakkireddy {
1655265af08eSRahul Lakkireddy 	struct adapter *adapter = pi->adapter;
1656265af08eSRahul Lakkireddy 	int err = 0;
1657265af08eSRahul Lakkireddy 
1658265af08eSRahul Lakkireddy 	err = t4_enable_vi(adapter, adapter->mbox, pi->viid, status, status);
1659265af08eSRahul Lakkireddy 	if (err) {
1660265af08eSRahul Lakkireddy 		dev_err(adapter, "%s: disable_vi failed: %d\n", __func__, err);
1661265af08eSRahul Lakkireddy 		return err;
1662265af08eSRahul Lakkireddy 	}
1663265af08eSRahul Lakkireddy 
1664265af08eSRahul Lakkireddy 	if (!status)
1665265af08eSRahul Lakkireddy 		t4_reset_link_config(adapter, pi->pidx);
1666265af08eSRahul Lakkireddy 
1667265af08eSRahul Lakkireddy 	return 0;
1668265af08eSRahul Lakkireddy }
1669265af08eSRahul Lakkireddy 
1670265af08eSRahul Lakkireddy /**
16710462d115SRahul Lakkireddy  * cxgb_up - enable the adapter
16720462d115SRahul Lakkireddy  * @adap: adapter being enabled
16730462d115SRahul Lakkireddy  *
16740462d115SRahul Lakkireddy  * Called when the first port is enabled, this function performs the
16750462d115SRahul Lakkireddy  * actions necessary to make an adapter operational, such as completing
16760462d115SRahul Lakkireddy  * the initialization of HW modules, and enabling interrupts.
16770462d115SRahul Lakkireddy  */
16780462d115SRahul Lakkireddy int cxgbe_up(struct adapter *adap)
16790462d115SRahul Lakkireddy {
1680d87ba24dSRahul Lakkireddy 	enable_rx(adap, &adap->sge.fw_evtq);
16810462d115SRahul Lakkireddy 	t4_sge_tx_monitor_start(adap);
16825e80364aSKumar Sanghvi 	if (is_pf4(adap))
16830462d115SRahul Lakkireddy 		t4_intr_enable(adap);
16840462d115SRahul Lakkireddy 	adap->flags |= FULL_INIT_DONE;
16850462d115SRahul Lakkireddy 
16860462d115SRahul Lakkireddy 	/* TODO: deadman watchdog ?? */
16870462d115SRahul Lakkireddy 	return 0;
16880462d115SRahul Lakkireddy }
16890462d115SRahul Lakkireddy 
16900462d115SRahul Lakkireddy /*
16910462d115SRahul Lakkireddy  * Close the port
16920462d115SRahul Lakkireddy  */
16930462d115SRahul Lakkireddy int cxgbe_down(struct port_info *pi)
16940462d115SRahul Lakkireddy {
1695265af08eSRahul Lakkireddy 	return cxgbe_set_link_status(pi, false);
16960462d115SRahul Lakkireddy }
16970462d115SRahul Lakkireddy 
16980462d115SRahul Lakkireddy /*
16990462d115SRahul Lakkireddy  * Release resources when all the ports have been stopped.
17000462d115SRahul Lakkireddy  */
17010462d115SRahul Lakkireddy void cxgbe_close(struct adapter *adapter)
17020462d115SRahul Lakkireddy {
17030462d115SRahul Lakkireddy 	struct port_info *pi;
17040462d115SRahul Lakkireddy 	int i;
17050462d115SRahul Lakkireddy 
17060462d115SRahul Lakkireddy 	if (adapter->flags & FULL_INIT_DONE) {
17076f2a064bSShagun Agrawal 		tid_free(&adapter->tids);
17086fda3f0dSShagun Agrawal 		t4_cleanup_mpstcam(adapter);
17093f2c1e20SShagun Agrawal 		t4_cleanup_clip_tbl(adapter);
171023af667fSShagun Agrawal 		t4_cleanup_l2t(adapter);
171123af667fSShagun Agrawal 		if (is_pf4(adapter))
171223af667fSShagun Agrawal 			t4_intr_disable(adapter);
17130462d115SRahul Lakkireddy 		t4_sge_tx_monitor_stop(adapter);
17140462d115SRahul Lakkireddy 		t4_free_sge_resources(adapter);
17150462d115SRahul Lakkireddy 		for_each_port(adapter, i) {
17160462d115SRahul Lakkireddy 			pi = adap2pinfo(adapter, i);
17170462d115SRahul Lakkireddy 			if (pi->viid != 0)
17180462d115SRahul Lakkireddy 				t4_free_vi(adapter, adapter->mbox,
17190462d115SRahul Lakkireddy 					   adapter->pf, 0, pi->viid);
17202195df6dSRahul Lakkireddy 			rte_eth_dev_release_port(pi->eth_dev);
17212195df6dSRahul Lakkireddy 		}
17220462d115SRahul Lakkireddy 		adapter->flags &= ~FULL_INIT_DONE;
17230462d115SRahul Lakkireddy 	}
17240462d115SRahul Lakkireddy 
17255e80364aSKumar Sanghvi 	if (is_pf4(adapter) && (adapter->flags & FW_OK))
17260462d115SRahul Lakkireddy 		t4_fw_bye(adapter, adapter->mbox);
17270462d115SRahul Lakkireddy }
17280462d115SRahul Lakkireddy 
172983189849SRahul Lakkireddy int cxgbe_probe(struct adapter *adapter)
173083189849SRahul Lakkireddy {
173183189849SRahul Lakkireddy 	struct port_info *pi;
173204868e5bSRahul Lakkireddy 	int chip;
173383189849SRahul Lakkireddy 	int func, i;
173483189849SRahul Lakkireddy 	int err = 0;
173504868e5bSRahul Lakkireddy 	u32 whoami;
173683189849SRahul Lakkireddy 
173704868e5bSRahul Lakkireddy 	whoami = t4_read_reg(adapter, A_PL_WHOAMI);
173804868e5bSRahul Lakkireddy 	chip = t4_get_chip_type(adapter,
173904868e5bSRahul Lakkireddy 			CHELSIO_PCI_ID_VER(adapter->pdev->id.device_id));
174004868e5bSRahul Lakkireddy 	if (chip < 0)
174104868e5bSRahul Lakkireddy 		return chip;
174204868e5bSRahul Lakkireddy 
174304868e5bSRahul Lakkireddy 	func = CHELSIO_CHIP_VERSION(chip) <= CHELSIO_T5 ?
174404868e5bSRahul Lakkireddy 	       G_SOURCEPF(whoami) : G_T6_SOURCEPF(whoami);
174504868e5bSRahul Lakkireddy 
174683189849SRahul Lakkireddy 	adapter->mbox = func;
174783189849SRahul Lakkireddy 	adapter->pf = func;
174883189849SRahul Lakkireddy 
174983189849SRahul Lakkireddy 	t4_os_lock_init(&adapter->mbox_lock);
175083189849SRahul Lakkireddy 	TAILQ_INIT(&adapter->mbox_list);
17518d3c12e1SShagun Agrawal 	t4_os_lock_init(&adapter->win0_lock);
175283189849SRahul Lakkireddy 
175383189849SRahul Lakkireddy 	err = t4_prep_adapter(adapter);
175483189849SRahul Lakkireddy 	if (err)
175583189849SRahul Lakkireddy 		return err;
175683189849SRahul Lakkireddy 
175783189849SRahul Lakkireddy 	setup_memwin(adapter);
175883189849SRahul Lakkireddy 	err = adap_init0(adapter);
175983189849SRahul Lakkireddy 	if (err) {
176083189849SRahul Lakkireddy 		dev_err(adapter, "%s: Adapter initialization failed, error %d\n",
176183189849SRahul Lakkireddy 			__func__, err);
176283189849SRahul Lakkireddy 		goto out_free;
176383189849SRahul Lakkireddy 	}
176483189849SRahul Lakkireddy 
176583189849SRahul Lakkireddy 	if (!is_t4(adapter->params.chip)) {
176683189849SRahul Lakkireddy 		/*
176783189849SRahul Lakkireddy 		 * The userspace doorbell BAR is split evenly into doorbell
176883189849SRahul Lakkireddy 		 * regions, each associated with an egress queue.  If this
176983189849SRahul Lakkireddy 		 * per-queue region is large enough (at least UDBS_SEG_SIZE)
177083189849SRahul Lakkireddy 		 * then it can be used to submit a tx work request with an
177183189849SRahul Lakkireddy 		 * implied doorbell.  Enable write combining on the BAR if
177283189849SRahul Lakkireddy 		 * there is room for such work requests.
177383189849SRahul Lakkireddy 		 */
177483189849SRahul Lakkireddy 		int s_qpp, qpp, num_seg;
177583189849SRahul Lakkireddy 
177683189849SRahul Lakkireddy 		s_qpp = (S_QUEUESPERPAGEPF0 +
177783189849SRahul Lakkireddy 			(S_QUEUESPERPAGEPF1 - S_QUEUESPERPAGEPF0) *
177883189849SRahul Lakkireddy 			adapter->pf);
177983189849SRahul Lakkireddy 		qpp = 1 << ((t4_read_reg(adapter,
178083189849SRahul Lakkireddy 				A_SGE_EGRESS_QUEUES_PER_PAGE_PF) >> s_qpp)
178183189849SRahul Lakkireddy 				& M_QUEUESPERPAGEPF0);
17821f8613f1SRahul Lakkireddy 		num_seg = CXGBE_PAGE_SIZE / UDBS_SEG_SIZE;
178383189849SRahul Lakkireddy 		if (qpp > num_seg)
178483189849SRahul Lakkireddy 			dev_warn(adapter, "Incorrect SGE EGRESS QUEUES_PER_PAGE configuration, continuing in debug mode\n");
178583189849SRahul Lakkireddy 
178683189849SRahul Lakkireddy 		adapter->bar2 = (void *)adapter->pdev->mem_resource[2].addr;
178783189849SRahul Lakkireddy 		if (!adapter->bar2) {
178883189849SRahul Lakkireddy 			dev_err(adapter, "cannot map device bar2 region\n");
178983189849SRahul Lakkireddy 			err = -ENOMEM;
179083189849SRahul Lakkireddy 			goto out_free;
179183189849SRahul Lakkireddy 		}
179283189849SRahul Lakkireddy 		t4_write_reg(adapter, A_SGE_STAT_CFG, V_STATSOURCE_T5(7) |
179383189849SRahul Lakkireddy 			     V_STATMODE(0));
179483189849SRahul Lakkireddy 	}
179583189849SRahul Lakkireddy 
179683189849SRahul Lakkireddy 	for_each_port(adapter, i) {
179783189849SRahul Lakkireddy 		const unsigned int numa_node = rte_socket_id();
17982195df6dSRahul Lakkireddy 		char name[RTE_ETH_NAME_MAX_LEN];
17992195df6dSRahul Lakkireddy 		struct rte_eth_dev *eth_dev;
180083189849SRahul Lakkireddy 
18012195df6dSRahul Lakkireddy 		snprintf(name, sizeof(name), "%s_%d",
18022195df6dSRahul Lakkireddy 			 adapter->pdev->device.name, i);
180383189849SRahul Lakkireddy 
180483189849SRahul Lakkireddy 		if (i == 0) {
180583189849SRahul Lakkireddy 			/* First port is already allocated by DPDK */
18062195df6dSRahul Lakkireddy 			eth_dev = adapter->eth_dev;
180783189849SRahul Lakkireddy 			goto allocate_mac;
180883189849SRahul Lakkireddy 		}
180983189849SRahul Lakkireddy 
181083189849SRahul Lakkireddy 		/*
181183189849SRahul Lakkireddy 		 * now do all data allocation - for eth_dev structure,
181283189849SRahul Lakkireddy 		 * and internal (private) data for the remaining ports
181383189849SRahul Lakkireddy 		 */
181483189849SRahul Lakkireddy 
181583189849SRahul Lakkireddy 		/* reserve an ethdev entry */
18162195df6dSRahul Lakkireddy 		eth_dev = rte_eth_dev_allocate(name);
18172195df6dSRahul Lakkireddy 		if (!eth_dev)
181883189849SRahul Lakkireddy 			goto out_free;
181983189849SRahul Lakkireddy 
18202195df6dSRahul Lakkireddy 		eth_dev->data->dev_private =
18212195df6dSRahul Lakkireddy 			rte_zmalloc_socket(name, sizeof(struct port_info),
18222195df6dSRahul Lakkireddy 					   RTE_CACHE_LINE_SIZE, numa_node);
18232195df6dSRahul Lakkireddy 		if (!eth_dev->data->dev_private)
182483189849SRahul Lakkireddy 			goto out_free;
182583189849SRahul Lakkireddy 
182683189849SRahul Lakkireddy allocate_mac:
18272195df6dSRahul Lakkireddy 		pi = (struct port_info *)eth_dev->data->dev_private;
18282195df6dSRahul Lakkireddy 		adapter->port[i] = pi;
18292195df6dSRahul Lakkireddy 		pi->eth_dev = eth_dev;
18302195df6dSRahul Lakkireddy 		pi->adapter = adapter;
18312195df6dSRahul Lakkireddy 		pi->xact_addr_filt = -1;
18322195df6dSRahul Lakkireddy 		pi->port_id = i;
18335e80364aSKumar Sanghvi 		pi->pidx = i;
18342195df6dSRahul Lakkireddy 
1835eac901ceSJan Blunck 		pi->eth_dev->device = &adapter->pdev->device;
183683189849SRahul Lakkireddy 		pi->eth_dev->dev_ops = adapter->eth_dev->dev_ops;
18374a01078bSRahul Lakkireddy 		pi->eth_dev->tx_pkt_burst = adapter->eth_dev->tx_pkt_burst;
183892c8a632SRahul Lakkireddy 		pi->eth_dev->rx_pkt_burst = adapter->eth_dev->rx_pkt_burst;
183913b0f500SRahul Lakkireddy 
1840eac901ceSJan Blunck 		rte_eth_copy_pci_info(pi->eth_dev, adapter->pdev);
184113b0f500SRahul Lakkireddy 
184283189849SRahul Lakkireddy 		pi->eth_dev->data->mac_addrs = rte_zmalloc(name,
184335b2d13fSOlivier Matz 							RTE_ETHER_ADDR_LEN, 0);
184483189849SRahul Lakkireddy 		if (!pi->eth_dev->data->mac_addrs) {
184583189849SRahul Lakkireddy 			dev_err(adapter, "%s: Mem allocation failed for storing mac addr, aborting\n",
184683189849SRahul Lakkireddy 				__func__);
184783189849SRahul Lakkireddy 			err = -1;
184883189849SRahul Lakkireddy 			goto out_free;
184983189849SRahul Lakkireddy 		}
1850fbe90cddSThomas Monjalon 
1851fbe90cddSThomas Monjalon 		if (i > 0) {
1852fbe90cddSThomas Monjalon 			/* First port will be notified by upper layer */
1853fbe90cddSThomas Monjalon 			rte_eth_dev_probing_finish(eth_dev);
1854fbe90cddSThomas Monjalon 		}
185583189849SRahul Lakkireddy 	}
185683189849SRahul Lakkireddy 
185783189849SRahul Lakkireddy 	if (adapter->flags & FW_OK) {
185883189849SRahul Lakkireddy 		err = t4_port_init(adapter, adapter->mbox, adapter->pf, 0);
185983189849SRahul Lakkireddy 		if (err) {
186083189849SRahul Lakkireddy 			dev_err(adapter, "%s: t4_port_init failed with err %d\n",
186183189849SRahul Lakkireddy 				__func__, err);
186283189849SRahul Lakkireddy 			goto out_free;
186383189849SRahul Lakkireddy 		}
186483189849SRahul Lakkireddy 	}
186583189849SRahul Lakkireddy 
1866b7fd9ea8SStephen Hemminger 	cxgbe_cfg_queues(adapter->eth_dev);
186792c8a632SRahul Lakkireddy 
1868b7fd9ea8SStephen Hemminger 	cxgbe_print_adapter_info(adapter);
1869b7fd9ea8SStephen Hemminger 	cxgbe_print_port_info(adapter);
187083189849SRahul Lakkireddy 
18713f2c1e20SShagun Agrawal 	adapter->clipt = t4_init_clip_tbl(adapter->clipt_start,
18723f2c1e20SShagun Agrawal 					  adapter->clipt_end);
18733f2c1e20SShagun Agrawal 	if (!adapter->clipt) {
18743f2c1e20SShagun Agrawal 		/* We tolerate a lack of clip_table, giving up some
18753f2c1e20SShagun Agrawal 		 * functionality
18763f2c1e20SShagun Agrawal 		 */
18773f2c1e20SShagun Agrawal 		dev_warn(adapter, "could not allocate CLIP. Continuing\n");
18783f2c1e20SShagun Agrawal 	}
18793f2c1e20SShagun Agrawal 
188023af667fSShagun Agrawal 	adapter->l2t = t4_init_l2t(adapter->l2t_start, adapter->l2t_end);
188123af667fSShagun Agrawal 	if (!adapter->l2t) {
188223af667fSShagun Agrawal 		/* We tolerate a lack of L2T, giving up some functionality */
188323af667fSShagun Agrawal 		dev_warn(adapter, "could not allocate L2T. Continuing\n");
188423af667fSShagun Agrawal 	}
188523af667fSShagun Agrawal 
18866f2a064bSShagun Agrawal 	if (tid_init(&adapter->tids) < 0) {
18876f2a064bSShagun Agrawal 		/* Disable filtering support */
18886f2a064bSShagun Agrawal 		dev_warn(adapter, "could not allocate TID table, "
18896f2a064bSShagun Agrawal 			 "filter support disabled. Continuing\n");
18906f2a064bSShagun Agrawal 	}
18916f2a064bSShagun Agrawal 
18926fda3f0dSShagun Agrawal 	adapter->mpstcam = t4_init_mpstcam(adapter);
18936fda3f0dSShagun Agrawal 	if (!adapter->mpstcam)
18946fda3f0dSShagun Agrawal 		dev_warn(adapter, "could not allocate mps tcam table."
18956fda3f0dSShagun Agrawal 			 " Continuing\n");
18966fda3f0dSShagun Agrawal 
18973a381a41SShagun Agrawal 	if (is_hashfilter(adapter)) {
18983a381a41SShagun Agrawal 		if (t4_read_reg(adapter, A_LE_DB_CONFIG) & F_HASHEN) {
18993a381a41SShagun Agrawal 			u32 hash_base, hash_reg;
19003a381a41SShagun Agrawal 
19013a381a41SShagun Agrawal 			hash_reg = A_LE_DB_TID_HASHBASE;
19023a381a41SShagun Agrawal 			hash_base = t4_read_reg(adapter, hash_reg);
19033a381a41SShagun Agrawal 			adapter->tids.hash_base = hash_base / 4;
19043a381a41SShagun Agrawal 		}
19053a381a41SShagun Agrawal 	} else {
19063a381a41SShagun Agrawal 		/* Disable hash filtering support */
19073a381a41SShagun Agrawal 		dev_warn(adapter,
19083a381a41SShagun Agrawal 			 "Maskless filter support disabled. Continuing\n");
19093a381a41SShagun Agrawal 	}
19103a381a41SShagun Agrawal 
1911b7fd9ea8SStephen Hemminger 	err = cxgbe_init_rss(adapter);
191292c8a632SRahul Lakkireddy 	if (err)
191392c8a632SRahul Lakkireddy 		goto out_free;
191492c8a632SRahul Lakkireddy 
191583189849SRahul Lakkireddy 	return 0;
191683189849SRahul Lakkireddy 
191783189849SRahul Lakkireddy out_free:
191883189849SRahul Lakkireddy 	for_each_port(adapter, i) {
191983189849SRahul Lakkireddy 		pi = adap2pinfo(adapter, i);
192083189849SRahul Lakkireddy 		if (pi->viid != 0)
192183189849SRahul Lakkireddy 			t4_free_vi(adapter, adapter->mbox, adapter->pf,
192283189849SRahul Lakkireddy 				   0, pi->viid);
19232195df6dSRahul Lakkireddy 		rte_eth_dev_release_port(pi->eth_dev);
19242195df6dSRahul Lakkireddy 	}
192583189849SRahul Lakkireddy 
192683189849SRahul Lakkireddy 	if (adapter->flags & FW_OK)
192783189849SRahul Lakkireddy 		t4_fw_bye(adapter, adapter->mbox);
192883189849SRahul Lakkireddy 	return -err;
192983189849SRahul Lakkireddy }
1930