@@ -449,7 +449,7 @@ static int crosslink_is_enabled(struct switchtec_ntb *sndev)
449449{
450450 struct ntb_info_regs __iomem * inf = sndev -> mmio_ntb ;
451451
452- return ioread8 (& inf -> crosslink [sndev -> self_partition ]. enabled );
452+ return ioread8 (& inf -> ntp_info [sndev -> peer_partition ]. xlink_enabled );
453453}
454454
455455static void crosslink_init_dbmsgs (struct switchtec_ntb * sndev )
@@ -775,9 +775,12 @@ static const struct ntb_dev_ops switchtec_ntb_ops = {
775775 .peer_spad_addr = switchtec_ntb_peer_spad_addr ,
776776};
777777
778- static void switchtec_ntb_init_sndev (struct switchtec_ntb * sndev )
778+ static int switchtec_ntb_init_sndev (struct switchtec_ntb * sndev )
779779{
780+ u64 tpart_vec ;
781+ int self ;
780782 u64 part_map ;
783+ int bit ;
781784
782785 sndev -> ntb .pdev = sndev -> stdev -> pdev ;
783786 sndev -> ntb .topo = NTB_TOPO_NONE ;
@@ -786,13 +789,47 @@ static void switchtec_ntb_init_sndev(struct switchtec_ntb *sndev)
786789 sndev -> self_partition = sndev -> stdev -> partition ;
787790
788791 sndev -> mmio_ntb = sndev -> stdev -> mmio_ntb ;
792+
793+ self = sndev -> self_partition ;
794+ tpart_vec = ioread32 (& sndev -> mmio_ntb -> ntp_info [self ].target_part_high );
795+ tpart_vec <<= 32 ;
796+ tpart_vec |= ioread32 (& sndev -> mmio_ntb -> ntp_info [self ].target_part_low );
797+
789798 part_map = ioread64 (& sndev -> mmio_ntb -> ep_map );
790799 part_map &= ~(1 << sndev -> self_partition );
791- sndev -> peer_partition = ffs (part_map ) - 1 ;
792800
793- dev_dbg (& sndev -> stdev -> dev , "Partition ID %d of %d (%llx)" ,
794- sndev -> self_partition , sndev -> stdev -> partition_count ,
795- part_map );
801+ if (!ffs (tpart_vec )) {
802+ if (sndev -> stdev -> partition_count != 2 ) {
803+ dev_err (& sndev -> stdev -> dev ,
804+ "ntb target partition not defined\n" );
805+ return - ENODEV ;
806+ }
807+
808+ bit = ffs (part_map );
809+ if (!bit ) {
810+ dev_err (& sndev -> stdev -> dev ,
811+ "peer partition is not NT partition\n" );
812+ return - ENODEV ;
813+ }
814+
815+ sndev -> peer_partition = bit - 1 ;
816+ } else {
817+ if (ffs (tpart_vec ) != fls (tpart_vec )) {
818+ dev_err (& sndev -> stdev -> dev ,
819+ "ntb driver only supports 1 pair of 1-1 ntb mapping\n" );
820+ return - ENODEV ;
821+ }
822+
823+ sndev -> peer_partition = ffs (tpart_vec ) - 1 ;
824+ if (!(part_map && (1 << sndev -> peer_partition ))) {
825+ dev_err (& sndev -> stdev -> dev ,
826+ "ntb target partition is not NT partition\n" );
827+ return - ENODEV ;
828+ }
829+ }
830+
831+ dev_dbg (& sndev -> stdev -> dev , "Partition ID %d of %d" ,
832+ sndev -> self_partition , sndev -> stdev -> partition_count );
796833
797834 sndev -> mmio_ctrl = (void * __iomem )sndev -> mmio_ntb +
798835 SWITCHTEC_NTB_REG_CTRL_OFFSET ;
@@ -803,6 +840,8 @@ static void switchtec_ntb_init_sndev(struct switchtec_ntb *sndev)
803840 sndev -> mmio_peer_ctrl = & sndev -> mmio_ctrl [sndev -> peer_partition ];
804841 sndev -> mmio_self_dbmsg = & sndev -> mmio_dbmsg [sndev -> self_partition ];
805842 sndev -> mmio_peer_dbmsg = sndev -> mmio_self_dbmsg ;
843+
844+ return 0 ;
806845}
807846
808847static int config_rsvd_lut_win (struct switchtec_ntb * sndev ,
@@ -1365,15 +1404,15 @@ static int switchtec_ntb_add(struct device *dev,
13651404 if (stdev -> pdev -> class != MICROSEMI_NTB_CLASSCODE )
13661405 return - ENODEV ;
13671406
1368- if (stdev -> partition_count != 2 )
1369- dev_warn (dev , "ntb driver only supports 2 partitions" );
1370-
13711407 sndev = kzalloc_node (sizeof (* sndev ), GFP_KERNEL , dev_to_node (dev ));
13721408 if (!sndev )
13731409 return - ENOMEM ;
13741410
13751411 sndev -> stdev = stdev ;
1376- switchtec_ntb_init_sndev (sndev );
1412+ rc = switchtec_ntb_init_sndev (sndev );
1413+ if (rc )
1414+ goto free_and_exit ;
1415+
13771416 switchtec_ntb_init_mw (sndev );
13781417
13791418 rc = switchtec_ntb_init_req_id_table (sndev );
0 commit comments