aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/acpi/Kconfig10
-rw-r--r--drivers/acpi/Makefile1
-rw-r--r--drivers/acpi/ac.c9
-rw-r--r--drivers/acpi/acpi_memhotplug.c9
-rw-r--r--drivers/acpi/asus_acpi.c20
-rw-r--r--drivers/acpi/battery.c24
-rw-r--r--drivers/acpi/bay.c107
-rw-r--r--drivers/acpi/bus.c30
-rw-r--r--drivers/acpi/button.c7
-rw-r--r--drivers/acpi/cm_sbs.c2
-rw-r--r--drivers/acpi/container.c9
-rw-r--r--drivers/acpi/debug.c2
-rw-r--r--drivers/acpi/dispatcher/dsmethod.c12
-rw-r--r--drivers/acpi/dock.c8
-rw-r--r--drivers/acpi/ec.c9
-rw-r--r--drivers/acpi/event.c2
-rw-r--r--drivers/acpi/events/evgpe.c11
-rw-r--r--drivers/acpi/events/evmisc.c11
-rw-r--r--drivers/acpi/executer/exdump.c2
-rw-r--r--drivers/acpi/executer/exmutex.c36
-rw-r--r--drivers/acpi/fan.c9
-rw-r--r--drivers/acpi/glue.c62
-rw-r--r--drivers/acpi/hardware/hwsleep.c13
-rw-r--r--drivers/acpi/hotkey.c1042
-rw-r--r--drivers/acpi/i2c_ec.c5
-rw-r--r--drivers/acpi/ibm_acpi.c18
-rw-r--r--drivers/acpi/numa.c18
-rw-r--r--drivers/acpi/osl.c35
-rw-r--r--drivers/acpi/pci_bind.c2
-rw-r--r--drivers/acpi/pci_irq.c2
-rw-r--r--drivers/acpi/pci_link.c5
-rw-r--r--drivers/acpi/pci_root.c5
-rw-r--r--drivers/acpi/power.c156
-rw-r--r--drivers/acpi/processor_core.c13
-rw-r--r--drivers/acpi/processor_idle.c11
-rw-r--r--drivers/acpi/processor_perflib.c3
-rw-r--r--drivers/acpi/processor_thermal.c3
-rw-r--r--drivers/acpi/processor_throttling.c3
-rw-r--r--drivers/acpi/sbs.c25
-rw-r--r--drivers/acpi/scan.c3
-rw-r--r--drivers/acpi/sleep/main.c3
-rw-r--r--drivers/acpi/system.c3
-rw-r--r--drivers/acpi/tables.c41
-rw-r--r--drivers/acpi/tables/tbxface.c9
-rw-r--r--drivers/acpi/thermal.c37
-rw-r--r--drivers/acpi/toshiba_acpi.c6
-rw-r--r--drivers/acpi/utilities/utdelete.c1
-rw-r--r--drivers/acpi/utils.c2
-rw-r--r--drivers/acpi/video.c9
-rw-r--r--drivers/base/bus.c22
-rw-r--r--drivers/base/class.c3
-rw-r--r--drivers/infiniband/core/Makefile2
-rw-r--r--drivers/infiniband/core/cma.c359
-rw-r--r--drivers/infiniband/core/fmr_pool.c4
-rw-r--r--drivers/infiniband/core/iwcm.c47
-rw-r--r--drivers/infiniband/core/multicast.c837
-rw-r--r--drivers/infiniband/core/sa.h66
-rw-r--r--drivers/infiniband/core/sa_query.c30
-rw-r--r--drivers/infiniband/core/sysfs.c2
-rw-r--r--drivers/infiniband/core/ucma.c204
-rw-r--r--drivers/infiniband/hw/cxgb3/cxio_dbg.c1
-rw-r--r--drivers/infiniband/hw/cxgb3/cxio_hal.c1
-rw-r--r--drivers/infiniband/hw/cxgb3/cxio_hal.h1
-rw-r--r--drivers/infiniband/hw/cxgb3/cxio_resource.c1
-rw-r--r--drivers/infiniband/hw/cxgb3/cxio_resource.h1
-rw-r--r--drivers/infiniband/hw/cxgb3/cxio_wr.h1
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch.c1
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch.h1
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_cm.c1
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_cm.h1
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_cq.c1
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_ev.c1
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_mem.c1
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_provider.c1
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_provider.h1
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_qp.c3
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_user.h1
-rw-r--r--drivers/infiniband/hw/ehca/Kconfig8
-rw-r--r--drivers/infiniband/hw/ehca/ehca_classes.h19
-rw-r--r--drivers/infiniband/hw/ehca/ehca_eq.c1
-rw-r--r--drivers/infiniband/hw/ehca/ehca_hca.c3
-rw-r--r--drivers/infiniband/hw/ehca/ehca_irq.c307
-rw-r--r--drivers/infiniband/hw/ehca/ehca_irq.h1
-rw-r--r--drivers/infiniband/hw/ehca/ehca_main.c32
-rw-r--r--drivers/infiniband/hw/ehca/ipz_pt_fn.h11
-rw-r--r--drivers/infiniband/hw/ipath/ipath_dma.c4
-rw-r--r--drivers/infiniband/hw/mthca/mthca_memfree.c4
-rw-r--r--drivers/infiniband/hw/mthca/mthca_qp.c5
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_cm.c4
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_multicast.c195
-rw-r--r--drivers/misc/Kconfig15
-rw-r--r--drivers/misc/Makefile1
-rw-r--r--drivers/misc/asus-laptop.c5
-rw-r--r--drivers/misc/sony-laptop.c562
-rw-r--r--drivers/pci/pci-driver.c1
-rw-r--r--drivers/pci/pci-sysfs.c11
-rw-r--r--drivers/pci/pci.c12
-rw-r--r--drivers/pci/setup-bus.c27
-rw-r--r--drivers/pci/setup-irq.c18
-rw-r--r--drivers/pcmcia/at91_cf.c2
-rw-r--r--drivers/pcmcia/soc_common.c8
-rw-r--r--drivers/pnp/pnpacpi/Kconfig16
-rw-r--r--drivers/scsi/sd.c11
-rw-r--r--drivers/serial/serial_cs.c5
-rw-r--r--drivers/usb/Makefile1
-rw-r--r--drivers/usb/atm/ueagle-atm.c1
-rw-r--r--drivers/usb/class/cdc-acm.c33
-rw-r--r--drivers/usb/core/devices.c9
-rw-r--r--drivers/usb/core/devio.c4
-rw-r--r--drivers/usb/core/driver.c1
-rw-r--r--drivers/usb/core/endpoint.c2
-rw-r--r--drivers/usb/core/generic.c2
-rw-r--r--drivers/usb/core/hub.c31
-rw-r--r--drivers/usb/core/message.c22
-rw-r--r--drivers/usb/core/otg_whitelist.h2
-rw-r--r--drivers/usb/core/sysfs.c2
-rw-r--r--drivers/usb/gadget/at91_udc.c15
-rw-r--r--drivers/usb/gadget/serial.c1
-rw-r--r--drivers/usb/host/ehci-hcd.c36
-rw-r--r--drivers/usb/host/ehci-hub.c2
-rw-r--r--drivers/usb/host/isp116x-hcd.c2
-rw-r--r--drivers/usb/host/ohci-at91.c50
-rw-r--r--drivers/usb/host/ohci-hcd.c18
-rw-r--r--drivers/usb/input/hid-core.c8
-rw-r--r--drivers/usb/misc/Kconfig11
-rw-r--r--drivers/usb/misc/Makefile1
-rw-r--r--drivers/usb/misc/appledisplay.c4
-rw-r--r--drivers/usb/misc/berry_charge.c140
-rw-r--r--drivers/usb/net/Kconfig11
-rw-r--r--drivers/usb/net/asix.c2
-rw-r--r--drivers/usb/net/cdc_subset.c21
-rw-r--r--drivers/usb/net/usbnet.c29
-rw-r--r--drivers/usb/serial/airprime.c35
-rw-r--r--drivers/usb/serial/cp2101.c1
-rw-r--r--drivers/usb/serial/generic.c102
-rw-r--r--drivers/usb/serial/option.c4
-rw-r--r--drivers/usb/serial/pl2303.c1
-rw-r--r--drivers/usb/serial/pl2303.h5
-rw-r--r--drivers/usb/storage/scsiglue.c6
-rw-r--r--drivers/usb/storage/unusual_devs.h26
-rw-r--r--drivers/usb/usb-skeleton.c10
141 files changed, 3358 insertions, 2041 deletions
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index 20eacc2c9e0e..e942ffe8b57e 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -13,6 +13,7 @@ config ACPI
13 depends on IA64 || X86 13 depends on IA64 || X86
14 depends on PCI 14 depends on PCI
15 depends on PM 15 depends on PM
16 select PNP
16 default y 17 default y
17 ---help--- 18 ---help---
18 Advanced Configuration and Power Interface (ACPI) support for 19 Advanced Configuration and Power Interface (ACPI) support for
@@ -132,15 +133,6 @@ config ACPI_VIDEO
132 Note that this is an ref. implementation only. It may or may not work 133 Note that this is an ref. implementation only. It may or may not work
133 for your integrated video device. 134 for your integrated video device.
134 135
135config ACPI_HOTKEY
136 tristate "Generic Hotkey (EXPERIMENTAL)"
137 depends on EXPERIMENTAL
138 depends on X86
139 default n
140 help
141 Experimental consolidated hotkey driver.
142 If you are unsure, say N.
143
144config ACPI_FAN 136config ACPI_FAN
145 tristate "Fan" 137 tristate "Fan"
146 default y 138 default y
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index 856c32bccacb..5956e9f64a8b 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -46,7 +46,6 @@ obj-$(CONFIG_ACPI_FAN) += fan.o
46obj-$(CONFIG_ACPI_DOCK) += dock.o 46obj-$(CONFIG_ACPI_DOCK) += dock.o
47obj-$(CONFIG_ACPI_BAY) += bay.o 47obj-$(CONFIG_ACPI_BAY) += bay.o
48obj-$(CONFIG_ACPI_VIDEO) += video.o 48obj-$(CONFIG_ACPI_VIDEO) += video.o
49obj-$(CONFIG_ACPI_HOTKEY) += hotkey.o
50obj-y += pci_root.o pci_link.o pci_irq.o pci_bind.o 49obj-y += pci_root.o pci_link.o pci_irq.o pci_bind.o
51obj-$(CONFIG_ACPI_POWER) += power.o 50obj-$(CONFIG_ACPI_POWER) += power.o
52obj-$(CONFIG_ACPI_PROCESSOR) += processor.o 51obj-$(CONFIG_ACPI_PROCESSOR) += processor.o
diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c
index 6daeace796a8..37c7dc4f9fe5 100644
--- a/drivers/acpi/ac.c
+++ b/drivers/acpi/ac.c
@@ -35,7 +35,6 @@
35#define ACPI_AC_COMPONENT 0x00020000 35#define ACPI_AC_COMPONENT 0x00020000
36#define ACPI_AC_CLASS "ac_adapter" 36#define ACPI_AC_CLASS "ac_adapter"
37#define ACPI_AC_HID "ACPI0003" 37#define ACPI_AC_HID "ACPI0003"
38#define ACPI_AC_DRIVER_NAME "ACPI AC Adapter Driver"
39#define ACPI_AC_DEVICE_NAME "AC Adapter" 38#define ACPI_AC_DEVICE_NAME "AC Adapter"
40#define ACPI_AC_FILE_STATE "state" 39#define ACPI_AC_FILE_STATE "state"
41#define ACPI_AC_NOTIFY_STATUS 0x80 40#define ACPI_AC_NOTIFY_STATUS 0x80
@@ -44,10 +43,10 @@
44#define ACPI_AC_STATUS_UNKNOWN 0xFF 43#define ACPI_AC_STATUS_UNKNOWN 0xFF
45 44
46#define _COMPONENT ACPI_AC_COMPONENT 45#define _COMPONENT ACPI_AC_COMPONENT
47ACPI_MODULE_NAME("acpi_ac") 46ACPI_MODULE_NAME("ac");
48 47
49 MODULE_AUTHOR("Paul Diefenbaugh"); 48MODULE_AUTHOR("Paul Diefenbaugh");
50MODULE_DESCRIPTION(ACPI_AC_DRIVER_NAME); 49MODULE_DESCRIPTION("ACPI AC Adapter Driver");
51MODULE_LICENSE("GPL"); 50MODULE_LICENSE("GPL");
52 51
53extern struct proc_dir_entry *acpi_lock_ac_dir(void); 52extern struct proc_dir_entry *acpi_lock_ac_dir(void);
@@ -58,7 +57,7 @@ static int acpi_ac_remove(struct acpi_device *device, int type);
58static int acpi_ac_open_fs(struct inode *inode, struct file *file); 57static int acpi_ac_open_fs(struct inode *inode, struct file *file);
59 58
60static struct acpi_driver acpi_ac_driver = { 59static struct acpi_driver acpi_ac_driver = {
61 .name = ACPI_AC_DRIVER_NAME, 60 .name = "ac",
62 .class = ACPI_AC_CLASS, 61 .class = ACPI_AC_CLASS,
63 .ids = ACPI_AC_HID, 62 .ids = ACPI_AC_HID,
64 .ops = { 63 .ops = {
diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c
index cd946ed192d3..c26172671fd8 100644
--- a/drivers/acpi/acpi_memhotplug.c
+++ b/drivers/acpi/acpi_memhotplug.c
@@ -35,14 +35,13 @@
35#define ACPI_MEMORY_DEVICE_COMPONENT 0x08000000UL 35#define ACPI_MEMORY_DEVICE_COMPONENT 0x08000000UL
36#define ACPI_MEMORY_DEVICE_CLASS "memory" 36#define ACPI_MEMORY_DEVICE_CLASS "memory"
37#define ACPI_MEMORY_DEVICE_HID "PNP0C80" 37#define ACPI_MEMORY_DEVICE_HID "PNP0C80"
38#define ACPI_MEMORY_DEVICE_DRIVER_NAME "Hotplug Mem Driver"
39#define ACPI_MEMORY_DEVICE_NAME "Hotplug Mem Device" 38#define ACPI_MEMORY_DEVICE_NAME "Hotplug Mem Device"
40 39
41#define _COMPONENT ACPI_MEMORY_DEVICE_COMPONENT 40#define _COMPONENT ACPI_MEMORY_DEVICE_COMPONENT
42 41
43ACPI_MODULE_NAME("acpi_memory") 42ACPI_MODULE_NAME("acpi_memhotplug");
44 MODULE_AUTHOR("Naveen B S <naveen.b.s@intel.com>"); 43MODULE_AUTHOR("Naveen B S <naveen.b.s@intel.com>");
45MODULE_DESCRIPTION(ACPI_MEMORY_DEVICE_DRIVER_NAME); 44MODULE_DESCRIPTION("Hotplug Mem Driver");
46MODULE_LICENSE("GPL"); 45MODULE_LICENSE("GPL");
47 46
48/* ACPI _STA method values */ 47/* ACPI _STA method values */
@@ -60,7 +59,7 @@ static int acpi_memory_device_remove(struct acpi_device *device, int type);
60static int acpi_memory_device_start(struct acpi_device *device); 59static int acpi_memory_device_start(struct acpi_device *device);
61 60
62static struct acpi_driver acpi_memory_device_driver = { 61static struct acpi_driver acpi_memory_device_driver = {
63 .name = ACPI_MEMORY_DEVICE_DRIVER_NAME, 62 .name = "acpi_memhotplug",
64 .class = ACPI_MEMORY_DEVICE_CLASS, 63 .class = ACPI_MEMORY_DEVICE_CLASS,
65 .ids = ACPI_MEMORY_DEVICE_HID, 64 .ids = ACPI_MEMORY_DEVICE_HID,
66 .ops = { 65 .ops = {
diff --git a/drivers/acpi/asus_acpi.c b/drivers/acpi/asus_acpi.c
index 31ad70a6e22e..772299fb5f9d 100644
--- a/drivers/acpi/asus_acpi.c
+++ b/drivers/acpi/asus_acpi.c
@@ -141,6 +141,7 @@ struct asus_hotk {
141 W5A, //W5A 141 W5A, //W5A
142 W3V, //W3030V 142 W3V, //W3030V
143 xxN, //M2400N, M3700N, M5200N, M6800N, S1300N, S5200N 143 xxN, //M2400N, M3700N, M5200N, M6800N, S1300N, S5200N
144 A4S, //Z81sp
144 //(Centrino) 145 //(Centrino)
145 END_MODEL 146 END_MODEL
146 } model; //Models currently supported 147 } model; //Models currently supported
@@ -397,7 +398,16 @@ static struct model_data model_conf[END_MODEL] = {
397 .brightness_set = "SPLV", 398 .brightness_set = "SPLV",
398 .brightness_get = "GPLV", 399 .brightness_get = "GPLV",
399 .display_set = "SDSP", 400 .display_set = "SDSP",
400 .display_get = "\\ADVG"} 401 .display_get = "\\ADVG"},
402
403 {
404 .name = "A4S",
405 .brightness_set = "SPLV",
406 .brightness_get = "GPLV",
407 .mt_bt_switch = "BLED",
408 .mt_wled = "WLED"
409 }
410
401}; 411};
402 412
403/* procdir we use */ 413/* procdir we use */
@@ -421,7 +431,7 @@ static struct asus_hotk *hotk;
421static int asus_hotk_add(struct acpi_device *device); 431static int asus_hotk_add(struct acpi_device *device);
422static int asus_hotk_remove(struct acpi_device *device, int type); 432static int asus_hotk_remove(struct acpi_device *device, int type);
423static struct acpi_driver asus_hotk_driver = { 433static struct acpi_driver asus_hotk_driver = {
424 .name = ACPI_HOTK_NAME, 434 .name = "asus_acpi",
425 .class = ACPI_HOTK_CLASS, 435 .class = ACPI_HOTK_CLASS,
426 .ids = ACPI_HOTK_HID, 436 .ids = ACPI_HOTK_HID,
427 .ops = { 437 .ops = {
@@ -1117,6 +1127,8 @@ static int asus_model_match(char *model)
1117 return W3V; 1127 return W3V;
1118 else if (strncmp(model, "W5A", 3) == 0) 1128 else if (strncmp(model, "W5A", 3) == 0)
1119 return W5A; 1129 return W5A;
1130 else if (strncmp(model, "A4S", 3) == 0)
1131 return A4S;
1120 else 1132 else
1121 return END_MODEL; 1133 return END_MODEL;
1122} 1134}
@@ -1365,10 +1377,6 @@ static int __init asus_acpi_init(void)
1365 if (acpi_disabled) 1377 if (acpi_disabled)
1366 return -ENODEV; 1378 return -ENODEV;
1367 1379
1368 if (!acpi_specific_hotkey_enabled) {
1369 printk(KERN_ERR "Using generic hotkey driver\n");
1370 return -ENODEV;
1371 }
1372 asus_proc_dir = proc_mkdir(PROC_ASUS, acpi_root_dir); 1380 asus_proc_dir = proc_mkdir(PROC_ASUS, acpi_root_dir);
1373 if (!asus_proc_dir) { 1381 if (!asus_proc_dir) {
1374 printk(KERN_ERR "Asus ACPI: Unable to create /proc entry\n"); 1382 printk(KERN_ERR "Asus ACPI: Unable to create /proc entry\n");
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 2f4521a48fe7..e64c76c8b726 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -42,7 +42,6 @@
42#define ACPI_BATTERY_COMPONENT 0x00040000 42#define ACPI_BATTERY_COMPONENT 0x00040000
43#define ACPI_BATTERY_CLASS "battery" 43#define ACPI_BATTERY_CLASS "battery"
44#define ACPI_BATTERY_HID "PNP0C0A" 44#define ACPI_BATTERY_HID "PNP0C0A"
45#define ACPI_BATTERY_DRIVER_NAME "ACPI Battery Driver"
46#define ACPI_BATTERY_DEVICE_NAME "Battery" 45#define ACPI_BATTERY_DEVICE_NAME "Battery"
47#define ACPI_BATTERY_FILE_INFO "info" 46#define ACPI_BATTERY_FILE_INFO "info"
48#define ACPI_BATTERY_FILE_STATUS "state" 47#define ACPI_BATTERY_FILE_STATUS "state"
@@ -53,10 +52,10 @@
53#define ACPI_BATTERY_UNITS_AMPS "mA" 52#define ACPI_BATTERY_UNITS_AMPS "mA"
54 53
55#define _COMPONENT ACPI_BATTERY_COMPONENT 54#define _COMPONENT ACPI_BATTERY_COMPONENT
56ACPI_MODULE_NAME("acpi_battery") 55ACPI_MODULE_NAME("battery");
57 56
58 MODULE_AUTHOR("Paul Diefenbaugh"); 57MODULE_AUTHOR("Paul Diefenbaugh");
59MODULE_DESCRIPTION(ACPI_BATTERY_DRIVER_NAME); 58MODULE_DESCRIPTION("ACPI Battery Driver");
60MODULE_LICENSE("GPL"); 59MODULE_LICENSE("GPL");
61 60
62extern struct proc_dir_entry *acpi_lock_battery_dir(void); 61extern struct proc_dir_entry *acpi_lock_battery_dir(void);
@@ -67,7 +66,7 @@ static int acpi_battery_remove(struct acpi_device *device, int type);
67static int acpi_battery_resume(struct acpi_device *device); 66static int acpi_battery_resume(struct acpi_device *device);
68 67
69static struct acpi_driver acpi_battery_driver = { 68static struct acpi_driver acpi_battery_driver = {
70 .name = ACPI_BATTERY_DRIVER_NAME, 69 .name = "battery",
71 .class = ACPI_BATTERY_CLASS, 70 .class = ACPI_BATTERY_CLASS,
72 .ids = ACPI_BATTERY_HID, 71 .ids = ACPI_BATTERY_HID,
73 .ops = { 72 .ops = {
@@ -324,6 +323,13 @@ static int acpi_battery_check(struct acpi_battery *battery)
324 return result; 323 return result;
325} 324}
326 325
326static void acpi_battery_check_present(struct acpi_battery *battery)
327{
328 if (!battery->flags.present) {
329 acpi_battery_check(battery);
330 }
331}
332
327/* -------------------------------------------------------------------------- 333/* --------------------------------------------------------------------------
328 FS Interface (/proc) 334 FS Interface (/proc)
329 -------------------------------------------------------------------------- */ 335 -------------------------------------------------------------------------- */
@@ -340,6 +346,8 @@ static int acpi_battery_read_info(struct seq_file *seq, void *offset)
340 if (!battery) 346 if (!battery)
341 goto end; 347 goto end;
342 348
349 acpi_battery_check_present(battery);
350
343 if (battery->flags.present) 351 if (battery->flags.present)
344 seq_printf(seq, "present: yes\n"); 352 seq_printf(seq, "present: yes\n");
345 else { 353 else {
@@ -424,6 +432,8 @@ static int acpi_battery_read_state(struct seq_file *seq, void *offset)
424 if (!battery) 432 if (!battery)
425 goto end; 433 goto end;
426 434
435 acpi_battery_check_present(battery);
436
427 if (battery->flags.present) 437 if (battery->flags.present)
428 seq_printf(seq, "present: yes\n"); 438 seq_printf(seq, "present: yes\n");
429 else { 439 else {
@@ -499,6 +509,8 @@ static int acpi_battery_read_alarm(struct seq_file *seq, void *offset)
499 if (!battery) 509 if (!battery)
500 goto end; 510 goto end;
501 511
512 acpi_battery_check_present(battery);
513
502 if (!battery->flags.present) { 514 if (!battery->flags.present) {
503 seq_printf(seq, "present: no\n"); 515 seq_printf(seq, "present: no\n");
504 goto end; 516 goto end;
@@ -536,6 +548,8 @@ acpi_battery_write_alarm(struct file *file,
536 if (!battery || (count > sizeof(alarm_string) - 1)) 548 if (!battery || (count > sizeof(alarm_string) - 1))
537 return -EINVAL; 549 return -EINVAL;
538 550
551 acpi_battery_check_present(battery);
552
539 if (!battery->flags.present) 553 if (!battery->flags.present)
540 return -ENODEV; 554 return -ENODEV;
541 555
diff --git a/drivers/acpi/bay.c b/drivers/acpi/bay.c
index 91082ce6f5d1..fb3f31b5e69f 100644
--- a/drivers/acpi/bay.c
+++ b/drivers/acpi/bay.c
@@ -32,11 +32,9 @@
32#include <asm/uaccess.h> 32#include <asm/uaccess.h>
33#include <linux/platform_device.h> 33#include <linux/platform_device.h>
34 34
35#define ACPI_BAY_DRIVER_NAME "ACPI Removable Drive Bay Driver" 35ACPI_MODULE_NAME("bay");
36
37ACPI_MODULE_NAME("bay")
38MODULE_AUTHOR("Kristen Carlson Accardi"); 36MODULE_AUTHOR("Kristen Carlson Accardi");
39MODULE_DESCRIPTION(ACPI_BAY_DRIVER_NAME); 37MODULE_DESCRIPTION("ACPI Removable Drive Bay Driver");
40MODULE_LICENSE("GPL"); 38MODULE_LICENSE("GPL");
41#define ACPI_BAY_CLASS "bay" 39#define ACPI_BAY_CLASS "bay"
42#define ACPI_BAY_COMPONENT 0x10000000 40#define ACPI_BAY_COMPONENT 0x10000000
@@ -47,18 +45,6 @@ MODULE_LICENSE("GPL");
47 acpi_get_name(h, ACPI_FULL_PATHNAME, &buffer);\ 45 acpi_get_name(h, ACPI_FULL_PATHNAME, &buffer);\
48 printk(KERN_DEBUG PREFIX "%s: %s\n", prefix, s); } 46 printk(KERN_DEBUG PREFIX "%s: %s\n", prefix, s); }
49static void bay_notify(acpi_handle handle, u32 event, void *data); 47static void bay_notify(acpi_handle handle, u32 event, void *data);
50static int acpi_bay_add(struct acpi_device *device);
51static int acpi_bay_remove(struct acpi_device *device, int type);
52
53static struct acpi_driver acpi_bay_driver = {
54 .name = ACPI_BAY_DRIVER_NAME,
55 .class = ACPI_BAY_CLASS,
56 .ids = ACPI_BAY_HID,
57 .ops = {
58 .add = acpi_bay_add,
59 .remove = acpi_bay_remove,
60 },
61};
62 48
63struct bay { 49struct bay {
64 acpi_handle handle; 50 acpi_handle handle;
@@ -234,14 +220,6 @@ int eject_removable_drive(struct device *dev)
234} 220}
235EXPORT_SYMBOL_GPL(eject_removable_drive); 221EXPORT_SYMBOL_GPL(eject_removable_drive);
236 222
237static int acpi_bay_add(struct acpi_device *device)
238{
239 bay_dprintk(device->handle, "adding bay device");
240 strcpy(acpi_device_name(device), "Dockable Bay");
241 strcpy(acpi_device_class(device), "bay");
242 return 0;
243}
244
245static int acpi_bay_add_fs(struct bay *bay) 223static int acpi_bay_add_fs(struct bay *bay)
246{ 224{
247 int ret; 225 int ret;
@@ -303,7 +281,7 @@ static int bay_add(acpi_handle handle, int id)
303 281
304 /* initialize platform device stuff */ 282 /* initialize platform device stuff */
305 pdev = platform_device_register_simple(ACPI_BAY_CLASS, id, NULL, 0); 283 pdev = platform_device_register_simple(ACPI_BAY_CLASS, id, NULL, 0);
306 if (pdev == NULL) { 284 if (IS_ERR(pdev)) {
307 printk(KERN_ERR PREFIX "Error registering bay device\n"); 285 printk(KERN_ERR PREFIX "Error registering bay device\n");
308 goto bay_add_err; 286 goto bay_add_err;
309 } 287 }
@@ -339,52 +317,6 @@ bay_add_err:
339 return -ENODEV; 317 return -ENODEV;
340} 318}
341 319
342static int acpi_bay_remove(struct acpi_device *device, int type)
343{
344 /*** FIXME: do something here */
345 return 0;
346}
347
348/**
349 * bay_create_acpi_device - add new devices to acpi
350 * @handle - handle of the device to add
351 *
352 * This function will create a new acpi_device for the given
353 * handle if one does not exist already. This should cause
354 * acpi to scan for drivers for the given devices, and call
355 * matching driver's add routine.
356 *
357 * Returns a pointer to the acpi_device corresponding to the handle.
358 */
359static struct acpi_device * bay_create_acpi_device(acpi_handle handle)
360{
361 struct acpi_device *device = NULL;
362 struct acpi_device *parent_device;
363 acpi_handle parent;
364 int ret;
365
366 bay_dprintk(handle, "Trying to get device");
367 if (acpi_bus_get_device(handle, &device)) {
368 /*
369 * no device created for this object,
370 * so we should create one.
371 */
372 bay_dprintk(handle, "No device for handle");
373 acpi_get_parent(handle, &parent);
374 if (acpi_bus_get_device(parent, &parent_device))
375 parent_device = NULL;
376
377 ret = acpi_bus_add(&device, parent_device, handle,
378 ACPI_BUS_TYPE_DEVICE);
379 if (ret) {
380 pr_debug("error adding bus, %x\n",
381 -ret);
382 return NULL;
383 }
384 }
385 return device;
386}
387
388/** 320/**
389 * bay_notify - act upon an acpi bay notification 321 * bay_notify - act upon an acpi bay notification
390 * @handle: the bay handle 322 * @handle: the bay handle
@@ -394,38 +326,19 @@ static struct acpi_device * bay_create_acpi_device(acpi_handle handle)
394 */ 326 */
395static void bay_notify(acpi_handle handle, u32 event, void *data) 327static void bay_notify(acpi_handle handle, u32 event, void *data)
396{ 328{
397 struct acpi_device *dev; 329 struct bay *bay_dev = (struct bay *)data;
330 struct device *dev = &bay_dev->pdev->dev;
398 331
399 bay_dprintk(handle, "Bay event"); 332 bay_dprintk(handle, "Bay event");
400 333
401 switch(event) { 334 switch(event) {
402 case ACPI_NOTIFY_BUS_CHECK: 335 case ACPI_NOTIFY_BUS_CHECK:
403 printk("Bus Check\n");
404 case ACPI_NOTIFY_DEVICE_CHECK: 336 case ACPI_NOTIFY_DEVICE_CHECK:
405 printk("Device Check\n");
406 dev = bay_create_acpi_device(handle);
407 if (dev)
408 acpi_bus_generate_event(dev, event, 0);
409 else
410 printk("No device for generating event\n");
411 /* wouldn't it be a good idea to just rescan SATA
412 * right here?
413 */
414 break;
415 case ACPI_NOTIFY_EJECT_REQUEST: 337 case ACPI_NOTIFY_EJECT_REQUEST:
416 printk("Eject request\n"); 338 kobject_uevent(&dev->kobj, KOBJ_CHANGE);
417 dev = bay_create_acpi_device(handle);
418 if (dev)
419 acpi_bus_generate_event(dev, event, 0);
420 else
421 printk("No device for generating eventn");
422
423 /* wouldn't it be a good idea to just call the
424 * eject_device here if we were a SATA device?
425 */
426 break; 339 break;
427 default: 340 default:
428 printk("unknown event %d\n", event); 341 printk(KERN_ERR PREFIX "Bay: unknown event %d\n", event);
429 } 342 }
430} 343}
431 344
@@ -457,10 +370,6 @@ static int __init bay_init(void)
457 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, 370 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
458 ACPI_UINT32_MAX, find_bay, &bays, NULL); 371 ACPI_UINT32_MAX, find_bay, &bays, NULL);
459 372
460 if (bays)
461 if ((acpi_bus_register_driver(&acpi_bay_driver) < 0))
462 printk(KERN_ERR "Unable to register bay driver\n");
463
464 if (!bays) 373 if (!bays)
465 return -ENODEV; 374 return -ENODEV;
466 375
@@ -481,8 +390,6 @@ static void __exit bay_exit(void)
481 kfree(bay->name); 390 kfree(bay->name);
482 kfree(bay); 391 kfree(bay);
483 } 392 }
484
485 acpi_bus_unregister_driver(&acpi_bay_driver);
486} 393}
487 394
488postcore_initcall(bay_init); 395postcore_initcall(bay_init);
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index c26468da4295..dd49ea0d0ed3 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -39,7 +39,7 @@
39#include <acpi/acpi_drivers.h> 39#include <acpi/acpi_drivers.h>
40 40
41#define _COMPONENT ACPI_BUS_COMPONENT 41#define _COMPONENT ACPI_BUS_COMPONENT
42ACPI_MODULE_NAME("acpi_bus") 42ACPI_MODULE_NAME("bus");
43#ifdef CONFIG_X86 43#ifdef CONFIG_X86
44extern void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger); 44extern void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger);
45#endif 45#endif
@@ -147,7 +147,7 @@ int acpi_bus_get_power(acpi_handle handle, int *state)
147 *state = ACPI_STATE_D0; 147 *state = ACPI_STATE_D0;
148 } else { 148 } else {
149 /* 149 /*
150 * Get the device's power state either directly (via _PSC) or 150 * Get the device's power state either directly (via _PSC) or
151 * indirectly (via power resources). 151 * indirectly (via power resources).
152 */ 152 */
153 if (device->power.flags.explicit_get) { 153 if (device->power.flags.explicit_get) {
@@ -199,15 +199,14 @@ int acpi_bus_set_power(acpi_handle handle, int state)
199 * Get device's current power state if it's unknown 199 * Get device's current power state if it's unknown
200 * This means device power state isn't initialized or previous setting failed 200 * This means device power state isn't initialized or previous setting failed
201 */ 201 */
202 if (!device->flags.force_power_state) { 202 if ((device->power.state == ACPI_STATE_UNKNOWN) || device->flags.force_power_state)
203 if (device->power.state == ACPI_STATE_UNKNOWN) 203 acpi_bus_get_power(device->handle, &device->power.state);
204 acpi_bus_get_power(device->handle, &device->power.state); 204 if ((state == device->power.state) && !device->flags.force_power_state) {
205 if (state == device->power.state) { 205 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n",
206 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n", 206 state));
207 state)); 207 return 0;
208 return 0;
209 }
210 } 208 }
209
211 if (!device->power.states[state].flags.valid) { 210 if (!device->power.states[state].flags.valid) {
212 printk(KERN_WARNING PREFIX "Device does not support D%d\n", state); 211 printk(KERN_WARNING PREFIX "Device does not support D%d\n", state);
213 return -ENODEV; 212 return -ENODEV;
@@ -462,7 +461,7 @@ static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
462 "Received BUS CHECK notification for device [%s]\n", 461 "Received BUS CHECK notification for device [%s]\n",
463 device->pnp.bus_id)); 462 device->pnp.bus_id));
464 result = acpi_bus_check_scope(device); 463 result = acpi_bus_check_scope(device);
465 /* 464 /*
466 * TBD: We'll need to outsource certain events to non-ACPI 465 * TBD: We'll need to outsource certain events to non-ACPI
467 * drivers via the device manager (device.c). 466 * drivers via the device manager (device.c).
468 */ 467 */
@@ -473,7 +472,7 @@ static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
473 "Received DEVICE CHECK notification for device [%s]\n", 472 "Received DEVICE CHECK notification for device [%s]\n",
474 device->pnp.bus_id)); 473 device->pnp.bus_id));
475 result = acpi_bus_check_device(device, NULL); 474 result = acpi_bus_check_device(device, NULL);
476 /* 475 /*
477 * TBD: We'll need to outsource certain events to non-ACPI 476 * TBD: We'll need to outsource certain events to non-ACPI
478 * drivers via the device manager (device.c). 477 * drivers via the device manager (device.c).
479 */ 478 */
@@ -543,7 +542,7 @@ static int __init acpi_bus_init_irq(void)
543 char *message = NULL; 542 char *message = NULL;
544 543
545 544
546 /* 545 /*
547 * Let the system know what interrupt model we are using by 546 * Let the system know what interrupt model we are using by
548 * evaluating the \_PIC object, if exists. 547 * evaluating the \_PIC object, if exists.
549 */ 548 */
@@ -684,7 +683,7 @@ static int __init acpi_bus_init(void)
684 * the EC device is found in the namespace (i.e. before acpi_initialize_objects() 683 * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
685 * is called). 684 * is called).
686 * 685 *
687 * This is accomplished by looking for the ECDT table, and getting 686 * This is accomplished by looking for the ECDT table, and getting
688 * the EC parameters out of that. 687 * the EC parameters out of that.
689 */ 688 */
690 status = acpi_ec_ecdt_probe(); 689 status = acpi_ec_ecdt_probe();
@@ -699,6 +698,9 @@ static int __init acpi_bus_init(void)
699 698
700 printk(KERN_INFO PREFIX "Interpreter enabled\n"); 699 printk(KERN_INFO PREFIX "Interpreter enabled\n");
701 700
701 /* Initialize sleep structures */
702 acpi_sleep_init();
703
702 /* 704 /*
703 * Get the system interrupt model and evaluate \_PIC. 705 * Get the system interrupt model and evaluate \_PIC.
704 */ 706 */
diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
index c726612fafb6..cb4110b50cd0 100644
--- a/drivers/acpi/button.c
+++ b/drivers/acpi/button.c
@@ -34,7 +34,6 @@
34#include <acpi/acpi_drivers.h> 34#include <acpi/acpi_drivers.h>
35 35
36#define ACPI_BUTTON_COMPONENT 0x00080000 36#define ACPI_BUTTON_COMPONENT 0x00080000
37#define ACPI_BUTTON_DRIVER_NAME "ACPI Button Driver"
38#define ACPI_BUTTON_CLASS "button" 37#define ACPI_BUTTON_CLASS "button"
39#define ACPI_BUTTON_FILE_INFO "info" 38#define ACPI_BUTTON_FILE_INFO "info"
40#define ACPI_BUTTON_FILE_STATE "state" 39#define ACPI_BUTTON_FILE_STATE "state"
@@ -61,10 +60,10 @@
61#define ACPI_BUTTON_TYPE_LID 0x05 60#define ACPI_BUTTON_TYPE_LID 0x05
62 61
63#define _COMPONENT ACPI_BUTTON_COMPONENT 62#define _COMPONENT ACPI_BUTTON_COMPONENT
64ACPI_MODULE_NAME("acpi_button") 63ACPI_MODULE_NAME("button");
65 64
66MODULE_AUTHOR("Paul Diefenbaugh"); 65MODULE_AUTHOR("Paul Diefenbaugh");
67MODULE_DESCRIPTION(ACPI_BUTTON_DRIVER_NAME); 66MODULE_DESCRIPTION("ACPI Button Driver");
68MODULE_LICENSE("GPL"); 67MODULE_LICENSE("GPL");
69 68
70static int acpi_button_add(struct acpi_device *device); 69static int acpi_button_add(struct acpi_device *device);
@@ -73,7 +72,7 @@ static int acpi_button_info_open_fs(struct inode *inode, struct file *file);
73static int acpi_button_state_open_fs(struct inode *inode, struct file *file); 72static int acpi_button_state_open_fs(struct inode *inode, struct file *file);
74 73
75static struct acpi_driver acpi_button_driver = { 74static struct acpi_driver acpi_button_driver = {
76 .name = ACPI_BUTTON_DRIVER_NAME, 75 .name = "button",
77 .class = ACPI_BUTTON_CLASS, 76 .class = ACPI_BUTTON_CLASS,
78 .ids = "button_power,button_sleep,PNP0C0D,PNP0C0C,PNP0C0E", 77 .ids = "button_power,button_sleep,PNP0C0D,PNP0C0C,PNP0C0E",
79 .ops = { 78 .ops = {
diff --git a/drivers/acpi/cm_sbs.c b/drivers/acpi/cm_sbs.c
index 4a9b7bf6f44e..f9db4f444bd0 100644
--- a/drivers/acpi/cm_sbs.c
+++ b/drivers/acpi/cm_sbs.c
@@ -31,7 +31,7 @@
31#include <acpi/actypes.h> 31#include <acpi/actypes.h>
32#include <acpi/acutils.h> 32#include <acpi/acutils.h>
33 33
34ACPI_MODULE_NAME("cm_sbs") 34ACPI_MODULE_NAME("cm_sbs");
35#define ACPI_AC_CLASS "ac_adapter" 35#define ACPI_AC_CLASS "ac_adapter"
36#define ACPI_BATTERY_CLASS "battery" 36#define ACPI_BATTERY_CLASS "battery"
37#define ACPI_SBS_COMPONENT 0x00080000 37#define ACPI_SBS_COMPONENT 0x00080000
diff --git a/drivers/acpi/container.c b/drivers/acpi/container.c
index 69a68fd394cf..0930d9413dfa 100644
--- a/drivers/acpi/container.c
+++ b/drivers/acpi/container.c
@@ -35,7 +35,6 @@
35#include <acpi/acpi_drivers.h> 35#include <acpi/acpi_drivers.h>
36#include <acpi/container.h> 36#include <acpi/container.h>
37 37
38#define ACPI_CONTAINER_DRIVER_NAME "ACPI container driver"
39#define ACPI_CONTAINER_DEVICE_NAME "ACPI container device" 38#define ACPI_CONTAINER_DEVICE_NAME "ACPI container device"
40#define ACPI_CONTAINER_CLASS "container" 39#define ACPI_CONTAINER_CLASS "container"
41 40
@@ -44,10 +43,10 @@
44 43
45#define ACPI_CONTAINER_COMPONENT 0x01000000 44#define ACPI_CONTAINER_COMPONENT 0x01000000
46#define _COMPONENT ACPI_CONTAINER_COMPONENT 45#define _COMPONENT ACPI_CONTAINER_COMPONENT
47ACPI_MODULE_NAME("acpi_container") 46ACPI_MODULE_NAME("container");
48 47
49 MODULE_AUTHOR("Anil S Keshavamurthy"); 48MODULE_AUTHOR("Anil S Keshavamurthy");
50MODULE_DESCRIPTION(ACPI_CONTAINER_DRIVER_NAME); 49MODULE_DESCRIPTION("ACPI container driver");
51MODULE_LICENSE("GPL"); 50MODULE_LICENSE("GPL");
52 51
53#define ACPI_STA_PRESENT (0x00000001) 52#define ACPI_STA_PRESENT (0x00000001)
@@ -56,7 +55,7 @@ static int acpi_container_add(struct acpi_device *device);
56static int acpi_container_remove(struct acpi_device *device, int type); 55static int acpi_container_remove(struct acpi_device *device, int type);
57 56
58static struct acpi_driver acpi_container_driver = { 57static struct acpi_driver acpi_container_driver = {
59 .name = ACPI_CONTAINER_DRIVER_NAME, 58 .name = "container",
60 .class = ACPI_CONTAINER_CLASS, 59 .class = ACPI_CONTAINER_CLASS,
61 .ids = "ACPI0004,PNP0A05,PNP0A06", 60 .ids = "ACPI0004,PNP0A05,PNP0A06",
62 .ops = { 61 .ops = {
diff --git a/drivers/acpi/debug.c b/drivers/acpi/debug.c
index d48f65a8f658..bf513e07b773 100644
--- a/drivers/acpi/debug.c
+++ b/drivers/acpi/debug.c
@@ -12,7 +12,7 @@
12#include <acpi/acglobal.h> 12#include <acpi/acglobal.h>
13 13
14#define _COMPONENT ACPI_SYSTEM_COMPONENT 14#define _COMPONENT ACPI_SYSTEM_COMPONENT
15ACPI_MODULE_NAME("debug") 15ACPI_MODULE_NAME("debug");
16 16
17#ifdef MODULE_PARAM_PREFIX 17#ifdef MODULE_PARAM_PREFIX
18#undef MODULE_PARAM_PREFIX 18#undef MODULE_PARAM_PREFIX
diff --git a/drivers/acpi/dispatcher/dsmethod.c b/drivers/acpi/dispatcher/dsmethod.c
index 1cbe61905824..1683e5c5b94c 100644
--- a/drivers/acpi/dispatcher/dsmethod.c
+++ b/drivers/acpi/dispatcher/dsmethod.c
@@ -231,10 +231,8 @@ acpi_ds_begin_method_execution(struct acpi_namespace_node *method_node,
231 * Obtain the method mutex if necessary. Do not acquire mutex for a 231 * Obtain the method mutex if necessary. Do not acquire mutex for a
232 * recursive call. 232 * recursive call.
233 */ 233 */
234 if (!walk_state || 234 if (acpi_os_get_thread_id() !=
235 !obj_desc->method.mutex->mutex.owner_thread || 235 obj_desc->method.mutex->mutex.owner_thread_id) {
236 (walk_state->thread !=
237 obj_desc->method.mutex->mutex.owner_thread)) {
238 /* 236 /*
239 * Acquire the method mutex. This releases the interpreter if we 237 * Acquire the method mutex. This releases the interpreter if we
240 * block (and reacquires it before it returns) 238 * block (and reacquires it before it returns)
@@ -248,14 +246,14 @@ acpi_ds_begin_method_execution(struct acpi_namespace_node *method_node,
248 } 246 }
249 247
250 /* Update the mutex and walk info and save the original sync_level */ 248 /* Update the mutex and walk info and save the original sync_level */
249 obj_desc->method.mutex->mutex.owner_thread_id =
250 acpi_os_get_thread_id();
251 251
252 if (walk_state) { 252 if (walk_state) {
253 obj_desc->method.mutex->mutex. 253 obj_desc->method.mutex->mutex.
254 original_sync_level = 254 original_sync_level =
255 walk_state->thread->current_sync_level; 255 walk_state->thread->current_sync_level;
256 256
257 obj_desc->method.mutex->mutex.owner_thread =
258 walk_state->thread;
259 walk_state->thread->current_sync_level = 257 walk_state->thread->current_sync_level =
260 obj_desc->method.sync_level; 258 obj_desc->method.sync_level;
261 } else { 259 } else {
@@ -569,7 +567,7 @@ acpi_ds_terminate_control_method(union acpi_operand_object *method_desc,
569 567
570 acpi_os_release_mutex(method_desc->method.mutex->mutex. 568 acpi_os_release_mutex(method_desc->method.mutex->mutex.
571 os_mutex); 569 os_mutex);
572 method_desc->method.mutex->mutex.owner_thread = NULL; 570 method_desc->method.mutex->mutex.owner_thread_id = ACPI_MUTEX_NOT_ACQUIRED;
573 } 571 }
574 } 572 }
575 573
diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
index 688e83a16906..54a697f9aa18 100644
--- a/drivers/acpi/dock.c
+++ b/drivers/acpi/dock.c
@@ -32,11 +32,11 @@
32#include <acpi/acpi_bus.h> 32#include <acpi/acpi_bus.h>
33#include <acpi/acpi_drivers.h> 33#include <acpi/acpi_drivers.h>
34 34
35#define ACPI_DOCK_DRIVER_NAME "ACPI Dock Station Driver" 35#define ACPI_DOCK_DRIVER_DESCRIPTION "ACPI Dock Station Driver"
36 36
37ACPI_MODULE_NAME("dock") 37ACPI_MODULE_NAME("dock");
38MODULE_AUTHOR("Kristen Carlson Accardi"); 38MODULE_AUTHOR("Kristen Carlson Accardi");
39MODULE_DESCRIPTION(ACPI_DOCK_DRIVER_NAME); 39MODULE_DESCRIPTION(ACPI_DOCK_DRIVER_DESCRIPTION);
40MODULE_LICENSE("GPL"); 40MODULE_LICENSE("GPL");
41 41
42static struct atomic_notifier_head dock_notifier_list; 42static struct atomic_notifier_head dock_notifier_list;
@@ -741,7 +741,7 @@ static int dock_add(acpi_handle handle)
741 goto dock_add_err; 741 goto dock_add_err;
742 } 742 }
743 743
744 printk(KERN_INFO PREFIX "%s \n", ACPI_DOCK_DRIVER_NAME); 744 printk(KERN_INFO PREFIX "%s \n", ACPI_DOCK_DRIVER_DESCRIPTION);
745 745
746 return 0; 746 return 0;
747 747
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index 743ce27fa0bb..ab6888373795 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -38,11 +38,10 @@
38#include <acpi/actypes.h> 38#include <acpi/actypes.h>
39 39
40#define _COMPONENT ACPI_EC_COMPONENT 40#define _COMPONENT ACPI_EC_COMPONENT
41ACPI_MODULE_NAME("acpi_ec") 41ACPI_MODULE_NAME("ec");
42#define ACPI_EC_COMPONENT 0x00100000 42#define ACPI_EC_COMPONENT 0x00100000
43#define ACPI_EC_CLASS "embedded_controller" 43#define ACPI_EC_CLASS "embedded_controller"
44#define ACPI_EC_HID "PNP0C09" 44#define ACPI_EC_HID "PNP0C09"
45#define ACPI_EC_DRIVER_NAME "ACPI Embedded Controller Driver"
46#define ACPI_EC_DEVICE_NAME "Embedded Controller" 45#define ACPI_EC_DEVICE_NAME "Embedded Controller"
47#define ACPI_EC_FILE_INFO "info" 46#define ACPI_EC_FILE_INFO "info"
48#undef PREFIX 47#undef PREFIX
@@ -80,7 +79,7 @@ static int acpi_ec_stop(struct acpi_device *device, int type);
80static int acpi_ec_add(struct acpi_device *device); 79static int acpi_ec_add(struct acpi_device *device);
81 80
82static struct acpi_driver acpi_ec_driver = { 81static struct acpi_driver acpi_ec_driver = {
83 .name = ACPI_EC_DRIVER_NAME, 82 .name = "ec",
84 .class = ACPI_EC_CLASS, 83 .class = ACPI_EC_CLASS,
85 .ids = ACPI_EC_HID, 84 .ids = ACPI_EC_HID,
86 .ops = { 85 .ops = {
@@ -280,8 +279,10 @@ static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
280 mutex_lock(&ec->lock); 279 mutex_lock(&ec->lock);
281 if (ec->global_lock) { 280 if (ec->global_lock) {
282 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); 281 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
283 if (ACPI_FAILURE(status)) 282 if (ACPI_FAILURE(status)) {
283 mutex_unlock(&ec->lock);
284 return -ENODEV; 284 return -ENODEV;
285 }
285 } 286 }
286 287
287 /* Make sure GPE is enabled before doing transaction */ 288 /* Make sure GPE is enabled before doing transaction */
diff --git a/drivers/acpi/event.c b/drivers/acpi/event.c
index 959a893c8d1f..3b23562e6f92 100644
--- a/drivers/acpi/event.c
+++ b/drivers/acpi/event.c
@@ -13,7 +13,7 @@
13#include <acpi/acpi_drivers.h> 13#include <acpi/acpi_drivers.h>
14 14
15#define _COMPONENT ACPI_SYSTEM_COMPONENT 15#define _COMPONENT ACPI_SYSTEM_COMPONENT
16ACPI_MODULE_NAME("event") 16ACPI_MODULE_NAME("event");
17 17
18/* Global vars for handling event proc entry */ 18/* Global vars for handling event proc entry */
19static DEFINE_SPINLOCK(acpi_system_event_lock); 19static DEFINE_SPINLOCK(acpi_system_event_lock);
diff --git a/drivers/acpi/events/evgpe.c b/drivers/acpi/events/evgpe.c
index dfac3ecc596e..635ba449ebc2 100644
--- a/drivers/acpi/events/evgpe.c
+++ b/drivers/acpi/events/evgpe.c
@@ -636,17 +636,6 @@ acpi_ev_gpe_dispatch(struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number)
636 } 636 }
637 } 637 }
638 638
639 if (!acpi_gbl_system_awake_and_running) {
640 /*
641 * We just woke up because of a wake GPE. Disable any further GPEs
642 * until we are fully up and running (Only wake GPEs should be enabled
643 * at this time, but we just brute-force disable them all.)
644 * 1) We must disable this particular wake GPE so it won't fire again
645 * 2) We want to disable all wake GPEs, since we are now awake
646 */
647 (void)acpi_hw_disable_all_gpes();
648 }
649
650 /* 639 /*
651 * Dispatch the GPE to either an installed handler, or the control method 640 * Dispatch the GPE to either an installed handler, or the control method
652 * associated with this GPE (_Lxx or _Exx). If a handler exists, we invoke 641 * associated with this GPE (_Lxx or _Exx). If a handler exists, we invoke
diff --git a/drivers/acpi/events/evmisc.c b/drivers/acpi/events/evmisc.c
index 1b784ffe54c3..d572700197f3 100644
--- a/drivers/acpi/events/evmisc.c
+++ b/drivers/acpi/events/evmisc.c
@@ -196,12 +196,11 @@ acpi_ev_queue_notify_request(struct acpi_namespace_node * node,
196 notify_info->notify.value = (u16) notify_value; 196 notify_info->notify.value = (u16) notify_value;
197 notify_info->notify.handler_obj = handler_obj; 197 notify_info->notify.handler_obj = handler_obj;
198 198
199 status = 199 acpi_ex_relinquish_interpreter();
200 acpi_os_execute(OSL_NOTIFY_HANDLER, acpi_ev_notify_dispatch, 200
201 notify_info); 201 acpi_ev_notify_dispatch(notify_info);
202 if (ACPI_FAILURE(status)) { 202
203 acpi_ut_delete_generic_state(notify_info); 203 acpi_ex_reacquire_interpreter();
204 }
205 } 204 }
206 205
207 if (!handler_obj) { 206 if (!handler_obj) {
diff --git a/drivers/acpi/executer/exdump.c b/drivers/acpi/executer/exdump.c
index 68d283fd60e7..1a73c14df2c5 100644
--- a/drivers/acpi/executer/exdump.c
+++ b/drivers/acpi/executer/exdump.c
@@ -134,7 +134,7 @@ static struct acpi_exdump_info acpi_ex_dump_method[8] = {
134static struct acpi_exdump_info acpi_ex_dump_mutex[5] = { 134static struct acpi_exdump_info acpi_ex_dump_mutex[5] = {
135 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_mutex), NULL}, 135 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_mutex), NULL},
136 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(mutex.sync_level), "Sync Level"}, 136 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(mutex.sync_level), "Sync Level"},
137 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(mutex.owner_thread), "Owner Thread"}, 137 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(mutex.owner_thread_id), "Owner Thread"},
138 {ACPI_EXD_UINT16, ACPI_EXD_OFFSET(mutex.acquisition_depth), 138 {ACPI_EXD_UINT16, ACPI_EXD_OFFSET(mutex.acquisition_depth),
139 "Acquire Depth"}, 139 "Acquire Depth"},
140 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(mutex.os_mutex), "OsMutex"} 140 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(mutex.os_mutex), "OsMutex"}
diff --git a/drivers/acpi/executer/exmutex.c b/drivers/acpi/executer/exmutex.c
index 5101bad5baf8..4eb883bda6ae 100644
--- a/drivers/acpi/executer/exmutex.c
+++ b/drivers/acpi/executer/exmutex.c
@@ -66,10 +66,9 @@ acpi_ex_link_mutex(union acpi_operand_object *obj_desc,
66 * 66 *
67 ******************************************************************************/ 67 ******************************************************************************/
68 68
69void acpi_ex_unlink_mutex(union acpi_operand_object *obj_desc) 69void acpi_ex_unlink_mutex(union acpi_operand_object *obj_desc,
70 struct acpi_thread_state *thread)
70{ 71{
71 struct acpi_thread_state *thread = obj_desc->mutex.owner_thread;
72
73 if (!thread) { 72 if (!thread) {
74 return; 73 return;
75 } 74 }
@@ -174,16 +173,13 @@ acpi_ex_acquire_mutex(union acpi_operand_object *time_desc,
174 173
175 /* Support for multiple acquires by the owning thread */ 174 /* Support for multiple acquires by the owning thread */
176 175
177 if (obj_desc->mutex.owner_thread) { 176 if (obj_desc->mutex.owner_thread_id == acpi_os_get_thread_id()) {
178 if (obj_desc->mutex.owner_thread->thread_id == 177 /*
179 walk_state->thread->thread_id) { 178 * The mutex is already owned by this thread, just increment the
180 /* 179 * acquisition depth
181 * The mutex is already owned by this thread, just increment the 180 */
182 * acquisition depth 181 obj_desc->mutex.acquisition_depth++;
183 */ 182 return_ACPI_STATUS(AE_OK);
184 obj_desc->mutex.acquisition_depth++;
185 return_ACPI_STATUS(AE_OK);
186 }
187 } 183 }
188 184
189 /* Acquire the mutex, wait if necessary. Special case for Global Lock */ 185 /* Acquire the mutex, wait if necessary. Special case for Global Lock */
@@ -206,7 +202,7 @@ acpi_ex_acquire_mutex(union acpi_operand_object *time_desc,
206 202
207 /* Have the mutex: update mutex and walk info and save the sync_level */ 203 /* Have the mutex: update mutex and walk info and save the sync_level */
208 204
209 obj_desc->mutex.owner_thread = walk_state->thread; 205 obj_desc->mutex.owner_thread_id = acpi_os_get_thread_id();
210 obj_desc->mutex.acquisition_depth = 1; 206 obj_desc->mutex.acquisition_depth = 1;
211 obj_desc->mutex.original_sync_level = 207 obj_desc->mutex.original_sync_level =
212 walk_state->thread->current_sync_level; 208 walk_state->thread->current_sync_level;
@@ -246,7 +242,7 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
246 242
247 /* The mutex must have been previously acquired in order to release it */ 243 /* The mutex must have been previously acquired in order to release it */
248 244
249 if (!obj_desc->mutex.owner_thread) { 245 if (!obj_desc->mutex.owner_thread_id) {
250 ACPI_ERROR((AE_INFO, 246 ACPI_ERROR((AE_INFO,
251 "Cannot release Mutex [%4.4s], not acquired", 247 "Cannot release Mutex [%4.4s], not acquired",
252 acpi_ut_get_node_name(obj_desc->mutex.node))); 248 acpi_ut_get_node_name(obj_desc->mutex.node)));
@@ -266,14 +262,14 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
266 * The Mutex is owned, but this thread must be the owner. 262 * The Mutex is owned, but this thread must be the owner.
267 * Special case for Global Lock, any thread can release 263 * Special case for Global Lock, any thread can release
268 */ 264 */
269 if ((obj_desc->mutex.owner_thread->thread_id != 265 if ((obj_desc->mutex.owner_thread_id !=
270 walk_state->thread->thread_id) 266 walk_state->thread->thread_id)
271 && (obj_desc->mutex.os_mutex != acpi_gbl_global_lock_mutex)) { 267 && (obj_desc->mutex.os_mutex != acpi_gbl_global_lock_mutex)) {
272 ACPI_ERROR((AE_INFO, 268 ACPI_ERROR((AE_INFO,
273 "Thread %lX cannot release Mutex [%4.4s] acquired by thread %lX", 269 "Thread %lX cannot release Mutex [%4.4s] acquired by thread %lX",
274 (unsigned long)walk_state->thread->thread_id, 270 (unsigned long)walk_state->thread->thread_id,
275 acpi_ut_get_node_name(obj_desc->mutex.node), 271 acpi_ut_get_node_name(obj_desc->mutex.node),
276 (unsigned long)obj_desc->mutex.owner_thread->thread_id)); 272 (unsigned long)obj_desc->mutex.owner_thread_id));
277 return_ACPI_STATUS(AE_AML_NOT_OWNER); 273 return_ACPI_STATUS(AE_AML_NOT_OWNER);
278 } 274 }
279 275
@@ -300,7 +296,7 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
300 296
301 /* Unlink the mutex from the owner's list */ 297 /* Unlink the mutex from the owner's list */
302 298
303 acpi_ex_unlink_mutex(obj_desc); 299 acpi_ex_unlink_mutex(obj_desc, walk_state->thread);
304 300
305 /* Release the mutex, special case for Global Lock */ 301 /* Release the mutex, special case for Global Lock */
306 302
@@ -312,7 +308,7 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
312 308
313 /* Update the mutex and restore sync_level */ 309 /* Update the mutex and restore sync_level */
314 310
315 obj_desc->mutex.owner_thread = NULL; 311 obj_desc->mutex.owner_thread_id = ACPI_MUTEX_NOT_ACQUIRED;
316 walk_state->thread->current_sync_level = 312 walk_state->thread->current_sync_level =
317 obj_desc->mutex.original_sync_level; 313 obj_desc->mutex.original_sync_level;
318 314
@@ -367,7 +363,7 @@ void acpi_ex_release_all_mutexes(struct acpi_thread_state *thread)
367 363
368 /* Mark mutex unowned */ 364 /* Mark mutex unowned */
369 365
370 obj_desc->mutex.owner_thread = NULL; 366 obj_desc->mutex.owner_thread_id = ACPI_MUTEX_NOT_ACQUIRED;
371 367
372 /* Update Thread sync_level (Last mutex is the important one) */ 368 /* Update Thread sync_level (Last mutex is the important one) */
373 369
diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c
index af22fdf73413..ec655c539492 100644
--- a/drivers/acpi/fan.c
+++ b/drivers/acpi/fan.c
@@ -36,14 +36,13 @@
36 36
37#define ACPI_FAN_COMPONENT 0x00200000 37#define ACPI_FAN_COMPONENT 0x00200000
38#define ACPI_FAN_CLASS "fan" 38#define ACPI_FAN_CLASS "fan"
39#define ACPI_FAN_DRIVER_NAME "ACPI Fan Driver"
40#define ACPI_FAN_FILE_STATE "state" 39#define ACPI_FAN_FILE_STATE "state"
41 40
42#define _COMPONENT ACPI_FAN_COMPONENT 41#define _COMPONENT ACPI_FAN_COMPONENT
43ACPI_MODULE_NAME("acpi_fan") 42ACPI_MODULE_NAME("fan");
44 43
45 MODULE_AUTHOR("Paul Diefenbaugh"); 44MODULE_AUTHOR("Paul Diefenbaugh");
46MODULE_DESCRIPTION(ACPI_FAN_DRIVER_NAME); 45MODULE_DESCRIPTION("ACPI Fan Driver");
47MODULE_LICENSE("GPL"); 46MODULE_LICENSE("GPL");
48 47
49static int acpi_fan_add(struct acpi_device *device); 48static int acpi_fan_add(struct acpi_device *device);
@@ -52,7 +51,7 @@ static int acpi_fan_suspend(struct acpi_device *device, pm_message_t state);
52static int acpi_fan_resume(struct acpi_device *device); 51static int acpi_fan_resume(struct acpi_device *device);
53 52
54static struct acpi_driver acpi_fan_driver = { 53static struct acpi_driver acpi_fan_driver = {
55 .name = ACPI_FAN_DRIVER_NAME, 54 .name = "fan",
56 .class = ACPI_FAN_CLASS, 55 .class = ACPI_FAN_CLASS,
57 .ids = "PNP0C0B", 56 .ids = "PNP0C0B",
58 .ops = { 57 .ops = {
diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c
index 7b6c9ff9bebe..4334c208841a 100644
--- a/drivers/acpi/glue.c
+++ b/drivers/acpi/glue.c
@@ -241,3 +241,65 @@ static int __init init_acpi_device_notify(void)
241} 241}
242 242
243arch_initcall(init_acpi_device_notify); 243arch_initcall(init_acpi_device_notify);
244
245
246#if defined(CONFIG_RTC_DRV_CMOS) || defined(CONFIG_RTC_DRV_CMOS_MODULE)
247
248/* Every ACPI platform has a mc146818 compatible "cmos rtc". Here we find
249 * its device node and pass extra config data. This helps its driver use
250 * capabilities that the now-obsolete mc146818 didn't have, and informs it
251 * that this board's RTC is wakeup-capable (per ACPI spec).
252 */
253#include <linux/mc146818rtc.h>
254
255static struct cmos_rtc_board_info rtc_info;
256
257
258/* PNP devices are registered in a subsys_initcall();
259 * ACPI specifies the PNP IDs to use.
260 */
261#include <linux/pnp.h>
262
263static int __init pnp_match(struct device *dev, void *data)
264{
265 static const char *ids[] = { "PNP0b00", "PNP0b01", "PNP0b02", };
266 struct pnp_dev *pnp = to_pnp_dev(dev);
267 int i;
268
269 for (i = 0; i < ARRAY_SIZE(ids); i++) {
270 if (compare_pnp_id(pnp->id, ids[i]) != 0)
271 return 1;
272 }
273 return 0;
274}
275
276static struct device *__init get_rtc_dev(void)
277{
278 return bus_find_device(&pnp_bus_type, NULL, NULL, pnp_match);
279}
280
281static int __init acpi_rtc_init(void)
282{
283 struct device *dev = get_rtc_dev();
284
285 if (dev) {
286 rtc_info.rtc_day_alarm = acpi_gbl_FADT.day_alarm;
287 rtc_info.rtc_mon_alarm = acpi_gbl_FADT.month_alarm;
288 rtc_info.rtc_century = acpi_gbl_FADT.century;
289
290 /* NOTE: acpi_gbl_FADT->rtcs4 is NOT currently useful */
291
292 dev->platform_data = &rtc_info;
293
294 /* RTC always wakes from S1/S2/S3, and often S4/STD */
295 device_init_wakeup(dev, 1);
296
297 put_device(dev);
298 } else
299 pr_debug("ACPI: RTC unavailable?\n");
300 return 0;
301}
302/* do this between RTC subsys_initcall() and rtc_cmos driver_initcall() */
303fs_initcall(acpi_rtc_init);
304
305#endif
diff --git a/drivers/acpi/hardware/hwsleep.c b/drivers/acpi/hardware/hwsleep.c
index 57901ca3ade9..8fa93125fd4c 100644
--- a/drivers/acpi/hardware/hwsleep.c
+++ b/drivers/acpi/hardware/hwsleep.c
@@ -235,6 +235,14 @@ acpi_status acpi_enter_sleep_state_prep(u8 sleep_state)
235 "While executing method _SST")); 235 "While executing method _SST"));
236 } 236 }
237 237
238 /*
239 * 1) Disable/Clear all GPEs
240 */
241 status = acpi_hw_disable_all_gpes();
242 if (ACPI_FAILURE(status)) {
243 return_ACPI_STATUS(status);
244 }
245
238 return_ACPI_STATUS(AE_OK); 246 return_ACPI_STATUS(AE_OK);
239} 247}
240 248
@@ -290,13 +298,8 @@ acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state)
290 } 298 }
291 299
292 /* 300 /*
293 * 1) Disable/Clear all GPEs
294 * 2) Enable all wakeup GPEs 301 * 2) Enable all wakeup GPEs
295 */ 302 */
296 status = acpi_hw_disable_all_gpes();
297 if (ACPI_FAILURE(status)) {
298 return_ACPI_STATUS(status);
299 }
300 acpi_gbl_system_awake_and_running = FALSE; 303 acpi_gbl_system_awake_and_running = FALSE;
301 304
302 status = acpi_hw_enable_all_wakeup_gpes(); 305 status = acpi_hw_enable_all_wakeup_gpes();
diff --git a/drivers/acpi/hotkey.c b/drivers/acpi/hotkey.c
deleted file mode 100644
index 8edfb92f7ede..000000000000
--- a/drivers/acpi/hotkey.c
+++ /dev/null
@@ -1,1042 +0,0 @@
1/*
2 * hotkey.c - ACPI Hotkey Driver ($Revision: 0.2 $)
3 *
4 * Copyright (C) 2004 Luming Yu <luming.yu@intel.com>
5 *
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or (at
11 * your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 */
24#include <linux/kernel.h>
25#include <linux/module.h>
26#include <linux/init.h>
27#include <linux/types.h>
28#include <linux/proc_fs.h>
29#include <linux/sched.h>
30#include <linux/kmod.h>
31#include <linux/seq_file.h>
32#include <acpi/acpi_drivers.h>
33#include <acpi/acpi_bus.h>
34#include <asm/uaccess.h>
35
36#define HOTKEY_ACPI_VERSION "0.1"
37
38#define HOTKEY_PROC "hotkey"
39#define HOTKEY_EV_CONFIG "event_config"
40#define HOTKEY_PL_CONFIG "poll_config"
41#define HOTKEY_ACTION "action"
42#define HOTKEY_INFO "info"
43
44#define ACPI_HOTK_NAME "Generic Hotkey Driver"
45#define ACPI_HOTK_CLASS "Hotkey"
46#define ACPI_HOTK_DEVICE_NAME "Hotkey"
47#define ACPI_HOTK_HID "Unknown?"
48#define ACPI_HOTKEY_COMPONENT 0x20000000
49
50#define ACPI_HOTKEY_EVENT 0x1
51#define ACPI_HOTKEY_POLLING 0x2
52#define ACPI_UNDEFINED_EVENT 0xf
53
54#define RESULT_STR_LEN 80
55
56#define ACTION_METHOD 0
57#define POLL_METHOD 1
58
59#define IS_EVENT(e) ((e) <= 10000 && (e) >0)
60#define IS_POLL(e) ((e) > 10000)
61#define IS_OTHERS(e) ((e)<=0 || (e)>=20000)
62#define _COMPONENT ACPI_HOTKEY_COMPONENT
63ACPI_MODULE_NAME("acpi_hotkey")
64
65 MODULE_AUTHOR("luming.yu@intel.com");
66MODULE_DESCRIPTION(ACPI_HOTK_NAME);
67MODULE_LICENSE("GPL");
68
69/* standardized internal hotkey number/event */
70enum {
71 /* Video Extension event */
72 HK_EVENT_CYCLE_OUTPUT_DEVICE = 0x80,
73 HK_EVENT_OUTPUT_DEVICE_STATUS_CHANGE,
74 HK_EVENT_CYCLE_DISPLAY_OUTPUT,
75 HK_EVENT_NEXT_DISPLAY_OUTPUT,
76 HK_EVENT_PREVIOUS_DISPLAY_OUTPUT,
77 HK_EVENT_CYCLE_BRIGHTNESS,
78 HK_EVENT_INCREASE_BRIGHTNESS,
79 HK_EVENT_DECREASE_BRIGHTNESS,
80 HK_EVENT_ZERO_BRIGHTNESS,
81 HK_EVENT_DISPLAY_DEVICE_OFF,
82
83 /* Snd Card event */
84 HK_EVENT_VOLUME_MUTE,
85 HK_EVENT_VOLUME_INCLREASE,
86 HK_EVENT_VOLUME_DECREASE,
87
88 /* running state control */
89 HK_EVENT_ENTERRING_S3,
90 HK_EVENT_ENTERRING_S4,
91 HK_EVENT_ENTERRING_S5,
92};
93
94enum conf_entry_enum {
95 bus_handle = 0,
96 bus_method = 1,
97 action_handle = 2,
98 method = 3,
99 LAST_CONF_ENTRY
100};
101
102/* procdir we use */
103static struct proc_dir_entry *hotkey_proc_dir;
104static struct proc_dir_entry *hotkey_config;
105static struct proc_dir_entry *hotkey_poll_config;
106static struct proc_dir_entry *hotkey_action;
107static struct proc_dir_entry *hotkey_info;
108
109/* linkage for all type of hotkey */
110struct acpi_hotkey_link {
111 struct list_head entries;
112 int hotkey_type; /* event or polling based hotkey */
113 int hotkey_standard_num; /* standardized hotkey(event) number */
114};
115
116/* event based hotkey */
117struct acpi_event_hotkey {
118 struct acpi_hotkey_link hotkey_link;
119 int flag;
120 acpi_handle bus_handle; /* bus to install notify handler */
121 int external_hotkey_num; /* external hotkey/event number */
122 acpi_handle action_handle; /* acpi handle attached aml action method */
123 char *action_method; /* action method */
124};
125
126/*
127 * There are two ways to poll status
128 * 1. directy call read_xxx method, without any arguments passed in
129 * 2. call write_xxx method, with arguments passed in, you need
130 * the result is saved in acpi_polling_hotkey.poll_result.
131 * anthoer read command through polling interface.
132 *
133 */
134
135/* polling based hotkey */
136struct acpi_polling_hotkey {
137 struct acpi_hotkey_link hotkey_link;
138 int flag;
139 acpi_handle poll_handle; /* acpi handle attached polling method */
140 char *poll_method; /* poll method */
141 acpi_handle action_handle; /* acpi handle attached action method */
142 char *action_method; /* action method */
143 union acpi_object *poll_result; /* polling_result */
144 struct proc_dir_entry *proc;
145};
146
147/* hotkey object union */
148union acpi_hotkey {
149 struct list_head entries;
150 struct acpi_hotkey_link link;
151 struct acpi_event_hotkey event_hotkey;
152 struct acpi_polling_hotkey poll_hotkey;
153};
154
155/* hotkey object list */
156struct acpi_hotkey_list {
157 struct list_head *entries;
158 int count;
159};
160
161static int auto_hotkey_add(struct acpi_device *device);
162static int auto_hotkey_remove(struct acpi_device *device, int type);
163
164static struct acpi_driver hotkey_driver = {
165 .name = ACPI_HOTK_NAME,
166 .class = ACPI_HOTK_CLASS,
167 .ids = ACPI_HOTK_HID,
168 .ops = {
169 .add = auto_hotkey_add,
170 .remove = auto_hotkey_remove,
171 },
172};
173
174static void free_hotkey_device(union acpi_hotkey *key);
175static void free_hotkey_buffer(union acpi_hotkey *key);
176static void free_poll_hotkey_buffer(union acpi_hotkey *key);
177static int hotkey_open_config(struct inode *inode, struct file *file);
178static int hotkey_poll_open_config(struct inode *inode, struct file *file);
179static ssize_t hotkey_write_config(struct file *file,
180 const char __user * buffer,
181 size_t count, loff_t * data);
182static int hotkey_info_open_fs(struct inode *inode, struct file *file);
183static int hotkey_action_open_fs(struct inode *inode, struct file *file);
184static ssize_t hotkey_execute_aml_method(struct file *file,
185 const char __user * buffer,
186 size_t count, loff_t * data);
187static int hotkey_config_seq_show(struct seq_file *seq, void *offset);
188static int hotkey_poll_config_seq_show(struct seq_file *seq, void *offset);
189static int hotkey_polling_open_fs(struct inode *inode, struct file *file);
190static union acpi_hotkey *get_hotkey_by_event(struct
191 acpi_hotkey_list
192 *hotkey_list, int event);
193
194/* event based config */
195static const struct file_operations hotkey_config_fops = {
196 .open = hotkey_open_config,
197 .read = seq_read,
198 .write = hotkey_write_config,
199 .llseek = seq_lseek,
200 .release = single_release,
201};
202
203/* polling based config */
204static const struct file_operations hotkey_poll_config_fops = {
205 .open = hotkey_poll_open_config,
206 .read = seq_read,
207 .write = hotkey_write_config,
208 .llseek = seq_lseek,
209 .release = single_release,
210};
211
212/* hotkey driver info */
213static const struct file_operations hotkey_info_fops = {
214 .open = hotkey_info_open_fs,
215 .read = seq_read,
216 .llseek = seq_lseek,
217 .release = single_release,
218};
219
220/* action */
221static const struct file_operations hotkey_action_fops = {
222 .open = hotkey_action_open_fs,
223 .read = seq_read,
224 .write = hotkey_execute_aml_method,
225 .llseek = seq_lseek,
226 .release = single_release,
227};
228
229/* polling results */
230static const struct file_operations hotkey_polling_fops = {
231 .open = hotkey_polling_open_fs,
232 .read = seq_read,
233 .llseek = seq_lseek,
234 .release = single_release,
235};
236
237struct acpi_hotkey_list global_hotkey_list; /* link all ev or pl hotkey */
238struct list_head hotkey_entries; /* head of the list of hotkey_list */
239
240static int hotkey_info_seq_show(struct seq_file *seq, void *offset)
241{
242
243 seq_printf(seq, "Hotkey generic driver ver: %s\n", HOTKEY_ACPI_VERSION);
244
245 return 0;
246}
247
248static int hotkey_info_open_fs(struct inode *inode, struct file *file)
249{
250 return single_open(file, hotkey_info_seq_show, PDE(inode)->data);
251}
252
253static char *format_result(union acpi_object *object)
254{
255 char *buf;
256
257 buf = kzalloc(RESULT_STR_LEN, GFP_KERNEL);
258 if (!buf)
259 return NULL;
260 /* Now, just support integer type */
261 if (object->type == ACPI_TYPE_INTEGER)
262 sprintf(buf, "%d\n", (u32) object->integer.value);
263 return buf;
264}
265
266static int hotkey_polling_seq_show(struct seq_file *seq, void *offset)
267{
268 struct acpi_polling_hotkey *poll_hotkey = seq->private;
269 char *buf;
270
271
272 if (poll_hotkey->poll_result) {
273 buf = format_result(poll_hotkey->poll_result);
274 if (buf)
275 seq_printf(seq, "%s", buf);
276 kfree(buf);
277 }
278 return 0;
279}
280
281static int hotkey_polling_open_fs(struct inode *inode, struct file *file)
282{
283 return single_open(file, hotkey_polling_seq_show, PDE(inode)->data);
284}
285
286static int hotkey_action_open_fs(struct inode *inode, struct file *file)
287{
288 return single_open(file, hotkey_info_seq_show, PDE(inode)->data);
289}
290
291/* Mapping external hotkey number to standardized hotkey event num */
292static int hotkey_get_internal_event(int event, struct acpi_hotkey_list *list)
293{
294 struct list_head *entries;
295 int val = -1;
296
297
298 list_for_each(entries, list->entries) {
299 union acpi_hotkey *key =
300 container_of(entries, union acpi_hotkey, entries);
301 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT
302 && key->event_hotkey.external_hotkey_num == event) {
303 val = key->link.hotkey_standard_num;
304 break;
305 }
306 }
307
308 return val;
309}
310
311static void
312acpi_hotkey_notify_handler(acpi_handle handle, u32 event, void *data)
313{
314 struct acpi_device *device = NULL;
315 u32 internal_event;
316
317
318 if (acpi_bus_get_device(handle, &device))
319 return;
320
321 internal_event = hotkey_get_internal_event(event, &global_hotkey_list);
322 acpi_bus_generate_event(device, internal_event, 0);
323
324 return;
325}
326
327/* Need to invent automatically hotkey add method */
328static int auto_hotkey_add(struct acpi_device *device)
329{
330 /* Implement me */
331 return 0;
332}
333
334/* Need to invent automatically hotkey remove method */
335static int auto_hotkey_remove(struct acpi_device *device, int type)
336{
337 /* Implement me */
338 return 0;
339}
340
341/* Create a proc file for each polling method */
342static int create_polling_proc(union acpi_hotkey *device)
343{
344 struct proc_dir_entry *proc;
345 char proc_name[80];
346 mode_t mode;
347
348 mode = S_IFREG | S_IRUGO | S_IWUGO;
349
350 sprintf(proc_name, "%d", device->link.hotkey_standard_num);
351 /*
352 strcat(proc_name, device->poll_hotkey.poll_method);
353 */
354 proc = create_proc_entry(proc_name, mode, hotkey_proc_dir);
355
356 if (!proc) {
357 return -ENODEV;
358 } else {
359 proc->proc_fops = &hotkey_polling_fops;
360 proc->owner = THIS_MODULE;
361 proc->data = device;
362 proc->uid = 0;
363 proc->gid = 0;
364 device->poll_hotkey.proc = proc;
365 }
366 return 0;
367}
368
369static int hotkey_add(union acpi_hotkey *device)
370{
371 int status = 0;
372 struct acpi_device *dev = NULL;
373
374
375 if (device->link.hotkey_type == ACPI_HOTKEY_EVENT) {
376 acpi_bus_get_device(device->event_hotkey.bus_handle, &dev);
377 status = acpi_install_notify_handler(dev->handle,
378 ACPI_DEVICE_NOTIFY,
379 acpi_hotkey_notify_handler,
380 dev);
381 } else /* Add polling hotkey */
382 create_polling_proc(device);
383
384 global_hotkey_list.count++;
385
386 list_add_tail(&device->link.entries, global_hotkey_list.entries);
387
388 return status;
389}
390
391static int hotkey_remove(union acpi_hotkey *device)
392{
393 struct list_head *entries, *next;
394
395
396 list_for_each_safe(entries, next, global_hotkey_list.entries) {
397 union acpi_hotkey *key =
398 container_of(entries, union acpi_hotkey, entries);
399 if (key->link.hotkey_standard_num ==
400 device->link.hotkey_standard_num) {
401 list_del(&key->link.entries);
402 free_hotkey_device(key);
403 global_hotkey_list.count--;
404 break;
405 }
406 }
407 kfree(device);
408 return 0;
409}
410
411static int hotkey_update(union acpi_hotkey *key)
412{
413 struct list_head *entries;
414
415
416 list_for_each(entries, global_hotkey_list.entries) {
417 union acpi_hotkey *tmp =
418 container_of(entries, union acpi_hotkey, entries);
419 if (tmp->link.hotkey_standard_num ==
420 key->link.hotkey_standard_num) {
421 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT) {
422 free_hotkey_buffer(tmp);
423 tmp->event_hotkey.bus_handle =
424 key->event_hotkey.bus_handle;
425 tmp->event_hotkey.external_hotkey_num =
426 key->event_hotkey.external_hotkey_num;
427 tmp->event_hotkey.action_handle =
428 key->event_hotkey.action_handle;
429 tmp->event_hotkey.action_method =
430 key->event_hotkey.action_method;
431 kfree(key);
432 } else {
433 /*
434 char proc_name[80];
435
436 sprintf(proc_name, "%d", tmp->link.hotkey_standard_num);
437 strcat(proc_name, tmp->poll_hotkey.poll_method);
438 remove_proc_entry(proc_name,hotkey_proc_dir);
439 */
440 free_poll_hotkey_buffer(tmp);
441 tmp->poll_hotkey.poll_handle =
442 key->poll_hotkey.poll_handle;
443 tmp->poll_hotkey.poll_method =
444 key->poll_hotkey.poll_method;
445 tmp->poll_hotkey.action_handle =
446 key->poll_hotkey.action_handle;
447 tmp->poll_hotkey.action_method =
448 key->poll_hotkey.action_method;
449 tmp->poll_hotkey.poll_result =
450 key->poll_hotkey.poll_result;
451 /*
452 create_polling_proc(tmp);
453 */
454 kfree(key);
455 }
456 return 0;
457 break;
458 }
459 }
460
461 return -ENODEV;
462}
463
464static void free_hotkey_device(union acpi_hotkey *key)
465{
466 struct acpi_device *dev;
467
468
469 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT) {
470 acpi_bus_get_device(key->event_hotkey.bus_handle, &dev);
471 if (dev->handle)
472 acpi_remove_notify_handler(dev->handle,
473 ACPI_DEVICE_NOTIFY,
474 acpi_hotkey_notify_handler);
475 free_hotkey_buffer(key);
476 } else {
477 char proc_name[80];
478
479 sprintf(proc_name, "%d", key->link.hotkey_standard_num);
480 /*
481 strcat(proc_name, key->poll_hotkey.poll_method);
482 */
483 remove_proc_entry(proc_name, hotkey_proc_dir);
484 free_poll_hotkey_buffer(key);
485 }
486 kfree(key);
487 return;
488}
489
490static void free_hotkey_buffer(union acpi_hotkey *key)
491{
492 /* key would never be null, action method could be */
493 kfree(key->event_hotkey.action_method);
494}
495
496static void free_poll_hotkey_buffer(union acpi_hotkey *key)
497{
498 /* key would never be null, others could be*/
499 kfree(key->poll_hotkey.action_method);
500 kfree(key->poll_hotkey.poll_method);
501 kfree(key->poll_hotkey.poll_result);
502}
503static int
504init_hotkey_device(union acpi_hotkey *key, char **config_entry,
505 int std_num, int external_num)
506{
507 acpi_handle tmp_handle;
508 acpi_status status = AE_OK;
509
510 if (std_num < 0 || IS_POLL(std_num) || !key)
511 goto do_fail;
512
513 if (!config_entry[bus_handle] || !config_entry[action_handle]
514 || !config_entry[method])
515 goto do_fail;
516
517 key->link.hotkey_type = ACPI_HOTKEY_EVENT;
518 key->link.hotkey_standard_num = std_num;
519 key->event_hotkey.flag = 0;
520 key->event_hotkey.action_method = config_entry[method];
521
522 status = acpi_get_handle(NULL, config_entry[bus_handle],
523 &(key->event_hotkey.bus_handle));
524 if (ACPI_FAILURE(status))
525 goto do_fail_zero;
526 key->event_hotkey.external_hotkey_num = external_num;
527 status = acpi_get_handle(NULL, config_entry[action_handle],
528 &(key->event_hotkey.action_handle));
529 if (ACPI_FAILURE(status))
530 goto do_fail_zero;
531 status = acpi_get_handle(key->event_hotkey.action_handle,
532 config_entry[method], &tmp_handle);
533 if (ACPI_FAILURE(status))
534 goto do_fail_zero;
535 return AE_OK;
536do_fail_zero:
537 key->event_hotkey.action_method = NULL;
538do_fail:
539 return -ENODEV;
540}
541
542static int
543init_poll_hotkey_device(union acpi_hotkey *key, char **config_entry,
544 int std_num)
545{
546 acpi_status status = AE_OK;
547 acpi_handle tmp_handle;
548
549 if (std_num < 0 || IS_EVENT(std_num) || !key)
550 goto do_fail;
551 if (!config_entry[bus_handle] ||!config_entry[bus_method] ||
552 !config_entry[action_handle] || !config_entry[method])
553 goto do_fail;
554
555 key->link.hotkey_type = ACPI_HOTKEY_POLLING;
556 key->link.hotkey_standard_num = std_num;
557 key->poll_hotkey.flag = 0;
558 key->poll_hotkey.poll_method = config_entry[bus_method];
559 key->poll_hotkey.action_method = config_entry[method];
560
561 status = acpi_get_handle(NULL, config_entry[bus_handle],
562 &(key->poll_hotkey.poll_handle));
563 if (ACPI_FAILURE(status))
564 goto do_fail_zero;
565 status = acpi_get_handle(key->poll_hotkey.poll_handle,
566 config_entry[bus_method], &tmp_handle);
567 if (ACPI_FAILURE(status))
568 goto do_fail_zero;
569 status =
570 acpi_get_handle(NULL, config_entry[action_handle],
571 &(key->poll_hotkey.action_handle));
572 if (ACPI_FAILURE(status))
573 goto do_fail_zero;
574 status = acpi_get_handle(key->poll_hotkey.action_handle,
575 config_entry[method], &tmp_handle);
576 if (ACPI_FAILURE(status))
577 goto do_fail_zero;
578 key->poll_hotkey.poll_result =
579 kmalloc(sizeof(union acpi_object), GFP_KERNEL);
580 if (!key->poll_hotkey.poll_result)
581 goto do_fail_zero;
582 return AE_OK;
583
584do_fail_zero:
585 key->poll_hotkey.poll_method = NULL;
586 key->poll_hotkey.action_method = NULL;
587do_fail:
588 return -ENODEV;
589}
590
591static int hotkey_open_config(struct inode *inode, struct file *file)
592{
593 return (single_open
594 (file, hotkey_config_seq_show, PDE(inode)->data));
595}
596
597static int hotkey_poll_open_config(struct inode *inode, struct file *file)
598{
599 return (single_open
600 (file, hotkey_poll_config_seq_show, PDE(inode)->data));
601}
602
603static int hotkey_config_seq_show(struct seq_file *seq, void *offset)
604{
605 struct acpi_hotkey_list *hotkey_list = &global_hotkey_list;
606 struct list_head *entries;
607 char bus_name[ACPI_PATHNAME_MAX] = { 0 };
608 char action_name[ACPI_PATHNAME_MAX] = { 0 };
609 struct acpi_buffer bus = { ACPI_PATHNAME_MAX, bus_name };
610 struct acpi_buffer act = { ACPI_PATHNAME_MAX, action_name };
611
612
613 list_for_each(entries, hotkey_list->entries) {
614 union acpi_hotkey *key =
615 container_of(entries, union acpi_hotkey, entries);
616 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT) {
617 acpi_get_name(key->event_hotkey.bus_handle,
618 ACPI_NAME_TYPE_MAX, &bus);
619 acpi_get_name(key->event_hotkey.action_handle,
620 ACPI_NAME_TYPE_MAX, &act);
621 seq_printf(seq, "%s:%s:%s:%d:%d\n", bus_name,
622 action_name,
623 key->event_hotkey.action_method,
624 key->link.hotkey_standard_num,
625 key->event_hotkey.external_hotkey_num);
626 }
627 }
628 seq_puts(seq, "\n");
629 return 0;
630}
631
632static int hotkey_poll_config_seq_show(struct seq_file *seq, void *offset)
633{
634 struct acpi_hotkey_list *hotkey_list = &global_hotkey_list;
635 struct list_head *entries;
636 char bus_name[ACPI_PATHNAME_MAX] = { 0 };
637 char action_name[ACPI_PATHNAME_MAX] = { 0 };
638 struct acpi_buffer bus = { ACPI_PATHNAME_MAX, bus_name };
639 struct acpi_buffer act = { ACPI_PATHNAME_MAX, action_name };
640
641
642 list_for_each(entries, hotkey_list->entries) {
643 union acpi_hotkey *key =
644 container_of(entries, union acpi_hotkey, entries);
645 if (key->link.hotkey_type == ACPI_HOTKEY_POLLING) {
646 acpi_get_name(key->poll_hotkey.poll_handle,
647 ACPI_NAME_TYPE_MAX, &bus);
648 acpi_get_name(key->poll_hotkey.action_handle,
649 ACPI_NAME_TYPE_MAX, &act);
650 seq_printf(seq, "%s:%s:%s:%s:%d\n", bus_name,
651 key->poll_hotkey.poll_method,
652 action_name,
653 key->poll_hotkey.action_method,
654 key->link.hotkey_standard_num);
655 }
656 }
657 seq_puts(seq, "\n");
658 return 0;
659}
660
661static int
662get_parms(char *config_record, int *cmd, char **config_entry,
663 int *internal_event_num, int *external_event_num)
664{
665/* the format of *config_record =
666 * "1:\d+:*" : "cmd:internal_event_num"
667 * "\d+:\w+:\w+:\w+:\w+:\d+:\d+" :
668 * "cmd:bus_handle:bus_method:action_handle:method:internal_event_num:external_event_num"
669 */
670 char *tmp, *tmp1, count;
671 int i;
672
673 sscanf(config_record, "%d", cmd);
674 if (*cmd == 1) {
675 if (sscanf(config_record, "%d:%d", cmd, internal_event_num) !=
676 2)
677 goto do_fail;
678 else
679 return (6);
680 }
681 tmp = strchr(config_record, ':');
682 if (!tmp)
683 goto do_fail;
684 tmp++;
685 for (i = 0; i < LAST_CONF_ENTRY; i++) {
686 tmp1 = strchr(tmp, ':');
687 if (!tmp1) {
688 goto do_fail;
689 }
690 count = tmp1 - tmp;
691 config_entry[i] = kzalloc(count + 1, GFP_KERNEL);
692 if (!config_entry[i])
693 goto handle_failure;
694 strncpy(config_entry[i], tmp, count);
695 tmp = tmp1 + 1;
696 }
697 if (sscanf(tmp, "%d:%d", internal_event_num, external_event_num) <= 0)
698 goto handle_failure;
699 if (!IS_OTHERS(*internal_event_num)) {
700 return 6;
701 }
702handle_failure:
703 while (i-- > 0)
704 kfree(config_entry[i]);
705do_fail:
706 return -1;
707}
708
709/* count is length for one input record */
710static ssize_t hotkey_write_config(struct file *file,
711 const char __user * buffer,
712 size_t count, loff_t * data)
713{
714 char *config_record = NULL;
715 char *config_entry[LAST_CONF_ENTRY];
716 int cmd, internal_event_num, external_event_num;
717 int ret = 0;
718 union acpi_hotkey *key = kzalloc(sizeof(union acpi_hotkey), GFP_KERNEL);
719
720 if (!key)
721 return -ENOMEM;
722
723 config_record = kzalloc(count + 1, GFP_KERNEL);
724 if (!config_record) {
725 kfree(key);
726 return -ENOMEM;
727 }
728
729 if (copy_from_user(config_record, buffer, count)) {
730 kfree(config_record);
731 kfree(key);
732 printk(KERN_ERR PREFIX "Invalid data\n");
733 return -EINVAL;
734 }
735 ret = get_parms(config_record, &cmd, config_entry,
736 &internal_event_num, &external_event_num);
737 kfree(config_record);
738 if (ret != 6) {
739 printk(KERN_ERR PREFIX "Invalid data format ret=%d\n", ret);
740 return -EINVAL;
741 }
742
743 if (cmd == 1) {
744 union acpi_hotkey *tmp = NULL;
745 tmp = get_hotkey_by_event(&global_hotkey_list,
746 internal_event_num);
747 if (!tmp)
748 printk(KERN_ERR PREFIX "Invalid key\n");
749 else
750 memcpy(key, tmp, sizeof(union acpi_hotkey));
751 goto cont_cmd;
752 }
753 if (IS_EVENT(internal_event_num)) {
754 if (init_hotkey_device(key, config_entry,
755 internal_event_num, external_event_num))
756 goto init_hotkey_fail;
757 } else {
758 if (init_poll_hotkey_device(key, config_entry,
759 internal_event_num))
760 goto init_poll_hotkey_fail;
761 }
762cont_cmd:
763 switch (cmd) {
764 case 0:
765 if (get_hotkey_by_event(&global_hotkey_list,
766 key->link.hotkey_standard_num))
767 goto fail_out;
768 else
769 hotkey_add(key);
770 break;
771 case 1:
772 hotkey_remove(key);
773 break;
774 case 2:
775 /* key is kfree()ed if matched*/
776 if (hotkey_update(key))
777 goto fail_out;
778 break;
779 default:
780 goto fail_out;
781 break;
782 }
783 return count;
784
785init_poll_hotkey_fail: /* failed init_poll_hotkey_device */
786 kfree(config_entry[bus_method]);
787 config_entry[bus_method] = NULL;
788init_hotkey_fail: /* failed init_hotkey_device */
789 kfree(config_entry[method]);
790fail_out:
791 kfree(config_entry[bus_handle]);
792 kfree(config_entry[action_handle]);
793 /* No double free since elements =NULL for error cases */
794 if (IS_EVENT(internal_event_num)) {
795 if (config_entry[bus_method])
796 kfree(config_entry[bus_method]);
797 free_hotkey_buffer(key); /* frees [method] */
798 } else
799 free_poll_hotkey_buffer(key); /* frees [bus_method]+[method] */
800 kfree(key);
801 printk(KERN_ERR PREFIX "invalid key\n");
802 return -EINVAL;
803}
804
805/*
806 * This function evaluates an ACPI method, given an int as parameter, the
807 * method is searched within the scope of the handle, can be NULL. The output
808 * of the method is written is output, which can also be NULL
809 *
810 * returns 1 if write is successful, 0 else.
811 */
812static int write_acpi_int(acpi_handle handle, const char *method, int val,
813 struct acpi_buffer *output)
814{
815 struct acpi_object_list params; /* list of input parameters (an int here) */
816 union acpi_object in_obj; /* the only param we use */
817 acpi_status status;
818
819 params.count = 1;
820 params.pointer = &in_obj;
821 in_obj.type = ACPI_TYPE_INTEGER;
822 in_obj.integer.value = val;
823
824 status = acpi_evaluate_object(handle, (char *)method, &params, output);
825
826 return (status == AE_OK);
827}
828
829static int read_acpi_int(acpi_handle handle, const char *method,
830 union acpi_object *val)
831{
832 struct acpi_buffer output;
833 union acpi_object out_obj;
834 acpi_status status;
835
836 output.length = sizeof(out_obj);
837 output.pointer = &out_obj;
838
839 status = acpi_evaluate_object(handle, (char *)method, NULL, &output);
840 if (val) {
841 val->integer.value = out_obj.integer.value;
842 val->type = out_obj.type;
843 } else
844 printk(KERN_ERR PREFIX "null val pointer\n");
845 return ((status == AE_OK)
846 && (out_obj.type == ACPI_TYPE_INTEGER));
847}
848
849static union acpi_hotkey *get_hotkey_by_event(struct
850 acpi_hotkey_list
851 *hotkey_list, int event)
852{
853 struct list_head *entries;
854
855 list_for_each(entries, hotkey_list->entries) {
856 union acpi_hotkey *key =
857 container_of(entries, union acpi_hotkey, entries);
858 if (key->link.hotkey_standard_num == event) {
859 return (key);
860 }
861 }
862 return (NULL);
863}
864
865/*
866 * user call AML method interface:
867 * Call convention:
868 * echo "event_num: arg type : value"
869 * example: echo "1:1:30" > /proc/acpi/action
870 * Just support 1 integer arg passing to AML method
871 */
872
873static ssize_t hotkey_execute_aml_method(struct file *file,
874 const char __user * buffer,
875 size_t count, loff_t * data)
876{
877 struct acpi_hotkey_list *hotkey_list = &global_hotkey_list;
878 char *arg;
879 int event, method_type, type, value;
880 union acpi_hotkey *key;
881
882
883 arg = kzalloc(count + 1, GFP_KERNEL);
884 if (!arg)
885 return -ENOMEM;
886
887 if (copy_from_user(arg, buffer, count)) {
888 kfree(arg);
889 printk(KERN_ERR PREFIX "Invalid argument 2\n");
890 return -EINVAL;
891 }
892
893 if (sscanf(arg, "%d:%d:%d:%d", &event, &method_type, &type, &value) !=
894 4) {
895 kfree(arg);
896 printk(KERN_ERR PREFIX "Invalid argument 3\n");
897 return -EINVAL;
898 }
899 kfree(arg);
900 if (type == ACPI_TYPE_INTEGER) {
901 key = get_hotkey_by_event(hotkey_list, event);
902 if (!key)
903 goto do_fail;
904 if (IS_EVENT(event))
905 write_acpi_int(key->event_hotkey.action_handle,
906 key->event_hotkey.action_method, value,
907 NULL);
908 else if (IS_POLL(event)) {
909 if (method_type == POLL_METHOD)
910 read_acpi_int(key->poll_hotkey.poll_handle,
911 key->poll_hotkey.poll_method,
912 key->poll_hotkey.poll_result);
913 else if (method_type == ACTION_METHOD)
914 write_acpi_int(key->poll_hotkey.action_handle,
915 key->poll_hotkey.action_method,
916 value, NULL);
917 else
918 goto do_fail;
919
920 }
921 } else {
922 printk(KERN_WARNING "Not supported\n");
923 return -EINVAL;
924 }
925 return count;
926 do_fail:
927 return -EINVAL;
928
929}
930
931static int __init hotkey_init(void)
932{
933 int result;
934 mode_t mode = S_IFREG | S_IRUGO | S_IWUGO;
935
936
937 if (acpi_disabled)
938 return -ENODEV;
939
940 if (acpi_specific_hotkey_enabled) {
941 printk("Using specific hotkey driver\n");
942 return -ENODEV;
943 }
944
945 hotkey_proc_dir = proc_mkdir(HOTKEY_PROC, acpi_root_dir);
946 if (!hotkey_proc_dir) {
947 return (-ENODEV);
948 }
949 hotkey_proc_dir->owner = THIS_MODULE;
950
951 hotkey_config =
952 create_proc_entry(HOTKEY_EV_CONFIG, mode, hotkey_proc_dir);
953 if (!hotkey_config) {
954 goto do_fail1;
955 } else {
956 hotkey_config->proc_fops = &hotkey_config_fops;
957 hotkey_config->data = &global_hotkey_list;
958 hotkey_config->owner = THIS_MODULE;
959 hotkey_config->uid = 0;
960 hotkey_config->gid = 0;
961 }
962
963 hotkey_poll_config =
964 create_proc_entry(HOTKEY_PL_CONFIG, mode, hotkey_proc_dir);
965 if (!hotkey_poll_config) {
966 goto do_fail2;
967 } else {
968 hotkey_poll_config->proc_fops = &hotkey_poll_config_fops;
969 hotkey_poll_config->data = &global_hotkey_list;
970 hotkey_poll_config->owner = THIS_MODULE;
971 hotkey_poll_config->uid = 0;
972 hotkey_poll_config->gid = 0;
973 }
974
975 hotkey_action = create_proc_entry(HOTKEY_ACTION, mode, hotkey_proc_dir);
976 if (!hotkey_action) {
977 goto do_fail3;
978 } else {
979 hotkey_action->proc_fops = &hotkey_action_fops;
980 hotkey_action->owner = THIS_MODULE;
981 hotkey_action->uid = 0;
982 hotkey_action->gid = 0;
983 }
984
985 hotkey_info = create_proc_entry(HOTKEY_INFO, mode, hotkey_proc_dir);
986 if (!hotkey_info) {
987 goto do_fail4;
988 } else {
989 hotkey_info->proc_fops = &hotkey_info_fops;
990 hotkey_info->owner = THIS_MODULE;
991 hotkey_info->uid = 0;
992 hotkey_info->gid = 0;
993 }
994
995 result = acpi_bus_register_driver(&hotkey_driver);
996 if (result < 0)
997 goto do_fail5;
998 global_hotkey_list.count = 0;
999 global_hotkey_list.entries = &hotkey_entries;
1000
1001 INIT_LIST_HEAD(&hotkey_entries);
1002
1003 return (0);
1004
1005 do_fail5:
1006 remove_proc_entry(HOTKEY_INFO, hotkey_proc_dir);
1007 do_fail4:
1008 remove_proc_entry(HOTKEY_ACTION, hotkey_proc_dir);
1009 do_fail3:
1010 remove_proc_entry(HOTKEY_PL_CONFIG, hotkey_proc_dir);
1011 do_fail2:
1012 remove_proc_entry(HOTKEY_EV_CONFIG, hotkey_proc_dir);
1013 do_fail1:
1014 remove_proc_entry(HOTKEY_PROC, acpi_root_dir);
1015 return (-ENODEV);
1016}
1017
1018static void __exit hotkey_exit(void)
1019{
1020 struct list_head *entries, *next;
1021
1022
1023 list_for_each_safe(entries, next, global_hotkey_list.entries) {
1024 union acpi_hotkey *key =
1025 container_of(entries, union acpi_hotkey, entries);
1026
1027 acpi_os_wait_events_complete(NULL);
1028 list_del(&key->link.entries);
1029 global_hotkey_list.count--;
1030 free_hotkey_device(key);
1031 }
1032 acpi_bus_unregister_driver(&hotkey_driver);
1033 remove_proc_entry(HOTKEY_EV_CONFIG, hotkey_proc_dir);
1034 remove_proc_entry(HOTKEY_PL_CONFIG, hotkey_proc_dir);
1035 remove_proc_entry(HOTKEY_ACTION, hotkey_proc_dir);
1036 remove_proc_entry(HOTKEY_INFO, hotkey_proc_dir);
1037 remove_proc_entry(HOTKEY_PROC, acpi_root_dir);
1038 return;
1039}
1040
1041module_init(hotkey_init);
1042module_exit(hotkey_exit);
diff --git a/drivers/acpi/i2c_ec.c b/drivers/acpi/i2c_ec.c
index 76ec8b63e69f..acab4a481897 100644
--- a/drivers/acpi/i2c_ec.c
+++ b/drivers/acpi/i2c_ec.c
@@ -27,18 +27,17 @@
27#define ACPI_EC_HC_COMPONENT 0x00080000 27#define ACPI_EC_HC_COMPONENT 0x00080000
28#define ACPI_EC_HC_CLASS "ec_hc_smbus" 28#define ACPI_EC_HC_CLASS "ec_hc_smbus"
29#define ACPI_EC_HC_HID "ACPI0001" 29#define ACPI_EC_HC_HID "ACPI0001"
30#define ACPI_EC_HC_DRIVER_NAME "ACPI EC HC smbus driver"
31#define ACPI_EC_HC_DEVICE_NAME "EC HC smbus" 30#define ACPI_EC_HC_DEVICE_NAME "EC HC smbus"
32 31
33#define _COMPONENT ACPI_EC_HC_COMPONENT 32#define _COMPONENT ACPI_EC_HC_COMPONENT
34 33
35ACPI_MODULE_NAME("acpi_smbus") 34ACPI_MODULE_NAME("i2c_ec");
36 35
37static int acpi_ec_hc_add(struct acpi_device *device); 36static int acpi_ec_hc_add(struct acpi_device *device);
38static int acpi_ec_hc_remove(struct acpi_device *device, int type); 37static int acpi_ec_hc_remove(struct acpi_device *device, int type);
39 38
40static struct acpi_driver acpi_ec_hc_driver = { 39static struct acpi_driver acpi_ec_hc_driver = {
41 .name = ACPI_EC_HC_DRIVER_NAME, 40 .name = "i2c_ec",
42 .class = ACPI_EC_HC_CLASS, 41 .class = ACPI_EC_HC_CLASS,
43 .ids = ACPI_EC_HC_HID, 42 .ids = ACPI_EC_HC_HID,
44 .ops = { 43 .ops = {
diff --git a/drivers/acpi/ibm_acpi.c b/drivers/acpi/ibm_acpi.c
index c6144ca66638..1a0ed3dc409c 100644
--- a/drivers/acpi/ibm_acpi.c
+++ b/drivers/acpi/ibm_acpi.c
@@ -496,6 +496,10 @@ static int ibm_acpi_driver_init(void)
496 printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION); 496 printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION);
497 printk(IBM_INFO "%s\n", IBM_URL); 497 printk(IBM_INFO "%s\n", IBM_URL);
498 498
499 if (ibm_thinkpad_ec_found)
500 printk(IBM_INFO "ThinkPad EC firmware %s\n",
501 ibm_thinkpad_ec_found);
502
499 return 0; 503 return 0;
500} 504}
501 505
@@ -2617,7 +2621,7 @@ static void __init ibm_handle_init(char *name,
2617 ibm_handle_init(#object, &object##_handle, *object##_parent, \ 2621 ibm_handle_init(#object, &object##_handle, *object##_parent, \
2618 object##_paths, ARRAY_SIZE(object##_paths), &object##_path) 2622 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
2619 2623
2620static int set_ibm_param(const char *val, struct kernel_param *kp) 2624static int __init set_ibm_param(const char *val, struct kernel_param *kp)
2621{ 2625{
2622 unsigned int i; 2626 unsigned int i;
2623 2627
@@ -2659,7 +2663,8 @@ static void acpi_ibm_exit(void)
2659 for (i = ARRAY_SIZE(ibms) - 1; i >= 0; i--) 2663 for (i = ARRAY_SIZE(ibms) - 1; i >= 0; i--)
2660 ibm_exit(&ibms[i]); 2664 ibm_exit(&ibms[i]);
2661 2665
2662 remove_proc_entry(IBM_DIR, acpi_root_dir); 2666 if (proc_dir)
2667 remove_proc_entry(IBM_DIR, acpi_root_dir);
2663 2668
2664 if (ibm_thinkpad_ec_found) 2669 if (ibm_thinkpad_ec_found)
2665 kfree(ibm_thinkpad_ec_found); 2670 kfree(ibm_thinkpad_ec_found);
@@ -2696,11 +2701,6 @@ static int __init acpi_ibm_init(void)
2696 if (acpi_disabled) 2701 if (acpi_disabled)
2697 return -ENODEV; 2702 return -ENODEV;
2698 2703
2699 if (!acpi_specific_hotkey_enabled) {
2700 printk(IBM_ERR "using generic hotkey driver\n");
2701 return -ENODEV;
2702 }
2703
2704 /* ec is required because many other handles are relative to it */ 2704 /* ec is required because many other handles are relative to it */
2705 IBM_HANDLE_INIT(ec); 2705 IBM_HANDLE_INIT(ec);
2706 if (!ec_handle) { 2706 if (!ec_handle) {
@@ -2710,9 +2710,6 @@ static int __init acpi_ibm_init(void)
2710 2710
2711 /* Models with newer firmware report the EC in DMI */ 2711 /* Models with newer firmware report the EC in DMI */
2712 ibm_thinkpad_ec_found = check_dmi_for_ec(); 2712 ibm_thinkpad_ec_found = check_dmi_for_ec();
2713 if (ibm_thinkpad_ec_found)
2714 printk(IBM_INFO "ThinkPad EC firmware %s\n",
2715 ibm_thinkpad_ec_found);
2716 2713
2717 /* these handles are not required */ 2714 /* these handles are not required */
2718 IBM_HANDLE_INIT(vid); 2715 IBM_HANDLE_INIT(vid);
@@ -2742,6 +2739,7 @@ static int __init acpi_ibm_init(void)
2742 proc_dir = proc_mkdir(IBM_DIR, acpi_root_dir); 2739 proc_dir = proc_mkdir(IBM_DIR, acpi_root_dir);
2743 if (!proc_dir) { 2740 if (!proc_dir) {
2744 printk(IBM_ERR "unable to create proc dir %s", IBM_DIR); 2741 printk(IBM_ERR "unable to create proc dir %s", IBM_DIR);
2742 acpi_ibm_exit();
2745 return -ENODEV; 2743 return -ENODEV;
2746 } 2744 }
2747 proc_dir->owner = THIS_MODULE; 2745 proc_dir->owner = THIS_MODULE;
diff --git a/drivers/acpi/numa.c b/drivers/acpi/numa.c
index 4a9faff4c01d..8fcd6a15517f 100644
--- a/drivers/acpi/numa.c
+++ b/drivers/acpi/numa.c
@@ -33,7 +33,7 @@
33 33
34#define ACPI_NUMA 0x80000000 34#define ACPI_NUMA 0x80000000
35#define _COMPONENT ACPI_NUMA 35#define _COMPONENT ACPI_NUMA
36ACPI_MODULE_NAME("numa") 36ACPI_MODULE_NAME("numa");
37 37
38static nodemask_t nodes_found_map = NODE_MASK_NONE; 38static nodemask_t nodes_found_map = NODE_MASK_NONE;
39#define PXM_INVAL -1 39#define PXM_INVAL -1
@@ -45,12 +45,6 @@ int __cpuinitdata pxm_to_node_map[MAX_PXM_DOMAINS]
45int __cpuinitdata node_to_pxm_map[MAX_NUMNODES] 45int __cpuinitdata node_to_pxm_map[MAX_NUMNODES]
46 = { [0 ... MAX_NUMNODES - 1] = PXM_INVAL }; 46 = { [0 ... MAX_NUMNODES - 1] = PXM_INVAL };
47 47
48extern int __init acpi_table_parse_madt_family(char *id,
49 unsigned long madt_size,
50 int entry_id,
51 acpi_madt_entry_handler handler,
52 unsigned int max_entries);
53
54int __cpuinit pxm_to_node(int pxm) 48int __cpuinit pxm_to_node(int pxm)
55{ 49{
56 if (pxm < 0) 50 if (pxm < 0)
@@ -208,9 +202,9 @@ static int __init acpi_parse_srat(struct acpi_table_header *table)
208 202
209int __init 203int __init
210acpi_table_parse_srat(enum acpi_srat_type id, 204acpi_table_parse_srat(enum acpi_srat_type id,
211 acpi_madt_entry_handler handler, unsigned int max_entries) 205 acpi_table_entry_handler handler, unsigned int max_entries)
212{ 206{
213 return acpi_table_parse_madt_family(ACPI_SIG_SRAT, 207 return acpi_table_parse_entries(ACPI_SIG_SRAT,
214 sizeof(struct acpi_table_srat), id, 208 sizeof(struct acpi_table_srat), id,
215 handler, max_entries); 209 handler, max_entries);
216} 210}
@@ -220,9 +214,7 @@ int __init acpi_numa_init(void)
220 int result; 214 int result;
221 215
222 /* SRAT: Static Resource Affinity Table */ 216 /* SRAT: Static Resource Affinity Table */
223 result = acpi_table_parse(ACPI_SIG_SRAT, acpi_parse_srat); 217 if (!acpi_table_parse(ACPI_SIG_SRAT, acpi_parse_srat)) {
224
225 if (result > 0) {
226 result = acpi_table_parse_srat(ACPI_SRAT_TYPE_CPU_AFFINITY, 218 result = acpi_table_parse_srat(ACPI_SRAT_TYPE_CPU_AFFINITY,
227 acpi_parse_processor_affinity, 219 acpi_parse_processor_affinity,
228 NR_CPUS); 220 NR_CPUS);
@@ -230,7 +222,7 @@ int __init acpi_numa_init(void)
230 } 222 }
231 223
232 /* SLIT: System Locality Information Table */ 224 /* SLIT: System Locality Information Table */
233 result = acpi_table_parse(ACPI_SIG_SLIT, acpi_parse_slit); 225 acpi_table_parse(ACPI_SIG_SLIT, acpi_parse_slit);
234 226
235 acpi_numa_arch_fixup(); 227 acpi_numa_arch_fixup();
236 return 0; 228 return 0;
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index 0f6f3bcbc8eb..971eca4864fa 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -46,7 +46,7 @@
46#include <linux/efi.h> 46#include <linux/efi.h>
47 47
48#define _COMPONENT ACPI_OS_SERVICES 48#define _COMPONENT ACPI_OS_SERVICES
49ACPI_MODULE_NAME("osl") 49ACPI_MODULE_NAME("osl");
50#define PREFIX "ACPI: " 50#define PREFIX "ACPI: "
51struct acpi_os_dpc { 51struct acpi_os_dpc {
52 acpi_osd_exec_callback function; 52 acpi_osd_exec_callback function;
@@ -68,9 +68,6 @@ EXPORT_SYMBOL(acpi_in_debugger);
68extern char line_buf[80]; 68extern char line_buf[80];
69#endif /*ENABLE_DEBUGGER */ 69#endif /*ENABLE_DEBUGGER */
70 70
71int acpi_specific_hotkey_enabled = TRUE;
72EXPORT_SYMBOL(acpi_specific_hotkey_enabled);
73
74static unsigned int acpi_irq_irq; 71static unsigned int acpi_irq_irq;
75static acpi_osd_handler acpi_irq_handler; 72static acpi_osd_handler acpi_irq_handler;
76static void *acpi_irq_context; 73static void *acpi_irq_context;
@@ -205,7 +202,7 @@ void __iomem *acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
205{ 202{
206 if (phys > ULONG_MAX) { 203 if (phys > ULONG_MAX) {
207 printk(KERN_ERR PREFIX "Cannot map memory that high\n"); 204 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
208 return 0; 205 return NULL;
209 } 206 }
210 if (acpi_gbl_permanent_mmap) 207 if (acpi_gbl_permanent_mmap)
211 /* 208 /*
@@ -890,26 +887,6 @@ u32 acpi_os_get_line(char *buffer)
890} 887}
891#endif /* ACPI_FUTURE_USAGE */ 888#endif /* ACPI_FUTURE_USAGE */
892 889
893/* Assumes no unreadable holes inbetween */
894u8 acpi_os_readable(void *ptr, acpi_size len)
895{
896#if defined(__i386__) || defined(__x86_64__)
897 char tmp;
898 return !__get_user(tmp, (char __user *)ptr)
899 && !__get_user(tmp, (char __user *)ptr + len - 1);
900#endif
901 return 1;
902}
903
904#ifdef ACPI_FUTURE_USAGE
905u8 acpi_os_writable(void *ptr, acpi_size len)
906{
907 /* could do dummy write (racy) or a kernel page table lookup.
908 The later may be difficult at early boot when kmap doesn't work yet. */
909 return 1;
910}
911#endif
912
913acpi_status acpi_os_signal(u32 function, void *info) 890acpi_status acpi_os_signal(u32 function, void *info)
914{ 891{
915 switch (function) { 892 switch (function) {
@@ -1012,14 +989,6 @@ static int __init acpi_wake_gpes_always_on_setup(char *str)
1012 989
1013__setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup); 990__setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
1014 991
1015static int __init acpi_hotkey_setup(char *str)
1016{
1017 acpi_specific_hotkey_enabled = FALSE;
1018 return 1;
1019}
1020
1021__setup("acpi_generic_hotkey", acpi_hotkey_setup);
1022
1023/* 992/*
1024 * max_cstate is defined in the base kernel so modules can 993 * max_cstate is defined in the base kernel so modules can
1025 * change it w/o depending on the state of the processor module. 994 * change it w/o depending on the state of the processor module.
diff --git a/drivers/acpi/pci_bind.c b/drivers/acpi/pci_bind.c
index 55f57a61c55e..028969370bbf 100644
--- a/drivers/acpi/pci_bind.c
+++ b/drivers/acpi/pci_bind.c
@@ -36,7 +36,7 @@
36#include <acpi/acpi_drivers.h> 36#include <acpi/acpi_drivers.h>
37 37
38#define _COMPONENT ACPI_PCI_COMPONENT 38#define _COMPONENT ACPI_PCI_COMPONENT
39ACPI_MODULE_NAME("pci_bind") 39ACPI_MODULE_NAME("pci_bind");
40 40
41struct acpi_pci_data { 41struct acpi_pci_data {
42 struct acpi_pci_id id; 42 struct acpi_pci_id id;
diff --git a/drivers/acpi/pci_irq.c b/drivers/acpi/pci_irq.c
index fe7d007833ad..dd3186abe07a 100644
--- a/drivers/acpi/pci_irq.c
+++ b/drivers/acpi/pci_irq.c
@@ -38,7 +38,7 @@
38#include <acpi/acpi_drivers.h> 38#include <acpi/acpi_drivers.h>
39 39
40#define _COMPONENT ACPI_PCI_COMPONENT 40#define _COMPONENT ACPI_PCI_COMPONENT
41ACPI_MODULE_NAME("pci_irq") 41ACPI_MODULE_NAME("pci_irq");
42 42
43static struct acpi_prt_list acpi_prt; 43static struct acpi_prt_list acpi_prt;
44static DEFINE_SPINLOCK(acpi_prt_lock); 44static DEFINE_SPINLOCK(acpi_prt_lock);
diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c
index 0f683c8c6fbc..acc594771379 100644
--- a/drivers/acpi/pci_link.c
+++ b/drivers/acpi/pci_link.c
@@ -44,10 +44,9 @@
44#include <acpi/acpi_drivers.h> 44#include <acpi/acpi_drivers.h>
45 45
46#define _COMPONENT ACPI_PCI_COMPONENT 46#define _COMPONENT ACPI_PCI_COMPONENT
47ACPI_MODULE_NAME("pci_link") 47ACPI_MODULE_NAME("pci_link");
48#define ACPI_PCI_LINK_CLASS "pci_irq_routing" 48#define ACPI_PCI_LINK_CLASS "pci_irq_routing"
49#define ACPI_PCI_LINK_HID "PNP0C0F" 49#define ACPI_PCI_LINK_HID "PNP0C0F"
50#define ACPI_PCI_LINK_DRIVER_NAME "ACPI PCI Interrupt Link Driver"
51#define ACPI_PCI_LINK_DEVICE_NAME "PCI Interrupt Link" 50#define ACPI_PCI_LINK_DEVICE_NAME "PCI Interrupt Link"
52#define ACPI_PCI_LINK_FILE_INFO "info" 51#define ACPI_PCI_LINK_FILE_INFO "info"
53#define ACPI_PCI_LINK_FILE_STATUS "state" 52#define ACPI_PCI_LINK_FILE_STATUS "state"
@@ -56,7 +55,7 @@ static int acpi_pci_link_add(struct acpi_device *device);
56static int acpi_pci_link_remove(struct acpi_device *device, int type); 55static int acpi_pci_link_remove(struct acpi_device *device, int type);
57 56
58static struct acpi_driver acpi_pci_link_driver = { 57static struct acpi_driver acpi_pci_link_driver = {
59 .name = ACPI_PCI_LINK_DRIVER_NAME, 58 .name = "pci_link",
60 .class = ACPI_PCI_LINK_CLASS, 59 .class = ACPI_PCI_LINK_CLASS,
61 .ids = ACPI_PCI_LINK_HID, 60 .ids = ACPI_PCI_LINK_HID,
62 .ops = { 61 .ops = {
diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c
index 4ecf701687e8..ad4145a37786 100644
--- a/drivers/acpi/pci_root.c
+++ b/drivers/acpi/pci_root.c
@@ -36,17 +36,16 @@
36#include <acpi/acpi_drivers.h> 36#include <acpi/acpi_drivers.h>
37 37
38#define _COMPONENT ACPI_PCI_COMPONENT 38#define _COMPONENT ACPI_PCI_COMPONENT
39ACPI_MODULE_NAME("pci_root") 39ACPI_MODULE_NAME("pci_root");
40#define ACPI_PCI_ROOT_CLASS "pci_bridge" 40#define ACPI_PCI_ROOT_CLASS "pci_bridge"
41#define ACPI_PCI_ROOT_HID "PNP0A03" 41#define ACPI_PCI_ROOT_HID "PNP0A03"
42#define ACPI_PCI_ROOT_DRIVER_NAME "ACPI PCI Root Bridge Driver"
43#define ACPI_PCI_ROOT_DEVICE_NAME "PCI Root Bridge" 42#define ACPI_PCI_ROOT_DEVICE_NAME "PCI Root Bridge"
44static int acpi_pci_root_add(struct acpi_device *device); 43static int acpi_pci_root_add(struct acpi_device *device);
45static int acpi_pci_root_remove(struct acpi_device *device, int type); 44static int acpi_pci_root_remove(struct acpi_device *device, int type);
46static int acpi_pci_root_start(struct acpi_device *device); 45static int acpi_pci_root_start(struct acpi_device *device);
47 46
48static struct acpi_driver acpi_pci_root_driver = { 47static struct acpi_driver acpi_pci_root_driver = {
49 .name = ACPI_PCI_ROOT_DRIVER_NAME, 48 .name = "pci_root",
50 .class = ACPI_PCI_ROOT_CLASS, 49 .class = ACPI_PCI_ROOT_CLASS,
51 .ids = ACPI_PCI_ROOT_HID, 50 .ids = ACPI_PCI_ROOT_HID,
52 .ops = { 51 .ops = {
diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c
index 0ba7dfbbb2ee..1ef338545dfe 100644
--- a/drivers/acpi/power.c
+++ b/drivers/acpi/power.c
@@ -45,10 +45,9 @@
45#include <acpi/acpi_drivers.h> 45#include <acpi/acpi_drivers.h>
46 46
47#define _COMPONENT ACPI_POWER_COMPONENT 47#define _COMPONENT ACPI_POWER_COMPONENT
48ACPI_MODULE_NAME("acpi_power") 48ACPI_MODULE_NAME("power");
49#define ACPI_POWER_COMPONENT 0x00800000 49#define ACPI_POWER_COMPONENT 0x00800000
50#define ACPI_POWER_CLASS "power_resource" 50#define ACPI_POWER_CLASS "power_resource"
51#define ACPI_POWER_DRIVER_NAME "ACPI Power Resource Driver"
52#define ACPI_POWER_DEVICE_NAME "Power Resource" 51#define ACPI_POWER_DEVICE_NAME "Power Resource"
53#define ACPI_POWER_FILE_INFO "info" 52#define ACPI_POWER_FILE_INFO "info"
54#define ACPI_POWER_FILE_STATUS "state" 53#define ACPI_POWER_FILE_STATUS "state"
@@ -57,25 +56,33 @@ ACPI_MODULE_NAME("acpi_power")
57#define ACPI_POWER_RESOURCE_STATE_UNKNOWN 0xFF 56#define ACPI_POWER_RESOURCE_STATE_UNKNOWN 0xFF
58static int acpi_power_add(struct acpi_device *device); 57static int acpi_power_add(struct acpi_device *device);
59static int acpi_power_remove(struct acpi_device *device, int type); 58static int acpi_power_remove(struct acpi_device *device, int type);
59static int acpi_power_resume(struct acpi_device *device);
60static int acpi_power_open_fs(struct inode *inode, struct file *file); 60static int acpi_power_open_fs(struct inode *inode, struct file *file);
61 61
62static struct acpi_driver acpi_power_driver = { 62static struct acpi_driver acpi_power_driver = {
63 .name = ACPI_POWER_DRIVER_NAME, 63 .name = "power",
64 .class = ACPI_POWER_CLASS, 64 .class = ACPI_POWER_CLASS,
65 .ids = ACPI_POWER_HID, 65 .ids = ACPI_POWER_HID,
66 .ops = { 66 .ops = {
67 .add = acpi_power_add, 67 .add = acpi_power_add,
68 .remove = acpi_power_remove, 68 .remove = acpi_power_remove,
69 .resume = acpi_power_resume,
69 }, 70 },
70}; 71};
71 72
73struct acpi_power_reference {
74 struct list_head node;
75 struct acpi_device *device;
76};
77
72struct acpi_power_resource { 78struct acpi_power_resource {
73 struct acpi_device * device; 79 struct acpi_device * device;
74 acpi_bus_id name; 80 acpi_bus_id name;
75 u32 system_level; 81 u32 system_level;
76 u32 order; 82 u32 order;
77 int state; 83 int state;
78 int references; 84 struct mutex resource_lock;
85 struct list_head reference;
79}; 86};
80 87
81static struct list_head acpi_power_resource_list; 88static struct list_head acpi_power_resource_list;
@@ -171,22 +178,47 @@ static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state)
171 return result; 178 return result;
172} 179}
173 180
174static int acpi_power_on(acpi_handle handle) 181static int acpi_power_on(acpi_handle handle, struct acpi_device *dev)
175{ 182{
176 int result = 0; 183 int result = 0;
184 int found = 0;
177 acpi_status status = AE_OK; 185 acpi_status status = AE_OK;
178 struct acpi_device *device = NULL;
179 struct acpi_power_resource *resource = NULL; 186 struct acpi_power_resource *resource = NULL;
187 struct list_head *node, *next;
188 struct acpi_power_reference *ref;
180 189
181 190
182 result = acpi_power_get_context(handle, &resource); 191 result = acpi_power_get_context(handle, &resource);
183 if (result) 192 if (result)
184 return result; 193 return result;
185 194
186 resource->references++; 195 mutex_lock(&resource->resource_lock);
196 list_for_each_safe(node, next, &resource->reference) {
197 ref = container_of(node, struct acpi_power_reference, node);
198 if (dev->handle == ref->device->handle) {
199 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] already referenced by resource [%s]\n",
200 dev->pnp.bus_id, resource->name));
201 found = 1;
202 break;
203 }
204 }
205
206 if (!found) {
207 ref = kmalloc(sizeof (struct acpi_power_reference),
208 irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL);
209 if (!ref) {
210 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "kmalloc() failed\n"));
211 mutex_unlock(&resource->resource_lock);
212 return -ENOMEM;
213 }
214 list_add_tail(&ref->node, &resource->reference);
215 ref->device = dev;
216 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] added to resource [%s] references\n",
217 dev->pnp.bus_id, resource->name));
218 }
219 mutex_unlock(&resource->resource_lock);
187 220
188 if ((resource->references > 1) 221 if (resource->state == ACPI_POWER_RESOURCE_STATE_ON) {
189 || (resource->state == ACPI_POWER_RESOURCE_STATE_ON)) {
190 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] already on\n", 222 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] already on\n",
191 resource->name)); 223 resource->name));
192 return 0; 224 return 0;
@@ -203,38 +235,49 @@ static int acpi_power_on(acpi_handle handle)
203 return -ENOEXEC; 235 return -ENOEXEC;
204 236
205 /* Update the power resource's _device_ power state */ 237 /* Update the power resource's _device_ power state */
206 device = resource->device;
207 resource->device->power.state = ACPI_STATE_D0; 238 resource->device->power.state = ACPI_STATE_D0;
208 239
209 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] turned on\n", 240 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] turned on\n",
210 resource->name)); 241 resource->name));
211
212 return 0; 242 return 0;
213} 243}
214 244
215static int acpi_power_off_device(acpi_handle handle) 245static int acpi_power_off_device(acpi_handle handle, struct acpi_device *dev)
216{ 246{
217 int result = 0; 247 int result = 0;
218 acpi_status status = AE_OK; 248 acpi_status status = AE_OK;
219 struct acpi_power_resource *resource = NULL; 249 struct acpi_power_resource *resource = NULL;
250 struct list_head *node, *next;
251 struct acpi_power_reference *ref;
252
220 253
221 result = acpi_power_get_context(handle, &resource); 254 result = acpi_power_get_context(handle, &resource);
222 if (result) 255 if (result)
223 return result; 256 return result;
224 257
225 if (resource->references) 258 mutex_lock(&resource->resource_lock);
226 resource->references--; 259 list_for_each_safe(node, next, &resource->reference) {
260 ref = container_of(node, struct acpi_power_reference, node);
261 if (dev->handle == ref->device->handle) {
262 list_del(&ref->node);
263 kfree(ref);
264 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] removed from resource [%s] references\n",
265 dev->pnp.bus_id, resource->name));
266 break;
267 }
268 }
227 269
228 if (resource->references) { 270 if (!list_empty(&resource->reference)) {
229 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 271 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Cannot turn resource [%s] off - resource is in use\n",
230 "Resource [%s] is still in use, dereferencing\n", 272 resource->name));
231 resource->device->pnp.bus_id)); 273 mutex_unlock(&resource->resource_lock);
232 return 0; 274 return 0;
233 } 275 }
276 mutex_unlock(&resource->resource_lock);
234 277
235 if (resource->state == ACPI_POWER_RESOURCE_STATE_OFF) { 278 if (resource->state == ACPI_POWER_RESOURCE_STATE_OFF) {
236 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] already off\n", 279 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] already off\n",
237 resource->device->pnp.bus_id)); 280 resource->name));
238 return 0; 281 return 0;
239 } 282 }
240 283
@@ -276,7 +319,7 @@ int acpi_enable_wakeup_device_power(struct acpi_device *dev)
276 arg.integer.value = 1; 319 arg.integer.value = 1;
277 /* Open power resource */ 320 /* Open power resource */
278 for (i = 0; i < dev->wakeup.resources.count; i++) { 321 for (i = 0; i < dev->wakeup.resources.count; i++) {
279 ret = acpi_power_on(dev->wakeup.resources.handles[i]); 322 ret = acpi_power_on(dev->wakeup.resources.handles[i], dev);
280 if (ret) { 323 if (ret) {
281 printk(KERN_ERR PREFIX "Transition power state\n"); 324 printk(KERN_ERR PREFIX "Transition power state\n");
282 dev->wakeup.flags.valid = 0; 325 dev->wakeup.flags.valid = 0;
@@ -323,7 +366,7 @@ int acpi_disable_wakeup_device_power(struct acpi_device *dev)
323 366
324 /* Close power resource */ 367 /* Close power resource */
325 for (i = 0; i < dev->wakeup.resources.count; i++) { 368 for (i = 0; i < dev->wakeup.resources.count; i++) {
326 ret = acpi_power_off_device(dev->wakeup.resources.handles[i]); 369 ret = acpi_power_off_device(dev->wakeup.resources.handles[i], dev);
327 if (ret) { 370 if (ret) {
328 printk(KERN_ERR PREFIX "Transition power state\n"); 371 printk(KERN_ERR PREFIX "Transition power state\n");
329 dev->wakeup.flags.valid = 0; 372 dev->wakeup.flags.valid = 0;
@@ -407,16 +450,20 @@ int acpi_power_transition(struct acpi_device *device, int state)
407 * (e.g. so the device doesn't lose power while transitioning). 450 * (e.g. so the device doesn't lose power while transitioning).
408 */ 451 */
409 for (i = 0; i < tl->count; i++) { 452 for (i = 0; i < tl->count; i++) {
410 result = acpi_power_on(tl->handles[i]); 453 result = acpi_power_on(tl->handles[i], device);
411 if (result) 454 if (result)
412 goto end; 455 goto end;
413 } 456 }
414 457
458 if (device->power.state == state) {
459 goto end;
460 }
461
415 /* 462 /*
416 * Then we dereference all power resources used in the current list. 463 * Then we dereference all power resources used in the current list.
417 */ 464 */
418 for (i = 0; i < cl->count; i++) { 465 for (i = 0; i < cl->count; i++) {
419 result = acpi_power_off_device(cl->handles[i]); 466 result = acpi_power_off_device(cl->handles[i], device);
420 if (result) 467 if (result)
421 goto end; 468 goto end;
422 } 469 }
@@ -439,7 +486,11 @@ static struct proc_dir_entry *acpi_power_dir;
439 486
440static int acpi_power_seq_show(struct seq_file *seq, void *offset) 487static int acpi_power_seq_show(struct seq_file *seq, void *offset)
441{ 488{
489 int count = 0;
490 int result = 0;
442 struct acpi_power_resource *resource = NULL; 491 struct acpi_power_resource *resource = NULL;
492 struct list_head *node, *next;
493 struct acpi_power_reference *ref;
443 494
444 495
445 resource = seq->private; 496 resource = seq->private;
@@ -447,6 +498,10 @@ static int acpi_power_seq_show(struct seq_file *seq, void *offset)
447 if (!resource) 498 if (!resource)
448 goto end; 499 goto end;
449 500
501 result = acpi_power_get_state(resource);
502 if (result)
503 goto end;
504
450 seq_puts(seq, "state: "); 505 seq_puts(seq, "state: ");
451 switch (resource->state) { 506 switch (resource->state) {
452 case ACPI_POWER_RESOURCE_STATE_ON: 507 case ACPI_POWER_RESOURCE_STATE_ON:
@@ -460,11 +515,18 @@ static int acpi_power_seq_show(struct seq_file *seq, void *offset)
460 break; 515 break;
461 } 516 }
462 517
518 mutex_lock(&resource->resource_lock);
519 list_for_each_safe(node, next, &resource->reference) {
520 ref = container_of(node, struct acpi_power_reference, node);
521 count++;
522 }
523 mutex_unlock(&resource->resource_lock);
524
463 seq_printf(seq, "system level: S%d\n" 525 seq_printf(seq, "system level: S%d\n"
464 "order: %d\n" 526 "order: %d\n"
465 "reference count: %d\n", 527 "reference count: %d\n",
466 resource->system_level, 528 resource->system_level,
467 resource->order, resource->references); 529 resource->order, count);
468 530
469 end: 531 end:
470 return 0; 532 return 0;
@@ -537,6 +599,8 @@ static int acpi_power_add(struct acpi_device *device)
537 return -ENOMEM; 599 return -ENOMEM;
538 600
539 resource->device = device; 601 resource->device = device;
602 mutex_init(&resource->resource_lock);
603 INIT_LIST_HEAD(&resource->reference);
540 strcpy(resource->name, device->pnp.bus_id); 604 strcpy(resource->name, device->pnp.bus_id);
541 strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME); 605 strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME);
542 strcpy(acpi_device_class(device), ACPI_POWER_CLASS); 606 strcpy(acpi_device_class(device), ACPI_POWER_CLASS);
@@ -584,6 +648,7 @@ static int acpi_power_add(struct acpi_device *device)
584static int acpi_power_remove(struct acpi_device *device, int type) 648static int acpi_power_remove(struct acpi_device *device, int type)
585{ 649{
586 struct acpi_power_resource *resource = NULL; 650 struct acpi_power_resource *resource = NULL;
651 struct list_head *node, *next;
587 652
588 653
589 if (!device || !acpi_driver_data(device)) 654 if (!device || !acpi_driver_data(device))
@@ -593,11 +658,54 @@ static int acpi_power_remove(struct acpi_device *device, int type)
593 658
594 acpi_power_remove_fs(device); 659 acpi_power_remove_fs(device);
595 660
661 mutex_lock(&resource->resource_lock);
662 list_for_each_safe(node, next, &resource->reference) {
663 struct acpi_power_reference *ref = container_of(node, struct acpi_power_reference, node);
664 list_del(&ref->node);
665 kfree(ref);
666 }
667 mutex_unlock(&resource->resource_lock);
668
596 kfree(resource); 669 kfree(resource);
597 670
598 return 0; 671 return 0;
599} 672}
600 673
674static int acpi_power_resume(struct acpi_device *device)
675{
676 int result = 0;
677 struct acpi_power_resource *resource = NULL;
678 struct acpi_power_reference *ref;
679
680 if (!device || !acpi_driver_data(device))
681 return -EINVAL;
682
683 resource = (struct acpi_power_resource *)acpi_driver_data(device);
684
685 result = acpi_power_get_state(resource);
686 if (result)
687 return result;
688
689 mutex_lock(&resource->resource_lock);
690 if ((resource->state == ACPI_POWER_RESOURCE_STATE_ON) &&
691 list_empty(&resource->reference)) {
692 mutex_unlock(&resource->resource_lock);
693 result = acpi_power_off_device(device->handle, NULL);
694 return result;
695 }
696
697 if ((resource->state == ACPI_POWER_RESOURCE_STATE_OFF) &&
698 !list_empty(&resource->reference)) {
699 ref = container_of(resource->reference.next, struct acpi_power_reference, node);
700 mutex_unlock(&resource->resource_lock);
701 result = acpi_power_on(device->handle, ref->device);
702 return result;
703 }
704
705 mutex_unlock(&resource->resource_lock);
706 return 0;
707}
708
601static int __init acpi_power_init(void) 709static int __init acpi_power_init(void)
602{ 710{
603 int result = 0; 711 int result = 0;
diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
index 0079bc51082c..99d1516d1e70 100644
--- a/drivers/acpi/processor_core.c
+++ b/drivers/acpi/processor_core.c
@@ -60,7 +60,6 @@
60 60
61#define ACPI_PROCESSOR_COMPONENT 0x01000000 61#define ACPI_PROCESSOR_COMPONENT 0x01000000
62#define ACPI_PROCESSOR_CLASS "processor" 62#define ACPI_PROCESSOR_CLASS "processor"
63#define ACPI_PROCESSOR_DRIVER_NAME "ACPI Processor Driver"
64#define ACPI_PROCESSOR_DEVICE_NAME "Processor" 63#define ACPI_PROCESSOR_DEVICE_NAME "Processor"
65#define ACPI_PROCESSOR_FILE_INFO "info" 64#define ACPI_PROCESSOR_FILE_INFO "info"
66#define ACPI_PROCESSOR_FILE_THROTTLING "throttling" 65#define ACPI_PROCESSOR_FILE_THROTTLING "throttling"
@@ -74,10 +73,10 @@
74#define ACPI_STA_PRESENT 0x00000001 73#define ACPI_STA_PRESENT 0x00000001
75 74
76#define _COMPONENT ACPI_PROCESSOR_COMPONENT 75#define _COMPONENT ACPI_PROCESSOR_COMPONENT
77ACPI_MODULE_NAME("acpi_processor") 76ACPI_MODULE_NAME("processor_core");
78 77
79 MODULE_AUTHOR("Paul Diefenbaugh"); 78MODULE_AUTHOR("Paul Diefenbaugh");
80MODULE_DESCRIPTION(ACPI_PROCESSOR_DRIVER_NAME); 79MODULE_DESCRIPTION("ACPI Processor Driver");
81MODULE_LICENSE("GPL"); 80MODULE_LICENSE("GPL");
82 81
83static int acpi_processor_add(struct acpi_device *device); 82static int acpi_processor_add(struct acpi_device *device);
@@ -89,7 +88,7 @@ static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu);
89static int acpi_processor_handle_eject(struct acpi_processor *pr); 88static int acpi_processor_handle_eject(struct acpi_processor *pr);
90 89
91static struct acpi_driver acpi_processor_driver = { 90static struct acpi_driver acpi_processor_driver = {
92 .name = ACPI_PROCESSOR_DRIVER_NAME, 91 .name = "processor",
93 .class = ACPI_PROCESSOR_CLASS, 92 .class = ACPI_PROCESSOR_CLASS,
94 .ids = ACPI_PROCESSOR_HID, 93 .ids = ACPI_PROCESSOR_HID,
95 .ops = { 94 .ops = {
@@ -404,7 +403,7 @@ static int map_lsapic_id(struct acpi_subtable_header *entry,
404 if (lsapic->lapic_flags & ACPI_MADT_ENABLED) { 403 if (lsapic->lapic_flags & ACPI_MADT_ENABLED) {
405 /* First check against id */ 404 /* First check against id */
406 if (lsapic->processor_id == acpi_id) { 405 if (lsapic->processor_id == acpi_id) {
407 *apic_id = lsapic->id; 406 *apic_id = (lsapic->id << 8) | lsapic->eid;
408 return 1; 407 return 1;
409 /* Check against optional uid */ 408 /* Check against optional uid */
410 } else if (entry->length >= 16 && 409 } else if (entry->length >= 16 &&
@@ -1005,7 +1004,7 @@ static int __init acpi_processor_init(void)
1005#ifdef CONFIG_SMP 1004#ifdef CONFIG_SMP
1006 if (ACPI_FAILURE(acpi_get_table(ACPI_SIG_MADT, 0, 1005 if (ACPI_FAILURE(acpi_get_table(ACPI_SIG_MADT, 0,
1007 (struct acpi_table_header **)&madt))) 1006 (struct acpi_table_header **)&madt)))
1008 madt = 0; 1007 madt = NULL;
1009#endif 1008#endif
1010 1009
1011 acpi_processor_dir = proc_mkdir(ACPI_PROCESSOR_CLASS, acpi_root_dir); 1010 acpi_processor_dir = proc_mkdir(ACPI_PROCESSOR_CLASS, acpi_root_dir);
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index 8206fc1ecc58..60773005b8af 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -51,6 +51,14 @@
51#include <asm/apic.h> 51#include <asm/apic.h>
52#endif 52#endif
53 53
54/*
55 * Include the apic definitions for x86 to have the APIC timer related defines
56 * available also for UP (on SMP it gets magically included via linux/smp.h).
57 */
58#ifdef CONFIG_X86
59#include <asm/apic.h>
60#endif
61
54#include <asm/io.h> 62#include <asm/io.h>
55#include <asm/uaccess.h> 63#include <asm/uaccess.h>
56 64
@@ -59,9 +67,8 @@
59 67
60#define ACPI_PROCESSOR_COMPONENT 0x01000000 68#define ACPI_PROCESSOR_COMPONENT 0x01000000
61#define ACPI_PROCESSOR_CLASS "processor" 69#define ACPI_PROCESSOR_CLASS "processor"
62#define ACPI_PROCESSOR_DRIVER_NAME "ACPI Processor Driver"
63#define _COMPONENT ACPI_PROCESSOR_COMPONENT 70#define _COMPONENT ACPI_PROCESSOR_COMPONENT
64ACPI_MODULE_NAME("acpi_processor") 71ACPI_MODULE_NAME("processor_idle");
65#define ACPI_PROCESSOR_FILE_POWER "power" 72#define ACPI_PROCESSOR_FILE_POWER "power"
66#define US_TO_PM_TIMER_TICKS(t) ((t * (PM_TIMER_FREQUENCY/1000)) / 1000) 73#define US_TO_PM_TIMER_TICKS(t) ((t * (PM_TIMER_FREQUENCY/1000)) / 1000)
67#define C2_OVERHEAD 4 /* 1us (3.579 ticks per us) */ 74#define C2_OVERHEAD 4 /* 1us (3.579 ticks per us) */
diff --git a/drivers/acpi/processor_perflib.c b/drivers/acpi/processor_perflib.c
index 058f13cf3b79..2f2e7964226d 100644
--- a/drivers/acpi/processor_perflib.c
+++ b/drivers/acpi/processor_perflib.c
@@ -44,10 +44,9 @@
44 44
45#define ACPI_PROCESSOR_COMPONENT 0x01000000 45#define ACPI_PROCESSOR_COMPONENT 0x01000000
46#define ACPI_PROCESSOR_CLASS "processor" 46#define ACPI_PROCESSOR_CLASS "processor"
47#define ACPI_PROCESSOR_DRIVER_NAME "ACPI Processor Driver"
48#define ACPI_PROCESSOR_FILE_PERFORMANCE "performance" 47#define ACPI_PROCESSOR_FILE_PERFORMANCE "performance"
49#define _COMPONENT ACPI_PROCESSOR_COMPONENT 48#define _COMPONENT ACPI_PROCESSOR_COMPONENT
50ACPI_MODULE_NAME("acpi_processor") 49ACPI_MODULE_NAME("processor_perflib");
51 50
52static DEFINE_MUTEX(performance_mutex); 51static DEFINE_MUTEX(performance_mutex);
53 52
diff --git a/drivers/acpi/processor_thermal.c b/drivers/acpi/processor_thermal.c
index 40fecd67ad83..06e6f3fb8825 100644
--- a/drivers/acpi/processor_thermal.c
+++ b/drivers/acpi/processor_thermal.c
@@ -41,9 +41,8 @@
41 41
42#define ACPI_PROCESSOR_COMPONENT 0x01000000 42#define ACPI_PROCESSOR_COMPONENT 0x01000000
43#define ACPI_PROCESSOR_CLASS "processor" 43#define ACPI_PROCESSOR_CLASS "processor"
44#define ACPI_PROCESSOR_DRIVER_NAME "ACPI Processor Driver"
45#define _COMPONENT ACPI_PROCESSOR_COMPONENT 44#define _COMPONENT ACPI_PROCESSOR_COMPONENT
46ACPI_MODULE_NAME("acpi_processor") 45ACPI_MODULE_NAME("processor_thermal");
47 46
48/* -------------------------------------------------------------------------- 47/* --------------------------------------------------------------------------
49 Limit Interface 48 Limit Interface
diff --git a/drivers/acpi/processor_throttling.c b/drivers/acpi/processor_throttling.c
index 89dff3639abe..b33486009f41 100644
--- a/drivers/acpi/processor_throttling.c
+++ b/drivers/acpi/processor_throttling.c
@@ -41,9 +41,8 @@
41 41
42#define ACPI_PROCESSOR_COMPONENT 0x01000000 42#define ACPI_PROCESSOR_COMPONENT 0x01000000
43#define ACPI_PROCESSOR_CLASS "processor" 43#define ACPI_PROCESSOR_CLASS "processor"
44#define ACPI_PROCESSOR_DRIVER_NAME "ACPI Processor Driver"
45#define _COMPONENT ACPI_PROCESSOR_COMPONENT 44#define _COMPONENT ACPI_PROCESSOR_COMPONENT
46ACPI_MODULE_NAME("acpi_processor") 45ACPI_MODULE_NAME("processor_throttling");
47 46
48/* -------------------------------------------------------------------------- 47/* --------------------------------------------------------------------------
49 Throttling Control 48 Throttling Control
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index f58fc7447ab4..59640d9a0acc 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -59,7 +59,6 @@ extern void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
59#define ACPI_AC_CLASS "ac_adapter" 59#define ACPI_AC_CLASS "ac_adapter"
60#define ACPI_BATTERY_CLASS "battery" 60#define ACPI_BATTERY_CLASS "battery"
61#define ACPI_SBS_HID "ACPI0002" 61#define ACPI_SBS_HID "ACPI0002"
62#define ACPI_SBS_DRIVER_NAME "ACPI Smart Battery System Driver"
63#define ACPI_SBS_DEVICE_NAME "Smart Battery System" 62#define ACPI_SBS_DEVICE_NAME "Smart Battery System"
64#define ACPI_SBS_FILE_INFO "info" 63#define ACPI_SBS_FILE_INFO "info"
65#define ACPI_SBS_FILE_STATE "state" 64#define ACPI_SBS_FILE_STATE "state"
@@ -78,7 +77,7 @@ extern void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
78#define MAX_SBS_BAT 4 77#define MAX_SBS_BAT 4
79#define MAX_SMBUS_ERR 1 78#define MAX_SMBUS_ERR 1
80 79
81ACPI_MODULE_NAME("acpi_sbs"); 80ACPI_MODULE_NAME("sbs");
82 81
83MODULE_AUTHOR("Rich Townsend"); 82MODULE_AUTHOR("Rich Townsend");
84MODULE_DESCRIPTION("Smart Battery System ACPI interface driver"); 83MODULE_DESCRIPTION("Smart Battery System ACPI interface driver");
@@ -110,7 +109,7 @@ static void acpi_battery_smbus_err_handler(struct acpi_ec_smbus *smbus);
110static void acpi_sbs_update_queue(void *data); 109static void acpi_sbs_update_queue(void *data);
111 110
112static struct acpi_driver acpi_sbs_driver = { 111static struct acpi_driver acpi_sbs_driver = {
113 .name = ACPI_SBS_DRIVER_NAME, 112 .name = "sbs",
114 .class = ACPI_SBS_CLASS, 113 .class = ACPI_SBS_CLASS,
115 .ids = ACPI_SBS_HID, 114 .ids = ACPI_SBS_HID,
116 .ops = { 115 .ops = {
@@ -1034,21 +1033,19 @@ static int acpi_battery_read_state(struct seq_file *seq, void *offset)
1034 } else { 1033 } else {
1035 seq_printf(seq, "capacity state: ok\n"); 1034 seq_printf(seq, "capacity state: ok\n");
1036 } 1035 }
1036
1037 foo = (s16) battery->state.amperage * battery->info.ipscale;
1038 if (battery->info.capacity_mode) {
1039 foo = foo * battery->info.design_voltage / 1000;
1040 }
1037 if (battery->state.amperage < 0) { 1041 if (battery->state.amperage < 0) {
1038 seq_printf(seq, "charging state: discharging\n"); 1042 seq_printf(seq, "charging state: discharging\n");
1039 foo = battery->state.remaining_capacity * cscale * 60 / 1043 seq_printf(seq, "present rate: %d %s\n",
1040 (battery->state.average_time_to_empty == 0 ? 1 : 1044 -foo, battery->info.capacity_mode ? "mW" : "mA");
1041 battery->state.average_time_to_empty);
1042 seq_printf(seq, "present rate: %i%s\n",
1043 foo, battery->info.capacity_mode ? "0 mW" : " mA");
1044 } else if (battery->state.amperage > 0) { 1045 } else if (battery->state.amperage > 0) {
1045 seq_printf(seq, "charging state: charging\n"); 1046 seq_printf(seq, "charging state: charging\n");
1046 foo = (battery->info.full_charge_capacity - 1047 seq_printf(seq, "present rate: %d %s\n",
1047 battery->state.remaining_capacity) * cscale * 60 / 1048 foo, battery->info.capacity_mode ? "mW" : "mA");
1048 (battery->state.average_time_to_full == 0 ? 1 :
1049 battery->state.average_time_to_full);
1050 seq_printf(seq, "present rate: %i%s\n",
1051 foo, battery->info.capacity_mode ? "0 mW" : " mA");
1052 } else { 1049 } else {
1053 seq_printf(seq, "charging state: charged\n"); 1050 seq_printf(seq, "charging state: charged\n");
1054 seq_printf(seq, "present rate: 0 %s\n", 1051 seq_printf(seq, "present rate: 0 %s\n",
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 64f26db10c8e..bb0e0da39fb1 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -11,13 +11,12 @@
11#include <acpi/acinterp.h> /* for acpi_ex_eisa_id_to_string() */ 11#include <acpi/acinterp.h> /* for acpi_ex_eisa_id_to_string() */
12 12
13#define _COMPONENT ACPI_BUS_COMPONENT 13#define _COMPONENT ACPI_BUS_COMPONENT
14ACPI_MODULE_NAME("scan") 14ACPI_MODULE_NAME("scan");
15#define STRUCT_TO_INT(s) (*((int*)&s)) 15#define STRUCT_TO_INT(s) (*((int*)&s))
16extern struct acpi_device *acpi_root; 16extern struct acpi_device *acpi_root;
17 17
18#define ACPI_BUS_CLASS "system_bus" 18#define ACPI_BUS_CLASS "system_bus"
19#define ACPI_BUS_HID "ACPI_BUS" 19#define ACPI_BUS_HID "ACPI_BUS"
20#define ACPI_BUS_DRIVER_NAME "ACPI Bus Driver"
21#define ACPI_BUS_DEVICE_NAME "System Bus" 20#define ACPI_BUS_DEVICE_NAME "System Bus"
22 21
23static LIST_HEAD(acpi_device_list); 22static LIST_HEAD(acpi_device_list);
diff --git a/drivers/acpi/sleep/main.c b/drivers/acpi/sleep/main.c
index 62ce87d71651..37a0930fc0a6 100644
--- a/drivers/acpi/sleep/main.c
+++ b/drivers/acpi/sleep/main.c
@@ -200,7 +200,7 @@ static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
200 {}, 200 {},
201}; 201};
202 202
203static int __init acpi_sleep_init(void) 203int __init acpi_sleep_init(void)
204{ 204{
205 int i = 0; 205 int i = 0;
206 206
@@ -229,4 +229,3 @@ static int __init acpi_sleep_init(void)
229 return 0; 229 return 0;
230} 230}
231 231
232late_initcall(acpi_sleep_init);
diff --git a/drivers/acpi/system.c b/drivers/acpi/system.c
index 7147b0bdab0a..83a8d3097904 100644
--- a/drivers/acpi/system.c
+++ b/drivers/acpi/system.c
@@ -31,14 +31,13 @@
31#include <acpi/acpi_drivers.h> 31#include <acpi/acpi_drivers.h>
32 32
33#define _COMPONENT ACPI_SYSTEM_COMPONENT 33#define _COMPONENT ACPI_SYSTEM_COMPONENT
34ACPI_MODULE_NAME("acpi_system") 34ACPI_MODULE_NAME("system");
35#ifdef MODULE_PARAM_PREFIX 35#ifdef MODULE_PARAM_PREFIX
36#undef MODULE_PARAM_PREFIX 36#undef MODULE_PARAM_PREFIX
37#endif 37#endif
38#define MODULE_PARAM_PREFIX "acpi." 38#define MODULE_PARAM_PREFIX "acpi."
39 39
40#define ACPI_SYSTEM_CLASS "system" 40#define ACPI_SYSTEM_CLASS "system"
41#define ACPI_SYSTEM_DRIVER_NAME "ACPI System Driver"
42#define ACPI_SYSTEM_DEVICE_NAME "System" 41#define ACPI_SYSTEM_DEVICE_NAME "System"
43#define ACPI_SYSTEM_FILE_INFO "info" 42#define ACPI_SYSTEM_FILE_INFO "info"
44#define ACPI_SYSTEM_FILE_EVENT "event" 43#define ACPI_SYSTEM_FILE_EVENT "event"
diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
index 45bd17313c4a..849e2c361804 100644
--- a/drivers/acpi/tables.c
+++ b/drivers/acpi/tables.c
@@ -169,40 +169,40 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header * header)
169 169
170 170
171int __init 171int __init
172acpi_table_parse_madt_family(char *id, 172acpi_table_parse_entries(char *id,
173 unsigned long madt_size, 173 unsigned long table_size,
174 int entry_id, 174 int entry_id,
175 acpi_madt_entry_handler handler, 175 acpi_table_entry_handler handler,
176 unsigned int max_entries) 176 unsigned int max_entries)
177{ 177{
178 struct acpi_table_header *madt = NULL; 178 struct acpi_table_header *table_header = NULL;
179 struct acpi_subtable_header *entry; 179 struct acpi_subtable_header *entry;
180 unsigned int count = 0; 180 unsigned int count = 0;
181 unsigned long madt_end; 181 unsigned long table_end;
182 182
183 if (!handler) 183 if (!handler)
184 return -EINVAL; 184 return -EINVAL;
185 185
186 /* Locate the MADT (if exists). There should only be one. */ 186 /* Locate the table (if exists). There should only be one. */
187 acpi_get_table(id, 0, &madt); 187 acpi_get_table(id, 0, &table_header);
188 188
189 if (!madt) { 189 if (!table_header) {
190 printk(KERN_WARNING PREFIX "%4.4s not present\n", id); 190 printk(KERN_WARNING PREFIX "%4.4s not present\n", id);
191 return -ENODEV; 191 return -ENODEV;
192 } 192 }
193 193
194 madt_end = (unsigned long)madt + madt->length; 194 table_end = (unsigned long)table_header + table_header->length;
195 195
196 /* Parse all entries looking for a match. */ 196 /* Parse all entries looking for a match. */
197 197
198 entry = (struct acpi_subtable_header *) 198 entry = (struct acpi_subtable_header *)
199 ((unsigned long)madt + madt_size); 199 ((unsigned long)table_header + table_size);
200 200
201 while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) < 201 while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) <
202 madt_end) { 202 table_end) {
203 if (entry->type == entry_id 203 if (entry->type == entry_id
204 && (!max_entries || count++ < max_entries)) 204 && (!max_entries || count++ < max_entries))
205 if (handler(entry, madt_end)) 205 if (handler(entry, table_end))
206 return -EINVAL; 206 return -EINVAL;
207 207
208 entry = (struct acpi_subtable_header *) 208 entry = (struct acpi_subtable_header *)
@@ -218,13 +218,22 @@ acpi_table_parse_madt_family(char *id,
218 218
219int __init 219int __init
220acpi_table_parse_madt(enum acpi_madt_type id, 220acpi_table_parse_madt(enum acpi_madt_type id,
221 acpi_madt_entry_handler handler, unsigned int max_entries) 221 acpi_table_entry_handler handler, unsigned int max_entries)
222{ 222{
223 return acpi_table_parse_madt_family(ACPI_SIG_MADT, 223 return acpi_table_parse_entries(ACPI_SIG_MADT,
224 sizeof(struct acpi_table_madt), id, 224 sizeof(struct acpi_table_madt), id,
225 handler, max_entries); 225 handler, max_entries);
226} 226}
227 227
228/**
229 * acpi_table_parse - find table with @id, run @handler on it
230 *
231 * @id: table id to find
232 * @handler: handler to run
233 *
234 * Scan the ACPI System Descriptor Table (STD) for a table matching @id,
235 * run @handler on it. Return 0 if table found, return on if not.
236 */
228int __init acpi_table_parse(char *id, acpi_table_handler handler) 237int __init acpi_table_parse(char *id, acpi_table_handler handler)
229{ 238{
230 struct acpi_table_header *table = NULL; 239 struct acpi_table_header *table = NULL;
@@ -234,9 +243,9 @@ int __init acpi_table_parse(char *id, acpi_table_handler handler)
234 acpi_get_table(id, 0, &table); 243 acpi_get_table(id, 0, &table);
235 if (table) { 244 if (table) {
236 handler(table); 245 handler(table);
237 return 1;
238 } else
239 return 0; 246 return 0;
247 } else
248 return 1;
240} 249}
241 250
242/* 251/*
diff --git a/drivers/acpi/tables/tbxface.c b/drivers/acpi/tables/tbxface.c
index 807978d5381a..417ef5fa7666 100644
--- a/drivers/acpi/tables/tbxface.c
+++ b/drivers/acpi/tables/tbxface.c
@@ -338,9 +338,9 @@ acpi_status acpi_unload_table_id(acpi_owner_id id)
338 int i; 338 int i;
339 acpi_status status = AE_NOT_EXIST; 339 acpi_status status = AE_NOT_EXIST;
340 340
341 ACPI_FUNCTION_TRACE(acpi_unload_table); 341 ACPI_FUNCTION_TRACE(acpi_unload_table_id);
342 342
343 /* Find table from the requested type list */ 343 /* Find table in the global table list */
344 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) { 344 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
345 if (id != acpi_gbl_root_table_list.tables[i].owner_id) { 345 if (id != acpi_gbl_root_table_list.tables[i].owner_id) {
346 continue; 346 continue;
@@ -352,8 +352,9 @@ acpi_status acpi_unload_table_id(acpi_owner_id id)
352 * simply a position within the hierarchy 352 * simply a position within the hierarchy
353 */ 353 */
354 acpi_tb_delete_namespace_by_owner(i); 354 acpi_tb_delete_namespace_by_owner(i);
355 acpi_tb_release_owner_id(i); 355 status = acpi_tb_release_owner_id(i);
356 acpi_tb_set_table_loaded_flag(i, FALSE); 356 acpi_tb_set_table_loaded_flag(i, FALSE);
357 break;
357 } 358 }
358 return_ACPI_STATUS(status); 359 return_ACPI_STATUS(status);
359} 360}
@@ -408,7 +409,7 @@ acpi_get_table(char *signature,
408 } 409 }
409 410
410 if (!acpi_gbl_permanent_mmap) { 411 if (!acpi_gbl_permanent_mmap) {
411 acpi_gbl_root_table_list.tables[i].pointer = 0; 412 acpi_gbl_root_table_list.tables[i].pointer = NULL;
412 } 413 }
413 414
414 return (status); 415 return (status);
diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index 986afd470a14..0ae8b9310cbf 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -47,7 +47,6 @@
47 47
48#define ACPI_THERMAL_COMPONENT 0x04000000 48#define ACPI_THERMAL_COMPONENT 0x04000000
49#define ACPI_THERMAL_CLASS "thermal_zone" 49#define ACPI_THERMAL_CLASS "thermal_zone"
50#define ACPI_THERMAL_DRIVER_NAME "ACPI Thermal Zone Driver"
51#define ACPI_THERMAL_DEVICE_NAME "Thermal Zone" 50#define ACPI_THERMAL_DEVICE_NAME "Thermal Zone"
52#define ACPI_THERMAL_FILE_STATE "state" 51#define ACPI_THERMAL_FILE_STATE "state"
53#define ACPI_THERMAL_FILE_TEMPERATURE "temperature" 52#define ACPI_THERMAL_FILE_TEMPERATURE "temperature"
@@ -71,10 +70,10 @@
71#define CELSIUS_TO_KELVIN(t) ((t+273)*10) 70#define CELSIUS_TO_KELVIN(t) ((t+273)*10)
72 71
73#define _COMPONENT ACPI_THERMAL_COMPONENT 72#define _COMPONENT ACPI_THERMAL_COMPONENT
74ACPI_MODULE_NAME("acpi_thermal") 73ACPI_MODULE_NAME("thermal");
75 74
76MODULE_AUTHOR("Paul Diefenbaugh"); 75MODULE_AUTHOR("Paul Diefenbaugh");
77MODULE_DESCRIPTION(ACPI_THERMAL_DRIVER_NAME); 76MODULE_DESCRIPTION("ACPI Thermal Zone Driver");
78MODULE_LICENSE("GPL"); 77MODULE_LICENSE("GPL");
79 78
80static int tzp; 79static int tzp;
@@ -99,7 +98,7 @@ static ssize_t acpi_thermal_write_polling(struct file *, const char __user *,
99 size_t, loff_t *); 98 size_t, loff_t *);
100 99
101static struct acpi_driver acpi_thermal_driver = { 100static struct acpi_driver acpi_thermal_driver = {
102 .name = ACPI_THERMAL_DRIVER_NAME, 101 .name = "thermal",
103 .class = ACPI_THERMAL_CLASS, 102 .class = ACPI_THERMAL_CLASS,
104 .ids = ACPI_THERMAL_HID, 103 .ids = ACPI_THERMAL_HID,
105 .ops = { 104 .ops = {
@@ -270,7 +269,7 @@ static int acpi_thermal_set_polling(struct acpi_thermal *tz, int seconds)
270 269
271 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 270 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
272 "Polling frequency set to %lu seconds\n", 271 "Polling frequency set to %lu seconds\n",
273 tz->polling_frequency)); 272 tz->polling_frequency/10));
274 273
275 return 0; 274 return 0;
276} 275}
@@ -1357,28 +1356,32 @@ static int acpi_thermal_remove(struct acpi_device *device, int type)
1357static int acpi_thermal_resume(struct acpi_device *device) 1356static int acpi_thermal_resume(struct acpi_device *device)
1358{ 1357{
1359 struct acpi_thermal *tz = NULL; 1358 struct acpi_thermal *tz = NULL;
1360 int i; 1359 int i, j, power_state, result;
1360
1361 1361
1362 if (!device || !acpi_driver_data(device)) 1362 if (!device || !acpi_driver_data(device))
1363 return -EINVAL; 1363 return -EINVAL;
1364 1364
1365 tz = acpi_driver_data(device); 1365 tz = acpi_driver_data(device);
1366 1366
1367 acpi_thermal_get_temperature(tz);
1368
1369 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { 1367 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
1370 if (tz->trips.active[i].flags.valid) { 1368 if (!(&tz->trips.active[i]))
1371 tz->temperature = tz->trips.active[i].temperature; 1369 break;
1372 tz->trips.active[i].flags.enabled = 0; 1370 if (!tz->trips.active[i].flags.valid)
1373 1371 break;
1374 acpi_thermal_active(tz); 1372 tz->trips.active[i].flags.enabled = 1;
1375 1373 for (j = 0; j < tz->trips.active[i].devices.count; j++) {
1376 tz->state.active |= tz->trips.active[i].flags.enabled; 1374 result = acpi_bus_get_power(tz->trips.active[i].devices.
1377 tz->state.active_index = i; 1375 handles[j], &power_state);
1376 if (result || (power_state != ACPI_STATE_D0)) {
1377 tz->trips.active[i].flags.enabled = 0;
1378 break;
1379 }
1378 } 1380 }
1381 tz->state.active |= tz->trips.active[i].flags.enabled;
1379 } 1382 }
1380 1383
1381 acpi_thermal_check(tz); 1384 acpi_thermal_check(tz);
1382 1385
1383 return AE_OK; 1386 return AE_OK;
1384} 1387}
diff --git a/drivers/acpi/toshiba_acpi.c b/drivers/acpi/toshiba_acpi.c
index d9b651ffcdc0..faf8a5232d8e 100644
--- a/drivers/acpi/toshiba_acpi.c
+++ b/drivers/acpi/toshiba_acpi.c
@@ -125,7 +125,7 @@ static int write_acpi_int(const char *methodName, int val)
125 union acpi_object in_objs[1]; 125 union acpi_object in_objs[1];
126 acpi_status status; 126 acpi_status status;
127 127
128 params.count = sizeof(in_objs) / sizeof(in_objs[0]); 128 params.count = ARRAY_SIZE(in_objs);
129 params.pointer = in_objs; 129 params.pointer = in_objs;
130 in_objs[0].type = ACPI_TYPE_INTEGER; 130 in_objs[0].type = ACPI_TYPE_INTEGER;
131 in_objs[0].integer.value = val; 131 in_objs[0].integer.value = val;
@@ -561,10 +561,6 @@ static int __init toshiba_acpi_init(void)
561 if (acpi_disabled) 561 if (acpi_disabled)
562 return -ENODEV; 562 return -ENODEV;
563 563
564 if (!acpi_specific_hotkey_enabled) {
565 printk(MY_INFO "Using generic hotkey driver\n");
566 return -ENODEV;
567 }
568 /* simple device detection: look for HCI method */ 564 /* simple device detection: look for HCI method */
569 if (is_valid_acpi_path(METHOD_HCI_1)) 565 if (is_valid_acpi_path(METHOD_HCI_1))
570 method_hci = METHOD_HCI_1; 566 method_hci = METHOD_HCI_1;
diff --git a/drivers/acpi/utilities/utdelete.c b/drivers/acpi/utilities/utdelete.c
index f777cebdc46d..673a0caa4073 100644
--- a/drivers/acpi/utilities/utdelete.c
+++ b/drivers/acpi/utilities/utdelete.c
@@ -170,7 +170,6 @@ static void acpi_ut_delete_internal_obj(union acpi_operand_object *object)
170 acpi_os_delete_mutex(object->mutex.os_mutex); 170 acpi_os_delete_mutex(object->mutex.os_mutex);
171 acpi_gbl_global_lock_mutex = NULL; 171 acpi_gbl_global_lock_mutex = NULL;
172 } else { 172 } else {
173 acpi_ex_unlink_mutex(object);
174 acpi_os_delete_mutex(object->mutex.os_mutex); 173 acpi_os_delete_mutex(object->mutex.os_mutex);
175 } 174 }
176 break; 175 break;
diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index 68a809fa7b19..34f157571080 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -31,7 +31,7 @@
31#include <acpi/acpi_drivers.h> 31#include <acpi/acpi_drivers.h>
32 32
33#define _COMPONENT ACPI_BUS_COMPONENT 33#define _COMPONENT ACPI_BUS_COMPONENT
34ACPI_MODULE_NAME("acpi_utils") 34ACPI_MODULE_NAME("utils");
35 35
36/* -------------------------------------------------------------------------- 36/* --------------------------------------------------------------------------
37 Object Evaluation Helpers 37 Object Evaluation Helpers
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index e0b97add8c63..bf525cca3b63 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -40,7 +40,6 @@
40 40
41#define ACPI_VIDEO_COMPONENT 0x08000000 41#define ACPI_VIDEO_COMPONENT 0x08000000
42#define ACPI_VIDEO_CLASS "video" 42#define ACPI_VIDEO_CLASS "video"
43#define ACPI_VIDEO_DRIVER_NAME "ACPI Video Driver"
44#define ACPI_VIDEO_BUS_NAME "Video Bus" 43#define ACPI_VIDEO_BUS_NAME "Video Bus"
45#define ACPI_VIDEO_DEVICE_NAME "Video Device" 44#define ACPI_VIDEO_DEVICE_NAME "Video Device"
46#define ACPI_VIDEO_NOTIFY_SWITCH 0x80 45#define ACPI_VIDEO_NOTIFY_SWITCH 0x80
@@ -65,17 +64,17 @@
65#define ACPI_VIDEO_DISPLAY_LCD 4 64#define ACPI_VIDEO_DISPLAY_LCD 4
66 65
67#define _COMPONENT ACPI_VIDEO_COMPONENT 66#define _COMPONENT ACPI_VIDEO_COMPONENT
68ACPI_MODULE_NAME("acpi_video") 67ACPI_MODULE_NAME("video");
69 68
70 MODULE_AUTHOR("Bruno Ducrot"); 69MODULE_AUTHOR("Bruno Ducrot");
71MODULE_DESCRIPTION(ACPI_VIDEO_DRIVER_NAME); 70MODULE_DESCRIPTION("ACPI Video Driver");
72MODULE_LICENSE("GPL"); 71MODULE_LICENSE("GPL");
73 72
74static int acpi_video_bus_add(struct acpi_device *device); 73static int acpi_video_bus_add(struct acpi_device *device);
75static int acpi_video_bus_remove(struct acpi_device *device, int type); 74static int acpi_video_bus_remove(struct acpi_device *device, int type);
76 75
77static struct acpi_driver acpi_video_bus = { 76static struct acpi_driver acpi_video_bus = {
78 .name = ACPI_VIDEO_DRIVER_NAME, 77 .name = "video",
79 .class = ACPI_VIDEO_CLASS, 78 .class = ACPI_VIDEO_CLASS,
80 .ids = ACPI_VIDEO_HID, 79 .ids = ACPI_VIDEO_HID,
81 .ops = { 80 .ops = {
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 472810f8e6e7..253868e03c70 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -324,27 +324,25 @@ int bus_for_each_drv(struct bus_type * bus, struct device_driver * start,
324 return error; 324 return error;
325} 325}
326 326
327static int device_add_attrs(struct bus_type * bus, struct device * dev) 327static int device_add_attrs(struct bus_type *bus, struct device *dev)
328{ 328{
329 int error = 0; 329 int error = 0;
330 int i; 330 int i;
331 331
332 if (bus->dev_attrs) { 332 if (!bus->dev_attrs)
333 for (i = 0; attr_name(bus->dev_attrs[i]); i++) { 333 return 0;
334 error = device_create_file(dev,&bus->dev_attrs[i]); 334
335 if (error) 335 for (i = 0; attr_name(bus->dev_attrs[i]); i++) {
336 goto Err; 336 error = device_create_file(dev,&bus->dev_attrs[i]);
337 if (error) {
338 while (--i >= 0)
339 device_remove_file(dev, &bus->dev_attrs[i]);
340 break;
337 } 341 }
338 } 342 }
339 Done:
340 return error; 343 return error;
341 Err:
342 while (--i >= 0)
343 device_remove_file(dev,&bus->dev_attrs[i]);
344 goto Done;
345} 344}
346 345
347
348static void device_remove_attrs(struct bus_type * bus, struct device * dev) 346static void device_remove_attrs(struct bus_type * bus, struct device * dev)
349{ 347{
350 int i; 348 int i;
diff --git a/drivers/base/class.c b/drivers/base/class.c
index 96def1ddba19..1417e5cd4c6f 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -163,8 +163,7 @@ int class_register(struct class * cls)
163void class_unregister(struct class * cls) 163void class_unregister(struct class * cls)
164{ 164{
165 pr_debug("device class '%s': unregistering\n", cls->name); 165 pr_debug("device class '%s': unregistering\n", cls->name);
166 if (cls->virtual_dir) 166 kobject_unregister(cls->virtual_dir);
167 kobject_unregister(cls->virtual_dir);
168 remove_class_attrs(cls); 167 remove_class_attrs(cls);
169 subsystem_unregister(&cls->subsys); 168 subsystem_unregister(&cls->subsys);
170} 169}
diff --git a/drivers/infiniband/core/Makefile b/drivers/infiniband/core/Makefile
index 50fb1cd447b7..189e5d4b9b17 100644
--- a/drivers/infiniband/core/Makefile
+++ b/drivers/infiniband/core/Makefile
@@ -12,7 +12,7 @@ ib_core-y := packer.o ud_header.o verbs.o sysfs.o \
12 12
13ib_mad-y := mad.o smi.o agent.o mad_rmpp.o 13ib_mad-y := mad.o smi.o agent.o mad_rmpp.o
14 14
15ib_sa-y := sa_query.o 15ib_sa-y := sa_query.o multicast.o
16 16
17ib_cm-y := cm.o 17ib_cm-y := cm.o
18 18
diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index db88e609bf42..f8d69b3fa307 100644
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -71,6 +71,7 @@ static struct workqueue_struct *cma_wq;
71static DEFINE_IDR(sdp_ps); 71static DEFINE_IDR(sdp_ps);
72static DEFINE_IDR(tcp_ps); 72static DEFINE_IDR(tcp_ps);
73static DEFINE_IDR(udp_ps); 73static DEFINE_IDR(udp_ps);
74static DEFINE_IDR(ipoib_ps);
74static int next_port; 75static int next_port;
75 76
76struct cma_device { 77struct cma_device {
@@ -116,6 +117,7 @@ struct rdma_id_private {
116 struct list_head list; 117 struct list_head list;
117 struct list_head listen_list; 118 struct list_head listen_list;
118 struct cma_device *cma_dev; 119 struct cma_device *cma_dev;
120 struct list_head mc_list;
119 121
120 enum cma_state state; 122 enum cma_state state;
121 spinlock_t lock; 123 spinlock_t lock;
@@ -134,10 +136,23 @@ struct rdma_id_private {
134 } cm_id; 136 } cm_id;
135 137
136 u32 seq_num; 138 u32 seq_num;
139 u32 qkey;
137 u32 qp_num; 140 u32 qp_num;
138 u8 srq; 141 u8 srq;
139}; 142};
140 143
144struct cma_multicast {
145 struct rdma_id_private *id_priv;
146 union {
147 struct ib_sa_multicast *ib;
148 } multicast;
149 struct list_head list;
150 void *context;
151 struct sockaddr addr;
152 u8 pad[sizeof(struct sockaddr_in6) -
153 sizeof(struct sockaddr)];
154};
155
141struct cma_work { 156struct cma_work {
142 struct work_struct work; 157 struct work_struct work;
143 struct rdma_id_private *id; 158 struct rdma_id_private *id;
@@ -243,6 +258,11 @@ static inline void sdp_set_ip_ver(struct sdp_hh *hh, u8 ip_ver)
243 hh->ip_version = (ip_ver << 4) | (hh->ip_version & 0xF); 258 hh->ip_version = (ip_ver << 4) | (hh->ip_version & 0xF);
244} 259}
245 260
261static inline int cma_is_ud_ps(enum rdma_port_space ps)
262{
263 return (ps == RDMA_PS_UDP || ps == RDMA_PS_IPOIB);
264}
265
246static void cma_attach_to_dev(struct rdma_id_private *id_priv, 266static void cma_attach_to_dev(struct rdma_id_private *id_priv,
247 struct cma_device *cma_dev) 267 struct cma_device *cma_dev)
248{ 268{
@@ -265,19 +285,41 @@ static void cma_detach_from_dev(struct rdma_id_private *id_priv)
265 id_priv->cma_dev = NULL; 285 id_priv->cma_dev = NULL;
266} 286}
267 287
288static int cma_set_qkey(struct ib_device *device, u8 port_num,
289 enum rdma_port_space ps,
290 struct rdma_dev_addr *dev_addr, u32 *qkey)
291{
292 struct ib_sa_mcmember_rec rec;
293 int ret = 0;
294
295 switch (ps) {
296 case RDMA_PS_UDP:
297 *qkey = RDMA_UDP_QKEY;
298 break;
299 case RDMA_PS_IPOIB:
300 ib_addr_get_mgid(dev_addr, &rec.mgid);
301 ret = ib_sa_get_mcmember_rec(device, port_num, &rec.mgid, &rec);
302 *qkey = be32_to_cpu(rec.qkey);
303 break;
304 default:
305 break;
306 }
307 return ret;
308}
309
268static int cma_acquire_dev(struct rdma_id_private *id_priv) 310static int cma_acquire_dev(struct rdma_id_private *id_priv)
269{ 311{
270 enum rdma_node_type dev_type = id_priv->id.route.addr.dev_addr.dev_type; 312 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr;
271 struct cma_device *cma_dev; 313 struct cma_device *cma_dev;
272 union ib_gid gid; 314 union ib_gid gid;
273 int ret = -ENODEV; 315 int ret = -ENODEV;
274 316
275 switch (rdma_node_get_transport(dev_type)) { 317 switch (rdma_node_get_transport(dev_addr->dev_type)) {
276 case RDMA_TRANSPORT_IB: 318 case RDMA_TRANSPORT_IB:
277 ib_addr_get_sgid(&id_priv->id.route.addr.dev_addr, &gid); 319 ib_addr_get_sgid(dev_addr, &gid);
278 break; 320 break;
279 case RDMA_TRANSPORT_IWARP: 321 case RDMA_TRANSPORT_IWARP:
280 iw_addr_get_sgid(&id_priv->id.route.addr.dev_addr, &gid); 322 iw_addr_get_sgid(dev_addr, &gid);
281 break; 323 break;
282 default: 324 default:
283 return -ENODEV; 325 return -ENODEV;
@@ -287,7 +329,12 @@ static int cma_acquire_dev(struct rdma_id_private *id_priv)
287 ret = ib_find_cached_gid(cma_dev->device, &gid, 329 ret = ib_find_cached_gid(cma_dev->device, &gid,
288 &id_priv->id.port_num, NULL); 330 &id_priv->id.port_num, NULL);
289 if (!ret) { 331 if (!ret) {
290 cma_attach_to_dev(id_priv, cma_dev); 332 ret = cma_set_qkey(cma_dev->device,
333 id_priv->id.port_num,
334 id_priv->id.ps, dev_addr,
335 &id_priv->qkey);
336 if (!ret)
337 cma_attach_to_dev(id_priv, cma_dev);
291 break; 338 break;
292 } 339 }
293 } 340 }
@@ -325,40 +372,50 @@ struct rdma_cm_id *rdma_create_id(rdma_cm_event_handler event_handler,
325 init_waitqueue_head(&id_priv->wait_remove); 372 init_waitqueue_head(&id_priv->wait_remove);
326 atomic_set(&id_priv->dev_remove, 0); 373 atomic_set(&id_priv->dev_remove, 0);
327 INIT_LIST_HEAD(&id_priv->listen_list); 374 INIT_LIST_HEAD(&id_priv->listen_list);
375 INIT_LIST_HEAD(&id_priv->mc_list);
328 get_random_bytes(&id_priv->seq_num, sizeof id_priv->seq_num); 376 get_random_bytes(&id_priv->seq_num, sizeof id_priv->seq_num);
329 377
330 return &id_priv->id; 378 return &id_priv->id;
331} 379}
332EXPORT_SYMBOL(rdma_create_id); 380EXPORT_SYMBOL(rdma_create_id);
333 381
334static int cma_init_ib_qp(struct rdma_id_private *id_priv, struct ib_qp *qp) 382static int cma_init_ud_qp(struct rdma_id_private *id_priv, struct ib_qp *qp)
335{ 383{
336 struct ib_qp_attr qp_attr; 384 struct ib_qp_attr qp_attr;
337 struct rdma_dev_addr *dev_addr; 385 int qp_attr_mask, ret;
338 int ret;
339 386
340 dev_addr = &id_priv->id.route.addr.dev_addr; 387 qp_attr.qp_state = IB_QPS_INIT;
341 ret = ib_find_cached_pkey(id_priv->id.device, id_priv->id.port_num, 388 ret = rdma_init_qp_attr(&id_priv->id, &qp_attr, &qp_attr_mask);
342 ib_addr_get_pkey(dev_addr),
343 &qp_attr.pkey_index);
344 if (ret) 389 if (ret)
345 return ret; 390 return ret;
346 391
347 qp_attr.qp_state = IB_QPS_INIT; 392 ret = ib_modify_qp(qp, &qp_attr, qp_attr_mask);
348 qp_attr.qp_access_flags = 0; 393 if (ret)
349 qp_attr.port_num = id_priv->id.port_num; 394 return ret;
350 return ib_modify_qp(qp, &qp_attr, IB_QP_STATE | IB_QP_ACCESS_FLAGS | 395
351 IB_QP_PKEY_INDEX | IB_QP_PORT); 396 qp_attr.qp_state = IB_QPS_RTR;
397 ret = ib_modify_qp(qp, &qp_attr, IB_QP_STATE);
398 if (ret)
399 return ret;
400
401 qp_attr.qp_state = IB_QPS_RTS;
402 qp_attr.sq_psn = 0;
403 ret = ib_modify_qp(qp, &qp_attr, IB_QP_STATE | IB_QP_SQ_PSN);
404
405 return ret;
352} 406}
353 407
354static int cma_init_iw_qp(struct rdma_id_private *id_priv, struct ib_qp *qp) 408static int cma_init_conn_qp(struct rdma_id_private *id_priv, struct ib_qp *qp)
355{ 409{
356 struct ib_qp_attr qp_attr; 410 struct ib_qp_attr qp_attr;
411 int qp_attr_mask, ret;
357 412
358 qp_attr.qp_state = IB_QPS_INIT; 413 qp_attr.qp_state = IB_QPS_INIT;
359 qp_attr.qp_access_flags = IB_ACCESS_LOCAL_WRITE; 414 ret = rdma_init_qp_attr(&id_priv->id, &qp_attr, &qp_attr_mask);
415 if (ret)
416 return ret;
360 417
361 return ib_modify_qp(qp, &qp_attr, IB_QP_STATE | IB_QP_ACCESS_FLAGS); 418 return ib_modify_qp(qp, &qp_attr, qp_attr_mask);
362} 419}
363 420
364int rdma_create_qp(struct rdma_cm_id *id, struct ib_pd *pd, 421int rdma_create_qp(struct rdma_cm_id *id, struct ib_pd *pd,
@@ -376,18 +433,10 @@ int rdma_create_qp(struct rdma_cm_id *id, struct ib_pd *pd,
376 if (IS_ERR(qp)) 433 if (IS_ERR(qp))
377 return PTR_ERR(qp); 434 return PTR_ERR(qp);
378 435
379 switch (rdma_node_get_transport(id->device->node_type)) { 436 if (cma_is_ud_ps(id_priv->id.ps))
380 case RDMA_TRANSPORT_IB: 437 ret = cma_init_ud_qp(id_priv, qp);
381 ret = cma_init_ib_qp(id_priv, qp); 438 else
382 break; 439 ret = cma_init_conn_qp(id_priv, qp);
383 case RDMA_TRANSPORT_IWARP:
384 ret = cma_init_iw_qp(id_priv, qp);
385 break;
386 default:
387 ret = -ENOSYS;
388 break;
389 }
390
391 if (ret) 440 if (ret)
392 goto err; 441 goto err;
393 442
@@ -460,23 +509,55 @@ static int cma_modify_qp_err(struct rdma_cm_id *id)
460 return ib_modify_qp(id->qp, &qp_attr, IB_QP_STATE); 509 return ib_modify_qp(id->qp, &qp_attr, IB_QP_STATE);
461} 510}
462 511
512static int cma_ib_init_qp_attr(struct rdma_id_private *id_priv,
513 struct ib_qp_attr *qp_attr, int *qp_attr_mask)
514{
515 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr;
516 int ret;
517
518 ret = ib_find_cached_pkey(id_priv->id.device, id_priv->id.port_num,
519 ib_addr_get_pkey(dev_addr),
520 &qp_attr->pkey_index);
521 if (ret)
522 return ret;
523
524 qp_attr->port_num = id_priv->id.port_num;
525 *qp_attr_mask = IB_QP_STATE | IB_QP_PKEY_INDEX | IB_QP_PORT;
526
527 if (cma_is_ud_ps(id_priv->id.ps)) {
528 qp_attr->qkey = id_priv->qkey;
529 *qp_attr_mask |= IB_QP_QKEY;
530 } else {
531 qp_attr->qp_access_flags = 0;
532 *qp_attr_mask |= IB_QP_ACCESS_FLAGS;
533 }
534 return 0;
535}
536
463int rdma_init_qp_attr(struct rdma_cm_id *id, struct ib_qp_attr *qp_attr, 537int rdma_init_qp_attr(struct rdma_cm_id *id, struct ib_qp_attr *qp_attr,
464 int *qp_attr_mask) 538 int *qp_attr_mask)
465{ 539{
466 struct rdma_id_private *id_priv; 540 struct rdma_id_private *id_priv;
467 int ret; 541 int ret = 0;
468 542
469 id_priv = container_of(id, struct rdma_id_private, id); 543 id_priv = container_of(id, struct rdma_id_private, id);
470 switch (rdma_node_get_transport(id_priv->id.device->node_type)) { 544 switch (rdma_node_get_transport(id_priv->id.device->node_type)) {
471 case RDMA_TRANSPORT_IB: 545 case RDMA_TRANSPORT_IB:
472 ret = ib_cm_init_qp_attr(id_priv->cm_id.ib, qp_attr, 546 if (!id_priv->cm_id.ib || cma_is_ud_ps(id_priv->id.ps))
473 qp_attr_mask); 547 ret = cma_ib_init_qp_attr(id_priv, qp_attr, qp_attr_mask);
548 else
549 ret = ib_cm_init_qp_attr(id_priv->cm_id.ib, qp_attr,
550 qp_attr_mask);
474 if (qp_attr->qp_state == IB_QPS_RTR) 551 if (qp_attr->qp_state == IB_QPS_RTR)
475 qp_attr->rq_psn = id_priv->seq_num; 552 qp_attr->rq_psn = id_priv->seq_num;
476 break; 553 break;
477 case RDMA_TRANSPORT_IWARP: 554 case RDMA_TRANSPORT_IWARP:
478 ret = iw_cm_init_qp_attr(id_priv->cm_id.iw, qp_attr, 555 if (!id_priv->cm_id.iw) {
479 qp_attr_mask); 556 qp_attr->qp_access_flags = IB_ACCESS_LOCAL_WRITE;
557 *qp_attr_mask = IB_QP_STATE | IB_QP_ACCESS_FLAGS;
558 } else
559 ret = iw_cm_init_qp_attr(id_priv->cm_id.iw, qp_attr,
560 qp_attr_mask);
480 break; 561 break;
481 default: 562 default:
482 ret = -ENOSYS; 563 ret = -ENOSYS;
@@ -698,6 +779,19 @@ static void cma_release_port(struct rdma_id_private *id_priv)
698 mutex_unlock(&lock); 779 mutex_unlock(&lock);
699} 780}
700 781
782static void cma_leave_mc_groups(struct rdma_id_private *id_priv)
783{
784 struct cma_multicast *mc;
785
786 while (!list_empty(&id_priv->mc_list)) {
787 mc = container_of(id_priv->mc_list.next,
788 struct cma_multicast, list);
789 list_del(&mc->list);
790 ib_sa_free_multicast(mc->multicast.ib);
791 kfree(mc);
792 }
793}
794
701void rdma_destroy_id(struct rdma_cm_id *id) 795void rdma_destroy_id(struct rdma_cm_id *id)
702{ 796{
703 struct rdma_id_private *id_priv; 797 struct rdma_id_private *id_priv;
@@ -722,6 +816,7 @@ void rdma_destroy_id(struct rdma_cm_id *id)
722 default: 816 default:
723 break; 817 break;
724 } 818 }
819 cma_leave_mc_groups(id_priv);
725 mutex_lock(&lock); 820 mutex_lock(&lock);
726 cma_detach_from_dev(id_priv); 821 cma_detach_from_dev(id_priv);
727 } 822 }
@@ -972,7 +1067,7 @@ static int cma_req_handler(struct ib_cm_id *cm_id, struct ib_cm_event *ib_event)
972 memset(&event, 0, sizeof event); 1067 memset(&event, 0, sizeof event);
973 offset = cma_user_data_offset(listen_id->id.ps); 1068 offset = cma_user_data_offset(listen_id->id.ps);
974 event.event = RDMA_CM_EVENT_CONNECT_REQUEST; 1069 event.event = RDMA_CM_EVENT_CONNECT_REQUEST;
975 if (listen_id->id.ps == RDMA_PS_UDP) { 1070 if (cma_is_ud_ps(listen_id->id.ps)) {
976 conn_id = cma_new_udp_id(&listen_id->id, ib_event); 1071 conn_id = cma_new_udp_id(&listen_id->id, ib_event);
977 event.param.ud.private_data = ib_event->private_data + offset; 1072 event.param.ud.private_data = ib_event->private_data + offset;
978 event.param.ud.private_data_len = 1073 event.param.ud.private_data_len =
@@ -1725,7 +1820,7 @@ static int cma_alloc_port(struct idr *ps, struct rdma_id_private *id_priv,
1725 struct rdma_bind_list *bind_list; 1820 struct rdma_bind_list *bind_list;
1726 int port, ret; 1821 int port, ret;
1727 1822
1728 bind_list = kzalloc(sizeof *bind_list, GFP_KERNEL); 1823 bind_list = kmalloc(sizeof *bind_list, GFP_KERNEL);
1729 if (!bind_list) 1824 if (!bind_list)
1730 return -ENOMEM; 1825 return -ENOMEM;
1731 1826
@@ -1847,6 +1942,9 @@ static int cma_get_port(struct rdma_id_private *id_priv)
1847 case RDMA_PS_UDP: 1942 case RDMA_PS_UDP:
1848 ps = &udp_ps; 1943 ps = &udp_ps;
1849 break; 1944 break;
1945 case RDMA_PS_IPOIB:
1946 ps = &ipoib_ps;
1947 break;
1850 default: 1948 default:
1851 return -EPROTONOSUPPORT; 1949 return -EPROTONOSUPPORT;
1852 } 1950 }
@@ -1961,7 +2059,7 @@ static int cma_sidr_rep_handler(struct ib_cm_id *cm_id,
1961 event.status = ib_event->param.sidr_rep_rcvd.status; 2059 event.status = ib_event->param.sidr_rep_rcvd.status;
1962 break; 2060 break;
1963 } 2061 }
1964 if (rep->qkey != RDMA_UD_QKEY) { 2062 if (id_priv->qkey != rep->qkey) {
1965 event.event = RDMA_CM_EVENT_UNREACHABLE; 2063 event.event = RDMA_CM_EVENT_UNREACHABLE;
1966 event.status = -EINVAL; 2064 event.status = -EINVAL;
1967 break; 2065 break;
@@ -2160,7 +2258,7 @@ int rdma_connect(struct rdma_cm_id *id, struct rdma_conn_param *conn_param)
2160 2258
2161 switch (rdma_node_get_transport(id->device->node_type)) { 2259 switch (rdma_node_get_transport(id->device->node_type)) {
2162 case RDMA_TRANSPORT_IB: 2260 case RDMA_TRANSPORT_IB:
2163 if (id->ps == RDMA_PS_UDP) 2261 if (cma_is_ud_ps(id->ps))
2164 ret = cma_resolve_ib_udp(id_priv, conn_param); 2262 ret = cma_resolve_ib_udp(id_priv, conn_param);
2165 else 2263 else
2166 ret = cma_connect_ib(id_priv, conn_param); 2264 ret = cma_connect_ib(id_priv, conn_param);
@@ -2256,7 +2354,7 @@ static int cma_send_sidr_rep(struct rdma_id_private *id_priv,
2256 rep.status = status; 2354 rep.status = status;
2257 if (status == IB_SIDR_SUCCESS) { 2355 if (status == IB_SIDR_SUCCESS) {
2258 rep.qp_num = id_priv->qp_num; 2356 rep.qp_num = id_priv->qp_num;
2259 rep.qkey = RDMA_UD_QKEY; 2357 rep.qkey = id_priv->qkey;
2260 } 2358 }
2261 rep.private_data = private_data; 2359 rep.private_data = private_data;
2262 rep.private_data_len = private_data_len; 2360 rep.private_data_len = private_data_len;
@@ -2280,7 +2378,7 @@ int rdma_accept(struct rdma_cm_id *id, struct rdma_conn_param *conn_param)
2280 2378
2281 switch (rdma_node_get_transport(id->device->node_type)) { 2379 switch (rdma_node_get_transport(id->device->node_type)) {
2282 case RDMA_TRANSPORT_IB: 2380 case RDMA_TRANSPORT_IB:
2283 if (id->ps == RDMA_PS_UDP) 2381 if (cma_is_ud_ps(id->ps))
2284 ret = cma_send_sidr_rep(id_priv, IB_SIDR_SUCCESS, 2382 ret = cma_send_sidr_rep(id_priv, IB_SIDR_SUCCESS,
2285 conn_param->private_data, 2383 conn_param->private_data,
2286 conn_param->private_data_len); 2384 conn_param->private_data_len);
@@ -2341,7 +2439,7 @@ int rdma_reject(struct rdma_cm_id *id, const void *private_data,
2341 2439
2342 switch (rdma_node_get_transport(id->device->node_type)) { 2440 switch (rdma_node_get_transport(id->device->node_type)) {
2343 case RDMA_TRANSPORT_IB: 2441 case RDMA_TRANSPORT_IB:
2344 if (id->ps == RDMA_PS_UDP) 2442 if (cma_is_ud_ps(id->ps))
2345 ret = cma_send_sidr_rep(id_priv, IB_SIDR_REJECT, 2443 ret = cma_send_sidr_rep(id_priv, IB_SIDR_REJECT,
2346 private_data, private_data_len); 2444 private_data, private_data_len);
2347 else 2445 else
@@ -2392,6 +2490,178 @@ out:
2392} 2490}
2393EXPORT_SYMBOL(rdma_disconnect); 2491EXPORT_SYMBOL(rdma_disconnect);
2394 2492
2493static int cma_ib_mc_handler(int status, struct ib_sa_multicast *multicast)
2494{
2495 struct rdma_id_private *id_priv;
2496 struct cma_multicast *mc = multicast->context;
2497 struct rdma_cm_event event;
2498 int ret;
2499
2500 id_priv = mc->id_priv;
2501 atomic_inc(&id_priv->dev_remove);
2502 if (!cma_comp(id_priv, CMA_ADDR_BOUND) &&
2503 !cma_comp(id_priv, CMA_ADDR_RESOLVED))
2504 goto out;
2505
2506 if (!status && id_priv->id.qp)
2507 status = ib_attach_mcast(id_priv->id.qp, &multicast->rec.mgid,
2508 multicast->rec.mlid);
2509
2510 memset(&event, 0, sizeof event);
2511 event.status = status;
2512 event.param.ud.private_data = mc->context;
2513 if (!status) {
2514 event.event = RDMA_CM_EVENT_MULTICAST_JOIN;
2515 ib_init_ah_from_mcmember(id_priv->id.device,
2516 id_priv->id.port_num, &multicast->rec,
2517 &event.param.ud.ah_attr);
2518 event.param.ud.qp_num = 0xFFFFFF;
2519 event.param.ud.qkey = be32_to_cpu(multicast->rec.qkey);
2520 } else
2521 event.event = RDMA_CM_EVENT_MULTICAST_ERROR;
2522
2523 ret = id_priv->id.event_handler(&id_priv->id, &event);
2524 if (ret) {
2525 cma_exch(id_priv, CMA_DESTROYING);
2526 cma_release_remove(id_priv);
2527 rdma_destroy_id(&id_priv->id);
2528 return 0;
2529 }
2530out:
2531 cma_release_remove(id_priv);
2532 return 0;
2533}
2534
2535static void cma_set_mgid(struct rdma_id_private *id_priv,
2536 struct sockaddr *addr, union ib_gid *mgid)
2537{
2538 unsigned char mc_map[MAX_ADDR_LEN];
2539 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr;
2540 struct sockaddr_in *sin = (struct sockaddr_in *) addr;
2541 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) addr;
2542
2543 if (cma_any_addr(addr)) {
2544 memset(mgid, 0, sizeof *mgid);
2545 } else if ((addr->sa_family == AF_INET6) &&
2546 ((be32_to_cpu(sin6->sin6_addr.s6_addr32[0]) & 0xFF10A01B) ==
2547 0xFF10A01B)) {
2548 /* IPv6 address is an SA assigned MGID. */
2549 memcpy(mgid, &sin6->sin6_addr, sizeof *mgid);
2550 } else {
2551 ip_ib_mc_map(sin->sin_addr.s_addr, mc_map);
2552 if (id_priv->id.ps == RDMA_PS_UDP)
2553 mc_map[7] = 0x01; /* Use RDMA CM signature */
2554 mc_map[8] = ib_addr_get_pkey(dev_addr) >> 8;
2555 mc_map[9] = (unsigned char) ib_addr_get_pkey(dev_addr);
2556 *mgid = *(union ib_gid *) (mc_map + 4);
2557 }
2558}
2559
2560static int cma_join_ib_multicast(struct rdma_id_private *id_priv,
2561 struct cma_multicast *mc)
2562{
2563 struct ib_sa_mcmember_rec rec;
2564 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr;
2565 ib_sa_comp_mask comp_mask;
2566 int ret;
2567
2568 ib_addr_get_mgid(dev_addr, &rec.mgid);
2569 ret = ib_sa_get_mcmember_rec(id_priv->id.device, id_priv->id.port_num,
2570 &rec.mgid, &rec);
2571 if (ret)
2572 return ret;
2573
2574 cma_set_mgid(id_priv, &mc->addr, &rec.mgid);
2575 if (id_priv->id.ps == RDMA_PS_UDP)
2576 rec.qkey = cpu_to_be32(RDMA_UDP_QKEY);
2577 ib_addr_get_sgid(dev_addr, &rec.port_gid);
2578 rec.pkey = cpu_to_be16(ib_addr_get_pkey(dev_addr));
2579 rec.join_state = 1;
2580
2581 comp_mask = IB_SA_MCMEMBER_REC_MGID | IB_SA_MCMEMBER_REC_PORT_GID |
2582 IB_SA_MCMEMBER_REC_PKEY | IB_SA_MCMEMBER_REC_JOIN_STATE |
2583 IB_SA_MCMEMBER_REC_QKEY | IB_SA_MCMEMBER_REC_SL |
2584 IB_SA_MCMEMBER_REC_FLOW_LABEL |
2585 IB_SA_MCMEMBER_REC_TRAFFIC_CLASS;
2586
2587 mc->multicast.ib = ib_sa_join_multicast(&sa_client, id_priv->id.device,
2588 id_priv->id.port_num, &rec,
2589 comp_mask, GFP_KERNEL,
2590 cma_ib_mc_handler, mc);
2591 if (IS_ERR(mc->multicast.ib))
2592 return PTR_ERR(mc->multicast.ib);
2593
2594 return 0;
2595}
2596
2597int rdma_join_multicast(struct rdma_cm_id *id, struct sockaddr *addr,
2598 void *context)
2599{
2600 struct rdma_id_private *id_priv;
2601 struct cma_multicast *mc;
2602 int ret;
2603
2604 id_priv = container_of(id, struct rdma_id_private, id);
2605 if (!cma_comp(id_priv, CMA_ADDR_BOUND) &&
2606 !cma_comp(id_priv, CMA_ADDR_RESOLVED))
2607 return -EINVAL;
2608
2609 mc = kmalloc(sizeof *mc, GFP_KERNEL);
2610 if (!mc)
2611 return -ENOMEM;
2612
2613 memcpy(&mc->addr, addr, ip_addr_size(addr));
2614 mc->context = context;
2615 mc->id_priv = id_priv;
2616
2617 spin_lock(&id_priv->lock);
2618 list_add(&mc->list, &id_priv->mc_list);
2619 spin_unlock(&id_priv->lock);
2620
2621 switch (rdma_node_get_transport(id->device->node_type)) {
2622 case RDMA_TRANSPORT_IB:
2623 ret = cma_join_ib_multicast(id_priv, mc);
2624 break;
2625 default:
2626 ret = -ENOSYS;
2627 break;
2628 }
2629
2630 if (ret) {
2631 spin_lock_irq(&id_priv->lock);
2632 list_del(&mc->list);
2633 spin_unlock_irq(&id_priv->lock);
2634 kfree(mc);
2635 }
2636 return ret;
2637}
2638EXPORT_SYMBOL(rdma_join_multicast);
2639
2640void rdma_leave_multicast(struct rdma_cm_id *id, struct sockaddr *addr)
2641{
2642 struct rdma_id_private *id_priv;
2643 struct cma_multicast *mc;
2644
2645 id_priv = container_of(id, struct rdma_id_private, id);
2646 spin_lock_irq(&id_priv->lock);
2647 list_for_each_entry(mc, &id_priv->mc_list, list) {
2648 if (!memcmp(&mc->addr, addr, ip_addr_size(addr))) {
2649 list_del(&mc->list);
2650 spin_unlock_irq(&id_priv->lock);
2651
2652 if (id->qp)
2653 ib_detach_mcast(id->qp,
2654 &mc->multicast.ib->rec.mgid,
2655 mc->multicast.ib->rec.mlid);
2656 ib_sa_free_multicast(mc->multicast.ib);
2657 kfree(mc);
2658 return;
2659 }
2660 }
2661 spin_unlock_irq(&id_priv->lock);
2662}
2663EXPORT_SYMBOL(rdma_leave_multicast);
2664
2395static void cma_add_one(struct ib_device *device) 2665static void cma_add_one(struct ib_device *device)
2396{ 2666{
2397 struct cma_device *cma_dev; 2667 struct cma_device *cma_dev;
@@ -2522,6 +2792,7 @@ static void cma_cleanup(void)
2522 idr_destroy(&sdp_ps); 2792 idr_destroy(&sdp_ps);
2523 idr_destroy(&tcp_ps); 2793 idr_destroy(&tcp_ps);
2524 idr_destroy(&udp_ps); 2794 idr_destroy(&udp_ps);
2795 idr_destroy(&ipoib_ps);
2525} 2796}
2526 2797
2527module_init(cma_init); 2798module_init(cma_init);
diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
index 8926a2bd4a87..1d796e7c8199 100644
--- a/drivers/infiniband/core/fmr_pool.c
+++ b/drivers/infiniband/core/fmr_pool.c
@@ -301,7 +301,7 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
301 301
302 { 302 {
303 struct ib_pool_fmr *fmr; 303 struct ib_pool_fmr *fmr;
304 struct ib_fmr_attr attr = { 304 struct ib_fmr_attr fmr_attr = {
305 .max_pages = params->max_pages_per_fmr, 305 .max_pages = params->max_pages_per_fmr,
306 .max_maps = pool->max_remaps, 306 .max_maps = pool->max_remaps,
307 .page_shift = params->page_shift 307 .page_shift = params->page_shift
@@ -321,7 +321,7 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
321 fmr->ref_count = 0; 321 fmr->ref_count = 0;
322 INIT_HLIST_NODE(&fmr->cache_node); 322 INIT_HLIST_NODE(&fmr->cache_node);
323 323
324 fmr->fmr = ib_alloc_fmr(pd, params->access, &attr); 324 fmr->fmr = ib_alloc_fmr(pd, params->access, &fmr_attr);
325 if (IS_ERR(fmr->fmr)) { 325 if (IS_ERR(fmr->fmr)) {
326 printk(KERN_WARNING "fmr_create failed for FMR %d", i); 326 printk(KERN_WARNING "fmr_create failed for FMR %d", i);
327 kfree(fmr); 327 kfree(fmr);
diff --git a/drivers/infiniband/core/iwcm.c b/drivers/infiniband/core/iwcm.c
index 1039ad57d53b..891d1fa7b2eb 100644
--- a/drivers/infiniband/core/iwcm.c
+++ b/drivers/infiniband/core/iwcm.c
@@ -146,6 +146,12 @@ static int copy_private_data(struct iw_cm_event *event)
146 return 0; 146 return 0;
147} 147}
148 148
149static void free_cm_id(struct iwcm_id_private *cm_id_priv)
150{
151 dealloc_work_entries(cm_id_priv);
152 kfree(cm_id_priv);
153}
154
149/* 155/*
150 * Release a reference on cm_id. If the last reference is being 156 * Release a reference on cm_id. If the last reference is being
151 * released, enable the waiting thread (in iw_destroy_cm_id) to 157 * released, enable the waiting thread (in iw_destroy_cm_id) to
@@ -153,21 +159,14 @@ static int copy_private_data(struct iw_cm_event *event)
153 */ 159 */
154static int iwcm_deref_id(struct iwcm_id_private *cm_id_priv) 160static int iwcm_deref_id(struct iwcm_id_private *cm_id_priv)
155{ 161{
156 int ret = 0;
157
158 BUG_ON(atomic_read(&cm_id_priv->refcount)==0); 162 BUG_ON(atomic_read(&cm_id_priv->refcount)==0);
159 if (atomic_dec_and_test(&cm_id_priv->refcount)) { 163 if (atomic_dec_and_test(&cm_id_priv->refcount)) {
160 BUG_ON(!list_empty(&cm_id_priv->work_list)); 164 BUG_ON(!list_empty(&cm_id_priv->work_list));
161 if (waitqueue_active(&cm_id_priv->destroy_comp.wait)) {
162 BUG_ON(cm_id_priv->state != IW_CM_STATE_DESTROYING);
163 BUG_ON(test_bit(IWCM_F_CALLBACK_DESTROY,
164 &cm_id_priv->flags));
165 ret = 1;
166 }
167 complete(&cm_id_priv->destroy_comp); 165 complete(&cm_id_priv->destroy_comp);
166 return 1;
168 } 167 }
169 168
170 return ret; 169 return 0;
171} 170}
172 171
173static void add_ref(struct iw_cm_id *cm_id) 172static void add_ref(struct iw_cm_id *cm_id)
@@ -181,7 +180,11 @@ static void rem_ref(struct iw_cm_id *cm_id)
181{ 180{
182 struct iwcm_id_private *cm_id_priv; 181 struct iwcm_id_private *cm_id_priv;
183 cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); 182 cm_id_priv = container_of(cm_id, struct iwcm_id_private, id);
184 iwcm_deref_id(cm_id_priv); 183 if (iwcm_deref_id(cm_id_priv) &&
184 test_bit(IWCM_F_CALLBACK_DESTROY, &cm_id_priv->flags)) {
185 BUG_ON(!list_empty(&cm_id_priv->work_list));
186 free_cm_id(cm_id_priv);
187 }
185} 188}
186 189
187static int cm_event_handler(struct iw_cm_id *cm_id, struct iw_cm_event *event); 190static int cm_event_handler(struct iw_cm_id *cm_id, struct iw_cm_event *event);
@@ -355,7 +358,9 @@ static void destroy_cm_id(struct iw_cm_id *cm_id)
355 case IW_CM_STATE_CONN_RECV: 358 case IW_CM_STATE_CONN_RECV:
356 /* 359 /*
357 * App called destroy before/without calling accept after 360 * App called destroy before/without calling accept after
358 * receiving connection request event notification. 361 * receiving connection request event notification or
362 * returned non zero from the event callback function.
363 * In either case, must tell the provider to reject.
359 */ 364 */
360 cm_id_priv->state = IW_CM_STATE_DESTROYING; 365 cm_id_priv->state = IW_CM_STATE_DESTROYING;
361 break; 366 break;
@@ -391,9 +396,7 @@ void iw_destroy_cm_id(struct iw_cm_id *cm_id)
391 396
392 wait_for_completion(&cm_id_priv->destroy_comp); 397 wait_for_completion(&cm_id_priv->destroy_comp);
393 398
394 dealloc_work_entries(cm_id_priv); 399 free_cm_id(cm_id_priv);
395
396 kfree(cm_id_priv);
397} 400}
398EXPORT_SYMBOL(iw_destroy_cm_id); 401EXPORT_SYMBOL(iw_destroy_cm_id);
399 402
@@ -647,10 +650,11 @@ static void cm_conn_req_handler(struct iwcm_id_private *listen_id_priv,
647 /* Call the client CM handler */ 650 /* Call the client CM handler */
648 ret = cm_id->cm_handler(cm_id, iw_event); 651 ret = cm_id->cm_handler(cm_id, iw_event);
649 if (ret) { 652 if (ret) {
653 iw_cm_reject(cm_id, NULL, 0);
650 set_bit(IWCM_F_CALLBACK_DESTROY, &cm_id_priv->flags); 654 set_bit(IWCM_F_CALLBACK_DESTROY, &cm_id_priv->flags);
651 destroy_cm_id(cm_id); 655 destroy_cm_id(cm_id);
652 if (atomic_read(&cm_id_priv->refcount)==0) 656 if (atomic_read(&cm_id_priv->refcount)==0)
653 kfree(cm_id); 657 free_cm_id(cm_id_priv);
654 } 658 }
655 659
656out: 660out:
@@ -854,13 +858,12 @@ static void cm_work_handler(struct work_struct *_work)
854 destroy_cm_id(&cm_id_priv->id); 858 destroy_cm_id(&cm_id_priv->id);
855 } 859 }
856 BUG_ON(atomic_read(&cm_id_priv->refcount)==0); 860 BUG_ON(atomic_read(&cm_id_priv->refcount)==0);
857 if (iwcm_deref_id(cm_id_priv)) 861 if (iwcm_deref_id(cm_id_priv)) {
858 return; 862 if (test_bit(IWCM_F_CALLBACK_DESTROY,
859 863 &cm_id_priv->flags)) {
860 if (atomic_read(&cm_id_priv->refcount)==0 && 864 BUG_ON(!list_empty(&cm_id_priv->work_list));
861 test_bit(IWCM_F_CALLBACK_DESTROY, &cm_id_priv->flags)) { 865 free_cm_id(cm_id_priv);
862 dealloc_work_entries(cm_id_priv); 866 }
863 kfree(cm_id_priv);
864 return; 867 return;
865 } 868 }
866 spin_lock_irqsave(&cm_id_priv->lock, flags); 869 spin_lock_irqsave(&cm_id_priv->lock, flags);
diff --git a/drivers/infiniband/core/multicast.c b/drivers/infiniband/core/multicast.c
new file mode 100644
index 000000000000..4a579b3a1c90
--- /dev/null
+++ b/drivers/infiniband/core/multicast.c
@@ -0,0 +1,837 @@
1/*
2 * Copyright (c) 2006 Intel Corporation.  All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <linux/completion.h>
34#include <linux/dma-mapping.h>
35#include <linux/err.h>
36#include <linux/interrupt.h>
37#include <linux/pci.h>
38#include <linux/bitops.h>
39#include <linux/random.h>
40
41#include <rdma/ib_cache.h>
42#include "sa.h"
43
44static void mcast_add_one(struct ib_device *device);
45static void mcast_remove_one(struct ib_device *device);
46
47static struct ib_client mcast_client = {
48 .name = "ib_multicast",
49 .add = mcast_add_one,
50 .remove = mcast_remove_one
51};
52
53static struct ib_sa_client sa_client;
54static struct workqueue_struct *mcast_wq;
55static union ib_gid mgid0;
56
57struct mcast_device;
58
59struct mcast_port {
60 struct mcast_device *dev;
61 spinlock_t lock;
62 struct rb_root table;
63 atomic_t refcount;
64 struct completion comp;
65 u8 port_num;
66};
67
68struct mcast_device {
69 struct ib_device *device;
70 struct ib_event_handler event_handler;
71 int start_port;
72 int end_port;
73 struct mcast_port port[0];
74};
75
76enum mcast_state {
77 MCAST_IDLE,
78 MCAST_JOINING,
79 MCAST_MEMBER,
80 MCAST_BUSY,
81 MCAST_ERROR
82};
83
84struct mcast_member;
85
86struct mcast_group {
87 struct ib_sa_mcmember_rec rec;
88 struct rb_node node;
89 struct mcast_port *port;
90 spinlock_t lock;
91 struct work_struct work;
92 struct list_head pending_list;
93 struct list_head active_list;
94 struct mcast_member *last_join;
95 int members[3];
96 atomic_t refcount;
97 enum mcast_state state;
98 struct ib_sa_query *query;
99 int query_id;
100};
101
102struct mcast_member {
103 struct ib_sa_multicast multicast;
104 struct ib_sa_client *client;
105 struct mcast_group *group;
106 struct list_head list;
107 enum mcast_state state;
108 atomic_t refcount;
109 struct completion comp;
110};
111
112static void join_handler(int status, struct ib_sa_mcmember_rec *rec,
113 void *context);
114static void leave_handler(int status, struct ib_sa_mcmember_rec *rec,
115 void *context);
116
117static struct mcast_group *mcast_find(struct mcast_port *port,
118 union ib_gid *mgid)
119{
120 struct rb_node *node = port->table.rb_node;
121 struct mcast_group *group;
122 int ret;
123
124 while (node) {
125 group = rb_entry(node, struct mcast_group, node);
126 ret = memcmp(mgid->raw, group->rec.mgid.raw, sizeof *mgid);
127 if (!ret)
128 return group;
129
130 if (ret < 0)
131 node = node->rb_left;
132 else
133 node = node->rb_right;
134 }
135 return NULL;
136}
137
138static struct mcast_group *mcast_insert(struct mcast_port *port,
139 struct mcast_group *group,
140 int allow_duplicates)
141{
142 struct rb_node **link = &port->table.rb_node;
143 struct rb_node *parent = NULL;
144 struct mcast_group *cur_group;
145 int ret;
146
147 while (*link) {
148 parent = *link;
149 cur_group = rb_entry(parent, struct mcast_group, node);
150
151 ret = memcmp(group->rec.mgid.raw, cur_group->rec.mgid.raw,
152 sizeof group->rec.mgid);
153 if (ret < 0)
154 link = &(*link)->rb_left;
155 else if (ret > 0)
156 link = &(*link)->rb_right;
157 else if (allow_duplicates)
158 link = &(*link)->rb_left;
159 else
160 return cur_group;
161 }
162 rb_link_node(&group->node, parent, link);
163 rb_insert_color(&group->node, &port->table);
164 return NULL;
165}
166
167static void deref_port(struct mcast_port *port)
168{
169 if (atomic_dec_and_test(&port->refcount))
170 complete(&port->comp);
171}
172
173static void release_group(struct mcast_group *group)
174{
175 struct mcast_port *port = group->port;
176 unsigned long flags;
177
178 spin_lock_irqsave(&port->lock, flags);
179 if (atomic_dec_and_test(&group->refcount)) {
180 rb_erase(&group->node, &port->table);
181 spin_unlock_irqrestore(&port->lock, flags);
182 kfree(group);
183 deref_port(port);
184 } else
185 spin_unlock_irqrestore(&port->lock, flags);
186}
187
188static void deref_member(struct mcast_member *member)
189{
190 if (atomic_dec_and_test(&member->refcount))
191 complete(&member->comp);
192}
193
194static void queue_join(struct mcast_member *member)
195{
196 struct mcast_group *group = member->group;
197 unsigned long flags;
198
199 spin_lock_irqsave(&group->lock, flags);
200 list_add(&member->list, &group->pending_list);
201 if (group->state == MCAST_IDLE) {
202 group->state = MCAST_BUSY;
203 atomic_inc(&group->refcount);
204 queue_work(mcast_wq, &group->work);
205 }
206 spin_unlock_irqrestore(&group->lock, flags);
207}
208
209/*
210 * A multicast group has three types of members: full member, non member, and
211 * send only member. We need to keep track of the number of members of each
212 * type based on their join state. Adjust the number of members the belong to
213 * the specified join states.
214 */
215static void adjust_membership(struct mcast_group *group, u8 join_state, int inc)
216{
217 int i;
218
219 for (i = 0; i < 3; i++, join_state >>= 1)
220 if (join_state & 0x1)
221 group->members[i] += inc;
222}
223
224/*
225 * If a multicast group has zero members left for a particular join state, but
226 * the group is still a member with the SA, we need to leave that join state.
227 * Determine which join states we still belong to, but that do not have any
228 * active members.
229 */
230static u8 get_leave_state(struct mcast_group *group)
231{
232 u8 leave_state = 0;
233 int i;
234
235 for (i = 0; i < 3; i++)
236 if (!group->members[i])
237 leave_state |= (0x1 << i);
238
239 return leave_state & group->rec.join_state;
240}
241
242static int check_selector(ib_sa_comp_mask comp_mask,
243 ib_sa_comp_mask selector_mask,
244 ib_sa_comp_mask value_mask,
245 u8 selector, u8 src_value, u8 dst_value)
246{
247 int err;
248
249 if (!(comp_mask & selector_mask) || !(comp_mask & value_mask))
250 return 0;
251
252 switch (selector) {
253 case IB_SA_GT:
254 err = (src_value <= dst_value);
255 break;
256 case IB_SA_LT:
257 err = (src_value >= dst_value);
258 break;
259 case IB_SA_EQ:
260 err = (src_value != dst_value);
261 break;
262 default:
263 err = 0;
264 break;
265 }
266
267 return err;
268}
269
270static int cmp_rec(struct ib_sa_mcmember_rec *src,
271 struct ib_sa_mcmember_rec *dst, ib_sa_comp_mask comp_mask)
272{
273 /* MGID must already match */
274
275 if (comp_mask & IB_SA_MCMEMBER_REC_PORT_GID &&
276 memcmp(&src->port_gid, &dst->port_gid, sizeof src->port_gid))
277 return -EINVAL;
278 if (comp_mask & IB_SA_MCMEMBER_REC_QKEY && src->qkey != dst->qkey)
279 return -EINVAL;
280 if (comp_mask & IB_SA_MCMEMBER_REC_MLID && src->mlid != dst->mlid)
281 return -EINVAL;
282 if (check_selector(comp_mask, IB_SA_MCMEMBER_REC_MTU_SELECTOR,
283 IB_SA_MCMEMBER_REC_MTU, dst->mtu_selector,
284 src->mtu, dst->mtu))
285 return -EINVAL;
286 if (comp_mask & IB_SA_MCMEMBER_REC_TRAFFIC_CLASS &&
287 src->traffic_class != dst->traffic_class)
288 return -EINVAL;
289 if (comp_mask & IB_SA_MCMEMBER_REC_PKEY && src->pkey != dst->pkey)
290 return -EINVAL;
291 if (check_selector(comp_mask, IB_SA_MCMEMBER_REC_RATE_SELECTOR,
292 IB_SA_MCMEMBER_REC_RATE, dst->rate_selector,
293 src->rate, dst->rate))
294 return -EINVAL;
295 if (check_selector(comp_mask,
296 IB_SA_MCMEMBER_REC_PACKET_LIFE_TIME_SELECTOR,
297 IB_SA_MCMEMBER_REC_PACKET_LIFE_TIME,
298 dst->packet_life_time_selector,
299 src->packet_life_time, dst->packet_life_time))
300 return -EINVAL;
301 if (comp_mask & IB_SA_MCMEMBER_REC_SL && src->sl != dst->sl)
302 return -EINVAL;
303 if (comp_mask & IB_SA_MCMEMBER_REC_FLOW_LABEL &&
304 src->flow_label != dst->flow_label)
305 return -EINVAL;
306 if (comp_mask & IB_SA_MCMEMBER_REC_HOP_LIMIT &&
307 src->hop_limit != dst->hop_limit)
308 return -EINVAL;
309 if (comp_mask & IB_SA_MCMEMBER_REC_SCOPE && src->scope != dst->scope)
310 return -EINVAL;
311
312 /* join_state checked separately, proxy_join ignored */
313
314 return 0;
315}
316
317static int send_join(struct mcast_group *group, struct mcast_member *member)
318{
319 struct mcast_port *port = group->port;
320 int ret;
321
322 group->last_join = member;
323 ret = ib_sa_mcmember_rec_query(&sa_client, port->dev->device,
324 port->port_num, IB_MGMT_METHOD_SET,
325 &member->multicast.rec,
326 member->multicast.comp_mask,
327 3000, GFP_KERNEL, join_handler, group,
328 &group->query);
329 if (ret >= 0) {
330 group->query_id = ret;
331 ret = 0;
332 }
333 return ret;
334}
335
336static int send_leave(struct mcast_group *group, u8 leave_state)
337{
338 struct mcast_port *port = group->port;
339 struct ib_sa_mcmember_rec rec;
340 int ret;
341
342 rec = group->rec;
343 rec.join_state = leave_state;
344
345 ret = ib_sa_mcmember_rec_query(&sa_client, port->dev->device,
346 port->port_num, IB_SA_METHOD_DELETE, &rec,
347 IB_SA_MCMEMBER_REC_MGID |
348 IB_SA_MCMEMBER_REC_PORT_GID |
349 IB_SA_MCMEMBER_REC_JOIN_STATE,
350 3000, GFP_KERNEL, leave_handler,
351 group, &group->query);
352 if (ret >= 0) {
353 group->query_id = ret;
354 ret = 0;
355 }
356 return ret;
357}
358
359static void join_group(struct mcast_group *group, struct mcast_member *member,
360 u8 join_state)
361{
362 member->state = MCAST_MEMBER;
363 adjust_membership(group, join_state, 1);
364 group->rec.join_state |= join_state;
365 member->multicast.rec = group->rec;
366 member->multicast.rec.join_state = join_state;
367 list_move(&member->list, &group->active_list);
368}
369
370static int fail_join(struct mcast_group *group, struct mcast_member *member,
371 int status)
372{
373 spin_lock_irq(&group->lock);
374 list_del_init(&member->list);
375 spin_unlock_irq(&group->lock);
376 return member->multicast.callback(status, &member->multicast);
377}
378
379static void process_group_error(struct mcast_group *group)
380{
381 struct mcast_member *member;
382 int ret;
383
384 spin_lock_irq(&group->lock);
385 while (!list_empty(&group->active_list)) {
386 member = list_entry(group->active_list.next,
387 struct mcast_member, list);
388 atomic_inc(&member->refcount);
389 list_del_init(&member->list);
390 adjust_membership(group, member->multicast.rec.join_state, -1);
391 member->state = MCAST_ERROR;
392 spin_unlock_irq(&group->lock);
393
394 ret = member->multicast.callback(-ENETRESET,
395 &member->multicast);
396 deref_member(member);
397 if (ret)
398 ib_sa_free_multicast(&member->multicast);
399 spin_lock_irq(&group->lock);
400 }
401
402 group->rec.join_state = 0;
403 group->state = MCAST_BUSY;
404 spin_unlock_irq(&group->lock);
405}
406
407static void mcast_work_handler(struct work_struct *work)
408{
409 struct mcast_group *group;
410 struct mcast_member *member;
411 struct ib_sa_multicast *multicast;
412 int status, ret;
413 u8 join_state;
414
415 group = container_of(work, typeof(*group), work);
416retest:
417 spin_lock_irq(&group->lock);
418 while (!list_empty(&group->pending_list) ||
419 (group->state == MCAST_ERROR)) {
420
421 if (group->state == MCAST_ERROR) {
422 spin_unlock_irq(&group->lock);
423 process_group_error(group);
424 goto retest;
425 }
426
427 member = list_entry(group->pending_list.next,
428 struct mcast_member, list);
429 multicast = &member->multicast;
430 join_state = multicast->rec.join_state;
431 atomic_inc(&member->refcount);
432
433 if (join_state == (group->rec.join_state & join_state)) {
434 status = cmp_rec(&group->rec, &multicast->rec,
435 multicast->comp_mask);
436 if (!status)
437 join_group(group, member, join_state);
438 else
439 list_del_init(&member->list);
440 spin_unlock_irq(&group->lock);
441 ret = multicast->callback(status, multicast);
442 } else {
443 spin_unlock_irq(&group->lock);
444 status = send_join(group, member);
445 if (!status) {
446 deref_member(member);
447 return;
448 }
449 ret = fail_join(group, member, status);
450 }
451
452 deref_member(member);
453 if (ret)
454 ib_sa_free_multicast(&member->multicast);
455 spin_lock_irq(&group->lock);
456 }
457
458 join_state = get_leave_state(group);
459 if (join_state) {
460 group->rec.join_state &= ~join_state;
461 spin_unlock_irq(&group->lock);
462 if (send_leave(group, join_state))
463 goto retest;
464 } else {
465 group->state = MCAST_IDLE;
466 spin_unlock_irq(&group->lock);
467 release_group(group);
468 }
469}
470
471/*
472 * Fail a join request if it is still active - at the head of the pending queue.
473 */
474static void process_join_error(struct mcast_group *group, int status)
475{
476 struct mcast_member *member;
477 int ret;
478
479 spin_lock_irq(&group->lock);
480 member = list_entry(group->pending_list.next,
481 struct mcast_member, list);
482 if (group->last_join == member) {
483 atomic_inc(&member->refcount);
484 list_del_init(&member->list);
485 spin_unlock_irq(&group->lock);
486 ret = member->multicast.callback(status, &member->multicast);
487 deref_member(member);
488 if (ret)
489 ib_sa_free_multicast(&member->multicast);
490 } else
491 spin_unlock_irq(&group->lock);
492}
493
494static void join_handler(int status, struct ib_sa_mcmember_rec *rec,
495 void *context)
496{
497 struct mcast_group *group = context;
498
499 if (status)
500 process_join_error(group, status);
501 else {
502 spin_lock_irq(&group->port->lock);
503 group->rec = *rec;
504 if (!memcmp(&mgid0, &group->rec.mgid, sizeof mgid0)) {
505 rb_erase(&group->node, &group->port->table);
506 mcast_insert(group->port, group, 1);
507 }
508 spin_unlock_irq(&group->port->lock);
509 }
510 mcast_work_handler(&group->work);
511}
512
513static void leave_handler(int status, struct ib_sa_mcmember_rec *rec,
514 void *context)
515{
516 struct mcast_group *group = context;
517
518 mcast_work_handler(&group->work);
519}
520
521static struct mcast_group *acquire_group(struct mcast_port *port,
522 union ib_gid *mgid, gfp_t gfp_mask)
523{
524 struct mcast_group *group, *cur_group;
525 unsigned long flags;
526 int is_mgid0;
527
528 is_mgid0 = !memcmp(&mgid0, mgid, sizeof mgid0);
529 if (!is_mgid0) {
530 spin_lock_irqsave(&port->lock, flags);
531 group = mcast_find(port, mgid);
532 if (group)
533 goto found;
534 spin_unlock_irqrestore(&port->lock, flags);
535 }
536
537 group = kzalloc(sizeof *group, gfp_mask);
538 if (!group)
539 return NULL;
540
541 group->port = port;
542 group->rec.mgid = *mgid;
543 INIT_LIST_HEAD(&group->pending_list);
544 INIT_LIST_HEAD(&group->active_list);
545 INIT_WORK(&group->work, mcast_work_handler);
546 spin_lock_init(&group->lock);
547
548 spin_lock_irqsave(&port->lock, flags);
549 cur_group = mcast_insert(port, group, is_mgid0);
550 if (cur_group) {
551 kfree(group);
552 group = cur_group;
553 } else
554 atomic_inc(&port->refcount);
555found:
556 atomic_inc(&group->refcount);
557 spin_unlock_irqrestore(&port->lock, flags);
558 return group;
559}
560
561/*
562 * We serialize all join requests to a single group to make our lives much
563 * easier. Otherwise, two users could try to join the same group
564 * simultaneously, with different configurations, one could leave while the
565 * join is in progress, etc., which makes locking around error recovery
566 * difficult.
567 */
568struct ib_sa_multicast *
569ib_sa_join_multicast(struct ib_sa_client *client,
570 struct ib_device *device, u8 port_num,
571 struct ib_sa_mcmember_rec *rec,
572 ib_sa_comp_mask comp_mask, gfp_t gfp_mask,
573 int (*callback)(int status,
574 struct ib_sa_multicast *multicast),
575 void *context)
576{
577 struct mcast_device *dev;
578 struct mcast_member *member;
579 struct ib_sa_multicast *multicast;
580 int ret;
581
582 dev = ib_get_client_data(device, &mcast_client);
583 if (!dev)
584 return ERR_PTR(-ENODEV);
585
586 member = kmalloc(sizeof *member, gfp_mask);
587 if (!member)
588 return ERR_PTR(-ENOMEM);
589
590 ib_sa_client_get(client);
591 member->client = client;
592 member->multicast.rec = *rec;
593 member->multicast.comp_mask = comp_mask;
594 member->multicast.callback = callback;
595 member->multicast.context = context;
596 init_completion(&member->comp);
597 atomic_set(&member->refcount, 1);
598 member->state = MCAST_JOINING;
599
600 member->group = acquire_group(&dev->port[port_num - dev->start_port],
601 &rec->mgid, gfp_mask);
602 if (!member->group) {
603 ret = -ENOMEM;
604 goto err;
605 }
606
607 /*
608 * The user will get the multicast structure in their callback. They
609 * could then free the multicast structure before we can return from
610 * this routine. So we save the pointer to return before queuing
611 * any callback.
612 */
613 multicast = &member->multicast;
614 queue_join(member);
615 return multicast;
616
617err:
618 ib_sa_client_put(client);
619 kfree(member);
620 return ERR_PTR(ret);
621}
622EXPORT_SYMBOL(ib_sa_join_multicast);
623
624void ib_sa_free_multicast(struct ib_sa_multicast *multicast)
625{
626 struct mcast_member *member;
627 struct mcast_group *group;
628
629 member = container_of(multicast, struct mcast_member, multicast);
630 group = member->group;
631
632 spin_lock_irq(&group->lock);
633 if (member->state == MCAST_MEMBER)
634 adjust_membership(group, multicast->rec.join_state, -1);
635
636 list_del_init(&member->list);
637
638 if (group->state == MCAST_IDLE) {
639 group->state = MCAST_BUSY;
640 spin_unlock_irq(&group->lock);
641 /* Continue to hold reference on group until callback */
642 queue_work(mcast_wq, &group->work);
643 } else {
644 spin_unlock_irq(&group->lock);
645 release_group(group);
646 }
647
648 deref_member(member);
649 wait_for_completion(&member->comp);
650 ib_sa_client_put(member->client);
651 kfree(member);
652}
653EXPORT_SYMBOL(ib_sa_free_multicast);
654
655int ib_sa_get_mcmember_rec(struct ib_device *device, u8 port_num,
656 union ib_gid *mgid, struct ib_sa_mcmember_rec *rec)
657{
658 struct mcast_device *dev;
659 struct mcast_port *port;
660 struct mcast_group *group;
661 unsigned long flags;
662 int ret = 0;
663
664 dev = ib_get_client_data(device, &mcast_client);
665 if (!dev)
666 return -ENODEV;
667
668 port = &dev->port[port_num - dev->start_port];
669 spin_lock_irqsave(&port->lock, flags);
670 group = mcast_find(port, mgid);
671 if (group)
672 *rec = group->rec;
673 else
674 ret = -EADDRNOTAVAIL;
675 spin_unlock_irqrestore(&port->lock, flags);
676
677 return ret;
678}
679EXPORT_SYMBOL(ib_sa_get_mcmember_rec);
680
681int ib_init_ah_from_mcmember(struct ib_device *device, u8 port_num,
682 struct ib_sa_mcmember_rec *rec,
683 struct ib_ah_attr *ah_attr)
684{
685 int ret;
686 u16 gid_index;
687 u8 p;
688
689 ret = ib_find_cached_gid(device, &rec->port_gid, &p, &gid_index);
690 if (ret)
691 return ret;
692
693 memset(ah_attr, 0, sizeof *ah_attr);
694 ah_attr->dlid = be16_to_cpu(rec->mlid);
695 ah_attr->sl = rec->sl;
696 ah_attr->port_num = port_num;
697 ah_attr->static_rate = rec->rate;
698
699 ah_attr->ah_flags = IB_AH_GRH;
700 ah_attr->grh.dgid = rec->mgid;
701
702 ah_attr->grh.sgid_index = (u8) gid_index;
703 ah_attr->grh.flow_label = be32_to_cpu(rec->flow_label);
704 ah_attr->grh.hop_limit = rec->hop_limit;
705 ah_attr->grh.traffic_class = rec->traffic_class;
706
707 return 0;
708}
709EXPORT_SYMBOL(ib_init_ah_from_mcmember);
710
711static void mcast_groups_lost(struct mcast_port *port)
712{
713 struct mcast_group *group;
714 struct rb_node *node;
715 unsigned long flags;
716
717 spin_lock_irqsave(&port->lock, flags);
718 for (node = rb_first(&port->table); node; node = rb_next(node)) {
719 group = rb_entry(node, struct mcast_group, node);
720 spin_lock(&group->lock);
721 if (group->state == MCAST_IDLE) {
722 atomic_inc(&group->refcount);
723 queue_work(mcast_wq, &group->work);
724 }
725 group->state = MCAST_ERROR;
726 spin_unlock(&group->lock);
727 }
728 spin_unlock_irqrestore(&port->lock, flags);
729}
730
731static void mcast_event_handler(struct ib_event_handler *handler,
732 struct ib_event *event)
733{
734 struct mcast_device *dev;
735
736 dev = container_of(handler, struct mcast_device, event_handler);
737
738 switch (event->event) {
739 case IB_EVENT_PORT_ERR:
740 case IB_EVENT_LID_CHANGE:
741 case IB_EVENT_SM_CHANGE:
742 case IB_EVENT_CLIENT_REREGISTER:
743 mcast_groups_lost(&dev->port[event->element.port_num -
744 dev->start_port]);
745 break;
746 default:
747 break;
748 }
749}
750
751static void mcast_add_one(struct ib_device *device)
752{
753 struct mcast_device *dev;
754 struct mcast_port *port;
755 int i;
756
757 if (rdma_node_get_transport(device->node_type) != RDMA_TRANSPORT_IB)
758 return;
759
760 dev = kmalloc(sizeof *dev + device->phys_port_cnt * sizeof *port,
761 GFP_KERNEL);
762 if (!dev)
763 return;
764
765 if (device->node_type == RDMA_NODE_IB_SWITCH)
766 dev->start_port = dev->end_port = 0;
767 else {
768 dev->start_port = 1;
769 dev->end_port = device->phys_port_cnt;
770 }
771
772 for (i = 0; i <= dev->end_port - dev->start_port; i++) {
773 port = &dev->port[i];
774 port->dev = dev;
775 port->port_num = dev->start_port + i;
776 spin_lock_init(&port->lock);
777 port->table = RB_ROOT;
778 init_completion(&port->comp);
779 atomic_set(&port->refcount, 1);
780 }
781
782 dev->device = device;
783 ib_set_client_data(device, &mcast_client, dev);
784
785 INIT_IB_EVENT_HANDLER(&dev->event_handler, device, mcast_event_handler);
786 ib_register_event_handler(&dev->event_handler);
787}
788
789static void mcast_remove_one(struct ib_device *device)
790{
791 struct mcast_device *dev;
792 struct mcast_port *port;
793 int i;
794
795 dev = ib_get_client_data(device, &mcast_client);
796 if (!dev)
797 return;
798
799 ib_unregister_event_handler(&dev->event_handler);
800 flush_workqueue(mcast_wq);
801
802 for (i = 0; i <= dev->end_port - dev->start_port; i++) {
803 port = &dev->port[i];
804 deref_port(port);
805 wait_for_completion(&port->comp);
806 }
807
808 kfree(dev);
809}
810
811int mcast_init(void)
812{
813 int ret;
814
815 mcast_wq = create_singlethread_workqueue("ib_mcast");
816 if (!mcast_wq)
817 return -ENOMEM;
818
819 ib_sa_register_client(&sa_client);
820
821 ret = ib_register_client(&mcast_client);
822 if (ret)
823 goto err;
824 return 0;
825
826err:
827 ib_sa_unregister_client(&sa_client);
828 destroy_workqueue(mcast_wq);
829 return ret;
830}
831
832void mcast_cleanup(void)
833{
834 ib_unregister_client(&mcast_client);
835 ib_sa_unregister_client(&sa_client);
836 destroy_workqueue(mcast_wq);
837}
diff --git a/drivers/infiniband/core/sa.h b/drivers/infiniband/core/sa.h
new file mode 100644
index 000000000000..24c93fd320fb
--- /dev/null
+++ b/drivers/infiniband/core/sa.h
@@ -0,0 +1,66 @@
1/*
2 * Copyright (c) 2004 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Voltaire, Inc.  All rights reserved.
4 * Copyright (c) 2006 Intel Corporation. All rights reserved.
5 *
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
11 *
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
14 * conditions are met:
15 *
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer.
19 *
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 * SOFTWARE.
33 */
34
35#ifndef SA_H
36#define SA_H
37
38#include <rdma/ib_sa.h>
39
40static inline void ib_sa_client_get(struct ib_sa_client *client)
41{
42 atomic_inc(&client->users);
43}
44
45static inline void ib_sa_client_put(struct ib_sa_client *client)
46{
47 if (atomic_dec_and_test(&client->users))
48 complete(&client->comp);
49}
50
51int ib_sa_mcmember_rec_query(struct ib_sa_client *client,
52 struct ib_device *device, u8 port_num,
53 u8 method,
54 struct ib_sa_mcmember_rec *rec,
55 ib_sa_comp_mask comp_mask,
56 int timeout_ms, gfp_t gfp_mask,
57 void (*callback)(int status,
58 struct ib_sa_mcmember_rec *resp,
59 void *context),
60 void *context,
61 struct ib_sa_query **sa_query);
62
63int mcast_init(void);
64void mcast_cleanup(void);
65
66#endif /* SA_H */
diff --git a/drivers/infiniband/core/sa_query.c b/drivers/infiniband/core/sa_query.c
index e45afba75341..68db633711c5 100644
--- a/drivers/infiniband/core/sa_query.c
+++ b/drivers/infiniband/core/sa_query.c
@@ -47,8 +47,8 @@
47#include <linux/workqueue.h> 47#include <linux/workqueue.h>
48 48
49#include <rdma/ib_pack.h> 49#include <rdma/ib_pack.h>
50#include <rdma/ib_sa.h>
51#include <rdma/ib_cache.h> 50#include <rdma/ib_cache.h>
51#include "sa.h"
52 52
53MODULE_AUTHOR("Roland Dreier"); 53MODULE_AUTHOR("Roland Dreier");
54MODULE_DESCRIPTION("InfiniBand subnet administration query support"); 54MODULE_DESCRIPTION("InfiniBand subnet administration query support");
@@ -425,17 +425,6 @@ void ib_sa_register_client(struct ib_sa_client *client)
425} 425}
426EXPORT_SYMBOL(ib_sa_register_client); 426EXPORT_SYMBOL(ib_sa_register_client);
427 427
428static inline void ib_sa_client_get(struct ib_sa_client *client)
429{
430 atomic_inc(&client->users);
431}
432
433static inline void ib_sa_client_put(struct ib_sa_client *client)
434{
435 if (atomic_dec_and_test(&client->users))
436 complete(&client->comp);
437}
438
439void ib_sa_unregister_client(struct ib_sa_client *client) 428void ib_sa_unregister_client(struct ib_sa_client *client)
440{ 429{
441 ib_sa_client_put(client); 430 ib_sa_client_put(client);
@@ -482,6 +471,7 @@ int ib_init_ah_from_path(struct ib_device *device, u8 port_num,
482 ah_attr->sl = rec->sl; 471 ah_attr->sl = rec->sl;
483 ah_attr->src_path_bits = be16_to_cpu(rec->slid) & 0x7f; 472 ah_attr->src_path_bits = be16_to_cpu(rec->slid) & 0x7f;
484 ah_attr->port_num = port_num; 473 ah_attr->port_num = port_num;
474 ah_attr->static_rate = rec->rate;
485 475
486 if (rec->hop_limit > 1) { 476 if (rec->hop_limit > 1) {
487 ah_attr->ah_flags = IB_AH_GRH; 477 ah_attr->ah_flags = IB_AH_GRH;
@@ -901,7 +891,6 @@ err1:
901 kfree(query); 891 kfree(query);
902 return ret; 892 return ret;
903} 893}
904EXPORT_SYMBOL(ib_sa_mcmember_rec_query);
905 894
906static void send_handler(struct ib_mad_agent *agent, 895static void send_handler(struct ib_mad_agent *agent,
907 struct ib_mad_send_wc *mad_send_wc) 896 struct ib_mad_send_wc *mad_send_wc)
@@ -1053,14 +1042,27 @@ static int __init ib_sa_init(void)
1053 get_random_bytes(&tid, sizeof tid); 1042 get_random_bytes(&tid, sizeof tid);
1054 1043
1055 ret = ib_register_client(&sa_client); 1044 ret = ib_register_client(&sa_client);
1056 if (ret) 1045 if (ret) {
1057 printk(KERN_ERR "Couldn't register ib_sa client\n"); 1046 printk(KERN_ERR "Couldn't register ib_sa client\n");
1047 goto err1;
1048 }
1049
1050 ret = mcast_init();
1051 if (ret) {
1052 printk(KERN_ERR "Couldn't initialize multicast handling\n");
1053 goto err2;
1054 }
1058 1055
1056 return 0;
1057err2:
1058 ib_unregister_client(&sa_client);
1059err1:
1059 return ret; 1060 return ret;
1060} 1061}
1061 1062
1062static void __exit ib_sa_cleanup(void) 1063static void __exit ib_sa_cleanup(void)
1063{ 1064{
1065 mcast_cleanup();
1064 ib_unregister_client(&sa_client); 1066 ib_unregister_client(&sa_client);
1065 idr_destroy(&query_idr); 1067 idr_destroy(&query_idr);
1066} 1068}
diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
index 709323c14c5d..000c086bf2e9 100644
--- a/drivers/infiniband/core/sysfs.c
+++ b/drivers/infiniband/core/sysfs.c
@@ -714,8 +714,6 @@ int ib_device_register_sysfs(struct ib_device *device)
714 if (ret) 714 if (ret)
715 goto err_put; 715 goto err_put;
716 } else { 716 } else {
717 int i;
718
719 for (i = 1; i <= device->phys_port_cnt; ++i) { 717 for (i = 1; i <= device->phys_port_cnt; ++i) {
720 ret = add_port(device, i); 718 ret = add_port(device, i);
721 if (ret) 719 if (ret)
diff --git a/drivers/infiniband/core/ucma.c b/drivers/infiniband/core/ucma.c
index 6b81b98961c7..b516b93b8550 100644
--- a/drivers/infiniband/core/ucma.c
+++ b/drivers/infiniband/core/ucma.c
@@ -70,10 +70,24 @@ struct ucma_context {
70 u64 uid; 70 u64 uid;
71 71
72 struct list_head list; 72 struct list_head list;
73 struct list_head mc_list;
74};
75
76struct ucma_multicast {
77 struct ucma_context *ctx;
78 int id;
79 int events_reported;
80
81 u64 uid;
82 struct list_head list;
83 struct sockaddr addr;
84 u8 pad[sizeof(struct sockaddr_in6) -
85 sizeof(struct sockaddr)];
73}; 86};
74 87
75struct ucma_event { 88struct ucma_event {
76 struct ucma_context *ctx; 89 struct ucma_context *ctx;
90 struct ucma_multicast *mc;
77 struct list_head list; 91 struct list_head list;
78 struct rdma_cm_id *cm_id; 92 struct rdma_cm_id *cm_id;
79 struct rdma_ucm_event_resp resp; 93 struct rdma_ucm_event_resp resp;
@@ -81,6 +95,7 @@ struct ucma_event {
81 95
82static DEFINE_MUTEX(mut); 96static DEFINE_MUTEX(mut);
83static DEFINE_IDR(ctx_idr); 97static DEFINE_IDR(ctx_idr);
98static DEFINE_IDR(multicast_idr);
84 99
85static inline struct ucma_context *_ucma_find_context(int id, 100static inline struct ucma_context *_ucma_find_context(int id,
86 struct ucma_file *file) 101 struct ucma_file *file)
@@ -124,6 +139,7 @@ static struct ucma_context *ucma_alloc_ctx(struct ucma_file *file)
124 139
125 atomic_set(&ctx->ref, 1); 140 atomic_set(&ctx->ref, 1);
126 init_completion(&ctx->comp); 141 init_completion(&ctx->comp);
142 INIT_LIST_HEAD(&ctx->mc_list);
127 ctx->file = file; 143 ctx->file = file;
128 144
129 do { 145 do {
@@ -147,6 +163,37 @@ error:
147 return NULL; 163 return NULL;
148} 164}
149 165
166static struct ucma_multicast* ucma_alloc_multicast(struct ucma_context *ctx)
167{
168 struct ucma_multicast *mc;
169 int ret;
170
171 mc = kzalloc(sizeof(*mc), GFP_KERNEL);
172 if (!mc)
173 return NULL;
174
175 do {
176 ret = idr_pre_get(&multicast_idr, GFP_KERNEL);
177 if (!ret)
178 goto error;
179
180 mutex_lock(&mut);
181 ret = idr_get_new(&multicast_idr, mc, &mc->id);
182 mutex_unlock(&mut);
183 } while (ret == -EAGAIN);
184
185 if (ret)
186 goto error;
187
188 mc->ctx = ctx;
189 list_add_tail(&mc->list, &ctx->mc_list);
190 return mc;
191
192error:
193 kfree(mc);
194 return NULL;
195}
196
150static void ucma_copy_conn_event(struct rdma_ucm_conn_param *dst, 197static void ucma_copy_conn_event(struct rdma_ucm_conn_param *dst,
151 struct rdma_conn_param *src) 198 struct rdma_conn_param *src)
152{ 199{
@@ -180,8 +227,19 @@ static void ucma_set_event_context(struct ucma_context *ctx,
180 struct ucma_event *uevent) 227 struct ucma_event *uevent)
181{ 228{
182 uevent->ctx = ctx; 229 uevent->ctx = ctx;
183 uevent->resp.uid = ctx->uid; 230 switch (event->event) {
184 uevent->resp.id = ctx->id; 231 case RDMA_CM_EVENT_MULTICAST_JOIN:
232 case RDMA_CM_EVENT_MULTICAST_ERROR:
233 uevent->mc = (struct ucma_multicast *)
234 event->param.ud.private_data;
235 uevent->resp.uid = uevent->mc->uid;
236 uevent->resp.id = uevent->mc->id;
237 break;
238 default:
239 uevent->resp.uid = ctx->uid;
240 uevent->resp.id = ctx->id;
241 break;
242 }
185} 243}
186 244
187static int ucma_event_handler(struct rdma_cm_id *cm_id, 245static int ucma_event_handler(struct rdma_cm_id *cm_id,
@@ -199,7 +257,7 @@ static int ucma_event_handler(struct rdma_cm_id *cm_id,
199 ucma_set_event_context(ctx, event, uevent); 257 ucma_set_event_context(ctx, event, uevent);
200 uevent->resp.event = event->event; 258 uevent->resp.event = event->event;
201 uevent->resp.status = event->status; 259 uevent->resp.status = event->status;
202 if (cm_id->ps == RDMA_PS_UDP) 260 if (cm_id->ps == RDMA_PS_UDP || cm_id->ps == RDMA_PS_IPOIB)
203 ucma_copy_ud_event(&uevent->resp.param.ud, &event->param.ud); 261 ucma_copy_ud_event(&uevent->resp.param.ud, &event->param.ud);
204 else 262 else
205 ucma_copy_conn_event(&uevent->resp.param.conn, 263 ucma_copy_conn_event(&uevent->resp.param.conn,
@@ -290,6 +348,8 @@ static ssize_t ucma_get_event(struct ucma_file *file, const char __user *inbuf,
290 348
291 list_del(&uevent->list); 349 list_del(&uevent->list);
292 uevent->ctx->events_reported++; 350 uevent->ctx->events_reported++;
351 if (uevent->mc)
352 uevent->mc->events_reported++;
293 kfree(uevent); 353 kfree(uevent);
294done: 354done:
295 mutex_unlock(&file->mut); 355 mutex_unlock(&file->mut);
@@ -342,6 +402,19 @@ err1:
342 return ret; 402 return ret;
343} 403}
344 404
405static void ucma_cleanup_multicast(struct ucma_context *ctx)
406{
407 struct ucma_multicast *mc, *tmp;
408
409 mutex_lock(&mut);
410 list_for_each_entry_safe(mc, tmp, &ctx->mc_list, list) {
411 list_del(&mc->list);
412 idr_remove(&multicast_idr, mc->id);
413 kfree(mc);
414 }
415 mutex_unlock(&mut);
416}
417
345static void ucma_cleanup_events(struct ucma_context *ctx) 418static void ucma_cleanup_events(struct ucma_context *ctx)
346{ 419{
347 struct ucma_event *uevent, *tmp; 420 struct ucma_event *uevent, *tmp;
@@ -360,6 +433,19 @@ static void ucma_cleanup_events(struct ucma_context *ctx)
360 } 433 }
361} 434}
362 435
436static void ucma_cleanup_mc_events(struct ucma_multicast *mc)
437{
438 struct ucma_event *uevent, *tmp;
439
440 list_for_each_entry_safe(uevent, tmp, &mc->ctx->file->event_list, list) {
441 if (uevent->mc != mc)
442 continue;
443
444 list_del(&uevent->list);
445 kfree(uevent);
446 }
447}
448
363static int ucma_free_ctx(struct ucma_context *ctx) 449static int ucma_free_ctx(struct ucma_context *ctx)
364{ 450{
365 int events_reported; 451 int events_reported;
@@ -367,6 +453,8 @@ static int ucma_free_ctx(struct ucma_context *ctx)
367 /* No new events will be generated after destroying the id. */ 453 /* No new events will be generated after destroying the id. */
368 rdma_destroy_id(ctx->cm_id); 454 rdma_destroy_id(ctx->cm_id);
369 455
456 ucma_cleanup_multicast(ctx);
457
370 /* Cleanup events not yet reported to the user. */ 458 /* Cleanup events not yet reported to the user. */
371 mutex_lock(&ctx->file->mut); 459 mutex_lock(&ctx->file->mut);
372 ucma_cleanup_events(ctx); 460 ucma_cleanup_events(ctx);
@@ -731,6 +819,114 @@ static ssize_t ucma_notify(struct ucma_file *file, const char __user *inbuf,
731 return ret; 819 return ret;
732} 820}
733 821
822static ssize_t ucma_join_multicast(struct ucma_file *file,
823 const char __user *inbuf,
824 int in_len, int out_len)
825{
826 struct rdma_ucm_join_mcast cmd;
827 struct rdma_ucm_create_id_resp resp;
828 struct ucma_context *ctx;
829 struct ucma_multicast *mc;
830 int ret;
831
832 if (out_len < sizeof(resp))
833 return -ENOSPC;
834
835 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
836 return -EFAULT;
837
838 ctx = ucma_get_ctx(file, cmd.id);
839 if (IS_ERR(ctx))
840 return PTR_ERR(ctx);
841
842 mutex_lock(&file->mut);
843 mc = ucma_alloc_multicast(ctx);
844 if (IS_ERR(mc)) {
845 ret = PTR_ERR(mc);
846 goto err1;
847 }
848
849 mc->uid = cmd.uid;
850 memcpy(&mc->addr, &cmd.addr, sizeof cmd.addr);
851 ret = rdma_join_multicast(ctx->cm_id, &mc->addr, mc);
852 if (ret)
853 goto err2;
854
855 resp.id = mc->id;
856 if (copy_to_user((void __user *)(unsigned long)cmd.response,
857 &resp, sizeof(resp))) {
858 ret = -EFAULT;
859 goto err3;
860 }
861
862 mutex_unlock(&file->mut);
863 ucma_put_ctx(ctx);
864 return 0;
865
866err3:
867 rdma_leave_multicast(ctx->cm_id, &mc->addr);
868 ucma_cleanup_mc_events(mc);
869err2:
870 mutex_lock(&mut);
871 idr_remove(&multicast_idr, mc->id);
872 mutex_unlock(&mut);
873 list_del(&mc->list);
874 kfree(mc);
875err1:
876 mutex_unlock(&file->mut);
877 ucma_put_ctx(ctx);
878 return ret;
879}
880
881static ssize_t ucma_leave_multicast(struct ucma_file *file,
882 const char __user *inbuf,
883 int in_len, int out_len)
884{
885 struct rdma_ucm_destroy_id cmd;
886 struct rdma_ucm_destroy_id_resp resp;
887 struct ucma_multicast *mc;
888 int ret = 0;
889
890 if (out_len < sizeof(resp))
891 return -ENOSPC;
892
893 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
894 return -EFAULT;
895
896 mutex_lock(&mut);
897 mc = idr_find(&multicast_idr, cmd.id);
898 if (!mc)
899 mc = ERR_PTR(-ENOENT);
900 else if (mc->ctx->file != file)
901 mc = ERR_PTR(-EINVAL);
902 else {
903 idr_remove(&multicast_idr, mc->id);
904 atomic_inc(&mc->ctx->ref);
905 }
906 mutex_unlock(&mut);
907
908 if (IS_ERR(mc)) {
909 ret = PTR_ERR(mc);
910 goto out;
911 }
912
913 rdma_leave_multicast(mc->ctx->cm_id, &mc->addr);
914 mutex_lock(&mc->ctx->file->mut);
915 ucma_cleanup_mc_events(mc);
916 list_del(&mc->list);
917 mutex_unlock(&mc->ctx->file->mut);
918
919 ucma_put_ctx(mc->ctx);
920 resp.events_reported = mc->events_reported;
921 kfree(mc);
922
923 if (copy_to_user((void __user *)(unsigned long)cmd.response,
924 &resp, sizeof(resp)))
925 ret = -EFAULT;
926out:
927 return ret;
928}
929
734static ssize_t (*ucma_cmd_table[])(struct ucma_file *file, 930static ssize_t (*ucma_cmd_table[])(struct ucma_file *file,
735 const char __user *inbuf, 931 const char __user *inbuf,
736 int in_len, int out_len) = { 932 int in_len, int out_len) = {
@@ -750,6 +946,8 @@ static ssize_t (*ucma_cmd_table[])(struct ucma_file *file,
750 [RDMA_USER_CM_CMD_GET_OPTION] = NULL, 946 [RDMA_USER_CM_CMD_GET_OPTION] = NULL,
751 [RDMA_USER_CM_CMD_SET_OPTION] = NULL, 947 [RDMA_USER_CM_CMD_SET_OPTION] = NULL,
752 [RDMA_USER_CM_CMD_NOTIFY] = ucma_notify, 948 [RDMA_USER_CM_CMD_NOTIFY] = ucma_notify,
949 [RDMA_USER_CM_CMD_JOIN_MCAST] = ucma_join_multicast,
950 [RDMA_USER_CM_CMD_LEAVE_MCAST] = ucma_leave_multicast,
753}; 951};
754 952
755static ssize_t ucma_write(struct file *filp, const char __user *buf, 953static ssize_t ucma_write(struct file *filp, const char __user *buf,
diff --git a/drivers/infiniband/hw/cxgb3/cxio_dbg.c b/drivers/infiniband/hw/cxgb3/cxio_dbg.c
index 5a7306f5efae..75f7b16a271d 100644
--- a/drivers/infiniband/hw/cxgb3/cxio_dbg.c
+++ b/drivers/infiniband/hw/cxgb3/cxio_dbg.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/cxio_hal.c b/drivers/infiniband/hw/cxgb3/cxio_hal.c
index 82fa72041989..114ac3b775dc 100644
--- a/drivers/infiniband/hw/cxgb3/cxio_hal.c
+++ b/drivers/infiniband/hw/cxgb3/cxio_hal.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/cxio_hal.h b/drivers/infiniband/hw/cxgb3/cxio_hal.h
index 1b97e80b8780..8ab04a7c6f6e 100644
--- a/drivers/infiniband/hw/cxgb3/cxio_hal.h
+++ b/drivers/infiniband/hw/cxgb3/cxio_hal.h
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/cxio_resource.c b/drivers/infiniband/hw/cxgb3/cxio_resource.c
index 997aa32cbf07..65bf577311aa 100644
--- a/drivers/infiniband/hw/cxgb3/cxio_resource.c
+++ b/drivers/infiniband/hw/cxgb3/cxio_resource.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/cxio_resource.h b/drivers/infiniband/hw/cxgb3/cxio_resource.h
index a6bbe8370d81..a2703a3d882d 100644
--- a/drivers/infiniband/hw/cxgb3/cxio_resource.h
+++ b/drivers/infiniband/hw/cxgb3/cxio_resource.h
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/cxio_wr.h b/drivers/infiniband/hw/cxgb3/cxio_wr.h
index 103fc42d6976..90d7b8972cb4 100644
--- a/drivers/infiniband/hw/cxgb3/cxio_wr.h
+++ b/drivers/infiniband/hw/cxgb3/cxio_wr.h
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/iwch.c b/drivers/infiniband/hw/cxgb3/iwch.c
index 4611afa52220..0315c9d9fce9 100644
--- a/drivers/infiniband/hw/cxgb3/iwch.c
+++ b/drivers/infiniband/hw/cxgb3/iwch.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/iwch.h b/drivers/infiniband/hw/cxgb3/iwch.h
index 6517ef85026f..caf4e6007a44 100644
--- a/drivers/infiniband/hw/cxgb3/iwch.h
+++ b/drivers/infiniband/hw/cxgb3/iwch.h
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/iwch_cm.c b/drivers/infiniband/hw/cxgb3/iwch_cm.c
index a522b1baa3b4..e5442e34b788 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_cm.c
+++ b/drivers/infiniband/hw/cxgb3/iwch_cm.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/iwch_cm.h b/drivers/infiniband/hw/cxgb3/iwch_cm.h
index 7c810d904279..0c6f281bd4a0 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_cm.h
+++ b/drivers/infiniband/hw/cxgb3/iwch_cm.h
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/iwch_cq.c b/drivers/infiniband/hw/cxgb3/iwch_cq.c
index 98b3bdb5de9e..d7624c170ee7 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_cq.c
+++ b/drivers/infiniband/hw/cxgb3/iwch_cq.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/iwch_ev.c b/drivers/infiniband/hw/cxgb3/iwch_ev.c
index a6efa8fe15d8..54362afbf72f 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_ev.c
+++ b/drivers/infiniband/hw/cxgb3/iwch_ev.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/iwch_mem.c b/drivers/infiniband/hw/cxgb3/iwch_mem.c
index 2b6cd53bb3fc..a6c2c4ba29e6 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_mem.c
+++ b/drivers/infiniband/hw/cxgb3/iwch_mem.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/iwch_provider.c b/drivers/infiniband/hw/cxgb3/iwch_provider.c
index 6861087d776c..2aef122f9955 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_provider.c
+++ b/drivers/infiniband/hw/cxgb3/iwch_provider.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/iwch_provider.h b/drivers/infiniband/hw/cxgb3/iwch_provider.h
index 61e3278fd7a8..2af3e93b607f 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_provider.h
+++ b/drivers/infiniband/hw/cxgb3/iwch_provider.h
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/iwch_qp.c b/drivers/infiniband/hw/cxgb3/iwch_qp.c
index e066727504b6..4dda2f6da2de 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_qp.c
+++ b/drivers/infiniband/hw/cxgb3/iwch_qp.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
@@ -846,6 +845,8 @@ int iwch_modify_qp(struct iwch_dev *rhp, struct iwch_qp *qhp,
846 break; 845 break;
847 case IWCH_QP_STATE_TERMINATE: 846 case IWCH_QP_STATE_TERMINATE:
848 qhp->attr.state = IWCH_QP_STATE_TERMINATE; 847 qhp->attr.state = IWCH_QP_STATE_TERMINATE;
848 if (t3b_device(qhp->rhp))
849 cxio_set_wq_in_error(&qhp->wq);
849 if (!internal) 850 if (!internal)
850 terminate = 1; 851 terminate = 1;
851 break; 852 break;
diff --git a/drivers/infiniband/hw/cxgb3/iwch_user.h b/drivers/infiniband/hw/cxgb3/iwch_user.h
index c4e7fbea8bbd..cb7086f558c1 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_user.h
+++ b/drivers/infiniband/hw/cxgb3/iwch_user.h
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/ehca/Kconfig b/drivers/infiniband/hw/ehca/Kconfig
index 727b10d89686..1a854598e0e6 100644
--- a/drivers/infiniband/hw/ehca/Kconfig
+++ b/drivers/infiniband/hw/ehca/Kconfig
@@ -7,11 +7,3 @@ config INFINIBAND_EHCA
7 To compile the driver as a module, choose M here. The module 7 To compile the driver as a module, choose M here. The module
8 will be called ib_ehca. 8 will be called ib_ehca.
9 9
10config INFINIBAND_EHCA_SCALING
11 bool "Scaling support (EXPERIMENTAL)"
12 depends on IBMEBUS && INFINIBAND_EHCA && HOTPLUG_CPU && EXPERIMENTAL
13 default y
14 ---help---
15 eHCA scaling support schedules the CQ callbacks to different CPUs.
16
17 To enable this feature choose Y here.
diff --git a/drivers/infiniband/hw/ehca/ehca_classes.h b/drivers/infiniband/hw/ehca/ehca_classes.h
index cf95ee474b0f..40404c9e2817 100644
--- a/drivers/infiniband/hw/ehca/ehca_classes.h
+++ b/drivers/infiniband/hw/ehca/ehca_classes.h
@@ -42,8 +42,6 @@
42#ifndef __EHCA_CLASSES_H__ 42#ifndef __EHCA_CLASSES_H__
43#define __EHCA_CLASSES_H__ 43#define __EHCA_CLASSES_H__
44 44
45#include "ehca_classes.h"
46#include "ipz_pt_fn.h"
47 45
48struct ehca_module; 46struct ehca_module;
49struct ehca_qp; 47struct ehca_qp;
@@ -54,14 +52,22 @@ struct ehca_mw;
54struct ehca_pd; 52struct ehca_pd;
55struct ehca_av; 53struct ehca_av;
56 54
55#include <rdma/ib_verbs.h>
56#include <rdma/ib_user_verbs.h>
57
57#ifdef CONFIG_PPC64 58#ifdef CONFIG_PPC64
58#include "ehca_classes_pSeries.h" 59#include "ehca_classes_pSeries.h"
59#endif 60#endif
61#include "ipz_pt_fn.h"
62#include "ehca_qes.h"
63#include "ehca_irq.h"
60 64
61#include <rdma/ib_verbs.h> 65#define EHCA_EQE_CACHE_SIZE 20
62#include <rdma/ib_user_verbs.h>
63 66
64#include "ehca_irq.h" 67struct ehca_eqe_cache_entry {
68 struct ehca_eqe *eqe;
69 struct ehca_cq *cq;
70};
65 71
66struct ehca_eq { 72struct ehca_eq {
67 u32 length; 73 u32 length;
@@ -74,6 +80,8 @@ struct ehca_eq {
74 spinlock_t spinlock; 80 spinlock_t spinlock;
75 struct tasklet_struct interrupt_task; 81 struct tasklet_struct interrupt_task;
76 u32 ist; 82 u32 ist;
83 spinlock_t irq_spinlock;
84 struct ehca_eqe_cache_entry eqe_cache[EHCA_EQE_CACHE_SIZE];
77}; 85};
78 86
79struct ehca_sport { 87struct ehca_sport {
@@ -269,6 +277,7 @@ extern struct idr ehca_cq_idr;
269extern int ehca_static_rate; 277extern int ehca_static_rate;
270extern int ehca_port_act_time; 278extern int ehca_port_act_time;
271extern int ehca_use_hp_mr; 279extern int ehca_use_hp_mr;
280extern int ehca_scaling_code;
272 281
273struct ipzu_queue_resp { 282struct ipzu_queue_resp {
274 u32 qe_size; /* queue entry size */ 283 u32 qe_size; /* queue entry size */
diff --git a/drivers/infiniband/hw/ehca/ehca_eq.c b/drivers/infiniband/hw/ehca/ehca_eq.c
index 24ceab0bae4a..4961eb88827c 100644
--- a/drivers/infiniband/hw/ehca/ehca_eq.c
+++ b/drivers/infiniband/hw/ehca/ehca_eq.c
@@ -61,6 +61,7 @@ int ehca_create_eq(struct ehca_shca *shca,
61 struct ib_device *ib_dev = &shca->ib_device; 61 struct ib_device *ib_dev = &shca->ib_device;
62 62
63 spin_lock_init(&eq->spinlock); 63 spin_lock_init(&eq->spinlock);
64 spin_lock_init(&eq->irq_spinlock);
64 eq->is_initialized = 0; 65 eq->is_initialized = 0;
65 66
66 if (type != EHCA_EQ && type != EHCA_NEQ) { 67 if (type != EHCA_EQ && type != EHCA_NEQ) {
diff --git a/drivers/infiniband/hw/ehca/ehca_hca.c b/drivers/infiniband/hw/ehca/ehca_hca.c
index b7be950ab47c..30eb45df9f0b 100644
--- a/drivers/infiniband/hw/ehca/ehca_hca.c
+++ b/drivers/infiniband/hw/ehca/ehca_hca.c
@@ -162,6 +162,9 @@ int ehca_query_port(struct ib_device *ibdev,
162 props->active_width = IB_WIDTH_12X; 162 props->active_width = IB_WIDTH_12X;
163 props->active_speed = 0x1; 163 props->active_speed = 0x1;
164 164
165 /* at the moment (logical) link state is always LINK_UP */
166 props->phys_state = 0x5;
167
165query_port1: 168query_port1:
166 ehca_free_fw_ctrlblock(rblock); 169 ehca_free_fw_ctrlblock(rblock);
167 170
diff --git a/drivers/infiniband/hw/ehca/ehca_irq.c b/drivers/infiniband/hw/ehca/ehca_irq.c
index 6c4f9f91b15d..3ec53c687d08 100644
--- a/drivers/infiniband/hw/ehca/ehca_irq.c
+++ b/drivers/infiniband/hw/ehca/ehca_irq.c
@@ -63,15 +63,11 @@
63#define ERROR_DATA_LENGTH EHCA_BMASK_IBM(52,63) 63#define ERROR_DATA_LENGTH EHCA_BMASK_IBM(52,63)
64#define ERROR_DATA_TYPE EHCA_BMASK_IBM(0,7) 64#define ERROR_DATA_TYPE EHCA_BMASK_IBM(0,7)
65 65
66#ifdef CONFIG_INFINIBAND_EHCA_SCALING
67
68static void queue_comp_task(struct ehca_cq *__cq); 66static void queue_comp_task(struct ehca_cq *__cq);
69 67
70static struct ehca_comp_pool* pool; 68static struct ehca_comp_pool* pool;
71static struct notifier_block comp_pool_callback_nb; 69static struct notifier_block comp_pool_callback_nb;
72 70
73#endif
74
75static inline void comp_event_callback(struct ehca_cq *cq) 71static inline void comp_event_callback(struct ehca_cq *cq)
76{ 72{
77 if (!cq->ib_cq.comp_handler) 73 if (!cq->ib_cq.comp_handler)
@@ -206,7 +202,7 @@ static void qp_event_callback(struct ehca_shca *shca,
206} 202}
207 203
208static void cq_event_callback(struct ehca_shca *shca, 204static void cq_event_callback(struct ehca_shca *shca,
209 u64 eqe) 205 u64 eqe)
210{ 206{
211 struct ehca_cq *cq; 207 struct ehca_cq *cq;
212 unsigned long flags; 208 unsigned long flags;
@@ -318,7 +314,7 @@ static void parse_ec(struct ehca_shca *shca, u64 eqe)
318 "disruptive port %x configuration change", port); 314 "disruptive port %x configuration change", port);
319 315
320 ehca_info(&shca->ib_device, 316 ehca_info(&shca->ib_device,
321 "port %x is inactive.", port); 317 "port %x is inactive.", port);
322 event.device = &shca->ib_device; 318 event.device = &shca->ib_device;
323 event.event = IB_EVENT_PORT_ERR; 319 event.event = IB_EVENT_PORT_ERR;
324 event.element.port_num = port; 320 event.element.port_num = port;
@@ -326,7 +322,7 @@ static void parse_ec(struct ehca_shca *shca, u64 eqe)
326 ib_dispatch_event(&event); 322 ib_dispatch_event(&event);
327 323
328 ehca_info(&shca->ib_device, 324 ehca_info(&shca->ib_device,
329 "port %x is active.", port); 325 "port %x is active.", port);
330 event.device = &shca->ib_device; 326 event.device = &shca->ib_device;
331 event.event = IB_EVENT_PORT_ACTIVE; 327 event.event = IB_EVENT_PORT_ACTIVE;
332 event.element.port_num = port; 328 event.element.port_num = port;
@@ -401,115 +397,170 @@ irqreturn_t ehca_interrupt_eq(int irq, void *dev_id)
401 return IRQ_HANDLED; 397 return IRQ_HANDLED;
402} 398}
403 399
404void ehca_tasklet_eq(unsigned long data)
405{
406 struct ehca_shca *shca = (struct ehca_shca*)data;
407 struct ehca_eqe *eqe;
408 int int_state;
409 int query_cnt = 0;
410 400
411 do { 401static inline void process_eqe(struct ehca_shca *shca, struct ehca_eqe *eqe)
412 eqe = (struct ehca_eqe *)ehca_poll_eq(shca, &shca->eq); 402{
403 u64 eqe_value;
404 u32 token;
405 unsigned long flags;
406 struct ehca_cq *cq;
407 eqe_value = eqe->entry;
408 ehca_dbg(&shca->ib_device, "eqe_value=%lx", eqe_value);
409 if (EHCA_BMASK_GET(EQE_COMPLETION_EVENT, eqe_value)) {
410 ehca_dbg(&shca->ib_device, "... completion event");
411 token = EHCA_BMASK_GET(EQE_CQ_TOKEN, eqe_value);
412 spin_lock_irqsave(&ehca_cq_idr_lock, flags);
413 cq = idr_find(&ehca_cq_idr, token);
414 if (cq == NULL) {
415 spin_unlock_irqrestore(&ehca_cq_idr_lock, flags);
416 ehca_err(&shca->ib_device,
417 "Invalid eqe for non-existing cq token=%x",
418 token);
419 return;
420 }
421 reset_eq_pending(cq);
422 if (ehca_scaling_code) {
423 queue_comp_task(cq);
424 spin_unlock_irqrestore(&ehca_cq_idr_lock, flags);
425 } else {
426 spin_unlock_irqrestore(&ehca_cq_idr_lock, flags);
427 comp_event_callback(cq);
428 }
429 } else {
430 ehca_dbg(&shca->ib_device,
431 "Got non completion event");
432 parse_identifier(shca, eqe_value);
433 }
434}
413 435
414 if ((shca->hw_level >= 2) && eqe) 436void ehca_process_eq(struct ehca_shca *shca, int is_irq)
415 int_state = 1; 437{
416 else 438 struct ehca_eq *eq = &shca->eq;
417 int_state = 0; 439 struct ehca_eqe_cache_entry *eqe_cache = eq->eqe_cache;
418 440 u64 eqe_value;
419 while ((int_state == 1) || eqe) { 441 unsigned long flags;
420 while (eqe) { 442 int eqe_cnt, i;
421 u64 eqe_value = eqe->entry; 443 int eq_empty = 0;
422 444
423 ehca_dbg(&shca->ib_device, 445 spin_lock_irqsave(&eq->irq_spinlock, flags);
424 "eqe_value=%lx", eqe_value); 446 if (is_irq) {
425 447 const int max_query_cnt = 100;
426 /* TODO: better structure */ 448 int query_cnt = 0;
427 if (EHCA_BMASK_GET(EQE_COMPLETION_EVENT, 449 int int_state = 1;
428 eqe_value)) { 450 do {
429 unsigned long flags; 451 int_state = hipz_h_query_int_state(
430 u32 token; 452 shca->ipz_hca_handle, eq->ist);
431 struct ehca_cq *cq; 453 query_cnt++;
432 454 iosync();
433 ehca_dbg(&shca->ib_device, 455 } while (int_state && query_cnt < max_query_cnt);
434 "... completion event"); 456 if (unlikely((query_cnt == max_query_cnt)))
435 token = 457 ehca_dbg(&shca->ib_device, "int_state=%x query_cnt=%x",
436 EHCA_BMASK_GET(EQE_CQ_TOKEN, 458 int_state, query_cnt);
437 eqe_value); 459 }
438 spin_lock_irqsave(&ehca_cq_idr_lock,
439 flags);
440 cq = idr_find(&ehca_cq_idr, token);
441
442 if (cq == NULL) {
443 spin_unlock_irqrestore(&ehca_cq_idr_lock,
444 flags);
445 break;
446 }
447
448 reset_eq_pending(cq);
449#ifdef CONFIG_INFINIBAND_EHCA_SCALING
450 queue_comp_task(cq);
451 spin_unlock_irqrestore(&ehca_cq_idr_lock,
452 flags);
453#else
454 spin_unlock_irqrestore(&ehca_cq_idr_lock,
455 flags);
456 comp_event_callback(cq);
457#endif
458 } else {
459 ehca_dbg(&shca->ib_device,
460 "... non completion event");
461 parse_identifier(shca, eqe_value);
462 }
463 eqe =
464 (struct ehca_eqe *)ehca_poll_eq(shca,
465 &shca->eq);
466 }
467 460
468 if (shca->hw_level >= 2) { 461 /* read out all eqes */
469 int_state = 462 eqe_cnt = 0;
470 hipz_h_query_int_state(shca->ipz_hca_handle, 463 do {
471 shca->eq.ist); 464 u32 token;
472 query_cnt++; 465 eqe_cache[eqe_cnt].eqe =
473 iosync(); 466 (struct ehca_eqe *)ehca_poll_eq(shca, eq);
474 if (query_cnt >= 100) { 467 if (!eqe_cache[eqe_cnt].eqe)
475 query_cnt = 0; 468 break;
476 int_state = 0; 469 eqe_value = eqe_cache[eqe_cnt].eqe->entry;
477 } 470 if (EHCA_BMASK_GET(EQE_COMPLETION_EVENT, eqe_value)) {
471 token = EHCA_BMASK_GET(EQE_CQ_TOKEN, eqe_value);
472 spin_lock(&ehca_cq_idr_lock);
473 eqe_cache[eqe_cnt].cq = idr_find(&ehca_cq_idr, token);
474 if (!eqe_cache[eqe_cnt].cq) {
475 spin_unlock(&ehca_cq_idr_lock);
476 ehca_err(&shca->ib_device,
477 "Invalid eqe for non-existing cq "
478 "token=%x", token);
479 continue;
478 } 480 }
479 eqe = (struct ehca_eqe *)ehca_poll_eq(shca, &shca->eq); 481 spin_unlock(&ehca_cq_idr_lock);
480 482 } else
483 eqe_cache[eqe_cnt].cq = NULL;
484 eqe_cnt++;
485 } while (eqe_cnt < EHCA_EQE_CACHE_SIZE);
486 if (!eqe_cnt) {
487 if (is_irq)
488 ehca_dbg(&shca->ib_device,
489 "No eqe found for irq event");
490 goto unlock_irq_spinlock;
491 } else if (!is_irq)
492 ehca_dbg(&shca->ib_device, "deadman found %x eqe", eqe_cnt);
493 if (unlikely(eqe_cnt == EHCA_EQE_CACHE_SIZE))
494 ehca_dbg(&shca->ib_device, "too many eqes for one irq event");
495 /* enable irq for new packets */
496 for (i = 0; i < eqe_cnt; i++) {
497 if (eq->eqe_cache[i].cq)
498 reset_eq_pending(eq->eqe_cache[i].cq);
499 }
500 /* check eq */
501 spin_lock(&eq->spinlock);
502 eq_empty = (!ipz_eqit_eq_peek_valid(&shca->eq.ipz_queue));
503 spin_unlock(&eq->spinlock);
504 /* call completion handler for cached eqes */
505 for (i = 0; i < eqe_cnt; i++)
506 if (eq->eqe_cache[i].cq) {
507 if (ehca_scaling_code) {
508 spin_lock(&ehca_cq_idr_lock);
509 queue_comp_task(eq->eqe_cache[i].cq);
510 spin_unlock(&ehca_cq_idr_lock);
511 } else
512 comp_event_callback(eq->eqe_cache[i].cq);
513 } else {
514 ehca_dbg(&shca->ib_device, "Got non completion event");
515 parse_identifier(shca, eq->eqe_cache[i].eqe->entry);
481 } 516 }
482 } while (int_state != 0); 517 /* poll eq if not empty */
483 518 if (eq_empty)
484 return; 519 goto unlock_irq_spinlock;
520 do {
521 struct ehca_eqe *eqe;
522 eqe = (struct ehca_eqe *)ehca_poll_eq(shca, &shca->eq);
523 if (!eqe)
524 break;
525 process_eqe(shca, eqe);
526 eqe_cnt++;
527 } while (1);
528
529unlock_irq_spinlock:
530 spin_unlock_irqrestore(&eq->irq_spinlock, flags);
485} 531}
486 532
487#ifdef CONFIG_INFINIBAND_EHCA_SCALING 533void ehca_tasklet_eq(unsigned long data)
534{
535 ehca_process_eq((struct ehca_shca*)data, 1);
536}
488 537
489static inline int find_next_online_cpu(struct ehca_comp_pool* pool) 538static inline int find_next_online_cpu(struct ehca_comp_pool* pool)
490{ 539{
491 unsigned long flags_last_cpu; 540 int cpu;
541 unsigned long flags;
492 542
543 WARN_ON_ONCE(!in_interrupt());
493 if (ehca_debug_level) 544 if (ehca_debug_level)
494 ehca_dmp(&cpu_online_map, sizeof(cpumask_t), ""); 545 ehca_dmp(&cpu_online_map, sizeof(cpumask_t), "");
495 546
496 spin_lock_irqsave(&pool->last_cpu_lock, flags_last_cpu); 547 spin_lock_irqsave(&pool->last_cpu_lock, flags);
497 pool->last_cpu = next_cpu(pool->last_cpu, cpu_online_map); 548 cpu = next_cpu(pool->last_cpu, cpu_online_map);
498 if (pool->last_cpu == NR_CPUS) 549 if (cpu == NR_CPUS)
499 pool->last_cpu = first_cpu(cpu_online_map); 550 cpu = first_cpu(cpu_online_map);
500 spin_unlock_irqrestore(&pool->last_cpu_lock, flags_last_cpu); 551 pool->last_cpu = cpu;
552 spin_unlock_irqrestore(&pool->last_cpu_lock, flags);
501 553
502 return pool->last_cpu; 554 return cpu;
503} 555}
504 556
505static void __queue_comp_task(struct ehca_cq *__cq, 557static void __queue_comp_task(struct ehca_cq *__cq,
506 struct ehca_cpu_comp_task *cct) 558 struct ehca_cpu_comp_task *cct)
507{ 559{
508 unsigned long flags_cct; 560 unsigned long flags;
509 unsigned long flags_cq;
510 561
511 spin_lock_irqsave(&cct->task_lock, flags_cct); 562 spin_lock_irqsave(&cct->task_lock, flags);
512 spin_lock_irqsave(&__cq->task_lock, flags_cq); 563 spin_lock(&__cq->task_lock);
513 564
514 if (__cq->nr_callbacks == 0) { 565 if (__cq->nr_callbacks == 0) {
515 __cq->nr_callbacks++; 566 __cq->nr_callbacks++;
@@ -520,8 +571,8 @@ static void __queue_comp_task(struct ehca_cq *__cq,
520 else 571 else
521 __cq->nr_callbacks++; 572 __cq->nr_callbacks++;
522 573
523 spin_unlock_irqrestore(&__cq->task_lock, flags_cq); 574 spin_unlock(&__cq->task_lock);
524 spin_unlock_irqrestore(&cct->task_lock, flags_cct); 575 spin_unlock_irqrestore(&cct->task_lock, flags);
525} 576}
526 577
527static void queue_comp_task(struct ehca_cq *__cq) 578static void queue_comp_task(struct ehca_cq *__cq)
@@ -532,69 +583,69 @@ static void queue_comp_task(struct ehca_cq *__cq)
532 583
533 cpu = get_cpu(); 584 cpu = get_cpu();
534 cpu_id = find_next_online_cpu(pool); 585 cpu_id = find_next_online_cpu(pool);
535
536 BUG_ON(!cpu_online(cpu_id)); 586 BUG_ON(!cpu_online(cpu_id));
537 587
538 cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu_id); 588 cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu_id);
589 BUG_ON(!cct);
539 590
540 if (cct->cq_jobs > 0) { 591 if (cct->cq_jobs > 0) {
541 cpu_id = find_next_online_cpu(pool); 592 cpu_id = find_next_online_cpu(pool);
542 cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu_id); 593 cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu_id);
594 BUG_ON(!cct);
543 } 595 }
544 596
545 __queue_comp_task(__cq, cct); 597 __queue_comp_task(__cq, cct);
546
547 put_cpu();
548
549 return;
550} 598}
551 599
552static void run_comp_task(struct ehca_cpu_comp_task* cct) 600static void run_comp_task(struct ehca_cpu_comp_task* cct)
553{ 601{
554 struct ehca_cq *cq; 602 struct ehca_cq *cq;
555 unsigned long flags_cct; 603 unsigned long flags;
556 unsigned long flags_cq;
557 604
558 spin_lock_irqsave(&cct->task_lock, flags_cct); 605 spin_lock_irqsave(&cct->task_lock, flags);
559 606
560 while (!list_empty(&cct->cq_list)) { 607 while (!list_empty(&cct->cq_list)) {
561 cq = list_entry(cct->cq_list.next, struct ehca_cq, entry); 608 cq = list_entry(cct->cq_list.next, struct ehca_cq, entry);
562 spin_unlock_irqrestore(&cct->task_lock, flags_cct); 609 spin_unlock_irqrestore(&cct->task_lock, flags);
563 comp_event_callback(cq); 610 comp_event_callback(cq);
564 spin_lock_irqsave(&cct->task_lock, flags_cct); 611 spin_lock_irqsave(&cct->task_lock, flags);
565 612
566 spin_lock_irqsave(&cq->task_lock, flags_cq); 613 spin_lock(&cq->task_lock);
567 cq->nr_callbacks--; 614 cq->nr_callbacks--;
568 if (cq->nr_callbacks == 0) { 615 if (cq->nr_callbacks == 0) {
569 list_del_init(cct->cq_list.next); 616 list_del_init(cct->cq_list.next);
570 cct->cq_jobs--; 617 cct->cq_jobs--;
571 } 618 }
572 spin_unlock_irqrestore(&cq->task_lock, flags_cq); 619 spin_unlock(&cq->task_lock);
573
574 } 620 }
575 621
576 spin_unlock_irqrestore(&cct->task_lock, flags_cct); 622 spin_unlock_irqrestore(&cct->task_lock, flags);
577
578 return;
579} 623}
580 624
581static int comp_task(void *__cct) 625static int comp_task(void *__cct)
582{ 626{
583 struct ehca_cpu_comp_task* cct = __cct; 627 struct ehca_cpu_comp_task* cct = __cct;
628 int cql_empty;
584 DECLARE_WAITQUEUE(wait, current); 629 DECLARE_WAITQUEUE(wait, current);
585 630
586 set_current_state(TASK_INTERRUPTIBLE); 631 set_current_state(TASK_INTERRUPTIBLE);
587 while(!kthread_should_stop()) { 632 while(!kthread_should_stop()) {
588 add_wait_queue(&cct->wait_queue, &wait); 633 add_wait_queue(&cct->wait_queue, &wait);
589 634
590 if (list_empty(&cct->cq_list)) 635 spin_lock_irq(&cct->task_lock);
636 cql_empty = list_empty(&cct->cq_list);
637 spin_unlock_irq(&cct->task_lock);
638 if (cql_empty)
591 schedule(); 639 schedule();
592 else 640 else
593 __set_current_state(TASK_RUNNING); 641 __set_current_state(TASK_RUNNING);
594 642
595 remove_wait_queue(&cct->wait_queue, &wait); 643 remove_wait_queue(&cct->wait_queue, &wait);
596 644
597 if (!list_empty(&cct->cq_list)) 645 spin_lock_irq(&cct->task_lock);
646 cql_empty = list_empty(&cct->cq_list);
647 spin_unlock_irq(&cct->task_lock);
648 if (!cql_empty)
598 run_comp_task(__cct); 649 run_comp_task(__cct);
599 650
600 set_current_state(TASK_INTERRUPTIBLE); 651 set_current_state(TASK_INTERRUPTIBLE);
@@ -637,8 +688,6 @@ static void destroy_comp_task(struct ehca_comp_pool *pool,
637 688
638 if (task) 689 if (task)
639 kthread_stop(task); 690 kthread_stop(task);
640
641 return;
642} 691}
643 692
644static void take_over_work(struct ehca_comp_pool *pool, 693static void take_over_work(struct ehca_comp_pool *pool,
@@ -654,11 +703,11 @@ static void take_over_work(struct ehca_comp_pool *pool,
654 list_splice_init(&cct->cq_list, &list); 703 list_splice_init(&cct->cq_list, &list);
655 704
656 while(!list_empty(&list)) { 705 while(!list_empty(&list)) {
657 cq = list_entry(cct->cq_list.next, struct ehca_cq, entry); 706 cq = list_entry(cct->cq_list.next, struct ehca_cq, entry);
658 707
659 list_del(&cq->entry); 708 list_del(&cq->entry);
660 __queue_comp_task(cq, per_cpu_ptr(pool->cpu_comp_tasks, 709 __queue_comp_task(cq, per_cpu_ptr(pool->cpu_comp_tasks,
661 smp_processor_id())); 710 smp_processor_id()));
662 } 711 }
663 712
664 spin_unlock_irqrestore(&cct->task_lock, flags_cct); 713 spin_unlock_irqrestore(&cct->task_lock, flags_cct);
@@ -708,14 +757,14 @@ static int comp_pool_callback(struct notifier_block *nfb,
708 return NOTIFY_OK; 757 return NOTIFY_OK;
709} 758}
710 759
711#endif
712
713int ehca_create_comp_pool(void) 760int ehca_create_comp_pool(void)
714{ 761{
715#ifdef CONFIG_INFINIBAND_EHCA_SCALING
716 int cpu; 762 int cpu;
717 struct task_struct *task; 763 struct task_struct *task;
718 764
765 if (!ehca_scaling_code)
766 return 0;
767
719 pool = kzalloc(sizeof(struct ehca_comp_pool), GFP_KERNEL); 768 pool = kzalloc(sizeof(struct ehca_comp_pool), GFP_KERNEL);
720 if (pool == NULL) 769 if (pool == NULL)
721 return -ENOMEM; 770 return -ENOMEM;
@@ -740,16 +789,19 @@ int ehca_create_comp_pool(void)
740 comp_pool_callback_nb.notifier_call = comp_pool_callback; 789 comp_pool_callback_nb.notifier_call = comp_pool_callback;
741 comp_pool_callback_nb.priority =0; 790 comp_pool_callback_nb.priority =0;
742 register_cpu_notifier(&comp_pool_callback_nb); 791 register_cpu_notifier(&comp_pool_callback_nb);
743#endif 792
793 printk(KERN_INFO "eHCA scaling code enabled\n");
744 794
745 return 0; 795 return 0;
746} 796}
747 797
748void ehca_destroy_comp_pool(void) 798void ehca_destroy_comp_pool(void)
749{ 799{
750#ifdef CONFIG_INFINIBAND_EHCA_SCALING
751 int i; 800 int i;
752 801
802 if (!ehca_scaling_code)
803 return;
804
753 unregister_cpu_notifier(&comp_pool_callback_nb); 805 unregister_cpu_notifier(&comp_pool_callback_nb);
754 806
755 for (i = 0; i < NR_CPUS; i++) { 807 for (i = 0; i < NR_CPUS; i++) {
@@ -758,7 +810,4 @@ void ehca_destroy_comp_pool(void)
758 } 810 }
759 free_percpu(pool->cpu_comp_tasks); 811 free_percpu(pool->cpu_comp_tasks);
760 kfree(pool); 812 kfree(pool);
761#endif
762
763 return;
764} 813}
diff --git a/drivers/infiniband/hw/ehca/ehca_irq.h b/drivers/infiniband/hw/ehca/ehca_irq.h
index be579cc0adf6..6ed06ee033ed 100644
--- a/drivers/infiniband/hw/ehca/ehca_irq.h
+++ b/drivers/infiniband/hw/ehca/ehca_irq.h
@@ -56,6 +56,7 @@ void ehca_tasklet_neq(unsigned long data);
56 56
57irqreturn_t ehca_interrupt_eq(int irq, void *dev_id); 57irqreturn_t ehca_interrupt_eq(int irq, void *dev_id);
58void ehca_tasklet_eq(unsigned long data); 58void ehca_tasklet_eq(unsigned long data);
59void ehca_process_eq(struct ehca_shca *shca, int is_irq);
59 60
60struct ehca_cpu_comp_task { 61struct ehca_cpu_comp_task {
61 wait_queue_head_t wait_queue; 62 wait_queue_head_t wait_queue;
diff --git a/drivers/infiniband/hw/ehca/ehca_main.c b/drivers/infiniband/hw/ehca/ehca_main.c
index 1155bcf48212..c1835121a822 100644
--- a/drivers/infiniband/hw/ehca/ehca_main.c
+++ b/drivers/infiniband/hw/ehca/ehca_main.c
@@ -52,7 +52,7 @@
52MODULE_LICENSE("Dual BSD/GPL"); 52MODULE_LICENSE("Dual BSD/GPL");
53MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>"); 53MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
54MODULE_DESCRIPTION("IBM eServer HCA InfiniBand Device Driver"); 54MODULE_DESCRIPTION("IBM eServer HCA InfiniBand Device Driver");
55MODULE_VERSION("SVNEHCA_0020"); 55MODULE_VERSION("SVNEHCA_0021");
56 56
57int ehca_open_aqp1 = 0; 57int ehca_open_aqp1 = 0;
58int ehca_debug_level = 0; 58int ehca_debug_level = 0;
@@ -62,6 +62,7 @@ int ehca_use_hp_mr = 0;
62int ehca_port_act_time = 30; 62int ehca_port_act_time = 30;
63int ehca_poll_all_eqs = 1; 63int ehca_poll_all_eqs = 1;
64int ehca_static_rate = -1; 64int ehca_static_rate = -1;
65int ehca_scaling_code = 1;
65 66
66module_param_named(open_aqp1, ehca_open_aqp1, int, 0); 67module_param_named(open_aqp1, ehca_open_aqp1, int, 0);
67module_param_named(debug_level, ehca_debug_level, int, 0); 68module_param_named(debug_level, ehca_debug_level, int, 0);
@@ -71,6 +72,7 @@ module_param_named(use_hp_mr, ehca_use_hp_mr, int, 0);
71module_param_named(port_act_time, ehca_port_act_time, int, 0); 72module_param_named(port_act_time, ehca_port_act_time, int, 0);
72module_param_named(poll_all_eqs, ehca_poll_all_eqs, int, 0); 73module_param_named(poll_all_eqs, ehca_poll_all_eqs, int, 0);
73module_param_named(static_rate, ehca_static_rate, int, 0); 74module_param_named(static_rate, ehca_static_rate, int, 0);
75module_param_named(scaling_code, ehca_scaling_code, int, 0);
74 76
75MODULE_PARM_DESC(open_aqp1, 77MODULE_PARM_DESC(open_aqp1,
76 "AQP1 on startup (0: no (default), 1: yes)"); 78 "AQP1 on startup (0: no (default), 1: yes)");
@@ -91,6 +93,8 @@ MODULE_PARM_DESC(poll_all_eqs,
91 " (0: no, 1: yes (default))"); 93 " (0: no, 1: yes (default))");
92MODULE_PARM_DESC(static_rate, 94MODULE_PARM_DESC(static_rate,
93 "set permanent static rate (default: disabled)"); 95 "set permanent static rate (default: disabled)");
96MODULE_PARM_DESC(scaling_code,
97 "set scaling code (0: disabled, 1: enabled/default)");
94 98
95spinlock_t ehca_qp_idr_lock; 99spinlock_t ehca_qp_idr_lock;
96spinlock_t ehca_cq_idr_lock; 100spinlock_t ehca_cq_idr_lock;
@@ -432,8 +436,8 @@ static int ehca_destroy_aqp1(struct ehca_sport *sport)
432 436
433static ssize_t ehca_show_debug_level(struct device_driver *ddp, char *buf) 437static ssize_t ehca_show_debug_level(struct device_driver *ddp, char *buf)
434{ 438{
435 return snprintf(buf, PAGE_SIZE, "%d\n", 439 return snprintf(buf, PAGE_SIZE, "%d\n",
436 ehca_debug_level); 440 ehca_debug_level);
437} 441}
438 442
439static ssize_t ehca_store_debug_level(struct device_driver *ddp, 443static ssize_t ehca_store_debug_level(struct device_driver *ddp,
@@ -778,8 +782,24 @@ void ehca_poll_eqs(unsigned long data)
778 782
779 spin_lock(&shca_list_lock); 783 spin_lock(&shca_list_lock);
780 list_for_each_entry(shca, &shca_list, shca_list) { 784 list_for_each_entry(shca, &shca_list, shca_list) {
781 if (shca->eq.is_initialized) 785 if (shca->eq.is_initialized) {
782 ehca_tasklet_eq((unsigned long)(void*)shca); 786 /* call deadman proc only if eq ptr does not change */
787 struct ehca_eq *eq = &shca->eq;
788 int max = 3;
789 volatile u64 q_ofs, q_ofs2;
790 u64 flags;
791 spin_lock_irqsave(&eq->spinlock, flags);
792 q_ofs = eq->ipz_queue.current_q_offset;
793 spin_unlock_irqrestore(&eq->spinlock, flags);
794 do {
795 spin_lock_irqsave(&eq->spinlock, flags);
796 q_ofs2 = eq->ipz_queue.current_q_offset;
797 spin_unlock_irqrestore(&eq->spinlock, flags);
798 max--;
799 } while (q_ofs == q_ofs2 && max > 0);
800 if (q_ofs == q_ofs2)
801 ehca_process_eq(shca, 0);
802 }
783 } 803 }
784 mod_timer(&poll_eqs_timer, jiffies + HZ); 804 mod_timer(&poll_eqs_timer, jiffies + HZ);
785 spin_unlock(&shca_list_lock); 805 spin_unlock(&shca_list_lock);
@@ -790,7 +810,7 @@ int __init ehca_module_init(void)
790 int ret; 810 int ret;
791 811
792 printk(KERN_INFO "eHCA Infiniband Device Driver " 812 printk(KERN_INFO "eHCA Infiniband Device Driver "
793 "(Rel.: SVNEHCA_0020)\n"); 813 "(Rel.: SVNEHCA_0021)\n");
794 idr_init(&ehca_qp_idr); 814 idr_init(&ehca_qp_idr);
795 idr_init(&ehca_cq_idr); 815 idr_init(&ehca_cq_idr);
796 spin_lock_init(&ehca_qp_idr_lock); 816 spin_lock_init(&ehca_qp_idr_lock);
diff --git a/drivers/infiniband/hw/ehca/ipz_pt_fn.h b/drivers/infiniband/hw/ehca/ipz_pt_fn.h
index dc3bda2634b7..8199c45768a3 100644
--- a/drivers/infiniband/hw/ehca/ipz_pt_fn.h
+++ b/drivers/infiniband/hw/ehca/ipz_pt_fn.h
@@ -79,7 +79,7 @@ static inline void *ipz_qeit_calc(struct ipz_queue *queue, u64 q_offset)
79 if (q_offset >= queue->queue_length) 79 if (q_offset >= queue->queue_length)
80 return NULL; 80 return NULL;
81 current_page = (queue->queue_pages)[q_offset >> EHCA_PAGESHIFT]; 81 current_page = (queue->queue_pages)[q_offset >> EHCA_PAGESHIFT];
82 return &current_page->entries[q_offset & (EHCA_PAGESIZE - 1)]; 82 return &current_page->entries[q_offset & (EHCA_PAGESIZE - 1)];
83} 83}
84 84
85/* 85/*
@@ -247,6 +247,15 @@ static inline void *ipz_eqit_eq_get_inc_valid(struct ipz_queue *queue)
247 return ret; 247 return ret;
248} 248}
249 249
250static inline void *ipz_eqit_eq_peek_valid(struct ipz_queue *queue)
251{
252 void *ret = ipz_qeit_get(queue);
253 u32 qe = *(u8 *) ret;
254 if ((qe >> 7) != (queue->toggle_state & 1))
255 return NULL;
256 return ret;
257}
258
250/* returns address (GX) of first queue entry */ 259/* returns address (GX) of first queue entry */
251static inline u64 ipz_qpt_get_firstpage(struct ipz_qpt *qpt) 260static inline u64 ipz_qpt_get_firstpage(struct ipz_qpt *qpt)
252{ 261{
diff --git a/drivers/infiniband/hw/ipath/ipath_dma.c b/drivers/infiniband/hw/ipath/ipath_dma.c
index 6e0f2b8918ce..f6f949040825 100644
--- a/drivers/infiniband/hw/ipath/ipath_dma.c
+++ b/drivers/infiniband/hw/ipath/ipath_dma.c
@@ -96,8 +96,8 @@ static void ipath_dma_unmap_page(struct ib_device *dev,
96 BUG_ON(!valid_dma_direction(direction)); 96 BUG_ON(!valid_dma_direction(direction));
97} 97}
98 98
99int ipath_map_sg(struct ib_device *dev, struct scatterlist *sg, int nents, 99static int ipath_map_sg(struct ib_device *dev, struct scatterlist *sg, int nents,
100 enum dma_data_direction direction) 100 enum dma_data_direction direction)
101{ 101{
102 u64 addr; 102 u64 addr;
103 int i; 103 int i;
diff --git a/drivers/infiniband/hw/mthca/mthca_memfree.c b/drivers/infiniband/hw/mthca/mthca_memfree.c
index 0b9d053a599d..48f7c65e9aed 100644
--- a/drivers/infiniband/hw/mthca/mthca_memfree.c
+++ b/drivers/infiniband/hw/mthca/mthca_memfree.c
@@ -175,7 +175,9 @@ struct mthca_icm *mthca_alloc_icm(struct mthca_dev *dev, int npages,
175 if (!ret) { 175 if (!ret) {
176 ++chunk->npages; 176 ++chunk->npages;
177 177
178 if (!coherent && chunk->npages == MTHCA_ICM_CHUNK_LEN) { 178 if (coherent)
179 ++chunk->nsg;
180 else if (chunk->npages == MTHCA_ICM_CHUNK_LEN) {
179 chunk->nsg = pci_map_sg(dev->pdev, chunk->mem, 181 chunk->nsg = pci_map_sg(dev->pdev, chunk->mem,
180 chunk->npages, 182 chunk->npages,
181 PCI_DMA_BIDIRECTIONAL); 183 PCI_DMA_BIDIRECTIONAL);
diff --git a/drivers/infiniband/hw/mthca/mthca_qp.c b/drivers/infiniband/hw/mthca/mthca_qp.c
index 224c93dd29eb..71dc84bd4254 100644
--- a/drivers/infiniband/hw/mthca/mthca_qp.c
+++ b/drivers/infiniband/hw/mthca/mthca_qp.c
@@ -573,6 +573,11 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask,
573 goto out; 573 goto out;
574 } 574 }
575 575
576 if (cur_state == new_state && cur_state == IB_QPS_RESET) {
577 err = 0;
578 goto out;
579 }
580
576 if ((attr_mask & IB_QP_PKEY_INDEX) && 581 if ((attr_mask & IB_QP_PKEY_INDEX) &&
577 attr->pkey_index >= dev->limits.pkey_table_len) { 582 attr->pkey_index >= dev->limits.pkey_table_len) {
578 mthca_dbg(dev, "P_Key index (%u) too large. max is %d\n", 583 mthca_dbg(dev, "P_Key index (%u) too large. max is %d\n",
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_cm.c b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
index 2d483874a589..4d59682f7d4a 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_cm.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
@@ -145,7 +145,7 @@ partial_error:
145 for (; i >= 0; --i) 145 for (; i >= 0; --i)
146 ib_dma_unmap_single(priv->ca, mapping[i + 1], PAGE_SIZE, DMA_FROM_DEVICE); 146 ib_dma_unmap_single(priv->ca, mapping[i + 1], PAGE_SIZE, DMA_FROM_DEVICE);
147 147
148 kfree_skb(skb); 148 dev_kfree_skb_any(skb);
149 return -ENOMEM; 149 return -ENOMEM;
150} 150}
151 151
@@ -1138,7 +1138,7 @@ static ssize_t set_mode(struct device *d, struct device_attribute *attr,
1138 return -EINVAL; 1138 return -EINVAL;
1139} 1139}
1140 1140
1141static DEVICE_ATTR(mode, S_IWUGO | S_IRUGO, show_mode, set_mode); 1141static DEVICE_ATTR(mode, S_IWUSR | S_IRUGO, show_mode, set_mode);
1142 1142
1143int ipoib_cm_add_mode_attr(struct net_device *dev) 1143int ipoib_cm_add_mode_attr(struct net_device *dev)
1144{ 1144{
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
index fea737f520fd..b303ce6bc21e 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
@@ -60,14 +60,11 @@ static DEFINE_MUTEX(mcast_mutex);
60/* Used for all multicast joins (broadcast, IPv4 mcast and IPv6 mcast) */ 60/* Used for all multicast joins (broadcast, IPv4 mcast and IPv6 mcast) */
61struct ipoib_mcast { 61struct ipoib_mcast {
62 struct ib_sa_mcmember_rec mcmember; 62 struct ib_sa_mcmember_rec mcmember;
63 struct ib_sa_multicast *mc;
63 struct ipoib_ah *ah; 64 struct ipoib_ah *ah;
64 65
65 struct rb_node rb_node; 66 struct rb_node rb_node;
66 struct list_head list; 67 struct list_head list;
67 struct completion done;
68
69 int query_id;
70 struct ib_sa_query *query;
71 68
72 unsigned long created; 69 unsigned long created;
73 unsigned long backoff; 70 unsigned long backoff;
@@ -299,18 +296,22 @@ static int ipoib_mcast_join_finish(struct ipoib_mcast *mcast,
299 return 0; 296 return 0;
300} 297}
301 298
302static void 299static int
303ipoib_mcast_sendonly_join_complete(int status, 300ipoib_mcast_sendonly_join_complete(int status,
304 struct ib_sa_mcmember_rec *mcmember, 301 struct ib_sa_multicast *multicast)
305 void *mcast_ptr)
306{ 302{
307 struct ipoib_mcast *mcast = mcast_ptr; 303 struct ipoib_mcast *mcast = multicast->context;
308 struct net_device *dev = mcast->dev; 304 struct net_device *dev = mcast->dev;
309 struct ipoib_dev_priv *priv = netdev_priv(dev); 305 struct ipoib_dev_priv *priv = netdev_priv(dev);
310 306
307 /* We trap for port events ourselves. */
308 if (status == -ENETRESET)
309 return 0;
310
311 if (!status) 311 if (!status)
312 ipoib_mcast_join_finish(mcast, mcmember); 312 status = ipoib_mcast_join_finish(mcast, &multicast->rec);
313 else { 313
314 if (status) {
314 if (mcast->logcount++ < 20) 315 if (mcast->logcount++ < 20)
315 ipoib_dbg_mcast(netdev_priv(dev), "multicast join failed for " 316 ipoib_dbg_mcast(netdev_priv(dev), "multicast join failed for "
316 IPOIB_GID_FMT ", status %d\n", 317 IPOIB_GID_FMT ", status %d\n",
@@ -325,11 +326,10 @@ ipoib_mcast_sendonly_join_complete(int status,
325 spin_unlock_irq(&priv->tx_lock); 326 spin_unlock_irq(&priv->tx_lock);
326 327
327 /* Clear the busy flag so we try again */ 328 /* Clear the busy flag so we try again */
328 clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags); 329 status = test_and_clear_bit(IPOIB_MCAST_FLAG_BUSY,
329 mcast->query = NULL; 330 &mcast->flags);
330 } 331 }
331 332 return status;
332 complete(&mcast->done);
333} 333}
334 334
335static int ipoib_mcast_sendonly_join(struct ipoib_mcast *mcast) 335static int ipoib_mcast_sendonly_join(struct ipoib_mcast *mcast)
@@ -359,35 +359,33 @@ static int ipoib_mcast_sendonly_join(struct ipoib_mcast *mcast)
359 rec.port_gid = priv->local_gid; 359 rec.port_gid = priv->local_gid;
360 rec.pkey = cpu_to_be16(priv->pkey); 360 rec.pkey = cpu_to_be16(priv->pkey);
361 361
362 init_completion(&mcast->done); 362 mcast->mc = ib_sa_join_multicast(&ipoib_sa_client, priv->ca,
363 363 priv->port, &rec,
364 ret = ib_sa_mcmember_rec_set(&ipoib_sa_client, priv->ca, priv->port, &rec, 364 IB_SA_MCMEMBER_REC_MGID |
365 IB_SA_MCMEMBER_REC_MGID | 365 IB_SA_MCMEMBER_REC_PORT_GID |
366 IB_SA_MCMEMBER_REC_PORT_GID | 366 IB_SA_MCMEMBER_REC_PKEY |
367 IB_SA_MCMEMBER_REC_PKEY | 367 IB_SA_MCMEMBER_REC_JOIN_STATE,
368 IB_SA_MCMEMBER_REC_JOIN_STATE, 368 GFP_ATOMIC,
369 1000, GFP_ATOMIC, 369 ipoib_mcast_sendonly_join_complete,
370 ipoib_mcast_sendonly_join_complete, 370 mcast);
371 mcast, &mcast->query); 371 if (IS_ERR(mcast->mc)) {
372 if (ret < 0) { 372 ret = PTR_ERR(mcast->mc);
373 ipoib_warn(priv, "ib_sa_mcmember_rec_set failed (ret = %d)\n", 373 clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags);
374 ipoib_warn(priv, "ib_sa_join_multicast failed (ret = %d)\n",
374 ret); 375 ret);
375 } else { 376 } else {
376 ipoib_dbg_mcast(priv, "no multicast record for " IPOIB_GID_FMT 377 ipoib_dbg_mcast(priv, "no multicast record for " IPOIB_GID_FMT
377 ", starting join\n", 378 ", starting join\n",
378 IPOIB_GID_ARG(mcast->mcmember.mgid)); 379 IPOIB_GID_ARG(mcast->mcmember.mgid));
379
380 mcast->query_id = ret;
381 } 380 }
382 381
383 return ret; 382 return ret;
384} 383}
385 384
386static void ipoib_mcast_join_complete(int status, 385static int ipoib_mcast_join_complete(int status,
387 struct ib_sa_mcmember_rec *mcmember, 386 struct ib_sa_multicast *multicast)
388 void *mcast_ptr)
389{ 387{
390 struct ipoib_mcast *mcast = mcast_ptr; 388 struct ipoib_mcast *mcast = multicast->context;
391 struct net_device *dev = mcast->dev; 389 struct net_device *dev = mcast->dev;
392 struct ipoib_dev_priv *priv = netdev_priv(dev); 390 struct ipoib_dev_priv *priv = netdev_priv(dev);
393 391
@@ -395,24 +393,25 @@ static void ipoib_mcast_join_complete(int status,
395 " (status %d)\n", 393 " (status %d)\n",
396 IPOIB_GID_ARG(mcast->mcmember.mgid), status); 394 IPOIB_GID_ARG(mcast->mcmember.mgid), status);
397 395
398 if (!status && !ipoib_mcast_join_finish(mcast, mcmember)) { 396 /* We trap for port events ourselves. */
397 if (status == -ENETRESET)
398 return 0;
399
400 if (!status)
401 status = ipoib_mcast_join_finish(mcast, &multicast->rec);
402
403 if (!status) {
399 mcast->backoff = 1; 404 mcast->backoff = 1;
400 mutex_lock(&mcast_mutex); 405 mutex_lock(&mcast_mutex);
401 if (test_bit(IPOIB_MCAST_RUN, &priv->flags)) 406 if (test_bit(IPOIB_MCAST_RUN, &priv->flags))
402 queue_delayed_work(ipoib_workqueue, 407 queue_delayed_work(ipoib_workqueue,
403 &priv->mcast_task, 0); 408 &priv->mcast_task, 0);
404 mutex_unlock(&mcast_mutex); 409 mutex_unlock(&mcast_mutex);
405 complete(&mcast->done); 410 return 0;
406 return;
407 }
408
409 if (status == -EINTR) {
410 complete(&mcast->done);
411 return;
412 } 411 }
413 412
414 if (status && mcast->logcount++ < 20) { 413 if (mcast->logcount++ < 20) {
415 if (status == -ETIMEDOUT || status == -EINTR) { 414 if (status == -ETIMEDOUT) {
416 ipoib_dbg_mcast(priv, "multicast join failed for " IPOIB_GID_FMT 415 ipoib_dbg_mcast(priv, "multicast join failed for " IPOIB_GID_FMT
417 ", status %d\n", 416 ", status %d\n",
418 IPOIB_GID_ARG(mcast->mcmember.mgid), 417 IPOIB_GID_ARG(mcast->mcmember.mgid),
@@ -429,24 +428,18 @@ static void ipoib_mcast_join_complete(int status,
429 if (mcast->backoff > IPOIB_MAX_BACKOFF_SECONDS) 428 if (mcast->backoff > IPOIB_MAX_BACKOFF_SECONDS)
430 mcast->backoff = IPOIB_MAX_BACKOFF_SECONDS; 429 mcast->backoff = IPOIB_MAX_BACKOFF_SECONDS;
431 430
432 mutex_lock(&mcast_mutex); 431 /* Clear the busy flag so we try again */
432 status = test_and_clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags);
433 433
434 mutex_lock(&mcast_mutex);
434 spin_lock_irq(&priv->lock); 435 spin_lock_irq(&priv->lock);
435 mcast->query = NULL; 436 if (test_bit(IPOIB_MCAST_RUN, &priv->flags))
436 437 queue_delayed_work(ipoib_workqueue, &priv->mcast_task,
437 if (test_bit(IPOIB_MCAST_RUN, &priv->flags)) { 438 mcast->backoff * HZ);
438 if (status == -ETIMEDOUT)
439 queue_delayed_work(ipoib_workqueue, &priv->mcast_task,
440 0);
441 else
442 queue_delayed_work(ipoib_workqueue, &priv->mcast_task,
443 mcast->backoff * HZ);
444 } else
445 complete(&mcast->done);
446 spin_unlock_irq(&priv->lock); 439 spin_unlock_irq(&priv->lock);
447 mutex_unlock(&mcast_mutex); 440 mutex_unlock(&mcast_mutex);
448 441
449 return; 442 return status;
450} 443}
451 444
452static void ipoib_mcast_join(struct net_device *dev, struct ipoib_mcast *mcast, 445static void ipoib_mcast_join(struct net_device *dev, struct ipoib_mcast *mcast,
@@ -495,15 +488,14 @@ static void ipoib_mcast_join(struct net_device *dev, struct ipoib_mcast *mcast,
495 rec.hop_limit = priv->broadcast->mcmember.hop_limit; 488 rec.hop_limit = priv->broadcast->mcmember.hop_limit;
496 } 489 }
497 490
498 init_completion(&mcast->done); 491 set_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags);
499 492 mcast->mc = ib_sa_join_multicast(&ipoib_sa_client, priv->ca, priv->port,
500 ret = ib_sa_mcmember_rec_set(&ipoib_sa_client, priv->ca, priv->port, 493 &rec, comp_mask, GFP_KERNEL,
501 &rec, comp_mask, mcast->backoff * 1000, 494 ipoib_mcast_join_complete, mcast);
502 GFP_ATOMIC, ipoib_mcast_join_complete, 495 if (IS_ERR(mcast->mc)) {
503 mcast, &mcast->query); 496 clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags);
504 497 ret = PTR_ERR(mcast->mc);
505 if (ret < 0) { 498 ipoib_warn(priv, "ib_sa_join_multicast failed, status %d\n", ret);
506 ipoib_warn(priv, "ib_sa_mcmember_rec_set failed, status %d\n", ret);
507 499
508 mcast->backoff *= 2; 500 mcast->backoff *= 2;
509 if (mcast->backoff > IPOIB_MAX_BACKOFF_SECONDS) 501 if (mcast->backoff > IPOIB_MAX_BACKOFF_SECONDS)
@@ -515,8 +507,7 @@ static void ipoib_mcast_join(struct net_device *dev, struct ipoib_mcast *mcast,
515 &priv->mcast_task, 507 &priv->mcast_task,
516 mcast->backoff * HZ); 508 mcast->backoff * HZ);
517 mutex_unlock(&mcast_mutex); 509 mutex_unlock(&mcast_mutex);
518 } else 510 }
519 mcast->query_id = ret;
520} 511}
521 512
522void ipoib_mcast_join_task(struct work_struct *work) 513void ipoib_mcast_join_task(struct work_struct *work)
@@ -541,7 +532,7 @@ void ipoib_mcast_join_task(struct work_struct *work)
541 priv->local_rate = attr.active_speed * 532 priv->local_rate = attr.active_speed *
542 ib_width_enum_to_int(attr.active_width); 533 ib_width_enum_to_int(attr.active_width);
543 } else 534 } else
544 ipoib_warn(priv, "ib_query_port failed\n"); 535 ipoib_warn(priv, "ib_query_port failed\n");
545 } 536 }
546 537
547 if (!priv->broadcast) { 538 if (!priv->broadcast) {
@@ -568,7 +559,8 @@ void ipoib_mcast_join_task(struct work_struct *work)
568 } 559 }
569 560
570 if (!test_bit(IPOIB_MCAST_FLAG_ATTACHED, &priv->broadcast->flags)) { 561 if (!test_bit(IPOIB_MCAST_FLAG_ATTACHED, &priv->broadcast->flags)) {
571 ipoib_mcast_join(dev, priv->broadcast, 0); 562 if (!test_bit(IPOIB_MCAST_FLAG_BUSY, &priv->broadcast->flags))
563 ipoib_mcast_join(dev, priv->broadcast, 0);
572 return; 564 return;
573 } 565 }
574 566
@@ -625,26 +617,9 @@ int ipoib_mcast_start_thread(struct net_device *dev)
625 return 0; 617 return 0;
626} 618}
627 619
628static void wait_for_mcast_join(struct ipoib_dev_priv *priv,
629 struct ipoib_mcast *mcast)
630{
631 spin_lock_irq(&priv->lock);
632 if (mcast && mcast->query) {
633 ib_sa_cancel_query(mcast->query_id, mcast->query);
634 mcast->query = NULL;
635 spin_unlock_irq(&priv->lock);
636 ipoib_dbg_mcast(priv, "waiting for MGID " IPOIB_GID_FMT "\n",
637 IPOIB_GID_ARG(mcast->mcmember.mgid));
638 wait_for_completion(&mcast->done);
639 }
640 else
641 spin_unlock_irq(&priv->lock);
642}
643
644int ipoib_mcast_stop_thread(struct net_device *dev, int flush) 620int ipoib_mcast_stop_thread(struct net_device *dev, int flush)
645{ 621{
646 struct ipoib_dev_priv *priv = netdev_priv(dev); 622 struct ipoib_dev_priv *priv = netdev_priv(dev);
647 struct ipoib_mcast *mcast;
648 623
649 ipoib_dbg_mcast(priv, "stopping multicast thread\n"); 624 ipoib_dbg_mcast(priv, "stopping multicast thread\n");
650 625
@@ -660,52 +635,27 @@ int ipoib_mcast_stop_thread(struct net_device *dev, int flush)
660 if (flush) 635 if (flush)
661 flush_workqueue(ipoib_workqueue); 636 flush_workqueue(ipoib_workqueue);
662 637
663 wait_for_mcast_join(priv, priv->broadcast);
664
665 list_for_each_entry(mcast, &priv->multicast_list, list)
666 wait_for_mcast_join(priv, mcast);
667
668 return 0; 638 return 0;
669} 639}
670 640
671static int ipoib_mcast_leave(struct net_device *dev, struct ipoib_mcast *mcast) 641static int ipoib_mcast_leave(struct net_device *dev, struct ipoib_mcast *mcast)
672{ 642{
673 struct ipoib_dev_priv *priv = netdev_priv(dev); 643 struct ipoib_dev_priv *priv = netdev_priv(dev);
674 struct ib_sa_mcmember_rec rec = {
675 .join_state = 1
676 };
677 int ret = 0; 644 int ret = 0;
678 645
679 if (!test_and_clear_bit(IPOIB_MCAST_FLAG_ATTACHED, &mcast->flags)) 646 if (test_and_clear_bit(IPOIB_MCAST_FLAG_ATTACHED, &mcast->flags)) {
680 return 0; 647 ipoib_dbg_mcast(priv, "leaving MGID " IPOIB_GID_FMT "\n",
681 648 IPOIB_GID_ARG(mcast->mcmember.mgid));
682 ipoib_dbg_mcast(priv, "leaving MGID " IPOIB_GID_FMT "\n",
683 IPOIB_GID_ARG(mcast->mcmember.mgid));
684
685 rec.mgid = mcast->mcmember.mgid;
686 rec.port_gid = priv->local_gid;
687 rec.pkey = cpu_to_be16(priv->pkey);
688 649
689 /* Remove ourselves from the multicast group */ 650 /* Remove ourselves from the multicast group */
690 ret = ipoib_mcast_detach(dev, be16_to_cpu(mcast->mcmember.mlid), 651 ret = ipoib_mcast_detach(dev, be16_to_cpu(mcast->mcmember.mlid),
691 &mcast->mcmember.mgid); 652 &mcast->mcmember.mgid);
692 if (ret) 653 if (ret)
693 ipoib_warn(priv, "ipoib_mcast_detach failed (result = %d)\n", ret); 654 ipoib_warn(priv, "ipoib_mcast_detach failed (result = %d)\n", ret);
655 }
694 656
695 /* 657 if (test_and_clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags))
696 * Just make one shot at leaving and don't wait for a reply; 658 ib_sa_free_multicast(mcast->mc);
697 * if we fail, too bad.
698 */
699 ret = ib_sa_mcmember_rec_delete(&ipoib_sa_client, priv->ca, priv->port, &rec,
700 IB_SA_MCMEMBER_REC_MGID |
701 IB_SA_MCMEMBER_REC_PORT_GID |
702 IB_SA_MCMEMBER_REC_PKEY |
703 IB_SA_MCMEMBER_REC_JOIN_STATE,
704 0, GFP_ATOMIC, NULL,
705 mcast, &mcast->query);
706 if (ret < 0)
707 ipoib_warn(priv, "ib_sa_mcmember_rec_delete failed "
708 "for leave (result = %d)\n", ret);
709 659
710 return 0; 660 return 0;
711} 661}
@@ -758,7 +708,7 @@ void ipoib_mcast_send(struct net_device *dev, void *mgid, struct sk_buff *skb)
758 dev_kfree_skb_any(skb); 708 dev_kfree_skb_any(skb);
759 } 709 }
760 710
761 if (mcast->query) 711 if (test_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags))
762 ipoib_dbg_mcast(priv, "no address vector, " 712 ipoib_dbg_mcast(priv, "no address vector, "
763 "but multicast join already started\n"); 713 "but multicast join already started\n");
764 else if (test_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags)) 714 else if (test_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags))
@@ -916,7 +866,6 @@ void ipoib_mcast_restart_task(struct work_struct *work)
916 866
917 /* We have to cancel outside of the spinlock */ 867 /* We have to cancel outside of the spinlock */
918 list_for_each_entry_safe(mcast, tmcast, &remove_list, list) { 868 list_for_each_entry_safe(mcast, tmcast, &remove_list, list) {
919 wait_for_mcast_join(priv, mcast);
920 ipoib_mcast_leave(mcast->dev, mcast); 869 ipoib_mcast_leave(mcast->dev, mcast);
921 ipoib_mcast_free(mcast); 870 ipoib_mcast_free(mcast);
922 } 871 }
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index bedae4ad3f74..80b199fa0aa9 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -107,4 +107,19 @@ config MSI_LAPTOP
107 107
108 If you have an MSI S270 laptop, say Y or M here. 108 If you have an MSI S270 laptop, say Y or M here.
109 109
110config SONY_LAPTOP
111 tristate "Sony Laptop Extras"
112 depends on X86 && ACPI
113 select BACKLIGHT_CLASS_DEVICE
114 ---help---
115 This mini-driver drives the SNC device present in the ACPI BIOS of
116 the Sony Vaio laptops.
117
118 It gives access to some extra laptop functionalities. In its current
119 form, this driver let the user set or query the screen brightness
120 through the backlight subsystem and remove/apply power to some
121 devices.
122
123 Read <file:Documentation/sony-laptop.txt> for more information.
124
110endmenu 125endmenu
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 35da53c409c0..7793ccd79049 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -11,3 +11,4 @@ obj-$(CONFIG_LKDTM) += lkdtm.o
11obj-$(CONFIG_TIFM_CORE) += tifm_core.o 11obj-$(CONFIG_TIFM_CORE) += tifm_core.o
12obj-$(CONFIG_TIFM_7XX1) += tifm_7xx1.o 12obj-$(CONFIG_TIFM_7XX1) += tifm_7xx1.o
13obj-$(CONFIG_SGI_IOC4) += ioc4.o 13obj-$(CONFIG_SGI_IOC4) += ioc4.o
14obj-$(CONFIG_SONY_LAPTOP) += sony-laptop.o
diff --git a/drivers/misc/asus-laptop.c b/drivers/misc/asus-laptop.c
index 861c39935f99..e4e2b707a353 100644
--- a/drivers/misc/asus-laptop.c
+++ b/drivers/misc/asus-laptop.c
@@ -1088,11 +1088,6 @@ static int __init asus_laptop_init(void)
1088 if (acpi_disabled) 1088 if (acpi_disabled)
1089 return -ENODEV; 1089 return -ENODEV;
1090 1090
1091 if (!acpi_specific_hotkey_enabled) {
1092 printk(ASUS_ERR "Using generic hotkey driver\n");
1093 return -ENODEV;
1094 }
1095
1096 result = acpi_bus_register_driver(&asus_hotk_driver); 1091 result = acpi_bus_register_driver(&asus_hotk_driver);
1097 if (result < 0) 1092 if (result < 0)
1098 return result; 1093 return result;
diff --git a/drivers/misc/sony-laptop.c b/drivers/misc/sony-laptop.c
new file mode 100644
index 000000000000..cabbed0015e4
--- /dev/null
+++ b/drivers/misc/sony-laptop.c
@@ -0,0 +1,562 @@
1/*
2 * ACPI Sony Notebook Control Driver (SNC)
3 *
4 * Copyright (C) 2004-2005 Stelian Pop <stelian@popies.net>
5 * Copyright (C) 2007 Mattia Dongili <malattia@linux.it>
6 *
7 * Parts of this driver inspired from asus_acpi.c and ibm_acpi.c
8 * which are copyrighted by their respective authors.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 */
25
26#include <linux/kernel.h>
27#include <linux/module.h>
28#include <linux/moduleparam.h>
29#include <linux/init.h>
30#include <linux/types.h>
31#include <linux/backlight.h>
32#include <linux/platform_device.h>
33#include <linux/err.h>
34#include <acpi/acpi_drivers.h>
35#include <acpi/acpi_bus.h>
36#include <asm/uaccess.h>
37
38#define ACPI_SNC_CLASS "sony"
39#define ACPI_SNC_HID "SNY5001"
40#define ACPI_SNC_DRIVER_NAME "ACPI Sony Notebook Control Driver v0.4"
41
42/* the device uses 1-based values, while the backlight subsystem uses
43 0-based values */
44#define SONY_MAX_BRIGHTNESS 8
45
46#define LOG_PFX KERN_WARNING "sony-laptop: "
47
48MODULE_AUTHOR("Stelian Pop, Mattia Dongili");
49MODULE_DESCRIPTION(ACPI_SNC_DRIVER_NAME);
50MODULE_LICENSE("GPL");
51
52static int debug;
53module_param(debug, int, 0);
54MODULE_PARM_DESC(debug, "set this to 1 (and RTFM) if you want to help "
55 "the development of this driver");
56
57static ssize_t sony_acpi_show(struct device *, struct device_attribute *,
58 char *);
59static ssize_t sony_acpi_store(struct device *, struct device_attribute *,
60 const char *, size_t);
61static int boolean_validate(const int, const int);
62static int brightness_default_validate(const int, const int);
63
64#define SNC_VALIDATE_IN 0
65#define SNC_VALIDATE_OUT 1
66
67struct sony_acpi_value {
68 char *name; /* name of the entry */
69 char **acpiget; /* names of the ACPI get function */
70 char **acpiset; /* names of the ACPI set function */
71 int (*validate)(const int, const int); /* input/output validation */
72 int value; /* current setting */
73 int valid; /* Has ever been set */
74 int debug; /* active only in debug mode ? */
75 struct device_attribute devattr; /* sysfs atribute */
76};
77
78#define HANDLE_NAMES(_name, _values...) \
79 static char *snc_##_name[] = { _values, NULL }
80
81#define SONY_ACPI_VALUE(_name, _getters, _setters, _validate, _debug) \
82 { \
83 .name = __stringify(_name), \
84 .acpiget = _getters, \
85 .acpiset = _setters, \
86 .validate = _validate, \
87 .debug = _debug, \
88 .devattr = __ATTR(_name, 0, sony_acpi_show, sony_acpi_store), \
89 }
90
91#define SONY_ACPI_VALUE_NULL { .name = NULL }
92
93HANDLE_NAMES(fnkey_get, "GHKE");
94
95HANDLE_NAMES(brightness_def_get, "GPBR");
96HANDLE_NAMES(brightness_def_set, "SPBR");
97
98HANDLE_NAMES(cdpower_get, "GCDP");
99HANDLE_NAMES(cdpower_set, "SCDP", "CDPW");
100
101HANDLE_NAMES(audiopower_get, "GAZP");
102HANDLE_NAMES(audiopower_set, "AZPW");
103
104HANDLE_NAMES(lanpower_get, "GLNP");
105HANDLE_NAMES(lanpower_set, "LNPW");
106
107HANDLE_NAMES(PID_get, "GPID");
108
109HANDLE_NAMES(CTR_get, "GCTR");
110HANDLE_NAMES(CTR_set, "SCTR");
111
112HANDLE_NAMES(PCR_get, "GPCR");
113HANDLE_NAMES(PCR_set, "SPCR");
114
115HANDLE_NAMES(CMI_get, "GCMI");
116HANDLE_NAMES(CMI_set, "SCMI");
117
118static struct sony_acpi_value sony_acpi_values[] = {
119 SONY_ACPI_VALUE(brightness_default, snc_brightness_def_get,
120 snc_brightness_def_set, brightness_default_validate, 0),
121 SONY_ACPI_VALUE(fnkey, snc_fnkey_get, NULL, NULL, 0),
122 SONY_ACPI_VALUE(cdpower, snc_cdpower_get, snc_cdpower_set, boolean_validate, 0),
123 SONY_ACPI_VALUE(audiopower, snc_audiopower_get, snc_audiopower_set,
124 boolean_validate, 0),
125 SONY_ACPI_VALUE(lanpower, snc_lanpower_get, snc_lanpower_set,
126 boolean_validate, 1),
127 /* unknown methods */
128 SONY_ACPI_VALUE(PID, snc_PID_get, NULL, NULL, 1),
129 SONY_ACPI_VALUE(CTR, snc_CTR_get, snc_CTR_set, NULL, 1),
130 SONY_ACPI_VALUE(PCR, snc_PCR_get, snc_PCR_set, NULL, 1),
131 SONY_ACPI_VALUE(CMI, snc_CMI_get, snc_CMI_set, NULL, 1),
132 SONY_ACPI_VALUE_NULL
133};
134
135static acpi_handle sony_acpi_handle;
136static struct acpi_device *sony_acpi_acpi_device = NULL;
137
138/*
139 * acpi_evaluate_object wrappers
140 */
141static int acpi_callgetfunc(acpi_handle handle, char *name, int *result)
142{
143 struct acpi_buffer output;
144 union acpi_object out_obj;
145 acpi_status status;
146
147 output.length = sizeof(out_obj);
148 output.pointer = &out_obj;
149
150 status = acpi_evaluate_object(handle, name, NULL, &output);
151 if ((status == AE_OK) && (out_obj.type == ACPI_TYPE_INTEGER)) {
152 *result = out_obj.integer.value;
153 return 0;
154 }
155
156 printk(LOG_PFX "acpi_callreadfunc failed\n");
157
158 return -1;
159}
160
161static int acpi_callsetfunc(acpi_handle handle, char *name, int value,
162 int *result)
163{
164 struct acpi_object_list params;
165 union acpi_object in_obj;
166 struct acpi_buffer output;
167 union acpi_object out_obj;
168 acpi_status status;
169
170 params.count = 1;
171 params.pointer = &in_obj;
172 in_obj.type = ACPI_TYPE_INTEGER;
173 in_obj.integer.value = value;
174
175 output.length = sizeof(out_obj);
176 output.pointer = &out_obj;
177
178 status = acpi_evaluate_object(handle, name, &params, &output);
179 if (status == AE_OK) {
180 if (result != NULL) {
181 if (out_obj.type != ACPI_TYPE_INTEGER) {
182 printk(LOG_PFX "acpi_evaluate_object bad "
183 "return type\n");
184 return -1;
185 }
186 *result = out_obj.integer.value;
187 }
188 return 0;
189 }
190
191 printk(LOG_PFX "acpi_evaluate_object failed\n");
192
193 return -1;
194}
195
196/*
197 * sony_acpi_values input/output validate functions
198 */
199
200/* brightness_default_validate:
201 *
202 * manipulate input output values to keep consistency with the
203 * backlight framework for which brightness values are 0-based.
204 */
205static int brightness_default_validate(const int direction, const int value)
206{
207 switch (direction) {
208 case SNC_VALIDATE_OUT:
209 return value - 1;
210 case SNC_VALIDATE_IN:
211 if (value >= 0 && value < SONY_MAX_BRIGHTNESS)
212 return value + 1;
213 }
214 return -EINVAL;
215}
216
217/* boolean_validate:
218 *
219 * on input validate boolean values 0/1, on output just pass the
220 * received value.
221 */
222static int boolean_validate(const int direction, const int value)
223{
224 if (direction == SNC_VALIDATE_IN) {
225 if (value != 0 && value != 1)
226 return -EINVAL;
227 }
228 return value;
229}
230
231/*
232 * Sysfs show/store common to all sony_acpi_values
233 */
234static ssize_t sony_acpi_show(struct device *dev, struct device_attribute *attr,
235 char *buffer)
236{
237 int value;
238 struct sony_acpi_value *item =
239 container_of(attr, struct sony_acpi_value, devattr);
240
241 if (!*item->acpiget)
242 return -EIO;
243
244 if (acpi_callgetfunc(sony_acpi_handle, *item->acpiget, &value) < 0)
245 return -EIO;
246
247 if (item->validate)
248 value = item->validate(SNC_VALIDATE_OUT, value);
249
250 return snprintf(buffer, PAGE_SIZE, "%d\n", value);
251}
252
253static ssize_t sony_acpi_store(struct device *dev,
254 struct device_attribute *attr,
255 const char *buffer, size_t count)
256{
257 int value;
258 struct sony_acpi_value *item =
259 container_of(attr, struct sony_acpi_value, devattr);
260
261 if (!item->acpiset)
262 return -EIO;
263
264 if (count > 31)
265 return -EINVAL;
266
267 value = simple_strtoul(buffer, NULL, 10);
268
269 if (item->validate)
270 value = item->validate(SNC_VALIDATE_IN, value);
271
272 if (value < 0)
273 return value;
274
275 if (acpi_callsetfunc(sony_acpi_handle, *item->acpiset, value, NULL) < 0)
276 return -EIO;
277 item->value = value;
278 item->valid = 1;
279 return count;
280}
281
282/*
283 * Platform device
284 */
285static struct platform_driver sncpf_driver = {
286 .driver = {
287 .name = "sony-laptop",
288 .owner = THIS_MODULE,
289 }
290};
291static struct platform_device *sncpf_device;
292
293static int sony_snc_pf_add(void)
294{
295 acpi_handle handle;
296 struct sony_acpi_value *item;
297 int ret = 0;
298
299 ret = platform_driver_register(&sncpf_driver);
300 if (ret)
301 goto out;
302
303 sncpf_device = platform_device_alloc("sony-laptop", -1);
304 if (!sncpf_device) {
305 ret = -ENOMEM;
306 goto out_platform_registered;
307 }
308
309 ret = platform_device_add(sncpf_device);
310 if (ret)
311 goto out_platform_alloced;
312
313 for (item = sony_acpi_values; item->name; ++item) {
314
315 if (!debug && item->debug)
316 continue;
317
318 /* find the available acpiget as described in the DSDT */
319 for (; item->acpiget && *item->acpiget; ++item->acpiget) {
320 if (ACPI_SUCCESS(acpi_get_handle(sony_acpi_handle,
321 *item->acpiget,
322 &handle))) {
323 if (debug)
324 printk(LOG_PFX "Found %s getter: %s\n",
325 item->name, *item->acpiget);
326 item->devattr.attr.mode |= S_IRUGO;
327 break;
328 }
329 }
330
331 /* find the available acpiset as described in the DSDT */
332 for (; item->acpiset && *item->acpiset; ++item->acpiset) {
333 if (ACPI_SUCCESS(acpi_get_handle(sony_acpi_handle,
334 *item->acpiset,
335 &handle))) {
336 if (debug)
337 printk(LOG_PFX "Found %s setter: %s\n",
338 item->name, *item->acpiset);
339 item->devattr.attr.mode |= S_IWUSR;
340 break;
341 }
342 }
343
344 if (item->devattr.attr.mode != 0) {
345 ret =
346 device_create_file(&sncpf_device->dev,
347 &item->devattr);
348 if (ret)
349 goto out_sysfs;
350 }
351 }
352
353 return 0;
354
355 out_sysfs:
356 for (item = sony_acpi_values; item->name; ++item) {
357 device_remove_file(&sncpf_device->dev, &item->devattr);
358 }
359 platform_device_del(sncpf_device);
360 out_platform_alloced:
361 platform_device_put(sncpf_device);
362 out_platform_registered:
363 platform_driver_unregister(&sncpf_driver);
364 out:
365 return ret;
366}
367
368static void sony_snc_pf_remove(void)
369{
370 struct sony_acpi_value *item;
371
372 for (item = sony_acpi_values; item->name; ++item) {
373 device_remove_file(&sncpf_device->dev, &item->devattr);
374 }
375
376 platform_device_del(sncpf_device);
377 platform_device_put(sncpf_device);
378 platform_driver_unregister(&sncpf_driver);
379}
380
381/*
382 * Backlight device
383 */
384static int sony_backlight_update_status(struct backlight_device *bd)
385{
386 return acpi_callsetfunc(sony_acpi_handle, "SBRT",
387 bd->props->brightness + 1, NULL);
388}
389
390static int sony_backlight_get_brightness(struct backlight_device *bd)
391{
392 int value;
393
394 if (acpi_callgetfunc(sony_acpi_handle, "GBRT", &value))
395 return 0;
396 /* brightness levels are 1-based, while backlight ones are 0-based */
397 return value - 1;
398}
399
400static struct backlight_device *sony_backlight_device;
401static struct backlight_properties sony_backlight_properties = {
402 .owner = THIS_MODULE,
403 .update_status = sony_backlight_update_status,
404 .get_brightness = sony_backlight_get_brightness,
405 .max_brightness = SONY_MAX_BRIGHTNESS - 1,
406};
407
408/*
409 * ACPI callbacks
410 */
411static void sony_acpi_notify(acpi_handle handle, u32 event, void *data)
412{
413 if (debug)
414 printk(LOG_PFX "sony_acpi_notify, event: %d\n", event);
415 acpi_bus_generate_event(sony_acpi_acpi_device, 1, event);
416}
417
418static acpi_status sony_walk_callback(acpi_handle handle, u32 level,
419 void *context, void **return_value)
420{
421 struct acpi_namespace_node *node;
422 union acpi_operand_object *operand;
423
424 node = (struct acpi_namespace_node *)handle;
425 operand = (union acpi_operand_object *)node->object;
426
427 printk(LOG_PFX "method: name: %4.4s, args %X\n", node->name.ascii,
428 (u32) operand->method.param_count);
429
430 return AE_OK;
431}
432
433/*
434 * ACPI device
435 */
436static int sony_acpi_resume(struct acpi_device *device)
437{
438 struct sony_acpi_value *item;
439
440 for (item = sony_acpi_values; item->name; item++) {
441 int ret;
442
443 if (!item->valid)
444 continue;
445 ret = acpi_callsetfunc(sony_acpi_handle, *item->acpiset,
446 item->value, NULL);
447 if (ret < 0) {
448 printk("%s: %d\n", __FUNCTION__, ret);
449 break;
450 }
451 }
452 return 0;
453}
454
455static int sony_acpi_add(struct acpi_device *device)
456{
457 acpi_status status;
458 int result;
459 acpi_handle handle;
460
461 sony_acpi_acpi_device = device;
462
463 sony_acpi_handle = device->handle;
464
465 if (debug) {
466 status = acpi_walk_namespace(ACPI_TYPE_METHOD, sony_acpi_handle,
467 1, sony_walk_callback, NULL, NULL);
468 if (ACPI_FAILURE(status)) {
469 printk(LOG_PFX "unable to walk acpi resources\n");
470 result = -ENODEV;
471 goto outwalk;
472 }
473 }
474
475 status = acpi_install_notify_handler(sony_acpi_handle,
476 ACPI_DEVICE_NOTIFY,
477 sony_acpi_notify, NULL);
478 if (ACPI_FAILURE(status)) {
479 printk(LOG_PFX "unable to install notify handler\n");
480 result = -ENODEV;
481 goto outwalk;
482 }
483
484 if (ACPI_SUCCESS(acpi_get_handle(sony_acpi_handle, "GBRT", &handle))) {
485 sony_backlight_device = backlight_device_register("sony", NULL,
486 NULL,
487 &sony_backlight_properties);
488
489 if (IS_ERR(sony_backlight_device)) {
490 printk(LOG_PFX "unable to register backlight device\n");
491 sony_backlight_device = NULL;
492 } else
493 sony_backlight_properties.brightness =
494 sony_backlight_get_brightness
495 (sony_backlight_device);
496 }
497
498 if (sony_snc_pf_add())
499 goto outbacklight;
500
501 printk(KERN_INFO ACPI_SNC_DRIVER_NAME " successfully installed\n");
502
503 return 0;
504
505 outbacklight:
506 if (sony_backlight_device)
507 backlight_device_unregister(sony_backlight_device);
508
509 status = acpi_remove_notify_handler(sony_acpi_handle,
510 ACPI_DEVICE_NOTIFY,
511 sony_acpi_notify);
512 if (ACPI_FAILURE(status))
513 printk(LOG_PFX "unable to remove notify handler\n");
514 outwalk:
515 return result;
516}
517
518static int sony_acpi_remove(struct acpi_device *device, int type)
519{
520 acpi_status status;
521
522 if (sony_backlight_device)
523 backlight_device_unregister(sony_backlight_device);
524
525 sony_acpi_acpi_device = NULL;
526
527 status = acpi_remove_notify_handler(sony_acpi_handle,
528 ACPI_DEVICE_NOTIFY,
529 sony_acpi_notify);
530 if (ACPI_FAILURE(status))
531 printk(LOG_PFX "unable to remove notify handler\n");
532
533 sony_snc_pf_remove();
534
535 printk(KERN_INFO ACPI_SNC_DRIVER_NAME " successfully removed\n");
536
537 return 0;
538}
539
540static struct acpi_driver sony_acpi_driver = {
541 .name = ACPI_SNC_DRIVER_NAME,
542 .class = ACPI_SNC_CLASS,
543 .ids = ACPI_SNC_HID,
544 .ops = {
545 .add = sony_acpi_add,
546 .remove = sony_acpi_remove,
547 .resume = sony_acpi_resume,
548 },
549};
550
551static int __init sony_acpi_init(void)
552{
553 return acpi_bus_register_driver(&sony_acpi_driver);
554}
555
556static void __exit sony_acpi_exit(void)
557{
558 acpi_bus_unregister_driver(&sony_acpi_driver);
559}
560
561module_init(sony_acpi_init);
562module_exit(sony_acpi_exit);
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 4438ae1ede4f..a3c1755b2f28 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -415,6 +415,7 @@ static struct kobj_type pci_driver_kobj_type = {
415 * __pci_register_driver - register a new pci driver 415 * __pci_register_driver - register a new pci driver
416 * @drv: the driver structure to register 416 * @drv: the driver structure to register
417 * @owner: owner module of drv 417 * @owner: owner module of drv
418 * @mod_name: module name string
418 * 419 *
419 * Adds the driver structure to the list of registered drivers. 420 * Adds the driver structure to the list of registered drivers.
420 * Returns a negative value on error, otherwise 0. 421 * Returns a negative value on error, otherwise 0.
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 7a94076752d0..cd913a2a416f 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -143,6 +143,14 @@ static ssize_t is_enabled_show(struct device *dev,
143 return sprintf (buf, "%u\n", atomic_read(&pdev->enable_cnt)); 143 return sprintf (buf, "%u\n", atomic_read(&pdev->enable_cnt));
144} 144}
145 145
146#ifdef CONFIG_NUMA
147static ssize_t
148numa_node_show(struct device *dev, struct device_attribute *attr, char *buf)
149{
150 return sprintf (buf, "%d\n", dev->numa_node);
151}
152#endif
153
146static ssize_t 154static ssize_t
147msi_bus_show(struct device *dev, struct device_attribute *attr, char *buf) 155msi_bus_show(struct device *dev, struct device_attribute *attr, char *buf)
148{ 156{
@@ -194,6 +202,9 @@ struct device_attribute pci_dev_attrs[] = {
194 __ATTR_RO(irq), 202 __ATTR_RO(irq),
195 __ATTR_RO(local_cpus), 203 __ATTR_RO(local_cpus),
196 __ATTR_RO(modalias), 204 __ATTR_RO(modalias),
205#ifdef CONFIG_NUMA
206 __ATTR_RO(numa_node),
207#endif
197 __ATTR(enable, 0600, is_enabled_show, is_enabled_store), 208 __ATTR(enable, 0600, is_enabled_show, is_enabled_store),
198 __ATTR(broken_parity_status,(S_IRUGO|S_IWUSR), 209 __ATTR(broken_parity_status,(S_IRUGO|S_IWUSR),
199 broken_parity_status_show,broken_parity_status_store), 210 broken_parity_status_show,broken_parity_status_store),
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 8b44cff2c176..1e74e1ee8bd8 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -21,6 +21,12 @@
21 21
22unsigned int pci_pm_d3_delay = 10; 22unsigned int pci_pm_d3_delay = 10;
23 23
24#define DEFAULT_CARDBUS_IO_SIZE (256)
25#define DEFAULT_CARDBUS_MEM_SIZE (64*1024*1024)
26/* pci=cbmemsize=nnM,cbiosize=nn can override this */
27unsigned long pci_cardbus_io_size = DEFAULT_CARDBUS_IO_SIZE;
28unsigned long pci_cardbus_mem_size = DEFAULT_CARDBUS_MEM_SIZE;
29
24/** 30/**
25 * pci_bus_max_busnr - returns maximum PCI bus number of given bus' children 31 * pci_bus_max_busnr - returns maximum PCI bus number of given bus' children
26 * @bus: pointer to PCI bus structure to search 32 * @bus: pointer to PCI bus structure to search
@@ -1300,7 +1306,7 @@ pci_set_consistent_dma_mask(struct pci_dev *dev, u64 mask)
1300 1306
1301/** 1307/**
1302 * pci_select_bars - Make BAR mask from the type of resource 1308 * pci_select_bars - Make BAR mask from the type of resource
1303 * @pdev: the PCI device for which BAR mask is made 1309 * @dev: the PCI device for which BAR mask is made
1304 * @flags: resource type mask to be selected 1310 * @flags: resource type mask to be selected
1305 * 1311 *
1306 * This helper routine makes bar mask from the type of resource. 1312 * This helper routine makes bar mask from the type of resource.
@@ -1333,6 +1339,10 @@ static int __devinit pci_setup(char *str)
1333 if (*str && (str = pcibios_setup(str)) && *str) { 1339 if (*str && (str = pcibios_setup(str)) && *str) {
1334 if (!strcmp(str, "nomsi")) { 1340 if (!strcmp(str, "nomsi")) {
1335 pci_no_msi(); 1341 pci_no_msi();
1342 } else if (!strncmp(str, "cbiosize=", 9)) {
1343 pci_cardbus_io_size = memparse(str + 9, &str);
1344 } else if (!strncmp(str, "cbmemsize=", 10)) {
1345 pci_cardbus_mem_size = memparse(str + 10, &str);
1336 } else { 1346 } else {
1337 printk(KERN_ERR "PCI: Unknown option `%s'\n", 1347 printk(KERN_ERR "PCI: Unknown option `%s'\n",
1338 str); 1348 str);
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 89f3036f0de8..3554f3948814 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -36,13 +36,6 @@
36 36
37#define ROUND_UP(x, a) (((x) + (a) - 1) & ~((a) - 1)) 37#define ROUND_UP(x, a) (((x) + (a) - 1) & ~((a) - 1))
38 38
39/*
40 * FIXME: IO should be max 256 bytes. However, since we may
41 * have a P2P bridge below a cardbus bridge, we need 4K.
42 */
43#define CARDBUS_IO_SIZE (256)
44#define CARDBUS_MEM_SIZE (64*1024*1024)
45
46static void __devinit 39static void __devinit
47pbus_assign_resources_sorted(struct pci_bus *bus) 40pbus_assign_resources_sorted(struct pci_bus *bus)
48{ 41{
@@ -415,12 +408,12 @@ pci_bus_size_cardbus(struct pci_bus *bus)
415 * Reserve some resources for CardBus. We reserve 408 * Reserve some resources for CardBus. We reserve
416 * a fixed amount of bus space for CardBus bridges. 409 * a fixed amount of bus space for CardBus bridges.
417 */ 410 */
418 b_res[0].start = CARDBUS_IO_SIZE; 411 b_res[0].start = pci_cardbus_io_size;
419 b_res[0].end = b_res[0].start + CARDBUS_IO_SIZE - 1; 412 b_res[0].end = b_res[0].start + pci_cardbus_io_size - 1;
420 b_res[0].flags |= IORESOURCE_IO; 413 b_res[0].flags |= IORESOURCE_IO;
421 414
422 b_res[1].start = CARDBUS_IO_SIZE; 415 b_res[1].start = pci_cardbus_io_size;
423 b_res[1].end = b_res[1].start + CARDBUS_IO_SIZE - 1; 416 b_res[1].end = b_res[1].start + pci_cardbus_io_size - 1;
424 b_res[1].flags |= IORESOURCE_IO; 417 b_res[1].flags |= IORESOURCE_IO;
425 418
426 /* 419 /*
@@ -440,16 +433,16 @@ pci_bus_size_cardbus(struct pci_bus *bus)
440 * twice the size. 433 * twice the size.
441 */ 434 */
442 if (ctrl & PCI_CB_BRIDGE_CTL_PREFETCH_MEM0) { 435 if (ctrl & PCI_CB_BRIDGE_CTL_PREFETCH_MEM0) {
443 b_res[2].start = CARDBUS_MEM_SIZE; 436 b_res[2].start = pci_cardbus_mem_size;
444 b_res[2].end = b_res[2].start + CARDBUS_MEM_SIZE - 1; 437 b_res[2].end = b_res[2].start + pci_cardbus_mem_size - 1;
445 b_res[2].flags |= IORESOURCE_MEM | IORESOURCE_PREFETCH; 438 b_res[2].flags |= IORESOURCE_MEM | IORESOURCE_PREFETCH;
446 439
447 b_res[3].start = CARDBUS_MEM_SIZE; 440 b_res[3].start = pci_cardbus_mem_size;
448 b_res[3].end = b_res[3].start + CARDBUS_MEM_SIZE - 1; 441 b_res[3].end = b_res[3].start + pci_cardbus_mem_size - 1;
449 b_res[3].flags |= IORESOURCE_MEM; 442 b_res[3].flags |= IORESOURCE_MEM;
450 } else { 443 } else {
451 b_res[3].start = CARDBUS_MEM_SIZE * 2; 444 b_res[3].start = pci_cardbus_mem_size * 2;
452 b_res[3].end = b_res[3].start + CARDBUS_MEM_SIZE * 2 - 1; 445 b_res[3].end = b_res[3].start + pci_cardbus_mem_size * 2 - 1;
453 b_res[3].flags |= IORESOURCE_MEM; 446 b_res[3].flags |= IORESOURCE_MEM;
454 } 447 }
455} 448}
diff --git a/drivers/pci/setup-irq.c b/drivers/pci/setup-irq.c
index a251289c9958..568f1877315c 100644
--- a/drivers/pci/setup-irq.c
+++ b/drivers/pci/setup-irq.c
@@ -24,7 +24,7 @@ pdev_fixup_irq(struct pci_dev *dev,
24 int (*map_irq)(struct pci_dev *, u8, u8)) 24 int (*map_irq)(struct pci_dev *, u8, u8))
25{ 25{
26 u8 pin, slot; 26 u8 pin, slot;
27 int irq; 27 int irq = 0;
28 28
29 /* If this device is not on the primary bus, we need to figure out 29 /* If this device is not on the primary bus, we need to figure out
30 which interrupt pin it will come in on. We know which slot it 30 which interrupt pin it will come in on. We know which slot it
@@ -33,16 +33,18 @@ pdev_fixup_irq(struct pci_dev *dev,
33 apply the swizzle function. */ 33 apply the swizzle function. */
34 34
35 pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin); 35 pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
36 /* Cope with 0 and illegal. */ 36 /* Cope with illegal. */
37 if (pin == 0 || pin > 4) 37 if (pin > 4)
38 pin = 1; 38 pin = 1;
39 39
40 /* Follow the chain of bridges, swizzling as we go. */ 40 if (pin != 0) {
41 slot = (*swizzle)(dev, &pin); 41 /* Follow the chain of bridges, swizzling as we go. */
42 slot = (*swizzle)(dev, &pin);
42 43
43 irq = (*map_irq)(dev, slot, pin); 44 irq = (*map_irq)(dev, slot, pin);
44 if (irq == -1) 45 if (irq == -1)
45 irq = 0; 46 irq = 0;
47 }
46 dev->irq = irq; 48 dev->irq = irq;
47 49
48 pr_debug("PCI: fixup irq: (%s) got %d\n", 50 pr_debug("PCI: fixup irq: (%s) got %d\n",
diff --git a/drivers/pcmcia/at91_cf.c b/drivers/pcmcia/at91_cf.c
index b31862837534..99baabc23599 100644
--- a/drivers/pcmcia/at91_cf.c
+++ b/drivers/pcmcia/at91_cf.c
@@ -277,7 +277,7 @@ static int __init at91_cf_probe(struct platform_device *pdev)
277 board->det_pin, board->irq_pin); 277 board->det_pin, board->irq_pin);
278 278
279 cf->socket.owner = THIS_MODULE; 279 cf->socket.owner = THIS_MODULE;
280 cf->socket.dev.dev = &pdev->dev; 280 cf->socket.dev.parent = &pdev->dev;
281 cf->socket.ops = &at91_cf_ops; 281 cf->socket.ops = &at91_cf_ops;
282 cf->socket.resource_ops = &pccard_static_ops; 282 cf->socket.resource_ops = &pccard_static_ops;
283 cf->socket.features = SS_CAP_PCCARD | SS_CAP_STATIC_MAP 283 cf->socket.features = SS_CAP_PCCARD | SS_CAP_STATIC_MAP
diff --git a/drivers/pcmcia/soc_common.c b/drivers/pcmcia/soc_common.c
index d2a3bea55de2..aa7779d89752 100644
--- a/drivers/pcmcia/soc_common.c
+++ b/drivers/pcmcia/soc_common.c
@@ -478,7 +478,7 @@ dump_bits(char **p, const char *prefix, unsigned int val, struct bittbl *bits, i
478 * 478 *
479 * Returns: the number of characters added to the buffer 479 * Returns: the number of characters added to the buffer
480 */ 480 */
481static ssize_t show_status(struct device *dev, char *buf) 481static ssize_t show_status(struct device *dev, struct device_attribute *attr, char *buf)
482{ 482{
483 struct soc_pcmcia_socket *skt = 483 struct soc_pcmcia_socket *skt =
484 container_of(dev, struct soc_pcmcia_socket, socket.dev); 484 container_of(dev, struct soc_pcmcia_socket, socket.dev);
@@ -501,7 +501,7 @@ static ssize_t show_status(struct device *dev, char *buf)
501 501
502 return p-buf; 502 return p-buf;
503} 503}
504static CLASS_DEVICE_ATTR(status, S_IRUGO, show_status, NULL); 504static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
505 505
506 506
507static struct pccard_operations soc_common_pcmcia_operations = { 507static struct pccard_operations soc_common_pcmcia_operations = {
@@ -660,7 +660,7 @@ int soc_common_drv_pcmcia_probe(struct device *dev, struct pcmcia_low_level *ops
660 660
661 skt->socket.ops = &soc_common_pcmcia_operations; 661 skt->socket.ops = &soc_common_pcmcia_operations;
662 skt->socket.owner = ops->owner; 662 skt->socket.owner = ops->owner;
663 skt->socket.dev.dev = dev; 663 skt->socket.dev.parent = dev;
664 664
665 init_timer(&skt->poll_timer); 665 init_timer(&skt->poll_timer);
666 skt->poll_timer.function = soc_common_pcmcia_poll_event; 666 skt->poll_timer.function = soc_common_pcmcia_poll_event;
@@ -747,7 +747,7 @@ int soc_common_drv_pcmcia_probe(struct device *dev, struct pcmcia_low_level *ops
747 747
748 add_timer(&skt->poll_timer); 748 add_timer(&skt->poll_timer);
749 749
750 device_create_file(&skt->socket.dev, &device_attr_status); 750 device_create_file(&skt->socket.dev, &dev_attr_status);
751 } 751 }
752 752
753 dev_set_drvdata(dev, sinfo); 753 dev_set_drvdata(dev, sinfo);
diff --git a/drivers/pnp/pnpacpi/Kconfig b/drivers/pnp/pnpacpi/Kconfig
index ad27e5e0101f..b04767ce273e 100644
--- a/drivers/pnp/pnpacpi/Kconfig
+++ b/drivers/pnp/pnpacpi/Kconfig
@@ -2,17 +2,5 @@
2# Plug and Play ACPI configuration 2# Plug and Play ACPI configuration
3# 3#
4config PNPACPI 4config PNPACPI
5 bool "Plug and Play ACPI support" 5 bool
6 depends on PNP && ACPI 6 default (PNP && ACPI)
7 default y
8 ---help---
9 Linux uses the PNPACPI to autodetect built-in
10 mainboard resources (e.g. parallel port resources).
11
12 Some features (e.g. real hotplug) are not currently
13 implemented.
14
15 If you would like the kernel to detect and allocate resources to
16 your mainboard devices (on some systems they are disabled by the
17 BIOS) say Y here. Also the PNPACPI can help prevent resource
18 conflicts between mainboard devices and other bus devices.
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 3f048bd6326d..5a8f55fea5ff 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1269,9 +1269,18 @@ repeat:
1269 1269
1270 /* Some devices return the total number of sectors, not the 1270 /* Some devices return the total number of sectors, not the
1271 * highest sector number. Make the necessary adjustment. */ 1271 * highest sector number. Make the necessary adjustment. */
1272 if (sdp->fix_capacity) 1272 if (sdp->fix_capacity) {
1273 --sdkp->capacity; 1273 --sdkp->capacity;
1274 1274
1275 /* Some devices have version which report the correct sizes
1276 * and others which do not. We guess size according to a heuristic
1277 * and err on the side of lowering the capacity. */
1278 } else {
1279 if (sdp->guess_capacity)
1280 if (sdkp->capacity & 0x01) /* odd sizes are odd */
1281 --sdkp->capacity;
1282 }
1283
1275got_data: 1284got_data:
1276 if (sector_size == 0) { 1285 if (sector_size == 0) {
1277 sector_size = 512; 1286 sector_size = 512;
diff --git a/drivers/serial/serial_cs.c b/drivers/serial/serial_cs.c
index c2f1012449da..6b76babc7fbf 100644
--- a/drivers/serial/serial_cs.c
+++ b/drivers/serial/serial_cs.c
@@ -248,6 +248,10 @@ static const struct serial_quirk quirks[] = {
248 .multi = 2, 248 .multi = 2,
249 }, { 249 }, {
250 .manfid = MANFID_QUATECH, 250 .manfid = MANFID_QUATECH,
251 .prodid = PRODID_QUATECH_DUAL_RS232_G,
252 .multi = 2,
253 }, {
254 .manfid = MANFID_QUATECH,
251 .prodid = PRODID_QUATECH_QUAD_RS232, 255 .prodid = PRODID_QUATECH_QUAD_RS232,
252 .multi = 4, 256 .multi = 4,
253 }, { 257 }, {
@@ -891,6 +895,7 @@ static struct pcmcia_device_id serial_ids[] = {
891 PCMCIA_DEVICE_PROD_ID12("OEM ", "C288MX ", 0xb572d360, 0xd2385b7a), 895 PCMCIA_DEVICE_PROD_ID12("OEM ", "C288MX ", 0xb572d360, 0xd2385b7a),
892 PCMCIA_DEVICE_PROD_ID12("PCMCIA ", "C336MX ", 0x99bcafe9, 0xaa25bcab), 896 PCMCIA_DEVICE_PROD_ID12("PCMCIA ", "C336MX ", 0x99bcafe9, 0xaa25bcab),
893 PCMCIA_DEVICE_PROD_ID12("Quatech Inc", "PCMCIA Dual RS-232 Serial Port Card", 0xc4420b35, 0x92abc92f), 897 PCMCIA_DEVICE_PROD_ID12("Quatech Inc", "PCMCIA Dual RS-232 Serial Port Card", 0xc4420b35, 0x92abc92f),
898 PCMCIA_DEVICE_PROD_ID12("Quatech Inc", "Dual RS-232 Serial Port PC Card", 0xc4420b35, 0x031a380d),
894 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "PCMCIA", "EN2218-LAN/MODEM", 0x281f1c5d, 0x570f348e, "PCMLM28.cis"), 899 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "PCMCIA", "EN2218-LAN/MODEM", 0x281f1c5d, 0x570f348e, "PCMLM28.cis"),
895 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "PCMCIA", "UE2218-LAN/MODEM", 0x281f1c5d, 0x6fdcacee, "PCMLM28.cis"), 900 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "PCMCIA", "UE2218-LAN/MODEM", 0x281f1c5d, 0x6fdcacee, "PCMLM28.cis"),
896 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "Psion Dacom", "Gold Card V34 Ethernet", 0xf5f025c2, 0x338e8155, "PCMLM28.cis"), 901 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "Psion Dacom", "Gold Card V34 Ethernet", 0xf5f025c2, 0x338e8155, "PCMLM28.cis"),
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index 825bf884537a..8b7ff467d262 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -51,6 +51,7 @@ obj-$(CONFIG_USB_SERIAL) += serial/
51obj-$(CONFIG_USB_ADUTUX) += misc/ 51obj-$(CONFIG_USB_ADUTUX) += misc/
52obj-$(CONFIG_USB_APPLEDISPLAY) += misc/ 52obj-$(CONFIG_USB_APPLEDISPLAY) += misc/
53obj-$(CONFIG_USB_AUERSWALD) += misc/ 53obj-$(CONFIG_USB_AUERSWALD) += misc/
54obj-$(CONFIG_USB_BERRY_CHARGE) += misc/
54obj-$(CONFIG_USB_CYPRESS_CY7C63)+= misc/ 55obj-$(CONFIG_USB_CYPRESS_CY7C63)+= misc/
55obj-$(CONFIG_USB_CYTHERM) += misc/ 56obj-$(CONFIG_USB_CYTHERM) += misc/
56obj-$(CONFIG_USB_EMI26) += misc/ 57obj-$(CONFIG_USB_EMI26) += misc/
diff --git a/drivers/usb/atm/ueagle-atm.c b/drivers/usb/atm/ueagle-atm.c
index dae4ef1e8fe5..4973e147bc79 100644
--- a/drivers/usb/atm/ueagle-atm.c
+++ b/drivers/usb/atm/ueagle-atm.c
@@ -61,6 +61,7 @@
61#include <linux/usb.h> 61#include <linux/usb.h>
62#include <linux/firmware.h> 62#include <linux/firmware.h>
63#include <linux/ctype.h> 63#include <linux/ctype.h>
64#include <linux/sched.h>
64#include <linux/kthread.h> 65#include <linux/kthread.h>
65#include <linux/version.h> 66#include <linux/version.h>
66#include <linux/mutex.h> 67#include <linux/mutex.h>
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 98199628e394..d38a25f36ea5 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -326,10 +326,16 @@ static void acm_rx_tasklet(unsigned long _acm)
326 struct tty_struct *tty = acm->tty; 326 struct tty_struct *tty = acm->tty;
327 struct acm_ru *rcv; 327 struct acm_ru *rcv;
328 unsigned long flags; 328 unsigned long flags;
329 int i = 0; 329 unsigned char throttled;
330 dbg("Entering acm_rx_tasklet"); 330 dbg("Entering acm_rx_tasklet");
331 331
332 if (!ACM_READY(acm) || acm->throttle) 332 if (!ACM_READY(acm))
333 return;
334
335 spin_lock(&acm->throttle_lock);
336 throttled = acm->throttle;
337 spin_unlock(&acm->throttle_lock);
338 if (throttled)
333 return; 339 return;
334 340
335next_buffer: 341next_buffer:
@@ -346,22 +352,20 @@ next_buffer:
346 dbg("acm_rx_tasklet: procesing buf 0x%p, size = %d", buf, buf->size); 352 dbg("acm_rx_tasklet: procesing buf 0x%p, size = %d", buf, buf->size);
347 353
348 tty_buffer_request_room(tty, buf->size); 354 tty_buffer_request_room(tty, buf->size);
349 if (!acm->throttle) 355 spin_lock(&acm->throttle_lock);
356 throttled = acm->throttle;
357 spin_unlock(&acm->throttle_lock);
358 if (!throttled)
350 tty_insert_flip_string(tty, buf->base, buf->size); 359 tty_insert_flip_string(tty, buf->base, buf->size);
351 tty_flip_buffer_push(tty); 360 tty_flip_buffer_push(tty);
352 361
353 spin_lock(&acm->throttle_lock); 362 if (throttled) {
354 if (acm->throttle) { 363 dbg("Throttling noticed");
355 dbg("Throtteling noticed");
356 memmove(buf->base, buf->base + i, buf->size - i);
357 buf->size -= i;
358 spin_unlock(&acm->throttle_lock);
359 spin_lock_irqsave(&acm->read_lock, flags); 364 spin_lock_irqsave(&acm->read_lock, flags);
360 list_add(&buf->list, &acm->filled_read_bufs); 365 list_add(&buf->list, &acm->filled_read_bufs);
361 spin_unlock_irqrestore(&acm->read_lock, flags); 366 spin_unlock_irqrestore(&acm->read_lock, flags);
362 return; 367 return;
363 } 368 }
364 spin_unlock(&acm->throttle_lock);
365 369
366 spin_lock_irqsave(&acm->read_lock, flags); 370 spin_lock_irqsave(&acm->read_lock, flags);
367 list_add(&buf->list, &acm->spare_read_bufs); 371 list_add(&buf->list, &acm->spare_read_bufs);
@@ -467,7 +471,8 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
467 goto bail_out; 471 goto bail_out;
468 } 472 }
469 473
470 if (0 > acm_set_control(acm, acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS)) 474 if (0 > acm_set_control(acm, acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS) &&
475 (acm->ctrl_caps & USB_CDC_CAP_LINE))
471 goto full_bailout; 476 goto full_bailout;
472 477
473 INIT_LIST_HEAD(&acm->spare_read_urbs); 478 INIT_LIST_HEAD(&acm->spare_read_urbs);
@@ -480,6 +485,8 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
480 list_add(&(acm->rb[i].list), &acm->spare_read_bufs); 485 list_add(&(acm->rb[i].list), &acm->spare_read_bufs);
481 } 486 }
482 487
488 acm->throttle = 0;
489
483 tasklet_schedule(&acm->urb_task); 490 tasklet_schedule(&acm->urb_task);
484 491
485done: 492done:
@@ -1092,6 +1099,10 @@ static struct usb_device_id acm_ids[] = {
1092 { USB_DEVICE(0x0ace, 0x1611), /* ZyDAS 56K USB MODEM - new version */ 1099 { USB_DEVICE(0x0ace, 0x1611), /* ZyDAS 56K USB MODEM - new version */
1093 .driver_info = SINGLE_RX_URB, /* firmware bug */ 1100 .driver_info = SINGLE_RX_URB, /* firmware bug */
1094 }, 1101 },
1102 { USB_DEVICE(0x22b8, 0x7000), /* Motorola Q Phone */
1103 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
1104 },
1105
1095 /* control interfaces with various AT-command sets */ 1106 /* control interfaces with various AT-command sets */
1096 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, 1107 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
1097 USB_CDC_ACM_PROTO_AT_V25TER) }, 1108 USB_CDC_ACM_PROTO_AT_V25TER) },
diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
index a47c30b2d764..aefc7987120d 100644
--- a/drivers/usb/core/devices.c
+++ b/drivers/usb/core/devices.c
@@ -604,10 +604,6 @@ static unsigned int usb_device_poll(struct file *file, struct poll_table_struct
604 lock_kernel(); 604 lock_kernel();
605 if (!st) { 605 if (!st) {
606 st = kmalloc(sizeof(struct usb_device_status), GFP_KERNEL); 606 st = kmalloc(sizeof(struct usb_device_status), GFP_KERNEL);
607 if (!st) {
608 unlock_kernel();
609 return POLLIN;
610 }
611 607
612 /* we may have dropped BKL - need to check for having lost the race */ 608 /* we may have dropped BKL - need to check for having lost the race */
613 if (file->private_data) { 609 if (file->private_data) {
@@ -615,6 +611,11 @@ static unsigned int usb_device_poll(struct file *file, struct poll_table_struct
615 st = file->private_data; 611 st = file->private_data;
616 goto lost_race; 612 goto lost_race;
617 } 613 }
614 /* we haven't lost - check for allocation failure now */
615 if (!st) {
616 unlock_kernel();
617 return POLLIN;
618 }
618 619
619 /* 620 /*
620 * need to prevent the module from being unloaded, since 621 * need to prevent the module from being unloaded, since
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 2087766f9e88..274f14f1633e 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -857,11 +857,11 @@ static int proc_setintf(struct dev_state *ps, void __user *arg)
857 857
858static int proc_setconfig(struct dev_state *ps, void __user *arg) 858static int proc_setconfig(struct dev_state *ps, void __user *arg)
859{ 859{
860 unsigned int u; 860 int u;
861 int status = 0; 861 int status = 0;
862 struct usb_host_config *actconfig; 862 struct usb_host_config *actconfig;
863 863
864 if (get_user(u, (unsigned int __user *)arg)) 864 if (get_user(u, (int __user *)arg))
865 return -EFAULT; 865 return -EFAULT;
866 866
867 actconfig = ps->dev->actconfig; 867 actconfig = ps->dev->actconfig;
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index 600d1bc8272a..2aded261f42c 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -743,6 +743,7 @@ EXPORT_SYMBOL_GPL(usb_deregister_device_driver);
743 * usb_register_driver - register a USB interface driver 743 * usb_register_driver - register a USB interface driver
744 * @new_driver: USB operations for the interface driver 744 * @new_driver: USB operations for the interface driver
745 * @owner: module owner of this driver. 745 * @owner: module owner of this driver.
746 * @mod_name: module name string
746 * 747 *
747 * Registers a USB interface driver with the USB core. The list of 748 * Registers a USB interface driver with the USB core. The list of
748 * unattached interfaces will be rescanned whenever a new driver is 749 * unattached interfaces will be rescanned whenever a new driver is
diff --git a/drivers/usb/core/endpoint.c b/drivers/usb/core/endpoint.c
index 5e628ae3aec7..e0ec7045e865 100644
--- a/drivers/usb/core/endpoint.c
+++ b/drivers/usb/core/endpoint.c
@@ -229,7 +229,7 @@ static int init_endpoint_class(void)
229 kref_init(&ep_class->kref); 229 kref_init(&ep_class->kref);
230 ep_class->class = class_create(THIS_MODULE, "usb_endpoint"); 230 ep_class->class = class_create(THIS_MODULE, "usb_endpoint");
231 if (IS_ERR(ep_class->class)) { 231 if (IS_ERR(ep_class->class)) {
232 result = IS_ERR(ep_class->class); 232 result = PTR_ERR(ep_class->class);
233 goto class_create_error; 233 goto class_create_error;
234 } 234 }
235 235
diff --git a/drivers/usb/core/generic.c b/drivers/usb/core/generic.c
index b531a4fd30c2..9bbcb20e2d94 100644
--- a/drivers/usb/core/generic.c
+++ b/drivers/usb/core/generic.c
@@ -184,7 +184,7 @@ static void generic_disconnect(struct usb_device *udev)
184 /* if this is only an unbind, not a physical disconnect, then 184 /* if this is only an unbind, not a physical disconnect, then
185 * unconfigure the device */ 185 * unconfigure the device */
186 if (udev->actconfig) 186 if (udev->actconfig)
187 usb_set_configuration(udev, 0); 187 usb_set_configuration(udev, -1);
188 188
189 usb_remove_sysfs_dev_files(udev); 189 usb_remove_sysfs_dev_files(udev);
190} 190}
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 590ec82d0515..50c0db15304a 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -44,6 +44,7 @@ struct usb_hub {
44 struct usb_hub_status hub; 44 struct usb_hub_status hub;
45 struct usb_port_status port; 45 struct usb_port_status port;
46 } *status; /* buffer for status reports */ 46 } *status; /* buffer for status reports */
47 struct mutex status_mutex; /* for the status buffer */
47 48
48 int error; /* last reported error */ 49 int error; /* last reported error */
49 int nerrors; /* track consecutive errors */ 50 int nerrors; /* track consecutive errors */
@@ -535,6 +536,7 @@ static int hub_hub_status(struct usb_hub *hub,
535{ 536{
536 int ret; 537 int ret;
537 538
539 mutex_lock(&hub->status_mutex);
538 ret = get_hub_status(hub->hdev, &hub->status->hub); 540 ret = get_hub_status(hub->hdev, &hub->status->hub);
539 if (ret < 0) 541 if (ret < 0)
540 dev_err (hub->intfdev, 542 dev_err (hub->intfdev,
@@ -544,6 +546,7 @@ static int hub_hub_status(struct usb_hub *hub,
544 *change = le16_to_cpu(hub->status->hub.wHubChange); 546 *change = le16_to_cpu(hub->status->hub.wHubChange);
545 ret = 0; 547 ret = 0;
546 } 548 }
549 mutex_unlock(&hub->status_mutex);
547 return ret; 550 return ret;
548} 551}
549 552
@@ -617,6 +620,7 @@ static int hub_configure(struct usb_hub *hub,
617 ret = -ENOMEM; 620 ret = -ENOMEM;
618 goto fail; 621 goto fail;
619 } 622 }
623 mutex_init(&hub->status_mutex);
620 624
621 hub->descriptor = kmalloc(sizeof(*hub->descriptor), GFP_KERNEL); 625 hub->descriptor = kmalloc(sizeof(*hub->descriptor), GFP_KERNEL);
622 if (!hub->descriptor) { 626 if (!hub->descriptor) {
@@ -1396,6 +1400,7 @@ static int hub_port_status(struct usb_hub *hub, int port1,
1396{ 1400{
1397 int ret; 1401 int ret;
1398 1402
1403 mutex_lock(&hub->status_mutex);
1399 ret = get_port_status(hub->hdev, port1, &hub->status->port); 1404 ret = get_port_status(hub->hdev, port1, &hub->status->port);
1400 if (ret < 4) { 1405 if (ret < 4) {
1401 dev_err (hub->intfdev, 1406 dev_err (hub->intfdev,
@@ -1407,6 +1412,7 @@ static int hub_port_status(struct usb_hub *hub, int port1,
1407 *change = le16_to_cpu(hub->status->port.wPortChange); 1412 *change = le16_to_cpu(hub->status->port.wPortChange);
1408 ret = 0; 1413 ret = 0;
1409 } 1414 }
1415 mutex_unlock(&hub->status_mutex);
1410 return ret; 1416 return ret;
1411} 1417}
1412 1418
@@ -1904,6 +1910,7 @@ static int hub_suspend(struct usb_interface *intf, pm_message_t msg)
1904 struct usb_hub *hub = usb_get_intfdata (intf); 1910 struct usb_hub *hub = usb_get_intfdata (intf);
1905 struct usb_device *hdev = hub->hdev; 1911 struct usb_device *hdev = hub->hdev;
1906 unsigned port1; 1912 unsigned port1;
1913 int status = 0;
1907 1914
1908 /* fail if children aren't already suspended */ 1915 /* fail if children aren't already suspended */
1909 for (port1 = 1; port1 <= hdev->maxchild; port1++) { 1916 for (port1 = 1; port1 <= hdev->maxchild; port1++) {
@@ -1927,24 +1934,18 @@ static int hub_suspend(struct usb_interface *intf, pm_message_t msg)
1927 1934
1928 dev_dbg(&intf->dev, "%s\n", __FUNCTION__); 1935 dev_dbg(&intf->dev, "%s\n", __FUNCTION__);
1929 1936
1937 /* stop khubd and related activity */
1938 hub_quiesce(hub);
1939
1930 /* "global suspend" of the downstream HC-to-USB interface */ 1940 /* "global suspend" of the downstream HC-to-USB interface */
1931 if (!hdev->parent) { 1941 if (!hdev->parent) {
1932 struct usb_bus *bus = hdev->bus; 1942 status = hcd_bus_suspend(hdev->bus);
1933 if (bus) { 1943 if (status != 0) {
1934 int status = hcd_bus_suspend (bus); 1944 dev_dbg(&hdev->dev, "'global' suspend %d\n", status);
1935 1945 hub_activate(hub);
1936 if (status != 0) { 1946 }
1937 dev_dbg(&hdev->dev, "'global' suspend %d\n",
1938 status);
1939 return status;
1940 }
1941 } else
1942 return -EOPNOTSUPP;
1943 } 1947 }
1944 1948 return status;
1945 /* stop khubd and related activity */
1946 hub_quiesce(hub);
1947 return 0;
1948} 1949}
1949 1950
1950static int hub_resume(struct usb_interface *intf) 1951static int hub_resume(struct usb_interface *intf)
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index 8aca3574c2b5..74edaea5665d 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -1316,6 +1316,14 @@ static void release_interface(struct device *dev)
1316 * use this kind of configurability; many devices only have one 1316 * use this kind of configurability; many devices only have one
1317 * configuration. 1317 * configuration.
1318 * 1318 *
1319 * @configuration is the value of the configuration to be installed.
1320 * According to the USB spec (e.g. section 9.1.1.5), configuration values
1321 * must be non-zero; a value of zero indicates that the device in
1322 * unconfigured. However some devices erroneously use 0 as one of their
1323 * configuration values. To help manage such devices, this routine will
1324 * accept @configuration = -1 as indicating the device should be put in
1325 * an unconfigured state.
1326 *
1319 * USB device configurations may affect Linux interoperability, 1327 * USB device configurations may affect Linux interoperability,
1320 * power consumption and the functionality available. For example, 1328 * power consumption and the functionality available. For example,
1321 * the default configuration is limited to using 100mA of bus power, 1329 * the default configuration is limited to using 100mA of bus power,
@@ -1347,10 +1355,15 @@ int usb_set_configuration(struct usb_device *dev, int configuration)
1347 struct usb_interface **new_interfaces = NULL; 1355 struct usb_interface **new_interfaces = NULL;
1348 int n, nintf; 1356 int n, nintf;
1349 1357
1350 for (i = 0; i < dev->descriptor.bNumConfigurations; i++) { 1358 if (configuration == -1)
1351 if (dev->config[i].desc.bConfigurationValue == configuration) { 1359 configuration = 0;
1352 cp = &dev->config[i]; 1360 else {
1353 break; 1361 for (i = 0; i < dev->descriptor.bNumConfigurations; i++) {
1362 if (dev->config[i].desc.bConfigurationValue ==
1363 configuration) {
1364 cp = &dev->config[i];
1365 break;
1366 }
1354 } 1367 }
1355 } 1368 }
1356 if ((!cp && configuration != 0)) 1369 if ((!cp && configuration != 0))
@@ -1359,6 +1372,7 @@ int usb_set_configuration(struct usb_device *dev, int configuration)
1359 /* The USB spec says configuration 0 means unconfigured. 1372 /* The USB spec says configuration 0 means unconfigured.
1360 * But if a device includes a configuration numbered 0, 1373 * But if a device includes a configuration numbered 0,
1361 * we will accept it as a correctly configured state. 1374 * we will accept it as a correctly configured state.
1375 * Use -1 if you really want to unconfigure the device.
1362 */ 1376 */
1363 if (cp && configuration == 0) 1377 if (cp && configuration == 0)
1364 dev_warn(&dev->dev, "config 0 descriptor??\n"); 1378 dev_warn(&dev->dev, "config 0 descriptor??\n");
diff --git a/drivers/usb/core/otg_whitelist.h b/drivers/usb/core/otg_whitelist.h
index 627a5a2fc9cf..7f31a495a25d 100644
--- a/drivers/usb/core/otg_whitelist.h
+++ b/drivers/usb/core/otg_whitelist.h
@@ -31,7 +31,7 @@ static struct usb_device_id whitelist_table [] = {
31{ USB_DEVICE_INFO(7, 1, 3) }, 31{ USB_DEVICE_INFO(7, 1, 3) },
32#endif 32#endif
33 33
34#ifdef CONFIG_USB_CDCETHER 34#ifdef CONFIG_USB_NET_CDCETHER
35/* Linux-USB CDC Ethernet gadget */ 35/* Linux-USB CDC Ethernet gadget */
36{ USB_DEVICE(0x0525, 0xa4a1), }, 36{ USB_DEVICE(0x0525, 0xa4a1), },
37/* Linux-USB CDC Ethernet + RNDIS gadget */ 37/* Linux-USB CDC Ethernet + RNDIS gadget */
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index 4eaa0ee8e72f..0edfbafd702c 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -63,7 +63,7 @@ set_bConfigurationValue(struct device *dev, struct device_attribute *attr,
63 struct usb_device *udev = to_usb_device(dev); 63 struct usb_device *udev = to_usb_device(dev);
64 int config, value; 64 int config, value;
65 65
66 if (sscanf(buf, "%u", &config) != 1 || config > 255) 66 if (sscanf(buf, "%d", &config) != 1 || config < -1 || config > 255)
67 return -EINVAL; 67 return -EINVAL;
68 usb_lock_device(udev); 68 usb_lock_device(udev);
69 value = usb_set_configuration(udev, config); 69 value = usb_set_configuration(udev, config);
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index 36b36e0175fc..82369c4729b5 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -784,7 +784,7 @@ static int at91_ep_set_halt(struct usb_ep *_ep, int value)
784 return status; 784 return status;
785} 785}
786 786
787static struct usb_ep_ops at91_ep_ops = { 787static const struct usb_ep_ops at91_ep_ops = {
788 .enable = at91_ep_enable, 788 .enable = at91_ep_enable,
789 .disable = at91_ep_disable, 789 .disable = at91_ep_disable,
790 .alloc_request = at91_ep_alloc_request, 790 .alloc_request = at91_ep_alloc_request,
@@ -1651,7 +1651,7 @@ static void at91udc_shutdown(struct platform_device *dev)
1651 pullup(platform_get_drvdata(dev), 0); 1651 pullup(platform_get_drvdata(dev), 0);
1652} 1652}
1653 1653
1654static int __devinit at91udc_probe(struct platform_device *pdev) 1654static int __init at91udc_probe(struct platform_device *pdev)
1655{ 1655{
1656 struct device *dev = &pdev->dev; 1656 struct device *dev = &pdev->dev;
1657 struct at91_udc *udc; 1657 struct at91_udc *udc;
@@ -1762,7 +1762,7 @@ fail0:
1762 return retval; 1762 return retval;
1763} 1763}
1764 1764
1765static int __devexit at91udc_remove(struct platform_device *pdev) 1765static int __exit at91udc_remove(struct platform_device *pdev)
1766{ 1766{
1767 struct at91_udc *udc = platform_get_drvdata(pdev); 1767 struct at91_udc *udc = platform_get_drvdata(pdev);
1768 struct resource *res; 1768 struct resource *res;
@@ -1836,8 +1836,7 @@ static int at91udc_resume(struct platform_device *pdev)
1836#endif 1836#endif
1837 1837
1838static struct platform_driver at91_udc = { 1838static struct platform_driver at91_udc = {
1839 .probe = at91udc_probe, 1839 .remove = __exit_p(at91udc_remove),
1840 .remove = __devexit_p(at91udc_remove),
1841 .shutdown = at91udc_shutdown, 1840 .shutdown = at91udc_shutdown,
1842 .suspend = at91udc_suspend, 1841 .suspend = at91udc_suspend,
1843 .resume = at91udc_resume, 1842 .resume = at91udc_resume,
@@ -1847,13 +1846,13 @@ static struct platform_driver at91_udc = {
1847 }, 1846 },
1848}; 1847};
1849 1848
1850static int __devinit udc_init_module(void) 1849static int __init udc_init_module(void)
1851{ 1850{
1852 return platform_driver_register(&at91_udc); 1851 return platform_driver_probe(&at91_udc, at91udc_probe);
1853} 1852}
1854module_init(udc_init_module); 1853module_init(udc_init_module);
1855 1854
1856static void __devexit udc_exit_module(void) 1855static void __exit udc_exit_module(void)
1857{ 1856{
1858 platform_driver_unregister(&at91_udc); 1857 platform_driver_unregister(&at91_udc);
1859} 1858}
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index e6c19aa4bef3..e552668d36b3 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -1699,6 +1699,7 @@ static int gs_setup_class(struct usb_gadget *gadget,
1699 memcpy(&port->port_line_coding, req->buf, ret); 1699 memcpy(&port->port_line_coding, req->buf, ret);
1700 spin_unlock(&port->port_lock); 1700 spin_unlock(&port->port_lock);
1701 } 1701 }
1702 ret = 0;
1702 break; 1703 break;
1703 1704
1704 case USB_CDC_REQ_GET_LINE_CODING: 1705 case USB_CDC_REQ_GET_LINE_CODING:
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 185721dba42b..a74056488234 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -42,6 +42,9 @@
42#include <asm/irq.h> 42#include <asm/irq.h>
43#include <asm/system.h> 43#include <asm/system.h>
44#include <asm/unaligned.h> 44#include <asm/unaligned.h>
45#ifdef CONFIG_PPC_PS3
46#include <asm/firmware.h>
47#endif
45 48
46 49
47/*-------------------------------------------------------------------------*/ 50/*-------------------------------------------------------------------------*/
@@ -299,6 +302,19 @@ static void ehci_watchdog (unsigned long param)
299 spin_unlock_irqrestore (&ehci->lock, flags); 302 spin_unlock_irqrestore (&ehci->lock, flags);
300} 303}
301 304
305/* On some systems, leaving remote wakeup enabled prevents system shutdown.
306 * The firmware seems to think that powering off is a wakeup event!
307 * This routine turns off remote wakeup and everything else, on all ports.
308 */
309static void ehci_turn_off_all_ports(struct ehci_hcd *ehci)
310{
311 int port = HCS_N_PORTS(ehci->hcs_params);
312
313 while (port--)
314 ehci_writel(ehci, PORT_RWC_BITS,
315 &ehci->regs->port_status[port]);
316}
317
302/* ehci_shutdown kick in for silicon on any bus (not just pci, etc). 318/* ehci_shutdown kick in for silicon on any bus (not just pci, etc).
303 * This forcibly disables dma and IRQs, helping kexec and other cases 319 * This forcibly disables dma and IRQs, helping kexec and other cases
304 * where the next system software may expect clean state. 320 * where the next system software may expect clean state.
@@ -310,9 +326,13 @@ ehci_shutdown (struct usb_hcd *hcd)
310 326
311 ehci = hcd_to_ehci (hcd); 327 ehci = hcd_to_ehci (hcd);
312 (void) ehci_halt (ehci); 328 (void) ehci_halt (ehci);
329 ehci_turn_off_all_ports(ehci);
313 330
314 /* make BIOS/etc use companion controller during reboot */ 331 /* make BIOS/etc use companion controller during reboot */
315 ehci_writel(ehci, 0, &ehci->regs->configured_flag); 332 ehci_writel(ehci, 0, &ehci->regs->configured_flag);
333
334 /* unblock posted writes */
335 ehci_readl(ehci, &ehci->regs->configured_flag);
316} 336}
317 337
318static void ehci_port_power (struct ehci_hcd *ehci, int is_on) 338static void ehci_port_power (struct ehci_hcd *ehci, int is_on)
@@ -951,15 +971,18 @@ static int __init ehci_hcd_init(void)
951#endif 971#endif
952 972
953#ifdef PS3_SYSTEM_BUS_DRIVER 973#ifdef PS3_SYSTEM_BUS_DRIVER
954 retval = ps3_system_bus_driver_register(&PS3_SYSTEM_BUS_DRIVER); 974 if (firmware_has_feature(FW_FEATURE_PS3_LV1)) {
955 if (retval < 0) { 975 retval = ps3_system_bus_driver_register(
976 &PS3_SYSTEM_BUS_DRIVER);
977 if (retval < 0) {
956#ifdef PLATFORM_DRIVER 978#ifdef PLATFORM_DRIVER
957 platform_driver_unregister(&PLATFORM_DRIVER); 979 platform_driver_unregister(&PLATFORM_DRIVER);
958#endif 980#endif
959#ifdef PCI_DRIVER 981#ifdef PCI_DRIVER
960 pci_unregister_driver(&PCI_DRIVER); 982 pci_unregister_driver(&PCI_DRIVER);
961#endif 983#endif
962 return retval; 984 return retval;
985 }
963 } 986 }
964#endif 987#endif
965 988
@@ -976,7 +999,8 @@ static void __exit ehci_hcd_cleanup(void)
976 pci_unregister_driver(&PCI_DRIVER); 999 pci_unregister_driver(&PCI_DRIVER);
977#endif 1000#endif
978#ifdef PS3_SYSTEM_BUS_DRIVER 1001#ifdef PS3_SYSTEM_BUS_DRIVER
979 ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); 1002 if (firmware_has_feature(FW_FEATURE_PS3_LV1))
1003 ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
980#endif 1004#endif
981} 1005}
982module_exit(ehci_hcd_cleanup); 1006module_exit(ehci_hcd_cleanup);
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index 0d83c6df1a3b..9af529d22b3e 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -36,6 +36,8 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
36 int port; 36 int port;
37 int mask; 37 int mask;
38 38
39 ehci_dbg(ehci, "suspend root hub\n");
40
39 if (time_before (jiffies, ehci->next_statechange)) 41 if (time_before (jiffies, ehci->next_statechange))
40 msleep(5); 42 msleep(5);
41 43
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c
index 2718b5dc4ec1..46873f2534b5 100644
--- a/drivers/usb/host/isp116x-hcd.c
+++ b/drivers/usb/host/isp116x-hcd.c
@@ -1577,7 +1577,7 @@ static int isp116x_remove(struct platform_device *pdev)
1577 1577
1578#define resource_len(r) (((r)->end - (r)->start) + 1) 1578#define resource_len(r) (((r)->end - (r)->start) + 1)
1579 1579
1580static int __init isp116x_probe(struct platform_device *pdev) 1580static int __devinit isp116x_probe(struct platform_device *pdev)
1581{ 1581{
1582 struct usb_hcd *hcd; 1582 struct usb_hcd *hcd;
1583 struct isp116x *isp116x; 1583 struct isp116x *isp116x;
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 930346487278..d849c809acbd 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -18,19 +18,38 @@
18#include <asm/mach-types.h> 18#include <asm/mach-types.h>
19#include <asm/hardware.h> 19#include <asm/hardware.h>
20#include <asm/arch/board.h> 20#include <asm/arch/board.h>
21#include <asm/arch/cpu.h>
21 22
22#ifndef CONFIG_ARCH_AT91 23#ifndef CONFIG_ARCH_AT91
23#error "CONFIG_ARCH_AT91 must be defined." 24#error "CONFIG_ARCH_AT91 must be defined."
24#endif 25#endif
25 26
26/* interface and function clocks */ 27/* interface and function clocks; sometimes also an AHB clock */
27static struct clk *iclk, *fclk; 28static struct clk *iclk, *fclk, *hclk;
28static int clocked; 29static int clocked;
29 30
30extern int usb_disabled(void); 31extern int usb_disabled(void);
31 32
32/*-------------------------------------------------------------------------*/ 33/*-------------------------------------------------------------------------*/
33 34
35static void at91_start_clock(void)
36{
37 if (cpu_is_at91sam9261())
38 clk_enable(hclk);
39 clk_enable(iclk);
40 clk_enable(fclk);
41 clocked = 1;
42}
43
44static void at91_stop_clock(void)
45{
46 clk_disable(fclk);
47 clk_disable(iclk);
48 if (cpu_is_at91sam9261())
49 clk_disable(hclk);
50 clocked = 0;
51}
52
34static void at91_start_hc(struct platform_device *pdev) 53static void at91_start_hc(struct platform_device *pdev)
35{ 54{
36 struct usb_hcd *hcd = platform_get_drvdata(pdev); 55 struct usb_hcd *hcd = platform_get_drvdata(pdev);
@@ -41,9 +60,7 @@ static void at91_start_hc(struct platform_device *pdev)
41 /* 60 /*
42 * Start the USB clocks. 61 * Start the USB clocks.
43 */ 62 */
44 clk_enable(iclk); 63 at91_start_clock();
45 clk_enable(fclk);
46 clocked = 1;
47 64
48 /* 65 /*
49 * The USB host controller must remain in reset. 66 * The USB host controller must remain in reset.
@@ -66,9 +83,7 @@ static void at91_stop_hc(struct platform_device *pdev)
66 /* 83 /*
67 * Stop the USB clocks. 84 * Stop the USB clocks.
68 */ 85 */
69 clk_disable(fclk); 86 at91_stop_clock();
70 clk_disable(iclk);
71 clocked = 0;
72} 87}
73 88
74 89
@@ -126,6 +141,8 @@ static int usb_hcd_at91_probe(const struct hc_driver *driver,
126 141
127 iclk = clk_get(&pdev->dev, "ohci_clk"); 142 iclk = clk_get(&pdev->dev, "ohci_clk");
128 fclk = clk_get(&pdev->dev, "uhpck"); 143 fclk = clk_get(&pdev->dev, "uhpck");
144 if (cpu_is_at91sam9261())
145 hclk = clk_get(&pdev->dev, "hck0");
129 146
130 at91_start_hc(pdev); 147 at91_start_hc(pdev);
131 ohci_hcd_init(hcd_to_ohci(hcd)); 148 ohci_hcd_init(hcd_to_ohci(hcd));
@@ -137,6 +154,8 @@ static int usb_hcd_at91_probe(const struct hc_driver *driver,
137 /* Error handling */ 154 /* Error handling */
138 at91_stop_hc(pdev); 155 at91_stop_hc(pdev);
139 156
157 if (cpu_is_at91sam9261())
158 clk_put(hclk);
140 clk_put(fclk); 159 clk_put(fclk);
141 clk_put(iclk); 160 clk_put(iclk);
142 161
@@ -171,9 +190,11 @@ static int usb_hcd_at91_remove(struct usb_hcd *hcd,
171 iounmap(hcd->regs); 190 iounmap(hcd->regs);
172 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 191 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
173 192
193 if (cpu_is_at91sam9261())
194 clk_put(hclk);
174 clk_put(fclk); 195 clk_put(fclk);
175 clk_put(iclk); 196 clk_put(iclk);
176 fclk = iclk = NULL; 197 fclk = iclk = hclk = NULL;
177 198
178 dev_set_drvdata(&pdev->dev, NULL); 199 dev_set_drvdata(&pdev->dev, NULL);
179 return 0; 200 return 0;
@@ -280,9 +301,7 @@ ohci_hcd_at91_drv_suspend(struct platform_device *pdev, pm_message_t mesg)
280 */ 301 */
281 if (at91_suspend_entering_slow_clock()) { 302 if (at91_suspend_entering_slow_clock()) {
282 ohci_usb_reset (ohci); 303 ohci_usb_reset (ohci);
283 clk_disable(fclk); 304 at91_stop_clock();
284 clk_disable(iclk);
285 clocked = 0;
286 } 305 }
287 306
288 return 0; 307 return 0;
@@ -295,11 +314,8 @@ static int ohci_hcd_at91_drv_resume(struct platform_device *pdev)
295 if (device_may_wakeup(&pdev->dev)) 314 if (device_may_wakeup(&pdev->dev))
296 disable_irq_wake(hcd->irq); 315 disable_irq_wake(hcd->irq);
297 316
298 if (!clocked) { 317 if (!clocked)
299 clk_enable(iclk); 318 at91_start_clock();
300 clk_enable(fclk);
301 clocked = 1;
302 }
303 319
304 return 0; 320 return 0;
305} 321}
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index fa6a7ceaa0db..f0d29eda3c6d 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -42,6 +42,9 @@
42#include <asm/system.h> 42#include <asm/system.h>
43#include <asm/unaligned.h> 43#include <asm/unaligned.h>
44#include <asm/byteorder.h> 44#include <asm/byteorder.h>
45#ifdef CONFIG_PPC_PS3
46#include <asm/firmware.h>
47#endif
45 48
46#include "../core/hcd.h" 49#include "../core/hcd.h"
47 50
@@ -944,9 +947,12 @@ static int __init ohci_hcd_mod_init(void)
944 sizeof (struct ed), sizeof (struct td)); 947 sizeof (struct ed), sizeof (struct td));
945 948
946#ifdef PS3_SYSTEM_BUS_DRIVER 949#ifdef PS3_SYSTEM_BUS_DRIVER
947 retval = ps3_system_bus_driver_register(&PS3_SYSTEM_BUS_DRIVER); 950 if (firmware_has_feature(FW_FEATURE_PS3_LV1)) {
948 if (retval < 0) 951 retval = ps3_system_bus_driver_register(
949 goto error_ps3; 952 &PS3_SYSTEM_BUS_DRIVER);
953 if (retval < 0)
954 goto error_ps3;
955 }
950#endif 956#endif
951 957
952#ifdef PLATFORM_DRIVER 958#ifdef PLATFORM_DRIVER
@@ -992,7 +998,8 @@ static int __init ohci_hcd_mod_init(void)
992 error_platform: 998 error_platform:
993#endif 999#endif
994#ifdef PS3_SYSTEM_BUS_DRIVER 1000#ifdef PS3_SYSTEM_BUS_DRIVER
995 ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); 1001 if (firmware_has_feature(FW_FEATURE_PS3_LV1))
1002 ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
996 error_ps3: 1003 error_ps3:
997#endif 1004#endif
998 return retval; 1005 return retval;
@@ -1014,7 +1021,8 @@ static void __exit ohci_hcd_mod_exit(void)
1014 platform_driver_unregister(&PLATFORM_DRIVER); 1021 platform_driver_unregister(&PLATFORM_DRIVER);
1015#endif 1022#endif
1016#ifdef PS3_SYSTEM_BUS_DRIVER 1023#ifdef PS3_SYSTEM_BUS_DRIVER
1017 ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); 1024 if (firmware_has_feature(FW_FEATURE_PS3_LV1))
1025 ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
1018#endif 1026#endif
1019} 1027}
1020module_exit(ohci_hcd_mod_exit); 1028module_exit(ohci_hcd_mod_exit);
diff --git a/drivers/usb/input/hid-core.c b/drivers/usb/input/hid-core.c
index 4d8ed3d71a15..ef09952f2039 100644
--- a/drivers/usb/input/hid-core.c
+++ b/drivers/usb/input/hid-core.c
@@ -515,6 +515,7 @@ void usbhid_close(struct hid_device *hid)
515 515
516#define USB_VENDOR_ID_TURBOX 0x062a 516#define USB_VENDOR_ID_TURBOX 0x062a
517#define USB_DEVICE_ID_TURBOX_KEYBOARD 0x0201 517#define USB_DEVICE_ID_TURBOX_KEYBOARD 0x0201
518#define USB_VENDOR_ID_CIDC 0x1677
518 519
519/* 520/*
520 * Initialize all reports 521 * Initialize all reports
@@ -548,7 +549,6 @@ void usbhid_init_reports(struct hid_device *hid)
548} 549}
549 550
550#define USB_VENDOR_ID_GTCO 0x078c 551#define USB_VENDOR_ID_GTCO 0x078c
551#define USB_VENDOR_ID_GTCO_IPANEL_2 0x5543
552#define USB_DEVICE_ID_GTCO_90 0x0090 552#define USB_DEVICE_ID_GTCO_90 0x0090
553#define USB_DEVICE_ID_GTCO_100 0x0100 553#define USB_DEVICE_ID_GTCO_100 0x0100
554#define USB_DEVICE_ID_GTCO_101 0x0101 554#define USB_DEVICE_ID_GTCO_101 0x0101
@@ -594,8 +594,6 @@ void usbhid_init_reports(struct hid_device *hid)
594#define USB_DEVICE_ID_GTCO_1004 0x1004 594#define USB_DEVICE_ID_GTCO_1004 0x1004
595#define USB_DEVICE_ID_GTCO_1005 0x1005 595#define USB_DEVICE_ID_GTCO_1005 0x1005
596#define USB_DEVICE_ID_GTCO_1006 0x1006 596#define USB_DEVICE_ID_GTCO_1006 0x1006
597#define USB_DEVICE_ID_GTCO_8 0x0008
598#define USB_DEVICE_ID_GTCO_d 0x000d
599 597
600#define USB_VENDOR_ID_WACOM 0x056a 598#define USB_VENDOR_ID_WACOM 0x056a
601 599
@@ -854,8 +852,6 @@ static const struct hid_blacklist {
854 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004, HID_QUIRK_IGNORE }, 852 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004, HID_QUIRK_IGNORE },
855 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005, HID_QUIRK_IGNORE }, 853 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005, HID_QUIRK_IGNORE },
856 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006, HID_QUIRK_IGNORE }, 854 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006, HID_QUIRK_IGNORE },
857 { USB_VENDOR_ID_GTCO_IPANEL_2, USB_DEVICE_ID_GTCO_8, HID_QUIRK_IGNORE },
858 { USB_VENDOR_ID_GTCO_IPANEL_2, USB_DEVICE_ID_GTCO_d, HID_QUIRK_IGNORE },
859 { USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA, HID_QUIRK_IGNORE }, 855 { USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA, HID_QUIRK_IGNORE },
860 { USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO, HID_QUIRK_IGNORE }, 856 { USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO, HID_QUIRK_IGNORE },
861 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY, HID_QUIRK_IGNORE }, 857 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY, HID_QUIRK_IGNORE },
@@ -953,6 +949,8 @@ static const struct hid_blacklist {
953 949
954 { USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER, HID_QUIRK_SONY_PS3_CONTROLLER }, 950 { USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER, HID_QUIRK_SONY_PS3_CONTROLLER },
955 951
952 { USB_VENDOR_ID_CIDC, 0x0103, HID_QUIRK_IGNORE },
953
956 { 0, 0 } 954 { 0, 0 }
957}; 955};
958 956
diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
index a74bf8617e7f..4907e8b80070 100644
--- a/drivers/usb/misc/Kconfig
+++ b/drivers/usb/misc/Kconfig
@@ -88,6 +88,17 @@ config USB_LCD
88 To compile this driver as a module, choose M here: the 88 To compile this driver as a module, choose M here: the
89 module will be called usblcd. 89 module will be called usblcd.
90 90
91config USB_BERRY_CHARGE
92 tristate "USB BlackBerry recharge support"
93 depends on USB
94 help
95 Say Y here if you want to connect a BlackBerry device to your
96 computer's USB port and have it automatically switch to "recharge"
97 mode.
98
99 To compile this driver as a module, choose M here: the
100 module will be called berry_charge.
101
91config USB_LED 102config USB_LED
92 tristate "USB LED driver support" 103 tristate "USB LED driver support"
93 depends on USB 104 depends on USB
diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile
index 2cba07d31971..dac2d5b71566 100644
--- a/drivers/usb/misc/Makefile
+++ b/drivers/usb/misc/Makefile
@@ -6,6 +6,7 @@
6obj-$(CONFIG_USB_ADUTUX) += adutux.o 6obj-$(CONFIG_USB_ADUTUX) += adutux.o
7obj-$(CONFIG_USB_APPLEDISPLAY) += appledisplay.o 7obj-$(CONFIG_USB_APPLEDISPLAY) += appledisplay.o
8obj-$(CONFIG_USB_AUERSWALD) += auerswald.o 8obj-$(CONFIG_USB_AUERSWALD) += auerswald.o
9obj-$(CONFIG_USB_BERRY_CHARGE) += berry_charge.o
9obj-$(CONFIG_USB_CYPRESS_CY7C63)+= cypress_cy7c63.o 10obj-$(CONFIG_USB_CYPRESS_CY7C63)+= cypress_cy7c63.o
10obj-$(CONFIG_USB_CYTHERM) += cytherm.o 11obj-$(CONFIG_USB_CYTHERM) += cytherm.o
11obj-$(CONFIG_USB_EMI26) += emi26.o 12obj-$(CONFIG_USB_EMI26) += emi26.o
diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
index 32f0e3a5b022..e573c8ba9785 100644
--- a/drivers/usb/misc/appledisplay.c
+++ b/drivers/usb/misc/appledisplay.c
@@ -281,8 +281,8 @@ static int appledisplay_probe(struct usb_interface *iface,
281 /* Register backlight device */ 281 /* Register backlight device */
282 snprintf(bl_name, sizeof(bl_name), "appledisplay%d", 282 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
283 atomic_inc_return(&count_displays) - 1); 283 atomic_inc_return(&count_displays) - 1);
284 pdata->bd = backlight_device_register(bl_name, NULL, 284 pdata->bd = backlight_device_register(bl_name, NULL, pdata,
285 pdata, &appledisplay_bl_data); 285 &appledisplay_bl_data);
286 if (IS_ERR(pdata->bd)) { 286 if (IS_ERR(pdata->bd)) {
287 err("appledisplay: Backlight registration failed"); 287 err("appledisplay: Backlight registration failed");
288 goto error; 288 goto error;
diff --git a/drivers/usb/misc/berry_charge.c b/drivers/usb/misc/berry_charge.c
new file mode 100644
index 000000000000..60893c6c8221
--- /dev/null
+++ b/drivers/usb/misc/berry_charge.c
@@ -0,0 +1,140 @@
1/*
2 * USB BlackBerry charging module
3 *
4 * Copyright (C) 2007 Greg Kroah-Hartman <gregkh@suse.de>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2.
9 *
10 * Information on how to switch configs was taken by the bcharge.cc file
11 * created by the barry.sf.net project.
12 *
13 * bcharge.cc has the following copyright:
14 * Copyright (C) 2006, Net Direct Inc. (http://www.netdirect.ca/)
15 * and is released under the GPLv2.
16 *
17 *
18 */
19
20#include <linux/kernel.h>
21#include <linux/errno.h>
22#include <linux/init.h>
23#include <linux/slab.h>
24#include <linux/module.h>
25#include <linux/usb.h>
26
27#define RIM_VENDOR 0x0fca
28#define BLACKBERRY 0x0001
29
30static int debug;
31
32#ifdef dbg
33#undef dbg
34#endif
35#define dbg(dev, format, arg...) \
36 if (debug) \
37 dev_printk(KERN_DEBUG , dev , format , ## arg)
38
39static struct usb_device_id id_table [] = {
40 { USB_DEVICE(RIM_VENDOR, BLACKBERRY) },
41 { }, /* Terminating entry */
42};
43MODULE_DEVICE_TABLE(usb, id_table);
44
45static int magic_charge(struct usb_device *udev)
46{
47 char *dummy_buffer = kzalloc(2, GFP_KERNEL);
48 int retval;
49
50 if (!dummy_buffer)
51 return -ENOMEM;
52
53 /* send two magic commands and then set the configuration. The device
54 * will then reset itself with the new power usage and should start
55 * charging. */
56
57 /* Note, with testing, it only seems that the first message is really
58 * needed (at least for the 8700c), but to be safe, we emulate what
59 * other operating systems seem to be sending to their device. We
60 * really need to get some specs for this device to be sure about what
61 * is going on here.
62 */
63 dbg(&udev->dev, "Sending first magic command\n");
64 retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
65 0xa5, 0xc0, 0, 1, dummy_buffer, 2, 100);
66 if (retval != 2) {
67 dev_err(&udev->dev, "First magic command failed: %d.\n",
68 retval);
69 return retval;
70 }
71
72 dbg(&udev->dev, "Sending first magic command\n");
73 retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
74 0xa2, 0x40, 0, 1, dummy_buffer, 0, 100);
75 if (retval != 0) {
76 dev_err(&udev->dev, "Second magic command failed: %d.\n",
77 retval);
78 return retval;
79 }
80
81 dbg(&udev->dev, "Calling set_configuration\n");
82 retval = usb_driver_set_configuration(udev, 1);
83 if (retval)
84 dev_err(&udev->dev, "Set Configuration failed :%d.\n", retval);
85
86 return retval;
87}
88
89static int berry_probe(struct usb_interface *intf,
90 const struct usb_device_id *id)
91{
92 struct usb_device *udev = interface_to_usbdev(intf);
93
94 dbg(&udev->dev, "Power is set to %dmA\n",
95 udev->actconfig->desc.bMaxPower * 2);
96
97 /* check the power usage so we don't try to enable something that is
98 * already enabled */
99 if ((udev->actconfig->desc.bMaxPower * 2) == 500) {
100 dbg(&udev->dev, "device is already charging, power is "
101 "set to %dmA\n", udev->actconfig->desc.bMaxPower * 2);
102 return -ENODEV;
103 }
104
105 /* turn the power on */
106 magic_charge(udev);
107
108 /* we don't really want to bind to the device, userspace programs can
109 * handle the syncing just fine, so get outta here. */
110 return -ENODEV;
111}
112
113static void berry_disconnect(struct usb_interface *intf)
114{
115}
116
117static struct usb_driver berry_driver = {
118 .name = "berry_charge",
119 .probe = berry_probe,
120 .disconnect = berry_disconnect,
121 .id_table = id_table,
122};
123
124static int __init berry_init(void)
125{
126 return usb_register(&berry_driver);
127}
128
129static void __exit berry_exit(void)
130{
131 usb_deregister(&berry_driver);
132}
133
134module_init(berry_init);
135module_exit(berry_exit);
136
137MODULE_LICENSE("GPL");
138MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@suse.de>");
139module_param(debug, bool, S_IRUGO | S_IWUSR);
140MODULE_PARM_DESC(debug, "Debug enabled or not");
diff --git a/drivers/usb/net/Kconfig b/drivers/usb/net/Kconfig
index a2b94ef512bc..0f3d7dbb537f 100644
--- a/drivers/usb/net/Kconfig
+++ b/drivers/usb/net/Kconfig
@@ -84,6 +84,7 @@ config USB_PEGASUS
84config USB_RTL8150 84config USB_RTL8150
85 tristate "USB RTL8150 based ethernet device support (EXPERIMENTAL)" 85 tristate "USB RTL8150 based ethernet device support (EXPERIMENTAL)"
86 depends on EXPERIMENTAL 86 depends on EXPERIMENTAL
87 select MII
87 help 88 help
88 Say Y here if you have RTL8150 based usb-ethernet adapter. 89 Say Y here if you have RTL8150 based usb-ethernet adapter.
89 Send me <petkan@users.sourceforge.net> any comments you may have. 90 Send me <petkan@users.sourceforge.net> any comments you may have.
@@ -98,7 +99,7 @@ config USB_USBNET_MII
98 99
99config USB_USBNET 100config USB_USBNET
100 tristate "Multi-purpose USB Networking Framework" 101 tristate "Multi-purpose USB Networking Framework"
101 select MII if USBNET_MII != n 102 select MII if USB_USBNET_MII != n
102 ---help--- 103 ---help---
103 This driver supports several kinds of network links over USB, 104 This driver supports several kinds of network links over USB,
104 with "minidrivers" built around a common network driver core 105 with "minidrivers" built around a common network driver core
@@ -239,6 +240,7 @@ config USB_NET_RNDIS_HOST
239config USB_NET_CDC_SUBSET 240config USB_NET_CDC_SUBSET
240 tristate "Simple USB Network Links (CDC Ethernet subset)" 241 tristate "Simple USB Network Links (CDC Ethernet subset)"
241 depends on USB_USBNET 242 depends on USB_USBNET
243 default y
242 help 244 help
243 This driver module supports USB network devices that can work 245 This driver module supports USB network devices that can work
244 without any device-specific information. Select it if you have 246 without any device-specific information. Select it if you have
@@ -298,6 +300,13 @@ config USB_EPSON2888
298 Choose this option to support the usb networking links used 300 Choose this option to support the usb networking links used
299 by some sample firmware from Epson. 301 by some sample firmware from Epson.
300 302
303config USB_KC2190
304 boolean "KT Technology KC2190 based cables (InstaNet)"
305 depends on USB_NET_CDC_SUBSET && EXPERIMENTAL
306 help
307  Choose this option if you're using a host-to-host cable
308  with one of these chips.
309
301config USB_NET_ZAURUS 310config USB_NET_ZAURUS
302 tristate "Sharp Zaurus (stock ROMs) and compatible" 311 tristate "Sharp Zaurus (stock ROMs) and compatible"
303 depends on USB_USBNET 312 depends on USB_USBNET
diff --git a/drivers/usb/net/asix.c b/drivers/usb/net/asix.c
index bd357e178e55..7ef2e4b5e39b 100644
--- a/drivers/usb/net/asix.c
+++ b/drivers/usb/net/asix.c
@@ -351,9 +351,11 @@ static struct sk_buff *asix_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
351 351
352 skb_push(skb, 4); 352 skb_push(skb, 4);
353 packet_len = (((skb->len - 4) ^ 0x0000ffff) << 16) + (skb->len - 4); 353 packet_len = (((skb->len - 4) ^ 0x0000ffff) << 16) + (skb->len - 4);
354 cpu_to_le32s(&packet_len);
354 memcpy(skb->data, &packet_len, sizeof(packet_len)); 355 memcpy(skb->data, &packet_len, sizeof(packet_len));
355 356
356 if ((skb->len % 512) == 0) { 357 if ((skb->len % 512) == 0) {
358 cpu_to_le32s(&padbytes);
357 memcpy( skb->tail, &padbytes, sizeof(padbytes)); 359 memcpy( skb->tail, &padbytes, sizeof(padbytes));
358 skb_put(skb, sizeof(padbytes)); 360 skb_put(skb, sizeof(padbytes));
359 } 361 }
diff --git a/drivers/usb/net/cdc_subset.c b/drivers/usb/net/cdc_subset.c
index ae8fb06cf38e..bc62b012602b 100644
--- a/drivers/usb/net/cdc_subset.c
+++ b/drivers/usb/net/cdc_subset.c
@@ -79,13 +79,19 @@ static int always_connected (struct usbnet *dev)
79 * 79 *
80 * ALi M5632 driver ... does high speed 80 * ALi M5632 driver ... does high speed
81 * 81 *
82 * NOTE that the MS-Windows drivers for this chip use some funky and
83 * (naturally) undocumented 7-byte prefix to each packet, so this is a
84 * case where we don't currently interoperate. Also, once you unplug
85 * one end of the cable, you need to replug the other end too ... since
86 * chip docs are unavailable, there's no way to reset the relevant state
87 * short of a power cycle.
88 *
82 *-------------------------------------------------------------------------*/ 89 *-------------------------------------------------------------------------*/
83 90
84static const struct driver_info ali_m5632_info = { 91static const struct driver_info ali_m5632_info = {
85 .description = "ALi M5632", 92 .description = "ALi M5632",
86}; 93};
87 94
88
89#endif 95#endif
90 96
91 97
@@ -159,6 +165,11 @@ static const struct driver_info epson2888_info = {
159#endif /* CONFIG_USB_EPSON2888 */ 165#endif /* CONFIG_USB_EPSON2888 */
160 166
161 167
168/*-------------------------------------------------------------------------
169 *
170 * info from Jonathan McDowell <noodles@earth.li>
171 *
172 *-------------------------------------------------------------------------*/
162#ifdef CONFIG_USB_KC2190 173#ifdef CONFIG_USB_KC2190
163#define HAVE_HARDWARE 174#define HAVE_HARDWARE
164static const struct driver_info kc2190_info = { 175static const struct driver_info kc2190_info = {
@@ -223,6 +234,10 @@ static const struct usb_device_id products [] = {
223 USB_DEVICE (0x0402, 0x5632), // ALi defaults 234 USB_DEVICE (0x0402, 0x5632), // ALi defaults
224 .driver_info = (unsigned long) &ali_m5632_info, 235 .driver_info = (unsigned long) &ali_m5632_info,
225}, 236},
237{
238 USB_DEVICE (0x182d,0x207c), // SiteCom CN-124
239 .driver_info = (unsigned long) &ali_m5632_info,
240},
226#endif 241#endif
227 242
228#ifdef CONFIG_USB_AN2720 243#ifdef CONFIG_USB_AN2720
@@ -314,13 +329,13 @@ static struct usb_driver cdc_subset_driver = {
314 329
315static int __init cdc_subset_init(void) 330static int __init cdc_subset_init(void)
316{ 331{
317 return usb_register(&cdc_subset_driver); 332 return usb_register(&cdc_subset_driver);
318} 333}
319module_init(cdc_subset_init); 334module_init(cdc_subset_init);
320 335
321static void __exit cdc_subset_exit(void) 336static void __exit cdc_subset_exit(void)
322{ 337{
323 usb_deregister(&cdc_subset_driver); 338 usb_deregister(&cdc_subset_driver);
324} 339}
325module_exit(cdc_subset_exit); 340module_exit(cdc_subset_exit);
326 341
diff --git a/drivers/usb/net/usbnet.c b/drivers/usb/net/usbnet.c
index 43ba61abfcc5..de69b183bd2f 100644
--- a/drivers/usb/net/usbnet.c
+++ b/drivers/usb/net/usbnet.c
@@ -147,7 +147,7 @@ int usbnet_get_endpoints(struct usbnet *dev, struct usb_interface *intf)
147 if (tmp < 0) 147 if (tmp < 0)
148 return tmp; 148 return tmp;
149 } 149 }
150 150
151 dev->in = usb_rcvbulkpipe (dev->udev, 151 dev->in = usb_rcvbulkpipe (dev->udev,
152 in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); 152 in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
153 dev->out = usb_sndbulkpipe (dev->udev, 153 dev->out = usb_sndbulkpipe (dev->udev,
@@ -327,7 +327,7 @@ static void rx_submit (struct usbnet *dev, struct urb *urb, gfp_t flags)
327 if (netif_running (dev->net) 327 if (netif_running (dev->net)
328 && netif_device_present (dev->net) 328 && netif_device_present (dev->net)
329 && !test_bit (EVENT_RX_HALT, &dev->flags)) { 329 && !test_bit (EVENT_RX_HALT, &dev->flags)) {
330 switch (retval = usb_submit_urb (urb, GFP_ATOMIC)){ 330 switch (retval = usb_submit_urb (urb, GFP_ATOMIC)){
331 case -EPIPE: 331 case -EPIPE:
332 usbnet_defer_kevent (dev, EVENT_RX_HALT); 332 usbnet_defer_kevent (dev, EVENT_RX_HALT);
333 break; 333 break;
@@ -443,7 +443,7 @@ block:
443 case -EOVERFLOW: 443 case -EOVERFLOW:
444 dev->stats.rx_over_errors++; 444 dev->stats.rx_over_errors++;
445 // FALLTHROUGH 445 // FALLTHROUGH
446 446
447 default: 447 default:
448 entry->state = rx_cleanup; 448 entry->state = rx_cleanup;
449 dev->stats.rx_errors++; 449 dev->stats.rx_errors++;
@@ -560,7 +560,7 @@ static int usbnet_stop (struct net_device *net)
560 560
561 if (netif_msg_ifdown (dev)) 561 if (netif_msg_ifdown (dev))
562 devinfo (dev, "stop stats: rx/tx %ld/%ld, errs %ld/%ld", 562 devinfo (dev, "stop stats: rx/tx %ld/%ld, errs %ld/%ld",
563 dev->stats.rx_packets, dev->stats.tx_packets, 563 dev->stats.rx_packets, dev->stats.tx_packets,
564 dev->stats.rx_errors, dev->stats.tx_errors 564 dev->stats.rx_errors, dev->stats.tx_errors
565 ); 565 );
566 566
@@ -578,7 +578,7 @@ static int usbnet_stop (struct net_device *net)
578 devdbg (dev, "waited for %d urb completions", temp); 578 devdbg (dev, "waited for %d urb completions", temp);
579 } 579 }
580 dev->wait = NULL; 580 dev->wait = NULL;
581 remove_wait_queue (&unlink_wakeup, &wait); 581 remove_wait_queue (&unlink_wakeup, &wait);
582 582
583 usb_kill_urb(dev->interrupt); 583 usb_kill_urb(dev->interrupt);
584 584
@@ -834,7 +834,7 @@ kevent (struct work_struct *work)
834 } 834 }
835 835
836 if (test_bit (EVENT_LINK_RESET, &dev->flags)) { 836 if (test_bit (EVENT_LINK_RESET, &dev->flags)) {
837 struct driver_info *info = dev->driver_info; 837 struct driver_info *info = dev->driver_info;
838 int retval = 0; 838 int retval = 0;
839 839
840 clear_bit (EVENT_LINK_RESET, &dev->flags); 840 clear_bit (EVENT_LINK_RESET, &dev->flags);
@@ -1066,7 +1066,7 @@ static void usbnet_bh (unsigned long param)
1066 * USB Device Driver support 1066 * USB Device Driver support
1067 * 1067 *
1068 *-------------------------------------------------------------------------*/ 1068 *-------------------------------------------------------------------------*/
1069 1069
1070// precondition: never called in_interrupt 1070// precondition: never called in_interrupt
1071 1071
1072void usbnet_disconnect (struct usb_interface *intf) 1072void usbnet_disconnect (struct usb_interface *intf)
@@ -1087,7 +1087,7 @@ void usbnet_disconnect (struct usb_interface *intf)
1087 intf->dev.driver->name, 1087 intf->dev.driver->name,
1088 xdev->bus->bus_name, xdev->devpath, 1088 xdev->bus->bus_name, xdev->devpath,
1089 dev->driver_info->description); 1089 dev->driver_info->description);
1090 1090
1091 net = dev->net; 1091 net = dev->net;
1092 unregister_netdev (net); 1092 unregister_netdev (net);
1093 1093
@@ -1111,7 +1111,7 @@ int
1111usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) 1111usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
1112{ 1112{
1113 struct usbnet *dev; 1113 struct usbnet *dev;
1114 struct net_device *net; 1114 struct net_device *net;
1115 struct usb_host_interface *interface; 1115 struct usb_host_interface *interface;
1116 struct driver_info *info; 1116 struct driver_info *info;
1117 struct usb_device *xdev; 1117 struct usb_device *xdev;
@@ -1181,6 +1181,9 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
1181 // NOTE net->name still not usable ... 1181 // NOTE net->name still not usable ...
1182 if (info->bind) { 1182 if (info->bind) {
1183 status = info->bind (dev, udev); 1183 status = info->bind (dev, udev);
1184 if (status < 0)
1185 goto out1;
1186
1184 // heuristic: "usb%d" for links we know are two-host, 1187 // heuristic: "usb%d" for links we know are two-host,
1185 // else "eth%d" when there's reasonable doubt. userspace 1188 // else "eth%d" when there's reasonable doubt. userspace
1186 // can rename the link if it knows better. 1189 // can rename the link if it knows better.
@@ -1207,12 +1210,12 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
1207 if (status == 0 && dev->status) 1210 if (status == 0 && dev->status)
1208 status = init_status (dev, udev); 1211 status = init_status (dev, udev);
1209 if (status < 0) 1212 if (status < 0)
1210 goto out1; 1213 goto out3;
1211 1214
1212 if (!dev->rx_urb_size) 1215 if (!dev->rx_urb_size)
1213 dev->rx_urb_size = dev->hard_mtu; 1216 dev->rx_urb_size = dev->hard_mtu;
1214 dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1); 1217 dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1);
1215 1218
1216 SET_NETDEV_DEV(net, &udev->dev); 1219 SET_NETDEV_DEV(net, &udev->dev);
1217 status = register_netdev (net); 1220 status = register_netdev (net);
1218 if (status) 1221 if (status)
@@ -1255,7 +1258,7 @@ EXPORT_SYMBOL_GPL(usbnet_probe);
1255int usbnet_suspend (struct usb_interface *intf, pm_message_t message) 1258int usbnet_suspend (struct usb_interface *intf, pm_message_t message)
1256{ 1259{
1257 struct usbnet *dev = usb_get_intfdata(intf); 1260 struct usbnet *dev = usb_get_intfdata(intf);
1258 1261
1259 /* accelerate emptying of the rx and queues, to avoid 1262 /* accelerate emptying of the rx and queues, to avoid
1260 * having everything error out. 1263 * having everything error out.
1261 */ 1264 */
@@ -1286,7 +1289,7 @@ static int __init usbnet_init(void)
1286 < sizeof (struct skb_data)); 1289 < sizeof (struct skb_data));
1287 1290
1288 random_ether_addr(node_id); 1291 random_ether_addr(node_id);
1289 return 0; 1292 return 0;
1290} 1293}
1291module_init(usbnet_init); 1294module_init(usbnet_init);
1292 1295
diff --git a/drivers/usb/serial/airprime.c b/drivers/usb/serial/airprime.c
index 0af42e32fa0a..18816bf96a4d 100644
--- a/drivers/usb/serial/airprime.c
+++ b/drivers/usb/serial/airprime.c
@@ -58,11 +58,6 @@ static void airprime_read_bulk_callback(struct urb *urb)
58 if (urb->status) { 58 if (urb->status) {
59 dbg("%s - nonzero read bulk status received: %d", 59 dbg("%s - nonzero read bulk status received: %d",
60 __FUNCTION__, urb->status); 60 __FUNCTION__, urb->status);
61 /* something happened, so free up the memory for this urb */
62 if (urb->transfer_buffer) {
63 kfree (urb->transfer_buffer);
64 urb->transfer_buffer = NULL;
65 }
66 return; 61 return;
67 } 62 }
68 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data); 63 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data);
@@ -146,6 +141,8 @@ static int airprime_open(struct usb_serial_port *port, struct file *filp)
146 airprime_read_bulk_callback, port); 141 airprime_read_bulk_callback, port);
147 result = usb_submit_urb(urb, GFP_KERNEL); 142 result = usb_submit_urb(urb, GFP_KERNEL);
148 if (result) { 143 if (result) {
144 usb_free_urb(urb);
145 kfree(buffer);
149 dev_err(&port->dev, 146 dev_err(&port->dev,
150 "%s - failed submitting read urb %d for port %d, error %d\n", 147 "%s - failed submitting read urb %d for port %d, error %d\n",
151 __FUNCTION__, i, port->number, result); 148 __FUNCTION__, i, port->number, result);
@@ -160,27 +157,12 @@ static int airprime_open(struct usb_serial_port *port, struct file *filp)
160 /* some error happened, cancel any submitted urbs and clean up anything that 157 /* some error happened, cancel any submitted urbs and clean up anything that
161 got allocated successfully */ 158 got allocated successfully */
162 159
163 for ( ; i >= 0; --i) { 160 while (i-- != 0) {
164 urb = priv->read_urbp[i]; 161 urb = priv->read_urbp[i];
165 if (urb) { 162 buffer = urb->transfer_buffer;
166 /* This urb was submitted successfully. So we have to 163 usb_kill_urb (urb);
167 cancel it. 164 usb_free_urb (urb);
168 Unlinking the urb will invoke read_bulk_callback() 165 kfree (buffer);
169 with an error status, so its transfer buffer will
170 be freed there */
171 if (usb_unlink_urb (urb) != -EINPROGRESS) {
172 /* comments in drivers/usb/core/urb.c say this
173 can only happen if the urb was never submitted,
174 or has completed already.
175 Either way we may have to free the transfer
176 buffer here. */
177 if (urb->transfer_buffer) {
178 kfree (urb->transfer_buffer);
179 urb->transfer_buffer = NULL;
180 }
181 }
182 usb_free_urb (urb);
183 }
184 } 166 }
185 167
186 out: 168 out:
@@ -194,10 +176,9 @@ static void airprime_close(struct usb_serial_port *port, struct file * filp)
194 176
195 dbg("%s - port %d", __FUNCTION__, port->number); 177 dbg("%s - port %d", __FUNCTION__, port->number);
196 178
197 /* killing the urb will invoke read_bulk_callback() with an error status,
198 so the transfer buffer will be freed there */
199 for (i = 0; i < NUM_READ_URBS; ++i) { 179 for (i = 0; i < NUM_READ_URBS; ++i) {
200 usb_kill_urb (priv->read_urbp[i]); 180 usb_kill_urb (priv->read_urbp[i]);
181 kfree (priv->read_urbp[i]->transfer_buffer);
201 usb_free_urb (priv->read_urbp[i]); 182 usb_free_urb (priv->read_urbp[i]);
202 } 183 }
203 184
diff --git a/drivers/usb/serial/cp2101.c b/drivers/usb/serial/cp2101.c
index 3ec24870bca9..db623e754899 100644
--- a/drivers/usb/serial/cp2101.c
+++ b/drivers/usb/serial/cp2101.c
@@ -69,6 +69,7 @@ static struct usb_device_id id_table [] = {
69 { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */ 69 { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */
70 { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */ 70 { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */
71 { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */ 71 { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */
72 { USB_DEVICE(0x10C5, 0xEA61) }, /* Silicon Labs MobiData GPRS USB Modem */
72 { USB_DEVICE(0x13AD, 0x9999) }, /* Baltech card reader */ 73 { USB_DEVICE(0x13AD, 0x9999) }, /* Baltech card reader */
73 { USB_DEVICE(0x16D6, 0x0001) }, /* Jablotron serial interface */ 74 { USB_DEVICE(0x16D6, 0x0001) }, /* Jablotron serial interface */
74 { } /* Terminating Entry */ 75 { } /* Terminating Entry */
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index 601e0648dec6..53baeec8f265 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -66,6 +66,8 @@ struct usb_serial_driver usb_serial_generic_device = {
66 .num_bulk_out = NUM_DONT_CARE, 66 .num_bulk_out = NUM_DONT_CARE,
67 .num_ports = 1, 67 .num_ports = 1,
68 .shutdown = usb_serial_generic_shutdown, 68 .shutdown = usb_serial_generic_shutdown,
69 .throttle = usb_serial_generic_throttle,
70 .unthrottle = usb_serial_generic_unthrottle,
69}; 71};
70 72
71static int generic_probe(struct usb_interface *interface, 73static int generic_probe(struct usb_interface *interface,
@@ -115,6 +117,7 @@ int usb_serial_generic_open (struct usb_serial_port *port, struct file *filp)
115{ 117{
116 struct usb_serial *serial = port->serial; 118 struct usb_serial *serial = port->serial;
117 int result = 0; 119 int result = 0;
120 unsigned long flags;
118 121
119 dbg("%s - port %d", __FUNCTION__, port->number); 122 dbg("%s - port %d", __FUNCTION__, port->number);
120 123
@@ -124,7 +127,13 @@ int usb_serial_generic_open (struct usb_serial_port *port, struct file *filp)
124 if (port->tty) 127 if (port->tty)
125 port->tty->low_latency = 1; 128 port->tty->low_latency = 1;
126 129
127 /* if we have a bulk interrupt, start reading from it */ 130 /* clear the throttle flags */
131 spin_lock_irqsave(&port->lock, flags);
132 port->throttled = 0;
133 port->throttle_req = 0;
134 spin_unlock_irqrestore(&port->lock, flags);
135
136 /* if we have a bulk endpoint, start reading from it */
128 if (serial->num_bulk_in) { 137 if (serial->num_bulk_in) {
129 /* Start reading from the device */ 138 /* Start reading from the device */
130 usb_fill_bulk_urb (port->read_urb, serial->dev, 139 usb_fill_bulk_urb (port->read_urb, serial->dev,
@@ -253,31 +262,22 @@ int usb_serial_generic_chars_in_buffer (struct usb_serial_port *port)
253 return (chars); 262 return (chars);
254} 263}
255 264
256void usb_serial_generic_read_bulk_callback (struct urb *urb) 265/* Push data to tty layer and resubmit the bulk read URB */
266static void flush_and_resubmit_read_urb (struct usb_serial_port *port)
257{ 267{
258 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
259 struct usb_serial *serial = port->serial; 268 struct usb_serial *serial = port->serial;
260 struct tty_struct *tty; 269 struct urb *urb = port->read_urb;
261 unsigned char *data = urb->transfer_buffer; 270 struct tty_struct *tty = port->tty;
262 int result; 271 int result;
263 272
264 dbg("%s - port %d", __FUNCTION__, port->number); 273 /* Push data to tty */
265
266 if (urb->status) {
267 dbg("%s - nonzero read bulk status received: %d", __FUNCTION__, urb->status);
268 return;
269 }
270
271 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data);
272
273 tty = port->tty;
274 if (tty && urb->actual_length) { 274 if (tty && urb->actual_length) {
275 tty_buffer_request_room(tty, urb->actual_length); 275 tty_buffer_request_room(tty, urb->actual_length);
276 tty_insert_flip_string(tty, data, urb->actual_length); 276 tty_insert_flip_string(tty, urb->transfer_buffer, urb->actual_length);
277 tty_flip_buffer_push(tty); 277 tty_flip_buffer_push(tty); /* is this allowed from an URB callback ? */
278 } 278 }
279 279
280 /* Continue trying to always read */ 280 /* Continue reading from device */
281 usb_fill_bulk_urb (port->read_urb, serial->dev, 281 usb_fill_bulk_urb (port->read_urb, serial->dev,
282 usb_rcvbulkpipe (serial->dev, 282 usb_rcvbulkpipe (serial->dev,
283 port->bulk_in_endpointAddress), 283 port->bulk_in_endpointAddress),
@@ -290,6 +290,40 @@ void usb_serial_generic_read_bulk_callback (struct urb *urb)
290 if (result) 290 if (result)
291 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result); 291 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result);
292} 292}
293
294void usb_serial_generic_read_bulk_callback (struct urb *urb)
295{
296 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
297 unsigned char *data = urb->transfer_buffer;
298 int is_throttled;
299 unsigned long flags;
300
301 dbg("%s - port %d", __FUNCTION__, port->number);
302
303 if (urb->status) {
304 dbg("%s - nonzero read bulk status received: %d", __FUNCTION__, urb->status);
305 return;
306 }
307
308 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data);
309
310 /* Throttle the device if requested by tty */
311 if (urb->actual_length) {
312 spin_lock_irqsave(&port->lock, flags);
313 is_throttled = port->throttled = port->throttle_req;
314 spin_unlock_irqrestore(&port->lock, flags);
315 if (is_throttled) {
316 /* Let the received data linger in the read URB;
317 * usb_serial_generic_unthrottle() will pick it
318 * up later. */
319 dbg("%s - throttling device", __FUNCTION__);
320 return;
321 }
322 }
323
324 /* Handle data and continue reading from device */
325 flush_and_resubmit_read_urb(port);
326}
293EXPORT_SYMBOL_GPL(usb_serial_generic_read_bulk_callback); 327EXPORT_SYMBOL_GPL(usb_serial_generic_read_bulk_callback);
294 328
295void usb_serial_generic_write_bulk_callback (struct urb *urb) 329void usb_serial_generic_write_bulk_callback (struct urb *urb)
@@ -308,6 +342,38 @@ void usb_serial_generic_write_bulk_callback (struct urb *urb)
308} 342}
309EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback); 343EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback);
310 344
345void usb_serial_generic_throttle (struct usb_serial_port *port)
346{
347 unsigned long flags;
348
349 dbg("%s - port %d", __FUNCTION__, port->number);
350
351 /* Set the throttle request flag. It will be picked up
352 * by usb_serial_generic_read_bulk_callback(). */
353 spin_lock_irqsave(&port->lock, flags);
354 port->throttle_req = 1;
355 spin_unlock_irqrestore(&port->lock, flags);
356}
357
358void usb_serial_generic_unthrottle (struct usb_serial_port *port)
359{
360 int was_throttled;
361 unsigned long flags;
362
363 dbg("%s - port %d", __FUNCTION__, port->number);
364
365 /* Clear the throttle flags */
366 spin_lock_irqsave(&port->lock, flags);
367 was_throttled = port->throttled;
368 port->throttled = port->throttle_req = 0;
369 spin_unlock_irqrestore(&port->lock, flags);
370
371 if (was_throttled) {
372 /* Handle pending data and resume reading from device */
373 flush_and_resubmit_read_urb(port);
374 }
375}
376
311void usb_serial_generic_shutdown (struct usb_serial *serial) 377void usb_serial_generic_shutdown (struct usb_serial *serial)
312{ 378{
313 int i; 379 int i;
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index ced9f32b29d9..9963a8b75840 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -69,7 +69,6 @@ static int option_send_setup(struct usb_serial_port *port);
69/* Vendor and product IDs */ 69/* Vendor and product IDs */
70#define OPTION_VENDOR_ID 0x0AF0 70#define OPTION_VENDOR_ID 0x0AF0
71#define HUAWEI_VENDOR_ID 0x12D1 71#define HUAWEI_VENDOR_ID 0x12D1
72#define AUDIOVOX_VENDOR_ID 0x0F3D
73#define NOVATELWIRELESS_VENDOR_ID 0x1410 72#define NOVATELWIRELESS_VENDOR_ID 0x1410
74#define ANYDATA_VENDOR_ID 0x16d5 73#define ANYDATA_VENDOR_ID 0x16d5
75 74
@@ -81,7 +80,6 @@ static int option_send_setup(struct usb_serial_port *port);
81#define OPTION_PRODUCT_GTMAX36 0x6701 80#define OPTION_PRODUCT_GTMAX36 0x6701
82#define HUAWEI_PRODUCT_E600 0x1001 81#define HUAWEI_PRODUCT_E600 0x1001
83#define HUAWEI_PRODUCT_E220 0x1003 82#define HUAWEI_PRODUCT_E220 0x1003
84#define AUDIOVOX_PRODUCT_AIRCARD 0x0112
85#define NOVATELWIRELESS_PRODUCT_U740 0x1400 83#define NOVATELWIRELESS_PRODUCT_U740 0x1400
86#define ANYDATA_PRODUCT_ID 0x6501 84#define ANYDATA_PRODUCT_ID 0x6501
87 85
@@ -94,7 +92,6 @@ static struct usb_device_id option_ids[] = {
94 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_GTMAX36) }, 92 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_GTMAX36) },
95 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) }, 93 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) },
96 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E220) }, 94 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E220) },
97 { USB_DEVICE(AUDIOVOX_VENDOR_ID, AUDIOVOX_PRODUCT_AIRCARD) },
98 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID,NOVATELWIRELESS_PRODUCT_U740) }, 95 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID,NOVATELWIRELESS_PRODUCT_U740) },
99 { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ID) }, 96 { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ID) },
100 { } /* Terminating entry */ 97 { } /* Terminating entry */
@@ -109,7 +106,6 @@ static struct usb_device_id option_ids1[] = {
109 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_GTMAX36) }, 106 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_GTMAX36) },
110 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) }, 107 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) },
111 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E220) }, 108 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E220) },
112 { USB_DEVICE(AUDIOVOX_VENDOR_ID, AUDIOVOX_PRODUCT_AIRCARD) },
113 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID,NOVATELWIRELESS_PRODUCT_U740) }, 109 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID,NOVATELWIRELESS_PRODUCT_U740) },
114 { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ID) }, 110 { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ID) },
115 { } /* Terminating entry */ 111 { } /* Terminating entry */
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index 6c083d4e2c9b..83dfae93a45d 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -83,6 +83,7 @@ static struct usb_device_id id_table [] = {
83 { USB_DEVICE(BELKIN_VENDOR_ID, BELKIN_PRODUCT_ID) }, 83 { USB_DEVICE(BELKIN_VENDOR_ID, BELKIN_PRODUCT_ID) },
84 { USB_DEVICE(ALCOR_VENDOR_ID, ALCOR_PRODUCT_ID) }, 84 { USB_DEVICE(ALCOR_VENDOR_ID, ALCOR_PRODUCT_ID) },
85 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_ID) }, 85 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_ID) },
86 { USB_DEVICE(WS002IN_VENDOR_ID, WS002IN_PRODUCT_ID) },
86 { } /* Terminating entry */ 87 { } /* Terminating entry */
87}; 88};
88 89
diff --git a/drivers/usb/serial/pl2303.h b/drivers/usb/serial/pl2303.h
index 65a5039665e7..f9a71d0c102e 100644
--- a/drivers/usb/serial/pl2303.h
+++ b/drivers/usb/serial/pl2303.h
@@ -97,3 +97,8 @@
97/* Huawei E620 UMTS/HSDPA card (ID: 12d1:1001) */ 97/* Huawei E620 UMTS/HSDPA card (ID: 12d1:1001) */
98#define HUAWEI_VENDOR_ID 0x12d1 98#define HUAWEI_VENDOR_ID 0x12d1
99#define HUAWEI_PRODUCT_ID 0x1001 99#define HUAWEI_PRODUCT_ID 0x1001
100
101/* Willcom WS002IN Data Driver (by NetIndex Inc.) */
102#define WS002IN_VENDOR_ID 0x11f6
103#define WS002IN_PRODUCT_ID 0x2001
104
diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
index 70234f5dbeeb..e227f64d5641 100644
--- a/drivers/usb/storage/scsiglue.c
+++ b/drivers/usb/storage/scsiglue.c
@@ -153,6 +153,12 @@ static int slave_configure(struct scsi_device *sdev)
153 if (us->flags & US_FL_FIX_CAPACITY) 153 if (us->flags & US_FL_FIX_CAPACITY)
154 sdev->fix_capacity = 1; 154 sdev->fix_capacity = 1;
155 155
156 /* A few disks have two indistinguishable version, one of
157 * which reports the correct capacity and the other does not.
158 * The sd driver has to guess which is the case. */
159 if (us->flags & US_FL_CAPACITY_HEURISTICS)
160 sdev->guess_capacity = 1;
161
156 /* Some devices report a SCSI revision level above 2 but are 162 /* Some devices report a SCSI revision level above 2 but are
157 * unable to handle the REPORT LUNS command (for which 163 * unable to handle the REPORT LUNS command (for which
158 * support is mandatory at level 3). Since we already have 164 * support is mandatory at level 3). Since we already have
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index f49a62fc32d2..9644a8ea4aa7 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -1101,6 +1101,15 @@ UNUSUAL_DEV( 0x08bd, 0x1100, 0x0000, 0x0000,
1101 US_SC_DEVICE, US_PR_DEVICE, NULL, 1101 US_SC_DEVICE, US_PR_DEVICE, NULL,
1102 US_FL_SINGLE_LUN), 1102 US_FL_SINGLE_LUN),
1103 1103
1104/* Submitted by Dylan Taft <d13f00l@gmail.com>
1105 * US_FL_IGNORE_RESIDUE Needed
1106 */
1107UNUSUAL_DEV( 0x08ca, 0x3103, 0x0100, 0x0100,
1108 "AIPTEK",
1109 "Aiptek USB Keychain MP3 Player",
1110 US_SC_DEVICE, US_PR_DEVICE, NULL,
1111 US_FL_IGNORE_RESIDUE),
1112
1104/* Entry needed for flags. Moreover, all devices with this ID use 1113/* Entry needed for flags. Moreover, all devices with this ID use
1105 * bulk-only transport, but _some_ falsely report Control/Bulk instead. 1114 * bulk-only transport, but _some_ falsely report Control/Bulk instead.
1106 * One example is "Trumpion Digital Research MYMP3". 1115 * One example is "Trumpion Digital Research MYMP3".
@@ -1311,12 +1320,13 @@ UNUSUAL_DEV( 0x0fce, 0xd008, 0x0000, 0x0000,
1311 US_SC_DEVICE, US_PR_DEVICE, NULL, 1320 US_SC_DEVICE, US_PR_DEVICE, NULL,
1312 US_FL_NO_WP_DETECT ), 1321 US_FL_NO_WP_DETECT ),
1313 1322
1314/* Reported by Jan Mate <mate@fiit.stuba.sk> */ 1323/* Reported by Jan Mate <mate@fiit.stuba.sk>
1324 * and by Soeren Sonnenburg <kernel@nn7.de> */
1315UNUSUAL_DEV( 0x0fce, 0xe030, 0x0000, 0x0000, 1325UNUSUAL_DEV( 0x0fce, 0xe030, 0x0000, 0x0000,
1316 "Sony Ericsson", 1326 "Sony Ericsson",
1317 "P990i", 1327 "P990i",
1318 US_SC_DEVICE, US_PR_DEVICE, NULL, 1328 US_SC_DEVICE, US_PR_DEVICE, NULL,
1319 US_FL_FIX_CAPACITY ), 1329 US_FL_FIX_CAPACITY | US_FL_IGNORE_RESIDUE ),
1320 1330
1321/* Reported by Emmanuel Vasilakis <evas@forthnet.gr> */ 1331/* Reported by Emmanuel Vasilakis <evas@forthnet.gr> */
1322UNUSUAL_DEV( 0x0fce, 0xe031, 0x0000, 0x0000, 1332UNUSUAL_DEV( 0x0fce, 0xe031, 0x0000, 0x0000,
@@ -1385,6 +1395,16 @@ UNUSUAL_DEV( 0x1652, 0x6600, 0x0201, 0x0201,
1385 US_SC_DEVICE, US_PR_DEVICE, NULL, 1395 US_SC_DEVICE, US_PR_DEVICE, NULL,
1386 US_FL_IGNORE_RESIDUE ), 1396 US_FL_IGNORE_RESIDUE ),
1387 1397
1398/* Reported by Thomas Baechler <thomas@archlinux.org>
1399 * Fixes I/O errors with Teac HD-35PU devices
1400 */
1401
1402UNUSUAL_DEV( 0x1652, 0x6600, 0x0201, 0x0201,
1403 "Super Top",
1404 "USB 2.0 IDE DEVICE",
1405 US_SC_DEVICE, US_PR_DEVICE, NULL,
1406 US_FL_IGNORE_RESIDUE),
1407
1388/* patch submitted by Davide Perini <perini.davide@dpsoftware.org> 1408/* patch submitted by Davide Perini <perini.davide@dpsoftware.org>
1389 * and Renato Perini <rperini@email.it> 1409 * and Renato Perini <rperini@email.it>
1390 */ 1410 */
@@ -1423,7 +1443,7 @@ UNUSUAL_DEV( 0xed06, 0x4500, 0x0001, 0x0001,
1423 "DataStor", 1443 "DataStor",
1424 "USB4500 FW1.04", 1444 "USB4500 FW1.04",
1425 US_SC_DEVICE, US_PR_DEVICE, NULL, 1445 US_SC_DEVICE, US_PR_DEVICE, NULL,
1426 US_FL_FIX_CAPACITY), 1446 US_FL_CAPACITY_HEURISTICS),
1427 1447
1428/* Control/Bulk transport for all SubClass values */ 1448/* Control/Bulk transport for all SubClass values */
1429USUAL_DEV(US_SC_RBC, US_PR_CB, USB_US_TYPE_STOR), 1449USUAL_DEV(US_SC_RBC, US_PR_CB, USB_US_TYPE_STOR),
diff --git a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c
index 296b091cf168..46929a1b6f24 100644
--- a/drivers/usb/usb-skeleton.c
+++ b/drivers/usb/usb-skeleton.c
@@ -90,13 +90,15 @@ static int skel_open(struct inode *inode, struct file *file)
90 goto exit; 90 goto exit;
91 } 91 }
92 92
93 /* increment our usage count for the device */
94 kref_get(&dev->kref);
95
93 /* prevent the device from being autosuspended */ 96 /* prevent the device from being autosuspended */
94 retval = usb_autopm_get_interface(interface); 97 retval = usb_autopm_get_interface(interface);
95 if (retval) 98 if (retval) {
99 kref_put(&dev->kref, skel_delete);
96 goto exit; 100 goto exit;
97 101 }
98 /* increment our usage count for the device */
99 kref_get(&dev->kref);
100 102
101 /* save our object in the file's private structure */ 103 /* save our object in the file's private structure */
102 file->private_data = dev; 104 file->private_data = dev;