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