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 int nfp_port_setup_tc(struct net_device *netdev, enum tc_setup_type type, 126 void *type_data); 127 128 static inline bool nfp_port_is_vnic(const struct nfp_port *port) 129 { 130 return port->type == NFP_PORT_PF_PORT || port->type == NFP_PORT_VF_PORT; 131 } 132 133 int 134 nfp_port_set_features(struct net_device *netdev, netdev_features_t features); 135 136 struct nfp_port *nfp_port_from_netdev(struct net_device *netdev); 137 struct nfp_port * 138 nfp_port_from_id(struct nfp_pf *pf, enum nfp_port_type type, unsigned int id); 139 struct nfp_eth_table_port *__nfp_port_get_eth_port(struct nfp_port *port); 140 struct nfp_eth_table_port *nfp_port_get_eth_port(struct nfp_port *port); 141 142 int 143 nfp_port_get_phys_port_name(struct net_device *netdev, char *name, size_t len); 144 int nfp_port_configure(struct net_device *netdev, bool configed); 145 146 struct nfp_port * 147 nfp_port_alloc(struct nfp_app *app, enum nfp_port_type type, 148 struct net_device *netdev); 149 void nfp_port_free(struct nfp_port *port); 150 151 int nfp_port_init_phy_port(struct nfp_pf *pf, struct nfp_app *app, 152 struct nfp_port *port, unsigned int id); 153 154 int nfp_net_refresh_eth_port(struct nfp_port *port); 155 void nfp_net_refresh_port_table(struct nfp_port *port); 156 int nfp_net_refresh_port_table_sync(struct nfp_pf *pf); 157 158 int nfp_devlink_port_register(struct nfp_app *app, struct nfp_port *port); 159 void nfp_devlink_port_unregister(struct nfp_port *port); 160 161 /** 162 * Mac stats (0x0000 - 0x0200) 163 * all counters are 64bit. 164 */ 165 #define NFP_MAC_STATS_BASE 0x0000 166 #define NFP_MAC_STATS_SIZE 0x0200 167 168 #define NFP_MAC_STATS_RX_IN_OCTETS (NFP_MAC_STATS_BASE + 0x000) 169 /* unused 0x008 */ 170 #define NFP_MAC_STATS_RX_FRAME_TOO_LONG_ERRORS (NFP_MAC_STATS_BASE + 0x010) 171 #define NFP_MAC_STATS_RX_RANGE_LENGTH_ERRORS (NFP_MAC_STATS_BASE + 0x018) 172 #define NFP_MAC_STATS_RX_VLAN_RECEIVED_OK (NFP_MAC_STATS_BASE + 0x020) 173 #define NFP_MAC_STATS_RX_IN_ERRORS (NFP_MAC_STATS_BASE + 0x028) 174 #define NFP_MAC_STATS_RX_IN_BROADCAST_PKTS (NFP_MAC_STATS_BASE + 0x030) 175 #define NFP_MAC_STATS_RX_DROP_EVENTS (NFP_MAC_STATS_BASE + 0x038) 176 #define NFP_MAC_STATS_RX_ALIGNMENT_ERRORS (NFP_MAC_STATS_BASE + 0x040) 177 #define NFP_MAC_STATS_RX_PAUSE_MAC_CTRL_FRAMES (NFP_MAC_STATS_BASE + 0x048) 178 #define NFP_MAC_STATS_RX_FRAMES_RECEIVED_OK (NFP_MAC_STATS_BASE + 0x050) 179 #define NFP_MAC_STATS_RX_FRAME_CHECK_SEQUENCE_ERRORS (NFP_MAC_STATS_BASE + 0x058) 180 #define NFP_MAC_STATS_RX_UNICAST_PKTS (NFP_MAC_STATS_BASE + 0x060) 181 #define NFP_MAC_STATS_RX_MULTICAST_PKTS (NFP_MAC_STATS_BASE + 0x068) 182 #define NFP_MAC_STATS_RX_PKTS (NFP_MAC_STATS_BASE + 0x070) 183 #define NFP_MAC_STATS_RX_UNDERSIZE_PKTS (NFP_MAC_STATS_BASE + 0x078) 184 #define NFP_MAC_STATS_RX_PKTS_64_OCTETS (NFP_MAC_STATS_BASE + 0x080) 185 #define NFP_MAC_STATS_RX_PKTS_65_TO_127_OCTETS (NFP_MAC_STATS_BASE + 0x088) 186 #define NFP_MAC_STATS_RX_PKTS_512_TO_1023_OCTETS (NFP_MAC_STATS_BASE + 0x090) 187 #define NFP_MAC_STATS_RX_PKTS_1024_TO_1518_OCTETS (NFP_MAC_STATS_BASE + 0x098) 188 #define NFP_MAC_STATS_RX_JABBERS (NFP_MAC_STATS_BASE + 0x0a0) 189 #define NFP_MAC_STATS_RX_FRAGMENTS (NFP_MAC_STATS_BASE + 0x0a8) 190 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS2 (NFP_MAC_STATS_BASE + 0x0b0) 191 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS3 (NFP_MAC_STATS_BASE + 0x0b8) 192 #define NFP_MAC_STATS_RX_PKTS_128_TO_255_OCTETS (NFP_MAC_STATS_BASE + 0x0c0) 193 #define NFP_MAC_STATS_RX_PKTS_256_TO_511_OCTETS (NFP_MAC_STATS_BASE + 0x0c8) 194 #define NFP_MAC_STATS_RX_PKTS_1519_TO_MAX_OCTETS (NFP_MAC_STATS_BASE + 0x0d0) 195 #define NFP_MAC_STATS_RX_OVERSIZE_PKTS (NFP_MAC_STATS_BASE + 0x0d8) 196 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS0 (NFP_MAC_STATS_BASE + 0x0e0) 197 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS1 (NFP_MAC_STATS_BASE + 0x0e8) 198 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS4 (NFP_MAC_STATS_BASE + 0x0f0) 199 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS5 (NFP_MAC_STATS_BASE + 0x0f8) 200 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS6 (NFP_MAC_STATS_BASE + 0x100) 201 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS7 (NFP_MAC_STATS_BASE + 0x108) 202 #define NFP_MAC_STATS_RX_MAC_CTRL_FRAMES_RECEIVED (NFP_MAC_STATS_BASE + 0x110) 203 #define NFP_MAC_STATS_RX_MAC_HEAD_DROP (NFP_MAC_STATS_BASE + 0x118) 204 /* unused 0x120 */ 205 /* unused 0x128 */ 206 /* unused 0x130 */ 207 #define NFP_MAC_STATS_TX_QUEUE_DROP (NFP_MAC_STATS_BASE + 0x138) 208 #define NFP_MAC_STATS_TX_OUT_OCTETS (NFP_MAC_STATS_BASE + 0x140) 209 /* unused 0x148 */ 210 #define NFP_MAC_STATS_TX_VLAN_TRANSMITTED_OK (NFP_MAC_STATS_BASE + 0x150) 211 #define NFP_MAC_STATS_TX_OUT_ERRORS (NFP_MAC_STATS_BASE + 0x158) 212 #define NFP_MAC_STATS_TX_BROADCAST_PKTS (NFP_MAC_STATS_BASE + 0x160) 213 #define NFP_MAC_STATS_TX_PKTS_64_OCTETS (NFP_MAC_STATS_BASE + 0x168) 214 #define NFP_MAC_STATS_TX_PKTS_256_TO_511_OCTETS (NFP_MAC_STATS_BASE + 0x170) 215 #define NFP_MAC_STATS_TX_PKTS_512_TO_1023_OCTETS (NFP_MAC_STATS_BASE + 0x178) 216 #define NFP_MAC_STATS_TX_PAUSE_MAC_CTRL_FRAMES (NFP_MAC_STATS_BASE + 0x180) 217 #define NFP_MAC_STATS_TX_FRAMES_TRANSMITTED_OK (NFP_MAC_STATS_BASE + 0x188) 218 #define NFP_MAC_STATS_TX_UNICAST_PKTS (NFP_MAC_STATS_BASE + 0x190) 219 #define NFP_MAC_STATS_TX_MULTICAST_PKTS (NFP_MAC_STATS_BASE + 0x198) 220 #define NFP_MAC_STATS_TX_PKTS_65_TO_127_OCTETS (NFP_MAC_STATS_BASE + 0x1a0) 221 #define NFP_MAC_STATS_TX_PKTS_128_TO_255_OCTETS (NFP_MAC_STATS_BASE + 0x1a8) 222 #define NFP_MAC_STATS_TX_PKTS_1024_TO_1518_OCTETS (NFP_MAC_STATS_BASE + 0x1b0) 223 #define NFP_MAC_STATS_TX_PKTS_1519_TO_MAX_OCTETS (NFP_MAC_STATS_BASE + 0x1b8) 224 #define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS0 (NFP_MAC_STATS_BASE + 0x1c0) 225 #define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS1 (NFP_MAC_STATS_BASE + 0x1c8) 226 #define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS4 (NFP_MAC_STATS_BASE + 0x1d0) 227 #define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS5 (NFP_MAC_STATS_BASE + 0x1d8) 228 #define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS2 (NFP_MAC_STATS_BASE + 0x1e0) 229 #define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS3 (NFP_MAC_STATS_BASE + 0x1e8) 230 #define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS6 (NFP_MAC_STATS_BASE + 0x1f0) 231 #define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS7 (NFP_MAC_STATS_BASE + 0x1f8) 232 233 #endif 234