2018-10-11 23:57:42 +08:00
|
|
|
/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
|
|
|
|
/* Copyright (C) 2017-2018 Netronome Systems, Inc. */
|
2017-06-24 04:12:02 +08:00
|
|
|
|
|
|
|
#ifndef NFP_NET_REPR_H
|
|
|
|
#define NFP_NET_REPR_H
|
|
|
|
|
|
|
|
struct metadata_dst;
|
2018-01-18 10:50:59 +08:00
|
|
|
struct nfp_app;
|
2017-06-24 04:12:02 +08:00
|
|
|
struct nfp_net;
|
|
|
|
struct nfp_port;
|
|
|
|
|
2017-06-30 04:08:15 +08:00
|
|
|
#include <net/dst_metadata.h>
|
|
|
|
|
2017-06-24 04:12:02 +08:00
|
|
|
/**
|
|
|
|
* struct nfp_reprs - container for representor netdevs
|
|
|
|
* @num_reprs: Number of elements in reprs array
|
|
|
|
* @reprs: Array of representor netdevs
|
|
|
|
*/
|
|
|
|
struct nfp_reprs {
|
|
|
|
unsigned int num_reprs;
|
2018-01-18 10:50:59 +08:00
|
|
|
struct net_device __rcu *reprs[0];
|
2017-06-24 04:12:02 +08:00
|
|
|
};
|
|
|
|
|
2017-06-24 04:12:03 +08:00
|
|
|
/**
|
|
|
|
* struct nfp_repr_pcpu_stats
|
|
|
|
* @rx_packets: Received packets
|
|
|
|
* @rx_bytes: Received bytes
|
|
|
|
* @tx_packets: Transmitted packets
|
|
|
|
* @tx_bytes: Transmitted dropped
|
|
|
|
* @tx_drops: Packets dropped on transmit
|
|
|
|
* @syncp: Reference count
|
|
|
|
*/
|
|
|
|
struct nfp_repr_pcpu_stats {
|
|
|
|
u64 rx_packets;
|
|
|
|
u64 rx_bytes;
|
|
|
|
u64 tx_packets;
|
|
|
|
u64 tx_bytes;
|
|
|
|
u64 tx_drops;
|
|
|
|
struct u64_stats_sync syncp;
|
|
|
|
};
|
|
|
|
|
2017-06-24 04:12:02 +08:00
|
|
|
/**
|
|
|
|
* struct nfp_repr - priv data for representor netdevs
|
|
|
|
* @netdev: Back pointer to netdev
|
|
|
|
* @dst: Destination for packet TX
|
|
|
|
* @port: Port of representor
|
|
|
|
* @app: APP handle
|
2017-06-24 04:12:03 +08:00
|
|
|
* @stats: Statistic of packets hitting CPU
|
2018-05-22 13:12:49 +08:00
|
|
|
* @app_priv: Pointer for APP data
|
2017-06-24 04:12:02 +08:00
|
|
|
*/
|
|
|
|
struct nfp_repr {
|
|
|
|
struct net_device *netdev;
|
|
|
|
struct metadata_dst *dst;
|
|
|
|
struct nfp_port *port;
|
|
|
|
struct nfp_app *app;
|
2017-06-24 04:12:03 +08:00
|
|
|
struct nfp_repr_pcpu_stats __percpu *stats;
|
2018-05-22 13:12:49 +08:00
|
|
|
void *app_priv;
|
2017-06-24 04:12:02 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* enum nfp_repr_type - type of representor
|
|
|
|
* @NFP_REPR_TYPE_PHYS_PORT: external NIC port
|
|
|
|
* @NFP_REPR_TYPE_PF: physical function
|
|
|
|
* @NFP_REPR_TYPE_VF: virtual function
|
2018-01-10 20:25:55 +08:00
|
|
|
* @__NFP_REPR_TYPE_MAX: number of representor types
|
2017-06-24 04:12:02 +08:00
|
|
|
*/
|
|
|
|
enum nfp_repr_type {
|
|
|
|
NFP_REPR_TYPE_PHYS_PORT,
|
|
|
|
NFP_REPR_TYPE_PF,
|
|
|
|
NFP_REPR_TYPE_VF,
|
|
|
|
|
|
|
|
__NFP_REPR_TYPE_MAX,
|
|
|
|
};
|
|
|
|
#define NFP_REPR_TYPE_MAX (__NFP_REPR_TYPE_MAX - 1)
|
|
|
|
|
2017-06-27 15:50:23 +08:00
|
|
|
extern const struct net_device_ops nfp_repr_netdev_ops;
|
|
|
|
|
|
|
|
static inline bool nfp_netdev_is_nfp_repr(struct net_device *netdev)
|
|
|
|
{
|
|
|
|
return netdev->netdev_ops == &nfp_repr_netdev_ops;
|
|
|
|
}
|
|
|
|
|
2017-06-30 04:08:15 +08:00
|
|
|
static inline int nfp_repr_get_port_id(struct net_device *netdev)
|
|
|
|
{
|
|
|
|
struct nfp_repr *priv = netdev_priv(netdev);
|
|
|
|
|
|
|
|
return priv->dst->u.port_info.port_id;
|
|
|
|
}
|
|
|
|
|
2018-01-18 10:50:59 +08:00
|
|
|
struct net_device *
|
|
|
|
nfp_repr_get_locked(struct nfp_app *app, struct nfp_reprs *set,
|
|
|
|
unsigned int id);
|
|
|
|
|
2017-06-24 04:12:03 +08:00
|
|
|
void nfp_repr_inc_rx_stats(struct net_device *netdev, unsigned int len);
|
2018-11-28 14:24:56 +08:00
|
|
|
void
|
|
|
|
nfp_repr_transfer_features(struct net_device *netdev, struct net_device *lower);
|
2017-06-24 04:12:02 +08:00
|
|
|
int nfp_repr_init(struct nfp_app *app, struct net_device *netdev,
|
|
|
|
u32 cmsg_port_id, struct nfp_port *port,
|
|
|
|
struct net_device *pf_netdev);
|
2018-05-17 18:06:43 +08:00
|
|
|
void nfp_repr_free(struct net_device *netdev);
|
2018-05-26 12:53:34 +08:00
|
|
|
struct net_device *
|
|
|
|
nfp_repr_alloc_mqs(struct nfp_app *app, unsigned int txqs, unsigned int rxqs);
|
2018-05-22 13:12:52 +08:00
|
|
|
void nfp_repr_clean_and_free(struct nfp_repr *repr);
|
2018-01-18 10:50:59 +08:00
|
|
|
void nfp_reprs_clean_and_free(struct nfp_app *app, struct nfp_reprs *reprs);
|
|
|
|
void nfp_reprs_clean_and_free_by_type(struct nfp_app *app,
|
|
|
|
enum nfp_repr_type type);
|
2017-06-24 04:12:02 +08:00
|
|
|
struct nfp_reprs *nfp_reprs_alloc(unsigned int num_reprs);
|
2017-11-04 23:48:57 +08:00
|
|
|
int nfp_reprs_resync_phys_ports(struct nfp_app *app);
|
2017-06-24 04:12:02 +08:00
|
|
|
|
2018-05-26 12:53:34 +08:00
|
|
|
static inline struct net_device *nfp_repr_alloc(struct nfp_app *app)
|
|
|
|
{
|
|
|
|
return nfp_repr_alloc_mqs(app, 1, 1);
|
|
|
|
}
|
2017-06-24 04:12:02 +08:00
|
|
|
#endif /* NFP_NET_REPR_H */
|