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/config.h> 28 29 /* 30 #define VERBOSE_DEBUG 31 */ 32 33 #include <asm/semaphore.h> 34 #include <linux/atm.h> 35 #include <linux/atmdev.h> 36 #include <linux/completion.h> 37 #include <linux/device.h> 38 #include <linux/kref.h> 39 #include <linux/list.h> 40 #include <linux/stringify.h> 41 #include <linux/usb.h> 42 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) 55 #define usb_dbg(instance, format, arg...) \ 56 dev_dbg(&(instance)->usb_intf->dev , format , ## arg) 57 58 /* FIXME: move to dev_* once ATM is driver model aware */ 59 #define atm_printk(level, instance, format, arg...) \ 60 printk(level "ATM dev %d: " format , \ 61 (instance)->atm_dev->number , ## arg) 62 63 #define atm_err(instance, format, arg...) \ 64 atm_printk(KERN_ERR, instance , format , ## arg) 65 #define atm_info(instance, format, arg...) \ 66 atm_printk(KERN_INFO, instance , format , ## arg) 67 #define atm_warn(instance, format, arg...) \ 68 atm_printk(KERN_WARNING, instance , format , ## arg) 69 #ifdef DEBUG 70 #define atm_dbg(instance, format, arg...) \ 71 atm_printk(KERN_DEBUG, instance , format , ## arg) 72 #else 73 #define atm_dbg(instance, format, arg...) \ 74 do {} while (0) 75 #endif 76 77 78 /* mini driver */ 79 80 struct usbatm_data; 81 82 /* 83 * Assuming all methods exist and succeed, they are called in this order: 84 * 85 * bind, heavy_init, atm_start, ..., atm_stop, unbind 86 */ 87 88 struct usbatm_driver { 89 struct module *owner; 90 91 const char *driver_name; 92 93 /* 94 * init device ... can sleep, or cause probe() failure. Drivers with a heavy_init 95 * method can avoid having it called by setting need_heavy_init to zero. 96 */ 97 int (*bind) (struct usbatm_data *, struct usb_interface *, 98 const struct usb_device_id *id, int *need_heavy_init); 99 100 /* additional device initialization that is too slow to be done in probe() */ 101 int (*heavy_init) (struct usbatm_data *, struct usb_interface *); 102 103 /* cleanup device ... can sleep, but can't fail */ 104 void (*unbind) (struct usbatm_data *, struct usb_interface *); 105 106 /* init ATM device ... can sleep, or cause ATM initialization failure */ 107 int (*atm_start) (struct usbatm_data *, struct atm_dev *); 108 109 /* cleanup ATM device ... can sleep, but can't fail */ 110 void (*atm_stop) (struct usbatm_data *, struct atm_dev *); 111 112 int in; /* rx endpoint */ 113 int out; /* tx endpoint */ 114 115 unsigned rx_padding; 116 unsigned tx_padding; 117 }; 118 119 extern int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id, 120 struct usbatm_driver *driver); 121 extern void usbatm_usb_disconnect(struct usb_interface *intf); 122 123 124 struct usbatm_channel { 125 int endpoint; /* usb pipe */ 126 unsigned int stride; /* ATM cell size + padding */ 127 unsigned int buf_size; /* urb buffer size */ 128 spinlock_t lock; 129 struct list_head list; 130 struct tasklet_struct tasklet; 131 struct timer_list delay; 132 struct usbatm_data *usbatm; 133 }; 134 135 /* main driver data */ 136 137 struct usbatm_data { 138 /****************** 139 * public fields * 140 ******************/ 141 142 /* mini driver */ 143 struct usbatm_driver *driver; 144 void *driver_data; 145 char driver_name[16]; 146 147 /* USB device */ 148 struct usb_device *usb_dev; 149 struct usb_interface *usb_intf; 150 char description[64]; 151 152 /* ATM device */ 153 struct atm_dev *atm_dev; 154 155 /******************************** 156 * private fields - do not use * 157 ********************************/ 158 159 struct kref refcount; 160 struct semaphore serialize; 161 162 /* heavy init */ 163 int thread_pid; 164 struct completion thread_started; 165 struct completion thread_exited; 166 167 /* ATM device */ 168 struct list_head vcc_list; 169 170 struct usbatm_channel rx_channel; 171 struct usbatm_channel tx_channel; 172 173 struct sk_buff_head sndqueue; 174 struct sk_buff *current_skb; /* being emptied */ 175 176 struct urb *urbs[0]; 177 }; 178 179 #endif /* _USBATM_H_ */ 180