hfc_usb.c 49 KB

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