hfc_usb.c 49 KB

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