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/dma-mapping.h>
19 #include <linux/init.h>
20 #include <linux/rio.h>
21 #include <linux/rio_drv.h>
22 #include <linux/rio_ids.h>
23 #include <linux/rio_regs.h>
24 #include <linux/module.h>
25 #include <linux/spinlock.h>
26 #include <linux/timer.h>
30 LIST_HEAD(rio_devices
);
31 static LIST_HEAD(rio_switches
);
33 #define RIO_ENUM_CMPL_MAGIC 0xdeadbeef
35 static void rio_enum_timeout(unsigned long);
37 DEFINE_SPINLOCK(rio_global_list_lock
);
39 static int next_destid
= 0;
40 static int next_switchid
= 0;
41 static int next_net
= 0;
43 static struct timer_list rio_enum_timer
=
44 TIMER_INITIALIZER(rio_enum_timeout
, 0, 0);
46 static int rio_mport_phys_table
[] = {
48 RIO_EFB_PAR_EP_REC_ID
,
50 RIO_EFB_SER_EP_REC_ID
,
54 static int rio_sport_phys_table
[] = {
55 RIO_EFB_PAR_EP_FREE_ID
,
56 RIO_EFB_SER_EP_FREE_ID
,
61 * rio_get_device_id - Get the base/extended device id for a device
62 * @port: RIO master port
63 * @destid: Destination ID of device
64 * @hopcount: Hopcount to device
66 * Reads the base/extended device id from a device. Returns the
69 static u16
rio_get_device_id(struct rio_mport
*port
, u16 destid
, u8 hopcount
)
73 rio_mport_read_config_32(port
, destid
, hopcount
, RIO_DID_CSR
, &result
);
75 return RIO_GET_DID(result
);
79 * rio_set_device_id - Set the base/extended device id for a device
80 * @port: RIO master port
81 * @destid: Destination ID of device
82 * @hopcount: Hopcount to device
83 * @did: Device ID value to be written
85 * Writes the base/extended device id from a device.
87 static void rio_set_device_id(struct rio_mport
*port
, u16 destid
, u8 hopcount
, u16 did
)
89 rio_mport_write_config_32(port
, destid
, hopcount
, RIO_DID_CSR
,
94 * rio_local_set_device_id - Set the base/extended device id for a port
95 * @port: RIO master port
96 * @did: Device ID value to be written
98 * Writes the base/extended device id from a device.
100 static void rio_local_set_device_id(struct rio_mport
*port
, u16 did
)
102 rio_local_write_config_32(port
, RIO_DID_CSR
, RIO_SET_DID(did
));
106 * rio_clear_locks- Release all host locks and signal enumeration complete
107 * @port: Master port to issue transaction
109 * Marks the component tag CSR on each device with the enumeration
110 * complete flag. When complete, it then release the host locks on
111 * each device. Returns 0 on success or %-EINVAL on failure.
113 static int rio_clear_locks(struct rio_mport
*port
)
115 struct rio_dev
*rdev
;
119 /* Write component tag CSR magic complete value */
120 rio_local_write_config_32(port
, RIO_COMPONENT_TAG_CSR
,
121 RIO_ENUM_CMPL_MAGIC
);
122 list_for_each_entry(rdev
, &rio_devices
, global_list
)
123 rio_write_config_32(rdev
, RIO_COMPONENT_TAG_CSR
,
124 RIO_ENUM_CMPL_MAGIC
);
126 /* Release host device id locks */
127 rio_local_write_config_32(port
, RIO_HOST_DID_LOCK_CSR
,
128 port
->host_deviceid
);
129 rio_local_read_config_32(port
, RIO_HOST_DID_LOCK_CSR
, &result
);
130 if ((result
& 0xffff) != 0xffff) {
132 "RIO: badness when releasing host lock on master port, result %8.8x\n",
136 list_for_each_entry(rdev
, &rio_devices
, global_list
) {
137 rio_write_config_32(rdev
, RIO_HOST_DID_LOCK_CSR
,
138 port
->host_deviceid
);
139 rio_read_config_32(rdev
, RIO_HOST_DID_LOCK_CSR
, &result
);
140 if ((result
& 0xffff) != 0xffff) {
142 "RIO: badness when releasing host lock on vid %4.4x did %4.4x\n",
143 rdev
->vid
, rdev
->did
);
152 * rio_enum_host- Set host lock and initialize host destination ID
153 * @port: Master port to issue transaction
155 * Sets the local host master port lock and destination ID register
156 * with the host device ID value. The host device ID value is provided
157 * by the platform. Returns %0 on success or %-1 on failure.
159 static int rio_enum_host(struct rio_mport
*port
)
163 /* Set master port host device id lock */
164 rio_local_write_config_32(port
, RIO_HOST_DID_LOCK_CSR
,
165 port
->host_deviceid
);
167 rio_local_read_config_32(port
, RIO_HOST_DID_LOCK_CSR
, &result
);
168 if ((result
& 0xffff) != port
->host_deviceid
)
171 /* Set master port destid and init destid ctr */
172 rio_local_set_device_id(port
, port
->host_deviceid
);
174 if (next_destid
== port
->host_deviceid
)
181 * rio_device_has_destid- Test if a device contains a destination ID register
182 * @port: Master port to issue transaction
183 * @src_ops: RIO device source operations
184 * @dst_ops: RIO device destination operations
186 * Checks the provided @src_ops and @dst_ops for the necessary transaction
187 * capabilities that indicate whether or not a device will implement a
188 * destination ID register. Returns 1 if true or 0 if false.
190 static int rio_device_has_destid(struct rio_mport
*port
, int src_ops
,
193 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
;
195 return !!((src_ops
| dst_ops
) & mask
);
199 * rio_release_dev- Frees a RIO device struct
200 * @dev: LDM device associated with a RIO device struct
202 * Gets the RIO device struct associated a RIO device struct.
203 * The RIO device struct is freed.
205 static void rio_release_dev(struct device
*dev
)
207 struct rio_dev
*rdev
;
209 rdev
= to_rio_dev(dev
);
214 * rio_is_switch- Tests if a RIO device has switch capabilities
217 * Gets the RIO device Processing Element Features register
218 * contents and tests for switch capabilities. Returns 1 if
219 * the device is a switch or 0 if it is not a switch.
220 * The RIO device struct is freed.
222 static int rio_is_switch(struct rio_dev
*rdev
)
224 if (rdev
->pef
& RIO_PEF_SWITCH
)
230 * rio_route_set_ops- Sets routing operations for a particular vendor switch
233 * Searches the RIO route ops table for known switch types. If the vid
234 * and did match a switch table entry, then set the add_entry() and
235 * get_entry() ops to the table entry values.
237 static void rio_route_set_ops(struct rio_dev
*rdev
)
239 struct rio_route_ops
*cur
= __start_rio_route_ops
;
240 struct rio_route_ops
*end
= __end_rio_route_ops
;
243 if ((cur
->vid
== rdev
->vid
) && (cur
->did
== rdev
->did
)) {
244 pr_debug("RIO: adding routing ops for %s\n", rio_name(rdev
));
245 rdev
->rswitch
->add_entry
= cur
->add_hook
;
246 rdev
->rswitch
->get_entry
= cur
->get_hook
;
251 if (!rdev
->rswitch
->add_entry
|| !rdev
->rswitch
->get_entry
)
252 printk(KERN_ERR
"RIO: missing routing ops for %s\n",
257 * rio_add_device- Adds a RIO device to the device model
260 * Adds the RIO device to the global device list and adds the RIO
261 * device to the RIO device list. Creates the generic sysfs nodes
264 static void __devinit
rio_add_device(struct rio_dev
*rdev
)
266 device_add(&rdev
->dev
);
268 spin_lock(&rio_global_list_lock
);
269 list_add_tail(&rdev
->global_list
, &rio_devices
);
270 spin_unlock(&rio_global_list_lock
);
272 rio_create_sysfs_dev_files(rdev
);
276 * rio_setup_device- Allocates and sets up a RIO device
278 * @port: Master port to send transactions
279 * @destid: Current destination ID
280 * @hopcount: Current hopcount
281 * @do_enum: Enumeration/Discovery mode flag
283 * Allocates a RIO device and configures fields based on configuration
284 * space contents. If device has a destination ID register, a destination
285 * ID is either assigned in enumeration mode or read from configuration
286 * space in discovery mode. If the device has switch capabilities, then
287 * a switch is allocated and configured appropriately. Returns a pointer
288 * to a RIO device on success or NULL on failure.
291 static struct rio_dev
*rio_setup_device(struct rio_net
*net
,
292 struct rio_mport
*port
, u16 destid
,
293 u8 hopcount
, int do_enum
)
295 struct rio_dev
*rdev
;
296 struct rio_switch
*rswitch
;
299 rdev
= kmalloc(sizeof(struct rio_dev
), GFP_KERNEL
);
303 memset(rdev
, 0, sizeof(struct rio_dev
));
305 rio_mport_read_config_32(port
, destid
, hopcount
, RIO_DEV_ID_CAR
,
307 rdev
->did
= result
>> 16;
308 rdev
->vid
= result
& 0xffff;
309 rio_mport_read_config_32(port
, destid
, hopcount
, RIO_DEV_INFO_CAR
,
311 rio_mport_read_config_32(port
, destid
, hopcount
, RIO_ASM_ID_CAR
,
313 rdev
->asm_did
= result
>> 16;
314 rdev
->asm_vid
= result
& 0xffff;
315 rio_mport_read_config_32(port
, destid
, hopcount
, RIO_ASM_INFO_CAR
,
317 rdev
->asm_rev
= result
>> 16;
318 rio_mport_read_config_32(port
, destid
, hopcount
, RIO_PEF_CAR
,
320 if (rdev
->pef
& RIO_PEF_EXT_FEATURES
)
321 rdev
->efptr
= result
& 0xffff;
323 rio_mport_read_config_32(port
, destid
, hopcount
, RIO_SRC_OPS_CAR
,
325 rio_mport_read_config_32(port
, destid
, hopcount
, RIO_DST_OPS_CAR
,
328 if (rio_device_has_destid(port
, rdev
->src_ops
, rdev
->dst_ops
)
330 rio_set_device_id(port
, destid
, hopcount
, next_destid
);
331 rdev
->destid
= next_destid
++;
332 if (next_destid
== port
->host_deviceid
)
335 rdev
->destid
= rio_get_device_id(port
, destid
, hopcount
);
337 /* If a PE has both switch and other functions, show it as a switch */
338 if (rio_is_switch(rdev
)) {
339 rio_mport_read_config_32(port
, destid
, hopcount
,
340 RIO_SWP_INFO_CAR
, &rdev
->swpinfo
);
341 rswitch
= kmalloc(sizeof(struct rio_switch
), GFP_KERNEL
);
347 rswitch
->switchid
= next_switchid
;
348 rswitch
->hopcount
= hopcount
;
349 rswitch
->destid
= 0xffff;
350 /* Initialize switch route table */
351 for (rdid
= 0; rdid
< RIO_MAX_ROUTE_ENTRIES
; rdid
++)
352 rswitch
->route_table
[rdid
] = RIO_INVALID_ROUTE
;
353 rdev
->rswitch
= rswitch
;
354 sprintf(rio_name(rdev
), "%02x:s:%04x", rdev
->net
->id
,
355 rdev
->rswitch
->switchid
);
356 rio_route_set_ops(rdev
);
358 list_add_tail(&rswitch
->node
, &rio_switches
);
361 sprintf(rio_name(rdev
), "%02x:e:%04x", rdev
->net
->id
,
364 rdev
->dev
.bus
= &rio_bus_type
;
366 device_initialize(&rdev
->dev
);
367 rdev
->dev
.release
= rio_release_dev
;
370 rdev
->dma_mask
= DMA_32BIT_MASK
;
371 rdev
->dev
.dma_mask
= &rdev
->dma_mask
;
372 rdev
->dev
.coherent_dma_mask
= DMA_32BIT_MASK
;
374 if ((rdev
->pef
& RIO_PEF_INB_DOORBELL
) &&
375 (rdev
->dst_ops
& RIO_DST_OPS_DOORBELL
))
376 rio_init_dbell_res(&rdev
->riores
[RIO_DOORBELL_RESOURCE
],
379 rio_add_device(rdev
);
386 * rio_sport_is_active- Tests if a switch port has an active connection.
387 * @port: Master port to send transaction
388 * @destid: Associated destination ID for switch
389 * @hopcount: Hopcount to reach switch
390 * @sport: Switch port number
392 * Reads the port error status CSR for a particular switch port to
393 * determine if the port has an active link. Returns
394 * %PORT_N_ERR_STS_PORT_OK if the port is active or %0 if it is
398 rio_sport_is_active(struct rio_mport
*port
, u16 destid
, u8 hopcount
, int sport
)
403 int *entry
= rio_sport_phys_table
;
407 rio_mport_get_feature(port
, 0, destid
, hopcount
, *entry
)))
410 } while (*++entry
>= 0);
413 rio_mport_read_config_32(port
, destid
, hopcount
,
415 RIO_PORT_N_ERR_STS_CSR(sport
),
418 return (result
& PORT_N_ERR_STS_PORT_OK
);
422 * rio_route_add_entry- Add a route entry to a switch routing table
423 * @mport: Master port to send transaction
424 * @rdev: Switch device
425 * @table: Routing table ID
426 * @route_destid: Destination ID to be routed
427 * @route_port: Port number to be routed
429 * Calls the switch specific add_entry() method to add a route entry
430 * on a switch. The route table can be specified using the @table
431 * argument if a switch has per port routing tables or the normal
432 * use is to specific all tables (or the global table) by passing
433 * %RIO_GLOBAL_TABLE in @table. Returns %0 on success or %-EINVAL
436 static int rio_route_add_entry(struct rio_mport
*mport
, struct rio_dev
*rdev
,
437 u16 table
, u16 route_destid
, u8 route_port
)
439 return rdev
->rswitch
->add_entry(mport
, rdev
->rswitch
->destid
,
440 rdev
->rswitch
->hopcount
, table
,
441 route_destid
, route_port
);
445 * rio_route_get_entry- Read a route entry in a switch routing table
446 * @mport: Master port to send transaction
447 * @rdev: Switch device
448 * @table: Routing table ID
449 * @route_destid: Destination ID to be routed
450 * @route_port: Pointer to read port number into
452 * Calls the switch specific get_entry() method to read a route entry
453 * in 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
460 rio_route_get_entry(struct rio_mport
*mport
, struct rio_dev
*rdev
, u16 table
,
461 u16 route_destid
, u8
* route_port
)
463 return rdev
->rswitch
->get_entry(mport
, rdev
->rswitch
->destid
,
464 rdev
->rswitch
->hopcount
, table
,
465 route_destid
, route_port
);
469 * rio_get_host_deviceid_lock- Reads the Host Device ID Lock CSR on a device
470 * @port: Master port to send transaction
471 * @hopcount: Number of hops to the device
473 * Used during enumeration to read the Host Device ID Lock CSR on a
474 * RIO device. Returns the value of the lock register.
476 static u16
rio_get_host_deviceid_lock(struct rio_mport
*port
, u8 hopcount
)
480 rio_mport_read_config_32(port
, RIO_ANY_DESTID
, hopcount
,
481 RIO_HOST_DID_LOCK_CSR
, &result
);
483 return (u16
) (result
& 0xffff);
487 * rio_get_swpinfo_inport- Gets the ingress port number
488 * @mport: Master port to send transaction
489 * @destid: Destination ID associated with the switch
490 * @hopcount: Number of hops to the device
492 * Returns port number being used to access the switch device.
495 rio_get_swpinfo_inport(struct rio_mport
*mport
, u16 destid
, u8 hopcount
)
499 rio_mport_read_config_32(mport
, destid
, hopcount
, RIO_SWP_INFO_CAR
,
502 return (u8
) (result
& 0xff);
506 * rio_get_swpinfo_tports- Gets total number of ports on the switch
507 * @mport: Master port to send transaction
508 * @destid: Destination ID associated with the switch
509 * @hopcount: Number of hops to the device
511 * Returns total numbers of ports implemented by the switch device.
513 static u8
rio_get_swpinfo_tports(struct rio_mport
*mport
, u16 destid
,
518 rio_mport_read_config_32(mport
, destid
, hopcount
, RIO_SWP_INFO_CAR
,
521 return RIO_GET_TOTAL_PORTS(result
);
525 * rio_net_add_mport- Add a master port to a RIO network
527 * @port: Master port to add
529 * Adds a master port to the network list of associated master
532 static void rio_net_add_mport(struct rio_net
*net
, struct rio_mport
*port
)
534 spin_lock(&rio_global_list_lock
);
535 list_add_tail(&port
->nnode
, &net
->mports
);
536 spin_unlock(&rio_global_list_lock
);
540 * rio_enum_peer- Recursively enumerate a RIO network through a master port
541 * @net: RIO network being enumerated
542 * @port: Master port to send transactions
543 * @hopcount: Number of hops into the network
545 * Recursively enumerates a RIO network. Transactions are sent via the
546 * master port passed in @port.
548 static int rio_enum_peer(struct rio_net
*net
, struct rio_mport
*port
,
554 struct rio_dev
*rdev
;
558 if (rio_get_host_deviceid_lock(port
, hopcount
) == port
->host_deviceid
) {
559 pr_debug("RIO: PE already discovered by this host\n");
561 * Already discovered by this host. Add it as another
562 * master port for the current network.
564 rio_net_add_mport(net
, port
);
568 /* Attempt to acquire device lock */
569 rio_mport_write_config_32(port
, RIO_ANY_DESTID
, hopcount
,
570 RIO_HOST_DID_LOCK_CSR
, port
->host_deviceid
);
571 while ((tmp
= rio_get_host_deviceid_lock(port
, hopcount
))
572 < port
->host_deviceid
) {
575 /* Attempt to acquire device lock again */
576 rio_mport_write_config_32(port
, RIO_ANY_DESTID
, hopcount
,
577 RIO_HOST_DID_LOCK_CSR
,
578 port
->host_deviceid
);
581 if (rio_get_host_deviceid_lock(port
, hopcount
) > port
->host_deviceid
) {
583 "RIO: PE locked by a higher priority host...retreating\n");
587 /* Setup new RIO device */
588 if ((rdev
= rio_setup_device(net
, port
, RIO_ANY_DESTID
, hopcount
, 1))) {
589 /* Add device to the global and bus/net specific list. */
590 list_add_tail(&rdev
->net_list
, &net
->devices
);
594 if (rio_is_switch(rdev
)) {
597 for (destid
= 0; destid
< next_destid
; destid
++) {
598 rio_route_add_entry(port
, rdev
, RIO_GLOBAL_TABLE
,
599 destid
, rio_get_swpinfo_inport(port
,
602 rdev
->rswitch
->route_table
[destid
] =
603 rio_get_swpinfo_inport(port
, RIO_ANY_DESTID
,
608 rio_get_swpinfo_tports(port
, RIO_ANY_DESTID
, hopcount
);
610 "RIO: found %s (vid %4.4x did %4.4x) with %d ports\n",
611 rio_name(rdev
), rdev
->vid
, rdev
->did
, num_ports
);
612 for (port_num
= 0; port_num
< num_ports
; port_num
++) {
613 if (rio_get_swpinfo_inport
614 (port
, RIO_ANY_DESTID
, hopcount
) == port_num
)
617 cur_destid
= next_destid
;
619 if (rio_sport_is_active
620 (port
, RIO_ANY_DESTID
, hopcount
, port_num
)) {
622 "RIO: scanning device on port %d\n",
624 rio_route_add_entry(port
, rdev
,
626 RIO_ANY_DESTID
, port_num
);
628 if (rio_enum_peer(net
, port
, hopcount
+ 1) < 0)
631 /* Update routing tables */
632 if (next_destid
> cur_destid
) {
633 for (destid
= cur_destid
;
634 destid
< next_destid
; destid
++) {
635 rio_route_add_entry(port
, rdev
,
640 route_table
[destid
] =
643 rdev
->rswitch
->destid
= cur_destid
;
648 pr_debug("RIO: found %s (vid %4.4x did %4.4x)\n",
649 rio_name(rdev
), rdev
->vid
, rdev
->did
);
655 * rio_enum_complete- Tests if enumeration of a network is complete
656 * @port: Master port to send transaction
658 * Tests the Component Tag CSR for presence of the magic enumeration
659 * complete flag. Return %1 if enumeration is complete or %0 if
660 * enumeration is incomplete.
662 static int rio_enum_complete(struct rio_mport
*port
)
667 rio_local_read_config_32(port
, RIO_COMPONENT_TAG_CSR
, &tag_csr
);
669 if (tag_csr
== RIO_ENUM_CMPL_MAGIC
)
676 * rio_disc_peer- Recursively discovers a RIO network through a master port
677 * @net: RIO network being discovered
678 * @port: Master port to send transactions
679 * @destid: Current destination ID in network
680 * @hopcount: Number of hops into the network
682 * Recursively discovers a RIO network. Transactions are sent via the
683 * master port passed in @port.
686 rio_disc_peer(struct rio_net
*net
, struct rio_mport
*port
, u16 destid
,
689 u8 port_num
, route_port
;
691 struct rio_dev
*rdev
;
694 /* Setup new RIO device */
695 if ((rdev
= rio_setup_device(net
, port
, destid
, hopcount
, 0))) {
696 /* Add device to the global and bus/net specific list. */
697 list_add_tail(&rdev
->net_list
, &net
->devices
);
701 if (rio_is_switch(rdev
)) {
704 /* Associated destid is how we accessed this switch */
705 rdev
->rswitch
->destid
= destid
;
707 num_ports
= rio_get_swpinfo_tports(port
, destid
, hopcount
);
709 "RIO: found %s (vid %4.4x did %4.4x) with %d ports\n",
710 rio_name(rdev
), rdev
->vid
, rdev
->did
, num_ports
);
711 for (port_num
= 0; port_num
< num_ports
; port_num
++) {
712 if (rio_get_swpinfo_inport(port
, destid
, hopcount
) ==
716 if (rio_sport_is_active
717 (port
, destid
, hopcount
, port_num
)) {
719 "RIO: scanning device on port %d\n",
721 for (ndestid
= 0; ndestid
< RIO_ANY_DESTID
;
723 rio_route_get_entry(port
, rdev
,
727 if (route_port
== port_num
)
732 (net
, port
, ndestid
, hopcount
+ 1) < 0)
737 pr_debug("RIO: found %s (vid %4.4x did %4.4x)\n",
738 rio_name(rdev
), rdev
->vid
, rdev
->did
);
744 * rio_mport_is_active- Tests if master port link is active
745 * @port: Master port to test
747 * Reads the port error status CSR for the master port to
748 * determine if the port has an active link. Returns
749 * %PORT_N_ERR_STS_PORT_OK if the master port is active
750 * or %0 if it is inactive.
752 static int rio_mport_is_active(struct rio_mport
*port
)
756 int *entry
= rio_mport_phys_table
;
760 rio_mport_get_feature(port
, 1, 0, 0, *entry
)))
762 } while (*++entry
>= 0);
765 rio_local_read_config_32(port
,
767 RIO_PORT_N_ERR_STS_CSR(port
->index
),
770 return (result
& PORT_N_ERR_STS_PORT_OK
);
774 * rio_alloc_net- Allocate and configure a new RIO network
775 * @port: Master port associated with the RIO network
777 * Allocates a RIO network structure, initializes per-network
778 * list heads, and adds the associated master port to the
779 * network list of associated master ports. Returns a
780 * RIO network pointer on success or %NULL on failure.
782 static struct rio_net __devinit
*rio_alloc_net(struct rio_mport
*port
)
786 net
= kmalloc(sizeof(struct rio_net
), GFP_KERNEL
);
788 memset(net
, 0, sizeof(struct rio_net
));
789 INIT_LIST_HEAD(&net
->node
);
790 INIT_LIST_HEAD(&net
->devices
);
791 INIT_LIST_HEAD(&net
->mports
);
792 list_add_tail(&port
->nnode
, &net
->mports
);
794 net
->id
= next_net
++;
800 * rio_enum_mport- Start enumeration through a master port
801 * @mport: Master port to send transactions
803 * Starts the enumeration process. If somebody has enumerated our
804 * master port device, then give up. If not and we have an active
805 * link, then start recursive peer enumeration. Returns %0 if
806 * enumeration succeeds or %-EBUSY if enumeration fails.
808 int rio_enum_mport(struct rio_mport
*mport
)
810 struct rio_net
*net
= NULL
;
813 printk(KERN_INFO
"RIO: enumerate master port %d, %s\n", mport
->id
,
815 /* If somebody else enumerated our master port device, bail. */
816 if (rio_enum_host(mport
) < 0) {
818 "RIO: master port %d device has been enumerated by a remote host\n",
824 /* If master port has an active link, allocate net and enum peers */
825 if (rio_mport_is_active(mport
)) {
826 if (!(net
= rio_alloc_net(mport
))) {
827 printk(KERN_ERR
"RIO: failed to allocate new net\n");
831 if (rio_enum_peer(net
, mport
, 0) < 0) {
832 /* A higher priority host won enumeration, bail. */
834 "RIO: master port %d device has lost enumeration to a remote host\n",
836 rio_clear_locks(mport
);
840 rio_clear_locks(mport
);
842 printk(KERN_INFO
"RIO: master port %d link inactive\n",
852 * rio_build_route_tables- Generate route tables from switch route entries
854 * For each switch device, generate a route table by copying existing
855 * route entries from the switch.
857 static void rio_build_route_tables(void)
859 struct rio_dev
*rdev
;
863 list_for_each_entry(rdev
, &rio_devices
, global_list
)
864 if (rio_is_switch(rdev
))
865 for (i
= 0; i
< RIO_MAX_ROUTE_ENTRIES
; i
++) {
866 if (rio_route_get_entry
867 (rdev
->net
->hport
, rdev
, RIO_GLOBAL_TABLE
, i
,
870 rdev
->rswitch
->route_table
[i
] = sport
;
875 * rio_enum_timeout- Signal that enumeration timed out
876 * @data: Address of timeout flag.
878 * When the enumeration complete timer expires, set a flag that
879 * signals to the discovery process that enumeration did not
880 * complete in a sane amount of time.
882 static void rio_enum_timeout(unsigned long data
)
884 /* Enumeration timed out, set flag */
889 * rio_disc_mport- Start discovery through a master port
890 * @mport: Master port to send transactions
892 * Starts the discovery process. If we have an active link,
893 * then wait for the signal that enumeration is complete.
894 * When enumeration completion is signaled, start recursive
895 * peer discovery. Returns %0 if discovery succeeds or %-EBUSY
898 int rio_disc_mport(struct rio_mport
*mport
)
900 struct rio_net
*net
= NULL
;
901 int enum_timeout_flag
= 0;
903 printk(KERN_INFO
"RIO: discover master port %d, %s\n", mport
->id
,
906 /* If master port has an active link, allocate net and discover peers */
907 if (rio_mport_is_active(mport
)) {
908 if (!(net
= rio_alloc_net(mport
))) {
909 printk(KERN_ERR
"RIO: Failed to allocate new net\n");
913 pr_debug("RIO: wait for enumeration complete...");
915 rio_enum_timer
.expires
=
916 jiffies
+ CONFIG_RAPIDIO_DISC_TIMEOUT
* HZ
;
917 rio_enum_timer
.data
= (unsigned long)&enum_timeout_flag
;
918 add_timer(&rio_enum_timer
);
919 while (!rio_enum_complete(mport
)) {
921 if (enum_timeout_flag
) {
922 del_timer_sync(&rio_enum_timer
);
926 del_timer_sync(&rio_enum_timer
);
929 if (rio_disc_peer(net
, mport
, RIO_ANY_DESTID
, 0) < 0) {
931 "RIO: master port %d device has failed discovery\n",
936 rio_build_route_tables();
942 pr_debug("timeout\n");