This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / drivers / usb / atm / usb_atm.h
1 /******************************************************************************
2  *  usb_atm.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 #include <linux/list.h>
25 #include <linux/usb.h>
26 #include <linux/kref.h>
27 #include <linux/atm.h>
28 #include <linux/atmdev.h>
29 #include <asm/semaphore.h>
30
31 #define UDSL_MAX_RCV_URBS               4
32 #define UDSL_MAX_SND_URBS               4
33 #define UDSL_MAX_RCV_BUFS               8
34 #define UDSL_MAX_SND_BUFS               8
35 #define UDSL_MAX_RCV_BUF_SIZE           1024    /* ATM cells */
36 #define UDSL_MAX_SND_BUF_SIZE           1024    /* ATM cells */
37 #define UDSL_DEFAULT_RCV_URBS           2
38 #define UDSL_DEFAULT_SND_URBS           2
39 #define UDSL_DEFAULT_RCV_BUFS           4
40 #define UDSL_DEFAULT_SND_BUFS           4
41 #define UDSL_DEFAULT_RCV_BUF_SIZE       64      /* ATM cells */
42 #define UDSL_DEFAULT_SND_BUF_SIZE       64      /* ATM cells */
43
44 #define ATM_CELL_HEADER                 (ATM_CELL_SIZE - ATM_CELL_PAYLOAD)
45 #define UDSL_NUM_CELLS(x)               (((x) + ATM_AAL5_TRAILER + ATM_CELL_PAYLOAD - 1) / ATM_CELL_PAYLOAD)
46
47 /* receive */
48
49 struct udsl_receive_buffer {
50         struct list_head list;
51         unsigned char *base;
52         unsigned int filled_cells;
53 };
54
55 struct udsl_receiver {
56         struct list_head list;
57         struct udsl_receive_buffer *buffer;
58         struct urb *urb;
59         struct udsl_instance_data *instance;
60 };
61
62 struct udsl_vcc_data {
63         /* vpi/vci lookup */
64         struct list_head list;
65         short vpi;
66         int vci;
67         struct atm_vcc *vcc;
68
69         /* raw cell reassembly */
70         struct sk_buff *sarb;
71 };
72
73 /* send */
74
75 struct udsl_send_buffer {
76         struct list_head list;
77         unsigned char *base;
78         unsigned char *free_start;
79         unsigned int free_cells;
80 };
81
82 struct udsl_sender {
83         struct list_head list;
84         struct udsl_send_buffer *buffer;
85         struct urb *urb;
86         struct udsl_instance_data *instance;
87 };
88
89 struct udsl_control {
90         struct atm_skb_data atm_data;
91         unsigned int num_cells;
92         unsigned int num_entire;
93         unsigned int pdu_padding;
94         unsigned char cell_header[ATM_CELL_HEADER];
95         unsigned char aal5_trailer[ATM_AAL5_TRAILER];
96 };
97
98 #define UDSL_SKB(x)             ((struct udsl_control *)(x)->cb)
99
100 /* main driver data */
101
102 enum udsl_status {
103         UDSL_NO_FIRMWARE,
104         UDSL_LOADING_FIRMWARE,
105         UDSL_LOADED_FIRMWARE
106 };
107
108 struct udsl_instance_data {
109         struct kref refcount;
110         struct semaphore serialize;
111
112         /* USB device part */
113         struct usb_device *usb_dev;
114         char description[64];
115         int data_endpoint;
116         int snd_padding;
117         int rcv_padding;
118         const char *driver_name;
119
120         /* ATM device part */
121         struct atm_dev *atm_dev;
122         struct list_head vcc_list;
123
124         /* firmware */
125         int (*firmware_wait) (struct udsl_instance_data *);
126         enum udsl_status status;
127         wait_queue_head_t firmware_waiters;
128
129         /* receive */
130         struct udsl_receiver receivers[UDSL_MAX_RCV_URBS];
131         struct udsl_receive_buffer receive_buffers[UDSL_MAX_RCV_BUFS];
132
133         spinlock_t receive_lock;
134         struct list_head spare_receivers;
135         struct list_head filled_receive_buffers;
136
137         struct tasklet_struct receive_tasklet;
138         struct list_head spare_receive_buffers;
139
140         /* send */
141         struct udsl_sender senders[UDSL_MAX_SND_URBS];
142         struct udsl_send_buffer send_buffers[UDSL_MAX_SND_BUFS];
143
144         struct sk_buff_head sndqueue;
145
146         spinlock_t send_lock;
147         struct list_head spare_senders;
148         struct list_head spare_send_buffers;
149
150         struct tasklet_struct send_tasklet;
151         struct sk_buff *current_skb;                    /* being emptied */
152         struct udsl_send_buffer *current_buffer;        /* being filled */
153         struct list_head filled_send_buffers;
154 };
155
156 extern int udsl_instance_setup(struct usb_device *dev,
157                                struct udsl_instance_data *instance);
158 extern void udsl_instance_disconnect(struct udsl_instance_data *instance);
159 extern void udsl_get_instance(struct udsl_instance_data *instance);
160 extern void udsl_put_instance(struct udsl_instance_data *instance);