201-hfc_usb_backport.patch 87 KB

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