1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ 2 /* Copyright (C) 2018 Netronome Systems, Inc. */ 3 4 #ifndef __NFP_ABM_H__ 5 #define __NFP_ABM_H__ 1 6 7 #include <linux/bits.h> 8 #include <linux/radix-tree.h> 9 #include <net/devlink.h> 10 #include <net/pkt_cls.h> 11 #include <net/pkt_sched.h> 12 13 /* Dump of 64 PRIOs and 256 REDs seems to take 850us on Xeon v4 @ 2.20GHz; 14 * 2.5ms / 400Hz seems more than sufficient for stats resolution. 15 */ 16 #define NFP_ABM_STATS_REFRESH_IVAL (2500 * 1000) /* ns */ 17 18 #define NFP_ABM_LVL_INFINITY S32_MAX 19 20 struct nfp_app; 21 struct nfp_net; 22 23 #define NFP_ABM_PORTID_TYPE GENMASK(23, 16) 24 #define NFP_ABM_PORTID_ID GENMASK(7, 0) 25 26 /** 27 * struct nfp_abm - ABM NIC app structure 28 * @app: back pointer to nfp_app 29 * @pf_id: ID of our PF link 30 * 31 * @num_prios: number of supported DSCP priorities 32 * @num_bands: number of supported DSCP priority bands 33 * 34 * @thresholds: current threshold configuration 35 * @threshold_undef: bitmap of thresholds which have not been set 36 * @num_thresholds: number of @thresholds and bits in @threshold_undef 37 * 38 * @eswitch_mode: devlink eswitch mode, advanced functions only visible 39 * in switchdev mode 40 * @q_lvls: queue level control area 41 * @qm_stats: queue statistics symbol 42 * @q_stats: basic queue statistics (only in per-band case) 43 */ 44 struct nfp_abm { 45 struct nfp_app *app; 46 unsigned int pf_id; 47 48 unsigned int num_prios; 49 unsigned int num_bands; 50 51 u32 *thresholds; 52 unsigned long *threshold_undef; 53 size_t num_thresholds; 54 55 enum devlink_eswitch_mode eswitch_mode; 56 const struct nfp_rtsym *q_lvls; 57 const struct nfp_rtsym *qm_stats; 58 const struct nfp_rtsym *q_stats; 59 }; 60 61 /** 62 * struct nfp_alink_stats - ABM NIC statistics 63 * @tx_pkts: number of TXed packets 64 * @tx_bytes: number of TXed bytes 65 * @backlog_pkts: momentary backlog length (packets) 66 * @backlog_bytes: momentary backlog length (bytes) 67 * @overlimits: number of ECN marked TXed packets (accumulative) 68 * @drops: number of tail-dropped packets (accumulative) 69 */ 70 struct nfp_alink_stats { 71 u64 tx_pkts; 72 u64 tx_bytes; 73 u64 backlog_pkts; 74 u64 backlog_bytes; 75 u64 overlimits; 76 u64 drops; 77 }; 78 79 /** 80 * struct nfp_alink_xstats - extended ABM NIC statistics 81 * @ecn_marked: number of ECN marked TXed packets 82 * @pdrop: number of hard drops due to queue limit 83 */ 84 struct nfp_alink_xstats { 85 u64 ecn_marked; 86 u64 pdrop; 87 }; 88 89 enum nfp_qdisc_type { 90 NFP_QDISC_NONE = 0, 91 NFP_QDISC_MQ, 92 NFP_QDISC_RED, 93 NFP_QDISC_GRED, 94 }; 95 96 #define NFP_QDISC_UNTRACKED ((struct nfp_qdisc *)1UL) 97 98 /** 99 * struct nfp_qdisc - tracked TC Qdisc 100 * @netdev: netdev on which Qdisc was created 101 * @type: Qdisc type 102 * @handle: handle of this Qdisc 103 * @parent_handle: handle of the parent (unreliable if Qdisc was grafted) 104 * @use_cnt: number of attachment points in the hierarchy 105 * @num_children: current size of the @children array 106 * @children: pointers to children 107 * 108 * @params_ok: parameters of this Qdisc are OK for offload 109 * @offload_mark: offload refresh state - selected for offload 110 * @offloaded: Qdisc is currently offloaded to the HW 111 * 112 * @mq: MQ Qdisc specific parameters and state 113 * @mq.stats: current stats of the MQ Qdisc 114 * @mq.prev_stats: previously reported @mq.stats 115 * 116 * @red: RED Qdisc specific parameters and state 117 * @red.num_bands: Number of valid entries in the @red.band table 118 * @red.band: Per-band array of RED instances 119 * @red.band.threshold: ECN marking threshold 120 * @red.band.stats: current stats of the RED Qdisc 121 * @red.band.prev_stats: previously reported @red.stats 122 * @red.band.xstats: extended stats for RED - current 123 * @red.band.prev_xstats: extended stats for RED - previously reported 124 */ 125 struct nfp_qdisc { 126 struct net_device *netdev; 127 enum nfp_qdisc_type type; 128 u32 handle; 129 u32 parent_handle; 130 unsigned int use_cnt; 131 unsigned int num_children; 132 struct nfp_qdisc **children; 133 134 bool params_ok; 135 bool offload_mark; 136 bool offloaded; 137 138 union { 139 /* NFP_QDISC_MQ */ 140 struct { 141 struct nfp_alink_stats stats; 142 struct nfp_alink_stats prev_stats; 143 } mq; 144 /* TC_SETUP_QDISC_RED, TC_SETUP_QDISC_GRED */ 145 struct { 146 unsigned int num_bands; 147 148 struct { 149 u32 threshold; 150 struct nfp_alink_stats stats; 151 struct nfp_alink_stats prev_stats; 152 struct nfp_alink_xstats xstats; 153 struct nfp_alink_xstats prev_xstats; 154 } band[MAX_DPs]; 155 } red; 156 }; 157 }; 158 159 /** 160 * struct nfp_abm_link - port tuple of a ABM NIC 161 * @abm: back pointer to nfp_abm 162 * @vnic: data vNIC 163 * @id: id of the data vNIC 164 * @queue_base: id of base to host queue within PCIe (not QC idx) 165 * @total_queues: number of PF queues 166 * 167 * @last_stats_update: ktime of last stats update 168 * 169 * @def_band: default band to use 170 * 171 * @root_qdisc: pointer to the current root of the Qdisc hierarchy 172 * @qdiscs: all qdiscs recorded by major part of the handle 173 */ 174 struct nfp_abm_link { 175 struct nfp_abm *abm; 176 struct nfp_net *vnic; 177 unsigned int id; 178 unsigned int queue_base; 179 unsigned int total_queues; 180 181 u64 last_stats_update; 182 183 u8 def_band; 184 185 struct nfp_qdisc *root_qdisc; 186 struct radix_tree_root qdiscs; 187 }; 188 189 static inline bool nfp_abm_has_prio(struct nfp_abm *abm) 190 { 191 return abm->num_bands > 1; 192 } 193 194 void nfp_abm_qdisc_offload_update(struct nfp_abm_link *alink); 195 int nfp_abm_setup_root(struct net_device *netdev, struct nfp_abm_link *alink, 196 struct tc_root_qopt_offload *opt); 197 int nfp_abm_setup_tc_red(struct net_device *netdev, struct nfp_abm_link *alink, 198 struct tc_red_qopt_offload *opt); 199 int nfp_abm_setup_tc_mq(struct net_device *netdev, struct nfp_abm_link *alink, 200 struct tc_mq_qopt_offload *opt); 201 int nfp_abm_setup_tc_gred(struct net_device *netdev, struct nfp_abm_link *alink, 202 struct tc_gred_qopt_offload *opt); 203 204 void nfp_abm_ctrl_read_params(struct nfp_abm_link *alink); 205 int nfp_abm_ctrl_find_addrs(struct nfp_abm *abm); 206 int __nfp_abm_ctrl_set_q_lvl(struct nfp_abm *abm, unsigned int id, u32 val); 207 int nfp_abm_ctrl_set_q_lvl(struct nfp_abm_link *alink, unsigned int band, 208 unsigned int queue, u32 val); 209 int nfp_abm_ctrl_read_q_stats(struct nfp_abm_link *alink, 210 unsigned int band, unsigned int queue, 211 struct nfp_alink_stats *stats); 212 int nfp_abm_ctrl_read_q_xstats(struct nfp_abm_link *alink, 213 unsigned int band, unsigned int queue, 214 struct nfp_alink_xstats *xstats); 215 u64 nfp_abm_ctrl_stat_non_sto(struct nfp_abm_link *alink, unsigned int i); 216 u64 nfp_abm_ctrl_stat_sto(struct nfp_abm_link *alink, unsigned int i); 217 int nfp_abm_ctrl_qm_enable(struct nfp_abm *abm); 218 int nfp_abm_ctrl_qm_disable(struct nfp_abm *abm); 219 #endif 220