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