Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
0002 /* Copyright (C) 2017-2018 Netronome Systems, Inc. */
0003 
0004 #ifndef _NFP_PORT_H_
0005 #define _NFP_PORT_H_
0006 
0007 #include <net/devlink.h>
0008 
0009 struct net_device;
0010 struct netdev_phys_item_id;
0011 struct nfp_app;
0012 struct nfp_pf;
0013 struct nfp_port;
0014 
0015 /**
0016  * enum nfp_port_type - type of port NFP can switch traffic to
0017  * @NFP_PORT_INVALID:   port is invalid, %NFP_PORT_PHYS_PORT transitions to this
0018  *          state when port disappears because of FW fault or config
0019  *          change
0020  * @NFP_PORT_PHYS_PORT: external NIC port
0021  * @NFP_PORT_PF_PORT:   logical port of PCI PF
0022  * @NFP_PORT_VF_PORT:   logical port of PCI VF
0023  */
0024 enum nfp_port_type {
0025     NFP_PORT_INVALID,
0026     NFP_PORT_PHYS_PORT,
0027     NFP_PORT_PF_PORT,
0028     NFP_PORT_VF_PORT,
0029 };
0030 
0031 /**
0032  * enum nfp_port_flags - port flags (can be type-specific)
0033  * @NFP_PORT_CHANGED:   port state has changed since last eth table refresh;
0034  *          for NFP_PORT_PHYS_PORT, never set otherwise; must hold
0035  *          rtnl_lock to clear
0036  */
0037 enum nfp_port_flags {
0038     NFP_PORT_CHANGED = 0,
0039 };
0040 
0041 /**
0042  * struct nfp_port - structure representing NFP port
0043  * @netdev: backpointer to associated netdev
0044  * @type:   what port type does the entity represent
0045  * @flags:  port flags
0046  * @tc_offload_cnt: number of active TC offloads, how offloads are counted
0047  *          is not defined, use as a boolean
0048  * @app:    backpointer to the app structure
0049  * @dl_port:    devlink port structure
0050  * @eth_id: for %NFP_PORT_PHYS_PORT port ID in NFP enumeration scheme
0051  * @eth_forced: for %NFP_PORT_PHYS_PORT port is forced UP or DOWN, don't change
0052  * @eth_port:   for %NFP_PORT_PHYS_PORT translated ETH Table port entry
0053  * @eth_stats:  for %NFP_PORT_PHYS_PORT MAC stats if available
0054  * @pf_id:  for %NFP_PORT_PF_PORT, %NFP_PORT_VF_PORT ID of the PCI PF (0-3)
0055  * @vf_id:  for %NFP_PORT_VF_PORT ID of the PCI VF within @pf_id
0056  * @pf_split:   for %NFP_PORT_PF_PORT %true if PCI PF has more than one vNIC
0057  * @pf_split_id:for %NFP_PORT_PF_PORT ID of PCI PF vNIC (valid if @pf_split)
0058  * @vnic:   for %NFP_PORT_PF_PORT, %NFP_PORT_VF_PORT vNIC ctrl memory
0059  * @port_list:  entry on pf's list of ports
0060  */
0061 struct nfp_port {
0062     struct net_device *netdev;
0063     enum nfp_port_type type;
0064 
0065     unsigned long flags;
0066     unsigned long tc_offload_cnt;
0067 
0068     struct nfp_app *app;
0069 
0070     struct devlink_port dl_port;
0071 
0072     union {
0073         /* NFP_PORT_PHYS_PORT */
0074         struct {
0075             unsigned int eth_id;
0076             bool eth_forced;
0077             struct nfp_eth_table_port *eth_port;
0078             u8 __iomem *eth_stats;
0079         };
0080         /* NFP_PORT_PF_PORT, NFP_PORT_VF_PORT */
0081         struct {
0082             unsigned int pf_id;
0083             unsigned int vf_id;
0084             bool pf_split;
0085             unsigned int pf_split_id;
0086             u8 __iomem *vnic;
0087         };
0088     };
0089 
0090     struct list_head port_list;
0091 };
0092 
0093 extern const struct ethtool_ops nfp_port_ethtool_ops;
0094 
0095 int nfp_port_setup_tc(struct net_device *netdev, enum tc_setup_type type,
0096               void *type_data);
0097 
0098 static inline bool nfp_port_is_vnic(const struct nfp_port *port)
0099 {
0100     return port->type == NFP_PORT_PF_PORT || port->type == NFP_PORT_VF_PORT;
0101 }
0102 
0103 int
0104 nfp_port_set_features(struct net_device *netdev, netdev_features_t features);
0105 
0106 struct nfp_port *nfp_port_from_netdev(struct net_device *netdev);
0107 int nfp_port_get_port_parent_id(struct net_device *netdev,
0108                 struct netdev_phys_item_id *ppid);
0109 struct nfp_eth_table_port *__nfp_port_get_eth_port(struct nfp_port *port);
0110 struct nfp_eth_table_port *nfp_port_get_eth_port(struct nfp_port *port);
0111 
0112 int
0113 nfp_port_get_phys_port_name(struct net_device *netdev, char *name, size_t len);
0114 int nfp_port_configure(struct net_device *netdev, bool configed);
0115 
0116 struct nfp_port *
0117 nfp_port_alloc(struct nfp_app *app, enum nfp_port_type type,
0118            struct net_device *netdev);
0119 void nfp_port_free(struct nfp_port *port);
0120 
0121 int nfp_port_init_phy_port(struct nfp_pf *pf, struct nfp_app *app,
0122                struct nfp_port *port, unsigned int id);
0123 
0124 int nfp_net_refresh_eth_port(struct nfp_port *port);
0125 void nfp_net_refresh_port_table(struct nfp_port *port);
0126 int nfp_net_refresh_port_table_sync(struct nfp_pf *pf);
0127 
0128 int nfp_devlink_port_register(struct nfp_app *app, struct nfp_port *port);
0129 void nfp_devlink_port_unregister(struct nfp_port *port);
0130 void nfp_devlink_port_type_eth_set(struct nfp_port *port);
0131 void nfp_devlink_port_type_clear(struct nfp_port *port);
0132 
0133 /* Mac stats (0x0000 - 0x0200)
0134  * all counters are 64bit.
0135  */
0136 #define NFP_MAC_STATS_BASE                0x0000
0137 #define NFP_MAC_STATS_SIZE                0x0200
0138 
0139 #define NFP_MAC_STATS_RX_IN_OCTETS          (NFP_MAC_STATS_BASE + 0x000)
0140                             /* unused 0x008 */
0141 #define NFP_MAC_STATS_RX_FRAME_TOO_LONG_ERRORS      (NFP_MAC_STATS_BASE + 0x010)
0142 #define NFP_MAC_STATS_RX_RANGE_LENGTH_ERRORS        (NFP_MAC_STATS_BASE + 0x018)
0143 #define NFP_MAC_STATS_RX_VLAN_RECEIVED_OK       (NFP_MAC_STATS_BASE + 0x020)
0144 #define NFP_MAC_STATS_RX_IN_ERRORS          (NFP_MAC_STATS_BASE + 0x028)
0145 #define NFP_MAC_STATS_RX_IN_BROADCAST_PKTS      (NFP_MAC_STATS_BASE + 0x030)
0146 #define NFP_MAC_STATS_RX_DROP_EVENTS            (NFP_MAC_STATS_BASE + 0x038)
0147 #define NFP_MAC_STATS_RX_ALIGNMENT_ERRORS       (NFP_MAC_STATS_BASE + 0x040)
0148 #define NFP_MAC_STATS_RX_PAUSE_MAC_CTRL_FRAMES      (NFP_MAC_STATS_BASE + 0x048)
0149 #define NFP_MAC_STATS_RX_FRAMES_RECEIVED_OK     (NFP_MAC_STATS_BASE + 0x050)
0150 #define NFP_MAC_STATS_RX_FRAME_CHECK_SEQUENCE_ERRORS    (NFP_MAC_STATS_BASE + 0x058)
0151 #define NFP_MAC_STATS_RX_UNICAST_PKTS           (NFP_MAC_STATS_BASE + 0x060)
0152 #define NFP_MAC_STATS_RX_MULTICAST_PKTS         (NFP_MAC_STATS_BASE + 0x068)
0153 #define NFP_MAC_STATS_RX_PKTS               (NFP_MAC_STATS_BASE + 0x070)
0154 #define NFP_MAC_STATS_RX_UNDERSIZE_PKTS         (NFP_MAC_STATS_BASE + 0x078)
0155 #define NFP_MAC_STATS_RX_PKTS_64_OCTETS         (NFP_MAC_STATS_BASE + 0x080)
0156 #define NFP_MAC_STATS_RX_PKTS_65_TO_127_OCTETS      (NFP_MAC_STATS_BASE + 0x088)
0157 #define NFP_MAC_STATS_RX_PKTS_512_TO_1023_OCTETS    (NFP_MAC_STATS_BASE + 0x090)
0158 #define NFP_MAC_STATS_RX_PKTS_1024_TO_1518_OCTETS   (NFP_MAC_STATS_BASE + 0x098)
0159 #define NFP_MAC_STATS_RX_JABBERS            (NFP_MAC_STATS_BASE + 0x0a0)
0160 #define NFP_MAC_STATS_RX_FRAGMENTS          (NFP_MAC_STATS_BASE + 0x0a8)
0161 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS2        (NFP_MAC_STATS_BASE + 0x0b0)
0162 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS3        (NFP_MAC_STATS_BASE + 0x0b8)
0163 #define NFP_MAC_STATS_RX_PKTS_128_TO_255_OCTETS     (NFP_MAC_STATS_BASE + 0x0c0)
0164 #define NFP_MAC_STATS_RX_PKTS_256_TO_511_OCTETS     (NFP_MAC_STATS_BASE + 0x0c8)
0165 #define NFP_MAC_STATS_RX_PKTS_1519_TO_MAX_OCTETS    (NFP_MAC_STATS_BASE + 0x0d0)
0166 #define NFP_MAC_STATS_RX_OVERSIZE_PKTS          (NFP_MAC_STATS_BASE + 0x0d8)
0167 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS0        (NFP_MAC_STATS_BASE + 0x0e0)
0168 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS1        (NFP_MAC_STATS_BASE + 0x0e8)
0169 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS4        (NFP_MAC_STATS_BASE + 0x0f0)
0170 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS5        (NFP_MAC_STATS_BASE + 0x0f8)
0171 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS6        (NFP_MAC_STATS_BASE + 0x100)
0172 #define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS7        (NFP_MAC_STATS_BASE + 0x108)
0173 #define NFP_MAC_STATS_RX_MAC_CTRL_FRAMES_RECEIVED   (NFP_MAC_STATS_BASE + 0x110)
0174 #define NFP_MAC_STATS_RX_MAC_HEAD_DROP          (NFP_MAC_STATS_BASE + 0x118)
0175                             /* unused 0x120 */
0176                             /* unused 0x128 */
0177                             /* unused 0x130 */
0178 #define NFP_MAC_STATS_TX_QUEUE_DROP         (NFP_MAC_STATS_BASE + 0x138)
0179 #define NFP_MAC_STATS_TX_OUT_OCTETS         (NFP_MAC_STATS_BASE + 0x140)
0180                             /* unused 0x148 */
0181 #define NFP_MAC_STATS_TX_VLAN_TRANSMITTED_OK        (NFP_MAC_STATS_BASE + 0x150)
0182 #define NFP_MAC_STATS_TX_OUT_ERRORS         (NFP_MAC_STATS_BASE + 0x158)
0183 #define NFP_MAC_STATS_TX_BROADCAST_PKTS         (NFP_MAC_STATS_BASE + 0x160)
0184 #define NFP_MAC_STATS_TX_PKTS_64_OCTETS         (NFP_MAC_STATS_BASE + 0x168)
0185 #define NFP_MAC_STATS_TX_PKTS_256_TO_511_OCTETS     (NFP_MAC_STATS_BASE + 0x170)
0186 #define NFP_MAC_STATS_TX_PKTS_512_TO_1023_OCTETS    (NFP_MAC_STATS_BASE + 0x178)
0187 #define NFP_MAC_STATS_TX_PAUSE_MAC_CTRL_FRAMES      (NFP_MAC_STATS_BASE + 0x180)
0188 #define NFP_MAC_STATS_TX_FRAMES_TRANSMITTED_OK      (NFP_MAC_STATS_BASE + 0x188)
0189 #define NFP_MAC_STATS_TX_UNICAST_PKTS           (NFP_MAC_STATS_BASE + 0x190)
0190 #define NFP_MAC_STATS_TX_MULTICAST_PKTS         (NFP_MAC_STATS_BASE + 0x198)
0191 #define NFP_MAC_STATS_TX_PKTS_65_TO_127_OCTETS      (NFP_MAC_STATS_BASE + 0x1a0)
0192 #define NFP_MAC_STATS_TX_PKTS_128_TO_255_OCTETS     (NFP_MAC_STATS_BASE + 0x1a8)
0193 #define NFP_MAC_STATS_TX_PKTS_1024_TO_1518_OCTETS   (NFP_MAC_STATS_BASE + 0x1b0)
0194 #define NFP_MAC_STATS_TX_PKTS_1519_TO_MAX_OCTETS    (NFP_MAC_STATS_BASE + 0x1b8)
0195 #define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS0        (NFP_MAC_STATS_BASE + 0x1c0)
0196 #define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS1        (NFP_MAC_STATS_BASE + 0x1c8)
0197 #define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS4        (NFP_MAC_STATS_BASE + 0x1d0)
0198 #define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS5        (NFP_MAC_STATS_BASE + 0x1d8)
0199 #define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS2        (NFP_MAC_STATS_BASE + 0x1e0)
0200 #define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS3        (NFP_MAC_STATS_BASE + 0x1e8)
0201 #define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS6        (NFP_MAC_STATS_BASE + 0x1f0)
0202 #define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS7        (NFP_MAC_STATS_BASE + 0x1f8)
0203 
0204 #endif