blob: 48e9041dd1e29b016b7997c2f8c74726ce90223d [file] [log] [blame]
Matt Portereb188d02005-11-07 01:00:17 -08001/*
2 * RapidIO enumeration and discovery support
3 *
4 * Copyright 2005 MontaVista Software, Inc.
5 * Matt Porter <mporter@kernel.crashing.org>
6 *
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -07007 * Copyright 2009 Integrated Device Technology, Inc.
8 * Alex Bounine <alexandre.bounine@idt.com>
9 * - Added Port-Write/Error Management initialization and handling
10 *
Thomas Moll933af4a2010-05-26 14:44:01 -070011 * Copyright 2009 Sysgo AG
12 * Thomas Moll <thomas.moll@sysgo.com>
13 * - Added Input- Output- enable functionality, to allow full communication
14 *
Matt Portereb188d02005-11-07 01:00:17 -080015 * This program is free software; you can redistribute it and/or modify it
16 * under the terms of the GNU General Public License as published by the
17 * Free Software Foundation; either version 2 of the License, or (at your
18 * option) any later version.
19 */
20
Matt Portereb188d02005-11-07 01:00:17 -080021#include <linux/types.h>
22#include <linux/kernel.h>
23
24#include <linux/delay.h>
Matt Porterfa78cc52005-11-07 01:00:18 -080025#include <linux/dma-mapping.h>
Matt Portereb188d02005-11-07 01:00:17 -080026#include <linux/init.h>
27#include <linux/rio.h>
28#include <linux/rio_drv.h>
29#include <linux/rio_ids.h>
30#include <linux/rio_regs.h>
31#include <linux/module.h>
32#include <linux/spinlock.h>
33#include <linux/timer.h>
Alexandre Bouninefa3dbaa2012-10-04 17:16:04 -070034#include <linux/sched.h>
Tim Schmielaude259682006-01-08 01:02:05 -080035#include <linux/jiffies.h>
36#include <linux/slab.h>
Matt Portereb188d02005-11-07 01:00:17 -080037
38#include "rio.h"
39
40LIST_HEAD(rio_devices);
Matt Portereb188d02005-11-07 01:00:17 -080041
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -070042static void rio_init_em(struct rio_dev *rdev);
43
Matt Porterfa78cc52005-11-07 01:00:18 -080044DEFINE_SPINLOCK(rio_global_list_lock);
45
Matt Portereb188d02005-11-07 01:00:17 -080046static int next_destid = 0;
Alexandre Bounineaf84ca32010-10-27 15:34:34 -070047static int next_comptag = 1;
Matt Portereb188d02005-11-07 01:00:17 -080048
Matt Portereb188d02005-11-07 01:00:17 -080049static int rio_mport_phys_table[] = {
50 RIO_EFB_PAR_EP_ID,
51 RIO_EFB_PAR_EP_REC_ID,
52 RIO_EFB_SER_EP_ID,
53 RIO_EFB_SER_EP_REC_ID,
54 -1,
55};
56
Alexandre Bouninede74e002012-10-04 17:16:13 -070057
58/*
59 * rio_destid_alloc - Allocate next available destID for given network
60 * net: RIO network
61 *
62 * Returns next available device destination ID for the specified RIO network.
63 * Marks allocated ID as one in use.
64 * Returns RIO_INVALID_DESTID if new destID is not available.
65 */
66static u16 rio_destid_alloc(struct rio_net *net)
67{
68 int destid;
69 struct rio_id_table *idtab = &net->destid_table;
70
71 spin_lock(&idtab->lock);
72 destid = find_next_zero_bit(idtab->table, idtab->max, idtab->next);
73 if (destid >= idtab->max)
74 destid = find_first_zero_bit(idtab->table, idtab->max);
75
76 if (destid < idtab->max) {
77 idtab->next = destid + 1;
78 if (idtab->next >= idtab->max)
79 idtab->next = 0;
80 set_bit(destid, idtab->table);
81 destid += idtab->start;
82 } else
83 destid = RIO_INVALID_DESTID;
84
85 spin_unlock(&idtab->lock);
86 return (u16)destid;
87}
88
89/*
90 * rio_destid_reserve - Reserve the specivied destID
91 * net: RIO network
92 * destid: destID to reserve
93 *
94 * Tries to reserve the specified destID.
95 * Returns 0 if successfull.
96 */
97static int rio_destid_reserve(struct rio_net *net, u16 destid)
98{
99 int oldbit;
100 struct rio_id_table *idtab = &net->destid_table;
101
102 destid -= idtab->start;
103 spin_lock(&idtab->lock);
104 oldbit = test_and_set_bit(destid, idtab->table);
105 spin_unlock(&idtab->lock);
106 return oldbit;
107}
108
109/*
110 * rio_destid_free - free a previously allocated destID
111 * net: RIO network
112 * destid: destID to free
113 *
114 * Makes the specified destID available for use.
115 */
116static void rio_destid_free(struct rio_net *net, u16 destid)
117{
118 struct rio_id_table *idtab = &net->destid_table;
119
120 destid -= idtab->start;
121 spin_lock(&idtab->lock);
122 clear_bit(destid, idtab->table);
123 spin_unlock(&idtab->lock);
124}
125
126/*
127 * rio_destid_first - return first destID in use
128 * net: RIO network
129 */
130static u16 rio_destid_first(struct rio_net *net)
131{
132 int destid;
133 struct rio_id_table *idtab = &net->destid_table;
134
135 spin_lock(&idtab->lock);
136 destid = find_first_bit(idtab->table, idtab->max);
137 if (destid >= idtab->max)
138 destid = RIO_INVALID_DESTID;
139 else
140 destid += idtab->start;
141 spin_unlock(&idtab->lock);
142 return (u16)destid;
143}
144
145/*
146 * rio_destid_next - return next destID in use
147 * net: RIO network
148 * from: destination ID from which search shall continue
149 */
150static u16 rio_destid_next(struct rio_net *net, u16 from)
151{
152 int destid;
153 struct rio_id_table *idtab = &net->destid_table;
154
155 spin_lock(&idtab->lock);
156 destid = find_next_bit(idtab->table, idtab->max, from);
157 if (destid >= idtab->max)
158 destid = RIO_INVALID_DESTID;
159 else
160 destid += idtab->start;
161 spin_unlock(&idtab->lock);
162 return (u16)destid;
163}
164
Matt Portereb188d02005-11-07 01:00:17 -0800165/**
166 * rio_get_device_id - Get the base/extended device id for a device
167 * @port: RIO master port
168 * @destid: Destination ID of device
169 * @hopcount: Hopcount to device
170 *
171 * Reads the base/extended device id from a device. Returns the
172 * 8/16-bit device ID.
173 */
174static u16 rio_get_device_id(struct rio_mport *port, u16 destid, u8 hopcount)
175{
176 u32 result;
177
178 rio_mport_read_config_32(port, destid, hopcount, RIO_DID_CSR, &result);
179
Zhang Weie0423232008-04-18 13:33:42 -0700180 return RIO_GET_DID(port->sys_size, result);
Matt Portereb188d02005-11-07 01:00:17 -0800181}
182
183/**
184 * rio_set_device_id - Set the base/extended device id for a device
185 * @port: RIO master port
186 * @destid: Destination ID of device
187 * @hopcount: Hopcount to device
188 * @did: Device ID value to be written
189 *
190 * Writes the base/extended device id from a device.
191 */
Matt Porterfa78cc52005-11-07 01:00:18 -0800192static void rio_set_device_id(struct rio_mport *port, u16 destid, u8 hopcount, u16 did)
Matt Portereb188d02005-11-07 01:00:17 -0800193{
194 rio_mport_write_config_32(port, destid, hopcount, RIO_DID_CSR,
Zhang Weie0423232008-04-18 13:33:42 -0700195 RIO_SET_DID(port->sys_size, did));
Matt Portereb188d02005-11-07 01:00:17 -0800196}
197
198/**
199 * rio_local_set_device_id - Set the base/extended device id for a port
200 * @port: RIO master port
201 * @did: Device ID value to be written
202 *
203 * Writes the base/extended device id from a device.
204 */
205static void rio_local_set_device_id(struct rio_mport *port, u16 did)
206{
Zhang Weie0423232008-04-18 13:33:42 -0700207 rio_local_write_config_32(port, RIO_DID_CSR, RIO_SET_DID(port->sys_size,
208 did));
Matt Portereb188d02005-11-07 01:00:17 -0800209}
210
211/**
212 * rio_clear_locks- Release all host locks and signal enumeration complete
Alexandre Bouninea7071ef2012-10-04 17:16:05 -0700213 * @net: RIO network to run on
Matt Portereb188d02005-11-07 01:00:17 -0800214 *
215 * Marks the component tag CSR on each device with the enumeration
216 * complete flag. When complete, it then release the host locks on
217 * each device. Returns 0 on success or %-EINVAL on failure.
218 */
Alexandre Bouninea7071ef2012-10-04 17:16:05 -0700219static int rio_clear_locks(struct rio_net *net)
Matt Portereb188d02005-11-07 01:00:17 -0800220{
Alexandre Bouninea7071ef2012-10-04 17:16:05 -0700221 struct rio_mport *port = net->hport;
Matt Portereb188d02005-11-07 01:00:17 -0800222 struct rio_dev *rdev;
223 u32 result;
224 int ret = 0;
225
Matt Portereb188d02005-11-07 01:00:17 -0800226 /* Release host device id locks */
227 rio_local_write_config_32(port, RIO_HOST_DID_LOCK_CSR,
228 port->host_deviceid);
229 rio_local_read_config_32(port, RIO_HOST_DID_LOCK_CSR, &result);
230 if ((result & 0xffff) != 0xffff) {
231 printk(KERN_INFO
232 "RIO: badness when releasing host lock on master port, result %8.8x\n",
233 result);
234 ret = -EINVAL;
235 }
Alexandre Bouninea7071ef2012-10-04 17:16:05 -0700236 list_for_each_entry(rdev, &net->devices, net_list) {
Matt Portereb188d02005-11-07 01:00:17 -0800237 rio_write_config_32(rdev, RIO_HOST_DID_LOCK_CSR,
238 port->host_deviceid);
239 rio_read_config_32(rdev, RIO_HOST_DID_LOCK_CSR, &result);
240 if ((result & 0xffff) != 0xffff) {
241 printk(KERN_INFO
242 "RIO: badness when releasing host lock on vid %4.4x did %4.4x\n",
243 rdev->vid, rdev->did);
244 ret = -EINVAL;
245 }
Alexandre Bounineaf84ca32010-10-27 15:34:34 -0700246
247 /* Mark device as discovered and enable master */
248 rio_read_config_32(rdev,
249 rdev->phys_efptr + RIO_PORT_GEN_CTL_CSR,
250 &result);
251 result |= RIO_PORT_GEN_DISCOVERED | RIO_PORT_GEN_MASTER;
252 rio_write_config_32(rdev,
253 rdev->phys_efptr + RIO_PORT_GEN_CTL_CSR,
254 result);
Matt Portereb188d02005-11-07 01:00:17 -0800255 }
256
257 return ret;
258}
259
260/**
261 * rio_enum_host- Set host lock and initialize host destination ID
262 * @port: Master port to issue transaction
263 *
264 * Sets the local host master port lock and destination ID register
265 * with the host device ID value. The host device ID value is provided
266 * by the platform. Returns %0 on success or %-1 on failure.
267 */
268static int rio_enum_host(struct rio_mport *port)
269{
270 u32 result;
271
272 /* Set master port host device id lock */
273 rio_local_write_config_32(port, RIO_HOST_DID_LOCK_CSR,
274 port->host_deviceid);
275
276 rio_local_read_config_32(port, RIO_HOST_DID_LOCK_CSR, &result);
277 if ((result & 0xffff) != port->host_deviceid)
278 return -1;
279
280 /* Set master port destid and init destid ctr */
281 rio_local_set_device_id(port, port->host_deviceid);
Matt Portereb188d02005-11-07 01:00:17 -0800282 return 0;
283}
284
285/**
286 * rio_device_has_destid- Test if a device contains a destination ID register
287 * @port: Master port to issue transaction
288 * @src_ops: RIO device source operations
289 * @dst_ops: RIO device destination operations
290 *
291 * Checks the provided @src_ops and @dst_ops for the necessary transaction
292 * capabilities that indicate whether or not a device will implement a
293 * destination ID register. Returns 1 if true or 0 if false.
294 */
295static int rio_device_has_destid(struct rio_mport *port, int src_ops,
296 int dst_ops)
297{
Matt Porterfa78cc52005-11-07 01:00:18 -0800298 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;
299
300 return !!((src_ops | dst_ops) & mask);
Matt Portereb188d02005-11-07 01:00:17 -0800301}
302
303/**
304 * rio_release_dev- Frees a RIO device struct
305 * @dev: LDM device associated with a RIO device struct
306 *
307 * Gets the RIO device struct associated a RIO device struct.
308 * The RIO device struct is freed.
309 */
310static void rio_release_dev(struct device *dev)
311{
312 struct rio_dev *rdev;
313
314 rdev = to_rio_dev(dev);
315 kfree(rdev);
316}
317
318/**
319 * rio_is_switch- Tests if a RIO device has switch capabilities
320 * @rdev: RIO device
321 *
322 * Gets the RIO device Processing Element Features register
323 * contents and tests for switch capabilities. Returns 1 if
324 * the device is a switch or 0 if it is not a switch.
325 * The RIO device struct is freed.
326 */
327static int rio_is_switch(struct rio_dev *rdev)
328{
329 if (rdev->pef & RIO_PEF_SWITCH)
330 return 1;
331 return 0;
332}
333
334/**
Alexandre Bounine058f88d62010-05-26 14:44:03 -0700335 * rio_switch_init - Sets switch operations for a particular vendor switch
Matt Portereb188d02005-11-07 01:00:17 -0800336 * @rdev: RIO device
Alexandre Bounine058f88d62010-05-26 14:44:03 -0700337 * @do_enum: Enumeration/Discovery mode flag
Matt Portereb188d02005-11-07 01:00:17 -0800338 *
Alexandre Bounine058f88d62010-05-26 14:44:03 -0700339 * Searches the RIO switch ops table for known switch types. If the vid
340 * and did match a switch table entry, then call switch initialization
341 * routine to setup switch-specific routines.
Matt Portereb188d02005-11-07 01:00:17 -0800342 */
Alexandre Bounine058f88d62010-05-26 14:44:03 -0700343static void rio_switch_init(struct rio_dev *rdev, int do_enum)
Matt Portereb188d02005-11-07 01:00:17 -0800344{
Alexandre Bounine058f88d62010-05-26 14:44:03 -0700345 struct rio_switch_ops *cur = __start_rio_switch_ops;
346 struct rio_switch_ops *end = __end_rio_switch_ops;
Matt Portereb188d02005-11-07 01:00:17 -0800347
348 while (cur < end) {
349 if ((cur->vid == rdev->vid) && (cur->did == rdev->did)) {
Alexandre Bounine058f88d62010-05-26 14:44:03 -0700350 pr_debug("RIO: calling init routine for %s\n",
351 rio_name(rdev));
352 cur->init_hook(rdev, do_enum);
Alexandre Bounine07590ff2010-05-26 14:43:57 -0700353 break;
Matt Portereb188d02005-11-07 01:00:17 -0800354 }
355 cur++;
356 }
357
Alexandre Bounine07590ff2010-05-26 14:43:57 -0700358 if ((cur >= end) && (rdev->pef & RIO_PEF_STD_RT)) {
359 pr_debug("RIO: adding STD routing ops for %s\n",
360 rio_name(rdev));
361 rdev->rswitch->add_entry = rio_std_route_add_entry;
362 rdev->rswitch->get_entry = rio_std_route_get_entry;
363 rdev->rswitch->clr_table = rio_std_route_clr_table;
364 }
365
Matt Portereb188d02005-11-07 01:00:17 -0800366 if (!rdev->rswitch->add_entry || !rdev->rswitch->get_entry)
367 printk(KERN_ERR "RIO: missing routing ops for %s\n",
368 rio_name(rdev));
369}
370
371/**
372 * rio_add_device- Adds a RIO device to the device model
373 * @rdev: RIO device
374 *
375 * Adds the RIO device to the global device list and adds the RIO
376 * device to the RIO device list. Creates the generic sysfs nodes
377 * for an RIO device.
378 */
Yang Li5f28c522009-05-11 22:36:02 +0000379static int __devinit rio_add_device(struct rio_dev *rdev)
Matt Portereb188d02005-11-07 01:00:17 -0800380{
Yang Li5f28c522009-05-11 22:36:02 +0000381 int err;
382
383 err = device_add(&rdev->dev);
384 if (err)
385 return err;
Matt Portereb188d02005-11-07 01:00:17 -0800386
387 spin_lock(&rio_global_list_lock);
388 list_add_tail(&rdev->global_list, &rio_devices);
389 spin_unlock(&rio_global_list_lock);
390
391 rio_create_sysfs_dev_files(rdev);
Yang Li5f28c522009-05-11 22:36:02 +0000392
393 return 0;
Matt Portereb188d02005-11-07 01:00:17 -0800394}
395
396/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300397 * rio_enable_rx_tx_port - enable input receiver and output transmitter of
Thomas Moll933af4a2010-05-26 14:44:01 -0700398 * given port
399 * @port: Master port associated with the RIO network
400 * @local: local=1 select local port otherwise a far device is reached
401 * @destid: Destination ID of the device to check host bit
402 * @hopcount: Number of hops to reach the target
403 * @port_num: Port (-number on switch) to enable on a far end device
404 *
405 * Returns 0 or 1 from on General Control Command and Status Register
406 * (EXT_PTR+0x3C)
407 */
408inline int rio_enable_rx_tx_port(struct rio_mport *port,
409 int local, u16 destid,
410 u8 hopcount, u8 port_num) {
411#ifdef CONFIG_RAPIDIO_ENABLE_RX_TX_PORTS
412 u32 regval;
413 u32 ext_ftr_ptr;
414
415 /*
416 * enable rx input tx output port
417 */
418 pr_debug("rio_enable_rx_tx_port(local = %d, destid = %d, hopcount = "
419 "%d, port_num = %d)\n", local, destid, hopcount, port_num);
420
421 ext_ftr_ptr = rio_mport_get_physefb(port, local, destid, hopcount);
422
423 if (local) {
424 rio_local_read_config_32(port, ext_ftr_ptr +
425 RIO_PORT_N_CTL_CSR(0),
426 &regval);
427 } else {
428 if (rio_mport_read_config_32(port, destid, hopcount,
429 ext_ftr_ptr + RIO_PORT_N_CTL_CSR(port_num), &regval) < 0)
430 return -EIO;
431 }
432
433 if (regval & RIO_PORT_N_CTL_P_TYP_SER) {
434 /* serial */
435 regval = regval | RIO_PORT_N_CTL_EN_RX_SER
436 | RIO_PORT_N_CTL_EN_TX_SER;
437 } else {
438 /* parallel */
439 regval = regval | RIO_PORT_N_CTL_EN_RX_PAR
440 | RIO_PORT_N_CTL_EN_TX_PAR;
441 }
442
443 if (local) {
444 rio_local_write_config_32(port, ext_ftr_ptr +
445 RIO_PORT_N_CTL_CSR(0), regval);
446 } else {
447 if (rio_mport_write_config_32(port, destid, hopcount,
448 ext_ftr_ptr + RIO_PORT_N_CTL_CSR(port_num), regval) < 0)
449 return -EIO;
450 }
451#endif
452 return 0;
453}
454
455/**
Matt Portereb188d02005-11-07 01:00:17 -0800456 * rio_setup_device- Allocates and sets up a RIO device
457 * @net: RIO network
458 * @port: Master port to send transactions
459 * @destid: Current destination ID
460 * @hopcount: Current hopcount
461 * @do_enum: Enumeration/Discovery mode flag
462 *
463 * Allocates a RIO device and configures fields based on configuration
464 * space contents. If device has a destination ID register, a destination
465 * ID is either assigned in enumeration mode or read from configuration
466 * space in discovery mode. If the device has switch capabilities, then
467 * a switch is allocated and configured appropriately. Returns a pointer
468 * to a RIO device on success or NULL on failure.
469 *
470 */
Li Yang181a6ff2009-05-12 16:36:03 +0800471static struct rio_dev __devinit *rio_setup_device(struct rio_net *net,
Matt Portereb188d02005-11-07 01:00:17 -0800472 struct rio_mport *port, u16 destid,
473 u8 hopcount, int do_enum)
474{
Yang Li5f28c522009-05-11 22:36:02 +0000475 int ret = 0;
Matt Portereb188d02005-11-07 01:00:17 -0800476 struct rio_dev *rdev;
Yang Li5f28c522009-05-11 22:36:02 +0000477 struct rio_switch *rswitch = NULL;
Matt Portereb188d02005-11-07 01:00:17 -0800478 int result, rdid;
Alexandre Bounineded05782011-01-12 17:00:39 -0800479 size_t size;
480 u32 swpinfo = 0;
Matt Portereb188d02005-11-07 01:00:17 -0800481
Alexandre Bounineded05782011-01-12 17:00:39 -0800482 size = sizeof(struct rio_dev);
483 if (rio_mport_read_config_32(port, destid, hopcount,
484 RIO_PEF_CAR, &result))
485 return NULL;
486
487 if (result & (RIO_PEF_SWITCH | RIO_PEF_MULTIPORT)) {
488 rio_mport_read_config_32(port, destid, hopcount,
489 RIO_SWP_INFO_CAR, &swpinfo);
490 if (result & RIO_PEF_SWITCH) {
491 size += (RIO_GET_TOTAL_PORTS(swpinfo) *
492 sizeof(rswitch->nextdev[0])) + sizeof(*rswitch);
493 }
494 }
495
496 rdev = kzalloc(size, GFP_KERNEL);
Matt Portereb188d02005-11-07 01:00:17 -0800497 if (!rdev)
Yang Li5f28c522009-05-11 22:36:02 +0000498 return NULL;
Matt Portereb188d02005-11-07 01:00:17 -0800499
Matt Portereb188d02005-11-07 01:00:17 -0800500 rdev->net = net;
Alexandre Bounineded05782011-01-12 17:00:39 -0800501 rdev->pef = result;
502 rdev->swpinfo = swpinfo;
Matt Portereb188d02005-11-07 01:00:17 -0800503 rio_mport_read_config_32(port, destid, hopcount, RIO_DEV_ID_CAR,
504 &result);
505 rdev->did = result >> 16;
506 rdev->vid = result & 0xffff;
507 rio_mport_read_config_32(port, destid, hopcount, RIO_DEV_INFO_CAR,
508 &rdev->device_rev);
509 rio_mport_read_config_32(port, destid, hopcount, RIO_ASM_ID_CAR,
510 &result);
511 rdev->asm_did = result >> 16;
512 rdev->asm_vid = result & 0xffff;
513 rio_mport_read_config_32(port, destid, hopcount, RIO_ASM_INFO_CAR,
514 &result);
515 rdev->asm_rev = result >> 16;
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -0700516 if (rdev->pef & RIO_PEF_EXT_FEATURES) {
Matt Portereb188d02005-11-07 01:00:17 -0800517 rdev->efptr = result & 0xffff;
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -0700518 rdev->phys_efptr = rio_mport_get_physefb(port, 0, destid,
519 hopcount);
520
521 rdev->em_efptr = rio_mport_get_feature(port, 0, destid,
522 hopcount, RIO_EFB_ERR_MGMNT);
523 }
Matt Portereb188d02005-11-07 01:00:17 -0800524
525 rio_mport_read_config_32(port, destid, hopcount, RIO_SRC_OPS_CAR,
526 &rdev->src_ops);
527 rio_mport_read_config_32(port, destid, hopcount, RIO_DST_OPS_CAR,
528 &rdev->dst_ops);
529
Alexandre Bounineaf84ca32010-10-27 15:34:34 -0700530 if (do_enum) {
531 /* Assign component tag to device */
532 if (next_comptag >= 0x10000) {
533 pr_err("RIO: Component Tag Counter Overflow\n");
534 goto cleanup;
535 }
536 rio_mport_write_config_32(port, destid, hopcount,
537 RIO_COMPONENT_TAG_CSR, next_comptag);
538 rdev->comp_tag = next_comptag++;
Alexandre Bounine558bda62011-01-12 17:00:42 -0800539 } else {
540 rio_mport_read_config_32(port, destid, hopcount,
541 RIO_COMPONENT_TAG_CSR,
542 &rdev->comp_tag);
Alexandre Bounineaf84ca32010-10-27 15:34:34 -0700543 }
544
Alexandre Bouninec70555b2007-02-10 01:46:47 -0800545 if (rio_device_has_destid(port, rdev->src_ops, rdev->dst_ops)) {
546 if (do_enum) {
547 rio_set_device_id(port, destid, hopcount, next_destid);
Alexandre Bouninede74e002012-10-04 17:16:13 -0700548 rdev->destid = next_destid;
549 next_destid = rio_destid_alloc(net);
Alexandre Bouninec70555b2007-02-10 01:46:47 -0800550 } else
551 rdev->destid = rio_get_device_id(port, destid, hopcount);
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800552
553 rdev->hopcount = 0xff;
554 } else {
555 /* Switch device has an associated destID which
556 * will be adjusted later
557 */
558 rdev->destid = destid;
559 rdev->hopcount = hopcount;
560 }
Matt Portereb188d02005-11-07 01:00:17 -0800561
562 /* If a PE has both switch and other functions, show it as a switch */
563 if (rio_is_switch(rdev)) {
Alexandre Bounineded05782011-01-12 17:00:39 -0800564 rswitch = rdev->rswitch;
Alexandre Bounine558bda62011-01-12 17:00:42 -0800565 rswitch->switchid = rdev->comp_tag & RIO_CTAG_UDEVID;
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -0700566 rswitch->port_ok = 0;
Zhang Weie0423232008-04-18 13:33:42 -0700567 rswitch->route_table = kzalloc(sizeof(u8)*
568 RIO_MAX_ROUTE_ENTRIES(port->sys_size),
569 GFP_KERNEL);
Yang Li5f28c522009-05-11 22:36:02 +0000570 if (!rswitch->route_table)
571 goto cleanup;
Matt Portereb188d02005-11-07 01:00:17 -0800572 /* Initialize switch route table */
Zhang Weie0423232008-04-18 13:33:42 -0700573 for (rdid = 0; rdid < RIO_MAX_ROUTE_ENTRIES(port->sys_size);
574 rdid++)
Matt Portereb188d02005-11-07 01:00:17 -0800575 rswitch->route_table[rdid] = RIO_INVALID_ROUTE;
Kay Sieversb53c75832008-12-04 10:01:52 -0800576 dev_set_name(&rdev->dev, "%02x:s:%04x", rdev->net->id,
Alexandre Bounineded05782011-01-12 17:00:39 -0800577 rswitch->switchid);
Alexandre Bounine058f88d62010-05-26 14:44:03 -0700578 rio_switch_init(rdev, do_enum);
Matt Portereb188d02005-11-07 01:00:17 -0800579
Alexandre Bounineded05782011-01-12 17:00:39 -0800580 if (do_enum && rswitch->clr_table)
581 rswitch->clr_table(port, destid, hopcount,
582 RIO_GLOBAL_TABLE);
Alexandre Bounine07590ff2010-05-26 14:43:57 -0700583
Alexandre Bouninea7071ef2012-10-04 17:16:05 -0700584 list_add_tail(&rswitch->node, &net->switches);
Matt Portereb188d02005-11-07 01:00:17 -0800585
Thomas Moll933af4a2010-05-26 14:44:01 -0700586 } else {
587 if (do_enum)
588 /*Enable Input Output Port (transmitter reviever)*/
589 rio_enable_rx_tx_port(port, 0, destid, hopcount, 0);
590
Kay Sieversb53c75832008-12-04 10:01:52 -0800591 dev_set_name(&rdev->dev, "%02x:e:%04x", rdev->net->id,
592 rdev->destid);
Thomas Moll933af4a2010-05-26 14:44:01 -0700593 }
Matt Portereb188d02005-11-07 01:00:17 -0800594
595 rdev->dev.bus = &rio_bus_type;
Alexandre Bounine2c70f022010-10-27 15:34:26 -0700596 rdev->dev.parent = &rio_bus;
Matt Portereb188d02005-11-07 01:00:17 -0800597
598 device_initialize(&rdev->dev);
599 rdev->dev.release = rio_release_dev;
600 rio_dev_get(rdev);
601
Yang Hongyang284901a2009-04-06 19:01:15 -0700602 rdev->dma_mask = DMA_BIT_MASK(32);
Matt Porterfa78cc52005-11-07 01:00:18 -0800603 rdev->dev.dma_mask = &rdev->dma_mask;
Yang Hongyang284901a2009-04-06 19:01:15 -0700604 rdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
Matt Portereb188d02005-11-07 01:00:17 -0800605
Alexandre Bounine284fb682011-08-25 15:59:13 -0700606 if (rdev->dst_ops & RIO_DST_OPS_DOORBELL)
Matt Portereb188d02005-11-07 01:00:17 -0800607 rio_init_dbell_res(&rdev->riores[RIO_DOORBELL_RESOURCE],
608 0, 0xffff);
609
Yang Li5f28c522009-05-11 22:36:02 +0000610 ret = rio_add_device(rdev);
611 if (ret)
612 goto cleanup;
Matt Portereb188d02005-11-07 01:00:17 -0800613
Matt Portereb188d02005-11-07 01:00:17 -0800614 return rdev;
Yang Li5f28c522009-05-11 22:36:02 +0000615
616cleanup:
Alexandre Bounine166c0502011-11-02 13:39:11 -0700617 if (rswitch)
Yang Li5f28c522009-05-11 22:36:02 +0000618 kfree(rswitch->route_table);
Alexandre Bounineded05782011-01-12 17:00:39 -0800619
Yang Li5f28c522009-05-11 22:36:02 +0000620 kfree(rdev);
621 return NULL;
Matt Portereb188d02005-11-07 01:00:17 -0800622}
623
624/**
625 * rio_sport_is_active- Tests if a switch port has an active connection.
626 * @port: Master port to send transaction
627 * @destid: Associated destination ID for switch
628 * @hopcount: Hopcount to reach switch
629 * @sport: Switch port number
630 *
631 * Reads the port error status CSR for a particular switch port to
632 * determine if the port has an active link. Returns
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -0700633 * %RIO_PORT_N_ERR_STS_PORT_OK if the port is active or %0 if it is
Matt Portereb188d02005-11-07 01:00:17 -0800634 * inactive.
635 */
636static int
637rio_sport_is_active(struct rio_mport *port, u16 destid, u8 hopcount, int sport)
638{
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -0700639 u32 result = 0;
Matt Portereb188d02005-11-07 01:00:17 -0800640 u32 ext_ftr_ptr;
641
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -0700642 ext_ftr_ptr = rio_mport_get_efb(port, 0, destid, hopcount, 0);
Matt Portereb188d02005-11-07 01:00:17 -0800643
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -0700644 while (ext_ftr_ptr) {
645 rio_mport_read_config_32(port, destid, hopcount,
646 ext_ftr_ptr, &result);
647 result = RIO_GET_BLOCK_ID(result);
648 if ((result == RIO_EFB_SER_EP_FREE_ID) ||
649 (result == RIO_EFB_SER_EP_FREE_ID_V13P) ||
650 (result == RIO_EFB_SER_EP_FREC_ID))
Matt Portereb188d02005-11-07 01:00:17 -0800651 break;
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -0700652
653 ext_ftr_ptr = rio_mport_get_efb(port, 0, destid, hopcount,
654 ext_ftr_ptr);
655 }
Matt Portereb188d02005-11-07 01:00:17 -0800656
657 if (ext_ftr_ptr)
658 rio_mport_read_config_32(port, destid, hopcount,
659 ext_ftr_ptr +
660 RIO_PORT_N_ERR_STS_CSR(sport),
661 &result);
662
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -0700663 return result & RIO_PORT_N_ERR_STS_PORT_OK;
Matt Portereb188d02005-11-07 01:00:17 -0800664}
665
666/**
Alexandre Bounine818a04a2010-05-26 14:43:58 -0700667 * rio_lock_device - Acquires host device lock for specified device
668 * @port: Master port to send transaction
669 * @destid: Destination ID for device/switch
670 * @hopcount: Hopcount to reach switch
671 * @wait_ms: Max wait time in msec (0 = no timeout)
672 *
673 * Attepts to acquire host device lock for specified device
674 * Returns 0 if device lock acquired or EINVAL if timeout expires.
675 */
676static int
677rio_lock_device(struct rio_mport *port, u16 destid, u8 hopcount, int wait_ms)
678{
679 u32 result;
680 int tcnt = 0;
681
682 /* Attempt to acquire device lock */
683 rio_mport_write_config_32(port, destid, hopcount,
684 RIO_HOST_DID_LOCK_CSR, port->host_deviceid);
685 rio_mport_read_config_32(port, destid, hopcount,
686 RIO_HOST_DID_LOCK_CSR, &result);
687
688 while (result != port->host_deviceid) {
689 if (wait_ms != 0 && tcnt == wait_ms) {
690 pr_debug("RIO: timeout when locking device %x:%x\n",
691 destid, hopcount);
692 return -EINVAL;
693 }
694
695 /* Delay a bit */
696 mdelay(1);
697 tcnt++;
698 /* Try to acquire device lock again */
699 rio_mport_write_config_32(port, destid,
700 hopcount,
701 RIO_HOST_DID_LOCK_CSR,
702 port->host_deviceid);
703 rio_mport_read_config_32(port, destid,
704 hopcount,
705 RIO_HOST_DID_LOCK_CSR, &result);
706 }
707
708 return 0;
709}
710
711/**
712 * rio_unlock_device - Releases host device lock for specified device
713 * @port: Master port to send transaction
714 * @destid: Destination ID for device/switch
715 * @hopcount: Hopcount to reach switch
716 *
717 * Returns 0 if device lock released or EINVAL if fails.
718 */
719static int
720rio_unlock_device(struct rio_mport *port, u16 destid, u8 hopcount)
721{
722 u32 result;
723
724 /* Release device lock */
725 rio_mport_write_config_32(port, destid,
726 hopcount,
727 RIO_HOST_DID_LOCK_CSR,
728 port->host_deviceid);
729 rio_mport_read_config_32(port, destid, hopcount,
730 RIO_HOST_DID_LOCK_CSR, &result);
731 if ((result & 0xffff) != 0xffff) {
732 pr_debug("RIO: badness when releasing device lock %x:%x\n",
733 destid, hopcount);
734 return -EINVAL;
735 }
736
737 return 0;
738}
739
740/**
Matt Portereb188d02005-11-07 01:00:17 -0800741 * rio_route_add_entry- Add a route entry to a switch routing table
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800742 * @rdev: RIO device
Matt Portereb188d02005-11-07 01:00:17 -0800743 * @table: Routing table ID
744 * @route_destid: Destination ID to be routed
745 * @route_port: Port number to be routed
Alexandre Bounine818a04a2010-05-26 14:43:58 -0700746 * @lock: lock switch device flag
Matt Portereb188d02005-11-07 01:00:17 -0800747 *
748 * Calls the switch specific add_entry() method to add a route entry
749 * on a switch. The route table can be specified using the @table
750 * argument if a switch has per port routing tables or the normal
751 * use is to specific all tables (or the global table) by passing
752 * %RIO_GLOBAL_TABLE in @table. Returns %0 on success or %-EINVAL
753 * on failure.
754 */
Alexandre Bounine818a04a2010-05-26 14:43:58 -0700755static int
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800756rio_route_add_entry(struct rio_dev *rdev,
Alexandre Bounine818a04a2010-05-26 14:43:58 -0700757 u16 table, u16 route_destid, u8 route_port, int lock)
Matt Portereb188d02005-11-07 01:00:17 -0800758{
Alexandre Bounine818a04a2010-05-26 14:43:58 -0700759 int rc;
760
761 if (lock) {
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800762 rc = rio_lock_device(rdev->net->hport, rdev->destid,
763 rdev->hopcount, 1000);
Alexandre Bounine818a04a2010-05-26 14:43:58 -0700764 if (rc)
765 return rc;
766 }
767
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800768 rc = rdev->rswitch->add_entry(rdev->net->hport, rdev->destid,
769 rdev->hopcount, table,
770 route_destid, route_port);
Alexandre Bounine818a04a2010-05-26 14:43:58 -0700771 if (lock)
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800772 rio_unlock_device(rdev->net->hport, rdev->destid,
773 rdev->hopcount);
Alexandre Bounine818a04a2010-05-26 14:43:58 -0700774
775 return rc;
Matt Portereb188d02005-11-07 01:00:17 -0800776}
777
778/**
779 * rio_route_get_entry- Read a route entry in a switch routing table
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800780 * @rdev: RIO device
Matt Portereb188d02005-11-07 01:00:17 -0800781 * @table: Routing table ID
782 * @route_destid: Destination ID to be routed
783 * @route_port: Pointer to read port number into
Alexandre Bounine818a04a2010-05-26 14:43:58 -0700784 * @lock: lock switch device flag
Matt Portereb188d02005-11-07 01:00:17 -0800785 *
786 * Calls the switch specific get_entry() method to read a route entry
787 * in a switch. The route table can be specified using the @table
788 * argument if a switch has per port routing tables or the normal
789 * use is to specific all tables (or the global table) by passing
790 * %RIO_GLOBAL_TABLE in @table. Returns %0 on success or %-EINVAL
791 * on failure.
792 */
793static int
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800794rio_route_get_entry(struct rio_dev *rdev, u16 table,
Alexandre Bounine818a04a2010-05-26 14:43:58 -0700795 u16 route_destid, u8 *route_port, int lock)
Matt Portereb188d02005-11-07 01:00:17 -0800796{
Alexandre Bounine818a04a2010-05-26 14:43:58 -0700797 int rc;
798
799 if (lock) {
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800800 rc = rio_lock_device(rdev->net->hport, rdev->destid,
801 rdev->hopcount, 1000);
Alexandre Bounine818a04a2010-05-26 14:43:58 -0700802 if (rc)
803 return rc;
804 }
805
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800806 rc = rdev->rswitch->get_entry(rdev->net->hport, rdev->destid,
807 rdev->hopcount, table,
808 route_destid, route_port);
Alexandre Bounine818a04a2010-05-26 14:43:58 -0700809 if (lock)
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800810 rio_unlock_device(rdev->net->hport, rdev->destid,
811 rdev->hopcount);
Alexandre Bounine818a04a2010-05-26 14:43:58 -0700812
813 return rc;
Matt Portereb188d02005-11-07 01:00:17 -0800814}
815
816/**
817 * rio_get_host_deviceid_lock- Reads the Host Device ID Lock CSR on a device
818 * @port: Master port to send transaction
819 * @hopcount: Number of hops to the device
820 *
821 * Used during enumeration to read the Host Device ID Lock CSR on a
822 * RIO device. Returns the value of the lock register.
823 */
824static u16 rio_get_host_deviceid_lock(struct rio_mport *port, u8 hopcount)
825{
826 u32 result;
827
Zhang Weie0423232008-04-18 13:33:42 -0700828 rio_mport_read_config_32(port, RIO_ANY_DESTID(port->sys_size), hopcount,
Matt Portereb188d02005-11-07 01:00:17 -0800829 RIO_HOST_DID_LOCK_CSR, &result);
830
831 return (u16) (result & 0xffff);
832}
833
834/**
Matt Portereb188d02005-11-07 01:00:17 -0800835 * rio_enum_peer- Recursively enumerate a RIO network through a master port
836 * @net: RIO network being enumerated
837 * @port: Master port to send transactions
838 * @hopcount: Number of hops into the network
Alexandre Bounine68fe4df2010-10-27 15:34:29 -0700839 * @prev: Previous RIO device connected to the enumerated one
840 * @prev_port: Port on previous RIO device
Matt Portereb188d02005-11-07 01:00:17 -0800841 *
842 * Recursively enumerates a RIO network. Transactions are sent via the
843 * master port passed in @port.
844 */
Li Yang181a6ff2009-05-12 16:36:03 +0800845static int __devinit rio_enum_peer(struct rio_net *net, struct rio_mport *port,
Alexandre Bounine68fe4df2010-10-27 15:34:29 -0700846 u8 hopcount, struct rio_dev *prev, int prev_port)
Matt Portereb188d02005-11-07 01:00:17 -0800847{
Matt Portereb188d02005-11-07 01:00:17 -0800848 struct rio_dev *rdev;
Alexandre Bounineaf84ca32010-10-27 15:34:34 -0700849 u32 regval;
Matt Portereb188d02005-11-07 01:00:17 -0800850 int tmp;
851
Alexandre Bouninee274e0e2010-10-27 15:34:32 -0700852 if (rio_mport_chk_dev_access(port,
853 RIO_ANY_DESTID(port->sys_size), hopcount)) {
854 pr_debug("RIO: device access check failed\n");
855 return -1;
856 }
857
Matt Portereb188d02005-11-07 01:00:17 -0800858 if (rio_get_host_deviceid_lock(port, hopcount) == port->host_deviceid) {
859 pr_debug("RIO: PE already discovered by this host\n");
860 /*
861 * Already discovered by this host. Add it as another
Alexandre Bounineaf84ca32010-10-27 15:34:34 -0700862 * link to the existing device.
Matt Portereb188d02005-11-07 01:00:17 -0800863 */
Alexandre Bounineaf84ca32010-10-27 15:34:34 -0700864 rio_mport_read_config_32(port, RIO_ANY_DESTID(port->sys_size),
865 hopcount, RIO_COMPONENT_TAG_CSR, &regval);
866
867 if (regval) {
868 rdev = rio_get_comptag((regval & 0xffff), NULL);
869
870 if (rdev && prev && rio_is_switch(prev)) {
871 pr_debug("RIO: redundant path to %s\n",
872 rio_name(rdev));
873 prev->rswitch->nextdev[prev_port] = rdev;
874 }
875 }
876
Matt Portereb188d02005-11-07 01:00:17 -0800877 return 0;
878 }
879
880 /* Attempt to acquire device lock */
Zhang Weie0423232008-04-18 13:33:42 -0700881 rio_mport_write_config_32(port, RIO_ANY_DESTID(port->sys_size),
882 hopcount,
Matt Portereb188d02005-11-07 01:00:17 -0800883 RIO_HOST_DID_LOCK_CSR, port->host_deviceid);
884 while ((tmp = rio_get_host_deviceid_lock(port, hopcount))
885 < port->host_deviceid) {
886 /* Delay a bit */
887 mdelay(1);
888 /* Attempt to acquire device lock again */
Zhang Weie0423232008-04-18 13:33:42 -0700889 rio_mport_write_config_32(port, RIO_ANY_DESTID(port->sys_size),
890 hopcount,
Matt Portereb188d02005-11-07 01:00:17 -0800891 RIO_HOST_DID_LOCK_CSR,
892 port->host_deviceid);
893 }
894
895 if (rio_get_host_deviceid_lock(port, hopcount) > port->host_deviceid) {
896 pr_debug(
897 "RIO: PE locked by a higher priority host...retreating\n");
898 return -1;
899 }
900
901 /* Setup new RIO device */
Zhang Weie0423232008-04-18 13:33:42 -0700902 rdev = rio_setup_device(net, port, RIO_ANY_DESTID(port->sys_size),
903 hopcount, 1);
904 if (rdev) {
Matt Portereb188d02005-11-07 01:00:17 -0800905 /* Add device to the global and bus/net specific list. */
906 list_add_tail(&rdev->net_list, &net->devices);
Alexandre Bounine68fe4df2010-10-27 15:34:29 -0700907 rdev->prev = prev;
908 if (prev && rio_is_switch(prev))
909 prev->rswitch->nextdev[prev_port] = rdev;
Matt Portereb188d02005-11-07 01:00:17 -0800910 } else
911 return -1;
912
913 if (rio_is_switch(rdev)) {
Alexandre Bouninede74e002012-10-04 17:16:13 -0700914 int sw_destid;
915 int cur_destid;
916 int sw_inport;
917 u16 destid;
918 int port_num;
919
Alexandre Bounineae05cbd2010-10-27 15:34:29 -0700920 sw_inport = RIO_GET_PORT_NUM(rdev->swpinfo);
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800921 rio_route_add_entry(rdev, RIO_GLOBAL_TABLE,
Alexandre Bounine818a04a2010-05-26 14:43:58 -0700922 port->host_deviceid, sw_inport, 0);
Alexandre Bouninec70555b2007-02-10 01:46:47 -0800923 rdev->rswitch->route_table[port->host_deviceid] = sw_inport;
Matt Portereb188d02005-11-07 01:00:17 -0800924
Alexandre Bouninede74e002012-10-04 17:16:13 -0700925 destid = rio_destid_first(net);
926 while (destid != RIO_INVALID_DESTID && destid < next_destid) {
927 if (destid != port->host_deviceid) {
928 rio_route_add_entry(rdev, RIO_GLOBAL_TABLE,
929 destid, sw_inport, 0);
930 rdev->rswitch->route_table[destid] = sw_inport;
931 }
932 destid = rio_destid_next(net, destid + 1);
Matt Portereb188d02005-11-07 01:00:17 -0800933 }
Matt Portereb188d02005-11-07 01:00:17 -0800934 pr_debug(
935 "RIO: found %s (vid %4.4x did %4.4x) with %d ports\n",
Alexandre Bounine68fe4df2010-10-27 15:34:29 -0700936 rio_name(rdev), rdev->vid, rdev->did,
937 RIO_GET_TOTAL_PORTS(rdev->swpinfo));
Alexandre Bouninec70555b2007-02-10 01:46:47 -0800938 sw_destid = next_destid;
Alexandre Bounine68fe4df2010-10-27 15:34:29 -0700939 for (port_num = 0;
940 port_num < RIO_GET_TOTAL_PORTS(rdev->swpinfo);
941 port_num++) {
Alexandre Bounine8d4630d2012-10-04 17:16:02 -0700942 if (sw_inport == port_num) {
943 rio_enable_rx_tx_port(port, 0,
Thomas Moll933af4a2010-05-26 14:44:01 -0700944 RIO_ANY_DESTID(port->sys_size),
945 hopcount, port_num);
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -0700946 rdev->rswitch->port_ok |= (1 << port_num);
Matt Portereb188d02005-11-07 01:00:17 -0800947 continue;
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -0700948 }
Matt Portereb188d02005-11-07 01:00:17 -0800949
950 cur_destid = next_destid;
951
952 if (rio_sport_is_active
Zhang Weie0423232008-04-18 13:33:42 -0700953 (port, RIO_ANY_DESTID(port->sys_size), hopcount,
954 port_num)) {
Matt Portereb188d02005-11-07 01:00:17 -0800955 pr_debug(
956 "RIO: scanning device on port %d\n",
957 port_num);
Alexandre Bounine8d4630d2012-10-04 17:16:02 -0700958 rio_enable_rx_tx_port(port, 0,
959 RIO_ANY_DESTID(port->sys_size),
960 hopcount, port_num);
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -0700961 rdev->rswitch->port_ok |= (1 << port_num);
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800962 rio_route_add_entry(rdev, RIO_GLOBAL_TABLE,
Zhang Weie0423232008-04-18 13:33:42 -0700963 RIO_ANY_DESTID(port->sys_size),
Alexandre Bounine818a04a2010-05-26 14:43:58 -0700964 port_num, 0);
Matt Portereb188d02005-11-07 01:00:17 -0800965
Alexandre Bounine68fe4df2010-10-27 15:34:29 -0700966 if (rio_enum_peer(net, port, hopcount + 1,
967 rdev, port_num) < 0)
Matt Portereb188d02005-11-07 01:00:17 -0800968 return -1;
969
970 /* Update routing tables */
Alexandre Bouninede74e002012-10-04 17:16:13 -0700971 destid = rio_destid_next(net, cur_destid + 1);
972 if (destid != RIO_INVALID_DESTID) {
Matt Portereb188d02005-11-07 01:00:17 -0800973 for (destid = cur_destid;
Alexandre Bouninede74e002012-10-04 17:16:13 -0700974 destid < next_destid;) {
975 if (destid != port->host_deviceid) {
976 rio_route_add_entry(rdev,
Matt Portereb188d02005-11-07 01:00:17 -0800977 RIO_GLOBAL_TABLE,
978 destid,
Alexandre Bounine818a04a2010-05-26 14:43:58 -0700979 port_num,
980 0);
Alexandre Bouninede74e002012-10-04 17:16:13 -0700981 rdev->rswitch->
982 route_table[destid] =
983 port_num;
984 }
985 destid = rio_destid_next(net,
986 destid + 1);
Matt Portereb188d02005-11-07 01:00:17 -0800987 }
Matt Portereb188d02005-11-07 01:00:17 -0800988 }
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -0700989 } else {
990 /* If switch supports Error Management,
991 * set PORT_LOCKOUT bit for unused port
992 */
993 if (rdev->em_efptr)
994 rio_set_port_lockout(rdev, port_num, 1);
995
996 rdev->rswitch->port_ok &= ~(1 << port_num);
Matt Portereb188d02005-11-07 01:00:17 -0800997 }
998 }
Alexandre Bouninec70555b2007-02-10 01:46:47 -0800999
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -07001000 /* Direct Port-write messages to the enumeratiing host */
1001 if ((rdev->src_ops & RIO_SRC_OPS_PORT_WRITE) &&
1002 (rdev->em_efptr)) {
1003 rio_write_config_32(rdev,
1004 rdev->em_efptr + RIO_EM_PW_TGT_DEVID,
1005 (port->host_deviceid << 16) |
1006 (port->sys_size << 15));
1007 }
1008
1009 rio_init_em(rdev);
1010
Alexandre Bouninec70555b2007-02-10 01:46:47 -08001011 /* Check for empty switch */
Alexandre Bouninede74e002012-10-04 17:16:13 -07001012 if (next_destid == sw_destid)
1013 next_destid = rio_destid_alloc(net);
Alexandre Bouninec70555b2007-02-10 01:46:47 -08001014
Alexandre Bouninea93192a2011-01-12 17:00:38 -08001015 rdev->destid = sw_destid;
Matt Portereb188d02005-11-07 01:00:17 -08001016 } else
1017 pr_debug("RIO: found %s (vid %4.4x did %4.4x)\n",
1018 rio_name(rdev), rdev->vid, rdev->did);
1019
1020 return 0;
1021}
1022
1023/**
1024 * rio_enum_complete- Tests if enumeration of a network is complete
1025 * @port: Master port to send transaction
1026 *
Liu Ganga5712592011-11-02 13:39:05 -07001027 * Tests the PGCCSR discovered bit for non-zero value (enumeration
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -07001028 * complete flag). Return %1 if enumeration is complete or %0 if
Matt Portereb188d02005-11-07 01:00:17 -08001029 * enumeration is incomplete.
1030 */
1031static int rio_enum_complete(struct rio_mport *port)
1032{
Alexandre Bounineaf84ca32010-10-27 15:34:34 -07001033 u32 regval;
Matt Portereb188d02005-11-07 01:00:17 -08001034
Alexandre Bounineaf84ca32010-10-27 15:34:34 -07001035 rio_local_read_config_32(port, port->phys_efptr + RIO_PORT_GEN_CTL_CSR,
1036 &regval);
Liu Ganga5712592011-11-02 13:39:05 -07001037 return (regval & RIO_PORT_GEN_DISCOVERED) ? 1 : 0;
Matt Portereb188d02005-11-07 01:00:17 -08001038}
1039
1040/**
1041 * rio_disc_peer- Recursively discovers a RIO network through a master port
1042 * @net: RIO network being discovered
1043 * @port: Master port to send transactions
1044 * @destid: Current destination ID in network
1045 * @hopcount: Number of hops into the network
Randy Dunlap9b310ac2011-01-22 20:16:12 -08001046 * @prev: previous rio_dev
1047 * @prev_port: previous port number
Matt Portereb188d02005-11-07 01:00:17 -08001048 *
1049 * Recursively discovers a RIO network. Transactions are sent via the
1050 * master port passed in @port.
1051 */
Li Yang181a6ff2009-05-12 16:36:03 +08001052static int __devinit
Matt Portereb188d02005-11-07 01:00:17 -08001053rio_disc_peer(struct rio_net *net, struct rio_mport *port, u16 destid,
Alexandre Bounine17e96202011-01-12 17:00:41 -08001054 u8 hopcount, struct rio_dev *prev, int prev_port)
Matt Portereb188d02005-11-07 01:00:17 -08001055{
1056 u8 port_num, route_port;
Matt Portereb188d02005-11-07 01:00:17 -08001057 struct rio_dev *rdev;
1058 u16 ndestid;
1059
1060 /* Setup new RIO device */
1061 if ((rdev = rio_setup_device(net, port, destid, hopcount, 0))) {
1062 /* Add device to the global and bus/net specific list. */
1063 list_add_tail(&rdev->net_list, &net->devices);
Alexandre Bounine17e96202011-01-12 17:00:41 -08001064 rdev->prev = prev;
1065 if (prev && rio_is_switch(prev))
1066 prev->rswitch->nextdev[prev_port] = rdev;
Matt Portereb188d02005-11-07 01:00:17 -08001067 } else
1068 return -1;
1069
1070 if (rio_is_switch(rdev)) {
Matt Portereb188d02005-11-07 01:00:17 -08001071 /* Associated destid is how we accessed this switch */
Alexandre Bouninea93192a2011-01-12 17:00:38 -08001072 rdev->destid = destid;
Matt Portereb188d02005-11-07 01:00:17 -08001073
Matt Portereb188d02005-11-07 01:00:17 -08001074 pr_debug(
1075 "RIO: found %s (vid %4.4x did %4.4x) with %d ports\n",
Alexandre Bounine68fe4df2010-10-27 15:34:29 -07001076 rio_name(rdev), rdev->vid, rdev->did,
1077 RIO_GET_TOTAL_PORTS(rdev->swpinfo));
1078 for (port_num = 0;
1079 port_num < RIO_GET_TOTAL_PORTS(rdev->swpinfo);
1080 port_num++) {
Alexandre Bounineae05cbd2010-10-27 15:34:29 -07001081 if (RIO_GET_PORT_NUM(rdev->swpinfo) == port_num)
Matt Portereb188d02005-11-07 01:00:17 -08001082 continue;
1083
1084 if (rio_sport_is_active
1085 (port, destid, hopcount, port_num)) {
1086 pr_debug(
1087 "RIO: scanning device on port %d\n",
1088 port_num);
Alexandre Bounine818a04a2010-05-26 14:43:58 -07001089
1090 rio_lock_device(port, destid, hopcount, 1000);
1091
Zhang Weie0423232008-04-18 13:33:42 -07001092 for (ndestid = 0;
1093 ndestid < RIO_ANY_DESTID(port->sys_size);
Matt Portereb188d02005-11-07 01:00:17 -08001094 ndestid++) {
Alexandre Bouninea93192a2011-01-12 17:00:38 -08001095 rio_route_get_entry(rdev,
Matt Portereb188d02005-11-07 01:00:17 -08001096 RIO_GLOBAL_TABLE,
1097 ndestid,
Alexandre Bounine818a04a2010-05-26 14:43:58 -07001098 &route_port, 0);
Matt Portereb188d02005-11-07 01:00:17 -08001099 if (route_port == port_num)
1100 break;
1101 }
1102
Alexandre Bounineaf84ca32010-10-27 15:34:34 -07001103 if (ndestid == RIO_ANY_DESTID(port->sys_size))
1104 continue;
Alexandre Bounine818a04a2010-05-26 14:43:58 -07001105 rio_unlock_device(port, destid, hopcount);
Alexandre Bounine17e96202011-01-12 17:00:41 -08001106 if (rio_disc_peer(net, port, ndestid,
1107 hopcount + 1, rdev, port_num) < 0)
Matt Portereb188d02005-11-07 01:00:17 -08001108 return -1;
1109 }
1110 }
1111 } else
1112 pr_debug("RIO: found %s (vid %4.4x did %4.4x)\n",
1113 rio_name(rdev), rdev->vid, rdev->did);
1114
1115 return 0;
1116}
1117
1118/**
1119 * rio_mport_is_active- Tests if master port link is active
1120 * @port: Master port to test
1121 *
1122 * Reads the port error status CSR for the master port to
1123 * determine if the port has an active link. Returns
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -07001124 * %RIO_PORT_N_ERR_STS_PORT_OK if the master port is active
Matt Portereb188d02005-11-07 01:00:17 -08001125 * or %0 if it is inactive.
1126 */
1127static int rio_mport_is_active(struct rio_mport *port)
1128{
1129 u32 result = 0;
1130 u32 ext_ftr_ptr;
1131 int *entry = rio_mport_phys_table;
1132
1133 do {
1134 if ((ext_ftr_ptr =
1135 rio_mport_get_feature(port, 1, 0, 0, *entry)))
1136 break;
1137 } while (*++entry >= 0);
1138
1139 if (ext_ftr_ptr)
1140 rio_local_read_config_32(port,
1141 ext_ftr_ptr +
1142 RIO_PORT_N_ERR_STS_CSR(port->index),
1143 &result);
1144
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -07001145 return result & RIO_PORT_N_ERR_STS_PORT_OK;
Matt Portereb188d02005-11-07 01:00:17 -08001146}
1147
1148/**
1149 * rio_alloc_net- Allocate and configure a new RIO network
1150 * @port: Master port associated with the RIO network
Alexandre Bouninede74e002012-10-04 17:16:13 -07001151 * @do_enum: Enumeration/Discovery mode flag
1152 * @start: logical minimal start id for new net
Matt Portereb188d02005-11-07 01:00:17 -08001153 *
1154 * Allocates a RIO network structure, initializes per-network
1155 * list heads, and adds the associated master port to the
1156 * network list of associated master ports. Returns a
1157 * RIO network pointer on success or %NULL on failure.
1158 */
Alexandre Bouninede74e002012-10-04 17:16:13 -07001159static struct rio_net __devinit *rio_alloc_net(struct rio_mport *port,
1160 int do_enum, u16 start)
Matt Portereb188d02005-11-07 01:00:17 -08001161{
1162 struct rio_net *net;
1163
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07001164 net = kzalloc(sizeof(struct rio_net), GFP_KERNEL);
Alexandre Bouninede74e002012-10-04 17:16:13 -07001165 if (net && do_enum) {
1166 net->destid_table.table = kzalloc(
1167 BITS_TO_LONGS(RIO_MAX_ROUTE_ENTRIES(port->sys_size)) *
1168 sizeof(long),
1169 GFP_KERNEL);
1170
1171 if (net->destid_table.table == NULL) {
1172 pr_err("RIO: failed to allocate destID table\n");
1173 kfree(net);
1174 net = NULL;
1175 } else {
1176 net->destid_table.start = start;
1177 net->destid_table.next = 0;
1178 net->destid_table.max =
1179 RIO_MAX_ROUTE_ENTRIES(port->sys_size);
1180 spin_lock_init(&net->destid_table.lock);
1181 }
1182 }
1183
Matt Portereb188d02005-11-07 01:00:17 -08001184 if (net) {
Matt Portereb188d02005-11-07 01:00:17 -08001185 INIT_LIST_HEAD(&net->node);
1186 INIT_LIST_HEAD(&net->devices);
Alexandre Bouninea7071ef2012-10-04 17:16:05 -07001187 INIT_LIST_HEAD(&net->switches);
Matt Portereb188d02005-11-07 01:00:17 -08001188 INIT_LIST_HEAD(&net->mports);
1189 list_add_tail(&port->nnode, &net->mports);
1190 net->hport = port;
Alexandre Bounine005842e2012-10-04 17:16:08 -07001191 net->id = port->id;
Matt Portereb188d02005-11-07 01:00:17 -08001192 }
1193 return net;
1194}
1195
1196/**
Alexandre Bouninec70555b2007-02-10 01:46:47 -08001197 * rio_update_route_tables- Updates route tables in switches
Alexandre Bouninea7071ef2012-10-04 17:16:05 -07001198 * @net: RIO network to run update on
Alexandre Bouninec70555b2007-02-10 01:46:47 -08001199 *
1200 * For each enumerated device, ensure that each switch in a system
1201 * has correct routing entries. Add routes for devices that where
1202 * unknown dirung the first enumeration pass through the switch.
1203 */
Alexandre Bouninea7071ef2012-10-04 17:16:05 -07001204static void rio_update_route_tables(struct rio_net *net)
Alexandre Bouninec70555b2007-02-10 01:46:47 -08001205{
Alexandre Bounineded05782011-01-12 17:00:39 -08001206 struct rio_dev *rdev, *swrdev;
Alexandre Bouninec70555b2007-02-10 01:46:47 -08001207 struct rio_switch *rswitch;
1208 u8 sport;
1209 u16 destid;
1210
Alexandre Bouninea7071ef2012-10-04 17:16:05 -07001211 list_for_each_entry(rdev, &net->devices, net_list) {
Alexandre Bouninec70555b2007-02-10 01:46:47 -08001212
Alexandre Bouninea93192a2011-01-12 17:00:38 -08001213 destid = rdev->destid;
Alexandre Bouninec70555b2007-02-10 01:46:47 -08001214
Alexandre Bouninea7071ef2012-10-04 17:16:05 -07001215 list_for_each_entry(rswitch, &net->switches, node) {
Alexandre Bouninec70555b2007-02-10 01:46:47 -08001216
1217 if (rio_is_switch(rdev) && (rdev->rswitch == rswitch))
1218 continue;
1219
1220 if (RIO_INVALID_ROUTE == rswitch->route_table[destid]) {
Alexandre Bounineded05782011-01-12 17:00:39 -08001221 swrdev = sw_to_rio_dev(rswitch);
1222
Alexandre Bounine07590ff2010-05-26 14:43:57 -07001223 /* Skip if destid ends in empty switch*/
Alexandre Bounineded05782011-01-12 17:00:39 -08001224 if (swrdev->destid == destid)
Alexandre Bounine07590ff2010-05-26 14:43:57 -07001225 continue;
Alexandre Bouninec70555b2007-02-10 01:46:47 -08001226
Alexandre Bounineded05782011-01-12 17:00:39 -08001227 sport = RIO_GET_PORT_NUM(swrdev->swpinfo);
Alexandre Bouninec70555b2007-02-10 01:46:47 -08001228
1229 if (rswitch->add_entry) {
Alexandre Bounineded05782011-01-12 17:00:39 -08001230 rio_route_add_entry(swrdev,
Alexandre Bounine818a04a2010-05-26 14:43:58 -07001231 RIO_GLOBAL_TABLE, destid,
1232 sport, 0);
Alexandre Bouninec70555b2007-02-10 01:46:47 -08001233 rswitch->route_table[destid] = sport;
1234 }
1235 }
1236 }
1237 }
1238}
1239
1240/**
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -07001241 * rio_init_em - Initializes RIO Error Management (for switches)
Randy Dunlap97ef6f72010-05-28 15:08:08 -07001242 * @rdev: RIO device
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -07001243 *
1244 * For each enumerated switch, call device-specific error management
1245 * initialization routine (if supplied by the switch driver).
1246 */
1247static void rio_init_em(struct rio_dev *rdev)
1248{
1249 if (rio_is_switch(rdev) && (rdev->em_efptr) &&
1250 (rdev->rswitch->em_init)) {
1251 rdev->rswitch->em_init(rdev);
1252 }
1253}
1254
1255/**
1256 * rio_pw_enable - Enables/disables port-write handling by a master port
1257 * @port: Master port associated with port-write handling
1258 * @enable: 1=enable, 0=disable
1259 */
1260static void rio_pw_enable(struct rio_mport *port, int enable)
1261{
1262 if (port->ops->pwenable)
1263 port->ops->pwenable(port, enable);
1264}
1265
1266/**
Matt Portereb188d02005-11-07 01:00:17 -08001267 * rio_enum_mport- Start enumeration through a master port
1268 * @mport: Master port to send transactions
1269 *
1270 * Starts the enumeration process. If somebody has enumerated our
1271 * master port device, then give up. If not and we have an active
1272 * link, then start recursive peer enumeration. Returns %0 if
1273 * enumeration succeeds or %-EBUSY if enumeration fails.
1274 */
Al Viro37d33d12008-11-22 17:36:24 +00001275int __devinit rio_enum_mport(struct rio_mport *mport)
Matt Portereb188d02005-11-07 01:00:17 -08001276{
1277 struct rio_net *net = NULL;
1278 int rc = 0;
1279
1280 printk(KERN_INFO "RIO: enumerate master port %d, %s\n", mport->id,
1281 mport->name);
1282 /* If somebody else enumerated our master port device, bail. */
1283 if (rio_enum_host(mport) < 0) {
1284 printk(KERN_INFO
1285 "RIO: master port %d device has been enumerated by a remote host\n",
1286 mport->id);
1287 rc = -EBUSY;
1288 goto out;
1289 }
1290
1291 /* If master port has an active link, allocate net and enum peers */
1292 if (rio_mport_is_active(mport)) {
Alexandre Bouninede74e002012-10-04 17:16:13 -07001293 net = rio_alloc_net(mport, 1, 0);
1294 if (!net) {
Matt Portereb188d02005-11-07 01:00:17 -08001295 printk(KERN_ERR "RIO: failed to allocate new net\n");
1296 rc = -ENOMEM;
1297 goto out;
1298 }
Thomas Moll933af4a2010-05-26 14:44:01 -07001299
Alexandre Bouninede74e002012-10-04 17:16:13 -07001300 /* reserve mport destID in new net */
1301 rio_destid_reserve(net, mport->host_deviceid);
1302
Thomas Moll933af4a2010-05-26 14:44:01 -07001303 /* Enable Input Output Port (transmitter reviever) */
1304 rio_enable_rx_tx_port(mport, 1, 0, 0, 0);
1305
Alexandre Bounineaf84ca32010-10-27 15:34:34 -07001306 /* Set component tag for host */
1307 rio_local_write_config_32(mport, RIO_COMPONENT_TAG_CSR,
1308 next_comptag++);
1309
Alexandre Bouninede74e002012-10-04 17:16:13 -07001310 next_destid = rio_destid_alloc(net);
1311
Alexandre Bounine68fe4df2010-10-27 15:34:29 -07001312 if (rio_enum_peer(net, mport, 0, NULL, 0) < 0) {
Matt Portereb188d02005-11-07 01:00:17 -08001313 /* A higher priority host won enumeration, bail. */
1314 printk(KERN_INFO
1315 "RIO: master port %d device has lost enumeration to a remote host\n",
1316 mport->id);
Alexandre Bouninea7071ef2012-10-04 17:16:05 -07001317 rio_clear_locks(net);
Matt Portereb188d02005-11-07 01:00:17 -08001318 rc = -EBUSY;
1319 goto out;
1320 }
Alexandre Bouninede74e002012-10-04 17:16:13 -07001321 /* free the last allocated destID (unused) */
1322 rio_destid_free(net, next_destid);
Alexandre Bouninea7071ef2012-10-04 17:16:05 -07001323 rio_update_route_tables(net);
1324 rio_clear_locks(net);
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -07001325 rio_pw_enable(mport, 1);
Matt Portereb188d02005-11-07 01:00:17 -08001326 } else {
1327 printk(KERN_INFO "RIO: master port %d link inactive\n",
1328 mport->id);
1329 rc = -EINVAL;
1330 }
1331
1332 out:
1333 return rc;
1334}
1335
1336/**
1337 * rio_build_route_tables- Generate route tables from switch route entries
Alexandre Bouninea7071ef2012-10-04 17:16:05 -07001338 * @net: RIO network to run route tables scan on
Matt Portereb188d02005-11-07 01:00:17 -08001339 *
1340 * For each switch device, generate a route table by copying existing
1341 * route entries from the switch.
1342 */
Alexandre Bouninea7071ef2012-10-04 17:16:05 -07001343static void rio_build_route_tables(struct rio_net *net)
Matt Portereb188d02005-11-07 01:00:17 -08001344{
Alexandre Bouninea7071ef2012-10-04 17:16:05 -07001345 struct rio_switch *rswitch;
Matt Portereb188d02005-11-07 01:00:17 -08001346 struct rio_dev *rdev;
1347 int i;
1348 u8 sport;
1349
Alexandre Bouninea7071ef2012-10-04 17:16:05 -07001350 list_for_each_entry(rswitch, &net->switches, node) {
1351 rdev = sw_to_rio_dev(rswitch);
Alexandre Bounine818a04a2010-05-26 14:43:58 -07001352
Alexandre Bouninea7071ef2012-10-04 17:16:05 -07001353 rio_lock_device(net->hport, rdev->destid,
1354 rdev->hopcount, 1000);
1355 for (i = 0;
1356 i < RIO_MAX_ROUTE_ENTRIES(net->hport->sys_size);
1357 i++) {
1358 if (rio_route_get_entry(rdev, RIO_GLOBAL_TABLE,
1359 i, &sport, 0) < 0)
1360 continue;
1361 rswitch->route_table[i] = sport;
Matt Portereb188d02005-11-07 01:00:17 -08001362 }
Alexandre Bouninea7071ef2012-10-04 17:16:05 -07001363
1364 rio_unlock_device(net->hport, rdev->destid, rdev->hopcount);
1365 }
Matt Portereb188d02005-11-07 01:00:17 -08001366}
1367
1368/**
Matt Portereb188d02005-11-07 01:00:17 -08001369 * rio_disc_mport- Start discovery through a master port
1370 * @mport: Master port to send transactions
1371 *
1372 * Starts the discovery process. If we have an active link,
1373 * then wait for the signal that enumeration is complete.
1374 * When enumeration completion is signaled, start recursive
1375 * peer discovery. Returns %0 if discovery succeeds or %-EBUSY
1376 * on failure.
1377 */
Al Viro37d33d12008-11-22 17:36:24 +00001378int __devinit rio_disc_mport(struct rio_mport *mport)
Matt Portereb188d02005-11-07 01:00:17 -08001379{
1380 struct rio_net *net = NULL;
Alexandre Bouninefa3dbaa2012-10-04 17:16:04 -07001381 unsigned long to_end;
Matt Portereb188d02005-11-07 01:00:17 -08001382
1383 printk(KERN_INFO "RIO: discover master port %d, %s\n", mport->id,
1384 mport->name);
1385
1386 /* If master port has an active link, allocate net and discover peers */
1387 if (rio_mport_is_active(mport)) {
Alexandre Bouninefa3dbaa2012-10-04 17:16:04 -07001388 pr_debug("RIO: wait for enumeration to complete...\n");
1389
1390 to_end = jiffies + CONFIG_RAPIDIO_DISC_TIMEOUT * HZ;
1391 while (time_before(jiffies, to_end)) {
1392 if (rio_enum_complete(mport))
1393 goto enum_done;
1394 schedule_timeout_uninterruptible(msecs_to_jiffies(10));
1395 }
1396
1397 pr_debug("RIO: discovery timeout on mport %d %s\n",
1398 mport->id, mport->name);
1399 goto bail;
1400enum_done:
1401 pr_debug("RIO: ... enumeration done\n");
1402
Alexandre Bouninede74e002012-10-04 17:16:13 -07001403 net = rio_alloc_net(mport, 0, 0);
Alexandre Bouninefa3dbaa2012-10-04 17:16:04 -07001404 if (!net) {
Matt Portereb188d02005-11-07 01:00:17 -08001405 printk(KERN_ERR "RIO: Failed to allocate new net\n");
1406 goto bail;
1407 }
1408
Alexandre Bounine818a04a2010-05-26 14:43:58 -07001409 /* Read DestID assigned by enumerator */
1410 rio_local_read_config_32(mport, RIO_DID_CSR,
1411 &mport->host_deviceid);
1412 mport->host_deviceid = RIO_GET_DID(mport->sys_size,
1413 mport->host_deviceid);
1414
Zhang Weie0423232008-04-18 13:33:42 -07001415 if (rio_disc_peer(net, mport, RIO_ANY_DESTID(mport->sys_size),
Alexandre Bounine17e96202011-01-12 17:00:41 -08001416 0, NULL, 0) < 0) {
Matt Portereb188d02005-11-07 01:00:17 -08001417 printk(KERN_INFO
1418 "RIO: master port %d device has failed discovery\n",
1419 mport->id);
1420 goto bail;
1421 }
1422
Alexandre Bouninea7071ef2012-10-04 17:16:05 -07001423 rio_build_route_tables(net);
Matt Portereb188d02005-11-07 01:00:17 -08001424 }
1425
1426 return 0;
Alexandre Bouninefa3dbaa2012-10-04 17:16:04 -07001427bail:
Matt Portereb188d02005-11-07 01:00:17 -08001428 return -EBUSY;
1429}