2018-10-11 08:57:42 -07:00
/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
/* Copyright (C) 2017-2018 Netronome Systems, Inc. */
2017-05-22 10:59:28 -07:00
# ifndef _NFP_PORT_H_
# define _NFP_PORT_H_
2017-05-26 01:03:34 -07:00
# include <net/devlink.h>
2017-05-22 10:59:28 -07:00
struct net_device ;
2019-02-06 09:45:41 -08:00
struct netdev_phys_item_id ;
2017-05-22 10:59:28 -07:00
struct nfp_app ;
2017-05-26 01:03:36 -07:00
struct nfp_pf ;
2017-05-22 10:59:28 -07:00
struct nfp_port ;
/**
* enum nfp_port_type - type of port NFP can switch traffic to
* @ NFP_PORT_INVALID : port is invalid , % NFP_PORT_PHYS_PORT transitions to this
* state when port disappears because of FW fault or config
* change
* @ NFP_PORT_PHYS_PORT : external NIC port
2017-06-27 00:50:20 -07:00
* @ NFP_PORT_PF_PORT : logical port of PCI PF
* @ NFP_PORT_VF_PORT : logical port of PCI VF
2017-05-22 10:59:28 -07:00
*/
enum nfp_port_type {
NFP_PORT_INVALID ,
NFP_PORT_PHYS_PORT ,
2017-06-27 00:50:20 -07:00
NFP_PORT_PF_PORT ,
NFP_PORT_VF_PORT ,
2017-05-22 10:59:28 -07:00
} ;
2017-05-22 10:59:30 -07:00
/**
* enum nfp_port_flags - port flags ( can be type - specific )
* @ NFP_PORT_CHANGED : port state has changed since last eth table refresh ;
* for NFP_PORT_PHYS_PORT , never set otherwise ; must hold
* rtnl_lock to clear
*/
enum nfp_port_flags {
NFP_PORT_CHANGED = 0 ,
} ;
2017-05-22 10:59:28 -07:00
/**
* struct nfp_port - structure representing NFP port
* @ netdev : backpointer to associated netdev
* @ type : what port type does the entity represent
2017-05-22 10:59:30 -07:00
* @ flags : port flags
2018-02-07 20:55:24 -08:00
* @ tc_offload_cnt : number of active TC offloads , how offloads are counted
* is not defined , use as a boolean
2017-05-22 10:59:28 -07:00
* @ app : backpointer to the app structure
2017-05-26 01:03:34 -07:00
* @ dl_port : devlink port structure
2017-05-22 10:59:28 -07:00
* @ eth_id : for % NFP_PORT_PHYS_PORT port ID in NFP enumeration scheme
2018-05-21 22:12:53 -07:00
* @ eth_forced : for % NFP_PORT_PHYS_PORT port is forced UP or DOWN , don ' t change
2017-05-22 10:59:28 -07:00
* @ eth_port : for % NFP_PORT_PHYS_PORT translated ETH Table port entry
2017-08-18 15:48:17 -07:00
* @ eth_stats : for % NFP_PORT_PHYS_PORT MAC stats if available
2017-06-27 00:50:20 -07:00
* @ pf_id : for % NFP_PORT_PF_PORT , % NFP_PORT_VF_PORT ID of the PCI PF ( 0 - 3 )
* @ vf_id : for % NFP_PORT_VF_PORT ID of the PCI VF within @ pf_id
2018-05-21 22:12:54 -07:00
* @ pf_split : for % NFP_PORT_PF_PORT % true if PCI PF has more than one vNIC
* @ pf_split_id : for % NFP_PORT_PF_PORT ID of PCI PF vNIC ( valid if @ pf_split )
2017-08-18 15:48:19 -07:00
* @ vnic : for % NFP_PORT_PF_PORT , % NFP_PORT_VF_PORT vNIC ctrl memory
2017-05-22 10:59:31 -07:00
* @ port_list : entry on pf ' s list of ports
2017-05-22 10:59:28 -07:00
*/
struct nfp_port {
struct net_device * netdev ;
enum nfp_port_type type ;
2017-05-22 10:59:30 -07:00
unsigned long flags ;
2018-02-07 20:55:24 -08:00
unsigned long tc_offload_cnt ;
2017-05-22 10:59:30 -07:00
2017-05-22 10:59:28 -07:00
struct nfp_app * app ;
2017-05-26 01:03:34 -07:00
struct devlink_port dl_port ;
2017-06-27 00:50:20 -07:00
union {
/* NFP_PORT_PHYS_PORT */
struct {
unsigned int eth_id ;
2018-05-21 22:12:53 -07:00
bool eth_forced ;
2017-06-27 00:50:20 -07:00
struct nfp_eth_table_port * eth_port ;
2017-08-18 15:48:17 -07:00
u8 __iomem * eth_stats ;
2017-06-27 00:50:20 -07:00
} ;
/* NFP_PORT_PF_PORT, NFP_PORT_VF_PORT */
struct {
unsigned int pf_id ;
unsigned int vf_id ;
2018-05-21 22:12:54 -07:00
bool pf_split ;
unsigned int pf_split_id ;
2017-08-18 15:48:19 -07:00
u8 __iomem * vnic ;
2017-06-27 00:50:20 -07:00
} ;
} ;
2017-05-22 10:59:31 -07:00
struct list_head port_list ;
2017-05-22 10:59:28 -07:00
} ;
2017-08-18 15:48:11 -07:00
extern const struct ethtool_ops nfp_port_ethtool_ops ;
2017-06-29 22:08:12 +02:00
2018-05-25 21:53:32 -07:00
__printf ( 2 , 3 ) u8 * nfp_pr_et ( u8 * data , const char * fmt , . . . ) ;
2017-08-07 10:15:17 +02:00
int nfp_port_setup_tc ( struct net_device * netdev , enum tc_setup_type type ,
2017-08-07 10:15:32 +02:00
void * type_data ) ;
2017-06-29 22:08:13 +02:00
2017-08-18 15:48:20 -07:00
static inline bool nfp_port_is_vnic ( const struct nfp_port * port )
{
return port - > type = = NFP_PORT_PF_PORT | | port - > type = = NFP_PORT_VF_PORT ;
}
2018-02-07 20:55:24 -08:00
int
nfp_port_set_features ( struct net_device * netdev , netdev_features_t features ) ;
2017-05-22 10:59:28 -07:00
struct nfp_port * nfp_port_from_netdev ( struct net_device * netdev ) ;
2019-02-06 09:45:41 -08:00
int nfp_port_get_port_parent_id ( struct net_device * netdev ,
struct netdev_phys_item_id * ppid ) ;
2017-05-26 01:03:36 -07:00
struct nfp_port *
nfp_port_from_id ( struct nfp_pf * pf , enum nfp_port_type type , unsigned int id ) ;
2017-05-22 10:59:28 -07:00
struct nfp_eth_table_port * __nfp_port_get_eth_port ( struct nfp_port * port ) ;
2017-05-22 10:59:34 -07:00
struct nfp_eth_table_port * nfp_port_get_eth_port ( struct nfp_port * port ) ;
2017-05-22 10:59:28 -07:00
int
nfp_port_get_phys_port_name ( struct net_device * netdev , char * name , size_t len ) ;
2017-07-25 00:51:08 -07:00
int nfp_port_configure ( struct net_device * netdev , bool configed ) ;
2017-05-22 10:59:28 -07:00
struct nfp_port *
nfp_port_alloc ( struct nfp_app * app , enum nfp_port_type type ,
struct net_device * netdev ) ;
void nfp_port_free ( struct nfp_port * port ) ;
2017-06-23 22:12:00 +02:00
int nfp_port_init_phy_port ( struct nfp_pf * pf , struct nfp_app * app ,
struct nfp_port * port , unsigned int id ) ;
2017-05-22 10:59:28 -07:00
int nfp_net_refresh_eth_port ( struct nfp_port * port ) ;
void nfp_net_refresh_port_table ( struct nfp_port * port ) ;
2017-05-26 01:03:36 -07:00
int nfp_net_refresh_port_table_sync ( struct nfp_pf * pf ) ;
2017-05-22 10:59:28 -07:00
2017-05-26 01:03:34 -07:00
int nfp_devlink_port_register ( struct nfp_app * app , struct nfp_port * port ) ;
void nfp_devlink_port_unregister ( struct nfp_port * port ) ;
2019-03-24 11:14:34 +01:00
void nfp_devlink_port_type_eth_set ( struct nfp_port * port ) ;
void nfp_devlink_port_type_clear ( struct nfp_port * port ) ;
2017-05-26 01:03:34 -07:00
2017-06-23 22:12:01 +02:00
/**
* Mac stats ( 0x0000 - 0x0200 )
* all counters are 64 bit .
*/
# define NFP_MAC_STATS_BASE 0x0000
# define NFP_MAC_STATS_SIZE 0x0200
# define NFP_MAC_STATS_RX_IN_OCTETS (NFP_MAC_STATS_BASE + 0x000)
2017-08-18 15:48:18 -07:00
/* unused 0x008 */
2017-06-23 22:12:01 +02:00
# define NFP_MAC_STATS_RX_FRAME_TOO_LONG_ERRORS (NFP_MAC_STATS_BASE + 0x010)
# define NFP_MAC_STATS_RX_RANGE_LENGTH_ERRORS (NFP_MAC_STATS_BASE + 0x018)
2017-11-16 17:06:40 -08:00
# define NFP_MAC_STATS_RX_VLAN_RECEIVED_OK (NFP_MAC_STATS_BASE + 0x020)
2017-06-23 22:12:01 +02:00
# define NFP_MAC_STATS_RX_IN_ERRORS (NFP_MAC_STATS_BASE + 0x028)
# define NFP_MAC_STATS_RX_IN_BROADCAST_PKTS (NFP_MAC_STATS_BASE + 0x030)
2017-08-18 15:48:18 -07:00
# define NFP_MAC_STATS_RX_DROP_EVENTS (NFP_MAC_STATS_BASE + 0x038)
2017-06-23 22:12:01 +02:00
# define NFP_MAC_STATS_RX_ALIGNMENT_ERRORS (NFP_MAC_STATS_BASE + 0x040)
# define NFP_MAC_STATS_RX_PAUSE_MAC_CTRL_FRAMES (NFP_MAC_STATS_BASE + 0x048)
# define NFP_MAC_STATS_RX_FRAMES_RECEIVED_OK (NFP_MAC_STATS_BASE + 0x050)
# define NFP_MAC_STATS_RX_FRAME_CHECK_SEQUENCE_ERRORS (NFP_MAC_STATS_BASE + 0x058)
# define NFP_MAC_STATS_RX_UNICAST_PKTS (NFP_MAC_STATS_BASE + 0x060)
# define NFP_MAC_STATS_RX_MULTICAST_PKTS (NFP_MAC_STATS_BASE + 0x068)
2017-08-18 15:48:18 -07:00
# define NFP_MAC_STATS_RX_PKTS (NFP_MAC_STATS_BASE + 0x070)
# define NFP_MAC_STATS_RX_UNDERSIZE_PKTS (NFP_MAC_STATS_BASE + 0x078)
# define NFP_MAC_STATS_RX_PKTS_64_OCTETS (NFP_MAC_STATS_BASE + 0x080)
# define NFP_MAC_STATS_RX_PKTS_65_TO_127_OCTETS (NFP_MAC_STATS_BASE + 0x088)
# define NFP_MAC_STATS_RX_PKTS_512_TO_1023_OCTETS (NFP_MAC_STATS_BASE + 0x090)
# define NFP_MAC_STATS_RX_PKTS_1024_TO_1518_OCTETS (NFP_MAC_STATS_BASE + 0x098)
# define NFP_MAC_STATS_RX_JABBERS (NFP_MAC_STATS_BASE + 0x0a0)
# define NFP_MAC_STATS_RX_FRAGMENTS (NFP_MAC_STATS_BASE + 0x0a8)
2017-06-23 22:12:01 +02:00
# define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS2 (NFP_MAC_STATS_BASE + 0x0b0)
# define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS3 (NFP_MAC_STATS_BASE + 0x0b8)
2017-08-18 15:48:18 -07:00
# define NFP_MAC_STATS_RX_PKTS_128_TO_255_OCTETS (NFP_MAC_STATS_BASE + 0x0c0)
# define NFP_MAC_STATS_RX_PKTS_256_TO_511_OCTETS (NFP_MAC_STATS_BASE + 0x0c8)
# define NFP_MAC_STATS_RX_PKTS_1519_TO_MAX_OCTETS (NFP_MAC_STATS_BASE + 0x0d0)
2017-06-23 22:12:01 +02:00
# define NFP_MAC_STATS_RX_OVERSIZE_PKTS (NFP_MAC_STATS_BASE + 0x0d8)
# define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS0 (NFP_MAC_STATS_BASE + 0x0e0)
# define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS1 (NFP_MAC_STATS_BASE + 0x0e8)
# define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS4 (NFP_MAC_STATS_BASE + 0x0f0)
# define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS5 (NFP_MAC_STATS_BASE + 0x0f8)
# define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS6 (NFP_MAC_STATS_BASE + 0x100)
# define NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS7 (NFP_MAC_STATS_BASE + 0x108)
# define NFP_MAC_STATS_RX_MAC_CTRL_FRAMES_RECEIVED (NFP_MAC_STATS_BASE + 0x110)
# define NFP_MAC_STATS_RX_MAC_HEAD_DROP (NFP_MAC_STATS_BASE + 0x118)
2017-08-18 15:48:18 -07:00
/* unused 0x120 */
/* unused 0x128 */
/* unused 0x130 */
2017-06-23 22:12:01 +02:00
# define NFP_MAC_STATS_TX_QUEUE_DROP (NFP_MAC_STATS_BASE + 0x138)
# define NFP_MAC_STATS_TX_OUT_OCTETS (NFP_MAC_STATS_BASE + 0x140)
2017-08-18 15:48:18 -07:00
/* unused 0x148 */
2017-06-23 22:12:01 +02:00
# define NFP_MAC_STATS_TX_VLAN_TRANSMITTED_OK (NFP_MAC_STATS_BASE + 0x150)
# define NFP_MAC_STATS_TX_OUT_ERRORS (NFP_MAC_STATS_BASE + 0x158)
# define NFP_MAC_STATS_TX_BROADCAST_PKTS (NFP_MAC_STATS_BASE + 0x160)
# define NFP_MAC_STATS_TX_PKTS_64_OCTETS (NFP_MAC_STATS_BASE + 0x168)
# define NFP_MAC_STATS_TX_PKTS_256_TO_511_OCTETS (NFP_MAC_STATS_BASE + 0x170)
# define NFP_MAC_STATS_TX_PKTS_512_TO_1023_OCTETS (NFP_MAC_STATS_BASE + 0x178)
# define NFP_MAC_STATS_TX_PAUSE_MAC_CTRL_FRAMES (NFP_MAC_STATS_BASE + 0x180)
# define NFP_MAC_STATS_TX_FRAMES_TRANSMITTED_OK (NFP_MAC_STATS_BASE + 0x188)
# define NFP_MAC_STATS_TX_UNICAST_PKTS (NFP_MAC_STATS_BASE + 0x190)
# define NFP_MAC_STATS_TX_MULTICAST_PKTS (NFP_MAC_STATS_BASE + 0x198)
# define NFP_MAC_STATS_TX_PKTS_65_TO_127_OCTETS (NFP_MAC_STATS_BASE + 0x1a0)
2017-08-18 15:48:18 -07:00
# define NFP_MAC_STATS_TX_PKTS_128_TO_255_OCTETS (NFP_MAC_STATS_BASE + 0x1a8)
# define NFP_MAC_STATS_TX_PKTS_1024_TO_1518_OCTETS (NFP_MAC_STATS_BASE + 0x1b0)
# define NFP_MAC_STATS_TX_PKTS_1519_TO_MAX_OCTETS (NFP_MAC_STATS_BASE + 0x1b8)
# define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS0 (NFP_MAC_STATS_BASE + 0x1c0)
# define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS1 (NFP_MAC_STATS_BASE + 0x1c8)
# define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS4 (NFP_MAC_STATS_BASE + 0x1d0)
# define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS5 (NFP_MAC_STATS_BASE + 0x1d8)
# define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS2 (NFP_MAC_STATS_BASE + 0x1e0)
# define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS3 (NFP_MAC_STATS_BASE + 0x1e8)
# define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS6 (NFP_MAC_STATS_BASE + 0x1f0)
# define NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS7 (NFP_MAC_STATS_BASE + 0x1f8)
2017-06-23 22:12:01 +02:00
2017-05-22 10:59:28 -07:00
# endif