Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
0002 /* Copyright (C) 2018 Netronome Systems, Inc. */
0003 
0004 #ifndef __NFP_ABM_H__
0005 #define __NFP_ABM_H__ 1
0006 
0007 #include <linux/bits.h>
0008 #include <linux/list.h>
0009 #include <linux/radix-tree.h>
0010 #include <net/devlink.h>
0011 #include <net/pkt_cls.h>
0012 #include <net/pkt_sched.h>
0013 
0014 /* Dump of 64 PRIOs and 256 REDs seems to take 850us on Xeon v4 @ 2.20GHz;
0015  * 2.5ms / 400Hz seems more than sufficient for stats resolution.
0016  */
0017 #define NFP_ABM_STATS_REFRESH_IVAL  (2500 * 1000) /* ns */
0018 
0019 #define NFP_ABM_LVL_INFINITY        S32_MAX
0020 
0021 struct nfp_app;
0022 struct nfp_net;
0023 
0024 #define NFP_ABM_PORTID_TYPE GENMASK(23, 16)
0025 #define NFP_ABM_PORTID_ID   GENMASK(7, 0)
0026 
0027 /* The possible actions if thresholds are exceeded */
0028 enum nfp_abm_q_action {
0029     /* mark if ECN capable, otherwise drop */
0030     NFP_ABM_ACT_MARK_DROP       = 0,
0031     /* mark if ECN capable, otherwise goto QM */
0032     NFP_ABM_ACT_MARK_QUEUE      = 1,
0033     NFP_ABM_ACT_DROP        = 2,
0034     NFP_ABM_ACT_QUEUE       = 3,
0035     NFP_ABM_ACT_NOQUEUE     = 4,
0036 };
0037 
0038 /**
0039  * struct nfp_abm - ABM NIC app structure
0040  * @app:    back pointer to nfp_app
0041  * @pf_id:  ID of our PF link
0042  *
0043  * @red_support:    is RED offload supported
0044  * @num_prios:  number of supported DSCP priorities
0045  * @num_bands:  number of supported DSCP priority bands
0046  * @action_mask:    bitmask of supported actions
0047  *
0048  * @thresholds:     current threshold configuration
0049  * @threshold_undef:    bitmap of thresholds which have not been set
0050  * @actions:        current FW action configuration
0051  * @num_thresholds: number of @thresholds and bits in @threshold_undef
0052  *
0053  * @prio_map_len:   computed length of FW priority map (in bytes)
0054  * @dscp_mask:      mask FW will apply on DSCP field
0055  *
0056  * @eswitch_mode:   devlink eswitch mode, advanced functions only visible
0057  *          in switchdev mode
0058  *
0059  * @q_lvls: queue level control area
0060  * @qm_stats:   queue statistics symbol
0061  * @q_stats:    basic queue statistics (only in per-band case)
0062  */
0063 struct nfp_abm {
0064     struct nfp_app *app;
0065     unsigned int pf_id;
0066 
0067     unsigned int red_support;
0068     unsigned int num_prios;
0069     unsigned int num_bands;
0070     unsigned int action_mask;
0071 
0072     u32 *thresholds;
0073     unsigned long *threshold_undef;
0074     u8 *actions;
0075     size_t num_thresholds;
0076 
0077     unsigned int prio_map_len;
0078     u8 dscp_mask;
0079 
0080     enum devlink_eswitch_mode eswitch_mode;
0081 
0082     const struct nfp_rtsym *q_lvls;
0083     const struct nfp_rtsym *qm_stats;
0084     const struct nfp_rtsym *q_stats;
0085 };
0086 
0087 /**
0088  * struct nfp_alink_stats - ABM NIC statistics
0089  * @tx_pkts:        number of TXed packets
0090  * @tx_bytes:       number of TXed bytes
0091  * @backlog_pkts:   momentary backlog length (packets)
0092  * @backlog_bytes:  momentary backlog length (bytes)
0093  * @overlimits:     number of ECN marked TXed packets (accumulative)
0094  * @drops:      number of tail-dropped packets (accumulative)
0095  */
0096 struct nfp_alink_stats {
0097     u64 tx_pkts;
0098     u64 tx_bytes;
0099     u64 backlog_pkts;
0100     u64 backlog_bytes;
0101     u64 overlimits;
0102     u64 drops;
0103 };
0104 
0105 /**
0106  * struct nfp_alink_xstats - extended ABM NIC statistics
0107  * @ecn_marked:     number of ECN marked TXed packets
0108  * @pdrop:      number of hard drops due to queue limit
0109  */
0110 struct nfp_alink_xstats {
0111     u64 ecn_marked;
0112     u64 pdrop;
0113 };
0114 
0115 enum nfp_qdisc_type {
0116     NFP_QDISC_NONE = 0,
0117     NFP_QDISC_MQ,
0118     NFP_QDISC_RED,
0119     NFP_QDISC_GRED,
0120 };
0121 
0122 #define NFP_QDISC_UNTRACKED ((struct nfp_qdisc *)1UL)
0123 
0124 /**
0125  * struct nfp_qdisc - tracked TC Qdisc
0126  * @netdev:     netdev on which Qdisc was created
0127  * @type:       Qdisc type
0128  * @handle:     handle of this Qdisc
0129  * @parent_handle:  handle of the parent (unreliable if Qdisc was grafted)
0130  * @use_cnt:        number of attachment points in the hierarchy
0131  * @num_children:   current size of the @children array
0132  * @children:       pointers to children
0133  *
0134  * @params_ok:      parameters of this Qdisc are OK for offload
0135  * @offload_mark:   offload refresh state - selected for offload
0136  * @offloaded:      Qdisc is currently offloaded to the HW
0137  *
0138  * @mq:         MQ Qdisc specific parameters and state
0139  * @mq.stats:       current stats of the MQ Qdisc
0140  * @mq.prev_stats:  previously reported @mq.stats
0141  *
0142  * @red:        RED Qdisc specific parameters and state
0143  * @red.num_bands:  Number of valid entries in the @red.band table
0144  * @red.band:       Per-band array of RED instances
0145  * @red.band.ecn:       ECN marking is enabled (rather than drop)
0146  * @red.band.threshold:     ECN marking threshold
0147  * @red.band.stats:     current stats of the RED Qdisc
0148  * @red.band.prev_stats:    previously reported @red.stats
0149  * @red.band.xstats:        extended stats for RED - current
0150  * @red.band.prev_xstats:   extended stats for RED - previously reported
0151  */
0152 struct nfp_qdisc {
0153     struct net_device *netdev;
0154     enum nfp_qdisc_type type;
0155     u32 handle;
0156     u32 parent_handle;
0157     unsigned int use_cnt;
0158     unsigned int num_children;
0159     struct nfp_qdisc **children;
0160 
0161     bool params_ok;
0162     bool offload_mark;
0163     bool offloaded;
0164 
0165     union {
0166         /* NFP_QDISC_MQ */
0167         struct {
0168             struct nfp_alink_stats stats;
0169             struct nfp_alink_stats prev_stats;
0170         } mq;
0171         /* TC_SETUP_QDISC_RED, TC_SETUP_QDISC_GRED */
0172         struct {
0173             unsigned int num_bands;
0174 
0175             struct {
0176                 bool ecn;
0177                 u32 threshold;
0178                 struct nfp_alink_stats stats;
0179                 struct nfp_alink_stats prev_stats;
0180                 struct nfp_alink_xstats xstats;
0181                 struct nfp_alink_xstats prev_xstats;
0182             } band[MAX_DPs];
0183         } red;
0184     };
0185 };
0186 
0187 /**
0188  * struct nfp_abm_link - port tuple of a ABM NIC
0189  * @abm:    back pointer to nfp_abm
0190  * @vnic:   data vNIC
0191  * @id:     id of the data vNIC
0192  * @queue_base: id of base to host queue within PCIe (not QC idx)
0193  * @total_queues:   number of PF queues
0194  *
0195  * @last_stats_update:  ktime of last stats update
0196  *
0197  * @prio_map:       current map of priorities
0198  * @has_prio:       @prio_map is valid
0199  *
0200  * @def_band:       default band to use
0201  * @dscp_map:       list of DSCP to band mappings
0202  *
0203  * @root_qdisc: pointer to the current root of the Qdisc hierarchy
0204  * @qdiscs: all qdiscs recorded by major part of the handle
0205  */
0206 struct nfp_abm_link {
0207     struct nfp_abm *abm;
0208     struct nfp_net *vnic;
0209     unsigned int id;
0210     unsigned int queue_base;
0211     unsigned int total_queues;
0212 
0213     u64 last_stats_update;
0214 
0215     u32 *prio_map;
0216     bool has_prio;
0217 
0218     u8 def_band;
0219     struct list_head dscp_map;
0220 
0221     struct nfp_qdisc *root_qdisc;
0222     struct radix_tree_root qdiscs;
0223 };
0224 
0225 static inline bool nfp_abm_has_prio(struct nfp_abm *abm)
0226 {
0227     return abm->num_bands > 1;
0228 }
0229 
0230 static inline bool nfp_abm_has_drop(struct nfp_abm *abm)
0231 {
0232     return abm->action_mask & BIT(NFP_ABM_ACT_DROP);
0233 }
0234 
0235 static inline bool nfp_abm_has_mark(struct nfp_abm *abm)
0236 {
0237     return abm->action_mask & BIT(NFP_ABM_ACT_MARK_DROP);
0238 }
0239 
0240 void nfp_abm_qdisc_offload_update(struct nfp_abm_link *alink);
0241 int nfp_abm_setup_root(struct net_device *netdev, struct nfp_abm_link *alink,
0242                struct tc_root_qopt_offload *opt);
0243 int nfp_abm_setup_tc_red(struct net_device *netdev, struct nfp_abm_link *alink,
0244              struct tc_red_qopt_offload *opt);
0245 int nfp_abm_setup_tc_mq(struct net_device *netdev, struct nfp_abm_link *alink,
0246             struct tc_mq_qopt_offload *opt);
0247 int nfp_abm_setup_tc_gred(struct net_device *netdev, struct nfp_abm_link *alink,
0248               struct tc_gred_qopt_offload *opt);
0249 int nfp_abm_setup_cls_block(struct net_device *netdev, struct nfp_repr *repr,
0250                 struct flow_block_offload *opt);
0251 
0252 int nfp_abm_ctrl_read_params(struct nfp_abm_link *alink);
0253 int nfp_abm_ctrl_find_addrs(struct nfp_abm *abm);
0254 int __nfp_abm_ctrl_set_q_lvl(struct nfp_abm *abm, unsigned int id, u32 val);
0255 int nfp_abm_ctrl_set_q_lvl(struct nfp_abm_link *alink, unsigned int band,
0256                unsigned int queue, u32 val);
0257 int __nfp_abm_ctrl_set_q_act(struct nfp_abm *abm, unsigned int id,
0258                  enum nfp_abm_q_action act);
0259 int nfp_abm_ctrl_set_q_act(struct nfp_abm_link *alink, unsigned int band,
0260                unsigned int queue, enum nfp_abm_q_action act);
0261 int nfp_abm_ctrl_read_q_stats(struct nfp_abm_link *alink,
0262                   unsigned int band, unsigned int queue,
0263                   struct nfp_alink_stats *stats);
0264 int nfp_abm_ctrl_read_q_xstats(struct nfp_abm_link *alink,
0265                    unsigned int band, unsigned int queue,
0266                    struct nfp_alink_xstats *xstats);
0267 u64 nfp_abm_ctrl_stat_non_sto(struct nfp_abm_link *alink, unsigned int i);
0268 u64 nfp_abm_ctrl_stat_sto(struct nfp_abm_link *alink, unsigned int i);
0269 int nfp_abm_ctrl_qm_enable(struct nfp_abm *abm);
0270 int nfp_abm_ctrl_qm_disable(struct nfp_abm *abm);
0271 void nfp_abm_prio_map_update(struct nfp_abm *abm);
0272 int nfp_abm_ctrl_prio_map_update(struct nfp_abm_link *alink, u32 *packed);
0273 #endif