xref: /openbmc/linux/drivers/net/ethernet/marvell/octeontx2/nic/qos.h (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
1ab6dddd2SSubbaraya Sundeep /* SPDX-License-Identifier: GPL-2.0 */
2ab6dddd2SSubbaraya Sundeep /* Marvell RVU Ethernet driver
3ab6dddd2SSubbaraya Sundeep  *
4ab6dddd2SSubbaraya Sundeep  * Copyright (C) 2023 Marvell.
5ab6dddd2SSubbaraya Sundeep  *
6ab6dddd2SSubbaraya Sundeep  */
7ab6dddd2SSubbaraya Sundeep #ifndef OTX2_QOS_H
8ab6dddd2SSubbaraya Sundeep #define OTX2_QOS_H
9ab6dddd2SSubbaraya Sundeep 
105e6808b4SNaveen Mamindlapalli #include <linux/types.h>
115e6808b4SNaveen Mamindlapalli #include <linux/netdevice.h>
125e6808b4SNaveen Mamindlapalli #include <linux/rhashtable.h>
135e6808b4SNaveen Mamindlapalli 
145e6808b4SNaveen Mamindlapalli #define OTX2_QOS_MAX_LVL		4
155e6808b4SNaveen Mamindlapalli #define OTX2_QOS_MAX_PRIO		7
16ab6dddd2SSubbaraya Sundeep #define OTX2_QOS_MAX_LEAF_NODES                16
17ab6dddd2SSubbaraya Sundeep 
185e6808b4SNaveen Mamindlapalli enum qos_smq_operations {
195e6808b4SNaveen Mamindlapalli 	QOS_CFG_SQ,
205e6808b4SNaveen Mamindlapalli 	QOS_SMQ_FLUSH,
215e6808b4SNaveen Mamindlapalli };
225e6808b4SNaveen Mamindlapalli 
235e6808b4SNaveen Mamindlapalli u64 otx2_get_txschq_rate_regval(struct otx2_nic *nic, u64 maxrate, u32 burst);
245e6808b4SNaveen Mamindlapalli 
255e6808b4SNaveen Mamindlapalli int otx2_setup_tc_htb(struct net_device *ndev, struct tc_htb_qopt_offload *htb);
265e6808b4SNaveen Mamindlapalli int otx2_qos_get_qid(struct otx2_nic *pfvf);
275e6808b4SNaveen Mamindlapalli void otx2_qos_free_qid(struct otx2_nic *pfvf, int qidx);
285e6808b4SNaveen Mamindlapalli int otx2_qos_enable_sq(struct otx2_nic *pfvf, int qidx);
295e6808b4SNaveen Mamindlapalli void otx2_qos_disable_sq(struct otx2_nic *pfvf, int qidx);
305e6808b4SNaveen Mamindlapalli 
315e6808b4SNaveen Mamindlapalli struct otx2_qos_cfg {
325e6808b4SNaveen Mamindlapalli 	u16 schq[NIX_TXSCH_LVL_CNT];
335e6808b4SNaveen Mamindlapalli 	u16 schq_contig[NIX_TXSCH_LVL_CNT];
345e6808b4SNaveen Mamindlapalli 	int static_node_pos[NIX_TXSCH_LVL_CNT];
355e6808b4SNaveen Mamindlapalli 	int dwrr_node_pos[NIX_TXSCH_LVL_CNT];
365e6808b4SNaveen Mamindlapalli 	u16 schq_contig_list[NIX_TXSCH_LVL_CNT][MAX_TXSCHQ_PER_FUNC];
375e6808b4SNaveen Mamindlapalli 	u16 schq_list[NIX_TXSCH_LVL_CNT][MAX_TXSCHQ_PER_FUNC];
38f78dca69SNaveen Mamindlapalli 	bool schq_index_used[NIX_TXSCH_LVL_CNT][MAX_TXSCHQ_PER_FUNC];
395e6808b4SNaveen Mamindlapalli };
40ab6dddd2SSubbaraya Sundeep 
41ab6dddd2SSubbaraya Sundeep struct otx2_qos {
425e6808b4SNaveen Mamindlapalli 	DECLARE_HASHTABLE(qos_hlist, order_base_2(OTX2_QOS_MAX_LEAF_NODES));
435e6808b4SNaveen Mamindlapalli 	struct mutex qos_lock; /* child list lock */
44ab6dddd2SSubbaraya Sundeep 	u16 qid_to_sqmap[OTX2_QOS_MAX_LEAF_NODES];
455e6808b4SNaveen Mamindlapalli 	struct list_head qos_tree;
465e6808b4SNaveen Mamindlapalli 	DECLARE_BITMAP(qos_sq_bmap, OTX2_QOS_MAX_LEAF_NODES);
475e6808b4SNaveen Mamindlapalli 	u16 maj_id;
485e6808b4SNaveen Mamindlapalli 	u16 defcls;
495e6808b4SNaveen Mamindlapalli 	u8  link_cfg_lvl; /* LINKX_CFG CSRs mapped to TL3 or TL2's index ? */
50ab6dddd2SSubbaraya Sundeep };
51ab6dddd2SSubbaraya Sundeep 
525e6808b4SNaveen Mamindlapalli struct otx2_qos_node {
535e6808b4SNaveen Mamindlapalli 	struct list_head list; /* list management */
545e6808b4SNaveen Mamindlapalli 	struct list_head child_list;
555e6808b4SNaveen Mamindlapalli 	struct list_head child_schq_list;
565e6808b4SNaveen Mamindlapalli 	struct hlist_node hlist;
575e6808b4SNaveen Mamindlapalli 	DECLARE_BITMAP(prio_bmap, OTX2_QOS_MAX_PRIO + 1);
585e6808b4SNaveen Mamindlapalli 	struct otx2_qos_node *parent;	/* parent qos node */
595e6808b4SNaveen Mamindlapalli 	u64 rate; /* htb params */
605e6808b4SNaveen Mamindlapalli 	u64 ceil;
615e6808b4SNaveen Mamindlapalli 	u32 classid;
625e6808b4SNaveen Mamindlapalli 	u32 prio;
63*47a9656fSNaveen Mamindlapalli 	u32 quantum;
64*47a9656fSNaveen Mamindlapalli 	/* hw txschq */
65*47a9656fSNaveen Mamindlapalli 	u16 schq;
665e6808b4SNaveen Mamindlapalli 	u16 qid;
675e6808b4SNaveen Mamindlapalli 	u16 prio_anchor;
68f78dca69SNaveen Mamindlapalli 	u16 max_static_prio;
69f78dca69SNaveen Mamindlapalli 	u16 child_dwrr_cnt;
70f78dca69SNaveen Mamindlapalli 	u16 child_static_cnt;
71*47a9656fSNaveen Mamindlapalli 	u16 child_dwrr_prio;
72f78dca69SNaveen Mamindlapalli 	u16 txschq_idx;			/* txschq allocation index */
735e6808b4SNaveen Mamindlapalli 	u8 level;
74f78dca69SNaveen Mamindlapalli 	bool is_static;
755e6808b4SNaveen Mamindlapalli };
765e6808b4SNaveen Mamindlapalli 
775e6808b4SNaveen Mamindlapalli 
78ab6dddd2SSubbaraya Sundeep #endif
79