@@ -309,9 +309,6 @@ static void mana_hwc_comp_event(void *ctx, struct gdma_queue *q_self)
309
309
310
310
static void mana_hwc_destroy_cq (struct gdma_context * gc , struct hwc_cq * hwc_cq )
311
311
{
312
- if (!hwc_cq )
313
- return ;
314
-
315
312
kfree (hwc_cq -> comp_buf );
316
313
317
314
if (hwc_cq -> gdma_cq )
@@ -446,9 +443,6 @@ static void mana_hwc_dealloc_dma_buf(struct hw_channel_context *hwc,
446
443
static void mana_hwc_destroy_wq (struct hw_channel_context * hwc ,
447
444
struct hwc_wq * hwc_wq )
448
445
{
449
- if (!hwc_wq )
450
- return ;
451
-
452
446
mana_hwc_dealloc_dma_buf (hwc , hwc_wq -> msg_buf );
453
447
454
448
if (hwc_wq -> gdma_wq )
@@ -621,6 +615,7 @@ static int mana_hwc_establish_channel(struct gdma_context *gc, u16 *q_depth,
621
615
* max_req_msg_size = hwc -> hwc_init_max_req_msg_size ;
622
616
* max_resp_msg_size = hwc -> hwc_init_max_resp_msg_size ;
623
617
618
+ /* Both were set in mana_hwc_init_event_handler(). */
624
619
if (WARN_ON (cq -> id >= gc -> max_num_cqs ))
625
620
return - EPROTO ;
626
621
@@ -636,9 +631,6 @@ static int mana_hwc_establish_channel(struct gdma_context *gc, u16 *q_depth,
636
631
static int mana_hwc_init_queues (struct hw_channel_context * hwc , u16 q_depth ,
637
632
u32 max_req_msg_size , u32 max_resp_msg_size )
638
633
{
639
- struct hwc_wq * hwc_rxq = NULL ;
640
- struct hwc_wq * hwc_txq = NULL ;
641
- struct hwc_cq * hwc_cq = NULL ;
642
634
int err ;
643
635
644
636
err = mana_hwc_init_inflight_msg (hwc , q_depth );
@@ -651,44 +643,32 @@ static int mana_hwc_init_queues(struct hw_channel_context *hwc, u16 q_depth,
651
643
err = mana_hwc_create_cq (hwc , q_depth * 2 ,
652
644
mana_hwc_init_event_handler , hwc ,
653
645
mana_hwc_rx_event_handler , hwc ,
654
- mana_hwc_tx_event_handler , hwc , & hwc_cq );
646
+ mana_hwc_tx_event_handler , hwc , & hwc -> cq );
655
647
if (err ) {
656
648
dev_err (hwc -> dev , "Failed to create HWC CQ: %d\n" , err );
657
649
goto out ;
658
650
}
659
- hwc -> cq = hwc_cq ;
660
651
661
652
err = mana_hwc_create_wq (hwc , GDMA_RQ , q_depth , max_req_msg_size ,
662
- hwc_cq , & hwc_rxq );
653
+ hwc -> cq , & hwc -> rxq );
663
654
if (err ) {
664
655
dev_err (hwc -> dev , "Failed to create HWC RQ: %d\n" , err );
665
656
goto out ;
666
657
}
667
- hwc -> rxq = hwc_rxq ;
668
658
669
659
err = mana_hwc_create_wq (hwc , GDMA_SQ , q_depth , max_resp_msg_size ,
670
- hwc_cq , & hwc_txq );
660
+ hwc -> cq , & hwc -> txq );
671
661
if (err ) {
672
662
dev_err (hwc -> dev , "Failed to create HWC SQ: %d\n" , err );
673
663
goto out ;
674
664
}
675
- hwc -> txq = hwc_txq ;
676
665
677
666
hwc -> num_inflight_msg = q_depth ;
678
667
hwc -> max_req_msg_size = max_req_msg_size ;
679
668
680
669
return 0 ;
681
670
out :
682
- if (hwc_txq )
683
- mana_hwc_destroy_wq (hwc , hwc_txq );
684
-
685
- if (hwc_rxq )
686
- mana_hwc_destroy_wq (hwc , hwc_rxq );
687
-
688
- if (hwc_cq )
689
- mana_hwc_destroy_cq (hwc -> gdma_dev -> gdma_context , hwc_cq );
690
-
691
- mana_gd_free_res_map (& hwc -> inflight_msg_res );
671
+ /* mana_hwc_create_channel() will do the cleanup.*/
692
672
return err ;
693
673
}
694
674
@@ -716,6 +696,9 @@ int mana_hwc_create_channel(struct gdma_context *gc)
716
696
gd -> pdid = INVALID_PDID ;
717
697
gd -> doorbell = INVALID_DOORBELL ;
718
698
699
+ /* mana_hwc_init_queues() only creates the required data structures,
700
+ * and doesn't touch the HWC device.
701
+ */
719
702
err = mana_hwc_init_queues (hwc , HW_CHANNEL_VF_BOOTSTRAP_QUEUE_DEPTH ,
720
703
HW_CHANNEL_MAX_REQUEST_SIZE ,
721
704
HW_CHANNEL_MAX_RESPONSE_SIZE );
@@ -741,42 +724,50 @@ int mana_hwc_create_channel(struct gdma_context *gc)
741
724
742
725
return 0 ;
743
726
out :
744
- kfree ( hwc );
727
+ mana_hwc_destroy_channel ( gc );
745
728
return err ;
746
729
}
747
730
748
731
void mana_hwc_destroy_channel (struct gdma_context * gc )
749
732
{
750
733
struct hw_channel_context * hwc = gc -> hwc .driver_data ;
751
- struct hwc_caller_ctx * ctx ;
752
734
753
- mana_smc_teardown_hwc (& gc -> shm_channel , false);
735
+ if (!hwc )
736
+ return ;
737
+
738
+ /* gc->max_num_cqs is set in mana_hwc_init_event_handler(). If it's
739
+ * non-zero, the HWC worked and we should tear down the HWC here.
740
+ */
741
+ if (gc -> max_num_cqs > 0 ) {
742
+ mana_smc_teardown_hwc (& gc -> shm_channel , false);
743
+ gc -> max_num_cqs = 0 ;
744
+ }
754
745
755
- ctx = hwc -> caller_ctx ;
756
- kfree (ctx );
746
+ kfree (hwc -> caller_ctx );
757
747
hwc -> caller_ctx = NULL ;
758
748
759
- mana_hwc_destroy_wq (hwc , hwc -> txq );
760
- hwc -> txq = NULL ;
749
+ if (hwc -> txq )
750
+ mana_hwc_destroy_wq ( hwc , hwc -> txq ) ;
761
751
762
- mana_hwc_destroy_wq (hwc , hwc -> rxq );
763
- hwc -> rxq = NULL ;
752
+ if (hwc -> rxq )
753
+ mana_hwc_destroy_wq ( hwc , hwc -> rxq ) ;
764
754
765
- mana_hwc_destroy_cq (hwc -> gdma_dev -> gdma_context , hwc -> cq );
766
- hwc -> cq = NULL ;
755
+ if (hwc -> cq )
756
+ mana_hwc_destroy_cq ( hwc -> gdma_dev -> gdma_context , hwc -> cq ) ;
767
757
768
758
mana_gd_free_res_map (& hwc -> inflight_msg_res );
769
759
770
760
hwc -> num_inflight_msg = 0 ;
771
761
772
- if (hwc -> gdma_dev -> pdid != INVALID_PDID ) {
773
- hwc -> gdma_dev -> doorbell = INVALID_DOORBELL ;
774
- hwc -> gdma_dev -> pdid = INVALID_PDID ;
775
- }
762
+ hwc -> gdma_dev -> doorbell = INVALID_DOORBELL ;
763
+ hwc -> gdma_dev -> pdid = INVALID_PDID ;
776
764
777
765
kfree (hwc );
778
766
gc -> hwc .driver_data = NULL ;
779
767
gc -> hwc .gdma_context = NULL ;
768
+
769
+ vfree (gc -> cq_table );
770
+ gc -> cq_table = NULL ;
780
771
}
781
772
782
773
int mana_hwc_send_request (struct hw_channel_context * hwc , u32 req_len ,
0 commit comments