1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
2 * Copyright(c) 2018-2019 Pensando Systems, Inc. All rights reserved.
5 #include <rte_malloc.h>
6 #include <ethdev_driver.h>
9 #include "ionic_logs.h"
10 #include "ionic_lif.h"
11 #include "ionic_ethdev.h"
12 #include "ionic_rx_filter.h"
13 #include "ionic_rxtx.h"
15 /* queuetype support level */
16 static const uint8_t ionic_qtype_vers[IONIC_QTYPE_MAX] = {
17 [IONIC_QTYPE_ADMINQ] = 0, /* 0 = Base version with CQ support */
18 [IONIC_QTYPE_NOTIFYQ] = 0, /* 0 = Base version */
19 [IONIC_QTYPE_RXQ] = 2, /* 0 = Base version with CQ+SG support
23 [IONIC_QTYPE_TXQ] = 3, /* 0 = Base version with CQ+SG support
24 * 1 = ... with Tx SG version 1
30 static int ionic_lif_addr_add(struct ionic_lif *lif, const uint8_t *addr);
31 static int ionic_lif_addr_del(struct ionic_lif *lif, const uint8_t *addr);
34 ionic_qcq_enable(struct ionic_qcq *qcq)
36 struct ionic_queue *q = &qcq->q;
37 struct ionic_lif *lif = qcq->lif;
38 struct ionic_admin_ctx ctx = {
41 .opcode = IONIC_CMD_Q_CONTROL,
43 .index = rte_cpu_to_le_32(q->index),
44 .oper = IONIC_Q_ENABLE,
48 return ionic_adminq_post_wait(lif, &ctx);
52 ionic_qcq_disable(struct ionic_qcq *qcq)
54 struct ionic_queue *q = &qcq->q;
55 struct ionic_lif *lif = qcq->lif;
56 struct ionic_admin_ctx ctx = {
59 .opcode = IONIC_CMD_Q_CONTROL,
61 .index = rte_cpu_to_le_32(q->index),
62 .oper = IONIC_Q_DISABLE,
66 return ionic_adminq_post_wait(lif, &ctx);
70 ionic_lif_stop(struct ionic_lif *lif)
76 lif->state &= ~IONIC_LIF_F_UP;
78 for (i = 0; i < lif->nrxqcqs; i++) {
79 struct ionic_rx_qcq *rxq = lif->rxqcqs[i];
80 if (rxq->flags & IONIC_QCQ_F_INITED)
81 (void)ionic_dev_rx_queue_stop(lif->eth_dev, i);
84 for (i = 0; i < lif->ntxqcqs; i++) {
85 struct ionic_tx_qcq *txq = lif->txqcqs[i];
86 if (txq->flags & IONIC_QCQ_F_INITED)
87 (void)ionic_dev_tx_queue_stop(lif->eth_dev, i);
92 ionic_lif_reset(struct ionic_lif *lif)
94 struct ionic_dev *idev = &lif->adapter->idev;
99 ionic_dev_cmd_lif_reset(idev);
100 err = ionic_dev_cmd_wait_check(idev, IONIC_DEVCMD_TIMEOUT);
102 IONIC_PRINT(WARNING, "Failed to reset %s", lif->name);
106 ionic_lif_get_abs_stats(const struct ionic_lif *lif, struct rte_eth_stats *stats)
108 struct ionic_lif_stats *ls = &lif->info->stats;
110 uint32_t num_rx_q_counters = RTE_MIN(lif->nrxqcqs, (uint32_t)
111 RTE_ETHDEV_QUEUE_STAT_CNTRS);
112 uint32_t num_tx_q_counters = RTE_MIN(lif->ntxqcqs, (uint32_t)
113 RTE_ETHDEV_QUEUE_STAT_CNTRS);
115 memset(stats, 0, sizeof(*stats));
118 IONIC_PRINT(DEBUG, "Stats on port %u not yet initialized",
125 stats->ipackets = ls->rx_ucast_packets +
126 ls->rx_mcast_packets +
127 ls->rx_bcast_packets;
129 stats->ibytes = ls->rx_ucast_bytes +
133 for (i = 0; i < lif->nrxqcqs; i++) {
134 struct ionic_rx_stats *rx_stats = &lif->rxqcqs[i]->stats;
136 rx_stats->no_cb_arg +
137 rx_stats->bad_cq_status +
143 ls->rx_ucast_drop_packets +
144 ls->rx_mcast_drop_packets +
145 ls->rx_bcast_drop_packets;
150 ls->rx_queue_disabled +
151 ls->rx_desc_fetch_error +
152 ls->rx_desc_data_error;
154 for (i = 0; i < num_rx_q_counters; i++) {
155 struct ionic_rx_stats *rx_stats = &lif->rxqcqs[i]->stats;
156 stats->q_ipackets[i] = rx_stats->packets;
157 stats->q_ibytes[i] = rx_stats->bytes;
159 rx_stats->no_cb_arg +
160 rx_stats->bad_cq_status +
167 stats->opackets = ls->tx_ucast_packets +
168 ls->tx_mcast_packets +
169 ls->tx_bcast_packets;
171 stats->obytes = ls->tx_ucast_bytes +
175 for (i = 0; i < lif->ntxqcqs; i++) {
176 struct ionic_tx_stats *tx_stats = &lif->txqcqs[i]->stats;
177 stats->oerrors += tx_stats->drop;
181 ls->tx_ucast_drop_packets +
182 ls->tx_mcast_drop_packets +
183 ls->tx_bcast_drop_packets;
187 ls->tx_queue_disabled +
188 ls->tx_desc_fetch_error +
189 ls->tx_desc_data_error;
191 for (i = 0; i < num_tx_q_counters; i++) {
192 struct ionic_tx_stats *tx_stats = &lif->txqcqs[i]->stats;
193 stats->q_opackets[i] = tx_stats->packets;
194 stats->q_obytes[i] = tx_stats->bytes;
199 ionic_lif_get_stats(const struct ionic_lif *lif,
200 struct rte_eth_stats *stats)
202 ionic_lif_get_abs_stats(lif, stats);
204 stats->ipackets -= lif->stats_base.ipackets;
205 stats->opackets -= lif->stats_base.opackets;
206 stats->ibytes -= lif->stats_base.ibytes;
207 stats->obytes -= lif->stats_base.obytes;
208 stats->imissed -= lif->stats_base.imissed;
209 stats->ierrors -= lif->stats_base.ierrors;
210 stats->oerrors -= lif->stats_base.oerrors;
211 stats->rx_nombuf -= lif->stats_base.rx_nombuf;
215 ionic_lif_reset_stats(struct ionic_lif *lif)
219 for (i = 0; i < lif->nrxqcqs; i++) {
220 memset(&lif->rxqcqs[i]->stats, 0,
221 sizeof(struct ionic_rx_stats));
222 memset(&lif->txqcqs[i]->stats, 0,
223 sizeof(struct ionic_tx_stats));
226 ionic_lif_get_abs_stats(lif, &lif->stats_base);
230 ionic_lif_get_hw_stats(struct ionic_lif *lif, struct ionic_lif_stats *stats)
232 uint16_t i, count = sizeof(struct ionic_lif_stats) / sizeof(uint64_t);
233 uint64_t *stats64 = (uint64_t *)stats;
234 uint64_t *lif_stats64 = (uint64_t *)&lif->info->stats;
235 uint64_t *lif_stats64_base = (uint64_t *)&lif->lif_stats_base;
237 for (i = 0; i < count; i++)
238 stats64[i] = lif_stats64[i] - lif_stats64_base[i];
242 ionic_lif_reset_hw_stats(struct ionic_lif *lif)
244 uint16_t i, count = sizeof(struct ionic_lif_stats) / sizeof(uint64_t);
245 uint64_t *lif_stats64 = (uint64_t *)&lif->info->stats;
246 uint64_t *lif_stats64_base = (uint64_t *)&lif->lif_stats_base;
248 for (i = 0; i < count; i++)
249 lif_stats64_base[i] = lif_stats64[i];
253 ionic_lif_addr_add(struct ionic_lif *lif, const uint8_t *addr)
255 struct ionic_admin_ctx ctx = {
256 .pending_work = true,
257 .cmd.rx_filter_add = {
258 .opcode = IONIC_CMD_RX_FILTER_ADD,
259 .match = rte_cpu_to_le_16(IONIC_RX_FILTER_MATCH_MAC),
264 memcpy(ctx.cmd.rx_filter_add.mac.addr, addr, RTE_ETHER_ADDR_LEN);
266 err = ionic_adminq_post_wait(lif, &ctx);
270 IONIC_PRINT(INFO, "rx_filter add (id %d)",
271 rte_le_to_cpu_32(ctx.comp.rx_filter_add.filter_id));
273 return ionic_rx_filter_save(lif, 0, IONIC_RXQ_INDEX_ANY, &ctx);
277 ionic_lif_addr_del(struct ionic_lif *lif, const uint8_t *addr)
279 struct ionic_admin_ctx ctx = {
280 .pending_work = true,
281 .cmd.rx_filter_del = {
282 .opcode = IONIC_CMD_RX_FILTER_DEL,
285 struct ionic_rx_filter *f;
290 rte_spinlock_lock(&lif->rx_filters.lock);
292 f = ionic_rx_filter_by_addr(lif, addr);
294 rte_spinlock_unlock(&lif->rx_filters.lock);
298 ctx.cmd.rx_filter_del.filter_id = rte_cpu_to_le_32(f->filter_id);
299 ionic_rx_filter_free(f);
301 rte_spinlock_unlock(&lif->rx_filters.lock);
303 err = ionic_adminq_post_wait(lif, &ctx);
307 IONIC_PRINT(INFO, "rx_filter del (id %d)",
308 rte_le_to_cpu_32(ctx.cmd.rx_filter_del.filter_id));
314 ionic_dev_add_mac(struct rte_eth_dev *eth_dev,
315 struct rte_ether_addr *mac_addr,
316 uint32_t index __rte_unused, uint32_t pool __rte_unused)
318 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
322 return ionic_lif_addr_add(lif, (const uint8_t *)mac_addr);
326 ionic_dev_remove_mac(struct rte_eth_dev *eth_dev, uint32_t index)
328 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
329 struct ionic_adapter *adapter = lif->adapter;
330 struct rte_ether_addr *mac_addr;
334 if (index >= adapter->max_mac_addrs) {
336 "Index %u is above MAC filter limit %u",
337 index, adapter->max_mac_addrs);
341 mac_addr = ð_dev->data->mac_addrs[index];
343 if (!rte_is_valid_assigned_ether_addr(mac_addr))
346 ionic_lif_addr_del(lif, (const uint8_t *)mac_addr);
350 ionic_dev_set_mac(struct rte_eth_dev *eth_dev, struct rte_ether_addr *mac_addr)
352 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
356 if (mac_addr == NULL) {
357 IONIC_PRINT(NOTICE, "New mac is null");
361 if (!rte_is_zero_ether_addr((struct rte_ether_addr *)lif->mac_addr)) {
362 IONIC_PRINT(INFO, "Deleting mac addr %pM",
364 ionic_lif_addr_del(lif, lif->mac_addr);
365 memset(lif->mac_addr, 0, RTE_ETHER_ADDR_LEN);
368 IONIC_PRINT(INFO, "Updating mac addr");
370 rte_ether_addr_copy(mac_addr, (struct rte_ether_addr *)lif->mac_addr);
372 return ionic_lif_addr_add(lif, (const uint8_t *)mac_addr);
376 ionic_vlan_rx_add_vid(struct ionic_lif *lif, uint16_t vid)
378 struct ionic_admin_ctx ctx = {
379 .pending_work = true,
380 .cmd.rx_filter_add = {
381 .opcode = IONIC_CMD_RX_FILTER_ADD,
382 .match = rte_cpu_to_le_16(IONIC_RX_FILTER_MATCH_VLAN),
383 .vlan.vlan = rte_cpu_to_le_16(vid),
388 err = ionic_adminq_post_wait(lif, &ctx);
392 IONIC_PRINT(INFO, "rx_filter add VLAN %d (id %d)", vid,
393 rte_le_to_cpu_32(ctx.comp.rx_filter_add.filter_id));
395 return ionic_rx_filter_save(lif, 0, IONIC_RXQ_INDEX_ANY, &ctx);
399 ionic_vlan_rx_kill_vid(struct ionic_lif *lif, uint16_t vid)
401 struct ionic_admin_ctx ctx = {
402 .pending_work = true,
403 .cmd.rx_filter_del = {
404 .opcode = IONIC_CMD_RX_FILTER_DEL,
407 struct ionic_rx_filter *f;
412 rte_spinlock_lock(&lif->rx_filters.lock);
414 f = ionic_rx_filter_by_vlan(lif, vid);
416 rte_spinlock_unlock(&lif->rx_filters.lock);
420 ctx.cmd.rx_filter_del.filter_id = rte_cpu_to_le_32(f->filter_id);
421 ionic_rx_filter_free(f);
422 rte_spinlock_unlock(&lif->rx_filters.lock);
424 err = ionic_adminq_post_wait(lif, &ctx);
428 IONIC_PRINT(INFO, "rx_filter del VLAN %d (id %d)", vid,
429 rte_le_to_cpu_32(ctx.cmd.rx_filter_del.filter_id));
435 ionic_dev_vlan_filter_set(struct rte_eth_dev *eth_dev, uint16_t vlan_id,
438 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
442 err = ionic_vlan_rx_add_vid(lif, vlan_id);
444 err = ionic_vlan_rx_kill_vid(lif, vlan_id);
450 ionic_lif_rx_mode(struct ionic_lif *lif, uint32_t rx_mode)
452 struct ionic_admin_ctx ctx = {
453 .pending_work = true,
455 .opcode = IONIC_CMD_RX_MODE_SET,
456 .rx_mode = rte_cpu_to_le_16(rx_mode),
461 if (rx_mode & IONIC_RX_MODE_F_UNICAST)
462 IONIC_PRINT(DEBUG, "rx_mode IONIC_RX_MODE_F_UNICAST");
463 if (rx_mode & IONIC_RX_MODE_F_MULTICAST)
464 IONIC_PRINT(DEBUG, "rx_mode IONIC_RX_MODE_F_MULTICAST");
465 if (rx_mode & IONIC_RX_MODE_F_BROADCAST)
466 IONIC_PRINT(DEBUG, "rx_mode IONIC_RX_MODE_F_BROADCAST");
467 if (rx_mode & IONIC_RX_MODE_F_PROMISC)
468 IONIC_PRINT(DEBUG, "rx_mode IONIC_RX_MODE_F_PROMISC");
469 if (rx_mode & IONIC_RX_MODE_F_ALLMULTI)
470 IONIC_PRINT(DEBUG, "rx_mode IONIC_RX_MODE_F_ALLMULTI");
472 err = ionic_adminq_post_wait(lif, &ctx);
474 IONIC_PRINT(ERR, "Failure setting RX mode");
478 ionic_set_rx_mode(struct ionic_lif *lif, uint32_t rx_mode)
480 if (lif->rx_mode != rx_mode) {
481 lif->rx_mode = rx_mode;
482 ionic_lif_rx_mode(lif, rx_mode);
487 ionic_dev_promiscuous_enable(struct rte_eth_dev *eth_dev)
489 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
490 uint32_t rx_mode = lif->rx_mode;
494 rx_mode |= IONIC_RX_MODE_F_PROMISC;
496 ionic_set_rx_mode(lif, rx_mode);
502 ionic_dev_promiscuous_disable(struct rte_eth_dev *eth_dev)
504 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
505 uint32_t rx_mode = lif->rx_mode;
507 rx_mode &= ~IONIC_RX_MODE_F_PROMISC;
509 ionic_set_rx_mode(lif, rx_mode);
515 ionic_dev_allmulticast_enable(struct rte_eth_dev *eth_dev)
517 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
518 uint32_t rx_mode = lif->rx_mode;
520 rx_mode |= IONIC_RX_MODE_F_ALLMULTI;
522 ionic_set_rx_mode(lif, rx_mode);
528 ionic_dev_allmulticast_disable(struct rte_eth_dev *eth_dev)
530 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
531 uint32_t rx_mode = lif->rx_mode;
533 rx_mode &= ~IONIC_RX_MODE_F_ALLMULTI;
535 ionic_set_rx_mode(lif, rx_mode);
541 ionic_lif_change_mtu(struct ionic_lif *lif, int new_mtu)
543 struct ionic_admin_ctx ctx = {
544 .pending_work = true,
546 .opcode = IONIC_CMD_LIF_SETATTR,
547 .attr = IONIC_LIF_ATTR_MTU,
548 .mtu = rte_cpu_to_le_32(new_mtu),
553 err = ionic_adminq_post_wait(lif, &ctx);
561 ionic_intr_alloc(struct ionic_lif *lif, struct ionic_intr_info *intr)
563 struct ionic_adapter *adapter = lif->adapter;
564 struct ionic_dev *idev = &adapter->idev;
568 * Note: interrupt handler is called for index = 0 only
569 * (we use interrupts for the notifyq only anyway,
570 * which has index = 0)
573 for (index = 0; index < adapter->nintrs; index++)
574 if (!adapter->intrs[index])
577 if (index == adapter->nintrs)
580 adapter->intrs[index] = true;
582 ionic_intr_init(idev, intr, index);
588 ionic_qcq_alloc(struct ionic_lif *lif,
593 const char *type_name,
597 uint16_t cq_desc_size,
598 uint16_t sg_desc_size,
599 struct ionic_qcq **qcq)
601 struct ionic_qcq *new;
602 uint32_t q_size, cq_size, sg_size, total_size;
603 void *q_base, *cq_base, *sg_base;
604 rte_iova_t q_base_pa = 0;
605 rte_iova_t cq_base_pa = 0;
606 rte_iova_t sg_base_pa = 0;
611 q_size = num_descs * desc_size;
612 cq_size = num_descs * cq_desc_size;
613 sg_size = num_descs * sg_desc_size;
615 total_size = RTE_ALIGN(q_size, rte_mem_page_size()) +
616 RTE_ALIGN(cq_size, rte_mem_page_size());
618 * Note: aligning q_size/cq_size is not enough due to cq_base address
619 * aligning as q_base could be not aligned to the page.
620 * Adding rte_mem_page_size().
622 total_size += rte_mem_page_size();
624 if (flags & IONIC_QCQ_F_SG) {
625 total_size += RTE_ALIGN(sg_size, rte_mem_page_size());
626 total_size += rte_mem_page_size();
629 new = rte_zmalloc("ionic", struct_size, 0);
631 IONIC_PRINT(ERR, "Cannot allocate queue structure");
637 new->q.info = rte_calloc_socket("ionic",
638 num_descs, sizeof(void *),
639 rte_mem_page_size(), socket_id);
641 IONIC_PRINT(ERR, "Cannot allocate queue info");
643 goto err_out_free_qcq;
648 err = ionic_q_init(&new->q, index, num_descs);
650 IONIC_PRINT(ERR, "Queue initialization failed");
651 goto err_out_free_info;
654 err = ionic_cq_init(&new->cq, num_descs);
656 IONIC_PRINT(ERR, "Completion queue initialization failed");
657 goto err_out_free_info;
660 new->base_z = rte_eth_dma_zone_reserve(lif->eth_dev,
661 type_name, index /* queue_idx */,
662 total_size, IONIC_ALIGN, socket_id);
665 IONIC_PRINT(ERR, "Cannot reserve queue DMA memory");
667 goto err_out_free_info;
670 new->base = new->base_z->addr;
671 new->base_pa = new->base_z->iova;
674 q_base_pa = new->base_pa;
676 cq_base = (void *)RTE_ALIGN((uintptr_t)q_base + q_size,
677 rte_mem_page_size());
678 cq_base_pa = RTE_ALIGN(q_base_pa + q_size,
679 rte_mem_page_size());
681 if (flags & IONIC_QCQ_F_SG) {
682 sg_base = (void *)RTE_ALIGN((uintptr_t)cq_base + cq_size,
683 rte_mem_page_size());
684 sg_base_pa = RTE_ALIGN(cq_base_pa + cq_size,
685 rte_mem_page_size());
686 ionic_q_sg_map(&new->q, sg_base, sg_base_pa);
689 IONIC_PRINT(DEBUG, "Q-Base-PA = %#jx CQ-Base-PA = %#jx "
691 q_base_pa, cq_base_pa, sg_base_pa);
693 ionic_q_map(&new->q, q_base, q_base_pa);
694 ionic_cq_map(&new->cq, cq_base, cq_base_pa);
701 rte_free(new->q.info);
709 ionic_qcq_free(struct ionic_qcq *qcq)
714 rte_memzone_free(qcq->base_z);
719 rte_free(qcq->q.info);
727 ionic_rx_qcq_alloc(struct ionic_lif *lif, uint32_t socket_id, uint32_t index,
728 uint16_t nrxq_descs, struct ionic_rx_qcq **rxq_out)
730 struct ionic_rx_qcq *rxq;
734 flags = IONIC_QCQ_F_SG;
735 err = ionic_qcq_alloc(lif,
737 sizeof(struct ionic_rx_qcq),
743 sizeof(struct ionic_rxq_desc),
744 sizeof(struct ionic_rxq_comp),
745 sizeof(struct ionic_rxq_sg_desc),
746 (struct ionic_qcq **)&rxq);
752 lif->rxqcqs[index] = rxq;
759 ionic_tx_qcq_alloc(struct ionic_lif *lif, uint32_t socket_id, uint32_t index,
760 uint16_t ntxq_descs, struct ionic_tx_qcq **txq_out)
762 struct ionic_tx_qcq *txq;
763 uint16_t flags, num_segs_fw;
766 flags = IONIC_QCQ_F_SG;
768 num_segs_fw = IONIC_TX_MAX_SG_ELEMS_V1 + 1;
770 err = ionic_qcq_alloc(lif,
772 sizeof(struct ionic_tx_qcq),
778 sizeof(struct ionic_txq_desc),
779 sizeof(struct ionic_txq_comp),
780 sizeof(struct ionic_txq_sg_desc_v1),
781 (struct ionic_qcq **)&txq);
786 txq->num_segs_fw = num_segs_fw;
788 lif->txqcqs[index] = txq;
795 ionic_admin_qcq_alloc(struct ionic_lif *lif)
800 err = ionic_qcq_alloc(lif,
802 sizeof(struct ionic_admin_qcq),
808 sizeof(struct ionic_admin_cmd),
809 sizeof(struct ionic_admin_comp),
811 (struct ionic_qcq **)&lif->adminqcq);
819 ionic_notify_qcq_alloc(struct ionic_lif *lif)
821 struct ionic_notify_qcq *nqcq;
822 struct ionic_dev *idev = &lif->adapter->idev;
826 err = ionic_qcq_alloc(lif,
828 sizeof(struct ionic_notify_qcq),
833 IONIC_NOTIFYQ_LENGTH,
834 sizeof(struct ionic_notifyq_cmd),
835 sizeof(union ionic_notifyq_comp),
837 (struct ionic_qcq **)&nqcq);
841 err = ionic_intr_alloc(lif, &nqcq->intr);
843 ionic_qcq_free(&nqcq->qcq);
847 ionic_intr_mask_assert(idev->intr_ctrl, nqcq->intr.index,
848 IONIC_INTR_MASK_SET);
850 lif->notifyqcq = nqcq;
856 ionic_bus_map_dbpage(struct ionic_adapter *adapter, int page_num)
858 char *vaddr = adapter->bars[IONIC_PCI_BAR_DBELL].vaddr;
860 if (adapter->num_bars <= IONIC_PCI_BAR_DBELL)
863 return (void *)&vaddr[page_num << PAGE_SHIFT];
867 ionic_lif_queue_identify(struct ionic_lif *lif)
869 struct ionic_adapter *adapter = lif->adapter;
870 struct ionic_dev *idev = &adapter->idev;
871 union ionic_q_identity *q_ident = &adapter->ident.txq;
872 uint32_t q_words = RTE_DIM(q_ident->words);
873 uint32_t cmd_words = RTE_DIM(idev->dev_cmd->data);
874 uint32_t i, nwords, qtype;
877 for (qtype = 0; qtype < RTE_DIM(ionic_qtype_vers); qtype++) {
878 struct ionic_qtype_info *qti = &lif->qtype_info[qtype];
880 /* Filter out the types this driver knows about */
882 case IONIC_QTYPE_ADMINQ:
883 case IONIC_QTYPE_NOTIFYQ:
884 case IONIC_QTYPE_RXQ:
885 case IONIC_QTYPE_TXQ:
891 memset(qti, 0, sizeof(*qti));
893 ionic_dev_cmd_queue_identify(idev, IONIC_LIF_TYPE_CLASSIC,
894 qtype, ionic_qtype_vers[qtype]);
895 err = ionic_dev_cmd_wait_check(idev, IONIC_DEVCMD_TIMEOUT);
896 if (err == -EINVAL) {
897 IONIC_PRINT(ERR, "qtype %d not supported\n", qtype);
899 } else if (err == -EIO) {
900 IONIC_PRINT(ERR, "q_ident failed, older FW\n");
903 IONIC_PRINT(ERR, "q_ident failed, qtype %d: %d\n",
908 nwords = RTE_MIN(q_words, cmd_words);
909 for (i = 0; i < nwords; i++)
910 q_ident->words[i] = ioread32(&idev->dev_cmd->data[i]);
912 qti->version = q_ident->version;
913 qti->supported = q_ident->supported;
914 qti->features = rte_le_to_cpu_64(q_ident->features);
915 qti->desc_sz = rte_le_to_cpu_16(q_ident->desc_sz);
916 qti->comp_sz = rte_le_to_cpu_16(q_ident->comp_sz);
917 qti->sg_desc_sz = rte_le_to_cpu_16(q_ident->sg_desc_sz);
918 qti->max_sg_elems = rte_le_to_cpu_16(q_ident->max_sg_elems);
919 qti->sg_desc_stride =
920 rte_le_to_cpu_16(q_ident->sg_desc_stride);
922 IONIC_PRINT(DEBUG, " qtype[%d].version = %d",
923 qtype, qti->version);
924 IONIC_PRINT(DEBUG, " qtype[%d].supported = %#x",
925 qtype, qti->supported);
926 IONIC_PRINT(DEBUG, " qtype[%d].features = %#jx",
927 qtype, qti->features);
928 IONIC_PRINT(DEBUG, " qtype[%d].desc_sz = %d",
929 qtype, qti->desc_sz);
930 IONIC_PRINT(DEBUG, " qtype[%d].comp_sz = %d",
931 qtype, qti->comp_sz);
932 IONIC_PRINT(DEBUG, " qtype[%d].sg_desc_sz = %d",
933 qtype, qti->sg_desc_sz);
934 IONIC_PRINT(DEBUG, " qtype[%d].max_sg_elems = %d",
935 qtype, qti->max_sg_elems);
936 IONIC_PRINT(DEBUG, " qtype[%d].sg_desc_stride = %d",
937 qtype, qti->sg_desc_stride);
942 ionic_lif_alloc(struct ionic_lif *lif)
944 struct ionic_adapter *adapter = lif->adapter;
945 uint32_t socket_id = rte_socket_id();
949 * lif->name was zeroed on allocation.
950 * Copy (sizeof() - 1) bytes to ensure that it is NULL terminated.
952 memcpy(lif->name, lif->eth_dev->data->name, sizeof(lif->name) - 1);
954 IONIC_PRINT(DEBUG, "LIF: %s", lif->name);
956 ionic_lif_queue_identify(lif);
958 if (lif->qtype_info[IONIC_QTYPE_TXQ].version < 1) {
959 IONIC_PRINT(ERR, "FW too old, please upgrade");
963 IONIC_PRINT(DEBUG, "Allocating Lif Info");
965 rte_spinlock_init(&lif->adminq_lock);
966 rte_spinlock_init(&lif->adminq_service_lock);
968 lif->kern_dbpage = ionic_bus_map_dbpage(adapter, 0);
969 if (!lif->kern_dbpage) {
970 IONIC_PRINT(ERR, "Cannot map dbpage, aborting");
974 lif->txqcqs = rte_zmalloc("ionic", sizeof(*lif->txqcqs) *
975 adapter->max_ntxqs_per_lif, 0);
978 IONIC_PRINT(ERR, "Cannot allocate tx queues array");
982 lif->rxqcqs = rte_zmalloc("ionic", sizeof(*lif->rxqcqs) *
983 adapter->max_nrxqs_per_lif, 0);
986 IONIC_PRINT(ERR, "Cannot allocate rx queues array");
990 IONIC_PRINT(DEBUG, "Allocating Notify Queue");
992 err = ionic_notify_qcq_alloc(lif);
994 IONIC_PRINT(ERR, "Cannot allocate notify queue");
998 IONIC_PRINT(DEBUG, "Allocating Admin Queue");
1000 err = ionic_admin_qcq_alloc(lif);
1002 IONIC_PRINT(ERR, "Cannot allocate admin queue");
1006 IONIC_PRINT(DEBUG, "Allocating Lif Info");
1008 lif->info_sz = RTE_ALIGN(sizeof(*lif->info), rte_mem_page_size());
1010 lif->info_z = rte_eth_dma_zone_reserve(lif->eth_dev,
1011 "lif_info", 0 /* queue_idx*/,
1012 lif->info_sz, IONIC_ALIGN, socket_id);
1014 IONIC_PRINT(ERR, "Cannot allocate lif info memory");
1018 lif->info = lif->info_z->addr;
1019 lif->info_pa = lif->info_z->iova;
1025 ionic_lif_free(struct ionic_lif *lif)
1027 if (lif->notifyqcq) {
1028 ionic_qcq_free(&lif->notifyqcq->qcq);
1029 lif->notifyqcq = NULL;
1032 if (lif->adminqcq) {
1033 ionic_qcq_free(&lif->adminqcq->qcq);
1034 lif->adminqcq = NULL;
1038 rte_free(lif->txqcqs);
1043 rte_free(lif->rxqcqs);
1048 rte_memzone_free(lif->info_z);
1054 ionic_lif_free_queues(struct ionic_lif *lif)
1058 for (i = 0; i < lif->ntxqcqs; i++) {
1059 ionic_dev_tx_queue_release(lif->eth_dev, i);
1060 lif->eth_dev->data->tx_queues[i] = NULL;
1062 for (i = 0; i < lif->nrxqcqs; i++) {
1063 ionic_dev_rx_queue_release(lif->eth_dev, i);
1064 lif->eth_dev->data->rx_queues[i] = NULL;
1069 ionic_lif_rss_config(struct ionic_lif *lif,
1070 const uint16_t types, const uint8_t *key, const uint32_t *indir)
1072 struct ionic_adapter *adapter = lif->adapter;
1073 struct ionic_admin_ctx ctx = {
1074 .pending_work = true,
1075 .cmd.lif_setattr = {
1076 .opcode = IONIC_CMD_LIF_SETATTR,
1077 .attr = IONIC_LIF_ATTR_RSS,
1078 .rss.types = rte_cpu_to_le_16(types),
1079 .rss.addr = rte_cpu_to_le_64(lif->rss_ind_tbl_pa),
1084 rte_le_to_cpu_16(adapter->ident.lif.eth.rss_ind_tbl_sz);
1088 lif->rss_types = types;
1091 memcpy(lif->rss_hash_key, key, IONIC_RSS_HASH_KEY_SIZE);
1094 for (i = 0; i < tbl_sz; i++)
1095 lif->rss_ind_tbl[i] = indir[i];
1097 memcpy(ctx.cmd.lif_setattr.rss.key, lif->rss_hash_key,
1098 IONIC_RSS_HASH_KEY_SIZE);
1100 return ionic_adminq_post_wait(lif, &ctx);
1104 ionic_lif_rss_setup(struct ionic_lif *lif)
1106 struct ionic_adapter *adapter = lif->adapter;
1107 static const uint8_t toeplitz_symmetric_key[] = {
1108 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A,
1109 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A,
1110 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A,
1111 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A,
1112 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A,
1116 rte_le_to_cpu_16(adapter->ident.lif.eth.rss_ind_tbl_sz);
1120 if (!lif->rss_ind_tbl_z) {
1121 lif->rss_ind_tbl_z = rte_eth_dma_zone_reserve(lif->eth_dev,
1122 "rss_ind_tbl", 0 /* queue_idx */,
1123 sizeof(*lif->rss_ind_tbl) * tbl_sz,
1124 IONIC_ALIGN, rte_socket_id());
1125 if (!lif->rss_ind_tbl_z) {
1126 IONIC_PRINT(ERR, "OOM");
1130 lif->rss_ind_tbl = lif->rss_ind_tbl_z->addr;
1131 lif->rss_ind_tbl_pa = lif->rss_ind_tbl_z->iova;
1134 if (lif->rss_ind_tbl_nrxqcqs != lif->nrxqcqs) {
1135 lif->rss_ind_tbl_nrxqcqs = lif->nrxqcqs;
1137 /* Fill indirection table with 'default' values */
1138 for (i = 0; i < tbl_sz; i++)
1139 lif->rss_ind_tbl[i] = i % lif->nrxqcqs;
1142 return ionic_lif_rss_config(lif, IONIC_RSS_OFFLOAD_ALL,
1143 toeplitz_symmetric_key, NULL);
1147 ionic_lif_rss_teardown(struct ionic_lif *lif)
1149 if (!lif->rss_ind_tbl)
1152 if (lif->rss_ind_tbl_z) {
1153 /* Disable RSS on the NIC */
1154 ionic_lif_rss_config(lif, 0x0, NULL, NULL);
1156 lif->rss_ind_tbl = NULL;
1157 lif->rss_ind_tbl_pa = 0;
1158 rte_memzone_free(lif->rss_ind_tbl_z);
1159 lif->rss_ind_tbl_z = NULL;
1164 ionic_lif_txq_deinit(struct ionic_tx_qcq *txq)
1166 txq->flags &= ~IONIC_QCQ_F_INITED;
1170 ionic_lif_rxq_deinit(struct ionic_rx_qcq *rxq)
1172 rxq->flags &= ~IONIC_QCQ_F_INITED;
1176 ionic_lif_adminq_deinit(struct ionic_lif *lif)
1178 lif->adminqcq->flags &= ~IONIC_QCQ_F_INITED;
1182 ionic_lif_notifyq_deinit(struct ionic_lif *lif)
1184 struct ionic_notify_qcq *nqcq = lif->notifyqcq;
1185 struct ionic_dev *idev = &lif->adapter->idev;
1187 if (!(nqcq->flags & IONIC_QCQ_F_INITED))
1190 ionic_intr_mask(idev->intr_ctrl, nqcq->intr.index,
1191 IONIC_INTR_MASK_SET);
1193 nqcq->flags &= ~IONIC_QCQ_F_INITED;
1196 /* This acts like ionic_napi */
1198 ionic_qcq_service(struct ionic_qcq *qcq, int budget, ionic_cq_cb cb,
1201 struct ionic_cq *cq = &qcq->cq;
1204 work_done = ionic_cq_service(cq, budget, cb, cb_arg);
1210 ionic_link_status_check(struct ionic_lif *lif)
1212 struct ionic_adapter *adapter = lif->adapter;
1215 lif->state &= ~IONIC_LIF_F_LINK_CHECK_NEEDED;
1220 link_up = (lif->info->status.link_status == IONIC_PORT_OPER_STATUS_UP);
1222 if ((link_up && adapter->link_up) ||
1223 (!link_up && !adapter->link_up))
1227 adapter->link_speed =
1228 rte_le_to_cpu_32(lif->info->status.link_speed);
1229 IONIC_PRINT(DEBUG, "Link up - %d Gbps",
1230 adapter->link_speed);
1232 IONIC_PRINT(DEBUG, "Link down");
1235 adapter->link_up = link_up;
1236 ionic_dev_link_update(lif->eth_dev, 0);
1240 ionic_lif_handle_fw_down(struct ionic_lif *lif)
1242 if (lif->state & IONIC_LIF_F_FW_RESET)
1245 lif->state |= IONIC_LIF_F_FW_RESET;
1247 if (lif->state & IONIC_LIF_F_UP) {
1249 "Surprise FW stop, stopping %s\n", lif->name);
1250 ionic_lif_stop(lif);
1253 IONIC_PRINT(NOTICE, "FW down, %s stopped", lif->name);
1257 ionic_notifyq_cb(struct ionic_cq *cq, uint16_t cq_desc_index, void *cb_arg)
1259 union ionic_notifyq_comp *cq_desc_base = cq->base;
1260 union ionic_notifyq_comp *cq_desc = &cq_desc_base[cq_desc_index];
1261 struct ionic_lif *lif = cb_arg;
1263 IONIC_PRINT(DEBUG, "Notifyq callback eid = %jd ecode = %d",
1264 cq_desc->event.eid, cq_desc->event.ecode);
1266 /* Have we run out of new completions to process? */
1267 if (!(cq_desc->event.eid > lif->last_eid))
1270 lif->last_eid = cq_desc->event.eid;
1272 switch (cq_desc->event.ecode) {
1273 case IONIC_EVENT_LINK_CHANGE:
1275 "Notifyq IONIC_EVENT_LINK_CHANGE %s "
1276 "eid=%jd link_status=%d link_speed=%d",
1279 cq_desc->link_change.link_status,
1280 cq_desc->link_change.link_speed);
1282 lif->state |= IONIC_LIF_F_LINK_CHECK_NEEDED;
1285 case IONIC_EVENT_RESET:
1287 "Notifyq IONIC_EVENT_RESET %s "
1288 "eid=%jd, reset_code=%d state=%d",
1291 cq_desc->reset.reset_code,
1292 cq_desc->reset.state);
1293 ionic_lif_handle_fw_down(lif);
1297 IONIC_PRINT(WARNING, "Notifyq bad event ecode=%d eid=%jd",
1298 cq_desc->event.ecode, cq_desc->event.eid);
1306 ionic_notifyq_handler(struct ionic_lif *lif, int budget)
1308 struct ionic_dev *idev = &lif->adapter->idev;
1309 struct ionic_notify_qcq *nqcq = lif->notifyqcq;
1312 if (!(nqcq->flags & IONIC_QCQ_F_INITED)) {
1313 IONIC_PRINT(DEBUG, "Notifyq not yet initialized");
1317 ionic_intr_mask(idev->intr_ctrl, nqcq->intr.index,
1318 IONIC_INTR_MASK_SET);
1320 work_done = ionic_qcq_service(&nqcq->qcq, budget,
1321 ionic_notifyq_cb, lif);
1323 if (lif->state & IONIC_LIF_F_LINK_CHECK_NEEDED)
1324 ionic_link_status_check(lif);
1326 ionic_intr_credits(idev->intr_ctrl, nqcq->intr.index,
1327 work_done, IONIC_INTR_CRED_RESET_COALESCE);
1329 ionic_intr_mask(idev->intr_ctrl, nqcq->intr.index,
1330 IONIC_INTR_MASK_CLEAR);
1336 ionic_lif_adminq_init(struct ionic_lif *lif)
1338 struct ionic_dev *idev = &lif->adapter->idev;
1339 struct ionic_admin_qcq *aqcq = lif->adminqcq;
1340 struct ionic_queue *q = &aqcq->qcq.q;
1341 struct ionic_q_init_comp comp;
1344 ionic_dev_cmd_adminq_init(idev, &aqcq->qcq);
1345 err = ionic_dev_cmd_wait_check(idev, IONIC_DEVCMD_TIMEOUT);
1349 ionic_dev_cmd_comp(idev, &comp);
1351 q->hw_type = comp.hw_type;
1352 q->hw_index = rte_le_to_cpu_32(comp.hw_index);
1353 q->db = ionic_db_map(lif, q);
1355 IONIC_PRINT(DEBUG, "adminq->hw_type %d", q->hw_type);
1356 IONIC_PRINT(DEBUG, "adminq->hw_index %d", q->hw_index);
1357 IONIC_PRINT(DEBUG, "adminq->db %p", q->db);
1359 aqcq->flags |= IONIC_QCQ_F_INITED;
1365 ionic_lif_notifyq_init(struct ionic_lif *lif)
1367 struct ionic_dev *idev = &lif->adapter->idev;
1368 struct ionic_notify_qcq *nqcq = lif->notifyqcq;
1369 struct ionic_queue *q = &nqcq->qcq.q;
1372 struct ionic_admin_ctx ctx = {
1373 .pending_work = true,
1375 .opcode = IONIC_CMD_Q_INIT,
1377 .ver = lif->qtype_info[q->type].version,
1378 .index = rte_cpu_to_le_32(q->index),
1379 .intr_index = rte_cpu_to_le_16(nqcq->intr.index),
1380 .flags = rte_cpu_to_le_16(IONIC_QINIT_F_IRQ |
1382 .ring_size = rte_log2_u32(q->num_descs),
1383 .ring_base = rte_cpu_to_le_64(q->base_pa),
1387 IONIC_PRINT(DEBUG, "notifyq_init.index %d", q->index);
1388 IONIC_PRINT(DEBUG, "notifyq_init.ring_base 0x%" PRIx64 "", q->base_pa);
1389 IONIC_PRINT(DEBUG, "notifyq_init.ring_size %d",
1390 ctx.cmd.q_init.ring_size);
1391 IONIC_PRINT(DEBUG, "notifyq_init.ver %u", ctx.cmd.q_init.ver);
1393 err = ionic_adminq_post_wait(lif, &ctx);
1397 q->hw_type = ctx.comp.q_init.hw_type;
1398 q->hw_index = rte_le_to_cpu_32(ctx.comp.q_init.hw_index);
1401 IONIC_PRINT(DEBUG, "notifyq->hw_type %d", q->hw_type);
1402 IONIC_PRINT(DEBUG, "notifyq->hw_index %d", q->hw_index);
1403 IONIC_PRINT(DEBUG, "notifyq->db %p", q->db);
1405 ionic_intr_mask(idev->intr_ctrl, nqcq->intr.index,
1406 IONIC_INTR_MASK_CLEAR);
1408 nqcq->flags |= IONIC_QCQ_F_INITED;
1414 ionic_lif_set_features(struct ionic_lif *lif)
1416 struct ionic_admin_ctx ctx = {
1417 .pending_work = true,
1418 .cmd.lif_setattr = {
1419 .opcode = IONIC_CMD_LIF_SETATTR,
1420 .attr = IONIC_LIF_ATTR_FEATURES,
1421 .features = rte_cpu_to_le_64(lif->features),
1426 err = ionic_adminq_post_wait(lif, &ctx);
1430 lif->hw_features = rte_le_to_cpu_64(ctx.cmd.lif_setattr.features &
1431 ctx.comp.lif_setattr.features);
1433 if (lif->hw_features & IONIC_ETH_HW_VLAN_TX_TAG)
1434 IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_VLAN_TX_TAG");
1435 if (lif->hw_features & IONIC_ETH_HW_VLAN_RX_STRIP)
1436 IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_VLAN_RX_STRIP");
1437 if (lif->hw_features & IONIC_ETH_HW_VLAN_RX_FILTER)
1438 IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_VLAN_RX_FILTER");
1439 if (lif->hw_features & IONIC_ETH_HW_RX_HASH)
1440 IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_RX_HASH");
1441 if (lif->hw_features & IONIC_ETH_HW_TX_SG)
1442 IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_TX_SG");
1443 if (lif->hw_features & IONIC_ETH_HW_RX_SG)
1444 IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_RX_SG");
1445 if (lif->hw_features & IONIC_ETH_HW_TX_CSUM)
1446 IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_TX_CSUM");
1447 if (lif->hw_features & IONIC_ETH_HW_RX_CSUM)
1448 IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_RX_CSUM");
1449 if (lif->hw_features & IONIC_ETH_HW_TSO)
1450 IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_TSO");
1451 if (lif->hw_features & IONIC_ETH_HW_TSO_IPV6)
1452 IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_TSO_IPV6");
1453 if (lif->hw_features & IONIC_ETH_HW_TSO_ECN)
1454 IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_TSO_ECN");
1455 if (lif->hw_features & IONIC_ETH_HW_TSO_GRE)
1456 IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_TSO_GRE");
1457 if (lif->hw_features & IONIC_ETH_HW_TSO_GRE_CSUM)
1458 IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_TSO_GRE_CSUM");
1459 if (lif->hw_features & IONIC_ETH_HW_TSO_IPXIP4)
1460 IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_TSO_IPXIP4");
1461 if (lif->hw_features & IONIC_ETH_HW_TSO_IPXIP6)
1462 IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_TSO_IPXIP6");
1463 if (lif->hw_features & IONIC_ETH_HW_TSO_UDP)
1464 IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_TSO_UDP");
1465 if (lif->hw_features & IONIC_ETH_HW_TSO_UDP_CSUM)
1466 IONIC_PRINT(DEBUG, "feature IONIC_ETH_HW_TSO_UDP_CSUM");
1472 ionic_lif_txq_init(struct ionic_tx_qcq *txq)
1474 struct ionic_qcq *qcq = &txq->qcq;
1475 struct ionic_queue *q = &qcq->q;
1476 struct ionic_lif *lif = qcq->lif;
1477 struct ionic_cq *cq = &qcq->cq;
1478 struct ionic_admin_ctx ctx = {
1479 .pending_work = true,
1481 .opcode = IONIC_CMD_Q_INIT,
1483 .ver = lif->qtype_info[q->type].version,
1484 .index = rte_cpu_to_le_32(q->index),
1485 .flags = rte_cpu_to_le_16(IONIC_QINIT_F_SG |
1487 .intr_index = rte_cpu_to_le_16(IONIC_INTR_NONE),
1488 .ring_size = rte_log2_u32(q->num_descs),
1489 .ring_base = rte_cpu_to_le_64(q->base_pa),
1490 .cq_ring_base = rte_cpu_to_le_64(cq->base_pa),
1491 .sg_ring_base = rte_cpu_to_le_64(q->sg_base_pa),
1496 IONIC_PRINT(DEBUG, "txq_init.index %d", q->index);
1497 IONIC_PRINT(DEBUG, "txq_init.ring_base 0x%" PRIx64 "", q->base_pa);
1498 IONIC_PRINT(DEBUG, "txq_init.ring_size %d",
1499 ctx.cmd.q_init.ring_size);
1500 IONIC_PRINT(DEBUG, "txq_init.ver %u", ctx.cmd.q_init.ver);
1502 err = ionic_adminq_post_wait(lif, &ctx);
1506 q->hw_type = ctx.comp.q_init.hw_type;
1507 q->hw_index = rte_le_to_cpu_32(ctx.comp.q_init.hw_index);
1508 q->db = ionic_db_map(lif, q);
1510 IONIC_PRINT(DEBUG, "txq->hw_type %d", q->hw_type);
1511 IONIC_PRINT(DEBUG, "txq->hw_index %d", q->hw_index);
1512 IONIC_PRINT(DEBUG, "txq->db %p", q->db);
1514 txq->flags |= IONIC_QCQ_F_INITED;
1520 ionic_lif_rxq_init(struct ionic_rx_qcq *rxq)
1522 struct ionic_qcq *qcq = &rxq->qcq;
1523 struct ionic_queue *q = &qcq->q;
1524 struct ionic_lif *lif = qcq->lif;
1525 struct ionic_cq *cq = &qcq->cq;
1526 struct ionic_admin_ctx ctx = {
1527 .pending_work = true,
1529 .opcode = IONIC_CMD_Q_INIT,
1531 .ver = lif->qtype_info[q->type].version,
1532 .index = rte_cpu_to_le_32(q->index),
1533 .flags = rte_cpu_to_le_16(IONIC_QINIT_F_SG |
1535 .intr_index = rte_cpu_to_le_16(IONIC_INTR_NONE),
1536 .ring_size = rte_log2_u32(q->num_descs),
1537 .ring_base = rte_cpu_to_le_64(q->base_pa),
1538 .cq_ring_base = rte_cpu_to_le_64(cq->base_pa),
1539 .sg_ring_base = rte_cpu_to_le_64(q->sg_base_pa),
1544 IONIC_PRINT(DEBUG, "rxq_init.index %d", q->index);
1545 IONIC_PRINT(DEBUG, "rxq_init.ring_base 0x%" PRIx64 "", q->base_pa);
1546 IONIC_PRINT(DEBUG, "rxq_init.ring_size %d",
1547 ctx.cmd.q_init.ring_size);
1548 IONIC_PRINT(DEBUG, "rxq_init.ver %u", ctx.cmd.q_init.ver);
1550 err = ionic_adminq_post_wait(lif, &ctx);
1554 q->hw_type = ctx.comp.q_init.hw_type;
1555 q->hw_index = rte_le_to_cpu_32(ctx.comp.q_init.hw_index);
1556 q->db = ionic_db_map(lif, q);
1558 rxq->flags |= IONIC_QCQ_F_INITED;
1560 IONIC_PRINT(DEBUG, "rxq->hw_type %d", q->hw_type);
1561 IONIC_PRINT(DEBUG, "rxq->hw_index %d", q->hw_index);
1562 IONIC_PRINT(DEBUG, "rxq->db %p", q->db);
1568 ionic_station_set(struct ionic_lif *lif)
1570 struct ionic_admin_ctx ctx = {
1571 .pending_work = true,
1572 .cmd.lif_getattr = {
1573 .opcode = IONIC_CMD_LIF_GETATTR,
1574 .attr = IONIC_LIF_ATTR_MAC,
1581 err = ionic_adminq_post_wait(lif, &ctx);
1585 memcpy(lif->mac_addr, ctx.comp.lif_getattr.mac, RTE_ETHER_ADDR_LEN);
1591 ionic_lif_set_name(struct ionic_lif *lif)
1593 struct ionic_admin_ctx ctx = {
1594 .pending_work = true,
1595 .cmd.lif_setattr = {
1596 .opcode = IONIC_CMD_LIF_SETATTR,
1597 .attr = IONIC_LIF_ATTR_NAME,
1601 memcpy(ctx.cmd.lif_setattr.name, lif->name,
1602 sizeof(ctx.cmd.lif_setattr.name) - 1);
1604 ionic_adminq_post_wait(lif, &ctx);
1608 ionic_lif_init(struct ionic_lif *lif)
1610 struct ionic_dev *idev = &lif->adapter->idev;
1611 struct ionic_lif_init_comp comp;
1614 memset(&lif->stats_base, 0, sizeof(lif->stats_base));
1616 ionic_dev_cmd_lif_init(idev, lif->info_pa);
1617 err = ionic_dev_cmd_wait_check(idev, IONIC_DEVCMD_TIMEOUT);
1621 ionic_dev_cmd_comp(idev, &comp);
1623 lif->hw_index = rte_cpu_to_le_16(comp.hw_index);
1625 err = ionic_lif_adminq_init(lif);
1629 err = ionic_lif_notifyq_init(lif);
1631 goto err_out_adminq_deinit;
1634 * Configure initial feature set
1635 * This will be updated later by the dev_configure() step
1637 lif->features = IONIC_ETH_HW_RX_HASH | IONIC_ETH_HW_VLAN_RX_FILTER;
1639 err = ionic_lif_set_features(lif);
1641 goto err_out_notifyq_deinit;
1643 err = ionic_rx_filters_init(lif);
1645 goto err_out_notifyq_deinit;
1647 err = ionic_station_set(lif);
1649 goto err_out_rx_filter_deinit;
1651 ionic_lif_set_name(lif);
1653 lif->state |= IONIC_LIF_F_INITED;
1657 err_out_rx_filter_deinit:
1658 ionic_rx_filters_deinit(lif);
1660 err_out_notifyq_deinit:
1661 ionic_lif_notifyq_deinit(lif);
1663 err_out_adminq_deinit:
1664 ionic_lif_adminq_deinit(lif);
1670 ionic_lif_deinit(struct ionic_lif *lif)
1672 if (!(lif->state & IONIC_LIF_F_INITED))
1675 ionic_rx_filters_deinit(lif);
1676 ionic_lif_rss_teardown(lif);
1677 ionic_lif_notifyq_deinit(lif);
1678 ionic_lif_adminq_deinit(lif);
1680 lif->state &= ~IONIC_LIF_F_INITED;
1684 ionic_lif_configure_vlan_offload(struct ionic_lif *lif, int mask)
1686 struct rte_eth_dev *eth_dev = lif->eth_dev;
1687 struct rte_eth_rxmode *rxmode = ð_dev->data->dev_conf.rxmode;
1690 * IONIC_ETH_HW_VLAN_RX_FILTER cannot be turned off, so
1691 * set DEV_RX_OFFLOAD_VLAN_FILTER and ignore ETH_VLAN_FILTER_MASK
1693 rxmode->offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
1695 if (mask & ETH_VLAN_STRIP_MASK) {
1696 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
1697 lif->features |= IONIC_ETH_HW_VLAN_RX_STRIP;
1699 lif->features &= ~IONIC_ETH_HW_VLAN_RX_STRIP;
1704 ionic_lif_configure(struct ionic_lif *lif)
1706 struct rte_eth_rxmode *rxmode = &lif->eth_dev->data->dev_conf.rxmode;
1707 struct rte_eth_txmode *txmode = &lif->eth_dev->data->dev_conf.txmode;
1708 struct ionic_identity *ident = &lif->adapter->ident;
1709 union ionic_lif_config *cfg = &ident->lif.eth.config;
1710 uint32_t ntxqs_per_lif =
1711 rte_le_to_cpu_32(cfg->queue_count[IONIC_QTYPE_TXQ]);
1712 uint32_t nrxqs_per_lif =
1713 rte_le_to_cpu_32(cfg->queue_count[IONIC_QTYPE_RXQ]);
1714 uint32_t nrxqs = lif->eth_dev->data->nb_rx_queues;
1715 uint32_t ntxqs = lif->eth_dev->data->nb_tx_queues;
1717 lif->port_id = lif->eth_dev->data->port_id;
1719 IONIC_PRINT(DEBUG, "Configuring LIF on port %u",
1723 nrxqs_per_lif = RTE_MIN(nrxqs_per_lif, nrxqs);
1726 ntxqs_per_lif = RTE_MIN(ntxqs_per_lif, ntxqs);
1728 lif->nrxqcqs = nrxqs_per_lif;
1729 lif->ntxqcqs = ntxqs_per_lif;
1731 /* Update the LIF configuration based on the eth_dev */
1734 * NB: While it is true that RSS_HASH is always enabled on ionic,
1735 * setting this flag unconditionally causes problems in DTS.
1736 * rxmode->offloads |= DEV_RX_OFFLOAD_RSS_HASH;
1741 if (rxmode->offloads & DEV_RX_OFFLOAD_IPV4_CKSUM ||
1742 rxmode->offloads & DEV_RX_OFFLOAD_UDP_CKSUM ||
1743 rxmode->offloads & DEV_RX_OFFLOAD_TCP_CKSUM)
1744 lif->features |= IONIC_ETH_HW_RX_CSUM;
1746 lif->features &= ~IONIC_ETH_HW_RX_CSUM;
1748 if (rxmode->offloads & DEV_RX_OFFLOAD_SCATTER) {
1749 lif->features |= IONIC_ETH_HW_RX_SG;
1750 lif->eth_dev->data->scattered_rx = 1;
1752 lif->features &= ~IONIC_ETH_HW_RX_SG;
1753 lif->eth_dev->data->scattered_rx = 0;
1756 /* Covers VLAN_STRIP */
1757 ionic_lif_configure_vlan_offload(lif, ETH_VLAN_STRIP_MASK);
1761 if (txmode->offloads & DEV_TX_OFFLOAD_IPV4_CKSUM ||
1762 txmode->offloads & DEV_TX_OFFLOAD_UDP_CKSUM ||
1763 txmode->offloads & DEV_TX_OFFLOAD_TCP_CKSUM ||
1764 txmode->offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM ||
1765 txmode->offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
1766 lif->features |= IONIC_ETH_HW_TX_CSUM;
1768 lif->features &= ~IONIC_ETH_HW_TX_CSUM;
1770 if (txmode->offloads & DEV_TX_OFFLOAD_VLAN_INSERT)
1771 lif->features |= IONIC_ETH_HW_VLAN_TX_TAG;
1773 lif->features &= ~IONIC_ETH_HW_VLAN_TX_TAG;
1775 if (txmode->offloads & DEV_TX_OFFLOAD_MULTI_SEGS)
1776 lif->features |= IONIC_ETH_HW_TX_SG;
1778 lif->features &= ~IONIC_ETH_HW_TX_SG;
1780 if (txmode->offloads & DEV_TX_OFFLOAD_TCP_TSO) {
1781 lif->features |= IONIC_ETH_HW_TSO;
1782 lif->features |= IONIC_ETH_HW_TSO_IPV6;
1783 lif->features |= IONIC_ETH_HW_TSO_ECN;
1785 lif->features &= ~IONIC_ETH_HW_TSO;
1786 lif->features &= ~IONIC_ETH_HW_TSO_IPV6;
1787 lif->features &= ~IONIC_ETH_HW_TSO_ECN;
1792 ionic_lif_start(struct ionic_lif *lif)
1798 err = ionic_lif_rss_setup(lif);
1802 if (!lif->rx_mode) {
1803 IONIC_PRINT(DEBUG, "Setting RX mode on %s",
1806 rx_mode = IONIC_RX_MODE_F_UNICAST;
1807 rx_mode |= IONIC_RX_MODE_F_MULTICAST;
1808 rx_mode |= IONIC_RX_MODE_F_BROADCAST;
1810 ionic_set_rx_mode(lif, rx_mode);
1813 IONIC_PRINT(DEBUG, "Starting %u RX queues and %u TX queues "
1815 lif->nrxqcqs, lif->ntxqcqs, lif->port_id);
1817 for (i = 0; i < lif->nrxqcqs; i++) {
1818 struct ionic_rx_qcq *rxq = lif->rxqcqs[i];
1819 if (!(rxq->flags & IONIC_QCQ_F_DEFERRED)) {
1820 err = ionic_dev_rx_queue_start(lif->eth_dev, i);
1827 for (i = 0; i < lif->ntxqcqs; i++) {
1828 struct ionic_tx_qcq *txq = lif->txqcqs[i];
1829 if (!(txq->flags & IONIC_QCQ_F_DEFERRED)) {
1830 err = ionic_dev_tx_queue_start(lif->eth_dev, i);
1837 /* Carrier ON here */
1838 lif->state |= IONIC_LIF_F_UP;
1840 ionic_link_status_check(lif);
1846 ionic_lif_identify(struct ionic_adapter *adapter)
1848 struct ionic_dev *idev = &adapter->idev;
1849 struct ionic_identity *ident = &adapter->ident;
1850 union ionic_lif_config *cfg = &ident->lif.eth.config;
1851 uint32_t lif_words = RTE_DIM(ident->lif.words);
1852 uint32_t cmd_words = RTE_DIM(idev->dev_cmd->data);
1856 ionic_dev_cmd_lif_identify(idev, IONIC_LIF_TYPE_CLASSIC,
1857 IONIC_IDENTITY_VERSION_1);
1858 err = ionic_dev_cmd_wait_check(idev, IONIC_DEVCMD_TIMEOUT);
1862 nwords = RTE_MIN(lif_words, cmd_words);
1863 for (i = 0; i < nwords; i++)
1864 ident->lif.words[i] = ioread32(&idev->dev_cmd->data[i]);
1866 IONIC_PRINT(INFO, "capabilities 0x%" PRIx64 " ",
1867 rte_le_to_cpu_64(ident->lif.capabilities));
1869 IONIC_PRINT(INFO, "eth.max_ucast_filters 0x%" PRIx32 " ",
1870 rte_le_to_cpu_32(ident->lif.eth.max_ucast_filters));
1871 IONIC_PRINT(INFO, "eth.max_mcast_filters 0x%" PRIx32 " ",
1872 rte_le_to_cpu_32(ident->lif.eth.max_mcast_filters));
1874 IONIC_PRINT(INFO, "eth.features 0x%" PRIx64 " ",
1875 rte_le_to_cpu_64(cfg->features));
1876 IONIC_PRINT(INFO, "eth.queue_count[IONIC_QTYPE_ADMINQ] 0x%" PRIx32 " ",
1877 rte_le_to_cpu_32(cfg->queue_count[IONIC_QTYPE_ADMINQ]));
1878 IONIC_PRINT(INFO, "eth.queue_count[IONIC_QTYPE_NOTIFYQ] 0x%" PRIx32 " ",
1879 rte_le_to_cpu_32(cfg->queue_count[IONIC_QTYPE_NOTIFYQ]));
1880 IONIC_PRINT(INFO, "eth.queue_count[IONIC_QTYPE_RXQ] 0x%" PRIx32 " ",
1881 rte_le_to_cpu_32(cfg->queue_count[IONIC_QTYPE_RXQ]));
1882 IONIC_PRINT(INFO, "eth.queue_count[IONIC_QTYPE_TXQ] 0x%" PRIx32 " ",
1883 rte_le_to_cpu_32(cfg->queue_count[IONIC_QTYPE_TXQ]));
1889 ionic_lifs_size(struct ionic_adapter *adapter)
1891 struct ionic_identity *ident = &adapter->ident;
1892 union ionic_lif_config *cfg = &ident->lif.eth.config;
1893 uint32_t nintrs, dev_nintrs = rte_le_to_cpu_32(ident->dev.nintrs);
1895 adapter->max_ntxqs_per_lif =
1896 rte_le_to_cpu_32(cfg->queue_count[IONIC_QTYPE_TXQ]);
1897 adapter->max_nrxqs_per_lif =
1898 rte_le_to_cpu_32(cfg->queue_count[IONIC_QTYPE_RXQ]);
1900 nintrs = 1 /* notifyq */;
1902 if (nintrs > dev_nintrs) {
1904 "At most %d intr supported, minimum req'd is %u",
1905 dev_nintrs, nintrs);
1909 adapter->nintrs = nintrs;