blob: 03b8c5af72bb9d38e7e988f3cd0a0b5719c9ec25 [file] [log] [blame]
Matt Porter394b7012005-11-07 01:00:15 -08001/*
2 * RapidIO interconnect services
3 * (RapidIO Interconnect Specification, http://www.rapidio.org)
4 *
5 * Copyright 2005 MontaVista Software, Inc.
6 * Matt Porter <mporter@kernel.crashing.org>
7 *
Alexandre Bouninefdf90ab2013-07-03 15:08:56 -07008 * Copyright 2009 - 2013 Integrated Device Technology, Inc.
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -07009 * Alex Bounine <alexandre.bounine@idt.com>
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -070010 *
Matt Porter394b7012005-11-07 01:00:15 -080011 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 */
16
Matt Porter394b7012005-11-07 01:00:15 -080017#include <linux/types.h>
18#include <linux/kernel.h>
19
20#include <linux/delay.h>
21#include <linux/init.h>
22#include <linux/rio.h>
23#include <linux/rio_drv.h>
24#include <linux/rio_ids.h>
25#include <linux/rio_regs.h>
26#include <linux/module.h>
27#include <linux/spinlock.h>
Tim Schmielaude259682006-01-08 01:02:05 -080028#include <linux/slab.h>
Kumar Gala5febf1c2008-01-23 05:53:47 -060029#include <linux/interrupt.h>
Matt Porter394b7012005-11-07 01:00:15 -080030
31#include "rio.h"
32
Alexandre Bouninefdf90ab2013-07-03 15:08:56 -070033MODULE_DESCRIPTION("RapidIO Subsystem Core");
34MODULE_AUTHOR("Matt Porter <mporter@kernel.crashing.org>");
35MODULE_AUTHOR("Alexandre Bounine <alexandre.bounine@idt.com>");
36MODULE_LICENSE("GPL");
37
38static int hdid[RIO_MAX_MPORTS];
39static int ids_num;
40module_param_array(hdid, int, &ids_num, 0);
41MODULE_PARM_DESC(hdid,
42 "Destination ID assignment to local RapidIO controllers");
43
Alexandre Bouninea11650e2013-05-24 15:55:05 -070044static LIST_HEAD(rio_devices);
Alexandre Bouninee6b585c2016-03-22 14:26:17 -070045static LIST_HEAD(rio_nets);
Alexandre Bouninea11650e2013-05-24 15:55:05 -070046static DEFINE_SPINLOCK(rio_global_list_lock);
47
Matt Porter394b7012005-11-07 01:00:15 -080048static LIST_HEAD(rio_mports);
Alexandre Bounine9edbc30b2013-07-03 15:08:53 -070049static LIST_HEAD(rio_scans);
Alexandre Bouninea11650e2013-05-24 15:55:05 -070050static DEFINE_MUTEX(rio_mport_list_lock);
Alexandre Bounine569fccb2011-03-23 16:43:05 -070051static unsigned char next_portid;
Alexandre Bounineda1589f2012-10-04 17:15:57 -070052static DEFINE_SPINLOCK(rio_mmap_lock);
Matt Porter394b7012005-11-07 01:00:15 -080053
54/**
55 * rio_local_get_device_id - Get the base/extended device id for a port
56 * @port: RIO master port from which to get the deviceid
57 *
58 * Reads the base/extended device id from the local device
59 * implementing the master port. Returns the 8/16-bit device
60 * id.
61 */
62u16 rio_local_get_device_id(struct rio_mport *port)
63{
64 u32 result;
65
66 rio_local_read_config_32(port, RIO_DID_CSR, &result);
67
Zhang Weie0423232008-04-18 13:33:42 -070068 return (RIO_GET_DID(port->sys_size, result));
Matt Porter394b7012005-11-07 01:00:15 -080069}
70
71/**
Alexandre Bounine8b189fd2016-03-22 14:26:00 -070072 * rio_query_mport - Query mport device attributes
73 * @port: mport device to query
74 * @mport_attr: mport attributes data structure
75 *
76 * Returns attributes of specified mport through the
77 * pointer to attributes data structure.
78 */
79int rio_query_mport(struct rio_mport *port,
80 struct rio_mport_attr *mport_attr)
81{
82 if (!port->ops->query_mport)
83 return -ENODATA;
84 return port->ops->query_mport(port, mport_attr);
85}
86EXPORT_SYMBOL(rio_query_mport);
87
88/**
Alexandre Bouninee6b585c2016-03-22 14:26:17 -070089 * rio_alloc_net- Allocate and initialize a new RIO network data structure
90 * @mport: Master port associated with the RIO network
91 *
92 * Allocates a RIO network structure, initializes per-network
93 * list heads, and adds the associated master port to the
94 * network list of associated master ports. Returns a
95 * RIO network pointer on success or %NULL on failure.
96 */
97struct rio_net *rio_alloc_net(struct rio_mport *mport)
98{
99 struct rio_net *net;
100
101 net = kzalloc(sizeof(struct rio_net), GFP_KERNEL);
102 if (net) {
103 INIT_LIST_HEAD(&net->node);
104 INIT_LIST_HEAD(&net->devices);
105 INIT_LIST_HEAD(&net->switches);
106 INIT_LIST_HEAD(&net->mports);
107 mport->net = net;
108 }
109 return net;
110}
111EXPORT_SYMBOL_GPL(rio_alloc_net);
112
113int rio_add_net(struct rio_net *net)
114{
115 int err;
116
117 err = device_register(&net->dev);
118 if (err)
119 return err;
120 spin_lock(&rio_global_list_lock);
121 list_add_tail(&net->node, &rio_nets);
122 spin_unlock(&rio_global_list_lock);
123
124 return 0;
125}
126EXPORT_SYMBOL_GPL(rio_add_net);
127
128void rio_free_net(struct rio_net *net)
129{
130 spin_lock(&rio_global_list_lock);
131 if (!list_empty(&net->node))
132 list_del(&net->node);
133 spin_unlock(&rio_global_list_lock);
134 if (net->release)
135 net->release(net);
136 device_unregister(&net->dev);
137}
138EXPORT_SYMBOL_GPL(rio_free_net);
139
140/**
Alexandre Bouninea11650e2013-05-24 15:55:05 -0700141 * rio_add_device- Adds a RIO device to the device model
142 * @rdev: RIO device
143 *
144 * Adds the RIO device to the global device list and adds the RIO
145 * device to the RIO device list. Creates the generic sysfs nodes
146 * for an RIO device.
147 */
148int rio_add_device(struct rio_dev *rdev)
149{
150 int err;
151
Alexandre Bounineb77a2032016-03-22 14:26:20 -0700152 atomic_set(&rdev->state, RIO_DEVICE_RUNNING);
Alexandre Bounineb74ec562016-03-22 14:26:14 -0700153 err = device_register(&rdev->dev);
Alexandre Bouninea11650e2013-05-24 15:55:05 -0700154 if (err)
155 return err;
156
157 spin_lock(&rio_global_list_lock);
158 list_add_tail(&rdev->global_list, &rio_devices);
Alexandre Bounineb74ec562016-03-22 14:26:14 -0700159 if (rdev->net) {
160 list_add_tail(&rdev->net_list, &rdev->net->devices);
161 if (rdev->pef & RIO_PEF_SWITCH)
162 list_add_tail(&rdev->rswitch->node,
163 &rdev->net->switches);
164 }
Alexandre Bouninea11650e2013-05-24 15:55:05 -0700165 spin_unlock(&rio_global_list_lock);
166
167 rio_create_sysfs_dev_files(rdev);
168
169 return 0;
170}
171EXPORT_SYMBOL_GPL(rio_add_device);
172
Alexandre Bounineb74ec562016-03-22 14:26:14 -0700173/*
174 * rio_del_device - removes a RIO device from the device model
175 * @rdev: RIO device
Alexandre Bounineb77a2032016-03-22 14:26:20 -0700176 * @state: device state to set during removal process
Alexandre Bounineb74ec562016-03-22 14:26:14 -0700177 *
178 * Removes the RIO device to the kernel device list and subsystem's device list.
179 * Clears sysfs entries for the removed device.
180 */
Alexandre Bounineb77a2032016-03-22 14:26:20 -0700181void rio_del_device(struct rio_dev *rdev, enum rio_device_state state)
Alexandre Bounineb74ec562016-03-22 14:26:14 -0700182{
183 pr_debug("RIO: %s: removing %s\n", __func__, rio_name(rdev));
Alexandre Bounineb77a2032016-03-22 14:26:20 -0700184 atomic_set(&rdev->state, state);
Alexandre Bounineb74ec562016-03-22 14:26:14 -0700185 spin_lock(&rio_global_list_lock);
186 list_del(&rdev->global_list);
187 if (rdev->net) {
188 list_del(&rdev->net_list);
189 if (rdev->pef & RIO_PEF_SWITCH) {
190 list_del(&rdev->rswitch->node);
191 kfree(rdev->rswitch->route_table);
192 }
193 }
194 spin_unlock(&rio_global_list_lock);
195 rio_remove_sysfs_dev_files(rdev);
196 device_unregister(&rdev->dev);
197}
198EXPORT_SYMBOL_GPL(rio_del_device);
199
Alexandre Bouninea11650e2013-05-24 15:55:05 -0700200/**
Matt Porter394b7012005-11-07 01:00:15 -0800201 * rio_request_inb_mbox - request inbound mailbox service
202 * @mport: RIO master port from which to allocate the mailbox resource
Matt Porter6978bbc2005-11-07 01:00:20 -0800203 * @dev_id: Device specific pointer to pass on event
Matt Porter394b7012005-11-07 01:00:15 -0800204 * @mbox: Mailbox number to claim
205 * @entries: Number of entries in inbound mailbox queue
206 * @minb: Callback to execute when inbound message is received
207 *
208 * Requests ownership of an inbound mailbox resource and binds
209 * a callback function to the resource. Returns %0 on success.
210 */
211int rio_request_inb_mbox(struct rio_mport *mport,
Matt Porter6978bbc2005-11-07 01:00:20 -0800212 void *dev_id,
Matt Porter394b7012005-11-07 01:00:15 -0800213 int mbox,
214 int entries,
Matt Porter6978bbc2005-11-07 01:00:20 -0800215 void (*minb) (struct rio_mport * mport, void *dev_id, int mbox,
Matt Porter394b7012005-11-07 01:00:15 -0800216 int slot))
217{
Alexandre Bouninef8f06262011-03-23 16:43:02 -0700218 int rc = -ENOSYS;
219 struct resource *res;
Matt Porter394b7012005-11-07 01:00:15 -0800220
Alexandre Bouninef8f06262011-03-23 16:43:02 -0700221 if (mport->ops->open_inb_mbox == NULL)
222 goto out;
223
Toshi Kani9a975be2016-01-26 21:57:25 +0100224 res = kzalloc(sizeof(struct resource), GFP_KERNEL);
Matt Porter394b7012005-11-07 01:00:15 -0800225
226 if (res) {
227 rio_init_mbox_res(res, mbox, mbox);
228
229 /* Make sure this mailbox isn't in use */
230 if ((rc =
231 request_resource(&mport->riores[RIO_INB_MBOX_RESOURCE],
232 res)) < 0) {
233 kfree(res);
234 goto out;
235 }
236
237 mport->inb_msg[mbox].res = res;
238
239 /* Hook the inbound message callback */
240 mport->inb_msg[mbox].mcback = minb;
241
Alexandre Bouninef8f06262011-03-23 16:43:02 -0700242 rc = mport->ops->open_inb_mbox(mport, dev_id, mbox, entries);
Matt Porter394b7012005-11-07 01:00:15 -0800243 } else
244 rc = -ENOMEM;
245
246 out:
247 return rc;
248}
249
250/**
251 * rio_release_inb_mbox - release inbound mailbox message service
252 * @mport: RIO master port from which to release the mailbox resource
253 * @mbox: Mailbox number to release
254 *
255 * Releases ownership of an inbound mailbox resource. Returns 0
256 * if the request has been satisfied.
257 */
258int rio_release_inb_mbox(struct rio_mport *mport, int mbox)
259{
Alexandre Bouninef8f06262011-03-23 16:43:02 -0700260 if (mport->ops->close_inb_mbox) {
261 mport->ops->close_inb_mbox(mport, mbox);
Matt Porter394b7012005-11-07 01:00:15 -0800262
Alexandre Bouninef8f06262011-03-23 16:43:02 -0700263 /* Release the mailbox resource */
264 return release_resource(mport->inb_msg[mbox].res);
265 } else
266 return -ENOSYS;
Matt Porter394b7012005-11-07 01:00:15 -0800267}
268
269/**
270 * rio_request_outb_mbox - request outbound mailbox service
271 * @mport: RIO master port from which to allocate the mailbox resource
Matt Porter6978bbc2005-11-07 01:00:20 -0800272 * @dev_id: Device specific pointer to pass on event
Matt Porter394b7012005-11-07 01:00:15 -0800273 * @mbox: Mailbox number to claim
274 * @entries: Number of entries in outbound mailbox queue
275 * @moutb: Callback to execute when outbound message is sent
276 *
277 * Requests ownership of an outbound mailbox resource and binds
278 * a callback function to the resource. Returns 0 on success.
279 */
280int rio_request_outb_mbox(struct rio_mport *mport,
Matt Porter6978bbc2005-11-07 01:00:20 -0800281 void *dev_id,
Matt Porter394b7012005-11-07 01:00:15 -0800282 int mbox,
283 int entries,
Matt Porter6978bbc2005-11-07 01:00:20 -0800284 void (*moutb) (struct rio_mport * mport, void *dev_id, int mbox, int slot))
Matt Porter394b7012005-11-07 01:00:15 -0800285{
Alexandre Bouninef8f06262011-03-23 16:43:02 -0700286 int rc = -ENOSYS;
287 struct resource *res;
Matt Porter394b7012005-11-07 01:00:15 -0800288
Alexandre Bouninef8f06262011-03-23 16:43:02 -0700289 if (mport->ops->open_outb_mbox == NULL)
290 goto out;
291
Toshi Kani9a975be2016-01-26 21:57:25 +0100292 res = kzalloc(sizeof(struct resource), GFP_KERNEL);
Matt Porter394b7012005-11-07 01:00:15 -0800293
294 if (res) {
295 rio_init_mbox_res(res, mbox, mbox);
296
297 /* Make sure this outbound mailbox isn't in use */
298 if ((rc =
299 request_resource(&mport->riores[RIO_OUTB_MBOX_RESOURCE],
300 res)) < 0) {
301 kfree(res);
302 goto out;
303 }
304
305 mport->outb_msg[mbox].res = res;
306
307 /* Hook the inbound message callback */
308 mport->outb_msg[mbox].mcback = moutb;
309
Alexandre Bouninef8f06262011-03-23 16:43:02 -0700310 rc = mport->ops->open_outb_mbox(mport, dev_id, mbox, entries);
Matt Porter394b7012005-11-07 01:00:15 -0800311 } else
312 rc = -ENOMEM;
313
314 out:
315 return rc;
316}
317
318/**
319 * rio_release_outb_mbox - release outbound mailbox message service
320 * @mport: RIO master port from which to release the mailbox resource
321 * @mbox: Mailbox number to release
322 *
323 * Releases ownership of an inbound mailbox resource. Returns 0
324 * if the request has been satisfied.
325 */
326int rio_release_outb_mbox(struct rio_mport *mport, int mbox)
327{
Alexandre Bouninef8f06262011-03-23 16:43:02 -0700328 if (mport->ops->close_outb_mbox) {
329 mport->ops->close_outb_mbox(mport, mbox);
Matt Porter394b7012005-11-07 01:00:15 -0800330
Alexandre Bouninef8f06262011-03-23 16:43:02 -0700331 /* Release the mailbox resource */
332 return release_resource(mport->outb_msg[mbox].res);
333 } else
334 return -ENOSYS;
Matt Porter394b7012005-11-07 01:00:15 -0800335}
336
337/**
338 * rio_setup_inb_dbell - bind inbound doorbell callback
339 * @mport: RIO master port to bind the doorbell callback
Matt Porter6978bbc2005-11-07 01:00:20 -0800340 * @dev_id: Device specific pointer to pass on event
Matt Porter394b7012005-11-07 01:00:15 -0800341 * @res: Doorbell message resource
342 * @dinb: Callback to execute when doorbell is received
343 *
344 * Adds a doorbell resource/callback pair into a port's
345 * doorbell event list. Returns 0 if the request has been
346 * satisfied.
347 */
348static int
Matt Porter6978bbc2005-11-07 01:00:20 -0800349rio_setup_inb_dbell(struct rio_mport *mport, void *dev_id, struct resource *res,
350 void (*dinb) (struct rio_mport * mport, void *dev_id, u16 src, u16 dst,
Matt Porter394b7012005-11-07 01:00:15 -0800351 u16 info))
352{
353 int rc = 0;
354 struct rio_dbell *dbell;
355
356 if (!(dbell = kmalloc(sizeof(struct rio_dbell), GFP_KERNEL))) {
357 rc = -ENOMEM;
358 goto out;
359 }
360
361 dbell->res = res;
362 dbell->dinb = dinb;
Matt Porter6978bbc2005-11-07 01:00:20 -0800363 dbell->dev_id = dev_id;
Matt Porter394b7012005-11-07 01:00:15 -0800364
365 list_add_tail(&dbell->node, &mport->dbells);
366
367 out:
368 return rc;
369}
370
371/**
372 * rio_request_inb_dbell - request inbound doorbell message service
373 * @mport: RIO master port from which to allocate the doorbell resource
Matt Porter6978bbc2005-11-07 01:00:20 -0800374 * @dev_id: Device specific pointer to pass on event
Matt Porter394b7012005-11-07 01:00:15 -0800375 * @start: Doorbell info range start
376 * @end: Doorbell info range end
377 * @dinb: Callback to execute when doorbell is received
378 *
379 * Requests ownership of an inbound doorbell resource and binds
380 * a callback function to the resource. Returns 0 if the request
381 * has been satisfied.
382 */
383int rio_request_inb_dbell(struct rio_mport *mport,
Matt Porter6978bbc2005-11-07 01:00:20 -0800384 void *dev_id,
Matt Porter394b7012005-11-07 01:00:15 -0800385 u16 start,
386 u16 end,
Matt Porter6978bbc2005-11-07 01:00:20 -0800387 void (*dinb) (struct rio_mport * mport, void *dev_id, u16 src,
Matt Porter394b7012005-11-07 01:00:15 -0800388 u16 dst, u16 info))
389{
390 int rc = 0;
391
Toshi Kani9a975be2016-01-26 21:57:25 +0100392 struct resource *res = kzalloc(sizeof(struct resource), GFP_KERNEL);
Matt Porter394b7012005-11-07 01:00:15 -0800393
394 if (res) {
395 rio_init_dbell_res(res, start, end);
396
397 /* Make sure these doorbells aren't in use */
398 if ((rc =
399 request_resource(&mport->riores[RIO_DOORBELL_RESOURCE],
400 res)) < 0) {
401 kfree(res);
402 goto out;
403 }
404
405 /* Hook the doorbell callback */
Matt Porter6978bbc2005-11-07 01:00:20 -0800406 rc = rio_setup_inb_dbell(mport, dev_id, res, dinb);
Matt Porter394b7012005-11-07 01:00:15 -0800407 } else
408 rc = -ENOMEM;
409
410 out:
411 return rc;
412}
413
414/**
415 * rio_release_inb_dbell - release inbound doorbell message service
416 * @mport: RIO master port from which to release the doorbell resource
417 * @start: Doorbell info range start
418 * @end: Doorbell info range end
419 *
420 * Releases ownership of an inbound doorbell resource and removes
421 * callback from the doorbell event list. Returns 0 if the request
422 * has been satisfied.
423 */
424int rio_release_inb_dbell(struct rio_mport *mport, u16 start, u16 end)
425{
426 int rc = 0, found = 0;
427 struct rio_dbell *dbell;
428
429 list_for_each_entry(dbell, &mport->dbells, node) {
430 if ((dbell->res->start == start) && (dbell->res->end == end)) {
431 found = 1;
432 break;
433 }
434 }
435
436 /* If we can't find an exact match, fail */
437 if (!found) {
438 rc = -EINVAL;
439 goto out;
440 }
441
442 /* Delete from list */
443 list_del(&dbell->node);
444
445 /* Release the doorbell resource */
446 rc = release_resource(dbell->res);
447
448 /* Free the doorbell event */
449 kfree(dbell);
450
451 out:
452 return rc;
453}
454
455/**
456 * rio_request_outb_dbell - request outbound doorbell message range
457 * @rdev: RIO device from which to allocate the doorbell resource
458 * @start: Doorbell message range start
459 * @end: Doorbell message range end
460 *
461 * Requests ownership of a doorbell message range. Returns a resource
462 * if the request has been satisfied or %NULL on failure.
463 */
464struct resource *rio_request_outb_dbell(struct rio_dev *rdev, u16 start,
465 u16 end)
466{
Toshi Kani9a975be2016-01-26 21:57:25 +0100467 struct resource *res = kzalloc(sizeof(struct resource), GFP_KERNEL);
Matt Porter394b7012005-11-07 01:00:15 -0800468
469 if (res) {
470 rio_init_dbell_res(res, start, end);
471
472 /* Make sure these doorbells aren't in use */
473 if (request_resource(&rdev->riores[RIO_DOORBELL_RESOURCE], res)
474 < 0) {
475 kfree(res);
476 res = NULL;
477 }
478 }
479
480 return res;
481}
482
483/**
484 * rio_release_outb_dbell - release outbound doorbell message range
485 * @rdev: RIO device from which to release the doorbell resource
486 * @res: Doorbell resource to be freed
487 *
488 * Releases ownership of a doorbell message range. Returns 0 if the
489 * request has been satisfied.
490 */
491int rio_release_outb_dbell(struct rio_dev *rdev, struct resource *res)
492{
493 int rc = release_resource(res);
494
495 kfree(res);
496
497 return rc;
498}
499
500/**
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -0700501 * rio_request_inb_pwrite - request inbound port-write message service
Randy Dunlap97ef6f72010-05-28 15:08:08 -0700502 * @rdev: RIO device to which register inbound port-write callback routine
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -0700503 * @pwcback: Callback routine to execute when port-write is received
504 *
505 * Binds a port-write callback function to the RapidIO device.
506 * Returns 0 if the request has been satisfied.
507 */
508int rio_request_inb_pwrite(struct rio_dev *rdev,
509 int (*pwcback)(struct rio_dev *rdev, union rio_pw_msg *msg, int step))
510{
511 int rc = 0;
512
513 spin_lock(&rio_global_list_lock);
514 if (rdev->pwcback != NULL)
515 rc = -ENOMEM;
516 else
517 rdev->pwcback = pwcback;
518
519 spin_unlock(&rio_global_list_lock);
520 return rc;
521}
522EXPORT_SYMBOL_GPL(rio_request_inb_pwrite);
523
524/**
525 * rio_release_inb_pwrite - release inbound port-write message service
526 * @rdev: RIO device which registered for inbound port-write callback
527 *
528 * Removes callback from the rio_dev structure. Returns 0 if the request
529 * has been satisfied.
530 */
531int rio_release_inb_pwrite(struct rio_dev *rdev)
532{
533 int rc = -ENOMEM;
534
535 spin_lock(&rio_global_list_lock);
536 if (rdev->pwcback) {
537 rdev->pwcback = NULL;
538 rc = 0;
539 }
540
541 spin_unlock(&rio_global_list_lock);
542 return rc;
543}
544EXPORT_SYMBOL_GPL(rio_release_inb_pwrite);
545
546/**
Alexandre Bounineda1589f2012-10-04 17:15:57 -0700547 * rio_map_inb_region -- Map inbound memory region.
548 * @mport: Master port.
Randy Dunlap2ca3cb52012-11-16 14:14:56 -0800549 * @local: physical address of memory region to be mapped
Alexandre Bounineda1589f2012-10-04 17:15:57 -0700550 * @rbase: RIO base address assigned to this window
551 * @size: Size of the memory region
552 * @rflags: Flags for mapping.
553 *
554 * Return: 0 -- Success.
555 *
556 * This function will create the mapping from RIO space to local memory.
557 */
558int rio_map_inb_region(struct rio_mport *mport, dma_addr_t local,
559 u64 rbase, u32 size, u32 rflags)
560{
561 int rc = 0;
562 unsigned long flags;
563
564 if (!mport->ops->map_inb)
565 return -1;
566 spin_lock_irqsave(&rio_mmap_lock, flags);
567 rc = mport->ops->map_inb(mport, local, rbase, size, rflags);
568 spin_unlock_irqrestore(&rio_mmap_lock, flags);
569 return rc;
570}
571EXPORT_SYMBOL_GPL(rio_map_inb_region);
572
573/**
574 * rio_unmap_inb_region -- Unmap the inbound memory region
575 * @mport: Master port
576 * @lstart: physical address of memory region to be unmapped
577 */
578void rio_unmap_inb_region(struct rio_mport *mport, dma_addr_t lstart)
579{
580 unsigned long flags;
581 if (!mport->ops->unmap_inb)
582 return;
583 spin_lock_irqsave(&rio_mmap_lock, flags);
584 mport->ops->unmap_inb(mport, lstart);
585 spin_unlock_irqrestore(&rio_mmap_lock, flags);
586}
587EXPORT_SYMBOL_GPL(rio_unmap_inb_region);
588
589/**
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -0700590 * rio_mport_get_physefb - Helper function that returns register offset
591 * for Physical Layer Extended Features Block.
Randy Dunlap97ef6f72010-05-28 15:08:08 -0700592 * @port: Master port to issue transaction
593 * @local: Indicate a local master port or remote device access
594 * @destid: Destination ID of the device
595 * @hopcount: Number of switch hops to the device
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -0700596 */
597u32
598rio_mport_get_physefb(struct rio_mport *port, int local,
599 u16 destid, u8 hopcount)
600{
601 u32 ext_ftr_ptr;
602 u32 ftr_header;
603
604 ext_ftr_ptr = rio_mport_get_efb(port, local, destid, hopcount, 0);
605
606 while (ext_ftr_ptr) {
607 if (local)
608 rio_local_read_config_32(port, ext_ftr_ptr,
609 &ftr_header);
610 else
611 rio_mport_read_config_32(port, destid, hopcount,
612 ext_ftr_ptr, &ftr_header);
613
614 ftr_header = RIO_GET_BLOCK_ID(ftr_header);
615 switch (ftr_header) {
616
617 case RIO_EFB_SER_EP_ID_V13P:
618 case RIO_EFB_SER_EP_REC_ID_V13P:
619 case RIO_EFB_SER_EP_FREE_ID_V13P:
620 case RIO_EFB_SER_EP_ID:
621 case RIO_EFB_SER_EP_REC_ID:
622 case RIO_EFB_SER_EP_FREE_ID:
623 case RIO_EFB_SER_EP_FREC_ID:
624
625 return ext_ftr_ptr;
626
627 default:
628 break;
629 }
630
631 ext_ftr_ptr = rio_mport_get_efb(port, local, destid,
632 hopcount, ext_ftr_ptr);
633 }
634
635 return ext_ftr_ptr;
636}
Alexandre Bouninea11650e2013-05-24 15:55:05 -0700637EXPORT_SYMBOL_GPL(rio_mport_get_physefb);
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -0700638
639/**
640 * rio_get_comptag - Begin or continue searching for a RIO device by component tag
Randy Dunlap97ef6f72010-05-28 15:08:08 -0700641 * @comp_tag: RIO component tag to match
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -0700642 * @from: Previous RIO device found in search, or %NULL for new search
643 *
644 * Iterates through the list of known RIO devices. If a RIO device is
645 * found with a matching @comp_tag, a pointer to its device
646 * structure is returned. Otherwise, %NULL is returned. A new search
647 * is initiated by passing %NULL to the @from argument. Otherwise, if
648 * @from is not %NULL, searches continue from next device on the global
649 * list.
650 */
Alexandre Bounineaf84ca32010-10-27 15:34:34 -0700651struct rio_dev *rio_get_comptag(u32 comp_tag, struct rio_dev *from)
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -0700652{
653 struct list_head *n;
654 struct rio_dev *rdev;
655
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -0700656 spin_lock(&rio_global_list_lock);
657 n = from ? from->global_list.next : rio_devices.next;
658
659 while (n && (n != &rio_devices)) {
660 rdev = rio_dev_g(n);
661 if (rdev->comp_tag == comp_tag)
662 goto exit;
663 n = n->next;
664 }
665 rdev = NULL;
666exit:
667 spin_unlock(&rio_global_list_lock);
668 return rdev;
669}
Alexandre Bouninea11650e2013-05-24 15:55:05 -0700670EXPORT_SYMBOL_GPL(rio_get_comptag);
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -0700671
672/**
673 * rio_set_port_lockout - Sets/clears LOCKOUT bit (RIO EM 1.3) for a switch port.
674 * @rdev: Pointer to RIO device control structure
675 * @pnum: Switch port number to set LOCKOUT bit
676 * @lock: Operation : set (=1) or clear (=0)
677 */
678int rio_set_port_lockout(struct rio_dev *rdev, u32 pnum, int lock)
679{
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -0700680 u32 regval;
681
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800682 rio_read_config_32(rdev,
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -0700683 rdev->phys_efptr + RIO_PORT_N_CTL_CSR(pnum),
684 &regval);
685 if (lock)
686 regval |= RIO_PORT_N_CTL_LOCKOUT;
687 else
688 regval &= ~RIO_PORT_N_CTL_LOCKOUT;
689
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800690 rio_write_config_32(rdev,
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -0700691 rdev->phys_efptr + RIO_PORT_N_CTL_CSR(pnum),
692 regval);
693 return 0;
694}
Alexandre Bouninea11650e2013-05-24 15:55:05 -0700695EXPORT_SYMBOL_GPL(rio_set_port_lockout);
696
697/**
Alexandre Bouninea11650e2013-05-24 15:55:05 -0700698 * rio_enable_rx_tx_port - enable input receiver and output transmitter of
699 * given port
700 * @port: Master port associated with the RIO network
701 * @local: local=1 select local port otherwise a far device is reached
702 * @destid: Destination ID of the device to check host bit
703 * @hopcount: Number of hops to reach the target
704 * @port_num: Port (-number on switch) to enable on a far end device
705 *
706 * Returns 0 or 1 from on General Control Command and Status Register
707 * (EXT_PTR+0x3C)
708 */
709int rio_enable_rx_tx_port(struct rio_mport *port,
710 int local, u16 destid,
711 u8 hopcount, u8 port_num)
712{
713#ifdef CONFIG_RAPIDIO_ENABLE_RX_TX_PORTS
714 u32 regval;
715 u32 ext_ftr_ptr;
716
717 /*
718 * enable rx input tx output port
719 */
720 pr_debug("rio_enable_rx_tx_port(local = %d, destid = %d, hopcount = "
721 "%d, port_num = %d)\n", local, destid, hopcount, port_num);
722
723 ext_ftr_ptr = rio_mport_get_physefb(port, local, destid, hopcount);
724
725 if (local) {
726 rio_local_read_config_32(port, ext_ftr_ptr +
727 RIO_PORT_N_CTL_CSR(0),
728 &regval);
729 } else {
730 if (rio_mport_read_config_32(port, destid, hopcount,
731 ext_ftr_ptr + RIO_PORT_N_CTL_CSR(port_num), &regval) < 0)
732 return -EIO;
733 }
734
735 if (regval & RIO_PORT_N_CTL_P_TYP_SER) {
736 /* serial */
737 regval = regval | RIO_PORT_N_CTL_EN_RX_SER
738 | RIO_PORT_N_CTL_EN_TX_SER;
739 } else {
740 /* parallel */
741 regval = regval | RIO_PORT_N_CTL_EN_RX_PAR
742 | RIO_PORT_N_CTL_EN_TX_PAR;
743 }
744
745 if (local) {
746 rio_local_write_config_32(port, ext_ftr_ptr +
747 RIO_PORT_N_CTL_CSR(0), regval);
748 } else {
749 if (rio_mport_write_config_32(port, destid, hopcount,
750 ext_ftr_ptr + RIO_PORT_N_CTL_CSR(port_num), regval) < 0)
751 return -EIO;
752 }
753#endif
754 return 0;
755}
756EXPORT_SYMBOL_GPL(rio_enable_rx_tx_port);
757
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -0700758
759/**
Alexandre Bounine6429cd42010-10-27 15:34:32 -0700760 * rio_chk_dev_route - Validate route to the specified device.
761 * @rdev: RIO device failed to respond
762 * @nrdev: Last active device on the route to rdev
763 * @npnum: nrdev's port number on the route to rdev
764 *
765 * Follows a route to the specified RIO device to determine the last available
766 * device (and corresponding RIO port) on the route.
767 */
768static int
769rio_chk_dev_route(struct rio_dev *rdev, struct rio_dev **nrdev, int *npnum)
770{
771 u32 result;
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800772 int p_port, rc = -EIO;
Alexandre Bounine6429cd42010-10-27 15:34:32 -0700773 struct rio_dev *prev = NULL;
774
775 /* Find switch with failed RIO link */
776 while (rdev->prev && (rdev->prev->pef & RIO_PEF_SWITCH)) {
777 if (!rio_read_config_32(rdev->prev, RIO_DEV_ID_CAR, &result)) {
778 prev = rdev->prev;
779 break;
780 }
781 rdev = rdev->prev;
782 }
783
784 if (prev == NULL)
785 goto err_out;
786
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800787 p_port = prev->rswitch->route_table[rdev->destid];
Alexandre Bounine6429cd42010-10-27 15:34:32 -0700788
Alexandre Bounineaf84ca32010-10-27 15:34:34 -0700789 if (p_port != RIO_INVALID_ROUTE) {
Alexandre Bounine6429cd42010-10-27 15:34:32 -0700790 pr_debug("RIO: link failed on [%s]-P%d\n",
791 rio_name(prev), p_port);
792 *nrdev = prev;
793 *npnum = p_port;
794 rc = 0;
795 } else
Alexandre Bounineaf84ca32010-10-27 15:34:34 -0700796 pr_debug("RIO: failed to trace route to %s\n", rio_name(rdev));
Alexandre Bounine6429cd42010-10-27 15:34:32 -0700797err_out:
798 return rc;
799}
800
801/**
802 * rio_mport_chk_dev_access - Validate access to the specified device.
803 * @mport: Master port to send transactions
804 * @destid: Device destination ID in network
805 * @hopcount: Number of hops into the network
806 */
Alexandre Bouninee274e0e2010-10-27 15:34:32 -0700807int
Alexandre Bounine6429cd42010-10-27 15:34:32 -0700808rio_mport_chk_dev_access(struct rio_mport *mport, u16 destid, u8 hopcount)
809{
810 int i = 0;
811 u32 tmp;
812
813 while (rio_mport_read_config_32(mport, destid, hopcount,
814 RIO_DEV_ID_CAR, &tmp)) {
815 i++;
816 if (i == RIO_MAX_CHK_RETRY)
817 return -EIO;
818 mdelay(1);
819 }
820
821 return 0;
822}
Alexandre Bouninea11650e2013-05-24 15:55:05 -0700823EXPORT_SYMBOL_GPL(rio_mport_chk_dev_access);
Alexandre Bounine6429cd42010-10-27 15:34:32 -0700824
825/**
826 * rio_chk_dev_access - Validate access to the specified device.
827 * @rdev: Pointer to RIO device control structure
828 */
829static int rio_chk_dev_access(struct rio_dev *rdev)
830{
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800831 return rio_mport_chk_dev_access(rdev->net->hport,
832 rdev->destid, rdev->hopcount);
Alexandre Bounine6429cd42010-10-27 15:34:32 -0700833}
834
835/**
Alexandre Bouninedd5648c2010-10-27 15:34:30 -0700836 * rio_get_input_status - Sends a Link-Request/Input-Status control symbol and
837 * returns link-response (if requested).
838 * @rdev: RIO devive to issue Input-status command
839 * @pnum: Device port number to issue the command
840 * @lnkresp: Response from a link partner
841 */
842static int
843rio_get_input_status(struct rio_dev *rdev, int pnum, u32 *lnkresp)
844{
Alexandre Bouninedd5648c2010-10-27 15:34:30 -0700845 u32 regval;
846 int checkcount;
847
848 if (lnkresp) {
849 /* Read from link maintenance response register
850 * to clear valid bit */
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800851 rio_read_config_32(rdev,
Alexandre Bouninedd5648c2010-10-27 15:34:30 -0700852 rdev->phys_efptr + RIO_PORT_N_MNT_RSP_CSR(pnum),
853 &regval);
854 udelay(50);
855 }
856
857 /* Issue Input-status command */
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800858 rio_write_config_32(rdev,
Alexandre Bouninedd5648c2010-10-27 15:34:30 -0700859 rdev->phys_efptr + RIO_PORT_N_MNT_REQ_CSR(pnum),
860 RIO_MNT_REQ_CMD_IS);
861
862 /* Exit if the response is not expected */
863 if (lnkresp == NULL)
864 return 0;
865
866 checkcount = 3;
867 while (checkcount--) {
868 udelay(50);
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800869 rio_read_config_32(rdev,
Alexandre Bouninedd5648c2010-10-27 15:34:30 -0700870 rdev->phys_efptr + RIO_PORT_N_MNT_RSP_CSR(pnum),
871 &regval);
872 if (regval & RIO_PORT_N_MNT_RSP_RVAL) {
873 *lnkresp = regval;
874 return 0;
875 }
876 }
877
878 return -EIO;
879}
880
881/**
882 * rio_clr_err_stopped - Clears port Error-stopped states.
883 * @rdev: Pointer to RIO device control structure
884 * @pnum: Switch port number to clear errors
885 * @err_status: port error status (if 0 reads register from device)
886 */
887static int rio_clr_err_stopped(struct rio_dev *rdev, u32 pnum, u32 err_status)
888{
Alexandre Bouninedd5648c2010-10-27 15:34:30 -0700889 struct rio_dev *nextdev = rdev->rswitch->nextdev[pnum];
890 u32 regval;
891 u32 far_ackid, far_linkstat, near_ackid;
892
893 if (err_status == 0)
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800894 rio_read_config_32(rdev,
Alexandre Bouninedd5648c2010-10-27 15:34:30 -0700895 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(pnum),
896 &err_status);
897
898 if (err_status & RIO_PORT_N_ERR_STS_PW_OUT_ES) {
899 pr_debug("RIO_EM: servicing Output Error-Stopped state\n");
900 /*
901 * Send a Link-Request/Input-Status control symbol
902 */
903 if (rio_get_input_status(rdev, pnum, &regval)) {
904 pr_debug("RIO_EM: Input-status response timeout\n");
905 goto rd_err;
906 }
907
908 pr_debug("RIO_EM: SP%d Input-status response=0x%08x\n",
909 pnum, regval);
910 far_ackid = (regval & RIO_PORT_N_MNT_RSP_ASTAT) >> 5;
911 far_linkstat = regval & RIO_PORT_N_MNT_RSP_LSTAT;
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800912 rio_read_config_32(rdev,
Alexandre Bouninedd5648c2010-10-27 15:34:30 -0700913 rdev->phys_efptr + RIO_PORT_N_ACK_STS_CSR(pnum),
914 &regval);
915 pr_debug("RIO_EM: SP%d_ACK_STS_CSR=0x%08x\n", pnum, regval);
916 near_ackid = (regval & RIO_PORT_N_ACK_INBOUND) >> 24;
917 pr_debug("RIO_EM: SP%d far_ackID=0x%02x far_linkstat=0x%02x" \
918 " near_ackID=0x%02x\n",
919 pnum, far_ackid, far_linkstat, near_ackid);
920
921 /*
922 * If required, synchronize ackIDs of near and
923 * far sides.
924 */
925 if ((far_ackid != ((regval & RIO_PORT_N_ACK_OUTSTAND) >> 8)) ||
926 (far_ackid != (regval & RIO_PORT_N_ACK_OUTBOUND))) {
927 /* Align near outstanding/outbound ackIDs with
928 * far inbound.
929 */
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800930 rio_write_config_32(rdev,
931 rdev->phys_efptr + RIO_PORT_N_ACK_STS_CSR(pnum),
Alexandre Bouninedd5648c2010-10-27 15:34:30 -0700932 (near_ackid << 24) |
933 (far_ackid << 8) | far_ackid);
934 /* Align far outstanding/outbound ackIDs with
935 * near inbound.
936 */
937 far_ackid++;
938 if (nextdev)
939 rio_write_config_32(nextdev,
940 nextdev->phys_efptr +
941 RIO_PORT_N_ACK_STS_CSR(RIO_GET_PORT_NUM(nextdev->swpinfo)),
942 (far_ackid << 24) |
943 (near_ackid << 8) | near_ackid);
944 else
945 pr_debug("RIO_EM: Invalid nextdev pointer (NULL)\n");
946 }
947rd_err:
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800948 rio_read_config_32(rdev,
Alexandre Bouninedd5648c2010-10-27 15:34:30 -0700949 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(pnum),
950 &err_status);
951 pr_debug("RIO_EM: SP%d_ERR_STS_CSR=0x%08x\n", pnum, err_status);
952 }
953
954 if ((err_status & RIO_PORT_N_ERR_STS_PW_INP_ES) && nextdev) {
955 pr_debug("RIO_EM: servicing Input Error-Stopped state\n");
956 rio_get_input_status(nextdev,
957 RIO_GET_PORT_NUM(nextdev->swpinfo), NULL);
958 udelay(50);
959
Alexandre Bouninea93192a2011-01-12 17:00:38 -0800960 rio_read_config_32(rdev,
Alexandre Bouninedd5648c2010-10-27 15:34:30 -0700961 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(pnum),
962 &err_status);
963 pr_debug("RIO_EM: SP%d_ERR_STS_CSR=0x%08x\n", pnum, err_status);
964 }
965
966 return (err_status & (RIO_PORT_N_ERR_STS_PW_OUT_ES |
967 RIO_PORT_N_ERR_STS_PW_INP_ES)) ? 1 : 0;
968}
969
970/**
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -0700971 * rio_inb_pwrite_handler - process inbound port-write message
972 * @pw_msg: pointer to inbound port-write message
973 *
974 * Processes an inbound port-write message. Returns 0 if the request
975 * has been satisfied.
976 */
977int rio_inb_pwrite_handler(union rio_pw_msg *pw_msg)
978{
979 struct rio_dev *rdev;
Alexandre Bouninedd5648c2010-10-27 15:34:30 -0700980 u32 err_status, em_perrdet, em_ltlerrdet;
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -0700981 int rc, portnum;
982
Alexandre Bouninee6536922011-01-12 17:00:40 -0800983 rdev = rio_get_comptag((pw_msg->em.comptag & RIO_CTAG_UDEVID), NULL);
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -0700984 if (rdev == NULL) {
Alexandre Bounine6429cd42010-10-27 15:34:32 -0700985 /* Device removed or enumeration error */
986 pr_debug("RIO: %s No matching device for CTag 0x%08x\n",
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -0700987 __func__, pw_msg->em.comptag);
988 return -EIO;
989 }
990
991 pr_debug("RIO: Port-Write message from %s\n", rio_name(rdev));
992
993#ifdef DEBUG_PW
994 {
995 u32 i;
996 for (i = 0; i < RIO_PW_MSG_SIZE/sizeof(u32);) {
Alexandre Bouninedd5648c2010-10-27 15:34:30 -0700997 pr_debug("0x%02x: %08x %08x %08x %08x\n",
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -0700998 i*4, pw_msg->raw[i], pw_msg->raw[i + 1],
999 pw_msg->raw[i + 2], pw_msg->raw[i + 3]);
1000 i += 4;
1001 }
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -07001002 }
1003#endif
1004
1005 /* Call an external service function (if such is registered
1006 * for this device). This may be the service for endpoints that send
1007 * device-specific port-write messages. End-point messages expected
1008 * to be handled completely by EP specific device driver.
1009 * For switches rc==0 signals that no standard processing required.
1010 */
1011 if (rdev->pwcback != NULL) {
1012 rc = rdev->pwcback(rdev, pw_msg, 0);
1013 if (rc == 0)
1014 return 0;
1015 }
1016
Alexandre Bounine6429cd42010-10-27 15:34:32 -07001017 portnum = pw_msg->em.is_port & 0xFF;
1018
1019 /* Check if device and route to it are functional:
1020 * Sometimes devices may send PW message(s) just before being
1021 * powered down (or link being lost).
1022 */
1023 if (rio_chk_dev_access(rdev)) {
1024 pr_debug("RIO: device access failed - get link partner\n");
1025 /* Scan route to the device and identify failed link.
1026 * This will replace device and port reported in PW message.
1027 * PW message should not be used after this point.
1028 */
1029 if (rio_chk_dev_route(rdev, &rdev, &portnum)) {
1030 pr_err("RIO: Route trace for %s failed\n",
1031 rio_name(rdev));
1032 return -EIO;
1033 }
1034 pw_msg = NULL;
1035 }
1036
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -07001037 /* For End-point devices processing stops here */
1038 if (!(rdev->pef & RIO_PEF_SWITCH))
1039 return 0;
1040
1041 if (rdev->phys_efptr == 0) {
1042 pr_err("RIO_PW: Bad switch initialization for %s\n",
1043 rio_name(rdev));
1044 return 0;
1045 }
1046
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -07001047 /*
1048 * Process the port-write notification from switch
1049 */
Alexandre Bounine2ec3ba62013-07-03 15:08:50 -07001050 if (rdev->rswitch->ops && rdev->rswitch->ops->em_handle)
1051 rdev->rswitch->ops->em_handle(rdev, portnum);
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -07001052
Alexandre Bouninea93192a2011-01-12 17:00:38 -08001053 rio_read_config_32(rdev,
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -07001054 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum),
1055 &err_status);
1056 pr_debug("RIO_PW: SP%d_ERR_STS_CSR=0x%08x\n", portnum, err_status);
1057
Alexandre Bouninedd5648c2010-10-27 15:34:30 -07001058 if (err_status & RIO_PORT_N_ERR_STS_PORT_OK) {
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -07001059
Alexandre Bouninedd5648c2010-10-27 15:34:30 -07001060 if (!(rdev->rswitch->port_ok & (1 << portnum))) {
1061 rdev->rswitch->port_ok |= (1 << portnum);
1062 rio_set_port_lockout(rdev, portnum, 0);
1063 /* Schedule Insertion Service */
1064 pr_debug("RIO_PW: Device Insertion on [%s]-P%d\n",
1065 rio_name(rdev), portnum);
1066 }
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -07001067
Alexandre Bouninedd5648c2010-10-27 15:34:30 -07001068 /* Clear error-stopped states (if reported).
1069 * Depending on the link partner state, two attempts
1070 * may be needed for successful recovery.
1071 */
1072 if (err_status & (RIO_PORT_N_ERR_STS_PW_OUT_ES |
1073 RIO_PORT_N_ERR_STS_PW_INP_ES)) {
1074 if (rio_clr_err_stopped(rdev, portnum, err_status))
1075 rio_clr_err_stopped(rdev, portnum, 0);
1076 }
1077 } else { /* if (err_status & RIO_PORT_N_ERR_STS_PORT_UNINIT) */
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -07001078
Alexandre Bouninedd5648c2010-10-27 15:34:30 -07001079 if (rdev->rswitch->port_ok & (1 << portnum)) {
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -07001080 rdev->rswitch->port_ok &= ~(1 << portnum);
1081 rio_set_port_lockout(rdev, portnum, 1);
1082
Alexandre Bouninea93192a2011-01-12 17:00:38 -08001083 rio_write_config_32(rdev,
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -07001084 rdev->phys_efptr +
1085 RIO_PORT_N_ACK_STS_CSR(portnum),
1086 RIO_PORT_N_ACK_CLEAR);
1087
1088 /* Schedule Extraction Service */
1089 pr_debug("RIO_PW: Device Extraction on [%s]-P%d\n",
1090 rio_name(rdev), portnum);
1091 }
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -07001092 }
1093
Alexandre Bouninea93192a2011-01-12 17:00:38 -08001094 rio_read_config_32(rdev,
Alexandre Bouninedd5648c2010-10-27 15:34:30 -07001095 rdev->em_efptr + RIO_EM_PN_ERR_DETECT(portnum), &em_perrdet);
1096 if (em_perrdet) {
1097 pr_debug("RIO_PW: RIO_EM_P%d_ERR_DETECT=0x%08x\n",
1098 portnum, em_perrdet);
1099 /* Clear EM Port N Error Detect CSR */
Alexandre Bouninea93192a2011-01-12 17:00:38 -08001100 rio_write_config_32(rdev,
Alexandre Bouninedd5648c2010-10-27 15:34:30 -07001101 rdev->em_efptr + RIO_EM_PN_ERR_DETECT(portnum), 0);
1102 }
1103
Alexandre Bouninea93192a2011-01-12 17:00:38 -08001104 rio_read_config_32(rdev,
Alexandre Bouninedd5648c2010-10-27 15:34:30 -07001105 rdev->em_efptr + RIO_EM_LTL_ERR_DETECT, &em_ltlerrdet);
1106 if (em_ltlerrdet) {
1107 pr_debug("RIO_PW: RIO_EM_LTL_ERR_DETECT=0x%08x\n",
1108 em_ltlerrdet);
1109 /* Clear EM L/T Layer Error Detect CSR */
Alexandre Bouninea93192a2011-01-12 17:00:38 -08001110 rio_write_config_32(rdev,
Alexandre Bouninedd5648c2010-10-27 15:34:30 -07001111 rdev->em_efptr + RIO_EM_LTL_ERR_DETECT, 0);
1112 }
1113
Alexandre Bounine388c45c2010-10-27 15:34:35 -07001114 /* Clear remaining error bits and Port-Write Pending bit */
Alexandre Bouninea93192a2011-01-12 17:00:38 -08001115 rio_write_config_32(rdev,
Alexandre Bouninedd5648c2010-10-27 15:34:30 -07001116 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum),
Alexandre Bounine388c45c2010-10-27 15:34:35 -07001117 err_status);
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -07001118
1119 return 0;
1120}
1121EXPORT_SYMBOL_GPL(rio_inb_pwrite_handler);
1122
1123/**
1124 * rio_mport_get_efb - get pointer to next extended features block
1125 * @port: Master port to issue transaction
1126 * @local: Indicate a local master port or remote device access
1127 * @destid: Destination ID of the device
1128 * @hopcount: Number of switch hops to the device
1129 * @from: Offset of current Extended Feature block header (if 0 starts
1130 * from ExtFeaturePtr)
1131 */
1132u32
1133rio_mport_get_efb(struct rio_mport *port, int local, u16 destid,
1134 u8 hopcount, u32 from)
1135{
1136 u32 reg_val;
1137
1138 if (from == 0) {
1139 if (local)
1140 rio_local_read_config_32(port, RIO_ASM_INFO_CAR,
1141 &reg_val);
1142 else
1143 rio_mport_read_config_32(port, destid, hopcount,
1144 RIO_ASM_INFO_CAR, &reg_val);
1145 return reg_val & RIO_EXT_FTR_PTR_MASK;
1146 } else {
1147 if (local)
1148 rio_local_read_config_32(port, from, &reg_val);
1149 else
1150 rio_mport_read_config_32(port, destid, hopcount,
1151 from, &reg_val);
1152 return RIO_GET_BLOCK_ID(reg_val);
1153 }
1154}
Alexandre Bouninea11650e2013-05-24 15:55:05 -07001155EXPORT_SYMBOL_GPL(rio_mport_get_efb);
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -07001156
1157/**
Matt Porter394b7012005-11-07 01:00:15 -08001158 * rio_mport_get_feature - query for devices' extended features
1159 * @port: Master port to issue transaction
1160 * @local: Indicate a local master port or remote device access
1161 * @destid: Destination ID of the device
1162 * @hopcount: Number of switch hops to the device
1163 * @ftr: Extended feature code
1164 *
1165 * Tell if a device supports a given RapidIO capability.
1166 * Returns the offset of the requested extended feature
1167 * block within the device's RIO configuration space or
1168 * 0 in case the device does not support it. Possible
1169 * values for @ftr:
1170 *
1171 * %RIO_EFB_PAR_EP_ID LP/LVDS EP Devices
1172 *
1173 * %RIO_EFB_PAR_EP_REC_ID LP/LVDS EP Recovery Devices
1174 *
1175 * %RIO_EFB_PAR_EP_FREE_ID LP/LVDS EP Free Devices
1176 *
1177 * %RIO_EFB_SER_EP_ID LP/Serial EP Devices
1178 *
1179 * %RIO_EFB_SER_EP_REC_ID LP/Serial EP Recovery Devices
1180 *
1181 * %RIO_EFB_SER_EP_FREE_ID LP/Serial EP Free Devices
1182 */
1183u32
1184rio_mport_get_feature(struct rio_mport * port, int local, u16 destid,
1185 u8 hopcount, int ftr)
1186{
1187 u32 asm_info, ext_ftr_ptr, ftr_header;
1188
1189 if (local)
1190 rio_local_read_config_32(port, RIO_ASM_INFO_CAR, &asm_info);
1191 else
1192 rio_mport_read_config_32(port, destid, hopcount,
1193 RIO_ASM_INFO_CAR, &asm_info);
1194
1195 ext_ftr_ptr = asm_info & RIO_EXT_FTR_PTR_MASK;
1196
1197 while (ext_ftr_ptr) {
1198 if (local)
1199 rio_local_read_config_32(port, ext_ftr_ptr,
1200 &ftr_header);
1201 else
1202 rio_mport_read_config_32(port, destid, hopcount,
1203 ext_ftr_ptr, &ftr_header);
1204 if (RIO_GET_BLOCK_ID(ftr_header) == ftr)
1205 return ext_ftr_ptr;
1206 if (!(ext_ftr_ptr = RIO_GET_BLOCK_PTR(ftr_header)))
1207 break;
1208 }
1209
1210 return 0;
1211}
Alexandre Bouninea11650e2013-05-24 15:55:05 -07001212EXPORT_SYMBOL_GPL(rio_mport_get_feature);
Matt Porter394b7012005-11-07 01:00:15 -08001213
1214/**
1215 * rio_get_asm - Begin or continue searching for a RIO device by vid/did/asm_vid/asm_did
1216 * @vid: RIO vid to match or %RIO_ANY_ID to match all vids
1217 * @did: RIO did to match or %RIO_ANY_ID to match all dids
1218 * @asm_vid: RIO asm_vid to match or %RIO_ANY_ID to match all asm_vids
1219 * @asm_did: RIO asm_did to match or %RIO_ANY_ID to match all asm_dids
1220 * @from: Previous RIO device found in search, or %NULL for new search
1221 *
1222 * Iterates through the list of known RIO devices. If a RIO device is
1223 * found with a matching @vid, @did, @asm_vid, @asm_did, the reference
1224 * count to the device is incrememted and a pointer to its device
1225 * structure is returned. Otherwise, %NULL is returned. A new search
1226 * is initiated by passing %NULL to the @from argument. Otherwise, if
1227 * @from is not %NULL, searches continue from next device on the global
1228 * list. The reference count for @from is always decremented if it is
1229 * not %NULL.
1230 */
1231struct rio_dev *rio_get_asm(u16 vid, u16 did,
1232 u16 asm_vid, u16 asm_did, struct rio_dev *from)
1233{
1234 struct list_head *n;
1235 struct rio_dev *rdev;
1236
1237 WARN_ON(in_interrupt());
1238 spin_lock(&rio_global_list_lock);
1239 n = from ? from->global_list.next : rio_devices.next;
1240
1241 while (n && (n != &rio_devices)) {
1242 rdev = rio_dev_g(n);
1243 if ((vid == RIO_ANY_ID || rdev->vid == vid) &&
1244 (did == RIO_ANY_ID || rdev->did == did) &&
1245 (asm_vid == RIO_ANY_ID || rdev->asm_vid == asm_vid) &&
1246 (asm_did == RIO_ANY_ID || rdev->asm_did == asm_did))
1247 goto exit;
1248 n = n->next;
1249 }
1250 rdev = NULL;
1251 exit:
1252 rio_dev_put(from);
1253 rdev = rio_dev_get(rdev);
1254 spin_unlock(&rio_global_list_lock);
1255 return rdev;
1256}
1257
1258/**
1259 * rio_get_device - Begin or continue searching for a RIO device by vid/did
1260 * @vid: RIO vid to match or %RIO_ANY_ID to match all vids
1261 * @did: RIO did to match or %RIO_ANY_ID to match all dids
1262 * @from: Previous RIO device found in search, or %NULL for new search
1263 *
1264 * Iterates through the list of known RIO devices. If a RIO device is
1265 * found with a matching @vid and @did, the reference count to the
1266 * device is incrememted and a pointer to its device structure is returned.
1267 * Otherwise, %NULL is returned. A new search is initiated by passing %NULL
1268 * to the @from argument. Otherwise, if @from is not %NULL, searches
1269 * continue from next device on the global list. The reference count for
1270 * @from is always decremented if it is not %NULL.
1271 */
1272struct rio_dev *rio_get_device(u16 vid, u16 did, struct rio_dev *from)
1273{
1274 return rio_get_asm(vid, did, RIO_ANY_ID, RIO_ANY_ID, from);
1275}
1276
Alexandre Bounine07590ff2010-05-26 14:43:57 -07001277/**
1278 * rio_std_route_add_entry - Add switch route table entry using standard
1279 * registers defined in RIO specification rev.1.3
1280 * @mport: Master port to issue transaction
1281 * @destid: Destination ID of the device
1282 * @hopcount: Number of switch hops to the device
1283 * @table: routing table ID (global or port-specific)
1284 * @route_destid: destID entry in the RT
1285 * @route_port: destination port for specified destID
1286 */
Alexandre Bounine2ec3ba62013-07-03 15:08:50 -07001287static int
1288rio_std_route_add_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
1289 u16 table, u16 route_destid, u8 route_port)
Alexandre Bounine07590ff2010-05-26 14:43:57 -07001290{
1291 if (table == RIO_GLOBAL_TABLE) {
1292 rio_mport_write_config_32(mport, destid, hopcount,
1293 RIO_STD_RTE_CONF_DESTID_SEL_CSR,
1294 (u32)route_destid);
1295 rio_mport_write_config_32(mport, destid, hopcount,
1296 RIO_STD_RTE_CONF_PORT_SEL_CSR,
1297 (u32)route_port);
1298 }
Alexandre Bouninee5cabeb2010-05-26 14:43:59 -07001299
Alexandre Bounine07590ff2010-05-26 14:43:57 -07001300 udelay(10);
1301 return 0;
1302}
1303
1304/**
1305 * rio_std_route_get_entry - Read switch route table entry (port number)
Uwe Kleine-König638c5942010-06-11 12:16:58 +02001306 * associated with specified destID using standard registers defined in RIO
Alexandre Bounine07590ff2010-05-26 14:43:57 -07001307 * specification rev.1.3
1308 * @mport: Master port to issue transaction
1309 * @destid: Destination ID of the device
1310 * @hopcount: Number of switch hops to the device
1311 * @table: routing table ID (global or port-specific)
1312 * @route_destid: destID entry in the RT
1313 * @route_port: returned destination port for specified destID
1314 */
Alexandre Bounine2ec3ba62013-07-03 15:08:50 -07001315static int
1316rio_std_route_get_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
1317 u16 table, u16 route_destid, u8 *route_port)
Alexandre Bounine07590ff2010-05-26 14:43:57 -07001318{
1319 u32 result;
1320
1321 if (table == RIO_GLOBAL_TABLE) {
1322 rio_mport_write_config_32(mport, destid, hopcount,
1323 RIO_STD_RTE_CONF_DESTID_SEL_CSR, route_destid);
1324 rio_mport_read_config_32(mport, destid, hopcount,
1325 RIO_STD_RTE_CONF_PORT_SEL_CSR, &result);
1326
1327 *route_port = (u8)result;
1328 }
1329
1330 return 0;
1331}
1332
1333/**
1334 * rio_std_route_clr_table - Clear swotch route table using standard registers
1335 * defined in RIO specification rev.1.3.
1336 * @mport: Master port to issue transaction
Alexandre Bounine07590ff2010-05-26 14:43:57 -07001337 * @destid: Destination ID of the device
1338 * @hopcount: Number of switch hops to the device
1339 * @table: routing table ID (global or port-specific)
1340 */
Alexandre Bounine2ec3ba62013-07-03 15:08:50 -07001341static int
1342rio_std_route_clr_table(struct rio_mport *mport, u16 destid, u8 hopcount,
1343 u16 table)
Alexandre Bounine07590ff2010-05-26 14:43:57 -07001344{
1345 u32 max_destid = 0xff;
1346 u32 i, pef, id_inc = 1, ext_cfg = 0;
1347 u32 port_sel = RIO_INVALID_ROUTE;
1348
1349 if (table == RIO_GLOBAL_TABLE) {
1350 rio_mport_read_config_32(mport, destid, hopcount,
1351 RIO_PEF_CAR, &pef);
1352
1353 if (mport->sys_size) {
1354 rio_mport_read_config_32(mport, destid, hopcount,
1355 RIO_SWITCH_RT_LIMIT,
1356 &max_destid);
1357 max_destid &= RIO_RT_MAX_DESTID;
1358 }
1359
1360 if (pef & RIO_PEF_EXT_RT) {
1361 ext_cfg = 0x80000000;
1362 id_inc = 4;
1363 port_sel = (RIO_INVALID_ROUTE << 24) |
1364 (RIO_INVALID_ROUTE << 16) |
1365 (RIO_INVALID_ROUTE << 8) |
1366 RIO_INVALID_ROUTE;
1367 }
1368
1369 for (i = 0; i <= max_destid;) {
1370 rio_mport_write_config_32(mport, destid, hopcount,
1371 RIO_STD_RTE_CONF_DESTID_SEL_CSR,
1372 ext_cfg | i);
1373 rio_mport_write_config_32(mport, destid, hopcount,
1374 RIO_STD_RTE_CONF_PORT_SEL_CSR,
1375 port_sel);
1376 i += id_inc;
1377 }
1378 }
1379
1380 udelay(10);
1381 return 0;
1382}
1383
Alexandre Bounine2ec3ba62013-07-03 15:08:50 -07001384/**
1385 * rio_lock_device - Acquires host device lock for specified device
1386 * @port: Master port to send transaction
1387 * @destid: Destination ID for device/switch
1388 * @hopcount: Hopcount to reach switch
1389 * @wait_ms: Max wait time in msec (0 = no timeout)
1390 *
1391 * Attepts to acquire host device lock for specified device
1392 * Returns 0 if device lock acquired or EINVAL if timeout expires.
1393 */
1394int rio_lock_device(struct rio_mport *port, u16 destid,
1395 u8 hopcount, int wait_ms)
1396{
1397 u32 result;
1398 int tcnt = 0;
1399
1400 /* Attempt to acquire device lock */
1401 rio_mport_write_config_32(port, destid, hopcount,
1402 RIO_HOST_DID_LOCK_CSR, port->host_deviceid);
1403 rio_mport_read_config_32(port, destid, hopcount,
1404 RIO_HOST_DID_LOCK_CSR, &result);
1405
1406 while (result != port->host_deviceid) {
1407 if (wait_ms != 0 && tcnt == wait_ms) {
1408 pr_debug("RIO: timeout when locking device %x:%x\n",
1409 destid, hopcount);
1410 return -EINVAL;
1411 }
1412
1413 /* Delay a bit */
1414 mdelay(1);
1415 tcnt++;
1416 /* Try to acquire device lock again */
1417 rio_mport_write_config_32(port, destid,
1418 hopcount,
1419 RIO_HOST_DID_LOCK_CSR,
1420 port->host_deviceid);
1421 rio_mport_read_config_32(port, destid,
1422 hopcount,
1423 RIO_HOST_DID_LOCK_CSR, &result);
1424 }
1425
1426 return 0;
1427}
1428EXPORT_SYMBOL_GPL(rio_lock_device);
1429
1430/**
1431 * rio_unlock_device - Releases host device lock for specified device
1432 * @port: Master port to send transaction
1433 * @destid: Destination ID for device/switch
1434 * @hopcount: Hopcount to reach switch
1435 *
1436 * Returns 0 if device lock released or EINVAL if fails.
1437 */
1438int rio_unlock_device(struct rio_mport *port, u16 destid, u8 hopcount)
1439{
1440 u32 result;
1441
1442 /* Release device lock */
1443 rio_mport_write_config_32(port, destid,
1444 hopcount,
1445 RIO_HOST_DID_LOCK_CSR,
1446 port->host_deviceid);
1447 rio_mport_read_config_32(port, destid, hopcount,
1448 RIO_HOST_DID_LOCK_CSR, &result);
1449 if ((result & 0xffff) != 0xffff) {
1450 pr_debug("RIO: badness when releasing device lock %x:%x\n",
1451 destid, hopcount);
1452 return -EINVAL;
1453 }
1454
1455 return 0;
1456}
1457EXPORT_SYMBOL_GPL(rio_unlock_device);
1458
1459/**
1460 * rio_route_add_entry- Add a route entry to a switch routing table
1461 * @rdev: RIO device
1462 * @table: Routing table ID
1463 * @route_destid: Destination ID to be routed
1464 * @route_port: Port number to be routed
1465 * @lock: apply a hardware lock on switch device flag (1=lock, 0=no_lock)
1466 *
1467 * If available calls the switch specific add_entry() method to add a route
1468 * entry into a switch routing table. Otherwise uses standard RT update method
1469 * as defined by RapidIO specification. A specific routing table can be selected
1470 * using the @table argument if a switch has per port routing tables or
1471 * the standard (or global) table may be used by passing
1472 * %RIO_GLOBAL_TABLE in @table.
1473 *
1474 * Returns %0 on success or %-EINVAL on failure.
1475 */
1476int rio_route_add_entry(struct rio_dev *rdev,
1477 u16 table, u16 route_destid, u8 route_port, int lock)
1478{
1479 int rc = -EINVAL;
1480 struct rio_switch_ops *ops = rdev->rswitch->ops;
1481
1482 if (lock) {
1483 rc = rio_lock_device(rdev->net->hport, rdev->destid,
1484 rdev->hopcount, 1000);
1485 if (rc)
1486 return rc;
1487 }
1488
1489 spin_lock(&rdev->rswitch->lock);
1490
1491 if (ops == NULL || ops->add_entry == NULL) {
1492 rc = rio_std_route_add_entry(rdev->net->hport, rdev->destid,
1493 rdev->hopcount, table,
1494 route_destid, route_port);
1495 } else if (try_module_get(ops->owner)) {
1496 rc = ops->add_entry(rdev->net->hport, rdev->destid,
1497 rdev->hopcount, table, route_destid,
1498 route_port);
1499 module_put(ops->owner);
1500 }
1501
1502 spin_unlock(&rdev->rswitch->lock);
1503
1504 if (lock)
1505 rio_unlock_device(rdev->net->hport, rdev->destid,
1506 rdev->hopcount);
1507
1508 return rc;
1509}
1510EXPORT_SYMBOL_GPL(rio_route_add_entry);
1511
1512/**
1513 * rio_route_get_entry- Read an entry from a switch routing table
1514 * @rdev: RIO device
1515 * @table: Routing table ID
1516 * @route_destid: Destination ID to be routed
1517 * @route_port: Pointer to read port number into
1518 * @lock: apply a hardware lock on switch device flag (1=lock, 0=no_lock)
1519 *
1520 * If available calls the switch specific get_entry() method to fetch a route
1521 * entry from a switch routing table. Otherwise uses standard RT read method
1522 * as defined by RapidIO specification. A specific routing table can be selected
1523 * using the @table argument if a switch has per port routing tables or
1524 * the standard (or global) table may be used by passing
1525 * %RIO_GLOBAL_TABLE in @table.
1526 *
1527 * Returns %0 on success or %-EINVAL on failure.
1528 */
1529int rio_route_get_entry(struct rio_dev *rdev, u16 table,
1530 u16 route_destid, u8 *route_port, int lock)
1531{
1532 int rc = -EINVAL;
1533 struct rio_switch_ops *ops = rdev->rswitch->ops;
1534
1535 if (lock) {
1536 rc = rio_lock_device(rdev->net->hport, rdev->destid,
1537 rdev->hopcount, 1000);
1538 if (rc)
1539 return rc;
1540 }
1541
1542 spin_lock(&rdev->rswitch->lock);
1543
1544 if (ops == NULL || ops->get_entry == NULL) {
1545 rc = rio_std_route_get_entry(rdev->net->hport, rdev->destid,
1546 rdev->hopcount, table,
1547 route_destid, route_port);
1548 } else if (try_module_get(ops->owner)) {
1549 rc = ops->get_entry(rdev->net->hport, rdev->destid,
1550 rdev->hopcount, table, route_destid,
1551 route_port);
1552 module_put(ops->owner);
1553 }
1554
1555 spin_unlock(&rdev->rswitch->lock);
1556
1557 if (lock)
1558 rio_unlock_device(rdev->net->hport, rdev->destid,
1559 rdev->hopcount);
1560 return rc;
1561}
1562EXPORT_SYMBOL_GPL(rio_route_get_entry);
1563
1564/**
1565 * rio_route_clr_table - Clear a switch routing table
1566 * @rdev: RIO device
1567 * @table: Routing table ID
1568 * @lock: apply a hardware lock on switch device flag (1=lock, 0=no_lock)
1569 *
1570 * If available calls the switch specific clr_table() method to clear a switch
1571 * routing table. Otherwise uses standard RT write method as defined by RapidIO
1572 * specification. A specific routing table can be selected using the @table
1573 * argument if a switch has per port routing tables or the standard (or global)
1574 * table may be used by passing %RIO_GLOBAL_TABLE in @table.
1575 *
1576 * Returns %0 on success or %-EINVAL on failure.
1577 */
1578int rio_route_clr_table(struct rio_dev *rdev, u16 table, int lock)
1579{
1580 int rc = -EINVAL;
1581 struct rio_switch_ops *ops = rdev->rswitch->ops;
1582
1583 if (lock) {
1584 rc = rio_lock_device(rdev->net->hport, rdev->destid,
1585 rdev->hopcount, 1000);
1586 if (rc)
1587 return rc;
1588 }
1589
1590 spin_lock(&rdev->rswitch->lock);
1591
1592 if (ops == NULL || ops->clr_table == NULL) {
1593 rc = rio_std_route_clr_table(rdev->net->hport, rdev->destid,
1594 rdev->hopcount, table);
1595 } else if (try_module_get(ops->owner)) {
1596 rc = ops->clr_table(rdev->net->hport, rdev->destid,
1597 rdev->hopcount, table);
1598
1599 module_put(ops->owner);
1600 }
1601
1602 spin_unlock(&rdev->rswitch->lock);
1603
1604 if (lock)
1605 rio_unlock_device(rdev->net->hport, rdev->destid,
1606 rdev->hopcount);
1607
1608 return rc;
1609}
1610EXPORT_SYMBOL_GPL(rio_route_clr_table);
1611
Alexandre Bouninee42d98e2012-05-31 16:26:38 -07001612#ifdef CONFIG_RAPIDIO_DMA_ENGINE
1613
1614static bool rio_chan_filter(struct dma_chan *chan, void *arg)
1615{
Alexandre Bounine4aff1ce2014-08-08 14:22:09 -07001616 struct rio_mport *mport = arg;
Alexandre Bouninee42d98e2012-05-31 16:26:38 -07001617
1618 /* Check that DMA device belongs to the right MPORT */
Alexandre Bounine4aff1ce2014-08-08 14:22:09 -07001619 return mport == container_of(chan->device, struct rio_mport, dma);
Alexandre Bouninee42d98e2012-05-31 16:26:38 -07001620}
1621
1622/**
Alexandre Bounine4aff1ce2014-08-08 14:22:09 -07001623 * rio_request_mport_dma - request RapidIO capable DMA channel associated
1624 * with specified local RapidIO mport device.
1625 * @mport: RIO mport to perform DMA data transfers
1626 *
1627 * Returns pointer to allocated DMA channel or NULL if failed.
1628 */
1629struct dma_chan *rio_request_mport_dma(struct rio_mport *mport)
1630{
1631 dma_cap_mask_t mask;
1632
1633 dma_cap_zero(mask);
1634 dma_cap_set(DMA_SLAVE, mask);
1635 return dma_request_channel(mask, rio_chan_filter, mport);
1636}
1637EXPORT_SYMBOL_GPL(rio_request_mport_dma);
1638
1639/**
Alexandre Bouninee42d98e2012-05-31 16:26:38 -07001640 * rio_request_dma - request RapidIO capable DMA channel that supports
1641 * specified target RapidIO device.
Alexandre Bounine4aff1ce2014-08-08 14:22:09 -07001642 * @rdev: RIO device associated with DMA transfer
Alexandre Bouninee42d98e2012-05-31 16:26:38 -07001643 *
1644 * Returns pointer to allocated DMA channel or NULL if failed.
1645 */
1646struct dma_chan *rio_request_dma(struct rio_dev *rdev)
1647{
Alexandre Bounine4aff1ce2014-08-08 14:22:09 -07001648 return rio_request_mport_dma(rdev->net->hport);
Alexandre Bouninee42d98e2012-05-31 16:26:38 -07001649}
1650EXPORT_SYMBOL_GPL(rio_request_dma);
1651
1652/**
1653 * rio_release_dma - release specified DMA channel
1654 * @dchan: DMA channel to release
1655 */
1656void rio_release_dma(struct dma_chan *dchan)
1657{
1658 dma_release_channel(dchan);
1659}
1660EXPORT_SYMBOL_GPL(rio_release_dma);
1661
1662/**
Alexandre Bounine4aff1ce2014-08-08 14:22:09 -07001663 * rio_dma_prep_xfer - RapidIO specific wrapper
1664 * for device_prep_slave_sg callback defined by DMAENGINE.
1665 * @dchan: DMA channel to configure
1666 * @destid: target RapidIO device destination ID
1667 * @data: RIO specific data descriptor
1668 * @direction: DMA data transfer direction (TO or FROM the device)
1669 * @flags: dmaengine defined flags
1670 *
1671 * Initializes RapidIO capable DMA channel for the specified data transfer.
1672 * Uses DMA channel private extension to pass information related to remote
1673 * target RIO device.
1674 * Returns pointer to DMA transaction descriptor or NULL if failed.
1675 */
1676struct dma_async_tx_descriptor *rio_dma_prep_xfer(struct dma_chan *dchan,
1677 u16 destid, struct rio_dma_data *data,
1678 enum dma_transfer_direction direction, unsigned long flags)
1679{
1680 struct rio_dma_ext rio_ext;
1681
1682 if (dchan->device->device_prep_slave_sg == NULL) {
1683 pr_err("%s: prep_rio_sg == NULL\n", __func__);
1684 return NULL;
1685 }
1686
1687 rio_ext.destid = destid;
1688 rio_ext.rio_addr_u = data->rio_addr_u;
1689 rio_ext.rio_addr = data->rio_addr;
1690 rio_ext.wr_type = data->wr_type;
1691
1692 return dmaengine_prep_rio_sg(dchan, data->sg, data->sg_len,
1693 direction, flags, &rio_ext);
1694}
1695EXPORT_SYMBOL_GPL(rio_dma_prep_xfer);
1696
1697/**
Alexandre Bouninee42d98e2012-05-31 16:26:38 -07001698 * rio_dma_prep_slave_sg - RapidIO specific wrapper
1699 * for device_prep_slave_sg callback defined by DMAENGINE.
1700 * @rdev: RIO device control structure
1701 * @dchan: DMA channel to configure
1702 * @data: RIO specific data descriptor
1703 * @direction: DMA data transfer direction (TO or FROM the device)
1704 * @flags: dmaengine defined flags
1705 *
1706 * Initializes RapidIO capable DMA channel for the specified data transfer.
1707 * Uses DMA channel private extension to pass information related to remote
1708 * target RIO device.
1709 * Returns pointer to DMA transaction descriptor or NULL if failed.
1710 */
1711struct dma_async_tx_descriptor *rio_dma_prep_slave_sg(struct rio_dev *rdev,
1712 struct dma_chan *dchan, struct rio_dma_data *data,
1713 enum dma_transfer_direction direction, unsigned long flags)
1714{
Alexandre Bounine4aff1ce2014-08-08 14:22:09 -07001715 return rio_dma_prep_xfer(dchan, rdev->destid, data, direction, flags);
Alexandre Bouninee42d98e2012-05-31 16:26:38 -07001716}
1717EXPORT_SYMBOL_GPL(rio_dma_prep_slave_sg);
1718
1719#endif /* CONFIG_RAPIDIO_DMA_ENGINE */
1720
Alexandre Bouninea11650e2013-05-24 15:55:05 -07001721/**
Alexandre Bouninebc8fcfe2013-05-24 15:55:06 -07001722 * rio_find_mport - find RIO mport by its ID
1723 * @mport_id: number (ID) of mport device
1724 *
1725 * Given a RIO mport number, the desired mport is located
1726 * in the global list of mports. If the mport is found, a pointer to its
1727 * data structure is returned. If no mport is found, %NULL is returned.
1728 */
1729struct rio_mport *rio_find_mport(int mport_id)
1730{
1731 struct rio_mport *port;
1732
1733 mutex_lock(&rio_mport_list_lock);
1734 list_for_each_entry(port, &rio_mports, node) {
1735 if (port->id == mport_id)
1736 goto found;
1737 }
1738 port = NULL;
1739found:
1740 mutex_unlock(&rio_mport_list_lock);
1741
1742 return port;
1743}
1744
1745/**
Alexandre Bouninea11650e2013-05-24 15:55:05 -07001746 * rio_register_scan - enumeration/discovery method registration interface
1747 * @mport_id: mport device ID for which fabric scan routine has to be set
1748 * (RIO_MPORT_ANY = set for all available mports)
Alexandre Bounine9edbc30b2013-07-03 15:08:53 -07001749 * @scan_ops: enumeration/discovery operations structure
Alexandre Bouninea11650e2013-05-24 15:55:05 -07001750 *
Alexandre Bounine9edbc30b2013-07-03 15:08:53 -07001751 * Registers enumeration/discovery operations with RapidIO subsystem and
1752 * attaches it to the specified mport device (or all available mports
1753 * if RIO_MPORT_ANY is specified).
1754 *
Alexandre Bouninea11650e2013-05-24 15:55:05 -07001755 * Returns error if the mport already has an enumerator attached to it.
Alexandre Bounine9edbc30b2013-07-03 15:08:53 -07001756 * In case of RIO_MPORT_ANY skips mports with valid scan routines (no error).
Alexandre Bouninea11650e2013-05-24 15:55:05 -07001757 */
1758int rio_register_scan(int mport_id, struct rio_scan *scan_ops)
1759{
1760 struct rio_mport *port;
Alexandre Bounine9edbc30b2013-07-03 15:08:53 -07001761 struct rio_scan_node *scan;
1762 int rc = 0;
1763
1764 pr_debug("RIO: %s for mport_id=%d\n", __func__, mport_id);
1765
1766 if ((mport_id != RIO_MPORT_ANY && mport_id >= RIO_MAX_MPORTS) ||
1767 !scan_ops)
1768 return -EINVAL;
Alexandre Bouninea11650e2013-05-24 15:55:05 -07001769
1770 mutex_lock(&rio_mport_list_lock);
Alexandre Bouninea11650e2013-05-24 15:55:05 -07001771
Alexandre Bounine9edbc30b2013-07-03 15:08:53 -07001772 /*
1773 * Check if there is another enumerator already registered for
1774 * the same mport ID (including RIO_MPORT_ANY). Multiple enumerators
1775 * for the same mport ID are not supported.
1776 */
1777 list_for_each_entry(scan, &rio_scans, node) {
1778 if (scan->mport_id == mport_id) {
1779 rc = -EBUSY;
1780 goto err_out;
Alexandre Bouninea11650e2013-05-24 15:55:05 -07001781 }
1782 }
Alexandre Bounine9edbc30b2013-07-03 15:08:53 -07001783
1784 /*
1785 * Allocate and initialize new scan registration node.
1786 */
1787 scan = kzalloc(sizeof(*scan), GFP_KERNEL);
1788 if (!scan) {
1789 rc = -ENOMEM;
1790 goto err_out;
1791 }
1792
1793 scan->mport_id = mport_id;
1794 scan->ops = scan_ops;
1795
1796 /*
1797 * Traverse the list of registered mports to attach this new scan.
1798 *
1799 * The new scan with matching mport ID overrides any previously attached
1800 * scan assuming that old scan (if any) is the default one (based on the
1801 * enumerator registration check above).
1802 * If the new scan is the global one, it will be attached only to mports
1803 * that do not have their own individual operations already attached.
1804 */
1805 list_for_each_entry(port, &rio_mports, node) {
1806 if (port->id == mport_id) {
1807 port->nscan = scan_ops;
1808 break;
1809 } else if (mport_id == RIO_MPORT_ANY && !port->nscan)
1810 port->nscan = scan_ops;
1811 }
1812
1813 list_add_tail(&scan->node, &rio_scans);
1814
1815err_out:
Alexandre Bouninea11650e2013-05-24 15:55:05 -07001816 mutex_unlock(&rio_mport_list_lock);
1817
1818 return rc;
1819}
1820EXPORT_SYMBOL_GPL(rio_register_scan);
1821
1822/**
1823 * rio_unregister_scan - removes enumeration/discovery method from mport
1824 * @mport_id: mport device ID for which fabric scan routine has to be
Alexandre Bounine9edbc30b2013-07-03 15:08:53 -07001825 * unregistered (RIO_MPORT_ANY = apply to all mports that use
1826 * the specified scan_ops)
1827 * @scan_ops: enumeration/discovery operations structure
Alexandre Bouninea11650e2013-05-24 15:55:05 -07001828 *
1829 * Removes enumeration or discovery method assigned to the specified mport
Alexandre Bounine9edbc30b2013-07-03 15:08:53 -07001830 * device. If RIO_MPORT_ANY is specified, removes the specified operations from
1831 * all mports that have them attached.
Alexandre Bouninea11650e2013-05-24 15:55:05 -07001832 */
Alexandre Bounine9edbc30b2013-07-03 15:08:53 -07001833int rio_unregister_scan(int mport_id, struct rio_scan *scan_ops)
Alexandre Bouninea11650e2013-05-24 15:55:05 -07001834{
1835 struct rio_mport *port;
Alexandre Bounine9edbc30b2013-07-03 15:08:53 -07001836 struct rio_scan_node *scan;
1837
1838 pr_debug("RIO: %s for mport_id=%d\n", __func__, mport_id);
1839
1840 if (mport_id != RIO_MPORT_ANY && mport_id >= RIO_MAX_MPORTS)
1841 return -EINVAL;
Alexandre Bouninea11650e2013-05-24 15:55:05 -07001842
1843 mutex_lock(&rio_mport_list_lock);
Alexandre Bounine9edbc30b2013-07-03 15:08:53 -07001844
1845 list_for_each_entry(port, &rio_mports, node)
1846 if (port->id == mport_id ||
1847 (mport_id == RIO_MPORT_ANY && port->nscan == scan_ops))
1848 port->nscan = NULL;
1849
Dan Carpenterf93f3c42013-07-31 13:53:34 -07001850 list_for_each_entry(scan, &rio_scans, node) {
Alexandre Bounine9edbc30b2013-07-03 15:08:53 -07001851 if (scan->mport_id == mport_id) {
1852 list_del(&scan->node);
1853 kfree(scan);
Dan Carpenterf93f3c42013-07-31 13:53:34 -07001854 break;
Alexandre Bouninea11650e2013-05-24 15:55:05 -07001855 }
Dan Carpenterf93f3c42013-07-31 13:53:34 -07001856 }
Alexandre Bounine9edbc30b2013-07-03 15:08:53 -07001857
Alexandre Bouninea11650e2013-05-24 15:55:05 -07001858 mutex_unlock(&rio_mport_list_lock);
1859
1860 return 0;
1861}
1862EXPORT_SYMBOL_GPL(rio_unregister_scan);
1863
Alexandre Bounine9edbc30b2013-07-03 15:08:53 -07001864/**
1865 * rio_mport_scan - execute enumeration/discovery on the specified mport
1866 * @mport_id: number (ID) of mport device
1867 */
1868int rio_mport_scan(int mport_id)
1869{
1870 struct rio_mport *port = NULL;
1871 int rc;
1872
1873 mutex_lock(&rio_mport_list_lock);
1874 list_for_each_entry(port, &rio_mports, node) {
1875 if (port->id == mport_id)
1876 goto found;
1877 }
1878 mutex_unlock(&rio_mport_list_lock);
1879 return -ENODEV;
1880found:
1881 if (!port->nscan) {
1882 mutex_unlock(&rio_mport_list_lock);
1883 return -EINVAL;
1884 }
1885
1886 if (!try_module_get(port->nscan->owner)) {
1887 mutex_unlock(&rio_mport_list_lock);
1888 return -ENODEV;
1889 }
1890
1891 mutex_unlock(&rio_mport_list_lock);
1892
1893 if (port->host_deviceid >= 0)
1894 rc = port->nscan->enumerate(port, 0);
1895 else
1896 rc = port->nscan->discover(port, RIO_SCAN_ENUM_NO_WAIT);
1897
1898 module_put(port->nscan->owner);
1899 return rc;
1900}
1901
Matt Porter394b7012005-11-07 01:00:15 -08001902static void rio_fixup_device(struct rio_dev *dev)
1903{
1904}
1905
Bill Pemberton305c8912012-11-19 13:23:25 -05001906static int rio_init(void)
Matt Porter394b7012005-11-07 01:00:15 -08001907{
1908 struct rio_dev *dev = NULL;
1909
1910 while ((dev = rio_get_device(RIO_ANY_ID, RIO_ANY_ID, dev)) != NULL) {
1911 rio_fixup_device(dev);
1912 }
1913 return 0;
1914}
1915
Alexandre Bounine005842e2012-10-04 17:16:08 -07001916static struct workqueue_struct *rio_wq;
1917
1918struct rio_disc_work {
1919 struct work_struct work;
1920 struct rio_mport *mport;
1921};
1922
Bill Pemberton305c8912012-11-19 13:23:25 -05001923static void disc_work_handler(struct work_struct *_work)
Alexandre Bounine005842e2012-10-04 17:16:08 -07001924{
1925 struct rio_disc_work *work;
1926
1927 work = container_of(_work, struct rio_disc_work, work);
1928 pr_debug("RIO: discovery work for mport %d %s\n",
1929 work->mport->id, work->mport->name);
Alexandre Bounine9edbc30b2013-07-03 15:08:53 -07001930 if (try_module_get(work->mport->nscan->owner)) {
1931 work->mport->nscan->discover(work->mport, 0);
1932 module_put(work->mport->nscan->owner);
1933 }
Alexandre Bounine005842e2012-10-04 17:16:08 -07001934}
1935
Bill Pemberton305c8912012-11-19 13:23:25 -05001936int rio_init_mports(void)
Matt Porter394b7012005-11-07 01:00:15 -08001937{
Matt Porter394b7012005-11-07 01:00:15 -08001938 struct rio_mport *port;
Alexandre Bounine005842e2012-10-04 17:16:08 -07001939 struct rio_disc_work *work;
Alexandre Bounine25747402012-10-10 15:53:59 -07001940 int n = 0;
Matt Porter394b7012005-11-07 01:00:15 -08001941
Alexandre Bounine25747402012-10-10 15:53:59 -07001942 if (!next_portid)
1943 return -ENODEV;
1944
1945 /*
1946 * First, run enumerations and check if we need to perform discovery
1947 * on any of the registered mports.
1948 */
Alexandre Bouninea11650e2013-05-24 15:55:05 -07001949 mutex_lock(&rio_mport_list_lock);
Matt Porter394b7012005-11-07 01:00:15 -08001950 list_for_each_entry(port, &rio_mports, node) {
Alexandre Bouninea11650e2013-05-24 15:55:05 -07001951 if (port->host_deviceid >= 0) {
Alexandre Bounine9edbc30b2013-07-03 15:08:53 -07001952 if (port->nscan && try_module_get(port->nscan->owner)) {
Alexandre Bouninebc8fcfe2013-05-24 15:55:06 -07001953 port->nscan->enumerate(port, 0);
Alexandre Bounine9edbc30b2013-07-03 15:08:53 -07001954 module_put(port->nscan->owner);
1955 }
Alexandre Bouninea11650e2013-05-24 15:55:05 -07001956 } else
Alexandre Bounine25747402012-10-10 15:53:59 -07001957 n++;
1958 }
Alexandre Bouninea11650e2013-05-24 15:55:05 -07001959 mutex_unlock(&rio_mport_list_lock);
Alexandre Bounine005842e2012-10-04 17:16:08 -07001960
Alexandre Bounine25747402012-10-10 15:53:59 -07001961 if (!n)
1962 goto no_disc;
Alexandre Bounine005842e2012-10-04 17:16:08 -07001963
Alexandre Bounine25747402012-10-10 15:53:59 -07001964 /*
1965 * If we have mports that require discovery schedule a discovery work
1966 * for each of them. If the code below fails to allocate needed
1967 * resources, exit without error to keep results of enumeration
1968 * process (if any).
Alexandre Bounine9edbc30b2013-07-03 15:08:53 -07001969 * TODO: Implement restart of discovery process for all or
Alexandre Bounine25747402012-10-10 15:53:59 -07001970 * individual discovering mports.
1971 */
1972 rio_wq = alloc_workqueue("riodisc", 0, 0);
1973 if (!rio_wq) {
1974 pr_err("RIO: unable allocate rio_wq\n");
1975 goto no_disc;
1976 }
1977
1978 work = kcalloc(n, sizeof *work, GFP_KERNEL);
1979 if (!work) {
1980 pr_err("RIO: no memory for work struct\n");
1981 destroy_workqueue(rio_wq);
1982 goto no_disc;
1983 }
1984
1985 n = 0;
Alexandre Bouninea11650e2013-05-24 15:55:05 -07001986 mutex_lock(&rio_mport_list_lock);
Alexandre Bounine25747402012-10-10 15:53:59 -07001987 list_for_each_entry(port, &rio_mports, node) {
Alexandre Bouninea11650e2013-05-24 15:55:05 -07001988 if (port->host_deviceid < 0 && port->nscan) {
Alexandre Bounine25747402012-10-10 15:53:59 -07001989 work[n].mport = port;
1990 INIT_WORK(&work[n].work, disc_work_handler);
1991 queue_work(rio_wq, &work[n].work);
1992 n++;
Alexandre Bounine005842e2012-10-04 17:16:08 -07001993 }
1994 }
1995
Alexandre Bounine25747402012-10-10 15:53:59 -07001996 flush_workqueue(rio_wq);
Alexandre Bounine9edbc30b2013-07-03 15:08:53 -07001997 mutex_unlock(&rio_mport_list_lock);
Alexandre Bounine25747402012-10-10 15:53:59 -07001998 pr_debug("RIO: destroy discovery workqueue\n");
1999 destroy_workqueue(rio_wq);
2000 kfree(work);
Matt Porter394b7012005-11-07 01:00:15 -08002001
Alexandre Bounine25747402012-10-10 15:53:59 -07002002no_disc:
Alexandre Bounine2f809982011-03-23 16:43:04 -07002003 rio_init();
2004
Alexandre Bouninec1256eb2011-03-23 16:43:06 -07002005 return 0;
Matt Porter394b7012005-11-07 01:00:15 -08002006}
2007
Alexandre Bounine569fccb2011-03-23 16:43:05 -07002008static int rio_get_hdid(int index)
2009{
Alexandre Bouninefdf90ab2013-07-03 15:08:56 -07002010 if (ids_num == 0 || ids_num <= index || index >= RIO_MAX_MPORTS)
Alexandre Bounine569fccb2011-03-23 16:43:05 -07002011 return -1;
2012
Alexandre Bouninefdf90ab2013-07-03 15:08:56 -07002013 return hdid[index];
Alexandre Bounine569fccb2011-03-23 16:43:05 -07002014}
2015
Alexandre Bounineb77a2032016-03-22 14:26:20 -07002016int rio_mport_initialize(struct rio_mport *mport)
2017{
2018 if (next_portid >= RIO_MAX_MPORTS) {
2019 pr_err("RIO: reached specified max number of mports\n");
2020 return -ENODEV;
2021 }
2022
2023 atomic_set(&mport->state, RIO_DEVICE_INITIALIZING);
2024 mport->id = next_portid++;
2025 mport->host_deviceid = rio_get_hdid(mport->id);
2026 mport->nscan = NULL;
2027
2028 return 0;
2029}
2030EXPORT_SYMBOL_GPL(rio_mport_initialize);
2031
Alexandre Bounine59f99962011-04-14 15:22:14 -07002032int rio_register_mport(struct rio_mport *port)
Matt Porter394b7012005-11-07 01:00:15 -08002033{
Alexandre Bounine9edbc30b2013-07-03 15:08:53 -07002034 struct rio_scan_node *scan = NULL;
Alexandre Bounine2aaf3082014-04-07 15:38:56 -07002035 int res = 0;
Alexandre Bounine9edbc30b2013-07-03 15:08:53 -07002036
Alexandre Bouninea11650e2013-05-24 15:55:05 -07002037 mutex_lock(&rio_mport_list_lock);
Alexandre Bounine9edbc30b2013-07-03 15:08:53 -07002038
2039 /*
2040 * Check if there are any registered enumeration/discovery operations
2041 * that have to be attached to the added mport.
2042 */
2043 list_for_each_entry(scan, &rio_scans, node) {
2044 if (port->id == scan->mport_id ||
2045 scan->mport_id == RIO_MPORT_ANY) {
2046 port->nscan = scan->ops;
2047 if (port->id == scan->mport_id)
2048 break;
2049 }
2050 }
Alexandre Bounineb77a2032016-03-22 14:26:20 -07002051
2052 list_add_tail(&port->node, &rio_mports);
Alexandre Bouninea11650e2013-05-24 15:55:05 -07002053 mutex_unlock(&rio_mport_list_lock);
Alexandre Bounine9edbc30b2013-07-03 15:08:53 -07002054
Alexandre Bounineb77a2032016-03-22 14:26:20 -07002055 dev_set_name(&port->dev, "rapidio%d", port->id);
2056 port->dev.class = &rio_mport_class;
2057 atomic_set(&port->state, RIO_DEVICE_RUNNING);
2058
2059 res = device_register(&port->dev);
2060 if (res)
2061 dev_err(&port->dev, "RIO: mport%d registration failed ERR=%d\n",
2062 port->id, res);
2063 else
2064 dev_dbg(&port->dev, "RIO: registered mport%d\n", port->id);
2065
2066 return res;
Matt Porter394b7012005-11-07 01:00:15 -08002067}
Alexandre Bounine94d9bd42013-07-03 15:08:55 -07002068EXPORT_SYMBOL_GPL(rio_register_mport);
Matt Porter394b7012005-11-07 01:00:15 -08002069
Alexandre Bounineb77a2032016-03-22 14:26:20 -07002070static int rio_mport_cleanup_callback(struct device *dev, void *data)
2071{
2072 struct rio_dev *rdev = to_rio_dev(dev);
2073
2074 if (dev->bus == &rio_bus_type)
2075 rio_del_device(rdev, RIO_DEVICE_SHUTDOWN);
2076 return 0;
2077}
2078
2079static int rio_net_remove_children(struct rio_net *net)
2080{
2081 /*
2082 * Unregister all RapidIO devices residing on this net (this will
2083 * invoke notification of registered subsystem interfaces as well).
2084 */
2085 device_for_each_child(&net->dev, NULL, rio_mport_cleanup_callback);
2086 return 0;
2087}
2088
2089int rio_unregister_mport(struct rio_mport *port)
2090{
2091 pr_debug("RIO: %s %s id=%d\n", __func__, port->name, port->id);
2092
2093 /* Transition mport to the SHUTDOWN state */
2094 if (atomic_cmpxchg(&port->state,
2095 RIO_DEVICE_RUNNING,
2096 RIO_DEVICE_SHUTDOWN) != RIO_DEVICE_RUNNING) {
2097 pr_err("RIO: %s unexpected state transition for mport %s\n",
2098 __func__, port->name);
2099 }
2100
2101 if (port->net && port->net->hport == port) {
2102 rio_net_remove_children(port->net);
2103 rio_free_net(port->net);
2104 }
2105
2106 /*
2107 * Unregister all RapidIO devices attached to this mport (this will
2108 * invoke notification of registered subsystem interfaces as well).
2109 */
2110 mutex_lock(&rio_mport_list_lock);
2111 list_del(&port->node);
2112 mutex_unlock(&rio_mport_list_lock);
2113 device_unregister(&port->dev);
2114
2115 return 0;
2116}
2117EXPORT_SYMBOL_GPL(rio_unregister_mport);
2118
Matt Porter394b7012005-11-07 01:00:15 -08002119EXPORT_SYMBOL_GPL(rio_local_get_device_id);
2120EXPORT_SYMBOL_GPL(rio_get_device);
2121EXPORT_SYMBOL_GPL(rio_get_asm);
2122EXPORT_SYMBOL_GPL(rio_request_inb_dbell);
2123EXPORT_SYMBOL_GPL(rio_release_inb_dbell);
2124EXPORT_SYMBOL_GPL(rio_request_outb_dbell);
2125EXPORT_SYMBOL_GPL(rio_release_outb_dbell);
2126EXPORT_SYMBOL_GPL(rio_request_inb_mbox);
2127EXPORT_SYMBOL_GPL(rio_release_inb_mbox);
2128EXPORT_SYMBOL_GPL(rio_request_outb_mbox);
2129EXPORT_SYMBOL_GPL(rio_release_outb_mbox);
Alexandre Bouninea11650e2013-05-24 15:55:05 -07002130EXPORT_SYMBOL_GPL(rio_init_mports);