Skip to content

Commit a595018

Browse files
shorman-netronomedavem330
authored andcommitted
nfp: map mac_stats and vf_cfg BARs
If present map mac_stats and vf_cfg BARs. These will be used by representor netdevs to read statistics for phys port and vf representors. Also provide defines describing the layout of the mac_stats area. Similar defines are already present for the cf_cfg area. Based in part on work by Jakub Kicinski. Signed-off-by: Simon Horman <[email protected]> Reviewed-by: Jakub Kicinski <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a7ceb99 commit a595018

File tree

5 files changed

+164
-33
lines changed

5 files changed

+164
-33
lines changed

drivers/net/ethernet/netronome/nfp/nfp_main.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ struct nfp_rtsym_table;
6868
* @data_vnic_bar: Pointer to the CPP area for the data vNICs' BARs
6969
* @ctrl_vnic_bar: Pointer to the CPP area for the ctrl vNIC's BAR
7070
* @qc_area: Pointer to the CPP area for the queues
71+
* @mac_stats_bar: Pointer to the CPP area for the MAC stats
72+
* @mac_stats_mem: Pointer to mapped MAC stats area
73+
* @vf_cfg_bar: Pointer to the CPP area for the VF configuration BAR
74+
* @vf_cfg_mem: Pointer to mapped VF configuration area
7175
* @irq_entries: Array of MSI-X entries for all vNICs
7276
* @limit_vfs: Number of VFs supported by firmware (~0 for PCI limit)
7377
* @num_vfs: Number of SR-IOV VFs enabled
@@ -97,6 +101,10 @@ struct nfp_pf {
97101
struct nfp_cpp_area *data_vnic_bar;
98102
struct nfp_cpp_area *ctrl_vnic_bar;
99103
struct nfp_cpp_area *qc_area;
104+
struct nfp_cpp_area *mac_stats_bar;
105+
u8 __iomem *mac_stats_mem;
106+
struct nfp_cpp_area *vf_cfg_bar;
107+
u8 __iomem *vf_cfg_mem;
100108

101109
struct msix_entry *irq_entries;
102110

drivers/net/ethernet/netronome/nfp/nfp_net_main.c

Lines changed: 90 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,8 @@ nfp_net_pf_map_rtsym(struct nfp_pf *pf, const char *name, const char *sym_fmt,
235235
nfp_cppcore_pcie_unit(pf->cpp));
236236

237237
sym = nfp_rtsym_lookup(pf->rtbl, pf_symbol);
238-
if (!sym) {
239-
nfp_err(pf->cpp, "Failed to find PF symbol %s\n", pf_symbol);
238+
if (!sym)
240239
return (u8 __iomem *)ERR_PTR(-ENOENT);
241-
}
242240

243241
if (sym->size < min_size) {
244242
nfp_err(pf->cpp, "PF symbol %s too small\n", pf_symbol);
@@ -486,6 +484,7 @@ nfp_net_pf_app_init(struct nfp_pf *pf, u8 __iomem *qc_bar, unsigned int stride)
486484
NFP_PF_CSR_SLICE_SIZE,
487485
&pf->ctrl_vnic_bar);
488486
if (IS_ERR(ctrl_bar)) {
487+
nfp_err(pf->cpp, "Failed to find data vNIC memory symbol\n");
489488
err = PTR_ERR(ctrl_bar);
490489
goto err_free;
491490
}
@@ -570,18 +569,89 @@ static void nfp_net_pf_app_stop(struct nfp_pf *pf)
570569
nfp_net_pf_app_stop_ctrl(pf);
571570
}
572571

572+
static void nfp_net_pci_unmap_mem(struct nfp_pf *pf)
573+
{
574+
if (pf->vf_cfg_bar)
575+
nfp_cpp_area_release_free(pf->vf_cfg_bar);
576+
if (pf->mac_stats_bar)
577+
nfp_cpp_area_release_free(pf->mac_stats_bar);
578+
nfp_cpp_area_release_free(pf->qc_area);
579+
nfp_cpp_area_release_free(pf->data_vnic_bar);
580+
}
581+
582+
static int nfp_net_pci_map_mem(struct nfp_pf *pf)
583+
{
584+
u32 ctrl_bar_sz;
585+
u8 __iomem *mem;
586+
int err;
587+
588+
ctrl_bar_sz = pf->max_data_vnics * NFP_PF_CSR_SLICE_SIZE;
589+
mem = nfp_net_pf_map_rtsym(pf, "net.ctrl", "_pf%d_net_bar0",
590+
ctrl_bar_sz, &pf->data_vnic_bar);
591+
if (IS_ERR(mem)) {
592+
nfp_err(pf->cpp, "Failed to find data vNIC memory symbol\n");
593+
err = PTR_ERR(mem);
594+
if (!pf->fw_loaded && err == -ENOENT)
595+
err = -EPROBE_DEFER;
596+
return err;
597+
}
598+
599+
pf->mac_stats_mem = nfp_net_pf_map_rtsym(pf, "net.macstats",
600+
"_mac_stats",
601+
NFP_MAC_STATS_SIZE *
602+
(pf->eth_tbl->max_index + 1),
603+
&pf->mac_stats_bar);
604+
if (IS_ERR(pf->mac_stats_mem)) {
605+
if (PTR_ERR(pf->mac_stats_mem) != -ENOENT) {
606+
err = PTR_ERR(pf->mac_stats_mem);
607+
goto err_unmap_ctrl;
608+
}
609+
pf->mac_stats_mem = NULL;
610+
}
611+
612+
pf->vf_cfg_mem = nfp_net_pf_map_rtsym(pf, "net.vfcfg",
613+
"_pf%d_net_vf_bar",
614+
NFP_NET_CFG_BAR_SZ *
615+
pf->limit_vfs, &pf->vf_cfg_bar);
616+
if (IS_ERR(pf->vf_cfg_mem)) {
617+
if (PTR_ERR(pf->vf_cfg_mem) != -ENOENT) {
618+
err = PTR_ERR(pf->vf_cfg_mem);
619+
goto err_unmap_mac_stats;
620+
}
621+
pf->vf_cfg_mem = NULL;
622+
}
623+
624+
mem = nfp_net_map_area(pf->cpp, "net.qc", 0, 0,
625+
NFP_PCIE_QUEUE(0), NFP_QCP_QUEUE_AREA_SZ,
626+
&pf->qc_area);
627+
if (IS_ERR(mem)) {
628+
nfp_err(pf->cpp, "Failed to map Queue Controller area.\n");
629+
err = PTR_ERR(mem);
630+
goto err_unmap_vf_cfg;
631+
}
632+
633+
return 0;
634+
635+
err_unmap_vf_cfg:
636+
if (pf->vf_cfg_bar)
637+
nfp_cpp_area_release_free(pf->vf_cfg_bar);
638+
err_unmap_mac_stats:
639+
if (pf->mac_stats_bar)
640+
nfp_cpp_area_release_free(pf->mac_stats_bar);
641+
err_unmap_ctrl:
642+
nfp_cpp_area_release_free(pf->data_vnic_bar);
643+
return err;
644+
}
645+
573646
static void nfp_net_pci_remove_finish(struct nfp_pf *pf)
574647
{
575648
nfp_net_pf_app_stop(pf);
576649
/* stop app first, to avoid double free of ctrl vNIC's ddir */
577650
nfp_net_debugfs_dir_clean(&pf->ddir);
578651

579652
nfp_net_pf_free_irqs(pf);
580-
581653
nfp_net_pf_app_clean(pf);
582-
583-
nfp_cpp_area_release_free(pf->qc_area);
584-
nfp_cpp_area_release_free(pf->data_vnic_bar);
654+
nfp_net_pci_unmap_mem(pf);
585655
}
586656

587657
static int
@@ -706,7 +776,6 @@ int nfp_net_pci_probe(struct nfp_pf *pf)
706776
{
707777
struct nfp_net_fw_version fw_ver;
708778
u8 __iomem *ctrl_bar, *qc_bar;
709-
u32 ctrl_bar_sz;
710779
int stride;
711780
int err;
712781

@@ -725,22 +794,23 @@ int nfp_net_pci_probe(struct nfp_pf *pf)
725794
goto err_unlock;
726795
}
727796

728-
ctrl_bar_sz = pf->max_data_vnics * NFP_PF_CSR_SLICE_SIZE;
729-
ctrl_bar = nfp_net_pf_map_rtsym(pf, "net.ctrl", "_pf%d_net_bar0",
730-
ctrl_bar_sz, &pf->data_vnic_bar);
731-
if (IS_ERR(ctrl_bar)) {
732-
err = PTR_ERR(ctrl_bar);
733-
if (!pf->fw_loaded && err == -ENOENT)
734-
err = -EPROBE_DEFER;
797+
err = nfp_net_pci_map_mem(pf);
798+
if (err)
735799
goto err_unlock;
800+
801+
ctrl_bar = nfp_cpp_area_iomem(pf->data_vnic_bar);
802+
qc_bar = nfp_cpp_area_iomem(pf->qc_area);
803+
if (!ctrl_bar || !qc_bar) {
804+
err = -EIO;
805+
goto err_unmap;
736806
}
737807

738808
nfp_net_get_fw_version(&fw_ver, ctrl_bar);
739809
if (fw_ver.resv || fw_ver.class != NFP_NET_CFG_VERSION_CLASS_GENERIC) {
740810
nfp_err(pf->cpp, "Unknown Firmware ABI %d.%d.%d.%d\n",
741811
fw_ver.resv, fw_ver.class, fw_ver.major, fw_ver.minor);
742812
err = -EINVAL;
743-
goto err_ctrl_unmap;
813+
goto err_unmap;
744814
}
745815

746816
/* Determine stride */
@@ -757,23 +827,13 @@ int nfp_net_pci_probe(struct nfp_pf *pf)
757827
fw_ver.resv, fw_ver.class,
758828
fw_ver.major, fw_ver.minor);
759829
err = -EINVAL;
760-
goto err_ctrl_unmap;
830+
goto err_unmap;
761831
}
762832
}
763833

764-
/* Map queues */
765-
qc_bar = nfp_net_map_area(pf->cpp, "net.qc", 0, 0,
766-
NFP_PCIE_QUEUE(0), NFP_QCP_QUEUE_AREA_SZ,
767-
&pf->qc_area);
768-
if (IS_ERR(qc_bar)) {
769-
nfp_err(pf->cpp, "Failed to map Queue Controller area.\n");
770-
err = PTR_ERR(qc_bar);
771-
goto err_ctrl_unmap;
772-
}
773-
774834
err = nfp_net_pf_app_init(pf, qc_bar, stride);
775835
if (err)
776-
goto err_unmap_qc;
836+
goto err_unmap;
777837

778838
pf->ddir = nfp_net_debugfs_device_add(pf->pdev);
779839

@@ -807,10 +867,8 @@ int nfp_net_pci_probe(struct nfp_pf *pf)
807867
err_clean_ddir:
808868
nfp_net_debugfs_dir_clean(&pf->ddir);
809869
nfp_net_pf_app_clean(pf);
810-
err_unmap_qc:
811-
nfp_cpp_area_release_free(pf->qc_area);
812-
err_ctrl_unmap:
813-
nfp_cpp_area_release_free(pf->data_vnic_bar);
870+
err_unmap:
871+
nfp_net_pci_unmap_mem(pf);
814872
err_unlock:
815873
mutex_unlock(&pf->lock);
816874
cancel_work_sync(&pf->port_refresh_work);

drivers/net/ethernet/netronome/nfp/nfp_port.h

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,64 @@ int nfp_net_refresh_port_table_sync(struct nfp_pf *pf);
114114
int nfp_devlink_port_register(struct nfp_app *app, struct nfp_port *port);
115115
void nfp_devlink_port_unregister(struct nfp_port *port);
116116

117+
/**
118+
* Mac stats (0x0000 - 0x0200)
119+
* all counters are 64bit.
120+
*/
121+
#define NFP_MAC_STATS_BASE 0x0000
122+
#define NFP_MAC_STATS_SIZE 0x0200
123+
124+
#define NFP_MAC_STATS_RX_IN_OCTETS (NFP_MAC_STATS_BASE + 0x000)
125+
#define NFP_MAC_STATS_RX_FRAME_TOO_LONG_ERRORS (NFP_MAC_STATS_BASE + 0x010)
126+
#define NFP_MAC_STATS_RX_RANGE_LENGTH_ERRORS (NFP_MAC_STATS_BASE + 0x018)
127+
#define NFP_MAC_STATS_RX_VLAN_REVEIVE_OK (NFP_MAC_STATS_BASE + 0x020)
128+
#define NFP_MAC_STATS_RX_IN_ERRORS (NFP_MAC_STATS_BASE + 0x028)
129+
#define NFP_MAC_STATS_RX_IN_BROADCAST_PKTS (NFP_MAC_STATS_BASE + 0x030)
130+
#define NFP_MAC_STATS_RX_STATS_DROP_EVENTS (NFP_MAC_STATS_BASE + 0x038)
131+
#define NFP_MAC_STATS_RX_ALIGNMENT_ERRORS (NFP_MAC_STATS_BASE + 0x040)
132+
#define NFP_MAC_STATS_RX_PAUSE_MAC_CTRL_FRAMES (NFP_MAC_STATS_BASE + 0x048)
133+
#define NFP_MAC_STATS_RX_FRAMES_RECEIVED_OK (NFP_MAC_STATS_BASE + 0x050)
134+
#define NFP_MAC_STATS_RX_FRAME_CHECK_SEQUENCE_ERRORS (NFP_MAC_STATS_BASE + 0x058)
135+
#define NFP_MAC_STATS_RX_UNICAST_PKTS (NFP_MAC_STATS_BASE + 0x060)
136+
#define NFP_MAC_STATS_RX_MULTICAST_PKTS (NFP_MAC_STATS_BASE + 0x068)
137+
#define NFP_MAC_STATS_RX_STATS_PKTS (NFP_MAC_STATS_BASE + 0x070)
138+
#define NFP_MAC_STATS_RX_STATS_UNDERSIZE_PKTS (NFP_MAC_STATS_BASE + 0x078)
139+
#define NFP_MAC_STATS_RX_STATS_PKTS_64_OCTETS (NFP_MAC_STATS_BASE + 0x080)
140+
#define NFP_MAC_STATS_RX_STATS_PKTS_65_TO_127_OCTETS (NFP_MAC_STATS_BASE + 0x088)
141+
#define NFP_MAC_STATS_RX_STATS_PKTS_512_TO_1023_OCTETS (NFP_MAC_STATS_BASE + 0x090)
142+
#define NFP_MAC_STATS_RX_STATS_PKTS_1024_TO_1518_OCTETS (NFP_MAC_STATS_BASE + 0x098)
143+
#define NFP_MAC_STATS_RX_STATS_JABBERS (NFP_MAC_STATS_BASE + 0x0a0)
144+
#define NFP_MAC_STATS_RX_STATS_FRAGMENTS (NFP_MAC_STATS_BASE + 0x0a8)
145+
#define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS2 (NFP_MAC_STATS_BASE + 0x0b0)
146+
#define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS3 (NFP_MAC_STATS_BASE + 0x0b8)
147+
#define NFP_MAC_STATS_RX_STATS_PKTS_128_TO_255_OCTETS (NFP_MAC_STATS_BASE + 0x0c0)
148+
#define NFP_MAC_STATS_RX_STATS_PKTS_256_TO_511_OCTETS (NFP_MAC_STATS_BASE + 0x0c8)
149+
#define NFP_MAC_STATS_RX_STATS_PKTS_1519_TO_MAX_OCTETS (NFP_MAC_STATS_BASE + 0x0d0)
150+
#define NFP_MAC_STATS_RX_OVERSIZE_PKTS (NFP_MAC_STATS_BASE + 0x0d8)
151+
#define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS0 (NFP_MAC_STATS_BASE + 0x0e0)
152+
#define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS1 (NFP_MAC_STATS_BASE + 0x0e8)
153+
#define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS4 (NFP_MAC_STATS_BASE + 0x0f0)
154+
#define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS5 (NFP_MAC_STATS_BASE + 0x0f8)
155+
#define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS6 (NFP_MAC_STATS_BASE + 0x100)
156+
#define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS7 (NFP_MAC_STATS_BASE + 0x108)
157+
#define NFP_MAC_STATS_RX_MAC_CTRL_FRAMES_RECEIVED (NFP_MAC_STATS_BASE + 0x110)
158+
#define NFP_MAC_STATS_RX_MAC_HEAD_DROP (NFP_MAC_STATS_BASE + 0x118)
159+
160+
#define NFP_MAC_STATS_TX_QUEUE_DROP (NFP_MAC_STATS_BASE + 0x138)
161+
#define NFP_MAC_STATS_TX_OUT_OCTETS (NFP_MAC_STATS_BASE + 0x140)
162+
#define NFP_MAC_STATS_TX_VLAN_TRANSMITTED_OK (NFP_MAC_STATS_BASE + 0x150)
163+
#define NFP_MAC_STATS_TX_OUT_ERRORS (NFP_MAC_STATS_BASE + 0x158)
164+
#define NFP_MAC_STATS_TX_BROADCAST_PKTS (NFP_MAC_STATS_BASE + 0x160)
165+
#define NFP_MAC_STATS_TX_PKTS_64_OCTETS (NFP_MAC_STATS_BASE + 0x168)
166+
#define NFP_MAC_STATS_TX_PKTS_256_TO_511_OCTETS (NFP_MAC_STATS_BASE + 0x170)
167+
#define NFP_MAC_STATS_TX_PKTS_512_TO_1023_OCTETS (NFP_MAC_STATS_BASE + 0x178)
168+
#define NFP_MAC_STATS_TX_PAUSE_MAC_CTRL_FRAMES (NFP_MAC_STATS_BASE + 0x180)
169+
#define NFP_MAC_STATS_TX_FRAMES_TRANSMITTED_OK (NFP_MAC_STATS_BASE + 0x188)
170+
#define NFP_MAC_STATS_TX_UNICAST_PKTS (NFP_MAC_STATS_BASE + 0x190)
171+
#define NFP_MAC_STATS_TX_MULTICAST_PKTS (NFP_MAC_STATS_BASE + 0x198)
172+
#define NFP_MAC_STATS_TX_PKTS_65_TO_127_OCTETS (NFP_MAC_STATS_BASE + 0x1a0)
173+
#define NFP_MAC_STATS_TX_PKTS_127_TO_512_OCTETS (NFP_MAC_STATS_BASE + 0x1a8)
174+
#define NFP_MAC_STATS_TX_PKTS_128_TO_1518_OCTETS (NFP_MAC_STATS_BASE + 0x1b0)
175+
#define NFP_MAC_STATS_TX_PKTS_1518_TO_MAX_OCTETS (NFP_MAC_STATS_BASE + 0x1b8)
176+
117177
#endif

drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ enum nfp_eth_aneg {
7676
/**
7777
* struct nfp_eth_table - ETH table information
7878
* @count: number of table entries
79+
* @max_index: max of @index fields of all @ports
7980
* @ports: table of ports
8081
*
8182
* @eth_index: port index according to legacy ethX numbering
@@ -101,6 +102,7 @@ enum nfp_eth_aneg {
101102
*/
102103
struct nfp_eth_table {
103104
unsigned int count;
105+
unsigned int max_index;
104106
struct nfp_eth_table_port {
105107
unsigned int eth_index;
106108
unsigned int index;

drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp_eth.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,9 @@ nfp_eth_calc_port_geometry(struct nfp_cpp *cpp, struct nfp_eth_table *table)
190190
{
191191
unsigned int i, j;
192192

193-
for (i = 0; i < table->count; i++)
193+
for (i = 0; i < table->count; i++) {
194+
table->max_index = max(table->max_index, table->ports[i].index);
195+
194196
for (j = 0; j < table->count; j++) {
195197
if (table->ports[i].label_port !=
196198
table->ports[j].label_port)
@@ -208,6 +210,7 @@ nfp_eth_calc_port_geometry(struct nfp_cpp *cpp, struct nfp_eth_table *table)
208210

209211
table->ports[i].is_split = true;
210212
}
213+
}
211214
}
212215

213216
static void

0 commit comments

Comments
 (0)