MLX5DV_DR_ACTION_CREATE_FLOW_METER(3)
๐ MLX5DV_DR API(3) โ the mlx5 Programmer's Manual, but make it make sense ๐
okay bestie, buckle up ๐
this is the Direct Rule API (mlx5dv_dr_*) and it's a whole thing. But it's honestly iconic once you get it. Let's go.
โจ NAME โจ
Managing all the flow things:
mlx5dv_dr_domain_create,mlx5dv_dr_domain_sync,mlx5dv_dr_domain_destroy,mlx5dv_dr_domain_set_reclaim_device_memory,mlx5dv_dr_domain_allow_duplicate_rulesโ manage flow domains ๐ซถmlx5dv_dr_table_create,mlx5dv_dr_table_destroyโ manage flow tablesmlx5dv_dr_matcher_create,mlx5dv_dr_matcher_destroy,mlx5dv_dr_matcher_set_layoutโ manage flow matchersmlx5dv_dr_rule_create,mlx5dv_dr_rule_destroyโ manage flow rulesmlx5dv_dr_action_create_dropโ create drop actionmlx5dv_dr_action_create_default_missโ create default miss actionmlx5dv_dr_action_create_tagโ create tag actionsmlx5dv_dr_action_create_dest_ibv_qpโ create packet destination QP actionmlx5dv_dr_action_create_dest_tableโ create packet destination dr table actionmlx5dv_dr_action_create_dest_root_tableโ create packet destination root table actionmlx5dv_dr_action_create_dest_vportโ create packet destination vport actionmlx5dv_dr_action_create_dest_ib_portโ create packet destination IB port actionmlx5dv_dr_action_create_dest_devx_tirโ create packet destination TIR actionmlx5dv_dr_action_create_dest_arrayโ create destination array actionmlx5dv_dr_action_create_packet_reformatโ create packet reformat actionsmlx5dv_dr_action_create_modify_headerโ create modify header actionsmlx5dv_dr_action_create_flow_counterโ create devx flow counter actionsmlx5dv_dr_action_create_aso,mlx5dv_dr_action_modify_asoโ create and modify ASO actionsmlx5dv_dr_action_create_flow_meter,mlx5dv_dr_action_modify_flow_meterโ create and modify meter actionmlx5dv_dr_action_create_flow_samplerโ create flow sampler actionmlx5dv_dr_action_create_pop_vlanโ create pop vlan actionmlx5dv_dr_action_create_push_vlanโ create push vlan actionmlx5dv_dr_action_destroyโ destroy actionsmlx5dv_dr_aso_other_domain_link,mlx5dv_dr_aso_other_domain_unlinkโ link/unlink ASO devx object to work with different domains
๐ธ SYNOPSIS ๐ธ
here's the whole cast, in code form ๐
#include <infiniband/mlx5dv.h>
struct mlx5dv_dr_domain *mlx5dv_dr_domain_create(
struct ibv_context *ctx,
enum mlx5dv_dr_domain_type type);
int mlx5dv_dr_domain_sync(
struct mlx5dv_dr_domain *domain,
uint32_t flags);
int mlx5dv_dr_domain_destroy(struct mlx5dv_dr_domain *domain);
void mlx5dv_dr_domain_set_reclaim_device_memory(
struct mlx5dv_dr_domain *dmn,
bool enable);
void mlx5dv_dr_domain_allow_duplicate_rules(struct mlx5dv_dr_domain *dmn, bool allow);
struct mlx5dv_dr_table *mlx5dv_dr_table_create(
struct mlx5dv_dr_domain *domain,
uint32_t level);
int mlx5dv_dr_table_destroy(struct mlx5dv_dr_table *table);
struct mlx5dv_dr_matcher *mlx5dv_dr_matcher_create(
struct mlx5dv_dr_table *table,
uint16_t priority,
uint8_t match_criteria_enable,
struct mlx5dv_flow_match_parameters *mask);
int mlx5dv_dr_matcher_destroy(struct mlx5dv_dr_matcher *matcher);
int mlx5dv_dr_matcher_set_layout(struct mlx5dv_dr_matcher *matcher, struct mlx5dv_dr_matcher_layout *matcher_layout);
struct mlx5dv_dr_rule *mlx5dv_dr_rule_create(
struct mlx5dv_dr_matcher *matcher,
struct mlx5dv_flow_match_parameters *value,
size_t num_actions,
struct mlx5dv_dr_action *actions[]);
void mlx5dv_dr_rule_destroy(struct mlx5dv_dr_rule *rule);
struct mlx5dv_dr_action *mlx5dv_dr_action_create_drop(void);
struct mlx5dv_dr_action *mlx5dv_dr_action_create_default_miss(void);
struct mlx5dv_dr_action *mlx5dv_dr_action_create_tag(
uint32_t tag_value);
struct mlx5dv_dr_action *mlx5dv_dr_action_create_dest_ibv_qp(
struct ibv_qp *ibqp);
struct mlx5dv_dr_action *mlx5dv_dr_action_create_dest_table(
struct mlx5dv_dr_table *table);
struct mlx5dv_dr_action *mlx5dv_dr_action_create_dest_root_table(
struct mlx5dv_dr_table *table, uint16_t priority);
struct mlx5dv_dr_action *mlx5dv_dr_action_create_dest_vport(
struct mlx5dv_dr_domain *domain,
uint32_t vport);
struct mlx5dv_dr_action *mlx5dv_dr_action_create_dest_ib_port(
struct mlx5dv_dr_domain *domain,
uint32_t ib_port);
struct mlx5dv_dr_action *mlx5dv_dr_action_create_dest_devx_tir(
struct mlx5dv_devx_obj *devx_obj);
struct mlx5dv_dr_action *mlx5dv_dr_action_create_packet_reformat(
struct mlx5dv_dr_domain *domain,
uint32_t flags,
enum mlx5dv_flow_action_packet_reformat_type reformat_type,
size_t data_sz, void *data);
struct mlx5dv_dr_action *mlx5dv_dr_action_create_modify_header(
struct mlx5dv_dr_domain *domain,
uint32_t flags,
size_t actions_sz,
__be64 actions[]);
struct mlx5dv_dr_action *mlx5dv_dr_action_create_flow_counter(
struct mlx5dv_devx_obj *devx_obj,
uint32_t offset);
struct mlx5dv_dr_action *
mlx5dv_dr_action_create_aso(struct mlx5dv_dr_domain *domain,
struct mlx5dv_devx_obj *devx_obj,
uint32_t offset,
uint32_t flags,
uint8_t return_reg_c);
int mlx5dv_dr_action_modify_aso(struct mlx5dv_dr_action *action,
uint32_t offset,
uint32_t flags,
uint8_t return_reg_c);
struct mlx5dv_dr_action *
mlx5dv_dr_action_create_flow_meter(struct mlx5dv_dr_flow_meter_attr *attr);
int mlx5dv_dr_action_modify_flow_meter(struct mlx5dv_dr_action *action,
struct mlx5dv_dr_flow_meter_attr *attr,
__be64 modify_field_select);
struct mlx5dv_dr_action *
mlx5dv_dr_action_create_flow_sampler(struct mlx5dv_dr_flow_sampler_attr *attr);
struct mlx5dv_dr_action *
mlx5dv_dr_action_create_dest_array(struct mlx5dv_dr_domain *domain,
size_t num_dest,
struct mlx5dv_dr_action_dest_attr *dests[]);
struct mlx5dv_dr_action *mlx5dv_dr_action_create_pop_vlan(void);
struct mlx5dv_dr_action *mlx5dv_dr_action_create_push_vlan(
struct mlx5dv_dr_domain *dmn,
__be32 vlan_hdr)
int mlx5dv_dr_action_destroy(struct mlx5dv_dr_action *action);
int mlx5dv_dr_aso_other_domain_link(struct mlx5dv_devx_obj *devx_obj,
struct mlx5dv_dr_domain *peer_dmn,
struct mlx5dv_dr_domain *dmn,
uint32_t flags,
uint8_t return_reg_c);
int mlx5dv_dr_aso_other_domain_unlink(struct mlx5dv_devx_obj *devx_obj,
struct mlx5dv_dr_domain *dmn);
๐ฆ DESCRIPTION ๐ฆ
so the Direct Rule API (mlx5dv_dr_*) is basically giving your verbs application complete access to the device's packet steering functionality. full send. no gatekeeping. ๐
A steering flow rule is the combination of attributes with a match pattern and a list of actions. Rules can have several distinct actions โ like counting, encapsulating, decapsulating, before redirecting packets to a particular queue or port, etc. etc. โจ
And to manage the rule execution order for the packet processing matching by HW, you get multiple flow tables in an ordered chain, plus multiple flow matchers sorted by priorities. it's giving organization. ๐
๐ Domain
mlx5dv_dr_domain_create() creates a DR domain object to be used with mlx5dv_dr_table_create() and mlx5dv_dr_action_create_*().
A domain should be destroyed by calling mlx5dv_dr_domain_destroy() once all depended resources are released. (yes bestie, clean up after yourself ๐ซถ)
The device supports the following domain types:
MLX5DV_DR_DOMAIN_TYPE_NIC_RXโ manage ethernet packets received on the NIC. Packets in this domain can be dropped, dispatched to QP's, modified or redirected to additional tables inside the domain. Default behavior: drop packet.MLX5DV_DR_DOMAIN_TYPE_NIC_TXโ manage ethernet packets transmit on the NIC. Packets in this domain can be dropped, modified or redirected to additional tables inside the domain. Default behavior: forward packet to NIC vport (to eSwitch or wire).MLX5DV_DR_DOMAIN_TYPE_FDBโ manage ethernet packets in the eSwitch Forwarding Data Base for packets received from wire or from any other vport. Packets in this domain can be dropped, dispatched to vport, modified or redirected to additional tables inside the domain. Default behavior: forward packet to eSwitch manager vport.
mlx5dv_dr_domain_sync() is used in order to flush the rule submission queue. by default, rules in a domain are updated in HW asynchronously, so this is your "okay but actually did it happen yet" function ๐ญ. flags should be a set of type enum mlx5dv_dr_domain_sync_flags:
MLX5DV_DR_DOMAIN_SYNC_FLAGS_SW: block until completion of all software queued tasks.MLX5DV_DR_DOMAIN_SYNC_FLAGS_HW: clear the steering HW cache to enforce next packet hits the latest rules, in addition to the SW SYNC handling.MLX5DV_DR_DOMAIN_SYNC_FLAGS_MEM: sync device memory to free cached memory.
mlx5dv_dr_domain_set_reclaim_device_memory() is used to enable the reclaiming of device memory back to the system when not in use. by default this feature is disabled ๐.
mlx5dv_dr_domain_allow_duplicate_rules() is used to allow or prevent insertion of rules matching on same fields (duplicates) on non root tables. by default this feature is allowed โ
.
๐ง Table
mlx5dv_dr_table_create() creates a DR table in the domain, at the appropriate level, and can be used with mlx5dv_dr_matcher_create(), mlx5dv_dr_action_create_dest_table() and mlx5dv_dr_action_create_dest_root_table.
here's the key detail bestie: all packets start traversing the steering domain tree at table level zero (0). ๐ฏ then, using rule and action, packets can be redirected to other tables in the domain.
A table should be destroyed by calling mlx5dv_dr_table_destroy() once all depended resources are released.
still going, don't go anywhere โ part 2 is coming ๐
Matcher
okay so bestie, mlx5dv_dr_matcher_create() creates a matcher object in table, at sorted priority (lower value is checked first โ so lowkey the lower number gets first dibs ๐). A matcher can hold multiple rules, all with identical mask of type struct mlx5dv_flow_match_parameters โ that's the exact attributes to be compared by HW steering. The match_criteria_enable and mask are defined in a device spec format. Only the fields that were masked in the matcher should be filled by the rule in mlx5dv_dr_rule_create(). Don't be out here filling unmasked fields, that's not the vibe โจ.
A matcher should be destroyed by calling mlx5dv_dr_matcher_destroy() once all dependent resources are released.
mlx5dv_dr_matcher_set_layout() is used to set specific layout parameters of a matcher. On some conditions setting some attributes might not be supported โ in such cases ENOTSUP will be returned (so that's a hard no from the driver ๐). flags should be a set of type enum mlx5dv_dr_matcher_layout_flags:
MLX5DV_DR_MATCHER_LAYOUT_RESIZABLEโ the matcher can resize its scale and resources according to the rules that are inserted or removed. It's giving flexible queen energy ๐ .MLX5DV_DR_MATCHER_LAYOUT_NUM_RULEโ indicates a hint from the application about the number of rules the matcher is expected to handle. This allows preallocation of matcher resources for faster rule updates when using with non-resizable layout mode. Basically a heads-up so the driver can pre-game ๐ฎ.
Actions
A set of action create APIs are defined by mlx5dv_dr_action_create_*() โ the whole squad ๐ซถ. All actions are created as struct mlx5dv_dr_action. An action should be destroyed by calling mlx5dv_dr_action_destroy() once all dependent rules are destroyed.
When an action handle is reused for multiple rules, the same action will be executed. e.g.: action count will count multiple flows rules on the same HW flow counter context. action drop will drop packets of different rule from any matcher.
- Action: Drop โ
mlx5dv_dr_action_create_dropcreates a terminating action which drops packets.
๐ซ no cap: this one cannot be mixed with Destination actions.
- Action: Default miss โ
mlx5dv_dr_action_create_default_misscreates a terminating action which will execute the default behavior based on the domain type. - Action: Tag โ
mlx5dv_dr_action_create_tagcreates a non-terminating action which tags packets withtag_value. Thetag_valueis available in the CQE of the packet received. Valid only on domain typeNIC_RX. - Action: Destination โ
mlx5dv_dr_action_create_dest_ibv_qpcreates a terminating action delivering the packet to a QP, defined byibqp. Valid only on domain typeNIC_RX.mlx5dv_dr_action_create_dest_tablecreates a forwarding action to another flow table, defined bytable. The destination table must be from the same domain with a level higher than zero.mlx5dv_dr_action_create_dest_root_tablecreates a forwarding action to another priority inside a root flow table, defined bytableandpriority.mlx5dv_dr_action_create_dest_vportcreates a forwarding action to a vport on the same domain. Valid only on domain typeFDB.mlx5dv_dr_action_create_dest_ib_portcreates a forwarding action to aib_porton the same domain. The valid range of ports is based on the capabilityphys_port_cnt_exprovided byibq_query_device_exand it is possible to query the ports details usingmlx5dv_query_port. Action is supported only on domain typeFDB.mlx5dv_dr_action_create_dest_devx_tircreates a terminating action delivering the packet to a TIR, defined bydevx_obj. Valid only on domain typeNIC_RX. - Action: Array โ
mlx5dv_dr_action_create_dest_arraycreates an action which replicates a packet to multiple destinations.num_destdefines the number of replication destinations. Eachdestsdestination array entry can be of different type. Use typeMLX5DV_DR_ACTION_DESTfor direct forwarding to an action destination. Use typeMLX5DV_DR_ACTION_DEST_REFORMATwhen reformat action should be performed on the packet before it is forwarding to the destination action. - Action: Packet Reformat โ
mlx5dv_dr_action_create_packet_reformatcreate a packet reformat context and action in the domain. Thereformat_type,data_szanddataare defined in manmlx5dv_create_flow_action_packet_reformat. - Action: Modify Header โ
mlx5dv_dr_action_create_modify_headercreate a modify header context and action in the domain. Theactions_szandactionsare defined in manmlx5dv_create_flow_action_modify_header. - Action: Flow Count โ
mlx5dv_dr_action_create_flow_countercreates a flow counter action from a DEVX flow counter object, based ondevx_objand specific counter index fromoffsetin the counter bulk. - Action: ASO โ
mlx5dv_dr_action_create_asoreceives a domain pointer and creates an ASO action from the DEVX ASO object, based ondevx_obj. Useoffsetto select the specific ASO object in thedevx_objbulk. DR rules using this action can optionally update the ASO object value according toflagsto choose the specific wanted behavior of this object. After a packet hits the rule with the ASO object the value of the ASO object will be copied into the chosenreturn_reg_cwhich can be used for match in following DR rules.mlx5dv_dr_action_modify_asomodifies ASO actionactionwith new values foroffset,return_reg_candflags. Only new DR rules using this action will use the modified values. Existing DR rules do not change the HW action values stored.flagscan be set to one of the types ofmlx5dv_dr_action_aso_first_hit_flagsormlx5dv_dr_action_aso_flow_meter_flagsormlx5dv_dr_action_aso_ct_flags:MLX5DV_DR_ACTION_ASO_FIRST_HIT_FLAGS_SETโ is used to set the ASO first hit object context, else the context is only copied to thereturn_reg_c.MLX5DV_DR_ACTION_FLAGS_ASO_FLOW_METER_REDโ is used to indicate to update the initial color in ASO flow meter object value to red.MLX5DV_DR_ACTION_FLAGS_ASO_FLOW_METER_YELLOWโ is used to indicate to update the initial color in ASO flow meter object value to yellow.MLX5DV_DR_ACTION_FLAGS_ASO_FLOW_METER_GREENโ is used to indicate to update the initial color in ASO flow meter object value to green.MLX5DV_DR_ACTION_FLAGS_ASO_FLOW_METER_UNDEFINEDโ is used to indicate to update the initial color in ASO flow meter object value to undefined.MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_INITIATORโ is used to indicate the TCP connection direction the SYN packet was sent on.MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_RESPONDERโ is used to indicate the TCP connection direction the SYN-ACK packet was sent on.
- Action: Meter โ
mlx5dv_dr_action_create_flow_metercreates a meter action based on the flow meter parameters. The parameters are according to the device specification.mlx5dv_dr_action_modify_flow_metermodifies existing flow meter action based onmodify_field_select.modify_field_selectis according to the device specification. - Action: Sampler โ
mlx5dv_dr_action_create_flow_samplercreates a sampler action, allowing us to duplicate and sample a portion of traffic. Packets steered to the sampler action will be sampled with an approximate probability of1/sample_ratioprovided inattr, andsample_actionsprovided inattrwill be executed over them. All original packets will be steered todefault_next_tableinattr. A modify header formatSET_ACTIONdata can be provided inactionofattr, which can be executed on packets before going to default flow table. On some devices, this is required to set register value. - Action Flags: action flags can be set to one of the types of enum
mlx5dv_dr_action_flags:- Action: Pop Vlan โ
mlx5dv_dr_action_create_pop_vlancreates a pop vlan action which removes VLAN tags from packets layer 2. - Action: Push Vlan โ
mlx5dv_dr_action_create_push_vlancreates a push vlan action which adds VLAN tags to packets layer 2. MLX5DV_DR_ACTION_FLAGS_ROOT_LEVELโ is used to indicate the action is targeted for flow table inlevel=0(ROOT) of the specific domain.
- Action: Pop Vlan โ
Rule
mlx5dv_dr_rule_create() creates a HW steering rule entry in matcher. The value of type struct mlx5dv_flow_match_parameters holds the exact attribute values of the steering rule to be matched, in a device spec format. Only the fields that were masked in the matcher should be filled. HW will perform the set of num_actions from the action array of type struct mlx5dv_dr_action, once a packet matches the exact value of the rule (referred to as a hit).
mlx5dv_dr_rule_destroy() destroys the rule.
Other
mlx5dv_dr_aso_other_domain_link() links the ASO devx object, devx_obj to a domain dmn, this will allow creating a rule with ASO action using the given object on the linked domain dmn. peer_dmn is the domain that the ASO devx object was created on. dmn is the domain that ASO devx object will be linked to. flags choose the specific wanted behavior of this object according to the flags, same as for ASO action creation flags. regc_index โ after a packet hits the rule with the ASO object the value of the ASO object will be copied into the regc register indicated by this param, and then we can use the value for matching in the following DR rules.
mlx5dv_dr_aso_other_domain_unlink() will unlink the devx_obj from the linked dmn. dmn is the domain that ASO devx object is linked to.
RETURN VALUE
The create API calls will return a pointer to the relevant object: table, matcher, action, rule. On failure, NULL will be returned and errno will be set.
The destroy API calls will return 0 on success, or the value of errno on failure (which indicates the failure reason).
LIMITATIONS
Application can verify if a feature is supported by trial and error. No capabilities are exposed, as the combination of all the options exposed are way too large to define.
Tables are size-less by definition. They are expected to grow and shrink to accommodate for all rules, according to driver capabilities. Once reaching a limit, an error is returned.
Matchers in same priority, in the same table, will have undefined order.
A rule with identical value pattern to another rule on a given matcher are rejected.
IP version in matcher mask and rule should be equal and set to 4, 6 or 0.
SEE ALSO
mlx5dv_open_device(3), mlx5dv_create_flow_action_packet_reformat(3), mlx5dv_create_flow_action_modify_header(3).
AUTHOR
Alex Rosenbaum <alexr@mellanox.com> Alex Vesker <valex@mellanox.com>
๐ that's the whole page, bestie! source: mlx5 ยท date: 2019-03-28 ยท version: MLX5DV_DR API(3) โ no cap, periodt. ๐ซถ
๐ฆ where this page comes from
- alpine 3.24: rdma-core-doc 61.0-r0 ยท GPL-2.0-only OR BSD-2-Clause
- centos-stream 10: rdma-core-devel 62.0-3.el10 ยท GPLv2 or BSD
- centos-stream 9: rdma-core-devel 61.0-3.el9 ยท GPLv2 or BSD
- centos-stream 9: rdma-core-devel 61.0-3.el9 ยท GPLv2 or BSD
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms