aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rapidio
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/rapidio')
-rw-r--r--drivers/rapidio/Makefile4
-rw-r--r--drivers/rapidio/rio-driver.c2
-rw-r--r--drivers/rapidio/rio-scan.c329
-rw-r--r--drivers/rapidio/rio-sysfs.c78
-rw-r--r--drivers/rapidio/rio.c427
-rw-r--r--drivers/rapidio/rio.h5
-rw-r--r--drivers/rapidio/switches/Kconfig7
-rw-r--r--drivers/rapidio/switches/Makefile5
-rw-r--r--drivers/rapidio/switches/idt_gen2.c430
-rw-r--r--drivers/rapidio/switches/idtcps.c12
-rw-r--r--drivers/rapidio/switches/tsi568.c18
-rw-r--r--drivers/rapidio/switches/tsi57x.c67
12 files changed, 1068 insertions, 316 deletions
diff --git a/drivers/rapidio/Makefile b/drivers/rapidio/Makefile
index b6139fe187bf..89b8eca825b5 100644
--- a/drivers/rapidio/Makefile
+++ b/drivers/rapidio/Makefile
@@ -5,6 +5,4 @@ obj-y += rio.o rio-access.o rio-driver.o rio-scan.o rio-sysfs.o
5 5
6obj-$(CONFIG_RAPIDIO) += switches/ 6obj-$(CONFIG_RAPIDIO) += switches/
7 7
8ifeq ($(CONFIG_RAPIDIO_DEBUG),y) 8subdir-ccflags-$(CONFIG_RAPIDIO_DEBUG) := -DDEBUG
9EXTRA_CFLAGS += -DDEBUG
10endif
diff --git a/drivers/rapidio/rio-driver.c b/drivers/rapidio/rio-driver.c
index 3222fa3c808c..0f4a53bdaa3c 100644
--- a/drivers/rapidio/rio-driver.c
+++ b/drivers/rapidio/rio-driver.c
@@ -192,7 +192,7 @@ static int rio_match_bus(struct device *dev, struct device_driver *drv)
192 out:return 0; 192 out:return 0;
193} 193}
194 194
195static struct device rio_bus = { 195struct device rio_bus = {
196 .init_name = "rapidio", 196 .init_name = "rapidio",
197}; 197};
198 198
diff --git a/drivers/rapidio/rio-scan.c b/drivers/rapidio/rio-scan.c
index 8070e074c739..ee893581d4b7 100644
--- a/drivers/rapidio/rio-scan.c
+++ b/drivers/rapidio/rio-scan.c
@@ -46,9 +46,8 @@ static void rio_init_em(struct rio_dev *rdev);
46DEFINE_SPINLOCK(rio_global_list_lock); 46DEFINE_SPINLOCK(rio_global_list_lock);
47 47
48static int next_destid = 0; 48static int next_destid = 0;
49static int next_switchid = 0;
50static int next_net = 0; 49static int next_net = 0;
51static int next_comptag; 50static int next_comptag = 1;
52 51
53static struct timer_list rio_enum_timer = 52static struct timer_list rio_enum_timer =
54TIMER_INITIALIZER(rio_enum_timeout, 0, 0); 53TIMER_INITIALIZER(rio_enum_timeout, 0, 0);
@@ -121,27 +120,6 @@ static int rio_clear_locks(struct rio_mport *port)
121 u32 result; 120 u32 result;
122 int ret = 0; 121 int ret = 0;
123 122
124 /* Assign component tag to all devices */
125 next_comptag = 1;
126 rio_local_write_config_32(port, RIO_COMPONENT_TAG_CSR, next_comptag++);
127
128 list_for_each_entry(rdev, &rio_devices, global_list) {
129 /* Mark device as discovered */
130 rio_read_config_32(rdev,
131 rdev->phys_efptr + RIO_PORT_GEN_CTL_CSR,
132 &result);
133 rio_write_config_32(rdev,
134 rdev->phys_efptr + RIO_PORT_GEN_CTL_CSR,
135 result | RIO_PORT_GEN_DISCOVERED);
136
137 rio_write_config_32(rdev, RIO_COMPONENT_TAG_CSR, next_comptag);
138 rdev->comp_tag = next_comptag++;
139 if (next_comptag >= 0x10000) {
140 pr_err("RIO: Component Tag Counter Overflow\n");
141 break;
142 }
143 }
144
145 /* Release host device id locks */ 123 /* Release host device id locks */
146 rio_local_write_config_32(port, RIO_HOST_DID_LOCK_CSR, 124 rio_local_write_config_32(port, RIO_HOST_DID_LOCK_CSR,
147 port->host_deviceid); 125 port->host_deviceid);
@@ -162,6 +140,15 @@ static int rio_clear_locks(struct rio_mport *port)
162 rdev->vid, rdev->did); 140 rdev->vid, rdev->did);
163 ret = -EINVAL; 141 ret = -EINVAL;
164 } 142 }
143
144 /* Mark device as discovered and enable master */
145 rio_read_config_32(rdev,
146 rdev->phys_efptr + RIO_PORT_GEN_CTL_CSR,
147 &result);
148 result |= RIO_PORT_GEN_DISCOVERED | RIO_PORT_GEN_MASTER;
149 rio_write_config_32(rdev,
150 rdev->phys_efptr + RIO_PORT_GEN_CTL_CSR,
151 result);
165 } 152 }
166 153
167 return ret; 154 return ret;
@@ -308,7 +295,7 @@ static int __devinit rio_add_device(struct rio_dev *rdev)
308} 295}
309 296
310/** 297/**
311 * rio_enable_rx_tx_port - enable input reciever and output transmitter of 298 * rio_enable_rx_tx_port - enable input receiver and output transmitter of
312 * given port 299 * given port
313 * @port: Master port associated with the RIO network 300 * @port: Master port associated with the RIO network
314 * @local: local=1 select local port otherwise a far device is reached 301 * @local: local=1 select local port otherwise a far device is reached
@@ -390,12 +377,30 @@ static struct rio_dev __devinit *rio_setup_device(struct rio_net *net,
390 struct rio_dev *rdev; 377 struct rio_dev *rdev;
391 struct rio_switch *rswitch = NULL; 378 struct rio_switch *rswitch = NULL;
392 int result, rdid; 379 int result, rdid;
380 size_t size;
381 u32 swpinfo = 0;
382
383 size = sizeof(struct rio_dev);
384 if (rio_mport_read_config_32(port, destid, hopcount,
385 RIO_PEF_CAR, &result))
386 return NULL;
393 387
394 rdev = kzalloc(sizeof(struct rio_dev), GFP_KERNEL); 388 if (result & (RIO_PEF_SWITCH | RIO_PEF_MULTIPORT)) {
389 rio_mport_read_config_32(port, destid, hopcount,
390 RIO_SWP_INFO_CAR, &swpinfo);
391 if (result & RIO_PEF_SWITCH) {
392 size += (RIO_GET_TOTAL_PORTS(swpinfo) *
393 sizeof(rswitch->nextdev[0])) + sizeof(*rswitch);
394 }
395 }
396
397 rdev = kzalloc(size, GFP_KERNEL);
395 if (!rdev) 398 if (!rdev)
396 return NULL; 399 return NULL;
397 400
398 rdev->net = net; 401 rdev->net = net;
402 rdev->pef = result;
403 rdev->swpinfo = swpinfo;
399 rio_mport_read_config_32(port, destid, hopcount, RIO_DEV_ID_CAR, 404 rio_mport_read_config_32(port, destid, hopcount, RIO_DEV_ID_CAR,
400 &result); 405 &result);
401 rdev->did = result >> 16; 406 rdev->did = result >> 16;
@@ -409,8 +414,6 @@ static struct rio_dev __devinit *rio_setup_device(struct rio_net *net,
409 rio_mport_read_config_32(port, destid, hopcount, RIO_ASM_INFO_CAR, 414 rio_mport_read_config_32(port, destid, hopcount, RIO_ASM_INFO_CAR,
410 &result); 415 &result);
411 rdev->asm_rev = result >> 16; 416 rdev->asm_rev = result >> 16;
412 rio_mport_read_config_32(port, destid, hopcount, RIO_PEF_CAR,
413 &rdev->pef);
414 if (rdev->pef & RIO_PEF_EXT_FEATURES) { 417 if (rdev->pef & RIO_PEF_EXT_FEATURES) {
415 rdev->efptr = result & 0xffff; 418 rdev->efptr = result & 0xffff;
416 rdev->phys_efptr = rio_mport_get_physefb(port, 0, destid, 419 rdev->phys_efptr = rio_mport_get_physefb(port, 0, destid,
@@ -425,6 +428,21 @@ static struct rio_dev __devinit *rio_setup_device(struct rio_net *net,
425 rio_mport_read_config_32(port, destid, hopcount, RIO_DST_OPS_CAR, 428 rio_mport_read_config_32(port, destid, hopcount, RIO_DST_OPS_CAR,
426 &rdev->dst_ops); 429 &rdev->dst_ops);
427 430
431 if (do_enum) {
432 /* Assign component tag to device */
433 if (next_comptag >= 0x10000) {
434 pr_err("RIO: Component Tag Counter Overflow\n");
435 goto cleanup;
436 }
437 rio_mport_write_config_32(port, destid, hopcount,
438 RIO_COMPONENT_TAG_CSR, next_comptag);
439 rdev->comp_tag = next_comptag++;
440 } else {
441 rio_mport_read_config_32(port, destid, hopcount,
442 RIO_COMPONENT_TAG_CSR,
443 &rdev->comp_tag);
444 }
445
428 if (rio_device_has_destid(port, rdev->src_ops, rdev->dst_ops)) { 446 if (rio_device_has_destid(port, rdev->src_ops, rdev->dst_ops)) {
429 if (do_enum) { 447 if (do_enum) {
430 rio_set_device_id(port, destid, hopcount, next_destid); 448 rio_set_device_id(port, destid, hopcount, next_destid);
@@ -433,20 +451,20 @@ static struct rio_dev __devinit *rio_setup_device(struct rio_net *net,
433 next_destid++; 451 next_destid++;
434 } else 452 } else
435 rdev->destid = rio_get_device_id(port, destid, hopcount); 453 rdev->destid = rio_get_device_id(port, destid, hopcount);
436 } else 454
437 /* Switch device has an associated destID */ 455 rdev->hopcount = 0xff;
438 rdev->destid = RIO_INVALID_DESTID; 456 } else {
457 /* Switch device has an associated destID which
458 * will be adjusted later
459 */
460 rdev->destid = destid;
461 rdev->hopcount = hopcount;
462 }
439 463
440 /* If a PE has both switch and other functions, show it as a switch */ 464 /* If a PE has both switch and other functions, show it as a switch */
441 if (rio_is_switch(rdev)) { 465 if (rio_is_switch(rdev)) {
442 rio_mport_read_config_32(port, destid, hopcount, 466 rswitch = rdev->rswitch;
443 RIO_SWP_INFO_CAR, &rdev->swpinfo); 467 rswitch->switchid = rdev->comp_tag & RIO_CTAG_UDEVID;
444 rswitch = kzalloc(sizeof(struct rio_switch), GFP_KERNEL);
445 if (!rswitch)
446 goto cleanup;
447 rswitch->switchid = next_switchid;
448 rswitch->hopcount = hopcount;
449 rswitch->destid = destid;
450 rswitch->port_ok = 0; 468 rswitch->port_ok = 0;
451 rswitch->route_table = kzalloc(sizeof(u8)* 469 rswitch->route_table = kzalloc(sizeof(u8)*
452 RIO_MAX_ROUTE_ENTRIES(port->sys_size), 470 RIO_MAX_ROUTE_ENTRIES(port->sys_size),
@@ -457,14 +475,13 @@ static struct rio_dev __devinit *rio_setup_device(struct rio_net *net,
457 for (rdid = 0; rdid < RIO_MAX_ROUTE_ENTRIES(port->sys_size); 475 for (rdid = 0; rdid < RIO_MAX_ROUTE_ENTRIES(port->sys_size);
458 rdid++) 476 rdid++)
459 rswitch->route_table[rdid] = RIO_INVALID_ROUTE; 477 rswitch->route_table[rdid] = RIO_INVALID_ROUTE;
460 rdev->rswitch = rswitch;
461 dev_set_name(&rdev->dev, "%02x:s:%04x", rdev->net->id, 478 dev_set_name(&rdev->dev, "%02x:s:%04x", rdev->net->id,
462 rdev->rswitch->switchid); 479 rswitch->switchid);
463 rio_switch_init(rdev, do_enum); 480 rio_switch_init(rdev, do_enum);
464 481
465 if (do_enum && rdev->rswitch->clr_table) 482 if (do_enum && rswitch->clr_table)
466 rdev->rswitch->clr_table(port, destid, hopcount, 483 rswitch->clr_table(port, destid, hopcount,
467 RIO_GLOBAL_TABLE); 484 RIO_GLOBAL_TABLE);
468 485
469 list_add_tail(&rswitch->node, &rio_switches); 486 list_add_tail(&rswitch->node, &rio_switches);
470 487
@@ -478,6 +495,7 @@ static struct rio_dev __devinit *rio_setup_device(struct rio_net *net,
478 } 495 }
479 496
480 rdev->dev.bus = &rio_bus_type; 497 rdev->dev.bus = &rio_bus_type;
498 rdev->dev.parent = &rio_bus;
481 499
482 device_initialize(&rdev->dev); 500 device_initialize(&rdev->dev);
483 rdev->dev.release = rio_release_dev; 501 rdev->dev.release = rio_release_dev;
@@ -499,10 +517,9 @@ static struct rio_dev __devinit *rio_setup_device(struct rio_net *net,
499 return rdev; 517 return rdev;
500 518
501cleanup: 519cleanup:
502 if (rswitch) { 520 if (rio_is_switch(rdev))
503 kfree(rswitch->route_table); 521 kfree(rswitch->route_table);
504 kfree(rswitch); 522
505 }
506 kfree(rdev); 523 kfree(rdev);
507 return NULL; 524 return NULL;
508} 525}
@@ -625,8 +642,7 @@ rio_unlock_device(struct rio_mport *port, u16 destid, u8 hopcount)
625 642
626/** 643/**
627 * rio_route_add_entry- Add a route entry to a switch routing table 644 * rio_route_add_entry- Add a route entry to a switch routing table
628 * @mport: Master port to send transaction 645 * @rdev: RIO device
629 * @rswitch: Switch device
630 * @table: Routing table ID 646 * @table: Routing table ID
631 * @route_destid: Destination ID to be routed 647 * @route_destid: Destination ID to be routed
632 * @route_port: Port number to be routed 648 * @route_port: Port number to be routed
@@ -640,31 +656,31 @@ rio_unlock_device(struct rio_mport *port, u16 destid, u8 hopcount)
640 * on failure. 656 * on failure.
641 */ 657 */
642static int 658static int
643rio_route_add_entry(struct rio_mport *mport, struct rio_switch *rswitch, 659rio_route_add_entry(struct rio_dev *rdev,
644 u16 table, u16 route_destid, u8 route_port, int lock) 660 u16 table, u16 route_destid, u8 route_port, int lock)
645{ 661{
646 int rc; 662 int rc;
647 663
648 if (lock) { 664 if (lock) {
649 rc = rio_lock_device(mport, rswitch->destid, 665 rc = rio_lock_device(rdev->net->hport, rdev->destid,
650 rswitch->hopcount, 1000); 666 rdev->hopcount, 1000);
651 if (rc) 667 if (rc)
652 return rc; 668 return rc;
653 } 669 }
654 670
655 rc = rswitch->add_entry(mport, rswitch->destid, 671 rc = rdev->rswitch->add_entry(rdev->net->hport, rdev->destid,
656 rswitch->hopcount, table, 672 rdev->hopcount, table,
657 route_destid, route_port); 673 route_destid, route_port);
658 if (lock) 674 if (lock)
659 rio_unlock_device(mport, rswitch->destid, rswitch->hopcount); 675 rio_unlock_device(rdev->net->hport, rdev->destid,
676 rdev->hopcount);
660 677
661 return rc; 678 return rc;
662} 679}
663 680
664/** 681/**
665 * rio_route_get_entry- Read a route entry in a switch routing table 682 * rio_route_get_entry- Read a route entry in a switch routing table
666 * @mport: Master port to send transaction 683 * @rdev: RIO device
667 * @rswitch: Switch device
668 * @table: Routing table ID 684 * @table: Routing table ID
669 * @route_destid: Destination ID to be routed 685 * @route_destid: Destination ID to be routed
670 * @route_port: Pointer to read port number into 686 * @route_port: Pointer to read port number into
@@ -678,23 +694,24 @@ rio_route_add_entry(struct rio_mport *mport, struct rio_switch *rswitch,
678 * on failure. 694 * on failure.
679 */ 695 */
680static int 696static int
681rio_route_get_entry(struct rio_mport *mport, struct rio_switch *rswitch, u16 table, 697rio_route_get_entry(struct rio_dev *rdev, u16 table,
682 u16 route_destid, u8 *route_port, int lock) 698 u16 route_destid, u8 *route_port, int lock)
683{ 699{
684 int rc; 700 int rc;
685 701
686 if (lock) { 702 if (lock) {
687 rc = rio_lock_device(mport, rswitch->destid, 703 rc = rio_lock_device(rdev->net->hport, rdev->destid,
688 rswitch->hopcount, 1000); 704 rdev->hopcount, 1000);
689 if (rc) 705 if (rc)
690 return rc; 706 return rc;
691 } 707 }
692 708
693 rc = rswitch->get_entry(mport, rswitch->destid, 709 rc = rdev->rswitch->get_entry(rdev->net->hport, rdev->destid,
694 rswitch->hopcount, table, 710 rdev->hopcount, table,
695 route_destid, route_port); 711 route_destid, route_port);
696 if (lock) 712 if (lock)
697 rio_unlock_device(mport, rswitch->destid, rswitch->hopcount); 713 rio_unlock_device(rdev->net->hport, rdev->destid,
714 rdev->hopcount);
698 715
699 return rc; 716 return rc;
700} 717}
@@ -718,86 +735,53 @@ static u16 rio_get_host_deviceid_lock(struct rio_mport *port, u8 hopcount)
718} 735}
719 736
720/** 737/**
721 * rio_get_swpinfo_inport- Gets the ingress port number
722 * @mport: Master port to send transaction
723 * @destid: Destination ID associated with the switch
724 * @hopcount: Number of hops to the device
725 *
726 * Returns port number being used to access the switch device.
727 */
728static u8
729rio_get_swpinfo_inport(struct rio_mport *mport, u16 destid, u8 hopcount)
730{
731 u32 result;
732
733 rio_mport_read_config_32(mport, destid, hopcount, RIO_SWP_INFO_CAR,
734 &result);
735
736 return (u8) (result & 0xff);
737}
738
739/**
740 * rio_get_swpinfo_tports- Gets total number of ports on the switch
741 * @mport: Master port to send transaction
742 * @destid: Destination ID associated with the switch
743 * @hopcount: Number of hops to the device
744 *
745 * Returns total numbers of ports implemented by the switch device.
746 */
747static u8 rio_get_swpinfo_tports(struct rio_mport *mport, u16 destid,
748 u8 hopcount)
749{
750 u32 result;
751
752 rio_mport_read_config_32(mport, destid, hopcount, RIO_SWP_INFO_CAR,
753 &result);
754
755 return RIO_GET_TOTAL_PORTS(result);
756}
757
758/**
759 * rio_net_add_mport- Add a master port to a RIO network
760 * @net: RIO network
761 * @port: Master port to add
762 *
763 * Adds a master port to the network list of associated master
764 * ports..
765 */
766static void rio_net_add_mport(struct rio_net *net, struct rio_mport *port)
767{
768 spin_lock(&rio_global_list_lock);
769 list_add_tail(&port->nnode, &net->mports);
770 spin_unlock(&rio_global_list_lock);
771}
772
773/**
774 * rio_enum_peer- Recursively enumerate a RIO network through a master port 738 * rio_enum_peer- Recursively enumerate a RIO network through a master port
775 * @net: RIO network being enumerated 739 * @net: RIO network being enumerated
776 * @port: Master port to send transactions 740 * @port: Master port to send transactions
777 * @hopcount: Number of hops into the network 741 * @hopcount: Number of hops into the network
742 * @prev: Previous RIO device connected to the enumerated one
743 * @prev_port: Port on previous RIO device
778 * 744 *
779 * Recursively enumerates a RIO network. Transactions are sent via the 745 * Recursively enumerates a RIO network. Transactions are sent via the
780 * master port passed in @port. 746 * master port passed in @port.
781 */ 747 */
782static int __devinit rio_enum_peer(struct rio_net *net, struct rio_mport *port, 748static int __devinit rio_enum_peer(struct rio_net *net, struct rio_mport *port,
783 u8 hopcount) 749 u8 hopcount, struct rio_dev *prev, int prev_port)
784{ 750{
785 int port_num; 751 int port_num;
786 int num_ports;
787 int cur_destid; 752 int cur_destid;
788 int sw_destid; 753 int sw_destid;
789 int sw_inport; 754 int sw_inport;
790 struct rio_dev *rdev; 755 struct rio_dev *rdev;
791 u16 destid; 756 u16 destid;
757 u32 regval;
792 int tmp; 758 int tmp;
793 759
760 if (rio_mport_chk_dev_access(port,
761 RIO_ANY_DESTID(port->sys_size), hopcount)) {
762 pr_debug("RIO: device access check failed\n");
763 return -1;
764 }
765
794 if (rio_get_host_deviceid_lock(port, hopcount) == port->host_deviceid) { 766 if (rio_get_host_deviceid_lock(port, hopcount) == port->host_deviceid) {
795 pr_debug("RIO: PE already discovered by this host\n"); 767 pr_debug("RIO: PE already discovered by this host\n");
796 /* 768 /*
797 * Already discovered by this host. Add it as another 769 * Already discovered by this host. Add it as another
798 * master port for the current network. 770 * link to the existing device.
799 */ 771 */
800 rio_net_add_mport(net, port); 772 rio_mport_read_config_32(port, RIO_ANY_DESTID(port->sys_size),
773 hopcount, RIO_COMPONENT_TAG_CSR, &regval);
774
775 if (regval) {
776 rdev = rio_get_comptag((regval & 0xffff), NULL);
777
778 if (rdev && prev && rio_is_switch(prev)) {
779 pr_debug("RIO: redundant path to %s\n",
780 rio_name(rdev));
781 prev->rswitch->nextdev[prev_port] = rdev;
782 }
783 }
784
801 return 0; 785 return 0;
802 } 786 }
803 787
@@ -828,33 +812,34 @@ static int __devinit rio_enum_peer(struct rio_net *net, struct rio_mport *port,
828 if (rdev) { 812 if (rdev) {
829 /* Add device to the global and bus/net specific list. */ 813 /* Add device to the global and bus/net specific list. */
830 list_add_tail(&rdev->net_list, &net->devices); 814 list_add_tail(&rdev->net_list, &net->devices);
815 rdev->prev = prev;
816 if (prev && rio_is_switch(prev))
817 prev->rswitch->nextdev[prev_port] = rdev;
831 } else 818 } else
832 return -1; 819 return -1;
833 820
834 if (rio_is_switch(rdev)) { 821 if (rio_is_switch(rdev)) {
835 next_switchid++; 822 sw_inport = RIO_GET_PORT_NUM(rdev->swpinfo);
836 sw_inport = rio_get_swpinfo_inport(port, 823 rio_route_add_entry(rdev, RIO_GLOBAL_TABLE,
837 RIO_ANY_DESTID(port->sys_size), hopcount);
838 rio_route_add_entry(port, rdev->rswitch, RIO_GLOBAL_TABLE,
839 port->host_deviceid, sw_inport, 0); 824 port->host_deviceid, sw_inport, 0);
840 rdev->rswitch->route_table[port->host_deviceid] = sw_inport; 825 rdev->rswitch->route_table[port->host_deviceid] = sw_inport;
841 826
842 for (destid = 0; destid < next_destid; destid++) { 827 for (destid = 0; destid < next_destid; destid++) {
843 if (destid == port->host_deviceid) 828 if (destid == port->host_deviceid)
844 continue; 829 continue;
845 rio_route_add_entry(port, rdev->rswitch, RIO_GLOBAL_TABLE, 830 rio_route_add_entry(rdev, RIO_GLOBAL_TABLE,
846 destid, sw_inport, 0); 831 destid, sw_inport, 0);
847 rdev->rswitch->route_table[destid] = sw_inport; 832 rdev->rswitch->route_table[destid] = sw_inport;
848 } 833 }
849 834
850 num_ports =
851 rio_get_swpinfo_tports(port, RIO_ANY_DESTID(port->sys_size),
852 hopcount);
853 pr_debug( 835 pr_debug(
854 "RIO: found %s (vid %4.4x did %4.4x) with %d ports\n", 836 "RIO: found %s (vid %4.4x did %4.4x) with %d ports\n",
855 rio_name(rdev), rdev->vid, rdev->did, num_ports); 837 rio_name(rdev), rdev->vid, rdev->did,
838 RIO_GET_TOTAL_PORTS(rdev->swpinfo));
856 sw_destid = next_destid; 839 sw_destid = next_destid;
857 for (port_num = 0; port_num < num_ports; port_num++) { 840 for (port_num = 0;
841 port_num < RIO_GET_TOTAL_PORTS(rdev->swpinfo);
842 port_num++) {
858 /*Enable Input Output Port (transmitter reviever)*/ 843 /*Enable Input Output Port (transmitter reviever)*/
859 rio_enable_rx_tx_port(port, 0, 844 rio_enable_rx_tx_port(port, 0,
860 RIO_ANY_DESTID(port->sys_size), 845 RIO_ANY_DESTID(port->sys_size),
@@ -874,12 +859,12 @@ static int __devinit rio_enum_peer(struct rio_net *net, struct rio_mport *port,
874 "RIO: scanning device on port %d\n", 859 "RIO: scanning device on port %d\n",
875 port_num); 860 port_num);
876 rdev->rswitch->port_ok |= (1 << port_num); 861 rdev->rswitch->port_ok |= (1 << port_num);
877 rio_route_add_entry(port, rdev->rswitch, 862 rio_route_add_entry(rdev, RIO_GLOBAL_TABLE,
878 RIO_GLOBAL_TABLE,
879 RIO_ANY_DESTID(port->sys_size), 863 RIO_ANY_DESTID(port->sys_size),
880 port_num, 0); 864 port_num, 0);
881 865
882 if (rio_enum_peer(net, port, hopcount + 1) < 0) 866 if (rio_enum_peer(net, port, hopcount + 1,
867 rdev, port_num) < 0)
883 return -1; 868 return -1;
884 869
885 /* Update routing tables */ 870 /* Update routing tables */
@@ -888,7 +873,7 @@ static int __devinit rio_enum_peer(struct rio_net *net, struct rio_mport *port,
888 destid < next_destid; destid++) { 873 destid < next_destid; destid++) {
889 if (destid == port->host_deviceid) 874 if (destid == port->host_deviceid)
890 continue; 875 continue;
891 rio_route_add_entry(port, rdev->rswitch, 876 rio_route_add_entry(rdev,
892 RIO_GLOBAL_TABLE, 877 RIO_GLOBAL_TABLE,
893 destid, 878 destid,
894 port_num, 879 port_num,
@@ -927,7 +912,7 @@ static int __devinit rio_enum_peer(struct rio_net *net, struct rio_mport *port,
927 next_destid++; 912 next_destid++;
928 } 913 }
929 914
930 rdev->rswitch->destid = sw_destid; 915 rdev->destid = sw_destid;
931 } else 916 } else
932 pr_debug("RIO: found %s (vid %4.4x did %4.4x)\n", 917 pr_debug("RIO: found %s (vid %4.4x did %4.4x)\n",
933 rio_name(rdev), rdev->vid, rdev->did); 918 rio_name(rdev), rdev->vid, rdev->did);
@@ -945,10 +930,11 @@ static int __devinit rio_enum_peer(struct rio_net *net, struct rio_mport *port,
945 */ 930 */
946static int rio_enum_complete(struct rio_mport *port) 931static int rio_enum_complete(struct rio_mport *port)
947{ 932{
948 u32 tag_csr; 933 u32 regval;
949 934
950 rio_local_read_config_32(port, RIO_COMPONENT_TAG_CSR, &tag_csr); 935 rio_local_read_config_32(port, port->phys_efptr + RIO_PORT_GEN_CTL_CSR,
951 return (tag_csr & 0xffff) ? 1 : 0; 936 &regval);
937 return (regval & RIO_PORT_GEN_MASTER) ? 1 : 0;
952} 938}
953 939
954/** 940/**
@@ -957,16 +943,17 @@ static int rio_enum_complete(struct rio_mport *port)
957 * @port: Master port to send transactions 943 * @port: Master port to send transactions
958 * @destid: Current destination ID in network 944 * @destid: Current destination ID in network
959 * @hopcount: Number of hops into the network 945 * @hopcount: Number of hops into the network
946 * @prev: previous rio_dev
947 * @prev_port: previous port number
960 * 948 *
961 * Recursively discovers a RIO network. Transactions are sent via the 949 * Recursively discovers a RIO network. Transactions are sent via the
962 * master port passed in @port. 950 * master port passed in @port.
963 */ 951 */
964static int __devinit 952static int __devinit
965rio_disc_peer(struct rio_net *net, struct rio_mport *port, u16 destid, 953rio_disc_peer(struct rio_net *net, struct rio_mport *port, u16 destid,
966 u8 hopcount) 954 u8 hopcount, struct rio_dev *prev, int prev_port)
967{ 955{
968 u8 port_num, route_port; 956 u8 port_num, route_port;
969 int num_ports;
970 struct rio_dev *rdev; 957 struct rio_dev *rdev;
971 u16 ndestid; 958 u16 ndestid;
972 959
@@ -974,22 +961,24 @@ rio_disc_peer(struct rio_net *net, struct rio_mport *port, u16 destid,
974 if ((rdev = rio_setup_device(net, port, destid, hopcount, 0))) { 961 if ((rdev = rio_setup_device(net, port, destid, hopcount, 0))) {
975 /* Add device to the global and bus/net specific list. */ 962 /* Add device to the global and bus/net specific list. */
976 list_add_tail(&rdev->net_list, &net->devices); 963 list_add_tail(&rdev->net_list, &net->devices);
964 rdev->prev = prev;
965 if (prev && rio_is_switch(prev))
966 prev->rswitch->nextdev[prev_port] = rdev;
977 } else 967 } else
978 return -1; 968 return -1;
979 969
980 if (rio_is_switch(rdev)) { 970 if (rio_is_switch(rdev)) {
981 next_switchid++;
982
983 /* Associated destid is how we accessed this switch */ 971 /* Associated destid is how we accessed this switch */
984 rdev->rswitch->destid = destid; 972 rdev->destid = destid;
985 973
986 num_ports = rio_get_swpinfo_tports(port, destid, hopcount);
987 pr_debug( 974 pr_debug(
988 "RIO: found %s (vid %4.4x did %4.4x) with %d ports\n", 975 "RIO: found %s (vid %4.4x did %4.4x) with %d ports\n",
989 rio_name(rdev), rdev->vid, rdev->did, num_ports); 976 rio_name(rdev), rdev->vid, rdev->did,
990 for (port_num = 0; port_num < num_ports; port_num++) { 977 RIO_GET_TOTAL_PORTS(rdev->swpinfo));
991 if (rio_get_swpinfo_inport(port, destid, hopcount) == 978 for (port_num = 0;
992 port_num) 979 port_num < RIO_GET_TOTAL_PORTS(rdev->swpinfo);
980 port_num++) {
981 if (RIO_GET_PORT_NUM(rdev->swpinfo) == port_num)
993 continue; 982 continue;
994 983
995 if (rio_sport_is_active 984 if (rio_sport_is_active
@@ -1003,7 +992,7 @@ rio_disc_peer(struct rio_net *net, struct rio_mport *port, u16 destid,
1003 for (ndestid = 0; 992 for (ndestid = 0;
1004 ndestid < RIO_ANY_DESTID(port->sys_size); 993 ndestid < RIO_ANY_DESTID(port->sys_size);
1005 ndestid++) { 994 ndestid++) {
1006 rio_route_get_entry(port, rdev->rswitch, 995 rio_route_get_entry(rdev,
1007 RIO_GLOBAL_TABLE, 996 RIO_GLOBAL_TABLE,
1008 ndestid, 997 ndestid,
1009 &route_port, 0); 998 &route_port, 0);
@@ -1011,9 +1000,11 @@ rio_disc_peer(struct rio_net *net, struct rio_mport *port, u16 destid,
1011 break; 1000 break;
1012 } 1001 }
1013 1002
1003 if (ndestid == RIO_ANY_DESTID(port->sys_size))
1004 continue;
1014 rio_unlock_device(port, destid, hopcount); 1005 rio_unlock_device(port, destid, hopcount);
1015 if (rio_disc_peer 1006 if (rio_disc_peer(net, port, ndestid,
1016 (net, port, ndestid, hopcount + 1) < 0) 1007 hopcount + 1, rdev, port_num) < 0)
1017 return -1; 1008 return -1;
1018 } 1009 }
1019 } 1010 }
@@ -1089,14 +1080,14 @@ static struct rio_net __devinit *rio_alloc_net(struct rio_mport *port)
1089 */ 1080 */
1090static void rio_update_route_tables(struct rio_mport *port) 1081static void rio_update_route_tables(struct rio_mport *port)
1091{ 1082{
1092 struct rio_dev *rdev; 1083 struct rio_dev *rdev, *swrdev;
1093 struct rio_switch *rswitch; 1084 struct rio_switch *rswitch;
1094 u8 sport; 1085 u8 sport;
1095 u16 destid; 1086 u16 destid;
1096 1087
1097 list_for_each_entry(rdev, &rio_devices, global_list) { 1088 list_for_each_entry(rdev, &rio_devices, global_list) {
1098 1089
1099 destid = (rio_is_switch(rdev))?rdev->rswitch->destid:rdev->destid; 1090 destid = rdev->destid;
1100 1091
1101 list_for_each_entry(rswitch, &rio_switches, node) { 1092 list_for_each_entry(rswitch, &rio_switches, node) {
1102 1093
@@ -1104,15 +1095,16 @@ static void rio_update_route_tables(struct rio_mport *port)
1104 continue; 1095 continue;
1105 1096
1106 if (RIO_INVALID_ROUTE == rswitch->route_table[destid]) { 1097 if (RIO_INVALID_ROUTE == rswitch->route_table[destid]) {
1098 swrdev = sw_to_rio_dev(rswitch);
1099
1107 /* Skip if destid ends in empty switch*/ 1100 /* Skip if destid ends in empty switch*/
1108 if (rswitch->destid == destid) 1101 if (swrdev->destid == destid)
1109 continue; 1102 continue;
1110 1103
1111 sport = rio_get_swpinfo_inport(port, 1104 sport = RIO_GET_PORT_NUM(swrdev->swpinfo);
1112 rswitch->destid, rswitch->hopcount);
1113 1105
1114 if (rswitch->add_entry) { 1106 if (rswitch->add_entry) {
1115 rio_route_add_entry(port, rswitch, 1107 rio_route_add_entry(swrdev,
1116 RIO_GLOBAL_TABLE, destid, 1108 RIO_GLOBAL_TABLE, destid,
1117 sport, 0); 1109 sport, 0);
1118 rswitch->route_table[destid] = sport; 1110 rswitch->route_table[destid] = sport;
@@ -1184,7 +1176,11 @@ int __devinit rio_enum_mport(struct rio_mport *mport)
1184 /* Enable Input Output Port (transmitter reviever) */ 1176 /* Enable Input Output Port (transmitter reviever) */
1185 rio_enable_rx_tx_port(mport, 1, 0, 0, 0); 1177 rio_enable_rx_tx_port(mport, 1, 0, 0, 0);
1186 1178
1187 if (rio_enum_peer(net, mport, 0) < 0) { 1179 /* Set component tag for host */
1180 rio_local_write_config_32(mport, RIO_COMPONENT_TAG_CSR,
1181 next_comptag++);
1182
1183 if (rio_enum_peer(net, mport, 0, NULL, 0) < 0) {
1188 /* A higher priority host won enumeration, bail. */ 1184 /* A higher priority host won enumeration, bail. */
1189 printk(KERN_INFO 1185 printk(KERN_INFO
1190 "RIO: master port %d device has lost enumeration to a remote host\n", 1186 "RIO: master port %d device has lost enumeration to a remote host\n",
@@ -1220,21 +1216,20 @@ static void rio_build_route_tables(void)
1220 1216
1221 list_for_each_entry(rdev, &rio_devices, global_list) 1217 list_for_each_entry(rdev, &rio_devices, global_list)
1222 if (rio_is_switch(rdev)) { 1218 if (rio_is_switch(rdev)) {
1223 rio_lock_device(rdev->net->hport, rdev->rswitch->destid, 1219 rio_lock_device(rdev->net->hport, rdev->destid,
1224 rdev->rswitch->hopcount, 1000); 1220 rdev->hopcount, 1000);
1225 for (i = 0; 1221 for (i = 0;
1226 i < RIO_MAX_ROUTE_ENTRIES(rdev->net->hport->sys_size); 1222 i < RIO_MAX_ROUTE_ENTRIES(rdev->net->hport->sys_size);
1227 i++) { 1223 i++) {
1228 if (rio_route_get_entry 1224 if (rio_route_get_entry(rdev,
1229 (rdev->net->hport, rdev->rswitch, 1225 RIO_GLOBAL_TABLE, i, &sport, 0) < 0)
1230 RIO_GLOBAL_TABLE, i, &sport, 0) < 0)
1231 continue; 1226 continue;
1232 rdev->rswitch->route_table[i] = sport; 1227 rdev->rswitch->route_table[i] = sport;
1233 } 1228 }
1234 1229
1235 rio_unlock_device(rdev->net->hport, 1230 rio_unlock_device(rdev->net->hport,
1236 rdev->rswitch->destid, 1231 rdev->destid,
1237 rdev->rswitch->hopcount); 1232 rdev->hopcount);
1238 } 1233 }
1239} 1234}
1240 1235
@@ -1301,7 +1296,7 @@ int __devinit rio_disc_mport(struct rio_mport *mport)
1301 mport->host_deviceid); 1296 mport->host_deviceid);
1302 1297
1303 if (rio_disc_peer(net, mport, RIO_ANY_DESTID(mport->sys_size), 1298 if (rio_disc_peer(net, mport, RIO_ANY_DESTID(mport->sys_size),
1304 0) < 0) { 1299 0, NULL, 0) < 0) {
1305 printk(KERN_INFO 1300 printk(KERN_INFO
1306 "RIO: master port %d device has failed discovery\n", 1301 "RIO: master port %d device has failed discovery\n",
1307 mport->id); 1302 mport->id);
diff --git a/drivers/rapidio/rio-sysfs.c b/drivers/rapidio/rio-sysfs.c
index 00b475658356..4dbe360989be 100644
--- a/drivers/rapidio/rio-sysfs.c
+++ b/drivers/rapidio/rio-sysfs.c
@@ -14,6 +14,7 @@
14#include <linux/rio.h> 14#include <linux/rio.h>
15#include <linux/rio_drv.h> 15#include <linux/rio_drv.h>
16#include <linux/stat.h> 16#include <linux/stat.h>
17#include <linux/capability.h>
17 18
18#include "rio.h" 19#include "rio.h"
19 20
@@ -33,6 +34,8 @@ rio_config_attr(device_rev, "0x%08x\n");
33rio_config_attr(asm_did, "0x%04x\n"); 34rio_config_attr(asm_did, "0x%04x\n");
34rio_config_attr(asm_vid, "0x%04x\n"); 35rio_config_attr(asm_vid, "0x%04x\n");
35rio_config_attr(asm_rev, "0x%04x\n"); 36rio_config_attr(asm_rev, "0x%04x\n");
37rio_config_attr(destid, "0x%04x\n");
38rio_config_attr(hopcount, "0x%02x\n");
36 39
37static ssize_t routes_show(struct device *dev, struct device_attribute *attr, char *buf) 40static ssize_t routes_show(struct device *dev, struct device_attribute *attr, char *buf)
38{ 41{
@@ -40,9 +43,6 @@ static ssize_t routes_show(struct device *dev, struct device_attribute *attr, ch
40 char *str = buf; 43 char *str = buf;
41 int i; 44 int i;
42 45
43 if (!rdev->rswitch)
44 goto out;
45
46 for (i = 0; i < RIO_MAX_ROUTE_ENTRIES(rdev->net->hport->sys_size); 46 for (i = 0; i < RIO_MAX_ROUTE_ENTRIES(rdev->net->hport->sys_size);
47 i++) { 47 i++) {
48 if (rdev->rswitch->route_table[i] == RIO_INVALID_ROUTE) 48 if (rdev->rswitch->route_table[i] == RIO_INVALID_ROUTE)
@@ -52,10 +52,38 @@ static ssize_t routes_show(struct device *dev, struct device_attribute *attr, ch
52 rdev->rswitch->route_table[i]); 52 rdev->rswitch->route_table[i]);
53 } 53 }
54 54
55 out:
56 return (str - buf); 55 return (str - buf);
57} 56}
58 57
58static ssize_t lprev_show(struct device *dev,
59 struct device_attribute *attr, char *buf)
60{
61 struct rio_dev *rdev = to_rio_dev(dev);
62
63 return sprintf(buf, "%s\n",
64 (rdev->prev) ? rio_name(rdev->prev) : "root");
65}
66
67static ssize_t lnext_show(struct device *dev,
68 struct device_attribute *attr, char *buf)
69{
70 struct rio_dev *rdev = to_rio_dev(dev);
71 char *str = buf;
72 int i;
73
74 if (rdev->pef & RIO_PEF_SWITCH) {
75 for (i = 0; i < RIO_GET_TOTAL_PORTS(rdev->swpinfo); i++) {
76 if (rdev->rswitch->nextdev[i])
77 str += sprintf(str, "%s\n",
78 rio_name(rdev->rswitch->nextdev[i]));
79 else
80 str += sprintf(str, "null\n");
81 }
82 }
83
84 return str - buf;
85}
86
59struct device_attribute rio_dev_attrs[] = { 87struct device_attribute rio_dev_attrs[] = {
60 __ATTR_RO(did), 88 __ATTR_RO(did),
61 __ATTR_RO(vid), 89 __ATTR_RO(vid),
@@ -63,10 +91,15 @@ struct device_attribute rio_dev_attrs[] = {
63 __ATTR_RO(asm_did), 91 __ATTR_RO(asm_did),
64 __ATTR_RO(asm_vid), 92 __ATTR_RO(asm_vid),
65 __ATTR_RO(asm_rev), 93 __ATTR_RO(asm_rev),
66 __ATTR_RO(routes), 94 __ATTR_RO(lprev),
95 __ATTR_RO(destid),
67 __ATTR_NULL, 96 __ATTR_NULL,
68}; 97};
69 98
99static DEVICE_ATTR(routes, S_IRUGO, routes_show, NULL);
100static DEVICE_ATTR(lnext, S_IRUGO, lnext_show, NULL);
101static DEVICE_ATTR(hopcount, S_IRUGO, hopcount_show, NULL);
102
70static ssize_t 103static ssize_t
71rio_read_config(struct file *filp, struct kobject *kobj, 104rio_read_config(struct file *filp, struct kobject *kobj,
72 struct bin_attribute *bin_attr, 105 struct bin_attribute *bin_attr,
@@ -80,9 +113,9 @@ rio_read_config(struct file *filp, struct kobject *kobj,
80 113
81 /* Several chips lock up trying to read undefined config space */ 114 /* Several chips lock up trying to read undefined config space */
82 if (capable(CAP_SYS_ADMIN)) 115 if (capable(CAP_SYS_ADMIN))
83 size = 0x200000; 116 size = RIO_MAINT_SPACE_SZ;
84 117
85 if (off > size) 118 if (off >= size)
86 return 0; 119 return 0;
87 if (off + count > size) { 120 if (off + count > size) {
88 size -= off; 121 size -= off;
@@ -150,10 +183,10 @@ rio_write_config(struct file *filp, struct kobject *kobj,
150 loff_t init_off = off; 183 loff_t init_off = off;
151 u8 *data = (u8 *) buf; 184 u8 *data = (u8 *) buf;
152 185
153 if (off > 0x200000) 186 if (off >= RIO_MAINT_SPACE_SZ)
154 return 0; 187 return 0;
155 if (off + count > 0x200000) { 188 if (off + count > RIO_MAINT_SPACE_SZ) {
156 size = 0x200000 - off; 189 size = RIO_MAINT_SPACE_SZ - off;
157 count = size; 190 count = size;
158 } 191 }
159 192
@@ -203,7 +236,7 @@ static struct bin_attribute rio_config_attr = {
203 .name = "config", 236 .name = "config",
204 .mode = S_IRUGO | S_IWUSR, 237 .mode = S_IRUGO | S_IWUSR,
205 }, 238 },
206 .size = 0x200000, 239 .size = RIO_MAINT_SPACE_SZ,
207 .read = rio_read_config, 240 .read = rio_read_config,
208 .write = rio_write_config, 241 .write = rio_write_config,
209}; 242};
@@ -218,7 +251,19 @@ int rio_create_sysfs_dev_files(struct rio_dev *rdev)
218{ 251{
219 int err = 0; 252 int err = 0;
220 253
221 err = sysfs_create_bin_file(&rdev->dev.kobj, &rio_config_attr); 254 err = device_create_bin_file(&rdev->dev, &rio_config_attr);
255
256 if (!err && (rdev->pef & RIO_PEF_SWITCH)) {
257 err |= device_create_file(&rdev->dev, &dev_attr_routes);
258 err |= device_create_file(&rdev->dev, &dev_attr_lnext);
259 err |= device_create_file(&rdev->dev, &dev_attr_hopcount);
260 if (!err && rdev->rswitch->sw_sysfs)
261 err = rdev->rswitch->sw_sysfs(rdev, RIO_SW_SYSFS_CREATE);
262 }
263
264 if (err)
265 pr_warning("RIO: Failed to create attribute file(s) for %s\n",
266 rio_name(rdev));
222 267
223 return err; 268 return err;
224} 269}
@@ -231,5 +276,12 @@ int rio_create_sysfs_dev_files(struct rio_dev *rdev)
231 */ 276 */
232void rio_remove_sysfs_dev_files(struct rio_dev *rdev) 277void rio_remove_sysfs_dev_files(struct rio_dev *rdev)
233{ 278{
234 sysfs_remove_bin_file(&rdev->dev.kobj, &rio_config_attr); 279 device_remove_bin_file(&rdev->dev, &rio_config_attr);
280 if (rdev->pef & RIO_PEF_SWITCH) {
281 device_remove_file(&rdev->dev, &dev_attr_routes);
282 device_remove_file(&rdev->dev, &dev_attr_lnext);
283 device_remove_file(&rdev->dev, &dev_attr_hopcount);
284 if (rdev->rswitch->sw_sysfs)
285 rdev->rswitch->sw_sysfs(rdev, RIO_SW_SYSFS_REMOVE);
286 }
235} 287}
diff --git a/drivers/rapidio/rio.c b/drivers/rapidio/rio.c
index 74e9d22d95fb..86c9a091a2ff 100644
--- a/drivers/rapidio/rio.c
+++ b/drivers/rapidio/rio.c
@@ -32,6 +32,7 @@
32#include "rio.h" 32#include "rio.h"
33 33
34static LIST_HEAD(rio_mports); 34static LIST_HEAD(rio_mports);
35static unsigned char next_portid;
35 36
36/** 37/**
37 * rio_local_get_device_id - Get the base/extended device id for a port 38 * rio_local_get_device_id - Get the base/extended device id for a port
@@ -68,9 +69,13 @@ int rio_request_inb_mbox(struct rio_mport *mport,
68 void (*minb) (struct rio_mport * mport, void *dev_id, int mbox, 69 void (*minb) (struct rio_mport * mport, void *dev_id, int mbox,
69 int slot)) 70 int slot))
70{ 71{
71 int rc = 0; 72 int rc = -ENOSYS;
73 struct resource *res;
72 74
73 struct resource *res = kmalloc(sizeof(struct resource), GFP_KERNEL); 75 if (mport->ops->open_inb_mbox == NULL)
76 goto out;
77
78 res = kmalloc(sizeof(struct resource), GFP_KERNEL);
74 79
75 if (res) { 80 if (res) {
76 rio_init_mbox_res(res, mbox, mbox); 81 rio_init_mbox_res(res, mbox, mbox);
@@ -88,7 +93,7 @@ int rio_request_inb_mbox(struct rio_mport *mport,
88 /* Hook the inbound message callback */ 93 /* Hook the inbound message callback */
89 mport->inb_msg[mbox].mcback = minb; 94 mport->inb_msg[mbox].mcback = minb;
90 95
91 rc = rio_open_inb_mbox(mport, dev_id, mbox, entries); 96 rc = mport->ops->open_inb_mbox(mport, dev_id, mbox, entries);
92 } else 97 } else
93 rc = -ENOMEM; 98 rc = -ENOMEM;
94 99
@@ -106,10 +111,13 @@ int rio_request_inb_mbox(struct rio_mport *mport,
106 */ 111 */
107int rio_release_inb_mbox(struct rio_mport *mport, int mbox) 112int rio_release_inb_mbox(struct rio_mport *mport, int mbox)
108{ 113{
109 rio_close_inb_mbox(mport, mbox); 114 if (mport->ops->close_inb_mbox) {
115 mport->ops->close_inb_mbox(mport, mbox);
110 116
111 /* Release the mailbox resource */ 117 /* Release the mailbox resource */
112 return release_resource(mport->inb_msg[mbox].res); 118 return release_resource(mport->inb_msg[mbox].res);
119 } else
120 return -ENOSYS;
113} 121}
114 122
115/** 123/**
@@ -129,9 +137,13 @@ int rio_request_outb_mbox(struct rio_mport *mport,
129 int entries, 137 int entries,
130 void (*moutb) (struct rio_mport * mport, void *dev_id, int mbox, int slot)) 138 void (*moutb) (struct rio_mport * mport, void *dev_id, int mbox, int slot))
131{ 139{
132 int rc = 0; 140 int rc = -ENOSYS;
141 struct resource *res;
133 142
134 struct resource *res = kmalloc(sizeof(struct resource), GFP_KERNEL); 143 if (mport->ops->open_outb_mbox == NULL)
144 goto out;
145
146 res = kmalloc(sizeof(struct resource), GFP_KERNEL);
135 147
136 if (res) { 148 if (res) {
137 rio_init_mbox_res(res, mbox, mbox); 149 rio_init_mbox_res(res, mbox, mbox);
@@ -149,7 +161,7 @@ int rio_request_outb_mbox(struct rio_mport *mport,
149 /* Hook the inbound message callback */ 161 /* Hook the inbound message callback */
150 mport->outb_msg[mbox].mcback = moutb; 162 mport->outb_msg[mbox].mcback = moutb;
151 163
152 rc = rio_open_outb_mbox(mport, dev_id, mbox, entries); 164 rc = mport->ops->open_outb_mbox(mport, dev_id, mbox, entries);
153 } else 165 } else
154 rc = -ENOMEM; 166 rc = -ENOMEM;
155 167
@@ -167,10 +179,13 @@ int rio_request_outb_mbox(struct rio_mport *mport,
167 */ 179 */
168int rio_release_outb_mbox(struct rio_mport *mport, int mbox) 180int rio_release_outb_mbox(struct rio_mport *mport, int mbox)
169{ 181{
170 rio_close_outb_mbox(mport, mbox); 182 if (mport->ops->close_outb_mbox) {
183 mport->ops->close_outb_mbox(mport, mbox);
171 184
172 /* Release the mailbox resource */ 185 /* Release the mailbox resource */
173 return release_resource(mport->outb_msg[mbox].res); 186 return release_resource(mport->outb_msg[mbox].res);
187 } else
188 return -ENOSYS;
174} 189}
175 190
176/** 191/**
@@ -443,7 +458,7 @@ rio_mport_get_physefb(struct rio_mport *port, int local,
443 * @from is not %NULL, searches continue from next device on the global 458 * @from is not %NULL, searches continue from next device on the global
444 * list. 459 * list.
445 */ 460 */
446static struct rio_dev *rio_get_comptag(u32 comp_tag, struct rio_dev *from) 461struct rio_dev *rio_get_comptag(u32 comp_tag, struct rio_dev *from)
447{ 462{
448 struct list_head *n; 463 struct list_head *n;
449 struct rio_dev *rdev; 464 struct rio_dev *rdev;
@@ -471,16 +486,9 @@ exit:
471 */ 486 */
472int rio_set_port_lockout(struct rio_dev *rdev, u32 pnum, int lock) 487int rio_set_port_lockout(struct rio_dev *rdev, u32 pnum, int lock)
473{ 488{
474 u8 hopcount = 0xff;
475 u16 destid = rdev->destid;
476 u32 regval; 489 u32 regval;
477 490
478 if (rdev->rswitch) { 491 rio_read_config_32(rdev,
479 destid = rdev->rswitch->destid;
480 hopcount = rdev->rswitch->hopcount;
481 }
482
483 rio_mport_read_config_32(rdev->net->hport, destid, hopcount,
484 rdev->phys_efptr + RIO_PORT_N_CTL_CSR(pnum), 492 rdev->phys_efptr + RIO_PORT_N_CTL_CSR(pnum),
485 &regval); 493 &regval);
486 if (lock) 494 if (lock)
@@ -488,13 +496,223 @@ int rio_set_port_lockout(struct rio_dev *rdev, u32 pnum, int lock)
488 else 496 else
489 regval &= ~RIO_PORT_N_CTL_LOCKOUT; 497 regval &= ~RIO_PORT_N_CTL_LOCKOUT;
490 498
491 rio_mport_write_config_32(rdev->net->hport, destid, hopcount, 499 rio_write_config_32(rdev,
492 rdev->phys_efptr + RIO_PORT_N_CTL_CSR(pnum), 500 rdev->phys_efptr + RIO_PORT_N_CTL_CSR(pnum),
493 regval); 501 regval);
494 return 0; 502 return 0;
495} 503}
496 504
497/** 505/**
506 * rio_chk_dev_route - Validate route to the specified device.
507 * @rdev: RIO device failed to respond
508 * @nrdev: Last active device on the route to rdev
509 * @npnum: nrdev's port number on the route to rdev
510 *
511 * Follows a route to the specified RIO device to determine the last available
512 * device (and corresponding RIO port) on the route.
513 */
514static int
515rio_chk_dev_route(struct rio_dev *rdev, struct rio_dev **nrdev, int *npnum)
516{
517 u32 result;
518 int p_port, rc = -EIO;
519 struct rio_dev *prev = NULL;
520
521 /* Find switch with failed RIO link */
522 while (rdev->prev && (rdev->prev->pef & RIO_PEF_SWITCH)) {
523 if (!rio_read_config_32(rdev->prev, RIO_DEV_ID_CAR, &result)) {
524 prev = rdev->prev;
525 break;
526 }
527 rdev = rdev->prev;
528 }
529
530 if (prev == NULL)
531 goto err_out;
532
533 p_port = prev->rswitch->route_table[rdev->destid];
534
535 if (p_port != RIO_INVALID_ROUTE) {
536 pr_debug("RIO: link failed on [%s]-P%d\n",
537 rio_name(prev), p_port);
538 *nrdev = prev;
539 *npnum = p_port;
540 rc = 0;
541 } else
542 pr_debug("RIO: failed to trace route to %s\n", rio_name(rdev));
543err_out:
544 return rc;
545}
546
547/**
548 * rio_mport_chk_dev_access - Validate access to the specified device.
549 * @mport: Master port to send transactions
550 * @destid: Device destination ID in network
551 * @hopcount: Number of hops into the network
552 */
553int
554rio_mport_chk_dev_access(struct rio_mport *mport, u16 destid, u8 hopcount)
555{
556 int i = 0;
557 u32 tmp;
558
559 while (rio_mport_read_config_32(mport, destid, hopcount,
560 RIO_DEV_ID_CAR, &tmp)) {
561 i++;
562 if (i == RIO_MAX_CHK_RETRY)
563 return -EIO;
564 mdelay(1);
565 }
566
567 return 0;
568}
569
570/**
571 * rio_chk_dev_access - Validate access to the specified device.
572 * @rdev: Pointer to RIO device control structure
573 */
574static int rio_chk_dev_access(struct rio_dev *rdev)
575{
576 return rio_mport_chk_dev_access(rdev->net->hport,
577 rdev->destid, rdev->hopcount);
578}
579
580/**
581 * rio_get_input_status - Sends a Link-Request/Input-Status control symbol and
582 * returns link-response (if requested).
583 * @rdev: RIO devive to issue Input-status command
584 * @pnum: Device port number to issue the command
585 * @lnkresp: Response from a link partner
586 */
587static int
588rio_get_input_status(struct rio_dev *rdev, int pnum, u32 *lnkresp)
589{
590 u32 regval;
591 int checkcount;
592
593 if (lnkresp) {
594 /* Read from link maintenance response register
595 * to clear valid bit */
596 rio_read_config_32(rdev,
597 rdev->phys_efptr + RIO_PORT_N_MNT_RSP_CSR(pnum),
598 &regval);
599 udelay(50);
600 }
601
602 /* Issue Input-status command */
603 rio_write_config_32(rdev,
604 rdev->phys_efptr + RIO_PORT_N_MNT_REQ_CSR(pnum),
605 RIO_MNT_REQ_CMD_IS);
606
607 /* Exit if the response is not expected */
608 if (lnkresp == NULL)
609 return 0;
610
611 checkcount = 3;
612 while (checkcount--) {
613 udelay(50);
614 rio_read_config_32(rdev,
615 rdev->phys_efptr + RIO_PORT_N_MNT_RSP_CSR(pnum),
616 &regval);
617 if (regval & RIO_PORT_N_MNT_RSP_RVAL) {
618 *lnkresp = regval;
619 return 0;
620 }
621 }
622
623 return -EIO;
624}
625
626/**
627 * rio_clr_err_stopped - Clears port Error-stopped states.
628 * @rdev: Pointer to RIO device control structure
629 * @pnum: Switch port number to clear errors
630 * @err_status: port error status (if 0 reads register from device)
631 */
632static int rio_clr_err_stopped(struct rio_dev *rdev, u32 pnum, u32 err_status)
633{
634 struct rio_dev *nextdev = rdev->rswitch->nextdev[pnum];
635 u32 regval;
636 u32 far_ackid, far_linkstat, near_ackid;
637
638 if (err_status == 0)
639 rio_read_config_32(rdev,
640 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(pnum),
641 &err_status);
642
643 if (err_status & RIO_PORT_N_ERR_STS_PW_OUT_ES) {
644 pr_debug("RIO_EM: servicing Output Error-Stopped state\n");
645 /*
646 * Send a Link-Request/Input-Status control symbol
647 */
648 if (rio_get_input_status(rdev, pnum, &regval)) {
649 pr_debug("RIO_EM: Input-status response timeout\n");
650 goto rd_err;
651 }
652
653 pr_debug("RIO_EM: SP%d Input-status response=0x%08x\n",
654 pnum, regval);
655 far_ackid = (regval & RIO_PORT_N_MNT_RSP_ASTAT) >> 5;
656 far_linkstat = regval & RIO_PORT_N_MNT_RSP_LSTAT;
657 rio_read_config_32(rdev,
658 rdev->phys_efptr + RIO_PORT_N_ACK_STS_CSR(pnum),
659 &regval);
660 pr_debug("RIO_EM: SP%d_ACK_STS_CSR=0x%08x\n", pnum, regval);
661 near_ackid = (regval & RIO_PORT_N_ACK_INBOUND) >> 24;
662 pr_debug("RIO_EM: SP%d far_ackID=0x%02x far_linkstat=0x%02x" \
663 " near_ackID=0x%02x\n",
664 pnum, far_ackid, far_linkstat, near_ackid);
665
666 /*
667 * If required, synchronize ackIDs of near and
668 * far sides.
669 */
670 if ((far_ackid != ((regval & RIO_PORT_N_ACK_OUTSTAND) >> 8)) ||
671 (far_ackid != (regval & RIO_PORT_N_ACK_OUTBOUND))) {
672 /* Align near outstanding/outbound ackIDs with
673 * far inbound.
674 */
675 rio_write_config_32(rdev,
676 rdev->phys_efptr + RIO_PORT_N_ACK_STS_CSR(pnum),
677 (near_ackid << 24) |
678 (far_ackid << 8) | far_ackid);
679 /* Align far outstanding/outbound ackIDs with
680 * near inbound.
681 */
682 far_ackid++;
683 if (nextdev)
684 rio_write_config_32(nextdev,
685 nextdev->phys_efptr +
686 RIO_PORT_N_ACK_STS_CSR(RIO_GET_PORT_NUM(nextdev->swpinfo)),
687 (far_ackid << 24) |
688 (near_ackid << 8) | near_ackid);
689 else
690 pr_debug("RIO_EM: Invalid nextdev pointer (NULL)\n");
691 }
692rd_err:
693 rio_read_config_32(rdev,
694 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(pnum),
695 &err_status);
696 pr_debug("RIO_EM: SP%d_ERR_STS_CSR=0x%08x\n", pnum, err_status);
697 }
698
699 if ((err_status & RIO_PORT_N_ERR_STS_PW_INP_ES) && nextdev) {
700 pr_debug("RIO_EM: servicing Input Error-Stopped state\n");
701 rio_get_input_status(nextdev,
702 RIO_GET_PORT_NUM(nextdev->swpinfo), NULL);
703 udelay(50);
704
705 rio_read_config_32(rdev,
706 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(pnum),
707 &err_status);
708 pr_debug("RIO_EM: SP%d_ERR_STS_CSR=0x%08x\n", pnum, err_status);
709 }
710
711 return (err_status & (RIO_PORT_N_ERR_STS_PW_OUT_ES |
712 RIO_PORT_N_ERR_STS_PW_INP_ES)) ? 1 : 0;
713}
714
715/**
498 * rio_inb_pwrite_handler - process inbound port-write message 716 * rio_inb_pwrite_handler - process inbound port-write message
499 * @pw_msg: pointer to inbound port-write message 717 * @pw_msg: pointer to inbound port-write message
500 * 718 *
@@ -504,16 +722,13 @@ int rio_set_port_lockout(struct rio_dev *rdev, u32 pnum, int lock)
504int rio_inb_pwrite_handler(union rio_pw_msg *pw_msg) 722int rio_inb_pwrite_handler(union rio_pw_msg *pw_msg)
505{ 723{
506 struct rio_dev *rdev; 724 struct rio_dev *rdev;
507 struct rio_mport *mport; 725 u32 err_status, em_perrdet, em_ltlerrdet;
508 u8 hopcount;
509 u16 destid;
510 u32 err_status;
511 int rc, portnum; 726 int rc, portnum;
512 727
513 rdev = rio_get_comptag(pw_msg->em.comptag, NULL); 728 rdev = rio_get_comptag((pw_msg->em.comptag & RIO_CTAG_UDEVID), NULL);
514 if (rdev == NULL) { 729 if (rdev == NULL) {
515 /* Someting bad here (probably enumeration error) */ 730 /* Device removed or enumeration error */
516 pr_err("RIO: %s No matching device for CTag 0x%08x\n", 731 pr_debug("RIO: %s No matching device for CTag 0x%08x\n",
517 __func__, pw_msg->em.comptag); 732 __func__, pw_msg->em.comptag);
518 return -EIO; 733 return -EIO;
519 } 734 }
@@ -524,12 +739,11 @@ int rio_inb_pwrite_handler(union rio_pw_msg *pw_msg)
524 { 739 {
525 u32 i; 740 u32 i;
526 for (i = 0; i < RIO_PW_MSG_SIZE/sizeof(u32);) { 741 for (i = 0; i < RIO_PW_MSG_SIZE/sizeof(u32);) {
527 pr_debug("0x%02x: %08x %08x %08x %08x", 742 pr_debug("0x%02x: %08x %08x %08x %08x\n",
528 i*4, pw_msg->raw[i], pw_msg->raw[i + 1], 743 i*4, pw_msg->raw[i], pw_msg->raw[i + 1],
529 pw_msg->raw[i + 2], pw_msg->raw[i + 3]); 744 pw_msg->raw[i + 2], pw_msg->raw[i + 3]);
530 i += 4; 745 i += 4;
531 } 746 }
532 pr_debug("\n");
533 } 747 }
534#endif 748#endif
535 749
@@ -545,6 +759,26 @@ int rio_inb_pwrite_handler(union rio_pw_msg *pw_msg)
545 return 0; 759 return 0;
546 } 760 }
547 761
762 portnum = pw_msg->em.is_port & 0xFF;
763
764 /* Check if device and route to it are functional:
765 * Sometimes devices may send PW message(s) just before being
766 * powered down (or link being lost).
767 */
768 if (rio_chk_dev_access(rdev)) {
769 pr_debug("RIO: device access failed - get link partner\n");
770 /* Scan route to the device and identify failed link.
771 * This will replace device and port reported in PW message.
772 * PW message should not be used after this point.
773 */
774 if (rio_chk_dev_route(rdev, &rdev, &portnum)) {
775 pr_err("RIO: Route trace for %s failed\n",
776 rio_name(rdev));
777 return -EIO;
778 }
779 pw_msg = NULL;
780 }
781
548 /* For End-point devices processing stops here */ 782 /* For End-point devices processing stops here */
549 if (!(rdev->pef & RIO_PEF_SWITCH)) 783 if (!(rdev->pef & RIO_PEF_SWITCH))
550 return 0; 784 return 0;
@@ -555,51 +789,43 @@ int rio_inb_pwrite_handler(union rio_pw_msg *pw_msg)
555 return 0; 789 return 0;
556 } 790 }
557 791
558 mport = rdev->net->hport;
559 destid = rdev->rswitch->destid;
560 hopcount = rdev->rswitch->hopcount;
561
562 /* 792 /*
563 * Process the port-write notification from switch 793 * Process the port-write notification from switch
564 */ 794 */
565
566 portnum = pw_msg->em.is_port & 0xFF;
567
568 if (rdev->rswitch->em_handle) 795 if (rdev->rswitch->em_handle)
569 rdev->rswitch->em_handle(rdev, portnum); 796 rdev->rswitch->em_handle(rdev, portnum);
570 797
571 rio_mport_read_config_32(mport, destid, hopcount, 798 rio_read_config_32(rdev,
572 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum), 799 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum),
573 &err_status); 800 &err_status);
574 pr_debug("RIO_PW: SP%d_ERR_STS_CSR=0x%08x\n", portnum, err_status); 801 pr_debug("RIO_PW: SP%d_ERR_STS_CSR=0x%08x\n", portnum, err_status);
575 802
576 if (pw_msg->em.errdetect) { 803 if (err_status & RIO_PORT_N_ERR_STS_PORT_OK) {
577 pr_debug("RIO_PW: RIO_EM_P%d_ERR_DETECT=0x%08x\n",
578 portnum, pw_msg->em.errdetect);
579 /* Clear EM Port N Error Detect CSR */
580 rio_mport_write_config_32(mport, destid, hopcount,
581 rdev->em_efptr + RIO_EM_PN_ERR_DETECT(portnum), 0);
582 }
583 804
584 if (pw_msg->em.ltlerrdet) { 805 if (!(rdev->rswitch->port_ok & (1 << portnum))) {
585 pr_debug("RIO_PW: RIO_EM_LTL_ERR_DETECT=0x%08x\n", 806 rdev->rswitch->port_ok |= (1 << portnum);
586 pw_msg->em.ltlerrdet); 807 rio_set_port_lockout(rdev, portnum, 0);
587 /* Clear EM L/T Layer Error Detect CSR */ 808 /* Schedule Insertion Service */
588 rio_mport_write_config_32(mport, destid, hopcount, 809 pr_debug("RIO_PW: Device Insertion on [%s]-P%d\n",
589 rdev->em_efptr + RIO_EM_LTL_ERR_DETECT, 0); 810 rio_name(rdev), portnum);
590 } 811 }
591 812
592 /* Clear Port Errors */ 813 /* Clear error-stopped states (if reported).
593 rio_mport_write_config_32(mport, destid, hopcount, 814 * Depending on the link partner state, two attempts
594 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum), 815 * may be needed for successful recovery.
595 err_status & RIO_PORT_N_ERR_STS_CLR_MASK); 816 */
817 if (err_status & (RIO_PORT_N_ERR_STS_PW_OUT_ES |
818 RIO_PORT_N_ERR_STS_PW_INP_ES)) {
819 if (rio_clr_err_stopped(rdev, portnum, err_status))
820 rio_clr_err_stopped(rdev, portnum, 0);
821 }
822 } else { /* if (err_status & RIO_PORT_N_ERR_STS_PORT_UNINIT) */
596 823
597 if (rdev->rswitch->port_ok & (1 << portnum)) { 824 if (rdev->rswitch->port_ok & (1 << portnum)) {
598 if (err_status & RIO_PORT_N_ERR_STS_PORT_UNINIT) {
599 rdev->rswitch->port_ok &= ~(1 << portnum); 825 rdev->rswitch->port_ok &= ~(1 << portnum);
600 rio_set_port_lockout(rdev, portnum, 1); 826 rio_set_port_lockout(rdev, portnum, 1);
601 827
602 rio_mport_write_config_32(mport, destid, hopcount, 828 rio_write_config_32(rdev,
603 rdev->phys_efptr + 829 rdev->phys_efptr +
604 RIO_PORT_N_ACK_STS_CSR(portnum), 830 RIO_PORT_N_ACK_STS_CSR(portnum),
605 RIO_PORT_N_ACK_CLEAR); 831 RIO_PORT_N_ACK_CLEAR);
@@ -608,21 +834,32 @@ int rio_inb_pwrite_handler(union rio_pw_msg *pw_msg)
608 pr_debug("RIO_PW: Device Extraction on [%s]-P%d\n", 834 pr_debug("RIO_PW: Device Extraction on [%s]-P%d\n",
609 rio_name(rdev), portnum); 835 rio_name(rdev), portnum);
610 } 836 }
611 } else { 837 }
612 if (err_status & RIO_PORT_N_ERR_STS_PORT_OK) {
613 rdev->rswitch->port_ok |= (1 << portnum);
614 rio_set_port_lockout(rdev, portnum, 0);
615 838
616 /* Schedule Insertion Service */ 839 rio_read_config_32(rdev,
617 pr_debug("RIO_PW: Device Insertion on [%s]-P%d\n", 840 rdev->em_efptr + RIO_EM_PN_ERR_DETECT(portnum), &em_perrdet);
618 rio_name(rdev), portnum); 841 if (em_perrdet) {
619 } 842 pr_debug("RIO_PW: RIO_EM_P%d_ERR_DETECT=0x%08x\n",
843 portnum, em_perrdet);
844 /* Clear EM Port N Error Detect CSR */
845 rio_write_config_32(rdev,
846 rdev->em_efptr + RIO_EM_PN_ERR_DETECT(portnum), 0);
620 } 847 }
621 848
622 /* Clear Port-Write Pending bit */ 849 rio_read_config_32(rdev,
623 rio_mport_write_config_32(mport, destid, hopcount, 850 rdev->em_efptr + RIO_EM_LTL_ERR_DETECT, &em_ltlerrdet);
851 if (em_ltlerrdet) {
852 pr_debug("RIO_PW: RIO_EM_LTL_ERR_DETECT=0x%08x\n",
853 em_ltlerrdet);
854 /* Clear EM L/T Layer Error Detect CSR */
855 rio_write_config_32(rdev,
856 rdev->em_efptr + RIO_EM_LTL_ERR_DETECT, 0);
857 }
858
859 /* Clear remaining error bits and Port-Write Pending bit */
860 rio_write_config_32(rdev,
624 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum), 861 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum),
625 RIO_PORT_N_ERR_STS_PW_PEND); 862 err_status);
626 863
627 return 0; 864 return 0;
628} 865}
@@ -898,37 +1135,53 @@ static int __devinit rio_init(void)
898 return 0; 1135 return 0;
899} 1136}
900 1137
901device_initcall(rio_init);
902
903int __devinit rio_init_mports(void) 1138int __devinit rio_init_mports(void)
904{ 1139{
905 int rc = 0;
906 struct rio_mport *port; 1140 struct rio_mport *port;
907 1141
908 list_for_each_entry(port, &rio_mports, node) { 1142 list_for_each_entry(port, &rio_mports, node) {
909 if (!request_mem_region(port->iores.start,
910 port->iores.end - port->iores.start,
911 port->name)) {
912 printk(KERN_ERR
913 "RIO: Error requesting master port region 0x%016llx-0x%016llx\n",
914 (u64)port->iores.start, (u64)port->iores.end - 1);
915 rc = -ENOMEM;
916 goto out;
917 }
918
919 if (port->host_deviceid >= 0) 1143 if (port->host_deviceid >= 0)
920 rio_enum_mport(port); 1144 rio_enum_mport(port);
921 else 1145 else
922 rio_disc_mport(port); 1146 rio_disc_mport(port);
923 } 1147 }
924 1148
925 out: 1149 rio_init();
926 return rc; 1150
1151 return 0;
1152}
1153
1154device_initcall_sync(rio_init_mports);
1155
1156static int hdids[RIO_MAX_MPORTS + 1];
1157
1158static int rio_get_hdid(int index)
1159{
1160 if (!hdids[0] || hdids[0] <= index || index >= RIO_MAX_MPORTS)
1161 return -1;
1162
1163 return hdids[index + 1];
927} 1164}
928 1165
929void rio_register_mport(struct rio_mport *port) 1166static int rio_hdid_setup(char *str)
930{ 1167{
1168 (void)get_options(str, ARRAY_SIZE(hdids), hdids);
1169 return 1;
1170}
1171
1172__setup("riohdid=", rio_hdid_setup);
1173
1174int rio_register_mport(struct rio_mport *port)
1175{
1176 if (next_portid >= RIO_MAX_MPORTS) {
1177 pr_err("RIO: reached specified max number of mports\n");
1178 return 1;
1179 }
1180
1181 port->id = next_portid++;
1182 port->host_deviceid = rio_get_hdid(port->id);
931 list_add_tail(&port->node, &rio_mports); 1183 list_add_tail(&port->node, &rio_mports);
1184 return 0;
932} 1185}
933 1186
934EXPORT_SYMBOL_GPL(rio_local_get_device_id); 1187EXPORT_SYMBOL_GPL(rio_local_get_device_id);
diff --git a/drivers/rapidio/rio.h b/drivers/rapidio/rio.h
index f27b7a9c47d2..b1af414f15e6 100644
--- a/drivers/rapidio/rio.h
+++ b/drivers/rapidio/rio.h
@@ -14,6 +14,8 @@
14#include <linux/list.h> 14#include <linux/list.h>
15#include <linux/rio.h> 15#include <linux/rio.h>
16 16
17#define RIO_MAX_CHK_RETRY 3
18
17/* Functions internal to the RIO core code */ 19/* Functions internal to the RIO core code */
18 20
19extern u32 rio_mport_get_feature(struct rio_mport *mport, int local, u16 destid, 21extern u32 rio_mport_get_feature(struct rio_mport *mport, int local, u16 destid,
@@ -22,6 +24,8 @@ extern u32 rio_mport_get_physefb(struct rio_mport *port, int local,
22 u16 destid, u8 hopcount); 24 u16 destid, u8 hopcount);
23extern u32 rio_mport_get_efb(struct rio_mport *port, int local, u16 destid, 25extern u32 rio_mport_get_efb(struct rio_mport *port, int local, u16 destid,
24 u8 hopcount, u32 from); 26 u8 hopcount, u32 from);
27extern int rio_mport_chk_dev_access(struct rio_mport *mport, u16 destid,
28 u8 hopcount);
25extern int rio_create_sysfs_dev_files(struct rio_dev *rdev); 29extern int rio_create_sysfs_dev_files(struct rio_dev *rdev);
26extern int rio_enum_mport(struct rio_mport *mport); 30extern int rio_enum_mport(struct rio_mport *mport);
27extern int rio_disc_mport(struct rio_mport *mport); 31extern int rio_disc_mport(struct rio_mport *mport);
@@ -34,6 +38,7 @@ extern int rio_std_route_get_entry(struct rio_mport *mport, u16 destid,
34extern int rio_std_route_clr_table(struct rio_mport *mport, u16 destid, 38extern int rio_std_route_clr_table(struct rio_mport *mport, u16 destid,
35 u8 hopcount, u16 table); 39 u8 hopcount, u16 table);
36extern int rio_set_port_lockout(struct rio_dev *rdev, u32 pnum, int lock); 40extern int rio_set_port_lockout(struct rio_dev *rdev, u32 pnum, int lock);
41extern struct rio_dev *rio_get_comptag(u32 comp_tag, struct rio_dev *from);
37 42
38/* Structures internal to the RIO core code */ 43/* Structures internal to the RIO core code */
39extern struct device_attribute rio_dev_attrs[]; 44extern struct device_attribute rio_dev_attrs[];
diff --git a/drivers/rapidio/switches/Kconfig b/drivers/rapidio/switches/Kconfig
index 2b4e9b2b6631..f47fee5d4563 100644
--- a/drivers/rapidio/switches/Kconfig
+++ b/drivers/rapidio/switches/Kconfig
@@ -20,6 +20,13 @@ config RAPIDIO_TSI568
20 ---help--- 20 ---help---
21 Includes support for IDT Tsi568 serial RapidIO switch. 21 Includes support for IDT Tsi568 serial RapidIO switch.
22 22
23config RAPIDIO_CPS_GEN2
24 bool "IDT CPS Gen.2 SRIO switch support"
25 depends on RAPIDIO
26 default n
27 ---help---
28 Includes support for ITD CPS Gen.2 serial RapidIO switches.
29
23config RAPIDIO_TSI500 30config RAPIDIO_TSI500
24 bool "Tsi500 Parallel RapidIO switch support" 31 bool "Tsi500 Parallel RapidIO switch support"
25 depends on RAPIDIO 32 depends on RAPIDIO
diff --git a/drivers/rapidio/switches/Makefile b/drivers/rapidio/switches/Makefile
index fe4adc3e8d5f..c4d3acc3c715 100644
--- a/drivers/rapidio/switches/Makefile
+++ b/drivers/rapidio/switches/Makefile
@@ -6,7 +6,4 @@ obj-$(CONFIG_RAPIDIO_TSI57X) += tsi57x.o
6obj-$(CONFIG_RAPIDIO_CPS_XX) += idtcps.o 6obj-$(CONFIG_RAPIDIO_CPS_XX) += idtcps.o
7obj-$(CONFIG_RAPIDIO_TSI568) += tsi568.o 7obj-$(CONFIG_RAPIDIO_TSI568) += tsi568.o
8obj-$(CONFIG_RAPIDIO_TSI500) += tsi500.o 8obj-$(CONFIG_RAPIDIO_TSI500) += tsi500.o
9 9obj-$(CONFIG_RAPIDIO_CPS_GEN2) += idt_gen2.o
10ifeq ($(CONFIG_RAPIDIO_DEBUG),y)
11EXTRA_CFLAGS += -DDEBUG
12endif
diff --git a/drivers/rapidio/switches/idt_gen2.c b/drivers/rapidio/switches/idt_gen2.c
new file mode 100644
index 000000000000..043ee3136e40
--- /dev/null
+++ b/drivers/rapidio/switches/idt_gen2.c
@@ -0,0 +1,430 @@
1/*
2 * IDT CPS Gen.2 Serial RapidIO switch family support
3 *
4 * Copyright 2010 Integrated Device Technology, Inc.
5 * Alexandre Bounine <alexandre.bounine@idt.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12
13#include <linux/rio.h>
14#include <linux/rio_drv.h>
15#include <linux/rio_ids.h>
16#include <linux/delay.h>
17#include "../rio.h"
18
19#define LOCAL_RTE_CONF_DESTID_SEL 0x010070
20#define LOCAL_RTE_CONF_DESTID_SEL_PSEL 0x0000001f
21
22#define IDT_LT_ERR_REPORT_EN 0x03100c
23
24#define IDT_PORT_ERR_REPORT_EN(n) (0x031044 + (n)*0x40)
25#define IDT_PORT_ERR_REPORT_EN_BC 0x03ff04
26
27#define IDT_PORT_ISERR_REPORT_EN(n) (0x03104C + (n)*0x40)
28#define IDT_PORT_ISERR_REPORT_EN_BC 0x03ff0c
29#define IDT_PORT_INIT_TX_ACQUIRED 0x00000020
30
31#define IDT_LANE_ERR_REPORT_EN(n) (0x038010 + (n)*0x100)
32#define IDT_LANE_ERR_REPORT_EN_BC 0x03ff10
33
34#define IDT_DEV_CTRL_1 0xf2000c
35#define IDT_DEV_CTRL_1_GENPW 0x02000000
36#define IDT_DEV_CTRL_1_PRSTBEH 0x00000001
37
38#define IDT_CFGBLK_ERR_CAPTURE_EN 0x020008
39#define IDT_CFGBLK_ERR_REPORT 0xf20014
40#define IDT_CFGBLK_ERR_REPORT_GENPW 0x00000002
41
42#define IDT_AUX_PORT_ERR_CAP_EN 0x020000
43#define IDT_AUX_ERR_REPORT_EN 0xf20018
44#define IDT_AUX_PORT_ERR_LOG_I2C 0x00000002
45#define IDT_AUX_PORT_ERR_LOG_JTAG 0x00000001
46
47#define IDT_ISLTL_ADDRESS_CAP 0x021014
48
49#define IDT_RIO_DOMAIN 0xf20020
50#define IDT_RIO_DOMAIN_MASK 0x000000ff
51
52#define IDT_PW_INFO_CSR 0xf20024
53
54#define IDT_SOFT_RESET 0xf20040
55#define IDT_SOFT_RESET_REQ 0x00030097
56
57#define IDT_I2C_MCTRL 0xf20050
58#define IDT_I2C_MCTRL_GENPW 0x04000000
59
60#define IDT_JTAG_CTRL 0xf2005c
61#define IDT_JTAG_CTRL_GENPW 0x00000002
62
63#define IDT_LANE_CTRL(n) (0xff8000 + (n)*0x100)
64#define IDT_LANE_CTRL_BC 0xffff00
65#define IDT_LANE_CTRL_GENPW 0x00200000
66#define IDT_LANE_DFE_1_BC 0xffff18
67#define IDT_LANE_DFE_2_BC 0xffff1c
68
69#define IDT_PORT_OPS(n) (0xf40004 + (n)*0x100)
70#define IDT_PORT_OPS_GENPW 0x08000000
71#define IDT_PORT_OPS_PL_ELOG 0x00000040
72#define IDT_PORT_OPS_LL_ELOG 0x00000020
73#define IDT_PORT_OPS_LT_ELOG 0x00000010
74#define IDT_PORT_OPS_BC 0xf4ff04
75
76#define IDT_PORT_ISERR_DET(n) (0xf40008 + (n)*0x100)
77
78#define IDT_ERR_CAP 0xfd0000
79#define IDT_ERR_CAP_LOG_OVERWR 0x00000004
80
81#define IDT_ERR_RD 0xfd0004
82
83#define IDT_DEFAULT_ROUTE 0xde
84#define IDT_NO_ROUTE 0xdf
85
86static int
87idtg2_route_add_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
88 u16 table, u16 route_destid, u8 route_port)
89{
90 /*
91 * Select routing table to update
92 */
93 if (table == RIO_GLOBAL_TABLE)
94 table = 0;
95 else
96 table++;
97
98 if (route_port == RIO_INVALID_ROUTE)
99 route_port = IDT_DEFAULT_ROUTE;
100
101 rio_mport_write_config_32(mport, destid, hopcount,
102 LOCAL_RTE_CONF_DESTID_SEL, table);
103
104 /*
105 * Program destination port for the specified destID
106 */
107 rio_mport_write_config_32(mport, destid, hopcount,
108 RIO_STD_RTE_CONF_DESTID_SEL_CSR,
109 (u32)route_destid);
110
111 rio_mport_write_config_32(mport, destid, hopcount,
112 RIO_STD_RTE_CONF_PORT_SEL_CSR,
113 (u32)route_port);
114 udelay(10);
115
116 return 0;
117}
118
119static int
120idtg2_route_get_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
121 u16 table, u16 route_destid, u8 *route_port)
122{
123 u32 result;
124
125 /*
126 * Select routing table to read
127 */
128 if (table == RIO_GLOBAL_TABLE)
129 table = 0;
130 else
131 table++;
132
133 rio_mport_write_config_32(mport, destid, hopcount,
134 LOCAL_RTE_CONF_DESTID_SEL, table);
135
136 rio_mport_write_config_32(mport, destid, hopcount,
137 RIO_STD_RTE_CONF_DESTID_SEL_CSR,
138 route_destid);
139
140 rio_mport_read_config_32(mport, destid, hopcount,
141 RIO_STD_RTE_CONF_PORT_SEL_CSR, &result);
142
143 if (IDT_DEFAULT_ROUTE == (u8)result || IDT_NO_ROUTE == (u8)result)
144 *route_port = RIO_INVALID_ROUTE;
145 else
146 *route_port = (u8)result;
147
148 return 0;
149}
150
151static int
152idtg2_route_clr_table(struct rio_mport *mport, u16 destid, u8 hopcount,
153 u16 table)
154{
155 u32 i;
156
157 /*
158 * Select routing table to read
159 */
160 if (table == RIO_GLOBAL_TABLE)
161 table = 0;
162 else
163 table++;
164
165 rio_mport_write_config_32(mport, destid, hopcount,
166 LOCAL_RTE_CONF_DESTID_SEL, table);
167
168 for (i = RIO_STD_RTE_CONF_EXTCFGEN;
169 i <= (RIO_STD_RTE_CONF_EXTCFGEN | 0xff);) {
170 rio_mport_write_config_32(mport, destid, hopcount,
171 RIO_STD_RTE_CONF_DESTID_SEL_CSR, i);
172 rio_mport_write_config_32(mport, destid, hopcount,
173 RIO_STD_RTE_CONF_PORT_SEL_CSR,
174 (IDT_DEFAULT_ROUTE << 24) | (IDT_DEFAULT_ROUTE << 16) |
175 (IDT_DEFAULT_ROUTE << 8) | IDT_DEFAULT_ROUTE);
176 i += 4;
177 }
178
179 return 0;
180}
181
182
183static int
184idtg2_set_domain(struct rio_mport *mport, u16 destid, u8 hopcount,
185 u8 sw_domain)
186{
187 /*
188 * Switch domain configuration operates only at global level
189 */
190 rio_mport_write_config_32(mport, destid, hopcount,
191 IDT_RIO_DOMAIN, (u32)sw_domain);
192 return 0;
193}
194
195static int
196idtg2_get_domain(struct rio_mport *mport, u16 destid, u8 hopcount,
197 u8 *sw_domain)
198{
199 u32 regval;
200
201 /*
202 * Switch domain configuration operates only at global level
203 */
204 rio_mport_read_config_32(mport, destid, hopcount,
205 IDT_RIO_DOMAIN, &regval);
206
207 *sw_domain = (u8)(regval & 0xff);
208
209 return 0;
210}
211
212static int
213idtg2_em_init(struct rio_dev *rdev)
214{
215 u32 regval;
216 int i, tmp;
217
218 /*
219 * This routine performs device-specific initialization only.
220 * All standard EM configuration should be performed at upper level.
221 */
222
223 pr_debug("RIO: %s [%d:%d]\n", __func__, rdev->destid, rdev->hopcount);
224
225 /* Set Port-Write info CSR: PRIO=3 and CRF=1 */
226 rio_write_config_32(rdev, IDT_PW_INFO_CSR, 0x0000e000);
227
228 /*
229 * Configure LT LAYER error reporting.
230 */
231
232 /* Enable standard (RIO.p8) error reporting */
233 rio_write_config_32(rdev, IDT_LT_ERR_REPORT_EN,
234 REM_LTL_ERR_ILLTRAN | REM_LTL_ERR_UNSOLR |
235 REM_LTL_ERR_UNSUPTR);
236
237 /* Use Port-Writes for LT layer error reporting.
238 * Enable per-port reset
239 */
240 rio_read_config_32(rdev, IDT_DEV_CTRL_1, &regval);
241 rio_write_config_32(rdev, IDT_DEV_CTRL_1,
242 regval | IDT_DEV_CTRL_1_GENPW | IDT_DEV_CTRL_1_PRSTBEH);
243
244 /*
245 * Configure PORT error reporting.
246 */
247
248 /* Report all RIO.p8 errors supported by device */
249 rio_write_config_32(rdev, IDT_PORT_ERR_REPORT_EN_BC, 0x807e8037);
250
251 /* Configure reporting of implementation specific errors/events */
252 rio_write_config_32(rdev, IDT_PORT_ISERR_REPORT_EN_BC,
253 IDT_PORT_INIT_TX_ACQUIRED);
254
255 /* Use Port-Writes for port error reporting and enable error logging */
256 tmp = RIO_GET_TOTAL_PORTS(rdev->swpinfo);
257 for (i = 0; i < tmp; i++) {
258 rio_read_config_32(rdev, IDT_PORT_OPS(i), &regval);
259 rio_write_config_32(rdev,
260 IDT_PORT_OPS(i), regval | IDT_PORT_OPS_GENPW |
261 IDT_PORT_OPS_PL_ELOG |
262 IDT_PORT_OPS_LL_ELOG |
263 IDT_PORT_OPS_LT_ELOG);
264 }
265 /* Overwrite error log if full */
266 rio_write_config_32(rdev, IDT_ERR_CAP, IDT_ERR_CAP_LOG_OVERWR);
267
268 /*
269 * Configure LANE error reporting.
270 */
271
272 /* Disable line error reporting */
273 rio_write_config_32(rdev, IDT_LANE_ERR_REPORT_EN_BC, 0);
274
275 /* Use Port-Writes for lane error reporting (when enabled)
276 * (do per-lane update because lanes may have different configuration)
277 */
278 tmp = (rdev->did == RIO_DID_IDTCPS1848) ? 48 : 16;
279 for (i = 0; i < tmp; i++) {
280 rio_read_config_32(rdev, IDT_LANE_CTRL(i), &regval);
281 rio_write_config_32(rdev, IDT_LANE_CTRL(i),
282 regval | IDT_LANE_CTRL_GENPW);
283 }
284
285 /*
286 * Configure AUX error reporting.
287 */
288
289 /* Disable JTAG and I2C Error capture */
290 rio_write_config_32(rdev, IDT_AUX_PORT_ERR_CAP_EN, 0);
291
292 /* Disable JTAG and I2C Error reporting/logging */
293 rio_write_config_32(rdev, IDT_AUX_ERR_REPORT_EN, 0);
294
295 /* Disable Port-Write notification from JTAG */
296 rio_write_config_32(rdev, IDT_JTAG_CTRL, 0);
297
298 /* Disable Port-Write notification from I2C */
299 rio_read_config_32(rdev, IDT_I2C_MCTRL, &regval);
300 rio_write_config_32(rdev, IDT_I2C_MCTRL, regval & ~IDT_I2C_MCTRL_GENPW);
301
302 /*
303 * Configure CFG_BLK error reporting.
304 */
305
306 /* Disable Configuration Block error capture */
307 rio_write_config_32(rdev, IDT_CFGBLK_ERR_CAPTURE_EN, 0);
308
309 /* Disable Port-Writes for Configuration Block error reporting */
310 rio_read_config_32(rdev, IDT_CFGBLK_ERR_REPORT, &regval);
311 rio_write_config_32(rdev, IDT_CFGBLK_ERR_REPORT,
312 regval & ~IDT_CFGBLK_ERR_REPORT_GENPW);
313
314 /* set TVAL = ~50us */
315 rio_write_config_32(rdev,
316 rdev->phys_efptr + RIO_PORT_LINKTO_CTL_CSR, 0x8e << 8);
317
318 return 0;
319}
320
321static int
322idtg2_em_handler(struct rio_dev *rdev, u8 portnum)
323{
324 u32 regval, em_perrdet, em_ltlerrdet;
325
326 rio_read_config_32(rdev,
327 rdev->em_efptr + RIO_EM_LTL_ERR_DETECT, &em_ltlerrdet);
328 if (em_ltlerrdet) {
329 /* Service Logical/Transport Layer Error(s) */
330 if (em_ltlerrdet & REM_LTL_ERR_IMPSPEC) {
331 /* Implementation specific error reported */
332 rio_read_config_32(rdev,
333 IDT_ISLTL_ADDRESS_CAP, &regval);
334
335 pr_debug("RIO: %s Implementation Specific LTL errors" \
336 " 0x%x @(0x%x)\n",
337 rio_name(rdev), em_ltlerrdet, regval);
338
339 /* Clear implementation specific address capture CSR */
340 rio_write_config_32(rdev, IDT_ISLTL_ADDRESS_CAP, 0);
341
342 }
343 }
344
345 rio_read_config_32(rdev,
346 rdev->em_efptr + RIO_EM_PN_ERR_DETECT(portnum), &em_perrdet);
347 if (em_perrdet) {
348 /* Service Port-Level Error(s) */
349 if (em_perrdet & REM_PED_IMPL_SPEC) {
350 /* Implementation Specific port error reported */
351
352 /* Get IS errors reported */
353 rio_read_config_32(rdev,
354 IDT_PORT_ISERR_DET(portnum), &regval);
355
356 pr_debug("RIO: %s Implementation Specific Port" \
357 " errors 0x%x\n", rio_name(rdev), regval);
358
359 /* Clear all implementation specific events */
360 rio_write_config_32(rdev,
361 IDT_PORT_ISERR_DET(portnum), 0);
362 }
363 }
364
365 return 0;
366}
367
368static ssize_t
369idtg2_show_errlog(struct device *dev, struct device_attribute *attr, char *buf)
370{
371 struct rio_dev *rdev = to_rio_dev(dev);
372 ssize_t len = 0;
373 u32 regval;
374
375 while (!rio_read_config_32(rdev, IDT_ERR_RD, &regval)) {
376 if (!regval) /* 0 = end of log */
377 break;
378 len += snprintf(buf + len, PAGE_SIZE - len,
379 "%08x\n", regval);
380 if (len >= (PAGE_SIZE - 10))
381 break;
382 }
383
384 return len;
385}
386
387static DEVICE_ATTR(errlog, S_IRUGO, idtg2_show_errlog, NULL);
388
389static int idtg2_sysfs(struct rio_dev *rdev, int create)
390{
391 struct device *dev = &rdev->dev;
392 int err = 0;
393
394 if (create == RIO_SW_SYSFS_CREATE) {
395 /* Initialize sysfs entries */
396 err = device_create_file(dev, &dev_attr_errlog);
397 if (err)
398 dev_err(dev, "Unable create sysfs errlog file\n");
399 } else
400 device_remove_file(dev, &dev_attr_errlog);
401
402 return err;
403}
404
405static int idtg2_switch_init(struct rio_dev *rdev, int do_enum)
406{
407 pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
408 rdev->rswitch->add_entry = idtg2_route_add_entry;
409 rdev->rswitch->get_entry = idtg2_route_get_entry;
410 rdev->rswitch->clr_table = idtg2_route_clr_table;
411 rdev->rswitch->set_domain = idtg2_set_domain;
412 rdev->rswitch->get_domain = idtg2_get_domain;
413 rdev->rswitch->em_init = idtg2_em_init;
414 rdev->rswitch->em_handle = idtg2_em_handler;
415 rdev->rswitch->sw_sysfs = idtg2_sysfs;
416
417 if (do_enum) {
418 /* Ensure that default routing is disabled on startup */
419 rio_write_config_32(rdev,
420 RIO_STD_RTE_DEFAULT_PORT, IDT_NO_ROUTE);
421 }
422
423 return 0;
424}
425
426DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTCPS1848, idtg2_switch_init);
427DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTCPS1616, idtg2_switch_init);
428DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTVPS1616, idtg2_switch_init);
429DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTSPS1616, idtg2_switch_init);
430DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTCPS1432, idtg2_switch_init);
diff --git a/drivers/rapidio/switches/idtcps.c b/drivers/rapidio/switches/idtcps.c
index 2c790c144f89..d06ee2d44b44 100644
--- a/drivers/rapidio/switches/idtcps.c
+++ b/drivers/rapidio/switches/idtcps.c
@@ -26,6 +26,9 @@ idtcps_route_add_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
26{ 26{
27 u32 result; 27 u32 result;
28 28
29 if (route_port == RIO_INVALID_ROUTE)
30 route_port = CPS_DEFAULT_ROUTE;
31
29 if (table == RIO_GLOBAL_TABLE) { 32 if (table == RIO_GLOBAL_TABLE) {
30 rio_mport_write_config_32(mport, destid, hopcount, 33 rio_mport_write_config_32(mport, destid, hopcount,
31 RIO_STD_RTE_CONF_DESTID_SEL_CSR, route_destid); 34 RIO_STD_RTE_CONF_DESTID_SEL_CSR, route_destid);
@@ -126,6 +129,15 @@ static int idtcps_switch_init(struct rio_dev *rdev, int do_enum)
126 rdev->rswitch->em_init = NULL; 129 rdev->rswitch->em_init = NULL;
127 rdev->rswitch->em_handle = NULL; 130 rdev->rswitch->em_handle = NULL;
128 131
132 if (do_enum) {
133 /* set TVAL = ~50us */
134 rio_write_config_32(rdev,
135 rdev->phys_efptr + RIO_PORT_LINKTO_CTL_CSR, 0x8e << 8);
136 /* Ensure that default routing is disabled on startup */
137 rio_write_config_32(rdev,
138 RIO_STD_RTE_DEFAULT_PORT, CPS_NO_ROUTE);
139 }
140
129 return 0; 141 return 0;
130} 142}
131 143
diff --git a/drivers/rapidio/switches/tsi568.c b/drivers/rapidio/switches/tsi568.c
index f7fd7898606e..3994c00aa01f 100644
--- a/drivers/rapidio/switches/tsi568.c
+++ b/drivers/rapidio/switches/tsi568.c
@@ -29,7 +29,7 @@
29#define SPP_ROUTE_CFG_DESTID(n) (0x11070 + 0x100*n) 29#define SPP_ROUTE_CFG_DESTID(n) (0x11070 + 0x100*n)
30#define SPP_ROUTE_CFG_PORT(n) (0x11074 + 0x100*n) 30#define SPP_ROUTE_CFG_PORT(n) (0x11074 + 0x100*n)
31 31
32#define TSI568_SP_MODE_BC 0x10004 32#define TSI568_SP_MODE(n) (0x11004 + 0x100*n)
33#define TSI568_SP_MODE_PW_DIS 0x08000000 33#define TSI568_SP_MODE_PW_DIS 0x08000000
34 34
35static int 35static int
@@ -113,18 +113,18 @@ tsi568_route_clr_table(struct rio_mport *mport, u16 destid, u8 hopcount,
113static int 113static int
114tsi568_em_init(struct rio_dev *rdev) 114tsi568_em_init(struct rio_dev *rdev)
115{ 115{
116 struct rio_mport *mport = rdev->net->hport;
117 u16 destid = rdev->rswitch->destid;
118 u8 hopcount = rdev->rswitch->hopcount;
119 u32 regval; 116 u32 regval;
117 int portnum;
120 118
121 pr_debug("TSI568 %s [%d:%d]\n", __func__, destid, hopcount); 119 pr_debug("TSI568 %s [%d:%d]\n", __func__, rdev->destid, rdev->hopcount);
122 120
123 /* Make sure that Port-Writes are disabled (for all ports) */ 121 /* Make sure that Port-Writes are disabled (for all ports) */
124 rio_mport_read_config_32(mport, destid, hopcount, 122 for (portnum = 0;
125 TSI568_SP_MODE_BC, &regval); 123 portnum < RIO_GET_TOTAL_PORTS(rdev->swpinfo); portnum++) {
126 rio_mport_write_config_32(mport, destid, hopcount, 124 rio_read_config_32(rdev, TSI568_SP_MODE(portnum), &regval);
127 TSI568_SP_MODE_BC, regval | TSI568_SP_MODE_PW_DIS); 125 rio_write_config_32(rdev, TSI568_SP_MODE(portnum),
126 regval | TSI568_SP_MODE_PW_DIS);
127 }
128 128
129 return 0; 129 return 0;
130} 130}
diff --git a/drivers/rapidio/switches/tsi57x.c b/drivers/rapidio/switches/tsi57x.c
index d34df722d95f..db8b8028988d 100644
--- a/drivers/rapidio/switches/tsi57x.c
+++ b/drivers/rapidio/switches/tsi57x.c
@@ -158,53 +158,55 @@ tsi57x_get_domain(struct rio_mport *mport, u16 destid, u8 hopcount,
158static int 158static int
159tsi57x_em_init(struct rio_dev *rdev) 159tsi57x_em_init(struct rio_dev *rdev)
160{ 160{
161 struct rio_mport *mport = rdev->net->hport;
162 u16 destid = rdev->rswitch->destid;
163 u8 hopcount = rdev->rswitch->hopcount;
164 u32 regval; 161 u32 regval;
165 int portnum; 162 int portnum;
166 163
167 pr_debug("TSI578 %s [%d:%d]\n", __func__, destid, hopcount); 164 pr_debug("TSI578 %s [%d:%d]\n", __func__, rdev->destid, rdev->hopcount);
168 165
169 for (portnum = 0; portnum < 16; portnum++) { 166 for (portnum = 0;
167 portnum < RIO_GET_TOTAL_PORTS(rdev->swpinfo); portnum++) {
170 /* Make sure that Port-Writes are enabled (for all ports) */ 168 /* Make sure that Port-Writes are enabled (for all ports) */
171 rio_mport_read_config_32(mport, destid, hopcount, 169 rio_read_config_32(rdev,
172 TSI578_SP_MODE(portnum), &regval); 170 TSI578_SP_MODE(portnum), &regval);
173 rio_mport_write_config_32(mport, destid, hopcount, 171 rio_write_config_32(rdev,
174 TSI578_SP_MODE(portnum), 172 TSI578_SP_MODE(portnum),
175 regval & ~TSI578_SP_MODE_PW_DIS); 173 regval & ~TSI578_SP_MODE_PW_DIS);
176 174
177 /* Clear all pending interrupts */ 175 /* Clear all pending interrupts */
178 rio_mport_read_config_32(mport, destid, hopcount, 176 rio_read_config_32(rdev,
179 rdev->phys_efptr + 177 rdev->phys_efptr +
180 RIO_PORT_N_ERR_STS_CSR(portnum), 178 RIO_PORT_N_ERR_STS_CSR(portnum),
181 &regval); 179 &regval);
182 rio_mport_write_config_32(mport, destid, hopcount, 180 rio_write_config_32(rdev,
183 rdev->phys_efptr + 181 rdev->phys_efptr +
184 RIO_PORT_N_ERR_STS_CSR(portnum), 182 RIO_PORT_N_ERR_STS_CSR(portnum),
185 regval & 0x07120214); 183 regval & 0x07120214);
186 184
187 rio_mport_read_config_32(mport, destid, hopcount, 185 rio_read_config_32(rdev,
188 TSI578_SP_INT_STATUS(portnum), &regval); 186 TSI578_SP_INT_STATUS(portnum), &regval);
189 rio_mport_write_config_32(mport, destid, hopcount, 187 rio_write_config_32(rdev,
190 TSI578_SP_INT_STATUS(portnum), 188 TSI578_SP_INT_STATUS(portnum),
191 regval & 0x000700bd); 189 regval & 0x000700bd);
192 190
193 /* Enable all interrupts to allow ports to send a port-write */ 191 /* Enable all interrupts to allow ports to send a port-write */
194 rio_mport_read_config_32(mport, destid, hopcount, 192 rio_read_config_32(rdev,
195 TSI578_SP_CTL_INDEP(portnum), &regval); 193 TSI578_SP_CTL_INDEP(portnum), &regval);
196 rio_mport_write_config_32(mport, destid, hopcount, 194 rio_write_config_32(rdev,
197 TSI578_SP_CTL_INDEP(portnum), 195 TSI578_SP_CTL_INDEP(portnum),
198 regval | 0x000b0000); 196 regval | 0x000b0000);
199 197
200 /* Skip next (odd) port if the current port is in x4 mode */ 198 /* Skip next (odd) port if the current port is in x4 mode */
201 rio_mport_read_config_32(mport, destid, hopcount, 199 rio_read_config_32(rdev,
202 rdev->phys_efptr + RIO_PORT_N_CTL_CSR(portnum), 200 rdev->phys_efptr + RIO_PORT_N_CTL_CSR(portnum),
203 &regval); 201 &regval);
204 if ((regval & RIO_PORT_N_CTL_PWIDTH) == RIO_PORT_N_CTL_PWIDTH_4) 202 if ((regval & RIO_PORT_N_CTL_PWIDTH) == RIO_PORT_N_CTL_PWIDTH_4)
205 portnum++; 203 portnum++;
206 } 204 }
207 205
206 /* set TVAL = ~50us */
207 rio_write_config_32(rdev,
208 rdev->phys_efptr + RIO_PORT_LINKTO_CTL_CSR, 0x9a << 8);
209
208 return 0; 210 return 0;
209} 211}
210 212
@@ -212,14 +214,12 @@ static int
212tsi57x_em_handler(struct rio_dev *rdev, u8 portnum) 214tsi57x_em_handler(struct rio_dev *rdev, u8 portnum)
213{ 215{
214 struct rio_mport *mport = rdev->net->hport; 216 struct rio_mport *mport = rdev->net->hport;
215 u16 destid = rdev->rswitch->destid;
216 u8 hopcount = rdev->rswitch->hopcount;
217 u32 intstat, err_status; 217 u32 intstat, err_status;
218 int sendcount, checkcount; 218 int sendcount, checkcount;
219 u8 route_port; 219 u8 route_port;
220 u32 regval; 220 u32 regval;
221 221
222 rio_mport_read_config_32(mport, destid, hopcount, 222 rio_read_config_32(rdev,
223 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum), 223 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum),
224 &err_status); 224 &err_status);
225 225
@@ -227,15 +227,15 @@ tsi57x_em_handler(struct rio_dev *rdev, u8 portnum)
227 (err_status & (RIO_PORT_N_ERR_STS_PW_OUT_ES | 227 (err_status & (RIO_PORT_N_ERR_STS_PW_OUT_ES |
228 RIO_PORT_N_ERR_STS_PW_INP_ES))) { 228 RIO_PORT_N_ERR_STS_PW_INP_ES))) {
229 /* Remove any queued packets by locking/unlocking port */ 229 /* Remove any queued packets by locking/unlocking port */
230 rio_mport_read_config_32(mport, destid, hopcount, 230 rio_read_config_32(rdev,
231 rdev->phys_efptr + RIO_PORT_N_CTL_CSR(portnum), 231 rdev->phys_efptr + RIO_PORT_N_CTL_CSR(portnum),
232 &regval); 232 &regval);
233 if (!(regval & RIO_PORT_N_CTL_LOCKOUT)) { 233 if (!(regval & RIO_PORT_N_CTL_LOCKOUT)) {
234 rio_mport_write_config_32(mport, destid, hopcount, 234 rio_write_config_32(rdev,
235 rdev->phys_efptr + RIO_PORT_N_CTL_CSR(portnum), 235 rdev->phys_efptr + RIO_PORT_N_CTL_CSR(portnum),
236 regval | RIO_PORT_N_CTL_LOCKOUT); 236 regval | RIO_PORT_N_CTL_LOCKOUT);
237 udelay(50); 237 udelay(50);
238 rio_mport_write_config_32(mport, destid, hopcount, 238 rio_write_config_32(rdev,
239 rdev->phys_efptr + RIO_PORT_N_CTL_CSR(portnum), 239 rdev->phys_efptr + RIO_PORT_N_CTL_CSR(portnum),
240 regval); 240 regval);
241 } 241 }
@@ -243,7 +243,7 @@ tsi57x_em_handler(struct rio_dev *rdev, u8 portnum)
243 /* Read from link maintenance response register to clear 243 /* Read from link maintenance response register to clear
244 * valid bit 244 * valid bit
245 */ 245 */
246 rio_mport_read_config_32(mport, destid, hopcount, 246 rio_read_config_32(rdev,
247 rdev->phys_efptr + RIO_PORT_N_MNT_RSP_CSR(portnum), 247 rdev->phys_efptr + RIO_PORT_N_MNT_RSP_CSR(portnum),
248 &regval); 248 &regval);
249 249
@@ -252,13 +252,12 @@ tsi57x_em_handler(struct rio_dev *rdev, u8 portnum)
252 */ 252 */
253 sendcount = 3; 253 sendcount = 3;
254 while (sendcount) { 254 while (sendcount) {
255 rio_mport_write_config_32(mport, destid, hopcount, 255 rio_write_config_32(rdev,
256 TSI578_SP_CS_TX(portnum), 0x40fc8000); 256 TSI578_SP_CS_TX(portnum), 0x40fc8000);
257 checkcount = 3; 257 checkcount = 3;
258 while (checkcount--) { 258 while (checkcount--) {
259 udelay(50); 259 udelay(50);
260 rio_mport_read_config_32( 260 rio_read_config_32(rdev,
261 mport, destid, hopcount,
262 rdev->phys_efptr + 261 rdev->phys_efptr +
263 RIO_PORT_N_MNT_RSP_CSR(portnum), 262 RIO_PORT_N_MNT_RSP_CSR(portnum),
264 &regval); 263 &regval);
@@ -272,25 +271,23 @@ tsi57x_em_handler(struct rio_dev *rdev, u8 portnum)
272 271
273exit_es: 272exit_es:
274 /* Clear implementation specific error status bits */ 273 /* Clear implementation specific error status bits */
275 rio_mport_read_config_32(mport, destid, hopcount, 274 rio_read_config_32(rdev, TSI578_SP_INT_STATUS(portnum), &intstat);
276 TSI578_SP_INT_STATUS(portnum), &intstat);
277 pr_debug("TSI578[%x:%x] SP%d_INT_STATUS=0x%08x\n", 275 pr_debug("TSI578[%x:%x] SP%d_INT_STATUS=0x%08x\n",
278 destid, hopcount, portnum, intstat); 276 rdev->destid, rdev->hopcount, portnum, intstat);
279 277
280 if (intstat & 0x10000) { 278 if (intstat & 0x10000) {
281 rio_mport_read_config_32(mport, destid, hopcount, 279 rio_read_config_32(rdev,
282 TSI578_SP_LUT_PEINF(portnum), &regval); 280 TSI578_SP_LUT_PEINF(portnum), &regval);
283 regval = (mport->sys_size) ? (regval >> 16) : (regval >> 24); 281 regval = (mport->sys_size) ? (regval >> 16) : (regval >> 24);
284 route_port = rdev->rswitch->route_table[regval]; 282 route_port = rdev->rswitch->route_table[regval];
285 pr_debug("RIO: TSI578[%s] P%d LUT Parity Error (destID=%d)\n", 283 pr_debug("RIO: TSI578[%s] P%d LUT Parity Error (destID=%d)\n",
286 rio_name(rdev), portnum, regval); 284 rio_name(rdev), portnum, regval);
287 tsi57x_route_add_entry(mport, destid, hopcount, 285 tsi57x_route_add_entry(mport, rdev->destid, rdev->hopcount,
288 RIO_GLOBAL_TABLE, regval, route_port); 286 RIO_GLOBAL_TABLE, regval, route_port);
289 } 287 }
290 288
291 rio_mport_write_config_32(mport, destid, hopcount, 289 rio_write_config_32(rdev, TSI578_SP_INT_STATUS(portnum),
292 TSI578_SP_INT_STATUS(portnum), 290 intstat & 0x000700bd);
293 intstat & 0x000700bd);
294 291
295 return 0; 292 return 0;
296} 293}
@@ -306,6 +303,12 @@ static int tsi57x_switch_init(struct rio_dev *rdev, int do_enum)
306 rdev->rswitch->em_init = tsi57x_em_init; 303 rdev->rswitch->em_init = tsi57x_em_init;
307 rdev->rswitch->em_handle = tsi57x_em_handler; 304 rdev->rswitch->em_handle = tsi57x_em_handler;
308 305
306 if (do_enum) {
307 /* Ensure that default routing is disabled on startup */
308 rio_write_config_32(rdev, RIO_STD_RTE_DEFAULT_PORT,
309 RIO_INVALID_ROUTE);
310 }
311
309 return 0; 312 return 0;
310} 313}
311 314