1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
2 /* Copyright (C) 2017-2018 Netronome Systems, Inc. */
3 
4 #ifndef _NFP_PORT_H_
5 #define _NFP_PORT_H_
6 
7 #include <net/devlink.h>
8 
9 struct net_device;
10 struct nfp_app;
11 struct nfp_pf;
12 struct nfp_port;
13 
14 /**
15  * enum nfp_port_type - type of port NFP can switch traffic to
16  * @NFP_PORT_INVALID:	port is invalid, %NFP_PORT_PHYS_PORT transitions to this
17  *			state when port disappears because of FW fault or config
18  *			change
19  * @NFP_PORT_PHYS_PORT:	external NIC port
20  * @NFP_PORT_PF_PORT:	logical port of PCI PF
21  * @NFP_PORT_VF_PORT:	logical port of PCI VF
22  */
23 enum nfp_port_type {
24 	NFP_PORT_INVALID,
25 	NFP_PORT_PHYS_PORT,
26 	NFP_PORT_PF_PORT,
27 	NFP_PORT_VF_PORT,
28 };
29 
30 /**
31  * enum nfp_port_flags - port flags (can be type-specific)
32  * @NFP_PORT_CHANGED:	port state has changed since last eth table refresh;
33  *			for NFP_PORT_PHYS_PORT, never set otherwise; must hold
34  *			rtnl_lock to clear
35  */
36 enum nfp_port_flags {
37 	NFP_PORT_CHANGED = 0,
38 };
39 
40 /**
41  * struct nfp_port - structure representing NFP port
42  * @netdev:	backpointer to associated netdev
43  * @type:	what port type does the entity represent
44  * @flags:	port flags
45  * @tc_offload_cnt:	number of active TC offloads, how offloads are counted
46  *			is not defined, use as a boolean
47  * @app:	backpointer to the app structure
48  * @dl_port:	devlink port structure
49  * @eth_id:	for %NFP_PORT_PHYS_PORT port ID in NFP enumeration scheme
50  * @eth_forced:	for %NFP_PORT_PHYS_PORT port is forced UP or DOWN, don't change
51  * @eth_port:	for %NFP_PORT_PHYS_PORT translated ETH Table port entry
52  * @eth_stats:	for %NFP_PORT_PHYS_PORT MAC stats if available
53  * @pf_id:	for %NFP_PORT_PF_PORT, %NFP_PORT_VF_PORT ID of the PCI PF (0-3)
54  * @vf_id:	for %NFP_PORT_VF_PORT ID of the PCI VF within @pf_id
55  * @pf_split:	for %NFP_PORT_PF_PORT %true if PCI PF has more than one vNIC
56  * @pf_split_id:for %NFP_PORT_PF_PORT ID of PCI PF vNIC (valid if @pf_split)
57  * @vnic:	for %NFP_PORT_PF_PORT, %NFP_PORT_VF_PORT vNIC ctrl memory
58  * @port_list:	entry on pf's list of ports
59  */
60 struct nfp_port {
61 	struct net_device *netdev;
62 	enum nfp_port_type type;
63 
64 	unsigned long flags;
65 	unsigned long tc_offload_cnt;
66 
67 	struct nfp_app *app;
68 
69 	struct devlink_port dl_port;
70 
71 	union {
72 		/* NFP_PORT_PHYS_PORT */
73 		struct {
74 			unsigned int eth_id;
75 			bool eth_forced;
76 			struct nfp_eth_table_port *eth_port;
77 			u8 __iomem *eth_stats;
78 		};
79 		/* NFP_PORT_PF_PORT, NFP_PORT_VF_PORT */
80 		struct {
81 			unsigned int pf_id;
82 			unsigned int vf_id;
83 			bool pf_split;
84 			unsigned int pf_split_id;
85 			u8 __iomem *vnic;
86 		};
87 	};
88 
89 	struct list_head port_list;
90 };
91 
92 extern const struct ethtool_ops nfp_port_ethtool_ops;
93 extern const struct switchdev_ops nfp_port_switchdev_ops;
94 
95 __printf(2, 3) u8 *nfp_pr_et(u8 *data, const char *fmt, ...);
96 
97 int nfp_port_setup_tc(struct net_device *netdev, enum tc_setup_type type,
98 		      void *type_data);
99 
100 static inline bool nfp_port_is_vnic(const struct nfp_port *port)
101 {
102 	return port->type == NFP_PORT_PF_PORT || port->type == NFP_PORT_VF_PORT;
103 }
104 
105 int
106 nfp_port_set_features(struct net_device *netdev, netdev_features_t features);
107 
108 struct nfp_port *nfp_port_from_netdev(struct net_device *netdev);
109 struct nfp_port *
110 nfp_port_from_id(struct nfp_pf *pf, enum nfp_port_type type, unsigned int id);
111 struct nfp_eth_table_port *__nfp_port_get_eth_port(struct nfp_port *port);
112 struct nfp_eth_table_port *nfp_port_get_eth_port(struct nfp_port *port);
113 
114 int
115 nfp_port_get_phys_port_name(struct net_device *netdev, char *name, size_t len);
116 int nfp_port_configure(struct net_device *netdev, bool configed);
117 
118 struct nfp_port *
119 nfp_port_alloc(struct nfp_app *app, enum nfp_port_type type,
120 	       struct net_device *netdev);
121 void nfp_port_free(struct nfp_port *port);
122 
123 int nfp_port_init_phy_port(struct nfp_pf *pf, struct nfp_app *app,
124 			   struct nfp_port *port, unsigned int id);
125 
126 int nfp_net_refresh_eth_port(struct nfp_port *port);
127 void nfp_net_refresh_port_table(struct nfp_port *port);
128 int nfp_net_refresh_port_table_sync(struct nfp_pf *pf);
129 
130 int nfp_devlink_port_register(struct nfp_app *app, struct nfp_port *port);
131 void nfp_devlink_port_unregister(struct nfp_port *port);
132 
133 /**
134  * Mac stats (0x0000 - 0x0200)
135  * all counters are 64bit.
136  */
137 #define NFP_MAC_STATS_BASE                0x0000
138 #define NFP_MAC_STATS_SIZE                0x0200
139 
140 #define NFP_MAC_STATS_RX_IN_OCTETS			(NFP_MAC_STATS_BASE + 0x000)
141 							/* unused 0x008 */
142 #define NFP_MAC_STATS_RX_FRAME_TOO_LONG_ERRORS		(NFP_MAC_STATS_BASE + 0x010)
143 #define NFP_MAC_STATS_RX_RANGE_LENGTH_ERRORS		(NFP_MAC_STATS_BASE + 0x018)
144 #define NFP_MAC_STATS_RX_VLAN_RECEIVED_OK		(NFP_MAC_STATS_BASE + 0x020)
145 #define NFP_MAC_STATS_RX_IN_ERRORS			(NFP_MAC_STATS_BASE + 0x028)
146 #define NFP_MAC_STATS_RX_IN_BROADCAST_PKTS		(NFP_MAC_STATS_BASE + 0x030)
147 #define NFP_MAC_STATS_RX_DROP_EVENTS			(NFP_MAC_STATS_BASE + 0x038)
148 #define NFP_MAC_STATS_RX_ALIGNMENT_ERRORS		(NFP_MAC_STATS_BASE + 0x040)
149 #define NFP_MAC_STATS_RX_PAUSE_MAC_CTRL_FRAMES		(NFP_MAC_STATS_BASE + 0x048)
150 #define NFP_MAC_STATS_RX_FRAMES_RECEIVED_OK		(NFP_MAC_STATS_BASE + 0x050)
151 #define NFP_MAC_STATS_RX_FRAME_CHECK_SEQUENCE_ERRORS	(NFP_MAC_STATS_BASE + 0x058)
152 #define NFP_MAC_STATS_RX_UNICAST_PKTS			(NFP_MAC_STATS_BASE + 0x060)
153 #define NFP_MAC_STATS_RX_MULTICAST_PKTS			(NFP_MAC_STATS_BASE + 0x068)
154 #define NFP_MAC_STATS_RX_PKTS				(NFP_MAC_STATS_BASE + 0x070)
155 #define NFP_MAC_STATS_RX_UNDERSIZE_PKTS			(NFP_MAC_STATS_BASE + 0x078)
156 #define NFP_MAC_STATS_RX_PKTS_64_OCTETS			(NFP_MAC_STATS_BASE + 0x080)
157 #define NFP_MAC_STATS_RX_PKTS_65_TO_127_OCTETS		(NFP_MAC_STATS_BASE + 0x088)
158 #define NFP_MAC_STATS_RX_PKTS_512_TO_1023_OCTETS	(NFP_MAC_STATS_BASE + 0x090)
159 #define NFP_MAC_STATS_RX_PKTS_1024_TO_1518_OCTETS	(NFP_MAC_STATS_BASE + 0x098)
160 #define NFP_MAC_STATS_RX_JABBERS			(NFP_MAC_STATS_BASE + 0x0a0)
161 #define NFP_MAC_STATS_RX_FRAGMENTS			(NFP_MAC_STATS_BASE + 0x0a8)
162 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS2		(NFP_MAC_STATS_BASE + 0x0b0)
163 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS3		(NFP_MAC_STATS_BASE + 0x0b8)
164 #define NFP_MAC_STATS_RX_PKTS_128_TO_255_OCTETS		(NFP_MAC_STATS_BASE + 0x0c0)
165 #define NFP_MAC_STATS_RX_PKTS_256_TO_511_OCTETS		(NFP_MAC_STATS_BASE + 0x0c8)
166 #define NFP_MAC_STATS_RX_PKTS_1519_TO_MAX_OCTETS	(NFP_MAC_STATS_BASE + 0x0d0)
167 #define NFP_MAC_STATS_RX_OVERSIZE_PKTS			(NFP_MAC_STATS_BASE + 0x0d8)
168 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS0		(NFP_MAC_STATS_BASE + 0x0e0)
169 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS1		(NFP_MAC_STATS_BASE + 0x0e8)
170 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS4		(NFP_MAC_STATS_BASE + 0x0f0)
171 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS5		(NFP_MAC_STATS_BASE + 0x0f8)
172 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS6		(NFP_MAC_STATS_BASE + 0x100)
173 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS7		(NFP_MAC_STATS_BASE + 0x108)
174 #define NFP_MAC_STATS_RX_MAC_CTRL_FRAMES_RECEIVED	(NFP_MAC_STATS_BASE + 0x110)
175 #define NFP_MAC_STATS_RX_MAC_HEAD_DROP			(NFP_MAC_STATS_BASE + 0x118)
176 							/* unused 0x120 */
177 							/* unused 0x128 */
178 							/* unused 0x130 */
179 #define NFP_MAC_STATS_TX_QUEUE_DROP			(NFP_MAC_STATS_BASE + 0x138)
180 #define NFP_MAC_STATS_TX_OUT_OCTETS			(NFP_MAC_STATS_BASE + 0x140)
181 							/* unused 0x148 */
182 #define NFP_MAC_STATS_TX_VLAN_TRANSMITTED_OK		(NFP_MAC_STATS_BASE + 0x150)
183 #define NFP_MAC_STATS_TX_OUT_ERRORS			(NFP_MAC_STATS_BASE + 0x158)
184 #define NFP_MAC_STATS_TX_BROADCAST_PKTS			(NFP_MAC_STATS_BASE + 0x160)
185 #define NFP_MAC_STATS_TX_PKTS_64_OCTETS			(NFP_MAC_STATS_BASE + 0x168)
186 #define NFP_MAC_STATS_TX_PKTS_256_TO_511_OCTETS		(NFP_MAC_STATS_BASE + 0x170)
187 #define NFP_MAC_STATS_TX_PKTS_512_TO_1023_OCTETS	(NFP_MAC_STATS_BASE + 0x178)
188 #define NFP_MAC_STATS_TX_PAUSE_MAC_CTRL_FRAMES		(NFP_MAC_STATS_BASE + 0x180)
189 #define NFP_MAC_STATS_TX_FRAMES_TRANSMITTED_OK		(NFP_MAC_STATS_BASE + 0x188)
190 #define NFP_MAC_STATS_TX_UNICAST_PKTS			(NFP_MAC_STATS_BASE + 0x190)
191 #define NFP_MAC_STATS_TX_MULTICAST_PKTS			(NFP_MAC_STATS_BASE + 0x198)
192 #define NFP_MAC_STATS_TX_PKTS_65_TO_127_OCTETS		(NFP_MAC_STATS_BASE + 0x1a0)
193 #define NFP_MAC_STATS_TX_PKTS_128_TO_255_OCTETS		(NFP_MAC_STATS_BASE + 0x1a8)
194 #define NFP_MAC_STATS_TX_PKTS_1024_TO_1518_OCTETS	(NFP_MAC_STATS_BASE + 0x1b0)
195 #define NFP_MAC_STATS_TX_PKTS_1519_TO_MAX_OCTETS	(NFP_MAC_STATS_BASE + 0x1b8)
196 #define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS0		(NFP_MAC_STATS_BASE + 0x1c0)
197 #define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS1		(NFP_MAC_STATS_BASE + 0x1c8)
198 #define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS4		(NFP_MAC_STATS_BASE + 0x1d0)
199 #define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS5		(NFP_MAC_STATS_BASE + 0x1d8)
200 #define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS2		(NFP_MAC_STATS_BASE + 0x1e0)
201 #define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS3		(NFP_MAC_STATS_BASE + 0x1e8)
202 #define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS6		(NFP_MAC_STATS_BASE + 0x1f0)
203 #define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS7		(NFP_MAC_STATS_BASE + 0x1f8)
204 
205 #endif
206