blob: f3eecd967a8a1cb152575828cf45741dfc2bf85d [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 <linux/atm.h>
28#include <linux/atmdev.h>
29#include <linux/completion.h>
30#include <linux/device.h>
Duncan Sands0ec3c7e2006-01-17 11:15:13 +010031#include <linux/kernel.h>
Duncan Sandsc59bba72005-05-11 20:24:03 +020032#include <linux/kref.h>
33#include <linux/list.h>
34#include <linux/stringify.h>
35#include <linux/usb.h>
Arjan van de Venab3c81f2006-01-13 15:52:55 +010036#include <linux/mutex.h>
Joe Perches32e24932013-10-26 20:49:24 -070037#include <linux/ratelimit.h>
Duncan Sandsc59bba72005-05-11 20:24:03 +020038
Duncan Sands0ec3c7e2006-01-17 11:15:13 +010039/*
40#define VERBOSE_DEBUG
41*/
42
Duncan Sandsc59bba72005-05-11 20:24:03 +020043#define usb_err(instance, format, arg...) \
44 dev_err(&(instance)->usb_intf->dev , format , ## arg)
45#define usb_info(instance, format, arg...) \
46 dev_info(&(instance)->usb_intf->dev , format , ## arg)
47#define usb_warn(instance, format, arg...) \
48 dev_warn(&(instance)->usb_intf->dev , format , ## arg)
49#define usb_dbg(instance, format, arg...) \
Greg Kroah-Hartmanca4d7012013-06-28 11:32:52 -070050 dev_dbg(&(instance)->usb_intf->dev , format , ## arg)
Duncan Sandsc59bba72005-05-11 20:24:03 +020051
52/* FIXME: move to dev_* once ATM is driver model aware */
53#define atm_printk(level, instance, format, arg...) \
Andrew Morton843c9442005-05-30 01:09:06 -070054 printk(level "ATM dev %d: " format , \
55 (instance)->atm_dev->number , ## arg)
Duncan Sandsc59bba72005-05-11 20:24:03 +020056
57#define atm_err(instance, format, arg...) \
58 atm_printk(KERN_ERR, instance , format , ## arg)
59#define atm_info(instance, format, arg...) \
60 atm_printk(KERN_INFO, instance , format , ## arg)
61#define atm_warn(instance, format, arg...) \
62 atm_printk(KERN_WARNING, instance , format , ## arg)
Joe Perches32e24932013-10-26 20:49:24 -070063#define atm_dbg(instance, format, ...) \
64 pr_debug("ATM dev %d: " format, \
65 (instance)->atm_dev->number, ##__VA_ARGS__)
66#define atm_rldbg(instance, format, ...) \
67 pr_debug_ratelimited("ATM dev %d: " format, \
68 (instance)->atm_dev->number, ##__VA_ARGS__)
Duncan Sandsc59bba72005-05-11 20:24:03 +020069
Duncan Sands35644b02006-01-17 11:16:13 +010070/* flags, set by mini-driver in bind() */
71
72#define UDSL_SKIP_HEAVY_INIT (1<<0)
Duncan Sands80aae7a2006-01-13 10:59:23 +010073#define UDSL_USE_ISOC (1<<1)
Duncan Sandsa3673d32006-01-13 11:12:58 +010074#define UDSL_IGNORE_EILSEQ (1<<2)
Duncan Sands35644b02006-01-17 11:16:13 +010075
76
Duncan Sandsc59bba72005-05-11 20:24:03 +020077/* mini driver */
78
79struct usbatm_data;
80
81/*
82* Assuming all methods exist and succeed, they are called in this order:
83*
Nicolas Kaiser16f76a72010-06-17 11:55:49 +020084* bind, heavy_init, atm_start, ..., atm_stop, unbind
Duncan Sandsc59bba72005-05-11 20:24:03 +020085*/
86
87struct usbatm_driver {
Duncan Sandsc59bba72005-05-11 20:24:03 +020088 const char *driver_name;
89
Duncan Sands35644b02006-01-17 11:16:13 +010090 /* init device ... can sleep, or cause probe() failure */
Nicolas Kaiser16f76a72010-06-17 11:55:49 +020091 int (*bind) (struct usbatm_data *, struct usb_interface *,
Duncan Sands35644b02006-01-17 11:16:13 +010092 const struct usb_device_id *id);
Duncan Sandsc59bba72005-05-11 20:24:03 +020093
94 /* additional device initialization that is too slow to be done in probe() */
Nicolas Kaiser16f76a72010-06-17 11:55:49 +020095 int (*heavy_init) (struct usbatm_data *, struct usb_interface *);
Duncan Sandsc59bba72005-05-11 20:24:03 +020096
97 /* cleanup device ... can sleep, but can't fail */
Nicolas Kaiser16f76a72010-06-17 11:55:49 +020098 void (*unbind) (struct usbatm_data *, struct usb_interface *);
Duncan Sandsc59bba72005-05-11 20:24:03 +020099
100 /* init ATM device ... can sleep, or cause ATM initialization failure */
101 int (*atm_start) (struct usbatm_data *, struct atm_dev *);
102
103 /* cleanup ATM device ... can sleep, but can't fail */
104 void (*atm_stop) (struct usbatm_data *, struct atm_dev *);
105
Nicolas Kaiser16f76a72010-06-17 11:55:49 +0200106 int bulk_in; /* bulk rx endpoint */
107 int isoc_in; /* isochronous rx endpoint */
108 int bulk_out; /* bulk tx endpoint */
Duncan Sandsc59bba72005-05-11 20:24:03 +0200109
110 unsigned rx_padding;
111 unsigned tx_padding;
112};
113
114extern int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
115 struct usbatm_driver *driver);
116extern void usbatm_usb_disconnect(struct usb_interface *intf);
117
118
119struct usbatm_channel {
120 int endpoint; /* usb pipe */
121 unsigned int stride; /* ATM cell size + padding */
122 unsigned int buf_size; /* urb buffer size */
Duncan Sands80aae7a2006-01-13 10:59:23 +0100123 unsigned int packet_size; /* endpoint maxpacket */
Duncan Sandsc59bba72005-05-11 20:24:03 +0200124 spinlock_t lock;
125 struct list_head list;
126 struct tasklet_struct tasklet;
127 struct timer_list delay;
128 struct usbatm_data *usbatm;
129};
130
131/* main driver data */
132
133struct usbatm_data {
134 /******************
135 * public fields *
Nicolas Kaiser16f76a72010-06-17 11:55:49 +0200136 ******************/
Duncan Sandsc59bba72005-05-11 20:24:03 +0200137
138 /* mini driver */
139 struct usbatm_driver *driver;
140 void *driver_data;
141 char driver_name[16];
Duncan Sands35644b02006-01-17 11:16:13 +0100142 unsigned int flags; /* set by mini-driver in bind() */
Duncan Sandsc59bba72005-05-11 20:24:03 +0200143
144 /* USB device */
145 struct usb_device *usb_dev;
146 struct usb_interface *usb_intf;
147 char description[64];
148
149 /* ATM device */
150 struct atm_dev *atm_dev;
151
152 /********************************
153 * private fields - do not use *
Nicolas Kaiser16f76a72010-06-17 11:55:49 +0200154 ********************************/
Duncan Sandsc59bba72005-05-11 20:24:03 +0200155
156 struct kref refcount;
Arjan van de Venab3c81f2006-01-13 15:52:55 +0100157 struct mutex serialize;
Duncan Sands0e42a622006-01-13 10:05:15 +0100158 int disconnected;
Duncan Sandsc59bba72005-05-11 20:24:03 +0200159
160 /* heavy init */
Pavel Emelyanovc4504a72008-02-11 15:26:09 +0300161 struct task_struct *thread;
Duncan Sandsc59bba72005-05-11 20:24:03 +0200162 struct completion thread_started;
163 struct completion thread_exited;
164
165 /* ATM device */
166 struct list_head vcc_list;
167
168 struct usbatm_channel rx_channel;
169 struct usbatm_channel tx_channel;
170
171 struct sk_buff_head sndqueue;
Duncan Sands0ec3c7e2006-01-17 11:15:13 +0100172 struct sk_buff *current_skb; /* being emptied */
Duncan Sandsc59bba72005-05-11 20:24:03 +0200173
Duncan Sandse3fb2f62006-01-13 11:06:46 +0100174 struct usbatm_vcc_data *cached_vcc;
175 int cached_vci;
176 short cached_vpi;
177
178 unsigned char *cell_buf; /* holds partial rx cell */
179 unsigned int buf_usage;
180
Duncan Sandsc59bba72005-05-11 20:24:03 +0200181 struct urb *urbs[0];
182};
183
Simon Arlott9fc950d2009-11-21 15:33:51 +0000184static inline void *to_usbatm_driver_data(struct usb_interface *intf)
185{
186 struct usbatm_data *usbatm_instance;
187
188 if (intf == NULL)
189 return NULL;
190
191 usbatm_instance = usb_get_intfdata(intf);
192
193 if (usbatm_instance == NULL) /* set NULL before unbind() */
194 return NULL;
195
196 return usbatm_instance->driver_data; /* set NULL after unbind() */
197}
198
Duncan Sandsc59bba72005-05-11 20:24:03 +0200199#endif /* _USBATM_H_ */