196de2506SJakub Kicinski /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
296de2506SJakub Kicinski /* Copyright (C) 2017-2018 Netronome Systems, Inc. */
35de73ee4SSimon Horman
45de73ee4SSimon Horman #ifndef NFP_NET_REPR_H
55de73ee4SSimon Horman #define NFP_NET_REPR_H
65de73ee4SSimon Horman
75de73ee4SSimon Horman struct metadata_dst;
83eb47dfcSJakub Kicinski struct nfp_app;
95de73ee4SSimon Horman struct nfp_net;
105de73ee4SSimon Horman struct nfp_port;
115de73ee4SSimon Horman
125571e8c9SPieter Jansen van Vuuren #include <net/dst_metadata.h>
135571e8c9SPieter Jansen van Vuuren
145de73ee4SSimon Horman /**
155de73ee4SSimon Horman * struct nfp_reprs - container for representor netdevs
165de73ee4SSimon Horman * @num_reprs: Number of elements in reprs array
175de73ee4SSimon Horman * @reprs: Array of representor netdevs
185de73ee4SSimon Horman */
195de73ee4SSimon Horman struct nfp_reprs {
205de73ee4SSimon Horman unsigned int num_reprs;
21*3f6e9633SGustavo A. R. Silva struct net_device __rcu *reprs[];
225de73ee4SSimon Horman };
235de73ee4SSimon Horman
245de73ee4SSimon Horman /**
25eadfa4c3SSimon Horman * struct nfp_repr_pcpu_stats
26eadfa4c3SSimon Horman * @rx_packets: Received packets
27eadfa4c3SSimon Horman * @rx_bytes: Received bytes
28eadfa4c3SSimon Horman * @tx_packets: Transmitted packets
29eadfa4c3SSimon Horman * @tx_bytes: Transmitted dropped
30eadfa4c3SSimon Horman * @tx_drops: Packets dropped on transmit
31eadfa4c3SSimon Horman * @syncp: Reference count
32eadfa4c3SSimon Horman */
33eadfa4c3SSimon Horman struct nfp_repr_pcpu_stats {
34eadfa4c3SSimon Horman u64 rx_packets;
35eadfa4c3SSimon Horman u64 rx_bytes;
36eadfa4c3SSimon Horman u64 tx_packets;
37eadfa4c3SSimon Horman u64 tx_bytes;
38eadfa4c3SSimon Horman u64 tx_drops;
39eadfa4c3SSimon Horman struct u64_stats_sync syncp;
40eadfa4c3SSimon Horman };
41eadfa4c3SSimon Horman
42eadfa4c3SSimon Horman /**
435de73ee4SSimon Horman * struct nfp_repr - priv data for representor netdevs
445de73ee4SSimon Horman * @netdev: Back pointer to netdev
455de73ee4SSimon Horman * @dst: Destination for packet TX
465de73ee4SSimon Horman * @port: Port of representor
475de73ee4SSimon Horman * @app: APP handle
48eadfa4c3SSimon Horman * @stats: Statistic of packets hitting CPU
49634c6b7aSJakub Kicinski * @app_priv: Pointer for APP data
505de73ee4SSimon Horman */
515de73ee4SSimon Horman struct nfp_repr {
525de73ee4SSimon Horman struct net_device *netdev;
535de73ee4SSimon Horman struct metadata_dst *dst;
545de73ee4SSimon Horman struct nfp_port *port;
555de73ee4SSimon Horman struct nfp_app *app;
56eadfa4c3SSimon Horman struct nfp_repr_pcpu_stats __percpu *stats;
57634c6b7aSJakub Kicinski void *app_priv;
585de73ee4SSimon Horman };
595de73ee4SSimon Horman
605de73ee4SSimon Horman /**
615de73ee4SSimon Horman * enum nfp_repr_type - type of representor
625de73ee4SSimon Horman * @NFP_REPR_TYPE_PHYS_PORT: external NIC port
635de73ee4SSimon Horman * @NFP_REPR_TYPE_PF: physical function
645de73ee4SSimon Horman * @NFP_REPR_TYPE_VF: virtual function
658c6a6d98SJakub Kicinski * @__NFP_REPR_TYPE_MAX: number of representor types
665de73ee4SSimon Horman */
675de73ee4SSimon Horman enum nfp_repr_type {
685de73ee4SSimon Horman NFP_REPR_TYPE_PHYS_PORT,
695de73ee4SSimon Horman NFP_REPR_TYPE_PF,
705de73ee4SSimon Horman NFP_REPR_TYPE_VF,
715de73ee4SSimon Horman
725de73ee4SSimon Horman __NFP_REPR_TYPE_MAX,
735de73ee4SSimon Horman };
745de73ee4SSimon Horman #define NFP_REPR_TYPE_MAX (__NFP_REPR_TYPE_MAX - 1)
755de73ee4SSimon Horman
7639ae7eb6SJakub Kicinski extern const struct net_device_ops nfp_repr_netdev_ops;
7739ae7eb6SJakub Kicinski
nfp_netdev_is_nfp_repr(struct net_device * netdev)7839ae7eb6SJakub Kicinski static inline bool nfp_netdev_is_nfp_repr(struct net_device *netdev)
7939ae7eb6SJakub Kicinski {
8039ae7eb6SJakub Kicinski return netdev->netdev_ops == &nfp_repr_netdev_ops;
8139ae7eb6SJakub Kicinski }
8239ae7eb6SJakub Kicinski
nfp_repr_get_port_id(struct net_device * netdev)835571e8c9SPieter Jansen van Vuuren static inline int nfp_repr_get_port_id(struct net_device *netdev)
845571e8c9SPieter Jansen van Vuuren {
855571e8c9SPieter Jansen van Vuuren struct nfp_repr *priv = netdev_priv(netdev);
865571e8c9SPieter Jansen van Vuuren
875571e8c9SPieter Jansen van Vuuren return priv->dst->u.port_info.port_id;
885571e8c9SPieter Jansen van Vuuren }
895571e8c9SPieter Jansen van Vuuren
903eb47dfcSJakub Kicinski struct net_device *
913eb47dfcSJakub Kicinski nfp_repr_get_locked(struct nfp_app *app, struct nfp_reprs *set,
923eb47dfcSJakub Kicinski unsigned int id);
933eb47dfcSJakub Kicinski
94eadfa4c3SSimon Horman void nfp_repr_inc_rx_stats(struct net_device *netdev, unsigned int len);
9551a6588eSJakub Kicinski void
9651a6588eSJakub Kicinski nfp_repr_transfer_features(struct net_device *netdev, struct net_device *lower);
975de73ee4SSimon Horman int nfp_repr_init(struct nfp_app *app, struct net_device *netdev,
985de73ee4SSimon Horman u32 cmsg_port_id, struct nfp_port *port,
995de73ee4SSimon Horman struct net_device *pf_netdev);
1003b734ff6SJiri Pirko void nfp_repr_free(struct net_device *netdev);
1012ef3c253SJakub Kicinski struct net_device *
1022ef3c253SJakub Kicinski nfp_repr_alloc_mqs(struct nfp_app *app, unsigned int txqs, unsigned int rxqs);
103d05d902eSJakub Kicinski void nfp_repr_clean_and_free(struct nfp_repr *repr);
1043eb47dfcSJakub Kicinski void nfp_reprs_clean_and_free(struct nfp_app *app, struct nfp_reprs *reprs);
1053eb47dfcSJakub Kicinski void nfp_reprs_clean_and_free_by_type(struct nfp_app *app,
1065de73ee4SSimon Horman enum nfp_repr_type type);
1075de73ee4SSimon Horman struct nfp_reprs *nfp_reprs_alloc(unsigned int num_reprs);
1085fa27d59SDirk van der Merwe int nfp_reprs_resync_phys_ports(struct nfp_app *app);
1095de73ee4SSimon Horman
nfp_repr_alloc(struct nfp_app * app)1102ef3c253SJakub Kicinski static inline struct net_device *nfp_repr_alloc(struct nfp_app *app)
1112ef3c253SJakub Kicinski {
1122ef3c253SJakub Kicinski return nfp_repr_alloc_mqs(app, 1, 1);
1132ef3c253SJakub Kicinski }
1145de73ee4SSimon Horman #endif /* NFP_NET_REPR_H */
115