201-hfc_usb_backport.patch 88 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665
  1. Index: linux-2.4.35.4/drivers/Makefile
  2. ===================================================================
  3. --- linux-2.4.35.4.orig/drivers/Makefile
  4. +++ linux-2.4.35.4/drivers/Makefile
  5. @@ -38,7 +38,7 @@ subdir-$(CONFIG_FUSION) += message/fusi
  6. subdir-$(CONFIG_MD) += md
  7. subdir-$(CONFIG_IEEE1394) += ieee1394
  8. subdir-$(CONFIG_PNP) += pnp
  9. -subdir-$(CONFIG_ISDN_BOOL) += isdn
  10. +subdir-$(CONFIG_ISDN) += isdn
  11. subdir-$(CONFIG_ATM) += atm
  12. subdir-$(CONFIG_FC4) += fc4
  13. Index: linux-2.4.35.4/drivers/isdn/hisax/hfc_usb.c
  14. ===================================================================
  15. --- linux-2.4.35.4.orig/drivers/isdn/hisax/hfc_usb.c
  16. +++ linux-2.4.35.4/drivers/isdn/hisax/hfc_usb.c
  17. @@ -1,13 +1,11 @@
  18. -/* $Id: hfc_usb.c,v 2.3 2001/07/06 21:30:11 werner Exp $
  19. +/*
  20. + * hfc_usb.c
  21. *
  22. + * modular HiSax ISDN driver for Colognechip HFC-USB chip
  23. *
  24. - *
  25. - * Author (C) 2001 Werner Cornelius ([email protected])
  26. - * modular driver for Colognechip HFC-USB chip
  27. - * as plugin for HiSax isdn driver
  28. - * type approval valid for HFC-S USB based TAs
  29. - *
  30. - * Copyright 2001 by Werner Cornelius ([email protected])
  31. + * Authors : Peter Sprenger ([email protected])
  32. + * Martin Bachem ([email protected])
  33. + * based on the first hfc_usb driver of Werner Cornelius ([email protected])
  34. *
  35. * This program is free software; you can redistribute it and/or modify
  36. * it under the terms of the GNU General Public License as published by
  37. @@ -23,70 +21,90 @@
  38. * along with this program; if not, write to the Free Software
  39. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  40. *
  41. - */
  42. + * 2005_Mar_16 grsch
  43. + * ported 2.6.8 hfc_usb.c to 2.4.20 format
  44. + * Gregor Schaffrath <[email protected]>
  45. +*/
  46. +
  47. #include <linux/types.h>
  48. #include <linux/stddef.h>
  49. #include <linux/timer.h>
  50. #include <linux/config.h>
  51. -#include <linux/isdn_compat.h>
  52. #include <linux/init.h>
  53. #include "hisax.h"
  54. #include <linux/module.h>
  55. #include <linux/kernel_stat.h>
  56. -#include <linux/tqueue.h>
  57. #include <linux/usb.h>
  58. #include <linux/kernel.h>
  59. #include <linux/smp_lock.h>
  60. #include <linux/sched.h>
  61. +#include "hisax_if.h"
  62. #include "hisax_loadable.h"
  63. +static const char *hfcusb_revision = "4.0";
  64. +
  65. +/*
  66. + to enable much mire debug messages in this driver, define
  67. + VERBOSE_USB_DEBUG and VERBOSE_ISDN_DEBUG
  68. + below
  69. +*/
  70. +
  71. +#define VERBOSE_USB_DEBUG
  72. +#define VERBOSE_ISDN_DEBUG
  73. +
  74. #define INCLUDE_INLINE_FUNCS
  75. +#define TRUE 1
  76. +#define FALSE 0
  77. +
  78. +
  79. /***********/
  80. /* defines */
  81. /***********/
  82. -#define HFC_CTRL_TIMEOUT 5 /* 5ms timeout writing/reading regs */
  83. -#define HFC_TIMER_T3 7000 /* timeout for l1 activation timer */
  84. -
  85. -#define HFCUSB_L1_STATECHANGE 0 /* L1 state changed */
  86. -#define HFCUSB_L1_DRX 1 /* D-frame received */
  87. -#define HFCUSB_L1_ERX 2 /* E-frame received */
  88. -#define HFCUSB_L1_DTX 4 /* D-frames completed */
  89. -
  90. -#define MAX_BCH_SIZE 2048 /* allowed B-channel packet size */
  91. -
  92. -#define HFCUSB_RX_THRESHOLD 64 /* threshold for fifo report bit rx */
  93. -#define HFCUSB_TX_THRESHOLD 64 /* threshold for fifo report bit tx */
  94. -
  95. -#define HFCUSB_CHIP_ID 0x16 /* Chip ID register index */
  96. -#define HFCUSB_CIRM 0x00 /* cirm register index */
  97. -#define HFCUSB_USB_SIZE 0x07 /* int length register */
  98. -#define HFCUSB_USB_SIZE_I 0x06 /* iso length register */
  99. -#define HFCUSB_F_CROSS 0x0b /* bit order register */
  100. -#define HFCUSB_CLKDEL 0x37 /* bit delay register */
  101. -#define HFCUSB_CON_HDLC 0xfa /* channel connect register */
  102. +#define HFC_CTRL_TIMEOUT 20 //(HZ * USB_CTRL_GET_TIMEOUT)
  103. +/* 5ms timeout writing/reading regs */
  104. +#define HFC_TIMER_T3 8000 /* timeout for l1 activation timer */
  105. +#define HFC_TIMER_T4 500 /* time for state change interval */
  106. +
  107. +#define HFCUSB_L1_STATECHANGE 0 /* L1 state changed */
  108. +#define HFCUSB_L1_DRX 1 /* D-frame received */
  109. +#define HFCUSB_L1_ERX 2 /* E-frame received */
  110. +#define HFCUSB_L1_DTX 4 /* D-frames completed */
  111. +
  112. +#define MAX_BCH_SIZE 2048 /* allowed B-channel packet size */
  113. +
  114. +#define HFCUSB_RX_THRESHOLD 64 /* threshold for fifo report bit rx */
  115. +#define HFCUSB_TX_THRESHOLD 64 /* threshold for fifo report bit tx */
  116. +
  117. +#define HFCUSB_CHIP_ID 0x16 /* Chip ID register index */
  118. +#define HFCUSB_CIRM 0x00 /* cirm register index */
  119. +#define HFCUSB_USB_SIZE 0x07 /* int length register */
  120. +#define HFCUSB_USB_SIZE_I 0x06 /* iso length register */
  121. +#define HFCUSB_F_CROSS 0x0b /* bit order register */
  122. +#define HFCUSB_CLKDEL 0x37 /* bit delay register */
  123. +#define HFCUSB_CON_HDLC 0xfa /* channel connect register */
  124. #define HFCUSB_HDLC_PAR 0xfb
  125. -#define HFCUSB_SCTRL 0x31 /* S-bus control register (tx) */
  126. -#define HFCUSB_SCTRL_E 0x32 /* same for E and special funcs */
  127. -#define HFCUSB_SCTRL_R 0x33 /* S-bus control register (rx) */
  128. -#define HFCUSB_F_THRES 0x0c /* threshold register */
  129. -#define HFCUSB_FIFO 0x0f /* fifo select register */
  130. -#define HFCUSB_F_USAGE 0x1a /* fifo usage register */
  131. +#define HFCUSB_SCTRL 0x31 /* S-bus control register (tx) */
  132. +#define HFCUSB_SCTRL_E 0x32 /* same for E and special funcs */
  133. +#define HFCUSB_SCTRL_R 0x33 /* S-bus control register (rx) */
  134. +#define HFCUSB_F_THRES 0x0c /* threshold register */
  135. +#define HFCUSB_FIFO 0x0f /* fifo select register */
  136. +#define HFCUSB_F_USAGE 0x1a /* fifo usage register */
  137. #define HFCUSB_MST_MODE0 0x14
  138. #define HFCUSB_MST_MODE1 0x15
  139. #define HFCUSB_P_DATA 0x1f
  140. #define HFCUSB_INC_RES_F 0x0e
  141. #define HFCUSB_STATES 0x30
  142. -#define HFCUSB_CHIPID 0x40 /* ID value of HFC-USB */
  143. +#define HFCUSB_CHIPID 0x40 /* ID value of HFC-USB */
  144. /******************/
  145. /* fifo registers */
  146. /******************/
  147. -#define HFCUSB_NUM_FIFOS 8 /* maximum number of fifos */
  148. -#define HFCUSB_B1_TX 0 /* index for B1 transmit bulk/int */
  149. -#define HFCUSB_B1_RX 1 /* index for B1 receive bulk/int */
  150. +#define HFCUSB_NUM_FIFOS 8 /* maximum number of fifos */
  151. +#define HFCUSB_B1_TX 0 /* index for B1 transmit bulk/int */
  152. +#define HFCUSB_B1_RX 1 /* index for B1 receive bulk/int */
  153. #define HFCUSB_B2_TX 2
  154. #define HFCUSB_B2_RX 3
  155. #define HFCUSB_D_TX 4
  156. @@ -94,198 +112,162 @@
  157. #define HFCUSB_PCM_TX 6
  158. #define HFCUSB_PCM_RX 7
  159. -/************/
  160. -/* LED mask */
  161. -/************/
  162. -#define LED_DRIVER 0x1
  163. -#define LED_L1 0x2
  164. -#define LED_BCH 0x4
  165. +/*
  166. +* used to switch snd_transfer_mode for different TA modes e.g. the Billion USB TA just
  167. +* supports ISO out, while the Cologne Chip EVAL TA just supports BULK out
  168. +*/
  169. +#define USB_INT 0
  170. +#define USB_BULK 1
  171. +#define USB_ISOC 2
  172. +
  173. +#define ISOC_PACKETS_D 8
  174. +#define ISOC_PACKETS_B 8
  175. +#define ISO_BUFFER_SIZE 128
  176. +
  177. +// ISO send definitions
  178. +#define SINK_MAX 68
  179. +#define SINK_MIN 48
  180. +#define SINK_DMIN 12
  181. +#define SINK_DMAX 18
  182. +#define BITLINE_INF (-64*8)
  183. +
  184. +
  185. +
  186. /**********/
  187. /* macros */
  188. /**********/
  189. -#define Write_hfc(a,b,c) usb_control_msg((a)->dev,(a)->ctrl_out_pipe,0,0x40,(c),(b),0,0,HFC_CTRL_TIMEOUT)
  190. -#define Read_hfc(a,b,c) usb_control_msg((a)->dev,(a)->ctrl_in_pipe,1,0xC0,0,(b),(c),1,HFC_CTRL_TIMEOUT)
  191. -
  192. -#ifdef COMPAT_HAS_USB_IDTAB
  193. -/****************************************/
  194. -/* data defining the devices to be used */
  195. -/****************************************/
  196. -static __devinitdata const struct usb_device_id hfc_usb_idtab[3] = {
  197. - {USB_DEVICE(0x959, 0x2bd0)}, /* Colognechip ROM */
  198. - {USB_DEVICE(0x7b0, 0x0006)}, /* USB TA 128 */
  199. - {} /* end with an all-zeroes entry */
  200. -};
  201. -#endif
  202. +#define write_usb(a,b,c) usb_control_msg((a)->dev,(a)->ctrl_out_pipe,0,0x40,(c),(b),NULL,0,HFC_CTRL_TIMEOUT)
  203. +#define read_usb(a,b,c) usb_control_msg((a)->dev,(a)->ctrl_in_pipe,1,0xC0,0,(b),(c),1,HFC_CTRL_TIMEOUT)
  204. /*************************************************/
  205. /* entry and size of output/input control buffer */
  206. /*************************************************/
  207. #define HFC_CTRL_BUFSIZE 32
  208. -typedef struct {
  209. +typedef struct
  210. +{
  211. __u8 hfc_reg; /* register number */
  212. __u8 reg_val; /* value to be written (or read) */
  213. + int action; /* data for action handler */
  214. +
  215. } ctrl_buft;
  216. +typedef struct
  217. +{
  218. + int vendor; // vendor id
  219. + int prod_id; // product id
  220. + char *vend_name; // vendor string
  221. + __u8 led_scheme; // led display scheme
  222. + __u8 led_invert; // invert led aux port settings
  223. + __u8 led_bits[8]; // array of 8 possible LED bitmask settings
  224. +
  225. +} vendor_data;
  226. +
  227. /***************************************************************/
  228. /* structure defining input+output fifos (interrupt/bulk mode) */
  229. /***************************************************************/
  230. -struct hfcusb_data; /* forward definition */
  231. -typedef struct {
  232. - int fifonum; /* fifo index attached to this structure */
  233. - __u8 fifo_mask; /* mask for this fifo */
  234. - int active; /* fifo is currently active */
  235. +
  236. +struct usb_fifo; /* forward definition */
  237. +typedef struct iso_urb_struct
  238. +{
  239. + struct urb *purb;
  240. + __u8 buffer[ISO_BUFFER_SIZE]; /* buffer incoming/outgoing data */
  241. + struct usb_fifo *owner_fifo; // pointer to owner fifo
  242. +} iso_urb_struct;
  243. +
  244. +
  245. +struct hfcusb_data; /* forward definition */
  246. +typedef struct usb_fifo
  247. +{
  248. + int fifonum; /* fifo index attached to this structure */
  249. + int active; /* fifo is currently active */
  250. struct hfcusb_data *hfc; /* pointer to main structure */
  251. - int pipe; /* address of endpoint */
  252. - __u8 usb_maxlen; /* maximum length for usb transfer */
  253. - int max_size; /* maximum size of receive/send packet */
  254. - int transmode; /* transparent mode selected */
  255. - int framenum; /* number of frame when last tx completed */
  256. - int rx_offset; /* offset inside rx buffer */
  257. - int next_complete; /* complete marker */
  258. - __u8 *act_ptr; /* pointer to next data */
  259. - __u8 intervall; /* interrupt interval */
  260. - struct sk_buff *buff; /* actual used buffer */
  261. - urb_t urb; /* transfer structure for usb routines */
  262. - __u8 buffer[128]; /* buffer incoming/outgoing data */
  263. + int pipe; /* address of endpoint */
  264. + __u8 usb_packet_maxlen; /* maximum length for usb transfer */
  265. + unsigned int max_size; /* maximum size of receive/send packet */
  266. + __u8 intervall; /* interrupt interval */
  267. + struct sk_buff *skbuff; /* actual used buffer */
  268. + struct urb *urb; /* transfer structure for usb routines */
  269. + __u8 buffer[128]; /* buffer incoming/outgoing data */
  270. + int bit_line; /* how much bits are in the fifo? */
  271. +
  272. + volatile __u8 usb_transfer_mode;/* switched between ISO and INT */
  273. + iso_urb_struct iso[2]; /* need two urbs to have one always for pending */
  274. + struct hisax_if *hif; /* hisax interface */
  275. + int delete_flg; /* only delete skbuff once */
  276. + int last_urblen; /* remember length of last packet */
  277. +
  278. } usb_fifo;
  279. +
  280. /*********************************************/
  281. /* structure holding all data for one device */
  282. /*********************************************/
  283. -typedef struct hfcusb_data {
  284. - struct hisax_drvreg regd; /* register data and callbacks */
  285. - struct usb_device *dev; /* our device */
  286. - int if_used; /* used interface number */
  287. - int alt_used; /* used alternate config */
  288. - int ctrl_paksize; /* control pipe packet size */
  289. +typedef struct hfcusb_data
  290. +{
  291. + // HiSax Interface for loadable Layer1 drivers
  292. + struct hisax_d_if d_if; /* see hisax_if.h */
  293. + struct hisax_b_if b_if[2]; /* see hisax_if.h */
  294. + int protocol;
  295. +
  296. + struct usb_device *dev; /* our device */
  297. + int if_used; /* used interface number */
  298. + int alt_used; /* used alternate config */
  299. + int ctrl_paksize; /* control pipe packet size */
  300. int ctrl_in_pipe, ctrl_out_pipe; /* handles for control pipe */
  301. + int cfg_used; /* configuration index used */
  302. + int vend_idx; // vendor found
  303. +
  304. + int b_mode[2]; // B-channel mode
  305. +
  306. + int l1_activated; // layer 1 activated
  307. +
  308. + int packet_size,iso_packet_size;
  309. /* control pipe background handling */
  310. ctrl_buft ctrl_buff[HFC_CTRL_BUFSIZE]; /* buffer holding queued data */
  311. - volatile int ctrl_in_idx, ctrl_out_idx, ctrl_cnt; /* input/output pointer + count */
  312. - urb_t ctrl_urb; /* transfer structure for control channel */
  313. - devrequest ctrl_write; /* buffer for control write request */
  314. - devrequest ctrl_read; /* same for read request */
  315. -
  316. - volatile __u8 dfifo_fill; /* value read from tx d-fifo */
  317. - volatile __u8 active_fifos; /* fifos currently active as bit mask */
  318. - volatile __u8 threshold_mask; /* threshold actually reported */
  319. - volatile __u8 service_request; /* fifo needs service from task */
  320. - volatile __u8 ctrl_fifo; /* last selected fifo */
  321. - volatile __u8 bch_enables; /* or mask for sctrl_r and sctrl register values */
  322. - volatile __u8 led_req; /* request status of adapters leds */
  323. - volatile __u8 led_act; /* active status of adapters leds */
  324. + volatile int ctrl_in_idx, ctrl_out_idx,
  325. + ctrl_cnt; /* input/output pointer + count */
  326. + struct urb *ctrl_urb; /* transfer structure for control channel */
  327. +
  328. + struct usb_ctrlrequest ctrl_write; /* buffer for control write request */
  329. + struct usb_ctrlrequest ctrl_read; /* same for read request */
  330. +
  331. + __u8 led_state,led_new_data,led_b_active;
  332. +
  333. + volatile __u8 threshold_mask; /* threshold actually reported */
  334. + volatile __u8 bch_enables; /* or mask for sctrl_r and sctrl register values */
  335. +
  336. usb_fifo fifos[HFCUSB_NUM_FIFOS]; /* structure holding all fifo data */
  337. - /* layer 1 activation/deactivation handling */
  338. - volatile __u8 l1_state; /* actual l1 state */
  339. - volatile ulong l1_event; /* event mask */
  340. - struct tq_struct l1_tq; /* l1 bh structure */
  341. - struct timer_list t3_timer; /* timer for activation/deactivation */
  342. - struct timer_list t4_timer; /* timer for activation/deactivation */
  343. + volatile __u8 l1_state; /* actual l1 state */
  344. + struct timer_list t3_timer; /* timer 3 for activation/deactivation */
  345. + struct timer_list t4_timer; /* timer 4 for activation/deactivation */
  346. + struct timer_list led_timer; /* timer flashing leds */
  347. +
  348. } hfcusb_data;
  349. -#if 0
  350. -static void
  351. -usb_dump_urb(purb_t purb)
  352. -{
  353. - printk("urb :%p\n", purb);
  354. - printk("next :%p\n", purb->next);
  355. - printk("dev :%p\n", purb->dev);
  356. - printk("pipe :%08X\n", purb->pipe);
  357. - printk("status :%d\n", purb->status);
  358. - printk("transfer_flags :%08X\n", purb->transfer_flags);
  359. - printk("transfer_buffer :%p\n", purb->transfer_buffer);
  360. - printk("transfer_buffer_length:%d\n",
  361. - purb->transfer_buffer_length);
  362. - printk("actual_length :%d\n", purb->actual_length);
  363. - printk("setup_packet :%p\n", purb->setup_packet);
  364. - printk("start_frame :%d\n", purb->start_frame);
  365. - printk("number_of_packets :%d\n", purb->number_of_packets);
  366. - printk("interval :%d\n", purb->interval);
  367. - printk("error_count :%d\n", purb->error_count);
  368. - printk("context :%p\n", purb->context);
  369. - printk("complete :%p\n", purb->complete);
  370. -}
  371. -#endif
  372. -/*************************************************************************/
  373. -/* bottom half handler for L1 activation/deactiavtaion + D-chan + E-chan */
  374. -/*************************************************************************/
  375. -static void
  376. -usb_l1d_bh(hfcusb_data * hfc)
  377. -{
  378. +static void collect_rx_frame(usb_fifo *fifo,__u8 *data,int len,int finish);
  379. +
  380. - while (hfc->l1_event) {
  381. - if (test_and_clear_bit
  382. - (HFCUSB_L1_STATECHANGE, &hfc->l1_event)) {
  383. - if (hfc->l1_state == 7)
  384. - hfc->led_req |= LED_L1;
  385. - else
  386. - hfc->led_req &= ~LED_L1;
  387. - if ((hfc->l1_state == 7) ||
  388. - (hfc->l1_state == 3))
  389. - hfc->regd.dch_l1l2(hfc->regd.arg_hisax,
  390. - (hfc->l1_state ==
  391. - 7) ? (PH_ACTIVATE |
  392. - INDICATION)
  393. - : (PH_DEACTIVATE | INDICATION),
  394. - NULL);
  395. - }
  396. - if (test_and_clear_bit(HFCUSB_L1_DRX, &hfc->l1_event)) {
  397. - hfc->regd.dch_l1l2(hfc->regd.arg_hisax,
  398. - PH_DATA | INDICATION,
  399. - (void *) 0);
  400. - }
  401. - if (test_and_clear_bit(HFCUSB_L1_ERX, &hfc->l1_event)) {
  402. - hfc->regd.dch_l1l2(hfc->regd.arg_hisax,
  403. - PH_DATA | INDICATION,
  404. - (void *) 1);
  405. - }
  406. - if (test_and_clear_bit(HFCUSB_L1_DTX, &hfc->l1_event)) {
  407. - hfc->regd.dch_l1l2(hfc->regd.arg_hisax,
  408. - PH_DATA | CONFIRM, NULL);
  409. - }
  410. - } /* while */
  411. -} /* usb_l1d_bh */
  412. /******************************************************/
  413. /* start next background transfer for control channel */
  414. /******************************************************/
  415. -static void
  416. -ctrl_start_transfer(hfcusb_data * hfc)
  417. +static void ctrl_start_transfer(hfcusb_data * hfc)
  418. {
  419. -
  420. - if (hfc->ctrl_cnt) {
  421. - switch (hfc->ctrl_buff[hfc->ctrl_out_idx].hfc_reg) {
  422. - case HFCUSB_F_USAGE:
  423. - hfc->ctrl_urb.pipe = hfc->ctrl_in_pipe;
  424. - hfc->ctrl_urb.setup_packet =
  425. - (u_char *) & hfc->ctrl_read;
  426. - hfc->ctrl_urb.transfer_buffer_length = 1;
  427. - hfc->ctrl_read.index =
  428. - hfc->ctrl_buff[hfc->ctrl_out_idx].
  429. - hfc_reg;
  430. - hfc->ctrl_urb.transfer_buffer =
  431. - (char *) &hfc->dfifo_fill;
  432. - break;
  433. -
  434. - default: /* write register */
  435. - hfc->ctrl_urb.pipe = hfc->ctrl_out_pipe;
  436. - hfc->ctrl_urb.setup_packet =
  437. - (u_char *) & hfc->ctrl_write;
  438. - hfc->ctrl_urb.transfer_buffer = NULL;
  439. - hfc->ctrl_urb.transfer_buffer_length = 0;
  440. - hfc->ctrl_write.index =
  441. - hfc->ctrl_buff[hfc->ctrl_out_idx].
  442. - hfc_reg;
  443. - hfc->ctrl_write.value =
  444. - hfc->ctrl_buff[hfc->ctrl_out_idx].
  445. - reg_val;
  446. - break;
  447. - }
  448. - usb_submit_urb(&hfc->ctrl_urb); /* start transfer */
  449. + int err;
  450. + if(hfc->ctrl_cnt)
  451. + {
  452. + hfc->ctrl_urb->pipe = hfc->ctrl_out_pipe;
  453. + hfc->ctrl_urb->setup_packet = (u_char *) & hfc->ctrl_write;
  454. + hfc->ctrl_urb->transfer_buffer = NULL;
  455. + hfc->ctrl_urb->transfer_buffer_length = 0;
  456. + hfc->ctrl_write.wIndex = hfc->ctrl_buff[hfc->ctrl_out_idx].hfc_reg;
  457. + hfc->ctrl_write.wValue = hfc->ctrl_buff[hfc->ctrl_out_idx].reg_val;
  458. + err = usb_submit_urb(hfc->ctrl_urb); /* start transfer */
  459. + printk(KERN_DEBUG "ctrl_start_transfer: submit %d\n", err);
  460. }
  461. } /* ctrl_start_transfer */
  462. @@ -293,897 +275,1418 @@ ctrl_start_transfer(hfcusb_data * hfc)
  463. /* queue a control transfer request */
  464. /* return 0 on success. */
  465. /************************************/
  466. -static int
  467. -queue_control_request(hfcusb_data * hfc, __u8 reg, __u8 val)
  468. +static int queue_control_request(hfcusb_data * hfc, __u8 reg, __u8 val,int action)
  469. {
  470. ctrl_buft *buf;
  471. - if (hfc->ctrl_cnt >= HFC_CTRL_BUFSIZE)
  472. - return (1); /* no space left */
  473. - buf = hfc->ctrl_buff + hfc->ctrl_in_idx; /* pointer to new index */
  474. +#ifdef VERBOSE_USB_DEBUG
  475. + printk ("HFC_USB: queue_control_request reg: %x, val: %x\n", reg, val);
  476. +#endif
  477. +
  478. + if(hfc->ctrl_cnt >= HFC_CTRL_BUFSIZE) return(1); /* no space left */
  479. + buf = &hfc->ctrl_buff[hfc->ctrl_in_idx]; /* pointer to new index */
  480. buf->hfc_reg = reg;
  481. buf->reg_val = val;
  482. + buf->action=action;
  483. if (++hfc->ctrl_in_idx >= HFC_CTRL_BUFSIZE)
  484. hfc->ctrl_in_idx = 0; /* pointer wrap */
  485. if (++hfc->ctrl_cnt == 1)
  486. ctrl_start_transfer(hfc);
  487. - return (0);
  488. -} /* queue_control_request */
  489. + return(0);
  490. +} /* queue_control_request */
  491. -/**************************************/
  492. -/* called when timer t3 or t4 expires */
  493. -/**************************************/
  494. -static void
  495. -l1_timer_expire(hfcusb_data * hfc)
  496. -{
  497. - if (timer_pending(&hfc->t4_timer))
  498. - del_timer(&hfc->t4_timer);
  499. - queue_control_request(hfc, HFCUSB_STATES, 0x40);
  500. - test_and_set_bit(HFCUSB_L1_STATECHANGE,
  501. - &hfc->l1_event);
  502. - queue_task(&hfc->l1_tq, &tq_immediate);
  503. - mark_bh(IMMEDIATE_BH);
  504. -} /* l1_timer_expire */
  505. -
  506. -/**************************************************/
  507. -/* (re)fills a tx-fifo urb. Queuing is done later */
  508. -/**************************************************/
  509. -static void
  510. -fill_tx_urb(usb_fifo * fifo)
  511. -{
  512. - struct sk_buff *skb;
  513. - long flags;
  514. - int i, ii = 0;
  515. -
  516. - fifo->urb.dev = fifo->hfc->dev;
  517. - if ((fifo->buff)
  518. - && (fifo->urb.transfer_buffer_length < fifo->usb_maxlen)) {
  519. - switch (fifo->fifonum) {
  520. - case HFCUSB_B1_TX:
  521. - case HFCUSB_B2_TX:
  522. - skb = fifo->buff;
  523. - fifo->buff = NULL;
  524. - fifo->hfc->regd.bch_l1l2(fifo->hfc->regd.
  525. - arg_hisax,
  526. - (fifo->fifonum ==
  527. - HFCUSB_B1_TX) ? 0
  528. - : 1,
  529. - (PH_DATA |
  530. - CONFIRM),
  531. - (void *) skb);
  532. - fifo->hfc->service_request |=
  533. - fifo->fifo_mask;
  534. - return;
  535. - case HFCUSB_D_TX:
  536. - dev_kfree_skb_any(fifo->buff);
  537. - fifo->buff = NULL;
  538. - save_flags(flags);
  539. - cli();
  540. - fifo->hfc->dfifo_fill = 0xff; /* currently invalid data */
  541. - queue_control_request(fifo->hfc,
  542. - HFCUSB_FIFO,
  543. - HFCUSB_D_TX);
  544. - queue_control_request(fifo->hfc,
  545. - HFCUSB_F_USAGE, 0);
  546. - restore_flags(flags);
  547. - return;
  548. - default:
  549. - return; /* error, invalid fifo */
  550. - }
  551. +
  552. +static int control_action_handler(hfcusb_data *hfc,int reg,int val,int action)
  553. +{
  554. + if(!action) return(1); // no action defined
  555. +
  556. + return(0);
  557. +}
  558. +
  559. +
  560. +/***************************************************************/
  561. +/* control completion routine handling background control cmds */
  562. +/***************************************************************/
  563. +static void ctrl_complete(struct urb *urb)
  564. +{
  565. + hfcusb_data *hfc = (hfcusb_data *) urb->context;
  566. + ctrl_buft *buf;
  567. +
  568. + printk(KERN_DEBUG "ctrl_complete cnt %d\n", hfc->ctrl_cnt);
  569. + urb->dev = hfc->dev;
  570. + if(hfc->ctrl_cnt)
  571. + {
  572. + buf=&hfc->ctrl_buff[hfc->ctrl_out_idx];
  573. + control_action_handler(hfc,buf->hfc_reg,buf->reg_val,buf->action);
  574. +
  575. + hfc->ctrl_cnt--; /* decrement actual count */
  576. + if(++hfc->ctrl_out_idx >= HFC_CTRL_BUFSIZE) hfc->ctrl_out_idx = 0; /* pointer wrap */
  577. +
  578. + ctrl_start_transfer(hfc); /* start next transfer */
  579. + }
  580. +} /* ctrl_complete */
  581. +
  582. +
  583. +
  584. +#define LED_OFF 0 // no LED support
  585. +#define LED_SCHEME1 1 // LED standard scheme
  586. +#define LED_SCHEME2 2 // not used yet...
  587. +
  588. +#define LED_POWER_ON 1
  589. +#define LED_POWER_OFF 2
  590. +#define LED_S0_ON 3
  591. +#define LED_S0_OFF 4
  592. +#define LED_B1_ON 5
  593. +#define LED_B1_OFF 6
  594. +#define LED_B1_DATA 7
  595. +#define LED_B2_ON 8
  596. +#define LED_B2_OFF 9
  597. +#define LED_B2_DATA 10
  598. +
  599. +#define LED_NORMAL 0 // LEDs are normal
  600. +#define LED_INVERTED 1 // LEDs are inverted
  601. +
  602. +// time for LED flashing
  603. +#define LED_TIME 250
  604. +
  605. +vendor_data vdata[]=
  606. +{
  607. + {0x959, 0x2bd0, "ISDN USB TA (Cologne Chip HFC-S USB based)", LED_OFF,LED_NORMAL,{4,0,2,1}}, /* CologneChip Eval TA */
  608. + {0x7b0, 0x0007, "Billion tiny USB ISDN TA 128", LED_SCHEME1, LED_INVERTED, {8,0x40,0x20,0x10}}, /* Billion TA */
  609. + {0x742, 0x2008, "Stollmann USB TA", LED_SCHEME1, LED_NORMAL, {4,0,2,1}}, /* Stollmann TA */
  610. + {0x8e3, 0x0301, "Olitec USB RNIS", LED_SCHEME1, LED_NORMAL, {2,0,1,4}}, /* Olitec TA */
  611. + {0x675, 0x1688, "DrayTec USB ISDN TA", LED_SCHEME1, LED_NORMAL, {4,0,2,1}}, /* Draytec TA */
  612. + {0x7fa, 0x0846, "Bewan Modem RNIS USB", LED_SCHEME1, LED_INVERTED, {8,0x40,0x20,0x10}}, /* Bewan TA */
  613. + {0} // EOL element
  614. +};
  615. +
  616. +/***************************************************/
  617. +/* write led data to auxport & invert if necessary */
  618. +/***************************************************/
  619. +static void write_led(hfcusb_data * hfc,__u8 led_state)
  620. +{
  621. + if(led_state!=hfc->led_state)
  622. + {
  623. + hfc->led_state=led_state;
  624. + queue_control_request(hfc, HFCUSB_P_DATA,(vdata[hfc->vend_idx].led_invert) ? ~led_state : led_state,1);
  625. + }
  626. +}
  627. +
  628. +/******************************************/
  629. +/* invert B-channel LEDs if data is sent */
  630. +/******************************************/
  631. +static void led_timer(hfcusb_data * hfc)
  632. +{
  633. + static int cnt=0;
  634. + __u8 led_state=hfc->led_state;
  635. +
  636. + if(cnt)
  637. + {
  638. + if(hfc->led_b_active&1) led_state|=vdata[hfc->vend_idx].led_bits[2];
  639. + if(hfc->led_b_active&2) led_state|=vdata[hfc->vend_idx].led_bits[3];
  640. + }
  641. + else
  642. + {
  643. + if(!(hfc->led_b_active&1) || hfc->led_new_data&1) led_state&=~vdata[hfc->vend_idx].led_bits[2];
  644. + if(!(hfc->led_b_active&2) || hfc->led_new_data&2) led_state&=~vdata[hfc->vend_idx].led_bits[3];
  645. }
  646. - /* check if new buffer needed */
  647. - if (!fifo->buff) {
  648. - switch (fifo->fifonum) {
  649. - case HFCUSB_B1_TX:
  650. - if (fifo->hfc->regd.bsk[0])
  651. - fifo->buff = *fifo->hfc->regd.bsk[0]; /* B1-channel tx buffer */
  652. + write_led(hfc,led_state);
  653. + hfc->led_new_data=0;
  654. +
  655. + cnt=!cnt;
  656. + // restart 4 hz timer
  657. + hfc->led_timer.expires = jiffies + (LED_TIME * HZ) / 1000;
  658. + if(!timer_pending(&hfc->led_timer)) add_timer(&hfc->led_timer);
  659. +}
  660. +
  661. +/**************************/
  662. +/* handle LED requests */
  663. +/**************************/
  664. +static void handle_led(hfcusb_data * hfc,int event)
  665. +{
  666. + __u8 led_state=hfc->led_state;
  667. +
  668. + // if no scheme -> no LED action
  669. + if(vdata[hfc->vend_idx].led_scheme==LED_OFF) return;
  670. +
  671. + switch(event)
  672. + {
  673. + case LED_POWER_ON:
  674. + led_state|=vdata[hfc->vend_idx].led_bits[0];
  675. + break;
  676. + case LED_POWER_OFF: // no Power off handling
  677. + break;
  678. + case LED_S0_ON:
  679. + led_state|=vdata[hfc->vend_idx].led_bits[1];
  680. + break;
  681. + case LED_S0_OFF:
  682. + led_state&=~vdata[hfc->vend_idx].led_bits[1];
  683. break;
  684. - case HFCUSB_B2_TX:
  685. - if (fifo->hfc->regd.bsk[1])
  686. - fifo->buff = *fifo->hfc->regd.bsk[1]; /* B2-channel tx buffer */
  687. + case LED_B1_ON:
  688. + hfc->led_b_active|=1;
  689. break;
  690. - case HFCUSB_D_TX:
  691. - if (fifo->hfc->regd.dsq)
  692. - fifo->buff = skb_dequeue(fifo->hfc->regd.dsq); /* D-channel tx queue */
  693. + case LED_B1_OFF:
  694. + hfc->led_b_active&=~1;
  695. break;
  696. - default:
  697. - return; /* error, invalid fifo */
  698. + case LED_B1_DATA:
  699. + hfc->led_new_data|=1;
  700. + break;
  701. + case LED_B2_ON:
  702. + hfc->led_b_active|=2;
  703. + break;
  704. + case LED_B2_OFF:
  705. + hfc->led_b_active&=~2;
  706. + break;
  707. + case LED_B2_DATA:
  708. + hfc->led_new_data|=2;
  709. + break;
  710. + }
  711. +
  712. + write_led(hfc,led_state);
  713. +}
  714. +
  715. +/********************************/
  716. +/* called when timer t3 expires */
  717. +/********************************/
  718. +static void l1_timer_expire_t3(hfcusb_data * hfc)
  719. +{
  720. + //printk (KERN_INFO "HFC-USB: l1_timer_expire_t3\n");
  721. +
  722. + hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,PH_DEACTIVATE | INDICATION,NULL);
  723. +#ifdef VERBOSE_USB_DEBUG
  724. + printk(KERN_INFO "PH_DEACTIVATE | INDICATION sent\n");
  725. +#endif
  726. + hfc->l1_activated=FALSE;
  727. + handle_led(hfc,LED_S0_OFF);
  728. +}
  729. +
  730. +/********************************/
  731. +/* called when timer t4 expires */
  732. +/********************************/
  733. +static void l1_timer_expire_t4(hfcusb_data * hfc)
  734. +{
  735. + //printk (KERN_INFO "HFC-USB: l1_timer_expire_t4\n");
  736. +
  737. + hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,PH_DEACTIVATE | INDICATION,NULL);
  738. +#ifdef VERBOSE_USB_DEBUG
  739. + printk(KERN_INFO "PH_DEACTIVATE | INDICATION sent\n");
  740. +#endif
  741. + hfc->l1_activated=FALSE;
  742. + handle_led(hfc,LED_S0_OFF);
  743. +}
  744. +
  745. +/*****************************/
  746. +/* handle S0 state changes */
  747. +/*****************************/
  748. +static void state_handler(hfcusb_data * hfc,__u8 state)
  749. +{
  750. + __u8 old_state;
  751. +
  752. + old_state=hfc->l1_state;
  753. +
  754. + // range check
  755. + if(state==old_state || state<1 || state>8) return;
  756. +
  757. +#ifdef VERBOSE_ISDN_DEBUG
  758. + printk(KERN_INFO "HFC-USB: new S0 state:%d old_state:%d\n",state,old_state);
  759. +#endif
  760. +
  761. + if(state<4 || state==7 || state==8)
  762. + {
  763. + if(timer_pending(&hfc->t3_timer)) del_timer(&hfc->t3_timer);
  764. + //printk(KERN_INFO "HFC-USB: T3 deactivated\n");
  765. + }
  766. +
  767. + if(state>=7)
  768. + {
  769. + if(timer_pending(&hfc->t4_timer)) del_timer(&hfc->t4_timer);
  770. + //printk(KERN_INFO "HFC-USB: T4 deactivated\n");
  771. + }
  772. +
  773. + if(state==7 && !hfc->l1_activated)
  774. + {
  775. + hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,PH_ACTIVATE | INDICATION,NULL);
  776. + //printk(KERN_INFO "HFC-USB: PH_ACTIVATE | INDICATION sent\n");
  777. + hfc->l1_activated=TRUE;
  778. + handle_led(hfc,LED_S0_ON);
  779. + }
  780. + else
  781. + if(state<=3 /* && activated*/)
  782. + {
  783. + if(old_state==7 || old_state==8)
  784. + {
  785. + //printk(KERN_INFO "HFC-USB: T4 activated\n");
  786. + hfc->t4_timer.expires = jiffies + (HFC_TIMER_T4 * HZ) / 1000;
  787. + if(!timer_pending(&hfc->t4_timer)) add_timer(&hfc->t4_timer);
  788. }
  789. - if (!fifo->buff) {
  790. - fifo->active = 0; /* we are inactive now */
  791. - fifo->hfc->active_fifos &= ~fifo->fifo_mask;
  792. - if (fifo->fifonum == HFCUSB_D_TX) {
  793. - test_and_set_bit(HFCUSB_L1_DTX,
  794. - &fifo->hfc->l1_event);
  795. - queue_task(&fifo->hfc->l1_tq,
  796. - &tq_immediate);
  797. - mark_bh(IMMEDIATE_BH);
  798. - }
  799. - return;
  800. + else
  801. + {
  802. + hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,PH_DEACTIVATE | INDICATION,NULL);
  803. + //printk(KERN_INFO "HFC-USB: PH_DEACTIVATE | INDICATION sent\n");
  804. + hfc->l1_activated=FALSE;
  805. + handle_led(hfc,LED_S0_OFF);
  806. }
  807. - fifo->act_ptr = fifo->buff->data; /* start of data */
  808. - fifo->active = 1;
  809. - ii = 1;
  810. - fifo->hfc->active_fifos |= fifo->fifo_mask;
  811. - fifo->hfc->service_request &= ~fifo->fifo_mask;
  812. - }
  813. - /* fillup the send buffer */
  814. - i = fifo->buff->len - (fifo->act_ptr - fifo->buff->data); /* remaining length */
  815. - fifo->buffer[0] = !fifo->transmode; /* not eof */
  816. - if (i > (fifo->usb_maxlen - ii)) {
  817. - i = fifo->usb_maxlen - ii;
  818. - }
  819. - if (i)
  820. - memcpy(fifo->buffer + ii, fifo->act_ptr, i);
  821. - fifo->urb.transfer_buffer_length = i + ii;
  822. - fifo->rx_offset = ii;
  823. -} /* fill_tx_urb */
  824. -
  825. -/************************************************/
  826. -/* transmit completion routine for all tx fifos */
  827. -/************************************************/
  828. -static void
  829. -tx_complete(purb_t urb)
  830. + }
  831. +
  832. + hfc->l1_state=state;
  833. +}
  834. +
  835. +
  836. +/* prepare iso urb */
  837. +static void fill_isoc_urb(struct urb *urb, struct usb_device *dev, unsigned int pipe, void *buf,
  838. + int num_packets, int packet_size, int interval, usb_complete_t complete, void *context)
  839. {
  840. - usb_fifo *fifo = (usb_fifo *) urb->context; /* pointer to our fifo */
  841. + int k;
  842. - fifo->hfc->service_request &= ~fifo->fifo_mask; /* no further handling */
  843. - fifo->framenum = usb_get_current_frame_number(fifo->hfc->dev);
  844. + spin_lock_init(&urb->lock); // do we really need spin_lock_init ?
  845. + urb->dev = dev;
  846. + urb->pipe = pipe;
  847. + urb->complete = complete;
  848. + urb->number_of_packets = num_packets;
  849. + urb->transfer_buffer_length = packet_size * num_packets;
  850. + urb->context = context;
  851. + urb->transfer_buffer = buf;
  852. + urb->transfer_flags = 0;
  853. + urb->transfer_flags = USB_ISO_ASAP;
  854. + urb->actual_length = 0;
  855. + urb->interval = interval;
  856. + for (k = 0; k < num_packets; k++) {
  857. + urb->iso_frame_desc[k].offset = packet_size * k;
  858. + urb->iso_frame_desc[k].length = packet_size;
  859. + urb->iso_frame_desc[k].actual_length = 0;
  860. + }
  861. +}
  862. - /* check for deactivation or error */
  863. - if ((!fifo->active) || (urb->status)) {
  864. - fifo->hfc->active_fifos &= ~fifo->fifo_mask; /* we are inactive */
  865. - fifo->active = 0;
  866. - if ((fifo->buff) && (fifo->fifonum == HFCUSB_D_TX)) {
  867. - dev_kfree_skb_any(fifo->buff);
  868. +/* allocs urbs and start isoc transfer with two pending urbs to avoid gaps in the transfer chain */
  869. +static int start_isoc_chain(usb_fifo * fifo, int num_packets_per_urb,usb_complete_t complete,int packet_size)
  870. +{
  871. + int i, k, errcode;
  872. +
  873. +#ifdef VERBOSE_USB_DEBUG
  874. + printk(KERN_INFO "HFC-USB: starting ISO-chain for Fifo %i\n", fifo->fifonum);
  875. +#endif
  876. +
  877. +
  878. + // allocate Memory for Iso out Urbs
  879. + for (i = 0; i < 2; i++) {
  880. + if (!(fifo->iso[i].purb)) {
  881. + fifo->iso[i].purb = usb_alloc_urb(num_packets_per_urb);
  882. + fifo->iso[i].owner_fifo = (struct usb_fifo *) fifo;
  883. +
  884. + // Init the first iso
  885. + if (ISO_BUFFER_SIZE >= (fifo->usb_packet_maxlen * num_packets_per_urb))
  886. + {
  887. +
  888. + fill_isoc_urb(fifo->iso[i].purb, fifo->hfc->dev, fifo->pipe, fifo->iso[i].buffer,
  889. + num_packets_per_urb, fifo->usb_packet_maxlen, fifo->intervall,
  890. + complete, &fifo->iso[i]);
  891. +
  892. + memset(fifo->iso[i].buffer, 0, sizeof(fifo->iso[i].buffer));
  893. +
  894. + // defining packet delimeters in fifo->buffer
  895. + for(k = 0; k < num_packets_per_urb; k++)
  896. + {
  897. + fifo->iso[i].purb->iso_frame_desc[k].offset = k*packet_size;
  898. + fifo->iso[i].purb->iso_frame_desc[k].length = packet_size;
  899. + }
  900. + }
  901. }
  902. - fifo->buff = NULL;
  903. - return;
  904. +
  905. + fifo->bit_line = BITLINE_INF;
  906. +
  907. + errcode = usb_submit_urb(fifo->iso[i].purb);
  908. + fifo->active = (errcode >= 0) ? 1 : 0;
  909. + if(errcode < 0)
  910. + {
  911. + printk(KERN_INFO "HFC-USB: error submitting ISO URB: %i.%i \n", errcode, i);
  912. + };
  913. +
  914. }
  915. - fifo->act_ptr += (urb->transfer_buffer_length - fifo->rx_offset); /* adjust pointer */
  916. - fill_tx_urb(fifo); /* refill the urb */
  917. - fifo->hfc->threshold_mask |= fifo->fifo_mask; /* assume threshold reached */
  918. - if (fifo->buff)
  919. - fifo->hfc->service_request |= fifo->fifo_mask; /* need to restart */
  920. -} /* tx_complete */
  921. -/***********************************************/
  922. -/* receive completion routine for all rx fifos */
  923. -/***********************************************/
  924. -static void
  925. -rx_complete(purb_t urb)
  926. + // errcode = (usb_submit_urb(fifo->iso[0].purb, GFP_KERNEL));
  927. + return(fifo->active);
  928. +}
  929. +
  930. +/* stops running iso chain and frees their pending urbs */
  931. +static void stop_isoc_chain(usb_fifo * fifo)
  932. {
  933. - usb_fifo *fifo = (usb_fifo *) urb->context; /* pointer to our fifo */
  934. - hfcusb_data *hfc = fifo->hfc;
  935. - usb_fifo *txfifo;
  936. - __u8 last_state;
  937. - int i, ii, currcnt, hdlci;
  938. - struct sk_buff *skb;
  939. -
  940. - urb->dev = hfc->dev; /* security init */
  941. - if ((!fifo->active) || (urb->status)) {
  942. - hfc->service_request &= ~fifo->fifo_mask; /* no further handling */
  943. - hfc->active_fifos &= ~fifo->fifo_mask; /* we are inactive */
  944. - fifo->urb.interval = 0; /* cancel automatic rescheduling */
  945. - if (fifo->buff) {
  946. - dev_kfree_skb_any(fifo->buff);
  947. - fifo->buff = NULL;
  948. + int i;
  949. +
  950. + for(i = 0; i < 2; i++)
  951. + {
  952. + if(fifo->iso[i].purb)
  953. + {
  954. +#ifdef VERBOSE_USB_DEBUG
  955. + printk(KERN_INFO "HFC-USB: Stopping iso chain for fifo %i.%i\n", fifo->fifonum, i);
  956. +#endif
  957. + usb_unlink_urb(fifo->iso[i].purb);
  958. + usb_free_urb(fifo->iso[i].purb);
  959. + fifo->iso[i].purb = NULL;
  960. }
  961. - return;
  962. }
  963. + if (fifo->urb) {
  964. + usb_unlink_urb(fifo->urb);
  965. + usb_free_urb(fifo->urb);
  966. + fifo->urb = NULL;
  967. + }
  968. + fifo->active = 0;
  969. +}
  970. - /* first check for any status changes */
  971. - if ((urb->actual_length < fifo->rx_offset)
  972. - || (urb->actual_length > fifo->usb_maxlen))
  973. - return; /* error condition */
  974. -
  975. - if (fifo->rx_offset) {
  976. - hfc->threshold_mask = fifo->buffer[1]; /* update threshold status */
  977. - fifo->next_complete = fifo->buffer[0] & 1;
  978. - if ((fifo->fifonum == HFCUSB_D_RX) &&
  979. - (hfc->led_req != hfc->led_act))
  980. - queue_control_request(hfc, HFCUSB_P_DATA, hfc->led_req);
  981. -
  982. - /* check if rescheduling needed */
  983. - if ((i =
  984. - hfc->service_request & hfc->active_fifos & ~hfc->
  985. - threshold_mask)) {
  986. - currcnt =
  987. - usb_get_current_frame_number(hfc->dev);
  988. - txfifo = hfc->fifos + HFCUSB_B1_TX;
  989. - ii = 3;
  990. - while (ii--) {
  991. - if ((i & txfifo->fifo_mask)
  992. - && (currcnt != txfifo->framenum)) {
  993. - hfc->service_request &=
  994. - ~txfifo->fifo_mask;
  995. - if (!txfifo->buff)
  996. - fill_tx_urb(txfifo);
  997. - if (txfifo->buff)
  998. - usb_submit_urb(&txfifo->
  999. - urb);
  1000. +// defines how much ISO packets are handled in one URB
  1001. +static int iso_packets[8]={ISOC_PACKETS_B,ISOC_PACKETS_B,ISOC_PACKETS_B,ISOC_PACKETS_B,
  1002. + ISOC_PACKETS_D,ISOC_PACKETS_D,ISOC_PACKETS_D,ISOC_PACKETS_D};
  1003. +
  1004. +/*****************************************************/
  1005. +/* transmit completion routine for all ISO tx fifos */
  1006. +/*****************************************************/
  1007. +static void tx_iso_complete(struct urb *urb)
  1008. +{
  1009. + iso_urb_struct *context_iso_urb = (iso_urb_struct *) urb->context;
  1010. + usb_fifo *fifo = context_iso_urb->owner_fifo;
  1011. + hfcusb_data *hfc = fifo->hfc;
  1012. + int k, tx_offset, num_isoc_packets, sink, len, current_len,errcode,frame_complete,transp_mode,fifon;
  1013. + __u8 threshbit;
  1014. + __u8 threshtable[8] = { 1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
  1015. +
  1016. + fifon=fifo->fifonum;
  1017. + tx_offset=0;
  1018. + // very weird error code when using ohci drivers, for now : ignore this error ... (MB)
  1019. + if(urb->status == -EOVERFLOW)
  1020. + {
  1021. + urb->status = 0;
  1022. +#ifdef VERBOSE_USB_DEBUG
  1023. + printk(KERN_INFO "HFC-USB: ignoring USB DATAOVERRUN for fifo %i \n",fifon);
  1024. +#endif
  1025. + }
  1026. +
  1027. + if(fifo->active && !urb->status)
  1028. + {
  1029. + transp_mode=0;
  1030. + if(fifon<4 && hfc->b_mode[fifon/2]==L1_MODE_TRANS) transp_mode=TRUE;
  1031. +
  1032. + threshbit = threshtable[fifon] & hfc->threshold_mask; // is threshold set for our channel?
  1033. + num_isoc_packets=iso_packets[fifon];
  1034. +
  1035. + if(fifon >= HFCUSB_D_TX)
  1036. + {
  1037. + sink = (threshbit) ? SINK_DMIN : SINK_DMAX; // how much bit go to the sink for D-channel?
  1038. + }
  1039. + else
  1040. + {
  1041. + sink = (threshbit) ? SINK_MIN : SINK_MAX; // how much bit go to the sink for B-channel?
  1042. + }
  1043. +
  1044. + // prepare ISO Urb
  1045. + fill_isoc_urb(urb, fifo->hfc->dev, fifo->pipe,context_iso_urb->buffer, num_isoc_packets,
  1046. + fifo->usb_packet_maxlen, fifo->intervall, tx_iso_complete, urb->context);
  1047. + memset(context_iso_urb->buffer, 0, sizeof(context_iso_urb->buffer));
  1048. +
  1049. + frame_complete=FALSE;
  1050. +
  1051. + // Generate Iso Packets
  1052. + for(k = 0; k < num_isoc_packets; ++k)
  1053. + {
  1054. + if(fifo->skbuff)
  1055. + {
  1056. + len = fifo->skbuff->len; // remaining length
  1057. +
  1058. + fifo->bit_line -= sink; // we lower data margin every msec
  1059. + current_len = (0 - fifo->bit_line) / 8;
  1060. + if(current_len > 14) current_len = 14; // maximum 15 byte for every ISO packet makes our life easier
  1061. + current_len = (len <= current_len) ? len : current_len;
  1062. + fifo->bit_line += current_len * 8; // how much bit do we put on the line?
  1063. +
  1064. + context_iso_urb->buffer[tx_offset] = 0;
  1065. + if(current_len == len)
  1066. + {
  1067. + if(!transp_mode)
  1068. + {
  1069. + context_iso_urb->buffer[tx_offset] = 1; // here frame completion
  1070. + fifo->bit_line += 32; // add 2 byte flags and 16bit CRC at end of ISDN frame
  1071. + }
  1072. + frame_complete = TRUE;
  1073. + }
  1074. +
  1075. + // copy bytes from buffer into ISO_URB
  1076. + memcpy(context_iso_urb->buffer+tx_offset+1,fifo->skbuff->data,current_len);
  1077. + skb_pull(fifo->skbuff,current_len);
  1078. +
  1079. + // define packet delimeters within the URB buffer
  1080. + urb->iso_frame_desc[k].offset = tx_offset;
  1081. + urb->iso_frame_desc[k].length = current_len + 1;
  1082. +
  1083. + tx_offset += (current_len + 1);
  1084. + // printk(KERN_INFO "HFC-USB: fifonum:%d,%d bytes to send, %d bytes ISO packet,bitline:%d,sink:%d,threshbit:%d,threshmask:%x\n",fifon,len,current_len,fifo->bit_line,sink,threshbit,hfc->threshold_mask);
  1085. + if(!transp_mode)
  1086. + {
  1087. + if(fifon==HFCUSB_B1_TX) handle_led(hfc,LED_B1_DATA);
  1088. + if(fifon==HFCUSB_B2_TX) handle_led(hfc,LED_B2_DATA);
  1089. + }
  1090. + }
  1091. + else
  1092. + {
  1093. + // we have no more data - generate 1 byte ISO packets
  1094. + urb->iso_frame_desc[k].offset = tx_offset++;
  1095. +
  1096. + urb->iso_frame_desc[k].length = 1;
  1097. + fifo->bit_line -= sink; // we lower data margin every msec
  1098. +
  1099. + if(fifo->bit_line < BITLINE_INF)
  1100. + {
  1101. + fifo->bit_line = BITLINE_INF;
  1102. + //printk (KERN_INFO "HFC-USB: BITLINE_INF underrun\n");
  1103. }
  1104. - txfifo += 2;
  1105. }
  1106. - }
  1107. - /* handle l1 events */
  1108. - if ((fifo->buffer[0] >> 4) != hfc->l1_state) {
  1109. - last_state = hfc->l1_state;
  1110. - hfc->l1_state = fifo->buffer[0] >> 4; /* update status */
  1111. - if (timer_pending(&hfc->t4_timer))
  1112. - del_timer(&hfc->t4_timer);
  1113. - if (((hfc->l1_state == 3) &&
  1114. - ((last_state == 7) ||
  1115. - (last_state == 8))) ||
  1116. - ((timer_pending(&hfc->t3_timer) &&
  1117. - (hfc->l1_state == 8)))) {
  1118. - hfc->t4_timer.expires = jiffies + 2;
  1119. - add_timer(&hfc->t4_timer);
  1120. - } else {
  1121. - if (timer_pending(&hfc->t3_timer)
  1122. - && (hfc->l1_state == 7))
  1123. - del_timer(&hfc->t3_timer); /* no longer needed */
  1124. - test_and_set_bit(HFCUSB_L1_STATECHANGE,
  1125. - &hfc->l1_event);
  1126. - queue_task(&hfc->l1_tq, &tq_immediate);
  1127. - mark_bh(IMMEDIATE_BH);
  1128. + if(frame_complete)
  1129. + {
  1130. + // delete the buffer only once, here or in hfc_usb_l2l1() in a PH_DATA|REQUEST
  1131. + fifo->delete_flg=TRUE;
  1132. +
  1133. + fifo->hif->l1l2(fifo->hif,PH_DATA|CONFIRM,(void*)fifo->skbuff->truesize);
  1134. +
  1135. + if(fifo->skbuff && fifo->delete_flg)
  1136. + {
  1137. + dev_kfree_skb_any(fifo->skbuff);
  1138. + //printk(KERN_INFO "HFC-USB: skbuff=NULL on fifo:%d\n",fifo->fifonum);
  1139. + fifo->skbuff = NULL;
  1140. + fifo->delete_flg=FALSE;
  1141. + }
  1142. +
  1143. + frame_complete=FALSE;
  1144. }
  1145. + }
  1146. +
  1147. + errcode = usb_submit_urb(urb);
  1148. + if(errcode < 0)
  1149. + {
  1150. + printk(KERN_INFO "HFC-USB: error submitting ISO URB: %i \n", errcode);
  1151. + }
  1152. + }
  1153. + else
  1154. + {
  1155. + if(urb->status)
  1156. + {
  1157. + printk(KERN_INFO "HFC-USB: tx_iso_complete : urb->status %i, fifonum %i\n", urb->status,fifon);
  1158. }
  1159. }
  1160. - /* check the length for data and move if present */
  1161. - if (fifo->next_complete || (urb->actual_length > fifo->rx_offset)) {
  1162. - i = fifo->buff->len + urb->actual_length - fifo->rx_offset; /* new total length */
  1163. - hdlci = (fifo->transmode) ? 0 : 3;
  1164. - if (i <= (fifo->max_size + hdlci)) {
  1165. - memcpy(fifo->act_ptr,
  1166. - fifo->buffer + fifo->rx_offset,
  1167. - urb->actual_length - fifo->rx_offset);
  1168. - fifo->act_ptr +=
  1169. - (urb->actual_length - fifo->rx_offset);
  1170. - fifo->buff->len +=
  1171. - (urb->actual_length - fifo->rx_offset);
  1172. - } else
  1173. - fifo->buff->len = fifo->max_size + 4; /* mark frame as to long */
  1174. - if (fifo->next_complete && (urb->actual_length < fifo->usb_maxlen)) {
  1175. - /* the frame is complete */
  1176. - fifo->next_complete = 0;
  1177. - if (((!*(fifo->act_ptr - 1)) || fifo->transmode) &&
  1178. - (fifo->buff->len >= (hdlci + 1))
  1179. - && (fifo->buff->len <=
  1180. - (fifo->max_size + hdlci)) &&
  1181. - ((skb = dev_alloc_skb(fifo->max_size + hdlci)) != NULL)) {
  1182. - fifo->buff->len -= hdlci; /* adjust size */
  1183. - switch (fifo->fifonum) {
  1184. - case HFCUSB_D_RX:
  1185. - skb_queue_tail(hfc->regd.
  1186. - drq,
  1187. - fifo->buff);
  1188. - test_and_set_bit
  1189. - (HFCUSB_L1_DRX,
  1190. - &hfc->l1_event);
  1191. - queue_task(&hfc->l1_tq,
  1192. - &tq_immediate);
  1193. - mark_bh(IMMEDIATE_BH);
  1194. - break;
  1195. +} /* tx_iso_complete */
  1196. - case HFCUSB_B1_RX:
  1197. - if (hfc->regd.brq[0]) {
  1198. - skb_queue_tail
  1199. - (hfc->regd.
  1200. - brq[0],
  1201. - fifo->buff);
  1202. - hfc->regd.
  1203. - bch_l1l2(hfc->
  1204. - regd.
  1205. - arg_hisax,
  1206. - 0,
  1207. - PH_DATA
  1208. - |
  1209. - INDICATION,
  1210. - (void *)
  1211. - fifo->
  1212. - buff);
  1213. - } else
  1214. - dev_kfree_skb_any
  1215. - (fifo->buff);
  1216. - break;
  1217. -
  1218. - case HFCUSB_B2_RX:
  1219. - if (hfc->regd.brq[1]) {
  1220. - skb_queue_tail
  1221. - (hfc->regd.
  1222. - brq[1],
  1223. - fifo->buff);
  1224. - hfc->regd.
  1225. - bch_l1l2(hfc->
  1226. - regd.
  1227. - arg_hisax,
  1228. - 1,
  1229. - PH_DATA
  1230. - |
  1231. - INDICATION,
  1232. - (void
  1233. - *)
  1234. - fifo->
  1235. - buff);
  1236. - } else
  1237. - dev_kfree_skb_any
  1238. - (fifo->buff);
  1239. - break;
  1240. +/*****************************************************/
  1241. +/* receive completion routine for all ISO tx fifos */
  1242. +/*****************************************************/
  1243. +static void rx_iso_complete(struct urb *urb)
  1244. +{
  1245. + iso_urb_struct *context_iso_urb = (iso_urb_struct *) urb->context;
  1246. + usb_fifo *fifo = context_iso_urb->owner_fifo;
  1247. + hfcusb_data *hfc = fifo->hfc;
  1248. + int k, len, errcode, offset, num_isoc_packets,fifon;
  1249. + __u8 *buf;
  1250. - case HFCUSB_PCM_RX:
  1251. - skb_queue_tail(&hfc->regd.
  1252. - erq,
  1253. - fifo->buff);
  1254. - test_and_set_bit
  1255. - (HFCUSB_L1_ERX,
  1256. - &hfc->l1_event);
  1257. - queue_task(&hfc->l1_tq,
  1258. - &tq_immediate);
  1259. - mark_bh(IMMEDIATE_BH);
  1260. - break;
  1261. + fifon=fifo->fifonum;
  1262. + // very weird error code when using ohci drivers, for now : ignore this error ... (MB)
  1263. + if(urb->status == -EOVERFLOW)
  1264. + {
  1265. + urb->status = 0;
  1266. +#ifdef VERBOSE_USB_DEBUG
  1267. + printk(KERN_INFO "HFC-USB: ignoring USB DATAOVERRUN for fifo %i \n",fifon);
  1268. +#endif
  1269. + }
  1270. - default:
  1271. - dev_kfree_skb_any(fifo->
  1272. - buff);
  1273. - break;
  1274. + if(fifo->active && !urb->status)
  1275. + {
  1276. + num_isoc_packets=iso_packets[fifon];
  1277. +
  1278. + // Generate D-Channel Iso Packets
  1279. + for(k = 0; k < num_isoc_packets; ++k)
  1280. + {
  1281. + len=urb->iso_frame_desc[k].actual_length;
  1282. + offset=urb->iso_frame_desc[k].offset;
  1283. + buf=context_iso_urb->buffer+offset;
  1284. +
  1285. + if(fifo->last_urblen!=fifo->usb_packet_maxlen)
  1286. + {
  1287. + // the threshold mask is in the 2nd status byte
  1288. + hfc->threshold_mask=buf[1];
  1289. + // the S0 state is in the upper half of the 1st status byte
  1290. + state_handler(hfc,buf[0] >> 4);
  1291. + // if we have more than the 2 status bytes -> collect data
  1292. + if(len>2) collect_rx_frame(fifo,buf+2,len-2,buf[0]&1);
  1293. }
  1294. - fifo->buff = skb;
  1295. - }
  1296. - fifo->buff->len = 0; /* reset counter */
  1297. - fifo->act_ptr = fifo->buff->data; /* and pointer */
  1298. + else collect_rx_frame(fifo,buf,len,0);
  1299. +
  1300. + fifo->last_urblen=len;
  1301. +
  1302. + }
  1303. +
  1304. + // prepare ISO Urb
  1305. + fill_isoc_urb(urb, fifo->hfc->dev, fifo->pipe,context_iso_urb->buffer, num_isoc_packets,
  1306. + fifo->usb_packet_maxlen, fifo->intervall, rx_iso_complete, urb->context);
  1307. +
  1308. + errcode = usb_submit_urb(urb);
  1309. + if(errcode < 0)
  1310. + {
  1311. + printk(KERN_INFO "HFC-USB: error submitting ISO URB: %i \n", errcode);
  1312. + }
  1313. + }
  1314. + else
  1315. + {
  1316. + if(urb->status)
  1317. + {
  1318. + printk(KERN_INFO "HFC-USB: rx_iso_complete : urb->status %i, fifonum %i\n", urb->status,fifon);
  1319. + }
  1320. + }
  1321. +} /* rx_iso_complete */
  1322. +
  1323. +
  1324. +/*****************************************************/
  1325. +/* collect data from interrupt or isochron in */
  1326. +/*****************************************************/
  1327. +static void collect_rx_frame(usb_fifo *fifo,__u8 *data,int len,int finish)
  1328. +{
  1329. + hfcusb_data *hfc = fifo->hfc;
  1330. + int transp_mode,fifon;
  1331. +
  1332. + fifon=fifo->fifonum;
  1333. + transp_mode=0;
  1334. + if(fifon<4 && hfc->b_mode[fifon/2]==L1_MODE_TRANS) transp_mode=TRUE;
  1335. +
  1336. + //printk(KERN_INFO "HFC-USB: got %d bytes finish:%d max_size:%d fifo:%d\n",len,finish,fifo->max_size,fifon);
  1337. + if(!fifo->skbuff)
  1338. + {
  1339. + // allocate sk buffer
  1340. + fifo->skbuff=dev_alloc_skb(fifo->max_size + 3);
  1341. + if(!fifo->skbuff)
  1342. + {
  1343. + printk(KERN_INFO "HFC-USB: cannot allocate buffer (dev_alloc_skb) fifo:%d\n",fifon);
  1344. + return;
  1345. + }
  1346. +
  1347. + }
  1348. +
  1349. + if(len && fifo->skbuff->len+len<fifo->max_size)
  1350. + {
  1351. + memcpy(skb_put(fifo->skbuff,len),data,len);
  1352. + }
  1353. + else printk(KERN_INFO "HCF-USB: got frame exceeded fifo->max_size:%d\n",fifo->max_size);
  1354. +
  1355. + // give transparent data up, when 128 byte are available
  1356. + if(transp_mode && fifo->skbuff->len>=128)
  1357. + {
  1358. + fifo->hif->l1l2(fifo->hif,PH_DATA | INDICATION,fifo->skbuff);
  1359. + fifo->skbuff = NULL; // buffer was freed from upper layer
  1360. + return;
  1361. + }
  1362. +
  1363. + // we have a complete hdlc packet
  1364. + if(finish)
  1365. + {
  1366. + if(!fifo->skbuff->data[fifo->skbuff->len-1])
  1367. + {
  1368. + skb_trim(fifo->skbuff,fifo->skbuff->len-3); // remove CRC & status
  1369. +
  1370. + //printk(KERN_INFO "HFC-USB: got frame %d bytes on fifo:%d\n",fifo->skbuff->len,fifon);
  1371. +
  1372. + if(fifon==HFCUSB_PCM_RX) fifo->hif->l1l2(fifo->hif,PH_DATA_E | INDICATION,fifo->skbuff);
  1373. + else fifo->hif->l1l2(fifo->hif,PH_DATA | INDICATION,fifo->skbuff);
  1374. +
  1375. + fifo->skbuff = NULL; // buffer was freed from upper layer
  1376. + }
  1377. + else
  1378. + {
  1379. + printk(KERN_INFO "HFC-USB: got frame %d bytes but CRC ERROR!!!\n",fifo->skbuff->len);
  1380. +
  1381. + skb_trim(fifo->skbuff,0); // clear whole buffer
  1382. + }
  1383. + }
  1384. +
  1385. + // LED flashing only in HDLC mode
  1386. + if(!transp_mode)
  1387. + {
  1388. + if(fifon==HFCUSB_B1_RX) handle_led(hfc,LED_B1_DATA);
  1389. + if(fifon==HFCUSB_B2_RX) handle_led(hfc,LED_B2_DATA);
  1390. + }
  1391. +}
  1392. +
  1393. +/***********************************************/
  1394. +/* receive completion routine for all rx fifos */
  1395. +/***********************************************/
  1396. +static void rx_complete(struct urb *urb)
  1397. +{
  1398. + int len;
  1399. + __u8 *buf;
  1400. + usb_fifo *fifo = (usb_fifo *) urb->context; /* pointer to our fifo */
  1401. + hfcusb_data *hfc = fifo->hfc;
  1402. +
  1403. + urb->dev = hfc->dev; /* security init */
  1404. +
  1405. + if((!fifo->active) || (urb->status)) {
  1406. +#ifdef VERBOSE_USB_DEBUG
  1407. + printk(KERN_INFO "HFC-USB: RX-Fifo %i is going down (%i)\n", fifo->fifonum, urb->status);
  1408. +#endif
  1409. + fifo->urb->interval = 0; /* cancel automatic rescheduling */
  1410. + if(fifo->skbuff) {
  1411. + dev_kfree_skb_any(fifo->skbuff);
  1412. + fifo->skbuff = NULL;
  1413. }
  1414. + return;
  1415. }
  1416. - fifo->rx_offset = (urb->actual_length < fifo->usb_maxlen) ? 2 : 0;
  1417. -} /* rx_complete */
  1418. +
  1419. + len=urb->actual_length;
  1420. + buf=fifo->buffer;
  1421. +
  1422. + if(fifo->last_urblen!=fifo->usb_packet_maxlen) {
  1423. + // the threshold mask is in the 2nd status byte
  1424. + hfc->threshold_mask=buf[1];
  1425. + // the S0 state is in the upper half of the 1st status byte
  1426. + state_handler(hfc,buf[0] >> 4);
  1427. + // if we have more than the 2 status bytes -> collect data
  1428. + if(len>2) collect_rx_frame(fifo,buf+2,urb->actual_length-2,buf[0]&1);
  1429. + } else
  1430. + collect_rx_frame(fifo,buf,urb->actual_length,0);
  1431. +
  1432. + fifo->last_urblen=urb->actual_length;
  1433. +
  1434. +
  1435. +} /* rx_complete */
  1436. +
  1437. +
  1438. /***************************************************/
  1439. /* start the interrupt transfer for the given fifo */
  1440. /***************************************************/
  1441. -static void
  1442. -start_rx_fifo(usb_fifo * fifo)
  1443. +static void start_int_fifo(usb_fifo * fifo)
  1444. {
  1445. - if (fifo->buff)
  1446. - return; /* still active */
  1447. - if (!
  1448. - (fifo->buff =
  1449. - dev_alloc_skb(fifo->max_size + (fifo->transmode ? 0 : 3))))
  1450. - return;
  1451. - fifo->act_ptr = fifo->buff->data;
  1452. - FILL_INT_URB(&fifo->urb, fifo->hfc->dev, fifo->pipe, fifo->buffer,
  1453. - fifo->usb_maxlen, rx_complete, fifo, fifo->intervall);
  1454. - fifo->next_complete = 0;
  1455. - fifo->rx_offset = 2;
  1456. - fifo->active = 1; /* must be marked active */
  1457. - fifo->hfc->active_fifos |= fifo->fifo_mask;
  1458. - if (usb_submit_urb(&fifo->urb)) {
  1459. + int errcode;
  1460. +
  1461. +#ifdef VERBOSE_USB_DEBUG
  1462. + printk(KERN_INFO "HFC-USB: starting intr IN fifo:%d\n", fifo->fifonum);
  1463. +#endif
  1464. + if (!fifo->urb) {
  1465. + fifo->urb = usb_alloc_urb(0);
  1466. + if (!fifo->urb)
  1467. + return;
  1468. + }
  1469. + usb_fill_int_urb(fifo->urb, fifo->hfc->dev, fifo->pipe, fifo->buffer,
  1470. + fifo->usb_packet_maxlen, rx_complete, fifo, fifo->intervall);
  1471. + fifo->active = 1; /* must be marked active */
  1472. + errcode = usb_submit_urb(fifo->urb);
  1473. +
  1474. + if(errcode)
  1475. + {
  1476. + printk(KERN_INFO "HFC-USB: submit URB error(start_int_info): status:%i\n", errcode);
  1477. fifo->active = 0;
  1478. - fifo->hfc->active_fifos &= ~fifo->fifo_mask;
  1479. - dev_kfree_skb_any(fifo->buff);
  1480. - fifo->buff = NULL;
  1481. + fifo->skbuff = NULL;
  1482. }
  1483. -} /* start_rx_fifo */
  1484. +} /* start_int_fifo */
  1485. -/***************************************************************/
  1486. -/* control completion routine handling background control cmds */
  1487. -/***************************************************************/
  1488. -static void
  1489. -ctrl_complete(purb_t urb)
  1490. +/*****************************/
  1491. +/* set the B-channel mode */
  1492. +/*****************************/
  1493. +static void set_hfcmode(hfcusb_data *hfc,int channel,int mode)
  1494. {
  1495. - hfcusb_data *hfc = (hfcusb_data *) urb->context;
  1496. + __u8 val,idx_table[2]={0,2};
  1497. - urb->dev = hfc->dev;
  1498. - if (hfc->ctrl_cnt) {
  1499. - switch (hfc->ctrl_buff[hfc->ctrl_out_idx].hfc_reg) {
  1500. - case HFCUSB_FIFO:
  1501. - hfc->ctrl_fifo =
  1502. - hfc->ctrl_buff[hfc->ctrl_out_idx].
  1503. - reg_val;
  1504. - break;
  1505. - case HFCUSB_F_USAGE:
  1506. - if (!hfc->dfifo_fill) {
  1507. - fill_tx_urb(hfc->fifos +
  1508. - HFCUSB_D_TX);
  1509. - if (hfc->fifos[HFCUSB_D_TX].buff)
  1510. - usb_submit_urb(&hfc->
  1511. - fifos
  1512. - [HFCUSB_D_TX].
  1513. - urb);
  1514. - } else {
  1515. - queue_control_request(hfc,
  1516. - HFCUSB_FIFO,
  1517. - HFCUSB_D_TX);
  1518. - queue_control_request(hfc,
  1519. - HFCUSB_F_USAGE,
  1520. - 0);
  1521. - }
  1522. - break;
  1523. - case HFCUSB_SCTRL_R:
  1524. - switch (hfc->ctrl_fifo) {
  1525. - case HFCUSB_B1_RX:
  1526. - if (hfc->bch_enables & 1)
  1527. - start_rx_fifo(hfc->
  1528. - fifos
  1529. - +
  1530. - HFCUSB_B1_RX);
  1531. - break;
  1532. - case HFCUSB_B2_RX:
  1533. - if (hfc->bch_enables & 2)
  1534. - start_rx_fifo(hfc->
  1535. - fifos
  1536. - +
  1537. - HFCUSB_B2_RX);
  1538. - break;
  1539. - }
  1540. - if (hfc->bch_enables & 3)
  1541. - hfc->led_req |= LED_BCH;
  1542. - else
  1543. - hfc->led_req &= ~LED_BCH;
  1544. - break;
  1545. - case HFCUSB_P_DATA:
  1546. - hfc->led_act =
  1547. - hfc->ctrl_buff[hfc->ctrl_out_idx].
  1548. - reg_val;
  1549. - break;
  1550. - }
  1551. - hfc->ctrl_cnt--; /* decrement actual count */
  1552. - if (++hfc->ctrl_out_idx >= HFC_CTRL_BUFSIZE)
  1553. - hfc->ctrl_out_idx = 0; /* pointer wrap */
  1554. - ctrl_start_transfer(hfc); /* start next transfer */
  1555. +#ifdef VERBOSE_ISDN_DEBUG
  1556. + printk (KERN_INFO "HFC-USB: setting channel %d to mode %d\n",channel,mode);
  1557. +#endif
  1558. +
  1559. + hfc->b_mode[channel]=mode;
  1560. +
  1561. + // setup CON_HDLC
  1562. + val=0;
  1563. + if(mode!=L1_MODE_NULL) val=8; // enable fifo?
  1564. + if(mode==L1_MODE_TRANS) val|=2; // set transparent bit
  1565. +
  1566. + queue_control_request(hfc,HFCUSB_FIFO,idx_table[channel],1); // set FIFO to transmit register
  1567. + queue_control_request(hfc,HFCUSB_CON_HDLC,val,1);
  1568. + queue_control_request(hfc,HFCUSB_INC_RES_F,2,1); // reset fifo
  1569. +
  1570. + queue_control_request(hfc,HFCUSB_FIFO,idx_table[channel]+1,1); // set FIFO to receive register
  1571. + queue_control_request(hfc,HFCUSB_CON_HDLC,val,1);
  1572. + queue_control_request(hfc,HFCUSB_INC_RES_F,2,1); // reset fifo
  1573. +
  1574. + val=0x40;
  1575. + if(hfc->b_mode[0]) val|=1;
  1576. + if(hfc->b_mode[1]) val|=2;
  1577. + queue_control_request(hfc,HFCUSB_SCTRL,val,1);
  1578. +
  1579. + val=0;
  1580. + if(hfc->b_mode[0]) val|=1;
  1581. + if(hfc->b_mode[1]) val|=2;
  1582. + queue_control_request(hfc,HFCUSB_SCTRL_R,val,1);
  1583. +
  1584. + if(mode==L1_MODE_NULL)
  1585. + {
  1586. + if(channel) handle_led(hfc,LED_B2_OFF);
  1587. + else handle_led(hfc,LED_B1_OFF);
  1588. }
  1589. -} /* ctrl_complete */
  1590. + else
  1591. + {
  1592. + if(channel) handle_led(hfc,LED_B2_ON);
  1593. + else handle_led(hfc,LED_B1_ON);
  1594. + }
  1595. +}
  1596. -/*****************************************/
  1597. -/* Layer 1 + D channel access from HiSax */
  1598. -/*****************************************/
  1599. -static void
  1600. -hfcusb_l1_access(void *drvarg, int pr, void *arg)
  1601. -{
  1602. - hfcusb_data *hfc = (hfcusb_data *) drvarg;
  1603. -
  1604. - switch (pr) {
  1605. - case (PH_DATA | REQUEST):
  1606. - case (PH_PULL | INDICATION):
  1607. - skb_queue_tail(hfc->regd.dsq,
  1608. - (struct sk_buff *) arg);
  1609. - if (!hfc->fifos[HFCUSB_D_TX].active
  1610. - && !hfc->dfifo_fill) {
  1611. - fill_tx_urb(hfc->fifos + HFCUSB_D_TX);
  1612. - hfc->active_fifos |=
  1613. - hfc->fifos[HFCUSB_D_TX].fifo_mask;
  1614. - usb_submit_urb(&hfc->fifos[HFCUSB_D_TX].
  1615. - urb);
  1616. - }
  1617. - break;
  1618. - case (PH_ACTIVATE | REQUEST):
  1619. - switch (hfc->l1_state) {
  1620. - case 6:
  1621. - case 8:
  1622. - hfc->regd.dch_l1l2(hfc->regd.arg_hisax,
  1623. - (PH_DEACTIVATE |
  1624. - INDICATION), NULL);
  1625. +/*
  1626. + --------------------------------------------------------------------------------------
  1627. + from here : hisax_if callback routines :
  1628. + - void hfc_usb_d_l2l1(struct hisax_if *hisax_d_if, int pr, void *arg) {
  1629. - break;
  1630. - case 7:
  1631. - hfc->regd.dch_l1l2(hfc->regd.arg_hisax,
  1632. - (PH_ACTIVATE |
  1633. - INDICATION), NULL);
  1634. + l1 to l2 routines :
  1635. + - static void hfc_usb_l1l2(hfcusb_data * hfc)
  1636. - break;
  1637. - default:
  1638. - queue_control_request(hfc, HFCUSB_STATES, 0x60); /* start activation */
  1639. - hfc->t3_timer.expires =
  1640. - jiffies + (HFC_TIMER_T3 * HZ) / 1000;
  1641. - if (!timer_pending(&hfc->t3_timer))
  1642. - add_timer(&hfc->t3_timer);
  1643. - break;
  1644. - }
  1645. - break;
  1646. +*/
  1647. - case (PH_DEACTIVATE | REQUEST):
  1648. - queue_control_request(hfc, HFCUSB_STATES, 0x40); /* start deactivation */
  1649. - break;
  1650. - default:
  1651. - printk(KERN_INFO "unknown hfcusb l1_access 0x%x\n",
  1652. - pr);
  1653. - break;
  1654. - }
  1655. -} /* hfcusb_l1_access */
  1656. -
  1657. -/*******************************/
  1658. -/* B channel access from HiSax */
  1659. -/*******************************/
  1660. -static void
  1661. -hfcusb_bch_access(void *drvarg, int chan, int pr, void *arg)
  1662. -{
  1663. - hfcusb_data *hfc = (hfcusb_data *) drvarg;
  1664. - usb_fifo *fifo = hfc->fifos + (chan ? HFCUSB_B2_TX : HFCUSB_B1_TX);
  1665. - long flags;
  1666. -
  1667. - switch (pr) {
  1668. - case (PH_DATA | REQUEST):
  1669. - case (PH_PULL | INDICATION):
  1670. - save_flags(flags);
  1671. - cli();
  1672. - if (!fifo->active) {
  1673. - fill_tx_urb(fifo);
  1674. - hfc->active_fifos |= fifo->fifo_mask;
  1675. - usb_submit_urb(&fifo->urb);
  1676. - }
  1677. - restore_flags(flags);
  1678. - break;
  1679. - case (PH_ACTIVATE | REQUEST):
  1680. - if (!((int) arg)) {
  1681. - hfc->bch_enables &= ~(1 << chan);
  1682. - if (fifo->active) {
  1683. - fifo->active = 0;
  1684. - usb_unlink_urb(&fifo->urb);
  1685. +void hfc_usb_l2l1(struct hisax_if *my_hisax_if, int pr, void *arg)
  1686. +{
  1687. + usb_fifo *fifo = my_hisax_if->priv;
  1688. + hfcusb_data *hfc = fifo->hfc;
  1689. +
  1690. + switch (pr) {
  1691. + case PH_ACTIVATE | REQUEST:
  1692. + if(fifo->fifonum==HFCUSB_D_TX)
  1693. + {
  1694. +#ifdef VERBOSE_ISDN_DEBUG
  1695. + printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_ACTIVATE | REQUEST\n");
  1696. +#endif
  1697. + queue_control_request(hfc, HFCUSB_STATES,0x60,1); /* make activation */
  1698. + hfc->t3_timer.expires = jiffies + (HFC_TIMER_T3 * HZ) / 1000;
  1699. + if(!timer_pending(&hfc->t3_timer)) add_timer(&hfc->t3_timer);
  1700. }
  1701. - save_flags(flags);
  1702. - cli();
  1703. - queue_control_request(hfc, HFCUSB_FIFO,
  1704. - fifo->fifonum);
  1705. - queue_control_request(hfc,
  1706. - HFCUSB_INC_RES_F, 2);
  1707. - queue_control_request(hfc, HFCUSB_CON_HDLC,
  1708. - 9);
  1709. - queue_control_request(hfc, HFCUSB_SCTRL,
  1710. - 0x40 +
  1711. - hfc->bch_enables);
  1712. - queue_control_request(hfc, HFCUSB_SCTRL_R,
  1713. - hfc->bch_enables);
  1714. - restore_flags(flags);
  1715. - fifo++;
  1716. - if (fifo->active) {
  1717. - fifo->active = 0;
  1718. - usb_unlink_urb(&fifo->urb);
  1719. + else
  1720. + {
  1721. +#ifdef VERBOSE_ISDN_DEBUG
  1722. + printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_ACTIVATE | REQUEST\n");
  1723. +#endif
  1724. + set_hfcmode(hfc,(fifo->fifonum==HFCUSB_B1_TX) ? 0 : 1 ,(int)arg);
  1725. + fifo->hif->l1l2(fifo->hif,PH_ACTIVATE | INDICATION, NULL);
  1726. }
  1727. - return; /* fifo deactivated */
  1728. - }
  1729. - fifo->transmode = ((int) arg == L1_MODE_TRANS);
  1730. - fifo->max_size =
  1731. - ((fifo->transmode) ? fifo->
  1732. - usb_maxlen : MAX_BCH_SIZE);
  1733. - (fifo + 1)->transmode = fifo->transmode;
  1734. - (fifo + 1)->max_size = fifo->max_size;
  1735. - hfc->bch_enables |= (1 << chan);
  1736. - save_flags(flags);
  1737. - cli();
  1738. - queue_control_request(hfc, HFCUSB_FIFO,
  1739. - fifo->fifonum);
  1740. - queue_control_request(hfc, HFCUSB_CON_HDLC,
  1741. - ((!fifo->
  1742. - transmode) ? 9 : 11));
  1743. - queue_control_request(hfc, HFCUSB_INC_RES_F, 2);
  1744. - queue_control_request(hfc, HFCUSB_SCTRL,
  1745. - 0x40 + hfc->bch_enables);
  1746. - if ((int) arg == L1_MODE_HDLC)
  1747. - queue_control_request(hfc, HFCUSB_CON_HDLC,
  1748. - 8);
  1749. - queue_control_request(hfc, HFCUSB_FIFO,
  1750. - fifo->fifonum + 1);
  1751. - queue_control_request(hfc, HFCUSB_CON_HDLC,
  1752. - ((!fifo->
  1753. - transmode) ? 8 : 10));
  1754. - queue_control_request(hfc, HFCUSB_INC_RES_F, 2);
  1755. - queue_control_request(hfc, HFCUSB_SCTRL_R,
  1756. - hfc->bch_enables);
  1757. - restore_flags(flags);
  1758. -
  1759. - break;
  1760. -
  1761. - default:
  1762. - printk(KERN_INFO
  1763. - "unknown hfcusb bch_access chan %d 0x%x\n",
  1764. - chan, pr);
  1765. - break;
  1766. - }
  1767. -} /* hfcusb_bch_access */
  1768. + break;
  1769. + case PH_DEACTIVATE | REQUEST:
  1770. + if(fifo->fifonum==HFCUSB_D_TX)
  1771. + {
  1772. +#ifdef VERBOSE_ISDN_DEBUG
  1773. + printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_DEACTIVATE | REQUEST\n");
  1774. +#endif
  1775. + printk (KERN_INFO "HFC-USB: ISDN TE device should not deativate...\n");
  1776. + }
  1777. + else
  1778. + {
  1779. +#ifdef VERBOSE_ISDN_DEBUG
  1780. + printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_DEACTIVATE | REQUEST\n");
  1781. +#endif
  1782. + set_hfcmode(hfc,(fifo->fifonum==HFCUSB_B1_TX) ? 0 : 1 ,(int)L1_MODE_NULL);
  1783. + fifo->hif->l1l2(fifo->hif,PH_DEACTIVATE | INDICATION, NULL);
  1784. + }
  1785. + break;
  1786. + case PH_DATA | REQUEST:
  1787. + if(fifo->skbuff && fifo->delete_flg)
  1788. + {
  1789. + dev_kfree_skb_any(fifo->skbuff);
  1790. + //printk(KERN_INFO "skbuff=NULL on fifo:%d\n",fifo->fifonum);
  1791. + fifo->skbuff = NULL;
  1792. + fifo->delete_flg=FALSE;
  1793. + }
  1794. +
  1795. + fifo->skbuff=arg; // we have a new buffer
  1796. +
  1797. + //if(fifo->fifonum==HFCUSB_D_TX) printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_DATA | REQUEST\n");
  1798. + //else printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_DATA | REQUEST\n");
  1799. + break;
  1800. + default:
  1801. + printk (KERN_INFO "HFC_USB: hfc_usb_d_l2l1: unkown state : %#x\n", pr);
  1802. + break;
  1803. + }
  1804. +}
  1805. +
  1806. +// valid configurations
  1807. +#define CNF_4INT3ISO 1 // 4 INT IN, 3 ISO OUT
  1808. +#define CNF_3INT3ISO 2 // 3 INT IN, 3 ISO OUT
  1809. +#define CNF_4ISO3ISO 3 // 4 ISO IN, 3 ISO OUT
  1810. +#define CNF_3ISO3ISO 4 // 3 ISO IN, 3 ISO OUT
  1811. +
  1812. +
  1813. +/*
  1814. + --------------------------------------------------------------------------------------
  1815. + From here on USB initialization and deactivation related routines are implemented :
  1816. +
  1817. + - hfc_usb_init :
  1818. + is the main Entry Point for the USB Subsystem when the device get plugged
  1819. + in. This function calls usb_register with usb_driver as parameter.
  1820. + Here, further entry points for probing (hfc_usb_probe) and disconnecting
  1821. + the device (hfc_usb_disconnect) are published, as the id_table
  1822. +
  1823. + - hfc_usb_probe
  1824. + this function is called by the usb subsystem, and steps through the alternate
  1825. + settings of the currently plugged in device to detect all Endpoints needed to
  1826. + run an ISDN TA.
  1827. + Needed EndPoints are
  1828. + 3 (+1) IntIn EndPoints (D-in, E-in, B1-in, B2-in, (E-in)) or
  1829. + 3 (+1) Isochron In Endpoints (D-out, B1-out, B2-out) and 3 IsoOut Endpoints
  1830. + The currently used transfer mode of on the Out-Endpoints will be stored in
  1831. + hfc->usb_transfer_mode and is either USB_INT or USB_ISO
  1832. + When a valid alternate setting could be found, the usb_init (see blow)
  1833. + function is called
  1834. +
  1835. + - usb_init
  1836. + Here, the HFC_USB Chip itself gets initialized and the USB framework to send/receive
  1837. + Data to/from the several EndPoints are initialized:
  1838. + The E- and D-Channel Int-In chain gets started
  1839. + The IsoChain for the Iso-Out traffic get started
  1840. +
  1841. + - hfc_usb_disconnect
  1842. + this function is called by the usb subsystem and has to free all resources
  1843. + and stop all usb traffic to allow a proper hotplugging disconnect.
  1844. +
  1845. +*/
  1846. /***************************************************************************/
  1847. /* usb_init is called once when a new matching device is detected to setup */
  1848. -/* main parmeters. It registers the driver at the main hisax module. */
  1849. +/* main parameters. It registers the driver at the main hisax module. */
  1850. /* on success 0 is returned. */
  1851. /***************************************************************************/
  1852. -static int
  1853. -usb_init(hfcusb_data * hfc)
  1854. +static int usb_init(hfcusb_data * hfc)
  1855. {
  1856. usb_fifo *fifo;
  1857. - int i;
  1858. + int i, err;
  1859. u_char b;
  1860. -
  1861. + struct hisax_b_if *p_b_if[2];
  1862. +
  1863. /* check the chip id */
  1864. - if ((Read_hfc(hfc, HFCUSB_CHIP_ID, &b) != 1) ||
  1865. - (b != HFCUSB_CHIPID)) {
  1866. + printk(KERN_INFO "HFCUSB_CHIP_ID begin\n");
  1867. + if (read_usb(hfc, HFCUSB_CHIP_ID, &b) != 1) {
  1868. + printk(KERN_INFO "HFC-USB: cannot read chip id\n");
  1869. + return(1);
  1870. + }
  1871. + printk(KERN_INFO "HFCUSB_CHIP_ID %x\n", b);
  1872. + if (b != HFCUSB_CHIPID) {
  1873. printk(KERN_INFO "HFC-USB: Invalid chip id 0x%02x\n", b);
  1874. - return (1);
  1875. + return(1);
  1876. }
  1877. /* first set the needed config, interface and alternate */
  1878. - usb_set_configuration(hfc->dev, 1);
  1879. - usb_set_interface(hfc->dev, hfc->if_used, hfc->alt_used);
  1880. + printk(KERN_INFO "usb_init 1\n");
  1881. +// usb_set_configuration(hfc->dev, 1);
  1882. + printk(KERN_INFO "usb_init 2\n");
  1883. + err = usb_set_interface(hfc->dev, hfc->if_used, hfc->alt_used);
  1884. + printk(KERN_INFO "usb_init usb_set_interface return %d\n", err);
  1885. + /* now we initialize the chip */
  1886. + write_usb(hfc, HFCUSB_CIRM, 8); // do reset
  1887. + write_usb(hfc, HFCUSB_CIRM, 0x10); // aux = output, reset off
  1888. - /* init the led state request */
  1889. - hfc->led_req = LED_DRIVER;
  1890. + // set USB_SIZE to match the the wMaxPacketSize for INT or BULK transfers
  1891. + write_usb(hfc, HFCUSB_USB_SIZE,(hfc->packet_size/8) | ((hfc->packet_size/8) << 4));
  1892. - /* now we initialise the chip */
  1893. - Write_hfc(hfc, HFCUSB_CIRM, 0x10); /* aux = output, reset off */
  1894. - Write_hfc(hfc, HFCUSB_P_DATA, 0); /* leds = off */
  1895. - Write_hfc(hfc, HFCUSB_USB_SIZE,
  1896. - (hfc->fifos[HFCUSB_B1_TX].usb_maxlen >> 3) |
  1897. - ((hfc->fifos[HFCUSB_B1_RX].usb_maxlen >> 3) << 4));
  1898. + // set USB_SIZE_I to match the the wMaxPacketSize for ISO transfers
  1899. + write_usb(hfc, HFCUSB_USB_SIZE_I, hfc->iso_packet_size);
  1900. /* enable PCM/GCI master mode */
  1901. - Write_hfc(hfc, HFCUSB_MST_MODE1, 0); /* set default values */
  1902. - Write_hfc(hfc, HFCUSB_MST_MODE0, 1); /* enable master mode */
  1903. + write_usb(hfc, HFCUSB_MST_MODE1, 0); /* set default values */
  1904. + write_usb(hfc, HFCUSB_MST_MODE0, 1); /* enable master mode */
  1905. /* init the fifos */
  1906. - Write_hfc(hfc, HFCUSB_F_THRES, (HFCUSB_TX_THRESHOLD >> 3) |
  1907. - ((HFCUSB_RX_THRESHOLD >> 3) << 4));
  1908. + write_usb(hfc, HFCUSB_F_THRES, (HFCUSB_TX_THRESHOLD/8) |((HFCUSB_RX_THRESHOLD/8) << 4));
  1909. - for (i = 0, fifo = hfc->fifos + i; i < HFCUSB_NUM_FIFOS;
  1910. - i++, fifo++) {
  1911. - Write_hfc(hfc, HFCUSB_FIFO, i); /* select the desired fifo */
  1912. -
  1913. - fifo->transmode = 0; /* hdlc mode selected */
  1914. - fifo->buff = NULL; /* init buffer pointer */
  1915. - fifo->max_size =
  1916. - (i <= HFCUSB_B2_RX) ? MAX_BCH_SIZE : MAX_DFRAME_LEN;
  1917. - Write_hfc(hfc, HFCUSB_HDLC_PAR, ((i <= HFCUSB_B2_RX) ? 0 : 2)); /* data length */
  1918. - Write_hfc(hfc, HFCUSB_CON_HDLC, ((i & 1) ? 0x08 : 0x09)); /* rx hdlc, tx fill 1 */
  1919. - Write_hfc(hfc, HFCUSB_INC_RES_F, 2); /* reset the fifo */
  1920. - }
  1921. -
  1922. - Write_hfc(hfc, HFCUSB_CLKDEL, 0x0f); /* clock delay value */
  1923. - Write_hfc(hfc, HFCUSB_STATES, 3 | 0x10); /* set deactivated mode */
  1924. - Write_hfc(hfc, HFCUSB_STATES, 3); /* enable state machine */
  1925. + fifo = hfc->fifos;
  1926. + for(i = 0; i < HFCUSB_NUM_FIFOS; i++)
  1927. + {
  1928. + write_usb(hfc, HFCUSB_FIFO, i); /* select the desired fifo */
  1929. + fifo[i].skbuff = NULL; /* init buffer pointer */
  1930. + fifo[i].max_size = (i <= HFCUSB_B2_RX) ? MAX_BCH_SIZE : MAX_DFRAME_LEN;
  1931. + fifo[i].last_urblen=0;
  1932. + write_usb(hfc, HFCUSB_HDLC_PAR, ((i <= HFCUSB_B2_RX) ? 0 : 2)); // set 2 bit for D- & E-channel
  1933. + write_usb(hfc, HFCUSB_CON_HDLC, ((i==HFCUSB_D_TX) ? 0x09 : 0x08)); // rx hdlc, enable IFF for D-channel
  1934. + write_usb(hfc, HFCUSB_INC_RES_F, 2); /* reset the fifo */
  1935. + }
  1936. - Write_hfc(hfc, HFCUSB_SCTRL_R, 0); /* disable both B receivers */
  1937. - Write_hfc(hfc, HFCUSB_SCTRL, 0x40); /* disable B transmitters + cap mode */
  1938. + write_usb(hfc, HFCUSB_CLKDEL, 0x0f); /* clock delay value */
  1939. + write_usb(hfc, HFCUSB_STATES, 3 | 0x10); /* set deactivated mode */
  1940. + write_usb(hfc, HFCUSB_STATES, 3); /* enable state machine */
  1941. +
  1942. + write_usb(hfc, HFCUSB_SCTRL_R, 0); /* disable both B receivers */
  1943. + write_usb(hfc, HFCUSB_SCTRL, 0x40); /* disable B transmitters + capacitive mode */
  1944. +
  1945. + // set both B-channel to not connected
  1946. + hfc->b_mode[0]=L1_MODE_NULL;
  1947. + hfc->b_mode[1]=L1_MODE_NULL;
  1948. +
  1949. + hfc->l1_activated=FALSE;
  1950. + hfc->led_state=0;
  1951. + hfc->led_new_data=0;
  1952. - /* init the l1 timer */
  1953. + /* init the t3 timer */
  1954. init_timer(&hfc->t3_timer);
  1955. hfc->t3_timer.data = (long) hfc;
  1956. - hfc->t3_timer.function = (void *) l1_timer_expire;
  1957. + hfc->t3_timer.function = (void *) l1_timer_expire_t3;
  1958. + /* init the t4 timer */
  1959. + init_timer(&hfc->t4_timer);
  1960. hfc->t4_timer.data = (long) hfc;
  1961. - hfc->t4_timer.function = (void *) l1_timer_expire;
  1962. - hfc->l1_tq.routine = (void *) (void *) usb_l1d_bh;
  1963. - hfc->l1_tq.sync = 0;
  1964. - hfc->l1_tq.data = hfc;
  1965. -
  1966. - /* init the background control machinery */
  1967. - hfc->ctrl_read.requesttype = 0xc0;
  1968. - hfc->ctrl_read.request = 1;
  1969. - hfc->ctrl_read.length = 1;
  1970. - hfc->ctrl_write.requesttype = 0x40;
  1971. - hfc->ctrl_write.request = 0;
  1972. - hfc->ctrl_write.length = 0;
  1973. - FILL_CONTROL_URB(&hfc->ctrl_urb, hfc->dev, hfc->ctrl_out_pipe,
  1974. - (u_char *) & hfc->ctrl_write, NULL, 0,
  1975. - ctrl_complete, hfc);
  1976. -
  1977. - /* init the TX-urbs */
  1978. - fifo = hfc->fifos + HFCUSB_D_TX;
  1979. - FILL_BULK_URB(&fifo->urb, hfc->dev, fifo->pipe,
  1980. - (u_char *) fifo->buffer, 0, tx_complete, fifo);
  1981. - fifo = hfc->fifos + HFCUSB_B1_TX;
  1982. - FILL_BULK_URB(&fifo->urb, hfc->dev, fifo->pipe,
  1983. - (u_char *) fifo->buffer, 0, tx_complete, fifo);
  1984. - fifo = hfc->fifos + HFCUSB_B2_TX;
  1985. - FILL_BULK_URB(&fifo->urb, hfc->dev, fifo->pipe,
  1986. - (u_char *) fifo->buffer, 0, tx_complete, fifo);
  1987. -
  1988. - /* init the E-buffer */
  1989. - skb_queue_head_init(&hfc->regd.erq);
  1990. -
  1991. - /* now register ourself at hisax */
  1992. - hfc->regd.version = HISAX_LOAD_VERSION; /* set our version */
  1993. - hfc->regd.cmd = HISAX_LOAD_REGISTER; /* register command */
  1994. - hfc->regd.argl1 = (void *) hfc; /* argument for our local routine */
  1995. - hfc->regd.dch_l2l1 = hfcusb_l1_access;
  1996. - hfc->regd.bch_l2l1 = hfcusb_bch_access;
  1997. - hfc->regd.drvname = "hfc_usb";
  1998. - if (hisax_register_hfcusb(&hfc->regd)) {
  1999. - printk(KERN_INFO "HFC-USB failed to register at hisax\n");
  2000. - Write_hfc(hfc, HFCUSB_CIRM, 0x08); /* aux = input, reset on */
  2001. - return (1);
  2002. - }
  2003. -
  2004. - /* startup the D- and E-channel fifos */
  2005. - start_rx_fifo(hfc->fifos + HFCUSB_D_RX); /* D-fifo */
  2006. - if (hfc->fifos[HFCUSB_PCM_RX].pipe)
  2007. - start_rx_fifo(hfc->fifos + HFCUSB_PCM_RX); /* E-fifo */
  2008. + hfc->t4_timer.function = (void *) l1_timer_expire_t4;
  2009. + /* init the led timer */
  2010. + init_timer(&hfc->led_timer);
  2011. + hfc->led_timer.data = (long) hfc;
  2012. + hfc->led_timer.function = (void *) led_timer;
  2013. + // trigger 4 hz led timer
  2014. + hfc->led_timer.expires = jiffies + (LED_TIME * HZ) / 1000;
  2015. + if(!timer_pending(&hfc->led_timer)) add_timer(&hfc->led_timer);
  2016. +
  2017. + // init the background machinery for control requests
  2018. + hfc->ctrl_read.bRequestType = 0xc0;
  2019. + hfc->ctrl_read.bRequest = 1;
  2020. + hfc->ctrl_read.wLength = 1;
  2021. + hfc->ctrl_write.bRequestType = 0x40;
  2022. + hfc->ctrl_write.bRequest = 0;
  2023. + hfc->ctrl_write.wLength = 0;
  2024. + usb_fill_control_urb(hfc->ctrl_urb, hfc->dev, hfc->ctrl_out_pipe,(u_char *) & hfc->ctrl_write, NULL, 0, ctrl_complete, hfc);
  2025. +
  2026. + /* Init All Fifos */
  2027. + for(i = 0; i < HFCUSB_NUM_FIFOS; i++)
  2028. + {
  2029. + hfc->fifos[i].iso[0].purb = NULL;
  2030. + hfc->fifos[i].iso[1].purb = NULL;
  2031. + hfc->fifos[i].active = 0;
  2032. + }
  2033. +
  2034. + // register like Germaschewski :
  2035. + hfc->d_if.owner = THIS_MODULE;
  2036. + hfc->d_if.ifc.priv = &hfc->fifos[HFCUSB_D_TX];
  2037. + hfc->d_if.ifc.l2l1 = hfc_usb_l2l1;
  2038. +
  2039. + for (i=0; i<2; i++)
  2040. + {
  2041. + hfc->b_if[i].ifc.priv = &hfc->fifos[HFCUSB_B1_TX+i*2];
  2042. + hfc->b_if[i].ifc.l2l1 = hfc_usb_l2l1;
  2043. + p_b_if[i] = &hfc->b_if[i];
  2044. + }
  2045. +
  2046. + hfc->protocol = 2; /* default EURO ISDN, should be a module_param */
  2047. + hisax_register(&hfc->d_if, p_b_if, "hfc_usb", hfc->protocol);
  2048. +
  2049. + for (i=0; i<4; i++)
  2050. + hfc->fifos[i].hif=&p_b_if[i/2]->ifc;
  2051. + for (i=4; i<8; i++)
  2052. + hfc->fifos[i].hif=&hfc->d_if.ifc;
  2053. +
  2054. + // 3 (+1) INT IN + 3 ISO OUT
  2055. + if(hfc->cfg_used == CNF_3INT3ISO || hfc->cfg_used == CNF_4INT3ISO)
  2056. + {
  2057. + start_int_fifo(hfc->fifos + HFCUSB_D_RX); // Int IN D-fifo
  2058. + if(hfc->fifos[HFCUSB_PCM_RX].pipe) start_int_fifo(hfc->fifos + HFCUSB_PCM_RX); // E-fifo
  2059. + start_int_fifo(hfc->fifos + HFCUSB_B1_RX); // Int IN B1-fifo
  2060. + start_int_fifo(hfc->fifos + HFCUSB_B2_RX); // Int IN B2-fifo
  2061. + }
  2062. +
  2063. + // 3 (+1) ISO IN + 3 ISO OUT
  2064. + if(hfc->cfg_used==CNF_3ISO3ISO || hfc->cfg_used==CNF_4ISO3ISO)
  2065. + {
  2066. + start_isoc_chain(hfc->fifos + HFCUSB_D_RX, ISOC_PACKETS_D, rx_iso_complete,16);
  2067. + if(hfc->fifos[HFCUSB_PCM_RX].pipe) start_isoc_chain(hfc->fifos + HFCUSB_PCM_RX, ISOC_PACKETS_D, rx_iso_complete,16);
  2068. + start_isoc_chain(hfc->fifos + HFCUSB_B1_RX, ISOC_PACKETS_B, rx_iso_complete,16);
  2069. + start_isoc_chain(hfc->fifos + HFCUSB_B2_RX, ISOC_PACKETS_B, rx_iso_complete,16);
  2070. + }
  2071. +
  2072. + start_isoc_chain(hfc->fifos + HFCUSB_D_TX, ISOC_PACKETS_D, tx_iso_complete,1);
  2073. + start_isoc_chain(hfc->fifos + HFCUSB_B1_TX, ISOC_PACKETS_B, tx_iso_complete,1);
  2074. + start_isoc_chain(hfc->fifos + HFCUSB_B2_TX, ISOC_PACKETS_B, tx_iso_complete,1);
  2075. +
  2076. + handle_led(hfc,LED_POWER_ON);
  2077. +
  2078. + return(0);
  2079. +} /* usb_init */
  2080. +
  2081. +
  2082. +/****************************************/
  2083. +/* data defining the devices to be used */
  2084. +/****************************************/
  2085. +// static __devinitdata const struct usb_device_id hfc_usb_idtab[3] = {
  2086. +static struct usb_device_id hfc_usb_idtab[] = {
  2087. + {USB_DEVICE(0x7b0, 0x0007)}, /* Billion USB TA 2 */
  2088. + {USB_DEVICE(0x742, 0x2008)}, /* Stollmann USB TA */
  2089. + {USB_DEVICE(0x959, 0x2bd0)}, /* Colognechip USB eval TA */
  2090. + {USB_DEVICE(0x8e3, 0x0301)}, /* OliTec ISDN USB */
  2091. + {USB_DEVICE(0x675, 0x1688)}, /* DrayTec ISDN USB */
  2092. + {USB_DEVICE(0x7fa, 0x0846)}, /* Bewan ISDN USB TA */
  2093. + {} /* end with an all-zeroes entry */
  2094. +};
  2095. +
  2096. +MODULE_AUTHOR("Peter Sprenger ([email protected])/Martin Bachem ([email protected])");
  2097. +MODULE_DESCRIPTION("HFC I4L USB driver");
  2098. +MODULE_DEVICE_TABLE(usb, hfc_usb_idtab);
  2099. +MODULE_LICENSE("GPL");
  2100. +
  2101. +#define EP_NUL 1 // Endpoint at this position not allowed
  2102. +#define EP_NOP 2 // all type of endpoints allowed at this position
  2103. +#define EP_ISO 3 // Isochron endpoint mandatory at this position
  2104. +#define EP_BLK 4 // Bulk endpoint mandatory at this position
  2105. +#define EP_INT 5 // Interrupt endpoint mandatory at this position
  2106. +
  2107. +// this array represents all endpoints possible in the HCF-USB
  2108. +// the last 2 entries are the configuration number and the minimum interval for Interrupt endpoints
  2109. +int validconf[][18]=
  2110. +{
  2111. + // INT in, ISO out config
  2112. + {EP_NUL,EP_INT,EP_NUL,EP_INT,EP_NUL,EP_INT,EP_NOP,EP_INT,EP_ISO,EP_NUL,EP_ISO,EP_NUL,EP_ISO,EP_NUL,EP_NUL,EP_NUL,CNF_4INT3ISO,2},
  2113. + {EP_NUL,EP_INT,EP_NUL,EP_INT,EP_NUL,EP_INT,EP_NUL,EP_NUL,EP_ISO,EP_NUL,EP_ISO,EP_NUL,EP_ISO,EP_NUL,EP_NUL,EP_NUL,CNF_3INT3ISO,2},
  2114. + // ISO in, ISO out config
  2115. + {EP_NUL,EP_NUL,EP_NUL,EP_NUL,EP_NUL,EP_NUL,EP_NUL,EP_NUL,EP_ISO,EP_ISO,EP_ISO,EP_ISO,EP_ISO,EP_ISO,EP_NOP,EP_ISO,CNF_4ISO3ISO,2},
  2116. + {EP_NUL,EP_NUL,EP_NUL,EP_NUL,EP_NUL,EP_NUL,EP_NUL,EP_NUL,EP_ISO,EP_ISO,EP_ISO,EP_ISO,EP_ISO,EP_ISO,EP_NUL,EP_NUL,CNF_3ISO3ISO,2},
  2117. + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} // EOL element
  2118. +};
  2119. +
  2120. +// string description of chosen config
  2121. +char *conf_str[]=
  2122. +{
  2123. + "4 Interrupt IN + 3 Isochron OUT",
  2124. + "3 Interrupt IN + 3 Isochron OUT",
  2125. + "4 Isochron IN + 3 Isochron OUT",
  2126. + "3 Isochron IN + 3 Isochron OUT"
  2127. +};
  2128. - return (0);
  2129. -} /* usb_init */
  2130. /*************************************************/
  2131. /* function called to probe a new plugged device */
  2132. /*************************************************/
  2133. -static void *
  2134. -hfc_usb_probe(struct usb_device *dev, unsigned int interface
  2135. -#ifdef COMPAT_HAS_USB_IDTAB
  2136. - , const struct usb_device_id *id_table)
  2137. -#else
  2138. - )
  2139. -#endif
  2140. +//static int hfc_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
  2141. +static void* hfc_usb_probe(struct usb_device *dev, unsigned int ifnum, const struct usb_device_id *id)
  2142. {
  2143. + //struct usb_device *dev= interface_to_usbdev(intf);
  2144. + struct usb_interface* intf = dev->actconfig->interface + ifnum;
  2145. hfcusb_data *context;
  2146. - struct usb_interface *ifp = dev->actconfig->interface + interface;
  2147. - struct usb_interface_descriptor *ifdp =
  2148. - ifp->altsetting + ifp->act_altsetting;
  2149. - struct usb_endpoint_descriptor *epd;
  2150. - int i, idx, ep_msk;
  2151. -
  2152. -#ifdef COMPAT_HAS_USB_IDTAB
  2153. - if (id_table && (dev->descriptor.idVendor == id_table->idVendor) &&
  2154. - (dev->descriptor.idProduct == id_table->idProduct) &&
  2155. -#else
  2156. - if ((((dev->descriptor.idVendor == 0x959) &&
  2157. - (dev->descriptor.idProduct == 0x2bd0)) ||
  2158. - ((dev->descriptor.idVendor == 0x7b0) &&
  2159. - (dev->descriptor.idProduct == 0x0006))) &&
  2160. -#endif
  2161. - (ifdp->bNumEndpoints >= 6) && (ifdp->bNumEndpoints <= 16)) {
  2162. - if (!(context = kmalloc(sizeof(hfcusb_data), GFP_KERNEL))) {
  2163. - return (NULL); /* got no mem */
  2164. - };
  2165. - memset(context, 0, sizeof(hfcusb_data)); /* clear the structure */
  2166. - i = ifdp->bNumEndpoints; /* get number of endpoints */
  2167. - ep_msk = 0; /* none found */
  2168. - epd = ifdp->endpoint; /* first endpoint descriptor */
  2169. - while (i-- && ((ep_msk & 0xcf) != 0xcf)) {
  2170. -
  2171. - idx = (((epd->bEndpointAddress & 0x7f) - 1) << 1); /* get endpoint base */
  2172. - if (idx < 7) {
  2173. - switch (epd->bmAttributes) {
  2174. - case USB_ENDPOINT_XFER_INT:
  2175. - if (!
  2176. - (epd->
  2177. - bEndpointAddress &
  2178. - 0x80))
  2179. - break; /* only interrupt in allowed */
  2180. - idx++; /* input index is odd */
  2181. - context->fifos[idx].pipe =
  2182. - usb_rcvintpipe(dev,
  2183. - epd->
  2184. - bEndpointAddress);
  2185. - break;
  2186. -
  2187. - case USB_ENDPOINT_XFER_BULK:
  2188. - if (epd->
  2189. - bEndpointAddress &
  2190. - 0x80)
  2191. - break; /* only bulk out allowed */
  2192. - context->fifos[idx].pipe =
  2193. - usb_sndbulkpipe(dev,
  2194. - epd->
  2195. - bEndpointAddress);
  2196. - break;
  2197. - default:
  2198. - context->fifos[idx].pipe = 0; /* reset data */
  2199. - } /* switch attribute */
  2200. -
  2201. - if (context->fifos[idx].pipe) {
  2202. - context->fifos[idx].fifonum = idx;
  2203. - context->fifos[idx].fifo_mask =
  2204. - 1 << idx;
  2205. - context->fifos[idx].hfc = context;
  2206. - context->fifos[idx].usb_maxlen =
  2207. - epd->wMaxPacketSize;
  2208. - context->fifos[idx].intervall =
  2209. - epd->bInterval;
  2210. - ep_msk |= (1 << idx);
  2211. - } else
  2212. - ep_msk &= ~(1 << idx);
  2213. - } /* idx < 7 */
  2214. - epd++;
  2215. - }
  2216. + //struct usb_host_interface *iface = intf->cur_altsetting;
  2217. + //struct usb_host_interface *iface_used = NULL;
  2218. + //struct usb_host_endpoint *ep;
  2219. + struct usb_endpoint_descriptor* ep;
  2220. + //int ifnum = iface->desc.bInterfaceNumber;
  2221. + struct usb_interface_descriptor* intfdesc = intf->altsetting + intf->act_altsetting;
  2222. + struct usb_interface_descriptor* intfdesc_used = NULL;
  2223. + int i, idx, alt_idx, probe_alt_setting, vend_idx, cfg_used, *vcf, attr, cfg_found, cidx, ep_addr;
  2224. + int cmptbl[16],small_match,iso_packet_size,packet_size,alt_used=0;
  2225. +
  2226. +// usb_show_device(dev);
  2227. +// usb_show_device_descriptor(&dev->descriptor);
  2228. +// usb_show_interface_descriptor(&iface->desc);
  2229. + vend_idx=0xffff;
  2230. + for(i=0;vdata[i].vendor;i++)
  2231. + {
  2232. + if(dev->descriptor.idVendor==vdata[i].vendor && dev->descriptor.idProduct==vdata[i].prod_id) vend_idx=i;
  2233. + }
  2234. +
  2235. - if ((ep_msk & 0x3f) != 0x3f) {
  2236. - kfree(context);
  2237. - return (NULL);
  2238. - }
  2239. - MOD_INC_USE_COUNT; /* lock our module */
  2240. - context->dev = dev; /* save device */
  2241. - context->if_used = interface; /* save used interface */
  2242. - context->alt_used = ifp->act_altsetting; /* and alternate config */
  2243. - context->ctrl_paksize = dev->descriptor.bMaxPacketSize0; /* control size */
  2244. -
  2245. - /* create the control pipes needed for register access */
  2246. - context->ctrl_in_pipe = usb_rcvctrlpipe(context->dev, 0);
  2247. - context->ctrl_out_pipe = usb_sndctrlpipe(context->dev, 0);
  2248. -
  2249. - /* init the chip and register the driver */
  2250. - if (usb_init(context)) {
  2251. - kfree(context);
  2252. - MOD_DEC_USE_COUNT;
  2253. - return (NULL);
  2254. - }
  2255. +#ifdef VERBOSE_USB_DEBUG
  2256. + printk(KERN_INFO "HFC-USB: probing interface(%d) actalt(%d)\n",
  2257. + ifnum, intfdesc->bAlternateSetting);
  2258. + /* printk(KERN_INFO "HFC-USB: probing interface(%d) actalt(%d) minor(%d)\n",
  2259. + ifnum, intfdesc->bAlternateSetting, intf->driver->minor); */
  2260. +#endif
  2261. - printk(KERN_INFO
  2262. - "HFC-USB: New device if=%d alt=%d registered\n",
  2263. - context->if_used, context->alt_used);
  2264. - return (context);
  2265. - }
  2266. + if (vend_idx != 0xffff) {
  2267. +#ifdef VERBOSE_USB_DEBUG
  2268. + printk(KERN_INFO "HFC-USB: found vendor idx:%d name:%s\n",vend_idx,vdata[vend_idx].vend_name);
  2269. +#endif
  2270. + /* if vendor and product ID is OK, start probing a matching alternate setting ... */
  2271. + alt_idx = 0;
  2272. + small_match=0xffff;
  2273. + // default settings
  2274. + iso_packet_size=16;
  2275. + packet_size=64;
  2276. +
  2277. + while (alt_idx < intf->num_altsetting) {
  2278. + //iface = intf->altsetting + alt_idx;
  2279. + intfdesc = intf->altsetting + alt_idx;
  2280. + probe_alt_setting = intfdesc->bAlternateSetting;
  2281. + cfg_used=0;
  2282. - return (NULL); /* no matching entry */
  2283. -} /* hfc_usb_probe */
  2284. +#ifdef VERBOSE_USB_DEBUG
  2285. + printk(KERN_INFO "HFC-USB: test alt_setting %d\n", probe_alt_setting);
  2286. +#endif
  2287. + // check for config EOL element
  2288. + while (validconf[cfg_used][0]) {
  2289. + cfg_found=TRUE;
  2290. + vcf=validconf[cfg_used];
  2291. + ep = intfdesc->endpoint; /* first endpoint descriptor */
  2292. +
  2293. +#ifdef VERBOSE_USB_DEBUG
  2294. + printk(KERN_INFO "HFC-USB: (if=%d alt=%d cfg_used=%d)\n",
  2295. + ifnum, probe_alt_setting, cfg_used);
  2296. +#endif
  2297. + // copy table
  2298. + memcpy(cmptbl,vcf,16*sizeof(int));
  2299. +
  2300. + // check for all endpoints in this alternate setting
  2301. + for (i=0; i < intfdesc->bNumEndpoints; i++) {
  2302. + ep_addr = ep->bEndpointAddress;
  2303. + idx = ((ep_addr & 0x7f)-1)*2; /* get endpoint base */
  2304. + if (ep_addr & 0x80)
  2305. + idx++;
  2306. + attr = ep->bmAttributes;
  2307. +
  2308. + if (cmptbl[idx] == EP_NUL) {
  2309. + printk(KERN_INFO "HFC-USB: cfg_found=FALSE in idx:%d attr:%d cmptbl[%d]:%d\n",
  2310. + idx, attr, idx, cmptbl[idx]);
  2311. + cfg_found = FALSE;
  2312. + }
  2313. +
  2314. + if (attr == USB_ENDPOINT_XFER_INT && cmptbl[idx] == EP_INT)
  2315. + cmptbl[idx] = EP_NUL;
  2316. + if (attr == USB_ENDPOINT_XFER_BULK && cmptbl[idx] == EP_BLK)
  2317. + cmptbl[idx] = EP_NUL;
  2318. + if (attr == USB_ENDPOINT_XFER_ISOC && cmptbl[idx] == EP_ISO)
  2319. + cmptbl[idx] = EP_NUL;
  2320. +
  2321. + // check if all INT endpoints match minimum interval
  2322. + if (attr == USB_ENDPOINT_XFER_INT && ep->bInterval < vcf[17]) {
  2323. +#ifdef VERBOSE_USB_DEBUG
  2324. + if (cfg_found)
  2325. + printk(KERN_INFO "HFC-USB: Interrupt Endpoint interval < %d found - skipping config\n",
  2326. + vcf[17]);
  2327. +#endif
  2328. + cfg_found = FALSE;
  2329. + }
  2330. +
  2331. + ep++;
  2332. + }
  2333. +
  2334. + for (i = 0; i < 16; i++) {
  2335. + // printk(KERN_INFO "HFC-USB: cmptbl[%d]:%d\n", i, cmptbl[i]);
  2336. +
  2337. + // all entries must be EP_NOP or EP_NUL for a valid config
  2338. + if (cmptbl[i] != EP_NOP && cmptbl[i] != EP_NUL)
  2339. + cfg_found = FALSE;
  2340. + }
  2341. +
  2342. + // we check for smallest match, to provide configuration priority
  2343. + // configurations with smaller index have higher priority
  2344. + if (cfg_found) {
  2345. + if (cfg_used < small_match) {
  2346. + small_match = cfg_used;
  2347. + alt_used = probe_alt_setting;
  2348. + //iface_used = iface;
  2349. + intfdesc_used = intfdesc;
  2350. + }
  2351. +#ifdef VERBOSE_USB_DEBUG
  2352. + printk(KERN_INFO "HFC-USB: small_match=%x %x\n", small_match, alt_used);
  2353. +#endif
  2354. + }
  2355. +
  2356. + cfg_used++;
  2357. + }
  2358. +
  2359. + alt_idx++;
  2360. + } /* (alt_idx < intf->num_altsetting) */
  2361. +#ifdef VERBOSE_USB_DEBUG
  2362. + printk(KERN_INFO "HFC-USB: final small_match=%x alt_used=%x\n",small_match, alt_used);
  2363. +#endif
  2364. + // yiipiee, we found a valid config
  2365. + if (small_match != 0xffff) {
  2366. + //iface = iface_used;
  2367. + intfdesc = intfdesc_used;
  2368. +
  2369. + if (!(context = kmalloc(sizeof(hfcusb_data), GFP_KERNEL)))
  2370. + return(NULL); /* got no mem */
  2371. + memset(context, 0, sizeof(hfcusb_data)); /* clear the structure */
  2372. +
  2373. + ep = intfdesc->endpoint; /* first endpoint descriptor */
  2374. + vcf = validconf[small_match];
  2375. +
  2376. + for (i = 0; i < intfdesc->bNumEndpoints; i++) {
  2377. + ep_addr = ep->bEndpointAddress;
  2378. + idx = ((ep_addr & 0x7f)-1)*2; /* get endpoint base */
  2379. + if (ep_addr & 0x80)
  2380. + idx++;
  2381. + cidx = idx & 7;
  2382. + attr = ep->bmAttributes;
  2383. +
  2384. + // only initialize used endpoints
  2385. + if (vcf[idx] != EP_NOP && vcf[idx] != EP_NUL) {
  2386. + switch (attr) {
  2387. + case USB_ENDPOINT_XFER_INT:
  2388. + context->fifos[cidx].pipe = usb_rcvintpipe(dev, ep->bEndpointAddress);
  2389. + context->fifos[cidx].usb_transfer_mode = USB_INT;
  2390. + packet_size = ep->wMaxPacketSize; // remember max packet size
  2391. +#ifdef VERBOSE_USB_DEBUG
  2392. + printk (KERN_INFO "HFC-USB: Interrupt-In Endpoint found %d ms(idx:%d cidx:%d)!\n",
  2393. + ep->bInterval, idx, cidx);
  2394. +#endif
  2395. + break;
  2396. + case USB_ENDPOINT_XFER_BULK:
  2397. + if (ep_addr & 0x80)
  2398. + context->fifos[cidx].pipe = usb_rcvbulkpipe(dev, ep->bEndpointAddress);
  2399. + else
  2400. + context->fifos[cidx].pipe = usb_sndbulkpipe(dev, ep->bEndpointAddress);
  2401. + context->fifos[cidx].usb_transfer_mode = USB_BULK;
  2402. + packet_size = ep->wMaxPacketSize; // remember max packet size
  2403. +#ifdef VERBOSE_USB_DEBUG
  2404. + printk (KERN_INFO "HFC-USB: Bulk Endpoint found (idx:%d cidx:%d)!\n",
  2405. + idx, cidx);
  2406. +#endif
  2407. + break;
  2408. + case USB_ENDPOINT_XFER_ISOC:
  2409. + if (ep_addr & 0x80)
  2410. + context->fifos[cidx].pipe = usb_rcvisocpipe(dev, ep->bEndpointAddress);
  2411. + else
  2412. + context->fifos[cidx].pipe = usb_sndisocpipe(dev, ep->bEndpointAddress);
  2413. + context->fifos[cidx].usb_transfer_mode = USB_ISOC;
  2414. + iso_packet_size = ep->wMaxPacketSize; // remember max packet size
  2415. +#ifdef VERBOSE_USB_DEBUG
  2416. + printk (KERN_INFO "HFC-USB: ISO Endpoint found (idx:%d cidx:%d)!\n",
  2417. + idx, cidx);
  2418. +#endif
  2419. + break;
  2420. + default:
  2421. + context->fifos[cidx].pipe = 0; /* reset data */
  2422. + } /* switch attribute */
  2423. +
  2424. + if (context->fifos[cidx].pipe) {
  2425. + context->fifos[cidx].fifonum = cidx;
  2426. + context->fifos[cidx].hfc = context;
  2427. + context->fifos[cidx].usb_packet_maxlen = ep->wMaxPacketSize;
  2428. + context->fifos[cidx].intervall = ep->bInterval;
  2429. + context->fifos[cidx].skbuff = NULL;
  2430. +#ifdef VERBOSE_USB_DEBUG
  2431. + printk (KERN_INFO "HFC-USB: fifo%d pktlen %d interval %d\n",
  2432. + context->fifos[cidx].fifonum,
  2433. + context->fifos[cidx].usb_packet_maxlen,
  2434. + context->fifos[cidx].intervall);
  2435. +#endif
  2436. + }
  2437. + }
  2438. +
  2439. + ep++;
  2440. + }
  2441. +
  2442. + // now share our luck
  2443. + context->dev = dev; /* save device */
  2444. + context->if_used = ifnum; /* save used interface */
  2445. + context->alt_used = alt_used; /* and alternate config */
  2446. + context->ctrl_paksize = dev->descriptor.bMaxPacketSize0; /* control size */
  2447. + context->cfg_used=vcf[16]; // store used config
  2448. + context->vend_idx=vend_idx; // store found vendor
  2449. + context->packet_size=packet_size;
  2450. + context->iso_packet_size=iso_packet_size;
  2451. +
  2452. + /* create the control pipes needed for register access */
  2453. + context->ctrl_in_pipe = usb_rcvctrlpipe(context->dev, 0);
  2454. + context->ctrl_out_pipe = usb_sndctrlpipe(context->dev, 0);
  2455. + context->ctrl_urb = usb_alloc_urb(0);
  2456. +
  2457. + printk(KERN_INFO "HFC-USB: detected \"%s\" configuration: %s (if=%d alt=%d)\n",
  2458. + vdata[vend_idx].vend_name, conf_str[small_match], context->if_used, context->alt_used);
  2459. +
  2460. + /* init the chip and register the driver */
  2461. + if (usb_init(context))
  2462. + {
  2463. + if (context->ctrl_urb) {
  2464. + usb_unlink_urb(context->ctrl_urb);
  2465. + usb_free_urb(context->ctrl_urb);
  2466. + context->ctrl_urb = NULL;
  2467. + }
  2468. + kfree(context);
  2469. + return(NULL);
  2470. + }
  2471. + //usb_set_intfdata(intf, context);
  2472. + //intf->private_data = context;
  2473. + return(context);
  2474. + }
  2475. + }
  2476. + return(NULL);
  2477. +}
  2478. /****************************************************/
  2479. /* function called when an active device is removed */
  2480. /****************************************************/
  2481. -static void
  2482. -hfc_usb_disconnect(struct usb_device *usbdev, void *drv_context)
  2483. +//static void hfc_usb_disconnect(struct usb_interface *intf)
  2484. +static void hfc_usb_disconnect(struct usb_device *usbdev, void* drv_context)
  2485. {
  2486. - hfcusb_data *context = drv_context;
  2487. + //hfcusb_data *context = intf->private_data;
  2488. + hfcusb_data* context = drv_context;
  2489. int i;
  2490. - struct sk_buff *skb;
  2491. - /* tell all fifos to terminate */
  2492. - for (i = 0; i < HFCUSB_NUM_FIFOS; i++)
  2493. - if (context->fifos[i].active) {
  2494. - context->fifos[i].active = 0;
  2495. - usb_unlink_urb(&context->fifos[i].urb);
  2496. - }
  2497. - while (context->active_fifos) {
  2498. - set_current_state(TASK_INTERRUPTIBLE);
  2499. - /* Timeout 10ms */
  2500. - schedule_timeout((10 * HZ) / 1000);
  2501. - }
  2502. + printk(KERN_INFO "HFC-USB: device disconnect\n");
  2503. +
  2504. + //intf->private_data = NULL;
  2505. + if (!context)
  2506. + return;
  2507. if (timer_pending(&context->t3_timer))
  2508. del_timer(&context->t3_timer);
  2509. - context->regd.release_driver(context->regd.arg_hisax);
  2510. - while ((skb = skb_dequeue(&context->regd.erq)) != NULL)
  2511. - dev_kfree_skb_any(skb);
  2512. + if (timer_pending(&context->t4_timer))
  2513. + del_timer(&context->t4_timer);
  2514. + if (timer_pending(&context->led_timer))
  2515. + del_timer(&context->led_timer);
  2516. +
  2517. + hisax_unregister(&context->d_if);
  2518. + /* tell all fifos to terminate */
  2519. + for(i = 0; i < HFCUSB_NUM_FIFOS; i++) {
  2520. + if(context->fifos[i].usb_transfer_mode == USB_ISOC) {
  2521. + if(context->fifos[i].active > 0) {
  2522. + stop_isoc_chain(&context->fifos[i]);
  2523. +#ifdef VERBOSE_USB_DEBUG
  2524. + printk (KERN_INFO "HFC-USB: hfc_usb_disconnect: stopping ISOC chain Fifo no %i\n", i);
  2525. +#endif
  2526. + }
  2527. + } else {
  2528. + if(context->fifos[i].active > 0) {
  2529. + context->fifos[i].active = 0;
  2530. +#ifdef VERBOSE_USB_DEBUG
  2531. + printk (KERN_INFO "HFC-USB: hfc_usb_disconnect: unlinking URB for Fifo no %i\n", i);
  2532. +#endif
  2533. + }
  2534. + if (context->fifos[i].urb) {
  2535. + usb_unlink_urb(context->fifos[i].urb);
  2536. + usb_free_urb(context->fifos[i].urb);
  2537. + context->fifos[i].urb = NULL;
  2538. + }
  2539. + }
  2540. + context->fifos[i].active = 0;
  2541. + }
  2542. + if (context->ctrl_urb) {
  2543. + usb_unlink_urb(context->ctrl_urb);
  2544. + usb_free_urb(context->ctrl_urb);
  2545. + context->ctrl_urb = NULL;
  2546. + }
  2547. kfree(context); /* free our structure again */
  2548. - MOD_DEC_USE_COUNT; /* and decrement the usage counter */
  2549. } /* hfc_usb_disconnect */
  2550. +
  2551. /************************************/
  2552. /* our driver information structure */
  2553. /************************************/
  2554. static struct usb_driver hfc_drv = {
  2555. name:"hfc_usb",
  2556. -#ifdef COMPAT_HAS_USB_IDTAB
  2557. id_table:hfc_usb_idtab,
  2558. -#endif
  2559. probe:hfc_usb_probe,
  2560. disconnect:hfc_usb_disconnect,
  2561. };
  2562. -static void __exit
  2563. -hfc_usb_exit(void)
  2564. -{
  2565. +static void __exit hfc_usb_exit(void)
  2566. +{
  2567. +#ifdef VERBOSE_USB_DEBUG
  2568. + printk ("HFC-USB: calling \"hfc_usb_exit\" ...\n");
  2569. +#endif
  2570. usb_deregister(&hfc_drv); /* release our driver */
  2571. printk(KERN_INFO "HFC-USB module removed\n");
  2572. }
  2573. -static int __init
  2574. -hfc_usb_init(void)
  2575. +static int __init hfc_usb_init(void)
  2576. {
  2577. - struct hisax_drvreg drv;
  2578. + printk ("HFC-USB: driver module revision %s loaded\n", hfcusb_revision);
  2579. - drv.version = HISAX_LOAD_VERSION; /* set our version */
  2580. - drv.cmd = HISAX_LOAD_CHKVER; /* check command only */
  2581. - if (hisax_register_hfcusb(&drv)) {
  2582. - printk(KERN_INFO "HFC-USB <-> hisax version conflict\n");
  2583. - return (-1); /* unable to register */
  2584. - }
  2585. - if (usb_register(&hfc_drv)) {
  2586. - printk(KERN_INFO
  2587. - "Unable to register HFC-USB module at usb stack\n");
  2588. - return (-1); /* unable to register */
  2589. + if(usb_register(&hfc_drv))
  2590. + {
  2591. + printk(KERN_INFO "HFC-USB: Unable to register HFC-USB module at usb stack\n");
  2592. + return(-1); /* unable to register */
  2593. }
  2594. -
  2595. - printk(KERN_INFO "HFC-USB module loaded\n");
  2596. - return (0);
  2597. + return(0);
  2598. }
  2599. +
  2600. +
  2601. +
  2602. +
  2603. module_init(hfc_usb_init);
  2604. module_exit(hfc_usb_exit);
  2605. +