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 <rte_ethdev_driver.h>
9 #include "ionic_logs.h"
10 #include "ionic_lif.h"
11 #include "ionic_ethdev.h"
14 ionic_bus_map_dbpage(struct ionic_adapter *adapter, int page_num)
16 char *vaddr = adapter->bars[IONIC_PCI_BAR_DBELL].vaddr;
18 if (adapter->num_bars <= IONIC_PCI_BAR_DBELL)
21 return (void *)&vaddr[page_num << PAGE_SHIFT];
25 ionic_lif_alloc(struct ionic_lif *lif)
27 struct ionic_adapter *adapter = lif->adapter;
28 uint32_t socket_id = rte_socket_id();
31 snprintf(lif->name, sizeof(lif->name), "lif%u", lif->index);
33 IONIC_PRINT(DEBUG, "Allocating Lif Info");
37 dbpage_num = ionic_db_page_num(lif, 0);
39 lif->kern_dbpage = ionic_bus_map_dbpage(adapter, dbpage_num);
40 if (!lif->kern_dbpage) {
41 IONIC_PRINT(ERR, "Cannot map dbpage, aborting");
45 lif->info_sz = RTE_ALIGN(sizeof(*lif->info), PAGE_SIZE);
47 lif->info_z = rte_eth_dma_zone_reserve(lif->eth_dev,
48 "lif_info", 0 /* queue_idx*/,
49 lif->info_sz, IONIC_ALIGN, socket_id);
51 IONIC_PRINT(ERR, "Cannot allocate lif info memory");
55 lif->info = lif->info_z->addr;
56 lif->info_pa = lif->info_z->iova;
62 ionic_lif_free(struct ionic_lif *lif)
65 rte_memzone_free(lif->info_z);
71 ionic_lif_init(struct ionic_lif *lif)
73 struct ionic_dev *idev = &lif->adapter->idev;
74 struct ionic_q_init_comp comp;
77 ionic_dev_cmd_lif_init(idev, lif->index, lif->info_pa);
78 err = ionic_dev_cmd_wait_check(idev, IONIC_DEVCMD_TIMEOUT);
79 ionic_dev_cmd_comp(idev, &comp);
83 lif->hw_index = comp.hw_index;
85 lif->state |= IONIC_LIF_F_INITED;
91 ionic_lif_deinit(struct ionic_lif *lif)
93 if (!(lif->state & IONIC_LIF_F_INITED))
96 lif->state &= ~IONIC_LIF_F_INITED;
100 ionic_lif_identify(struct ionic_adapter *adapter)
102 struct ionic_dev *idev = &adapter->idev;
103 struct ionic_identity *ident = &adapter->ident;
106 unsigned int lif_words = sizeof(ident->lif.words) /
107 sizeof(ident->lif.words[0]);
108 unsigned int cmd_words = sizeof(idev->dev_cmd->data) /
109 sizeof(idev->dev_cmd->data[0]);
112 ionic_dev_cmd_lif_identify(idev, IONIC_LIF_TYPE_CLASSIC,
113 IONIC_IDENTITY_VERSION_1);
114 err = ionic_dev_cmd_wait_check(idev, IONIC_DEVCMD_TIMEOUT);
118 nwords = RTE_MIN(lif_words, cmd_words);
119 for (i = 0; i < nwords; i++)
120 ident->lif.words[i] = ioread32(&idev->dev_cmd->data[i]);
122 IONIC_PRINT(INFO, "capabilities 0x%" PRIx64 " ",
123 ident->lif.capabilities);
125 IONIC_PRINT(INFO, "eth.max_ucast_filters 0x%" PRIx32 " ",
126 ident->lif.eth.max_ucast_filters);
127 IONIC_PRINT(INFO, "eth.max_mcast_filters 0x%" PRIx32 " ",
128 ident->lif.eth.max_mcast_filters);
130 IONIC_PRINT(INFO, "eth.features 0x%" PRIx64 " ",
131 ident->lif.eth.config.features);
132 IONIC_PRINT(INFO, "eth.queue_count[IONIC_QTYPE_ADMINQ] 0x%" PRIx32 " ",
133 ident->lif.eth.config.queue_count[IONIC_QTYPE_ADMINQ]);
134 IONIC_PRINT(INFO, "eth.queue_count[IONIC_QTYPE_NOTIFYQ] 0x%" PRIx32 " ",
135 ident->lif.eth.config.queue_count[IONIC_QTYPE_NOTIFYQ]);
136 IONIC_PRINT(INFO, "eth.queue_count[IONIC_QTYPE_RXQ] 0x%" PRIx32 " ",
137 ident->lif.eth.config.queue_count[IONIC_QTYPE_RXQ]);
138 IONIC_PRINT(INFO, "eth.queue_count[IONIC_QTYPE_TXQ] 0x%" PRIx32 " ",
139 ident->lif.eth.config.queue_count[IONIC_QTYPE_TXQ]);
145 ionic_lifs_size(struct ionic_adapter *adapter)
147 struct ionic_identity *ident = &adapter->ident;
148 uint32_t nlifs = ident->dev.nlifs;
149 uint32_t nintrs, dev_nintrs = ident->dev.nintrs;
151 adapter->max_ntxqs_per_lif =
152 ident->lif.eth.config.queue_count[IONIC_QTYPE_TXQ];
153 adapter->max_nrxqs_per_lif =
154 ident->lif.eth.config.queue_count[IONIC_QTYPE_RXQ];
156 nintrs = nlifs * 1 /* notifyq */;
158 if (nintrs > dev_nintrs) {
159 IONIC_PRINT(ERR, "At most %d intr queues supported, minimum required is %u",
164 adapter->nintrs = nintrs;