diff options
Diffstat (limited to 'drivers/misc')
35 files changed, 2061 insertions, 485 deletions
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index e83fdfe0c8ca..e29e7980a359 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig | |||
@@ -93,6 +93,14 @@ config ATMEL_TCB_CLKSRC_BLOCK | |||
93 | TC can be used for other purposes, such as PWM generation and | 93 | TC can be used for other purposes, such as PWM generation and |
94 | interval timing. | 94 | interval timing. |
95 | 95 | ||
96 | config DUMMY_IRQ | ||
97 | tristate "Dummy IRQ handler" | ||
98 | default n | ||
99 | ---help--- | ||
100 | This module accepts a single 'irq' parameter, which it should register for. | ||
101 | The sole purpose of this module is to help with debugging of systems on | ||
102 | which spurious IRQs would happen on disabled IRQ vector. | ||
103 | |||
96 | config IBM_ASM | 104 | config IBM_ASM |
97 | tristate "Device driver for IBM RSA service processor" | 105 | tristate "Device driver for IBM RSA service processor" |
98 | depends on X86 && PCI && INPUT | 106 | depends on X86 && PCI && INPUT |
@@ -398,7 +406,7 @@ config DS1682 | |||
398 | 406 | ||
399 | config SPEAR13XX_PCIE_GADGET | 407 | config SPEAR13XX_PCIE_GADGET |
400 | bool "PCIe gadget support for SPEAr13XX platform" | 408 | bool "PCIe gadget support for SPEAr13XX platform" |
401 | depends on ARCH_SPEAR13XX | 409 | depends on ARCH_SPEAR13XX && BROKEN |
402 | default n | 410 | default n |
403 | help | 411 | help |
404 | This option enables gadget support for PCIe controller. If | 412 | This option enables gadget support for PCIe controller. If |
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index 35a1463c72d9..865cbc6a7ae1 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile | |||
@@ -13,6 +13,7 @@ obj-$(CONFIG_ATMEL_TCLIB) += atmel_tclib.o | |||
13 | obj-$(CONFIG_BMP085) += bmp085.o | 13 | obj-$(CONFIG_BMP085) += bmp085.o |
14 | obj-$(CONFIG_BMP085_I2C) += bmp085-i2c.o | 14 | obj-$(CONFIG_BMP085_I2C) += bmp085-i2c.o |
15 | obj-$(CONFIG_BMP085_SPI) += bmp085-spi.o | 15 | obj-$(CONFIG_BMP085_SPI) += bmp085-spi.o |
16 | obj-$(CONFIG_DUMMY_IRQ) += dummy-irq.o | ||
16 | obj-$(CONFIG_ICS932S401) += ics932s401.o | 17 | obj-$(CONFIG_ICS932S401) += ics932s401.o |
17 | obj-$(CONFIG_LKDTM) += lkdtm.o | 18 | obj-$(CONFIG_LKDTM) += lkdtm.o |
18 | obj-$(CONFIG_TIFM_CORE) += tifm_core.o | 19 | obj-$(CONFIG_TIFM_CORE) += tifm_core.o |
@@ -49,6 +50,5 @@ obj-y += carma/ | |||
49 | obj-$(CONFIG_USB_SWITCH_FSA9480) += fsa9480.o | 50 | obj-$(CONFIG_USB_SWITCH_FSA9480) += fsa9480.o |
50 | obj-$(CONFIG_ALTERA_STAPL) +=altera-stapl/ | 51 | obj-$(CONFIG_ALTERA_STAPL) +=altera-stapl/ |
51 | obj-$(CONFIG_INTEL_MEI) += mei/ | 52 | obj-$(CONFIG_INTEL_MEI) += mei/ |
52 | obj-$(CONFIG_MAX8997_MUIC) += max8997-muic.o | ||
53 | obj-$(CONFIG_VMWARE_VMCI) += vmw_vmci/ | 53 | obj-$(CONFIG_VMWARE_VMCI) += vmw_vmci/ |
54 | obj-$(CONFIG_LATTICE_ECP3_CONFIG) += lattice-ecp3-config.o | 54 | obj-$(CONFIG_LATTICE_ECP3_CONFIG) += lattice-ecp3-config.o |
diff --git a/drivers/misc/apds9802als.c b/drivers/misc/apds9802als.c index d648b0893027..5b5fd8416b3e 100644 --- a/drivers/misc/apds9802als.c +++ b/drivers/misc/apds9802als.c | |||
@@ -272,19 +272,8 @@ static int apds9802als_remove(struct i2c_client *client) | |||
272 | } | 272 | } |
273 | 273 | ||
274 | #ifdef CONFIG_PM | 274 | #ifdef CONFIG_PM |
275 | static int apds9802als_suspend(struct i2c_client *client, pm_message_t mesg) | ||
276 | { | ||
277 | als_set_power_state(client, false); | ||
278 | return 0; | ||
279 | } | ||
280 | |||
281 | static int apds9802als_resume(struct i2c_client *client) | ||
282 | { | ||
283 | als_set_default_config(client); | ||
284 | return 0; | ||
285 | } | ||
286 | 275 | ||
287 | static int apds9802als_runtime_suspend(struct device *dev) | 276 | static int apds9802als_suspend(struct device *dev) |
288 | { | 277 | { |
289 | struct i2c_client *client = to_i2c_client(dev); | 278 | struct i2c_client *client = to_i2c_client(dev); |
290 | 279 | ||
@@ -292,7 +281,7 @@ static int apds9802als_runtime_suspend(struct device *dev) | |||
292 | return 0; | 281 | return 0; |
293 | } | 282 | } |
294 | 283 | ||
295 | static int apds9802als_runtime_resume(struct device *dev) | 284 | static int apds9802als_resume(struct device *dev) |
296 | { | 285 | { |
297 | struct i2c_client *client = to_i2c_client(dev); | 286 | struct i2c_client *client = to_i2c_client(dev); |
298 | 287 | ||
@@ -300,16 +289,12 @@ static int apds9802als_runtime_resume(struct device *dev) | |||
300 | return 0; | 289 | return 0; |
301 | } | 290 | } |
302 | 291 | ||
303 | static const struct dev_pm_ops apds9802als_pm_ops = { | 292 | static UNIVERSAL_DEV_PM_OPS(apds9802als_pm_ops, apds9802als_suspend, |
304 | .runtime_suspend = apds9802als_runtime_suspend, | 293 | apds9802als_resume, NULL); |
305 | .runtime_resume = apds9802als_runtime_resume, | ||
306 | }; | ||
307 | 294 | ||
308 | #define APDS9802ALS_PM_OPS (&apds9802als_pm_ops) | 295 | #define APDS9802ALS_PM_OPS (&apds9802als_pm_ops) |
309 | 296 | ||
310 | #else /* CONFIG_PM */ | 297 | #else /* CONFIG_PM */ |
311 | #define apds9802als_suspend NULL | ||
312 | #define apds9802als_resume NULL | ||
313 | #define APDS9802ALS_PM_OPS NULL | 298 | #define APDS9802ALS_PM_OPS NULL |
314 | #endif /* CONFIG_PM */ | 299 | #endif /* CONFIG_PM */ |
315 | 300 | ||
@@ -327,8 +312,6 @@ static struct i2c_driver apds9802als_driver = { | |||
327 | }, | 312 | }, |
328 | .probe = apds9802als_probe, | 313 | .probe = apds9802als_probe, |
329 | .remove = apds9802als_remove, | 314 | .remove = apds9802als_remove, |
330 | .suspend = apds9802als_suspend, | ||
331 | .resume = apds9802als_resume, | ||
332 | .id_table = apds9802als_id, | 315 | .id_table = apds9802als_id, |
333 | }; | 316 | }; |
334 | 317 | ||
diff --git a/drivers/misc/apds990x.c b/drivers/misc/apds990x.c index 0e67f8263cd8..98f9bb26492a 100644 --- a/drivers/misc/apds990x.c +++ b/drivers/misc/apds990x.c | |||
@@ -700,9 +700,6 @@ static ssize_t apds990x_lux_calib_store(struct device *dev, | |||
700 | if (strict_strtoul(buf, 0, &value)) | 700 | if (strict_strtoul(buf, 0, &value)) |
701 | return -EINVAL; | 701 | return -EINVAL; |
702 | 702 | ||
703 | if (chip->lux_calib > APDS_RANGE) | ||
704 | return -EINVAL; | ||
705 | |||
706 | chip->lux_calib = value; | 703 | chip->lux_calib = value; |
707 | 704 | ||
708 | return len; | 705 | return len; |
@@ -1204,7 +1201,7 @@ static int apds990x_remove(struct i2c_client *client) | |||
1204 | return 0; | 1201 | return 0; |
1205 | } | 1202 | } |
1206 | 1203 | ||
1207 | #ifdef CONFIG_PM | 1204 | #ifdef CONFIG_PM_SLEEP |
1208 | static int apds990x_suspend(struct device *dev) | 1205 | static int apds990x_suspend(struct device *dev) |
1209 | { | 1206 | { |
1210 | struct i2c_client *client = container_of(dev, struct i2c_client, dev); | 1207 | struct i2c_client *client = container_of(dev, struct i2c_client, dev); |
@@ -1227,10 +1224,6 @@ static int apds990x_resume(struct device *dev) | |||
1227 | 1224 | ||
1228 | return 0; | 1225 | return 0; |
1229 | } | 1226 | } |
1230 | #else | ||
1231 | #define apds990x_suspend NULL | ||
1232 | #define apds990x_resume NULL | ||
1233 | #define apds990x_shutdown NULL | ||
1234 | #endif | 1227 | #endif |
1235 | 1228 | ||
1236 | #ifdef CONFIG_PM_RUNTIME | 1229 | #ifdef CONFIG_PM_RUNTIME |
diff --git a/drivers/misc/arm-charlcd.c b/drivers/misc/arm-charlcd.c index fe8616a8d287..48651ef0028c 100644 --- a/drivers/misc/arm-charlcd.c +++ b/drivers/misc/arm-charlcd.c | |||
@@ -378,18 +378,7 @@ static struct platform_driver charlcd_driver = { | |||
378 | .remove = __exit_p(charlcd_remove), | 378 | .remove = __exit_p(charlcd_remove), |
379 | }; | 379 | }; |
380 | 380 | ||
381 | static int __init charlcd_init(void) | 381 | module_platform_driver_probe(charlcd_driver, charlcd_probe); |
382 | { | ||
383 | return platform_driver_probe(&charlcd_driver, charlcd_probe); | ||
384 | } | ||
385 | |||
386 | static void __exit charlcd_exit(void) | ||
387 | { | ||
388 | platform_driver_unregister(&charlcd_driver); | ||
389 | } | ||
390 | |||
391 | module_init(charlcd_init); | ||
392 | module_exit(charlcd_exit); | ||
393 | 382 | ||
394 | MODULE_AUTHOR("Linus Walleij <triad@df.lth.se>"); | 383 | MODULE_AUTHOR("Linus Walleij <triad@df.lth.se>"); |
395 | MODULE_DESCRIPTION("ARM Character LCD Driver"); | 384 | MODULE_DESCRIPTION("ARM Character LCD Driver"); |
diff --git a/drivers/misc/atmel_pwm.c b/drivers/misc/atmel_pwm.c index 28f5aaa19d4a..494d0500bda6 100644 --- a/drivers/misc/atmel_pwm.c +++ b/drivers/misc/atmel_pwm.c | |||
@@ -393,17 +393,7 @@ static struct platform_driver atmel_pwm_driver = { | |||
393 | */ | 393 | */ |
394 | }; | 394 | }; |
395 | 395 | ||
396 | static int __init pwm_init(void) | 396 | module_platform_driver_probe(atmel_pwm_driver, pwm_probe); |
397 | { | ||
398 | return platform_driver_probe(&atmel_pwm_driver, pwm_probe); | ||
399 | } | ||
400 | module_init(pwm_init); | ||
401 | |||
402 | static void __exit pwm_exit(void) | ||
403 | { | ||
404 | platform_driver_unregister(&atmel_pwm_driver); | ||
405 | } | ||
406 | module_exit(pwm_exit); | ||
407 | 397 | ||
408 | MODULE_DESCRIPTION("Driver for AT32/AT91 PWM module"); | 398 | MODULE_DESCRIPTION("Driver for AT32/AT91 PWM module"); |
409 | MODULE_LICENSE("GPL"); | 399 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/misc/bh1770glc.c b/drivers/misc/bh1770glc.c index 2ed8fc3be7e6..f4975f7d0d5b 100644 --- a/drivers/misc/bh1770glc.c +++ b/drivers/misc/bh1770glc.c | |||
@@ -1310,7 +1310,7 @@ static int bh1770_remove(struct i2c_client *client) | |||
1310 | return 0; | 1310 | return 0; |
1311 | } | 1311 | } |
1312 | 1312 | ||
1313 | #ifdef CONFIG_PM | 1313 | #ifdef CONFIG_PM_SLEEP |
1314 | static int bh1770_suspend(struct device *dev) | 1314 | static int bh1770_suspend(struct device *dev) |
1315 | { | 1315 | { |
1316 | struct i2c_client *client = container_of(dev, struct i2c_client, dev); | 1316 | struct i2c_client *client = container_of(dev, struct i2c_client, dev); |
@@ -1346,11 +1346,6 @@ static int bh1770_resume(struct device *dev) | |||
1346 | } | 1346 | } |
1347 | return ret; | 1347 | return ret; |
1348 | } | 1348 | } |
1349 | |||
1350 | #else | ||
1351 | #define bh1770_suspend NULL | ||
1352 | #define bh1770_shutdown NULL | ||
1353 | #define bh1770_resume NULL | ||
1354 | #endif | 1349 | #endif |
1355 | 1350 | ||
1356 | #ifdef CONFIG_PM_RUNTIME | 1351 | #ifdef CONFIG_PM_RUNTIME |
diff --git a/drivers/misc/bh1780gli.c b/drivers/misc/bh1780gli.c index cf03d0abf33e..818f3a0e62bf 100644 --- a/drivers/misc/bh1780gli.c +++ b/drivers/misc/bh1780gli.c | |||
@@ -196,7 +196,7 @@ static int bh1780_remove(struct i2c_client *client) | |||
196 | return 0; | 196 | return 0; |
197 | } | 197 | } |
198 | 198 | ||
199 | #ifdef CONFIG_PM | 199 | #ifdef CONFIG_PM_SLEEP |
200 | static int bh1780_suspend(struct device *dev) | 200 | static int bh1780_suspend(struct device *dev) |
201 | { | 201 | { |
202 | struct bh1780_data *ddata; | 202 | struct bh1780_data *ddata; |
@@ -235,11 +235,9 @@ static int bh1780_resume(struct device *dev) | |||
235 | 235 | ||
236 | return 0; | 236 | return 0; |
237 | } | 237 | } |
238 | #endif /* CONFIG_PM_SLEEP */ | ||
239 | |||
238 | static SIMPLE_DEV_PM_OPS(bh1780_pm, bh1780_suspend, bh1780_resume); | 240 | static SIMPLE_DEV_PM_OPS(bh1780_pm, bh1780_suspend, bh1780_resume); |
239 | #define BH1780_PMOPS (&bh1780_pm) | ||
240 | #else | ||
241 | #define BH1780_PMOPS NULL | ||
242 | #endif /* CONFIG_PM */ | ||
243 | 241 | ||
244 | static const struct i2c_device_id bh1780_id[] = { | 242 | static const struct i2c_device_id bh1780_id[] = { |
245 | { "bh1780", 0 }, | 243 | { "bh1780", 0 }, |
@@ -252,7 +250,7 @@ static struct i2c_driver bh1780_driver = { | |||
252 | .id_table = bh1780_id, | 250 | .id_table = bh1780_id, |
253 | .driver = { | 251 | .driver = { |
254 | .name = "bh1780", | 252 | .name = "bh1780", |
255 | .pm = BH1780_PMOPS, | 253 | .pm = &bh1780_pm, |
256 | }, | 254 | }, |
257 | }; | 255 | }; |
258 | 256 | ||
diff --git a/drivers/misc/cs5535-mfgpt.c b/drivers/misc/cs5535-mfgpt.c index 9858f36dad8b..effd8c6b2b94 100644 --- a/drivers/misc/cs5535-mfgpt.c +++ b/drivers/misc/cs5535-mfgpt.c | |||
@@ -24,8 +24,11 @@ | |||
24 | 24 | ||
25 | static int mfgpt_reset_timers; | 25 | static int mfgpt_reset_timers; |
26 | module_param_named(mfgptfix, mfgpt_reset_timers, int, 0644); | 26 | module_param_named(mfgptfix, mfgpt_reset_timers, int, 0644); |
27 | MODULE_PARM_DESC(mfgptfix, "Reset the MFGPT timers during init; " | 27 | MODULE_PARM_DESC(mfgptfix, "Try to reset the MFGPT timers during init; " |
28 | "required by some broken BIOSes (ie, TinyBIOS < 0.99)."); | 28 | "required by some broken BIOSes (ie, TinyBIOS < 0.99) or kexec " |
29 | "(1 = reset the MFGPT using an undocumented bit, " | ||
30 | "2 = perform a soft reset by unconfiguring all timers); " | ||
31 | "use what works best for you."); | ||
29 | 32 | ||
30 | struct cs5535_mfgpt_timer { | 33 | struct cs5535_mfgpt_timer { |
31 | struct cs5535_mfgpt_chip *chip; | 34 | struct cs5535_mfgpt_chip *chip; |
@@ -256,6 +259,28 @@ static void reset_all_timers(void) | |||
256 | } | 259 | } |
257 | 260 | ||
258 | /* | 261 | /* |
262 | * This is another sledgehammer to reset all MFGPT timers. | ||
263 | * Instead of using the undocumented bit method it clears | ||
264 | * IRQ, NMI and RESET settings. | ||
265 | */ | ||
266 | static void soft_reset(void) | ||
267 | { | ||
268 | int i; | ||
269 | struct cs5535_mfgpt_timer t; | ||
270 | |||
271 | for (i = 0; i < MFGPT_MAX_TIMERS; i++) { | ||
272 | t.nr = i; | ||
273 | |||
274 | cs5535_mfgpt_toggle_event(&t, MFGPT_CMP1, MFGPT_EVENT_RESET, 0); | ||
275 | cs5535_mfgpt_toggle_event(&t, MFGPT_CMP2, MFGPT_EVENT_RESET, 0); | ||
276 | cs5535_mfgpt_toggle_event(&t, MFGPT_CMP1, MFGPT_EVENT_NMI, 0); | ||
277 | cs5535_mfgpt_toggle_event(&t, MFGPT_CMP2, MFGPT_EVENT_NMI, 0); | ||
278 | cs5535_mfgpt_toggle_event(&t, MFGPT_CMP1, MFGPT_EVENT_IRQ, 0); | ||
279 | cs5535_mfgpt_toggle_event(&t, MFGPT_CMP2, MFGPT_EVENT_IRQ, 0); | ||
280 | } | ||
281 | } | ||
282 | |||
283 | /* | ||
259 | * Check whether any MFGPTs are available for the kernel to use. In most | 284 | * Check whether any MFGPTs are available for the kernel to use. In most |
260 | * cases, firmware that uses AMD's VSA code will claim all timers during | 285 | * cases, firmware that uses AMD's VSA code will claim all timers during |
261 | * bootup; we certainly don't want to take them if they're already in use. | 286 | * bootup; we certainly don't want to take them if they're already in use. |
@@ -271,15 +296,17 @@ static int scan_timers(struct cs5535_mfgpt_chip *mfgpt) | |||
271 | int i; | 296 | int i; |
272 | 297 | ||
273 | /* bios workaround */ | 298 | /* bios workaround */ |
274 | if (mfgpt_reset_timers) | 299 | if (mfgpt_reset_timers == 1) |
275 | reset_all_timers(); | 300 | reset_all_timers(); |
301 | else if (mfgpt_reset_timers == 2) | ||
302 | soft_reset(); | ||
276 | 303 | ||
277 | /* just to be safe, protect this section w/ lock */ | 304 | /* just to be safe, protect this section w/ lock */ |
278 | spin_lock_irqsave(&mfgpt->lock, flags); | 305 | spin_lock_irqsave(&mfgpt->lock, flags); |
279 | for (i = 0; i < MFGPT_MAX_TIMERS; i++) { | 306 | for (i = 0; i < MFGPT_MAX_TIMERS; i++) { |
280 | timer.nr = i; | 307 | timer.nr = i; |
281 | val = cs5535_mfgpt_read(&timer, MFGPT_REG_SETUP); | 308 | val = cs5535_mfgpt_read(&timer, MFGPT_REG_SETUP); |
282 | if (!(val & MFGPT_SETUP_SETUP)) { | 309 | if (!(val & MFGPT_SETUP_SETUP) || mfgpt_reset_timers == 2) { |
283 | __set_bit(i, mfgpt->avail); | 310 | __set_bit(i, mfgpt->avail); |
284 | timers++; | 311 | timers++; |
285 | } | 312 | } |
@@ -294,6 +321,12 @@ static int cs5535_mfgpt_probe(struct platform_device *pdev) | |||
294 | struct resource *res; | 321 | struct resource *res; |
295 | int err = -EIO, t; | 322 | int err = -EIO, t; |
296 | 323 | ||
324 | if (mfgpt_reset_timers < 0 || mfgpt_reset_timers > 2) { | ||
325 | dev_err(&pdev->dev, "Bad mfgpt_reset_timers value: %i\n", | ||
326 | mfgpt_reset_timers); | ||
327 | goto done; | ||
328 | } | ||
329 | |||
297 | /* There are two ways to get the MFGPT base address; one is by | 330 | /* There are two ways to get the MFGPT base address; one is by |
298 | * fetching it from MSR_LBAR_MFGPT, the other is by reading the | 331 | * fetching it from MSR_LBAR_MFGPT, the other is by reading the |
299 | * PCI BAR info. The latter method is easier (especially across | 332 | * PCI BAR info. The latter method is easier (especially across |
diff --git a/drivers/misc/dummy-irq.c b/drivers/misc/dummy-irq.c new file mode 100644 index 000000000000..7014167e2c61 --- /dev/null +++ b/drivers/misc/dummy-irq.c | |||
@@ -0,0 +1,59 @@ | |||
1 | /* | ||
2 | * Dummy IRQ handler driver. | ||
3 | * | ||
4 | * This module only registers itself as a handler that is specified to it | ||
5 | * by the 'irq' parameter. | ||
6 | * | ||
7 | * The sole purpose of this module is to help with debugging of systems on | ||
8 | * which spurious IRQs would happen on disabled IRQ vector. | ||
9 | * | ||
10 | * Copyright (C) 2013 Jiri Kosina | ||
11 | */ | ||
12 | |||
13 | /* | ||
14 | * This program is free software; you can redistribute it and/or modify it | ||
15 | * under the terms of the GNU General Public License version 2 as published by | ||
16 | * the Free Software Foundation. | ||
17 | */ | ||
18 | #include <linux/module.h> | ||
19 | #include <linux/irq.h> | ||
20 | #include <linux/interrupt.h> | ||
21 | |||
22 | static int irq; | ||
23 | |||
24 | static irqreturn_t dummy_interrupt(int irq, void *dev_id) | ||
25 | { | ||
26 | static int count = 0; | ||
27 | |||
28 | if (count == 0) { | ||
29 | printk(KERN_INFO "dummy-irq: interrupt occured on IRQ %d\n", | ||
30 | irq); | ||
31 | count++; | ||
32 | } | ||
33 | |||
34 | return IRQ_NONE; | ||
35 | } | ||
36 | |||
37 | static int __init dummy_irq_init(void) | ||
38 | { | ||
39 | if (request_irq(irq, &dummy_interrupt, IRQF_SHARED, "dummy_irq", &irq)) { | ||
40 | printk(KERN_ERR "dummy-irq: cannot register IRQ %d\n", irq); | ||
41 | return -EIO; | ||
42 | } | ||
43 | printk(KERN_INFO "dummy-irq: registered for IRQ %d\n", irq); | ||
44 | return 0; | ||
45 | } | ||
46 | |||
47 | static void __exit dummy_irq_exit(void) | ||
48 | { | ||
49 | printk(KERN_INFO "dummy-irq unloaded\n"); | ||
50 | free_irq(irq, &irq); | ||
51 | } | ||
52 | |||
53 | module_init(dummy_irq_init); | ||
54 | module_exit(dummy_irq_exit); | ||
55 | |||
56 | MODULE_LICENSE("GPL"); | ||
57 | MODULE_AUTHOR("Jiri Kosina"); | ||
58 | module_param(irq, uint, 0444); | ||
59 | MODULE_PARM_DESC(irq, "The IRQ to register for"); | ||
diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c index b08cf8a08789..ad8fd8e64937 100644 --- a/drivers/misc/eeprom/at25.c +++ b/drivers/misc/eeprom/at25.c | |||
@@ -412,7 +412,7 @@ static int at25_probe(struct spi_device *spi) | |||
412 | mutex_init(&at25->lock); | 412 | mutex_init(&at25->lock); |
413 | at25->chip = chip; | 413 | at25->chip = chip; |
414 | at25->spi = spi_dev_get(spi); | 414 | at25->spi = spi_dev_get(spi); |
415 | dev_set_drvdata(&spi->dev, at25); | 415 | spi_set_drvdata(spi, at25); |
416 | at25->addrlen = addrlen; | 416 | at25->addrlen = addrlen; |
417 | 417 | ||
418 | /* Export the EEPROM bytes through sysfs, since that's convenient. | 418 | /* Export the EEPROM bytes through sysfs, since that's convenient. |
@@ -463,7 +463,7 @@ static int at25_remove(struct spi_device *spi) | |||
463 | { | 463 | { |
464 | struct at25_data *at25; | 464 | struct at25_data *at25; |
465 | 465 | ||
466 | at25 = dev_get_drvdata(&spi->dev); | 466 | at25 = spi_get_drvdata(spi); |
467 | sysfs_remove_bin_file(&spi->dev.kobj, &at25->bin); | 467 | sysfs_remove_bin_file(&spi->dev.kobj, &at25->bin); |
468 | kfree(at25); | 468 | kfree(at25); |
469 | return 0; | 469 | return 0; |
diff --git a/drivers/misc/eeprom/eeprom_93xx46.c b/drivers/misc/eeprom/eeprom_93xx46.c index a6b5d5e73485..94cfc1212577 100644 --- a/drivers/misc/eeprom/eeprom_93xx46.c +++ b/drivers/misc/eeprom/eeprom_93xx46.c | |||
@@ -363,7 +363,7 @@ static int eeprom_93xx46_probe(struct spi_device *spi) | |||
363 | dev_err(&spi->dev, "can't create erase interface\n"); | 363 | dev_err(&spi->dev, "can't create erase interface\n"); |
364 | } | 364 | } |
365 | 365 | ||
366 | dev_set_drvdata(&spi->dev, edev); | 366 | spi_set_drvdata(spi, edev); |
367 | return 0; | 367 | return 0; |
368 | fail: | 368 | fail: |
369 | kfree(edev); | 369 | kfree(edev); |
@@ -372,13 +372,13 @@ fail: | |||
372 | 372 | ||
373 | static int eeprom_93xx46_remove(struct spi_device *spi) | 373 | static int eeprom_93xx46_remove(struct spi_device *spi) |
374 | { | 374 | { |
375 | struct eeprom_93xx46_dev *edev = dev_get_drvdata(&spi->dev); | 375 | struct eeprom_93xx46_dev *edev = spi_get_drvdata(spi); |
376 | 376 | ||
377 | if (!(edev->pdata->flags & EE_READONLY)) | 377 | if (!(edev->pdata->flags & EE_READONLY)) |
378 | device_remove_file(&spi->dev, &dev_attr_erase); | 378 | device_remove_file(&spi->dev, &dev_attr_erase); |
379 | 379 | ||
380 | sysfs_remove_bin_file(&spi->dev.kobj, &edev->bin); | 380 | sysfs_remove_bin_file(&spi->dev.kobj, &edev->bin); |
381 | dev_set_drvdata(&spi->dev, NULL); | 381 | spi_set_drvdata(spi, NULL); |
382 | kfree(edev); | 382 | kfree(edev); |
383 | return 0; | 383 | return 0; |
384 | } | 384 | } |
diff --git a/drivers/misc/ep93xx_pwm.c b/drivers/misc/ep93xx_pwm.c index 16d7179e2f9b..96787ec15cad 100644 --- a/drivers/misc/ep93xx_pwm.c +++ b/drivers/misc/ep93xx_pwm.c | |||
@@ -365,18 +365,7 @@ static struct platform_driver ep93xx_pwm_driver = { | |||
365 | .remove = __exit_p(ep93xx_pwm_remove), | 365 | .remove = __exit_p(ep93xx_pwm_remove), |
366 | }; | 366 | }; |
367 | 367 | ||
368 | static int __init ep93xx_pwm_init(void) | 368 | module_platform_driver_probe(ep93xx_pwm_driver, ep93xx_pwm_probe); |
369 | { | ||
370 | return platform_driver_probe(&ep93xx_pwm_driver, ep93xx_pwm_probe); | ||
371 | } | ||
372 | |||
373 | static void __exit ep93xx_pwm_exit(void) | ||
374 | { | ||
375 | platform_driver_unregister(&ep93xx_pwm_driver); | ||
376 | } | ||
377 | |||
378 | module_init(ep93xx_pwm_init); | ||
379 | module_exit(ep93xx_pwm_exit); | ||
380 | 369 | ||
381 | MODULE_AUTHOR("Matthieu Crapet <mcrapet@gmail.com>, " | 370 | MODULE_AUTHOR("Matthieu Crapet <mcrapet@gmail.com>, " |
382 | "H Hartley Sweeten <hsweeten@visionengravers.com>"); | 371 | "H Hartley Sweeten <hsweeten@visionengravers.com>"); |
diff --git a/drivers/misc/fsa9480.c b/drivers/misc/fsa9480.c index e8cbb1c59f4c..a725c79c35f5 100644 --- a/drivers/misc/fsa9480.c +++ b/drivers/misc/fsa9480.c | |||
@@ -474,10 +474,11 @@ static int fsa9480_remove(struct i2c_client *client) | |||
474 | return 0; | 474 | return 0; |
475 | } | 475 | } |
476 | 476 | ||
477 | #ifdef CONFIG_PM | 477 | #ifdef CONFIG_PM_SLEEP |
478 | 478 | ||
479 | static int fsa9480_suspend(struct i2c_client *client, pm_message_t state) | 479 | static int fsa9480_suspend(struct device *dev) |
480 | { | 480 | { |
481 | struct i2c_client *client = to_i2c_client(dev); | ||
481 | struct fsa9480_usbsw *usbsw = i2c_get_clientdata(client); | 482 | struct fsa9480_usbsw *usbsw = i2c_get_clientdata(client); |
482 | struct fsa9480_platform_data *pdata = usbsw->pdata; | 483 | struct fsa9480_platform_data *pdata = usbsw->pdata; |
483 | 484 | ||
@@ -490,8 +491,9 @@ static int fsa9480_suspend(struct i2c_client *client, pm_message_t state) | |||
490 | return 0; | 491 | return 0; |
491 | } | 492 | } |
492 | 493 | ||
493 | static int fsa9480_resume(struct i2c_client *client) | 494 | static int fsa9480_resume(struct device *dev) |
494 | { | 495 | { |
496 | struct i2c_client *client = to_i2c_client(dev); | ||
495 | struct fsa9480_usbsw *usbsw = i2c_get_clientdata(client); | 497 | struct fsa9480_usbsw *usbsw = i2c_get_clientdata(client); |
496 | int dev1, dev2; | 498 | int dev1, dev2; |
497 | 499 | ||
@@ -515,12 +517,14 @@ static int fsa9480_resume(struct i2c_client *client) | |||
515 | return 0; | 517 | return 0; |
516 | } | 518 | } |
517 | 519 | ||
520 | static SIMPLE_DEV_PM_OPS(fsa9480_pm_ops, fsa9480_suspend, fsa9480_resume); | ||
521 | #define FSA9480_PM_OPS (&fsa9480_pm_ops) | ||
522 | |||
518 | #else | 523 | #else |
519 | 524 | ||
520 | #define fsa9480_suspend NULL | 525 | #define FSA9480_PM_OPS NULL |
521 | #define fsa9480_resume NULL | ||
522 | 526 | ||
523 | #endif /* CONFIG_PM */ | 527 | #endif /* CONFIG_PM_SLEEP */ |
524 | 528 | ||
525 | static const struct i2c_device_id fsa9480_id[] = { | 529 | static const struct i2c_device_id fsa9480_id[] = { |
526 | {"fsa9480", 0}, | 530 | {"fsa9480", 0}, |
@@ -531,11 +535,10 @@ MODULE_DEVICE_TABLE(i2c, fsa9480_id); | |||
531 | static struct i2c_driver fsa9480_i2c_driver = { | 535 | static struct i2c_driver fsa9480_i2c_driver = { |
532 | .driver = { | 536 | .driver = { |
533 | .name = "fsa9480", | 537 | .name = "fsa9480", |
538 | .pm = FSA9480_PM_OPS, | ||
534 | }, | 539 | }, |
535 | .probe = fsa9480_probe, | 540 | .probe = fsa9480_probe, |
536 | .remove = fsa9480_remove, | 541 | .remove = fsa9480_remove, |
537 | .resume = fsa9480_resume, | ||
538 | .suspend = fsa9480_suspend, | ||
539 | .id_table = fsa9480_id, | 542 | .id_table = fsa9480_id, |
540 | }; | 543 | }; |
541 | 544 | ||
diff --git a/drivers/misc/isl29003.c b/drivers/misc/isl29003.c index 29b306c6bdb3..c5145b3fcce8 100644 --- a/drivers/misc/isl29003.c +++ b/drivers/misc/isl29003.c | |||
@@ -409,18 +409,20 @@ static int isl29003_remove(struct i2c_client *client) | |||
409 | return 0; | 409 | return 0; |
410 | } | 410 | } |
411 | 411 | ||
412 | #ifdef CONFIG_PM | 412 | #ifdef CONFIG_PM_SLEEP |
413 | static int isl29003_suspend(struct i2c_client *client, pm_message_t mesg) | 413 | static int isl29003_suspend(struct device *dev) |
414 | { | 414 | { |
415 | struct i2c_client *client = to_i2c_client(dev); | ||
415 | struct isl29003_data *data = i2c_get_clientdata(client); | 416 | struct isl29003_data *data = i2c_get_clientdata(client); |
416 | 417 | ||
417 | data->power_state_before_suspend = isl29003_get_power_state(client); | 418 | data->power_state_before_suspend = isl29003_get_power_state(client); |
418 | return isl29003_set_power_state(client, 0); | 419 | return isl29003_set_power_state(client, 0); |
419 | } | 420 | } |
420 | 421 | ||
421 | static int isl29003_resume(struct i2c_client *client) | 422 | static int isl29003_resume(struct device *dev) |
422 | { | 423 | { |
423 | int i; | 424 | int i; |
425 | struct i2c_client *client = to_i2c_client(dev); | ||
424 | struct isl29003_data *data = i2c_get_clientdata(client); | 426 | struct isl29003_data *data = i2c_get_clientdata(client); |
425 | 427 | ||
426 | /* restore registers from cache */ | 428 | /* restore registers from cache */ |
@@ -432,10 +434,12 @@ static int isl29003_resume(struct i2c_client *client) | |||
432 | data->power_state_before_suspend); | 434 | data->power_state_before_suspend); |
433 | } | 435 | } |
434 | 436 | ||
437 | static SIMPLE_DEV_PM_OPS(isl29003_pm_ops, isl29003_suspend, isl29003_resume); | ||
438 | #define ISL29003_PM_OPS (&isl29003_pm_ops) | ||
439 | |||
435 | #else | 440 | #else |
436 | #define isl29003_suspend NULL | 441 | #define ISL29003_PM_OPS NULL |
437 | #define isl29003_resume NULL | 442 | #endif /* CONFIG_PM_SLEEP */ |
438 | #endif /* CONFIG_PM */ | ||
439 | 443 | ||
440 | static const struct i2c_device_id isl29003_id[] = { | 444 | static const struct i2c_device_id isl29003_id[] = { |
441 | { "isl29003", 0 }, | 445 | { "isl29003", 0 }, |
@@ -447,9 +451,8 @@ static struct i2c_driver isl29003_driver = { | |||
447 | .driver = { | 451 | .driver = { |
448 | .name = ISL29003_DRV_NAME, | 452 | .name = ISL29003_DRV_NAME, |
449 | .owner = THIS_MODULE, | 453 | .owner = THIS_MODULE, |
454 | .pm = ISL29003_PM_OPS, | ||
450 | }, | 455 | }, |
451 | .suspend = isl29003_suspend, | ||
452 | .resume = isl29003_resume, | ||
453 | .probe = isl29003_probe, | 456 | .probe = isl29003_probe, |
454 | .remove = isl29003_remove, | 457 | .remove = isl29003_remove, |
455 | .id_table = isl29003_id, | 458 | .id_table = isl29003_id, |
diff --git a/drivers/misc/lattice-ecp3-config.c b/drivers/misc/lattice-ecp3-config.c index 155700bfd2b6..bb26f086bd8b 100644 --- a/drivers/misc/lattice-ecp3-config.c +++ b/drivers/misc/lattice-ecp3-config.c | |||
@@ -69,7 +69,7 @@ static const struct ecp3_dev ecp3_dev[] = { | |||
69 | static void firmware_load(const struct firmware *fw, void *context) | 69 | static void firmware_load(const struct firmware *fw, void *context) |
70 | { | 70 | { |
71 | struct spi_device *spi = (struct spi_device *)context; | 71 | struct spi_device *spi = (struct spi_device *)context; |
72 | struct fpga_data *data = dev_get_drvdata(&spi->dev); | 72 | struct fpga_data *data = spi_get_drvdata(spi); |
73 | u8 *buffer; | 73 | u8 *buffer; |
74 | int ret; | 74 | int ret; |
75 | u8 txbuf[8]; | 75 | u8 txbuf[8]; |
diff --git a/drivers/misc/mei/Kconfig b/drivers/misc/mei/Kconfig index d21b4d006a55..c76fa31e9bf6 100644 --- a/drivers/misc/mei/Kconfig +++ b/drivers/misc/mei/Kconfig | |||
@@ -10,10 +10,9 @@ config INTEL_MEI | |||
10 | <http://software.intel.com/en-us/manageability/> | 10 | <http://software.intel.com/en-us/manageability/> |
11 | 11 | ||
12 | config INTEL_MEI_ME | 12 | config INTEL_MEI_ME |
13 | bool "ME Enabled Intel Chipsets" | 13 | tristate "ME Enabled Intel Chipsets" |
14 | depends on INTEL_MEI | 14 | select INTEL_MEI |
15 | depends on X86 && PCI && WATCHDOG_CORE | 15 | depends on X86 && PCI && WATCHDOG_CORE |
16 | default y | ||
17 | help | 16 | help |
18 | MEI support for ME Enabled Intel chipsets. | 17 | MEI support for ME Enabled Intel chipsets. |
19 | 18 | ||
diff --git a/drivers/misc/mei/Makefile b/drivers/misc/mei/Makefile index 040af6c7b147..08698a466268 100644 --- a/drivers/misc/mei/Makefile +++ b/drivers/misc/mei/Makefile | |||
@@ -10,5 +10,10 @@ mei-objs += client.o | |||
10 | mei-objs += main.o | 10 | mei-objs += main.o |
11 | mei-objs += amthif.o | 11 | mei-objs += amthif.o |
12 | mei-objs += wd.o | 12 | mei-objs += wd.o |
13 | mei-$(CONFIG_INTEL_MEI_ME) += pci-me.o | 13 | mei-objs += bus.o |
14 | mei-$(CONFIG_INTEL_MEI_ME) += hw-me.o | 14 | mei-objs += nfc.o |
15 | mei-$(CONFIG_DEBUG_FS) += debugfs.o | ||
16 | |||
17 | obj-$(CONFIG_INTEL_MEI_ME) += mei-me.o | ||
18 | mei-me-objs := pci-me.o | ||
19 | mei-me-objs += hw-me.o | ||
diff --git a/drivers/misc/mei/amthif.c b/drivers/misc/mei/amthif.c index c86d7e3839a4..31a6212cb8b1 100644 --- a/drivers/misc/mei/amthif.c +++ b/drivers/misc/mei/amthif.c | |||
@@ -449,7 +449,7 @@ int mei_amthif_irq_write_complete(struct mei_device *dev, s32 *slots, | |||
449 | struct mei_msg_hdr mei_hdr; | 449 | struct mei_msg_hdr mei_hdr; |
450 | struct mei_cl *cl = cb->cl; | 450 | struct mei_cl *cl = cb->cl; |
451 | size_t len = dev->iamthif_msg_buf_size - dev->iamthif_msg_buf_index; | 451 | size_t len = dev->iamthif_msg_buf_size - dev->iamthif_msg_buf_index; |
452 | size_t msg_slots = mei_data2slots(len); | 452 | u32 msg_slots = mei_data2slots(len); |
453 | 453 | ||
454 | mei_hdr.host_addr = cl->host_client_id; | 454 | mei_hdr.host_addr = cl->host_client_id; |
455 | mei_hdr.me_addr = cl->me_client_id; | 455 | mei_hdr.me_addr = cl->me_client_id; |
@@ -505,14 +505,15 @@ int mei_amthif_irq_write_complete(struct mei_device *dev, s32 *slots, | |||
505 | * mei_amthif_irq_read_message - read routine after ISR to | 505 | * mei_amthif_irq_read_message - read routine after ISR to |
506 | * handle the read amthif message | 506 | * handle the read amthif message |
507 | * | 507 | * |
508 | * @complete_list: An instance of our list structure | ||
509 | * @dev: the device structure | 508 | * @dev: the device structure |
510 | * @mei_hdr: header of amthif message | 509 | * @mei_hdr: header of amthif message |
510 | * @complete_list: An instance of our list structure | ||
511 | * | 511 | * |
512 | * returns 0 on success, <0 on failure. | 512 | * returns 0 on success, <0 on failure. |
513 | */ | 513 | */ |
514 | int mei_amthif_irq_read_message(struct mei_cl_cb *complete_list, | 514 | int mei_amthif_irq_read_msg(struct mei_device *dev, |
515 | struct mei_device *dev, struct mei_msg_hdr *mei_hdr) | 515 | struct mei_msg_hdr *mei_hdr, |
516 | struct mei_cl_cb *complete_list) | ||
516 | { | 517 | { |
517 | struct mei_cl_cb *cb; | 518 | struct mei_cl_cb *cb; |
518 | unsigned char *buffer; | 519 | unsigned char *buffer; |
@@ -530,8 +531,7 @@ int mei_amthif_irq_read_message(struct mei_cl_cb *complete_list, | |||
530 | if (!mei_hdr->msg_complete) | 531 | if (!mei_hdr->msg_complete) |
531 | return 0; | 532 | return 0; |
532 | 533 | ||
533 | dev_dbg(&dev->pdev->dev, | 534 | dev_dbg(&dev->pdev->dev, "amthif_message_buffer_index =%d\n", |
534 | "amthif_message_buffer_index =%d\n", | ||
535 | mei_hdr->length); | 535 | mei_hdr->length); |
536 | 536 | ||
537 | dev_dbg(&dev->pdev->dev, "completed amthif read.\n "); | 537 | dev_dbg(&dev->pdev->dev, "completed amthif read.\n "); |
@@ -566,12 +566,13 @@ int mei_amthif_irq_read_message(struct mei_cl_cb *complete_list, | |||
566 | */ | 566 | */ |
567 | int mei_amthif_irq_read(struct mei_device *dev, s32 *slots) | 567 | int mei_amthif_irq_read(struct mei_device *dev, s32 *slots) |
568 | { | 568 | { |
569 | u32 msg_slots = mei_data2slots(sizeof(struct hbm_flow_control)); | ||
569 | 570 | ||
570 | if (((*slots) * sizeof(u32)) < (sizeof(struct mei_msg_hdr) | 571 | if (*slots < msg_slots) |
571 | + sizeof(struct hbm_flow_control))) { | ||
572 | return -EMSGSIZE; | 572 | return -EMSGSIZE; |
573 | } | 573 | |
574 | *slots -= mei_data2slots(sizeof(struct hbm_flow_control)); | 574 | *slots -= msg_slots; |
575 | |||
575 | if (mei_hbm_cl_flow_control_req(dev, &dev->iamthif_cl)) { | 576 | if (mei_hbm_cl_flow_control_req(dev, &dev->iamthif_cl)) { |
576 | dev_dbg(&dev->pdev->dev, "iamthif flow control failed\n"); | 577 | dev_dbg(&dev->pdev->dev, "iamthif flow control failed\n"); |
577 | return -EIO; | 578 | return -EIO; |
diff --git a/drivers/misc/mei/bus.c b/drivers/misc/mei/bus.c new file mode 100644 index 000000000000..1e935eacaa7f --- /dev/null +++ b/drivers/misc/mei/bus.c | |||
@@ -0,0 +1,528 @@ | |||
1 | /* | ||
2 | * Intel Management Engine Interface (Intel MEI) Linux driver | ||
3 | * Copyright (c) 2012-2013, Intel Corporation. | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify it | ||
6 | * under the terms and conditions of the GNU General Public License, | ||
7 | * version 2, as published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
12 | * more details. | ||
13 | * | ||
14 | */ | ||
15 | |||
16 | #include <linux/module.h> | ||
17 | #include <linux/device.h> | ||
18 | #include <linux/kernel.h> | ||
19 | #include <linux/sched.h> | ||
20 | #include <linux/init.h> | ||
21 | #include <linux/errno.h> | ||
22 | #include <linux/slab.h> | ||
23 | #include <linux/mutex.h> | ||
24 | #include <linux/interrupt.h> | ||
25 | #include <linux/pci.h> | ||
26 | #include <linux/mei_cl_bus.h> | ||
27 | |||
28 | #include "mei_dev.h" | ||
29 | #include "hw-me.h" | ||
30 | #include "client.h" | ||
31 | |||
32 | #define to_mei_cl_driver(d) container_of(d, struct mei_cl_driver, driver) | ||
33 | #define to_mei_cl_device(d) container_of(d, struct mei_cl_device, dev) | ||
34 | |||
35 | static int mei_cl_device_match(struct device *dev, struct device_driver *drv) | ||
36 | { | ||
37 | struct mei_cl_device *device = to_mei_cl_device(dev); | ||
38 | struct mei_cl_driver *driver = to_mei_cl_driver(drv); | ||
39 | const struct mei_cl_device_id *id; | ||
40 | |||
41 | if (!device) | ||
42 | return 0; | ||
43 | |||
44 | if (!driver || !driver->id_table) | ||
45 | return 0; | ||
46 | |||
47 | id = driver->id_table; | ||
48 | |||
49 | while (id->name[0]) { | ||
50 | if (!strcmp(dev_name(dev), id->name)) | ||
51 | return 1; | ||
52 | |||
53 | id++; | ||
54 | } | ||
55 | |||
56 | return 0; | ||
57 | } | ||
58 | |||
59 | static int mei_cl_device_probe(struct device *dev) | ||
60 | { | ||
61 | struct mei_cl_device *device = to_mei_cl_device(dev); | ||
62 | struct mei_cl_driver *driver; | ||
63 | struct mei_cl_device_id id; | ||
64 | |||
65 | if (!device) | ||
66 | return 0; | ||
67 | |||
68 | driver = to_mei_cl_driver(dev->driver); | ||
69 | if (!driver || !driver->probe) | ||
70 | return -ENODEV; | ||
71 | |||
72 | dev_dbg(dev, "Device probe\n"); | ||
73 | |||
74 | strncpy(id.name, dev_name(dev), MEI_CL_NAME_SIZE); | ||
75 | |||
76 | return driver->probe(device, &id); | ||
77 | } | ||
78 | |||
79 | static int mei_cl_device_remove(struct device *dev) | ||
80 | { | ||
81 | struct mei_cl_device *device = to_mei_cl_device(dev); | ||
82 | struct mei_cl_driver *driver; | ||
83 | |||
84 | if (!device || !dev->driver) | ||
85 | return 0; | ||
86 | |||
87 | if (device->event_cb) { | ||
88 | device->event_cb = NULL; | ||
89 | cancel_work_sync(&device->event_work); | ||
90 | } | ||
91 | |||
92 | driver = to_mei_cl_driver(dev->driver); | ||
93 | if (!driver->remove) { | ||
94 | dev->driver = NULL; | ||
95 | |||
96 | return 0; | ||
97 | } | ||
98 | |||
99 | return driver->remove(device); | ||
100 | } | ||
101 | |||
102 | static ssize_t modalias_show(struct device *dev, struct device_attribute *a, | ||
103 | char *buf) | ||
104 | { | ||
105 | int len; | ||
106 | |||
107 | len = snprintf(buf, PAGE_SIZE, "mei:%s\n", dev_name(dev)); | ||
108 | |||
109 | return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len; | ||
110 | } | ||
111 | |||
112 | static struct device_attribute mei_cl_dev_attrs[] = { | ||
113 | __ATTR_RO(modalias), | ||
114 | __ATTR_NULL, | ||
115 | }; | ||
116 | |||
117 | static int mei_cl_uevent(struct device *dev, struct kobj_uevent_env *env) | ||
118 | { | ||
119 | if (add_uevent_var(env, "MODALIAS=mei:%s", dev_name(dev))) | ||
120 | return -ENOMEM; | ||
121 | |||
122 | return 0; | ||
123 | } | ||
124 | |||
125 | static struct bus_type mei_cl_bus_type = { | ||
126 | .name = "mei", | ||
127 | .dev_attrs = mei_cl_dev_attrs, | ||
128 | .match = mei_cl_device_match, | ||
129 | .probe = mei_cl_device_probe, | ||
130 | .remove = mei_cl_device_remove, | ||
131 | .uevent = mei_cl_uevent, | ||
132 | }; | ||
133 | |||
134 | static void mei_cl_dev_release(struct device *dev) | ||
135 | { | ||
136 | kfree(to_mei_cl_device(dev)); | ||
137 | } | ||
138 | |||
139 | static struct device_type mei_cl_device_type = { | ||
140 | .release = mei_cl_dev_release, | ||
141 | }; | ||
142 | |||
143 | static struct mei_cl *mei_bus_find_mei_cl_by_uuid(struct mei_device *dev, | ||
144 | uuid_le uuid) | ||
145 | { | ||
146 | struct mei_cl *cl, *next; | ||
147 | |||
148 | list_for_each_entry_safe(cl, next, &dev->device_list, device_link) { | ||
149 | if (!uuid_le_cmp(uuid, cl->device_uuid)) | ||
150 | return cl; | ||
151 | } | ||
152 | |||
153 | return NULL; | ||
154 | } | ||
155 | struct mei_cl_device *mei_cl_add_device(struct mei_device *dev, | ||
156 | uuid_le uuid, char *name, | ||
157 | struct mei_cl_ops *ops) | ||
158 | { | ||
159 | struct mei_cl_device *device; | ||
160 | struct mei_cl *cl; | ||
161 | int status; | ||
162 | |||
163 | cl = mei_bus_find_mei_cl_by_uuid(dev, uuid); | ||
164 | if (cl == NULL) | ||
165 | return NULL; | ||
166 | |||
167 | device = kzalloc(sizeof(struct mei_cl_device), GFP_KERNEL); | ||
168 | if (!device) | ||
169 | return NULL; | ||
170 | |||
171 | device->cl = cl; | ||
172 | device->ops = ops; | ||
173 | |||
174 | device->dev.parent = &dev->pdev->dev; | ||
175 | device->dev.bus = &mei_cl_bus_type; | ||
176 | device->dev.type = &mei_cl_device_type; | ||
177 | |||
178 | dev_set_name(&device->dev, "%s", name); | ||
179 | |||
180 | status = device_register(&device->dev); | ||
181 | if (status) { | ||
182 | dev_err(&dev->pdev->dev, "Failed to register MEI device\n"); | ||
183 | kfree(device); | ||
184 | return NULL; | ||
185 | } | ||
186 | |||
187 | cl->device = device; | ||
188 | |||
189 | dev_dbg(&device->dev, "client %s registered\n", name); | ||
190 | |||
191 | return device; | ||
192 | } | ||
193 | EXPORT_SYMBOL_GPL(mei_cl_add_device); | ||
194 | |||
195 | void mei_cl_remove_device(struct mei_cl_device *device) | ||
196 | { | ||
197 | device_unregister(&device->dev); | ||
198 | } | ||
199 | EXPORT_SYMBOL_GPL(mei_cl_remove_device); | ||
200 | |||
201 | int __mei_cl_driver_register(struct mei_cl_driver *driver, struct module *owner) | ||
202 | { | ||
203 | int err; | ||
204 | |||
205 | driver->driver.name = driver->name; | ||
206 | driver->driver.owner = owner; | ||
207 | driver->driver.bus = &mei_cl_bus_type; | ||
208 | |||
209 | err = driver_register(&driver->driver); | ||
210 | if (err) | ||
211 | return err; | ||
212 | |||
213 | pr_debug("mei: driver [%s] registered\n", driver->driver.name); | ||
214 | |||
215 | return 0; | ||
216 | } | ||
217 | EXPORT_SYMBOL_GPL(__mei_cl_driver_register); | ||
218 | |||
219 | void mei_cl_driver_unregister(struct mei_cl_driver *driver) | ||
220 | { | ||
221 | driver_unregister(&driver->driver); | ||
222 | |||
223 | pr_debug("mei: driver [%s] unregistered\n", driver->driver.name); | ||
224 | } | ||
225 | EXPORT_SYMBOL_GPL(mei_cl_driver_unregister); | ||
226 | |||
227 | static int ___mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length, | ||
228 | bool blocking) | ||
229 | { | ||
230 | struct mei_device *dev; | ||
231 | struct mei_cl_cb *cb; | ||
232 | int id; | ||
233 | int rets; | ||
234 | |||
235 | if (WARN_ON(!cl || !cl->dev)) | ||
236 | return -ENODEV; | ||
237 | |||
238 | dev = cl->dev; | ||
239 | |||
240 | if (cl->state != MEI_FILE_CONNECTED) | ||
241 | return -ENODEV; | ||
242 | |||
243 | /* Check if we have an ME client device */ | ||
244 | id = mei_me_cl_by_id(dev, cl->me_client_id); | ||
245 | if (id < 0) | ||
246 | return -ENODEV; | ||
247 | |||
248 | if (length > dev->me_clients[id].props.max_msg_length) | ||
249 | return -EINVAL; | ||
250 | |||
251 | cb = mei_io_cb_init(cl, NULL); | ||
252 | if (!cb) | ||
253 | return -ENOMEM; | ||
254 | |||
255 | rets = mei_io_cb_alloc_req_buf(cb, length); | ||
256 | if (rets < 0) { | ||
257 | mei_io_cb_free(cb); | ||
258 | return rets; | ||
259 | } | ||
260 | |||
261 | memcpy(cb->request_buffer.data, buf, length); | ||
262 | |||
263 | mutex_lock(&dev->device_lock); | ||
264 | |||
265 | rets = mei_cl_write(cl, cb, blocking); | ||
266 | |||
267 | mutex_unlock(&dev->device_lock); | ||
268 | if (rets < 0) | ||
269 | mei_io_cb_free(cb); | ||
270 | |||
271 | return rets; | ||
272 | } | ||
273 | |||
274 | int __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length) | ||
275 | { | ||
276 | struct mei_device *dev; | ||
277 | struct mei_cl_cb *cb; | ||
278 | size_t r_length; | ||
279 | int err; | ||
280 | |||
281 | if (WARN_ON(!cl || !cl->dev)) | ||
282 | return -ENODEV; | ||
283 | |||
284 | dev = cl->dev; | ||
285 | |||
286 | mutex_lock(&dev->device_lock); | ||
287 | |||
288 | if (!cl->read_cb) { | ||
289 | err = mei_cl_read_start(cl, length); | ||
290 | if (err < 0) { | ||
291 | mutex_unlock(&dev->device_lock); | ||
292 | return err; | ||
293 | } | ||
294 | } | ||
295 | |||
296 | if (cl->reading_state != MEI_READ_COMPLETE && | ||
297 | !waitqueue_active(&cl->rx_wait)) { | ||
298 | mutex_unlock(&dev->device_lock); | ||
299 | |||
300 | if (wait_event_interruptible(cl->rx_wait, | ||
301 | (MEI_READ_COMPLETE == cl->reading_state))) { | ||
302 | if (signal_pending(current)) | ||
303 | return -EINTR; | ||
304 | return -ERESTARTSYS; | ||
305 | } | ||
306 | |||
307 | mutex_lock(&dev->device_lock); | ||
308 | } | ||
309 | |||
310 | cb = cl->read_cb; | ||
311 | |||
312 | if (cl->reading_state != MEI_READ_COMPLETE) { | ||
313 | r_length = 0; | ||
314 | goto out; | ||
315 | } | ||
316 | |||
317 | r_length = min_t(size_t, length, cb->buf_idx); | ||
318 | |||
319 | memcpy(buf, cb->response_buffer.data, r_length); | ||
320 | |||
321 | mei_io_cb_free(cb); | ||
322 | cl->reading_state = MEI_IDLE; | ||
323 | cl->read_cb = NULL; | ||
324 | |||
325 | out: | ||
326 | mutex_unlock(&dev->device_lock); | ||
327 | |||
328 | return r_length; | ||
329 | } | ||
330 | |||
331 | inline int __mei_cl_async_send(struct mei_cl *cl, u8 *buf, size_t length) | ||
332 | { | ||
333 | return ___mei_cl_send(cl, buf, length, 0); | ||
334 | } | ||
335 | |||
336 | inline int __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length) | ||
337 | { | ||
338 | return ___mei_cl_send(cl, buf, length, 1); | ||
339 | } | ||
340 | |||
341 | int mei_cl_send(struct mei_cl_device *device, u8 *buf, size_t length) | ||
342 | { | ||
343 | struct mei_cl *cl = device->cl; | ||
344 | |||
345 | if (cl == NULL) | ||
346 | return -ENODEV; | ||
347 | |||
348 | if (device->ops && device->ops->send) | ||
349 | return device->ops->send(device, buf, length); | ||
350 | |||
351 | return __mei_cl_send(cl, buf, length); | ||
352 | } | ||
353 | EXPORT_SYMBOL_GPL(mei_cl_send); | ||
354 | |||
355 | int mei_cl_recv(struct mei_cl_device *device, u8 *buf, size_t length) | ||
356 | { | ||
357 | struct mei_cl *cl = device->cl; | ||
358 | |||
359 | if (cl == NULL) | ||
360 | return -ENODEV; | ||
361 | |||
362 | if (device->ops && device->ops->recv) | ||
363 | return device->ops->recv(device, buf, length); | ||
364 | |||
365 | return __mei_cl_recv(cl, buf, length); | ||
366 | } | ||
367 | EXPORT_SYMBOL_GPL(mei_cl_recv); | ||
368 | |||
369 | static void mei_bus_event_work(struct work_struct *work) | ||
370 | { | ||
371 | struct mei_cl_device *device; | ||
372 | |||
373 | device = container_of(work, struct mei_cl_device, event_work); | ||
374 | |||
375 | if (device->event_cb) | ||
376 | device->event_cb(device, device->events, device->event_context); | ||
377 | |||
378 | device->events = 0; | ||
379 | |||
380 | /* Prepare for the next read */ | ||
381 | mei_cl_read_start(device->cl, 0); | ||
382 | } | ||
383 | |||
384 | int mei_cl_register_event_cb(struct mei_cl_device *device, | ||
385 | mei_cl_event_cb_t event_cb, void *context) | ||
386 | { | ||
387 | if (device->event_cb) | ||
388 | return -EALREADY; | ||
389 | |||
390 | device->events = 0; | ||
391 | device->event_cb = event_cb; | ||
392 | device->event_context = context; | ||
393 | INIT_WORK(&device->event_work, mei_bus_event_work); | ||
394 | |||
395 | mei_cl_read_start(device->cl, 0); | ||
396 | |||
397 | return 0; | ||
398 | } | ||
399 | EXPORT_SYMBOL_GPL(mei_cl_register_event_cb); | ||
400 | |||
401 | void *mei_cl_get_drvdata(const struct mei_cl_device *device) | ||
402 | { | ||
403 | return dev_get_drvdata(&device->dev); | ||
404 | } | ||
405 | EXPORT_SYMBOL_GPL(mei_cl_get_drvdata); | ||
406 | |||
407 | void mei_cl_set_drvdata(struct mei_cl_device *device, void *data) | ||
408 | { | ||
409 | dev_set_drvdata(&device->dev, data); | ||
410 | } | ||
411 | EXPORT_SYMBOL_GPL(mei_cl_set_drvdata); | ||
412 | |||
413 | int mei_cl_enable_device(struct mei_cl_device *device) | ||
414 | { | ||
415 | int err; | ||
416 | struct mei_device *dev; | ||
417 | struct mei_cl *cl = device->cl; | ||
418 | |||
419 | if (cl == NULL) | ||
420 | return -ENODEV; | ||
421 | |||
422 | dev = cl->dev; | ||
423 | |||
424 | mutex_lock(&dev->device_lock); | ||
425 | |||
426 | cl->state = MEI_FILE_CONNECTING; | ||
427 | |||
428 | err = mei_cl_connect(cl, NULL); | ||
429 | if (err < 0) { | ||
430 | mutex_unlock(&dev->device_lock); | ||
431 | dev_err(&dev->pdev->dev, "Could not connect to the ME client"); | ||
432 | |||
433 | return err; | ||
434 | } | ||
435 | |||
436 | mutex_unlock(&dev->device_lock); | ||
437 | |||
438 | if (device->event_cb && !cl->read_cb) | ||
439 | mei_cl_read_start(device->cl, 0); | ||
440 | |||
441 | if (!device->ops || !device->ops->enable) | ||
442 | return 0; | ||
443 | |||
444 | return device->ops->enable(device); | ||
445 | } | ||
446 | EXPORT_SYMBOL_GPL(mei_cl_enable_device); | ||
447 | |||
448 | int mei_cl_disable_device(struct mei_cl_device *device) | ||
449 | { | ||
450 | int err; | ||
451 | struct mei_device *dev; | ||
452 | struct mei_cl *cl = device->cl; | ||
453 | |||
454 | if (cl == NULL) | ||
455 | return -ENODEV; | ||
456 | |||
457 | dev = cl->dev; | ||
458 | |||
459 | mutex_lock(&dev->device_lock); | ||
460 | |||
461 | if (cl->state != MEI_FILE_CONNECTED) { | ||
462 | mutex_unlock(&dev->device_lock); | ||
463 | dev_err(&dev->pdev->dev, "Already disconnected"); | ||
464 | |||
465 | return 0; | ||
466 | } | ||
467 | |||
468 | cl->state = MEI_FILE_DISCONNECTING; | ||
469 | |||
470 | err = mei_cl_disconnect(cl); | ||
471 | if (err < 0) { | ||
472 | mutex_unlock(&dev->device_lock); | ||
473 | dev_err(&dev->pdev->dev, | ||
474 | "Could not disconnect from the ME client"); | ||
475 | |||
476 | return err; | ||
477 | } | ||
478 | |||
479 | /* Flush queues and remove any pending read */ | ||
480 | mei_cl_flush_queues(cl); | ||
481 | |||
482 | if (cl->read_cb) { | ||
483 | struct mei_cl_cb *cb = NULL; | ||
484 | |||
485 | cb = mei_cl_find_read_cb(cl); | ||
486 | /* Remove entry from read list */ | ||
487 | if (cb) | ||
488 | list_del(&cb->list); | ||
489 | |||
490 | cb = cl->read_cb; | ||
491 | cl->read_cb = NULL; | ||
492 | |||
493 | if (cb) { | ||
494 | mei_io_cb_free(cb); | ||
495 | cb = NULL; | ||
496 | } | ||
497 | } | ||
498 | |||
499 | mutex_unlock(&dev->device_lock); | ||
500 | |||
501 | if (!device->ops || !device->ops->disable) | ||
502 | return 0; | ||
503 | |||
504 | return device->ops->disable(device); | ||
505 | } | ||
506 | EXPORT_SYMBOL_GPL(mei_cl_disable_device); | ||
507 | |||
508 | void mei_cl_bus_rx_event(struct mei_cl *cl) | ||
509 | { | ||
510 | struct mei_cl_device *device = cl->device; | ||
511 | |||
512 | if (!device || !device->event_cb) | ||
513 | return; | ||
514 | |||
515 | set_bit(MEI_CL_EVENT_RX, &device->events); | ||
516 | |||
517 | schedule_work(&device->event_work); | ||
518 | } | ||
519 | |||
520 | int __init mei_cl_bus_init(void) | ||
521 | { | ||
522 | return bus_register(&mei_cl_bus_type); | ||
523 | } | ||
524 | |||
525 | void __exit mei_cl_bus_exit(void) | ||
526 | { | ||
527 | bus_unregister(&mei_cl_bus_type); | ||
528 | } | ||
diff --git a/drivers/misc/mei/client.c b/drivers/misc/mei/client.c index 1569afe935de..71892745e2e8 100644 --- a/drivers/misc/mei/client.c +++ b/drivers/misc/mei/client.c | |||
@@ -216,6 +216,7 @@ void mei_cl_init(struct mei_cl *cl, struct mei_device *dev) | |||
216 | init_waitqueue_head(&cl->rx_wait); | 216 | init_waitqueue_head(&cl->rx_wait); |
217 | init_waitqueue_head(&cl->tx_wait); | 217 | init_waitqueue_head(&cl->tx_wait); |
218 | INIT_LIST_HEAD(&cl->link); | 218 | INIT_LIST_HEAD(&cl->link); |
219 | INIT_LIST_HEAD(&cl->device_link); | ||
219 | cl->reading_state = MEI_IDLE; | 220 | cl->reading_state = MEI_IDLE; |
220 | cl->writing_state = MEI_IDLE; | 221 | cl->writing_state = MEI_IDLE; |
221 | cl->dev = dev; | 222 | cl->dev = dev; |
@@ -357,6 +358,9 @@ void mei_host_client_init(struct work_struct *work) | |||
357 | mei_amthif_host_init(dev); | 358 | mei_amthif_host_init(dev); |
358 | else if (!uuid_le_cmp(client_props->protocol_name, mei_wd_guid)) | 359 | else if (!uuid_le_cmp(client_props->protocol_name, mei_wd_guid)) |
359 | mei_wd_host_init(dev); | 360 | mei_wd_host_init(dev); |
361 | else if (!uuid_le_cmp(client_props->protocol_name, mei_nfc_guid)) | ||
362 | mei_nfc_host_init(dev); | ||
363 | |||
360 | } | 364 | } |
361 | 365 | ||
362 | dev->dev_state = MEI_DEV_ENABLED; | 366 | dev->dev_state = MEI_DEV_ENABLED; |
@@ -620,7 +624,7 @@ int mei_cl_flow_ctrl_reduce(struct mei_cl *cl) | |||
620 | * | 624 | * |
621 | * returns 0 on success, <0 on failure. | 625 | * returns 0 on success, <0 on failure. |
622 | */ | 626 | */ |
623 | int mei_cl_read_start(struct mei_cl *cl) | 627 | int mei_cl_read_start(struct mei_cl *cl, size_t length) |
624 | { | 628 | { |
625 | struct mei_device *dev; | 629 | struct mei_device *dev; |
626 | struct mei_cl_cb *cb; | 630 | struct mei_cl_cb *cb; |
@@ -653,8 +657,9 @@ int mei_cl_read_start(struct mei_cl *cl) | |||
653 | if (!cb) | 657 | if (!cb) |
654 | return -ENOMEM; | 658 | return -ENOMEM; |
655 | 659 | ||
656 | rets = mei_io_cb_alloc_resp_buf(cb, | 660 | /* always allocate at least client max message */ |
657 | dev->me_clients[i].props.max_msg_length); | 661 | length = max_t(size_t, length, dev->me_clients[i].props.max_msg_length); |
662 | rets = mei_io_cb_alloc_resp_buf(cb, length); | ||
658 | if (rets) | 663 | if (rets) |
659 | goto err; | 664 | goto err; |
660 | 665 | ||
@@ -677,6 +682,111 @@ err: | |||
677 | } | 682 | } |
678 | 683 | ||
679 | /** | 684 | /** |
685 | * mei_cl_write - submit a write cb to mei device | ||
686 | assumes device_lock is locked | ||
687 | * | ||
688 | * @cl: host client | ||
689 | * @cl: write callback with filled data | ||
690 | * | ||
691 | * returns numbe of bytes sent on success, <0 on failure. | ||
692 | */ | ||
693 | int mei_cl_write(struct mei_cl *cl, struct mei_cl_cb *cb, bool blocking) | ||
694 | { | ||
695 | struct mei_device *dev; | ||
696 | struct mei_msg_data *buf; | ||
697 | struct mei_msg_hdr mei_hdr; | ||
698 | int rets; | ||
699 | |||
700 | |||
701 | if (WARN_ON(!cl || !cl->dev)) | ||
702 | return -ENODEV; | ||
703 | |||
704 | if (WARN_ON(!cb)) | ||
705 | return -EINVAL; | ||
706 | |||
707 | dev = cl->dev; | ||
708 | |||
709 | |||
710 | buf = &cb->request_buffer; | ||
711 | |||
712 | dev_dbg(&dev->pdev->dev, "mei_cl_write %d\n", buf->size); | ||
713 | |||
714 | |||
715 | cb->fop_type = MEI_FOP_WRITE; | ||
716 | |||
717 | rets = mei_cl_flow_ctrl_creds(cl); | ||
718 | if (rets < 0) | ||
719 | goto err; | ||
720 | |||
721 | /* Host buffer is not ready, we queue the request */ | ||
722 | if (rets == 0 || !dev->hbuf_is_ready) { | ||
723 | cb->buf_idx = 0; | ||
724 | /* unseting complete will enqueue the cb for write */ | ||
725 | mei_hdr.msg_complete = 0; | ||
726 | cl->writing_state = MEI_WRITING; | ||
727 | rets = buf->size; | ||
728 | goto out; | ||
729 | } | ||
730 | |||
731 | dev->hbuf_is_ready = false; | ||
732 | |||
733 | /* Check for a maximum length */ | ||
734 | if (buf->size > mei_hbuf_max_len(dev)) { | ||
735 | mei_hdr.length = mei_hbuf_max_len(dev); | ||
736 | mei_hdr.msg_complete = 0; | ||
737 | } else { | ||
738 | mei_hdr.length = buf->size; | ||
739 | mei_hdr.msg_complete = 1; | ||
740 | } | ||
741 | |||
742 | mei_hdr.host_addr = cl->host_client_id; | ||
743 | mei_hdr.me_addr = cl->me_client_id; | ||
744 | mei_hdr.reserved = 0; | ||
745 | |||
746 | dev_dbg(&dev->pdev->dev, "write " MEI_HDR_FMT "\n", | ||
747 | MEI_HDR_PRM(&mei_hdr)); | ||
748 | |||
749 | |||
750 | if (mei_write_message(dev, &mei_hdr, buf->data)) { | ||
751 | rets = -EIO; | ||
752 | goto err; | ||
753 | } | ||
754 | |||
755 | cl->writing_state = MEI_WRITING; | ||
756 | cb->buf_idx = mei_hdr.length; | ||
757 | |||
758 | rets = buf->size; | ||
759 | out: | ||
760 | if (mei_hdr.msg_complete) { | ||
761 | if (mei_cl_flow_ctrl_reduce(cl)) { | ||
762 | rets = -ENODEV; | ||
763 | goto err; | ||
764 | } | ||
765 | list_add_tail(&cb->list, &dev->write_waiting_list.list); | ||
766 | } else { | ||
767 | list_add_tail(&cb->list, &dev->write_list.list); | ||
768 | } | ||
769 | |||
770 | |||
771 | if (blocking && cl->writing_state != MEI_WRITE_COMPLETE) { | ||
772 | |||
773 | mutex_unlock(&dev->device_lock); | ||
774 | if (wait_event_interruptible(cl->tx_wait, | ||
775 | cl->writing_state == MEI_WRITE_COMPLETE)) { | ||
776 | if (signal_pending(current)) | ||
777 | rets = -EINTR; | ||
778 | else | ||
779 | rets = -ERESTARTSYS; | ||
780 | } | ||
781 | mutex_lock(&dev->device_lock); | ||
782 | } | ||
783 | err: | ||
784 | return rets; | ||
785 | } | ||
786 | |||
787 | |||
788 | |||
789 | /** | ||
680 | * mei_cl_all_disconnect - disconnect forcefully all connected clients | 790 | * mei_cl_all_disconnect - disconnect forcefully all connected clients |
681 | * | 791 | * |
682 | * @dev - mei device | 792 | * @dev - mei device |
diff --git a/drivers/misc/mei/client.h b/drivers/misc/mei/client.h index 214b2397ec3e..cfdb144526aa 100644 --- a/drivers/misc/mei/client.h +++ b/drivers/misc/mei/client.h | |||
@@ -86,17 +86,16 @@ int mei_cl_flow_ctrl_reduce(struct mei_cl *cl); | |||
86 | */ | 86 | */ |
87 | bool mei_cl_is_other_connecting(struct mei_cl *cl); | 87 | bool mei_cl_is_other_connecting(struct mei_cl *cl); |
88 | int mei_cl_disconnect(struct mei_cl *cl); | 88 | int mei_cl_disconnect(struct mei_cl *cl); |
89 | |||
90 | int mei_cl_read_start(struct mei_cl *cl); | ||
91 | |||
92 | int mei_cl_connect(struct mei_cl *cl, struct file *file); | 89 | int mei_cl_connect(struct mei_cl *cl, struct file *file); |
90 | int mei_cl_read_start(struct mei_cl *cl, size_t length); | ||
91 | int mei_cl_write(struct mei_cl *cl, struct mei_cl_cb *cb, bool blocking); | ||
93 | 92 | ||
94 | void mei_host_client_init(struct work_struct *work); | 93 | void mei_host_client_init(struct work_struct *work); |
95 | 94 | ||
96 | 95 | ||
96 | |||
97 | void mei_cl_all_disconnect(struct mei_device *dev); | 97 | void mei_cl_all_disconnect(struct mei_device *dev); |
98 | void mei_cl_all_read_wakeup(struct mei_device *dev); | 98 | void mei_cl_all_read_wakeup(struct mei_device *dev); |
99 | void mei_cl_all_write_clear(struct mei_device *dev); | 99 | void mei_cl_all_write_clear(struct mei_device *dev); |
100 | 100 | ||
101 | |||
102 | #endif /* _MEI_CLIENT_H_ */ | 101 | #endif /* _MEI_CLIENT_H_ */ |
diff --git a/drivers/misc/mei/debugfs.c b/drivers/misc/mei/debugfs.c new file mode 100644 index 000000000000..e3870f22d238 --- /dev/null +++ b/drivers/misc/mei/debugfs.c | |||
@@ -0,0 +1,143 @@ | |||
1 | /* | ||
2 | * | ||
3 | * Intel Management Engine Interface (Intel MEI) Linux driver | ||
4 | * Copyright (c) 2012-2013, Intel Corporation. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms and conditions of the GNU General Public License, | ||
8 | * version 2, as published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | * more details. | ||
14 | * | ||
15 | */ | ||
16 | #include <linux/slab.h> | ||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/device.h> | ||
19 | #include <linux/debugfs.h> | ||
20 | #include <linux/pci.h> | ||
21 | |||
22 | #include <linux/mei.h> | ||
23 | |||
24 | #include "mei_dev.h" | ||
25 | #include "hw.h" | ||
26 | |||
27 | static ssize_t mei_dbgfs_read_meclients(struct file *fp, char __user *ubuf, | ||
28 | size_t cnt, loff_t *ppos) | ||
29 | { | ||
30 | struct mei_device *dev = fp->private_data; | ||
31 | struct mei_me_client *cl; | ||
32 | const size_t bufsz = 1024; | ||
33 | char *buf = kzalloc(bufsz, GFP_KERNEL); | ||
34 | int i; | ||
35 | int pos = 0; | ||
36 | int ret; | ||
37 | |||
38 | if (!buf) | ||
39 | return -ENOMEM; | ||
40 | |||
41 | pos += scnprintf(buf + pos, bufsz - pos, | ||
42 | " |id|addr| UUID |con|msg len|\n"); | ||
43 | |||
44 | mutex_lock(&dev->device_lock); | ||
45 | |||
46 | /* if the driver is not enabled the list won't b consitent */ | ||
47 | if (dev->dev_state != MEI_DEV_ENABLED) | ||
48 | goto out; | ||
49 | |||
50 | for (i = 0; i < dev->me_clients_num; i++) { | ||
51 | cl = &dev->me_clients[i]; | ||
52 | |||
53 | /* skip me clients that cannot be connected */ | ||
54 | if (cl->props.max_number_of_connections == 0) | ||
55 | continue; | ||
56 | |||
57 | pos += scnprintf(buf + pos, bufsz - pos, | ||
58 | "%2d|%2d|%4d|%pUl|%3d|%7d|\n", | ||
59 | i, cl->client_id, | ||
60 | cl->props.fixed_address, | ||
61 | &cl->props.protocol_name, | ||
62 | cl->props.max_number_of_connections, | ||
63 | cl->props.max_msg_length); | ||
64 | } | ||
65 | out: | ||
66 | mutex_unlock(&dev->device_lock); | ||
67 | ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, pos); | ||
68 | kfree(buf); | ||
69 | return ret; | ||
70 | } | ||
71 | |||
72 | static const struct file_operations mei_dbgfs_fops_meclients = { | ||
73 | .open = simple_open, | ||
74 | .read = mei_dbgfs_read_meclients, | ||
75 | .llseek = generic_file_llseek, | ||
76 | }; | ||
77 | |||
78 | static ssize_t mei_dbgfs_read_devstate(struct file *fp, char __user *ubuf, | ||
79 | size_t cnt, loff_t *ppos) | ||
80 | { | ||
81 | struct mei_device *dev = fp->private_data; | ||
82 | const size_t bufsz = 1024; | ||
83 | char *buf = kzalloc(bufsz, GFP_KERNEL); | ||
84 | int pos = 0; | ||
85 | int ret; | ||
86 | |||
87 | if (!buf) | ||
88 | return -ENOMEM; | ||
89 | |||
90 | pos += scnprintf(buf + pos, bufsz - pos, "%s\n", | ||
91 | mei_dev_state_str(dev->dev_state)); | ||
92 | ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, pos); | ||
93 | kfree(buf); | ||
94 | return ret; | ||
95 | } | ||
96 | static const struct file_operations mei_dbgfs_fops_devstate = { | ||
97 | .open = simple_open, | ||
98 | .read = mei_dbgfs_read_devstate, | ||
99 | .llseek = generic_file_llseek, | ||
100 | }; | ||
101 | |||
102 | /** | ||
103 | * mei_dbgfs_deregister - Remove the debugfs files and directories | ||
104 | * @mei - pointer to mei device private dat | ||
105 | */ | ||
106 | void mei_dbgfs_deregister(struct mei_device *dev) | ||
107 | { | ||
108 | if (!dev->dbgfs_dir) | ||
109 | return; | ||
110 | debugfs_remove_recursive(dev->dbgfs_dir); | ||
111 | dev->dbgfs_dir = NULL; | ||
112 | } | ||
113 | |||
114 | /** | ||
115 | * Add the debugfs files | ||
116 | * | ||
117 | */ | ||
118 | int mei_dbgfs_register(struct mei_device *dev, const char *name) | ||
119 | { | ||
120 | struct dentry *dir, *f; | ||
121 | dir = debugfs_create_dir(name, NULL); | ||
122 | if (!dir) | ||
123 | return -ENOMEM; | ||
124 | |||
125 | f = debugfs_create_file("meclients", S_IRUSR, dir, | ||
126 | dev, &mei_dbgfs_fops_meclients); | ||
127 | if (!f) { | ||
128 | dev_err(&dev->pdev->dev, "meclients: registration failed\n"); | ||
129 | goto err; | ||
130 | } | ||
131 | f = debugfs_create_file("devstate", S_IRUSR, dir, | ||
132 | dev, &mei_dbgfs_fops_devstate); | ||
133 | if (!f) { | ||
134 | dev_err(&dev->pdev->dev, "devstate: registration failed\n"); | ||
135 | goto err; | ||
136 | } | ||
137 | dev->dbgfs_dir = dir; | ||
138 | return 0; | ||
139 | err: | ||
140 | mei_dbgfs_deregister(dev); | ||
141 | return -ENODEV; | ||
142 | } | ||
143 | |||
diff --git a/drivers/misc/mei/hbm.c b/drivers/misc/mei/hbm.c index fb9e63ba3bb1..db605f5cf187 100644 --- a/drivers/misc/mei/hbm.c +++ b/drivers/misc/mei/hbm.c | |||
@@ -52,7 +52,7 @@ static void mei_hbm_me_cl_allocate(struct mei_device *dev) | |||
52 | sizeof(struct mei_me_client), GFP_KERNEL); | 52 | sizeof(struct mei_me_client), GFP_KERNEL); |
53 | if (!clients) { | 53 | if (!clients) { |
54 | dev_err(&dev->pdev->dev, "memory allocation for ME clients failed.\n"); | 54 | dev_err(&dev->pdev->dev, "memory allocation for ME clients failed.\n"); |
55 | dev->dev_state = MEI_DEV_RESETING; | 55 | dev->dev_state = MEI_DEV_RESETTING; |
56 | mei_reset(dev, 1); | 56 | mei_reset(dev, 1); |
57 | return; | 57 | return; |
58 | } | 58 | } |
@@ -123,12 +123,33 @@ static bool is_treat_specially_client(struct mei_cl *cl, | |||
123 | return false; | 123 | return false; |
124 | } | 124 | } |
125 | 125 | ||
126 | int mei_hbm_start_wait(struct mei_device *dev) | ||
127 | { | ||
128 | int ret; | ||
129 | if (dev->hbm_state > MEI_HBM_START) | ||
130 | return 0; | ||
131 | |||
132 | mutex_unlock(&dev->device_lock); | ||
133 | ret = wait_event_interruptible_timeout(dev->wait_recvd_msg, | ||
134 | dev->hbm_state == MEI_HBM_IDLE || | ||
135 | dev->hbm_state > MEI_HBM_START, | ||
136 | mei_secs_to_jiffies(MEI_INTEROP_TIMEOUT)); | ||
137 | mutex_lock(&dev->device_lock); | ||
138 | |||
139 | if (ret <= 0 && (dev->hbm_state <= MEI_HBM_START)) { | ||
140 | dev->hbm_state = MEI_HBM_IDLE; | ||
141 | dev_err(&dev->pdev->dev, "wating for mei start failed\n"); | ||
142 | return -ETIMEDOUT; | ||
143 | } | ||
144 | return 0; | ||
145 | } | ||
146 | |||
126 | /** | 147 | /** |
127 | * mei_hbm_start_req - sends start request message. | 148 | * mei_hbm_start_req - sends start request message. |
128 | * | 149 | * |
129 | * @dev: the device structure | 150 | * @dev: the device structure |
130 | */ | 151 | */ |
131 | void mei_hbm_start_req(struct mei_device *dev) | 152 | int mei_hbm_start_req(struct mei_device *dev) |
132 | { | 153 | { |
133 | struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr; | 154 | struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr; |
134 | struct hbm_host_version_request *start_req; | 155 | struct hbm_host_version_request *start_req; |
@@ -143,18 +164,19 @@ void mei_hbm_start_req(struct mei_device *dev) | |||
143 | start_req->host_version.major_version = HBM_MAJOR_VERSION; | 164 | start_req->host_version.major_version = HBM_MAJOR_VERSION; |
144 | start_req->host_version.minor_version = HBM_MINOR_VERSION; | 165 | start_req->host_version.minor_version = HBM_MINOR_VERSION; |
145 | 166 | ||
146 | dev->recvd_msg = false; | 167 | dev->hbm_state = MEI_HBM_IDLE; |
147 | if (mei_write_message(dev, mei_hdr, dev->wr_msg.data)) { | 168 | if (mei_write_message(dev, mei_hdr, dev->wr_msg.data)) { |
148 | dev_dbg(&dev->pdev->dev, "write send version message to FW fail.\n"); | 169 | dev_err(&dev->pdev->dev, "version message writet failed\n"); |
149 | dev->dev_state = MEI_DEV_RESETING; | 170 | dev->dev_state = MEI_DEV_RESETTING; |
150 | mei_reset(dev, 1); | 171 | mei_reset(dev, 1); |
172 | return -ENODEV; | ||
151 | } | 173 | } |
152 | dev->init_clients_state = MEI_START_MESSAGE; | 174 | dev->hbm_state = MEI_HBM_START; |
153 | dev->init_clients_timer = MEI_CLIENTS_INIT_TIMEOUT; | 175 | dev->init_clients_timer = MEI_CLIENTS_INIT_TIMEOUT; |
154 | return ; | 176 | return 0; |
155 | } | 177 | } |
156 | 178 | ||
157 | /** | 179 | /* |
158 | * mei_hbm_enum_clients_req - sends enumeration client request message. | 180 | * mei_hbm_enum_clients_req - sends enumeration client request message. |
159 | * | 181 | * |
160 | * @dev: the device structure | 182 | * @dev: the device structure |
@@ -174,11 +196,11 @@ static void mei_hbm_enum_clients_req(struct mei_device *dev) | |||
174 | enum_req->hbm_cmd = HOST_ENUM_REQ_CMD; | 196 | enum_req->hbm_cmd = HOST_ENUM_REQ_CMD; |
175 | 197 | ||
176 | if (mei_write_message(dev, mei_hdr, dev->wr_msg.data)) { | 198 | if (mei_write_message(dev, mei_hdr, dev->wr_msg.data)) { |
177 | dev->dev_state = MEI_DEV_RESETING; | 199 | dev->dev_state = MEI_DEV_RESETTING; |
178 | dev_dbg(&dev->pdev->dev, "write send enumeration request message to FW fail.\n"); | 200 | dev_err(&dev->pdev->dev, "enumeration request write failed.\n"); |
179 | mei_reset(dev, 1); | 201 | mei_reset(dev, 1); |
180 | } | 202 | } |
181 | dev->init_clients_state = MEI_ENUM_CLIENTS_MESSAGE; | 203 | dev->hbm_state = MEI_HBM_ENUM_CLIENTS; |
182 | dev->init_clients_timer = MEI_CLIENTS_INIT_TIMEOUT; | 204 | dev->init_clients_timer = MEI_CLIENTS_INIT_TIMEOUT; |
183 | return; | 205 | return; |
184 | } | 206 | } |
@@ -208,6 +230,7 @@ static int mei_hbm_prop_req(struct mei_device *dev) | |||
208 | 230 | ||
209 | /* We got all client properties */ | 231 | /* We got all client properties */ |
210 | if (next_client_index == MEI_CLIENTS_MAX) { | 232 | if (next_client_index == MEI_CLIENTS_MAX) { |
233 | dev->hbm_state = MEI_HBM_STARTED; | ||
211 | schedule_work(&dev->init_work); | 234 | schedule_work(&dev->init_work); |
212 | 235 | ||
213 | return 0; | 236 | return 0; |
@@ -226,8 +249,8 @@ static int mei_hbm_prop_req(struct mei_device *dev) | |||
226 | prop_req->address = next_client_index; | 249 | prop_req->address = next_client_index; |
227 | 250 | ||
228 | if (mei_write_message(dev, mei_hdr, dev->wr_msg.data)) { | 251 | if (mei_write_message(dev, mei_hdr, dev->wr_msg.data)) { |
229 | dev->dev_state = MEI_DEV_RESETING; | 252 | dev->dev_state = MEI_DEV_RESETTING; |
230 | dev_err(&dev->pdev->dev, "Properties request command failed\n"); | 253 | dev_err(&dev->pdev->dev, "properties request write failed\n"); |
231 | mei_reset(dev, 1); | 254 | mei_reset(dev, 1); |
232 | 255 | ||
233 | return -EIO; | 256 | return -EIO; |
@@ -542,27 +565,28 @@ void mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr) | |||
542 | dev->version = version_res->me_max_version; | 565 | dev->version = version_res->me_max_version; |
543 | dev_dbg(&dev->pdev->dev, "version mismatch.\n"); | 566 | dev_dbg(&dev->pdev->dev, "version mismatch.\n"); |
544 | 567 | ||
568 | dev->hbm_state = MEI_HBM_STOP; | ||
545 | mei_hbm_stop_req_prepare(dev, &dev->wr_msg.hdr, | 569 | mei_hbm_stop_req_prepare(dev, &dev->wr_msg.hdr, |
546 | dev->wr_msg.data); | 570 | dev->wr_msg.data); |
547 | mei_write_message(dev, &dev->wr_msg.hdr, | 571 | mei_write_message(dev, &dev->wr_msg.hdr, |
548 | dev->wr_msg.data); | 572 | dev->wr_msg.data); |
573 | |||
549 | return; | 574 | return; |
550 | } | 575 | } |
551 | 576 | ||
552 | dev->version.major_version = HBM_MAJOR_VERSION; | 577 | dev->version.major_version = HBM_MAJOR_VERSION; |
553 | dev->version.minor_version = HBM_MINOR_VERSION; | 578 | dev->version.minor_version = HBM_MINOR_VERSION; |
554 | if (dev->dev_state == MEI_DEV_INIT_CLIENTS && | 579 | if (dev->dev_state == MEI_DEV_INIT_CLIENTS && |
555 | dev->init_clients_state == MEI_START_MESSAGE) { | 580 | dev->hbm_state == MEI_HBM_START) { |
556 | dev->init_clients_timer = 0; | 581 | dev->init_clients_timer = 0; |
557 | mei_hbm_enum_clients_req(dev); | 582 | mei_hbm_enum_clients_req(dev); |
558 | } else { | 583 | } else { |
559 | dev->recvd_msg = false; | 584 | dev_err(&dev->pdev->dev, "reset: wrong host start response\n"); |
560 | dev_dbg(&dev->pdev->dev, "reset due to received hbm: host start\n"); | ||
561 | mei_reset(dev, 1); | 585 | mei_reset(dev, 1); |
562 | return; | 586 | return; |
563 | } | 587 | } |
564 | 588 | ||
565 | dev->recvd_msg = true; | 589 | wake_up_interruptible(&dev->wait_recvd_msg); |
566 | dev_dbg(&dev->pdev->dev, "host start response message received.\n"); | 590 | dev_dbg(&dev->pdev->dev, "host start response message received.\n"); |
567 | break; | 591 | break; |
568 | 592 | ||
@@ -591,23 +615,20 @@ void mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr) | |||
591 | me_client = &dev->me_clients[dev->me_client_presentation_num]; | 615 | me_client = &dev->me_clients[dev->me_client_presentation_num]; |
592 | 616 | ||
593 | if (props_res->status || !dev->me_clients) { | 617 | if (props_res->status || !dev->me_clients) { |
594 | dev_dbg(&dev->pdev->dev, "reset due to received host client properties response bus message wrong status.\n"); | 618 | dev_err(&dev->pdev->dev, "reset: properties response hbm wrong status.\n"); |
595 | mei_reset(dev, 1); | 619 | mei_reset(dev, 1); |
596 | return; | 620 | return; |
597 | } | 621 | } |
598 | 622 | ||
599 | if (me_client->client_id != props_res->address) { | 623 | if (me_client->client_id != props_res->address) { |
600 | dev_err(&dev->pdev->dev, | 624 | dev_err(&dev->pdev->dev, "reset: host properties response address mismatch\n"); |
601 | "Host client properties reply mismatch\n"); | ||
602 | mei_reset(dev, 1); | 625 | mei_reset(dev, 1); |
603 | |||
604 | return; | 626 | return; |
605 | } | 627 | } |
606 | 628 | ||
607 | if (dev->dev_state != MEI_DEV_INIT_CLIENTS || | 629 | if (dev->dev_state != MEI_DEV_INIT_CLIENTS || |
608 | dev->init_clients_state != MEI_CLIENT_PROPERTIES_MESSAGE) { | 630 | dev->hbm_state != MEI_HBM_CLIENT_PROPERTIES) { |
609 | dev_err(&dev->pdev->dev, | 631 | dev_err(&dev->pdev->dev, "reset: unexpected properties response\n"); |
610 | "Unexpected client properties reply\n"); | ||
611 | mei_reset(dev, 1); | 632 | mei_reset(dev, 1); |
612 | 633 | ||
613 | return; | 634 | return; |
@@ -626,26 +647,28 @@ void mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr) | |||
626 | enum_res = (struct hbm_host_enum_response *) mei_msg; | 647 | enum_res = (struct hbm_host_enum_response *) mei_msg; |
627 | memcpy(dev->me_clients_map, enum_res->valid_addresses, 32); | 648 | memcpy(dev->me_clients_map, enum_res->valid_addresses, 32); |
628 | if (dev->dev_state == MEI_DEV_INIT_CLIENTS && | 649 | if (dev->dev_state == MEI_DEV_INIT_CLIENTS && |
629 | dev->init_clients_state == MEI_ENUM_CLIENTS_MESSAGE) { | 650 | dev->hbm_state == MEI_HBM_ENUM_CLIENTS) { |
630 | dev->init_clients_timer = 0; | 651 | dev->init_clients_timer = 0; |
631 | dev->me_client_presentation_num = 0; | 652 | dev->me_client_presentation_num = 0; |
632 | dev->me_client_index = 0; | 653 | dev->me_client_index = 0; |
633 | mei_hbm_me_cl_allocate(dev); | 654 | mei_hbm_me_cl_allocate(dev); |
634 | dev->init_clients_state = | 655 | dev->hbm_state = MEI_HBM_CLIENT_PROPERTIES; |
635 | MEI_CLIENT_PROPERTIES_MESSAGE; | ||
636 | 656 | ||
637 | /* first property reqeust */ | 657 | /* first property reqeust */ |
638 | mei_hbm_prop_req(dev); | 658 | mei_hbm_prop_req(dev); |
639 | } else { | 659 | } else { |
640 | dev_dbg(&dev->pdev->dev, "reset due to received host enumeration clients response bus message.\n"); | 660 | dev_err(&dev->pdev->dev, "reset: unexpected enumeration response hbm.\n"); |
641 | mei_reset(dev, 1); | 661 | mei_reset(dev, 1); |
642 | return; | 662 | return; |
643 | } | 663 | } |
644 | break; | 664 | break; |
645 | 665 | ||
646 | case HOST_STOP_RES_CMD: | 666 | case HOST_STOP_RES_CMD: |
667 | |||
668 | if (dev->hbm_state != MEI_HBM_STOP) | ||
669 | dev_err(&dev->pdev->dev, "unexpected stop response hbm.\n"); | ||
647 | dev->dev_state = MEI_DEV_DISABLED; | 670 | dev->dev_state = MEI_DEV_DISABLED; |
648 | dev_dbg(&dev->pdev->dev, "resetting because of FW stop response.\n"); | 671 | dev_info(&dev->pdev->dev, "reset: FW stop response.\n"); |
649 | mei_reset(dev, 1); | 672 | mei_reset(dev, 1); |
650 | break; | 673 | break; |
651 | 674 | ||
@@ -657,6 +680,7 @@ void mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr) | |||
657 | 680 | ||
658 | case ME_STOP_REQ_CMD: | 681 | case ME_STOP_REQ_CMD: |
659 | 682 | ||
683 | dev->hbm_state = MEI_HBM_STOP; | ||
660 | mei_hbm_stop_req_prepare(dev, &dev->wr_ext_msg.hdr, | 684 | mei_hbm_stop_req_prepare(dev, &dev->wr_ext_msg.hdr, |
661 | dev->wr_ext_msg.data); | 685 | dev->wr_ext_msg.data); |
662 | break; | 686 | break; |
diff --git a/drivers/misc/mei/hbm.h b/drivers/misc/mei/hbm.h index b552afbaf85c..e80dc24ef3e2 100644 --- a/drivers/misc/mei/hbm.h +++ b/drivers/misc/mei/hbm.h | |||
@@ -17,6 +17,27 @@ | |||
17 | #ifndef _MEI_HBM_H_ | 17 | #ifndef _MEI_HBM_H_ |
18 | #define _MEI_HBM_H_ | 18 | #define _MEI_HBM_H_ |
19 | 19 | ||
20 | struct mei_device; | ||
21 | struct mei_msg_hdr; | ||
22 | struct mei_cl; | ||
23 | |||
24 | /** | ||
25 | * enum mei_hbm_state - host bus message protocol state | ||
26 | * | ||
27 | * @MEI_HBM_IDLE : protocol not started | ||
28 | * @MEI_HBM_START : start request message was sent | ||
29 | * @MEI_HBM_ENUM_CLIENTS : enumeration request was sent | ||
30 | * @MEI_HBM_CLIENT_PROPERTIES : acquiring clients properties | ||
31 | */ | ||
32 | enum mei_hbm_state { | ||
33 | MEI_HBM_IDLE = 0, | ||
34 | MEI_HBM_START, | ||
35 | MEI_HBM_ENUM_CLIENTS, | ||
36 | MEI_HBM_CLIENT_PROPERTIES, | ||
37 | MEI_HBM_STARTED, | ||
38 | MEI_HBM_STOP, | ||
39 | }; | ||
40 | |||
20 | void mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr); | 41 | void mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr); |
21 | 42 | ||
22 | static inline void mei_hbm_hdr(struct mei_msg_hdr *hdr, size_t length) | 43 | static inline void mei_hbm_hdr(struct mei_msg_hdr *hdr, size_t length) |
@@ -28,8 +49,8 @@ static inline void mei_hbm_hdr(struct mei_msg_hdr *hdr, size_t length) | |||
28 | hdr->reserved = 0; | 49 | hdr->reserved = 0; |
29 | } | 50 | } |
30 | 51 | ||
31 | void mei_hbm_start_req(struct mei_device *dev); | 52 | int mei_hbm_start_req(struct mei_device *dev); |
32 | 53 | int mei_hbm_start_wait(struct mei_device *dev); | |
33 | int mei_hbm_cl_flow_control_req(struct mei_device *dev, struct mei_cl *cl); | 54 | int mei_hbm_cl_flow_control_req(struct mei_device *dev, struct mei_cl *cl); |
34 | int mei_hbm_cl_disconnect_req(struct mei_device *dev, struct mei_cl *cl); | 55 | int mei_hbm_cl_disconnect_req(struct mei_device *dev, struct mei_cl *cl); |
35 | int mei_hbm_cl_connect_req(struct mei_device *dev, struct mei_cl *cl); | 56 | int mei_hbm_cl_connect_req(struct mei_device *dev, struct mei_cl *cl); |
diff --git a/drivers/misc/mei/hw-me.c b/drivers/misc/mei/hw-me.c index 642c6223fa6c..fc032270916a 100644 --- a/drivers/misc/mei/hw-me.c +++ b/drivers/misc/mei/hw-me.c | |||
@@ -26,14 +26,14 @@ | |||
26 | 26 | ||
27 | 27 | ||
28 | /** | 28 | /** |
29 | * mei_reg_read - Reads 32bit data from the mei device | 29 | * mei_me_reg_read - Reads 32bit data from the mei device |
30 | * | 30 | * |
31 | * @dev: the device structure | 31 | * @dev: the device structure |
32 | * @offset: offset from which to read the data | 32 | * @offset: offset from which to read the data |
33 | * | 33 | * |
34 | * returns register value (u32) | 34 | * returns register value (u32) |
35 | */ | 35 | */ |
36 | static inline u32 mei_reg_read(const struct mei_me_hw *hw, | 36 | static inline u32 mei_me_reg_read(const struct mei_me_hw *hw, |
37 | unsigned long offset) | 37 | unsigned long offset) |
38 | { | 38 | { |
39 | return ioread32(hw->mem_addr + offset); | 39 | return ioread32(hw->mem_addr + offset); |
@@ -41,20 +41,20 @@ static inline u32 mei_reg_read(const struct mei_me_hw *hw, | |||
41 | 41 | ||
42 | 42 | ||
43 | /** | 43 | /** |
44 | * mei_reg_write - Writes 32bit data to the mei device | 44 | * mei_me_reg_write - Writes 32bit data to the mei device |
45 | * | 45 | * |
46 | * @dev: the device structure | 46 | * @dev: the device structure |
47 | * @offset: offset from which to write the data | 47 | * @offset: offset from which to write the data |
48 | * @value: register value to write (u32) | 48 | * @value: register value to write (u32) |
49 | */ | 49 | */ |
50 | static inline void mei_reg_write(const struct mei_me_hw *hw, | 50 | static inline void mei_me_reg_write(const struct mei_me_hw *hw, |
51 | unsigned long offset, u32 value) | 51 | unsigned long offset, u32 value) |
52 | { | 52 | { |
53 | iowrite32(value, hw->mem_addr + offset); | 53 | iowrite32(value, hw->mem_addr + offset); |
54 | } | 54 | } |
55 | 55 | ||
56 | /** | 56 | /** |
57 | * mei_mecbrw_read - Reads 32bit data from ME circular buffer | 57 | * mei_me_mecbrw_read - Reads 32bit data from ME circular buffer |
58 | * read window register | 58 | * read window register |
59 | * | 59 | * |
60 | * @dev: the device structure | 60 | * @dev: the device structure |
@@ -63,18 +63,18 @@ static inline void mei_reg_write(const struct mei_me_hw *hw, | |||
63 | */ | 63 | */ |
64 | static u32 mei_me_mecbrw_read(const struct mei_device *dev) | 64 | static u32 mei_me_mecbrw_read(const struct mei_device *dev) |
65 | { | 65 | { |
66 | return mei_reg_read(to_me_hw(dev), ME_CB_RW); | 66 | return mei_me_reg_read(to_me_hw(dev), ME_CB_RW); |
67 | } | 67 | } |
68 | /** | 68 | /** |
69 | * mei_mecsr_read - Reads 32bit data from the ME CSR | 69 | * mei_me_mecsr_read - Reads 32bit data from the ME CSR |
70 | * | 70 | * |
71 | * @dev: the device structure | 71 | * @dev: the device structure |
72 | * | 72 | * |
73 | * returns ME_CSR_HA register value (u32) | 73 | * returns ME_CSR_HA register value (u32) |
74 | */ | 74 | */ |
75 | static inline u32 mei_mecsr_read(const struct mei_me_hw *hw) | 75 | static inline u32 mei_me_mecsr_read(const struct mei_me_hw *hw) |
76 | { | 76 | { |
77 | return mei_reg_read(hw, ME_CSR_HA); | 77 | return mei_me_reg_read(hw, ME_CSR_HA); |
78 | } | 78 | } |
79 | 79 | ||
80 | /** | 80 | /** |
@@ -86,7 +86,7 @@ static inline u32 mei_mecsr_read(const struct mei_me_hw *hw) | |||
86 | */ | 86 | */ |
87 | static inline u32 mei_hcsr_read(const struct mei_me_hw *hw) | 87 | static inline u32 mei_hcsr_read(const struct mei_me_hw *hw) |
88 | { | 88 | { |
89 | return mei_reg_read(hw, H_CSR); | 89 | return mei_me_reg_read(hw, H_CSR); |
90 | } | 90 | } |
91 | 91 | ||
92 | /** | 92 | /** |
@@ -98,7 +98,7 @@ static inline u32 mei_hcsr_read(const struct mei_me_hw *hw) | |||
98 | static inline void mei_hcsr_set(struct mei_me_hw *hw, u32 hcsr) | 98 | static inline void mei_hcsr_set(struct mei_me_hw *hw, u32 hcsr) |
99 | { | 99 | { |
100 | hcsr &= ~H_IS; | 100 | hcsr &= ~H_IS; |
101 | mei_reg_write(hw, H_CSR, hcsr); | 101 | mei_me_reg_write(hw, H_CSR, hcsr); |
102 | } | 102 | } |
103 | 103 | ||
104 | 104 | ||
@@ -123,7 +123,7 @@ static void mei_me_intr_clear(struct mei_device *dev) | |||
123 | struct mei_me_hw *hw = to_me_hw(dev); | 123 | struct mei_me_hw *hw = to_me_hw(dev); |
124 | u32 hcsr = mei_hcsr_read(hw); | 124 | u32 hcsr = mei_hcsr_read(hw); |
125 | if ((hcsr & H_IS) == H_IS) | 125 | if ((hcsr & H_IS) == H_IS) |
126 | mei_reg_write(hw, H_CSR, hcsr); | 126 | mei_me_reg_write(hw, H_CSR, hcsr); |
127 | } | 127 | } |
128 | /** | 128 | /** |
129 | * mei_me_intr_enable - enables mei device interrupts | 129 | * mei_me_intr_enable - enables mei device interrupts |
@@ -228,10 +228,42 @@ static bool mei_me_host_is_ready(struct mei_device *dev) | |||
228 | static bool mei_me_hw_is_ready(struct mei_device *dev) | 228 | static bool mei_me_hw_is_ready(struct mei_device *dev) |
229 | { | 229 | { |
230 | struct mei_me_hw *hw = to_me_hw(dev); | 230 | struct mei_me_hw *hw = to_me_hw(dev); |
231 | hw->me_hw_state = mei_mecsr_read(hw); | 231 | hw->me_hw_state = mei_me_mecsr_read(hw); |
232 | return (hw->me_hw_state & ME_RDY_HRA) == ME_RDY_HRA; | 232 | return (hw->me_hw_state & ME_RDY_HRA) == ME_RDY_HRA; |
233 | } | 233 | } |
234 | 234 | ||
235 | static int mei_me_hw_ready_wait(struct mei_device *dev) | ||
236 | { | ||
237 | int err; | ||
238 | if (mei_me_hw_is_ready(dev)) | ||
239 | return 0; | ||
240 | |||
241 | mutex_unlock(&dev->device_lock); | ||
242 | err = wait_event_interruptible_timeout(dev->wait_hw_ready, | ||
243 | dev->recvd_hw_ready, MEI_INTEROP_TIMEOUT); | ||
244 | mutex_lock(&dev->device_lock); | ||
245 | if (!err && !dev->recvd_hw_ready) { | ||
246 | dev_err(&dev->pdev->dev, | ||
247 | "wait hw ready failed. status = 0x%x\n", err); | ||
248 | return -ETIMEDOUT; | ||
249 | } | ||
250 | |||
251 | dev->recvd_hw_ready = false; | ||
252 | return 0; | ||
253 | } | ||
254 | |||
255 | static int mei_me_hw_start(struct mei_device *dev) | ||
256 | { | ||
257 | int ret = mei_me_hw_ready_wait(dev); | ||
258 | if (ret) | ||
259 | return ret; | ||
260 | dev_dbg(&dev->pdev->dev, "hw is ready\n"); | ||
261 | |||
262 | mei_me_host_set_ready(dev); | ||
263 | return ret; | ||
264 | } | ||
265 | |||
266 | |||
235 | /** | 267 | /** |
236 | * mei_hbuf_filled_slots - gets number of device filled buffer slots | 268 | * mei_hbuf_filled_slots - gets number of device filled buffer slots |
237 | * | 269 | * |
@@ -305,10 +337,11 @@ static int mei_me_write_message(struct mei_device *dev, | |||
305 | unsigned char *buf) | 337 | unsigned char *buf) |
306 | { | 338 | { |
307 | struct mei_me_hw *hw = to_me_hw(dev); | 339 | struct mei_me_hw *hw = to_me_hw(dev); |
308 | unsigned long rem, dw_cnt; | 340 | unsigned long rem; |
309 | unsigned long length = header->length; | 341 | unsigned long length = header->length; |
310 | u32 *reg_buf = (u32 *)buf; | 342 | u32 *reg_buf = (u32 *)buf; |
311 | u32 hcsr; | 343 | u32 hcsr; |
344 | u32 dw_cnt; | ||
312 | int i; | 345 | int i; |
313 | int empty_slots; | 346 | int empty_slots; |
314 | 347 | ||
@@ -321,16 +354,16 @@ static int mei_me_write_message(struct mei_device *dev, | |||
321 | if (empty_slots < 0 || dw_cnt > empty_slots) | 354 | if (empty_slots < 0 || dw_cnt > empty_slots) |
322 | return -EIO; | 355 | return -EIO; |
323 | 356 | ||
324 | mei_reg_write(hw, H_CB_WW, *((u32 *) header)); | 357 | mei_me_reg_write(hw, H_CB_WW, *((u32 *) header)); |
325 | 358 | ||
326 | for (i = 0; i < length / 4; i++) | 359 | for (i = 0; i < length / 4; i++) |
327 | mei_reg_write(hw, H_CB_WW, reg_buf[i]); | 360 | mei_me_reg_write(hw, H_CB_WW, reg_buf[i]); |
328 | 361 | ||
329 | rem = length & 0x3; | 362 | rem = length & 0x3; |
330 | if (rem > 0) { | 363 | if (rem > 0) { |
331 | u32 reg = 0; | 364 | u32 reg = 0; |
332 | memcpy(®, &buf[length - rem], rem); | 365 | memcpy(®, &buf[length - rem], rem); |
333 | mei_reg_write(hw, H_CB_WW, reg); | 366 | mei_me_reg_write(hw, H_CB_WW, reg); |
334 | } | 367 | } |
335 | 368 | ||
336 | hcsr = mei_hcsr_read(hw) | H_IG; | 369 | hcsr = mei_hcsr_read(hw) | H_IG; |
@@ -354,7 +387,7 @@ static int mei_me_count_full_read_slots(struct mei_device *dev) | |||
354 | char read_ptr, write_ptr; | 387 | char read_ptr, write_ptr; |
355 | unsigned char buffer_depth, filled_slots; | 388 | unsigned char buffer_depth, filled_slots; |
356 | 389 | ||
357 | hw->me_hw_state = mei_mecsr_read(hw); | 390 | hw->me_hw_state = mei_me_mecsr_read(hw); |
358 | buffer_depth = (unsigned char)((hw->me_hw_state & ME_CBD_HRA) >> 24); | 391 | buffer_depth = (unsigned char)((hw->me_hw_state & ME_CBD_HRA) >> 24); |
359 | read_ptr = (char) ((hw->me_hw_state & ME_CBRP_HRA) >> 8); | 392 | read_ptr = (char) ((hw->me_hw_state & ME_CBRP_HRA) >> 8); |
360 | write_ptr = (char) ((hw->me_hw_state & ME_CBWP_HRA) >> 16); | 393 | write_ptr = (char) ((hw->me_hw_state & ME_CBWP_HRA) >> 16); |
@@ -414,7 +447,7 @@ irqreturn_t mei_me_irq_quick_handler(int irq, void *dev_id) | |||
414 | return IRQ_NONE; | 447 | return IRQ_NONE; |
415 | 448 | ||
416 | /* clear H_IS bit in H_CSR */ | 449 | /* clear H_IS bit in H_CSR */ |
417 | mei_reg_write(hw, H_CSR, csr_reg); | 450 | mei_me_reg_write(hw, H_CSR, csr_reg); |
418 | 451 | ||
419 | return IRQ_WAKE_THREAD; | 452 | return IRQ_WAKE_THREAD; |
420 | } | 453 | } |
@@ -433,12 +466,8 @@ irqreturn_t mei_me_irq_thread_handler(int irq, void *dev_id) | |||
433 | { | 466 | { |
434 | struct mei_device *dev = (struct mei_device *) dev_id; | 467 | struct mei_device *dev = (struct mei_device *) dev_id; |
435 | struct mei_cl_cb complete_list; | 468 | struct mei_cl_cb complete_list; |
436 | struct mei_cl_cb *cb_pos = NULL, *cb_next = NULL; | ||
437 | struct mei_cl *cl; | ||
438 | s32 slots; | 469 | s32 slots; |
439 | int rets; | 470 | int rets; |
440 | bool bus_message_received; | ||
441 | |||
442 | 471 | ||
443 | dev_dbg(&dev->pdev->dev, "function called after ISR to handle the interrupt processing.\n"); | 472 | dev_dbg(&dev->pdev->dev, "function called after ISR to handle the interrupt processing.\n"); |
444 | /* initialize our complete list */ | 473 | /* initialize our complete list */ |
@@ -452,7 +481,7 @@ irqreturn_t mei_me_irq_thread_handler(int irq, void *dev_id) | |||
452 | 481 | ||
453 | /* check if ME wants a reset */ | 482 | /* check if ME wants a reset */ |
454 | if (!mei_hw_is_ready(dev) && | 483 | if (!mei_hw_is_ready(dev) && |
455 | dev->dev_state != MEI_DEV_RESETING && | 484 | dev->dev_state != MEI_DEV_RESETTING && |
456 | dev->dev_state != MEI_DEV_INITIALIZING) { | 485 | dev->dev_state != MEI_DEV_INITIALIZING) { |
457 | dev_dbg(&dev->pdev->dev, "FW not ready.\n"); | 486 | dev_dbg(&dev->pdev->dev, "FW not ready.\n"); |
458 | mei_reset(dev, 1); | 487 | mei_reset(dev, 1); |
@@ -465,14 +494,9 @@ irqreturn_t mei_me_irq_thread_handler(int irq, void *dev_id) | |||
465 | if (mei_hw_is_ready(dev)) { | 494 | if (mei_hw_is_ready(dev)) { |
466 | dev_dbg(&dev->pdev->dev, "we need to start the dev.\n"); | 495 | dev_dbg(&dev->pdev->dev, "we need to start the dev.\n"); |
467 | 496 | ||
468 | mei_host_set_ready(dev); | 497 | dev->recvd_hw_ready = true; |
498 | wake_up_interruptible(&dev->wait_hw_ready); | ||
469 | 499 | ||
470 | dev_dbg(&dev->pdev->dev, "link is established start sending messages.\n"); | ||
471 | /* link is established * start sending messages. */ | ||
472 | |||
473 | dev->dev_state = MEI_DEV_INIT_CLIENTS; | ||
474 | |||
475 | mei_hbm_start_req(dev); | ||
476 | mutex_unlock(&dev->device_lock); | 500 | mutex_unlock(&dev->device_lock); |
477 | return IRQ_HANDLED; | 501 | return IRQ_HANDLED; |
478 | } else { | 502 | } else { |
@@ -499,44 +523,20 @@ end: | |||
499 | dev_dbg(&dev->pdev->dev, "end of bottom half function.\n"); | 523 | dev_dbg(&dev->pdev->dev, "end of bottom half function.\n"); |
500 | dev->hbuf_is_ready = mei_hbuf_is_ready(dev); | 524 | dev->hbuf_is_ready = mei_hbuf_is_ready(dev); |
501 | 525 | ||
502 | bus_message_received = false; | ||
503 | if (dev->recvd_msg && waitqueue_active(&dev->wait_recvd_msg)) { | ||
504 | dev_dbg(&dev->pdev->dev, "received waiting bus message\n"); | ||
505 | bus_message_received = true; | ||
506 | } | ||
507 | mutex_unlock(&dev->device_lock); | 526 | mutex_unlock(&dev->device_lock); |
508 | if (bus_message_received) { | ||
509 | dev_dbg(&dev->pdev->dev, "wake up dev->wait_recvd_msg\n"); | ||
510 | wake_up_interruptible(&dev->wait_recvd_msg); | ||
511 | bus_message_received = false; | ||
512 | } | ||
513 | if (list_empty(&complete_list.list)) | ||
514 | return IRQ_HANDLED; | ||
515 | 527 | ||
528 | mei_irq_compl_handler(dev, &complete_list); | ||
516 | 529 | ||
517 | list_for_each_entry_safe(cb_pos, cb_next, &complete_list.list, list) { | ||
518 | cl = cb_pos->cl; | ||
519 | list_del(&cb_pos->list); | ||
520 | if (cl) { | ||
521 | if (cl != &dev->iamthif_cl) { | ||
522 | dev_dbg(&dev->pdev->dev, "completing call back.\n"); | ||
523 | mei_irq_complete_handler(cl, cb_pos); | ||
524 | cb_pos = NULL; | ||
525 | } else if (cl == &dev->iamthif_cl) { | ||
526 | mei_amthif_complete(dev, cb_pos); | ||
527 | } | ||
528 | } | ||
529 | } | ||
530 | return IRQ_HANDLED; | 530 | return IRQ_HANDLED; |
531 | } | 531 | } |
532 | static const struct mei_hw_ops mei_me_hw_ops = { | 532 | static const struct mei_hw_ops mei_me_hw_ops = { |
533 | 533 | ||
534 | .host_set_ready = mei_me_host_set_ready, | ||
535 | .host_is_ready = mei_me_host_is_ready, | 534 | .host_is_ready = mei_me_host_is_ready, |
536 | 535 | ||
537 | .hw_is_ready = mei_me_hw_is_ready, | 536 | .hw_is_ready = mei_me_hw_is_ready, |
538 | .hw_reset = mei_me_hw_reset, | 537 | .hw_reset = mei_me_hw_reset, |
539 | .hw_config = mei_me_hw_config, | 538 | .hw_config = mei_me_hw_config, |
539 | .hw_start = mei_me_hw_start, | ||
540 | 540 | ||
541 | .intr_clear = mei_me_intr_clear, | 541 | .intr_clear = mei_me_intr_clear, |
542 | .intr_enable = mei_me_intr_enable, | 542 | .intr_enable = mei_me_intr_enable, |
@@ -571,14 +571,6 @@ struct mei_device *mei_me_dev_init(struct pci_dev *pdev) | |||
571 | 571 | ||
572 | mei_device_init(dev); | 572 | mei_device_init(dev); |
573 | 573 | ||
574 | INIT_LIST_HEAD(&dev->wd_cl.link); | ||
575 | INIT_LIST_HEAD(&dev->iamthif_cl.link); | ||
576 | mei_io_list_init(&dev->amthif_cmd_list); | ||
577 | mei_io_list_init(&dev->amthif_rd_complete_list); | ||
578 | |||
579 | INIT_DELAYED_WORK(&dev->timer_work, mei_timer); | ||
580 | INIT_WORK(&dev->init_work, mei_host_client_init); | ||
581 | |||
582 | dev->ops = &mei_me_hw_ops; | 574 | dev->ops = &mei_me_hw_ops; |
583 | 575 | ||
584 | dev->pdev = pdev; | 576 | dev->pdev = pdev; |
diff --git a/drivers/misc/mei/hw-me.h b/drivers/misc/mei/hw-me.h index 8518d3eeb838..80bd829fbd9a 100644 --- a/drivers/misc/mei/hw-me.h +++ b/drivers/misc/mei/hw-me.h | |||
@@ -36,12 +36,6 @@ struct mei_me_hw { | |||
36 | 36 | ||
37 | struct mei_device *mei_me_dev_init(struct pci_dev *pdev); | 37 | struct mei_device *mei_me_dev_init(struct pci_dev *pdev); |
38 | 38 | ||
39 | /* get slots (dwords) from a message length + header (bytes) */ | ||
40 | static inline unsigned char mei_data2slots(size_t length) | ||
41 | { | ||
42 | return DIV_ROUND_UP(sizeof(struct mei_msg_hdr) + length, 4); | ||
43 | } | ||
44 | |||
45 | irqreturn_t mei_me_irq_quick_handler(int irq, void *dev_id); | 39 | irqreturn_t mei_me_irq_quick_handler(int irq, void *dev_id); |
46 | irqreturn_t mei_me_irq_thread_handler(int irq, void *dev_id); | 40 | irqreturn_t mei_me_irq_thread_handler(int irq, void *dev_id); |
47 | 41 | ||
diff --git a/drivers/misc/mei/init.c b/drivers/misc/mei/init.c index 356179991a2e..713d89fedc46 100644 --- a/drivers/misc/mei/init.c +++ b/drivers/misc/mei/init.c | |||
@@ -14,6 +14,7 @@ | |||
14 | * | 14 | * |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include <linux/export.h> | ||
17 | #include <linux/pci.h> | 18 | #include <linux/pci.h> |
18 | #include <linux/sched.h> | 19 | #include <linux/sched.h> |
19 | #include <linux/wait.h> | 20 | #include <linux/wait.h> |
@@ -22,6 +23,7 @@ | |||
22 | #include <linux/mei.h> | 23 | #include <linux/mei.h> |
23 | 24 | ||
24 | #include "mei_dev.h" | 25 | #include "mei_dev.h" |
26 | #include "hbm.h" | ||
25 | #include "client.h" | 27 | #include "client.h" |
26 | 28 | ||
27 | const char *mei_dev_state_str(int state) | 29 | const char *mei_dev_state_str(int state) |
@@ -31,9 +33,8 @@ const char *mei_dev_state_str(int state) | |||
31 | MEI_DEV_STATE(INITIALIZING); | 33 | MEI_DEV_STATE(INITIALIZING); |
32 | MEI_DEV_STATE(INIT_CLIENTS); | 34 | MEI_DEV_STATE(INIT_CLIENTS); |
33 | MEI_DEV_STATE(ENABLED); | 35 | MEI_DEV_STATE(ENABLED); |
34 | MEI_DEV_STATE(RESETING); | 36 | MEI_DEV_STATE(RESETTING); |
35 | MEI_DEV_STATE(DISABLED); | 37 | MEI_DEV_STATE(DISABLED); |
36 | MEI_DEV_STATE(RECOVERING_FROM_RESET); | ||
37 | MEI_DEV_STATE(POWER_DOWN); | 38 | MEI_DEV_STATE(POWER_DOWN); |
38 | MEI_DEV_STATE(POWER_UP); | 39 | MEI_DEV_STATE(POWER_UP); |
39 | default: | 40 | default: |
@@ -46,7 +47,9 @@ void mei_device_init(struct mei_device *dev) | |||
46 | { | 47 | { |
47 | /* setup our list array */ | 48 | /* setup our list array */ |
48 | INIT_LIST_HEAD(&dev->file_list); | 49 | INIT_LIST_HEAD(&dev->file_list); |
50 | INIT_LIST_HEAD(&dev->device_list); | ||
49 | mutex_init(&dev->device_lock); | 51 | mutex_init(&dev->device_lock); |
52 | init_waitqueue_head(&dev->wait_hw_ready); | ||
50 | init_waitqueue_head(&dev->wait_recvd_msg); | 53 | init_waitqueue_head(&dev->wait_recvd_msg); |
51 | init_waitqueue_head(&dev->wait_stop_wd); | 54 | init_waitqueue_head(&dev->wait_stop_wd); |
52 | dev->dev_state = MEI_DEV_INITIALIZING; | 55 | dev->dev_state = MEI_DEV_INITIALIZING; |
@@ -56,19 +59,27 @@ void mei_device_init(struct mei_device *dev) | |||
56 | mei_io_list_init(&dev->write_waiting_list); | 59 | mei_io_list_init(&dev->write_waiting_list); |
57 | mei_io_list_init(&dev->ctrl_wr_list); | 60 | mei_io_list_init(&dev->ctrl_wr_list); |
58 | mei_io_list_init(&dev->ctrl_rd_list); | 61 | mei_io_list_init(&dev->ctrl_rd_list); |
62 | |||
63 | INIT_DELAYED_WORK(&dev->timer_work, mei_timer); | ||
64 | INIT_WORK(&dev->init_work, mei_host_client_init); | ||
65 | |||
66 | INIT_LIST_HEAD(&dev->wd_cl.link); | ||
67 | INIT_LIST_HEAD(&dev->iamthif_cl.link); | ||
68 | mei_io_list_init(&dev->amthif_cmd_list); | ||
69 | mei_io_list_init(&dev->amthif_rd_complete_list); | ||
70 | |||
59 | } | 71 | } |
72 | EXPORT_SYMBOL_GPL(mei_device_init); | ||
60 | 73 | ||
61 | /** | 74 | /** |
62 | * mei_hw_init - initializes host and fw to start work. | 75 | * mei_start - initializes host and fw to start work. |
63 | * | 76 | * |
64 | * @dev: the device structure | 77 | * @dev: the device structure |
65 | * | 78 | * |
66 | * returns 0 on success, <0 on failure. | 79 | * returns 0 on success, <0 on failure. |
67 | */ | 80 | */ |
68 | int mei_hw_init(struct mei_device *dev) | 81 | int mei_start(struct mei_device *dev) |
69 | { | 82 | { |
70 | int ret = 0; | ||
71 | |||
72 | mutex_lock(&dev->device_lock); | 83 | mutex_lock(&dev->device_lock); |
73 | 84 | ||
74 | /* acknowledge interrupt and stop interupts */ | 85 | /* acknowledge interrupt and stop interupts */ |
@@ -76,29 +87,15 @@ int mei_hw_init(struct mei_device *dev) | |||
76 | 87 | ||
77 | mei_hw_config(dev); | 88 | mei_hw_config(dev); |
78 | 89 | ||
79 | dev->recvd_msg = false; | ||
80 | dev_dbg(&dev->pdev->dev, "reset in start the mei device.\n"); | 90 | dev_dbg(&dev->pdev->dev, "reset in start the mei device.\n"); |
81 | 91 | ||
82 | mei_reset(dev, 1); | 92 | mei_reset(dev, 1); |
83 | 93 | ||
84 | /* wait for ME to turn on ME_RDY */ | 94 | if (mei_hbm_start_wait(dev)) { |
85 | if (!dev->recvd_msg) { | 95 | dev_err(&dev->pdev->dev, "HBM haven't started"); |
86 | mutex_unlock(&dev->device_lock); | ||
87 | ret = wait_event_interruptible_timeout(dev->wait_recvd_msg, | ||
88 | dev->recvd_msg, | ||
89 | mei_secs_to_jiffies(MEI_INTEROP_TIMEOUT)); | ||
90 | mutex_lock(&dev->device_lock); | ||
91 | } | ||
92 | |||
93 | if (ret <= 0 && !dev->recvd_msg) { | ||
94 | dev->dev_state = MEI_DEV_DISABLED; | ||
95 | dev_dbg(&dev->pdev->dev, | ||
96 | "wait_event_interruptible_timeout failed" | ||
97 | "on wait for ME to turn on ME_RDY.\n"); | ||
98 | goto err; | 96 | goto err; |
99 | } | 97 | } |
100 | 98 | ||
101 | |||
102 | if (!mei_host_is_ready(dev)) { | 99 | if (!mei_host_is_ready(dev)) { |
103 | dev_err(&dev->pdev->dev, "host is not ready.\n"); | 100 | dev_err(&dev->pdev->dev, "host is not ready.\n"); |
104 | goto err; | 101 | goto err; |
@@ -115,7 +112,6 @@ int mei_hw_init(struct mei_device *dev) | |||
115 | goto err; | 112 | goto err; |
116 | } | 113 | } |
117 | 114 | ||
118 | dev->recvd_msg = false; | ||
119 | dev_dbg(&dev->pdev->dev, "link layer has been established.\n"); | 115 | dev_dbg(&dev->pdev->dev, "link layer has been established.\n"); |
120 | 116 | ||
121 | mutex_unlock(&dev->device_lock); | 117 | mutex_unlock(&dev->device_lock); |
@@ -126,6 +122,7 @@ err: | |||
126 | mutex_unlock(&dev->device_lock); | 122 | mutex_unlock(&dev->device_lock); |
127 | return -ENODEV; | 123 | return -ENODEV; |
128 | } | 124 | } |
125 | EXPORT_SYMBOL_GPL(mei_start); | ||
129 | 126 | ||
130 | /** | 127 | /** |
131 | * mei_reset - resets host and fw. | 128 | * mei_reset - resets host and fw. |
@@ -137,9 +134,6 @@ void mei_reset(struct mei_device *dev, int interrupts_enabled) | |||
137 | { | 134 | { |
138 | bool unexpected; | 135 | bool unexpected; |
139 | 136 | ||
140 | if (dev->dev_state == MEI_DEV_RECOVERING_FROM_RESET) | ||
141 | return; | ||
142 | |||
143 | unexpected = (dev->dev_state != MEI_DEV_INITIALIZING && | 137 | unexpected = (dev->dev_state != MEI_DEV_INITIALIZING && |
144 | dev->dev_state != MEI_DEV_DISABLED && | 138 | dev->dev_state != MEI_DEV_DISABLED && |
145 | dev->dev_state != MEI_DEV_POWER_DOWN && | 139 | dev->dev_state != MEI_DEV_POWER_DOWN && |
@@ -147,11 +141,12 @@ void mei_reset(struct mei_device *dev, int interrupts_enabled) | |||
147 | 141 | ||
148 | mei_hw_reset(dev, interrupts_enabled); | 142 | mei_hw_reset(dev, interrupts_enabled); |
149 | 143 | ||
144 | dev->hbm_state = MEI_HBM_IDLE; | ||
150 | 145 | ||
151 | if (dev->dev_state != MEI_DEV_INITIALIZING) { | 146 | if (dev->dev_state != MEI_DEV_INITIALIZING) { |
152 | if (dev->dev_state != MEI_DEV_DISABLED && | 147 | if (dev->dev_state != MEI_DEV_DISABLED && |
153 | dev->dev_state != MEI_DEV_POWER_DOWN) | 148 | dev->dev_state != MEI_DEV_POWER_DOWN) |
154 | dev->dev_state = MEI_DEV_RESETING; | 149 | dev->dev_state = MEI_DEV_RESETTING; |
155 | 150 | ||
156 | mei_cl_all_disconnect(dev); | 151 | mei_cl_all_disconnect(dev); |
157 | 152 | ||
@@ -176,12 +171,27 @@ void mei_reset(struct mei_device *dev, int interrupts_enabled) | |||
176 | dev_warn(&dev->pdev->dev, "unexpected reset: dev_state = %s\n", | 171 | dev_warn(&dev->pdev->dev, "unexpected reset: dev_state = %s\n", |
177 | mei_dev_state_str(dev->dev_state)); | 172 | mei_dev_state_str(dev->dev_state)); |
178 | 173 | ||
174 | if (!interrupts_enabled) { | ||
175 | dev_dbg(&dev->pdev->dev, "intr not enabled end of reset\n"); | ||
176 | return; | ||
177 | } | ||
178 | |||
179 | mei_hw_start(dev); | ||
180 | |||
181 | dev_dbg(&dev->pdev->dev, "link is established start sending messages.\n"); | ||
182 | /* link is established * start sending messages. */ | ||
183 | |||
184 | dev->dev_state = MEI_DEV_INIT_CLIENTS; | ||
185 | |||
186 | mei_hbm_start_req(dev); | ||
187 | |||
179 | /* wake up all readings so they can be interrupted */ | 188 | /* wake up all readings so they can be interrupted */ |
180 | mei_cl_all_read_wakeup(dev); | 189 | mei_cl_all_read_wakeup(dev); |
181 | 190 | ||
182 | /* remove all waiting requests */ | 191 | /* remove all waiting requests */ |
183 | mei_cl_all_write_clear(dev); | 192 | mei_cl_all_write_clear(dev); |
184 | } | 193 | } |
194 | EXPORT_SYMBOL_GPL(mei_reset); | ||
185 | 195 | ||
186 | void mei_stop(struct mei_device *dev) | 196 | void mei_stop(struct mei_device *dev) |
187 | { | 197 | { |
@@ -193,14 +203,18 @@ void mei_stop(struct mei_device *dev) | |||
193 | 203 | ||
194 | mei_wd_stop(dev); | 204 | mei_wd_stop(dev); |
195 | 205 | ||
206 | mei_nfc_host_exit(); | ||
207 | |||
196 | dev->dev_state = MEI_DEV_POWER_DOWN; | 208 | dev->dev_state = MEI_DEV_POWER_DOWN; |
197 | mei_reset(dev, 0); | 209 | mei_reset(dev, 0); |
198 | 210 | ||
199 | mutex_unlock(&dev->device_lock); | 211 | mutex_unlock(&dev->device_lock); |
200 | 212 | ||
201 | flush_scheduled_work(); | 213 | flush_scheduled_work(); |
202 | } | ||
203 | 214 | ||
215 | mei_watchdog_unregister(dev); | ||
216 | } | ||
217 | EXPORT_SYMBOL_GPL(mei_stop); | ||
204 | 218 | ||
205 | 219 | ||
206 | 220 | ||
diff --git a/drivers/misc/mei/interrupt.c b/drivers/misc/mei/interrupt.c index 3535b2676c97..1473cfdbc426 100644 --- a/drivers/misc/mei/interrupt.c +++ b/drivers/misc/mei/interrupt.c | |||
@@ -15,6 +15,7 @@ | |||
15 | */ | 15 | */ |
16 | 16 | ||
17 | 17 | ||
18 | #include <linux/export.h> | ||
18 | #include <linux/pci.h> | 19 | #include <linux/pci.h> |
19 | #include <linux/kthread.h> | 20 | #include <linux/kthread.h> |
20 | #include <linux/interrupt.h> | 21 | #include <linux/interrupt.h> |
@@ -30,103 +31,153 @@ | |||
30 | 31 | ||
31 | 32 | ||
32 | /** | 33 | /** |
33 | * mei_complete_handler - processes completed operation. | 34 | * mei_cl_complete_handler - processes completed operation for a client |
34 | * | 35 | * |
35 | * @cl: private data of the file object. | 36 | * @cl: private data of the file object. |
36 | * @cb_pos: callback block. | 37 | * @cb: callback block. |
37 | */ | 38 | */ |
38 | void mei_irq_complete_handler(struct mei_cl *cl, struct mei_cl_cb *cb_pos) | 39 | static void mei_cl_complete_handler(struct mei_cl *cl, struct mei_cl_cb *cb) |
39 | { | 40 | { |
40 | if (cb_pos->fop_type == MEI_FOP_WRITE) { | 41 | if (cb->fop_type == MEI_FOP_WRITE) { |
41 | mei_io_cb_free(cb_pos); | 42 | mei_io_cb_free(cb); |
42 | cb_pos = NULL; | 43 | cb = NULL; |
43 | cl->writing_state = MEI_WRITE_COMPLETE; | 44 | cl->writing_state = MEI_WRITE_COMPLETE; |
44 | if (waitqueue_active(&cl->tx_wait)) | 45 | if (waitqueue_active(&cl->tx_wait)) |
45 | wake_up_interruptible(&cl->tx_wait); | 46 | wake_up_interruptible(&cl->tx_wait); |
46 | 47 | ||
47 | } else if (cb_pos->fop_type == MEI_FOP_READ && | 48 | } else if (cb->fop_type == MEI_FOP_READ && |
48 | MEI_READING == cl->reading_state) { | 49 | MEI_READING == cl->reading_state) { |
49 | cl->reading_state = MEI_READ_COMPLETE; | 50 | cl->reading_state = MEI_READ_COMPLETE; |
50 | if (waitqueue_active(&cl->rx_wait)) | 51 | if (waitqueue_active(&cl->rx_wait)) |
51 | wake_up_interruptible(&cl->rx_wait); | 52 | wake_up_interruptible(&cl->rx_wait); |
53 | else | ||
54 | mei_cl_bus_rx_event(cl); | ||
55 | |||
56 | } | ||
57 | } | ||
58 | |||
59 | /** | ||
60 | * mei_irq_compl_handler - dispatch complete handelers | ||
61 | * for the completed callbacks | ||
62 | * | ||
63 | * @dev - mei device | ||
64 | * @compl_list - list of completed cbs | ||
65 | */ | ||
66 | void mei_irq_compl_handler(struct mei_device *dev, struct mei_cl_cb *compl_list) | ||
67 | { | ||
68 | struct mei_cl_cb *cb, *next; | ||
69 | struct mei_cl *cl; | ||
70 | |||
71 | list_for_each_entry_safe(cb, next, &compl_list->list, list) { | ||
72 | cl = cb->cl; | ||
73 | list_del(&cb->list); | ||
74 | if (!cl) | ||
75 | continue; | ||
52 | 76 | ||
77 | dev_dbg(&dev->pdev->dev, "completing call back.\n"); | ||
78 | if (cl == &dev->iamthif_cl) | ||
79 | mei_amthif_complete(dev, cb); | ||
80 | else | ||
81 | mei_cl_complete_handler(cl, cb); | ||
53 | } | 82 | } |
54 | } | 83 | } |
84 | EXPORT_SYMBOL_GPL(mei_irq_compl_handler); | ||
55 | 85 | ||
56 | /** | 86 | /** |
57 | * _mei_irq_thread_state_ok - checks if mei header matches file private data | 87 | * mei_cl_hbm_equal - check if hbm is addressed to the client |
58 | * | 88 | * |
59 | * @cl: private data of the file object | 89 | * @cl: host client |
60 | * @mei_hdr: header of mei client message | 90 | * @mei_hdr: header of mei client message |
61 | * | 91 | * |
62 | * returns !=0 if matches, 0 if no match. | 92 | * returns true if matches, false otherwise |
93 | */ | ||
94 | static inline int mei_cl_hbm_equal(struct mei_cl *cl, | ||
95 | struct mei_msg_hdr *mei_hdr) | ||
96 | { | ||
97 | return cl->host_client_id == mei_hdr->host_addr && | ||
98 | cl->me_client_id == mei_hdr->me_addr; | ||
99 | } | ||
100 | /** | ||
101 | * mei_cl_is_reading - checks if the client | ||
102 | is the one to read this message | ||
103 | * | ||
104 | * @cl: mei client | ||
105 | * @mei_hdr: header of mei message | ||
106 | * | ||
107 | * returns true on match and false otherwise | ||
63 | */ | 108 | */ |
64 | static int _mei_irq_thread_state_ok(struct mei_cl *cl, | 109 | static bool mei_cl_is_reading(struct mei_cl *cl, struct mei_msg_hdr *mei_hdr) |
65 | struct mei_msg_hdr *mei_hdr) | ||
66 | { | 110 | { |
67 | return (cl->host_client_id == mei_hdr->host_addr && | 111 | return mei_cl_hbm_equal(cl, mei_hdr) && |
68 | cl->me_client_id == mei_hdr->me_addr && | ||
69 | cl->state == MEI_FILE_CONNECTED && | 112 | cl->state == MEI_FILE_CONNECTED && |
70 | MEI_READ_COMPLETE != cl->reading_state); | 113 | cl->reading_state != MEI_READ_COMPLETE; |
71 | } | 114 | } |
72 | 115 | ||
73 | /** | 116 | /** |
74 | * mei_irq_thread_read_client_message - bottom half read routine after ISR to | 117 | * mei_irq_read_client_message - process client message |
75 | * handle the read mei client message data processing. | ||
76 | * | 118 | * |
77 | * @complete_list: An instance of our list structure | ||
78 | * @dev: the device structure | 119 | * @dev: the device structure |
79 | * @mei_hdr: header of mei client message | 120 | * @mei_hdr: header of mei client message |
121 | * @complete_list: An instance of our list structure | ||
80 | * | 122 | * |
81 | * returns 0 on success, <0 on failure. | 123 | * returns 0 on success, <0 on failure. |
82 | */ | 124 | */ |
83 | static int mei_irq_thread_read_client_message(struct mei_cl_cb *complete_list, | 125 | static int mei_cl_irq_read_msg(struct mei_device *dev, |
84 | struct mei_device *dev, | 126 | struct mei_msg_hdr *mei_hdr, |
85 | struct mei_msg_hdr *mei_hdr) | 127 | struct mei_cl_cb *complete_list) |
86 | { | 128 | { |
87 | struct mei_cl *cl; | 129 | struct mei_cl *cl; |
88 | struct mei_cl_cb *cb_pos = NULL, *cb_next = NULL; | 130 | struct mei_cl_cb *cb, *next; |
89 | unsigned char *buffer = NULL; | 131 | unsigned char *buffer = NULL; |
90 | 132 | ||
91 | dev_dbg(&dev->pdev->dev, "start client msg\n"); | 133 | list_for_each_entry_safe(cb, next, &dev->read_list.list, list) { |
92 | if (list_empty(&dev->read_list.list)) | 134 | cl = cb->cl; |
93 | goto quit; | 135 | if (!cl || !mei_cl_is_reading(cl, mei_hdr)) |
136 | continue; | ||
94 | 137 | ||
95 | list_for_each_entry_safe(cb_pos, cb_next, &dev->read_list.list, list) { | 138 | cl->reading_state = MEI_READING; |
96 | cl = cb_pos->cl; | ||
97 | if (cl && _mei_irq_thread_state_ok(cl, mei_hdr)) { | ||
98 | cl->reading_state = MEI_READING; | ||
99 | buffer = cb_pos->response_buffer.data + cb_pos->buf_idx; | ||
100 | 139 | ||
101 | if (cb_pos->response_buffer.size < | 140 | if (cb->response_buffer.size == 0 || |
102 | mei_hdr->length + cb_pos->buf_idx) { | 141 | cb->response_buffer.data == NULL) { |
103 | dev_dbg(&dev->pdev->dev, "message overflow.\n"); | 142 | dev_err(&dev->pdev->dev, "response buffer is not allocated.\n"); |
104 | list_del(&cb_pos->list); | 143 | list_del(&cb->list); |
144 | return -ENOMEM; | ||
145 | } | ||
146 | |||
147 | if (cb->response_buffer.size < mei_hdr->length + cb->buf_idx) { | ||
148 | dev_dbg(&dev->pdev->dev, "message overflow. size %d len %d idx %ld\n", | ||
149 | cb->response_buffer.size, | ||
150 | mei_hdr->length, cb->buf_idx); | ||
151 | buffer = krealloc(cb->response_buffer.data, | ||
152 | mei_hdr->length + cb->buf_idx, | ||
153 | GFP_KERNEL); | ||
154 | |||
155 | if (!buffer) { | ||
156 | dev_err(&dev->pdev->dev, "allocation failed.\n"); | ||
157 | list_del(&cb->list); | ||
105 | return -ENOMEM; | 158 | return -ENOMEM; |
106 | } | 159 | } |
107 | if (buffer) | 160 | cb->response_buffer.data = buffer; |
108 | mei_read_slots(dev, buffer, mei_hdr->length); | 161 | cb->response_buffer.size = |
109 | 162 | mei_hdr->length + cb->buf_idx; | |
110 | cb_pos->buf_idx += mei_hdr->length; | ||
111 | if (mei_hdr->msg_complete) { | ||
112 | cl->status = 0; | ||
113 | list_del(&cb_pos->list); | ||
114 | dev_dbg(&dev->pdev->dev, | ||
115 | "completed read H cl = %d, ME cl = %d, length = %lu\n", | ||
116 | cl->host_client_id, | ||
117 | cl->me_client_id, | ||
118 | cb_pos->buf_idx); | ||
119 | |||
120 | list_add_tail(&cb_pos->list, | ||
121 | &complete_list->list); | ||
122 | } | ||
123 | |||
124 | break; | ||
125 | } | 163 | } |
126 | 164 | ||
165 | buffer = cb->response_buffer.data + cb->buf_idx; | ||
166 | mei_read_slots(dev, buffer, mei_hdr->length); | ||
167 | |||
168 | cb->buf_idx += mei_hdr->length; | ||
169 | if (mei_hdr->msg_complete) { | ||
170 | cl->status = 0; | ||
171 | list_del(&cb->list); | ||
172 | dev_dbg(&dev->pdev->dev, "completed read H cl = %d, ME cl = %d, length = %lu\n", | ||
173 | cl->host_client_id, | ||
174 | cl->me_client_id, | ||
175 | cb->buf_idx); | ||
176 | list_add_tail(&cb->list, &complete_list->list); | ||
177 | } | ||
178 | break; | ||
127 | } | 179 | } |
128 | 180 | ||
129 | quit: | ||
130 | dev_dbg(&dev->pdev->dev, "message read\n"); | 181 | dev_dbg(&dev->pdev->dev, "message read\n"); |
131 | if (!buffer) { | 182 | if (!buffer) { |
132 | mei_read_slots(dev, dev->rd_msg_buf, mei_hdr->length); | 183 | mei_read_slots(dev, dev->rd_msg_buf, mei_hdr->length); |
@@ -153,25 +204,27 @@ static int _mei_irq_thread_close(struct mei_device *dev, s32 *slots, | |||
153 | struct mei_cl *cl, | 204 | struct mei_cl *cl, |
154 | struct mei_cl_cb *cmpl_list) | 205 | struct mei_cl_cb *cmpl_list) |
155 | { | 206 | { |
156 | if ((*slots * sizeof(u32)) < (sizeof(struct mei_msg_hdr) + | 207 | u32 msg_slots = |
157 | sizeof(struct hbm_client_connect_request))) | 208 | mei_data2slots(sizeof(struct hbm_client_connect_request)); |
158 | return -EBADMSG; | ||
159 | 209 | ||
160 | *slots -= mei_data2slots(sizeof(struct hbm_client_connect_request)); | 210 | if (*slots < msg_slots) |
211 | return -EMSGSIZE; | ||
212 | |||
213 | *slots -= msg_slots; | ||
161 | 214 | ||
162 | if (mei_hbm_cl_disconnect_req(dev, cl)) { | 215 | if (mei_hbm_cl_disconnect_req(dev, cl)) { |
163 | cl->status = 0; | 216 | cl->status = 0; |
164 | cb_pos->buf_idx = 0; | 217 | cb_pos->buf_idx = 0; |
165 | list_move_tail(&cb_pos->list, &cmpl_list->list); | 218 | list_move_tail(&cb_pos->list, &cmpl_list->list); |
166 | return -EMSGSIZE; | 219 | return -EIO; |
167 | } else { | ||
168 | cl->state = MEI_FILE_DISCONNECTING; | ||
169 | cl->status = 0; | ||
170 | cb_pos->buf_idx = 0; | ||
171 | list_move_tail(&cb_pos->list, &dev->ctrl_rd_list.list); | ||
172 | cl->timer_count = MEI_CONNECT_TIMEOUT; | ||
173 | } | 220 | } |
174 | 221 | ||
222 | cl->state = MEI_FILE_DISCONNECTING; | ||
223 | cl->status = 0; | ||
224 | cb_pos->buf_idx = 0; | ||
225 | list_move_tail(&cb_pos->list, &dev->ctrl_rd_list.list); | ||
226 | cl->timer_count = MEI_CONNECT_TIMEOUT; | ||
227 | |||
175 | return 0; | 228 | return 0; |
176 | } | 229 | } |
177 | 230 | ||
@@ -192,14 +245,15 @@ static int _mei_irq_thread_read(struct mei_device *dev, s32 *slots, | |||
192 | struct mei_cl *cl, | 245 | struct mei_cl *cl, |
193 | struct mei_cl_cb *cmpl_list) | 246 | struct mei_cl_cb *cmpl_list) |
194 | { | 247 | { |
195 | if ((*slots * sizeof(u32)) < (sizeof(struct mei_msg_hdr) + | 248 | u32 msg_slots = mei_data2slots(sizeof(struct hbm_flow_control)); |
196 | sizeof(struct hbm_flow_control))) { | 249 | |
250 | if (*slots < msg_slots) { | ||
197 | /* return the cancel routine */ | 251 | /* return the cancel routine */ |
198 | list_del(&cb_pos->list); | 252 | list_del(&cb_pos->list); |
199 | return -EBADMSG; | 253 | return -EMSGSIZE; |
200 | } | 254 | } |
201 | 255 | ||
202 | *slots -= mei_data2slots(sizeof(struct hbm_flow_control)); | 256 | *slots -= msg_slots; |
203 | 257 | ||
204 | if (mei_hbm_cl_flow_control_req(dev, cl)) { | 258 | if (mei_hbm_cl_flow_control_req(dev, cl)) { |
205 | cl->status = -ENODEV; | 259 | cl->status = -ENODEV; |
@@ -229,15 +283,19 @@ static int _mei_irq_thread_ioctl(struct mei_device *dev, s32 *slots, | |||
229 | struct mei_cl *cl, | 283 | struct mei_cl *cl, |
230 | struct mei_cl_cb *cmpl_list) | 284 | struct mei_cl_cb *cmpl_list) |
231 | { | 285 | { |
232 | if ((*slots * sizeof(u32)) < (sizeof(struct mei_msg_hdr) + | 286 | u32 msg_slots = |
233 | sizeof(struct hbm_client_connect_request))) { | 287 | mei_data2slots(sizeof(struct hbm_client_connect_request)); |
288 | |||
289 | if (*slots < msg_slots) { | ||
234 | /* return the cancel routine */ | 290 | /* return the cancel routine */ |
235 | list_del(&cb_pos->list); | 291 | list_del(&cb_pos->list); |
236 | return -EBADMSG; | 292 | return -EMSGSIZE; |
237 | } | 293 | } |
238 | 294 | ||
295 | *slots -= msg_slots; | ||
296 | |||
239 | cl->state = MEI_FILE_CONNECTING; | 297 | cl->state = MEI_FILE_CONNECTING; |
240 | *slots -= mei_data2slots(sizeof(struct hbm_client_connect_request)); | 298 | |
241 | if (mei_hbm_cl_connect_req(dev, cl)) { | 299 | if (mei_hbm_cl_connect_req(dev, cl)) { |
242 | cl->status = -ENODEV; | 300 | cl->status = -ENODEV; |
243 | cb_pos->buf_idx = 0; | 301 | cb_pos->buf_idx = 0; |
@@ -266,7 +324,7 @@ static int mei_irq_thread_write_complete(struct mei_device *dev, s32 *slots, | |||
266 | struct mei_msg_hdr mei_hdr; | 324 | struct mei_msg_hdr mei_hdr; |
267 | struct mei_cl *cl = cb->cl; | 325 | struct mei_cl *cl = cb->cl; |
268 | size_t len = cb->request_buffer.size - cb->buf_idx; | 326 | size_t len = cb->request_buffer.size - cb->buf_idx; |
269 | size_t msg_slots = mei_data2slots(len); | 327 | u32 msg_slots = mei_data2slots(len); |
270 | 328 | ||
271 | mei_hdr.host_addr = cl->host_client_id; | 329 | mei_hdr.host_addr = cl->host_client_id; |
272 | mei_hdr.me_addr = cl->me_client_id; | 330 | mei_hdr.me_addr = cl->me_client_id; |
@@ -298,13 +356,14 @@ static int mei_irq_thread_write_complete(struct mei_device *dev, s32 *slots, | |||
298 | return -ENODEV; | 356 | return -ENODEV; |
299 | } | 357 | } |
300 | 358 | ||
301 | if (mei_cl_flow_ctrl_reduce(cl)) | ||
302 | return -ENODEV; | ||
303 | 359 | ||
304 | cl->status = 0; | 360 | cl->status = 0; |
305 | cb->buf_idx += mei_hdr.length; | 361 | cb->buf_idx += mei_hdr.length; |
306 | if (mei_hdr.msg_complete) | 362 | if (mei_hdr.msg_complete) { |
363 | if (mei_cl_flow_ctrl_reduce(cl)) | ||
364 | return -ENODEV; | ||
307 | list_move_tail(&cb->list, &dev->write_waiting_list.list); | 365 | list_move_tail(&cb->list, &dev->write_waiting_list.list); |
366 | } | ||
308 | 367 | ||
309 | return 0; | 368 | return 0; |
310 | } | 369 | } |
@@ -350,8 +409,7 @@ int mei_irq_read_handler(struct mei_device *dev, | |||
350 | " client = %d, ME client = %d\n", | 409 | " client = %d, ME client = %d\n", |
351 | cl_pos->host_client_id, | 410 | cl_pos->host_client_id, |
352 | cl_pos->me_client_id); | 411 | cl_pos->me_client_id); |
353 | if (cl_pos->host_client_id == mei_hdr->host_addr && | 412 | if (mei_cl_hbm_equal(cl_pos, mei_hdr)) |
354 | cl_pos->me_client_id == mei_hdr->me_addr) | ||
355 | break; | 413 | break; |
356 | } | 414 | } |
357 | 415 | ||
@@ -362,7 +420,7 @@ int mei_irq_read_handler(struct mei_device *dev, | |||
362 | } | 420 | } |
363 | } | 421 | } |
364 | if (((*slots) * sizeof(u32)) < mei_hdr->length) { | 422 | if (((*slots) * sizeof(u32)) < mei_hdr->length) { |
365 | dev_dbg(&dev->pdev->dev, | 423 | dev_err(&dev->pdev->dev, |
366 | "we can't read the message slots =%08x.\n", | 424 | "we can't read the message slots =%08x.\n", |
367 | *slots); | 425 | *slots); |
368 | /* we can't read the message */ | 426 | /* we can't read the message */ |
@@ -378,20 +436,19 @@ int mei_irq_read_handler(struct mei_device *dev, | |||
378 | } else if (mei_hdr->host_addr == dev->iamthif_cl.host_client_id && | 436 | } else if (mei_hdr->host_addr == dev->iamthif_cl.host_client_id && |
379 | (MEI_FILE_CONNECTED == dev->iamthif_cl.state) && | 437 | (MEI_FILE_CONNECTED == dev->iamthif_cl.state) && |
380 | (dev->iamthif_state == MEI_IAMTHIF_READING)) { | 438 | (dev->iamthif_state == MEI_IAMTHIF_READING)) { |
381 | dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_iamthif_message.\n"); | ||
382 | 439 | ||
440 | dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_iamthif_message.\n"); | ||
383 | dev_dbg(&dev->pdev->dev, MEI_HDR_FMT, MEI_HDR_PRM(mei_hdr)); | 441 | dev_dbg(&dev->pdev->dev, MEI_HDR_FMT, MEI_HDR_PRM(mei_hdr)); |
384 | 442 | ||
385 | ret = mei_amthif_irq_read_message(cmpl_list, dev, mei_hdr); | 443 | ret = mei_amthif_irq_read_msg(dev, mei_hdr, cmpl_list); |
386 | if (ret) | 444 | if (ret) |
387 | goto end; | 445 | goto end; |
388 | } else { | 446 | } else { |
389 | dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_client_message.\n"); | 447 | dev_dbg(&dev->pdev->dev, "call mei_cl_irq_read_msg.\n"); |
390 | ret = mei_irq_thread_read_client_message(cmpl_list, | 448 | dev_dbg(&dev->pdev->dev, MEI_HDR_FMT, MEI_HDR_PRM(mei_hdr)); |
391 | dev, mei_hdr); | 449 | ret = mei_cl_irq_read_msg(dev, mei_hdr, cmpl_list); |
392 | if (ret) | 450 | if (ret) |
393 | goto end; | 451 | goto end; |
394 | |||
395 | } | 452 | } |
396 | 453 | ||
397 | /* reset the number of slots and header */ | 454 | /* reset the number of slots and header */ |
@@ -400,7 +457,7 @@ int mei_irq_read_handler(struct mei_device *dev, | |||
400 | 457 | ||
401 | if (*slots == -EOVERFLOW) { | 458 | if (*slots == -EOVERFLOW) { |
402 | /* overflow - reset */ | 459 | /* overflow - reset */ |
403 | dev_dbg(&dev->pdev->dev, "resetting due to slots overflow.\n"); | 460 | dev_err(&dev->pdev->dev, "resetting due to slots overflow.\n"); |
404 | /* set the event since message has been read */ | 461 | /* set the event since message has been read */ |
405 | ret = -ERANGE; | 462 | ret = -ERANGE; |
406 | goto end; | 463 | goto end; |
@@ -408,6 +465,7 @@ int mei_irq_read_handler(struct mei_device *dev, | |||
408 | end: | 465 | end: |
409 | return ret; | 466 | return ret; |
410 | } | 467 | } |
468 | EXPORT_SYMBOL_GPL(mei_irq_read_handler); | ||
411 | 469 | ||
412 | 470 | ||
413 | /** | 471 | /** |
@@ -419,8 +477,7 @@ end: | |||
419 | * | 477 | * |
420 | * returns 0 on success, <0 on failure. | 478 | * returns 0 on success, <0 on failure. |
421 | */ | 479 | */ |
422 | int mei_irq_write_handler(struct mei_device *dev, | 480 | int mei_irq_write_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list) |
423 | struct mei_cl_cb *cmpl_list) | ||
424 | { | 481 | { |
425 | 482 | ||
426 | struct mei_cl *cl; | 483 | struct mei_cl *cl; |
@@ -559,6 +616,7 @@ int mei_irq_write_handler(struct mei_device *dev, | |||
559 | } | 616 | } |
560 | return 0; | 617 | return 0; |
561 | } | 618 | } |
619 | EXPORT_SYMBOL_GPL(mei_irq_write_handler); | ||
562 | 620 | ||
563 | 621 | ||
564 | 622 | ||
@@ -586,8 +644,8 @@ void mei_timer(struct work_struct *work) | |||
586 | if (dev->dev_state == MEI_DEV_INIT_CLIENTS) { | 644 | if (dev->dev_state == MEI_DEV_INIT_CLIENTS) { |
587 | if (dev->init_clients_timer) { | 645 | if (dev->init_clients_timer) { |
588 | if (--dev->init_clients_timer == 0) { | 646 | if (--dev->init_clients_timer == 0) { |
589 | dev_dbg(&dev->pdev->dev, "IMEI reset due to init clients timeout ,init clients state = %d.\n", | 647 | dev_err(&dev->pdev->dev, "reset: init clients timeout hbm_state = %d.\n", |
590 | dev->init_clients_state); | 648 | dev->hbm_state); |
591 | mei_reset(dev, 1); | 649 | mei_reset(dev, 1); |
592 | } | 650 | } |
593 | } | 651 | } |
@@ -598,7 +656,7 @@ void mei_timer(struct work_struct *work) | |||
598 | list_for_each_entry_safe(cl_pos, cl_next, &dev->file_list, link) { | 656 | list_for_each_entry_safe(cl_pos, cl_next, &dev->file_list, link) { |
599 | if (cl_pos->timer_count) { | 657 | if (cl_pos->timer_count) { |
600 | if (--cl_pos->timer_count == 0) { | 658 | if (--cl_pos->timer_count == 0) { |
601 | dev_dbg(&dev->pdev->dev, "HECI reset due to connect/disconnect timeout.\n"); | 659 | dev_err(&dev->pdev->dev, "reset: connect/disconnect timeout.\n"); |
602 | mei_reset(dev, 1); | 660 | mei_reset(dev, 1); |
603 | goto out; | 661 | goto out; |
604 | } | 662 | } |
@@ -607,7 +665,7 @@ void mei_timer(struct work_struct *work) | |||
607 | 665 | ||
608 | if (dev->iamthif_stall_timer) { | 666 | if (dev->iamthif_stall_timer) { |
609 | if (--dev->iamthif_stall_timer == 0) { | 667 | if (--dev->iamthif_stall_timer == 0) { |
610 | dev_dbg(&dev->pdev->dev, "resetting because of hang to amthi.\n"); | 668 | dev_err(&dev->pdev->dev, "reset: amthif hanged.\n"); |
611 | mei_reset(dev, 1); | 669 | mei_reset(dev, 1); |
612 | dev->iamthif_msg_buf_size = 0; | 670 | dev->iamthif_msg_buf_size = 0; |
613 | dev->iamthif_msg_buf_index = 0; | 671 | dev->iamthif_msg_buf_index = 0; |
diff --git a/drivers/misc/mei/main.c b/drivers/misc/mei/main.c index 903f809b21f7..7c44c8dbae42 100644 --- a/drivers/misc/mei/main.c +++ b/drivers/misc/mei/main.c | |||
@@ -48,7 +48,7 @@ | |||
48 | * | 48 | * |
49 | * @inode: pointer to inode structure | 49 | * @inode: pointer to inode structure |
50 | * @file: pointer to file structure | 50 | * @file: pointer to file structure |
51 | * | 51 | e |
52 | * returns 0 on success, <0 on error | 52 | * returns 0 on success, <0 on error |
53 | */ | 53 | */ |
54 | static int mei_open(struct inode *inode, struct file *file) | 54 | static int mei_open(struct inode *inode, struct file *file) |
@@ -244,7 +244,7 @@ static ssize_t mei_read(struct file *file, char __user *ubuf, | |||
244 | goto out; | 244 | goto out; |
245 | } | 245 | } |
246 | 246 | ||
247 | err = mei_cl_read_start(cl); | 247 | err = mei_cl_read_start(cl, length); |
248 | if (err && err != -EBUSY) { | 248 | if (err && err != -EBUSY) { |
249 | dev_dbg(&dev->pdev->dev, | 249 | dev_dbg(&dev->pdev->dev, |
250 | "mei start read failure with status = %d\n", err); | 250 | "mei start read failure with status = %d\n", err); |
@@ -292,9 +292,8 @@ static ssize_t mei_read(struct file *file, char __user *ubuf, | |||
292 | } | 292 | } |
293 | /* now copy the data to user space */ | 293 | /* now copy the data to user space */ |
294 | copy_buffer: | 294 | copy_buffer: |
295 | dev_dbg(&dev->pdev->dev, "cb->response_buffer size - %d\n", | 295 | dev_dbg(&dev->pdev->dev, "buf.size = %d buf.idx= %ld\n", |
296 | cb->response_buffer.size); | 296 | cb->response_buffer.size, cb->buf_idx); |
297 | dev_dbg(&dev->pdev->dev, "cb->buf_idx - %lu\n", cb->buf_idx); | ||
298 | if (length == 0 || ubuf == NULL || *offset > cb->buf_idx) { | 297 | if (length == 0 || ubuf == NULL || *offset > cb->buf_idx) { |
299 | rets = -EMSGSIZE; | 298 | rets = -EMSGSIZE; |
300 | goto free; | 299 | goto free; |
@@ -342,11 +341,10 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, | |||
342 | { | 341 | { |
343 | struct mei_cl *cl = file->private_data; | 342 | struct mei_cl *cl = file->private_data; |
344 | struct mei_cl_cb *write_cb = NULL; | 343 | struct mei_cl_cb *write_cb = NULL; |
345 | struct mei_msg_hdr mei_hdr; | ||
346 | struct mei_device *dev; | 344 | struct mei_device *dev; |
347 | unsigned long timeout = 0; | 345 | unsigned long timeout = 0; |
348 | int rets; | 346 | int rets; |
349 | int i; | 347 | int id; |
350 | 348 | ||
351 | if (WARN_ON(!cl || !cl->dev)) | 349 | if (WARN_ON(!cl || !cl->dev)) |
352 | return -ENODEV; | 350 | return -ENODEV; |
@@ -357,24 +355,24 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, | |||
357 | 355 | ||
358 | if (dev->dev_state != MEI_DEV_ENABLED) { | 356 | if (dev->dev_state != MEI_DEV_ENABLED) { |
359 | rets = -ENODEV; | 357 | rets = -ENODEV; |
360 | goto err; | 358 | goto out; |
361 | } | 359 | } |
362 | 360 | ||
363 | i = mei_me_cl_by_id(dev, cl->me_client_id); | 361 | id = mei_me_cl_by_id(dev, cl->me_client_id); |
364 | if (i < 0) { | 362 | if (id < 0) { |
365 | rets = -ENODEV; | 363 | rets = -ENODEV; |
366 | goto err; | 364 | goto out; |
367 | } | 365 | } |
368 | if (length > dev->me_clients[i].props.max_msg_length || length <= 0) { | 366 | if (length > dev->me_clients[id].props.max_msg_length || length <= 0) { |
369 | rets = -EMSGSIZE; | 367 | rets = -EMSGSIZE; |
370 | goto err; | 368 | goto out; |
371 | } | 369 | } |
372 | 370 | ||
373 | if (cl->state != MEI_FILE_CONNECTED) { | 371 | if (cl->state != MEI_FILE_CONNECTED) { |
374 | rets = -ENODEV; | ||
375 | dev_err(&dev->pdev->dev, "host client = %d, is not connected to ME client = %d", | 372 | dev_err(&dev->pdev->dev, "host client = %d, is not connected to ME client = %d", |
376 | cl->host_client_id, cl->me_client_id); | 373 | cl->host_client_id, cl->me_client_id); |
377 | goto err; | 374 | rets = -ENODEV; |
375 | goto out; | ||
378 | } | 376 | } |
379 | if (cl == &dev->iamthif_cl) { | 377 | if (cl == &dev->iamthif_cl) { |
380 | write_cb = mei_amthif_find_read_list_entry(dev, file); | 378 | write_cb = mei_amthif_find_read_list_entry(dev, file); |
@@ -412,17 +410,15 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, | |||
412 | if (!write_cb) { | 410 | if (!write_cb) { |
413 | dev_err(&dev->pdev->dev, "write cb allocation failed\n"); | 411 | dev_err(&dev->pdev->dev, "write cb allocation failed\n"); |
414 | rets = -ENOMEM; | 412 | rets = -ENOMEM; |
415 | goto err; | 413 | goto out; |
416 | } | 414 | } |
417 | rets = mei_io_cb_alloc_req_buf(write_cb, length); | 415 | rets = mei_io_cb_alloc_req_buf(write_cb, length); |
418 | if (rets) | 416 | if (rets) |
419 | goto err; | 417 | goto out; |
420 | |||
421 | dev_dbg(&dev->pdev->dev, "cb request size = %zd\n", length); | ||
422 | 418 | ||
423 | rets = copy_from_user(write_cb->request_buffer.data, ubuf, length); | 419 | rets = copy_from_user(write_cb->request_buffer.data, ubuf, length); |
424 | if (rets) | 420 | if (rets) |
425 | goto err; | 421 | goto out; |
426 | 422 | ||
427 | cl->sm_state = 0; | 423 | cl->sm_state = 0; |
428 | if (length == 4 && | 424 | if (length == 4 && |
@@ -440,65 +436,17 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, | |||
440 | if (rets) { | 436 | if (rets) { |
441 | dev_err(&dev->pdev->dev, | 437 | dev_err(&dev->pdev->dev, |
442 | "amthif write failed with status = %d\n", rets); | 438 | "amthif write failed with status = %d\n", rets); |
443 | goto err; | 439 | goto out; |
444 | } | 440 | } |
445 | mutex_unlock(&dev->device_lock); | 441 | mutex_unlock(&dev->device_lock); |
446 | return length; | 442 | return length; |
447 | } | 443 | } |
448 | 444 | ||
449 | write_cb->fop_type = MEI_FOP_WRITE; | 445 | rets = mei_cl_write(cl, write_cb, false); |
450 | |||
451 | dev_dbg(&dev->pdev->dev, "host client = %d, ME client = %d\n", | ||
452 | cl->host_client_id, cl->me_client_id); | ||
453 | rets = mei_cl_flow_ctrl_creds(cl); | ||
454 | if (rets < 0) | ||
455 | goto err; | ||
456 | |||
457 | if (rets == 0 || !dev->hbuf_is_ready) { | ||
458 | write_cb->buf_idx = 0; | ||
459 | mei_hdr.msg_complete = 0; | ||
460 | cl->writing_state = MEI_WRITING; | ||
461 | goto out; | ||
462 | } | ||
463 | |||
464 | dev->hbuf_is_ready = false; | ||
465 | if (length > mei_hbuf_max_len(dev)) { | ||
466 | mei_hdr.length = mei_hbuf_max_len(dev); | ||
467 | mei_hdr.msg_complete = 0; | ||
468 | } else { | ||
469 | mei_hdr.length = length; | ||
470 | mei_hdr.msg_complete = 1; | ||
471 | } | ||
472 | mei_hdr.host_addr = cl->host_client_id; | ||
473 | mei_hdr.me_addr = cl->me_client_id; | ||
474 | mei_hdr.reserved = 0; | ||
475 | |||
476 | dev_dbg(&dev->pdev->dev, "write " MEI_HDR_FMT "\n", | ||
477 | MEI_HDR_PRM(&mei_hdr)); | ||
478 | if (mei_write_message(dev, &mei_hdr, write_cb->request_buffer.data)) { | ||
479 | rets = -ENODEV; | ||
480 | goto err; | ||
481 | } | ||
482 | cl->writing_state = MEI_WRITING; | ||
483 | write_cb->buf_idx = mei_hdr.length; | ||
484 | |||
485 | out: | 446 | out: |
486 | if (mei_hdr.msg_complete) { | ||
487 | if (mei_cl_flow_ctrl_reduce(cl)) { | ||
488 | rets = -ENODEV; | ||
489 | goto err; | ||
490 | } | ||
491 | list_add_tail(&write_cb->list, &dev->write_waiting_list.list); | ||
492 | } else { | ||
493 | list_add_tail(&write_cb->list, &dev->write_list.list); | ||
494 | } | ||
495 | |||
496 | mutex_unlock(&dev->device_lock); | 447 | mutex_unlock(&dev->device_lock); |
497 | return length; | 448 | if (rets < 0) |
498 | 449 | mei_io_cb_free(write_cb); | |
499 | err: | ||
500 | mutex_unlock(&dev->device_lock); | ||
501 | mei_io_cb_free(write_cb); | ||
502 | return rets; | 450 | return rets; |
503 | } | 451 | } |
504 | 452 | ||
@@ -753,17 +701,44 @@ static struct miscdevice mei_misc_device = { | |||
753 | .minor = MISC_DYNAMIC_MINOR, | 701 | .minor = MISC_DYNAMIC_MINOR, |
754 | }; | 702 | }; |
755 | 703 | ||
756 | int mei_register(struct device *dev) | 704 | |
705 | int mei_register(struct mei_device *dev) | ||
757 | { | 706 | { |
758 | mei_misc_device.parent = dev; | 707 | int ret; |
759 | return misc_register(&mei_misc_device); | 708 | mei_misc_device.parent = &dev->pdev->dev; |
709 | ret = misc_register(&mei_misc_device); | ||
710 | if (ret) | ||
711 | return ret; | ||
712 | |||
713 | if (mei_dbgfs_register(dev, mei_misc_device.name)) | ||
714 | dev_err(&dev->pdev->dev, "cannot register debugfs\n"); | ||
715 | |||
716 | return 0; | ||
760 | } | 717 | } |
718 | EXPORT_SYMBOL_GPL(mei_register); | ||
761 | 719 | ||
762 | void mei_deregister(void) | 720 | void mei_deregister(struct mei_device *dev) |
763 | { | 721 | { |
722 | mei_dbgfs_deregister(dev); | ||
764 | misc_deregister(&mei_misc_device); | 723 | misc_deregister(&mei_misc_device); |
765 | mei_misc_device.parent = NULL; | 724 | mei_misc_device.parent = NULL; |
766 | } | 725 | } |
726 | EXPORT_SYMBOL_GPL(mei_deregister); | ||
727 | |||
728 | static int __init mei_init(void) | ||
729 | { | ||
730 | return mei_cl_bus_init(); | ||
731 | } | ||
732 | |||
733 | static void __exit mei_exit(void) | ||
734 | { | ||
735 | mei_cl_bus_exit(); | ||
736 | } | ||
737 | |||
738 | module_init(mei_init); | ||
739 | module_exit(mei_exit); | ||
767 | 740 | ||
741 | MODULE_AUTHOR("Intel Corporation"); | ||
742 | MODULE_DESCRIPTION("Intel(R) Management Engine Interface"); | ||
768 | MODULE_LICENSE("GPL v2"); | 743 | MODULE_LICENSE("GPL v2"); |
769 | 744 | ||
diff --git a/drivers/misc/mei/mei_dev.h b/drivers/misc/mei/mei_dev.h index 97873812e33b..4de5140e7379 100644 --- a/drivers/misc/mei/mei_dev.h +++ b/drivers/misc/mei/mei_dev.h | |||
@@ -21,9 +21,11 @@ | |||
21 | #include <linux/watchdog.h> | 21 | #include <linux/watchdog.h> |
22 | #include <linux/poll.h> | 22 | #include <linux/poll.h> |
23 | #include <linux/mei.h> | 23 | #include <linux/mei.h> |
24 | #include <linux/mei_cl_bus.h> | ||
24 | 25 | ||
25 | #include "hw.h" | 26 | #include "hw.h" |
26 | #include "hw-me-regs.h" | 27 | #include "hw-me-regs.h" |
28 | #include "hbm.h" | ||
27 | 29 | ||
28 | /* | 30 | /* |
29 | * watch dog definition | 31 | * watch dog definition |
@@ -95,22 +97,14 @@ enum mei_dev_state { | |||
95 | MEI_DEV_INITIALIZING = 0, | 97 | MEI_DEV_INITIALIZING = 0, |
96 | MEI_DEV_INIT_CLIENTS, | 98 | MEI_DEV_INIT_CLIENTS, |
97 | MEI_DEV_ENABLED, | 99 | MEI_DEV_ENABLED, |
98 | MEI_DEV_RESETING, | 100 | MEI_DEV_RESETTING, |
99 | MEI_DEV_DISABLED, | 101 | MEI_DEV_DISABLED, |
100 | MEI_DEV_RECOVERING_FROM_RESET, | ||
101 | MEI_DEV_POWER_DOWN, | 102 | MEI_DEV_POWER_DOWN, |
102 | MEI_DEV_POWER_UP | 103 | MEI_DEV_POWER_UP |
103 | }; | 104 | }; |
104 | 105 | ||
105 | const char *mei_dev_state_str(int state); | 106 | const char *mei_dev_state_str(int state); |
106 | 107 | ||
107 | /* init clients states*/ | ||
108 | enum mei_init_clients_states { | ||
109 | MEI_START_MESSAGE = 0, | ||
110 | MEI_ENUM_CLIENTS_MESSAGE, | ||
111 | MEI_CLIENT_PROPERTIES_MESSAGE | ||
112 | }; | ||
113 | |||
114 | enum iamthif_states { | 108 | enum iamthif_states { |
115 | MEI_IAMTHIF_IDLE, | 109 | MEI_IAMTHIF_IDLE, |
116 | MEI_IAMTHIF_WRITING, | 110 | MEI_IAMTHIF_WRITING, |
@@ -153,7 +147,7 @@ enum mei_cb_file_ops { | |||
153 | /* | 147 | /* |
154 | * Intel MEI message data struct | 148 | * Intel MEI message data struct |
155 | */ | 149 | */ |
156 | struct mei_message_data { | 150 | struct mei_msg_data { |
157 | u32 size; | 151 | u32 size; |
158 | unsigned char *data; | 152 | unsigned char *data; |
159 | }; | 153 | }; |
@@ -184,8 +178,8 @@ struct mei_cl_cb { | |||
184 | struct list_head list; | 178 | struct list_head list; |
185 | struct mei_cl *cl; | 179 | struct mei_cl *cl; |
186 | enum mei_cb_file_ops fop_type; | 180 | enum mei_cb_file_ops fop_type; |
187 | struct mei_message_data request_buffer; | 181 | struct mei_msg_data request_buffer; |
188 | struct mei_message_data response_buffer; | 182 | struct mei_msg_data response_buffer; |
189 | unsigned long buf_idx; | 183 | unsigned long buf_idx; |
190 | unsigned long read_time; | 184 | unsigned long read_time; |
191 | struct file *file_object; | 185 | struct file *file_object; |
@@ -209,15 +203,20 @@ struct mei_cl { | |||
209 | enum mei_file_transaction_states writing_state; | 203 | enum mei_file_transaction_states writing_state; |
210 | int sm_state; | 204 | int sm_state; |
211 | struct mei_cl_cb *read_cb; | 205 | struct mei_cl_cb *read_cb; |
206 | |||
207 | /* MEI CL bus data */ | ||
208 | struct mei_cl_device *device; | ||
209 | struct list_head device_link; | ||
210 | uuid_le device_uuid; | ||
212 | }; | 211 | }; |
213 | 212 | ||
214 | /** struct mei_hw_ops | 213 | /** struct mei_hw_ops |
215 | * | 214 | * |
216 | * @host_set_ready - notify FW that host side is ready | ||
217 | * @host_is_ready - query for host readiness | 215 | * @host_is_ready - query for host readiness |
218 | 216 | ||
219 | * @hw_is_ready - query if hw is ready | 217 | * @hw_is_ready - query if hw is ready |
220 | * @hw_reset - reset hw | 218 | * @hw_reset - reset hw |
219 | * @hw_start - start hw after reset | ||
221 | * @hw_config - configure hw | 220 | * @hw_config - configure hw |
222 | 221 | ||
223 | * @intr_clear - clear pending interrupts | 222 | * @intr_clear - clear pending interrupts |
@@ -237,11 +236,11 @@ struct mei_cl { | |||
237 | */ | 236 | */ |
238 | struct mei_hw_ops { | 237 | struct mei_hw_ops { |
239 | 238 | ||
240 | void (*host_set_ready) (struct mei_device *dev); | ||
241 | bool (*host_is_ready) (struct mei_device *dev); | 239 | bool (*host_is_ready) (struct mei_device *dev); |
242 | 240 | ||
243 | bool (*hw_is_ready) (struct mei_device *dev); | 241 | bool (*hw_is_ready) (struct mei_device *dev); |
244 | void (*hw_reset) (struct mei_device *dev, bool enable); | 242 | void (*hw_reset) (struct mei_device *dev, bool enable); |
243 | int (*hw_start) (struct mei_device *dev); | ||
245 | void (*hw_config) (struct mei_device *dev); | 244 | void (*hw_config) (struct mei_device *dev); |
246 | 245 | ||
247 | void (*intr_clear) (struct mei_device *dev); | 246 | void (*intr_clear) (struct mei_device *dev); |
@@ -263,9 +262,77 @@ struct mei_hw_ops { | |||
263 | unsigned char *buf, unsigned long len); | 262 | unsigned char *buf, unsigned long len); |
264 | }; | 263 | }; |
265 | 264 | ||
265 | /* MEI bus API*/ | ||
266 | |||
267 | /** | ||
268 | * struct mei_cl_ops - MEI CL device ops | ||
269 | * This structure allows ME host clients to implement technology | ||
270 | * specific operations. | ||
271 | * | ||
272 | * @enable: Enable an MEI CL device. Some devices require specific | ||
273 | * HECI commands to initialize completely. | ||
274 | * @disable: Disable an MEI CL device. | ||
275 | * @send: Tx hook for the device. This allows ME host clients to trap | ||
276 | * the device driver buffers before actually physically | ||
277 | * pushing it to the ME. | ||
278 | * @recv: Rx hook for the device. This allows ME host clients to trap the | ||
279 | * ME buffers before forwarding them to the device driver. | ||
280 | */ | ||
281 | struct mei_cl_ops { | ||
282 | int (*enable)(struct mei_cl_device *device); | ||
283 | int (*disable)(struct mei_cl_device *device); | ||
284 | int (*send)(struct mei_cl_device *device, u8 *buf, size_t length); | ||
285 | int (*recv)(struct mei_cl_device *device, u8 *buf, size_t length); | ||
286 | }; | ||
287 | |||
288 | struct mei_cl_device *mei_cl_add_device(struct mei_device *dev, | ||
289 | uuid_le uuid, char *name, | ||
290 | struct mei_cl_ops *ops); | ||
291 | void mei_cl_remove_device(struct mei_cl_device *device); | ||
292 | |||
293 | int __mei_cl_async_send(struct mei_cl *cl, u8 *buf, size_t length); | ||
294 | int __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length); | ||
295 | int __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length); | ||
296 | void mei_cl_bus_rx_event(struct mei_cl *cl); | ||
297 | int mei_cl_bus_init(void); | ||
298 | void mei_cl_bus_exit(void); | ||
299 | |||
300 | |||
301 | /** | ||
302 | * struct mei_cl_device - MEI device handle | ||
303 | * An mei_cl_device pointer is returned from mei_add_device() | ||
304 | * and links MEI bus clients to their actual ME host client pointer. | ||
305 | * Drivers for MEI devices will get an mei_cl_device pointer | ||
306 | * when being probed and shall use it for doing ME bus I/O. | ||
307 | * | ||
308 | * @dev: linux driver model device pointer | ||
309 | * @uuid: me client uuid | ||
310 | * @cl: mei client | ||
311 | * @ops: ME transport ops | ||
312 | * @event_cb: Drivers register this callback to get asynchronous ME | ||
313 | * events (e.g. Rx buffer pending) notifications. | ||
314 | * @events: Events bitmask sent to the driver. | ||
315 | * @priv_data: client private data | ||
316 | */ | ||
317 | struct mei_cl_device { | ||
318 | struct device dev; | ||
319 | |||
320 | struct mei_cl *cl; | ||
321 | |||
322 | const struct mei_cl_ops *ops; | ||
323 | |||
324 | struct work_struct event_work; | ||
325 | mei_cl_event_cb_t event_cb; | ||
326 | void *event_context; | ||
327 | unsigned long events; | ||
328 | |||
329 | void *priv_data; | ||
330 | }; | ||
331 | |||
266 | /** | 332 | /** |
267 | * struct mei_device - MEI private device struct | 333 | * struct mei_device - MEI private device struct |
268 | 334 | ||
335 | * @hbm_state - state of host bus message protocol | ||
269 | * @mem_addr - mem mapped base register address | 336 | * @mem_addr - mem mapped base register address |
270 | 337 | ||
271 | * @hbuf_depth - depth of hardware host/write buffer is slots | 338 | * @hbuf_depth - depth of hardware host/write buffer is slots |
@@ -296,11 +363,12 @@ struct mei_device { | |||
296 | */ | 363 | */ |
297 | struct mutex device_lock; /* device lock */ | 364 | struct mutex device_lock; /* device lock */ |
298 | struct delayed_work timer_work; /* MEI timer delayed work (timeouts) */ | 365 | struct delayed_work timer_work; /* MEI timer delayed work (timeouts) */ |
299 | bool recvd_msg; | ||
300 | 366 | ||
367 | bool recvd_hw_ready; | ||
301 | /* | 368 | /* |
302 | * waiting queue for receive message from FW | 369 | * waiting queue for receive message from FW |
303 | */ | 370 | */ |
371 | wait_queue_head_t wait_hw_ready; | ||
304 | wait_queue_head_t wait_recvd_msg; | 372 | wait_queue_head_t wait_recvd_msg; |
305 | wait_queue_head_t wait_stop_wd; | 373 | wait_queue_head_t wait_stop_wd; |
306 | 374 | ||
@@ -308,7 +376,7 @@ struct mei_device { | |||
308 | * mei device states | 376 | * mei device states |
309 | */ | 377 | */ |
310 | enum mei_dev_state dev_state; | 378 | enum mei_dev_state dev_state; |
311 | enum mei_init_clients_states init_clients_state; | 379 | enum mei_hbm_state hbm_state; |
312 | u16 init_clients_timer; | 380 | u16 init_clients_timer; |
313 | 381 | ||
314 | unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE]; /* control messages */ | 382 | unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE]; /* control messages */ |
@@ -365,6 +433,14 @@ struct mei_device { | |||
365 | 433 | ||
366 | struct work_struct init_work; | 434 | struct work_struct init_work; |
367 | 435 | ||
436 | /* List of bus devices */ | ||
437 | struct list_head device_list; | ||
438 | |||
439 | #if IS_ENABLED(CONFIG_DEBUG_FS) | ||
440 | struct dentry *dbgfs_dir; | ||
441 | #endif /* CONFIG_DEBUG_FS */ | ||
442 | |||
443 | |||
368 | const struct mei_hw_ops *ops; | 444 | const struct mei_hw_ops *ops; |
369 | char hw[0] __aligned(sizeof(void *)); | 445 | char hw[0] __aligned(sizeof(void *)); |
370 | }; | 446 | }; |
@@ -374,13 +450,23 @@ static inline unsigned long mei_secs_to_jiffies(unsigned long sec) | |||
374 | return msecs_to_jiffies(sec * MSEC_PER_SEC); | 450 | return msecs_to_jiffies(sec * MSEC_PER_SEC); |
375 | } | 451 | } |
376 | 452 | ||
453 | /** | ||
454 | * mei_data2slots - get slots - number of (dwords) from a message length | ||
455 | * + size of the mei header | ||
456 | * @length - size of the messages in bytes | ||
457 | * returns - number of slots | ||
458 | */ | ||
459 | static inline u32 mei_data2slots(size_t length) | ||
460 | { | ||
461 | return DIV_ROUND_UP(sizeof(struct mei_msg_hdr) + length, 4); | ||
462 | } | ||
377 | 463 | ||
378 | /* | 464 | /* |
379 | * mei init function prototypes | 465 | * mei init function prototypes |
380 | */ | 466 | */ |
381 | void mei_device_init(struct mei_device *dev); | 467 | void mei_device_init(struct mei_device *dev); |
382 | void mei_reset(struct mei_device *dev, int interrupts); | 468 | void mei_reset(struct mei_device *dev, int interrupts); |
383 | int mei_hw_init(struct mei_device *dev); | 469 | int mei_start(struct mei_device *dev); |
384 | void mei_stop(struct mei_device *dev); | 470 | void mei_stop(struct mei_device *dev); |
385 | 471 | ||
386 | /* | 472 | /* |
@@ -392,8 +478,7 @@ int mei_irq_read_handler(struct mei_device *dev, | |||
392 | struct mei_cl_cb *cmpl_list, s32 *slots); | 478 | struct mei_cl_cb *cmpl_list, s32 *slots); |
393 | 479 | ||
394 | int mei_irq_write_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list); | 480 | int mei_irq_write_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list); |
395 | 481 | void mei_irq_compl_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list); | |
396 | void mei_irq_complete_handler(struct mei_cl *cl, struct mei_cl_cb *cb_pos); | ||
397 | 482 | ||
398 | /* | 483 | /* |
399 | * AMTHIF - AMT Host Interface Functions | 484 | * AMTHIF - AMT Host Interface Functions |
@@ -417,6 +502,25 @@ struct mei_cl_cb *mei_amthif_find_read_list_entry(struct mei_device *dev, | |||
417 | 502 | ||
418 | void mei_amthif_run_next_cmd(struct mei_device *dev); | 503 | void mei_amthif_run_next_cmd(struct mei_device *dev); |
419 | 504 | ||
505 | int mei_amthif_irq_write_complete(struct mei_device *dev, s32 *slots, | ||
506 | struct mei_cl_cb *cb, struct mei_cl_cb *cmpl_list); | ||
507 | |||
508 | void mei_amthif_complete(struct mei_device *dev, struct mei_cl_cb *cb); | ||
509 | int mei_amthif_irq_read_msg(struct mei_device *dev, | ||
510 | struct mei_msg_hdr *mei_hdr, | ||
511 | struct mei_cl_cb *complete_list); | ||
512 | int mei_amthif_irq_read(struct mei_device *dev, s32 *slots); | ||
513 | |||
514 | /* | ||
515 | * NFC functions | ||
516 | */ | ||
517 | int mei_nfc_host_init(struct mei_device *dev); | ||
518 | void mei_nfc_host_exit(void); | ||
519 | |||
520 | /* | ||
521 | * NFC Client UUID | ||
522 | */ | ||
523 | extern const uuid_le mei_nfc_guid; | ||
420 | 524 | ||
421 | int mei_amthif_irq_write_complete(struct mei_device *dev, s32 *slots, | 525 | int mei_amthif_irq_write_complete(struct mei_device *dev, s32 *slots, |
422 | struct mei_cl_cb *cb, struct mei_cl_cb *cmpl_list); | 526 | struct mei_cl_cb *cb, struct mei_cl_cb *cmpl_list); |
@@ -455,6 +559,11 @@ static inline void mei_hw_reset(struct mei_device *dev, bool enable) | |||
455 | dev->ops->hw_reset(dev, enable); | 559 | dev->ops->hw_reset(dev, enable); |
456 | } | 560 | } |
457 | 561 | ||
562 | static inline void mei_hw_start(struct mei_device *dev) | ||
563 | { | ||
564 | dev->ops->hw_start(dev); | ||
565 | } | ||
566 | |||
458 | static inline void mei_clear_interrupts(struct mei_device *dev) | 567 | static inline void mei_clear_interrupts(struct mei_device *dev) |
459 | { | 568 | { |
460 | dev->ops->intr_clear(dev); | 569 | dev->ops->intr_clear(dev); |
@@ -470,10 +579,6 @@ static inline void mei_disable_interrupts(struct mei_device *dev) | |||
470 | dev->ops->intr_disable(dev); | 579 | dev->ops->intr_disable(dev); |
471 | } | 580 | } |
472 | 581 | ||
473 | static inline void mei_host_set_ready(struct mei_device *dev) | ||
474 | { | ||
475 | dev->ops->host_set_ready(dev); | ||
476 | } | ||
477 | static inline bool mei_host_is_ready(struct mei_device *dev) | 582 | static inline bool mei_host_is_ready(struct mei_device *dev) |
478 | { | 583 | { |
479 | return dev->ops->host_is_ready(dev); | 584 | return dev->ops->host_is_ready(dev); |
@@ -521,8 +626,19 @@ static inline int mei_count_full_read_slots(struct mei_device *dev) | |||
521 | return dev->ops->rdbuf_full_slots(dev); | 626 | return dev->ops->rdbuf_full_slots(dev); |
522 | } | 627 | } |
523 | 628 | ||
524 | int mei_register(struct device *dev); | 629 | #if IS_ENABLED(CONFIG_DEBUG_FS) |
525 | void mei_deregister(void); | 630 | int mei_dbgfs_register(struct mei_device *dev, const char *name); |
631 | void mei_dbgfs_deregister(struct mei_device *dev); | ||
632 | #else | ||
633 | static inline int mei_dbgfs_register(struct mei_device *dev, const char *name) | ||
634 | { | ||
635 | return 0; | ||
636 | } | ||
637 | static inline void mei_dbgfs_deregister(struct mei_device *dev) {} | ||
638 | #endif /* CONFIG_DEBUG_FS */ | ||
639 | |||
640 | int mei_register(struct mei_device *dev); | ||
641 | void mei_deregister(struct mei_device *dev); | ||
526 | 642 | ||
527 | #define MEI_HDR_FMT "hdr:host=%02d me=%02d len=%d comp=%1d" | 643 | #define MEI_HDR_FMT "hdr:host=%02d me=%02d len=%d comp=%1d" |
528 | #define MEI_HDR_PRM(hdr) \ | 644 | #define MEI_HDR_PRM(hdr) \ |
diff --git a/drivers/misc/mei/nfc.c b/drivers/misc/mei/nfc.c new file mode 100644 index 000000000000..3adf8a70f26e --- /dev/null +++ b/drivers/misc/mei/nfc.c | |||
@@ -0,0 +1,554 @@ | |||
1 | /* | ||
2 | * | ||
3 | * Intel Management Engine Interface (Intel MEI) Linux driver | ||
4 | * Copyright (c) 2003-2013, Intel Corporation. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms and conditions of the GNU General Public License, | ||
8 | * version 2, as published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | * more details. | ||
14 | * | ||
15 | */ | ||
16 | |||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/sched.h> | ||
19 | #include <linux/module.h> | ||
20 | #include <linux/moduleparam.h> | ||
21 | #include <linux/device.h> | ||
22 | #include <linux/pci.h> | ||
23 | #include <linux/mei_cl_bus.h> | ||
24 | |||
25 | #include "mei_dev.h" | ||
26 | #include "client.h" | ||
27 | |||
28 | struct mei_nfc_cmd { | ||
29 | u8 command; | ||
30 | u8 status; | ||
31 | u16 req_id; | ||
32 | u32 reserved; | ||
33 | u16 data_size; | ||
34 | u8 sub_command; | ||
35 | u8 data[]; | ||
36 | } __packed; | ||
37 | |||
38 | struct mei_nfc_reply { | ||
39 | u8 command; | ||
40 | u8 status; | ||
41 | u16 req_id; | ||
42 | u32 reserved; | ||
43 | u16 data_size; | ||
44 | u8 sub_command; | ||
45 | u8 reply_status; | ||
46 | u8 data[]; | ||
47 | } __packed; | ||
48 | |||
49 | struct mei_nfc_if_version { | ||
50 | u8 radio_version_sw[3]; | ||
51 | u8 reserved[3]; | ||
52 | u8 radio_version_hw[3]; | ||
53 | u8 i2c_addr; | ||
54 | u8 fw_ivn; | ||
55 | u8 vendor_id; | ||
56 | u8 radio_type; | ||
57 | } __packed; | ||
58 | |||
59 | struct mei_nfc_connect { | ||
60 | u8 fw_ivn; | ||
61 | u8 vendor_id; | ||
62 | } __packed; | ||
63 | |||
64 | struct mei_nfc_connect_resp { | ||
65 | u8 fw_ivn; | ||
66 | u8 vendor_id; | ||
67 | u16 me_major; | ||
68 | u16 me_minor; | ||
69 | u16 me_hotfix; | ||
70 | u16 me_build; | ||
71 | } __packed; | ||
72 | |||
73 | struct mei_nfc_hci_hdr { | ||
74 | u8 cmd; | ||
75 | u8 status; | ||
76 | u16 req_id; | ||
77 | u32 reserved; | ||
78 | u16 data_size; | ||
79 | } __packed; | ||
80 | |||
81 | #define MEI_NFC_CMD_MAINTENANCE 0x00 | ||
82 | #define MEI_NFC_CMD_HCI_SEND 0x01 | ||
83 | #define MEI_NFC_CMD_HCI_RECV 0x02 | ||
84 | |||
85 | #define MEI_NFC_SUBCMD_CONNECT 0x00 | ||
86 | #define MEI_NFC_SUBCMD_IF_VERSION 0x01 | ||
87 | |||
88 | #define MEI_NFC_HEADER_SIZE 10 | ||
89 | |||
90 | /** mei_nfc_dev - NFC mei device | ||
91 | * | ||
92 | * @cl: NFC host client | ||
93 | * @cl_info: NFC info host client | ||
94 | * @init_work: perform connection to the info client | ||
95 | * @fw_ivn: NFC Intervace Version Number | ||
96 | * @vendor_id: NFC manufacturer ID | ||
97 | * @radio_type: NFC radio type | ||
98 | */ | ||
99 | struct mei_nfc_dev { | ||
100 | struct mei_cl *cl; | ||
101 | struct mei_cl *cl_info; | ||
102 | struct work_struct init_work; | ||
103 | wait_queue_head_t send_wq; | ||
104 | u8 fw_ivn; | ||
105 | u8 vendor_id; | ||
106 | u8 radio_type; | ||
107 | char *bus_name; | ||
108 | |||
109 | u16 req_id; | ||
110 | u16 recv_req_id; | ||
111 | }; | ||
112 | |||
113 | static struct mei_nfc_dev nfc_dev; | ||
114 | |||
115 | /* UUIDs for NFC F/W clients */ | ||
116 | const uuid_le mei_nfc_guid = UUID_LE(0x0bb17a78, 0x2a8e, 0x4c50, | ||
117 | 0x94, 0xd4, 0x50, 0x26, | ||
118 | 0x67, 0x23, 0x77, 0x5c); | ||
119 | |||
120 | static const uuid_le mei_nfc_info_guid = UUID_LE(0xd2de1625, 0x382d, 0x417d, | ||
121 | 0x48, 0xa4, 0xef, 0xab, | ||
122 | 0xba, 0x8a, 0x12, 0x06); | ||
123 | |||
124 | /* Vendors */ | ||
125 | #define MEI_NFC_VENDOR_INSIDE 0x00 | ||
126 | #define MEI_NFC_VENDOR_NXP 0x01 | ||
127 | |||
128 | /* Radio types */ | ||
129 | #define MEI_NFC_VENDOR_INSIDE_UREAD 0x00 | ||
130 | #define MEI_NFC_VENDOR_NXP_PN544 0x01 | ||
131 | |||
132 | static void mei_nfc_free(struct mei_nfc_dev *ndev) | ||
133 | { | ||
134 | if (ndev->cl) { | ||
135 | list_del(&ndev->cl->device_link); | ||
136 | mei_cl_unlink(ndev->cl); | ||
137 | kfree(ndev->cl); | ||
138 | } | ||
139 | |||
140 | if (ndev->cl_info) { | ||
141 | list_del(&ndev->cl_info->device_link); | ||
142 | mei_cl_unlink(ndev->cl_info); | ||
143 | kfree(ndev->cl_info); | ||
144 | } | ||
145 | } | ||
146 | |||
147 | static int mei_nfc_build_bus_name(struct mei_nfc_dev *ndev) | ||
148 | { | ||
149 | struct mei_device *dev; | ||
150 | |||
151 | if (!ndev->cl) | ||
152 | return -ENODEV; | ||
153 | |||
154 | dev = ndev->cl->dev; | ||
155 | |||
156 | switch (ndev->vendor_id) { | ||
157 | case MEI_NFC_VENDOR_INSIDE: | ||
158 | switch (ndev->radio_type) { | ||
159 | case MEI_NFC_VENDOR_INSIDE_UREAD: | ||
160 | ndev->bus_name = "microread"; | ||
161 | return 0; | ||
162 | |||
163 | default: | ||
164 | dev_err(&dev->pdev->dev, "Unknow radio type 0x%x\n", | ||
165 | ndev->radio_type); | ||
166 | |||
167 | return -EINVAL; | ||
168 | } | ||
169 | |||
170 | case MEI_NFC_VENDOR_NXP: | ||
171 | switch (ndev->radio_type) { | ||
172 | case MEI_NFC_VENDOR_NXP_PN544: | ||
173 | ndev->bus_name = "pn544"; | ||
174 | return 0; | ||
175 | default: | ||
176 | dev_err(&dev->pdev->dev, "Unknow radio type 0x%x\n", | ||
177 | ndev->radio_type); | ||
178 | |||
179 | return -EINVAL; | ||
180 | } | ||
181 | |||
182 | default: | ||
183 | dev_err(&dev->pdev->dev, "Unknow vendor ID 0x%x\n", | ||
184 | ndev->vendor_id); | ||
185 | |||
186 | return -EINVAL; | ||
187 | } | ||
188 | |||
189 | return 0; | ||
190 | } | ||
191 | |||
192 | static int mei_nfc_connect(struct mei_nfc_dev *ndev) | ||
193 | { | ||
194 | struct mei_device *dev; | ||
195 | struct mei_cl *cl; | ||
196 | struct mei_nfc_cmd *cmd, *reply; | ||
197 | struct mei_nfc_connect *connect; | ||
198 | struct mei_nfc_connect_resp *connect_resp; | ||
199 | size_t connect_length, connect_resp_length; | ||
200 | int bytes_recv, ret; | ||
201 | |||
202 | cl = ndev->cl; | ||
203 | dev = cl->dev; | ||
204 | |||
205 | connect_length = sizeof(struct mei_nfc_cmd) + | ||
206 | sizeof(struct mei_nfc_connect); | ||
207 | |||
208 | connect_resp_length = sizeof(struct mei_nfc_cmd) + | ||
209 | sizeof(struct mei_nfc_connect_resp); | ||
210 | |||
211 | cmd = kzalloc(connect_length, GFP_KERNEL); | ||
212 | if (!cmd) | ||
213 | return -ENOMEM; | ||
214 | connect = (struct mei_nfc_connect *)cmd->data; | ||
215 | |||
216 | reply = kzalloc(connect_resp_length, GFP_KERNEL); | ||
217 | if (!reply) { | ||
218 | kfree(cmd); | ||
219 | return -ENOMEM; | ||
220 | } | ||
221 | |||
222 | connect_resp = (struct mei_nfc_connect_resp *)reply->data; | ||
223 | |||
224 | cmd->command = MEI_NFC_CMD_MAINTENANCE; | ||
225 | cmd->data_size = 3; | ||
226 | cmd->sub_command = MEI_NFC_SUBCMD_CONNECT; | ||
227 | connect->fw_ivn = ndev->fw_ivn; | ||
228 | connect->vendor_id = ndev->vendor_id; | ||
229 | |||
230 | ret = __mei_cl_send(cl, (u8 *)cmd, connect_length); | ||
231 | if (ret < 0) { | ||
232 | dev_err(&dev->pdev->dev, "Could not send connect cmd\n"); | ||
233 | goto err; | ||
234 | } | ||
235 | |||
236 | bytes_recv = __mei_cl_recv(cl, (u8 *)reply, connect_resp_length); | ||
237 | if (bytes_recv < 0) { | ||
238 | dev_err(&dev->pdev->dev, "Could not read connect response\n"); | ||
239 | ret = bytes_recv; | ||
240 | goto err; | ||
241 | } | ||
242 | |||
243 | dev_info(&dev->pdev->dev, "IVN 0x%x Vendor ID 0x%x\n", | ||
244 | connect_resp->fw_ivn, connect_resp->vendor_id); | ||
245 | |||
246 | dev_info(&dev->pdev->dev, "ME FW %d.%d.%d.%d\n", | ||
247 | connect_resp->me_major, connect_resp->me_minor, | ||
248 | connect_resp->me_hotfix, connect_resp->me_build); | ||
249 | |||
250 | ret = 0; | ||
251 | |||
252 | err: | ||
253 | kfree(reply); | ||
254 | kfree(cmd); | ||
255 | |||
256 | return ret; | ||
257 | } | ||
258 | |||
259 | static int mei_nfc_if_version(struct mei_nfc_dev *ndev) | ||
260 | { | ||
261 | struct mei_device *dev; | ||
262 | struct mei_cl *cl; | ||
263 | |||
264 | struct mei_nfc_cmd cmd; | ||
265 | struct mei_nfc_reply *reply = NULL; | ||
266 | struct mei_nfc_if_version *version; | ||
267 | size_t if_version_length; | ||
268 | int bytes_recv, ret; | ||
269 | |||
270 | cl = ndev->cl_info; | ||
271 | dev = cl->dev; | ||
272 | |||
273 | memset(&cmd, 0, sizeof(struct mei_nfc_cmd)); | ||
274 | cmd.command = MEI_NFC_CMD_MAINTENANCE; | ||
275 | cmd.data_size = 1; | ||
276 | cmd.sub_command = MEI_NFC_SUBCMD_IF_VERSION; | ||
277 | |||
278 | ret = __mei_cl_send(cl, (u8 *)&cmd, sizeof(struct mei_nfc_cmd)); | ||
279 | if (ret < 0) { | ||
280 | dev_err(&dev->pdev->dev, "Could not send IF version cmd\n"); | ||
281 | return ret; | ||
282 | } | ||
283 | |||
284 | /* to be sure on the stack we alloc memory */ | ||
285 | if_version_length = sizeof(struct mei_nfc_reply) + | ||
286 | sizeof(struct mei_nfc_if_version); | ||
287 | |||
288 | reply = kzalloc(if_version_length, GFP_KERNEL); | ||
289 | if (!reply) | ||
290 | return -ENOMEM; | ||
291 | |||
292 | bytes_recv = __mei_cl_recv(cl, (u8 *)reply, if_version_length); | ||
293 | if (bytes_recv < 0 || bytes_recv < sizeof(struct mei_nfc_reply)) { | ||
294 | dev_err(&dev->pdev->dev, "Could not read IF version\n"); | ||
295 | ret = -EIO; | ||
296 | goto err; | ||
297 | } | ||
298 | |||
299 | version = (struct mei_nfc_if_version *)reply->data; | ||
300 | |||
301 | ndev->fw_ivn = version->fw_ivn; | ||
302 | ndev->vendor_id = version->vendor_id; | ||
303 | ndev->radio_type = version->radio_type; | ||
304 | |||
305 | err: | ||
306 | kfree(reply); | ||
307 | return ret; | ||
308 | } | ||
309 | |||
310 | static int mei_nfc_enable(struct mei_cl_device *cldev) | ||
311 | { | ||
312 | struct mei_device *dev; | ||
313 | struct mei_nfc_dev *ndev = &nfc_dev; | ||
314 | int ret; | ||
315 | |||
316 | dev = ndev->cl->dev; | ||
317 | |||
318 | ret = mei_nfc_connect(ndev); | ||
319 | if (ret < 0) { | ||
320 | dev_err(&dev->pdev->dev, "Could not connect to NFC"); | ||
321 | return ret; | ||
322 | } | ||
323 | |||
324 | return 0; | ||
325 | } | ||
326 | |||
327 | static int mei_nfc_disable(struct mei_cl_device *cldev) | ||
328 | { | ||
329 | return 0; | ||
330 | } | ||
331 | |||
332 | static int mei_nfc_send(struct mei_cl_device *cldev, u8 *buf, size_t length) | ||
333 | { | ||
334 | struct mei_device *dev; | ||
335 | struct mei_nfc_dev *ndev; | ||
336 | struct mei_nfc_hci_hdr *hdr; | ||
337 | u8 *mei_buf; | ||
338 | int err; | ||
339 | |||
340 | ndev = (struct mei_nfc_dev *) cldev->priv_data; | ||
341 | dev = ndev->cl->dev; | ||
342 | |||
343 | mei_buf = kzalloc(length + MEI_NFC_HEADER_SIZE, GFP_KERNEL); | ||
344 | if (!mei_buf) | ||
345 | return -ENOMEM; | ||
346 | |||
347 | hdr = (struct mei_nfc_hci_hdr *) mei_buf; | ||
348 | hdr->cmd = MEI_NFC_CMD_HCI_SEND; | ||
349 | hdr->status = 0; | ||
350 | hdr->req_id = ndev->req_id; | ||
351 | hdr->reserved = 0; | ||
352 | hdr->data_size = length; | ||
353 | |||
354 | memcpy(mei_buf + MEI_NFC_HEADER_SIZE, buf, length); | ||
355 | |||
356 | err = __mei_cl_send(ndev->cl, mei_buf, length + MEI_NFC_HEADER_SIZE); | ||
357 | if (err < 0) | ||
358 | return err; | ||
359 | |||
360 | kfree(mei_buf); | ||
361 | |||
362 | if (!wait_event_interruptible_timeout(ndev->send_wq, | ||
363 | ndev->recv_req_id == ndev->req_id, HZ)) { | ||
364 | dev_err(&dev->pdev->dev, "NFC MEI command timeout\n"); | ||
365 | err = -ETIMEDOUT; | ||
366 | } else { | ||
367 | ndev->req_id++; | ||
368 | } | ||
369 | |||
370 | return err; | ||
371 | } | ||
372 | |||
373 | static int mei_nfc_recv(struct mei_cl_device *cldev, u8 *buf, size_t length) | ||
374 | { | ||
375 | struct mei_nfc_dev *ndev; | ||
376 | struct mei_nfc_hci_hdr *hci_hdr; | ||
377 | int received_length; | ||
378 | |||
379 | ndev = (struct mei_nfc_dev *)cldev->priv_data; | ||
380 | |||
381 | received_length = __mei_cl_recv(ndev->cl, buf, length); | ||
382 | if (received_length < 0) | ||
383 | return received_length; | ||
384 | |||
385 | hci_hdr = (struct mei_nfc_hci_hdr *) buf; | ||
386 | |||
387 | if (hci_hdr->cmd == MEI_NFC_CMD_HCI_SEND) { | ||
388 | ndev->recv_req_id = hci_hdr->req_id; | ||
389 | wake_up(&ndev->send_wq); | ||
390 | |||
391 | return 0; | ||
392 | } | ||
393 | |||
394 | return received_length; | ||
395 | } | ||
396 | |||
397 | static struct mei_cl_ops nfc_ops = { | ||
398 | .enable = mei_nfc_enable, | ||
399 | .disable = mei_nfc_disable, | ||
400 | .send = mei_nfc_send, | ||
401 | .recv = mei_nfc_recv, | ||
402 | }; | ||
403 | |||
404 | static void mei_nfc_init(struct work_struct *work) | ||
405 | { | ||
406 | struct mei_device *dev; | ||
407 | struct mei_cl_device *cldev; | ||
408 | struct mei_nfc_dev *ndev; | ||
409 | struct mei_cl *cl_info; | ||
410 | |||
411 | ndev = container_of(work, struct mei_nfc_dev, init_work); | ||
412 | |||
413 | cl_info = ndev->cl_info; | ||
414 | dev = cl_info->dev; | ||
415 | |||
416 | mutex_lock(&dev->device_lock); | ||
417 | |||
418 | if (mei_cl_connect(cl_info, NULL) < 0) { | ||
419 | mutex_unlock(&dev->device_lock); | ||
420 | dev_err(&dev->pdev->dev, | ||
421 | "Could not connect to the NFC INFO ME client"); | ||
422 | |||
423 | goto err; | ||
424 | } | ||
425 | |||
426 | mutex_unlock(&dev->device_lock); | ||
427 | |||
428 | if (mei_nfc_if_version(ndev) < 0) { | ||
429 | dev_err(&dev->pdev->dev, "Could not get the NFC interfave version"); | ||
430 | |||
431 | goto err; | ||
432 | } | ||
433 | |||
434 | dev_info(&dev->pdev->dev, | ||
435 | "NFC MEI VERSION: IVN 0x%x Vendor ID 0x%x Type 0x%x\n", | ||
436 | ndev->fw_ivn, ndev->vendor_id, ndev->radio_type); | ||
437 | |||
438 | mutex_lock(&dev->device_lock); | ||
439 | |||
440 | if (mei_cl_disconnect(cl_info) < 0) { | ||
441 | mutex_unlock(&dev->device_lock); | ||
442 | dev_err(&dev->pdev->dev, | ||
443 | "Could not disconnect the NFC INFO ME client"); | ||
444 | |||
445 | goto err; | ||
446 | } | ||
447 | |||
448 | mutex_unlock(&dev->device_lock); | ||
449 | |||
450 | if (mei_nfc_build_bus_name(ndev) < 0) { | ||
451 | dev_err(&dev->pdev->dev, | ||
452 | "Could not build the bus ID name\n"); | ||
453 | return; | ||
454 | } | ||
455 | |||
456 | cldev = mei_cl_add_device(dev, mei_nfc_guid, ndev->bus_name, &nfc_ops); | ||
457 | if (!cldev) { | ||
458 | dev_err(&dev->pdev->dev, | ||
459 | "Could not add the NFC device to the MEI bus\n"); | ||
460 | |||
461 | goto err; | ||
462 | } | ||
463 | |||
464 | cldev->priv_data = ndev; | ||
465 | |||
466 | |||
467 | return; | ||
468 | |||
469 | err: | ||
470 | mei_nfc_free(ndev); | ||
471 | |||
472 | return; | ||
473 | } | ||
474 | |||
475 | |||
476 | int mei_nfc_host_init(struct mei_device *dev) | ||
477 | { | ||
478 | struct mei_nfc_dev *ndev = &nfc_dev; | ||
479 | struct mei_cl *cl_info, *cl = NULL; | ||
480 | int i, ret; | ||
481 | |||
482 | /* already initialzed */ | ||
483 | if (ndev->cl_info) | ||
484 | return 0; | ||
485 | |||
486 | cl_info = mei_cl_allocate(dev); | ||
487 | cl = mei_cl_allocate(dev); | ||
488 | |||
489 | if (!cl || !cl_info) { | ||
490 | ret = -ENOMEM; | ||
491 | goto err; | ||
492 | } | ||
493 | |||
494 | /* check for valid client id */ | ||
495 | i = mei_me_cl_by_uuid(dev, &mei_nfc_info_guid); | ||
496 | if (i < 0) { | ||
497 | dev_info(&dev->pdev->dev, "nfc: failed to find the client\n"); | ||
498 | ret = -ENOENT; | ||
499 | goto err; | ||
500 | } | ||
501 | |||
502 | cl_info->me_client_id = dev->me_clients[i].client_id; | ||
503 | |||
504 | ret = mei_cl_link(cl_info, MEI_HOST_CLIENT_ID_ANY); | ||
505 | if (ret) | ||
506 | goto err; | ||
507 | |||
508 | cl_info->device_uuid = mei_nfc_info_guid; | ||
509 | |||
510 | list_add_tail(&cl_info->device_link, &dev->device_list); | ||
511 | |||
512 | /* check for valid client id */ | ||
513 | i = mei_me_cl_by_uuid(dev, &mei_nfc_guid); | ||
514 | if (i < 0) { | ||
515 | dev_info(&dev->pdev->dev, "nfc: failed to find the client\n"); | ||
516 | ret = -ENOENT; | ||
517 | goto err; | ||
518 | } | ||
519 | |||
520 | cl->me_client_id = dev->me_clients[i].client_id; | ||
521 | |||
522 | ret = mei_cl_link(cl, MEI_HOST_CLIENT_ID_ANY); | ||
523 | if (ret) | ||
524 | goto err; | ||
525 | |||
526 | cl->device_uuid = mei_nfc_guid; | ||
527 | |||
528 | list_add_tail(&cl->device_link, &dev->device_list); | ||
529 | |||
530 | ndev->cl_info = cl_info; | ||
531 | ndev->cl = cl; | ||
532 | ndev->req_id = 1; | ||
533 | |||
534 | INIT_WORK(&ndev->init_work, mei_nfc_init); | ||
535 | init_waitqueue_head(&ndev->send_wq); | ||
536 | schedule_work(&ndev->init_work); | ||
537 | |||
538 | return 0; | ||
539 | |||
540 | err: | ||
541 | mei_nfc_free(ndev); | ||
542 | |||
543 | return ret; | ||
544 | } | ||
545 | |||
546 | void mei_nfc_host_exit(void) | ||
547 | { | ||
548 | struct mei_nfc_dev *ndev = &nfc_dev; | ||
549 | |||
550 | if (ndev->cl && ndev->cl->device) | ||
551 | mei_cl_remove_device(ndev->cl->device); | ||
552 | |||
553 | mei_nfc_free(ndev); | ||
554 | } | ||
diff --git a/drivers/misc/mei/pci-me.c b/drivers/misc/mei/pci-me.c index b8b5c9c3ad03..88aec6a90ff4 100644 --- a/drivers/misc/mei/pci-me.c +++ b/drivers/misc/mei/pci-me.c | |||
@@ -47,7 +47,7 @@ | |||
47 | static struct pci_dev *mei_pdev; | 47 | static struct pci_dev *mei_pdev; |
48 | 48 | ||
49 | /* mei_pci_tbl - PCI Device ID Table */ | 49 | /* mei_pci_tbl - PCI Device ID Table */ |
50 | static DEFINE_PCI_DEVICE_TABLE(mei_pci_tbl) = { | 50 | static DEFINE_PCI_DEVICE_TABLE(mei_me_pci_tbl) = { |
51 | {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_82946GZ)}, | 51 | {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_82946GZ)}, |
52 | {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_82G35)}, | 52 | {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_82G35)}, |
53 | {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_82Q965)}, | 53 | {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_82Q965)}, |
@@ -86,7 +86,7 @@ static DEFINE_PCI_DEVICE_TABLE(mei_pci_tbl) = { | |||
86 | {0, } | 86 | {0, } |
87 | }; | 87 | }; |
88 | 88 | ||
89 | MODULE_DEVICE_TABLE(pci, mei_pci_tbl); | 89 | MODULE_DEVICE_TABLE(pci, mei_me_pci_tbl); |
90 | 90 | ||
91 | static DEFINE_MUTEX(mei_mutex); | 91 | static DEFINE_MUTEX(mei_mutex); |
92 | 92 | ||
@@ -97,7 +97,7 @@ static DEFINE_MUTEX(mei_mutex); | |||
97 | * | 97 | * |
98 | * returns true if ME Interface is valid, false otherwise | 98 | * returns true if ME Interface is valid, false otherwise |
99 | */ | 99 | */ |
100 | static bool mei_quirk_probe(struct pci_dev *pdev, | 100 | static bool mei_me_quirk_probe(struct pci_dev *pdev, |
101 | const struct pci_device_id *ent) | 101 | const struct pci_device_id *ent) |
102 | { | 102 | { |
103 | u32 reg; | 103 | u32 reg; |
@@ -119,7 +119,7 @@ static bool mei_quirk_probe(struct pci_dev *pdev, | |||
119 | * | 119 | * |
120 | * returns 0 on success, <0 on failure. | 120 | * returns 0 on success, <0 on failure. |
121 | */ | 121 | */ |
122 | static int mei_probe(struct pci_dev *pdev, const struct pci_device_id *ent) | 122 | static int mei_me_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
123 | { | 123 | { |
124 | struct mei_device *dev; | 124 | struct mei_device *dev; |
125 | struct mei_me_hw *hw; | 125 | struct mei_me_hw *hw; |
@@ -127,7 +127,7 @@ static int mei_probe(struct pci_dev *pdev, const struct pci_device_id *ent) | |||
127 | 127 | ||
128 | mutex_lock(&mei_mutex); | 128 | mutex_lock(&mei_mutex); |
129 | 129 | ||
130 | if (!mei_quirk_probe(pdev, ent)) { | 130 | if (!mei_me_quirk_probe(pdev, ent)) { |
131 | err = -ENODEV; | 131 | err = -ENODEV; |
132 | goto end; | 132 | goto end; |
133 | } | 133 | } |
@@ -184,20 +184,19 @@ static int mei_probe(struct pci_dev *pdev, const struct pci_device_id *ent) | |||
184 | goto disable_msi; | 184 | goto disable_msi; |
185 | } | 185 | } |
186 | 186 | ||
187 | if (mei_hw_init(dev)) { | 187 | if (mei_start(dev)) { |
188 | dev_err(&pdev->dev, "init hw failure.\n"); | 188 | dev_err(&pdev->dev, "init hw failure.\n"); |
189 | err = -ENODEV; | 189 | err = -ENODEV; |
190 | goto release_irq; | 190 | goto release_irq; |
191 | } | 191 | } |
192 | 192 | ||
193 | err = mei_register(&pdev->dev); | 193 | err = mei_register(dev); |
194 | if (err) | 194 | if (err) |
195 | goto release_irq; | 195 | goto release_irq; |
196 | 196 | ||
197 | mei_pdev = pdev; | 197 | mei_pdev = pdev; |
198 | pci_set_drvdata(pdev, dev); | 198 | pci_set_drvdata(pdev, dev); |
199 | 199 | ||
200 | |||
201 | schedule_delayed_work(&dev->timer_work, HZ); | 200 | schedule_delayed_work(&dev->timer_work, HZ); |
202 | 201 | ||
203 | mutex_unlock(&mei_mutex); | 202 | mutex_unlock(&mei_mutex); |
@@ -233,7 +232,7 @@ end: | |||
233 | * mei_remove is called by the PCI subsystem to alert the driver | 232 | * mei_remove is called by the PCI subsystem to alert the driver |
234 | * that it should release a PCI device. | 233 | * that it should release a PCI device. |
235 | */ | 234 | */ |
236 | static void mei_remove(struct pci_dev *pdev) | 235 | static void mei_me_remove(struct pci_dev *pdev) |
237 | { | 236 | { |
238 | struct mei_device *dev; | 237 | struct mei_device *dev; |
239 | struct mei_me_hw *hw; | 238 | struct mei_me_hw *hw; |
@@ -253,8 +252,6 @@ static void mei_remove(struct pci_dev *pdev) | |||
253 | 252 | ||
254 | mei_pdev = NULL; | 253 | mei_pdev = NULL; |
255 | 254 | ||
256 | mei_watchdog_unregister(dev); | ||
257 | |||
258 | /* disable interrupts */ | 255 | /* disable interrupts */ |
259 | mei_disable_interrupts(dev); | 256 | mei_disable_interrupts(dev); |
260 | 257 | ||
@@ -265,16 +262,17 @@ static void mei_remove(struct pci_dev *pdev) | |||
265 | if (hw->mem_addr) | 262 | if (hw->mem_addr) |
266 | pci_iounmap(pdev, hw->mem_addr); | 263 | pci_iounmap(pdev, hw->mem_addr); |
267 | 264 | ||
265 | mei_deregister(dev); | ||
266 | |||
268 | kfree(dev); | 267 | kfree(dev); |
269 | 268 | ||
270 | pci_release_regions(pdev); | 269 | pci_release_regions(pdev); |
271 | pci_disable_device(pdev); | 270 | pci_disable_device(pdev); |
272 | 271 | ||
273 | mei_deregister(); | ||
274 | 272 | ||
275 | } | 273 | } |
276 | #ifdef CONFIG_PM | 274 | #ifdef CONFIG_PM |
277 | static int mei_pci_suspend(struct device *device) | 275 | static int mei_me_pci_suspend(struct device *device) |
278 | { | 276 | { |
279 | struct pci_dev *pdev = to_pci_dev(device); | 277 | struct pci_dev *pdev = to_pci_dev(device); |
280 | struct mei_device *dev = pci_get_drvdata(pdev); | 278 | struct mei_device *dev = pci_get_drvdata(pdev); |
@@ -294,7 +292,7 @@ static int mei_pci_suspend(struct device *device) | |||
294 | return 0; | 292 | return 0; |
295 | } | 293 | } |
296 | 294 | ||
297 | static int mei_pci_resume(struct device *device) | 295 | static int mei_me_pci_resume(struct device *device) |
298 | { | 296 | { |
299 | struct pci_dev *pdev = to_pci_dev(device); | 297 | struct pci_dev *pdev = to_pci_dev(device); |
300 | struct mei_device *dev; | 298 | struct mei_device *dev; |
@@ -334,24 +332,24 @@ static int mei_pci_resume(struct device *device) | |||
334 | 332 | ||
335 | return err; | 333 | return err; |
336 | } | 334 | } |
337 | static SIMPLE_DEV_PM_OPS(mei_pm_ops, mei_pci_suspend, mei_pci_resume); | 335 | static SIMPLE_DEV_PM_OPS(mei_me_pm_ops, mei_me_pci_suspend, mei_me_pci_resume); |
338 | #define MEI_PM_OPS (&mei_pm_ops) | 336 | #define MEI_ME_PM_OPS (&mei_me_pm_ops) |
339 | #else | 337 | #else |
340 | #define MEI_PM_OPS NULL | 338 | #define MEI_ME_PM_OPS NULL |
341 | #endif /* CONFIG_PM */ | 339 | #endif /* CONFIG_PM */ |
342 | /* | 340 | /* |
343 | * PCI driver structure | 341 | * PCI driver structure |
344 | */ | 342 | */ |
345 | static struct pci_driver mei_driver = { | 343 | static struct pci_driver mei_me_driver = { |
346 | .name = KBUILD_MODNAME, | 344 | .name = KBUILD_MODNAME, |
347 | .id_table = mei_pci_tbl, | 345 | .id_table = mei_me_pci_tbl, |
348 | .probe = mei_probe, | 346 | .probe = mei_me_probe, |
349 | .remove = mei_remove, | 347 | .remove = mei_me_remove, |
350 | .shutdown = mei_remove, | 348 | .shutdown = mei_me_remove, |
351 | .driver.pm = MEI_PM_OPS, | 349 | .driver.pm = MEI_ME_PM_OPS, |
352 | }; | 350 | }; |
353 | 351 | ||
354 | module_pci_driver(mei_driver); | 352 | module_pci_driver(mei_me_driver); |
355 | 353 | ||
356 | MODULE_AUTHOR("Intel Corporation"); | 354 | MODULE_AUTHOR("Intel Corporation"); |
357 | MODULE_DESCRIPTION("Intel(R) Management Engine Interface"); | 355 | MODULE_DESCRIPTION("Intel(R) Management Engine Interface"); |
diff --git a/drivers/misc/mei/wd.c b/drivers/misc/mei/wd.c index 2413247fc392..eb3f05c8d7d0 100644 --- a/drivers/misc/mei/wd.c +++ b/drivers/misc/mei/wd.c | |||
@@ -317,7 +317,8 @@ end: | |||
317 | * | 317 | * |
318 | * returns 0 if success, negative errno code for failure | 318 | * returns 0 if success, negative errno code for failure |
319 | */ | 319 | */ |
320 | static int mei_wd_ops_set_timeout(struct watchdog_device *wd_dev, unsigned int timeout) | 320 | static int mei_wd_ops_set_timeout(struct watchdog_device *wd_dev, |
321 | unsigned int timeout) | ||
321 | { | 322 | { |
322 | struct mei_device *dev; | 323 | struct mei_device *dev; |
323 | 324 | ||
diff --git a/drivers/misc/tsl2550.c b/drivers/misc/tsl2550.c index 1e7bc0eb081e..1dfde4d543db 100644 --- a/drivers/misc/tsl2550.c +++ b/drivers/misc/tsl2550.c | |||
@@ -417,24 +417,26 @@ static int tsl2550_remove(struct i2c_client *client) | |||
417 | return 0; | 417 | return 0; |
418 | } | 418 | } |
419 | 419 | ||
420 | #ifdef CONFIG_PM | 420 | #ifdef CONFIG_PM_SLEEP |
421 | 421 | ||
422 | static int tsl2550_suspend(struct i2c_client *client, pm_message_t mesg) | 422 | static int tsl2550_suspend(struct device *dev) |
423 | { | 423 | { |
424 | return tsl2550_set_power_state(client, 0); | 424 | return tsl2550_set_power_state(to_i2c_client(dev), 0); |
425 | } | 425 | } |
426 | 426 | ||
427 | static int tsl2550_resume(struct i2c_client *client) | 427 | static int tsl2550_resume(struct device *dev) |
428 | { | 428 | { |
429 | return tsl2550_set_power_state(client, 1); | 429 | return tsl2550_set_power_state(to_i2c_client(dev), 1); |
430 | } | 430 | } |
431 | 431 | ||
432 | static SIMPLE_DEV_PM_OPS(tsl2550_pm_ops, tsl2550_suspend, tsl2550_resume); | ||
433 | #define TSL2550_PM_OPS (&tsl2550_pm_ops) | ||
434 | |||
432 | #else | 435 | #else |
433 | 436 | ||
434 | #define tsl2550_suspend NULL | 437 | #define TSL2550_PM_OPS NULL |
435 | #define tsl2550_resume NULL | ||
436 | 438 | ||
437 | #endif /* CONFIG_PM */ | 439 | #endif /* CONFIG_PM_SLEEP */ |
438 | 440 | ||
439 | static const struct i2c_device_id tsl2550_id[] = { | 441 | static const struct i2c_device_id tsl2550_id[] = { |
440 | { "tsl2550", 0 }, | 442 | { "tsl2550", 0 }, |
@@ -446,9 +448,8 @@ static struct i2c_driver tsl2550_driver = { | |||
446 | .driver = { | 448 | .driver = { |
447 | .name = TSL2550_DRV_NAME, | 449 | .name = TSL2550_DRV_NAME, |
448 | .owner = THIS_MODULE, | 450 | .owner = THIS_MODULE, |
451 | .pm = TSL2550_PM_OPS, | ||
449 | }, | 452 | }, |
450 | .suspend = tsl2550_suspend, | ||
451 | .resume = tsl2550_resume, | ||
452 | .probe = tsl2550_probe, | 453 | .probe = tsl2550_probe, |
453 | .remove = tsl2550_remove, | 454 | .remove = tsl2550_remove, |
454 | .id_table = tsl2550_id, | 455 | .id_table = tsl2550_id, |