2 * RapidIO enumeration and discovery support
4 * Copyright 2005 MontaVista Software, Inc.
5 * Matt Porter <mporter@kernel.crashing.org>
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.
13 #include <linux/config.h>
14 #include <linux/types.h>
15 #include <linux/kernel.h>
17 #include <linux/delay.h>
18 #include <linux/init.h>
19 #include <linux/rio.h>
20 #include <linux/rio_drv.h>
21 #include <linux/rio_ids.h>
22 #include <linux/rio_regs.h>
23 #include <linux/module.h>
24 #include <linux/spinlock.h>
25 #include <linux/timer.h>
29 LIST_HEAD(rio_devices);
30 static LIST_HEAD(rio_switches);
32 #define RIO_ENUM_CMPL_MAGIC 0xdeadbeef
34 static void rio_enum_timeout(unsigned long);
36 spinlock_t rio_global_list_lock = SPIN_LOCK_UNLOCKED;
37 static int next_destid = 0;
38 static int next_switchid = 0;
39 static int next_net = 0;
41 static struct timer_list rio_enum_timer =
42 TIMER_INITIALIZER(rio_enum_timeout, 0, 0);
44 static int rio_mport_phys_table[] = {
46 RIO_EFB_PAR_EP_REC_ID,
48 RIO_EFB_SER_EP_REC_ID,
52 static int rio_sport_phys_table[] = {
53 RIO_EFB_PAR_EP_FREE_ID,
54 RIO_EFB_SER_EP_FREE_ID,
58 extern struct rio_route_ops __start_rio_route_ops[];
59 extern struct rio_route_ops __end_rio_route_ops[];
62 * rio_get_device_id - Get the base/extended device id for a device
63 * @port: RIO master port
64 * @destid: Destination ID of device
65 * @hopcount: Hopcount to device
67 * Reads the base/extended device id from a device. Returns the
70 static u16 rio_get_device_id(struct rio_mport *port, u16 destid, u8 hopcount)
74 rio_mport_read_config_32(port, destid, hopcount, RIO_DID_CSR, &result);
76 return RIO_GET_DID(result);
80 * rio_set_device_id - Set the base/extended device id for a device
81 * @port: RIO master port
82 * @destid: Destination ID of device
83 * @hopcount: Hopcount to device
84 * @did: Device ID value to be written
86 * Writes the base/extended device id from a device.
89 rio_set_device_id(struct rio_mport *port, u16 destid, u8 hopcount, u16 did)
91 rio_mport_write_config_32(port, destid, hopcount, RIO_DID_CSR,
96 * rio_local_set_device_id - Set the base/extended device id for a port
97 * @port: RIO master port
98 * @did: Device ID value to be written
100 * Writes the base/extended device id from a device.
102 static void rio_local_set_device_id(struct rio_mport *port, u16 did)
104 rio_local_write_config_32(port, RIO_DID_CSR, RIO_SET_DID(did));
108 * rio_clear_locks- Release all host locks and signal enumeration complete
109 * @port: Master port to issue transaction
111 * Marks the component tag CSR on each device with the enumeration
112 * complete flag. When complete, it then release the host locks on
113 * each device. Returns 0 on success or %-EINVAL on failure.
115 static int rio_clear_locks(struct rio_mport *port)
117 struct rio_dev *rdev;
121 /* Write component tag CSR magic complete value */
122 rio_local_write_config_32(port, RIO_COMPONENT_TAG_CSR,
123 RIO_ENUM_CMPL_MAGIC);
124 list_for_each_entry(rdev, &rio_devices, global_list)
125 rio_write_config_32(rdev, RIO_COMPONENT_TAG_CSR,
126 RIO_ENUM_CMPL_MAGIC);
128 /* Release host device id locks */
129 rio_local_write_config_32(port, RIO_HOST_DID_LOCK_CSR,
130 port->host_deviceid);
131 rio_local_read_config_32(port, RIO_HOST_DID_LOCK_CSR, &result);
132 if ((result & 0xffff) != 0xffff) {
134 "RIO: badness when releasing host lock on master port, result %8.8x\n",
138 list_for_each_entry(rdev, &rio_devices, global_list) {
139 rio_write_config_32(rdev, RIO_HOST_DID_LOCK_CSR,
140 port->host_deviceid);
141 rio_read_config_32(rdev, RIO_HOST_DID_LOCK_CSR, &result);
142 if ((result & 0xffff) != 0xffff) {
144 "RIO: badness when releasing host lock on vid %4.4x did %4.4x\n",
145 rdev->vid, rdev->did);
154 * rio_enum_host- Set host lock and initialize host destination ID
155 * @port: Master port to issue transaction
157 * Sets the local host master port lock and destination ID register
158 * with the host device ID value. The host device ID value is provided
159 * by the platform. Returns %0 on success or %-1 on failure.
161 static int rio_enum_host(struct rio_mport *port)
165 /* Set master port host device id lock */
166 rio_local_write_config_32(port, RIO_HOST_DID_LOCK_CSR,
167 port->host_deviceid);
169 rio_local_read_config_32(port, RIO_HOST_DID_LOCK_CSR, &result);
170 if ((result & 0xffff) != port->host_deviceid)
173 /* Set master port destid and init destid ctr */
174 rio_local_set_device_id(port, port->host_deviceid);
176 if (next_destid == port->host_deviceid)
183 * rio_device_has_destid- Test if a device contains a destination ID register
184 * @port: Master port to issue transaction
185 * @src_ops: RIO device source operations
186 * @dst_ops: RIO device destination operations
188 * Checks the provided @src_ops and @dst_ops for the necessary transaction
189 * capabilities that indicate whether or not a device will implement a
190 * destination ID register. Returns 1 if true or 0 if false.
192 static int rio_device_has_destid(struct rio_mport *port, int src_ops,
195 if (((src_ops & RIO_SRC_OPS_READ) ||
196 (src_ops & RIO_SRC_OPS_WRITE) ||
197 (src_ops & RIO_SRC_OPS_ATOMIC_TST_SWP) ||
198 (src_ops & RIO_SRC_OPS_ATOMIC_INC) ||
199 (src_ops & RIO_SRC_OPS_ATOMIC_DEC) ||
200 (src_ops & RIO_SRC_OPS_ATOMIC_SET) ||
201 (src_ops & RIO_SRC_OPS_ATOMIC_CLR)) &&
202 ((dst_ops & RIO_DST_OPS_READ) ||
203 (dst_ops & RIO_DST_OPS_WRITE) ||
204 (dst_ops & RIO_DST_OPS_ATOMIC_TST_SWP) ||
205 (dst_ops & RIO_DST_OPS_ATOMIC_INC) ||
206 (dst_ops & RIO_DST_OPS_ATOMIC_DEC) ||
207 (dst_ops & RIO_DST_OPS_ATOMIC_SET) ||
208 (dst_ops & RIO_DST_OPS_ATOMIC_CLR))) {
215 * rio_release_dev- Frees a RIO device struct
216 * @dev: LDM device associated with a RIO device struct
218 * Gets the RIO device struct associated a RIO device struct.
219 * The RIO device struct is freed.
221 static void rio_release_dev(struct device *dev)
223 struct rio_dev *rdev;
225 rdev = to_rio_dev(dev);
230 * rio_is_switch- Tests if a RIO device has switch capabilities
233 * Gets the RIO device Processing Element Features register
234 * contents and tests for switch capabilities. Returns 1 if
235 * the device is a switch or 0 if it is not a switch.
236 * The RIO device struct is freed.
238 static int rio_is_switch(struct rio_dev *rdev)
240 if (rdev->pef & RIO_PEF_SWITCH)
246 * rio_route_set_ops- Sets routing operations for a particular vendor switch
249 * Searches the RIO route ops table for known switch types. If the vid
250 * and did match a switch table entry, then set the add_entry() and
251 * get_entry() ops to the table entry values.
253 static void rio_route_set_ops(struct rio_dev *rdev)
255 struct rio_route_ops *cur = __start_rio_route_ops;
256 struct rio_route_ops *end = __end_rio_route_ops;
259 if ((cur->vid == rdev->vid) && (cur->did == rdev->did)) {
260 pr_debug("RIO: adding routing ops for %s\n", rio_name(rdev));
261 rdev->rswitch->add_entry = cur->add_hook;
262 rdev->rswitch->get_entry = cur->get_hook;
267 if (!rdev->rswitch->add_entry || !rdev->rswitch->get_entry)
268 printk(KERN_ERR "RIO: missing routing ops for %s\n",
273 * rio_add_device- Adds a RIO device to the device model
276 * Adds the RIO device to the global device list and adds the RIO
277 * device to the RIO device list. Creates the generic sysfs nodes
280 static void __devinit rio_add_device(struct rio_dev *rdev)
282 device_add(&rdev->dev);
284 spin_lock(&rio_global_list_lock);
285 list_add_tail(&rdev->global_list, &rio_devices);
286 spin_unlock(&rio_global_list_lock);
288 rio_create_sysfs_dev_files(rdev);
292 * rio_setup_device- Allocates and sets up a RIO device
294 * @port: Master port to send transactions
295 * @destid: Current destination ID
296 * @hopcount: Current hopcount
297 * @do_enum: Enumeration/Discovery mode flag
299 * Allocates a RIO device and configures fields based on configuration
300 * space contents. If device has a destination ID register, a destination
301 * ID is either assigned in enumeration mode or read from configuration
302 * space in discovery mode. If the device has switch capabilities, then
303 * a switch is allocated and configured appropriately. Returns a pointer
304 * to a RIO device on success or NULL on failure.
307 static struct rio_dev *rio_setup_device(struct rio_net *net,
308 struct rio_mport *port, u16 destid,
309 u8 hopcount, int do_enum)
311 struct rio_dev *rdev;
312 struct rio_switch *rswitch;
315 rdev = kmalloc(sizeof(struct rio_dev), GFP_KERNEL);
319 memset(rdev, 0, sizeof(struct rio_dev));
321 rio_mport_read_config_32(port, destid, hopcount, RIO_DEV_ID_CAR,
323 rdev->did = result >> 16;
324 rdev->vid = result & 0xffff;
325 rio_mport_read_config_32(port, destid, hopcount, RIO_DEV_INFO_CAR,
327 rio_mport_read_config_32(port, destid, hopcount, RIO_ASM_ID_CAR,
329 rdev->asm_did = result >> 16;
330 rdev->asm_vid = result & 0xffff;
331 rio_mport_read_config_32(port, destid, hopcount, RIO_ASM_INFO_CAR,
333 rdev->asm_rev = result >> 16;
334 rio_mport_read_config_32(port, destid, hopcount, RIO_PEF_CAR,
336 if (rdev->pef & RIO_PEF_EXT_FEATURES)
337 rdev->efptr = result & 0xffff;
339 rio_mport_read_config_32(port, destid, hopcount, RIO_SRC_OPS_CAR,
341 rio_mport_read_config_32(port, destid, hopcount, RIO_DST_OPS_CAR,
344 if (rio_device_has_destid(port, rdev->src_ops, rdev->dst_ops)
346 rio_set_device_id(port, destid, hopcount, next_destid);
347 rdev->destid = next_destid++;
348 if (next_destid == port->host_deviceid)
351 rdev->destid = rio_get_device_id(port, destid, hopcount);
353 /* If a PE has both switch and other functions, show it as a switch */
354 if (rio_is_switch(rdev)) {
355 rio_mport_read_config_32(port, destid, hopcount,
356 RIO_SWP_INFO_CAR, &rdev->swpinfo);
357 rswitch = kmalloc(sizeof(struct rio_switch), GFP_KERNEL);
363 rswitch->switchid = next_switchid;
364 rswitch->hopcount = hopcount;
365 rswitch->destid = 0xffff;
366 /* Initialize switch route table */
367 for (rdid = 0; rdid < RIO_MAX_ROUTE_ENTRIES; rdid++)
368 rswitch->route_table[rdid] = RIO_INVALID_ROUTE;
369 rdev->rswitch = rswitch;
370 sprintf(rio_name(rdev), "%02x:s:%04x", rdev->net->id,
371 rdev->rswitch->switchid);
372 rio_route_set_ops(rdev);
374 list_add_tail(&rswitch->node, &rio_switches);
377 sprintf(rio_name(rdev), "%02x:e:%04x", rdev->net->id,
380 rdev->dev.bus = &rio_bus_type;
382 device_initialize(&rdev->dev);
383 rdev->dev.release = rio_release_dev;
386 rdev->dev.dma_mask = (u64 *) 0xffffffff;
387 rdev->dev.coherent_dma_mask = 0xffffffffULL;
389 if ((rdev->pef & RIO_PEF_INB_DOORBELL) &&
390 (rdev->dst_ops & RIO_DST_OPS_DOORBELL))
391 rio_init_dbell_res(&rdev->riores[RIO_DOORBELL_RESOURCE],
394 rio_add_device(rdev);
401 * rio_sport_is_active- Tests if a switch port has an active connection.
402 * @port: Master port to send transaction
403 * @destid: Associated destination ID for switch
404 * @hopcount: Hopcount to reach switch
405 * @sport: Switch port number
407 * Reads the port error status CSR for a particular switch port to
408 * determine if the port has an active link. Returns
409 * %PORT_N_ERR_STS_PORT_OK if the port is active or %0 if it is
413 rio_sport_is_active(struct rio_mport *port, u16 destid, u8 hopcount, int sport)
418 int *entry = rio_sport_phys_table;
422 rio_mport_get_feature(port, 0, destid, hopcount, *entry)))
425 } while (*++entry >= 0);
428 rio_mport_read_config_32(port, destid, hopcount,
430 RIO_PORT_N_ERR_STS_CSR(sport),
433 return (result & PORT_N_ERR_STS_PORT_OK);
437 * rio_route_add_entry- Add a route entry to a switch routing table
438 * @mport: Master port to send transaction
439 * @rdev: Switch device
440 * @table: Routing table ID
441 * @route_destid: Destination ID to be routed
442 * @route_port: Port number to be routed
444 * Calls the switch specific add_entry() method to add a route entry
445 * on a switch. The route table can be specified using the @table
446 * argument if a switch has per port routing tables or the normal
447 * use is to specific all tables (or the global table) by passing
448 * %RIO_GLOBAL_TABLE in @table. Returns %0 on success or %-EINVAL
451 static int rio_route_add_entry(struct rio_mport *mport, struct rio_dev *rdev,
452 u16 table, u16 route_destid, u8 route_port)
454 return rdev->rswitch->add_entry(mport, rdev->rswitch->destid,
455 rdev->rswitch->hopcount, table,
456 route_destid, route_port);
460 * rio_route_get_entry- Read a route entry in a switch routing table
461 * @mport: Master port to send transaction
462 * @rdev: Switch device
463 * @table: Routing table ID
464 * @route_destid: Destination ID to be routed
465 * @route_port: Pointer to read port number into
467 * Calls the switch specific get_entry() method to read a route entry
468 * in a switch. The route table can be specified using the @table
469 * argument if a switch has per port routing tables or the normal
470 * use is to specific all tables (or the global table) by passing
471 * %RIO_GLOBAL_TABLE in @table. Returns %0 on success or %-EINVAL
475 rio_route_get_entry(struct rio_mport *mport, struct rio_dev *rdev, u16 table,
476 u16 route_destid, u8 * route_port)
478 return rdev->rswitch->get_entry(mport, rdev->rswitch->destid,
479 rdev->rswitch->hopcount, table,
480 route_destid, route_port);
484 * rio_get_host_deviceid_lock- Reads the Host Device ID Lock CSR on a device
485 * @port: Master port to send transaction
486 * @hopcount: Number of hops to the device
488 * Used during enumeration to read the Host Device ID Lock CSR on a
489 * RIO device. Returns the value of the lock register.
491 static u16 rio_get_host_deviceid_lock(struct rio_mport *port, u8 hopcount)
495 rio_mport_read_config_32(port, RIO_ANY_DESTID, hopcount,
496 RIO_HOST_DID_LOCK_CSR, &result);
498 return (u16) (result & 0xffff);
502 * rio_get_swpinfo_inport- Gets the ingress port number
503 * @mport: Master port to send transaction
504 * @destid: Destination ID associated with the switch
505 * @hopcount: Number of hops to the device
507 * Returns port number being used to access the switch device.
510 rio_get_swpinfo_inport(struct rio_mport *mport, u16 destid, u8 hopcount)
514 rio_mport_read_config_32(mport, destid, hopcount, RIO_SWP_INFO_CAR,
517 return (u8) (result & 0xff);
521 * rio_get_swpinfo_tports- Gets total number of ports on the switch
522 * @mport: Master port to send transaction
523 * @destid: Destination ID associated with the switch
524 * @hopcount: Number of hops to the device
526 * Returns total numbers of ports implemented by the switch device.
528 static u8 rio_get_swpinfo_tports(struct rio_mport *mport, u16 destid,
533 rio_mport_read_config_32(mport, destid, hopcount, RIO_SWP_INFO_CAR,
536 return RIO_GET_TOTAL_PORTS(result);
540 * rio_net_add_mport- Add a master port to a RIO network
542 * @port: Master port to add
544 * Adds a master port to the network list of associated master
547 static void rio_net_add_mport(struct rio_net *net, struct rio_mport *port)
549 spin_lock(&rio_global_list_lock);
550 list_add_tail(&port->nnode, &net->mports);
551 spin_unlock(&rio_global_list_lock);
555 * rio_enum_peer- Recursively enumerate a RIO network through a master port
556 * @net: RIO network being enumerated
557 * @port: Master port to send transactions
558 * @hopcount: Number of hops into the network
560 * Recursively enumerates a RIO network. Transactions are sent via the
561 * master port passed in @port.
563 static int rio_enum_peer(struct rio_net *net, struct rio_mport *port,
569 struct rio_dev *rdev;
573 if (rio_get_host_deviceid_lock(port, hopcount) == port->host_deviceid) {
574 pr_debug("RIO: PE already discovered by this host\n");
576 * Already discovered by this host. Add it as another
577 * master port for the current network.
579 rio_net_add_mport(net, port);
583 /* Attempt to acquire device lock */
584 rio_mport_write_config_32(port, RIO_ANY_DESTID, hopcount,
585 RIO_HOST_DID_LOCK_CSR, port->host_deviceid);
586 while ((tmp = rio_get_host_deviceid_lock(port, hopcount))
587 < port->host_deviceid) {
590 /* Attempt to acquire device lock again */
591 rio_mport_write_config_32(port, RIO_ANY_DESTID, hopcount,
592 RIO_HOST_DID_LOCK_CSR,
593 port->host_deviceid);
596 if (rio_get_host_deviceid_lock(port, hopcount) > port->host_deviceid) {
598 "RIO: PE locked by a higher priority host...retreating\n");
602 /* Setup new RIO device */
603 if ((rdev = rio_setup_device(net, port, RIO_ANY_DESTID, hopcount, 1))) {
604 /* Add device to the global and bus/net specific list. */
605 list_add_tail(&rdev->net_list, &net->devices);
609 if (rio_is_switch(rdev)) {
612 for (destid = 0; destid < next_destid; destid++) {
613 rio_route_add_entry(port, rdev, RIO_GLOBAL_TABLE,
614 destid, rio_get_swpinfo_inport(port,
617 rdev->rswitch->route_table[destid] =
618 rio_get_swpinfo_inport(port, RIO_ANY_DESTID,
623 rio_get_swpinfo_tports(port, RIO_ANY_DESTID, hopcount);
625 "RIO: found %s (vid %4.4x did %4.4x) with %d ports\n",
626 rio_name(rdev), rdev->vid, rdev->did, num_ports);
627 for (port_num = 0; port_num < num_ports; port_num++) {
628 if (rio_get_swpinfo_inport
629 (port, RIO_ANY_DESTID, hopcount) == port_num)
632 cur_destid = next_destid;
634 if (rio_sport_is_active
635 (port, RIO_ANY_DESTID, hopcount, port_num)) {
637 "RIO: scanning device on port %d\n",
639 rio_route_add_entry(port, rdev,
641 RIO_ANY_DESTID, port_num);
643 if (rio_enum_peer(net, port, hopcount + 1) < 0)
646 /* Update routing tables */
647 if (next_destid > cur_destid) {
648 for (destid = cur_destid;
649 destid < next_destid; destid++) {
650 rio_route_add_entry(port, rdev,
655 route_table[destid] =
658 rdev->rswitch->destid = cur_destid;
663 pr_debug("RIO: found %s (vid %4.4x did %4.4x)\n",
664 rio_name(rdev), rdev->vid, rdev->did);
670 * rio_enum_complete- Tests if enumeration of a network is complete
671 * @port: Master port to send transaction
673 * Tests the Component Tag CSR for presence of the magic enumeration
674 * complete flag. Return %1 if enumeration is complete or %0 if
675 * enumeration is incomplete.
677 static int rio_enum_complete(struct rio_mport *port)
682 rio_local_read_config_32(port, RIO_COMPONENT_TAG_CSR, &tag_csr);
684 if (tag_csr == RIO_ENUM_CMPL_MAGIC)
691 * rio_disc_peer- Recursively discovers a RIO network through a master port
692 * @net: RIO network being discovered
693 * @port: Master port to send transactions
694 * @destid: Current destination ID in network
695 * @hopcount: Number of hops into the network
697 * Recursively discovers a RIO network. Transactions are sent via the
698 * master port passed in @port.
701 rio_disc_peer(struct rio_net *net, struct rio_mport *port, u16 destid,
704 u8 port_num, route_port;
706 struct rio_dev *rdev;
709 /* Setup new RIO device */
710 if ((rdev = rio_setup_device(net, port, destid, hopcount, 0))) {
711 /* Add device to the global and bus/net specific list. */
712 list_add_tail(&rdev->net_list, &net->devices);
716 if (rio_is_switch(rdev)) {
719 /* Associated destid is how we accessed this switch */
720 rdev->rswitch->destid = destid;
722 num_ports = rio_get_swpinfo_tports(port, destid, hopcount);
724 "RIO: found %s (vid %4.4x did %4.4x) with %d ports\n",
725 rio_name(rdev), rdev->vid, rdev->did, num_ports);
726 for (port_num = 0; port_num < num_ports; port_num++) {
727 if (rio_get_swpinfo_inport(port, destid, hopcount) ==
731 if (rio_sport_is_active
732 (port, destid, hopcount, port_num)) {
734 "RIO: scanning device on port %d\n",
736 for (ndestid = 0; ndestid < RIO_ANY_DESTID;
738 rio_route_get_entry(port, rdev,
742 if (route_port == port_num)
747 (net, port, ndestid, hopcount + 1) < 0)
752 pr_debug("RIO: found %s (vid %4.4x did %4.4x)\n",
753 rio_name(rdev), rdev->vid, rdev->did);
759 * rio_mport_is_active- Tests if master port link is active
760 * @port: Master port to test
762 * Reads the port error status CSR for the master port to
763 * determine if the port has an active link. Returns
764 * %PORT_N_ERR_STS_PORT_OK if the master port is active
765 * or %0 if it is inactive.
767 static int rio_mport_is_active(struct rio_mport *port)
771 int *entry = rio_mport_phys_table;
775 rio_mport_get_feature(port, 1, 0, 0, *entry)))
777 } while (*++entry >= 0);
780 rio_local_read_config_32(port,
782 RIO_PORT_N_ERR_STS_CSR(port->index),
785 return (result & PORT_N_ERR_STS_PORT_OK);
789 * rio_alloc_net- Allocate and configure a new RIO network
790 * @port: Master port associated with the RIO network
792 * Allocates a RIO network structure, initializes per-network
793 * list heads, and adds the associated master port to the
794 * network list of associated master ports. Returns a
795 * RIO network pointer on success or %NULL on failure.
797 static struct rio_net __devinit *rio_alloc_net(struct rio_mport *port)
801 net = kmalloc(sizeof(struct rio_net), GFP_KERNEL);
803 memset(net, 0, sizeof(struct rio_net));
804 INIT_LIST_HEAD(&net->node);
805 INIT_LIST_HEAD(&net->devices);
806 INIT_LIST_HEAD(&net->mports);
807 list_add_tail(&port->nnode, &net->mports);
809 net->id = next_net++;
815 * rio_enum_mport- Start enumeration through a master port
816 * @mport: Master port to send transactions
818 * Starts the enumeration process. If somebody has enumerated our
819 * master port device, then give up. If not and we have an active
820 * link, then start recursive peer enumeration. Returns %0 if
821 * enumeration succeeds or %-EBUSY if enumeration fails.
823 int rio_enum_mport(struct rio_mport *mport)
825 struct rio_net *net = NULL;
828 printk(KERN_INFO "RIO: enumerate master port %d, %s\n", mport->id,
830 /* If somebody else enumerated our master port device, bail. */
831 if (rio_enum_host(mport) < 0) {
833 "RIO: master port %d device has been enumerated by a remote host\n",
839 /* If master port has an active link, allocate net and enum peers */
840 if (rio_mport_is_active(mport)) {
841 if (!(net = rio_alloc_net(mport))) {
842 printk(KERN_ERR "RIO: failed to allocate new net\n");
846 if (rio_enum_peer(net, mport, 0) < 0) {
847 /* A higher priority host won enumeration, bail. */
849 "RIO: master port %d device has lost enumeration to a remote host\n",
851 rio_clear_locks(mport);
855 rio_clear_locks(mport);
857 printk(KERN_INFO "RIO: master port %d link inactive\n",
867 * rio_build_route_tables- Generate route tables from switch route entries
869 * For each switch device, generate a route table by copying existing
870 * route entries from the switch.
872 static void rio_build_route_tables(void)
874 struct rio_dev *rdev;
878 list_for_each_entry(rdev, &rio_devices, global_list)
879 if (rio_is_switch(rdev))
880 for (i = 0; i < RIO_MAX_ROUTE_ENTRIES; i++) {
881 if (rio_route_get_entry
882 (rdev->net->hport, rdev, RIO_GLOBAL_TABLE, i,
885 rdev->rswitch->route_table[i] = sport;
890 * rio_enum_timeout- Signal that enumeration timed out
891 * @data: Address of timeout flag.
893 * When the enumeration complete timer expires, set a flag that
894 * signals to the discovery process that enumeration did not
895 * complete in a sane amount of time.
897 static void rio_enum_timeout(unsigned long data)
899 /* Enumeration timed out, set flag */
904 * rio_disc_mport- Start discovery through a master port
905 * @mport: Master port to send transactions
907 * Starts the discovery process. If we have an active link,
908 * then wait for the signal that enumeration is complete.
909 * When enumeration completion is signaled, start recursive
910 * peer discovery. Returns %0 if discovery succeeds or %-EBUSY
913 int rio_disc_mport(struct rio_mport *mport)
915 struct rio_net *net = NULL;
916 int enum_timeout_flag = 0;
918 printk(KERN_INFO "RIO: discover master port %d, %s\n", mport->id,
921 /* If master port has an active link, allocate net and discover peers */
922 if (rio_mport_is_active(mport)) {
923 if (!(net = rio_alloc_net(mport))) {
924 printk(KERN_ERR "RIO: Failed to allocate new net\n");
928 pr_debug("RIO: wait for enumeration complete...");
930 rio_enum_timer.expires =
931 jiffies + CONFIG_RAPIDIO_DISC_TIMEOUT * HZ;
932 rio_enum_timer.data = (unsigned long)&enum_timeout_flag;
933 add_timer(&rio_enum_timer);
934 while (!rio_enum_complete(mport)) {
936 if (enum_timeout_flag) {
937 del_timer_sync(&rio_enum_timer);
941 del_timer_sync(&rio_enum_timer);
944 if (rio_disc_peer(net, mport, RIO_ANY_DESTID, 0) < 0) {
946 "RIO: master port %d device has failed discovery\n",
951 rio_build_route_tables();
957 pr_debug("timeout\n");