blob: b29eb807f2038d151a268630ad7e8dc0d5a4a43f [file] [log] [blame]
Duncan Sandsc59bba72005-05-11 20:24:03 +02001/******************************************************************************
2 * usbatm.h - Generic USB xDSL driver core
3 *
4 * Copyright (C) 2001, Alcatel
5 * Copyright (C) 2003, Duncan Sands, SolNegro, Josep Comas
6 * Copyright (C) 2004, David Woodhouse
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * this program; if not, write to the Free Software Foundation, Inc., 59
20 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 *
22 ******************************************************************************/
23
24#ifndef _USBATM_H_
25#define _USBATM_H_
26
Duncan Sandsc59bba72005-05-11 20:24:03 +020027#include <asm/semaphore.h>
28#include <linux/atm.h>
29#include <linux/atmdev.h>
30#include <linux/completion.h>
31#include <linux/device.h>
Duncan Sands0ec3c7e2006-01-17 11:15:13 +010032#include <linux/kernel.h>
Duncan Sandsc59bba72005-05-11 20:24:03 +020033#include <linux/kref.h>
34#include <linux/list.h>
35#include <linux/stringify.h>
36#include <linux/usb.h>
37
Duncan Sands0ec3c7e2006-01-17 11:15:13 +010038/*
39#define VERBOSE_DEBUG
40*/
41
Duncan Sandsc59bba72005-05-11 20:24:03 +020042#ifdef DEBUG
43#define UDSL_ASSERT(x) BUG_ON(!(x))
44#else
45#define UDSL_ASSERT(x) do { if (!(x)) warn("failed assertion '%s' at line %d", __stringify(x), __LINE__); } while(0)
46#endif
47
48#define usb_err(instance, format, arg...) \
49 dev_err(&(instance)->usb_intf->dev , format , ## arg)
50#define usb_info(instance, format, arg...) \
51 dev_info(&(instance)->usb_intf->dev , format , ## arg)
52#define usb_warn(instance, format, arg...) \
53 dev_warn(&(instance)->usb_intf->dev , format , ## arg)
Duncan Sands0ec3c7e2006-01-17 11:15:13 +010054#ifdef DEBUG
Duncan Sandsc59bba72005-05-11 20:24:03 +020055#define usb_dbg(instance, format, arg...) \
Duncan Sands0ec3c7e2006-01-17 11:15:13 +010056 dev_printk(KERN_DEBUG , &(instance)->usb_intf->dev , format , ## arg)
57#else
58#define usb_dbg(instance, format, arg...) \
59 do {} while (0)
60#endif
Duncan Sandsc59bba72005-05-11 20:24:03 +020061
62/* FIXME: move to dev_* once ATM is driver model aware */
63#define atm_printk(level, instance, format, arg...) \
Andrew Morton843c9442005-05-30 01:09:06 -070064 printk(level "ATM dev %d: " format , \
65 (instance)->atm_dev->number , ## arg)
Duncan Sandsc59bba72005-05-11 20:24:03 +020066
67#define atm_err(instance, format, arg...) \
68 atm_printk(KERN_ERR, instance , format , ## arg)
69#define atm_info(instance, format, arg...) \
70 atm_printk(KERN_INFO, instance , format , ## arg)
71#define atm_warn(instance, format, arg...) \
72 atm_printk(KERN_WARNING, instance , format , ## arg)
73#ifdef DEBUG
74#define atm_dbg(instance, format, arg...) \
75 atm_printk(KERN_DEBUG, instance , format , ## arg)
Duncan Sands0ec3c7e2006-01-17 11:15:13 +010076#define atm_rldbg(instance, format, arg...) \
77 if (printk_ratelimit()) \
78 atm_printk(KERN_DEBUG, instance , format , ## arg)
Duncan Sandsc59bba72005-05-11 20:24:03 +020079#else
80#define atm_dbg(instance, format, arg...) \
81 do {} while (0)
Duncan Sands0ec3c7e2006-01-17 11:15:13 +010082#define atm_rldbg(instance, format, arg...) \
83 do {} while (0)
Duncan Sandsc59bba72005-05-11 20:24:03 +020084#endif
85
86
Duncan Sands35644b02006-01-17 11:16:13 +010087/* flags, set by mini-driver in bind() */
88
89#define UDSL_SKIP_HEAVY_INIT (1<<0)
90
91
Duncan Sandsc59bba72005-05-11 20:24:03 +020092/* mini driver */
93
94struct usbatm_data;
95
96/*
97* Assuming all methods exist and succeed, they are called in this order:
98*
99* bind, heavy_init, atm_start, ..., atm_stop, unbind
100*/
101
102struct usbatm_driver {
103 struct module *owner;
104
105 const char *driver_name;
106
Duncan Sands35644b02006-01-17 11:16:13 +0100107 /* init device ... can sleep, or cause probe() failure */
Duncan Sandsc59bba72005-05-11 20:24:03 +0200108 int (*bind) (struct usbatm_data *, struct usb_interface *,
Duncan Sands35644b02006-01-17 11:16:13 +0100109 const struct usb_device_id *id);
Duncan Sandsc59bba72005-05-11 20:24:03 +0200110
111 /* additional device initialization that is too slow to be done in probe() */
112 int (*heavy_init) (struct usbatm_data *, struct usb_interface *);
113
114 /* cleanup device ... can sleep, but can't fail */
115 void (*unbind) (struct usbatm_data *, struct usb_interface *);
116
117 /* init ATM device ... can sleep, or cause ATM initialization failure */
118 int (*atm_start) (struct usbatm_data *, struct atm_dev *);
119
120 /* cleanup ATM device ... can sleep, but can't fail */
121 void (*atm_stop) (struct usbatm_data *, struct atm_dev *);
122
123 int in; /* rx endpoint */
124 int out; /* tx endpoint */
125
126 unsigned rx_padding;
127 unsigned tx_padding;
128};
129
130extern int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
131 struct usbatm_driver *driver);
132extern void usbatm_usb_disconnect(struct usb_interface *intf);
133
134
135struct usbatm_channel {
136 int endpoint; /* usb pipe */
137 unsigned int stride; /* ATM cell size + padding */
138 unsigned int buf_size; /* urb buffer size */
139 spinlock_t lock;
140 struct list_head list;
141 struct tasklet_struct tasklet;
142 struct timer_list delay;
143 struct usbatm_data *usbatm;
144};
145
146/* main driver data */
147
148struct usbatm_data {
149 /******************
150 * public fields *
151 ******************/
152
153 /* mini driver */
154 struct usbatm_driver *driver;
155 void *driver_data;
156 char driver_name[16];
Duncan Sands35644b02006-01-17 11:16:13 +0100157 unsigned int flags; /* set by mini-driver in bind() */
Duncan Sandsc59bba72005-05-11 20:24:03 +0200158
159 /* USB device */
160 struct usb_device *usb_dev;
161 struct usb_interface *usb_intf;
162 char description[64];
163
164 /* ATM device */
165 struct atm_dev *atm_dev;
166
167 /********************************
168 * private fields - do not use *
169 ********************************/
170
171 struct kref refcount;
172 struct semaphore serialize;
173
174 /* heavy init */
175 int thread_pid;
176 struct completion thread_started;
177 struct completion thread_exited;
178
179 /* ATM device */
180 struct list_head vcc_list;
181
182 struct usbatm_channel rx_channel;
183 struct usbatm_channel tx_channel;
184
185 struct sk_buff_head sndqueue;
Duncan Sands0ec3c7e2006-01-17 11:15:13 +0100186 struct sk_buff *current_skb; /* being emptied */
Duncan Sandsc59bba72005-05-11 20:24:03 +0200187
188 struct urb *urbs[0];
189};
190
191#endif /* _USBATM_H_ */