| Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 1 | /****************************************************************************** | 
|  | 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 Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 27 | #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 Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 32 | #include <linux/kernel.h> | 
| Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 33 | #include <linux/kref.h> | 
|  | 34 | #include <linux/list.h> | 
|  | 35 | #include <linux/stringify.h> | 
|  | 36 | #include <linux/usb.h> | 
| Arjan van de Ven | ab3c81f | 2006-01-13 15:52:55 +0100 | [diff] [blame] | 37 | #include <linux/mutex.h> | 
| Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 38 |  | 
| Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 39 | /* | 
|  | 40 | #define VERBOSE_DEBUG | 
|  | 41 | */ | 
|  | 42 |  | 
| Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 43 | #ifdef DEBUG | 
|  | 44 | #define UDSL_ASSERT(x)	BUG_ON(!(x)) | 
|  | 45 | #else | 
|  | 46 | #define UDSL_ASSERT(x)	do { if (!(x)) warn("failed assertion '%s' at line %d", __stringify(x), __LINE__); } while(0) | 
|  | 47 | #endif | 
|  | 48 |  | 
|  | 49 | #define usb_err(instance, format, arg...)	\ | 
|  | 50 | dev_err(&(instance)->usb_intf->dev , format , ## arg) | 
|  | 51 | #define usb_info(instance, format, arg...)	\ | 
|  | 52 | dev_info(&(instance)->usb_intf->dev , format , ## arg) | 
|  | 53 | #define usb_warn(instance, format, arg...)	\ | 
|  | 54 | dev_warn(&(instance)->usb_intf->dev , format , ## arg) | 
| Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 55 | #ifdef DEBUG | 
| Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 56 | #define usb_dbg(instance, format, arg...)	\ | 
| Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 57 | dev_printk(KERN_DEBUG , &(instance)->usb_intf->dev , format , ## arg) | 
|  | 58 | #else | 
|  | 59 | #define usb_dbg(instance, format, arg...)	\ | 
|  | 60 | do {} while (0) | 
|  | 61 | #endif | 
| Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 62 |  | 
|  | 63 | /* FIXME: move to dev_* once ATM is driver model aware */ | 
|  | 64 | #define atm_printk(level, instance, format, arg...)	\ | 
| Andrew Morton | 843c944 | 2005-05-30 01:09:06 -0700 | [diff] [blame] | 65 | printk(level "ATM dev %d: " format ,		\ | 
|  | 66 | (instance)->atm_dev->number , ## arg) | 
| Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 67 |  | 
|  | 68 | #define atm_err(instance, format, arg...)	\ | 
|  | 69 | atm_printk(KERN_ERR, instance , format , ## arg) | 
|  | 70 | #define atm_info(instance, format, arg...)	\ | 
|  | 71 | atm_printk(KERN_INFO, instance , format , ## arg) | 
|  | 72 | #define atm_warn(instance, format, arg...)	\ | 
|  | 73 | atm_printk(KERN_WARNING, instance , format , ## arg) | 
|  | 74 | #ifdef DEBUG | 
|  | 75 | #define atm_dbg(instance, format, arg...)	\ | 
|  | 76 | atm_printk(KERN_DEBUG, instance , format , ## arg) | 
| Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 77 | #define atm_rldbg(instance, format, arg...)	\ | 
|  | 78 | if (printk_ratelimit())				\ | 
|  | 79 | atm_printk(KERN_DEBUG, instance , format , ## arg) | 
| Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 80 | #else | 
|  | 81 | #define atm_dbg(instance, format, arg...)	\ | 
|  | 82 | do {} while (0) | 
| Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 83 | #define atm_rldbg(instance, format, arg...)	\ | 
|  | 84 | do {} while (0) | 
| Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 85 | #endif | 
|  | 86 |  | 
|  | 87 |  | 
| Duncan Sands | 35644b0 | 2006-01-17 11:16:13 +0100 | [diff] [blame] | 88 | /* flags, set by mini-driver in bind() */ | 
|  | 89 |  | 
|  | 90 | #define UDSL_SKIP_HEAVY_INIT	(1<<0) | 
| Duncan Sands | 80aae7a | 2006-01-13 10:59:23 +0100 | [diff] [blame] | 91 | #define UDSL_USE_ISOC		(1<<1) | 
| Duncan Sands | a3673d3 | 2006-01-13 11:12:58 +0100 | [diff] [blame] | 92 | #define UDSL_IGNORE_EILSEQ	(1<<2) | 
| Duncan Sands | 35644b0 | 2006-01-17 11:16:13 +0100 | [diff] [blame] | 93 |  | 
|  | 94 |  | 
| Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 95 | /* mini driver */ | 
|  | 96 |  | 
|  | 97 | struct usbatm_data; | 
|  | 98 |  | 
|  | 99 | /* | 
|  | 100 | *  Assuming all methods exist and succeed, they are called in this order: | 
|  | 101 | * | 
|  | 102 | *  	bind, heavy_init, atm_start, ..., atm_stop, unbind | 
|  | 103 | */ | 
|  | 104 |  | 
|  | 105 | struct usbatm_driver { | 
| Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 106 | const char *driver_name; | 
|  | 107 |  | 
| Duncan Sands | 35644b0 | 2006-01-17 11:16:13 +0100 | [diff] [blame] | 108 | /* init device ... can sleep, or cause probe() failure */ | 
| Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 109 | int (*bind) (struct usbatm_data *, struct usb_interface *, | 
| Duncan Sands | 35644b0 | 2006-01-17 11:16:13 +0100 | [diff] [blame] | 110 | const struct usb_device_id *id); | 
| Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 111 |  | 
|  | 112 | /* additional device initialization that is too slow to be done in probe() */ | 
|  | 113 | int (*heavy_init) (struct usbatm_data *, struct usb_interface *); | 
|  | 114 |  | 
|  | 115 | /* cleanup device ... can sleep, but can't fail */ | 
|  | 116 | void (*unbind) (struct usbatm_data *, struct usb_interface *); | 
|  | 117 |  | 
|  | 118 | /* init ATM device ... can sleep, or cause ATM initialization failure */ | 
|  | 119 | int (*atm_start) (struct usbatm_data *, struct atm_dev *); | 
|  | 120 |  | 
|  | 121 | /* cleanup ATM device ... can sleep, but can't fail */ | 
|  | 122 | void (*atm_stop) (struct usbatm_data *, struct atm_dev *); | 
|  | 123 |  | 
| Duncan Sands | 80aae7a | 2006-01-13 10:59:23 +0100 | [diff] [blame] | 124 | int bulk_in;	/* bulk rx endpoint */ | 
|  | 125 | int isoc_in;	/* isochronous rx endpoint */ | 
|  | 126 | int bulk_out;	/* bulk tx endpoint */ | 
| Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 127 |  | 
|  | 128 | unsigned rx_padding; | 
|  | 129 | unsigned tx_padding; | 
|  | 130 | }; | 
|  | 131 |  | 
|  | 132 | extern int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id, | 
|  | 133 | struct usbatm_driver *driver); | 
|  | 134 | extern void usbatm_usb_disconnect(struct usb_interface *intf); | 
|  | 135 |  | 
|  | 136 |  | 
|  | 137 | struct usbatm_channel { | 
|  | 138 | int endpoint;			/* usb pipe */ | 
|  | 139 | unsigned int stride;		/* ATM cell size + padding */ | 
|  | 140 | unsigned int buf_size;		/* urb buffer size */ | 
| Duncan Sands | 80aae7a | 2006-01-13 10:59:23 +0100 | [diff] [blame] | 141 | unsigned int packet_size;	/* endpoint maxpacket */ | 
| Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 142 | spinlock_t lock; | 
|  | 143 | struct list_head list; | 
|  | 144 | struct tasklet_struct tasklet; | 
|  | 145 | struct timer_list delay; | 
|  | 146 | struct usbatm_data *usbatm; | 
|  | 147 | }; | 
|  | 148 |  | 
|  | 149 | /* main driver data */ | 
|  | 150 |  | 
|  | 151 | struct usbatm_data { | 
|  | 152 | /****************** | 
|  | 153 | *  public fields  * | 
|  | 154 | ******************/ | 
|  | 155 |  | 
|  | 156 | /* mini driver */ | 
|  | 157 | struct usbatm_driver *driver; | 
|  | 158 | void *driver_data; | 
|  | 159 | char driver_name[16]; | 
| Duncan Sands | 35644b0 | 2006-01-17 11:16:13 +0100 | [diff] [blame] | 160 | unsigned int flags; /* set by mini-driver in bind() */ | 
| Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 161 |  | 
|  | 162 | /* USB device */ | 
|  | 163 | struct usb_device *usb_dev; | 
|  | 164 | struct usb_interface *usb_intf; | 
|  | 165 | char description[64]; | 
|  | 166 |  | 
|  | 167 | /* ATM device */ | 
|  | 168 | struct atm_dev *atm_dev; | 
|  | 169 |  | 
|  | 170 | /******************************** | 
|  | 171 | *  private fields - do not use  * | 
|  | 172 | ********************************/ | 
|  | 173 |  | 
|  | 174 | struct kref refcount; | 
| Arjan van de Ven | ab3c81f | 2006-01-13 15:52:55 +0100 | [diff] [blame] | 175 | struct mutex serialize; | 
| Duncan Sands | 0e42a62 | 2006-01-13 10:05:15 +0100 | [diff] [blame] | 176 | int disconnected; | 
| Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 177 |  | 
|  | 178 | /* heavy init */ | 
|  | 179 | int thread_pid; | 
|  | 180 | struct completion thread_started; | 
|  | 181 | struct completion thread_exited; | 
|  | 182 |  | 
|  | 183 | /* ATM device */ | 
|  | 184 | struct list_head vcc_list; | 
|  | 185 |  | 
|  | 186 | struct usbatm_channel rx_channel; | 
|  | 187 | struct usbatm_channel tx_channel; | 
|  | 188 |  | 
|  | 189 | struct sk_buff_head sndqueue; | 
| Duncan Sands | 0ec3c7e | 2006-01-17 11:15:13 +0100 | [diff] [blame] | 190 | struct sk_buff *current_skb;	/* being emptied */ | 
| Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 191 |  | 
| Duncan Sands | e3fb2f6 | 2006-01-13 11:06:46 +0100 | [diff] [blame] | 192 | struct usbatm_vcc_data *cached_vcc; | 
|  | 193 | int cached_vci; | 
|  | 194 | short cached_vpi; | 
|  | 195 |  | 
|  | 196 | unsigned char *cell_buf;	/* holds partial rx cell */ | 
|  | 197 | unsigned int buf_usage; | 
|  | 198 |  | 
| Duncan Sands | c59bba7 | 2005-05-11 20:24:03 +0200 | [diff] [blame] | 199 | struct urb *urbs[0]; | 
|  | 200 | }; | 
|  | 201 |  | 
|  | 202 | #endif	/* _USBATM_H_ */ |