2 * RapidIO interconnect services
3 * (RapidIO Interconnect Specification, http://www.rapidio.org)
5 * Copyright 2005 MontaVista Software, Inc.
6 * Matt Porter <mporter@kernel.crashing.org>
8 * Copyright 2009 Integrated Device Technology, Inc.
9 * Alex Bounine <alexandre.bounine@idt.com>
11 * 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.
17 #include <linux/types.h>
18 #include <linux/kernel.h>
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>
28 #include <linux/slab.h>
29 #include <linux/interrupt.h>
33 static LIST_HEAD(rio_devices
);
34 static DEFINE_SPINLOCK(rio_global_list_lock
);
36 static LIST_HEAD(rio_mports
);
37 static DEFINE_MUTEX(rio_mport_list_lock
);
38 static unsigned char next_portid
;
39 static DEFINE_SPINLOCK(rio_mmap_lock
);
42 * rio_local_get_device_id - Get the base/extended device id for a port
43 * @port: RIO master port from which to get the deviceid
45 * Reads the base/extended device id from the local device
46 * implementing the master port. Returns the 8/16-bit device
49 u16
rio_local_get_device_id(struct rio_mport
*port
)
53 rio_local_read_config_32(port
, RIO_DID_CSR
, &result
);
55 return (RIO_GET_DID(port
->sys_size
, result
));
59 * rio_add_device- Adds a RIO device to the device model
62 * Adds the RIO device to the global device list and adds the RIO
63 * device to the RIO device list. Creates the generic sysfs nodes
66 int rio_add_device(struct rio_dev
*rdev
)
70 err
= device_add(&rdev
->dev
);
74 spin_lock(&rio_global_list_lock
);
75 list_add_tail(&rdev
->global_list
, &rio_devices
);
76 spin_unlock(&rio_global_list_lock
);
78 rio_create_sysfs_dev_files(rdev
);
82 EXPORT_SYMBOL_GPL(rio_add_device
);
85 * rio_request_inb_mbox - request inbound mailbox service
86 * @mport: RIO master port from which to allocate the mailbox resource
87 * @dev_id: Device specific pointer to pass on event
88 * @mbox: Mailbox number to claim
89 * @entries: Number of entries in inbound mailbox queue
90 * @minb: Callback to execute when inbound message is received
92 * Requests ownership of an inbound mailbox resource and binds
93 * a callback function to the resource. Returns %0 on success.
95 int rio_request_inb_mbox(struct rio_mport
*mport
,
99 void (*minb
) (struct rio_mport
* mport
, void *dev_id
, int mbox
,
103 struct resource
*res
;
105 if (mport
->ops
->open_inb_mbox
== NULL
)
108 res
= kmalloc(sizeof(struct resource
), GFP_KERNEL
);
111 rio_init_mbox_res(res
, mbox
, mbox
);
113 /* Make sure this mailbox isn't in use */
115 request_resource(&mport
->riores
[RIO_INB_MBOX_RESOURCE
],
121 mport
->inb_msg
[mbox
].res
= res
;
123 /* Hook the inbound message callback */
124 mport
->inb_msg
[mbox
].mcback
= minb
;
126 rc
= mport
->ops
->open_inb_mbox(mport
, dev_id
, mbox
, entries
);
135 * rio_release_inb_mbox - release inbound mailbox message service
136 * @mport: RIO master port from which to release the mailbox resource
137 * @mbox: Mailbox number to release
139 * Releases ownership of an inbound mailbox resource. Returns 0
140 * if the request has been satisfied.
142 int rio_release_inb_mbox(struct rio_mport
*mport
, int mbox
)
144 if (mport
->ops
->close_inb_mbox
) {
145 mport
->ops
->close_inb_mbox(mport
, mbox
);
147 /* Release the mailbox resource */
148 return release_resource(mport
->inb_msg
[mbox
].res
);
154 * rio_request_outb_mbox - request outbound mailbox service
155 * @mport: RIO master port from which to allocate the mailbox resource
156 * @dev_id: Device specific pointer to pass on event
157 * @mbox: Mailbox number to claim
158 * @entries: Number of entries in outbound mailbox queue
159 * @moutb: Callback to execute when outbound message is sent
161 * Requests ownership of an outbound mailbox resource and binds
162 * a callback function to the resource. Returns 0 on success.
164 int rio_request_outb_mbox(struct rio_mport
*mport
,
168 void (*moutb
) (struct rio_mport
* mport
, void *dev_id
, int mbox
, int slot
))
171 struct resource
*res
;
173 if (mport
->ops
->open_outb_mbox
== NULL
)
176 res
= kmalloc(sizeof(struct resource
), GFP_KERNEL
);
179 rio_init_mbox_res(res
, mbox
, mbox
);
181 /* Make sure this outbound mailbox isn't in use */
183 request_resource(&mport
->riores
[RIO_OUTB_MBOX_RESOURCE
],
189 mport
->outb_msg
[mbox
].res
= res
;
191 /* Hook the inbound message callback */
192 mport
->outb_msg
[mbox
].mcback
= moutb
;
194 rc
= mport
->ops
->open_outb_mbox(mport
, dev_id
, mbox
, entries
);
203 * rio_release_outb_mbox - release outbound mailbox message service
204 * @mport: RIO master port from which to release the mailbox resource
205 * @mbox: Mailbox number to release
207 * Releases ownership of an inbound mailbox resource. Returns 0
208 * if the request has been satisfied.
210 int rio_release_outb_mbox(struct rio_mport
*mport
, int mbox
)
212 if (mport
->ops
->close_outb_mbox
) {
213 mport
->ops
->close_outb_mbox(mport
, mbox
);
215 /* Release the mailbox resource */
216 return release_resource(mport
->outb_msg
[mbox
].res
);
222 * rio_setup_inb_dbell - bind inbound doorbell callback
223 * @mport: RIO master port to bind the doorbell callback
224 * @dev_id: Device specific pointer to pass on event
225 * @res: Doorbell message resource
226 * @dinb: Callback to execute when doorbell is received
228 * Adds a doorbell resource/callback pair into a port's
229 * doorbell event list. Returns 0 if the request has been
233 rio_setup_inb_dbell(struct rio_mport
*mport
, void *dev_id
, struct resource
*res
,
234 void (*dinb
) (struct rio_mport
* mport
, void *dev_id
, u16 src
, u16 dst
,
238 struct rio_dbell
*dbell
;
240 if (!(dbell
= kmalloc(sizeof(struct rio_dbell
), GFP_KERNEL
))) {
247 dbell
->dev_id
= dev_id
;
249 list_add_tail(&dbell
->node
, &mport
->dbells
);
256 * rio_request_inb_dbell - request inbound doorbell message service
257 * @mport: RIO master port from which to allocate the doorbell resource
258 * @dev_id: Device specific pointer to pass on event
259 * @start: Doorbell info range start
260 * @end: Doorbell info range end
261 * @dinb: Callback to execute when doorbell is received
263 * Requests ownership of an inbound doorbell resource and binds
264 * a callback function to the resource. Returns 0 if the request
265 * has been satisfied.
267 int rio_request_inb_dbell(struct rio_mport
*mport
,
271 void (*dinb
) (struct rio_mport
* mport
, void *dev_id
, u16 src
,
276 struct resource
*res
= kmalloc(sizeof(struct resource
), GFP_KERNEL
);
279 rio_init_dbell_res(res
, start
, end
);
281 /* Make sure these doorbells aren't in use */
283 request_resource(&mport
->riores
[RIO_DOORBELL_RESOURCE
],
289 /* Hook the doorbell callback */
290 rc
= rio_setup_inb_dbell(mport
, dev_id
, res
, dinb
);
299 * rio_release_inb_dbell - release inbound doorbell message service
300 * @mport: RIO master port from which to release the doorbell resource
301 * @start: Doorbell info range start
302 * @end: Doorbell info range end
304 * Releases ownership of an inbound doorbell resource and removes
305 * callback from the doorbell event list. Returns 0 if the request
306 * has been satisfied.
308 int rio_release_inb_dbell(struct rio_mport
*mport
, u16 start
, u16 end
)
310 int rc
= 0, found
= 0;
311 struct rio_dbell
*dbell
;
313 list_for_each_entry(dbell
, &mport
->dbells
, node
) {
314 if ((dbell
->res
->start
== start
) && (dbell
->res
->end
== end
)) {
320 /* If we can't find an exact match, fail */
326 /* Delete from list */
327 list_del(&dbell
->node
);
329 /* Release the doorbell resource */
330 rc
= release_resource(dbell
->res
);
332 /* Free the doorbell event */
340 * rio_request_outb_dbell - request outbound doorbell message range
341 * @rdev: RIO device from which to allocate the doorbell resource
342 * @start: Doorbell message range start
343 * @end: Doorbell message range end
345 * Requests ownership of a doorbell message range. Returns a resource
346 * if the request has been satisfied or %NULL on failure.
348 struct resource
*rio_request_outb_dbell(struct rio_dev
*rdev
, u16 start
,
351 struct resource
*res
= kmalloc(sizeof(struct resource
), GFP_KERNEL
);
354 rio_init_dbell_res(res
, start
, end
);
356 /* Make sure these doorbells aren't in use */
357 if (request_resource(&rdev
->riores
[RIO_DOORBELL_RESOURCE
], res
)
368 * rio_release_outb_dbell - release outbound doorbell message range
369 * @rdev: RIO device from which to release the doorbell resource
370 * @res: Doorbell resource to be freed
372 * Releases ownership of a doorbell message range. Returns 0 if the
373 * request has been satisfied.
375 int rio_release_outb_dbell(struct rio_dev
*rdev
, struct resource
*res
)
377 int rc
= release_resource(res
);
385 * rio_request_inb_pwrite - request inbound port-write message service
386 * @rdev: RIO device to which register inbound port-write callback routine
387 * @pwcback: Callback routine to execute when port-write is received
389 * Binds a port-write callback function to the RapidIO device.
390 * Returns 0 if the request has been satisfied.
392 int rio_request_inb_pwrite(struct rio_dev
*rdev
,
393 int (*pwcback
)(struct rio_dev
*rdev
, union rio_pw_msg
*msg
, int step
))
397 spin_lock(&rio_global_list_lock
);
398 if (rdev
->pwcback
!= NULL
)
401 rdev
->pwcback
= pwcback
;
403 spin_unlock(&rio_global_list_lock
);
406 EXPORT_SYMBOL_GPL(rio_request_inb_pwrite
);
409 * rio_release_inb_pwrite - release inbound port-write message service
410 * @rdev: RIO device which registered for inbound port-write callback
412 * Removes callback from the rio_dev structure. Returns 0 if the request
413 * has been satisfied.
415 int rio_release_inb_pwrite(struct rio_dev
*rdev
)
419 spin_lock(&rio_global_list_lock
);
421 rdev
->pwcback
= NULL
;
425 spin_unlock(&rio_global_list_lock
);
428 EXPORT_SYMBOL_GPL(rio_release_inb_pwrite
);
431 * rio_map_inb_region -- Map inbound memory region.
432 * @mport: Master port.
433 * @local: physical address of memory region to be mapped
434 * @rbase: RIO base address assigned to this window
435 * @size: Size of the memory region
436 * @rflags: Flags for mapping.
438 * Return: 0 -- Success.
440 * This function will create the mapping from RIO space to local memory.
442 int rio_map_inb_region(struct rio_mport
*mport
, dma_addr_t local
,
443 u64 rbase
, u32 size
, u32 rflags
)
448 if (!mport
->ops
->map_inb
)
450 spin_lock_irqsave(&rio_mmap_lock
, flags
);
451 rc
= mport
->ops
->map_inb(mport
, local
, rbase
, size
, rflags
);
452 spin_unlock_irqrestore(&rio_mmap_lock
, flags
);
455 EXPORT_SYMBOL_GPL(rio_map_inb_region
);
458 * rio_unmap_inb_region -- Unmap the inbound memory region
459 * @mport: Master port
460 * @lstart: physical address of memory region to be unmapped
462 void rio_unmap_inb_region(struct rio_mport
*mport
, dma_addr_t lstart
)
465 if (!mport
->ops
->unmap_inb
)
467 spin_lock_irqsave(&rio_mmap_lock
, flags
);
468 mport
->ops
->unmap_inb(mport
, lstart
);
469 spin_unlock_irqrestore(&rio_mmap_lock
, flags
);
471 EXPORT_SYMBOL_GPL(rio_unmap_inb_region
);
474 * rio_mport_get_physefb - Helper function that returns register offset
475 * for Physical Layer Extended Features Block.
476 * @port: Master port to issue transaction
477 * @local: Indicate a local master port or remote device access
478 * @destid: Destination ID of the device
479 * @hopcount: Number of switch hops to the device
482 rio_mport_get_physefb(struct rio_mport
*port
, int local
,
483 u16 destid
, u8 hopcount
)
488 ext_ftr_ptr
= rio_mport_get_efb(port
, local
, destid
, hopcount
, 0);
490 while (ext_ftr_ptr
) {
492 rio_local_read_config_32(port
, ext_ftr_ptr
,
495 rio_mport_read_config_32(port
, destid
, hopcount
,
496 ext_ftr_ptr
, &ftr_header
);
498 ftr_header
= RIO_GET_BLOCK_ID(ftr_header
);
499 switch (ftr_header
) {
501 case RIO_EFB_SER_EP_ID_V13P
:
502 case RIO_EFB_SER_EP_REC_ID_V13P
:
503 case RIO_EFB_SER_EP_FREE_ID_V13P
:
504 case RIO_EFB_SER_EP_ID
:
505 case RIO_EFB_SER_EP_REC_ID
:
506 case RIO_EFB_SER_EP_FREE_ID
:
507 case RIO_EFB_SER_EP_FREC_ID
:
515 ext_ftr_ptr
= rio_mport_get_efb(port
, local
, destid
,
516 hopcount
, ext_ftr_ptr
);
521 EXPORT_SYMBOL_GPL(rio_mport_get_physefb
);
524 * rio_get_comptag - Begin or continue searching for a RIO device by component tag
525 * @comp_tag: RIO component tag to match
526 * @from: Previous RIO device found in search, or %NULL for new search
528 * Iterates through the list of known RIO devices. If a RIO device is
529 * found with a matching @comp_tag, a pointer to its device
530 * structure is returned. Otherwise, %NULL is returned. A new search
531 * is initiated by passing %NULL to the @from argument. Otherwise, if
532 * @from is not %NULL, searches continue from next device on the global
535 struct rio_dev
*rio_get_comptag(u32 comp_tag
, struct rio_dev
*from
)
538 struct rio_dev
*rdev
;
540 spin_lock(&rio_global_list_lock
);
541 n
= from
? from
->global_list
.next
: rio_devices
.next
;
543 while (n
&& (n
!= &rio_devices
)) {
545 if (rdev
->comp_tag
== comp_tag
)
551 spin_unlock(&rio_global_list_lock
);
554 EXPORT_SYMBOL_GPL(rio_get_comptag
);
557 * rio_set_port_lockout - Sets/clears LOCKOUT bit (RIO EM 1.3) for a switch port.
558 * @rdev: Pointer to RIO device control structure
559 * @pnum: Switch port number to set LOCKOUT bit
560 * @lock: Operation : set (=1) or clear (=0)
562 int rio_set_port_lockout(struct rio_dev
*rdev
, u32 pnum
, int lock
)
566 rio_read_config_32(rdev
,
567 rdev
->phys_efptr
+ RIO_PORT_N_CTL_CSR(pnum
),
570 regval
|= RIO_PORT_N_CTL_LOCKOUT
;
572 regval
&= ~RIO_PORT_N_CTL_LOCKOUT
;
574 rio_write_config_32(rdev
,
575 rdev
->phys_efptr
+ RIO_PORT_N_CTL_CSR(pnum
),
579 EXPORT_SYMBOL_GPL(rio_set_port_lockout
);
582 * rio_enable_rx_tx_port - enable input receiver and output transmitter of
584 * @port: Master port associated with the RIO network
585 * @local: local=1 select local port otherwise a far device is reached
586 * @destid: Destination ID of the device to check host bit
587 * @hopcount: Number of hops to reach the target
588 * @port_num: Port (-number on switch) to enable on a far end device
590 * Returns 0 or 1 from on General Control Command and Status Register
593 int rio_enable_rx_tx_port(struct rio_mport
*port
,
594 int local
, u16 destid
,
595 u8 hopcount
, u8 port_num
)
597 #ifdef CONFIG_RAPIDIO_ENABLE_RX_TX_PORTS
602 * enable rx input tx output port
604 pr_debug("rio_enable_rx_tx_port(local = %d, destid = %d, hopcount = "
605 "%d, port_num = %d)\n", local
, destid
, hopcount
, port_num
);
607 ext_ftr_ptr
= rio_mport_get_physefb(port
, local
, destid
, hopcount
);
610 rio_local_read_config_32(port
, ext_ftr_ptr
+
611 RIO_PORT_N_CTL_CSR(0),
614 if (rio_mport_read_config_32(port
, destid
, hopcount
,
615 ext_ftr_ptr
+ RIO_PORT_N_CTL_CSR(port_num
), ®val
) < 0)
619 if (regval
& RIO_PORT_N_CTL_P_TYP_SER
) {
621 regval
= regval
| RIO_PORT_N_CTL_EN_RX_SER
622 | RIO_PORT_N_CTL_EN_TX_SER
;
625 regval
= regval
| RIO_PORT_N_CTL_EN_RX_PAR
626 | RIO_PORT_N_CTL_EN_TX_PAR
;
630 rio_local_write_config_32(port
, ext_ftr_ptr
+
631 RIO_PORT_N_CTL_CSR(0), regval
);
633 if (rio_mport_write_config_32(port
, destid
, hopcount
,
634 ext_ftr_ptr
+ RIO_PORT_N_CTL_CSR(port_num
), regval
) < 0)
640 EXPORT_SYMBOL_GPL(rio_enable_rx_tx_port
);
644 * rio_chk_dev_route - Validate route to the specified device.
645 * @rdev: RIO device failed to respond
646 * @nrdev: Last active device on the route to rdev
647 * @npnum: nrdev's port number on the route to rdev
649 * Follows a route to the specified RIO device to determine the last available
650 * device (and corresponding RIO port) on the route.
653 rio_chk_dev_route(struct rio_dev
*rdev
, struct rio_dev
**nrdev
, int *npnum
)
656 int p_port
, rc
= -EIO
;
657 struct rio_dev
*prev
= NULL
;
659 /* Find switch with failed RIO link */
660 while (rdev
->prev
&& (rdev
->prev
->pef
& RIO_PEF_SWITCH
)) {
661 if (!rio_read_config_32(rdev
->prev
, RIO_DEV_ID_CAR
, &result
)) {
671 p_port
= prev
->rswitch
->route_table
[rdev
->destid
];
673 if (p_port
!= RIO_INVALID_ROUTE
) {
674 pr_debug("RIO: link failed on [%s]-P%d\n",
675 rio_name(prev
), p_port
);
680 pr_debug("RIO: failed to trace route to %s\n", rio_name(rdev
));
686 * rio_mport_chk_dev_access - Validate access to the specified device.
687 * @mport: Master port to send transactions
688 * @destid: Device destination ID in network
689 * @hopcount: Number of hops into the network
692 rio_mport_chk_dev_access(struct rio_mport
*mport
, u16 destid
, u8 hopcount
)
697 while (rio_mport_read_config_32(mport
, destid
, hopcount
,
698 RIO_DEV_ID_CAR
, &tmp
)) {
700 if (i
== RIO_MAX_CHK_RETRY
)
707 EXPORT_SYMBOL_GPL(rio_mport_chk_dev_access
);
710 * rio_chk_dev_access - Validate access to the specified device.
711 * @rdev: Pointer to RIO device control structure
713 static int rio_chk_dev_access(struct rio_dev
*rdev
)
715 return rio_mport_chk_dev_access(rdev
->net
->hport
,
716 rdev
->destid
, rdev
->hopcount
);
720 * rio_get_input_status - Sends a Link-Request/Input-Status control symbol and
721 * returns link-response (if requested).
722 * @rdev: RIO devive to issue Input-status command
723 * @pnum: Device port number to issue the command
724 * @lnkresp: Response from a link partner
727 rio_get_input_status(struct rio_dev
*rdev
, int pnum
, u32
*lnkresp
)
733 /* Read from link maintenance response register
734 * to clear valid bit */
735 rio_read_config_32(rdev
,
736 rdev
->phys_efptr
+ RIO_PORT_N_MNT_RSP_CSR(pnum
),
741 /* Issue Input-status command */
742 rio_write_config_32(rdev
,
743 rdev
->phys_efptr
+ RIO_PORT_N_MNT_REQ_CSR(pnum
),
746 /* Exit if the response is not expected */
751 while (checkcount
--) {
753 rio_read_config_32(rdev
,
754 rdev
->phys_efptr
+ RIO_PORT_N_MNT_RSP_CSR(pnum
),
756 if (regval
& RIO_PORT_N_MNT_RSP_RVAL
) {
766 * rio_clr_err_stopped - Clears port Error-stopped states.
767 * @rdev: Pointer to RIO device control structure
768 * @pnum: Switch port number to clear errors
769 * @err_status: port error status (if 0 reads register from device)
771 static int rio_clr_err_stopped(struct rio_dev
*rdev
, u32 pnum
, u32 err_status
)
773 struct rio_dev
*nextdev
= rdev
->rswitch
->nextdev
[pnum
];
775 u32 far_ackid
, far_linkstat
, near_ackid
;
778 rio_read_config_32(rdev
,
779 rdev
->phys_efptr
+ RIO_PORT_N_ERR_STS_CSR(pnum
),
782 if (err_status
& RIO_PORT_N_ERR_STS_PW_OUT_ES
) {
783 pr_debug("RIO_EM: servicing Output Error-Stopped state\n");
785 * Send a Link-Request/Input-Status control symbol
787 if (rio_get_input_status(rdev
, pnum
, ®val
)) {
788 pr_debug("RIO_EM: Input-status response timeout\n");
792 pr_debug("RIO_EM: SP%d Input-status response=0x%08x\n",
794 far_ackid
= (regval
& RIO_PORT_N_MNT_RSP_ASTAT
) >> 5;
795 far_linkstat
= regval
& RIO_PORT_N_MNT_RSP_LSTAT
;
796 rio_read_config_32(rdev
,
797 rdev
->phys_efptr
+ RIO_PORT_N_ACK_STS_CSR(pnum
),
799 pr_debug("RIO_EM: SP%d_ACK_STS_CSR=0x%08x\n", pnum
, regval
);
800 near_ackid
= (regval
& RIO_PORT_N_ACK_INBOUND
) >> 24;
801 pr_debug("RIO_EM: SP%d far_ackID=0x%02x far_linkstat=0x%02x" \
802 " near_ackID=0x%02x\n",
803 pnum
, far_ackid
, far_linkstat
, near_ackid
);
806 * If required, synchronize ackIDs of near and
809 if ((far_ackid
!= ((regval
& RIO_PORT_N_ACK_OUTSTAND
) >> 8)) ||
810 (far_ackid
!= (regval
& RIO_PORT_N_ACK_OUTBOUND
))) {
811 /* Align near outstanding/outbound ackIDs with
814 rio_write_config_32(rdev
,
815 rdev
->phys_efptr
+ RIO_PORT_N_ACK_STS_CSR(pnum
),
817 (far_ackid
<< 8) | far_ackid
);
818 /* Align far outstanding/outbound ackIDs with
823 rio_write_config_32(nextdev
,
824 nextdev
->phys_efptr
+
825 RIO_PORT_N_ACK_STS_CSR(RIO_GET_PORT_NUM(nextdev
->swpinfo
)),
827 (near_ackid
<< 8) | near_ackid
);
829 pr_debug("RIO_EM: Invalid nextdev pointer (NULL)\n");
832 rio_read_config_32(rdev
,
833 rdev
->phys_efptr
+ RIO_PORT_N_ERR_STS_CSR(pnum
),
835 pr_debug("RIO_EM: SP%d_ERR_STS_CSR=0x%08x\n", pnum
, err_status
);
838 if ((err_status
& RIO_PORT_N_ERR_STS_PW_INP_ES
) && nextdev
) {
839 pr_debug("RIO_EM: servicing Input Error-Stopped state\n");
840 rio_get_input_status(nextdev
,
841 RIO_GET_PORT_NUM(nextdev
->swpinfo
), NULL
);
844 rio_read_config_32(rdev
,
845 rdev
->phys_efptr
+ RIO_PORT_N_ERR_STS_CSR(pnum
),
847 pr_debug("RIO_EM: SP%d_ERR_STS_CSR=0x%08x\n", pnum
, err_status
);
850 return (err_status
& (RIO_PORT_N_ERR_STS_PW_OUT_ES
|
851 RIO_PORT_N_ERR_STS_PW_INP_ES
)) ? 1 : 0;
855 * rio_inb_pwrite_handler - process inbound port-write message
856 * @pw_msg: pointer to inbound port-write message
858 * Processes an inbound port-write message. Returns 0 if the request
859 * has been satisfied.
861 int rio_inb_pwrite_handler(union rio_pw_msg
*pw_msg
)
863 struct rio_dev
*rdev
;
864 u32 err_status
, em_perrdet
, em_ltlerrdet
;
867 rdev
= rio_get_comptag((pw_msg
->em
.comptag
& RIO_CTAG_UDEVID
), NULL
);
869 /* Device removed or enumeration error */
870 pr_debug("RIO: %s No matching device for CTag 0x%08x\n",
871 __func__
, pw_msg
->em
.comptag
);
875 pr_debug("RIO: Port-Write message from %s\n", rio_name(rdev
));
880 for (i
= 0; i
< RIO_PW_MSG_SIZE
/sizeof(u32
);) {
881 pr_debug("0x%02x: %08x %08x %08x %08x\n",
882 i
*4, pw_msg
->raw
[i
], pw_msg
->raw
[i
+ 1],
883 pw_msg
->raw
[i
+ 2], pw_msg
->raw
[i
+ 3]);
889 /* Call an external service function (if such is registered
890 * for this device). This may be the service for endpoints that send
891 * device-specific port-write messages. End-point messages expected
892 * to be handled completely by EP specific device driver.
893 * For switches rc==0 signals that no standard processing required.
895 if (rdev
->pwcback
!= NULL
) {
896 rc
= rdev
->pwcback(rdev
, pw_msg
, 0);
901 portnum
= pw_msg
->em
.is_port
& 0xFF;
903 /* Check if device and route to it are functional:
904 * Sometimes devices may send PW message(s) just before being
905 * powered down (or link being lost).
907 if (rio_chk_dev_access(rdev
)) {
908 pr_debug("RIO: device access failed - get link partner\n");
909 /* Scan route to the device and identify failed link.
910 * This will replace device and port reported in PW message.
911 * PW message should not be used after this point.
913 if (rio_chk_dev_route(rdev
, &rdev
, &portnum
)) {
914 pr_err("RIO: Route trace for %s failed\n",
921 /* For End-point devices processing stops here */
922 if (!(rdev
->pef
& RIO_PEF_SWITCH
))
925 if (rdev
->phys_efptr
== 0) {
926 pr_err("RIO_PW: Bad switch initialization for %s\n",
932 * Process the port-write notification from switch
934 if (rdev
->rswitch
->ops
&& rdev
->rswitch
->ops
->em_handle
)
935 rdev
->rswitch
->ops
->em_handle(rdev
, portnum
);
937 rio_read_config_32(rdev
,
938 rdev
->phys_efptr
+ RIO_PORT_N_ERR_STS_CSR(portnum
),
940 pr_debug("RIO_PW: SP%d_ERR_STS_CSR=0x%08x\n", portnum
, err_status
);
942 if (err_status
& RIO_PORT_N_ERR_STS_PORT_OK
) {
944 if (!(rdev
->rswitch
->port_ok
& (1 << portnum
))) {
945 rdev
->rswitch
->port_ok
|= (1 << portnum
);
946 rio_set_port_lockout(rdev
, portnum
, 0);
947 /* Schedule Insertion Service */
948 pr_debug("RIO_PW: Device Insertion on [%s]-P%d\n",
949 rio_name(rdev
), portnum
);
952 /* Clear error-stopped states (if reported).
953 * Depending on the link partner state, two attempts
954 * may be needed for successful recovery.
956 if (err_status
& (RIO_PORT_N_ERR_STS_PW_OUT_ES
|
957 RIO_PORT_N_ERR_STS_PW_INP_ES
)) {
958 if (rio_clr_err_stopped(rdev
, portnum
, err_status
))
959 rio_clr_err_stopped(rdev
, portnum
, 0);
961 } else { /* if (err_status & RIO_PORT_N_ERR_STS_PORT_UNINIT) */
963 if (rdev
->rswitch
->port_ok
& (1 << portnum
)) {
964 rdev
->rswitch
->port_ok
&= ~(1 << portnum
);
965 rio_set_port_lockout(rdev
, portnum
, 1);
967 rio_write_config_32(rdev
,
969 RIO_PORT_N_ACK_STS_CSR(portnum
),
970 RIO_PORT_N_ACK_CLEAR
);
972 /* Schedule Extraction Service */
973 pr_debug("RIO_PW: Device Extraction on [%s]-P%d\n",
974 rio_name(rdev
), portnum
);
978 rio_read_config_32(rdev
,
979 rdev
->em_efptr
+ RIO_EM_PN_ERR_DETECT(portnum
), &em_perrdet
);
981 pr_debug("RIO_PW: RIO_EM_P%d_ERR_DETECT=0x%08x\n",
982 portnum
, em_perrdet
);
983 /* Clear EM Port N Error Detect CSR */
984 rio_write_config_32(rdev
,
985 rdev
->em_efptr
+ RIO_EM_PN_ERR_DETECT(portnum
), 0);
988 rio_read_config_32(rdev
,
989 rdev
->em_efptr
+ RIO_EM_LTL_ERR_DETECT
, &em_ltlerrdet
);
991 pr_debug("RIO_PW: RIO_EM_LTL_ERR_DETECT=0x%08x\n",
993 /* Clear EM L/T Layer Error Detect CSR */
994 rio_write_config_32(rdev
,
995 rdev
->em_efptr
+ RIO_EM_LTL_ERR_DETECT
, 0);
998 /* Clear remaining error bits and Port-Write Pending bit */
999 rio_write_config_32(rdev
,
1000 rdev
->phys_efptr
+ RIO_PORT_N_ERR_STS_CSR(portnum
),
1005 EXPORT_SYMBOL_GPL(rio_inb_pwrite_handler
);
1008 * rio_mport_get_efb - get pointer to next extended features block
1009 * @port: Master port to issue transaction
1010 * @local: Indicate a local master port or remote device access
1011 * @destid: Destination ID of the device
1012 * @hopcount: Number of switch hops to the device
1013 * @from: Offset of current Extended Feature block header (if 0 starts
1014 * from ExtFeaturePtr)
1017 rio_mport_get_efb(struct rio_mport
*port
, int local
, u16 destid
,
1018 u8 hopcount
, u32 from
)
1024 rio_local_read_config_32(port
, RIO_ASM_INFO_CAR
,
1027 rio_mport_read_config_32(port
, destid
, hopcount
,
1028 RIO_ASM_INFO_CAR
, ®_val
);
1029 return reg_val
& RIO_EXT_FTR_PTR_MASK
;
1032 rio_local_read_config_32(port
, from
, ®_val
);
1034 rio_mport_read_config_32(port
, destid
, hopcount
,
1036 return RIO_GET_BLOCK_ID(reg_val
);
1039 EXPORT_SYMBOL_GPL(rio_mport_get_efb
);
1042 * rio_mport_get_feature - query for devices' extended features
1043 * @port: Master port to issue transaction
1044 * @local: Indicate a local master port or remote device access
1045 * @destid: Destination ID of the device
1046 * @hopcount: Number of switch hops to the device
1047 * @ftr: Extended feature code
1049 * Tell if a device supports a given RapidIO capability.
1050 * Returns the offset of the requested extended feature
1051 * block within the device's RIO configuration space or
1052 * 0 in case the device does not support it. Possible
1055 * %RIO_EFB_PAR_EP_ID LP/LVDS EP Devices
1057 * %RIO_EFB_PAR_EP_REC_ID LP/LVDS EP Recovery Devices
1059 * %RIO_EFB_PAR_EP_FREE_ID LP/LVDS EP Free Devices
1061 * %RIO_EFB_SER_EP_ID LP/Serial EP Devices
1063 * %RIO_EFB_SER_EP_REC_ID LP/Serial EP Recovery Devices
1065 * %RIO_EFB_SER_EP_FREE_ID LP/Serial EP Free Devices
1068 rio_mport_get_feature(struct rio_mport
* port
, int local
, u16 destid
,
1069 u8 hopcount
, int ftr
)
1071 u32 asm_info
, ext_ftr_ptr
, ftr_header
;
1074 rio_local_read_config_32(port
, RIO_ASM_INFO_CAR
, &asm_info
);
1076 rio_mport_read_config_32(port
, destid
, hopcount
,
1077 RIO_ASM_INFO_CAR
, &asm_info
);
1079 ext_ftr_ptr
= asm_info
& RIO_EXT_FTR_PTR_MASK
;
1081 while (ext_ftr_ptr
) {
1083 rio_local_read_config_32(port
, ext_ftr_ptr
,
1086 rio_mport_read_config_32(port
, destid
, hopcount
,
1087 ext_ftr_ptr
, &ftr_header
);
1088 if (RIO_GET_BLOCK_ID(ftr_header
) == ftr
)
1090 if (!(ext_ftr_ptr
= RIO_GET_BLOCK_PTR(ftr_header
)))
1096 EXPORT_SYMBOL_GPL(rio_mport_get_feature
);
1099 * rio_get_asm - Begin or continue searching for a RIO device by vid/did/asm_vid/asm_did
1100 * @vid: RIO vid to match or %RIO_ANY_ID to match all vids
1101 * @did: RIO did to match or %RIO_ANY_ID to match all dids
1102 * @asm_vid: RIO asm_vid to match or %RIO_ANY_ID to match all asm_vids
1103 * @asm_did: RIO asm_did to match or %RIO_ANY_ID to match all asm_dids
1104 * @from: Previous RIO device found in search, or %NULL for new search
1106 * Iterates through the list of known RIO devices. If a RIO device is
1107 * found with a matching @vid, @did, @asm_vid, @asm_did, the reference
1108 * count to the device is incrememted and a pointer to its device
1109 * structure is returned. Otherwise, %NULL is returned. A new search
1110 * is initiated by passing %NULL to the @from argument. Otherwise, if
1111 * @from is not %NULL, searches continue from next device on the global
1112 * list. The reference count for @from is always decremented if it is
1115 struct rio_dev
*rio_get_asm(u16 vid
, u16 did
,
1116 u16 asm_vid
, u16 asm_did
, struct rio_dev
*from
)
1118 struct list_head
*n
;
1119 struct rio_dev
*rdev
;
1121 WARN_ON(in_interrupt());
1122 spin_lock(&rio_global_list_lock
);
1123 n
= from
? from
->global_list
.next
: rio_devices
.next
;
1125 while (n
&& (n
!= &rio_devices
)) {
1126 rdev
= rio_dev_g(n
);
1127 if ((vid
== RIO_ANY_ID
|| rdev
->vid
== vid
) &&
1128 (did
== RIO_ANY_ID
|| rdev
->did
== did
) &&
1129 (asm_vid
== RIO_ANY_ID
|| rdev
->asm_vid
== asm_vid
) &&
1130 (asm_did
== RIO_ANY_ID
|| rdev
->asm_did
== asm_did
))
1137 rdev
= rio_dev_get(rdev
);
1138 spin_unlock(&rio_global_list_lock
);
1143 * rio_get_device - Begin or continue searching for a RIO device by vid/did
1144 * @vid: RIO vid to match or %RIO_ANY_ID to match all vids
1145 * @did: RIO did to match or %RIO_ANY_ID to match all dids
1146 * @from: Previous RIO device found in search, or %NULL for new search
1148 * Iterates through the list of known RIO devices. If a RIO device is
1149 * found with a matching @vid and @did, the reference count to the
1150 * device is incrememted and a pointer to its device structure is returned.
1151 * Otherwise, %NULL is returned. A new search is initiated by passing %NULL
1152 * to the @from argument. Otherwise, if @from is not %NULL, searches
1153 * continue from next device on the global list. The reference count for
1154 * @from is always decremented if it is not %NULL.
1156 struct rio_dev
*rio_get_device(u16 vid
, u16 did
, struct rio_dev
*from
)
1158 return rio_get_asm(vid
, did
, RIO_ANY_ID
, RIO_ANY_ID
, from
);
1162 * rio_std_route_add_entry - Add switch route table entry using standard
1163 * registers defined in RIO specification rev.1.3
1164 * @mport: Master port to issue transaction
1165 * @destid: Destination ID of the device
1166 * @hopcount: Number of switch hops to the device
1167 * @table: routing table ID (global or port-specific)
1168 * @route_destid: destID entry in the RT
1169 * @route_port: destination port for specified destID
1172 rio_std_route_add_entry(struct rio_mport
*mport
, u16 destid
, u8 hopcount
,
1173 u16 table
, u16 route_destid
, u8 route_port
)
1175 if (table
== RIO_GLOBAL_TABLE
) {
1176 rio_mport_write_config_32(mport
, destid
, hopcount
,
1177 RIO_STD_RTE_CONF_DESTID_SEL_CSR
,
1179 rio_mport_write_config_32(mport
, destid
, hopcount
,
1180 RIO_STD_RTE_CONF_PORT_SEL_CSR
,
1189 * rio_std_route_get_entry - Read switch route table entry (port number)
1190 * associated with specified destID using standard registers defined in RIO
1191 * specification rev.1.3
1192 * @mport: Master port to issue transaction
1193 * @destid: Destination ID of the device
1194 * @hopcount: Number of switch hops to the device
1195 * @table: routing table ID (global or port-specific)
1196 * @route_destid: destID entry in the RT
1197 * @route_port: returned destination port for specified destID
1200 rio_std_route_get_entry(struct rio_mport
*mport
, u16 destid
, u8 hopcount
,
1201 u16 table
, u16 route_destid
, u8
*route_port
)
1205 if (table
== RIO_GLOBAL_TABLE
) {
1206 rio_mport_write_config_32(mport
, destid
, hopcount
,
1207 RIO_STD_RTE_CONF_DESTID_SEL_CSR
, route_destid
);
1208 rio_mport_read_config_32(mport
, destid
, hopcount
,
1209 RIO_STD_RTE_CONF_PORT_SEL_CSR
, &result
);
1211 *route_port
= (u8
)result
;
1218 * rio_std_route_clr_table - Clear swotch route table using standard registers
1219 * defined in RIO specification rev.1.3.
1220 * @mport: Master port to issue transaction
1221 * @destid: Destination ID of the device
1222 * @hopcount: Number of switch hops to the device
1223 * @table: routing table ID (global or port-specific)
1226 rio_std_route_clr_table(struct rio_mport
*mport
, u16 destid
, u8 hopcount
,
1229 u32 max_destid
= 0xff;
1230 u32 i
, pef
, id_inc
= 1, ext_cfg
= 0;
1231 u32 port_sel
= RIO_INVALID_ROUTE
;
1233 if (table
== RIO_GLOBAL_TABLE
) {
1234 rio_mport_read_config_32(mport
, destid
, hopcount
,
1237 if (mport
->sys_size
) {
1238 rio_mport_read_config_32(mport
, destid
, hopcount
,
1239 RIO_SWITCH_RT_LIMIT
,
1241 max_destid
&= RIO_RT_MAX_DESTID
;
1244 if (pef
& RIO_PEF_EXT_RT
) {
1245 ext_cfg
= 0x80000000;
1247 port_sel
= (RIO_INVALID_ROUTE
<< 24) |
1248 (RIO_INVALID_ROUTE
<< 16) |
1249 (RIO_INVALID_ROUTE
<< 8) |
1253 for (i
= 0; i
<= max_destid
;) {
1254 rio_mport_write_config_32(mport
, destid
, hopcount
,
1255 RIO_STD_RTE_CONF_DESTID_SEL_CSR
,
1257 rio_mport_write_config_32(mport
, destid
, hopcount
,
1258 RIO_STD_RTE_CONF_PORT_SEL_CSR
,
1269 * rio_lock_device - Acquires host device lock for specified device
1270 * @port: Master port to send transaction
1271 * @destid: Destination ID for device/switch
1272 * @hopcount: Hopcount to reach switch
1273 * @wait_ms: Max wait time in msec (0 = no timeout)
1275 * Attepts to acquire host device lock for specified device
1276 * Returns 0 if device lock acquired or EINVAL if timeout expires.
1278 int rio_lock_device(struct rio_mport
*port
, u16 destid
,
1279 u8 hopcount
, int wait_ms
)
1284 /* Attempt to acquire device lock */
1285 rio_mport_write_config_32(port
, destid
, hopcount
,
1286 RIO_HOST_DID_LOCK_CSR
, port
->host_deviceid
);
1287 rio_mport_read_config_32(port
, destid
, hopcount
,
1288 RIO_HOST_DID_LOCK_CSR
, &result
);
1290 while (result
!= port
->host_deviceid
) {
1291 if (wait_ms
!= 0 && tcnt
== wait_ms
) {
1292 pr_debug("RIO: timeout when locking device %x:%x\n",
1300 /* Try to acquire device lock again */
1301 rio_mport_write_config_32(port
, destid
,
1303 RIO_HOST_DID_LOCK_CSR
,
1304 port
->host_deviceid
);
1305 rio_mport_read_config_32(port
, destid
,
1307 RIO_HOST_DID_LOCK_CSR
, &result
);
1312 EXPORT_SYMBOL_GPL(rio_lock_device
);
1315 * rio_unlock_device - Releases host device lock for specified device
1316 * @port: Master port to send transaction
1317 * @destid: Destination ID for device/switch
1318 * @hopcount: Hopcount to reach switch
1320 * Returns 0 if device lock released or EINVAL if fails.
1322 int rio_unlock_device(struct rio_mport
*port
, u16 destid
, u8 hopcount
)
1326 /* Release device lock */
1327 rio_mport_write_config_32(port
, destid
,
1329 RIO_HOST_DID_LOCK_CSR
,
1330 port
->host_deviceid
);
1331 rio_mport_read_config_32(port
, destid
, hopcount
,
1332 RIO_HOST_DID_LOCK_CSR
, &result
);
1333 if ((result
& 0xffff) != 0xffff) {
1334 pr_debug("RIO: badness when releasing device lock %x:%x\n",
1341 EXPORT_SYMBOL_GPL(rio_unlock_device
);
1344 * rio_route_add_entry- Add a route entry to a switch routing table
1346 * @table: Routing table ID
1347 * @route_destid: Destination ID to be routed
1348 * @route_port: Port number to be routed
1349 * @lock: apply a hardware lock on switch device flag (1=lock, 0=no_lock)
1351 * If available calls the switch specific add_entry() method to add a route
1352 * entry into a switch routing table. Otherwise uses standard RT update method
1353 * as defined by RapidIO specification. A specific routing table can be selected
1354 * using the @table argument if a switch has per port routing tables or
1355 * the standard (or global) table may be used by passing
1356 * %RIO_GLOBAL_TABLE in @table.
1358 * Returns %0 on success or %-EINVAL on failure.
1360 int rio_route_add_entry(struct rio_dev
*rdev
,
1361 u16 table
, u16 route_destid
, u8 route_port
, int lock
)
1364 struct rio_switch_ops
*ops
= rdev
->rswitch
->ops
;
1367 rc
= rio_lock_device(rdev
->net
->hport
, rdev
->destid
,
1368 rdev
->hopcount
, 1000);
1373 spin_lock(&rdev
->rswitch
->lock
);
1375 if (ops
== NULL
|| ops
->add_entry
== NULL
) {
1376 rc
= rio_std_route_add_entry(rdev
->net
->hport
, rdev
->destid
,
1377 rdev
->hopcount
, table
,
1378 route_destid
, route_port
);
1379 } else if (try_module_get(ops
->owner
)) {
1380 rc
= ops
->add_entry(rdev
->net
->hport
, rdev
->destid
,
1381 rdev
->hopcount
, table
, route_destid
,
1383 module_put(ops
->owner
);
1386 spin_unlock(&rdev
->rswitch
->lock
);
1389 rio_unlock_device(rdev
->net
->hport
, rdev
->destid
,
1394 EXPORT_SYMBOL_GPL(rio_route_add_entry
);
1397 * rio_route_get_entry- Read an entry from a switch routing table
1399 * @table: Routing table ID
1400 * @route_destid: Destination ID to be routed
1401 * @route_port: Pointer to read port number into
1402 * @lock: apply a hardware lock on switch device flag (1=lock, 0=no_lock)
1404 * If available calls the switch specific get_entry() method to fetch a route
1405 * entry from a switch routing table. Otherwise uses standard RT read method
1406 * as defined by RapidIO specification. A specific routing table can be selected
1407 * using the @table argument if a switch has per port routing tables or
1408 * the standard (or global) table may be used by passing
1409 * %RIO_GLOBAL_TABLE in @table.
1411 * Returns %0 on success or %-EINVAL on failure.
1413 int rio_route_get_entry(struct rio_dev
*rdev
, u16 table
,
1414 u16 route_destid
, u8
*route_port
, int lock
)
1417 struct rio_switch_ops
*ops
= rdev
->rswitch
->ops
;
1420 rc
= rio_lock_device(rdev
->net
->hport
, rdev
->destid
,
1421 rdev
->hopcount
, 1000);
1426 spin_lock(&rdev
->rswitch
->lock
);
1428 if (ops
== NULL
|| ops
->get_entry
== NULL
) {
1429 rc
= rio_std_route_get_entry(rdev
->net
->hport
, rdev
->destid
,
1430 rdev
->hopcount
, table
,
1431 route_destid
, route_port
);
1432 } else if (try_module_get(ops
->owner
)) {
1433 rc
= ops
->get_entry(rdev
->net
->hport
, rdev
->destid
,
1434 rdev
->hopcount
, table
, route_destid
,
1436 module_put(ops
->owner
);
1439 spin_unlock(&rdev
->rswitch
->lock
);
1442 rio_unlock_device(rdev
->net
->hport
, rdev
->destid
,
1446 EXPORT_SYMBOL_GPL(rio_route_get_entry
);
1449 * rio_route_clr_table - Clear a switch routing table
1451 * @table: Routing table ID
1452 * @lock: apply a hardware lock on switch device flag (1=lock, 0=no_lock)
1454 * If available calls the switch specific clr_table() method to clear a switch
1455 * routing table. Otherwise uses standard RT write method as defined by RapidIO
1456 * specification. A specific routing table can be selected using the @table
1457 * argument if a switch has per port routing tables or the standard (or global)
1458 * table may be used by passing %RIO_GLOBAL_TABLE in @table.
1460 * Returns %0 on success or %-EINVAL on failure.
1462 int rio_route_clr_table(struct rio_dev
*rdev
, u16 table
, int lock
)
1465 struct rio_switch_ops
*ops
= rdev
->rswitch
->ops
;
1468 rc
= rio_lock_device(rdev
->net
->hport
, rdev
->destid
,
1469 rdev
->hopcount
, 1000);
1474 spin_lock(&rdev
->rswitch
->lock
);
1476 if (ops
== NULL
|| ops
->clr_table
== NULL
) {
1477 rc
= rio_std_route_clr_table(rdev
->net
->hport
, rdev
->destid
,
1478 rdev
->hopcount
, table
);
1479 } else if (try_module_get(ops
->owner
)) {
1480 rc
= ops
->clr_table(rdev
->net
->hport
, rdev
->destid
,
1481 rdev
->hopcount
, table
);
1483 module_put(ops
->owner
);
1486 spin_unlock(&rdev
->rswitch
->lock
);
1489 rio_unlock_device(rdev
->net
->hport
, rdev
->destid
,
1494 EXPORT_SYMBOL_GPL(rio_route_clr_table
);
1496 #ifdef CONFIG_RAPIDIO_DMA_ENGINE
1498 static bool rio_chan_filter(struct dma_chan
*chan
, void *arg
)
1500 struct rio_dev
*rdev
= arg
;
1502 /* Check that DMA device belongs to the right MPORT */
1503 return (rdev
->net
->hport
==
1504 container_of(chan
->device
, struct rio_mport
, dma
));
1508 * rio_request_dma - request RapidIO capable DMA channel that supports
1509 * specified target RapidIO device.
1510 * @rdev: RIO device control structure
1512 * Returns pointer to allocated DMA channel or NULL if failed.
1514 struct dma_chan
*rio_request_dma(struct rio_dev
*rdev
)
1516 dma_cap_mask_t mask
;
1517 struct dma_chan
*dchan
;
1520 dma_cap_set(DMA_SLAVE
, mask
);
1521 dchan
= dma_request_channel(mask
, rio_chan_filter
, rdev
);
1525 EXPORT_SYMBOL_GPL(rio_request_dma
);
1528 * rio_release_dma - release specified DMA channel
1529 * @dchan: DMA channel to release
1531 void rio_release_dma(struct dma_chan
*dchan
)
1533 dma_release_channel(dchan
);
1535 EXPORT_SYMBOL_GPL(rio_release_dma
);
1538 * rio_dma_prep_slave_sg - RapidIO specific wrapper
1539 * for device_prep_slave_sg callback defined by DMAENGINE.
1540 * @rdev: RIO device control structure
1541 * @dchan: DMA channel to configure
1542 * @data: RIO specific data descriptor
1543 * @direction: DMA data transfer direction (TO or FROM the device)
1544 * @flags: dmaengine defined flags
1546 * Initializes RapidIO capable DMA channel for the specified data transfer.
1547 * Uses DMA channel private extension to pass information related to remote
1548 * target RIO device.
1549 * Returns pointer to DMA transaction descriptor or NULL if failed.
1551 struct dma_async_tx_descriptor
*rio_dma_prep_slave_sg(struct rio_dev
*rdev
,
1552 struct dma_chan
*dchan
, struct rio_dma_data
*data
,
1553 enum dma_transfer_direction direction
, unsigned long flags
)
1555 struct dma_async_tx_descriptor
*txd
= NULL
;
1556 struct rio_dma_ext rio_ext
;
1558 if (dchan
->device
->device_prep_slave_sg
== NULL
) {
1559 pr_err("%s: prep_rio_sg == NULL\n", __func__
);
1563 rio_ext
.destid
= rdev
->destid
;
1564 rio_ext
.rio_addr_u
= data
->rio_addr_u
;
1565 rio_ext
.rio_addr
= data
->rio_addr
;
1566 rio_ext
.wr_type
= data
->wr_type
;
1568 txd
= dmaengine_prep_rio_sg(dchan
, data
->sg
, data
->sg_len
,
1569 direction
, flags
, &rio_ext
);
1573 EXPORT_SYMBOL_GPL(rio_dma_prep_slave_sg
);
1575 #endif /* CONFIG_RAPIDIO_DMA_ENGINE */
1578 * rio_find_mport - find RIO mport by its ID
1579 * @mport_id: number (ID) of mport device
1581 * Given a RIO mport number, the desired mport is located
1582 * in the global list of mports. If the mport is found, a pointer to its
1583 * data structure is returned. If no mport is found, %NULL is returned.
1585 struct rio_mport
*rio_find_mport(int mport_id
)
1587 struct rio_mport
*port
;
1589 mutex_lock(&rio_mport_list_lock
);
1590 list_for_each_entry(port
, &rio_mports
, node
) {
1591 if (port
->id
== mport_id
)
1596 mutex_unlock(&rio_mport_list_lock
);
1602 * rio_register_scan - enumeration/discovery method registration interface
1603 * @mport_id: mport device ID for which fabric scan routine has to be set
1604 * (RIO_MPORT_ANY = set for all available mports)
1605 * @scan_ops: enumeration/discovery control structure
1607 * Assigns enumeration or discovery method to the specified mport device (or all
1608 * available mports if RIO_MPORT_ANY is specified).
1609 * Returns error if the mport already has an enumerator attached to it.
1610 * In case of RIO_MPORT_ANY ignores ports with valid scan routines and returns
1611 * an error if was unable to find at least one available mport.
1613 int rio_register_scan(int mport_id
, struct rio_scan
*scan_ops
)
1615 struct rio_mport
*port
;
1618 mutex_lock(&rio_mport_list_lock
);
1619 list_for_each_entry(port
, &rio_mports
, node
) {
1620 if (port
->id
== mport_id
|| mport_id
== RIO_MPORT_ANY
) {
1621 if (port
->nscan
&& mport_id
== RIO_MPORT_ANY
)
1623 else if (port
->nscan
)
1626 port
->nscan
= scan_ops
;
1629 if (mport_id
!= RIO_MPORT_ANY
)
1633 mutex_unlock(&rio_mport_list_lock
);
1637 EXPORT_SYMBOL_GPL(rio_register_scan
);
1640 * rio_unregister_scan - removes enumeration/discovery method from mport
1641 * @mport_id: mport device ID for which fabric scan routine has to be
1642 * unregistered (RIO_MPORT_ANY = set for all available mports)
1644 * Removes enumeration or discovery method assigned to the specified mport
1645 * device (or all available mports if RIO_MPORT_ANY is specified).
1647 int rio_unregister_scan(int mport_id
)
1649 struct rio_mport
*port
;
1651 mutex_lock(&rio_mport_list_lock
);
1652 list_for_each_entry(port
, &rio_mports
, node
) {
1653 if (port
->id
== mport_id
|| mport_id
== RIO_MPORT_ANY
) {
1656 if (mport_id
!= RIO_MPORT_ANY
)
1660 mutex_unlock(&rio_mport_list_lock
);
1664 EXPORT_SYMBOL_GPL(rio_unregister_scan
);
1666 static void rio_fixup_device(struct rio_dev
*dev
)
1670 static int rio_init(void)
1672 struct rio_dev
*dev
= NULL
;
1674 while ((dev
= rio_get_device(RIO_ANY_ID
, RIO_ANY_ID
, dev
)) != NULL
) {
1675 rio_fixup_device(dev
);
1680 static struct workqueue_struct
*rio_wq
;
1682 struct rio_disc_work
{
1683 struct work_struct work
;
1684 struct rio_mport
*mport
;
1687 static void disc_work_handler(struct work_struct
*_work
)
1689 struct rio_disc_work
*work
;
1691 work
= container_of(_work
, struct rio_disc_work
, work
);
1692 pr_debug("RIO: discovery work for mport %d %s\n",
1693 work
->mport
->id
, work
->mport
->name
);
1694 work
->mport
->nscan
->discover(work
->mport
, 0);
1697 int rio_init_mports(void)
1699 struct rio_mport
*port
;
1700 struct rio_disc_work
*work
;
1707 * First, run enumerations and check if we need to perform discovery
1708 * on any of the registered mports.
1710 mutex_lock(&rio_mport_list_lock
);
1711 list_for_each_entry(port
, &rio_mports
, node
) {
1712 if (port
->host_deviceid
>= 0) {
1714 port
->nscan
->enumerate(port
, 0);
1718 mutex_unlock(&rio_mport_list_lock
);
1724 * If we have mports that require discovery schedule a discovery work
1725 * for each of them. If the code below fails to allocate needed
1726 * resources, exit without error to keep results of enumeration
1728 * TODO: Implement restart of dicovery process for all or
1729 * individual discovering mports.
1731 rio_wq
= alloc_workqueue("riodisc", 0, 0);
1733 pr_err("RIO: unable allocate rio_wq\n");
1737 work
= kcalloc(n
, sizeof *work
, GFP_KERNEL
);
1739 pr_err("RIO: no memory for work struct\n");
1740 destroy_workqueue(rio_wq
);
1745 mutex_lock(&rio_mport_list_lock
);
1746 list_for_each_entry(port
, &rio_mports
, node
) {
1747 if (port
->host_deviceid
< 0 && port
->nscan
) {
1748 work
[n
].mport
= port
;
1749 INIT_WORK(&work
[n
].work
, disc_work_handler
);
1750 queue_work(rio_wq
, &work
[n
].work
);
1754 mutex_unlock(&rio_mport_list_lock
);
1756 flush_workqueue(rio_wq
);
1757 pr_debug("RIO: destroy discovery workqueue\n");
1758 destroy_workqueue(rio_wq
);
1767 static int hdids
[RIO_MAX_MPORTS
+ 1];
1769 static int rio_get_hdid(int index
)
1771 if (!hdids
[0] || hdids
[0] <= index
|| index
>= RIO_MAX_MPORTS
)
1774 return hdids
[index
+ 1];
1777 static int rio_hdid_setup(char *str
)
1779 (void)get_options(str
, ARRAY_SIZE(hdids
), hdids
);
1783 __setup("riohdid=", rio_hdid_setup
);
1785 int rio_register_mport(struct rio_mport
*port
)
1787 if (next_portid
>= RIO_MAX_MPORTS
) {
1788 pr_err("RIO: reached specified max number of mports\n");
1792 port
->id
= next_portid
++;
1793 port
->host_deviceid
= rio_get_hdid(port
->id
);
1795 mutex_lock(&rio_mport_list_lock
);
1796 list_add_tail(&port
->node
, &rio_mports
);
1797 mutex_unlock(&rio_mport_list_lock
);
1801 EXPORT_SYMBOL_GPL(rio_local_get_device_id
);
1802 EXPORT_SYMBOL_GPL(rio_get_device
);
1803 EXPORT_SYMBOL_GPL(rio_get_asm
);
1804 EXPORT_SYMBOL_GPL(rio_request_inb_dbell
);
1805 EXPORT_SYMBOL_GPL(rio_release_inb_dbell
);
1806 EXPORT_SYMBOL_GPL(rio_request_outb_dbell
);
1807 EXPORT_SYMBOL_GPL(rio_release_outb_dbell
);
1808 EXPORT_SYMBOL_GPL(rio_request_inb_mbox
);
1809 EXPORT_SYMBOL_GPL(rio_release_inb_mbox
);
1810 EXPORT_SYMBOL_GPL(rio_request_outb_mbox
);
1811 EXPORT_SYMBOL_GPL(rio_release_outb_mbox
);
1812 EXPORT_SYMBOL_GPL(rio_init_mports
);