Skip to content

Commit 2ec3ba6

Browse files
Alexandre Bouninetorvalds
authored andcommitted
rapidio: convert switch drivers to modules
Rework RapidIO switch drivers to add an option to build them as loadable kernel modules. This patch removes RapidIO-specific vmlinux section and converts switch drivers to be compatible with LDM driver registration method. To simplify registration of device-specific callback routines this patch introduces rio_switch_ops data structure. The sw_sysfs() callback is removed from the list of device-specific operations because under the new structure its functions can be handled by switch driver's probe() and remove() routines. If a specific switch device driver is not loaded the RapidIO subsystem core will use default standard-based operations to configure a switch. Because the current implementation of RapidIO enumeration/discovery method relies on availability of device-specific operations for error management, switch device drivers must be loaded before the RapidIO enumeration/discovery starts. This patch also moves several common routines from enumeration/discovery module into the RapidIO core code to make switch-specific operations accessible to all components of RapidIO subsystem. Signed-off-by: Alexandre Bounine <alexandre.bounine@idt.com> Cc: Matt Porter <mporter@kernel.crashing.org> Cc: Li Yang <leoli@freescale.com> Cc: Kumar Gala <galak@kernel.crashing.org> Cc: Andre van Herk <andre.van.herk@Prodrive.nl> Cc: Micha Nelissen <micha.nelissen@Prodrive.nl> Cc: Stef van Os <stef.van.os@Prodrive.nl> Cc: Jean Delvare <jdelvare@suse.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 36f0efb commit 2ec3ba6

File tree

12 files changed

+568
-345
lines changed

12 files changed

+568
-345
lines changed

drivers/rapidio/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,9 @@ config RAPIDIO_ENUM_BASIC
6767

6868
endchoice
6969

70+
menu "RapidIO Switch drivers"
71+
depends on RAPIDIO
72+
7073
source "drivers/rapidio/switches/Kconfig"
74+
75+
endmenu

drivers/rapidio/rio-scan.c

Lines changed: 9 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ static struct rio_dev *rio_setup_device(struct rio_net *net,
406406
rio_mport_write_config_32(port, destid, hopcount,
407407
RIO_COMPONENT_TAG_CSR, next_comptag);
408408
rdev->comp_tag = next_comptag++;
409+
rdev->do_enum = true;
409410
} else {
410411
rio_mport_read_config_32(port, destid, hopcount,
411412
RIO_COMPONENT_TAG_CSR,
@@ -434,6 +435,7 @@ static struct rio_dev *rio_setup_device(struct rio_net *net,
434435
rswitch = rdev->rswitch;
435436
rswitch->switchid = rdev->comp_tag & RIO_CTAG_UDEVID;
436437
rswitch->port_ok = 0;
438+
spin_lock_init(&rswitch->lock);
437439
rswitch->route_table = kzalloc(sizeof(u8)*
438440
RIO_MAX_ROUTE_ENTRIES(port->sys_size),
439441
GFP_KERNEL);
@@ -445,11 +447,9 @@ static struct rio_dev *rio_setup_device(struct rio_net *net,
445447
rswitch->route_table[rdid] = RIO_INVALID_ROUTE;
446448
dev_set_name(&rdev->dev, "%02x:s:%04x", rdev->net->id,
447449
rswitch->switchid);
448-
rio_switch_init(rdev, do_enum);
449450

450-
if (do_enum && rswitch->clr_table)
451-
rswitch->clr_table(port, destid, hopcount,
452-
RIO_GLOBAL_TABLE);
451+
if (do_enum)
452+
rio_route_clr_table(rdev, RIO_GLOBAL_TABLE, 0);
453453

454454
list_add_tail(&rswitch->node, &net->switches);
455455

@@ -532,156 +532,6 @@ rio_sport_is_active(struct rio_mport *port, u16 destid, u8 hopcount, int sport)
532532
return result & RIO_PORT_N_ERR_STS_PORT_OK;
533533
}
534534

535-
/**
536-
* rio_lock_device - Acquires host device lock for specified device
537-
* @port: Master port to send transaction
538-
* @destid: Destination ID for device/switch
539-
* @hopcount: Hopcount to reach switch
540-
* @wait_ms: Max wait time in msec (0 = no timeout)
541-
*
542-
* Attepts to acquire host device lock for specified device
543-
* Returns 0 if device lock acquired or EINVAL if timeout expires.
544-
*/
545-
static int
546-
rio_lock_device(struct rio_mport *port, u16 destid, u8 hopcount, int wait_ms)
547-
{
548-
u32 result;
549-
int tcnt = 0;
550-
551-
/* Attempt to acquire device lock */
552-
rio_mport_write_config_32(port, destid, hopcount,
553-
RIO_HOST_DID_LOCK_CSR, port->host_deviceid);
554-
rio_mport_read_config_32(port, destid, hopcount,
555-
RIO_HOST_DID_LOCK_CSR, &result);
556-
557-
while (result != port->host_deviceid) {
558-
if (wait_ms != 0 && tcnt == wait_ms) {
559-
pr_debug("RIO: timeout when locking device %x:%x\n",
560-
destid, hopcount);
561-
return -EINVAL;
562-
}
563-
564-
/* Delay a bit */
565-
mdelay(1);
566-
tcnt++;
567-
/* Try to acquire device lock again */
568-
rio_mport_write_config_32(port, destid,
569-
hopcount,
570-
RIO_HOST_DID_LOCK_CSR,
571-
port->host_deviceid);
572-
rio_mport_read_config_32(port, destid,
573-
hopcount,
574-
RIO_HOST_DID_LOCK_CSR, &result);
575-
}
576-
577-
return 0;
578-
}
579-
580-
/**
581-
* rio_unlock_device - Releases host device lock for specified device
582-
* @port: Master port to send transaction
583-
* @destid: Destination ID for device/switch
584-
* @hopcount: Hopcount to reach switch
585-
*
586-
* Returns 0 if device lock released or EINVAL if fails.
587-
*/
588-
static int
589-
rio_unlock_device(struct rio_mport *port, u16 destid, u8 hopcount)
590-
{
591-
u32 result;
592-
593-
/* Release device lock */
594-
rio_mport_write_config_32(port, destid,
595-
hopcount,
596-
RIO_HOST_DID_LOCK_CSR,
597-
port->host_deviceid);
598-
rio_mport_read_config_32(port, destid, hopcount,
599-
RIO_HOST_DID_LOCK_CSR, &result);
600-
if ((result & 0xffff) != 0xffff) {
601-
pr_debug("RIO: badness when releasing device lock %x:%x\n",
602-
destid, hopcount);
603-
return -EINVAL;
604-
}
605-
606-
return 0;
607-
}
608-
609-
/**
610-
* rio_route_add_entry- Add a route entry to a switch routing table
611-
* @rdev: RIO device
612-
* @table: Routing table ID
613-
* @route_destid: Destination ID to be routed
614-
* @route_port: Port number to be routed
615-
* @lock: lock switch device flag
616-
*
617-
* Calls the switch specific add_entry() method to add a route entry
618-
* on a switch. The route table can be specified using the @table
619-
* argument if a switch has per port routing tables or the normal
620-
* use is to specific all tables (or the global table) by passing
621-
* %RIO_GLOBAL_TABLE in @table. Returns %0 on success or %-EINVAL
622-
* on failure.
623-
*/
624-
static int
625-
rio_route_add_entry(struct rio_dev *rdev,
626-
u16 table, u16 route_destid, u8 route_port, int lock)
627-
{
628-
int rc;
629-
630-
if (lock) {
631-
rc = rio_lock_device(rdev->net->hport, rdev->destid,
632-
rdev->hopcount, 1000);
633-
if (rc)
634-
return rc;
635-
}
636-
637-
rc = rdev->rswitch->add_entry(rdev->net->hport, rdev->destid,
638-
rdev->hopcount, table,
639-
route_destid, route_port);
640-
if (lock)
641-
rio_unlock_device(rdev->net->hport, rdev->destid,
642-
rdev->hopcount);
643-
644-
return rc;
645-
}
646-
647-
/**
648-
* rio_route_get_entry- Read a route entry in a switch routing table
649-
* @rdev: RIO device
650-
* @table: Routing table ID
651-
* @route_destid: Destination ID to be routed
652-
* @route_port: Pointer to read port number into
653-
* @lock: lock switch device flag
654-
*
655-
* Calls the switch specific get_entry() method to read a route entry
656-
* in a switch. The route table can be specified using the @table
657-
* argument if a switch has per port routing tables or the normal
658-
* use is to specific all tables (or the global table) by passing
659-
* %RIO_GLOBAL_TABLE in @table. Returns %0 on success or %-EINVAL
660-
* on failure.
661-
*/
662-
static int
663-
rio_route_get_entry(struct rio_dev *rdev, u16 table,
664-
u16 route_destid, u8 *route_port, int lock)
665-
{
666-
int rc;
667-
668-
if (lock) {
669-
rc = rio_lock_device(rdev->net->hport, rdev->destid,
670-
rdev->hopcount, 1000);
671-
if (rc)
672-
return rc;
673-
}
674-
675-
rc = rdev->rswitch->get_entry(rdev->net->hport, rdev->destid,
676-
rdev->hopcount, table,
677-
route_destid, route_port);
678-
if (lock)
679-
rio_unlock_device(rdev->net->hport, rdev->destid,
680-
rdev->hopcount);
681-
682-
return rc;
683-
}
684-
685535
/**
686536
* rio_get_host_deviceid_lock- Reads the Host Device ID Lock CSR on a device
687537
* @port: Master port to send transaction
@@ -1094,12 +944,9 @@ static void rio_update_route_tables(struct rio_net *net)
1094944

1095945
sport = RIO_GET_PORT_NUM(swrdev->swpinfo);
1096946

1097-
if (rswitch->add_entry) {
1098-
rio_route_add_entry(swrdev,
1099-
RIO_GLOBAL_TABLE, destid,
1100-
sport, 0);
1101-
rswitch->route_table[destid] = sport;
1102-
}
947+
rio_route_add_entry(swrdev, RIO_GLOBAL_TABLE,
948+
destid, sport, 0);
949+
rswitch->route_table[destid] = sport;
1103950
}
1104951
}
1105952
}
@@ -1115,8 +962,8 @@ static void rio_update_route_tables(struct rio_net *net)
1115962
static void rio_init_em(struct rio_dev *rdev)
1116963
{
1117964
if (rio_is_switch(rdev) && (rdev->em_efptr) &&
1118-
(rdev->rswitch->em_init)) {
1119-
rdev->rswitch->em_init(rdev);
965+
rdev->rswitch->ops && rdev->rswitch->ops->em_init) {
966+
rdev->rswitch->ops->em_init(rdev);
1120967
}
1121968
}
1122969

drivers/rapidio/rio-sysfs.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,6 @@ int rio_create_sysfs_dev_files(struct rio_dev *rdev)
257257
err |= device_create_file(&rdev->dev, &dev_attr_routes);
258258
err |= device_create_file(&rdev->dev, &dev_attr_lnext);
259259
err |= device_create_file(&rdev->dev, &dev_attr_hopcount);
260-
if (!err && rdev->rswitch->sw_sysfs)
261-
err = rdev->rswitch->sw_sysfs(rdev, RIO_SW_SYSFS_CREATE);
262260
}
263261

264262
if (err)
@@ -281,8 +279,6 @@ void rio_remove_sysfs_dev_files(struct rio_dev *rdev)
281279
device_remove_file(&rdev->dev, &dev_attr_routes);
282280
device_remove_file(&rdev->dev, &dev_attr_lnext);
283281
device_remove_file(&rdev->dev, &dev_attr_hopcount);
284-
if (rdev->rswitch->sw_sysfs)
285-
rdev->rswitch->sw_sysfs(rdev, RIO_SW_SYSFS_REMOVE);
286282
}
287283
}
288284

0 commit comments

Comments
 (0)