@@ -486,6 +486,111 @@ static void recv_mbox_handler(struct hinic_mbox_func_to_func *func_to_func,
486
486
kfree (rcv_mbox_temp );
487
487
}
488
488
489
+ static int set_vf_mbox_random_id (struct hinic_hwdev * hwdev , u16 func_id )
490
+ {
491
+ struct hinic_mbox_func_to_func * func_to_func = hwdev -> func_to_func ;
492
+ struct hinic_set_random_id rand_info = {0 };
493
+ u16 out_size = sizeof (rand_info );
494
+ struct hinic_pfhwdev * pfhwdev ;
495
+ int ret ;
496
+
497
+ pfhwdev = container_of (hwdev , struct hinic_pfhwdev , hwdev );
498
+
499
+ rand_info .version = HINIC_CMD_VER_FUNC_ID ;
500
+ rand_info .func_idx = func_id ;
501
+ rand_info .vf_in_pf = func_id - hinic_glb_pf_vf_offset (hwdev -> hwif );
502
+ rand_info .random_id = get_random_u32 ();
503
+
504
+ func_to_func -> vf_mbx_rand_id [func_id ] = rand_info .random_id ;
505
+
506
+ ret = hinic_msg_to_mgmt (& pfhwdev -> pf_to_mgmt , HINIC_MOD_COMM ,
507
+ HINIC_MGMT_CMD_SET_VF_RANDOM_ID ,
508
+ & rand_info , sizeof (rand_info ),
509
+ & rand_info , & out_size , HINIC_MGMT_MSG_SYNC );
510
+ if ((rand_info .status != HINIC_MGMT_CMD_UNSUPPORTED &&
511
+ rand_info .status ) || !out_size || ret ) {
512
+ dev_err (& hwdev -> hwif -> pdev -> dev , "Set VF random id failed, err: %d, status: 0x%x, out size: 0x%x\n" ,
513
+ ret , rand_info .status , out_size );
514
+ return - EIO ;
515
+ }
516
+
517
+ if (rand_info .status == HINIC_MGMT_CMD_UNSUPPORTED )
518
+ return rand_info .status ;
519
+
520
+ func_to_func -> vf_mbx_old_rand_id [func_id ] =
521
+ func_to_func -> vf_mbx_rand_id [func_id ];
522
+
523
+ return 0 ;
524
+ }
525
+
526
+ static void update_random_id_work_handler (struct work_struct * work )
527
+ {
528
+ struct hinic_mbox_work * mbox_work =
529
+ container_of (work , struct hinic_mbox_work , work );
530
+ struct hinic_mbox_func_to_func * func_to_func ;
531
+ u16 src = mbox_work -> src_func_idx ;
532
+
533
+ func_to_func = mbox_work -> func_to_func ;
534
+
535
+ if (set_vf_mbox_random_id (func_to_func -> hwdev , src ))
536
+ dev_warn (& func_to_func -> hwdev -> hwif -> pdev -> dev , "Update VF id: 0x%x random id failed\n" ,
537
+ mbox_work -> src_func_idx );
538
+
539
+ kfree (mbox_work );
540
+ }
541
+
542
+ static bool check_vf_mbox_random_id (struct hinic_mbox_func_to_func * func_to_func ,
543
+ u8 * header )
544
+ {
545
+ struct hinic_hwdev * hwdev = func_to_func -> hwdev ;
546
+ struct hinic_mbox_work * mbox_work = NULL ;
547
+ u64 mbox_header = * ((u64 * )header );
548
+ u16 offset , src ;
549
+ u32 random_id ;
550
+ int vf_in_pf ;
551
+
552
+ src = HINIC_MBOX_HEADER_GET (mbox_header , SRC_GLB_FUNC_IDX );
553
+
554
+ if (IS_PF_OR_PPF_SRC (src ) || !func_to_func -> support_vf_random )
555
+ return true;
556
+
557
+ if (!HINIC_IS_PPF (hwdev -> hwif )) {
558
+ offset = hinic_glb_pf_vf_offset (hwdev -> hwif );
559
+ vf_in_pf = src - offset ;
560
+
561
+ if (vf_in_pf < 1 || vf_in_pf > hwdev -> nic_cap .max_vf ) {
562
+ dev_warn (& hwdev -> hwif -> pdev -> dev ,
563
+ "Receive vf id(0x%x) is invalid, vf id should be from 0x%x to 0x%x\n" ,
564
+ src , offset + 1 ,
565
+ hwdev -> nic_cap .max_vf + offset );
566
+ return false;
567
+ }
568
+ }
569
+
570
+ random_id = be32_to_cpu (* (u32 * )(header + MBOX_SEG_LEN +
571
+ MBOX_HEADER_SZ ));
572
+
573
+ if (random_id == func_to_func -> vf_mbx_rand_id [src ] ||
574
+ random_id == func_to_func -> vf_mbx_old_rand_id [src ])
575
+ return true;
576
+
577
+ dev_warn (& hwdev -> hwif -> pdev -> dev ,
578
+ "The mailbox random id(0x%x) of func_id(0x%x) doesn't match with pf reservation(0x%x)\n" ,
579
+ random_id , src , func_to_func -> vf_mbx_rand_id [src ]);
580
+
581
+ mbox_work = kzalloc (sizeof (* mbox_work ), GFP_KERNEL );
582
+ if (!mbox_work )
583
+ return false;
584
+
585
+ mbox_work -> func_to_func = func_to_func ;
586
+ mbox_work -> src_func_idx = src ;
587
+
588
+ INIT_WORK (& mbox_work -> work , update_random_id_work_handler );
589
+ queue_work (func_to_func -> workq , & mbox_work -> work );
590
+
591
+ return false;
592
+ }
593
+
489
594
void hinic_mbox_func_aeqe_handler (void * handle , void * header , u8 size )
490
595
{
491
596
struct hinic_mbox_func_to_func * func_to_func ;
@@ -504,6 +609,9 @@ void hinic_mbox_func_aeqe_handler(void *handle, void *header, u8 size)
504
609
return ;
505
610
}
506
611
612
+ if (!check_vf_mbox_random_id (func_to_func , header ))
613
+ return ;
614
+
507
615
recv_mbox = (dir == HINIC_HWIF_DIRECT_SEND ) ?
508
616
& func_to_func -> mbox_send [src ] :
509
617
& func_to_func -> mbox_resp [src ];
@@ -1210,3 +1318,32 @@ void hinic_func_to_func_free(struct hinic_hwdev *hwdev)
1210
1318
1211
1319
kfree (func_to_func );
1212
1320
}
1321
+
1322
+ int hinic_vf_mbox_random_id_init (struct hinic_hwdev * hwdev )
1323
+ {
1324
+ u16 vf_offset ;
1325
+ u8 vf_in_pf ;
1326
+ int err = 0 ;
1327
+
1328
+ if (HINIC_IS_VF (hwdev -> hwif ))
1329
+ return 0 ;
1330
+
1331
+ vf_offset = hinic_glb_pf_vf_offset (hwdev -> hwif );
1332
+
1333
+ for (vf_in_pf = 1 ; vf_in_pf <= hwdev -> nic_cap .max_vf ; vf_in_pf ++ ) {
1334
+ err = set_vf_mbox_random_id (hwdev , vf_offset + vf_in_pf );
1335
+ if (err )
1336
+ break ;
1337
+ }
1338
+
1339
+ if (err == HINIC_MGMT_CMD_UNSUPPORTED ) {
1340
+ hwdev -> func_to_func -> support_vf_random = false;
1341
+ err = 0 ;
1342
+ dev_warn (& hwdev -> hwif -> pdev -> dev , "Mgmt is unsupported to set VF%d random id\n" ,
1343
+ vf_in_pf - 1 );
1344
+ } else if (!err ) {
1345
+ hwdev -> func_to_func -> support_vf_random = true;
1346
+ }
1347
+
1348
+ return err ;
1349
+ }
0 commit comments