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/types.h>
14 #include <linux/kernel.h>
16 #include <linux/delay.h>
17 #include <linux/dma-mapping.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>
26 #include <linux/jiffies.h>
27 #include <linux/slab.h>
31 LIST_HEAD(rio_devices);
32 static LIST_HEAD(rio_switches);
34 #define RIO_ENUM_CMPL_MAGIC 0xdeadbeef
36 static void rio_enum_timeout(unsigned long);
38 DEFINE_SPINLOCK(rio_global_list_lock);
40 static int next_destid = 0;
41 static int next_switchid = 0;
42 static int next_net = 0;
44 static struct timer_list rio_enum_timer =
45 TIMER_INITIALIZER(rio_enum_timeout, 0, 0);
47 static int rio_mport_phys_table[] = {
49 RIO_EFB_PAR_EP_REC_ID,
51 RIO_EFB_SER_EP_REC_ID,
55 static int rio_sport_phys_table[] = {
56 RIO_EFB_PAR_EP_FREE_ID,
57 RIO_EFB_SER_EP_FREE_ID,
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(port->sys_size, 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.
88 static void rio_set_device_id(struct rio_mport *port, u16 destid, u8 hopcount, u16 did)
90 rio_mport_write_config_32(port, destid, hopcount, RIO_DID_CSR,
91 RIO_SET_DID(port->sys_size, did));
95 * rio_local_set_device_id - Set the base/extended device id for a port
96 * @port: RIO master port
97 * @did: Device ID value to be written
99 * Writes the base/extended device id from a device.
101 static void rio_local_set_device_id(struct rio_mport *port, u16 did)
103 rio_local_write_config_32(port, RIO_DID_CSR, RIO_SET_DID(port->sys_size,
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 u32 mask = RIO_OPS_READ | RIO_OPS_WRITE | RIO_OPS_ATOMIC_TST_SWP | RIO_OPS_ATOMIC_INC | RIO_OPS_ATOMIC_DEC | RIO_OPS_ATOMIC_SET | RIO_OPS_ATOMIC_CLR;
197 return !!((src_ops | dst_ops) & mask);
201 * rio_release_dev- Frees a RIO device struct
202 * @dev: LDM device associated with a RIO device struct
204 * Gets the RIO device struct associated a RIO device struct.
205 * The RIO device struct is freed.
207 static void rio_release_dev(struct device *dev)
209 struct rio_dev *rdev;
211 rdev = to_rio_dev(dev);
216 * rio_is_switch- Tests if a RIO device has switch capabilities
219 * Gets the RIO device Processing Element Features register
220 * contents and tests for switch capabilities. Returns 1 if
221 * the device is a switch or 0 if it is not a switch.
222 * The RIO device struct is freed.
224 static int rio_is_switch(struct rio_dev *rdev)
226 if (rdev->pef & RIO_PEF_SWITCH)
232 * rio_route_set_ops- Sets routing operations for a particular vendor switch
235 * Searches the RIO route ops table for known switch types. If the vid
236 * and did match a switch table entry, then set the add_entry() and
237 * get_entry() ops to the table entry values.
239 static void rio_route_set_ops(struct rio_dev *rdev)
241 struct rio_route_ops *cur = __start_rio_route_ops;
242 struct rio_route_ops *end = __end_rio_route_ops;
245 if ((cur->vid == rdev->vid) && (cur->did == rdev->did)) {
246 pr_debug("RIO: adding routing ops for %s\n", rio_name(rdev));
247 rdev->rswitch->add_entry = cur->add_hook;
248 rdev->rswitch->get_entry = cur->get_hook;
253 if (!rdev->rswitch->add_entry || !rdev->rswitch->get_entry)
254 printk(KERN_ERR "RIO: missing routing ops for %s\n",
259 * rio_add_device- Adds a RIO device to the device model
262 * Adds the RIO device to the global device list and adds the RIO
263 * device to the RIO device list. Creates the generic sysfs nodes
266 static int __devinit rio_add_device(struct rio_dev *rdev)
270 err = device_add(&rdev->dev);
274 spin_lock(&rio_global_list_lock);
275 list_add_tail(&rdev->global_list, &rio_devices);
276 spin_unlock(&rio_global_list_lock);
278 rio_create_sysfs_dev_files(rdev);
284 * rio_setup_device- Allocates and sets up a RIO device
286 * @port: Master port to send transactions
287 * @destid: Current destination ID
288 * @hopcount: Current hopcount
289 * @do_enum: Enumeration/Discovery mode flag
291 * Allocates a RIO device and configures fields based on configuration
292 * space contents. If device has a destination ID register, a destination
293 * ID is either assigned in enumeration mode or read from configuration
294 * space in discovery mode. If the device has switch capabilities, then
295 * a switch is allocated and configured appropriately. Returns a pointer
296 * to a RIO device on success or NULL on failure.
299 static struct rio_dev __devinit *rio_setup_device(struct rio_net *net,
300 struct rio_mport *port, u16 destid,
301 u8 hopcount, int do_enum)
304 struct rio_dev *rdev;
305 struct rio_switch *rswitch = NULL;
308 rdev = kzalloc(sizeof(struct rio_dev), GFP_KERNEL);
313 rio_mport_read_config_32(port, destid, hopcount, RIO_DEV_ID_CAR,
315 rdev->did = result >> 16;
316 rdev->vid = result & 0xffff;
317 rio_mport_read_config_32(port, destid, hopcount, RIO_DEV_INFO_CAR,
319 rio_mport_read_config_32(port, destid, hopcount, RIO_ASM_ID_CAR,
321 rdev->asm_did = result >> 16;
322 rdev->asm_vid = result & 0xffff;
323 rio_mport_read_config_32(port, destid, hopcount, RIO_ASM_INFO_CAR,
325 rdev->asm_rev = result >> 16;
326 rio_mport_read_config_32(port, destid, hopcount, RIO_PEF_CAR,
328 if (rdev->pef & RIO_PEF_EXT_FEATURES)
329 rdev->efptr = result & 0xffff;
331 rio_mport_read_config_32(port, destid, hopcount, RIO_SRC_OPS_CAR,
333 rio_mport_read_config_32(port, destid, hopcount, RIO_DST_OPS_CAR,
336 if (rio_device_has_destid(port, rdev->src_ops, rdev->dst_ops)) {
338 rio_set_device_id(port, destid, hopcount, next_destid);
339 rdev->destid = next_destid++;
340 if (next_destid == port->host_deviceid)
343 rdev->destid = rio_get_device_id(port, destid, hopcount);
345 /* Switch device has an associated destID */
346 rdev->destid = RIO_INVALID_DESTID;
348 /* If a PE has both switch and other functions, show it as a switch */
349 if (rio_is_switch(rdev)) {
350 rio_mport_read_config_32(port, destid, hopcount,
351 RIO_SWP_INFO_CAR, &rdev->swpinfo);
352 rswitch = kmalloc(sizeof(struct rio_switch), GFP_KERNEL);
355 rswitch->switchid = next_switchid;
356 rswitch->hopcount = hopcount;
357 rswitch->destid = destid;
358 rswitch->route_table = kzalloc(sizeof(u8)*
359 RIO_MAX_ROUTE_ENTRIES(port->sys_size),
361 if (!rswitch->route_table)
363 /* Initialize switch route table */
364 for (rdid = 0; rdid < RIO_MAX_ROUTE_ENTRIES(port->sys_size);
366 rswitch->route_table[rdid] = RIO_INVALID_ROUTE;
367 rdev->rswitch = rswitch;
368 dev_set_name(&rdev->dev, "%02x:s:%04x", rdev->net->id,
369 rdev->rswitch->switchid);
370 rio_route_set_ops(rdev);
372 list_add_tail(&rswitch->node, &rio_switches);
375 dev_set_name(&rdev->dev, "%02x:e:%04x", rdev->net->id,
378 rdev->dev.bus = &rio_bus_type;
380 device_initialize(&rdev->dev);
381 rdev->dev.release = rio_release_dev;
384 rdev->dma_mask = DMA_BIT_MASK(32);
385 rdev->dev.dma_mask = &rdev->dma_mask;
386 rdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
388 if ((rdev->pef & RIO_PEF_INB_DOORBELL) &&
389 (rdev->dst_ops & RIO_DST_OPS_DOORBELL))
390 rio_init_dbell_res(&rdev->riores[RIO_DOORBELL_RESOURCE],
393 ret = rio_add_device(rdev);
401 kfree(rswitch->route_table);
409 * rio_sport_is_active- Tests if a switch port has an active connection.
410 * @port: Master port to send transaction
411 * @destid: Associated destination ID for switch
412 * @hopcount: Hopcount to reach switch
413 * @sport: Switch port number
415 * Reads the port error status CSR for a particular switch port to
416 * determine if the port has an active link. Returns
417 * %PORT_N_ERR_STS_PORT_OK if the port is active or %0 if it is
421 rio_sport_is_active(struct rio_mport *port, u16 destid, u8 hopcount, int sport)
426 int *entry = rio_sport_phys_table;
430 rio_mport_get_feature(port, 0, destid, hopcount, *entry)))
433 } while (*++entry >= 0);
436 rio_mport_read_config_32(port, destid, hopcount,
438 RIO_PORT_N_ERR_STS_CSR(sport),
441 return (result & PORT_N_ERR_STS_PORT_OK);
445 * rio_route_add_entry- Add a route entry to a switch routing table
446 * @mport: Master port to send transaction
447 * @rswitch: Switch device
448 * @table: Routing table ID
449 * @route_destid: Destination ID to be routed
450 * @route_port: Port number to be routed
452 * Calls the switch specific add_entry() method to add a route entry
453 * on a switch. The route table can be specified using the @table
454 * argument if a switch has per port routing tables or the normal
455 * use is to specific all tables (or the global table) by passing
456 * %RIO_GLOBAL_TABLE in @table. Returns %0 on success or %-EINVAL
459 static int rio_route_add_entry(struct rio_mport *mport, struct rio_switch *rswitch,
460 u16 table, u16 route_destid, u8 route_port)
462 return rswitch->add_entry(mport, rswitch->destid,
463 rswitch->hopcount, table,
464 route_destid, route_port);
468 * rio_route_get_entry- Read a route entry in a switch routing table
469 * @mport: Master port to send transaction
470 * @rswitch: Switch device
471 * @table: Routing table ID
472 * @route_destid: Destination ID to be routed
473 * @route_port: Pointer to read port number into
475 * Calls the switch specific get_entry() method to read a route entry
476 * in a switch. The route table can be specified using the @table
477 * argument if a switch has per port routing tables or the normal
478 * use is to specific all tables (or the global table) by passing
479 * %RIO_GLOBAL_TABLE in @table. Returns %0 on success or %-EINVAL
483 rio_route_get_entry(struct rio_mport *mport, struct rio_switch *rswitch, u16 table,
484 u16 route_destid, u8 * route_port)
486 return rswitch->get_entry(mport, rswitch->destid,
487 rswitch->hopcount, table,
488 route_destid, route_port);
492 * rio_get_host_deviceid_lock- Reads the Host Device ID Lock CSR on a device
493 * @port: Master port to send transaction
494 * @hopcount: Number of hops to the device
496 * Used during enumeration to read the Host Device ID Lock CSR on a
497 * RIO device. Returns the value of the lock register.
499 static u16 rio_get_host_deviceid_lock(struct rio_mport *port, u8 hopcount)
503 rio_mport_read_config_32(port, RIO_ANY_DESTID(port->sys_size), hopcount,
504 RIO_HOST_DID_LOCK_CSR, &result);
506 return (u16) (result & 0xffff);
510 * rio_get_swpinfo_inport- Gets the ingress port number
511 * @mport: Master port to send transaction
512 * @destid: Destination ID associated with the switch
513 * @hopcount: Number of hops to the device
515 * Returns port number being used to access the switch device.
518 rio_get_swpinfo_inport(struct rio_mport *mport, u16 destid, u8 hopcount)
522 rio_mport_read_config_32(mport, destid, hopcount, RIO_SWP_INFO_CAR,
525 return (u8) (result & 0xff);
529 * rio_get_swpinfo_tports- Gets total number of ports on the switch
530 * @mport: Master port to send transaction
531 * @destid: Destination ID associated with the switch
532 * @hopcount: Number of hops to the device
534 * Returns total numbers of ports implemented by the switch device.
536 static u8 rio_get_swpinfo_tports(struct rio_mport *mport, u16 destid,
541 rio_mport_read_config_32(mport, destid, hopcount, RIO_SWP_INFO_CAR,
544 return RIO_GET_TOTAL_PORTS(result);
548 * rio_net_add_mport- Add a master port to a RIO network
550 * @port: Master port to add
552 * Adds a master port to the network list of associated master
555 static void rio_net_add_mport(struct rio_net *net, struct rio_mport *port)
557 spin_lock(&rio_global_list_lock);
558 list_add_tail(&port->nnode, &net->mports);
559 spin_unlock(&rio_global_list_lock);
563 * rio_enum_peer- Recursively enumerate a RIO network through a master port
564 * @net: RIO network being enumerated
565 * @port: Master port to send transactions
566 * @hopcount: Number of hops into the network
568 * Recursively enumerates a RIO network. Transactions are sent via the
569 * master port passed in @port.
571 static int __devinit rio_enum_peer(struct rio_net *net, struct rio_mport *port,
579 struct rio_dev *rdev;
583 if (rio_get_host_deviceid_lock(port, hopcount) == port->host_deviceid) {
584 pr_debug("RIO: PE already discovered by this host\n");
586 * Already discovered by this host. Add it as another
587 * master port for the current network.
589 rio_net_add_mport(net, port);
593 /* Attempt to acquire device lock */
594 rio_mport_write_config_32(port, RIO_ANY_DESTID(port->sys_size),
596 RIO_HOST_DID_LOCK_CSR, port->host_deviceid);
597 while ((tmp = rio_get_host_deviceid_lock(port, hopcount))
598 < port->host_deviceid) {
601 /* Attempt to acquire device lock again */
602 rio_mport_write_config_32(port, RIO_ANY_DESTID(port->sys_size),
604 RIO_HOST_DID_LOCK_CSR,
605 port->host_deviceid);
608 if (rio_get_host_deviceid_lock(port, hopcount) > port->host_deviceid) {
610 "RIO: PE locked by a higher priority host...retreating\n");
614 /* Setup new RIO device */
615 rdev = rio_setup_device(net, port, RIO_ANY_DESTID(port->sys_size),
618 /* Add device to the global and bus/net specific list. */
619 list_add_tail(&rdev->net_list, &net->devices);
623 if (rio_is_switch(rdev)) {
625 sw_inport = rio_get_swpinfo_inport(port,
626 RIO_ANY_DESTID(port->sys_size), hopcount);
627 rio_route_add_entry(port, rdev->rswitch, RIO_GLOBAL_TABLE,
628 port->host_deviceid, sw_inport);
629 rdev->rswitch->route_table[port->host_deviceid] = sw_inport;
631 for (destid = 0; destid < next_destid; destid++) {
632 if (destid == port->host_deviceid)
634 rio_route_add_entry(port, rdev->rswitch, RIO_GLOBAL_TABLE,
636 rdev->rswitch->route_table[destid] = sw_inport;
640 rio_get_swpinfo_tports(port, RIO_ANY_DESTID(port->sys_size),
643 "RIO: found %s (vid %4.4x did %4.4x) with %d ports\n",
644 rio_name(rdev), rdev->vid, rdev->did, num_ports);
645 sw_destid = next_destid;
646 for (port_num = 0; port_num < num_ports; port_num++) {
647 if (sw_inport == port_num)
650 cur_destid = next_destid;
652 if (rio_sport_is_active
653 (port, RIO_ANY_DESTID(port->sys_size), hopcount,
656 "RIO: scanning device on port %d\n",
658 rio_route_add_entry(port, rdev->rswitch,
660 RIO_ANY_DESTID(port->sys_size),
663 if (rio_enum_peer(net, port, hopcount + 1) < 0)
666 /* Update routing tables */
667 if (next_destid > cur_destid) {
668 for (destid = cur_destid;
669 destid < next_destid; destid++) {
670 if (destid == port->host_deviceid)
672 rio_route_add_entry(port, rdev->rswitch,
677 route_table[destid] =
684 /* Check for empty switch */
685 if (next_destid == sw_destid) {
687 if (next_destid == port->host_deviceid)
691 rdev->rswitch->destid = sw_destid;
693 pr_debug("RIO: found %s (vid %4.4x did %4.4x)\n",
694 rio_name(rdev), rdev->vid, rdev->did);
700 * rio_enum_complete- Tests if enumeration of a network is complete
701 * @port: Master port to send transaction
703 * Tests the Component Tag CSR for presence of the magic enumeration
704 * complete flag. Return %1 if enumeration is complete or %0 if
705 * enumeration is incomplete.
707 static int rio_enum_complete(struct rio_mport *port)
712 rio_local_read_config_32(port, RIO_COMPONENT_TAG_CSR, &tag_csr);
714 if (tag_csr == RIO_ENUM_CMPL_MAGIC)
721 * rio_disc_peer- Recursively discovers a RIO network through a master port
722 * @net: RIO network being discovered
723 * @port: Master port to send transactions
724 * @destid: Current destination ID in network
725 * @hopcount: Number of hops into the network
727 * Recursively discovers a RIO network. Transactions are sent via the
728 * master port passed in @port.
731 rio_disc_peer(struct rio_net *net, struct rio_mport *port, u16 destid,
734 u8 port_num, route_port;
736 struct rio_dev *rdev;
739 /* Setup new RIO device */
740 if ((rdev = rio_setup_device(net, port, destid, hopcount, 0))) {
741 /* Add device to the global and bus/net specific list. */
742 list_add_tail(&rdev->net_list, &net->devices);
746 if (rio_is_switch(rdev)) {
749 /* Associated destid is how we accessed this switch */
750 rdev->rswitch->destid = destid;
752 num_ports = rio_get_swpinfo_tports(port, destid, hopcount);
754 "RIO: found %s (vid %4.4x did %4.4x) with %d ports\n",
755 rio_name(rdev), rdev->vid, rdev->did, num_ports);
756 for (port_num = 0; port_num < num_ports; port_num++) {
757 if (rio_get_swpinfo_inport(port, destid, hopcount) ==
761 if (rio_sport_is_active
762 (port, destid, hopcount, port_num)) {
764 "RIO: scanning device on port %d\n",
767 ndestid < RIO_ANY_DESTID(port->sys_size);
769 rio_route_get_entry(port, rdev->rswitch,
773 if (route_port == port_num)
778 (net, port, ndestid, hopcount + 1) < 0)
783 pr_debug("RIO: found %s (vid %4.4x did %4.4x)\n",
784 rio_name(rdev), rdev->vid, rdev->did);
790 * rio_mport_is_active- Tests if master port link is active
791 * @port: Master port to test
793 * Reads the port error status CSR for the master port to
794 * determine if the port has an active link. Returns
795 * %PORT_N_ERR_STS_PORT_OK if the master port is active
796 * or %0 if it is inactive.
798 static int rio_mport_is_active(struct rio_mport *port)
802 int *entry = rio_mport_phys_table;
806 rio_mport_get_feature(port, 1, 0, 0, *entry)))
808 } while (*++entry >= 0);
811 rio_local_read_config_32(port,
813 RIO_PORT_N_ERR_STS_CSR(port->index),
816 return (result & PORT_N_ERR_STS_PORT_OK);
820 * rio_alloc_net- Allocate and configure a new RIO network
821 * @port: Master port associated with the RIO network
823 * Allocates a RIO network structure, initializes per-network
824 * list heads, and adds the associated master port to the
825 * network list of associated master ports. Returns a
826 * RIO network pointer on success or %NULL on failure.
828 static struct rio_net __devinit *rio_alloc_net(struct rio_mport *port)
832 net = kzalloc(sizeof(struct rio_net), GFP_KERNEL);
834 INIT_LIST_HEAD(&net->node);
835 INIT_LIST_HEAD(&net->devices);
836 INIT_LIST_HEAD(&net->mports);
837 list_add_tail(&port->nnode, &net->mports);
839 net->id = next_net++;
845 * rio_update_route_tables- Updates route tables in switches
846 * @port: Master port associated with the RIO network
848 * For each enumerated device, ensure that each switch in a system
849 * has correct routing entries. Add routes for devices that where
850 * unknown dirung the first enumeration pass through the switch.
852 static void rio_update_route_tables(struct rio_mport *port)
854 struct rio_dev *rdev;
855 struct rio_switch *rswitch;
859 list_for_each_entry(rdev, &rio_devices, global_list) {
861 destid = (rio_is_switch(rdev))?rdev->rswitch->destid:rdev->destid;
863 list_for_each_entry(rswitch, &rio_switches, node) {
865 if (rio_is_switch(rdev) && (rdev->rswitch == rswitch))
868 if (RIO_INVALID_ROUTE == rswitch->route_table[destid]) {
870 sport = rio_get_swpinfo_inport(port,
871 rswitch->destid, rswitch->hopcount);
873 if (rswitch->add_entry) {
874 rio_route_add_entry(port, rswitch, RIO_GLOBAL_TABLE, destid, sport);
875 rswitch->route_table[destid] = sport;
883 * rio_enum_mport- Start enumeration through a master port
884 * @mport: Master port to send transactions
886 * Starts the enumeration process. If somebody has enumerated our
887 * master port device, then give up. If not and we have an active
888 * link, then start recursive peer enumeration. Returns %0 if
889 * enumeration succeeds or %-EBUSY if enumeration fails.
891 int __devinit rio_enum_mport(struct rio_mport *mport)
893 struct rio_net *net = NULL;
896 printk(KERN_INFO "RIO: enumerate master port %d, %s\n", mport->id,
898 /* If somebody else enumerated our master port device, bail. */
899 if (rio_enum_host(mport) < 0) {
901 "RIO: master port %d device has been enumerated by a remote host\n",
907 /* If master port has an active link, allocate net and enum peers */
908 if (rio_mport_is_active(mport)) {
909 if (!(net = rio_alloc_net(mport))) {
910 printk(KERN_ERR "RIO: failed to allocate new net\n");
914 if (rio_enum_peer(net, mport, 0) < 0) {
915 /* A higher priority host won enumeration, bail. */
917 "RIO: master port %d device has lost enumeration to a remote host\n",
919 rio_clear_locks(mport);
923 rio_update_route_tables(mport);
924 rio_clear_locks(mport);
926 printk(KERN_INFO "RIO: master port %d link inactive\n",
936 * rio_build_route_tables- Generate route tables from switch route entries
938 * For each switch device, generate a route table by copying existing
939 * route entries from the switch.
941 static void rio_build_route_tables(void)
943 struct rio_dev *rdev;
947 list_for_each_entry(rdev, &rio_devices, global_list)
948 if (rio_is_switch(rdev))
950 i < RIO_MAX_ROUTE_ENTRIES(rdev->net->hport->sys_size);
952 if (rio_route_get_entry
953 (rdev->net->hport, rdev->rswitch, RIO_GLOBAL_TABLE,
956 rdev->rswitch->route_table[i] = sport;
961 * rio_enum_timeout- Signal that enumeration timed out
962 * @data: Address of timeout flag.
964 * When the enumeration complete timer expires, set a flag that
965 * signals to the discovery process that enumeration did not
966 * complete in a sane amount of time.
968 static void rio_enum_timeout(unsigned long data)
970 /* Enumeration timed out, set flag */
975 * rio_disc_mport- Start discovery through a master port
976 * @mport: Master port to send transactions
978 * Starts the discovery process. If we have an active link,
979 * then wait for the signal that enumeration is complete.
980 * When enumeration completion is signaled, start recursive
981 * peer discovery. Returns %0 if discovery succeeds or %-EBUSY
984 int __devinit rio_disc_mport(struct rio_mport *mport)
986 struct rio_net *net = NULL;
987 int enum_timeout_flag = 0;
989 printk(KERN_INFO "RIO: discover master port %d, %s\n", mport->id,
992 /* If master port has an active link, allocate net and discover peers */
993 if (rio_mport_is_active(mport)) {
994 if (!(net = rio_alloc_net(mport))) {
995 printk(KERN_ERR "RIO: Failed to allocate new net\n");
999 pr_debug("RIO: wait for enumeration complete...");
1001 rio_enum_timer.expires =
1002 jiffies + CONFIG_RAPIDIO_DISC_TIMEOUT * HZ;
1003 rio_enum_timer.data = (unsigned long)&enum_timeout_flag;
1004 add_timer(&rio_enum_timer);
1005 while (!rio_enum_complete(mport)) {
1007 if (enum_timeout_flag) {
1008 del_timer_sync(&rio_enum_timer);
1012 del_timer_sync(&rio_enum_timer);
1015 if (rio_disc_peer(net, mport, RIO_ANY_DESTID(mport->sys_size),
1018 "RIO: master port %d device has failed discovery\n",
1023 rio_build_route_tables();
1029 pr_debug("timeout\n");