hfc_usb.c 48 KB

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