Path: blob/master/drivers/isdn/hardware/mISDN/hfcsusb.h
15112 views
/*1* hfcsusb.h, HFC-S USB mISDN driver2*/34#ifndef __HFCSUSB_H__5#define __HFCSUSB_H__678#define DRIVER_NAME "HFC-S_USB"910#define DBG_HFC_CALL_TRACE 0x0001000011#define DBG_HFC_FIFO_VERBOSE 0x0002000012#define DBG_HFC_USB_VERBOSE 0x0010000013#define DBG_HFC_URB_INFO 0x0020000014#define DBG_HFC_URB_ERROR 0x004000001516#define DEFAULT_TRANSP_BURST_SZ 1281718#define HFC_CTRL_TIMEOUT 20 /* 5ms timeout writing/reading regs */19#define CLKDEL_TE 0x0f /* CLKDEL in TE mode */20#define CLKDEL_NT 0x6c /* CLKDEL in NT mode */2122/* hfcsusb Layer1 commands */23#define HFC_L1_ACTIVATE_TE 124#define HFC_L1_ACTIVATE_NT 225#define HFC_L1_DEACTIVATE_NT 326#define HFC_L1_FORCE_DEACTIVATE_TE 42728/* cmd FLAGS in HFCUSB_STATES register */29#define HFCUSB_LOAD_STATE 0x1030#define HFCUSB_ACTIVATE 0x2031#define HFCUSB_DO_ACTION 0x4032#define HFCUSB_NT_G2_G3 0x803334/* timers */35#define NT_ACTIVATION_TIMER 0x01 /* enables NT mode activation Timer */36#define NT_T1_COUNT 103738#define MAX_BCH_SIZE 2048 /* allowed B-channel packet size */3940#define HFCUSB_RX_THRESHOLD 64 /* threshold for fifo report bit rx */41#define HFCUSB_TX_THRESHOLD 96 /* threshold for fifo report bit tx */4243#define HFCUSB_CHIP_ID 0x16 /* Chip ID register index */44#define HFCUSB_CIRM 0x00 /* cirm register index */45#define HFCUSB_USB_SIZE 0x07 /* int length register */46#define HFCUSB_USB_SIZE_I 0x06 /* iso length register */47#define HFCUSB_F_CROSS 0x0b /* bit order register */48#define HFCUSB_CLKDEL 0x37 /* bit delay register */49#define HFCUSB_CON_HDLC 0xfa /* channel connect register */50#define HFCUSB_HDLC_PAR 0xfb51#define HFCUSB_SCTRL 0x31 /* S-bus control register (tx) */52#define HFCUSB_SCTRL_E 0x32 /* same for E and special funcs */53#define HFCUSB_SCTRL_R 0x33 /* S-bus control register (rx) */54#define HFCUSB_F_THRES 0x0c /* threshold register */55#define HFCUSB_FIFO 0x0f /* fifo select register */56#define HFCUSB_F_USAGE 0x1a /* fifo usage register */57#define HFCUSB_MST_MODE0 0x1458#define HFCUSB_MST_MODE1 0x1559#define HFCUSB_P_DATA 0x1f60#define HFCUSB_INC_RES_F 0x0e61#define HFCUSB_B1_SSL 0x2062#define HFCUSB_B2_SSL 0x2163#define HFCUSB_B1_RSL 0x2464#define HFCUSB_B2_RSL 0x2565#define HFCUSB_STATES 0x30666768#define HFCUSB_CHIPID 0x40 /* ID value of HFC-S USB */6970/* fifo registers */71#define HFCUSB_NUM_FIFOS 8 /* maximum number of fifos */72#define HFCUSB_B1_TX 0 /* index for B1 transmit bulk/int */73#define HFCUSB_B1_RX 1 /* index for B1 receive bulk/int */74#define HFCUSB_B2_TX 275#define HFCUSB_B2_RX 376#define HFCUSB_D_TX 477#define HFCUSB_D_RX 578#define HFCUSB_PCM_TX 679#define HFCUSB_PCM_RX 7808182#define USB_INT 083#define USB_BULK 184#define USB_ISOC 28586#define ISOC_PACKETS_D 887#define ISOC_PACKETS_B 888#define ISO_BUFFER_SIZE 1288990/* defines how much ISO packets are handled in one URB */91static int iso_packets[8] =92{ ISOC_PACKETS_B, ISOC_PACKETS_B, ISOC_PACKETS_B, ISOC_PACKETS_B,93ISOC_PACKETS_D, ISOC_PACKETS_D, ISOC_PACKETS_D, ISOC_PACKETS_D94};959697/* Fifo flow Control for TX ISO */98#define SINK_MAX 6899#define SINK_MIN 48100#define SINK_DMIN 12101#define SINK_DMAX 18102#define BITLINE_INF (-96*8)103104/* HFC-S USB register access by Control-URSs */105#define write_reg_atomic(a, b, c) \106usb_control_msg((a)->dev, (a)->ctrl_out_pipe, 0, 0x40, (c), (b), \1070, 0, HFC_CTRL_TIMEOUT)108#define read_reg_atomic(a, b, c) \109usb_control_msg((a)->dev, (a)->ctrl_in_pipe, 1, 0xC0, 0, (b), (c), \1101, HFC_CTRL_TIMEOUT)111#define HFC_CTRL_BUFSIZE 64112113struct ctrl_buf {114__u8 hfcs_reg; /* register number */115__u8 reg_val; /* value to be written (or read) */116};117118/*119* URB error codes120* Used to represent a list of values and their respective symbolic names121*/122struct hfcusb_symbolic_list {123const int num;124const char *name;125};126127static struct hfcusb_symbolic_list urb_errlist[] = {128{-ENOMEM, "No memory for allocation of internal structures"},129{-ENOSPC, "The host controller's bandwidth is already consumed"},130{-ENOENT, "URB was canceled by unlink_urb"},131{-EXDEV, "ISO transfer only partially completed"},132{-EAGAIN, "Too match scheduled for the future"},133{-ENXIO, "URB already queued"},134{-EFBIG, "Too much ISO frames requested"},135{-ENOSR, "Buffer error (overrun)"},136{-EPIPE, "Specified endpoint is stalled (device not responding)"},137{-EOVERFLOW, "Babble (bad cable?)"},138{-EPROTO, "Bit-stuff error (bad cable?)"},139{-EILSEQ, "CRC/Timeout"},140{-ETIMEDOUT, "NAK (device does not respond)"},141{-ESHUTDOWN, "Device unplugged"},142{-1, NULL}143};144145static inline const char *146symbolic(struct hfcusb_symbolic_list list[], const int num)147{148int i;149for (i = 0; list[i].name != NULL; i++)150if (list[i].num == num)151return list[i].name;152return "<unknown USB Error>";153}154155/* USB descriptor need to contain one of the following EndPoint combination: */156#define CNF_4INT3ISO 1 /* 4 INT IN, 3 ISO OUT */157#define CNF_3INT3ISO 2 /* 3 INT IN, 3 ISO OUT */158#define CNF_4ISO3ISO 3 /* 4 ISO IN, 3 ISO OUT */159#define CNF_3ISO3ISO 4 /* 3 ISO IN, 3 ISO OUT */160161#define EP_NUL 1 /* Endpoint at this position not allowed */162#define EP_NOP 2 /* all type of endpoints allowed at this position */163#define EP_ISO 3 /* Isochron endpoint mandatory at this position */164#define EP_BLK 4 /* Bulk endpoint mandatory at this position */165#define EP_INT 5 /* Interrupt endpoint mandatory at this position */166167#define HFC_CHAN_B1 0168#define HFC_CHAN_B2 1169#define HFC_CHAN_D 2170#define HFC_CHAN_E 3171172173/*174* List of all supported enpoints configiration sets, used to find the175* best matching endpoint configuration within a devices' USB descriptor.176* We need at least 3 RX endpoints, and 3 TX endpoints, either177* INT-in and ISO-out, or ISO-in and ISO-out)178* with 4 RX endpoints even E-Channel logging is possible179*/180static int181validconf[][19] = {182/* INT in, ISO out config */183{EP_NUL, EP_INT, EP_NUL, EP_INT, EP_NUL, EP_INT, EP_NOP, EP_INT,184EP_ISO, EP_NUL, EP_ISO, EP_NUL, EP_ISO, EP_NUL, EP_NUL, EP_NUL,185CNF_4INT3ISO, 2, 1},186{EP_NUL, EP_INT, EP_NUL, EP_INT, EP_NUL, EP_INT, EP_NUL, EP_NUL,187EP_ISO, EP_NUL, EP_ISO, EP_NUL, EP_ISO, EP_NUL, EP_NUL, EP_NUL,188CNF_3INT3ISO, 2, 0},189/* ISO in, ISO out config */190{EP_NOP, EP_NOP, EP_NOP, EP_NOP, EP_NOP, EP_NOP, EP_NOP, EP_NOP,191EP_ISO, EP_ISO, EP_ISO, EP_ISO, EP_ISO, EP_ISO, EP_NOP, EP_ISO,192CNF_4ISO3ISO, 2, 1},193{EP_NUL, EP_NUL, EP_NUL, EP_NUL, EP_NUL, EP_NUL, EP_NUL, EP_NUL,194EP_ISO, EP_ISO, EP_ISO, EP_ISO, EP_ISO, EP_ISO, EP_NUL, EP_NUL,195CNF_3ISO3ISO, 2, 0},196{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} /* EOL element */197};198199/* string description of chosen config */200static char *conf_str[] = {201"4 Interrupt IN + 3 Isochron OUT",202"3 Interrupt IN + 3 Isochron OUT",203"4 Isochron IN + 3 Isochron OUT",204"3 Isochron IN + 3 Isochron OUT"205};206207208#define LED_OFF 0 /* no LED support */209#define LED_SCHEME1 1 /* LED standard scheme */210#define LED_SCHEME2 2 /* not used yet... */211212#define LED_POWER_ON 1213#define LED_POWER_OFF 2214#define LED_S0_ON 3215#define LED_S0_OFF 4216#define LED_B1_ON 5217#define LED_B1_OFF 6218#define LED_B1_DATA 7219#define LED_B2_ON 8220#define LED_B2_OFF 9221#define LED_B2_DATA 10222223#define LED_NORMAL 0 /* LEDs are normal */224#define LED_INVERTED 1 /* LEDs are inverted */225226/* time in ms to perform a Flashing LED when B-Channel has traffic */227#define LED_TIME 250228229230231struct hfcsusb;232struct usb_fifo;233234/* structure defining input+output fifos (interrupt/bulk mode) */235struct iso_urb {236struct urb *urb;237__u8 buffer[ISO_BUFFER_SIZE]; /* buffer rx/tx USB URB data */238struct usb_fifo *owner_fifo; /* pointer to owner fifo */239__u8 indx; /* Fifos's ISO double buffer 0 or 1 ? */240#ifdef ISO_FRAME_START_DEBUG241int start_frames[ISO_FRAME_START_RING_COUNT];242__u8 iso_frm_strt_pos; /* index in start_frame[] */243#endif244};245246struct usb_fifo {247int fifonum; /* fifo index attached to this structure */248int active; /* fifo is currently active */249struct hfcsusb *hw; /* pointer to main structure */250int pipe; /* address of endpoint */251__u8 usb_packet_maxlen; /* maximum length for usb transfer */252unsigned int max_size; /* maximum size of receive/send packet */253__u8 intervall; /* interrupt interval */254struct urb *urb; /* transfer structure for usb routines */255__u8 buffer[128]; /* buffer USB INT OUT URB data */256int bit_line; /* how much bits are in the fifo? */257258__u8 usb_transfer_mode; /* switched between ISO and INT */259struct iso_urb iso[2]; /* two urbs to have one always260one pending */261262struct dchannel *dch; /* link to hfcsusb_t->dch */263struct bchannel *bch; /* link to hfcsusb_t->bch */264struct dchannel *ech; /* link to hfcsusb_t->ech, TODO: E-CHANNEL */265int last_urblen; /* remember length of last packet */266__u8 stop_gracefull; /* stops URB retransmission */267};268269struct hfcsusb {270struct list_head list;271struct dchannel dch;272struct bchannel bch[2];273struct dchannel ech; /* TODO : wait for struct echannel ;) */274275struct usb_device *dev; /* our device */276struct usb_interface *intf; /* used interface */277int if_used; /* used interface number */278int alt_used; /* used alternate config */279int cfg_used; /* configuration index used */280int vend_idx; /* index in hfcsusb_idtab */281int packet_size;282int iso_packet_size;283struct usb_fifo fifos[HFCUSB_NUM_FIFOS];284285/* control pipe background handling */286struct ctrl_buf ctrl_buff[HFC_CTRL_BUFSIZE];287int ctrl_in_idx, ctrl_out_idx, ctrl_cnt;288struct urb *ctrl_urb;289struct usb_ctrlrequest ctrl_write;290struct usb_ctrlrequest ctrl_read;291int ctrl_paksize;292int ctrl_in_pipe, ctrl_out_pipe;293spinlock_t ctrl_lock; /* lock for ctrl */294spinlock_t lock;295296__u8 threshold_mask;297__u8 led_state;298299__u8 protocol;300int nt_timer;301int open;302__u8 timers;303__u8 initdone;304char name[MISDN_MAX_IDLEN];305};306307/* private vendor specific data */308struct hfcsusb_vdata {309__u8 led_scheme; /* led display scheme */310signed short led_bits[8]; /* array of 8 possible LED bitmask */311char *vend_name; /* device name */312};313314315#define HFC_MAX_TE_LAYER1_STATE 8316#define HFC_MAX_NT_LAYER1_STATE 4317318static const char *HFC_TE_LAYER1_STATES[HFC_MAX_TE_LAYER1_STATE + 1] = {319"TE F0 - Reset",320"TE F1 - Reset",321"TE F2 - Sensing",322"TE F3 - Deactivated",323"TE F4 - Awaiting signal",324"TE F5 - Identifying input",325"TE F6 - Synchronized",326"TE F7 - Activated",327"TE F8 - Lost framing",328};329330static const char *HFC_NT_LAYER1_STATES[HFC_MAX_NT_LAYER1_STATE + 1] = {331"NT G0 - Reset",332"NT G1 - Deactive",333"NT G2 - Pending activation",334"NT G3 - Active",335"NT G4 - Pending deactivation",336};337338/* supported devices */339static struct usb_device_id hfcsusb_idtab[] = {340{341USB_DEVICE(0x0959, 0x2bd0),342.driver_info = (unsigned long) &((struct hfcsusb_vdata)343{LED_OFF, {4, 0, 2, 1},344"ISDN USB TA (Cologne Chip HFC-S USB based)"}),345},346{347USB_DEVICE(0x0675, 0x1688),348.driver_info = (unsigned long) &((struct hfcsusb_vdata)349{LED_SCHEME1, {1, 2, 0, 0},350"DrayTek miniVigor 128 USB ISDN TA"}),351},352{353USB_DEVICE(0x07b0, 0x0007),354.driver_info = (unsigned long) &((struct hfcsusb_vdata)355{LED_SCHEME1, {0x80, -64, -32, -16},356"Billion tiny USB ISDN TA 128"}),357},358{359USB_DEVICE(0x0742, 0x2008),360.driver_info = (unsigned long) &((struct hfcsusb_vdata)361{LED_SCHEME1, {4, 0, 2, 1},362"Stollmann USB TA"}),363},364{365USB_DEVICE(0x0742, 0x2009),366.driver_info = (unsigned long) &((struct hfcsusb_vdata)367{LED_SCHEME1, {4, 0, 2, 1},368"Aceex USB ISDN TA"}),369},370{371USB_DEVICE(0x0742, 0x200A),372.driver_info = (unsigned long) &((struct hfcsusb_vdata)373{LED_SCHEME1, {4, 0, 2, 1},374"OEM USB ISDN TA"}),375},376{377USB_DEVICE(0x08e3, 0x0301),378.driver_info = (unsigned long) &((struct hfcsusb_vdata)379{LED_SCHEME1, {2, 0, 1, 4},380"Olitec USB RNIS"}),381},382{383USB_DEVICE(0x07fa, 0x0846),384.driver_info = (unsigned long) &((struct hfcsusb_vdata)385{LED_SCHEME1, {0x80, -64, -32, -16},386"Bewan Modem RNIS USB"}),387},388{389USB_DEVICE(0x07fa, 0x0847),390.driver_info = (unsigned long) &((struct hfcsusb_vdata)391{LED_SCHEME1, {0x80, -64, -32, -16},392"Djinn Numeris USB"}),393},394{395USB_DEVICE(0x07b0, 0x0006),396.driver_info = (unsigned long) &((struct hfcsusb_vdata)397{LED_SCHEME1, {0x80, -64, -32, -16},398"Twister ISDN TA"}),399},400{401USB_DEVICE(0x071d, 0x1005),402.driver_info = (unsigned long) &((struct hfcsusb_vdata)403{LED_SCHEME1, {0x02, 0, 0x01, 0x04},404"Eicon DIVA USB 4.0"}),405},406{407USB_DEVICE(0x0586, 0x0102),408.driver_info = (unsigned long) &((struct hfcsusb_vdata)409{LED_SCHEME1, {0x88, -64, -32, -16},410"ZyXEL OMNI.NET USB II"}),411},412{ }413};414415MODULE_DEVICE_TABLE(usb, hfcsusb_idtab);416417#endif /* __HFCSUSB_H__ */418419420