| 1 | --- a/drivers/Makefile |
| 2 | +++ b/drivers/Makefile |
| 3 | @@ -38,7 +38,7 @@ subdir-$(CONFIG_FUSION) += message/fusi |
| 4 | subdir-$(CONFIG_MD) += md |
| 5 | subdir-$(CONFIG_IEEE1394) += ieee1394 |
| 6 | subdir-$(CONFIG_PNP) += pnp |
| 7 | -subdir-$(CONFIG_ISDN_BOOL) += isdn |
| 8 | +subdir-$(CONFIG_ISDN) += isdn |
| 9 | subdir-$(CONFIG_ATM) += atm |
| 10 | subdir-$(CONFIG_FC4) += fc4 |
| 11 | |
| 12 | --- a/drivers/isdn/hisax/hfc_usb.c |
| 13 | +++ b/drivers/isdn/hisax/hfc_usb.c |
| 14 | @@ -1,13 +1,11 @@ |
| 15 | -/* $Id: hfc_usb.c,v 2.3 2001/07/06 21:30:11 werner Exp $ |
| 16 | +/* |
| 17 | + * hfc_usb.c |
| 18 | * |
| 19 | + * modular HiSax ISDN driver for Colognechip HFC-USB chip |
| 20 | * |
| 21 | - * |
| 22 | - * Author (C) 2001 Werner Cornelius (werner@isdn-development.de) |
| 23 | - * modular driver for Colognechip HFC-USB chip |
| 24 | - * as plugin for HiSax isdn driver |
| 25 | - * type approval valid for HFC-S USB based TAs |
| 26 | - * |
| 27 | - * Copyright 2001 by Werner Cornelius (werner@isdn-development.de) |
| 28 | + * Authors : Peter Sprenger (sprenger@moving-byters.de) |
| 29 | + * Martin Bachem (info@colognechip.com) |
| 30 | + * based on the first hfc_usb driver of Werner Cornelius (werner@isdn-development.de) |
| 31 | * |
| 32 | * This program is free software; you can redistribute it and/or modify |
| 33 | * it under the terms of the GNU General Public License as published by |
| 34 | @@ -23,70 +21,90 @@ |
| 35 | * along with this program; if not, write to the Free Software |
| 36 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 37 | * |
| 38 | - */ |
| 39 | + * 2005_Mar_16 grsch |
| 40 | + * ported 2.6.8 hfc_usb.c to 2.4.20 format |
| 41 | + * Gregor Schaffrath <gschaff@ran-dom.org> |
| 42 | +*/ |
| 43 | + |
| 44 | |
| 45 | #include <linux/types.h> |
| 46 | #include <linux/stddef.h> |
| 47 | #include <linux/timer.h> |
| 48 | #include <linux/config.h> |
| 49 | -#include <linux/isdn_compat.h> |
| 50 | #include <linux/init.h> |
| 51 | #include "hisax.h" |
| 52 | #include <linux/module.h> |
| 53 | #include <linux/kernel_stat.h> |
| 54 | -#include <linux/tqueue.h> |
| 55 | #include <linux/usb.h> |
| 56 | #include <linux/kernel.h> |
| 57 | #include <linux/smp_lock.h> |
| 58 | #include <linux/sched.h> |
| 59 | +#include "hisax_if.h" |
| 60 | #include "hisax_loadable.h" |
| 61 | |
| 62 | +static const char *hfcusb_revision = "4.0"; |
| 63 | + |
| 64 | +/* |
| 65 | + to enable much mire debug messages in this driver, define |
| 66 | + VERBOSE_USB_DEBUG and VERBOSE_ISDN_DEBUG |
| 67 | + below |
| 68 | +*/ |
| 69 | + |
| 70 | +#define VERBOSE_USB_DEBUG |
| 71 | +#define VERBOSE_ISDN_DEBUG |
| 72 | + |
| 73 | #define INCLUDE_INLINE_FUNCS |
| 74 | |
| 75 | +#define TRUE 1 |
| 76 | +#define FALSE 0 |
| 77 | + |
| 78 | + |
| 79 | /***********/ |
| 80 | /* defines */ |
| 81 | /***********/ |
| 82 | -#define HFC_CTRL_TIMEOUT 5 /* 5ms timeout writing/reading regs */ |
| 83 | -#define HFC_TIMER_T3 7000 /* timeout for l1 activation timer */ |
| 84 | - |
| 85 | -#define HFCUSB_L1_STATECHANGE 0 /* L1 state changed */ |
| 86 | -#define HFCUSB_L1_DRX 1 /* D-frame received */ |
| 87 | -#define HFCUSB_L1_ERX 2 /* E-frame received */ |
| 88 | -#define HFCUSB_L1_DTX 4 /* D-frames completed */ |
| 89 | - |
| 90 | -#define MAX_BCH_SIZE 2048 /* allowed B-channel packet size */ |
| 91 | - |
| 92 | -#define HFCUSB_RX_THRESHOLD 64 /* threshold for fifo report bit rx */ |
| 93 | -#define HFCUSB_TX_THRESHOLD 64 /* threshold for fifo report bit tx */ |
| 94 | - |
| 95 | -#define HFCUSB_CHIP_ID 0x16 /* Chip ID register index */ |
| 96 | -#define HFCUSB_CIRM 0x00 /* cirm register index */ |
| 97 | -#define HFCUSB_USB_SIZE 0x07 /* int length register */ |
| 98 | -#define HFCUSB_USB_SIZE_I 0x06 /* iso length register */ |
| 99 | -#define HFCUSB_F_CROSS 0x0b /* bit order register */ |
| 100 | -#define HFCUSB_CLKDEL 0x37 /* bit delay register */ |
| 101 | -#define HFCUSB_CON_HDLC 0xfa /* channel connect register */ |
| 102 | +#define HFC_CTRL_TIMEOUT 20 //(HZ * USB_CTRL_GET_TIMEOUT) |
| 103 | +/* 5ms timeout writing/reading regs */ |
| 104 | +#define HFC_TIMER_T3 8000 /* timeout for l1 activation timer */ |
| 105 | +#define HFC_TIMER_T4 500 /* time for state change interval */ |
| 106 | + |
| 107 | +#define HFCUSB_L1_STATECHANGE 0 /* L1 state changed */ |
| 108 | +#define HFCUSB_L1_DRX 1 /* D-frame received */ |
| 109 | +#define HFCUSB_L1_ERX 2 /* E-frame received */ |
| 110 | +#define HFCUSB_L1_DTX 4 /* D-frames completed */ |
| 111 | + |
| 112 | +#define MAX_BCH_SIZE 2048 /* allowed B-channel packet size */ |
| 113 | + |
| 114 | +#define HFCUSB_RX_THRESHOLD 64 /* threshold for fifo report bit rx */ |
| 115 | +#define HFCUSB_TX_THRESHOLD 64 /* threshold for fifo report bit tx */ |
| 116 | + |
| 117 | +#define HFCUSB_CHIP_ID 0x16 /* Chip ID register index */ |
| 118 | +#define HFCUSB_CIRM 0x00 /* cirm register index */ |
| 119 | +#define HFCUSB_USB_SIZE 0x07 /* int length register */ |
| 120 | +#define HFCUSB_USB_SIZE_I 0x06 /* iso length register */ |
| 121 | +#define HFCUSB_F_CROSS 0x0b /* bit order register */ |
| 122 | +#define HFCUSB_CLKDEL 0x37 /* bit delay register */ |
| 123 | +#define HFCUSB_CON_HDLC 0xfa /* channel connect register */ |
| 124 | #define HFCUSB_HDLC_PAR 0xfb |
| 125 | -#define HFCUSB_SCTRL 0x31 /* S-bus control register (tx) */ |
| 126 | -#define HFCUSB_SCTRL_E 0x32 /* same for E and special funcs */ |
| 127 | -#define HFCUSB_SCTRL_R 0x33 /* S-bus control register (rx) */ |
| 128 | -#define HFCUSB_F_THRES 0x0c /* threshold register */ |
| 129 | -#define HFCUSB_FIFO 0x0f /* fifo select register */ |
| 130 | -#define HFCUSB_F_USAGE 0x1a /* fifo usage register */ |
| 131 | +#define HFCUSB_SCTRL 0x31 /* S-bus control register (tx) */ |
| 132 | +#define HFCUSB_SCTRL_E 0x32 /* same for E and special funcs */ |
| 133 | +#define HFCUSB_SCTRL_R 0x33 /* S-bus control register (rx) */ |
| 134 | +#define HFCUSB_F_THRES 0x0c /* threshold register */ |
| 135 | +#define HFCUSB_FIFO 0x0f /* fifo select register */ |
| 136 | +#define HFCUSB_F_USAGE 0x1a /* fifo usage register */ |
| 137 | #define HFCUSB_MST_MODE0 0x14 |
| 138 | #define HFCUSB_MST_MODE1 0x15 |
| 139 | #define HFCUSB_P_DATA 0x1f |
| 140 | #define HFCUSB_INC_RES_F 0x0e |
| 141 | #define HFCUSB_STATES 0x30 |
| 142 | |
| 143 | -#define HFCUSB_CHIPID 0x40 /* ID value of HFC-USB */ |
| 144 | +#define HFCUSB_CHIPID 0x40 /* ID value of HFC-USB */ |
| 145 | |
| 146 | /******************/ |
| 147 | /* fifo registers */ |
| 148 | /******************/ |
| 149 | -#define HFCUSB_NUM_FIFOS 8 /* maximum number of fifos */ |
| 150 | -#define HFCUSB_B1_TX 0 /* index for B1 transmit bulk/int */ |
| 151 | -#define HFCUSB_B1_RX 1 /* index for B1 receive bulk/int */ |
| 152 | +#define HFCUSB_NUM_FIFOS 8 /* maximum number of fifos */ |
| 153 | +#define HFCUSB_B1_TX 0 /* index for B1 transmit bulk/int */ |
| 154 | +#define HFCUSB_B1_RX 1 /* index for B1 receive bulk/int */ |
| 155 | #define HFCUSB_B2_TX 2 |
| 156 | #define HFCUSB_B2_RX 3 |
| 157 | #define HFCUSB_D_TX 4 |
| 158 | @@ -94,198 +112,162 @@ |
| 159 | #define HFCUSB_PCM_TX 6 |
| 160 | #define HFCUSB_PCM_RX 7 |
| 161 | |
| 162 | -/************/ |
| 163 | -/* LED mask */ |
| 164 | -/************/ |
| 165 | -#define LED_DRIVER 0x1 |
| 166 | -#define LED_L1 0x2 |
| 167 | -#define LED_BCH 0x4 |
| 168 | +/* |
| 169 | +* used to switch snd_transfer_mode for different TA modes e.g. the Billion USB TA just |
| 170 | +* supports ISO out, while the Cologne Chip EVAL TA just supports BULK out |
| 171 | +*/ |
| 172 | +#define USB_INT 0 |
| 173 | +#define USB_BULK 1 |
| 174 | +#define USB_ISOC 2 |
| 175 | + |
| 176 | +#define ISOC_PACKETS_D 8 |
| 177 | +#define ISOC_PACKETS_B 8 |
| 178 | +#define ISO_BUFFER_SIZE 128 |
| 179 | + |
| 180 | +// ISO send definitions |
| 181 | +#define SINK_MAX 68 |
| 182 | +#define SINK_MIN 48 |
| 183 | +#define SINK_DMIN 12 |
| 184 | +#define SINK_DMAX 18 |
| 185 | +#define BITLINE_INF (-64*8) |
| 186 | + |
| 187 | + |
| 188 | + |
| 189 | |
| 190 | /**********/ |
| 191 | /* macros */ |
| 192 | /**********/ |
| 193 | -#define Write_hfc(a,b,c) usb_control_msg((a)->dev,(a)->ctrl_out_pipe,0,0x40,(c),(b),0,0,HFC_CTRL_TIMEOUT) |
| 194 | -#define Read_hfc(a,b,c) usb_control_msg((a)->dev,(a)->ctrl_in_pipe,1,0xC0,0,(b),(c),1,HFC_CTRL_TIMEOUT) |
| 195 | - |
| 196 | -#ifdef COMPAT_HAS_USB_IDTAB |
| 197 | -/****************************************/ |
| 198 | -/* data defining the devices to be used */ |
| 199 | -/****************************************/ |
| 200 | -static __devinitdata const struct usb_device_id hfc_usb_idtab[3] = { |
| 201 | - {USB_DEVICE(0x959, 0x2bd0)}, /* Colognechip ROM */ |
| 202 | - {USB_DEVICE(0x7b0, 0x0006)}, /* USB TA 128 */ |
| 203 | - {} /* end with an all-zeroes entry */ |
| 204 | -}; |
| 205 | -#endif |
| 206 | +#define write_usb(a,b,c) usb_control_msg((a)->dev,(a)->ctrl_out_pipe,0,0x40,(c),(b),NULL,0,HFC_CTRL_TIMEOUT) |
| 207 | +#define read_usb(a,b,c) usb_control_msg((a)->dev,(a)->ctrl_in_pipe,1,0xC0,0,(b),(c),1,HFC_CTRL_TIMEOUT) |
| 208 | |
| 209 | /*************************************************/ |
| 210 | /* entry and size of output/input control buffer */ |
| 211 | /*************************************************/ |
| 212 | #define HFC_CTRL_BUFSIZE 32 |
| 213 | -typedef struct { |
| 214 | +typedef struct |
| 215 | +{ |
| 216 | __u8 hfc_reg; /* register number */ |
| 217 | __u8 reg_val; /* value to be written (or read) */ |
| 218 | + int action; /* data for action handler */ |
| 219 | + |
| 220 | } ctrl_buft; |
| 221 | |
| 222 | +typedef struct |
| 223 | +{ |
| 224 | + int vendor; // vendor id |
| 225 | + int prod_id; // product id |
| 226 | + char *vend_name; // vendor string |
| 227 | + __u8 led_scheme; // led display scheme |
| 228 | + __u8 led_invert; // invert led aux port settings |
| 229 | + __u8 led_bits[8]; // array of 8 possible LED bitmask settings |
| 230 | + |
| 231 | +} vendor_data; |
| 232 | + |
| 233 | /***************************************************************/ |
| 234 | /* structure defining input+output fifos (interrupt/bulk mode) */ |
| 235 | /***************************************************************/ |
| 236 | -struct hfcusb_data; /* forward definition */ |
| 237 | -typedef struct { |
| 238 | - int fifonum; /* fifo index attached to this structure */ |
| 239 | - __u8 fifo_mask; /* mask for this fifo */ |
| 240 | - int active; /* fifo is currently active */ |
| 241 | + |
| 242 | +struct usb_fifo; /* forward definition */ |
| 243 | +typedef struct iso_urb_struct |
| 244 | +{ |
| 245 | + struct urb *purb; |
| 246 | + __u8 buffer[ISO_BUFFER_SIZE]; /* buffer incoming/outgoing data */ |
| 247 | + struct usb_fifo *owner_fifo; // pointer to owner fifo |
| 248 | +} iso_urb_struct; |
| 249 | + |
| 250 | + |
| 251 | +struct hfcusb_data; /* forward definition */ |
| 252 | +typedef struct usb_fifo |
| 253 | +{ |
| 254 | + int fifonum; /* fifo index attached to this structure */ |
| 255 | + int active; /* fifo is currently active */ |
| 256 | struct hfcusb_data *hfc; /* pointer to main structure */ |
| 257 | - int pipe; /* address of endpoint */ |
| 258 | - __u8 usb_maxlen; /* maximum length for usb transfer */ |
| 259 | - int max_size; /* maximum size of receive/send packet */ |
| 260 | - int transmode; /* transparent mode selected */ |
| 261 | - int framenum; /* number of frame when last tx completed */ |
| 262 | - int rx_offset; /* offset inside rx buffer */ |
| 263 | - int next_complete; /* complete marker */ |
| 264 | - __u8 *act_ptr; /* pointer to next data */ |
| 265 | - __u8 intervall; /* interrupt interval */ |
| 266 | - struct sk_buff *buff; /* actual used buffer */ |
| 267 | - urb_t urb; /* transfer structure for usb routines */ |
| 268 | - __u8 buffer[128]; /* buffer incoming/outgoing data */ |
| 269 | + int pipe; /* address of endpoint */ |
| 270 | + __u8 usb_packet_maxlen; /* maximum length for usb transfer */ |
| 271 | + unsigned int max_size; /* maximum size of receive/send packet */ |
| 272 | + __u8 intervall; /* interrupt interval */ |
| 273 | + struct sk_buff *skbuff; /* actual used buffer */ |
| 274 | + struct urb *urb; /* transfer structure for usb routines */ |
| 275 | + __u8 buffer[128]; /* buffer incoming/outgoing data */ |
| 276 | + int bit_line; /* how much bits are in the fifo? */ |
| 277 | + |
| 278 | + volatile __u8 usb_transfer_mode;/* switched between ISO and INT */ |
| 279 | + iso_urb_struct iso[2]; /* need two urbs to have one always for pending */ |
| 280 | + struct hisax_if *hif; /* hisax interface */ |
| 281 | + int delete_flg; /* only delete skbuff once */ |
| 282 | + int last_urblen; /* remember length of last packet */ |
| 283 | + |
| 284 | } usb_fifo; |
| 285 | |
| 286 | + |
| 287 | /*********************************************/ |
| 288 | /* structure holding all data for one device */ |
| 289 | /*********************************************/ |
| 290 | -typedef struct hfcusb_data { |
| 291 | - struct hisax_drvreg regd; /* register data and callbacks */ |
| 292 | - struct usb_device *dev; /* our device */ |
| 293 | - int if_used; /* used interface number */ |
| 294 | - int alt_used; /* used alternate config */ |
| 295 | - int ctrl_paksize; /* control pipe packet size */ |
| 296 | +typedef struct hfcusb_data |
| 297 | +{ |
| 298 | + // HiSax Interface for loadable Layer1 drivers |
| 299 | + struct hisax_d_if d_if; /* see hisax_if.h */ |
| 300 | + struct hisax_b_if b_if[2]; /* see hisax_if.h */ |
| 301 | + int protocol; |
| 302 | + |
| 303 | + struct usb_device *dev; /* our device */ |
| 304 | + int if_used; /* used interface number */ |
| 305 | + int alt_used; /* used alternate config */ |
| 306 | + int ctrl_paksize; /* control pipe packet size */ |
| 307 | int ctrl_in_pipe, ctrl_out_pipe; /* handles for control pipe */ |
| 308 | + int cfg_used; /* configuration index used */ |
| 309 | + int vend_idx; // vendor found |
| 310 | + |
| 311 | + int b_mode[2]; // B-channel mode |
| 312 | + |
| 313 | + int l1_activated; // layer 1 activated |
| 314 | + |
| 315 | + int packet_size,iso_packet_size; |
| 316 | |
| 317 | /* control pipe background handling */ |
| 318 | ctrl_buft ctrl_buff[HFC_CTRL_BUFSIZE]; /* buffer holding queued data */ |
| 319 | - volatile int ctrl_in_idx, ctrl_out_idx, ctrl_cnt; /* input/output pointer + count */ |
| 320 | - urb_t ctrl_urb; /* transfer structure for control channel */ |
| 321 | - devrequest ctrl_write; /* buffer for control write request */ |
| 322 | - devrequest ctrl_read; /* same for read request */ |
| 323 | - |
| 324 | - volatile __u8 dfifo_fill; /* value read from tx d-fifo */ |
| 325 | - volatile __u8 active_fifos; /* fifos currently active as bit mask */ |
| 326 | - volatile __u8 threshold_mask; /* threshold actually reported */ |
| 327 | - volatile __u8 service_request; /* fifo needs service from task */ |
| 328 | - volatile __u8 ctrl_fifo; /* last selected fifo */ |
| 329 | - volatile __u8 bch_enables; /* or mask for sctrl_r and sctrl register values */ |
| 330 | - volatile __u8 led_req; /* request status of adapters leds */ |
| 331 | - volatile __u8 led_act; /* active status of adapters leds */ |
| 332 | + volatile int ctrl_in_idx, ctrl_out_idx, |
| 333 | + ctrl_cnt; /* input/output pointer + count */ |
| 334 | + struct urb *ctrl_urb; /* transfer structure for control channel */ |
| 335 | + |
| 336 | + struct usb_ctrlrequest ctrl_write; /* buffer for control write request */ |
| 337 | + struct usb_ctrlrequest ctrl_read; /* same for read request */ |
| 338 | + |
| 339 | + __u8 led_state,led_new_data,led_b_active; |
| 340 | + |
| 341 | + volatile __u8 threshold_mask; /* threshold actually reported */ |
| 342 | + volatile __u8 bch_enables; /* or mask for sctrl_r and sctrl register values */ |
| 343 | + |
| 344 | usb_fifo fifos[HFCUSB_NUM_FIFOS]; /* structure holding all fifo data */ |
| 345 | |
| 346 | - /* layer 1 activation/deactivation handling */ |
| 347 | - volatile __u8 l1_state; /* actual l1 state */ |
| 348 | - volatile ulong l1_event; /* event mask */ |
| 349 | - struct tq_struct l1_tq; /* l1 bh structure */ |
| 350 | - struct timer_list t3_timer; /* timer for activation/deactivation */ |
| 351 | - struct timer_list t4_timer; /* timer for activation/deactivation */ |
| 352 | + volatile __u8 l1_state; /* actual l1 state */ |
| 353 | + struct timer_list t3_timer; /* timer 3 for activation/deactivation */ |
| 354 | + struct timer_list t4_timer; /* timer 4 for activation/deactivation */ |
| 355 | + struct timer_list led_timer; /* timer flashing leds */ |
| 356 | + |
| 357 | } hfcusb_data; |
| 358 | |
| 359 | -#if 0 |
| 360 | -static void |
| 361 | -usb_dump_urb(purb_t purb) |
| 362 | -{ |
| 363 | - printk("urb :%p\n", purb); |
| 364 | - printk("next :%p\n", purb->next); |
| 365 | - printk("dev :%p\n", purb->dev); |
| 366 | - printk("pipe :%08X\n", purb->pipe); |
| 367 | - printk("status :%d\n", purb->status); |
| 368 | - printk("transfer_flags :%08X\n", purb->transfer_flags); |
| 369 | - printk("transfer_buffer :%p\n", purb->transfer_buffer); |
| 370 | - printk("transfer_buffer_length:%d\n", |
| 371 | - purb->transfer_buffer_length); |
| 372 | - printk("actual_length :%d\n", purb->actual_length); |
| 373 | - printk("setup_packet :%p\n", purb->setup_packet); |
| 374 | - printk("start_frame :%d\n", purb->start_frame); |
| 375 | - printk("number_of_packets :%d\n", purb->number_of_packets); |
| 376 | - printk("interval :%d\n", purb->interval); |
| 377 | - printk("error_count :%d\n", purb->error_count); |
| 378 | - printk("context :%p\n", purb->context); |
| 379 | - printk("complete :%p\n", purb->complete); |
| 380 | -} |
| 381 | -#endif |
| 382 | |
| 383 | -/*************************************************************************/ |
| 384 | -/* bottom half handler for L1 activation/deactiavtaion + D-chan + E-chan */ |
| 385 | -/*************************************************************************/ |
| 386 | -static void |
| 387 | -usb_l1d_bh(hfcusb_data * hfc) |
| 388 | -{ |
| 389 | +static void collect_rx_frame(usb_fifo *fifo,__u8 *data,int len,int finish); |
| 390 | + |
| 391 | |
| 392 | - while (hfc->l1_event) { |
| 393 | - if (test_and_clear_bit |
| 394 | - (HFCUSB_L1_STATECHANGE, &hfc->l1_event)) { |
| 395 | - if (hfc->l1_state == 7) |
| 396 | - hfc->led_req |= LED_L1; |
| 397 | - else |
| 398 | - hfc->led_req &= ~LED_L1; |
| 399 | - if ((hfc->l1_state == 7) || |
| 400 | - (hfc->l1_state == 3)) |
| 401 | - hfc->regd.dch_l1l2(hfc->regd.arg_hisax, |
| 402 | - (hfc->l1_state == |
| 403 | - 7) ? (PH_ACTIVATE | |
| 404 | - INDICATION) |
| 405 | - : (PH_DEACTIVATE | INDICATION), |
| 406 | - NULL); |
| 407 | - } |
| 408 | - if (test_and_clear_bit(HFCUSB_L1_DRX, &hfc->l1_event)) { |
| 409 | - hfc->regd.dch_l1l2(hfc->regd.arg_hisax, |
| 410 | - PH_DATA | INDICATION, |
| 411 | - (void *) 0); |
| 412 | - } |
| 413 | - if (test_and_clear_bit(HFCUSB_L1_ERX, &hfc->l1_event)) { |
| 414 | - hfc->regd.dch_l1l2(hfc->regd.arg_hisax, |
| 415 | - PH_DATA | INDICATION, |
| 416 | - (void *) 1); |
| 417 | - } |
| 418 | - if (test_and_clear_bit(HFCUSB_L1_DTX, &hfc->l1_event)) { |
| 419 | - hfc->regd.dch_l1l2(hfc->regd.arg_hisax, |
| 420 | - PH_DATA | CONFIRM, NULL); |
| 421 | - } |
| 422 | - } /* while */ |
| 423 | -} /* usb_l1d_bh */ |
| 424 | |
| 425 | /******************************************************/ |
| 426 | /* start next background transfer for control channel */ |
| 427 | /******************************************************/ |
| 428 | -static void |
| 429 | -ctrl_start_transfer(hfcusb_data * hfc) |
| 430 | +static void ctrl_start_transfer(hfcusb_data * hfc) |
| 431 | { |
| 432 | - |
| 433 | - if (hfc->ctrl_cnt) { |
| 434 | - switch (hfc->ctrl_buff[hfc->ctrl_out_idx].hfc_reg) { |
| 435 | - case HFCUSB_F_USAGE: |
| 436 | - hfc->ctrl_urb.pipe = hfc->ctrl_in_pipe; |
| 437 | - hfc->ctrl_urb.setup_packet = |
| 438 | - (u_char *) & hfc->ctrl_read; |
| 439 | - hfc->ctrl_urb.transfer_buffer_length = 1; |
| 440 | - hfc->ctrl_read.index = |
| 441 | - hfc->ctrl_buff[hfc->ctrl_out_idx]. |
| 442 | - hfc_reg; |
| 443 | - hfc->ctrl_urb.transfer_buffer = |
| 444 | - (char *) &hfc->dfifo_fill; |
| 445 | - break; |
| 446 | - |
| 447 | - default: /* write register */ |
| 448 | - hfc->ctrl_urb.pipe = hfc->ctrl_out_pipe; |
| 449 | - hfc->ctrl_urb.setup_packet = |
| 450 | - (u_char *) & hfc->ctrl_write; |
| 451 | - hfc->ctrl_urb.transfer_buffer = NULL; |
| 452 | - hfc->ctrl_urb.transfer_buffer_length = 0; |
| 453 | - hfc->ctrl_write.index = |
| 454 | - hfc->ctrl_buff[hfc->ctrl_out_idx]. |
| 455 | - hfc_reg; |
| 456 | - hfc->ctrl_write.value = |
| 457 | - hfc->ctrl_buff[hfc->ctrl_out_idx]. |
| 458 | - reg_val; |
| 459 | - break; |
| 460 | - } |
| 461 | - usb_submit_urb(&hfc->ctrl_urb); /* start transfer */ |
| 462 | + int err; |
| 463 | + if(hfc->ctrl_cnt) |
| 464 | + { |
| 465 | + hfc->ctrl_urb->pipe = hfc->ctrl_out_pipe; |
| 466 | + hfc->ctrl_urb->setup_packet = (u_char *) & hfc->ctrl_write; |
| 467 | + hfc->ctrl_urb->transfer_buffer = NULL; |
| 468 | + hfc->ctrl_urb->transfer_buffer_length = 0; |
| 469 | + hfc->ctrl_write.wIndex = hfc->ctrl_buff[hfc->ctrl_out_idx].hfc_reg; |
| 470 | + hfc->ctrl_write.wValue = hfc->ctrl_buff[hfc->ctrl_out_idx].reg_val; |
| 471 | + err = usb_submit_urb(hfc->ctrl_urb); /* start transfer */ |
| 472 | + printk(KERN_DEBUG "ctrl_start_transfer: submit %d\n", err); |
| 473 | } |
| 474 | } /* ctrl_start_transfer */ |
| 475 | |
| 476 | @@ -293,897 +275,1418 @@ ctrl_start_transfer(hfcusb_data * hfc) |
| 477 | /* queue a control transfer request */ |
| 478 | /* return 0 on success. */ |
| 479 | /************************************/ |
| 480 | -static int |
| 481 | -queue_control_request(hfcusb_data * hfc, __u8 reg, __u8 val) |
| 482 | +static int queue_control_request(hfcusb_data * hfc, __u8 reg, __u8 val,int action) |
| 483 | { |
| 484 | ctrl_buft *buf; |
| 485 | |
| 486 | - if (hfc->ctrl_cnt >= HFC_CTRL_BUFSIZE) |
| 487 | - return (1); /* no space left */ |
| 488 | - buf = hfc->ctrl_buff + hfc->ctrl_in_idx; /* pointer to new index */ |
| 489 | +#ifdef VERBOSE_USB_DEBUG |
| 490 | + printk ("HFC_USB: queue_control_request reg: %x, val: %x\n", reg, val); |
| 491 | +#endif |
| 492 | + |
| 493 | + if(hfc->ctrl_cnt >= HFC_CTRL_BUFSIZE) return(1); /* no space left */ |
| 494 | + buf = &hfc->ctrl_buff[hfc->ctrl_in_idx]; /* pointer to new index */ |
| 495 | buf->hfc_reg = reg; |
| 496 | buf->reg_val = val; |
| 497 | + buf->action=action; |
| 498 | if (++hfc->ctrl_in_idx >= HFC_CTRL_BUFSIZE) |
| 499 | hfc->ctrl_in_idx = 0; /* pointer wrap */ |
| 500 | if (++hfc->ctrl_cnt == 1) |
| 501 | ctrl_start_transfer(hfc); |
| 502 | - return (0); |
| 503 | -} /* queue_control_request */ |
| 504 | + return(0); |
| 505 | +} /* queue_control_request */ |
| 506 | |
| 507 | -/**************************************/ |
| 508 | -/* called when timer t3 or t4 expires */ |
| 509 | -/**************************************/ |
| 510 | -static void |
| 511 | -l1_timer_expire(hfcusb_data * hfc) |
| 512 | -{ |
| 513 | - if (timer_pending(&hfc->t4_timer)) |
| 514 | - del_timer(&hfc->t4_timer); |
| 515 | - queue_control_request(hfc, HFCUSB_STATES, 0x40); |
| 516 | - test_and_set_bit(HFCUSB_L1_STATECHANGE, |
| 517 | - &hfc->l1_event); |
| 518 | - queue_task(&hfc->l1_tq, &tq_immediate); |
| 519 | - mark_bh(IMMEDIATE_BH); |
| 520 | -} /* l1_timer_expire */ |
| 521 | - |
| 522 | -/**************************************************/ |
| 523 | -/* (re)fills a tx-fifo urb. Queuing is done later */ |
| 524 | -/**************************************************/ |
| 525 | -static void |
| 526 | -fill_tx_urb(usb_fifo * fifo) |
| 527 | -{ |
| 528 | - struct sk_buff *skb; |
| 529 | - long flags; |
| 530 | - int i, ii = 0; |
| 531 | - |
| 532 | - fifo->urb.dev = fifo->hfc->dev; |
| 533 | - if ((fifo->buff) |
| 534 | - && (fifo->urb.transfer_buffer_length < fifo->usb_maxlen)) { |
| 535 | - switch (fifo->fifonum) { |
| 536 | - case HFCUSB_B1_TX: |
| 537 | - case HFCUSB_B2_TX: |
| 538 | - skb = fifo->buff; |
| 539 | - fifo->buff = NULL; |
| 540 | - fifo->hfc->regd.bch_l1l2(fifo->hfc->regd. |
| 541 | - arg_hisax, |
| 542 | - (fifo->fifonum == |
| 543 | - HFCUSB_B1_TX) ? 0 |
| 544 | - : 1, |
| 545 | - (PH_DATA | |
| 546 | - CONFIRM), |
| 547 | - (void *) skb); |
| 548 | - fifo->hfc->service_request |= |
| 549 | - fifo->fifo_mask; |
| 550 | - return; |
| 551 | - case HFCUSB_D_TX: |
| 552 | - dev_kfree_skb_any(fifo->buff); |
| 553 | - fifo->buff = NULL; |
| 554 | - save_flags(flags); |
| 555 | - cli(); |
| 556 | - fifo->hfc->dfifo_fill = 0xff; /* currently invalid data */ |
| 557 | - queue_control_request(fifo->hfc, |
| 558 | - HFCUSB_FIFO, |
| 559 | - HFCUSB_D_TX); |
| 560 | - queue_control_request(fifo->hfc, |
| 561 | - HFCUSB_F_USAGE, 0); |
| 562 | - restore_flags(flags); |
| 563 | - return; |
| 564 | - default: |
| 565 | - return; /* error, invalid fifo */ |
| 566 | - } |
| 567 | + |
| 568 | +static int control_action_handler(hfcusb_data *hfc,int reg,int val,int action) |
| 569 | +{ |
| 570 | + if(!action) return(1); // no action defined |
| 571 | + |
| 572 | + return(0); |
| 573 | +} |
| 574 | + |
| 575 | + |
| 576 | +/***************************************************************/ |
| 577 | +/* control completion routine handling background control cmds */ |
| 578 | +/***************************************************************/ |
| 579 | +static void ctrl_complete(struct urb *urb) |
| 580 | +{ |
| 581 | + hfcusb_data *hfc = (hfcusb_data *) urb->context; |
| 582 | + ctrl_buft *buf; |
| 583 | + |
| 584 | + printk(KERN_DEBUG "ctrl_complete cnt %d\n", hfc->ctrl_cnt); |
| 585 | + urb->dev = hfc->dev; |
| 586 | + if(hfc->ctrl_cnt) |
| 587 | + { |
| 588 | + buf=&hfc->ctrl_buff[hfc->ctrl_out_idx]; |
| 589 | + control_action_handler(hfc,buf->hfc_reg,buf->reg_val,buf->action); |
| 590 | + |
| 591 | + hfc->ctrl_cnt--; /* decrement actual count */ |
| 592 | + if(++hfc->ctrl_out_idx >= HFC_CTRL_BUFSIZE) hfc->ctrl_out_idx = 0; /* pointer wrap */ |
| 593 | + |
| 594 | + ctrl_start_transfer(hfc); /* start next transfer */ |
| 595 | + } |
| 596 | +} /* ctrl_complete */ |
| 597 | + |
| 598 | + |
| 599 | + |
| 600 | +#define LED_OFF 0 // no LED support |
| 601 | +#define LED_SCHEME1 1 // LED standard scheme |
| 602 | +#define LED_SCHEME2 2 // not used yet... |
| 603 | + |
| 604 | +#define LED_POWER_ON 1 |
| 605 | +#define LED_POWER_OFF 2 |
| 606 | +#define LED_S0_ON 3 |
| 607 | +#define LED_S0_OFF 4 |
| 608 | +#define LED_B1_ON 5 |
| 609 | +#define LED_B1_OFF 6 |
| 610 | +#define LED_B1_DATA 7 |
| 611 | +#define LED_B2_ON 8 |
| 612 | +#define LED_B2_OFF 9 |
| 613 | +#define LED_B2_DATA 10 |
| 614 | + |
| 615 | +#define LED_NORMAL 0 // LEDs are normal |
| 616 | +#define LED_INVERTED 1 // LEDs are inverted |
| 617 | + |
| 618 | +// time for LED flashing |
| 619 | +#define LED_TIME 250 |
| 620 | + |
| 621 | +vendor_data vdata[]= |
| 622 | +{ |
| 623 | + {0x959, 0x2bd0, "ISDN USB TA (Cologne Chip HFC-S USB based)", LED_OFF,LED_NORMAL,{4,0,2,1}}, /* CologneChip Eval TA */ |
| 624 | + {0x7b0, 0x0007, "Billion tiny USB ISDN TA 128", LED_SCHEME1, LED_INVERTED, {8,0x40,0x20,0x10}}, /* Billion TA */ |
| 625 | + {0x742, 0x2008, "Stollmann USB TA", LED_SCHEME1, LED_NORMAL, {4,0,2,1}}, /* Stollmann TA */ |
| 626 | + {0x8e3, 0x0301, "Olitec USB RNIS", LED_SCHEME1, LED_NORMAL, {2,0,1,4}}, /* Olitec TA */ |
| 627 | + {0x675, 0x1688, "DrayTec USB ISDN TA", LED_SCHEME1, LED_NORMAL, {4,0,2,1}}, /* Draytec TA */ |
| 628 | + {0x7fa, 0x0846, "Bewan Modem RNIS USB", LED_SCHEME1, LED_INVERTED, {8,0x40,0x20,0x10}}, /* Bewan TA */ |
| 629 | + {0} // EOL element |
| 630 | +}; |
| 631 | + |
| 632 | +/***************************************************/ |
| 633 | +/* write led data to auxport & invert if necessary */ |
| 634 | +/***************************************************/ |
| 635 | +static void write_led(hfcusb_data * hfc,__u8 led_state) |
| 636 | +{ |
| 637 | + if(led_state!=hfc->led_state) |
| 638 | + { |
| 639 | + hfc->led_state=led_state; |
| 640 | + queue_control_request(hfc, HFCUSB_P_DATA,(vdata[hfc->vend_idx].led_invert) ? ~led_state : led_state,1); |
| 641 | + } |
| 642 | +} |
| 643 | + |
| 644 | +/******************************************/ |
| 645 | +/* invert B-channel LEDs if data is sent */ |
| 646 | +/******************************************/ |
| 647 | +static void led_timer(hfcusb_data * hfc) |
| 648 | +{ |
| 649 | + static int cnt=0; |
| 650 | + __u8 led_state=hfc->led_state; |
| 651 | + |
| 652 | + if(cnt) |
| 653 | + { |
| 654 | + if(hfc->led_b_active&1) led_state|=vdata[hfc->vend_idx].led_bits[2]; |
| 655 | + if(hfc->led_b_active&2) led_state|=vdata[hfc->vend_idx].led_bits[3]; |
| 656 | + } |
| 657 | + else |
| 658 | + { |
| 659 | + if(!(hfc->led_b_active&1) || hfc->led_new_data&1) led_state&=~vdata[hfc->vend_idx].led_bits[2]; |
| 660 | + if(!(hfc->led_b_active&2) || hfc->led_new_data&2) led_state&=~vdata[hfc->vend_idx].led_bits[3]; |
| 661 | } |
| 662 | |
| 663 | - /* check if new buffer needed */ |
| 664 | - if (!fifo->buff) { |
| 665 | - switch (fifo->fifonum) { |
| 666 | - case HFCUSB_B1_TX: |
| 667 | - if (fifo->hfc->regd.bsk[0]) |
| 668 | - fifo->buff = *fifo->hfc->regd.bsk[0]; /* B1-channel tx buffer */ |
| 669 | + write_led(hfc,led_state); |
| 670 | + hfc->led_new_data=0; |
| 671 | + |
| 672 | + cnt=!cnt; |
| 673 | + // restart 4 hz timer |
| 674 | + hfc->led_timer.expires = jiffies + (LED_TIME * HZ) / 1000; |
| 675 | + if(!timer_pending(&hfc->led_timer)) add_timer(&hfc->led_timer); |
| 676 | +} |
| 677 | + |
| 678 | +/**************************/ |
| 679 | +/* handle LED requests */ |
| 680 | +/**************************/ |
| 681 | +static void handle_led(hfcusb_data * hfc,int event) |
| 682 | +{ |
| 683 | + __u8 led_state=hfc->led_state; |
| 684 | + |
| 685 | + // if no scheme -> no LED action |
| 686 | + if(vdata[hfc->vend_idx].led_scheme==LED_OFF) return; |
| 687 | + |
| 688 | + switch(event) |
| 689 | + { |
| 690 | + case LED_POWER_ON: |
| 691 | + led_state|=vdata[hfc->vend_idx].led_bits[0]; |
| 692 | + break; |
| 693 | + case LED_POWER_OFF: // no Power off handling |
| 694 | + break; |
| 695 | + case LED_S0_ON: |
| 696 | + led_state|=vdata[hfc->vend_idx].led_bits[1]; |
| 697 | + break; |
| 698 | + case LED_S0_OFF: |
| 699 | + led_state&=~vdata[hfc->vend_idx].led_bits[1]; |
| 700 | break; |
| 701 | - case HFCUSB_B2_TX: |
| 702 | - if (fifo->hfc->regd.bsk[1]) |
| 703 | - fifo->buff = *fifo->hfc->regd.bsk[1]; /* B2-channel tx buffer */ |
| 704 | + case LED_B1_ON: |
| 705 | + hfc->led_b_active|=1; |
| 706 | break; |
| 707 | - case HFCUSB_D_TX: |
| 708 | - if (fifo->hfc->regd.dsq) |
| 709 | - fifo->buff = skb_dequeue(fifo->hfc->regd.dsq); /* D-channel tx queue */ |
| 710 | + case LED_B1_OFF: |
| 711 | + hfc->led_b_active&=~1; |
| 712 | break; |
| 713 | - default: |
| 714 | - return; /* error, invalid fifo */ |
| 715 | + case LED_B1_DATA: |
| 716 | + hfc->led_new_data|=1; |
| 717 | + break; |
| 718 | + case LED_B2_ON: |
| 719 | + hfc->led_b_active|=2; |
| 720 | + break; |
| 721 | + case LED_B2_OFF: |
| 722 | + hfc->led_b_active&=~2; |
| 723 | + break; |
| 724 | + case LED_B2_DATA: |
| 725 | + hfc->led_new_data|=2; |
| 726 | + break; |
| 727 | + } |
| 728 | + |
| 729 | + write_led(hfc,led_state); |
| 730 | +} |
| 731 | + |
| 732 | +/********************************/ |
| 733 | +/* called when timer t3 expires */ |
| 734 | +/********************************/ |
| 735 | +static void l1_timer_expire_t3(hfcusb_data * hfc) |
| 736 | +{ |
| 737 | + //printk (KERN_INFO "HFC-USB: l1_timer_expire_t3\n"); |
| 738 | + |
| 739 | + hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,PH_DEACTIVATE | INDICATION,NULL); |
| 740 | +#ifdef VERBOSE_USB_DEBUG |
| 741 | + printk(KERN_INFO "PH_DEACTIVATE | INDICATION sent\n"); |
| 742 | +#endif |
| 743 | + hfc->l1_activated=FALSE; |
| 744 | + handle_led(hfc,LED_S0_OFF); |
| 745 | +} |
| 746 | + |
| 747 | +/********************************/ |
| 748 | +/* called when timer t4 expires */ |
| 749 | +/********************************/ |
| 750 | +static void l1_timer_expire_t4(hfcusb_data * hfc) |
| 751 | +{ |
| 752 | + //printk (KERN_INFO "HFC-USB: l1_timer_expire_t4\n"); |
| 753 | + |
| 754 | + hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,PH_DEACTIVATE | INDICATION,NULL); |
| 755 | +#ifdef VERBOSE_USB_DEBUG |
| 756 | + printk(KERN_INFO "PH_DEACTIVATE | INDICATION sent\n"); |
| 757 | +#endif |
| 758 | + hfc->l1_activated=FALSE; |
| 759 | + handle_led(hfc,LED_S0_OFF); |
| 760 | +} |
| 761 | + |
| 762 | +/*****************************/ |
| 763 | +/* handle S0 state changes */ |
| 764 | +/*****************************/ |
| 765 | +static void state_handler(hfcusb_data * hfc,__u8 state) |
| 766 | +{ |
| 767 | + __u8 old_state; |
| 768 | + |
| 769 | + old_state=hfc->l1_state; |
| 770 | + |
| 771 | + // range check |
| 772 | + if(state==old_state || state<1 || state>8) return; |
| 773 | + |
| 774 | +#ifdef VERBOSE_ISDN_DEBUG |
| 775 | + printk(KERN_INFO "HFC-USB: new S0 state:%d old_state:%d\n",state,old_state); |
| 776 | +#endif |
| 777 | + |
| 778 | + if(state<4 || state==7 || state==8) |
| 779 | + { |
| 780 | + if(timer_pending(&hfc->t3_timer)) del_timer(&hfc->t3_timer); |
| 781 | + //printk(KERN_INFO "HFC-USB: T3 deactivated\n"); |
| 782 | + } |
| 783 | + |
| 784 | + if(state>=7) |
| 785 | + { |
| 786 | + if(timer_pending(&hfc->t4_timer)) del_timer(&hfc->t4_timer); |
| 787 | + //printk(KERN_INFO "HFC-USB: T4 deactivated\n"); |
| 788 | + } |
| 789 | + |
| 790 | + if(state==7 && !hfc->l1_activated) |
| 791 | + { |
| 792 | + hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,PH_ACTIVATE | INDICATION,NULL); |
| 793 | + //printk(KERN_INFO "HFC-USB: PH_ACTIVATE | INDICATION sent\n"); |
| 794 | + hfc->l1_activated=TRUE; |
| 795 | + handle_led(hfc,LED_S0_ON); |
| 796 | + } |
| 797 | + else |
| 798 | + if(state<=3 /* && activated*/) |
| 799 | + { |
| 800 | + if(old_state==7 || old_state==8) |
| 801 | + { |
| 802 | + //printk(KERN_INFO "HFC-USB: T4 activated\n"); |
| 803 | + hfc->t4_timer.expires = jiffies + (HFC_TIMER_T4 * HZ) / 1000; |
| 804 | + if(!timer_pending(&hfc->t4_timer)) add_timer(&hfc->t4_timer); |
| 805 | } |
| 806 | - if (!fifo->buff) { |
| 807 | - fifo->active = 0; /* we are inactive now */ |
| 808 | - fifo->hfc->active_fifos &= ~fifo->fifo_mask; |
| 809 | - if (fifo->fifonum == HFCUSB_D_TX) { |
| 810 | - test_and_set_bit(HFCUSB_L1_DTX, |
| 811 | - &fifo->hfc->l1_event); |
| 812 | - queue_task(&fifo->hfc->l1_tq, |
| 813 | - &tq_immediate); |
| 814 | - mark_bh(IMMEDIATE_BH); |
| 815 | - } |
| 816 | - return; |
| 817 | + else |
| 818 | + { |
| 819 | + hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,PH_DEACTIVATE | INDICATION,NULL); |
| 820 | + //printk(KERN_INFO "HFC-USB: PH_DEACTIVATE | INDICATION sent\n"); |
| 821 | + hfc->l1_activated=FALSE; |
| 822 | + handle_led(hfc,LED_S0_OFF); |
| 823 | } |
| 824 | - fifo->act_ptr = fifo->buff->data; /* start of data */ |
| 825 | - fifo->active = 1; |
| 826 | - ii = 1; |
| 827 | - fifo->hfc->active_fifos |= fifo->fifo_mask; |
| 828 | - fifo->hfc->service_request &= ~fifo->fifo_mask; |
| 829 | - } |
| 830 | - /* fillup the send buffer */ |
| 831 | - i = fifo->buff->len - (fifo->act_ptr - fifo->buff->data); /* remaining length */ |
| 832 | - fifo->buffer[0] = !fifo->transmode; /* not eof */ |
| 833 | - if (i > (fifo->usb_maxlen - ii)) { |
| 834 | - i = fifo->usb_maxlen - ii; |
| 835 | - } |
| 836 | - if (i) |
| 837 | - memcpy(fifo->buffer + ii, fifo->act_ptr, i); |
| 838 | - fifo->urb.transfer_buffer_length = i + ii; |
| 839 | - fifo->rx_offset = ii; |
| 840 | -} /* fill_tx_urb */ |
| 841 | - |
| 842 | -/************************************************/ |
| 843 | -/* transmit completion routine for all tx fifos */ |
| 844 | -/************************************************/ |
| 845 | -static void |
| 846 | -tx_complete(purb_t urb) |
| 847 | + } |
| 848 | + |
| 849 | + hfc->l1_state=state; |
| 850 | +} |
| 851 | + |
| 852 | + |
| 853 | +/* prepare iso urb */ |
| 854 | +static void fill_isoc_urb(struct urb *urb, struct usb_device *dev, unsigned int pipe, void *buf, |
| 855 | + int num_packets, int packet_size, int interval, usb_complete_t complete, void *context) |
| 856 | { |
| 857 | - usb_fifo *fifo = (usb_fifo *) urb->context; /* pointer to our fifo */ |
| 858 | + int k; |
| 859 | |
| 860 | - fifo->hfc->service_request &= ~fifo->fifo_mask; /* no further handling */ |
| 861 | - fifo->framenum = usb_get_current_frame_number(fifo->hfc->dev); |
| 862 | + spin_lock_init(&urb->lock); // do we really need spin_lock_init ? |
| 863 | + urb->dev = dev; |
| 864 | + urb->pipe = pipe; |
| 865 | + urb->complete = complete; |
| 866 | + urb->number_of_packets = num_packets; |
| 867 | + urb->transfer_buffer_length = packet_size * num_packets; |
| 868 | + urb->context = context; |
| 869 | + urb->transfer_buffer = buf; |
| 870 | + urb->transfer_flags = 0; |
| 871 | + urb->transfer_flags = USB_ISO_ASAP; |
| 872 | + urb->actual_length = 0; |
| 873 | + urb->interval = interval; |
| 874 | + for (k = 0; k < num_packets; k++) { |
| 875 | + urb->iso_frame_desc[k].offset = packet_size * k; |
| 876 | + urb->iso_frame_desc[k].length = packet_size; |
| 877 | + urb->iso_frame_desc[k].actual_length = 0; |
| 878 | + } |
| 879 | +} |
| 880 | |
| 881 | - /* check for deactivation or error */ |
| 882 | - if ((!fifo->active) || (urb->status)) { |
| 883 | - fifo->hfc->active_fifos &= ~fifo->fifo_mask; /* we are inactive */ |
| 884 | - fifo->active = 0; |
| 885 | - if ((fifo->buff) && (fifo->fifonum == HFCUSB_D_TX)) { |
| 886 | - dev_kfree_skb_any(fifo->buff); |
| 887 | +/* allocs urbs and start isoc transfer with two pending urbs to avoid gaps in the transfer chain */ |
| 888 | +static int start_isoc_chain(usb_fifo * fifo, int num_packets_per_urb,usb_complete_t complete,int packet_size) |
| 889 | +{ |
| 890 | + int i, k, errcode; |
| 891 | + |
| 892 | +#ifdef VERBOSE_USB_DEBUG |
| 893 | + printk(KERN_INFO "HFC-USB: starting ISO-chain for Fifo %i\n", fifo->fifonum); |
| 894 | +#endif |
| 895 | + |
| 896 | + |
| 897 | + // allocate Memory for Iso out Urbs |
| 898 | + for (i = 0; i < 2; i++) { |
| 899 | + if (!(fifo->iso[i].purb)) { |
| 900 | + fifo->iso[i].purb = usb_alloc_urb(num_packets_per_urb); |
| 901 | + fifo->iso[i].owner_fifo = (struct usb_fifo *) fifo; |
| 902 | + |
| 903 | + // Init the first iso |
| 904 | + if (ISO_BUFFER_SIZE >= (fifo->usb_packet_maxlen * num_packets_per_urb)) |
| 905 | + { |
| 906 | + |
| 907 | + fill_isoc_urb(fifo->iso[i].purb, fifo->hfc->dev, fifo->pipe, fifo->iso[i].buffer, |
| 908 | + num_packets_per_urb, fifo->usb_packet_maxlen, fifo->intervall, |
| 909 | + complete, &fifo->iso[i]); |
| 910 | + |
| 911 | + memset(fifo->iso[i].buffer, 0, sizeof(fifo->iso[i].buffer)); |
| 912 | + |
| 913 | + // defining packet delimeters in fifo->buffer |
| 914 | + for(k = 0; k < num_packets_per_urb; k++) |
| 915 | + { |
| 916 | + fifo->iso[i].purb->iso_frame_desc[k].offset = k*packet_size; |
| 917 | + fifo->iso[i].purb->iso_frame_desc[k].length = packet_size; |
| 918 | + } |
| 919 | + } |
| 920 | } |
| 921 | - fifo->buff = NULL; |
| 922 | - return; |
| 923 | + |
| 924 | + fifo->bit_line = BITLINE_INF; |
| 925 | + |
| 926 | + errcode = usb_submit_urb(fifo->iso[i].purb); |
| 927 | + fifo->active = (errcode >= 0) ? 1 : 0; |
| 928 | + if(errcode < 0) |
| 929 | + { |
| 930 | + printk(KERN_INFO "HFC-USB: error submitting ISO URB: %i.%i \n", errcode, i); |
| 931 | + }; |
| 932 | + |
| 933 | } |
| 934 | - fifo->act_ptr += (urb->transfer_buffer_length - fifo->rx_offset); /* adjust pointer */ |
| 935 | - fill_tx_urb(fifo); /* refill the urb */ |
| 936 | - fifo->hfc->threshold_mask |= fifo->fifo_mask; /* assume threshold reached */ |
| 937 | - if (fifo->buff) |
| 938 | - fifo->hfc->service_request |= fifo->fifo_mask; /* need to restart */ |
| 939 | -} /* tx_complete */ |
| 940 | |
| 941 | -/***********************************************/ |
| 942 | -/* receive completion routine for all rx fifos */ |
| 943 | -/***********************************************/ |
| 944 | -static void |
| 945 | -rx_complete(purb_t urb) |
| 946 | + // errcode = (usb_submit_urb(fifo->iso[0].purb, GFP_KERNEL)); |
| 947 | + return(fifo->active); |
| 948 | +} |
| 949 | + |
| 950 | +/* stops running iso chain and frees their pending urbs */ |
| 951 | +static void stop_isoc_chain(usb_fifo * fifo) |
| 952 | { |
| 953 | - usb_fifo *fifo = (usb_fifo *) urb->context; /* pointer to our fifo */ |
| 954 | - hfcusb_data *hfc = fifo->hfc; |
| 955 | - usb_fifo *txfifo; |
| 956 | - __u8 last_state; |
| 957 | - int i, ii, currcnt, hdlci; |
| 958 | - struct sk_buff *skb; |
| 959 | - |
| 960 | - urb->dev = hfc->dev; /* security init */ |
| 961 | - if ((!fifo->active) || (urb->status)) { |
| 962 | - hfc->service_request &= ~fifo->fifo_mask; /* no further handling */ |
| 963 | - hfc->active_fifos &= ~fifo->fifo_mask; /* we are inactive */ |
| 964 | - fifo->urb.interval = 0; /* cancel automatic rescheduling */ |
| 965 | - if (fifo->buff) { |
| 966 | - dev_kfree_skb_any(fifo->buff); |
| 967 | - fifo->buff = NULL; |
| 968 | + int i; |
| 969 | + |
| 970 | + for(i = 0; i < 2; i++) |
| 971 | + { |
| 972 | + if(fifo->iso[i].purb) |
| 973 | + { |
| 974 | +#ifdef VERBOSE_USB_DEBUG |
| 975 | + printk(KERN_INFO "HFC-USB: Stopping iso chain for fifo %i.%i\n", fifo->fifonum, i); |
| 976 | +#endif |
| 977 | + usb_unlink_urb(fifo->iso[i].purb); |
| 978 | + usb_free_urb(fifo->iso[i].purb); |
| 979 | + fifo->iso[i].purb = NULL; |
| 980 | } |
| 981 | - return; |
| 982 | } |
| 983 | + if (fifo->urb) { |
| 984 | + usb_unlink_urb(fifo->urb); |
| 985 | + usb_free_urb(fifo->urb); |
| 986 | + fifo->urb = NULL; |
| 987 | + } |
| 988 | + fifo->active = 0; |
| 989 | +} |
| 990 | |
| 991 | - /* first check for any status changes */ |
| 992 | - if ((urb->actual_length < fifo->rx_offset) |
| 993 | - || (urb->actual_length > fifo->usb_maxlen)) |
| 994 | - return; /* error condition */ |
| 995 | - |
| 996 | - if (fifo->rx_offset) { |
| 997 | - hfc->threshold_mask = fifo->buffer[1]; /* update threshold status */ |
| 998 | - fifo->next_complete = fifo->buffer[0] & 1; |
| 999 | - if ((fifo->fifonum == HFCUSB_D_RX) && |
| 1000 | - (hfc->led_req != hfc->led_act)) |
| 1001 | - queue_control_request(hfc, HFCUSB_P_DATA, hfc->led_req); |
| 1002 | - |
| 1003 | - /* check if rescheduling needed */ |
| 1004 | - if ((i = |
| 1005 | - hfc->service_request & hfc->active_fifos & ~hfc-> |
| 1006 | - threshold_mask)) { |
| 1007 | - currcnt = |
| 1008 | - usb_get_current_frame_number(hfc->dev); |
| 1009 | - txfifo = hfc->fifos + HFCUSB_B1_TX; |
| 1010 | - ii = 3; |
| 1011 | - while (ii--) { |
| 1012 | - if ((i & txfifo->fifo_mask) |
| 1013 | - && (currcnt != txfifo->framenum)) { |
| 1014 | - hfc->service_request &= |
| 1015 | - ~txfifo->fifo_mask; |
| 1016 | - if (!txfifo->buff) |
| 1017 | - fill_tx_urb(txfifo); |
| 1018 | - if (txfifo->buff) |
| 1019 | - usb_submit_urb(&txfifo-> |
| 1020 | - urb); |
| 1021 | +// defines how much ISO packets are handled in one URB |
| 1022 | +static int iso_packets[8]={ISOC_PACKETS_B,ISOC_PACKETS_B,ISOC_PACKETS_B,ISOC_PACKETS_B, |
| 1023 | + ISOC_PACKETS_D,ISOC_PACKETS_D,ISOC_PACKETS_D,ISOC_PACKETS_D}; |
| 1024 | + |
| 1025 | +/*****************************************************/ |
| 1026 | +/* transmit completion routine for all ISO tx fifos */ |
| 1027 | +/*****************************************************/ |
| 1028 | +static void tx_iso_complete(struct urb *urb) |
| 1029 | +{ |
| 1030 | + iso_urb_struct *context_iso_urb = (iso_urb_struct *) urb->context; |
| 1031 | + usb_fifo *fifo = context_iso_urb->owner_fifo; |
| 1032 | + hfcusb_data *hfc = fifo->hfc; |
| 1033 | + int k, tx_offset, num_isoc_packets, sink, len, current_len,errcode,frame_complete,transp_mode,fifon; |
| 1034 | + __u8 threshbit; |
| 1035 | + __u8 threshtable[8] = { 1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80}; |
| 1036 | + |
| 1037 | + fifon=fifo->fifonum; |
| 1038 | + tx_offset=0; |
| 1039 | + // very weird error code when using ohci drivers, for now : ignore this error ... (MB) |
| 1040 | + if(urb->status == -EOVERFLOW) |
| 1041 | + { |
| 1042 | + urb->status = 0; |
| 1043 | +#ifdef VERBOSE_USB_DEBUG |
| 1044 | + printk(KERN_INFO "HFC-USB: ignoring USB DATAOVERRUN for fifo %i \n",fifon); |
| 1045 | +#endif |
| 1046 | + } |
| 1047 | + |
| 1048 | + if(fifo->active && !urb->status) |
| 1049 | + { |
| 1050 | + transp_mode=0; |
| 1051 | + if(fifon<4 && hfc->b_mode[fifon/2]==L1_MODE_TRANS) transp_mode=TRUE; |
| 1052 | + |
| 1053 | + threshbit = threshtable[fifon] & hfc->threshold_mask; // is threshold set for our channel? |
| 1054 | + num_isoc_packets=iso_packets[fifon]; |
| 1055 | + |
| 1056 | + if(fifon >= HFCUSB_D_TX) |
| 1057 | + { |
| 1058 | + sink = (threshbit) ? SINK_DMIN : SINK_DMAX; // how much bit go to the sink for D-channel? |
| 1059 | + } |
| 1060 | + else |
| 1061 | + { |
| 1062 | + sink = (threshbit) ? SINK_MIN : SINK_MAX; // how much bit go to the sink for B-channel? |
| 1063 | + } |
| 1064 | + |
| 1065 | + // prepare ISO Urb |
| 1066 | + fill_isoc_urb(urb, fifo->hfc->dev, fifo->pipe,context_iso_urb->buffer, num_isoc_packets, |
| 1067 | + fifo->usb_packet_maxlen, fifo->intervall, tx_iso_complete, urb->context); |
| 1068 | + memset(context_iso_urb->buffer, 0, sizeof(context_iso_urb->buffer)); |
| 1069 | + |
| 1070 | + frame_complete=FALSE; |
| 1071 | + |
| 1072 | + // Generate Iso Packets |
| 1073 | + for(k = 0; k < num_isoc_packets; ++k) |
| 1074 | + { |
| 1075 | + if(fifo->skbuff) |
| 1076 | + { |
| 1077 | + len = fifo->skbuff->len; // remaining length |
| 1078 | + |
| 1079 | + fifo->bit_line -= sink; // we lower data margin every msec |
| 1080 | + current_len = (0 - fifo->bit_line) / 8; |
| 1081 | + if(current_len > 14) current_len = 14; // maximum 15 byte for every ISO packet makes our life easier |
| 1082 | + current_len = (len <= current_len) ? len : current_len; |
| 1083 | + fifo->bit_line += current_len * 8; // how much bit do we put on the line? |
| 1084 | + |
| 1085 | + context_iso_urb->buffer[tx_offset] = 0; |
| 1086 | + if(current_len == len) |
| 1087 | + { |
| 1088 | + if(!transp_mode) |
| 1089 | + { |
| 1090 | + context_iso_urb->buffer[tx_offset] = 1; // here frame completion |
| 1091 | + fifo->bit_line += 32; // add 2 byte flags and 16bit CRC at end of ISDN frame |
| 1092 | + } |
| 1093 | + frame_complete = TRUE; |
| 1094 | + } |
| 1095 | + |
| 1096 | + // copy bytes from buffer into ISO_URB |
| 1097 | + memcpy(context_iso_urb->buffer+tx_offset+1,fifo->skbuff->data,current_len); |
| 1098 | + skb_pull(fifo->skbuff,current_len); |
| 1099 | + |
| 1100 | + // define packet delimeters within the URB buffer |
| 1101 | + urb->iso_frame_desc[k].offset = tx_offset; |
| 1102 | + urb->iso_frame_desc[k].length = current_len + 1; |
| 1103 | + |
| 1104 | + tx_offset += (current_len + 1); |
| 1105 | + // printk(KERN_INFO "HFC-USB: fifonum:%d,%d bytes to send, %d bytes ISO packet,bitline:%d,sink:%d,threshbit:%d,threshmask:%x\n",fifon,len,current_len,fifo->bit_line,sink,threshbit,hfc->threshold_mask); |
| 1106 | + if(!transp_mode) |
| 1107 | + { |
| 1108 | + if(fifon==HFCUSB_B1_TX) handle_led(hfc,LED_B1_DATA); |
| 1109 | + if(fifon==HFCUSB_B2_TX) handle_led(hfc,LED_B2_DATA); |
| 1110 | + } |
| 1111 | + } |
| 1112 | + else |
| 1113 | + { |
| 1114 | + // we have no more data - generate 1 byte ISO packets |
| 1115 | + urb->iso_frame_desc[k].offset = tx_offset++; |
| 1116 | + |
| 1117 | + urb->iso_frame_desc[k].length = 1; |
| 1118 | + fifo->bit_line -= sink; // we lower data margin every msec |
| 1119 | + |
| 1120 | + if(fifo->bit_line < BITLINE_INF) |
| 1121 | + { |
| 1122 | + fifo->bit_line = BITLINE_INF; |
| 1123 | + //printk (KERN_INFO "HFC-USB: BITLINE_INF underrun\n"); |
| 1124 | } |
| 1125 | - txfifo += 2; |
| 1126 | } |
| 1127 | - } |
| 1128 | |
| 1129 | - /* handle l1 events */ |
| 1130 | - if ((fifo->buffer[0] >> 4) != hfc->l1_state) { |
| 1131 | - last_state = hfc->l1_state; |
| 1132 | - hfc->l1_state = fifo->buffer[0] >> 4; /* update status */ |
| 1133 | - if (timer_pending(&hfc->t4_timer)) |
| 1134 | - del_timer(&hfc->t4_timer); |
| 1135 | - if (((hfc->l1_state == 3) && |
| 1136 | - ((last_state == 7) || |
| 1137 | - (last_state == 8))) || |
| 1138 | - ((timer_pending(&hfc->t3_timer) && |
| 1139 | - (hfc->l1_state == 8)))) { |
| 1140 | - hfc->t4_timer.expires = jiffies + 2; |
| 1141 | - add_timer(&hfc->t4_timer); |
| 1142 | - } else { |
| 1143 | - if (timer_pending(&hfc->t3_timer) |
| 1144 | - && (hfc->l1_state == 7)) |
| 1145 | - del_timer(&hfc->t3_timer); /* no longer needed */ |
| 1146 | - test_and_set_bit(HFCUSB_L1_STATECHANGE, |
| 1147 | - &hfc->l1_event); |
| 1148 | - queue_task(&hfc->l1_tq, &tq_immediate); |
| 1149 | - mark_bh(IMMEDIATE_BH); |
| 1150 | + if(frame_complete) |
| 1151 | + { |
| 1152 | + // delete the buffer only once, here or in hfc_usb_l2l1() in a PH_DATA|REQUEST |
| 1153 | + fifo->delete_flg=TRUE; |
| 1154 | + |
| 1155 | + fifo->hif->l1l2(fifo->hif,PH_DATA|CONFIRM,(void*)fifo->skbuff->truesize); |
| 1156 | + |
| 1157 | + if(fifo->skbuff && fifo->delete_flg) |
| 1158 | + { |
| 1159 | + dev_kfree_skb_any(fifo->skbuff); |
| 1160 | + //printk(KERN_INFO "HFC-USB: skbuff=NULL on fifo:%d\n",fifo->fifonum); |
| 1161 | + fifo->skbuff = NULL; |
| 1162 | + fifo->delete_flg=FALSE; |
| 1163 | + } |
| 1164 | + |
| 1165 | + frame_complete=FALSE; |
| 1166 | } |
| 1167 | + } |
| 1168 | + |
| 1169 | + errcode = usb_submit_urb(urb); |
| 1170 | + if(errcode < 0) |
| 1171 | + { |
| 1172 | + printk(KERN_INFO "HFC-USB: error submitting ISO URB: %i \n", errcode); |
| 1173 | + } |
| 1174 | + } |
| 1175 | + else |
| 1176 | + { |
| 1177 | + if(urb->status) |
| 1178 | + { |
| 1179 | + printk(KERN_INFO "HFC-USB: tx_iso_complete : urb->status %i, fifonum %i\n", urb->status,fifon); |
| 1180 | } |
| 1181 | } |
| 1182 | |
| 1183 | - /* check the length for data and move if present */ |
| 1184 | - if (fifo->next_complete || (urb->actual_length > fifo->rx_offset)) { |
| 1185 | - i = fifo->buff->len + urb->actual_length - fifo->rx_offset; /* new total length */ |
| 1186 | - hdlci = (fifo->transmode) ? 0 : 3; |
| 1187 | - if (i <= (fifo->max_size + hdlci)) { |
| 1188 | - memcpy(fifo->act_ptr, |
| 1189 | - fifo->buffer + fifo->rx_offset, |
| 1190 | - urb->actual_length - fifo->rx_offset); |
| 1191 | - fifo->act_ptr += |
| 1192 | - (urb->actual_length - fifo->rx_offset); |
| 1193 | - fifo->buff->len += |
| 1194 | - (urb->actual_length - fifo->rx_offset); |
| 1195 | - } else |
| 1196 | - fifo->buff->len = fifo->max_size + 4; /* mark frame as to long */ |
| 1197 | - if (fifo->next_complete && (urb->actual_length < fifo->usb_maxlen)) { |
| 1198 | - /* the frame is complete */ |
| 1199 | - fifo->next_complete = 0; |
| 1200 | - if (((!*(fifo->act_ptr - 1)) || fifo->transmode) && |
| 1201 | - (fifo->buff->len >= (hdlci + 1)) |
| 1202 | - && (fifo->buff->len <= |
| 1203 | - (fifo->max_size + hdlci)) && |
| 1204 | - ((skb = dev_alloc_skb(fifo->max_size + hdlci)) != NULL)) { |
| 1205 | - fifo->buff->len -= hdlci; /* adjust size */ |
| 1206 | - switch (fifo->fifonum) { |
| 1207 | - case HFCUSB_D_RX: |
| 1208 | - skb_queue_tail(hfc->regd. |
| 1209 | - drq, |
| 1210 | - fifo->buff); |
| 1211 | - test_and_set_bit |
| 1212 | - (HFCUSB_L1_DRX, |
| 1213 | - &hfc->l1_event); |
| 1214 | - queue_task(&hfc->l1_tq, |
| 1215 | - &tq_immediate); |
| 1216 | - mark_bh(IMMEDIATE_BH); |
| 1217 | - break; |
| 1218 | +} /* tx_iso_complete */ |
| 1219 | |
| 1220 | - case HFCUSB_B1_RX: |
| 1221 | - if (hfc->regd.brq[0]) { |
| 1222 | - skb_queue_tail |
| 1223 | - (hfc->regd. |
| 1224 | - brq[0], |
| 1225 | - fifo->buff); |
| 1226 | - hfc->regd. |
| 1227 | - bch_l1l2(hfc-> |
| 1228 | - regd. |
| 1229 | - arg_hisax, |
| 1230 | - 0, |
| 1231 | - PH_DATA |
| 1232 | - | |
| 1233 | - INDICATION, |
| 1234 | - (void *) |
| 1235 | - fifo-> |
| 1236 | - buff); |
| 1237 | - } else |
| 1238 | - dev_kfree_skb_any |
| 1239 | - (fifo->buff); |
| 1240 | - break; |
| 1241 | - |
| 1242 | - case HFCUSB_B2_RX: |
| 1243 | - if (hfc->regd.brq[1]) { |
| 1244 | - skb_queue_tail |
| 1245 | - (hfc->regd. |
| 1246 | - brq[1], |
| 1247 | - fifo->buff); |
| 1248 | - hfc->regd. |
| 1249 | - bch_l1l2(hfc-> |
| 1250 | - regd. |
| 1251 | - arg_hisax, |
| 1252 | - 1, |
| 1253 | - PH_DATA |
| 1254 | - | |
| 1255 | - INDICATION, |
| 1256 | - (void |
| 1257 | - *) |
| 1258 | - fifo-> |
| 1259 | - buff); |
| 1260 | - } else |
| 1261 | - dev_kfree_skb_any |
| 1262 | - (fifo->buff); |
| 1263 | - break; |
| 1264 | +/*****************************************************/ |
| 1265 | +/* receive completion routine for all ISO tx fifos */ |
| 1266 | +/*****************************************************/ |
| 1267 | +static void rx_iso_complete(struct urb *urb) |
| 1268 | +{ |
| 1269 | + iso_urb_struct *context_iso_urb = (iso_urb_struct *) urb->context; |
| 1270 | + usb_fifo *fifo = context_iso_urb->owner_fifo; |
| 1271 | + hfcusb_data *hfc = fifo->hfc; |
| 1272 | + int k, len, errcode, offset, num_isoc_packets,fifon; |
| 1273 | + __u8 *buf; |
| 1274 | |
| 1275 | - case HFCUSB_PCM_RX: |
| 1276 | - skb_queue_tail(&hfc->regd. |
| 1277 | - erq, |
| 1278 | - fifo->buff); |
| 1279 | - test_and_set_bit |
| 1280 | - (HFCUSB_L1_ERX, |
| 1281 | - &hfc->l1_event); |
| 1282 | - queue_task(&hfc->l1_tq, |
| 1283 | - &tq_immediate); |
| 1284 | - mark_bh(IMMEDIATE_BH); |
| 1285 | - break; |
| 1286 | + fifon=fifo->fifonum; |
| 1287 | + // very weird error code when using ohci drivers, for now : ignore this error ... (MB) |
| 1288 | + if(urb->status == -EOVERFLOW) |
| 1289 | + { |
| 1290 | + urb->status = 0; |
| 1291 | +#ifdef VERBOSE_USB_DEBUG |
| 1292 | + printk(KERN_INFO "HFC-USB: ignoring USB DATAOVERRUN for fifo %i \n",fifon); |
| 1293 | +#endif |
| 1294 | + } |
| 1295 | |
| 1296 | - default: |
| 1297 | - dev_kfree_skb_any(fifo-> |
| 1298 | - buff); |
| 1299 | - break; |
| 1300 | + if(fifo->active && !urb->status) |
| 1301 | + { |
| 1302 | + num_isoc_packets=iso_packets[fifon]; |
| 1303 | + |
| 1304 | + // Generate D-Channel Iso Packets |
| 1305 | + for(k = 0; k < num_isoc_packets; ++k) |
| 1306 | + { |
| 1307 | + len=urb->iso_frame_desc[k].actual_length; |
| 1308 | + offset=urb->iso_frame_desc[k].offset; |
| 1309 | + buf=context_iso_urb->buffer+offset; |
| 1310 | + |
| 1311 | + if(fifo->last_urblen!=fifo->usb_packet_maxlen) |
| 1312 | + { |
| 1313 | + // the threshold mask is in the 2nd status byte |
| 1314 | + hfc->threshold_mask=buf[1]; |
| 1315 | + // the S0 state is in the upper half of the 1st status byte |
| 1316 | + state_handler(hfc,buf[0] >> 4); |
| 1317 | + // if we have more than the 2 status bytes -> collect data |
| 1318 | + if(len>2) collect_rx_frame(fifo,buf+2,len-2,buf[0]&1); |
| 1319 | } |
| 1320 | - fifo->buff = skb; |
| 1321 | - } |
| 1322 | - fifo->buff->len = 0; /* reset counter */ |
| 1323 | - fifo->act_ptr = fifo->buff->data; /* and pointer */ |
| 1324 | + else collect_rx_frame(fifo,buf,len,0); |
| 1325 | + |
| 1326 | + fifo->last_urblen=len; |
| 1327 | + |
| 1328 | + } |
| 1329 | + |
| 1330 | + // prepare ISO Urb |
| 1331 | + fill_isoc_urb(urb, fifo->hfc->dev, fifo->pipe,context_iso_urb->buffer, num_isoc_packets, |
| 1332 | + fifo->usb_packet_maxlen, fifo->intervall, rx_iso_complete, urb->context); |
| 1333 | + |
| 1334 | + errcode = usb_submit_urb(urb); |
| 1335 | + if(errcode < 0) |
| 1336 | + { |
| 1337 | + printk(KERN_INFO "HFC-USB: error submitting ISO URB: %i \n", errcode); |
| 1338 | + } |
| 1339 | + } |
| 1340 | + else |
| 1341 | + { |
| 1342 | + if(urb->status) |
| 1343 | + { |
| 1344 | + printk(KERN_INFO "HFC-USB: rx_iso_complete : urb->status %i, fifonum %i\n", urb->status,fifon); |
| 1345 | + } |
| 1346 | + } |
| 1347 | +} /* rx_iso_complete */ |
| 1348 | + |
| 1349 | + |
| 1350 | +/*****************************************************/ |
| 1351 | +/* collect data from interrupt or isochron in */ |
| 1352 | +/*****************************************************/ |
| 1353 | +static void collect_rx_frame(usb_fifo *fifo,__u8 *data,int len,int finish) |
| 1354 | +{ |
| 1355 | + hfcusb_data *hfc = fifo->hfc; |
| 1356 | + int transp_mode,fifon; |
| 1357 | + |
| 1358 | + fifon=fifo->fifonum; |
| 1359 | + transp_mode=0; |
| 1360 | + if(fifon<4 && hfc->b_mode[fifon/2]==L1_MODE_TRANS) transp_mode=TRUE; |
| 1361 | + |
| 1362 | + //printk(KERN_INFO "HFC-USB: got %d bytes finish:%d max_size:%d fifo:%d\n",len,finish,fifo->max_size,fifon); |
| 1363 | + if(!fifo->skbuff) |
| 1364 | + { |
| 1365 | + // allocate sk buffer |
| 1366 | + fifo->skbuff=dev_alloc_skb(fifo->max_size + 3); |
| 1367 | + if(!fifo->skbuff) |
| 1368 | + { |
| 1369 | + printk(KERN_INFO "HFC-USB: cannot allocate buffer (dev_alloc_skb) fifo:%d\n",fifon); |
| 1370 | + return; |
| 1371 | + } |
| 1372 | + |
| 1373 | + } |
| 1374 | + |
| 1375 | + if(len && fifo->skbuff->len+len<fifo->max_size) |
| 1376 | + { |
| 1377 | + memcpy(skb_put(fifo->skbuff,len),data,len); |
| 1378 | + } |
| 1379 | + else printk(KERN_INFO "HCF-USB: got frame exceeded fifo->max_size:%d\n",fifo->max_size); |
| 1380 | + |
| 1381 | + // give transparent data up, when 128 byte are available |
| 1382 | + if(transp_mode && fifo->skbuff->len>=128) |
| 1383 | + { |
| 1384 | + fifo->hif->l1l2(fifo->hif,PH_DATA | INDICATION,fifo->skbuff); |
| 1385 | + fifo->skbuff = NULL; // buffer was freed from upper layer |
| 1386 | + return; |
| 1387 | + } |
| 1388 | + |
| 1389 | + // we have a complete hdlc packet |
| 1390 | + if(finish) |
| 1391 | + { |
| 1392 | + if(!fifo->skbuff->data[fifo->skbuff->len-1]) |
| 1393 | + { |
| 1394 | + skb_trim(fifo->skbuff,fifo->skbuff->len-3); // remove CRC & status |
| 1395 | + |
| 1396 | + //printk(KERN_INFO "HFC-USB: got frame %d bytes on fifo:%d\n",fifo->skbuff->len,fifon); |
| 1397 | + |
| 1398 | + if(fifon==HFCUSB_PCM_RX) fifo->hif->l1l2(fifo->hif,PH_DATA_E | INDICATION,fifo->skbuff); |
| 1399 | + else fifo->hif->l1l2(fifo->hif,PH_DATA | INDICATION,fifo->skbuff); |
| 1400 | + |
| 1401 | + fifo->skbuff = NULL; // buffer was freed from upper layer |
| 1402 | + } |
| 1403 | + else |
| 1404 | + { |
| 1405 | + printk(KERN_INFO "HFC-USB: got frame %d bytes but CRC ERROR!!!\n",fifo->skbuff->len); |
| 1406 | + |
| 1407 | + skb_trim(fifo->skbuff,0); // clear whole buffer |
| 1408 | + } |
| 1409 | + } |
| 1410 | + |
| 1411 | + // LED flashing only in HDLC mode |
| 1412 | + if(!transp_mode) |
| 1413 | + { |
| 1414 | + if(fifon==HFCUSB_B1_RX) handle_led(hfc,LED_B1_DATA); |
| 1415 | + if(fifon==HFCUSB_B2_RX) handle_led(hfc,LED_B2_DATA); |
| 1416 | + } |
| 1417 | +} |
| 1418 | + |
| 1419 | +/***********************************************/ |
| 1420 | +/* receive completion routine for all rx fifos */ |
| 1421 | +/***********************************************/ |
| 1422 | +static void rx_complete(struct urb *urb) |
| 1423 | +{ |
| 1424 | + int len; |
| 1425 | + __u8 *buf; |
| 1426 | + usb_fifo *fifo = (usb_fifo *) urb->context; /* pointer to our fifo */ |
| 1427 | + hfcusb_data *hfc = fifo->hfc; |
| 1428 | + |
| 1429 | + urb->dev = hfc->dev; /* security init */ |
| 1430 | + |
| 1431 | + if((!fifo->active) || (urb->status)) { |
| 1432 | +#ifdef VERBOSE_USB_DEBUG |
| 1433 | + printk(KERN_INFO "HFC-USB: RX-Fifo %i is going down (%i)\n", fifo->fifonum, urb->status); |
| 1434 | +#endif |
| 1435 | + fifo->urb->interval = 0; /* cancel automatic rescheduling */ |
| 1436 | + if(fifo->skbuff) { |
| 1437 | + dev_kfree_skb_any(fifo->skbuff); |
| 1438 | + fifo->skbuff = NULL; |
| 1439 | } |
| 1440 | + return; |
| 1441 | } |
| 1442 | - fifo->rx_offset = (urb->actual_length < fifo->usb_maxlen) ? 2 : 0; |
| 1443 | -} /* rx_complete */ |
| 1444 | + |
| 1445 | + len=urb->actual_length; |
| 1446 | + buf=fifo->buffer; |
| 1447 | + |
| 1448 | + if(fifo->last_urblen!=fifo->usb_packet_maxlen) { |
| 1449 | + // the threshold mask is in the 2nd status byte |
| 1450 | + hfc->threshold_mask=buf[1]; |
| 1451 | + // the S0 state is in the upper half of the 1st status byte |
| 1452 | + state_handler(hfc,buf[0] >> 4); |
| 1453 | + // if we have more than the 2 status bytes -> collect data |
| 1454 | + if(len>2) collect_rx_frame(fifo,buf+2,urb->actual_length-2,buf[0]&1); |
| 1455 | + } else |
| 1456 | + collect_rx_frame(fifo,buf,urb->actual_length,0); |
| 1457 | + |
| 1458 | + fifo->last_urblen=urb->actual_length; |
| 1459 | + |
| 1460 | + |
| 1461 | +} /* rx_complete */ |
| 1462 | + |
| 1463 | + |
| 1464 | |
| 1465 | /***************************************************/ |
| 1466 | /* start the interrupt transfer for the given fifo */ |
| 1467 | /***************************************************/ |
| 1468 | -static void |
| 1469 | -start_rx_fifo(usb_fifo * fifo) |
| 1470 | +static void start_int_fifo(usb_fifo * fifo) |
| 1471 | { |
| 1472 | - if (fifo->buff) |
| 1473 | - return; /* still active */ |
| 1474 | - if (! |
| 1475 | - (fifo->buff = |
| 1476 | - dev_alloc_skb(fifo->max_size + (fifo->transmode ? 0 : 3)))) |
| 1477 | - return; |
| 1478 | - fifo->act_ptr = fifo->buff->data; |
| 1479 | - FILL_INT_URB(&fifo->urb, fifo->hfc->dev, fifo->pipe, fifo->buffer, |
| 1480 | - fifo->usb_maxlen, rx_complete, fifo, fifo->intervall); |
| 1481 | - fifo->next_complete = 0; |
| 1482 | - fifo->rx_offset = 2; |
| 1483 | - fifo->active = 1; /* must be marked active */ |
| 1484 | - fifo->hfc->active_fifos |= fifo->fifo_mask; |
| 1485 | - if (usb_submit_urb(&fifo->urb)) { |
| 1486 | + int errcode; |
| 1487 | + |
| 1488 | +#ifdef VERBOSE_USB_DEBUG |
| 1489 | + printk(KERN_INFO "HFC-USB: starting intr IN fifo:%d\n", fifo->fifonum); |
| 1490 | +#endif |
| 1491 | + if (!fifo->urb) { |
| 1492 | + fifo->urb = usb_alloc_urb(0); |
| 1493 | + if (!fifo->urb) |
| 1494 | + return; |
| 1495 | + } |
| 1496 | + usb_fill_int_urb(fifo->urb, fifo->hfc->dev, fifo->pipe, fifo->buffer, |
| 1497 | + fifo->usb_packet_maxlen, rx_complete, fifo, fifo->intervall); |
| 1498 | + fifo->active = 1; /* must be marked active */ |
| 1499 | + errcode = usb_submit_urb(fifo->urb); |
| 1500 | + |
| 1501 | + if(errcode) |
| 1502 | + { |
| 1503 | + printk(KERN_INFO "HFC-USB: submit URB error(start_int_info): status:%i\n", errcode); |
| 1504 | fifo->active = 0; |
| 1505 | - fifo->hfc->active_fifos &= ~fifo->fifo_mask; |
| 1506 | - dev_kfree_skb_any(fifo->buff); |
| 1507 | - fifo->buff = NULL; |
| 1508 | + fifo->skbuff = NULL; |
| 1509 | } |
| 1510 | -} /* start_rx_fifo */ |
| 1511 | +} /* start_int_fifo */ |
| 1512 | |
| 1513 | -/***************************************************************/ |
| 1514 | -/* control completion routine handling background control cmds */ |
| 1515 | -/***************************************************************/ |
| 1516 | -static void |
| 1517 | -ctrl_complete(purb_t urb) |
| 1518 | +/*****************************/ |
| 1519 | +/* set the B-channel mode */ |
| 1520 | +/*****************************/ |
| 1521 | +static void set_hfcmode(hfcusb_data *hfc,int channel,int mode) |
| 1522 | { |
| 1523 | - hfcusb_data *hfc = (hfcusb_data *) urb->context; |
| 1524 | + __u8 val,idx_table[2]={0,2}; |
| 1525 | |
| 1526 | - urb->dev = hfc->dev; |
| 1527 | - if (hfc->ctrl_cnt) { |
| 1528 | - switch (hfc->ctrl_buff[hfc->ctrl_out_idx].hfc_reg) { |
| 1529 | - case HFCUSB_FIFO: |
| 1530 | - hfc->ctrl_fifo = |
| 1531 | - hfc->ctrl_buff[hfc->ctrl_out_idx]. |
| 1532 | - reg_val; |
| 1533 | - break; |
| 1534 | - case HFCUSB_F_USAGE: |
| 1535 | - if (!hfc->dfifo_fill) { |
| 1536 | - fill_tx_urb(hfc->fifos + |
| 1537 | - HFCUSB_D_TX); |
| 1538 | - if (hfc->fifos[HFCUSB_D_TX].buff) |
| 1539 | - usb_submit_urb(&hfc-> |
| 1540 | - fifos |
| 1541 | - [HFCUSB_D_TX]. |
| 1542 | - urb); |
| 1543 | - } else { |
| 1544 | - queue_control_request(hfc, |
| 1545 | - HFCUSB_FIFO, |
| 1546 | - HFCUSB_D_TX); |
| 1547 | - queue_control_request(hfc, |
| 1548 | - HFCUSB_F_USAGE, |
| 1549 | - 0); |
| 1550 | - } |
| 1551 | - break; |
| 1552 | - case HFCUSB_SCTRL_R: |
| 1553 | - switch (hfc->ctrl_fifo) { |
| 1554 | - case HFCUSB_B1_RX: |
| 1555 | - if (hfc->bch_enables & 1) |
| 1556 | - start_rx_fifo(hfc-> |
| 1557 | - fifos |
| 1558 | - + |
| 1559 | - HFCUSB_B1_RX); |
| 1560 | - break; |
| 1561 | - case HFCUSB_B2_RX: |
| 1562 | - if (hfc->bch_enables & 2) |
| 1563 | - start_rx_fifo(hfc-> |
| 1564 | - fifos |
| 1565 | - + |
| 1566 | - HFCUSB_B2_RX); |
| 1567 | - break; |
| 1568 | - } |
| 1569 | - if (hfc->bch_enables & 3) |
| 1570 | - hfc->led_req |= LED_BCH; |
| 1571 | - else |
| 1572 | - hfc->led_req &= ~LED_BCH; |
| 1573 | - break; |
| 1574 | - case HFCUSB_P_DATA: |
| 1575 | - hfc->led_act = |
| 1576 | - hfc->ctrl_buff[hfc->ctrl_out_idx]. |
| 1577 | - reg_val; |
| 1578 | - break; |
| 1579 | - } |
| 1580 | - hfc->ctrl_cnt--; /* decrement actual count */ |
| 1581 | - if (++hfc->ctrl_out_idx >= HFC_CTRL_BUFSIZE) |
| 1582 | - hfc->ctrl_out_idx = 0; /* pointer wrap */ |
| 1583 | - ctrl_start_transfer(hfc); /* start next transfer */ |
| 1584 | +#ifdef VERBOSE_ISDN_DEBUG |
| 1585 | + printk (KERN_INFO "HFC-USB: setting channel %d to mode %d\n",channel,mode); |
| 1586 | +#endif |
| 1587 | + |
| 1588 | + hfc->b_mode[channel]=mode; |
| 1589 | + |
| 1590 | + // setup CON_HDLC |
| 1591 | + val=0; |
| 1592 | + if(mode!=L1_MODE_NULL) val=8; // enable fifo? |
| 1593 | + if(mode==L1_MODE_TRANS) val|=2; // set transparent bit |
| 1594 | + |
| 1595 | + queue_control_request(hfc,HFCUSB_FIFO,idx_table[channel],1); // set FIFO to transmit register |
| 1596 | + queue_control_request(hfc,HFCUSB_CON_HDLC,val,1); |
| 1597 | + queue_control_request(hfc,HFCUSB_INC_RES_F,2,1); // reset fifo |
| 1598 | + |
| 1599 | + queue_control_request(hfc,HFCUSB_FIFO,idx_table[channel]+1,1); // set FIFO to receive register |
| 1600 | + queue_control_request(hfc,HFCUSB_CON_HDLC,val,1); |
| 1601 | + queue_control_request(hfc,HFCUSB_INC_RES_F,2,1); // reset fifo |
| 1602 | + |
| 1603 | + val=0x40; |
| 1604 | + if(hfc->b_mode[0]) val|=1; |
| 1605 | + if(hfc->b_mode[1]) val|=2; |
| 1606 | + queue_control_request(hfc,HFCUSB_SCTRL,val,1); |
| 1607 | + |
| 1608 | + val=0; |
| 1609 | + if(hfc->b_mode[0]) val|=1; |
| 1610 | + if(hfc->b_mode[1]) val|=2; |
| 1611 | + queue_control_request(hfc,HFCUSB_SCTRL_R,val,1); |
| 1612 | + |
| 1613 | + if(mode==L1_MODE_NULL) |
| 1614 | + { |
| 1615 | + if(channel) handle_led(hfc,LED_B2_OFF); |
| 1616 | + else handle_led(hfc,LED_B1_OFF); |
| 1617 | } |
| 1618 | -} /* ctrl_complete */ |
| 1619 | + else |
| 1620 | + { |
| 1621 | + if(channel) handle_led(hfc,LED_B2_ON); |
| 1622 | + else handle_led(hfc,LED_B1_ON); |
| 1623 | + } |
| 1624 | +} |
| 1625 | |
| 1626 | -/*****************************************/ |
| 1627 | -/* Layer 1 + D channel access from HiSax */ |
| 1628 | -/*****************************************/ |
| 1629 | -static void |
| 1630 | -hfcusb_l1_access(void *drvarg, int pr, void *arg) |
| 1631 | -{ |
| 1632 | - hfcusb_data *hfc = (hfcusb_data *) drvarg; |
| 1633 | - |
| 1634 | - switch (pr) { |
| 1635 | - case (PH_DATA | REQUEST): |
| 1636 | - case (PH_PULL | INDICATION): |
| 1637 | - skb_queue_tail(hfc->regd.dsq, |
| 1638 | - (struct sk_buff *) arg); |
| 1639 | - if (!hfc->fifos[HFCUSB_D_TX].active |
| 1640 | - && !hfc->dfifo_fill) { |
| 1641 | - fill_tx_urb(hfc->fifos + HFCUSB_D_TX); |
| 1642 | - hfc->active_fifos |= |
| 1643 | - hfc->fifos[HFCUSB_D_TX].fifo_mask; |
| 1644 | - usb_submit_urb(&hfc->fifos[HFCUSB_D_TX]. |
| 1645 | - urb); |
| 1646 | - } |
| 1647 | - break; |
| 1648 | - case (PH_ACTIVATE | REQUEST): |
| 1649 | - switch (hfc->l1_state) { |
| 1650 | - case 6: |
| 1651 | - case 8: |
| 1652 | - hfc->regd.dch_l1l2(hfc->regd.arg_hisax, |
| 1653 | - (PH_DEACTIVATE | |
| 1654 | - INDICATION), NULL); |
| 1655 | +/* |
| 1656 | + -------------------------------------------------------------------------------------- |
| 1657 | + from here : hisax_if callback routines : |
| 1658 | + - void hfc_usb_d_l2l1(struct hisax_if *hisax_d_if, int pr, void *arg) { |
| 1659 | |
| 1660 | - break; |
| 1661 | - case 7: |
| 1662 | - hfc->regd.dch_l1l2(hfc->regd.arg_hisax, |
| 1663 | - (PH_ACTIVATE | |
| 1664 | - INDICATION), NULL); |
| 1665 | + l1 to l2 routines : |
| 1666 | + - static void hfc_usb_l1l2(hfcusb_data * hfc) |
| 1667 | |
| 1668 | - break; |
| 1669 | - default: |
| 1670 | - queue_control_request(hfc, HFCUSB_STATES, 0x60); /* start activation */ |
| 1671 | - hfc->t3_timer.expires = |
| 1672 | - jiffies + (HFC_TIMER_T3 * HZ) / 1000; |
| 1673 | - if (!timer_pending(&hfc->t3_timer)) |
| 1674 | - add_timer(&hfc->t3_timer); |
| 1675 | - break; |
| 1676 | - } |
| 1677 | - break; |
| 1678 | +*/ |
| 1679 | |
| 1680 | - case (PH_DEACTIVATE | REQUEST): |
| 1681 | - queue_control_request(hfc, HFCUSB_STATES, 0x40); /* start deactivation */ |
| 1682 | - break; |
| 1683 | - default: |
| 1684 | - printk(KERN_INFO "unknown hfcusb l1_access 0x%x\n", |
| 1685 | - pr); |
| 1686 | - break; |
| 1687 | - } |
| 1688 | -} /* hfcusb_l1_access */ |
| 1689 | - |
| 1690 | -/*******************************/ |
| 1691 | -/* B channel access from HiSax */ |
| 1692 | -/*******************************/ |
| 1693 | -static void |
| 1694 | -hfcusb_bch_access(void *drvarg, int chan, int pr, void *arg) |
| 1695 | -{ |
| 1696 | - hfcusb_data *hfc = (hfcusb_data *) drvarg; |
| 1697 | - usb_fifo *fifo = hfc->fifos + (chan ? HFCUSB_B2_TX : HFCUSB_B1_TX); |
| 1698 | - long flags; |
| 1699 | - |
| 1700 | - switch (pr) { |
| 1701 | - case (PH_DATA | REQUEST): |
| 1702 | - case (PH_PULL | INDICATION): |
| 1703 | - save_flags(flags); |
| 1704 | - cli(); |
| 1705 | - if (!fifo->active) { |
| 1706 | - fill_tx_urb(fifo); |
| 1707 | - hfc->active_fifos |= fifo->fifo_mask; |
| 1708 | - usb_submit_urb(&fifo->urb); |
| 1709 | - } |
| 1710 | - restore_flags(flags); |
| 1711 | - break; |
| 1712 | - case (PH_ACTIVATE | REQUEST): |
| 1713 | - if (!((int) arg)) { |
| 1714 | - hfc->bch_enables &= ~(1 << chan); |
| 1715 | - if (fifo->active) { |
| 1716 | - fifo->active = 0; |
| 1717 | - usb_unlink_urb(&fifo->urb); |
| 1718 | +void hfc_usb_l2l1(struct hisax_if *my_hisax_if, int pr, void *arg) |
| 1719 | +{ |
| 1720 | + usb_fifo *fifo = my_hisax_if->priv; |
| 1721 | + hfcusb_data *hfc = fifo->hfc; |
| 1722 | + |
| 1723 | + switch (pr) { |
| 1724 | + case PH_ACTIVATE | REQUEST: |
| 1725 | + if(fifo->fifonum==HFCUSB_D_TX) |
| 1726 | + { |
| 1727 | +#ifdef VERBOSE_ISDN_DEBUG |
| 1728 | + printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_ACTIVATE | REQUEST\n"); |
| 1729 | +#endif |
| 1730 | + queue_control_request(hfc, HFCUSB_STATES,0x60,1); /* make activation */ |
| 1731 | + hfc->t3_timer.expires = jiffies + (HFC_TIMER_T3 * HZ) / 1000; |
| 1732 | + if(!timer_pending(&hfc->t3_timer)) add_timer(&hfc->t3_timer); |
| 1733 | } |
| 1734 | - save_flags(flags); |
| 1735 | - cli(); |
| 1736 | - queue_control_request(hfc, HFCUSB_FIFO, |
| 1737 | - fifo->fifonum); |
| 1738 | - queue_control_request(hfc, |
| 1739 | - HFCUSB_INC_RES_F, 2); |
| 1740 | - queue_control_request(hfc, HFCUSB_CON_HDLC, |
| 1741 | - 9); |
| 1742 | - queue_control_request(hfc, HFCUSB_SCTRL, |
| 1743 | - 0x40 + |
| 1744 | - hfc->bch_enables); |
| 1745 | - queue_control_request(hfc, HFCUSB_SCTRL_R, |
| 1746 | - hfc->bch_enables); |
| 1747 | - restore_flags(flags); |
| 1748 | - fifo++; |
| 1749 | - if (fifo->active) { |
| 1750 | - fifo->active = 0; |
| 1751 | - usb_unlink_urb(&fifo->urb); |
| 1752 | + else |
| 1753 | + { |
| 1754 | +#ifdef VERBOSE_ISDN_DEBUG |
| 1755 | + printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_ACTIVATE | REQUEST\n"); |
| 1756 | +#endif |
| 1757 | + set_hfcmode(hfc,(fifo->fifonum==HFCUSB_B1_TX) ? 0 : 1 ,(int)arg); |
| 1758 | + fifo->hif->l1l2(fifo->hif,PH_ACTIVATE | INDICATION, NULL); |
| 1759 | } |
| 1760 | - return; /* fifo deactivated */ |
| 1761 | - } |
| 1762 | - fifo->transmode = ((int) arg == L1_MODE_TRANS); |
| 1763 | - fifo->max_size = |
| 1764 | - ((fifo->transmode) ? fifo-> |
| 1765 | - usb_maxlen : MAX_BCH_SIZE); |
| 1766 | - (fifo + 1)->transmode = fifo->transmode; |
| 1767 | - (fifo + 1)->max_size = fifo->max_size; |
| 1768 | - hfc->bch_enables |= (1 << chan); |
| 1769 | - save_flags(flags); |
| 1770 | - cli(); |
| 1771 | - queue_control_request(hfc, HFCUSB_FIFO, |
| 1772 | - fifo->fifonum); |
| 1773 | - queue_control_request(hfc, HFCUSB_CON_HDLC, |
| 1774 | - ((!fifo-> |
| 1775 | - transmode) ? 9 : 11)); |
| 1776 | - queue_control_request(hfc, HFCUSB_INC_RES_F, 2); |
| 1777 | - queue_control_request(hfc, HFCUSB_SCTRL, |
| 1778 | - 0x40 + hfc->bch_enables); |
| 1779 | - if ((int) arg == L1_MODE_HDLC) |
| 1780 | - queue_control_request(hfc, HFCUSB_CON_HDLC, |
| 1781 | - 8); |
| 1782 | - queue_control_request(hfc, HFCUSB_FIFO, |
| 1783 | - fifo->fifonum + 1); |
| 1784 | - queue_control_request(hfc, HFCUSB_CON_HDLC, |
| 1785 | - ((!fifo-> |
| 1786 | - transmode) ? 8 : 10)); |
| 1787 | - queue_control_request(hfc, HFCUSB_INC_RES_F, 2); |
| 1788 | - queue_control_request(hfc, HFCUSB_SCTRL_R, |
| 1789 | - hfc->bch_enables); |
| 1790 | - restore_flags(flags); |
| 1791 | - |
| 1792 | - break; |
| 1793 | - |
| 1794 | - default: |
| 1795 | - printk(KERN_INFO |
| 1796 | - "unknown hfcusb bch_access chan %d 0x%x\n", |
| 1797 | - chan, pr); |
| 1798 | - break; |
| 1799 | - } |
| 1800 | -} /* hfcusb_bch_access */ |
| 1801 | + break; |
| 1802 | + case PH_DEACTIVATE | REQUEST: |
| 1803 | + if(fifo->fifonum==HFCUSB_D_TX) |
| 1804 | + { |
| 1805 | +#ifdef VERBOSE_ISDN_DEBUG |
| 1806 | + printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_DEACTIVATE | REQUEST\n"); |
| 1807 | +#endif |
| 1808 | + printk (KERN_INFO "HFC-USB: ISDN TE device should not deativate...\n"); |
| 1809 | + } |
| 1810 | + else |
| 1811 | + { |
| 1812 | +#ifdef VERBOSE_ISDN_DEBUG |
| 1813 | + printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_DEACTIVATE | REQUEST\n"); |
| 1814 | +#endif |
| 1815 | + set_hfcmode(hfc,(fifo->fifonum==HFCUSB_B1_TX) ? 0 : 1 ,(int)L1_MODE_NULL); |
| 1816 | + fifo->hif->l1l2(fifo->hif,PH_DEACTIVATE | INDICATION, NULL); |
| 1817 | + } |
| 1818 | + break; |
| 1819 | + case PH_DATA | REQUEST: |
| 1820 | + if(fifo->skbuff && fifo->delete_flg) |
| 1821 | + { |
| 1822 | + dev_kfree_skb_any(fifo->skbuff); |
| 1823 | + //printk(KERN_INFO "skbuff=NULL on fifo:%d\n",fifo->fifonum); |
| 1824 | + fifo->skbuff = NULL; |
| 1825 | + fifo->delete_flg=FALSE; |
| 1826 | + } |
| 1827 | + |
| 1828 | + fifo->skbuff=arg; // we have a new buffer |
| 1829 | + |
| 1830 | + //if(fifo->fifonum==HFCUSB_D_TX) printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_DATA | REQUEST\n"); |
| 1831 | + //else printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_DATA | REQUEST\n"); |
| 1832 | + break; |
| 1833 | + default: |
| 1834 | + printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1: unkown state : %#x\n", pr); |
| 1835 | + break; |
| 1836 | + } |
| 1837 | +} |
| 1838 | + |
| 1839 | +// valid configurations |
| 1840 | +#define CNF_4INT3ISO 1 // 4 INT IN, 3 ISO OUT |
| 1841 | +#define CNF_3INT3ISO 2 // 3 INT IN, 3 ISO OUT |
| 1842 | +#define CNF_4ISO3ISO 3 // 4 ISO IN, 3 ISO OUT |
| 1843 | +#define CNF_3ISO3ISO 4 // 3 ISO IN, 3 ISO OUT |
| 1844 | + |
| 1845 | + |
| 1846 | +/* |
| 1847 | + -------------------------------------------------------------------------------------- |
| 1848 | + From here on USB initialization and deactivation related routines are implemented : |
| 1849 | + |
| 1850 | + - hfc_usb_init : |
| 1851 | + is the main Entry Point for the USB Subsystem when the device get plugged |
| 1852 | + in. This function calls usb_register with usb_driver as parameter. |
| 1853 | + Here, further entry points for probing (hfc_usb_probe) and disconnecting |
| 1854 | + the device (hfc_usb_disconnect) are published, as the id_table |
| 1855 | + |
| 1856 | + - hfc_usb_probe |
| 1857 | + this function is called by the usb subsystem, and steps through the alternate |
| 1858 | + settings of the currently plugged in device to detect all Endpoints needed to |
| 1859 | + run an ISDN TA. |
| 1860 | + Needed EndPoints are |
| 1861 | + 3 (+1) IntIn EndPoints (D-in, E-in, B1-in, B2-in, (E-in)) or |
| 1862 | + 3 (+1) Isochron In Endpoints (D-out, B1-out, B2-out) and 3 IsoOut Endpoints |
| 1863 | + The currently used transfer mode of on the Out-Endpoints will be stored in |
| 1864 | + hfc->usb_transfer_mode and is either USB_INT or USB_ISO |
| 1865 | + When a valid alternate setting could be found, the usb_init (see blow) |
| 1866 | + function is called |
| 1867 | + |
| 1868 | + - usb_init |
| 1869 | + Here, the HFC_USB Chip itself gets initialized and the USB framework to send/receive |
| 1870 | + Data to/from the several EndPoints are initialized: |
| 1871 | + The E- and D-Channel Int-In chain gets started |
| 1872 | + The IsoChain for the Iso-Out traffic get started |
| 1873 | + |
| 1874 | + - hfc_usb_disconnect |
| 1875 | + this function is called by the usb subsystem and has to free all resources |
| 1876 | + and stop all usb traffic to allow a proper hotplugging disconnect. |
| 1877 | + |
| 1878 | +*/ |
| 1879 | |
| 1880 | /***************************************************************************/ |
| 1881 | /* usb_init is called once when a new matching device is detected to setup */ |
| 1882 | -/* main parmeters. It registers the driver at the main hisax module. */ |
| 1883 | +/* main parameters. It registers the driver at the main hisax module. */ |
| 1884 | /* on success 0 is returned. */ |
| 1885 | /***************************************************************************/ |
| 1886 | -static int |
| 1887 | -usb_init(hfcusb_data * hfc) |
| 1888 | +static int usb_init(hfcusb_data * hfc) |
| 1889 | { |
| 1890 | usb_fifo *fifo; |
| 1891 | - int i; |
| 1892 | + int i, err; |
| 1893 | u_char b; |
| 1894 | - |
| 1895 | + struct hisax_b_if *p_b_if[2]; |
| 1896 | + |
| 1897 | /* check the chip id */ |
| 1898 | - if ((Read_hfc(hfc, HFCUSB_CHIP_ID, &b) != 1) || |
| 1899 | - (b != HFCUSB_CHIPID)) { |
| 1900 | + printk(KERN_INFO "HFCUSB_CHIP_ID begin\n"); |
| 1901 | + if (read_usb(hfc, HFCUSB_CHIP_ID, &b) != 1) { |
| 1902 | + printk(KERN_INFO "HFC-USB: cannot read chip id\n"); |
| 1903 | + return(1); |
| 1904 | + } |
| 1905 | + printk(KERN_INFO "HFCUSB_CHIP_ID %x\n", b); |
| 1906 | + if (b != HFCUSB_CHIPID) { |
| 1907 | printk(KERN_INFO "HFC-USB: Invalid chip id 0x%02x\n", b); |
| 1908 | - return (1); |
| 1909 | + return(1); |
| 1910 | } |
| 1911 | |
| 1912 | /* first set the needed config, interface and alternate */ |
| 1913 | - usb_set_configuration(hfc->dev, 1); |
| 1914 | - usb_set_interface(hfc->dev, hfc->if_used, hfc->alt_used); |
| 1915 | + printk(KERN_INFO "usb_init 1\n"); |
| 1916 | +// usb_set_configuration(hfc->dev, 1); |
| 1917 | + printk(KERN_INFO "usb_init 2\n"); |
| 1918 | + err = usb_set_interface(hfc->dev, hfc->if_used, hfc->alt_used); |
| 1919 | + printk(KERN_INFO "usb_init usb_set_interface return %d\n", err); |
| 1920 | + /* now we initialize the chip */ |
| 1921 | + write_usb(hfc, HFCUSB_CIRM, 8); // do reset |
| 1922 | + write_usb(hfc, HFCUSB_CIRM, 0x10); // aux = output, reset off |
| 1923 | |
| 1924 | - /* init the led state request */ |
| 1925 | - hfc->led_req = LED_DRIVER; |
| 1926 | + // set USB_SIZE to match the the wMaxPacketSize for INT or BULK transfers |
| 1927 | + write_usb(hfc, HFCUSB_USB_SIZE,(hfc->packet_size/8) | ((hfc->packet_size/8) << 4)); |
| 1928 | |
| 1929 | - /* now we initialise the chip */ |
| 1930 | - Write_hfc(hfc, HFCUSB_CIRM, 0x10); /* aux = output, reset off */ |
| 1931 | - Write_hfc(hfc, HFCUSB_P_DATA, 0); /* leds = off */ |
| 1932 | - Write_hfc(hfc, HFCUSB_USB_SIZE, |
| 1933 | - (hfc->fifos[HFCUSB_B1_TX].usb_maxlen >> 3) | |
| 1934 | - ((hfc->fifos[HFCUSB_B1_RX].usb_maxlen >> 3) << 4)); |
| 1935 | + // set USB_SIZE_I to match the the wMaxPacketSize for ISO transfers |
| 1936 | + write_usb(hfc, HFCUSB_USB_SIZE_I, hfc->iso_packet_size); |
| 1937 | |
| 1938 | /* enable PCM/GCI master mode */ |
| 1939 | - Write_hfc(hfc, HFCUSB_MST_MODE1, 0); /* set default values */ |
| 1940 | - Write_hfc(hfc, HFCUSB_MST_MODE0, 1); /* enable master mode */ |
| 1941 | + write_usb(hfc, HFCUSB_MST_MODE1, 0); /* set default values */ |
| 1942 | + write_usb(hfc, HFCUSB_MST_MODE0, 1); /* enable master mode */ |
| 1943 | |
| 1944 | /* init the fifos */ |
| 1945 | - Write_hfc(hfc, HFCUSB_F_THRES, (HFCUSB_TX_THRESHOLD >> 3) | |
| 1946 | - ((HFCUSB_RX_THRESHOLD >> 3) << 4)); |
| 1947 | + write_usb(hfc, HFCUSB_F_THRES, (HFCUSB_TX_THRESHOLD/8) |((HFCUSB_RX_THRESHOLD/8) << 4)); |
| 1948 | |
| 1949 | - for (i = 0, fifo = hfc->fifos + i; i < HFCUSB_NUM_FIFOS; |
| 1950 | - i++, fifo++) { |
| 1951 | - Write_hfc(hfc, HFCUSB_FIFO, i); /* select the desired fifo */ |
| 1952 | - |
| 1953 | - fifo->transmode = 0; /* hdlc mode selected */ |
| 1954 | - fifo->buff = NULL; /* init buffer pointer */ |
| 1955 | - fifo->max_size = |
| 1956 | - (i <= HFCUSB_B2_RX) ? MAX_BCH_SIZE : MAX_DFRAME_LEN; |
| 1957 | - Write_hfc(hfc, HFCUSB_HDLC_PAR, ((i <= HFCUSB_B2_RX) ? 0 : 2)); /* data length */ |
| 1958 | - Write_hfc(hfc, HFCUSB_CON_HDLC, ((i & 1) ? 0x08 : 0x09)); /* rx hdlc, tx fill 1 */ |
| 1959 | - Write_hfc(hfc, HFCUSB_INC_RES_F, 2); /* reset the fifo */ |
| 1960 | - } |
| 1961 | - |
| 1962 | - Write_hfc(hfc, HFCUSB_CLKDEL, 0x0f); /* clock delay value */ |
| 1963 | - Write_hfc(hfc, HFCUSB_STATES, 3 | 0x10); /* set deactivated mode */ |
| 1964 | - Write_hfc(hfc, HFCUSB_STATES, 3); /* enable state machine */ |
| 1965 | + fifo = hfc->fifos; |
| 1966 | + for(i = 0; i < HFCUSB_NUM_FIFOS; i++) |
| 1967 | + { |
| 1968 | + write_usb(hfc, HFCUSB_FIFO, i); /* select the desired fifo */ |
| 1969 | + fifo[i].skbuff = NULL; /* init buffer pointer */ |
| 1970 | + fifo[i].max_size = (i <= HFCUSB_B2_RX) ? MAX_BCH_SIZE : MAX_DFRAME_LEN; |
| 1971 | + fifo[i].last_urblen=0; |
| 1972 | + write_usb(hfc, HFCUSB_HDLC_PAR, ((i <= HFCUSB_B2_RX) ? 0 : 2)); // set 2 bit for D- & E-channel |
| 1973 | + write_usb(hfc, HFCUSB_CON_HDLC, ((i==HFCUSB_D_TX) ? 0x09 : 0x08)); // rx hdlc, enable IFF for D-channel |
| 1974 | + write_usb(hfc, HFCUSB_INC_RES_F, 2); /* reset the fifo */ |
| 1975 | + } |
| 1976 | |
| 1977 | - Write_hfc(hfc, HFCUSB_SCTRL_R, 0); /* disable both B receivers */ |
| 1978 | - Write_hfc(hfc, HFCUSB_SCTRL, 0x40); /* disable B transmitters + cap mode */ |
| 1979 | + write_usb(hfc, HFCUSB_CLKDEL, 0x0f); /* clock delay value */ |
| 1980 | + write_usb(hfc, HFCUSB_STATES, 3 | 0x10); /* set deactivated mode */ |
| 1981 | + write_usb(hfc, HFCUSB_STATES, 3); /* enable state machine */ |
| 1982 | + |
| 1983 | + write_usb(hfc, HFCUSB_SCTRL_R, 0); /* disable both B receivers */ |
| 1984 | + write_usb(hfc, HFCUSB_SCTRL, 0x40); /* disable B transmitters + capacitive mode */ |
| 1985 | + |
| 1986 | + // set both B-channel to not connected |
| 1987 | + hfc->b_mode[0]=L1_MODE_NULL; |
| 1988 | + hfc->b_mode[1]=L1_MODE_NULL; |
| 1989 | + |
| 1990 | + hfc->l1_activated=FALSE; |
| 1991 | + hfc->led_state=0; |
| 1992 | + hfc->led_new_data=0; |
| 1993 | |
| 1994 | - /* init the l1 timer */ |
| 1995 | + /* init the t3 timer */ |
| 1996 | init_timer(&hfc->t3_timer); |
| 1997 | hfc->t3_timer.data = (long) hfc; |
| 1998 | - hfc->t3_timer.function = (void *) l1_timer_expire; |
| 1999 | + hfc->t3_timer.function = (void *) l1_timer_expire_t3; |
| 2000 | + /* init the t4 timer */ |
| 2001 | + init_timer(&hfc->t4_timer); |
| 2002 | hfc->t4_timer.data = (long) hfc; |
| 2003 | - hfc->t4_timer.function = (void *) l1_timer_expire; |
| 2004 | - hfc->l1_tq.routine = (void *) (void *) usb_l1d_bh; |
| 2005 | - hfc->l1_tq.sync = 0; |
| 2006 | - hfc->l1_tq.data = hfc; |
| 2007 | - |
| 2008 | - /* init the background control machinery */ |
| 2009 | - hfc->ctrl_read.requesttype = 0xc0; |
| 2010 | - hfc->ctrl_read.request = 1; |
| 2011 | - hfc->ctrl_read.length = 1; |
| 2012 | - hfc->ctrl_write.requesttype = 0x40; |
| 2013 | - hfc->ctrl_write.request = 0; |
| 2014 | - hfc->ctrl_write.length = 0; |
| 2015 | - FILL_CONTROL_URB(&hfc->ctrl_urb, hfc->dev, hfc->ctrl_out_pipe, |
| 2016 | - (u_char *) & hfc->ctrl_write, NULL, 0, |
| 2017 | - ctrl_complete, hfc); |
| 2018 | - |
| 2019 | - /* init the TX-urbs */ |
| 2020 | - fifo = hfc->fifos + HFCUSB_D_TX; |
| 2021 | - FILL_BULK_URB(&fifo->urb, hfc->dev, fifo->pipe, |
| 2022 | - (u_char *) fifo->buffer, 0, tx_complete, fifo); |
| 2023 | - fifo = hfc->fifos + HFCUSB_B1_TX; |
| 2024 | - FILL_BULK_URB(&fifo->urb, hfc->dev, fifo->pipe, |
| 2025 | - (u_char *) fifo->buffer, 0, tx_complete, fifo); |
| 2026 | - fifo = hfc->fifos + HFCUSB_B2_TX; |
| 2027 | - FILL_BULK_URB(&fifo->urb, hfc->dev, fifo->pipe, |
| 2028 | - (u_char *) fifo->buffer, 0, tx_complete, fifo); |
| 2029 | - |
| 2030 | - /* init the E-buffer */ |
| 2031 | - skb_queue_head_init(&hfc->regd.erq); |
| 2032 | - |
| 2033 | - /* now register ourself at hisax */ |
| 2034 | - hfc->regd.version = HISAX_LOAD_VERSION; /* set our version */ |
| 2035 | - hfc->regd.cmd = HISAX_LOAD_REGISTER; /* register command */ |
| 2036 | - hfc->regd.argl1 = (void *) hfc; /* argument for our local routine */ |
| 2037 | - hfc->regd.dch_l2l1 = hfcusb_l1_access; |
| 2038 | - hfc->regd.bch_l2l1 = hfcusb_bch_access; |
| 2039 | - hfc->regd.drvname = "hfc_usb"; |
| 2040 | - if (hisax_register_hfcusb(&hfc->regd)) { |
| 2041 | - printk(KERN_INFO "HFC-USB failed to register at hisax\n"); |
| 2042 | - Write_hfc(hfc, HFCUSB_CIRM, 0x08); /* aux = input, reset on */ |
| 2043 | - return (1); |
| 2044 | - } |
| 2045 | - |
| 2046 | - /* startup the D- and E-channel fifos */ |
| 2047 | - start_rx_fifo(hfc->fifos + HFCUSB_D_RX); /* D-fifo */ |
| 2048 | - if (hfc->fifos[HFCUSB_PCM_RX].pipe) |
| 2049 | - start_rx_fifo(hfc->fifos + HFCUSB_PCM_RX); /* E-fifo */ |
| 2050 | + hfc->t4_timer.function = (void *) l1_timer_expire_t4; |
| 2051 | + /* init the led timer */ |
| 2052 | + init_timer(&hfc->led_timer); |
| 2053 | + hfc->led_timer.data = (long) hfc; |
| 2054 | + hfc->led_timer.function = (void *) led_timer; |
| 2055 | + // trigger 4 hz led timer |
| 2056 | + hfc->led_timer.expires = jiffies + (LED_TIME * HZ) / 1000; |
| 2057 | + if(!timer_pending(&hfc->led_timer)) add_timer(&hfc->led_timer); |
| 2058 | + |
| 2059 | + // init the background machinery for control requests |
| 2060 | + hfc->ctrl_read.bRequestType = 0xc0; |
| 2061 | + hfc->ctrl_read.bRequest = 1; |
| 2062 | + hfc->ctrl_read.wLength = 1; |
| 2063 | + hfc->ctrl_write.bRequestType = 0x40; |
| 2064 | + hfc->ctrl_write.bRequest = 0; |
| 2065 | + hfc->ctrl_write.wLength = 0; |
| 2066 | + usb_fill_control_urb(hfc->ctrl_urb, hfc->dev, hfc->ctrl_out_pipe,(u_char *) & hfc->ctrl_write, NULL, 0, ctrl_complete, hfc); |
| 2067 | + |
| 2068 | + /* Init All Fifos */ |
| 2069 | + for(i = 0; i < HFCUSB_NUM_FIFOS; i++) |
| 2070 | + { |
| 2071 | + hfc->fifos[i].iso[0].purb = NULL; |
| 2072 | + hfc->fifos[i].iso[1].purb = NULL; |
| 2073 | + hfc->fifos[i].active = 0; |
| 2074 | + } |
| 2075 | + |
| 2076 | + // register like Germaschewski : |
| 2077 | + hfc->d_if.owner = THIS_MODULE; |
| 2078 | + hfc->d_if.ifc.priv = &hfc->fifos[HFCUSB_D_TX]; |
| 2079 | + hfc->d_if.ifc.l2l1 = hfc_usb_l2l1; |
| 2080 | + |
| 2081 | + for (i=0; i<2; i++) |
| 2082 | + { |
| 2083 | + hfc->b_if[i].ifc.priv = &hfc->fifos[HFCUSB_B1_TX+i*2]; |
| 2084 | + hfc->b_if[i].ifc.l2l1 = hfc_usb_l2l1; |
| 2085 | + p_b_if[i] = &hfc->b_if[i]; |
| 2086 | + } |
| 2087 | + |
| 2088 | + hfc->protocol = 2; /* default EURO ISDN, should be a module_param */ |
| 2089 | + hisax_register(&hfc->d_if, p_b_if, "hfc_usb", hfc->protocol); |
| 2090 | + |
| 2091 | + for (i=0; i<4; i++) |
| 2092 | + hfc->fifos[i].hif=&p_b_if[i/2]->ifc; |
| 2093 | + for (i=4; i<8; i++) |
| 2094 | + hfc->fifos[i].hif=&hfc->d_if.ifc; |
| 2095 | + |
| 2096 | + // 3 (+1) INT IN + 3 ISO OUT |
| 2097 | + if(hfc->cfg_used == CNF_3INT3ISO || hfc->cfg_used == CNF_4INT3ISO) |
| 2098 | + { |
| 2099 | + start_int_fifo(hfc->fifos + HFCUSB_D_RX); // Int IN D-fifo |
| 2100 | + if(hfc->fifos[HFCUSB_PCM_RX].pipe) start_int_fifo(hfc->fifos + HFCUSB_PCM_RX); // E-fifo |
| 2101 | + start_int_fifo(hfc->fifos + HFCUSB_B1_RX); // Int IN B1-fifo |
| 2102 | + start_int_fifo(hfc->fifos + HFCUSB_B2_RX); // Int IN B2-fifo |
| 2103 | + } |
| 2104 | + |
| 2105 | + // 3 (+1) ISO IN + 3 ISO OUT |
| 2106 | + if(hfc->cfg_used==CNF_3ISO3ISO || hfc->cfg_used==CNF_4ISO3ISO) |
| 2107 | + { |
| 2108 | + start_isoc_chain(hfc->fifos + HFCUSB_D_RX, ISOC_PACKETS_D, rx_iso_complete,16); |
| 2109 | + if(hfc->fifos[HFCUSB_PCM_RX].pipe) start_isoc_chain(hfc->fifos + HFCUSB_PCM_RX, ISOC_PACKETS_D, rx_iso_complete,16); |
| 2110 | + start_isoc_chain(hfc->fifos + HFCUSB_B1_RX, ISOC_PACKETS_B, rx_iso_complete,16); |
| 2111 | + start_isoc_chain(hfc->fifos + HFCUSB_B2_RX, ISOC_PACKETS_B, rx_iso_complete,16); |
| 2112 | + } |
| 2113 | + |
| 2114 | + start_isoc_chain(hfc->fifos + HFCUSB_D_TX, ISOC_PACKETS_D, tx_iso_complete,1); |
| 2115 | + start_isoc_chain(hfc->fifos + HFCUSB_B1_TX, ISOC_PACKETS_B, tx_iso_complete,1); |
| 2116 | + start_isoc_chain(hfc->fifos + HFCUSB_B2_TX, ISOC_PACKETS_B, tx_iso_complete,1); |
| 2117 | + |
| 2118 | + handle_led(hfc,LED_POWER_ON); |
| 2119 | + |
| 2120 | + return(0); |
| 2121 | +} /* usb_init */ |
| 2122 | + |
| 2123 | + |
| 2124 | +/****************************************/ |
| 2125 | +/* data defining the devices to be used */ |
| 2126 | +/****************************************/ |
| 2127 | +// static __devinitdata const struct usb_device_id hfc_usb_idtab[3] = { |
| 2128 | +static struct usb_device_id hfc_usb_idtab[] = { |
| 2129 | + {USB_DEVICE(0x7b0, 0x0007)}, /* Billion USB TA 2 */ |
| 2130 | + {USB_DEVICE(0x742, 0x2008)}, /* Stollmann USB TA */ |
| 2131 | + {USB_DEVICE(0x959, 0x2bd0)}, /* Colognechip USB eval TA */ |
| 2132 | + {USB_DEVICE(0x8e3, 0x0301)}, /* OliTec ISDN USB */ |
| 2133 | + {USB_DEVICE(0x675, 0x1688)}, /* DrayTec ISDN USB */ |
| 2134 | + {USB_DEVICE(0x7fa, 0x0846)}, /* Bewan ISDN USB TA */ |
| 2135 | + {} /* end with an all-zeroes entry */ |
| 2136 | +}; |
| 2137 | + |
| 2138 | +MODULE_AUTHOR("Peter Sprenger (sprenger@moving-byters.de)/Martin Bachem (info@colognechip.com)"); |
| 2139 | +MODULE_DESCRIPTION("HFC I4L USB driver"); |
| 2140 | +MODULE_DEVICE_TABLE(usb, hfc_usb_idtab); |
| 2141 | +MODULE_LICENSE("GPL"); |
| 2142 | + |
| 2143 | +#define EP_NUL 1 // Endpoint at this position not allowed |
| 2144 | +#define EP_NOP 2 // all type of endpoints allowed at this position |
| 2145 | +#define EP_ISO 3 // Isochron endpoint mandatory at this position |
| 2146 | +#define EP_BLK 4 // Bulk endpoint mandatory at this position |
| 2147 | +#define EP_INT 5 // Interrupt endpoint mandatory at this position |
| 2148 | + |
| 2149 | +// this array represents all endpoints possible in the HCF-USB |
| 2150 | +// the last 2 entries are the configuration number and the minimum interval for Interrupt endpoints |
| 2151 | +int validconf[][18]= |
| 2152 | +{ |
| 2153 | + // INT in, ISO out config |
| 2154 | + {EP_NUL,EP_INT,EP_NUL,EP_INT,EP_NUL,EP_INT,EP_NOP,EP_INT,EP_ISO,EP_NUL,EP_ISO,EP_NUL,EP_ISO,EP_NUL,EP_NUL,EP_NUL,CNF_4INT3ISO,2}, |
| 2155 | + {EP_NUL,EP_INT,EP_NUL,EP_INT,EP_NUL,EP_INT,EP_NUL,EP_NUL,EP_ISO,EP_NUL,EP_ISO,EP_NUL,EP_ISO,EP_NUL,EP_NUL,EP_NUL,CNF_3INT3ISO,2}, |
| 2156 | + // ISO in, ISO out config |
| 2157 | + {EP_NUL,EP_NUL,EP_NUL,EP_NUL,EP_NUL,EP_NUL,EP_NUL,EP_NUL,EP_ISO,EP_ISO,EP_ISO,EP_ISO,EP_ISO,EP_ISO,EP_NOP,EP_ISO,CNF_4ISO3ISO,2}, |
| 2158 | + {EP_NUL,EP_NUL,EP_NUL,EP_NUL,EP_NUL,EP_NUL,EP_NUL,EP_NUL,EP_ISO,EP_ISO,EP_ISO,EP_ISO,EP_ISO,EP_ISO,EP_NUL,EP_NUL,CNF_3ISO3ISO,2}, |
| 2159 | + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} // EOL element |
| 2160 | +}; |
| 2161 | + |
| 2162 | +// string description of chosen config |
| 2163 | +char *conf_str[]= |
| 2164 | +{ |
| 2165 | + "4 Interrupt IN + 3 Isochron OUT", |
| 2166 | + "3 Interrupt IN + 3 Isochron OUT", |
| 2167 | + "4 Isochron IN + 3 Isochron OUT", |
| 2168 | + "3 Isochron IN + 3 Isochron OUT" |
| 2169 | +}; |
| 2170 | |
| 2171 | - return (0); |
| 2172 | -} /* usb_init */ |
| 2173 | |
| 2174 | /*************************************************/ |
| 2175 | /* function called to probe a new plugged device */ |
| 2176 | /*************************************************/ |
| 2177 | -static void * |
| 2178 | -hfc_usb_probe(struct usb_device *dev, unsigned int interface |
| 2179 | -#ifdef COMPAT_HAS_USB_IDTAB |
| 2180 | - , const struct usb_device_id *id_table) |
| 2181 | -#else |
| 2182 | - ) |
| 2183 | -#endif |
| 2184 | +//static int hfc_usb_probe(struct usb_interface *intf, const struct usb_device_id *id) |
| 2185 | +static void* hfc_usb_probe(struct usb_device *dev, unsigned int ifnum, const struct usb_device_id *id) |
| 2186 | { |
| 2187 | + //struct usb_device *dev= interface_to_usbdev(intf); |
| 2188 | + struct usb_interface* intf = dev->actconfig->interface + ifnum; |
| 2189 | hfcusb_data *context; |
| 2190 | - struct usb_interface *ifp = dev->actconfig->interface + interface; |
| 2191 | - struct usb_interface_descriptor *ifdp = |
| 2192 | - ifp->altsetting + ifp->act_altsetting; |
| 2193 | - struct usb_endpoint_descriptor *epd; |
| 2194 | - int i, idx, ep_msk; |
| 2195 | - |
| 2196 | -#ifdef COMPAT_HAS_USB_IDTAB |
| 2197 | - if (id_table && (dev->descriptor.idVendor == id_table->idVendor) && |
| 2198 | - (dev->descriptor.idProduct == id_table->idProduct) && |
| 2199 | -#else |
| 2200 | - if ((((dev->descriptor.idVendor == 0x959) && |
| 2201 | - (dev->descriptor.idProduct == 0x2bd0)) || |
| 2202 | - ((dev->descriptor.idVendor == 0x7b0) && |
| 2203 | - (dev->descriptor.idProduct == 0x0006))) && |
| 2204 | -#endif |
| 2205 | - (ifdp->bNumEndpoints >= 6) && (ifdp->bNumEndpoints <= 16)) { |
| 2206 | - if (!(context = kmalloc(sizeof(hfcusb_data), GFP_KERNEL))) { |
| 2207 | - return (NULL); /* got no mem */ |
| 2208 | - }; |
| 2209 | - memset(context, 0, sizeof(hfcusb_data)); /* clear the structure */ |
| 2210 | - i = ifdp->bNumEndpoints; /* get number of endpoints */ |
| 2211 | - ep_msk = 0; /* none found */ |
| 2212 | - epd = ifdp->endpoint; /* first endpoint descriptor */ |
| 2213 | - while (i-- && ((ep_msk & 0xcf) != 0xcf)) { |
| 2214 | - |
| 2215 | - idx = (((epd->bEndpointAddress & 0x7f) - 1) << 1); /* get endpoint base */ |
| 2216 | - if (idx < 7) { |
| 2217 | - switch (epd->bmAttributes) { |
| 2218 | - case USB_ENDPOINT_XFER_INT: |
| 2219 | - if (! |
| 2220 | - (epd-> |
| 2221 | - bEndpointAddress & |
| 2222 | - 0x80)) |
| 2223 | - break; /* only interrupt in allowed */ |
| 2224 | - idx++; /* input index is odd */ |
| 2225 | - context->fifos[idx].pipe = |
| 2226 | - usb_rcvintpipe(dev, |
| 2227 | - epd-> |
| 2228 | - bEndpointAddress); |
| 2229 | - break; |
| 2230 | - |
| 2231 | - case USB_ENDPOINT_XFER_BULK: |
| 2232 | - if (epd-> |
| 2233 | - bEndpointAddress & |
| 2234 | - 0x80) |
| 2235 | - break; /* only bulk out allowed */ |
| 2236 | - context->fifos[idx].pipe = |
| 2237 | - usb_sndbulkpipe(dev, |
| 2238 | - epd-> |
| 2239 | - bEndpointAddress); |
| 2240 | - break; |
| 2241 | - default: |
| 2242 | - context->fifos[idx].pipe = 0; /* reset data */ |
| 2243 | - } /* switch attribute */ |
| 2244 | - |
| 2245 | - if (context->fifos[idx].pipe) { |
| 2246 | - context->fifos[idx].fifonum = idx; |
| 2247 | - context->fifos[idx].fifo_mask = |
| 2248 | - 1 << idx; |
| 2249 | - context->fifos[idx].hfc = context; |
| 2250 | - context->fifos[idx].usb_maxlen = |
| 2251 | - epd->wMaxPacketSize; |
| 2252 | - context->fifos[idx].intervall = |
| 2253 | - epd->bInterval; |
| 2254 | - ep_msk |= (1 << idx); |
| 2255 | - } else |
| 2256 | - ep_msk &= ~(1 << idx); |
| 2257 | - } /* idx < 7 */ |
| 2258 | - epd++; |
| 2259 | - } |
| 2260 | + //struct usb_host_interface *iface = intf->cur_altsetting; |
| 2261 | + //struct usb_host_interface *iface_used = NULL; |
| 2262 | + //struct usb_host_endpoint *ep; |
| 2263 | + struct usb_endpoint_descriptor* ep; |
| 2264 | + //int ifnum = iface->desc.bInterfaceNumber; |
| 2265 | + struct usb_interface_descriptor* intfdesc = intf->altsetting + intf->act_altsetting; |
| 2266 | + struct usb_interface_descriptor* intfdesc_used = NULL; |
| 2267 | + int i, idx, alt_idx, probe_alt_setting, vend_idx, cfg_used, *vcf, attr, cfg_found, cidx, ep_addr; |
| 2268 | + int cmptbl[16],small_match,iso_packet_size,packet_size,alt_used=0; |
| 2269 | + |
| 2270 | +// usb_show_device(dev); |
| 2271 | +// usb_show_device_descriptor(&dev->descriptor); |
| 2272 | +// usb_show_interface_descriptor(&iface->desc); |
| 2273 | + vend_idx=0xffff; |
| 2274 | + for(i=0;vdata[i].vendor;i++) |
| 2275 | + { |
| 2276 | + if(dev->descriptor.idVendor==vdata[i].vendor && dev->descriptor.idProduct==vdata[i].prod_id) vend_idx=i; |
| 2277 | + } |
| 2278 | + |
| 2279 | |
| 2280 | - if ((ep_msk & 0x3f) != 0x3f) { |
| 2281 | - kfree(context); |
| 2282 | - return (NULL); |
| 2283 | - } |
| 2284 | - MOD_INC_USE_COUNT; /* lock our module */ |
| 2285 | - context->dev = dev; /* save device */ |
| 2286 | - context->if_used = interface; /* save used interface */ |
| 2287 | - context->alt_used = ifp->act_altsetting; /* and alternate config */ |
| 2288 | - context->ctrl_paksize = dev->descriptor.bMaxPacketSize0; /* control size */ |
| 2289 | - |
| 2290 | - /* create the control pipes needed for register access */ |
| 2291 | - context->ctrl_in_pipe = usb_rcvctrlpipe(context->dev, 0); |
| 2292 | - context->ctrl_out_pipe = usb_sndctrlpipe(context->dev, 0); |
| 2293 | - |
| 2294 | - /* init the chip and register the driver */ |
| 2295 | - if (usb_init(context)) { |
| 2296 | - kfree(context); |
| 2297 | - MOD_DEC_USE_COUNT; |
| 2298 | - return (NULL); |
| 2299 | - } |
| 2300 | +#ifdef VERBOSE_USB_DEBUG |
| 2301 | + printk(KERN_INFO "HFC-USB: probing interface(%d) actalt(%d)\n", |
| 2302 | + ifnum, intfdesc->bAlternateSetting); |
| 2303 | + /* printk(KERN_INFO "HFC-USB: probing interface(%d) actalt(%d) minor(%d)\n", |
| 2304 | + ifnum, intfdesc->bAlternateSetting, intf->driver->minor); */ |
| 2305 | +#endif |
| 2306 | |
| 2307 | - printk(KERN_INFO |
| 2308 | - "HFC-USB: New device if=%d alt=%d registered\n", |
| 2309 | - context->if_used, context->alt_used); |
| 2310 | - return (context); |
| 2311 | - } |
| 2312 | + if (vend_idx != 0xffff) { |
| 2313 | +#ifdef VERBOSE_USB_DEBUG |
| 2314 | + printk(KERN_INFO "HFC-USB: found vendor idx:%d name:%s\n",vend_idx,vdata[vend_idx].vend_name); |
| 2315 | +#endif |
| 2316 | + /* if vendor and product ID is OK, start probing a matching alternate setting ... */ |
| 2317 | + alt_idx = 0; |
| 2318 | + small_match=0xffff; |
| 2319 | + // default settings |
| 2320 | + iso_packet_size=16; |
| 2321 | + packet_size=64; |
| 2322 | + |
| 2323 | + while (alt_idx < intf->num_altsetting) { |
| 2324 | + //iface = intf->altsetting + alt_idx; |
| 2325 | + intfdesc = intf->altsetting + alt_idx; |
| 2326 | + probe_alt_setting = intfdesc->bAlternateSetting; |
| 2327 | + cfg_used=0; |
| 2328 | |
| 2329 | - return (NULL); /* no matching entry */ |
| 2330 | -} /* hfc_usb_probe */ |
| 2331 | +#ifdef VERBOSE_USB_DEBUG |
| 2332 | + printk(KERN_INFO "HFC-USB: test alt_setting %d\n", probe_alt_setting); |
| 2333 | +#endif |
| 2334 | + // check for config EOL element |
| 2335 | + while (validconf[cfg_used][0]) { |
| 2336 | + cfg_found=TRUE; |
| 2337 | + vcf=validconf[cfg_used]; |
| 2338 | + ep = intfdesc->endpoint; /* first endpoint descriptor */ |
| 2339 | + |
| 2340 | +#ifdef VERBOSE_USB_DEBUG |
| 2341 | + printk(KERN_INFO "HFC-USB: (if=%d alt=%d cfg_used=%d)\n", |
| 2342 | + ifnum, probe_alt_setting, cfg_used); |
| 2343 | +#endif |
| 2344 | + // copy table |
| 2345 | + memcpy(cmptbl,vcf,16*sizeof(int)); |
| 2346 | + |
| 2347 | + // check for all endpoints in this alternate setting |
| 2348 | + for (i=0; i < intfdesc->bNumEndpoints; i++) { |
| 2349 | + ep_addr = ep->bEndpointAddress; |
| 2350 | + idx = ((ep_addr & 0x7f)-1)*2; /* get endpoint base */ |
| 2351 | + if (ep_addr & 0x80) |
| 2352 | + idx++; |
| 2353 | + attr = ep->bmAttributes; |
| 2354 | + |
| 2355 | + if (cmptbl[idx] == EP_NUL) { |
| 2356 | + printk(KERN_INFO "HFC-USB: cfg_found=FALSE in idx:%d attr:%d cmptbl[%d]:%d\n", |
| 2357 | + idx, attr, idx, cmptbl[idx]); |
| 2358 | + cfg_found = FALSE; |
| 2359 | + } |
| 2360 | + |
| 2361 | + if (attr == USB_ENDPOINT_XFER_INT && cmptbl[idx] == EP_INT) |
| 2362 | + cmptbl[idx] = EP_NUL; |
| 2363 | + if (attr == USB_ENDPOINT_XFER_BULK && cmptbl[idx] == EP_BLK) |
| 2364 | + cmptbl[idx] = EP_NUL; |
| 2365 | + if (attr == USB_ENDPOINT_XFER_ISOC && cmptbl[idx] == EP_ISO) |
| 2366 | + cmptbl[idx] = EP_NUL; |
| 2367 | + |
| 2368 | + // check if all INT endpoints match minimum interval |
| 2369 | + if (attr == USB_ENDPOINT_XFER_INT && ep->bInterval < vcf[17]) { |
| 2370 | +#ifdef VERBOSE_USB_DEBUG |
| 2371 | + if (cfg_found) |
| 2372 | + printk(KERN_INFO "HFC-USB: Interrupt Endpoint interval < %d found - skipping config\n", |
| 2373 | + vcf[17]); |
| 2374 | +#endif |
| 2375 | + cfg_found = FALSE; |
| 2376 | + } |
| 2377 | + |
| 2378 | + ep++; |
| 2379 | + } |
| 2380 | + |
| 2381 | + for (i = 0; i < 16; i++) { |
| 2382 | + // printk(KERN_INFO "HFC-USB: cmptbl[%d]:%d\n", i, cmptbl[i]); |
| 2383 | + |
| 2384 | + // all entries must be EP_NOP or EP_NUL for a valid config |
| 2385 | + if (cmptbl[i] != EP_NOP && cmptbl[i] != EP_NUL) |
| 2386 | + cfg_found = FALSE; |
| 2387 | + } |
| 2388 | + |
| 2389 | + // we check for smallest match, to provide configuration priority |
| 2390 | + // configurations with smaller index have higher priority |
| 2391 | + if (cfg_found) { |
| 2392 | + if (cfg_used < small_match) { |
| 2393 | + small_match = cfg_used; |
| 2394 | + alt_used = probe_alt_setting; |
| 2395 | + //iface_used = iface; |
| 2396 | + intfdesc_used = intfdesc; |
| 2397 | + } |
| 2398 | +#ifdef VERBOSE_USB_DEBUG |
| 2399 | + printk(KERN_INFO "HFC-USB: small_match=%x %x\n", small_match, alt_used); |
| 2400 | +#endif |
| 2401 | + } |
| 2402 | + |
| 2403 | + cfg_used++; |
| 2404 | + } |
| 2405 | + |
| 2406 | + alt_idx++; |
| 2407 | + } /* (alt_idx < intf->num_altsetting) */ |
| 2408 | +#ifdef VERBOSE_USB_DEBUG |
| 2409 | + printk(KERN_INFO "HFC-USB: final small_match=%x alt_used=%x\n",small_match, alt_used); |
| 2410 | +#endif |
| 2411 | + // yiipiee, we found a valid config |
| 2412 | + if (small_match != 0xffff) { |
| 2413 | + //iface = iface_used; |
| 2414 | + intfdesc = intfdesc_used; |
| 2415 | + |
| 2416 | + if (!(context = kmalloc(sizeof(hfcusb_data), GFP_KERNEL))) |
| 2417 | + return(NULL); /* got no mem */ |
| 2418 | + memset(context, 0, sizeof(hfcusb_data)); /* clear the structure */ |
| 2419 | + |
| 2420 | + ep = intfdesc->endpoint; /* first endpoint descriptor */ |
| 2421 | + vcf = validconf[small_match]; |
| 2422 | + |
| 2423 | + for (i = 0; i < intfdesc->bNumEndpoints; i++) { |
| 2424 | + ep_addr = ep->bEndpointAddress; |
| 2425 | + idx = ((ep_addr & 0x7f)-1)*2; /* get endpoint base */ |
| 2426 | + if (ep_addr & 0x80) |
| 2427 | + idx++; |
| 2428 | + cidx = idx & 7; |
| 2429 | + attr = ep->bmAttributes; |
| 2430 | + |
| 2431 | + // only initialize used endpoints |
| 2432 | + if (vcf[idx] != EP_NOP && vcf[idx] != EP_NUL) { |
| 2433 | + switch (attr) { |
| 2434 | + case USB_ENDPOINT_XFER_INT: |
| 2435 | + context->fifos[cidx].pipe = usb_rcvintpipe(dev, ep->bEndpointAddress); |
| 2436 | + context->fifos[cidx].usb_transfer_mode = USB_INT; |
| 2437 | + packet_size = ep->wMaxPacketSize; // remember max packet size |
| 2438 | +#ifdef VERBOSE_USB_DEBUG |
| 2439 | + printk (KERN_INFO "HFC-USB: Interrupt-In Endpoint found %d ms(idx:%d cidx:%d)!\n", |
| 2440 | + ep->bInterval, idx, cidx); |
| 2441 | +#endif |
| 2442 | + break; |
| 2443 | + case USB_ENDPOINT_XFER_BULK: |
| 2444 | + if (ep_addr & 0x80) |
| 2445 | + context->fifos[cidx].pipe = usb_rcvbulkpipe(dev, ep->bEndpointAddress); |
| 2446 | + else |
| 2447 | + context->fifos[cidx].pipe = usb_sndbulkpipe(dev, ep->bEndpointAddress); |
| 2448 | + context->fifos[cidx].usb_transfer_mode = USB_BULK; |
| 2449 | + packet_size = ep->wMaxPacketSize; // remember max packet size |
| 2450 | +#ifdef VERBOSE_USB_DEBUG |
| 2451 | + printk (KERN_INFO "HFC-USB: Bulk Endpoint found (idx:%d cidx:%d)!\n", |
| 2452 | + idx, cidx); |
| 2453 | +#endif |
| 2454 | + break; |
| 2455 | + case USB_ENDPOINT_XFER_ISOC: |
| 2456 | + if (ep_addr & 0x80) |
| 2457 | + context->fifos[cidx].pipe = usb_rcvisocpipe(dev, ep->bEndpointAddress); |
| 2458 | + else |
| 2459 | + context->fifos[cidx].pipe = usb_sndisocpipe(dev, ep->bEndpointAddress); |
| 2460 | + context->fifos[cidx].usb_transfer_mode = USB_ISOC; |
| 2461 | + iso_packet_size = ep->wMaxPacketSize; // remember max packet size |
| 2462 | +#ifdef VERBOSE_USB_DEBUG |
| 2463 | + printk (KERN_INFO "HFC-USB: ISO Endpoint found (idx:%d cidx:%d)!\n", |
| 2464 | + idx, cidx); |
| 2465 | +#endif |
| 2466 | + break; |
| 2467 | + default: |
| 2468 | + context->fifos[cidx].pipe = 0; /* reset data */ |
| 2469 | + } /* switch attribute */ |
| 2470 | + |
| 2471 | + if (context->fifos[cidx].pipe) { |
| 2472 | + context->fifos[cidx].fifonum = cidx; |
| 2473 | + context->fifos[cidx].hfc = context; |
| 2474 | + context->fifos[cidx].usb_packet_maxlen = ep->wMaxPacketSize; |
| 2475 | + context->fifos[cidx].intervall = ep->bInterval; |
| 2476 | + context->fifos[cidx].skbuff = NULL; |
| 2477 | +#ifdef VERBOSE_USB_DEBUG |
| 2478 | + printk (KERN_INFO "HFC-USB: fifo%d pktlen %d interval %d\n", |
| 2479 | + context->fifos[cidx].fifonum, |
| 2480 | + context->fifos[cidx].usb_packet_maxlen, |
| 2481 | + context->fifos[cidx].intervall); |
| 2482 | +#endif |
| 2483 | + } |
| 2484 | + } |
| 2485 | + |
| 2486 | + ep++; |
| 2487 | + } |
| 2488 | + |
| 2489 | + // now share our luck |
| 2490 | + context->dev = dev; /* save device */ |
| 2491 | + context->if_used = ifnum; /* save used interface */ |
| 2492 | + context->alt_used = alt_used; /* and alternate config */ |
| 2493 | + context->ctrl_paksize = dev->descriptor.bMaxPacketSize0; /* control size */ |
| 2494 | + context->cfg_used=vcf[16]; // store used config |
| 2495 | + context->vend_idx=vend_idx; // store found vendor |
| 2496 | + context->packet_size=packet_size; |
| 2497 | + context->iso_packet_size=iso_packet_size; |
| 2498 | + |
| 2499 | + /* create the control pipes needed for register access */ |
| 2500 | + context->ctrl_in_pipe = usb_rcvctrlpipe(context->dev, 0); |
| 2501 | + context->ctrl_out_pipe = usb_sndctrlpipe(context->dev, 0); |
| 2502 | + context->ctrl_urb = usb_alloc_urb(0); |
| 2503 | + |
| 2504 | + printk(KERN_INFO "HFC-USB: detected \"%s\" configuration: %s (if=%d alt=%d)\n", |
| 2505 | + vdata[vend_idx].vend_name, conf_str[small_match], context->if_used, context->alt_used); |
| 2506 | + |
| 2507 | + /* init the chip and register the driver */ |
| 2508 | + if (usb_init(context)) |
| 2509 | + { |
| 2510 | + if (context->ctrl_urb) { |
| 2511 | + usb_unlink_urb(context->ctrl_urb); |
| 2512 | + usb_free_urb(context->ctrl_urb); |
| 2513 | + context->ctrl_urb = NULL; |
| 2514 | + } |
| 2515 | + kfree(context); |
| 2516 | + return(NULL); |
| 2517 | + } |
| 2518 | + //usb_set_intfdata(intf, context); |
| 2519 | + //intf->private_data = context; |
| 2520 | + return(context); |
| 2521 | + } |
| 2522 | + } |
| 2523 | + return(NULL); |
| 2524 | +} |
| 2525 | |
| 2526 | /****************************************************/ |
| 2527 | /* function called when an active device is removed */ |
| 2528 | /****************************************************/ |
| 2529 | -static void |
| 2530 | -hfc_usb_disconnect(struct usb_device *usbdev, void *drv_context) |
| 2531 | +//static void hfc_usb_disconnect(struct usb_interface *intf) |
| 2532 | +static void hfc_usb_disconnect(struct usb_device *usbdev, void* drv_context) |
| 2533 | { |
| 2534 | - hfcusb_data *context = drv_context; |
| 2535 | + //hfcusb_data *context = intf->private_data; |
| 2536 | + hfcusb_data* context = drv_context; |
| 2537 | int i; |
| 2538 | - struct sk_buff *skb; |
| 2539 | |
| 2540 | - /* tell all fifos to terminate */ |
| 2541 | - for (i = 0; i < HFCUSB_NUM_FIFOS; i++) |
| 2542 | - if (context->fifos[i].active) { |
| 2543 | - context->fifos[i].active = 0; |
| 2544 | - usb_unlink_urb(&context->fifos[i].urb); |
| 2545 | - } |
| 2546 | - while (context->active_fifos) { |
| 2547 | - set_current_state(TASK_INTERRUPTIBLE); |
| 2548 | - /* Timeout 10ms */ |
| 2549 | - schedule_timeout((10 * HZ) / 1000); |
| 2550 | - } |
| 2551 | + printk(KERN_INFO "HFC-USB: device disconnect\n"); |
| 2552 | + |
| 2553 | + //intf->private_data = NULL; |
| 2554 | + if (!context) |
| 2555 | + return; |
| 2556 | if (timer_pending(&context->t3_timer)) |
| 2557 | del_timer(&context->t3_timer); |
| 2558 | - context->regd.release_driver(context->regd.arg_hisax); |
| 2559 | - while ((skb = skb_dequeue(&context->regd.erq)) != NULL) |
| 2560 | - dev_kfree_skb_any(skb); |
| 2561 | + if (timer_pending(&context->t4_timer)) |
| 2562 | + del_timer(&context->t4_timer); |
| 2563 | + if (timer_pending(&context->led_timer)) |
| 2564 | + del_timer(&context->led_timer); |
| 2565 | + |
| 2566 | + hisax_unregister(&context->d_if); |
| 2567 | |
| 2568 | + /* tell all fifos to terminate */ |
| 2569 | + for(i = 0; i < HFCUSB_NUM_FIFOS; i++) { |
| 2570 | + if(context->fifos[i].usb_transfer_mode == USB_ISOC) { |
| 2571 | + if(context->fifos[i].active > 0) { |
| 2572 | + stop_isoc_chain(&context->fifos[i]); |
| 2573 | +#ifdef VERBOSE_USB_DEBUG |
| 2574 | + printk (KERN_INFO "HFC-USB: hfc_usb_disconnect: stopping ISOC chain Fifo no %i\n", i); |
| 2575 | +#endif |
| 2576 | + } |
| 2577 | + } else { |
| 2578 | + if(context->fifos[i].active > 0) { |
| 2579 | + context->fifos[i].active = 0; |
| 2580 | +#ifdef VERBOSE_USB_DEBUG |
| 2581 | + printk (KERN_INFO "HFC-USB: hfc_usb_disconnect: unlinking URB for Fifo no %i\n", i); |
| 2582 | +#endif |
| 2583 | + } |
| 2584 | + if (context->fifos[i].urb) { |
| 2585 | + usb_unlink_urb(context->fifos[i].urb); |
| 2586 | + usb_free_urb(context->fifos[i].urb); |
| 2587 | + context->fifos[i].urb = NULL; |
| 2588 | + } |
| 2589 | + } |
| 2590 | + context->fifos[i].active = 0; |
| 2591 | + } |
| 2592 | + if (context->ctrl_urb) { |
| 2593 | + usb_unlink_urb(context->ctrl_urb); |
| 2594 | + usb_free_urb(context->ctrl_urb); |
| 2595 | + context->ctrl_urb = NULL; |
| 2596 | + } |
| 2597 | kfree(context); /* free our structure again */ |
| 2598 | - MOD_DEC_USE_COUNT; /* and decrement the usage counter */ |
| 2599 | } /* hfc_usb_disconnect */ |
| 2600 | |
| 2601 | + |
| 2602 | /************************************/ |
| 2603 | /* our driver information structure */ |
| 2604 | /************************************/ |
| 2605 | static struct usb_driver hfc_drv = { |
| 2606 | name:"hfc_usb", |
| 2607 | -#ifdef COMPAT_HAS_USB_IDTAB |
| 2608 | id_table:hfc_usb_idtab, |
| 2609 | -#endif |
| 2610 | probe:hfc_usb_probe, |
| 2611 | disconnect:hfc_usb_disconnect, |
| 2612 | }; |
| 2613 | |
| 2614 | -static void __exit |
| 2615 | -hfc_usb_exit(void) |
| 2616 | -{ |
| 2617 | |
| 2618 | +static void __exit hfc_usb_exit(void) |
| 2619 | +{ |
| 2620 | +#ifdef VERBOSE_USB_DEBUG |
| 2621 | + printk ("HFC-USB: calling \"hfc_usb_exit\" ...\n"); |
| 2622 | +#endif |
| 2623 | usb_deregister(&hfc_drv); /* release our driver */ |
| 2624 | printk(KERN_INFO "HFC-USB module removed\n"); |
| 2625 | } |
| 2626 | |
| 2627 | -static int __init |
| 2628 | -hfc_usb_init(void) |
| 2629 | +static int __init hfc_usb_init(void) |
| 2630 | { |
| 2631 | - struct hisax_drvreg drv; |
| 2632 | + printk ("HFC-USB: driver module revision %s loaded\n", hfcusb_revision); |
| 2633 | |
| 2634 | - drv.version = HISAX_LOAD_VERSION; /* set our version */ |
| 2635 | - drv.cmd = HISAX_LOAD_CHKVER; /* check command only */ |
| 2636 | - if (hisax_register_hfcusb(&drv)) { |
| 2637 | - printk(KERN_INFO "HFC-USB <-> hisax version conflict\n"); |
| 2638 | - return (-1); /* unable to register */ |
| 2639 | - } |
| 2640 | - if (usb_register(&hfc_drv)) { |
| 2641 | - printk(KERN_INFO |
| 2642 | - "Unable to register HFC-USB module at usb stack\n"); |
| 2643 | - return (-1); /* unable to register */ |
| 2644 | + if(usb_register(&hfc_drv)) |
| 2645 | + { |
| 2646 | + printk(KERN_INFO "HFC-USB: Unable to register HFC-USB module at usb stack\n"); |
| 2647 | + return(-1); /* unable to register */ |
| 2648 | } |
| 2649 | - |
| 2650 | - printk(KERN_INFO "HFC-USB module loaded\n"); |
| 2651 | - return (0); |
| 2652 | + return(0); |
| 2653 | } |
| 2654 | |
| 2655 | + |
| 2656 | + |
| 2657 | + |
| 2658 | + |
| 2659 | module_init(hfc_usb_init); |
| 2660 | module_exit(hfc_usb_exit); |
| 2661 | + |
| 2662 | |