source: freewrt/target/linux/generic-2.4/patches/201-hfc_usb_backport.patch@ a3abab6

freewrt_1_0 freewrt_2_0
Last change on this file since a3abab6 was 475ad56, checked in by Waldemar Brodkorb <wbx@…>, 20 years ago

add OpenWrt trunk revision 3830.

git-svn-id: svn://www.freewrt.org/trunk/freewrt@1 afb5a338-a214-0410-bd46-81f09a774fd1

  • Property mode set to 100644
File size: 87.7 KB
  • drivers/Makefile

    diff -rNu linux-2.4.29.old/drivers/Makefile linux-2.4.29/drivers/Makefile
    old new  
    3838subdir-$(CONFIG_MD)             += md
    3939subdir-$(CONFIG_IEEE1394)       += ieee1394
    4040subdir-$(CONFIG_PNP)            += pnp
    41 subdir-$(CONFIG_ISDN_BOOL)      += isdn
     41subdir-$(CONFIG_ISDN)           += isdn
    4242subdir-$(CONFIG_ATM)            += atm
    4343subdir-$(CONFIG_FC4)            += fc4
    4444
  • drivers/isdn/hisax/hfc_usb.c

    diff -rNu linux-2.4.29.old/drivers/isdn/hisax/hfc_usb.c linux-2.4.29/drivers/isdn/hisax/hfc_usb.c
    old new  
    1 /* $Id: hfc_usb.c,v 2.3 2001/07/06 21:30:11 werner Exp $
     1/*
     2 * hfc_usb.c
    23 *
     4 * modular HiSax ISDN driver for Colognechip HFC-USB chip
    35 *
    4  *
    5  * Author       (C) 2001 Werner Cornelius (werner@isdn-development.de)
    6  *              modular driver for Colognechip HFC-USB chip
    7  *              as plugin for HiSax isdn driver
    8  *              type approval valid for HFC-S USB based TAs
    9  *
    10  * Copyright 2001  by Werner Cornelius (werner@isdn-development.de)
     6 * Authors : Peter Sprenger  (sprenger@moving-byters.de)
     7 *           Martin Bachem   (info@colognechip.com)
     8 *           based on the first hfc_usb driver of Werner Cornelius (werner@isdn-development.de)
    119 *
    1210 * This program is free software; you can redistribute it and/or modify
    1311 * it under the terms of the GNU General Public License as published by
     
    2321 * along with this program; if not, write to the Free Software
    2422 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    2523 *
    26  */
     24 * 2005_Mar_16 grsch
     25 *      ported 2.6.8 hfc_usb.c to 2.4.20 format
     26 *      Gregor Schaffrath <gschaff@ran-dom.org>
     27*/
     28
    2729
    2830#include <linux/types.h>
    2931#include <linux/stddef.h>
    3032#include <linux/timer.h>
    3133#include <linux/config.h>
    32 #include <linux/isdn_compat.h>
    3334#include <linux/init.h>
    3435#include "hisax.h"
    3536#include <linux/module.h>
    3637#include <linux/kernel_stat.h>
    37 #include <linux/tqueue.h>
    3838#include <linux/usb.h>
    3939#include <linux/kernel.h>
    4040#include <linux/smp_lock.h>
    4141#include <linux/sched.h>
     42#include "hisax_if.h"
    4243#include "hisax_loadable.h"
    4344
     45static const char *hfcusb_revision = "4.0";
     46
     47/*
     48        to enable much mire debug messages in this driver, define
     49                        VERBOSE_USB_DEBUG and VERBOSE_ISDN_DEBUG
     50        below
     51*/
     52
     53#define VERBOSE_USB_DEBUG
     54#define VERBOSE_ISDN_DEBUG
     55
    4456#define INCLUDE_INLINE_FUNCS
    4557
     58#define TRUE  1
     59#define FALSE 0
     60
     61
    4662/***********/
    4763/* defines */
    4864/***********/
    49 #define HFC_CTRL_TIMEOUT 5      /* 5ms timeout writing/reading regs */
    50 #define HFC_TIMER_T3     7000   /* timeout for l1 activation timer */
    51 
    52 #define HFCUSB_L1_STATECHANGE   0       /* L1 state changed */
    53 #define HFCUSB_L1_DRX           1       /* D-frame received */
    54 #define HFCUSB_L1_ERX           2       /* E-frame received */
    55 #define HFCUSB_L1_DTX           4       /* D-frames completed */
    56 
    57 #define MAX_BCH_SIZE        2048        /* allowed B-channel packet size */
    58 
    59 #define HFCUSB_RX_THRESHOLD 64  /* threshold for fifo report bit rx */
    60 #define HFCUSB_TX_THRESHOLD 64  /* threshold for fifo report bit tx */
    61 
    62 #define HFCUSB_CHIP_ID    0x16  /* Chip ID register index */
    63 #define HFCUSB_CIRM       0x00  /* cirm register index */
    64 #define HFCUSB_USB_SIZE   0x07  /* int length register */
    65 #define HFCUSB_USB_SIZE_I 0x06  /* iso length register */
    66 #define HFCUSB_F_CROSS    0x0b  /* bit order register */
    67 #define HFCUSB_CLKDEL     0x37  /* bit delay register */
    68 #define HFCUSB_CON_HDLC   0xfa  /* channel connect register */
     65#define HFC_CTRL_TIMEOUT        20  //(HZ * USB_CTRL_GET_TIMEOUT)
     66/* 5ms timeout writing/reading regs */
     67#define HFC_TIMER_T3     8000      /* timeout for l1 activation timer */
     68#define HFC_TIMER_T4     500       /* time for state change interval */
     69
     70#define HFCUSB_L1_STATECHANGE   0  /* L1 state changed */
     71#define HFCUSB_L1_DRX           1  /* D-frame received */
     72#define HFCUSB_L1_ERX           2  /* E-frame received */
     73#define HFCUSB_L1_DTX           4  /* D-frames completed */
     74
     75#define MAX_BCH_SIZE        2048   /* allowed B-channel packet size */
     76
     77#define HFCUSB_RX_THRESHOLD 64     /* threshold for fifo report bit rx */
     78#define HFCUSB_TX_THRESHOLD 64     /* threshold for fifo report bit tx */
     79
     80#define HFCUSB_CHIP_ID    0x16     /* Chip ID register index */
     81#define HFCUSB_CIRM       0x00     /* cirm register index */
     82#define HFCUSB_USB_SIZE   0x07     /* int length register */
     83#define HFCUSB_USB_SIZE_I 0x06     /* iso length register */
     84#define HFCUSB_F_CROSS    0x0b     /* bit order register */
     85#define HFCUSB_CLKDEL     0x37     /* bit delay register */
     86#define HFCUSB_CON_HDLC   0xfa     /* channel connect register */
    6987#define HFCUSB_HDLC_PAR   0xfb
    70 #define HFCUSB_SCTRL      0x31  /* S-bus control register (tx) */
    71 #define HFCUSB_SCTRL_E    0x32  /* same for E and special funcs */
    72 #define HFCUSB_SCTRL_R    0x33  /* S-bus control register (rx) */
    73 #define HFCUSB_F_THRES    0x0c  /* threshold register */
    74 #define HFCUSB_FIFO       0x0f  /* fifo select register */
    75 #define HFCUSB_F_USAGE    0x1a  /* fifo usage register */
     88#define HFCUSB_SCTRL      0x31     /* S-bus control register (tx) */
     89#define HFCUSB_SCTRL_E    0x32     /* same for E and special funcs */
     90#define HFCUSB_SCTRL_R    0x33     /* S-bus control register (rx) */
     91#define HFCUSB_F_THRES    0x0c     /* threshold register */
     92#define HFCUSB_FIFO       0x0f     /* fifo select register */
     93#define HFCUSB_F_USAGE    0x1a     /* fifo usage register */
    7694#define HFCUSB_MST_MODE0  0x14
    7795#define HFCUSB_MST_MODE1  0x15
    7896#define HFCUSB_P_DATA     0x1f
    7997#define HFCUSB_INC_RES_F  0x0e
    8098#define HFCUSB_STATES     0x30
    8199
    82 #define HFCUSB_CHIPID 0x40      /* ID value of HFC-USB */
     100#define HFCUSB_CHIPID 0x40         /* ID value of HFC-USB */
    83101
    84102/******************/
    85103/* fifo registers */
    86104/******************/
    87 #define HFCUSB_NUM_FIFOS   8    /* maximum number of fifos */
    88 #define HFCUSB_B1_TX       0    /* index for B1 transmit bulk/int */
    89 #define HFCUSB_B1_RX       1    /* index for B1 receive bulk/int */
     105#define HFCUSB_NUM_FIFOS   8       /* maximum number of fifos */
     106#define HFCUSB_B1_TX       0       /* index for B1 transmit bulk/int */
     107#define HFCUSB_B1_RX       1       /* index for B1 receive bulk/int */
    90108#define HFCUSB_B2_TX       2
    91109#define HFCUSB_B2_RX       3
    92110#define HFCUSB_D_TX        4
     
    94112#define HFCUSB_PCM_TX      6
    95113#define HFCUSB_PCM_RX      7
    96114
    97 /************/
    98 /* LED mask */
    99 /************/
    100 #define LED_DRIVER         0x1
    101 #define LED_L1             0x2
    102 #define LED_BCH            0x4
     115/*
     116* used to switch snd_transfer_mode for different TA modes e.g. the Billion USB TA just
     117* supports ISO out, while the Cologne Chip EVAL TA just supports BULK out
     118*/
     119#define USB_INT         0
     120#define USB_BULK        1
     121#define USB_ISOC        2
     122
     123#define ISOC_PACKETS_D  8
     124#define ISOC_PACKETS_B  8
     125#define ISO_BUFFER_SIZE 128
     126
     127// ISO send definitions
     128#define SINK_MAX        68
     129#define SINK_MIN        48
     130#define SINK_DMIN       12
     131#define SINK_DMAX       18
     132#define BITLINE_INF     (-64*8)
     133
     134
     135
    103136
    104137/**********/
    105138/* macros */
    106139/**********/
    107 #define Write_hfc(a,b,c) usb_control_msg((a)->dev,(a)->ctrl_out_pipe,0,0x40,(c),(b),0,0,HFC_CTRL_TIMEOUT)
    108 #define Read_hfc(a,b,c) usb_control_msg((a)->dev,(a)->ctrl_in_pipe,1,0xC0,0,(b),(c),1,HFC_CTRL_TIMEOUT)
    109 
    110 #ifdef COMPAT_HAS_USB_IDTAB
    111 /****************************************/
    112 /* data defining the devices to be used */
    113 /****************************************/
    114 static __devinitdata const struct usb_device_id hfc_usb_idtab[3] = {
    115         {USB_DEVICE(0x959, 0x2bd0)},    /* Colognechip ROM */
    116         {USB_DEVICE(0x7b0, 0x0006)},    /* USB TA 128 */
    117         {}                      /* end with an all-zeroes entry */
    118 };
    119 #endif
     140#define write_usb(a,b,c) usb_control_msg((a)->dev,(a)->ctrl_out_pipe,0,0x40,(c),(b),NULL,0,HFC_CTRL_TIMEOUT)
     141#define read_usb(a,b,c) usb_control_msg((a)->dev,(a)->ctrl_in_pipe,1,0xC0,0,(b),(c),1,HFC_CTRL_TIMEOUT)
    120142
    121143/*************************************************/
    122144/* entry and size of output/input control buffer */
    123145/*************************************************/
    124146#define HFC_CTRL_BUFSIZE 32
    125 typedef struct {
     147typedef struct
     148{
    126149        __u8 hfc_reg;           /* register number */
    127150        __u8 reg_val;           /* value to be written (or read) */
     151        int action;         /* data for action handler */
     152
    128153} ctrl_buft;
    129154
     155typedef struct
     156{
     157        int vendor;         // vendor id
     158        int prod_id;        // product id
     159        char *vend_name;    // vendor string
     160        __u8 led_scheme;    // led display scheme
     161        __u8 led_invert;    // invert led aux port settings
     162        __u8 led_bits[8];   // array of 8 possible LED bitmask settings
     163
     164} vendor_data;
     165
    130166/***************************************************************/
    131167/* structure defining input+output fifos (interrupt/bulk mode) */
    132168/***************************************************************/
    133 struct hfcusb_data;             /* forward definition */
    134 typedef struct {
    135         int fifonum;            /* fifo index attached to this structure */
    136         __u8 fifo_mask;         /* mask for this fifo */
    137         int active;             /* fifo is currently active */
     169
     170struct usb_fifo;                        /* forward definition */
     171typedef struct iso_urb_struct
     172{
     173        struct urb *purb;
     174        __u8 buffer[ISO_BUFFER_SIZE];   /* buffer incoming/outgoing data */
     175        struct usb_fifo *owner_fifo;    // pointer to owner fifo
     176} iso_urb_struct;
     177
     178
     179struct hfcusb_data;                     /* forward definition */
     180typedef struct usb_fifo
     181{
     182        int fifonum;                    /* fifo index attached to this structure */
     183        int active;                     /* fifo is currently active */
    138184        struct hfcusb_data *hfc;        /* pointer to main structure */
    139         int pipe;               /* address of endpoint */
    140         __u8 usb_maxlen;        /* maximum length for usb transfer */
    141         int max_size;           /* maximum size of receive/send packet */
    142         int transmode;          /* transparent mode selected */
    143         int framenum;           /* number of frame when last tx completed */
    144         int rx_offset;          /* offset inside rx buffer */
    145         int next_complete;      /* complete marker */
    146         __u8 *act_ptr;          /* pointer to next data */
    147         __u8 intervall;         /* interrupt interval */
    148         struct sk_buff *buff;   /* actual used buffer */
    149         urb_t urb;              /* transfer structure for usb routines */
    150         __u8 buffer[128];       /* buffer incoming/outgoing data */
     185        int pipe;                       /* address of endpoint */
     186        __u8 usb_packet_maxlen;         /* maximum length for usb transfer */
     187        unsigned int max_size;          /* maximum size of receive/send packet */
     188        __u8 intervall;                 /* interrupt interval */
     189        struct sk_buff *skbuff;         /* actual used buffer */
     190        struct urb *urb;                /* transfer structure for usb routines */
     191        __u8 buffer[128];               /* buffer incoming/outgoing data */
     192        int bit_line;                   /* how much bits are in the fifo? */
     193
     194        volatile __u8 usb_transfer_mode;/* switched between ISO and INT */
     195        iso_urb_struct iso[2];          /* need two urbs to have one always for pending */
     196        struct hisax_if *hif;           /* hisax interface */
     197        int delete_flg;                 /* only delete skbuff once */
     198        int last_urblen;                /* remember length of last packet */
     199
    151200} usb_fifo;
    152201
     202
    153203/*********************************************/
    154204/* structure holding all data for one device */
    155205/*********************************************/
    156 typedef struct hfcusb_data {
    157         struct hisax_drvreg regd;       /* register data and callbacks */
    158         struct usb_device *dev; /* our device */
    159         int if_used;            /* used interface number */
    160         int alt_used;           /* used alternate config */
    161         int ctrl_paksize;       /* control pipe packet size */
     206typedef struct hfcusb_data
     207{
     208        // HiSax Interface for loadable Layer1 drivers
     209        struct hisax_d_if d_if;                 /* see hisax_if.h */
     210        struct hisax_b_if b_if[2];              /* see hisax_if.h */
     211        int protocol;
     212       
     213        struct usb_device *dev;                 /* our device */
     214        int if_used;                            /* used interface number */
     215        int alt_used;                           /* used alternate config */
     216        int ctrl_paksize;                       /* control pipe packet size */
    162217        int ctrl_in_pipe, ctrl_out_pipe;        /* handles for control pipe */
     218        int cfg_used;                           /* configuration index used */
     219        int vend_idx;                           // vendor found
     220
     221        int b_mode[2];                          // B-channel mode
     222
     223        int l1_activated;                       // layer 1 activated
     224
     225        int packet_size,iso_packet_size;       
    163226
    164227        /* control pipe background handling */
    165228        ctrl_buft ctrl_buff[HFC_CTRL_BUFSIZE];  /* buffer holding queued data */
    166         volatile int ctrl_in_idx, ctrl_out_idx, ctrl_cnt;       /* input/output pointer + count */
    167         urb_t ctrl_urb;         /* transfer structure for control channel */
    168         devrequest ctrl_write;  /* buffer for control write request */
    169         devrequest ctrl_read;   /* same for read request */
    170 
    171         volatile __u8 dfifo_fill;       /* value read from tx d-fifo */
    172         volatile __u8 active_fifos;     /* fifos currently active as bit mask */
    173         volatile __u8 threshold_mask;   /* threshold actually reported */
    174         volatile __u8 service_request;  /* fifo needs service from task */
    175         volatile __u8 ctrl_fifo;        /* last selected fifo */
    176         volatile __u8 bch_enables;      /* or mask for sctrl_r and sctrl register values */
    177         volatile __u8 led_req;          /* request status of adapters leds */
    178         volatile __u8 led_act;          /* active status of adapters leds */
     229        volatile int ctrl_in_idx, ctrl_out_idx,
     230                ctrl_cnt;                       /* input/output pointer + count */
     231        struct urb *ctrl_urb;                   /* transfer structure for control channel */
     232
     233        struct usb_ctrlrequest ctrl_write;      /* buffer for control write request */
     234        struct usb_ctrlrequest ctrl_read;       /* same for read request */
     235
     236        __u8 led_state,led_new_data,led_b_active;
     237
     238        volatile __u8 threshold_mask;           /* threshold actually reported */
     239        volatile __u8 bch_enables;              /* or mask for sctrl_r and sctrl register values */
     240
    179241        usb_fifo fifos[HFCUSB_NUM_FIFOS];       /* structure holding all fifo data */
    180242
    181         /* layer 1 activation/deactivation handling */
    182         volatile __u8 l1_state; /* actual l1 state */
    183         volatile ulong l1_event;        /* event mask */
    184         struct tq_struct l1_tq; /* l1 bh structure */
    185         struct timer_list t3_timer;     /* timer for activation/deactivation */
    186         struct timer_list t4_timer;     /* timer for activation/deactivation */
     243        volatile __u8 l1_state;                 /* actual l1 state */
     244        struct timer_list t3_timer;             /* timer 3 for activation/deactivation */
     245        struct timer_list t4_timer;             /* timer 4 for activation/deactivation */
     246        struct timer_list led_timer;            /* timer flashing leds */
     247
    187248} hfcusb_data;
    188249
    189 #if 0
    190 static void
    191 usb_dump_urb(purb_t purb)
    192 {
    193         printk("urb                   :%p\n", purb);
    194         printk("next                  :%p\n", purb->next);
    195         printk("dev                   :%p\n", purb->dev);
    196         printk("pipe                  :%08X\n", purb->pipe);
    197         printk("status                :%d\n", purb->status);
    198         printk("transfer_flags        :%08X\n", purb->transfer_flags);
    199         printk("transfer_buffer       :%p\n", purb->transfer_buffer);
    200         printk("transfer_buffer_length:%d\n",
    201                purb->transfer_buffer_length);
    202         printk("actual_length         :%d\n", purb->actual_length);
    203         printk("setup_packet          :%p\n", purb->setup_packet);
    204         printk("start_frame           :%d\n", purb->start_frame);
    205         printk("number_of_packets     :%d\n", purb->number_of_packets);
    206         printk("interval              :%d\n", purb->interval);
    207         printk("error_count           :%d\n", purb->error_count);
    208         printk("context               :%p\n", purb->context);
    209         printk("complete              :%p\n", purb->complete);
    210 }
    211 #endif
    212250
    213 /*************************************************************************/
    214 /* bottom half handler for L1 activation/deactiavtaion + D-chan + E-chan */
    215 /*************************************************************************/
    216 static void
    217 usb_l1d_bh(hfcusb_data * hfc)
    218 {
     251static void collect_rx_frame(usb_fifo *fifo,__u8 *data,int len,int finish);
     252
    219253
    220         while (hfc->l1_event) {
    221                 if (test_and_clear_bit
    222                     (HFCUSB_L1_STATECHANGE, &hfc->l1_event)) {
    223                         if (hfc->l1_state == 7)
    224                             hfc->led_req |= LED_L1;
    225                         else
    226                             hfc->led_req &= ~LED_L1;
    227                         if ((hfc->l1_state == 7) ||
    228                             (hfc->l1_state == 3))
    229                             hfc->regd.dch_l1l2(hfc->regd.arg_hisax,
    230                                                (hfc->l1_state ==
    231                                                 7) ? (PH_ACTIVATE |
    232                                                       INDICATION)
    233                                                : (PH_DEACTIVATE | INDICATION),
    234                                                NULL);
    235                 }
    236                 if (test_and_clear_bit(HFCUSB_L1_DRX, &hfc->l1_event)) {
    237                         hfc->regd.dch_l1l2(hfc->regd.arg_hisax,
    238                                            PH_DATA | INDICATION,
    239                                            (void *) 0);
    240                 }
    241                 if (test_and_clear_bit(HFCUSB_L1_ERX, &hfc->l1_event)) {
    242                         hfc->regd.dch_l1l2(hfc->regd.arg_hisax,
    243                                            PH_DATA | INDICATION,
    244                                            (void *) 1);
    245                 }
    246                 if (test_and_clear_bit(HFCUSB_L1_DTX, &hfc->l1_event)) {
    247                         hfc->regd.dch_l1l2(hfc->regd.arg_hisax,
    248                                            PH_DATA | CONFIRM, NULL);
    249                 }
    250         }                       /* while */
    251 }                               /* usb_l1d_bh */
    252254
    253255/******************************************************/
    254256/* start next background transfer for control channel */
    255257/******************************************************/
    256 static void
    257 ctrl_start_transfer(hfcusb_data * hfc)
     258static void ctrl_start_transfer(hfcusb_data * hfc)
    258259{
    259 
    260         if (hfc->ctrl_cnt) {
    261                 switch (hfc->ctrl_buff[hfc->ctrl_out_idx].hfc_reg) {
    262                         case HFCUSB_F_USAGE:
    263                                 hfc->ctrl_urb.pipe = hfc->ctrl_in_pipe;
    264                                 hfc->ctrl_urb.setup_packet =
    265                                     (u_char *) & hfc->ctrl_read;
    266                                 hfc->ctrl_urb.transfer_buffer_length = 1;
    267                                 hfc->ctrl_read.index =
    268                                     hfc->ctrl_buff[hfc->ctrl_out_idx].
    269                                     hfc_reg;
    270                                 hfc->ctrl_urb.transfer_buffer =
    271                                     (char *) &hfc->dfifo_fill;
    272                                 break;
    273 
    274                         default:        /* write register */
    275                                 hfc->ctrl_urb.pipe = hfc->ctrl_out_pipe;
    276                                 hfc->ctrl_urb.setup_packet =
    277                                     (u_char *) & hfc->ctrl_write;
    278                                 hfc->ctrl_urb.transfer_buffer = NULL;
    279                                 hfc->ctrl_urb.transfer_buffer_length = 0;
    280                                 hfc->ctrl_write.index =
    281                                     hfc->ctrl_buff[hfc->ctrl_out_idx].
    282                                     hfc_reg;
    283                                 hfc->ctrl_write.value =
    284                                     hfc->ctrl_buff[hfc->ctrl_out_idx].
    285                                     reg_val;
    286                                 break;
    287                 }
    288                 usb_submit_urb(&hfc->ctrl_urb); /* start transfer */
     260        int err;
     261        if(hfc->ctrl_cnt)
     262        {
     263                hfc->ctrl_urb->pipe = hfc->ctrl_out_pipe;
     264                hfc->ctrl_urb->setup_packet = (u_char *) & hfc->ctrl_write;
     265                hfc->ctrl_urb->transfer_buffer = NULL;
     266                hfc->ctrl_urb->transfer_buffer_length = 0;
     267                hfc->ctrl_write.wIndex = hfc->ctrl_buff[hfc->ctrl_out_idx].hfc_reg;
     268                hfc->ctrl_write.wValue = hfc->ctrl_buff[hfc->ctrl_out_idx].reg_val;
     269                err = usb_submit_urb(hfc->ctrl_urb);    /* start transfer */
     270                printk(KERN_DEBUG "ctrl_start_transfer: submit %d\n", err);
    289271        }
    290272}                               /* ctrl_start_transfer */
    291273
     
    293275/* queue a control transfer request */
    294276/* return 0 on success.             */
    295277/************************************/
    296 static int
    297 queue_control_request(hfcusb_data * hfc, __u8 reg, __u8 val)
     278static int queue_control_request(hfcusb_data * hfc, __u8 reg, __u8 val,int action)
    298279{
    299280        ctrl_buft *buf;
    300281
    301         if (hfc->ctrl_cnt >= HFC_CTRL_BUFSIZE)
    302                 return (1);     /* no space left */
    303         buf = hfc->ctrl_buff + hfc->ctrl_in_idx;        /* pointer to new index */
     282#ifdef VERBOSE_USB_DEBUG
     283        printk ("HFC_USB: queue_control_request reg: %x, val: %x\n", reg, val);
     284#endif
     285
     286        if(hfc->ctrl_cnt >= HFC_CTRL_BUFSIZE)  return(1);          /* no space left */
     287        buf = &hfc->ctrl_buff[hfc->ctrl_in_idx];        /* pointer to new index */
    304288        buf->hfc_reg = reg;
    305289        buf->reg_val = val;
     290        buf->action=action;
    306291        if (++hfc->ctrl_in_idx >= HFC_CTRL_BUFSIZE)
    307292                hfc->ctrl_in_idx = 0;   /* pointer wrap */
    308293        if (++hfc->ctrl_cnt == 1)
    309294                ctrl_start_transfer(hfc);
    310         return (0);
    311 }                               /* queue_control_request */
     295        return(0);
     296}               /* queue_control_request */
    312297
    313 /**************************************/
    314 /* called when timer t3 or t4 expires */
    315 /**************************************/
    316 static void
    317 l1_timer_expire(hfcusb_data * hfc)
    318 {
    319     if (timer_pending(&hfc->t4_timer))
    320         del_timer(&hfc->t4_timer);
    321     queue_control_request(hfc, HFCUSB_STATES, 0x40);
    322     test_and_set_bit(HFCUSB_L1_STATECHANGE,
    323                      &hfc->l1_event);
    324     queue_task(&hfc->l1_tq, &tq_immediate);
    325     mark_bh(IMMEDIATE_BH);
    326 } /* l1_timer_expire */
    327 
    328 /**************************************************/
    329 /* (re)fills a tx-fifo urb. Queuing is done later */
    330 /**************************************************/
    331 static void
    332 fill_tx_urb(usb_fifo * fifo)
    333 {
    334         struct sk_buff *skb;
    335         long flags;
    336         int i, ii = 0;
    337 
    338         fifo->urb.dev = fifo->hfc->dev;
    339         if ((fifo->buff)
    340             && (fifo->urb.transfer_buffer_length < fifo->usb_maxlen)) {
    341                 switch (fifo->fifonum) {
    342                         case HFCUSB_B1_TX:
    343                         case HFCUSB_B2_TX:
    344                                 skb = fifo->buff;
    345                                 fifo->buff = NULL;
    346                                 fifo->hfc->regd.bch_l1l2(fifo->hfc->regd.
    347                                                          arg_hisax,
    348                                                          (fifo->fifonum ==
    349                                                           HFCUSB_B1_TX) ? 0
    350                                                          : 1,
    351                                                          (PH_DATA |
    352                                                           CONFIRM),
    353                                                          (void *) skb);
    354                                 fifo->hfc->service_request |=
    355                                     fifo->fifo_mask;
    356                                 return;
    357                         case HFCUSB_D_TX:
    358                                 dev_kfree_skb_any(fifo->buff);
    359                                 fifo->buff = NULL;
    360                                 save_flags(flags);
    361                                 cli();
    362                                 fifo->hfc->dfifo_fill = 0xff;   /* currently invalid data */
    363                                 queue_control_request(fifo->hfc,
    364                                                       HFCUSB_FIFO,
    365                                                       HFCUSB_D_TX);
    366                                 queue_control_request(fifo->hfc,
    367                                                       HFCUSB_F_USAGE, 0);
    368                                 restore_flags(flags);
    369                                 return;
    370                         default:
    371                                 return; /* error, invalid fifo */
    372                 }
     298
     299static int control_action_handler(hfcusb_data *hfc,int reg,int val,int action)
     300{
     301        if(!action) return(1);  // no action defined
     302
     303        return(0);
     304}
     305
     306
     307/***************************************************************/
     308/* control completion routine handling background control cmds */
     309/***************************************************************/
     310static void ctrl_complete(struct urb *urb)
     311{
     312        hfcusb_data *hfc = (hfcusb_data *) urb->context;
     313        ctrl_buft *buf;
     314
     315        printk(KERN_DEBUG "ctrl_complete cnt %d\n", hfc->ctrl_cnt);
     316        urb->dev = hfc->dev;
     317        if(hfc->ctrl_cnt)
     318        {
     319                buf=&hfc->ctrl_buff[hfc->ctrl_out_idx];
     320                control_action_handler(hfc,buf->hfc_reg,buf->reg_val,buf->action);
     321
     322                hfc->ctrl_cnt--;        /* decrement actual count */
     323                if(++hfc->ctrl_out_idx >= HFC_CTRL_BUFSIZE) hfc->ctrl_out_idx = 0;      /* pointer wrap */
     324
     325                ctrl_start_transfer(hfc);       /* start next transfer */
     326        }
     327}                               /* ctrl_complete */
     328
     329
     330
     331#define LED_OFF      0   // no LED support
     332#define LED_SCHEME1  1   // LED standard scheme
     333#define LED_SCHEME2  2   // not used yet...
     334
     335#define LED_POWER_ON    1
     336#define LED_POWER_OFF   2
     337#define LED_S0_ON               3
     338#define LED_S0_OFF              4
     339#define LED_B1_ON               5
     340#define LED_B1_OFF              6
     341#define LED_B1_DATA             7
     342#define LED_B2_ON               8
     343#define LED_B2_OFF              9
     344#define LED_B2_DATA        10
     345
     346#define LED_NORMAL   0   // LEDs are normal
     347#define LED_INVERTED 1   // LEDs are inverted
     348
     349// time for LED flashing
     350#define LED_TIME      250
     351
     352vendor_data vdata[]=
     353{
     354    {0x959, 0x2bd0, "ISDN USB TA (Cologne Chip HFC-S USB based)", LED_OFF,LED_NORMAL,{4,0,2,1}},     /* CologneChip Eval TA */
     355        {0x7b0, 0x0007, "Billion tiny USB ISDN TA 128", LED_SCHEME1,  LED_INVERTED, {8,0x40,0x20,0x10}},  /* Billion TA */
     356        {0x742, 0x2008, "Stollmann USB TA",             LED_SCHEME1,  LED_NORMAL,   {4,0,2,1}},           /* Stollmann TA */
     357        {0x8e3, 0x0301, "Olitec USB RNIS",              LED_SCHEME1,  LED_NORMAL,   {2,0,1,4}},           /* Olitec TA  */
     358        {0x675, 0x1688, "DrayTec USB ISDN TA",          LED_SCHEME1,  LED_NORMAL,   {4,0,2,1}},           /* Draytec TA */
     359        {0x7fa, 0x0846, "Bewan Modem RNIS USB",         LED_SCHEME1,  LED_INVERTED, {8,0x40,0x20,0x10}},  /* Bewan TA   */
     360        {0}                        // EOL element
     361};
     362                                                                               
     363/***************************************************/
     364/* write led data to auxport & invert if necessary */
     365/***************************************************/
     366static void write_led(hfcusb_data * hfc,__u8 led_state)
     367{
     368        if(led_state!=hfc->led_state)
     369        {
     370                hfc->led_state=led_state;
     371                queue_control_request(hfc, HFCUSB_P_DATA,(vdata[hfc->vend_idx].led_invert) ? ~led_state : led_state,1);
     372        }
     373}
     374
     375/******************************************/
     376/* invert B-channel LEDs if data is sent  */
     377/******************************************/
     378static void led_timer(hfcusb_data * hfc)
     379{
     380        static int cnt=0;
     381        __u8 led_state=hfc->led_state;
     382
     383        if(cnt)
     384        {
     385                if(hfc->led_b_active&1) led_state|=vdata[hfc->vend_idx].led_bits[2];
     386                if(hfc->led_b_active&2) led_state|=vdata[hfc->vend_idx].led_bits[3];
     387        }
     388        else
     389        {
     390                if(!(hfc->led_b_active&1) || hfc->led_new_data&1) led_state&=~vdata[hfc->vend_idx].led_bits[2];
     391                if(!(hfc->led_b_active&2) || hfc->led_new_data&2) led_state&=~vdata[hfc->vend_idx].led_bits[3];
    373392        }
    374393
    375         /* check if new buffer needed */
    376         if (!fifo->buff) {
    377                 switch (fifo->fifonum) {
    378                         case HFCUSB_B1_TX:
    379                                 if (fifo->hfc->regd.bsk[0])
    380                                         fifo->buff = *fifo->hfc->regd.bsk[0];   /* B1-channel tx buffer */
     394        write_led(hfc,led_state);
     395        hfc->led_new_data=0;
     396
     397        cnt=!cnt;
     398        // restart 4 hz timer
     399        hfc->led_timer.expires = jiffies + (LED_TIME * HZ) / 1000;
     400        if(!timer_pending(&hfc->led_timer)) add_timer(&hfc->led_timer);
     401}
     402
     403/**************************/
     404/* handle LED requests    */
     405/**************************/
     406static void handle_led(hfcusb_data * hfc,int event)
     407{
     408        __u8 led_state=hfc->led_state;
     409
     410        // if no scheme -> no LED action
     411        if(vdata[hfc->vend_idx].led_scheme==LED_OFF) return;
     412
     413        switch(event)
     414        {
     415                case LED_POWER_ON:
     416                                   led_state|=vdata[hfc->vend_idx].led_bits[0];
     417                                break;
     418                case LED_POWER_OFF: // no Power off handling
     419                                break;
     420                case LED_S0_ON:
     421                                   led_state|=vdata[hfc->vend_idx].led_bits[1];
     422                                break;
     423                case LED_S0_OFF:
     424                                   led_state&=~vdata[hfc->vend_idx].led_bits[1];
    381425                                break;
    382                         case HFCUSB_B2_TX:
    383                                 if (fifo->hfc->regd.bsk[1])
    384                                         fifo->buff = *fifo->hfc->regd.bsk[1];   /* B2-channel tx buffer */
     426                case LED_B1_ON:
     427                                        hfc->led_b_active|=1;
    385428                                break;
    386                         case HFCUSB_D_TX:
    387                                 if (fifo->hfc->regd.dsq)
    388                                         fifo->buff = skb_dequeue(fifo->hfc->regd.dsq);  /* D-channel tx queue */
     429                case LED_B1_OFF:
     430                                        hfc->led_b_active&=~1;
    389431                                break;
    390                         default:
    391                                 return; /* error, invalid fifo */
     432                case LED_B1_DATA:
     433                                   hfc->led_new_data|=1;
     434                                break;
     435                case LED_B2_ON:
     436                                   hfc->led_b_active|=2;
     437                                break;
     438                case LED_B2_OFF:
     439                                        hfc->led_b_active&=~2;
     440                                break;
     441                case LED_B2_DATA:
     442                                   hfc->led_new_data|=2;
     443                                break;
     444        }
     445       
     446        write_led(hfc,led_state);
     447}
     448
     449/********************************/
     450/* called when timer t3 expires */
     451/********************************/
     452static void l1_timer_expire_t3(hfcusb_data * hfc)
     453{
     454    //printk (KERN_INFO "HFC-USB: l1_timer_expire_t3\n");
     455
     456        hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,PH_DEACTIVATE | INDICATION,NULL);
     457#ifdef VERBOSE_USB_DEBUG
     458        printk(KERN_INFO "PH_DEACTIVATE | INDICATION sent\n");
     459#endif
     460        hfc->l1_activated=FALSE;
     461        handle_led(hfc,LED_S0_OFF);
     462}
     463
     464/********************************/
     465/* called when timer t4 expires */
     466/********************************/
     467static void l1_timer_expire_t4(hfcusb_data * hfc)
     468{
     469    //printk (KERN_INFO "HFC-USB: l1_timer_expire_t4\n");
     470
     471        hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,PH_DEACTIVATE | INDICATION,NULL);
     472#ifdef VERBOSE_USB_DEBUG
     473        printk(KERN_INFO "PH_DEACTIVATE | INDICATION sent\n");
     474#endif
     475        hfc->l1_activated=FALSE;
     476        handle_led(hfc,LED_S0_OFF);
     477}
     478
     479/*****************************/
     480/* handle S0 state changes   */
     481/*****************************/
     482static void state_handler(hfcusb_data * hfc,__u8 state)
     483{
     484        __u8 old_state;
     485
     486        old_state=hfc->l1_state;
     487
     488        // range check
     489        if(state==old_state || state<1 || state>8) return;
     490
     491#ifdef VERBOSE_ISDN_DEBUG
     492        printk(KERN_INFO "HFC-USB: new S0 state:%d old_state:%d\n",state,old_state);
     493#endif
     494
     495        if(state<4 || state==7 || state==8)
     496        {
     497        if(timer_pending(&hfc->t3_timer)) del_timer(&hfc->t3_timer);
     498                //printk(KERN_INFO "HFC-USB: T3 deactivated\n");
     499        }
     500
     501        if(state>=7)
     502        {
     503        if(timer_pending(&hfc->t4_timer)) del_timer(&hfc->t4_timer);
     504                //printk(KERN_INFO "HFC-USB: T4 deactivated\n");
     505        }
     506
     507        if(state==7 && !hfc->l1_activated)
     508        {
     509                hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,PH_ACTIVATE | INDICATION,NULL);
     510                //printk(KERN_INFO "HFC-USB: PH_ACTIVATE | INDICATION sent\n");
     511                hfc->l1_activated=TRUE;
     512                handle_led(hfc,LED_S0_ON);
     513        }
     514        else
     515        if(state<=3 /* && activated*/)
     516        {
     517                if(old_state==7 || old_state==8)
     518                {
     519                        //printk(KERN_INFO "HFC-USB: T4 activated\n");
     520                        hfc->t4_timer.expires = jiffies + (HFC_TIMER_T4 * HZ) / 1000;
     521                        if(!timer_pending(&hfc->t4_timer)) add_timer(&hfc->t4_timer);
    392522                }
    393                 if (!fifo->buff) {
    394                         fifo->active = 0;       /* we are inactive now */
    395                         fifo->hfc->active_fifos &= ~fifo->fifo_mask;
    396                         if (fifo->fifonum == HFCUSB_D_TX) {
    397                                 test_and_set_bit(HFCUSB_L1_DTX,
    398                                                  &fifo->hfc->l1_event);
    399                                 queue_task(&fifo->hfc->l1_tq,
    400                                            &tq_immediate);
    401                                 mark_bh(IMMEDIATE_BH);
    402                         }
    403                         return;
     523                else
     524                {
     525                        hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,PH_DEACTIVATE | INDICATION,NULL);
     526                        //printk(KERN_INFO "HFC-USB: PH_DEACTIVATE | INDICATION sent\n");
     527                        hfc->l1_activated=FALSE;
     528                        handle_led(hfc,LED_S0_OFF);
    404529                }
    405                 fifo->act_ptr = fifo->buff->data;       /* start of data */
    406                 fifo->active = 1;
    407                 ii = 1;
    408                 fifo->hfc->active_fifos |= fifo->fifo_mask;
    409                 fifo->hfc->service_request &= ~fifo->fifo_mask;
    410         }
    411         /* fillup the send buffer */
    412         i = fifo->buff->len - (fifo->act_ptr - fifo->buff->data);       /* remaining length */
    413         fifo->buffer[0] = !fifo->transmode;     /* not eof */
    414         if (i > (fifo->usb_maxlen - ii)) {
    415                 i = fifo->usb_maxlen - ii;
    416         }
    417         if (i)
    418                 memcpy(fifo->buffer + ii, fifo->act_ptr, i);
    419         fifo->urb.transfer_buffer_length = i + ii;
    420         fifo->rx_offset = ii;
    421 }                               /* fill_tx_urb */
    422 
    423 /************************************************/
    424 /* transmit completion routine for all tx fifos */
    425 /************************************************/
    426 static void
    427 tx_complete(purb_t urb)
     530        }
     531
     532        hfc->l1_state=state;
     533}
     534
     535
     536/* prepare iso urb */
     537static void fill_isoc_urb(struct urb *urb, struct usb_device *dev, unsigned int pipe, void *buf,
     538        int num_packets, int packet_size, int interval, usb_complete_t complete, void *context)
    428539{
    429         usb_fifo *fifo = (usb_fifo *) urb->context;     /* pointer to our fifo */
     540        int k;
    430541
    431         fifo->hfc->service_request &= ~fifo->fifo_mask; /* no further handling */
    432         fifo->framenum = usb_get_current_frame_number(fifo->hfc->dev);
     542        spin_lock_init(&urb->lock);     // do we really need spin_lock_init ?
     543        urb->dev = dev;
     544        urb->pipe = pipe;
     545        urb->complete = complete;
     546        urb->number_of_packets = num_packets;
     547        urb->transfer_buffer_length = packet_size * num_packets;
     548        urb->context = context;
     549        urb->transfer_buffer = buf;
     550        urb->transfer_flags = 0;
     551        urb->transfer_flags = USB_ISO_ASAP;
     552        urb->actual_length = 0;
     553        urb->interval = interval;
     554        for (k = 0; k < num_packets; k++) {
     555                urb->iso_frame_desc[k].offset = packet_size * k;
     556                urb->iso_frame_desc[k].length = packet_size;
     557                urb->iso_frame_desc[k].actual_length = 0;
     558        }
     559}
    433560
    434         /* check for deactivation or error */
    435         if ((!fifo->active) || (urb->status)) {
    436                 fifo->hfc->active_fifos &= ~fifo->fifo_mask;    /* we are inactive */
    437                 fifo->active = 0;
    438                 if ((fifo->buff) && (fifo->fifonum == HFCUSB_D_TX)) {
    439                         dev_kfree_skb_any(fifo->buff);
     561/* allocs urbs and start isoc transfer with two pending urbs to avoid gaps in the transfer chain */
     562static int start_isoc_chain(usb_fifo * fifo, int num_packets_per_urb,usb_complete_t complete,int packet_size)
     563{
     564        int i, k, errcode;
     565
     566#ifdef VERBOSE_USB_DEBUG
     567        printk(KERN_INFO "HFC-USB: starting ISO-chain for Fifo %i\n",  fifo->fifonum);
     568#endif
     569
     570
     571        // allocate Memory for Iso out Urbs
     572        for (i = 0; i < 2; i++) {
     573                if (!(fifo->iso[i].purb)) {
     574                        fifo->iso[i].purb = usb_alloc_urb(num_packets_per_urb);
     575                        fifo->iso[i].owner_fifo = (struct usb_fifo *) fifo;
     576
     577                        // Init the first iso
     578                        if (ISO_BUFFER_SIZE >= (fifo->usb_packet_maxlen * num_packets_per_urb))
     579                        {
     580
     581                                fill_isoc_urb(fifo->iso[i].purb, fifo->hfc->dev, fifo->pipe, fifo->iso[i].buffer,
     582                                        num_packets_per_urb, fifo->usb_packet_maxlen, fifo->intervall,
     583                                        complete, &fifo->iso[i]);
     584
     585                                memset(fifo->iso[i].buffer, 0, sizeof(fifo->iso[i].buffer));
     586
     587                                // defining packet delimeters in fifo->buffer
     588                                for(k = 0; k < num_packets_per_urb; k++)
     589                                {
     590                                        fifo->iso[i].purb->iso_frame_desc[k].offset = k*packet_size;
     591                                        fifo->iso[i].purb->iso_frame_desc[k].length = packet_size;
     592                                }
     593                        }
    440594                }
    441                 fifo->buff = NULL;
    442                 return;
     595
     596                fifo->bit_line = BITLINE_INF;
     597
     598                errcode = usb_submit_urb(fifo->iso[i].purb);
     599                fifo->active = (errcode >= 0) ? 1 : 0;
     600                if(errcode < 0)
     601                {
     602                        printk(KERN_INFO "HFC-USB: error submitting ISO URB: %i.%i \n",  errcode, i);
     603                };
     604
    443605        }
    444         fifo->act_ptr += (urb->transfer_buffer_length - fifo->rx_offset);       /* adjust pointer */
    445         fill_tx_urb(fifo);      /* refill the urb */
    446         fifo->hfc->threshold_mask |= fifo->fifo_mask;   /* assume threshold reached */
    447         if (fifo->buff)
    448                 fifo->hfc->service_request |= fifo->fifo_mask;  /* need to restart */
    449 }                               /* tx_complete */
    450606
    451 /***********************************************/
    452 /* receive completion routine for all rx fifos */
    453 /***********************************************/
    454 static void
    455 rx_complete(purb_t urb)
     607        // errcode = (usb_submit_urb(fifo->iso[0].purb, GFP_KERNEL));
     608        return(fifo->active);
     609}
     610
     611/* stops running iso chain and frees their pending urbs */
     612static void stop_isoc_chain(usb_fifo * fifo)
    456613{
    457         usb_fifo *fifo = (usb_fifo *) urb->context;     /* pointer to our fifo */
    458         hfcusb_data *hfc = fifo->hfc;
    459         usb_fifo *txfifo;
    460         __u8 last_state;
    461         int i, ii, currcnt, hdlci;
    462         struct sk_buff *skb;
    463 
    464         urb->dev = hfc->dev; /* security init */
    465         if ((!fifo->active) || (urb->status)) {
    466                 hfc->service_request &= ~fifo->fifo_mask;       /* no further handling */
    467                 hfc->active_fifos &= ~fifo->fifo_mask;  /* we are inactive */
    468                 fifo->urb.interval = 0; /* cancel automatic rescheduling */
    469                 if (fifo->buff) {
    470                         dev_kfree_skb_any(fifo->buff);
    471                         fifo->buff = NULL;
     614        int i;
     615
     616        for(i = 0; i < 2; i++)
     617        {
     618                if(fifo->iso[i].purb)
     619                {
     620#ifdef VERBOSE_USB_DEBUG
     621                        printk(KERN_INFO "HFC-USB: Stopping iso chain for fifo %i.%i\n", fifo->fifonum, i);
     622#endif
     623                        usb_unlink_urb(fifo->iso[i].purb);
     624                        usb_free_urb(fifo->iso[i].purb);
     625                        fifo->iso[i].purb = NULL;
    472626                }
    473                 return;
    474627        }
     628        if (fifo->urb) {
     629                usb_unlink_urb(fifo->urb);
     630                usb_free_urb(fifo->urb);
     631                fifo->urb = NULL;
     632        }
     633        fifo->active = 0;
     634}
    475635
    476         /* first check for any status changes */
    477         if ((urb->actual_length < fifo->rx_offset)
    478             || (urb->actual_length > fifo->usb_maxlen))
    479                 return;         /* error condition */
    480 
    481         if (fifo->rx_offset) {
    482                 hfc->threshold_mask = fifo->buffer[1];  /* update threshold status */
    483                 fifo->next_complete = fifo->buffer[0] & 1;
    484                 if ((fifo->fifonum == HFCUSB_D_RX) &&
    485                     (hfc->led_req != hfc->led_act))
    486                     queue_control_request(hfc, HFCUSB_P_DATA, hfc->led_req);
    487 
    488                 /* check if rescheduling needed */
    489                 if ((i =
    490                      hfc->service_request & hfc->active_fifos & ~hfc->
    491                      threshold_mask)) {
    492                         currcnt =
    493                             usb_get_current_frame_number(hfc->dev);
    494                         txfifo = hfc->fifos + HFCUSB_B1_TX;
    495                         ii = 3;
    496                         while (ii--) {
    497                                 if ((i & txfifo->fifo_mask)
    498                                     && (currcnt != txfifo->framenum)) {
    499                                         hfc->service_request &=
    500                                             ~txfifo->fifo_mask;
    501                                         if (!txfifo->buff)
    502                                                 fill_tx_urb(txfifo);
    503                                         if (txfifo->buff)
    504                                                 usb_submit_urb(&txfifo->
    505                                                                urb);
     636// defines how much ISO packets are handled in one URB
     637static int iso_packets[8]={ISOC_PACKETS_B,ISOC_PACKETS_B,ISOC_PACKETS_B,ISOC_PACKETS_B,
     638                               ISOC_PACKETS_D,ISOC_PACKETS_D,ISOC_PACKETS_D,ISOC_PACKETS_D};
     639
     640/*****************************************************/
     641/* transmit completion routine for all ISO tx fifos */
     642/*****************************************************/
     643static void tx_iso_complete(struct urb *urb)
     644{
     645        iso_urb_struct *context_iso_urb = (iso_urb_struct *) urb->context;
     646        usb_fifo *fifo = context_iso_urb->owner_fifo;
     647        hfcusb_data *hfc = fifo->hfc;
     648        int k, tx_offset, num_isoc_packets, sink, len, current_len,errcode,frame_complete,transp_mode,fifon;
     649        __u8 threshbit;
     650        __u8 threshtable[8] = { 1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
     651
     652        fifon=fifo->fifonum;
     653        tx_offset=0;
     654        // very weird error code when using ohci drivers, for now : ignore this error ...  (MB)
     655        if(urb->status == -EOVERFLOW)
     656        {
     657                urb->status = 0;
     658#ifdef VERBOSE_USB_DEBUG
     659                printk(KERN_INFO "HFC-USB: ignoring USB DATAOVERRUN  for fifo  %i \n",fifon);
     660#endif
     661        }
     662
     663        if(fifo->active && !urb->status)
     664        {
     665                transp_mode=0;
     666                if(fifon<4 && hfc->b_mode[fifon/2]==L1_MODE_TRANS) transp_mode=TRUE;
     667
     668                threshbit = threshtable[fifon] & hfc->threshold_mask;   // is threshold set for our channel?
     669                num_isoc_packets=iso_packets[fifon];
     670
     671                if(fifon >= HFCUSB_D_TX)
     672                {
     673                        sink = (threshbit) ? SINK_DMIN : SINK_DMAX;     // how much bit go to the sink for D-channel?
     674                }
     675                else
     676                {
     677                        sink = (threshbit) ? SINK_MIN : SINK_MAX;       // how much bit go to the sink for B-channel?
     678                }
     679
     680                // prepare ISO Urb
     681                fill_isoc_urb(urb, fifo->hfc->dev, fifo->pipe,context_iso_urb->buffer, num_isoc_packets,
     682                        fifo->usb_packet_maxlen, fifo->intervall, tx_iso_complete, urb->context);
     683                memset(context_iso_urb->buffer, 0, sizeof(context_iso_urb->buffer));
     684
     685                frame_complete=FALSE;
     686
     687                // Generate Iso Packets
     688                for(k = 0; k < num_isoc_packets; ++k)
     689                {
     690                        if(fifo->skbuff)
     691                        {
     692                                len = fifo->skbuff->len;        // remaining length
     693
     694                                fifo->bit_line -= sink; // we lower data margin every msec
     695                                current_len = (0 - fifo->bit_line) / 8;
     696                                if(current_len > 14) current_len = 14;  // maximum 15 byte for every ISO packet makes our life easier
     697                                current_len = (len <= current_len) ? len : current_len;
     698                                fifo->bit_line += current_len * 8;      // how much bit do we put on the line?
     699
     700                                context_iso_urb->buffer[tx_offset] = 0;
     701                                if(current_len == len)
     702                                {
     703                                        if(!transp_mode)
     704                                        {
     705                                                context_iso_urb->buffer[tx_offset] = 1; // here frame completion
     706                                                fifo->bit_line += 32;   // add 2 byte flags and 16bit CRC at end of ISDN frame
     707                                        }
     708                                        frame_complete = TRUE;
     709                                }
     710
     711                                // copy bytes from buffer into ISO_URB
     712                                memcpy(context_iso_urb->buffer+tx_offset+1,fifo->skbuff->data,current_len);
     713                                skb_pull(fifo->skbuff,current_len);
     714
     715                                // define packet delimeters within the URB buffer
     716                                urb->iso_frame_desc[k].offset = tx_offset;
     717                                urb->iso_frame_desc[k].length = current_len + 1;
     718
     719                                tx_offset += (current_len + 1);
     720                                // 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);
     721                                if(!transp_mode)
     722                                {
     723                                        if(fifon==HFCUSB_B1_TX) handle_led(hfc,LED_B1_DATA);
     724                                        if(fifon==HFCUSB_B2_TX) handle_led(hfc,LED_B2_DATA);
     725                                }
     726                        }
     727                        else
     728                        {
     729                                // we have no more data - generate 1 byte ISO packets
     730                                urb->iso_frame_desc[k].offset = tx_offset++;
     731
     732                                urb->iso_frame_desc[k].length = 1;
     733                                fifo->bit_line -= sink; // we lower data margin every msec
     734
     735                                if(fifo->bit_line < BITLINE_INF)
     736                                {
     737                                        fifo->bit_line = BITLINE_INF;
     738                                        //printk (KERN_INFO "HFC-USB: BITLINE_INF underrun\n");
    506739                                }
    507                                 txfifo += 2;
    508740                        }
    509                 }
    510741
    511                 /* handle l1 events */
    512                 if ((fifo->buffer[0] >> 4) != hfc->l1_state) {
    513                         last_state = hfc->l1_state;
    514                         hfc->l1_state = fifo->buffer[0] >> 4;   /* update status */
    515                         if (timer_pending(&hfc->t4_timer))
    516                             del_timer(&hfc->t4_timer);
    517                         if (((hfc->l1_state == 3) &&
    518                              ((last_state == 7) ||
    519                               (last_state == 8))) ||
    520                             ((timer_pending(&hfc->t3_timer) &&
    521                             (hfc->l1_state == 8)))) {
    522                             hfc->t4_timer.expires = jiffies + 2;
    523                             add_timer(&hfc->t4_timer);
    524                         } else {
    525                                 if (timer_pending(&hfc->t3_timer)
    526                                     && (hfc->l1_state == 7))
    527                                         del_timer(&hfc->t3_timer);      /* no longer needed */
    528                                 test_and_set_bit(HFCUSB_L1_STATECHANGE,
    529                                                  &hfc->l1_event);
    530                                 queue_task(&hfc->l1_tq, &tq_immediate);
    531                                 mark_bh(IMMEDIATE_BH);
     742                        if(frame_complete)
     743                        {
     744                                // delete the buffer only once, here or in hfc_usb_l2l1() in a PH_DATA|REQUEST
     745                                fifo->delete_flg=TRUE;
     746
     747                                fifo->hif->l1l2(fifo->hif,PH_DATA|CONFIRM,(void*)fifo->skbuff->truesize);
     748
     749                                if(fifo->skbuff && fifo->delete_flg)
     750                                {
     751                                        dev_kfree_skb_any(fifo->skbuff);
     752                                        //printk(KERN_INFO "HFC-USB: skbuff=NULL on fifo:%d\n",fifo->fifonum);
     753                                        fifo->skbuff = NULL;
     754                                        fifo->delete_flg=FALSE;
     755                                }
     756
     757                                frame_complete=FALSE;
    532758                        }
     759        }
     760
     761                errcode = usb_submit_urb(urb);
     762                if(errcode < 0)
     763                {
     764                        printk(KERN_INFO "HFC-USB: error submitting ISO URB: %i \n",  errcode);
     765                }
     766        }
     767        else
     768        {
     769                if(urb->status)
     770                {
     771                        printk(KERN_INFO "HFC-USB: tx_iso_complete : urb->status %i, fifonum %i\n",  urb->status,fifon);
    533772                }
    534773        }
    535774
    536         /* check the length for data and move if present */
    537         if (fifo->next_complete || (urb->actual_length > fifo->rx_offset)) {
    538                 i = fifo->buff->len + urb->actual_length - fifo->rx_offset;     /* new total length */
    539                 hdlci = (fifo->transmode) ? 0 : 3;
    540                 if (i <= (fifo->max_size + hdlci)) {
    541                         memcpy(fifo->act_ptr,
    542                                fifo->buffer + fifo->rx_offset,
    543                                urb->actual_length - fifo->rx_offset);
    544                         fifo->act_ptr +=
    545                             (urb->actual_length - fifo->rx_offset);
    546                         fifo->buff->len +=
    547                             (urb->actual_length - fifo->rx_offset);
    548                 } else
    549                         fifo->buff->len = fifo->max_size + 4;   /* mark frame as to long */
    550                 if (fifo->next_complete && (urb->actual_length < fifo->usb_maxlen)) {
    551                     /* the frame is complete */
    552                     fifo->next_complete = 0;
    553                     if (((!*(fifo->act_ptr - 1)) || fifo->transmode) &&
    554                         (fifo->buff->len >= (hdlci + 1))
    555                         && (fifo->buff->len <=
    556                             (fifo->max_size + hdlci)) &&
    557                         ((skb = dev_alloc_skb(fifo->max_size + hdlci)) != NULL)) {
    558                         fifo->buff->len -= hdlci;       /* adjust size */
    559                         switch (fifo->fifonum) {
    560                             case HFCUSB_D_RX:
    561                                 skb_queue_tail(hfc->regd.
    562                                                drq,
    563                                                fifo->buff);
    564                                 test_and_set_bit
    565                                     (HFCUSB_L1_DRX,
    566                                      &hfc->l1_event);
    567                                 queue_task(&hfc->l1_tq,
    568                                            &tq_immediate);
    569                                 mark_bh(IMMEDIATE_BH);
    570                                 break;
     775}                               /* tx_iso_complete */
    571776
    572                             case HFCUSB_B1_RX:
    573                                 if (hfc->regd.brq[0]) {
    574                                     skb_queue_tail
    575                                         (hfc->regd.
    576                                          brq[0],
    577                                          fifo->buff);
    578                                     hfc->regd.
    579                                         bch_l1l2(hfc->
    580                                                  regd.
    581                                                  arg_hisax,
    582                                                  0,
    583                                                  PH_DATA
    584                                                  |
    585                                                  INDICATION,
    586                                                  (void *)
    587                                                  fifo->
    588                                                  buff);
    589                                 } else
    590                                     dev_kfree_skb_any
    591                                         (fifo->buff);
    592                                 break;
    593                                
    594                             case HFCUSB_B2_RX:
    595                                 if (hfc->regd.brq[1]) {
    596                                     skb_queue_tail
    597                                         (hfc->regd.
    598                                          brq[1],
    599                                          fifo->buff);
    600                                     hfc->regd.
    601                                         bch_l1l2(hfc->
    602                                                  regd.
    603                                                  arg_hisax,
    604                                                  1,
    605                                                  PH_DATA
    606                                                  |
    607                                                  INDICATION,
    608                                                  (void
    609                                                   *)
    610                                                  fifo->
    611                                                  buff);
    612                                 } else
    613                                     dev_kfree_skb_any
    614                                         (fifo->buff);
    615                                 break;
     777/*****************************************************/
     778/* receive completion routine for all ISO tx fifos   */
     779/*****************************************************/
     780static void rx_iso_complete(struct urb *urb)
     781{
     782        iso_urb_struct *context_iso_urb = (iso_urb_struct *) urb->context;
     783        usb_fifo *fifo = context_iso_urb->owner_fifo;
     784        hfcusb_data *hfc = fifo->hfc;
     785        int k, len, errcode, offset, num_isoc_packets,fifon;
     786        __u8 *buf;
    616787
    617                             case HFCUSB_PCM_RX:
    618                                 skb_queue_tail(&hfc->regd.
    619                                                erq,
    620                                                fifo->buff);
    621                                 test_and_set_bit
    622                                     (HFCUSB_L1_ERX,
    623                                      &hfc->l1_event);
    624                                 queue_task(&hfc->l1_tq,
    625                                            &tq_immediate);
    626                                 mark_bh(IMMEDIATE_BH);
    627                                 break;
     788        fifon=fifo->fifonum;
     789        // very weird error code when using ohci drivers, for now : ignore this error ...  (MB)
     790        if(urb->status == -EOVERFLOW)
     791        {
     792                urb->status = 0;
     793#ifdef VERBOSE_USB_DEBUG
     794                printk(KERN_INFO "HFC-USB: ignoring USB DATAOVERRUN  for fifo  %i \n",fifon);
     795#endif
     796        }
    628797
    629                             default:
    630                                 dev_kfree_skb_any(fifo->
    631                                                   buff);
    632                                 break;
     798        if(fifo->active && !urb->status)
     799        {
     800                num_isoc_packets=iso_packets[fifon];
     801
     802                // Generate D-Channel Iso Packets
     803                for(k = 0; k < num_isoc_packets; ++k)
     804                {
     805                        len=urb->iso_frame_desc[k].actual_length;
     806                        offset=urb->iso_frame_desc[k].offset;
     807                        buf=context_iso_urb->buffer+offset;
     808
     809                        if(fifo->last_urblen!=fifo->usb_packet_maxlen)
     810                        {
     811                                // the threshold mask is in the 2nd status byte
     812                                hfc->threshold_mask=buf[1];
     813                                // the S0 state is in the upper half of the 1st status byte
     814                                state_handler(hfc,buf[0] >> 4);
     815                                // if we have more than the 2 status bytes -> collect data
     816                                if(len>2) collect_rx_frame(fifo,buf+2,len-2,buf[0]&1);
    633817                        }
    634                         fifo->buff = skb;
    635                     }
    636                     fifo->buff->len = 0;        /* reset counter */
    637                     fifo->act_ptr = fifo->buff->data;   /* and pointer */
     818                        else collect_rx_frame(fifo,buf,len,0);
     819
     820                        fifo->last_urblen=len;
     821
     822        }
     823
     824                // prepare ISO Urb
     825                fill_isoc_urb(urb, fifo->hfc->dev, fifo->pipe,context_iso_urb->buffer, num_isoc_packets,
     826                        fifo->usb_packet_maxlen, fifo->intervall, rx_iso_complete, urb->context);
     827
     828                errcode = usb_submit_urb(urb);
     829                if(errcode < 0)
     830                {
     831                        printk(KERN_INFO "HFC-USB: error submitting ISO URB: %i \n",  errcode);
     832                }
     833        }
     834        else
     835        {
     836                if(urb->status)
     837                {
     838                        printk(KERN_INFO "HFC-USB: rx_iso_complete : urb->status %i, fifonum %i\n",  urb->status,fifon);
     839                }
     840        }
     841}                               /* rx_iso_complete */
     842
     843
     844/*****************************************************/
     845/* collect data from interrupt or isochron in        */
     846/*****************************************************/
     847static void collect_rx_frame(usb_fifo *fifo,__u8 *data,int len,int finish)
     848{
     849        hfcusb_data *hfc = fifo->hfc;
     850        int transp_mode,fifon;
     851
     852        fifon=fifo->fifonum;
     853        transp_mode=0;
     854        if(fifon<4 && hfc->b_mode[fifon/2]==L1_MODE_TRANS) transp_mode=TRUE;
     855
     856        //printk(KERN_INFO "HFC-USB: got %d bytes finish:%d max_size:%d fifo:%d\n",len,finish,fifo->max_size,fifon);
     857        if(!fifo->skbuff)
     858        {
     859                // allocate sk buffer
     860                fifo->skbuff=dev_alloc_skb(fifo->max_size + 3);
     861                if(!fifo->skbuff)
     862                {
     863                        printk(KERN_INFO "HFC-USB: cannot allocate buffer (dev_alloc_skb) fifo:%d\n",fifon);
     864                        return;
     865                }
     866               
     867        }
     868
     869        if(len && fifo->skbuff->len+len<fifo->max_size)
     870        {
     871                memcpy(skb_put(fifo->skbuff,len),data,len);
     872        }
     873        else printk(KERN_INFO "HCF-USB: got frame exceeded fifo->max_size:%d\n",fifo->max_size);
     874
     875        // give transparent data up, when 128 byte are available
     876        if(transp_mode && fifo->skbuff->len>=128)
     877        {
     878                fifo->hif->l1l2(fifo->hif,PH_DATA | INDICATION,fifo->skbuff);
     879                fifo->skbuff = NULL;  // buffer was freed from upper layer
     880                return;
     881        }
     882
     883        // we have a complete hdlc packet
     884        if(finish)
     885        {
     886                if(!fifo->skbuff->data[fifo->skbuff->len-1])
     887                {
     888                        skb_trim(fifo->skbuff,fifo->skbuff->len-3);  // remove CRC & status
     889
     890                        //printk(KERN_INFO "HFC-USB: got frame %d bytes on fifo:%d\n",fifo->skbuff->len,fifon);
     891
     892                        if(fifon==HFCUSB_PCM_RX) fifo->hif->l1l2(fifo->hif,PH_DATA_E | INDICATION,fifo->skbuff);
     893                        else fifo->hif->l1l2(fifo->hif,PH_DATA | INDICATION,fifo->skbuff);
     894
     895                        fifo->skbuff = NULL;  // buffer was freed from upper layer
     896                }
     897                else
     898                {
     899                        printk(KERN_INFO "HFC-USB: got frame %d bytes but CRC ERROR!!!\n",fifo->skbuff->len);
     900
     901                        skb_trim(fifo->skbuff,0);  // clear whole buffer
     902                }
     903        }
     904
     905        // LED flashing only in HDLC mode
     906        if(!transp_mode)
     907        {
     908                if(fifon==HFCUSB_B1_RX) handle_led(hfc,LED_B1_DATA);
     909                if(fifon==HFCUSB_B2_RX) handle_led(hfc,LED_B2_DATA);
     910        }
     911}
     912
     913/***********************************************/
     914/* receive completion routine for all rx fifos */
     915/***********************************************/
     916static void rx_complete(struct urb *urb)
     917{
     918        int len;
     919        __u8 *buf;
     920        usb_fifo *fifo = (usb_fifo *) urb->context;     /* pointer to our fifo */
     921        hfcusb_data *hfc = fifo->hfc;
     922
     923        urb->dev = hfc->dev;    /* security init */
     924
     925        if((!fifo->active) || (urb->status)) {
     926#ifdef VERBOSE_USB_DEBUG
     927                printk(KERN_INFO "HFC-USB: RX-Fifo %i is going down (%i)\n", fifo->fifonum, urb->status);
     928#endif
     929                fifo->urb->interval = 0;        /* cancel automatic rescheduling */
     930                if(fifo->skbuff) {
     931                        dev_kfree_skb_any(fifo->skbuff);
     932                        fifo->skbuff = NULL;
    638933                }
     934                return;
    639935        }
    640         fifo->rx_offset = (urb->actual_length < fifo->usb_maxlen) ? 2 : 0;
    641 }                               /* rx_complete */
     936
     937        len=urb->actual_length;
     938        buf=fifo->buffer;
     939
     940        if(fifo->last_urblen!=fifo->usb_packet_maxlen) {
     941                // the threshold mask is in the 2nd status byte
     942                hfc->threshold_mask=buf[1];
     943                // the S0 state is in the upper half of the 1st status byte
     944                state_handler(hfc,buf[0] >> 4);
     945                // if we have more than the 2 status bytes -> collect data
     946                if(len>2) collect_rx_frame(fifo,buf+2,urb->actual_length-2,buf[0]&1);
     947        } else
     948                collect_rx_frame(fifo,buf,urb->actual_length,0);
     949
     950        fifo->last_urblen=urb->actual_length;
     951
     952
     953}       /* rx_complete */
     954
     955
    642956
    643957/***************************************************/
    644958/* start the interrupt transfer for the given fifo */
    645959/***************************************************/
    646 static void
    647 start_rx_fifo(usb_fifo * fifo)
     960static void start_int_fifo(usb_fifo * fifo)
    648961{
    649         if (fifo->buff)
    650                 return;         /* still active */
    651         if (!
    652             (fifo->buff =
    653              dev_alloc_skb(fifo->max_size + (fifo->transmode ? 0 : 3))))
    654                 return;
    655         fifo->act_ptr = fifo->buff->data;
    656         FILL_INT_URB(&fifo->urb, fifo->hfc->dev, fifo->pipe, fifo->buffer,
    657                      fifo->usb_maxlen, rx_complete, fifo, fifo->intervall);
    658         fifo->next_complete = 0;
    659         fifo->rx_offset = 2;
    660         fifo->active = 1;       /* must be marked active */
    661         fifo->hfc->active_fifos |= fifo->fifo_mask;
    662         if (usb_submit_urb(&fifo->urb)) {
     962        int errcode;
     963
     964#ifdef VERBOSE_USB_DEBUG
     965        printk(KERN_INFO "HFC-USB: starting intr IN fifo:%d\n", fifo->fifonum);
     966#endif
     967        if (!fifo->urb) {
     968                fifo->urb = usb_alloc_urb(0);
     969                if (!fifo->urb)
     970                        return;
     971        }
     972        usb_fill_int_urb(fifo->urb, fifo->hfc->dev, fifo->pipe, fifo->buffer,
     973                                 fifo->usb_packet_maxlen, rx_complete, fifo, fifo->intervall);
     974        fifo->active = 1;               /* must be marked active */
     975        errcode = usb_submit_urb(fifo->urb);
     976
     977        if(errcode)
     978        {
     979                printk(KERN_INFO "HFC-USB: submit URB error(start_int_info): status:%i\n",   errcode);
    663980                fifo->active = 0;
    664                 fifo->hfc->active_fifos &= ~fifo->fifo_mask;
    665                 dev_kfree_skb_any(fifo->buff);
    666                 fifo->buff = NULL;
     981                fifo->skbuff = NULL;
    667982        }
    668 }                               /* start_rx_fifo */
     983} /* start_int_fifo */
    669984
    670 /***************************************************************/
    671 /* control completion routine handling background control cmds */
    672 /***************************************************************/
    673 static void
    674 ctrl_complete(purb_t urb)
     985/*****************************/
     986/* set the B-channel mode    */
     987/*****************************/
     988static void set_hfcmode(hfcusb_data *hfc,int channel,int mode)
    675989{
    676         hfcusb_data *hfc = (hfcusb_data *) urb->context;
     990        __u8 val,idx_table[2]={0,2};
    677991
    678         urb->dev = hfc->dev;
    679         if (hfc->ctrl_cnt) {
    680                 switch (hfc->ctrl_buff[hfc->ctrl_out_idx].hfc_reg) {
    681                         case HFCUSB_FIFO:
    682                                 hfc->ctrl_fifo =
    683                                     hfc->ctrl_buff[hfc->ctrl_out_idx].
    684                                     reg_val;
    685                                 break;
    686                         case HFCUSB_F_USAGE:
    687                                 if (!hfc->dfifo_fill) {
    688                                         fill_tx_urb(hfc->fifos +
    689                                                     HFCUSB_D_TX);
    690                                         if (hfc->fifos[HFCUSB_D_TX].buff)
    691                                                 usb_submit_urb(&hfc->
    692                                                                fifos
    693                                                                [HFCUSB_D_TX].
    694                                                                urb);
    695                                 } else {
    696                                         queue_control_request(hfc,
    697                                                               HFCUSB_FIFO,
    698                                                               HFCUSB_D_TX);
    699                                         queue_control_request(hfc,
    700                                                               HFCUSB_F_USAGE,
    701                                                               0);
    702                                 }
    703                                 break;
    704                         case HFCUSB_SCTRL_R:
    705                                 switch (hfc->ctrl_fifo) {
    706                                         case HFCUSB_B1_RX:
    707                                                 if (hfc->bch_enables & 1)
    708                                                         start_rx_fifo(hfc->
    709                                                                       fifos
    710                                                                       +
    711                                                                       HFCUSB_B1_RX);
    712                                                 break;
    713                                         case HFCUSB_B2_RX:
    714                                                 if (hfc->bch_enables & 2)
    715                                                         start_rx_fifo(hfc->
    716                                                                       fifos
    717                                                                       +
    718                                                                       HFCUSB_B2_RX);
    719                                                 break;
    720                                 }
    721                                 if (hfc->bch_enables & 3)
    722                                     hfc->led_req |= LED_BCH;
    723                                 else
    724                                     hfc->led_req &= ~LED_BCH;
    725                                 break;
    726                         case HFCUSB_P_DATA:
    727                                 hfc->led_act =
    728                                     hfc->ctrl_buff[hfc->ctrl_out_idx].
    729                                     reg_val;
    730                                 break;
    731                 }
    732                 hfc->ctrl_cnt--;        /* decrement actual count */
    733                 if (++hfc->ctrl_out_idx >= HFC_CTRL_BUFSIZE)
    734                         hfc->ctrl_out_idx = 0;  /* pointer wrap */
    735                 ctrl_start_transfer(hfc);       /* start next transfer */
     992#ifdef VERBOSE_ISDN_DEBUG
     993  printk (KERN_INFO "HFC-USB: setting channel %d to mode %d\n",channel,mode);
     994#endif
     995
     996        hfc->b_mode[channel]=mode;
     997
     998        // setup CON_HDLC
     999        val=0;
     1000        if(mode!=L1_MODE_NULL) val=8;    // enable fifo?
     1001        if(mode==L1_MODE_TRANS) val|=2;  // set transparent bit
     1002
     1003        queue_control_request(hfc,HFCUSB_FIFO,idx_table[channel],1); // set FIFO to transmit register
     1004        queue_control_request(hfc,HFCUSB_CON_HDLC,val,1);
     1005        queue_control_request(hfc,HFCUSB_INC_RES_F,2,1); // reset fifo
     1006
     1007        queue_control_request(hfc,HFCUSB_FIFO,idx_table[channel]+1,1); // set FIFO to receive register
     1008        queue_control_request(hfc,HFCUSB_CON_HDLC,val,1);
     1009        queue_control_request(hfc,HFCUSB_INC_RES_F,2,1);  // reset fifo
     1010
     1011        val=0x40;
     1012        if(hfc->b_mode[0]) val|=1;
     1013        if(hfc->b_mode[1]) val|=2;
     1014        queue_control_request(hfc,HFCUSB_SCTRL,val,1);
     1015
     1016        val=0;
     1017        if(hfc->b_mode[0]) val|=1;
     1018        if(hfc->b_mode[1]) val|=2;
     1019        queue_control_request(hfc,HFCUSB_SCTRL_R,val,1);
     1020
     1021        if(mode==L1_MODE_NULL)
     1022        {
     1023                if(channel) handle_led(hfc,LED_B2_OFF);
     1024                else handle_led(hfc,LED_B1_OFF);
    7361025        }
    737 }                               /* ctrl_complete */
     1026        else
     1027        {
     1028                if(channel) handle_led(hfc,LED_B2_ON);
     1029                else handle_led(hfc,LED_B1_ON);
     1030        }
     1031}
    7381032
    739 /*****************************************/
    740 /* Layer 1 + D channel access from HiSax */
    741 /*****************************************/
    742 static void
    743 hfcusb_l1_access(void *drvarg, int pr, void *arg)
    744 {
    745         hfcusb_data *hfc = (hfcusb_data *) drvarg;
    746 
    747         switch (pr) {
    748                 case (PH_DATA | REQUEST):
    749                 case (PH_PULL | INDICATION):
    750                         skb_queue_tail(hfc->regd.dsq,
    751                                        (struct sk_buff *) arg);
    752                         if (!hfc->fifos[HFCUSB_D_TX].active
    753                             && !hfc->dfifo_fill) {
    754                                 fill_tx_urb(hfc->fifos + HFCUSB_D_TX);
    755                                 hfc->active_fifos |=
    756                                     hfc->fifos[HFCUSB_D_TX].fifo_mask;
    757                                 usb_submit_urb(&hfc->fifos[HFCUSB_D_TX].
    758                                                urb);
    759                         }
    760                         break;
    761                 case (PH_ACTIVATE | REQUEST):
    762                     switch (hfc->l1_state) {
    763                         case 6:
    764                         case 8:
    765                                 hfc->regd.dch_l1l2(hfc->regd.arg_hisax,
    766                                                    (PH_DEACTIVATE |
    767                                                    INDICATION), NULL);
     1033/*
     1034   --------------------------------------------------------------------------------------
     1035   from here : hisax_if callback routines :
     1036     - void hfc_usb_d_l2l1(struct hisax_if *hisax_d_if, int pr, void *arg) {
    7681037
    769                                 break;
    770                         case 7:
    771                                 hfc->regd.dch_l1l2(hfc->regd.arg_hisax,
    772                                                    (PH_ACTIVATE |
    773                                                    INDICATION), NULL);
     1038   l1 to l2 routines :
     1039     - static void hfc_usb_l1l2(hfcusb_data * hfc)
    7741040
    775                                 break;
    776                         default:
    777                                 queue_control_request(hfc, HFCUSB_STATES, 0x60);        /* start activation */
    778                                 hfc->t3_timer.expires =
    779                                     jiffies + (HFC_TIMER_T3 * HZ) / 1000;
    780                                 if (!timer_pending(&hfc->t3_timer))
    781                                         add_timer(&hfc->t3_timer);
    782                                 break;
    783                     }
    784                     break;
     1041*/
    7851042
    786                 case (PH_DEACTIVATE | REQUEST):
    787                         queue_control_request(hfc, HFCUSB_STATES, 0x40);        /* start deactivation */
    788                         break;
    789                 default:
    790                         printk(KERN_INFO "unknown hfcusb l1_access 0x%x\n",
    791                                pr);
    792                         break;
    793         }
    794 }                               /* hfcusb_l1_access */
    795 
    796 /*******************************/
    797 /* B channel access from HiSax */
    798 /*******************************/
    799 static void
    800 hfcusb_bch_access(void *drvarg, int chan, int pr, void *arg)
    801 {
    802         hfcusb_data *hfc = (hfcusb_data *) drvarg;
    803         usb_fifo *fifo = hfc->fifos + (chan ? HFCUSB_B2_TX : HFCUSB_B1_TX);
    804         long flags;
    805 
    806         switch (pr) {
    807                 case (PH_DATA | REQUEST):
    808                 case (PH_PULL | INDICATION):
    809                         save_flags(flags);
    810                         cli();
    811                         if (!fifo->active) {
    812                                 fill_tx_urb(fifo);
    813                                 hfc->active_fifos |= fifo->fifo_mask;
    814                                 usb_submit_urb(&fifo->urb);
    815                         }
    816                         restore_flags(flags);
    817                         break;
    818                 case (PH_ACTIVATE | REQUEST):
    819                         if (!((int) arg)) {
    820                                 hfc->bch_enables &= ~(1 << chan);
    821                                 if (fifo->active) {
    822                                         fifo->active = 0;
    823                                         usb_unlink_urb(&fifo->urb);
     1043void hfc_usb_l2l1(struct hisax_if *my_hisax_if, int pr, void *arg)
     1044{
     1045    usb_fifo *fifo = my_hisax_if->priv;
     1046        hfcusb_data *hfc = fifo->hfc;
     1047
     1048    switch (pr) {
     1049                case PH_ACTIVATE | REQUEST:
     1050                                if(fifo->fifonum==HFCUSB_D_TX)
     1051                                {
     1052#ifdef VERBOSE_ISDN_DEBUG
     1053                                        printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_ACTIVATE | REQUEST\n");
     1054#endif
     1055                                        queue_control_request(hfc, HFCUSB_STATES,0x60,1);       /* make activation */
     1056                                        hfc->t3_timer.expires = jiffies + (HFC_TIMER_T3 * HZ) / 1000;
     1057                                        if(!timer_pending(&hfc->t3_timer)) add_timer(&hfc->t3_timer);
    8241058                                }
    825                                 save_flags(flags);
    826                                 cli();
    827                                 queue_control_request(hfc, HFCUSB_FIFO,
    828                                                       fifo->fifonum);
    829                                 queue_control_request(hfc,
    830                                                       HFCUSB_INC_RES_F, 2);
    831                                 queue_control_request(hfc, HFCUSB_CON_HDLC,
    832                                                       9);
    833                                 queue_control_request(hfc, HFCUSB_SCTRL,
    834                                                       0x40 +
    835                                                       hfc->bch_enables);
    836                                 queue_control_request(hfc, HFCUSB_SCTRL_R,
    837                                                       hfc->bch_enables);
    838                                 restore_flags(flags);
    839                                 fifo++;
    840                                 if (fifo->active) {
    841                                         fifo->active = 0;
    842                                         usb_unlink_urb(&fifo->urb);
     1059                                else
     1060                                {
     1061#ifdef VERBOSE_ISDN_DEBUG
     1062                                        printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_ACTIVATE | REQUEST\n");
     1063#endif
     1064                                        set_hfcmode(hfc,(fifo->fifonum==HFCUSB_B1_TX) ? 0 : 1 ,(int)arg);
     1065                                        fifo->hif->l1l2(fifo->hif,PH_ACTIVATE | INDICATION, NULL);
    8431066                                }
    844                                 return; /* fifo deactivated */
    845                         }
    846                         fifo->transmode = ((int) arg == L1_MODE_TRANS);
    847                         fifo->max_size =
    848                             ((fifo->transmode) ? fifo->
    849                              usb_maxlen : MAX_BCH_SIZE);
    850                         (fifo + 1)->transmode = fifo->transmode;
    851                         (fifo + 1)->max_size = fifo->max_size;
    852                         hfc->bch_enables |= (1 << chan);
    853                         save_flags(flags);
    854                         cli();
    855                         queue_control_request(hfc, HFCUSB_FIFO,
    856                                               fifo->fifonum);
    857                         queue_control_request(hfc, HFCUSB_CON_HDLC,
    858                                               ((!fifo->
    859                                                 transmode) ? 9 : 11));
    860                         queue_control_request(hfc, HFCUSB_INC_RES_F, 2);
    861                         queue_control_request(hfc, HFCUSB_SCTRL,
    862                                               0x40 + hfc->bch_enables);
    863                         if ((int) arg == L1_MODE_HDLC)
    864                                 queue_control_request(hfc, HFCUSB_CON_HDLC,
    865                                                       8);
    866                         queue_control_request(hfc, HFCUSB_FIFO,
    867                                               fifo->fifonum + 1);
    868                         queue_control_request(hfc, HFCUSB_CON_HDLC,
    869                                               ((!fifo->
    870                                                 transmode) ? 8 : 10));
    871                         queue_control_request(hfc, HFCUSB_INC_RES_F, 2);
    872                         queue_control_request(hfc, HFCUSB_SCTRL_R,
    873                                               hfc->bch_enables);
    874                         restore_flags(flags);
    875 
    876                         break;
    877 
    878                 default:
    879                         printk(KERN_INFO
    880                                "unknown hfcusb bch_access chan %d 0x%x\n",
    881                                chan, pr);
    882                         break;
    883         }
    884 }                               /* hfcusb_bch_access */
     1067                break;
     1068        case PH_DEACTIVATE | REQUEST:
     1069                                if(fifo->fifonum==HFCUSB_D_TX)
     1070                                {
     1071#ifdef VERBOSE_ISDN_DEBUG
     1072                                        printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_DEACTIVATE | REQUEST\n");
     1073#endif
     1074                                        printk (KERN_INFO "HFC-USB: ISDN TE device should not deativate...\n");
     1075                                }
     1076                                else
     1077                                {
     1078#ifdef VERBOSE_ISDN_DEBUG
     1079                                        printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_DEACTIVATE | REQUEST\n");
     1080#endif
     1081                                        set_hfcmode(hfc,(fifo->fifonum==HFCUSB_B1_TX) ? 0 : 1 ,(int)L1_MODE_NULL);
     1082                                        fifo->hif->l1l2(fifo->hif,PH_DEACTIVATE | INDICATION, NULL);
     1083                                }
     1084                break;
     1085                case PH_DATA | REQUEST:
     1086                                if(fifo->skbuff && fifo->delete_flg)
     1087                                {
     1088                                        dev_kfree_skb_any(fifo->skbuff);
     1089                                        //printk(KERN_INFO "skbuff=NULL on fifo:%d\n",fifo->fifonum);
     1090                                        fifo->skbuff = NULL;
     1091                                        fifo->delete_flg=FALSE;
     1092                                }
     1093
     1094                                fifo->skbuff=arg; // we have a new buffer
     1095
     1096                                //if(fifo->fifonum==HFCUSB_D_TX) printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_DATA | REQUEST\n");
     1097                                //else printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_DATA | REQUEST\n");
     1098                break;
     1099        default:
     1100                printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1: unkown state : %#x\n", pr);
     1101                break;
     1102    }
     1103}
     1104
     1105// valid configurations
     1106#define CNF_4INT3ISO  1      // 4 INT IN, 3 ISO OUT
     1107#define CNF_3INT3ISO  2      // 3 INT IN, 3 ISO OUT
     1108#define CNF_4ISO3ISO  3      // 4 ISO IN, 3 ISO OUT
     1109#define CNF_3ISO3ISO  4          // 3 ISO IN, 3 ISO OUT
     1110
     1111
     1112/*
     1113   --------------------------------------------------------------------------------------
     1114   From here on USB initialization and deactivation related routines are implemented :
     1115
     1116   - hfc_usb_init :
     1117      is the main Entry Point for the USB Subsystem when the device get plugged
     1118      in. This function calls usb_register with usb_driver as parameter.
     1119      Here, further entry points for probing (hfc_usb_probe) and disconnecting
     1120      the device (hfc_usb_disconnect) are published, as the id_table
     1121
     1122   - hfc_usb_probe
     1123      this function is called by the usb subsystem, and steps through the alternate
     1124      settings of the currently plugged in device to detect all Endpoints needed to
     1125      run an ISDN TA.
     1126      Needed EndPoints are
     1127      3 (+1) IntIn EndPoints   (D-in,  E-in, B1-in, B2-in, (E-in)) or
     1128      3 (+1) Isochron In Endpoints (D-out, B1-out, B2-out) and 3 IsoOut Endpoints
     1129      The currently used transfer mode of on the Out-Endpoints will be stored in
     1130      hfc->usb_transfer_mode and is either USB_INT or USB_ISO
     1131      When a valid alternate setting could be found, the usb_init (see blow)
     1132      function is called
     1133
     1134   - usb_init
     1135      Here, the HFC_USB Chip itself gets initialized and the USB framework to send/receive
     1136      Data to/from the several EndPoints are initialized:
     1137       The E- and D-Channel Int-In chain gets started
     1138       The IsoChain for the Iso-Out traffic get started
     1139
     1140   - hfc_usb_disconnect
     1141      this function is called by the usb subsystem and has to free all resources
     1142      and stop all usb traffic to allow a proper hotplugging disconnect.
     1143
     1144*/
    8851145
    8861146/***************************************************************************/
    8871147/* usb_init is called once when a new matching device is detected to setup */
    888 /* main parmeters. It registers the driver at the main hisax module.       */
     1148/* main parameters. It registers the driver at the main hisax module.       */
    8891149/* on success 0 is returned.                                               */
    8901150/***************************************************************************/
    891 static int
    892 usb_init(hfcusb_data * hfc)
     1151static int usb_init(hfcusb_data * hfc)
    8931152{
    8941153        usb_fifo *fifo;
    895         int i;
     1154        int i, err;
    8961155        u_char b;
    897 
     1156        struct hisax_b_if *p_b_if[2];
     1157       
    8981158        /* check the chip id */
    899         if ((Read_hfc(hfc, HFCUSB_CHIP_ID, &b) != 1) ||
    900             (b != HFCUSB_CHIPID)) {
     1159        printk(KERN_INFO "HFCUSB_CHIP_ID begin\n");
     1160        if (read_usb(hfc, HFCUSB_CHIP_ID, &b) != 1) {
     1161                printk(KERN_INFO "HFC-USB: cannot read chip id\n");
     1162                return(1);
     1163        }
     1164        printk(KERN_INFO "HFCUSB_CHIP_ID %x\n", b);
     1165        if (b != HFCUSB_CHIPID) {
    9011166                printk(KERN_INFO "HFC-USB: Invalid chip id 0x%02x\n", b);
    902                 return (1);
     1167                return(1);
    9031168        }
    9041169
    9051170        /* first set the needed config, interface and alternate */
    906         usb_set_configuration(hfc->dev, 1);
    907         usb_set_interface(hfc->dev, hfc->if_used, hfc->alt_used);
     1171        printk(KERN_INFO "usb_init 1\n");
     1172//      usb_set_configuration(hfc->dev, 1);
     1173        printk(KERN_INFO "usb_init 2\n");
     1174        err = usb_set_interface(hfc->dev, hfc->if_used, hfc->alt_used);
     1175        printk(KERN_INFO "usb_init usb_set_interface return %d\n", err);
     1176        /* now we initialize the chip */
     1177        write_usb(hfc, HFCUSB_CIRM, 8);     // do reset
     1178        write_usb(hfc, HFCUSB_CIRM, 0x10);      // aux = output, reset off
    9081179
    909         /* init the led state request */
    910         hfc->led_req = LED_DRIVER;
     1180        // set USB_SIZE to match the the wMaxPacketSize for INT or BULK transfers
     1181        write_usb(hfc, HFCUSB_USB_SIZE,(hfc->packet_size/8) | ((hfc->packet_size/8) << 4));
    9111182
    912         /* now we initialise the chip */
    913         Write_hfc(hfc, HFCUSB_CIRM, 0x10);      /* aux = output, reset off */
    914         Write_hfc(hfc, HFCUSB_P_DATA, 0);       /* leds = off */
    915         Write_hfc(hfc, HFCUSB_USB_SIZE,
    916                   (hfc->fifos[HFCUSB_B1_TX].usb_maxlen >> 3) |
    917                   ((hfc->fifos[HFCUSB_B1_RX].usb_maxlen >> 3) << 4));
     1183        // set USB_SIZE_I to match the the wMaxPacketSize for ISO transfers
     1184        write_usb(hfc, HFCUSB_USB_SIZE_I, hfc->iso_packet_size);
    9181185
    9191186        /* enable PCM/GCI master mode */
    920         Write_hfc(hfc, HFCUSB_MST_MODE1, 0);    /* set default values */
    921         Write_hfc(hfc, HFCUSB_MST_MODE0, 1);    /* enable master mode */
     1187        write_usb(hfc, HFCUSB_MST_MODE1, 0);    /* set default values */
     1188        write_usb(hfc, HFCUSB_MST_MODE0, 1);    /* enable master mode */
    9221189
    9231190        /* init the fifos */
    924         Write_hfc(hfc, HFCUSB_F_THRES, (HFCUSB_TX_THRESHOLD >> 3) |
    925                   ((HFCUSB_RX_THRESHOLD >> 3) << 4));
     1191        write_usb(hfc, HFCUSB_F_THRES, (HFCUSB_TX_THRESHOLD/8) |((HFCUSB_RX_THRESHOLD/8) << 4));
    9261192
    927         for (i = 0, fifo = hfc->fifos + i; i < HFCUSB_NUM_FIFOS;
    928              i++, fifo++) {
    929                 Write_hfc(hfc, HFCUSB_FIFO, i); /* select the desired fifo */
    930 
    931                 fifo->transmode = 0;    /* hdlc mode selected */
    932                 fifo->buff = NULL;      /* init buffer pointer */
    933                 fifo->max_size =
    934                     (i <= HFCUSB_B2_RX) ? MAX_BCH_SIZE : MAX_DFRAME_LEN;
    935                 Write_hfc(hfc, HFCUSB_HDLC_PAR, ((i <= HFCUSB_B2_RX) ? 0 : 2)); /* data length */
    936                 Write_hfc(hfc, HFCUSB_CON_HDLC, ((i & 1) ? 0x08 : 0x09));       /* rx hdlc, tx fill 1 */
    937                 Write_hfc(hfc, HFCUSB_INC_RES_F, 2);    /* reset the fifo */
    938         }
    939 
    940         Write_hfc(hfc, HFCUSB_CLKDEL, 0x0f);    /* clock delay value */
    941         Write_hfc(hfc, HFCUSB_STATES, 3 | 0x10);        /* set deactivated mode */
    942         Write_hfc(hfc, HFCUSB_STATES, 3);       /* enable state machine */
     1193        fifo = hfc->fifos;
     1194        for(i = 0; i < HFCUSB_NUM_FIFOS; i++)
     1195        {
     1196                write_usb(hfc, HFCUSB_FIFO, i); /* select the desired fifo */
     1197                fifo[i].skbuff = NULL;  /* init buffer pointer */
     1198                fifo[i].max_size = (i <= HFCUSB_B2_RX) ? MAX_BCH_SIZE : MAX_DFRAME_LEN;
     1199                fifo[i].last_urblen=0;
     1200                write_usb(hfc, HFCUSB_HDLC_PAR, ((i <= HFCUSB_B2_RX) ? 0 : 2));     // set 2 bit for D- & E-channel
     1201                write_usb(hfc, HFCUSB_CON_HDLC, ((i==HFCUSB_D_TX) ? 0x09 : 0x08));      // rx hdlc, enable IFF for D-channel
     1202                write_usb(hfc, HFCUSB_INC_RES_F, 2);    /* reset the fifo */
     1203        }
    9431204
    944         Write_hfc(hfc, HFCUSB_SCTRL_R, 0);      /* disable both B receivers */
    945         Write_hfc(hfc, HFCUSB_SCTRL, 0x40);     /* disable B transmitters + cap mode */
     1205        write_usb(hfc, HFCUSB_CLKDEL, 0x0f);     /* clock delay value */
     1206        write_usb(hfc, HFCUSB_STATES, 3 | 0x10); /* set deactivated mode */
     1207        write_usb(hfc, HFCUSB_STATES, 3);            /* enable state machine */
     1208
     1209        write_usb(hfc, HFCUSB_SCTRL_R, 0);           /* disable both B receivers */
     1210        write_usb(hfc, HFCUSB_SCTRL, 0x40);          /* disable B transmitters + capacitive mode */
     1211
     1212        // set both B-channel to not connected
     1213        hfc->b_mode[0]=L1_MODE_NULL;
     1214        hfc->b_mode[1]=L1_MODE_NULL;
     1215
     1216        hfc->l1_activated=FALSE;
     1217        hfc->led_state=0;
     1218        hfc->led_new_data=0;
    9461219
    947         /* init the l1 timer */
     1220        /* init the t3 timer */
    9481221        init_timer(&hfc->t3_timer);
    9491222        hfc->t3_timer.data = (long) hfc;
    950         hfc->t3_timer.function = (void *) l1_timer_expire;
     1223        hfc->t3_timer.function = (void *) l1_timer_expire_t3;
     1224        /* init the t4 timer */
     1225        init_timer(&hfc->t4_timer);
    9511226        hfc->t4_timer.data = (long) hfc;
    952         hfc->t4_timer.function = (void *) l1_timer_expire;
    953         hfc->l1_tq.routine = (void *) (void *) usb_l1d_bh;
    954         hfc->l1_tq.sync = 0;
    955         hfc->l1_tq.data = hfc;
    956 
    957         /* init the background control machinery */
    958         hfc->ctrl_read.requesttype = 0xc0;
    959         hfc->ctrl_read.request = 1;
    960         hfc->ctrl_read.length = 1;
    961         hfc->ctrl_write.requesttype = 0x40;
    962         hfc->ctrl_write.request = 0;
    963         hfc->ctrl_write.length = 0;
    964         FILL_CONTROL_URB(&hfc->ctrl_urb, hfc->dev, hfc->ctrl_out_pipe,
    965                          (u_char *) & hfc->ctrl_write, NULL, 0,
    966                          ctrl_complete, hfc);
    967 
    968         /* init the TX-urbs */
    969         fifo = hfc->fifos + HFCUSB_D_TX;
    970         FILL_BULK_URB(&fifo->urb, hfc->dev, fifo->pipe,
    971                       (u_char *) fifo->buffer, 0, tx_complete, fifo);
    972         fifo = hfc->fifos + HFCUSB_B1_TX;
    973         FILL_BULK_URB(&fifo->urb, hfc->dev, fifo->pipe,
    974                       (u_char *) fifo->buffer, 0, tx_complete, fifo);
    975         fifo = hfc->fifos + HFCUSB_B2_TX;
    976         FILL_BULK_URB(&fifo->urb, hfc->dev, fifo->pipe,
    977                       (u_char *) fifo->buffer, 0, tx_complete, fifo);
    978 
    979         /* init the E-buffer */
    980         skb_queue_head_init(&hfc->regd.erq);
    981 
    982         /* now register ourself at hisax */
    983         hfc->regd.version = HISAX_LOAD_VERSION; /* set our version */
    984         hfc->regd.cmd = HISAX_LOAD_REGISTER;    /* register command */
    985         hfc->regd.argl1 = (void *) hfc; /* argument for our local routine */
    986         hfc->regd.dch_l2l1 = hfcusb_l1_access;
    987         hfc->regd.bch_l2l1 = hfcusb_bch_access;
    988         hfc->regd.drvname = "hfc_usb";
    989         if (hisax_register_hfcusb(&hfc->regd)) {
    990                 printk(KERN_INFO "HFC-USB failed to register at hisax\n");
    991                 Write_hfc(hfc, HFCUSB_CIRM, 0x08);      /* aux = input, reset on */
    992                 return (1);
    993         }
    994 
    995         /* startup the D- and E-channel fifos */
    996         start_rx_fifo(hfc->fifos + HFCUSB_D_RX);        /* D-fifo */
    997         if (hfc->fifos[HFCUSB_PCM_RX].pipe)
    998                 start_rx_fifo(hfc->fifos + HFCUSB_PCM_RX);      /* E-fifo */
     1227        hfc->t4_timer.function = (void *) l1_timer_expire_t4;
     1228        /* init the led timer */
     1229        init_timer(&hfc->led_timer);
     1230        hfc->led_timer.data = (long) hfc;
     1231        hfc->led_timer.function = (void *) led_timer;
     1232        // trigger 4 hz led timer
     1233        hfc->led_timer.expires = jiffies + (LED_TIME * HZ) / 1000;
     1234        if(!timer_pending(&hfc->led_timer)) add_timer(&hfc->led_timer);
     1235
     1236        // init the background machinery for control requests
     1237        hfc->ctrl_read.bRequestType = 0xc0;
     1238        hfc->ctrl_read.bRequest = 1;
     1239        hfc->ctrl_read.wLength = 1;
     1240        hfc->ctrl_write.bRequestType = 0x40;
     1241        hfc->ctrl_write.bRequest = 0;
     1242        hfc->ctrl_write.wLength = 0;
     1243        usb_fill_control_urb(hfc->ctrl_urb, hfc->dev, hfc->ctrl_out_pipe,(u_char *) & hfc->ctrl_write, NULL, 0, ctrl_complete, hfc);
     1244                                       
     1245        /* Init All Fifos */
     1246        for(i = 0; i < HFCUSB_NUM_FIFOS; i++)
     1247        {
     1248                hfc->fifos[i].iso[0].purb = NULL;
     1249                hfc->fifos[i].iso[1].purb = NULL;
     1250                hfc->fifos[i].active = 0;
     1251        }
     1252
     1253        // register like Germaschewski :
     1254        hfc->d_if.owner = THIS_MODULE;
     1255        hfc->d_if.ifc.priv = &hfc->fifos[HFCUSB_D_TX];
     1256        hfc->d_if.ifc.l2l1 = hfc_usb_l2l1;
     1257
     1258        for (i=0; i<2; i++)
     1259        {
     1260                hfc->b_if[i].ifc.priv = &hfc->fifos[HFCUSB_B1_TX+i*2];
     1261                hfc->b_if[i].ifc.l2l1 = hfc_usb_l2l1;
     1262                p_b_if[i] = &hfc->b_if[i];
     1263        }
     1264       
     1265        hfc->protocol = 2;  /* default EURO ISDN, should be a module_param */
     1266        hisax_register(&hfc->d_if, p_b_if, "hfc_usb", hfc->protocol);
     1267       
     1268        for (i=0; i<4; i++)
     1269                hfc->fifos[i].hif=&p_b_if[i/2]->ifc;
     1270        for (i=4; i<8; i++)
     1271                hfc->fifos[i].hif=&hfc->d_if.ifc;
     1272
     1273        // 3 (+1) INT IN + 3 ISO OUT
     1274        if(hfc->cfg_used == CNF_3INT3ISO || hfc->cfg_used == CNF_4INT3ISO)
     1275        {
     1276                start_int_fifo(hfc->fifos + HFCUSB_D_RX);       // Int IN D-fifo
     1277                if(hfc->fifos[HFCUSB_PCM_RX].pipe) start_int_fifo(hfc->fifos + HFCUSB_PCM_RX);  // E-fifo
     1278                start_int_fifo(hfc->fifos + HFCUSB_B1_RX);      // Int IN B1-fifo
     1279                start_int_fifo(hfc->fifos + HFCUSB_B2_RX);      // Int IN B2-fifo
     1280        }
     1281
     1282        // 3 (+1) ISO IN + 3 ISO OUT
     1283        if(hfc->cfg_used==CNF_3ISO3ISO || hfc->cfg_used==CNF_4ISO3ISO)
     1284        {
     1285                start_isoc_chain(hfc->fifos + HFCUSB_D_RX, ISOC_PACKETS_D, rx_iso_complete,16);
     1286                if(hfc->fifos[HFCUSB_PCM_RX].pipe) start_isoc_chain(hfc->fifos + HFCUSB_PCM_RX, ISOC_PACKETS_D, rx_iso_complete,16);
     1287                start_isoc_chain(hfc->fifos + HFCUSB_B1_RX, ISOC_PACKETS_B, rx_iso_complete,16);
     1288                start_isoc_chain(hfc->fifos + HFCUSB_B2_RX, ISOC_PACKETS_B, rx_iso_complete,16);
     1289        }
     1290
     1291        start_isoc_chain(hfc->fifos + HFCUSB_D_TX, ISOC_PACKETS_D, tx_iso_complete,1);
     1292        start_isoc_chain(hfc->fifos + HFCUSB_B1_TX, ISOC_PACKETS_B, tx_iso_complete,1);
     1293        start_isoc_chain(hfc->fifos + HFCUSB_B2_TX, ISOC_PACKETS_B, tx_iso_complete,1);
     1294
     1295        handle_led(hfc,LED_POWER_ON);
     1296
     1297        return(0);
     1298}       /* usb_init */
     1299
     1300
     1301/****************************************/
     1302/* data defining the devices to be used */
     1303/****************************************/
     1304// static __devinitdata const struct usb_device_id hfc_usb_idtab[3] = {
     1305static struct usb_device_id hfc_usb_idtab[] = {
     1306        {USB_DEVICE(0x7b0, 0x0007)},    /* Billion USB TA 2 */
     1307        {USB_DEVICE(0x742, 0x2008)},    /* Stollmann USB TA */
     1308        {USB_DEVICE(0x959, 0x2bd0)},    /* Colognechip USB eval TA */
     1309        {USB_DEVICE(0x8e3, 0x0301)},    /* OliTec ISDN USB */
     1310        {USB_DEVICE(0x675, 0x1688)},    /* DrayTec ISDN USB */
     1311        {USB_DEVICE(0x7fa, 0x0846)},    /* Bewan ISDN USB TA */
     1312        {}                              /* end with an all-zeroes entry */
     1313};
     1314
     1315MODULE_AUTHOR("Peter Sprenger (sprenger@moving-byters.de)/Martin Bachem (info@colognechip.com)");
     1316MODULE_DESCRIPTION("HFC I4L USB driver");
     1317MODULE_DEVICE_TABLE(usb, hfc_usb_idtab);
     1318MODULE_LICENSE("GPL");
     1319
     1320#define EP_NUL 1    // Endpoint at this position not allowed
     1321#define EP_NOP 2        // all type of endpoints allowed at this position
     1322#define EP_ISO 3        // Isochron endpoint mandatory at this position
     1323#define EP_BLK 4        // Bulk endpoint mandatory at this position
     1324#define EP_INT 5        // Interrupt endpoint mandatory at this position
     1325
     1326// this array represents all endpoints possible in the HCF-USB
     1327// the last 2 entries are the configuration number and the minimum interval for Interrupt endpoints
     1328int validconf[][18]=
     1329{
     1330        // INT in, ISO out config
     1331        {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},
     1332        {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},
     1333        // ISO in, ISO out config
     1334        {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},
     1335        {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},
     1336        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}       // EOL element
     1337};
     1338
     1339// string description of chosen config
     1340char *conf_str[]=
     1341{
     1342        "4 Interrupt IN + 3 Isochron OUT",
     1343        "3 Interrupt IN + 3 Isochron OUT",
     1344        "4 Isochron IN + 3 Isochron OUT",
     1345        "3 Isochron IN + 3 Isochron OUT"
     1346};
    9991347
    1000         return (0);
    1001 }                               /* usb_init */
    10021348
    10031349/*************************************************/
    10041350/* function called to probe a new plugged device */
    10051351/*************************************************/
    1006 static void *
    1007 hfc_usb_probe(struct usb_device *dev, unsigned int interface
    1008 #ifdef COMPAT_HAS_USB_IDTAB
    1009               , const struct usb_device_id *id_table)
    1010 #else
    1011     )
    1012 #endif
     1352//static int hfc_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
     1353static void* hfc_usb_probe(struct usb_device *dev, unsigned int ifnum, const struct usb_device_id *id)
    10131354{
     1355        //struct usb_device *dev= interface_to_usbdev(intf);
     1356        struct usb_interface* intf = dev->actconfig->interface + ifnum;
    10141357        hfcusb_data *context;
    1015         struct usb_interface *ifp = dev->actconfig->interface + interface;
    1016         struct usb_interface_descriptor *ifdp =
    1017             ifp->altsetting + ifp->act_altsetting;
    1018         struct usb_endpoint_descriptor *epd;
    1019         int i, idx, ep_msk;
    1020 
    1021 #ifdef COMPAT_HAS_USB_IDTAB
    1022         if (id_table && (dev->descriptor.idVendor == id_table->idVendor) &&
    1023             (dev->descriptor.idProduct == id_table->idProduct) &&
    1024 #else
    1025         if ((((dev->descriptor.idVendor == 0x959) &&
    1026             (dev->descriptor.idProduct == 0x2bd0)) ||
    1027             ((dev->descriptor.idVendor == 0x7b0) &&
    1028             (dev->descriptor.idProduct == 0x0006))) &&
    1029 #endif
    1030             (ifdp->bNumEndpoints >= 6) && (ifdp->bNumEndpoints <= 16)) {
    1031                 if (!(context = kmalloc(sizeof(hfcusb_data), GFP_KERNEL))) {
    1032                         return (NULL);  /* got no mem */
    1033                 };
    1034                 memset(context, 0, sizeof(hfcusb_data));        /* clear the structure */
    1035                 i = ifdp->bNumEndpoints;        /* get number of endpoints */
    1036                 ep_msk = 0;     /* none found */
    1037                 epd = ifdp->endpoint;   /* first endpoint descriptor */
    1038                 while (i-- && ((ep_msk & 0xcf) != 0xcf)) {
    1039 
    1040                         idx = (((epd->bEndpointAddress & 0x7f) - 1) << 1);      /* get endpoint base */
    1041                         if (idx < 7) {
    1042                                 switch (epd->bmAttributes) {
    1043                                         case USB_ENDPOINT_XFER_INT:
    1044                                                 if (!
    1045                                                     (epd->
    1046                                                      bEndpointAddress &
    1047                                                      0x80))
    1048                                                         break;  /* only interrupt in allowed */
    1049                                                 idx++;  /* input index is odd */
    1050                                                 context->fifos[idx].pipe =
    1051                                                     usb_rcvintpipe(dev,
    1052                                                                    epd->
    1053                                                                    bEndpointAddress);
    1054                                                 break;
    1055 
    1056                                         case USB_ENDPOINT_XFER_BULK:
    1057                                                 if (epd->
    1058                                                     bEndpointAddress &
    1059                                                     0x80)
    1060                                                         break;  /* only bulk out allowed */
    1061                                                 context->fifos[idx].pipe =
    1062                                                     usb_sndbulkpipe(dev,
    1063                                                                     epd->
    1064                                                                     bEndpointAddress);
    1065                                                 break;
    1066                                         default:
    1067                                                 context->fifos[idx].pipe = 0;   /* reset data */
    1068                                 }       /* switch attribute */
    1069 
    1070                                 if (context->fifos[idx].pipe) {
    1071                                         context->fifos[idx].fifonum = idx;
    1072                                         context->fifos[idx].fifo_mask =
    1073                                             1 << idx;
    1074                                         context->fifos[idx].hfc = context;
    1075                                         context->fifos[idx].usb_maxlen =
    1076                                             epd->wMaxPacketSize;
    1077                                         context->fifos[idx].intervall =
    1078                                             epd->bInterval;
    1079                                         ep_msk |= (1 << idx);
    1080                                 } else
    1081                                         ep_msk &= ~(1 << idx);
    1082                         }       /* idx < 7 */
    1083                         epd++;
    1084                 }
     1358        //struct usb_host_interface *iface = intf->cur_altsetting;
     1359        //struct usb_host_interface *iface_used = NULL;
     1360        //struct usb_host_endpoint *ep;
     1361        struct usb_endpoint_descriptor* ep;
     1362        //int ifnum = iface->desc.bInterfaceNumber;
     1363        struct usb_interface_descriptor* intfdesc = intf->altsetting + intf->act_altsetting;
     1364        struct usb_interface_descriptor* intfdesc_used = NULL;
     1365        int i, idx, alt_idx, probe_alt_setting, vend_idx, cfg_used, *vcf, attr, cfg_found, cidx, ep_addr;
     1366        int cmptbl[16],small_match,iso_packet_size,packet_size,alt_used=0;
     1367
     1368//        usb_show_device(dev);
     1369//      usb_show_device_descriptor(&dev->descriptor);
     1370//      usb_show_interface_descriptor(&iface->desc);
     1371        vend_idx=0xffff;
     1372        for(i=0;vdata[i].vendor;i++)
     1373        {
     1374                if(dev->descriptor.idVendor==vdata[i].vendor && dev->descriptor.idProduct==vdata[i].prod_id) vend_idx=i;
     1375        }
     1376       
    10851377
    1086                 if ((ep_msk & 0x3f) != 0x3f) {
    1087                         kfree(context);
    1088                         return (NULL);
    1089                 }
    1090                 MOD_INC_USE_COUNT;      /* lock our module */
    1091                 context->dev = dev;     /* save device */
    1092                 context->if_used = interface;   /* save used interface */
    1093                 context->alt_used = ifp->act_altsetting;        /* and alternate config */
    1094                 context->ctrl_paksize = dev->descriptor.bMaxPacketSize0;        /* control size */
    1095 
    1096                 /* create the control pipes needed for register access */
    1097                 context->ctrl_in_pipe = usb_rcvctrlpipe(context->dev, 0);
    1098                 context->ctrl_out_pipe = usb_sndctrlpipe(context->dev, 0);
    1099 
    1100                 /* init the chip and register the driver */
    1101                 if (usb_init(context)) {
    1102                         kfree(context);
    1103                         MOD_DEC_USE_COUNT;
    1104                         return (NULL);
    1105                 }
     1378#ifdef VERBOSE_USB_DEBUG       
     1379        printk(KERN_INFO "HFC-USB: probing interface(%d) actalt(%d)\n",
     1380                ifnum, intfdesc->bAlternateSetting);
     1381        /*      printk(KERN_INFO "HFC-USB: probing interface(%d) actalt(%d) minor(%d)\n",
     1382                ifnum, intfdesc->bAlternateSetting, intf->driver->minor); */
     1383#endif
    11061384
    1107                 printk(KERN_INFO
    1108                        "HFC-USB: New device if=%d alt=%d registered\n",
    1109                        context->if_used, context->alt_used);
    1110                 return (context);
    1111         }
     1385        if (vend_idx != 0xffff) {
     1386#ifdef VERBOSE_USB_DEBUG
     1387                printk(KERN_INFO "HFC-USB: found vendor idx:%d  name:%s\n",vend_idx,vdata[vend_idx].vend_name);
     1388#endif
     1389                /* if vendor and product ID is OK, start probing a matching alternate setting ... */
     1390                alt_idx = 0;
     1391                small_match=0xffff;
     1392                // default settings
     1393                iso_packet_size=16;
     1394                packet_size=64;
     1395
     1396                while (alt_idx < intf->num_altsetting) {
     1397                        //iface = intf->altsetting + alt_idx;
     1398                        intfdesc = intf->altsetting + alt_idx;
     1399                        probe_alt_setting = intfdesc->bAlternateSetting;
     1400                        cfg_used=0;
    11121401
    1113         return (NULL);          /* no matching entry */
    1114 }                               /* hfc_usb_probe */
     1402#ifdef VERBOSE_USB_DEBUG
     1403                        printk(KERN_INFO "HFC-USB: test alt_setting %d\n", probe_alt_setting);
     1404#endif
     1405                        // check for config EOL element
     1406                        while (validconf[cfg_used][0]) {
     1407                                cfg_found=TRUE;
     1408                                vcf=validconf[cfg_used];
     1409                                ep = intfdesc->endpoint;        /* first endpoint descriptor */
     1410
     1411#ifdef VERBOSE_USB_DEBUG
     1412                                printk(KERN_INFO "HFC-USB: (if=%d alt=%d cfg_used=%d)\n",
     1413                                        ifnum, probe_alt_setting, cfg_used);
     1414#endif
     1415                                // copy table
     1416                                memcpy(cmptbl,vcf,16*sizeof(int));
     1417
     1418                                // check for all endpoints in this alternate setting
     1419                                for (i=0; i < intfdesc->bNumEndpoints; i++) {
     1420                                        ep_addr = ep->bEndpointAddress;
     1421                                        idx = ((ep_addr & 0x7f)-1)*2;   /* get endpoint base */
     1422                                        if (ep_addr & 0x80)
     1423                                                idx++;
     1424                                        attr = ep->bmAttributes;
     1425
     1426                                        if (cmptbl[idx] == EP_NUL) {
     1427                                                printk(KERN_INFO "HFC-USB: cfg_found=FALSE in idx:%d  attr:%d  cmptbl[%d]:%d\n",
     1428                                                        idx, attr, idx, cmptbl[idx]);
     1429                                                cfg_found = FALSE;
     1430                                        }
     1431
     1432                                        if (attr == USB_ENDPOINT_XFER_INT && cmptbl[idx] == EP_INT)
     1433                                                cmptbl[idx] = EP_NUL;
     1434                                        if (attr == USB_ENDPOINT_XFER_BULK && cmptbl[idx] == EP_BLK)
     1435                                                cmptbl[idx] = EP_NUL;
     1436                                        if (attr == USB_ENDPOINT_XFER_ISOC && cmptbl[idx] == EP_ISO)
     1437                                                cmptbl[idx] = EP_NUL;
     1438
     1439                                        // check if all INT endpoints match minimum interval
     1440                                        if (attr == USB_ENDPOINT_XFER_INT && ep->bInterval < vcf[17]) {
     1441#ifdef VERBOSE_USB_DEBUG
     1442                                                if (cfg_found)
     1443                                                        printk(KERN_INFO "HFC-USB: Interrupt Endpoint interval < %d found - skipping config\n",
     1444                                                                vcf[17]);
     1445#endif
     1446                                                cfg_found = FALSE;
     1447                                        }
     1448
     1449                                        ep++;
     1450                                }
     1451
     1452                                for (i = 0; i < 16; i++) {
     1453                                        // printk(KERN_INFO "HFC-USB: cmptbl[%d]:%d\n", i, cmptbl[i]);
     1454
     1455                                        // all entries must be EP_NOP or EP_NUL for a valid config
     1456                                        if (cmptbl[i] != EP_NOP && cmptbl[i] != EP_NUL)
     1457                                                cfg_found = FALSE;
     1458                                }
     1459
     1460                                // we check for smallest match, to provide configuration priority
     1461                                // configurations with smaller index have higher priority
     1462                                if (cfg_found) {
     1463                                        if (cfg_used < small_match) {
     1464                                                small_match = cfg_used;
     1465                                                alt_used = probe_alt_setting;
     1466                                                //iface_used = iface;
     1467                                                intfdesc_used = intfdesc;
     1468                                        }
     1469#ifdef VERBOSE_USB_DEBUG
     1470                                        printk(KERN_INFO "HFC-USB: small_match=%x %x\n", small_match, alt_used);
     1471#endif
     1472                                }
     1473
     1474                                cfg_used++;
     1475                        }
     1476
     1477                        alt_idx++;
     1478                }               /* (alt_idx < intf->num_altsetting) */
     1479#ifdef VERBOSE_USB_DEBUG
     1480                printk(KERN_INFO "HFC-USB: final small_match=%x alt_used=%x\n",small_match, alt_used);
     1481#endif
     1482                // yiipiee, we found a valid config
     1483                if (small_match != 0xffff) {
     1484                        //iface = iface_used;
     1485                        intfdesc = intfdesc_used;
     1486
     1487                        if (!(context = kmalloc(sizeof(hfcusb_data), GFP_KERNEL)))
     1488                                return(NULL);  /* got no mem */
     1489                        memset(context, 0, sizeof(hfcusb_data));        /* clear the structure */
     1490
     1491                        ep = intfdesc->endpoint;        /* first endpoint descriptor */
     1492                        vcf = validconf[small_match];
     1493
     1494                        for (i = 0; i < intfdesc->bNumEndpoints; i++) {
     1495                                ep_addr = ep->bEndpointAddress;
     1496                                idx = ((ep_addr & 0x7f)-1)*2;   /* get endpoint base */
     1497                                if (ep_addr & 0x80)
     1498                                        idx++;
     1499                                cidx = idx & 7;
     1500                                attr = ep->bmAttributes;
     1501
     1502                                // only initialize used endpoints
     1503                                if (vcf[idx] != EP_NOP && vcf[idx] != EP_NUL) {
     1504                                        switch (attr) {
     1505                                                case USB_ENDPOINT_XFER_INT:
     1506                                                        context->fifos[cidx].pipe = usb_rcvintpipe(dev, ep->bEndpointAddress);
     1507                                                        context->fifos[cidx].usb_transfer_mode = USB_INT;
     1508                                                        packet_size = ep->wMaxPacketSize; // remember max packet size
     1509#ifdef VERBOSE_USB_DEBUG
     1510                                                        printk (KERN_INFO "HFC-USB: Interrupt-In Endpoint found %d ms(idx:%d cidx:%d)!\n",
     1511                                                                ep->bInterval, idx, cidx);
     1512#endif
     1513                                                        break;
     1514                                                case USB_ENDPOINT_XFER_BULK:
     1515                                                        if (ep_addr & 0x80)
     1516                                                                context->fifos[cidx].pipe = usb_rcvbulkpipe(dev, ep->bEndpointAddress);
     1517                                                        else
     1518                                                                context->fifos[cidx].pipe = usb_sndbulkpipe(dev, ep->bEndpointAddress);
     1519                                                        context->fifos[cidx].usb_transfer_mode = USB_BULK;
     1520                                                        packet_size = ep->wMaxPacketSize; // remember max packet size
     1521#ifdef VERBOSE_USB_DEBUG
     1522                                                        printk (KERN_INFO "HFC-USB: Bulk Endpoint found (idx:%d cidx:%d)!\n",
     1523                                                                idx, cidx);
     1524#endif
     1525                                                        break;
     1526                                                case USB_ENDPOINT_XFER_ISOC:
     1527                                                        if (ep_addr & 0x80)
     1528                                                                context->fifos[cidx].pipe = usb_rcvisocpipe(dev, ep->bEndpointAddress);
     1529                                                        else
     1530                                                                context->fifos[cidx].pipe = usb_sndisocpipe(dev, ep->bEndpointAddress);
     1531                                                        context->fifos[cidx].usb_transfer_mode = USB_ISOC;
     1532                                                        iso_packet_size = ep->wMaxPacketSize; // remember max packet size
     1533#ifdef VERBOSE_USB_DEBUG
     1534                                                        printk (KERN_INFO "HFC-USB: ISO Endpoint found (idx:%d cidx:%d)!\n",
     1535                                                                idx, cidx);
     1536#endif
     1537                                                        break;
     1538                                                default:
     1539                                                        context->fifos[cidx].pipe = 0;  /* reset data */
     1540                                        }       /* switch attribute */
     1541
     1542                                        if (context->fifos[cidx].pipe) {
     1543                                                context->fifos[cidx].fifonum = cidx;
     1544                                                context->fifos[cidx].hfc = context;
     1545                                                context->fifos[cidx].usb_packet_maxlen = ep->wMaxPacketSize;
     1546                                                context->fifos[cidx].intervall = ep->bInterval;
     1547                                                context->fifos[cidx].skbuff = NULL;
     1548#ifdef VERBOSE_USB_DEBUG
     1549                                                printk (KERN_INFO "HFC-USB: fifo%d pktlen %d interval %d\n",
     1550                                                        context->fifos[cidx].fifonum,
     1551                                                        context->fifos[cidx].usb_packet_maxlen,
     1552                                                        context->fifos[cidx].intervall);
     1553#endif
     1554                                        }
     1555                                }
     1556
     1557                                ep++;
     1558                        }
     1559
     1560                        // now share our luck
     1561                        context->dev = dev;                                             /* save device */
     1562                        context->if_used = ifnum;                                       /* save used interface */
     1563                        context->alt_used = alt_used;                                   /* and alternate config */
     1564                        context->ctrl_paksize = dev->descriptor.bMaxPacketSize0;        /* control size */
     1565                        context->cfg_used=vcf[16];                                      // store used config
     1566                        context->vend_idx=vend_idx;                                     // store found vendor
     1567                        context->packet_size=packet_size;
     1568                        context->iso_packet_size=iso_packet_size;
     1569
     1570                        /* create the control pipes needed for register access */
     1571                        context->ctrl_in_pipe = usb_rcvctrlpipe(context->dev, 0);
     1572                        context->ctrl_out_pipe = usb_sndctrlpipe(context->dev, 0);
     1573                        context->ctrl_urb = usb_alloc_urb(0);
     1574
     1575                        printk(KERN_INFO "HFC-USB: detected \"%s\" configuration: %s (if=%d alt=%d)\n",
     1576                                vdata[vend_idx].vend_name, conf_str[small_match], context->if_used, context->alt_used);
     1577
     1578                        /* init the chip and register the driver */
     1579                        if (usb_init(context))
     1580                        {
     1581                                if (context->ctrl_urb) {
     1582                                        usb_unlink_urb(context->ctrl_urb);
     1583                                        usb_free_urb(context->ctrl_urb);
     1584                                        context->ctrl_urb = NULL;
     1585                                }
     1586                                kfree(context);
     1587                                return(NULL);
     1588                        }
     1589                        //usb_set_intfdata(intf, context);
     1590                        //intf->private_data = context;
     1591                        return(context);
     1592                }
     1593        }
     1594        return(NULL);
     1595}
    11151596
    11161597/****************************************************/
    11171598/* function called when an active device is removed */
    11181599/****************************************************/
    1119 static void
    1120 hfc_usb_disconnect(struct usb_device *usbdev, void *drv_context)
     1600//static void hfc_usb_disconnect(struct usb_interface *intf)
     1601static void hfc_usb_disconnect(struct usb_device *usbdev, void* drv_context)
    11211602{
    1122         hfcusb_data *context = drv_context;
     1603        //hfcusb_data *context = intf->private_data;
     1604        hfcusb_data* context = drv_context;
    11231605        int i;
    1124         struct sk_buff *skb;
    11251606
    1126         /* tell all fifos to terminate */
    1127         for (i = 0; i < HFCUSB_NUM_FIFOS; i++)
    1128                 if (context->fifos[i].active) {
    1129                         context->fifos[i].active = 0;
    1130                         usb_unlink_urb(&context->fifos[i].urb);
    1131                 }
    1132         while (context->active_fifos) {
    1133                 set_current_state(TASK_INTERRUPTIBLE);
    1134                 /* Timeout 10ms */
    1135                 schedule_timeout((10 * HZ) / 1000);
    1136         }
     1607        printk(KERN_INFO "HFC-USB: device disconnect\n");
     1608       
     1609        //intf->private_data = NULL;
     1610        if (!context)
     1611                return;
    11371612        if (timer_pending(&context->t3_timer))
    11381613                del_timer(&context->t3_timer);
    1139         context->regd.release_driver(context->regd.arg_hisax);
    1140         while ((skb = skb_dequeue(&context->regd.erq)) != NULL)
    1141                 dev_kfree_skb_any(skb);
     1614        if (timer_pending(&context->t4_timer))
     1615                del_timer(&context->t4_timer);
     1616        if (timer_pending(&context->led_timer))
     1617                del_timer(&context->led_timer);
     1618
     1619        hisax_unregister(&context->d_if);
    11421620
     1621        /* tell all fifos to terminate */
     1622        for(i = 0; i < HFCUSB_NUM_FIFOS; i++) {
     1623                if(context->fifos[i].usb_transfer_mode == USB_ISOC) {
     1624                        if(context->fifos[i].active > 0) {
     1625                                stop_isoc_chain(&context->fifos[i]);
     1626#ifdef VERBOSE_USB_DEBUG
     1627                                printk (KERN_INFO "HFC-USB: hfc_usb_disconnect: stopping ISOC chain Fifo no %i\n", i);
     1628#endif
     1629                        }
     1630                } else {
     1631                        if(context->fifos[i].active > 0) {
     1632                                context->fifos[i].active = 0;
     1633#ifdef VERBOSE_USB_DEBUG
     1634                                printk (KERN_INFO "HFC-USB: hfc_usb_disconnect: unlinking URB for Fifo no %i\n", i);
     1635#endif
     1636                        }
     1637                        if (context->fifos[i].urb) {
     1638                                usb_unlink_urb(context->fifos[i].urb);
     1639                                usb_free_urb(context->fifos[i].urb);
     1640                                context->fifos[i].urb = NULL;
     1641                        }
     1642                }
     1643                context->fifos[i].active = 0;
     1644        }
     1645        if (context->ctrl_urb) {
     1646                usb_unlink_urb(context->ctrl_urb);
     1647                usb_free_urb(context->ctrl_urb);
     1648                context->ctrl_urb = NULL;
     1649        }
    11431650        kfree(context);         /* free our structure again */
    1144         MOD_DEC_USE_COUNT;      /* and decrement the usage counter */
    11451651}                               /* hfc_usb_disconnect */
    11461652
     1653
    11471654/************************************/
    11481655/* our driver information structure */
    11491656/************************************/
    11501657static struct usb_driver hfc_drv = {
    11511658        name:"hfc_usb",
    1152 #ifdef COMPAT_HAS_USB_IDTAB
    11531659        id_table:hfc_usb_idtab,
    1154 #endif
    11551660        probe:hfc_usb_probe,
    11561661        disconnect:hfc_usb_disconnect,
    11571662};
    11581663
    1159 static void __exit
    1160 hfc_usb_exit(void)
    1161 {
    11621664
     1665static void __exit hfc_usb_exit(void)
     1666{
     1667#ifdef VERBOSE_USB_DEBUG
     1668        printk ("HFC-USB: calling \"hfc_usb_exit\" ...\n");
     1669#endif
    11631670        usb_deregister(&hfc_drv);       /* release our driver */
    11641671        printk(KERN_INFO "HFC-USB module removed\n");
    11651672}
    11661673
    1167 static int __init
    1168 hfc_usb_init(void)
     1674static int __init hfc_usb_init(void)
    11691675{
    1170         struct hisax_drvreg drv;
     1676        printk ("HFC-USB: driver module revision %s loaded\n", hfcusb_revision);
    11711677
    1172         drv.version = HISAX_LOAD_VERSION;       /* set our version */
    1173         drv.cmd = HISAX_LOAD_CHKVER;    /* check command only */
    1174         if (hisax_register_hfcusb(&drv)) {
    1175                 printk(KERN_INFO "HFC-USB <-> hisax version conflict\n");
    1176                 return (-1);    /* unable to register */
    1177         }
    1178         if (usb_register(&hfc_drv)) {
    1179                 printk(KERN_INFO
    1180                        "Unable to register HFC-USB module at usb stack\n");
    1181                 return (-1);    /* unable to register */
     1678        if(usb_register(&hfc_drv))
     1679        {
     1680                printk(KERN_INFO "HFC-USB: Unable to register HFC-USB module at usb stack\n");
     1681                return(-1);                /* unable to register */
    11821682        }
    1183 
    1184         printk(KERN_INFO "HFC-USB module loaded\n");
    1185         return (0);
     1683        return(0);
    11861684}
    11871685
     1686
     1687
     1688
     1689
    11881690module_init(hfc_usb_init);
    11891691module_exit(hfc_usb_exit);
     1692
Note: See TracBrowser for help on using the repository browser.