drivers/net/ethernet/mellanox/mlx5/core/en/htb.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlx5/core/en/htb.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlx5/core/en/htb.c- Extension
.c- Size
- 18956 bytes
- Lines
- 723
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
net/pkt_cls.hhtb.hen.h../qos.h
Detected Declarations
struct mlx5e_qos_nodestruct mlx5e_htbfunction mlx5e_htb_enumerate_leavesfunction hash_for_eachfunction mlx5e_htb_cur_leaf_nodesfunction mlx5e_htb_find_unused_qos_qidfunction mlx5e_htb_node_create_leaffunction hash_for_each_possiblefunction hash_for_each_possible_rcufunction mlx5e_htb_node_deletefunction mlx5e_htb_get_txq_by_classidfunction mlx5e_htb_root_addfunction mlx5e_htb_root_delfunction mlx5e_htb_convert_ratefunction mlx5e_htb_convert_ceilfunction mlx5e_htb_leaf_alloc_queuefunction mlx5e_htb_leaf_to_innerfunction mlx5e_htb_leaf_delfunction mlx5e_htb_leaf_del_lastfunction mlx5e_htb_update_childrenfunction hash_for_eachfunction mlx5e_htb_node_modifyfunction mlx5e_htb_freefunction mlx5e_htb_initfunction mlx5e_htb_cleanup
Annotated Snippet
struct mlx5e_qos_node {
struct hlist_node hnode;
struct mlx5e_qos_node *parent;
u64 rate;
u32 bw_share;
u32 max_average_bw;
u32 hw_id;
u32 classid; /* 16-bit, except root. */
u16 qid;
};
struct mlx5e_htb {
DECLARE_HASHTABLE(qos_tc2node, order_base_2(MLX5E_QOS_MAX_LEAF_NODES));
DECLARE_BITMAP(qos_used_qids, MLX5E_QOS_MAX_LEAF_NODES);
struct mlx5_core_dev *mdev;
struct net_device *netdev;
struct mlx5e_priv *priv;
struct mlx5e_selq *selq;
};
#define MLX5E_QOS_QID_INNER 0xffff
#define MLX5E_HTB_CLASSID_ROOT 0xffffffff
/* Software representation of the QoS tree */
int mlx5e_htb_enumerate_leaves(struct mlx5e_htb *htb, mlx5e_fp_htb_enumerate callback, void *data)
{
struct mlx5e_qos_node *node = NULL;
int bkt, err;
hash_for_each(htb->qos_tc2node, bkt, node, hnode) {
if (node->qid == MLX5E_QOS_QID_INNER)
continue;
err = callback(data, node->qid, node->hw_id);
if (err)
return err;
}
return 0;
}
int mlx5e_htb_cur_leaf_nodes(struct mlx5e_htb *htb)
{
int last;
last = find_last_bit(htb->qos_used_qids, mlx5e_qos_max_leaf_nodes(htb->mdev));
return last == mlx5e_qos_max_leaf_nodes(htb->mdev) ? 0 : last + 1;
}
static int mlx5e_htb_find_unused_qos_qid(struct mlx5e_htb *htb)
{
int size = mlx5e_qos_max_leaf_nodes(htb->mdev);
struct mlx5e_priv *priv = htb->priv;
int res;
WARN_ONCE(!mutex_is_locked(&priv->state_lock), "%s: state_lock is not held\n", __func__);
res = find_first_zero_bit(htb->qos_used_qids, size);
return res == size ? -ENOSPC : res;
}
static struct mlx5e_qos_node *
mlx5e_htb_node_create_leaf(struct mlx5e_htb *htb, u16 classid, u16 qid,
struct mlx5e_qos_node *parent)
{
struct mlx5e_qos_node *node;
node = kzalloc_obj(*node);
if (!node)
return ERR_PTR(-ENOMEM);
node->parent = parent;
node->qid = qid;
__set_bit(qid, htb->qos_used_qids);
node->classid = classid;
hash_add_rcu(htb->qos_tc2node, &node->hnode, classid);
mlx5e_update_tx_netdev_queues(htb->priv);
return node;
}
static struct mlx5e_qos_node *mlx5e_htb_node_create_root(struct mlx5e_htb *htb)
{
struct mlx5e_qos_node *node;
node = kzalloc_obj(*node);
if (!node)
return ERR_PTR(-ENOMEM);
Annotation
- Immediate include surface: `net/pkt_cls.h`, `htb.h`, `en.h`, `../qos.h`.
- Detected declarations: `struct mlx5e_qos_node`, `struct mlx5e_htb`, `function mlx5e_htb_enumerate_leaves`, `function hash_for_each`, `function mlx5e_htb_cur_leaf_nodes`, `function mlx5e_htb_find_unused_qos_qid`, `function mlx5e_htb_node_create_leaf`, `function hash_for_each_possible`, `function hash_for_each_possible_rcu`, `function mlx5e_htb_node_delete`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.