@@ -70,9 +70,11 @@ static struct workqueue_struct *kpcintb_workqueue;
70
70
enum epf_ntb_bar {
71
71
BAR_CONFIG ,
72
72
BAR_DB ,
73
- BAR_MW0 ,
74
73
BAR_MW1 ,
75
74
BAR_MW2 ,
75
+ BAR_MW3 ,
76
+ BAR_MW4 ,
77
+ VNTB_BAR_NUM ,
76
78
};
77
79
78
80
/*
@@ -132,7 +134,7 @@ struct epf_ntb {
132
134
bool linkup ;
133
135
u32 spad_size ;
134
136
135
- enum pci_barno epf_ntb_bar [6 ];
137
+ enum pci_barno epf_ntb_bar [VNTB_BAR_NUM ];
136
138
137
139
struct epf_ntb_ctrl * reg ;
138
140
@@ -510,7 +512,7 @@ static int epf_ntb_db_bar_init(struct epf_ntb *ntb)
510
512
struct device * dev = & ntb -> epf -> dev ;
511
513
int ret ;
512
514
struct pci_epf_bar * epf_bar ;
513
- void __iomem * mw_addr ;
515
+ void * mw_addr ;
514
516
enum pci_barno barno ;
515
517
size_t size = sizeof (u32 ) * ntb -> db_count ;
516
518
@@ -576,7 +578,7 @@ static int epf_ntb_mw_bar_init(struct epf_ntb *ntb)
576
578
577
579
for (i = 0 ; i < ntb -> num_mws ; i ++ ) {
578
580
size = ntb -> mws_size [i ];
579
- barno = ntb -> epf_ntb_bar [BAR_MW0 + i ];
581
+ barno = ntb -> epf_ntb_bar [BAR_MW1 + i ];
580
582
581
583
ntb -> epf -> bar [barno ].barno = barno ;
582
584
ntb -> epf -> bar [barno ].size = size ;
@@ -629,7 +631,7 @@ static void epf_ntb_mw_bar_clear(struct epf_ntb *ntb, int num_mws)
629
631
int i ;
630
632
631
633
for (i = 0 ; i < num_mws ; i ++ ) {
632
- barno = ntb -> epf_ntb_bar [BAR_MW0 + i ];
634
+ barno = ntb -> epf_ntb_bar [BAR_MW1 + i ];
633
635
pci_epc_clear_bar (ntb -> epf -> epc ,
634
636
ntb -> epf -> func_no ,
635
637
ntb -> epf -> vfunc_no ,
@@ -654,6 +656,63 @@ static void epf_ntb_epc_destroy(struct epf_ntb *ntb)
654
656
pci_epc_put (ntb -> epf -> epc );
655
657
}
656
658
659
+
660
+ /**
661
+ * epf_ntb_is_bar_used() - Check if a bar is used in the ntb configuration
662
+ * @ntb: NTB device that facilitates communication between HOST and VHOST
663
+ * @barno: Checked bar number
664
+ *
665
+ * Returns: true if used, false if free.
666
+ */
667
+ static bool epf_ntb_is_bar_used (struct epf_ntb * ntb ,
668
+ enum pci_barno barno )
669
+ {
670
+ int i ;
671
+
672
+ for (i = 0 ; i < VNTB_BAR_NUM ; i ++ ) {
673
+ if (ntb -> epf_ntb_bar [i ] == barno )
674
+ return true;
675
+ }
676
+
677
+ return false;
678
+ }
679
+
680
+ /**
681
+ * epf_ntb_find_bar() - Assign BAR number when no configuration is provided
682
+ * @ntb: NTB device that facilitates communication between HOST and VHOST
683
+ * @epc_features: The features provided by the EPC specific to this EPF
684
+ * @bar: NTB BAR index
685
+ * @barno: Bar start index
686
+ *
687
+ * When the BAR configuration was not provided through the userspace
688
+ * configuration, automatically assign BAR as it has been historically
689
+ * done by this endpoint function.
690
+ *
691
+ * Returns: the BAR number found, if any. -1 otherwise
692
+ */
693
+ static int epf_ntb_find_bar (struct epf_ntb * ntb ,
694
+ const struct pci_epc_features * epc_features ,
695
+ enum epf_ntb_bar bar ,
696
+ enum pci_barno barno )
697
+ {
698
+ while (ntb -> epf_ntb_bar [bar ] < 0 ) {
699
+ barno = pci_epc_get_next_free_bar (epc_features , barno );
700
+ if (barno < 0 )
701
+ break ; /* No more BAR available */
702
+
703
+ /*
704
+ * Verify if the BAR found is not already assigned
705
+ * through the provided configuration
706
+ */
707
+ if (!epf_ntb_is_bar_used (ntb , barno ))
708
+ ntb -> epf_ntb_bar [bar ] = barno ;
709
+
710
+ barno += 1 ;
711
+ }
712
+
713
+ return barno ;
714
+ }
715
+
657
716
/**
658
717
* epf_ntb_init_epc_bar() - Identify BARs to be used for each of the NTB
659
718
* constructs (scratchpad region, doorbell, memorywindow)
@@ -676,23 +735,21 @@ static int epf_ntb_init_epc_bar(struct epf_ntb *ntb)
676
735
epc_features = pci_epc_get_features (ntb -> epf -> epc , ntb -> epf -> func_no , ntb -> epf -> vfunc_no );
677
736
678
737
/* These are required BARs which are mandatory for NTB functionality */
679
- for (bar = BAR_CONFIG ; bar <= BAR_MW0 ; bar ++ , barno ++ ) {
680
- barno = pci_epc_get_next_free_bar ( epc_features , barno );
738
+ for (bar = BAR_CONFIG ; bar <= BAR_MW1 ; bar ++ ) {
739
+ barno = epf_ntb_find_bar ( ntb , epc_features , bar , barno );
681
740
if (barno < 0 ) {
682
741
dev_err (dev , "Fail to get NTB function BAR\n" );
683
- return barno ;
742
+ return - ENOENT ;
684
743
}
685
- ntb -> epf_ntb_bar [bar ] = barno ;
686
744
}
687
745
688
746
/* These are optional BARs which don't impact NTB functionality */
689
- for (bar = BAR_MW1 , i = 1 ; i < num_mws ; bar ++ , barno ++ , i ++ ) {
690
- barno = pci_epc_get_next_free_bar ( epc_features , barno );
747
+ for (bar = BAR_MW1 , i = 1 ; i < num_mws ; bar ++ , i ++ ) {
748
+ barno = epf_ntb_find_bar ( ntb , epc_features , bar , barno );
691
749
if (barno < 0 ) {
692
750
ntb -> num_mws = i ;
693
751
dev_dbg (dev , "BAR not available for > MW%d\n" , i + 1 );
694
752
}
695
- ntb -> epf_ntb_bar [bar ] = barno ;
696
753
}
697
754
698
755
return 0 ;
@@ -860,6 +917,37 @@ static ssize_t epf_ntb_##_name##_store(struct config_item *item, \
860
917
return len; \
861
918
}
862
919
920
+ #define EPF_NTB_BAR_R (_name , _id ) \
921
+ static ssize_t epf_ntb_##_name##_show(struct config_item *item, \
922
+ char *page) \
923
+ { \
924
+ struct config_group *group = to_config_group(item); \
925
+ struct epf_ntb *ntb = to_epf_ntb(group); \
926
+ \
927
+ return sprintf(page, "%d\n", ntb->epf_ntb_bar[_id]); \
928
+ }
929
+
930
+ #define EPF_NTB_BAR_W (_name , _id ) \
931
+ static ssize_t epf_ntb_##_name##_store(struct config_item *item, \
932
+ const char *page, size_t len) \
933
+ { \
934
+ struct config_group *group = to_config_group(item); \
935
+ struct epf_ntb *ntb = to_epf_ntb(group); \
936
+ int val; \
937
+ int ret; \
938
+ \
939
+ ret = kstrtoint(page, 0, &val); \
940
+ if (ret) \
941
+ return ret; \
942
+ \
943
+ if (val < NO_BAR || val > BAR_5) \
944
+ return -EINVAL; \
945
+ \
946
+ ntb->epf_ntb_bar[_id] = val; \
947
+ \
948
+ return len; \
949
+ }
950
+
863
951
static ssize_t epf_ntb_num_mws_store (struct config_item * item ,
864
952
const char * page , size_t len )
865
953
{
@@ -899,6 +987,18 @@ EPF_NTB_MW_R(mw3)
899
987
EPF_NTB_MW_W (mw3 )
900
988
EPF_NTB_MW_R (mw4 )
901
989
EPF_NTB_MW_W (mw4 )
990
+ EPF_NTB_BAR_R (ctrl_bar , BAR_CONFIG )
991
+ EPF_NTB_BAR_W (ctrl_bar , BAR_CONFIG )
992
+ EPF_NTB_BAR_R (db_bar , BAR_DB )
993
+ EPF_NTB_BAR_W (db_bar , BAR_DB )
994
+ EPF_NTB_BAR_R (mw1_bar , BAR_MW1 )
995
+ EPF_NTB_BAR_W (mw1_bar , BAR_MW1 )
996
+ EPF_NTB_BAR_R (mw2_bar , BAR_MW2 )
997
+ EPF_NTB_BAR_W (mw2_bar , BAR_MW2 )
998
+ EPF_NTB_BAR_R (mw3_bar , BAR_MW3 )
999
+ EPF_NTB_BAR_W (mw3_bar , BAR_MW3 )
1000
+ EPF_NTB_BAR_R (mw4_bar , BAR_MW4 )
1001
+ EPF_NTB_BAR_W (mw4_bar , BAR_MW4 )
902
1002
903
1003
CONFIGFS_ATTR (epf_ntb_ , spad_count );
904
1004
CONFIGFS_ATTR (epf_ntb_ , db_count );
@@ -910,6 +1010,12 @@ CONFIGFS_ATTR(epf_ntb_, mw4);
910
1010
CONFIGFS_ATTR (epf_ntb_ , vbus_number );
911
1011
CONFIGFS_ATTR (epf_ntb_ , vntb_pid );
912
1012
CONFIGFS_ATTR (epf_ntb_ , vntb_vid );
1013
+ CONFIGFS_ATTR (epf_ntb_ , ctrl_bar );
1014
+ CONFIGFS_ATTR (epf_ntb_ , db_bar );
1015
+ CONFIGFS_ATTR (epf_ntb_ , mw1_bar );
1016
+ CONFIGFS_ATTR (epf_ntb_ , mw2_bar );
1017
+ CONFIGFS_ATTR (epf_ntb_ , mw3_bar );
1018
+ CONFIGFS_ATTR (epf_ntb_ , mw4_bar );
913
1019
914
1020
static struct configfs_attribute * epf_ntb_attrs [] = {
915
1021
& epf_ntb_attr_spad_count ,
@@ -922,6 +1028,12 @@ static struct configfs_attribute *epf_ntb_attrs[] = {
922
1028
& epf_ntb_attr_vbus_number ,
923
1029
& epf_ntb_attr_vntb_pid ,
924
1030
& epf_ntb_attr_vntb_vid ,
1031
+ & epf_ntb_attr_ctrl_bar ,
1032
+ & epf_ntb_attr_db_bar ,
1033
+ & epf_ntb_attr_mw1_bar ,
1034
+ & epf_ntb_attr_mw2_bar ,
1035
+ & epf_ntb_attr_mw3_bar ,
1036
+ & epf_ntb_attr_mw4_bar ,
925
1037
NULL ,
926
1038
};
927
1039
@@ -1048,7 +1160,7 @@ static int vntb_epf_mw_set_trans(struct ntb_dev *ndev, int pidx, int idx,
1048
1160
struct device * dev ;
1049
1161
1050
1162
dev = & ntb -> ntb .dev ;
1051
- barno = ntb -> epf_ntb_bar [BAR_MW0 + idx ];
1163
+ barno = ntb -> epf_ntb_bar [BAR_MW1 + idx ];
1052
1164
epf_bar = & ntb -> epf -> bar [barno ];
1053
1165
epf_bar -> phys_addr = addr ;
1054
1166
epf_bar -> barno = barno ;
@@ -1379,6 +1491,7 @@ static int epf_ntb_probe(struct pci_epf *epf,
1379
1491
{
1380
1492
struct epf_ntb * ntb ;
1381
1493
struct device * dev ;
1494
+ int i ;
1382
1495
1383
1496
dev = & epf -> dev ;
1384
1497
@@ -1389,6 +1502,11 @@ static int epf_ntb_probe(struct pci_epf *epf,
1389
1502
epf -> header = & epf_ntb_header ;
1390
1503
ntb -> epf = epf ;
1391
1504
ntb -> vbus_number = 0xff ;
1505
+
1506
+ /* Initially, no bar is assigned */
1507
+ for (i = 0 ; i < VNTB_BAR_NUM ; i ++ )
1508
+ ntb -> epf_ntb_bar [i ] = NO_BAR ;
1509
+
1392
1510
epf_set_drvdata (epf , ntb );
1393
1511
1394
1512
dev_info (dev , "pci-ep epf driver loaded\n" );
0 commit comments