12aa5c722SRahul Lakkireddy /* SPDX-License-Identifier: BSD-3-Clause 22aa5c722SRahul Lakkireddy * Copyright(c) 2014-2018 Chelsio Communications. 383189849SRahul Lakkireddy * All rights reserved. 483189849SRahul Lakkireddy */ 583189849SRahul Lakkireddy 683189849SRahul Lakkireddy #include <sys/queue.h> 783189849SRahul Lakkireddy #include <stdio.h> 883189849SRahul Lakkireddy #include <errno.h> 983189849SRahul Lakkireddy #include <stdint.h> 1083189849SRahul Lakkireddy #include <string.h> 1183189849SRahul Lakkireddy #include <unistd.h> 1283189849SRahul Lakkireddy #include <stdarg.h> 1383189849SRahul Lakkireddy #include <inttypes.h> 1483189849SRahul Lakkireddy #include <netinet/in.h> 1583189849SRahul Lakkireddy 1683189849SRahul Lakkireddy #include <rte_byteorder.h> 1783189849SRahul Lakkireddy #include <rte_common.h> 1883189849SRahul Lakkireddy #include <rte_cycles.h> 1983189849SRahul Lakkireddy #include <rte_interrupts.h> 2083189849SRahul Lakkireddy #include <rte_log.h> 2183189849SRahul Lakkireddy #include <rte_debug.h> 2283189849SRahul Lakkireddy #include <rte_pci.h> 2383189849SRahul Lakkireddy #include <rte_atomic.h> 2483189849SRahul Lakkireddy #include <rte_branch_prediction.h> 2583189849SRahul Lakkireddy #include <rte_memory.h> 2683189849SRahul Lakkireddy #include <rte_tailq.h> 2783189849SRahul Lakkireddy #include <rte_eal.h> 2883189849SRahul Lakkireddy #include <rte_alarm.h> 2983189849SRahul Lakkireddy #include <rte_ether.h> 30ffc905f3SFerruh Yigit #include <rte_ethdev_driver.h> 317d012402SJan Blunck #include <rte_ethdev_pci.h> 3283189849SRahul Lakkireddy #include <rte_random.h> 3383189849SRahul Lakkireddy #include <rte_dev.h> 34cda260a4SShagun Agrawal #include <rte_kvargs.h> 3583189849SRahul Lakkireddy 3689c8bd95SRahul Lakkireddy #include "base/common.h" 3789c8bd95SRahul Lakkireddy #include "base/t4_regs.h" 3889c8bd95SRahul Lakkireddy #include "base/t4_msg.h" 3983189849SRahul Lakkireddy #include "cxgbe.h" 403f2c1e20SShagun Agrawal #include "clip_tbl.h" 4123af667fSShagun Agrawal #include "l2t.h" 426fda3f0dSShagun Agrawal #include "mps_tcam.h" 4383189849SRahul Lakkireddy 446f2a064bSShagun Agrawal /** 456f2a064bSShagun Agrawal * Allocate a chunk of memory. The allocated memory is cleared. 466f2a064bSShagun Agrawal */ 476f2a064bSShagun Agrawal void *t4_alloc_mem(size_t size) 486f2a064bSShagun Agrawal { 496f2a064bSShagun Agrawal return rte_zmalloc(NULL, size, 0); 506f2a064bSShagun Agrawal } 516f2a064bSShagun Agrawal 526f2a064bSShagun Agrawal /** 536f2a064bSShagun Agrawal * Free memory allocated through t4_alloc_mem(). 546f2a064bSShagun Agrawal */ 556f2a064bSShagun Agrawal void t4_free_mem(void *addr) 566f2a064bSShagun Agrawal { 576f2a064bSShagun Agrawal rte_free(addr); 586f2a064bSShagun Agrawal } 596f2a064bSShagun Agrawal 6092c8a632SRahul Lakkireddy /* 6192c8a632SRahul Lakkireddy * Response queue handler for the FW event queue. 6292c8a632SRahul Lakkireddy */ 6392c8a632SRahul Lakkireddy static int fwevtq_handler(struct sge_rspq *q, const __be64 *rsp, 6492c8a632SRahul Lakkireddy __rte_unused const struct pkt_gl *gl) 6592c8a632SRahul Lakkireddy { 6692c8a632SRahul Lakkireddy u8 opcode = ((const struct rss_header *)rsp)->opcode; 6792c8a632SRahul Lakkireddy 6892c8a632SRahul Lakkireddy rsp++; /* skip RSS header */ 6992c8a632SRahul Lakkireddy 7092c8a632SRahul Lakkireddy /* 7192c8a632SRahul Lakkireddy * FW can send EGR_UPDATEs encapsulated in a CPL_FW4_MSG. 7292c8a632SRahul Lakkireddy */ 7392c8a632SRahul Lakkireddy if (unlikely(opcode == CPL_FW4_MSG && 7492c8a632SRahul Lakkireddy ((const struct cpl_fw4_msg *)rsp)->type == 7592c8a632SRahul Lakkireddy FW_TYPE_RSSCPL)) { 7692c8a632SRahul Lakkireddy rsp++; 7792c8a632SRahul Lakkireddy opcode = ((const struct rss_header *)rsp)->opcode; 7892c8a632SRahul Lakkireddy rsp++; 7992c8a632SRahul Lakkireddy if (opcode != CPL_SGE_EGR_UPDATE) { 8092c8a632SRahul Lakkireddy dev_err(q->adapter, "unexpected FW4/CPL %#x on FW event queue\n", 8192c8a632SRahul Lakkireddy opcode); 8292c8a632SRahul Lakkireddy goto out; 8392c8a632SRahul Lakkireddy } 8492c8a632SRahul Lakkireddy } 8592c8a632SRahul Lakkireddy 8692c8a632SRahul Lakkireddy if (likely(opcode == CPL_SGE_EGR_UPDATE)) { 8792c8a632SRahul Lakkireddy /* do nothing */ 8892c8a632SRahul Lakkireddy } else if (opcode == CPL_FW6_MSG || opcode == CPL_FW4_MSG) { 8992c8a632SRahul Lakkireddy const struct cpl_fw6_msg *msg = (const void *)rsp; 9092c8a632SRahul Lakkireddy 9192c8a632SRahul Lakkireddy t4_handle_fw_rpl(q->adapter, msg->data); 9241dc98b0SShagun Agrawal } else if (opcode == CPL_ABORT_RPL_RSS) { 9341dc98b0SShagun Agrawal const struct cpl_abort_rpl_rss *p = (const void *)rsp; 9441dc98b0SShagun Agrawal 9571e9b334SRahul Lakkireddy cxgbe_hash_del_filter_rpl(q->adapter, p); 969eb2c9a4SShagun Agrawal } else if (opcode == CPL_SET_TCB_RPL) { 979eb2c9a4SShagun Agrawal const struct cpl_set_tcb_rpl *p = (const void *)rsp; 989eb2c9a4SShagun Agrawal 9971e9b334SRahul Lakkireddy cxgbe_filter_rpl(q->adapter, p); 100af44a577SShagun Agrawal } else if (opcode == CPL_ACT_OPEN_RPL) { 101af44a577SShagun Agrawal const struct cpl_act_open_rpl *p = (const void *)rsp; 102af44a577SShagun Agrawal 10371e9b334SRahul Lakkireddy cxgbe_hash_filter_rpl(q->adapter, p); 10423af667fSShagun Agrawal } else if (opcode == CPL_L2T_WRITE_RPL) { 10523af667fSShagun Agrawal const struct cpl_l2t_write_rpl *p = (const void *)rsp; 10623af667fSShagun Agrawal 10771e9b334SRahul Lakkireddy cxgbe_do_l2t_write_rpl(q->adapter, p); 10892c8a632SRahul Lakkireddy } else { 10992c8a632SRahul Lakkireddy dev_err(adapter, "unexpected CPL %#x on FW event queue\n", 11092c8a632SRahul Lakkireddy opcode); 11192c8a632SRahul Lakkireddy } 11292c8a632SRahul Lakkireddy out: 11392c8a632SRahul Lakkireddy return 0; 11492c8a632SRahul Lakkireddy } 11592c8a632SRahul Lakkireddy 1163a3aaabcSShagun Agrawal /** 1173a3aaabcSShagun Agrawal * Setup sge control queues to pass control information. 1183a3aaabcSShagun Agrawal */ 119b7fd9ea8SStephen Hemminger int cxgbe_setup_sge_ctrl_txq(struct adapter *adapter) 1203a3aaabcSShagun Agrawal { 1213a3aaabcSShagun Agrawal struct sge *s = &adapter->sge; 1223a3aaabcSShagun Agrawal int err = 0, i = 0; 1233a3aaabcSShagun Agrawal 1243a3aaabcSShagun Agrawal for_each_port(adapter, i) { 12546df488bSRahul Lakkireddy struct port_info *pi = adap2pinfo(adapter, i); 1263a3aaabcSShagun Agrawal char name[RTE_ETH_NAME_MAX_LEN]; 1273a3aaabcSShagun Agrawal struct sge_ctrl_txq *q = &s->ctrlq[i]; 1283a3aaabcSShagun Agrawal 1293a3aaabcSShagun Agrawal q->q.size = 1024; 1303a3aaabcSShagun Agrawal err = t4_sge_alloc_ctrl_txq(adapter, q, 1313a3aaabcSShagun Agrawal adapter->eth_dev, i, 1323a3aaabcSShagun Agrawal s->fw_evtq.cntxt_id, 1333a3aaabcSShagun Agrawal rte_socket_id()); 1343a3aaabcSShagun Agrawal if (err) { 1353a3aaabcSShagun Agrawal dev_err(adapter, "Failed to alloc ctrl txq. Err: %d", 1363a3aaabcSShagun Agrawal err); 1373a3aaabcSShagun Agrawal goto out; 1383a3aaabcSShagun Agrawal } 13946df488bSRahul Lakkireddy snprintf(name, sizeof(name), "%s_ctrl_pool_%d", 14046df488bSRahul Lakkireddy pi->eth_dev->device->driver->name, 14146df488bSRahul Lakkireddy pi->eth_dev->data->port_id); 1423a3aaabcSShagun Agrawal q->mb_pool = rte_pktmbuf_pool_create(name, s->ctrlq[i].q.size, 1433a3aaabcSShagun Agrawal RTE_CACHE_LINE_SIZE, 1443a3aaabcSShagun Agrawal RTE_MBUF_PRIV_ALIGN, 1453a3aaabcSShagun Agrawal RTE_MBUF_DEFAULT_BUF_SIZE, 1463a3aaabcSShagun Agrawal SOCKET_ID_ANY); 1473a3aaabcSShagun Agrawal if (!q->mb_pool) { 14846df488bSRahul Lakkireddy err = -rte_errno; 14946df488bSRahul Lakkireddy dev_err(adapter, 15046df488bSRahul Lakkireddy "Can't create ctrl pool for port %d. Err: %d\n", 15146df488bSRahul Lakkireddy pi->eth_dev->data->port_id, err); 1523a3aaabcSShagun Agrawal goto out; 1533a3aaabcSShagun Agrawal } 1543a3aaabcSShagun Agrawal } 1553a3aaabcSShagun Agrawal return 0; 1563a3aaabcSShagun Agrawal out: 1573a3aaabcSShagun Agrawal t4_free_sge_resources(adapter); 1583a3aaabcSShagun Agrawal return err; 1593a3aaabcSShagun Agrawal } 1603a3aaabcSShagun Agrawal 1619eb2c9a4SShagun Agrawal /** 1629eb2c9a4SShagun Agrawal * cxgbe_poll_for_completion: Poll rxq for completion 1639eb2c9a4SShagun Agrawal * @q: rxq to poll 164f1e9d2afSRahul Lakkireddy * @ms: milliseconds to delay 1659eb2c9a4SShagun Agrawal * @cnt: number of times to poll 1669eb2c9a4SShagun Agrawal * @c: completion to check for 'done' status 1679eb2c9a4SShagun Agrawal * 1689eb2c9a4SShagun Agrawal * Polls the rxq for reples until completion is done or the count 1699eb2c9a4SShagun Agrawal * expires. 1709eb2c9a4SShagun Agrawal */ 171f1e9d2afSRahul Lakkireddy int cxgbe_poll_for_completion(struct sge_rspq *q, unsigned int ms, 1729eb2c9a4SShagun Agrawal unsigned int cnt, struct t4_completion *c) 1739eb2c9a4SShagun Agrawal { 1749eb2c9a4SShagun Agrawal unsigned int i; 175f1e9d2afSRahul Lakkireddy unsigned int work_done, budget = 32; 1769eb2c9a4SShagun Agrawal 1779eb2c9a4SShagun Agrawal if (!c) 1789eb2c9a4SShagun Agrawal return -EINVAL; 1799eb2c9a4SShagun Agrawal 1809eb2c9a4SShagun Agrawal for (i = 0; i < cnt; i++) { 1819eb2c9a4SShagun Agrawal cxgbe_poll(q, NULL, budget, &work_done); 1829eb2c9a4SShagun Agrawal t4_os_lock(&c->lock); 1839eb2c9a4SShagun Agrawal if (c->done) { 1849eb2c9a4SShagun Agrawal t4_os_unlock(&c->lock); 1859eb2c9a4SShagun Agrawal return 0; 1869eb2c9a4SShagun Agrawal } 1879eb2c9a4SShagun Agrawal t4_os_unlock(&c->lock); 188f1e9d2afSRahul Lakkireddy rte_delay_ms(ms); 1899eb2c9a4SShagun Agrawal } 1909eb2c9a4SShagun Agrawal return -ETIMEDOUT; 1919eb2c9a4SShagun Agrawal } 1929eb2c9a4SShagun Agrawal 193b7fd9ea8SStephen Hemminger int cxgbe_setup_sge_fwevtq(struct adapter *adapter) 19492c8a632SRahul Lakkireddy { 19592c8a632SRahul Lakkireddy struct sge *s = &adapter->sge; 19692c8a632SRahul Lakkireddy int err = 0; 19792c8a632SRahul Lakkireddy int msi_idx = 0; 19892c8a632SRahul Lakkireddy 19992c8a632SRahul Lakkireddy err = t4_sge_alloc_rxq(adapter, &s->fw_evtq, true, adapter->eth_dev, 20092c8a632SRahul Lakkireddy msi_idx, NULL, fwevtq_handler, -1, NULL, 0, 20192c8a632SRahul Lakkireddy rte_socket_id()); 20292c8a632SRahul Lakkireddy return err; 20392c8a632SRahul Lakkireddy } 20492c8a632SRahul Lakkireddy 20592c8a632SRahul Lakkireddy static int closest_timer(const struct sge *s, int time) 20692c8a632SRahul Lakkireddy { 20792c8a632SRahul Lakkireddy unsigned int i, match = 0; 20892c8a632SRahul Lakkireddy int delta, min_delta = INT_MAX; 20992c8a632SRahul Lakkireddy 21092c8a632SRahul Lakkireddy for (i = 0; i < ARRAY_SIZE(s->timer_val); i++) { 21192c8a632SRahul Lakkireddy delta = time - s->timer_val[i]; 21292c8a632SRahul Lakkireddy if (delta < 0) 21392c8a632SRahul Lakkireddy delta = -delta; 21492c8a632SRahul Lakkireddy if (delta < min_delta) { 21592c8a632SRahul Lakkireddy min_delta = delta; 21692c8a632SRahul Lakkireddy match = i; 21792c8a632SRahul Lakkireddy } 21892c8a632SRahul Lakkireddy } 21992c8a632SRahul Lakkireddy return match; 22092c8a632SRahul Lakkireddy } 22192c8a632SRahul Lakkireddy 22292c8a632SRahul Lakkireddy static int closest_thres(const struct sge *s, int thres) 22392c8a632SRahul Lakkireddy { 22492c8a632SRahul Lakkireddy unsigned int i, match = 0; 22592c8a632SRahul Lakkireddy int delta, min_delta = INT_MAX; 22692c8a632SRahul Lakkireddy 22792c8a632SRahul Lakkireddy for (i = 0; i < ARRAY_SIZE(s->counter_val); i++) { 22892c8a632SRahul Lakkireddy delta = thres - s->counter_val[i]; 22992c8a632SRahul Lakkireddy if (delta < 0) 23092c8a632SRahul Lakkireddy delta = -delta; 23192c8a632SRahul Lakkireddy if (delta < min_delta) { 23292c8a632SRahul Lakkireddy min_delta = delta; 23392c8a632SRahul Lakkireddy match = i; 23492c8a632SRahul Lakkireddy } 23592c8a632SRahul Lakkireddy } 23692c8a632SRahul Lakkireddy return match; 23792c8a632SRahul Lakkireddy } 23892c8a632SRahul Lakkireddy 23992c8a632SRahul Lakkireddy /** 24092c8a632SRahul Lakkireddy * cxgb4_set_rspq_intr_params - set a queue's interrupt holdoff parameters 24192c8a632SRahul Lakkireddy * @q: the Rx queue 24292c8a632SRahul Lakkireddy * @us: the hold-off time in us, or 0 to disable timer 24392c8a632SRahul Lakkireddy * @cnt: the hold-off packet count, or 0 to disable counter 24492c8a632SRahul Lakkireddy * 24592c8a632SRahul Lakkireddy * Sets an Rx queue's interrupt hold-off time and packet count. At least 24692c8a632SRahul Lakkireddy * one of the two needs to be enabled for the queue to generate interrupts. 24792c8a632SRahul Lakkireddy */ 24892c8a632SRahul Lakkireddy int cxgb4_set_rspq_intr_params(struct sge_rspq *q, unsigned int us, 24992c8a632SRahul Lakkireddy unsigned int cnt) 25092c8a632SRahul Lakkireddy { 25192c8a632SRahul Lakkireddy struct adapter *adap = q->adapter; 25292c8a632SRahul Lakkireddy unsigned int timer_val; 25392c8a632SRahul Lakkireddy 25492c8a632SRahul Lakkireddy if (cnt) { 25592c8a632SRahul Lakkireddy int err; 25692c8a632SRahul Lakkireddy u32 v, new_idx; 25792c8a632SRahul Lakkireddy 25892c8a632SRahul Lakkireddy new_idx = closest_thres(&adap->sge, cnt); 25992c8a632SRahul Lakkireddy if (q->desc && q->pktcnt_idx != new_idx) { 26092c8a632SRahul Lakkireddy /* the queue has already been created, update it */ 26192c8a632SRahul Lakkireddy v = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DMAQ) | 26292c8a632SRahul Lakkireddy V_FW_PARAMS_PARAM_X( 26392c8a632SRahul Lakkireddy FW_PARAMS_PARAM_DMAQ_IQ_INTCNTTHRESH) | 26492c8a632SRahul Lakkireddy V_FW_PARAMS_PARAM_YZ(q->cntxt_id); 26592c8a632SRahul Lakkireddy err = t4_set_params(adap, adap->mbox, adap->pf, 0, 1, 26692c8a632SRahul Lakkireddy &v, &new_idx); 26792c8a632SRahul Lakkireddy if (err) 26892c8a632SRahul Lakkireddy return err; 26992c8a632SRahul Lakkireddy } 27092c8a632SRahul Lakkireddy q->pktcnt_idx = new_idx; 27192c8a632SRahul Lakkireddy } 27292c8a632SRahul Lakkireddy 27392c8a632SRahul Lakkireddy timer_val = (us == 0) ? X_TIMERREG_RESTART_COUNTER : 27492c8a632SRahul Lakkireddy closest_timer(&adap->sge, us); 27592c8a632SRahul Lakkireddy 27692c8a632SRahul Lakkireddy if ((us | cnt) == 0) 27792c8a632SRahul Lakkireddy q->intr_params = V_QINTR_TIMER_IDX(X_TIMERREG_UPDATE_CIDX); 27892c8a632SRahul Lakkireddy else 27992c8a632SRahul Lakkireddy q->intr_params = V_QINTR_TIMER_IDX(timer_val) | 28092c8a632SRahul Lakkireddy V_QINTR_CNT_EN(cnt > 0); 28192c8a632SRahul Lakkireddy return 0; 28292c8a632SRahul Lakkireddy } 28392c8a632SRahul Lakkireddy 2846f2a064bSShagun Agrawal /** 285af44a577SShagun Agrawal * Allocate an active-open TID and set it to the supplied value. 286af44a577SShagun Agrawal */ 287af44a577SShagun Agrawal int cxgbe_alloc_atid(struct tid_info *t, void *data) 288af44a577SShagun Agrawal { 289af44a577SShagun Agrawal int atid = -1; 290af44a577SShagun Agrawal 291af44a577SShagun Agrawal t4_os_lock(&t->atid_lock); 292af44a577SShagun Agrawal if (t->afree) { 293af44a577SShagun Agrawal union aopen_entry *p = t->afree; 294af44a577SShagun Agrawal 295af44a577SShagun Agrawal atid = p - t->atid_tab; 296af44a577SShagun Agrawal t->afree = p->next; 297af44a577SShagun Agrawal p->data = data; 298af44a577SShagun Agrawal t->atids_in_use++; 299af44a577SShagun Agrawal } 300af44a577SShagun Agrawal t4_os_unlock(&t->atid_lock); 301af44a577SShagun Agrawal return atid; 302af44a577SShagun Agrawal } 303af44a577SShagun Agrawal 304af44a577SShagun Agrawal /** 305af44a577SShagun Agrawal * Release an active-open TID. 306af44a577SShagun Agrawal */ 307af44a577SShagun Agrawal void cxgbe_free_atid(struct tid_info *t, unsigned int atid) 308af44a577SShagun Agrawal { 309af44a577SShagun Agrawal union aopen_entry *p = &t->atid_tab[atid]; 310af44a577SShagun Agrawal 311af44a577SShagun Agrawal t4_os_lock(&t->atid_lock); 312af44a577SShagun Agrawal p->next = t->afree; 313af44a577SShagun Agrawal t->afree = p; 314af44a577SShagun Agrawal t->atids_in_use--; 315af44a577SShagun Agrawal t4_os_unlock(&t->atid_lock); 316af44a577SShagun Agrawal } 317af44a577SShagun Agrawal 318af44a577SShagun Agrawal /** 31941dc98b0SShagun Agrawal * Populate a TID_RELEASE WR. Caller must properly size the skb. 32041dc98b0SShagun Agrawal */ 32141dc98b0SShagun Agrawal static void mk_tid_release(struct rte_mbuf *mbuf, unsigned int tid) 32241dc98b0SShagun Agrawal { 32341dc98b0SShagun Agrawal struct cpl_tid_release *req; 32441dc98b0SShagun Agrawal 32541dc98b0SShagun Agrawal req = rte_pktmbuf_mtod(mbuf, struct cpl_tid_release *); 32641dc98b0SShagun Agrawal INIT_TP_WR_MIT_CPL(req, CPL_TID_RELEASE, tid); 32741dc98b0SShagun Agrawal } 32841dc98b0SShagun Agrawal 32941dc98b0SShagun Agrawal /** 33041dc98b0SShagun Agrawal * Release a TID and inform HW. If we are unable to allocate the release 33141dc98b0SShagun Agrawal * message we defer to a work queue. 33241dc98b0SShagun Agrawal */ 33341dc98b0SShagun Agrawal void cxgbe_remove_tid(struct tid_info *t, unsigned int chan, unsigned int tid, 33441dc98b0SShagun Agrawal unsigned short family) 33541dc98b0SShagun Agrawal { 33641dc98b0SShagun Agrawal struct rte_mbuf *mbuf; 33741dc98b0SShagun Agrawal struct adapter *adap = container_of(t, struct adapter, tids); 33841dc98b0SShagun Agrawal 33941dc98b0SShagun Agrawal WARN_ON(tid >= t->ntids); 34041dc98b0SShagun Agrawal 34141dc98b0SShagun Agrawal if (t->tid_tab[tid]) { 34241dc98b0SShagun Agrawal t->tid_tab[tid] = NULL; 34341dc98b0SShagun Agrawal rte_atomic32_dec(&t->conns_in_use); 34441dc98b0SShagun Agrawal if (t->hash_base && tid >= t->hash_base) { 34541dc98b0SShagun Agrawal if (family == FILTER_TYPE_IPV4) 34641dc98b0SShagun Agrawal rte_atomic32_dec(&t->hash_tids_in_use); 34741dc98b0SShagun Agrawal } else { 34841dc98b0SShagun Agrawal if (family == FILTER_TYPE_IPV4) 34941dc98b0SShagun Agrawal rte_atomic32_dec(&t->tids_in_use); 35041dc98b0SShagun Agrawal } 35141dc98b0SShagun Agrawal } 35241dc98b0SShagun Agrawal 35341dc98b0SShagun Agrawal mbuf = rte_pktmbuf_alloc((&adap->sge.ctrlq[chan])->mb_pool); 35441dc98b0SShagun Agrawal if (mbuf) { 35541dc98b0SShagun Agrawal mbuf->data_len = sizeof(struct cpl_tid_release); 35641dc98b0SShagun Agrawal mbuf->pkt_len = mbuf->data_len; 35741dc98b0SShagun Agrawal mk_tid_release(mbuf, tid); 35841dc98b0SShagun Agrawal t4_mgmt_tx(&adap->sge.ctrlq[chan], mbuf); 35941dc98b0SShagun Agrawal } 36041dc98b0SShagun Agrawal } 36141dc98b0SShagun Agrawal 36241dc98b0SShagun Agrawal /** 363af44a577SShagun Agrawal * Insert a TID. 364af44a577SShagun Agrawal */ 365af44a577SShagun Agrawal void cxgbe_insert_tid(struct tid_info *t, void *data, unsigned int tid, 366af44a577SShagun Agrawal unsigned short family) 367af44a577SShagun Agrawal { 368af44a577SShagun Agrawal t->tid_tab[tid] = data; 369af44a577SShagun Agrawal if (t->hash_base && tid >= t->hash_base) { 370af44a577SShagun Agrawal if (family == FILTER_TYPE_IPV4) 371af44a577SShagun Agrawal rte_atomic32_inc(&t->hash_tids_in_use); 372af44a577SShagun Agrawal } else { 373af44a577SShagun Agrawal if (family == FILTER_TYPE_IPV4) 374af44a577SShagun Agrawal rte_atomic32_inc(&t->tids_in_use); 375af44a577SShagun Agrawal } 376af44a577SShagun Agrawal 377af44a577SShagun Agrawal rte_atomic32_inc(&t->conns_in_use); 378af44a577SShagun Agrawal } 379af44a577SShagun Agrawal 380af44a577SShagun Agrawal /** 3816f2a064bSShagun Agrawal * Free TID tables. 3826f2a064bSShagun Agrawal */ 3836f2a064bSShagun Agrawal static void tid_free(struct tid_info *t) 3846f2a064bSShagun Agrawal { 3856f2a064bSShagun Agrawal if (t->tid_tab) { 3866f2a064bSShagun Agrawal if (t->ftid_bmap) 3876f2a064bSShagun Agrawal rte_bitmap_free(t->ftid_bmap); 3886f2a064bSShagun Agrawal 3896f2a064bSShagun Agrawal if (t->ftid_bmap_array) 3906f2a064bSShagun Agrawal t4_os_free(t->ftid_bmap_array); 3916f2a064bSShagun Agrawal 3926f2a064bSShagun Agrawal t4_os_free(t->tid_tab); 3936f2a064bSShagun Agrawal } 3946f2a064bSShagun Agrawal 3956f2a064bSShagun Agrawal memset(t, 0, sizeof(struct tid_info)); 3966f2a064bSShagun Agrawal } 3976f2a064bSShagun Agrawal 3986f2a064bSShagun Agrawal /** 3996f2a064bSShagun Agrawal * Allocate and initialize the TID tables. Returns 0 on success. 4006f2a064bSShagun Agrawal */ 4016f2a064bSShagun Agrawal static int tid_init(struct tid_info *t) 4026f2a064bSShagun Agrawal { 4036f2a064bSShagun Agrawal size_t size; 4046f2a064bSShagun Agrawal unsigned int ftid_bmap_size; 4053a381a41SShagun Agrawal unsigned int natids = t->natids; 4066f2a064bSShagun Agrawal unsigned int max_ftids = t->nftids; 4076f2a064bSShagun Agrawal 4086f2a064bSShagun Agrawal ftid_bmap_size = rte_bitmap_get_memory_footprint(t->nftids); 4096f2a064bSShagun Agrawal size = t->ntids * sizeof(*t->tid_tab) + 4103a381a41SShagun Agrawal max_ftids * sizeof(*t->ftid_tab) + 4113a381a41SShagun Agrawal natids * sizeof(*t->atid_tab); 4126f2a064bSShagun Agrawal 4136f2a064bSShagun Agrawal t->tid_tab = t4_os_alloc(size); 4146f2a064bSShagun Agrawal if (!t->tid_tab) 4156f2a064bSShagun Agrawal return -ENOMEM; 4166f2a064bSShagun Agrawal 4173a381a41SShagun Agrawal t->atid_tab = (union aopen_entry *)&t->tid_tab[t->ntids]; 41827288219SRahul Lakkireddy t->ftid_tab = (struct filter_entry *)&t->atid_tab[t->natids]; 4196f2a064bSShagun Agrawal t->ftid_bmap_array = t4_os_alloc(ftid_bmap_size); 4206f2a064bSShagun Agrawal if (!t->ftid_bmap_array) { 4216f2a064bSShagun Agrawal tid_free(t); 4226f2a064bSShagun Agrawal return -ENOMEM; 4236f2a064bSShagun Agrawal } 4246f2a064bSShagun Agrawal 4253a381a41SShagun Agrawal t4_os_lock_init(&t->atid_lock); 4266f2a064bSShagun Agrawal t4_os_lock_init(&t->ftid_lock); 4273a381a41SShagun Agrawal 4283a381a41SShagun Agrawal t->afree = NULL; 4293a381a41SShagun Agrawal t->atids_in_use = 0; 4303a381a41SShagun Agrawal rte_atomic32_init(&t->tids_in_use); 4313a381a41SShagun Agrawal rte_atomic32_set(&t->tids_in_use, 0); 4323a381a41SShagun Agrawal rte_atomic32_init(&t->conns_in_use); 4333a381a41SShagun Agrawal rte_atomic32_set(&t->conns_in_use, 0); 4343a381a41SShagun Agrawal 4353a381a41SShagun Agrawal /* Setup the free list for atid_tab and clear the stid bitmap. */ 4363a381a41SShagun Agrawal if (natids) { 4373a381a41SShagun Agrawal while (--natids) 4383a381a41SShagun Agrawal t->atid_tab[natids - 1].next = &t->atid_tab[natids]; 4393a381a41SShagun Agrawal t->afree = t->atid_tab; 4403a381a41SShagun Agrawal } 4413a381a41SShagun Agrawal 4426f2a064bSShagun Agrawal t->ftid_bmap = rte_bitmap_init(t->nftids, t->ftid_bmap_array, 4436f2a064bSShagun Agrawal ftid_bmap_size); 4446f2a064bSShagun Agrawal if (!t->ftid_bmap) { 4456f2a064bSShagun Agrawal tid_free(t); 4466f2a064bSShagun Agrawal return -ENOMEM; 4476f2a064bSShagun Agrawal } 4486f2a064bSShagun Agrawal 4496f2a064bSShagun Agrawal return 0; 4506f2a064bSShagun Agrawal } 4516f2a064bSShagun Agrawal 45292c8a632SRahul Lakkireddy static inline bool is_x_1g_port(const struct link_config *lc) 45392c8a632SRahul Lakkireddy { 45476488837SRahul Lakkireddy return (lc->pcaps & FW_PORT_CAP32_SPEED_1G) != 0; 45592c8a632SRahul Lakkireddy } 45692c8a632SRahul Lakkireddy 45792c8a632SRahul Lakkireddy static inline bool is_x_10g_port(const struct link_config *lc) 45892c8a632SRahul Lakkireddy { 4599da2a694SRahul Lakkireddy unsigned int speeds, high_speeds; 4609da2a694SRahul Lakkireddy 46176488837SRahul Lakkireddy speeds = V_FW_PORT_CAP32_SPEED(G_FW_PORT_CAP32_SPEED(lc->pcaps)); 46276488837SRahul Lakkireddy high_speeds = speeds & 46376488837SRahul Lakkireddy ~(FW_PORT_CAP32_SPEED_100M | FW_PORT_CAP32_SPEED_1G); 4649da2a694SRahul Lakkireddy 4659da2a694SRahul Lakkireddy return high_speeds != 0; 46692c8a632SRahul Lakkireddy } 46792c8a632SRahul Lakkireddy 468b7fd9ea8SStephen Hemminger static inline void init_rspq(struct adapter *adap, struct sge_rspq *q, 46992c8a632SRahul Lakkireddy unsigned int us, unsigned int cnt, 47092c8a632SRahul Lakkireddy unsigned int size, unsigned int iqe_size) 47192c8a632SRahul Lakkireddy { 47292c8a632SRahul Lakkireddy q->adapter = adap; 47392c8a632SRahul Lakkireddy cxgb4_set_rspq_intr_params(q, us, cnt); 47492c8a632SRahul Lakkireddy q->iqe_len = iqe_size; 47592c8a632SRahul Lakkireddy q->size = size; 47692c8a632SRahul Lakkireddy } 47792c8a632SRahul Lakkireddy 478b7fd9ea8SStephen Hemminger int cxgbe_cfg_queue_count(struct rte_eth_dev *eth_dev) 47992c8a632SRahul Lakkireddy { 48063a97e58SStephen Hemminger struct port_info *pi = eth_dev->data->dev_private; 48192c8a632SRahul Lakkireddy struct adapter *adap = pi->adapter; 48292c8a632SRahul Lakkireddy struct sge *s = &adap->sge; 48392c8a632SRahul Lakkireddy unsigned int max_queues = s->max_ethqsets / adap->params.nports; 48492c8a632SRahul Lakkireddy 48592c8a632SRahul Lakkireddy if ((eth_dev->data->nb_rx_queues < 1) || 48692c8a632SRahul Lakkireddy (eth_dev->data->nb_tx_queues < 1)) 48792c8a632SRahul Lakkireddy return -EINVAL; 48892c8a632SRahul Lakkireddy 48992c8a632SRahul Lakkireddy if ((eth_dev->data->nb_rx_queues > max_queues) || 49092c8a632SRahul Lakkireddy (eth_dev->data->nb_tx_queues > max_queues)) 49192c8a632SRahul Lakkireddy return -EINVAL; 49292c8a632SRahul Lakkireddy 49392c8a632SRahul Lakkireddy if (eth_dev->data->nb_rx_queues > pi->rss_size) 49492c8a632SRahul Lakkireddy return -EINVAL; 49592c8a632SRahul Lakkireddy 49692c8a632SRahul Lakkireddy /* We must configure RSS, since config has changed*/ 49792c8a632SRahul Lakkireddy pi->flags &= ~PORT_RSS_DONE; 49892c8a632SRahul Lakkireddy 49992c8a632SRahul Lakkireddy pi->n_rx_qsets = eth_dev->data->nb_rx_queues; 50092c8a632SRahul Lakkireddy pi->n_tx_qsets = eth_dev->data->nb_tx_queues; 50192c8a632SRahul Lakkireddy 50292c8a632SRahul Lakkireddy return 0; 50392c8a632SRahul Lakkireddy } 50492c8a632SRahul Lakkireddy 505b7fd9ea8SStephen Hemminger void cxgbe_cfg_queues(struct rte_eth_dev *eth_dev) 50692c8a632SRahul Lakkireddy { 50763a97e58SStephen Hemminger struct port_info *pi = eth_dev->data->dev_private; 50892c8a632SRahul Lakkireddy struct adapter *adap = pi->adapter; 50992c8a632SRahul Lakkireddy struct sge *s = &adap->sge; 51092c8a632SRahul Lakkireddy unsigned int i, nb_ports = 0, qidx = 0; 51192c8a632SRahul Lakkireddy unsigned int q_per_port = 0; 51292c8a632SRahul Lakkireddy 51392c8a632SRahul Lakkireddy if (!(adap->flags & CFG_QUEUES)) { 51492c8a632SRahul Lakkireddy for_each_port(adap, i) { 51592c8a632SRahul Lakkireddy struct port_info *tpi = adap2pinfo(adap, i); 51692c8a632SRahul Lakkireddy 51792c8a632SRahul Lakkireddy nb_ports += (is_x_10g_port(&tpi->link_cfg)) || 51892c8a632SRahul Lakkireddy is_x_1g_port(&tpi->link_cfg) ? 1 : 0; 51992c8a632SRahul Lakkireddy } 52092c8a632SRahul Lakkireddy 52192c8a632SRahul Lakkireddy /* 52292c8a632SRahul Lakkireddy * We default up to # of cores queues per 1G/10G port. 52392c8a632SRahul Lakkireddy */ 52492c8a632SRahul Lakkireddy if (nb_ports) 52587a3ae3eSRahul Lakkireddy q_per_port = (s->max_ethqsets - 52692c8a632SRahul Lakkireddy (adap->params.nports - nb_ports)) / 52792c8a632SRahul Lakkireddy nb_ports; 52892c8a632SRahul Lakkireddy 52964a46f14SDavid Marchand if (q_per_port > rte_lcore_count()) 53064a46f14SDavid Marchand q_per_port = rte_lcore_count(); 53192c8a632SRahul Lakkireddy 53292c8a632SRahul Lakkireddy for_each_port(adap, i) { 53392c8a632SRahul Lakkireddy struct port_info *pi = adap2pinfo(adap, i); 53492c8a632SRahul Lakkireddy 53592c8a632SRahul Lakkireddy pi->first_qset = qidx; 53692c8a632SRahul Lakkireddy 53792c8a632SRahul Lakkireddy /* Initially n_rx_qsets == n_tx_qsets */ 53892c8a632SRahul Lakkireddy pi->n_rx_qsets = (is_x_10g_port(&pi->link_cfg) || 53992c8a632SRahul Lakkireddy is_x_1g_port(&pi->link_cfg)) ? 54092c8a632SRahul Lakkireddy q_per_port : 1; 54192c8a632SRahul Lakkireddy pi->n_tx_qsets = pi->n_rx_qsets; 54292c8a632SRahul Lakkireddy 54392c8a632SRahul Lakkireddy if (pi->n_rx_qsets > pi->rss_size) 54492c8a632SRahul Lakkireddy pi->n_rx_qsets = pi->rss_size; 54592c8a632SRahul Lakkireddy 54692c8a632SRahul Lakkireddy qidx += pi->n_rx_qsets; 54792c8a632SRahul Lakkireddy } 54892c8a632SRahul Lakkireddy 54992c8a632SRahul Lakkireddy for (i = 0; i < ARRAY_SIZE(s->ethrxq); i++) { 55092c8a632SRahul Lakkireddy struct sge_eth_rxq *r = &s->ethrxq[i]; 55192c8a632SRahul Lakkireddy 5526c280962SRahul Lakkireddy init_rspq(adap, &r->rspq, 5, 32, 1024, 64); 55392c8a632SRahul Lakkireddy r->usembufs = 1; 55492c8a632SRahul Lakkireddy r->fl.size = (r->usembufs ? 1024 : 72); 55592c8a632SRahul Lakkireddy } 55692c8a632SRahul Lakkireddy 55792c8a632SRahul Lakkireddy for (i = 0; i < ARRAY_SIZE(s->ethtxq); i++) 55892c8a632SRahul Lakkireddy s->ethtxq[i].q.size = 1024; 55992c8a632SRahul Lakkireddy 56092c8a632SRahul Lakkireddy init_rspq(adap, &adap->sge.fw_evtq, 0, 0, 1024, 64); 56192c8a632SRahul Lakkireddy adap->flags |= CFG_QUEUES; 56292c8a632SRahul Lakkireddy } 56392c8a632SRahul Lakkireddy } 56492c8a632SRahul Lakkireddy 565856505d3SRahul Lakkireddy void cxgbe_stats_get(struct port_info *pi, struct port_stats *stats) 566856505d3SRahul Lakkireddy { 567856505d3SRahul Lakkireddy t4_get_port_stats_offset(pi->adapter, pi->tx_chan, stats, 568856505d3SRahul Lakkireddy &pi->stats_base); 569856505d3SRahul Lakkireddy } 570856505d3SRahul Lakkireddy 571856505d3SRahul Lakkireddy void cxgbe_stats_reset(struct port_info *pi) 572856505d3SRahul Lakkireddy { 573856505d3SRahul Lakkireddy t4_clr_port_stats(pi->adapter, pi->tx_chan); 574856505d3SRahul Lakkireddy } 575856505d3SRahul Lakkireddy 57683189849SRahul Lakkireddy static void setup_memwin(struct adapter *adap) 57783189849SRahul Lakkireddy { 57883189849SRahul Lakkireddy u32 mem_win0_base; 57983189849SRahul Lakkireddy 58083189849SRahul Lakkireddy /* For T5, only relative offset inside the PCIe BAR is passed */ 58183189849SRahul Lakkireddy mem_win0_base = MEMWIN0_BASE; 58283189849SRahul Lakkireddy 58383189849SRahul Lakkireddy /* 58483189849SRahul Lakkireddy * Set up memory window for accessing adapter memory ranges. (Read 58583189849SRahul Lakkireddy * back MA register to ensure that changes propagate before we attempt 58683189849SRahul Lakkireddy * to use the new values.) 58783189849SRahul Lakkireddy */ 58883189849SRahul Lakkireddy t4_write_reg(adap, 58983189849SRahul Lakkireddy PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_BASE_WIN, 59083189849SRahul Lakkireddy MEMWIN_NIC), 59183189849SRahul Lakkireddy mem_win0_base | V_BIR(0) | 59283189849SRahul Lakkireddy V_WINDOW(ilog2(MEMWIN0_APERTURE) - X_WINDOW_SHIFT)); 59383189849SRahul Lakkireddy t4_read_reg(adap, 59483189849SRahul Lakkireddy PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_BASE_WIN, 59583189849SRahul Lakkireddy MEMWIN_NIC)); 59683189849SRahul Lakkireddy } 59783189849SRahul Lakkireddy 598b7fd9ea8SStephen Hemminger int cxgbe_init_rss(struct adapter *adap) 59992c8a632SRahul Lakkireddy { 60092c8a632SRahul Lakkireddy unsigned int i; 601bfcb257dSKumar Sanghvi 602bfcb257dSKumar Sanghvi if (is_pf4(adap)) { 60392c8a632SRahul Lakkireddy int err; 60492c8a632SRahul Lakkireddy 60592c8a632SRahul Lakkireddy err = t4_init_rss_mode(adap, adap->mbox); 60692c8a632SRahul Lakkireddy if (err) 60792c8a632SRahul Lakkireddy return err; 608bfcb257dSKumar Sanghvi } 60992c8a632SRahul Lakkireddy 61092c8a632SRahul Lakkireddy for_each_port(adap, i) { 61192c8a632SRahul Lakkireddy struct port_info *pi = adap2pinfo(adap, i); 61292c8a632SRahul Lakkireddy 6138dca8cc5SRahul Lakkireddy pi->rss = rte_zmalloc(NULL, pi->rss_size * sizeof(u16), 0); 61492c8a632SRahul Lakkireddy if (!pi->rss) 61592c8a632SRahul Lakkireddy return -ENOMEM; 61608e21af9SKumar Sanghvi 61708e21af9SKumar Sanghvi pi->rss_hf = CXGBE_RSS_HF_ALL; 61892c8a632SRahul Lakkireddy } 61992c8a632SRahul Lakkireddy return 0; 62092c8a632SRahul Lakkireddy } 62192c8a632SRahul Lakkireddy 622c962618cSRahul Lakkireddy /** 623c962618cSRahul Lakkireddy * Dump basic information about the adapter. 624c962618cSRahul Lakkireddy */ 625b7fd9ea8SStephen Hemminger void cxgbe_print_adapter_info(struct adapter *adap) 626c962618cSRahul Lakkireddy { 627c962618cSRahul Lakkireddy /** 628c962618cSRahul Lakkireddy * Hardware/Firmware/etc. Version/Revision IDs. 629c962618cSRahul Lakkireddy */ 630c962618cSRahul Lakkireddy t4_dump_version_info(adap); 631c962618cSRahul Lakkireddy } 632c962618cSRahul Lakkireddy 633b7fd9ea8SStephen Hemminger void cxgbe_print_port_info(struct adapter *adap) 63483189849SRahul Lakkireddy { 63583189849SRahul Lakkireddy int i; 63683189849SRahul Lakkireddy char buf[80]; 63783189849SRahul Lakkireddy struct rte_pci_addr *loc = &adap->pdev->addr; 63883189849SRahul Lakkireddy 63983189849SRahul Lakkireddy for_each_port(adap, i) { 6402195df6dSRahul Lakkireddy const struct port_info *pi = adap2pinfo(adap, i); 64183189849SRahul Lakkireddy char *bufp = buf; 64283189849SRahul Lakkireddy 64376488837SRahul Lakkireddy if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_100M) 6449da2a694SRahul Lakkireddy bufp += sprintf(bufp, "100M/"); 64576488837SRahul Lakkireddy if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_1G) 6469da2a694SRahul Lakkireddy bufp += sprintf(bufp, "1G/"); 64776488837SRahul Lakkireddy if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_10G) 64883189849SRahul Lakkireddy bufp += sprintf(bufp, "10G/"); 64976488837SRahul Lakkireddy if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_25G) 6509da2a694SRahul Lakkireddy bufp += sprintf(bufp, "25G/"); 65176488837SRahul Lakkireddy if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_40G) 65283189849SRahul Lakkireddy bufp += sprintf(bufp, "40G/"); 65376488837SRahul Lakkireddy if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_50G) 65476488837SRahul Lakkireddy bufp += sprintf(bufp, "50G/"); 65576488837SRahul Lakkireddy if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_100G) 6569da2a694SRahul Lakkireddy bufp += sprintf(bufp, "100G/"); 65783189849SRahul Lakkireddy if (bufp != buf) 65883189849SRahul Lakkireddy --bufp; 65983189849SRahul Lakkireddy sprintf(bufp, "BASE-%s", 660efa8a43eSBruce Richardson t4_get_port_type_description( 661efa8a43eSBruce Richardson (enum fw_port_type)pi->port_type)); 66283189849SRahul Lakkireddy 66383189849SRahul Lakkireddy dev_info(adap, 66483189849SRahul Lakkireddy " " PCI_PRI_FMT " Chelsio rev %d %s %s\n", 66583189849SRahul Lakkireddy loc->domain, loc->bus, loc->devid, loc->function, 66683189849SRahul Lakkireddy CHELSIO_CHIP_RELEASE(adap->params.chip), buf, 66783189849SRahul Lakkireddy (adap->flags & USING_MSIX) ? " MSI-X" : 66883189849SRahul Lakkireddy (adap->flags & USING_MSI) ? " MSI" : ""); 66983189849SRahul Lakkireddy } 67083189849SRahul Lakkireddy } 67183189849SRahul Lakkireddy 672*dd7c9f12SRahul Lakkireddy static int check_devargs_handler(const char *key, const char *value, void *p) 673cda260a4SShagun Agrawal { 674*dd7c9f12SRahul Lakkireddy if (!strncmp(key, CXGBE_DEVARG_CMN_KEEP_OVLAN, strlen(key)) || 675*dd7c9f12SRahul Lakkireddy !strncmp(key, CXGBE_DEVARG_VF_FORCE_LINK_UP, strlen(key))) { 676*dd7c9f12SRahul Lakkireddy if (!strncmp(value, "1", 1)) { 677*dd7c9f12SRahul Lakkireddy bool *dst_val = (bool *)p; 678*dd7c9f12SRahul Lakkireddy 679*dd7c9f12SRahul Lakkireddy *dst_val = true; 680*dd7c9f12SRahul Lakkireddy } 681*dd7c9f12SRahul Lakkireddy } 682cda260a4SShagun Agrawal 683cda260a4SShagun Agrawal return 0; 684cda260a4SShagun Agrawal } 685cda260a4SShagun Agrawal 686*dd7c9f12SRahul Lakkireddy static int cxgbe_get_devargs(struct rte_devargs *devargs, const char *key, 687*dd7c9f12SRahul Lakkireddy void *p) 688cda260a4SShagun Agrawal { 689cda260a4SShagun Agrawal struct rte_kvargs *kvlist; 690*dd7c9f12SRahul Lakkireddy int ret = 0; 691cda260a4SShagun Agrawal 692cda260a4SShagun Agrawal if (!devargs) 693cda260a4SShagun Agrawal return 0; 694cda260a4SShagun Agrawal 695cda260a4SShagun Agrawal kvlist = rte_kvargs_parse(devargs->args, NULL); 696cda260a4SShagun Agrawal if (!kvlist) 697cda260a4SShagun Agrawal return 0; 698cda260a4SShagun Agrawal 699*dd7c9f12SRahul Lakkireddy if (!rte_kvargs_count(kvlist, key)) 700*dd7c9f12SRahul Lakkireddy goto out; 701cda260a4SShagun Agrawal 702*dd7c9f12SRahul Lakkireddy ret = rte_kvargs_process(kvlist, key, check_devargs_handler, p); 703*dd7c9f12SRahul Lakkireddy 704*dd7c9f12SRahul Lakkireddy out: 705cda260a4SShagun Agrawal rte_kvargs_free(kvlist); 706cda260a4SShagun Agrawal 707*dd7c9f12SRahul Lakkireddy return ret; 708*dd7c9f12SRahul Lakkireddy } 709*dd7c9f12SRahul Lakkireddy 710*dd7c9f12SRahul Lakkireddy static void cxgbe_get_devargs_int(struct adapter *adap, int *dst, 711*dd7c9f12SRahul Lakkireddy const char *key, int default_value) 712*dd7c9f12SRahul Lakkireddy { 713*dd7c9f12SRahul Lakkireddy struct rte_pci_device *pdev = adap->pdev; 714*dd7c9f12SRahul Lakkireddy int ret, devarg_value = default_value; 715*dd7c9f12SRahul Lakkireddy 716*dd7c9f12SRahul Lakkireddy *dst = default_value; 717*dd7c9f12SRahul Lakkireddy if (!pdev) 718*dd7c9f12SRahul Lakkireddy return; 719*dd7c9f12SRahul Lakkireddy 720*dd7c9f12SRahul Lakkireddy ret = cxgbe_get_devargs(pdev->device.devargs, key, &devarg_value); 721*dd7c9f12SRahul Lakkireddy if (ret) 722*dd7c9f12SRahul Lakkireddy return; 723*dd7c9f12SRahul Lakkireddy 724*dd7c9f12SRahul Lakkireddy *dst = devarg_value; 725*dd7c9f12SRahul Lakkireddy } 726*dd7c9f12SRahul Lakkireddy 727*dd7c9f12SRahul Lakkireddy void cxgbe_process_devargs(struct adapter *adap) 728*dd7c9f12SRahul Lakkireddy { 729*dd7c9f12SRahul Lakkireddy cxgbe_get_devargs_int(adap, &adap->devargs.keep_ovlan, 730*dd7c9f12SRahul Lakkireddy CXGBE_DEVARG_CMN_KEEP_OVLAN, 0); 731*dd7c9f12SRahul Lakkireddy cxgbe_get_devargs_int(adap, &adap->devargs.force_link_up, 732*dd7c9f12SRahul Lakkireddy CXGBE_DEVARG_VF_FORCE_LINK_UP, 0); 733cda260a4SShagun Agrawal } 734cda260a4SShagun Agrawal 735cda260a4SShagun Agrawal static void configure_vlan_types(struct adapter *adapter) 736cda260a4SShagun Agrawal { 737cda260a4SShagun Agrawal int i; 738cda260a4SShagun Agrawal 739cda260a4SShagun Agrawal for_each_port(adapter, i) { 740cda260a4SShagun Agrawal /* OVLAN Type 0x88a8 */ 741cda260a4SShagun Agrawal t4_set_reg_field(adapter, MPS_PORT_RX_OVLAN_REG(i, A_RX_OVLAN0), 742cda260a4SShagun Agrawal V_OVLAN_MASK(M_OVLAN_MASK) | 743cda260a4SShagun Agrawal V_OVLAN_ETYPE(M_OVLAN_ETYPE), 744cda260a4SShagun Agrawal V_OVLAN_MASK(M_OVLAN_MASK) | 745cda260a4SShagun Agrawal V_OVLAN_ETYPE(0x88a8)); 746cda260a4SShagun Agrawal /* OVLAN Type 0x9100 */ 747cda260a4SShagun Agrawal t4_set_reg_field(adapter, MPS_PORT_RX_OVLAN_REG(i, A_RX_OVLAN1), 748cda260a4SShagun Agrawal V_OVLAN_MASK(M_OVLAN_MASK) | 749cda260a4SShagun Agrawal V_OVLAN_ETYPE(M_OVLAN_ETYPE), 750cda260a4SShagun Agrawal V_OVLAN_MASK(M_OVLAN_MASK) | 751cda260a4SShagun Agrawal V_OVLAN_ETYPE(0x9100)); 752cda260a4SShagun Agrawal /* OVLAN Type 0x8100 */ 753cda260a4SShagun Agrawal t4_set_reg_field(adapter, MPS_PORT_RX_OVLAN_REG(i, A_RX_OVLAN2), 754cda260a4SShagun Agrawal V_OVLAN_MASK(M_OVLAN_MASK) | 755cda260a4SShagun Agrawal V_OVLAN_ETYPE(M_OVLAN_ETYPE), 756cda260a4SShagun Agrawal V_OVLAN_MASK(M_OVLAN_MASK) | 757cda260a4SShagun Agrawal V_OVLAN_ETYPE(0x8100)); 758cda260a4SShagun Agrawal 759cda260a4SShagun Agrawal /* IVLAN 0X8100 */ 760cda260a4SShagun Agrawal t4_set_reg_field(adapter, MPS_PORT_RX_IVLAN(i), 761cda260a4SShagun Agrawal V_IVLAN_ETYPE(M_IVLAN_ETYPE), 762cda260a4SShagun Agrawal V_IVLAN_ETYPE(0x8100)); 763cda260a4SShagun Agrawal 764cda260a4SShagun Agrawal t4_set_reg_field(adapter, MPS_PORT_RX_CTL(i), 765cda260a4SShagun Agrawal F_OVLAN_EN0 | F_OVLAN_EN1 | 766cda260a4SShagun Agrawal F_OVLAN_EN2 | F_IVLAN_EN, 767cda260a4SShagun Agrawal F_OVLAN_EN0 | F_OVLAN_EN1 | 768cda260a4SShagun Agrawal F_OVLAN_EN2 | F_IVLAN_EN); 769cda260a4SShagun Agrawal } 770cda260a4SShagun Agrawal 771*dd7c9f12SRahul Lakkireddy t4_tp_wr_bits_indirect(adapter, A_TP_INGRESS_CONFIG, V_RM_OVLAN(1), 772*dd7c9f12SRahul Lakkireddy V_RM_OVLAN(!adapter->devargs.keep_ovlan)); 773cda260a4SShagun Agrawal } 774cda260a4SShagun Agrawal 775ee606d92SRahul Lakkireddy static void configure_pcie_ext_tag(struct adapter *adapter) 776ee606d92SRahul Lakkireddy { 777ee606d92SRahul Lakkireddy u16 v; 778ee606d92SRahul Lakkireddy int pos = t4_os_find_pci_capability(adapter, PCI_CAP_ID_EXP); 779ee606d92SRahul Lakkireddy 780ee606d92SRahul Lakkireddy if (!pos) 781ee606d92SRahul Lakkireddy return; 782ee606d92SRahul Lakkireddy 783ee606d92SRahul Lakkireddy if (pos > 0) { 784ee606d92SRahul Lakkireddy t4_os_pci_read_cfg2(adapter, pos + PCI_EXP_DEVCTL, &v); 785ee606d92SRahul Lakkireddy v |= PCI_EXP_DEVCTL_EXT_TAG; 786ee606d92SRahul Lakkireddy t4_os_pci_write_cfg2(adapter, pos + PCI_EXP_DEVCTL, v); 787ee606d92SRahul Lakkireddy if (is_t6(adapter->params.chip)) { 788ee606d92SRahul Lakkireddy t4_set_reg_field(adapter, A_PCIE_CFG2, 789ee606d92SRahul Lakkireddy V_T6_TOTMAXTAG(M_T6_TOTMAXTAG), 790ee606d92SRahul Lakkireddy V_T6_TOTMAXTAG(7)); 791ee606d92SRahul Lakkireddy t4_set_reg_field(adapter, A_PCIE_CMD_CFG, 792ee606d92SRahul Lakkireddy V_T6_MINTAG(M_T6_MINTAG), 793ee606d92SRahul Lakkireddy V_T6_MINTAG(8)); 794ee606d92SRahul Lakkireddy } else { 795ee606d92SRahul Lakkireddy t4_set_reg_field(adapter, A_PCIE_CFG2, 796ee606d92SRahul Lakkireddy V_TOTMAXTAG(M_TOTMAXTAG), 797ee606d92SRahul Lakkireddy V_TOTMAXTAG(3)); 798ee606d92SRahul Lakkireddy t4_set_reg_field(adapter, A_PCIE_CMD_CFG, 799ee606d92SRahul Lakkireddy V_MINTAG(M_MINTAG), 800ee606d92SRahul Lakkireddy V_MINTAG(8)); 801ee606d92SRahul Lakkireddy } 802ee606d92SRahul Lakkireddy } 803ee606d92SRahul Lakkireddy } 804ee606d92SRahul Lakkireddy 80587a3ae3eSRahul Lakkireddy /* Figure out how many Queue Sets we can support */ 806b7fd9ea8SStephen Hemminger void cxgbe_configure_max_ethqsets(struct adapter *adapter) 80787a3ae3eSRahul Lakkireddy { 80887a3ae3eSRahul Lakkireddy unsigned int ethqsets; 80987a3ae3eSRahul Lakkireddy 81087a3ae3eSRahul Lakkireddy /* 81187a3ae3eSRahul Lakkireddy * We need to reserve an Ingress Queue for the Asynchronous Firmware 81287a3ae3eSRahul Lakkireddy * Event Queue. 81387a3ae3eSRahul Lakkireddy * 81487a3ae3eSRahul Lakkireddy * For each Queue Set, we'll need the ability to allocate two Egress 81587a3ae3eSRahul Lakkireddy * Contexts -- one for the Ingress Queue Free List and one for the TX 81687a3ae3eSRahul Lakkireddy * Ethernet Queue. 81787a3ae3eSRahul Lakkireddy */ 81887a3ae3eSRahul Lakkireddy if (is_pf4(adapter)) { 81987a3ae3eSRahul Lakkireddy struct pf_resources *pfres = &adapter->params.pfres; 82087a3ae3eSRahul Lakkireddy 82187a3ae3eSRahul Lakkireddy ethqsets = pfres->niqflint - 1; 82287a3ae3eSRahul Lakkireddy if (pfres->neq < ethqsets * 2) 82387a3ae3eSRahul Lakkireddy ethqsets = pfres->neq / 2; 82487a3ae3eSRahul Lakkireddy } else { 82587a3ae3eSRahul Lakkireddy struct vf_resources *vfres = &adapter->params.vfres; 82687a3ae3eSRahul Lakkireddy 82787a3ae3eSRahul Lakkireddy ethqsets = vfres->niqflint - 1; 82887a3ae3eSRahul Lakkireddy if (vfres->nethctrl != ethqsets) 82987a3ae3eSRahul Lakkireddy ethqsets = min(vfres->nethctrl, ethqsets); 83087a3ae3eSRahul Lakkireddy if (vfres->neq < ethqsets * 2) 83187a3ae3eSRahul Lakkireddy ethqsets = vfres->neq / 2; 83287a3ae3eSRahul Lakkireddy } 83387a3ae3eSRahul Lakkireddy 83487a3ae3eSRahul Lakkireddy if (ethqsets > MAX_ETH_QSETS) 83587a3ae3eSRahul Lakkireddy ethqsets = MAX_ETH_QSETS; 83687a3ae3eSRahul Lakkireddy adapter->sge.max_ethqsets = ethqsets; 83787a3ae3eSRahul Lakkireddy } 83887a3ae3eSRahul Lakkireddy 83983189849SRahul Lakkireddy /* 84083189849SRahul Lakkireddy * Tweak configuration based on system architecture, etc. Most of these have 84183189849SRahul Lakkireddy * defaults assigned to them by Firmware Configuration Files (if we're using 84283189849SRahul Lakkireddy * them) but need to be explicitly set if we're using hard-coded 84383189849SRahul Lakkireddy * initialization. So these are essentially common tweaks/settings for 84483189849SRahul Lakkireddy * Configuration Files and hard-coded initialization ... 84583189849SRahul Lakkireddy */ 84683189849SRahul Lakkireddy static int adap_init0_tweaks(struct adapter *adapter) 84783189849SRahul Lakkireddy { 84883189849SRahul Lakkireddy u8 rx_dma_offset; 84983189849SRahul Lakkireddy 85083189849SRahul Lakkireddy /* 85183189849SRahul Lakkireddy * Fix up various Host-Dependent Parameters like Page Size, Cache 85283189849SRahul Lakkireddy * Line Size, etc. The firmware default is for a 4KB Page Size and 85383189849SRahul Lakkireddy * 64B Cache Line Size ... 85483189849SRahul Lakkireddy */ 8551f8613f1SRahul Lakkireddy t4_fixup_host_params_compat(adapter, CXGBE_PAGE_SIZE, L1_CACHE_BYTES, 85683189849SRahul Lakkireddy T5_LAST_REV); 85783189849SRahul Lakkireddy 85883189849SRahul Lakkireddy /* 85983189849SRahul Lakkireddy * Keep the chip default offset to deliver Ingress packets into our 86083189849SRahul Lakkireddy * DMA buffers to zero 86183189849SRahul Lakkireddy */ 86283189849SRahul Lakkireddy rx_dma_offset = 0; 86383189849SRahul Lakkireddy t4_set_reg_field(adapter, A_SGE_CONTROL, V_PKTSHIFT(M_PKTSHIFT), 86483189849SRahul Lakkireddy V_PKTSHIFT(rx_dma_offset)); 86583189849SRahul Lakkireddy 866bf89cbedSRahul Lakkireddy t4_set_reg_field(adapter, A_SGE_FLM_CFG, 867bf89cbedSRahul Lakkireddy V_CREDITCNT(M_CREDITCNT) | M_CREDITCNTPACKING, 868bf89cbedSRahul Lakkireddy V_CREDITCNT(3) | V_CREDITCNTPACKING(1)); 869bf89cbedSRahul Lakkireddy 8706c280962SRahul Lakkireddy t4_set_reg_field(adapter, A_SGE_INGRESS_RX_THRESHOLD, 8716c280962SRahul Lakkireddy V_THRESHOLD_3(M_THRESHOLD_3), V_THRESHOLD_3(32U)); 8726c280962SRahul Lakkireddy 873bf89cbedSRahul Lakkireddy t4_set_reg_field(adapter, A_SGE_CONTROL2, V_IDMAARBROUNDROBIN(1U), 874bf89cbedSRahul Lakkireddy V_IDMAARBROUNDROBIN(1U)); 875bf89cbedSRahul Lakkireddy 87683189849SRahul Lakkireddy /* 87783189849SRahul Lakkireddy * Don't include the "IP Pseudo Header" in CPL_RX_PKT checksums: Linux 87883189849SRahul Lakkireddy * adds the pseudo header itself. 87983189849SRahul Lakkireddy */ 88083189849SRahul Lakkireddy t4_tp_wr_bits_indirect(adapter, A_TP_INGRESS_CONFIG, 88183189849SRahul Lakkireddy F_CSUM_HAS_PSEUDO_HDR, 0); 88283189849SRahul Lakkireddy 88383189849SRahul Lakkireddy return 0; 88483189849SRahul Lakkireddy } 88583189849SRahul Lakkireddy 88683189849SRahul Lakkireddy /* 88783189849SRahul Lakkireddy * Attempt to initialize the adapter via a Firmware Configuration File. 88883189849SRahul Lakkireddy */ 88983189849SRahul Lakkireddy static int adap_init0_config(struct adapter *adapter, int reset) 89083189849SRahul Lakkireddy { 89183189849SRahul Lakkireddy struct fw_caps_config_cmd caps_cmd; 89283189849SRahul Lakkireddy unsigned long mtype = 0, maddr = 0; 89383189849SRahul Lakkireddy u32 finiver, finicsum, cfcsum; 89483189849SRahul Lakkireddy int ret; 89583189849SRahul Lakkireddy int config_issued = 0; 89683189849SRahul Lakkireddy int cfg_addr; 89783189849SRahul Lakkireddy char config_name[20]; 89883189849SRahul Lakkireddy 89983189849SRahul Lakkireddy /* 90083189849SRahul Lakkireddy * Reset device if necessary. 90183189849SRahul Lakkireddy */ 90283189849SRahul Lakkireddy if (reset) { 90383189849SRahul Lakkireddy ret = t4_fw_reset(adapter, adapter->mbox, 90483189849SRahul Lakkireddy F_PIORSTMODE | F_PIORST); 90583189849SRahul Lakkireddy if (ret < 0) { 90683189849SRahul Lakkireddy dev_warn(adapter, "Firmware reset failed, error %d\n", 90783189849SRahul Lakkireddy -ret); 90883189849SRahul Lakkireddy goto bye; 90983189849SRahul Lakkireddy } 91083189849SRahul Lakkireddy } 91183189849SRahul Lakkireddy 91283189849SRahul Lakkireddy cfg_addr = t4_flash_cfg_addr(adapter); 91383189849SRahul Lakkireddy if (cfg_addr < 0) { 91483189849SRahul Lakkireddy ret = cfg_addr; 91583189849SRahul Lakkireddy dev_warn(adapter, "Finding address for firmware config file in flash failed, error %d\n", 91683189849SRahul Lakkireddy -ret); 91783189849SRahul Lakkireddy goto bye; 91883189849SRahul Lakkireddy } 91983189849SRahul Lakkireddy 92083189849SRahul Lakkireddy strcpy(config_name, "On Flash"); 92183189849SRahul Lakkireddy mtype = FW_MEMTYPE_CF_FLASH; 92283189849SRahul Lakkireddy maddr = cfg_addr; 92383189849SRahul Lakkireddy 92483189849SRahul Lakkireddy /* 92583189849SRahul Lakkireddy * Issue a Capability Configuration command to the firmware to get it 92683189849SRahul Lakkireddy * to parse the Configuration File. We don't use t4_fw_config_file() 92783189849SRahul Lakkireddy * because we want the ability to modify various features after we've 92883189849SRahul Lakkireddy * processed the configuration file ... 92983189849SRahul Lakkireddy */ 93083189849SRahul Lakkireddy memset(&caps_cmd, 0, sizeof(caps_cmd)); 93183189849SRahul Lakkireddy caps_cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) | 93283189849SRahul Lakkireddy F_FW_CMD_REQUEST | F_FW_CMD_READ); 93383189849SRahul Lakkireddy caps_cmd.cfvalid_to_len16 = 93483189849SRahul Lakkireddy cpu_to_be32(F_FW_CAPS_CONFIG_CMD_CFVALID | 93583189849SRahul Lakkireddy V_FW_CAPS_CONFIG_CMD_MEMTYPE_CF(mtype) | 93683189849SRahul Lakkireddy V_FW_CAPS_CONFIG_CMD_MEMADDR64K_CF(maddr >> 16) | 93783189849SRahul Lakkireddy FW_LEN16(caps_cmd)); 93883189849SRahul Lakkireddy ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd, sizeof(caps_cmd), 93983189849SRahul Lakkireddy &caps_cmd); 94083189849SRahul Lakkireddy /* 94183189849SRahul Lakkireddy * If the CAPS_CONFIG failed with an ENOENT (for a Firmware 94283189849SRahul Lakkireddy * Configuration File in FLASH), our last gasp effort is to use the 94383189849SRahul Lakkireddy * Firmware Configuration File which is embedded in the firmware. A 94483189849SRahul Lakkireddy * very few early versions of the firmware didn't have one embedded 94583189849SRahul Lakkireddy * but we can ignore those. 94683189849SRahul Lakkireddy */ 94783189849SRahul Lakkireddy if (ret == -ENOENT) { 94883189849SRahul Lakkireddy dev_info(adapter, "%s: Going for embedded config in firmware..\n", 94983189849SRahul Lakkireddy __func__); 95083189849SRahul Lakkireddy 95183189849SRahul Lakkireddy memset(&caps_cmd, 0, sizeof(caps_cmd)); 95283189849SRahul Lakkireddy caps_cmd.op_to_write = 95383189849SRahul Lakkireddy cpu_to_be32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) | 95483189849SRahul Lakkireddy F_FW_CMD_REQUEST | F_FW_CMD_READ); 95583189849SRahul Lakkireddy caps_cmd.cfvalid_to_len16 = cpu_to_be32(FW_LEN16(caps_cmd)); 95683189849SRahul Lakkireddy ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd, 95783189849SRahul Lakkireddy sizeof(caps_cmd), &caps_cmd); 95883189849SRahul Lakkireddy strcpy(config_name, "Firmware Default"); 95983189849SRahul Lakkireddy } 96083189849SRahul Lakkireddy 96183189849SRahul Lakkireddy config_issued = 1; 96283189849SRahul Lakkireddy if (ret < 0) 96383189849SRahul Lakkireddy goto bye; 96483189849SRahul Lakkireddy 96583189849SRahul Lakkireddy finiver = be32_to_cpu(caps_cmd.finiver); 96683189849SRahul Lakkireddy finicsum = be32_to_cpu(caps_cmd.finicsum); 96783189849SRahul Lakkireddy cfcsum = be32_to_cpu(caps_cmd.cfcsum); 96883189849SRahul Lakkireddy if (finicsum != cfcsum) 96983189849SRahul Lakkireddy dev_warn(adapter, "Configuration File checksum mismatch: [fini] csum=%#x, computed csum=%#x\n", 97083189849SRahul Lakkireddy finicsum, cfcsum); 97183189849SRahul Lakkireddy 97283189849SRahul Lakkireddy /* 97383189849SRahul Lakkireddy * If we're a pure NIC driver then disable all offloading facilities. 97483189849SRahul Lakkireddy * This will allow the firmware to optimize aspects of the hardware 97583189849SRahul Lakkireddy * configuration which will result in improved performance. 97683189849SRahul Lakkireddy */ 9773a381a41SShagun Agrawal caps_cmd.niccaps &= cpu_to_be16(~FW_CAPS_CONFIG_NIC_ETHOFLD); 97883189849SRahul Lakkireddy caps_cmd.toecaps = 0; 97983189849SRahul Lakkireddy caps_cmd.iscsicaps = 0; 98083189849SRahul Lakkireddy caps_cmd.rdmacaps = 0; 98183189849SRahul Lakkireddy caps_cmd.fcoecaps = 0; 98283189849SRahul Lakkireddy 98383189849SRahul Lakkireddy /* 98483189849SRahul Lakkireddy * And now tell the firmware to use the configuration we just loaded. 98583189849SRahul Lakkireddy */ 98683189849SRahul Lakkireddy caps_cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) | 98783189849SRahul Lakkireddy F_FW_CMD_REQUEST | F_FW_CMD_WRITE); 98883189849SRahul Lakkireddy caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd)); 98983189849SRahul Lakkireddy ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd, sizeof(caps_cmd), 99083189849SRahul Lakkireddy NULL); 99183189849SRahul Lakkireddy if (ret < 0) { 99283189849SRahul Lakkireddy dev_warn(adapter, "Unable to finalize Firmware Capabilities %d\n", 99383189849SRahul Lakkireddy -ret); 99483189849SRahul Lakkireddy goto bye; 99583189849SRahul Lakkireddy } 99683189849SRahul Lakkireddy 99783189849SRahul Lakkireddy /* 99883189849SRahul Lakkireddy * Tweak configuration based on system architecture, etc. 99983189849SRahul Lakkireddy */ 100083189849SRahul Lakkireddy ret = adap_init0_tweaks(adapter); 100183189849SRahul Lakkireddy if (ret < 0) { 100283189849SRahul Lakkireddy dev_warn(adapter, "Unable to do init0-tweaks %d\n", -ret); 100383189849SRahul Lakkireddy goto bye; 100483189849SRahul Lakkireddy } 100583189849SRahul Lakkireddy 100683189849SRahul Lakkireddy /* 100783189849SRahul Lakkireddy * And finally tell the firmware to initialize itself using the 100883189849SRahul Lakkireddy * parameters from the Configuration File. 100983189849SRahul Lakkireddy */ 101083189849SRahul Lakkireddy ret = t4_fw_initialize(adapter, adapter->mbox); 101183189849SRahul Lakkireddy if (ret < 0) { 101283189849SRahul Lakkireddy dev_warn(adapter, "Initializing Firmware failed, error %d\n", 101383189849SRahul Lakkireddy -ret); 101483189849SRahul Lakkireddy goto bye; 101583189849SRahul Lakkireddy } 101683189849SRahul Lakkireddy 101783189849SRahul Lakkireddy /* 101883189849SRahul Lakkireddy * Return successfully and note that we're operating with parameters 101983189849SRahul Lakkireddy * not supplied by the driver, rather than from hard-wired 102098a7ea33SJerin Jacob * initialization constants buried in the driver. 102183189849SRahul Lakkireddy */ 102283189849SRahul Lakkireddy dev_info(adapter, 102383189849SRahul Lakkireddy "Successfully configured using Firmware Configuration File \"%s\", version %#x, computed checksum %#x\n", 102483189849SRahul Lakkireddy config_name, finiver, cfcsum); 102583189849SRahul Lakkireddy 102683189849SRahul Lakkireddy return 0; 102783189849SRahul Lakkireddy 102883189849SRahul Lakkireddy /* 102983189849SRahul Lakkireddy * Something bad happened. Return the error ... (If the "error" 103083189849SRahul Lakkireddy * is that there's no Configuration File on the adapter we don't 103183189849SRahul Lakkireddy * want to issue a warning since this is fairly common.) 103283189849SRahul Lakkireddy */ 103383189849SRahul Lakkireddy bye: 103483189849SRahul Lakkireddy if (config_issued && ret != -ENOENT) 103583189849SRahul Lakkireddy dev_warn(adapter, "\"%s\" configuration file error %d\n", 103683189849SRahul Lakkireddy config_name, -ret); 103783189849SRahul Lakkireddy 103883189849SRahul Lakkireddy dev_debug(adapter, "%s: returning ret = %d ..\n", __func__, ret); 103983189849SRahul Lakkireddy return ret; 104083189849SRahul Lakkireddy } 104183189849SRahul Lakkireddy 104283189849SRahul Lakkireddy static int adap_init0(struct adapter *adap) 104383189849SRahul Lakkireddy { 10446f2a064bSShagun Agrawal struct fw_caps_config_cmd caps_cmd; 104583189849SRahul Lakkireddy int ret = 0; 104683189849SRahul Lakkireddy u32 v, port_vec; 104783189849SRahul Lakkireddy enum dev_state state; 104883189849SRahul Lakkireddy u32 params[7], val[7]; 104983189849SRahul Lakkireddy int reset = 1; 105083189849SRahul Lakkireddy int mbox = adap->mbox; 105183189849SRahul Lakkireddy 105283189849SRahul Lakkireddy /* 105383189849SRahul Lakkireddy * Contact FW, advertising Master capability. 105483189849SRahul Lakkireddy */ 105583189849SRahul Lakkireddy ret = t4_fw_hello(adap, adap->mbox, adap->mbox, MASTER_MAY, &state); 105683189849SRahul Lakkireddy if (ret < 0) { 105783189849SRahul Lakkireddy dev_err(adap, "%s: could not connect to FW, error %d\n", 105883189849SRahul Lakkireddy __func__, -ret); 105983189849SRahul Lakkireddy goto bye; 106083189849SRahul Lakkireddy } 106183189849SRahul Lakkireddy 106283189849SRahul Lakkireddy CXGBE_DEBUG_MBOX(adap, "%s: adap->mbox = %d; ret = %d\n", __func__, 106383189849SRahul Lakkireddy adap->mbox, ret); 106483189849SRahul Lakkireddy 106583189849SRahul Lakkireddy if (ret == mbox) 106683189849SRahul Lakkireddy adap->flags |= MASTER_PF; 106783189849SRahul Lakkireddy 106883189849SRahul Lakkireddy if (state == DEV_STATE_INIT) { 106983189849SRahul Lakkireddy /* 107083189849SRahul Lakkireddy * Force halt and reset FW because a previous instance may have 107183189849SRahul Lakkireddy * exited abnormally without properly shutting down 107283189849SRahul Lakkireddy */ 107383189849SRahul Lakkireddy ret = t4_fw_halt(adap, adap->mbox, reset); 107483189849SRahul Lakkireddy if (ret < 0) { 107583189849SRahul Lakkireddy dev_err(adap, "Failed to halt. Exit.\n"); 107683189849SRahul Lakkireddy goto bye; 107783189849SRahul Lakkireddy } 107883189849SRahul Lakkireddy 107983189849SRahul Lakkireddy ret = t4_fw_restart(adap, adap->mbox, reset); 108083189849SRahul Lakkireddy if (ret < 0) { 108183189849SRahul Lakkireddy dev_err(adap, "Failed to restart. Exit.\n"); 108283189849SRahul Lakkireddy goto bye; 108383189849SRahul Lakkireddy } 1084efa8a43eSBruce Richardson state = (enum dev_state)((unsigned)state & ~DEV_STATE_INIT); 108583189849SRahul Lakkireddy } 108683189849SRahul Lakkireddy 1087c962618cSRahul Lakkireddy t4_get_version_info(adap); 108883189849SRahul Lakkireddy 108983189849SRahul Lakkireddy ret = t4_get_core_clock(adap, &adap->params.vpd); 109083189849SRahul Lakkireddy if (ret < 0) { 109183189849SRahul Lakkireddy dev_err(adap, "%s: could not get core clock, error %d\n", 109283189849SRahul Lakkireddy __func__, -ret); 109383189849SRahul Lakkireddy goto bye; 109483189849SRahul Lakkireddy } 109583189849SRahul Lakkireddy 109683189849SRahul Lakkireddy /* 109783189849SRahul Lakkireddy * If the firmware is initialized already (and we're not forcing a 109883189849SRahul Lakkireddy * master initialization), note that we're living with existing 109983189849SRahul Lakkireddy * adapter parameters. Otherwise, it's time to try initializing the 110083189849SRahul Lakkireddy * adapter ... 110183189849SRahul Lakkireddy */ 110283189849SRahul Lakkireddy if (state == DEV_STATE_INIT) { 110383189849SRahul Lakkireddy dev_info(adap, "Coming up as %s: Adapter already initialized\n", 110483189849SRahul Lakkireddy adap->flags & MASTER_PF ? "MASTER" : "SLAVE"); 110583189849SRahul Lakkireddy } else { 110683189849SRahul Lakkireddy dev_info(adap, "Coming up as MASTER: Initializing adapter\n"); 110783189849SRahul Lakkireddy 110883189849SRahul Lakkireddy ret = adap_init0_config(adap, reset); 110983189849SRahul Lakkireddy if (ret == -ENOENT) { 111083189849SRahul Lakkireddy dev_err(adap, 111183189849SRahul Lakkireddy "No Configuration File present on adapter. Using hard-wired configuration parameters.\n"); 111283189849SRahul Lakkireddy goto bye; 111383189849SRahul Lakkireddy } 111483189849SRahul Lakkireddy } 111583189849SRahul Lakkireddy if (ret < 0) { 111683189849SRahul Lakkireddy dev_err(adap, "could not initialize adapter, error %d\n", -ret); 111783189849SRahul Lakkireddy goto bye; 111883189849SRahul Lakkireddy } 111983189849SRahul Lakkireddy 112087a3ae3eSRahul Lakkireddy /* Now that we've successfully configured and initialized the adapter 112187a3ae3eSRahul Lakkireddy * (or found it already initialized), we can ask the Firmware what 112287a3ae3eSRahul Lakkireddy * resources it has provisioned for us. 112387a3ae3eSRahul Lakkireddy */ 112487a3ae3eSRahul Lakkireddy ret = t4_get_pfres(adap); 112587a3ae3eSRahul Lakkireddy if (ret) { 112687a3ae3eSRahul Lakkireddy dev_err(adap->pdev_dev, 112787a3ae3eSRahul Lakkireddy "Unable to retrieve resource provisioning info\n"); 112887a3ae3eSRahul Lakkireddy goto bye; 112987a3ae3eSRahul Lakkireddy } 113087a3ae3eSRahul Lakkireddy 11315eb55bf8SRahul Lakkireddy /* Find out what ports are available to us. */ 11325eb55bf8SRahul Lakkireddy v = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) | 11335eb55bf8SRahul Lakkireddy V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_PORTVEC); 11345eb55bf8SRahul Lakkireddy ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1, &v, &port_vec); 11355eb55bf8SRahul Lakkireddy if (ret < 0) { 11365eb55bf8SRahul Lakkireddy dev_err(adap, "%s: failure in t4_query_params; error = %d\n", 11375eb55bf8SRahul Lakkireddy __func__, ret); 11385eb55bf8SRahul Lakkireddy goto bye; 11395eb55bf8SRahul Lakkireddy } 11405eb55bf8SRahul Lakkireddy 11415eb55bf8SRahul Lakkireddy adap->params.nports = hweight32(port_vec); 11425eb55bf8SRahul Lakkireddy adap->params.portvec = port_vec; 11435eb55bf8SRahul Lakkireddy 11445eb55bf8SRahul Lakkireddy dev_debug(adap, "%s: adap->params.nports = %u\n", __func__, 11455eb55bf8SRahul Lakkireddy adap->params.nports); 11465eb55bf8SRahul Lakkireddy 114783189849SRahul Lakkireddy /* 114883189849SRahul Lakkireddy * Give the SGE code a chance to pull in anything that it needs ... 114983189849SRahul Lakkireddy * Note that this must be called after we retrieve our VPD parameters 115083189849SRahul Lakkireddy * in order to know how to convert core ticks to seconds, etc. 115183189849SRahul Lakkireddy */ 115283189849SRahul Lakkireddy ret = t4_sge_init(adap); 115383189849SRahul Lakkireddy if (ret < 0) { 115483189849SRahul Lakkireddy dev_err(adap, "t4_sge_init failed with error %d\n", 115583189849SRahul Lakkireddy -ret); 115683189849SRahul Lakkireddy goto bye; 115783189849SRahul Lakkireddy } 115883189849SRahul Lakkireddy 115983189849SRahul Lakkireddy /* 116083189849SRahul Lakkireddy * Grab some of our basic fundamental operating parameters. 116183189849SRahul Lakkireddy */ 116283189849SRahul Lakkireddy #define FW_PARAM_DEV(param) \ 116383189849SRahul Lakkireddy (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) | \ 116483189849SRahul Lakkireddy V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_##param)) 116583189849SRahul Lakkireddy 116683189849SRahul Lakkireddy #define FW_PARAM_PFVF(param) \ 116783189849SRahul Lakkireddy (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_PFVF) | \ 116883189849SRahul Lakkireddy V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_PFVF_##param) | \ 116983189849SRahul Lakkireddy V_FW_PARAMS_PARAM_Y(0) | \ 117083189849SRahul Lakkireddy V_FW_PARAMS_PARAM_Z(0)) 117183189849SRahul Lakkireddy 117223af667fSShagun Agrawal params[0] = FW_PARAM_PFVF(L2T_START); 117323af667fSShagun Agrawal params[1] = FW_PARAM_PFVF(L2T_END); 117423af667fSShagun Agrawal params[2] = FW_PARAM_PFVF(FILTER_START); 117523af667fSShagun Agrawal params[3] = FW_PARAM_PFVF(FILTER_END); 117623af667fSShagun Agrawal ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 4, params, val); 11776f2a064bSShagun Agrawal if (ret < 0) 11786f2a064bSShagun Agrawal goto bye; 117923af667fSShagun Agrawal adap->l2t_start = val[0]; 118023af667fSShagun Agrawal adap->l2t_end = val[1]; 118123af667fSShagun Agrawal adap->tids.ftid_base = val[2]; 118223af667fSShagun Agrawal adap->tids.nftids = val[3] - val[2] + 1; 11836f2a064bSShagun Agrawal 11843f2c1e20SShagun Agrawal params[0] = FW_PARAM_PFVF(CLIP_START); 11853f2c1e20SShagun Agrawal params[1] = FW_PARAM_PFVF(CLIP_END); 11863f2c1e20SShagun Agrawal ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params, val); 11873f2c1e20SShagun Agrawal if (ret < 0) 11883f2c1e20SShagun Agrawal goto bye; 11893f2c1e20SShagun Agrawal adap->clipt_start = val[0]; 11903f2c1e20SShagun Agrawal adap->clipt_end = val[1]; 11913f2c1e20SShagun Agrawal 11926f2a064bSShagun Agrawal /* 11936f2a064bSShagun Agrawal * Get device capabilities so we can determine what resources we need 11946f2a064bSShagun Agrawal * to manage. 11956f2a064bSShagun Agrawal */ 11966f2a064bSShagun Agrawal memset(&caps_cmd, 0, sizeof(caps_cmd)); 11976f2a064bSShagun Agrawal caps_cmd.op_to_write = htonl(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) | 11986f2a064bSShagun Agrawal F_FW_CMD_REQUEST | F_FW_CMD_READ); 11996f2a064bSShagun Agrawal caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd)); 12006f2a064bSShagun Agrawal ret = t4_wr_mbox(adap, adap->mbox, &caps_cmd, sizeof(caps_cmd), 12016f2a064bSShagun Agrawal &caps_cmd); 12026f2a064bSShagun Agrawal if (ret < 0) 12036f2a064bSShagun Agrawal goto bye; 12046f2a064bSShagun Agrawal 12053a381a41SShagun Agrawal if ((caps_cmd.niccaps & cpu_to_be16(FW_CAPS_CONFIG_NIC_HASHFILTER)) && 12063a381a41SShagun Agrawal is_t6(adap->params.chip)) { 120771e9b334SRahul Lakkireddy if (cxgbe_init_hash_filter(adap) < 0) 12083a381a41SShagun Agrawal goto bye; 12093a381a41SShagun Agrawal } 12103a381a41SShagun Agrawal 121148f523f6SRahul Lakkireddy /* See if FW supports FW_FILTER2 work request */ 121248f523f6SRahul Lakkireddy if (is_t4(adap->params.chip)) { 121348f523f6SRahul Lakkireddy adap->params.filter2_wr_support = 0; 121448f523f6SRahul Lakkireddy } else { 121548f523f6SRahul Lakkireddy params[0] = FW_PARAM_DEV(FILTER2_WR); 121648f523f6SRahul Lakkireddy ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 121748f523f6SRahul Lakkireddy 1, params, val); 121848f523f6SRahul Lakkireddy adap->params.filter2_wr_support = (ret == 0 && val[0] != 0); 121948f523f6SRahul Lakkireddy } 122048f523f6SRahul Lakkireddy 12216f2a064bSShagun Agrawal /* query tid-related parameters */ 12226f2a064bSShagun Agrawal params[0] = FW_PARAM_DEV(NTID); 12236f2a064bSShagun Agrawal ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1, 12246f2a064bSShagun Agrawal params, val); 12256f2a064bSShagun Agrawal if (ret < 0) 12266f2a064bSShagun Agrawal goto bye; 12276f2a064bSShagun Agrawal adap->tids.ntids = val[0]; 12283a381a41SShagun Agrawal adap->tids.natids = min(adap->tids.ntids / 2, MAX_ATIDS); 12296f2a064bSShagun Agrawal 123083189849SRahul Lakkireddy /* If we're running on newer firmware, let it know that we're 123183189849SRahul Lakkireddy * prepared to deal with encapsulated CPL messages. Older 123283189849SRahul Lakkireddy * firmware won't understand this and we'll just get 123383189849SRahul Lakkireddy * unencapsulated messages ... 123483189849SRahul Lakkireddy */ 123583189849SRahul Lakkireddy params[0] = FW_PARAM_PFVF(CPLFW4MSG_ENCAP); 123683189849SRahul Lakkireddy val[0] = 1; 123783189849SRahul Lakkireddy (void)t4_set_params(adap, adap->mbox, adap->pf, 0, 1, params, val); 123883189849SRahul Lakkireddy 123983189849SRahul Lakkireddy /* 124083189849SRahul Lakkireddy * Find out whether we're allowed to use the T5+ ULPTX MEMWRITE DSGL 124183189849SRahul Lakkireddy * capability. Earlier versions of the firmware didn't have the 124283189849SRahul Lakkireddy * ULPTX_MEMWRITE_DSGL so we'll interpret a query failure as no 124383189849SRahul Lakkireddy * permission to use ULPTX MEMWRITE DSGL. 124483189849SRahul Lakkireddy */ 124583189849SRahul Lakkireddy if (is_t4(adap->params.chip)) { 124683189849SRahul Lakkireddy adap->params.ulptx_memwrite_dsgl = false; 124783189849SRahul Lakkireddy } else { 124883189849SRahul Lakkireddy params[0] = FW_PARAM_DEV(ULPTX_MEMWRITE_DSGL); 124983189849SRahul Lakkireddy ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 125083189849SRahul Lakkireddy 1, params, val); 125183189849SRahul Lakkireddy adap->params.ulptx_memwrite_dsgl = (ret == 0 && val[0] != 0); 125283189849SRahul Lakkireddy } 125383189849SRahul Lakkireddy 125483189849SRahul Lakkireddy /* 125583189849SRahul Lakkireddy * The MTU/MSS Table is initialized by now, so load their values. If 125683189849SRahul Lakkireddy * we're initializing the adapter, then we'll make any modifications 125783189849SRahul Lakkireddy * we want to the MTU/MSS Table and also initialize the congestion 125883189849SRahul Lakkireddy * parameters. 125983189849SRahul Lakkireddy */ 126083189849SRahul Lakkireddy t4_read_mtu_tbl(adap, adap->params.mtus, NULL); 126183189849SRahul Lakkireddy if (state != DEV_STATE_INIT) { 126283189849SRahul Lakkireddy int i; 126383189849SRahul Lakkireddy 126483189849SRahul Lakkireddy /* 126583189849SRahul Lakkireddy * The default MTU Table contains values 1492 and 1500. 126683189849SRahul Lakkireddy * However, for TCP, it's better to have two values which are 126783189849SRahul Lakkireddy * a multiple of 8 +/- 4 bytes apart near this popular MTU. 126883189849SRahul Lakkireddy * This allows us to have a TCP Data Payload which is a 126983189849SRahul Lakkireddy * multiple of 8 regardless of what combination of TCP Options 127083189849SRahul Lakkireddy * are in use (always a multiple of 4 bytes) which is 127183189849SRahul Lakkireddy * important for performance reasons. For instance, if no 127283189849SRahul Lakkireddy * options are in use, then we have a 20-byte IP header and a 127383189849SRahul Lakkireddy * 20-byte TCP header. In this case, a 1500-byte MSS would 127483189849SRahul Lakkireddy * result in a TCP Data Payload of 1500 - 40 == 1460 bytes 127583189849SRahul Lakkireddy * which is not a multiple of 8. So using an MSS of 1488 in 127683189849SRahul Lakkireddy * this case results in a TCP Data Payload of 1448 bytes which 127783189849SRahul Lakkireddy * is a multiple of 8. On the other hand, if 12-byte TCP Time 127883189849SRahul Lakkireddy * Stamps have been negotiated, then an MTU of 1500 bytes 127983189849SRahul Lakkireddy * results in a TCP Data Payload of 1448 bytes which, as 128083189849SRahul Lakkireddy * above, is a multiple of 8 bytes ... 128183189849SRahul Lakkireddy */ 128283189849SRahul Lakkireddy for (i = 0; i < NMTUS; i++) 128383189849SRahul Lakkireddy if (adap->params.mtus[i] == 1492) { 128483189849SRahul Lakkireddy adap->params.mtus[i] = 1488; 128583189849SRahul Lakkireddy break; 128683189849SRahul Lakkireddy } 128783189849SRahul Lakkireddy 128883189849SRahul Lakkireddy t4_load_mtus(adap, adap->params.mtus, adap->params.a_wnd, 128983189849SRahul Lakkireddy adap->params.b_wnd); 129083189849SRahul Lakkireddy } 129183189849SRahul Lakkireddy t4_init_sge_params(adap); 129283189849SRahul Lakkireddy t4_init_tp_params(adap); 1293ee606d92SRahul Lakkireddy configure_pcie_ext_tag(adap); 1294cda260a4SShagun Agrawal configure_vlan_types(adap); 1295b7fd9ea8SStephen Hemminger cxgbe_configure_max_ethqsets(adap); 129683189849SRahul Lakkireddy 129783189849SRahul Lakkireddy adap->params.drv_memwin = MEMWIN_NIC; 129883189849SRahul Lakkireddy adap->flags |= FW_OK; 129983189849SRahul Lakkireddy dev_debug(adap, "%s: returning zero..\n", __func__); 130083189849SRahul Lakkireddy return 0; 130183189849SRahul Lakkireddy 130283189849SRahul Lakkireddy /* 130383189849SRahul Lakkireddy * Something bad happened. If a command timed out or failed with EIO 130483189849SRahul Lakkireddy * FW does not operate within its spec or something catastrophic 130583189849SRahul Lakkireddy * happened to HW/FW, stop issuing commands. 130683189849SRahul Lakkireddy */ 130783189849SRahul Lakkireddy bye: 130883189849SRahul Lakkireddy if (ret != -ETIMEDOUT && ret != -EIO) 130983189849SRahul Lakkireddy t4_fw_bye(adap, adap->mbox); 131083189849SRahul Lakkireddy return ret; 131183189849SRahul Lakkireddy } 131283189849SRahul Lakkireddy 131383189849SRahul Lakkireddy /** 131483189849SRahul Lakkireddy * t4_os_portmod_changed - handle port module changes 131583189849SRahul Lakkireddy * @adap: the adapter associated with the module change 131683189849SRahul Lakkireddy * @port_id: the port index whose module status has changed 131783189849SRahul Lakkireddy * 131883189849SRahul Lakkireddy * This is the OS-dependent handler for port module changes. It is 131983189849SRahul Lakkireddy * invoked when a port module is removed or inserted for any OS-specific 132083189849SRahul Lakkireddy * processing. 132183189849SRahul Lakkireddy */ 132283189849SRahul Lakkireddy void t4_os_portmod_changed(const struct adapter *adap, int port_id) 132383189849SRahul Lakkireddy { 132483189849SRahul Lakkireddy static const char * const mod_str[] = { 132583189849SRahul Lakkireddy NULL, "LR", "SR", "ER", "passive DA", "active DA", "LRM" 132683189849SRahul Lakkireddy }; 132783189849SRahul Lakkireddy 13282195df6dSRahul Lakkireddy const struct port_info *pi = adap2pinfo(adap, port_id); 132983189849SRahul Lakkireddy 133083189849SRahul Lakkireddy if (pi->mod_type == FW_PORT_MOD_TYPE_NONE) 133183189849SRahul Lakkireddy dev_info(adap, "Port%d: port module unplugged\n", pi->port_id); 133283189849SRahul Lakkireddy else if (pi->mod_type < ARRAY_SIZE(mod_str)) 133383189849SRahul Lakkireddy dev_info(adap, "Port%d: %s port module inserted\n", pi->port_id, 133483189849SRahul Lakkireddy mod_str[pi->mod_type]); 133583189849SRahul Lakkireddy else if (pi->mod_type == FW_PORT_MOD_TYPE_NOTSUPPORTED) 13369da2a694SRahul Lakkireddy dev_info(adap, "Port%d: unsupported port module inserted\n", 133783189849SRahul Lakkireddy pi->port_id); 133883189849SRahul Lakkireddy else if (pi->mod_type == FW_PORT_MOD_TYPE_UNKNOWN) 13399da2a694SRahul Lakkireddy dev_info(adap, "Port%d: unknown port module inserted\n", 134083189849SRahul Lakkireddy pi->port_id); 134183189849SRahul Lakkireddy else if (pi->mod_type == FW_PORT_MOD_TYPE_ERROR) 134283189849SRahul Lakkireddy dev_info(adap, "Port%d: transceiver module error\n", 134383189849SRahul Lakkireddy pi->port_id); 134483189849SRahul Lakkireddy else 134583189849SRahul Lakkireddy dev_info(adap, "Port%d: unknown module type %d inserted\n", 134683189849SRahul Lakkireddy pi->port_id, pi->mod_type); 134783189849SRahul Lakkireddy } 134883189849SRahul Lakkireddy 1349b7fd9ea8SStephen Hemminger bool cxgbe_force_linkup(struct adapter *adap) 1350f5b3c7b2SShagun Agrawal { 1351f5b3c7b2SShagun Agrawal if (is_pf4(adap)) 1352f5b3c7b2SShagun Agrawal return false; /* force_linkup not required for pf driver */ 1353*dd7c9f12SRahul Lakkireddy 1354*dd7c9f12SRahul Lakkireddy return adap->devargs.force_link_up; 1355f5b3c7b2SShagun Agrawal } 1356f5b3c7b2SShagun Agrawal 135792c8a632SRahul Lakkireddy /** 13580462d115SRahul Lakkireddy * link_start - enable a port 13590462d115SRahul Lakkireddy * @dev: the port to enable 13600462d115SRahul Lakkireddy * 13610462d115SRahul Lakkireddy * Performs the MAC and PHY actions needed to enable a port. 13620462d115SRahul Lakkireddy */ 1363b7fd9ea8SStephen Hemminger int cxgbe_link_start(struct port_info *pi) 13640462d115SRahul Lakkireddy { 13650462d115SRahul Lakkireddy struct adapter *adapter = pi->adapter; 13666507fb6fSRahul Lakkireddy u64 conf_offloads; 13675a9e303aSRahul Lakkireddy unsigned int mtu; 13686507fb6fSRahul Lakkireddy int ret; 13695a9e303aSRahul Lakkireddy 13705a9e303aSRahul Lakkireddy mtu = pi->eth_dev->data->dev_conf.rxmode.max_rx_pkt_len - 137135b2d13fSOlivier Matz (RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN); 13720462d115SRahul Lakkireddy 13736507fb6fSRahul Lakkireddy conf_offloads = pi->eth_dev->data->dev_conf.rxmode.offloads; 13746507fb6fSRahul Lakkireddy 13750462d115SRahul Lakkireddy /* 13760462d115SRahul Lakkireddy * We do not set address filters and promiscuity here, the stack does 13770462d115SRahul Lakkireddy * that step explicitly. 13780462d115SRahul Lakkireddy */ 13796507fb6fSRahul Lakkireddy ret = t4_set_rxmode(adapter, adapter->mbox, pi->viid, mtu, -1, -1, -1, 13806507fb6fSRahul Lakkireddy !!(conf_offloads & DEV_RX_OFFLOAD_VLAN_STRIP), 13816507fb6fSRahul Lakkireddy true); 13820462d115SRahul Lakkireddy if (ret == 0) { 1383fefee7a6SShagun Agrawal ret = cxgbe_mpstcam_modify(pi, (int)pi->xact_addr_filt, 1384fefee7a6SShagun Agrawal (u8 *)&pi->eth_dev->data->mac_addrs[0]); 13850462d115SRahul Lakkireddy if (ret >= 0) { 13860462d115SRahul Lakkireddy pi->xact_addr_filt = ret; 13870462d115SRahul Lakkireddy ret = 0; 13880462d115SRahul Lakkireddy } 13890462d115SRahul Lakkireddy } 13905e80364aSKumar Sanghvi if (ret == 0 && is_pf4(adapter)) 13910462d115SRahul Lakkireddy ret = t4_link_l1cfg(adapter, adapter->mbox, pi->tx_chan, 13920462d115SRahul Lakkireddy &pi->link_cfg); 13930462d115SRahul Lakkireddy if (ret == 0) { 13940462d115SRahul Lakkireddy /* 13950462d115SRahul Lakkireddy * Enabling a Virtual Interface can result in an interrupt 13960462d115SRahul Lakkireddy * during the processing of the VI Enable command and, in some 13970462d115SRahul Lakkireddy * paths, result in an attempt to issue another command in the 13980462d115SRahul Lakkireddy * interrupt context. Thus, we disable interrupts during the 13990462d115SRahul Lakkireddy * course of the VI Enable command ... 14000462d115SRahul Lakkireddy */ 14010462d115SRahul Lakkireddy ret = t4_enable_vi_params(adapter, adapter->mbox, pi->viid, 14020462d115SRahul Lakkireddy true, true, false); 14030462d115SRahul Lakkireddy } 1404f5b3c7b2SShagun Agrawal 1405b7fd9ea8SStephen Hemminger if (ret == 0 && cxgbe_force_linkup(adapter)) 1406f5b3c7b2SShagun Agrawal pi->eth_dev->data->dev_link.link_status = ETH_LINK_UP; 14070462d115SRahul Lakkireddy return ret; 14080462d115SRahul Lakkireddy } 14090462d115SRahul Lakkireddy 14100462d115SRahul Lakkireddy /** 141108e21af9SKumar Sanghvi * cxgbe_write_rss_conf - flash the RSS configuration for a given port 141208e21af9SKumar Sanghvi * @pi: the port 141308e21af9SKumar Sanghvi * @rss_hf: Hash configuration to apply 141408e21af9SKumar Sanghvi */ 141508e21af9SKumar Sanghvi int cxgbe_write_rss_conf(const struct port_info *pi, uint64_t rss_hf) 141608e21af9SKumar Sanghvi { 141708e21af9SKumar Sanghvi struct adapter *adapter = pi->adapter; 141808e21af9SKumar Sanghvi const struct sge_eth_rxq *rxq; 141908e21af9SKumar Sanghvi u64 flags = 0; 142008e21af9SKumar Sanghvi u16 rss; 142108e21af9SKumar Sanghvi int err; 142208e21af9SKumar Sanghvi 142308e21af9SKumar Sanghvi /* Should never be called before setting up sge eth rx queues */ 142408e21af9SKumar Sanghvi if (!(adapter->flags & FULL_INIT_DONE)) { 142508e21af9SKumar Sanghvi dev_err(adap, "%s No RXQs available on port %d\n", 142608e21af9SKumar Sanghvi __func__, pi->port_id); 142708e21af9SKumar Sanghvi return -EINVAL; 142808e21af9SKumar Sanghvi } 142908e21af9SKumar Sanghvi 143008e21af9SKumar Sanghvi /* Don't allow unsupported hash functions */ 143108e21af9SKumar Sanghvi if (rss_hf & ~CXGBE_RSS_HF_ALL) 143208e21af9SKumar Sanghvi return -EINVAL; 143308e21af9SKumar Sanghvi 1434d97aa415SRahul Lakkireddy if (rss_hf & CXGBE_RSS_HF_IPV4_MASK) 143508e21af9SKumar Sanghvi flags |= F_FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN; 143608e21af9SKumar Sanghvi 143708e21af9SKumar Sanghvi if (rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) 143808e21af9SKumar Sanghvi flags |= F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN; 143908e21af9SKumar Sanghvi 144008e21af9SKumar Sanghvi if (rss_hf & ETH_RSS_NONFRAG_IPV4_UDP) 144108e21af9SKumar Sanghvi flags |= F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN | 144208e21af9SKumar Sanghvi F_FW_RSS_VI_CONFIG_CMD_UDPEN; 144308e21af9SKumar Sanghvi 1444d97aa415SRahul Lakkireddy if (rss_hf & CXGBE_RSS_HF_IPV6_MASK) 144508e21af9SKumar Sanghvi flags |= F_FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN; 144608e21af9SKumar Sanghvi 1447d97aa415SRahul Lakkireddy if (rss_hf & CXGBE_RSS_HF_TCP_IPV6_MASK) 1448d97aa415SRahul Lakkireddy flags |= F_FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN | 1449d97aa415SRahul Lakkireddy F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN; 145008e21af9SKumar Sanghvi 1451d97aa415SRahul Lakkireddy if (rss_hf & CXGBE_RSS_HF_UDP_IPV6_MASK) 1452d97aa415SRahul Lakkireddy flags |= F_FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN | 1453d97aa415SRahul Lakkireddy F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN | 145408e21af9SKumar Sanghvi F_FW_RSS_VI_CONFIG_CMD_UDPEN; 145508e21af9SKumar Sanghvi 145608e21af9SKumar Sanghvi rxq = &adapter->sge.ethrxq[pi->first_qset]; 145708e21af9SKumar Sanghvi rss = rxq[0].rspq.abs_id; 145808e21af9SKumar Sanghvi 145908e21af9SKumar Sanghvi /* If Tunnel All Lookup isn't specified in the global RSS 146008e21af9SKumar Sanghvi * Configuration, then we need to specify a default Ingress 146108e21af9SKumar Sanghvi * Queue for any ingress packets which aren't hashed. We'll 146208e21af9SKumar Sanghvi * use our first ingress queue ... 146308e21af9SKumar Sanghvi */ 146408e21af9SKumar Sanghvi err = t4_config_vi_rss(adapter, adapter->mbox, pi->viid, 146508e21af9SKumar Sanghvi flags, rss); 146608e21af9SKumar Sanghvi return err; 146708e21af9SKumar Sanghvi } 146808e21af9SKumar Sanghvi 146908e21af9SKumar Sanghvi /** 147008e21af9SKumar Sanghvi * cxgbe_write_rss - write the RSS table for a given port 147192c8a632SRahul Lakkireddy * @pi: the port 147292c8a632SRahul Lakkireddy * @queues: array of queue indices for RSS 147392c8a632SRahul Lakkireddy * 147492c8a632SRahul Lakkireddy * Sets up the portion of the HW RSS table for the port's VI to distribute 147592c8a632SRahul Lakkireddy * packets to the Rx queues in @queues. 147692c8a632SRahul Lakkireddy */ 147708e21af9SKumar Sanghvi int cxgbe_write_rss(const struct port_info *pi, const u16 *queues) 147892c8a632SRahul Lakkireddy { 147992c8a632SRahul Lakkireddy u16 *rss; 148092c8a632SRahul Lakkireddy int i, err; 148192c8a632SRahul Lakkireddy struct adapter *adapter = pi->adapter; 148292c8a632SRahul Lakkireddy const struct sge_eth_rxq *rxq; 148392c8a632SRahul Lakkireddy 148492c8a632SRahul Lakkireddy /* Should never be called before setting up sge eth rx queues */ 148592c8a632SRahul Lakkireddy BUG_ON(!(adapter->flags & FULL_INIT_DONE)); 148692c8a632SRahul Lakkireddy 148792c8a632SRahul Lakkireddy rxq = &adapter->sge.ethrxq[pi->first_qset]; 148892c8a632SRahul Lakkireddy rss = rte_zmalloc(NULL, pi->rss_size * sizeof(u16), 0); 148992c8a632SRahul Lakkireddy if (!rss) 149092c8a632SRahul Lakkireddy return -ENOMEM; 149192c8a632SRahul Lakkireddy 149292c8a632SRahul Lakkireddy /* map the queue indices to queue ids */ 149392c8a632SRahul Lakkireddy for (i = 0; i < pi->rss_size; i++, queues++) 149492c8a632SRahul Lakkireddy rss[i] = rxq[*queues].rspq.abs_id; 149592c8a632SRahul Lakkireddy 149692c8a632SRahul Lakkireddy err = t4_config_rss_range(adapter, adapter->pf, pi->viid, 0, 149792c8a632SRahul Lakkireddy pi->rss_size, rss, pi->rss_size); 149892c8a632SRahul Lakkireddy rte_free(rss); 149992c8a632SRahul Lakkireddy return err; 150092c8a632SRahul Lakkireddy } 150192c8a632SRahul Lakkireddy 150292c8a632SRahul Lakkireddy /** 150392c8a632SRahul Lakkireddy * setup_rss - configure RSS 150492c8a632SRahul Lakkireddy * @adapter: the adapter 150592c8a632SRahul Lakkireddy * 150692c8a632SRahul Lakkireddy * Sets up RSS to distribute packets to multiple receive queues. We 150792c8a632SRahul Lakkireddy * configure the RSS CPU lookup table to distribute to the number of HW 150892c8a632SRahul Lakkireddy * receive queues, and the response queue lookup table to narrow that 150992c8a632SRahul Lakkireddy * down to the response queues actually configured for each port. 151092c8a632SRahul Lakkireddy * We always configure the RSS mapping for all ports since the mapping 151192c8a632SRahul Lakkireddy * table has plenty of entries. 151292c8a632SRahul Lakkireddy */ 1513b7fd9ea8SStephen Hemminger int cxgbe_setup_rss(struct port_info *pi) 151492c8a632SRahul Lakkireddy { 151592c8a632SRahul Lakkireddy int j, err; 151692c8a632SRahul Lakkireddy struct adapter *adapter = pi->adapter; 151792c8a632SRahul Lakkireddy 151892c8a632SRahul Lakkireddy dev_debug(adapter, "%s: pi->rss_size = %u; pi->n_rx_qsets = %u\n", 151992c8a632SRahul Lakkireddy __func__, pi->rss_size, pi->n_rx_qsets); 152092c8a632SRahul Lakkireddy 15211039ee1cSEmmanuel Roullit if (!(pi->flags & PORT_RSS_DONE)) { 152292c8a632SRahul Lakkireddy if (adapter->flags & FULL_INIT_DONE) { 152392c8a632SRahul Lakkireddy /* Fill default values with equal distribution */ 152492c8a632SRahul Lakkireddy for (j = 0; j < pi->rss_size; j++) 152592c8a632SRahul Lakkireddy pi->rss[j] = j % pi->n_rx_qsets; 152692c8a632SRahul Lakkireddy 152708e21af9SKumar Sanghvi err = cxgbe_write_rss(pi, pi->rss); 152808e21af9SKumar Sanghvi if (err) 152908e21af9SKumar Sanghvi return err; 153008e21af9SKumar Sanghvi 153108e21af9SKumar Sanghvi err = cxgbe_write_rss_conf(pi, pi->rss_hf); 153292c8a632SRahul Lakkireddy if (err) 153392c8a632SRahul Lakkireddy return err; 153492c8a632SRahul Lakkireddy pi->flags |= PORT_RSS_DONE; 153592c8a632SRahul Lakkireddy } 153692c8a632SRahul Lakkireddy } 153792c8a632SRahul Lakkireddy return 0; 153892c8a632SRahul Lakkireddy } 153992c8a632SRahul Lakkireddy 15400462d115SRahul Lakkireddy /* 15410462d115SRahul Lakkireddy * Enable NAPI scheduling and interrupt generation for all Rx queues. 15420462d115SRahul Lakkireddy */ 1543d87ba24dSRahul Lakkireddy static void enable_rx(struct adapter *adap, struct sge_rspq *q) 15440462d115SRahul Lakkireddy { 15450462d115SRahul Lakkireddy /* 0-increment GTS to start the timer and enable interrupts */ 15465e59e39aSKumar Sanghvi t4_write_reg(adap, is_pf4(adap) ? MYPF_REG(A_SGE_PF_GTS) : 15475e59e39aSKumar Sanghvi T4VF_SGE_BASE_ADDR + A_SGE_VF_GTS, 15480462d115SRahul Lakkireddy V_SEINTARM(q->intr_params) | 15490462d115SRahul Lakkireddy V_INGRESSQID(q->cntxt_id)); 15500462d115SRahul Lakkireddy } 1551d87ba24dSRahul Lakkireddy 1552d87ba24dSRahul Lakkireddy void cxgbe_enable_rx_queues(struct port_info *pi) 1553d87ba24dSRahul Lakkireddy { 1554d87ba24dSRahul Lakkireddy struct adapter *adap = pi->adapter; 1555d87ba24dSRahul Lakkireddy struct sge *s = &adap->sge; 1556d87ba24dSRahul Lakkireddy unsigned int i; 1557d87ba24dSRahul Lakkireddy 1558d87ba24dSRahul Lakkireddy for (i = 0; i < pi->n_rx_qsets; i++) 1559d87ba24dSRahul Lakkireddy enable_rx(adap, &s->ethrxq[pi->first_qset + i].rspq); 15600462d115SRahul Lakkireddy } 15610462d115SRahul Lakkireddy 15620462d115SRahul Lakkireddy /** 1563e307e65bSRahul Lakkireddy * fw_caps_to_speed_caps - translate Firmware Port Caps to Speed Caps. 1564e307e65bSRahul Lakkireddy * @port_type: Firmware Port Type 1565e307e65bSRahul Lakkireddy * @fw_caps: Firmware Port Capabilities 1566e307e65bSRahul Lakkireddy * @speed_caps: Device Info Speed Capabilities 1567e307e65bSRahul Lakkireddy * 1568e307e65bSRahul Lakkireddy * Translate a Firmware Port Capabilities specification to Device Info 1569e307e65bSRahul Lakkireddy * Speed Capabilities. 1570e307e65bSRahul Lakkireddy */ 1571e307e65bSRahul Lakkireddy static void fw_caps_to_speed_caps(enum fw_port_type port_type, 1572e307e65bSRahul Lakkireddy unsigned int fw_caps, 1573e307e65bSRahul Lakkireddy u32 *speed_caps) 1574e307e65bSRahul Lakkireddy { 1575e307e65bSRahul Lakkireddy #define SET_SPEED(__speed_name) \ 1576e307e65bSRahul Lakkireddy do { \ 1577e307e65bSRahul Lakkireddy *speed_caps |= ETH_LINK_ ## __speed_name; \ 1578e307e65bSRahul Lakkireddy } while (0) 1579e307e65bSRahul Lakkireddy 1580e307e65bSRahul Lakkireddy #define FW_CAPS_TO_SPEED(__fw_name) \ 1581e307e65bSRahul Lakkireddy do { \ 158276488837SRahul Lakkireddy if (fw_caps & FW_PORT_CAP32_ ## __fw_name) \ 1583e307e65bSRahul Lakkireddy SET_SPEED(__fw_name); \ 1584e307e65bSRahul Lakkireddy } while (0) 1585e307e65bSRahul Lakkireddy 1586e307e65bSRahul Lakkireddy switch (port_type) { 1587e307e65bSRahul Lakkireddy case FW_PORT_TYPE_BT_SGMII: 1588e307e65bSRahul Lakkireddy case FW_PORT_TYPE_BT_XFI: 1589e307e65bSRahul Lakkireddy case FW_PORT_TYPE_BT_XAUI: 1590e307e65bSRahul Lakkireddy FW_CAPS_TO_SPEED(SPEED_100M); 1591e307e65bSRahul Lakkireddy FW_CAPS_TO_SPEED(SPEED_1G); 1592e307e65bSRahul Lakkireddy FW_CAPS_TO_SPEED(SPEED_10G); 1593e307e65bSRahul Lakkireddy break; 1594e307e65bSRahul Lakkireddy 1595e307e65bSRahul Lakkireddy case FW_PORT_TYPE_KX4: 1596e307e65bSRahul Lakkireddy case FW_PORT_TYPE_KX: 1597e307e65bSRahul Lakkireddy case FW_PORT_TYPE_FIBER_XFI: 1598e307e65bSRahul Lakkireddy case FW_PORT_TYPE_FIBER_XAUI: 1599e307e65bSRahul Lakkireddy case FW_PORT_TYPE_SFP: 1600e307e65bSRahul Lakkireddy case FW_PORT_TYPE_QSFP_10G: 1601e307e65bSRahul Lakkireddy case FW_PORT_TYPE_QSA: 1602e307e65bSRahul Lakkireddy FW_CAPS_TO_SPEED(SPEED_1G); 1603e307e65bSRahul Lakkireddy FW_CAPS_TO_SPEED(SPEED_10G); 1604e307e65bSRahul Lakkireddy break; 1605e307e65bSRahul Lakkireddy 1606e307e65bSRahul Lakkireddy case FW_PORT_TYPE_KR: 1607e307e65bSRahul Lakkireddy SET_SPEED(SPEED_10G); 1608e307e65bSRahul Lakkireddy break; 1609e307e65bSRahul Lakkireddy 1610e307e65bSRahul Lakkireddy case FW_PORT_TYPE_BP_AP: 1611e307e65bSRahul Lakkireddy case FW_PORT_TYPE_BP4_AP: 1612e307e65bSRahul Lakkireddy SET_SPEED(SPEED_1G); 1613e307e65bSRahul Lakkireddy SET_SPEED(SPEED_10G); 1614e307e65bSRahul Lakkireddy break; 1615e307e65bSRahul Lakkireddy 1616e307e65bSRahul Lakkireddy case FW_PORT_TYPE_BP40_BA: 1617e307e65bSRahul Lakkireddy case FW_PORT_TYPE_QSFP: 1618e307e65bSRahul Lakkireddy SET_SPEED(SPEED_40G); 1619e307e65bSRahul Lakkireddy break; 1620e307e65bSRahul Lakkireddy 1621e307e65bSRahul Lakkireddy case FW_PORT_TYPE_CR_QSFP: 1622e307e65bSRahul Lakkireddy case FW_PORT_TYPE_SFP28: 1623e307e65bSRahul Lakkireddy case FW_PORT_TYPE_KR_SFP28: 1624e307e65bSRahul Lakkireddy FW_CAPS_TO_SPEED(SPEED_1G); 1625e307e65bSRahul Lakkireddy FW_CAPS_TO_SPEED(SPEED_10G); 1626e307e65bSRahul Lakkireddy FW_CAPS_TO_SPEED(SPEED_25G); 1627e307e65bSRahul Lakkireddy break; 1628e307e65bSRahul Lakkireddy 1629e307e65bSRahul Lakkireddy case FW_PORT_TYPE_CR2_QSFP: 1630e307e65bSRahul Lakkireddy SET_SPEED(SPEED_50G); 1631e307e65bSRahul Lakkireddy break; 1632e307e65bSRahul Lakkireddy 1633e307e65bSRahul Lakkireddy case FW_PORT_TYPE_KR4_100G: 1634e307e65bSRahul Lakkireddy case FW_PORT_TYPE_CR4_QSFP: 1635e307e65bSRahul Lakkireddy FW_CAPS_TO_SPEED(SPEED_25G); 1636e307e65bSRahul Lakkireddy FW_CAPS_TO_SPEED(SPEED_40G); 163776488837SRahul Lakkireddy FW_CAPS_TO_SPEED(SPEED_50G); 1638e307e65bSRahul Lakkireddy FW_CAPS_TO_SPEED(SPEED_100G); 1639e307e65bSRahul Lakkireddy break; 1640e307e65bSRahul Lakkireddy 1641e307e65bSRahul Lakkireddy default: 1642e307e65bSRahul Lakkireddy break; 1643e307e65bSRahul Lakkireddy } 1644e307e65bSRahul Lakkireddy 1645e307e65bSRahul Lakkireddy #undef FW_CAPS_TO_SPEED 1646e307e65bSRahul Lakkireddy #undef SET_SPEED 1647e307e65bSRahul Lakkireddy } 1648e307e65bSRahul Lakkireddy 1649e307e65bSRahul Lakkireddy /** 1650e307e65bSRahul Lakkireddy * cxgbe_get_speed_caps - Fetch supported speed capabilities 1651e307e65bSRahul Lakkireddy * @pi: Underlying port's info 1652e307e65bSRahul Lakkireddy * @speed_caps: Device Info speed capabilities 1653e307e65bSRahul Lakkireddy * 1654e307e65bSRahul Lakkireddy * Fetch supported speed capabilities of the underlying port. 1655e307e65bSRahul Lakkireddy */ 1656e307e65bSRahul Lakkireddy void cxgbe_get_speed_caps(struct port_info *pi, u32 *speed_caps) 1657e307e65bSRahul Lakkireddy { 1658e307e65bSRahul Lakkireddy *speed_caps = 0; 1659e307e65bSRahul Lakkireddy 166076488837SRahul Lakkireddy fw_caps_to_speed_caps(pi->port_type, pi->link_cfg.pcaps, 1661e307e65bSRahul Lakkireddy speed_caps); 1662e307e65bSRahul Lakkireddy 166376488837SRahul Lakkireddy if (!(pi->link_cfg.pcaps & FW_PORT_CAP32_ANEG)) 1664e307e65bSRahul Lakkireddy *speed_caps |= ETH_LINK_SPEED_FIXED; 1665e307e65bSRahul Lakkireddy } 1666e307e65bSRahul Lakkireddy 1667e307e65bSRahul Lakkireddy /** 1668265af08eSRahul Lakkireddy * cxgbe_set_link_status - Set device link up or down. 1669265af08eSRahul Lakkireddy * @pi: Underlying port's info 1670265af08eSRahul Lakkireddy * @status: 0 - down, 1 - up 1671265af08eSRahul Lakkireddy * 1672265af08eSRahul Lakkireddy * Set the device link up or down. 1673265af08eSRahul Lakkireddy */ 1674265af08eSRahul Lakkireddy int cxgbe_set_link_status(struct port_info *pi, bool status) 1675265af08eSRahul Lakkireddy { 1676265af08eSRahul Lakkireddy struct adapter *adapter = pi->adapter; 1677265af08eSRahul Lakkireddy int err = 0; 1678265af08eSRahul Lakkireddy 1679265af08eSRahul Lakkireddy err = t4_enable_vi(adapter, adapter->mbox, pi->viid, status, status); 1680265af08eSRahul Lakkireddy if (err) { 1681265af08eSRahul Lakkireddy dev_err(adapter, "%s: disable_vi failed: %d\n", __func__, err); 1682265af08eSRahul Lakkireddy return err; 1683265af08eSRahul Lakkireddy } 1684265af08eSRahul Lakkireddy 1685265af08eSRahul Lakkireddy if (!status) 1686265af08eSRahul Lakkireddy t4_reset_link_config(adapter, pi->pidx); 1687265af08eSRahul Lakkireddy 1688265af08eSRahul Lakkireddy return 0; 1689265af08eSRahul Lakkireddy } 1690265af08eSRahul Lakkireddy 1691265af08eSRahul Lakkireddy /** 16920462d115SRahul Lakkireddy * cxgb_up - enable the adapter 16930462d115SRahul Lakkireddy * @adap: adapter being enabled 16940462d115SRahul Lakkireddy * 16950462d115SRahul Lakkireddy * Called when the first port is enabled, this function performs the 16960462d115SRahul Lakkireddy * actions necessary to make an adapter operational, such as completing 16970462d115SRahul Lakkireddy * the initialization of HW modules, and enabling interrupts. 16980462d115SRahul Lakkireddy */ 16990462d115SRahul Lakkireddy int cxgbe_up(struct adapter *adap) 17000462d115SRahul Lakkireddy { 1701d87ba24dSRahul Lakkireddy enable_rx(adap, &adap->sge.fw_evtq); 17020462d115SRahul Lakkireddy t4_sge_tx_monitor_start(adap); 17035e80364aSKumar Sanghvi if (is_pf4(adap)) 17040462d115SRahul Lakkireddy t4_intr_enable(adap); 17050462d115SRahul Lakkireddy adap->flags |= FULL_INIT_DONE; 17060462d115SRahul Lakkireddy 17070462d115SRahul Lakkireddy /* TODO: deadman watchdog ?? */ 17080462d115SRahul Lakkireddy return 0; 17090462d115SRahul Lakkireddy } 17100462d115SRahul Lakkireddy 17110462d115SRahul Lakkireddy /* 17120462d115SRahul Lakkireddy * Close the port 17130462d115SRahul Lakkireddy */ 17140462d115SRahul Lakkireddy int cxgbe_down(struct port_info *pi) 17150462d115SRahul Lakkireddy { 1716265af08eSRahul Lakkireddy return cxgbe_set_link_status(pi, false); 17170462d115SRahul Lakkireddy } 17180462d115SRahul Lakkireddy 17190462d115SRahul Lakkireddy /* 17200462d115SRahul Lakkireddy * Release resources when all the ports have been stopped. 17210462d115SRahul Lakkireddy */ 17220462d115SRahul Lakkireddy void cxgbe_close(struct adapter *adapter) 17230462d115SRahul Lakkireddy { 17240462d115SRahul Lakkireddy struct port_info *pi; 17250462d115SRahul Lakkireddy int i; 17260462d115SRahul Lakkireddy 17270462d115SRahul Lakkireddy if (adapter->flags & FULL_INIT_DONE) { 17286f2a064bSShagun Agrawal tid_free(&adapter->tids); 17296fda3f0dSShagun Agrawal t4_cleanup_mpstcam(adapter); 17303f2c1e20SShagun Agrawal t4_cleanup_clip_tbl(adapter); 173123af667fSShagun Agrawal t4_cleanup_l2t(adapter); 173223af667fSShagun Agrawal if (is_pf4(adapter)) 173323af667fSShagun Agrawal t4_intr_disable(adapter); 17340462d115SRahul Lakkireddy t4_sge_tx_monitor_stop(adapter); 17350462d115SRahul Lakkireddy t4_free_sge_resources(adapter); 17360462d115SRahul Lakkireddy for_each_port(adapter, i) { 17370462d115SRahul Lakkireddy pi = adap2pinfo(adapter, i); 17380462d115SRahul Lakkireddy if (pi->viid != 0) 17390462d115SRahul Lakkireddy t4_free_vi(adapter, adapter->mbox, 17400462d115SRahul Lakkireddy adapter->pf, 0, pi->viid); 17412195df6dSRahul Lakkireddy rte_eth_dev_release_port(pi->eth_dev); 17422195df6dSRahul Lakkireddy } 17430462d115SRahul Lakkireddy adapter->flags &= ~FULL_INIT_DONE; 17440462d115SRahul Lakkireddy } 17450462d115SRahul Lakkireddy 17465e80364aSKumar Sanghvi if (is_pf4(adapter) && (adapter->flags & FW_OK)) 17470462d115SRahul Lakkireddy t4_fw_bye(adapter, adapter->mbox); 17480462d115SRahul Lakkireddy } 17490462d115SRahul Lakkireddy 175083189849SRahul Lakkireddy int cxgbe_probe(struct adapter *adapter) 175183189849SRahul Lakkireddy { 175283189849SRahul Lakkireddy struct port_info *pi; 175304868e5bSRahul Lakkireddy int chip; 175483189849SRahul Lakkireddy int func, i; 175583189849SRahul Lakkireddy int err = 0; 175604868e5bSRahul Lakkireddy u32 whoami; 175783189849SRahul Lakkireddy 175804868e5bSRahul Lakkireddy whoami = t4_read_reg(adapter, A_PL_WHOAMI); 175904868e5bSRahul Lakkireddy chip = t4_get_chip_type(adapter, 176004868e5bSRahul Lakkireddy CHELSIO_PCI_ID_VER(adapter->pdev->id.device_id)); 176104868e5bSRahul Lakkireddy if (chip < 0) 176204868e5bSRahul Lakkireddy return chip; 176304868e5bSRahul Lakkireddy 176404868e5bSRahul Lakkireddy func = CHELSIO_CHIP_VERSION(chip) <= CHELSIO_T5 ? 176504868e5bSRahul Lakkireddy G_SOURCEPF(whoami) : G_T6_SOURCEPF(whoami); 176604868e5bSRahul Lakkireddy 176783189849SRahul Lakkireddy adapter->mbox = func; 176883189849SRahul Lakkireddy adapter->pf = func; 176983189849SRahul Lakkireddy 177083189849SRahul Lakkireddy t4_os_lock_init(&adapter->mbox_lock); 177183189849SRahul Lakkireddy TAILQ_INIT(&adapter->mbox_list); 17728d3c12e1SShagun Agrawal t4_os_lock_init(&adapter->win0_lock); 177383189849SRahul Lakkireddy 177483189849SRahul Lakkireddy err = t4_prep_adapter(adapter); 177583189849SRahul Lakkireddy if (err) 177683189849SRahul Lakkireddy return err; 177783189849SRahul Lakkireddy 177883189849SRahul Lakkireddy setup_memwin(adapter); 177983189849SRahul Lakkireddy err = adap_init0(adapter); 178083189849SRahul Lakkireddy if (err) { 178183189849SRahul Lakkireddy dev_err(adapter, "%s: Adapter initialization failed, error %d\n", 178283189849SRahul Lakkireddy __func__, err); 178383189849SRahul Lakkireddy goto out_free; 178483189849SRahul Lakkireddy } 178583189849SRahul Lakkireddy 178683189849SRahul Lakkireddy if (!is_t4(adapter->params.chip)) { 178783189849SRahul Lakkireddy /* 178883189849SRahul Lakkireddy * The userspace doorbell BAR is split evenly into doorbell 178983189849SRahul Lakkireddy * regions, each associated with an egress queue. If this 179083189849SRahul Lakkireddy * per-queue region is large enough (at least UDBS_SEG_SIZE) 179183189849SRahul Lakkireddy * then it can be used to submit a tx work request with an 179283189849SRahul Lakkireddy * implied doorbell. Enable write combining on the BAR if 179383189849SRahul Lakkireddy * there is room for such work requests. 179483189849SRahul Lakkireddy */ 179583189849SRahul Lakkireddy int s_qpp, qpp, num_seg; 179683189849SRahul Lakkireddy 179783189849SRahul Lakkireddy s_qpp = (S_QUEUESPERPAGEPF0 + 179883189849SRahul Lakkireddy (S_QUEUESPERPAGEPF1 - S_QUEUESPERPAGEPF0) * 179983189849SRahul Lakkireddy adapter->pf); 180083189849SRahul Lakkireddy qpp = 1 << ((t4_read_reg(adapter, 180183189849SRahul Lakkireddy A_SGE_EGRESS_QUEUES_PER_PAGE_PF) >> s_qpp) 180283189849SRahul Lakkireddy & M_QUEUESPERPAGEPF0); 18031f8613f1SRahul Lakkireddy num_seg = CXGBE_PAGE_SIZE / UDBS_SEG_SIZE; 180483189849SRahul Lakkireddy if (qpp > num_seg) 180583189849SRahul Lakkireddy dev_warn(adapter, "Incorrect SGE EGRESS QUEUES_PER_PAGE configuration, continuing in debug mode\n"); 180683189849SRahul Lakkireddy 180783189849SRahul Lakkireddy adapter->bar2 = (void *)adapter->pdev->mem_resource[2].addr; 180883189849SRahul Lakkireddy if (!adapter->bar2) { 180983189849SRahul Lakkireddy dev_err(adapter, "cannot map device bar2 region\n"); 181083189849SRahul Lakkireddy err = -ENOMEM; 181183189849SRahul Lakkireddy goto out_free; 181283189849SRahul Lakkireddy } 181383189849SRahul Lakkireddy t4_write_reg(adapter, A_SGE_STAT_CFG, V_STATSOURCE_T5(7) | 181483189849SRahul Lakkireddy V_STATMODE(0)); 181583189849SRahul Lakkireddy } 181683189849SRahul Lakkireddy 181783189849SRahul Lakkireddy for_each_port(adapter, i) { 181883189849SRahul Lakkireddy const unsigned int numa_node = rte_socket_id(); 18192195df6dSRahul Lakkireddy char name[RTE_ETH_NAME_MAX_LEN]; 18202195df6dSRahul Lakkireddy struct rte_eth_dev *eth_dev; 182183189849SRahul Lakkireddy 18222195df6dSRahul Lakkireddy snprintf(name, sizeof(name), "%s_%d", 18232195df6dSRahul Lakkireddy adapter->pdev->device.name, i); 182483189849SRahul Lakkireddy 182583189849SRahul Lakkireddy if (i == 0) { 182683189849SRahul Lakkireddy /* First port is already allocated by DPDK */ 18272195df6dSRahul Lakkireddy eth_dev = adapter->eth_dev; 182883189849SRahul Lakkireddy goto allocate_mac; 182983189849SRahul Lakkireddy } 183083189849SRahul Lakkireddy 183183189849SRahul Lakkireddy /* 183283189849SRahul Lakkireddy * now do all data allocation - for eth_dev structure, 183383189849SRahul Lakkireddy * and internal (private) data for the remaining ports 183483189849SRahul Lakkireddy */ 183583189849SRahul Lakkireddy 183683189849SRahul Lakkireddy /* reserve an ethdev entry */ 18372195df6dSRahul Lakkireddy eth_dev = rte_eth_dev_allocate(name); 18382195df6dSRahul Lakkireddy if (!eth_dev) 183983189849SRahul Lakkireddy goto out_free; 184083189849SRahul Lakkireddy 18412195df6dSRahul Lakkireddy eth_dev->data->dev_private = 18422195df6dSRahul Lakkireddy rte_zmalloc_socket(name, sizeof(struct port_info), 18432195df6dSRahul Lakkireddy RTE_CACHE_LINE_SIZE, numa_node); 18442195df6dSRahul Lakkireddy if (!eth_dev->data->dev_private) 184583189849SRahul Lakkireddy goto out_free; 184683189849SRahul Lakkireddy 184783189849SRahul Lakkireddy allocate_mac: 184863a97e58SStephen Hemminger pi = eth_dev->data->dev_private; 18492195df6dSRahul Lakkireddy adapter->port[i] = pi; 18502195df6dSRahul Lakkireddy pi->eth_dev = eth_dev; 18512195df6dSRahul Lakkireddy pi->adapter = adapter; 18522195df6dSRahul Lakkireddy pi->xact_addr_filt = -1; 18532195df6dSRahul Lakkireddy pi->port_id = i; 18545e80364aSKumar Sanghvi pi->pidx = i; 18552195df6dSRahul Lakkireddy 1856eac901ceSJan Blunck pi->eth_dev->device = &adapter->pdev->device; 185783189849SRahul Lakkireddy pi->eth_dev->dev_ops = adapter->eth_dev->dev_ops; 18584a01078bSRahul Lakkireddy pi->eth_dev->tx_pkt_burst = adapter->eth_dev->tx_pkt_burst; 185992c8a632SRahul Lakkireddy pi->eth_dev->rx_pkt_burst = adapter->eth_dev->rx_pkt_burst; 186013b0f500SRahul Lakkireddy 1861eac901ceSJan Blunck rte_eth_copy_pci_info(pi->eth_dev, adapter->pdev); 186213b0f500SRahul Lakkireddy 186383189849SRahul Lakkireddy pi->eth_dev->data->mac_addrs = rte_zmalloc(name, 186435b2d13fSOlivier Matz RTE_ETHER_ADDR_LEN, 0); 186583189849SRahul Lakkireddy if (!pi->eth_dev->data->mac_addrs) { 186683189849SRahul Lakkireddy dev_err(adapter, "%s: Mem allocation failed for storing mac addr, aborting\n", 186783189849SRahul Lakkireddy __func__); 186883189849SRahul Lakkireddy err = -1; 186983189849SRahul Lakkireddy goto out_free; 187083189849SRahul Lakkireddy } 1871fbe90cddSThomas Monjalon 1872fbe90cddSThomas Monjalon if (i > 0) { 1873fbe90cddSThomas Monjalon /* First port will be notified by upper layer */ 1874fbe90cddSThomas Monjalon rte_eth_dev_probing_finish(eth_dev); 1875fbe90cddSThomas Monjalon } 187683189849SRahul Lakkireddy } 187783189849SRahul Lakkireddy 187883189849SRahul Lakkireddy if (adapter->flags & FW_OK) { 187983189849SRahul Lakkireddy err = t4_port_init(adapter, adapter->mbox, adapter->pf, 0); 188083189849SRahul Lakkireddy if (err) { 188183189849SRahul Lakkireddy dev_err(adapter, "%s: t4_port_init failed with err %d\n", 188283189849SRahul Lakkireddy __func__, err); 188383189849SRahul Lakkireddy goto out_free; 188483189849SRahul Lakkireddy } 188583189849SRahul Lakkireddy } 188683189849SRahul Lakkireddy 1887b7fd9ea8SStephen Hemminger cxgbe_cfg_queues(adapter->eth_dev); 188892c8a632SRahul Lakkireddy 1889b7fd9ea8SStephen Hemminger cxgbe_print_adapter_info(adapter); 1890b7fd9ea8SStephen Hemminger cxgbe_print_port_info(adapter); 189183189849SRahul Lakkireddy 18923f2c1e20SShagun Agrawal adapter->clipt = t4_init_clip_tbl(adapter->clipt_start, 18933f2c1e20SShagun Agrawal adapter->clipt_end); 18943f2c1e20SShagun Agrawal if (!adapter->clipt) { 18953f2c1e20SShagun Agrawal /* We tolerate a lack of clip_table, giving up some 18963f2c1e20SShagun Agrawal * functionality 18973f2c1e20SShagun Agrawal */ 18983f2c1e20SShagun Agrawal dev_warn(adapter, "could not allocate CLIP. Continuing\n"); 18993f2c1e20SShagun Agrawal } 19003f2c1e20SShagun Agrawal 190123af667fSShagun Agrawal adapter->l2t = t4_init_l2t(adapter->l2t_start, adapter->l2t_end); 190223af667fSShagun Agrawal if (!adapter->l2t) { 190323af667fSShagun Agrawal /* We tolerate a lack of L2T, giving up some functionality */ 190423af667fSShagun Agrawal dev_warn(adapter, "could not allocate L2T. Continuing\n"); 190523af667fSShagun Agrawal } 190623af667fSShagun Agrawal 19076f2a064bSShagun Agrawal if (tid_init(&adapter->tids) < 0) { 19086f2a064bSShagun Agrawal /* Disable filtering support */ 19096f2a064bSShagun Agrawal dev_warn(adapter, "could not allocate TID table, " 19106f2a064bSShagun Agrawal "filter support disabled. Continuing\n"); 19116f2a064bSShagun Agrawal } 19126f2a064bSShagun Agrawal 19136fda3f0dSShagun Agrawal adapter->mpstcam = t4_init_mpstcam(adapter); 19146fda3f0dSShagun Agrawal if (!adapter->mpstcam) 19156fda3f0dSShagun Agrawal dev_warn(adapter, "could not allocate mps tcam table." 19166fda3f0dSShagun Agrawal " Continuing\n"); 19176fda3f0dSShagun Agrawal 19183a381a41SShagun Agrawal if (is_hashfilter(adapter)) { 19193a381a41SShagun Agrawal if (t4_read_reg(adapter, A_LE_DB_CONFIG) & F_HASHEN) { 19203a381a41SShagun Agrawal u32 hash_base, hash_reg; 19213a381a41SShagun Agrawal 19223a381a41SShagun Agrawal hash_reg = A_LE_DB_TID_HASHBASE; 19233a381a41SShagun Agrawal hash_base = t4_read_reg(adapter, hash_reg); 19243a381a41SShagun Agrawal adapter->tids.hash_base = hash_base / 4; 19253a381a41SShagun Agrawal } 19263a381a41SShagun Agrawal } else { 19273a381a41SShagun Agrawal /* Disable hash filtering support */ 19283a381a41SShagun Agrawal dev_warn(adapter, 19293a381a41SShagun Agrawal "Maskless filter support disabled. Continuing\n"); 19303a381a41SShagun Agrawal } 19313a381a41SShagun Agrawal 1932b7fd9ea8SStephen Hemminger err = cxgbe_init_rss(adapter); 193392c8a632SRahul Lakkireddy if (err) 193492c8a632SRahul Lakkireddy goto out_free; 193592c8a632SRahul Lakkireddy 193683189849SRahul Lakkireddy return 0; 193783189849SRahul Lakkireddy 193883189849SRahul Lakkireddy out_free: 193983189849SRahul Lakkireddy for_each_port(adapter, i) { 194083189849SRahul Lakkireddy pi = adap2pinfo(adapter, i); 194183189849SRahul Lakkireddy if (pi->viid != 0) 194283189849SRahul Lakkireddy t4_free_vi(adapter, adapter->mbox, adapter->pf, 194383189849SRahul Lakkireddy 0, pi->viid); 19442195df6dSRahul Lakkireddy rte_eth_dev_release_port(pi->eth_dev); 19452195df6dSRahul Lakkireddy } 194683189849SRahul Lakkireddy 194783189849SRahul Lakkireddy if (adapter->flags & FW_OK) 194883189849SRahul Lakkireddy t4_fw_bye(adapter, adapter->mbox); 194983189849SRahul Lakkireddy return -err; 195083189849SRahul Lakkireddy } 1951