239c5401000c431ee95e2c95ed31fbc1d01b0f5a
[platform/kernel/linux-rpi.git] / drivers / net / ethernet / netronome / nfp / nfp_port.h
1 /*
2  * Copyright (C) 2017 Netronome Systems, Inc.
3  *
4  * This software is dual licensed under the GNU General License Version 2,
5  * June 1991 as shown in the file COPYING in the top-level directory of this
6  * source tree or the BSD 2-Clause License provided below.  You have the
7  * option to license this software under the complete terms of either license.
8  *
9  * The BSD 2-Clause License:
10  *
11  *     Redistribution and use in source and binary forms, with or
12  *     without modification, are permitted provided that the following
13  *     conditions are met:
14  *
15  *      1. Redistributions of source code must retain the above
16  *         copyright notice, this list of conditions and the following
17  *         disclaimer.
18  *
19  *      2. Redistributions in binary form must reproduce the above
20  *         copyright notice, this list of conditions and the following
21  *         disclaimer in the documentation and/or other materials
22  *         provided with the distribution.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31  * SOFTWARE.
32  */
33
34 #ifndef _NFP_PORT_H_
35 #define _NFP_PORT_H_
36
37 #include <net/devlink.h>
38
39 struct tc_to_netdev;
40 struct net_device;
41 struct nfp_app;
42 struct nfp_pf;
43 struct nfp_port;
44
45 /**
46  * enum nfp_port_type - type of port NFP can switch traffic to
47  * @NFP_PORT_INVALID:   port is invalid, %NFP_PORT_PHYS_PORT transitions to this
48  *                      state when port disappears because of FW fault or config
49  *                      change
50  * @NFP_PORT_PHYS_PORT: external NIC port
51  * @NFP_PORT_PF_PORT:   logical port of PCI PF
52  * @NFP_PORT_VF_PORT:   logical port of PCI VF
53  */
54 enum nfp_port_type {
55         NFP_PORT_INVALID,
56         NFP_PORT_PHYS_PORT,
57         NFP_PORT_PF_PORT,
58         NFP_PORT_VF_PORT,
59 };
60
61 /**
62  * enum nfp_port_flags - port flags (can be type-specific)
63  * @NFP_PORT_CHANGED:   port state has changed since last eth table refresh;
64  *                      for NFP_PORT_PHYS_PORT, never set otherwise; must hold
65  *                      rtnl_lock to clear
66  */
67 enum nfp_port_flags {
68         NFP_PORT_CHANGED = 0,
69 };
70
71 /**
72  * struct nfp_port - structure representing NFP port
73  * @netdev:     backpointer to associated netdev
74  * @type:       what port type does the entity represent
75  * @flags:      port flags
76  * @app:        backpointer to the app structure
77  * @dl_port:    devlink port structure
78  * @eth_id:     for %NFP_PORT_PHYS_PORT port ID in NFP enumeration scheme
79  * @eth_port:   for %NFP_PORT_PHYS_PORT translated ETH Table port entry
80  * @pf_id:      for %NFP_PORT_PF_PORT, %NFP_PORT_VF_PORT ID of the PCI PF (0-3)
81  * @vf_id:      for %NFP_PORT_VF_PORT ID of the PCI VF within @pf_id
82  * @port_list:  entry on pf's list of ports
83  */
84 struct nfp_port {
85         struct net_device *netdev;
86         enum nfp_port_type type;
87
88         unsigned long flags;
89
90         struct nfp_app *app;
91
92         struct devlink_port dl_port;
93
94         union {
95                 /* NFP_PORT_PHYS_PORT */
96                 struct {
97                         unsigned int eth_id;
98                         struct nfp_eth_table_port *eth_port;
99                 };
100                 /* NFP_PORT_PF_PORT, NFP_PORT_VF_PORT */
101                 struct {
102                         unsigned int pf_id;
103                         unsigned int vf_id;
104                 };
105         };
106
107         struct list_head port_list;
108 };
109
110 extern const struct switchdev_ops nfp_port_switchdev_ops;
111
112 int nfp_port_setup_tc(struct net_device *netdev, enum tc_setup_type type,
113                       u32 handle, u32 chain_index, __be16 proto,
114                       struct tc_to_netdev *tc);
115
116 struct nfp_port *nfp_port_from_netdev(struct net_device *netdev);
117 struct nfp_port *
118 nfp_port_from_id(struct nfp_pf *pf, enum nfp_port_type type, unsigned int id);
119 struct nfp_eth_table_port *__nfp_port_get_eth_port(struct nfp_port *port);
120 struct nfp_eth_table_port *nfp_port_get_eth_port(struct nfp_port *port);
121
122 int
123 nfp_port_get_phys_port_name(struct net_device *netdev, char *name, size_t len);
124 int nfp_port_configure(struct net_device *netdev, bool configed);
125
126 struct nfp_port *
127 nfp_port_alloc(struct nfp_app *app, enum nfp_port_type type,
128                struct net_device *netdev);
129 void nfp_port_free(struct nfp_port *port);
130
131 int nfp_port_init_phy_port(struct nfp_pf *pf, struct nfp_app *app,
132                            struct nfp_port *port, unsigned int id);
133
134 int nfp_net_refresh_eth_port(struct nfp_port *port);
135 void nfp_net_refresh_port_table(struct nfp_port *port);
136 int nfp_net_refresh_port_table_sync(struct nfp_pf *pf);
137
138 int nfp_devlink_port_register(struct nfp_app *app, struct nfp_port *port);
139 void nfp_devlink_port_unregister(struct nfp_port *port);
140
141 /**
142  * Mac stats (0x0000 - 0x0200)
143  * all counters are 64bit.
144  */
145 #define NFP_MAC_STATS_BASE                0x0000
146 #define NFP_MAC_STATS_SIZE                0x0200
147
148 #define NFP_MAC_STATS_RX_IN_OCTETS                      (NFP_MAC_STATS_BASE + 0x000)
149 #define NFP_MAC_STATS_RX_FRAME_TOO_LONG_ERRORS          (NFP_MAC_STATS_BASE + 0x010)
150 #define NFP_MAC_STATS_RX_RANGE_LENGTH_ERRORS            (NFP_MAC_STATS_BASE + 0x018)
151 #define NFP_MAC_STATS_RX_VLAN_REVEIVE_OK                (NFP_MAC_STATS_BASE + 0x020)
152 #define NFP_MAC_STATS_RX_IN_ERRORS                      (NFP_MAC_STATS_BASE + 0x028)
153 #define NFP_MAC_STATS_RX_IN_BROADCAST_PKTS              (NFP_MAC_STATS_BASE + 0x030)
154 #define NFP_MAC_STATS_RX_STATS_DROP_EVENTS              (NFP_MAC_STATS_BASE + 0x038)
155 #define NFP_MAC_STATS_RX_ALIGNMENT_ERRORS               (NFP_MAC_STATS_BASE + 0x040)
156 #define NFP_MAC_STATS_RX_PAUSE_MAC_CTRL_FRAMES          (NFP_MAC_STATS_BASE + 0x048)
157 #define NFP_MAC_STATS_RX_FRAMES_RECEIVED_OK             (NFP_MAC_STATS_BASE + 0x050)
158 #define NFP_MAC_STATS_RX_FRAME_CHECK_SEQUENCE_ERRORS    (NFP_MAC_STATS_BASE + 0x058)
159 #define NFP_MAC_STATS_RX_UNICAST_PKTS                   (NFP_MAC_STATS_BASE + 0x060)
160 #define NFP_MAC_STATS_RX_MULTICAST_PKTS                 (NFP_MAC_STATS_BASE + 0x068)
161 #define NFP_MAC_STATS_RX_STATS_PKTS                     (NFP_MAC_STATS_BASE + 0x070)
162 #define NFP_MAC_STATS_RX_STATS_UNDERSIZE_PKTS           (NFP_MAC_STATS_BASE + 0x078)
163 #define NFP_MAC_STATS_RX_STATS_PKTS_64_OCTETS           (NFP_MAC_STATS_BASE + 0x080)
164 #define NFP_MAC_STATS_RX_STATS_PKTS_65_TO_127_OCTETS    (NFP_MAC_STATS_BASE + 0x088)
165 #define NFP_MAC_STATS_RX_STATS_PKTS_512_TO_1023_OCTETS  (NFP_MAC_STATS_BASE + 0x090)
166 #define NFP_MAC_STATS_RX_STATS_PKTS_1024_TO_1518_OCTETS (NFP_MAC_STATS_BASE + 0x098)
167 #define NFP_MAC_STATS_RX_STATS_JABBERS                  (NFP_MAC_STATS_BASE + 0x0a0)
168 #define NFP_MAC_STATS_RX_STATS_FRAGMENTS                (NFP_MAC_STATS_BASE + 0x0a8)
169 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS2            (NFP_MAC_STATS_BASE + 0x0b0)
170 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS3            (NFP_MAC_STATS_BASE + 0x0b8)
171 #define NFP_MAC_STATS_RX_STATS_PKTS_128_TO_255_OCTETS   (NFP_MAC_STATS_BASE + 0x0c0)
172 #define NFP_MAC_STATS_RX_STATS_PKTS_256_TO_511_OCTETS   (NFP_MAC_STATS_BASE + 0x0c8)
173 #define NFP_MAC_STATS_RX_STATS_PKTS_1519_TO_MAX_OCTETS  (NFP_MAC_STATS_BASE + 0x0d0)
174 #define NFP_MAC_STATS_RX_OVERSIZE_PKTS                  (NFP_MAC_STATS_BASE + 0x0d8)
175 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS0            (NFP_MAC_STATS_BASE + 0x0e0)
176 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS1            (NFP_MAC_STATS_BASE + 0x0e8)
177 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS4            (NFP_MAC_STATS_BASE + 0x0f0)
178 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS5            (NFP_MAC_STATS_BASE + 0x0f8)
179 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS6            (NFP_MAC_STATS_BASE + 0x100)
180 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS7            (NFP_MAC_STATS_BASE + 0x108)
181 #define NFP_MAC_STATS_RX_MAC_CTRL_FRAMES_RECEIVED       (NFP_MAC_STATS_BASE + 0x110)
182 #define NFP_MAC_STATS_RX_MAC_HEAD_DROP                  (NFP_MAC_STATS_BASE + 0x118)
183
184 #define NFP_MAC_STATS_TX_QUEUE_DROP                     (NFP_MAC_STATS_BASE + 0x138)
185 #define NFP_MAC_STATS_TX_OUT_OCTETS                     (NFP_MAC_STATS_BASE + 0x140)
186 #define NFP_MAC_STATS_TX_VLAN_TRANSMITTED_OK            (NFP_MAC_STATS_BASE + 0x150)
187 #define NFP_MAC_STATS_TX_OUT_ERRORS                     (NFP_MAC_STATS_BASE + 0x158)
188 #define NFP_MAC_STATS_TX_BROADCAST_PKTS                 (NFP_MAC_STATS_BASE + 0x160)
189 #define NFP_MAC_STATS_TX_PKTS_64_OCTETS                 (NFP_MAC_STATS_BASE + 0x168)
190 #define NFP_MAC_STATS_TX_PKTS_256_TO_511_OCTETS         (NFP_MAC_STATS_BASE + 0x170)
191 #define NFP_MAC_STATS_TX_PKTS_512_TO_1023_OCTETS        (NFP_MAC_STATS_BASE + 0x178)
192 #define NFP_MAC_STATS_TX_PAUSE_MAC_CTRL_FRAMES          (NFP_MAC_STATS_BASE + 0x180)
193 #define NFP_MAC_STATS_TX_FRAMES_TRANSMITTED_OK          (NFP_MAC_STATS_BASE + 0x188)
194 #define NFP_MAC_STATS_TX_UNICAST_PKTS                   (NFP_MAC_STATS_BASE + 0x190)
195 #define NFP_MAC_STATS_TX_MULTICAST_PKTS                 (NFP_MAC_STATS_BASE + 0x198)
196 #define NFP_MAC_STATS_TX_PKTS_65_TO_127_OCTETS          (NFP_MAC_STATS_BASE + 0x1a0)
197 #define NFP_MAC_STATS_TX_PKTS_127_TO_512_OCTETS         (NFP_MAC_STATS_BASE + 0x1a8)
198 #define NFP_MAC_STATS_TX_PKTS_128_TO_1518_OCTETS        (NFP_MAC_STATS_BASE + 0x1b0)
199 #define NFP_MAC_STATS_TX_PKTS_1518_TO_MAX_OCTETS        (NFP_MAC_STATS_BASE + 0x1b8)
200
201 #endif