1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
2 /* Copyright (C) 2018 Netronome Systems, Inc. */
5 #define __NFP_ABM_H__ 1
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>
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.
17 #define NFP_ABM_STATS_REFRESH_IVAL (2500 * 1000) /* ns */
19 #define NFP_ABM_LVL_INFINITY S32_MAX
24 #define NFP_ABM_PORTID_TYPE GENMASK(23, 16)
25 #define NFP_ABM_PORTID_ID GENMASK(7, 0)
27 /* The possible actions if thresholds are exceeded */
28 enum nfp_abm_q_action
{
29 /* mark if ECN capable, otherwise drop */
30 NFP_ABM_ACT_MARK_DROP
= 0,
31 /* mark if ECN capable, otherwise goto QM */
32 NFP_ABM_ACT_MARK_QUEUE
= 1,
34 NFP_ABM_ACT_QUEUE
= 3,
35 NFP_ABM_ACT_NOQUEUE
= 4,
39 * struct nfp_abm - ABM NIC app structure
40 * @app: back pointer to nfp_app
41 * @pf_id: ID of our PF link
43 * @red_support: is RED offload supported
44 * @num_prios: number of supported DSCP priorities
45 * @num_bands: number of supported DSCP priority bands
46 * @action_mask: bitmask of supported actions
48 * @thresholds: current threshold configuration
49 * @threshold_undef: bitmap of thresholds which have not been set
50 * @actions: current FW action configuration
51 * @num_thresholds: number of @thresholds and bits in @threshold_undef
53 * @prio_map_len: computed length of FW priority map (in bytes)
54 * @dscp_mask: mask FW will apply on DSCP field
56 * @eswitch_mode: devlink eswitch mode, advanced functions only visible
59 * @q_lvls: queue level control area
60 * @qm_stats: queue statistics symbol
61 * @q_stats: basic queue statistics (only in per-band case)
67 unsigned int red_support
;
68 unsigned int num_prios
;
69 unsigned int num_bands
;
70 unsigned int action_mask
;
73 unsigned long *threshold_undef
;
75 size_t num_thresholds
;
77 unsigned int prio_map_len
;
80 enum devlink_eswitch_mode eswitch_mode
;
82 const struct nfp_rtsym
*q_lvls
;
83 const struct nfp_rtsym
*qm_stats
;
84 const struct nfp_rtsym
*q_stats
;
88 * struct nfp_alink_stats - ABM NIC statistics
89 * @tx_pkts: number of TXed packets
90 * @tx_bytes: number of TXed bytes
91 * @backlog_pkts: momentary backlog length (packets)
92 * @backlog_bytes: momentary backlog length (bytes)
93 * @overlimits: number of ECN marked TXed packets (accumulative)
94 * @drops: number of tail-dropped packets (accumulative)
96 struct nfp_alink_stats
{
106 * struct nfp_alink_xstats - extended ABM NIC statistics
107 * @ecn_marked: number of ECN marked TXed packets
108 * @pdrop: number of hard drops due to queue limit
110 struct nfp_alink_xstats
{
115 enum nfp_qdisc_type
{
122 #define NFP_QDISC_UNTRACKED ((struct nfp_qdisc *)1UL)
125 * struct nfp_qdisc - tracked TC Qdisc
126 * @netdev: netdev on which Qdisc was created
128 * @handle: handle of this Qdisc
129 * @parent_handle: handle of the parent (unreliable if Qdisc was grafted)
130 * @use_cnt: number of attachment points in the hierarchy
131 * @num_children: current size of the @children array
132 * @children: pointers to children
134 * @params_ok: parameters of this Qdisc are OK for offload
135 * @offload_mark: offload refresh state - selected for offload
136 * @offloaded: Qdisc is currently offloaded to the HW
138 * @mq: MQ Qdisc specific parameters and state
139 * @mq.stats: current stats of the MQ Qdisc
140 * @mq.prev_stats: previously reported @mq.stats
142 * @red: RED Qdisc specific parameters and state
143 * @red.num_bands: Number of valid entries in the @red.band table
144 * @red.band: Per-band array of RED instances
145 * @red.band.ecn: ECN marking is enabled (rather than drop)
146 * @red.band.threshold: ECN marking threshold
147 * @red.band.stats: current stats of the RED Qdisc
148 * @red.band.prev_stats: previously reported @red.stats
149 * @red.band.xstats: extended stats for RED - current
150 * @red.band.prev_xstats: extended stats for RED - previously reported
153 struct net_device
*netdev
;
154 enum nfp_qdisc_type type
;
157 unsigned int use_cnt
;
158 unsigned int num_children
;
159 struct nfp_qdisc
**children
;
168 struct nfp_alink_stats stats
;
169 struct nfp_alink_stats prev_stats
;
171 /* TC_SETUP_QDISC_RED, TC_SETUP_QDISC_GRED */
173 unsigned int num_bands
;
178 struct nfp_alink_stats stats
;
179 struct nfp_alink_stats prev_stats
;
180 struct nfp_alink_xstats xstats
;
181 struct nfp_alink_xstats prev_xstats
;
188 * struct nfp_abm_link - port tuple of a ABM NIC
189 * @abm: back pointer to nfp_abm
191 * @id: id of the data vNIC
192 * @queue_base: id of base to host queue within PCIe (not QC idx)
193 * @total_queues: number of PF queues
195 * @last_stats_update: ktime of last stats update
197 * @prio_map: current map of priorities
198 * @has_prio: @prio_map is valid
200 * @def_band: default band to use
201 * @dscp_map: list of DSCP to band mappings
203 * @root_qdisc: pointer to the current root of the Qdisc hierarchy
204 * @qdiscs: all qdiscs recorded by major part of the handle
206 struct nfp_abm_link
{
208 struct nfp_net
*vnic
;
210 unsigned int queue_base
;
211 unsigned int total_queues
;
213 u64 last_stats_update
;
219 struct list_head dscp_map
;
221 struct nfp_qdisc
*root_qdisc
;
222 struct radix_tree_root qdiscs
;
225 static inline bool nfp_abm_has_prio(struct nfp_abm
*abm
)
227 return abm
->num_bands
> 1;
230 static inline bool nfp_abm_has_drop(struct nfp_abm
*abm
)
232 return abm
->action_mask
& BIT(NFP_ABM_ACT_DROP
);
235 static inline bool nfp_abm_has_mark(struct nfp_abm
*abm
)
237 return abm
->action_mask
& BIT(NFP_ABM_ACT_MARK_DROP
);
240 void nfp_abm_qdisc_offload_update(struct nfp_abm_link
*alink
);
241 int nfp_abm_setup_root(struct net_device
*netdev
, struct nfp_abm_link
*alink
,
242 struct tc_root_qopt_offload
*opt
);
243 int nfp_abm_setup_tc_red(struct net_device
*netdev
, struct nfp_abm_link
*alink
,
244 struct tc_red_qopt_offload
*opt
);
245 int nfp_abm_setup_tc_mq(struct net_device
*netdev
, struct nfp_abm_link
*alink
,
246 struct tc_mq_qopt_offload
*opt
);
247 int nfp_abm_setup_tc_gred(struct net_device
*netdev
, struct nfp_abm_link
*alink
,
248 struct tc_gred_qopt_offload
*opt
);
249 int nfp_abm_setup_cls_block(struct net_device
*netdev
, struct nfp_repr
*repr
,
250 struct flow_block_offload
*opt
);
252 int nfp_abm_ctrl_read_params(struct nfp_abm_link
*alink
);
253 int nfp_abm_ctrl_find_addrs(struct nfp_abm
*abm
);
254 int __nfp_abm_ctrl_set_q_lvl(struct nfp_abm
*abm
, unsigned int id
, u32 val
);
255 int nfp_abm_ctrl_set_q_lvl(struct nfp_abm_link
*alink
, unsigned int band
,
256 unsigned int queue
, u32 val
);
257 int __nfp_abm_ctrl_set_q_act(struct nfp_abm
*abm
, unsigned int id
,
258 enum nfp_abm_q_action act
);
259 int nfp_abm_ctrl_set_q_act(struct nfp_abm_link
*alink
, unsigned int band
,
260 unsigned int queue
, enum nfp_abm_q_action act
);
261 int nfp_abm_ctrl_read_q_stats(struct nfp_abm_link
*alink
,
262 unsigned int band
, unsigned int queue
,
263 struct nfp_alink_stats
*stats
);
264 int nfp_abm_ctrl_read_q_xstats(struct nfp_abm_link
*alink
,
265 unsigned int band
, unsigned int queue
,
266 struct nfp_alink_xstats
*xstats
);
267 u64
nfp_abm_ctrl_stat_non_sto(struct nfp_abm_link
*alink
, unsigned int i
);
268 u64
nfp_abm_ctrl_stat_sto(struct nfp_abm_link
*alink
, unsigned int i
);
269 int nfp_abm_ctrl_qm_enable(struct nfp_abm
*abm
);
270 int nfp_abm_ctrl_qm_disable(struct nfp_abm
*abm
);
271 void nfp_abm_prio_map_update(struct nfp_abm
*abm
);
272 int nfp_abm_ctrl_prio_map_update(struct nfp_abm_link
*alink
, u32
*packed
);