/*
* Intel Wireless WiMAX Connection 2400m
* Generic probe/disconnect, reset and message passing
*
*
* Copyright (C) 2007-2008 Intel Corporation <linux-wimax@intel.com>
* Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version
* 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*
*
* See i2400m.h for driver documentation. This contains helpers for
* the driver model glue [_setup()/_release()], handling device resets
* [_dev_reset_handle()], and the backends for the WiMAX stack ops
* reset [_op_reset()] and message from user [_op_msg_from_user()].
*
* ROADMAP:
*
* i2400m_op_msg_from_user()
* i2400m_msg_to_dev()
* wimax_msg_to_user_send()
*
* i2400m_op_reset()
* i240m->bus_reset()
*
* i2400m_dev_reset_handle()
* __i2400m_dev_reset_handle()
* __i2400m_dev_stop()
* __i2400m_dev_start()
*
* i2400m_setup()
* i2400m->bus_setup()
* i2400m_bootrom_init()
* register_netdev()
* wimax_dev_add()
* i2400m_dev_start()
* __i2400m_dev_start()
* i2400m_dev_bootstrap()
* i2400m_tx_setup()
* i2400m->bus_dev_start()
* i2400m_firmware_check()
* i2400m_check_mac_addr()
*
* i2400m_release()
* i2400m_dev_stop()
* __i2400m_dev_stop()
* i2400m_dev_shutdown()
* i2400m->bus_dev_stop()
* i2400m_tx_release()
* i2400m->bus_release()
* wimax_dev_rm()
* unregister_netdev()
*/
#include "i2400m.h"
#include <linux/etherdevice.h>
#include <linux/wimax/i2400m.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/suspend.h>
#include <linux/slab.h>
#define D_SUBMODULE driver
#include "debug-levels.h"
static char i2400m_debug_params[128];
module_param_string(debug, i2400m_debug_params, sizeof(i2400m_debug_params),
0644);
MODULE_PARM_DESC(debug,
"String of space-separated NAME:VALUE pairs, where NAMEs "
"are the different debug submodules and VALUE are the "
"initial debug value to set.");
static char i2400m_barkers_params[128];
module_param_string(barkers, i2400m_barkers_params,
sizeof(i2400m_barkers_params), 0644);
MODULE_PARM_DESC(barkers,
"String of comma-separated 32-bit values; each is "
"recognized as the value the device sends as a reboot "
"signal; values are appended to a list--setting one value "
"as zero cleans the existing list and starts a new one.");
static
struct i2400m_work *__i2400m_work_setup(
struct i2400m *i2400m, void (*fn)(struct work_struct *),
gfp_t gfp_flags, const void *pl, size_t pl_size)
{
struct i2400m_work *iw;
iw = kzalloc(sizeof(*iw) + pl_size, gfp_flags);
if (iw == NULL)
return NULL;
iw->i2400m = i2400m_get(i2400m);
iw->pl_size = pl_size;
memcpy(iw->pl, pl, pl_size);
INIT_WORK(&iw->ws, fn);
return iw;
}
/*
* Schedule i2400m's specific work on the system's queue.
*
* Used for a few cases where we really need it; otherwise, identical
* to i2400m_queue_work().
*
* Returns < 0 errno code on error, 1 if ok.
*
* If it returns zero, something really bad happened, as it means the
* works struct was already queued, but we have just allocated it, so
* it should not happen.
*/
static int i2400m_schedule_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;
result = -ENOMEM;
iw = __i2400m_work_setup(i2400m, fn, gfp_flags, pl, pl_size);
if (iw != NULL) {
result = schedule_work(&iw->ws);
if (WARN_ON(result == 0))
result = -ENXIO;
}
return result;
}
/*
* WiMAX stack operation: relay a message from user space
*
* @wimax_dev: device descriptor
* @pipe_name: named pipe the message is for
* @msg_buf: pointer to the message bytes
* @msg_len: length of the buffer
* @genl_info: passed by the generic netlink layer
*
* The WiMAX stack will call this function when a message was received
* from user space.
*
* For the i2400m, this is an L3L4 message, as specified in
* include/linux/wimax/i2400m.h, and thus prefixed with a 'struct
* i2400m_l3l4_hdr'. Driver (and device) expect the messages to be
* coded in Little Endian.
*
* This function just verifies that the header declaration and the
* payload are consistent and then deals with it, either forwarding it
* to the device or procesing it locally.
*
* In the i2400m, messages are basically commands that will carry an
* ack, so we use i2400m_msg_to_dev() and then deliver the ack back to
* user space. The rx.c code might intercept the response and use it
* to update the driver's state, but then it will pass it on so it can
* be relayed back to user space.
*
* Note that asynchronous events from the device are processed and
* sent to user space in rx.c.
*/
static
int i2400m_op_msg_from_user(struct wimax_dev *wimax_dev,
const char *pipe_name,
const void *msg_buf, size_t msg_len,
const struct genl_info *genl_info)
{
int result;
struct i2400m *i2400m = wimax_dev_to_i2400m(wimax_dev);
struct device *dev = i2400m_dev(i2400m);
struct sk_buff *ack_skb;
d_fnstart(4, dev, "(wimax_dev %p [i2400m %p] msg_buf %p "
"msg_len %zu genl_info %p)\n"