@@ -158,7 +158,7 @@ static bool is_index_valid(struct mlx5_vdpa_dev *mvdev, u16 idx)
158
158
159
159
static void free_fixed_resources (struct mlx5_vdpa_net * ndev );
160
160
static void mvqs_set_defaults (struct mlx5_vdpa_net * ndev );
161
- static int setup_vq_resources (struct mlx5_vdpa_net * ndev );
161
+ static int setup_vq_resources (struct mlx5_vdpa_net * ndev , bool filled );
162
162
static void teardown_vq_resources (struct mlx5_vdpa_net * ndev );
163
163
164
164
static bool mlx5_vdpa_debug ;
@@ -874,13 +874,16 @@ static bool msix_mode_supported(struct mlx5_vdpa_dev *mvdev)
874
874
pci_msix_can_alloc_dyn (mvdev -> mdev -> pdev );
875
875
}
876
876
877
- static int create_virtqueue (struct mlx5_vdpa_net * ndev , struct mlx5_vdpa_virtqueue * mvq )
877
+ static int create_virtqueue (struct mlx5_vdpa_net * ndev ,
878
+ struct mlx5_vdpa_virtqueue * mvq ,
879
+ bool filled )
878
880
{
879
881
int inlen = MLX5_ST_SZ_BYTES (create_virtio_net_q_in );
880
882
u32 out [MLX5_ST_SZ_DW (create_virtio_net_q_out )] = {};
881
883
struct mlx5_vdpa_dev * mvdev = & ndev -> mvdev ;
882
884
struct mlx5_vdpa_mr * vq_mr ;
883
885
struct mlx5_vdpa_mr * vq_desc_mr ;
886
+ u64 features = filled ? mvdev -> actual_features : mvdev -> mlx_features ;
884
887
void * obj_context ;
885
888
u16 mlx_features ;
886
889
void * cmd_hdr ;
@@ -898,16 +901,14 @@ static int create_virtqueue(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtque
898
901
goto err_alloc ;
899
902
}
900
903
901
- mlx_features = get_features (ndev -> mvdev . actual_features );
904
+ mlx_features = get_features (features );
902
905
cmd_hdr = MLX5_ADDR_OF (create_virtio_net_q_in , in , general_obj_in_cmd_hdr );
903
906
904
907
MLX5_SET (general_obj_in_cmd_hdr , cmd_hdr , opcode , MLX5_CMD_OP_CREATE_GENERAL_OBJECT );
905
908
MLX5_SET (general_obj_in_cmd_hdr , cmd_hdr , obj_type , MLX5_OBJ_TYPE_VIRTIO_NET_Q );
906
909
MLX5_SET (general_obj_in_cmd_hdr , cmd_hdr , uid , ndev -> mvdev .res .uid );
907
910
908
911
obj_context = MLX5_ADDR_OF (create_virtio_net_q_in , in , obj_context );
909
- MLX5_SET (virtio_net_q_object , obj_context , hw_available_index , mvq -> avail_idx );
910
- MLX5_SET (virtio_net_q_object , obj_context , hw_used_index , mvq -> used_idx );
911
912
MLX5_SET (virtio_net_q_object , obj_context , queue_feature_bit_mask_12_3 ,
912
913
mlx_features >> 3 );
913
914
MLX5_SET (virtio_net_q_object , obj_context , queue_feature_bit_mask_2_0 ,
@@ -929,17 +930,36 @@ static int create_virtqueue(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtque
929
930
MLX5_SET (virtio_q , vq_ctx , queue_index , mvq -> index );
930
931
MLX5_SET (virtio_q , vq_ctx , queue_size , mvq -> num_ent );
931
932
MLX5_SET (virtio_q , vq_ctx , virtio_version_1_0 ,
932
- !!(ndev -> mvdev .actual_features & BIT_ULL (VIRTIO_F_VERSION_1 )));
933
- MLX5_SET64 (virtio_q , vq_ctx , desc_addr , mvq -> desc_addr );
934
- MLX5_SET64 (virtio_q , vq_ctx , used_addr , mvq -> device_addr );
935
- MLX5_SET64 (virtio_q , vq_ctx , available_addr , mvq -> driver_addr );
936
- vq_mr = mvdev -> mr [mvdev -> group2asid [MLX5_VDPA_DATAVQ_GROUP ]];
937
- if (vq_mr )
938
- MLX5_SET (virtio_q , vq_ctx , virtio_q_mkey , vq_mr -> mkey );
939
-
940
- vq_desc_mr = mvdev -> mr [mvdev -> group2asid [MLX5_VDPA_DATAVQ_DESC_GROUP ]];
941
- if (vq_desc_mr && MLX5_CAP_DEV_VDPA_EMULATION (mvdev -> mdev , desc_group_mkey_supported ))
942
- MLX5_SET (virtio_q , vq_ctx , desc_group_mkey , vq_desc_mr -> mkey );
933
+ !!(features & BIT_ULL (VIRTIO_F_VERSION_1 )));
934
+
935
+ if (filled ) {
936
+ MLX5_SET (virtio_net_q_object , obj_context , hw_available_index , mvq -> avail_idx );
937
+ MLX5_SET (virtio_net_q_object , obj_context , hw_used_index , mvq -> used_idx );
938
+
939
+ MLX5_SET64 (virtio_q , vq_ctx , desc_addr , mvq -> desc_addr );
940
+ MLX5_SET64 (virtio_q , vq_ctx , used_addr , mvq -> device_addr );
941
+ MLX5_SET64 (virtio_q , vq_ctx , available_addr , mvq -> driver_addr );
942
+
943
+ vq_mr = mvdev -> mr [mvdev -> group2asid [MLX5_VDPA_DATAVQ_GROUP ]];
944
+ if (vq_mr )
945
+ MLX5_SET (virtio_q , vq_ctx , virtio_q_mkey , vq_mr -> mkey );
946
+
947
+ vq_desc_mr = mvdev -> mr [mvdev -> group2asid [MLX5_VDPA_DATAVQ_DESC_GROUP ]];
948
+ if (vq_desc_mr &&
949
+ MLX5_CAP_DEV_VDPA_EMULATION (mvdev -> mdev , desc_group_mkey_supported ))
950
+ MLX5_SET (virtio_q , vq_ctx , desc_group_mkey , vq_desc_mr -> mkey );
951
+ } else {
952
+ /* If there is no mr update, make sure that the existing ones are set
953
+ * modify to ready.
954
+ */
955
+ vq_mr = mvdev -> mr [mvdev -> group2asid [MLX5_VDPA_DATAVQ_GROUP ]];
956
+ if (vq_mr )
957
+ mvq -> modified_fields |= MLX5_VIRTQ_MODIFY_MASK_VIRTIO_Q_MKEY ;
958
+
959
+ vq_desc_mr = mvdev -> mr [mvdev -> group2asid [MLX5_VDPA_DATAVQ_DESC_GROUP ]];
960
+ if (vq_desc_mr )
961
+ mvq -> modified_fields |= MLX5_VIRTQ_MODIFY_MASK_DESC_GROUP_MKEY ;
962
+ }
943
963
944
964
MLX5_SET (virtio_q , vq_ctx , umem_1_id , mvq -> umem1 .id );
945
965
MLX5_SET (virtio_q , vq_ctx , umem_1_size , mvq -> umem1 .size );
@@ -959,12 +979,15 @@ static int create_virtqueue(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtque
959
979
kfree (in );
960
980
mvq -> virtq_id = MLX5_GET (general_obj_out_cmd_hdr , out , obj_id );
961
981
962
- mlx5_vdpa_get_mr (mvdev , vq_mr );
963
- mvq -> vq_mr = vq_mr ;
982
+ if (filled ) {
983
+ mlx5_vdpa_get_mr (mvdev , vq_mr );
984
+ mvq -> vq_mr = vq_mr ;
964
985
965
- if (vq_desc_mr && MLX5_CAP_DEV_VDPA_EMULATION (mvdev -> mdev , desc_group_mkey_supported )) {
966
- mlx5_vdpa_get_mr (mvdev , vq_desc_mr );
967
- mvq -> desc_mr = vq_desc_mr ;
986
+ if (vq_desc_mr &&
987
+ MLX5_CAP_DEV_VDPA_EMULATION (mvdev -> mdev , desc_group_mkey_supported )) {
988
+ mlx5_vdpa_get_mr (mvdev , vq_desc_mr );
989
+ mvq -> desc_mr = vq_desc_mr ;
990
+ }
968
991
}
969
992
970
993
return 0 ;
@@ -1442,7 +1465,9 @@ static void dealloc_vector(struct mlx5_vdpa_net *ndev,
1442
1465
}
1443
1466
}
1444
1467
1445
- static int setup_vq (struct mlx5_vdpa_net * ndev , struct mlx5_vdpa_virtqueue * mvq )
1468
+ static int setup_vq (struct mlx5_vdpa_net * ndev ,
1469
+ struct mlx5_vdpa_virtqueue * mvq ,
1470
+ bool filled )
1446
1471
{
1447
1472
u16 idx = mvq -> index ;
1448
1473
int err ;
@@ -1471,7 +1496,7 @@ static int setup_vq(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq)
1471
1496
goto err_connect ;
1472
1497
1473
1498
alloc_vector (ndev , mvq );
1474
- err = create_virtqueue (ndev , mvq );
1499
+ err = create_virtqueue (ndev , mvq , filled );
1475
1500
if (err )
1476
1501
goto err_vq ;
1477
1502
@@ -2062,7 +2087,7 @@ static int change_num_qps(struct mlx5_vdpa_dev *mvdev, int newqps)
2062
2087
} else {
2063
2088
ndev -> cur_num_vqs = 2 * newqps ;
2064
2089
for (i = cur_qps * 2 ; i < 2 * newqps ; i ++ ) {
2065
- err = setup_vq (ndev , & ndev -> vqs [i ]);
2090
+ err = setup_vq (ndev , & ndev -> vqs [i ], true );
2066
2091
if (err )
2067
2092
goto clean_added ;
2068
2093
}
@@ -2558,14 +2583,14 @@ static int verify_driver_features(struct mlx5_vdpa_dev *mvdev, u64 features)
2558
2583
return 0 ;
2559
2584
}
2560
2585
2561
- static int setup_virtqueues (struct mlx5_vdpa_dev * mvdev )
2586
+ static int setup_virtqueues (struct mlx5_vdpa_dev * mvdev , bool filled )
2562
2587
{
2563
2588
struct mlx5_vdpa_net * ndev = to_mlx5_vdpa_ndev (mvdev );
2564
2589
int err ;
2565
2590
int i ;
2566
2591
2567
2592
for (i = 0 ; i < mvdev -> max_vqs ; i ++ ) {
2568
- err = setup_vq (ndev , & ndev -> vqs [i ]);
2593
+ err = setup_vq (ndev , & ndev -> vqs [i ], filled );
2569
2594
if (err )
2570
2595
goto err_vq ;
2571
2596
}
@@ -2877,7 +2902,7 @@ static int mlx5_vdpa_change_map(struct mlx5_vdpa_dev *mvdev,
2877
2902
2878
2903
if (teardown ) {
2879
2904
restore_channels_info (ndev );
2880
- err = setup_vq_resources (ndev );
2905
+ err = setup_vq_resources (ndev , true );
2881
2906
if (err )
2882
2907
return err ;
2883
2908
}
@@ -2888,7 +2913,7 @@ static int mlx5_vdpa_change_map(struct mlx5_vdpa_dev *mvdev,
2888
2913
}
2889
2914
2890
2915
/* reslock must be held for this function */
2891
- static int setup_vq_resources (struct mlx5_vdpa_net * ndev )
2916
+ static int setup_vq_resources (struct mlx5_vdpa_net * ndev , bool filled )
2892
2917
{
2893
2918
struct mlx5_vdpa_dev * mvdev = & ndev -> mvdev ;
2894
2919
int err ;
@@ -2906,7 +2931,7 @@ static int setup_vq_resources(struct mlx5_vdpa_net *ndev)
2906
2931
if (err )
2907
2932
goto err_setup ;
2908
2933
2909
- err = setup_virtqueues (mvdev );
2934
+ err = setup_virtqueues (mvdev , filled );
2910
2935
if (err ) {
2911
2936
mlx5_vdpa_warn (mvdev , "setup_virtqueues\n" );
2912
2937
goto err_setup ;
@@ -3000,7 +3025,7 @@ static void mlx5_vdpa_set_status(struct vdpa_device *vdev, u8 status)
3000
3025
goto err_setup ;
3001
3026
}
3002
3027
register_link_notifier (ndev );
3003
- err = setup_vq_resources (ndev );
3028
+ err = setup_vq_resources (ndev , true );
3004
3029
if (err ) {
3005
3030
mlx5_vdpa_warn (mvdev , "failed to setup driver\n" );
3006
3031
goto err_driver ;
0 commit comments