]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/mmc/core/sdio_irq.c
sdio: give sdio irq thread a host specific name
[linux-2.6-omap-h63xx.git] / drivers / mmc / core / sdio_irq.c
index 8843a4c2fe91997f1a0851796b1dc90dfff9be32..bb192f90e8e9a0028770a04073aefed345d35f95 100644 (file)
@@ -5,6 +5,8 @@
  * Created:     June 18, 2007
  * Copyright:   MontaVista Software Inc.
  *
+ * Copyright 2008 Pierre Ossman
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or (at
@@ -27,7 +29,7 @@
 
 static int process_sdio_pending_irqs(struct mmc_card *card)
 {
-       int i, ret;
+       int i, ret, count;
        unsigned char pending;
 
        ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_INTx, 0, &pending);
@@ -37,29 +39,37 @@ static int process_sdio_pending_irqs(struct mmc_card *card)
                return ret;
        }
 
+       count = 0;
        for (i = 1; i <= 7; i++) {
                if (pending & (1 << i)) {
                        struct sdio_func *func = card->sdio_func[i - 1];
                        if (!func) {
                                printk(KERN_WARNING "%s: pending IRQ for "
                                        "non-existant function\n",
-                                       sdio_func_id(func));
+                                       mmc_card_id(card));
+                               ret = -EINVAL;
                        } else if (func->irq_handler) {
                                func->irq_handler(func);
-                       } else
+                               count++;
+                       } else {
                                printk(KERN_WARNING "%s: pending IRQ with no handler\n",
                                       sdio_func_id(func));
+                               ret = -EINVAL;
+                       }
                }
        }
 
-       return 0;
+       if (count)
+               return count;
+
+       return ret;
 }
 
 static int sdio_irq_thread(void *_host)
 {
        struct mmc_host *host = _host;
        struct sched_param param = { .sched_priority = 1 };
-       unsigned long period;
+       unsigned long period, idle_period;
        int ret;
 
        sched_setscheduler(current, SCHED_FIFO, &param);
@@ -70,8 +80,9 @@ static int sdio_irq_thread(void *_host)
         * asynchronous notification of pending SDIO card interrupts
         * hence we poll for them in that case.
         */
+       idle_period = msecs_to_jiffies(10);
        period = (host->caps & MMC_CAP_SDIO_IRQ) ?
-               MAX_SCHEDULE_TIMEOUT : msecs_to_jiffies(10);
+               MAX_SCHEDULE_TIMEOUT : idle_period;
 
        pr_debug("%s: IRQ thread started (poll period = %lu jiffies)\n",
                 mmc_hostname(host), period);
@@ -98,18 +109,36 @@ static int sdio_irq_thread(void *_host)
 
                /*
                 * Give other threads a chance to run in the presence of
-                * errors.  FIXME: determine if due to card removal and
-                * possibly exit this thread if so.
+                * errors.
                 */
-               if (ret)
-                       ssleep(1);
+               if (ret < 0) {
+                       set_current_state(TASK_INTERRUPTIBLE);
+                       if (!kthread_should_stop())
+                               schedule_timeout(HZ);
+                       set_current_state(TASK_RUNNING);
+               }
+
+               /*
+                * Adaptive polling frequency based on the assumption
+                * that an interrupt will be closely followed by more.
+                * This has a substantial benefit for network devices.
+                */
+               if (!(host->caps & MMC_CAP_SDIO_IRQ)) {
+                       if (ret > 0)
+                               period /= 2;
+                       else {
+                               period++;
+                               if (period > idle_period)
+                                       period = idle_period;
+                       }
+               }
 
-               set_task_state(current, TASK_INTERRUPTIBLE);
+               set_current_state(TASK_INTERRUPTIBLE);
                if (host->caps & MMC_CAP_SDIO_IRQ)
                        host->ops->enable_sdio_irq(host, 1);
                if (!kthread_should_stop())
                        schedule_timeout(period);
-               set_task_state(current, TASK_RUNNING);
+               set_current_state(TASK_RUNNING);
        } while (!kthread_should_stop());
 
        if (host->caps & MMC_CAP_SDIO_IRQ)
@@ -130,7 +159,8 @@ static int sdio_card_irq_get(struct mmc_card *card)
        if (!host->sdio_irqs++) {
                atomic_set(&host->sdio_irq_thread_abort, 0);
                host->sdio_irq_thread =
-                       kthread_run(sdio_irq_thread, host, "ksdiorqd");
+                       kthread_run(sdio_irq_thread, host, "ksdioirqd/%s",
+                               mmc_hostname(host));
                if (IS_ERR(host->sdio_irq_thread)) {
                        int err = PTR_ERR(host->sdio_irq_thread);
                        host->sdio_irqs--;