Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
0002 /* Copyright (C) 2017-2018 Netronome Systems, Inc. */
0003 
0004 #ifndef _NFP_APP_H
0005 #define _NFP_APP_H 1
0006 
0007 #include <net/devlink.h>
0008 
0009 #include <trace/events/devlink.h>
0010 
0011 #include "nfp_net_repr.h"
0012 
0013 #define NFP_APP_CTRL_MTU_MAX    U32_MAX
0014 
0015 struct bpf_prog;
0016 struct net_device;
0017 struct netdev_bpf;
0018 struct netlink_ext_ack;
0019 struct pci_dev;
0020 struct sk_buff;
0021 struct nfp_app;
0022 struct nfp_cpp;
0023 struct nfp_pf;
0024 struct nfp_repr;
0025 struct nfp_net;
0026 
0027 enum nfp_app_id {
0028     NFP_APP_CORE_NIC    = 0x1,
0029     NFP_APP_BPF_NIC     = 0x2,
0030     NFP_APP_FLOWER_NIC  = 0x3,
0031     NFP_APP_ACTIVE_BUFFER_MGMT_NIC = 0x4,
0032 };
0033 
0034 extern const struct nfp_app_type app_nic;
0035 extern const struct nfp_app_type app_bpf;
0036 extern const struct nfp_app_type app_flower;
0037 extern const struct nfp_app_type app_abm;
0038 
0039 /**
0040  * struct nfp_app_type - application definition
0041  * @id:     application ID
0042  * @name:   application name
0043  * @ctrl_cap_mask:  ctrl vNIC capability mask, allows disabling features like
0044  *          IRQMOD which are on by default but counter-productive for
0045  *          control messages which are often latency-sensitive
0046  * @ctrl_has_meta:  control messages have prepend of type:5/port:CTRL
0047  *
0048  * Callbacks
0049  * @init:   perform basic app checks and init
0050  * @clean:  clean app state
0051  * @extra_cap:  extra capabilities string
0052  * @ndo_init:   vNIC and repr netdev .ndo_init
0053  * @ndo_uninit: vNIC and repr netdev .ndo_unint
0054  * @vnic_alloc: allocate vNICs (assign port types, etc.)
0055  * @vnic_free:  free up app's vNIC state
0056  * @vnic_init:  vNIC netdev was registered
0057  * @vnic_clean: vNIC netdev about to be unregistered
0058  * @repr_init:  representor about to be registered
0059  * @repr_preclean:  representor about to unregistered, executed before app
0060  *          reference to the it is removed
0061  * @repr_clean: representor about to be unregistered
0062  * @repr_open:  representor netdev open callback
0063  * @repr_stop:  representor netdev stop callback
0064  * @check_mtu:  MTU change request on a netdev (verify it is valid)
0065  * @repr_change_mtu:    MTU change request on repr (make and verify change)
0066  * @port_get_stats:     get extra ethtool statistics for a port
0067  * @port_get_stats_count:   get count of extra statistics for a port
0068  * @port_get_stats_strings: get strings for extra statistics
0069  * @start:  start application logic
0070  * @stop:   stop application logic
0071  * @netdev_event:   Netdevice notifier event
0072  * @ctrl_msg_rx:    control message handler
0073  * @ctrl_msg_rx_raw:    handler for control messages from data queues
0074  * @setup_tc:   setup TC ndo
0075  * @bpf:    BPF ndo offload-related calls
0076  * @xdp_offload:    offload an XDP program
0077  * @eswitch_mode_get:    get SR-IOV eswitch mode
0078  * @eswitch_mode_set:    set SR-IOV eswitch mode
0079  * @sriov_enable: app-specific sriov initialisation
0080  * @sriov_disable: app-specific sriov clean-up
0081  * @dev_get:    get representor or internal port representing netdev
0082  */
0083 struct nfp_app_type {
0084     enum nfp_app_id id;
0085     const char *name;
0086 
0087     u32 ctrl_cap_mask;
0088     bool ctrl_has_meta;
0089 
0090     int (*init)(struct nfp_app *app);
0091     void (*clean)(struct nfp_app *app);
0092 
0093     const char *(*extra_cap)(struct nfp_app *app, struct nfp_net *nn);
0094 
0095     int (*ndo_init)(struct nfp_app *app, struct net_device *netdev);
0096     void (*ndo_uninit)(struct nfp_app *app, struct net_device *netdev);
0097 
0098     int (*vnic_alloc)(struct nfp_app *app, struct nfp_net *nn,
0099               unsigned int id);
0100     void (*vnic_free)(struct nfp_app *app, struct nfp_net *nn);
0101     int (*vnic_init)(struct nfp_app *app, struct nfp_net *nn);
0102     void (*vnic_clean)(struct nfp_app *app, struct nfp_net *nn);
0103 
0104     int (*repr_init)(struct nfp_app *app, struct net_device *netdev);
0105     void (*repr_preclean)(struct nfp_app *app, struct net_device *netdev);
0106     void (*repr_clean)(struct nfp_app *app, struct net_device *netdev);
0107 
0108     int (*repr_open)(struct nfp_app *app, struct nfp_repr *repr);
0109     int (*repr_stop)(struct nfp_app *app, struct nfp_repr *repr);
0110 
0111     int (*check_mtu)(struct nfp_app *app, struct net_device *netdev,
0112              int new_mtu);
0113     int (*repr_change_mtu)(struct nfp_app *app, struct net_device *netdev,
0114                    int new_mtu);
0115 
0116     u64 *(*port_get_stats)(struct nfp_app *app,
0117                    struct nfp_port *port, u64 *data);
0118     int (*port_get_stats_count)(struct nfp_app *app, struct nfp_port *port);
0119     u8 *(*port_get_stats_strings)(struct nfp_app *app,
0120                       struct nfp_port *port, u8 *data);
0121 
0122     int (*start)(struct nfp_app *app);
0123     void (*stop)(struct nfp_app *app);
0124 
0125     int (*netdev_event)(struct nfp_app *app, struct net_device *netdev,
0126                 unsigned long event, void *ptr);
0127 
0128     void (*ctrl_msg_rx)(struct nfp_app *app, struct sk_buff *skb);
0129     void (*ctrl_msg_rx_raw)(struct nfp_app *app, const void *data,
0130                 unsigned int len);
0131 
0132     int (*setup_tc)(struct nfp_app *app, struct net_device *netdev,
0133             enum tc_setup_type type, void *type_data);
0134     int (*bpf)(struct nfp_app *app, struct nfp_net *nn,
0135            struct netdev_bpf *xdp);
0136     int (*xdp_offload)(struct nfp_app *app, struct nfp_net *nn,
0137                struct bpf_prog *prog,
0138                struct netlink_ext_ack *extack);
0139 
0140     int (*sriov_enable)(struct nfp_app *app, int num_vfs);
0141     void (*sriov_disable)(struct nfp_app *app);
0142 
0143     enum devlink_eswitch_mode (*eswitch_mode_get)(struct nfp_app *app);
0144     int (*eswitch_mode_set)(struct nfp_app *app, u16 mode);
0145     struct net_device *(*dev_get)(struct nfp_app *app, u32 id,
0146                       bool *redir_egress);
0147 };
0148 
0149 /**
0150  * struct nfp_app - NFP application container
0151  * @pdev:   backpointer to PCI device
0152  * @pf:     backpointer to NFP PF structure
0153  * @cpp:    pointer to the CPP handle
0154  * @ctrl:   pointer to ctrl vNIC struct
0155  * @reprs:  array of pointers to representors
0156  * @type:   pointer to const application ops and info
0157  * @ctrl_mtu:   MTU to set on the control vNIC (set in .init())
0158  * @netdev_nb:  Netdevice notifier block
0159  * @priv:   app-specific priv data
0160  */
0161 struct nfp_app {
0162     struct pci_dev *pdev;
0163     struct nfp_pf *pf;
0164     struct nfp_cpp *cpp;
0165 
0166     struct nfp_net *ctrl;
0167     struct nfp_reprs __rcu *reprs[NFP_REPR_TYPE_MAX + 1];
0168 
0169     const struct nfp_app_type *type;
0170     unsigned int ctrl_mtu;
0171 
0172     struct notifier_block netdev_nb;
0173 
0174     void *priv;
0175 };
0176 
0177 static inline void assert_nfp_app_locked(struct nfp_app *app)
0178 {
0179     devl_assert_locked(priv_to_devlink(app->pf));
0180 }
0181 
0182 static inline bool nfp_app_is_locked(struct nfp_app *app)
0183 {
0184     return devl_lock_is_held(priv_to_devlink(app->pf));
0185 }
0186 
0187 void nfp_check_rhashtable_empty(void *ptr, void *arg);
0188 bool __nfp_ctrl_tx(struct nfp_net *nn, struct sk_buff *skb);
0189 bool nfp_ctrl_tx(struct nfp_net *nn, struct sk_buff *skb);
0190 
0191 static inline int nfp_app_init(struct nfp_app *app)
0192 {
0193     if (!app->type->init)
0194         return 0;
0195     return app->type->init(app);
0196 }
0197 
0198 static inline void nfp_app_clean(struct nfp_app *app)
0199 {
0200     if (app->type->clean)
0201         app->type->clean(app);
0202 }
0203 
0204 int nfp_app_ndo_init(struct net_device *netdev);
0205 void nfp_app_ndo_uninit(struct net_device *netdev);
0206 
0207 static inline int nfp_app_vnic_alloc(struct nfp_app *app, struct nfp_net *nn,
0208                      unsigned int id)
0209 {
0210     return app->type->vnic_alloc(app, nn, id);
0211 }
0212 
0213 static inline void nfp_app_vnic_free(struct nfp_app *app, struct nfp_net *nn)
0214 {
0215     if (app->type->vnic_free)
0216         app->type->vnic_free(app, nn);
0217 }
0218 
0219 static inline int nfp_app_vnic_init(struct nfp_app *app, struct nfp_net *nn)
0220 {
0221     if (!app->type->vnic_init)
0222         return 0;
0223     return app->type->vnic_init(app, nn);
0224 }
0225 
0226 static inline void nfp_app_vnic_clean(struct nfp_app *app, struct nfp_net *nn)
0227 {
0228     if (app->type->vnic_clean)
0229         app->type->vnic_clean(app, nn);
0230 }
0231 
0232 static inline int nfp_app_repr_open(struct nfp_app *app, struct nfp_repr *repr)
0233 {
0234     if (!app->type->repr_open)
0235         return -EINVAL;
0236     return app->type->repr_open(app, repr);
0237 }
0238 
0239 static inline int nfp_app_repr_stop(struct nfp_app *app, struct nfp_repr *repr)
0240 {
0241     if (!app->type->repr_stop)
0242         return -EINVAL;
0243     return app->type->repr_stop(app, repr);
0244 }
0245 
0246 static inline int
0247 nfp_app_repr_init(struct nfp_app *app, struct net_device *netdev)
0248 {
0249     if (!app->type->repr_init)
0250         return 0;
0251     return app->type->repr_init(app, netdev);
0252 }
0253 
0254 static inline void
0255 nfp_app_repr_preclean(struct nfp_app *app, struct net_device *netdev)
0256 {
0257     if (app->type->repr_preclean)
0258         app->type->repr_preclean(app, netdev);
0259 }
0260 
0261 static inline void
0262 nfp_app_repr_clean(struct nfp_app *app, struct net_device *netdev)
0263 {
0264     if (app->type->repr_clean)
0265         app->type->repr_clean(app, netdev);
0266 }
0267 
0268 static inline int
0269 nfp_app_check_mtu(struct nfp_app *app, struct net_device *netdev, int new_mtu)
0270 {
0271     if (!app || !app->type->check_mtu)
0272         return 0;
0273     return app->type->check_mtu(app, netdev, new_mtu);
0274 }
0275 
0276 static inline int
0277 nfp_app_repr_change_mtu(struct nfp_app *app, struct net_device *netdev,
0278             int new_mtu)
0279 {
0280     if (!app || !app->type->repr_change_mtu)
0281         return 0;
0282     return app->type->repr_change_mtu(app, netdev, new_mtu);
0283 }
0284 
0285 static inline const char *nfp_app_name(struct nfp_app *app)
0286 {
0287     if (!app)
0288         return "";
0289     return app->type->name;
0290 }
0291 
0292 static inline bool nfp_app_needs_ctrl_vnic(struct nfp_app *app)
0293 {
0294     return app && app->type->ctrl_msg_rx;
0295 }
0296 
0297 static inline bool nfp_app_ctrl_has_meta(struct nfp_app *app)
0298 {
0299     return app->type->ctrl_has_meta;
0300 }
0301 
0302 static inline bool nfp_app_ctrl_uses_data_vnics(struct nfp_app *app)
0303 {
0304     return app && app->type->ctrl_msg_rx_raw;
0305 }
0306 
0307 static inline const char *nfp_app_extra_cap(struct nfp_app *app,
0308                         struct nfp_net *nn)
0309 {
0310     if (!app || !app->type->extra_cap)
0311         return "";
0312     return app->type->extra_cap(app, nn);
0313 }
0314 
0315 static inline bool nfp_app_has_tc(struct nfp_app *app)
0316 {
0317     return app && app->type->setup_tc;
0318 }
0319 
0320 static inline int nfp_app_setup_tc(struct nfp_app *app,
0321                    struct net_device *netdev,
0322                    enum tc_setup_type type, void *type_data)
0323 {
0324     if (!app || !app->type->setup_tc)
0325         return -EOPNOTSUPP;
0326     return app->type->setup_tc(app, netdev, type, type_data);
0327 }
0328 
0329 static inline int nfp_app_bpf(struct nfp_app *app, struct nfp_net *nn,
0330                   struct netdev_bpf *bpf)
0331 {
0332     if (!app || !app->type->bpf)
0333         return -EINVAL;
0334     return app->type->bpf(app, nn, bpf);
0335 }
0336 
0337 static inline int nfp_app_xdp_offload(struct nfp_app *app, struct nfp_net *nn,
0338                       struct bpf_prog *prog,
0339                       struct netlink_ext_ack *extack)
0340 {
0341     if (!app || !app->type->xdp_offload)
0342         return -EOPNOTSUPP;
0343     return app->type->xdp_offload(app, nn, prog, extack);
0344 }
0345 
0346 static inline bool __nfp_app_ctrl_tx(struct nfp_app *app, struct sk_buff *skb)
0347 {
0348     trace_devlink_hwmsg(priv_to_devlink(app->pf), false, 0,
0349                 skb->data, skb->len);
0350 
0351     return __nfp_ctrl_tx(app->ctrl, skb);
0352 }
0353 
0354 static inline bool nfp_app_ctrl_tx(struct nfp_app *app, struct sk_buff *skb)
0355 {
0356     trace_devlink_hwmsg(priv_to_devlink(app->pf), false, 0,
0357                 skb->data, skb->len);
0358 
0359     return nfp_ctrl_tx(app->ctrl, skb);
0360 }
0361 
0362 static inline void nfp_app_ctrl_rx(struct nfp_app *app, struct sk_buff *skb)
0363 {
0364     trace_devlink_hwmsg(priv_to_devlink(app->pf), true, 0,
0365                 skb->data, skb->len);
0366 
0367     app->type->ctrl_msg_rx(app, skb);
0368 }
0369 
0370 static inline void
0371 nfp_app_ctrl_rx_raw(struct nfp_app *app, const void *data, unsigned int len)
0372 {
0373     if (!app || !app->type->ctrl_msg_rx_raw)
0374         return;
0375 
0376     trace_devlink_hwmsg(priv_to_devlink(app->pf), true, 0, data, len);
0377     app->type->ctrl_msg_rx_raw(app, data, len);
0378 }
0379 
0380 static inline int nfp_app_eswitch_mode_get(struct nfp_app *app, u16 *mode)
0381 {
0382     if (!app->type->eswitch_mode_get)
0383         return -EOPNOTSUPP;
0384 
0385     *mode = app->type->eswitch_mode_get(app);
0386 
0387     return 0;
0388 }
0389 
0390 static inline int nfp_app_eswitch_mode_set(struct nfp_app *app, u16 mode)
0391 {
0392     if (!app->type->eswitch_mode_set)
0393         return -EOPNOTSUPP;
0394     return app->type->eswitch_mode_set(app, mode);
0395 }
0396 
0397 static inline int nfp_app_sriov_enable(struct nfp_app *app, int num_vfs)
0398 {
0399     if (!app || !app->type->sriov_enable)
0400         return -EOPNOTSUPP;
0401     return app->type->sriov_enable(app, num_vfs);
0402 }
0403 
0404 static inline void nfp_app_sriov_disable(struct nfp_app *app)
0405 {
0406     if (app && app->type->sriov_disable)
0407         app->type->sriov_disable(app);
0408 }
0409 
0410 static inline
0411 struct net_device *nfp_app_dev_get(struct nfp_app *app, u32 id,
0412                    bool *redir_egress)
0413 {
0414     if (unlikely(!app || !app->type->dev_get))
0415         return NULL;
0416 
0417     return app->type->dev_get(app, id, redir_egress);
0418 }
0419 
0420 struct nfp_app *nfp_app_from_netdev(struct net_device *netdev);
0421 
0422 u64 *nfp_app_port_get_stats(struct nfp_port *port, u64 *data);
0423 int nfp_app_port_get_stats_count(struct nfp_port *port);
0424 u8 *nfp_app_port_get_stats_strings(struct nfp_port *port, u8 *data);
0425 
0426 struct nfp_reprs *
0427 nfp_reprs_get_locked(struct nfp_app *app, enum nfp_repr_type type);
0428 struct nfp_reprs *
0429 nfp_app_reprs_set(struct nfp_app *app, enum nfp_repr_type type,
0430           struct nfp_reprs *reprs);
0431 
0432 const char *nfp_app_mip_name(struct nfp_app *app);
0433 struct sk_buff *
0434 nfp_app_ctrl_msg_alloc(struct nfp_app *app, unsigned int size, gfp_t priority);
0435 
0436 struct nfp_app *nfp_app_alloc(struct nfp_pf *pf, enum nfp_app_id id);
0437 void nfp_app_free(struct nfp_app *app);
0438 int nfp_app_start(struct nfp_app *app, struct nfp_net *ctrl);
0439 void nfp_app_stop(struct nfp_app *app);
0440 
0441 /* Callbacks shared between apps */
0442 
0443 int nfp_app_nic_vnic_alloc(struct nfp_app *app, struct nfp_net *nn,
0444                unsigned int id);
0445 int nfp_app_nic_vnic_init_phy_port(struct nfp_pf *pf, struct nfp_app *app,
0446                    struct nfp_net *nn, unsigned int id);
0447 
0448 struct devlink_port *nfp_devlink_get_devlink_port(struct net_device *netdev);
0449 
0450 #endif