Commit 183b9b59 authored by Inaky Perez-Gonzalez's avatar Inaky Perez-Gonzalez Committed by David Vrabel

uwb: add the UWB stack (core files)

UWB device and radio controller device and event management.
Signed-off-by: default avatarDavid Vrabel <david.vrabel@csr.com>
parent 34e95e41
/*
* Ultra Wide Band
* Driver initialization, etc
*
* Copyright (C) 2005-2006 Intel Corporation
* 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.
*
*
* FIXME: docs
*
* Life cycle: FIXME: explain
*
* UWB radio controller:
*
* 1. alloc a uwb_rc, zero it
* 2. call uwb_rc_init() on it to set it up + ops (won't do any
* kind of allocation)
* 3. register (now it is owned by the UWB stack--deregister before
* freeing/destroying).
* 4. It lives on it's own now (UWB stack handles)--when it
* disconnects, call unregister()
* 5. free it.
*
* Make sure you have a reference to the uwb_rc before calling
* any of the UWB API functions.
*
* TODO:
*
* 1. Locking and life cycle management is crappy still. All entry
* points to the UWB HCD API assume you have a reference on the
* uwb_rc structure and that it won't go away. They mutex lock it
* before doing anything.
*/
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/kdev_t.h>
#include <linux/random.h>
#include <linux/uwb/debug.h>
#include "uwb-internal.h"
/* UWB stack attributes (or 'global' constants) */
/**
* If a beacon dissapears for longer than this, then we consider the
* device who was represented by that beacon to be gone.
*
* ECMA-368[17.2.3, last para] establishes that a device must not
* consider a device to be its neighbour if he doesn't receive a beacon
* for more than mMaxLostBeacons. mMaxLostBeacons is defined in
* ECMA-368[17.16] as 3; because we can get only one beacon per
* superframe, that'd be 3 * 65ms = 195 ~ 200 ms. Let's give it time
* for jitter and stuff and make it 500 ms.
*/
unsigned long beacon_timeout_ms = 500;
static
ssize_t beacon_timeout_ms_show(struct class *class, char *buf)
{
return scnprintf(buf, PAGE_SIZE, "%lu\n", beacon_timeout_ms);
}
static
ssize_t beacon_timeout_ms_store(struct class *class,
const char *buf, size_t size)
{
unsigned long bt;
ssize_t result;
result = sscanf(buf, "%lu", &bt);
if (result != 1)
return -EINVAL;
beacon_timeout_ms = bt;
return size;
}
static struct class_attribute uwb_class_attrs[] = {
__ATTR(beacon_timeout_ms, S_IWUSR | S_IRUGO,
beacon_timeout_ms_show, beacon_timeout_ms_store),
__ATTR_NULL,
};
/** Device model classes */
struct class uwb_rc_class = {
.name = "uwb_rc",
.class_attrs = uwb_class_attrs,
};
static int __init uwb_subsys_init(void)
{
int result = 0;
result = uwb_est_create();
if (result < 0) {
printk(KERN_ERR "uwb: Can't initialize EST subsystem\n");
goto error_est_init;
}
result = class_register(&uwb_rc_class);
if (result < 0)
goto error_uwb_rc_class_register;
uwbd_start();
return 0;
error_uwb_rc_class_register:
uwb_est_destroy();
error_est_init:
return result;
}
module_init(uwb_subsys_init);
static void __exit uwb_subsys_exit(void)
{
uwbd_stop();
class_unregister(&uwb_rc_class);
uwb_est_destroy();
return;
}
module_exit(uwb_subsys_exit);
MODULE_AUTHOR("Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>");
MODULE_DESCRIPTION("Ultra Wide Band core");
MODULE_LICENSE("GPL");
This diff is collapsed.
This diff is collapsed.
/*
* UWB PAL support.
*
* Copyright (C) 2008 Cambridge Silicon Radio Ltd.
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#include <linux/kernel.h>
#include <linux/uwb.h>
#include "uwb-internal.h"
/**
* uwb_pal_init - initialize a UWB PAL
* @pal: the PAL to initialize
*/
void uwb_pal_init(struct uwb_pal *pal)
{
INIT_LIST_HEAD(&pal->node);
}
EXPORT_SYMBOL_GPL(uwb_pal_init);
/**
* uwb_pal_register - register a UWB PAL
* @rc: the radio controller the PAL will be using
* @pal: the PAL
*
* The PAL must be initialized with uwb_pal_init().
*/
int uwb_pal_register(struct uwb_rc *rc, struct uwb_pal *pal)
{
spin_lock(&rc->pal_lock);
list_add(&pal->node, &rc->pals);
spin_unlock(&rc->pal_lock);
return 0;
}
EXPORT_SYMBOL_GPL(uwb_pal_register);
/**
* uwb_pal_register - unregister a UWB PAL
* @rc: the radio controller the PAL was using
* @pal: the PAL
*/
void uwb_pal_unregister(struct uwb_rc *rc, struct uwb_pal *pal)
{
spin_lock(&rc->pal_lock);
list_del(&pal->node);
spin_unlock(&rc->pal_lock);
}
EXPORT_SYMBOL_GPL(uwb_pal_unregister);
/**
* uwb_rc_pal_init - initialize the PAL related parts of a radio controller
* @rc: the radio controller
*/
void uwb_rc_pal_init(struct uwb_rc *rc)
{
spin_lock_init(&rc->pal_lock);
INIT_LIST_HEAD(&rc->pals);
}
/*
* Ultra Wide Band
* UWB internal API
*
* Copyright (C) 2005-2006 Intel Corporation
* 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.
*
* This contains most of the internal API for UWB. This is stuff used
* across the stack that of course, is of no interest to the rest.
*
* Some parts might end up going public (like uwb_rc_*())...
*/
#ifndef __UWB_INTERNAL_H__
#define __UWB_INTERNAL_H__
#include <linux/version.h>
#include <linux/kernel.h>
#include <linux/device.h>
#include <linux/uwb.h>
#include <linux/mutex.h>
struct uwb_beca_e;
/* General device API */
extern void uwb_dev_init(struct uwb_dev *uwb_dev);
extern int __uwb_dev_offair(struct uwb_dev *, struct uwb_rc *);
extern int uwb_dev_add(struct uwb_dev *uwb_dev, struct device *parent_dev,
struct uwb_rc *parent_rc);
extern void uwb_dev_rm(struct uwb_dev *uwb_dev);
extern void uwbd_dev_onair(struct uwb_rc *, struct uwb_beca_e *);
extern void uwbd_dev_offair(struct uwb_beca_e *);
void uwb_notify(struct uwb_rc *rc, struct uwb_dev *uwb_dev, enum uwb_notifs event);
/* General UWB Radio Controller Internal API */
extern struct uwb_rc *__uwb_rc_try_get(struct uwb_rc *);
static inline struct uwb_rc *__uwb_rc_get(struct uwb_rc *rc)
{
uwb_dev_get(&rc->uwb_dev);
return rc;
}
static inline void __uwb_rc_put(struct uwb_rc *rc)
{
uwb_dev_put(&rc->uwb_dev);
}
extern int uwb_rc_reset(struct uwb_rc *rc);
extern int uwb_rc_beacon(struct uwb_rc *rc,
int channel, unsigned bpst_offset);
extern int uwb_rc_scan(struct uwb_rc *rc,
unsigned channel, enum uwb_scan_type type,
unsigned bpst_offset);
extern int uwb_rc_send_all_drp_ie(struct uwb_rc *rc);
extern ssize_t uwb_rc_print_IEs(struct uwb_rc *rc, char *, size_t);
extern void uwb_rc_ie_init(struct uwb_rc *);
extern void uwb_rc_ie_init(struct uwb_rc *);
extern ssize_t uwb_rc_ie_setup(struct uwb_rc *);
extern void uwb_rc_ie_release(struct uwb_rc *);
extern int uwb_rc_ie_add(struct uwb_rc *,
const struct uwb_ie_hdr *, size_t);
extern int uwb_rc_ie_rm(struct uwb_rc *, enum uwb_ie);
extern int uwb_rc_set_identification_ie(struct uwb_rc *);
extern const char *uwb_rc_strerror(unsigned code);
/*
* Time to wait for a response to an RC command.
*
* Some commands can take a long time to response. e.g., START_BEACON
* may scan for several superframes before joining an existing beacon
* group and this can take around 600 ms.
*/
#define UWB_RC_CMD_TIMEOUT_MS 1000 /* ms */
/*
* Notification/Event Handlers
*/
struct uwb_rc_neh;
void uwb_rc_neh_create(struct uwb_rc *rc);
void uwb_rc_neh_destroy(struct uwb_rc *rc);
struct uwb_rc_neh *uwb_rc_neh_add(struct uwb_rc *rc, struct uwb_rccb *cmd,
u8 expected_type, u16 expected_event,
uwb_rc_cmd_cb_f cb, void *arg);
void uwb_rc_neh_rm(struct uwb_rc *rc, struct uwb_rc_neh *neh);
void uwb_rc_neh_arm(struct uwb_rc *rc, struct uwb_rc_neh *neh);
void uwb_rc_neh_put(struct uwb_rc_neh *neh);
/* Event size tables */
extern int uwb_est_create(void);
extern void uwb_est_destroy(void);
/*
* UWB Events & management daemon
*/
/**
* enum uwb_event_type - types of UWB management daemon events
*
* The UWB management daemon (uwbd) can receive two types of events:
* UWB_EVT_TYPE_NOTIF - notification from the radio controller.
* UWB_EVT_TYPE_MSG - a simple message.
*/
enum uwb_event_type {
UWB_EVT_TYPE_NOTIF,
UWB_EVT_TYPE_MSG,
};
/**
* struct uwb_event_notif - an event for a radio controller notification
* @size: Size of the buffer (ie: Guaranteed to contain at least
* a full 'struct uwb_rceb')
* @rceb: Pointer to a kmalloced() event payload
*/
struct uwb_event_notif {
size_t size;
struct uwb_rceb *rceb;
};
/**
* enum uwb_event_message - an event for a message for asynchronous processing
*
* UWB_EVT_MSG_RESET - reset the radio controller and all PAL hardware.
*/
enum uwb_event_message {
UWB_EVT_MSG_RESET,
};
/**
* UWB Event
* @rc: Radio controller that emitted the event (referenced)
* @ts_jiffies: Timestamp, when was it received
* @type: This event's type.
*/
struct uwb_event {
struct list_head list_node;
struct uwb_rc *rc;
unsigned long ts_jiffies;
enum uwb_event_type type;
union {
struct uwb_event_notif notif;
enum uwb_event_message message;
};
};
extern void uwbd_start(void);
extern void uwbd_stop(void);
extern struct uwb_event *uwb_event_alloc(size_t, gfp_t gfp_mask);
extern void uwbd_event_queue(struct uwb_event *);
void uwbd_flush(struct uwb_rc *rc);
/* UWB event handlers */
extern int uwbd_evt_handle_rc_beacon(struct uwb_event *);
extern int uwbd_evt_handle_rc_beacon_size(struct uwb_event *);
extern int uwbd_evt_handle_rc_bpoie_change(struct uwb_event *);
extern int uwbd_evt_handle_rc_bp_slot_change(struct uwb_event *);
extern int uwbd_evt_handle_rc_drp(struct uwb_event *);
extern int uwbd_evt_handle_rc_drp_avail(struct uwb_event *);
int uwbd_msg_handle_reset(struct uwb_event *evt);
/*
* Address management
*/
int uwb_rc_dev_addr_assign(struct uwb_rc *rc);
int uwbd_evt_handle_rc_dev_addr_conflict(struct uwb_event *evt);
/*
* UWB Beacon Cache
*
* Each beacon we received is kept in a cache--when we receive that
* beacon consistently, that means there is a new device that we have
* to add to the system.
*/
extern unsigned long beacon_timeout_ms;
/** Beacon cache list */
struct uwb_beca {
struct list_head list;
size_t entries;
struct mutex mutex;
};
extern struct uwb_beca uwb_beca;
/**
* Beacon cache entry
*
* @jiffies_refresh: last time a beacon was received that refreshed
* this cache entry.
* @uwb_dev: device connected to this beacon. This pointer is not
* safe, you need to get it with uwb_dev_try_get()
*
* @hits: how many time we have seen this beacon since last time we
* cleared it
*/
struct uwb_beca_e {
struct mutex mutex;
struct kref refcnt;
struct list_head node;
struct uwb_mac_addr *mac_addr;
struct uwb_dev_addr dev_addr;
u8 hits;
unsigned long ts_jiffies;
struct uwb_dev *uwb_dev;
struct uwb_rc_evt_beacon *be;
struct stats lqe_stats, rssi_stats; /* radio statistics */
};
struct uwb_beacon_frame;
extern ssize_t uwb_bce_print_IEs(struct uwb_dev *, struct uwb_beca_e *,
char *, size_t);
extern struct uwb_beca_e *__uwb_beca_add(struct uwb_rc_evt_beacon *,
struct uwb_beacon_frame *,
unsigned long);
extern void uwb_bce_kfree(struct kref *_bce);
static inline void uwb_bce_get(struct uwb_beca_e *bce)
{
kref_get(&bce->refcnt);
}
static inline void uwb_bce_put(struct uwb_beca_e *bce)
{
kref_put(&bce->refcnt, uwb_bce_kfree);
}
extern void uwb_beca_purge(void);
extern void uwb_beca_release(void);
struct uwb_dev *uwb_dev_get_by_devaddr(struct uwb_rc *rc,
const struct uwb_dev_addr *devaddr);
struct uwb_dev *uwb_dev_get_by_macaddr(struct uwb_rc *rc,
const struct uwb_mac_addr *macaddr);
/* -- UWB Sysfs representation */
extern struct class uwb_rc_class;
extern struct device_attribute dev_attr_mac_address;
extern struct device_attribute dev_attr_beacon;
extern struct device_attribute dev_attr_scan;
/* -- DRP Bandwidth allocator: bandwidth allocations, reservations, DRP */
void uwb_rsv_init(struct uwb_rc *rc);
int uwb_rsv_setup(struct uwb_rc *rc);
void uwb_rsv_cleanup(struct uwb_rc *rc);
void uwb_rsv_set_state(struct uwb_rsv *rsv, enum uwb_rsv_state new_state);
void uwb_rsv_remove(struct uwb_rsv *rsv);
struct uwb_rsv *uwb_rsv_find(struct uwb_rc *rc, struct uwb_dev *src,
struct uwb_ie_drp *drp_ie);
void uwb_rsv_sched_update(struct uwb_rc *rc);
void uwb_drp_handle_timeout(struct uwb_rsv *rsv);
int uwb_drp_ie_update(struct uwb_rsv *rsv);
void uwb_drp_ie_to_bm(struct uwb_mas_bm *bm, const struct uwb_ie_drp *drp_ie);
void uwb_drp_avail_init(struct uwb_rc *rc);
int uwb_drp_avail_reserve_pending(struct uwb_rc *rc, struct uwb_mas_bm *mas);
void uwb_drp_avail_reserve(struct uwb_rc *rc, struct uwb_mas_bm *mas);
void uwb_drp_avail_release(struct uwb_rc *rc, struct uwb_mas_bm *mas);
void uwb_drp_avail_ie_update(struct uwb_rc *rc);
/* -- PAL support */
void uwb_rc_pal_init(struct uwb_rc *rc);
/* -- Misc */
extern ssize_t uwb_mac_frame_hdr_print(char *, size_t,
const struct uwb_mac_frame_hdr *);
/* -- Debug interface */
void uwb_dbg_init(void);
void uwb_dbg_exit(void);
void uwb_dbg_add_rc(struct uwb_rc *rc);
void uwb_dbg_del_rc(struct uwb_rc *rc);
/* Workarounds for version specific stuff */
static inline void uwb_dev_lock(struct uwb_dev *uwb_dev)
{
down(&uwb_dev->dev.sem);
}
static inline void uwb_dev_unlock(struct uwb_dev *uwb_dev)
{
up(&uwb_dev->dev.sem);
}
#endif /* #ifndef __UWB_INTERNAL_H__ */
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment