@@ -811,9 +811,12 @@ static const struct ntb_dev_ops switchtec_ntb_ops = {
811811 .peer_spad_addr = switchtec_ntb_peer_spad_addr ,
812812};
813813
814- static void switchtec_ntb_init_sndev (struct switchtec_ntb * sndev )
814+ static int switchtec_ntb_init_sndev (struct switchtec_ntb * sndev )
815815{
816+ u64 tpart_vec ;
817+ int self ;
816818 u64 part_map ;
819+ int bit ;
817820
818821 sndev -> ntb .pdev = sndev -> stdev -> pdev ;
819822 sndev -> ntb .topo = NTB_TOPO_NONE ;
@@ -822,13 +825,47 @@ static void switchtec_ntb_init_sndev(struct switchtec_ntb *sndev)
822825 sndev -> self_partition = sndev -> stdev -> partition ;
823826
824827 sndev -> mmio_ntb = sndev -> stdev -> mmio_ntb ;
828+
829+ self = sndev -> self_partition ;
830+ tpart_vec = ioread32 (& sndev -> mmio_ntb -> ntp_info [self ].target_part_high );
831+ tpart_vec <<= 32 ;
832+ tpart_vec |= ioread32 (& sndev -> mmio_ntb -> ntp_info [self ].target_part_low );
833+
825834 part_map = ioread64 (& sndev -> mmio_ntb -> ep_map );
826835 part_map &= ~(1 << sndev -> self_partition );
827- sndev -> peer_partition = ffs (part_map ) - 1 ;
828836
829- dev_dbg (& sndev -> stdev -> dev , "Partition ID %d of %d (%llx)" ,
830- sndev -> self_partition , sndev -> stdev -> partition_count ,
831- part_map );
837+ if (!ffs (tpart_vec )) {
838+ if (sndev -> stdev -> partition_count != 2 ) {
839+ dev_err (& sndev -> stdev -> dev ,
840+ "ntb target partition not defined\n" );
841+ return - ENODEV ;
842+ }
843+
844+ bit = ffs (part_map );
845+ if (!bit ) {
846+ dev_err (& sndev -> stdev -> dev ,
847+ "peer partition is not NT partition\n" );
848+ return - ENODEV ;
849+ }
850+
851+ sndev -> peer_partition = bit - 1 ;
852+ } else {
853+ if (ffs (tpart_vec ) != fls (tpart_vec )) {
854+ dev_err (& sndev -> stdev -> dev ,
855+ "ntb driver only supports 1 pair of 1-1 ntb mapping\n" );
856+ return - ENODEV ;
857+ }
858+
859+ sndev -> peer_partition = ffs (tpart_vec ) - 1 ;
860+ if (!(part_map && (1 << sndev -> peer_partition ))) {
861+ dev_err (& sndev -> stdev -> dev ,
862+ "ntb target partition is not NT partition\n" );
863+ return - ENODEV ;
864+ }
865+ }
866+
867+ dev_dbg (& sndev -> stdev -> dev , "Partition ID %d of %d" ,
868+ sndev -> self_partition , sndev -> stdev -> partition_count );
832869
833870 sndev -> mmio_ctrl = (void * __iomem )sndev -> mmio_ntb +
834871 SWITCHTEC_NTB_REG_CTRL_OFFSET ;
@@ -839,6 +876,8 @@ static void switchtec_ntb_init_sndev(struct switchtec_ntb *sndev)
839876 sndev -> mmio_peer_ctrl = & sndev -> mmio_ctrl [sndev -> peer_partition ];
840877 sndev -> mmio_self_dbmsg = & sndev -> mmio_dbmsg [sndev -> self_partition ];
841878 sndev -> mmio_peer_dbmsg = sndev -> mmio_self_dbmsg ;
879+
880+ return 0 ;
842881}
843882
844883static int config_rsvd_lut_win (struct switchtec_ntb * sndev ,
@@ -1401,15 +1440,15 @@ static int switchtec_ntb_add(struct device *dev,
14011440 if (stdev -> pdev -> class != MICROSEMI_NTB_CLASSCODE )
14021441 return - ENODEV ;
14031442
1404- if (stdev -> partition_count != 2 )
1405- dev_warn (dev , "ntb driver only supports 2 partitions" );
1406-
14071443 sndev = kzalloc_node (sizeof (* sndev ), GFP_KERNEL , dev_to_node (dev ));
14081444 if (!sndev )
14091445 return - ENOMEM ;
14101446
14111447 sndev -> stdev = stdev ;
1412- switchtec_ntb_init_sndev (sndev );
1448+ rc = switchtec_ntb_init_sndev (sndev );
1449+ if (rc )
1450+ goto free_and_exit ;
1451+
14131452 switchtec_ntb_init_mw (sndev );
14141453
14151454 rc = switchtec_ntb_init_req_id_table (sndev );
0 commit comments