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