From 6e7b51a733fde86d3be748543215a69da04d5bb7 Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Wed, 6 Jan 2010 13:57:43 +0100 Subject: pcmcia: move cistpl.c into pcmcia module As PCMCIA is the only real user of CIS access functions, include cistpl.c in the PCMCIA module, not in the PCMCIA & CardBus core module. Tested-by: Wolfram Sang Signed-off-by: Dominik Brodowski --- drivers/pcmcia/socket_sysfs.c | 150 +----------------------------------------- 1 file changed, 1 insertion(+), 149 deletions(-) (limited to 'drivers/pcmcia/socket_sysfs.c') diff --git a/drivers/pcmcia/socket_sysfs.c b/drivers/pcmcia/socket_sysfs.c index 7a456000332..537d79305e7 100644 --- a/drivers/pcmcia/socket_sysfs.c +++ b/drivers/pcmcia/socket_sysfs.c @@ -213,138 +213,6 @@ static ssize_t pccard_store_resource(struct device *dev, } static DEVICE_ATTR(available_resources_setup_done, 0600, pccard_show_resource, pccard_store_resource); - -static ssize_t pccard_extract_cis(struct pcmcia_socket *s, char *buf, loff_t off, size_t count) -{ - tuple_t tuple; - int status, i; - loff_t pointer = 0; - ssize_t ret = 0; - u_char *tuplebuffer; - u_char *tempbuffer; - - tuplebuffer = kmalloc(sizeof(u_char) * 256, GFP_KERNEL); - if (!tuplebuffer) - return -ENOMEM; - - tempbuffer = kmalloc(sizeof(u_char) * 258, GFP_KERNEL); - if (!tempbuffer) { - ret = -ENOMEM; - goto free_tuple; - } - - memset(&tuple, 0, sizeof(tuple_t)); - - tuple.Attributes = TUPLE_RETURN_LINK | TUPLE_RETURN_COMMON; - tuple.DesiredTuple = RETURN_FIRST_TUPLE; - tuple.TupleOffset = 0; - - status = pccard_get_first_tuple(s, BIND_FN_ALL, &tuple); - while (!status) { - tuple.TupleData = tuplebuffer; - tuple.TupleDataMax = 255; - memset(tuplebuffer, 0, sizeof(u_char) * 255); - - status = pccard_get_tuple_data(s, &tuple); - if (status) - break; - - if (off < (pointer + 2 + tuple.TupleDataLen)) { - tempbuffer[0] = tuple.TupleCode & 0xff; - tempbuffer[1] = tuple.TupleLink & 0xff; - for (i = 0; i < tuple.TupleDataLen; i++) - tempbuffer[i + 2] = tuplebuffer[i] & 0xff; - - for (i = 0; i < (2 + tuple.TupleDataLen); i++) { - if (((i + pointer) >= off) && - (i + pointer) < (off + count)) { - buf[ret] = tempbuffer[i]; - ret++; - } - } - } - - pointer += 2 + tuple.TupleDataLen; - - if (pointer >= (off + count)) - break; - - if (tuple.TupleCode == CISTPL_END) - break; - status = pccard_get_next_tuple(s, BIND_FN_ALL, &tuple); - } - - kfree(tempbuffer); - free_tuple: - kfree(tuplebuffer); - - return ret; -} - -static ssize_t pccard_show_cis(struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t count) -{ - unsigned int size = 0x200; - - if (off >= size) - count = 0; - else { - struct pcmcia_socket *s; - unsigned int chains; - - if (off + count > size) - count = size - off; - - s = to_socket(container_of(kobj, struct device, kobj)); - - if (!(s->state & SOCKET_PRESENT)) - return -ENODEV; - if (pccard_validate_cis(s, &chains)) - return -EIO; - if (!chains) - return -ENODATA; - - count = pccard_extract_cis(s, buf, off, count); - } - - return count; -} - -static ssize_t pccard_store_cis(struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t count) -{ - struct pcmcia_socket *s = to_socket(container_of(kobj, struct device, kobj)); - int error; - - if (off) - return -EINVAL; - - if (count >= CISTPL_MAX_CIS_SIZE) - return -EINVAL; - - if (!(s->state & SOCKET_PRESENT)) - return -ENODEV; - - error = pcmcia_replace_cis(s, buf, count); - if (error) - return -EIO; - - mutex_lock(&s->skt_mutex); - if ((s->callback) && (s->state & SOCKET_PRESENT) && - !(s->state & SOCKET_CARDBUS)) { - if (try_module_get(s->callback->owner)) { - s->callback->requery(s, 1); - module_put(s->callback->owner); - } - } - mutex_unlock(&s->skt_mutex); - - return count; -} - - static struct attribute *pccard_socket_attributes[] = { &dev_attr_card_type.attr, &dev_attr_card_voltage.attr, @@ -362,28 +230,12 @@ static const struct attribute_group socket_attrs = { .attrs = pccard_socket_attributes, }; -static struct bin_attribute pccard_cis_attr = { - .attr = { .name = "cis", .mode = S_IRUGO | S_IWUSR }, - .size = 0x200, - .read = pccard_show_cis, - .write = pccard_store_cis, -}; - int pccard_sysfs_add_socket(struct device *dev) { - int ret = 0; - - ret = sysfs_create_group(&dev->kobj, &socket_attrs); - if (!ret) { - ret = sysfs_create_bin_file(&dev->kobj, &pccard_cis_attr); - if (ret) - sysfs_remove_group(&dev->kobj, &socket_attrs); - } - return ret; + return sysfs_create_group(&dev->kobj, &socket_attrs); } void pccard_sysfs_remove_socket(struct device *dev) { - sysfs_remove_bin_file(&dev->kobj, &pccard_cis_attr); sysfs_remove_group(&dev->kobj, &socket_attrs); } -- cgit v1.2.3 From 64d8d46f5f501a19aec4db7ff93faf1b831d05ed Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sat, 16 Jan 2010 01:14:38 +0100 Subject: pcmcia: properly lock skt->irq, skt->irq_mask Tested-by: Wolfram Sang Signed-off-by: Dominik Brodowski --- drivers/pcmcia/socket_sysfs.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers/pcmcia/socket_sysfs.c') diff --git a/drivers/pcmcia/socket_sysfs.c b/drivers/pcmcia/socket_sysfs.c index 537d79305e7..1cba9d38d81 100644 --- a/drivers/pcmcia/socket_sysfs.c +++ b/drivers/pcmcia/socket_sysfs.c @@ -167,7 +167,9 @@ static ssize_t pccard_store_irq_mask(struct device *dev, ret = sscanf(buf, "0x%x\n", &mask); if (ret == 1) { + mutex_lock(&s->ops_mutex); s->irq_mask &= mask; + mutex_unlock(&s->ops_mutex); ret = 0; } -- cgit v1.2.3 From 00ce99ff506a17882747a7d6874e3f5206a99043 Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sat, 16 Jan 2010 09:14:11 +0100 Subject: pcmcia: simplify locking replace pcmcia_socket->lock and pcmcia_dev_list_lock by using the per-socket "ops_mutex", as we do neither need different locks nor a spinlock here. Tested-by: Wolfram Sang Signed-off-by: Dominik Brodowski --- drivers/pcmcia/socket_sysfs.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'drivers/pcmcia/socket_sysfs.c') diff --git a/drivers/pcmcia/socket_sysfs.c b/drivers/pcmcia/socket_sysfs.c index 1cba9d38d81..e8826df00a3 100644 --- a/drivers/pcmcia/socket_sysfs.c +++ b/drivers/pcmcia/socket_sysfs.c @@ -189,16 +189,15 @@ static ssize_t pccard_store_resource(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - unsigned long flags; struct pcmcia_socket *s = to_socket(dev); if (!count) return -EINVAL; - spin_lock_irqsave(&s->lock, flags); + mutex_lock(&s->ops_mutex); if (!s->resource_setup_done) s->resource_setup_done = 1; - spin_unlock_irqrestore(&s->lock, flags); + mutex_unlock(&s->ops_mutex); mutex_lock(&s->skt_mutex); if ((s->callback) && -- cgit v1.2.3 From f971dbd5da4e2fbf756d07b938a9c65a9c75178b Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sun, 17 Jan 2010 18:13:31 +0100 Subject: pcmcia: use pccardd to handle eject, insert, suspend and resume requests This avoids any sysfs-related deadlock (or lockdep warning), such as reported at http://lkml.org/lkml/2010/1/17/88 . Reported-by: Ming Lei Tested-by: Wolfram Sang Signed-off-by: Dominik Brodowski --- drivers/pcmcia/socket_sysfs.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'drivers/pcmcia/socket_sysfs.c') diff --git a/drivers/pcmcia/socket_sysfs.c b/drivers/pcmcia/socket_sysfs.c index e8826df00a3..fba0e30183f 100644 --- a/drivers/pcmcia/socket_sysfs.c +++ b/drivers/pcmcia/socket_sysfs.c @@ -88,15 +88,14 @@ static DEVICE_ATTR(card_vcc, 0444, pccard_show_vcc, NULL); static ssize_t pccard_store_insert(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - ssize_t ret; struct pcmcia_socket *s = to_socket(dev); if (!count) return -EINVAL; - ret = pcmcia_insert_card(s); + pcmcia_parse_uevents(s, PCMCIA_UEVENT_INSERT); - return ret ? ret : count; + return count; } static DEVICE_ATTR(card_insert, 0200, NULL, pccard_store_insert); @@ -113,18 +112,22 @@ static ssize_t pccard_store_card_pm_state(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - ssize_t ret = -EINVAL; struct pcmcia_socket *s = to_socket(dev); + ssize_t ret = count; if (!count) return -EINVAL; - if (!(s->state & SOCKET_SUSPEND) && !strncmp(buf, "off", 3)) - ret = pcmcia_suspend_card(s); - else if ((s->state & SOCKET_SUSPEND) && !strncmp(buf, "on", 2)) - ret = pcmcia_resume_card(s); + if (!strncmp(buf, "off", 3)) + pcmcia_parse_uevents(s, PCMCIA_UEVENT_SUSPEND); + else { + if (!strncmp(buf, "on", 2)) + pcmcia_parse_uevents(s, PCMCIA_UEVENT_RESUME); + else + ret = -EINVAL; + } - return ret ? -ENODEV : count; + return ret; } static DEVICE_ATTR(card_pm_state, 0644, pccard_show_card_pm_state, pccard_store_card_pm_state); @@ -132,15 +135,14 @@ static ssize_t pccard_store_eject(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - ssize_t ret; struct pcmcia_socket *s = to_socket(dev); if (!count) return -EINVAL; - ret = pcmcia_eject_card(s); + pcmcia_parse_uevents(s, PCMCIA_UEVENT_EJECT); - return ret ? ret : count; + return count; } static DEVICE_ATTR(card_eject, 0200, NULL, pccard_store_eject); -- cgit v1.2.3 From af461fc1875b6ec18e23b5f670af36c4ed35c84e Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sun, 17 Jan 2010 19:30:53 +0100 Subject: pcmcia: delay re-scanning and re-querying of PCMCIA bus After a CIS update -- or the finalization of the resource database --, proceed with the re-scanning or re-querying of PCMCIA cards only in a separate thread to avoid deadlocks. Tested-by: Wolfram Sang Signed-off-by: Dominik Brodowski --- drivers/pcmcia/socket_sysfs.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'drivers/pcmcia/socket_sysfs.c') diff --git a/drivers/pcmcia/socket_sysfs.c b/drivers/pcmcia/socket_sysfs.c index fba0e30183f..08278016e58 100644 --- a/drivers/pcmcia/socket_sysfs.c +++ b/drivers/pcmcia/socket_sysfs.c @@ -201,16 +201,7 @@ static ssize_t pccard_store_resource(struct device *dev, s->resource_setup_done = 1; mutex_unlock(&s->ops_mutex); - mutex_lock(&s->skt_mutex); - if ((s->callback) && - (s->state & SOCKET_PRESENT) && - !(s->state & SOCKET_CARDBUS)) { - if (try_module_get(s->callback->owner)) { - s->callback->requery(s, 0); - module_put(s->callback->owner); - } - } - mutex_unlock(&s->skt_mutex); + pcmcia_parse_uevents(s, PCMCIA_UEVENT_REQUERY); return count; } -- cgit v1.2.3