hfc_usb.c 50 KB

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