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