1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Chelsio Communications.
6 #include <ethdev_driver.h>
7 #include <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"
14 #include "cxgbe_pfvf.h"
18 * Figure out how many Ports and Queue Sets we can support. This depends on
19 * knowing our Virtual Function Resources and may be called a second time if
20 * we fall back from MSI-X to MSI Interrupt Mode.
22 static void size_nports_qsets(struct adapter *adapter)
24 struct vf_resources *vfres = &adapter->params.vfres;
25 unsigned int pmask_nports;
28 * The number of "ports" which we support is equal to the number of
29 * Virtual Interfaces with which we've been provisioned.
31 adapter->params.nports = vfres->nvi;
32 if (adapter->params.nports > MAX_NPORTS) {
33 dev_warn(adapter->pdev_dev, "only using %d of %d maximum"
34 " allowed virtual interfaces\n", MAX_NPORTS,
35 adapter->params.nports);
36 adapter->params.nports = MAX_NPORTS;
40 * We may have been provisioned with more VIs than the number of
41 * ports we're allowed to access (our Port Access Rights Mask).
42 * This is obviously a configuration conflict but we don't want to
43 * do anything silly just because of that.
45 pmask_nports = hweight32(adapter->params.vfres.pmask);
46 if (pmask_nports < adapter->params.nports) {
47 dev_warn(adapter->pdev_dev, "only using %d of %d provissioned"
48 " virtual interfaces; limited by Port Access Rights"
49 " mask %#x\n", pmask_nports, adapter->params.nports,
50 adapter->params.vfres.pmask);
51 adapter->params.nports = pmask_nports;
54 cxgbe_configure_max_ethqsets(adapter);
55 if (adapter->sge.max_ethqsets < adapter->params.nports) {
56 dev_warn(adapter->pdev_dev, "only using %d of %d available"
57 " virtual interfaces (too few Queue Sets)\n",
58 adapter->sge.max_ethqsets, adapter->params.nports);
59 adapter->params.nports = adapter->sge.max_ethqsets;
63 void cxgbevf_stats_get(struct port_info *pi, struct port_stats *stats)
65 t4vf_get_port_stats(pi->adapter, pi->pidx, stats);
68 static int adap_init0vf(struct adapter *adapter)
73 err = t4vf_fw_reset(adapter);
75 dev_err(adapter->pdev_dev, "FW reset failed: err=%d\n", err);
80 * Grab basic operational parameters. These will predominantly have
81 * been set up by the Physical Function Driver or will be hard coded
82 * into the adapter. We just have to live with them ... Note that
83 * we _must_ get our VPD parameters before our SGE parameters because
84 * we need to know the adapter's core clock from the VPD in order to
85 * properly decode the SGE Timer Values.
87 err = t4vf_get_dev_params(adapter);
89 dev_err(adapter->pdev_dev, "unable to retrieve adapter"
90 " device parameters: err=%d\n", err);
94 err = t4vf_get_vpd_params(adapter);
96 dev_err(adapter->pdev_dev, "unable to retrieve adapter"
97 " VPD parameters: err=%d\n", err);
101 adapter->pf = t4vf_get_pf_from_vf(adapter);
102 err = t4vf_sge_init(adapter);
104 dev_err(adapter->pdev_dev, "error in sge init\n");
108 err = t4vf_get_rss_glb_config(adapter);
110 dev_err(adapter->pdev_dev, "unable to retrieve adapter"
111 " RSS parameters: err=%d\n", err);
114 if (adapter->params.rss.mode !=
115 FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL) {
116 dev_err(adapter->pdev_dev, "unable to operate with global RSS"
117 " mode %d\n", adapter->params.rss.mode);
121 /* If we're running on newer firmware, let it know that we're
122 * prepared to deal with encapsulated CPL messages. Older
123 * firmware won't understand this and we'll just get
124 * unencapsulated messages ...
126 param = CXGBE_FW_PARAM_PFVF(CPLFW4MSG_ENCAP);
128 t4vf_set_params(adapter, 1, ¶m, &val);
130 /* Query for max number of packets that can be coalesced for Tx */
131 param = CXGBE_FW_PARAM_PFVF(MAX_PKTS_PER_ETH_TX_PKTS_WR);
132 err = t4vf_query_params(adapter, 1, ¶m, &val);
134 adapter->params.max_tx_coalesce_num = val;
136 adapter->params.max_tx_coalesce_num = ETH_COALESCE_VF_PKT_NUM;
139 * Grab our Virtual Interface resource allocation, extract the
140 * features that we're interested in and do a bit of sanity testing on
143 err = t4vf_get_vfres(adapter);
145 dev_err(adapter->pdev_dev, "unable to get virtual interface"
146 " resources: err=%d\n", err);
151 * Check for various parameter sanity issues.
153 if (adapter->params.vfres.pmask == 0) {
154 dev_err(adapter->pdev_dev, "no port access configured\n"
158 if (adapter->params.vfres.nvi == 0) {
159 dev_err(adapter->pdev_dev, "no virtual interfaces configured/"
165 * Initialize nports and max_ethqsets now that we have our Virtual
166 * Function Resources.
168 size_nports_qsets(adapter);
169 adapter->flags |= FW_OK;
173 int cxgbevf_probe(struct adapter *adapter)
175 struct port_info *pi;
180 t4_os_lock_init(&adapter->mbox_lock);
181 TAILQ_INIT(&adapter->mbox_list);
182 err = t4vf_prep_adapter(adapter);
186 if (!is_t4(adapter->params.chip)) {
187 adapter->bar2 = (void *)adapter->pdev->mem_resource[2].addr;
188 if (!adapter->bar2) {
189 dev_err(adapter, "cannot map device bar2 region\n");
195 err = adap_init0vf(adapter);
197 dev_err(adapter, "%s: Adapter initialization failed, error %d\n",
202 pmask = adapter->params.vfres.pmask;
203 for_each_port(adapter, i) {
204 const unsigned int numa_node = rte_socket_id();
205 char name[RTE_ETH_NAME_MAX_LEN];
206 struct rte_eth_dev *eth_dev;
211 port_id = ffs(pmask) - 1;
212 pmask &= ~(1 << port_id);
214 snprintf(name, sizeof(name), "%s_%d",
215 adapter->pdev->device.name, i);
218 /* First port is already allocated by DPDK */
219 eth_dev = adapter->eth_dev;
224 * now do all data allocation - for eth_dev structure,
225 * and internal (private) data for the remaining ports
228 /* reserve an ethdev entry */
229 eth_dev = rte_eth_dev_allocate(name);
234 eth_dev->data->dev_private =
235 rte_zmalloc_socket(name, sizeof(struct port_info),
236 RTE_CACHE_LINE_SIZE, numa_node);
237 if (!eth_dev->data->dev_private)
241 pi = eth_dev->data->dev_private;
242 adapter->port[i] = pi;
243 pi->eth_dev = eth_dev;
244 pi->adapter = adapter;
245 pi->xact_addr_filt = -1;
246 pi->port_id = port_id;
249 pi->eth_dev->device = &adapter->pdev->device;
250 pi->eth_dev->dev_ops = adapter->eth_dev->dev_ops;
251 pi->eth_dev->tx_pkt_burst = adapter->eth_dev->tx_pkt_burst;
252 pi->eth_dev->rx_pkt_burst = adapter->eth_dev->rx_pkt_burst;
254 rte_eth_copy_pci_info(pi->eth_dev, adapter->pdev);
255 pi->eth_dev->data->mac_addrs = rte_zmalloc(name,
256 RTE_ETHER_ADDR_LEN, 0);
257 if (!pi->eth_dev->data->mac_addrs) {
258 dev_err(adapter, "%s: Mem allocation failed for storing mac addr, aborting\n",
265 /* First port will be notified by upper layer */
266 rte_eth_dev_probing_finish(eth_dev);
270 if (adapter->flags & FW_OK) {
271 err = t4vf_port_init(adapter);
273 dev_err(adapter, "%s: t4_port_init failed with err %d\n",
279 err = cxgbe_cfg_queues(adapter->eth_dev);
283 cxgbe_print_adapter_info(adapter);
284 cxgbe_print_port_info(adapter);
286 adapter->mpstcam = t4_init_mpstcam(adapter);
287 if (!adapter->mpstcam)
289 "VF could not allocate mps tcam table. Continuing\n");
291 err = cxgbe_init_rss(adapter);
297 cxgbe_cfg_queues_free(adapter);
299 for_each_port(adapter, i) {
300 pi = adap2pinfo(adapter, i);
302 t4_free_vi(adapter, adapter->mbox, adapter->pf,
304 rte_eth_dev_release_port(pi->eth_dev);