usbatm.h 6.07 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/******************************************************************************
 *  usbatm.h - Generic USB xDSL driver core
 *
 *  Copyright (C) 2001, Alcatel
 *  Copyright (C) 2003, Duncan Sands, SolNegro, Josep Comas
 *  Copyright (C) 2004, David Woodhouse
 *
 *  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 your option)
 *  any later version.
 *
 *  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., 59
 *  Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 ******************************************************************************/

#ifndef	_USBATM_H_
#define	_USBATM_H_

#include <linux/atm.h>
#include <linux/atmdev.h>
#include <linux/completion.h>
#include <linux/device.h>
31
#include <linux/kernel.h>
32 33 34 35
#include <linux/kref.h>
#include <linux/list.h>
#include <linux/stringify.h>
#include <linux/usb.h>
36
#include <linux/mutex.h>
37

38 39 40 41
/*
#define VERBOSE_DEBUG
*/

42
#ifdef DEBUG
43
#define UDSL_ASSERT(instance, x)	BUG_ON(!(x))
44
#else
45 46 47 48 49 50
#define UDSL_ASSERT(instance, x)					\
	do {	\
		if (!(x))						\
			dev_warn(&(instance)->usb_intf->dev,		\
				 "failed assertion '%s' at line %d",	\
				 __stringify(x), __LINE__);		\
51
	} while (0)
52 53 54 55 56 57 58 59
#endif

#define usb_err(instance, format, arg...)	\
	dev_err(&(instance)->usb_intf->dev , format , ## arg)
#define usb_info(instance, format, arg...)	\
	dev_info(&(instance)->usb_intf->dev , format , ## arg)
#define usb_warn(instance, format, arg...)	\
	dev_warn(&(instance)->usb_intf->dev , format , ## arg)
60 61
#ifdef DEBUG
#define usb_dbg(instance, format, arg...)	\
62
	dev_printk(KERN_DEBUG , &(instance)->usb_intf->dev , format , ## arg)
63
#else
64
#define usb_dbg(instance, format, arg...)	\
65 66
	do {} while (0)
#endif
67 68 69

/* FIXME: move to dev_* once ATM is driver model aware */
#define atm_printk(level, instance, format, arg...)	\
70 71
	printk(level "ATM dev %d: " format ,		\
	(instance)->atm_dev->number , ## arg)
72 73 74 75 76 77 78 79 80 81

#define atm_err(instance, format, arg...)	\
	atm_printk(KERN_ERR, instance , format , ## arg)
#define atm_info(instance, format, arg...)	\
	atm_printk(KERN_INFO, instance , format , ## arg)
#define atm_warn(instance, format, arg...)	\
	atm_printk(KERN_WARNING, instance , format , ## arg)
#ifdef DEBUG
#define atm_dbg(instance, format, arg...)	\
	atm_printk(KERN_DEBUG, instance , format , ## arg)
82 83 84
#define atm_rldbg(instance, format, arg...)	\
	if (printk_ratelimit())				\
		atm_printk(KERN_DEBUG, instance , format , ## arg)
85 86 87
#else
#define atm_dbg(instance, format, arg...)	\
	do {} while (0)
88 89
#define atm_rldbg(instance, format, arg...)	\
	do {} while (0)
90 91 92
#endif


93 94 95
/* flags, set by mini-driver in bind() */

#define UDSL_SKIP_HEAVY_INIT	(1<<0)
96
#define UDSL_USE_ISOC		(1<<1)
97
#define UDSL_IGNORE_EILSEQ	(1<<2)
98 99


100 101 102 103 104 105 106
/* mini driver */

struct usbatm_data;

/*
*  Assuming all methods exist and succeed, they are called in this order:
*
107
*	bind, heavy_init, atm_start, ..., atm_stop, unbind
108 109 110 111 112
*/

struct usbatm_driver {
	const char *driver_name;

113
	/* init device ... can sleep, or cause probe() failure */
114
	int (*bind) (struct usbatm_data *, struct usb_interface *,
115
		     const struct usb_device_id *id);
116 117

	/* additional device initialization that is too slow to be done in probe() */
118
	int (*heavy_init) (struct usbatm_data *, struct usb_interface *);
119 120

	/* cleanup device ... can sleep, but can't fail */
121
	void (*unbind) (struct usbatm_data *, struct usb_interface *);
122 123 124 125 126 127 128

	/* init ATM device ... can sleep, or cause ATM initialization failure */
	int (*atm_start) (struct usbatm_data *, struct atm_dev *);

	/* cleanup ATM device ... can sleep, but can't fail */
	void (*atm_stop) (struct usbatm_data *, struct atm_dev *);

129 130 131
	int bulk_in;	/* bulk rx endpoint */
	int isoc_in;	/* isochronous rx endpoint */
	int bulk_out;	/* bulk tx endpoint */
132 133 134 135 136 137 138 139 140 141 142 143 144 145

	unsigned rx_padding;
	unsigned tx_padding;
};

extern int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
		struct usbatm_driver *driver);
extern void usbatm_usb_disconnect(struct usb_interface *intf);


struct usbatm_channel {
	int endpoint;			/* usb pipe */
	unsigned int stride;		/* ATM cell size + padding */
	unsigned int buf_size;		/* urb buffer size */
146
	unsigned int packet_size;	/* endpoint maxpacket */
147 148 149 150 151 152 153 154 155 156 157 158
	spinlock_t lock;
	struct list_head list;
	struct tasklet_struct tasklet;
	struct timer_list delay;
	struct usbatm_data *usbatm;
};

/* main driver data */

struct usbatm_data {
	/******************
	*  public fields  *
159
	******************/
160 161 162 163 164

	/* mini driver */
	struct usbatm_driver *driver;
	void *driver_data;
	char driver_name[16];
165
	unsigned int flags; /* set by mini-driver in bind() */
166 167 168 169 170 171 172 173 174 175 176

	/* USB device */
	struct usb_device *usb_dev;
	struct usb_interface *usb_intf;
	char description[64];

	/* ATM device */
	struct atm_dev *atm_dev;

	/********************************
	*  private fields - do not use  *
177
	********************************/
178 179

	struct kref refcount;
180
	struct mutex serialize;
181
	int disconnected;
182 183

	/* heavy init */
184
	struct task_struct *thread;
185 186 187 188 189 190 191 192 193 194
	struct completion thread_started;
	struct completion thread_exited;

	/* ATM device */
	struct list_head vcc_list;

	struct usbatm_channel rx_channel;
	struct usbatm_channel tx_channel;

	struct sk_buff_head sndqueue;
195
	struct sk_buff *current_skb;	/* being emptied */
196

197 198 199 200 201 202 203
	struct usbatm_vcc_data *cached_vcc;
	int cached_vci;
	short cached_vpi;

	unsigned char *cell_buf;	/* holds partial rx cell */
	unsigned int buf_usage;

204 205 206
	struct urb *urbs[0];
};

207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
static inline void *to_usbatm_driver_data(struct usb_interface *intf)
{
	struct usbatm_data *usbatm_instance;

	if (intf == NULL)
		return NULL;

	usbatm_instance = usb_get_intfdata(intf);

	if (usbatm_instance == NULL) /* set NULL before unbind() */
		return NULL;

	return usbatm_instance->driver_data; /* set NULL after unbind() */
}

222
#endif	/* _USBATM_H_ */