hfc_usb.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742
  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. urb->dev = dev;
  444. urb->pipe = pipe;
  445. urb->complete = complete;
  446. urb->number_of_packets = num_packets;
  447. urb->transfer_buffer_length = packet_size * num_packets;
  448. urb->context = context;
  449. urb->transfer_buffer = buf;
  450. urb->transfer_flags = URB_ISO_ASAP;
  451. urb->actual_length = 0;
  452. urb->interval = interval;
  453. for (k = 0; k < num_packets; k++) {
  454. urb->iso_frame_desc[k].offset = packet_size * k;
  455. urb->iso_frame_desc[k].length = packet_size;
  456. urb->iso_frame_desc[k].actual_length = 0;
  457. }
  458. }
  459. /* allocs urbs and start isoc transfer with two pending urbs to avoid
  460. gaps in the transfer chain */
  461. static int
  462. start_isoc_chain(usb_fifo * fifo, int num_packets_per_urb,
  463. usb_complete_t complete, int packet_size)
  464. {
  465. int i, k, errcode;
  466. printk(KERN_INFO "HFC-S USB: starting ISO-chain for Fifo %i\n",
  467. fifo->fifonum);
  468. /* allocate Memory for Iso out Urbs */
  469. for (i = 0; i < 2; i++) {
  470. if (!(fifo->iso[i].purb)) {
  471. fifo->iso[i].purb =
  472. usb_alloc_urb(num_packets_per_urb, GFP_KERNEL);
  473. if (!(fifo->iso[i].purb)) {
  474. printk(KERN_INFO
  475. "alloc urb for fifo %i failed!!!",
  476. fifo->fifonum);
  477. }
  478. fifo->iso[i].owner_fifo = (struct usb_fifo *) fifo;
  479. /* Init the first iso */
  480. if (ISO_BUFFER_SIZE >=
  481. (fifo->usb_packet_maxlen *
  482. num_packets_per_urb)) {
  483. fill_isoc_urb(fifo->iso[i].purb,
  484. fifo->hfc->dev, fifo->pipe,
  485. fifo->iso[i].buffer,
  486. num_packets_per_urb,
  487. fifo->usb_packet_maxlen,
  488. fifo->intervall, complete,
  489. &fifo->iso[i]);
  490. memset(fifo->iso[i].buffer, 0,
  491. sizeof(fifo->iso[i].buffer));
  492. /* defining packet delimeters in fifo->buffer */
  493. for (k = 0; k < num_packets_per_urb; k++) {
  494. fifo->iso[i].purb->
  495. iso_frame_desc[k].offset =
  496. k * packet_size;
  497. fifo->iso[i].purb->
  498. iso_frame_desc[k].length =
  499. packet_size;
  500. }
  501. } else {
  502. printk(KERN_INFO
  503. "HFC-S USB: ISO Buffer size to small!\n");
  504. }
  505. }
  506. fifo->bit_line = BITLINE_INF;
  507. errcode = usb_submit_urb(fifo->iso[i].purb, GFP_KERNEL);
  508. fifo->active = (errcode >= 0) ? 1 : 0;
  509. if (errcode < 0) {
  510. printk(KERN_INFO "HFC-S USB: %s URB nr:%d\n",
  511. symbolic(urb_errlist, errcode), i);
  512. };
  513. }
  514. return (fifo->active);
  515. }
  516. /* stops running iso chain and frees their pending urbs */
  517. static void
  518. stop_isoc_chain(usb_fifo * fifo)
  519. {
  520. int i;
  521. for (i = 0; i < 2; i++) {
  522. if (fifo->iso[i].purb) {
  523. #ifdef CONFIG_HISAX_DEBUG
  524. DBG(USB_DBG,
  525. "HFC-S USB: Stopping iso chain for fifo %i.%i",
  526. fifo->fifonum, i);
  527. #endif
  528. usb_kill_urb(fifo->iso[i].purb);
  529. usb_free_urb(fifo->iso[i].purb);
  530. fifo->iso[i].purb = NULL;
  531. }
  532. }
  533. usb_kill_urb(fifo->urb);
  534. usb_free_urb(fifo->urb);
  535. fifo->urb = NULL;
  536. fifo->active = 0;
  537. }
  538. /* defines how much ISO packets are handled in one URB */
  539. static int iso_packets[8] =
  540. { ISOC_PACKETS_B, ISOC_PACKETS_B, ISOC_PACKETS_B, ISOC_PACKETS_B,
  541. ISOC_PACKETS_D, ISOC_PACKETS_D, ISOC_PACKETS_D, ISOC_PACKETS_D
  542. };
  543. /*****************************************************/
  544. /* transmit completion routine for all ISO tx fifos */
  545. /*****************************************************/
  546. static void
  547. tx_iso_complete(struct urb *urb)
  548. {
  549. iso_urb_struct *context_iso_urb = (iso_urb_struct *) urb->context;
  550. usb_fifo *fifo = context_iso_urb->owner_fifo;
  551. hfcusb_data *hfc = fifo->hfc;
  552. int k, tx_offset, num_isoc_packets, sink, len, current_len,
  553. errcode;
  554. int frame_complete, transp_mode, fifon, status;
  555. __u8 threshbit;
  556. __u8 threshtable[8] = { 1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80 };
  557. fifon = fifo->fifonum;
  558. status = urb->status;
  559. tx_offset = 0;
  560. if (fifo->active && !status) {
  561. transp_mode = 0;
  562. if (fifon < 4 && hfc->b_mode[fifon / 2] == L1_MODE_TRANS)
  563. transp_mode = true;
  564. /* is FifoFull-threshold set for our channel? */
  565. threshbit = threshtable[fifon] & hfc->threshold_mask;
  566. num_isoc_packets = iso_packets[fifon];
  567. /* predict dataflow to avoid fifo overflow */
  568. if (fifon >= HFCUSB_D_TX) {
  569. sink = (threshbit) ? SINK_DMIN : SINK_DMAX;
  570. } else {
  571. sink = (threshbit) ? SINK_MIN : SINK_MAX;
  572. }
  573. fill_isoc_urb(urb, fifo->hfc->dev, fifo->pipe,
  574. context_iso_urb->buffer, num_isoc_packets,
  575. fifo->usb_packet_maxlen, fifo->intervall,
  576. tx_iso_complete, urb->context);
  577. memset(context_iso_urb->buffer, 0,
  578. sizeof(context_iso_urb->buffer));
  579. frame_complete = false;
  580. /* Generate next Iso Packets */
  581. for (k = 0; k < num_isoc_packets; ++k) {
  582. if (fifo->skbuff) {
  583. len = fifo->skbuff->len;
  584. /* we lower data margin every msec */
  585. fifo->bit_line -= sink;
  586. current_len = (0 - fifo->bit_line) / 8;
  587. /* maximum 15 byte for every ISO packet makes our life easier */
  588. if (current_len > 14)
  589. current_len = 14;
  590. current_len =
  591. (len <=
  592. current_len) ? len : current_len;
  593. /* how much bit do we put on the line? */
  594. fifo->bit_line += current_len * 8;
  595. context_iso_urb->buffer[tx_offset] = 0;
  596. if (current_len == len) {
  597. if (!transp_mode) {
  598. /* here frame completion */
  599. context_iso_urb->
  600. buffer[tx_offset] = 1;
  601. /* add 2 byte flags and 16bit CRC at end of ISDN frame */
  602. fifo->bit_line += 32;
  603. }
  604. frame_complete = true;
  605. }
  606. memcpy(context_iso_urb->buffer +
  607. tx_offset + 1, fifo->skbuff->data,
  608. current_len);
  609. skb_pull(fifo->skbuff, current_len);
  610. /* define packet delimeters within the URB buffer */
  611. urb->iso_frame_desc[k].offset = tx_offset;
  612. urb->iso_frame_desc[k].length =
  613. current_len + 1;
  614. tx_offset += (current_len + 1);
  615. } else {
  616. urb->iso_frame_desc[k].offset =
  617. tx_offset++;
  618. urb->iso_frame_desc[k].length = 1;
  619. fifo->bit_line -= sink; /* we lower data margin every msec */
  620. if (fifo->bit_line < BITLINE_INF) {
  621. fifo->bit_line = BITLINE_INF;
  622. }
  623. }
  624. if (frame_complete) {
  625. fifo->delete_flg = true;
  626. fifo->hif->l1l2(fifo->hif,
  627. PH_DATA | CONFIRM,
  628. (void *) (unsigned long) fifo->skbuff->
  629. truesize);
  630. if (fifo->skbuff && fifo->delete_flg) {
  631. dev_kfree_skb_any(fifo->skbuff);
  632. fifo->skbuff = NULL;
  633. fifo->delete_flg = false;
  634. }
  635. frame_complete = false;
  636. }
  637. }
  638. errcode = usb_submit_urb(urb, GFP_ATOMIC);
  639. if (errcode < 0) {
  640. printk(KERN_INFO
  641. "HFC-S USB: error submitting ISO URB: %d \n",
  642. errcode);
  643. }
  644. } else {
  645. if (status && !hfc->disc_flag) {
  646. printk(KERN_INFO
  647. "HFC-S USB: tx_iso_complete : urb->status %s (%i), fifonum=%d\n",
  648. symbolic(urb_errlist, status), status,
  649. fifon);
  650. }
  651. }
  652. } /* tx_iso_complete */
  653. /*****************************************************/
  654. /* receive completion routine for all ISO tx fifos */
  655. /*****************************************************/
  656. static void
  657. rx_iso_complete(struct urb *urb)
  658. {
  659. iso_urb_struct *context_iso_urb = (iso_urb_struct *) urb->context;
  660. usb_fifo *fifo = context_iso_urb->owner_fifo;
  661. hfcusb_data *hfc = fifo->hfc;
  662. int k, len, errcode, offset, num_isoc_packets, fifon, maxlen,
  663. status;
  664. unsigned int iso_status;
  665. __u8 *buf;
  666. static __u8 eof[8];
  667. #ifdef CONFIG_HISAX_DEBUG
  668. __u8 i;
  669. #endif
  670. fifon = fifo->fifonum;
  671. status = urb->status;
  672. if (urb->status == -EOVERFLOW) {
  673. #ifdef CONFIG_HISAX_DEBUG
  674. DBG(USB_DBG,
  675. "HFC-USB: ignoring USB DATAOVERRUN for fifo %i \n",
  676. fifon);
  677. #endif
  678. status = 0;
  679. }
  680. if (fifo->active && !status) {
  681. num_isoc_packets = iso_packets[fifon];
  682. maxlen = fifo->usb_packet_maxlen;
  683. for (k = 0; k < num_isoc_packets; ++k) {
  684. len = urb->iso_frame_desc[k].actual_length;
  685. offset = urb->iso_frame_desc[k].offset;
  686. buf = context_iso_urb->buffer + offset;
  687. iso_status = urb->iso_frame_desc[k].status;
  688. #ifdef CONFIG_HISAX_DEBUG
  689. if (iso_status && !hfc->disc_flag)
  690. DBG(USB_DBG,
  691. "HFC-S USB: ISO packet failure - status:%x",
  692. iso_status);
  693. if ((fifon == 5) && (debug > 1)) {
  694. printk(KERN_INFO
  695. "HFC-S USB: ISO-D-RX lst_urblen:%2d "
  696. "act_urblen:%2d max-urblen:%2d "
  697. "EOF:0x%0x DATA: ",
  698. fifo->last_urblen, len, maxlen,
  699. eof[5]);
  700. for (i = 0; i < len; i++)
  701. printk("%.2x ", buf[i]);
  702. printk("\n");
  703. }
  704. #endif
  705. if (fifo->last_urblen != maxlen) {
  706. /* the threshold mask is in the 2nd status byte */
  707. hfc->threshold_mask = buf[1];
  708. /* care for L1 state only for D-Channel
  709. to avoid overlapped iso completions */
  710. if (fifon == 5) {
  711. /* the S0 state is in the upper half
  712. of the 1st status byte */
  713. state_handler(hfc, buf[0] >> 4);
  714. }
  715. eof[fifon] = buf[0] & 1;
  716. if (len > 2)
  717. collect_rx_frame(fifo, buf + 2,
  718. len - 2,
  719. (len <
  720. maxlen) ?
  721. eof[fifon] : 0);
  722. } else {
  723. collect_rx_frame(fifo, buf, len,
  724. (len <
  725. maxlen) ? eof[fifon] :
  726. 0);
  727. }
  728. fifo->last_urblen = len;
  729. }
  730. fill_isoc_urb(urb, fifo->hfc->dev, fifo->pipe,
  731. context_iso_urb->buffer, num_isoc_packets,
  732. fifo->usb_packet_maxlen, fifo->intervall,
  733. rx_iso_complete, urb->context);
  734. errcode = usb_submit_urb(urb, GFP_ATOMIC);
  735. if (errcode < 0) {
  736. printk(KERN_INFO
  737. "HFC-S USB: error submitting ISO URB: %d \n",
  738. errcode);
  739. }
  740. } else {
  741. if (status && !hfc->disc_flag) {
  742. printk(KERN_INFO
  743. "HFC-S USB: rx_iso_complete : "
  744. "urb->status %d, fifonum %d\n",
  745. status, fifon);
  746. }
  747. }
  748. } /* rx_iso_complete */
  749. /*****************************************************/
  750. /* collect data from interrupt or isochron in */
  751. /*****************************************************/
  752. static void
  753. collect_rx_frame(usb_fifo * fifo, __u8 * data, int len, int finish)
  754. {
  755. hfcusb_data *hfc = fifo->hfc;
  756. int transp_mode, fifon;
  757. #ifdef CONFIG_HISAX_DEBUG
  758. int i;
  759. #endif
  760. fifon = fifo->fifonum;
  761. transp_mode = 0;
  762. if (fifon < 4 && hfc->b_mode[fifon / 2] == L1_MODE_TRANS)
  763. transp_mode = true;
  764. if (!fifo->skbuff) {
  765. fifo->skbuff = dev_alloc_skb(fifo->max_size + 3);
  766. if (!fifo->skbuff) {
  767. printk(KERN_INFO
  768. "HFC-S USB: cannot allocate buffer (dev_alloc_skb) fifo:%d\n",
  769. fifon);
  770. return;
  771. }
  772. }
  773. if (len) {
  774. if (fifo->skbuff->len + len < fifo->max_size) {
  775. memcpy(skb_put(fifo->skbuff, len), data, len);
  776. } else {
  777. #ifdef CONFIG_HISAX_DEBUG
  778. printk(KERN_INFO "HFC-S USB: ");
  779. for (i = 0; i < 15; i++)
  780. printk("%.2x ",
  781. fifo->skbuff->data[fifo->skbuff->
  782. len - 15 + i]);
  783. printk("\n");
  784. #endif
  785. printk(KERN_INFO
  786. "HCF-USB: got frame exceeded fifo->max_size:%d on fifo:%d\n",
  787. fifo->max_size, fifon);
  788. }
  789. }
  790. if (transp_mode && fifo->skbuff->len >= 128) {
  791. fifo->hif->l1l2(fifo->hif, PH_DATA | INDICATION,
  792. fifo->skbuff);
  793. fifo->skbuff = NULL;
  794. return;
  795. }
  796. /* we have a complete hdlc packet */
  797. if (finish) {
  798. if ((!fifo->skbuff->data[fifo->skbuff->len - 1])
  799. && (fifo->skbuff->len > 3)) {
  800. /* remove CRC & status */
  801. skb_trim(fifo->skbuff, fifo->skbuff->len - 3);
  802. if (fifon == HFCUSB_PCM_RX) {
  803. fifo->hif->l1l2(fifo->hif,
  804. PH_DATA_E | INDICATION,
  805. fifo->skbuff);
  806. } else
  807. fifo->hif->l1l2(fifo->hif,
  808. PH_DATA | INDICATION,
  809. fifo->skbuff);
  810. fifo->skbuff = NULL; /* buffer was freed from upper layer */
  811. } else {
  812. if (fifo->skbuff->len > 3) {
  813. printk(KERN_INFO
  814. "HFC-S USB: got frame %d bytes but CRC ERROR on fifo:%d!!!\n",
  815. fifo->skbuff->len, fifon);
  816. #ifdef CONFIG_HISAX_DEBUG
  817. if (debug > 1) {
  818. printk(KERN_INFO "HFC-S USB: ");
  819. for (i = 0; i < 15; i++)
  820. printk("%.2x ",
  821. fifo->skbuff->
  822. data[fifo->skbuff->
  823. len - 15 + i]);
  824. printk("\n");
  825. }
  826. #endif
  827. }
  828. #ifdef CONFIG_HISAX_DEBUG
  829. else {
  830. printk(KERN_INFO
  831. "HFC-S USB: frame to small (%d bytes)!!!\n",
  832. fifo->skbuff->len);
  833. }
  834. #endif
  835. skb_trim(fifo->skbuff, 0);
  836. }
  837. }
  838. }
  839. /***********************************************/
  840. /* receive completion routine for all rx fifos */
  841. /***********************************************/
  842. static void
  843. rx_complete(struct urb *urb)
  844. {
  845. int len;
  846. int status;
  847. __u8 *buf, maxlen, fifon;
  848. usb_fifo *fifo = (usb_fifo *) urb->context;
  849. hfcusb_data *hfc = fifo->hfc;
  850. static __u8 eof[8];
  851. #ifdef CONFIG_HISAX_DEBUG
  852. __u8 i;
  853. #endif
  854. urb->dev = hfc->dev; /* security init */
  855. fifon = fifo->fifonum;
  856. if ((!fifo->active) || (urb->status)) {
  857. #ifdef CONFIG_HISAX_DEBUG
  858. DBG(USB_DBG, "HFC-S USB: RX-Fifo %i is going down (%i)",
  859. fifon, urb->status);
  860. #endif
  861. fifo->urb->interval = 0; /* cancel automatic rescheduling */
  862. if (fifo->skbuff) {
  863. dev_kfree_skb_any(fifo->skbuff);
  864. fifo->skbuff = NULL;
  865. }
  866. return;
  867. }
  868. len = urb->actual_length;
  869. buf = fifo->buffer;
  870. maxlen = fifo->usb_packet_maxlen;
  871. #ifdef CONFIG_HISAX_DEBUG
  872. if ((fifon == 5) && (debug > 1)) {
  873. printk(KERN_INFO
  874. "HFC-S USB: INT-D-RX lst_urblen:%2d act_urblen:%2d max-urblen:%2d EOF:0x%0x DATA: ",
  875. fifo->last_urblen, len, maxlen, eof[5]);
  876. for (i = 0; i < len; i++)
  877. printk("%.2x ", buf[i]);
  878. printk("\n");
  879. }
  880. #endif
  881. if (fifo->last_urblen != fifo->usb_packet_maxlen) {
  882. /* the threshold mask is in the 2nd status byte */
  883. hfc->threshold_mask = buf[1];
  884. /* the S0 state is in the upper half of the 1st status byte */
  885. state_handler(hfc, buf[0] >> 4);
  886. eof[fifon] = buf[0] & 1;
  887. /* if we have more than the 2 status bytes -> collect data */
  888. if (len > 2)
  889. collect_rx_frame(fifo, buf + 2,
  890. urb->actual_length - 2,
  891. (len < maxlen) ? eof[fifon] : 0);
  892. } else {
  893. collect_rx_frame(fifo, buf, urb->actual_length,
  894. (len < maxlen) ? eof[fifon] : 0);
  895. }
  896. fifo->last_urblen = urb->actual_length;
  897. status = usb_submit_urb(urb, GFP_ATOMIC);
  898. if (status) {
  899. printk(KERN_INFO
  900. "HFC-S USB: error resubmitting URN at rx_complete...\n");
  901. }
  902. } /* rx_complete */
  903. /***************************************************/
  904. /* start the interrupt transfer for the given fifo */
  905. /***************************************************/
  906. static void
  907. start_int_fifo(usb_fifo * fifo)
  908. {
  909. int errcode;
  910. printk(KERN_INFO "HFC-S USB: starting intr IN fifo:%d\n",
  911. fifo->fifonum);
  912. if (!fifo->urb) {
  913. fifo->urb = usb_alloc_urb(0, GFP_KERNEL);
  914. if (!fifo->urb)
  915. return;
  916. }
  917. usb_fill_int_urb(fifo->urb, fifo->hfc->dev, fifo->pipe,
  918. fifo->buffer, fifo->usb_packet_maxlen,
  919. rx_complete, fifo, fifo->intervall);
  920. fifo->active = 1; /* must be marked active */
  921. errcode = usb_submit_urb(fifo->urb, GFP_KERNEL);
  922. if (errcode) {
  923. printk(KERN_INFO
  924. "HFC-S USB: submit URB error(start_int_info): status:%i\n",
  925. errcode);
  926. fifo->active = 0;
  927. fifo->skbuff = NULL;
  928. }
  929. } /* start_int_fifo */
  930. /*****************************/
  931. /* set the B-channel mode */
  932. /*****************************/
  933. static void
  934. set_hfcmode(hfcusb_data * hfc, int channel, int mode)
  935. {
  936. __u8 val, idx_table[2] = { 0, 2 };
  937. if (hfc->disc_flag) {
  938. return;
  939. }
  940. #ifdef CONFIG_HISAX_DEBUG
  941. DBG(ISDN_DBG, "HFC-S USB: setting channel %d to mode %d", channel,
  942. mode);
  943. #endif
  944. hfc->b_mode[channel] = mode;
  945. /* setup CON_HDLC */
  946. val = 0;
  947. if (mode != L1_MODE_NULL)
  948. val = 8; /* enable fifo? */
  949. if (mode == L1_MODE_TRANS)
  950. val |= 2; /* set transparent bit */
  951. /* set FIFO to transmit register */
  952. queue_control_request(hfc, HFCUSB_FIFO, idx_table[channel], 1);
  953. queue_control_request(hfc, HFCUSB_CON_HDLC, val, 1);
  954. /* reset fifo */
  955. queue_control_request(hfc, HFCUSB_INC_RES_F, 2, 1);
  956. /* set FIFO to receive register */
  957. queue_control_request(hfc, HFCUSB_FIFO, idx_table[channel] + 1, 1);
  958. queue_control_request(hfc, HFCUSB_CON_HDLC, val, 1);
  959. /* reset fifo */
  960. queue_control_request(hfc, HFCUSB_INC_RES_F, 2, 1);
  961. val = 0x40;
  962. if (hfc->b_mode[0])
  963. val |= 1;
  964. if (hfc->b_mode[1])
  965. val |= 2;
  966. queue_control_request(hfc, HFCUSB_SCTRL, val, 1);
  967. val = 0;
  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_R, val, 1);
  973. if (mode == L1_MODE_NULL) {
  974. if (channel)
  975. handle_led(hfc, LED_B2_OFF);
  976. else
  977. handle_led(hfc, LED_B1_OFF);
  978. } else {
  979. if (channel)
  980. handle_led(hfc, LED_B2_ON);
  981. else
  982. handle_led(hfc, LED_B1_ON);
  983. }
  984. }
  985. static void
  986. hfc_usb_l2l1(struct hisax_if *my_hisax_if, int pr, void *arg)
  987. {
  988. usb_fifo *fifo = my_hisax_if->priv;
  989. hfcusb_data *hfc = fifo->hfc;
  990. switch (pr) {
  991. case PH_ACTIVATE | REQUEST:
  992. if (fifo->fifonum == HFCUSB_D_TX) {
  993. #ifdef CONFIG_HISAX_DEBUG
  994. DBG(ISDN_DBG,
  995. "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_ACTIVATE | REQUEST");
  996. #endif
  997. if (hfc->l1_state != 3
  998. && hfc->l1_state != 7) {
  999. hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,
  1000. PH_DEACTIVATE |
  1001. INDICATION,
  1002. NULL);
  1003. #ifdef CONFIG_HISAX_DEBUG
  1004. DBG(ISDN_DBG,
  1005. "HFC-S USB: PH_DEACTIVATE | INDICATION sent (not state 3 or 7)");
  1006. #endif
  1007. } else {
  1008. if (hfc->l1_state == 7) { /* l1 already active */
  1009. hfc->d_if.ifc.l1l2(&hfc->
  1010. d_if.
  1011. ifc,
  1012. PH_ACTIVATE
  1013. |
  1014. INDICATION,
  1015. NULL);
  1016. #ifdef CONFIG_HISAX_DEBUG
  1017. DBG(ISDN_DBG,
  1018. "HFC-S USB: PH_ACTIVATE | INDICATION sent again ;)");
  1019. #endif
  1020. } else {
  1021. /* force sending sending INFO1 */
  1022. queue_control_request(hfc,
  1023. HFCUSB_STATES,
  1024. 0x14,
  1025. 1);
  1026. mdelay(1);
  1027. /* start l1 activation */
  1028. queue_control_request(hfc,
  1029. HFCUSB_STATES,
  1030. 0x04,
  1031. 1);
  1032. if (!timer_pending
  1033. (&hfc->t3_timer)) {
  1034. hfc->t3_timer.
  1035. expires =
  1036. jiffies +
  1037. (HFC_TIMER_T3 *
  1038. HZ) / 1000;
  1039. add_timer(&hfc->
  1040. t3_timer);
  1041. }
  1042. }
  1043. }
  1044. } else {
  1045. #ifdef CONFIG_HISAX_DEBUG
  1046. DBG(ISDN_DBG,
  1047. "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_ACTIVATE | REQUEST");
  1048. #endif
  1049. set_hfcmode(hfc,
  1050. (fifo->fifonum ==
  1051. HFCUSB_B1_TX) ? 0 : 1,
  1052. (long) arg);
  1053. fifo->hif->l1l2(fifo->hif,
  1054. PH_ACTIVATE | INDICATION,
  1055. NULL);
  1056. }
  1057. break;
  1058. case PH_DEACTIVATE | REQUEST:
  1059. if (fifo->fifonum == HFCUSB_D_TX) {
  1060. #ifdef CONFIG_HISAX_DEBUG
  1061. DBG(ISDN_DBG,
  1062. "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_DEACTIVATE | REQUEST");
  1063. #endif
  1064. printk(KERN_INFO
  1065. "HFC-S USB: ISDN TE device should not deativate...\n");
  1066. } else {
  1067. #ifdef CONFIG_HISAX_DEBUG
  1068. DBG(ISDN_DBG,
  1069. "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_DEACTIVATE | REQUEST");
  1070. #endif
  1071. set_hfcmode(hfc,
  1072. (fifo->fifonum ==
  1073. HFCUSB_B1_TX) ? 0 : 1,
  1074. (int) L1_MODE_NULL);
  1075. fifo->hif->l1l2(fifo->hif,
  1076. PH_DEACTIVATE | INDICATION,
  1077. NULL);
  1078. }
  1079. break;
  1080. case PH_DATA | REQUEST:
  1081. if (fifo->skbuff && fifo->delete_flg) {
  1082. dev_kfree_skb_any(fifo->skbuff);
  1083. fifo->skbuff = NULL;
  1084. fifo->delete_flg = false;
  1085. }
  1086. fifo->skbuff = arg; /* we have a new buffer */
  1087. break;
  1088. default:
  1089. printk(KERN_INFO
  1090. "HFC_USB: hfc_usb_d_l2l1: unkown state : %#x\n",
  1091. pr);
  1092. break;
  1093. }
  1094. }
  1095. /***************************************************************************/
  1096. /* usb_init is called once when a new matching device is detected to setup */
  1097. /* main parameters. It registers the driver at the main hisax module. */
  1098. /* on success 0 is returned. */
  1099. /***************************************************************************/
  1100. static int
  1101. usb_init(hfcusb_data * hfc)
  1102. {
  1103. usb_fifo *fifo;
  1104. int i, err;
  1105. u_char b;
  1106. struct hisax_b_if *p_b_if[2];
  1107. /* check the chip id */
  1108. if (read_usb(hfc, HFCUSB_CHIP_ID, &b) != 1) {
  1109. printk(KERN_INFO "HFC-USB: cannot read chip id\n");
  1110. return (1);
  1111. }
  1112. if (b != HFCUSB_CHIPID) {
  1113. printk(KERN_INFO "HFC-S USB: Invalid chip id 0x%02x\n", b);
  1114. return (1);
  1115. }
  1116. /* first set the needed config, interface and alternate */
  1117. err = usb_set_interface(hfc->dev, hfc->if_used, hfc->alt_used);
  1118. /* do Chip reset */
  1119. write_usb(hfc, HFCUSB_CIRM, 8);
  1120. /* aux = output, reset off */
  1121. write_usb(hfc, HFCUSB_CIRM, 0x10);
  1122. /* set USB_SIZE to match the wMaxPacketSize for INT or BULK transfers */
  1123. write_usb(hfc, HFCUSB_USB_SIZE,
  1124. (hfc->packet_size / 8) | ((hfc->packet_size / 8) << 4));
  1125. /* set USB_SIZE_I to match the wMaxPacketSize for ISO transfers */
  1126. write_usb(hfc, HFCUSB_USB_SIZE_I, hfc->iso_packet_size);
  1127. /* enable PCM/GCI master mode */
  1128. write_usb(hfc, HFCUSB_MST_MODE1, 0); /* set default values */
  1129. write_usb(hfc, HFCUSB_MST_MODE0, 1); /* enable master mode */
  1130. /* init the fifos */
  1131. write_usb(hfc, HFCUSB_F_THRES,
  1132. (HFCUSB_TX_THRESHOLD /
  1133. 8) | ((HFCUSB_RX_THRESHOLD / 8) << 4));
  1134. fifo = hfc->fifos;
  1135. for (i = 0; i < HFCUSB_NUM_FIFOS; i++) {
  1136. write_usb(hfc, HFCUSB_FIFO, i); /* select the desired fifo */
  1137. fifo[i].skbuff = NULL; /* init buffer pointer */
  1138. fifo[i].max_size =
  1139. (i <= HFCUSB_B2_RX) ? MAX_BCH_SIZE : MAX_DFRAME_LEN;
  1140. fifo[i].last_urblen = 0;
  1141. /* set 2 bit for D- & E-channel */
  1142. write_usb(hfc, HFCUSB_HDLC_PAR,
  1143. ((i <= HFCUSB_B2_RX) ? 0 : 2));
  1144. /* rx hdlc, enable IFF for D-channel */
  1145. write_usb(hfc, HFCUSB_CON_HDLC,
  1146. ((i == HFCUSB_D_TX) ? 0x09 : 0x08));
  1147. write_usb(hfc, HFCUSB_INC_RES_F, 2); /* reset the fifo */
  1148. }
  1149. write_usb(hfc, HFCUSB_CLKDEL, 0x0f); /* clock delay value */
  1150. write_usb(hfc, HFCUSB_STATES, 3 | 0x10); /* set deactivated mode */
  1151. write_usb(hfc, HFCUSB_STATES, 3); /* enable state machine */
  1152. write_usb(hfc, HFCUSB_SCTRL_R, 0); /* disable both B receivers */
  1153. write_usb(hfc, HFCUSB_SCTRL, 0x40); /* disable B transmitters + capacitive mode */
  1154. /* set both B-channel to not connected */
  1155. hfc->b_mode[0] = L1_MODE_NULL;
  1156. hfc->b_mode[1] = L1_MODE_NULL;
  1157. hfc->l1_activated = false;
  1158. hfc->disc_flag = false;
  1159. hfc->led_state = 0;
  1160. hfc->led_new_data = 0;
  1161. hfc->old_led_state = 0;
  1162. /* init the t3 timer */
  1163. init_timer(&hfc->t3_timer);
  1164. hfc->t3_timer.data = (long) hfc;
  1165. hfc->t3_timer.function = (void *) l1_timer_expire_t3;
  1166. /* init the t4 timer */
  1167. init_timer(&hfc->t4_timer);
  1168. hfc->t4_timer.data = (long) hfc;
  1169. hfc->t4_timer.function = (void *) l1_timer_expire_t4;
  1170. /* init the background machinery for control requests */
  1171. hfc->ctrl_read.bRequestType = 0xc0;
  1172. hfc->ctrl_read.bRequest = 1;
  1173. hfc->ctrl_read.wLength = cpu_to_le16(1);
  1174. hfc->ctrl_write.bRequestType = 0x40;
  1175. hfc->ctrl_write.bRequest = 0;
  1176. hfc->ctrl_write.wLength = 0;
  1177. usb_fill_control_urb(hfc->ctrl_urb,
  1178. hfc->dev,
  1179. hfc->ctrl_out_pipe,
  1180. (u_char *) & hfc->ctrl_write,
  1181. NULL, 0, ctrl_complete, hfc);
  1182. /* Init All Fifos */
  1183. for (i = 0; i < HFCUSB_NUM_FIFOS; i++) {
  1184. hfc->fifos[i].iso[0].purb = NULL;
  1185. hfc->fifos[i].iso[1].purb = NULL;
  1186. hfc->fifos[i].active = 0;
  1187. }
  1188. /* register Modul to upper Hisax Layers */
  1189. hfc->d_if.owner = THIS_MODULE;
  1190. hfc->d_if.ifc.priv = &hfc->fifos[HFCUSB_D_TX];
  1191. hfc->d_if.ifc.l2l1 = hfc_usb_l2l1;
  1192. for (i = 0; i < 2; i++) {
  1193. hfc->b_if[i].ifc.priv = &hfc->fifos[HFCUSB_B1_TX + i * 2];
  1194. hfc->b_if[i].ifc.l2l1 = hfc_usb_l2l1;
  1195. p_b_if[i] = &hfc->b_if[i];
  1196. }
  1197. /* default Prot: EURO ISDN, should be a module_param */
  1198. hfc->protocol = 2;
  1199. i = hisax_register(&hfc->d_if, p_b_if, "hfc_usb", hfc->protocol);
  1200. if (i) {
  1201. printk(KERN_INFO "HFC-S USB: hisax_register -> %d\n", i);
  1202. return i;
  1203. }
  1204. #ifdef CONFIG_HISAX_DEBUG
  1205. hfc_debug = debug;
  1206. #endif
  1207. for (i = 0; i < 4; i++)
  1208. hfc->fifos[i].hif = &p_b_if[i / 2]->ifc;
  1209. for (i = 4; i < 8; i++)
  1210. hfc->fifos[i].hif = &hfc->d_if.ifc;
  1211. /* 3 (+1) INT IN + 3 ISO OUT */
  1212. if (hfc->cfg_used == CNF_3INT3ISO || hfc->cfg_used == CNF_4INT3ISO) {
  1213. start_int_fifo(hfc->fifos + HFCUSB_D_RX);
  1214. if (hfc->fifos[HFCUSB_PCM_RX].pipe)
  1215. start_int_fifo(hfc->fifos + HFCUSB_PCM_RX);
  1216. start_int_fifo(hfc->fifos + HFCUSB_B1_RX);
  1217. start_int_fifo(hfc->fifos + HFCUSB_B2_RX);
  1218. }
  1219. /* 3 (+1) ISO IN + 3 ISO OUT */
  1220. if (hfc->cfg_used == CNF_3ISO3ISO || hfc->cfg_used == CNF_4ISO3ISO) {
  1221. start_isoc_chain(hfc->fifos + HFCUSB_D_RX, ISOC_PACKETS_D,
  1222. rx_iso_complete, 16);
  1223. if (hfc->fifos[HFCUSB_PCM_RX].pipe)
  1224. start_isoc_chain(hfc->fifos + HFCUSB_PCM_RX,
  1225. ISOC_PACKETS_D, rx_iso_complete,
  1226. 16);
  1227. start_isoc_chain(hfc->fifos + HFCUSB_B1_RX, ISOC_PACKETS_B,
  1228. rx_iso_complete, 16);
  1229. start_isoc_chain(hfc->fifos + HFCUSB_B2_RX, ISOC_PACKETS_B,
  1230. rx_iso_complete, 16);
  1231. }
  1232. start_isoc_chain(hfc->fifos + HFCUSB_D_TX, ISOC_PACKETS_D,
  1233. tx_iso_complete, 1);
  1234. start_isoc_chain(hfc->fifos + HFCUSB_B1_TX, ISOC_PACKETS_B,
  1235. tx_iso_complete, 1);
  1236. start_isoc_chain(hfc->fifos + HFCUSB_B2_TX, ISOC_PACKETS_B,
  1237. tx_iso_complete, 1);
  1238. handle_led(hfc, LED_POWER_ON);
  1239. return (0);
  1240. } /* usb_init */
  1241. /*************************************************/
  1242. /* function called to probe a new plugged device */
  1243. /*************************************************/
  1244. static int
  1245. hfc_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
  1246. {
  1247. struct usb_device *dev = interface_to_usbdev(intf);
  1248. hfcusb_data *context;
  1249. struct usb_host_interface *iface = intf->cur_altsetting;
  1250. struct usb_host_interface *iface_used = NULL;
  1251. struct usb_host_endpoint *ep;
  1252. int ifnum = iface->desc.bInterfaceNumber;
  1253. int i, idx, alt_idx, probe_alt_setting, vend_idx, cfg_used, *vcf,
  1254. attr, cfg_found, cidx, ep_addr;
  1255. int cmptbl[16], small_match, iso_packet_size, packet_size,
  1256. alt_used = 0;
  1257. hfcsusb_vdata *driver_info;
  1258. vend_idx = 0xffff;
  1259. for (i = 0; hfcusb_idtab[i].idVendor; i++) {
  1260. if ((le16_to_cpu(dev->descriptor.idVendor) == hfcusb_idtab[i].idVendor)
  1261. && (le16_to_cpu(dev->descriptor.idProduct) == hfcusb_idtab[i].idProduct)) {
  1262. vend_idx = i;
  1263. continue;
  1264. }
  1265. }
  1266. #ifdef CONFIG_HISAX_DEBUG
  1267. DBG(USB_DBG,
  1268. "HFC-USB: probing interface(%d) actalt(%d) minor(%d)\n", ifnum,
  1269. iface->desc.bAlternateSetting, intf->minor);
  1270. #endif
  1271. printk(KERN_INFO
  1272. "HFC-S USB: probing interface(%d) actalt(%d) minor(%d)\n",
  1273. ifnum, iface->desc.bAlternateSetting, intf->minor);
  1274. if (vend_idx != 0xffff) {
  1275. /* if vendor and product ID is OK, start probing alternate settings */
  1276. alt_idx = 0;
  1277. small_match = 0xffff;
  1278. /* default settings */
  1279. iso_packet_size = 16;
  1280. packet_size = 64;
  1281. while (alt_idx < intf->num_altsetting) {
  1282. iface = intf->altsetting + alt_idx;
  1283. probe_alt_setting = iface->desc.bAlternateSetting;
  1284. cfg_used = 0;
  1285. /* check for config EOL element */
  1286. while (validconf[cfg_used][0]) {
  1287. cfg_found = true;
  1288. vcf = validconf[cfg_used];
  1289. /* first endpoint descriptor */
  1290. ep = iface->endpoint;
  1291. #ifdef CONFIG_HISAX_DEBUG
  1292. DBG(USB_DBG,
  1293. "HFC-S USB: (if=%d alt=%d cfg_used=%d)\n",
  1294. ifnum, probe_alt_setting, cfg_used);
  1295. #endif
  1296. memcpy(cmptbl, vcf, 16 * sizeof(int));
  1297. /* check for all endpoints in this alternate setting */
  1298. for (i = 0; i < iface->desc.bNumEndpoints;
  1299. i++) {
  1300. ep_addr =
  1301. ep->desc.bEndpointAddress;
  1302. /* get endpoint base */
  1303. idx = ((ep_addr & 0x7f) - 1) * 2;
  1304. if (ep_addr & 0x80)
  1305. idx++;
  1306. attr = ep->desc.bmAttributes;
  1307. if (cmptbl[idx] == EP_NUL) {
  1308. cfg_found = false;
  1309. }
  1310. if (attr == USB_ENDPOINT_XFER_INT
  1311. && cmptbl[idx] == EP_INT)
  1312. cmptbl[idx] = EP_NUL;
  1313. if (attr == USB_ENDPOINT_XFER_BULK
  1314. && cmptbl[idx] == EP_BLK)
  1315. cmptbl[idx] = EP_NUL;
  1316. if (attr == USB_ENDPOINT_XFER_ISOC
  1317. && cmptbl[idx] == EP_ISO)
  1318. cmptbl[idx] = EP_NUL;
  1319. /* check if all INT endpoints match minimum interval */
  1320. if (attr == USB_ENDPOINT_XFER_INT
  1321. && ep->desc.bInterval <
  1322. vcf[17]) {
  1323. #ifdef CONFIG_HISAX_DEBUG
  1324. if (cfg_found)
  1325. DBG(USB_DBG,
  1326. "HFC-S USB: Interrupt Endpoint interval < %d found - skipping config",
  1327. vcf[17]);
  1328. #endif
  1329. cfg_found = false;
  1330. }
  1331. ep++;
  1332. }
  1333. for (i = 0; i < 16; i++) {
  1334. /* all entries must be EP_NOP or EP_NUL for a valid config */
  1335. if (cmptbl[i] != EP_NOP
  1336. && cmptbl[i] != EP_NUL)
  1337. cfg_found = false;
  1338. }
  1339. if (cfg_found) {
  1340. if (cfg_used < small_match) {
  1341. small_match = cfg_used;
  1342. alt_used =
  1343. probe_alt_setting;
  1344. iface_used = iface;
  1345. }
  1346. #ifdef CONFIG_HISAX_DEBUG
  1347. DBG(USB_DBG,
  1348. "HFC-USB: small_match=%x %x\n",
  1349. small_match, alt_used);
  1350. #endif
  1351. }
  1352. cfg_used++;
  1353. }
  1354. alt_idx++;
  1355. } /* (alt_idx < intf->num_altsetting) */
  1356. /* found a valid USB Ta Endpint config */
  1357. if (small_match != 0xffff) {
  1358. iface = iface_used;
  1359. if (!
  1360. (context =
  1361. kzalloc(sizeof(hfcusb_data), GFP_KERNEL)))
  1362. return (-ENOMEM); /* got no mem */
  1363. ep = iface->endpoint;
  1364. vcf = validconf[small_match];
  1365. for (i = 0; i < iface->desc.bNumEndpoints; i++) {
  1366. ep_addr = ep->desc.bEndpointAddress;
  1367. /* get endpoint base */
  1368. idx = ((ep_addr & 0x7f) - 1) * 2;
  1369. if (ep_addr & 0x80)
  1370. idx++;
  1371. cidx = idx & 7;
  1372. attr = ep->desc.bmAttributes;
  1373. /* init Endpoints */
  1374. if (vcf[idx] != EP_NOP
  1375. && vcf[idx] != EP_NUL) {
  1376. switch (attr) {
  1377. case USB_ENDPOINT_XFER_INT:
  1378. context->
  1379. fifos[cidx].
  1380. pipe =
  1381. usb_rcvintpipe
  1382. (dev,
  1383. ep->desc.
  1384. bEndpointAddress);
  1385. context->
  1386. fifos[cidx].
  1387. usb_transfer_mode
  1388. = USB_INT;
  1389. packet_size =
  1390. le16_to_cpu(ep->desc.wMaxPacketSize);
  1391. break;
  1392. case USB_ENDPOINT_XFER_BULK:
  1393. if (ep_addr & 0x80)
  1394. context->
  1395. fifos
  1396. [cidx].
  1397. pipe =
  1398. usb_rcvbulkpipe
  1399. (dev,
  1400. ep->
  1401. desc.
  1402. bEndpointAddress);
  1403. else
  1404. context->
  1405. fifos
  1406. [cidx].
  1407. pipe =
  1408. usb_sndbulkpipe
  1409. (dev,
  1410. ep->
  1411. desc.
  1412. bEndpointAddress);
  1413. context->
  1414. fifos[cidx].
  1415. usb_transfer_mode
  1416. = USB_BULK;
  1417. packet_size =
  1418. le16_to_cpu(ep->desc.wMaxPacketSize);
  1419. break;
  1420. case USB_ENDPOINT_XFER_ISOC:
  1421. if (ep_addr & 0x80)
  1422. context->
  1423. fifos
  1424. [cidx].
  1425. pipe =
  1426. usb_rcvisocpipe
  1427. (dev,
  1428. ep->
  1429. desc.
  1430. bEndpointAddress);
  1431. else
  1432. context->
  1433. fifos
  1434. [cidx].
  1435. pipe =
  1436. usb_sndisocpipe
  1437. (dev,
  1438. ep->
  1439. desc.
  1440. bEndpointAddress);
  1441. context->
  1442. fifos[cidx].
  1443. usb_transfer_mode
  1444. = USB_ISOC;
  1445. iso_packet_size =
  1446. le16_to_cpu(ep->desc.wMaxPacketSize);
  1447. break;
  1448. default:
  1449. context->
  1450. fifos[cidx].
  1451. pipe = 0;
  1452. } /* switch attribute */
  1453. if (context->fifos[cidx].pipe) {
  1454. context->fifos[cidx].
  1455. fifonum = cidx;
  1456. context->fifos[cidx].hfc =
  1457. context;
  1458. context->fifos[cidx].usb_packet_maxlen =
  1459. le16_to_cpu(ep->desc.wMaxPacketSize);
  1460. context->fifos[cidx].
  1461. intervall =
  1462. ep->desc.bInterval;
  1463. context->fifos[cidx].
  1464. skbuff = NULL;
  1465. }
  1466. }
  1467. ep++;
  1468. }
  1469. context->dev = dev; /* save device */
  1470. context->if_used = ifnum; /* save used interface */
  1471. context->alt_used = alt_used; /* and alternate config */
  1472. context->ctrl_paksize = dev->descriptor.bMaxPacketSize0; /* control size */
  1473. context->cfg_used = vcf[16]; /* store used config */
  1474. context->vend_idx = vend_idx; /* store found vendor */
  1475. context->packet_size = packet_size;
  1476. context->iso_packet_size = iso_packet_size;
  1477. /* create the control pipes needed for register access */
  1478. context->ctrl_in_pipe =
  1479. usb_rcvctrlpipe(context->dev, 0);
  1480. context->ctrl_out_pipe =
  1481. usb_sndctrlpipe(context->dev, 0);
  1482. context->ctrl_urb = usb_alloc_urb(0, GFP_KERNEL);
  1483. driver_info =
  1484. (hfcsusb_vdata *) hfcusb_idtab[vend_idx].
  1485. driver_info;
  1486. printk(KERN_INFO "HFC-S USB: detected \"%s\"\n",
  1487. driver_info->vend_name);
  1488. #ifdef CONFIG_HISAX_DEBUG
  1489. DBG(USB_DBG,
  1490. "HFC-S USB: Endpoint-Config: %s (if=%d alt=%d)\n",
  1491. conf_str[small_match], context->if_used,
  1492. context->alt_used);
  1493. printk(KERN_INFO
  1494. "HFC-S USB: E-channel (\"ECHO:\") logging ");
  1495. if (validconf[small_match][18])
  1496. printk(" possible\n");
  1497. else
  1498. printk("NOT possible\n");
  1499. #endif
  1500. /* init the chip and register the driver */
  1501. if (usb_init(context)) {
  1502. usb_kill_urb(context->ctrl_urb);
  1503. usb_free_urb(context->ctrl_urb);
  1504. context->ctrl_urb = NULL;
  1505. kfree(context);
  1506. return (-EIO);
  1507. }
  1508. usb_set_intfdata(intf, context);
  1509. return (0);
  1510. }
  1511. } else {
  1512. printk(KERN_INFO
  1513. "HFC-S USB: no valid vendor found in USB descriptor\n");
  1514. }
  1515. return (-EIO);
  1516. }
  1517. /****************************************************/
  1518. /* function called when an active device is removed */
  1519. /****************************************************/
  1520. static void
  1521. hfc_usb_disconnect(struct usb_interface
  1522. *intf)
  1523. {
  1524. hfcusb_data *context = usb_get_intfdata(intf);
  1525. int i;
  1526. printk(KERN_INFO "HFC-S USB: device disconnect\n");
  1527. context->disc_flag = true;
  1528. usb_set_intfdata(intf, NULL);
  1529. if (!context)
  1530. return;
  1531. if (timer_pending(&context->t3_timer))
  1532. del_timer(&context->t3_timer);
  1533. if (timer_pending(&context->t4_timer))
  1534. del_timer(&context->t4_timer);
  1535. /* tell all fifos to terminate */
  1536. for (i = 0; i < HFCUSB_NUM_FIFOS; i++) {
  1537. if (context->fifos[i].usb_transfer_mode == USB_ISOC) {
  1538. if (context->fifos[i].active > 0) {
  1539. stop_isoc_chain(&context->fifos[i]);
  1540. #ifdef CONFIG_HISAX_DEBUG
  1541. DBG(USB_DBG,
  1542. "HFC-S USB: hfc_usb_disconnect: stopping ISOC chain Fifo no %i",
  1543. i);
  1544. #endif
  1545. }
  1546. } else {
  1547. if (context->fifos[i].active > 0) {
  1548. context->fifos[i].active = 0;
  1549. #ifdef CONFIG_HISAX_DEBUG
  1550. DBG(USB_DBG,
  1551. "HFC-S USB: hfc_usb_disconnect: unlinking URB for Fifo no %i",
  1552. i);
  1553. #endif
  1554. }
  1555. usb_kill_urb(context->fifos[i].urb);
  1556. usb_free_urb(context->fifos[i].urb);
  1557. context->fifos[i].urb = NULL;
  1558. }
  1559. context->fifos[i].active = 0;
  1560. }
  1561. usb_kill_urb(context->ctrl_urb);
  1562. usb_free_urb(context->ctrl_urb);
  1563. context->ctrl_urb = NULL;
  1564. hisax_unregister(&context->d_if);
  1565. kfree(context); /* free our structure again */
  1566. } /* hfc_usb_disconnect */
  1567. /************************************/
  1568. /* our driver information structure */
  1569. /************************************/
  1570. static struct usb_driver hfc_drv = {
  1571. .name = "hfc_usb",
  1572. .id_table = hfcusb_idtab,
  1573. .probe = hfc_usb_probe,
  1574. .disconnect = hfc_usb_disconnect,
  1575. };
  1576. static void __exit
  1577. hfc_usb_exit(void)
  1578. {
  1579. #ifdef CONFIG_HISAX_DEBUG
  1580. DBG(USB_DBG, "HFC-S USB: calling \"hfc_usb_exit\" ...");
  1581. #endif
  1582. usb_deregister(&hfc_drv); /* release our driver */
  1583. printk(KERN_INFO "HFC-S USB: module removed\n");
  1584. }
  1585. static int __init
  1586. hfc_usb_init(void)
  1587. {
  1588. #ifndef CONFIG_HISAX_DEBUG
  1589. unsigned int debug = -1;
  1590. #endif
  1591. char revstr[30], datestr[30], dummy[30];
  1592. sscanf(hfcusb_revision,
  1593. "%s %s $ %s %s %s $ ", dummy, revstr,
  1594. dummy, datestr, dummy);
  1595. printk(KERN_INFO
  1596. "HFC-S USB: driver module revision %s date %s loaded, (debug=%i)\n",
  1597. revstr, datestr, debug);
  1598. if (usb_register(&hfc_drv)) {
  1599. printk(KERN_INFO
  1600. "HFC-S USB: Unable to register HFC-S USB module at usb stack\n");
  1601. return (-1); /* unable to register */
  1602. }
  1603. return (0);
  1604. }
  1605. module_init(hfc_usb_init);
  1606. module_exit(hfc_usb_exit);
  1607. MODULE_AUTHOR(DRIVER_AUTHOR);
  1608. MODULE_DESCRIPTION(DRIVER_DESC);
  1609. MODULE_LICENSE("GPL");
  1610. MODULE_DEVICE_TABLE(usb, hfcusb_idtab);