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