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 * @app: backpointer to the app structure 76 * @dl_port: devlink port structure 77 * @eth_id: for %NFP_PORT_PHYS_PORT port ID in NFP enumeration scheme 78 * @eth_port: for %NFP_PORT_PHYS_PORT translated ETH Table port entry 79 * @eth_stats: for %NFP_PORT_PHYS_PORT MAC stats if available 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 * @vnic: for %NFP_PORT_PF_PORT, %NFP_PORT_VF_PORT vNIC ctrl memory 83 * @port_list: entry on pf's list of ports 84 */ 85 struct nfp_port { 86 struct net_device *netdev; 87 enum nfp_port_type type; 88 89 unsigned long flags; 90 91 struct nfp_app *app; 92 93 struct devlink_port dl_port; 94 95 union { 96 /* NFP_PORT_PHYS_PORT */ 97 struct { 98 unsigned int eth_id; 99 struct nfp_eth_table_port *eth_port; 100 u8 __iomem *eth_stats; 101 }; 102 /* NFP_PORT_PF_PORT, NFP_PORT_VF_PORT */ 103 struct { 104 unsigned int pf_id; 105 unsigned int vf_id; 106 u8 __iomem *vnic; 107 }; 108 }; 109 110 struct list_head port_list; 111 }; 112 113 extern const struct ethtool_ops nfp_port_ethtool_ops; 114 extern const struct switchdev_ops nfp_port_switchdev_ops; 115 116 int nfp_port_setup_tc(struct net_device *netdev, enum tc_setup_type type, 117 void *type_data); 118 119 static inline bool nfp_port_is_vnic(const struct nfp_port *port) 120 { 121 return port->type == NFP_PORT_PF_PORT || port->type == NFP_PORT_VF_PORT; 122 } 123 124 struct nfp_port *nfp_port_from_netdev(struct net_device *netdev); 125 struct nfp_port * 126 nfp_port_from_id(struct nfp_pf *pf, enum nfp_port_type type, unsigned int id); 127 struct nfp_eth_table_port *__nfp_port_get_eth_port(struct nfp_port *port); 128 struct nfp_eth_table_port *nfp_port_get_eth_port(struct nfp_port *port); 129 130 int 131 nfp_port_get_phys_port_name(struct net_device *netdev, char *name, size_t len); 132 int nfp_port_configure(struct net_device *netdev, bool configed); 133 134 struct nfp_port * 135 nfp_port_alloc(struct nfp_app *app, enum nfp_port_type type, 136 struct net_device *netdev); 137 void nfp_port_free(struct nfp_port *port); 138 139 int nfp_port_init_phy_port(struct nfp_pf *pf, struct nfp_app *app, 140 struct nfp_port *port, unsigned int id); 141 142 int nfp_net_refresh_eth_port(struct nfp_port *port); 143 void nfp_net_refresh_port_table(struct nfp_port *port); 144 int nfp_net_refresh_port_table_sync(struct nfp_pf *pf); 145 146 int nfp_devlink_port_register(struct nfp_app *app, struct nfp_port *port); 147 void nfp_devlink_port_unregister(struct nfp_port *port); 148 149 /** 150 * Mac stats (0x0000 - 0x0200) 151 * all counters are 64bit. 152 */ 153 #define NFP_MAC_STATS_BASE 0x0000 154 #define NFP_MAC_STATS_SIZE 0x0200 155 156 #define NFP_MAC_STATS_RX_IN_OCTETS (NFP_MAC_STATS_BASE + 0x000) 157 /* unused 0x008 */ 158 #define NFP_MAC_STATS_RX_FRAME_TOO_LONG_ERRORS (NFP_MAC_STATS_BASE + 0x010) 159 #define NFP_MAC_STATS_RX_RANGE_LENGTH_ERRORS (NFP_MAC_STATS_BASE + 0x018) 160 #define NFP_MAC_STATS_RX_VLAN_REVEIVE_OK (NFP_MAC_STATS_BASE + 0x020) 161 #define NFP_MAC_STATS_RX_IN_ERRORS (NFP_MAC_STATS_BASE + 0x028) 162 #define NFP_MAC_STATS_RX_IN_BROADCAST_PKTS (NFP_MAC_STATS_BASE + 0x030) 163 #define NFP_MAC_STATS_RX_DROP_EVENTS (NFP_MAC_STATS_BASE + 0x038) 164 #define NFP_MAC_STATS_RX_ALIGNMENT_ERRORS (NFP_MAC_STATS_BASE + 0x040) 165 #define NFP_MAC_STATS_RX_PAUSE_MAC_CTRL_FRAMES (NFP_MAC_STATS_BASE + 0x048) 166 #define NFP_MAC_STATS_RX_FRAMES_RECEIVED_OK (NFP_MAC_STATS_BASE + 0x050) 167 #define NFP_MAC_STATS_RX_FRAME_CHECK_SEQUENCE_ERRORS (NFP_MAC_STATS_BASE + 0x058) 168 #define NFP_MAC_STATS_RX_UNICAST_PKTS (NFP_MAC_STATS_BASE + 0x060) 169 #define NFP_MAC_STATS_RX_MULTICAST_PKTS (NFP_MAC_STATS_BASE + 0x068) 170 #define NFP_MAC_STATS_RX_PKTS (NFP_MAC_STATS_BASE + 0x070) 171 #define NFP_MAC_STATS_RX_UNDERSIZE_PKTS (NFP_MAC_STATS_BASE + 0x078) 172 #define NFP_MAC_STATS_RX_PKTS_64_OCTETS (NFP_MAC_STATS_BASE + 0x080) 173 #define NFP_MAC_STATS_RX_PKTS_65_TO_127_OCTETS (NFP_MAC_STATS_BASE + 0x088) 174 #define NFP_MAC_STATS_RX_PKTS_512_TO_1023_OCTETS (NFP_MAC_STATS_BASE + 0x090) 175 #define NFP_MAC_STATS_RX_PKTS_1024_TO_1518_OCTETS (NFP_MAC_STATS_BASE + 0x098) 176 #define NFP_MAC_STATS_RX_JABBERS (NFP_MAC_STATS_BASE + 0x0a0) 177 #define NFP_MAC_STATS_RX_FRAGMENTS (NFP_MAC_STATS_BASE + 0x0a8) 178 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS2 (NFP_MAC_STATS_BASE + 0x0b0) 179 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS3 (NFP_MAC_STATS_BASE + 0x0b8) 180 #define NFP_MAC_STATS_RX_PKTS_128_TO_255_OCTETS (NFP_MAC_STATS_BASE + 0x0c0) 181 #define NFP_MAC_STATS_RX_PKTS_256_TO_511_OCTETS (NFP_MAC_STATS_BASE + 0x0c8) 182 #define NFP_MAC_STATS_RX_PKTS_1519_TO_MAX_OCTETS (NFP_MAC_STATS_BASE + 0x0d0) 183 #define NFP_MAC_STATS_RX_OVERSIZE_PKTS (NFP_MAC_STATS_BASE + 0x0d8) 184 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS0 (NFP_MAC_STATS_BASE + 0x0e0) 185 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS1 (NFP_MAC_STATS_BASE + 0x0e8) 186 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS4 (NFP_MAC_STATS_BASE + 0x0f0) 187 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS5 (NFP_MAC_STATS_BASE + 0x0f8) 188 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS6 (NFP_MAC_STATS_BASE + 0x100) 189 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS7 (NFP_MAC_STATS_BASE + 0x108) 190 #define NFP_MAC_STATS_RX_MAC_CTRL_FRAMES_RECEIVED (NFP_MAC_STATS_BASE + 0x110) 191 #define NFP_MAC_STATS_RX_MAC_HEAD_DROP (NFP_MAC_STATS_BASE + 0x118) 192 /* unused 0x120 */ 193 /* unused 0x128 */ 194 /* unused 0x130 */ 195 #define NFP_MAC_STATS_TX_QUEUE_DROP (NFP_MAC_STATS_BASE + 0x138) 196 #define NFP_MAC_STATS_TX_OUT_OCTETS (NFP_MAC_STATS_BASE + 0x140) 197 /* unused 0x148 */ 198 #define NFP_MAC_STATS_TX_VLAN_TRANSMITTED_OK (NFP_MAC_STATS_BASE + 0x150) 199 #define NFP_MAC_STATS_TX_OUT_ERRORS (NFP_MAC_STATS_BASE + 0x158) 200 #define NFP_MAC_STATS_TX_BROADCAST_PKTS (NFP_MAC_STATS_BASE + 0x160) 201 #define NFP_MAC_STATS_TX_PKTS_64_OCTETS (NFP_MAC_STATS_BASE + 0x168) 202 #define NFP_MAC_STATS_TX_PKTS_256_TO_511_OCTETS (NFP_MAC_STATS_BASE + 0x170) 203 #define NFP_MAC_STATS_TX_PKTS_512_TO_1023_OCTETS (NFP_MAC_STATS_BASE + 0x178) 204 #define NFP_MAC_STATS_TX_PAUSE_MAC_CTRL_FRAMES (NFP_MAC_STATS_BASE + 0x180) 205 #define NFP_MAC_STATS_TX_FRAMES_TRANSMITTED_OK (NFP_MAC_STATS_BASE + 0x188) 206 #define NFP_MAC_STATS_TX_UNICAST_PKTS (NFP_MAC_STATS_BASE + 0x190) 207 #define NFP_MAC_STATS_TX_MULTICAST_PKTS (NFP_MAC_STATS_BASE + 0x198) 208 #define NFP_MAC_STATS_TX_PKTS_65_TO_127_OCTETS (NFP_MAC_STATS_BASE + 0x1a0) 209 #define NFP_MAC_STATS_TX_PKTS_128_TO_255_OCTETS (NFP_MAC_STATS_BASE + 0x1a8) 210 #define NFP_MAC_STATS_TX_PKTS_1024_TO_1518_OCTETS (NFP_MAC_STATS_BASE + 0x1b0) 211 #define NFP_MAC_STATS_TX_PKTS_1519_TO_MAX_OCTETS (NFP_MAC_STATS_BASE + 0x1b8) 212 #define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS0 (NFP_MAC_STATS_BASE + 0x1c0) 213 #define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS1 (NFP_MAC_STATS_BASE + 0x1c8) 214 #define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS4 (NFP_MAC_STATS_BASE + 0x1d0) 215 #define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS5 (NFP_MAC_STATS_BASE + 0x1d8) 216 #define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS2 (NFP_MAC_STATS_BASE + 0x1e0) 217 #define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS3 (NFP_MAC_STATS_BASE + 0x1e8) 218 #define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS6 (NFP_MAC_STATS_BASE + 0x1f0) 219 #define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS7 (NFP_MAC_STATS_BASE + 0x1f8) 220 221 #endif 222