Skip to content

Commit 2aaf308

Browse files
Alexandre Bouninetorvalds
authored andcommitted
rapidio: rework device hierarchy and introduce mport class of devices
This patch removes an artificial RapidIO bus root device and establishes actual device hierarchy by providing reference to real parent devices. It also introduces device class for RapidIO controller devices (on-chip or an eternal bridge, known as "mport"). Existing implementation was sufficient for SoC-based platforms that have a single RapidIO controller. With introduction of devices using multiple RapidIO controllers and PCIe-to-RapidIO bridges the old scheme is very limiting or does not work at all. The implemented changes allow to properly reference platform's local RapidIO mport devices and provide device details needed for upper layers. This change to RapidIO device hierarchy does not break any known existing kernel or user space interfaces. 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-technologies.com> Cc: Stef van Os <stef.van.os@prodrive-technologies.com> Cc: Jerry Jacobs <jerry.jacobs@prodrive-technologies.com> Cc: Arno Tiemersma <arno.tiemersma@prodrive-technologies.com> Cc: Rob Landley <rob@landley.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 40f847b commit 2aaf308

10 files changed

Lines changed: 133 additions & 16 deletions

File tree

‎Documentation/rapidio/sysfs.txt‎

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
44

5-
1. Device Subdirectories
6-
------------------------
5+
1. RapidIO Device Subdirectories
6+
--------------------------------
77

88
For each RapidIO device, the RapidIO subsystem creates files in an individual
99
subdirectory with the following name, /sys/bus/rapidio/devices/<device_name>.
@@ -25,8 +25,8 @@ seen by the enumerating host (destID = 1):
2525
NOTE: An enumerating or discovering endpoint does not create a sysfs entry for
2626
itself, this is why an endpoint with destID=1 is not shown in the list.
2727

28-
2. Attributes Common for All Devices
29-
------------------------------------
28+
2. Attributes Common for All RapidIO Devices
29+
--------------------------------------------
3030

3131
Each device subdirectory contains the following informational read-only files:
3232

@@ -52,16 +52,16 @@ This attribute is similar in behavior to the "config" attribute of PCI devices
5252
and provides an access to the RapidIO device registers using standard file read
5353
and write operations.
5454

55-
3. Endpoint Device Attributes
56-
-----------------------------
55+
3. RapidIO Endpoint Device Attributes
56+
-------------------------------------
5757

5858
Currently Linux RapidIO subsystem does not create any endpoint specific sysfs
5959
attributes. It is possible that RapidIO master port drivers and endpoint device
6060
drivers will add their device-specific sysfs attributes but such attributes are
6161
outside the scope of this document.
6262

63-
4. Switch Device Attributes
64-
---------------------------
63+
4. RapidIO Switch Device Attributes
64+
-----------------------------------
6565

6666
RapidIO switches have additional attributes in sysfs. RapidIO subsystem supports
6767
common and device-specific sysfs attributes for switches. Because switches are
@@ -106,3 +106,53 @@ attribute:
106106
for that controller always will be 0.
107107
To initiate RapidIO enumeration/discovery on all available mports
108108
a user must write '-1' (or RIO_MPORT_ANY) into this attribute file.
109+
110+
111+
6. RapidIO Bus Controllers/Ports
112+
--------------------------------
113+
114+
On-chip RapidIO controllers and PCIe-to-RapidIO bridges (referenced as
115+
"Master Port" or "mport") are presented in sysfs as the special class of
116+
devices: "rapidio_port".
117+
118+
The /sys/class/rapidio_port subdirectory contains individual subdirectories
119+
named as "rapidioN" where N = mport ID registered with RapidIO subsystem.
120+
121+
NOTE: An mport ID is not a RapidIO destination ID assigned to a given local
122+
mport device.
123+
124+
Each mport device subdirectory in addition to standard entries contains the
125+
following device-specific attributes:
126+
127+
port_destid - reports RapidIO destination ID assigned to the given RapidIO
128+
mport device. If value 0xFFFFFFFF is returned this means that
129+
no valid destination ID have been assigned to the mport (yet).
130+
Normally, before enumeration/discovery have been executed only
131+
fabric enumerating mports have a valid destination ID assigned
132+
to them using "hdid=..." rapidio module parameter.
133+
sys_size - reports RapidIO common transport system size:
134+
0 = small (8-bit destination ID, max. 256 devices),
135+
1 = large (16-bit destination ID, max. 65536 devices).
136+
137+
After enumeration or discovery was performed for a given mport device,
138+
the corresponding subdirectory will also contain subdirectories for each
139+
child RapidIO device connected to the mport. Naming conventions for RapidIO
140+
devices are described in Section 1 above.
141+
142+
The example below shows mport device subdirectory with several child RapidIO
143+
devices attached to it.
144+
145+
[rio@rapidio ~]$ ls /sys/class/rapidio_port/rapidio0/ -l
146+
total 0
147+
drwxr-xr-x 3 root root 0 Feb 11 15:10 00:e:0001
148+
drwxr-xr-x 3 root root 0 Feb 11 15:10 00:e:0004
149+
drwxr-xr-x 3 root root 0 Feb 11 15:10 00:e:0007
150+
drwxr-xr-x 3 root root 0 Feb 11 15:10 00:s:0002
151+
drwxr-xr-x 3 root root 0 Feb 11 15:10 00:s:0003
152+
drwxr-xr-x 3 root root 0 Feb 11 15:10 00:s:0005
153+
lrwxrwxrwx 1 root root 0 Feb 11 15:11 device -> ../../../0000:01:00.0
154+
-r--r--r-- 1 root root 4096 Feb 11 15:11 port_destid
155+
drwxr-xr-x 2 root root 0 Feb 11 15:11 power
156+
lrwxrwxrwx 1 root root 0 Feb 11 15:04 subsystem -> ../../../../../../class/rapidio_port
157+
-r--r--r-- 1 root root 4096 Feb 11 15:11 sys_size
158+
-rw-r--r-- 1 root root 4096 Feb 11 15:04 uevent

‎arch/powerpc/sysdev/fsl_rio.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ int fsl_rio_setup(struct platform_device *dev)
531531
sprintf(port->name, "RIO mport %d", i);
532532

533533
priv->dev = &dev->dev;
534+
port->dev.parent = &dev->dev;
534535
port->ops = ops;
535536
port->priv = priv;
536537
port->phys_efptr = 0x100;

‎drivers/net/rionet.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ static int rionet_setup_netdev(struct rio_mport *mport, struct net_device *ndev)
493493
ndev->netdev_ops = &rionet_netdev_ops;
494494
ndev->mtu = RIO_MAX_MSG_SIZE - 14;
495495
ndev->features = NETIF_F_LLTX;
496+
SET_NETDEV_DEV(ndev, &mport->dev);
496497
SET_ETHTOOL_OPS(ndev, &rionet_ethtool_ops);
497498

498499
spin_lock_init(&rnet->lock);

‎drivers/rapidio/devices/tsi721.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,6 +2256,7 @@ static int tsi721_setup_mport(struct tsi721_device *priv)
22562256
mport->phy_type = RIO_PHY_SERIAL;
22572257
mport->priv = (void *)priv;
22582258
mport->phys_efptr = 0x100;
2259+
mport->dev.parent = &pdev->dev;
22592260
priv->mport = mport;
22602261

22612262
INIT_LIST_HEAD(&mport->dbells);

‎drivers/rapidio/rio-driver.c‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ void rio_unregister_driver(struct rio_driver *rdrv)
167167
void rio_attach_device(struct rio_dev *rdev)
168168
{
169169
rdev->dev.bus = &rio_bus_type;
170-
rdev->dev.parent = &rio_bus;
171170
}
172171
EXPORT_SYMBOL_GPL(rio_attach_device);
173172

@@ -216,9 +215,12 @@ static int rio_uevent(struct device *dev, struct kobj_uevent_env *env)
216215
return 0;
217216
}
218217

219-
struct device rio_bus = {
220-
.init_name = "rapidio",
218+
struct class rio_mport_class = {
219+
.name = "rapidio_port",
220+
.owner = THIS_MODULE,
221+
.dev_groups = rio_mport_groups,
221222
};
223+
EXPORT_SYMBOL_GPL(rio_mport_class);
222224

223225
struct bus_type rio_bus_type = {
224226
.name = "rapidio",
@@ -233,14 +235,20 @@ struct bus_type rio_bus_type = {
233235
/**
234236
* rio_bus_init - Register the RapidIO bus with the device model
235237
*
236-
* Registers the RIO bus device and RIO bus type with the Linux
238+
* Registers the RIO mport device class and RIO bus type with the Linux
237239
* device model.
238240
*/
239241
static int __init rio_bus_init(void)
240242
{
241-
if (device_register(&rio_bus) < 0)
242-
printk("RIO: failed to register RIO bus device\n");
243-
return bus_register(&rio_bus_type);
243+
int ret;
244+
245+
ret = class_register(&rio_mport_class);
246+
if (!ret) {
247+
ret = bus_register(&rio_bus_type);
248+
if (ret)
249+
class_unregister(&rio_mport_class);
250+
}
251+
return ret;
244252
}
245253

246254
postcore_initcall(rio_bus_init);

‎drivers/rapidio/rio-scan.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ static struct rio_dev *rio_setup_device(struct rio_net *net,
461461
rdev->comp_tag & RIO_CTAG_UDEVID);
462462
}
463463

464+
rdev->dev.parent = &port->dev;
464465
rio_attach_device(rdev);
465466

466467
device_initialize(&rdev->dev);

‎drivers/rapidio/rio-sysfs.c‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,43 @@ const struct attribute_group *rio_bus_groups[] = {
341341
&rio_bus_group,
342342
NULL,
343343
};
344+
345+
static ssize_t
346+
port_destid_show(struct device *dev, struct device_attribute *attr,
347+
char *buf)
348+
{
349+
struct rio_mport *mport = to_rio_mport(dev);
350+
351+
if (mport)
352+
return sprintf(buf, "0x%04x\n", mport->host_deviceid);
353+
else
354+
return -ENODEV;
355+
}
356+
static DEVICE_ATTR_RO(port_destid);
357+
358+
static ssize_t sys_size_show(struct device *dev, struct device_attribute *attr,
359+
char *buf)
360+
{
361+
struct rio_mport *mport = to_rio_mport(dev);
362+
363+
if (mport)
364+
return sprintf(buf, "%u\n", mport->sys_size);
365+
else
366+
return -ENODEV;
367+
}
368+
static DEVICE_ATTR_RO(sys_size);
369+
370+
static struct attribute *rio_mport_attrs[] = {
371+
&dev_attr_port_destid.attr,
372+
&dev_attr_sys_size.attr,
373+
NULL,
374+
};
375+
376+
static const struct attribute_group rio_mport_group = {
377+
.attrs = rio_mport_attrs,
378+
};
379+
380+
const struct attribute_group *rio_mport_groups[] = {
381+
&rio_mport_group,
382+
NULL,
383+
};

‎drivers/rapidio/rio.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,6 +1884,7 @@ static int rio_get_hdid(int index)
18841884
int rio_register_mport(struct rio_mport *port)
18851885
{
18861886
struct rio_scan_node *scan = NULL;
1887+
int res = 0;
18871888

18881889
if (next_portid >= RIO_MAX_MPORTS) {
18891890
pr_err("RIO: reached specified max number of mports\n");
@@ -1894,6 +1895,16 @@ int rio_register_mport(struct rio_mport *port)
18941895
port->host_deviceid = rio_get_hdid(port->id);
18951896
port->nscan = NULL;
18961897

1898+
dev_set_name(&port->dev, "rapidio%d", port->id);
1899+
port->dev.class = &rio_mport_class;
1900+
1901+
res = device_register(&port->dev);
1902+
if (res)
1903+
dev_err(&port->dev, "RIO: mport%d registration failed ERR=%d\n",
1904+
port->id, res);
1905+
else
1906+
dev_dbg(&port->dev, "RIO: mport%d registered\n", port->id);
1907+
18971908
mutex_lock(&rio_mport_list_lock);
18981909
list_add_tail(&port->node, &rio_mports);
18991910

‎drivers/rapidio/rio.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ extern int rio_mport_scan(int mport_id);
5050
/* Structures internal to the RIO core code */
5151
extern const struct attribute_group *rio_dev_groups[];
5252
extern const struct attribute_group *rio_bus_groups[];
53+
extern const struct attribute_group *rio_mport_groups[];
5354

5455
#define RIO_GET_DID(size, x) (size ? (x & 0xffff) : ((x & 0x00ff0000) >> 16))
5556
#define RIO_SET_DID(size, x) (size ? (x & 0xffff) : ((x & 0x000000ff) << 16))

‎include/linux/rio.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
#define RIO_CTAG_UDEVID 0x0001ffff /* Unique device identifier */
8484

8585
extern struct bus_type rio_bus_type;
86-
extern struct device rio_bus;
86+
extern struct class rio_mport_class;
8787

8888
struct rio_mport;
8989
struct rio_dev;
@@ -201,6 +201,7 @@ struct rio_dev {
201201
#define rio_dev_f(n) list_entry(n, struct rio_dev, net_list)
202202
#define to_rio_dev(n) container_of(n, struct rio_dev, dev)
203203
#define sw_to_rio_dev(n) container_of(n, struct rio_dev, rswitch[0])
204+
#define to_rio_mport(n) container_of(n, struct rio_mport, dev)
204205

205206
/**
206207
* struct rio_msg - RIO message event
@@ -248,6 +249,7 @@ enum rio_phy_type {
248249
* @phy_type: RapidIO phy type
249250
* @phys_efptr: RIO port extended features pointer
250251
* @name: Port name string
252+
* @dev: device structure associated with an mport
251253
* @priv: Master port private data
252254
* @dma: DMA device associated with mport
253255
* @nscan: RapidIO network enumeration/discovery operations
@@ -272,6 +274,7 @@ struct rio_mport {
272274
enum rio_phy_type phy_type; /* RapidIO phy type */
273275
u32 phys_efptr;
274276
unsigned char name[RIO_MAX_MPORT_NAME];
277+
struct device dev;
275278
void *priv; /* Master port private data */
276279
#ifdef CONFIG_RAPIDIO_DMA_ENGINE
277280
struct dma_device dma;

0 commit comments

Comments
 (0)