@@ -516,3 +516,69 @@ void mlx5_encap_dealloc(struct mlx5_core_dev *dev, u32 encap_id)
516
516
517
517
mlx5_cmd_exec (dev , in , sizeof (in ), out , sizeof (out ));
518
518
}
519
+
520
+ int mlx5_modify_header_alloc (struct mlx5_core_dev * dev ,
521
+ u8 namespace , u8 num_actions ,
522
+ void * modify_actions , u32 * modify_header_id )
523
+ {
524
+ u32 out [MLX5_ST_SZ_DW (alloc_modify_header_context_out )];
525
+ int max_actions , actions_size , inlen , err ;
526
+ void * actions_in ;
527
+ u8 table_type ;
528
+ u32 * in ;
529
+
530
+ switch (namespace ) {
531
+ case MLX5_FLOW_NAMESPACE_FDB :
532
+ max_actions = MLX5_CAP_ESW_FLOWTABLE_FDB (dev , max_modify_header_actions );
533
+ table_type = FS_FT_FDB ;
534
+ break ;
535
+ case MLX5_FLOW_NAMESPACE_KERNEL :
536
+ max_actions = MLX5_CAP_FLOWTABLE_NIC_RX (dev , max_modify_header_actions );
537
+ table_type = FS_FT_NIC_RX ;
538
+ break ;
539
+ default :
540
+ return - EOPNOTSUPP ;
541
+ }
542
+
543
+ if (num_actions > max_actions ) {
544
+ mlx5_core_warn (dev , "too many modify header actions %d, max supported %d\n" ,
545
+ num_actions , max_actions );
546
+ return - EOPNOTSUPP ;
547
+ }
548
+
549
+ actions_size = MLX5_UN_SZ_BYTES (set_action_in_add_action_in_auto ) * num_actions ;
550
+ inlen = MLX5_ST_SZ_BYTES (alloc_modify_header_context_in ) + actions_size ;
551
+
552
+ in = kzalloc (inlen , GFP_KERNEL );
553
+ if (!in )
554
+ return - ENOMEM ;
555
+
556
+ MLX5_SET (alloc_modify_header_context_in , in , opcode ,
557
+ MLX5_CMD_OP_ALLOC_MODIFY_HEADER_CONTEXT );
558
+ MLX5_SET (alloc_modify_header_context_in , in , table_type , table_type );
559
+ MLX5_SET (alloc_modify_header_context_in , in , num_of_actions , num_actions );
560
+
561
+ actions_in = MLX5_ADDR_OF (alloc_modify_header_context_in , in , actions );
562
+ memcpy (actions_in , modify_actions , actions_size );
563
+
564
+ memset (out , 0 , sizeof (out ));
565
+ err = mlx5_cmd_exec (dev , in , inlen , out , sizeof (out ));
566
+
567
+ * modify_header_id = MLX5_GET (alloc_modify_header_context_out , out , modify_header_id );
568
+ kfree (in );
569
+ return err ;
570
+ }
571
+
572
+ void mlx5_modify_header_dealloc (struct mlx5_core_dev * dev , u32 modify_header_id )
573
+ {
574
+ u32 in [MLX5_ST_SZ_DW (dealloc_modify_header_context_in )];
575
+ u32 out [MLX5_ST_SZ_DW (dealloc_modify_header_context_out )];
576
+
577
+ memset (in , 0 , sizeof (in ));
578
+ MLX5_SET (dealloc_modify_header_context_in , in , opcode ,
579
+ MLX5_CMD_OP_DEALLOC_MODIFY_HEADER_CONTEXT );
580
+ MLX5_SET (dealloc_modify_header_context_in , in , modify_header_id ,
581
+ modify_header_id );
582
+
583
+ mlx5_cmd_exec (dev , in , sizeof (in ), out , sizeof (out ));
584
+ }
0 commit comments