@@ -95,6 +95,7 @@ static void set_frmr_seg(struct hns_roce_v2_rc_send_wqe *rc_sq_wqe,
95
95
{
96
96
struct hns_roce_mr * mr = to_hr_mr (wr -> mr );
97
97
struct hns_roce_wqe_frmr_seg * fseg = wqe ;
98
+ u64 pbl_ba ;
98
99
99
100
/* use ib_access_flags */
100
101
roce_set_bit (rc_sq_wqe -> byte_4 , V2_RC_FRMR_WQE_BYTE_4_BIND_EN_S ,
@@ -109,19 +110,20 @@ static void set_frmr_seg(struct hns_roce_v2_rc_send_wqe *rc_sq_wqe,
109
110
wr -> access & IB_ACCESS_LOCAL_WRITE ? 1 : 0 );
110
111
111
112
/* Data structure reuse may lead to confusion */
112
- rc_sq_wqe -> msg_len = cpu_to_le32 (mr -> pbl_ba & 0xffffffff );
113
- rc_sq_wqe -> inv_key = cpu_to_le32 (mr -> pbl_ba >> 32 );
113
+ pbl_ba = mr -> pbl_mtr .hem_cfg .root_ba ;
114
+ rc_sq_wqe -> msg_len = cpu_to_le32 (lower_32_bits (pbl_ba ));
115
+ rc_sq_wqe -> inv_key = cpu_to_le32 (upper_32_bits (pbl_ba ));
114
116
115
117
rc_sq_wqe -> byte_16 = cpu_to_le32 (wr -> mr -> length & 0xffffffff );
116
118
rc_sq_wqe -> byte_20 = cpu_to_le32 (wr -> mr -> length >> 32 );
117
119
rc_sq_wqe -> rkey = cpu_to_le32 (wr -> key );
118
120
rc_sq_wqe -> va = cpu_to_le64 (wr -> mr -> iova );
119
121
120
- fseg -> pbl_size = cpu_to_le32 (mr -> pbl_size );
122
+ fseg -> pbl_size = cpu_to_le32 (mr -> npages );
121
123
roce_set_field (fseg -> mode_buf_pg_sz ,
122
124
V2_RC_FRMR_WQE_BYTE_40_PBL_BUF_PG_SZ_M ,
123
125
V2_RC_FRMR_WQE_BYTE_40_PBL_BUF_PG_SZ_S ,
124
- mr -> pbl_buf_pg_sz + PG_SHIFT_OFFSET );
126
+ to_hr_hw_page_shift ( mr -> pbl_mtr . hem_cfg . buf_pg_shift ) );
125
127
roce_set_bit (fseg -> mode_buf_pg_sz ,
126
128
V2_RC_FRMR_WQE_BYTE_40_BLK_MODE_S , 0 );
127
129
}
@@ -2439,32 +2441,30 @@ static int hns_roce_v2_set_mac(struct hns_roce_dev *hr_dev, u8 phy_port,
2439
2441
static int set_mtpt_pbl (struct hns_roce_v2_mpt_entry * mpt_entry ,
2440
2442
struct hns_roce_mr * mr )
2441
2443
{
2442
- struct sg_dma_page_iter sg_iter ;
2443
- u64 page_addr ;
2444
- u64 * pages ;
2445
- int i ;
2444
+ struct hns_roce_dev * hr_dev = to_hr_dev (mr -> ibmr .device );
2445
+ u64 pages [HNS_ROCE_V2_MAX_INNER_MTPT_NUM ] = { 0 };
2446
+ struct ib_device * ibdev = & hr_dev -> ib_dev ;
2447
+ dma_addr_t pbl_ba ;
2448
+ int i , count ;
2446
2449
2447
- mpt_entry -> pbl_size = cpu_to_le32 (mr -> pbl_size );
2448
- mpt_entry -> pbl_ba_l = cpu_to_le32 (lower_32_bits (mr -> pbl_ba >> 3 ));
2449
- roce_set_field (mpt_entry -> byte_48_mode_ba ,
2450
- V2_MPT_BYTE_48_PBL_BA_H_M , V2_MPT_BYTE_48_PBL_BA_H_S ,
2451
- upper_32_bits (mr -> pbl_ba >> 3 ));
2450
+ count = hns_roce_mtr_find (hr_dev , & mr -> pbl_mtr , 0 , pages ,
2451
+ ARRAY_SIZE (pages ), & pbl_ba );
2452
+ if (count < 1 ) {
2453
+ ibdev_err (ibdev , "failed to find PBL mtr, count = %d.\n" ,
2454
+ count );
2455
+ return - ENOBUFS ;
2456
+ }
2452
2457
2453
- pages = ( u64 * ) __get_free_page ( GFP_KERNEL );
2454
- if (! pages )
2455
- return - ENOMEM ;
2458
+ /* Aligned to the hardware address access unit */
2459
+ for ( i = 0 ; i < count ; i ++ )
2460
+ pages [ i ] >>= 6 ;
2456
2461
2457
- i = 0 ;
2458
- for_each_sg_dma_page (mr -> umem -> sg_head .sgl , & sg_iter , mr -> umem -> nmap , 0 ) {
2459
- page_addr = sg_page_iter_dma_address (& sg_iter );
2460
- pages [i ] = page_addr >> 6 ;
2462
+ mpt_entry -> pbl_size = cpu_to_le32 (mr -> npages );
2463
+ mpt_entry -> pbl_ba_l = cpu_to_le32 (pbl_ba >> 3 );
2464
+ roce_set_field (mpt_entry -> byte_48_mode_ba ,
2465
+ V2_MPT_BYTE_48_PBL_BA_H_M , V2_MPT_BYTE_48_PBL_BA_H_S ,
2466
+ upper_32_bits (pbl_ba >> 3 ));
2461
2467
2462
- /* Record the first 2 entry directly to MTPT table */
2463
- if (i >= HNS_ROCE_V2_MAX_INNER_MTPT_NUM - 1 )
2464
- goto found ;
2465
- i ++ ;
2466
- }
2467
- found :
2468
2468
mpt_entry -> pa0_l = cpu_to_le32 (lower_32_bits (pages [0 ]));
2469
2469
roce_set_field (mpt_entry -> byte_56_pa0_h , V2_MPT_BYTE_56_PA0_H_M ,
2470
2470
V2_MPT_BYTE_56_PA0_H_S , upper_32_bits (pages [0 ]));
@@ -2475,9 +2475,7 @@ static int set_mtpt_pbl(struct hns_roce_v2_mpt_entry *mpt_entry,
2475
2475
roce_set_field (mpt_entry -> byte_64_buf_pa1 ,
2476
2476
V2_MPT_BYTE_64_PBL_BUF_PG_SZ_M ,
2477
2477
V2_MPT_BYTE_64_PBL_BUF_PG_SZ_S ,
2478
- mr -> pbl_buf_pg_sz + PG_SHIFT_OFFSET );
2479
-
2480
- free_page ((unsigned long )pages );
2478
+ to_hr_hw_page_shift (mr -> pbl_mtr .hem_cfg .buf_pg_shift ));
2481
2479
2482
2480
return 0 ;
2483
2481
}
@@ -2499,7 +2497,7 @@ static int hns_roce_v2_write_mtpt(void *mb_buf, struct hns_roce_mr *mr,
2499
2497
roce_set_field (mpt_entry -> byte_4_pd_hop_st ,
2500
2498
V2_MPT_BYTE_4_PBL_BA_PG_SZ_M ,
2501
2499
V2_MPT_BYTE_4_PBL_BA_PG_SZ_S ,
2502
- mr -> pbl_ba_pg_sz + PG_SHIFT_OFFSET );
2500
+ to_hr_hw_page_shift ( mr -> pbl_mtr . hem_cfg . ba_pg_shift ) );
2503
2501
roce_set_field (mpt_entry -> byte_4_pd_hop_st , V2_MPT_BYTE_4_PD_M ,
2504
2502
V2_MPT_BYTE_4_PD_S , mr -> pd );
2505
2503
@@ -2585,19 +2583,27 @@ static int hns_roce_v2_rereg_write_mtpt(struct hns_roce_dev *hr_dev,
2585
2583
2586
2584
static int hns_roce_v2_frmr_write_mtpt (void * mb_buf , struct hns_roce_mr * mr )
2587
2585
{
2586
+ struct hns_roce_dev * hr_dev = to_hr_dev (mr -> ibmr .device );
2587
+ struct ib_device * ibdev = & hr_dev -> ib_dev ;
2588
2588
struct hns_roce_v2_mpt_entry * mpt_entry ;
2589
+ dma_addr_t pbl_ba = 0 ;
2589
2590
2590
2591
mpt_entry = mb_buf ;
2591
2592
memset (mpt_entry , 0 , sizeof (* mpt_entry ));
2592
2593
2594
+ if (hns_roce_mtr_find (hr_dev , & mr -> pbl_mtr , 0 , NULL , 0 , & pbl_ba ) < 0 ) {
2595
+ ibdev_err (ibdev , "failed to find frmr mtr.\n" );
2596
+ return - ENOBUFS ;
2597
+ }
2598
+
2593
2599
roce_set_field (mpt_entry -> byte_4_pd_hop_st , V2_MPT_BYTE_4_MPT_ST_M ,
2594
2600
V2_MPT_BYTE_4_MPT_ST_S , V2_MPT_ST_FREE );
2595
2601
roce_set_field (mpt_entry -> byte_4_pd_hop_st , V2_MPT_BYTE_4_PBL_HOP_NUM_M ,
2596
2602
V2_MPT_BYTE_4_PBL_HOP_NUM_S , 1 );
2597
2603
roce_set_field (mpt_entry -> byte_4_pd_hop_st ,
2598
2604
V2_MPT_BYTE_4_PBL_BA_PG_SZ_M ,
2599
2605
V2_MPT_BYTE_4_PBL_BA_PG_SZ_S ,
2600
- mr -> pbl_ba_pg_sz + PG_SHIFT_OFFSET );
2606
+ to_hr_hw_page_shift ( mr -> pbl_mtr . hem_cfg . ba_pg_shift ) );
2601
2607
roce_set_field (mpt_entry -> byte_4_pd_hop_st , V2_MPT_BYTE_4_PD_M ,
2602
2608
V2_MPT_BYTE_4_PD_S , mr -> pd );
2603
2609
@@ -2610,17 +2616,17 @@ static int hns_roce_v2_frmr_write_mtpt(void *mb_buf, struct hns_roce_mr *mr)
2610
2616
roce_set_bit (mpt_entry -> byte_12_mw_pa , V2_MPT_BYTE_12_MR_MW_S , 0 );
2611
2617
roce_set_bit (mpt_entry -> byte_12_mw_pa , V2_MPT_BYTE_12_BPD_S , 1 );
2612
2618
2613
- mpt_entry -> pbl_size = cpu_to_le32 (mr -> pbl_size );
2619
+ mpt_entry -> pbl_size = cpu_to_le32 (mr -> npages );
2614
2620
2615
- mpt_entry -> pbl_ba_l = cpu_to_le32 (lower_32_bits (mr -> pbl_ba >> 3 ));
2621
+ mpt_entry -> pbl_ba_l = cpu_to_le32 (lower_32_bits (pbl_ba >> 3 ));
2616
2622
roce_set_field (mpt_entry -> byte_48_mode_ba , V2_MPT_BYTE_48_PBL_BA_H_M ,
2617
2623
V2_MPT_BYTE_48_PBL_BA_H_S ,
2618
- upper_32_bits (mr -> pbl_ba >> 3 ));
2624
+ upper_32_bits (pbl_ba >> 3 ));
2619
2625
2620
2626
roce_set_field (mpt_entry -> byte_64_buf_pa1 ,
2621
2627
V2_MPT_BYTE_64_PBL_BUF_PG_SZ_M ,
2622
2628
V2_MPT_BYTE_64_PBL_BUF_PG_SZ_S ,
2623
- mr -> pbl_buf_pg_sz + PG_SHIFT_OFFSET );
2629
+ to_hr_hw_page_shift ( mr -> pbl_mtr . hem_cfg . buf_pg_shift ) );
2624
2630
2625
2631
return 0 ;
2626
2632
}
0 commit comments