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" 40*51abd7b2SRahul Lakkireddy #include "cxgbe_pfvf.h" 413f2c1e20SShagun Agrawal #include "clip_tbl.h" 4223af667fSShagun Agrawal #include "l2t.h" 436fda3f0dSShagun Agrawal #include "mps_tcam.h" 4483189849SRahul Lakkireddy 456f2a064bSShagun Agrawal /** 466f2a064bSShagun Agrawal * Allocate a chunk of memory. The allocated memory is cleared. 476f2a064bSShagun Agrawal */ 486f2a064bSShagun Agrawal void *t4_alloc_mem(size_t size) 496f2a064bSShagun Agrawal { 506f2a064bSShagun Agrawal return rte_zmalloc(NULL, size, 0); 516f2a064bSShagun Agrawal } 526f2a064bSShagun Agrawal 536f2a064bSShagun Agrawal /** 546f2a064bSShagun Agrawal * Free memory allocated through t4_alloc_mem(). 556f2a064bSShagun Agrawal */ 566f2a064bSShagun Agrawal void t4_free_mem(void *addr) 576f2a064bSShagun Agrawal { 586f2a064bSShagun Agrawal rte_free(addr); 596f2a064bSShagun Agrawal } 606f2a064bSShagun Agrawal 6192c8a632SRahul Lakkireddy /* 6292c8a632SRahul Lakkireddy * Response queue handler for the FW event queue. 6392c8a632SRahul Lakkireddy */ 6492c8a632SRahul Lakkireddy static int fwevtq_handler(struct sge_rspq *q, const __be64 *rsp, 6592c8a632SRahul Lakkireddy __rte_unused const struct pkt_gl *gl) 6692c8a632SRahul Lakkireddy { 6792c8a632SRahul Lakkireddy u8 opcode = ((const struct rss_header *)rsp)->opcode; 6892c8a632SRahul Lakkireddy 6992c8a632SRahul Lakkireddy rsp++; /* skip RSS header */ 7092c8a632SRahul Lakkireddy 7192c8a632SRahul Lakkireddy /* 7292c8a632SRahul Lakkireddy * FW can send EGR_UPDATEs encapsulated in a CPL_FW4_MSG. 7392c8a632SRahul Lakkireddy */ 7492c8a632SRahul Lakkireddy if (unlikely(opcode == CPL_FW4_MSG && 7592c8a632SRahul Lakkireddy ((const struct cpl_fw4_msg *)rsp)->type == 7692c8a632SRahul Lakkireddy FW_TYPE_RSSCPL)) { 7792c8a632SRahul Lakkireddy rsp++; 7892c8a632SRahul Lakkireddy opcode = ((const struct rss_header *)rsp)->opcode; 7992c8a632SRahul Lakkireddy rsp++; 8092c8a632SRahul Lakkireddy if (opcode != CPL_SGE_EGR_UPDATE) { 8192c8a632SRahul Lakkireddy dev_err(q->adapter, "unexpected FW4/CPL %#x on FW event queue\n", 8292c8a632SRahul Lakkireddy opcode); 8392c8a632SRahul Lakkireddy goto out; 8492c8a632SRahul Lakkireddy } 8592c8a632SRahul Lakkireddy } 8692c8a632SRahul Lakkireddy 8792c8a632SRahul Lakkireddy if (likely(opcode == CPL_SGE_EGR_UPDATE)) { 8892c8a632SRahul Lakkireddy /* do nothing */ 8992c8a632SRahul Lakkireddy } else if (opcode == CPL_FW6_MSG || opcode == CPL_FW4_MSG) { 9092c8a632SRahul Lakkireddy const struct cpl_fw6_msg *msg = (const void *)rsp; 9192c8a632SRahul Lakkireddy 9292c8a632SRahul Lakkireddy t4_handle_fw_rpl(q->adapter, msg->data); 9341dc98b0SShagun Agrawal } else if (opcode == CPL_ABORT_RPL_RSS) { 9441dc98b0SShagun Agrawal const struct cpl_abort_rpl_rss *p = (const void *)rsp; 9541dc98b0SShagun Agrawal 9671e9b334SRahul Lakkireddy cxgbe_hash_del_filter_rpl(q->adapter, p); 979eb2c9a4SShagun Agrawal } else if (opcode == CPL_SET_TCB_RPL) { 989eb2c9a4SShagun Agrawal const struct cpl_set_tcb_rpl *p = (const void *)rsp; 999eb2c9a4SShagun Agrawal 10071e9b334SRahul Lakkireddy cxgbe_filter_rpl(q->adapter, p); 101af44a577SShagun Agrawal } else if (opcode == CPL_ACT_OPEN_RPL) { 102af44a577SShagun Agrawal const struct cpl_act_open_rpl *p = (const void *)rsp; 103af44a577SShagun Agrawal 10471e9b334SRahul Lakkireddy cxgbe_hash_filter_rpl(q->adapter, p); 10523af667fSShagun Agrawal } else if (opcode == CPL_L2T_WRITE_RPL) { 10623af667fSShagun Agrawal const struct cpl_l2t_write_rpl *p = (const void *)rsp; 10723af667fSShagun Agrawal 10871e9b334SRahul Lakkireddy cxgbe_do_l2t_write_rpl(q->adapter, p); 10992c8a632SRahul Lakkireddy } else { 11092c8a632SRahul Lakkireddy dev_err(adapter, "unexpected CPL %#x on FW event queue\n", 11192c8a632SRahul Lakkireddy opcode); 11292c8a632SRahul Lakkireddy } 11392c8a632SRahul Lakkireddy out: 11492c8a632SRahul Lakkireddy return 0; 11592c8a632SRahul Lakkireddy } 11692c8a632SRahul Lakkireddy 1173a3aaabcSShagun Agrawal /** 1183a3aaabcSShagun Agrawal * Setup sge control queues to pass control information. 1193a3aaabcSShagun Agrawal */ 120b7fd9ea8SStephen Hemminger int cxgbe_setup_sge_ctrl_txq(struct adapter *adapter) 1213a3aaabcSShagun Agrawal { 1223a3aaabcSShagun Agrawal struct sge *s = &adapter->sge; 1233a3aaabcSShagun Agrawal int err = 0, i = 0; 1243a3aaabcSShagun Agrawal 1253a3aaabcSShagun Agrawal for_each_port(adapter, i) { 12646df488bSRahul Lakkireddy struct port_info *pi = adap2pinfo(adapter, i); 1273a3aaabcSShagun Agrawal char name[RTE_ETH_NAME_MAX_LEN]; 1283a3aaabcSShagun Agrawal struct sge_ctrl_txq *q = &s->ctrlq[i]; 1293a3aaabcSShagun Agrawal 1303a3aaabcSShagun Agrawal q->q.size = 1024; 1313a3aaabcSShagun Agrawal err = t4_sge_alloc_ctrl_txq(adapter, q, 1323a3aaabcSShagun Agrawal adapter->eth_dev, i, 1333a3aaabcSShagun Agrawal s->fw_evtq.cntxt_id, 1343a3aaabcSShagun Agrawal rte_socket_id()); 1353a3aaabcSShagun Agrawal if (err) { 1363a3aaabcSShagun Agrawal dev_err(adapter, "Failed to alloc ctrl txq. Err: %d", 1373a3aaabcSShagun Agrawal err); 1383a3aaabcSShagun Agrawal goto out; 1393a3aaabcSShagun Agrawal } 14046df488bSRahul Lakkireddy snprintf(name, sizeof(name), "%s_ctrl_pool_%d", 14146df488bSRahul Lakkireddy pi->eth_dev->device->driver->name, 14246df488bSRahul Lakkireddy pi->eth_dev->data->port_id); 1433a3aaabcSShagun Agrawal q->mb_pool = rte_pktmbuf_pool_create(name, s->ctrlq[i].q.size, 1443a3aaabcSShagun Agrawal RTE_CACHE_LINE_SIZE, 1453a3aaabcSShagun Agrawal RTE_MBUF_PRIV_ALIGN, 1463a3aaabcSShagun Agrawal RTE_MBUF_DEFAULT_BUF_SIZE, 1473a3aaabcSShagun Agrawal SOCKET_ID_ANY); 1483a3aaabcSShagun Agrawal if (!q->mb_pool) { 14946df488bSRahul Lakkireddy err = -rte_errno; 15046df488bSRahul Lakkireddy dev_err(adapter, 15146df488bSRahul Lakkireddy "Can't create ctrl pool for port %d. Err: %d\n", 15246df488bSRahul Lakkireddy pi->eth_dev->data->port_id, err); 1533a3aaabcSShagun Agrawal goto out; 1543a3aaabcSShagun Agrawal } 1553a3aaabcSShagun Agrawal } 1563a3aaabcSShagun Agrawal return 0; 1573a3aaabcSShagun Agrawal out: 1583a3aaabcSShagun Agrawal t4_free_sge_resources(adapter); 1593a3aaabcSShagun Agrawal return err; 1603a3aaabcSShagun Agrawal } 1613a3aaabcSShagun Agrawal 1629eb2c9a4SShagun Agrawal /** 1639eb2c9a4SShagun Agrawal * cxgbe_poll_for_completion: Poll rxq for completion 1649eb2c9a4SShagun Agrawal * @q: rxq to poll 165f1e9d2afSRahul Lakkireddy * @ms: milliseconds to delay 1669eb2c9a4SShagun Agrawal * @cnt: number of times to poll 1679eb2c9a4SShagun Agrawal * @c: completion to check for 'done' status 1689eb2c9a4SShagun Agrawal * 1699eb2c9a4SShagun Agrawal * Polls the rxq for reples until completion is done or the count 1709eb2c9a4SShagun Agrawal * expires. 1719eb2c9a4SShagun Agrawal */ 172f1e9d2afSRahul Lakkireddy int cxgbe_poll_for_completion(struct sge_rspq *q, unsigned int ms, 1739eb2c9a4SShagun Agrawal unsigned int cnt, struct t4_completion *c) 1749eb2c9a4SShagun Agrawal { 1759eb2c9a4SShagun Agrawal unsigned int i; 176f1e9d2afSRahul Lakkireddy unsigned int work_done, budget = 32; 1779eb2c9a4SShagun Agrawal 1789eb2c9a4SShagun Agrawal if (!c) 1799eb2c9a4SShagun Agrawal return -EINVAL; 1809eb2c9a4SShagun Agrawal 1819eb2c9a4SShagun Agrawal for (i = 0; i < cnt; i++) { 1829eb2c9a4SShagun Agrawal cxgbe_poll(q, NULL, budget, &work_done); 1839eb2c9a4SShagun Agrawal t4_os_lock(&c->lock); 1849eb2c9a4SShagun Agrawal if (c->done) { 1859eb2c9a4SShagun Agrawal t4_os_unlock(&c->lock); 1869eb2c9a4SShagun Agrawal return 0; 1879eb2c9a4SShagun Agrawal } 1889eb2c9a4SShagun Agrawal t4_os_unlock(&c->lock); 189f1e9d2afSRahul Lakkireddy rte_delay_ms(ms); 1909eb2c9a4SShagun Agrawal } 1919eb2c9a4SShagun Agrawal return -ETIMEDOUT; 1929eb2c9a4SShagun Agrawal } 1939eb2c9a4SShagun Agrawal 194b7fd9ea8SStephen Hemminger int cxgbe_setup_sge_fwevtq(struct adapter *adapter) 19592c8a632SRahul Lakkireddy { 19692c8a632SRahul Lakkireddy struct sge *s = &adapter->sge; 19792c8a632SRahul Lakkireddy int err = 0; 19892c8a632SRahul Lakkireddy int msi_idx = 0; 19992c8a632SRahul Lakkireddy 20092c8a632SRahul Lakkireddy err = t4_sge_alloc_rxq(adapter, &s->fw_evtq, true, adapter->eth_dev, 20192c8a632SRahul Lakkireddy msi_idx, NULL, fwevtq_handler, -1, NULL, 0, 20292c8a632SRahul Lakkireddy rte_socket_id()); 20392c8a632SRahul Lakkireddy return err; 20492c8a632SRahul Lakkireddy } 20592c8a632SRahul Lakkireddy 20692c8a632SRahul Lakkireddy static int closest_timer(const struct sge *s, int time) 20792c8a632SRahul Lakkireddy { 20892c8a632SRahul Lakkireddy unsigned int i, match = 0; 20992c8a632SRahul Lakkireddy int delta, min_delta = INT_MAX; 21092c8a632SRahul Lakkireddy 21192c8a632SRahul Lakkireddy for (i = 0; i < ARRAY_SIZE(s->timer_val); i++) { 21292c8a632SRahul Lakkireddy delta = time - s->timer_val[i]; 21392c8a632SRahul Lakkireddy if (delta < 0) 21492c8a632SRahul Lakkireddy delta = -delta; 21592c8a632SRahul Lakkireddy if (delta < min_delta) { 21692c8a632SRahul Lakkireddy min_delta = delta; 21792c8a632SRahul Lakkireddy match = i; 21892c8a632SRahul Lakkireddy } 21992c8a632SRahul Lakkireddy } 22092c8a632SRahul Lakkireddy return match; 22192c8a632SRahul Lakkireddy } 22292c8a632SRahul Lakkireddy 22392c8a632SRahul Lakkireddy static int closest_thres(const struct sge *s, int thres) 22492c8a632SRahul Lakkireddy { 22592c8a632SRahul Lakkireddy unsigned int i, match = 0; 22692c8a632SRahul Lakkireddy int delta, min_delta = INT_MAX; 22792c8a632SRahul Lakkireddy 22892c8a632SRahul Lakkireddy for (i = 0; i < ARRAY_SIZE(s->counter_val); i++) { 22992c8a632SRahul Lakkireddy delta = thres - s->counter_val[i]; 23092c8a632SRahul Lakkireddy if (delta < 0) 23192c8a632SRahul Lakkireddy delta = -delta; 23292c8a632SRahul Lakkireddy if (delta < min_delta) { 23392c8a632SRahul Lakkireddy min_delta = delta; 23492c8a632SRahul Lakkireddy match = i; 23592c8a632SRahul Lakkireddy } 23692c8a632SRahul Lakkireddy } 23792c8a632SRahul Lakkireddy return match; 23892c8a632SRahul Lakkireddy } 23992c8a632SRahul Lakkireddy 24092c8a632SRahul Lakkireddy /** 24192c8a632SRahul Lakkireddy * cxgb4_set_rspq_intr_params - set a queue's interrupt holdoff parameters 24292c8a632SRahul Lakkireddy * @q: the Rx queue 24392c8a632SRahul Lakkireddy * @us: the hold-off time in us, or 0 to disable timer 24492c8a632SRahul Lakkireddy * @cnt: the hold-off packet count, or 0 to disable counter 24592c8a632SRahul Lakkireddy * 24692c8a632SRahul Lakkireddy * Sets an Rx queue's interrupt hold-off time and packet count. At least 24792c8a632SRahul Lakkireddy * one of the two needs to be enabled for the queue to generate interrupts. 24892c8a632SRahul Lakkireddy */ 24992c8a632SRahul Lakkireddy int cxgb4_set_rspq_intr_params(struct sge_rspq *q, unsigned int us, 25092c8a632SRahul Lakkireddy unsigned int cnt) 25192c8a632SRahul Lakkireddy { 25292c8a632SRahul Lakkireddy struct adapter *adap = q->adapter; 25392c8a632SRahul Lakkireddy unsigned int timer_val; 25492c8a632SRahul Lakkireddy 25592c8a632SRahul Lakkireddy if (cnt) { 25692c8a632SRahul Lakkireddy int err; 25792c8a632SRahul Lakkireddy u32 v, new_idx; 25892c8a632SRahul Lakkireddy 25992c8a632SRahul Lakkireddy new_idx = closest_thres(&adap->sge, cnt); 26092c8a632SRahul Lakkireddy if (q->desc && q->pktcnt_idx != new_idx) { 26192c8a632SRahul Lakkireddy /* the queue has already been created, update it */ 26292c8a632SRahul Lakkireddy v = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DMAQ) | 26392c8a632SRahul Lakkireddy V_FW_PARAMS_PARAM_X( 26492c8a632SRahul Lakkireddy FW_PARAMS_PARAM_DMAQ_IQ_INTCNTTHRESH) | 26592c8a632SRahul Lakkireddy V_FW_PARAMS_PARAM_YZ(q->cntxt_id); 26692c8a632SRahul Lakkireddy err = t4_set_params(adap, adap->mbox, adap->pf, 0, 1, 26792c8a632SRahul Lakkireddy &v, &new_idx); 26892c8a632SRahul Lakkireddy if (err) 26992c8a632SRahul Lakkireddy return err; 27092c8a632SRahul Lakkireddy } 27192c8a632SRahul Lakkireddy q->pktcnt_idx = new_idx; 27292c8a632SRahul Lakkireddy } 27392c8a632SRahul Lakkireddy 27492c8a632SRahul Lakkireddy timer_val = (us == 0) ? X_TIMERREG_RESTART_COUNTER : 27592c8a632SRahul Lakkireddy closest_timer(&adap->sge, us); 27692c8a632SRahul Lakkireddy 27792c8a632SRahul Lakkireddy if ((us | cnt) == 0) 27892c8a632SRahul Lakkireddy q->intr_params = V_QINTR_TIMER_IDX(X_TIMERREG_UPDATE_CIDX); 27992c8a632SRahul Lakkireddy else 28092c8a632SRahul Lakkireddy q->intr_params = V_QINTR_TIMER_IDX(timer_val) | 28192c8a632SRahul Lakkireddy V_QINTR_CNT_EN(cnt > 0); 28292c8a632SRahul Lakkireddy return 0; 28392c8a632SRahul Lakkireddy } 28492c8a632SRahul Lakkireddy 2856f2a064bSShagun Agrawal /** 286af44a577SShagun Agrawal * Allocate an active-open TID and set it to the supplied value. 287af44a577SShagun Agrawal */ 288af44a577SShagun Agrawal int cxgbe_alloc_atid(struct tid_info *t, void *data) 289af44a577SShagun Agrawal { 290af44a577SShagun Agrawal int atid = -1; 291af44a577SShagun Agrawal 292af44a577SShagun Agrawal t4_os_lock(&t->atid_lock); 293af44a577SShagun Agrawal if (t->afree) { 294af44a577SShagun Agrawal union aopen_entry *p = t->afree; 295af44a577SShagun Agrawal 296af44a577SShagun Agrawal atid = p - t->atid_tab; 297af44a577SShagun Agrawal t->afree = p->next; 298af44a577SShagun Agrawal p->data = data; 299af44a577SShagun Agrawal t->atids_in_use++; 300af44a577SShagun Agrawal } 301af44a577SShagun Agrawal t4_os_unlock(&t->atid_lock); 302af44a577SShagun Agrawal return atid; 303af44a577SShagun Agrawal } 304af44a577SShagun Agrawal 305af44a577SShagun Agrawal /** 306af44a577SShagun Agrawal * Release an active-open TID. 307af44a577SShagun Agrawal */ 308af44a577SShagun Agrawal void cxgbe_free_atid(struct tid_info *t, unsigned int atid) 309af44a577SShagun Agrawal { 310af44a577SShagun Agrawal union aopen_entry *p = &t->atid_tab[atid]; 311af44a577SShagun Agrawal 312af44a577SShagun Agrawal t4_os_lock(&t->atid_lock); 313af44a577SShagun Agrawal p->next = t->afree; 314af44a577SShagun Agrawal t->afree = p; 315af44a577SShagun Agrawal t->atids_in_use--; 316af44a577SShagun Agrawal t4_os_unlock(&t->atid_lock); 317af44a577SShagun Agrawal } 318af44a577SShagun Agrawal 319af44a577SShagun Agrawal /** 32041dc98b0SShagun Agrawal * Populate a TID_RELEASE WR. Caller must properly size the skb. 32141dc98b0SShagun Agrawal */ 32241dc98b0SShagun Agrawal static void mk_tid_release(struct rte_mbuf *mbuf, unsigned int tid) 32341dc98b0SShagun Agrawal { 32441dc98b0SShagun Agrawal struct cpl_tid_release *req; 32541dc98b0SShagun Agrawal 32641dc98b0SShagun Agrawal req = rte_pktmbuf_mtod(mbuf, struct cpl_tid_release *); 32741dc98b0SShagun Agrawal INIT_TP_WR_MIT_CPL(req, CPL_TID_RELEASE, tid); 32841dc98b0SShagun Agrawal } 32941dc98b0SShagun Agrawal 33041dc98b0SShagun Agrawal /** 33141dc98b0SShagun Agrawal * Release a TID and inform HW. If we are unable to allocate the release 33241dc98b0SShagun Agrawal * message we defer to a work queue. 33341dc98b0SShagun Agrawal */ 33441dc98b0SShagun Agrawal void cxgbe_remove_tid(struct tid_info *t, unsigned int chan, unsigned int tid, 33541dc98b0SShagun Agrawal unsigned short family) 33641dc98b0SShagun Agrawal { 33741dc98b0SShagun Agrawal struct rte_mbuf *mbuf; 33841dc98b0SShagun Agrawal struct adapter *adap = container_of(t, struct adapter, tids); 33941dc98b0SShagun Agrawal 34041dc98b0SShagun Agrawal WARN_ON(tid >= t->ntids); 34141dc98b0SShagun Agrawal 34241dc98b0SShagun Agrawal if (t->tid_tab[tid]) { 34341dc98b0SShagun Agrawal t->tid_tab[tid] = NULL; 34441dc98b0SShagun Agrawal rte_atomic32_dec(&t->conns_in_use); 34541dc98b0SShagun Agrawal if (t->hash_base && tid >= t->hash_base) { 34641dc98b0SShagun Agrawal if (family == FILTER_TYPE_IPV4) 34741dc98b0SShagun Agrawal rte_atomic32_dec(&t->hash_tids_in_use); 34841dc98b0SShagun Agrawal } else { 34941dc98b0SShagun Agrawal if (family == FILTER_TYPE_IPV4) 35041dc98b0SShagun Agrawal rte_atomic32_dec(&t->tids_in_use); 35141dc98b0SShagun Agrawal } 35241dc98b0SShagun Agrawal } 35341dc98b0SShagun Agrawal 35441dc98b0SShagun Agrawal mbuf = rte_pktmbuf_alloc((&adap->sge.ctrlq[chan])->mb_pool); 35541dc98b0SShagun Agrawal if (mbuf) { 35641dc98b0SShagun Agrawal mbuf->data_len = sizeof(struct cpl_tid_release); 35741dc98b0SShagun Agrawal mbuf->pkt_len = mbuf->data_len; 35841dc98b0SShagun Agrawal mk_tid_release(mbuf, tid); 35941dc98b0SShagun Agrawal t4_mgmt_tx(&adap->sge.ctrlq[chan], mbuf); 36041dc98b0SShagun Agrawal } 36141dc98b0SShagun Agrawal } 36241dc98b0SShagun Agrawal 36341dc98b0SShagun Agrawal /** 364af44a577SShagun Agrawal * Insert a TID. 365af44a577SShagun Agrawal */ 366af44a577SShagun Agrawal void cxgbe_insert_tid(struct tid_info *t, void *data, unsigned int tid, 367af44a577SShagun Agrawal unsigned short family) 368af44a577SShagun Agrawal { 369af44a577SShagun Agrawal t->tid_tab[tid] = data; 370af44a577SShagun Agrawal if (t->hash_base && tid >= t->hash_base) { 371af44a577SShagun Agrawal if (family == FILTER_TYPE_IPV4) 372af44a577SShagun Agrawal rte_atomic32_inc(&t->hash_tids_in_use); 373af44a577SShagun Agrawal } else { 374af44a577SShagun Agrawal if (family == FILTER_TYPE_IPV4) 375af44a577SShagun Agrawal rte_atomic32_inc(&t->tids_in_use); 376af44a577SShagun Agrawal } 377af44a577SShagun Agrawal 378af44a577SShagun Agrawal rte_atomic32_inc(&t->conns_in_use); 379af44a577SShagun Agrawal } 380af44a577SShagun Agrawal 381af44a577SShagun Agrawal /** 3826f2a064bSShagun Agrawal * Free TID tables. 3836f2a064bSShagun Agrawal */ 3846f2a064bSShagun Agrawal static void tid_free(struct tid_info *t) 3856f2a064bSShagun Agrawal { 3866f2a064bSShagun Agrawal if (t->tid_tab) { 3876f2a064bSShagun Agrawal if (t->ftid_bmap) 3886f2a064bSShagun Agrawal rte_bitmap_free(t->ftid_bmap); 3896f2a064bSShagun Agrawal 3906f2a064bSShagun Agrawal if (t->ftid_bmap_array) 3916f2a064bSShagun Agrawal t4_os_free(t->ftid_bmap_array); 3926f2a064bSShagun Agrawal 3936f2a064bSShagun Agrawal t4_os_free(t->tid_tab); 3946f2a064bSShagun Agrawal } 3956f2a064bSShagun Agrawal 3966f2a064bSShagun Agrawal memset(t, 0, sizeof(struct tid_info)); 3976f2a064bSShagun Agrawal } 3986f2a064bSShagun Agrawal 3996f2a064bSShagun Agrawal /** 4006f2a064bSShagun Agrawal * Allocate and initialize the TID tables. Returns 0 on success. 4016f2a064bSShagun Agrawal */ 4026f2a064bSShagun Agrawal static int tid_init(struct tid_info *t) 4036f2a064bSShagun Agrawal { 4046f2a064bSShagun Agrawal size_t size; 4056f2a064bSShagun Agrawal unsigned int ftid_bmap_size; 4063a381a41SShagun Agrawal unsigned int natids = t->natids; 4076f2a064bSShagun Agrawal unsigned int max_ftids = t->nftids; 4086f2a064bSShagun Agrawal 4096f2a064bSShagun Agrawal ftid_bmap_size = rte_bitmap_get_memory_footprint(t->nftids); 4106f2a064bSShagun Agrawal size = t->ntids * sizeof(*t->tid_tab) + 4113a381a41SShagun Agrawal max_ftids * sizeof(*t->ftid_tab) + 4123a381a41SShagun Agrawal natids * sizeof(*t->atid_tab); 4136f2a064bSShagun Agrawal 4146f2a064bSShagun Agrawal t->tid_tab = t4_os_alloc(size); 4156f2a064bSShagun Agrawal if (!t->tid_tab) 4166f2a064bSShagun Agrawal return -ENOMEM; 4176f2a064bSShagun Agrawal 4183a381a41SShagun Agrawal t->atid_tab = (union aopen_entry *)&t->tid_tab[t->ntids]; 41927288219SRahul Lakkireddy t->ftid_tab = (struct filter_entry *)&t->atid_tab[t->natids]; 4206f2a064bSShagun Agrawal t->ftid_bmap_array = t4_os_alloc(ftid_bmap_size); 4216f2a064bSShagun Agrawal if (!t->ftid_bmap_array) { 4226f2a064bSShagun Agrawal tid_free(t); 4236f2a064bSShagun Agrawal return -ENOMEM; 4246f2a064bSShagun Agrawal } 4256f2a064bSShagun Agrawal 4263a381a41SShagun Agrawal t4_os_lock_init(&t->atid_lock); 4276f2a064bSShagun Agrawal t4_os_lock_init(&t->ftid_lock); 4283a381a41SShagun Agrawal 4293a381a41SShagun Agrawal t->afree = NULL; 4303a381a41SShagun Agrawal t->atids_in_use = 0; 4313a381a41SShagun Agrawal rte_atomic32_init(&t->tids_in_use); 4323a381a41SShagun Agrawal rte_atomic32_set(&t->tids_in_use, 0); 4333a381a41SShagun Agrawal rte_atomic32_init(&t->conns_in_use); 4343a381a41SShagun Agrawal rte_atomic32_set(&t->conns_in_use, 0); 4353a381a41SShagun Agrawal 4363a381a41SShagun Agrawal /* Setup the free list for atid_tab and clear the stid bitmap. */ 4373a381a41SShagun Agrawal if (natids) { 4383a381a41SShagun Agrawal while (--natids) 4393a381a41SShagun Agrawal t->atid_tab[natids - 1].next = &t->atid_tab[natids]; 4403a381a41SShagun Agrawal t->afree = t->atid_tab; 4413a381a41SShagun Agrawal } 4423a381a41SShagun Agrawal 4436f2a064bSShagun Agrawal t->ftid_bmap = rte_bitmap_init(t->nftids, t->ftid_bmap_array, 4446f2a064bSShagun Agrawal ftid_bmap_size); 4456f2a064bSShagun Agrawal if (!t->ftid_bmap) { 4466f2a064bSShagun Agrawal tid_free(t); 4476f2a064bSShagun Agrawal return -ENOMEM; 4486f2a064bSShagun Agrawal } 4496f2a064bSShagun Agrawal 4506f2a064bSShagun Agrawal return 0; 4516f2a064bSShagun Agrawal } 4526f2a064bSShagun Agrawal 45392c8a632SRahul Lakkireddy static inline bool is_x_1g_port(const struct link_config *lc) 45492c8a632SRahul Lakkireddy { 45576488837SRahul Lakkireddy return (lc->pcaps & FW_PORT_CAP32_SPEED_1G) != 0; 45692c8a632SRahul Lakkireddy } 45792c8a632SRahul Lakkireddy 45892c8a632SRahul Lakkireddy static inline bool is_x_10g_port(const struct link_config *lc) 45992c8a632SRahul Lakkireddy { 4609da2a694SRahul Lakkireddy unsigned int speeds, high_speeds; 4619da2a694SRahul Lakkireddy 46276488837SRahul Lakkireddy speeds = V_FW_PORT_CAP32_SPEED(G_FW_PORT_CAP32_SPEED(lc->pcaps)); 46376488837SRahul Lakkireddy high_speeds = speeds & 46476488837SRahul Lakkireddy ~(FW_PORT_CAP32_SPEED_100M | FW_PORT_CAP32_SPEED_1G); 4659da2a694SRahul Lakkireddy 4669da2a694SRahul Lakkireddy return high_speeds != 0; 46792c8a632SRahul Lakkireddy } 46892c8a632SRahul Lakkireddy 469b7fd9ea8SStephen Hemminger static inline void init_rspq(struct adapter *adap, struct sge_rspq *q, 47092c8a632SRahul Lakkireddy unsigned int us, unsigned int cnt, 47192c8a632SRahul Lakkireddy unsigned int size, unsigned int iqe_size) 47292c8a632SRahul Lakkireddy { 47392c8a632SRahul Lakkireddy q->adapter = adap; 47492c8a632SRahul Lakkireddy cxgb4_set_rspq_intr_params(q, us, cnt); 47592c8a632SRahul Lakkireddy q->iqe_len = iqe_size; 47692c8a632SRahul Lakkireddy q->size = size; 47792c8a632SRahul Lakkireddy } 47892c8a632SRahul Lakkireddy 479b7fd9ea8SStephen Hemminger int cxgbe_cfg_queue_count(struct rte_eth_dev *eth_dev) 48092c8a632SRahul Lakkireddy { 48163a97e58SStephen Hemminger struct port_info *pi = eth_dev->data->dev_private; 48292c8a632SRahul Lakkireddy struct adapter *adap = pi->adapter; 48392c8a632SRahul Lakkireddy struct sge *s = &adap->sge; 48492c8a632SRahul Lakkireddy unsigned int max_queues = s->max_ethqsets / adap->params.nports; 48592c8a632SRahul Lakkireddy 48692c8a632SRahul Lakkireddy if ((eth_dev->data->nb_rx_queues < 1) || 48792c8a632SRahul Lakkireddy (eth_dev->data->nb_tx_queues < 1)) 48892c8a632SRahul Lakkireddy return -EINVAL; 48992c8a632SRahul Lakkireddy 49092c8a632SRahul Lakkireddy if ((eth_dev->data->nb_rx_queues > max_queues) || 49192c8a632SRahul Lakkireddy (eth_dev->data->nb_tx_queues > max_queues)) 49292c8a632SRahul Lakkireddy return -EINVAL; 49392c8a632SRahul Lakkireddy 49492c8a632SRahul Lakkireddy if (eth_dev->data->nb_rx_queues > pi->rss_size) 49592c8a632SRahul Lakkireddy return -EINVAL; 49692c8a632SRahul Lakkireddy 49792c8a632SRahul Lakkireddy /* We must configure RSS, since config has changed*/ 49892c8a632SRahul Lakkireddy pi->flags &= ~PORT_RSS_DONE; 49992c8a632SRahul Lakkireddy 50092c8a632SRahul Lakkireddy pi->n_rx_qsets = eth_dev->data->nb_rx_queues; 50192c8a632SRahul Lakkireddy pi->n_tx_qsets = eth_dev->data->nb_tx_queues; 50292c8a632SRahul Lakkireddy 50392c8a632SRahul Lakkireddy return 0; 50492c8a632SRahul Lakkireddy } 50592c8a632SRahul Lakkireddy 506b7fd9ea8SStephen Hemminger void cxgbe_cfg_queues(struct rte_eth_dev *eth_dev) 50792c8a632SRahul Lakkireddy { 50863a97e58SStephen Hemminger struct port_info *pi = eth_dev->data->dev_private; 50992c8a632SRahul Lakkireddy struct adapter *adap = pi->adapter; 51092c8a632SRahul Lakkireddy struct sge *s = &adap->sge; 51192c8a632SRahul Lakkireddy unsigned int i, nb_ports = 0, qidx = 0; 51292c8a632SRahul Lakkireddy unsigned int q_per_port = 0; 51392c8a632SRahul Lakkireddy 51492c8a632SRahul Lakkireddy if (!(adap->flags & CFG_QUEUES)) { 51592c8a632SRahul Lakkireddy for_each_port(adap, i) { 51692c8a632SRahul Lakkireddy struct port_info *tpi = adap2pinfo(adap, i); 51792c8a632SRahul Lakkireddy 51892c8a632SRahul Lakkireddy nb_ports += (is_x_10g_port(&tpi->link_cfg)) || 51992c8a632SRahul Lakkireddy is_x_1g_port(&tpi->link_cfg) ? 1 : 0; 52092c8a632SRahul Lakkireddy } 52192c8a632SRahul Lakkireddy 52292c8a632SRahul Lakkireddy /* 52392c8a632SRahul Lakkireddy * We default up to # of cores queues per 1G/10G port. 52492c8a632SRahul Lakkireddy */ 52592c8a632SRahul Lakkireddy if (nb_ports) 52687a3ae3eSRahul Lakkireddy q_per_port = (s->max_ethqsets - 52792c8a632SRahul Lakkireddy (adap->params.nports - nb_ports)) / 52892c8a632SRahul Lakkireddy nb_ports; 52992c8a632SRahul Lakkireddy 53064a46f14SDavid Marchand if (q_per_port > rte_lcore_count()) 53164a46f14SDavid Marchand q_per_port = rte_lcore_count(); 53292c8a632SRahul Lakkireddy 53392c8a632SRahul Lakkireddy for_each_port(adap, i) { 53492c8a632SRahul Lakkireddy struct port_info *pi = adap2pinfo(adap, i); 53592c8a632SRahul Lakkireddy 53692c8a632SRahul Lakkireddy pi->first_qset = qidx; 53792c8a632SRahul Lakkireddy 53892c8a632SRahul Lakkireddy /* Initially n_rx_qsets == n_tx_qsets */ 53992c8a632SRahul Lakkireddy pi->n_rx_qsets = (is_x_10g_port(&pi->link_cfg) || 54092c8a632SRahul Lakkireddy is_x_1g_port(&pi->link_cfg)) ? 54192c8a632SRahul Lakkireddy q_per_port : 1; 54292c8a632SRahul Lakkireddy pi->n_tx_qsets = pi->n_rx_qsets; 54392c8a632SRahul Lakkireddy 54492c8a632SRahul Lakkireddy if (pi->n_rx_qsets > pi->rss_size) 54592c8a632SRahul Lakkireddy pi->n_rx_qsets = pi->rss_size; 54692c8a632SRahul Lakkireddy 54792c8a632SRahul Lakkireddy qidx += pi->n_rx_qsets; 54892c8a632SRahul Lakkireddy } 54992c8a632SRahul Lakkireddy 55092c8a632SRahul Lakkireddy for (i = 0; i < ARRAY_SIZE(s->ethrxq); i++) { 55192c8a632SRahul Lakkireddy struct sge_eth_rxq *r = &s->ethrxq[i]; 55292c8a632SRahul Lakkireddy 5536c280962SRahul Lakkireddy init_rspq(adap, &r->rspq, 5, 32, 1024, 64); 55492c8a632SRahul Lakkireddy r->usembufs = 1; 55592c8a632SRahul Lakkireddy r->fl.size = (r->usembufs ? 1024 : 72); 55692c8a632SRahul Lakkireddy } 55792c8a632SRahul Lakkireddy 55892c8a632SRahul Lakkireddy for (i = 0; i < ARRAY_SIZE(s->ethtxq); i++) 55992c8a632SRahul Lakkireddy s->ethtxq[i].q.size = 1024; 56092c8a632SRahul Lakkireddy 56192c8a632SRahul Lakkireddy init_rspq(adap, &adap->sge.fw_evtq, 0, 0, 1024, 64); 56292c8a632SRahul Lakkireddy adap->flags |= CFG_QUEUES; 56392c8a632SRahul Lakkireddy } 56492c8a632SRahul Lakkireddy } 56592c8a632SRahul Lakkireddy 566856505d3SRahul Lakkireddy void cxgbe_stats_get(struct port_info *pi, struct port_stats *stats) 567856505d3SRahul Lakkireddy { 568856505d3SRahul Lakkireddy t4_get_port_stats_offset(pi->adapter, pi->tx_chan, stats, 569856505d3SRahul Lakkireddy &pi->stats_base); 570856505d3SRahul Lakkireddy } 571856505d3SRahul Lakkireddy 572856505d3SRahul Lakkireddy void cxgbe_stats_reset(struct port_info *pi) 573856505d3SRahul Lakkireddy { 574856505d3SRahul Lakkireddy t4_clr_port_stats(pi->adapter, pi->tx_chan); 575856505d3SRahul Lakkireddy } 576856505d3SRahul Lakkireddy 57783189849SRahul Lakkireddy static void setup_memwin(struct adapter *adap) 57883189849SRahul Lakkireddy { 57983189849SRahul Lakkireddy u32 mem_win0_base; 58083189849SRahul Lakkireddy 58183189849SRahul Lakkireddy /* For T5, only relative offset inside the PCIe BAR is passed */ 58283189849SRahul Lakkireddy mem_win0_base = MEMWIN0_BASE; 58383189849SRahul Lakkireddy 58483189849SRahul Lakkireddy /* 58583189849SRahul Lakkireddy * Set up memory window for accessing adapter memory ranges. (Read 58683189849SRahul Lakkireddy * back MA register to ensure that changes propagate before we attempt 58783189849SRahul Lakkireddy * to use the new values.) 58883189849SRahul Lakkireddy */ 58983189849SRahul Lakkireddy t4_write_reg(adap, 59083189849SRahul Lakkireddy PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_BASE_WIN, 59183189849SRahul Lakkireddy MEMWIN_NIC), 59283189849SRahul Lakkireddy mem_win0_base | V_BIR(0) | 59383189849SRahul Lakkireddy V_WINDOW(ilog2(MEMWIN0_APERTURE) - X_WINDOW_SHIFT)); 59483189849SRahul Lakkireddy t4_read_reg(adap, 59583189849SRahul Lakkireddy PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_BASE_WIN, 59683189849SRahul Lakkireddy MEMWIN_NIC)); 59783189849SRahul Lakkireddy } 59883189849SRahul Lakkireddy 599b7fd9ea8SStephen Hemminger int cxgbe_init_rss(struct adapter *adap) 60092c8a632SRahul Lakkireddy { 60192c8a632SRahul Lakkireddy unsigned int i; 602bfcb257dSKumar Sanghvi 603bfcb257dSKumar Sanghvi if (is_pf4(adap)) { 60492c8a632SRahul Lakkireddy int err; 60592c8a632SRahul Lakkireddy 60692c8a632SRahul Lakkireddy err = t4_init_rss_mode(adap, adap->mbox); 60792c8a632SRahul Lakkireddy if (err) 60892c8a632SRahul Lakkireddy return err; 609bfcb257dSKumar Sanghvi } 61092c8a632SRahul Lakkireddy 61192c8a632SRahul Lakkireddy for_each_port(adap, i) { 61292c8a632SRahul Lakkireddy struct port_info *pi = adap2pinfo(adap, i); 61392c8a632SRahul Lakkireddy 6148dca8cc5SRahul Lakkireddy pi->rss = rte_zmalloc(NULL, pi->rss_size * sizeof(u16), 0); 61592c8a632SRahul Lakkireddy if (!pi->rss) 61692c8a632SRahul Lakkireddy return -ENOMEM; 61708e21af9SKumar Sanghvi 61808e21af9SKumar Sanghvi pi->rss_hf = CXGBE_RSS_HF_ALL; 61992c8a632SRahul Lakkireddy } 62092c8a632SRahul Lakkireddy return 0; 62192c8a632SRahul Lakkireddy } 62292c8a632SRahul Lakkireddy 623c962618cSRahul Lakkireddy /** 624c962618cSRahul Lakkireddy * Dump basic information about the adapter. 625c962618cSRahul Lakkireddy */ 626b7fd9ea8SStephen Hemminger void cxgbe_print_adapter_info(struct adapter *adap) 627c962618cSRahul Lakkireddy { 628c962618cSRahul Lakkireddy /** 629c962618cSRahul Lakkireddy * Hardware/Firmware/etc. Version/Revision IDs. 630c962618cSRahul Lakkireddy */ 631c962618cSRahul Lakkireddy t4_dump_version_info(adap); 632c962618cSRahul Lakkireddy } 633c962618cSRahul Lakkireddy 634b7fd9ea8SStephen Hemminger void cxgbe_print_port_info(struct adapter *adap) 63583189849SRahul Lakkireddy { 63683189849SRahul Lakkireddy int i; 63783189849SRahul Lakkireddy char buf[80]; 63883189849SRahul Lakkireddy struct rte_pci_addr *loc = &adap->pdev->addr; 63983189849SRahul Lakkireddy 64083189849SRahul Lakkireddy for_each_port(adap, i) { 6412195df6dSRahul Lakkireddy const struct port_info *pi = adap2pinfo(adap, i); 64283189849SRahul Lakkireddy char *bufp = buf; 64383189849SRahul Lakkireddy 64476488837SRahul Lakkireddy if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_100M) 6459da2a694SRahul Lakkireddy bufp += sprintf(bufp, "100M/"); 64676488837SRahul Lakkireddy if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_1G) 6479da2a694SRahul Lakkireddy bufp += sprintf(bufp, "1G/"); 64876488837SRahul Lakkireddy if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_10G) 64983189849SRahul Lakkireddy bufp += sprintf(bufp, "10G/"); 65076488837SRahul Lakkireddy if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_25G) 6519da2a694SRahul Lakkireddy bufp += sprintf(bufp, "25G/"); 65276488837SRahul Lakkireddy if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_40G) 65383189849SRahul Lakkireddy bufp += sprintf(bufp, "40G/"); 65476488837SRahul Lakkireddy if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_50G) 65576488837SRahul Lakkireddy bufp += sprintf(bufp, "50G/"); 65676488837SRahul Lakkireddy if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_100G) 6579da2a694SRahul Lakkireddy bufp += sprintf(bufp, "100G/"); 65883189849SRahul Lakkireddy if (bufp != buf) 65983189849SRahul Lakkireddy --bufp; 66083189849SRahul Lakkireddy sprintf(bufp, "BASE-%s", 661efa8a43eSBruce Richardson t4_get_port_type_description( 662efa8a43eSBruce Richardson (enum fw_port_type)pi->port_type)); 66383189849SRahul Lakkireddy 66483189849SRahul Lakkireddy dev_info(adap, 66583189849SRahul Lakkireddy " " PCI_PRI_FMT " Chelsio rev %d %s %s\n", 66683189849SRahul Lakkireddy loc->domain, loc->bus, loc->devid, loc->function, 66783189849SRahul Lakkireddy CHELSIO_CHIP_RELEASE(adap->params.chip), buf, 66883189849SRahul Lakkireddy (adap->flags & USING_MSIX) ? " MSI-X" : 66983189849SRahul Lakkireddy (adap->flags & USING_MSI) ? " MSI" : ""); 67083189849SRahul Lakkireddy } 67183189849SRahul Lakkireddy } 67283189849SRahul Lakkireddy 673dd7c9f12SRahul Lakkireddy static int check_devargs_handler(const char *key, const char *value, void *p) 674cda260a4SShagun Agrawal { 675dd7c9f12SRahul Lakkireddy if (!strncmp(key, CXGBE_DEVARG_CMN_KEEP_OVLAN, strlen(key)) || 676fa033437SRahul Lakkireddy !strncmp(key, CXGBE_DEVARG_CMN_TX_MODE_LATENCY, strlen(key)) || 677dd7c9f12SRahul Lakkireddy !strncmp(key, CXGBE_DEVARG_VF_FORCE_LINK_UP, strlen(key))) { 678dd7c9f12SRahul Lakkireddy if (!strncmp(value, "1", 1)) { 679dd7c9f12SRahul Lakkireddy bool *dst_val = (bool *)p; 680dd7c9f12SRahul Lakkireddy 681dd7c9f12SRahul Lakkireddy *dst_val = true; 682dd7c9f12SRahul Lakkireddy } 683dd7c9f12SRahul Lakkireddy } 684cda260a4SShagun Agrawal 685cda260a4SShagun Agrawal return 0; 686cda260a4SShagun Agrawal } 687cda260a4SShagun Agrawal 688dd7c9f12SRahul Lakkireddy static int cxgbe_get_devargs(struct rte_devargs *devargs, const char *key, 689dd7c9f12SRahul Lakkireddy void *p) 690cda260a4SShagun Agrawal { 691cda260a4SShagun Agrawal struct rte_kvargs *kvlist; 692dd7c9f12SRahul Lakkireddy int ret = 0; 693cda260a4SShagun Agrawal 694cda260a4SShagun Agrawal if (!devargs) 695cda260a4SShagun Agrawal return 0; 696cda260a4SShagun Agrawal 697cda260a4SShagun Agrawal kvlist = rte_kvargs_parse(devargs->args, NULL); 698cda260a4SShagun Agrawal if (!kvlist) 699cda260a4SShagun Agrawal return 0; 700cda260a4SShagun Agrawal 701dd7c9f12SRahul Lakkireddy if (!rte_kvargs_count(kvlist, key)) 702dd7c9f12SRahul Lakkireddy goto out; 703cda260a4SShagun Agrawal 704dd7c9f12SRahul Lakkireddy ret = rte_kvargs_process(kvlist, key, check_devargs_handler, p); 705dd7c9f12SRahul Lakkireddy 706dd7c9f12SRahul Lakkireddy out: 707cda260a4SShagun Agrawal rte_kvargs_free(kvlist); 708cda260a4SShagun Agrawal 709dd7c9f12SRahul Lakkireddy return ret; 710dd7c9f12SRahul Lakkireddy } 711dd7c9f12SRahul Lakkireddy 712dd7c9f12SRahul Lakkireddy static void cxgbe_get_devargs_int(struct adapter *adap, int *dst, 713dd7c9f12SRahul Lakkireddy const char *key, int default_value) 714dd7c9f12SRahul Lakkireddy { 715dd7c9f12SRahul Lakkireddy struct rte_pci_device *pdev = adap->pdev; 716dd7c9f12SRahul Lakkireddy int ret, devarg_value = default_value; 717dd7c9f12SRahul Lakkireddy 718dd7c9f12SRahul Lakkireddy *dst = default_value; 719dd7c9f12SRahul Lakkireddy if (!pdev) 720dd7c9f12SRahul Lakkireddy return; 721dd7c9f12SRahul Lakkireddy 722dd7c9f12SRahul Lakkireddy ret = cxgbe_get_devargs(pdev->device.devargs, key, &devarg_value); 723dd7c9f12SRahul Lakkireddy if (ret) 724dd7c9f12SRahul Lakkireddy return; 725dd7c9f12SRahul Lakkireddy 726dd7c9f12SRahul Lakkireddy *dst = devarg_value; 727dd7c9f12SRahul Lakkireddy } 728dd7c9f12SRahul Lakkireddy 729dd7c9f12SRahul Lakkireddy void cxgbe_process_devargs(struct adapter *adap) 730dd7c9f12SRahul Lakkireddy { 731dd7c9f12SRahul Lakkireddy cxgbe_get_devargs_int(adap, &adap->devargs.keep_ovlan, 732dd7c9f12SRahul Lakkireddy CXGBE_DEVARG_CMN_KEEP_OVLAN, 0); 733fa033437SRahul Lakkireddy cxgbe_get_devargs_int(adap, &adap->devargs.tx_mode_latency, 734fa033437SRahul Lakkireddy CXGBE_DEVARG_CMN_TX_MODE_LATENCY, 0); 735dd7c9f12SRahul Lakkireddy cxgbe_get_devargs_int(adap, &adap->devargs.force_link_up, 736dd7c9f12SRahul Lakkireddy CXGBE_DEVARG_VF_FORCE_LINK_UP, 0); 737cda260a4SShagun Agrawal } 738cda260a4SShagun Agrawal 739cda260a4SShagun Agrawal static void configure_vlan_types(struct adapter *adapter) 740cda260a4SShagun Agrawal { 741cda260a4SShagun Agrawal int i; 742cda260a4SShagun Agrawal 743cda260a4SShagun Agrawal for_each_port(adapter, i) { 744cda260a4SShagun Agrawal /* OVLAN Type 0x88a8 */ 745cda260a4SShagun Agrawal t4_set_reg_field(adapter, MPS_PORT_RX_OVLAN_REG(i, A_RX_OVLAN0), 746cda260a4SShagun Agrawal V_OVLAN_MASK(M_OVLAN_MASK) | 747cda260a4SShagun Agrawal V_OVLAN_ETYPE(M_OVLAN_ETYPE), 748cda260a4SShagun Agrawal V_OVLAN_MASK(M_OVLAN_MASK) | 749cda260a4SShagun Agrawal V_OVLAN_ETYPE(0x88a8)); 750cda260a4SShagun Agrawal /* OVLAN Type 0x9100 */ 751cda260a4SShagun Agrawal t4_set_reg_field(adapter, MPS_PORT_RX_OVLAN_REG(i, A_RX_OVLAN1), 752cda260a4SShagun Agrawal V_OVLAN_MASK(M_OVLAN_MASK) | 753cda260a4SShagun Agrawal V_OVLAN_ETYPE(M_OVLAN_ETYPE), 754cda260a4SShagun Agrawal V_OVLAN_MASK(M_OVLAN_MASK) | 755cda260a4SShagun Agrawal V_OVLAN_ETYPE(0x9100)); 756cda260a4SShagun Agrawal /* OVLAN Type 0x8100 */ 757cda260a4SShagun Agrawal t4_set_reg_field(adapter, MPS_PORT_RX_OVLAN_REG(i, A_RX_OVLAN2), 758cda260a4SShagun Agrawal V_OVLAN_MASK(M_OVLAN_MASK) | 759cda260a4SShagun Agrawal V_OVLAN_ETYPE(M_OVLAN_ETYPE), 760cda260a4SShagun Agrawal V_OVLAN_MASK(M_OVLAN_MASK) | 761cda260a4SShagun Agrawal V_OVLAN_ETYPE(0x8100)); 762cda260a4SShagun Agrawal 763cda260a4SShagun Agrawal /* IVLAN 0X8100 */ 764cda260a4SShagun Agrawal t4_set_reg_field(adapter, MPS_PORT_RX_IVLAN(i), 765cda260a4SShagun Agrawal V_IVLAN_ETYPE(M_IVLAN_ETYPE), 766cda260a4SShagun Agrawal V_IVLAN_ETYPE(0x8100)); 767cda260a4SShagun Agrawal 768cda260a4SShagun Agrawal t4_set_reg_field(adapter, MPS_PORT_RX_CTL(i), 769cda260a4SShagun Agrawal F_OVLAN_EN0 | F_OVLAN_EN1 | 770cda260a4SShagun Agrawal F_OVLAN_EN2 | F_IVLAN_EN, 771cda260a4SShagun Agrawal F_OVLAN_EN0 | F_OVLAN_EN1 | 772cda260a4SShagun Agrawal F_OVLAN_EN2 | F_IVLAN_EN); 773cda260a4SShagun Agrawal } 774cda260a4SShagun Agrawal 775dd7c9f12SRahul Lakkireddy t4_tp_wr_bits_indirect(adapter, A_TP_INGRESS_CONFIG, V_RM_OVLAN(1), 776dd7c9f12SRahul Lakkireddy V_RM_OVLAN(!adapter->devargs.keep_ovlan)); 777cda260a4SShagun Agrawal } 778cda260a4SShagun Agrawal 779ee606d92SRahul Lakkireddy static void configure_pcie_ext_tag(struct adapter *adapter) 780ee606d92SRahul Lakkireddy { 781ee606d92SRahul Lakkireddy u16 v; 782ee606d92SRahul Lakkireddy int pos = t4_os_find_pci_capability(adapter, PCI_CAP_ID_EXP); 783ee606d92SRahul Lakkireddy 784ee606d92SRahul Lakkireddy if (!pos) 785ee606d92SRahul Lakkireddy return; 786ee606d92SRahul Lakkireddy 787ee606d92SRahul Lakkireddy if (pos > 0) { 788ee606d92SRahul Lakkireddy t4_os_pci_read_cfg2(adapter, pos + PCI_EXP_DEVCTL, &v); 789ee606d92SRahul Lakkireddy v |= PCI_EXP_DEVCTL_EXT_TAG; 790ee606d92SRahul Lakkireddy t4_os_pci_write_cfg2(adapter, pos + PCI_EXP_DEVCTL, v); 791ee606d92SRahul Lakkireddy if (is_t6(adapter->params.chip)) { 792ee606d92SRahul Lakkireddy t4_set_reg_field(adapter, A_PCIE_CFG2, 793ee606d92SRahul Lakkireddy V_T6_TOTMAXTAG(M_T6_TOTMAXTAG), 794ee606d92SRahul Lakkireddy V_T6_TOTMAXTAG(7)); 795ee606d92SRahul Lakkireddy t4_set_reg_field(adapter, A_PCIE_CMD_CFG, 796ee606d92SRahul Lakkireddy V_T6_MINTAG(M_T6_MINTAG), 797ee606d92SRahul Lakkireddy V_T6_MINTAG(8)); 798ee606d92SRahul Lakkireddy } else { 799ee606d92SRahul Lakkireddy t4_set_reg_field(adapter, A_PCIE_CFG2, 800ee606d92SRahul Lakkireddy V_TOTMAXTAG(M_TOTMAXTAG), 801ee606d92SRahul Lakkireddy V_TOTMAXTAG(3)); 802ee606d92SRahul Lakkireddy t4_set_reg_field(adapter, A_PCIE_CMD_CFG, 803ee606d92SRahul Lakkireddy V_MINTAG(M_MINTAG), 804ee606d92SRahul Lakkireddy V_MINTAG(8)); 805ee606d92SRahul Lakkireddy } 806ee606d92SRahul Lakkireddy } 807ee606d92SRahul Lakkireddy } 808ee606d92SRahul Lakkireddy 80987a3ae3eSRahul Lakkireddy /* Figure out how many Queue Sets we can support */ 810b7fd9ea8SStephen Hemminger void cxgbe_configure_max_ethqsets(struct adapter *adapter) 81187a3ae3eSRahul Lakkireddy { 81287a3ae3eSRahul Lakkireddy unsigned int ethqsets; 81387a3ae3eSRahul Lakkireddy 81487a3ae3eSRahul Lakkireddy /* 81587a3ae3eSRahul Lakkireddy * We need to reserve an Ingress Queue for the Asynchronous Firmware 81687a3ae3eSRahul Lakkireddy * Event Queue. 81787a3ae3eSRahul Lakkireddy * 81887a3ae3eSRahul Lakkireddy * For each Queue Set, we'll need the ability to allocate two Egress 81987a3ae3eSRahul Lakkireddy * Contexts -- one for the Ingress Queue Free List and one for the TX 82087a3ae3eSRahul Lakkireddy * Ethernet Queue. 82187a3ae3eSRahul Lakkireddy */ 82287a3ae3eSRahul Lakkireddy if (is_pf4(adapter)) { 82387a3ae3eSRahul Lakkireddy struct pf_resources *pfres = &adapter->params.pfres; 82487a3ae3eSRahul Lakkireddy 82587a3ae3eSRahul Lakkireddy ethqsets = pfres->niqflint - 1; 82687a3ae3eSRahul Lakkireddy if (pfres->neq < ethqsets * 2) 82787a3ae3eSRahul Lakkireddy ethqsets = pfres->neq / 2; 82887a3ae3eSRahul Lakkireddy } else { 82987a3ae3eSRahul Lakkireddy struct vf_resources *vfres = &adapter->params.vfres; 83087a3ae3eSRahul Lakkireddy 83187a3ae3eSRahul Lakkireddy ethqsets = vfres->niqflint - 1; 83287a3ae3eSRahul Lakkireddy if (vfres->nethctrl != ethqsets) 83387a3ae3eSRahul Lakkireddy ethqsets = min(vfres->nethctrl, ethqsets); 83487a3ae3eSRahul Lakkireddy if (vfres->neq < ethqsets * 2) 83587a3ae3eSRahul Lakkireddy ethqsets = vfres->neq / 2; 83687a3ae3eSRahul Lakkireddy } 83787a3ae3eSRahul Lakkireddy 83887a3ae3eSRahul Lakkireddy if (ethqsets > MAX_ETH_QSETS) 83987a3ae3eSRahul Lakkireddy ethqsets = MAX_ETH_QSETS; 84087a3ae3eSRahul Lakkireddy adapter->sge.max_ethqsets = ethqsets; 84187a3ae3eSRahul Lakkireddy } 84287a3ae3eSRahul Lakkireddy 84383189849SRahul Lakkireddy /* 84483189849SRahul Lakkireddy * Tweak configuration based on system architecture, etc. Most of these have 84583189849SRahul Lakkireddy * defaults assigned to them by Firmware Configuration Files (if we're using 84683189849SRahul Lakkireddy * them) but need to be explicitly set if we're using hard-coded 84783189849SRahul Lakkireddy * initialization. So these are essentially common tweaks/settings for 84883189849SRahul Lakkireddy * Configuration Files and hard-coded initialization ... 84983189849SRahul Lakkireddy */ 85083189849SRahul Lakkireddy static int adap_init0_tweaks(struct adapter *adapter) 85183189849SRahul Lakkireddy { 85283189849SRahul Lakkireddy u8 rx_dma_offset; 85383189849SRahul Lakkireddy 85483189849SRahul Lakkireddy /* 85583189849SRahul Lakkireddy * Fix up various Host-Dependent Parameters like Page Size, Cache 85683189849SRahul Lakkireddy * Line Size, etc. The firmware default is for a 4KB Page Size and 85783189849SRahul Lakkireddy * 64B Cache Line Size ... 85883189849SRahul Lakkireddy */ 8591f8613f1SRahul Lakkireddy t4_fixup_host_params_compat(adapter, CXGBE_PAGE_SIZE, L1_CACHE_BYTES, 86083189849SRahul Lakkireddy T5_LAST_REV); 86183189849SRahul Lakkireddy 86283189849SRahul Lakkireddy /* 86383189849SRahul Lakkireddy * Keep the chip default offset to deliver Ingress packets into our 86483189849SRahul Lakkireddy * DMA buffers to zero 86583189849SRahul Lakkireddy */ 86683189849SRahul Lakkireddy rx_dma_offset = 0; 86783189849SRahul Lakkireddy t4_set_reg_field(adapter, A_SGE_CONTROL, V_PKTSHIFT(M_PKTSHIFT), 86883189849SRahul Lakkireddy V_PKTSHIFT(rx_dma_offset)); 86983189849SRahul Lakkireddy 870bf89cbedSRahul Lakkireddy t4_set_reg_field(adapter, A_SGE_FLM_CFG, 871bf89cbedSRahul Lakkireddy V_CREDITCNT(M_CREDITCNT) | M_CREDITCNTPACKING, 872bf89cbedSRahul Lakkireddy V_CREDITCNT(3) | V_CREDITCNTPACKING(1)); 873bf89cbedSRahul Lakkireddy 8746c280962SRahul Lakkireddy t4_set_reg_field(adapter, A_SGE_INGRESS_RX_THRESHOLD, 8756c280962SRahul Lakkireddy V_THRESHOLD_3(M_THRESHOLD_3), V_THRESHOLD_3(32U)); 8766c280962SRahul Lakkireddy 877bf89cbedSRahul Lakkireddy t4_set_reg_field(adapter, A_SGE_CONTROL2, V_IDMAARBROUNDROBIN(1U), 878bf89cbedSRahul Lakkireddy V_IDMAARBROUNDROBIN(1U)); 879bf89cbedSRahul Lakkireddy 88083189849SRahul Lakkireddy /* 88183189849SRahul Lakkireddy * Don't include the "IP Pseudo Header" in CPL_RX_PKT checksums: Linux 88283189849SRahul Lakkireddy * adds the pseudo header itself. 88383189849SRahul Lakkireddy */ 88483189849SRahul Lakkireddy t4_tp_wr_bits_indirect(adapter, A_TP_INGRESS_CONFIG, 88583189849SRahul Lakkireddy F_CSUM_HAS_PSEUDO_HDR, 0); 88683189849SRahul Lakkireddy 88783189849SRahul Lakkireddy return 0; 88883189849SRahul Lakkireddy } 88983189849SRahul Lakkireddy 89083189849SRahul Lakkireddy /* 89183189849SRahul Lakkireddy * Attempt to initialize the adapter via a Firmware Configuration File. 89283189849SRahul Lakkireddy */ 89383189849SRahul Lakkireddy static int adap_init0_config(struct adapter *adapter, int reset) 89483189849SRahul Lakkireddy { 89583189849SRahul Lakkireddy struct fw_caps_config_cmd caps_cmd; 89683189849SRahul Lakkireddy unsigned long mtype = 0, maddr = 0; 89783189849SRahul Lakkireddy u32 finiver, finicsum, cfcsum; 89883189849SRahul Lakkireddy int ret; 89983189849SRahul Lakkireddy int config_issued = 0; 90083189849SRahul Lakkireddy int cfg_addr; 90183189849SRahul Lakkireddy char config_name[20]; 90283189849SRahul Lakkireddy 90383189849SRahul Lakkireddy /* 90483189849SRahul Lakkireddy * Reset device if necessary. 90583189849SRahul Lakkireddy */ 90683189849SRahul Lakkireddy if (reset) { 90783189849SRahul Lakkireddy ret = t4_fw_reset(adapter, adapter->mbox, 90883189849SRahul Lakkireddy F_PIORSTMODE | F_PIORST); 90983189849SRahul Lakkireddy if (ret < 0) { 91083189849SRahul Lakkireddy dev_warn(adapter, "Firmware reset failed, error %d\n", 91183189849SRahul Lakkireddy -ret); 91283189849SRahul Lakkireddy goto bye; 91383189849SRahul Lakkireddy } 91483189849SRahul Lakkireddy } 91583189849SRahul Lakkireddy 91683189849SRahul Lakkireddy cfg_addr = t4_flash_cfg_addr(adapter); 91783189849SRahul Lakkireddy if (cfg_addr < 0) { 91883189849SRahul Lakkireddy ret = cfg_addr; 91983189849SRahul Lakkireddy dev_warn(adapter, "Finding address for firmware config file in flash failed, error %d\n", 92083189849SRahul Lakkireddy -ret); 92183189849SRahul Lakkireddy goto bye; 92283189849SRahul Lakkireddy } 92383189849SRahul Lakkireddy 92483189849SRahul Lakkireddy strcpy(config_name, "On Flash"); 92583189849SRahul Lakkireddy mtype = FW_MEMTYPE_CF_FLASH; 92683189849SRahul Lakkireddy maddr = cfg_addr; 92783189849SRahul Lakkireddy 92883189849SRahul Lakkireddy /* 92983189849SRahul Lakkireddy * Issue a Capability Configuration command to the firmware to get it 93083189849SRahul Lakkireddy * to parse the Configuration File. We don't use t4_fw_config_file() 93183189849SRahul Lakkireddy * because we want the ability to modify various features after we've 93283189849SRahul Lakkireddy * processed the configuration file ... 93383189849SRahul Lakkireddy */ 93483189849SRahul Lakkireddy memset(&caps_cmd, 0, sizeof(caps_cmd)); 93583189849SRahul Lakkireddy caps_cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) | 93683189849SRahul Lakkireddy F_FW_CMD_REQUEST | F_FW_CMD_READ); 93783189849SRahul Lakkireddy caps_cmd.cfvalid_to_len16 = 93883189849SRahul Lakkireddy cpu_to_be32(F_FW_CAPS_CONFIG_CMD_CFVALID | 93983189849SRahul Lakkireddy V_FW_CAPS_CONFIG_CMD_MEMTYPE_CF(mtype) | 94083189849SRahul Lakkireddy V_FW_CAPS_CONFIG_CMD_MEMADDR64K_CF(maddr >> 16) | 94183189849SRahul Lakkireddy FW_LEN16(caps_cmd)); 94283189849SRahul Lakkireddy ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd, sizeof(caps_cmd), 94383189849SRahul Lakkireddy &caps_cmd); 94483189849SRahul Lakkireddy /* 94583189849SRahul Lakkireddy * If the CAPS_CONFIG failed with an ENOENT (for a Firmware 94683189849SRahul Lakkireddy * Configuration File in FLASH), our last gasp effort is to use the 94783189849SRahul Lakkireddy * Firmware Configuration File which is embedded in the firmware. A 94883189849SRahul Lakkireddy * very few early versions of the firmware didn't have one embedded 94983189849SRahul Lakkireddy * but we can ignore those. 95083189849SRahul Lakkireddy */ 95183189849SRahul Lakkireddy if (ret == -ENOENT) { 95283189849SRahul Lakkireddy dev_info(adapter, "%s: Going for embedded config in firmware..\n", 95383189849SRahul Lakkireddy __func__); 95483189849SRahul Lakkireddy 95583189849SRahul Lakkireddy memset(&caps_cmd, 0, sizeof(caps_cmd)); 95683189849SRahul Lakkireddy caps_cmd.op_to_write = 95783189849SRahul Lakkireddy cpu_to_be32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) | 95883189849SRahul Lakkireddy F_FW_CMD_REQUEST | F_FW_CMD_READ); 95983189849SRahul Lakkireddy caps_cmd.cfvalid_to_len16 = cpu_to_be32(FW_LEN16(caps_cmd)); 96083189849SRahul Lakkireddy ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd, 96183189849SRahul Lakkireddy sizeof(caps_cmd), &caps_cmd); 96283189849SRahul Lakkireddy strcpy(config_name, "Firmware Default"); 96383189849SRahul Lakkireddy } 96483189849SRahul Lakkireddy 96583189849SRahul Lakkireddy config_issued = 1; 96683189849SRahul Lakkireddy if (ret < 0) 96783189849SRahul Lakkireddy goto bye; 96883189849SRahul Lakkireddy 96983189849SRahul Lakkireddy finiver = be32_to_cpu(caps_cmd.finiver); 97083189849SRahul Lakkireddy finicsum = be32_to_cpu(caps_cmd.finicsum); 97183189849SRahul Lakkireddy cfcsum = be32_to_cpu(caps_cmd.cfcsum); 97283189849SRahul Lakkireddy if (finicsum != cfcsum) 97383189849SRahul Lakkireddy dev_warn(adapter, "Configuration File checksum mismatch: [fini] csum=%#x, computed csum=%#x\n", 97483189849SRahul Lakkireddy finicsum, cfcsum); 97583189849SRahul Lakkireddy 97683189849SRahul Lakkireddy /* 97783189849SRahul Lakkireddy * If we're a pure NIC driver then disable all offloading facilities. 97883189849SRahul Lakkireddy * This will allow the firmware to optimize aspects of the hardware 97983189849SRahul Lakkireddy * configuration which will result in improved performance. 98083189849SRahul Lakkireddy */ 9813a381a41SShagun Agrawal caps_cmd.niccaps &= cpu_to_be16(~FW_CAPS_CONFIG_NIC_ETHOFLD); 98283189849SRahul Lakkireddy caps_cmd.toecaps = 0; 98383189849SRahul Lakkireddy caps_cmd.iscsicaps = 0; 98483189849SRahul Lakkireddy caps_cmd.rdmacaps = 0; 98583189849SRahul Lakkireddy caps_cmd.fcoecaps = 0; 98683189849SRahul Lakkireddy 98783189849SRahul Lakkireddy /* 98883189849SRahul Lakkireddy * And now tell the firmware to use the configuration we just loaded. 98983189849SRahul Lakkireddy */ 99083189849SRahul Lakkireddy caps_cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) | 99183189849SRahul Lakkireddy F_FW_CMD_REQUEST | F_FW_CMD_WRITE); 99283189849SRahul Lakkireddy caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd)); 99383189849SRahul Lakkireddy ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd, sizeof(caps_cmd), 99483189849SRahul Lakkireddy NULL); 99583189849SRahul Lakkireddy if (ret < 0) { 99683189849SRahul Lakkireddy dev_warn(adapter, "Unable to finalize Firmware Capabilities %d\n", 99783189849SRahul Lakkireddy -ret); 99883189849SRahul Lakkireddy goto bye; 99983189849SRahul Lakkireddy } 100083189849SRahul Lakkireddy 100183189849SRahul Lakkireddy /* 100283189849SRahul Lakkireddy * Tweak configuration based on system architecture, etc. 100383189849SRahul Lakkireddy */ 100483189849SRahul Lakkireddy ret = adap_init0_tweaks(adapter); 100583189849SRahul Lakkireddy if (ret < 0) { 100683189849SRahul Lakkireddy dev_warn(adapter, "Unable to do init0-tweaks %d\n", -ret); 100783189849SRahul Lakkireddy goto bye; 100883189849SRahul Lakkireddy } 100983189849SRahul Lakkireddy 101083189849SRahul Lakkireddy /* 101183189849SRahul Lakkireddy * And finally tell the firmware to initialize itself using the 101283189849SRahul Lakkireddy * parameters from the Configuration File. 101383189849SRahul Lakkireddy */ 101483189849SRahul Lakkireddy ret = t4_fw_initialize(adapter, adapter->mbox); 101583189849SRahul Lakkireddy if (ret < 0) { 101683189849SRahul Lakkireddy dev_warn(adapter, "Initializing Firmware failed, error %d\n", 101783189849SRahul Lakkireddy -ret); 101883189849SRahul Lakkireddy goto bye; 101983189849SRahul Lakkireddy } 102083189849SRahul Lakkireddy 102183189849SRahul Lakkireddy /* 102283189849SRahul Lakkireddy * Return successfully and note that we're operating with parameters 102383189849SRahul Lakkireddy * not supplied by the driver, rather than from hard-wired 102498a7ea33SJerin Jacob * initialization constants buried in the driver. 102583189849SRahul Lakkireddy */ 102683189849SRahul Lakkireddy dev_info(adapter, 102783189849SRahul Lakkireddy "Successfully configured using Firmware Configuration File \"%s\", version %#x, computed checksum %#x\n", 102883189849SRahul Lakkireddy config_name, finiver, cfcsum); 102983189849SRahul Lakkireddy 103083189849SRahul Lakkireddy return 0; 103183189849SRahul Lakkireddy 103283189849SRahul Lakkireddy /* 103383189849SRahul Lakkireddy * Something bad happened. Return the error ... (If the "error" 103483189849SRahul Lakkireddy * is that there's no Configuration File on the adapter we don't 103583189849SRahul Lakkireddy * want to issue a warning since this is fairly common.) 103683189849SRahul Lakkireddy */ 103783189849SRahul Lakkireddy bye: 103883189849SRahul Lakkireddy if (config_issued && ret != -ENOENT) 103983189849SRahul Lakkireddy dev_warn(adapter, "\"%s\" configuration file error %d\n", 104083189849SRahul Lakkireddy config_name, -ret); 104183189849SRahul Lakkireddy 104283189849SRahul Lakkireddy dev_debug(adapter, "%s: returning ret = %d ..\n", __func__, ret); 104383189849SRahul Lakkireddy return ret; 104483189849SRahul Lakkireddy } 104583189849SRahul Lakkireddy 104683189849SRahul Lakkireddy static int adap_init0(struct adapter *adap) 104783189849SRahul Lakkireddy { 10486f2a064bSShagun Agrawal struct fw_caps_config_cmd caps_cmd; 104983189849SRahul Lakkireddy int ret = 0; 105083189849SRahul Lakkireddy u32 v, port_vec; 105183189849SRahul Lakkireddy enum dev_state state; 105283189849SRahul Lakkireddy u32 params[7], val[7]; 105383189849SRahul Lakkireddy int reset = 1; 105483189849SRahul Lakkireddy int mbox = adap->mbox; 105583189849SRahul Lakkireddy 105683189849SRahul Lakkireddy /* 105783189849SRahul Lakkireddy * Contact FW, advertising Master capability. 105883189849SRahul Lakkireddy */ 105983189849SRahul Lakkireddy ret = t4_fw_hello(adap, adap->mbox, adap->mbox, MASTER_MAY, &state); 106083189849SRahul Lakkireddy if (ret < 0) { 106183189849SRahul Lakkireddy dev_err(adap, "%s: could not connect to FW, error %d\n", 106283189849SRahul Lakkireddy __func__, -ret); 106383189849SRahul Lakkireddy goto bye; 106483189849SRahul Lakkireddy } 106583189849SRahul Lakkireddy 106683189849SRahul Lakkireddy CXGBE_DEBUG_MBOX(adap, "%s: adap->mbox = %d; ret = %d\n", __func__, 106783189849SRahul Lakkireddy adap->mbox, ret); 106883189849SRahul Lakkireddy 106983189849SRahul Lakkireddy if (ret == mbox) 107083189849SRahul Lakkireddy adap->flags |= MASTER_PF; 107183189849SRahul Lakkireddy 107283189849SRahul Lakkireddy if (state == DEV_STATE_INIT) { 107383189849SRahul Lakkireddy /* 107483189849SRahul Lakkireddy * Force halt and reset FW because a previous instance may have 107583189849SRahul Lakkireddy * exited abnormally without properly shutting down 107683189849SRahul Lakkireddy */ 107783189849SRahul Lakkireddy ret = t4_fw_halt(adap, adap->mbox, reset); 107883189849SRahul Lakkireddy if (ret < 0) { 107983189849SRahul Lakkireddy dev_err(adap, "Failed to halt. Exit.\n"); 108083189849SRahul Lakkireddy goto bye; 108183189849SRahul Lakkireddy } 108283189849SRahul Lakkireddy 108383189849SRahul Lakkireddy ret = t4_fw_restart(adap, adap->mbox, reset); 108483189849SRahul Lakkireddy if (ret < 0) { 108583189849SRahul Lakkireddy dev_err(adap, "Failed to restart. Exit.\n"); 108683189849SRahul Lakkireddy goto bye; 108783189849SRahul Lakkireddy } 1088efa8a43eSBruce Richardson state = (enum dev_state)((unsigned)state & ~DEV_STATE_INIT); 108983189849SRahul Lakkireddy } 109083189849SRahul Lakkireddy 1091c962618cSRahul Lakkireddy t4_get_version_info(adap); 109283189849SRahul Lakkireddy 109383189849SRahul Lakkireddy ret = t4_get_core_clock(adap, &adap->params.vpd); 109483189849SRahul Lakkireddy if (ret < 0) { 109583189849SRahul Lakkireddy dev_err(adap, "%s: could not get core clock, error %d\n", 109683189849SRahul Lakkireddy __func__, -ret); 109783189849SRahul Lakkireddy goto bye; 109883189849SRahul Lakkireddy } 109983189849SRahul Lakkireddy 110083189849SRahul Lakkireddy /* 110183189849SRahul Lakkireddy * If the firmware is initialized already (and we're not forcing a 110283189849SRahul Lakkireddy * master initialization), note that we're living with existing 110383189849SRahul Lakkireddy * adapter parameters. Otherwise, it's time to try initializing the 110483189849SRahul Lakkireddy * adapter ... 110583189849SRahul Lakkireddy */ 110683189849SRahul Lakkireddy if (state == DEV_STATE_INIT) { 110783189849SRahul Lakkireddy dev_info(adap, "Coming up as %s: Adapter already initialized\n", 110883189849SRahul Lakkireddy adap->flags & MASTER_PF ? "MASTER" : "SLAVE"); 110983189849SRahul Lakkireddy } else { 111083189849SRahul Lakkireddy dev_info(adap, "Coming up as MASTER: Initializing adapter\n"); 111183189849SRahul Lakkireddy 111283189849SRahul Lakkireddy ret = adap_init0_config(adap, reset); 111383189849SRahul Lakkireddy if (ret == -ENOENT) { 111483189849SRahul Lakkireddy dev_err(adap, 111583189849SRahul Lakkireddy "No Configuration File present on adapter. Using hard-wired configuration parameters.\n"); 111683189849SRahul Lakkireddy goto bye; 111783189849SRahul Lakkireddy } 111883189849SRahul Lakkireddy } 111983189849SRahul Lakkireddy if (ret < 0) { 112083189849SRahul Lakkireddy dev_err(adap, "could not initialize adapter, error %d\n", -ret); 112183189849SRahul Lakkireddy goto bye; 112283189849SRahul Lakkireddy } 112383189849SRahul Lakkireddy 112487a3ae3eSRahul Lakkireddy /* Now that we've successfully configured and initialized the adapter 112587a3ae3eSRahul Lakkireddy * (or found it already initialized), we can ask the Firmware what 112687a3ae3eSRahul Lakkireddy * resources it has provisioned for us. 112787a3ae3eSRahul Lakkireddy */ 112887a3ae3eSRahul Lakkireddy ret = t4_get_pfres(adap); 112987a3ae3eSRahul Lakkireddy if (ret) { 113087a3ae3eSRahul Lakkireddy dev_err(adap->pdev_dev, 113187a3ae3eSRahul Lakkireddy "Unable to retrieve resource provisioning info\n"); 113287a3ae3eSRahul Lakkireddy goto bye; 113387a3ae3eSRahul Lakkireddy } 113487a3ae3eSRahul Lakkireddy 11355eb55bf8SRahul Lakkireddy /* Find out what ports are available to us. */ 11365eb55bf8SRahul Lakkireddy v = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) | 11375eb55bf8SRahul Lakkireddy V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_PORTVEC); 11385eb55bf8SRahul Lakkireddy ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1, &v, &port_vec); 11395eb55bf8SRahul Lakkireddy if (ret < 0) { 11405eb55bf8SRahul Lakkireddy dev_err(adap, "%s: failure in t4_query_params; error = %d\n", 11415eb55bf8SRahul Lakkireddy __func__, ret); 11425eb55bf8SRahul Lakkireddy goto bye; 11435eb55bf8SRahul Lakkireddy } 11445eb55bf8SRahul Lakkireddy 11455eb55bf8SRahul Lakkireddy adap->params.nports = hweight32(port_vec); 11465eb55bf8SRahul Lakkireddy adap->params.portvec = port_vec; 11475eb55bf8SRahul Lakkireddy 11485eb55bf8SRahul Lakkireddy dev_debug(adap, "%s: adap->params.nports = %u\n", __func__, 11495eb55bf8SRahul Lakkireddy adap->params.nports); 11505eb55bf8SRahul Lakkireddy 115183189849SRahul Lakkireddy /* 115283189849SRahul Lakkireddy * Give the SGE code a chance to pull in anything that it needs ... 115383189849SRahul Lakkireddy * Note that this must be called after we retrieve our VPD parameters 115483189849SRahul Lakkireddy * in order to know how to convert core ticks to seconds, etc. 115583189849SRahul Lakkireddy */ 115683189849SRahul Lakkireddy ret = t4_sge_init(adap); 115783189849SRahul Lakkireddy if (ret < 0) { 115883189849SRahul Lakkireddy dev_err(adap, "t4_sge_init failed with error %d\n", 115983189849SRahul Lakkireddy -ret); 116083189849SRahul Lakkireddy goto bye; 116183189849SRahul Lakkireddy } 116283189849SRahul Lakkireddy 116383189849SRahul Lakkireddy /* 116483189849SRahul Lakkireddy * Grab some of our basic fundamental operating parameters. 116583189849SRahul Lakkireddy */ 1166*51abd7b2SRahul Lakkireddy params[0] = CXGBE_FW_PARAM_PFVF(L2T_START); 1167*51abd7b2SRahul Lakkireddy params[1] = CXGBE_FW_PARAM_PFVF(L2T_END); 1168*51abd7b2SRahul Lakkireddy params[2] = CXGBE_FW_PARAM_PFVF(FILTER_START); 1169*51abd7b2SRahul Lakkireddy params[3] = CXGBE_FW_PARAM_PFVF(FILTER_END); 117023af667fSShagun Agrawal ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 4, params, val); 11716f2a064bSShagun Agrawal if (ret < 0) 11726f2a064bSShagun Agrawal goto bye; 117323af667fSShagun Agrawal adap->l2t_start = val[0]; 117423af667fSShagun Agrawal adap->l2t_end = val[1]; 117523af667fSShagun Agrawal adap->tids.ftid_base = val[2]; 117623af667fSShagun Agrawal adap->tids.nftids = val[3] - val[2] + 1; 11776f2a064bSShagun Agrawal 1178*51abd7b2SRahul Lakkireddy params[0] = CXGBE_FW_PARAM_PFVF(CLIP_START); 1179*51abd7b2SRahul Lakkireddy params[1] = CXGBE_FW_PARAM_PFVF(CLIP_END); 11803f2c1e20SShagun Agrawal ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params, val); 11813f2c1e20SShagun Agrawal if (ret < 0) 11823f2c1e20SShagun Agrawal goto bye; 11833f2c1e20SShagun Agrawal adap->clipt_start = val[0]; 11843f2c1e20SShagun Agrawal adap->clipt_end = val[1]; 11853f2c1e20SShagun Agrawal 11866f2a064bSShagun Agrawal /* 11876f2a064bSShagun Agrawal * Get device capabilities so we can determine what resources we need 11886f2a064bSShagun Agrawal * to manage. 11896f2a064bSShagun Agrawal */ 11906f2a064bSShagun Agrawal memset(&caps_cmd, 0, sizeof(caps_cmd)); 11916f2a064bSShagun Agrawal caps_cmd.op_to_write = htonl(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) | 11926f2a064bSShagun Agrawal F_FW_CMD_REQUEST | F_FW_CMD_READ); 11936f2a064bSShagun Agrawal caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd)); 11946f2a064bSShagun Agrawal ret = t4_wr_mbox(adap, adap->mbox, &caps_cmd, sizeof(caps_cmd), 11956f2a064bSShagun Agrawal &caps_cmd); 11966f2a064bSShagun Agrawal if (ret < 0) 11976f2a064bSShagun Agrawal goto bye; 11986f2a064bSShagun Agrawal 11993a381a41SShagun Agrawal if ((caps_cmd.niccaps & cpu_to_be16(FW_CAPS_CONFIG_NIC_HASHFILTER)) && 12003a381a41SShagun Agrawal is_t6(adap->params.chip)) { 120171e9b334SRahul Lakkireddy if (cxgbe_init_hash_filter(adap) < 0) 12023a381a41SShagun Agrawal goto bye; 12033a381a41SShagun Agrawal } 12043a381a41SShagun Agrawal 120548f523f6SRahul Lakkireddy /* See if FW supports FW_FILTER2 work request */ 120648f523f6SRahul Lakkireddy if (is_t4(adap->params.chip)) { 120748f523f6SRahul Lakkireddy adap->params.filter2_wr_support = 0; 120848f523f6SRahul Lakkireddy } else { 1209*51abd7b2SRahul Lakkireddy params[0] = CXGBE_FW_PARAM_DEV(FILTER2_WR); 121048f523f6SRahul Lakkireddy ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 121148f523f6SRahul Lakkireddy 1, params, val); 121248f523f6SRahul Lakkireddy adap->params.filter2_wr_support = (ret == 0 && val[0] != 0); 121348f523f6SRahul Lakkireddy } 121448f523f6SRahul Lakkireddy 12156f2a064bSShagun Agrawal /* query tid-related parameters */ 1216*51abd7b2SRahul Lakkireddy params[0] = CXGBE_FW_PARAM_DEV(NTID); 12176f2a064bSShagun Agrawal ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1, 12186f2a064bSShagun Agrawal params, val); 12196f2a064bSShagun Agrawal if (ret < 0) 12206f2a064bSShagun Agrawal goto bye; 12216f2a064bSShagun Agrawal adap->tids.ntids = val[0]; 12223a381a41SShagun Agrawal adap->tids.natids = min(adap->tids.ntids / 2, MAX_ATIDS); 12236f2a064bSShagun Agrawal 122483189849SRahul Lakkireddy /* If we're running on newer firmware, let it know that we're 122583189849SRahul Lakkireddy * prepared to deal with encapsulated CPL messages. Older 122683189849SRahul Lakkireddy * firmware won't understand this and we'll just get 122783189849SRahul Lakkireddy * unencapsulated messages ... 122883189849SRahul Lakkireddy */ 1229*51abd7b2SRahul Lakkireddy params[0] = CXGBE_FW_PARAM_PFVF(CPLFW4MSG_ENCAP); 123083189849SRahul Lakkireddy val[0] = 1; 123183189849SRahul Lakkireddy (void)t4_set_params(adap, adap->mbox, adap->pf, 0, 1, params, val); 123283189849SRahul Lakkireddy 123383189849SRahul Lakkireddy /* 123483189849SRahul Lakkireddy * Find out whether we're allowed to use the T5+ ULPTX MEMWRITE DSGL 123583189849SRahul Lakkireddy * capability. Earlier versions of the firmware didn't have the 123683189849SRahul Lakkireddy * ULPTX_MEMWRITE_DSGL so we'll interpret a query failure as no 123783189849SRahul Lakkireddy * permission to use ULPTX MEMWRITE DSGL. 123883189849SRahul Lakkireddy */ 123983189849SRahul Lakkireddy if (is_t4(adap->params.chip)) { 124083189849SRahul Lakkireddy adap->params.ulptx_memwrite_dsgl = false; 124183189849SRahul Lakkireddy } else { 1242*51abd7b2SRahul Lakkireddy params[0] = CXGBE_FW_PARAM_DEV(ULPTX_MEMWRITE_DSGL); 124383189849SRahul Lakkireddy ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 124483189849SRahul Lakkireddy 1, params, val); 124583189849SRahul Lakkireddy adap->params.ulptx_memwrite_dsgl = (ret == 0 && val[0] != 0); 124683189849SRahul Lakkireddy } 124783189849SRahul Lakkireddy 1248*51abd7b2SRahul Lakkireddy /* Query for max number of packets that can be coalesced for Tx */ 1249*51abd7b2SRahul Lakkireddy params[0] = CXGBE_FW_PARAM_PFVF(MAX_PKTS_PER_ETH_TX_PKTS_WR); 1250*51abd7b2SRahul Lakkireddy ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1, params, val); 1251*51abd7b2SRahul Lakkireddy if (!ret && val[0] > 0) 1252*51abd7b2SRahul Lakkireddy adap->params.max_tx_coalesce_num = val[0]; 1253*51abd7b2SRahul Lakkireddy else 1254*51abd7b2SRahul Lakkireddy adap->params.max_tx_coalesce_num = ETH_COALESCE_PKT_NUM; 1255*51abd7b2SRahul Lakkireddy 125683189849SRahul Lakkireddy /* 125783189849SRahul Lakkireddy * The MTU/MSS Table is initialized by now, so load their values. If 125883189849SRahul Lakkireddy * we're initializing the adapter, then we'll make any modifications 125983189849SRahul Lakkireddy * we want to the MTU/MSS Table and also initialize the congestion 126083189849SRahul Lakkireddy * parameters. 126183189849SRahul Lakkireddy */ 126283189849SRahul Lakkireddy t4_read_mtu_tbl(adap, adap->params.mtus, NULL); 126383189849SRahul Lakkireddy if (state != DEV_STATE_INIT) { 126483189849SRahul Lakkireddy int i; 126583189849SRahul Lakkireddy 126683189849SRahul Lakkireddy /* 126783189849SRahul Lakkireddy * The default MTU Table contains values 1492 and 1500. 126883189849SRahul Lakkireddy * However, for TCP, it's better to have two values which are 126983189849SRahul Lakkireddy * a multiple of 8 +/- 4 bytes apart near this popular MTU. 127083189849SRahul Lakkireddy * This allows us to have a TCP Data Payload which is a 127183189849SRahul Lakkireddy * multiple of 8 regardless of what combination of TCP Options 127283189849SRahul Lakkireddy * are in use (always a multiple of 4 bytes) which is 127383189849SRahul Lakkireddy * important for performance reasons. For instance, if no 127483189849SRahul Lakkireddy * options are in use, then we have a 20-byte IP header and a 127583189849SRahul Lakkireddy * 20-byte TCP header. In this case, a 1500-byte MSS would 127683189849SRahul Lakkireddy * result in a TCP Data Payload of 1500 - 40 == 1460 bytes 127783189849SRahul Lakkireddy * which is not a multiple of 8. So using an MSS of 1488 in 127883189849SRahul Lakkireddy * this case results in a TCP Data Payload of 1448 bytes which 127983189849SRahul Lakkireddy * is a multiple of 8. On the other hand, if 12-byte TCP Time 128083189849SRahul Lakkireddy * Stamps have been negotiated, then an MTU of 1500 bytes 128183189849SRahul Lakkireddy * results in a TCP Data Payload of 1448 bytes which, as 128283189849SRahul Lakkireddy * above, is a multiple of 8 bytes ... 128383189849SRahul Lakkireddy */ 128483189849SRahul Lakkireddy for (i = 0; i < NMTUS; i++) 128583189849SRahul Lakkireddy if (adap->params.mtus[i] == 1492) { 128683189849SRahul Lakkireddy adap->params.mtus[i] = 1488; 128783189849SRahul Lakkireddy break; 128883189849SRahul Lakkireddy } 128983189849SRahul Lakkireddy 129083189849SRahul Lakkireddy t4_load_mtus(adap, adap->params.mtus, adap->params.a_wnd, 129183189849SRahul Lakkireddy adap->params.b_wnd); 129283189849SRahul Lakkireddy } 129383189849SRahul Lakkireddy t4_init_sge_params(adap); 129483189849SRahul Lakkireddy t4_init_tp_params(adap); 1295ee606d92SRahul Lakkireddy configure_pcie_ext_tag(adap); 1296cda260a4SShagun Agrawal configure_vlan_types(adap); 1297b7fd9ea8SStephen Hemminger cxgbe_configure_max_ethqsets(adap); 129883189849SRahul Lakkireddy 129983189849SRahul Lakkireddy adap->params.drv_memwin = MEMWIN_NIC; 130083189849SRahul Lakkireddy adap->flags |= FW_OK; 130183189849SRahul Lakkireddy dev_debug(adap, "%s: returning zero..\n", __func__); 130283189849SRahul Lakkireddy return 0; 130383189849SRahul Lakkireddy 130483189849SRahul Lakkireddy /* 130583189849SRahul Lakkireddy * Something bad happened. If a command timed out or failed with EIO 130683189849SRahul Lakkireddy * FW does not operate within its spec or something catastrophic 130783189849SRahul Lakkireddy * happened to HW/FW, stop issuing commands. 130883189849SRahul Lakkireddy */ 130983189849SRahul Lakkireddy bye: 131083189849SRahul Lakkireddy if (ret != -ETIMEDOUT && ret != -EIO) 131183189849SRahul Lakkireddy t4_fw_bye(adap, adap->mbox); 131283189849SRahul Lakkireddy return ret; 131383189849SRahul Lakkireddy } 131483189849SRahul Lakkireddy 131583189849SRahul Lakkireddy /** 131683189849SRahul Lakkireddy * t4_os_portmod_changed - handle port module changes 131783189849SRahul Lakkireddy * @adap: the adapter associated with the module change 131883189849SRahul Lakkireddy * @port_id: the port index whose module status has changed 131983189849SRahul Lakkireddy * 132083189849SRahul Lakkireddy * This is the OS-dependent handler for port module changes. It is 132183189849SRahul Lakkireddy * invoked when a port module is removed or inserted for any OS-specific 132283189849SRahul Lakkireddy * processing. 132383189849SRahul Lakkireddy */ 132483189849SRahul Lakkireddy void t4_os_portmod_changed(const struct adapter *adap, int port_id) 132583189849SRahul Lakkireddy { 132683189849SRahul Lakkireddy static const char * const mod_str[] = { 132783189849SRahul Lakkireddy NULL, "LR", "SR", "ER", "passive DA", "active DA", "LRM" 132883189849SRahul Lakkireddy }; 132983189849SRahul Lakkireddy 13302195df6dSRahul Lakkireddy const struct port_info *pi = adap2pinfo(adap, port_id); 133183189849SRahul Lakkireddy 133283189849SRahul Lakkireddy if (pi->mod_type == FW_PORT_MOD_TYPE_NONE) 133383189849SRahul Lakkireddy dev_info(adap, "Port%d: port module unplugged\n", pi->port_id); 133483189849SRahul Lakkireddy else if (pi->mod_type < ARRAY_SIZE(mod_str)) 133583189849SRahul Lakkireddy dev_info(adap, "Port%d: %s port module inserted\n", pi->port_id, 133683189849SRahul Lakkireddy mod_str[pi->mod_type]); 133783189849SRahul Lakkireddy else if (pi->mod_type == FW_PORT_MOD_TYPE_NOTSUPPORTED) 13389da2a694SRahul Lakkireddy dev_info(adap, "Port%d: unsupported port module inserted\n", 133983189849SRahul Lakkireddy pi->port_id); 134083189849SRahul Lakkireddy else if (pi->mod_type == FW_PORT_MOD_TYPE_UNKNOWN) 13419da2a694SRahul Lakkireddy dev_info(adap, "Port%d: unknown port module inserted\n", 134283189849SRahul Lakkireddy pi->port_id); 134383189849SRahul Lakkireddy else if (pi->mod_type == FW_PORT_MOD_TYPE_ERROR) 134483189849SRahul Lakkireddy dev_info(adap, "Port%d: transceiver module error\n", 134583189849SRahul Lakkireddy pi->port_id); 134683189849SRahul Lakkireddy else 134783189849SRahul Lakkireddy dev_info(adap, "Port%d: unknown module type %d inserted\n", 134883189849SRahul Lakkireddy pi->port_id, pi->mod_type); 134983189849SRahul Lakkireddy } 135083189849SRahul Lakkireddy 1351b7fd9ea8SStephen Hemminger bool cxgbe_force_linkup(struct adapter *adap) 1352f5b3c7b2SShagun Agrawal { 1353f5b3c7b2SShagun Agrawal if (is_pf4(adap)) 1354f5b3c7b2SShagun Agrawal return false; /* force_linkup not required for pf driver */ 1355dd7c9f12SRahul Lakkireddy 1356dd7c9f12SRahul Lakkireddy return adap->devargs.force_link_up; 1357f5b3c7b2SShagun Agrawal } 1358f5b3c7b2SShagun Agrawal 135992c8a632SRahul Lakkireddy /** 13600462d115SRahul Lakkireddy * link_start - enable a port 13610462d115SRahul Lakkireddy * @dev: the port to enable 13620462d115SRahul Lakkireddy * 13630462d115SRahul Lakkireddy * Performs the MAC and PHY actions needed to enable a port. 13640462d115SRahul Lakkireddy */ 1365b7fd9ea8SStephen Hemminger int cxgbe_link_start(struct port_info *pi) 13660462d115SRahul Lakkireddy { 13670462d115SRahul Lakkireddy struct adapter *adapter = pi->adapter; 13686507fb6fSRahul Lakkireddy u64 conf_offloads; 13695a9e303aSRahul Lakkireddy unsigned int mtu; 13706507fb6fSRahul Lakkireddy int ret; 13715a9e303aSRahul Lakkireddy 13725a9e303aSRahul Lakkireddy mtu = pi->eth_dev->data->dev_conf.rxmode.max_rx_pkt_len - 137335b2d13fSOlivier Matz (RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN); 13740462d115SRahul Lakkireddy 13756507fb6fSRahul Lakkireddy conf_offloads = pi->eth_dev->data->dev_conf.rxmode.offloads; 13766507fb6fSRahul Lakkireddy 13770462d115SRahul Lakkireddy /* 13780462d115SRahul Lakkireddy * We do not set address filters and promiscuity here, the stack does 13790462d115SRahul Lakkireddy * that step explicitly. 13800462d115SRahul Lakkireddy */ 13816507fb6fSRahul Lakkireddy ret = t4_set_rxmode(adapter, adapter->mbox, pi->viid, mtu, -1, -1, -1, 13826507fb6fSRahul Lakkireddy !!(conf_offloads & DEV_RX_OFFLOAD_VLAN_STRIP), 13836507fb6fSRahul Lakkireddy true); 13840462d115SRahul Lakkireddy if (ret == 0) { 1385fefee7a6SShagun Agrawal ret = cxgbe_mpstcam_modify(pi, (int)pi->xact_addr_filt, 1386fefee7a6SShagun Agrawal (u8 *)&pi->eth_dev->data->mac_addrs[0]); 13870462d115SRahul Lakkireddy if (ret >= 0) { 13880462d115SRahul Lakkireddy pi->xact_addr_filt = ret; 13890462d115SRahul Lakkireddy ret = 0; 13900462d115SRahul Lakkireddy } 13910462d115SRahul Lakkireddy } 13925e80364aSKumar Sanghvi if (ret == 0 && is_pf4(adapter)) 13930462d115SRahul Lakkireddy ret = t4_link_l1cfg(adapter, adapter->mbox, pi->tx_chan, 13940462d115SRahul Lakkireddy &pi->link_cfg); 13950462d115SRahul Lakkireddy if (ret == 0) { 13960462d115SRahul Lakkireddy /* 13970462d115SRahul Lakkireddy * Enabling a Virtual Interface can result in an interrupt 13980462d115SRahul Lakkireddy * during the processing of the VI Enable command and, in some 13990462d115SRahul Lakkireddy * paths, result in an attempt to issue another command in the 14000462d115SRahul Lakkireddy * interrupt context. Thus, we disable interrupts during the 14010462d115SRahul Lakkireddy * course of the VI Enable command ... 14020462d115SRahul Lakkireddy */ 14030462d115SRahul Lakkireddy ret = t4_enable_vi_params(adapter, adapter->mbox, pi->viid, 14040462d115SRahul Lakkireddy true, true, false); 14050462d115SRahul Lakkireddy } 1406f5b3c7b2SShagun Agrawal 1407b7fd9ea8SStephen Hemminger if (ret == 0 && cxgbe_force_linkup(adapter)) 1408f5b3c7b2SShagun Agrawal pi->eth_dev->data->dev_link.link_status = ETH_LINK_UP; 14090462d115SRahul Lakkireddy return ret; 14100462d115SRahul Lakkireddy } 14110462d115SRahul Lakkireddy 14120462d115SRahul Lakkireddy /** 141308e21af9SKumar Sanghvi * cxgbe_write_rss_conf - flash the RSS configuration for a given port 141408e21af9SKumar Sanghvi * @pi: the port 141508e21af9SKumar Sanghvi * @rss_hf: Hash configuration to apply 141608e21af9SKumar Sanghvi */ 141708e21af9SKumar Sanghvi int cxgbe_write_rss_conf(const struct port_info *pi, uint64_t rss_hf) 141808e21af9SKumar Sanghvi { 141908e21af9SKumar Sanghvi struct adapter *adapter = pi->adapter; 142008e21af9SKumar Sanghvi const struct sge_eth_rxq *rxq; 142108e21af9SKumar Sanghvi u64 flags = 0; 142208e21af9SKumar Sanghvi u16 rss; 142308e21af9SKumar Sanghvi int err; 142408e21af9SKumar Sanghvi 142508e21af9SKumar Sanghvi /* Should never be called before setting up sge eth rx queues */ 142608e21af9SKumar Sanghvi if (!(adapter->flags & FULL_INIT_DONE)) { 142708e21af9SKumar Sanghvi dev_err(adap, "%s No RXQs available on port %d\n", 142808e21af9SKumar Sanghvi __func__, pi->port_id); 142908e21af9SKumar Sanghvi return -EINVAL; 143008e21af9SKumar Sanghvi } 143108e21af9SKumar Sanghvi 143208e21af9SKumar Sanghvi /* Don't allow unsupported hash functions */ 143308e21af9SKumar Sanghvi if (rss_hf & ~CXGBE_RSS_HF_ALL) 143408e21af9SKumar Sanghvi return -EINVAL; 143508e21af9SKumar Sanghvi 1436d97aa415SRahul Lakkireddy if (rss_hf & CXGBE_RSS_HF_IPV4_MASK) 143708e21af9SKumar Sanghvi flags |= F_FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN; 143808e21af9SKumar Sanghvi 143908e21af9SKumar Sanghvi if (rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) 144008e21af9SKumar Sanghvi flags |= F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN; 144108e21af9SKumar Sanghvi 144208e21af9SKumar Sanghvi if (rss_hf & ETH_RSS_NONFRAG_IPV4_UDP) 144308e21af9SKumar Sanghvi flags |= F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN | 144408e21af9SKumar Sanghvi F_FW_RSS_VI_CONFIG_CMD_UDPEN; 144508e21af9SKumar Sanghvi 1446d97aa415SRahul Lakkireddy if (rss_hf & CXGBE_RSS_HF_IPV6_MASK) 144708e21af9SKumar Sanghvi flags |= F_FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN; 144808e21af9SKumar Sanghvi 1449d97aa415SRahul Lakkireddy if (rss_hf & CXGBE_RSS_HF_TCP_IPV6_MASK) 1450d97aa415SRahul Lakkireddy flags |= F_FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN | 1451d97aa415SRahul Lakkireddy F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN; 145208e21af9SKumar Sanghvi 1453d97aa415SRahul Lakkireddy if (rss_hf & CXGBE_RSS_HF_UDP_IPV6_MASK) 1454d97aa415SRahul Lakkireddy flags |= F_FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN | 1455d97aa415SRahul Lakkireddy F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN | 145608e21af9SKumar Sanghvi F_FW_RSS_VI_CONFIG_CMD_UDPEN; 145708e21af9SKumar Sanghvi 145808e21af9SKumar Sanghvi rxq = &adapter->sge.ethrxq[pi->first_qset]; 145908e21af9SKumar Sanghvi rss = rxq[0].rspq.abs_id; 146008e21af9SKumar Sanghvi 146108e21af9SKumar Sanghvi /* If Tunnel All Lookup isn't specified in the global RSS 146208e21af9SKumar Sanghvi * Configuration, then we need to specify a default Ingress 146308e21af9SKumar Sanghvi * Queue for any ingress packets which aren't hashed. We'll 146408e21af9SKumar Sanghvi * use our first ingress queue ... 146508e21af9SKumar Sanghvi */ 146608e21af9SKumar Sanghvi err = t4_config_vi_rss(adapter, adapter->mbox, pi->viid, 146708e21af9SKumar Sanghvi flags, rss); 146808e21af9SKumar Sanghvi return err; 146908e21af9SKumar Sanghvi } 147008e21af9SKumar Sanghvi 147108e21af9SKumar Sanghvi /** 147208e21af9SKumar Sanghvi * cxgbe_write_rss - write the RSS table for a given port 147392c8a632SRahul Lakkireddy * @pi: the port 147492c8a632SRahul Lakkireddy * @queues: array of queue indices for RSS 147592c8a632SRahul Lakkireddy * 147692c8a632SRahul Lakkireddy * Sets up the portion of the HW RSS table for the port's VI to distribute 147792c8a632SRahul Lakkireddy * packets to the Rx queues in @queues. 147892c8a632SRahul Lakkireddy */ 147908e21af9SKumar Sanghvi int cxgbe_write_rss(const struct port_info *pi, const u16 *queues) 148092c8a632SRahul Lakkireddy { 148192c8a632SRahul Lakkireddy u16 *rss; 148292c8a632SRahul Lakkireddy int i, err; 148392c8a632SRahul Lakkireddy struct adapter *adapter = pi->adapter; 148492c8a632SRahul Lakkireddy const struct sge_eth_rxq *rxq; 148592c8a632SRahul Lakkireddy 148692c8a632SRahul Lakkireddy /* Should never be called before setting up sge eth rx queues */ 148792c8a632SRahul Lakkireddy BUG_ON(!(adapter->flags & FULL_INIT_DONE)); 148892c8a632SRahul Lakkireddy 148992c8a632SRahul Lakkireddy rxq = &adapter->sge.ethrxq[pi->first_qset]; 149092c8a632SRahul Lakkireddy rss = rte_zmalloc(NULL, pi->rss_size * sizeof(u16), 0); 149192c8a632SRahul Lakkireddy if (!rss) 149292c8a632SRahul Lakkireddy return -ENOMEM; 149392c8a632SRahul Lakkireddy 149492c8a632SRahul Lakkireddy /* map the queue indices to queue ids */ 149592c8a632SRahul Lakkireddy for (i = 0; i < pi->rss_size; i++, queues++) 149692c8a632SRahul Lakkireddy rss[i] = rxq[*queues].rspq.abs_id; 149792c8a632SRahul Lakkireddy 149892c8a632SRahul Lakkireddy err = t4_config_rss_range(adapter, adapter->pf, pi->viid, 0, 149992c8a632SRahul Lakkireddy pi->rss_size, rss, pi->rss_size); 150092c8a632SRahul Lakkireddy rte_free(rss); 150192c8a632SRahul Lakkireddy return err; 150292c8a632SRahul Lakkireddy } 150392c8a632SRahul Lakkireddy 150492c8a632SRahul Lakkireddy /** 150592c8a632SRahul Lakkireddy * setup_rss - configure RSS 150692c8a632SRahul Lakkireddy * @adapter: the adapter 150792c8a632SRahul Lakkireddy * 150892c8a632SRahul Lakkireddy * Sets up RSS to distribute packets to multiple receive queues. We 150992c8a632SRahul Lakkireddy * configure the RSS CPU lookup table to distribute to the number of HW 151092c8a632SRahul Lakkireddy * receive queues, and the response queue lookup table to narrow that 151192c8a632SRahul Lakkireddy * down to the response queues actually configured for each port. 151292c8a632SRahul Lakkireddy * We always configure the RSS mapping for all ports since the mapping 151392c8a632SRahul Lakkireddy * table has plenty of entries. 151492c8a632SRahul Lakkireddy */ 1515b7fd9ea8SStephen Hemminger int cxgbe_setup_rss(struct port_info *pi) 151692c8a632SRahul Lakkireddy { 151792c8a632SRahul Lakkireddy int j, err; 151892c8a632SRahul Lakkireddy struct adapter *adapter = pi->adapter; 151992c8a632SRahul Lakkireddy 152092c8a632SRahul Lakkireddy dev_debug(adapter, "%s: pi->rss_size = %u; pi->n_rx_qsets = %u\n", 152192c8a632SRahul Lakkireddy __func__, pi->rss_size, pi->n_rx_qsets); 152292c8a632SRahul Lakkireddy 15231039ee1cSEmmanuel Roullit if (!(pi->flags & PORT_RSS_DONE)) { 152492c8a632SRahul Lakkireddy if (adapter->flags & FULL_INIT_DONE) { 152592c8a632SRahul Lakkireddy /* Fill default values with equal distribution */ 152692c8a632SRahul Lakkireddy for (j = 0; j < pi->rss_size; j++) 152792c8a632SRahul Lakkireddy pi->rss[j] = j % pi->n_rx_qsets; 152892c8a632SRahul Lakkireddy 152908e21af9SKumar Sanghvi err = cxgbe_write_rss(pi, pi->rss); 153008e21af9SKumar Sanghvi if (err) 153108e21af9SKumar Sanghvi return err; 153208e21af9SKumar Sanghvi 153308e21af9SKumar Sanghvi err = cxgbe_write_rss_conf(pi, pi->rss_hf); 153492c8a632SRahul Lakkireddy if (err) 153592c8a632SRahul Lakkireddy return err; 153692c8a632SRahul Lakkireddy pi->flags |= PORT_RSS_DONE; 153792c8a632SRahul Lakkireddy } 153892c8a632SRahul Lakkireddy } 153992c8a632SRahul Lakkireddy return 0; 154092c8a632SRahul Lakkireddy } 154192c8a632SRahul Lakkireddy 15420462d115SRahul Lakkireddy /* 15430462d115SRahul Lakkireddy * Enable NAPI scheduling and interrupt generation for all Rx queues. 15440462d115SRahul Lakkireddy */ 1545d87ba24dSRahul Lakkireddy static void enable_rx(struct adapter *adap, struct sge_rspq *q) 15460462d115SRahul Lakkireddy { 15470462d115SRahul Lakkireddy /* 0-increment GTS to start the timer and enable interrupts */ 15485e59e39aSKumar Sanghvi t4_write_reg(adap, is_pf4(adap) ? MYPF_REG(A_SGE_PF_GTS) : 15495e59e39aSKumar Sanghvi T4VF_SGE_BASE_ADDR + A_SGE_VF_GTS, 15500462d115SRahul Lakkireddy V_SEINTARM(q->intr_params) | 15510462d115SRahul Lakkireddy V_INGRESSQID(q->cntxt_id)); 15520462d115SRahul Lakkireddy } 1553d87ba24dSRahul Lakkireddy 1554d87ba24dSRahul Lakkireddy void cxgbe_enable_rx_queues(struct port_info *pi) 1555d87ba24dSRahul Lakkireddy { 1556d87ba24dSRahul Lakkireddy struct adapter *adap = pi->adapter; 1557d87ba24dSRahul Lakkireddy struct sge *s = &adap->sge; 1558d87ba24dSRahul Lakkireddy unsigned int i; 1559d87ba24dSRahul Lakkireddy 1560d87ba24dSRahul Lakkireddy for (i = 0; i < pi->n_rx_qsets; i++) 1561d87ba24dSRahul Lakkireddy enable_rx(adap, &s->ethrxq[pi->first_qset + i].rspq); 15620462d115SRahul Lakkireddy } 15630462d115SRahul Lakkireddy 15640462d115SRahul Lakkireddy /** 1565e307e65bSRahul Lakkireddy * fw_caps_to_speed_caps - translate Firmware Port Caps to Speed Caps. 1566e307e65bSRahul Lakkireddy * @port_type: Firmware Port Type 1567e307e65bSRahul Lakkireddy * @fw_caps: Firmware Port Capabilities 1568e307e65bSRahul Lakkireddy * @speed_caps: Device Info Speed Capabilities 1569e307e65bSRahul Lakkireddy * 1570e307e65bSRahul Lakkireddy * Translate a Firmware Port Capabilities specification to Device Info 1571e307e65bSRahul Lakkireddy * Speed Capabilities. 1572e307e65bSRahul Lakkireddy */ 1573e307e65bSRahul Lakkireddy static void fw_caps_to_speed_caps(enum fw_port_type port_type, 1574e307e65bSRahul Lakkireddy unsigned int fw_caps, 1575e307e65bSRahul Lakkireddy u32 *speed_caps) 1576e307e65bSRahul Lakkireddy { 1577e307e65bSRahul Lakkireddy #define SET_SPEED(__speed_name) \ 1578e307e65bSRahul Lakkireddy do { \ 1579e307e65bSRahul Lakkireddy *speed_caps |= ETH_LINK_ ## __speed_name; \ 1580e307e65bSRahul Lakkireddy } while (0) 1581e307e65bSRahul Lakkireddy 1582e307e65bSRahul Lakkireddy #define FW_CAPS_TO_SPEED(__fw_name) \ 1583e307e65bSRahul Lakkireddy do { \ 158476488837SRahul Lakkireddy if (fw_caps & FW_PORT_CAP32_ ## __fw_name) \ 1585e307e65bSRahul Lakkireddy SET_SPEED(__fw_name); \ 1586e307e65bSRahul Lakkireddy } while (0) 1587e307e65bSRahul Lakkireddy 1588e307e65bSRahul Lakkireddy switch (port_type) { 1589e307e65bSRahul Lakkireddy case FW_PORT_TYPE_BT_SGMII: 1590e307e65bSRahul Lakkireddy case FW_PORT_TYPE_BT_XFI: 1591e307e65bSRahul Lakkireddy case FW_PORT_TYPE_BT_XAUI: 1592e307e65bSRahul Lakkireddy FW_CAPS_TO_SPEED(SPEED_100M); 1593e307e65bSRahul Lakkireddy FW_CAPS_TO_SPEED(SPEED_1G); 1594e307e65bSRahul Lakkireddy FW_CAPS_TO_SPEED(SPEED_10G); 1595e307e65bSRahul Lakkireddy break; 1596e307e65bSRahul Lakkireddy 1597e307e65bSRahul Lakkireddy case FW_PORT_TYPE_KX4: 1598e307e65bSRahul Lakkireddy case FW_PORT_TYPE_KX: 1599e307e65bSRahul Lakkireddy case FW_PORT_TYPE_FIBER_XFI: 1600e307e65bSRahul Lakkireddy case FW_PORT_TYPE_FIBER_XAUI: 1601e307e65bSRahul Lakkireddy case FW_PORT_TYPE_SFP: 1602e307e65bSRahul Lakkireddy case FW_PORT_TYPE_QSFP_10G: 1603e307e65bSRahul Lakkireddy case FW_PORT_TYPE_QSA: 1604e307e65bSRahul Lakkireddy FW_CAPS_TO_SPEED(SPEED_1G); 1605e307e65bSRahul Lakkireddy FW_CAPS_TO_SPEED(SPEED_10G); 1606e307e65bSRahul Lakkireddy break; 1607e307e65bSRahul Lakkireddy 1608e307e65bSRahul Lakkireddy case FW_PORT_TYPE_KR: 1609e307e65bSRahul Lakkireddy SET_SPEED(SPEED_10G); 1610e307e65bSRahul Lakkireddy break; 1611e307e65bSRahul Lakkireddy 1612e307e65bSRahul Lakkireddy case FW_PORT_TYPE_BP_AP: 1613e307e65bSRahul Lakkireddy case FW_PORT_TYPE_BP4_AP: 1614e307e65bSRahul Lakkireddy SET_SPEED(SPEED_1G); 1615e307e65bSRahul Lakkireddy SET_SPEED(SPEED_10G); 1616e307e65bSRahul Lakkireddy break; 1617e307e65bSRahul Lakkireddy 1618e307e65bSRahul Lakkireddy case FW_PORT_TYPE_BP40_BA: 1619e307e65bSRahul Lakkireddy case FW_PORT_TYPE_QSFP: 1620e307e65bSRahul Lakkireddy SET_SPEED(SPEED_40G); 1621e307e65bSRahul Lakkireddy break; 1622e307e65bSRahul Lakkireddy 1623e307e65bSRahul Lakkireddy case FW_PORT_TYPE_CR_QSFP: 1624e307e65bSRahul Lakkireddy case FW_PORT_TYPE_SFP28: 1625e307e65bSRahul Lakkireddy case FW_PORT_TYPE_KR_SFP28: 1626e307e65bSRahul Lakkireddy FW_CAPS_TO_SPEED(SPEED_1G); 1627e307e65bSRahul Lakkireddy FW_CAPS_TO_SPEED(SPEED_10G); 1628e307e65bSRahul Lakkireddy FW_CAPS_TO_SPEED(SPEED_25G); 1629e307e65bSRahul Lakkireddy break; 1630e307e65bSRahul Lakkireddy 1631e307e65bSRahul Lakkireddy case FW_PORT_TYPE_CR2_QSFP: 1632e307e65bSRahul Lakkireddy SET_SPEED(SPEED_50G); 1633e307e65bSRahul Lakkireddy break; 1634e307e65bSRahul Lakkireddy 1635e307e65bSRahul Lakkireddy case FW_PORT_TYPE_KR4_100G: 1636e307e65bSRahul Lakkireddy case FW_PORT_TYPE_CR4_QSFP: 1637e307e65bSRahul Lakkireddy FW_CAPS_TO_SPEED(SPEED_25G); 1638e307e65bSRahul Lakkireddy FW_CAPS_TO_SPEED(SPEED_40G); 163976488837SRahul Lakkireddy FW_CAPS_TO_SPEED(SPEED_50G); 1640e307e65bSRahul Lakkireddy FW_CAPS_TO_SPEED(SPEED_100G); 1641e307e65bSRahul Lakkireddy break; 1642e307e65bSRahul Lakkireddy 1643e307e65bSRahul Lakkireddy default: 1644e307e65bSRahul Lakkireddy break; 1645e307e65bSRahul Lakkireddy } 1646e307e65bSRahul Lakkireddy 1647e307e65bSRahul Lakkireddy #undef FW_CAPS_TO_SPEED 1648e307e65bSRahul Lakkireddy #undef SET_SPEED 1649e307e65bSRahul Lakkireddy } 1650e307e65bSRahul Lakkireddy 1651e307e65bSRahul Lakkireddy /** 1652e307e65bSRahul Lakkireddy * cxgbe_get_speed_caps - Fetch supported speed capabilities 1653e307e65bSRahul Lakkireddy * @pi: Underlying port's info 1654e307e65bSRahul Lakkireddy * @speed_caps: Device Info speed capabilities 1655e307e65bSRahul Lakkireddy * 1656e307e65bSRahul Lakkireddy * Fetch supported speed capabilities of the underlying port. 1657e307e65bSRahul Lakkireddy */ 1658e307e65bSRahul Lakkireddy void cxgbe_get_speed_caps(struct port_info *pi, u32 *speed_caps) 1659e307e65bSRahul Lakkireddy { 1660e307e65bSRahul Lakkireddy *speed_caps = 0; 1661e307e65bSRahul Lakkireddy 166276488837SRahul Lakkireddy fw_caps_to_speed_caps(pi->port_type, pi->link_cfg.pcaps, 1663e307e65bSRahul Lakkireddy speed_caps); 1664e307e65bSRahul Lakkireddy 166576488837SRahul Lakkireddy if (!(pi->link_cfg.pcaps & FW_PORT_CAP32_ANEG)) 1666e307e65bSRahul Lakkireddy *speed_caps |= ETH_LINK_SPEED_FIXED; 1667e307e65bSRahul Lakkireddy } 1668e307e65bSRahul Lakkireddy 1669e307e65bSRahul Lakkireddy /** 1670265af08eSRahul Lakkireddy * cxgbe_set_link_status - Set device link up or down. 1671265af08eSRahul Lakkireddy * @pi: Underlying port's info 1672265af08eSRahul Lakkireddy * @status: 0 - down, 1 - up 1673265af08eSRahul Lakkireddy * 1674265af08eSRahul Lakkireddy * Set the device link up or down. 1675265af08eSRahul Lakkireddy */ 1676265af08eSRahul Lakkireddy int cxgbe_set_link_status(struct port_info *pi, bool status) 1677265af08eSRahul Lakkireddy { 1678265af08eSRahul Lakkireddy struct adapter *adapter = pi->adapter; 1679265af08eSRahul Lakkireddy int err = 0; 1680265af08eSRahul Lakkireddy 1681265af08eSRahul Lakkireddy err = t4_enable_vi(adapter, adapter->mbox, pi->viid, status, status); 1682265af08eSRahul Lakkireddy if (err) { 1683265af08eSRahul Lakkireddy dev_err(adapter, "%s: disable_vi failed: %d\n", __func__, err); 1684265af08eSRahul Lakkireddy return err; 1685265af08eSRahul Lakkireddy } 1686265af08eSRahul Lakkireddy 1687265af08eSRahul Lakkireddy if (!status) 1688265af08eSRahul Lakkireddy t4_reset_link_config(adapter, pi->pidx); 1689265af08eSRahul Lakkireddy 1690265af08eSRahul Lakkireddy return 0; 1691265af08eSRahul Lakkireddy } 1692265af08eSRahul Lakkireddy 1693265af08eSRahul Lakkireddy /** 16940462d115SRahul Lakkireddy * cxgb_up - enable the adapter 16950462d115SRahul Lakkireddy * @adap: adapter being enabled 16960462d115SRahul Lakkireddy * 16970462d115SRahul Lakkireddy * Called when the first port is enabled, this function performs the 16980462d115SRahul Lakkireddy * actions necessary to make an adapter operational, such as completing 16990462d115SRahul Lakkireddy * the initialization of HW modules, and enabling interrupts. 17000462d115SRahul Lakkireddy */ 17010462d115SRahul Lakkireddy int cxgbe_up(struct adapter *adap) 17020462d115SRahul Lakkireddy { 1703d87ba24dSRahul Lakkireddy enable_rx(adap, &adap->sge.fw_evtq); 17040462d115SRahul Lakkireddy t4_sge_tx_monitor_start(adap); 17055e80364aSKumar Sanghvi if (is_pf4(adap)) 17060462d115SRahul Lakkireddy t4_intr_enable(adap); 17070462d115SRahul Lakkireddy adap->flags |= FULL_INIT_DONE; 17080462d115SRahul Lakkireddy 17090462d115SRahul Lakkireddy /* TODO: deadman watchdog ?? */ 17100462d115SRahul Lakkireddy return 0; 17110462d115SRahul Lakkireddy } 17120462d115SRahul Lakkireddy 17130462d115SRahul Lakkireddy /* 17140462d115SRahul Lakkireddy * Close the port 17150462d115SRahul Lakkireddy */ 17160462d115SRahul Lakkireddy int cxgbe_down(struct port_info *pi) 17170462d115SRahul Lakkireddy { 1718265af08eSRahul Lakkireddy return cxgbe_set_link_status(pi, false); 17190462d115SRahul Lakkireddy } 17200462d115SRahul Lakkireddy 17210462d115SRahul Lakkireddy /* 17220462d115SRahul Lakkireddy * Release resources when all the ports have been stopped. 17230462d115SRahul Lakkireddy */ 17240462d115SRahul Lakkireddy void cxgbe_close(struct adapter *adapter) 17250462d115SRahul Lakkireddy { 17260462d115SRahul Lakkireddy struct port_info *pi; 17270462d115SRahul Lakkireddy int i; 17280462d115SRahul Lakkireddy 17290462d115SRahul Lakkireddy if (adapter->flags & FULL_INIT_DONE) { 17306f2a064bSShagun Agrawal tid_free(&adapter->tids); 17316fda3f0dSShagun Agrawal t4_cleanup_mpstcam(adapter); 17323f2c1e20SShagun Agrawal t4_cleanup_clip_tbl(adapter); 173323af667fSShagun Agrawal t4_cleanup_l2t(adapter); 173423af667fSShagun Agrawal if (is_pf4(adapter)) 173523af667fSShagun Agrawal t4_intr_disable(adapter); 17360462d115SRahul Lakkireddy t4_sge_tx_monitor_stop(adapter); 17370462d115SRahul Lakkireddy t4_free_sge_resources(adapter); 17380462d115SRahul Lakkireddy for_each_port(adapter, i) { 17390462d115SRahul Lakkireddy pi = adap2pinfo(adapter, i); 17400462d115SRahul Lakkireddy if (pi->viid != 0) 17410462d115SRahul Lakkireddy t4_free_vi(adapter, adapter->mbox, 17420462d115SRahul Lakkireddy adapter->pf, 0, pi->viid); 17432195df6dSRahul Lakkireddy rte_eth_dev_release_port(pi->eth_dev); 17442195df6dSRahul Lakkireddy } 17450462d115SRahul Lakkireddy adapter->flags &= ~FULL_INIT_DONE; 17460462d115SRahul Lakkireddy } 17470462d115SRahul Lakkireddy 17485e80364aSKumar Sanghvi if (is_pf4(adapter) && (adapter->flags & FW_OK)) 17490462d115SRahul Lakkireddy t4_fw_bye(adapter, adapter->mbox); 17500462d115SRahul Lakkireddy } 17510462d115SRahul Lakkireddy 175283189849SRahul Lakkireddy int cxgbe_probe(struct adapter *adapter) 175383189849SRahul Lakkireddy { 175483189849SRahul Lakkireddy struct port_info *pi; 175504868e5bSRahul Lakkireddy int chip; 175683189849SRahul Lakkireddy int func, i; 175783189849SRahul Lakkireddy int err = 0; 175804868e5bSRahul Lakkireddy u32 whoami; 175983189849SRahul Lakkireddy 176004868e5bSRahul Lakkireddy whoami = t4_read_reg(adapter, A_PL_WHOAMI); 176104868e5bSRahul Lakkireddy chip = t4_get_chip_type(adapter, 176204868e5bSRahul Lakkireddy CHELSIO_PCI_ID_VER(adapter->pdev->id.device_id)); 176304868e5bSRahul Lakkireddy if (chip < 0) 176404868e5bSRahul Lakkireddy return chip; 176504868e5bSRahul Lakkireddy 176604868e5bSRahul Lakkireddy func = CHELSIO_CHIP_VERSION(chip) <= CHELSIO_T5 ? 176704868e5bSRahul Lakkireddy G_SOURCEPF(whoami) : G_T6_SOURCEPF(whoami); 176804868e5bSRahul Lakkireddy 176983189849SRahul Lakkireddy adapter->mbox = func; 177083189849SRahul Lakkireddy adapter->pf = func; 177183189849SRahul Lakkireddy 177283189849SRahul Lakkireddy t4_os_lock_init(&adapter->mbox_lock); 177383189849SRahul Lakkireddy TAILQ_INIT(&adapter->mbox_list); 17748d3c12e1SShagun Agrawal t4_os_lock_init(&adapter->win0_lock); 177583189849SRahul Lakkireddy 177683189849SRahul Lakkireddy err = t4_prep_adapter(adapter); 177783189849SRahul Lakkireddy if (err) 177883189849SRahul Lakkireddy return err; 177983189849SRahul Lakkireddy 178083189849SRahul Lakkireddy setup_memwin(adapter); 178183189849SRahul Lakkireddy err = adap_init0(adapter); 178283189849SRahul Lakkireddy if (err) { 178383189849SRahul Lakkireddy dev_err(adapter, "%s: Adapter initialization failed, error %d\n", 178483189849SRahul Lakkireddy __func__, err); 178583189849SRahul Lakkireddy goto out_free; 178683189849SRahul Lakkireddy } 178783189849SRahul Lakkireddy 178883189849SRahul Lakkireddy if (!is_t4(adapter->params.chip)) { 178983189849SRahul Lakkireddy /* 179083189849SRahul Lakkireddy * The userspace doorbell BAR is split evenly into doorbell 179183189849SRahul Lakkireddy * regions, each associated with an egress queue. If this 179283189849SRahul Lakkireddy * per-queue region is large enough (at least UDBS_SEG_SIZE) 179383189849SRahul Lakkireddy * then it can be used to submit a tx work request with an 179483189849SRahul Lakkireddy * implied doorbell. Enable write combining on the BAR if 179583189849SRahul Lakkireddy * there is room for such work requests. 179683189849SRahul Lakkireddy */ 179783189849SRahul Lakkireddy int s_qpp, qpp, num_seg; 179883189849SRahul Lakkireddy 179983189849SRahul Lakkireddy s_qpp = (S_QUEUESPERPAGEPF0 + 180083189849SRahul Lakkireddy (S_QUEUESPERPAGEPF1 - S_QUEUESPERPAGEPF0) * 180183189849SRahul Lakkireddy adapter->pf); 180283189849SRahul Lakkireddy qpp = 1 << ((t4_read_reg(adapter, 180383189849SRahul Lakkireddy A_SGE_EGRESS_QUEUES_PER_PAGE_PF) >> s_qpp) 180483189849SRahul Lakkireddy & M_QUEUESPERPAGEPF0); 18051f8613f1SRahul Lakkireddy num_seg = CXGBE_PAGE_SIZE / UDBS_SEG_SIZE; 180683189849SRahul Lakkireddy if (qpp > num_seg) 180783189849SRahul Lakkireddy dev_warn(adapter, "Incorrect SGE EGRESS QUEUES_PER_PAGE configuration, continuing in debug mode\n"); 180883189849SRahul Lakkireddy 180983189849SRahul Lakkireddy adapter->bar2 = (void *)adapter->pdev->mem_resource[2].addr; 181083189849SRahul Lakkireddy if (!adapter->bar2) { 181183189849SRahul Lakkireddy dev_err(adapter, "cannot map device bar2 region\n"); 181283189849SRahul Lakkireddy err = -ENOMEM; 181383189849SRahul Lakkireddy goto out_free; 181483189849SRahul Lakkireddy } 181583189849SRahul Lakkireddy t4_write_reg(adapter, A_SGE_STAT_CFG, V_STATSOURCE_T5(7) | 181683189849SRahul Lakkireddy V_STATMODE(0)); 181783189849SRahul Lakkireddy } 181883189849SRahul Lakkireddy 181983189849SRahul Lakkireddy for_each_port(adapter, i) { 182083189849SRahul Lakkireddy const unsigned int numa_node = rte_socket_id(); 18212195df6dSRahul Lakkireddy char name[RTE_ETH_NAME_MAX_LEN]; 18222195df6dSRahul Lakkireddy struct rte_eth_dev *eth_dev; 182383189849SRahul Lakkireddy 18242195df6dSRahul Lakkireddy snprintf(name, sizeof(name), "%s_%d", 18252195df6dSRahul Lakkireddy adapter->pdev->device.name, i); 182683189849SRahul Lakkireddy 182783189849SRahul Lakkireddy if (i == 0) { 182883189849SRahul Lakkireddy /* First port is already allocated by DPDK */ 18292195df6dSRahul Lakkireddy eth_dev = adapter->eth_dev; 183083189849SRahul Lakkireddy goto allocate_mac; 183183189849SRahul Lakkireddy } 183283189849SRahul Lakkireddy 183383189849SRahul Lakkireddy /* 183483189849SRahul Lakkireddy * now do all data allocation - for eth_dev structure, 183583189849SRahul Lakkireddy * and internal (private) data for the remaining ports 183683189849SRahul Lakkireddy */ 183783189849SRahul Lakkireddy 183883189849SRahul Lakkireddy /* reserve an ethdev entry */ 18392195df6dSRahul Lakkireddy eth_dev = rte_eth_dev_allocate(name); 18402195df6dSRahul Lakkireddy if (!eth_dev) 184183189849SRahul Lakkireddy goto out_free; 184283189849SRahul Lakkireddy 18432195df6dSRahul Lakkireddy eth_dev->data->dev_private = 18442195df6dSRahul Lakkireddy rte_zmalloc_socket(name, sizeof(struct port_info), 18452195df6dSRahul Lakkireddy RTE_CACHE_LINE_SIZE, numa_node); 18462195df6dSRahul Lakkireddy if (!eth_dev->data->dev_private) 184783189849SRahul Lakkireddy goto out_free; 184883189849SRahul Lakkireddy 184983189849SRahul Lakkireddy allocate_mac: 185063a97e58SStephen Hemminger pi = eth_dev->data->dev_private; 18512195df6dSRahul Lakkireddy adapter->port[i] = pi; 18522195df6dSRahul Lakkireddy pi->eth_dev = eth_dev; 18532195df6dSRahul Lakkireddy pi->adapter = adapter; 18542195df6dSRahul Lakkireddy pi->xact_addr_filt = -1; 18552195df6dSRahul Lakkireddy pi->port_id = i; 18565e80364aSKumar Sanghvi pi->pidx = i; 18572195df6dSRahul Lakkireddy 1858eac901ceSJan Blunck pi->eth_dev->device = &adapter->pdev->device; 185983189849SRahul Lakkireddy pi->eth_dev->dev_ops = adapter->eth_dev->dev_ops; 18604a01078bSRahul Lakkireddy pi->eth_dev->tx_pkt_burst = adapter->eth_dev->tx_pkt_burst; 186192c8a632SRahul Lakkireddy pi->eth_dev->rx_pkt_burst = adapter->eth_dev->rx_pkt_burst; 186213b0f500SRahul Lakkireddy 1863eac901ceSJan Blunck rte_eth_copy_pci_info(pi->eth_dev, adapter->pdev); 186413b0f500SRahul Lakkireddy 186583189849SRahul Lakkireddy pi->eth_dev->data->mac_addrs = rte_zmalloc(name, 186635b2d13fSOlivier Matz RTE_ETHER_ADDR_LEN, 0); 186783189849SRahul Lakkireddy if (!pi->eth_dev->data->mac_addrs) { 186883189849SRahul Lakkireddy dev_err(adapter, "%s: Mem allocation failed for storing mac addr, aborting\n", 186983189849SRahul Lakkireddy __func__); 187083189849SRahul Lakkireddy err = -1; 187183189849SRahul Lakkireddy goto out_free; 187283189849SRahul Lakkireddy } 1873fbe90cddSThomas Monjalon 1874fbe90cddSThomas Monjalon if (i > 0) { 1875fbe90cddSThomas Monjalon /* First port will be notified by upper layer */ 1876fbe90cddSThomas Monjalon rte_eth_dev_probing_finish(eth_dev); 1877fbe90cddSThomas Monjalon } 187883189849SRahul Lakkireddy } 187983189849SRahul Lakkireddy 188083189849SRahul Lakkireddy if (adapter->flags & FW_OK) { 188183189849SRahul Lakkireddy err = t4_port_init(adapter, adapter->mbox, adapter->pf, 0); 188283189849SRahul Lakkireddy if (err) { 188383189849SRahul Lakkireddy dev_err(adapter, "%s: t4_port_init failed with err %d\n", 188483189849SRahul Lakkireddy __func__, err); 188583189849SRahul Lakkireddy goto out_free; 188683189849SRahul Lakkireddy } 188783189849SRahul Lakkireddy } 188883189849SRahul Lakkireddy 1889b7fd9ea8SStephen Hemminger cxgbe_cfg_queues(adapter->eth_dev); 189092c8a632SRahul Lakkireddy 1891b7fd9ea8SStephen Hemminger cxgbe_print_adapter_info(adapter); 1892b7fd9ea8SStephen Hemminger cxgbe_print_port_info(adapter); 189383189849SRahul Lakkireddy 18943f2c1e20SShagun Agrawal adapter->clipt = t4_init_clip_tbl(adapter->clipt_start, 18953f2c1e20SShagun Agrawal adapter->clipt_end); 18963f2c1e20SShagun Agrawal if (!adapter->clipt) { 18973f2c1e20SShagun Agrawal /* We tolerate a lack of clip_table, giving up some 18983f2c1e20SShagun Agrawal * functionality 18993f2c1e20SShagun Agrawal */ 19003f2c1e20SShagun Agrawal dev_warn(adapter, "could not allocate CLIP. Continuing\n"); 19013f2c1e20SShagun Agrawal } 19023f2c1e20SShagun Agrawal 190323af667fSShagun Agrawal adapter->l2t = t4_init_l2t(adapter->l2t_start, adapter->l2t_end); 190423af667fSShagun Agrawal if (!adapter->l2t) { 190523af667fSShagun Agrawal /* We tolerate a lack of L2T, giving up some functionality */ 190623af667fSShagun Agrawal dev_warn(adapter, "could not allocate L2T. Continuing\n"); 190723af667fSShagun Agrawal } 190823af667fSShagun Agrawal 19096f2a064bSShagun Agrawal if (tid_init(&adapter->tids) < 0) { 19106f2a064bSShagun Agrawal /* Disable filtering support */ 19116f2a064bSShagun Agrawal dev_warn(adapter, "could not allocate TID table, " 19126f2a064bSShagun Agrawal "filter support disabled. Continuing\n"); 19136f2a064bSShagun Agrawal } 19146f2a064bSShagun Agrawal 19156fda3f0dSShagun Agrawal adapter->mpstcam = t4_init_mpstcam(adapter); 19166fda3f0dSShagun Agrawal if (!adapter->mpstcam) 19176fda3f0dSShagun Agrawal dev_warn(adapter, "could not allocate mps tcam table." 19186fda3f0dSShagun Agrawal " Continuing\n"); 19196fda3f0dSShagun Agrawal 19203a381a41SShagun Agrawal if (is_hashfilter(adapter)) { 19213a381a41SShagun Agrawal if (t4_read_reg(adapter, A_LE_DB_CONFIG) & F_HASHEN) { 19223a381a41SShagun Agrawal u32 hash_base, hash_reg; 19233a381a41SShagun Agrawal 19243a381a41SShagun Agrawal hash_reg = A_LE_DB_TID_HASHBASE; 19253a381a41SShagun Agrawal hash_base = t4_read_reg(adapter, hash_reg); 19263a381a41SShagun Agrawal adapter->tids.hash_base = hash_base / 4; 19273a381a41SShagun Agrawal } 19283a381a41SShagun Agrawal } else { 19293a381a41SShagun Agrawal /* Disable hash filtering support */ 19303a381a41SShagun Agrawal dev_warn(adapter, 19313a381a41SShagun Agrawal "Maskless filter support disabled. Continuing\n"); 19323a381a41SShagun Agrawal } 19333a381a41SShagun Agrawal 1934b7fd9ea8SStephen Hemminger err = cxgbe_init_rss(adapter); 193592c8a632SRahul Lakkireddy if (err) 193692c8a632SRahul Lakkireddy goto out_free; 193792c8a632SRahul Lakkireddy 193883189849SRahul Lakkireddy return 0; 193983189849SRahul Lakkireddy 194083189849SRahul Lakkireddy out_free: 194183189849SRahul Lakkireddy for_each_port(adapter, i) { 194283189849SRahul Lakkireddy pi = adap2pinfo(adapter, i); 194383189849SRahul Lakkireddy if (pi->viid != 0) 194483189849SRahul Lakkireddy t4_free_vi(adapter, adapter->mbox, adapter->pf, 194583189849SRahul Lakkireddy 0, pi->viid); 19462195df6dSRahul Lakkireddy rte_eth_dev_release_port(pi->eth_dev); 19472195df6dSRahul Lakkireddy } 194883189849SRahul Lakkireddy 194983189849SRahul Lakkireddy if (adapter->flags & FW_OK) 195083189849SRahul Lakkireddy t4_fw_bye(adapter, adapter->mbox); 195183189849SRahul Lakkireddy return -err; 195283189849SRahul Lakkireddy } 1953