linux/drivers/net/ethernet/netronome/nfp/nfp_net_repr.h
<<
>>
Prefs
   1/*
   2 * Copyright (C) 2017 Netronome Systems, Inc.
   3 *
   4 * This software is dual licensed under the GNU General License Version 2,
   5 * June 1991 as shown in the file COPYING in the top-level directory of this
   6 * source tree or the BSD 2-Clause License provided below.  You have the
   7 * option to license this software under the complete terms of either license.
   8 *
   9 * The BSD 2-Clause License:
  10 *
  11 *     Redistribution and use in source and binary forms, with or
  12 *     without modification, are permitted provided that the following
  13 *     conditions are met:
  14 *
  15 *      1. Redistributions of source code must retain the above
  16 *         copyright notice, this list of conditions and the following
  17 *         disclaimer.
  18 *
  19 *      2. Redistributions in binary form must reproduce the above
  20 *         copyright notice, this list of conditions and the following
  21 *         disclaimer in the documentation and/or other materials
  22 *         provided with the distribution.
  23 *
  24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  31 * SOFTWARE.
  32 */
  33
  34#ifndef NFP_NET_REPR_H
  35#define NFP_NET_REPR_H
  36
  37struct metadata_dst;
  38struct nfp_net;
  39struct nfp_port;
  40
  41#include <net/dst_metadata.h>
  42
  43/**
  44 * struct nfp_reprs - container for representor netdevs
  45 * @num_reprs:  Number of elements in reprs array
  46 * @reprs:      Array of representor netdevs
  47 */
  48struct nfp_reprs {
  49        unsigned int num_reprs;
  50        struct net_device *reprs[0];
  51};
  52
  53/**
  54 * struct nfp_repr_pcpu_stats
  55 * @rx_packets: Received packets
  56 * @rx_bytes:   Received bytes
  57 * @tx_packets: Transmitted packets
  58 * @tx_bytes:   Transmitted dropped
  59 * @tx_drops:   Packets dropped on transmit
  60 * @syncp:      Reference count
  61 */
  62struct nfp_repr_pcpu_stats {
  63        u64 rx_packets;
  64        u64 rx_bytes;
  65        u64 tx_packets;
  66        u64 tx_bytes;
  67        u64 tx_drops;
  68        struct u64_stats_sync syncp;
  69};
  70
  71/**
  72 * struct nfp_repr - priv data for representor netdevs
  73 * @netdev:     Back pointer to netdev
  74 * @dst:        Destination for packet TX
  75 * @port:       Port of representor
  76 * @app:        APP handle
  77 * @stats:      Statistic of packets hitting CPU
  78 */
  79struct nfp_repr {
  80        struct net_device *netdev;
  81        struct metadata_dst *dst;
  82        struct nfp_port *port;
  83        struct nfp_app *app;
  84        struct nfp_repr_pcpu_stats __percpu *stats;
  85};
  86
  87/**
  88 * enum nfp_repr_type - type of representor
  89 * @NFP_REPR_TYPE_PHYS_PORT:    external NIC port
  90 * @NFP_REPR_TYPE_PF:           physical function
  91 * @NFP_REPR_TYPE_VF:           virtual function
  92 */
  93enum nfp_repr_type {
  94        NFP_REPR_TYPE_PHYS_PORT,
  95        NFP_REPR_TYPE_PF,
  96        NFP_REPR_TYPE_VF,
  97
  98        __NFP_REPR_TYPE_MAX,
  99};
 100#define NFP_REPR_TYPE_MAX (__NFP_REPR_TYPE_MAX - 1)
 101
 102extern const struct net_device_ops nfp_repr_netdev_ops;
 103
 104static inline bool nfp_netdev_is_nfp_repr(struct net_device *netdev)
 105{
 106        return netdev->netdev_ops == &nfp_repr_netdev_ops;
 107}
 108
 109static inline int nfp_repr_get_port_id(struct net_device *netdev)
 110{
 111        struct nfp_repr *priv = netdev_priv(netdev);
 112
 113        return priv->dst->u.port_info.port_id;
 114}
 115
 116void nfp_repr_inc_rx_stats(struct net_device *netdev, unsigned int len);
 117int nfp_repr_init(struct nfp_app *app, struct net_device *netdev,
 118                  u32 cmsg_port_id, struct nfp_port *port,
 119                  struct net_device *pf_netdev);
 120struct net_device *nfp_repr_alloc(struct nfp_app *app);
 121void
 122nfp_reprs_clean_and_free(struct nfp_reprs *reprs);
 123void
 124nfp_reprs_clean_and_free_by_type(struct nfp_app *app,
 125                                 enum nfp_repr_type type);
 126struct nfp_reprs *nfp_reprs_alloc(unsigned int num_reprs);
 127
 128#endif /* NFP_NET_REPR_H */
 129