include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / drivers / net / wimax / i2400m / driver.c
index 1f6aa2a..94dc83c 100644 (file)
@@ -69,6 +69,7 @@
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/suspend.h>
+#include <linux/slab.h>
 
 #define D_SUBMODULE driver
 #include "debug-levels.h"
@@ -128,76 +129,6 @@ struct i2400m_work *__i2400m_work_setup(
 }
 
 
-/**
- * i2400m_queue_work - schedule work on a i2400m's queue
- *
- * @i2400m: device descriptor
- *
- * @fn: function to run to execute work. It gets passed a 'struct
- *     work_struct' that is wrapped in a 'struct i2400m_work'. Once
- *     done, you have to (1) i2400m_put(i2400m_work->i2400m) and then
- *     (2) kfree(i2400m_work).
- *
- * @gfp_flags: GFP flags for memory allocation.
- *
- * @pl: pointer to a payload buffer that you want to pass to the _work
- *     function. Use this to pack (for example) a struct with extra
- *     arguments.
- *
- * @pl_size: size of the payload buffer.
- *
- * We do this quite often, so this just saves typing; allocate a
- * wrapper for a i2400m, get a ref to it, pack arguments and launch
- * the work.
- *
- * A usual workflow is:
- *
- * struct my_work_args {
- *         void *something;
- *         int whatever;
- * };
- * ...
- *
- * struct my_work_args my_args = {
- *         .something = FOO,
- *         .whaetever = BLAH
- * };
- * i2400m_queue_work(i2400m, 1, my_work_function, GFP_KERNEL,
- *                   &args, sizeof(args))
- *
- * And now the work function can unpack the arguments and call the
- * real function (or do the job itself):
- *
- * static
- * void my_work_fn((struct work_struct *ws)
- * {
- *         struct i2400m_work *iw =
- *                container_of(ws, struct i2400m_work, ws);
- *        struct my_work_args *my_args = (void *) iw->pl;
- *
- *        my_work(iw->i2400m, my_args->something, my_args->whatevert);
- * }
- */
-int i2400m_queue_work(struct i2400m *i2400m,
-                     void (*fn)(struct work_struct *), gfp_t gfp_flags,
-                     const void *pl, size_t pl_size)
-{
-       int result;
-       struct i2400m_work *iw;
-
-       BUG_ON(i2400m->work_queue == NULL);
-       result = -ENOMEM;
-       iw = __i2400m_work_setup(i2400m, fn, gfp_flags, pl, pl_size);
-       if (iw != NULL) {
-               result = queue_work(i2400m->work_queue, &iw->ws);
-               if (WARN_ON(result == 0))
-                       result = -ENXIO;
-       }
-       return result;
-}
-EXPORT_SYMBOL_GPL(i2400m_queue_work);
-
-
 /*
  * Schedule i2400m's specific work on the system's queue.
  *
@@ -325,7 +256,7 @@ int i2400m_op_reset(struct wimax_dev *wimax_dev)
        mutex_lock(&i2400m->init_mutex);
        i2400m->reset_ctx = &ctx;
        mutex_unlock(&i2400m->init_mutex);
-       result = i2400m->bus_reset(i2400m, I2400M_RT_WARM);
+       result = i2400m_reset(i2400m, I2400M_RT_WARM);
        if (result < 0)
                goto out;
        result = wait_for_completion_timeout(&ctx.completion, 4*HZ);
@@ -371,24 +302,15 @@ int i2400m_check_mac_addr(struct i2400m *i2400m)
        /* Extract MAC addresss */
        ddi = (void *) skb->data;
        BUILD_BUG_ON(ETH_ALEN != sizeof(ddi->mac_address));
-       d_printf(2, dev, "GET DEVICE INFO: mac addr "
-                "%02x:%02x:%02x:%02x:%02x:%02x\n",
-                ddi->mac_address[0], ddi->mac_address[1],
-                ddi->mac_address[2], ddi->mac_address[3],
-                ddi->mac_address[4], ddi->mac_address[5]);
+       d_printf(2, dev, "GET DEVICE INFO: mac addr %pM\n",
+                ddi->mac_address);
        if (!memcmp(net_dev->perm_addr, ddi->mac_address,
                   sizeof(ddi->mac_address)))
                goto ok;
        dev_warn(dev, "warning: device reports a different MAC address "
                 "to that of boot mode's\n");
-       dev_warn(dev, "device reports     %02x:%02x:%02x:%02x:%02x:%02x\n",
-                ddi->mac_address[0], ddi->mac_address[1],
-                ddi->mac_address[2], ddi->mac_address[3],
-                ddi->mac_address[4], ddi->mac_address[5]);
-       dev_warn(dev, "boot mode reported %02x:%02x:%02x:%02x:%02x:%02x\n",
-                net_dev->perm_addr[0], net_dev->perm_addr[1],
-                net_dev->perm_addr[2], net_dev->perm_addr[3],
-                net_dev->perm_addr[4], net_dev->perm_addr[5]);
+       dev_warn(dev, "device reports     %pM\n", ddi->mac_address);
+       dev_warn(dev, "boot mode reported %pM\n", net_dev->perm_addr);
        if (!memcmp(zeromac, ddi->mac_address, sizeof(zeromac)))
                dev_err(dev, "device reports an invalid MAC address, "
                        "not updating\n");
@@ -454,11 +376,15 @@ retry:
                dev_err(dev, "cannot create workqueue\n");
                goto error_create_workqueue;
        }
-       result = i2400m->bus_dev_start(i2400m);
-       if (result < 0)
-               goto error_bus_dev_start;
+       if (i2400m->bus_dev_start) {
+               result = i2400m->bus_dev_start(i2400m);
+               if (result < 0)
+                       goto error_bus_dev_start;
+       }
        i2400m->ready = 1;
        wmb();          /* see i2400m->ready's documentation  */
+       /* process pending reports from the device */
+       queue_work(i2400m->work_queue, &i2400m->rx_report_ws);
        result = i2400m_firmware_check(i2400m); /* fw versions ok? */
        if (result < 0)
                goto error_fw_check;
@@ -466,7 +392,6 @@ retry:
        result = i2400m_check_mac_addr(i2400m);
        if (result < 0)
                goto error_check_mac_addr;
-       wimax_state_change(wimax_dev, WIMAX_ST_UNINITIALIZED);
        result = i2400m_dev_initialize(i2400m);
        if (result < 0)
                goto error_dev_initialize;
@@ -482,7 +407,8 @@ error_check_mac_addr:
        wmb();          /* see i2400m->ready's documentation  */
        flush_workqueue(i2400m->work_queue);
 error_fw_check:
-       i2400m->bus_dev_stop(i2400m);
+       if (i2400m->bus_dev_stop)
+               i2400m->bus_dev_stop(i2400m);
 error_bus_dev_start:
        destroy_workqueue(i2400m->work_queue);
 error_create_workqueue:
@@ -537,6 +463,8 @@ void __i2400m_dev_stop(struct i2400m *i2400m)
 
        d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
        wimax_state_change(wimax_dev, __WIMAX_ST_QUIESCING);
+       i2400m_msg_to_dev_cancel_wait(i2400m, -EL3RST);
+       complete(&i2400m->msg_completion);
        i2400m_net_wake_stop(i2400m);
        i2400m_dev_shutdown(i2400m);
        /*
@@ -547,7 +475,8 @@ void __i2400m_dev_stop(struct i2400m *i2400m)
        wmb();          /* see i2400m->ready's documentation  */
        flush_workqueue(i2400m->work_queue);
 
-       i2400m->bus_dev_stop(i2400m);
+       if (i2400m->bus_dev_stop)
+               i2400m->bus_dev_stop(i2400m);
        destroy_workqueue(i2400m->work_queue);
        i2400m_rx_release(i2400m);
        i2400m_tx_release(i2400m);
@@ -763,9 +692,7 @@ void __i2400m_dev_reset_handle(struct work_struct *ws)
                wmb();          /* see i2400m->updown's documentation  */
                dev_err(dev, "%s: cannot start the device: %d\n",
                        reason, result);
-               result = i2400m->bus_reset(i2400m, I2400M_RT_BUS);
-               if (result >= 0)
-                       result = -ENODEV;
+               result = -EUCLEAN;
        }
 out_unlock:
        if (i2400m->reset_ctx) {
@@ -773,6 +700,12 @@ out_unlock:
                complete(&ctx->completion);
        }
        mutex_unlock(&i2400m->init_mutex);
+       if (result == -EUCLEAN) {
+               /* ops, need to clean up [w/ init_mutex not held] */
+               result = i2400m_reset(i2400m, I2400M_RT_BUS);
+               if (result >= 0)
+                       result = -ENODEV;
+       }
 out:
        i2400m_put(i2400m);
        kfree(iw);
@@ -843,6 +776,56 @@ void i2400m_bm_buf_free(struct i2400m *i2400m)
 
 
 /**
+ * i2400m_init - Initialize a 'struct i2400m' from all zeroes
+ *
+ * This is a bus-generic API call.
+ */
+void i2400m_init(struct i2400m *i2400m)
+{
+       wimax_dev_init(&i2400m->wimax_dev);
+
+       i2400m->boot_mode = 1;
+       i2400m->rx_reorder = 1;
+       init_waitqueue_head(&i2400m->state_wq);
+
+       spin_lock_init(&i2400m->tx_lock);
+       i2400m->tx_pl_min = UINT_MAX;
+       i2400m->tx_size_min = UINT_MAX;
+
+       spin_lock_init(&i2400m->rx_lock);
+       i2400m->rx_pl_min = UINT_MAX;
+       i2400m->rx_size_min = UINT_MAX;
+       INIT_LIST_HEAD(&i2400m->rx_reports);
+       INIT_WORK(&i2400m->rx_report_ws, i2400m_report_hook_work);
+
+       mutex_init(&i2400m->msg_mutex);
+       init_completion(&i2400m->msg_completion);
+
+       mutex_init(&i2400m->init_mutex);
+       /* wake_tx_ws is initialized in i2400m_tx_setup() */
+}
+EXPORT_SYMBOL_GPL(i2400m_init);
+
+
+int i2400m_reset(struct i2400m *i2400m, enum i2400m_reset_type rt)
+{
+       struct net_device *net_dev = i2400m->wimax_dev.net_dev;
+
+       /*
+        * Make sure we stop TXs and down the carrier before
+        * resetting; this is needed to avoid things like
+        * i2400m_wake_tx() scheduling stuff in parallel.
+        */
+       if (net_dev->reg_state == NETREG_REGISTERED) {
+               netif_tx_disable(net_dev);
+               netif_carrier_off(net_dev);
+       }
+       return i2400m->bus_reset(i2400m, rt);
+}
+EXPORT_SYMBOL_GPL(i2400m_reset);
+
+
+/**
  * i2400m_setup - bus-generic setup function for the i2400m device
  *
  * @i2400m: device descriptor (bus-specific parts have been initialized)