diff options
author | Jakub Kicinski <jakub.kicinski@netronome.com> | 2017-06-27 00:50:23 -0700 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2017-06-27 15:48:48 -0400 |
commit | 39ae7eb69db3a3daa3aa2f6c66e37dba1975ef00 (patch) | |
tree | aa3e13945b9ca10db383d33b8942a647058160e1 /drivers/net/ethernet/netronome/nfp | |
parent | 5d7c64a70fa15aef903469b05ca664f7cd17d769 (diff) |
nfp: allow converting representor's netdev into nfp_port
Based on struct net_device_ops figure out if netdev is a nfp_repr.
Use this knowledge to convert netdev directly to nfp_port.
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Simon Horman <simon.horman@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ethernet/netronome/nfp')
-rw-r--r-- | drivers/net/ethernet/netronome/nfp/nfp_net_repr.c | 2 | ||||
-rw-r--r-- | drivers/net/ethernet/netronome/nfp/nfp_net_repr.h | 7 | ||||
-rw-r--r-- | drivers/net/ethernet/netronome/nfp/nfp_port.c | 18 |
3 files changed, 21 insertions, 6 deletions
diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_repr.c b/drivers/net/ethernet/netronome/nfp/nfp_net_repr.c index 44416f679fdb..7bfdef2af1a9 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_repr.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_repr.c @@ -249,7 +249,7 @@ static int nfp_repr_open(struct net_device *netdev) return nfp_app_repr_open(repr->app, repr); } -static const struct net_device_ops nfp_repr_netdev_ops = { +const struct net_device_ops nfp_repr_netdev_ops = { .ndo_open = nfp_repr_open, .ndo_stop = nfp_repr_stop, .ndo_start_xmit = nfp_repr_xmit, diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_repr.h b/drivers/net/ethernet/netronome/nfp/nfp_net_repr.h index 8f126362d5ed..6a6727816010 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_repr.h +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_repr.h @@ -97,6 +97,13 @@ enum nfp_repr_type { }; #define NFP_REPR_TYPE_MAX (__NFP_REPR_TYPE_MAX - 1) +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; +} + void nfp_repr_inc_rx_stats(struct net_device *netdev, unsigned int len); int nfp_repr_init(struct nfp_app *app, struct net_device *netdev, u32 cmsg_port_id, struct nfp_port *port, diff --git a/drivers/net/ethernet/netronome/nfp/nfp_port.c b/drivers/net/ethernet/netronome/nfp/nfp_port.c index 19bceeb82225..0be6c7e0b1c1 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_port.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_port.c @@ -42,13 +42,21 @@ struct nfp_port *nfp_port_from_netdev(struct net_device *netdev) { - struct nfp_net *nn; + if (nfp_netdev_is_nfp_net(netdev)) { + struct nfp_net *nn = netdev_priv(netdev); - if (WARN_ON(!nfp_netdev_is_nfp_net(netdev))) - return NULL; - nn = netdev_priv(netdev); + return nn->port; + } - return nn->port; + if (nfp_netdev_is_nfp_repr(netdev)) { + struct nfp_repr *repr = netdev_priv(netdev); + + return repr->port; + } + + WARN(1, "Unknown netdev type for nfp_port\n"); + + return NULL; } struct nfp_port * |