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
,
73 struct resource
*res
= kmalloc(sizeof(struct resource
), GFP_KERNEL
);
76 rio_init_mbox_res(res
, mbox
, mbox
);
78 /* Make sure this mailbox isn't in use */
80 request_resource(&mport
->riores
[RIO_INB_MBOX_RESOURCE
],
86 mport
->inb_msg
[mbox
].res
= res
;
88 /* Hook the inbound message callback */
89 mport
->inb_msg
[mbox
].mcback
= minb
;
91 rc
= rio_open_inb_mbox(mport
, dev_id
, mbox
, entries
);
100 * rio_release_inb_mbox - release inbound mailbox message service
101 * @mport: RIO master port from which to release the mailbox resource
102 * @mbox: Mailbox number to release
104 * Releases ownership of an inbound mailbox resource. Returns 0
105 * if the request has been satisfied.
107 int rio_release_inb_mbox(struct rio_mport
*mport
, int mbox
)
109 rio_close_inb_mbox(mport
, mbox
);
111 /* Release the mailbox resource */
112 return release_resource(mport
->inb_msg
[mbox
].res
);
116 * rio_request_outb_mbox - request outbound mailbox service
117 * @mport: RIO master port from which to allocate the mailbox resource
118 * @dev_id: Device specific pointer to pass on event
119 * @mbox: Mailbox number to claim
120 * @entries: Number of entries in outbound mailbox queue
121 * @moutb: Callback to execute when outbound message is sent
123 * Requests ownership of an outbound mailbox resource and binds
124 * a callback function to the resource. Returns 0 on success.
126 int rio_request_outb_mbox(struct rio_mport
*mport
,
130 void (*moutb
) (struct rio_mport
* mport
, void *dev_id
, int mbox
, int slot
))
134 struct resource
*res
= kmalloc(sizeof(struct resource
), GFP_KERNEL
);
137 rio_init_mbox_res(res
, mbox
, mbox
);
139 /* Make sure this outbound mailbox isn't in use */
141 request_resource(&mport
->riores
[RIO_OUTB_MBOX_RESOURCE
],
147 mport
->outb_msg
[mbox
].res
= res
;
149 /* Hook the inbound message callback */
150 mport
->outb_msg
[mbox
].mcback
= moutb
;
152 rc
= rio_open_outb_mbox(mport
, dev_id
, mbox
, entries
);
161 * rio_release_outb_mbox - release outbound mailbox message service
162 * @mport: RIO master port from which to release the mailbox resource
163 * @mbox: Mailbox number to release
165 * Releases ownership of an inbound mailbox resource. Returns 0
166 * if the request has been satisfied.
168 int rio_release_outb_mbox(struct rio_mport
*mport
, int mbox
)
170 rio_close_outb_mbox(mport
, mbox
);
172 /* Release the mailbox resource */
173 return release_resource(mport
->outb_msg
[mbox
].res
);
177 * rio_setup_inb_dbell - bind inbound doorbell callback
178 * @mport: RIO master port to bind the doorbell callback
179 * @dev_id: Device specific pointer to pass on event
180 * @res: Doorbell message resource
181 * @dinb: Callback to execute when doorbell is received
183 * Adds a doorbell resource/callback pair into a port's
184 * doorbell event list. Returns 0 if the request has been
188 rio_setup_inb_dbell(struct rio_mport
*mport
, void *dev_id
, struct resource
*res
,
189 void (*dinb
) (struct rio_mport
* mport
, void *dev_id
, u16 src
, u16 dst
,
193 struct rio_dbell
*dbell
;
195 if (!(dbell
= kmalloc(sizeof(struct rio_dbell
), GFP_KERNEL
))) {
202 dbell
->dev_id
= dev_id
;
204 list_add_tail(&dbell
->node
, &mport
->dbells
);
211 * rio_request_inb_dbell - request inbound doorbell message service
212 * @mport: RIO master port from which to allocate the doorbell resource
213 * @dev_id: Device specific pointer to pass on event
214 * @start: Doorbell info range start
215 * @end: Doorbell info range end
216 * @dinb: Callback to execute when doorbell is received
218 * Requests ownership of an inbound doorbell resource and binds
219 * a callback function to the resource. Returns 0 if the request
220 * has been satisfied.
222 int rio_request_inb_dbell(struct rio_mport
*mport
,
226 void (*dinb
) (struct rio_mport
* mport
, void *dev_id
, u16 src
,
231 struct resource
*res
= kmalloc(sizeof(struct resource
), GFP_KERNEL
);
234 rio_init_dbell_res(res
, start
, end
);
236 /* Make sure these doorbells aren't in use */
238 request_resource(&mport
->riores
[RIO_DOORBELL_RESOURCE
],
244 /* Hook the doorbell callback */
245 rc
= rio_setup_inb_dbell(mport
, dev_id
, res
, dinb
);
254 * rio_release_inb_dbell - release inbound doorbell message service
255 * @mport: RIO master port from which to release the doorbell resource
256 * @start: Doorbell info range start
257 * @end: Doorbell info range end
259 * Releases ownership of an inbound doorbell resource and removes
260 * callback from the doorbell event list. Returns 0 if the request
261 * has been satisfied.
263 int rio_release_inb_dbell(struct rio_mport
*mport
, u16 start
, u16 end
)
265 int rc
= 0, found
= 0;
266 struct rio_dbell
*dbell
;
268 list_for_each_entry(dbell
, &mport
->dbells
, node
) {
269 if ((dbell
->res
->start
== start
) && (dbell
->res
->end
== end
)) {
275 /* If we can't find an exact match, fail */
281 /* Delete from list */
282 list_del(&dbell
->node
);
284 /* Release the doorbell resource */
285 rc
= release_resource(dbell
->res
);
287 /* Free the doorbell event */
295 * rio_request_outb_dbell - request outbound doorbell message range
296 * @rdev: RIO device from which to allocate the doorbell resource
297 * @start: Doorbell message range start
298 * @end: Doorbell message range end
300 * Requests ownership of a doorbell message range. Returns a resource
301 * if the request has been satisfied or %NULL on failure.
303 struct resource
*rio_request_outb_dbell(struct rio_dev
*rdev
, u16 start
,
306 struct resource
*res
= kmalloc(sizeof(struct resource
), GFP_KERNEL
);
309 rio_init_dbell_res(res
, start
, end
);
311 /* Make sure these doorbells aren't in use */
312 if (request_resource(&rdev
->riores
[RIO_DOORBELL_RESOURCE
], res
)
323 * rio_release_outb_dbell - release outbound doorbell message range
324 * @rdev: RIO device from which to release the doorbell resource
325 * @res: Doorbell resource to be freed
327 * Releases ownership of a doorbell message range. Returns 0 if the
328 * request has been satisfied.
330 int rio_release_outb_dbell(struct rio_dev
*rdev
, struct resource
*res
)
332 int rc
= release_resource(res
);
340 * rio_request_inb_pwrite - request inbound port-write message service
341 * @mport: RIO device to which register inbound port-write callback routine
342 * @pwcback: Callback routine to execute when port-write is received
344 * Binds a port-write callback function to the RapidIO device.
345 * Returns 0 if the request has been satisfied.
347 int rio_request_inb_pwrite(struct rio_dev
*rdev
,
348 int (*pwcback
)(struct rio_dev
*rdev
, union rio_pw_msg
*msg
, int step
))
352 spin_lock(&rio_global_list_lock
);
353 if (rdev
->pwcback
!= NULL
)
356 rdev
->pwcback
= pwcback
;
358 spin_unlock(&rio_global_list_lock
);
361 EXPORT_SYMBOL_GPL(rio_request_inb_pwrite
);
364 * rio_release_inb_pwrite - release inbound port-write message service
365 * @rdev: RIO device which registered for inbound port-write callback
367 * Removes callback from the rio_dev structure. Returns 0 if the request
368 * has been satisfied.
370 int rio_release_inb_pwrite(struct rio_dev
*rdev
)
374 spin_lock(&rio_global_list_lock
);
376 rdev
->pwcback
= NULL
;
380 spin_unlock(&rio_global_list_lock
);
383 EXPORT_SYMBOL_GPL(rio_release_inb_pwrite
);
386 * rio_mport_get_physefb - Helper function that returns register offset
387 * for Physical Layer Extended Features Block.
391 rio_mport_get_physefb(struct rio_mport
*port
, int local
,
392 u16 destid
, u8 hopcount
)
397 ext_ftr_ptr
= rio_mport_get_efb(port
, local
, destid
, hopcount
, 0);
399 while (ext_ftr_ptr
) {
401 rio_local_read_config_32(port
, ext_ftr_ptr
,
404 rio_mport_read_config_32(port
, destid
, hopcount
,
405 ext_ftr_ptr
, &ftr_header
);
407 ftr_header
= RIO_GET_BLOCK_ID(ftr_header
);
408 switch (ftr_header
) {
410 case RIO_EFB_SER_EP_ID_V13P
:
411 case RIO_EFB_SER_EP_REC_ID_V13P
:
412 case RIO_EFB_SER_EP_FREE_ID_V13P
:
413 case RIO_EFB_SER_EP_ID
:
414 case RIO_EFB_SER_EP_REC_ID
:
415 case RIO_EFB_SER_EP_FREE_ID
:
416 case RIO_EFB_SER_EP_FREC_ID
:
424 ext_ftr_ptr
= rio_mport_get_efb(port
, local
, destid
,
425 hopcount
, ext_ftr_ptr
);
432 * rio_get_comptag - Begin or continue searching for a RIO device by component tag
433 * @comp_tag: RIO component tad to match
434 * @from: Previous RIO device found in search, or %NULL for new search
436 * Iterates through the list of known RIO devices. If a RIO device is
437 * found with a matching @comp_tag, a pointer to its device
438 * structure is returned. Otherwise, %NULL is returned. A new search
439 * is initiated by passing %NULL to the @from argument. Otherwise, if
440 * @from is not %NULL, searches continue from next device on the global
443 static struct rio_dev
*rio_get_comptag(u32 comp_tag
, struct rio_dev
*from
)
446 struct rio_dev
*rdev
;
448 WARN_ON(in_interrupt());
449 spin_lock(&rio_global_list_lock
);
450 n
= from
? from
->global_list
.next
: rio_devices
.next
;
452 while (n
&& (n
!= &rio_devices
)) {
454 if (rdev
->comp_tag
== comp_tag
)
460 spin_unlock(&rio_global_list_lock
);
465 * rio_set_port_lockout - Sets/clears LOCKOUT bit (RIO EM 1.3) for a switch port.
466 * @rdev: Pointer to RIO device control structure
467 * @pnum: Switch port number to set LOCKOUT bit
468 * @lock: Operation : set (=1) or clear (=0)
470 int rio_set_port_lockout(struct rio_dev
*rdev
, u32 pnum
, int lock
)
473 u16 destid
= rdev
->destid
;
477 destid
= rdev
->rswitch
->destid
;
478 hopcount
= rdev
->rswitch
->hopcount
;
481 rio_mport_read_config_32(rdev
->net
->hport
, destid
, hopcount
,
482 rdev
->phys_efptr
+ RIO_PORT_N_CTL_CSR(pnum
),
485 regval
|= RIO_PORT_N_CTL_LOCKOUT
;
487 regval
&= ~RIO_PORT_N_CTL_LOCKOUT
;
489 rio_mport_write_config_32(rdev
->net
->hport
, destid
, hopcount
,
490 rdev
->phys_efptr
+ RIO_PORT_N_CTL_CSR(pnum
),
496 * rio_inb_pwrite_handler - process inbound port-write message
497 * @pw_msg: pointer to inbound port-write message
499 * Processes an inbound port-write message. Returns 0 if the request
500 * has been satisfied.
502 int rio_inb_pwrite_handler(union rio_pw_msg
*pw_msg
)
504 struct rio_dev
*rdev
;
505 struct rio_mport
*mport
;
511 rdev
= rio_get_comptag(pw_msg
->em
.comptag
, NULL
);
513 /* Someting bad here (probably enumeration error) */
514 pr_err("RIO: %s No matching device for CTag 0x%08x\n",
515 __func__
, pw_msg
->em
.comptag
);
519 pr_debug("RIO: Port-Write message from %s\n", rio_name(rdev
));
524 for (i
= 0; i
< RIO_PW_MSG_SIZE
/sizeof(u32
);) {
525 pr_debug("0x%02x: %08x %08x %08x %08x",
526 i
*4, pw_msg
->raw
[i
], pw_msg
->raw
[i
+ 1],
527 pw_msg
->raw
[i
+ 2], pw_msg
->raw
[i
+ 3]);
534 /* Call an external service function (if such is registered
535 * for this device). This may be the service for endpoints that send
536 * device-specific port-write messages. End-point messages expected
537 * to be handled completely by EP specific device driver.
538 * For switches rc==0 signals that no standard processing required.
540 if (rdev
->pwcback
!= NULL
) {
541 rc
= rdev
->pwcback(rdev
, pw_msg
, 0);
546 /* For End-point devices processing stops here */
547 if (!(rdev
->pef
& RIO_PEF_SWITCH
))
550 if (rdev
->phys_efptr
== 0) {
551 pr_err("RIO_PW: Bad switch initialization for %s\n",
556 mport
= rdev
->net
->hport
;
557 destid
= rdev
->rswitch
->destid
;
558 hopcount
= rdev
->rswitch
->hopcount
;
561 * Process the port-write notification from switch
564 portnum
= pw_msg
->em
.is_port
& 0xFF;
566 if (rdev
->rswitch
->em_handle
)
567 rdev
->rswitch
->em_handle(rdev
, portnum
);
569 rio_mport_read_config_32(mport
, destid
, hopcount
,
570 rdev
->phys_efptr
+ RIO_PORT_N_ERR_STS_CSR(portnum
),
572 pr_debug("RIO_PW: SP%d_ERR_STS_CSR=0x%08x\n", portnum
, err_status
);
574 if (pw_msg
->em
.errdetect
) {
575 pr_debug("RIO_PW: RIO_EM_P%d_ERR_DETECT=0x%08x\n",
576 portnum
, pw_msg
->em
.errdetect
);
577 /* Clear EM Port N Error Detect CSR */
578 rio_mport_write_config_32(mport
, destid
, hopcount
,
579 rdev
->em_efptr
+ RIO_EM_PN_ERR_DETECT(portnum
), 0);
582 if (pw_msg
->em
.ltlerrdet
) {
583 pr_debug("RIO_PW: RIO_EM_LTL_ERR_DETECT=0x%08x\n",
584 pw_msg
->em
.ltlerrdet
);
585 /* Clear EM L/T Layer Error Detect CSR */
586 rio_mport_write_config_32(mport
, destid
, hopcount
,
587 rdev
->em_efptr
+ RIO_EM_LTL_ERR_DETECT
, 0);
590 /* Clear Port Errors */
591 rio_mport_write_config_32(mport
, destid
, hopcount
,
592 rdev
->phys_efptr
+ RIO_PORT_N_ERR_STS_CSR(portnum
),
593 err_status
& RIO_PORT_N_ERR_STS_CLR_MASK
);
595 if (rdev
->rswitch
->port_ok
& (1 << portnum
)) {
596 if (err_status
& RIO_PORT_N_ERR_STS_PORT_UNINIT
) {
597 rdev
->rswitch
->port_ok
&= ~(1 << portnum
);
598 rio_set_port_lockout(rdev
, portnum
, 1);
600 rio_mport_write_config_32(mport
, destid
, hopcount
,
602 RIO_PORT_N_ACK_STS_CSR(portnum
),
603 RIO_PORT_N_ACK_CLEAR
);
605 /* Schedule Extraction Service */
606 pr_debug("RIO_PW: Device Extraction on [%s]-P%d\n",
607 rio_name(rdev
), portnum
);
610 if (err_status
& RIO_PORT_N_ERR_STS_PORT_OK
) {
611 rdev
->rswitch
->port_ok
|= (1 << portnum
);
612 rio_set_port_lockout(rdev
, portnum
, 0);
614 /* Schedule Insertion Service */
615 pr_debug("RIO_PW: Device Insertion on [%s]-P%d\n",
616 rio_name(rdev
), portnum
);
620 /* Clear Port-Write Pending bit */
621 rio_mport_write_config_32(mport
, destid
, hopcount
,
622 rdev
->phys_efptr
+ RIO_PORT_N_ERR_STS_CSR(portnum
),
623 RIO_PORT_N_ERR_STS_PW_PEND
);
627 EXPORT_SYMBOL_GPL(rio_inb_pwrite_handler
);
630 * rio_mport_get_efb - get pointer to next extended features block
631 * @port: Master port to issue transaction
632 * @local: Indicate a local master port or remote device access
633 * @destid: Destination ID of the device
634 * @hopcount: Number of switch hops to the device
635 * @from: Offset of current Extended Feature block header (if 0 starts
636 * from ExtFeaturePtr)
639 rio_mport_get_efb(struct rio_mport
*port
, int local
, u16 destid
,
640 u8 hopcount
, u32 from
)
646 rio_local_read_config_32(port
, RIO_ASM_INFO_CAR
,
649 rio_mport_read_config_32(port
, destid
, hopcount
,
650 RIO_ASM_INFO_CAR
, ®_val
);
651 return reg_val
& RIO_EXT_FTR_PTR_MASK
;
654 rio_local_read_config_32(port
, from
, ®_val
);
656 rio_mport_read_config_32(port
, destid
, hopcount
,
658 return RIO_GET_BLOCK_ID(reg_val
);
663 * rio_mport_get_feature - query for devices' extended features
664 * @port: Master port to issue transaction
665 * @local: Indicate a local master port or remote device access
666 * @destid: Destination ID of the device
667 * @hopcount: Number of switch hops to the device
668 * @ftr: Extended feature code
670 * Tell if a device supports a given RapidIO capability.
671 * Returns the offset of the requested extended feature
672 * block within the device's RIO configuration space or
673 * 0 in case the device does not support it. Possible
676 * %RIO_EFB_PAR_EP_ID LP/LVDS EP Devices
678 * %RIO_EFB_PAR_EP_REC_ID LP/LVDS EP Recovery Devices
680 * %RIO_EFB_PAR_EP_FREE_ID LP/LVDS EP Free Devices
682 * %RIO_EFB_SER_EP_ID LP/Serial EP Devices
684 * %RIO_EFB_SER_EP_REC_ID LP/Serial EP Recovery Devices
686 * %RIO_EFB_SER_EP_FREE_ID LP/Serial EP Free Devices
689 rio_mport_get_feature(struct rio_mport
* port
, int local
, u16 destid
,
690 u8 hopcount
, int ftr
)
692 u32 asm_info
, ext_ftr_ptr
, ftr_header
;
695 rio_local_read_config_32(port
, RIO_ASM_INFO_CAR
, &asm_info
);
697 rio_mport_read_config_32(port
, destid
, hopcount
,
698 RIO_ASM_INFO_CAR
, &asm_info
);
700 ext_ftr_ptr
= asm_info
& RIO_EXT_FTR_PTR_MASK
;
702 while (ext_ftr_ptr
) {
704 rio_local_read_config_32(port
, ext_ftr_ptr
,
707 rio_mport_read_config_32(port
, destid
, hopcount
,
708 ext_ftr_ptr
, &ftr_header
);
709 if (RIO_GET_BLOCK_ID(ftr_header
) == ftr
)
711 if (!(ext_ftr_ptr
= RIO_GET_BLOCK_PTR(ftr_header
)))
719 * rio_get_asm - Begin or continue searching for a RIO device by vid/did/asm_vid/asm_did
720 * @vid: RIO vid to match or %RIO_ANY_ID to match all vids
721 * @did: RIO did to match or %RIO_ANY_ID to match all dids
722 * @asm_vid: RIO asm_vid to match or %RIO_ANY_ID to match all asm_vids
723 * @asm_did: RIO asm_did to match or %RIO_ANY_ID to match all asm_dids
724 * @from: Previous RIO device found in search, or %NULL for new search
726 * Iterates through the list of known RIO devices. If a RIO device is
727 * found with a matching @vid, @did, @asm_vid, @asm_did, the reference
728 * count to the device is incrememted and a pointer to its device
729 * structure is returned. Otherwise, %NULL is returned. A new search
730 * is initiated by passing %NULL to the @from argument. Otherwise, if
731 * @from is not %NULL, searches continue from next device on the global
732 * list. The reference count for @from is always decremented if it is
735 struct rio_dev
*rio_get_asm(u16 vid
, u16 did
,
736 u16 asm_vid
, u16 asm_did
, struct rio_dev
*from
)
739 struct rio_dev
*rdev
;
741 WARN_ON(in_interrupt());
742 spin_lock(&rio_global_list_lock
);
743 n
= from
? from
->global_list
.next
: rio_devices
.next
;
745 while (n
&& (n
!= &rio_devices
)) {
747 if ((vid
== RIO_ANY_ID
|| rdev
->vid
== vid
) &&
748 (did
== RIO_ANY_ID
|| rdev
->did
== did
) &&
749 (asm_vid
== RIO_ANY_ID
|| rdev
->asm_vid
== asm_vid
) &&
750 (asm_did
== RIO_ANY_ID
|| rdev
->asm_did
== asm_did
))
757 rdev
= rio_dev_get(rdev
);
758 spin_unlock(&rio_global_list_lock
);
763 * rio_get_device - Begin or continue searching for a RIO device by vid/did
764 * @vid: RIO vid to match or %RIO_ANY_ID to match all vids
765 * @did: RIO did to match or %RIO_ANY_ID to match all dids
766 * @from: Previous RIO device found in search, or %NULL for new search
768 * Iterates through the list of known RIO devices. If a RIO device is
769 * found with a matching @vid and @did, the reference count to the
770 * device is incrememted and a pointer to its device structure is returned.
771 * Otherwise, %NULL is returned. A new search is initiated by passing %NULL
772 * to the @from argument. Otherwise, if @from is not %NULL, searches
773 * continue from next device on the global list. The reference count for
774 * @from is always decremented if it is not %NULL.
776 struct rio_dev
*rio_get_device(u16 vid
, u16 did
, struct rio_dev
*from
)
778 return rio_get_asm(vid
, did
, RIO_ANY_ID
, RIO_ANY_ID
, from
);
782 * rio_std_route_add_entry - Add switch route table entry using standard
783 * registers defined in RIO specification rev.1.3
784 * @mport: Master port to issue transaction
785 * @destid: Destination ID of the device
786 * @hopcount: Number of switch hops to the device
787 * @table: routing table ID (global or port-specific)
788 * @route_destid: destID entry in the RT
789 * @route_port: destination port for specified destID
791 int rio_std_route_add_entry(struct rio_mport
*mport
, u16 destid
, u8 hopcount
,
792 u16 table
, u16 route_destid
, u8 route_port
)
794 if (table
== RIO_GLOBAL_TABLE
) {
795 rio_mport_write_config_32(mport
, destid
, hopcount
,
796 RIO_STD_RTE_CONF_DESTID_SEL_CSR
,
798 rio_mport_write_config_32(mport
, destid
, hopcount
,
799 RIO_STD_RTE_CONF_PORT_SEL_CSR
,
808 * rio_std_route_get_entry - Read switch route table entry (port number)
809 * assosiated with specified destID using standard registers defined in RIO
810 * specification rev.1.3
811 * @mport: Master port to issue transaction
812 * @destid: Destination ID of the device
813 * @hopcount: Number of switch hops to the device
814 * @table: routing table ID (global or port-specific)
815 * @route_destid: destID entry in the RT
816 * @route_port: returned destination port for specified destID
818 int rio_std_route_get_entry(struct rio_mport
*mport
, u16 destid
, u8 hopcount
,
819 u16 table
, u16 route_destid
, u8
*route_port
)
823 if (table
== RIO_GLOBAL_TABLE
) {
824 rio_mport_write_config_32(mport
, destid
, hopcount
,
825 RIO_STD_RTE_CONF_DESTID_SEL_CSR
, route_destid
);
826 rio_mport_read_config_32(mport
, destid
, hopcount
,
827 RIO_STD_RTE_CONF_PORT_SEL_CSR
, &result
);
829 *route_port
= (u8
)result
;
836 * rio_std_route_clr_table - Clear swotch route table using standard registers
837 * defined in RIO specification rev.1.3.
838 * @mport: Master port to issue transaction
839 * @local: Indicate a local master port or remote device access
840 * @destid: Destination ID of the device
841 * @hopcount: Number of switch hops to the device
842 * @table: routing table ID (global or port-specific)
844 int rio_std_route_clr_table(struct rio_mport
*mport
, u16 destid
, u8 hopcount
,
847 u32 max_destid
= 0xff;
848 u32 i
, pef
, id_inc
= 1, ext_cfg
= 0;
849 u32 port_sel
= RIO_INVALID_ROUTE
;
851 if (table
== RIO_GLOBAL_TABLE
) {
852 rio_mport_read_config_32(mport
, destid
, hopcount
,
855 if (mport
->sys_size
) {
856 rio_mport_read_config_32(mport
, destid
, hopcount
,
859 max_destid
&= RIO_RT_MAX_DESTID
;
862 if (pef
& RIO_PEF_EXT_RT
) {
863 ext_cfg
= 0x80000000;
865 port_sel
= (RIO_INVALID_ROUTE
<< 24) |
866 (RIO_INVALID_ROUTE
<< 16) |
867 (RIO_INVALID_ROUTE
<< 8) |
871 for (i
= 0; i
<= max_destid
;) {
872 rio_mport_write_config_32(mport
, destid
, hopcount
,
873 RIO_STD_RTE_CONF_DESTID_SEL_CSR
,
875 rio_mport_write_config_32(mport
, destid
, hopcount
,
876 RIO_STD_RTE_CONF_PORT_SEL_CSR
,
886 static void rio_fixup_device(struct rio_dev
*dev
)
890 static int __devinit
rio_init(void)
892 struct rio_dev
*dev
= NULL
;
894 while ((dev
= rio_get_device(RIO_ANY_ID
, RIO_ANY_ID
, dev
)) != NULL
) {
895 rio_fixup_device(dev
);
900 device_initcall(rio_init
);
902 int __devinit
rio_init_mports(void)
905 struct rio_mport
*port
;
907 list_for_each_entry(port
, &rio_mports
, node
) {
908 if (!request_mem_region(port
->iores
.start
,
909 port
->iores
.end
- port
->iores
.start
,
912 "RIO: Error requesting master port region 0x%016llx-0x%016llx\n",
913 (u64
)port
->iores
.start
, (u64
)port
->iores
.end
- 1);
918 if (port
->host_deviceid
>= 0)
919 rio_enum_mport(port
);
921 rio_disc_mport(port
);
928 void rio_register_mport(struct rio_mport
*port
)
930 list_add_tail(&port
->node
, &rio_mports
);
933 EXPORT_SYMBOL_GPL(rio_local_get_device_id
);
934 EXPORT_SYMBOL_GPL(rio_get_device
);
935 EXPORT_SYMBOL_GPL(rio_get_asm
);
936 EXPORT_SYMBOL_GPL(rio_request_inb_dbell
);
937 EXPORT_SYMBOL_GPL(rio_release_inb_dbell
);
938 EXPORT_SYMBOL_GPL(rio_request_outb_dbell
);
939 EXPORT_SYMBOL_GPL(rio_release_outb_dbell
);
940 EXPORT_SYMBOL_GPL(rio_request_inb_mbox
);
941 EXPORT_SYMBOL_GPL(rio_release_inb_mbox
);
942 EXPORT_SYMBOL_GPL(rio_request_outb_mbox
);
943 EXPORT_SYMBOL_GPL(rio_release_outb_mbox
);