1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Chelsio Communications.
6 #include <rte_ethdev_driver.h>
7 #include <rte_ethdev_pci.h>
8 #include <rte_malloc.h>
10 #include "base/common.h"
11 #include "base/t4_regs.h"
12 #include "base/t4_msg.h"
17 * Figure out how many Ports and Queue Sets we can support. This depends on
18 * knowing our Virtual Function Resources and may be called a second time if
19 * we fall back from MSI-X to MSI Interrupt Mode.
21 static void size_nports_qsets(struct adapter *adapter)
23 struct vf_resources *vfres = &adapter->params.vfres;
24 unsigned int pmask_nports;
27 * The number of "ports" which we support is equal to the number of
28 * Virtual Interfaces with which we've been provisioned.
30 adapter->params.nports = vfres->nvi;
31 if (adapter->params.nports > MAX_NPORTS) {
32 dev_warn(adapter->pdev_dev, "only using %d of %d maximum"
33 " allowed virtual interfaces\n", MAX_NPORTS,
34 adapter->params.nports);
35 adapter->params.nports = MAX_NPORTS;
39 * We may have been provisioned with more VIs than the number of
40 * ports we're allowed to access (our Port Access Rights Mask).
41 * This is obviously a configuration conflict but we don't want to
42 * do anything silly just because of that.
44 pmask_nports = hweight32(adapter->params.vfres.pmask);
45 if (pmask_nports < adapter->params.nports) {
46 dev_warn(adapter->pdev_dev, "only using %d of %d provissioned"
47 " virtual interfaces; limited by Port Access Rights"
48 " mask %#x\n", pmask_nports, adapter->params.nports,
49 adapter->params.vfres.pmask);
50 adapter->params.nports = pmask_nports;
53 cxgbe_configure_max_ethqsets(adapter);
54 if (adapter->sge.max_ethqsets < adapter->params.nports) {
55 dev_warn(adapter->pdev_dev, "only using %d of %d available"
56 " virtual interfaces (too few Queue Sets)\n",
57 adapter->sge.max_ethqsets, adapter->params.nports);
58 adapter->params.nports = adapter->sge.max_ethqsets;
62 void cxgbevf_stats_get(struct port_info *pi, struct port_stats *stats)
64 t4vf_get_port_stats(pi->adapter, pi->pidx, stats);
67 static int adap_init0vf(struct adapter *adapter)
72 err = t4vf_fw_reset(adapter);
74 dev_err(adapter->pdev_dev, "FW reset failed: err=%d\n", err);
79 * Grab basic operational parameters. These will predominantly have
80 * been set up by the Physical Function Driver or will be hard coded
81 * into the adapter. We just have to live with them ... Note that
82 * we _must_ get our VPD parameters before our SGE parameters because
83 * we need to know the adapter's core clock from the VPD in order to
84 * properly decode the SGE Timer Values.
86 err = t4vf_get_dev_params(adapter);
88 dev_err(adapter->pdev_dev, "unable to retrieve adapter"
89 " device parameters: err=%d\n", err);
93 err = t4vf_get_vpd_params(adapter);
95 dev_err(adapter->pdev_dev, "unable to retrieve adapter"
96 " VPD parameters: err=%d\n", err);
100 adapter->pf = t4vf_get_pf_from_vf(adapter);
101 err = t4vf_sge_init(adapter);
103 dev_err(adapter->pdev_dev, "error in sge init\n");
107 err = t4vf_get_rss_glb_config(adapter);
109 dev_err(adapter->pdev_dev, "unable to retrieve adapter"
110 " RSS parameters: err=%d\n", err);
113 if (adapter->params.rss.mode !=
114 FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL) {
115 dev_err(adapter->pdev_dev, "unable to operate with global RSS"
116 " mode %d\n", adapter->params.rss.mode);
120 /* If we're running on newer firmware, let it know that we're
121 * prepared to deal with encapsulated CPL messages. Older
122 * firmware won't understand this and we'll just get
123 * unencapsulated messages ...
125 param = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_PFVF) |
126 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_PFVF_CPLFW4MSG_ENCAP);
128 t4vf_set_params(adapter, 1, ¶m, &val);
131 * Grab our Virtual Interface resource allocation, extract the
132 * features that we're interested in and do a bit of sanity testing on
135 err = t4vf_get_vfres(adapter);
137 dev_err(adapter->pdev_dev, "unable to get virtual interface"
138 " resources: err=%d\n", err);
143 * Check for various parameter sanity issues.
145 if (adapter->params.vfres.pmask == 0) {
146 dev_err(adapter->pdev_dev, "no port access configured\n"
150 if (adapter->params.vfres.nvi == 0) {
151 dev_err(adapter->pdev_dev, "no virtual interfaces configured/"
157 * Initialize nports and max_ethqsets now that we have our Virtual
158 * Function Resources.
160 size_nports_qsets(adapter);
161 adapter->flags |= FW_OK;
165 int cxgbevf_probe(struct adapter *adapter)
167 struct port_info *pi;
172 t4_os_lock_init(&adapter->mbox_lock);
173 TAILQ_INIT(&adapter->mbox_list);
174 err = t4vf_prep_adapter(adapter);
178 if (!is_t4(adapter->params.chip)) {
179 adapter->bar2 = (void *)adapter->pdev->mem_resource[2].addr;
180 if (!adapter->bar2) {
181 dev_err(adapter, "cannot map device bar2 region\n");
187 err = adap_init0vf(adapter);
189 dev_err(adapter, "%s: Adapter initialization failed, error %d\n",
194 pmask = adapter->params.vfres.pmask;
195 for_each_port(adapter, i) {
196 const unsigned int numa_node = rte_socket_id();
197 char name[RTE_ETH_NAME_MAX_LEN];
198 struct rte_eth_dev *eth_dev;
203 port_id = ffs(pmask) - 1;
204 pmask &= ~(1 << port_id);
206 snprintf(name, sizeof(name), "%s_%d",
207 adapter->pdev->device.name, i);
210 /* First port is already allocated by DPDK */
211 eth_dev = adapter->eth_dev;
216 * now do all data allocation - for eth_dev structure,
217 * and internal (private) data for the remaining ports
220 /* reserve an ethdev entry */
221 eth_dev = rte_eth_dev_allocate(name);
226 eth_dev->data->dev_private =
227 rte_zmalloc_socket(name, sizeof(struct port_info),
228 RTE_CACHE_LINE_SIZE, numa_node);
229 if (!eth_dev->data->dev_private)
233 pi = eth_dev->data->dev_private;
234 adapter->port[i] = pi;
235 pi->eth_dev = eth_dev;
236 pi->adapter = adapter;
237 pi->xact_addr_filt = -1;
238 pi->port_id = port_id;
241 pi->eth_dev->device = &adapter->pdev->device;
242 pi->eth_dev->dev_ops = adapter->eth_dev->dev_ops;
243 pi->eth_dev->tx_pkt_burst = adapter->eth_dev->tx_pkt_burst;
244 pi->eth_dev->rx_pkt_burst = adapter->eth_dev->rx_pkt_burst;
246 rte_eth_copy_pci_info(pi->eth_dev, adapter->pdev);
247 pi->eth_dev->data->mac_addrs = rte_zmalloc(name,
248 RTE_ETHER_ADDR_LEN, 0);
249 if (!pi->eth_dev->data->mac_addrs) {
250 dev_err(adapter, "%s: Mem allocation failed for storing mac addr, aborting\n",
257 /* First port will be notified by upper layer */
258 rte_eth_dev_probing_finish(eth_dev);
262 if (adapter->flags & FW_OK) {
263 err = t4vf_port_init(adapter);
265 dev_err(adapter, "%s: t4_port_init failed with err %d\n",
271 cxgbe_cfg_queues(adapter->eth_dev);
272 cxgbe_print_adapter_info(adapter);
273 cxgbe_print_port_info(adapter);
275 adapter->mpstcam = t4_init_mpstcam(adapter);
276 if (!adapter->mpstcam)
278 "VF could not allocate mps tcam table. Continuing\n");
280 err = cxgbe_init_rss(adapter);
286 for_each_port(adapter, i) {
287 pi = adap2pinfo(adapter, i);
289 t4_free_vi(adapter, adapter->mbox, adapter->pf,
291 rte_eth_dev_release_port(pi->eth_dev);