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>
10 * - Added Port-Write/Error Management initialization and handling
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
18 #include <linux/types.h>
19 #include <linux/kernel.h>
21 #include <linux/delay.h>
22 #include <linux/init.h>
23 #include <linux/rio.h>
24 #include <linux/rio_drv.h>
25 #include <linux/rio_ids.h>
26 #include <linux/rio_regs.h>
27 #include <linux/module.h>
28 #include <linux/spinlock.h>
29 #include <linux/slab.h>
30 #include <linux/interrupt.h>
34 static LIST_HEAD(rio_mports
);
37 * rio_local_get_device_id - Get the base/extended device id for a port
38 * @port: RIO master port from which to get the deviceid
40 * Reads the base/extended device id from the local device
41 * implementing the master port. Returns the 8/16-bit device
44 u16
rio_local_get_device_id(struct rio_mport
*port
)
48 rio_local_read_config_32(port
, RIO_DID_CSR
, &result
);
50 return (RIO_GET_DID(port
->sys_size
, result
));
54 * rio_request_inb_mbox - request inbound mailbox service
55 * @mport: RIO master port from which to allocate the mailbox resource
56 * @dev_id: Device specific pointer to pass on event
57 * @mbox: Mailbox number to claim
58 * @entries: Number of entries in inbound mailbox queue
59 * @minb: Callback to execute when inbound message is received
61 * Requests ownership of an inbound mailbox resource and binds
62 * a callback function to the resource. Returns %0 on success.
64 int rio_request_inb_mbox(struct rio_mport
*mport
,
68 void (*minb
) (struct rio_mport
* mport
, void *dev_id
, int mbox
,
74 if (mport
->ops
->open_inb_mbox
== NULL
)
77 res
= kmalloc(sizeof(struct resource
), GFP_KERNEL
);
80 rio_init_mbox_res(res
, mbox
, mbox
);
82 /* Make sure this mailbox isn't in use */
84 request_resource(&mport
->riores
[RIO_INB_MBOX_RESOURCE
],
90 mport
->inb_msg
[mbox
].res
= res
;
92 /* Hook the inbound message callback */
93 mport
->inb_msg
[mbox
].mcback
= minb
;
95 rc
= mport
->ops
->open_inb_mbox(mport
, dev_id
, mbox
, entries
);
104 * rio_release_inb_mbox - release inbound mailbox message service
105 * @mport: RIO master port from which to release the mailbox resource
106 * @mbox: Mailbox number to release
108 * Releases ownership of an inbound mailbox resource. Returns 0
109 * if the request has been satisfied.
111 int rio_release_inb_mbox(struct rio_mport
*mport
, int mbox
)
113 if (mport
->ops
->close_inb_mbox
) {
114 mport
->ops
->close_inb_mbox(mport
, mbox
);
116 /* Release the mailbox resource */
117 return release_resource(mport
->inb_msg
[mbox
].res
);
123 * rio_request_outb_mbox - request outbound mailbox service
124 * @mport: RIO master port from which to allocate the mailbox resource
125 * @dev_id: Device specific pointer to pass on event
126 * @mbox: Mailbox number to claim
127 * @entries: Number of entries in outbound mailbox queue
128 * @moutb: Callback to execute when outbound message is sent
130 * Requests ownership of an outbound mailbox resource and binds
131 * a callback function to the resource. Returns 0 on success.
133 int rio_request_outb_mbox(struct rio_mport
*mport
,
137 void (*moutb
) (struct rio_mport
* mport
, void *dev_id
, int mbox
, int slot
))
140 struct resource
*res
;
142 if (mport
->ops
->open_outb_mbox
== NULL
)
145 res
= kmalloc(sizeof(struct resource
), GFP_KERNEL
);
148 rio_init_mbox_res(res
, mbox
, mbox
);
150 /* Make sure this outbound mailbox isn't in use */
152 request_resource(&mport
->riores
[RIO_OUTB_MBOX_RESOURCE
],
158 mport
->outb_msg
[mbox
].res
= res
;
160 /* Hook the inbound message callback */
161 mport
->outb_msg
[mbox
].mcback
= moutb
;
163 rc
= mport
->ops
->open_outb_mbox(mport
, dev_id
, mbox
, entries
);
172 * rio_release_outb_mbox - release outbound mailbox message service
173 * @mport: RIO master port from which to release the mailbox resource
174 * @mbox: Mailbox number to release
176 * Releases ownership of an inbound mailbox resource. Returns 0
177 * if the request has been satisfied.
179 int rio_release_outb_mbox(struct rio_mport
*mport
, int mbox
)
181 if (mport
->ops
->close_outb_mbox
) {
182 mport
->ops
->close_outb_mbox(mport
, mbox
);
184 /* Release the mailbox resource */
185 return release_resource(mport
->outb_msg
[mbox
].res
);
191 * rio_setup_inb_dbell - bind inbound doorbell callback
192 * @mport: RIO master port to bind the doorbell callback
193 * @dev_id: Device specific pointer to pass on event
194 * @res: Doorbell message resource
195 * @dinb: Callback to execute when doorbell is received
197 * Adds a doorbell resource/callback pair into a port's
198 * doorbell event list. Returns 0 if the request has been
202 rio_setup_inb_dbell(struct rio_mport
*mport
, void *dev_id
, struct resource
*res
,
203 void (*dinb
) (struct rio_mport
* mport
, void *dev_id
, u16 src
, u16 dst
,
207 struct rio_dbell
*dbell
;
209 if (!(dbell
= kmalloc(sizeof(struct rio_dbell
), GFP_KERNEL
))) {
216 dbell
->dev_id
= dev_id
;
218 list_add_tail(&dbell
->node
, &mport
->dbells
);
225 * rio_request_inb_dbell - request inbound doorbell message service
226 * @mport: RIO master port from which to allocate the doorbell resource
227 * @dev_id: Device specific pointer to pass on event
228 * @start: Doorbell info range start
229 * @end: Doorbell info range end
230 * @dinb: Callback to execute when doorbell is received
232 * Requests ownership of an inbound doorbell resource and binds
233 * a callback function to the resource. Returns 0 if the request
234 * has been satisfied.
236 int rio_request_inb_dbell(struct rio_mport
*mport
,
240 void (*dinb
) (struct rio_mport
* mport
, void *dev_id
, u16 src
,
245 struct resource
*res
= kmalloc(sizeof(struct resource
), GFP_KERNEL
);
248 rio_init_dbell_res(res
, start
, end
);
250 /* Make sure these doorbells aren't in use */
252 request_resource(&mport
->riores
[RIO_DOORBELL_RESOURCE
],
258 /* Hook the doorbell callback */
259 rc
= rio_setup_inb_dbell(mport
, dev_id
, res
, dinb
);
268 * rio_release_inb_dbell - release inbound doorbell message service
269 * @mport: RIO master port from which to release the doorbell resource
270 * @start: Doorbell info range start
271 * @end: Doorbell info range end
273 * Releases ownership of an inbound doorbell resource and removes
274 * callback from the doorbell event list. Returns 0 if the request
275 * has been satisfied.
277 int rio_release_inb_dbell(struct rio_mport
*mport
, u16 start
, u16 end
)
279 int rc
= 0, found
= 0;
280 struct rio_dbell
*dbell
;
282 list_for_each_entry(dbell
, &mport
->dbells
, node
) {
283 if ((dbell
->res
->start
== start
) && (dbell
->res
->end
== end
)) {
289 /* If we can't find an exact match, fail */
295 /* Delete from list */
296 list_del(&dbell
->node
);
298 /* Release the doorbell resource */
299 rc
= release_resource(dbell
->res
);
301 /* Free the doorbell event */
309 * rio_request_outb_dbell - request outbound doorbell message range
310 * @rdev: RIO device from which to allocate the doorbell resource
311 * @start: Doorbell message range start
312 * @end: Doorbell message range end
314 * Requests ownership of a doorbell message range. Returns a resource
315 * if the request has been satisfied or %NULL on failure.
317 struct resource
*rio_request_outb_dbell(struct rio_dev
*rdev
, u16 start
,
320 struct resource
*res
= kmalloc(sizeof(struct resource
), GFP_KERNEL
);
323 rio_init_dbell_res(res
, start
, end
);
325 /* Make sure these doorbells aren't in use */
326 if (request_resource(&rdev
->riores
[RIO_DOORBELL_RESOURCE
], res
)
337 * rio_release_outb_dbell - release outbound doorbell message range
338 * @rdev: RIO device from which to release the doorbell resource
339 * @res: Doorbell resource to be freed
341 * Releases ownership of a doorbell message range. Returns 0 if the
342 * request has been satisfied.
344 int rio_release_outb_dbell(struct rio_dev
*rdev
, struct resource
*res
)
346 int rc
= release_resource(res
);
354 * rio_request_inb_pwrite - request inbound port-write message service
355 * @rdev: RIO device to which register inbound port-write callback routine
356 * @pwcback: Callback routine to execute when port-write is received
358 * Binds a port-write callback function to the RapidIO device.
359 * Returns 0 if the request has been satisfied.
361 int rio_request_inb_pwrite(struct rio_dev
*rdev
,
362 int (*pwcback
)(struct rio_dev
*rdev
, union rio_pw_msg
*msg
, int step
))
366 spin_lock(&rio_global_list_lock
);
367 if (rdev
->pwcback
!= NULL
)
370 rdev
->pwcback
= pwcback
;
372 spin_unlock(&rio_global_list_lock
);
375 EXPORT_SYMBOL_GPL(rio_request_inb_pwrite
);
378 * rio_release_inb_pwrite - release inbound port-write message service
379 * @rdev: RIO device which registered for inbound port-write callback
381 * Removes callback from the rio_dev structure. Returns 0 if the request
382 * has been satisfied.
384 int rio_release_inb_pwrite(struct rio_dev
*rdev
)
388 spin_lock(&rio_global_list_lock
);
390 rdev
->pwcback
= NULL
;
394 spin_unlock(&rio_global_list_lock
);
397 EXPORT_SYMBOL_GPL(rio_release_inb_pwrite
);
400 * rio_mport_get_physefb - Helper function that returns register offset
401 * for Physical Layer Extended Features Block.
402 * @port: Master port to issue transaction
403 * @local: Indicate a local master port or remote device access
404 * @destid: Destination ID of the device
405 * @hopcount: Number of switch hops to the device
408 rio_mport_get_physefb(struct rio_mport
*port
, int local
,
409 u16 destid
, u8 hopcount
)
414 ext_ftr_ptr
= rio_mport_get_efb(port
, local
, destid
, hopcount
, 0);
416 while (ext_ftr_ptr
) {
418 rio_local_read_config_32(port
, ext_ftr_ptr
,
421 rio_mport_read_config_32(port
, destid
, hopcount
,
422 ext_ftr_ptr
, &ftr_header
);
424 ftr_header
= RIO_GET_BLOCK_ID(ftr_header
);
425 switch (ftr_header
) {
427 case RIO_EFB_SER_EP_ID_V13P
:
428 case RIO_EFB_SER_EP_REC_ID_V13P
:
429 case RIO_EFB_SER_EP_FREE_ID_V13P
:
430 case RIO_EFB_SER_EP_ID
:
431 case RIO_EFB_SER_EP_REC_ID
:
432 case RIO_EFB_SER_EP_FREE_ID
:
433 case RIO_EFB_SER_EP_FREC_ID
:
441 ext_ftr_ptr
= rio_mport_get_efb(port
, local
, destid
,
442 hopcount
, ext_ftr_ptr
);
449 * rio_get_comptag - Begin or continue searching for a RIO device by component tag
450 * @comp_tag: RIO component tag to match
451 * @from: Previous RIO device found in search, or %NULL for new search
453 * Iterates through the list of known RIO devices. If a RIO device is
454 * found with a matching @comp_tag, a pointer to its device
455 * structure is returned. Otherwise, %NULL is returned. A new search
456 * is initiated by passing %NULL to the @from argument. Otherwise, if
457 * @from is not %NULL, searches continue from next device on the global
460 struct rio_dev
*rio_get_comptag(u32 comp_tag
, struct rio_dev
*from
)
463 struct rio_dev
*rdev
;
465 spin_lock(&rio_global_list_lock
);
466 n
= from
? from
->global_list
.next
: rio_devices
.next
;
468 while (n
&& (n
!= &rio_devices
)) {
470 if (rdev
->comp_tag
== comp_tag
)
476 spin_unlock(&rio_global_list_lock
);
481 * rio_set_port_lockout - Sets/clears LOCKOUT bit (RIO EM 1.3) for a switch port.
482 * @rdev: Pointer to RIO device control structure
483 * @pnum: Switch port number to set LOCKOUT bit
484 * @lock: Operation : set (=1) or clear (=0)
486 int rio_set_port_lockout(struct rio_dev
*rdev
, u32 pnum
, int lock
)
490 rio_read_config_32(rdev
,
491 rdev
->phys_efptr
+ RIO_PORT_N_CTL_CSR(pnum
),
494 regval
|= RIO_PORT_N_CTL_LOCKOUT
;
496 regval
&= ~RIO_PORT_N_CTL_LOCKOUT
;
498 rio_write_config_32(rdev
,
499 rdev
->phys_efptr
+ RIO_PORT_N_CTL_CSR(pnum
),
505 * rio_chk_dev_route - Validate route to the specified device.
506 * @rdev: RIO device failed to respond
507 * @nrdev: Last active device on the route to rdev
508 * @npnum: nrdev's port number on the route to rdev
510 * Follows a route to the specified RIO device to determine the last available
511 * device (and corresponding RIO port) on the route.
514 rio_chk_dev_route(struct rio_dev
*rdev
, struct rio_dev
**nrdev
, int *npnum
)
517 int p_port
, rc
= -EIO
;
518 struct rio_dev
*prev
= NULL
;
520 /* Find switch with failed RIO link */
521 while (rdev
->prev
&& (rdev
->prev
->pef
& RIO_PEF_SWITCH
)) {
522 if (!rio_read_config_32(rdev
->prev
, RIO_DEV_ID_CAR
, &result
)) {
532 p_port
= prev
->rswitch
->route_table
[rdev
->destid
];
534 if (p_port
!= RIO_INVALID_ROUTE
) {
535 pr_debug("RIO: link failed on [%s]-P%d\n",
536 rio_name(prev
), p_port
);
541 pr_debug("RIO: failed to trace route to %s\n", rio_name(rdev
));
547 * rio_mport_chk_dev_access - Validate access to the specified device.
548 * @mport: Master port to send transactions
549 * @destid: Device destination ID in network
550 * @hopcount: Number of hops into the network
553 rio_mport_chk_dev_access(struct rio_mport
*mport
, u16 destid
, u8 hopcount
)
558 while (rio_mport_read_config_32(mport
, destid
, hopcount
,
559 RIO_DEV_ID_CAR
, &tmp
)) {
561 if (i
== RIO_MAX_CHK_RETRY
)
570 * rio_chk_dev_access - Validate access to the specified device.
571 * @rdev: Pointer to RIO device control structure
573 static int rio_chk_dev_access(struct rio_dev
*rdev
)
575 return rio_mport_chk_dev_access(rdev
->net
->hport
,
576 rdev
->destid
, rdev
->hopcount
);
580 * rio_get_input_status - Sends a Link-Request/Input-Status control symbol and
581 * returns link-response (if requested).
582 * @rdev: RIO devive to issue Input-status command
583 * @pnum: Device port number to issue the command
584 * @lnkresp: Response from a link partner
587 rio_get_input_status(struct rio_dev
*rdev
, int pnum
, u32
*lnkresp
)
593 /* Read from link maintenance response register
594 * to clear valid bit */
595 rio_read_config_32(rdev
,
596 rdev
->phys_efptr
+ RIO_PORT_N_MNT_RSP_CSR(pnum
),
601 /* Issue Input-status command */
602 rio_write_config_32(rdev
,
603 rdev
->phys_efptr
+ RIO_PORT_N_MNT_REQ_CSR(pnum
),
606 /* Exit if the response is not expected */
611 while (checkcount
--) {
613 rio_read_config_32(rdev
,
614 rdev
->phys_efptr
+ RIO_PORT_N_MNT_RSP_CSR(pnum
),
616 if (regval
& RIO_PORT_N_MNT_RSP_RVAL
) {
626 * rio_clr_err_stopped - Clears port Error-stopped states.
627 * @rdev: Pointer to RIO device control structure
628 * @pnum: Switch port number to clear errors
629 * @err_status: port error status (if 0 reads register from device)
631 static int rio_clr_err_stopped(struct rio_dev
*rdev
, u32 pnum
, u32 err_status
)
633 struct rio_dev
*nextdev
= rdev
->rswitch
->nextdev
[pnum
];
635 u32 far_ackid
, far_linkstat
, near_ackid
;
638 rio_read_config_32(rdev
,
639 rdev
->phys_efptr
+ RIO_PORT_N_ERR_STS_CSR(pnum
),
642 if (err_status
& RIO_PORT_N_ERR_STS_PW_OUT_ES
) {
643 pr_debug("RIO_EM: servicing Output Error-Stopped state\n");
645 * Send a Link-Request/Input-Status control symbol
647 if (rio_get_input_status(rdev
, pnum
, ®val
)) {
648 pr_debug("RIO_EM: Input-status response timeout\n");
652 pr_debug("RIO_EM: SP%d Input-status response=0x%08x\n",
654 far_ackid
= (regval
& RIO_PORT_N_MNT_RSP_ASTAT
) >> 5;
655 far_linkstat
= regval
& RIO_PORT_N_MNT_RSP_LSTAT
;
656 rio_read_config_32(rdev
,
657 rdev
->phys_efptr
+ RIO_PORT_N_ACK_STS_CSR(pnum
),
659 pr_debug("RIO_EM: SP%d_ACK_STS_CSR=0x%08x\n", pnum
, regval
);
660 near_ackid
= (regval
& RIO_PORT_N_ACK_INBOUND
) >> 24;
661 pr_debug("RIO_EM: SP%d far_ackID=0x%02x far_linkstat=0x%02x" \
662 " near_ackID=0x%02x\n",
663 pnum
, far_ackid
, far_linkstat
, near_ackid
);
666 * If required, synchronize ackIDs of near and
669 if ((far_ackid
!= ((regval
& RIO_PORT_N_ACK_OUTSTAND
) >> 8)) ||
670 (far_ackid
!= (regval
& RIO_PORT_N_ACK_OUTBOUND
))) {
671 /* Align near outstanding/outbound ackIDs with
674 rio_write_config_32(rdev
,
675 rdev
->phys_efptr
+ RIO_PORT_N_ACK_STS_CSR(pnum
),
677 (far_ackid
<< 8) | far_ackid
);
678 /* Align far outstanding/outbound ackIDs with
683 rio_write_config_32(nextdev
,
684 nextdev
->phys_efptr
+
685 RIO_PORT_N_ACK_STS_CSR(RIO_GET_PORT_NUM(nextdev
->swpinfo
)),
687 (near_ackid
<< 8) | near_ackid
);
689 pr_debug("RIO_EM: Invalid nextdev pointer (NULL)\n");
692 rio_read_config_32(rdev
,
693 rdev
->phys_efptr
+ RIO_PORT_N_ERR_STS_CSR(pnum
),
695 pr_debug("RIO_EM: SP%d_ERR_STS_CSR=0x%08x\n", pnum
, err_status
);
698 if ((err_status
& RIO_PORT_N_ERR_STS_PW_INP_ES
) && nextdev
) {
699 pr_debug("RIO_EM: servicing Input Error-Stopped state\n");
700 rio_get_input_status(nextdev
,
701 RIO_GET_PORT_NUM(nextdev
->swpinfo
), NULL
);
704 rio_read_config_32(rdev
,
705 rdev
->phys_efptr
+ RIO_PORT_N_ERR_STS_CSR(pnum
),
707 pr_debug("RIO_EM: SP%d_ERR_STS_CSR=0x%08x\n", pnum
, err_status
);
710 return (err_status
& (RIO_PORT_N_ERR_STS_PW_OUT_ES
|
711 RIO_PORT_N_ERR_STS_PW_INP_ES
)) ? 1 : 0;
715 * rio_inb_pwrite_handler - process inbound port-write message
716 * @pw_msg: pointer to inbound port-write message
718 * Processes an inbound port-write message. Returns 0 if the request
719 * has been satisfied.
721 int rio_inb_pwrite_handler(union rio_pw_msg
*pw_msg
)
723 struct rio_dev
*rdev
;
724 u32 err_status
, em_perrdet
, em_ltlerrdet
;
727 rdev
= rio_get_comptag((pw_msg
->em
.comptag
& RIO_CTAG_UDEVID
), NULL
);
729 /* Device removed or enumeration error */
730 pr_debug("RIO: %s No matching device for CTag 0x%08x\n",
731 __func__
, pw_msg
->em
.comptag
);
735 pr_debug("RIO: Port-Write message from %s\n", rio_name(rdev
));
740 for (i
= 0; i
< RIO_PW_MSG_SIZE
/sizeof(u32
);) {
741 pr_debug("0x%02x: %08x %08x %08x %08x\n",
742 i
*4, pw_msg
->raw
[i
], pw_msg
->raw
[i
+ 1],
743 pw_msg
->raw
[i
+ 2], pw_msg
->raw
[i
+ 3]);
749 /* Call an external service function (if such is registered
750 * for this device). This may be the service for endpoints that send
751 * device-specific port-write messages. End-point messages expected
752 * to be handled completely by EP specific device driver.
753 * For switches rc==0 signals that no standard processing required.
755 if (rdev
->pwcback
!= NULL
) {
756 rc
= rdev
->pwcback(rdev
, pw_msg
, 0);
761 portnum
= pw_msg
->em
.is_port
& 0xFF;
763 /* Check if device and route to it are functional:
764 * Sometimes devices may send PW message(s) just before being
765 * powered down (or link being lost).
767 if (rio_chk_dev_access(rdev
)) {
768 pr_debug("RIO: device access failed - get link partner\n");
769 /* Scan route to the device and identify failed link.
770 * This will replace device and port reported in PW message.
771 * PW message should not be used after this point.
773 if (rio_chk_dev_route(rdev
, &rdev
, &portnum
)) {
774 pr_err("RIO: Route trace for %s failed\n",
781 /* For End-point devices processing stops here */
782 if (!(rdev
->pef
& RIO_PEF_SWITCH
))
785 if (rdev
->phys_efptr
== 0) {
786 pr_err("RIO_PW: Bad switch initialization for %s\n",
792 * Process the port-write notification from switch
794 if (rdev
->rswitch
->em_handle
)
795 rdev
->rswitch
->em_handle(rdev
, portnum
);
797 rio_read_config_32(rdev
,
798 rdev
->phys_efptr
+ RIO_PORT_N_ERR_STS_CSR(portnum
),
800 pr_debug("RIO_PW: SP%d_ERR_STS_CSR=0x%08x\n", portnum
, err_status
);
802 if (err_status
& RIO_PORT_N_ERR_STS_PORT_OK
) {
804 if (!(rdev
->rswitch
->port_ok
& (1 << portnum
))) {
805 rdev
->rswitch
->port_ok
|= (1 << portnum
);
806 rio_set_port_lockout(rdev
, portnum
, 0);
807 /* Schedule Insertion Service */
808 pr_debug("RIO_PW: Device Insertion on [%s]-P%d\n",
809 rio_name(rdev
), portnum
);
812 /* Clear error-stopped states (if reported).
813 * Depending on the link partner state, two attempts
814 * may be needed for successful recovery.
816 if (err_status
& (RIO_PORT_N_ERR_STS_PW_OUT_ES
|
817 RIO_PORT_N_ERR_STS_PW_INP_ES
)) {
818 if (rio_clr_err_stopped(rdev
, portnum
, err_status
))
819 rio_clr_err_stopped(rdev
, portnum
, 0);
821 } else { /* if (err_status & RIO_PORT_N_ERR_STS_PORT_UNINIT) */
823 if (rdev
->rswitch
->port_ok
& (1 << portnum
)) {
824 rdev
->rswitch
->port_ok
&= ~(1 << portnum
);
825 rio_set_port_lockout(rdev
, portnum
, 1);
827 rio_write_config_32(rdev
,
829 RIO_PORT_N_ACK_STS_CSR(portnum
),
830 RIO_PORT_N_ACK_CLEAR
);
832 /* Schedule Extraction Service */
833 pr_debug("RIO_PW: Device Extraction on [%s]-P%d\n",
834 rio_name(rdev
), portnum
);
838 rio_read_config_32(rdev
,
839 rdev
->em_efptr
+ RIO_EM_PN_ERR_DETECT(portnum
), &em_perrdet
);
841 pr_debug("RIO_PW: RIO_EM_P%d_ERR_DETECT=0x%08x\n",
842 portnum
, em_perrdet
);
843 /* Clear EM Port N Error Detect CSR */
844 rio_write_config_32(rdev
,
845 rdev
->em_efptr
+ RIO_EM_PN_ERR_DETECT(portnum
), 0);
848 rio_read_config_32(rdev
,
849 rdev
->em_efptr
+ RIO_EM_LTL_ERR_DETECT
, &em_ltlerrdet
);
851 pr_debug("RIO_PW: RIO_EM_LTL_ERR_DETECT=0x%08x\n",
853 /* Clear EM L/T Layer Error Detect CSR */
854 rio_write_config_32(rdev
,
855 rdev
->em_efptr
+ RIO_EM_LTL_ERR_DETECT
, 0);
858 /* Clear remaining error bits and Port-Write Pending bit */
859 rio_write_config_32(rdev
,
860 rdev
->phys_efptr
+ RIO_PORT_N_ERR_STS_CSR(portnum
),
865 EXPORT_SYMBOL_GPL(rio_inb_pwrite_handler
);
868 * rio_mport_get_efb - get pointer to next extended features block
869 * @port: Master port to issue transaction
870 * @local: Indicate a local master port or remote device access
871 * @destid: Destination ID of the device
872 * @hopcount: Number of switch hops to the device
873 * @from: Offset of current Extended Feature block header (if 0 starts
874 * from ExtFeaturePtr)
877 rio_mport_get_efb(struct rio_mport
*port
, int local
, u16 destid
,
878 u8 hopcount
, u32 from
)
884 rio_local_read_config_32(port
, RIO_ASM_INFO_CAR
,
887 rio_mport_read_config_32(port
, destid
, hopcount
,
888 RIO_ASM_INFO_CAR
, ®_val
);
889 return reg_val
& RIO_EXT_FTR_PTR_MASK
;
892 rio_local_read_config_32(port
, from
, ®_val
);
894 rio_mport_read_config_32(port
, destid
, hopcount
,
896 return RIO_GET_BLOCK_ID(reg_val
);
901 * rio_mport_get_feature - query for devices' extended features
902 * @port: Master port to issue transaction
903 * @local: Indicate a local master port or remote device access
904 * @destid: Destination ID of the device
905 * @hopcount: Number of switch hops to the device
906 * @ftr: Extended feature code
908 * Tell if a device supports a given RapidIO capability.
909 * Returns the offset of the requested extended feature
910 * block within the device's RIO configuration space or
911 * 0 in case the device does not support it. Possible
914 * %RIO_EFB_PAR_EP_ID LP/LVDS EP Devices
916 * %RIO_EFB_PAR_EP_REC_ID LP/LVDS EP Recovery Devices
918 * %RIO_EFB_PAR_EP_FREE_ID LP/LVDS EP Free Devices
920 * %RIO_EFB_SER_EP_ID LP/Serial EP Devices
922 * %RIO_EFB_SER_EP_REC_ID LP/Serial EP Recovery Devices
924 * %RIO_EFB_SER_EP_FREE_ID LP/Serial EP Free Devices
927 rio_mport_get_feature(struct rio_mport
* port
, int local
, u16 destid
,
928 u8 hopcount
, int ftr
)
930 u32 asm_info
, ext_ftr_ptr
, ftr_header
;
933 rio_local_read_config_32(port
, RIO_ASM_INFO_CAR
, &asm_info
);
935 rio_mport_read_config_32(port
, destid
, hopcount
,
936 RIO_ASM_INFO_CAR
, &asm_info
);
938 ext_ftr_ptr
= asm_info
& RIO_EXT_FTR_PTR_MASK
;
940 while (ext_ftr_ptr
) {
942 rio_local_read_config_32(port
, ext_ftr_ptr
,
945 rio_mport_read_config_32(port
, destid
, hopcount
,
946 ext_ftr_ptr
, &ftr_header
);
947 if (RIO_GET_BLOCK_ID(ftr_header
) == ftr
)
949 if (!(ext_ftr_ptr
= RIO_GET_BLOCK_PTR(ftr_header
)))
957 * rio_get_asm - Begin or continue searching for a RIO device by vid/did/asm_vid/asm_did
958 * @vid: RIO vid to match or %RIO_ANY_ID to match all vids
959 * @did: RIO did to match or %RIO_ANY_ID to match all dids
960 * @asm_vid: RIO asm_vid to match or %RIO_ANY_ID to match all asm_vids
961 * @asm_did: RIO asm_did to match or %RIO_ANY_ID to match all asm_dids
962 * @from: Previous RIO device found in search, or %NULL for new search
964 * Iterates through the list of known RIO devices. If a RIO device is
965 * found with a matching @vid, @did, @asm_vid, @asm_did, the reference
966 * count to the device is incrememted and a pointer to its device
967 * structure is returned. Otherwise, %NULL is returned. A new search
968 * is initiated by passing %NULL to the @from argument. Otherwise, if
969 * @from is not %NULL, searches continue from next device on the global
970 * list. The reference count for @from is always decremented if it is
973 struct rio_dev
*rio_get_asm(u16 vid
, u16 did
,
974 u16 asm_vid
, u16 asm_did
, struct rio_dev
*from
)
977 struct rio_dev
*rdev
;
979 WARN_ON(in_interrupt());
980 spin_lock(&rio_global_list_lock
);
981 n
= from
? from
->global_list
.next
: rio_devices
.next
;
983 while (n
&& (n
!= &rio_devices
)) {
985 if ((vid
== RIO_ANY_ID
|| rdev
->vid
== vid
) &&
986 (did
== RIO_ANY_ID
|| rdev
->did
== did
) &&
987 (asm_vid
== RIO_ANY_ID
|| rdev
->asm_vid
== asm_vid
) &&
988 (asm_did
== RIO_ANY_ID
|| rdev
->asm_did
== asm_did
))
995 rdev
= rio_dev_get(rdev
);
996 spin_unlock(&rio_global_list_lock
);
1001 * rio_get_device - Begin or continue searching for a RIO device by vid/did
1002 * @vid: RIO vid to match or %RIO_ANY_ID to match all vids
1003 * @did: RIO did to match or %RIO_ANY_ID to match all dids
1004 * @from: Previous RIO device found in search, or %NULL for new search
1006 * Iterates through the list of known RIO devices. If a RIO device is
1007 * found with a matching @vid and @did, the reference count to the
1008 * device is incrememted and a pointer to its device structure is returned.
1009 * Otherwise, %NULL is returned. A new search is initiated by passing %NULL
1010 * to the @from argument. Otherwise, if @from is not %NULL, searches
1011 * continue from next device on the global list. The reference count for
1012 * @from is always decremented if it is not %NULL.
1014 struct rio_dev
*rio_get_device(u16 vid
, u16 did
, struct rio_dev
*from
)
1016 return rio_get_asm(vid
, did
, RIO_ANY_ID
, RIO_ANY_ID
, from
);
1020 * rio_std_route_add_entry - Add switch route table entry using standard
1021 * registers defined in RIO specification rev.1.3
1022 * @mport: Master port to issue transaction
1023 * @destid: Destination ID of the device
1024 * @hopcount: Number of switch hops to the device
1025 * @table: routing table ID (global or port-specific)
1026 * @route_destid: destID entry in the RT
1027 * @route_port: destination port for specified destID
1029 int rio_std_route_add_entry(struct rio_mport
*mport
, u16 destid
, u8 hopcount
,
1030 u16 table
, u16 route_destid
, u8 route_port
)
1032 if (table
== RIO_GLOBAL_TABLE
) {
1033 rio_mport_write_config_32(mport
, destid
, hopcount
,
1034 RIO_STD_RTE_CONF_DESTID_SEL_CSR
,
1036 rio_mport_write_config_32(mport
, destid
, hopcount
,
1037 RIO_STD_RTE_CONF_PORT_SEL_CSR
,
1046 * rio_std_route_get_entry - Read switch route table entry (port number)
1047 * associated with specified destID using standard registers defined in RIO
1048 * specification rev.1.3
1049 * @mport: Master port to issue transaction
1050 * @destid: Destination ID of the device
1051 * @hopcount: Number of switch hops to the device
1052 * @table: routing table ID (global or port-specific)
1053 * @route_destid: destID entry in the RT
1054 * @route_port: returned destination port for specified destID
1056 int rio_std_route_get_entry(struct rio_mport
*mport
, u16 destid
, u8 hopcount
,
1057 u16 table
, u16 route_destid
, u8
*route_port
)
1061 if (table
== RIO_GLOBAL_TABLE
) {
1062 rio_mport_write_config_32(mport
, destid
, hopcount
,
1063 RIO_STD_RTE_CONF_DESTID_SEL_CSR
, route_destid
);
1064 rio_mport_read_config_32(mport
, destid
, hopcount
,
1065 RIO_STD_RTE_CONF_PORT_SEL_CSR
, &result
);
1067 *route_port
= (u8
)result
;
1074 * rio_std_route_clr_table - Clear swotch route table using standard registers
1075 * defined in RIO specification rev.1.3.
1076 * @mport: Master port to issue transaction
1077 * @destid: Destination ID of the device
1078 * @hopcount: Number of switch hops to the device
1079 * @table: routing table ID (global or port-specific)
1081 int rio_std_route_clr_table(struct rio_mport
*mport
, u16 destid
, u8 hopcount
,
1084 u32 max_destid
= 0xff;
1085 u32 i
, pef
, id_inc
= 1, ext_cfg
= 0;
1086 u32 port_sel
= RIO_INVALID_ROUTE
;
1088 if (table
== RIO_GLOBAL_TABLE
) {
1089 rio_mport_read_config_32(mport
, destid
, hopcount
,
1092 if (mport
->sys_size
) {
1093 rio_mport_read_config_32(mport
, destid
, hopcount
,
1094 RIO_SWITCH_RT_LIMIT
,
1096 max_destid
&= RIO_RT_MAX_DESTID
;
1099 if (pef
& RIO_PEF_EXT_RT
) {
1100 ext_cfg
= 0x80000000;
1102 port_sel
= (RIO_INVALID_ROUTE
<< 24) |
1103 (RIO_INVALID_ROUTE
<< 16) |
1104 (RIO_INVALID_ROUTE
<< 8) |
1108 for (i
= 0; i
<= max_destid
;) {
1109 rio_mport_write_config_32(mport
, destid
, hopcount
,
1110 RIO_STD_RTE_CONF_DESTID_SEL_CSR
,
1112 rio_mport_write_config_32(mport
, destid
, hopcount
,
1113 RIO_STD_RTE_CONF_PORT_SEL_CSR
,
1123 static void rio_fixup_device(struct rio_dev
*dev
)
1127 static int __devinit
rio_init(void)
1129 struct rio_dev
*dev
= NULL
;
1131 while ((dev
= rio_get_device(RIO_ANY_ID
, RIO_ANY_ID
, dev
)) != NULL
) {
1132 rio_fixup_device(dev
);
1137 device_initcall(rio_init
);
1139 int __devinit
rio_init_mports(void)
1142 struct rio_mport
*port
;
1144 list_for_each_entry(port
, &rio_mports
, node
) {
1145 if (!request_mem_region(port
->iores
.start
,
1146 resource_size(&port
->iores
),
1149 "RIO: Error requesting master port region 0x%016llx-0x%016llx\n",
1150 (u64
)port
->iores
.start
, (u64
)port
->iores
.end
);
1155 if (port
->host_deviceid
>= 0)
1156 rio_enum_mport(port
);
1158 rio_disc_mport(port
);
1165 void rio_register_mport(struct rio_mport
*port
)
1167 list_add_tail(&port
->node
, &rio_mports
);
1170 EXPORT_SYMBOL_GPL(rio_local_get_device_id
);
1171 EXPORT_SYMBOL_GPL(rio_get_device
);
1172 EXPORT_SYMBOL_GPL(rio_get_asm
);
1173 EXPORT_SYMBOL_GPL(rio_request_inb_dbell
);
1174 EXPORT_SYMBOL_GPL(rio_release_inb_dbell
);
1175 EXPORT_SYMBOL_GPL(rio_request_outb_dbell
);
1176 EXPORT_SYMBOL_GPL(rio_release_outb_dbell
);
1177 EXPORT_SYMBOL_GPL(rio_request_inb_mbox
);
1178 EXPORT_SYMBOL_GPL(rio_release_inb_mbox
);
1179 EXPORT_SYMBOL_GPL(rio_request_outb_mbox
);
1180 EXPORT_SYMBOL_GPL(rio_release_outb_mbox
);