hfc_usb.c 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752
  1. /*
  2. * hfc_usb.c
  3. *
  4. * $Id: hfc_usb.c,v 2.3.2.13 2006/02/17 17:17:22 mbachem Exp $
  5. *
  6. * modular HiSax ISDN driver for Colognechip HFC-S USB chip
  7. *
  8. * Authors : Peter Sprenger (sprenger@moving-bytes.de)
  9. * Martin Bachem (info@colognechip.com)
  10. *
  11. * based on the first hfc_usb driver of
  12. * Werner Cornelius (werner@isdn-development.de)
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2, or (at your option)
  17. * any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  27. *
  28. * See Version Histroy at the bottom of this file
  29. *
  30. */
  31. #include <linux/types.h>
  32. #include <linux/stddef.h>
  33. #include <linux/timer.h>
  34. #include <linux/init.h>
  35. #include <linux/module.h>
  36. #include <linux/kernel_stat.h>
  37. #include <linux/usb.h>
  38. #include <linux/kernel.h>
  39. #include <linux/smp_lock.h>
  40. #include <linux/sched.h>
  41. #include "hisax.h"
  42. #include "hisax_if.h"
  43. #include "hfc_usb.h"
  44. static const char *hfcusb_revision =
  45. "$Revision: 2.3.2.13 $ $Date: 2006/02/17 17:17:22 $ ";
  46. /* Hisax debug support
  47. * use "modprobe debug=x" where x is bitfield of USB_DBG & ISDN_DBG
  48. */
  49. #ifdef CONFIG_HISAX_DEBUG
  50. #include <linux/moduleparam.h>
  51. #define __debug_variable hfc_debug
  52. #include "hisax_debug.h"
  53. static u_int debug;
  54. module_param(debug, uint, 0);
  55. static int hfc_debug;
  56. #endif
  57. /* private vendor specific data */
  58. typedef struct {
  59. __u8 led_scheme; // led display scheme
  60. signed short led_bits[8]; // array of 8 possible LED bitmask settings
  61. char *vend_name; // device name
  62. } hfcsusb_vdata;
  63. /****************************************/
  64. /* data defining the devices to be used */
  65. /****************************************/
  66. static struct usb_device_id hfcusb_idtab[] = {
  67. {
  68. USB_DEVICE(0x0959, 0x2bd0),
  69. .driver_info = (unsigned long) &((hfcsusb_vdata)
  70. {LED_OFF, {4, 0, 2, 1},
  71. "ISDN USB TA (Cologne Chip HFC-S USB based)"}),
  72. },
  73. {
  74. USB_DEVICE(0x0675, 0x1688),
  75. .driver_info = (unsigned long) &((hfcsusb_vdata)
  76. {LED_SCHEME1, {1, 2, 0, 0},
  77. "DrayTek miniVigor 128 USB ISDN TA"}),
  78. },
  79. {
  80. USB_DEVICE(0x07b0, 0x0007),
  81. .driver_info = (unsigned long) &((hfcsusb_vdata)
  82. {LED_SCHEME1, {0x80, -64, -32, -16},
  83. "Billion tiny USB ISDN TA 128"}),
  84. },
  85. {
  86. USB_DEVICE(0x0742, 0x2008),
  87. .driver_info = (unsigned long) &((hfcsusb_vdata)
  88. {LED_SCHEME1, {4, 0, 2, 1},
  89. "Stollmann USB TA"}),
  90. },
  91. {
  92. USB_DEVICE(0x0742, 0x2009),
  93. .driver_info = (unsigned long) &((hfcsusb_vdata)
  94. {LED_SCHEME1, {4, 0, 2, 1},
  95. "Aceex USB ISDN TA"}),
  96. },
  97. {
  98. USB_DEVICE(0x0742, 0x200A),
  99. .driver_info = (unsigned long) &((hfcsusb_vdata)
  100. {LED_SCHEME1, {4, 0, 2, 1},
  101. "OEM USB ISDN TA"}),
  102. },
  103. {
  104. USB_DEVICE(0x08e3, 0x0301),
  105. .driver_info = (unsigned long) &((hfcsusb_vdata)
  106. {LED_SCHEME1, {2, 0, 1, 4},
  107. "Olitec USB RNIS"}),
  108. },
  109. {
  110. USB_DEVICE(0x07fa, 0x0846),
  111. .driver_info = (unsigned long) &((hfcsusb_vdata)
  112. {LED_SCHEME1, {0x80, -64, -32, -16},
  113. "Bewan Modem RNIS USB"}),
  114. },
  115. {
  116. USB_DEVICE(0x07fa, 0x0847),
  117. .driver_info = (unsigned long) &((hfcsusb_vdata)
  118. {LED_SCHEME1, {0x80, -64, -32, -16},
  119. "Djinn Numeris USB"}),
  120. },
  121. {
  122. USB_DEVICE(0x07b0, 0x0006),
  123. .driver_info = (unsigned long) &((hfcsusb_vdata)
  124. {LED_SCHEME1, {0x80, -64, -32, -16},
  125. "Twister ISDN TA"}),
  126. },
  127. { }
  128. };
  129. /***************************************************************/
  130. /* structure defining input+output fifos (interrupt/bulk mode) */
  131. /***************************************************************/
  132. struct usb_fifo; /* forward definition */
  133. typedef struct iso_urb_struct {
  134. struct urb *purb;
  135. __u8 buffer[ISO_BUFFER_SIZE]; /* buffer incoming/outgoing data */
  136. struct usb_fifo *owner_fifo; /* pointer to owner fifo */
  137. } iso_urb_struct;
  138. struct hfcusb_data; /* forward definition */
  139. typedef struct usb_fifo {
  140. int fifonum; /* fifo index attached to this structure */
  141. int active; /* fifo is currently active */
  142. struct hfcusb_data *hfc; /* pointer to main structure */
  143. int pipe; /* address of endpoint */
  144. __u8 usb_packet_maxlen; /* maximum length for usb transfer */
  145. unsigned int max_size; /* maximum size of receive/send packet */
  146. __u8 intervall; /* interrupt interval */
  147. struct sk_buff *skbuff; /* actual used buffer */
  148. struct urb *urb; /* transfer structure for usb routines */
  149. __u8 buffer[128]; /* buffer incoming/outgoing data */
  150. int bit_line; /* how much bits are in the fifo? */
  151. volatile __u8 usb_transfer_mode; /* switched between ISO and INT */
  152. iso_urb_struct iso[2]; /* need two urbs to have one always for pending */
  153. struct hisax_if *hif; /* hisax interface */
  154. int delete_flg; /* only delete skbuff once */
  155. int last_urblen; /* remember length of last packet */
  156. } usb_fifo;
  157. /*********************************************/
  158. /* structure holding all data for one device */
  159. /*********************************************/
  160. typedef struct hfcusb_data {
  161. /* HiSax Interface for loadable Layer1 drivers */
  162. struct hisax_d_if d_if; /* see hisax_if.h */
  163. struct hisax_b_if b_if[2]; /* see hisax_if.h */
  164. int protocol;
  165. struct usb_device *dev; /* our device */
  166. int if_used; /* used interface number */
  167. int alt_used; /* used alternate config */
  168. int ctrl_paksize; /* control pipe packet size */
  169. int ctrl_in_pipe, ctrl_out_pipe; /* handles for control pipe */
  170. int cfg_used; /* configuration index used */
  171. int vend_idx; /* vendor found */
  172. int b_mode[2]; /* B-channel mode */
  173. int l1_activated; /* layer 1 activated */
  174. int disc_flag; /* TRUE if device was disonnected to avoid some USB actions */
  175. int packet_size, iso_packet_size;
  176. /* control pipe background handling */
  177. ctrl_buft ctrl_buff[HFC_CTRL_BUFSIZE]; /* buffer holding queued data */
  178. volatile int ctrl_in_idx, ctrl_out_idx, ctrl_cnt; /* input/output pointer + count */
  179. struct urb *ctrl_urb; /* transfer structure for control channel */
  180. struct usb_ctrlrequest ctrl_write; /* buffer for control write request */
  181. struct usb_ctrlrequest ctrl_read; /* same for read request */
  182. __u8 old_led_state, led_state, led_new_data, led_b_active;
  183. volatile __u8 threshold_mask; /* threshold actually reported */
  184. volatile __u8 bch_enables; /* or mask for sctrl_r and sctrl register values */
  185. usb_fifo fifos[HFCUSB_NUM_FIFOS]; /* structure holding all fifo data */
  186. volatile __u8 l1_state; /* actual l1 state */
  187. struct timer_list t3_timer; /* timer 3 for activation/deactivation */
  188. struct timer_list t4_timer; /* timer 4 for activation/deactivation */
  189. } hfcusb_data;
  190. static void collect_rx_frame(usb_fifo * fifo, __u8 * data, int len,
  191. int finish);
  192. static inline const char *
  193. symbolic(struct hfcusb_symbolic_list list[], const int num)
  194. {
  195. int i;
  196. for (i = 0; list[i].name != NULL; i++)
  197. if (list[i].num == num)
  198. return (list[i].name);
  199. return "<unknown ERROR>";
  200. }
  201. /******************************************************/
  202. /* start next background transfer for control channel */
  203. /******************************************************/
  204. static void
  205. ctrl_start_transfer(hfcusb_data * hfc)
  206. {
  207. if (hfc->ctrl_cnt) {
  208. hfc->ctrl_urb->pipe = hfc->ctrl_out_pipe;
  209. hfc->ctrl_urb->setup_packet = (u_char *) & hfc->ctrl_write;
  210. hfc->ctrl_urb->transfer_buffer = NULL;
  211. hfc->ctrl_urb->transfer_buffer_length = 0;
  212. hfc->ctrl_write.wIndex =
  213. cpu_to_le16(hfc->ctrl_buff[hfc->ctrl_out_idx].hfc_reg);
  214. hfc->ctrl_write.wValue =
  215. cpu_to_le16(hfc->ctrl_buff[hfc->ctrl_out_idx].reg_val);
  216. usb_submit_urb(hfc->ctrl_urb, GFP_ATOMIC); /* start transfer */
  217. }
  218. } /* ctrl_start_transfer */
  219. /************************************/
  220. /* queue a control transfer request */
  221. /* return 0 on success. */
  222. /************************************/
  223. static int
  224. queue_control_request(hfcusb_data * hfc, __u8 reg, __u8 val, int action)
  225. {
  226. ctrl_buft *buf;
  227. if (hfc->ctrl_cnt >= HFC_CTRL_BUFSIZE)
  228. return (1); /* no space left */
  229. buf = &hfc->ctrl_buff[hfc->ctrl_in_idx]; /* pointer to new index */
  230. buf->hfc_reg = reg;
  231. buf->reg_val = val;
  232. buf->action = action;
  233. if (++hfc->ctrl_in_idx >= HFC_CTRL_BUFSIZE)
  234. hfc->ctrl_in_idx = 0; /* pointer wrap */
  235. if (++hfc->ctrl_cnt == 1)
  236. ctrl_start_transfer(hfc);
  237. return (0);
  238. } /* queue_control_request */
  239. static int
  240. control_action_handler(hfcusb_data * hfc, int reg, int val, int action)
  241. {
  242. if (!action)
  243. return (1); /* no action defined */
  244. return (0);
  245. }
  246. /***************************************************************/
  247. /* control completion routine handling background control cmds */
  248. /***************************************************************/
  249. static void
  250. ctrl_complete(struct urb *urb)
  251. {
  252. hfcusb_data *hfc = (hfcusb_data *) urb->context;
  253. ctrl_buft *buf;
  254. urb->dev = hfc->dev;
  255. if (hfc->ctrl_cnt) {
  256. buf = &hfc->ctrl_buff[hfc->ctrl_out_idx];
  257. control_action_handler(hfc, buf->hfc_reg, buf->reg_val,
  258. buf->action);
  259. hfc->ctrl_cnt--; /* decrement actual count */
  260. if (++hfc->ctrl_out_idx >= HFC_CTRL_BUFSIZE)
  261. hfc->ctrl_out_idx = 0; /* pointer wrap */
  262. ctrl_start_transfer(hfc); /* start next transfer */
  263. }
  264. } /* ctrl_complete */
  265. /***************************************************/
  266. /* write led data to auxport & invert if necessary */
  267. /***************************************************/
  268. static void
  269. write_led(hfcusb_data * hfc, __u8 led_state)
  270. {
  271. if (led_state != hfc->old_led_state) {
  272. hfc->old_led_state = led_state;
  273. queue_control_request(hfc, HFCUSB_P_DATA, led_state, 1);
  274. }
  275. }
  276. /**************************/
  277. /* handle LED bits */
  278. /**************************/
  279. static void
  280. set_led_bit(hfcusb_data * hfc, signed short led_bits, int unset)
  281. {
  282. if (unset) {
  283. if (led_bits < 0)
  284. hfc->led_state |= abs(led_bits);
  285. else
  286. hfc->led_state &= ~led_bits;
  287. } else {
  288. if (led_bits < 0)
  289. hfc->led_state &= ~abs(led_bits);
  290. else
  291. hfc->led_state |= led_bits;
  292. }
  293. }
  294. /**************************/
  295. /* handle LED requests */
  296. /**************************/
  297. static void
  298. handle_led(hfcusb_data * hfc, int event)
  299. {
  300. hfcsusb_vdata *driver_info =
  301. (hfcsusb_vdata *) hfcusb_idtab[hfc->vend_idx].driver_info;
  302. /* if no scheme -> no LED action */
  303. if (driver_info->led_scheme == LED_OFF)
  304. return;
  305. switch (event) {
  306. case LED_POWER_ON:
  307. set_led_bit(hfc, driver_info->led_bits[0],
  308. 0);
  309. set_led_bit(hfc, driver_info->led_bits[1],
  310. 1);
  311. set_led_bit(hfc, driver_info->led_bits[2],
  312. 1);
  313. set_led_bit(hfc, driver_info->led_bits[3],
  314. 1);
  315. break;
  316. case LED_POWER_OFF: /* no Power off handling */
  317. break;
  318. case LED_S0_ON:
  319. set_led_bit(hfc, driver_info->led_bits[1],
  320. 0);
  321. break;
  322. case LED_S0_OFF:
  323. set_led_bit(hfc, driver_info->led_bits[1],
  324. 1);
  325. break;
  326. case LED_B1_ON:
  327. set_led_bit(hfc, driver_info->led_bits[2],
  328. 0);
  329. break;
  330. case LED_B1_OFF:
  331. set_led_bit(hfc, driver_info->led_bits[2],
  332. 1);
  333. break;
  334. case LED_B2_ON:
  335. set_led_bit(hfc, driver_info->led_bits[3],
  336. 0);
  337. break;
  338. case LED_B2_OFF:
  339. set_led_bit(hfc, driver_info->led_bits[3],
  340. 1);
  341. break;
  342. }
  343. write_led(hfc, hfc->led_state);
  344. }
  345. /********************************/
  346. /* called when timer t3 expires */
  347. /********************************/
  348. static void
  349. l1_timer_expire_t3(hfcusb_data * hfc)
  350. {
  351. hfc->d_if.ifc.l1l2(&hfc->d_if.ifc, PH_DEACTIVATE | INDICATION,
  352. NULL);
  353. #ifdef CONFIG_HISAX_DEBUG
  354. DBG(ISDN_DBG,
  355. "HFC-S USB: PH_DEACTIVATE | INDICATION sent (T3 expire)");
  356. #endif
  357. hfc->l1_activated = FALSE;
  358. handle_led(hfc, LED_S0_OFF);
  359. /* deactivate : */
  360. queue_control_request(hfc, HFCUSB_STATES, 0x10, 1);
  361. queue_control_request(hfc, HFCUSB_STATES, 3, 1);
  362. }
  363. /********************************/
  364. /* called when timer t4 expires */
  365. /********************************/
  366. static void
  367. l1_timer_expire_t4(hfcusb_data * hfc)
  368. {
  369. hfc->d_if.ifc.l1l2(&hfc->d_if.ifc, PH_DEACTIVATE | INDICATION,
  370. NULL);
  371. #ifdef CONFIG_HISAX_DEBUG
  372. DBG(ISDN_DBG,
  373. "HFC-S USB: PH_DEACTIVATE | INDICATION sent (T4 expire)");
  374. #endif
  375. hfc->l1_activated = FALSE;
  376. handle_led(hfc, LED_S0_OFF);
  377. }
  378. /*****************************/
  379. /* handle S0 state changes */
  380. /*****************************/
  381. static void
  382. state_handler(hfcusb_data * hfc, __u8 state)
  383. {
  384. __u8 old_state;
  385. old_state = hfc->l1_state;
  386. if (state == old_state || state < 1 || state > 8)
  387. return;
  388. #ifdef CONFIG_HISAX_DEBUG
  389. DBG(ISDN_DBG, "HFC-S USB: new S0 state:%d old_state:%d", state,
  390. old_state);
  391. #endif
  392. if (state < 4 || state == 7 || state == 8) {
  393. if (timer_pending(&hfc->t3_timer))
  394. del_timer(&hfc->t3_timer);
  395. #ifdef CONFIG_HISAX_DEBUG
  396. DBG(ISDN_DBG, "HFC-S USB: T3 deactivated");
  397. #endif
  398. }
  399. if (state >= 7) {
  400. if (timer_pending(&hfc->t4_timer))
  401. del_timer(&hfc->t4_timer);
  402. #ifdef CONFIG_HISAX_DEBUG
  403. DBG(ISDN_DBG, "HFC-S USB: T4 deactivated");
  404. #endif
  405. }
  406. if (state == 7 && !hfc->l1_activated) {
  407. hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,
  408. PH_ACTIVATE | INDICATION, NULL);
  409. #ifdef CONFIG_HISAX_DEBUG
  410. DBG(ISDN_DBG, "HFC-S USB: PH_ACTIVATE | INDICATION sent");
  411. #endif
  412. hfc->l1_activated = TRUE;
  413. handle_led(hfc, LED_S0_ON);
  414. } else if (state <= 3 /* && activated */ ) {
  415. if (old_state == 7 || old_state == 8) {
  416. #ifdef CONFIG_HISAX_DEBUG
  417. DBG(ISDN_DBG, "HFC-S USB: T4 activated");
  418. #endif
  419. if (!timer_pending(&hfc->t4_timer)) {
  420. hfc->t4_timer.expires =
  421. jiffies + (HFC_TIMER_T4 * HZ) / 1000;
  422. add_timer(&hfc->t4_timer);
  423. }
  424. } else {
  425. hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,
  426. PH_DEACTIVATE | INDICATION,
  427. NULL);
  428. #ifdef CONFIG_HISAX_DEBUG
  429. DBG(ISDN_DBG,
  430. "HFC-S USB: PH_DEACTIVATE | INDICATION sent");
  431. #endif
  432. hfc->l1_activated = FALSE;
  433. handle_led(hfc, LED_S0_OFF);
  434. }
  435. }
  436. hfc->l1_state = state;
  437. }
  438. /* prepare iso urb */
  439. static void
  440. fill_isoc_urb(struct urb *urb, struct usb_device *dev, unsigned int pipe,
  441. void *buf, int num_packets, int packet_size, int interval,
  442. usb_complete_t complete, void *context)
  443. {
  444. int k;
  445. spin_lock_init(&urb->lock);
  446. urb->dev = dev;
  447. urb->pipe = pipe;
  448. urb->complete = complete;
  449. urb->number_of_packets = num_packets;
  450. urb->transfer_buffer_length = packet_size * num_packets;
  451. urb->context = context;
  452. urb->transfer_buffer = buf;
  453. urb->transfer_flags = URB_ISO_ASAP;
  454. urb->actual_length = 0;
  455. urb->interval = interval;
  456. for (k = 0; k < num_packets; k++) {
  457. urb->iso_frame_desc[k].offset = packet_size * k;
  458. urb->iso_frame_desc[k].length = packet_size;
  459. urb->iso_frame_desc[k].actual_length = 0;
  460. }
  461. }
  462. /* allocs urbs and start isoc transfer with two pending urbs to avoid
  463. gaps in the transfer chain */
  464. static int
  465. start_isoc_chain(usb_fifo * fifo, int num_packets_per_urb,
  466. usb_complete_t complete, int packet_size)
  467. {
  468. int i, k, errcode;
  469. printk(KERN_INFO "HFC-S USB: starting ISO-chain for Fifo %i\n",
  470. fifo->fifonum);
  471. /* allocate Memory for Iso out Urbs */
  472. for (i = 0; i < 2; i++) {
  473. if (!(fifo->iso[i].purb)) {
  474. fifo->iso[i].purb =
  475. usb_alloc_urb(num_packets_per_urb, GFP_KERNEL);
  476. if (!(fifo->iso[i].purb)) {
  477. printk(KERN_INFO
  478. "alloc urb for fifo %i failed!!!",
  479. fifo->fifonum);
  480. }
  481. fifo->iso[i].owner_fifo = (struct usb_fifo *) fifo;
  482. /* Init the first iso */
  483. if (ISO_BUFFER_SIZE >=
  484. (fifo->usb_packet_maxlen *
  485. num_packets_per_urb)) {
  486. fill_isoc_urb(fifo->iso[i].purb,
  487. fifo->hfc->dev, fifo->pipe,
  488. fifo->iso[i].buffer,
  489. num_packets_per_urb,
  490. fifo->usb_packet_maxlen,
  491. fifo->intervall, complete,
  492. &fifo->iso[i]);
  493. memset(fifo->iso[i].buffer, 0,
  494. sizeof(fifo->iso[i].buffer));
  495. /* defining packet delimeters in fifo->buffer */
  496. for (k = 0; k < num_packets_per_urb; k++) {
  497. fifo->iso[i].purb->
  498. iso_frame_desc[k].offset =
  499. k * packet_size;
  500. fifo->iso[i].purb->
  501. iso_frame_desc[k].length =
  502. packet_size;
  503. }
  504. } else {
  505. printk(KERN_INFO
  506. "HFC-S USB: ISO Buffer size to small!\n");
  507. }
  508. }
  509. fifo->bit_line = BITLINE_INF;
  510. errcode = usb_submit_urb(fifo->iso[i].purb, GFP_KERNEL);
  511. fifo->active = (errcode >= 0) ? 1 : 0;
  512. if (errcode < 0) {
  513. printk(KERN_INFO "HFC-S USB: %s URB nr:%d\n",
  514. symbolic(urb_errlist, errcode), i);
  515. };
  516. }
  517. return (fifo->active);
  518. }
  519. /* stops running iso chain and frees their pending urbs */
  520. static void
  521. stop_isoc_chain(usb_fifo * fifo)
  522. {
  523. int i;
  524. for (i = 0; i < 2; i++) {
  525. if (fifo->iso[i].purb) {
  526. #ifdef CONFIG_HISAX_DEBUG
  527. DBG(USB_DBG,
  528. "HFC-S USB: Stopping iso chain for fifo %i.%i",
  529. fifo->fifonum, i);
  530. #endif
  531. usb_unlink_urb(fifo->iso[i].purb);
  532. usb_free_urb(fifo->iso[i].purb);
  533. fifo->iso[i].purb = NULL;
  534. }
  535. }
  536. if (fifo->urb) {
  537. usb_unlink_urb(fifo->urb);
  538. usb_free_urb(fifo->urb);
  539. fifo->urb = NULL;
  540. }
  541. fifo->active = 0;
  542. }
  543. /* defines how much ISO packets are handled in one URB */
  544. static int iso_packets[8] =
  545. { ISOC_PACKETS_B, ISOC_PACKETS_B, ISOC_PACKETS_B, ISOC_PACKETS_B,
  546. ISOC_PACKETS_D, ISOC_PACKETS_D, ISOC_PACKETS_D, ISOC_PACKETS_D
  547. };
  548. /*****************************************************/
  549. /* transmit completion routine for all ISO tx fifos */
  550. /*****************************************************/
  551. static void
  552. tx_iso_complete(struct urb *urb)
  553. {
  554. iso_urb_struct *context_iso_urb = (iso_urb_struct *) urb->context;
  555. usb_fifo *fifo = context_iso_urb->owner_fifo;
  556. hfcusb_data *hfc = fifo->hfc;
  557. int k, tx_offset, num_isoc_packets, sink, len, current_len,
  558. errcode;
  559. int frame_complete, transp_mode, fifon, status;
  560. __u8 threshbit;
  561. __u8 threshtable[8] = { 1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80 };
  562. fifon = fifo->fifonum;
  563. status = urb->status;
  564. tx_offset = 0;
  565. if (fifo->active && !status) {
  566. transp_mode = 0;
  567. if (fifon < 4 && hfc->b_mode[fifon / 2] == L1_MODE_TRANS)
  568. transp_mode = TRUE;
  569. /* is FifoFull-threshold set for our channel? */
  570. threshbit = threshtable[fifon] & hfc->threshold_mask;
  571. num_isoc_packets = iso_packets[fifon];
  572. /* predict dataflow to avoid fifo overflow */
  573. if (fifon >= HFCUSB_D_TX) {
  574. sink = (threshbit) ? SINK_DMIN : SINK_DMAX;
  575. } else {
  576. sink = (threshbit) ? SINK_MIN : SINK_MAX;
  577. }
  578. fill_isoc_urb(urb, fifo->hfc->dev, fifo->pipe,
  579. context_iso_urb->buffer, num_isoc_packets,
  580. fifo->usb_packet_maxlen, fifo->intervall,
  581. tx_iso_complete, urb->context);
  582. memset(context_iso_urb->buffer, 0,
  583. sizeof(context_iso_urb->buffer));
  584. frame_complete = FALSE;
  585. /* Generate next Iso Packets */
  586. for (k = 0; k < num_isoc_packets; ++k) {
  587. if (fifo->skbuff) {
  588. len = fifo->skbuff->len;
  589. /* we lower data margin every msec */
  590. fifo->bit_line -= sink;
  591. current_len = (0 - fifo->bit_line) / 8;
  592. /* maximum 15 byte for every ISO packet makes our life easier */
  593. if (current_len > 14)
  594. current_len = 14;
  595. current_len =
  596. (len <=
  597. current_len) ? len : current_len;
  598. /* how much bit do we put on the line? */
  599. fifo->bit_line += current_len * 8;
  600. context_iso_urb->buffer[tx_offset] = 0;
  601. if (current_len == len) {
  602. if (!transp_mode) {
  603. /* here frame completion */
  604. context_iso_urb->
  605. buffer[tx_offset] = 1;
  606. /* add 2 byte flags and 16bit CRC at end of ISDN frame */
  607. fifo->bit_line += 32;
  608. }
  609. frame_complete = TRUE;
  610. }
  611. memcpy(context_iso_urb->buffer +
  612. tx_offset + 1, fifo->skbuff->data,
  613. current_len);
  614. skb_pull(fifo->skbuff, current_len);
  615. /* define packet delimeters within the URB buffer */
  616. urb->iso_frame_desc[k].offset = tx_offset;
  617. urb->iso_frame_desc[k].length =
  618. current_len + 1;
  619. tx_offset += (current_len + 1);
  620. } else {
  621. urb->iso_frame_desc[k].offset =
  622. tx_offset++;
  623. urb->iso_frame_desc[k].length = 1;
  624. fifo->bit_line -= sink; /* we lower data margin every msec */
  625. if (fifo->bit_line < BITLINE_INF) {
  626. fifo->bit_line = BITLINE_INF;
  627. }
  628. }
  629. if (frame_complete) {
  630. fifo->delete_flg = TRUE;
  631. fifo->hif->l1l2(fifo->hif,
  632. PH_DATA | CONFIRM,
  633. (void *) (unsigned long) fifo->skbuff->
  634. truesize);
  635. if (fifo->skbuff && fifo->delete_flg) {
  636. dev_kfree_skb_any(fifo->skbuff);
  637. fifo->skbuff = NULL;
  638. fifo->delete_flg = FALSE;
  639. }
  640. frame_complete = FALSE;
  641. }
  642. }
  643. errcode = usb_submit_urb(urb, GFP_ATOMIC);
  644. if (errcode < 0) {
  645. printk(KERN_INFO
  646. "HFC-S USB: error submitting ISO URB: %d \n",
  647. errcode);
  648. }
  649. } else {
  650. if (status && !hfc->disc_flag) {
  651. printk(KERN_INFO
  652. "HFC-S USB: tx_iso_complete : urb->status %s (%i), fifonum=%d\n",
  653. symbolic(urb_errlist, status), status,
  654. fifon);
  655. }
  656. }
  657. } /* tx_iso_complete */
  658. /*****************************************************/
  659. /* receive completion routine for all ISO tx fifos */
  660. /*****************************************************/
  661. static void
  662. rx_iso_complete(struct urb *urb)
  663. {
  664. iso_urb_struct *context_iso_urb = (iso_urb_struct *) urb->context;
  665. usb_fifo *fifo = context_iso_urb->owner_fifo;
  666. hfcusb_data *hfc = fifo->hfc;
  667. int k, len, errcode, offset, num_isoc_packets, fifon, maxlen,
  668. status;
  669. unsigned int iso_status;
  670. __u8 *buf;
  671. static __u8 eof[8];
  672. #ifdef CONFIG_HISAX_DEBUG
  673. __u8 i;
  674. #endif
  675. fifon = fifo->fifonum;
  676. status = urb->status;
  677. if (urb->status == -EOVERFLOW) {
  678. #ifdef CONFIG_HISAX_DEBUG
  679. DBG(USB_DBG,
  680. "HFC-USB: ignoring USB DATAOVERRUN for fifo %i \n",
  681. fifon);
  682. #endif
  683. status = 0;
  684. }
  685. if (fifo->active && !status) {
  686. num_isoc_packets = iso_packets[fifon];
  687. maxlen = fifo->usb_packet_maxlen;
  688. for (k = 0; k < num_isoc_packets; ++k) {
  689. len = urb->iso_frame_desc[k].actual_length;
  690. offset = urb->iso_frame_desc[k].offset;
  691. buf = context_iso_urb->buffer + offset;
  692. iso_status = urb->iso_frame_desc[k].status;
  693. #ifdef CONFIG_HISAX_DEBUG
  694. if (iso_status && !hfc->disc_flag)
  695. DBG(USB_DBG,
  696. "HFC-S USB: ISO packet failure - status:%x",
  697. iso_status);
  698. if ((fifon == 5) && (debug > 1)) {
  699. printk(KERN_INFO
  700. "HFC-S USB: ISO-D-RX lst_urblen:%2d "
  701. "act_urblen:%2d max-urblen:%2d "
  702. "EOF:0x%0x DATA: ",
  703. fifo->last_urblen, len, maxlen,
  704. eof[5]);
  705. for (i = 0; i < len; i++)
  706. printk("%.2x ", buf[i]);
  707. printk("\n");
  708. }
  709. #endif
  710. if (fifo->last_urblen != maxlen) {
  711. /* the threshold mask is in the 2nd status byte */
  712. hfc->threshold_mask = buf[1];
  713. /* care for L1 state only for D-Channel
  714. to avoid overlapped iso completions */
  715. if (fifon == 5) {
  716. /* the S0 state is in the upper half
  717. of the 1st status byte */
  718. state_handler(hfc, buf[0] >> 4);
  719. }
  720. eof[fifon] = buf[0] & 1;
  721. if (len > 2)
  722. collect_rx_frame(fifo, buf + 2,
  723. len - 2,
  724. (len <
  725. maxlen) ?
  726. eof[fifon] : 0);
  727. } else {
  728. collect_rx_frame(fifo, buf, len,
  729. (len <
  730. maxlen) ? eof[fifon] :
  731. 0);
  732. }
  733. fifo->last_urblen = len;
  734. }
  735. fill_isoc_urb(urb, fifo->hfc->dev, fifo->pipe,
  736. context_iso_urb->buffer, num_isoc_packets,
  737. fifo->usb_packet_maxlen, fifo->intervall,
  738. rx_iso_complete, urb->context);
  739. errcode = usb_submit_urb(urb, GFP_ATOMIC);
  740. if (errcode < 0) {
  741. printk(KERN_INFO
  742. "HFC-S USB: error submitting ISO URB: %d \n",
  743. errcode);
  744. }
  745. } else {
  746. if (status && !hfc->disc_flag) {
  747. printk(KERN_INFO
  748. "HFC-S USB: rx_iso_complete : "
  749. "urb->status %d, fifonum %d\n",
  750. status, fifon);
  751. }
  752. }
  753. } /* rx_iso_complete */
  754. /*****************************************************/
  755. /* collect data from interrupt or isochron in */
  756. /*****************************************************/
  757. static void
  758. collect_rx_frame(usb_fifo * fifo, __u8 * data, int len, int finish)
  759. {
  760. hfcusb_data *hfc = fifo->hfc;
  761. int transp_mode, fifon;
  762. #ifdef CONFIG_HISAX_DEBUG
  763. int i;
  764. #endif
  765. fifon = fifo->fifonum;
  766. transp_mode = 0;
  767. if (fifon < 4 && hfc->b_mode[fifon / 2] == L1_MODE_TRANS)
  768. transp_mode = TRUE;
  769. if (!fifo->skbuff) {
  770. fifo->skbuff = dev_alloc_skb(fifo->max_size + 3);
  771. if (!fifo->skbuff) {
  772. printk(KERN_INFO
  773. "HFC-S USB: cannot allocate buffer (dev_alloc_skb) fifo:%d\n",
  774. fifon);
  775. return;
  776. }
  777. }
  778. if (len) {
  779. if (fifo->skbuff->len + len < fifo->max_size) {
  780. memcpy(skb_put(fifo->skbuff, len), data, len);
  781. } else {
  782. #ifdef CONFIG_HISAX_DEBUG
  783. printk(KERN_INFO "HFC-S USB: ");
  784. for (i = 0; i < 15; i++)
  785. printk("%.2x ",
  786. fifo->skbuff->data[fifo->skbuff->
  787. len - 15 + i]);
  788. printk("\n");
  789. #endif
  790. printk(KERN_INFO
  791. "HCF-USB: got frame exceeded fifo->max_size:%d on fifo:%d\n",
  792. fifo->max_size, fifon);
  793. }
  794. }
  795. if (transp_mode && fifo->skbuff->len >= 128) {
  796. fifo->hif->l1l2(fifo->hif, PH_DATA | INDICATION,
  797. fifo->skbuff);
  798. fifo->skbuff = NULL;
  799. return;
  800. }
  801. /* we have a complete hdlc packet */
  802. if (finish) {
  803. if ((!fifo->skbuff->data[fifo->skbuff->len - 1])
  804. && (fifo->skbuff->len > 3)) {
  805. /* remove CRC & status */
  806. skb_trim(fifo->skbuff, fifo->skbuff->len - 3);
  807. if (fifon == HFCUSB_PCM_RX) {
  808. fifo->hif->l1l2(fifo->hif,
  809. PH_DATA_E | INDICATION,
  810. fifo->skbuff);
  811. } else
  812. fifo->hif->l1l2(fifo->hif,
  813. PH_DATA | INDICATION,
  814. fifo->skbuff);
  815. fifo->skbuff = NULL; /* buffer was freed from upper layer */
  816. } else {
  817. if (fifo->skbuff->len > 3) {
  818. printk(KERN_INFO
  819. "HFC-S USB: got frame %d bytes but CRC ERROR on fifo:%d!!!\n",
  820. fifo->skbuff->len, fifon);
  821. #ifdef CONFIG_HISAX_DEBUG
  822. if (debug > 1) {
  823. printk(KERN_INFO "HFC-S USB: ");
  824. for (i = 0; i < 15; i++)
  825. printk("%.2x ",
  826. fifo->skbuff->
  827. data[fifo->skbuff->
  828. len - 15 + i]);
  829. printk("\n");
  830. }
  831. #endif
  832. }
  833. #ifdef CONFIG_HISAX_DEBUG
  834. else {
  835. printk(KERN_INFO
  836. "HFC-S USB: frame to small (%d bytes)!!!\n",
  837. fifo->skbuff->len);
  838. }
  839. #endif
  840. skb_trim(fifo->skbuff, 0);
  841. }
  842. }
  843. }
  844. /***********************************************/
  845. /* receive completion routine for all rx fifos */
  846. /***********************************************/
  847. static void
  848. rx_complete(struct urb *urb)
  849. {
  850. int len;
  851. int status;
  852. __u8 *buf, maxlen, fifon;
  853. usb_fifo *fifo = (usb_fifo *) urb->context;
  854. hfcusb_data *hfc = fifo->hfc;
  855. static __u8 eof[8];
  856. #ifdef CONFIG_HISAX_DEBUG
  857. __u8 i;
  858. #endif
  859. urb->dev = hfc->dev; /* security init */
  860. fifon = fifo->fifonum;
  861. if ((!fifo->active) || (urb->status)) {
  862. #ifdef CONFIG_HISAX_DEBUG
  863. DBG(USB_DBG, "HFC-S USB: RX-Fifo %i is going down (%i)",
  864. fifon, urb->status);
  865. #endif
  866. fifo->urb->interval = 0; /* cancel automatic rescheduling */
  867. if (fifo->skbuff) {
  868. dev_kfree_skb_any(fifo->skbuff);
  869. fifo->skbuff = NULL;
  870. }
  871. return;
  872. }
  873. len = urb->actual_length;
  874. buf = fifo->buffer;
  875. maxlen = fifo->usb_packet_maxlen;
  876. #ifdef CONFIG_HISAX_DEBUG
  877. if ((fifon == 5) && (debug > 1)) {
  878. printk(KERN_INFO
  879. "HFC-S USB: INT-D-RX lst_urblen:%2d act_urblen:%2d max-urblen:%2d EOF:0x%0x DATA: ",
  880. fifo->last_urblen, len, maxlen, eof[5]);
  881. for (i = 0; i < len; i++)
  882. printk("%.2x ", buf[i]);
  883. printk("\n");
  884. }
  885. #endif
  886. if (fifo->last_urblen != fifo->usb_packet_maxlen) {
  887. /* the threshold mask is in the 2nd status byte */
  888. hfc->threshold_mask = buf[1];
  889. /* the S0 state is in the upper half of the 1st status byte */
  890. state_handler(hfc, buf[0] >> 4);
  891. eof[fifon] = buf[0] & 1;
  892. /* if we have more than the 2 status bytes -> collect data */
  893. if (len > 2)
  894. collect_rx_frame(fifo, buf + 2,
  895. urb->actual_length - 2,
  896. (len < maxlen) ? eof[fifon] : 0);
  897. } else {
  898. collect_rx_frame(fifo, buf, urb->actual_length,
  899. (len < maxlen) ? eof[fifon] : 0);
  900. }
  901. fifo->last_urblen = urb->actual_length;
  902. status = usb_submit_urb(urb, GFP_ATOMIC);
  903. if (status) {
  904. printk(KERN_INFO
  905. "HFC-S USB: error resubmitting URN at rx_complete...\n");
  906. }
  907. } /* rx_complete */
  908. /***************************************************/
  909. /* start the interrupt transfer for the given fifo */
  910. /***************************************************/
  911. static void
  912. start_int_fifo(usb_fifo * fifo)
  913. {
  914. int errcode;
  915. printk(KERN_INFO "HFC-S USB: starting intr IN fifo:%d\n",
  916. fifo->fifonum);
  917. if (!fifo->urb) {
  918. fifo->urb = usb_alloc_urb(0, GFP_KERNEL);
  919. if (!fifo->urb)
  920. return;
  921. }
  922. usb_fill_int_urb(fifo->urb, fifo->hfc->dev, fifo->pipe,
  923. fifo->buffer, fifo->usb_packet_maxlen,
  924. rx_complete, fifo, fifo->intervall);
  925. fifo->active = 1; /* must be marked active */
  926. errcode = usb_submit_urb(fifo->urb, GFP_KERNEL);
  927. if (errcode) {
  928. printk(KERN_INFO
  929. "HFC-S USB: submit URB error(start_int_info): status:%i\n",
  930. errcode);
  931. fifo->active = 0;
  932. fifo->skbuff = NULL;
  933. }
  934. } /* start_int_fifo */
  935. /*****************************/
  936. /* set the B-channel mode */
  937. /*****************************/
  938. static void
  939. set_hfcmode(hfcusb_data * hfc, int channel, int mode)
  940. {
  941. __u8 val, idx_table[2] = { 0, 2 };
  942. if (hfc->disc_flag) {
  943. return;
  944. }
  945. #ifdef CONFIG_HISAX_DEBUG
  946. DBG(ISDN_DBG, "HFC-S USB: setting channel %d to mode %d", channel,
  947. mode);
  948. #endif
  949. hfc->b_mode[channel] = mode;
  950. /* setup CON_HDLC */
  951. val = 0;
  952. if (mode != L1_MODE_NULL)
  953. val = 8; /* enable fifo? */
  954. if (mode == L1_MODE_TRANS)
  955. val |= 2; /* set transparent bit */
  956. /* set FIFO to transmit register */
  957. queue_control_request(hfc, HFCUSB_FIFO, idx_table[channel], 1);
  958. queue_control_request(hfc, HFCUSB_CON_HDLC, val, 1);
  959. /* reset fifo */
  960. queue_control_request(hfc, HFCUSB_INC_RES_F, 2, 1);
  961. /* set FIFO to receive register */
  962. queue_control_request(hfc, HFCUSB_FIFO, idx_table[channel] + 1, 1);
  963. queue_control_request(hfc, HFCUSB_CON_HDLC, val, 1);
  964. /* reset fifo */
  965. queue_control_request(hfc, HFCUSB_INC_RES_F, 2, 1);
  966. val = 0x40;
  967. if (hfc->b_mode[0])
  968. val |= 1;
  969. if (hfc->b_mode[1])
  970. val |= 2;
  971. queue_control_request(hfc, HFCUSB_SCTRL, val, 1);
  972. val = 0;
  973. if (hfc->b_mode[0])
  974. val |= 1;
  975. if (hfc->b_mode[1])
  976. val |= 2;
  977. queue_control_request(hfc, HFCUSB_SCTRL_R, val, 1);
  978. if (mode == L1_MODE_NULL) {
  979. if (channel)
  980. handle_led(hfc, LED_B2_OFF);
  981. else
  982. handle_led(hfc, LED_B1_OFF);
  983. } else {
  984. if (channel)
  985. handle_led(hfc, LED_B2_ON);
  986. else
  987. handle_led(hfc, LED_B1_ON);
  988. }
  989. }
  990. static void
  991. hfc_usb_l2l1(struct hisax_if *my_hisax_if, int pr, void *arg)
  992. {
  993. usb_fifo *fifo = my_hisax_if->priv;
  994. hfcusb_data *hfc = fifo->hfc;
  995. switch (pr) {
  996. case PH_ACTIVATE | REQUEST:
  997. if (fifo->fifonum == HFCUSB_D_TX) {
  998. #ifdef CONFIG_HISAX_DEBUG
  999. DBG(ISDN_DBG,
  1000. "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_ACTIVATE | REQUEST");
  1001. #endif
  1002. if (hfc->l1_state != 3
  1003. && hfc->l1_state != 7) {
  1004. hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,
  1005. PH_DEACTIVATE |
  1006. INDICATION,
  1007. NULL);
  1008. #ifdef CONFIG_HISAX_DEBUG
  1009. DBG(ISDN_DBG,
  1010. "HFC-S USB: PH_DEACTIVATE | INDICATION sent (not state 3 or 7)");
  1011. #endif
  1012. } else {
  1013. if (hfc->l1_state == 7) { /* l1 already active */
  1014. hfc->d_if.ifc.l1l2(&hfc->
  1015. d_if.
  1016. ifc,
  1017. PH_ACTIVATE
  1018. |
  1019. INDICATION,
  1020. NULL);
  1021. #ifdef CONFIG_HISAX_DEBUG
  1022. DBG(ISDN_DBG,
  1023. "HFC-S USB: PH_ACTIVATE | INDICATION sent again ;)");
  1024. #endif
  1025. } else {
  1026. /* force sending sending INFO1 */
  1027. queue_control_request(hfc,
  1028. HFCUSB_STATES,
  1029. 0x14,
  1030. 1);
  1031. mdelay(1);
  1032. /* start l1 activation */
  1033. queue_control_request(hfc,
  1034. HFCUSB_STATES,
  1035. 0x04,
  1036. 1);
  1037. if (!timer_pending
  1038. (&hfc->t3_timer)) {
  1039. hfc->t3_timer.
  1040. expires =
  1041. jiffies +
  1042. (HFC_TIMER_T3 *
  1043. HZ) / 1000;
  1044. add_timer(&hfc->
  1045. t3_timer);
  1046. }
  1047. }
  1048. }
  1049. } else {
  1050. #ifdef CONFIG_HISAX_DEBUG
  1051. DBG(ISDN_DBG,
  1052. "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_ACTIVATE | REQUEST");
  1053. #endif
  1054. set_hfcmode(hfc,
  1055. (fifo->fifonum ==
  1056. HFCUSB_B1_TX) ? 0 : 1,
  1057. (long) arg);
  1058. fifo->hif->l1l2(fifo->hif,
  1059. PH_ACTIVATE | INDICATION,
  1060. NULL);
  1061. }
  1062. break;
  1063. case PH_DEACTIVATE | REQUEST:
  1064. if (fifo->fifonum == HFCUSB_D_TX) {
  1065. #ifdef CONFIG_HISAX_DEBUG
  1066. DBG(ISDN_DBG,
  1067. "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_DEACTIVATE | REQUEST");
  1068. #endif
  1069. printk(KERN_INFO
  1070. "HFC-S USB: ISDN TE device should not deativate...\n");
  1071. } else {
  1072. #ifdef CONFIG_HISAX_DEBUG
  1073. DBG(ISDN_DBG,
  1074. "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_DEACTIVATE | REQUEST");
  1075. #endif
  1076. set_hfcmode(hfc,
  1077. (fifo->fifonum ==
  1078. HFCUSB_B1_TX) ? 0 : 1,
  1079. (int) L1_MODE_NULL);
  1080. fifo->hif->l1l2(fifo->hif,
  1081. PH_DEACTIVATE | INDICATION,
  1082. NULL);
  1083. }
  1084. break;
  1085. case PH_DATA | REQUEST:
  1086. if (fifo->skbuff && fifo->delete_flg) {
  1087. dev_kfree_skb_any(fifo->skbuff);
  1088. fifo->skbuff = NULL;
  1089. fifo->delete_flg = FALSE;
  1090. }
  1091. fifo->skbuff = arg; /* we have a new buffer */
  1092. break;
  1093. default:
  1094. printk(KERN_INFO
  1095. "HFC_USB: hfc_usb_d_l2l1: unkown state : %#x\n",
  1096. pr);
  1097. break;
  1098. }
  1099. }
  1100. /***************************************************************************/
  1101. /* usb_init is called once when a new matching device is detected to setup */
  1102. /* main parameters. It registers the driver at the main hisax module. */
  1103. /* on success 0 is returned. */
  1104. /***************************************************************************/
  1105. static int
  1106. usb_init(hfcusb_data * hfc)
  1107. {
  1108. usb_fifo *fifo;
  1109. int i, err;
  1110. u_char b;
  1111. struct hisax_b_if *p_b_if[2];
  1112. /* check the chip id */
  1113. if (read_usb(hfc, HFCUSB_CHIP_ID, &b) != 1) {
  1114. printk(KERN_INFO "HFC-USB: cannot read chip id\n");
  1115. return (1);
  1116. }
  1117. if (b != HFCUSB_CHIPID) {
  1118. printk(KERN_INFO "HFC-S USB: Invalid chip id 0x%02x\n", b);
  1119. return (1);
  1120. }
  1121. /* first set the needed config, interface and alternate */
  1122. err = usb_set_interface(hfc->dev, hfc->if_used, hfc->alt_used);
  1123. /* do Chip reset */
  1124. write_usb(hfc, HFCUSB_CIRM, 8);
  1125. /* aux = output, reset off */
  1126. write_usb(hfc, HFCUSB_CIRM, 0x10);
  1127. /* set USB_SIZE to match the the wMaxPacketSize for INT or BULK transfers */
  1128. write_usb(hfc, HFCUSB_USB_SIZE,
  1129. (hfc->packet_size / 8) | ((hfc->packet_size / 8) << 4));
  1130. /* set USB_SIZE_I to match the the wMaxPacketSize for ISO transfers */
  1131. write_usb(hfc, HFCUSB_USB_SIZE_I, hfc->iso_packet_size);
  1132. /* enable PCM/GCI master mode */
  1133. write_usb(hfc, HFCUSB_MST_MODE1, 0); /* set default values */
  1134. write_usb(hfc, HFCUSB_MST_MODE0, 1); /* enable master mode */
  1135. /* init the fifos */
  1136. write_usb(hfc, HFCUSB_F_THRES,
  1137. (HFCUSB_TX_THRESHOLD /
  1138. 8) | ((HFCUSB_RX_THRESHOLD / 8) << 4));
  1139. fifo = hfc->fifos;
  1140. for (i = 0; i < HFCUSB_NUM_FIFOS; i++) {
  1141. write_usb(hfc, HFCUSB_FIFO, i); /* select the desired fifo */
  1142. fifo[i].skbuff = NULL; /* init buffer pointer */
  1143. fifo[i].max_size =
  1144. (i <= HFCUSB_B2_RX) ? MAX_BCH_SIZE : MAX_DFRAME_LEN;
  1145. fifo[i].last_urblen = 0;
  1146. /* set 2 bit for D- & E-channel */
  1147. write_usb(hfc, HFCUSB_HDLC_PAR,
  1148. ((i <= HFCUSB_B2_RX) ? 0 : 2));
  1149. /* rx hdlc, enable IFF for D-channel */
  1150. write_usb(hfc, HFCUSB_CON_HDLC,
  1151. ((i == HFCUSB_D_TX) ? 0x09 : 0x08));
  1152. write_usb(hfc, HFCUSB_INC_RES_F, 2); /* reset the fifo */
  1153. }
  1154. write_usb(hfc, HFCUSB_CLKDEL, 0x0f); /* clock delay value */
  1155. write_usb(hfc, HFCUSB_STATES, 3 | 0x10); /* set deactivated mode */
  1156. write_usb(hfc, HFCUSB_STATES, 3); /* enable state machine */
  1157. write_usb(hfc, HFCUSB_SCTRL_R, 0); /* disable both B receivers */
  1158. write_usb(hfc, HFCUSB_SCTRL, 0x40); /* disable B transmitters + capacitive mode */
  1159. /* set both B-channel to not connected */
  1160. hfc->b_mode[0] = L1_MODE_NULL;
  1161. hfc->b_mode[1] = L1_MODE_NULL;
  1162. hfc->l1_activated = FALSE;
  1163. hfc->disc_flag = FALSE;
  1164. hfc->led_state = 0;
  1165. hfc->led_new_data = 0;
  1166. hfc->old_led_state = 0;
  1167. /* init the t3 timer */
  1168. init_timer(&hfc->t3_timer);
  1169. hfc->t3_timer.data = (long) hfc;
  1170. hfc->t3_timer.function = (void *) l1_timer_expire_t3;
  1171. /* init the t4 timer */
  1172. init_timer(&hfc->t4_timer);
  1173. hfc->t4_timer.data = (long) hfc;
  1174. hfc->t4_timer.function = (void *) l1_timer_expire_t4;
  1175. /* init the background machinery for control requests */
  1176. hfc->ctrl_read.bRequestType = 0xc0;
  1177. hfc->ctrl_read.bRequest = 1;
  1178. hfc->ctrl_read.wLength = cpu_to_le16(1);
  1179. hfc->ctrl_write.bRequestType = 0x40;
  1180. hfc->ctrl_write.bRequest = 0;
  1181. hfc->ctrl_write.wLength = 0;
  1182. usb_fill_control_urb(hfc->ctrl_urb,
  1183. hfc->dev,
  1184. hfc->ctrl_out_pipe,
  1185. (u_char *) & hfc->ctrl_write,
  1186. NULL, 0, ctrl_complete, hfc);
  1187. /* Init All Fifos */
  1188. for (i = 0; i < HFCUSB_NUM_FIFOS; i++) {
  1189. hfc->fifos[i].iso[0].purb = NULL;
  1190. hfc->fifos[i].iso[1].purb = NULL;
  1191. hfc->fifos[i].active = 0;
  1192. }
  1193. /* register Modul to upper Hisax Layers */
  1194. hfc->d_if.owner = THIS_MODULE;
  1195. hfc->d_if.ifc.priv = &hfc->fifos[HFCUSB_D_TX];
  1196. hfc->d_if.ifc.l2l1 = hfc_usb_l2l1;
  1197. for (i = 0; i < 2; i++) {
  1198. hfc->b_if[i].ifc.priv = &hfc->fifos[HFCUSB_B1_TX + i * 2];
  1199. hfc->b_if[i].ifc.l2l1 = hfc_usb_l2l1;
  1200. p_b_if[i] = &hfc->b_if[i];
  1201. }
  1202. /* default Prot: EURO ISDN, should be a module_param */
  1203. hfc->protocol = 2;
  1204. hisax_register(&hfc->d_if, p_b_if, "hfc_usb", hfc->protocol);
  1205. #ifdef CONFIG_HISAX_DEBUG
  1206. hfc_debug = debug;
  1207. #endif
  1208. for (i = 0; i < 4; i++)
  1209. hfc->fifos[i].hif = &p_b_if[i / 2]->ifc;
  1210. for (i = 4; i < 8; i++)
  1211. hfc->fifos[i].hif = &hfc->d_if.ifc;
  1212. /* 3 (+1) INT IN + 3 ISO OUT */
  1213. if (hfc->cfg_used == CNF_3INT3ISO || hfc->cfg_used == CNF_4INT3ISO) {
  1214. start_int_fifo(hfc->fifos + HFCUSB_D_RX);
  1215. if (hfc->fifos[HFCUSB_PCM_RX].pipe)
  1216. start_int_fifo(hfc->fifos + HFCUSB_PCM_RX);
  1217. start_int_fifo(hfc->fifos + HFCUSB_B1_RX);
  1218. start_int_fifo(hfc->fifos + HFCUSB_B2_RX);
  1219. }
  1220. /* 3 (+1) ISO IN + 3 ISO OUT */
  1221. if (hfc->cfg_used == CNF_3ISO3ISO || hfc->cfg_used == CNF_4ISO3ISO) {
  1222. start_isoc_chain(hfc->fifos + HFCUSB_D_RX, ISOC_PACKETS_D,
  1223. rx_iso_complete, 16);
  1224. if (hfc->fifos[HFCUSB_PCM_RX].pipe)
  1225. start_isoc_chain(hfc->fifos + HFCUSB_PCM_RX,
  1226. ISOC_PACKETS_D, rx_iso_complete,
  1227. 16);
  1228. start_isoc_chain(hfc->fifos + HFCUSB_B1_RX, ISOC_PACKETS_B,
  1229. rx_iso_complete, 16);
  1230. start_isoc_chain(hfc->fifos + HFCUSB_B2_RX, ISOC_PACKETS_B,
  1231. rx_iso_complete, 16);
  1232. }
  1233. start_isoc_chain(hfc->fifos + HFCUSB_D_TX, ISOC_PACKETS_D,
  1234. tx_iso_complete, 1);
  1235. start_isoc_chain(hfc->fifos + HFCUSB_B1_TX, ISOC_PACKETS_B,
  1236. tx_iso_complete, 1);
  1237. start_isoc_chain(hfc->fifos + HFCUSB_B2_TX, ISOC_PACKETS_B,
  1238. tx_iso_complete, 1);
  1239. handle_led(hfc, LED_POWER_ON);
  1240. return (0);
  1241. } /* usb_init */
  1242. /*************************************************/
  1243. /* function called to probe a new plugged device */
  1244. /*************************************************/
  1245. static int
  1246. hfc_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
  1247. {
  1248. struct usb_device *dev = interface_to_usbdev(intf);
  1249. hfcusb_data *context;
  1250. struct usb_host_interface *iface = intf->cur_altsetting;
  1251. struct usb_host_interface *iface_used = NULL;
  1252. struct usb_host_endpoint *ep;
  1253. int ifnum = iface->desc.bInterfaceNumber;
  1254. int i, idx, alt_idx, probe_alt_setting, vend_idx, cfg_used, *vcf,
  1255. attr, cfg_found, cidx, ep_addr;
  1256. int cmptbl[16], small_match, iso_packet_size, packet_size,
  1257. alt_used = 0;
  1258. hfcsusb_vdata *driver_info;
  1259. vend_idx = 0xffff;
  1260. for (i = 0; hfcusb_idtab[i].idVendor; i++) {
  1261. if ((le16_to_cpu(dev->descriptor.idVendor) == hfcusb_idtab[i].idVendor)
  1262. && (le16_to_cpu(dev->descriptor.idProduct) == hfcusb_idtab[i].idProduct)) {
  1263. vend_idx = i;
  1264. continue;
  1265. }
  1266. }
  1267. #ifdef CONFIG_HISAX_DEBUG
  1268. DBG(USB_DBG,
  1269. "HFC-USB: probing interface(%d) actalt(%d) minor(%d)\n", ifnum,
  1270. iface->desc.bAlternateSetting, intf->minor);
  1271. #endif
  1272. printk(KERN_INFO
  1273. "HFC-S USB: probing interface(%d) actalt(%d) minor(%d)\n",
  1274. ifnum, iface->desc.bAlternateSetting, intf->minor);
  1275. if (vend_idx != 0xffff) {
  1276. /* if vendor and product ID is OK, start probing alternate settings */
  1277. alt_idx = 0;
  1278. small_match = 0xffff;
  1279. /* default settings */
  1280. iso_packet_size = 16;
  1281. packet_size = 64;
  1282. while (alt_idx < intf->num_altsetting) {
  1283. iface = intf->altsetting + alt_idx;
  1284. probe_alt_setting = iface->desc.bAlternateSetting;
  1285. cfg_used = 0;
  1286. /* check for config EOL element */
  1287. while (validconf[cfg_used][0]) {
  1288. cfg_found = TRUE;
  1289. vcf = validconf[cfg_used];
  1290. /* first endpoint descriptor */
  1291. ep = iface->endpoint;
  1292. #ifdef CONFIG_HISAX_DEBUG
  1293. DBG(USB_DBG,
  1294. "HFC-S USB: (if=%d alt=%d cfg_used=%d)\n",
  1295. ifnum, probe_alt_setting, cfg_used);
  1296. #endif
  1297. memcpy(cmptbl, vcf, 16 * sizeof(int));
  1298. /* check for all endpoints in this alternate setting */
  1299. for (i = 0; i < iface->desc.bNumEndpoints;
  1300. i++) {
  1301. ep_addr =
  1302. ep->desc.bEndpointAddress;
  1303. /* get endpoint base */
  1304. idx = ((ep_addr & 0x7f) - 1) * 2;
  1305. if (ep_addr & 0x80)
  1306. idx++;
  1307. attr = ep->desc.bmAttributes;
  1308. if (cmptbl[idx] == EP_NUL) {
  1309. cfg_found = FALSE;
  1310. }
  1311. if (attr == USB_ENDPOINT_XFER_INT
  1312. && cmptbl[idx] == EP_INT)
  1313. cmptbl[idx] = EP_NUL;
  1314. if (attr == USB_ENDPOINT_XFER_BULK
  1315. && cmptbl[idx] == EP_BLK)
  1316. cmptbl[idx] = EP_NUL;
  1317. if (attr == USB_ENDPOINT_XFER_ISOC
  1318. && cmptbl[idx] == EP_ISO)
  1319. cmptbl[idx] = EP_NUL;
  1320. /* check if all INT endpoints match minimum interval */
  1321. if (attr == USB_ENDPOINT_XFER_INT
  1322. && ep->desc.bInterval <
  1323. vcf[17]) {
  1324. #ifdef CONFIG_HISAX_DEBUG
  1325. if (cfg_found)
  1326. DBG(USB_DBG,
  1327. "HFC-S USB: Interrupt Endpoint interval < %d found - skipping config",
  1328. vcf[17]);
  1329. #endif
  1330. cfg_found = FALSE;
  1331. }
  1332. ep++;
  1333. }
  1334. for (i = 0; i < 16; i++) {
  1335. /* all entries must be EP_NOP or EP_NUL for a valid config */
  1336. if (cmptbl[i] != EP_NOP
  1337. && cmptbl[i] != EP_NUL)
  1338. cfg_found = FALSE;
  1339. }
  1340. if (cfg_found) {
  1341. if (cfg_used < small_match) {
  1342. small_match = cfg_used;
  1343. alt_used =
  1344. probe_alt_setting;
  1345. iface_used = iface;
  1346. }
  1347. #ifdef CONFIG_HISAX_DEBUG
  1348. DBG(USB_DBG,
  1349. "HFC-USB: small_match=%x %x\n",
  1350. small_match, alt_used);
  1351. #endif
  1352. }
  1353. cfg_used++;
  1354. }
  1355. alt_idx++;
  1356. } /* (alt_idx < intf->num_altsetting) */
  1357. /* found a valid USB Ta Endpint config */
  1358. if (small_match != 0xffff) {
  1359. iface = iface_used;
  1360. if (!
  1361. (context =
  1362. kmalloc(sizeof(hfcusb_data), GFP_KERNEL)))
  1363. return (-ENOMEM); /* got no mem */
  1364. memset(context, 0, sizeof(hfcusb_data));
  1365. ep = iface->endpoint;
  1366. vcf = validconf[small_match];
  1367. for (i = 0; i < iface->desc.bNumEndpoints; i++) {
  1368. ep_addr = ep->desc.bEndpointAddress;
  1369. /* get endpoint base */
  1370. idx = ((ep_addr & 0x7f) - 1) * 2;
  1371. if (ep_addr & 0x80)
  1372. idx++;
  1373. cidx = idx & 7;
  1374. attr = ep->desc.bmAttributes;
  1375. /* init Endpoints */
  1376. if (vcf[idx] != EP_NOP
  1377. && vcf[idx] != EP_NUL) {
  1378. switch (attr) {
  1379. case USB_ENDPOINT_XFER_INT:
  1380. context->
  1381. fifos[cidx].
  1382. pipe =
  1383. usb_rcvintpipe
  1384. (dev,
  1385. ep->desc.
  1386. bEndpointAddress);
  1387. context->
  1388. fifos[cidx].
  1389. usb_transfer_mode
  1390. = USB_INT;
  1391. packet_size =
  1392. le16_to_cpu(ep->desc.wMaxPacketSize);
  1393. break;
  1394. case USB_ENDPOINT_XFER_BULK:
  1395. if (ep_addr & 0x80)
  1396. context->
  1397. fifos
  1398. [cidx].
  1399. pipe =
  1400. usb_rcvbulkpipe
  1401. (dev,
  1402. ep->
  1403. desc.
  1404. bEndpointAddress);
  1405. else
  1406. context->
  1407. fifos
  1408. [cidx].
  1409. pipe =
  1410. usb_sndbulkpipe
  1411. (dev,
  1412. ep->
  1413. desc.
  1414. bEndpointAddress);
  1415. context->
  1416. fifos[cidx].
  1417. usb_transfer_mode
  1418. = USB_BULK;
  1419. packet_size =
  1420. le16_to_cpu(ep->desc.wMaxPacketSize);
  1421. break;
  1422. case USB_ENDPOINT_XFER_ISOC:
  1423. if (ep_addr & 0x80)
  1424. context->
  1425. fifos
  1426. [cidx].
  1427. pipe =
  1428. usb_rcvisocpipe
  1429. (dev,
  1430. ep->
  1431. desc.
  1432. bEndpointAddress);
  1433. else
  1434. context->
  1435. fifos
  1436. [cidx].
  1437. pipe =
  1438. usb_sndisocpipe
  1439. (dev,
  1440. ep->
  1441. desc.
  1442. bEndpointAddress);
  1443. context->
  1444. fifos[cidx].
  1445. usb_transfer_mode
  1446. = USB_ISOC;
  1447. iso_packet_size =
  1448. le16_to_cpu(ep->desc.wMaxPacketSize);
  1449. break;
  1450. default:
  1451. context->
  1452. fifos[cidx].
  1453. pipe = 0;
  1454. } /* switch attribute */
  1455. if (context->fifos[cidx].pipe) {
  1456. context->fifos[cidx].
  1457. fifonum = cidx;
  1458. context->fifos[cidx].hfc =
  1459. context;
  1460. context->fifos[cidx].usb_packet_maxlen =
  1461. le16_to_cpu(ep->desc.wMaxPacketSize);
  1462. context->fifos[cidx].
  1463. intervall =
  1464. ep->desc.bInterval;
  1465. context->fifos[cidx].
  1466. skbuff = NULL;
  1467. }
  1468. }
  1469. ep++;
  1470. }
  1471. context->dev = dev; /* save device */
  1472. context->if_used = ifnum; /* save used interface */
  1473. context->alt_used = alt_used; /* and alternate config */
  1474. context->ctrl_paksize = dev->descriptor.bMaxPacketSize0; /* control size */
  1475. context->cfg_used = vcf[16]; /* store used config */
  1476. context->vend_idx = vend_idx; /* store found vendor */
  1477. context->packet_size = packet_size;
  1478. context->iso_packet_size = iso_packet_size;
  1479. /* create the control pipes needed for register access */
  1480. context->ctrl_in_pipe =
  1481. usb_rcvctrlpipe(context->dev, 0);
  1482. context->ctrl_out_pipe =
  1483. usb_sndctrlpipe(context->dev, 0);
  1484. context->ctrl_urb = usb_alloc_urb(0, GFP_KERNEL);
  1485. driver_info =
  1486. (hfcsusb_vdata *) hfcusb_idtab[vend_idx].
  1487. driver_info;
  1488. printk(KERN_INFO "HFC-S USB: detected \"%s\"\n",
  1489. driver_info->vend_name);
  1490. #ifdef CONFIG_HISAX_DEBUG
  1491. DBG(USB_DBG,
  1492. "HFC-S USB: Endpoint-Config: %s (if=%d alt=%d)\n",
  1493. conf_str[small_match], context->if_used,
  1494. context->alt_used);
  1495. printk(KERN_INFO
  1496. "HFC-S USB: E-channel (\"ECHO:\") logging ");
  1497. if (validconf[small_match][18])
  1498. printk(" possible\n");
  1499. else
  1500. printk("NOT possible\n");
  1501. #endif
  1502. /* init the chip and register the driver */
  1503. if (usb_init(context)) {
  1504. if (context->ctrl_urb) {
  1505. usb_unlink_urb(context->ctrl_urb);
  1506. usb_free_urb(context->ctrl_urb);
  1507. context->ctrl_urb = NULL;
  1508. }
  1509. kfree(context);
  1510. return (-EIO);
  1511. }
  1512. usb_set_intfdata(intf, context);
  1513. return (0);
  1514. }
  1515. } else {
  1516. printk(KERN_INFO
  1517. "HFC-S USB: no valid vendor found in USB descriptor\n");
  1518. }
  1519. return (-EIO);
  1520. }
  1521. /****************************************************/
  1522. /* function called when an active device is removed */
  1523. /****************************************************/
  1524. static void
  1525. hfc_usb_disconnect(struct usb_interface
  1526. *intf)
  1527. {
  1528. hfcusb_data *context = usb_get_intfdata(intf);
  1529. int i;
  1530. printk(KERN_INFO "HFC-S USB: device disconnect\n");
  1531. context->disc_flag = TRUE;
  1532. usb_set_intfdata(intf, NULL);
  1533. if (!context)
  1534. return;
  1535. if (timer_pending(&context->t3_timer))
  1536. del_timer(&context->t3_timer);
  1537. if (timer_pending(&context->t4_timer))
  1538. del_timer(&context->t4_timer);
  1539. /* tell all fifos to terminate */
  1540. for (i = 0; i < HFCUSB_NUM_FIFOS; i++) {
  1541. if (context->fifos[i].usb_transfer_mode == USB_ISOC) {
  1542. if (context->fifos[i].active > 0) {
  1543. stop_isoc_chain(&context->fifos[i]);
  1544. #ifdef CONFIG_HISAX_DEBUG
  1545. DBG(USB_DBG,
  1546. "HFC-S USB: hfc_usb_disconnect: stopping ISOC chain Fifo no %i",
  1547. i);
  1548. #endif
  1549. }
  1550. } else {
  1551. if (context->fifos[i].active > 0) {
  1552. context->fifos[i].active = 0;
  1553. #ifdef CONFIG_HISAX_DEBUG
  1554. DBG(USB_DBG,
  1555. "HFC-S USB: hfc_usb_disconnect: unlinking URB for Fifo no %i",
  1556. i);
  1557. #endif
  1558. }
  1559. if (context->fifos[i].urb) {
  1560. usb_unlink_urb(context->fifos[i].urb);
  1561. usb_free_urb(context->fifos[i].urb);
  1562. context->fifos[i].urb = NULL;
  1563. }
  1564. }
  1565. context->fifos[i].active = 0;
  1566. }
  1567. /* wait for all URBS to terminate */
  1568. mdelay(10);
  1569. if (context->ctrl_urb) {
  1570. usb_unlink_urb(context->ctrl_urb);
  1571. usb_free_urb(context->ctrl_urb);
  1572. context->ctrl_urb = NULL;
  1573. }
  1574. hisax_unregister(&context->d_if);
  1575. kfree(context); /* free our structure again */
  1576. } /* hfc_usb_disconnect */
  1577. /************************************/
  1578. /* our driver information structure */
  1579. /************************************/
  1580. static struct usb_driver hfc_drv = {
  1581. .name = "hfc_usb",
  1582. .id_table = hfcusb_idtab,
  1583. .probe = hfc_usb_probe,
  1584. .disconnect = hfc_usb_disconnect,
  1585. };
  1586. static void __exit
  1587. hfc_usb_exit(void)
  1588. {
  1589. #ifdef CONFIG_HISAX_DEBUG
  1590. DBG(USB_DBG, "HFC-S USB: calling \"hfc_usb_exit\" ...");
  1591. #endif
  1592. usb_deregister(&hfc_drv); /* release our driver */
  1593. printk(KERN_INFO "HFC-S USB: module removed\n");
  1594. }
  1595. static int __init
  1596. hfc_usb_init(void)
  1597. {
  1598. #ifndef CONFIG_HISAX_DEBUG
  1599. unsigned int debug = -1;
  1600. #endif
  1601. char revstr[30], datestr[30], dummy[30];
  1602. sscanf(hfcusb_revision,
  1603. "%s %s $ %s %s %s $ ", dummy, revstr,
  1604. dummy, datestr, dummy);
  1605. printk(KERN_INFO
  1606. "HFC-S USB: driver module revision %s date %s loaded, (debug=%i)\n",
  1607. revstr, datestr, debug);
  1608. if (usb_register(&hfc_drv)) {
  1609. printk(KERN_INFO
  1610. "HFC-S USB: Unable to register HFC-S USB module at usb stack\n");
  1611. return (-1); /* unable to register */
  1612. }
  1613. return (0);
  1614. }
  1615. module_init(hfc_usb_init);
  1616. module_exit(hfc_usb_exit);
  1617. MODULE_AUTHOR(DRIVER_AUTHOR);
  1618. MODULE_DESCRIPTION(DRIVER_DESC);
  1619. MODULE_LICENSE("GPL");
  1620. MODULE_DEVICE_TABLE(usb, hfcusb_idtab);