21 #include <linux/types.h>
22 #include <linux/kernel.h>
31 #include <linux/module.h>
34 #include <linux/sched.h>
36 #include <linux/slab.h>
46 static int next_destid = 0;
47 static int next_comptag = 1;
49 static int rio_mport_phys_table[] = {
71 spin_lock(&idtab->
lock);
74 if (destid < idtab->
max) {
76 destid += idtab->
start;
80 spin_unlock(&idtab->
lock);
92 static int rio_destid_reserve(
struct rio_net *net,
u16 destid)
97 destid -= idtab->
start;
98 spin_lock(&idtab->
lock);
100 spin_unlock(&idtab->
lock);
111 static void rio_destid_free(
struct rio_net *net,
u16 destid)
115 destid -= idtab->
start;
116 spin_lock(&idtab->
lock);
118 spin_unlock(&idtab->
lock);
125 static u16 rio_destid_first(
struct rio_net *net)
130 spin_lock(&idtab->
lock);
132 if (destid >= idtab->
max)
135 destid += idtab->
start;
136 spin_unlock(&idtab->
lock);
150 spin_lock(&idtab->
lock);
152 if (destid >= idtab->
max)
155 destid += idtab->
start;
156 spin_unlock(&idtab->
lock);
200 static void rio_local_set_device_id(
struct rio_mport *port,
u16 did)
214 static int rio_clear_locks(
struct rio_net *net)
225 if ((result & 0xffff) != 0xffff) {
227 "RIO: badness when releasing host lock on master port, result %8.8x\n",
235 if ((result & 0xffff) != 0xffff) {
237 "RIO: badness when releasing host lock on vid %4.4x did %4.4x\n",
243 rio_read_config_32(rdev,
247 rio_write_config_32(rdev,
263 static int rio_enum_host(
struct rio_mport *port)
295 return !!((src_ops |
dst_ops) & mask);
305 static void rio_release_dev(
struct device *
dev)
322 static int rio_is_switch(
struct rio_dev *rdev)
338 static void rio_switch_init(
struct rio_dev *rdev,
int do_enum)
344 if ((cur->
vid == rdev->
vid) && (cur->
did == rdev->
did)) {
345 pr_debug(
"RIO: calling init routine for %s\n",
354 pr_debug(
"RIO: adding STD routing ops for %s\n",
382 spin_lock(&rio_global_list_lock);
384 spin_unlock(&rio_global_list_lock);
404 int local,
u16 destid,
406 #ifdef CONFIG_RAPIDIO_ENABLE_RX_TX_PORTS
413 pr_debug(
"rio_enable_rx_tx_port(local = %d, destid = %d, hopcount = "
414 "%d, port_num = %d)\n", local, destid, hopcount, port_num);
419 rio_local_read_config_32(port, ext_ftr_ptr +
439 rio_local_write_config_32(port, ext_ftr_ptr +
468 u8 hopcount,
int do_enum)
487 sizeof(rswitch->
nextdev[0])) +
sizeof(*rswitch);
500 rdev->
did = result >> 16;
501 rdev->
vid = result & 0xffff;
507 rdev->
asm_vid = result & 0xffff;
512 rdev->
efptr = result & 0xffff;
527 if (next_comptag >= 0x10000) {
528 pr_err(
"RIO: Component Tag Counter Overflow\n");
542 rio_set_device_id(port, destid, hopcount, next_destid);
543 rdev->
destid = next_destid;
544 next_destid = rio_destid_alloc(net);
546 rdev->
destid = rio_get_device_id(port, destid, hopcount);
558 if (rio_is_switch(rdev)) {
573 rio_switch_init(rdev, do_enum);
576 rswitch->
clr_table(port, destid, hopcount,
594 rdev->
dev.release = rio_release_dev;
605 ret = rio_add_device(rdev);
632 rio_sport_is_active(
struct rio_mport *port,
u16 destid,
u8 hopcount,
int sport)
639 while (ext_ftr_ptr) {
641 ext_ftr_ptr, &result);
672 rio_lock_device(
struct rio_mport *port,
u16 destid,
u8 hopcount,
int wait_ms)
684 if (wait_ms != 0 && tcnt == wait_ms) {
685 pr_debug(
"RIO: timeout when locking device %x:%x\n",
715 rio_unlock_device(
struct rio_mport *port,
u16 destid,
u8 hopcount)
726 if ((result & 0xffff) != 0xffff) {
727 pr_debug(
"RIO: badness when releasing device lock %x:%x\n",
751 rio_route_add_entry(
struct rio_dev *rdev,
757 rc = rio_lock_device(rdev->
net->hport, rdev->
destid,
765 route_destid, route_port);
767 rio_unlock_device(rdev->
net->hport, rdev->
destid,
789 rio_route_get_entry(
struct rio_dev *rdev,
u16 table,
790 u16 route_destid,
u8 *route_port,
int lock)
795 rc = rio_lock_device(rdev->
net->hport, rdev->
destid,
803 route_destid, route_port);
805 rio_unlock_device(rdev->
net->hport, rdev->
destid,
819 static u16 rio_get_host_deviceid_lock(
struct rio_mport *port,
u8 hopcount)
826 return (
u16) (result & 0xffff);
849 pr_debug(
"RIO: device access check failed\n");
853 if (rio_get_host_deviceid_lock(port, hopcount) == port->
host_deviceid) {
854 pr_debug(
"RIO: PE already discovered by this host\n");
865 if (rdev && prev && rio_is_switch(prev)) {
866 pr_debug(
"RIO: redundant path to %s\n",
879 while ((tmp = rio_get_host_deviceid_lock(port, hopcount))
890 if (rio_get_host_deviceid_lock(port, hopcount) > port->
host_deviceid) {
892 "RIO: PE locked by a higher priority host...retreating\n");
903 if (prev && rio_is_switch(prev))
908 if (rio_is_switch(rdev)) {
920 destid = rio_destid_first(net);
924 destid, sw_inport, 0);
927 destid = rio_destid_next(net, destid + 1);
930 "RIO: found %s (vid %4.4x did %4.4x) with %d ports\n",
931 rio_name(rdev), rdev->
vid, rdev->
did,
933 sw_destid = next_destid;
937 if (sw_inport == port_num) {
945 cur_destid = next_destid;
947 if (rio_sport_is_active
951 "RIO: scanning device on port %d\n",
961 if (rio_enum_peer(net, port, hopcount + 1,
966 destid = rio_destid_next(net, cur_destid + 1);
968 for (destid = cur_destid;
969 destid < next_destid;) {
971 rio_route_add_entry(rdev,
980 destid = rio_destid_next(net,
998 rio_write_config_32(rdev,
1007 if (next_destid == sw_destid)
1008 next_destid = rio_destid_alloc(net);
1010 rdev->
destid = sw_destid;
1012 pr_debug(
"RIO: found %s (vid %4.4x did %4.4x)\n",
1013 rio_name(rdev), rdev->
vid, rdev->
did);
1026 static int rio_enum_complete(
struct rio_mport *port)
1049 u8 hopcount,
struct rio_dev *prev,
int prev_port)
1056 if ((rdev = rio_setup_device(net, port, destid, hopcount, 0))) {
1060 if (prev && rio_is_switch(prev))
1065 if (rio_is_switch(rdev)) {
1070 "RIO: found %s (vid %4.4x did %4.4x) with %d ports\n",
1071 rio_name(rdev), rdev->
vid, rdev->
did,
1079 if (rio_sport_is_active
1080 (port, destid, hopcount, port_num)) {
1082 "RIO: scanning device on port %d\n",
1085 rio_lock_device(port, destid, hopcount, 1000);
1090 rio_route_get_entry(rdev,
1094 if (route_port == port_num)
1100 rio_unlock_device(port, destid, hopcount);
1101 if (rio_disc_peer(net, port, ndestid,
1102 hopcount + 1, rdev, port_num) < 0)
1107 pr_debug(
"RIO: found %s (vid %4.4x did %4.4x)\n",
1108 rio_name(rdev), rdev->
vid, rdev->
did);
1122 static int rio_mport_is_active(
struct rio_mport *port)
1126 int *
entry = rio_mport_phys_table;
1132 }
while (*++entry >= 0);
1135 rio_local_read_config_32(port,
1160 if (net && do_enum) {
1167 pr_err(
"RIO: failed to allocate destID table\n");
1179 INIT_LIST_HEAD(&net->
node);
1180 INIT_LIST_HEAD(&net->
devices);
1182 INIT_LIST_HEAD(&net->
mports);
1198 static void rio_update_route_tables(
struct rio_net *net)
1211 if (rio_is_switch(rdev) && (rdev->
rswitch == rswitch))
1218 if (swrdev->
destid == destid)
1224 rio_route_add_entry(swrdev,
1241 static void rio_init_em(
struct rio_dev *rdev)
1243 if (rio_is_switch(rdev) && (rdev->
em_efptr) &&
1256 if (port->
ops->pwenable)
1257 port->
ops->pwenable(port, enable);
1277 if (rio_enum_host(mport) < 0) {
1279 "RIO: master port %d device has been enumerated by a remote host\n",
1286 if (rio_mport_is_active(mport)) {
1287 net = rio_alloc_net(mport, 1, 0);
1304 next_destid = rio_destid_alloc(net);
1306 if (rio_enum_peer(net, mport, 0,
NULL, 0) < 0) {
1309 "RIO: master port %d device has lost enumeration to a remote host\n",
1311 rio_clear_locks(net);
1316 rio_destid_free(net, next_destid);
1317 rio_update_route_tables(net);
1318 rio_clear_locks(net);
1319 rio_pw_enable(mport, 1);
1337 static void rio_build_route_tables(
struct rio_net *net)
1375 unsigned long to_end;
1381 if (rio_mport_is_active(mport)) {
1382 pr_debug(
"RIO: wait for enumeration to complete...\n");
1384 to_end =
jiffies + CONFIG_RAPIDIO_DISC_TIMEOUT *
HZ;
1386 if (rio_enum_complete(mport))
1391 pr_debug(
"RIO: discovery timeout on mport %d %s\n",
1395 pr_debug(
"RIO: ... enumeration done\n");
1397 net = rio_alloc_net(mport, 0, 0);
1412 "RIO: master port %d device has failed discovery\n",
1417 rio_build_route_tables(net);