]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * hfc_usb.c | |
3 | * | |
7441dd12 | 4 | * $Id: hfc_usb.c,v 2.3.2.24 2007/10/14 08:40:29 mbachem Exp $ |
1da177e4 LT |
5 | * |
6 | * modular HiSax ISDN driver for Colognechip HFC-S USB chip | |
7 | * | |
d6c59c13 MB |
8 | * Authors : Peter Sprenger (sprenger@moving-bytes.de) |
9 | * Martin Bachem (m.bachem@gmx.de, info@colognechip.com) | |
1da177e4 LT |
10 | * |
11 | * based on the first hfc_usb driver of | |
12 | * Werner Cornelius (werner@isdn-development.de) | |
13 | * | |
14 | * This program is free software; you can redistribute it and/or modify | |
15 | * it under the terms of the GNU General Public License as published by | |
16 | * the Free Software Foundation; either version 2, or (at your option) | |
17 | * any later version. | |
18 | * | |
19 | * This program is distributed in the hope that it will be useful, | |
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 | * GNU General Public License for more details. | |
23 | * | |
24 | * You should have received a copy of the GNU General Public License | |
25 | * along with this program; if not, write to the Free Software | |
26 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
27 | * | |
28 | * See Version Histroy at the bottom of this file | |
29 | * | |
475be4d8 | 30 | */ |
1da177e4 LT |
31 | |
32 | #include <linux/types.h> | |
33 | #include <linux/stddef.h> | |
34 | #include <linux/timer.h> | |
1da177e4 LT |
35 | #include <linux/init.h> |
36 | #include <linux/module.h> | |
37 | #include <linux/kernel_stat.h> | |
38 | #include <linux/usb.h> | |
39 | #include <linux/kernel.h> | |
d6c59c13 MB |
40 | #include <linux/sched.h> |
41 | #include <linux/moduleparam.h> | |
5a0e3ad6 | 42 | #include <linux/slab.h> |
1da177e4 LT |
43 | #include "hisax.h" |
44 | #include "hisax_if.h" | |
45 | #include "hfc_usb.h" | |
46 | ||
1da177e4 | 47 | static const char *hfcusb_revision = |
475be4d8 | 48 | "$Revision: 2.3.2.24 $ $Date: 2007/10/14 08:40:29 $ "; |
1da177e4 LT |
49 | |
50 | /* Hisax debug support | |
475be4d8 JP |
51 | * debug flags defined in hfc_usb.h as HFCUSB_DBG_[*] |
52 | */ | |
1da177e4 LT |
53 | #define __debug_variable hfc_debug |
54 | #include "hisax_debug.h" | |
55 | static u_int debug; | |
56 | module_param(debug, uint, 0); | |
672c3fd9 | 57 | static int hfc_debug; |
d6c59c13 | 58 | |
1da177e4 | 59 | |
597a107b MB |
60 | /* private vendor specific data */ |
61 | typedef struct { | |
62 | __u8 led_scheme; // led display scheme | |
63 | signed short led_bits[8]; // array of 8 possible LED bitmask settings | |
64 | char *vend_name; // device name | |
65 | } hfcsusb_vdata; | |
1da177e4 | 66 | |
d6c59c13 | 67 | /* VID/PID device list */ |
585f46a8 | 68 | static const struct usb_device_id hfcusb_idtab[] = { |
597a107b | 69 | { |
475be4d8 JP |
70 | USB_DEVICE(0x0959, 0x2bd0), |
71 | .driver_info = (unsigned long) &((hfcsusb_vdata) | |
72 | {LED_OFF, {4, 0, 2, 1}, | |
73 | "ISDN USB TA (Cologne Chip HFC-S USB based)"}), | |
597a107b MB |
74 | }, |
75 | { | |
475be4d8 JP |
76 | USB_DEVICE(0x0675, 0x1688), |
77 | .driver_info = (unsigned long) &((hfcsusb_vdata) | |
78 | {LED_SCHEME1, {1, 2, 0, 0}, | |
79 | "DrayTek miniVigor 128 USB ISDN TA"}), | |
597a107b MB |
80 | }, |
81 | { | |
475be4d8 JP |
82 | USB_DEVICE(0x07b0, 0x0007), |
83 | .driver_info = (unsigned long) &((hfcsusb_vdata) | |
84 | {LED_SCHEME1, {0x80, -64, -32, -16}, | |
85 | "Billion tiny USB ISDN TA 128"}), | |
597a107b MB |
86 | }, |
87 | { | |
475be4d8 JP |
88 | USB_DEVICE(0x0742, 0x2008), |
89 | .driver_info = (unsigned long) &((hfcsusb_vdata) | |
90 | {LED_SCHEME1, {4, 0, 2, 1}, | |
91 | "Stollmann USB TA"}), | |
d6c59c13 | 92 | }, |
597a107b | 93 | { |
475be4d8 JP |
94 | USB_DEVICE(0x0742, 0x2009), |
95 | .driver_info = (unsigned long) &((hfcsusb_vdata) | |
96 | {LED_SCHEME1, {4, 0, 2, 1}, | |
97 | "Aceex USB ISDN TA"}), | |
d6c59c13 | 98 | }, |
597a107b | 99 | { |
475be4d8 JP |
100 | USB_DEVICE(0x0742, 0x200A), |
101 | .driver_info = (unsigned long) &((hfcsusb_vdata) | |
102 | {LED_SCHEME1, {4, 0, 2, 1}, | |
103 | "OEM USB ISDN TA"}), | |
d6c59c13 | 104 | }, |
597a107b | 105 | { |
475be4d8 JP |
106 | USB_DEVICE(0x08e3, 0x0301), |
107 | .driver_info = (unsigned long) &((hfcsusb_vdata) | |
108 | {LED_SCHEME1, {2, 0, 1, 4}, | |
109 | "Olitec USB RNIS"}), | |
d6c59c13 | 110 | }, |
597a107b | 111 | { |
475be4d8 JP |
112 | USB_DEVICE(0x07fa, 0x0846), |
113 | .driver_info = (unsigned long) &((hfcsusb_vdata) | |
114 | {LED_SCHEME1, {0x80, -64, -32, -16}, | |
115 | "Bewan Modem RNIS USB"}), | |
d6c59c13 | 116 | }, |
597a107b | 117 | { |
475be4d8 JP |
118 | USB_DEVICE(0x07fa, 0x0847), |
119 | .driver_info = (unsigned long) &((hfcsusb_vdata) | |
120 | {LED_SCHEME1, {0x80, -64, -32, -16}, | |
121 | "Djinn Numeris USB"}), | |
d6c59c13 | 122 | }, |
597a107b | 123 | { |
475be4d8 JP |
124 | USB_DEVICE(0x07b0, 0x0006), |
125 | .driver_info = (unsigned long) &((hfcsusb_vdata) | |
126 | {LED_SCHEME1, {0x80, -64, -32, -16}, | |
127 | "Twister ISDN TA"}), | |
d6c59c13 | 128 | }, |
7441dd12 | 129 | { |
475be4d8 JP |
130 | USB_DEVICE(0x071d, 0x1005), |
131 | .driver_info = (unsigned long) &((hfcsusb_vdata) | |
132 | {LED_SCHEME1, {0x02, 0, 0x01, 0x04}, | |
133 | "Eicon DIVA USB 4.0"}), | |
7441dd12 | 134 | }, |
d6a1a64a | 135 | { } |
1da177e4 LT |
136 | }; |
137 | ||
1da177e4 | 138 | /* structure defining input+output fifos (interrupt/bulk mode) */ |
1da177e4 LT |
139 | struct usb_fifo; /* forward definition */ |
140 | typedef struct iso_urb_struct { | |
141 | struct urb *purb; | |
142 | __u8 buffer[ISO_BUFFER_SIZE]; /* buffer incoming/outgoing data */ | |
143 | struct usb_fifo *owner_fifo; /* pointer to owner fifo */ | |
144 | } iso_urb_struct; | |
145 | ||
1da177e4 | 146 | struct hfcusb_data; /* forward definition */ |
d6c59c13 | 147 | |
1da177e4 LT |
148 | typedef struct usb_fifo { |
149 | int fifonum; /* fifo index attached to this structure */ | |
150 | int active; /* fifo is currently active */ | |
151 | struct hfcusb_data *hfc; /* pointer to main structure */ | |
152 | int pipe; /* address of endpoint */ | |
153 | __u8 usb_packet_maxlen; /* maximum length for usb transfer */ | |
154 | unsigned int max_size; /* maximum size of receive/send packet */ | |
155 | __u8 intervall; /* interrupt interval */ | |
156 | struct sk_buff *skbuff; /* actual used buffer */ | |
157 | struct urb *urb; /* transfer structure for usb routines */ | |
158 | __u8 buffer[128]; /* buffer incoming/outgoing data */ | |
159 | int bit_line; /* how much bits are in the fifo? */ | |
160 | ||
161 | volatile __u8 usb_transfer_mode; /* switched between ISO and INT */ | |
162 | iso_urb_struct iso[2]; /* need two urbs to have one always for pending */ | |
163 | struct hisax_if *hif; /* hisax interface */ | |
164 | int delete_flg; /* only delete skbuff once */ | |
165 | int last_urblen; /* remember length of last packet */ | |
1da177e4 LT |
166 | } usb_fifo; |
167 | ||
1da177e4 | 168 | /* structure holding all data for one device */ |
1da177e4 LT |
169 | typedef struct hfcusb_data { |
170 | /* HiSax Interface for loadable Layer1 drivers */ | |
d6c59c13 | 171 | struct hisax_d_if d_if; /* see hisax_if.h */ |
1da177e4 LT |
172 | struct hisax_b_if b_if[2]; /* see hisax_if.h */ |
173 | int protocol; | |
174 | ||
175 | struct usb_device *dev; /* our device */ | |
176 | int if_used; /* used interface number */ | |
177 | int alt_used; /* used alternate config */ | |
178 | int ctrl_paksize; /* control pipe packet size */ | |
d6c59c13 | 179 | int ctrl_in_pipe, /* handles for control pipe */ |
475be4d8 | 180 | ctrl_out_pipe; |
1da177e4 LT |
181 | int cfg_used; /* configuration index used */ |
182 | int vend_idx; /* vendor found */ | |
183 | int b_mode[2]; /* B-channel mode */ | |
184 | int l1_activated; /* layer 1 activated */ | |
d6c59c13 | 185 | int disc_flag; /* TRUE if device was disonnected to avoid some USB actions */ |
1da177e4 LT |
186 | int packet_size, iso_packet_size; |
187 | ||
188 | /* control pipe background handling */ | |
189 | ctrl_buft ctrl_buff[HFC_CTRL_BUFSIZE]; /* buffer holding queued data */ | |
190 | volatile int ctrl_in_idx, ctrl_out_idx, ctrl_cnt; /* input/output pointer + count */ | |
191 | struct urb *ctrl_urb; /* transfer structure for control channel */ | |
192 | ||
193 | struct usb_ctrlrequest ctrl_write; /* buffer for control write request */ | |
194 | struct usb_ctrlrequest ctrl_read; /* same for read request */ | |
195 | ||
7441dd12 | 196 | __u8 old_led_state, led_state; |
1da177e4 LT |
197 | |
198 | volatile __u8 threshold_mask; /* threshold actually reported */ | |
199 | volatile __u8 bch_enables; /* or mask for sctrl_r and sctrl register values */ | |
200 | ||
201 | usb_fifo fifos[HFCUSB_NUM_FIFOS]; /* structure holding all fifo data */ | |
202 | ||
203 | volatile __u8 l1_state; /* actual l1 state */ | |
204 | struct timer_list t3_timer; /* timer 3 for activation/deactivation */ | |
205 | struct timer_list t4_timer; /* timer 4 for activation/deactivation */ | |
1da177e4 LT |
206 | } hfcusb_data; |
207 | ||
208 | ||
475be4d8 | 209 | static void collect_rx_frame(usb_fifo *fifo, __u8 *data, int len, |
1da177e4 LT |
210 | int finish); |
211 | ||
1da177e4 LT |
212 | static inline const char * |
213 | symbolic(struct hfcusb_symbolic_list list[], const int num) | |
214 | { | |
215 | int i; | |
216 | for (i = 0; list[i].name != NULL; i++) | |
217 | if (list[i].num == num) | |
218 | return (list[i].name); | |
b05121b2 | 219 | return "<unknown ERROR>"; |
1da177e4 LT |
220 | } |
221 | ||
1da177e4 | 222 | static void |
475be4d8 | 223 | ctrl_start_transfer(hfcusb_data *hfc) |
1da177e4 LT |
224 | { |
225 | if (hfc->ctrl_cnt) { | |
226 | hfc->ctrl_urb->pipe = hfc->ctrl_out_pipe; | |
475be4d8 | 227 | hfc->ctrl_urb->setup_packet = (u_char *)&hfc->ctrl_write; |
1da177e4 LT |
228 | hfc->ctrl_urb->transfer_buffer = NULL; |
229 | hfc->ctrl_urb->transfer_buffer_length = 0; | |
230 | hfc->ctrl_write.wIndex = | |
475be4d8 | 231 | cpu_to_le16(hfc->ctrl_buff[hfc->ctrl_out_idx].hfc_reg); |
1da177e4 | 232 | hfc->ctrl_write.wValue = |
475be4d8 | 233 | cpu_to_le16(hfc->ctrl_buff[hfc->ctrl_out_idx].reg_val); |
1da177e4 LT |
234 | |
235 | usb_submit_urb(hfc->ctrl_urb, GFP_ATOMIC); /* start transfer */ | |
236 | } | |
237 | } /* ctrl_start_transfer */ | |
238 | ||
1da177e4 | 239 | static int |
475be4d8 | 240 | queue_control_request(hfcusb_data *hfc, __u8 reg, __u8 val, int action) |
1da177e4 LT |
241 | { |
242 | ctrl_buft *buf; | |
243 | ||
244 | if (hfc->ctrl_cnt >= HFC_CTRL_BUFSIZE) | |
245 | return (1); /* no space left */ | |
246 | buf = &hfc->ctrl_buff[hfc->ctrl_in_idx]; /* pointer to new index */ | |
247 | buf->hfc_reg = reg; | |
248 | buf->reg_val = val; | |
249 | buf->action = action; | |
250 | if (++hfc->ctrl_in_idx >= HFC_CTRL_BUFSIZE) | |
251 | hfc->ctrl_in_idx = 0; /* pointer wrap */ | |
252 | if (++hfc->ctrl_cnt == 1) | |
253 | ctrl_start_transfer(hfc); | |
254 | return (0); | |
1da177e4 LT |
255 | } |
256 | ||
1da177e4 | 257 | static void |
7d12e780 | 258 | ctrl_complete(struct urb *urb) |
1da177e4 LT |
259 | { |
260 | hfcusb_data *hfc = (hfcusb_data *) urb->context; | |
1da177e4 LT |
261 | |
262 | urb->dev = hfc->dev; | |
263 | if (hfc->ctrl_cnt) { | |
1da177e4 LT |
264 | hfc->ctrl_cnt--; /* decrement actual count */ |
265 | if (++hfc->ctrl_out_idx >= HFC_CTRL_BUFSIZE) | |
266 | hfc->ctrl_out_idx = 0; /* pointer wrap */ | |
267 | ||
268 | ctrl_start_transfer(hfc); /* start next transfer */ | |
269 | } | |
7441dd12 | 270 | } |
1da177e4 | 271 | |
1da177e4 | 272 | /* write led data to auxport & invert if necessary */ |
1da177e4 | 273 | static void |
475be4d8 | 274 | write_led(hfcusb_data *hfc, __u8 led_state) |
1da177e4 LT |
275 | { |
276 | if (led_state != hfc->old_led_state) { | |
277 | hfc->old_led_state = led_state; | |
278 | queue_control_request(hfc, HFCUSB_P_DATA, led_state, 1); | |
279 | } | |
280 | } | |
281 | ||
1da177e4 | 282 | static void |
475be4d8 | 283 | set_led_bit(hfcusb_data *hfc, signed short led_bits, int on) |
1da177e4 | 284 | { |
7441dd12 | 285 | if (on) { |
1da177e4 | 286 | if (led_bits < 0) |
7441dd12 | 287 | hfc->led_state &= ~abs(led_bits); |
1da177e4 | 288 | else |
7441dd12 | 289 | hfc->led_state |= led_bits; |
1da177e4 LT |
290 | } else { |
291 | if (led_bits < 0) | |
7441dd12 | 292 | hfc->led_state |= abs(led_bits); |
1da177e4 | 293 | else |
7441dd12 | 294 | hfc->led_state &= ~led_bits; |
1da177e4 LT |
295 | } |
296 | } | |
297 | ||
d6c59c13 | 298 | /* handle LED requests */ |
1da177e4 | 299 | static void |
475be4d8 | 300 | handle_led(hfcusb_data *hfc, int event) |
1da177e4 | 301 | { |
597a107b | 302 | hfcsusb_vdata *driver_info = |
475be4d8 | 303 | (hfcsusb_vdata *) hfcusb_idtab[hfc->vend_idx].driver_info; |
597a107b | 304 | |
1da177e4 | 305 | /* if no scheme -> no LED action */ |
597a107b | 306 | if (driver_info->led_scheme == LED_OFF) |
1da177e4 LT |
307 | return; |
308 | ||
309 | switch (event) { | |
475be4d8 JP |
310 | case LED_POWER_ON: |
311 | set_led_bit(hfc, driver_info->led_bits[0], 1); | |
312 | set_led_bit(hfc, driver_info->led_bits[1], 0); | |
313 | set_led_bit(hfc, driver_info->led_bits[2], 0); | |
314 | set_led_bit(hfc, driver_info->led_bits[3], 0); | |
315 | break; | |
316 | case LED_POWER_OFF: | |
317 | set_led_bit(hfc, driver_info->led_bits[0], 0); | |
318 | set_led_bit(hfc, driver_info->led_bits[1], 0); | |
319 | set_led_bit(hfc, driver_info->led_bits[2], 0); | |
320 | set_led_bit(hfc, driver_info->led_bits[3], 0); | |
321 | break; | |
322 | case LED_S0_ON: | |
323 | set_led_bit(hfc, driver_info->led_bits[1], 1); | |
324 | break; | |
325 | case LED_S0_OFF: | |
326 | set_led_bit(hfc, driver_info->led_bits[1], 0); | |
327 | break; | |
328 | case LED_B1_ON: | |
329 | set_led_bit(hfc, driver_info->led_bits[2], 1); | |
330 | break; | |
331 | case LED_B1_OFF: | |
332 | set_led_bit(hfc, driver_info->led_bits[2], 0); | |
333 | break; | |
334 | case LED_B2_ON: | |
335 | set_led_bit(hfc, driver_info->led_bits[3], 1); | |
336 | break; | |
337 | case LED_B2_OFF: | |
338 | set_led_bit(hfc, driver_info->led_bits[3], 0); | |
339 | break; | |
1da177e4 | 340 | } |
1da177e4 LT |
341 | write_led(hfc, hfc->led_state); |
342 | } | |
343 | ||
d6c59c13 | 344 | /* ISDN l1 timer T3 expires */ |
1da177e4 | 345 | static void |
475be4d8 | 346 | l1_timer_expire_t3(hfcusb_data *hfc) |
1da177e4 LT |
347 | { |
348 | hfc->d_if.ifc.l1l2(&hfc->d_if.ifc, PH_DEACTIVATE | INDICATION, | |
349 | NULL); | |
d6c59c13 MB |
350 | |
351 | DBG(HFCUSB_DBG_STATES, | |
1da177e4 | 352 | "HFC-S USB: PH_DEACTIVATE | INDICATION sent (T3 expire)"); |
d6c59c13 MB |
353 | |
354 | hfc->l1_activated = 0; | |
1da177e4 LT |
355 | handle_led(hfc, LED_S0_OFF); |
356 | /* deactivate : */ | |
357 | queue_control_request(hfc, HFCUSB_STATES, 0x10, 1); | |
358 | queue_control_request(hfc, HFCUSB_STATES, 3, 1); | |
359 | } | |
360 | ||
d6c59c13 | 361 | /* ISDN l1 timer T4 expires */ |
1da177e4 | 362 | static void |
475be4d8 | 363 | l1_timer_expire_t4(hfcusb_data *hfc) |
1da177e4 LT |
364 | { |
365 | hfc->d_if.ifc.l1l2(&hfc->d_if.ifc, PH_DEACTIVATE | INDICATION, | |
366 | NULL); | |
d6c59c13 MB |
367 | |
368 | DBG(HFCUSB_DBG_STATES, | |
1da177e4 | 369 | "HFC-S USB: PH_DEACTIVATE | INDICATION sent (T4 expire)"); |
d6c59c13 MB |
370 | |
371 | hfc->l1_activated = 0; | |
1da177e4 LT |
372 | handle_led(hfc, LED_S0_OFF); |
373 | } | |
374 | ||
d6c59c13 | 375 | /* S0 state changed */ |
1da177e4 | 376 | static void |
475be4d8 | 377 | s0_state_handler(hfcusb_data *hfc, __u8 state) |
1da177e4 LT |
378 | { |
379 | __u8 old_state; | |
380 | ||
381 | old_state = hfc->l1_state; | |
382 | if (state == old_state || state < 1 || state > 8) | |
383 | return; | |
384 | ||
d6c59c13 MB |
385 | DBG(HFCUSB_DBG_STATES, "HFC-S USB: S0 statechange(%d -> %d)", |
386 | old_state, state); | |
387 | ||
1da177e4 LT |
388 | if (state < 4 || state == 7 || state == 8) { |
389 | if (timer_pending(&hfc->t3_timer)) | |
390 | del_timer(&hfc->t3_timer); | |
d6c59c13 | 391 | DBG(HFCUSB_DBG_STATES, "HFC-S USB: T3 deactivated"); |
1da177e4 LT |
392 | } |
393 | if (state >= 7) { | |
394 | if (timer_pending(&hfc->t4_timer)) | |
395 | del_timer(&hfc->t4_timer); | |
d6c59c13 | 396 | DBG(HFCUSB_DBG_STATES, "HFC-S USB: T4 deactivated"); |
1da177e4 LT |
397 | } |
398 | ||
399 | if (state == 7 && !hfc->l1_activated) { | |
400 | hfc->d_if.ifc.l1l2(&hfc->d_if.ifc, | |
401 | PH_ACTIVATE | INDICATION, NULL); | |
d6c59c13 MB |
402 | DBG(HFCUSB_DBG_STATES, "HFC-S USB: PH_ACTIVATE | INDICATION sent"); |
403 | hfc->l1_activated = 1; | |
1da177e4 | 404 | handle_led(hfc, LED_S0_ON); |
475be4d8 | 405 | } else if (state <= 3 /* && activated */) { |
1da177e4 | 406 | if (old_state == 7 || old_state == 8) { |
d6c59c13 | 407 | DBG(HFCUSB_DBG_STATES, "HFC-S USB: T4 activated"); |
1da177e4 LT |
408 | if (!timer_pending(&hfc->t4_timer)) { |
409 | hfc->t4_timer.expires = | |
475be4d8 | 410 | jiffies + (HFC_TIMER_T4 * HZ) / 1000; |
1da177e4 LT |
411 | add_timer(&hfc->t4_timer); |
412 | } | |
413 | } else { | |
414 | hfc->d_if.ifc.l1l2(&hfc->d_if.ifc, | |
415 | PH_DEACTIVATE | INDICATION, | |
416 | NULL); | |
d6c59c13 | 417 | DBG(HFCUSB_DBG_STATES, |
1da177e4 | 418 | "HFC-S USB: PH_DEACTIVATE | INDICATION sent"); |
d6c59c13 | 419 | hfc->l1_activated = 0; |
1da177e4 LT |
420 | handle_led(hfc, LED_S0_OFF); |
421 | } | |
422 | } | |
423 | hfc->l1_state = state; | |
424 | } | |
425 | ||
1da177e4 LT |
426 | static void |
427 | fill_isoc_urb(struct urb *urb, struct usb_device *dev, unsigned int pipe, | |
428 | void *buf, int num_packets, int packet_size, int interval, | |
429 | usb_complete_t complete, void *context) | |
430 | { | |
431 | int k; | |
432 | ||
1da177e4 LT |
433 | urb->dev = dev; |
434 | urb->pipe = pipe; | |
435 | urb->complete = complete; | |
436 | urb->number_of_packets = num_packets; | |
437 | urb->transfer_buffer_length = packet_size * num_packets; | |
438 | urb->context = context; | |
439 | urb->transfer_buffer = buf; | |
440 | urb->transfer_flags = URB_ISO_ASAP; | |
441 | urb->actual_length = 0; | |
442 | urb->interval = interval; | |
443 | for (k = 0; k < num_packets; k++) { | |
444 | urb->iso_frame_desc[k].offset = packet_size * k; | |
445 | urb->iso_frame_desc[k].length = packet_size; | |
446 | urb->iso_frame_desc[k].actual_length = 0; | |
447 | } | |
448 | } | |
449 | ||
450 | /* allocs urbs and start isoc transfer with two pending urbs to avoid | |
d6c59c13 MB |
451 | * gaps in the transfer chain |
452 | */ | |
1da177e4 | 453 | static int |
475be4d8 | 454 | start_isoc_chain(usb_fifo *fifo, int num_packets_per_urb, |
1da177e4 LT |
455 | usb_complete_t complete, int packet_size) |
456 | { | |
457 | int i, k, errcode; | |
458 | ||
d6c59c13 MB |
459 | DBG(HFCUSB_DBG_INIT, "HFC-S USB: starting ISO-URBs for fifo:%d\n", |
460 | fifo->fifonum); | |
1da177e4 LT |
461 | |
462 | /* allocate Memory for Iso out Urbs */ | |
463 | for (i = 0; i < 2; i++) { | |
464 | if (!(fifo->iso[i].purb)) { | |
465 | fifo->iso[i].purb = | |
475be4d8 | 466 | usb_alloc_urb(num_packets_per_urb, GFP_KERNEL); |
1da177e4 LT |
467 | if (!(fifo->iso[i].purb)) { |
468 | printk(KERN_INFO | |
469 | "alloc urb for fifo %i failed!!!", | |
470 | fifo->fifonum); | |
471 | } | |
472 | fifo->iso[i].owner_fifo = (struct usb_fifo *) fifo; | |
473 | ||
474 | /* Init the first iso */ | |
475 | if (ISO_BUFFER_SIZE >= | |
476 | (fifo->usb_packet_maxlen * | |
477 | num_packets_per_urb)) { | |
478 | fill_isoc_urb(fifo->iso[i].purb, | |
479 | fifo->hfc->dev, fifo->pipe, | |
480 | fifo->iso[i].buffer, | |
481 | num_packets_per_urb, | |
482 | fifo->usb_packet_maxlen, | |
483 | fifo->intervall, complete, | |
484 | &fifo->iso[i]); | |
485 | memset(fifo->iso[i].buffer, 0, | |
486 | sizeof(fifo->iso[i].buffer)); | |
487 | /* defining packet delimeters in fifo->buffer */ | |
488 | for (k = 0; k < num_packets_per_urb; k++) { | |
489 | fifo->iso[i].purb-> | |
475be4d8 JP |
490 | iso_frame_desc[k].offset = |
491 | k * packet_size; | |
1da177e4 | 492 | fifo->iso[i].purb-> |
475be4d8 JP |
493 | iso_frame_desc[k].length = |
494 | packet_size; | |
1da177e4 LT |
495 | } |
496 | } else { | |
497 | printk(KERN_INFO | |
498 | "HFC-S USB: ISO Buffer size to small!\n"); | |
499 | } | |
500 | } | |
501 | fifo->bit_line = BITLINE_INF; | |
502 | ||
503 | errcode = usb_submit_urb(fifo->iso[i].purb, GFP_KERNEL); | |
504 | fifo->active = (errcode >= 0) ? 1 : 0; | |
d6c59c13 MB |
505 | if (errcode < 0) |
506 | printk(KERN_INFO "HFC-S USB: usb_submit_urb URB nr:%d, error(%i): '%s'\n", | |
507 | i, errcode, symbolic(urb_errlist, errcode)); | |
1da177e4 LT |
508 | } |
509 | return (fifo->active); | |
510 | } | |
511 | ||
512 | /* stops running iso chain and frees their pending urbs */ | |
513 | static void | |
475be4d8 | 514 | stop_isoc_chain(usb_fifo *fifo) |
1da177e4 LT |
515 | { |
516 | int i; | |
517 | ||
518 | for (i = 0; i < 2; i++) { | |
519 | if (fifo->iso[i].purb) { | |
d6c59c13 | 520 | DBG(HFCUSB_DBG_INIT, |
1da177e4 LT |
521 | "HFC-S USB: Stopping iso chain for fifo %i.%i", |
522 | fifo->fifonum, i); | |
ae2d990e | 523 | usb_kill_urb(fifo->iso[i].purb); |
1da177e4 LT |
524 | usb_free_urb(fifo->iso[i].purb); |
525 | fifo->iso[i].purb = NULL; | |
526 | } | |
527 | } | |
d6c59c13 | 528 | |
ae2d990e AS |
529 | usb_kill_urb(fifo->urb); |
530 | usb_free_urb(fifo->urb); | |
531 | fifo->urb = NULL; | |
1da177e4 LT |
532 | fifo->active = 0; |
533 | } | |
534 | ||
535 | /* defines how much ISO packets are handled in one URB */ | |
536 | static int iso_packets[8] = | |
475be4d8 JP |
537 | { ISOC_PACKETS_B, ISOC_PACKETS_B, ISOC_PACKETS_B, ISOC_PACKETS_B, |
538 | ISOC_PACKETS_D, ISOC_PACKETS_D, ISOC_PACKETS_D, ISOC_PACKETS_D | |
1da177e4 LT |
539 | }; |
540 | ||
1da177e4 | 541 | static void |
7d12e780 | 542 | tx_iso_complete(struct urb *urb) |
1da177e4 LT |
543 | { |
544 | iso_urb_struct *context_iso_urb = (iso_urb_struct *) urb->context; | |
545 | usb_fifo *fifo = context_iso_urb->owner_fifo; | |
546 | hfcusb_data *hfc = fifo->hfc; | |
547 | int k, tx_offset, num_isoc_packets, sink, len, current_len, | |
475be4d8 | 548 | errcode; |
1da177e4 LT |
549 | int frame_complete, transp_mode, fifon, status; |
550 | __u8 threshbit; | |
1da177e4 LT |
551 | |
552 | fifon = fifo->fifonum; | |
553 | status = urb->status; | |
554 | ||
555 | tx_offset = 0; | |
556 | ||
d6c59c13 MB |
557 | /* ISO transfer only partially completed, |
558 | look at individual frame status for details */ | |
559 | if (status == -EXDEV) { | |
560 | DBG(HFCUSB_DBG_VERBOSE_USB, "HFC-S USB: tx_iso_complete with -EXDEV" | |
561 | ", urb->status %d, fifonum %d\n", | |
562 | status, fifon); | |
563 | ||
564 | for (k = 0; k < iso_packets[fifon]; ++k) { | |
565 | errcode = urb->iso_frame_desc[k].status; | |
566 | if (errcode) | |
567 | DBG(HFCUSB_DBG_VERBOSE_USB, "HFC-S USB: tx_iso_complete " | |
475be4d8 JP |
568 | "packet %i, status: %i\n", |
569 | k, errcode); | |
d6c59c13 MB |
570 | } |
571 | ||
572 | // clear status, so go on with ISO transfers | |
573 | status = 0; | |
574 | } | |
575 | ||
1da177e4 LT |
576 | if (fifo->active && !status) { |
577 | transp_mode = 0; | |
578 | if (fifon < 4 && hfc->b_mode[fifon / 2] == L1_MODE_TRANS) | |
d6c59c13 | 579 | transp_mode = 1; |
1da177e4 LT |
580 | |
581 | /* is FifoFull-threshold set for our channel? */ | |
d6c59c13 | 582 | threshbit = (hfc->threshold_mask & (1 << fifon)); |
1da177e4 LT |
583 | num_isoc_packets = iso_packets[fifon]; |
584 | ||
585 | /* predict dataflow to avoid fifo overflow */ | |
586 | if (fifon >= HFCUSB_D_TX) { | |
587 | sink = (threshbit) ? SINK_DMIN : SINK_DMAX; | |
588 | } else { | |
589 | sink = (threshbit) ? SINK_MIN : SINK_MAX; | |
590 | } | |
591 | fill_isoc_urb(urb, fifo->hfc->dev, fifo->pipe, | |
592 | context_iso_urb->buffer, num_isoc_packets, | |
593 | fifo->usb_packet_maxlen, fifo->intervall, | |
594 | tx_iso_complete, urb->context); | |
595 | memset(context_iso_urb->buffer, 0, | |
596 | sizeof(context_iso_urb->buffer)); | |
d6c59c13 MB |
597 | frame_complete = 0; |
598 | ||
599 | /* Generate next ISO Packets */ | |
1da177e4 LT |
600 | for (k = 0; k < num_isoc_packets; ++k) { |
601 | if (fifo->skbuff) { | |
602 | len = fifo->skbuff->len; | |
603 | /* we lower data margin every msec */ | |
604 | fifo->bit_line -= sink; | |
605 | current_len = (0 - fifo->bit_line) / 8; | |
606 | /* maximum 15 byte for every ISO packet makes our life easier */ | |
607 | if (current_len > 14) | |
608 | current_len = 14; | |
609 | current_len = | |
475be4d8 JP |
610 | (len <= |
611 | current_len) ? len : current_len; | |
1da177e4 LT |
612 | /* how much bit do we put on the line? */ |
613 | fifo->bit_line += current_len * 8; | |
614 | ||
615 | context_iso_urb->buffer[tx_offset] = 0; | |
616 | if (current_len == len) { | |
617 | if (!transp_mode) { | |
618 | /* here frame completion */ | |
619 | context_iso_urb-> | |
475be4d8 | 620 | buffer[tx_offset] = 1; |
1da177e4 LT |
621 | /* add 2 byte flags and 16bit CRC at end of ISDN frame */ |
622 | fifo->bit_line += 32; | |
623 | } | |
d6c59c13 | 624 | frame_complete = 1; |
1da177e4 LT |
625 | } |
626 | ||
627 | memcpy(context_iso_urb->buffer + | |
628 | tx_offset + 1, fifo->skbuff->data, | |
629 | current_len); | |
630 | skb_pull(fifo->skbuff, current_len); | |
631 | ||
632 | /* define packet delimeters within the URB buffer */ | |
633 | urb->iso_frame_desc[k].offset = tx_offset; | |
634 | urb->iso_frame_desc[k].length = | |
475be4d8 | 635 | current_len + 1; |
1da177e4 LT |
636 | |
637 | tx_offset += (current_len + 1); | |
1da177e4 LT |
638 | } else { |
639 | urb->iso_frame_desc[k].offset = | |
475be4d8 | 640 | tx_offset++; |
1da177e4 LT |
641 | |
642 | urb->iso_frame_desc[k].length = 1; | |
643 | fifo->bit_line -= sink; /* we lower data margin every msec */ | |
644 | ||
645 | if (fifo->bit_line < BITLINE_INF) { | |
646 | fifo->bit_line = BITLINE_INF; | |
647 | } | |
648 | } | |
649 | ||
650 | if (frame_complete) { | |
d6c59c13 | 651 | fifo->delete_flg = 1; |
1da177e4 LT |
652 | fifo->hif->l1l2(fifo->hif, |
653 | PH_DATA | CONFIRM, | |
17a4506d | 654 | (void *) (unsigned long) fifo->skbuff-> |
1da177e4 LT |
655 | truesize); |
656 | if (fifo->skbuff && fifo->delete_flg) { | |
657 | dev_kfree_skb_any(fifo->skbuff); | |
658 | fifo->skbuff = NULL; | |
d6c59c13 | 659 | fifo->delete_flg = 0; |
1da177e4 | 660 | } |
d6c59c13 | 661 | frame_complete = 0; |
1da177e4 LT |
662 | } |
663 | } | |
664 | errcode = usb_submit_urb(urb, GFP_ATOMIC); | |
665 | if (errcode < 0) { | |
666 | printk(KERN_INFO | |
d6c59c13 | 667 | "HFC-S USB: error submitting ISO URB: %d\n", |
1da177e4 LT |
668 | errcode); |
669 | } | |
670 | } else { | |
671 | if (status && !hfc->disc_flag) { | |
672 | printk(KERN_INFO | |
d6c59c13 MB |
673 | "HFC-S USB: tx_iso_complete: error(%i): '%s', fifonum=%d\n", |
674 | status, symbolic(urb_errlist, status), fifon); | |
1da177e4 LT |
675 | } |
676 | } | |
d6c59c13 | 677 | } |
1da177e4 | 678 | |
1da177e4 | 679 | static void |
7d12e780 | 680 | rx_iso_complete(struct urb *urb) |
1da177e4 LT |
681 | { |
682 | iso_urb_struct *context_iso_urb = (iso_urb_struct *) urb->context; | |
683 | usb_fifo *fifo = context_iso_urb->owner_fifo; | |
684 | hfcusb_data *hfc = fifo->hfc; | |
685 | int k, len, errcode, offset, num_isoc_packets, fifon, maxlen, | |
475be4d8 | 686 | status; |
1da177e4 LT |
687 | unsigned int iso_status; |
688 | __u8 *buf; | |
689 | static __u8 eof[8]; | |
1da177e4 LT |
690 | |
691 | fifon = fifo->fifonum; | |
692 | status = urb->status; | |
693 | ||
694 | if (urb->status == -EOVERFLOW) { | |
d6c59c13 MB |
695 | DBG(HFCUSB_DBG_VERBOSE_USB, |
696 | "HFC-USB: ignoring USB DATAOVERRUN fifo(%i)", fifon); | |
697 | status = 0; | |
698 | } | |
699 | ||
700 | /* ISO transfer only partially completed, | |
701 | look at individual frame status for details */ | |
702 | if (status == -EXDEV) { | |
703 | DBG(HFCUSB_DBG_VERBOSE_USB, "HFC-S USB: rx_iso_complete with -EXDEV " | |
704 | "urb->status %d, fifonum %d\n", | |
705 | status, fifon); | |
1da177e4 LT |
706 | status = 0; |
707 | } | |
d6c59c13 | 708 | |
1da177e4 LT |
709 | if (fifo->active && !status) { |
710 | num_isoc_packets = iso_packets[fifon]; | |
711 | maxlen = fifo->usb_packet_maxlen; | |
712 | for (k = 0; k < num_isoc_packets; ++k) { | |
713 | len = urb->iso_frame_desc[k].actual_length; | |
714 | offset = urb->iso_frame_desc[k].offset; | |
715 | buf = context_iso_urb->buffer + offset; | |
716 | iso_status = urb->iso_frame_desc[k].status; | |
d6c59c13 | 717 | |
1da177e4 | 718 | if (iso_status && !hfc->disc_flag) |
d6c59c13 MB |
719 | DBG(HFCUSB_DBG_VERBOSE_USB, |
720 | "HFC-S USB: rx_iso_complete " | |
721 | "ISO packet %i, status: %i\n", | |
722 | k, iso_status); | |
1da177e4 | 723 | |
d6c59c13 MB |
724 | if (fifon == HFCUSB_D_RX) { |
725 | DBG(HFCUSB_DBG_VERBOSE_USB, | |
475be4d8 JP |
726 | "HFC-S USB: ISO-D-RX lst_urblen:%2d " |
727 | "act_urblen:%2d max-urblen:%2d EOF:0x%0x", | |
728 | fifo->last_urblen, len, maxlen, | |
729 | eof[5]); | |
d6c59c13 MB |
730 | |
731 | DBG_PACKET(HFCUSB_DBG_VERBOSE_USB, buf, len); | |
1da177e4 | 732 | } |
d6c59c13 | 733 | |
1da177e4 LT |
734 | if (fifo->last_urblen != maxlen) { |
735 | /* the threshold mask is in the 2nd status byte */ | |
736 | hfc->threshold_mask = buf[1]; | |
737 | /* care for L1 state only for D-Channel | |
738 | to avoid overlapped iso completions */ | |
d6c59c13 | 739 | if (fifon == HFCUSB_D_RX) { |
1da177e4 LT |
740 | /* the S0 state is in the upper half |
741 | of the 1st status byte */ | |
d6c59c13 | 742 | s0_state_handler(hfc, buf[0] >> 4); |
1da177e4 LT |
743 | } |
744 | eof[fifon] = buf[0] & 1; | |
745 | if (len > 2) | |
746 | collect_rx_frame(fifo, buf + 2, | |
747 | len - 2, | |
d6c59c13 | 748 | (len < maxlen) ? |
1da177e4 LT |
749 | eof[fifon] : 0); |
750 | } else { | |
751 | collect_rx_frame(fifo, buf, len, | |
752 | (len < | |
753 | maxlen) ? eof[fifon] : | |
754 | 0); | |
755 | } | |
756 | fifo->last_urblen = len; | |
757 | } | |
758 | ||
759 | fill_isoc_urb(urb, fifo->hfc->dev, fifo->pipe, | |
760 | context_iso_urb->buffer, num_isoc_packets, | |
761 | fifo->usb_packet_maxlen, fifo->intervall, | |
762 | rx_iso_complete, urb->context); | |
763 | errcode = usb_submit_urb(urb, GFP_ATOMIC); | |
764 | if (errcode < 0) { | |
d6c59c13 MB |
765 | printk(KERN_ERR |
766 | "HFC-S USB: error submitting ISO URB: %d\n", | |
1da177e4 LT |
767 | errcode); |
768 | } | |
769 | } else { | |
770 | if (status && !hfc->disc_flag) { | |
d6c59c13 | 771 | printk(KERN_ERR |
1da177e4 LT |
772 | "HFC-S USB: rx_iso_complete : " |
773 | "urb->status %d, fifonum %d\n", | |
774 | status, fifon); | |
775 | } | |
776 | } | |
d6c59c13 | 777 | } |
1da177e4 | 778 | |
d6c59c13 | 779 | /* collect rx data from INT- and ISO-URBs */ |
1da177e4 | 780 | static void |
475be4d8 | 781 | collect_rx_frame(usb_fifo *fifo, __u8 *data, int len, int finish) |
1da177e4 LT |
782 | { |
783 | hfcusb_data *hfc = fifo->hfc; | |
784 | int transp_mode, fifon; | |
d6c59c13 | 785 | |
1da177e4 LT |
786 | fifon = fifo->fifonum; |
787 | transp_mode = 0; | |
788 | if (fifon < 4 && hfc->b_mode[fifon / 2] == L1_MODE_TRANS) | |
d6c59c13 | 789 | transp_mode = 1; |
1da177e4 LT |
790 | |
791 | if (!fifo->skbuff) { | |
792 | fifo->skbuff = dev_alloc_skb(fifo->max_size + 3); | |
793 | if (!fifo->skbuff) { | |
d6c59c13 MB |
794 | printk(KERN_ERR |
795 | "HFC-S USB: cannot allocate buffer for fifo(%d)\n", | |
1da177e4 LT |
796 | fifon); |
797 | return; | |
798 | } | |
799 | } | |
800 | if (len) { | |
801 | if (fifo->skbuff->len + len < fifo->max_size) { | |
59ae1d12 | 802 | skb_put_data(fifo->skbuff, data, len); |
1da177e4 | 803 | } else { |
d6c59c13 | 804 | DBG(HFCUSB_DBG_FIFO_ERR, |
475be4d8 JP |
805 | "HCF-USB: got frame exceeded fifo->max_size(%d) fifo(%d)", |
806 | fifo->max_size, fifon); | |
d6c59c13 MB |
807 | DBG_SKB(HFCUSB_DBG_VERBOSE_USB, fifo->skbuff); |
808 | skb_trim(fifo->skbuff, 0); | |
1da177e4 LT |
809 | } |
810 | } | |
811 | if (transp_mode && fifo->skbuff->len >= 128) { | |
812 | fifo->hif->l1l2(fifo->hif, PH_DATA | INDICATION, | |
813 | fifo->skbuff); | |
814 | fifo->skbuff = NULL; | |
815 | return; | |
816 | } | |
817 | /* we have a complete hdlc packet */ | |
818 | if (finish) { | |
286e633e | 819 | if (fifo->skbuff->len > 3 && |
475be4d8 | 820 | !fifo->skbuff->data[fifo->skbuff->len - 1]) { |
d6c59c13 MB |
821 | |
822 | if (fifon == HFCUSB_D_RX) { | |
823 | DBG(HFCUSB_DBG_DCHANNEL, | |
824 | "HFC-S USB: D-RX len(%d)", fifo->skbuff->len); | |
825 | DBG_SKB(HFCUSB_DBG_DCHANNEL, fifo->skbuff); | |
826 | } | |
827 | ||
1da177e4 LT |
828 | /* remove CRC & status */ |
829 | skb_trim(fifo->skbuff, fifo->skbuff->len - 3); | |
830 | if (fifon == HFCUSB_PCM_RX) { | |
831 | fifo->hif->l1l2(fifo->hif, | |
832 | PH_DATA_E | INDICATION, | |
833 | fifo->skbuff); | |
834 | } else | |
835 | fifo->hif->l1l2(fifo->hif, | |
836 | PH_DATA | INDICATION, | |
837 | fifo->skbuff); | |
838 | fifo->skbuff = NULL; /* buffer was freed from upper layer */ | |
839 | } else { | |
d6c59c13 MB |
840 | DBG(HFCUSB_DBG_FIFO_ERR, |
841 | "HFC-S USB: ERROR frame len(%d) fifo(%d)", | |
842 | fifo->skbuff->len, fifon); | |
843 | DBG_SKB(HFCUSB_DBG_VERBOSE_USB, fifo->skbuff); | |
1da177e4 LT |
844 | skb_trim(fifo->skbuff, 0); |
845 | } | |
846 | } | |
1da177e4 LT |
847 | } |
848 | ||
1da177e4 | 849 | static void |
d6c59c13 | 850 | rx_int_complete(struct urb *urb) |
1da177e4 LT |
851 | { |
852 | int len; | |
853 | int status; | |
854 | __u8 *buf, maxlen, fifon; | |
855 | usb_fifo *fifo = (usb_fifo *) urb->context; | |
856 | hfcusb_data *hfc = fifo->hfc; | |
857 | static __u8 eof[8]; | |
1da177e4 LT |
858 | |
859 | urb->dev = hfc->dev; /* security init */ | |
860 | ||
861 | fifon = fifo->fifonum; | |
862 | if ((!fifo->active) || (urb->status)) { | |
d6c59c13 | 863 | DBG(HFCUSB_DBG_INIT, "HFC-S USB: RX-Fifo %i is going down (%i)", |
1da177e4 | 864 | fifon, urb->status); |
d6c59c13 | 865 | |
1da177e4 LT |
866 | fifo->urb->interval = 0; /* cancel automatic rescheduling */ |
867 | if (fifo->skbuff) { | |
868 | dev_kfree_skb_any(fifo->skbuff); | |
869 | fifo->skbuff = NULL; | |
870 | } | |
871 | return; | |
872 | } | |
873 | len = urb->actual_length; | |
874 | buf = fifo->buffer; | |
875 | maxlen = fifo->usb_packet_maxlen; | |
876 | ||
d6c59c13 MB |
877 | if (fifon == HFCUSB_D_RX) { |
878 | DBG(HFCUSB_DBG_VERBOSE_USB, | |
475be4d8 JP |
879 | "HFC-S USB: INT-D-RX lst_urblen:%2d " |
880 | "act_urblen:%2d max-urblen:%2d EOF:0x%0x", | |
881 | fifo->last_urblen, len, maxlen, | |
882 | eof[5]); | |
d6c59c13 | 883 | DBG_PACKET(HFCUSB_DBG_VERBOSE_USB, buf, len); |
1da177e4 | 884 | } |
1da177e4 LT |
885 | |
886 | if (fifo->last_urblen != fifo->usb_packet_maxlen) { | |
887 | /* the threshold mask is in the 2nd status byte */ | |
888 | hfc->threshold_mask = buf[1]; | |
889 | /* the S0 state is in the upper half of the 1st status byte */ | |
d6c59c13 | 890 | s0_state_handler(hfc, buf[0] >> 4); |
1da177e4 LT |
891 | eof[fifon] = buf[0] & 1; |
892 | /* if we have more than the 2 status bytes -> collect data */ | |
893 | if (len > 2) | |
894 | collect_rx_frame(fifo, buf + 2, | |
895 | urb->actual_length - 2, | |
896 | (len < maxlen) ? eof[fifon] : 0); | |
897 | } else { | |
898 | collect_rx_frame(fifo, buf, urb->actual_length, | |
899 | (len < maxlen) ? eof[fifon] : 0); | |
900 | } | |
901 | fifo->last_urblen = urb->actual_length; | |
902 | status = usb_submit_urb(urb, GFP_ATOMIC); | |
903 | if (status) { | |
904 | printk(KERN_INFO | |
d6c59c13 | 905 | "HFC-S USB: %s error resubmitting URB fifo(%d)\n", |
156f1ed6 | 906 | __func__, fifon); |
1da177e4 | 907 | } |
d6c59c13 | 908 | } |
1da177e4 | 909 | |
d6c59c13 | 910 | /* start initial INT-URB for certain fifo */ |
1da177e4 | 911 | static void |
475be4d8 | 912 | start_int_fifo(usb_fifo *fifo) |
1da177e4 LT |
913 | { |
914 | int errcode; | |
915 | ||
d6c59c13 MB |
916 | DBG(HFCUSB_DBG_INIT, "HFC-S USB: starting RX INT-URB for fifo:%d\n", |
917 | fifo->fifonum); | |
1da177e4 LT |
918 | |
919 | if (!fifo->urb) { | |
920 | fifo->urb = usb_alloc_urb(0, GFP_KERNEL); | |
921 | if (!fifo->urb) | |
922 | return; | |
923 | } | |
924 | usb_fill_int_urb(fifo->urb, fifo->hfc->dev, fifo->pipe, | |
925 | fifo->buffer, fifo->usb_packet_maxlen, | |
d6c59c13 | 926 | rx_int_complete, fifo, fifo->intervall); |
1da177e4 LT |
927 | fifo->active = 1; /* must be marked active */ |
928 | errcode = usb_submit_urb(fifo->urb, GFP_KERNEL); | |
929 | if (errcode) { | |
eeb4e6d1 JL |
930 | printk(KERN_ERR "HFC-S USB: submit URB error(%s): status:%i\n", |
931 | __func__, errcode); | |
1da177e4 LT |
932 | fifo->active = 0; |
933 | fifo->skbuff = NULL; | |
934 | } | |
d6c59c13 | 935 | } |
1da177e4 | 936 | |
1da177e4 | 937 | static void |
475be4d8 | 938 | setup_bchannel(hfcusb_data *hfc, int channel, int mode) |
1da177e4 LT |
939 | { |
940 | __u8 val, idx_table[2] = { 0, 2 }; | |
941 | ||
942 | if (hfc->disc_flag) { | |
943 | return; | |
944 | } | |
d6c59c13 MB |
945 | DBG(HFCUSB_DBG_STATES, "HFC-S USB: setting channel %d to mode %d", |
946 | channel, mode); | |
1da177e4 LT |
947 | hfc->b_mode[channel] = mode; |
948 | ||
949 | /* setup CON_HDLC */ | |
950 | val = 0; | |
951 | if (mode != L1_MODE_NULL) | |
952 | val = 8; /* enable fifo? */ | |
953 | if (mode == L1_MODE_TRANS) | |
954 | val |= 2; /* set transparent bit */ | |
955 | ||
956 | /* set FIFO to transmit register */ | |
957 | queue_control_request(hfc, HFCUSB_FIFO, idx_table[channel], 1); | |
958 | queue_control_request(hfc, HFCUSB_CON_HDLC, val, 1); | |
959 | /* reset fifo */ | |
960 | queue_control_request(hfc, HFCUSB_INC_RES_F, 2, 1); | |
961 | /* set FIFO to receive register */ | |
962 | queue_control_request(hfc, HFCUSB_FIFO, idx_table[channel] + 1, 1); | |
963 | queue_control_request(hfc, HFCUSB_CON_HDLC, val, 1); | |
964 | /* reset fifo */ | |
965 | queue_control_request(hfc, HFCUSB_INC_RES_F, 2, 1); | |
966 | ||
967 | val = 0x40; | |
968 | if (hfc->b_mode[0]) | |
969 | val |= 1; | |
970 | if (hfc->b_mode[1]) | |
971 | val |= 2; | |
972 | queue_control_request(hfc, HFCUSB_SCTRL, val, 1); | |
973 | ||
974 | val = 0; | |
975 | if (hfc->b_mode[0]) | |
976 | val |= 1; | |
977 | if (hfc->b_mode[1]) | |
978 | val |= 2; | |
979 | queue_control_request(hfc, HFCUSB_SCTRL_R, val, 1); | |
980 | ||
981 | if (mode == L1_MODE_NULL) { | |
982 | if (channel) | |
983 | handle_led(hfc, LED_B2_OFF); | |
984 | else | |
985 | handle_led(hfc, LED_B1_OFF); | |
986 | } else { | |
987 | if (channel) | |
988 | handle_led(hfc, LED_B2_ON); | |
989 | else | |
990 | handle_led(hfc, LED_B1_ON); | |
991 | } | |
992 | } | |
993 | ||
672c3fd9 | 994 | static void |
1da177e4 LT |
995 | hfc_usb_l2l1(struct hisax_if *my_hisax_if, int pr, void *arg) |
996 | { | |
997 | usb_fifo *fifo = my_hisax_if->priv; | |
998 | hfcusb_data *hfc = fifo->hfc; | |
999 | ||
1000 | switch (pr) { | |
475be4d8 JP |
1001 | case PH_ACTIVATE | REQUEST: |
1002 | if (fifo->fifonum == HFCUSB_D_TX) { | |
1003 | DBG(HFCUSB_DBG_STATES, | |
1004 | "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_ACTIVATE | REQUEST"); | |
1005 | ||
1006 | if (hfc->l1_state != 3 | |
1007 | && hfc->l1_state != 7) { | |
1008 | hfc->d_if.ifc.l1l2(&hfc->d_if.ifc, | |
1009 | PH_DEACTIVATE | | |
1010 | INDICATION, | |
1011 | NULL); | |
d6c59c13 | 1012 | DBG(HFCUSB_DBG_STATES, |
475be4d8 JP |
1013 | "HFC-S USB: PH_DEACTIVATE | INDICATION sent (not state 3 or 7)"); |
1014 | } else { | |
1015 | if (hfc->l1_state == 7) { /* l1 already active */ | |
1016 | hfc->d_if.ifc.l1l2(&hfc-> | |
1017 | d_if. | |
1018 | ifc, | |
1019 | PH_ACTIVATE | |
1020 | | | |
1da177e4 LT |
1021 | INDICATION, |
1022 | NULL); | |
d6c59c13 | 1023 | DBG(HFCUSB_DBG_STATES, |
475be4d8 | 1024 | "HFC-S USB: PH_ACTIVATE | INDICATION sent again ;)"); |
1da177e4 | 1025 | } else { |
475be4d8 JP |
1026 | /* force sending sending INFO1 */ |
1027 | queue_control_request(hfc, | |
1028 | HFCUSB_STATES, | |
1029 | 0x14, | |
1030 | 1); | |
1031 | mdelay(1); | |
1032 | /* start l1 activation */ | |
1033 | queue_control_request(hfc, | |
1034 | HFCUSB_STATES, | |
1035 | 0x04, | |
1036 | 1); | |
1037 | if (!timer_pending | |
1038 | (&hfc->t3_timer)) { | |
1039 | hfc->t3_timer. | |
1040 | expires = | |
1041 | jiffies + | |
1042 | (HFC_TIMER_T3 * | |
1043 | HZ) / 1000; | |
1044 | add_timer(&hfc-> | |
1045 | t3_timer); | |
1da177e4 LT |
1046 | } |
1047 | } | |
1da177e4 | 1048 | } |
475be4d8 JP |
1049 | } else { |
1050 | DBG(HFCUSB_DBG_STATES, | |
1051 | "HFC_USB: hfc_usb_d_l2l1 B-chan: PH_ACTIVATE | REQUEST"); | |
1052 | setup_bchannel(hfc, | |
1053 | (fifo->fifonum == | |
1054 | HFCUSB_B1_TX) ? 0 : 1, | |
1055 | (long) arg); | |
1056 | fifo->hif->l1l2(fifo->hif, | |
1057 | PH_ACTIVATE | INDICATION, | |
1058 | NULL); | |
1059 | } | |
1060 | break; | |
1061 | case PH_DEACTIVATE | REQUEST: | |
1062 | if (fifo->fifonum == HFCUSB_D_TX) { | |
1063 | DBG(HFCUSB_DBG_STATES, | |
1064 | "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_DEACTIVATE | REQUEST"); | |
1065 | } else { | |
d6c59c13 | 1066 | DBG(HFCUSB_DBG_STATES, |
475be4d8 JP |
1067 | "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_DEACTIVATE | REQUEST"); |
1068 | setup_bchannel(hfc, | |
1069 | (fifo->fifonum == | |
1070 | HFCUSB_B1_TX) ? 0 : 1, | |
1071 | (int) L1_MODE_NULL); | |
1072 | fifo->hif->l1l2(fifo->hif, | |
1073 | PH_DEACTIVATE | INDICATION, | |
1074 | NULL); | |
1075 | } | |
1076 | break; | |
1077 | case PH_DATA | REQUEST: | |
1078 | if (fifo->skbuff && fifo->delete_flg) { | |
1079 | dev_kfree_skb_any(fifo->skbuff); | |
1080 | fifo->skbuff = NULL; | |
1081 | fifo->delete_flg = 0; | |
1082 | } | |
1083 | fifo->skbuff = arg; /* we have a new buffer */ | |
1084 | break; | |
1085 | default: | |
1086 | DBG(HFCUSB_DBG_STATES, | |
1087 | "HFC_USB: hfc_usb_d_l2l1: unknown state : %#x", pr); | |
1088 | break; | |
1da177e4 LT |
1089 | } |
1090 | } | |
1091 | ||
d6c59c13 | 1092 | /* initial init HFC-S USB chip registers, HiSax interface, USB URBs */ |
1da177e4 | 1093 | static int |
475be4d8 | 1094 | hfc_usb_init(hfcusb_data *hfc) |
1da177e4 LT |
1095 | { |
1096 | usb_fifo *fifo; | |
a1e6216d | 1097 | int i; |
1da177e4 LT |
1098 | u_char b; |
1099 | struct hisax_b_if *p_b_if[2]; | |
1100 | ||
1101 | /* check the chip id */ | |
1102 | if (read_usb(hfc, HFCUSB_CHIP_ID, &b) != 1) { | |
1103 | printk(KERN_INFO "HFC-USB: cannot read chip id\n"); | |
1104 | return (1); | |
1105 | } | |
1106 | if (b != HFCUSB_CHIPID) { | |
1107 | printk(KERN_INFO "HFC-S USB: Invalid chip id 0x%02x\n", b); | |
1108 | return (1); | |
1109 | } | |
1110 | ||
1111 | /* first set the needed config, interface and alternate */ | |
a1e6216d | 1112 | usb_set_interface(hfc->dev, hfc->if_used, hfc->alt_used); |
1da177e4 LT |
1113 | |
1114 | /* do Chip reset */ | |
1115 | write_usb(hfc, HFCUSB_CIRM, 8); | |
1116 | /* aux = output, reset off */ | |
1117 | write_usb(hfc, HFCUSB_CIRM, 0x10); | |
1118 | ||
d6c59c13 | 1119 | /* set USB_SIZE to match wMaxPacketSize for INT or BULK transfers */ |
1da177e4 LT |
1120 | write_usb(hfc, HFCUSB_USB_SIZE, |
1121 | (hfc->packet_size / 8) | ((hfc->packet_size / 8) << 4)); | |
1122 | ||
d6c59c13 | 1123 | /* set USB_SIZE_I to match wMaxPacketSize for ISO transfers */ |
1da177e4 LT |
1124 | write_usb(hfc, HFCUSB_USB_SIZE_I, hfc->iso_packet_size); |
1125 | ||
1126 | /* enable PCM/GCI master mode */ | |
1127 | write_usb(hfc, HFCUSB_MST_MODE1, 0); /* set default values */ | |
1128 | write_usb(hfc, HFCUSB_MST_MODE0, 1); /* enable master mode */ | |
1129 | ||
1130 | /* init the fifos */ | |
1131 | write_usb(hfc, HFCUSB_F_THRES, | |
1132 | (HFCUSB_TX_THRESHOLD / | |
1133 | 8) | ((HFCUSB_RX_THRESHOLD / 8) << 4)); | |
1134 | ||
1135 | fifo = hfc->fifos; | |
1136 | for (i = 0; i < HFCUSB_NUM_FIFOS; i++) { | |
1137 | write_usb(hfc, HFCUSB_FIFO, i); /* select the desired fifo */ | |
1138 | fifo[i].skbuff = NULL; /* init buffer pointer */ | |
1139 | fifo[i].max_size = | |
475be4d8 | 1140 | (i <= HFCUSB_B2_RX) ? MAX_BCH_SIZE : MAX_DFRAME_LEN; |
1da177e4 LT |
1141 | fifo[i].last_urblen = 0; |
1142 | /* set 2 bit for D- & E-channel */ | |
1143 | write_usb(hfc, HFCUSB_HDLC_PAR, | |
1144 | ((i <= HFCUSB_B2_RX) ? 0 : 2)); | |
1145 | /* rx hdlc, enable IFF for D-channel */ | |
1146 | write_usb(hfc, HFCUSB_CON_HDLC, | |
1147 | ((i == HFCUSB_D_TX) ? 0x09 : 0x08)); | |
1148 | write_usb(hfc, HFCUSB_INC_RES_F, 2); /* reset the fifo */ | |
1149 | } | |
1150 | ||
1151 | write_usb(hfc, HFCUSB_CLKDEL, 0x0f); /* clock delay value */ | |
1152 | write_usb(hfc, HFCUSB_STATES, 3 | 0x10); /* set deactivated mode */ | |
1153 | write_usb(hfc, HFCUSB_STATES, 3); /* enable state machine */ | |
1154 | ||
1155 | write_usb(hfc, HFCUSB_SCTRL_R, 0); /* disable both B receivers */ | |
1156 | write_usb(hfc, HFCUSB_SCTRL, 0x40); /* disable B transmitters + capacitive mode */ | |
1157 | ||
1158 | /* set both B-channel to not connected */ | |
1159 | hfc->b_mode[0] = L1_MODE_NULL; | |
1160 | hfc->b_mode[1] = L1_MODE_NULL; | |
1161 | ||
d6c59c13 MB |
1162 | hfc->l1_activated = 0; |
1163 | hfc->disc_flag = 0; | |
1da177e4 | 1164 | hfc->led_state = 0; |
1da177e4 LT |
1165 | hfc->old_led_state = 0; |
1166 | ||
1167 | /* init the t3 timer */ | |
aff55a36 | 1168 | setup_timer(&hfc->t3_timer, (void *)l1_timer_expire_t3, (long)hfc); |
1da177e4 LT |
1169 | |
1170 | /* init the t4 timer */ | |
aff55a36 | 1171 | setup_timer(&hfc->t4_timer, (void *)l1_timer_expire_t4, (long)hfc); |
1da177e4 | 1172 | |
1da177e4 LT |
1173 | /* init the background machinery for control requests */ |
1174 | hfc->ctrl_read.bRequestType = 0xc0; | |
1175 | hfc->ctrl_read.bRequest = 1; | |
b05121b2 | 1176 | hfc->ctrl_read.wLength = cpu_to_le16(1); |
1da177e4 LT |
1177 | hfc->ctrl_write.bRequestType = 0x40; |
1178 | hfc->ctrl_write.bRequest = 0; | |
1179 | hfc->ctrl_write.wLength = 0; | |
1180 | usb_fill_control_urb(hfc->ctrl_urb, | |
1181 | hfc->dev, | |
1182 | hfc->ctrl_out_pipe, | |
475be4d8 | 1183 | (u_char *)&hfc->ctrl_write, |
1da177e4 LT |
1184 | NULL, 0, ctrl_complete, hfc); |
1185 | /* Init All Fifos */ | |
1186 | for (i = 0; i < HFCUSB_NUM_FIFOS; i++) { | |
1187 | hfc->fifos[i].iso[0].purb = NULL; | |
1188 | hfc->fifos[i].iso[1].purb = NULL; | |
1189 | hfc->fifos[i].active = 0; | |
1190 | } | |
1191 | /* register Modul to upper Hisax Layers */ | |
1192 | hfc->d_if.owner = THIS_MODULE; | |
1193 | hfc->d_if.ifc.priv = &hfc->fifos[HFCUSB_D_TX]; | |
1194 | hfc->d_if.ifc.l2l1 = hfc_usb_l2l1; | |
1195 | for (i = 0; i < 2; i++) { | |
1196 | hfc->b_if[i].ifc.priv = &hfc->fifos[HFCUSB_B1_TX + i * 2]; | |
1197 | hfc->b_if[i].ifc.l2l1 = hfc_usb_l2l1; | |
1198 | p_b_if[i] = &hfc->b_if[i]; | |
1199 | } | |
1200 | /* default Prot: EURO ISDN, should be a module_param */ | |
1201 | hfc->protocol = 2; | |
ae2d990e AS |
1202 | i = hisax_register(&hfc->d_if, p_b_if, "hfc_usb", hfc->protocol); |
1203 | if (i) { | |
1204 | printk(KERN_INFO "HFC-S USB: hisax_register -> %d\n", i); | |
1205 | return i; | |
1206 | } | |
1da177e4 LT |
1207 | |
1208 | #ifdef CONFIG_HISAX_DEBUG | |
1209 | hfc_debug = debug; | |
1210 | #endif | |
1211 | ||
1212 | for (i = 0; i < 4; i++) | |
1213 | hfc->fifos[i].hif = &p_b_if[i / 2]->ifc; | |
1214 | for (i = 4; i < 8; i++) | |
1215 | hfc->fifos[i].hif = &hfc->d_if.ifc; | |
1216 | ||
1217 | /* 3 (+1) INT IN + 3 ISO OUT */ | |
1218 | if (hfc->cfg_used == CNF_3INT3ISO || hfc->cfg_used == CNF_4INT3ISO) { | |
1219 | start_int_fifo(hfc->fifos + HFCUSB_D_RX); | |
1220 | if (hfc->fifos[HFCUSB_PCM_RX].pipe) | |
1221 | start_int_fifo(hfc->fifos + HFCUSB_PCM_RX); | |
1222 | start_int_fifo(hfc->fifos + HFCUSB_B1_RX); | |
1223 | start_int_fifo(hfc->fifos + HFCUSB_B2_RX); | |
1224 | } | |
1225 | /* 3 (+1) ISO IN + 3 ISO OUT */ | |
1226 | if (hfc->cfg_used == CNF_3ISO3ISO || hfc->cfg_used == CNF_4ISO3ISO) { | |
1227 | start_isoc_chain(hfc->fifos + HFCUSB_D_RX, ISOC_PACKETS_D, | |
1228 | rx_iso_complete, 16); | |
1229 | if (hfc->fifos[HFCUSB_PCM_RX].pipe) | |
1230 | start_isoc_chain(hfc->fifos + HFCUSB_PCM_RX, | |
1231 | ISOC_PACKETS_D, rx_iso_complete, | |
1232 | 16); | |
1233 | start_isoc_chain(hfc->fifos + HFCUSB_B1_RX, ISOC_PACKETS_B, | |
1234 | rx_iso_complete, 16); | |
1235 | start_isoc_chain(hfc->fifos + HFCUSB_B2_RX, ISOC_PACKETS_B, | |
1236 | rx_iso_complete, 16); | |
1237 | } | |
1238 | ||
1239 | start_isoc_chain(hfc->fifos + HFCUSB_D_TX, ISOC_PACKETS_D, | |
1240 | tx_iso_complete, 1); | |
1241 | start_isoc_chain(hfc->fifos + HFCUSB_B1_TX, ISOC_PACKETS_B, | |
1242 | tx_iso_complete, 1); | |
1243 | start_isoc_chain(hfc->fifos + HFCUSB_B2_TX, ISOC_PACKETS_B, | |
1244 | tx_iso_complete, 1); | |
1245 | ||
1246 | handle_led(hfc, LED_POWER_ON); | |
1247 | ||
1248 | return (0); | |
d6c59c13 | 1249 | } |
1da177e4 | 1250 | |
d6c59c13 | 1251 | /* initial callback for each plugged USB device */ |
1da177e4 LT |
1252 | static int |
1253 | hfc_usb_probe(struct usb_interface *intf, const struct usb_device_id *id) | |
1254 | { | |
1255 | struct usb_device *dev = interface_to_usbdev(intf); | |
1256 | hfcusb_data *context; | |
1257 | struct usb_host_interface *iface = intf->cur_altsetting; | |
1258 | struct usb_host_interface *iface_used = NULL; | |
1259 | struct usb_host_endpoint *ep; | |
1260 | int ifnum = iface->desc.bInterfaceNumber; | |
1261 | int i, idx, alt_idx, probe_alt_setting, vend_idx, cfg_used, *vcf, | |
475be4d8 | 1262 | attr, cfg_found, cidx, ep_addr; |
1da177e4 | 1263 | int cmptbl[16], small_match, iso_packet_size, packet_size, |
475be4d8 | 1264 | alt_used = 0; |
597a107b | 1265 | hfcsusb_vdata *driver_info; |
1da177e4 LT |
1266 | |
1267 | vend_idx = 0xffff; | |
597a107b | 1268 | for (i = 0; hfcusb_idtab[i].idVendor; i++) { |
b05121b2 KK |
1269 | if ((le16_to_cpu(dev->descriptor.idVendor) == hfcusb_idtab[i].idVendor) |
1270 | && (le16_to_cpu(dev->descriptor.idProduct) == hfcusb_idtab[i].idProduct)) { | |
1da177e4 | 1271 | vend_idx = i; |
597a107b MB |
1272 | continue; |
1273 | } | |
1da177e4 | 1274 | } |
597a107b | 1275 | |
1da177e4 LT |
1276 | printk(KERN_INFO |
1277 | "HFC-S USB: probing interface(%d) actalt(%d) minor(%d)\n", | |
1278 | ifnum, iface->desc.bAlternateSetting, intf->minor); | |
1279 | ||
1280 | if (vend_idx != 0xffff) { | |
1da177e4 LT |
1281 | /* if vendor and product ID is OK, start probing alternate settings */ |
1282 | alt_idx = 0; | |
1283 | small_match = 0xffff; | |
1284 | ||
1285 | /* default settings */ | |
1286 | iso_packet_size = 16; | |
1287 | packet_size = 64; | |
1288 | ||
1289 | while (alt_idx < intf->num_altsetting) { | |
1290 | iface = intf->altsetting + alt_idx; | |
1291 | probe_alt_setting = iface->desc.bAlternateSetting; | |
1292 | cfg_used = 0; | |
1293 | ||
1294 | /* check for config EOL element */ | |
1295 | while (validconf[cfg_used][0]) { | |
d6c59c13 | 1296 | cfg_found = 1; |
1da177e4 LT |
1297 | vcf = validconf[cfg_used]; |
1298 | /* first endpoint descriptor */ | |
1299 | ep = iface->endpoint; | |
d6c59c13 | 1300 | |
1da177e4 LT |
1301 | memcpy(cmptbl, vcf, 16 * sizeof(int)); |
1302 | ||
1303 | /* check for all endpoints in this alternate setting */ | |
1304 | for (i = 0; i < iface->desc.bNumEndpoints; | |
1305 | i++) { | |
1306 | ep_addr = | |
475be4d8 | 1307 | ep->desc.bEndpointAddress; |
1da177e4 LT |
1308 | /* get endpoint base */ |
1309 | idx = ((ep_addr & 0x7f) - 1) * 2; | |
1310 | if (ep_addr & 0x80) | |
1311 | idx++; | |
1312 | attr = ep->desc.bmAttributes; | |
1313 | if (cmptbl[idx] == EP_NUL) { | |
d6c59c13 | 1314 | cfg_found = 0; |
1da177e4 LT |
1315 | } |
1316 | if (attr == USB_ENDPOINT_XFER_INT | |
1317 | && cmptbl[idx] == EP_INT) | |
1318 | cmptbl[idx] = EP_NUL; | |
1319 | if (attr == USB_ENDPOINT_XFER_BULK | |
1320 | && cmptbl[idx] == EP_BLK) | |
1321 | cmptbl[idx] = EP_NUL; | |
1322 | if (attr == USB_ENDPOINT_XFER_ISOC | |
1323 | && cmptbl[idx] == EP_ISO) | |
1324 | cmptbl[idx] = EP_NUL; | |
1325 | ||
1326 | /* check if all INT endpoints match minimum interval */ | |
d6c59c13 MB |
1327 | if ((attr == USB_ENDPOINT_XFER_INT) |
1328 | && (ep->desc.bInterval < vcf[17])) { | |
1329 | cfg_found = 0; | |
1da177e4 LT |
1330 | } |
1331 | ep++; | |
1332 | } | |
1333 | for (i = 0; i < 16; i++) { | |
1334 | /* all entries must be EP_NOP or EP_NUL for a valid config */ | |
1335 | if (cmptbl[i] != EP_NOP | |
1336 | && cmptbl[i] != EP_NUL) | |
d6c59c13 | 1337 | cfg_found = 0; |
1da177e4 LT |
1338 | } |
1339 | if (cfg_found) { | |
1340 | if (cfg_used < small_match) { | |
1341 | small_match = cfg_used; | |
1342 | alt_used = | |
475be4d8 | 1343 | probe_alt_setting; |
1da177e4 LT |
1344 | iface_used = iface; |
1345 | } | |
1da177e4 LT |
1346 | } |
1347 | cfg_used++; | |
1348 | } | |
1349 | alt_idx++; | |
d6c59c13 | 1350 | } /* (alt_idx < intf->num_altsetting) */ |
1da177e4 LT |
1351 | |
1352 | /* found a valid USB Ta Endpint config */ | |
1353 | if (small_match != 0xffff) { | |
1354 | iface = iface_used; | |
d6c59c13 | 1355 | if (!(context = kzalloc(sizeof(hfcusb_data), GFP_KERNEL))) |
1da177e4 | 1356 | return (-ENOMEM); /* got no mem */ |
1da177e4 LT |
1357 | |
1358 | ep = iface->endpoint; | |
1359 | vcf = validconf[small_match]; | |
1360 | ||
1361 | for (i = 0; i < iface->desc.bNumEndpoints; i++) { | |
1362 | ep_addr = ep->desc.bEndpointAddress; | |
1363 | /* get endpoint base */ | |
1364 | idx = ((ep_addr & 0x7f) - 1) * 2; | |
1365 | if (ep_addr & 0x80) | |
1366 | idx++; | |
1367 | cidx = idx & 7; | |
1368 | attr = ep->desc.bmAttributes; | |
1369 | ||
1370 | /* init Endpoints */ | |
1371 | if (vcf[idx] != EP_NOP | |
1372 | && vcf[idx] != EP_NUL) { | |
1373 | switch (attr) { | |
475be4d8 JP |
1374 | case USB_ENDPOINT_XFER_INT: |
1375 | context-> | |
1376 | fifos[cidx]. | |
1377 | pipe = | |
1378 | usb_rcvintpipe | |
1379 | (dev, | |
1380 | ep->desc. | |
1381 | bEndpointAddress); | |
1382 | context-> | |
1383 | fifos[cidx]. | |
1384 | usb_transfer_mode | |
1385 | = USB_INT; | |
1386 | packet_size = | |
1387 | le16_to_cpu(ep->desc.wMaxPacketSize); | |
1388 | break; | |
1389 | case USB_ENDPOINT_XFER_BULK: | |
1390 | if (ep_addr & 0x80) | |
1da177e4 | 1391 | context-> |
475be4d8 JP |
1392 | fifos |
1393 | [cidx]. | |
1394 | pipe = | |
1395 | usb_rcvbulkpipe | |
1396 | (dev, | |
1397 | ep-> | |
1398 | desc. | |
1399 | bEndpointAddress); | |
1400 | else | |
1da177e4 | 1401 | context-> |
475be4d8 JP |
1402 | fifos |
1403 | [cidx]. | |
1404 | pipe = | |
1405 | usb_sndbulkpipe | |
1406 | (dev, | |
1407 | ep-> | |
1408 | desc. | |
1409 | bEndpointAddress); | |
1410 | context-> | |
1411 | fifos[cidx]. | |
1412 | usb_transfer_mode | |
1413 | = USB_BULK; | |
1414 | packet_size = | |
1415 | le16_to_cpu(ep->desc.wMaxPacketSize); | |
1416 | break; | |
1417 | case USB_ENDPOINT_XFER_ISOC: | |
1418 | if (ep_addr & 0x80) | |
1da177e4 | 1419 | context-> |
475be4d8 JP |
1420 | fifos |
1421 | [cidx]. | |
1422 | pipe = | |
1423 | usb_rcvisocpipe | |
1424 | (dev, | |
1425 | ep-> | |
1426 | desc. | |
1427 | bEndpointAddress); | |
1428 | else | |
1da177e4 | 1429 | context-> |
475be4d8 JP |
1430 | fifos |
1431 | [cidx]. | |
1432 | pipe = | |
1433 | usb_sndisocpipe | |
1434 | (dev, | |
1435 | ep-> | |
1436 | desc. | |
1437 | bEndpointAddress); | |
1438 | context-> | |
1439 | fifos[cidx]. | |
1440 | usb_transfer_mode | |
1441 | = USB_ISOC; | |
1442 | iso_packet_size = | |
1443 | le16_to_cpu(ep->desc.wMaxPacketSize); | |
1444 | break; | |
1445 | default: | |
1446 | context-> | |
1447 | fifos[cidx]. | |
1448 | pipe = 0; | |
1da177e4 LT |
1449 | } /* switch attribute */ |
1450 | ||
1451 | if (context->fifos[cidx].pipe) { | |
1452 | context->fifos[cidx]. | |
475be4d8 | 1453 | fifonum = cidx; |
1da177e4 | 1454 | context->fifos[cidx].hfc = |
475be4d8 | 1455 | context; |
b05121b2 | 1456 | context->fifos[cidx].usb_packet_maxlen = |
475be4d8 | 1457 | le16_to_cpu(ep->desc.wMaxPacketSize); |
1da177e4 | 1458 | context->fifos[cidx]. |
475be4d8 JP |
1459 | intervall = |
1460 | ep->desc.bInterval; | |
1da177e4 | 1461 | context->fifos[cidx]. |
475be4d8 | 1462 | skbuff = NULL; |
1da177e4 LT |
1463 | } |
1464 | } | |
1465 | ep++; | |
1466 | } | |
1467 | context->dev = dev; /* save device */ | |
1468 | context->if_used = ifnum; /* save used interface */ | |
1469 | context->alt_used = alt_used; /* and alternate config */ | |
1470 | context->ctrl_paksize = dev->descriptor.bMaxPacketSize0; /* control size */ | |
1471 | context->cfg_used = vcf[16]; /* store used config */ | |
1472 | context->vend_idx = vend_idx; /* store found vendor */ | |
1473 | context->packet_size = packet_size; | |
1474 | context->iso_packet_size = iso_packet_size; | |
1475 | ||
1476 | /* create the control pipes needed for register access */ | |
1477 | context->ctrl_in_pipe = | |
475be4d8 | 1478 | usb_rcvctrlpipe(context->dev, 0); |
1da177e4 | 1479 | context->ctrl_out_pipe = |
475be4d8 | 1480 | usb_sndctrlpipe(context->dev, 0); |
2ae4605d KK |
1481 | |
1482 | driver_info = (hfcsusb_vdata *) | |
1483 | hfcusb_idtab[vend_idx].driver_info; | |
1484 | ||
1da177e4 LT |
1485 | context->ctrl_urb = usb_alloc_urb(0, GFP_KERNEL); |
1486 | ||
2ae4605d KK |
1487 | if (!context->ctrl_urb) { |
1488 | pr_warn("%s: No memory for control urb\n", | |
1489 | driver_info->vend_name); | |
1490 | kfree(context); | |
1491 | return -ENOMEM; | |
1492 | } | |
1493 | ||
1494 | pr_info("HFC-S USB: detected \"%s\"\n", | |
1495 | driver_info->vend_name); | |
d6c59c13 MB |
1496 | |
1497 | DBG(HFCUSB_DBG_INIT, | |
1498 | "HFC-S USB: Endpoint-Config: %s (if=%d alt=%d), E-Channel(%d)", | |
1da177e4 | 1499 | conf_str[small_match], context->if_used, |
d6c59c13 MB |
1500 | context->alt_used, |
1501 | validconf[small_match][18]); | |
1502 | ||
1da177e4 | 1503 | /* init the chip and register the driver */ |
d6c59c13 | 1504 | if (hfc_usb_init(context)) { |
ae2d990e AS |
1505 | usb_kill_urb(context->ctrl_urb); |
1506 | usb_free_urb(context->ctrl_urb); | |
1507 | context->ctrl_urb = NULL; | |
1da177e4 LT |
1508 | kfree(context); |
1509 | return (-EIO); | |
1510 | } | |
1511 | usb_set_intfdata(intf, context); | |
1512 | return (0); | |
1513 | } | |
1514 | } else { | |
1515 | printk(KERN_INFO | |
1516 | "HFC-S USB: no valid vendor found in USB descriptor\n"); | |
1517 | } | |
1518 | return (-EIO); | |
1519 | } | |
1520 | ||
d6c59c13 | 1521 | /* callback for unplugged USB device */ |
1da177e4 | 1522 | static void |
7441dd12 | 1523 | hfc_usb_disconnect(struct usb_interface *intf) |
1da177e4 LT |
1524 | { |
1525 | hfcusb_data *context = usb_get_intfdata(intf); | |
1526 | int i; | |
d6c59c13 MB |
1527 | |
1528 | handle_led(context, LED_POWER_OFF); | |
7441dd12 | 1529 | schedule_timeout(HZ / 100); |
d6c59c13 | 1530 | |
1da177e4 | 1531 | printk(KERN_INFO "HFC-S USB: device disconnect\n"); |
d6c59c13 | 1532 | context->disc_flag = 1; |
1da177e4 | 1533 | usb_set_intfdata(intf, NULL); |
7441dd12 | 1534 | |
1da177e4 LT |
1535 | if (timer_pending(&context->t3_timer)) |
1536 | del_timer(&context->t3_timer); | |
1537 | if (timer_pending(&context->t4_timer)) | |
1538 | del_timer(&context->t4_timer); | |
d6c59c13 | 1539 | |
1da177e4 LT |
1540 | /* tell all fifos to terminate */ |
1541 | for (i = 0; i < HFCUSB_NUM_FIFOS; i++) { | |
1542 | if (context->fifos[i].usb_transfer_mode == USB_ISOC) { | |
1543 | if (context->fifos[i].active > 0) { | |
1544 | stop_isoc_chain(&context->fifos[i]); | |
d6c59c13 MB |
1545 | DBG(HFCUSB_DBG_INIT, |
1546 | "HFC-S USB: %s stopping ISOC chain Fifo(%i)", | |
156f1ed6 | 1547 | __func__, i); |
1da177e4 LT |
1548 | } |
1549 | } else { | |
1550 | if (context->fifos[i].active > 0) { | |
1551 | context->fifos[i].active = 0; | |
d6c59c13 MB |
1552 | DBG(HFCUSB_DBG_INIT, |
1553 | "HFC-S USB: %s unlinking URB for Fifo(%i)", | |
156f1ed6 | 1554 | __func__, i); |
1da177e4 | 1555 | } |
ae2d990e AS |
1556 | usb_kill_urb(context->fifos[i].urb); |
1557 | usb_free_urb(context->fifos[i].urb); | |
1558 | context->fifos[i].urb = NULL; | |
1da177e4 LT |
1559 | } |
1560 | context->fifos[i].active = 0; | |
1561 | } | |
ae2d990e AS |
1562 | usb_kill_urb(context->ctrl_urb); |
1563 | usb_free_urb(context->ctrl_urb); | |
1564 | context->ctrl_urb = NULL; | |
1da177e4 LT |
1565 | hisax_unregister(&context->d_if); |
1566 | kfree(context); /* free our structure again */ | |
d6c59c13 | 1567 | } |
1da177e4 | 1568 | |
1da177e4 | 1569 | static struct usb_driver hfc_drv = { |
597a107b MB |
1570 | .name = "hfc_usb", |
1571 | .id_table = hfcusb_idtab, | |
1572 | .probe = hfc_usb_probe, | |
1573 | .disconnect = hfc_usb_disconnect, | |
e1f12eb6 | 1574 | .disable_hub_initiated_lpm = 1, |
1da177e4 | 1575 | }; |
d6c59c13 | 1576 | |
1da177e4 | 1577 | static void __exit |
d6c59c13 | 1578 | hfc_usb_mod_exit(void) |
1da177e4 | 1579 | { |
d6c59c13 | 1580 | usb_deregister(&hfc_drv); /* release our driver */ |
1da177e4 LT |
1581 | printk(KERN_INFO "HFC-S USB: module removed\n"); |
1582 | } | |
1583 | ||
1584 | static int __init | |
d6c59c13 | 1585 | hfc_usb_mod_init(void) |
1da177e4 | 1586 | { |
d6c59c13 | 1587 | char revstr[30], datestr[30], dummy[30]; |
1da177e4 | 1588 | #ifndef CONFIG_HISAX_DEBUG |
d6c59c13 | 1589 | hfc_debug = debug; |
1da177e4 | 1590 | #endif |
1da177e4 LT |
1591 | sscanf(hfcusb_revision, |
1592 | "%s %s $ %s %s %s $ ", dummy, revstr, | |
1593 | dummy, datestr, dummy); | |
1594 | printk(KERN_INFO | |
1595 | "HFC-S USB: driver module revision %s date %s loaded, (debug=%i)\n", | |
1596 | revstr, datestr, debug); | |
1597 | if (usb_register(&hfc_drv)) { | |
1598 | printk(KERN_INFO | |
1599 | "HFC-S USB: Unable to register HFC-S USB module at usb stack\n"); | |
1600 | return (-1); /* unable to register */ | |
1601 | } | |
1602 | return (0); | |
1603 | } | |
1604 | ||
d6c59c13 MB |
1605 | module_init(hfc_usb_mod_init); |
1606 | module_exit(hfc_usb_mod_exit); | |
1da177e4 LT |
1607 | MODULE_AUTHOR(DRIVER_AUTHOR); |
1608 | MODULE_DESCRIPTION(DRIVER_DESC); | |
1609 | MODULE_LICENSE("GPL"); | |
597a107b | 1610 | MODULE_DEVICE_TABLE(usb, hfcusb_idtab); |