diff --git a/drivers/isdn/Config.in b/drivers/isdn/Config.in index a31c0ce9..2bd5f929 100644 --- a/drivers/isdn/Config.in +++ b/drivers/isdn/Config.in @@ -83,6 +83,10 @@ if [ "$CONFIG_ISDN_DRV_HISAX" != "n" ]; then dep_tristate 'ELSA PCMCIA MicroLink cards' CONFIG_HISAX_ELSA_CS $CONFIG_PCMCIA dep_tristate 'ST5481 USB ISDN modem (EXPERIMENTAL)' CONFIG_HISAX_ST5481 $CONFIG_HISAX $CONFIG_USB $CONFIG_EXPERIMENTAL dep_tristate 'Fritz!PCIv2 support (EXPERIMENTAL)' CONFIG_HISAX_FRITZ_PCIPNP $CONFIG_HISAX $CONFIG_EXPERIMENTAL + dep_tristate 'Cologne Chip AG HFC-S USB based ISDN TAs (EXPERIMANTAL)' CONFIG_HISAX_HFCUSB_CS $CONFIG_ISDN_DRV_HISAX $CONFIG_EXPERIMENTAL + if [ "$CONFIG_HISAX_HFCUSB_CS" != "n" ]; then + bool ' skip module usage counting (not recommended)' CONFIG_HFC_USB_SKIP_MOD_COUNTING + fi fi endmenu diff --git a/drivers/isdn/hisax/Makefile b/drivers/isdn/hisax/Makefile index 36d535ea..ade95162 100644 --- a/drivers/isdn/hisax/Makefile +++ b/drivers/isdn/hisax/Makefile @@ -10,11 +10,12 @@ export-objs := config.o fsm.o hisax_isac.o # Multipart objects. -list-multi := hisax.o hisax_st5481.o +list-multi := hisax.o hisax_st5481.o hfc_usb.o hisax-objs := config.o isdnl1.o tei.o isdnl2.o isdnl3.o \ lmgr.o q931.o callc.o fsm.o cert.o hisax_st5481-objs := st5481_init.o st5481_usb.o st5481_d.o st5481_b.o \ st5481_hdlc.o +hfc_usb-objs := hfc_usb.o # Optional parts of multipart objects. hisax-objs-$(CONFIG_HISAX_EURO) += l3dss1.o @@ -60,6 +61,7 @@ obj-$(CONFIG_HISAX_SEDLBAUER_CS) += sedlbauer_cs.o obj-$(CONFIG_HISAX_ELSA_CS) += elsa_cs.o obj-$(CONFIG_HISAX_ST5481) += hisax_st5481.o obj-$(CONFIG_HISAX_FRITZ_PCIPNP) += hisax_fcpcipnp.o hisax_isac.o +obj-$(CONFIG_HISAX_HFCUSB_CS) += hfc_usb.o CERT := $(shell md5sum -c md5sums.asc >> /dev/null;echo $$?) CFLAGS_cert.o := -DCERTIFICATION=$(CERT) diff --git a/drivers/isdn/hisax/hfc_usb.c b/drivers/isdn/hisax/hfc_usb.c new file mode 100644 index 00000000..eeea9eea --- /dev/null +++ b/drivers/isdn/hisax/hfc_usb.c @@ -0,0 +1,1830 @@ +/* + * hfc_usb.c + * + * $Id$ + * + * modular HiSax ISDN driver for Colognechip HFC-S USB chip + * + * Authors : Peter Sprenger (sprenger@moving-bytes.de) + * Martin Bachem (info@colognechip.com) + * based on the first hfc_usb driver of Werner Cornelius (werner@isdn-development.de) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * See Version Histroy at the bottom of this file + * +*/ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "hisax.h" +#include "hisax_if.h" +#include "hfc_usb.h" + + +static const char *hfcusb_revision = + "Revision: 4.29.2.5 $ Date: 2005/04/11 08:46:12 $ "; + + +/* Hisax debug support +* use "modprobe debug=x" where x is bitfield of USB_DBG & ISDN_DBG +*/ +#ifdef CONFIG_HISAX_DEBUG +#define __debug_variable hfc_debug +#include "hisax_debug.h" +static int debug = 0x0; +MODULE_PARM(debug, "i"); +int hfc_debug; +#endif + + +/* private vendor specific data */ +typedef struct { + __u8 led_scheme; // led display scheme + signed short led_bits[8]; // array of 8 possible LED bitmask settings + char *vend_name; // device name +} hfcsusb_vdata; + +/****************************************/ +/* data defining the devices to be used */ +/****************************************/ +static struct usb_device_id hfcusb_idtab[] = { + { + .idVendor = 0x0959, + .idProduct = 0x2bd0, + .driver_info = (unsigned long) &((hfcsusb_vdata) + {LED_OFF, {4, 0, 2, 1}, + "ISDN USB TA (Cologne Chip HFC-S USB based)"}), + }, + { + .idVendor = 0x0675, + .idProduct = 0x1688, + .driver_info = (unsigned long) &((hfcsusb_vdata) + {LED_SCHEME1, {1, 2, 0, 0}, + "DrayTek miniVigor 128 USB ISDN TA"}), + }, + { + .idVendor = 0x07b0, + .idProduct = 0x0007, + .driver_info = (unsigned long) &((hfcsusb_vdata) + {LED_SCHEME1, {0x80, -64, -32, -16}, + "Billion tiny USB ISDN TA 128"}), + }, + { + .idVendor = 0x0742, + .idProduct = 0x2008, + .driver_info = (unsigned long) &((hfcsusb_vdata) + {LED_SCHEME1, {4, 0, 2, 1}, + "Stollmann USB TA"}), + }, + { + .idVendor = 0x0742, + .idProduct = 0x2009, + .driver_info = (unsigned long) &((hfcsusb_vdata) + {LED_SCHEME1, {4, 0, 2, 1}, + "Aceex USB ISDN TA"}), + }, + { + .idVendor = 0x0742, + .idProduct = 0x200A, + .driver_info = (unsigned long) &((hfcsusb_vdata) + {LED_SCHEME1, {4, 0, 2, 1}, + "OEM USB ISDN TA"}), + }, + { + .idVendor = 0x08e3, + .idProduct = 0x0301, + .driver_info = (unsigned long) &((hfcsusb_vdata) + {LED_SCHEME1, {2, 0, 1, 4}, + "Olitec USB RNIS"}), + }, + { + .idVendor = 0x07fa, + .idProduct = 0x0846, + .driver_info = (unsigned long) &((hfcsusb_vdata) + {LED_SCHEME1, {0x80, -64, -32, -16}, + "Bewan Modem RNIS USB"}), + }, + { + .idVendor = 0x07fa, + .idProduct = 0x0847, + .driver_info = (unsigned long) &((hfcsusb_vdata) + {LED_SCHEME1, {0x80, -64, -32, -16}, + "Djinn Numeris USB"}), + }, + { + .idVendor = 0x07b0, + .idProduct = 0x0006, + .driver_info = (unsigned long) &((hfcsusb_vdata) + {LED_SCHEME1, {0x80, -64, -32, -16}, + "Twister ISDN TA"}), + }, +}; + + +/***************************************************************/ +/* structure defining input+output fifos (interrupt/bulk mode) */ +/***************************************************************/ + +struct usb_fifo; /* forward definition */ +typedef struct iso_urb_struct { + struct urb *purb; + __u8 buffer[128]; /* buffer incoming/outgoing data */ + struct usb_fifo *owner_fifo; // pointer to owner fifo +} iso_urb_struct; + + +struct hfcusb_data; /* forward definition */ +typedef struct usb_fifo { + int fifonum; /* fifo index attached to this structure */ + int active; /* fifo is currently active */ + struct hfcusb_data *hfc; /* pointer to main structure */ + int pipe; /* address of endpoint */ + __u8 usb_packet_maxlen; /* maximum length for usb transfer */ + unsigned int max_size; /* maximum size of receive/send packet */ + __u8 intervall; /* interrupt interval */ + struct sk_buff *skbuff; /* actual used buffer */ + struct urb urb; /* transfer structure for usb routines */ + __u8 buffer[128]; /* buffer incoming/outgoing data */ + int bit_line; /* how much bits are in the fifo? */ + + volatile __u8 usb_transfer_mode; /* switched between ISO and INT */ + iso_urb_struct iso[2]; /* need two urbs to have one always for pending */ + struct hisax_if *hif; /* hisax interface */ + int delete_flg; /* only delete skbuff once */ + int last_urblen; /* remember length of last packet */ + +} usb_fifo; + +/*********************************************/ +/* structure holding all data for one device */ +/*********************************************/ +typedef struct hfcusb_data { + // HiSax Interface for loadable Layer1 drivers + struct hisax_d_if d_if; /* see hisax_if.h */ + struct hisax_b_if b_if[2]; /* see hisax_if.h */ + int protocol; + + struct usb_device *dev; /* our device */ + int if_used; /* used interface number */ + int alt_used; /* used alternate config */ + int ctrl_paksize; /* control pipe packet size */ + int ctrl_in_pipe, ctrl_out_pipe; /* handles for control pipe */ + int cfg_used; /* configuration index used */ + int vend_idx; // vendor found + + int b_mode[2]; // B-channel mode + + int l1_activated; // layer 1 activated + int disc_flag; // ignore some error when disconnect + + int packet_size, iso_packet_size; + + /* control pipe background handling */ + ctrl_buft ctrl_buff[HFC_CTRL_BUFSIZE]; /* buffer holding queued data */ + volatile int ctrl_in_idx, ctrl_out_idx, ctrl_cnt; /* input/output pointer + count */ + struct urb ctrl_urb; /* transfer structure for control channel */ + + struct usb_ctrlrequest ctrl_write; /* buffer for control write request */ + struct usb_ctrlrequest ctrl_read; /* same for read request */ + + __u8 old_led_state, led_state, led_new_data, led_b_active; + + volatile __u8 threshold_mask; /* threshold actually reported */ + volatile __u8 bch_enables; /* or mask for sctrl_r and sctrl register values */ + + usb_fifo fifos[HFCUSB_NUM_FIFOS]; /* structure holding all fifo data */ + + volatile __u8 l1_state; /* actual l1 state */ + struct timer_list t3_timer; /* timer 3 for activation/deactivation */ + struct timer_list t4_timer; /* timer 4 for activation/deactivation */ + +} hfcusb_data; + + +static void collect_rx_frame(usb_fifo * fifo, __u8 * data, int len, + int finish); + + +static inline const char * +symbolic(struct hfcusb_symbolic_list list[], const int num) +{ + int i; + for (i = 0; list[i].name != NULL; i++) + if (list[i].num == num) + return (list[i].name); + return ""; +} + + +/******************************************************/ +/* start next background transfer for control channel */ +/******************************************************/ +static void +ctrl_start_transfer(hfcusb_data * hfc) +{ + if (hfc->ctrl_cnt) { + hfc->ctrl_urb.pipe = hfc->ctrl_out_pipe; + hfc->ctrl_urb.setup_packet = (u_char *) & hfc->ctrl_write; + hfc->ctrl_urb.transfer_buffer = NULL; + hfc->ctrl_urb.transfer_buffer_length = 0; + hfc->ctrl_write.wIndex = + hfc->ctrl_buff[hfc->ctrl_out_idx].hfc_reg; + hfc->ctrl_write.wValue = + hfc->ctrl_buff[hfc->ctrl_out_idx].reg_val; + + usb_submit_urb(&hfc->ctrl_urb); /* start transfer */ + } +} /* ctrl_start_transfer */ + +/************************************/ +/* queue a control transfer request */ +/* return 0 on success. */ +/************************************/ +static int +queue_control_request(hfcusb_data * hfc, __u8 reg, __u8 val, int action) +{ + ctrl_buft *buf; + + //printk ("HFC_USB: queue_control_request reg: %x, val: %x\n", reg, val); + + if (hfc->ctrl_cnt >= HFC_CTRL_BUFSIZE) + return (1); /* no space left */ + buf = &hfc->ctrl_buff[hfc->ctrl_in_idx]; /* pointer to new index */ + buf->hfc_reg = reg; + buf->reg_val = val; + buf->action = action; + if (++hfc->ctrl_in_idx >= HFC_CTRL_BUFSIZE) + hfc->ctrl_in_idx = 0; /* pointer wrap */ + if (++hfc->ctrl_cnt == 1) + ctrl_start_transfer(hfc); + return (0); +} /* queue_control_request */ + + +static int +control_action_handler(hfcusb_data * hfc, int reg, int val, int action) +{ + if (!action) + return (1); // no action defined + + return (0); +} + +/***************************************************************/ +/* control completion routine handling background control cmds */ +/***************************************************************/ +static void +ctrl_complete(struct urb *urb) +{ + hfcusb_data *hfc = (hfcusb_data *) urb->context; + ctrl_buft *buf; + + urb->dev = hfc->dev; + if (hfc->ctrl_cnt) { + buf = &hfc->ctrl_buff[hfc->ctrl_out_idx]; + control_action_handler(hfc, buf->hfc_reg, buf->reg_val, + buf->action); + + hfc->ctrl_cnt--; /* decrement actual count */ + if (++hfc->ctrl_out_idx >= HFC_CTRL_BUFSIZE) + hfc->ctrl_out_idx = 0; /* pointer wrap */ + + ctrl_start_transfer(hfc); /* start next transfer */ + } +} /* ctrl_complete */ + +/***************************************************/ +/* write led data to auxport & invert if necessary */ +/***************************************************/ +static void +write_led(hfcusb_data * hfc, __u8 led_state) +{ + if (led_state != hfc->old_led_state) { + hfc->old_led_state = led_state; + queue_control_request(hfc, HFCUSB_P_DATA, led_state, 1); +#ifdef CONFIG_HISAX_DEBUG + DBG(USB_DBG, "HFCUSB_P_DATA: %x\n", led_state); +#endif + + } +} + +/**************************/ +/* handle LED bits */ +/**************************/ +static void +set_led_bit(hfcusb_data * hfc, signed short led_bits, int unset) +{ + if (unset) { + if (led_bits < 0) + hfc->led_state |= abs(led_bits); + else + hfc->led_state &= ~led_bits; + } else { + if (led_bits < 0) + hfc->led_state &= ~abs(led_bits); + else + hfc->led_state |= led_bits; + } + + //printk(KERN_INFO "led_state:%x led_bits:%d unset:%d\n",hfc->led_state,led_bits,unset); +} + +/**************************/ +/* handle LED requests */ +/**************************/ +static void +handle_led(hfcusb_data * hfc, int event) +{ + hfcsusb_vdata *driver_info = + (hfcsusb_vdata *) hfcusb_idtab[hfc->vend_idx].driver_info; + + // if no scheme -> no LED action + if (driver_info->led_scheme == LED_OFF) + return; + + switch (event) { + case LED_POWER_ON: + set_led_bit(hfc, driver_info->led_bits[0], + 0); + set_led_bit(hfc, driver_info->led_bits[1], + 1); + set_led_bit(hfc, driver_info->led_bits[2], + 1); + set_led_bit(hfc, driver_info->led_bits[3], + 1); + break; + case LED_POWER_OFF: // no Power off handling + break; + case LED_S0_ON: + set_led_bit(hfc, driver_info->led_bits[1], + 0); + break; + case LED_S0_OFF: + set_led_bit(hfc, driver_info->led_bits[1], + 1); + break; + case LED_B1_ON: + set_led_bit(hfc, driver_info->led_bits[2], + 0); + break; + case LED_B1_OFF: + set_led_bit(hfc, driver_info->led_bits[2], + 1); + break; + case LED_B2_ON: + set_led_bit(hfc, driver_info->led_bits[3], + 0); + break; + case LED_B2_OFF: + set_led_bit(hfc, driver_info->led_bits[3], + 1); + break; + } + write_led(hfc, hfc->led_state); +} + +/********************************/ +/* called when timer t3 expires */ +/********************************/ +static void +l1_timer_expire_t3(hfcusb_data * hfc) +{ + hfc->d_if.ifc.l1l2(&hfc->d_if.ifc, PH_DEACTIVATE | INDICATION, + NULL); +#ifdef CONFIG_HISAX_DEBUG + DBG(ISDN_DBG, + "HFC-S USB: PH_DEACTIVATE | INDICATION sent (T3 expire)"); +#endif + hfc->l1_activated = FALSE; + handle_led(hfc, LED_S0_OFF); + queue_control_request(hfc, HFCUSB_STATES, 0x10, 1); // deactivate + queue_control_request(hfc, HFCUSB_STATES, 3, 1); // deactivate +} + +/********************************/ +/* called when timer t4 expires */ +/********************************/ +static void +l1_timer_expire_t4(hfcusb_data * hfc) +{ + hfc->d_if.ifc.l1l2(&hfc->d_if.ifc, PH_DEACTIVATE | INDICATION, + NULL); +#ifdef CONFIG_HISAX_DEBUG + DBG(ISDN_DBG, + "HFC-S USB: PH_DEACTIVATE | INDICATION sent (T4 expire)"); +#endif + hfc->l1_activated = FALSE; + handle_led(hfc, LED_S0_OFF); +} + +/*****************************/ +/* handle S0 state changes */ +/*****************************/ +static void +state_handler(hfcusb_data * hfc, __u8 state) +{ + __u8 old_state; + + old_state = hfc->l1_state; + + // range check + if (state == old_state || state < 1 || state > 8) + return; + +#ifdef CONFIG_HISAX_DEBUG + DBG(ISDN_DBG, "HFC-S USB: new S0 state:%d old_state:%d", state, + old_state); +#endif + if (state < 4 || state == 7 || state == 8) { + if (timer_pending(&hfc->t3_timer)) + del_timer(&hfc->t3_timer); +#ifdef CONFIG_HISAX_DEBUG + DBG(ISDN_DBG, "HFC-S USB: T3 deactivated"); +#endif + } + if (state >= 7) { + if (timer_pending(&hfc->t4_timer)) + del_timer(&hfc->t4_timer); +#ifdef CONFIG_HISAX_DEBUG + DBG(ISDN_DBG, "HFC-S USB: T4 deactivated"); +#endif + } + + if (state == 7 && !hfc->l1_activated) { + hfc->d_if.ifc.l1l2(&hfc->d_if.ifc, + PH_ACTIVATE | INDICATION, NULL); +#ifdef CONFIG_HISAX_DEBUG + DBG(ISDN_DBG, "HFC-S USB: PH_ACTIVATE | INDICATION sent"); +#endif + hfc->l1_activated = TRUE; + handle_led(hfc, LED_S0_ON); + } else if (state <= 3 /* && activated */ ) { + if (old_state == 7 || old_state == 8) { +#ifdef CONFIG_HISAX_DEBUG + DBG(ISDN_DBG, "HFC-S USB: T4 activated"); +#endif + hfc->t4_timer.expires = + jiffies + (HFC_TIMER_T4 * HZ) / 1000; + if (!timer_pending(&hfc->t4_timer)) + add_timer(&hfc->t4_timer); + } else { + hfc->d_if.ifc.l1l2(&hfc->d_if.ifc, + PH_DEACTIVATE | INDICATION, + NULL); +#ifdef CONFIG_HISAX_DEBUG + DBG(ISDN_DBG, + "HFC-S USB: PH_DEACTIVATE | INDICATION sent"); +#endif + hfc->l1_activated = FALSE; + handle_led(hfc, LED_S0_OFF); + } + } + + hfc->l1_state = state; +} + + +/* prepare iso urb */ +static void +fill_isoc_urb(struct urb *urb, struct usb_device *dev, unsigned int pipe, + void *buf, int num_packets, int packet_size, + usb_complete_t complete, void *context) +{ + spin_lock_init(&urb->lock); // do we really need spin_lock_init ? + urb->dev = dev; + urb->pipe = pipe; + urb->complete = complete; + urb->number_of_packets = num_packets; + urb->transfer_buffer_length = packet_size * num_packets; + urb->context = context; + urb->transfer_buffer = buf; + urb->transfer_flags = USB_ISO_ASAP; +} + +/* allocs urbs and start isoc transfer with two pending urbs to avoid gaps in the transfer chain */ +static int +start_isoc_chain(usb_fifo * fifo, int num_packets_per_urb, + usb_complete_t complete, int packet_size) +{ + int i, k, errcode; + +#ifdef CONFIG_HISAX_DEBUG + DBG(USB_DBG, "HFC-S USB: starting ISO-chain for Fifo %i", + fifo->fifonum); +#endif + + // allocate Memory for Iso out Urbs + for (i = 0; i < 2; i++) { + if (!(fifo->iso[i].purb)) { + fifo->iso[i].purb = + usb_alloc_urb(num_packets_per_urb); + fifo->iso[i].owner_fifo = (struct usb_fifo *) fifo; + + // Init the first iso + if ((int) sizeof(fifo->iso[i].buffer) >= + (fifo->usb_packet_maxlen * + num_packets_per_urb)) { + + fill_isoc_urb(fifo->iso[i].purb, + fifo->hfc->dev, fifo->pipe, + fifo->iso[i].buffer, + num_packets_per_urb, + fifo->usb_packet_maxlen, + complete, &fifo->iso[i]); + + memset(fifo->iso[i].buffer, 0, + sizeof(fifo->iso[i].buffer)); + + // defining packet delimeters in fifo->buffer + for (k = 0; k < num_packets_per_urb; k++) { + fifo->iso[i].purb-> + iso_frame_desc[k].offset = + k * packet_size; + fifo->iso[i].purb-> + iso_frame_desc[k].length = + packet_size; + } + } + } + + fifo->bit_line = BITLINE_INF; + + errcode = usb_submit_urb(fifo->iso[i].purb); + fifo->active = (errcode >= 0) ? 1 : 0; + if (errcode < 0) { + printk(KERN_INFO "HFC-S USB: %s URB nr:%d\n", + symbolic(urb_errlist, errcode), i); + }; + } + + // errcode = (usb_submit_urb(fifo->iso[0].purb)); + return (fifo->active); +} + +/* stops running iso chain and frees their pending urbs */ +static void +stop_isoc_chain(usb_fifo * fifo) +{ + int i; + + for (i = 0; i < 2; i++) { + if (fifo->iso[i].purb) { +#ifdef CONFIG_HISAX_DEBUG + DBG(USB_DBG, + "HFC-S USB: Stopping iso chain for fifo %i.%i", + fifo->fifonum, i); +#endif + usb_unlink_urb(fifo->iso[i].purb); + usb_free_urb(fifo->iso[i].purb); + fifo->iso[i].purb = NULL; + } + } + fifo->active = 0; +} + +// defines how much ISO packets are handled in one URB +static int iso_packets[8] = + { ISOC_PACKETS_B, ISOC_PACKETS_B, ISOC_PACKETS_B, ISOC_PACKETS_B, + ISOC_PACKETS_D, ISOC_PACKETS_D, ISOC_PACKETS_D, ISOC_PACKETS_D +}; + +/*****************************************************/ +/* transmit completion routine for all ISO tx fifos */ +/*****************************************************/ +static void +tx_iso_complete(struct urb *urb) +{ + iso_urb_struct *context_iso_urb = (iso_urb_struct *) urb->context; + usb_fifo *fifo = context_iso_urb->owner_fifo; + hfcusb_data *hfc = fifo->hfc; + int k, tx_offset, num_isoc_packets, sink, len, current_len, + errcode; + int frame_complete, transp_mode, fifon, status; + __u8 threshbit; + __u8 threshtable[8] = { 1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80 }; + + fifon = fifo->fifonum; + status = urb->status; + tx_offset = 0; + // very weird error code when using ohci drivers, for now : ignore this error ... (MB) + if (status == USB_ST_DATAOVERRUN || status == USB_ST_CRC) { +#ifdef CONFIG_HISAX_DEBUG + DBG(USB_DBG, + "HFC-S USB: ignoring USB_ST_DATAOVERRUN & USB_ST_CRC for fifo %i - status:%d", + fifon, status); +#endif + status = 0; + } + + if (fifo->active && !status) { + transp_mode = 0; + if (fifon < 4 && hfc->b_mode[fifon / 2] == L1_MODE_TRANS) + transp_mode = TRUE; + + threshbit = threshtable[fifon] & hfc->threshold_mask; // is threshold set for our channel? + num_isoc_packets = iso_packets[fifon]; + + if (fifon >= HFCUSB_D_TX) { + sink = (threshbit) ? SINK_DMIN : SINK_DMAX; // how much bit go to the sink for D-channel? + } else { + sink = (threshbit) ? SINK_MIN : SINK_MAX; // how much bit go to the sink for B-channel? + } + + // prepare ISO Urb + fill_isoc_urb(urb, fifo->hfc->dev, fifo->pipe, + context_iso_urb->buffer, num_isoc_packets, + fifo->usb_packet_maxlen, tx_iso_complete, + urb->context); + memset(context_iso_urb->buffer, 0, + sizeof(context_iso_urb->buffer)); + + frame_complete = FALSE; + + // Generate Iso Packets + for (k = 0; k < num_isoc_packets; ++k) { + if (fifo->skbuff) { + len = fifo->skbuff->len; // remaining length + + fifo->bit_line -= sink; // we lower data margin every msec + current_len = (0 - fifo->bit_line) / 8; + if (current_len > 14) + current_len = 14; // maximum 15 byte for every ISO packet makes our life easier + current_len = + (len <= + current_len) ? len : current_len; + fifo->bit_line += current_len * 8; // how much bit do we put on the line? + + context_iso_urb->buffer[tx_offset] = 0; + if (current_len == len) { + if (!transp_mode) { + context_iso_urb->buffer[tx_offset] = 1; // here frame completion + fifo->bit_line += 32; // add 2 byte flags and 16bit CRC at end of ISDN frame + } + frame_complete = TRUE; + } + // copy bytes from buffer into ISO_URB + memcpy(context_iso_urb->buffer + + tx_offset + 1, fifo->skbuff->data, + current_len); + skb_pull(fifo->skbuff, current_len); + + // define packet delimeters within the URB buffer + urb->iso_frame_desc[k].offset = tx_offset; + urb->iso_frame_desc[k].length = + current_len + 1; + + tx_offset += (current_len + 1); + if (!transp_mode) { + if (fifon == HFCUSB_B1_TX) + handle_led(hfc, + LED_B1_DATA); + if (fifon == HFCUSB_B2_TX) + handle_led(hfc, + LED_B2_DATA); + } + } else { + // we have no more data - generate 1 byte ISO packets + urb->iso_frame_desc[k].offset = + tx_offset++; + + urb->iso_frame_desc[k].length = 1; + fifo->bit_line -= sink; // we lower data margin every msec + + if (fifo->bit_line < BITLINE_INF) { + fifo->bit_line = BITLINE_INF; + //printk (KERN_INFO "HFC-S USB: BITLINE_INF underrun\n"); + } + } + + if (frame_complete) { + // delete the buffer only once, here or in hfc_usb_l2l1() in a PH_DATA|REQUEST + fifo->delete_flg = TRUE; + + fifo->hif->l1l2(fifo->hif, + PH_DATA | CONFIRM, + (void *) fifo->skbuff-> + truesize); + + if (fifo->skbuff && fifo->delete_flg) { + dev_kfree_skb_any(fifo->skbuff); + fifo->skbuff = NULL; + fifo->delete_flg = FALSE; + } + + frame_complete = FALSE; + } + } + + errcode = usb_submit_urb(urb); + if (errcode < 0) { + printk(KERN_INFO + "HFC-S USB: error submitting ISO URB: %d \n", + errcode); + } + } else { + if (status && !hfc->disc_flag) { + printk(KERN_INFO + "HFC-S USB: tx_iso_complete : urb->status %s (%i), fifonum=%d\n", + symbolic(urb_errlist, status), status, + fifon); + } + } + +} /* tx_iso_complete */ + +/*****************************************************/ +/* receive completion routine for all ISO tx fifos */ +/*****************************************************/ +static void +rx_iso_complete(struct urb *urb) +{ + iso_urb_struct *context_iso_urb = (iso_urb_struct *) urb->context; + usb_fifo *fifo = context_iso_urb->owner_fifo; + hfcusb_data *hfc = fifo->hfc; + int k, len, errcode, offset, num_isoc_packets, fifon, maxlen, + status; + unsigned int iso_status; + __u8 *buf; +#ifdef CONFIG_HISAX_DEBUG + __u8 i; +#endif + + static __u8 eof[8]; + + fifon = fifo->fifonum; + status = urb->status; + // very weird error code when using ohci drivers, for now : ignore this error ... (MB) + if (status == USB_ST_DATAOVERRUN || status == USB_ST_CRC) { +#ifdef CONFIG_HISAX_DEBUG + DBG(USB_DBG, + "HFC-S USB: ignoring USB_ST_DATAOVERRUN & USB_ST_CRC for fifo %d status:%d", + fifon, status); +#endif + status = 0; + } + + if (fifo->active && !status) { + num_isoc_packets = iso_packets[fifon]; + maxlen = fifo->usb_packet_maxlen; + + // Analyse D-Channel Iso Packets + for (k = 0; k < num_isoc_packets; ++k) { + len = urb->iso_frame_desc[k].actual_length; + offset = urb->iso_frame_desc[k].offset; + buf = context_iso_urb->buffer + offset; + iso_status = urb->iso_frame_desc[k].status; + +#ifdef CONFIG_HISAX_DEBUG + if (iso_status && !hfc->disc_flag) + DBG(USB_DBG, + "HFC-S USB: ISO packet failure - status:%x", + iso_status); + + if ((fifon == 5) && (debug > 1)) { + printk(KERN_INFO + "HFC-S USB: ISO-D-RX lst_urblen:%2d act_urblen:%2d max-urblen:%2d EOF:0x%0x DATA: ", + fifo->last_urblen, len, maxlen, + eof[5]); + for (i = 0; i < len; i++) + printk("%.2x ", buf[i]); + printk("\n"); + } +#endif + + + if (fifo->last_urblen != maxlen) { + // the threshold mask is in the 2nd status byte + hfc->threshold_mask = buf[1]; + + /* care for L1 state only for D-Channel to avoid overlapped iso completions */ + if (fifon == 5) { + // the S0 state is in the upper half of the 1st status byte + state_handler(hfc, buf[0] >> 4); + } + + eof[fifon] = buf[0] & 1; /* End Of Frame? */ + + // if we have more than the 2 status bytes -> collect data + if (len > 2) + collect_rx_frame(fifo, buf + 2, + len - 2, + (len < + maxlen) ? + eof[fifon] : 0); + } else { + collect_rx_frame(fifo, buf, len, + (len < + maxlen) ? eof[fifon] : + 0); + } + + fifo->last_urblen = len; + + } + + // prepare ISO Urb + fill_isoc_urb(urb, fifo->hfc->dev, fifo->pipe, + context_iso_urb->buffer, num_isoc_packets, + fifo->usb_packet_maxlen, rx_iso_complete, + urb->context); + + errcode = usb_submit_urb(urb); + if (errcode < 0) { + printk(KERN_INFO + "HFC-S USB: error submitting ISO URB: %d \n", + errcode); + } + } else { + if (status && !hfc->disc_flag) { + printk(KERN_INFO + "HFC-S USB: rx_iso_complete : urb->status %d, fifonum %d\n", + status, fifon); + } + } +} /* rx_iso_complete */ + + +/*****************************************************/ +/* collect data from interrupt or isochron in */ +/*****************************************************/ +static void +collect_rx_frame(usb_fifo * fifo, __u8 * data, int len, int finish) +{ + hfcusb_data *hfc = fifo->hfc; + int transp_mode, fifon; +#ifdef CONFIG_HISAX_DEBUG + int i; +#endif + + fifon = fifo->fifonum; + transp_mode = 0; + if (fifon < 4 && hfc->b_mode[fifon / 2] == L1_MODE_TRANS) + transp_mode = TRUE; + + //printk(KERN_INFO "HFC-S USB: got %d bytes finish:%d max_size:%d fifo:%d\n",len,finish,fifo->max_size,fifon); + if (!fifo->skbuff) { + // allocate sk buffer + fifo->skbuff = dev_alloc_skb(fifo->max_size + 3); + if (!fifo->skbuff) { + printk(KERN_INFO + "HFC-S USB: cannot allocate buffer (dev_alloc_skb) fifo:%d\n", + fifon); + return; + } + } + + if (len) { + if (fifo->skbuff->len + len < fifo->max_size) { + memcpy(skb_put(fifo->skbuff, len), data, len); + } else { +#ifdef CONFIG_HISAX_DEBUG + printk(KERN_INFO "HFC-S USB: "); + for (i = 0; i < 15; i++) + printk("%.2x ", + fifo->skbuff->data[fifo->skbuff-> + len - 15 + i]); + printk("\n"); +#endif + printk(KERN_INFO + "HCF-USB: got frame exceeded fifo->max_size:%d on fifo:%d\n", + fifo->max_size, fifon); + } + } + // give transparent data up, when 128 byte are available + if (transp_mode && fifo->skbuff->len >= 128) { + fifo->hif->l1l2(fifo->hif, PH_DATA | INDICATION, + fifo->skbuff); + fifo->skbuff = NULL; // buffer was freed from upper layer + return; + } + // we have a complete hdlc packet + if (finish) { + /* can CRC be valid, and is Frame of minimum length at least */ + if ((!fifo->skbuff->data[fifo->skbuff->len - 1]) + && (fifo->skbuff->len > 3)) { + skb_trim(fifo->skbuff, fifo->skbuff->len - 3); // remove CRC & status + + if (fifon == HFCUSB_PCM_RX) { + fifo->hif->l1l2(fifo->hif, + PH_DATA_E | INDICATION, + fifo->skbuff); + } else + fifo->hif->l1l2(fifo->hif, + PH_DATA | INDICATION, + fifo->skbuff); + + fifo->skbuff = NULL; // buffer was freed from upper layer + } else { + if (fifo->skbuff->len > 3) { + printk(KERN_INFO + "HFC-S USB: got frame %d bytes but CRC ERROR on fifo:%d!!!\n", + fifo->skbuff->len, fifon); +#ifdef CONFIG_HISAX_DEBUG + if (debug > 1) { + printk(KERN_INFO "HFC-S USB: "); + for (i = 0; i < 15; i++) + printk("%.2x ", + fifo->skbuff-> + data[fifo->skbuff-> + len - 15 + i]); + printk("\n"); + } +#endif + } +#ifdef CONFIG_HISAX_DEBUG + else { + printk(KERN_INFO + "HFC-S USB: frame to small (%d bytes)!!!\n", + fifo->skbuff->len); + } +#endif + + skb_trim(fifo->skbuff, 0); // clear whole buffer + } + } + // LED flashing only in HDLC mode + if (!transp_mode) { + if (fifon == HFCUSB_B1_RX) + handle_led(hfc, LED_B1_DATA); + if (fifon == HFCUSB_B2_RX) + handle_led(hfc, LED_B2_DATA); + } +} + +/***********************************************/ +/* receive completion routine for all rx fifos */ +/***********************************************/ +static void +rx_complete(struct urb *urb) +{ + int len; + __u8 *buf, maxlen, fifon; + usb_fifo *fifo = (usb_fifo *) urb->context; /* pointer to our fifo */ + hfcusb_data *hfc = fifo->hfc; + static __u8 eof[8]; +#ifdef CONFIG_HISAX_DEBUG + __u8 i; +#endif + + urb->dev = hfc->dev; /* security init */ + + fifon = fifo->fifonum; + if ((!fifo->active) || (urb->status)) { +#ifdef CONFIG_HISAX_DEBUG + DBG(USB_DBG, "HFC-S USB: RX-Fifo %i is going down (%i)", + fifon, urb->status); +#endif + fifo->urb.interval = 0; /* cancel automatic rescheduling */ + if (fifo->skbuff) { + dev_kfree_skb_any(fifo->skbuff); + fifo->skbuff = NULL; + } + return; + } + + len = urb->actual_length; + buf = fifo->buffer; + maxlen = fifo->usb_packet_maxlen; + + +#ifdef CONFIG_HISAX_DEBUG + if ((fifon == 5) && (hfc_debug > 1)) { + printk(KERN_INFO + "HFC-S USB: INT-D-RX lst_urblen:%2d act_urblen:%2d max-urblen:%2d EOF:0x%0x DATA: ", + fifo->last_urblen, len, maxlen, eof[5]); + for (i = 0; i < len; i++) + printk("%.2x ", buf[i]); + printk("\n"); + } +#endif + + + //memcpy(testbuf,buf,len); + //testlen=len; + if (fifo->last_urblen != fifo->usb_packet_maxlen) { + // the threshold mask is in the 2nd status byte + hfc->threshold_mask = buf[1]; + // the S0 state is in the upper half of the 1st status byte + state_handler(hfc, buf[0] >> 4); + eof[fifon] = buf[0] & 1; + // if we have more than the 2 status bytes -> collect data + if (len > 2) + collect_rx_frame(fifo, buf + 2, + urb->actual_length - 2, + (len < maxlen) ? eof[fifon] : 0); + } else { + collect_rx_frame(fifo, buf, urb->actual_length, + (len < maxlen) ? eof[fifon] : 0); + } + + fifo->last_urblen = urb->actual_length; + + +} /* rx_complete */ + +/***************************************************/ +/* start the interrupt transfer for the given fifo */ +/***************************************************/ +static void +start_int_fifo(usb_fifo * fifo) +{ + int errcode; + +#ifdef CONFIG_HISAX_DEBUG + DBG(USB_DBG, "HFC-S USB: starting intr IN fifo:%d", fifo->fifonum); +#endif + FILL_INT_URB(&fifo->urb, fifo->hfc->dev, fifo->pipe, fifo->buffer, + fifo->usb_packet_maxlen, rx_complete, fifo, + fifo->intervall); + fifo->active = 1; /* must be marked active */ + errcode = usb_submit_urb(&fifo->urb); + + if (errcode) { + printk(KERN_INFO + "HFC-S USB: submit URB error(start_int_info): status:%i\n", + errcode); + fifo->active = 0; + fifo->skbuff = NULL; + } +} /* start_int_fifo */ + +/*****************************/ +/* set the B-channel mode */ +/*****************************/ +static void +set_hfcmode(hfcusb_data * hfc, int channel, int mode) +{ + __u8 val, idx_table[2] = { 0, 2 }; + + // don't queue any control urbs if device has been disconnected + if (hfc->disc_flag) { + return; + } +#ifdef CONFIG_HISAX_DEBUG + DBG(ISDN_DBG, "HFC-S USB: setting channel %d to mode %d", channel, + mode); +#endif + hfc->b_mode[channel] = mode; + + // setup CON_HDLC + val = 0; + if (mode != L1_MODE_NULL) + val = 8; // enable fifo? + if (mode == L1_MODE_TRANS) + val |= 2; // set transparent bit + + queue_control_request(hfc, HFCUSB_FIFO, idx_table[channel], 1); // set FIFO to transmit register + queue_control_request(hfc, HFCUSB_CON_HDLC, val, 1); + queue_control_request(hfc, HFCUSB_INC_RES_F, 2, 1); // reset fifo + + queue_control_request(hfc, HFCUSB_FIFO, idx_table[channel] + 1, 1); // set FIFO to receive register + queue_control_request(hfc, HFCUSB_CON_HDLC, val, 1); + queue_control_request(hfc, HFCUSB_INC_RES_F, 2, 1); // reset fifo + + val = 0x40; + if (hfc->b_mode[0]) + val |= 1; + if (hfc->b_mode[1]) + val |= 2; + queue_control_request(hfc, HFCUSB_SCTRL, val, 1); + + val = 0; + if (hfc->b_mode[0]) + val |= 1; + if (hfc->b_mode[1]) + val |= 2; + queue_control_request(hfc, HFCUSB_SCTRL_R, val, 1); + + if (mode == L1_MODE_NULL) { + if (channel) + handle_led(hfc, LED_B2_OFF); + else + handle_led(hfc, LED_B1_OFF); + } else { + if (channel) + handle_led(hfc, LED_B2_ON); + else + handle_led(hfc, LED_B1_ON); + } +} + + +/* +* HiSax CallBack layer2 -> layer1 +*/ +void +hfc_usb_l2l1(struct hisax_if *my_hisax_if, int pr, void *arg) +{ + usb_fifo *fifo = my_hisax_if->priv; + hfcusb_data *hfc = fifo->hfc; + + switch (pr) { + case PH_ACTIVATE | REQUEST: + if (fifo->fifonum == HFCUSB_D_TX) { +#ifdef CONFIG_HISAX_DEBUG + DBG(ISDN_DBG, + "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_ACTIVATE | REQUEST"); +#endif + if (hfc->l1_state != 3 + && hfc->l1_state != 7) { + hfc->d_if.ifc.l1l2(&hfc->d_if.ifc, + PH_DEACTIVATE | + INDICATION, + NULL); +#ifdef CONFIG_HISAX_DEBUG + DBG(ISDN_DBG, + "HFC-S USB: PH_DEACTIVATE | INDICATION sent (not state 3 or 7)"); +#endif + } else { + if (hfc->l1_state == 7) { /* l1 already active */ + hfc->d_if.ifc.l1l2(&hfc-> + d_if. + ifc, + PH_ACTIVATE + | + INDICATION, + NULL); +#ifdef CONFIG_HISAX_DEBUG + DBG(ISDN_DBG, + "HFC-S USB: PH_ACTIVATE | INDICATION sent again ;)"); +#endif + } else { + /* hfc->l1_state==3) */ + queue_control_request(hfc, HFCUSB_STATES, 0x14, 1); // force sending sending INFO1 + mdelay(1); + queue_control_request(hfc, HFCUSB_STATES, 0x04, 1); // start l1 activation + + if (!timer_pending + (&hfc->t3_timer)) { + hfc->t3_timer. + expires = + jiffies + + (HFC_TIMER_T3 * + HZ) / 1000; + add_timer(&hfc-> + t3_timer); + } + } + } + } else { +#ifdef CONFIG_HISAX_DEBUG + DBG(ISDN_DBG, + "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_ACTIVATE | REQUEST"); +#endif + set_hfcmode(hfc, + (fifo->fifonum == + HFCUSB_B1_TX) ? 0 : 1, + (int) arg); + fifo->hif->l1l2(fifo->hif, + PH_ACTIVATE | INDICATION, + NULL); + } + break; + case PH_DEACTIVATE | REQUEST: + if (fifo->fifonum == HFCUSB_D_TX) { +#ifdef CONFIG_HISAX_DEBUG + DBG(ISDN_DBG, + "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_DEACTIVATE | REQUEST"); +#endif + printk(KERN_INFO + "HFC-S USB: ISDN TE device should not deativate...\n"); + } else { +#ifdef CONFIG_HISAX_DEBUG + DBG(ISDN_DBG, + "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_DEACTIVATE | REQUEST"); +#endif + set_hfcmode(hfc, + (fifo->fifonum == + HFCUSB_B1_TX) ? 0 : 1, + (int) L1_MODE_NULL); + fifo->hif->l1l2(fifo->hif, + PH_DEACTIVATE | INDICATION, + NULL); + } + break; + case PH_DATA | REQUEST: + if (fifo->skbuff && fifo->delete_flg) { + dev_kfree_skb_any(fifo->skbuff); + fifo->skbuff = NULL; + fifo->delete_flg = FALSE; + } + + fifo->skbuff = arg; // we have a new buffer + + //if(fifo->fifonum==HFCUSB_D_TX) printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_DATA | REQUEST\n"); + //else printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_DATA | REQUEST\n"); + break; + default: + printk(KERN_INFO + "HFC_USB: hfc_usb_d_l2l1: unkown state : %#x\n", + pr); + break; + } +} + +/***************************************************************************/ +/* usb_init is called once when a new matching device is detected to setup */ +/* main parameters. It registers the driver at the main hisax module. */ +/* on success 0 is returned. */ +/***************************************************************************/ +static int +usb_init(hfcusb_data * hfc) +{ + usb_fifo *fifo; + int i; + u_char b; + struct hisax_b_if *p_b_if[2]; + + /* check the chip id */ + if ((read_usb(hfc, HFCUSB_CHIP_ID, &b) != 1) + || (b != HFCUSB_CHIPID)) { + printk(KERN_INFO "HFC-S USB: Invalid chip id 0x%02x\n", b); + return (1); + } + + /* first set the needed config, interface and alternate */ + usb_set_configuration(hfc->dev, 1); + usb_set_interface(hfc->dev, hfc->if_used, hfc->alt_used); + + /* now we initialize the chip */ + write_usb(hfc, HFCUSB_CIRM, 8); // do reset + write_usb(hfc, HFCUSB_CIRM, 0x10); // aux = output, reset off + + // set USB_SIZE to match the the wMaxPacketSize for INT or BULK transfers + write_usb(hfc, HFCUSB_USB_SIZE, + (hfc->packet_size / 8) | ((hfc->packet_size / 8) << 4)); + + // set USB_SIZE_I to match the the wMaxPacketSize for ISO transfers + write_usb(hfc, HFCUSB_USB_SIZE_I, hfc->iso_packet_size); + + /* enable PCM/GCI master mode */ + write_usb(hfc, HFCUSB_MST_MODE1, 0); /* set default values */ + write_usb(hfc, HFCUSB_MST_MODE0, 1); /* enable master mode */ + + /* init the fifos */ + write_usb(hfc, HFCUSB_F_THRES, + (HFCUSB_TX_THRESHOLD / + 8) | ((HFCUSB_RX_THRESHOLD / 8) << 4)); + + fifo = hfc->fifos; + for (i = 0; i < HFCUSB_NUM_FIFOS; i++) { + write_usb(hfc, HFCUSB_FIFO, i); /* select the desired fifo */ + fifo[i].skbuff = NULL; /* init buffer pointer */ + fifo[i].max_size = + (i <= HFCUSB_B2_RX) ? MAX_BCH_SIZE : MAX_DFRAME_LEN; + fifo[i].last_urblen = 0; + write_usb(hfc, HFCUSB_HDLC_PAR, ((i <= HFCUSB_B2_RX) ? 0 : 2)); // set 2 bit for D- & E-channel + write_usb(hfc, HFCUSB_CON_HDLC, ((i == HFCUSB_D_TX) ? 0x09 : 0x08)); // rx hdlc, enable IFF for D-channel + write_usb(hfc, HFCUSB_INC_RES_F, 2); /* reset the fifo */ + } + + write_usb(hfc, HFCUSB_CLKDEL, 0x0f); /* clock delay value */ + write_usb(hfc, HFCUSB_STATES, 3 | 0x10); /* set deactivated mode */ + write_usb(hfc, HFCUSB_STATES, 3); /* enable state machine */ + + write_usb(hfc, HFCUSB_SCTRL_R, 0); /* disable both B receivers */ + write_usb(hfc, HFCUSB_SCTRL, 0x40); /* disable B transmitters + capacitive mode */ + + // set both B-channel to not connected + hfc->b_mode[0] = L1_MODE_NULL; + hfc->b_mode[1] = L1_MODE_NULL; + + hfc->l1_activated = FALSE; + hfc->disc_flag = FALSE; + hfc->led_state = 0; + hfc->led_new_data = 0; + hfc->old_led_state = 0; + + /* init the t3 timer */ + init_timer(&hfc->t3_timer); + hfc->t3_timer.data = (long) hfc; + hfc->t3_timer.function = (void *) l1_timer_expire_t3; + /* init the t4 timer */ + init_timer(&hfc->t4_timer); + hfc->t4_timer.data = (long) hfc; + hfc->t4_timer.function = (void *) l1_timer_expire_t4; + + // init the background machinery for control requests + hfc->ctrl_read.bRequestType = 0xc0; + hfc->ctrl_read.bRequest = 1; + hfc->ctrl_read.wLength = 1; + hfc->ctrl_write.bRequestType = 0x40; + hfc->ctrl_write.bRequest = 0; + hfc->ctrl_write.wLength = 0; + FILL_CONTROL_URB(&hfc->ctrl_urb, hfc->dev, hfc->ctrl_out_pipe, + (u_char *) & hfc->ctrl_write, NULL, 0, + ctrl_complete, hfc); + + /* Init All Fifos */ + for (i = 0; i < HFCUSB_NUM_FIFOS; i++) { + hfc->fifos[i].iso[0].purb = NULL; + hfc->fifos[i].iso[1].purb = NULL; + hfc->fifos[i].active = 0; + } + + // register like Germaschewski : + SET_MODULE_OWNER(&hfc->d_if); + hfc->d_if.ifc.priv = &hfc->fifos[HFCUSB_D_TX]; + hfc->d_if.ifc.l2l1 = hfc_usb_l2l1; + + for (i = 0; i < 2; i++) { + hfc->b_if[i].ifc.priv = &hfc->fifos[HFCUSB_B1_TX + i * 2]; + hfc->b_if[i].ifc.l2l1 = hfc_usb_l2l1; + p_b_if[i] = &hfc->b_if[i]; + } + + hfc->protocol = 2; /* default EURO ISDN, should be a module_param */ + hisax_register(&hfc->d_if, p_b_if, "hfc_usb", hfc->protocol); + +#ifdef CONFIG_HISAX_DEBUG + hfc_debug = debug; +#endif + + for (i = 0; i < 4; i++) + hfc->fifos[i].hif = &p_b_if[i / 2]->ifc; + for (i = 4; i < 8; i++) + hfc->fifos[i].hif = &hfc->d_if.ifc; + + // 3 (+1) INT IN + 3 ISO OUT + if (hfc->cfg_used == CNF_3INT3ISO || hfc->cfg_used == CNF_4INT3ISO) { + start_int_fifo(hfc->fifos + HFCUSB_D_RX); // Int IN D-fifo + if (hfc->fifos[HFCUSB_PCM_RX].pipe) + start_int_fifo(hfc->fifos + HFCUSB_PCM_RX); // E-fifo + start_int_fifo(hfc->fifos + HFCUSB_B1_RX); // Int IN B1-fifo + start_int_fifo(hfc->fifos + HFCUSB_B2_RX); // Int IN B2-fifo + } + // 3 (+1) ISO IN + 3 ISO OUT + if (hfc->cfg_used == CNF_3ISO3ISO || hfc->cfg_used == CNF_4ISO3ISO) { + start_isoc_chain(hfc->fifos + HFCUSB_D_RX, ISOC_PACKETS_D, + rx_iso_complete, 16); + if (hfc->fifos[HFCUSB_PCM_RX].pipe) + start_isoc_chain(hfc->fifos + HFCUSB_PCM_RX, + ISOC_PACKETS_D, rx_iso_complete, + 16); + start_isoc_chain(hfc->fifos + HFCUSB_B1_RX, ISOC_PACKETS_B, + rx_iso_complete, 16); + start_isoc_chain(hfc->fifos + HFCUSB_B2_RX, ISOC_PACKETS_B, + rx_iso_complete, 16); + } + + start_isoc_chain(hfc->fifos + HFCUSB_D_TX, ISOC_PACKETS_D, + tx_iso_complete, 1); + start_isoc_chain(hfc->fifos + HFCUSB_B1_TX, ISOC_PACKETS_B, + tx_iso_complete, 1); + start_isoc_chain(hfc->fifos + HFCUSB_B2_TX, ISOC_PACKETS_B, + tx_iso_complete, 1); + + handle_led(hfc, LED_POWER_ON); + + return (0); +} /* usb_init */ + + +/*************************************************/ +/* function called to probe a new plugged device */ +/*************************************************/ +static void * +hfc_usb_probe(struct usb_device *dev, unsigned int interface, + const struct usb_device_id *id_table) +{ + hfcusb_data *context; + struct usb_interface *ifp = dev->actconfig->interface + interface; + struct usb_interface_descriptor *ifdp = + ifp->altsetting + ifp->act_altsetting; + struct usb_endpoint_descriptor *epd; + int i, idx, probe_alt_setting, vend_idx, cfg_used, *vcf, attr, + cfg_found, cidx, ep_addr; + int cmptbl[16], small_match, iso_packet_size, packet_size, + alt_used = 0; + hfcsusb_vdata *driver_info; + + vend_idx = 0xffff; + for (i = 0; hfcusb_idtab[i].idVendor; i++) { + if (dev->descriptor.idVendor == hfcusb_idtab[i].idVendor + && dev->descriptor.idProduct == + hfcusb_idtab[i].idProduct) { + vend_idx = i; + continue; + } + } + +#ifdef CONFIG_HISAX_DEBUG + DBG(USB_DBG, "HFC-S USB: probing interface:%d", interface); +#endif + + if (vend_idx != 0xffff) { + /* if vendor and product ID is OK, start probing a matching alternate setting ... */ + probe_alt_setting = 0; + small_match = 0xffff; + // default settings + iso_packet_size = 16; + packet_size = 64; + + while (probe_alt_setting < ifp->num_altsetting) { + ifp->act_altsetting = probe_alt_setting; + ifdp = ifp->altsetting + ifp->act_altsetting; + cfg_used = 0; + + //printk(KERN_INFO "HFC-S USB: if=%d alt=%d\n",interface, ifp->act_altsetting); + + // check for config EOL element + while (validconf[cfg_used][0]) { + cfg_found = TRUE; + vcf = validconf[cfg_used]; + epd = ifdp->endpoint; /* first endpoint descriptor */ + +#ifdef CONFIG_HISAX_DEBUG + DBG(USB_DBG, + "HFC-S USB: (if=%d alt=%d cfg_used=%d)", + interface, ifp->act_altsetting, + cfg_used); +#endif + + // copy table + memcpy(cmptbl, vcf, 16 * sizeof(int)); + + // check for all endpoints in this alternate setting + for (i = 0; i < ifdp->bNumEndpoints; i++) { + ep_addr = epd->bEndpointAddress; + idx = ((ep_addr & 0x7f) - 1) * 2; /* get endpoint base */ + if (ep_addr & 0x80) + idx++; + attr = epd->bmAttributes; + + if (cmptbl[idx] == EP_NUL) { + //printk(KERN_INFO "HFC-S USB: cfg_found=FALSE in idx:%d attr:%d cmptbl[%d]:%d\n",idx,attr,idx,cmptbl[idx]); + cfg_found = FALSE; + } + + if (attr == USB_ENDPOINT_XFER_INT + && cmptbl[idx] == EP_INT) + cmptbl[idx] = EP_NUL; + if (attr == USB_ENDPOINT_XFER_BULK + && cmptbl[idx] == EP_BLK) + cmptbl[idx] = EP_NUL; + if (attr == USB_ENDPOINT_XFER_ISOC + && cmptbl[idx] == EP_ISO) + cmptbl[idx] = EP_NUL; + + // check if all INT endpoints match minimum interval + if (attr == USB_ENDPOINT_XFER_INT + && epd->bInterval < vcf[17]) { +#ifdef CONFIG_HISAX_DEBUG + if (cfg_found) + DBG(USB_DBG, + "HFC-S USB: Interrupt Endpoint interval < %d found - skipping config", + vcf[17]); +#endif + + cfg_found = FALSE; + } + + epd++; + } + + for (i = 0; i < 16; i++) { + // all entries must be EP_NOP or EP_NUL for a valid config + if (cmptbl[i] != EP_NOP + && cmptbl[i] != EP_NUL) + cfg_found = FALSE; + } + + // we check for smallest match, to provide configuration priority + // configurations with smaller index have higher priority + if (cfg_found) { + if (cfg_used < small_match) { + small_match = cfg_used; + alt_used = + ifp->act_altsetting; + } +#ifdef CONFIG_HISAX_DEBUG + DBG(USB_DBG, + "HFC-S USB: small_match=%d", + small_match); +#endif + } + + cfg_used++; + } + + probe_alt_setting++; + } /* (probe_alt_setting < ifp->num_altsetting) */ + + + // yiipiee, we found a valid config + if (small_match != 0xffff) { + ifp->act_altsetting = alt_used; + ifdp = ifp->altsetting + ifp->act_altsetting; + + if (! + (context = + kmalloc(sizeof(hfcusb_data), GFP_KERNEL))) + return (NULL); /* got no mem */ + memset(context, 0, sizeof(hfcusb_data)); /* clear the structure */ + + epd = ifdp->endpoint; /* first endpoint descriptor */ + vcf = validconf[small_match]; + + for (i = 0; i < ifdp->bNumEndpoints; i++) { + ep_addr = epd->bEndpointAddress; + idx = ((ep_addr & 0x7f) - 1) * 2; /* get endpoint base */ + if (ep_addr & 0x80) + idx++; + cidx = idx & 7; + attr = epd->bmAttributes; + + // only initialize used endpoints + if (vcf[idx] != EP_NOP + && vcf[idx] != EP_NUL) { + switch (attr) { + case USB_ENDPOINT_XFER_INT: + context-> + fifos[cidx]. + pipe = + usb_rcvintpipe + (dev, + epd-> + bEndpointAddress); + context-> + fifos[cidx]. + usb_transfer_mode + = USB_INT; + packet_size = epd->wMaxPacketSize; // remember max packet size +#ifdef CONFIG_HISAX_DEBUG + DBG(USB_DBG, + "HFC-S USB: Interrupt-In Endpoint found %d ms(idx:%d cidx:%d)!", + epd->bInterval, + idx, cidx); +#endif + break; + + case USB_ENDPOINT_XFER_BULK: + if (ep_addr & 0x80) + context-> + fifos + [cidx]. + pipe = + usb_rcvbulkpipe + (dev, + epd-> + bEndpointAddress); + else + context-> + fifos + [cidx]. + pipe = + usb_sndbulkpipe + (dev, + epd-> + bEndpointAddress); + context-> + fifos[cidx]. + usb_transfer_mode + = USB_BULK; + packet_size = epd->wMaxPacketSize; // remember max packet size +#ifdef CONFIG_HISAX_DEBUG + DBG(USB_DBG, + "HFC-S USB: Bulk Endpoint found (idx:%d cidx:%d)!", + idx, cidx); +#endif + break; + + case USB_ENDPOINT_XFER_ISOC: + if (ep_addr & 0x80) + context-> + fifos + [cidx]. + pipe = + usb_rcvisocpipe + (dev, + epd-> + bEndpointAddress); + else + context-> + fifos + [cidx]. + pipe = + usb_sndisocpipe + (dev, + epd-> + bEndpointAddress); + context-> + fifos[cidx]. + usb_transfer_mode + = USB_ISOC; + iso_packet_size = epd->wMaxPacketSize; // remember max packet size +#ifdef CONFIG_HISAX_DEBUG + DBG(USB_DBG, + "HFC-S USB: ISO Endpoint found (idx:%d cidx:%d)!", + idx, cidx); +#endif + break; + + default: + context->fifos[cidx].pipe = 0; /* reset data */ + } /* switch attribute */ + + if (context->fifos[cidx].pipe) { + context->fifos[cidx]. + fifonum = cidx; + context->fifos[cidx].hfc = + context; + context->fifos[cidx]. + usb_packet_maxlen = + epd->wMaxPacketSize; + context->fifos[cidx]. + intervall = + epd->bInterval; + context->fifos[cidx]. + skbuff = NULL; + } + } + + epd++; + } + + // now share our luck +#ifndef CONFIG_HFC_USB_SKIP_MOD_COUNTING + MOD_INC_USE_COUNT; /* lock our module */ +#endif + context->dev = dev; /* save device */ + context->if_used = interface; /* save used interface */ + context->alt_used = ifp->act_altsetting; /* and alternate config */ + context->ctrl_paksize = dev->descriptor.bMaxPacketSize0; /* control size */ + context->cfg_used = vcf[16]; // store used config + context->vend_idx = vend_idx; // store found vendor + context->packet_size = packet_size; + context->iso_packet_size = iso_packet_size; + + /* create the control pipes needed for register access */ + context->ctrl_in_pipe = + usb_rcvctrlpipe(context->dev, 0); + context->ctrl_out_pipe = + usb_sndctrlpipe(context->dev, 0); + + driver_info = + (hfcsusb_vdata *) hfcusb_idtab[vend_idx]. + driver_info; + printk(KERN_INFO "HFC-S USB: detected \"%s\"\n", + driver_info->vend_name); +#ifdef CONFIG_HISAX_DEBUG + DBG(USB_DBG, + "HFC-S USB: Endpoint-Config: %s (if=%d alt=%d)\n", + conf_str[small_match], context->if_used, + context->alt_used); + printk(KERN_INFO + "HFC-S USB: E-channel (\"ECHO:\") logging "); + if (validconf[small_match][18]) + printk(" possible\n"); + else + printk("NOT possible\n"); +#endif + + /* init the chip and register the driver */ + if (usb_init(context)) { + + kfree(context); +#ifndef CONFIG_HFC_USB_SKIP_MOD_COUNTING + MOD_DEC_USE_COUNT; +#endif + return (NULL); + } + + return (context); + } + } else { + printk(KERN_INFO + "HFC-S USB: no valid vendor found in USB descriptor\n"); + } + + return (NULL); +} + +/****************************************************/ +/* function called when an active device is removed */ +/****************************************************/ +static void +hfc_usb_disconnect(struct usb_device *usbdev, void *drv_context) +{ + hfcusb_data *context = drv_context; + int i; + + printk(KERN_INFO "HFC-S USB: device disconnect\n"); + + context->disc_flag = TRUE; + + if (timer_pending(&context->t3_timer)) + del_timer(&context->t3_timer); + if (timer_pending(&context->t4_timer)) + del_timer(&context->t4_timer); + + /* tell all fifos to terminate */ + for (i = 0; i < HFCUSB_NUM_FIFOS; i++) { + if (context->fifos[i].usb_transfer_mode == USB_ISOC) { + if (context->fifos[i].active > 0) { + stop_isoc_chain(&context->fifos[i]); +#ifdef CONFIG_HISAX_DEBUG + DBG(USB_DBG, + "HFC-S USB: hfc_usb_disconnect: stopping ISOC chain Fifo no %i", + i); +#endif + } + } else { + if (context->fifos[i].active > 0) { + context->fifos[i].active = 0; + usb_unlink_urb(&context->fifos[i].urb); +#ifdef CONFIG_HISAX_DEBUG + DBG(USB_DBG, + "HFC-S USB: hfc_usb_disconnect: unlinking URB for Fifo no %i", + i); +#endif + } + } + context->fifos[i].active = 0; + } + + // wait for all URBS to terminate + mdelay(10); + + if (&context->ctrl_urb) { + usb_unlink_urb(&context->ctrl_urb); + } + + hisax_unregister(&context->d_if); + +#ifndef CONFIG_HFC_USB_SKIP_MOD_COUNTING + MOD_DEC_USE_COUNT; /* and decrement the usage counter */ +#endif +} /* hfc_usb_disconnect */ + + +/************************************/ +/* our driver information structure */ +/************************************/ +static struct usb_driver hfc_drv = { + name:"hfc_usb", + id_table:hfcusb_idtab, + probe:hfc_usb_probe, + disconnect:hfc_usb_disconnect, +}; + +static void __exit +hfc_usb_exit(void) +{ +#ifdef CONFIG_HISAX_DEBUG + DBG(USB_DBG, "HFC-S USB: calling \"hfc_usb_exit\" ..."); +#endif + usb_deregister(&hfc_drv); /* release our driver */ + printk(KERN_INFO "HFC-S USB: module removed\n"); +} + +static int __init +hfc_usb_init(void) +{ + char revstr[30], datestr[30], dummy[30]; + + sscanf(hfcusb_revision, "%s %s $ %s %s %s $ ", dummy, revstr, + dummy, datestr, dummy); + printk(KERN_INFO + "HFC-S USB: driver module revision %s date %s loaded\n", + revstr, datestr); + + if (usb_register(&hfc_drv)) { + printk(KERN_INFO + "HFC-S USB: Unable to register HFC-S USB module at usb stack\n"); + return (-1); /* unable to register */ + } + return (0); +} + +module_init(hfc_usb_init); +module_exit(hfc_usb_exit); +MODULE_DEVICE_TABLE(usb, hfcusb_idtab); +MODULE_AUTHOR(DRIVER_AUTHOR); +MODULE_DESCRIPTION(DRIVER_DESC); +MODULE_LICENSE("GPL"); diff --git a/drivers/isdn/hisax/hfc_usb.h b/drivers/isdn/hisax/hfc_usb.h new file mode 100644 index 00000000..a9529e59 --- /dev/null +++ b/drivers/isdn/hisax/hfc_usb.h @@ -0,0 +1,228 @@ +/* +* hfc_usb.h +* +* $Id$ +*/ + +#ifndef __HFC_USB_H__ +#define __HFC_USB_H__ + +#define DRIVER_AUTHOR "Peter Sprenger (sprenger@moving-byters.de)" +#define DRIVER_DESC "HFC-S USB based HiSAX ISDN driver" + +#define VERBOSE_USB_DEBUG + +#define TRUE 1 +#define FALSE 0 + + +/***********/ +/* defines */ +/***********/ +#define HFC_CTRL_TIMEOUT 20 /* 5ms timeout writing/reading regs */ +#define HFC_TIMER_T3 8000 /* timeout for l1 activation timer */ +#define HFC_TIMER_T4 500 /* time for state change interval */ + +#define HFCUSB_L1_STATECHANGE 0 /* L1 state changed */ +#define HFCUSB_L1_DRX 1 /* D-frame received */ +#define HFCUSB_L1_ERX 2 /* E-frame received */ +#define HFCUSB_L1_DTX 4 /* D-frames completed */ + +#define MAX_BCH_SIZE 2048 /* allowed B-channel packet size */ + +#define HFCUSB_RX_THRESHOLD 64 /* threshold for fifo report bit rx */ +#define HFCUSB_TX_THRESHOLD 64 /* threshold for fifo report bit tx */ + +#define HFCUSB_CHIP_ID 0x16 /* Chip ID register index */ +#define HFCUSB_CIRM 0x00 /* cirm register index */ +#define HFCUSB_USB_SIZE 0x07 /* int length register */ +#define HFCUSB_USB_SIZE_I 0x06 /* iso length register */ +#define HFCUSB_F_CROSS 0x0b /* bit order register */ +#define HFCUSB_CLKDEL 0x37 /* bit delay register */ +#define HFCUSB_CON_HDLC 0xfa /* channel connect register */ +#define HFCUSB_HDLC_PAR 0xfb +#define HFCUSB_SCTRL 0x31 /* S-bus control register (tx) */ +#define HFCUSB_SCTRL_E 0x32 /* same for E and special funcs */ +#define HFCUSB_SCTRL_R 0x33 /* S-bus control register (rx) */ +#define HFCUSB_F_THRES 0x0c /* threshold register */ +#define HFCUSB_FIFO 0x0f /* fifo select register */ +#define HFCUSB_F_USAGE 0x1a /* fifo usage register */ +#define HFCUSB_MST_MODE0 0x14 +#define HFCUSB_MST_MODE1 0x15 +#define HFCUSB_P_DATA 0x1f +#define HFCUSB_INC_RES_F 0x0e +#define HFCUSB_STATES 0x30 + +#define HFCUSB_CHIPID 0x40 /* ID value of HFC-S USB */ + +/******************/ +/* fifo registers */ +/******************/ +#define HFCUSB_NUM_FIFOS 8 /* maximum number of fifos */ +#define HFCUSB_B1_TX 0 /* index for B1 transmit bulk/int */ +#define HFCUSB_B1_RX 1 /* index for B1 receive bulk/int */ +#define HFCUSB_B2_TX 2 +#define HFCUSB_B2_RX 3 +#define HFCUSB_D_TX 4 +#define HFCUSB_D_RX 5 +#define HFCUSB_PCM_TX 6 +#define HFCUSB_PCM_RX 7 + +/* +* used to switch snd_transfer_mode for different TA modes e.g. the Billion USB TA just +* supports ISO out, while the Cologne Chip EVAL TA just supports BULK out +*/ +#define USB_INT 0 +#define USB_BULK 1 +#define USB_ISOC 2 + +#define ISOC_PACKETS_D 8 +#define ISOC_PACKETS_B 8 +#define ISO_BUFFER_SIZE 128 + +// ISO send definitions +#define SINK_MAX 68 +#define SINK_MIN 48 +#define SINK_DMIN 12 +#define SINK_DMAX 18 +#define BITLINE_INF (-64*8) + + +/**********/ +/* macros */ +/**********/ +#define write_usb(a,b,c)usb_control_msg((a)->dev,(a)->ctrl_out_pipe,0,0x40,(c),(b),NULL,0,HFC_CTRL_TIMEOUT) +#define read_usb(a,b,c) usb_control_msg((a)->dev,(a)->ctrl_in_pipe,1,0xC0,0,(b),(c),1,HFC_CTRL_TIMEOUT) + + +/*******************/ +/* Debugging Flags */ +/*******************/ +#define USB_DBG 1 +#define ISDN_DBG 2 + + +/* *********************/ +/* USB related defines */ +/***********************/ +#define HFC_CTRL_BUFSIZE 32 + + + +/*************************************************/ +/* entry and size of output/input control buffer */ +/*************************************************/ +typedef struct { + __u8 hfc_reg; /* register number */ + __u8 reg_val; /* value to be written (or read) */ + int action; /* data for action handler */ +} ctrl_buft; + + +/********************/ +/* URB error codes: */ +/********************/ +/* Used to represent a list of values and their respective symbolic names */ +struct hfcusb_symbolic_list { + const int num; + const char *name; +}; + +static struct hfcusb_symbolic_list urb_errlist[] = { + {-ENOMEM, "No memory for allocation of internal structures"}, + {-ENOSPC, "The host controller's bandwidth is already consumed"}, + {-ENOENT, "URB was canceled by unlink_urb"}, + {-EXDEV, "ISO transfer only partially completed"}, + {-EAGAIN, "Too match scheduled for the future"}, + {-ENXIO, "URB already queued"}, + {-EFBIG, "Too much ISO frames requested"}, + {-ENOSR, "Buffer error (overrun)"}, + {-EPIPE, "Specified endpoint is stalled (device not responding)"}, + {-EOVERFLOW, "Babble (bad cable?)"}, + {-EPROTO, "Bit-stuff error (bad cable?)"}, + {-EILSEQ, "CRC/Timeout"}, + {-ETIMEDOUT, "NAK (device does not respond)"}, + {-ESHUTDOWN, "Device unplugged"}, + {-1, NULL} +}; + + +/*****************************************************/ +/* device dependant information to support different */ +/* ISDN Ta's using the HFC-S USB chip */ +/*****************************************************/ + +/* USB descriptor need to contain one of the following EndPoint combination: */ +#define CNF_4INT3ISO 1 // 4 INT IN, 3 ISO OUT +#define CNF_3INT3ISO 2 // 3 INT IN, 3 ISO OUT +#define CNF_4ISO3ISO 3 // 4 ISO IN, 3 ISO OUT +#define CNF_3ISO3ISO 4 // 3 ISO IN, 3 ISO OUT + +#define EP_NUL 1 // Endpoint at this position not allowed +#define EP_NOP 2 // all type of endpoints allowed at this position +#define EP_ISO 3 // Isochron endpoint mandatory at this position +#define EP_BLK 4 // Bulk endpoint mandatory at this position +#define EP_INT 5 // Interrupt endpoint mandatory at this position + +/* this array represents all endpoints possible in the HCF-USB the last +* 3 entries are the configuration number, the minimum interval for +* Interrupt endpoints & boolean if E-channel logging possible +*/ +int validconf[][19] = { + // INT in, ISO out config + {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, 1}, + {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, 0}, + // ISO in, ISO out config + {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, 1}, + {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, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} // EOL element +}; + +// string description of chosen config +char *conf_str[] = { + "4 Interrupt IN + 3 Isochron OUT", + "3 Interrupt IN + 3 Isochron OUT", + "4 Isochron IN + 3 Isochron OUT", + "3 Isochron IN + 3 Isochron OUT" +}; + + +typedef struct { + int vendor; // vendor id + int prod_id; // product id + char *vend_name; // vendor string + __u8 led_scheme; // led display scheme + signed short led_bits[8]; // array of 8 possible LED bitmask settings +} vendor_data; + +#define LED_OFF 0 // no LED support +#define LED_SCHEME1 1 // LED standard scheme +#define LED_SCHEME2 2 // not used yet... + +#define LED_POWER_ON 1 +#define LED_POWER_OFF 2 +#define LED_S0_ON 3 +#define LED_S0_OFF 4 +#define LED_B1_ON 5 +#define LED_B1_OFF 6 +#define LED_B1_DATA 7 +#define LED_B2_ON 8 +#define LED_B2_OFF 9 +#define LED_B2_DATA 10 + +#define LED_NORMAL 0 // LEDs are normal +#define LED_INVERTED 1 // LEDs are inverted + +/* time in ms to perform a Flashing LED when B-Channel has traffic */ +#define LED_TIME 250 + + +#endif // __HFC_USB_H__