linux/drivers/net/ethernet/netronome/nfp/nfp_app.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
   2/* Copyright (C) 2017-2018 Netronome Systems, Inc. */
   3
   4#ifndef _NFP_APP_H
   5#define _NFP_APP_H 1
   6
   7#include <net/devlink.h>
   8
   9#include <trace/events/devlink.h>
  10
  11#include "nfp_net_repr.h"
  12
  13#define NFP_APP_CTRL_MTU_MAX    U32_MAX
  14
  15struct bpf_prog;
  16struct net_device;
  17struct netdev_bpf;
  18struct netlink_ext_ack;
  19struct pci_dev;
  20struct sk_buff;
  21struct nfp_app;
  22struct nfp_cpp;
  23struct nfp_pf;
  24struct nfp_repr;
  25struct nfp_net;
  26
  27enum nfp_app_id {
  28        NFP_APP_CORE_NIC        = 0x1,
  29        NFP_APP_BPF_NIC         = 0x2,
  30        NFP_APP_FLOWER_NIC      = 0x3,
  31        NFP_APP_ACTIVE_BUFFER_MGMT_NIC = 0x4,
  32};
  33
  34extern const struct nfp_app_type app_nic;
  35extern const struct nfp_app_type app_bpf;
  36extern const struct nfp_app_type app_flower;
  37extern const struct nfp_app_type app_abm;
  38
  39/**
  40 * struct nfp_app_type - application definition
  41 * @id:         application ID
  42 * @name:       application name
  43 * @ctrl_cap_mask:  ctrl vNIC capability mask, allows disabling features like
  44 *                  IRQMOD which are on by default but counter-productive for
  45 *                  control messages which are often latency-sensitive
  46 * @ctrl_has_meta:  control messages have prepend of type:5/port:CTRL
  47 *
  48 * Callbacks
  49 * @init:       perform basic app checks and init
  50 * @clean:      clean app state
  51 * @extra_cap:  extra capabilities string
  52 * @ndo_init:   vNIC and repr netdev .ndo_init
  53 * @ndo_uninit: vNIC and repr netdev .ndo_unint
  54 * @vnic_alloc: allocate vNICs (assign port types, etc.)
  55 * @vnic_free:  free up app's vNIC state
  56 * @vnic_init:  vNIC netdev was registered
  57 * @vnic_clean: vNIC netdev about to be unregistered
  58 * @repr_init:  representor about to be registered
  59 * @repr_preclean:      representor about to unregistered, executed before app
  60 *                      reference to the it is removed
  61 * @repr_clean: representor about to be unregistered
  62 * @repr_open:  representor netdev open callback
  63 * @repr_stop:  representor netdev stop callback
  64 * @check_mtu:  MTU change request on a netdev (verify it is valid)
  65 * @repr_change_mtu:    MTU change request on repr (make and verify change)
  66 * @port_get_stats:             get extra ethtool statistics for a port
  67 * @port_get_stats_count:       get count of extra statistics for a port
  68 * @port_get_stats_strings:     get strings for extra statistics
  69 * @start:      start application logic
  70 * @stop:       stop application logic
  71 * @netdev_event:       Netdevice notifier event
  72 * @ctrl_msg_rx:    control message handler
  73 * @ctrl_msg_rx_raw:    handler for control messages from data queues
  74 * @setup_tc:   setup TC ndo
  75 * @bpf:        BPF ndo offload-related calls
  76 * @xdp_offload:    offload an XDP program
  77 * @eswitch_mode_get:    get SR-IOV eswitch mode
  78 * @eswitch_mode_set:    set SR-IOV eswitch mode (under pf->lock)
  79 * @sriov_enable: app-specific sriov initialisation
  80 * @sriov_disable: app-specific sriov clean-up
  81 * @dev_get:    get representor or internal port representing netdev
  82 */
  83struct nfp_app_type {
  84        enum nfp_app_id id;
  85        const char *name;
  86
  87        u32 ctrl_cap_mask;
  88        bool ctrl_has_meta;
  89
  90        int (*init)(struct nfp_app *app);
  91        void (*clean)(struct nfp_app *app);
  92
  93        const char *(*extra_cap)(struct nfp_app *app, struct nfp_net *nn);
  94
  95        int (*ndo_init)(struct nfp_app *app, struct net_device *netdev);
  96        void (*ndo_uninit)(struct nfp_app *app, struct net_device *netdev);
  97
  98        int (*vnic_alloc)(struct nfp_app *app, struct nfp_net *nn,
  99                          unsigned int id);
 100        void (*vnic_free)(struct nfp_app *app, struct nfp_net *nn);
 101        int (*vnic_init)(struct nfp_app *app, struct nfp_net *nn);
 102        void (*vnic_clean)(struct nfp_app *app, struct nfp_net *nn);
 103
 104        int (*repr_init)(struct nfp_app *app, struct net_device *netdev);
 105        void (*repr_preclean)(struct nfp_app *app, struct net_device *netdev);
 106        void (*repr_clean)(struct nfp_app *app, struct net_device *netdev);
 107
 108        int (*repr_open)(struct nfp_app *app, struct nfp_repr *repr);
 109        int (*repr_stop)(struct nfp_app *app, struct nfp_repr *repr);
 110
 111        int (*check_mtu)(struct nfp_app *app, struct net_device *netdev,
 112                         int new_mtu);
 113        int (*repr_change_mtu)(struct nfp_app *app, struct net_device *netdev,
 114                               int new_mtu);
 115
 116        u64 *(*port_get_stats)(struct nfp_app *app,
 117                               struct nfp_port *port, u64 *data);
 118        int (*port_get_stats_count)(struct nfp_app *app, struct nfp_port *port);
 119        u8 *(*port_get_stats_strings)(struct nfp_app *app,
 120                                      struct nfp_port *port, u8 *data);
 121
 122        int (*start)(struct nfp_app *app);
 123        void (*stop)(struct nfp_app *app);
 124
 125        int (*netdev_event)(struct nfp_app *app, struct net_device *netdev,
 126                            unsigned long event, void *ptr);
 127
 128        void (*ctrl_msg_rx)(struct nfp_app *app, struct sk_buff *skb);
 129        void (*ctrl_msg_rx_raw)(struct nfp_app *app, const void *data,
 130                                unsigned int len);
 131
 132        int (*setup_tc)(struct nfp_app *app, struct net_device *netdev,
 133                        enum tc_setup_type type, void *type_data);
 134        int (*bpf)(struct nfp_app *app, struct nfp_net *nn,
 135                   struct netdev_bpf *xdp);
 136        int (*xdp_offload)(struct nfp_app *app, struct nfp_net *nn,
 137                           struct bpf_prog *prog,
 138                           struct netlink_ext_ack *extack);
 139
 140        int (*sriov_enable)(struct nfp_app *app, int num_vfs);
 141        void (*sriov_disable)(struct nfp_app *app);
 142
 143        enum devlink_eswitch_mode (*eswitch_mode_get)(struct nfp_app *app);
 144        int (*eswitch_mode_set)(struct nfp_app *app, u16 mode);
 145        struct net_device *(*dev_get)(struct nfp_app *app, u32 id,
 146                                      bool *redir_egress);
 147};
 148
 149/**
 150 * struct nfp_app - NFP application container
 151 * @pdev:       backpointer to PCI device
 152 * @pf:         backpointer to NFP PF structure
 153 * @cpp:        pointer to the CPP handle
 154 * @ctrl:       pointer to ctrl vNIC struct
 155 * @reprs:      array of pointers to representors
 156 * @type:       pointer to const application ops and info
 157 * @ctrl_mtu:   MTU to set on the control vNIC (set in .init())
 158 * @netdev_nb:  Netdevice notifier block
 159 * @priv:       app-specific priv data
 160 */
 161struct nfp_app {
 162        struct pci_dev *pdev;
 163        struct nfp_pf *pf;
 164        struct nfp_cpp *cpp;
 165
 166        struct nfp_net *ctrl;
 167        struct nfp_reprs __rcu *reprs[NFP_REPR_TYPE_MAX + 1];
 168
 169        const struct nfp_app_type *type;
 170        unsigned int ctrl_mtu;
 171
 172        struct notifier_block netdev_nb;
 173
 174        void *priv;
 175};
 176
 177void nfp_check_rhashtable_empty(void *ptr, void *arg);
 178bool __nfp_ctrl_tx(struct nfp_net *nn, struct sk_buff *skb);
 179bool nfp_ctrl_tx(struct nfp_net *nn, struct sk_buff *skb);
 180
 181static inline int nfp_app_init(struct nfp_app *app)
 182{
 183        if (!app->type->init)
 184                return 0;
 185        return app->type->init(app);
 186}
 187
 188static inline void nfp_app_clean(struct nfp_app *app)
 189{
 190        if (app->type->clean)
 191                app->type->clean(app);
 192}
 193
 194int nfp_app_ndo_init(struct net_device *netdev);
 195void nfp_app_ndo_uninit(struct net_device *netdev);
 196
 197static inline int nfp_app_vnic_alloc(struct nfp_app *app, struct nfp_net *nn,
 198                                     unsigned int id)
 199{
 200        return app->type->vnic_alloc(app, nn, id);
 201}
 202
 203static inline void nfp_app_vnic_free(struct nfp_app *app, struct nfp_net *nn)
 204{
 205        if (app->type->vnic_free)
 206                app->type->vnic_free(app, nn);
 207}
 208
 209static inline int nfp_app_vnic_init(struct nfp_app *app, struct nfp_net *nn)
 210{
 211        if (!app->type->vnic_init)
 212                return 0;
 213        return app->type->vnic_init(app, nn);
 214}
 215
 216static inline void nfp_app_vnic_clean(struct nfp_app *app, struct nfp_net *nn)
 217{
 218        if (app->type->vnic_clean)
 219                app->type->vnic_clean(app, nn);
 220}
 221
 222static inline int nfp_app_repr_open(struct nfp_app *app, struct nfp_repr *repr)
 223{
 224        if (!app->type->repr_open)
 225                return -EINVAL;
 226        return app->type->repr_open(app, repr);
 227}
 228
 229static inline int nfp_app_repr_stop(struct nfp_app *app, struct nfp_repr *repr)
 230{
 231        if (!app->type->repr_stop)
 232                return -EINVAL;
 233        return app->type->repr_stop(app, repr);
 234}
 235
 236static inline int
 237nfp_app_repr_init(struct nfp_app *app, struct net_device *netdev)
 238{
 239        if (!app->type->repr_init)
 240                return 0;
 241        return app->type->repr_init(app, netdev);
 242}
 243
 244static inline void
 245nfp_app_repr_preclean(struct nfp_app *app, struct net_device *netdev)
 246{
 247        if (app->type->repr_preclean)
 248                app->type->repr_preclean(app, netdev);
 249}
 250
 251static inline void
 252nfp_app_repr_clean(struct nfp_app *app, struct net_device *netdev)
 253{
 254        if (app->type->repr_clean)
 255                app->type->repr_clean(app, netdev);
 256}
 257
 258static inline int
 259nfp_app_check_mtu(struct nfp_app *app, struct net_device *netdev, int new_mtu)
 260{
 261        if (!app || !app->type->check_mtu)
 262                return 0;
 263        return app->type->check_mtu(app, netdev, new_mtu);
 264}
 265
 266static inline int
 267nfp_app_repr_change_mtu(struct nfp_app *app, struct net_device *netdev,
 268                        int new_mtu)
 269{
 270        if (!app || !app->type->repr_change_mtu)
 271                return 0;
 272        return app->type->repr_change_mtu(app, netdev, new_mtu);
 273}
 274
 275static inline const char *nfp_app_name(struct nfp_app *app)
 276{
 277        if (!app)
 278                return "";
 279        return app->type->name;
 280}
 281
 282static inline bool nfp_app_needs_ctrl_vnic(struct nfp_app *app)
 283{
 284        return app && app->type->ctrl_msg_rx;
 285}
 286
 287static inline bool nfp_app_ctrl_has_meta(struct nfp_app *app)
 288{
 289        return app->type->ctrl_has_meta;
 290}
 291
 292static inline bool nfp_app_ctrl_uses_data_vnics(struct nfp_app *app)
 293{
 294        return app && app->type->ctrl_msg_rx_raw;
 295}
 296
 297static inline const char *nfp_app_extra_cap(struct nfp_app *app,
 298                                            struct nfp_net *nn)
 299{
 300        if (!app || !app->type->extra_cap)
 301                return "";
 302        return app->type->extra_cap(app, nn);
 303}
 304
 305static inline bool nfp_app_has_tc(struct nfp_app *app)
 306{
 307        return app && app->type->setup_tc;
 308}
 309
 310static inline int nfp_app_setup_tc(struct nfp_app *app,
 311                                   struct net_device *netdev,
 312                                   enum tc_setup_type type, void *type_data)
 313{
 314        if (!app || !app->type->setup_tc)
 315                return -EOPNOTSUPP;
 316        return app->type->setup_tc(app, netdev, type, type_data);
 317}
 318
 319static inline int nfp_app_bpf(struct nfp_app *app, struct nfp_net *nn,
 320                              struct netdev_bpf *bpf)
 321{
 322        if (!app || !app->type->bpf)
 323                return -EINVAL;
 324        return app->type->bpf(app, nn, bpf);
 325}
 326
 327static inline int nfp_app_xdp_offload(struct nfp_app *app, struct nfp_net *nn,
 328                                      struct bpf_prog *prog,
 329                                      struct netlink_ext_ack *extack)
 330{
 331        if (!app || !app->type->xdp_offload)
 332                return -EOPNOTSUPP;
 333        return app->type->xdp_offload(app, nn, prog, extack);
 334}
 335
 336static inline bool __nfp_app_ctrl_tx(struct nfp_app *app, struct sk_buff *skb)
 337{
 338        trace_devlink_hwmsg(priv_to_devlink(app->pf), false, 0,
 339                            skb->data, skb->len);
 340
 341        return __nfp_ctrl_tx(app->ctrl, skb);
 342}
 343
 344static inline bool nfp_app_ctrl_tx(struct nfp_app *app, struct sk_buff *skb)
 345{
 346        trace_devlink_hwmsg(priv_to_devlink(app->pf), false, 0,
 347                            skb->data, skb->len);
 348
 349        return nfp_ctrl_tx(app->ctrl, skb);
 350}
 351
 352static inline void nfp_app_ctrl_rx(struct nfp_app *app, struct sk_buff *skb)
 353{
 354        trace_devlink_hwmsg(priv_to_devlink(app->pf), true, 0,
 355                            skb->data, skb->len);
 356
 357        app->type->ctrl_msg_rx(app, skb);
 358}
 359
 360static inline void
 361nfp_app_ctrl_rx_raw(struct nfp_app *app, const void *data, unsigned int len)
 362{
 363        if (!app || !app->type->ctrl_msg_rx_raw)
 364                return;
 365
 366        trace_devlink_hwmsg(priv_to_devlink(app->pf), true, 0, data, len);
 367        app->type->ctrl_msg_rx_raw(app, data, len);
 368}
 369
 370static inline int nfp_app_eswitch_mode_get(struct nfp_app *app, u16 *mode)
 371{
 372        if (!app->type->eswitch_mode_get)
 373                return -EOPNOTSUPP;
 374
 375        *mode = app->type->eswitch_mode_get(app);
 376
 377        return 0;
 378}
 379
 380static inline int nfp_app_eswitch_mode_set(struct nfp_app *app, u16 mode)
 381{
 382        if (!app->type->eswitch_mode_set)
 383                return -EOPNOTSUPP;
 384        return app->type->eswitch_mode_set(app, mode);
 385}
 386
 387static inline int nfp_app_sriov_enable(struct nfp_app *app, int num_vfs)
 388{
 389        if (!app || !app->type->sriov_enable)
 390                return -EOPNOTSUPP;
 391        return app->type->sriov_enable(app, num_vfs);
 392}
 393
 394static inline void nfp_app_sriov_disable(struct nfp_app *app)
 395{
 396        if (app && app->type->sriov_disable)
 397                app->type->sriov_disable(app);
 398}
 399
 400static inline
 401struct net_device *nfp_app_dev_get(struct nfp_app *app, u32 id,
 402                                   bool *redir_egress)
 403{
 404        if (unlikely(!app || !app->type->dev_get))
 405                return NULL;
 406
 407        return app->type->dev_get(app, id, redir_egress);
 408}
 409
 410struct nfp_app *nfp_app_from_netdev(struct net_device *netdev);
 411
 412u64 *nfp_app_port_get_stats(struct nfp_port *port, u64 *data);
 413int nfp_app_port_get_stats_count(struct nfp_port *port);
 414u8 *nfp_app_port_get_stats_strings(struct nfp_port *port, u8 *data);
 415
 416struct nfp_reprs *
 417nfp_reprs_get_locked(struct nfp_app *app, enum nfp_repr_type type);
 418struct nfp_reprs *
 419nfp_app_reprs_set(struct nfp_app *app, enum nfp_repr_type type,
 420                  struct nfp_reprs *reprs);
 421
 422const char *nfp_app_mip_name(struct nfp_app *app);
 423struct sk_buff *
 424nfp_app_ctrl_msg_alloc(struct nfp_app *app, unsigned int size, gfp_t priority);
 425
 426struct nfp_app *nfp_app_alloc(struct nfp_pf *pf, enum nfp_app_id id);
 427void nfp_app_free(struct nfp_app *app);
 428int nfp_app_start(struct nfp_app *app, struct nfp_net *ctrl);
 429void nfp_app_stop(struct nfp_app *app);
 430
 431/* Callbacks shared between apps */
 432
 433int nfp_app_nic_vnic_alloc(struct nfp_app *app, struct nfp_net *nn,
 434                           unsigned int id);
 435int nfp_app_nic_vnic_init_phy_port(struct nfp_pf *pf, struct nfp_app *app,
 436                                   struct nfp_net *nn, unsigned int id);
 437
 438struct devlink_port *nfp_devlink_get_devlink_port(struct net_device *netdev);
 439
 440#endif
 441