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