1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2014-2018 Chelsio Communications.
14 #include <netinet/in.h>
16 #include <rte_byteorder.h>
17 #include <rte_common.h>
18 #include <rte_cycles.h>
19 #include <rte_interrupts.h>
21 #include <rte_debug.h>
23 #include <rte_atomic.h>
24 #include <rte_branch_prediction.h>
25 #include <rte_memory.h>
26 #include <rte_tailq.h>
28 #include <rte_alarm.h>
29 #include <rte_ether.h>
30 #include <rte_ethdev_driver.h>
31 #include <rte_ethdev_pci.h>
32 #include <rte_random.h>
34 #include <rte_kvargs.h>
43 * Allocate a chunk of memory. The allocated memory is cleared.
45 void *t4_alloc_mem(size_t size)
47 return rte_zmalloc(NULL, size, 0);
51 * Free memory allocated through t4_alloc_mem().
53 void t4_free_mem(void *addr)
59 * Response queue handler for the FW event queue.
61 static int fwevtq_handler(struct sge_rspq *q, const __be64 *rsp,
62 __rte_unused const struct pkt_gl *gl)
64 u8 opcode = ((const struct rss_header *)rsp)->opcode;
66 rsp++; /* skip RSS header */
69 * FW can send EGR_UPDATEs encapsulated in a CPL_FW4_MSG.
71 if (unlikely(opcode == CPL_FW4_MSG &&
72 ((const struct cpl_fw4_msg *)rsp)->type ==
75 opcode = ((const struct rss_header *)rsp)->opcode;
77 if (opcode != CPL_SGE_EGR_UPDATE) {
78 dev_err(q->adapter, "unexpected FW4/CPL %#x on FW event queue\n",
84 if (likely(opcode == CPL_SGE_EGR_UPDATE)) {
86 } else if (opcode == CPL_FW6_MSG || opcode == CPL_FW4_MSG) {
87 const struct cpl_fw6_msg *msg = (const void *)rsp;
89 t4_handle_fw_rpl(q->adapter, msg->data);
90 } else if (opcode == CPL_ABORT_RPL_RSS) {
91 const struct cpl_abort_rpl_rss *p = (const void *)rsp;
93 hash_del_filter_rpl(q->adapter, p);
94 } else if (opcode == CPL_SET_TCB_RPL) {
95 const struct cpl_set_tcb_rpl *p = (const void *)rsp;
97 filter_rpl(q->adapter, p);
98 } else if (opcode == CPL_ACT_OPEN_RPL) {
99 const struct cpl_act_open_rpl *p = (const void *)rsp;
101 hash_filter_rpl(q->adapter, p);
103 dev_err(adapter, "unexpected CPL %#x on FW event queue\n",
111 * Setup sge control queues to pass control information.
113 int setup_sge_ctrl_txq(struct adapter *adapter)
115 struct sge *s = &adapter->sge;
118 for_each_port(adapter, i) {
119 char name[RTE_ETH_NAME_MAX_LEN];
120 struct sge_ctrl_txq *q = &s->ctrlq[i];
123 err = t4_sge_alloc_ctrl_txq(adapter, q,
128 dev_err(adapter, "Failed to alloc ctrl txq. Err: %d",
132 snprintf(name, sizeof(name), "cxgbe_ctrl_pool_%d", i);
133 q->mb_pool = rte_pktmbuf_pool_create(name, s->ctrlq[i].q.size,
136 RTE_MBUF_DEFAULT_BUF_SIZE,
139 dev_err(adapter, "Can't create ctrl pool for port: %d",
147 t4_free_sge_resources(adapter);
152 * cxgbe_poll_for_completion: Poll rxq for completion
154 * @us: microseconds to delay
155 * @cnt: number of times to poll
156 * @c: completion to check for 'done' status
158 * Polls the rxq for reples until completion is done or the count
161 int cxgbe_poll_for_completion(struct sge_rspq *q, unsigned int us,
162 unsigned int cnt, struct t4_completion *c)
165 unsigned int work_done, budget = 4;
170 for (i = 0; i < cnt; i++) {
171 cxgbe_poll(q, NULL, budget, &work_done);
172 t4_os_lock(&c->lock);
174 t4_os_unlock(&c->lock);
177 t4_os_unlock(&c->lock);
183 int setup_sge_fwevtq(struct adapter *adapter)
185 struct sge *s = &adapter->sge;
189 err = t4_sge_alloc_rxq(adapter, &s->fw_evtq, true, adapter->eth_dev,
190 msi_idx, NULL, fwevtq_handler, -1, NULL, 0,
195 static int closest_timer(const struct sge *s, int time)
197 unsigned int i, match = 0;
198 int delta, min_delta = INT_MAX;
200 for (i = 0; i < ARRAY_SIZE(s->timer_val); i++) {
201 delta = time - s->timer_val[i];
204 if (delta < min_delta) {
212 static int closest_thres(const struct sge *s, int thres)
214 unsigned int i, match = 0;
215 int delta, min_delta = INT_MAX;
217 for (i = 0; i < ARRAY_SIZE(s->counter_val); i++) {
218 delta = thres - s->counter_val[i];
221 if (delta < min_delta) {
230 * cxgb4_set_rspq_intr_params - set a queue's interrupt holdoff parameters
232 * @us: the hold-off time in us, or 0 to disable timer
233 * @cnt: the hold-off packet count, or 0 to disable counter
235 * Sets an Rx queue's interrupt hold-off time and packet count. At least
236 * one of the two needs to be enabled for the queue to generate interrupts.
238 int cxgb4_set_rspq_intr_params(struct sge_rspq *q, unsigned int us,
241 struct adapter *adap = q->adapter;
242 unsigned int timer_val;
248 new_idx = closest_thres(&adap->sge, cnt);
249 if (q->desc && q->pktcnt_idx != new_idx) {
250 /* the queue has already been created, update it */
251 v = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DMAQ) |
253 FW_PARAMS_PARAM_DMAQ_IQ_INTCNTTHRESH) |
254 V_FW_PARAMS_PARAM_YZ(q->cntxt_id);
255 err = t4_set_params(adap, adap->mbox, adap->pf, 0, 1,
260 q->pktcnt_idx = new_idx;
263 timer_val = (us == 0) ? X_TIMERREG_RESTART_COUNTER :
264 closest_timer(&adap->sge, us);
267 q->intr_params = V_QINTR_TIMER_IDX(X_TIMERREG_UPDATE_CIDX);
269 q->intr_params = V_QINTR_TIMER_IDX(timer_val) |
270 V_QINTR_CNT_EN(cnt > 0);
275 * Allocate an active-open TID and set it to the supplied value.
277 int cxgbe_alloc_atid(struct tid_info *t, void *data)
281 t4_os_lock(&t->atid_lock);
283 union aopen_entry *p = t->afree;
285 atid = p - t->atid_tab;
290 t4_os_unlock(&t->atid_lock);
295 * Release an active-open TID.
297 void cxgbe_free_atid(struct tid_info *t, unsigned int atid)
299 union aopen_entry *p = &t->atid_tab[atid];
301 t4_os_lock(&t->atid_lock);
305 t4_os_unlock(&t->atid_lock);
309 * Populate a TID_RELEASE WR. Caller must properly size the skb.
311 static void mk_tid_release(struct rte_mbuf *mbuf, unsigned int tid)
313 struct cpl_tid_release *req;
315 req = rte_pktmbuf_mtod(mbuf, struct cpl_tid_release *);
316 INIT_TP_WR_MIT_CPL(req, CPL_TID_RELEASE, tid);
320 * Release a TID and inform HW. If we are unable to allocate the release
321 * message we defer to a work queue.
323 void cxgbe_remove_tid(struct tid_info *t, unsigned int chan, unsigned int tid,
324 unsigned short family)
326 struct rte_mbuf *mbuf;
327 struct adapter *adap = container_of(t, struct adapter, tids);
329 WARN_ON(tid >= t->ntids);
331 if (t->tid_tab[tid]) {
332 t->tid_tab[tid] = NULL;
333 rte_atomic32_dec(&t->conns_in_use);
334 if (t->hash_base && tid >= t->hash_base) {
335 if (family == FILTER_TYPE_IPV4)
336 rte_atomic32_dec(&t->hash_tids_in_use);
338 if (family == FILTER_TYPE_IPV4)
339 rte_atomic32_dec(&t->tids_in_use);
343 mbuf = rte_pktmbuf_alloc((&adap->sge.ctrlq[chan])->mb_pool);
345 mbuf->data_len = sizeof(struct cpl_tid_release);
346 mbuf->pkt_len = mbuf->data_len;
347 mk_tid_release(mbuf, tid);
348 t4_mgmt_tx(&adap->sge.ctrlq[chan], mbuf);
355 void cxgbe_insert_tid(struct tid_info *t, void *data, unsigned int tid,
356 unsigned short family)
358 t->tid_tab[tid] = data;
359 if (t->hash_base && tid >= t->hash_base) {
360 if (family == FILTER_TYPE_IPV4)
361 rte_atomic32_inc(&t->hash_tids_in_use);
363 if (family == FILTER_TYPE_IPV4)
364 rte_atomic32_inc(&t->tids_in_use);
367 rte_atomic32_inc(&t->conns_in_use);
373 static void tid_free(struct tid_info *t)
377 rte_bitmap_free(t->ftid_bmap);
379 if (t->ftid_bmap_array)
380 t4_os_free(t->ftid_bmap_array);
382 t4_os_free(t->tid_tab);
385 memset(t, 0, sizeof(struct tid_info));
389 * Allocate and initialize the TID tables. Returns 0 on success.
391 static int tid_init(struct tid_info *t)
394 unsigned int ftid_bmap_size;
395 unsigned int natids = t->natids;
396 unsigned int max_ftids = t->nftids;
398 ftid_bmap_size = rte_bitmap_get_memory_footprint(t->nftids);
399 size = t->ntids * sizeof(*t->tid_tab) +
400 max_ftids * sizeof(*t->ftid_tab) +
401 natids * sizeof(*t->atid_tab);
403 t->tid_tab = t4_os_alloc(size);
407 t->atid_tab = (union aopen_entry *)&t->tid_tab[t->ntids];
408 t->ftid_tab = (struct filter_entry *)&t->tid_tab[t->natids];
409 t->ftid_bmap_array = t4_os_alloc(ftid_bmap_size);
410 if (!t->ftid_bmap_array) {
415 t4_os_lock_init(&t->atid_lock);
416 t4_os_lock_init(&t->ftid_lock);
420 rte_atomic32_init(&t->tids_in_use);
421 rte_atomic32_set(&t->tids_in_use, 0);
422 rte_atomic32_init(&t->conns_in_use);
423 rte_atomic32_set(&t->conns_in_use, 0);
425 /* Setup the free list for atid_tab and clear the stid bitmap. */
428 t->atid_tab[natids - 1].next = &t->atid_tab[natids];
429 t->afree = t->atid_tab;
432 t->ftid_bmap = rte_bitmap_init(t->nftids, t->ftid_bmap_array,
442 static inline bool is_x_1g_port(const struct link_config *lc)
444 return (lc->pcaps & FW_PORT_CAP32_SPEED_1G) != 0;
447 static inline bool is_x_10g_port(const struct link_config *lc)
449 unsigned int speeds, high_speeds;
451 speeds = V_FW_PORT_CAP32_SPEED(G_FW_PORT_CAP32_SPEED(lc->pcaps));
452 high_speeds = speeds &
453 ~(FW_PORT_CAP32_SPEED_100M | FW_PORT_CAP32_SPEED_1G);
455 return high_speeds != 0;
458 inline void init_rspq(struct adapter *adap, struct sge_rspq *q,
459 unsigned int us, unsigned int cnt,
460 unsigned int size, unsigned int iqe_size)
463 cxgb4_set_rspq_intr_params(q, us, cnt);
464 q->iqe_len = iqe_size;
468 int cfg_queue_count(struct rte_eth_dev *eth_dev)
470 struct port_info *pi = (struct port_info *)(eth_dev->data->dev_private);
471 struct adapter *adap = pi->adapter;
472 struct sge *s = &adap->sge;
473 unsigned int max_queues = s->max_ethqsets / adap->params.nports;
475 if ((eth_dev->data->nb_rx_queues < 1) ||
476 (eth_dev->data->nb_tx_queues < 1))
479 if ((eth_dev->data->nb_rx_queues > max_queues) ||
480 (eth_dev->data->nb_tx_queues > max_queues))
483 if (eth_dev->data->nb_rx_queues > pi->rss_size)
486 /* We must configure RSS, since config has changed*/
487 pi->flags &= ~PORT_RSS_DONE;
489 pi->n_rx_qsets = eth_dev->data->nb_rx_queues;
490 pi->n_tx_qsets = eth_dev->data->nb_tx_queues;
495 void cfg_queues(struct rte_eth_dev *eth_dev)
497 struct rte_config *config = rte_eal_get_configuration();
498 struct port_info *pi = (struct port_info *)(eth_dev->data->dev_private);
499 struct adapter *adap = pi->adapter;
500 struct sge *s = &adap->sge;
501 unsigned int i, nb_ports = 0, qidx = 0;
502 unsigned int q_per_port = 0;
504 if (!(adap->flags & CFG_QUEUES)) {
505 for_each_port(adap, i) {
506 struct port_info *tpi = adap2pinfo(adap, i);
508 nb_ports += (is_x_10g_port(&tpi->link_cfg)) ||
509 is_x_1g_port(&tpi->link_cfg) ? 1 : 0;
513 * We default up to # of cores queues per 1G/10G port.
516 q_per_port = (s->max_ethqsets -
517 (adap->params.nports - nb_ports)) /
520 if (q_per_port > config->lcore_count)
521 q_per_port = config->lcore_count;
523 for_each_port(adap, i) {
524 struct port_info *pi = adap2pinfo(adap, i);
526 pi->first_qset = qidx;
528 /* Initially n_rx_qsets == n_tx_qsets */
529 pi->n_rx_qsets = (is_x_10g_port(&pi->link_cfg) ||
530 is_x_1g_port(&pi->link_cfg)) ?
532 pi->n_tx_qsets = pi->n_rx_qsets;
534 if (pi->n_rx_qsets > pi->rss_size)
535 pi->n_rx_qsets = pi->rss_size;
537 qidx += pi->n_rx_qsets;
540 for (i = 0; i < ARRAY_SIZE(s->ethrxq); i++) {
541 struct sge_eth_rxq *r = &s->ethrxq[i];
543 init_rspq(adap, &r->rspq, 5, 32, 1024, 64);
545 r->fl.size = (r->usembufs ? 1024 : 72);
548 for (i = 0; i < ARRAY_SIZE(s->ethtxq); i++)
549 s->ethtxq[i].q.size = 1024;
551 init_rspq(adap, &adap->sge.fw_evtq, 0, 0, 1024, 64);
552 adap->flags |= CFG_QUEUES;
556 void cxgbe_stats_get(struct port_info *pi, struct port_stats *stats)
558 t4_get_port_stats_offset(pi->adapter, pi->tx_chan, stats,
562 void cxgbe_stats_reset(struct port_info *pi)
564 t4_clr_port_stats(pi->adapter, pi->tx_chan);
567 static void setup_memwin(struct adapter *adap)
571 /* For T5, only relative offset inside the PCIe BAR is passed */
572 mem_win0_base = MEMWIN0_BASE;
575 * Set up memory window for accessing adapter memory ranges. (Read
576 * back MA register to ensure that changes propagate before we attempt
577 * to use the new values.)
580 PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_BASE_WIN,
582 mem_win0_base | V_BIR(0) |
583 V_WINDOW(ilog2(MEMWIN0_APERTURE) - X_WINDOW_SHIFT));
585 PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_BASE_WIN,
589 int init_rss(struct adapter *adap)
596 err = t4_init_rss_mode(adap, adap->mbox);
601 for_each_port(adap, i) {
602 struct port_info *pi = adap2pinfo(adap, i);
604 pi->rss = rte_zmalloc(NULL, pi->rss_size * sizeof(u16), 0);
608 pi->rss_hf = CXGBE_RSS_HF_ALL;
614 * Dump basic information about the adapter.
616 void print_adapter_info(struct adapter *adap)
619 * Hardware/Firmware/etc. Version/Revision IDs.
621 t4_dump_version_info(adap);
624 void print_port_info(struct adapter *adap)
628 struct rte_pci_addr *loc = &adap->pdev->addr;
630 for_each_port(adap, i) {
631 const struct port_info *pi = adap2pinfo(adap, i);
634 if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_100M)
635 bufp += sprintf(bufp, "100M/");
636 if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_1G)
637 bufp += sprintf(bufp, "1G/");
638 if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_10G)
639 bufp += sprintf(bufp, "10G/");
640 if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_25G)
641 bufp += sprintf(bufp, "25G/");
642 if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_40G)
643 bufp += sprintf(bufp, "40G/");
644 if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_50G)
645 bufp += sprintf(bufp, "50G/");
646 if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_100G)
647 bufp += sprintf(bufp, "100G/");
650 sprintf(bufp, "BASE-%s",
651 t4_get_port_type_description(
652 (enum fw_port_type)pi->port_type));
655 " " PCI_PRI_FMT " Chelsio rev %d %s %s\n",
656 loc->domain, loc->bus, loc->devid, loc->function,
657 CHELSIO_CHIP_RELEASE(adap->params.chip), buf,
658 (adap->flags & USING_MSIX) ? " MSI-X" :
659 (adap->flags & USING_MSI) ? " MSI" : "");
664 check_devargs_handler(__rte_unused const char *key, const char *value,
665 __rte_unused void *opaque)
667 if (strcmp(value, "1"))
673 int cxgbe_get_devargs(struct rte_devargs *devargs, const char *key)
675 struct rte_kvargs *kvlist;
680 kvlist = rte_kvargs_parse(devargs->args, NULL);
684 if (!rte_kvargs_count(kvlist, key)) {
685 rte_kvargs_free(kvlist);
689 if (rte_kvargs_process(kvlist, key,
690 check_devargs_handler, NULL) < 0) {
691 rte_kvargs_free(kvlist);
694 rte_kvargs_free(kvlist);
699 static void configure_vlan_types(struct adapter *adapter)
701 struct rte_pci_device *pdev = adapter->pdev;
704 for_each_port(adapter, i) {
705 /* OVLAN Type 0x88a8 */
706 t4_set_reg_field(adapter, MPS_PORT_RX_OVLAN_REG(i, A_RX_OVLAN0),
707 V_OVLAN_MASK(M_OVLAN_MASK) |
708 V_OVLAN_ETYPE(M_OVLAN_ETYPE),
709 V_OVLAN_MASK(M_OVLAN_MASK) |
710 V_OVLAN_ETYPE(0x88a8));
711 /* OVLAN Type 0x9100 */
712 t4_set_reg_field(adapter, MPS_PORT_RX_OVLAN_REG(i, A_RX_OVLAN1),
713 V_OVLAN_MASK(M_OVLAN_MASK) |
714 V_OVLAN_ETYPE(M_OVLAN_ETYPE),
715 V_OVLAN_MASK(M_OVLAN_MASK) |
716 V_OVLAN_ETYPE(0x9100));
717 /* OVLAN Type 0x8100 */
718 t4_set_reg_field(adapter, MPS_PORT_RX_OVLAN_REG(i, A_RX_OVLAN2),
719 V_OVLAN_MASK(M_OVLAN_MASK) |
720 V_OVLAN_ETYPE(M_OVLAN_ETYPE),
721 V_OVLAN_MASK(M_OVLAN_MASK) |
722 V_OVLAN_ETYPE(0x8100));
725 t4_set_reg_field(adapter, MPS_PORT_RX_IVLAN(i),
726 V_IVLAN_ETYPE(M_IVLAN_ETYPE),
727 V_IVLAN_ETYPE(0x8100));
729 t4_set_reg_field(adapter, MPS_PORT_RX_CTL(i),
730 F_OVLAN_EN0 | F_OVLAN_EN1 |
731 F_OVLAN_EN2 | F_IVLAN_EN,
732 F_OVLAN_EN0 | F_OVLAN_EN1 |
733 F_OVLAN_EN2 | F_IVLAN_EN);
736 if (cxgbe_get_devargs(pdev->device.devargs, CXGBE_DEVARG_KEEP_OVLAN))
737 t4_tp_wr_bits_indirect(adapter, A_TP_INGRESS_CONFIG,
738 V_RM_OVLAN(1), V_RM_OVLAN(0));
741 static void configure_pcie_ext_tag(struct adapter *adapter)
744 int pos = t4_os_find_pci_capability(adapter, PCI_CAP_ID_EXP);
750 t4_os_pci_read_cfg2(adapter, pos + PCI_EXP_DEVCTL, &v);
751 v |= PCI_EXP_DEVCTL_EXT_TAG;
752 t4_os_pci_write_cfg2(adapter, pos + PCI_EXP_DEVCTL, v);
753 if (is_t6(adapter->params.chip)) {
754 t4_set_reg_field(adapter, A_PCIE_CFG2,
755 V_T6_TOTMAXTAG(M_T6_TOTMAXTAG),
757 t4_set_reg_field(adapter, A_PCIE_CMD_CFG,
758 V_T6_MINTAG(M_T6_MINTAG),
761 t4_set_reg_field(adapter, A_PCIE_CFG2,
762 V_TOTMAXTAG(M_TOTMAXTAG),
764 t4_set_reg_field(adapter, A_PCIE_CMD_CFG,
771 /* Figure out how many Queue Sets we can support */
772 void configure_max_ethqsets(struct adapter *adapter)
774 unsigned int ethqsets;
777 * We need to reserve an Ingress Queue for the Asynchronous Firmware
780 * For each Queue Set, we'll need the ability to allocate two Egress
781 * Contexts -- one for the Ingress Queue Free List and one for the TX
784 if (is_pf4(adapter)) {
785 struct pf_resources *pfres = &adapter->params.pfres;
787 ethqsets = pfres->niqflint - 1;
788 if (pfres->neq < ethqsets * 2)
789 ethqsets = pfres->neq / 2;
791 struct vf_resources *vfres = &adapter->params.vfres;
793 ethqsets = vfres->niqflint - 1;
794 if (vfres->nethctrl != ethqsets)
795 ethqsets = min(vfres->nethctrl, ethqsets);
796 if (vfres->neq < ethqsets * 2)
797 ethqsets = vfres->neq / 2;
800 if (ethqsets > MAX_ETH_QSETS)
801 ethqsets = MAX_ETH_QSETS;
802 adapter->sge.max_ethqsets = ethqsets;
806 * Tweak configuration based on system architecture, etc. Most of these have
807 * defaults assigned to them by Firmware Configuration Files (if we're using
808 * them) but need to be explicitly set if we're using hard-coded
809 * initialization. So these are essentially common tweaks/settings for
810 * Configuration Files and hard-coded initialization ...
812 static int adap_init0_tweaks(struct adapter *adapter)
817 * Fix up various Host-Dependent Parameters like Page Size, Cache
818 * Line Size, etc. The firmware default is for a 4KB Page Size and
819 * 64B Cache Line Size ...
821 t4_fixup_host_params_compat(adapter, CXGBE_PAGE_SIZE, L1_CACHE_BYTES,
825 * Keep the chip default offset to deliver Ingress packets into our
826 * DMA buffers to zero
829 t4_set_reg_field(adapter, A_SGE_CONTROL, V_PKTSHIFT(M_PKTSHIFT),
830 V_PKTSHIFT(rx_dma_offset));
832 t4_set_reg_field(adapter, A_SGE_FLM_CFG,
833 V_CREDITCNT(M_CREDITCNT) | M_CREDITCNTPACKING,
834 V_CREDITCNT(3) | V_CREDITCNTPACKING(1));
836 t4_set_reg_field(adapter, A_SGE_INGRESS_RX_THRESHOLD,
837 V_THRESHOLD_3(M_THRESHOLD_3), V_THRESHOLD_3(32U));
839 t4_set_reg_field(adapter, A_SGE_CONTROL2, V_IDMAARBROUNDROBIN(1U),
840 V_IDMAARBROUNDROBIN(1U));
843 * Don't include the "IP Pseudo Header" in CPL_RX_PKT checksums: Linux
844 * adds the pseudo header itself.
846 t4_tp_wr_bits_indirect(adapter, A_TP_INGRESS_CONFIG,
847 F_CSUM_HAS_PSEUDO_HDR, 0);
853 * Attempt to initialize the adapter via a Firmware Configuration File.
855 static int adap_init0_config(struct adapter *adapter, int reset)
857 struct fw_caps_config_cmd caps_cmd;
858 unsigned long mtype = 0, maddr = 0;
859 u32 finiver, finicsum, cfcsum;
861 int config_issued = 0;
863 char config_name[20];
866 * Reset device if necessary.
869 ret = t4_fw_reset(adapter, adapter->mbox,
870 F_PIORSTMODE | F_PIORST);
872 dev_warn(adapter, "Firmware reset failed, error %d\n",
878 cfg_addr = t4_flash_cfg_addr(adapter);
881 dev_warn(adapter, "Finding address for firmware config file in flash failed, error %d\n",
886 strcpy(config_name, "On Flash");
887 mtype = FW_MEMTYPE_CF_FLASH;
891 * Issue a Capability Configuration command to the firmware to get it
892 * to parse the Configuration File. We don't use t4_fw_config_file()
893 * because we want the ability to modify various features after we've
894 * processed the configuration file ...
896 memset(&caps_cmd, 0, sizeof(caps_cmd));
897 caps_cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
898 F_FW_CMD_REQUEST | F_FW_CMD_READ);
899 caps_cmd.cfvalid_to_len16 =
900 cpu_to_be32(F_FW_CAPS_CONFIG_CMD_CFVALID |
901 V_FW_CAPS_CONFIG_CMD_MEMTYPE_CF(mtype) |
902 V_FW_CAPS_CONFIG_CMD_MEMADDR64K_CF(maddr >> 16) |
904 ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd, sizeof(caps_cmd),
907 * If the CAPS_CONFIG failed with an ENOENT (for a Firmware
908 * Configuration File in FLASH), our last gasp effort is to use the
909 * Firmware Configuration File which is embedded in the firmware. A
910 * very few early versions of the firmware didn't have one embedded
911 * but we can ignore those.
913 if (ret == -ENOENT) {
914 dev_info(adapter, "%s: Going for embedded config in firmware..\n",
917 memset(&caps_cmd, 0, sizeof(caps_cmd));
918 caps_cmd.op_to_write =
919 cpu_to_be32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
920 F_FW_CMD_REQUEST | F_FW_CMD_READ);
921 caps_cmd.cfvalid_to_len16 = cpu_to_be32(FW_LEN16(caps_cmd));
922 ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd,
923 sizeof(caps_cmd), &caps_cmd);
924 strcpy(config_name, "Firmware Default");
931 finiver = be32_to_cpu(caps_cmd.finiver);
932 finicsum = be32_to_cpu(caps_cmd.finicsum);
933 cfcsum = be32_to_cpu(caps_cmd.cfcsum);
934 if (finicsum != cfcsum)
935 dev_warn(adapter, "Configuration File checksum mismatch: [fini] csum=%#x, computed csum=%#x\n",
939 * If we're a pure NIC driver then disable all offloading facilities.
940 * This will allow the firmware to optimize aspects of the hardware
941 * configuration which will result in improved performance.
943 caps_cmd.niccaps &= cpu_to_be16(~FW_CAPS_CONFIG_NIC_ETHOFLD);
944 caps_cmd.toecaps = 0;
945 caps_cmd.iscsicaps = 0;
946 caps_cmd.rdmacaps = 0;
947 caps_cmd.fcoecaps = 0;
950 * And now tell the firmware to use the configuration we just loaded.
952 caps_cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
953 F_FW_CMD_REQUEST | F_FW_CMD_WRITE);
954 caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd));
955 ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd, sizeof(caps_cmd),
958 dev_warn(adapter, "Unable to finalize Firmware Capabilities %d\n",
964 * Tweak configuration based on system architecture, etc.
966 ret = adap_init0_tweaks(adapter);
968 dev_warn(adapter, "Unable to do init0-tweaks %d\n", -ret);
973 * And finally tell the firmware to initialize itself using the
974 * parameters from the Configuration File.
976 ret = t4_fw_initialize(adapter, adapter->mbox);
978 dev_warn(adapter, "Initializing Firmware failed, error %d\n",
984 * Return successfully and note that we're operating with parameters
985 * not supplied by the driver, rather than from hard-wired
986 * initialization constants buried in the driver.
989 "Successfully configured using Firmware Configuration File \"%s\", version %#x, computed checksum %#x\n",
990 config_name, finiver, cfcsum);
995 * Something bad happened. Return the error ... (If the "error"
996 * is that there's no Configuration File on the adapter we don't
997 * want to issue a warning since this is fairly common.)
1000 if (config_issued && ret != -ENOENT)
1001 dev_warn(adapter, "\"%s\" configuration file error %d\n",
1004 dev_debug(adapter, "%s: returning ret = %d ..\n", __func__, ret);
1008 static int adap_init0(struct adapter *adap)
1010 struct fw_caps_config_cmd caps_cmd;
1013 enum dev_state state;
1014 u32 params[7], val[7];
1016 int mbox = adap->mbox;
1019 * Contact FW, advertising Master capability.
1021 ret = t4_fw_hello(adap, adap->mbox, adap->mbox, MASTER_MAY, &state);
1023 dev_err(adap, "%s: could not connect to FW, error %d\n",
1028 CXGBE_DEBUG_MBOX(adap, "%s: adap->mbox = %d; ret = %d\n", __func__,
1032 adap->flags |= MASTER_PF;
1034 if (state == DEV_STATE_INIT) {
1036 * Force halt and reset FW because a previous instance may have
1037 * exited abnormally without properly shutting down
1039 ret = t4_fw_halt(adap, adap->mbox, reset);
1041 dev_err(adap, "Failed to halt. Exit.\n");
1045 ret = t4_fw_restart(adap, adap->mbox, reset);
1047 dev_err(adap, "Failed to restart. Exit.\n");
1050 state = (enum dev_state)((unsigned)state & ~DEV_STATE_INIT);
1053 t4_get_version_info(adap);
1055 ret = t4_get_core_clock(adap, &adap->params.vpd);
1057 dev_err(adap, "%s: could not get core clock, error %d\n",
1063 * If the firmware is initialized already (and we're not forcing a
1064 * master initialization), note that we're living with existing
1065 * adapter parameters. Otherwise, it's time to try initializing the
1068 if (state == DEV_STATE_INIT) {
1069 dev_info(adap, "Coming up as %s: Adapter already initialized\n",
1070 adap->flags & MASTER_PF ? "MASTER" : "SLAVE");
1072 dev_info(adap, "Coming up as MASTER: Initializing adapter\n");
1074 ret = adap_init0_config(adap, reset);
1075 if (ret == -ENOENT) {
1077 "No Configuration File present on adapter. Using hard-wired configuration parameters.\n");
1082 dev_err(adap, "could not initialize adapter, error %d\n", -ret);
1086 /* Now that we've successfully configured and initialized the adapter
1087 * (or found it already initialized), we can ask the Firmware what
1088 * resources it has provisioned for us.
1090 ret = t4_get_pfres(adap);
1092 dev_err(adap->pdev_dev,
1093 "Unable to retrieve resource provisioning info\n");
1097 /* Find out what ports are available to us. */
1098 v = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
1099 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_PORTVEC);
1100 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1, &v, &port_vec);
1102 dev_err(adap, "%s: failure in t4_query_params; error = %d\n",
1107 adap->params.nports = hweight32(port_vec);
1108 adap->params.portvec = port_vec;
1110 dev_debug(adap, "%s: adap->params.nports = %u\n", __func__,
1111 adap->params.nports);
1114 * Give the SGE code a chance to pull in anything that it needs ...
1115 * Note that this must be called after we retrieve our VPD parameters
1116 * in order to know how to convert core ticks to seconds, etc.
1118 ret = t4_sge_init(adap);
1120 dev_err(adap, "t4_sge_init failed with error %d\n",
1126 * Grab some of our basic fundamental operating parameters.
1128 #define FW_PARAM_DEV(param) \
1129 (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) | \
1130 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_##param))
1132 #define FW_PARAM_PFVF(param) \
1133 (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_PFVF) | \
1134 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_PFVF_##param) | \
1135 V_FW_PARAMS_PARAM_Y(0) | \
1136 V_FW_PARAMS_PARAM_Z(0))
1138 params[0] = FW_PARAM_PFVF(FILTER_START);
1139 params[1] = FW_PARAM_PFVF(FILTER_END);
1140 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params, val);
1143 adap->tids.ftid_base = val[0];
1144 adap->tids.nftids = val[1] - val[0] + 1;
1146 params[0] = FW_PARAM_PFVF(CLIP_START);
1147 params[1] = FW_PARAM_PFVF(CLIP_END);
1148 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params, val);
1151 adap->clipt_start = val[0];
1152 adap->clipt_end = val[1];
1155 * Get device capabilities so we can determine what resources we need
1158 memset(&caps_cmd, 0, sizeof(caps_cmd));
1159 caps_cmd.op_to_write = htonl(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
1160 F_FW_CMD_REQUEST | F_FW_CMD_READ);
1161 caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd));
1162 ret = t4_wr_mbox(adap, adap->mbox, &caps_cmd, sizeof(caps_cmd),
1167 if ((caps_cmd.niccaps & cpu_to_be16(FW_CAPS_CONFIG_NIC_HASHFILTER)) &&
1168 is_t6(adap->params.chip)) {
1169 if (init_hash_filter(adap) < 0)
1173 /* query tid-related parameters */
1174 params[0] = FW_PARAM_DEV(NTID);
1175 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1,
1179 adap->tids.ntids = val[0];
1180 adap->tids.natids = min(adap->tids.ntids / 2, MAX_ATIDS);
1182 /* If we're running on newer firmware, let it know that we're
1183 * prepared to deal with encapsulated CPL messages. Older
1184 * firmware won't understand this and we'll just get
1185 * unencapsulated messages ...
1187 params[0] = FW_PARAM_PFVF(CPLFW4MSG_ENCAP);
1189 (void)t4_set_params(adap, adap->mbox, adap->pf, 0, 1, params, val);
1192 * Find out whether we're allowed to use the T5+ ULPTX MEMWRITE DSGL
1193 * capability. Earlier versions of the firmware didn't have the
1194 * ULPTX_MEMWRITE_DSGL so we'll interpret a query failure as no
1195 * permission to use ULPTX MEMWRITE DSGL.
1197 if (is_t4(adap->params.chip)) {
1198 adap->params.ulptx_memwrite_dsgl = false;
1200 params[0] = FW_PARAM_DEV(ULPTX_MEMWRITE_DSGL);
1201 ret = t4_query_params(adap, adap->mbox, adap->pf, 0,
1203 adap->params.ulptx_memwrite_dsgl = (ret == 0 && val[0] != 0);
1207 * The MTU/MSS Table is initialized by now, so load their values. If
1208 * we're initializing the adapter, then we'll make any modifications
1209 * we want to the MTU/MSS Table and also initialize the congestion
1212 t4_read_mtu_tbl(adap, adap->params.mtus, NULL);
1213 if (state != DEV_STATE_INIT) {
1217 * The default MTU Table contains values 1492 and 1500.
1218 * However, for TCP, it's better to have two values which are
1219 * a multiple of 8 +/- 4 bytes apart near this popular MTU.
1220 * This allows us to have a TCP Data Payload which is a
1221 * multiple of 8 regardless of what combination of TCP Options
1222 * are in use (always a multiple of 4 bytes) which is
1223 * important for performance reasons. For instance, if no
1224 * options are in use, then we have a 20-byte IP header and a
1225 * 20-byte TCP header. In this case, a 1500-byte MSS would
1226 * result in a TCP Data Payload of 1500 - 40 == 1460 bytes
1227 * which is not a multiple of 8. So using an MSS of 1488 in
1228 * this case results in a TCP Data Payload of 1448 bytes which
1229 * is a multiple of 8. On the other hand, if 12-byte TCP Time
1230 * Stamps have been negotiated, then an MTU of 1500 bytes
1231 * results in a TCP Data Payload of 1448 bytes which, as
1232 * above, is a multiple of 8 bytes ...
1234 for (i = 0; i < NMTUS; i++)
1235 if (adap->params.mtus[i] == 1492) {
1236 adap->params.mtus[i] = 1488;
1240 t4_load_mtus(adap, adap->params.mtus, adap->params.a_wnd,
1241 adap->params.b_wnd);
1243 t4_init_sge_params(adap);
1244 t4_init_tp_params(adap);
1245 configure_pcie_ext_tag(adap);
1246 configure_vlan_types(adap);
1247 configure_max_ethqsets(adap);
1249 adap->params.drv_memwin = MEMWIN_NIC;
1250 adap->flags |= FW_OK;
1251 dev_debug(adap, "%s: returning zero..\n", __func__);
1255 * Something bad happened. If a command timed out or failed with EIO
1256 * FW does not operate within its spec or something catastrophic
1257 * happened to HW/FW, stop issuing commands.
1260 if (ret != -ETIMEDOUT && ret != -EIO)
1261 t4_fw_bye(adap, adap->mbox);
1266 * t4_os_portmod_changed - handle port module changes
1267 * @adap: the adapter associated with the module change
1268 * @port_id: the port index whose module status has changed
1270 * This is the OS-dependent handler for port module changes. It is
1271 * invoked when a port module is removed or inserted for any OS-specific
1274 void t4_os_portmod_changed(const struct adapter *adap, int port_id)
1276 static const char * const mod_str[] = {
1277 NULL, "LR", "SR", "ER", "passive DA", "active DA", "LRM"
1280 const struct port_info *pi = adap2pinfo(adap, port_id);
1282 if (pi->mod_type == FW_PORT_MOD_TYPE_NONE)
1283 dev_info(adap, "Port%d: port module unplugged\n", pi->port_id);
1284 else if (pi->mod_type < ARRAY_SIZE(mod_str))
1285 dev_info(adap, "Port%d: %s port module inserted\n", pi->port_id,
1286 mod_str[pi->mod_type]);
1287 else if (pi->mod_type == FW_PORT_MOD_TYPE_NOTSUPPORTED)
1288 dev_info(adap, "Port%d: unsupported port module inserted\n",
1290 else if (pi->mod_type == FW_PORT_MOD_TYPE_UNKNOWN)
1291 dev_info(adap, "Port%d: unknown port module inserted\n",
1293 else if (pi->mod_type == FW_PORT_MOD_TYPE_ERROR)
1294 dev_info(adap, "Port%d: transceiver module error\n",
1297 dev_info(adap, "Port%d: unknown module type %d inserted\n",
1298 pi->port_id, pi->mod_type);
1301 inline bool force_linkup(struct adapter *adap)
1303 struct rte_pci_device *pdev = adap->pdev;
1306 return false; /* force_linkup not required for pf driver*/
1307 if (!cxgbe_get_devargs(pdev->device.devargs,
1308 CXGBE_DEVARG_FORCE_LINK_UP))
1314 * link_start - enable a port
1315 * @dev: the port to enable
1317 * Performs the MAC and PHY actions needed to enable a port.
1319 int link_start(struct port_info *pi)
1321 struct adapter *adapter = pi->adapter;
1325 mtu = pi->eth_dev->data->dev_conf.rxmode.max_rx_pkt_len -
1326 (ETHER_HDR_LEN + ETHER_CRC_LEN);
1329 * We do not set address filters and promiscuity here, the stack does
1330 * that step explicitly.
1332 ret = t4_set_rxmode(adapter, adapter->mbox, pi->viid, mtu, -1, -1,
1335 ret = t4_change_mac(adapter, adapter->mbox, pi->viid,
1337 (u8 *)&pi->eth_dev->data->mac_addrs[0],
1340 pi->xact_addr_filt = ret;
1344 if (ret == 0 && is_pf4(adapter))
1345 ret = t4_link_l1cfg(adapter, adapter->mbox, pi->tx_chan,
1349 * Enabling a Virtual Interface can result in an interrupt
1350 * during the processing of the VI Enable command and, in some
1351 * paths, result in an attempt to issue another command in the
1352 * interrupt context. Thus, we disable interrupts during the
1353 * course of the VI Enable command ...
1355 ret = t4_enable_vi_params(adapter, adapter->mbox, pi->viid,
1359 if (ret == 0 && force_linkup(adapter))
1360 pi->eth_dev->data->dev_link.link_status = ETH_LINK_UP;
1365 * cxgbe_write_rss_conf - flash the RSS configuration for a given port
1367 * @rss_hf: Hash configuration to apply
1369 int cxgbe_write_rss_conf(const struct port_info *pi, uint64_t rss_hf)
1371 struct adapter *adapter = pi->adapter;
1372 const struct sge_eth_rxq *rxq;
1377 /* Should never be called before setting up sge eth rx queues */
1378 if (!(adapter->flags & FULL_INIT_DONE)) {
1379 dev_err(adap, "%s No RXQs available on port %d\n",
1380 __func__, pi->port_id);
1384 /* Don't allow unsupported hash functions */
1385 if (rss_hf & ~CXGBE_RSS_HF_ALL)
1388 if (rss_hf & CXGBE_RSS_HF_IPV4_MASK)
1389 flags |= F_FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN;
1391 if (rss_hf & ETH_RSS_NONFRAG_IPV4_TCP)
1392 flags |= F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN;
1394 if (rss_hf & ETH_RSS_NONFRAG_IPV4_UDP)
1395 flags |= F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN |
1396 F_FW_RSS_VI_CONFIG_CMD_UDPEN;
1398 if (rss_hf & CXGBE_RSS_HF_IPV6_MASK)
1399 flags |= F_FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN;
1401 if (rss_hf & CXGBE_RSS_HF_TCP_IPV6_MASK)
1402 flags |= F_FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN |
1403 F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN;
1405 if (rss_hf & CXGBE_RSS_HF_UDP_IPV6_MASK)
1406 flags |= F_FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN |
1407 F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN |
1408 F_FW_RSS_VI_CONFIG_CMD_UDPEN;
1410 rxq = &adapter->sge.ethrxq[pi->first_qset];
1411 rss = rxq[0].rspq.abs_id;
1413 /* If Tunnel All Lookup isn't specified in the global RSS
1414 * Configuration, then we need to specify a default Ingress
1415 * Queue for any ingress packets which aren't hashed. We'll
1416 * use our first ingress queue ...
1418 err = t4_config_vi_rss(adapter, adapter->mbox, pi->viid,
1424 * cxgbe_write_rss - write the RSS table for a given port
1426 * @queues: array of queue indices for RSS
1428 * Sets up the portion of the HW RSS table for the port's VI to distribute
1429 * packets to the Rx queues in @queues.
1431 int cxgbe_write_rss(const struct port_info *pi, const u16 *queues)
1435 struct adapter *adapter = pi->adapter;
1436 const struct sge_eth_rxq *rxq;
1438 /* Should never be called before setting up sge eth rx queues */
1439 BUG_ON(!(adapter->flags & FULL_INIT_DONE));
1441 rxq = &adapter->sge.ethrxq[pi->first_qset];
1442 rss = rte_zmalloc(NULL, pi->rss_size * sizeof(u16), 0);
1446 /* map the queue indices to queue ids */
1447 for (i = 0; i < pi->rss_size; i++, queues++)
1448 rss[i] = rxq[*queues].rspq.abs_id;
1450 err = t4_config_rss_range(adapter, adapter->pf, pi->viid, 0,
1451 pi->rss_size, rss, pi->rss_size);
1457 * setup_rss - configure RSS
1458 * @adapter: the adapter
1460 * Sets up RSS to distribute packets to multiple receive queues. We
1461 * configure the RSS CPU lookup table to distribute to the number of HW
1462 * receive queues, and the response queue lookup table to narrow that
1463 * down to the response queues actually configured for each port.
1464 * We always configure the RSS mapping for all ports since the mapping
1465 * table has plenty of entries.
1467 int setup_rss(struct port_info *pi)
1470 struct adapter *adapter = pi->adapter;
1472 dev_debug(adapter, "%s: pi->rss_size = %u; pi->n_rx_qsets = %u\n",
1473 __func__, pi->rss_size, pi->n_rx_qsets);
1475 if (!(pi->flags & PORT_RSS_DONE)) {
1476 if (adapter->flags & FULL_INIT_DONE) {
1477 /* Fill default values with equal distribution */
1478 for (j = 0; j < pi->rss_size; j++)
1479 pi->rss[j] = j % pi->n_rx_qsets;
1481 err = cxgbe_write_rss(pi, pi->rss);
1485 err = cxgbe_write_rss_conf(pi, pi->rss_hf);
1488 pi->flags |= PORT_RSS_DONE;
1495 * Enable NAPI scheduling and interrupt generation for all Rx queues.
1497 static void enable_rx(struct adapter *adap, struct sge_rspq *q)
1499 /* 0-increment GTS to start the timer and enable interrupts */
1500 t4_write_reg(adap, is_pf4(adap) ? MYPF_REG(A_SGE_PF_GTS) :
1501 T4VF_SGE_BASE_ADDR + A_SGE_VF_GTS,
1502 V_SEINTARM(q->intr_params) |
1503 V_INGRESSQID(q->cntxt_id));
1506 void cxgbe_enable_rx_queues(struct port_info *pi)
1508 struct adapter *adap = pi->adapter;
1509 struct sge *s = &adap->sge;
1512 for (i = 0; i < pi->n_rx_qsets; i++)
1513 enable_rx(adap, &s->ethrxq[pi->first_qset + i].rspq);
1517 * fw_caps_to_speed_caps - translate Firmware Port Caps to Speed Caps.
1518 * @port_type: Firmware Port Type
1519 * @fw_caps: Firmware Port Capabilities
1520 * @speed_caps: Device Info Speed Capabilities
1522 * Translate a Firmware Port Capabilities specification to Device Info
1523 * Speed Capabilities.
1525 static void fw_caps_to_speed_caps(enum fw_port_type port_type,
1526 unsigned int fw_caps,
1529 #define SET_SPEED(__speed_name) \
1531 *speed_caps |= ETH_LINK_ ## __speed_name; \
1534 #define FW_CAPS_TO_SPEED(__fw_name) \
1536 if (fw_caps & FW_PORT_CAP32_ ## __fw_name) \
1537 SET_SPEED(__fw_name); \
1540 switch (port_type) {
1541 case FW_PORT_TYPE_BT_SGMII:
1542 case FW_PORT_TYPE_BT_XFI:
1543 case FW_PORT_TYPE_BT_XAUI:
1544 FW_CAPS_TO_SPEED(SPEED_100M);
1545 FW_CAPS_TO_SPEED(SPEED_1G);
1546 FW_CAPS_TO_SPEED(SPEED_10G);
1549 case FW_PORT_TYPE_KX4:
1550 case FW_PORT_TYPE_KX:
1551 case FW_PORT_TYPE_FIBER_XFI:
1552 case FW_PORT_TYPE_FIBER_XAUI:
1553 case FW_PORT_TYPE_SFP:
1554 case FW_PORT_TYPE_QSFP_10G:
1555 case FW_PORT_TYPE_QSA:
1556 FW_CAPS_TO_SPEED(SPEED_1G);
1557 FW_CAPS_TO_SPEED(SPEED_10G);
1560 case FW_PORT_TYPE_KR:
1561 SET_SPEED(SPEED_10G);
1564 case FW_PORT_TYPE_BP_AP:
1565 case FW_PORT_TYPE_BP4_AP:
1566 SET_SPEED(SPEED_1G);
1567 SET_SPEED(SPEED_10G);
1570 case FW_PORT_TYPE_BP40_BA:
1571 case FW_PORT_TYPE_QSFP:
1572 SET_SPEED(SPEED_40G);
1575 case FW_PORT_TYPE_CR_QSFP:
1576 case FW_PORT_TYPE_SFP28:
1577 case FW_PORT_TYPE_KR_SFP28:
1578 FW_CAPS_TO_SPEED(SPEED_1G);
1579 FW_CAPS_TO_SPEED(SPEED_10G);
1580 FW_CAPS_TO_SPEED(SPEED_25G);
1583 case FW_PORT_TYPE_CR2_QSFP:
1584 SET_SPEED(SPEED_50G);
1587 case FW_PORT_TYPE_KR4_100G:
1588 case FW_PORT_TYPE_CR4_QSFP:
1589 FW_CAPS_TO_SPEED(SPEED_25G);
1590 FW_CAPS_TO_SPEED(SPEED_40G);
1591 FW_CAPS_TO_SPEED(SPEED_50G);
1592 FW_CAPS_TO_SPEED(SPEED_100G);
1599 #undef FW_CAPS_TO_SPEED
1604 * cxgbe_get_speed_caps - Fetch supported speed capabilities
1605 * @pi: Underlying port's info
1606 * @speed_caps: Device Info speed capabilities
1608 * Fetch supported speed capabilities of the underlying port.
1610 void cxgbe_get_speed_caps(struct port_info *pi, u32 *speed_caps)
1614 fw_caps_to_speed_caps(pi->port_type, pi->link_cfg.pcaps,
1617 if (!(pi->link_cfg.pcaps & FW_PORT_CAP32_ANEG))
1618 *speed_caps |= ETH_LINK_SPEED_FIXED;
1622 * cxgbe_set_link_status - Set device link up or down.
1623 * @pi: Underlying port's info
1624 * @status: 0 - down, 1 - up
1626 * Set the device link up or down.
1628 int cxgbe_set_link_status(struct port_info *pi, bool status)
1630 struct adapter *adapter = pi->adapter;
1633 err = t4_enable_vi(adapter, adapter->mbox, pi->viid, status, status);
1635 dev_err(adapter, "%s: disable_vi failed: %d\n", __func__, err);
1640 t4_reset_link_config(adapter, pi->pidx);
1646 * cxgb_up - enable the adapter
1647 * @adap: adapter being enabled
1649 * Called when the first port is enabled, this function performs the
1650 * actions necessary to make an adapter operational, such as completing
1651 * the initialization of HW modules, and enabling interrupts.
1653 int cxgbe_up(struct adapter *adap)
1655 enable_rx(adap, &adap->sge.fw_evtq);
1656 t4_sge_tx_monitor_start(adap);
1658 t4_intr_enable(adap);
1659 adap->flags |= FULL_INIT_DONE;
1661 /* TODO: deadman watchdog ?? */
1668 int cxgbe_down(struct port_info *pi)
1670 return cxgbe_set_link_status(pi, false);
1674 * Release resources when all the ports have been stopped.
1676 void cxgbe_close(struct adapter *adapter)
1678 struct port_info *pi;
1681 if (adapter->flags & FULL_INIT_DONE) {
1682 if (is_pf4(adapter))
1683 t4_intr_disable(adapter);
1684 tid_free(&adapter->tids);
1685 t4_cleanup_clip_tbl(adapter);
1686 t4_sge_tx_monitor_stop(adapter);
1687 t4_free_sge_resources(adapter);
1688 for_each_port(adapter, i) {
1689 pi = adap2pinfo(adapter, i);
1691 t4_free_vi(adapter, adapter->mbox,
1692 adapter->pf, 0, pi->viid);
1693 rte_free(pi->eth_dev->data->mac_addrs);
1694 /* Skip first port since it'll be freed by DPDK stack */
1696 rte_free(pi->eth_dev->data->dev_private);
1697 rte_eth_dev_release_port(pi->eth_dev);
1700 adapter->flags &= ~FULL_INIT_DONE;
1703 if (is_pf4(adapter) && (adapter->flags & FW_OK))
1704 t4_fw_bye(adapter, adapter->mbox);
1707 int cxgbe_probe(struct adapter *adapter)
1709 struct port_info *pi;
1715 whoami = t4_read_reg(adapter, A_PL_WHOAMI);
1716 chip = t4_get_chip_type(adapter,
1717 CHELSIO_PCI_ID_VER(adapter->pdev->id.device_id));
1721 func = CHELSIO_CHIP_VERSION(chip) <= CHELSIO_T5 ?
1722 G_SOURCEPF(whoami) : G_T6_SOURCEPF(whoami);
1724 adapter->mbox = func;
1727 t4_os_lock_init(&adapter->mbox_lock);
1728 TAILQ_INIT(&adapter->mbox_list);
1729 t4_os_lock_init(&adapter->win0_lock);
1731 err = t4_prep_adapter(adapter);
1735 setup_memwin(adapter);
1736 err = adap_init0(adapter);
1738 dev_err(adapter, "%s: Adapter initialization failed, error %d\n",
1743 if (!is_t4(adapter->params.chip)) {
1745 * The userspace doorbell BAR is split evenly into doorbell
1746 * regions, each associated with an egress queue. If this
1747 * per-queue region is large enough (at least UDBS_SEG_SIZE)
1748 * then it can be used to submit a tx work request with an
1749 * implied doorbell. Enable write combining on the BAR if
1750 * there is room for such work requests.
1752 int s_qpp, qpp, num_seg;
1754 s_qpp = (S_QUEUESPERPAGEPF0 +
1755 (S_QUEUESPERPAGEPF1 - S_QUEUESPERPAGEPF0) *
1757 qpp = 1 << ((t4_read_reg(adapter,
1758 A_SGE_EGRESS_QUEUES_PER_PAGE_PF) >> s_qpp)
1759 & M_QUEUESPERPAGEPF0);
1760 num_seg = CXGBE_PAGE_SIZE / UDBS_SEG_SIZE;
1762 dev_warn(adapter, "Incorrect SGE EGRESS QUEUES_PER_PAGE configuration, continuing in debug mode\n");
1764 adapter->bar2 = (void *)adapter->pdev->mem_resource[2].addr;
1765 if (!adapter->bar2) {
1766 dev_err(adapter, "cannot map device bar2 region\n");
1770 t4_write_reg(adapter, A_SGE_STAT_CFG, V_STATSOURCE_T5(7) |
1774 for_each_port(adapter, i) {
1775 const unsigned int numa_node = rte_socket_id();
1776 char name[RTE_ETH_NAME_MAX_LEN];
1777 struct rte_eth_dev *eth_dev;
1779 snprintf(name, sizeof(name), "%s_%d",
1780 adapter->pdev->device.name, i);
1783 /* First port is already allocated by DPDK */
1784 eth_dev = adapter->eth_dev;
1789 * now do all data allocation - for eth_dev structure,
1790 * and internal (private) data for the remaining ports
1793 /* reserve an ethdev entry */
1794 eth_dev = rte_eth_dev_allocate(name);
1798 eth_dev->data->dev_private =
1799 rte_zmalloc_socket(name, sizeof(struct port_info),
1800 RTE_CACHE_LINE_SIZE, numa_node);
1801 if (!eth_dev->data->dev_private)
1805 pi = (struct port_info *)eth_dev->data->dev_private;
1806 adapter->port[i] = pi;
1807 pi->eth_dev = eth_dev;
1808 pi->adapter = adapter;
1809 pi->xact_addr_filt = -1;
1813 pi->eth_dev->device = &adapter->pdev->device;
1814 pi->eth_dev->dev_ops = adapter->eth_dev->dev_ops;
1815 pi->eth_dev->tx_pkt_burst = adapter->eth_dev->tx_pkt_burst;
1816 pi->eth_dev->rx_pkt_burst = adapter->eth_dev->rx_pkt_burst;
1818 rte_eth_copy_pci_info(pi->eth_dev, adapter->pdev);
1820 pi->eth_dev->data->mac_addrs = rte_zmalloc(name,
1822 if (!pi->eth_dev->data->mac_addrs) {
1823 dev_err(adapter, "%s: Mem allocation failed for storing mac addr, aborting\n",
1830 /* First port will be notified by upper layer */
1831 rte_eth_dev_probing_finish(eth_dev);
1835 if (adapter->flags & FW_OK) {
1836 err = t4_port_init(adapter, adapter->mbox, adapter->pf, 0);
1838 dev_err(adapter, "%s: t4_port_init failed with err %d\n",
1844 cfg_queues(adapter->eth_dev);
1846 print_adapter_info(adapter);
1847 print_port_info(adapter);
1849 adapter->clipt = t4_init_clip_tbl(adapter->clipt_start,
1850 adapter->clipt_end);
1851 if (!adapter->clipt) {
1852 /* We tolerate a lack of clip_table, giving up some
1855 dev_warn(adapter, "could not allocate CLIP. Continuing\n");
1858 if (tid_init(&adapter->tids) < 0) {
1859 /* Disable filtering support */
1860 dev_warn(adapter, "could not allocate TID table, "
1861 "filter support disabled. Continuing\n");
1864 if (is_hashfilter(adapter)) {
1865 if (t4_read_reg(adapter, A_LE_DB_CONFIG) & F_HASHEN) {
1866 u32 hash_base, hash_reg;
1868 hash_reg = A_LE_DB_TID_HASHBASE;
1869 hash_base = t4_read_reg(adapter, hash_reg);
1870 adapter->tids.hash_base = hash_base / 4;
1873 /* Disable hash filtering support */
1875 "Maskless filter support disabled. Continuing\n");
1878 err = init_rss(adapter);
1885 for_each_port(adapter, i) {
1886 pi = adap2pinfo(adapter, i);
1888 t4_free_vi(adapter, adapter->mbox, adapter->pf,
1890 /* Skip first port since it'll be de-allocated by DPDK */
1894 if (pi->eth_dev->data->dev_private)
1895 rte_free(pi->eth_dev->data->dev_private);
1896 rte_eth_dev_release_port(pi->eth_dev);
1900 if (adapter->flags & FW_OK)
1901 t4_fw_bye(adapter, adapter->mbox);