Skip to content

Commit c93b76b

Browse files
Tomas Winklergregkh
authored andcommitted
mei: bus: report also uuid in module alias
In order to automate modules matching add device uuid which is reported in client enumeration, keep also the name that is needed in for nfc distinguishing radio vendor Report mei:name:uuid Cc: linux-api@vger.kernel.org Cc: Samuel Ortiz <sameo@linux.intel.com> Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 41c95b0 commit c93b76b

9 files changed

Lines changed: 72 additions & 13 deletions

File tree

‎Documentation/ABI/testing/sysfs-bus-mei‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ KernelVersion: 3.10
44
Contact: Samuel Ortiz <sameo@linux.intel.com>
55
linux-mei@linux.intel.com
66
Description: Stores the same MODALIAS value emitted by uevent
7-
Format: mei:<mei device name>
7+
Format: mei:<mei device name>:<device uuid>:

‎drivers/misc/mei/bus.c‎

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,40 @@
3030
#define to_mei_cl_driver(d) container_of(d, struct mei_cl_driver, driver)
3131
#define to_mei_cl_device(d) container_of(d, struct mei_cl_device, dev)
3232

33+
static inline uuid_le uuid_le_cast(const __u8 uuid[16])
34+
{
35+
return *(uuid_le *)uuid;
36+
}
37+
3338
static int mei_cl_device_match(struct device *dev, struct device_driver *drv)
3439
{
3540
struct mei_cl_device *device = to_mei_cl_device(dev);
3641
struct mei_cl_driver *driver = to_mei_cl_driver(drv);
3742
const struct mei_cl_device_id *id;
43+
const uuid_le *uuid;
44+
const char *name;
3845

3946
if (!device)
4047
return 0;
4148

49+
uuid = mei_me_cl_uuid(device->me_cl);
50+
name = device->name;
51+
4252
if (!driver || !driver->id_table)
4353
return 0;
4454

4555
id = driver->id_table;
4656

47-
while (id->name[0]) {
48-
if (!strncmp(dev_name(dev), id->name, sizeof(id->name)))
49-
return 1;
57+
while (uuid_le_cmp(NULL_UUID_LE, uuid_le_cast(id->uuid))) {
58+
59+
if (!uuid_le_cmp(*uuid, uuid_le_cast(id->uuid))) {
60+
if (id->name[0]) {
61+
if (!strncmp(name, id->name, sizeof(id->name)))
62+
return 1;
63+
} else {
64+
return 1;
65+
}
66+
}
5067

5168
id++;
5269
}
@@ -69,7 +86,7 @@ static int mei_cl_device_probe(struct device *dev)
6986

7087
dev_dbg(dev, "Device probe\n");
7188

72-
strlcpy(id.name, dev_name(dev), sizeof(id.name));
89+
strlcpy(id.name, device->name, sizeof(id.name));
7390

7491
return driver->probe(device, &id);
7592
}
@@ -100,9 +117,12 @@ static int mei_cl_device_remove(struct device *dev)
100117
static ssize_t modalias_show(struct device *dev, struct device_attribute *a,
101118
char *buf)
102119
{
103-
int len;
120+
struct mei_cl_device *device = to_mei_cl_device(dev);
121+
const uuid_le *uuid = mei_me_cl_uuid(device->me_cl);
122+
size_t len;
104123

105-
len = snprintf(buf, PAGE_SIZE, "mei:%s\n", dev_name(dev));
124+
len = snprintf(buf, PAGE_SIZE, "mei:%s:" MEI_CL_UUID_FMT ":",
125+
device->name, MEI_CL_UUID_ARGS(uuid->b));
106126

107127
return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len;
108128
}
@@ -116,7 +136,11 @@ ATTRIBUTE_GROUPS(mei_cl_dev);
116136

117137
static int mei_cl_uevent(struct device *dev, struct kobj_uevent_env *env)
118138
{
119-
if (add_uevent_var(env, "MODALIAS=mei:%s", dev_name(dev)))
139+
struct mei_cl_device *device = to_mei_cl_device(dev);
140+
const uuid_le *uuid = mei_me_cl_uuid(device->me_cl);
141+
142+
if (add_uevent_var(env, "MODALIAS=mei:%s:" MEI_CL_UUID_FMT ":",
143+
device->name, MEI_CL_UUID_ARGS(uuid->b)))
120144
return -ENOMEM;
121145

122146
return 0;
@@ -185,7 +209,9 @@ struct mei_cl_device *mei_cl_add_device(struct mei_device *dev,
185209
device->dev.bus = &mei_cl_bus_type;
186210
device->dev.type = &mei_cl_device_type;
187211

188-
dev_set_name(&device->dev, "%s", name);
212+
strlcpy(device->name, name, sizeof(device->name));
213+
214+
dev_set_name(&device->dev, "mei:%s:%pUl", name, mei_me_cl_uuid(me_cl));
189215

190216
status = device_register(&device->dev);
191217
if (status) {

‎drivers/misc/mei/mei_dev.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ struct mei_cl *mei_cl_bus_find_cl_by_uuid(struct mei_device *dev, uuid_le uuid);
376376
* @dev: linux driver model device pointer
377377
* @me_cl: me client
378378
* @cl: mei client
379+
* @name: device name
379380
* @ops: ME transport ops
380381
* @event_work: async work to execute event callback
381382
* @event_cb: Drivers register this callback to get asynchronous ME
@@ -389,6 +390,7 @@ struct mei_cl_device {
389390

390391
struct mei_me_client *me_cl;
391392
struct mei_cl *cl;
393+
char name[MEI_CL_NAME_SIZE];
392394

393395
const struct mei_cl_ops *ops;
394396

‎drivers/nfc/mei_phy.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33

44
#include <linux/mei_cl_bus.h>
55
#include <net/nfc/hci.h>
6+
#include <linux/uuid.h>
67

8+
#define MEI_NFC_UUID __UUID_LE(0x0bb17a78, 0x2a8e, 0x4c50, \
9+
0x94, 0xd4, 0x50, 0x26, 0x67, 0x23, 0x77, 0x5c)
710
#define MEI_NFC_HEADER_SIZE 10
811
#define MEI_NFC_MAX_HCI_PAYLOAD 300
912

‎drivers/nfc/microread/mei.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static int microread_mei_remove(struct mei_cl_device *device)
6767
}
6868

6969
static struct mei_cl_device_id microread_mei_tbl[] = {
70-
{ MICROREAD_DRIVER_NAME },
70+
{ MICROREAD_DRIVER_NAME, MEI_NFC_UUID},
7171

7272
/* required last entry */
7373
{ }

‎drivers/nfc/pn544/mei.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static int pn544_mei_remove(struct mei_cl_device *device)
6767
}
6868

6969
static struct mei_cl_device_id pn544_mei_tbl[] = {
70-
{ PN544_DRIVER_NAME },
70+
{ PN544_DRIVER_NAME, MEI_NFC_UUID},
7171

7272
/* required last entry */
7373
{ }

‎include/linux/mod_devicetable.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,9 +599,22 @@ struct ipack_device_id {
599599

600600
#define MEI_CL_MODULE_PREFIX "mei:"
601601
#define MEI_CL_NAME_SIZE 32
602+
#define MEI_CL_UUID_FMT "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
603+
#define MEI_CL_UUID_ARGS(_u) \
604+
_u[0], _u[1], _u[2], _u[3], _u[4], _u[5], _u[6], _u[7], \
605+
_u[8], _u[9], _u[10], _u[11], _u[12], _u[13], _u[14], _u[15]
602606

607+
/**
608+
* struct mei_cl_device_id - MEI client device identifier
609+
* @name: helper name
610+
* @uuid: client uuid
611+
* @driver_info: information used by the driver.
612+
*
613+
* identifies mei client device by uuid and name
614+
*/
603615
struct mei_cl_device_id {
604616
char name[MEI_CL_NAME_SIZE];
617+
__u8 uuid[16];
605618
kernel_ulong_t driver_info;
606619
};
607620

‎scripts/mod/devicetable-offsets.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ int main(void)
182182

183183
DEVID(mei_cl_device_id);
184184
DEVID_FIELD(mei_cl_device_id, name);
185+
DEVID_FIELD(mei_cl_device_id, uuid);
185186

186187
DEVID(rio_device_id);
187188
DEVID_FIELD(rio_device_id, did);

‎scripts/mod/file2alias.c‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,15 @@ static inline void add_wildcard(char *str)
131131
strcat(str + len, "*");
132132
}
133133

134+
static inline void add_uuid(char *str, __u8 uuid[16])
135+
{
136+
int len = strlen(str);
137+
int i;
138+
139+
for (i = 0; i < 16; i++)
140+
sprintf(str + len + (i << 1), "%02x", uuid[i]);
141+
}
142+
134143
/**
135144
* Check that sizeof(device_id type) are consistent with size of section
136145
* in .o file. If in-consistent then userspace and kernel does not agree
@@ -1160,13 +1169,18 @@ static int do_cpu_entry(const char *filename, void *symval, char *alias)
11601169
}
11611170
ADD_TO_DEVTABLE("cpu", cpu_feature, do_cpu_entry);
11621171

1163-
/* Looks like: mei:S */
1172+
/* Looks like: mei:S:uuid */
11641173
static int do_mei_entry(const char *filename, void *symval,
11651174
char *alias)
11661175
{
11671176
DEF_FIELD_ADDR(symval, mei_cl_device_id, name);
1177+
DEF_FIELD_ADDR(symval, mei_cl_device_id, uuid);
1178+
1179+
sprintf(alias, MEI_CL_MODULE_PREFIX);
1180+
sprintf(alias + strlen(alias), "%s:", (*name)[0] ? *name : "*");
1181+
add_uuid(alias, *uuid);
11681182

1169-
sprintf(alias, MEI_CL_MODULE_PREFIX "%s", *name);
1183+
strcat(alias, ":*");
11701184

11711185
return 1;
11721186
}

0 commit comments

Comments
 (0)