aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/char/amiserial.c1
-rw-r--r--drivers/char/esp.c1
-rw-r--r--drivers/char/generic_serial.c1
-rw-r--r--drivers/char/riscom8.c1
-rw-r--r--drivers/char/serial167.c1
-rw-r--r--drivers/char/specialix.c3
-rw-r--r--drivers/char/synclink.c1
-rw-r--r--drivers/infiniband/core/cm.c29
-rw-r--r--drivers/infiniband/core/device.c23
-rw-r--r--drivers/infiniband/core/sysfs.c22
-rw-r--r--drivers/infiniband/core/ucm.c23
-rw-r--r--drivers/infiniband/core/uverbs.h5
-rw-r--r--drivers/infiniband/core/uverbs_cmd.c152
-rw-r--r--drivers/infiniband/core/uverbs_main.c8
-rw-r--r--drivers/infiniband/hw/mthca/mthca_av.c10
-rw-r--r--drivers/infiniband/hw/mthca/mthca_cmd.c7
-rw-r--r--drivers/infiniband/hw/mthca/mthca_dev.h1
-rw-r--r--drivers/infiniband/hw/mthca/mthca_eq.c28
-rw-r--r--drivers/infiniband/hw/mthca/mthca_provider.c132
-rw-r--r--drivers/infiniband/hw/mthca/mthca_qp.c2
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib.h6
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_ib.c31
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_main.c12
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_multicast.c105
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_verbs.c8
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_vlan.c10
-rw-r--r--drivers/infiniband/ulp/srp/ib_srp.c23
-rw-r--r--drivers/input/mouse/alps.c38
-rw-r--r--drivers/input/mouse/logips2pp.c2
-rw-r--r--drivers/input/mouse/psmouse-base.c316
-rw-r--r--drivers/input/mouse/psmouse.h9
-rw-r--r--drivers/input/mouse/synaptics.c2
-rw-r--r--drivers/input/serio/i8042-x86ia64io.h7
-rw-r--r--drivers/macintosh/macio-adb.c13
-rw-r--r--drivers/sbus/char/aurora.c1
-rw-r--r--drivers/serial/68328serial.c1
-rw-r--r--drivers/usb/input/Kconfig10
-rw-r--r--drivers/usb/input/hid-core.c30
-rw-r--r--drivers/usb/input/hid-input.c179
-rw-r--r--drivers/usb/input/hid.h30
-rw-r--r--drivers/usb/input/pid.c2
-rw-r--r--drivers/usb/input/wacom.c14
-rw-r--r--drivers/usb/serial/pl2303.c2
43 files changed, 845 insertions, 457 deletions
diff --git a/drivers/char/amiserial.c b/drivers/char/amiserial.c
index 667a21c72edb..7ac365b5d9ec 100644
--- a/drivers/char/amiserial.c
+++ b/drivers/char/amiserial.c
@@ -129,7 +129,6 @@ static struct serial_state rs_table[1];
129 * memory if large numbers of serial ports are open. 129 * memory if large numbers of serial ports are open.
130 */ 130 */
131static unsigned char *tmp_buf; 131static unsigned char *tmp_buf;
132static DECLARE_MUTEX(tmp_buf_sem);
133 132
134#include <asm/uaccess.h> 133#include <asm/uaccess.h>
135 134
diff --git a/drivers/char/esp.c b/drivers/char/esp.c
index e469f641c728..dd5dc8fa490d 100644
--- a/drivers/char/esp.c
+++ b/drivers/char/esp.c
@@ -160,7 +160,6 @@ static void rs_wait_until_sent(struct tty_struct *, int);
160 * memory if large numbers of serial ports are open. 160 * memory if large numbers of serial ports are open.
161 */ 161 */
162static unsigned char *tmp_buf; 162static unsigned char *tmp_buf;
163static DECLARE_MUTEX(tmp_buf_sem);
164 163
165static inline int serial_paranoia_check(struct esp_struct *info, 164static inline int serial_paranoia_check(struct esp_struct *info,
166 char *name, const char *routine) 165 char *name, const char *routine)
diff --git a/drivers/char/generic_serial.c b/drivers/char/generic_serial.c
index 204a7302a4a9..e38a5f0e07bb 100644
--- a/drivers/char/generic_serial.c
+++ b/drivers/char/generic_serial.c
@@ -34,7 +34,6 @@
34#define DEBUG 34#define DEBUG
35 35
36static char * tmp_buf; 36static char * tmp_buf;
37static DECLARE_MUTEX(tmp_buf_sem);
38 37
39static int gs_debug; 38static int gs_debug;
40 39
diff --git a/drivers/char/riscom8.c b/drivers/char/riscom8.c
index 050e70ee5920..119e629656b7 100644
--- a/drivers/char/riscom8.c
+++ b/drivers/char/riscom8.c
@@ -82,7 +82,6 @@
82static struct riscom_board * IRQ_to_board[16]; 82static struct riscom_board * IRQ_to_board[16];
83static struct tty_driver *riscom_driver; 83static struct tty_driver *riscom_driver;
84static unsigned char * tmp_buf; 84static unsigned char * tmp_buf;
85static DECLARE_MUTEX(tmp_buf_sem);
86 85
87static unsigned long baud_table[] = { 86static unsigned long baud_table[] = {
88 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 87 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
diff --git a/drivers/char/serial167.c b/drivers/char/serial167.c
index f36342ae8e7e..037c940ac71b 100644
--- a/drivers/char/serial167.c
+++ b/drivers/char/serial167.c
@@ -129,7 +129,6 @@ struct cyclades_port cy_port[] = {
129 * memory if large numbers of serial ports are open. 129 * memory if large numbers of serial ports are open.
130 */ 130 */
131static unsigned char *tmp_buf = 0; 131static unsigned char *tmp_buf = 0;
132DECLARE_MUTEX(tmp_buf_sem);
133 132
134/* 133/*
135 * This is used to look up the divisor speeds and the timeouts 134 * This is used to look up the divisor speeds and the timeouts
diff --git a/drivers/char/specialix.c b/drivers/char/specialix.c
index 0a574bdbce36..5343e9fc6ab7 100644
--- a/drivers/char/specialix.c
+++ b/drivers/char/specialix.c
@@ -184,7 +184,6 @@ static int sx_poll = HZ;
184 184
185static struct tty_driver *specialix_driver; 185static struct tty_driver *specialix_driver;
186static unsigned char * tmp_buf; 186static unsigned char * tmp_buf;
187static DECLARE_MUTEX(tmp_buf_sem);
188 187
189static unsigned long baud_table[] = { 188static unsigned long baud_table[] = {
190 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 189 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
@@ -2556,8 +2555,6 @@ static int __init specialix_init_module(void)
2556 2555
2557 func_enter(); 2556 func_enter();
2558 2557
2559 init_MUTEX(&tmp_buf_sem); /* Init de the semaphore - pvdl */
2560
2561 if (iobase[0] || iobase[1] || iobase[2] || iobase[3]) { 2558 if (iobase[0] || iobase[1] || iobase[2] || iobase[3]) {
2562 for(i = 0; i < SX_NBOARD; i++) { 2559 for(i = 0; i < SX_NBOARD; i++) {
2563 sx_board[i].base = iobase[i]; 2560 sx_board[i].base = iobase[i];
diff --git a/drivers/char/synclink.c b/drivers/char/synclink.c
index 9f1b466c4f84..ede688a4e141 100644
--- a/drivers/char/synclink.c
+++ b/drivers/char/synclink.c
@@ -951,7 +951,6 @@ static void* mgsl_get_text_ptr(void)
951 * memory if large numbers of serial ports are open. 951 * memory if large numbers of serial ports are open.
952 */ 952 */
953static unsigned char *tmp_buf; 953static unsigned char *tmp_buf;
954static DECLARE_MUTEX(tmp_buf_sem);
955 954
956static inline int mgsl_paranoia_check(struct mgsl_struct *info, 955static inline int mgsl_paranoia_check(struct mgsl_struct *info,
957 char *name, const char *routine) 956 char *name, const char *routine)
diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
index 3a611fe5497e..c06b18102b6a 100644
--- a/drivers/infiniband/core/cm.c
+++ b/drivers/infiniband/core/cm.c
@@ -3163,22 +3163,6 @@ int ib_cm_init_qp_attr(struct ib_cm_id *cm_id,
3163} 3163}
3164EXPORT_SYMBOL(ib_cm_init_qp_attr); 3164EXPORT_SYMBOL(ib_cm_init_qp_attr);
3165 3165
3166static __be64 cm_get_ca_guid(struct ib_device *device)
3167{
3168 struct ib_device_attr *device_attr;
3169 __be64 guid;
3170 int ret;
3171
3172 device_attr = kmalloc(sizeof *device_attr, GFP_KERNEL);
3173 if (!device_attr)
3174 return 0;
3175
3176 ret = ib_query_device(device, device_attr);
3177 guid = ret ? 0 : device_attr->node_guid;
3178 kfree(device_attr);
3179 return guid;
3180}
3181
3182static void cm_add_one(struct ib_device *device) 3166static void cm_add_one(struct ib_device *device)
3183{ 3167{
3184 struct cm_device *cm_dev; 3168 struct cm_device *cm_dev;
@@ -3200,9 +3184,7 @@ static void cm_add_one(struct ib_device *device)
3200 return; 3184 return;
3201 3185
3202 cm_dev->device = device; 3186 cm_dev->device = device;
3203 cm_dev->ca_guid = cm_get_ca_guid(device); 3187 cm_dev->ca_guid = device->node_guid;
3204 if (!cm_dev->ca_guid)
3205 goto error1;
3206 3188
3207 set_bit(IB_MGMT_METHOD_SEND, reg_req.method_mask); 3189 set_bit(IB_MGMT_METHOD_SEND, reg_req.method_mask);
3208 for (i = 1; i <= device->phys_port_cnt; i++) { 3190 for (i = 1; i <= device->phys_port_cnt; i++) {
@@ -3217,11 +3199,11 @@ static void cm_add_one(struct ib_device *device)
3217 cm_recv_handler, 3199 cm_recv_handler,
3218 port); 3200 port);
3219 if (IS_ERR(port->mad_agent)) 3201 if (IS_ERR(port->mad_agent))
3220 goto error2; 3202 goto error1;
3221 3203
3222 ret = ib_modify_port(device, i, 0, &port_modify); 3204 ret = ib_modify_port(device, i, 0, &port_modify);
3223 if (ret) 3205 if (ret)
3224 goto error3; 3206 goto error2;
3225 } 3207 }
3226 ib_set_client_data(device, &cm_client, cm_dev); 3208 ib_set_client_data(device, &cm_client, cm_dev);
3227 3209
@@ -3230,9 +3212,9 @@ static void cm_add_one(struct ib_device *device)
3230 write_unlock_irqrestore(&cm.device_lock, flags); 3212 write_unlock_irqrestore(&cm.device_lock, flags);
3231 return; 3213 return;
3232 3214
3233error3:
3234 ib_unregister_mad_agent(port->mad_agent);
3235error2: 3215error2:
3216 ib_unregister_mad_agent(port->mad_agent);
3217error1:
3236 port_modify.set_port_cap_mask = 0; 3218 port_modify.set_port_cap_mask = 0;
3237 port_modify.clr_port_cap_mask = IB_PORT_CM_SUP; 3219 port_modify.clr_port_cap_mask = IB_PORT_CM_SUP;
3238 while (--i) { 3220 while (--i) {
@@ -3240,7 +3222,6 @@ error2:
3240 ib_modify_port(device, port->port_num, 0, &port_modify); 3222 ib_modify_port(device, port->port_num, 0, &port_modify);
3241 ib_unregister_mad_agent(port->mad_agent); 3223 ib_unregister_mad_agent(port->mad_agent);
3242 } 3224 }
3243error1:
3244 kfree(cm_dev); 3225 kfree(cm_dev);
3245} 3226}
3246 3227
diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
index e169e798354b..b2f3cb91d9bc 100644
--- a/drivers/infiniband/core/device.c
+++ b/drivers/infiniband/core/device.c
@@ -38,8 +38,7 @@
38#include <linux/errno.h> 38#include <linux/errno.h>
39#include <linux/slab.h> 39#include <linux/slab.h>
40#include <linux/init.h> 40#include <linux/init.h>
41 41#include <linux/mutex.h>
42#include <asm/semaphore.h>
43 42
44#include "core_priv.h" 43#include "core_priv.h"
45 44
@@ -57,13 +56,13 @@ static LIST_HEAD(device_list);
57static LIST_HEAD(client_list); 56static LIST_HEAD(client_list);
58 57
59/* 58/*
60 * device_sem protects access to both device_list and client_list. 59 * device_mutex protects access to both device_list and client_list.
61 * There's no real point to using multiple locks or something fancier 60 * There's no real point to using multiple locks or something fancier
62 * like an rwsem: we always access both lists, and we're always 61 * like an rwsem: we always access both lists, and we're always
63 * modifying one list or the other list. In any case this is not a 62 * modifying one list or the other list. In any case this is not a
64 * hot path so there's no point in trying to optimize. 63 * hot path so there's no point in trying to optimize.
65 */ 64 */
66static DECLARE_MUTEX(device_sem); 65static DEFINE_MUTEX(device_mutex);
67 66
68static int ib_device_check_mandatory(struct ib_device *device) 67static int ib_device_check_mandatory(struct ib_device *device)
69{ 68{
@@ -221,7 +220,7 @@ int ib_register_device(struct ib_device *device)
221{ 220{
222 int ret; 221 int ret;
223 222
224 down(&device_sem); 223 mutex_lock(&device_mutex);
225 224
226 if (strchr(device->name, '%')) { 225 if (strchr(device->name, '%')) {
227 ret = alloc_name(device->name); 226 ret = alloc_name(device->name);
@@ -259,7 +258,7 @@ int ib_register_device(struct ib_device *device)
259 } 258 }
260 259
261 out: 260 out:
262 up(&device_sem); 261 mutex_unlock(&device_mutex);
263 return ret; 262 return ret;
264} 263}
265EXPORT_SYMBOL(ib_register_device); 264EXPORT_SYMBOL(ib_register_device);
@@ -276,7 +275,7 @@ void ib_unregister_device(struct ib_device *device)
276 struct ib_client_data *context, *tmp; 275 struct ib_client_data *context, *tmp;
277 unsigned long flags; 276 unsigned long flags;
278 277
279 down(&device_sem); 278 mutex_lock(&device_mutex);
280 279
281 list_for_each_entry_reverse(client, &client_list, list) 280 list_for_each_entry_reverse(client, &client_list, list)
282 if (client->remove) 281 if (client->remove)
@@ -284,7 +283,7 @@ void ib_unregister_device(struct ib_device *device)
284 283
285 list_del(&device->core_list); 284 list_del(&device->core_list);
286 285
287 up(&device_sem); 286 mutex_unlock(&device_mutex);
288 287
289 spin_lock_irqsave(&device->client_data_lock, flags); 288 spin_lock_irqsave(&device->client_data_lock, flags);
290 list_for_each_entry_safe(context, tmp, &device->client_data_list, list) 289 list_for_each_entry_safe(context, tmp, &device->client_data_list, list)
@@ -312,14 +311,14 @@ int ib_register_client(struct ib_client *client)
312{ 311{
313 struct ib_device *device; 312 struct ib_device *device;
314 313
315 down(&device_sem); 314 mutex_lock(&device_mutex);
316 315
317 list_add_tail(&client->list, &client_list); 316 list_add_tail(&client->list, &client_list);
318 list_for_each_entry(device, &device_list, core_list) 317 list_for_each_entry(device, &device_list, core_list)
319 if (client->add && !add_client_context(device, client)) 318 if (client->add && !add_client_context(device, client))
320 client->add(device); 319 client->add(device);
321 320
322 up(&device_sem); 321 mutex_unlock(&device_mutex);
323 322
324 return 0; 323 return 0;
325} 324}
@@ -339,7 +338,7 @@ void ib_unregister_client(struct ib_client *client)
339 struct ib_device *device; 338 struct ib_device *device;
340 unsigned long flags; 339 unsigned long flags;
341 340
342 down(&device_sem); 341 mutex_lock(&device_mutex);
343 342
344 list_for_each_entry(device, &device_list, core_list) { 343 list_for_each_entry(device, &device_list, core_list) {
345 if (client->remove) 344 if (client->remove)
@@ -355,7 +354,7 @@ void ib_unregister_client(struct ib_client *client)
355 } 354 }
356 list_del(&client->list); 355 list_del(&client->list);
357 356
358 up(&device_sem); 357 mutex_unlock(&device_mutex);
359} 358}
360EXPORT_SYMBOL(ib_unregister_client); 359EXPORT_SYMBOL(ib_unregister_client);
361 360
diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
index 1f1743c5c9a3..5982d687a000 100644
--- a/drivers/infiniband/core/sysfs.c
+++ b/drivers/infiniband/core/sysfs.c
@@ -445,13 +445,7 @@ static int ib_device_uevent(struct class_device *cdev, char **envp,
445 return -ENOMEM; 445 return -ENOMEM;
446 446
447 /* 447 /*
448 * It might be nice to pass the node GUID with the event, but 448 * It would be nice to pass the node GUID with the event...
449 * right now the only way to get it is to query the device
450 * provider, and this can crash during device removal because
451 * we are will be running after driver removal has started.
452 * We could add a node_guid field to struct ib_device, or we
453 * could just let userspace read the node GUID from sysfs when
454 * devices are added.
455 */ 449 */
456 450
457 envp[i] = NULL; 451 envp[i] = NULL;
@@ -623,21 +617,15 @@ static ssize_t show_sys_image_guid(struct class_device *cdev, char *buf)
623static ssize_t show_node_guid(struct class_device *cdev, char *buf) 617static ssize_t show_node_guid(struct class_device *cdev, char *buf)
624{ 618{
625 struct ib_device *dev = container_of(cdev, struct ib_device, class_dev); 619 struct ib_device *dev = container_of(cdev, struct ib_device, class_dev);
626 struct ib_device_attr attr;
627 ssize_t ret;
628 620
629 if (!ibdev_is_alive(dev)) 621 if (!ibdev_is_alive(dev))
630 return -ENODEV; 622 return -ENODEV;
631 623
632 ret = ib_query_device(dev, &attr);
633 if (ret)
634 return ret;
635
636 return sprintf(buf, "%04x:%04x:%04x:%04x\n", 624 return sprintf(buf, "%04x:%04x:%04x:%04x\n",
637 be16_to_cpu(((__be16 *) &attr.node_guid)[0]), 625 be16_to_cpu(((__be16 *) &dev->node_guid)[0]),
638 be16_to_cpu(((__be16 *) &attr.node_guid)[1]), 626 be16_to_cpu(((__be16 *) &dev->node_guid)[1]),
639 be16_to_cpu(((__be16 *) &attr.node_guid)[2]), 627 be16_to_cpu(((__be16 *) &dev->node_guid)[2]),
640 be16_to_cpu(((__be16 *) &attr.node_guid)[3])); 628 be16_to_cpu(((__be16 *) &dev->node_guid)[3]));
641} 629}
642 630
643static CLASS_DEVICE_ATTR(node_type, S_IRUGO, show_node_type, NULL); 631static CLASS_DEVICE_ATTR(node_type, S_IRUGO, show_node_type, NULL);
diff --git a/drivers/infiniband/core/ucm.c b/drivers/infiniband/core/ucm.c
index 6e15787d1de1..e95c4293a496 100644
--- a/drivers/infiniband/core/ucm.c
+++ b/drivers/infiniband/core/ucm.c
@@ -42,6 +42,7 @@
42#include <linux/mount.h> 42#include <linux/mount.h>
43#include <linux/cdev.h> 43#include <linux/cdev.h>
44#include <linux/idr.h> 44#include <linux/idr.h>
45#include <linux/mutex.h>
45 46
46#include <asm/uaccess.h> 47#include <asm/uaccess.h>
47 48
@@ -113,7 +114,7 @@ static struct ib_client ucm_client = {
113 .remove = ib_ucm_remove_one 114 .remove = ib_ucm_remove_one
114}; 115};
115 116
116static DECLARE_MUTEX(ctx_id_mutex); 117static DEFINE_MUTEX(ctx_id_mutex);
117static DEFINE_IDR(ctx_id_table); 118static DEFINE_IDR(ctx_id_table);
118static DECLARE_BITMAP(dev_map, IB_UCM_MAX_DEVICES); 119static DECLARE_BITMAP(dev_map, IB_UCM_MAX_DEVICES);
119 120
@@ -121,7 +122,7 @@ static struct ib_ucm_context *ib_ucm_ctx_get(struct ib_ucm_file *file, int id)
121{ 122{
122 struct ib_ucm_context *ctx; 123 struct ib_ucm_context *ctx;
123 124
124 down(&ctx_id_mutex); 125 mutex_lock(&ctx_id_mutex);
125 ctx = idr_find(&ctx_id_table, id); 126 ctx = idr_find(&ctx_id_table, id);
126 if (!ctx) 127 if (!ctx)
127 ctx = ERR_PTR(-ENOENT); 128 ctx = ERR_PTR(-ENOENT);
@@ -129,7 +130,7 @@ static struct ib_ucm_context *ib_ucm_ctx_get(struct ib_ucm_file *file, int id)
129 ctx = ERR_PTR(-EINVAL); 130 ctx = ERR_PTR(-EINVAL);
130 else 131 else
131 atomic_inc(&ctx->ref); 132 atomic_inc(&ctx->ref);
132 up(&ctx_id_mutex); 133 mutex_unlock(&ctx_id_mutex);
133 134
134 return ctx; 135 return ctx;
135} 136}
@@ -186,9 +187,9 @@ static struct ib_ucm_context *ib_ucm_ctx_alloc(struct ib_ucm_file *file)
186 if (!result) 187 if (!result)
187 goto error; 188 goto error;
188 189
189 down(&ctx_id_mutex); 190 mutex_lock(&ctx_id_mutex);
190 result = idr_get_new(&ctx_id_table, ctx, &ctx->id); 191 result = idr_get_new(&ctx_id_table, ctx, &ctx->id);
191 up(&ctx_id_mutex); 192 mutex_unlock(&ctx_id_mutex);
192 } while (result == -EAGAIN); 193 } while (result == -EAGAIN);
193 194
194 if (result) 195 if (result)
@@ -550,9 +551,9 @@ static ssize_t ib_ucm_create_id(struct ib_ucm_file *file,
550err2: 551err2:
551 ib_destroy_cm_id(ctx->cm_id); 552 ib_destroy_cm_id(ctx->cm_id);
552err1: 553err1:
553 down(&ctx_id_mutex); 554 mutex_lock(&ctx_id_mutex);
554 idr_remove(&ctx_id_table, ctx->id); 555 idr_remove(&ctx_id_table, ctx->id);
555 up(&ctx_id_mutex); 556 mutex_unlock(&ctx_id_mutex);
556 kfree(ctx); 557 kfree(ctx);
557 return result; 558 return result;
558} 559}
@@ -572,7 +573,7 @@ static ssize_t ib_ucm_destroy_id(struct ib_ucm_file *file,
572 if (copy_from_user(&cmd, inbuf, sizeof(cmd))) 573 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
573 return -EFAULT; 574 return -EFAULT;
574 575
575 down(&ctx_id_mutex); 576 mutex_lock(&ctx_id_mutex);
576 ctx = idr_find(&ctx_id_table, cmd.id); 577 ctx = idr_find(&ctx_id_table, cmd.id);
577 if (!ctx) 578 if (!ctx)
578 ctx = ERR_PTR(-ENOENT); 579 ctx = ERR_PTR(-ENOENT);
@@ -580,7 +581,7 @@ static ssize_t ib_ucm_destroy_id(struct ib_ucm_file *file,
580 ctx = ERR_PTR(-EINVAL); 581 ctx = ERR_PTR(-EINVAL);
581 else 582 else
582 idr_remove(&ctx_id_table, ctx->id); 583 idr_remove(&ctx_id_table, ctx->id);
583 up(&ctx_id_mutex); 584 mutex_unlock(&ctx_id_mutex);
584 585
585 if (IS_ERR(ctx)) 586 if (IS_ERR(ctx))
586 return PTR_ERR(ctx); 587 return PTR_ERR(ctx);
@@ -1280,9 +1281,9 @@ static int ib_ucm_close(struct inode *inode, struct file *filp)
1280 struct ib_ucm_context, file_list); 1281 struct ib_ucm_context, file_list);
1281 up(&file->mutex); 1282 up(&file->mutex);
1282 1283
1283 down(&ctx_id_mutex); 1284 mutex_lock(&ctx_id_mutex);
1284 idr_remove(&ctx_id_table, ctx->id); 1285 idr_remove(&ctx_id_table, ctx->id);
1285 up(&ctx_id_mutex); 1286 mutex_unlock(&ctx_id_mutex);
1286 1287
1287 ib_destroy_cm_id(ctx->cm_id); 1288 ib_destroy_cm_id(ctx->cm_id);
1288 ib_ucm_cleanup_events(ctx); 1289 ib_ucm_cleanup_events(ctx);
diff --git a/drivers/infiniband/core/uverbs.h b/drivers/infiniband/core/uverbs.h
index 7114e3fbab00..f7eecbc6af6c 100644
--- a/drivers/infiniband/core/uverbs.h
+++ b/drivers/infiniband/core/uverbs.h
@@ -41,6 +41,7 @@
41 41
42#include <linux/kref.h> 42#include <linux/kref.h>
43#include <linux/idr.h> 43#include <linux/idr.h>
44#include <linux/mutex.h>
44 45
45#include <rdma/ib_verbs.h> 46#include <rdma/ib_verbs.h>
46#include <rdma/ib_user_verbs.h> 47#include <rdma/ib_user_verbs.h>
@@ -88,7 +89,7 @@ struct ib_uverbs_event_file {
88 89
89struct ib_uverbs_file { 90struct ib_uverbs_file {
90 struct kref ref; 91 struct kref ref;
91 struct semaphore mutex; 92 struct mutex mutex;
92 struct ib_uverbs_device *device; 93 struct ib_uverbs_device *device;
93 struct ib_ucontext *ucontext; 94 struct ib_ucontext *ucontext;
94 struct ib_event_handler event_handler; 95 struct ib_event_handler event_handler;
@@ -131,7 +132,7 @@ struct ib_ucq_object {
131 u32 async_events_reported; 132 u32 async_events_reported;
132}; 133};
133 134
134extern struct semaphore ib_uverbs_idr_mutex; 135extern struct mutex ib_uverbs_idr_mutex;
135extern struct idr ib_uverbs_pd_idr; 136extern struct idr ib_uverbs_pd_idr;
136extern struct idr ib_uverbs_mr_idr; 137extern struct idr ib_uverbs_mr_idr;
137extern struct idr ib_uverbs_mw_idr; 138extern struct idr ib_uverbs_mw_idr;
diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c
index a02c5a05c984..407b6284d7d5 100644
--- a/drivers/infiniband/core/uverbs_cmd.c
+++ b/drivers/infiniband/core/uverbs_cmd.c
@@ -67,7 +67,7 @@ ssize_t ib_uverbs_get_context(struct ib_uverbs_file *file,
67 if (copy_from_user(&cmd, buf, sizeof cmd)) 67 if (copy_from_user(&cmd, buf, sizeof cmd))
68 return -EFAULT; 68 return -EFAULT;
69 69
70 down(&file->mutex); 70 mutex_lock(&file->mutex);
71 71
72 if (file->ucontext) { 72 if (file->ucontext) {
73 ret = -EINVAL; 73 ret = -EINVAL;
@@ -119,7 +119,7 @@ ssize_t ib_uverbs_get_context(struct ib_uverbs_file *file,
119 119
120 fd_install(resp.async_fd, filp); 120 fd_install(resp.async_fd, filp);
121 121
122 up(&file->mutex); 122 mutex_unlock(&file->mutex);
123 123
124 return in_len; 124 return in_len;
125 125
@@ -131,7 +131,7 @@ err_free:
131 ibdev->dealloc_ucontext(ucontext); 131 ibdev->dealloc_ucontext(ucontext);
132 132
133err: 133err:
134 up(&file->mutex); 134 mutex_unlock(&file->mutex);
135 return ret; 135 return ret;
136} 136}
137 137
@@ -157,7 +157,7 @@ ssize_t ib_uverbs_query_device(struct ib_uverbs_file *file,
157 memset(&resp, 0, sizeof resp); 157 memset(&resp, 0, sizeof resp);
158 158
159 resp.fw_ver = attr.fw_ver; 159 resp.fw_ver = attr.fw_ver;
160 resp.node_guid = attr.node_guid; 160 resp.node_guid = file->device->ib_dev->node_guid;
161 resp.sys_image_guid = attr.sys_image_guid; 161 resp.sys_image_guid = attr.sys_image_guid;
162 resp.max_mr_size = attr.max_mr_size; 162 resp.max_mr_size = attr.max_mr_size;
163 resp.page_size_cap = attr.page_size_cap; 163 resp.page_size_cap = attr.page_size_cap;
@@ -290,7 +290,7 @@ ssize_t ib_uverbs_alloc_pd(struct ib_uverbs_file *file,
290 pd->uobject = uobj; 290 pd->uobject = uobj;
291 atomic_set(&pd->usecnt, 0); 291 atomic_set(&pd->usecnt, 0);
292 292
293 down(&ib_uverbs_idr_mutex); 293 mutex_lock(&ib_uverbs_idr_mutex);
294 294
295retry: 295retry:
296 if (!idr_pre_get(&ib_uverbs_pd_idr, GFP_KERNEL)) { 296 if (!idr_pre_get(&ib_uverbs_pd_idr, GFP_KERNEL)) {
@@ -314,11 +314,11 @@ retry:
314 goto err_idr; 314 goto err_idr;
315 } 315 }
316 316
317 down(&file->mutex); 317 mutex_lock(&file->mutex);
318 list_add_tail(&uobj->list, &file->ucontext->pd_list); 318 list_add_tail(&uobj->list, &file->ucontext->pd_list);
319 up(&file->mutex); 319 mutex_unlock(&file->mutex);
320 320
321 up(&ib_uverbs_idr_mutex); 321 mutex_unlock(&ib_uverbs_idr_mutex);
322 322
323 return in_len; 323 return in_len;
324 324
@@ -326,7 +326,7 @@ err_idr:
326 idr_remove(&ib_uverbs_pd_idr, uobj->id); 326 idr_remove(&ib_uverbs_pd_idr, uobj->id);
327 327
328err_up: 328err_up:
329 up(&ib_uverbs_idr_mutex); 329 mutex_unlock(&ib_uverbs_idr_mutex);
330 ib_dealloc_pd(pd); 330 ib_dealloc_pd(pd);
331 331
332err: 332err:
@@ -346,7 +346,7 @@ ssize_t ib_uverbs_dealloc_pd(struct ib_uverbs_file *file,
346 if (copy_from_user(&cmd, buf, sizeof cmd)) 346 if (copy_from_user(&cmd, buf, sizeof cmd))
347 return -EFAULT; 347 return -EFAULT;
348 348
349 down(&ib_uverbs_idr_mutex); 349 mutex_lock(&ib_uverbs_idr_mutex);
350 350
351 pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle); 351 pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle);
352 if (!pd || pd->uobject->context != file->ucontext) 352 if (!pd || pd->uobject->context != file->ucontext)
@@ -360,14 +360,14 @@ ssize_t ib_uverbs_dealloc_pd(struct ib_uverbs_file *file,
360 360
361 idr_remove(&ib_uverbs_pd_idr, cmd.pd_handle); 361 idr_remove(&ib_uverbs_pd_idr, cmd.pd_handle);
362 362
363 down(&file->mutex); 363 mutex_lock(&file->mutex);
364 list_del(&uobj->list); 364 list_del(&uobj->list);
365 up(&file->mutex); 365 mutex_unlock(&file->mutex);
366 366
367 kfree(uobj); 367 kfree(uobj);
368 368
369out: 369out:
370 up(&ib_uverbs_idr_mutex); 370 mutex_unlock(&ib_uverbs_idr_mutex);
371 371
372 return ret ? ret : in_len; 372 return ret ? ret : in_len;
373} 373}
@@ -426,7 +426,7 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file,
426 426
427 obj->umem.virt_base = cmd.hca_va; 427 obj->umem.virt_base = cmd.hca_va;
428 428
429 down(&ib_uverbs_idr_mutex); 429 mutex_lock(&ib_uverbs_idr_mutex);
430 430
431 pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle); 431 pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle);
432 if (!pd || pd->uobject->context != file->ucontext) { 432 if (!pd || pd->uobject->context != file->ucontext) {
@@ -476,11 +476,11 @@ retry:
476 goto err_idr; 476 goto err_idr;
477 } 477 }
478 478
479 down(&file->mutex); 479 mutex_lock(&file->mutex);
480 list_add_tail(&obj->uobject.list, &file->ucontext->mr_list); 480 list_add_tail(&obj->uobject.list, &file->ucontext->mr_list);
481 up(&file->mutex); 481 mutex_unlock(&file->mutex);
482 482
483 up(&ib_uverbs_idr_mutex); 483 mutex_unlock(&ib_uverbs_idr_mutex);
484 484
485 return in_len; 485 return in_len;
486 486
@@ -492,7 +492,7 @@ err_unreg:
492 atomic_dec(&pd->usecnt); 492 atomic_dec(&pd->usecnt);
493 493
494err_up: 494err_up:
495 up(&ib_uverbs_idr_mutex); 495 mutex_unlock(&ib_uverbs_idr_mutex);
496 496
497 ib_umem_release(file->device->ib_dev, &obj->umem); 497 ib_umem_release(file->device->ib_dev, &obj->umem);
498 498
@@ -513,7 +513,7 @@ ssize_t ib_uverbs_dereg_mr(struct ib_uverbs_file *file,
513 if (copy_from_user(&cmd, buf, sizeof cmd)) 513 if (copy_from_user(&cmd, buf, sizeof cmd))
514 return -EFAULT; 514 return -EFAULT;
515 515
516 down(&ib_uverbs_idr_mutex); 516 mutex_lock(&ib_uverbs_idr_mutex);
517 517
518 mr = idr_find(&ib_uverbs_mr_idr, cmd.mr_handle); 518 mr = idr_find(&ib_uverbs_mr_idr, cmd.mr_handle);
519 if (!mr || mr->uobject->context != file->ucontext) 519 if (!mr || mr->uobject->context != file->ucontext)
@@ -527,15 +527,15 @@ ssize_t ib_uverbs_dereg_mr(struct ib_uverbs_file *file,
527 527
528 idr_remove(&ib_uverbs_mr_idr, cmd.mr_handle); 528 idr_remove(&ib_uverbs_mr_idr, cmd.mr_handle);
529 529
530 down(&file->mutex); 530 mutex_lock(&file->mutex);
531 list_del(&memobj->uobject.list); 531 list_del(&memobj->uobject.list);
532 up(&file->mutex); 532 mutex_unlock(&file->mutex);
533 533
534 ib_umem_release(file->device->ib_dev, &memobj->umem); 534 ib_umem_release(file->device->ib_dev, &memobj->umem);
535 kfree(memobj); 535 kfree(memobj);
536 536
537out: 537out:
538 up(&ib_uverbs_idr_mutex); 538 mutex_unlock(&ib_uverbs_idr_mutex);
539 539
540 return ret ? ret : in_len; 540 return ret ? ret : in_len;
541} 541}
@@ -628,7 +628,7 @@ ssize_t ib_uverbs_create_cq(struct ib_uverbs_file *file,
628 cq->cq_context = ev_file; 628 cq->cq_context = ev_file;
629 atomic_set(&cq->usecnt, 0); 629 atomic_set(&cq->usecnt, 0);
630 630
631 down(&ib_uverbs_idr_mutex); 631 mutex_lock(&ib_uverbs_idr_mutex);
632 632
633retry: 633retry:
634 if (!idr_pre_get(&ib_uverbs_cq_idr, GFP_KERNEL)) { 634 if (!idr_pre_get(&ib_uverbs_cq_idr, GFP_KERNEL)) {
@@ -653,11 +653,11 @@ retry:
653 goto err_idr; 653 goto err_idr;
654 } 654 }
655 655
656 down(&file->mutex); 656 mutex_lock(&file->mutex);
657 list_add_tail(&uobj->uobject.list, &file->ucontext->cq_list); 657 list_add_tail(&uobj->uobject.list, &file->ucontext->cq_list);
658 up(&file->mutex); 658 mutex_unlock(&file->mutex);
659 659
660 up(&ib_uverbs_idr_mutex); 660 mutex_unlock(&ib_uverbs_idr_mutex);
661 661
662 return in_len; 662 return in_len;
663 663
@@ -665,7 +665,7 @@ err_idr:
665 idr_remove(&ib_uverbs_cq_idr, uobj->uobject.id); 665 idr_remove(&ib_uverbs_cq_idr, uobj->uobject.id);
666 666
667err_up: 667err_up:
668 up(&ib_uverbs_idr_mutex); 668 mutex_unlock(&ib_uverbs_idr_mutex);
669 ib_destroy_cq(cq); 669 ib_destroy_cq(cq);
670 670
671err: 671err:
@@ -701,7 +701,7 @@ ssize_t ib_uverbs_poll_cq(struct ib_uverbs_file *file,
701 goto out_wc; 701 goto out_wc;
702 } 702 }
703 703
704 down(&ib_uverbs_idr_mutex); 704 mutex_lock(&ib_uverbs_idr_mutex);
705 cq = idr_find(&ib_uverbs_cq_idr, cmd.cq_handle); 705 cq = idr_find(&ib_uverbs_cq_idr, cmd.cq_handle);
706 if (!cq || cq->uobject->context != file->ucontext) { 706 if (!cq || cq->uobject->context != file->ucontext) {
707 ret = -EINVAL; 707 ret = -EINVAL;
@@ -731,7 +731,7 @@ ssize_t ib_uverbs_poll_cq(struct ib_uverbs_file *file,
731 ret = -EFAULT; 731 ret = -EFAULT;
732 732
733out: 733out:
734 up(&ib_uverbs_idr_mutex); 734 mutex_unlock(&ib_uverbs_idr_mutex);
735 kfree(resp); 735 kfree(resp);
736 736
737out_wc: 737out_wc:
@@ -750,14 +750,14 @@ ssize_t ib_uverbs_req_notify_cq(struct ib_uverbs_file *file,
750 if (copy_from_user(&cmd, buf, sizeof cmd)) 750 if (copy_from_user(&cmd, buf, sizeof cmd))
751 return -EFAULT; 751 return -EFAULT;
752 752
753 down(&ib_uverbs_idr_mutex); 753 mutex_lock(&ib_uverbs_idr_mutex);
754 cq = idr_find(&ib_uverbs_cq_idr, cmd.cq_handle); 754 cq = idr_find(&ib_uverbs_cq_idr, cmd.cq_handle);
755 if (cq && cq->uobject->context == file->ucontext) { 755 if (cq && cq->uobject->context == file->ucontext) {
756 ib_req_notify_cq(cq, cmd.solicited_only ? 756 ib_req_notify_cq(cq, cmd.solicited_only ?
757 IB_CQ_SOLICITED : IB_CQ_NEXT_COMP); 757 IB_CQ_SOLICITED : IB_CQ_NEXT_COMP);
758 ret = in_len; 758 ret = in_len;
759 } 759 }
760 up(&ib_uverbs_idr_mutex); 760 mutex_unlock(&ib_uverbs_idr_mutex);
761 761
762 return ret; 762 return ret;
763} 763}
@@ -779,7 +779,7 @@ ssize_t ib_uverbs_destroy_cq(struct ib_uverbs_file *file,
779 779
780 memset(&resp, 0, sizeof resp); 780 memset(&resp, 0, sizeof resp);
781 781
782 down(&ib_uverbs_idr_mutex); 782 mutex_lock(&ib_uverbs_idr_mutex);
783 783
784 cq = idr_find(&ib_uverbs_cq_idr, cmd.cq_handle); 784 cq = idr_find(&ib_uverbs_cq_idr, cmd.cq_handle);
785 if (!cq || cq->uobject->context != file->ucontext) 785 if (!cq || cq->uobject->context != file->ucontext)
@@ -795,9 +795,9 @@ ssize_t ib_uverbs_destroy_cq(struct ib_uverbs_file *file,
795 795
796 idr_remove(&ib_uverbs_cq_idr, cmd.cq_handle); 796 idr_remove(&ib_uverbs_cq_idr, cmd.cq_handle);
797 797
798 down(&file->mutex); 798 mutex_lock(&file->mutex);
799 list_del(&uobj->uobject.list); 799 list_del(&uobj->uobject.list);
800 up(&file->mutex); 800 mutex_unlock(&file->mutex);
801 801
802 ib_uverbs_release_ucq(file, ev_file, uobj); 802 ib_uverbs_release_ucq(file, ev_file, uobj);
803 803
@@ -811,7 +811,7 @@ ssize_t ib_uverbs_destroy_cq(struct ib_uverbs_file *file,
811 ret = -EFAULT; 811 ret = -EFAULT;
812 812
813out: 813out:
814 up(&ib_uverbs_idr_mutex); 814 mutex_unlock(&ib_uverbs_idr_mutex);
815 815
816 return ret ? ret : in_len; 816 return ret ? ret : in_len;
817} 817}
@@ -845,7 +845,7 @@ ssize_t ib_uverbs_create_qp(struct ib_uverbs_file *file,
845 if (!uobj) 845 if (!uobj)
846 return -ENOMEM; 846 return -ENOMEM;
847 847
848 down(&ib_uverbs_idr_mutex); 848 mutex_lock(&ib_uverbs_idr_mutex);
849 849
850 pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle); 850 pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle);
851 scq = idr_find(&ib_uverbs_cq_idr, cmd.send_cq_handle); 851 scq = idr_find(&ib_uverbs_cq_idr, cmd.send_cq_handle);
@@ -930,11 +930,11 @@ retry:
930 goto err_idr; 930 goto err_idr;
931 } 931 }
932 932
933 down(&file->mutex); 933 mutex_lock(&file->mutex);
934 list_add_tail(&uobj->uevent.uobject.list, &file->ucontext->qp_list); 934 list_add_tail(&uobj->uevent.uobject.list, &file->ucontext->qp_list);
935 up(&file->mutex); 935 mutex_unlock(&file->mutex);
936 936
937 up(&ib_uverbs_idr_mutex); 937 mutex_unlock(&ib_uverbs_idr_mutex);
938 938
939 return in_len; 939 return in_len;
940 940
@@ -950,7 +950,7 @@ err_destroy:
950 atomic_dec(&attr.srq->usecnt); 950 atomic_dec(&attr.srq->usecnt);
951 951
952err_up: 952err_up:
953 up(&ib_uverbs_idr_mutex); 953 mutex_unlock(&ib_uverbs_idr_mutex);
954 954
955 kfree(uobj); 955 kfree(uobj);
956 return ret; 956 return ret;
@@ -972,7 +972,7 @@ ssize_t ib_uverbs_modify_qp(struct ib_uverbs_file *file,
972 if (!attr) 972 if (!attr)
973 return -ENOMEM; 973 return -ENOMEM;
974 974
975 down(&ib_uverbs_idr_mutex); 975 mutex_lock(&ib_uverbs_idr_mutex);
976 976
977 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle); 977 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle);
978 if (!qp || qp->uobject->context != file->ucontext) { 978 if (!qp || qp->uobject->context != file->ucontext) {
@@ -1033,7 +1033,7 @@ ssize_t ib_uverbs_modify_qp(struct ib_uverbs_file *file,
1033 ret = in_len; 1033 ret = in_len;
1034 1034
1035out: 1035out:
1036 up(&ib_uverbs_idr_mutex); 1036 mutex_unlock(&ib_uverbs_idr_mutex);
1037 kfree(attr); 1037 kfree(attr);
1038 1038
1039 return ret; 1039 return ret;
@@ -1054,7 +1054,7 @@ ssize_t ib_uverbs_destroy_qp(struct ib_uverbs_file *file,
1054 1054
1055 memset(&resp, 0, sizeof resp); 1055 memset(&resp, 0, sizeof resp);
1056 1056
1057 down(&ib_uverbs_idr_mutex); 1057 mutex_lock(&ib_uverbs_idr_mutex);
1058 1058
1059 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle); 1059 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle);
1060 if (!qp || qp->uobject->context != file->ucontext) 1060 if (!qp || qp->uobject->context != file->ucontext)
@@ -1073,9 +1073,9 @@ ssize_t ib_uverbs_destroy_qp(struct ib_uverbs_file *file,
1073 1073
1074 idr_remove(&ib_uverbs_qp_idr, cmd.qp_handle); 1074 idr_remove(&ib_uverbs_qp_idr, cmd.qp_handle);
1075 1075
1076 down(&file->mutex); 1076 mutex_lock(&file->mutex);
1077 list_del(&uobj->uevent.uobject.list); 1077 list_del(&uobj->uevent.uobject.list);
1078 up(&file->mutex); 1078 mutex_unlock(&file->mutex);
1079 1079
1080 ib_uverbs_release_uevent(file, &uobj->uevent); 1080 ib_uverbs_release_uevent(file, &uobj->uevent);
1081 1081
@@ -1088,7 +1088,7 @@ ssize_t ib_uverbs_destroy_qp(struct ib_uverbs_file *file,
1088 ret = -EFAULT; 1088 ret = -EFAULT;
1089 1089
1090out: 1090out:
1091 up(&ib_uverbs_idr_mutex); 1091 mutex_unlock(&ib_uverbs_idr_mutex);
1092 1092
1093 return ret ? ret : in_len; 1093 return ret ? ret : in_len;
1094} 1094}
@@ -1119,7 +1119,7 @@ ssize_t ib_uverbs_post_send(struct ib_uverbs_file *file,
1119 if (!user_wr) 1119 if (!user_wr)
1120 return -ENOMEM; 1120 return -ENOMEM;
1121 1121
1122 down(&ib_uverbs_idr_mutex); 1122 mutex_lock(&ib_uverbs_idr_mutex);
1123 1123
1124 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle); 1124 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle);
1125 if (!qp || qp->uobject->context != file->ucontext) 1125 if (!qp || qp->uobject->context != file->ucontext)
@@ -1224,7 +1224,7 @@ ssize_t ib_uverbs_post_send(struct ib_uverbs_file *file,
1224 ret = -EFAULT; 1224 ret = -EFAULT;
1225 1225
1226out: 1226out:
1227 up(&ib_uverbs_idr_mutex); 1227 mutex_unlock(&ib_uverbs_idr_mutex);
1228 1228
1229 while (wr) { 1229 while (wr) {
1230 next = wr->next; 1230 next = wr->next;
@@ -1341,7 +1341,7 @@ ssize_t ib_uverbs_post_recv(struct ib_uverbs_file *file,
1341 if (IS_ERR(wr)) 1341 if (IS_ERR(wr))
1342 return PTR_ERR(wr); 1342 return PTR_ERR(wr);
1343 1343
1344 down(&ib_uverbs_idr_mutex); 1344 mutex_lock(&ib_uverbs_idr_mutex);
1345 1345
1346 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle); 1346 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle);
1347 if (!qp || qp->uobject->context != file->ucontext) 1347 if (!qp || qp->uobject->context != file->ucontext)
@@ -1362,7 +1362,7 @@ ssize_t ib_uverbs_post_recv(struct ib_uverbs_file *file,
1362 ret = -EFAULT; 1362 ret = -EFAULT;
1363 1363
1364out: 1364out:
1365 up(&ib_uverbs_idr_mutex); 1365 mutex_unlock(&ib_uverbs_idr_mutex);
1366 1366
1367 while (wr) { 1367 while (wr) {
1368 next = wr->next; 1368 next = wr->next;
@@ -1392,7 +1392,7 @@ ssize_t ib_uverbs_post_srq_recv(struct ib_uverbs_file *file,
1392 if (IS_ERR(wr)) 1392 if (IS_ERR(wr))
1393 return PTR_ERR(wr); 1393 return PTR_ERR(wr);
1394 1394
1395 down(&ib_uverbs_idr_mutex); 1395 mutex_lock(&ib_uverbs_idr_mutex);
1396 1396
1397 srq = idr_find(&ib_uverbs_srq_idr, cmd.srq_handle); 1397 srq = idr_find(&ib_uverbs_srq_idr, cmd.srq_handle);
1398 if (!srq || srq->uobject->context != file->ucontext) 1398 if (!srq || srq->uobject->context != file->ucontext)
@@ -1413,7 +1413,7 @@ ssize_t ib_uverbs_post_srq_recv(struct ib_uverbs_file *file,
1413 ret = -EFAULT; 1413 ret = -EFAULT;
1414 1414
1415out: 1415out:
1416 up(&ib_uverbs_idr_mutex); 1416 mutex_unlock(&ib_uverbs_idr_mutex);
1417 1417
1418 while (wr) { 1418 while (wr) {
1419 next = wr->next; 1419 next = wr->next;
@@ -1446,7 +1446,7 @@ ssize_t ib_uverbs_create_ah(struct ib_uverbs_file *file,
1446 if (!uobj) 1446 if (!uobj)
1447 return -ENOMEM; 1447 return -ENOMEM;
1448 1448
1449 down(&ib_uverbs_idr_mutex); 1449 mutex_lock(&ib_uverbs_idr_mutex);
1450 1450
1451 pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle); 1451 pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle);
1452 if (!pd || pd->uobject->context != file->ucontext) { 1452 if (!pd || pd->uobject->context != file->ucontext) {
@@ -1498,11 +1498,11 @@ retry:
1498 goto err_idr; 1498 goto err_idr;
1499 } 1499 }
1500 1500
1501 down(&file->mutex); 1501 mutex_lock(&file->mutex);
1502 list_add_tail(&uobj->list, &file->ucontext->ah_list); 1502 list_add_tail(&uobj->list, &file->ucontext->ah_list);
1503 up(&file->mutex); 1503 mutex_unlock(&file->mutex);
1504 1504
1505 up(&ib_uverbs_idr_mutex); 1505 mutex_unlock(&ib_uverbs_idr_mutex);
1506 1506
1507 return in_len; 1507 return in_len;
1508 1508
@@ -1513,7 +1513,7 @@ err_destroy:
1513 ib_destroy_ah(ah); 1513 ib_destroy_ah(ah);
1514 1514
1515err_up: 1515err_up:
1516 up(&ib_uverbs_idr_mutex); 1516 mutex_unlock(&ib_uverbs_idr_mutex);
1517 1517
1518 kfree(uobj); 1518 kfree(uobj);
1519 return ret; 1519 return ret;
@@ -1530,7 +1530,7 @@ ssize_t ib_uverbs_destroy_ah(struct ib_uverbs_file *file,
1530 if (copy_from_user(&cmd, buf, sizeof cmd)) 1530 if (copy_from_user(&cmd, buf, sizeof cmd))
1531 return -EFAULT; 1531 return -EFAULT;
1532 1532
1533 down(&ib_uverbs_idr_mutex); 1533 mutex_lock(&ib_uverbs_idr_mutex);
1534 1534
1535 ah = idr_find(&ib_uverbs_ah_idr, cmd.ah_handle); 1535 ah = idr_find(&ib_uverbs_ah_idr, cmd.ah_handle);
1536 if (!ah || ah->uobject->context != file->ucontext) 1536 if (!ah || ah->uobject->context != file->ucontext)
@@ -1544,14 +1544,14 @@ ssize_t ib_uverbs_destroy_ah(struct ib_uverbs_file *file,
1544 1544
1545 idr_remove(&ib_uverbs_ah_idr, cmd.ah_handle); 1545 idr_remove(&ib_uverbs_ah_idr, cmd.ah_handle);
1546 1546
1547 down(&file->mutex); 1547 mutex_lock(&file->mutex);
1548 list_del(&uobj->list); 1548 list_del(&uobj->list);
1549 up(&file->mutex); 1549 mutex_unlock(&file->mutex);
1550 1550
1551 kfree(uobj); 1551 kfree(uobj);
1552 1552
1553out: 1553out:
1554 up(&ib_uverbs_idr_mutex); 1554 mutex_unlock(&ib_uverbs_idr_mutex);
1555 1555
1556 return ret ? ret : in_len; 1556 return ret ? ret : in_len;
1557} 1557}
@@ -1569,7 +1569,7 @@ ssize_t ib_uverbs_attach_mcast(struct ib_uverbs_file *file,
1569 if (copy_from_user(&cmd, buf, sizeof cmd)) 1569 if (copy_from_user(&cmd, buf, sizeof cmd))
1570 return -EFAULT; 1570 return -EFAULT;
1571 1571
1572 down(&ib_uverbs_idr_mutex); 1572 mutex_lock(&ib_uverbs_idr_mutex);
1573 1573
1574 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle); 1574 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle);
1575 if (!qp || qp->uobject->context != file->ucontext) 1575 if (!qp || qp->uobject->context != file->ucontext)
@@ -1602,7 +1602,7 @@ ssize_t ib_uverbs_attach_mcast(struct ib_uverbs_file *file,
1602 kfree(mcast); 1602 kfree(mcast);
1603 1603
1604out: 1604out:
1605 up(&ib_uverbs_idr_mutex); 1605 mutex_unlock(&ib_uverbs_idr_mutex);
1606 1606
1607 return ret ? ret : in_len; 1607 return ret ? ret : in_len;
1608} 1608}
@@ -1620,7 +1620,7 @@ ssize_t ib_uverbs_detach_mcast(struct ib_uverbs_file *file,
1620 if (copy_from_user(&cmd, buf, sizeof cmd)) 1620 if (copy_from_user(&cmd, buf, sizeof cmd))
1621 return -EFAULT; 1621 return -EFAULT;
1622 1622
1623 down(&ib_uverbs_idr_mutex); 1623 mutex_lock(&ib_uverbs_idr_mutex);
1624 1624
1625 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle); 1625 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle);
1626 if (!qp || qp->uobject->context != file->ucontext) 1626 if (!qp || qp->uobject->context != file->ucontext)
@@ -1641,7 +1641,7 @@ ssize_t ib_uverbs_detach_mcast(struct ib_uverbs_file *file,
1641 } 1641 }
1642 1642
1643out: 1643out:
1644 up(&ib_uverbs_idr_mutex); 1644 mutex_unlock(&ib_uverbs_idr_mutex);
1645 1645
1646 return ret ? ret : in_len; 1646 return ret ? ret : in_len;
1647} 1647}
@@ -1673,7 +1673,7 @@ ssize_t ib_uverbs_create_srq(struct ib_uverbs_file *file,
1673 if (!uobj) 1673 if (!uobj)
1674 return -ENOMEM; 1674 return -ENOMEM;
1675 1675
1676 down(&ib_uverbs_idr_mutex); 1676 mutex_lock(&ib_uverbs_idr_mutex);
1677 1677
1678 pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle); 1678 pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle);
1679 1679
@@ -1730,11 +1730,11 @@ retry:
1730 goto err_idr; 1730 goto err_idr;
1731 } 1731 }
1732 1732
1733 down(&file->mutex); 1733 mutex_lock(&file->mutex);
1734 list_add_tail(&uobj->uobject.list, &file->ucontext->srq_list); 1734 list_add_tail(&uobj->uobject.list, &file->ucontext->srq_list);
1735 up(&file->mutex); 1735 mutex_unlock(&file->mutex);
1736 1736
1737 up(&ib_uverbs_idr_mutex); 1737 mutex_unlock(&ib_uverbs_idr_mutex);
1738 1738
1739 return in_len; 1739 return in_len;
1740 1740
@@ -1746,7 +1746,7 @@ err_destroy:
1746 atomic_dec(&pd->usecnt); 1746 atomic_dec(&pd->usecnt);
1747 1747
1748err_up: 1748err_up:
1749 up(&ib_uverbs_idr_mutex); 1749 mutex_unlock(&ib_uverbs_idr_mutex);
1750 1750
1751 kfree(uobj); 1751 kfree(uobj);
1752 return ret; 1752 return ret;
@@ -1764,7 +1764,7 @@ ssize_t ib_uverbs_modify_srq(struct ib_uverbs_file *file,
1764 if (copy_from_user(&cmd, buf, sizeof cmd)) 1764 if (copy_from_user(&cmd, buf, sizeof cmd))
1765 return -EFAULT; 1765 return -EFAULT;
1766 1766
1767 down(&ib_uverbs_idr_mutex); 1767 mutex_lock(&ib_uverbs_idr_mutex);
1768 1768
1769 srq = idr_find(&ib_uverbs_srq_idr, cmd.srq_handle); 1769 srq = idr_find(&ib_uverbs_srq_idr, cmd.srq_handle);
1770 if (!srq || srq->uobject->context != file->ucontext) { 1770 if (!srq || srq->uobject->context != file->ucontext) {
@@ -1778,7 +1778,7 @@ ssize_t ib_uverbs_modify_srq(struct ib_uverbs_file *file,
1778 ret = ib_modify_srq(srq, &attr, cmd.attr_mask); 1778 ret = ib_modify_srq(srq, &attr, cmd.attr_mask);
1779 1779
1780out: 1780out:
1781 up(&ib_uverbs_idr_mutex); 1781 mutex_unlock(&ib_uverbs_idr_mutex);
1782 1782
1783 return ret ? ret : in_len; 1783 return ret ? ret : in_len;
1784} 1784}
@@ -1796,7 +1796,7 @@ ssize_t ib_uverbs_destroy_srq(struct ib_uverbs_file *file,
1796 if (copy_from_user(&cmd, buf, sizeof cmd)) 1796 if (copy_from_user(&cmd, buf, sizeof cmd))
1797 return -EFAULT; 1797 return -EFAULT;
1798 1798
1799 down(&ib_uverbs_idr_mutex); 1799 mutex_lock(&ib_uverbs_idr_mutex);
1800 1800
1801 memset(&resp, 0, sizeof resp); 1801 memset(&resp, 0, sizeof resp);
1802 1802
@@ -1812,9 +1812,9 @@ ssize_t ib_uverbs_destroy_srq(struct ib_uverbs_file *file,
1812 1812
1813 idr_remove(&ib_uverbs_srq_idr, cmd.srq_handle); 1813 idr_remove(&ib_uverbs_srq_idr, cmd.srq_handle);
1814 1814
1815 down(&file->mutex); 1815 mutex_lock(&file->mutex);
1816 list_del(&uobj->uobject.list); 1816 list_del(&uobj->uobject.list);
1817 up(&file->mutex); 1817 mutex_unlock(&file->mutex);
1818 1818
1819 ib_uverbs_release_uevent(file, uobj); 1819 ib_uverbs_release_uevent(file, uobj);
1820 1820
@@ -1827,7 +1827,7 @@ ssize_t ib_uverbs_destroy_srq(struct ib_uverbs_file *file,
1827 ret = -EFAULT; 1827 ret = -EFAULT;
1828 1828
1829out: 1829out:
1830 up(&ib_uverbs_idr_mutex); 1830 mutex_unlock(&ib_uverbs_idr_mutex);
1831 1831
1832 return ret ? ret : in_len; 1832 return ret ? ret : in_len;
1833} 1833}
diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c
index 81737bd6faea..96ea79b63df7 100644
--- a/drivers/infiniband/core/uverbs_main.c
+++ b/drivers/infiniband/core/uverbs_main.c
@@ -66,7 +66,7 @@ enum {
66 66
67static struct class *uverbs_class; 67static struct class *uverbs_class;
68 68
69DECLARE_MUTEX(ib_uverbs_idr_mutex); 69DEFINE_MUTEX(ib_uverbs_idr_mutex);
70DEFINE_IDR(ib_uverbs_pd_idr); 70DEFINE_IDR(ib_uverbs_pd_idr);
71DEFINE_IDR(ib_uverbs_mr_idr); 71DEFINE_IDR(ib_uverbs_mr_idr);
72DEFINE_IDR(ib_uverbs_mw_idr); 72DEFINE_IDR(ib_uverbs_mw_idr);
@@ -180,7 +180,7 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,
180 if (!context) 180 if (!context)
181 return 0; 181 return 0;
182 182
183 down(&ib_uverbs_idr_mutex); 183 mutex_lock(&ib_uverbs_idr_mutex);
184 184
185 list_for_each_entry_safe(uobj, tmp, &context->ah_list, list) { 185 list_for_each_entry_safe(uobj, tmp, &context->ah_list, list) {
186 struct ib_ah *ah = idr_find(&ib_uverbs_ah_idr, uobj->id); 186 struct ib_ah *ah = idr_find(&ib_uverbs_ah_idr, uobj->id);
@@ -250,7 +250,7 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,
250 kfree(uobj); 250 kfree(uobj);
251 } 251 }
252 252
253 up(&ib_uverbs_idr_mutex); 253 mutex_unlock(&ib_uverbs_idr_mutex);
254 254
255 return context->device->dealloc_ucontext(context); 255 return context->device->dealloc_ucontext(context);
256} 256}
@@ -653,7 +653,7 @@ static int ib_uverbs_open(struct inode *inode, struct file *filp)
653 file->ucontext = NULL; 653 file->ucontext = NULL;
654 file->async_file = NULL; 654 file->async_file = NULL;
655 kref_init(&file->ref); 655 kref_init(&file->ref);
656 init_MUTEX(&file->mutex); 656 mutex_init(&file->mutex);
657 657
658 filp->private_data = file; 658 filp->private_data = file;
659 659
diff --git a/drivers/infiniband/hw/mthca/mthca_av.c b/drivers/infiniband/hw/mthca/mthca_av.c
index 22fdc446f25c..a14eed08a0fc 100644
--- a/drivers/infiniband/hw/mthca/mthca_av.c
+++ b/drivers/infiniband/hw/mthca/mthca_av.c
@@ -163,6 +163,11 @@ int mthca_destroy_ah(struct mthca_dev *dev, struct mthca_ah *ah)
163 return 0; 163 return 0;
164} 164}
165 165
166int mthca_ah_grh_present(struct mthca_ah *ah)
167{
168 return !!(ah->av->g_slid & 0x80);
169}
170
166int mthca_read_ah(struct mthca_dev *dev, struct mthca_ah *ah, 171int mthca_read_ah(struct mthca_dev *dev, struct mthca_ah *ah,
167 struct ib_ud_header *header) 172 struct ib_ud_header *header)
168{ 173{
@@ -172,8 +177,7 @@ int mthca_read_ah(struct mthca_dev *dev, struct mthca_ah *ah,
172 header->lrh.service_level = be32_to_cpu(ah->av->sl_tclass_flowlabel) >> 28; 177 header->lrh.service_level = be32_to_cpu(ah->av->sl_tclass_flowlabel) >> 28;
173 header->lrh.destination_lid = ah->av->dlid; 178 header->lrh.destination_lid = ah->av->dlid;
174 header->lrh.source_lid = cpu_to_be16(ah->av->g_slid & 0x7f); 179 header->lrh.source_lid = cpu_to_be16(ah->av->g_slid & 0x7f);
175 if (ah->av->g_slid & 0x80) { 180 if (mthca_ah_grh_present(ah)) {
176 header->grh_present = 1;
177 header->grh.traffic_class = 181 header->grh.traffic_class =
178 (be32_to_cpu(ah->av->sl_tclass_flowlabel) >> 20) & 0xff; 182 (be32_to_cpu(ah->av->sl_tclass_flowlabel) >> 20) & 0xff;
179 header->grh.flow_label = 183 header->grh.flow_label =
@@ -184,8 +188,6 @@ int mthca_read_ah(struct mthca_dev *dev, struct mthca_ah *ah,
184 &header->grh.source_gid); 188 &header->grh.source_gid);
185 memcpy(header->grh.destination_gid.raw, 189 memcpy(header->grh.destination_gid.raw,
186 ah->av->dgid, 16); 190 ah->av->dgid, 16);
187 } else {
188 header->grh_present = 0;
189 } 191 }
190 192
191 return 0; 193 return 0;
diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
index 22ac72bc20c3..be1791be627b 100644
--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
@@ -606,7 +606,7 @@ static int mthca_map_cmd(struct mthca_dev *dev, u16 op, struct mthca_icm *icm,
606 err = -EINVAL; 606 err = -EINVAL;
607 goto out; 607 goto out;
608 } 608 }
609 for (i = 0; i < mthca_icm_size(&iter) / (1 << lg); ++i) { 609 for (i = 0; i < mthca_icm_size(&iter) >> lg; ++i) {
610 if (virt != -1) { 610 if (virt != -1) {
611 pages[nent * 2] = cpu_to_be64(virt); 611 pages[nent * 2] = cpu_to_be64(virt);
612 virt += 1 << lg; 612 virt += 1 << lg;
@@ -727,8 +727,8 @@ int mthca_QUERY_FW(struct mthca_dev *dev, u8 *status)
727 * system pages needed. 727 * system pages needed.
728 */ 728 */
729 dev->fw.arbel.fw_pages = 729 dev->fw.arbel.fw_pages =
730 (dev->fw.arbel.fw_pages + (1 << (PAGE_SHIFT - 12)) - 1) >> 730 ALIGN(dev->fw.arbel.fw_pages, PAGE_SIZE >> 12) >>
731 (PAGE_SHIFT - 12); 731 (PAGE_SHIFT - 12);
732 732
733 mthca_dbg(dev, "Clear int @ %llx, EQ arm @ %llx, EQ set CI @ %llx\n", 733 mthca_dbg(dev, "Clear int @ %llx, EQ arm @ %llx, EQ set CI @ %llx\n",
734 (unsigned long long) dev->fw.arbel.clr_int_base, 734 (unsigned long long) dev->fw.arbel.clr_int_base,
@@ -1445,6 +1445,7 @@ int mthca_SET_ICM_SIZE(struct mthca_dev *dev, u64 icm_size, u64 *aux_pages,
1445 * pages needed. 1445 * pages needed.
1446 */ 1446 */
1447 *aux_pages = (*aux_pages + (1 << (PAGE_SHIFT - 12)) - 1) >> (PAGE_SHIFT - 12); 1447 *aux_pages = (*aux_pages + (1 << (PAGE_SHIFT - 12)) - 1) >> (PAGE_SHIFT - 12);
1448 *aux_pages = ALIGN(*aux_pages, PAGE_SIZE >> 12) >> (PAGE_SHIFT - 12);
1448 1449
1449 return 0; 1450 return 0;
1450} 1451}
diff --git a/drivers/infiniband/hw/mthca/mthca_dev.h b/drivers/infiniband/hw/mthca/mthca_dev.h
index 795b379260bf..a104ab041ea3 100644
--- a/drivers/infiniband/hw/mthca/mthca_dev.h
+++ b/drivers/infiniband/hw/mthca/mthca_dev.h
@@ -520,6 +520,7 @@ int mthca_create_ah(struct mthca_dev *dev,
520int mthca_destroy_ah(struct mthca_dev *dev, struct mthca_ah *ah); 520int mthca_destroy_ah(struct mthca_dev *dev, struct mthca_ah *ah);
521int mthca_read_ah(struct mthca_dev *dev, struct mthca_ah *ah, 521int mthca_read_ah(struct mthca_dev *dev, struct mthca_ah *ah,
522 struct ib_ud_header *header); 522 struct ib_ud_header *header);
523int mthca_ah_grh_present(struct mthca_ah *ah);
523 524
524int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid); 525int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid);
525int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid); 526int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid);
diff --git a/drivers/infiniband/hw/mthca/mthca_eq.c b/drivers/infiniband/hw/mthca/mthca_eq.c
index e8a948f087c0..2eabb27804cd 100644
--- a/drivers/infiniband/hw/mthca/mthca_eq.c
+++ b/drivers/infiniband/hw/mthca/mthca_eq.c
@@ -45,6 +45,7 @@
45enum { 45enum {
46 MTHCA_NUM_ASYNC_EQE = 0x80, 46 MTHCA_NUM_ASYNC_EQE = 0x80,
47 MTHCA_NUM_CMD_EQE = 0x80, 47 MTHCA_NUM_CMD_EQE = 0x80,
48 MTHCA_NUM_SPARE_EQE = 0x80,
48 MTHCA_EQ_ENTRY_SIZE = 0x20 49 MTHCA_EQ_ENTRY_SIZE = 0x20
49}; 50};
50 51
@@ -277,11 +278,10 @@ static int mthca_eq_int(struct mthca_dev *dev, struct mthca_eq *eq)
277{ 278{
278 struct mthca_eqe *eqe; 279 struct mthca_eqe *eqe;
279 int disarm_cqn; 280 int disarm_cqn;
280 int eqes_found = 0; 281 int eqes_found = 0;
282 int set_ci = 0;
281 283
282 while ((eqe = next_eqe_sw(eq))) { 284 while ((eqe = next_eqe_sw(eq))) {
283 int set_ci = 0;
284
285 /* 285 /*
286 * Make sure we read EQ entry contents after we've 286 * Make sure we read EQ entry contents after we've
287 * checked the ownership bit. 287 * checked the ownership bit.
@@ -345,12 +345,6 @@ static int mthca_eq_int(struct mthca_dev *dev, struct mthca_eq *eq)
345 be16_to_cpu(eqe->event.cmd.token), 345 be16_to_cpu(eqe->event.cmd.token),
346 eqe->event.cmd.status, 346 eqe->event.cmd.status,
347 be64_to_cpu(eqe->event.cmd.out_param)); 347 be64_to_cpu(eqe->event.cmd.out_param));
348 /*
349 * cmd_event() may add more commands.
350 * The card will think the queue has overflowed if
351 * we don't tell it we've been processing events.
352 */
353 set_ci = 1;
354 break; 348 break;
355 349
356 case MTHCA_EVENT_TYPE_PORT_CHANGE: 350 case MTHCA_EVENT_TYPE_PORT_CHANGE:
@@ -385,8 +379,16 @@ static int mthca_eq_int(struct mthca_dev *dev, struct mthca_eq *eq)
385 set_eqe_hw(eqe); 379 set_eqe_hw(eqe);
386 ++eq->cons_index; 380 ++eq->cons_index;
387 eqes_found = 1; 381 eqes_found = 1;
382 ++set_ci;
388 383
389 if (unlikely(set_ci)) { 384 /*
385 * The HCA will think the queue has overflowed if we
386 * don't tell it we've been processing events. We
387 * create our EQs with MTHCA_NUM_SPARE_EQE extra
388 * entries, so we must update our consumer index at
389 * least that often.
390 */
391 if (unlikely(set_ci >= MTHCA_NUM_SPARE_EQE)) {
390 /* 392 /*
391 * Conditional on hca_type is OK here because 393 * Conditional on hca_type is OK here because
392 * this is a rare case, not the fast path. 394 * this is a rare case, not the fast path.
@@ -862,19 +864,19 @@ int __devinit mthca_init_eq_table(struct mthca_dev *dev)
862 intr = (dev->mthca_flags & MTHCA_FLAG_MSI) ? 864 intr = (dev->mthca_flags & MTHCA_FLAG_MSI) ?
863 128 : dev->eq_table.inta_pin; 865 128 : dev->eq_table.inta_pin;
864 866
865 err = mthca_create_eq(dev, dev->limits.num_cqs, 867 err = mthca_create_eq(dev, dev->limits.num_cqs + MTHCA_NUM_SPARE_EQE,
866 (dev->mthca_flags & MTHCA_FLAG_MSI_X) ? 128 : intr, 868 (dev->mthca_flags & MTHCA_FLAG_MSI_X) ? 128 : intr,
867 &dev->eq_table.eq[MTHCA_EQ_COMP]); 869 &dev->eq_table.eq[MTHCA_EQ_COMP]);
868 if (err) 870 if (err)
869 goto err_out_unmap; 871 goto err_out_unmap;
870 872
871 err = mthca_create_eq(dev, MTHCA_NUM_ASYNC_EQE, 873 err = mthca_create_eq(dev, MTHCA_NUM_ASYNC_EQE + MTHCA_NUM_SPARE_EQE,
872 (dev->mthca_flags & MTHCA_FLAG_MSI_X) ? 129 : intr, 874 (dev->mthca_flags & MTHCA_FLAG_MSI_X) ? 129 : intr,
873 &dev->eq_table.eq[MTHCA_EQ_ASYNC]); 875 &dev->eq_table.eq[MTHCA_EQ_ASYNC]);
874 if (err) 876 if (err)
875 goto err_out_comp; 877 goto err_out_comp;
876 878
877 err = mthca_create_eq(dev, MTHCA_NUM_CMD_EQE, 879 err = mthca_create_eq(dev, MTHCA_NUM_CMD_EQE + MTHCA_NUM_SPARE_EQE,
878 (dev->mthca_flags & MTHCA_FLAG_MSI_X) ? 130 : intr, 880 (dev->mthca_flags & MTHCA_FLAG_MSI_X) ? 130 : intr,
879 &dev->eq_table.eq[MTHCA_EQ_CMD]); 881 &dev->eq_table.eq[MTHCA_EQ_CMD]);
880 if (err) 882 if (err)
diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
index 4cc7e2846df1..484a7e6b7f8c 100644
--- a/drivers/infiniband/hw/mthca/mthca_provider.c
+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
@@ -33,7 +33,7 @@
33 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 33 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 * SOFTWARE. 34 * SOFTWARE.
35 * 35 *
36 * $Id: mthca_provider.c 1397 2004-12-28 05:09:00Z roland $ 36 * $Id: mthca_provider.c 4859 2006-01-09 21:55:10Z roland $
37 */ 37 */
38 38
39#include <rdma/ib_smi.h> 39#include <rdma/ib_smi.h>
@@ -45,6 +45,14 @@
45#include "mthca_user.h" 45#include "mthca_user.h"
46#include "mthca_memfree.h" 46#include "mthca_memfree.h"
47 47
48static void init_query_mad(struct ib_smp *mad)
49{
50 mad->base_version = 1;
51 mad->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
52 mad->class_version = 1;
53 mad->method = IB_MGMT_METHOD_GET;
54}
55
48static int mthca_query_device(struct ib_device *ibdev, 56static int mthca_query_device(struct ib_device *ibdev,
49 struct ib_device_attr *props) 57 struct ib_device_attr *props)
50{ 58{
@@ -55,7 +63,7 @@ static int mthca_query_device(struct ib_device *ibdev,
55 63
56 u8 status; 64 u8 status;
57 65
58 in_mad = kmalloc(sizeof *in_mad, GFP_KERNEL); 66 in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL);
59 out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL); 67 out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
60 if (!in_mad || !out_mad) 68 if (!in_mad || !out_mad)
61 goto out; 69 goto out;
@@ -64,12 +72,8 @@ static int mthca_query_device(struct ib_device *ibdev,
64 72
65 props->fw_ver = mdev->fw_ver; 73 props->fw_ver = mdev->fw_ver;
66 74
67 memset(in_mad, 0, sizeof *in_mad); 75 init_query_mad(in_mad);
68 in_mad->base_version = 1; 76 in_mad->attr_id = IB_SMP_ATTR_NODE_INFO;
69 in_mad->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
70 in_mad->class_version = 1;
71 in_mad->method = IB_MGMT_METHOD_GET;
72 in_mad->attr_id = IB_SMP_ATTR_NODE_INFO;
73 77
74 err = mthca_MAD_IFC(mdev, 1, 1, 78 err = mthca_MAD_IFC(mdev, 1, 1,
75 1, NULL, NULL, in_mad, out_mad, 79 1, NULL, NULL, in_mad, out_mad,
@@ -87,7 +91,6 @@ static int mthca_query_device(struct ib_device *ibdev,
87 props->vendor_part_id = be16_to_cpup((__be16 *) (out_mad->data + 30)); 91 props->vendor_part_id = be16_to_cpup((__be16 *) (out_mad->data + 30));
88 props->hw_ver = be32_to_cpup((__be32 *) (out_mad->data + 32)); 92 props->hw_ver = be32_to_cpup((__be32 *) (out_mad->data + 32));
89 memcpy(&props->sys_image_guid, out_mad->data + 4, 8); 93 memcpy(&props->sys_image_guid, out_mad->data + 4, 8);
90 memcpy(&props->node_guid, out_mad->data + 12, 8);
91 94
92 props->max_mr_size = ~0ull; 95 props->max_mr_size = ~0ull;
93 props->page_size_cap = mdev->limits.page_size_cap; 96 props->page_size_cap = mdev->limits.page_size_cap;
@@ -128,20 +131,16 @@ static int mthca_query_port(struct ib_device *ibdev,
128 int err = -ENOMEM; 131 int err = -ENOMEM;
129 u8 status; 132 u8 status;
130 133
131 in_mad = kmalloc(sizeof *in_mad, GFP_KERNEL); 134 in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL);
132 out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL); 135 out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
133 if (!in_mad || !out_mad) 136 if (!in_mad || !out_mad)
134 goto out; 137 goto out;
135 138
136 memset(props, 0, sizeof *props); 139 memset(props, 0, sizeof *props);
137 140
138 memset(in_mad, 0, sizeof *in_mad); 141 init_query_mad(in_mad);
139 in_mad->base_version = 1; 142 in_mad->attr_id = IB_SMP_ATTR_PORT_INFO;
140 in_mad->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED; 143 in_mad->attr_mod = cpu_to_be32(port);
141 in_mad->class_version = 1;
142 in_mad->method = IB_MGMT_METHOD_GET;
143 in_mad->attr_id = IB_SMP_ATTR_PORT_INFO;
144 in_mad->attr_mod = cpu_to_be32(port);
145 144
146 err = mthca_MAD_IFC(to_mdev(ibdev), 1, 1, 145 err = mthca_MAD_IFC(to_mdev(ibdev), 1, 1,
147 port, NULL, NULL, in_mad, out_mad, 146 port, NULL, NULL, in_mad, out_mad,
@@ -220,18 +219,14 @@ static int mthca_query_pkey(struct ib_device *ibdev,
220 int err = -ENOMEM; 219 int err = -ENOMEM;
221 u8 status; 220 u8 status;
222 221
223 in_mad = kmalloc(sizeof *in_mad, GFP_KERNEL); 222 in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL);
224 out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL); 223 out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
225 if (!in_mad || !out_mad) 224 if (!in_mad || !out_mad)
226 goto out; 225 goto out;
227 226
228 memset(in_mad, 0, sizeof *in_mad); 227 init_query_mad(in_mad);
229 in_mad->base_version = 1; 228 in_mad->attr_id = IB_SMP_ATTR_PKEY_TABLE;
230 in_mad->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED; 229 in_mad->attr_mod = cpu_to_be32(index / 32);
231 in_mad->class_version = 1;
232 in_mad->method = IB_MGMT_METHOD_GET;
233 in_mad->attr_id = IB_SMP_ATTR_PKEY_TABLE;
234 in_mad->attr_mod = cpu_to_be32(index / 32);
235 230
236 err = mthca_MAD_IFC(to_mdev(ibdev), 1, 1, 231 err = mthca_MAD_IFC(to_mdev(ibdev), 1, 1,
237 port, NULL, NULL, in_mad, out_mad, 232 port, NULL, NULL, in_mad, out_mad,
@@ -259,18 +254,14 @@ static int mthca_query_gid(struct ib_device *ibdev, u8 port,
259 int err = -ENOMEM; 254 int err = -ENOMEM;
260 u8 status; 255 u8 status;
261 256
262 in_mad = kmalloc(sizeof *in_mad, GFP_KERNEL); 257 in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL);
263 out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL); 258 out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
264 if (!in_mad || !out_mad) 259 if (!in_mad || !out_mad)
265 goto out; 260 goto out;
266 261
267 memset(in_mad, 0, sizeof *in_mad); 262 init_query_mad(in_mad);
268 in_mad->base_version = 1; 263 in_mad->attr_id = IB_SMP_ATTR_PORT_INFO;
269 in_mad->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED; 264 in_mad->attr_mod = cpu_to_be32(port);
270 in_mad->class_version = 1;
271 in_mad->method = IB_MGMT_METHOD_GET;
272 in_mad->attr_id = IB_SMP_ATTR_PORT_INFO;
273 in_mad->attr_mod = cpu_to_be32(port);
274 265
275 err = mthca_MAD_IFC(to_mdev(ibdev), 1, 1, 266 err = mthca_MAD_IFC(to_mdev(ibdev), 1, 1,
276 port, NULL, NULL, in_mad, out_mad, 267 port, NULL, NULL, in_mad, out_mad,
@@ -284,13 +275,9 @@ static int mthca_query_gid(struct ib_device *ibdev, u8 port,
284 275
285 memcpy(gid->raw, out_mad->data + 8, 8); 276 memcpy(gid->raw, out_mad->data + 8, 8);
286 277
287 memset(in_mad, 0, sizeof *in_mad); 278 init_query_mad(in_mad);
288 in_mad->base_version = 1; 279 in_mad->attr_id = IB_SMP_ATTR_GUID_INFO;
289 in_mad->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED; 280 in_mad->attr_mod = cpu_to_be32(index / 8);
290 in_mad->class_version = 1;
291 in_mad->method = IB_MGMT_METHOD_GET;
292 in_mad->attr_id = IB_SMP_ATTR_GUID_INFO;
293 in_mad->attr_mod = cpu_to_be32(index / 8);
294 281
295 err = mthca_MAD_IFC(to_mdev(ibdev), 1, 1, 282 err = mthca_MAD_IFC(to_mdev(ibdev), 1, 1,
296 port, NULL, NULL, in_mad, out_mad, 283 port, NULL, NULL, in_mad, out_mad,
@@ -458,8 +445,10 @@ static struct ib_srq *mthca_create_srq(struct ib_pd *pd,
458 if (pd->uobject) { 445 if (pd->uobject) {
459 context = to_mucontext(pd->uobject->context); 446 context = to_mucontext(pd->uobject->context);
460 447
461 if (ib_copy_from_udata(&ucmd, udata, sizeof ucmd)) 448 if (ib_copy_from_udata(&ucmd, udata, sizeof ucmd)) {
462 return ERR_PTR(-EFAULT); 449 err = -EFAULT;
450 goto err_free;
451 }
463 452
464 err = mthca_map_user_db(to_mdev(pd->device), &context->uar, 453 err = mthca_map_user_db(to_mdev(pd->device), &context->uar,
465 context->db_tab, ucmd.db_index, 454 context->db_tab, ucmd.db_index,
@@ -535,8 +524,10 @@ static struct ib_qp *mthca_create_qp(struct ib_pd *pd,
535 if (pd->uobject) { 524 if (pd->uobject) {
536 context = to_mucontext(pd->uobject->context); 525 context = to_mucontext(pd->uobject->context);
537 526
538 if (ib_copy_from_udata(&ucmd, udata, sizeof ucmd)) 527 if (ib_copy_from_udata(&ucmd, udata, sizeof ucmd)) {
528 kfree(qp);
539 return ERR_PTR(-EFAULT); 529 return ERR_PTR(-EFAULT);
530 }
540 531
541 err = mthca_map_user_db(to_mdev(pd->device), &context->uar, 532 err = mthca_map_user_db(to_mdev(pd->device), &context->uar,
542 context->db_tab, 533 context->db_tab,
@@ -783,24 +774,20 @@ static struct ib_mr *mthca_reg_phys_mr(struct ib_pd *pd,
783 if ((*iova_start & ~PAGE_MASK) != (buffer_list[0].addr & ~PAGE_MASK)) 774 if ((*iova_start & ~PAGE_MASK) != (buffer_list[0].addr & ~PAGE_MASK))
784 return ERR_PTR(-EINVAL); 775 return ERR_PTR(-EINVAL);
785 776
786 if (num_phys_buf > 1 &&
787 ((buffer_list[0].addr + buffer_list[0].size) & ~PAGE_MASK))
788 return ERR_PTR(-EINVAL);
789
790 mask = 0; 777 mask = 0;
791 total_size = 0; 778 total_size = 0;
792 for (i = 0; i < num_phys_buf; ++i) { 779 for (i = 0; i < num_phys_buf; ++i) {
793 if (i != 0 && buffer_list[i].addr & ~PAGE_MASK) 780 if (i != 0)
794 return ERR_PTR(-EINVAL); 781 mask |= buffer_list[i].addr;
795 if (i != 0 && i != num_phys_buf - 1 && 782 if (i != num_phys_buf - 1)
796 (buffer_list[i].size & ~PAGE_MASK)) 783 mask |= buffer_list[i].addr + buffer_list[i].size;
797 return ERR_PTR(-EINVAL);
798 784
799 total_size += buffer_list[i].size; 785 total_size += buffer_list[i].size;
800 if (i > 0)
801 mask |= buffer_list[i].addr;
802 } 786 }
803 787
788 if (mask & ~PAGE_MASK)
789 return ERR_PTR(-EINVAL);
790
804 /* Find largest page shift we can use to cover buffers */ 791 /* Find largest page shift we can use to cover buffers */
805 for (shift = PAGE_SHIFT; shift < 31; ++shift) 792 for (shift = PAGE_SHIFT; shift < 31; ++shift)
806 if (num_phys_buf > 1) { 793 if (num_phys_buf > 1) {
@@ -1070,11 +1057,48 @@ static struct class_device_attribute *mthca_class_attributes[] = {
1070 &class_device_attr_board_id 1057 &class_device_attr_board_id
1071}; 1058};
1072 1059
1060static int mthca_init_node_data(struct mthca_dev *dev)
1061{
1062 struct ib_smp *in_mad = NULL;
1063 struct ib_smp *out_mad = NULL;
1064 int err = -ENOMEM;
1065 u8 status;
1066
1067 in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL);
1068 out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
1069 if (!in_mad || !out_mad)
1070 goto out;
1071
1072 init_query_mad(in_mad);
1073 in_mad->attr_id = IB_SMP_ATTR_NODE_INFO;
1074
1075 err = mthca_MAD_IFC(dev, 1, 1,
1076 1, NULL, NULL, in_mad, out_mad,
1077 &status);
1078 if (err)
1079 goto out;
1080 if (status) {
1081 err = -EINVAL;
1082 goto out;
1083 }
1084
1085 memcpy(&dev->ib_dev.node_guid, out_mad->data + 12, 8);
1086
1087out:
1088 kfree(in_mad);
1089 kfree(out_mad);
1090 return err;
1091}
1092
1073int mthca_register_device(struct mthca_dev *dev) 1093int mthca_register_device(struct mthca_dev *dev)
1074{ 1094{
1075 int ret; 1095 int ret;
1076 int i; 1096 int i;
1077 1097
1098 ret = mthca_init_node_data(dev);
1099 if (ret)
1100 return ret;
1101
1078 strlcpy(dev->ib_dev.name, "mthca%d", IB_DEVICE_NAME_MAX); 1102 strlcpy(dev->ib_dev.name, "mthca%d", IB_DEVICE_NAME_MAX);
1079 dev->ib_dev.owner = THIS_MODULE; 1103 dev->ib_dev.owner = THIS_MODULE;
1080 1104
diff --git a/drivers/infiniband/hw/mthca/mthca_qp.c b/drivers/infiniband/hw/mthca/mthca_qp.c
index 564b6d51c394..fba608ed7df2 100644
--- a/drivers/infiniband/hw/mthca/mthca_qp.c
+++ b/drivers/infiniband/hw/mthca/mthca_qp.c
@@ -1434,7 +1434,7 @@ static int build_mlx_header(struct mthca_dev *dev, struct mthca_sqp *sqp,
1434 u16 pkey; 1434 u16 pkey;
1435 1435
1436 ib_ud_header_init(256, /* assume a MAD */ 1436 ib_ud_header_init(256, /* assume a MAD */
1437 sqp->ud_header.grh_present, 1437 mthca_ah_grh_present(to_mah(wr->wr.ud.ah)),
1438 &sqp->ud_header); 1438 &sqp->ud_header);
1439 1439
1440 err = mthca_read_ah(dev, to_mah(wr->wr.ud.ah), &sqp->ud_header); 1440 err = mthca_read_ah(dev, to_mah(wr->wr.ud.ah), &sqp->ud_header);
diff --git a/drivers/infiniband/ulp/ipoib/ipoib.h b/drivers/infiniband/ulp/ipoib/ipoib.h
index 9923a15a9996..e0a5412b7e68 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib.h
+++ b/drivers/infiniband/ulp/ipoib/ipoib.h
@@ -45,11 +45,11 @@
45#include <linux/config.h> 45#include <linux/config.h>
46#include <linux/kref.h> 46#include <linux/kref.h>
47#include <linux/if_infiniband.h> 47#include <linux/if_infiniband.h>
48#include <linux/mutex.h>
48 49
49#include <net/neighbour.h> 50#include <net/neighbour.h>
50 51
51#include <asm/atomic.h> 52#include <asm/atomic.h>
52#include <asm/semaphore.h>
53 53
54#include <rdma/ib_verbs.h> 54#include <rdma/ib_verbs.h>
55#include <rdma/ib_pack.h> 55#include <rdma/ib_pack.h>
@@ -123,8 +123,8 @@ struct ipoib_dev_priv {
123 123
124 unsigned long flags; 124 unsigned long flags;
125 125
126 struct semaphore mcast_mutex; 126 struct mutex mcast_mutex;
127 struct semaphore vlan_mutex; 127 struct mutex vlan_mutex;
128 128
129 struct rb_root path_tree; 129 struct rb_root path_tree;
130 struct list_head path_list; 130 struct list_head path_list;
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_ib.c b/drivers/infiniband/ulp/ipoib/ipoib_ib.c
index 23885801b6d2..86bcdd72a107 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_ib.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_ib.c
@@ -52,7 +52,7 @@ MODULE_PARM_DESC(data_debug_level,
52 52
53#define IPOIB_OP_RECV (1ul << 31) 53#define IPOIB_OP_RECV (1ul << 31)
54 54
55static DECLARE_MUTEX(pkey_sem); 55static DEFINE_MUTEX(pkey_mutex);
56 56
57struct ipoib_ah *ipoib_create_ah(struct net_device *dev, 57struct ipoib_ah *ipoib_create_ah(struct net_device *dev,
58 struct ib_pd *pd, struct ib_ah_attr *attr) 58 struct ib_pd *pd, struct ib_ah_attr *attr)
@@ -445,25 +445,16 @@ int ipoib_ib_dev_down(struct net_device *dev)
445 445
446 /* Shutdown the P_Key thread if still active */ 446 /* Shutdown the P_Key thread if still active */
447 if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) { 447 if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) {
448 down(&pkey_sem); 448 mutex_lock(&pkey_mutex);
449 set_bit(IPOIB_PKEY_STOP, &priv->flags); 449 set_bit(IPOIB_PKEY_STOP, &priv->flags);
450 cancel_delayed_work(&priv->pkey_task); 450 cancel_delayed_work(&priv->pkey_task);
451 up(&pkey_sem); 451 mutex_unlock(&pkey_mutex);
452 flush_workqueue(ipoib_workqueue); 452 flush_workqueue(ipoib_workqueue);
453 } 453 }
454 454
455 ipoib_mcast_stop_thread(dev, 1); 455 ipoib_mcast_stop_thread(dev, 1);
456
457 /*
458 * Flush the multicast groups first so we stop any multicast joins. The
459 * completion thread may have already died and we may deadlock waiting
460 * for the completion thread to finish some multicast joins.
461 */
462 ipoib_mcast_dev_flush(dev); 456 ipoib_mcast_dev_flush(dev);
463 457
464 /* Delete broadcast and local addresses since they will be recreated */
465 ipoib_mcast_dev_down(dev);
466
467 ipoib_flush_paths(dev); 458 ipoib_flush_paths(dev);
468 459
469 return 0; 460 return 0;
@@ -608,13 +599,13 @@ void ipoib_ib_dev_flush(void *_dev)
608 if (test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags)) 599 if (test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags))
609 ipoib_ib_dev_up(dev); 600 ipoib_ib_dev_up(dev);
610 601
611 down(&priv->vlan_mutex); 602 mutex_lock(&priv->vlan_mutex);
612 603
613 /* Flush any child interfaces too */ 604 /* Flush any child interfaces too */
614 list_for_each_entry(cpriv, &priv->child_intfs, list) 605 list_for_each_entry(cpriv, &priv->child_intfs, list)
615 ipoib_ib_dev_flush(&cpriv->dev); 606 ipoib_ib_dev_flush(&cpriv->dev);
616 607
617 up(&priv->vlan_mutex); 608 mutex_unlock(&priv->vlan_mutex);
618} 609}
619 610
620void ipoib_ib_dev_cleanup(struct net_device *dev) 611void ipoib_ib_dev_cleanup(struct net_device *dev)
@@ -624,9 +615,7 @@ void ipoib_ib_dev_cleanup(struct net_device *dev)
624 ipoib_dbg(priv, "cleaning up ib_dev\n"); 615 ipoib_dbg(priv, "cleaning up ib_dev\n");
625 616
626 ipoib_mcast_stop_thread(dev, 1); 617 ipoib_mcast_stop_thread(dev, 1);
627 618 ipoib_mcast_dev_flush(dev);
628 /* Delete the broadcast address and the local address */
629 ipoib_mcast_dev_down(dev);
630 619
631 ipoib_transport_dev_cleanup(dev); 620 ipoib_transport_dev_cleanup(dev);
632} 621}
@@ -662,12 +651,12 @@ void ipoib_pkey_poll(void *dev_ptr)
662 if (test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) 651 if (test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags))
663 ipoib_open(dev); 652 ipoib_open(dev);
664 else { 653 else {
665 down(&pkey_sem); 654 mutex_lock(&pkey_mutex);
666 if (!test_bit(IPOIB_PKEY_STOP, &priv->flags)) 655 if (!test_bit(IPOIB_PKEY_STOP, &priv->flags))
667 queue_delayed_work(ipoib_workqueue, 656 queue_delayed_work(ipoib_workqueue,
668 &priv->pkey_task, 657 &priv->pkey_task,
669 HZ); 658 HZ);
670 up(&pkey_sem); 659 mutex_unlock(&pkey_mutex);
671 } 660 }
672} 661}
673 662
@@ -681,12 +670,12 @@ int ipoib_pkey_dev_delay_open(struct net_device *dev)
681 670
682 /* P_Key value not assigned yet - start polling */ 671 /* P_Key value not assigned yet - start polling */
683 if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) { 672 if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) {
684 down(&pkey_sem); 673 mutex_lock(&pkey_mutex);
685 clear_bit(IPOIB_PKEY_STOP, &priv->flags); 674 clear_bit(IPOIB_PKEY_STOP, &priv->flags);
686 queue_delayed_work(ipoib_workqueue, 675 queue_delayed_work(ipoib_workqueue,
687 &priv->pkey_task, 676 &priv->pkey_task,
688 HZ); 677 HZ);
689 up(&pkey_sem); 678 mutex_unlock(&pkey_mutex);
690 return 1; 679 return 1;
691 } 680 }
692 681
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c
index 780009c7eaa6..fd3f5c862a5d 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_main.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c
@@ -105,7 +105,7 @@ int ipoib_open(struct net_device *dev)
105 struct ipoib_dev_priv *cpriv; 105 struct ipoib_dev_priv *cpriv;
106 106
107 /* Bring up any child interfaces too */ 107 /* Bring up any child interfaces too */
108 down(&priv->vlan_mutex); 108 mutex_lock(&priv->vlan_mutex);
109 list_for_each_entry(cpriv, &priv->child_intfs, list) { 109 list_for_each_entry(cpriv, &priv->child_intfs, list) {
110 int flags; 110 int flags;
111 111
@@ -115,7 +115,7 @@ int ipoib_open(struct net_device *dev)
115 115
116 dev_change_flags(cpriv->dev, flags | IFF_UP); 116 dev_change_flags(cpriv->dev, flags | IFF_UP);
117 } 117 }
118 up(&priv->vlan_mutex); 118 mutex_unlock(&priv->vlan_mutex);
119 } 119 }
120 120
121 netif_start_queue(dev); 121 netif_start_queue(dev);
@@ -140,7 +140,7 @@ static int ipoib_stop(struct net_device *dev)
140 struct ipoib_dev_priv *cpriv; 140 struct ipoib_dev_priv *cpriv;
141 141
142 /* Bring down any child interfaces too */ 142 /* Bring down any child interfaces too */
143 down(&priv->vlan_mutex); 143 mutex_lock(&priv->vlan_mutex);
144 list_for_each_entry(cpriv, &priv->child_intfs, list) { 144 list_for_each_entry(cpriv, &priv->child_intfs, list) {
145 int flags; 145 int flags;
146 146
@@ -150,7 +150,7 @@ static int ipoib_stop(struct net_device *dev)
150 150
151 dev_change_flags(cpriv->dev, flags & ~IFF_UP); 151 dev_change_flags(cpriv->dev, flags & ~IFF_UP);
152 } 152 }
153 up(&priv->vlan_mutex); 153 mutex_unlock(&priv->vlan_mutex);
154 } 154 }
155 155
156 return 0; 156 return 0;
@@ -892,8 +892,8 @@ static void ipoib_setup(struct net_device *dev)
892 spin_lock_init(&priv->lock); 892 spin_lock_init(&priv->lock);
893 spin_lock_init(&priv->tx_lock); 893 spin_lock_init(&priv->tx_lock);
894 894
895 init_MUTEX(&priv->mcast_mutex); 895 mutex_init(&priv->mcast_mutex);
896 init_MUTEX(&priv->vlan_mutex); 896 mutex_init(&priv->vlan_mutex);
897 897
898 INIT_LIST_HEAD(&priv->path_list); 898 INIT_LIST_HEAD(&priv->path_list);
899 INIT_LIST_HEAD(&priv->child_intfs); 899 INIT_LIST_HEAD(&priv->child_intfs);
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
index ed0c2ead8bc1..98039da0caf0 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
@@ -55,7 +55,7 @@ MODULE_PARM_DESC(mcast_debug_level,
55 "Enable multicast debug tracing if > 0"); 55 "Enable multicast debug tracing if > 0");
56#endif 56#endif
57 57
58static DECLARE_MUTEX(mcast_mutex); 58static DEFINE_MUTEX(mcast_mutex);
59 59
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 {
@@ -97,8 +97,6 @@ static void ipoib_mcast_free(struct ipoib_mcast *mcast)
97 struct ipoib_dev_priv *priv = netdev_priv(dev); 97 struct ipoib_dev_priv *priv = netdev_priv(dev);
98 struct ipoib_neigh *neigh, *tmp; 98 struct ipoib_neigh *neigh, *tmp;
99 unsigned long flags; 99 unsigned long flags;
100 LIST_HEAD(ah_list);
101 struct ipoib_ah *ah, *tah;
102 100
103 ipoib_dbg_mcast(netdev_priv(dev), 101 ipoib_dbg_mcast(netdev_priv(dev),
104 "deleting multicast group " IPOIB_GID_FMT "\n", 102 "deleting multicast group " IPOIB_GID_FMT "\n",
@@ -107,8 +105,14 @@ static void ipoib_mcast_free(struct ipoib_mcast *mcast)
107 spin_lock_irqsave(&priv->lock, flags); 105 spin_lock_irqsave(&priv->lock, flags);
108 106
109 list_for_each_entry_safe(neigh, tmp, &mcast->neigh_list, list) { 107 list_for_each_entry_safe(neigh, tmp, &mcast->neigh_list, list) {
108 /*
109 * It's safe to call ipoib_put_ah() inside priv->lock
110 * here, because we know that mcast->ah will always
111 * hold one more reference, so ipoib_put_ah() will
112 * never do more than decrement the ref count.
113 */
110 if (neigh->ah) 114 if (neigh->ah)
111 list_add_tail(&neigh->ah->list, &ah_list); 115 ipoib_put_ah(neigh->ah);
112 *to_ipoib_neigh(neigh->neighbour) = NULL; 116 *to_ipoib_neigh(neigh->neighbour) = NULL;
113 neigh->neighbour->ops->destructor = NULL; 117 neigh->neighbour->ops->destructor = NULL;
114 kfree(neigh); 118 kfree(neigh);
@@ -116,9 +120,6 @@ static void ipoib_mcast_free(struct ipoib_mcast *mcast)
116 120
117 spin_unlock_irqrestore(&priv->lock, flags); 121 spin_unlock_irqrestore(&priv->lock, flags);
118 122
119 list_for_each_entry_safe(ah, tah, &ah_list, list)
120 ipoib_put_ah(ah);
121
122 if (mcast->ah) 123 if (mcast->ah)
123 ipoib_put_ah(mcast->ah); 124 ipoib_put_ah(mcast->ah);
124 125
@@ -384,10 +385,10 @@ static void ipoib_mcast_join_complete(int status,
384 385
385 if (!status && !ipoib_mcast_join_finish(mcast, mcmember)) { 386 if (!status && !ipoib_mcast_join_finish(mcast, mcmember)) {
386 mcast->backoff = 1; 387 mcast->backoff = 1;
387 down(&mcast_mutex); 388 mutex_lock(&mcast_mutex);
388 if (test_bit(IPOIB_MCAST_RUN, &priv->flags)) 389 if (test_bit(IPOIB_MCAST_RUN, &priv->flags))
389 queue_work(ipoib_workqueue, &priv->mcast_task); 390 queue_work(ipoib_workqueue, &priv->mcast_task);
390 up(&mcast_mutex); 391 mutex_unlock(&mcast_mutex);
391 complete(&mcast->done); 392 complete(&mcast->done);
392 return; 393 return;
393 } 394 }
@@ -417,7 +418,7 @@ static void ipoib_mcast_join_complete(int status,
417 418
418 mcast->query = NULL; 419 mcast->query = NULL;
419 420
420 down(&mcast_mutex); 421 mutex_lock(&mcast_mutex);
421 if (test_bit(IPOIB_MCAST_RUN, &priv->flags)) { 422 if (test_bit(IPOIB_MCAST_RUN, &priv->flags)) {
422 if (status == -ETIMEDOUT) 423 if (status == -ETIMEDOUT)
423 queue_work(ipoib_workqueue, &priv->mcast_task); 424 queue_work(ipoib_workqueue, &priv->mcast_task);
@@ -426,7 +427,7 @@ static void ipoib_mcast_join_complete(int status,
426 mcast->backoff * HZ); 427 mcast->backoff * HZ);
427 } else 428 } else
428 complete(&mcast->done); 429 complete(&mcast->done);
429 up(&mcast_mutex); 430 mutex_unlock(&mcast_mutex);
430 431
431 return; 432 return;
432} 433}
@@ -481,12 +482,12 @@ static void ipoib_mcast_join(struct net_device *dev, struct ipoib_mcast *mcast,
481 if (mcast->backoff > IPOIB_MAX_BACKOFF_SECONDS) 482 if (mcast->backoff > IPOIB_MAX_BACKOFF_SECONDS)
482 mcast->backoff = IPOIB_MAX_BACKOFF_SECONDS; 483 mcast->backoff = IPOIB_MAX_BACKOFF_SECONDS;
483 484
484 down(&mcast_mutex); 485 mutex_lock(&mcast_mutex);
485 if (test_bit(IPOIB_MCAST_RUN, &priv->flags)) 486 if (test_bit(IPOIB_MCAST_RUN, &priv->flags))
486 queue_delayed_work(ipoib_workqueue, 487 queue_delayed_work(ipoib_workqueue,
487 &priv->mcast_task, 488 &priv->mcast_task,
488 mcast->backoff * HZ); 489 mcast->backoff * HZ);
489 up(&mcast_mutex); 490 mutex_unlock(&mcast_mutex);
490 } else 491 } else
491 mcast->query_id = ret; 492 mcast->query_id = ret;
492} 493}
@@ -519,11 +520,11 @@ void ipoib_mcast_join_task(void *dev_ptr)
519 priv->broadcast = ipoib_mcast_alloc(dev, 1); 520 priv->broadcast = ipoib_mcast_alloc(dev, 1);
520 if (!priv->broadcast) { 521 if (!priv->broadcast) {
521 ipoib_warn(priv, "failed to allocate broadcast group\n"); 522 ipoib_warn(priv, "failed to allocate broadcast group\n");
522 down(&mcast_mutex); 523 mutex_lock(&mcast_mutex);
523 if (test_bit(IPOIB_MCAST_RUN, &priv->flags)) 524 if (test_bit(IPOIB_MCAST_RUN, &priv->flags))
524 queue_delayed_work(ipoib_workqueue, 525 queue_delayed_work(ipoib_workqueue,
525 &priv->mcast_task, HZ); 526 &priv->mcast_task, HZ);
526 up(&mcast_mutex); 527 mutex_unlock(&mcast_mutex);
527 return; 528 return;
528 } 529 }
529 530
@@ -579,10 +580,10 @@ int ipoib_mcast_start_thread(struct net_device *dev)
579 580
580 ipoib_dbg_mcast(priv, "starting multicast thread\n"); 581 ipoib_dbg_mcast(priv, "starting multicast thread\n");
581 582
582 down(&mcast_mutex); 583 mutex_lock(&mcast_mutex);
583 if (!test_and_set_bit(IPOIB_MCAST_RUN, &priv->flags)) 584 if (!test_and_set_bit(IPOIB_MCAST_RUN, &priv->flags))
584 queue_work(ipoib_workqueue, &priv->mcast_task); 585 queue_work(ipoib_workqueue, &priv->mcast_task);
585 up(&mcast_mutex); 586 mutex_unlock(&mcast_mutex);
586 587
587 return 0; 588 return 0;
588} 589}
@@ -594,10 +595,10 @@ int ipoib_mcast_stop_thread(struct net_device *dev, int flush)
594 595
595 ipoib_dbg_mcast(priv, "stopping multicast thread\n"); 596 ipoib_dbg_mcast(priv, "stopping multicast thread\n");
596 597
597 down(&mcast_mutex); 598 mutex_lock(&mcast_mutex);
598 clear_bit(IPOIB_MCAST_RUN, &priv->flags); 599 clear_bit(IPOIB_MCAST_RUN, &priv->flags);
599 cancel_delayed_work(&priv->mcast_task); 600 cancel_delayed_work(&priv->mcast_task);
600 up(&mcast_mutex); 601 mutex_unlock(&mcast_mutex);
601 602
602 if (flush) 603 if (flush)
603 flush_workqueue(ipoib_workqueue); 604 flush_workqueue(ipoib_workqueue);
@@ -741,48 +742,23 @@ void ipoib_mcast_dev_flush(struct net_device *dev)
741{ 742{
742 struct ipoib_dev_priv *priv = netdev_priv(dev); 743 struct ipoib_dev_priv *priv = netdev_priv(dev);
743 LIST_HEAD(remove_list); 744 LIST_HEAD(remove_list);
744 struct ipoib_mcast *mcast, *tmcast, *nmcast; 745 struct ipoib_mcast *mcast, *tmcast;
745 unsigned long flags; 746 unsigned long flags;
746 747
747 ipoib_dbg_mcast(priv, "flushing multicast list\n"); 748 ipoib_dbg_mcast(priv, "flushing multicast list\n");
748 749
749 spin_lock_irqsave(&priv->lock, flags); 750 spin_lock_irqsave(&priv->lock, flags);
750 list_for_each_entry_safe(mcast, tmcast, &priv->multicast_list, list) {
751 nmcast = ipoib_mcast_alloc(dev, 0);
752 if (nmcast) {
753 nmcast->flags =
754 mcast->flags & (1 << IPOIB_MCAST_FLAG_SENDONLY);
755 751
756 nmcast->mcmember.mgid = mcast->mcmember.mgid; 752 list_for_each_entry_safe(mcast, tmcast, &priv->multicast_list, list) {
757 753 list_del(&mcast->list);
758 /* Add the new group in before the to-be-destroyed group */ 754 rb_erase(&mcast->rb_node, &priv->multicast_tree);
759 list_add_tail(&nmcast->list, &mcast->list); 755 list_add_tail(&mcast->list, &remove_list);
760 list_del_init(&mcast->list);
761
762 rb_replace_node(&mcast->rb_node, &nmcast->rb_node,
763 &priv->multicast_tree);
764
765 list_add_tail(&mcast->list, &remove_list);
766 } else {
767 ipoib_warn(priv, "could not reallocate multicast group "
768 IPOIB_GID_FMT "\n",
769 IPOIB_GID_ARG(mcast->mcmember.mgid));
770 }
771 } 756 }
772 757
773 if (priv->broadcast) { 758 if (priv->broadcast) {
774 nmcast = ipoib_mcast_alloc(dev, 0); 759 rb_erase(&priv->broadcast->rb_node, &priv->multicast_tree);
775 if (nmcast) { 760 list_add_tail(&priv->broadcast->list, &remove_list);
776 nmcast->mcmember.mgid = priv->broadcast->mcmember.mgid; 761 priv->broadcast = NULL;
777
778 rb_replace_node(&priv->broadcast->rb_node,
779 &nmcast->rb_node,
780 &priv->multicast_tree);
781
782 list_add_tail(&priv->broadcast->list, &remove_list);
783 }
784
785 priv->broadcast = nmcast;
786 } 762 }
787 763
788 spin_unlock_irqrestore(&priv->lock, flags); 764 spin_unlock_irqrestore(&priv->lock, flags);
@@ -793,24 +769,6 @@ void ipoib_mcast_dev_flush(struct net_device *dev)
793 } 769 }
794} 770}
795 771
796void ipoib_mcast_dev_down(struct net_device *dev)
797{
798 struct ipoib_dev_priv *priv = netdev_priv(dev);
799 unsigned long flags;
800
801 /* Delete broadcast since it will be recreated */
802 if (priv->broadcast) {
803 ipoib_dbg_mcast(priv, "deleting broadcast group\n");
804
805 spin_lock_irqsave(&priv->lock, flags);
806 rb_erase(&priv->broadcast->rb_node, &priv->multicast_tree);
807 spin_unlock_irqrestore(&priv->lock, flags);
808 ipoib_mcast_leave(dev, priv->broadcast);
809 ipoib_mcast_free(priv->broadcast);
810 priv->broadcast = NULL;
811 }
812}
813
814void ipoib_mcast_restart_task(void *dev_ptr) 772void ipoib_mcast_restart_task(void *dev_ptr)
815{ 773{
816 struct net_device *dev = dev_ptr; 774 struct net_device *dev = dev_ptr;
@@ -824,7 +782,8 @@ void ipoib_mcast_restart_task(void *dev_ptr)
824 782
825 ipoib_mcast_stop_thread(dev, 0); 783 ipoib_mcast_stop_thread(dev, 0);
826 784
827 spin_lock_irqsave(&priv->lock, flags); 785 spin_lock_irqsave(&dev->xmit_lock, flags);
786 spin_lock(&priv->lock);
828 787
829 /* 788 /*
830 * Unfortunately, the networking core only gives us a list of all of 789 * Unfortunately, the networking core only gives us a list of all of
@@ -896,7 +855,9 @@ void ipoib_mcast_restart_task(void *dev_ptr)
896 list_add_tail(&mcast->list, &remove_list); 855 list_add_tail(&mcast->list, &remove_list);
897 } 856 }
898 } 857 }
899 spin_unlock_irqrestore(&priv->lock, flags); 858
859 spin_unlock(&priv->lock);
860 spin_unlock_irqrestore(&dev->xmit_lock, flags);
900 861
901 /* We have to cancel outside of the spinlock */ 862 /* We have to cancel outside of the spinlock */
902 list_for_each_entry_safe(mcast, tmcast, &remove_list, list) { 863 list_for_each_entry_safe(mcast, tmcast, &remove_list, list) {
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_verbs.c b/drivers/infiniband/ulp/ipoib/ipoib_verbs.c
index e829e10400e3..faaf10e5fc7b 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_verbs.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_verbs.c
@@ -65,9 +65,9 @@ int ipoib_mcast_attach(struct net_device *dev, u16 mlid, union ib_gid *mgid)
65 } 65 }
66 66
67 /* attach QP to multicast group */ 67 /* attach QP to multicast group */
68 down(&priv->mcast_mutex); 68 mutex_lock(&priv->mcast_mutex);
69 ret = ib_attach_mcast(priv->qp, mgid, mlid); 69 ret = ib_attach_mcast(priv->qp, mgid, mlid);
70 up(&priv->mcast_mutex); 70 mutex_unlock(&priv->mcast_mutex);
71 if (ret) 71 if (ret)
72 ipoib_warn(priv, "failed to attach to multicast group, ret = %d\n", ret); 72 ipoib_warn(priv, "failed to attach to multicast group, ret = %d\n", ret);
73 73
@@ -81,9 +81,9 @@ int ipoib_mcast_detach(struct net_device *dev, u16 mlid, union ib_gid *mgid)
81 struct ipoib_dev_priv *priv = netdev_priv(dev); 81 struct ipoib_dev_priv *priv = netdev_priv(dev);
82 int ret; 82 int ret;
83 83
84 down(&priv->mcast_mutex); 84 mutex_lock(&priv->mcast_mutex);
85 ret = ib_detach_mcast(priv->qp, mgid, mlid); 85 ret = ib_detach_mcast(priv->qp, mgid, mlid);
86 up(&priv->mcast_mutex); 86 mutex_unlock(&priv->mcast_mutex);
87 if (ret) 87 if (ret)
88 ipoib_warn(priv, "ib_detach_mcast failed (result = %d)\n", ret); 88 ipoib_warn(priv, "ib_detach_mcast failed (result = %d)\n", ret);
89 89
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_vlan.c b/drivers/infiniband/ulp/ipoib/ipoib_vlan.c
index d280b341a37f..4ca175553f9f 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_vlan.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_vlan.c
@@ -63,7 +63,7 @@ int ipoib_vlan_add(struct net_device *pdev, unsigned short pkey)
63 63
64 ppriv = netdev_priv(pdev); 64 ppriv = netdev_priv(pdev);
65 65
66 down(&ppriv->vlan_mutex); 66 mutex_lock(&ppriv->vlan_mutex);
67 67
68 /* 68 /*
69 * First ensure this isn't a duplicate. We check the parent device and 69 * First ensure this isn't a duplicate. We check the parent device and
@@ -124,7 +124,7 @@ int ipoib_vlan_add(struct net_device *pdev, unsigned short pkey)
124 124
125 list_add_tail(&priv->list, &ppriv->child_intfs); 125 list_add_tail(&priv->list, &ppriv->child_intfs);
126 126
127 up(&ppriv->vlan_mutex); 127 mutex_unlock(&ppriv->vlan_mutex);
128 128
129 return 0; 129 return 0;
130 130
@@ -139,7 +139,7 @@ device_init_failed:
139 free_netdev(priv->dev); 139 free_netdev(priv->dev);
140 140
141err: 141err:
142 up(&ppriv->vlan_mutex); 142 mutex_unlock(&ppriv->vlan_mutex);
143 return result; 143 return result;
144} 144}
145 145
@@ -153,7 +153,7 @@ int ipoib_vlan_delete(struct net_device *pdev, unsigned short pkey)
153 153
154 ppriv = netdev_priv(pdev); 154 ppriv = netdev_priv(pdev);
155 155
156 down(&ppriv->vlan_mutex); 156 mutex_lock(&ppriv->vlan_mutex);
157 list_for_each_entry_safe(priv, tpriv, &ppriv->child_intfs, list) { 157 list_for_each_entry_safe(priv, tpriv, &ppriv->child_intfs, list) {
158 if (priv->pkey == pkey) { 158 if (priv->pkey == pkey) {
159 unregister_netdev(priv->dev); 159 unregister_netdev(priv->dev);
@@ -167,7 +167,7 @@ int ipoib_vlan_delete(struct net_device *pdev, unsigned short pkey)
167 break; 167 break;
168 } 168 }
169 } 169 }
170 up(&ppriv->vlan_mutex); 170 mutex_unlock(&ppriv->vlan_mutex);
171 171
172 return ret; 172 return ret;
173} 173}
diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
index dd488d3cffa9..31207e664148 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.c
+++ b/drivers/infiniband/ulp/srp/ib_srp.c
@@ -1516,8 +1516,7 @@ static ssize_t show_port(struct class_device *class_dev, char *buf)
1516 1516
1517static CLASS_DEVICE_ATTR(port, S_IRUGO, show_port, NULL); 1517static CLASS_DEVICE_ATTR(port, S_IRUGO, show_port, NULL);
1518 1518
1519static struct srp_host *srp_add_port(struct ib_device *device, 1519static struct srp_host *srp_add_port(struct ib_device *device, u8 port)
1520 __be64 node_guid, u8 port)
1521{ 1520{
1522 struct srp_host *host; 1521 struct srp_host *host;
1523 1522
@@ -1532,7 +1531,7 @@ static struct srp_host *srp_add_port(struct ib_device *device,
1532 host->port = port; 1531 host->port = port;
1533 1532
1534 host->initiator_port_id[7] = port; 1533 host->initiator_port_id[7] = port;
1535 memcpy(host->initiator_port_id + 8, &node_guid, 8); 1534 memcpy(host->initiator_port_id + 8, &device->node_guid, 8);
1536 1535
1537 host->pd = ib_alloc_pd(device); 1536 host->pd = ib_alloc_pd(device);
1538 if (IS_ERR(host->pd)) 1537 if (IS_ERR(host->pd))
@@ -1580,22 +1579,11 @@ static void srp_add_one(struct ib_device *device)
1580{ 1579{
1581 struct list_head *dev_list; 1580 struct list_head *dev_list;
1582 struct srp_host *host; 1581 struct srp_host *host;
1583 struct ib_device_attr *dev_attr;
1584 int s, e, p; 1582 int s, e, p;
1585 1583
1586 dev_attr = kmalloc(sizeof *dev_attr, GFP_KERNEL);
1587 if (!dev_attr)
1588 return;
1589
1590 if (ib_query_device(device, dev_attr)) {
1591 printk(KERN_WARNING PFX "Couldn't query node GUID for %s.\n",
1592 device->name);
1593 goto out;
1594 }
1595
1596 dev_list = kmalloc(sizeof *dev_list, GFP_KERNEL); 1584 dev_list = kmalloc(sizeof *dev_list, GFP_KERNEL);
1597 if (!dev_list) 1585 if (!dev_list)
1598 goto out; 1586 return;
1599 1587
1600 INIT_LIST_HEAD(dev_list); 1588 INIT_LIST_HEAD(dev_list);
1601 1589
@@ -1608,15 +1596,12 @@ static void srp_add_one(struct ib_device *device)
1608 } 1596 }
1609 1597
1610 for (p = s; p <= e; ++p) { 1598 for (p = s; p <= e; ++p) {
1611 host = srp_add_port(device, dev_attr->node_guid, p); 1599 host = srp_add_port(device, p);
1612 if (host) 1600 if (host)
1613 list_add_tail(&host->list, dev_list); 1601 list_add_tail(&host->list, dev_list);
1614 } 1602 }
1615 1603
1616 ib_set_client_data(device, &srp_client, dev_list); 1604 ib_set_client_data(device, &srp_client, dev_list);
1617
1618out:
1619 kfree(dev_attr);
1620} 1605}
1621 1606
1622static void srp_remove_one(struct ib_device *device) 1607static void srp_remove_one(struct ib_device *device)
diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index 24474335dfd1..2141501e9f2e 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -348,6 +348,40 @@ static int alps_tap_mode(struct psmouse *psmouse, int enable)
348 return 0; 348 return 0;
349} 349}
350 350
351/*
352 * alps_poll() - poll the touchpad for current motion packet.
353 * Used in resync.
354 */
355static int alps_poll(struct psmouse *psmouse)
356{
357 struct alps_data *priv = psmouse->private;
358 unsigned char buf[6];
359 int poll_failed;
360
361 if (priv->i->flags & ALPS_PASS)
362 alps_passthrough_mode(psmouse, 1);
363
364 poll_failed = ps2_command(&psmouse->ps2dev, buf,
365 PSMOUSE_CMD_POLL | (psmouse->pktsize << 8)) < 0;
366
367 if (priv->i->flags & ALPS_PASS)
368 alps_passthrough_mode(psmouse, 0);
369
370 if (poll_failed || (buf[0] & priv->i->mask0) != priv->i->byte0)
371 return -1;
372
373 if ((psmouse->badbyte & 0xc8) == 0x08) {
374/*
375 * Poll the track stick ...
376 */
377 if (ps2_command(&psmouse->ps2dev, buf, PSMOUSE_CMD_POLL | (3 << 8)))
378 return -1;
379 }
380
381 memcpy(psmouse->packet, buf, sizeof(buf));
382 return 0;
383}
384
351static int alps_reconnect(struct psmouse *psmouse) 385static int alps_reconnect(struct psmouse *psmouse)
352{ 386{
353 struct alps_data *priv = psmouse->private; 387 struct alps_data *priv = psmouse->private;
@@ -451,10 +485,14 @@ int alps_init(struct psmouse *psmouse)
451 input_register_device(priv->dev2); 485 input_register_device(priv->dev2);
452 486
453 psmouse->protocol_handler = alps_process_byte; 487 psmouse->protocol_handler = alps_process_byte;
488 psmouse->poll = alps_poll;
454 psmouse->disconnect = alps_disconnect; 489 psmouse->disconnect = alps_disconnect;
455 psmouse->reconnect = alps_reconnect; 490 psmouse->reconnect = alps_reconnect;
456 psmouse->pktsize = 6; 491 psmouse->pktsize = 6;
457 492
493 /* We are having trouble resyncing ALPS touchpads so disable it for now */
494 psmouse->resync_time = 0;
495
458 return 0; 496 return 0;
459 497
460init_fail: 498init_fail:
diff --git a/drivers/input/mouse/logips2pp.c b/drivers/input/mouse/logips2pp.c
index 025a71de5404..c88520d3d13c 100644
--- a/drivers/input/mouse/logips2pp.c
+++ b/drivers/input/mouse/logips2pp.c
@@ -117,7 +117,7 @@ static int ps2pp_cmd(struct psmouse *psmouse, unsigned char *param, unsigned cha
117 if (psmouse_sliced_command(psmouse, command)) 117 if (psmouse_sliced_command(psmouse, command))
118 return -1; 118 return -1;
119 119
120 if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_POLL)) 120 if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_POLL | 0x0300))
121 return -1; 121 return -1;
122 122
123 return 0; 123 return 0;
diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
index 4d5ecc04c5b6..7665fd9ce559 100644
--- a/drivers/input/mouse/psmouse-base.c
+++ b/drivers/input/mouse/psmouse-base.c
@@ -54,10 +54,14 @@ static unsigned int psmouse_smartscroll = 1;
54module_param_named(smartscroll, psmouse_smartscroll, bool, 0644); 54module_param_named(smartscroll, psmouse_smartscroll, bool, 0644);
55MODULE_PARM_DESC(smartscroll, "Logitech Smartscroll autorepeat, 1 = enabled (default), 0 = disabled."); 55MODULE_PARM_DESC(smartscroll, "Logitech Smartscroll autorepeat, 1 = enabled (default), 0 = disabled.");
56 56
57static unsigned int psmouse_resetafter; 57static unsigned int psmouse_resetafter = 5;
58module_param_named(resetafter, psmouse_resetafter, uint, 0644); 58module_param_named(resetafter, psmouse_resetafter, uint, 0644);
59MODULE_PARM_DESC(resetafter, "Reset device after so many bad packets (0 = never)."); 59MODULE_PARM_DESC(resetafter, "Reset device after so many bad packets (0 = never).");
60 60
61static unsigned int psmouse_resync_time = 5;
62module_param_named(resync_time, psmouse_resync_time, uint, 0644);
63MODULE_PARM_DESC(resync_time, "How long can mouse stay idle before forcing resync (in seconds, 0 = never).");
64
61PSMOUSE_DEFINE_ATTR(protocol, S_IWUSR | S_IRUGO, 65PSMOUSE_DEFINE_ATTR(protocol, S_IWUSR | S_IRUGO,
62 NULL, 66 NULL,
63 psmouse_attr_show_protocol, psmouse_attr_set_protocol); 67 psmouse_attr_show_protocol, psmouse_attr_set_protocol);
@@ -70,12 +74,16 @@ PSMOUSE_DEFINE_ATTR(resolution, S_IWUSR | S_IRUGO,
70PSMOUSE_DEFINE_ATTR(resetafter, S_IWUSR | S_IRUGO, 74PSMOUSE_DEFINE_ATTR(resetafter, S_IWUSR | S_IRUGO,
71 (void *) offsetof(struct psmouse, resetafter), 75 (void *) offsetof(struct psmouse, resetafter),
72 psmouse_show_int_attr, psmouse_set_int_attr); 76 psmouse_show_int_attr, psmouse_set_int_attr);
77PSMOUSE_DEFINE_ATTR(resync_time, S_IWUSR | S_IRUGO,
78 (void *) offsetof(struct psmouse, resync_time),
79 psmouse_show_int_attr, psmouse_set_int_attr);
73 80
74static struct attribute *psmouse_attributes[] = { 81static struct attribute *psmouse_attributes[] = {
75 &psmouse_attr_protocol.dattr.attr, 82 &psmouse_attr_protocol.dattr.attr,
76 &psmouse_attr_rate.dattr.attr, 83 &psmouse_attr_rate.dattr.attr,
77 &psmouse_attr_resolution.dattr.attr, 84 &psmouse_attr_resolution.dattr.attr,
78 &psmouse_attr_resetafter.dattr.attr, 85 &psmouse_attr_resetafter.dattr.attr,
86 &psmouse_attr_resync_time.dattr.attr,
79 NULL 87 NULL
80}; 88};
81 89
@@ -98,6 +106,8 @@ __obsolete_setup("psmouse_rate=");
98 */ 106 */
99static DECLARE_MUTEX(psmouse_sem); 107static DECLARE_MUTEX(psmouse_sem);
100 108
109static struct workqueue_struct *kpsmoused_wq;
110
101struct psmouse_protocol { 111struct psmouse_protocol {
102 enum psmouse_type type; 112 enum psmouse_type type;
103 char *name; 113 char *name;
@@ -178,15 +188,79 @@ static psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse, struct pt_reg
178} 188}
179 189
180/* 190/*
181 * psmouse_interrupt() handles incoming characters, either gathering them into 191 * __psmouse_set_state() sets new psmouse state and resets all flags.
182 * packets or passing them to the command routine as command output. 192 */
193
194static inline void __psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state)
195{
196 psmouse->state = new_state;
197 psmouse->pktcnt = psmouse->out_of_sync = 0;
198 psmouse->ps2dev.flags = 0;
199 psmouse->last = jiffies;
200}
201
202
203/*
204 * psmouse_set_state() sets new psmouse state and resets all flags and
205 * counters while holding serio lock so fighting with interrupt handler
206 * is not a concern.
207 */
208
209static void psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state)
210{
211 serio_pause_rx(psmouse->ps2dev.serio);
212 __psmouse_set_state(psmouse, new_state);
213 serio_continue_rx(psmouse->ps2dev.serio);
214}
215
216/*
217 * psmouse_handle_byte() processes one byte of the input data stream
218 * by calling corresponding protocol handler.
219 */
220
221static int psmouse_handle_byte(struct psmouse *psmouse, struct pt_regs *regs)
222{
223 psmouse_ret_t rc = psmouse->protocol_handler(psmouse, regs);
224
225 switch (rc) {
226 case PSMOUSE_BAD_DATA:
227 if (psmouse->state == PSMOUSE_ACTIVATED) {
228 printk(KERN_WARNING "psmouse.c: %s at %s lost sync at byte %d\n",
229 psmouse->name, psmouse->phys, psmouse->pktcnt);
230 if (++psmouse->out_of_sync == psmouse->resetafter) {
231 __psmouse_set_state(psmouse, PSMOUSE_IGNORE);
232 printk(KERN_NOTICE "psmouse.c: issuing reconnect request\n");
233 serio_reconnect(psmouse->ps2dev.serio);
234 return -1;
235 }
236 }
237 psmouse->pktcnt = 0;
238 break;
239
240 case PSMOUSE_FULL_PACKET:
241 psmouse->pktcnt = 0;
242 if (psmouse->out_of_sync) {
243 psmouse->out_of_sync = 0;
244 printk(KERN_NOTICE "psmouse.c: %s at %s - driver resynched.\n",
245 psmouse->name, psmouse->phys);
246 }
247 break;
248
249 case PSMOUSE_GOOD_DATA:
250 break;
251 }
252 return 0;
253}
254
255/*
256 * psmouse_interrupt() handles incoming characters, either passing them
257 * for normal processing or gathering them as command response.
183 */ 258 */
184 259
185static irqreturn_t psmouse_interrupt(struct serio *serio, 260static irqreturn_t psmouse_interrupt(struct serio *serio,
186 unsigned char data, unsigned int flags, struct pt_regs *regs) 261 unsigned char data, unsigned int flags, struct pt_regs *regs)
187{ 262{
188 struct psmouse *psmouse = serio_get_drvdata(serio); 263 struct psmouse *psmouse = serio_get_drvdata(serio);
189 psmouse_ret_t rc;
190 264
191 if (psmouse->state == PSMOUSE_IGNORE) 265 if (psmouse->state == PSMOUSE_IGNORE)
192 goto out; 266 goto out;
@@ -208,67 +282,58 @@ static irqreturn_t psmouse_interrupt(struct serio *serio,
208 if (ps2_handle_response(&psmouse->ps2dev, data)) 282 if (ps2_handle_response(&psmouse->ps2dev, data))
209 goto out; 283 goto out;
210 284
211 if (psmouse->state == PSMOUSE_INITIALIZING) 285 if (psmouse->state <= PSMOUSE_RESYNCING)
212 goto out; 286 goto out;
213 287
214 if (psmouse->state == PSMOUSE_ACTIVATED && 288 if (psmouse->state == PSMOUSE_ACTIVATED &&
215 psmouse->pktcnt && time_after(jiffies, psmouse->last + HZ/2)) { 289 psmouse->pktcnt && time_after(jiffies, psmouse->last + HZ/2)) {
216 printk(KERN_WARNING "psmouse.c: %s at %s lost synchronization, throwing %d bytes away.\n", 290 printk(KERN_INFO "psmouse.c: %s at %s lost synchronization, throwing %d bytes away.\n",
217 psmouse->name, psmouse->phys, psmouse->pktcnt); 291 psmouse->name, psmouse->phys, psmouse->pktcnt);
218 psmouse->pktcnt = 0; 292 psmouse->badbyte = psmouse->packet[0];
293 __psmouse_set_state(psmouse, PSMOUSE_RESYNCING);
294 queue_work(kpsmoused_wq, &psmouse->resync_work);
295 goto out;
219 } 296 }
220 297
221 psmouse->last = jiffies;
222 psmouse->packet[psmouse->pktcnt++] = data; 298 psmouse->packet[psmouse->pktcnt++] = data;
223 299/*
224 if (psmouse->packet[0] == PSMOUSE_RET_BAT) { 300 * Check if this is a new device announcement (0xAA 0x00)
301 */
302 if (unlikely(psmouse->packet[0] == PSMOUSE_RET_BAT && psmouse->pktcnt <= 2)) {
225 if (psmouse->pktcnt == 1) 303 if (psmouse->pktcnt == 1)
226 goto out; 304 goto out;
227 305
228 if (psmouse->pktcnt == 2) { 306 if (psmouse->packet[1] == PSMOUSE_RET_ID) {
229 if (psmouse->packet[1] == PSMOUSE_RET_ID) { 307 __psmouse_set_state(psmouse, PSMOUSE_IGNORE);
230 psmouse->state = PSMOUSE_IGNORE; 308 serio_reconnect(serio);
231 serio_reconnect(serio); 309 goto out;
232 goto out;
233 }
234 if (psmouse->type == PSMOUSE_SYNAPTICS) {
235 /* neither 0xAA nor 0x00 are valid first bytes
236 * for a packet in absolute mode
237 */
238 psmouse->pktcnt = 0;
239 goto out;
240 }
241 } 310 }
242 } 311/*
243 312 * Not a new device, try processing first byte normally
244 rc = psmouse->protocol_handler(psmouse, regs); 313 */
314 psmouse->pktcnt = 1;
315 if (psmouse_handle_byte(psmouse, regs))
316 goto out;
245 317
246 switch (rc) { 318 psmouse->packet[psmouse->pktcnt++] = data;
247 case PSMOUSE_BAD_DATA: 319 }
248 printk(KERN_WARNING "psmouse.c: %s at %s lost sync at byte %d\n",
249 psmouse->name, psmouse->phys, psmouse->pktcnt);
250 psmouse->pktcnt = 0;
251 320
252 if (++psmouse->out_of_sync == psmouse->resetafter) { 321/*
253 psmouse->state = PSMOUSE_IGNORE; 322 * See if we need to force resync because mouse was idle for too long
254 printk(KERN_NOTICE "psmouse.c: issuing reconnect request\n"); 323 */
255 serio_reconnect(psmouse->ps2dev.serio); 324 if (psmouse->state == PSMOUSE_ACTIVATED &&
256 } 325 psmouse->pktcnt == 1 && psmouse->resync_time &&
257 break; 326 time_after(jiffies, psmouse->last + psmouse->resync_time * HZ)) {
327 psmouse->badbyte = psmouse->packet[0];
328 __psmouse_set_state(psmouse, PSMOUSE_RESYNCING);
329 queue_work(kpsmoused_wq, &psmouse->resync_work);
330 goto out;
331 }
258 332
259 case PSMOUSE_FULL_PACKET: 333 psmouse->last = jiffies;
260 psmouse->pktcnt = 0; 334 psmouse_handle_byte(psmouse, regs);
261 if (psmouse->out_of_sync) {
262 psmouse->out_of_sync = 0;
263 printk(KERN_NOTICE "psmouse.c: %s at %s - driver resynched.\n",
264 psmouse->name, psmouse->phys);
265 }
266 break;
267 335
268 case PSMOUSE_GOOD_DATA: 336 out:
269 break;
270 }
271out:
272 return IRQ_HANDLED; 337 return IRQ_HANDLED;
273} 338}
274 339
@@ -752,21 +817,6 @@ static void psmouse_initialize(struct psmouse *psmouse)
752} 817}
753 818
754/* 819/*
755 * psmouse_set_state() sets new psmouse state and resets all flags and
756 * counters while holding serio lock so fighting with interrupt handler
757 * is not a concern.
758 */
759
760static void psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state)
761{
762 serio_pause_rx(psmouse->ps2dev.serio);
763 psmouse->state = new_state;
764 psmouse->pktcnt = psmouse->out_of_sync = 0;
765 psmouse->ps2dev.flags = 0;
766 serio_continue_rx(psmouse->ps2dev.serio);
767}
768
769/*
770 * psmouse_activate() enables the mouse so that we get motion reports from it. 820 * psmouse_activate() enables the mouse so that we get motion reports from it.
771 */ 821 */
772 822
@@ -794,6 +844,111 @@ static void psmouse_deactivate(struct psmouse *psmouse)
794 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); 844 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
795} 845}
796 846
847/*
848 * psmouse_poll() - default poll hanlder. Everyone except for ALPS uses it.
849 */
850
851static int psmouse_poll(struct psmouse *psmouse)
852{
853 return ps2_command(&psmouse->ps2dev, psmouse->packet,
854 PSMOUSE_CMD_POLL | (psmouse->pktsize << 8));
855}
856
857
858/*
859 * psmouse_resync() attempts to re-validate current protocol.
860 */
861
862static void psmouse_resync(void *p)
863{
864 struct psmouse *psmouse = p, *parent = NULL;
865 struct serio *serio = psmouse->ps2dev.serio;
866 psmouse_ret_t rc = PSMOUSE_GOOD_DATA;
867 int failed = 0, enabled = 0;
868 int i;
869
870 down(&psmouse_sem);
871
872 if (psmouse->state != PSMOUSE_RESYNCING)
873 goto out;
874
875 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
876 parent = serio_get_drvdata(serio->parent);
877 psmouse_deactivate(parent);
878 }
879
880/*
881 * Some mice don't ACK commands sent while they are in the middle of
882 * transmitting motion packet. To avoid delay we use ps2_sendbyte()
883 * instead of ps2_command() which would wait for 200ms for an ACK
884 * that may never come.
885 * As an additional quirk ALPS touchpads may not only forget to ACK
886 * disable command but will stop reporting taps, so if we see that
887 * mouse at least once ACKs disable we will do full reconnect if ACK
888 * is missing.
889 */
890 psmouse->num_resyncs++;
891
892 if (ps2_sendbyte(&psmouse->ps2dev, PSMOUSE_CMD_DISABLE, 20)) {
893 if (psmouse->num_resyncs < 3 || psmouse->acks_disable_command)
894 failed = 1;
895 } else
896 psmouse->acks_disable_command = 1;
897
898/*
899 * Poll the mouse. If it was reset the packet will be shorter than
900 * psmouse->pktsize and ps2_command will fail. We do not expect and
901 * do not handle scenario when mouse "upgrades" its protocol while
902 * disconnected since it would require additional delay. If we ever
903 * see a mouse that does it we'll adjust the code.
904 */
905 if (!failed) {
906 if (psmouse->poll(psmouse))
907 failed = 1;
908 else {
909 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
910 for (i = 0; i < psmouse->pktsize; i++) {
911 psmouse->pktcnt++;
912 rc = psmouse->protocol_handler(psmouse, NULL);
913 if (rc != PSMOUSE_GOOD_DATA)
914 break;
915 }
916 if (rc != PSMOUSE_FULL_PACKET)
917 failed = 1;
918 psmouse_set_state(psmouse, PSMOUSE_RESYNCING);
919 }
920 }
921/*
922 * Now try to enable mouse. We try to do that even if poll failed and also
923 * repeat our attempts 5 times, otherwise we may be left out with disabled
924 * mouse.
925 */
926 for (i = 0; i < 5; i++) {
927 if (!ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_ENABLE)) {
928 enabled = 1;
929 break;
930 }
931 msleep(200);
932 }
933
934 if (!enabled) {
935 printk(KERN_WARNING "psmouse.c: failed to re-enable mouse on %s\n",
936 psmouse->ps2dev.serio->phys);
937 failed = 1;
938 }
939
940 if (failed) {
941 psmouse_set_state(psmouse, PSMOUSE_IGNORE);
942 printk(KERN_INFO "psmouse.c: resync failed, issuing reconnect request\n");
943 serio_reconnect(serio);
944 } else
945 psmouse_set_state(psmouse, PSMOUSE_ACTIVATED);
946
947 if (parent)
948 psmouse_activate(parent);
949 out:
950 up(&psmouse_sem);
951}
797 952
798/* 953/*
799 * psmouse_cleanup() resets the mouse into power-on state. 954 * psmouse_cleanup() resets the mouse into power-on state.
@@ -822,6 +977,11 @@ static void psmouse_disconnect(struct serio *serio)
822 977
823 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); 978 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
824 979
980 /* make sure we don't have a resync in progress */
981 up(&psmouse_sem);
982 flush_workqueue(kpsmoused_wq);
983 down(&psmouse_sem);
984
825 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { 985 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
826 parent = serio_get_drvdata(serio->parent); 986 parent = serio_get_drvdata(serio->parent);
827 psmouse_deactivate(parent); 987 psmouse_deactivate(parent);
@@ -859,6 +1019,7 @@ static int psmouse_switch_protocol(struct psmouse *psmouse, struct psmouse_proto
859 1019
860 psmouse->set_rate = psmouse_set_rate; 1020 psmouse->set_rate = psmouse_set_rate;
861 psmouse->set_resolution = psmouse_set_resolution; 1021 psmouse->set_resolution = psmouse_set_resolution;
1022 psmouse->poll = psmouse_poll;
862 psmouse->protocol_handler = psmouse_process_byte; 1023 psmouse->protocol_handler = psmouse_process_byte;
863 psmouse->pktsize = 3; 1024 psmouse->pktsize = 3;
864 1025
@@ -874,6 +1035,23 @@ static int psmouse_switch_protocol(struct psmouse *psmouse, struct psmouse_proto
874 else 1035 else
875 psmouse->type = psmouse_extensions(psmouse, psmouse_max_proto, 1); 1036 psmouse->type = psmouse_extensions(psmouse, psmouse_max_proto, 1);
876 1037
1038 /*
1039 * If mouse's packet size is 3 there is no point in polling the
1040 * device in hopes to detect protocol reset - we won't get less
1041 * than 3 bytes response anyhow.
1042 */
1043 if (psmouse->pktsize == 3)
1044 psmouse->resync_time = 0;
1045
1046 /*
1047 * Some smart KVMs fake response to POLL command returning just
1048 * 3 bytes and messing up our resync logic, so if initial poll
1049 * fails we won't try polling the device anymore. Hopefully
1050 * such KVM will maintain initially selected protocol.
1051 */
1052 if (psmouse->resync_time && psmouse->poll(psmouse))
1053 psmouse->resync_time = 0;
1054
877 sprintf(psmouse->devname, "%s %s %s", 1055 sprintf(psmouse->devname, "%s %s %s",
878 psmouse_protocol_by_type(psmouse->type)->name, psmouse->vendor, psmouse->name); 1056 psmouse_protocol_by_type(psmouse->type)->name, psmouse->vendor, psmouse->name);
879 1057
@@ -914,6 +1092,7 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
914 goto out; 1092 goto out;
915 1093
916 ps2_init(&psmouse->ps2dev, serio); 1094 ps2_init(&psmouse->ps2dev, serio);
1095 INIT_WORK(&psmouse->resync_work, psmouse_resync, psmouse);
917 psmouse->dev = input_dev; 1096 psmouse->dev = input_dev;
918 sprintf(psmouse->phys, "%s/input0", serio->phys); 1097 sprintf(psmouse->phys, "%s/input0", serio->phys);
919 1098
@@ -934,6 +1113,7 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
934 psmouse->rate = psmouse_rate; 1113 psmouse->rate = psmouse_rate;
935 psmouse->resolution = psmouse_resolution; 1114 psmouse->resolution = psmouse_resolution;
936 psmouse->resetafter = psmouse_resetafter; 1115 psmouse->resetafter = psmouse_resetafter;
1116 psmouse->resync_time = parent ? 0 : psmouse_resync_time;
937 psmouse->smartscroll = psmouse_smartscroll; 1117 psmouse->smartscroll = psmouse_smartscroll;
938 1118
939 psmouse_switch_protocol(psmouse, NULL); 1119 psmouse_switch_protocol(psmouse, NULL);
@@ -1278,13 +1458,21 @@ static int psmouse_get_maxproto(char *buffer, struct kernel_param *kp)
1278 1458
1279static int __init psmouse_init(void) 1459static int __init psmouse_init(void)
1280{ 1460{
1461 kpsmoused_wq = create_singlethread_workqueue("kpsmoused");
1462 if (!kpsmoused_wq) {
1463 printk(KERN_ERR "psmouse: failed to create kpsmoused workqueue\n");
1464 return -ENOMEM;
1465 }
1466
1281 serio_register_driver(&psmouse_drv); 1467 serio_register_driver(&psmouse_drv);
1468
1282 return 0; 1469 return 0;
1283} 1470}
1284 1471
1285static void __exit psmouse_exit(void) 1472static void __exit psmouse_exit(void)
1286{ 1473{
1287 serio_unregister_driver(&psmouse_drv); 1474 serio_unregister_driver(&psmouse_drv);
1475 destroy_workqueue(kpsmoused_wq);
1288} 1476}
1289 1477
1290module_init(psmouse_init); 1478module_init(psmouse_init);
diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
index 7c4192bd1279..4d9107fba6a1 100644
--- a/drivers/input/mouse/psmouse.h
+++ b/drivers/input/mouse/psmouse.h
@@ -7,7 +7,7 @@
7#define PSMOUSE_CMD_GETINFO 0x03e9 7#define PSMOUSE_CMD_GETINFO 0x03e9
8#define PSMOUSE_CMD_SETSTREAM 0x00ea 8#define PSMOUSE_CMD_SETSTREAM 0x00ea
9#define PSMOUSE_CMD_SETPOLL 0x00f0 9#define PSMOUSE_CMD_SETPOLL 0x00f0
10#define PSMOUSE_CMD_POLL 0x03eb 10#define PSMOUSE_CMD_POLL 0x00eb /* caller sets number of bytes to receive */
11#define PSMOUSE_CMD_GETID 0x02f2 11#define PSMOUSE_CMD_GETID 0x02f2
12#define PSMOUSE_CMD_SETRATE 0x10f3 12#define PSMOUSE_CMD_SETRATE 0x10f3
13#define PSMOUSE_CMD_ENABLE 0x00f4 13#define PSMOUSE_CMD_ENABLE 0x00f4
@@ -23,6 +23,7 @@
23enum psmouse_state { 23enum psmouse_state {
24 PSMOUSE_IGNORE, 24 PSMOUSE_IGNORE,
25 PSMOUSE_INITIALIZING, 25 PSMOUSE_INITIALIZING,
26 PSMOUSE_RESYNCING,
26 PSMOUSE_CMD_MODE, 27 PSMOUSE_CMD_MODE,
27 PSMOUSE_ACTIVATED, 28 PSMOUSE_ACTIVATED,
28}; 29};
@@ -38,15 +39,19 @@ struct psmouse {
38 void *private; 39 void *private;
39 struct input_dev *dev; 40 struct input_dev *dev;
40 struct ps2dev ps2dev; 41 struct ps2dev ps2dev;
42 struct work_struct resync_work;
41 char *vendor; 43 char *vendor;
42 char *name; 44 char *name;
43 unsigned char packet[8]; 45 unsigned char packet[8];
46 unsigned char badbyte;
44 unsigned char pktcnt; 47 unsigned char pktcnt;
45 unsigned char pktsize; 48 unsigned char pktsize;
46 unsigned char type; 49 unsigned char type;
50 unsigned char acks_disable_command;
47 unsigned int model; 51 unsigned int model;
48 unsigned long last; 52 unsigned long last;
49 unsigned long out_of_sync; 53 unsigned long out_of_sync;
54 unsigned long num_resyncs;
50 enum psmouse_state state; 55 enum psmouse_state state;
51 char devname[64]; 56 char devname[64];
52 char phys[32]; 57 char phys[32];
@@ -54,6 +59,7 @@ struct psmouse {
54 unsigned int rate; 59 unsigned int rate;
55 unsigned int resolution; 60 unsigned int resolution;
56 unsigned int resetafter; 61 unsigned int resetafter;
62 unsigned int resync_time;
57 unsigned int smartscroll; /* Logitech only */ 63 unsigned int smartscroll; /* Logitech only */
58 64
59 psmouse_ret_t (*protocol_handler)(struct psmouse *psmouse, struct pt_regs *regs); 65 psmouse_ret_t (*protocol_handler)(struct psmouse *psmouse, struct pt_regs *regs);
@@ -62,6 +68,7 @@ struct psmouse {
62 68
63 int (*reconnect)(struct psmouse *psmouse); 69 int (*reconnect)(struct psmouse *psmouse);
64 void (*disconnect)(struct psmouse *psmouse); 70 void (*disconnect)(struct psmouse *psmouse);
71 int (*poll)(struct psmouse *psmouse);
65 72
66 void (*pt_activate)(struct psmouse *psmouse); 73 void (*pt_activate)(struct psmouse *psmouse);
67 void (*pt_deactivate)(struct psmouse *psmouse); 74 void (*pt_deactivate)(struct psmouse *psmouse);
diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
index 97cdfd6acaca..2051bec2c394 100644
--- a/drivers/input/mouse/synaptics.c
+++ b/drivers/input/mouse/synaptics.c
@@ -652,6 +652,8 @@ int synaptics_init(struct psmouse *psmouse)
652 psmouse->disconnect = synaptics_disconnect; 652 psmouse->disconnect = synaptics_disconnect;
653 psmouse->reconnect = synaptics_reconnect; 653 psmouse->reconnect = synaptics_reconnect;
654 psmouse->pktsize = 6; 654 psmouse->pktsize = 6;
655 /* Synaptics can usually stay in sync without extra help */
656 psmouse->resync_time = 0;
655 657
656 if (SYN_CAP_PASS_THROUGH(priv->capabilities)) 658 if (SYN_CAP_PASS_THROUGH(priv->capabilities))
657 synaptics_pt_create(psmouse); 659 synaptics_pt_create(psmouse);
diff --git a/drivers/input/serio/i8042-x86ia64io.h b/drivers/input/serio/i8042-x86ia64io.h
index 2d2f9fb3aded..a4c6f3522723 100644
--- a/drivers/input/serio/i8042-x86ia64io.h
+++ b/drivers/input/serio/i8042-x86ia64io.h
@@ -173,6 +173,13 @@ static struct dmi_system_id __initdata i8042_dmi_nomux_table[] = {
173 DMI_MATCH(DMI_PRODUCT_NAME, "PC-MM20 Series"), 173 DMI_MATCH(DMI_PRODUCT_NAME, "PC-MM20 Series"),
174 }, 174 },
175 }, 175 },
176 {
177 .ident = "Sony Vaio FS-115b",
178 .matches = {
179 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
180 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FS115B"),
181 },
182 },
176 { } 183 { }
177}; 184};
178 185
diff --git a/drivers/macintosh/macio-adb.c b/drivers/macintosh/macio-adb.c
index cf6a6f2248ac..314fc0830d90 100644
--- a/drivers/macintosh/macio-adb.c
+++ b/drivers/macintosh/macio-adb.c
@@ -17,6 +17,7 @@
17#include <asm/irq.h> 17#include <asm/irq.h>
18#include <asm/system.h> 18#include <asm/system.h>
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/ioport.h>
20 21
21struct preg { 22struct preg {
22 unsigned char r; 23 unsigned char r;
@@ -88,24 +89,26 @@ int macio_probe(void)
88int macio_init(void) 89int macio_init(void)
89{ 90{
90 struct device_node *adbs; 91 struct device_node *adbs;
92 struct resource r;
91 93
92 adbs = find_compatible_devices("adb", "chrp,adb0"); 94 adbs = find_compatible_devices("adb", "chrp,adb0");
93 if (adbs == 0) 95 if (adbs == 0)
94 return -ENXIO; 96 return -ENXIO;
95 97
96#if 0 98#if 0
97 { int i; 99 { int i = 0;
98 100
99 printk("macio_adb_init: node = %p, addrs =", adbs->node); 101 printk("macio_adb_init: node = %p, addrs =", adbs->node);
100 for (i = 0; i < adbs->n_addrs; ++i) 102 while(!of_address_to_resource(adbs, i, &r))
101 printk(" %x(%x)", adbs->addrs[i].address, adbs->addrs[i].size); 103 printk(" %x(%x)", r.start, r.end - r.start);
102 printk(", intrs ="); 104 printk(", intrs =");
103 for (i = 0; i < adbs->n_intrs; ++i) 105 for (i = 0; i < adbs->n_intrs; ++i)
104 printk(" %x", adbs->intrs[i].line); 106 printk(" %x", adbs->intrs[i].line);
105 printk("\n"); } 107 printk("\n"); }
106#endif 108#endif
107 109 if (of_address_to_resource(adbs, 0, &r))
108 adb = ioremap(adbs->addrs->address, sizeof(struct adb_regs)); 110 return -ENXIO;
111 adb = ioremap(r.start, sizeof(struct adb_regs));
109 112
110 out_8(&adb->ctrl.r, 0); 113 out_8(&adb->ctrl.r, 0);
111 out_8(&adb->intr.r, 0); 114 out_8(&adb->intr.r, 0);
diff --git a/drivers/sbus/char/aurora.c b/drivers/sbus/char/aurora.c
index 92e6c5639dd3..015db40ad8a4 100644
--- a/drivers/sbus/char/aurora.c
+++ b/drivers/sbus/char/aurora.c
@@ -92,7 +92,6 @@ static struct Aurora_port aurora_port[AURORA_TNPORTS] = {
92 92
93/* no longer used. static struct Aurora_board * IRQ_to_board[16] = { NULL, } ;*/ 93/* no longer used. static struct Aurora_board * IRQ_to_board[16] = { NULL, } ;*/
94static unsigned char * tmp_buf = NULL; 94static unsigned char * tmp_buf = NULL;
95static DECLARE_MUTEX(tmp_buf_sem);
96 95
97DECLARE_TASK_QUEUE(tq_aurora); 96DECLARE_TASK_QUEUE(tq_aurora);
98 97
diff --git a/drivers/serial/68328serial.c b/drivers/serial/68328serial.c
index 4dd5c3f98167..8cbf0fc5a225 100644
--- a/drivers/serial/68328serial.c
+++ b/drivers/serial/68328serial.c
@@ -143,7 +143,6 @@ static int m68328_console_cbaud = DEFAULT_CBAUD;
143 * memory if large numbers of serial ports are open. 143 * memory if large numbers of serial ports are open.
144 */ 144 */
145static unsigned char tmp_buf[SERIAL_XMIT_SIZE]; /* This is cheating */ 145static unsigned char tmp_buf[SERIAL_XMIT_SIZE]; /* This is cheating */
146DECLARE_MUTEX(tmp_buf_sem);
147 146
148static inline int serial_paranoia_check(struct m68k_serial *info, 147static inline int serial_paranoia_check(struct m68k_serial *info,
149 char *name, const char *routine) 148 char *name, const char *routine)
diff --git a/drivers/usb/input/Kconfig b/drivers/usb/input/Kconfig
index 509dd0a04c54..5246b35301de 100644
--- a/drivers/usb/input/Kconfig
+++ b/drivers/usb/input/Kconfig
@@ -37,6 +37,16 @@ config USB_HIDINPUT
37 37
38 If unsure, say Y. 38 If unsure, say Y.
39 39
40config USB_HIDINPUT_POWERBOOK
41 bool "Enable support for iBook/PowerBook special keys"
42 default n
43 depends on USB_HIDINPUT
44 help
45 Say Y here if you want support for the special keys (Fn, Numlock) on
46 Apple iBooks and PowerBooks.
47
48 If unsure, say N.
49
40config HID_FF 50config HID_FF
41 bool "Force feedback support (EXPERIMENTAL)" 51 bool "Force feedback support (EXPERIMENTAL)"
42 depends on USB_HIDINPUT && EXPERIMENTAL 52 depends on USB_HIDINPUT && EXPERIMENTAL
diff --git a/drivers/usb/input/hid-core.c b/drivers/usb/input/hid-core.c
index 5f52979af1c7..a91e72c41415 100644
--- a/drivers/usb/input/hid-core.c
+++ b/drivers/usb/input/hid-core.c
@@ -1450,6 +1450,9 @@ void hid_init_reports(struct hid_device *hid)
1450#define USB_VENDOR_ID_APPLE 0x05ac 1450#define USB_VENDOR_ID_APPLE 0x05ac
1451#define USB_DEVICE_ID_APPLE_POWERMOUSE 0x0304 1451#define USB_DEVICE_ID_APPLE_POWERMOUSE 0x0304
1452 1452
1453#define USB_VENDOR_ID_CHERRY 0x046a
1454#define USB_DEVICE_ID_CHERRY_CYMOTION 0x0023
1455
1453/* 1456/*
1454 * Alphabetically sorted blacklist by quirk type. 1457 * Alphabetically sorted blacklist by quirk type.
1455 */ 1458 */
@@ -1580,6 +1583,16 @@ static const struct hid_blacklist {
1580 { USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RUMBLEPAD, HID_QUIRK_BADPAD }, 1583 { USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RUMBLEPAD, HID_QUIRK_BADPAD },
1581 { USB_VENDOR_ID_TOPMAX, USB_DEVICE_ID_TOPMAX_COBRAPAD, HID_QUIRK_BADPAD }, 1584 { USB_VENDOR_ID_TOPMAX, USB_DEVICE_ID_TOPMAX_COBRAPAD, HID_QUIRK_BADPAD },
1582 1585
1586 { USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION, HID_QUIRK_CYMOTION },
1587
1588 { USB_VENDOR_ID_APPLE, 0x020E, HID_QUIRK_POWERBOOK_HAS_FN },
1589 { USB_VENDOR_ID_APPLE, 0x020F, HID_QUIRK_POWERBOOK_HAS_FN },
1590 { USB_VENDOR_ID_APPLE, 0x0214, HID_QUIRK_POWERBOOK_HAS_FN },
1591 { USB_VENDOR_ID_APPLE, 0x0215, HID_QUIRK_POWERBOOK_HAS_FN },
1592 { USB_VENDOR_ID_APPLE, 0x0216, HID_QUIRK_POWERBOOK_HAS_FN },
1593 { USB_VENDOR_ID_APPLE, 0x030A, HID_QUIRK_POWERBOOK_HAS_FN },
1594 { USB_VENDOR_ID_APPLE, 0x030B, HID_QUIRK_POWERBOOK_HAS_FN },
1595
1583 { 0, 0 } 1596 { 0, 0 }
1584}; 1597};
1585 1598
@@ -1626,6 +1639,20 @@ static void hid_free_buffers(struct usb_device *dev, struct hid_device *hid)
1626 usb_buffer_free(dev, hid->bufsize, hid->ctrlbuf, hid->ctrlbuf_dma); 1639 usb_buffer_free(dev, hid->bufsize, hid->ctrlbuf, hid->ctrlbuf_dma);
1627} 1640}
1628 1641
1642/*
1643 * Cherry Cymotion keyboard have an invalid HID report descriptor,
1644 * that needs fixing before we can parse it.
1645 */
1646
1647static void hid_fixup_cymotion_descriptor(char *rdesc, int rsize)
1648{
1649 if (rsize >= 17 && rdesc[11] == 0x3c && rdesc[12] == 0x02) {
1650 info("Fixing up Cherry Cymotion report descriptor");
1651 rdesc[11] = rdesc[16] = 0xff;
1652 rdesc[12] = rdesc[17] = 0x03;
1653 }
1654}
1655
1629static struct hid_device *usb_hid_configure(struct usb_interface *intf) 1656static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1630{ 1657{
1631 struct usb_host_interface *interface = intf->cur_altsetting; 1658 struct usb_host_interface *interface = intf->cur_altsetting;
@@ -1673,6 +1700,9 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1673 return NULL; 1700 return NULL;
1674 } 1701 }
1675 1702
1703 if ((quirks & HID_QUIRK_CYMOTION))
1704 hid_fixup_cymotion_descriptor(rdesc, rsize);
1705
1676#ifdef DEBUG_DATA 1706#ifdef DEBUG_DATA
1677 printk(KERN_DEBUG __FILE__ ": report descriptor (size %u, read %d) = ", rsize, n); 1707 printk(KERN_DEBUG __FILE__ ": report descriptor (size %u, read %d) = ", rsize, n);
1678 for (n = 0; n < rsize; n++) 1708 for (n = 0; n < rsize; n++)
diff --git a/drivers/usb/input/hid-input.c b/drivers/usb/input/hid-input.c
index 192a03b28971..cb0d80f49252 100644
--- a/drivers/usb/input/hid-input.c
+++ b/drivers/usb/input/hid-input.c
@@ -73,6 +73,160 @@ static const struct {
73#define map_key_clear(c) do { map_key(c); clear_bit(c, bit); } while (0) 73#define map_key_clear(c) do { map_key(c); clear_bit(c, bit); } while (0)
74#define map_ff_effect(c) do { set_bit(c, input->ffbit); } while (0) 74#define map_ff_effect(c) do { set_bit(c, input->ffbit); } while (0)
75 75
76#ifdef CONFIG_USB_HIDINPUT_POWERBOOK
77
78struct hidinput_key_translation {
79 u16 from;
80 u16 to;
81 u8 flags;
82};
83
84#define POWERBOOK_FLAG_FKEY 0x01
85
86static struct hidinput_key_translation powerbook_fn_keys[] = {
87 { KEY_BACKSPACE, KEY_DELETE },
88 { KEY_F1, KEY_BRIGHTNESSDOWN, POWERBOOK_FLAG_FKEY },
89 { KEY_F2, KEY_BRIGHTNESSUP, POWERBOOK_FLAG_FKEY },
90 { KEY_F3, KEY_MUTE, POWERBOOK_FLAG_FKEY },
91 { KEY_F4, KEY_VOLUMEDOWN, POWERBOOK_FLAG_FKEY },
92 { KEY_F5, KEY_VOLUMEUP, POWERBOOK_FLAG_FKEY },
93 { KEY_F6, KEY_NUMLOCK, POWERBOOK_FLAG_FKEY },
94 { KEY_F7, KEY_SWITCHVIDEOMODE, POWERBOOK_FLAG_FKEY },
95 { KEY_F8, KEY_KBDILLUMTOGGLE, POWERBOOK_FLAG_FKEY },
96 { KEY_F9, KEY_KBDILLUMDOWN, POWERBOOK_FLAG_FKEY },
97 { KEY_F10, KEY_KBDILLUMUP, POWERBOOK_FLAG_FKEY },
98 { KEY_UP, KEY_PAGEUP },
99 { KEY_DOWN, KEY_PAGEDOWN },
100 { KEY_LEFT, KEY_HOME },
101 { KEY_RIGHT, KEY_END },
102 { }
103};
104
105static struct hidinput_key_translation powerbook_numlock_keys[] = {
106 { KEY_J, KEY_KP1 },
107 { KEY_K, KEY_KP2 },
108 { KEY_L, KEY_KP3 },
109 { KEY_U, KEY_KP4 },
110 { KEY_I, KEY_KP5 },
111 { KEY_O, KEY_KP6 },
112 { KEY_7, KEY_KP7 },
113 { KEY_8, KEY_KP8 },
114 { KEY_9, KEY_KP9 },
115 { KEY_M, KEY_KP0 },
116 { KEY_DOT, KEY_KPDOT },
117 { KEY_SLASH, KEY_KPPLUS },
118 { KEY_SEMICOLON, KEY_KPMINUS },
119 { KEY_P, KEY_KPASTERISK },
120 { KEY_MINUS, KEY_KPEQUAL },
121 { KEY_0, KEY_KPSLASH },
122 { KEY_F6, KEY_NUMLOCK },
123 { KEY_KPENTER, KEY_KPENTER },
124 { KEY_BACKSPACE, KEY_BACKSPACE },
125 { }
126};
127
128static int usbhid_pb_fnmode = 1;
129module_param_named(pb_fnmode, usbhid_pb_fnmode, int, 0644);
130MODULE_PARM_DESC(pb_fnmode,
131 "Mode of fn key on PowerBooks (0 = disabled, 1 = fkeyslast, 2 = fkeysfirst)");
132
133static struct hidinput_key_translation *find_translation(struct hidinput_key_translation *table, u16 from)
134{
135 struct hidinput_key_translation *trans;
136
137 /* Look for the translation */
138 for (trans = table; trans->from; trans++)
139 if (trans->from == from)
140 return trans;
141
142 return NULL;
143}
144
145static int hidinput_pb_event(struct hid_device *hid, struct input_dev *input,
146 struct hid_usage *usage, __s32 value)
147{
148 struct hidinput_key_translation *trans;
149
150 if (usage->code == KEY_FN) {
151 if (value) hid->quirks |= HID_QUIRK_POWERBOOK_FN_ON;
152 else hid->quirks &= ~HID_QUIRK_POWERBOOK_FN_ON;
153
154 input_event(input, usage->type, usage->code, value);
155
156 return 1;
157 }
158
159 if (usbhid_pb_fnmode) {
160 int do_translate;
161
162 trans = find_translation(powerbook_fn_keys, usage->code);
163 if (trans) {
164 if (test_bit(usage->code, hid->pb_pressed_fn))
165 do_translate = 1;
166 else if (trans->flags & POWERBOOK_FLAG_FKEY)
167 do_translate =
168 (usbhid_pb_fnmode == 2 && (hid->quirks & HID_QUIRK_POWERBOOK_FN_ON)) ||
169 (usbhid_pb_fnmode == 1 && !(hid->quirks & HID_QUIRK_POWERBOOK_FN_ON));
170 else
171 do_translate = (hid->quirks & HID_QUIRK_POWERBOOK_FN_ON);
172
173 if (do_translate) {
174 if (value)
175 set_bit(usage->code, hid->pb_pressed_fn);
176 else
177 clear_bit(usage->code, hid->pb_pressed_fn);
178
179 input_event(input, usage->type, trans->to, value);
180
181 return 1;
182 }
183 }
184
185 if (test_bit(usage->code, hid->pb_pressed_numlock) ||
186 test_bit(LED_NUML, input->led)) {
187 trans = find_translation(powerbook_numlock_keys, usage->code);
188
189 if (trans) {
190 if (value)
191 set_bit(usage->code, hid->pb_pressed_numlock);
192 else
193 clear_bit(usage->code, hid->pb_pressed_numlock);
194
195 input_event(input, usage->type, trans->to, value);
196 }
197
198 return 1;
199 }
200 }
201
202 return 0;
203}
204
205static void hidinput_pb_setup(struct input_dev *input)
206{
207 struct hidinput_key_translation *trans;
208
209 set_bit(KEY_NUMLOCK, input->keybit);
210
211 /* Enable all needed keys */
212 for (trans = powerbook_fn_keys; trans->from; trans++)
213 set_bit(trans->to, input->keybit);
214
215 for (trans = powerbook_numlock_keys; trans->from; trans++)
216 set_bit(trans->to, input->keybit);
217}
218#else
219static inline int hidinput_pb_event(struct hid_device *hid, struct input_dev *input,
220 struct hid_usage *usage, __s32 value)
221{
222 return 0;
223}
224
225static inline void hidinput_pb_setup(struct input_dev *input)
226{
227}
228#endif
229
76static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_field *field, 230static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_field *field,
77 struct hid_usage *usage) 231 struct hid_usage *usage)
78{ 232{
@@ -135,8 +289,11 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
135 case HID_UP_SIMULATION: 289 case HID_UP_SIMULATION:
136 290
137 switch (usage->hid & 0xffff) { 291 switch (usage->hid & 0xffff) {
138 case 0xba: map_abs(ABS_RUDDER); break; 292 case 0xba: map_abs(ABS_RUDDER); break;
139 case 0xbb: map_abs(ABS_THROTTLE); break; 293 case 0xbb: map_abs(ABS_THROTTLE); break;
294 case 0xc4: map_abs(ABS_GAS); break;
295 case 0xc5: map_abs(ABS_BRAKE); break;
296 case 0xc8: map_abs(ABS_WHEEL); break;
140 default: goto ignore; 297 default: goto ignore;
141 } 298 }
142 break; 299 break;
@@ -289,11 +446,19 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
289 case 0x226: map_key_clear(KEY_STOP); break; 446 case 0x226: map_key_clear(KEY_STOP); break;
290 case 0x227: map_key_clear(KEY_REFRESH); break; 447 case 0x227: map_key_clear(KEY_REFRESH); break;
291 case 0x22a: map_key_clear(KEY_BOOKMARKS); break; 448 case 0x22a: map_key_clear(KEY_BOOKMARKS); break;
449 case 0x233: map_key_clear(KEY_SCROLLUP); break;
450 case 0x234: map_key_clear(KEY_SCROLLDOWN); break;
292 case 0x238: map_rel(REL_HWHEEL); break; 451 case 0x238: map_rel(REL_HWHEEL); break;
293 case 0x279: map_key_clear(KEY_REDO); break; 452 case 0x279: map_key_clear(KEY_REDO); break;
294 case 0x289: map_key_clear(KEY_REPLY); break; 453 case 0x289: map_key_clear(KEY_REPLY); break;
295 case 0x28b: map_key_clear(KEY_FORWARDMAIL); break; 454 case 0x28b: map_key_clear(KEY_FORWARDMAIL); break;
296 case 0x28c: map_key_clear(KEY_SEND); break; 455 case 0x28c: map_key_clear(KEY_SEND); break;
456
457 /* Reported on a Cherry Cymotion keyboard */
458 case 0x301: map_key_clear(KEY_PROG1); break;
459 case 0x302: map_key_clear(KEY_PROG2); break;
460 case 0x303: map_key_clear(KEY_PROG3); break;
461
297 default: goto ignore; 462 default: goto ignore;
298 } 463 }
299 break; 464 break;
@@ -325,7 +490,12 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
325 490
326 set_bit(EV_REP, input->evbit); 491 set_bit(EV_REP, input->evbit);
327 switch(usage->hid & HID_USAGE) { 492 switch(usage->hid & HID_USAGE) {
328 case 0x003: map_key_clear(KEY_FN); break; 493 case 0x003:
494 /* The fn key on Apple PowerBooks */
495 map_key_clear(KEY_FN);
496 hidinput_pb_setup(input);
497 break;
498
329 default: goto ignore; 499 default: goto ignore;
330 } 500 }
331 break; 501 break;
@@ -482,6 +652,9 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
482 return; 652 return;
483 } 653 }
484 654
655 if ((hid->quirks & HID_QUIRK_POWERBOOK_HAS_FN) && hidinput_pb_event(hid, input, usage, value))
656 return;
657
485 if (usage->hat_min < usage->hat_max || usage->hat_dir) { 658 if (usage->hat_min < usage->hat_max || usage->hat_dir) {
486 int hat_dir = usage->hat_dir; 659 int hat_dir = usage->hat_dir;
487 if (!hat_dir) 660 if (!hat_dir)
@@ -524,7 +697,7 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
524 return; 697 return;
525 } 698 }
526 699
527 if((usage->type == EV_KEY) && (usage->code == 0)) /* Key 0 is "unassigned", not KEY_UNKNOWN */ 700 if ((usage->type == EV_KEY) && (usage->code == 0)) /* Key 0 is "unassigned", not KEY_UNKNOWN */
528 return; 701 return;
529 702
530 input_event(input, usage->type, usage->code, value); 703 input_event(input, usage->type, usage->code, value);
diff --git a/drivers/usb/input/hid.h b/drivers/usb/input/hid.h
index ee48a2276104..8b0d4346ce9c 100644
--- a/drivers/usb/input/hid.h
+++ b/drivers/usb/input/hid.h
@@ -235,17 +235,20 @@ struct hid_item {
235 * HID device quirks. 235 * HID device quirks.
236 */ 236 */
237 237
238#define HID_QUIRK_INVERT 0x001 238#define HID_QUIRK_INVERT 0x00000001
239#define HID_QUIRK_NOTOUCH 0x002 239#define HID_QUIRK_NOTOUCH 0x00000002
240#define HID_QUIRK_IGNORE 0x004 240#define HID_QUIRK_IGNORE 0x00000004
241#define HID_QUIRK_NOGET 0x008 241#define HID_QUIRK_NOGET 0x00000008
242#define HID_QUIRK_HIDDEV 0x010 242#define HID_QUIRK_HIDDEV 0x00000010
243#define HID_QUIRK_BADPAD 0x020 243#define HID_QUIRK_BADPAD 0x00000020
244#define HID_QUIRK_MULTI_INPUT 0x040 244#define HID_QUIRK_MULTI_INPUT 0x00000040
245#define HID_QUIRK_2WHEEL_MOUSE_HACK_7 0x080 245#define HID_QUIRK_2WHEEL_MOUSE_HACK_7 0x00000080
246#define HID_QUIRK_2WHEEL_MOUSE_HACK_5 0x100 246#define HID_QUIRK_2WHEEL_MOUSE_HACK_5 0x00000100
247#define HID_QUIRK_2WHEEL_MOUSE_HACK_ON 0x200 247#define HID_QUIRK_2WHEEL_MOUSE_HACK_ON 0x00000200
248#define HID_QUIRK_2WHEEL_POWERMOUSE 0x400 248#define HID_QUIRK_2WHEEL_POWERMOUSE 0x00000400
249#define HID_QUIRK_CYMOTION 0x00000800
250#define HID_QUIRK_POWERBOOK_HAS_FN 0x00001000
251#define HID_QUIRK_POWERBOOK_FN_ON 0x00002000
249 252
250/* 253/*
251 * This is the global environment of the parser. This information is 254 * This is the global environment of the parser. This information is
@@ -431,6 +434,11 @@ struct hid_device { /* device report descriptor */
431 void (*ff_exit)(struct hid_device*); /* Called by hid_exit_ff(hid) */ 434 void (*ff_exit)(struct hid_device*); /* Called by hid_exit_ff(hid) */
432 int (*ff_event)(struct hid_device *hid, struct input_dev *input, 435 int (*ff_event)(struct hid_device *hid, struct input_dev *input,
433 unsigned int type, unsigned int code, int value); 436 unsigned int type, unsigned int code, int value);
437
438#ifdef CONFIG_USB_HIDINPUT_POWERBOOK
439 unsigned long pb_pressed_fn[NBITS(KEY_MAX)];
440 unsigned long pb_pressed_numlock[NBITS(KEY_MAX)];
441#endif
434}; 442};
435 443
436#define HID_GLOBAL_STACK_SIZE 4 444#define HID_GLOBAL_STACK_SIZE 4
diff --git a/drivers/usb/input/pid.c b/drivers/usb/input/pid.c
index 19e015d171aa..d9d9f656b8c9 100644
--- a/drivers/usb/input/pid.c
+++ b/drivers/usb/input/pid.c
@@ -259,7 +259,7 @@ static int hid_pid_upload_effect(struct input_dev *dev,
259int hid_pid_init(struct hid_device *hid) 259int hid_pid_init(struct hid_device *hid)
260{ 260{
261 struct hid_ff_pid *private; 261 struct hid_ff_pid *private;
262 struct hid_input *hidinput = list_entry(&hid->inputs, struct hid_input, list); 262 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
263 struct input_dev *input_dev = hidinput->input; 263 struct input_dev *input_dev = hidinput->input;
264 264
265 private = hid->ff_private = kzalloc(sizeof(struct hid_ff_pid), GFP_KERNEL); 265 private = hid->ff_private = kzalloc(sizeof(struct hid_ff_pid), GFP_KERNEL);
diff --git a/drivers/usb/input/wacom.c b/drivers/usb/input/wacom.c
index 48df4cfd5a42..d3e15df9e815 100644
--- a/drivers/usb/input/wacom.c
+++ b/drivers/usb/input/wacom.c
@@ -95,7 +95,7 @@ MODULE_LICENSE(DRIVER_LICENSE);
95enum { 95enum {
96 PENPARTNER = 0, 96 PENPARTNER = 0,
97 GRAPHIRE, 97 GRAPHIRE,
98 G4, 98 WACOM_G4,
99 PL, 99 PL,
100 INTUOS, 100 INTUOS,
101 INTUOS3, 101 INTUOS3,
@@ -373,7 +373,7 @@ static void wacom_graphire_irq(struct urb *urb, struct pt_regs *regs)
373 373
374 case 2: /* Mouse with wheel */ 374 case 2: /* Mouse with wheel */
375 input_report_key(dev, BTN_MIDDLE, data[1] & 0x04); 375 input_report_key(dev, BTN_MIDDLE, data[1] & 0x04);
376 if (wacom->features->type == G4) { 376 if (wacom->features->type == WACOM_G4) {
377 rw = data[7] & 0x04 ? -(data[7] & 0x03) : (data[7] & 0x03); 377 rw = data[7] & 0x04 ? -(data[7] & 0x03) : (data[7] & 0x03);
378 input_report_rel(dev, REL_WHEEL, rw); 378 input_report_rel(dev, REL_WHEEL, rw);
379 } else 379 } else
@@ -385,7 +385,7 @@ static void wacom_graphire_irq(struct urb *urb, struct pt_regs *regs)
385 id = CURSOR_DEVICE_ID; 385 id = CURSOR_DEVICE_ID;
386 input_report_key(dev, BTN_LEFT, data[1] & 0x01); 386 input_report_key(dev, BTN_LEFT, data[1] & 0x01);
387 input_report_key(dev, BTN_RIGHT, data[1] & 0x02); 387 input_report_key(dev, BTN_RIGHT, data[1] & 0x02);
388 if (wacom->features->type == G4) 388 if (wacom->features->type == WACOM_G4)
389 input_report_abs(dev, ABS_DISTANCE, data[6]); 389 input_report_abs(dev, ABS_DISTANCE, data[6]);
390 else 390 else
391 input_report_abs(dev, ABS_DISTANCE, data[7]); 391 input_report_abs(dev, ABS_DISTANCE, data[7]);
@@ -410,7 +410,7 @@ static void wacom_graphire_irq(struct urb *urb, struct pt_regs *regs)
410 input_sync(dev); 410 input_sync(dev);
411 411
412 /* send pad data */ 412 /* send pad data */
413 if (wacom->features->type == G4) { 413 if (wacom->features->type == WACOM_G4) {
414 /* fist time sending pad data */ 414 /* fist time sending pad data */
415 if (wacom->tool[1] != BTN_TOOL_FINGER) { 415 if (wacom->tool[1] != BTN_TOOL_FINGER) {
416 wacom->id[1] = 0; 416 wacom->id[1] = 0;
@@ -713,8 +713,8 @@ static struct wacom_features wacom_features[] = {
713 { "Wacom Graphire2 5x7", 8, 13918, 10206, 511, 32, GRAPHIRE, wacom_graphire_irq }, 713 { "Wacom Graphire2 5x7", 8, 13918, 10206, 511, 32, GRAPHIRE, wacom_graphire_irq },
714 { "Wacom Graphire3", 8, 10208, 7424, 511, 32, GRAPHIRE, wacom_graphire_irq }, 714 { "Wacom Graphire3", 8, 10208, 7424, 511, 32, GRAPHIRE, wacom_graphire_irq },
715 { "Wacom Graphire3 6x8", 8, 16704, 12064, 511, 32, GRAPHIRE, wacom_graphire_irq }, 715 { "Wacom Graphire3 6x8", 8, 16704, 12064, 511, 32, GRAPHIRE, wacom_graphire_irq },
716 { "Wacom Graphire4 4x5", 8, 10208, 7424, 511, 32, G4, wacom_graphire_irq }, 716 { "Wacom Graphire4 4x5", 8, 10208, 7424, 511, 32, WACOM_G4, wacom_graphire_irq },
717 { "Wacom Graphire4 6x8", 8, 16704, 12064, 511, 32, G4, wacom_graphire_irq }, 717 { "Wacom Graphire4 6x8", 8, 16704, 12064, 511, 32, WACOM_G4, wacom_graphire_irq },
718 { "Wacom Volito", 8, 5104, 3712, 511, 32, GRAPHIRE, wacom_graphire_irq }, 718 { "Wacom Volito", 8, 5104, 3712, 511, 32, GRAPHIRE, wacom_graphire_irq },
719 { "Wacom PenStation2", 8, 3250, 2320, 255, 32, GRAPHIRE, wacom_graphire_irq }, 719 { "Wacom PenStation2", 8, 3250, 2320, 255, 32, GRAPHIRE, wacom_graphire_irq },
720 { "Wacom Volito2 4x5", 8, 5104, 3712, 511, 32, GRAPHIRE, wacom_graphire_irq }, 720 { "Wacom Volito2 4x5", 8, 5104, 3712, 511, 32, GRAPHIRE, wacom_graphire_irq },
@@ -859,7 +859,7 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
859 input_set_abs_params(input_dev, ABS_PRESSURE, 0, wacom->features->pressure_max, 0, 0); 859 input_set_abs_params(input_dev, ABS_PRESSURE, 0, wacom->features->pressure_max, 0, 0);
860 860
861 switch (wacom->features->type) { 861 switch (wacom->features->type) {
862 case G4: 862 case WACOM_G4:
863 input_dev->evbit[0] |= BIT(EV_MSC); 863 input_dev->evbit[0] |= BIT(EV_MSC);
864 input_dev->mscbit[0] |= BIT(MSC_SERIAL); 864 input_dev->mscbit[0] |= BIT(MSC_SERIAL);
865 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_FINGER); 865 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_FINGER);
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index 9ffff1938239..0eb883f44ada 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -43,8 +43,6 @@ static int debug;
43#define PL2303_BUF_SIZE 1024 43#define PL2303_BUF_SIZE 1024
44#define PL2303_TMP_BUF_SIZE 1024 44#define PL2303_TMP_BUF_SIZE 1024
45 45
46static DECLARE_MUTEX(pl2303_tmp_buf_sem);
47
48struct pl2303_buf { 46struct pl2303_buf {
49 unsigned int buf_size; 47 unsigned int buf_size;
50 char *buf_buf; 48 char *buf_buf;