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 * @prio_map_len: computed length of FW priority map (in bytes) 38 * 39 * @eswitch_mode: devlink eswitch mode, advanced functions only visible 40 * in switchdev mode 41 * 42 * @q_lvls: queue level control area 43 * @qm_stats: queue statistics symbol 44 * @q_stats: basic queue statistics (only in per-band case) 45 */ 46 struct nfp_abm { 47 struct nfp_app *app; 48 unsigned int pf_id; 49 50 unsigned int num_prios; 51 unsigned int num_bands; 52 53 u32 *thresholds; 54 unsigned long *threshold_undef; 55 size_t num_thresholds; 56 unsigned int prio_map_len; 57 58 enum devlink_eswitch_mode eswitch_mode; 59 60 const struct nfp_rtsym *q_lvls; 61 const struct nfp_rtsym *qm_stats; 62 const struct nfp_rtsym *q_stats; 63 }; 64 65 /** 66 * struct nfp_alink_stats - ABM NIC statistics 67 * @tx_pkts: number of TXed packets 68 * @tx_bytes: number of TXed bytes 69 * @backlog_pkts: momentary backlog length (packets) 70 * @backlog_bytes: momentary backlog length (bytes) 71 * @overlimits: number of ECN marked TXed packets (accumulative) 72 * @drops: number of tail-dropped packets (accumulative) 73 */ 74 struct nfp_alink_stats { 75 u64 tx_pkts; 76 u64 tx_bytes; 77 u64 backlog_pkts; 78 u64 backlog_bytes; 79 u64 overlimits; 80 u64 drops; 81 }; 82 83 /** 84 * struct nfp_alink_xstats - extended ABM NIC statistics 85 * @ecn_marked: number of ECN marked TXed packets 86 * @pdrop: number of hard drops due to queue limit 87 */ 88 struct nfp_alink_xstats { 89 u64 ecn_marked; 90 u64 pdrop; 91 }; 92 93 enum nfp_qdisc_type { 94 NFP_QDISC_NONE = 0, 95 NFP_QDISC_MQ, 96 NFP_QDISC_RED, 97 NFP_QDISC_GRED, 98 }; 99 100 #define NFP_QDISC_UNTRACKED ((struct nfp_qdisc *)1UL) 101 102 /** 103 * struct nfp_qdisc - tracked TC Qdisc 104 * @netdev: netdev on which Qdisc was created 105 * @type: Qdisc type 106 * @handle: handle of this Qdisc 107 * @parent_handle: handle of the parent (unreliable if Qdisc was grafted) 108 * @use_cnt: number of attachment points in the hierarchy 109 * @num_children: current size of the @children array 110 * @children: pointers to children 111 * 112 * @params_ok: parameters of this Qdisc are OK for offload 113 * @offload_mark: offload refresh state - selected for offload 114 * @offloaded: Qdisc is currently offloaded to the HW 115 * 116 * @mq: MQ Qdisc specific parameters and state 117 * @mq.stats: current stats of the MQ Qdisc 118 * @mq.prev_stats: previously reported @mq.stats 119 * 120 * @red: RED Qdisc specific parameters and state 121 * @red.num_bands: Number of valid entries in the @red.band table 122 * @red.band: Per-band array of RED instances 123 * @red.band.threshold: ECN marking threshold 124 * @red.band.stats: current stats of the RED Qdisc 125 * @red.band.prev_stats: previously reported @red.stats 126 * @red.band.xstats: extended stats for RED - current 127 * @red.band.prev_xstats: extended stats for RED - previously reported 128 */ 129 struct nfp_qdisc { 130 struct net_device *netdev; 131 enum nfp_qdisc_type type; 132 u32 handle; 133 u32 parent_handle; 134 unsigned int use_cnt; 135 unsigned int num_children; 136 struct nfp_qdisc **children; 137 138 bool params_ok; 139 bool offload_mark; 140 bool offloaded; 141 142 union { 143 /* NFP_QDISC_MQ */ 144 struct { 145 struct nfp_alink_stats stats; 146 struct nfp_alink_stats prev_stats; 147 } mq; 148 /* TC_SETUP_QDISC_RED, TC_SETUP_QDISC_GRED */ 149 struct { 150 unsigned int num_bands; 151 152 struct { 153 u32 threshold; 154 struct nfp_alink_stats stats; 155 struct nfp_alink_stats prev_stats; 156 struct nfp_alink_xstats xstats; 157 struct nfp_alink_xstats prev_xstats; 158 } band[MAX_DPs]; 159 } red; 160 }; 161 }; 162 163 /** 164 * struct nfp_abm_link - port tuple of a ABM NIC 165 * @abm: back pointer to nfp_abm 166 * @vnic: data vNIC 167 * @id: id of the data vNIC 168 * @queue_base: id of base to host queue within PCIe (not QC idx) 169 * @total_queues: number of PF queues 170 * 171 * @last_stats_update: ktime of last stats update 172 * 173 * @def_band: default band to use 174 * 175 * @root_qdisc: pointer to the current root of the Qdisc hierarchy 176 * @qdiscs: all qdiscs recorded by major part of the handle 177 */ 178 struct nfp_abm_link { 179 struct nfp_abm *abm; 180 struct nfp_net *vnic; 181 unsigned int id; 182 unsigned int queue_base; 183 unsigned int total_queues; 184 185 u64 last_stats_update; 186 187 u8 def_band; 188 189 struct nfp_qdisc *root_qdisc; 190 struct radix_tree_root qdiscs; 191 }; 192 193 static inline bool nfp_abm_has_prio(struct nfp_abm *abm) 194 { 195 return abm->num_bands > 1; 196 } 197 198 void nfp_abm_qdisc_offload_update(struct nfp_abm_link *alink); 199 int nfp_abm_setup_root(struct net_device *netdev, struct nfp_abm_link *alink, 200 struct tc_root_qopt_offload *opt); 201 int nfp_abm_setup_tc_red(struct net_device *netdev, struct nfp_abm_link *alink, 202 struct tc_red_qopt_offload *opt); 203 int nfp_abm_setup_tc_mq(struct net_device *netdev, struct nfp_abm_link *alink, 204 struct tc_mq_qopt_offload *opt); 205 int nfp_abm_setup_tc_gred(struct net_device *netdev, struct nfp_abm_link *alink, 206 struct tc_gred_qopt_offload *opt); 207 208 int nfp_abm_ctrl_read_params(struct nfp_abm_link *alink); 209 int nfp_abm_ctrl_find_addrs(struct nfp_abm *abm); 210 int __nfp_abm_ctrl_set_q_lvl(struct nfp_abm *abm, unsigned int id, u32 val); 211 int nfp_abm_ctrl_set_q_lvl(struct nfp_abm_link *alink, unsigned int band, 212 unsigned int queue, u32 val); 213 int nfp_abm_ctrl_read_q_stats(struct nfp_abm_link *alink, 214 unsigned int band, unsigned int queue, 215 struct nfp_alink_stats *stats); 216 int nfp_abm_ctrl_read_q_xstats(struct nfp_abm_link *alink, 217 unsigned int band, unsigned int queue, 218 struct nfp_alink_xstats *xstats); 219 u64 nfp_abm_ctrl_stat_non_sto(struct nfp_abm_link *alink, unsigned int i); 220 u64 nfp_abm_ctrl_stat_sto(struct nfp_abm_link *alink, unsigned int i); 221 int nfp_abm_ctrl_qm_enable(struct nfp_abm *abm); 222 int nfp_abm_ctrl_qm_disable(struct nfp_abm *abm); 223 #endif 224