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_NET_REPR_H
0005 #define NFP_NET_REPR_H
0006 
0007 struct metadata_dst;
0008 struct nfp_app;
0009 struct nfp_net;
0010 struct nfp_port;
0011 
0012 #include <net/dst_metadata.h>
0013 
0014 /**
0015  * struct nfp_reprs - container for representor netdevs
0016  * @num_reprs:  Number of elements in reprs array
0017  * @reprs:  Array of representor netdevs
0018  */
0019 struct nfp_reprs {
0020     unsigned int num_reprs;
0021     struct net_device __rcu *reprs[];
0022 };
0023 
0024 /**
0025  * struct nfp_repr_pcpu_stats
0026  * @rx_packets: Received packets
0027  * @rx_bytes:   Received bytes
0028  * @tx_packets: Transmitted packets
0029  * @tx_bytes:   Transmitted dropped
0030  * @tx_drops:   Packets dropped on transmit
0031  * @syncp:  Reference count
0032  */
0033 struct nfp_repr_pcpu_stats {
0034     u64 rx_packets;
0035     u64 rx_bytes;
0036     u64 tx_packets;
0037     u64 tx_bytes;
0038     u64 tx_drops;
0039     struct u64_stats_sync syncp;
0040 };
0041 
0042 /**
0043  * struct nfp_repr - priv data for representor netdevs
0044  * @netdev: Back pointer to netdev
0045  * @dst:    Destination for packet TX
0046  * @port:   Port of representor
0047  * @app:    APP handle
0048  * @stats:  Statistic of packets hitting CPU
0049  * @app_priv:   Pointer for APP data
0050  */
0051 struct nfp_repr {
0052     struct net_device *netdev;
0053     struct metadata_dst *dst;
0054     struct nfp_port *port;
0055     struct nfp_app *app;
0056     struct nfp_repr_pcpu_stats __percpu *stats;
0057     void *app_priv;
0058 };
0059 
0060 /**
0061  * enum nfp_repr_type - type of representor
0062  * @NFP_REPR_TYPE_PHYS_PORT:    external NIC port
0063  * @NFP_REPR_TYPE_PF:       physical function
0064  * @NFP_REPR_TYPE_VF:       virtual function
0065  * @__NFP_REPR_TYPE_MAX:    number of representor types
0066  */
0067 enum nfp_repr_type {
0068     NFP_REPR_TYPE_PHYS_PORT,
0069     NFP_REPR_TYPE_PF,
0070     NFP_REPR_TYPE_VF,
0071 
0072     __NFP_REPR_TYPE_MAX,
0073 };
0074 #define NFP_REPR_TYPE_MAX (__NFP_REPR_TYPE_MAX - 1)
0075 
0076 extern const struct net_device_ops nfp_repr_netdev_ops;
0077 
0078 static inline bool nfp_netdev_is_nfp_repr(struct net_device *netdev)
0079 {
0080     return netdev->netdev_ops == &nfp_repr_netdev_ops;
0081 }
0082 
0083 static inline int nfp_repr_get_port_id(struct net_device *netdev)
0084 {
0085     struct nfp_repr *priv = netdev_priv(netdev);
0086 
0087     return priv->dst->u.port_info.port_id;
0088 }
0089 
0090 struct net_device *
0091 nfp_repr_get_locked(struct nfp_app *app, struct nfp_reprs *set,
0092             unsigned int id);
0093 
0094 void nfp_repr_inc_rx_stats(struct net_device *netdev, unsigned int len);
0095 void
0096 nfp_repr_transfer_features(struct net_device *netdev, struct net_device *lower);
0097 int nfp_repr_init(struct nfp_app *app, struct net_device *netdev,
0098           u32 cmsg_port_id, struct nfp_port *port,
0099           struct net_device *pf_netdev);
0100 void nfp_repr_free(struct net_device *netdev);
0101 struct net_device *
0102 nfp_repr_alloc_mqs(struct nfp_app *app, unsigned int txqs, unsigned int rxqs);
0103 void nfp_repr_clean_and_free(struct nfp_repr *repr);
0104 void nfp_reprs_clean_and_free(struct nfp_app *app, struct nfp_reprs *reprs);
0105 void nfp_reprs_clean_and_free_by_type(struct nfp_app *app,
0106                       enum nfp_repr_type type);
0107 struct nfp_reprs *nfp_reprs_alloc(unsigned int num_reprs);
0108 int nfp_reprs_resync_phys_ports(struct nfp_app *app);
0109 
0110 static inline struct net_device *nfp_repr_alloc(struct nfp_app *app)
0111 {
0112     return nfp_repr_alloc_mqs(app, 1, 1);
0113 }
0114 #endif /* NFP_NET_REPR_H */