Commit c24ca95f authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller

nfp: make vNIC ctrl memory mapping function reusable

We will soon need to map control vNIC PCI memory as well as data vNIC
memory.  Make the function for mapping areas pointed to by an RTsym
reusable.
Signed-off-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 77ece8d5
...@@ -248,40 +248,37 @@ nfp_net_pf_total_qcs(struct nfp_pf *pf, void __iomem *ctrl_bar, ...@@ -248,40 +248,37 @@ nfp_net_pf_total_qcs(struct nfp_pf *pf, void __iomem *ctrl_bar,
return max_qc - min_qc; return max_qc - min_qc;
} }
static u8 __iomem *nfp_net_pf_map_ctrl_bar(struct nfp_pf *pf) static u8 __iomem *
nfp_net_pf_map_rtsym(struct nfp_pf *pf, const char *name, const char *sym_fmt,
unsigned int min_size, struct nfp_cpp_area **area)
{ {
const struct nfp_rtsym *ctrl_sym; const struct nfp_rtsym *sym;
u8 __iomem *ctrl_bar;
char pf_symbol[256]; char pf_symbol[256];
u8 __iomem *mem;
snprintf(pf_symbol, sizeof(pf_symbol), "_pf%u_net_bar0", snprintf(pf_symbol, sizeof(pf_symbol), sym_fmt,
nfp_cppcore_pcie_unit(pf->cpp)); nfp_cppcore_pcie_unit(pf->cpp));
ctrl_sym = nfp_rtsym_lookup(pf->cpp, pf_symbol); sym = nfp_rtsym_lookup(pf->cpp, pf_symbol);
if (!ctrl_sym) { if (!sym) {
dev_err(&pf->pdev->dev, nfp_err(pf->cpp, "Failed to find PF symbol %s\n", pf_symbol);
"Failed to find PF BAR0 symbol %s\n", pf_symbol); return (u8 __iomem *)ERR_PTR(-ENOENT);
return NULL;
} }
if (ctrl_sym->size < pf->max_data_vnics * NFP_PF_CSR_SLICE_SIZE) { if (sym->size < min_size) {
dev_err(&pf->pdev->dev, nfp_err(pf->cpp, "PF symbol %s too small\n", pf_symbol);
"PF BAR0 too small to contain %d vNICs\n", return (u8 __iomem *)ERR_PTR(-EINVAL);
pf->max_data_vnics);
return NULL;
} }
ctrl_bar = nfp_net_map_area(pf->cpp, "net.ctrl", mem = nfp_net_map_area(pf->cpp, name, sym->domain, sym->target,
ctrl_sym->domain, ctrl_sym->target, sym->addr, sym->size, area);
ctrl_sym->addr, ctrl_sym->size, if (IS_ERR(mem)) {
&pf->data_vnic_bar); nfp_err(pf->cpp, "Failed to map PF symbol %s: %ld\n",
if (IS_ERR(ctrl_bar)) { pf_symbol, PTR_ERR(mem));
dev_err(&pf->pdev->dev, "Failed to map PF BAR0: %ld\n", return mem;
PTR_ERR(ctrl_bar));
return NULL;
} }
return ctrl_bar; return mem;
} }
static void nfp_net_pf_free_vnic(struct nfp_pf *pf, struct nfp_net *nn) static void nfp_net_pf_free_vnic(struct nfp_pf *pf, struct nfp_net *nn)
...@@ -662,10 +659,10 @@ int nfp_net_refresh_eth_port(struct nfp_port *port) ...@@ -662,10 +659,10 @@ int nfp_net_refresh_eth_port(struct nfp_port *port)
*/ */
int nfp_net_pci_probe(struct nfp_pf *pf) int nfp_net_pci_probe(struct nfp_pf *pf)
{ {
u32 ctrl_bar_sz, tx_area_sz, rx_area_sz;
u8 __iomem *ctrl_bar, *tx_bar, *rx_bar; u8 __iomem *ctrl_bar, *tx_bar, *rx_bar;
u32 total_tx_qcs, total_rx_qcs; u32 total_tx_qcs, total_rx_qcs;
struct nfp_net_fw_version fw_ver; struct nfp_net_fw_version fw_ver;
u32 tx_area_sz, rx_area_sz;
u32 start_q; u32 start_q;
int stride; int stride;
int err; int err;
...@@ -685,9 +682,13 @@ int nfp_net_pci_probe(struct nfp_pf *pf) ...@@ -685,9 +682,13 @@ int nfp_net_pci_probe(struct nfp_pf *pf)
goto err_unlock; goto err_unlock;
} }
ctrl_bar = nfp_net_pf_map_ctrl_bar(pf); ctrl_bar_sz = pf->max_data_vnics * NFP_PF_CSR_SLICE_SIZE;
if (!ctrl_bar) { ctrl_bar = nfp_net_pf_map_rtsym(pf, "net.ctrl", "_pf%d_net_bar0",
err = pf->fw_loaded ? -EINVAL : -EPROBE_DEFER; ctrl_bar_sz, &pf->data_vnic_bar);
if (IS_ERR(ctrl_bar)) {
err = PTR_ERR(ctrl_bar);
if (!pf->fw_loaded && err == -ENOENT)
err = -EPROBE_DEFER;
goto err_unlock; goto err_unlock;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment